Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions bundles/datastar.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions bundles/datastar.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions library/src/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
declare const ALIAS: string | null

interface Element {
startViewTransition(callback: () => void | Promise<void>): ViewTransition
}
14 changes: 9 additions & 5 deletions library/src/plugins/watchers/patchElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ watcher({
elements,
}

if (useViewTransition && supportsViewTransitions()) {
let element: any = document.documentElement
if (useViewTransition) {
let target: Document | Element = document
if (viewTransitionSelector) {
const el = document.querySelector(viewTransitionSelector)
if (el && supportsViewTransitions(el)) {
element = el
if (el) {
target = el
}
}
element.startViewTransition(() => onPatchElements(ctx, patchElementsArgs))
if (supportsViewTransitions(target)) {
target.startViewTransition(() => onPatchElements(ctx, patchElementsArgs))
} else {
onPatchElements(ctx, patchElementsArgs)
}
} else {
onPatchElements(ctx, patchElementsArgs)
}
Expand Down
7 changes: 3 additions & 4 deletions library/src/utils/view-transitions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { EventCallbackHandler, Modifiers } from '@engine/types'

export const supportsViewTransitions = (
element: Element = document.documentElement,
): boolean => 'startViewTransition' in element
export const supportsViewTransitions = (target: Document | Element): boolean =>
'startViewTransition' in target

export const modifyViewTransition = (
callback: EventCallbackHandler,
mods: Modifiers,
): EventCallbackHandler => {
if (mods.has('viewtransition') && supportsViewTransitions()) {
if (mods.has('viewtransition') && supportsViewTransitions(document)) {
const cb = callback // I hate javascript
callback = (...args: any[]) =>
document.startViewTransition(() => cb(...args))
Expand Down