@atom.io/spa 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +381 -10
- package/README.mdx +101 -5
- package/dist/astro-application.d.ts +1 -1
- package/dist/astro-client.d.ts +1 -1
- package/dist/astro-client.js +2 -2
- package/dist/astro-request-DRKvDjsO.js.map +1 -1
- package/dist/astro-resumability-client.d.ts +1 -1
- package/dist/astro-server.js +1 -1
- package/dist/{astro-shared-DHIpjNIG.d.ts → astro-shared-DZp1x8RQ.d.ts} +2 -2
- package/dist/{astro-shared-DHIpjNIG.d.ts.map → astro-shared-DZp1x8RQ.d.ts.map} +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/astro.js +1 -1
- package/dist/{capabilities-BCtBG-ni.d.ts → capabilities-DNcnGRv_.d.ts} +11 -5
- package/dist/capabilities-DNcnGRv_.d.ts.map +1 -0
- package/dist/{capabilities-BkQ2i0vV.js → capabilities-nOIitQ-_.js} +6 -4
- package/dist/capabilities-nOIitQ-_.js.map +1 -0
- package/dist/client.min.js +1 -1
- package/dist/{core-DjFJ0aIJ.js → core-B4rJ0xdc.js} +22 -12
- package/dist/core-B4rJ0xdc.js.map +1 -0
- package/dist/development/astro-client.js +2 -2
- package/dist/development/astro-request-DRKvDjsO.js.map +1 -1
- package/dist/development/astro-server.js +1 -1
- package/dist/development/astro.js +1 -1
- package/dist/development/{capabilities-BkQ2i0vV.js → capabilities-nOIitQ-_.js} +6 -4
- package/dist/development/capabilities-nOIitQ-_.js.map +1 -0
- package/dist/development/{core-DxPiKryn.js → core-BHA7I1nf.js} +24 -14
- package/dist/development/core-BHA7I1nf.js.map +1 -0
- package/dist/development/{dom-BytVV6Rp.js → dom-DQ0M3rLL.js} +11 -10
- package/dist/development/{dom-BytVV6Rp.js.map → dom-DQ0M3rLL.js.map} +1 -1
- package/dist/development/floating.js +148 -0
- package/dist/development/floating.js.map +1 -0
- package/dist/development/index.js +4 -4
- package/dist/development/jsx-runtime.js +2 -2
- package/dist/development/jsx-runtime.js.map +1 -1
- package/dist/development/konva.js +2 -2
- package/dist/development/motion.js +419 -25
- package/dist/development/motion.js.map +1 -1
- package/dist/development/renderer.js +2 -2
- package/dist/development/{server-renderer-CUQXh9oF.js → server-renderer-DCLoMdOX.js} +3 -3
- package/dist/development/{server-renderer-CUQXh9oF.js.map → server-renderer-DCLoMdOX.js.map} +1 -1
- package/dist/development/server.js +1 -1
- package/dist/{src-DWIqXCiz.js → development/src-DoQgCX-O.js} +2 -2
- package/dist/development/{src-WSHJxR9b.js.map → src-DoQgCX-O.js.map} +1 -1
- package/dist/development/three.js +87 -31
- package/dist/development/three.js.map +1 -1
- package/dist/development/{vite-CSHoxzXU.js → vite-Bmyb6P5w.js} +32 -7
- package/dist/development/vite-Bmyb6P5w.js.map +1 -0
- package/dist/development/vite.js +1 -1
- package/dist/{dom-B5OxgHkr.js → dom-D8g3roX9.js} +11 -10
- package/dist/{dom-B5OxgHkr.js.map → dom-D8g3roX9.js.map} +1 -1
- package/dist/floating.d.ts +16 -0
- package/dist/floating.d.ts.map +1 -0
- package/dist/floating.js +148 -0
- package/dist/floating.js.map +1 -0
- package/dist/{index-DufwkB6W.d.ts → index-BFnXIfOj.d.ts} +3 -3
- package/dist/{index-DufwkB6W.d.ts.map → index-BFnXIfOj.d.ts.map} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/{jsx-runtime-DMDVr7A5.d.ts → jsx-runtime-DQnpyT_g.d.ts} +2 -2
- package/dist/{jsx-runtime-DMDVr7A5.d.ts.map → jsx-runtime-DQnpyT_g.d.ts.map} +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +2 -2
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/konva.d.ts +3 -3
- package/dist/konva.js +2 -2
- package/dist/motion.d.ts +39 -16
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +419 -25
- package/dist/motion.js.map +1 -1
- package/dist/renderer.d.ts +1 -1
- package/dist/renderer.js +2 -2
- package/dist/{server-renderer-DcU55e6s.js → server-renderer-D0rsFL_-.js} +3 -3
- package/dist/{server-renderer-DcU55e6s.js.map → server-renderer-D0rsFL_-.js.map} +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/size.json +12 -12
- package/dist/{development/src-WSHJxR9b.js → src-Bme1kz2b.js} +2 -2
- package/dist/{src-DWIqXCiz.js.map → src-Bme1kz2b.js.map} +1 -1
- package/dist/three.d.ts +27 -8
- package/dist/three.d.ts.map +1 -1
- package/dist/three.js +87 -31
- package/dist/three.js.map +1 -1
- package/dist/{vite-CSHoxzXU.js → vite-Bmyb6P5w.js} +32 -7
- package/dist/vite-Bmyb6P5w.js.map +1 -0
- package/dist/vite.js +1 -1
- package/package.json +18 -5
- package/src/astro-request.ts +1 -1
- package/src/capabilities.ts +11 -4
- package/src/compiler.ts +28 -9
- package/src/core.ts +26 -12
- package/src/dom.ts +12 -11
- package/src/floating.ts +234 -0
- package/src/index.ts +1 -0
- package/src/jsx-runtime.ts +4 -1
- package/src/motion-layout.ts +363 -0
- package/src/motion-transition.ts +92 -0
- package/src/motion-tween.ts +19 -2
- package/src/motion.ts +215 -77
- package/src/presence.ts +1 -1
- package/src/three-events.ts +14 -10
- package/src/three.ts +134 -39
- package/dist/capabilities-BCtBG-ni.d.ts.map +0 -1
- package/dist/capabilities-BkQ2i0vV.js.map +0 -1
- package/dist/core-DjFJ0aIJ.js.map +0 -1
- package/dist/development/capabilities-BkQ2i0vV.js.map +0 -1
- package/dist/development/core-DxPiKryn.js.map +0 -1
- package/dist/development/vite-CSHoxzXU.js.map +0 -1
- package/dist/vite-CSHoxzXU.js.map +0 -1
package/src/compiler.ts
CHANGED
|
@@ -161,7 +161,11 @@ export function compile(
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
+
const component =
|
|
165
|
+
node.type === `JSXElement` &&
|
|
166
|
+
!tag(node.openingElement.name).startsWith(`"`)
|
|
164
167
|
const children: Part[][] = []
|
|
168
|
+
let lazyChildren = false
|
|
165
169
|
for (const child of node.children) {
|
|
166
170
|
if (child.type === `JSXText`) {
|
|
167
171
|
const value = text(decodeJsx(child.value))
|
|
@@ -169,18 +173,33 @@ export function compile(
|
|
|
169
173
|
} else if (child.type === `JSXElement` || child.type === `JSXFragment`)
|
|
170
174
|
children.push([child])
|
|
171
175
|
else if (child.type === `JSXExpressionContainer`) {
|
|
172
|
-
if (child.expression.type !== `JSXEmptyExpression`)
|
|
173
|
-
|
|
176
|
+
if (child.expression.type !== `JSXEmptyExpression`) {
|
|
177
|
+
if (component) {
|
|
178
|
+
// Component props expose their declared values, including callbacks.
|
|
179
|
+
children.push([`(`, child.expression, `)`])
|
|
180
|
+
if (!eager(child.expression, true)) lazyChildren = true
|
|
181
|
+
} else children.push(expression(child.expression))
|
|
182
|
+
}
|
|
174
183
|
} else
|
|
175
184
|
throw new SyntaxError(`${filename}: JSX spread children are unsupported`)
|
|
176
185
|
}
|
|
177
|
-
if (children.length)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
186
|
+
if (children.length) {
|
|
187
|
+
const value =
|
|
188
|
+
children.length === 1 ? children[0] : [`[`, ...join(children, `, `), `]`]
|
|
189
|
+
if (lazyChildren) {
|
|
190
|
+
// Capture the computation outside the getter's method scope.
|
|
191
|
+
const read = uid(`children`)
|
|
192
|
+
properties.push([`get children(){ return ${read}(); }`])
|
|
193
|
+
chunks.push([
|
|
194
|
+
`((${read}) => ({`,
|
|
195
|
+
...join(properties, `, `),
|
|
196
|
+
`}))(() => (`,
|
|
197
|
+
...value,
|
|
198
|
+
`))`,
|
|
199
|
+
])
|
|
200
|
+
properties = []
|
|
201
|
+
} else properties.push([`children: `, ...value])
|
|
202
|
+
}
|
|
184
203
|
flush()
|
|
185
204
|
const spreads =
|
|
186
205
|
node.type === `JSXElement` &&
|
package/src/core.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
disposeState,
|
|
2
3
|
ReadableFamilyToken,
|
|
3
4
|
ReadableToken,
|
|
4
5
|
RegularAtomFamilyToken,
|
|
@@ -17,6 +18,7 @@ import type { RootStore } from "atom.io/internal"
|
|
|
17
18
|
import {
|
|
18
19
|
actUponStore,
|
|
19
20
|
clearTimelineInStore,
|
|
21
|
+
disposeFromStore,
|
|
20
22
|
findInStore,
|
|
21
23
|
findTimelineInStore,
|
|
22
24
|
getFromStore,
|
|
@@ -199,13 +201,21 @@ export function createRoot(options: RootOptions = {}, server = false): Root {
|
|
|
199
201
|
root._presence = capability.presence(root)
|
|
200
202
|
}
|
|
201
203
|
root.flush = () => {
|
|
204
|
+
if (!root._queue.size && !root._mounts!.length) return
|
|
202
205
|
try {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
const commits = [...capabilities.values()].map((capability) =>
|
|
207
|
+
capability.beforeUpdate?.(root),
|
|
208
|
+
)
|
|
209
|
+
try {
|
|
210
|
+
let passes = 0
|
|
211
|
+
while (root._queue.size || root._mounts!.length) {
|
|
212
|
+
if (import.meta.env.DEV && ++passes > 100)
|
|
213
|
+
throw new Error(`spa: update loop`)
|
|
214
|
+
for (const run of [...root._queue]) if (root._queue.delete(run)) run()
|
|
215
|
+
for (const run of root._mounts!.splice(0)) run()
|
|
216
|
+
}
|
|
217
|
+
} finally {
|
|
218
|
+
for (const commit of commits) commit?.()
|
|
209
219
|
}
|
|
210
220
|
} catch (error) {
|
|
211
221
|
fail(root, error)
|
|
@@ -217,6 +227,10 @@ export function createRoot(options: RootOptions = {}, server = false): Root {
|
|
|
217
227
|
export function useStore(): RootStore {
|
|
218
228
|
return owner!._root._store
|
|
219
229
|
}
|
|
230
|
+
/** Return atom.io disposal bound to the current root's store. */
|
|
231
|
+
export function useDisposal(): typeof disposeState {
|
|
232
|
+
return disposeFromStore.bind(null, useStore()) as typeof disposeState
|
|
233
|
+
}
|
|
220
234
|
export function onCleanup(cleanup: Cleanup): void {
|
|
221
235
|
owner!._cleanups.add(cleanup)
|
|
222
236
|
}
|
|
@@ -279,7 +293,7 @@ export function observe<T>(
|
|
|
279
293
|
|
|
280
294
|
/** Resolve a fixed family key in the current owner's store. */
|
|
281
295
|
export function resolveStateToken(token: any, key?: Canonical): any {
|
|
282
|
-
const store =
|
|
296
|
+
const store = useStore()
|
|
283
297
|
return token.type.endsWith(`_family`) ? findInStore(store, token, key!) : token
|
|
284
298
|
}
|
|
285
299
|
|
|
@@ -294,7 +308,7 @@ export function useGetter<T, K extends Canonical, E = never>(
|
|
|
294
308
|
export function useGetter(token: any, key?: Canonical): Accessor<any> {
|
|
295
309
|
token = resolveStateToken(token, key)
|
|
296
310
|
const root = owner!._root
|
|
297
|
-
const store =
|
|
311
|
+
const store = useStore()
|
|
298
312
|
const subscribe: Subscribe = (notify) =>
|
|
299
313
|
subscribeToState(store, token, `spa:${serial++}`, notify)
|
|
300
314
|
return () => {
|
|
@@ -313,7 +327,7 @@ export function useSetter<T, K extends Canonical>(
|
|
|
313
327
|
): (value: T | Setter<T>) => void
|
|
314
328
|
export function useSetter(token: any, key?: Canonical): (value: any) => void {
|
|
315
329
|
token = resolveStateToken(token, key)
|
|
316
|
-
const store =
|
|
330
|
+
const store = useStore()
|
|
317
331
|
return (value) => {
|
|
318
332
|
setIntoStore(store, token, value)
|
|
319
333
|
}
|
|
@@ -321,7 +335,7 @@ export function useSetter(token: any, key?: Canonical): (value: any) => void {
|
|
|
321
335
|
export function useTransaction<F extends (...args: any[]) => any>(
|
|
322
336
|
token: TransactionToken<F>,
|
|
323
337
|
): (...args: Parameters<F>) => ReturnType<F> {
|
|
324
|
-
return actUponStore(
|
|
338
|
+
return actUponStore(useStore(), token, `spa:${serial++}`)
|
|
325
339
|
}
|
|
326
340
|
|
|
327
341
|
const refs = new WeakMap<RootStore, Map<string, object>>()
|
|
@@ -337,7 +351,7 @@ export function useRef<E extends Element>(
|
|
|
337
351
|
key?: Canonical,
|
|
338
352
|
): (element: E | null) => void {
|
|
339
353
|
token = resolveStateToken(token, key)
|
|
340
|
-
const store =
|
|
354
|
+
const store = useStore()
|
|
341
355
|
const owners = refs.get(store) ?? new Map<string, object>()
|
|
342
356
|
refs.set(store, owners)
|
|
343
357
|
const identity = {}
|
|
@@ -370,7 +384,7 @@ export function useTimeline<K extends Canonical, M extends TimelineManageable>(
|
|
|
370
384
|
key: NoInfer<K>,
|
|
371
385
|
): TimelineControls
|
|
372
386
|
export function useTimeline(token: any, key?: Canonical): TimelineControls {
|
|
373
|
-
const store =
|
|
387
|
+
const store = useStore()
|
|
374
388
|
const selected: TimelineToken<any> =
|
|
375
389
|
token.type === `timeline_family`
|
|
376
390
|
? findTimelineInStore(store, token, key!)
|
package/src/dom.ts
CHANGED
|
@@ -341,21 +341,16 @@ function mount(
|
|
|
341
341
|
)
|
|
342
342
|
finish(children)
|
|
343
343
|
}
|
|
344
|
+
let previous: Record<string, any> = {}
|
|
344
345
|
const nativeProps = capabilityProps(
|
|
345
346
|
owner,
|
|
346
347
|
{ kind: `dom`, node: element },
|
|
347
348
|
() => ({ ...props }),
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
})
|
|
354
|
-
observe(
|
|
355
|
-
owner,
|
|
356
|
-
() => ({ ...props }),
|
|
357
|
-
(all) => {
|
|
358
|
-
const next = nativeProps(all)
|
|
349
|
+
(next) => {
|
|
350
|
+
const previousStyle =
|
|
351
|
+
previous[`style`] !== next[`style`]
|
|
352
|
+
? (element.getAttribute(`style`) ?? ``)
|
|
353
|
+
: undefined
|
|
359
354
|
for (const key in { ...previous, ...next })
|
|
360
355
|
if (
|
|
361
356
|
!Object.is(previous[key], next[key]) ||
|
|
@@ -365,8 +360,14 @@ function mount(
|
|
|
365
360
|
previous[key] = next[key]
|
|
366
361
|
}
|
|
367
362
|
previous = next
|
|
363
|
+
return previousStyle
|
|
368
364
|
},
|
|
369
365
|
)
|
|
366
|
+
owner._cleanups.add(() => {
|
|
367
|
+
for (const key in previous)
|
|
368
|
+
if (key.startsWith(`on`)) property(element, key, null, previous[key])
|
|
369
|
+
})
|
|
370
|
+
observe(owner, () => ({ ...props }), nativeProps)
|
|
370
371
|
const ref = untrack(() => props[`ref`])
|
|
371
372
|
if (ref) {
|
|
372
373
|
owner._root._mounts!.unshift(() => {
|
package/src/floating.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AutoUpdateOptions,
|
|
3
|
+
Middleware,
|
|
4
|
+
Placement,
|
|
5
|
+
ReferenceElement,
|
|
6
|
+
Strategy,
|
|
7
|
+
} from "@floating-ui/dom"
|
|
8
|
+
import { autoUpdate, computePosition } from "@floating-ui/dom"
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
Capability,
|
|
12
|
+
CapabilityBinding,
|
|
13
|
+
CapabilityTarget,
|
|
14
|
+
} from "./capabilities.ts"
|
|
15
|
+
import type { Scope } from "./core.ts"
|
|
16
|
+
import { fail, onMount, within } from "./core.ts"
|
|
17
|
+
|
|
18
|
+
export interface FloatingAttributes<Kind extends string = `dom`> {
|
|
19
|
+
[`floating:reference`]?: Kind extends `dom` ? ReferenceElement | null : never
|
|
20
|
+
[`floating:placement`]?: Kind extends `dom` ? Placement : never
|
|
21
|
+
[`floating:strategy`]?: Kind extends `dom` ? Strategy : never
|
|
22
|
+
[`floating:middleware`]?: Kind extends `dom` ? readonly Middleware[] : never
|
|
23
|
+
[`floating:enabled`]?: Kind extends `dom` ? boolean : never
|
|
24
|
+
[`floating:autoUpdate`]?: Kind extends `dom`
|
|
25
|
+
? boolean | AutoUpdateOptions
|
|
26
|
+
: never
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line quotes -- TypeScript module augmentation requires a string literal.
|
|
30
|
+
declare module "@atom.io/spa/jsx-runtime" {
|
|
31
|
+
// oxlint-disable-next-line typescript/no-empty-interface -- Declaration merging supplies optional floating attributes.
|
|
32
|
+
interface CapabilityAttributes<
|
|
33
|
+
Kind extends string,
|
|
34
|
+
> extends FloatingAttributes<Kind> {}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface FloatingProps {
|
|
38
|
+
reference?: ReferenceElement | null
|
|
39
|
+
placement?: Placement
|
|
40
|
+
strategy?: Strategy
|
|
41
|
+
middleware?: readonly Middleware[]
|
|
42
|
+
enabled?: boolean
|
|
43
|
+
autoUpdate?: boolean | AutoUpdateOptions
|
|
44
|
+
}
|
|
45
|
+
const allowed = new Set([
|
|
46
|
+
`reference`,
|
|
47
|
+
`placement`,
|
|
48
|
+
`strategy`,
|
|
49
|
+
`middleware`,
|
|
50
|
+
`enabled`,
|
|
51
|
+
`autoUpdate`,
|
|
52
|
+
])
|
|
53
|
+
const observerKeys = [
|
|
54
|
+
`ancestorScroll`,
|
|
55
|
+
`ancestorResize`,
|
|
56
|
+
`elementResize`,
|
|
57
|
+
`layoutShift`,
|
|
58
|
+
`animationFrame`,
|
|
59
|
+
] as const
|
|
60
|
+
const ownedStyles = [
|
|
61
|
+
`position`,
|
|
62
|
+
`left`,
|
|
63
|
+
`top`,
|
|
64
|
+
`translate`,
|
|
65
|
+
`visibility`,
|
|
66
|
+
] as const
|
|
67
|
+
|
|
68
|
+
function attach(target: CapabilityTarget, scope?: Scope): CapabilityBinding {
|
|
69
|
+
const element = target.node as HTMLElement
|
|
70
|
+
if (
|
|
71
|
+
target.kind !== `dom` ||
|
|
72
|
+
element?.namespaceURI !== `http://www.w3.org/1999/xhtml`
|
|
73
|
+
)
|
|
74
|
+
throw new Error(`spa/floating: floating elements must be HTML elements`)
|
|
75
|
+
let props: FloatingProps = {}
|
|
76
|
+
let dead = false
|
|
77
|
+
let mounted = false
|
|
78
|
+
let generation = 0
|
|
79
|
+
let request = 0
|
|
80
|
+
let stop: (() => void) | undefined
|
|
81
|
+
let reference: ReferenceElement | undefined
|
|
82
|
+
let observing: boolean | AutoUpdateOptions | undefined
|
|
83
|
+
let original: Map<string, { value: string; priority: string }> | undefined
|
|
84
|
+
let positioned = false
|
|
85
|
+
let translation = ``
|
|
86
|
+
|
|
87
|
+
const restore = () => {
|
|
88
|
+
if (!original) return
|
|
89
|
+
for (const [key, style] of original) {
|
|
90
|
+
if (style.value)
|
|
91
|
+
element.style.setProperty(key, style.value, style.priority)
|
|
92
|
+
else element.style.removeProperty(key)
|
|
93
|
+
}
|
|
94
|
+
original = undefined
|
|
95
|
+
positioned = false
|
|
96
|
+
translation = ``
|
|
97
|
+
}
|
|
98
|
+
const disconnect = () => {
|
|
99
|
+
++generation
|
|
100
|
+
stop?.()
|
|
101
|
+
stop = undefined
|
|
102
|
+
reference = undefined
|
|
103
|
+
}
|
|
104
|
+
const report = (error: unknown) => {
|
|
105
|
+
if (!scope) {
|
|
106
|
+
queueMicrotask(() => {
|
|
107
|
+
throw error
|
|
108
|
+
})
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
fail(scope._root, error)
|
|
113
|
+
} catch (failure) {
|
|
114
|
+
scope._root.error(failure)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const updatePosition = () => {
|
|
118
|
+
const anchor = reference
|
|
119
|
+
if (dead || !anchor) return
|
|
120
|
+
const currentGeneration = generation
|
|
121
|
+
const currentRequest = ++request
|
|
122
|
+
void computePosition(anchor, element, {
|
|
123
|
+
placement: props.placement ?? `bottom`,
|
|
124
|
+
strategy: props.strategy ?? `absolute`,
|
|
125
|
+
middleware: props.middleware ? [...props.middleware] : [],
|
|
126
|
+
}).then(
|
|
127
|
+
({ x, y }) => {
|
|
128
|
+
if (
|
|
129
|
+
dead ||
|
|
130
|
+
generation !== currentGeneration ||
|
|
131
|
+
currentRequest !== request
|
|
132
|
+
)
|
|
133
|
+
return
|
|
134
|
+
translation = `${x}px ${y}px`
|
|
135
|
+
element.style.setProperty(`translate`, translation)
|
|
136
|
+
if (!positioned) {
|
|
137
|
+
positioned = true
|
|
138
|
+
const visibility = original!.get(`visibility`)!
|
|
139
|
+
if (visibility.value)
|
|
140
|
+
element.style.setProperty(
|
|
141
|
+
`visibility`,
|
|
142
|
+
visibility.value,
|
|
143
|
+
visibility.priority,
|
|
144
|
+
)
|
|
145
|
+
else element.style.removeProperty(`visibility`)
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
(error: unknown) => {
|
|
149
|
+
if (
|
|
150
|
+
!dead &&
|
|
151
|
+
generation === currentGeneration &&
|
|
152
|
+
currentRequest === request
|
|
153
|
+
)
|
|
154
|
+
report(error)
|
|
155
|
+
},
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
const connect = () => {
|
|
159
|
+
if (dead || !mounted) return
|
|
160
|
+
const nextReference =
|
|
161
|
+
props.enabled === false ? undefined : (props.reference ?? undefined)
|
|
162
|
+
const nextObserving = props.autoUpdate ?? true
|
|
163
|
+
const optionsChanged =
|
|
164
|
+
typeof nextObserving !== typeof observing ||
|
|
165
|
+
(typeof nextObserving === `object` && typeof observing === `object`
|
|
166
|
+
? observerKeys.some(
|
|
167
|
+
(key) =>
|
|
168
|
+
nextObserving[key] !== (observing as AutoUpdateOptions)[key],
|
|
169
|
+
)
|
|
170
|
+
: nextObserving !== observing)
|
|
171
|
+
const reconnect = nextReference !== reference || optionsChanged
|
|
172
|
+
if (reconnect) disconnect()
|
|
173
|
+
if (!nextReference) {
|
|
174
|
+
restore()
|
|
175
|
+
return
|
|
176
|
+
}
|
|
177
|
+
original ??= new Map(
|
|
178
|
+
ownedStyles.map((key) => [
|
|
179
|
+
key,
|
|
180
|
+
{
|
|
181
|
+
value: element.style.getPropertyValue(key),
|
|
182
|
+
priority: element.style.getPropertyPriority(key),
|
|
183
|
+
},
|
|
184
|
+
]),
|
|
185
|
+
)
|
|
186
|
+
element.style.setProperty(`position`, props.strategy ?? `absolute`)
|
|
187
|
+
element.style.setProperty(`left`, `0px`)
|
|
188
|
+
element.style.setProperty(`top`, `0px`)
|
|
189
|
+
if (positioned) element.style.setProperty(`translate`, translation)
|
|
190
|
+
else element.style.setProperty(`visibility`, `hidden`, `important`)
|
|
191
|
+
reference = nextReference
|
|
192
|
+
observing =
|
|
193
|
+
typeof nextObserving === `object` ? { ...nextObserving } : nextObserving
|
|
194
|
+
if (reconnect && nextObserving !== false) {
|
|
195
|
+
stop = autoUpdate(
|
|
196
|
+
nextReference,
|
|
197
|
+
element,
|
|
198
|
+
updatePosition,
|
|
199
|
+
typeof nextObserving === `object` ? nextObserving : undefined,
|
|
200
|
+
)
|
|
201
|
+
} else updatePosition()
|
|
202
|
+
}
|
|
203
|
+
const mount = () => {
|
|
204
|
+
if (dead) return
|
|
205
|
+
mounted = true
|
|
206
|
+
connect()
|
|
207
|
+
}
|
|
208
|
+
if (scope)
|
|
209
|
+
within(scope, () => {
|
|
210
|
+
onMount(mount)
|
|
211
|
+
})
|
|
212
|
+
else queueMicrotask(mount)
|
|
213
|
+
return {
|
|
214
|
+
update(next) {
|
|
215
|
+
if (dead) return
|
|
216
|
+
for (const key of Object.keys(next))
|
|
217
|
+
if (!allowed.has(key))
|
|
218
|
+
throw new Error(`spa/floating: unknown property floating:${key}`)
|
|
219
|
+
props = next
|
|
220
|
+
connect()
|
|
221
|
+
},
|
|
222
|
+
dispose() {
|
|
223
|
+
if (dead) return
|
|
224
|
+
dead = true
|
|
225
|
+
disconnect()
|
|
226
|
+
restore()
|
|
227
|
+
},
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Position HTML overlays using CSS translate, leaving transform available to Motion. */
|
|
232
|
+
export function floatingCapability(): Capability {
|
|
233
|
+
return { namespace: `floating`, attach }
|
|
234
|
+
}
|
package/src/index.ts
CHANGED
package/src/jsx-runtime.ts
CHANGED
|
@@ -47,7 +47,10 @@ export function merge(
|
|
|
47
47
|
.reverse()
|
|
48
48
|
.find((source) => Object.hasOwn(source, key))?.[key],
|
|
49
49
|
ownKeys: () => [...new Set(values().flatMap(Object.keys))],
|
|
50
|
-
getOwnPropertyDescriptor: () =>
|
|
50
|
+
getOwnPropertyDescriptor: (_, key) =>
|
|
51
|
+
values().some((source) => Object.hasOwn(source, key))
|
|
52
|
+
? { enumerable: true, configurable: true }
|
|
53
|
+
: undefined,
|
|
51
54
|
},
|
|
52
55
|
)
|
|
53
56
|
}
|