@getcortexlabs/mavis-web 0.1.0-rc.12.2 → 0.1.0-rc.14

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.
Files changed (110) hide show
  1. package/README.md +4 -4
  2. package/dist/animated-number.d.ts.map +1 -1
  3. package/dist/animated-number.js +8 -10
  4. package/dist/animated-number.js.map +1 -1
  5. package/dist/component-motion.d.ts.map +1 -1
  6. package/dist/component-motion.js +26 -3
  7. package/dist/component-motion.js.map +1 -1
  8. package/dist/components/ChartPlot.d.ts +8 -0
  9. package/dist/components/ChartPlot.d.ts.map +1 -1
  10. package/dist/components/ChartPlot.js +30 -8
  11. package/dist/components/ChartPlot.js.map +1 -1
  12. package/dist/components/DateCalendar.d.ts +1 -1
  13. package/dist/components/DateCalendar.d.ts.map +1 -1
  14. package/dist/components/DateCalendar.js +3 -1
  15. package/dist/components/DateCalendar.js.map +1 -1
  16. package/dist/components/MButton.d.ts +7 -7
  17. package/dist/components/MCard.d.ts.map +1 -1
  18. package/dist/components/MCard.js +68 -21
  19. package/dist/components/MCard.js.map +1 -1
  20. package/dist/components/MChip.d.ts +1 -1
  21. package/dist/components/MDatePicker.d.ts +96 -96
  22. package/dist/components/MDatePicker.d.ts.map +1 -1
  23. package/dist/components/MEmptyState.d.ts +1 -1
  24. package/dist/components/MInput.d.ts +5 -5
  25. package/dist/components/MInput.d.ts.map +1 -1
  26. package/dist/components/MInput.js +16 -4
  27. package/dist/components/MInput.js.map +1 -1
  28. package/dist/components/MLink.d.ts +1 -1
  29. package/dist/components/MPopover.d.ts +1 -1
  30. package/dist/components/MProgress.d.ts +1 -1
  31. package/dist/components/MRangeSlider.d.ts +2 -2
  32. package/dist/components/MResizablePanels.d.ts +2 -2
  33. package/dist/components/MReveal.d.ts +10 -10
  34. package/dist/components/MSheet.d.ts +5 -5
  35. package/dist/components/MSlider.d.ts +2 -2
  36. package/dist/components/MStack.d.ts +10 -10
  37. package/dist/components/MTimePicker.d.ts +40 -40
  38. package/dist/components/MTimePicker.d.ts.map +1 -1
  39. package/dist/components/MTooltip.d.ts +1 -1
  40. package/dist/components/MVirtualList.d.ts.map +1 -1
  41. package/dist/components/MVirtualList.js +111 -40
  42. package/dist/components/MVirtualList.js.map +1 -1
  43. package/dist/components/advanced.d.ts +34 -34
  44. package/dist/components/configurator.d.ts +33 -33
  45. package/dist/components/creative.d.ts +20 -20
  46. package/dist/components/creative.d.ts.map +1 -1
  47. package/dist/components/creative.js +7 -5
  48. package/dist/components/creative.js.map +1 -1
  49. package/dist/components/dashboard.d.ts +12 -12
  50. package/dist/components/dashboard.d.ts.map +1 -1
  51. package/dist/components/dashboard.js +144 -79
  52. package/dist/components/dashboard.js.map +1 -1
  53. package/dist/components/discovery.d.ts +10 -10
  54. package/dist/components/interactive.d.ts +6 -6
  55. package/dist/components/layout.d.ts +41 -30
  56. package/dist/components/layout.d.ts.map +1 -1
  57. package/dist/components/layout.js +8 -1
  58. package/dist/components/layout.js.map +1 -1
  59. package/dist/components/navigation.d.ts +4 -4
  60. package/dist/components/screen-components.d.ts +23 -23
  61. package/dist/components/wayfinding.d.ts +11 -11
  62. package/dist/components/workflows.d.ts +5 -5
  63. package/dist/experimental.d.ts +8 -0
  64. package/dist/experimental.d.ts.map +1 -1
  65. package/dist/experimental.js +17 -0
  66. package/dist/experimental.js.map +1 -1
  67. package/dist/motion-region.d.ts.map +1 -1
  68. package/dist/motion-region.js +1 -0
  69. package/dist/motion-region.js.map +1 -1
  70. package/dist/motion-surface.d.ts +12 -6
  71. package/dist/motion-surface.d.ts.map +1 -1
  72. package/dist/motion-surface.js +94 -17
  73. package/dist/motion-surface.js.map +1 -1
  74. package/dist/motion.d.ts.map +1 -1
  75. package/dist/motion.js +8 -3
  76. package/dist/motion.js.map +1 -1
  77. package/dist/reduced-motion.d.ts +10 -0
  78. package/dist/reduced-motion.d.ts.map +1 -0
  79. package/dist/reduced-motion.js +26 -0
  80. package/dist/reduced-motion.js.map +1 -0
  81. package/dist/scroll-motion.d.ts.map +1 -1
  82. package/dist/scroll-motion.js +19 -6
  83. package/dist/scroll-motion.js.map +1 -1
  84. package/dist/section-scroll.d.ts +2 -1
  85. package/dist/section-scroll.d.ts.map +1 -1
  86. package/dist/section-scroll.js +43 -12
  87. package/dist/section-scroll.js.map +1 -1
  88. package/dist/visual-effects.d.ts.map +1 -1
  89. package/dist/visual-effects.js +14 -1
  90. package/dist/visual-effects.js.map +1 -1
  91. package/package.json +3 -3
  92. package/src/animated-number.ts +7 -9
  93. package/src/base.css +43 -1
  94. package/src/component-motion.ts +26 -2
  95. package/src/components/ChartPlot.ts +29 -10
  96. package/src/components/DateCalendar.ts +3 -1
  97. package/src/components/MCard.ts +81 -20
  98. package/src/components/MInput.ts +13 -4
  99. package/src/components/MVirtualList.ts +107 -29
  100. package/src/components/creative.ts +7 -5
  101. package/src/components/dashboard.ts +140 -80
  102. package/src/components/layout.ts +8 -1
  103. package/src/experimental.ts +20 -0
  104. package/src/motion-region.ts +1 -0
  105. package/src/motion-surface.ts +104 -22
  106. package/src/motion.ts +16 -5
  107. package/src/reduced-motion.ts +30 -0
  108. package/src/scroll-motion.ts +17 -6
  109. package/src/section-scroll.ts +38 -12
  110. package/src/visual-effects.ts +12 -1
