@getcortexlabs/mavis-web 0.1.0-alpha.5 → 0.1.0-alpha.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 +4 -4
- package/dist/components/ChoicePaint.d.ts +17 -0
- package/dist/components/ChoicePaint.d.ts.map +1 -0
- package/dist/components/ChoicePaint.js +81 -0
- package/dist/components/ChoicePaint.js.map +1 -0
- package/dist/components/DateCalendar.d.ts +3 -3
- package/dist/components/MAccordion.d.ts +1 -1
- package/dist/components/MAlert.d.ts +1 -1
- package/dist/components/MAvatar.d.ts +1 -1
- package/dist/components/MBadge.d.ts +1 -1
- package/dist/components/MButton.d.ts +55 -9
- package/dist/components/MButton.d.ts.map +1 -1
- package/dist/components/MButton.js +13 -8
- package/dist/components/MButton.js.map +1 -1
- package/dist/components/MCard.d.ts +49 -2
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +44 -31
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MCheckbox.d.ts +1 -1
- package/dist/components/MCheckbox.d.ts.map +1 -1
- package/dist/components/MCheckbox.js +11 -6
- package/dist/components/MCheckbox.js.map +1 -1
- package/dist/components/MChip.d.ts +3 -3
- package/dist/components/MCombobox.d.ts +2 -2
- package/dist/components/MCombobox.js +3 -3
- package/dist/components/MCombobox.js.map +1 -1
- package/dist/components/MDatePicker.d.ts +72 -24
- package/dist/components/MDatePicker.d.ts.map +1 -1
- package/dist/components/MDatePicker.js +9 -0
- package/dist/components/MDatePicker.js.map +1 -1
- package/dist/components/MDialog.d.ts +2 -2
- package/dist/components/MEmptyState.d.ts +1 -1
- package/dist/components/MFilePicker.d.ts +2 -2
- package/dist/components/MIcon.d.ts +1 -1
- package/dist/components/MImage.d.ts +192 -0
- package/dist/components/MImage.d.ts.map +1 -0
- package/dist/components/MImage.js +97 -0
- package/dist/components/MImage.js.map +1 -0
- package/dist/components/MInput.d.ts +7 -7
- package/dist/components/MInput.js +3 -3
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MLink.d.ts +120 -0
- package/dist/components/MLink.d.ts.map +1 -0
- package/dist/components/MLink.js +75 -0
- package/dist/components/MLink.js.map +1 -0
- package/dist/components/MListItem.d.ts +3 -1
- package/dist/components/MListItem.d.ts.map +1 -1
- package/dist/components/MProgress.d.ts +3 -3
- package/dist/components/MRadioGroup.d.ts +1 -1
- package/dist/components/MRadioGroup.d.ts.map +1 -1
- package/dist/components/MRadioGroup.js +5 -3
- package/dist/components/MRadioGroup.js.map +1 -1
- package/dist/components/MReveal.d.ts +2 -2
- package/dist/components/MReveal.d.ts.map +1 -1
- package/dist/components/MReveal.js +39 -50
- package/dist/components/MReveal.js.map +1 -1
- package/dist/components/MSegmentedControl.d.ts +1 -1
- package/dist/components/MSelect.d.ts +1 -1
- package/dist/components/MSeparator.d.ts +1 -1
- package/dist/components/MSheet.d.ts +1 -1
- package/dist/components/MSlider.d.ts +1 -1
- package/dist/components/MStack.d.ts +198 -0
- package/dist/components/MStack.d.ts.map +1 -0
- package/dist/components/MStack.js +62 -0
- package/dist/components/MStack.js.map +1 -0
- package/dist/components/MSwitch.d.ts +1 -1
- package/dist/components/MSwitch.d.ts.map +1 -1
- package/dist/components/MSwitch.js +12 -5
- package/dist/components/MSwitch.js.map +1 -1
- package/dist/components/MTabs.d.ts +1 -1
- package/dist/components/MText.d.ts +4 -4
- package/dist/components/MText.js +6 -6
- package/dist/components/MText.js.map +1 -1
- package/dist/components/configurator.d.ts +541 -0
- package/dist/components/configurator.d.ts.map +1 -0
- package/dist/components/configurator.js +20 -0
- package/dist/components/configurator.js.map +1 -0
- package/dist/components/layout.d.ts +179 -2
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +10 -10
- package/dist/components/layout.js.map +1 -1
- package/dist/components/workflows.d.ts +1 -1
- package/dist/connected-motion.d.ts +6 -0
- package/dist/connected-motion.d.ts.map +1 -0
- package/dist/connected-motion.js +18 -0
- package/dist/connected-motion.js.map +1 -0
- package/dist/experimental.d.ts +9 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +27 -0
- package/dist/experimental.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/motion-region.d.ts +3 -0
- package/dist/motion-region.d.ts.map +1 -1
- package/dist/motion-region.js +69 -39
- package/dist/motion-region.js.map +1 -1
- package/dist/motion-surface.d.ts +4 -0
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +66 -2
- package/dist/motion-surface.js.map +1 -1
- package/dist/motion.d.ts +2 -2
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +8 -27
- package/dist/motion.js.map +1 -1
- package/dist/navigation.d.ts +12 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +38 -0
- package/dist/navigation.js.map +1 -0
- package/dist/reveal-motion.d.ts +5 -0
- package/dist/reveal-motion.d.ts.map +1 -0
- package/dist/reveal-motion.js +53 -0
- package/dist/reveal-motion.js.map +1 -0
- package/dist/scroll-motion.d.ts.map +1 -1
- package/dist/scroll-motion.js +33 -18
- package/dist/scroll-motion.js.map +1 -1
- package/dist/tokens.d.ts +7 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +29 -0
- package/dist/tokens.js.map +1 -0
- package/package.json +7 -3
- package/src/components/ChoicePaint.ts +96 -0
- package/src/components/MButton.ts +17 -7
- package/src/components/MCard.ts +54 -28
- package/src/components/MCheckbox.ts +17 -6
- package/src/components/MCombobox.ts +3 -3
- package/src/components/MDatePicker.ts +8 -0
- package/src/components/MImage.ts +108 -0
- package/src/components/MInput.ts +3 -3
- package/src/components/MLink.ts +85 -0
- package/src/components/MRadioGroup.ts +9 -3
- package/src/components/MReveal.ts +57 -64
- package/src/components/MStack.ts +90 -0
- package/src/components/MSwitch.ts +17 -6
- package/src/components/MText.ts +6 -6
- package/src/components/configurator.ts +24 -0
- package/src/components/layout.ts +10 -10
- package/src/connected-motion.ts +23 -0
- package/src/experimental.ts +29 -0
- package/src/index.ts +15 -0
- package/src/motion-region.ts +94 -41
- package/src/motion-surface.ts +72 -4
- package/src/motion.ts +10 -40
- package/src/navigation.ts +44 -0
- package/src/reveal-motion.ts +59 -0
- package/src/scroll-motion.ts +31 -18
- package/src/style.css +13 -10
- package/src/tokens.ts +29 -0
package/src/motion-surface.ts
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
import { webScrollElement } from './scroll-motion.js'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
WebReadableValue,
|
|
4
|
+
WebRuntime,
|
|
5
|
+
WebMotionScope,
|
|
6
|
+
WebMotionValue,
|
|
7
|
+
} from '@rafaelaugusto/jolt/web'
|
|
3
8
|
import type { MotionSurfaceAdapter } from '@getcortexlabs/mavis-core/experimental'
|
|
4
9
|
import { webRegion } from './motion-region.js'
|
|
5
10
|
|
|
11
|
+
const boundPaint = new WeakMap<HTMLElement, Map<string, number>>()
|
|
12
|
+
const paintKeys = new Set([
|
|
13
|
+
'backgroundColor',
|
|
14
|
+
'borderColor',
|
|
15
|
+
'color',
|
|
16
|
+
'borderRadius',
|
|
17
|
+
'borderWidth',
|
|
18
|
+
])
|
|
19
|
+
/** Vue may rerender slots while an application value owns paint on this element. */
|
|
20
|
+
export function preserveBoundPaint(target: HTMLElement | undefined) {
|
|
21
|
+
return target
|
|
22
|
+
? Object.fromEntries(
|
|
23
|
+
[...(boundPaint.get(target)?.keys() ?? [])].map((key) => [
|
|
24
|
+
key,
|
|
25
|
+
target.style[key as 'backgroundColor'],
|
|
26
|
+
]),
|
|
27
|
+
)
|
|
28
|
+
: {}
|
|
29
|
+
}
|
|
30
|
+
|
|
6
31
|
const targets = new WeakMap<MotionSurfaceAdapter, { runtime: WebRuntime; target: HTMLElement }>()
|
|
7
32
|
export function webSurfaceTarget(adapter: MotionSurfaceAdapter) {
|
|
8
33
|
const target = targets.get(adapter)
|
|
@@ -76,6 +101,10 @@ export function webMotionSurface(
|
|
|
76
101
|
? owner.map(value, input, output, options)
|
|
77
102
|
: value.to(input, output, options)
|
|
78
103
|
},
|
|
104
|
+
mapColor(source, input, output) {
|
|
105
|
+
const value = sources.get(source) ?? (source as WebReadableValue)
|
|
106
|
+
return 'map' in owner ? owner.map(value, input, output) : value.to(input, output)
|
|
107
|
+
},
|
|
79
108
|
springValue(source, options) {
|
|
80
109
|
// Keep the runtime's private value identity; it rejects values from other contexts.
|
|
81
110
|
const spring = owner.springValue(source as ReturnType<WebRuntime['motionValue']>, options)
|
|
@@ -96,20 +125,59 @@ export function webMotionSurface(
|
|
|
96
125
|
return wrapper
|
|
97
126
|
},
|
|
98
127
|
|
|
128
|
+
animateValue: (value, frames, options) =>
|
|
129
|
+
owner.animate(value as WebMotionValue, frames, options),
|
|
130
|
+
stopValue: (value, options) => runtime.stop(value as WebMotionValue, options),
|
|
131
|
+
playbackProgress: (handle) =>
|
|
132
|
+
owner.playbackProgress(handle as Parameters<WebRuntime['playbackProgress']>[0]),
|
|
133
|
+
decay: (velocity, options) => owner.decay(target, velocity, options),
|
|
99
134
|
animate: (values, options) => owner.animate(target, values, options),
|
|
100
135
|
set: (values) => owner.set(target, values),
|
|
101
136
|
motionValue: (initial) => owner.motionValue(initial),
|
|
102
137
|
bind(values) {
|
|
103
138
|
// Spring wrappers retain their public handle, rather than registering a second clock.
|
|
104
|
-
|
|
139
|
+
const binding = owner.bind(
|
|
105
140
|
target,
|
|
106
141
|
Object.fromEntries(
|
|
107
142
|
Object.entries(values).map(([key, value]) => [key, sources.get(value) ?? value]),
|
|
108
|
-
) as
|
|
143
|
+
) as Parameters<WebRuntime['bind']>[1],
|
|
109
144
|
)
|
|
145
|
+
let counts = boundPaint.get(target)
|
|
146
|
+
if (!counts) boundPaint.set(target, (counts = new Map()))
|
|
147
|
+
const keys = Object.keys(values).filter((key) => paintKeys.has(key))
|
|
148
|
+
for (const key of keys) counts.set(key, (counts.get(key) ?? 0) + 1)
|
|
149
|
+
let disposed = false
|
|
150
|
+
return {
|
|
151
|
+
dispose() {
|
|
152
|
+
if (disposed) return
|
|
153
|
+
disposed = true
|
|
154
|
+
try {
|
|
155
|
+
binding.dispose()
|
|
156
|
+
} finally {
|
|
157
|
+
for (const key of keys) {
|
|
158
|
+
const count = counts!.get(key)! - 1
|
|
159
|
+
if (count) counts!.set(key, count)
|
|
160
|
+
else counts!.delete(key)
|
|
161
|
+
}
|
|
162
|
+
if (!counts!.size) boundPaint.delete(target)
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
}
|
|
110
166
|
},
|
|
111
167
|
drag(options) {
|
|
112
|
-
const drag = owner.drag(target, {
|
|
168
|
+
const drag = owner.drag(target, {
|
|
169
|
+
...options,
|
|
170
|
+
disabled: !enabled(),
|
|
171
|
+
onRelease: options.onRelease
|
|
172
|
+
? (event) =>
|
|
173
|
+
options.onRelease!({
|
|
174
|
+
x: event.x,
|
|
175
|
+
y: event.y,
|
|
176
|
+
velocityX: event.velocity.x,
|
|
177
|
+
velocityY: event.velocity.y,
|
|
178
|
+
})
|
|
179
|
+
: undefined,
|
|
180
|
+
})
|
|
113
181
|
let paused = false
|
|
114
182
|
const refresh = () => {
|
|
115
183
|
const disabled = paused || !enabled()
|
package/src/motion.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
onActivated,
|
|
3
|
-
onDeactivated,
|
|
4
|
-
onBeforeUnmount,
|
|
5
|
-
shallowRef,
|
|
6
|
-
watch,
|
|
7
|
-
type Ref,
|
|
8
|
-
type VNode,
|
|
9
|
-
} from 'vue'
|
|
1
|
+
import { onBeforeUnmount, shallowRef, watch, type Ref, type VNode } from 'vue'
|
|
10
2
|
import type { WebRuntime } from '@rafaelaugusto/jolt/web'
|
|
11
|
-
import { pressMotion, type MavisTheme } from '@getcortexlabs/mavis-core'
|
|
3
|
+
import { pressMotion, type MotionTheme, type MavisTheme } from '@getcortexlabs/mavis-core'
|
|
12
4
|
import { bindMotionSurface, type MotionSurface } from '@getcortexlabs/mavis-core/experimental'
|
|
13
5
|
import { webMotionSurface } from './motion-surface.js'
|
|
14
6
|
import { useMotionContext } from './motion-context.js'
|
|
7
|
+
import { useConnectedMotion } from './connected-motion.js'
|
|
15
8
|
|
|
16
9
|
// Chip keeps its separate CSS feedback until its interaction contract is migrated.
|
|
17
10
|
export function pressStyle(scale: number) {
|
|
@@ -23,7 +16,7 @@ export function attachWebPress(
|
|
|
23
16
|
target: HTMLElement,
|
|
24
17
|
runtime: WebRuntime,
|
|
25
18
|
enabled: () => boolean,
|
|
26
|
-
scale: () => number
|
|
19
|
+
scale: () => number | Readonly<MotionTheme>,
|
|
27
20
|
applicationSurface: () => boolean = () => false,
|
|
28
21
|
) {
|
|
29
22
|
const window = target.ownerDocument.defaultView!
|
|
@@ -205,7 +198,6 @@ export function usePressFeedback(
|
|
|
205
198
|
) {
|
|
206
199
|
const element = shallowRef<HTMLElement | null>(null)
|
|
207
200
|
const context = useMotionContext()
|
|
208
|
-
let lease: ReturnType<typeof context.acquire> | undefined
|
|
209
201
|
let attached: HTMLElement | undefined
|
|
210
202
|
let runtime: WebRuntime | undefined
|
|
211
203
|
let feedback: ReturnType<typeof attachWebPress> | undefined
|
|
@@ -215,13 +207,11 @@ export function usePressFeedback(
|
|
|
215
207
|
const cleanup = unbind,
|
|
216
208
|
press = feedback,
|
|
217
209
|
host = runtime,
|
|
218
|
-
target = attached
|
|
219
|
-
ownership = lease
|
|
210
|
+
target = attached
|
|
220
211
|
unbind = undefined
|
|
221
212
|
application = undefined
|
|
222
213
|
feedback = undefined
|
|
223
214
|
attached = undefined
|
|
224
|
-
lease = undefined
|
|
225
215
|
runtime = undefined
|
|
226
216
|
const errors: unknown[] = []
|
|
227
217
|
for (const dispose of [
|
|
@@ -230,7 +220,6 @@ export function usePressFeedback(
|
|
|
230
220
|
() => {
|
|
231
221
|
if (target) host?.release(target)
|
|
232
222
|
},
|
|
233
|
-
() => ownership?.release(),
|
|
234
223
|
]) {
|
|
235
224
|
try {
|
|
236
225
|
dispose?.()
|
|
@@ -256,18 +245,15 @@ export function usePressFeedback(
|
|
|
256
245
|
}
|
|
257
246
|
}
|
|
258
247
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
if (!target || runtime) return
|
|
262
|
-
lease = context.acquire(target.ownerDocument)
|
|
263
|
-
runtime = lease.runtime
|
|
248
|
+
useConnectedMotion(element, context, (host, target) => {
|
|
249
|
+
runtime = host
|
|
264
250
|
attached = target
|
|
265
251
|
try {
|
|
266
252
|
feedback = attachWebPress(
|
|
267
253
|
target,
|
|
268
254
|
runtime,
|
|
269
255
|
enabled,
|
|
270
|
-
() => theme.value.motion
|
|
256
|
+
() => theme.value.motion,
|
|
271
257
|
() => Boolean(surface?.()),
|
|
272
258
|
)
|
|
273
259
|
bind()
|
|
@@ -275,25 +261,9 @@ export function usePressFeedback(
|
|
|
275
261
|
release()
|
|
276
262
|
throw error
|
|
277
263
|
}
|
|
278
|
-
|
|
279
|
-
let active = true
|
|
280
|
-
watch(
|
|
281
|
-
element,
|
|
282
|
-
() => {
|
|
283
|
-
release()
|
|
284
|
-
if (active) attach()
|
|
285
|
-
},
|
|
286
|
-
{ flush: 'post' },
|
|
287
|
-
)
|
|
288
|
-
onActivated(() => {
|
|
289
|
-
active = true
|
|
290
|
-
attach()
|
|
291
|
-
})
|
|
292
|
-
onDeactivated(() => {
|
|
293
|
-
active = false
|
|
294
|
-
release()
|
|
264
|
+
return release
|
|
295
265
|
})
|
|
296
|
-
watch([enabled, () => theme.value.motion
|
|
266
|
+
watch([enabled, () => theme.value.motion], () => feedback?.refresh(), {
|
|
297
267
|
flush: 'pre',
|
|
298
268
|
})
|
|
299
269
|
watch(() => surface?.(), bind, { flush: 'post' })
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { linkDestination, linkRel } from '@getcortexlabs/mavis-core'
|
|
2
|
+
import type { NavigationOptions } from '@getcortexlabs/mavis-core'
|
|
3
|
+
|
|
4
|
+
/** One real anchor; the application can supply a RouterLink custom-slot navigate callback. */
|
|
5
|
+
export function navigationAttrs(
|
|
6
|
+
options: NavigationOptions,
|
|
7
|
+
disabled: boolean,
|
|
8
|
+
activate: () => void,
|
|
9
|
+
fail: (error: unknown) => void,
|
|
10
|
+
) {
|
|
11
|
+
const href = linkDestination(options.href!)
|
|
12
|
+
return {
|
|
13
|
+
href: disabled ? undefined : href,
|
|
14
|
+
role: 'link',
|
|
15
|
+
target: options.target,
|
|
16
|
+
rel: linkRel(options.target ?? '_self', options.rel),
|
|
17
|
+
tabindex: disabled ? -1 : undefined,
|
|
18
|
+
'aria-disabled': disabled || undefined,
|
|
19
|
+
onClick(event: MouseEvent) {
|
|
20
|
+
if (disabled) {
|
|
21
|
+
event.preventDefault()
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
if (event.defaultPrevented) return
|
|
25
|
+
activate()
|
|
26
|
+
if (
|
|
27
|
+
!options.navigate ||
|
|
28
|
+
(options.target && options.target !== '_self') ||
|
|
29
|
+
event.button !== 0 ||
|
|
30
|
+
event.metaKey ||
|
|
31
|
+
event.ctrlKey ||
|
|
32
|
+
event.shiftKey ||
|
|
33
|
+
event.altKey
|
|
34
|
+
)
|
|
35
|
+
return
|
|
36
|
+
event.preventDefault()
|
|
37
|
+
try {
|
|
38
|
+
Promise.resolve(options.navigate(href)).catch(fail)
|
|
39
|
+
} catch (error) {
|
|
40
|
+
fail(error)
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { motionRecipe, type MavisTheme } from '@getcortexlabs/mavis-core'
|
|
2
|
+
import type { RevealHost } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import type { WebMotionContext } from './motion-context.js'
|
|
4
|
+
|
|
5
|
+
export function revealHost(
|
|
6
|
+
element: HTMLElement,
|
|
7
|
+
context: WebMotionContext,
|
|
8
|
+
theme: () => MavisTheme,
|
|
9
|
+
hidden: () => boolean,
|
|
10
|
+
): RevealHost {
|
|
11
|
+
let trigger: HTMLElement | undefined
|
|
12
|
+
// Initial SSR/KeepAlive presentation needs no animation or geometry acquisition.
|
|
13
|
+
let lease: ReturnType<typeof context.acquire> | undefined
|
|
14
|
+
const originalHeight = element.style.height
|
|
15
|
+
return {
|
|
16
|
+
animate(open, fromClosed) {
|
|
17
|
+
if (!element.isConnected) return { finished: Promise.resolve(true), stop() {} }
|
|
18
|
+
lease ??= context.acquire(element.ownerDocument)
|
|
19
|
+
const runtime = lease.runtime
|
|
20
|
+
if (fromClosed) {
|
|
21
|
+
element.style.height = '0px'
|
|
22
|
+
runtime.set(element, { opacity: 0 })
|
|
23
|
+
}
|
|
24
|
+
const recipe = motionRecipe(theme(), open ? 'enter' : 'exit')
|
|
25
|
+
const size = runtime.animateSize(element, { height: open ? 'auto' : 0 }, recipe.transition)
|
|
26
|
+
const opacity = runtime.animate(element, { opacity: open ? 1 : 0 }, recipe.transition)
|
|
27
|
+
return {
|
|
28
|
+
finished: size.finished,
|
|
29
|
+
stop() {
|
|
30
|
+
size.stop({ restore: true })
|
|
31
|
+
opacity.stop()
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
interactive(enabled) {
|
|
36
|
+
element.toggleAttribute('inert', !enabled || Boolean(hidden()))
|
|
37
|
+
if (!enabled || hidden()) element.setAttribute('aria-hidden', 'true')
|
|
38
|
+
else element.removeAttribute('aria-hidden')
|
|
39
|
+
},
|
|
40
|
+
captureFocus() {
|
|
41
|
+
const active = element.ownerDocument.activeElement
|
|
42
|
+
if (
|
|
43
|
+
active instanceof element.ownerDocument.defaultView!.HTMLElement &&
|
|
44
|
+
!element.contains(active)
|
|
45
|
+
)
|
|
46
|
+
trigger = active
|
|
47
|
+
},
|
|
48
|
+
restoreFocus() {
|
|
49
|
+
if (element.contains(element.ownerDocument.activeElement) && trigger?.isConnected)
|
|
50
|
+
trigger.focus({ preventScroll: true })
|
|
51
|
+
},
|
|
52
|
+
release() {
|
|
53
|
+
lease?.runtime.release(element)
|
|
54
|
+
lease?.release()
|
|
55
|
+
lease = undefined
|
|
56
|
+
element.style.height = originalHeight
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/scroll-motion.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { computed, watch, type Ref } from 'vue'
|
|
2
|
+
import { useConnectedMotion } from './connected-motion.js'
|
|
3
|
+
import { useMotionContext } from './motion-context.js'
|
|
2
4
|
import {
|
|
3
5
|
bindMotionScrollSource,
|
|
4
6
|
type MotionScrollAdapter,
|
|
@@ -17,17 +19,15 @@ export function useScrollMotion(
|
|
|
17
19
|
source: () => MotionScrollSource | undefined,
|
|
18
20
|
enabled: () => boolean,
|
|
19
21
|
) {
|
|
20
|
-
let active = true
|
|
21
22
|
let release: (() => void) | undefined
|
|
22
23
|
const clear = () => {
|
|
23
24
|
release?.()
|
|
24
25
|
release = undefined
|
|
25
26
|
}
|
|
26
|
-
const attach = () => {
|
|
27
|
+
const attach = (target: HTMLElement) => {
|
|
27
28
|
clear()
|
|
28
|
-
const reference = source()
|
|
29
|
-
|
|
30
|
-
if (!active || !enabled() || !reference || !target) return
|
|
29
|
+
const reference = source()
|
|
30
|
+
if (!enabled() || !reference) return
|
|
31
31
|
const adapter: MotionScrollAdapter = { kind: 'web' }
|
|
32
32
|
sources.set(adapter, target)
|
|
33
33
|
const unbind = bindMotionScrollSource(reference, adapter)
|
|
@@ -39,10 +39,21 @@ export function useScrollMotion(
|
|
|
39
39
|
// A ScrollTimeline can become inactive when content no longer overflows. Rebase
|
|
40
40
|
// its retained pose on layout changes too, without observing values every frame.
|
|
41
41
|
const resize = new view.ResizeObserver(refresh)
|
|
42
|
+
const observed = new Set<Element>()
|
|
42
43
|
const observe = () => {
|
|
43
|
-
|
|
44
|
-
resize.
|
|
45
|
-
|
|
44
|
+
// Keep existing observations across text/subtree mutations. Re-observing an
|
|
45
|
+
// unchanged ancestor during resize delivery can trigger a WebKit resize loop.
|
|
46
|
+
const wanted = new Set<Element>([target, ...target.children])
|
|
47
|
+
for (const node of observed) {
|
|
48
|
+
if (wanted.has(node)) continue
|
|
49
|
+
resize.unobserve(node)
|
|
50
|
+
observed.delete(node)
|
|
51
|
+
}
|
|
52
|
+
for (const node of wanted) {
|
|
53
|
+
if (observed.has(node)) continue
|
|
54
|
+
resize.observe(node)
|
|
55
|
+
observed.add(node)
|
|
56
|
+
}
|
|
46
57
|
}
|
|
47
58
|
const mutations = new view.MutationObserver(() => {
|
|
48
59
|
observe()
|
|
@@ -55,6 +66,7 @@ export function useScrollMotion(
|
|
|
55
66
|
release = () => {
|
|
56
67
|
disposed = true
|
|
57
68
|
resize.disconnect()
|
|
69
|
+
observed.clear()
|
|
58
70
|
mutations.disconnect()
|
|
59
71
|
target.ownerDocument.fonts?.removeEventListener('loadingdone', refresh)
|
|
60
72
|
view.removeEventListener('resize', refresh)
|
|
@@ -62,14 +74,15 @@ export function useScrollMotion(
|
|
|
62
74
|
sources.delete(adapter)
|
|
63
75
|
}
|
|
64
76
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
const target = computed(() => (enabled() && source() ? element.value : undefined))
|
|
78
|
+
useConnectedMotion(target, useMotionContext(), (_, connected) => {
|
|
79
|
+
const stop = watch([source, enabled], () => attach(connected), {
|
|
80
|
+
immediate: true,
|
|
81
|
+
flush: 'post',
|
|
82
|
+
})
|
|
83
|
+
return () => {
|
|
84
|
+
stop()
|
|
85
|
+
clear()
|
|
86
|
+
}
|
|
73
87
|
})
|
|
74
|
-
onBeforeUnmount(clear)
|
|
75
88
|
}
|
package/src/style.css
CHANGED
|
@@ -222,7 +222,6 @@ html:has(.m-sheet[open]) {
|
|
|
222
222
|
flex-shrink: 0;
|
|
223
223
|
border-radius: 999px;
|
|
224
224
|
background: var(--m-switch-track);
|
|
225
|
-
transition: background-color 160ms ease;
|
|
226
225
|
}
|
|
227
226
|
.m-switch-thumb {
|
|
228
227
|
display: block;
|
|
@@ -236,8 +235,7 @@ html:has(.m-sheet[open]) {
|
|
|
236
235
|
box-shadow: 0 1px 3px #0003;
|
|
237
236
|
transition:
|
|
238
237
|
inset-inline-start 180ms ease,
|
|
239
|
-
transform 120ms ease
|
|
240
|
-
background-color 160ms ease;
|
|
238
|
+
transform 120ms ease;
|
|
241
239
|
}
|
|
242
240
|
.m-switch[aria-checked='true'] .m-switch-thumb {
|
|
243
241
|
inset-inline-start: 24px;
|
|
@@ -283,6 +281,8 @@ html:has(.m-sheet[open]) {
|
|
|
283
281
|
outline-offset: 2px;
|
|
284
282
|
}
|
|
285
283
|
.m-checkbox-box {
|
|
284
|
+
position: relative;
|
|
285
|
+
--m-choice-border: 2px;
|
|
286
286
|
display: flex;
|
|
287
287
|
align-items: center;
|
|
288
288
|
justify-content: center;
|
|
@@ -292,10 +292,7 @@ html:has(.m-sheet[open]) {
|
|
|
292
292
|
flex-shrink: 0;
|
|
293
293
|
border: 2px solid var(--m-checkbox-border);
|
|
294
294
|
border-radius: 7px;
|
|
295
|
-
transition:
|
|
296
|
-
transform 120ms ease,
|
|
297
|
-
background-color 140ms ease,
|
|
298
|
-
border-color 140ms ease;
|
|
295
|
+
transition: transform 120ms ease;
|
|
299
296
|
}
|
|
300
297
|
.m-checkbox-mark {
|
|
301
298
|
display: none;
|
|
@@ -383,6 +380,8 @@ html:has(.m-sheet[open]) {
|
|
|
383
380
|
outline-offset: 2px;
|
|
384
381
|
}
|
|
385
382
|
.m-radio-indicator {
|
|
383
|
+
position: relative;
|
|
384
|
+
--m-choice-border: 2px;
|
|
386
385
|
width: 24px;
|
|
387
386
|
height: 24px;
|
|
388
387
|
flex-shrink: 0;
|
|
@@ -392,9 +391,7 @@ html:has(.m-sheet[open]) {
|
|
|
392
391
|
display: flex;
|
|
393
392
|
align-items: center;
|
|
394
393
|
justify-content: center;
|
|
395
|
-
transition:
|
|
396
|
-
transform 120ms ease,
|
|
397
|
-
border-color 140ms ease;
|
|
394
|
+
transition: transform 120ms ease;
|
|
398
395
|
}
|
|
399
396
|
.m-radio-dot {
|
|
400
397
|
width: 12px;
|
|
@@ -976,3 +973,9 @@ button.m-chip-label:disabled {
|
|
|
976
973
|
flex-shrink: 0;
|
|
977
974
|
pointer-events: none;
|
|
978
975
|
}
|
|
976
|
+
|
|
977
|
+
.m-link:focus-visible {
|
|
978
|
+
outline: 2px solid var(--m-focus);
|
|
979
|
+
outline-offset: 3px;
|
|
980
|
+
border-radius: 3px;
|
|
981
|
+
}
|
package/src/tokens.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { computed, type CSSProperties } from 'vue'
|
|
2
|
+
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'
|
|
3
|
+
import { fontFamily, shadowStyle, type MavisTheme } from '@getcortexlabs/mavis-core'
|
|
4
|
+
|
|
5
|
+
/** CSS values for one theme scope. No document mutation or application singleton. */
|
|
6
|
+
export function themeVariables(theme: MavisTheme): CSSProperties {
|
|
7
|
+
const variables: Record<string, string | number> = {}
|
|
8
|
+
for (const [name, value] of Object.entries(theme.colors)) variables[`--m-color-${name}`] = value
|
|
9
|
+
for (const [name, value] of Object.entries(theme.space))
|
|
10
|
+
variables[`--m-space-${name}`] = `${value}px`
|
|
11
|
+
for (const [name, value] of Object.entries(theme.radius))
|
|
12
|
+
variables[`--m-radius-${name}`] = `${value}px`
|
|
13
|
+
for (const [name, value] of Object.entries(theme.elevation))
|
|
14
|
+
variables[`--m-elevation-${name}`] = shadowStyle(value)
|
|
15
|
+
for (const [name, type] of Object.entries(theme.typography)) {
|
|
16
|
+
variables[`--m-type-${name}-font-family`] = fontFamily(type.fontFamily, 'web')
|
|
17
|
+
variables[`--m-type-${name}-font-size`] = `${type.fontSize}px`
|
|
18
|
+
variables[`--m-type-${name}-font-weight`] = type.fontWeight
|
|
19
|
+
variables[`--m-type-${name}-line-height`] = type.lineHeight
|
|
20
|
+
variables[`--m-type-${name}-letter-spacing`] = `${type.letterSpacing}em`
|
|
21
|
+
}
|
|
22
|
+
return variables as CSSProperties
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Bind to a host's :style inside the desired MThemeProvider scope. Also works during SSR. */
|
|
26
|
+
export function useMavisTokens() {
|
|
27
|
+
const { theme } = useMavisTheme()
|
|
28
|
+
return computed(() => themeVariables(theme.value))
|
|
29
|
+
}
|