@getcortexlabs/mavis-web 0.1.0-rc.12.2 → 0.1.0-rc.13
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/animated-number.d.ts.map +1 -1
- package/dist/animated-number.js +8 -10
- package/dist/animated-number.js.map +1 -1
- package/dist/component-motion.d.ts.map +1 -1
- package/dist/component-motion.js +10 -3
- package/dist/component-motion.js.map +1 -1
- package/dist/components/ChartPlot.d.ts.map +1 -1
- package/dist/components/ChartPlot.js +9 -7
- package/dist/components/ChartPlot.js.map +1 -1
- package/dist/components/MButton.d.ts +2 -2
- package/dist/components/MCard.d.ts.map +1 -1
- package/dist/components/MCard.js +11 -4
- package/dist/components/MCard.js.map +1 -1
- package/dist/components/MChip.d.ts +1 -1
- package/dist/components/MEmptyState.d.ts +1 -1
- package/dist/components/MInput.d.ts +2 -2
- package/dist/components/MInput.d.ts.map +1 -1
- package/dist/components/MInput.js +16 -4
- package/dist/components/MInput.js.map +1 -1
- package/dist/components/MPopover.d.ts +1 -1
- package/dist/components/MTooltip.d.ts +1 -1
- package/dist/components/creative.d.ts.map +1 -1
- package/dist/components/creative.js +7 -5
- package/dist/components/creative.js.map +1 -1
- package/dist/components/dashboard.d.ts.map +1 -1
- package/dist/components/dashboard.js +7 -5
- package/dist/components/dashboard.js.map +1 -1
- package/dist/components/layout.d.ts +11 -0
- package/dist/components/layout.d.ts.map +1 -1
- package/dist/components/layout.js +8 -1
- package/dist/components/layout.js.map +1 -1
- package/dist/experimental.d.ts +8 -0
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +17 -0
- package/dist/experimental.js.map +1 -1
- package/dist/motion-surface.d.ts +6 -5
- package/dist/motion-surface.d.ts.map +1 -1
- package/dist/motion-surface.js +41 -10
- package/dist/motion-surface.js.map +1 -1
- package/dist/reduced-motion.d.ts +10 -0
- package/dist/reduced-motion.d.ts.map +1 -0
- package/dist/reduced-motion.js +26 -0
- package/dist/reduced-motion.js.map +1 -0
- package/dist/visual-effects.d.ts.map +1 -1
- package/dist/visual-effects.js +14 -1
- package/dist/visual-effects.js.map +1 -1
- package/package.json +3 -3
- package/src/animated-number.ts +7 -9
- package/src/component-motion.ts +11 -2
- package/src/components/ChartPlot.ts +8 -9
- package/src/components/MCard.ts +11 -4
- package/src/components/MInput.ts +13 -4
- package/src/components/creative.ts +7 -5
- package/src/components/dashboard.ts +7 -5
- package/src/components/layout.ts +8 -1
- package/src/experimental.ts +20 -0
- package/src/motion-surface.ts +40 -13
- package/src/reduced-motion.ts +30 -0
- package/src/visual-effects.ts +12 -1
package/src/animated-number.ts
CHANGED
|
@@ -8,7 +8,7 @@ export function useAnimatedNumber(read: () => number, direct: () => boolean) {
|
|
|
8
8
|
let lease: ReturnType<typeof context.acquire> | undefined
|
|
9
9
|
let value: ReturnType<ReturnType<typeof context.acquire>['runtime']['motionValue']> | undefined
|
|
10
10
|
let off: (() => void) | undefined
|
|
11
|
-
let
|
|
11
|
+
let unfollow: (() => void) | undefined
|
|
12
12
|
const settle = () => {
|
|
13
13
|
if (!value || !lease) {
|
|
14
14
|
shown.value = read()
|
|
@@ -18,11 +18,8 @@ export function useAnimatedNumber(read: () => number, direct: () => boolean) {
|
|
|
18
18
|
lease.runtime.set(value, read())
|
|
19
19
|
shown.value = read()
|
|
20
20
|
}
|
|
21
|
-
const reduced = () => {
|
|
22
|
-
if (preference?.matches) settle()
|
|
23
|
-
}
|
|
24
21
|
const update = () => {
|
|
25
|
-
if (!lease || !value || direct() ||
|
|
22
|
+
if (!lease || !value || direct() || lease.runtime.reducedMotion()) {
|
|
26
23
|
settle()
|
|
27
24
|
return
|
|
28
25
|
}
|
|
@@ -35,13 +32,14 @@ export function useAnimatedNumber(read: () => number, direct: () => boolean) {
|
|
|
35
32
|
off = value.subscribe((next) => {
|
|
36
33
|
shown.value = next
|
|
37
34
|
})
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
unfollow = lease.runtime.onReducedMotion((reduced) => {
|
|
36
|
+
if (reduced) settle()
|
|
37
|
+
})
|
|
40
38
|
shown.value = read()
|
|
41
39
|
}
|
|
42
40
|
const detach = () => {
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
unfollow?.()
|
|
42
|
+
unfollow = undefined
|
|
45
43
|
off?.()
|
|
46
44
|
off = undefined
|
|
47
45
|
value?.dispose()
|
package/src/component-motion.ts
CHANGED
|
@@ -48,6 +48,7 @@ export function useComponentTransition(offset = 6) {
|
|
|
48
48
|
lease: ReturnType<typeof context.acquire>
|
|
49
49
|
playback?: ReturnType<WebRuntime['animate']>
|
|
50
50
|
generation: number
|
|
51
|
+
leaving?: () => void
|
|
51
52
|
}
|
|
52
53
|
>()
|
|
53
54
|
function release(element: Element) {
|
|
@@ -67,6 +68,7 @@ export function useComponentTransition(offset = 6) {
|
|
|
67
68
|
entries.set(element, entry)
|
|
68
69
|
}
|
|
69
70
|
const token = ++entry.generation
|
|
71
|
+
entry.leaving = entering ? undefined : done
|
|
70
72
|
const target = element as HTMLElement
|
|
71
73
|
if (entering && fresh)
|
|
72
74
|
entry.lease.runtime.animate(target, { opacity: 0, y: offset }, { duration: 0 })
|
|
@@ -79,12 +81,17 @@ export function useComponentTransition(offset = 6) {
|
|
|
79
81
|
)
|
|
80
82
|
void entry.playback.finished.then(() => {
|
|
81
83
|
if (entries.get(element) !== entry || entry.generation !== token) return
|
|
84
|
+
entry.leaving = undefined
|
|
82
85
|
done()
|
|
83
86
|
if (!entering) release(element)
|
|
84
87
|
})
|
|
85
88
|
}
|
|
86
89
|
onScopeDispose(() => {
|
|
87
|
-
for (const element of entries
|
|
90
|
+
for (const [element, { leaving }] of [...entries]) {
|
|
91
|
+
release(element)
|
|
92
|
+
// Vue keeps a leaving element until done(); without it the node outlives its owner.
|
|
93
|
+
leaving?.()
|
|
94
|
+
}
|
|
88
95
|
})
|
|
89
96
|
return {
|
|
90
97
|
css: false,
|
|
@@ -98,7 +105,9 @@ export function useComponentTransition(offset = 6) {
|
|
|
98
105
|
},
|
|
99
106
|
onLeaveCancelled: (element: Element) => {
|
|
100
107
|
const entry = entries.get(element)
|
|
101
|
-
if (entry)
|
|
108
|
+
if (!entry) return
|
|
109
|
+
entry.generation++
|
|
110
|
+
entry.leaving = undefined
|
|
102
111
|
},
|
|
103
112
|
}
|
|
104
113
|
}
|
|
@@ -32,10 +32,10 @@ export const ChartPlot = defineComponent({
|
|
|
32
32
|
let progress:
|
|
33
33
|
ReturnType<ReturnType<typeof context.acquire>['runtime']['motionValue']> | undefined
|
|
34
34
|
let off: (() => void) | undefined
|
|
35
|
-
let
|
|
35
|
+
let unfollow: (() => void) | undefined
|
|
36
36
|
let generation = 0
|
|
37
37
|
const settle = () => {
|
|
38
|
-
if (
|
|
38
|
+
if (lease && progress) {
|
|
39
39
|
generation++
|
|
40
40
|
lease.runtime.stop(progress)
|
|
41
41
|
lease.runtime.set(progress, 1)
|
|
@@ -96,7 +96,7 @@ export const ChartPlot = defineComponent({
|
|
|
96
96
|
}
|
|
97
97
|
startGeometry = presentation
|
|
98
98
|
const token = ++generation
|
|
99
|
-
if (
|
|
99
|
+
if (lease.runtime.reducedMotion()) {
|
|
100
100
|
settle()
|
|
101
101
|
return
|
|
102
102
|
}
|
|
@@ -111,10 +111,9 @@ export const ChartPlot = defineComponent({
|
|
|
111
111
|
function connect() {
|
|
112
112
|
if (lease || !plot.value) return
|
|
113
113
|
lease = context.acquire(plot.value.ownerDocument)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
)
|
|
117
|
-
preference.addEventListener('change', settle)
|
|
114
|
+
unfollow = lease.runtime.onReducedMotion((reduced) => {
|
|
115
|
+
if (reduced) settle()
|
|
116
|
+
})
|
|
118
117
|
progress = lease.runtime.motionValue(0)
|
|
119
118
|
off = progress.subscribe((value) =>
|
|
120
119
|
paint(interpolateChart(startGeometry, destination, value)),
|
|
@@ -123,8 +122,8 @@ export const ChartPlot = defineComponent({
|
|
|
123
122
|
}
|
|
124
123
|
function disconnect() {
|
|
125
124
|
generation++
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
unfollow?.()
|
|
126
|
+
unfollow = undefined
|
|
128
127
|
off?.()
|
|
129
128
|
off = undefined
|
|
130
129
|
progress?.dispose()
|
package/src/components/MCard.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolveSpace, resolveRadius, shadowStyle } from '@getcortexlabs/mavis-core'
|
|
2
|
-
import { defineComponent, h, mergeProps, shallowRef, type VNode } from 'vue'
|
|
2
|
+
import { defineComponent, getCurrentInstance, h, mergeProps, shallowRef, type VNode } from 'vue'
|
|
3
3
|
import { preserveBoundPaint } from '../motion-surface.js'
|
|
4
4
|
import {
|
|
5
5
|
useButtonAction,
|
|
@@ -23,6 +23,7 @@ export const MCard = defineComponent({
|
|
|
23
23
|
useButtonAction(() => props.interactive || props.href !== undefined)
|
|
24
24
|
const { theme } = useMavisTheme()
|
|
25
25
|
const navigation = useNavigationOptions(props)
|
|
26
|
+
const instance = getCurrentInstance()
|
|
26
27
|
const element = shallowRef<HTMLElement>()
|
|
27
28
|
const lifecycle = usePressFeedback(
|
|
28
29
|
() => (props.interactive || props.href !== undefined) && !props.disabled,
|
|
@@ -46,6 +47,7 @@ export const MCard = defineComponent({
|
|
|
46
47
|
...layout
|
|
47
48
|
} = props
|
|
48
49
|
const tokens = theme.value.components.card
|
|
50
|
+
const shadow = `var(--m-card-shadow, ${shadowStyle(theme.value.elevation[elevation ?? tokens.elevation])})`
|
|
49
51
|
layout.padding ??= tokens.padding
|
|
50
52
|
layout.radius ??= tokens.radius
|
|
51
53
|
return h(
|
|
@@ -76,7 +78,7 @@ export const MCard = defineComponent({
|
|
|
76
78
|
props.radius !== undefined
|
|
77
79
|
? `${resolveRadius(theme.value, props.radius)}px`
|
|
78
80
|
: `var(--m-card-radius, ${resolveRadius(theme.value, tokens.radius)}px)`,
|
|
79
|
-
boxShadow:
|
|
81
|
+
boxShadow: shadow,
|
|
80
82
|
backgroundColor:
|
|
81
83
|
props.backgroundColor ?? `var(--m-card-background, ${theme.value.colors.surface})`,
|
|
82
84
|
border: `var(--m-card-border, 1px solid ${theme.value.colors.border})`,
|
|
@@ -91,7 +93,7 @@ export const MCard = defineComponent({
|
|
|
91
93
|
onVnodeMounted: (node: VNode) => {
|
|
92
94
|
element.value = node.el as HTMLElement
|
|
93
95
|
},
|
|
94
|
-
style: preserveBoundPaint(element.value),
|
|
96
|
+
style: preserveBoundPaint(element.value, shadow),
|
|
95
97
|
},
|
|
96
98
|
href !== undefined
|
|
97
99
|
? navigationAttrs(navigation(), disabled, activate, (error) => emit('error', error))
|
|
@@ -113,7 +115,12 @@ export const MCard = defineComponent({
|
|
|
113
115
|
}
|
|
114
116
|
},
|
|
115
117
|
}
|
|
116
|
-
:
|
|
118
|
+
: // A labelled card with no action wired is read as one element, as on native.
|
|
119
|
+
props.accessibilityLabel &&
|
|
120
|
+
attrs.role === undefined &&
|
|
121
|
+
!instance?.vnode.props?.onClick
|
|
122
|
+
? { role: 'img' }
|
|
123
|
+
: {},
|
|
117
124
|
),
|
|
118
125
|
slots,
|
|
119
126
|
)
|
package/src/components/MInput.ts
CHANGED
|
@@ -93,6 +93,7 @@ const Input = defineComponent({
|
|
|
93
93
|
let observer: ResizeObserver | undefined
|
|
94
94
|
let observed: HTMLElement | undefined
|
|
95
95
|
let width = 0
|
|
96
|
+
let frame: number | undefined
|
|
96
97
|
let measured = ''
|
|
97
98
|
|
|
98
99
|
function resize() {
|
|
@@ -129,16 +130,24 @@ const Input = defineComponent({
|
|
|
129
130
|
if (typeof document !== 'undefined') focused.value = editor.value === document.activeElement
|
|
130
131
|
if (typeof ResizeObserver !== 'undefined') {
|
|
131
132
|
observer = new ResizeObserver(([entry]) => {
|
|
132
|
-
if (entry
|
|
133
|
-
|
|
133
|
+
if (!entry || entry.contentRect.width === width) return
|
|
134
|
+
width = entry.contentRect.width
|
|
135
|
+
// The new height also resizes observed ancestors, such as a grid. Inside this
|
|
136
|
+
// delivery browsers report that as a ResizeObserver loop error.
|
|
137
|
+
if (frame !== undefined) cancelAnimationFrame(frame)
|
|
138
|
+
frame = requestAnimationFrame(() => {
|
|
139
|
+
frame = undefined
|
|
134
140
|
resize()
|
|
135
|
-
}
|
|
141
|
+
})
|
|
136
142
|
})
|
|
137
143
|
}
|
|
138
144
|
observe()
|
|
139
145
|
})
|
|
140
146
|
onUpdated(observe)
|
|
141
|
-
onBeforeUnmount(() =>
|
|
147
|
+
onBeforeUnmount(() => {
|
|
148
|
+
observer?.disconnect()
|
|
149
|
+
if (frame !== undefined) cancelAnimationFrame(frame)
|
|
150
|
+
})
|
|
142
151
|
watch(
|
|
143
152
|
() => props.disabled,
|
|
144
153
|
(disabled) => {
|
|
@@ -23,6 +23,8 @@ import {
|
|
|
23
23
|
} from '@getcortexlabs/mavis-core/vue'
|
|
24
24
|
import type { gaugeGeometry } from '@getcortexlabs/mavis-core'
|
|
25
25
|
import { MBox, MColumn, MRow } from './layout.js'
|
|
26
|
+
import { useMotionContext } from '../motion-context.js'
|
|
27
|
+
import { followReducedMotion } from '../reduced-motion.js'
|
|
26
28
|
import { MStack } from './MStack.js'
|
|
27
29
|
import { MCard } from './MCard.js'
|
|
28
30
|
import { MText } from './MText.js'
|
|
@@ -145,7 +147,8 @@ const MarqueeHost = defineComponent({
|
|
|
145
147
|
emits: ['environment'],
|
|
146
148
|
setup(_props, { attrs, slots, emit }) {
|
|
147
149
|
const root = ref<HTMLElement>()
|
|
148
|
-
|
|
150
|
+
const context = useMotionContext()
|
|
151
|
+
let follow: ReturnType<typeof followReducedMotion> | undefined,
|
|
149
152
|
resize: ResizeObserver | undefined,
|
|
150
153
|
intersection: IntersectionObserver | undefined
|
|
151
154
|
let hovered = false,
|
|
@@ -154,15 +157,14 @@ const MarqueeHost = defineComponent({
|
|
|
154
157
|
attached = false
|
|
155
158
|
const update = () =>
|
|
156
159
|
emit('environment', {
|
|
157
|
-
reduced:
|
|
160
|
+
reduced: follow?.reduced ?? true,
|
|
158
161
|
paused: !attached || document.hidden || hovered || focused || !visible,
|
|
159
162
|
width: root.value?.clientWidth ?? 0,
|
|
160
163
|
})
|
|
161
164
|
function attach() {
|
|
162
165
|
if (attached || !root.value) return
|
|
163
166
|
attached = true
|
|
164
|
-
|
|
165
|
-
media.addEventListener('change', update)
|
|
167
|
+
follow = followReducedMotion(context, root.value.ownerDocument, update)
|
|
166
168
|
resize = new ResizeObserver(update)
|
|
167
169
|
resize.observe(root.value)
|
|
168
170
|
intersection = new IntersectionObserver(([entry]) => {
|
|
@@ -175,7 +177,7 @@ const MarqueeHost = defineComponent({
|
|
|
175
177
|
}
|
|
176
178
|
function detach() {
|
|
177
179
|
attached = false
|
|
178
|
-
|
|
180
|
+
follow?.release()
|
|
179
181
|
resize?.disconnect()
|
|
180
182
|
intersection?.disconnect()
|
|
181
183
|
document.removeEventListener('visibilitychange', update)
|
|
@@ -27,6 +27,8 @@ import {
|
|
|
27
27
|
} from '@getcortexlabs/mavis-core/vue'
|
|
28
28
|
import { createMotionSurface } from '@getcortexlabs/mavis-core/experimental'
|
|
29
29
|
import { MBox, MColumn, MRow } from './layout.js'
|
|
30
|
+
import { useMotionContext } from '../motion-context.js'
|
|
31
|
+
import { followReducedMotion } from '../reduced-motion.js'
|
|
30
32
|
import { MStack } from './MStack.js'
|
|
31
33
|
import { MText } from './MText.js'
|
|
32
34
|
import { MButton } from './MButton.js'
|
|
@@ -77,19 +79,19 @@ const Environment = defineComponent({
|
|
|
77
79
|
const root = ref<HTMLElement>()
|
|
78
80
|
let attached = false,
|
|
79
81
|
visible = true,
|
|
80
|
-
|
|
82
|
+
follow: ReturnType<typeof followReducedMotion> | undefined,
|
|
81
83
|
observer: IntersectionObserver | undefined
|
|
84
|
+
const context = useMotionContext()
|
|
82
85
|
function update() {
|
|
83
86
|
emit('environment', {
|
|
84
|
-
reduced:
|
|
87
|
+
reduced: follow?.reduced ?? true,
|
|
85
88
|
paused: !attached || document.hidden || !visible,
|
|
86
89
|
})
|
|
87
90
|
}
|
|
88
91
|
function connect() {
|
|
89
92
|
if (attached || !root.value) return
|
|
90
93
|
attached = true
|
|
91
|
-
|
|
92
|
-
media.addEventListener('change', update)
|
|
94
|
+
follow = followReducedMotion(context, root.value.ownerDocument, update)
|
|
93
95
|
document.addEventListener('visibilitychange', update)
|
|
94
96
|
observer = new IntersectionObserver(([entry]) => {
|
|
95
97
|
const next = entry?.isIntersecting ?? false
|
|
@@ -103,7 +105,7 @@ const Environment = defineComponent({
|
|
|
103
105
|
}
|
|
104
106
|
function disconnect() {
|
|
105
107
|
attached = false
|
|
106
|
-
|
|
108
|
+
follow?.release()
|
|
107
109
|
observer?.disconnect()
|
|
108
110
|
document.removeEventListener('visibilitychange', update)
|
|
109
111
|
update()
|
package/src/components/layout.ts
CHANGED
|
@@ -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: {
|
|
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,
|
package/src/experimental.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/motion-surface.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
WebMotionScope,
|
|
7
7
|
WebMotionValue,
|
|
8
8
|
} from '@rafaelaugusto/jolt/web'
|
|
9
|
-
import type
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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 }>()
|
|
@@ -124,7 +140,10 @@ export function webMotionSurface(
|
|
|
124
140
|
return {
|
|
125
141
|
x: wrap(pointer.x),
|
|
126
142
|
y: wrap(pointer.y),
|
|
143
|
+
presence: wrap(pointer.presence),
|
|
127
144
|
execution: 'hover',
|
|
145
|
+
// Pointer events exist in every browser; whether a mouse is connected is not known.
|
|
146
|
+
available: true,
|
|
128
147
|
get active() {
|
|
129
148
|
return pointer.active
|
|
130
149
|
},
|
|
@@ -187,8 +206,16 @@ export function webMotionSurface(
|
|
|
187
206
|
playbackProgress: (handle) =>
|
|
188
207
|
owner.playbackProgress(handle as Parameters<WebRuntime['playbackProgress']>[0]),
|
|
189
208
|
decay: (velocity, options) => owner.decay(target, velocity, options),
|
|
190
|
-
animate
|
|
191
|
-
|
|
209
|
+
animate(values, options) {
|
|
210
|
+
const playback = owner.animate(target, motionKeyframes(values), options)
|
|
211
|
+
takeShadow(target, values)
|
|
212
|
+
return playback
|
|
213
|
+
},
|
|
214
|
+
set(values) {
|
|
215
|
+
const playback = owner.set(target, values)
|
|
216
|
+
takeShadow(target, values)
|
|
217
|
+
return playback
|
|
218
|
+
},
|
|
192
219
|
motionValue: (initial) => owner.motionValue(initial),
|
|
193
220
|
bind(values) {
|
|
194
221
|
// Spring wrappers retain their public handle, rather than registering a second clock.
|
|
@@ -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
|
+
}
|
package/src/visual-effects.ts
CHANGED
|
@@ -13,6 +13,15 @@ import {
|
|
|
13
13
|
} from '@getcortexlabs/mavis-core/experimental'
|
|
14
14
|
|
|
15
15
|
const circles = new WeakMap<HTMLElement, { dispose(): void }>()
|
|
16
|
+
/** No shadow, or one outer shadow without spread: the shape shared with iOS. */
|
|
17
|
+
function singleShadow(target: HTMLElement) {
|
|
18
|
+
const shadow = target.ownerDocument.defaultView!.getComputedStyle(target).boxShadow
|
|
19
|
+
if (!shadow || shadow === 'none') return true
|
|
20
|
+
const flat = shadow.replace(/\([^)]*\)/g, '')
|
|
21
|
+
if (flat.includes(',') || /\binset\b/.test(flat)) return false
|
|
22
|
+
const lengths = flat.match(/-?[\d.]+px/g) ?? []
|
|
23
|
+
return lengths.length >= 2 && lengths.length <= 4 && parseFloat(lengths[3] ?? '0') === 0
|
|
24
|
+
}
|
|
16
25
|
export function webVisualEffects(
|
|
17
26
|
owner: WebRuntime | WebMotionScope,
|
|
18
27
|
target: HTMLElement,
|
|
@@ -33,7 +42,9 @@ export function webVisualEffects(
|
|
|
33
42
|
? plainText()
|
|
34
43
|
: effect === 'image' || effect === 'liquid'
|
|
35
44
|
? target.tagName === 'IMG'
|
|
36
|
-
:
|
|
45
|
+
: effect === 'shadow'
|
|
46
|
+
? singleShadow(target)
|
|
47
|
+
: true,
|
|
37
48
|
gradient(options) {
|
|
38
49
|
const paint = owner.gradient(target, options)
|
|
39
50
|
return {
|