@@ -24,9 +24,14 @@ import {
24
24
  kanbanRegistryKey,
25
25
  kanbanZoneProps,
26
26
  kanbanDragProps,
27
+ type KanbanRegistry,
27
28
  } from '@getcortexlabs/mavis-core/vue'
29
+ import type { WebRuntime } from '@rafaelaugusto/jolt/web'
28
30
  import { createMotionSurface } from '@getcortexlabs/mavis-core/experimental'
29
31
  import { MBox, MColumn, MRow } from './layout.js'
32
+ import { useMotionContext } from '../motion-context.js'
33
+ import { useConnectedMotion } from '../connected-motion.js'
34
+ import { followReducedMotion } from '../reduced-motion.js'
30
35
  import { MStack } from './MStack.js'
31
36
  import { MText } from './MText.js'
32
37
  import { MButton } from './MButton.js'
@@ -77,19 +82,19 @@ const Environment = defineComponent({
77
82
  const root = ref<HTMLElement>()
78
83
  let attached = false,
79
84
  visible = true,
80
- media: MediaQueryList | undefined,
85
+ follow: ReturnType<typeof followReducedMotion> | undefined,
81
86
  observer: IntersectionObserver | undefined
87
+ const context = useMotionContext()
82
88
  function update() {
83
89
  emit('environment', {
84
- reduced: media?.matches ?? true,
90
+ reduced: follow?.reduced ?? true,
85
91
  paused: !attached || document.hidden || !visible,
86
92
  })
87
93
  }
88
94
  function connect() {
89
95
  if (attached || !root.value) return
90
96
  attached = true
91
- media = matchMedia('(prefers-reduced-motion: reduce)')
92
- media.addEventListener('change', update)
97
+ follow = followReducedMotion(context, root.value.ownerDocument, update)
93
98
  document.addEventListener('visibilitychange', update)
94
99
  observer = new IntersectionObserver(([entry]) => {
95
100
  const next = entry?.isIntersecting ?? false
@@ -103,7 +108,7 @@ const Environment = defineComponent({
103
108
  }
104
109
  function disconnect() {
105
110
  attached = false
106
- media?.removeEventListener('change', update)
111
+ follow?.release()
107
112
  observer?.disconnect()
108
113
  document.removeEventListener('visibilitychange', update)
109
114
  update()
@@ -124,10 +129,16 @@ const Zone = defineComponent({
124
129
  inheritAttrs: false,
125
130
  props: kanbanZoneProps,
126
131
  setup(props, { attrs, slots }) {
127
- const registry = inject(kanbanRegistryKey)!,
132
+ const registry = inject(kanbanRegistryKey)! as KanbanRegistry<HTMLElement>,
128
133
  root = ref<HTMLElement>()
129
- onMounted(() => registry.zones.set(props.column, () => root.value?.getBoundingClientRect()))
130
- onBeforeUnmount(() => registry.zones.delete(props.column))
134
+ onMounted(() => {
135
+ registry.zones.set(props.column, root.value!)
136
+ registry.revision.value++
137
+ })
138
+ onBeforeUnmount(() => {
139
+ registry.zones.delete(props.column)
140
+ registry.revision.value++
141
+ })
131
142
  return () =>
132
143
  h(
133
144
  'div',
@@ -140,38 +151,117 @@ const Drag = defineComponent({
140
151
  inheritAttrs: false,
141
152
  props: kanbanDragProps,
142
153
  setup(props, { attrs, slots }) {
143
- const registry = inject(kanbanRegistryKey)!,
154
+ const registry = inject(kanbanRegistryKey)! as KanbanRegistry<HTMLElement>,
144
155
  root = ref<HTMLElement>(),
145
156
  surface = markRaw(createMotionSurface()),
146
157
  dragging = ref(false)
147
- let pointer: number | undefined,
148
- anchor: DOMRect | undefined,
149
- startX = 0,
150
- startY = 0,
151
- handle: HTMLElement | undefined
152
- function end(commit = false) {
153
- const was = dragging.value
154
- dragging.value = false
155
- const id = pointer
156
- pointer = undefined
157
- if (id !== undefined && handle?.hasPointerCapture(id)) handle.releasePointerCapture(id)
158
- window.removeEventListener('keydown', escape)
159
- window.removeEventListener('scroll', cancel, true)
160
- window.removeEventListener('resize', cancel)
161
- if (surface.available) {
162
- if (props.animated && !commit)
163
- surface.animate({ x: 0, y: 0, scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
164
- else surface.set({ x: 0, y: 0, scale: 1 })
165
- }
166
- if (was) registry.finish(commit)
167
- }
168
- const cancel = () => end(false)
158
+ let runtime: WebRuntime | undefined,
159
+ zones: ReturnType<WebRuntime['dropZones']> | undefined,
160
+ live = false
169
161
  const escape = (e: KeyboardEvent) => {
170
162
  if (e.key === 'Escape') {
171
163
  e.preventDefault()
172
164
  cancel()
173
165
  }
174
166
  }
167
+ // Jolt cancels on these and leaves the card where it was; the board brings it back.
168
+ const interrupted = () => {
169
+ if (live) cancel()
170
+ }
171
+ function watchInput(on: boolean) {
172
+ const listen = on ? 'addEventListener' : 'removeEventListener'
173
+ window[listen]('keydown', escape as EventListener)
174
+ window[listen]('blur', interrupted)
175
+ window[listen]('resize', interrupted)
176
+ window[listen]('scroll', interrupted, true)
177
+ document[listen]('visibilitychange', interrupted)
178
+ }
179
+ function settle() {
180
+ if (live) watchInput(false)
181
+ live = false
182
+ dragging.value = false
183
+ }
184
+ function rest(animated: boolean) {
185
+ if (!surface.available) return
186
+ if (animated && props.animated)
187
+ surface.animate({ x: 0, y: 0, scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
188
+ else surface.set({ x: 0, y: 0, scale: 1 })
189
+ }
190
+ function cancel() {
191
+ const was = live
192
+ settle()
193
+ zones?.cancel()
194
+ if (!was) return
195
+ rest(true)
196
+ registry.finish(props.cardId)
197
+ }
198
+ function release() {
199
+ zones?.dispose()
200
+ zones = undefined
201
+ }
202
+ // Jolt refuses a drag under a transformed ancestor, so each contact gets fresh drop zones,
203
+ // after ending the layout motion that may still be moving the card's column.
204
+ function attach(handle: HTMLElement) {
205
+ if (live) return
206
+ release()
207
+ const source = root.value?.firstElementChild
208
+ if (!runtime || !(source instanceof HTMLElement)) return
209
+ for (let node = source.parentElement; node?.parentElement; node = node.parentElement) {
210
+ if (!new DOMMatrixReadOnly(getComputedStyle(node).transform).isIdentity)
211
+ runtime.animateLayout(node.parentElement).stop()
212
+ if (node.classList.contains('m-kanban')) break
213
+ }
214
+ const targets = registry.targets(props.cardId)
215
+ if (!targets.length) return
216
+ try {
217
+ zones = runtime.dropZones(source, {
218
+ targets,
219
+ drag: { handle, snap: [0] },
220
+ onMove({ id, bounds }) {
221
+ if (!live) {
222
+ if (!registry.begin(props.cardId, cancel)) {
223
+ zones?.cancel()
224
+ return
225
+ }
226
+ live = true
227
+ dragging.value = true
228
+ watchInput(true)
229
+ if (surface.available) surface.set({ scale: 1.02 })
230
+ }
231
+ registry.move(id, bounds)
232
+ },
233
+ onLeave: () => registry.leave(),
234
+ onDrop() {
235
+ settle()
236
+ rest(false)
237
+ registry.drop()
238
+ },
239
+ onReject() {
240
+ settle()
241
+ registry.finish(props.cardId)
242
+ if (!surface.available) return
243
+ if (props.animated)
244
+ surface.animate({ scale: 1 }, { type: 'spring', duration: 280, bounce: 0.12 })
245
+ // Jolt starts its return after this callback; without motion the card goes back at once.
246
+ else
247
+ queueMicrotask(() => {
248
+ zones?.cancel()
249
+ rest(false)
250
+ })
251
+ },
252
+ })
253
+ } catch {
254
+ zones = undefined
255
+ }
256
+ }
257
+ useConnectedMotion(root, useMotionContext(), (owner) => {
258
+ runtime = owner
259
+ return () => {
260
+ cancel()
261
+ release()
262
+ runtime = undefined
263
+ }
264
+ })
175
265
  onMounted(() => {
176
266
  registry.cards.set(props.cardId, () => root.value?.getBoundingClientRect())
177
267
  registry.focus.set(props.cardId, () =>
@@ -186,15 +276,12 @@ const Drag = defineComponent({
186
276
  registry.focus.delete(props.cardId)
187
277
  })
188
278
  onDeactivated(cancel)
189
- onScopeDispose(
190
- surface.use(() => () => {
191
- if (dragging.value) cancel()
192
- }),
193
- )
194
279
  watch(
195
280
  () => props.disabled,
196
281
  (value) => {
197
- if (value) cancel()
282
+ if (!value) return
283
+ cancel()
284
+ release()
198
285
  },
199
286
  )
200
287
  return () =>
@@ -204,6 +291,19 @@ const Drag = defineComponent({
204
291
  ref: root,
205
292
  'data-kanban-card': props.cardId,
206
293
  style: { position: 'relative', zIndex: dragging.value ? 20 : undefined },
294
+ onPointerdownCapture: (e: PointerEvent) => {
295
+ const handle =
296
+ e.target instanceof Element ? e.target.closest('[data-kanban-handle]') : null
297
+ if (
298
+ !(handle instanceof HTMLElement) ||
299
+ props.disabled ||
300
+ e.button !== 0 ||
301
+ !e.isPrimary
302
+ )
303
+ return
304
+ handle.focus({ preventScroll: true })
305
+ attach(handle)
306
+ },
207
307
  }),
208
308
  [
209
309
  h(MBox, { motionSurface: surface }, () =>
@@ -226,49 +326,9 @@ const Drag = defineComponent({
226
326
  border: '0',
227
327
  opacity: props.disabled ? 0.4 : 0.65,
228
328
  },
229
- onPointerdown: (e: PointerEvent) => {
230
- if (props.disabled || e.button !== 0 || !e.isPrimary || pointer !== undefined)
231
- return
232
- e.preventDefault()
233
- handle = e.currentTarget as HTMLElement
234
- handle.focus({ preventScroll: true })
235
- pointer = e.pointerId
236
- startX = e.clientX
237
- startY = e.clientY
238
- handle.setPointerCapture(pointer)
239
- window.addEventListener('keydown', escape)
240
- window.addEventListener('scroll', cancel, true)
241
- window.addEventListener('resize', cancel)
242
- },
243
- onPointermove: (e: PointerEvent) => {
244
- if (e.pointerId !== pointer) return
245
- const x = e.clientX - startX,
246
- y = e.clientY - startY
247
- if (!dragging.value && Math.hypot(x, y) >= 6) {
248
- if (!registry.begin(props.cardId, cancel)) {
249
- cancel()
250
- return
251
- }
252
- anchor = root.value?.getBoundingClientRect()
253
- dragging.value = true
254
- }
255
- if (dragging.value && surface.available) {
256
- const current = root.value?.getBoundingClientRect()
257
- surface.set({
258
- x: x + (anchor && current ? anchor.x - current.x : 0),
259
- y: y + (anchor && current ? anchor.y - current.y : 0),
260
- scale: 1.02,
261
- })
262
- registry.move(x, y)
263
- }
264
- },
265
- onPointerup: (e: PointerEvent) => {
266
- if (e.pointerId === pointer) end(true)
267
- },
268
- onPointercancel: cancel,
269
- onLostpointercapture: () => {
270
- if (pointer !== undefined) cancel()
271
- },
329
+ onLostpointercapture: interrupted,
330
+ // Safari moves focus to the page on mouse down; the grip keeps it for the arrow keys.
331
+ onMousedown: (e: MouseEvent) => e.preventDefault(),
272
332
  onKeydown: (e: KeyboardEvent) => {
273
333
  const direction = (
274
334
  {
@@ -9,6 +9,7 @@ import {
9
9
  } from '@getcortexlabs/mavis-core/vue'
10
10
  import { defineComponent, h, mergeProps, provide } from 'vue'
11
11
  import { resolveSpace } from '@getcortexlabs/mavis-core'
12
+ import { resolvePerspective } from '@getcortexlabs/mavis-core/experimental'
12
13
  import { boxStyle, webAttrs } from '../style.js'
13
14
  import { useMotionRegion } from '../motion-region.js'
14
15
  import { useMotionSurface } from '../use-motion-surface.js'
@@ -80,7 +81,13 @@ export const MBox = defineComponent({
80
81
  mergeProps(
81
82
  {
82
83
  class: 'm-box',
83
- style: { ...boxStyle(theme.value, props, shrink.value), display: 'grid' },
84
+ style: {
85
+ ...boxStyle(theme.value, props, shrink.value),
86
+ display: 'grid',
87
+ ...(props.perspective === undefined
88
+ ? {}
89
+ : { perspective: `${resolvePerspective(props.perspective)}px` }),
90
+ },
84
91
  },
85
92
  webAttrs({ ...attrs, ...viewAttrs(props) }),
86
93
  region,
@@ -35,3 +35,23 @@ export function useMavisWebMotion(
35
35
  onScopeDispose(stop)
36
36
  return stop
37
37
  }
38
+
39
+ /**
40
+ * Web-only: the region's own policy for reduced motion. `user` follows the system. Components
41
+ * inside the region read the same effective preference, and it returns to `user` when the
42
+ * region leaves the document or the returned function is called.
43
+ */
44
+ export function configureMavisWebMotion(
45
+ region: MotionRegion,
46
+ options: { reducedMotion: 'user' | 'always' | 'never' },
47
+ ): () => void {
48
+ if (!['user', 'always', 'never'].includes(options?.reducedMotion))
49
+ throw new RangeError('reducedMotion must be user, always or never.')
50
+ const stop = region.onAvailable(() => {
51
+ const { runtime } = webRegion(regionState(region).adapter)
52
+ runtime.configure({ reducedMotion: options.reducedMotion })
53
+ return () => runtime.configure({ reducedMotion: 'user' })
54
+ })
55
+ if (getCurrentScope()) onScopeDispose(stop)
56
+ return stop
57
+ }
@@ -42,6 +42,7 @@ function regionAdapter(runtime: WebRuntime, target: HTMLElement): MotionRegionAd
42
42
  : ([resolve(step[0]), step[1], step[2]] as const),
43
43
  )
44
44
  const adapter: MotionRegionAdapter = {
45
+ // Jolt owns the Vue flush boundary and bounded leaving copies, including interruption.
45
46
  animateLayout: (change, { transition, ...options }) =>
46
47
  runtime.animateLayout(target, change, { ...transition, ...options }),
47
48
  ...webPlatformMotion(runtime, target, resolve),
@@ -6,7 +6,7 @@ import type {
6
6
  WebMotionScope,
7
7
  WebMotionValue,
8
8
  } from '@rafaelaugusto/jolt/web'
9
- import type { MotionSurfaceAdapter } from '@getcortexlabs/mavis-core/experimental'
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
12
 
@@ -18,16 +18,32 @@ const paintKeys = new Set([
18
18
  'borderRadius',
19
19
  'borderWidth',
20
20
  ])
21
- /** Vue may rerender slots while an application value owns paint on this element. */
22
- export function preserveBoundPaint(target: HTMLElement | undefined) {
23
- return target
24
- ? Object.fromEntries(
25
- [...(boundPaint.get(target)?.keys() ?? [])].map((key) => [
26
- key,
27
- target.style[key as 'backgroundColor'],
28
- ]),
29
- )
30
- : {}
21
+ // The shadow the component declared when application motion took it, and the last one rendered.
22
+ const movedShadow = new WeakMap<HTMLElement, string | undefined>()
23
+ const declaredShadow = new WeakMap<HTMLElement, string | undefined>()
24
+ /**
25
+ * Vue may rerender slots while an application value owns paint on this element. A shadow the
26
+ * application animated stays until the component declares a different one: then the theme wins.
27
+ */
28
+ export function preserveBoundPaint(target: HTMLElement | undefined, shadow?: string) {
29
+ if (!target) return {}
30
+ const paint: Record<string, string> = Object.fromEntries(
31
+ [...(boundPaint.get(target)?.keys() ?? [])].map((key) => [
32
+ key,
33
+ target.style[key as 'backgroundColor'],
34
+ ]),
35
+ )
36
+ if (movedShadow.has(target)) {
37
+ const current = target.style.boxShadow
38
+ if (movedShadow.get(target) !== shadow) movedShadow.delete(target)
39
+ else if (current && current !== shadow) paint.boxShadow = current
40
+ }
41
+ declaredShadow.set(target, shadow)
42
+ return paint
43
+ }
44
+ const takeShadow = (target: HTMLElement, values: object) => {
45
+ if (!movedShadow.has(target) && Object.keys(values).some((key) => key.startsWith('shadow')))
46
+ movedShadow.set(target, declaredShadow.get(target))
31
47
  }
32
48
 
33
49
  const targets = new WeakMap<MotionSurfaceAdapter, { runtime: WebRuntime; target: HTMLElement }>()
@@ -46,7 +62,11 @@ export function webMotionSurface(
46
62
  sources = new WeakMap<object, WebReadableValue>(),
47
63
  refreshes = new Map<object, () => void>(),
48
64
  plainText: () => boolean = () => false,
65
+ sections = new Set<ReturnType<typeof webSectionScroll>>(),
49
66
  ) {
67
+ const interrupt = (properties: readonly string[]) => {
68
+ for (const section of sections) section.interrupt(properties)
69
+ }
50
70
  const adapter: MotionSurfaceAdapter = {
51
71
  ...webVisualEffects(owner, target, sources, plainText),
52
72
  sensor(kind, options) {
@@ -94,8 +114,16 @@ export function webMotionSurface(
94
114
  try {
95
115
  scope.use((child) =>
96
116
  setup(
97
- webMotionSurface(runtime, target, enabled, child, sources, refreshes, plainText)
98
- .adapter,
117
+ webMotionSurface(
118
+ runtime,
119
+ target,
120
+ enabled,
121
+ child,
122
+ sources,
123
+ refreshes,
124
+ plainText,
125
+ sections,
126
+ ).adapter,
99
127
  ),
100
128
  )
101
129
  } catch (error) {
@@ -124,7 +152,10 @@ export function webMotionSurface(
124
152
  return {
125
153
  x: wrap(pointer.x),
126
154
  y: wrap(pointer.y),
155
+ presence: wrap(pointer.presence),
127
156
  execution: 'hover',
157
+ // Pointer events exist in every browser; whether a mouse is connected is not known.
158
+ available: true,
128
159
  get active() {
129
160
  return pointer.active
130
161
  },
@@ -140,17 +171,32 @@ export function webMotionSurface(
140
171
  }
141
172
  },
142
173
  refresh: () => runtime.refresh(target),
143
- scrollSection: (source, section, frames, options) =>
144
- webSectionScroll(
174
+ scrollSection(source, section, frames, options) {
175
+ interrupt(Object.keys(frames))
176
+ const link = webSectionScroll(
145
177
  owner,
146
178
  webScrollElement(source),
147
179
  webRegion(section).target,
148
180
  target,
149
181
  frames,
150
182
  options,
151
- ),
152
- scrollLinked: (source, frames, options) =>
153
- owner.scrollLinked(webScrollElement(source), target, frames, options),
183
+ )
184
+ sections.add(link)
185
+ return {
186
+ get execution() {
187
+ return link.execution
188
+ },
189
+ refresh: () => link.refresh(),
190
+ dispose() {
191
+ sections.delete(link)
192
+ link.dispose()
193
+ },
194
+ }
195
+ },
196
+ scrollLinked(source, frames, options) {
197
+ interrupt(Object.keys(frames))
198
+ return owner.scrollLinked(webScrollElement(source), target, frames, options)
199
+ },
154
200
  map(source, input, output, options) {
155
201
  const value = sources.get(source) ?? (source as WebReadableValue)
156
202
  return 'map' in owner
@@ -161,9 +207,26 @@ export function webMotionSurface(
161
207
  const value = sources.get(source) ?? (source as WebReadableValue)
162
208
  return 'map' in owner ? owner.map(value, input, output) : value.to(input, output)
163
209
  },
210
+ scalar(source, operation, operand, maximum) {
211
+ const value = sources.get(source) ?? (source as WebReadableValue)
212
+ if (operation === 'clamp') return value.clamp(operand as number, maximum!)
213
+ if (
214
+ operation === 'abs' ||
215
+ operation === 'sin' ||
216
+ operation === 'cos' ||
217
+ operation === 'velocity'
218
+ )
219
+ return value[operation]()
220
+ const right =
221
+ typeof operand === 'number'
222
+ ? operand
223
+ : (sources.get(operand!) ?? (operand as WebReadableValue))
224
+ return value[operation](right)
225
+ },
226
+ readVelocity: (source) => (sources.get(source) ?? (source as WebReadableValue)).getVelocity(),
164
227
  springValue(source, options) {
165
228
  // Keep the runtime's private value identity; it rejects values from other contexts.
166
- const spring = owner.springValue(source as ReturnType<WebRuntime['motionValue']>, options)
229
+ const spring = owner.springValue(sources.get(source) ?? (source as WebReadableValue), options)
167
230
  const wrapper = {
168
231
  get: () => spring.get(),
169
232
  getVelocity: () => spring.getVelocity(),
@@ -186,11 +249,25 @@ export function webMotionSurface(
186
249
  stopValue: (value, options) => runtime.stop(value as WebMotionValue, options),
187
250
  playbackProgress: (handle) =>
188
251
  owner.playbackProgress(handle as Parameters<WebRuntime['playbackProgress']>[0]),
189
- decay: (velocity, options) => owner.decay(target, velocity, options),
190
- animate: (values, options) => owner.animate(target, values, options),
191
- set: (values) => owner.set(target, values),
252
+ decay(velocity, options) {
253
+ interrupt(Object.keys(velocity))
254
+ return owner.decay(target, velocity, options)
255
+ },
256
+ animate(values, options) {
257
+ interrupt(Object.keys(values))
258
+ const playback = owner.animate(target, motionKeyframes(values), options)
259
+ takeShadow(target, values)
260
+ return playback
261
+ },
262
+ set(values) {
263
+ interrupt(Object.keys(values))
264
+ const playback = owner.set(target, values)
265
+ takeShadow(target, values)
266
+ return playback
267
+ },
192
268
  motionValue: (initial) => owner.motionValue(initial),
193
269
  bind(values) {
270
+ interrupt(Object.keys(values))
194
271
  // Spring wrappers retain their public handle, rather than registering a second clock.
195
272
  const binding = owner.bind(
196
273
  target,
@@ -221,8 +298,13 @@ export function webMotionSurface(
221
298
  }
222
299
  },
223
300
  drag(options) {
301
+ // An interactive Card owns input through its surface button. Jolt must treat that
302
+ // button as the handle, while translation still belongs to the surrounding card.
303
+ // Only a direct child qualifies: nested controls keep their own pointer input.
304
+ const handle = target.querySelector<HTMLElement>(':scope > .m-card-action') ?? undefined
224
305
  const drag = owner.drag(target, {
225
306
  ...options,
307
+ handle,
226
308
  disabled: !enabled(),
227
309
  onRelease: options.onRelease
228
310
  ? (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 === target) break
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 !== 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(target, 'blur', () => {
147
- if (key) cancel()
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,30 @@
1
+ import type { WebMotionContext } from './motion-context.js'
2
+
3
+ /**
4
+ * The effective preference of the region's runtime: the system's, unless the runtime was
5
+ * configured to always or never reduce. The lease keeps that runtime alive while observed.
6
+ */
7
+ export function followReducedMotion(
8
+ context: WebMotionContext,
9
+ document: Document,
10
+ changed: () => void,
11
+ ) {
12
+ const lease = context.acquire(document)
13
+ let last = lease.runtime.reducedMotion()
14
+ let off: (() => void) | undefined = lease.runtime.onReducedMotion((reduced) => {
15
+ last = reduced
16
+ changed()
17
+ })
18
+ return {
19
+ get reduced() {
20
+ return off ? (last = lease.runtime.reducedMotion()) : last
21
+ },
22
+ release() {
23
+ if (!off) return
24
+ last = lease.runtime.reducedMotion()
25
+ off()
26
+ off = undefined
27
+ lease.release()
28
+ },
29
+ }
30
+ }
@@ -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
- const resize = new view.ResizeObserver(refresh)
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
- refresh()
70
+ scheduleRefresh()
61
71
  })
62
72
  observe()
63
73
  mutations.observe(target, { childList: true, characterData: true, subtree: true })
64
- target.ownerDocument.fonts?.addEventListener('loadingdone', refresh)
65
- view.addEventListener('resize', refresh)
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', refresh)
72
- view.removeEventListener('resize', refresh)
82
+ target.ownerDocument.fonts?.removeEventListener('loadingdone', scheduleRefresh)
83
+ view.removeEventListener('resize', scheduleRefresh)
73
84
  unbind()
74
85
  sources.delete(adapter)
75
86
  }