@getcortexlabs/mavis-web 0.1.0-rc.13 → 0.1.0-rc.15
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 +4 -4
- package/dist/component-motion.d.ts.map +1 -1
- package/dist/component-motion.js +16 -0
- package/dist/component-motion.js.map +1 -1
- package/dist/components/ChartPlot.d.ts +8 -0
- package/dist/components/ChartPlot.d.ts.map +1 -1
- package/dist/components/ChartPlot.js +21 -1
- package/dist/components/ChartPlot.js.map +1 -1
- package/dist/components/DateCalendar.d.ts +1 -1
- package/dist/components/DateCalendar.d.ts.map +1 -1
- package/dist/components/DateCalendar.js +3 -1
- package/dist/components/DateCalendar.js.map +1 -1
- package/dist/components/MButton.d.ts +7 -7
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +59 -19
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MChip.d.ts +1 -1
- package/dist/components/MDatePicker.d.ts +96 -96
- package/dist/components/MDatePicker.d.ts.map +1 -1
- package/dist/components/MEmptyState.d.ts +1 -1
- package/dist/components/MInput.d.ts +9 -9
- package/dist/components/MLink.d.ts +1 -1
- package/dist/components/MPopover.d.ts +1 -1
- package/dist/components/MProgress.d.ts +1 -1
- package/dist/components/MRangeSlider.d.ts +2 -2
- package/dist/components/MResizablePanels.d.ts +2 -2
- package/dist/components/MReveal.d.ts +10 -10
- package/dist/components/MSheet.d.ts +5 -5
- package/dist/components/MSlider.d.ts +2 -2
- package/dist/components/MStack.d.ts +10 -10
- package/dist/components/MTimePicker.d.ts +40 -40
- package/dist/components/MTimePicker.d.ts.map +1 -1
- package/dist/components/MTooltip.d.ts +1 -1
- package/dist/components/MVirtualList.d.ts.map +1 -1
- package/dist/components/MVirtualList.js +111 -40
- package/dist/components/MVirtualList.js.map +1 -1
- package/dist/components/advanced.d.ts +34 -34
- package/dist/components/configurator.d.ts +33 -33
- package/dist/components/creative.d.ts +20 -20
- package/dist/components/dashboard.d.ts +12 -12
- package/dist/components/dashboard.d.ts.map +1 -1
- package/dist/components/dashboard.js +153 -76
- package/dist/components/dashboard.js.map +1 -1
- package/dist/components/discovery.d.ts +10 -10
- package/dist/components/interactive.d.ts +6 -6
- package/dist/components/layout.d.ts +30 -30
- package/dist/components/navigation.d.ts +4 -4
- package/dist/components/screen-components.d.ts +23 -23
- package/dist/components/screen-components.d.ts.map +1 -1
- package/dist/components/wayfinding.d.ts +11 -11
- package/dist/components/workflows.d.ts +5 -5
- package/dist/motion-region.d.ts.map +1 -1
- package/dist/motion-region.js +1 -0
- package/dist/motion-region.js.map +1 -1
- package/dist/motion-surface.d.ts +6 -1
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +77 -14
- package/dist/motion-surface.js.map +1 -1
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +8 -3
- package/dist/motion.js.map +1 -1
- package/dist/pointer-availability.d.ts +6 -0
- package/dist/pointer-availability.d.ts.map +1 -0
- package/dist/pointer-availability.js +49 -0
- package/dist/pointer-availability.js.map +1 -0
- package/dist/scroll-motion.d.ts.map +1 -1
- package/dist/scroll-motion.js +19 -6
- package/dist/scroll-motion.js.map +1 -1
- package/dist/section-scroll.d.ts +2 -1
- package/dist/section-scroll.d.ts.map +1 -1
- package/dist/section-scroll.js +43 -12
- package/dist/section-scroll.js.map +1 -1
- package/package.json +3 -3
- package/src/base.css +43 -1
- package/src/component-motion.ts +15 -0
- package/src/components/ChartPlot.ts +21 -1
- package/src/components/DateCalendar.ts +3 -1
- package/src/components/MCard.ts +71 -17
- package/src/components/MVirtualList.ts +107 -29
- package/src/components/dashboard.ts +149 -75
- package/src/motion-region.ts +1 -0
- package/src/motion-surface.ts +87 -16
- package/src/motion.ts +16 -5
- package/src/pointer-availability.ts +54 -0
- package/src/scroll-motion.ts +17 -6
- package/src/section-scroll.ts +38 -12
package/src/motion-surface.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
import { motionKeyframes, type MotionSurfaceAdapter } from '@getcortexlabs/mavis-core/experimental'
|
|
10
10
|
import { webRegion } from './motion-region.js'
|
|
11
11
|
import { webVisualEffects } from './visual-effects.js'
|
|
12
|
+
import { watchPointerAvailability } from './pointer-availability.js'
|
|
12
13
|
|
|
13
14
|
const boundPaint = new WeakMap<HTMLElement, Map<string, number>>()
|
|
14
15
|
const paintKeys = new Set([
|
|
@@ -62,7 +63,11 @@ export function webMotionSurface(
|
|
|
62
63
|
sources = new WeakMap<object, WebReadableValue>(),
|
|
63
64
|
refreshes = new Map<object, () => void>(),
|
|
64
65
|
plainText: () => boolean = () => false,
|
|
66
|
+
sections = new Set<ReturnType<typeof webSectionScroll>>(),
|
|
65
67
|
) {
|
|
68
|
+
const interrupt = (properties: readonly string[]) => {
|
|
69
|
+
for (const section of sections) section.interrupt(properties)
|
|
70
|
+
}
|
|
66
71
|
const adapter: MotionSurfaceAdapter = {
|
|
67
72
|
...webVisualEffects(owner, target, sources, plainText),
|
|
68
73
|
sensor(kind, options) {
|
|
@@ -110,8 +115,16 @@ export function webMotionSurface(
|
|
|
110
115
|
try {
|
|
111
116
|
scope.use((child) =>
|
|
112
117
|
setup(
|
|
113
|
-
webMotionSurface(
|
|
114
|
-
|
|
118
|
+
webMotionSurface(
|
|
119
|
+
runtime,
|
|
120
|
+
target,
|
|
121
|
+
enabled,
|
|
122
|
+
child,
|
|
123
|
+
sources,
|
|
124
|
+
refreshes,
|
|
125
|
+
plainText,
|
|
126
|
+
sections,
|
|
127
|
+
).adapter,
|
|
115
128
|
),
|
|
116
129
|
)
|
|
117
130
|
} catch (error) {
|
|
@@ -124,12 +137,17 @@ export function webMotionSurface(
|
|
|
124
137
|
const input = webRegion(region)
|
|
125
138
|
if (input.runtime !== runtime || input.target === target || !input.target.contains(target))
|
|
126
139
|
throw new TypeError('Use a separate enclosing motion region for pointer input.')
|
|
140
|
+
const { onAvailabilityChange, ...inputOptions } = options
|
|
127
141
|
const pointer = owner.pointerFollow(input.target, {
|
|
128
|
-
...
|
|
142
|
+
...inputOptions,
|
|
129
143
|
disabled: options.disabled || !enabled(),
|
|
130
144
|
})
|
|
131
145
|
let disabled = options.disabled ?? false
|
|
132
|
-
const
|
|
146
|
+
const unwatch = watchPointerAvailability(pointer, input.target, runtime, onAvailabilityChange)
|
|
147
|
+
const refresh = () => {
|
|
148
|
+
pointer.update({ disabled: disabled || !enabled() })
|
|
149
|
+
unwatch.notify()
|
|
150
|
+
}
|
|
133
151
|
refreshes.set(pointer, refresh)
|
|
134
152
|
// The pointer owns its values; wrappers are borrowed by Mavis bindings.
|
|
135
153
|
const wrap = (value: WebReadableValue) => {
|
|
@@ -141,9 +159,12 @@ export function webMotionSurface(
|
|
|
141
159
|
x: wrap(pointer.x),
|
|
142
160
|
y: wrap(pointer.y),
|
|
143
161
|
presence: wrap(pointer.presence),
|
|
144
|
-
execution
|
|
145
|
-
|
|
146
|
-
|
|
162
|
+
get execution() {
|
|
163
|
+
return pointer.available ? ('hover' as const) : ('static' as const)
|
|
164
|
+
},
|
|
165
|
+
get available() {
|
|
166
|
+
return pointer.available
|
|
167
|
+
},
|
|
147
168
|
get active() {
|
|
148
169
|
return pointer.active
|
|
149
170
|
},
|
|
@@ -151,25 +172,47 @@ export function webMotionSurface(
|
|
|
151
172
|
disabled = state.disabled
|
|
152
173
|
refresh()
|
|
153
174
|
},
|
|
154
|
-
refresh: () =>
|
|
175
|
+
refresh: () => {
|
|
176
|
+
pointer.refresh()
|
|
177
|
+
unwatch.notify()
|
|
178
|
+
},
|
|
155
179
|
dispose() {
|
|
156
180
|
refreshes.delete(pointer)
|
|
157
|
-
|
|
181
|
+
try {
|
|
182
|
+
unwatch()
|
|
183
|
+
} finally {
|
|
184
|
+
pointer.dispose()
|
|
185
|
+
}
|
|
158
186
|
},
|
|
159
187
|
}
|
|
160
188
|
},
|
|
161
189
|
refresh: () => runtime.refresh(target),
|
|
162
|
-
scrollSection
|
|
163
|
-
|
|
190
|
+
scrollSection(source, section, frames, options) {
|
|
191
|
+
interrupt(Object.keys(frames))
|
|
192
|
+
const link = webSectionScroll(
|
|
164
193
|
owner,
|
|
165
194
|
webScrollElement(source),
|
|
166
195
|
webRegion(section).target,
|
|
167
196
|
target,
|
|
168
197
|
frames,
|
|
169
198
|
options,
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
|
|
199
|
+
)
|
|
200
|
+
sections.add(link)
|
|
201
|
+
return {
|
|
202
|
+
get execution() {
|
|
203
|
+
return link.execution
|
|
204
|
+
},
|
|
205
|
+
refresh: () => link.refresh(),
|
|
206
|
+
dispose() {
|
|
207
|
+
sections.delete(link)
|
|
208
|
+
link.dispose()
|
|
209
|
+
},
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
scrollLinked(source, frames, options) {
|
|
213
|
+
interrupt(Object.keys(frames))
|
|
214
|
+
return owner.scrollLinked(webScrollElement(source), target, frames, options)
|
|
215
|
+
},
|
|
173
216
|
map(source, input, output, options) {
|
|
174
217
|
const value = sources.get(source) ?? (source as WebReadableValue)
|
|
175
218
|
return 'map' in owner
|
|
@@ -180,9 +223,26 @@ export function webMotionSurface(
|
|
|
180
223
|
const value = sources.get(source) ?? (source as WebReadableValue)
|
|
181
224
|
return 'map' in owner ? owner.map(value, input, output) : value.to(input, output)
|
|
182
225
|
},
|
|
226
|
+
scalar(source, operation, operand, maximum) {
|
|
227
|
+
const value = sources.get(source) ?? (source as WebReadableValue)
|
|
228
|
+
if (operation === 'clamp') return value.clamp(operand as number, maximum!)
|
|
229
|
+
if (
|
|
230
|
+
operation === 'abs' ||
|
|
231
|
+
operation === 'sin' ||
|
|
232
|
+
operation === 'cos' ||
|
|
233
|
+
operation === 'velocity'
|
|
234
|
+
)
|
|
235
|
+
return value[operation]()
|
|
236
|
+
const right =
|
|
237
|
+
typeof operand === 'number'
|
|
238
|
+
? operand
|
|
239
|
+
: (sources.get(operand!) ?? (operand as WebReadableValue))
|
|
240
|
+
return value[operation](right)
|
|
241
|
+
},
|
|
242
|
+
readVelocity: (source) => (sources.get(source) ?? (source as WebReadableValue)).getVelocity(),
|
|
183
243
|
springValue(source, options) {
|
|
184
244
|
// Keep the runtime's private value identity; it rejects values from other contexts.
|
|
185
|
-
const spring = owner.springValue(source as
|
|
245
|
+
const spring = owner.springValue(sources.get(source) ?? (source as WebReadableValue), options)
|
|
186
246
|
const wrapper = {
|
|
187
247
|
get: () => spring.get(),
|
|
188
248
|
getVelocity: () => spring.getVelocity(),
|
|
@@ -205,19 +265,25 @@ export function webMotionSurface(
|
|
|
205
265
|
stopValue: (value, options) => runtime.stop(value as WebMotionValue, options),
|
|
206
266
|
playbackProgress: (handle) =>
|
|
207
267
|
owner.playbackProgress(handle as Parameters<WebRuntime['playbackProgress']>[0]),
|
|
208
|
-
decay
|
|
268
|
+
decay(velocity, options) {
|
|
269
|
+
interrupt(Object.keys(velocity))
|
|
270
|
+
return owner.decay(target, velocity, options)
|
|
271
|
+
},
|
|
209
272
|
animate(values, options) {
|
|
273
|
+
interrupt(Object.keys(values))
|
|
210
274
|
const playback = owner.animate(target, motionKeyframes(values), options)
|
|
211
275
|
takeShadow(target, values)
|
|
212
276
|
return playback
|
|
213
277
|
},
|
|
214
278
|
set(values) {
|
|
279
|
+
interrupt(Object.keys(values))
|
|
215
280
|
const playback = owner.set(target, values)
|
|
216
281
|
takeShadow(target, values)
|
|
217
282
|
return playback
|
|
218
283
|
},
|
|
219
284
|
motionValue: (initial) => owner.motionValue(initial),
|
|
220
285
|
bind(values) {
|
|
286
|
+
interrupt(Object.keys(values))
|
|
221
287
|
// Spring wrappers retain their public handle, rather than registering a second clock.
|
|
222
288
|
const binding = owner.bind(
|
|
223
289
|
target,
|
|
@@ -248,8 +314,13 @@ export function webMotionSurface(
|
|
|
248
314
|
}
|
|
249
315
|
},
|
|
250
316
|
drag(options) {
|
|
317
|
+
// An interactive Card owns input through its surface button. Jolt must treat that
|
|
318
|
+
// button as the handle, while translation still belongs to the surrounding card.
|
|
319
|
+
// Only a direct child qualifies: nested controls keep their own pointer input.
|
|
320
|
+
const handle = target.querySelector<HTMLElement>(':scope > .m-card-action') ?? undefined
|
|
251
321
|
const drag = owner.drag(target, {
|
|
252
322
|
...options,
|
|
323
|
+
handle,
|
|
253
324
|
disabled: !enabled(),
|
|
254
325
|
onRelease: options.onRelease
|
|
255
326
|
? (event) =>
|
package/src/motion.ts
CHANGED
|
@@ -42,6 +42,12 @@ export function attachWebPress(
|
|
|
42
42
|
}
|
|
43
43
|
if (applicationSurface()) observeGeometry()
|
|
44
44
|
const blocked = () => !enabled() || Boolean(target.closest('[inert], [aria-disabled="true"]'))
|
|
45
|
+
// MCard's action is a sibling of its controls, but feedback still transforms the whole card.
|
|
46
|
+
const ownsAction = (node: EventTarget | null) =>
|
|
47
|
+
node === target ||
|
|
48
|
+
(node instanceof window.Element &&
|
|
49
|
+
node.parentElement === target &&
|
|
50
|
+
node.classList.contains('m-card-action'))
|
|
45
51
|
const apply = () => {
|
|
46
52
|
const recipe = pressMotion(scale())[pressed ? 'pressed' : 'released']
|
|
47
53
|
observeGeometry()
|
|
@@ -85,7 +91,7 @@ export function attachWebPress(
|
|
|
85
91
|
)
|
|
86
92
|
return
|
|
87
93
|
for (const node of event.composedPath()) {
|
|
88
|
-
if (node
|
|
94
|
+
if (ownsAction(node)) break
|
|
89
95
|
if (
|
|
90
96
|
node instanceof window.Element &&
|
|
91
97
|
node.matches('button, a[href], input, select, textarea, [contenteditable], [role="button"]')
|
|
@@ -119,7 +125,7 @@ export function attachWebPress(
|
|
|
119
125
|
'keydown',
|
|
120
126
|
(event: KeyboardEvent) => {
|
|
121
127
|
if (
|
|
122
|
-
event.target
|
|
128
|
+
!ownsAction(event.target) ||
|
|
123
129
|
event.defaultPrevented ||
|
|
124
130
|
event.repeat ||
|
|
125
131
|
event.isComposing ||
|
|
@@ -143,9 +149,14 @@ export function attachWebPress(
|
|
|
143
149
|
},
|
|
144
150
|
true,
|
|
145
151
|
)
|
|
146
|
-
listen(
|
|
147
|
-
|
|
148
|
-
|
|
152
|
+
listen(
|
|
153
|
+
target,
|
|
154
|
+
'blur',
|
|
155
|
+
() => {
|
|
156
|
+
if (key) cancel()
|
|
157
|
+
},
|
|
158
|
+
true,
|
|
159
|
+
)
|
|
149
160
|
listen(window, 'blur', cancel)
|
|
150
161
|
listen(document, 'visibilitychange', () => {
|
|
151
162
|
if (document.hidden) cancel()
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { WebPointerFollow, WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
2
|
+
|
|
3
|
+
/** Observe inputs that can change Jolt's getter; Jolt alone decides availability and resets motion. */
|
|
4
|
+
export function watchPointerAvailability(
|
|
5
|
+
pointer: WebPointerFollow,
|
|
6
|
+
region: HTMLElement,
|
|
7
|
+
runtime: WebRuntime,
|
|
8
|
+
changed?: (available: boolean) => void,
|
|
9
|
+
) {
|
|
10
|
+
if (!changed) return Object.assign(() => {}, { notify() {} })
|
|
11
|
+
const document = region.ownerDocument
|
|
12
|
+
const view = document.defaultView!
|
|
13
|
+
let stopped = false,
|
|
14
|
+
queued = false,
|
|
15
|
+
previous: boolean | undefined
|
|
16
|
+
const notify = () => {
|
|
17
|
+
if (stopped || queued) return
|
|
18
|
+
queued = true
|
|
19
|
+
// Let Jolt process the same event first, including reduced-motion preferences.
|
|
20
|
+
queueMicrotask(() => {
|
|
21
|
+
queued = false
|
|
22
|
+
if (stopped) return
|
|
23
|
+
const available = pointer.available
|
|
24
|
+
if (available !== previous) changed((previous = available))
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
const hover = view.matchMedia('(any-hover: hover)')
|
|
28
|
+
hover.addEventListener('change', notify)
|
|
29
|
+
document.addEventListener('visibilitychange', notify)
|
|
30
|
+
const offReduced = runtime.onReducedMotion(notify)
|
|
31
|
+
const observer = new MutationObserver(notify)
|
|
32
|
+
observer.observe(document, { childList: true, subtree: true })
|
|
33
|
+
let ancestor: Element | null = region
|
|
34
|
+
while (ancestor) {
|
|
35
|
+
observer.observe(ancestor, {
|
|
36
|
+
attributes: true,
|
|
37
|
+
attributeFilter: ['disabled', 'aria-disabled', 'aria-busy', 'inert'],
|
|
38
|
+
})
|
|
39
|
+
ancestor = ancestor.parentElement ?? (ancestor.getRootNode() as ShadowRoot).host ?? null
|
|
40
|
+
}
|
|
41
|
+
notify()
|
|
42
|
+
return Object.assign(
|
|
43
|
+
() => {
|
|
44
|
+
if (stopped) return
|
|
45
|
+
stopped = true
|
|
46
|
+
observer.disconnect()
|
|
47
|
+
hover.removeEventListener('change', notify)
|
|
48
|
+
document.removeEventListener('visibilitychange', notify)
|
|
49
|
+
offReduced()
|
|
50
|
+
if (previous !== false) changed(false)
|
|
51
|
+
},
|
|
52
|
+
{ notify },
|
|
53
|
+
)
|
|
54
|
+
}
|
package/src/scroll-motion.ts
CHANGED
|
@@ -36,9 +36,19 @@ export function useScrollMotion(
|
|
|
36
36
|
const refresh = () => {
|
|
37
37
|
if (!disposed) reference.refresh()
|
|
38
38
|
}
|
|
39
|
+
let pendingFrame: number | undefined
|
|
40
|
+
const scheduleRefresh = () => {
|
|
41
|
+
if (disposed || pendingFrame !== undefined) return
|
|
42
|
+
pendingFrame = view.requestAnimationFrame(() => {
|
|
43
|
+
pendingFrame = undefined
|
|
44
|
+
refresh()
|
|
45
|
+
})
|
|
46
|
+
}
|
|
39
47
|
// A ScrollTimeline can become inactive when content no longer overflows. Rebase
|
|
40
48
|
// its retained pose on layout changes too, without observing values every frame.
|
|
41
|
-
|
|
49
|
+
// Source refresh also refreshes section links, which may replace their
|
|
50
|
+
// geometry observers. Never do that inside ResizeObserver delivery.
|
|
51
|
+
const resize = new view.ResizeObserver(scheduleRefresh)
|
|
42
52
|
const observed = new Set<Element>()
|
|
43
53
|
const observe = () => {
|
|
44
54
|
// Keep existing observations across text/subtree mutations. Re-observing an
|
|
@@ -57,19 +67,20 @@ export function useScrollMotion(
|
|
|
57
67
|
}
|
|
58
68
|
const mutations = new view.MutationObserver(() => {
|
|
59
69
|
observe()
|
|
60
|
-
|
|
70
|
+
scheduleRefresh()
|
|
61
71
|
})
|
|
62
72
|
observe()
|
|
63
73
|
mutations.observe(target, { childList: true, characterData: true, subtree: true })
|
|
64
|
-
target.ownerDocument.fonts?.addEventListener('loadingdone',
|
|
65
|
-
view.addEventListener('resize',
|
|
74
|
+
target.ownerDocument.fonts?.addEventListener('loadingdone', scheduleRefresh)
|
|
75
|
+
view.addEventListener('resize', scheduleRefresh)
|
|
66
76
|
release = () => {
|
|
67
77
|
disposed = true
|
|
78
|
+
if (pendingFrame !== undefined) view.cancelAnimationFrame(pendingFrame)
|
|
68
79
|
resize.disconnect()
|
|
69
80
|
observed.clear()
|
|
70
81
|
mutations.disconnect()
|
|
71
|
-
target.ownerDocument.fonts?.removeEventListener('loadingdone',
|
|
72
|
-
view.removeEventListener('resize',
|
|
82
|
+
target.ownerDocument.fonts?.removeEventListener('loadingdone', scheduleRefresh)
|
|
83
|
+
view.removeEventListener('resize', scheduleRefresh)
|
|
73
84
|
unbind()
|
|
74
85
|
sources.delete(adapter)
|
|
75
86
|
}
|
package/src/section-scroll.ts
CHANGED
|
@@ -19,6 +19,12 @@ export function webSectionScroll(
|
|
|
19
19
|
let link: ReturnType<WebMotionScope['scrollLinked']> | undefined
|
|
20
20
|
let previous = '',
|
|
21
21
|
disposed = false
|
|
22
|
+
const active = new Map(Object.entries(frames))
|
|
23
|
+
if (active.has('scale')) {
|
|
24
|
+
if (!active.has('scaleX')) active.set('scaleX', active.get('scale')!)
|
|
25
|
+
if (!active.has('scaleY')) active.set('scaleY', active.get('scale')!)
|
|
26
|
+
active.delete('scale')
|
|
27
|
+
}
|
|
22
28
|
const observed = new Set<Element>()
|
|
23
29
|
const refresh = () => {
|
|
24
30
|
if (disposed || !section.isConnected) return
|
|
@@ -38,17 +44,28 @@ export function webSectionScroll(
|
|
|
38
44
|
}
|
|
39
45
|
const values = measured.settled
|
|
40
46
|
? Object.fromEntries(
|
|
41
|
-
|
|
42
|
-
property,
|
|
43
|
-
[values.at(-1)!, values.at(-1)!],
|
|
44
|
-
]),
|
|
47
|
+
[...active].map(([property, values]) => [property, [values.at(-1)!, values.at(-1)!]]),
|
|
45
48
|
)
|
|
46
|
-
:
|
|
49
|
+
: Object.fromEntries(active)
|
|
47
50
|
link?.dispose()
|
|
48
|
-
link = owner.scrollLinked(source, target, values, {
|
|
51
|
+
link = owner.scrollLinked(source, target, values, {
|
|
52
|
+
range: measured.range,
|
|
53
|
+
execution: options.execution,
|
|
54
|
+
})
|
|
49
55
|
previous = key
|
|
50
56
|
}
|
|
51
|
-
|
|
57
|
+
// Replacing a Jolt link installs its geometry observers. Do that outside
|
|
58
|
+
// ResizeObserver delivery so WebKit cannot deliver the new observer in the
|
|
59
|
+
// same resize cycle, and coalesce content and geometry invalidations.
|
|
60
|
+
let pendingFrame: number | undefined
|
|
61
|
+
const scheduleRefresh = () => {
|
|
62
|
+
if (disposed || pendingFrame !== undefined) return
|
|
63
|
+
pendingFrame = view.requestAnimationFrame(() => {
|
|
64
|
+
pendingFrame = undefined
|
|
65
|
+
refresh()
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
const resize = new view.ResizeObserver(scheduleRefresh)
|
|
52
69
|
const observe = () => {
|
|
53
70
|
const wanted = new Set<Element>([source, ...source.children])
|
|
54
71
|
for (
|
|
@@ -69,24 +86,27 @@ export function webSectionScroll(
|
|
|
69
86
|
resize.observe(node)
|
|
70
87
|
observed.add(node)
|
|
71
88
|
}
|
|
72
|
-
|
|
89
|
+
scheduleRefresh()
|
|
73
90
|
}
|
|
74
91
|
const mutations = new view.MutationObserver(observe)
|
|
75
92
|
const dispose = () => {
|
|
76
93
|
if (disposed) return
|
|
77
94
|
disposed = true
|
|
95
|
+
if (pendingFrame !== undefined) view.cancelAnimationFrame(pendingFrame)
|
|
78
96
|
resize.disconnect()
|
|
79
97
|
mutations.disconnect()
|
|
80
98
|
observed.clear()
|
|
81
|
-
view.removeEventListener('resize',
|
|
82
|
-
source.ownerDocument.fonts?.removeEventListener('loadingdone',
|
|
99
|
+
view.removeEventListener('resize', scheduleRefresh)
|
|
100
|
+
source.ownerDocument.fonts?.removeEventListener('loadingdone', scheduleRefresh)
|
|
83
101
|
link?.dispose()
|
|
84
102
|
}
|
|
85
103
|
try {
|
|
86
104
|
observe()
|
|
105
|
+
// Initial execution is observable immediately to the shared controller.
|
|
106
|
+
refresh()
|
|
87
107
|
mutations.observe(source, { childList: true, characterData: true, subtree: true })
|
|
88
|
-
view.addEventListener('resize',
|
|
89
|
-
source.ownerDocument.fonts?.addEventListener('loadingdone',
|
|
108
|
+
view.addEventListener('resize', scheduleRefresh)
|
|
109
|
+
source.ownerDocument.fonts?.addEventListener('loadingdone', scheduleRefresh)
|
|
90
110
|
} catch (error) {
|
|
91
111
|
dispose()
|
|
92
112
|
throw error
|
|
@@ -96,6 +116,12 @@ export function webSectionScroll(
|
|
|
96
116
|
return disposed ? ('released' as const) : (link?.execution ?? ('released' as const))
|
|
97
117
|
},
|
|
98
118
|
refresh,
|
|
119
|
+
interrupt(properties: readonly string[]) {
|
|
120
|
+
for (const property of properties)
|
|
121
|
+
for (const key of property === 'scale' ? ['scaleX', 'scaleY'] : [property])
|
|
122
|
+
active.delete(key)
|
|
123
|
+
if (!active.size) dispose()
|
|
124
|
+
},
|
|
99
125
|
dispose,
|
|
100
126
|
}
|
|
101
127
|
}
|