@cognitap/radiant 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -368
- package/README.md +41 -1006
- package/RELEASE_POLICY.md +3 -3
- package/dist/library/Accordion.d.ts +3 -0
- package/dist/library/Accordion.d.ts.map +1 -1
- package/dist/library/Accordion.js +1 -1
- package/dist/library/Accordion.js.map +1 -1
- package/dist/library/Button.d.ts +8 -1
- package/dist/library/Button.d.ts.map +1 -1
- package/dist/library/Button.js +44 -2
- package/dist/library/Button.js.map +1 -1
- package/dist/library/Card.d.ts +2 -0
- package/dist/library/Card.d.ts.map +1 -1
- package/dist/library/Card.js +1 -1
- package/dist/library/Card.js.map +1 -1
- package/dist/library/Checkbox.d.ts +5 -0
- package/dist/library/Checkbox.d.ts.map +1 -1
- package/dist/library/Checkbox.js +3 -2
- package/dist/library/Checkbox.js.map +1 -1
- package/dist/library/Collapsible.d.ts +6 -1
- package/dist/library/Collapsible.d.ts.map +1 -1
- package/dist/library/Collapsible.js +24 -3
- package/dist/library/Collapsible.js.map +1 -1
- package/dist/library/Dialog.d.ts +5 -1
- package/dist/library/Dialog.d.ts.map +1 -1
- package/dist/library/Dialog.js +5 -2
- package/dist/library/Dialog.js.map +1 -1
- package/dist/library/Field.d.ts +8 -0
- package/dist/library/Field.d.ts.map +1 -1
- package/dist/library/Field.js +2 -0
- package/dist/library/Field.js.map +1 -1
- package/dist/library/Input.d.ts +3 -0
- package/dist/library/Input.d.ts.map +1 -1
- package/dist/library/Input.js +1 -0
- package/dist/library/Input.js.map +1 -1
- package/dist/library/Link.d.ts +5 -0
- package/dist/library/Link.d.ts.map +1 -1
- package/dist/library/Link.js.map +1 -1
- package/dist/library/RadioGroup.d.ts +8 -0
- package/dist/library/RadioGroup.d.ts.map +1 -1
- package/dist/library/RadioGroup.js +4 -2
- package/dist/library/RadioGroup.js.map +1 -1
- package/dist/library/ThemeScope.d.ts.map +1 -1
- package/dist/library/ThemeScope.js +10 -9
- package/dist/library/ThemeScope.js.map +1 -1
- package/dist/library/examples/expressive.d.ts +4 -0
- package/dist/library/examples/expressive.d.ts.map +1 -0
- package/dist/library/{themes → examples}/expressive.js +4 -3
- package/dist/library/examples/expressive.js.map +1 -0
- package/dist/library/examples/glass.d.ts +4 -0
- package/dist/library/examples/glass.d.ts.map +1 -0
- package/dist/library/{themes → examples}/glass.js +4 -3
- package/dist/library/examples/glass.js.map +1 -0
- package/dist/library/examples/index.d.ts +13 -0
- package/dist/library/examples/index.d.ts.map +1 -0
- package/dist/library/examples/index.js +32 -0
- package/dist/library/examples/index.js.map +1 -0
- package/dist/library/examples/jelly.d.ts +4 -0
- package/dist/library/examples/jelly.d.ts.map +1 -0
- package/dist/library/{themes → examples}/jelly.js +4 -3
- package/dist/library/examples/jelly.js.map +1 -0
- package/dist/library/examples/preset-values.d.ts.map +1 -0
- package/dist/library/examples/preset-values.js.map +1 -0
- package/dist/library/examples/radiant.d.ts +4 -0
- package/dist/library/examples/radiant.d.ts.map +1 -0
- package/dist/library/{themes → examples}/radiant.js +4 -3
- package/dist/library/examples/radiant.js.map +1 -0
- package/dist/library/examples/sharp-3d.d.ts +4 -0
- package/dist/library/examples/sharp-3d.d.ts.map +1 -0
- package/dist/library/{themes → examples}/sharp-3d.js +4 -3
- package/dist/library/examples/sharp-3d.js.map +1 -0
- package/dist/library/examples/soft-squircle.d.ts +4 -0
- package/dist/library/examples/soft-squircle.d.ts.map +1 -0
- package/dist/library/{themes → examples}/soft-squircle.js +4 -3
- package/dist/library/examples/soft-squircle.js.map +1 -0
- package/dist/library/examples/ticket.d.ts +4 -0
- package/dist/library/examples/ticket.d.ts.map +1 -0
- package/dist/library/{themes → examples}/ticket.js +4 -3
- package/dist/library/examples/ticket.js.map +1 -0
- package/dist/library/index.d.ts +4 -2
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +2 -1
- package/dist/library/index.js.map +1 -1
- package/dist/library/motion/MotionLink.d.ts +8 -0
- package/dist/library/motion/MotionLink.d.ts.map +1 -0
- package/dist/library/motion/MotionLink.js +44 -0
- package/dist/library/motion/MotionLink.js.map +1 -0
- package/dist/library/motion/browser.d.ts +5 -0
- package/dist/library/motion/browser.d.ts.map +1 -0
- package/dist/library/motion/browser.js +35 -0
- package/dist/library/motion/browser.js.map +1 -0
- package/dist/library/motion/config.d.ts +26 -0
- package/dist/library/motion/config.d.ts.map +1 -0
- package/dist/library/motion/config.js +58 -0
- package/dist/library/motion/config.js.map +1 -0
- package/dist/library/motion/context.d.ts +2 -0
- package/dist/library/motion/context.d.ts.map +1 -0
- package/dist/library/motion/context.js +5 -0
- package/dist/library/motion/context.js.map +1 -0
- package/dist/library/motion/drag.d.ts +20 -0
- package/dist/library/motion/drag.d.ts.map +1 -0
- package/dist/library/motion/drag.js +138 -0
- package/dist/library/motion/drag.js.map +1 -0
- package/dist/library/motion/dragBrowser.d.ts +4 -0
- package/dist/library/motion/dragBrowser.d.ts.map +1 -0
- package/dist/library/motion/dragBrowser.js +156 -0
- package/dist/library/motion/dragBrowser.js.map +1 -0
- package/dist/library/motion/follow.d.ts +9 -0
- package/dist/library/motion/follow.d.ts.map +1 -0
- package/dist/library/motion/follow.js +26 -0
- package/dist/library/motion/follow.js.map +1 -0
- package/dist/library/motion/host.d.ts +30 -0
- package/dist/library/motion/host.d.ts.map +1 -0
- package/dist/library/motion/host.js +70 -0
- package/dist/library/motion/host.js.map +1 -0
- package/dist/library/motion/index.d.ts +16 -0
- package/dist/library/motion/index.d.ts.map +1 -0
- package/dist/library/motion/index.js +9 -0
- package/dist/library/motion/index.js.map +1 -0
- package/dist/library/motion/layout.d.ts +20 -0
- package/dist/library/motion/layout.d.ts.map +1 -0
- package/dist/library/motion/layout.js +67 -0
- package/dist/library/motion/layout.js.map +1 -0
- package/dist/library/motion/layoutDom.d.ts +17 -0
- package/dist/library/motion/layoutDom.d.ts.map +1 -0
- package/dist/library/motion/layoutDom.js +272 -0
- package/dist/library/motion/layoutDom.js.map +1 -0
- package/dist/library/motion/press.d.ts +5 -0
- package/dist/library/motion/press.d.ts.map +1 -0
- package/dist/library/motion/press.js +99 -0
- package/dist/library/motion/press.js.map +1 -0
- package/dist/library/motion/pressPolicy.d.ts +5 -0
- package/dist/library/motion/pressPolicy.d.ts.map +1 -0
- package/dist/library/motion/pressPolicy.js +8 -0
- package/dist/library/motion/pressPolicy.js.map +1 -0
- package/dist/library/motion/react.d.ts +35 -0
- package/dist/library/motion/react.d.ts.map +1 -0
- package/dist/library/motion/react.js +224 -0
- package/dist/library/motion/react.js.map +1 -0
- package/dist/library/motion/runtime.d.ts +22 -0
- package/dist/library/motion/runtime.d.ts.map +1 -0
- package/dist/library/motion/runtime.js +117 -0
- package/dist/library/motion/runtime.js.map +1 -0
- package/dist/library/motion/transitions.d.ts +5 -0
- package/dist/library/motion/transitions.d.ts.map +1 -0
- package/dist/library/motion/transitions.js +244 -0
- package/dist/library/motion/transitions.js.map +1 -0
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/defineTheme.d.ts +3 -0
- package/dist/library/themes/defineTheme.d.ts.map +1 -1
- package/dist/library/themes/defineTheme.js +4 -2
- package/dist/library/themes/defineTheme.js.map +1 -1
- package/dist/library/themes/index.d.ts +2 -12
- package/dist/library/themes/index.d.ts.map +1 -1
- package/dist/library/themes/index.js +1 -19
- package/dist/library/themes/index.js.map +1 -1
- package/dist/library/themes/themeDocument.d.ts.map +1 -1
- package/dist/library/themes/themeDocument.js +11 -5
- package/dist/library/themes/themeDocument.js.map +1 -1
- package/dist/library/themes/themeDocumentTypes.d.ts +5 -1
- package/dist/library/themes/themeDocumentTypes.d.ts.map +1 -1
- package/dist/library/themes/themeDocumentTypes.js.map +1 -1
- package/docs/accessibility.md +76 -142
- package/docs/architecture.md +197 -0
- package/docs/motion.md +153 -0
- package/docs/theming.md +275 -882
- package/package.json +22 -7
- package/src/Accordion.tsx +4 -1
- package/src/Button.tsx +55 -1
- package/src/Card.tsx +3 -1
- package/src/Checkbox.tsx +7 -2
- package/src/Collapsible.tsx +38 -2
- package/src/Dialog.tsx +13 -1
- package/src/Field.tsx +8 -0
- package/src/Input.tsx +3 -0
- package/src/Link.tsx +5 -0
- package/src/RadioGroup.tsx +10 -2
- package/src/ThemeScope.tsx +21 -17
- package/src/{themes → examples}/expressive.ts +5 -3
- package/src/{themes → examples}/glass.ts +5 -3
- package/src/examples/index.ts +35 -0
- package/src/{themes → examples}/jelly.ts +5 -3
- package/src/{themes → examples}/radiant.ts +5 -3
- package/src/{themes → examples}/sharp-3d.ts +5 -3
- package/src/{themes → examples}/soft-squircle.ts +5 -3
- package/src/{themes → examples}/ticket.ts +5 -3
- package/src/index.ts +10 -13
- package/src/motion/MotionLink.tsx +69 -0
- package/src/motion/browser.ts +45 -0
- package/src/motion/config.ts +79 -0
- package/src/motion/context.ts +4 -0
- package/src/motion/drag.ts +151 -0
- package/src/motion/dragBrowser.ts +159 -0
- package/src/motion/follow.ts +28 -0
- package/src/motion/host.ts +96 -0
- package/src/motion/index.ts +28 -0
- package/src/motion/layout.ts +78 -0
- package/src/motion/layoutDom.ts +293 -0
- package/src/motion/press.ts +97 -0
- package/src/motion/pressPolicy.ts +14 -0
- package/src/motion/react.ts +272 -0
- package/src/motion/runtime.ts +122 -0
- package/src/motion/transitions.ts +237 -0
- package/src/themes/defineTheme.ts +10 -2
- package/src/themes/index.ts +2 -22
- package/src/themes/themeDocument.ts +14 -6
- package/src/themes/themeDocumentTypes.ts +12 -5
- package/dist/library/themes/expressive.d.ts +0 -2
- package/dist/library/themes/expressive.d.ts.map +0 -1
- package/dist/library/themes/expressive.js.map +0 -1
- package/dist/library/themes/glass.d.ts +0 -2
- package/dist/library/themes/glass.d.ts.map +0 -1
- package/dist/library/themes/glass.js.map +0 -1
- package/dist/library/themes/jelly.d.ts +0 -2
- package/dist/library/themes/jelly.d.ts.map +0 -1
- package/dist/library/themes/jelly.js.map +0 -1
- package/dist/library/themes/preset-values.d.ts.map +0 -1
- package/dist/library/themes/preset-values.js.map +0 -1
- package/dist/library/themes/radiant.d.ts +0 -2
- package/dist/library/themes/radiant.d.ts.map +0 -1
- package/dist/library/themes/radiant.js.map +0 -1
- package/dist/library/themes/sharp-3d.d.ts +0 -2
- package/dist/library/themes/sharp-3d.d.ts.map +0 -1
- package/dist/library/themes/sharp-3d.js.map +0 -1
- package/dist/library/themes/soft-squircle.d.ts +0 -2
- package/dist/library/themes/soft-squircle.d.ts.map +0 -1
- package/dist/library/themes/soft-squircle.js.map +0 -1
- package/dist/library/themes/ticket.d.ts +0 -2
- package/dist/library/themes/ticket.d.ts.map +0 -1
- package/dist/library/themes/ticket.js.map +0 -1
- package/docs/system.md +0 -238
- /package/dist/library/{themes → examples}/preset-values.d.ts +0 -0
- /package/dist/library/{themes → examples}/preset-values.js +0 -0
- /package/src/{themes → examples}/preset-values.ts +0 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import {
|
|
3
|
+
useContext,
|
|
4
|
+
useEffect,
|
|
5
|
+
useLayoutEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
useSyncExternalStore,
|
|
9
|
+
type RefObject
|
|
10
|
+
} from 'react'
|
|
11
|
+
import { createElement, type ReactNode } from 'react'
|
|
12
|
+
import { MotionHostContext } from './host.js'
|
|
13
|
+
import { bindDisclosureMotion, bindDialogMotion } from './transitions.js'
|
|
14
|
+
import { bindPressMotion } from './press.js'
|
|
15
|
+
import { MotionProfileContext } from './context.js'
|
|
16
|
+
import { resolveMotion, type MotionInteraction } from './config.js'
|
|
17
|
+
import { createSpringDrag, type SpringDragController, type SpringDragOptions } from './drag.js'
|
|
18
|
+
import { bindSpringDrag } from './dragBrowser.js'
|
|
19
|
+
import { createSpring, type SpringController } from './runtime.js'
|
|
20
|
+
import { bindSpringStyle, type SpringStyleProperty } from './browser.js'
|
|
21
|
+
import { bindSpringSource, type SpringSource } from './follow.js'
|
|
22
|
+
import { bindSpringLayout, type SpringLayoutController } from './layoutDom.js'
|
|
23
|
+
|
|
24
|
+
// Start conservatively for SSR/hydration; only subscribing reads the browser.
|
|
25
|
+
const listeners = new Set<() => void>()
|
|
26
|
+
let query: MediaQueryList | undefined
|
|
27
|
+
function subscribeReduced(listener: () => void) {
|
|
28
|
+
if (!query) query = window.matchMedia('(prefers-reduced-motion: reduce)')
|
|
29
|
+
const current = query
|
|
30
|
+
const notify = () => listener()
|
|
31
|
+
listeners.add(notify)
|
|
32
|
+
current.addEventListener('change', notify)
|
|
33
|
+
return () => {
|
|
34
|
+
listeners.delete(notify)
|
|
35
|
+
current.removeEventListener('change', notify)
|
|
36
|
+
if (!listeners.size) query = undefined
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function useReducedMotion(): boolean {
|
|
40
|
+
return useSyncExternalStore(
|
|
41
|
+
subscribeReduced,
|
|
42
|
+
() => query?.matches ?? true,
|
|
43
|
+
() => true
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
export function useSpring(
|
|
47
|
+
initial: number,
|
|
48
|
+
interaction: MotionInteraction = 'follow',
|
|
49
|
+
reducedValue?: number
|
|
50
|
+
): SpringController {
|
|
51
|
+
const profile = useContext(MotionProfileContext)
|
|
52
|
+
const reduced = useReducedMotion()
|
|
53
|
+
const resolved = resolveMotion(profile, interaction, reduced)
|
|
54
|
+
const owned = useRef<SpringController | null>(null)
|
|
55
|
+
const requested = useRef(initial)
|
|
56
|
+
const requestedVelocity = useRef<number | undefined>(undefined)
|
|
57
|
+
const callbacks = useRef(new Set<(value: number) => void>())
|
|
58
|
+
const initialOptions = useRef({ ...resolved, reducedValue })
|
|
59
|
+
const policy = useRef(resolved.enabled)
|
|
60
|
+
const initialValue = useRef(initial)
|
|
61
|
+
const [controller] = useState<SpringController>(() => ({
|
|
62
|
+
get: () => owned.current?.get() ?? requested.current,
|
|
63
|
+
getVelocity: () => owned.current?.getVelocity() ?? 0,
|
|
64
|
+
isAnimating: () => owned.current?.isAnimating() ?? false,
|
|
65
|
+
to(next, velocity) {
|
|
66
|
+
if (velocity !== undefined && !Number.isFinite(velocity))
|
|
67
|
+
throw new TypeError('Velocity must be finite.')
|
|
68
|
+
requestedVelocity.current = velocity
|
|
69
|
+
if (!Number.isFinite(next)) throw new TypeError('Spring value must be finite.')
|
|
70
|
+
requested.current = next
|
|
71
|
+
owned.current?.to(next, velocity)
|
|
72
|
+
},
|
|
73
|
+
jump(next) {
|
|
74
|
+
if (!Number.isFinite(next)) throw new TypeError('Spring value must be finite.')
|
|
75
|
+
requested.current = next
|
|
76
|
+
owned.current?.jump(next)
|
|
77
|
+
},
|
|
78
|
+
stop() {
|
|
79
|
+
owned.current?.stop()
|
|
80
|
+
requested.current = owned.current?.get() ?? requested.current
|
|
81
|
+
},
|
|
82
|
+
configure(next) {
|
|
83
|
+
owned.current?.configure({ ...next, enabled: policy.current && (next.enabled ?? true) })
|
|
84
|
+
},
|
|
85
|
+
subscribe(listener) {
|
|
86
|
+
callbacks.current.add(listener)
|
|
87
|
+
return () => {
|
|
88
|
+
callbacks.current.delete(listener)
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
destroy() {
|
|
92
|
+
owned.current?.destroy()
|
|
93
|
+
}
|
|
94
|
+
}))
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
const spring = createSpring(initialValue.current, initialOptions.current)
|
|
97
|
+
owned.current = spring
|
|
98
|
+
const off = spring.subscribe(next => callbacks.current.forEach(listener => listener(next)))
|
|
99
|
+
spring.to(requested.current, requestedVelocity.current)
|
|
100
|
+
return () => {
|
|
101
|
+
off()
|
|
102
|
+
spring.destroy()
|
|
103
|
+
owned.current = null
|
|
104
|
+
}
|
|
105
|
+
}, [])
|
|
106
|
+
const { stiffness, damping, mass } = resolved.parameters
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
policy.current = resolved.enabled
|
|
109
|
+
owned.current?.configure({
|
|
110
|
+
enabled: resolved.enabled,
|
|
111
|
+
parameters: { stiffness, damping, mass },
|
|
112
|
+
reducedValue
|
|
113
|
+
})
|
|
114
|
+
}, [resolved.enabled, stiffness, damping, mass, reducedValue])
|
|
115
|
+
return controller
|
|
116
|
+
}
|
|
117
|
+
/** Use the real native ref; events/state remain with the component and caller. */
|
|
118
|
+
export function useSpringStyle(
|
|
119
|
+
ref: RefObject<HTMLElement | null>,
|
|
120
|
+
property: SpringStyleProperty,
|
|
121
|
+
initial: number,
|
|
122
|
+
interaction: MotionInteraction = 'follow',
|
|
123
|
+
reducedValue?: number
|
|
124
|
+
): SpringController {
|
|
125
|
+
const spring = useSpring(initial, interaction, reducedValue)
|
|
126
|
+
// Rebind after every commit to handle a replaced render host; no animation state enters React.
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (!ref.current) return
|
|
129
|
+
return bindSpringStyle(ref.current, spring, property)
|
|
130
|
+
})
|
|
131
|
+
return spring
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const hostRuntime = {
|
|
135
|
+
press: bindPressMotion,
|
|
136
|
+
disclosure: bindDisclosureMotion,
|
|
137
|
+
dialog: bindDialogMotion
|
|
138
|
+
}
|
|
139
|
+
/** Opt into native Radiant spring interactions without adding a DOM wrapper. */
|
|
140
|
+
export function MotionProvider({ children }: { children?: ReactNode }) {
|
|
141
|
+
return createElement(MotionHostContext.Provider, { value: hostRuntime }, children)
|
|
142
|
+
}
|
|
143
|
+
export { MotionLink } from './MotionLink.js'
|
|
144
|
+
export type { MotionLinkProps } from './MotionLink.js'
|
|
145
|
+
|
|
146
|
+
/** Dedicated one-axis handle binding; explicit native keyboard controls are retained. */
|
|
147
|
+
export function useSpringDrag(
|
|
148
|
+
ref: RefObject<HTMLElement | null>,
|
|
149
|
+
initial: number,
|
|
150
|
+
options: Omit<SpringDragOptions, 'parameters' | 'enabled'> & { axis?: 'x' | 'y' }
|
|
151
|
+
) {
|
|
152
|
+
const profile = useContext(MotionProfileContext)
|
|
153
|
+
const reduced = useReducedMotion()
|
|
154
|
+
const resolved = resolveMotion(profile, 'drag', reduced)
|
|
155
|
+
const latest = useRef({ initial, options, resolved })
|
|
156
|
+
const owned = useRef<SpringDragController | null>(null)
|
|
157
|
+
const [control] = useState(() => ({
|
|
158
|
+
get: () => owned.current?.get() ?? initial,
|
|
159
|
+
getVelocity: () => owned.current?.getVelocity() ?? 0,
|
|
160
|
+
subscribe: (listener: (value: number) => void) =>
|
|
161
|
+
owned.current?.subscribe(listener) ?? (() => {}),
|
|
162
|
+
to: (target: number) => owned.current?.to(target),
|
|
163
|
+
cancel: () => owned.current?.cancel(),
|
|
164
|
+
step: (direction: -1 | 1 | 'first' | 'last') => owned.current?.step(direction),
|
|
165
|
+
isAnimating: () => owned.current?.isAnimating() ?? false
|
|
166
|
+
}))
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
const current = latest.current
|
|
169
|
+
const drag = createSpringDrag(current.initial, { ...current.options, ...current.resolved })
|
|
170
|
+
owned.current = drag
|
|
171
|
+
return () => {
|
|
172
|
+
drag.destroy()
|
|
173
|
+
owned.current = null
|
|
174
|
+
}
|
|
175
|
+
}, [])
|
|
176
|
+
const points = options.snapPoints?.join(',')
|
|
177
|
+
const { stiffness, damping, mass } = resolved.parameters
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
owned.current?.configure({
|
|
180
|
+
min: options.min,
|
|
181
|
+
max: options.max,
|
|
182
|
+
snapPoints: points?.split(',').map(Number),
|
|
183
|
+
parameters: { stiffness, damping, mass },
|
|
184
|
+
enabled: resolved.enabled
|
|
185
|
+
})
|
|
186
|
+
}, [options.min, options.max, points, stiffness, damping, mass, resolved.enabled])
|
|
187
|
+
const binding = useRef<{
|
|
188
|
+
node: HTMLElement
|
|
189
|
+
axis: 'x' | 'y' | undefined
|
|
190
|
+
cleanup: () => void
|
|
191
|
+
} | null>(null)
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
if (
|
|
194
|
+
binding.current &&
|
|
195
|
+
(binding.current.node !== ref.current || binding.current.axis !== options.axis)
|
|
196
|
+
) {
|
|
197
|
+
binding.current.cleanup()
|
|
198
|
+
binding.current = null
|
|
199
|
+
}
|
|
200
|
+
if (!binding.current && ref.current && owned.current)
|
|
201
|
+
binding.current = {
|
|
202
|
+
node: ref.current,
|
|
203
|
+
axis: options.axis,
|
|
204
|
+
cleanup: bindSpringDrag(ref.current, owned.current, options.axis)
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
useEffect(
|
|
208
|
+
() => () => {
|
|
209
|
+
binding.current?.cleanup()
|
|
210
|
+
binding.current = null
|
|
211
|
+
},
|
|
212
|
+
[]
|
|
213
|
+
)
|
|
214
|
+
return control
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Follow committed numeric props or an external source without rendering each spring frame. */
|
|
218
|
+
export function useSpringFollow(
|
|
219
|
+
target: number | SpringSource,
|
|
220
|
+
interaction: MotionInteraction = 'follow',
|
|
221
|
+
reducedValue?: number
|
|
222
|
+
): SpringController {
|
|
223
|
+
const spring = useSpring(
|
|
224
|
+
typeof target === 'number' ? target : target.get(),
|
|
225
|
+
interaction,
|
|
226
|
+
reducedValue
|
|
227
|
+
)
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
if (typeof target === 'number') spring.to(target)
|
|
230
|
+
else return bindSpringSource(spring, target)
|
|
231
|
+
}, [spring, target])
|
|
232
|
+
return spring
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Batch direct-child layout slots after each commit and observe later intrinsic changes. */
|
|
236
|
+
export function useSpringLayout(
|
|
237
|
+
ref: RefObject<HTMLElement | null>
|
|
238
|
+
): Pick<SpringLayoutController, 'measure' | 'get' | 'getVelocity' | 'isAnimating'> {
|
|
239
|
+
const profile = useContext(MotionProfileContext)
|
|
240
|
+
const reduced = useReducedMotion()
|
|
241
|
+
const resolved = resolveMotion(profile, 'layout', reduced)
|
|
242
|
+
const binding = useRef<{ node: HTMLElement; controller: SpringLayoutController } | null>(null)
|
|
243
|
+
const [controller] = useState<
|
|
244
|
+
Pick<SpringLayoutController, 'measure' | 'get' | 'getVelocity' | 'isAnimating'>
|
|
245
|
+
>(() => ({
|
|
246
|
+
measure: () => binding.current?.controller.measure(),
|
|
247
|
+
get: slot => binding.current?.controller.get(slot),
|
|
248
|
+
getVelocity: slot => binding.current?.controller.getVelocity(slot),
|
|
249
|
+
isAnimating: () => binding.current?.controller.isAnimating() ?? false
|
|
250
|
+
}))
|
|
251
|
+
useLayoutEffect(() => {
|
|
252
|
+
if (binding.current?.node !== ref.current) {
|
|
253
|
+
binding.current?.controller.destroy()
|
|
254
|
+
binding.current = null
|
|
255
|
+
}
|
|
256
|
+
if (!ref.current) return
|
|
257
|
+
if (!binding.current)
|
|
258
|
+
binding.current = { node: ref.current, controller: bindSpringLayout(ref.current, resolved) }
|
|
259
|
+
else {
|
|
260
|
+
binding.current.controller.configure(resolved)
|
|
261
|
+
binding.current.controller.measure()
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
useLayoutEffect(
|
|
265
|
+
() => () => {
|
|
266
|
+
binding.current?.controller.destroy()
|
|
267
|
+
binding.current = null
|
|
268
|
+
},
|
|
269
|
+
[]
|
|
270
|
+
)
|
|
271
|
+
return controller
|
|
272
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { springValue } from 'motion'
|
|
2
|
+
import { resolveSpringParameters, type SpringParameters } from './config.js'
|
|
3
|
+
|
|
4
|
+
export interface SpringOptions {
|
|
5
|
+
readonly parameters?: Partial<SpringParameters>
|
|
6
|
+
readonly enabled?: boolean
|
|
7
|
+
/** Presentation neutral (e.g. scale 1); otherwise off snaps to the latest goal. */
|
|
8
|
+
readonly reducedValue?: number
|
|
9
|
+
}
|
|
10
|
+
export interface SpringController {
|
|
11
|
+
get(): number
|
|
12
|
+
getVelocity(): number
|
|
13
|
+
isAnimating(): boolean
|
|
14
|
+
to(target: number, velocity?: number): void
|
|
15
|
+
jump(target: number): void
|
|
16
|
+
/** Stop at the current presentation and discard the old goal. */
|
|
17
|
+
stop(): void
|
|
18
|
+
configure(options: SpringOptions): void
|
|
19
|
+
subscribe(listener: (value: number) => void): () => void
|
|
20
|
+
destroy(): void
|
|
21
|
+
}
|
|
22
|
+
function finite(value: number) {
|
|
23
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
24
|
+
throw new TypeError('Spring values must be finite numbers in one consistent unit.')
|
|
25
|
+
return value
|
|
26
|
+
}
|
|
27
|
+
function same(a: SpringParameters, b: SpringParameters) {
|
|
28
|
+
return a.stiffness === b.stiffness && a.damping === b.damping && a.mass === b.mass
|
|
29
|
+
}
|
|
30
|
+
/** One persistent upstream follower; numeric values only, no DOM or React ownership. */
|
|
31
|
+
export function createSpring(initial: number, options: SpringOptions = {}): SpringController {
|
|
32
|
+
let parameters = resolveSpringParameters(options.parameters)
|
|
33
|
+
let pending = parameters
|
|
34
|
+
let value = springValue(finite(initial), parameters)
|
|
35
|
+
let enabled = options.enabled ?? true
|
|
36
|
+
let reducedValue = options.reducedValue === undefined ? undefined : finite(options.reducedValue)
|
|
37
|
+
let target = initial
|
|
38
|
+
let destroyed = false
|
|
39
|
+
const listeners = new Set<(value: number) => void>()
|
|
40
|
+
let offChange: () => void
|
|
41
|
+
let offComplete: () => void
|
|
42
|
+
function attach() {
|
|
43
|
+
offChange = value.on('change', next => listeners.forEach(listener => listener(next)))
|
|
44
|
+
offComplete = value.on('animationComplete', applyPending)
|
|
45
|
+
}
|
|
46
|
+
function applyPending() {
|
|
47
|
+
if (destroyed || same(parameters, pending)) return
|
|
48
|
+
const current = value.get()
|
|
49
|
+
offChange()
|
|
50
|
+
offComplete()
|
|
51
|
+
value.destroy()
|
|
52
|
+
parameters = pending
|
|
53
|
+
value = springValue(current, parameters)
|
|
54
|
+
attach()
|
|
55
|
+
}
|
|
56
|
+
attach()
|
|
57
|
+
const controller: SpringController = {
|
|
58
|
+
get: () => value.get(),
|
|
59
|
+
getVelocity: () => (destroyed ? 0 : value.getVelocity()),
|
|
60
|
+
isAnimating: () => !destroyed && value.isAnimating(),
|
|
61
|
+
to(next, velocity) {
|
|
62
|
+
finite(next)
|
|
63
|
+
if (velocity !== undefined) finite(velocity)
|
|
64
|
+
if (destroyed) return
|
|
65
|
+
target = next
|
|
66
|
+
if (enabled) {
|
|
67
|
+
if (velocity !== undefined) {
|
|
68
|
+
const current = value.get()
|
|
69
|
+
value.jump(current)
|
|
70
|
+
applyPending()
|
|
71
|
+
value.setWithVelocity(current - velocity / 60, current, 1000 / 60)
|
|
72
|
+
}
|
|
73
|
+
value.set(next)
|
|
74
|
+
} else value.jump(reducedValue ?? target)
|
|
75
|
+
},
|
|
76
|
+
jump(next) {
|
|
77
|
+
finite(next)
|
|
78
|
+
if (destroyed) return
|
|
79
|
+
target = next
|
|
80
|
+
value.jump(enabled ? next : (reducedValue ?? next))
|
|
81
|
+
applyPending()
|
|
82
|
+
},
|
|
83
|
+
stop() {
|
|
84
|
+
if (destroyed) return
|
|
85
|
+
target = value.get()
|
|
86
|
+
value.jump(target)
|
|
87
|
+
applyPending()
|
|
88
|
+
},
|
|
89
|
+
configure(next) {
|
|
90
|
+
const resolved = resolveSpringParameters(next.parameters, pending)
|
|
91
|
+
const neutral = Object.hasOwn(next, 'reducedValue')
|
|
92
|
+
? next.reducedValue === undefined
|
|
93
|
+
? undefined
|
|
94
|
+
: finite(next.reducedValue)
|
|
95
|
+
: reducedValue
|
|
96
|
+
if (destroyed) return
|
|
97
|
+
pending = resolved
|
|
98
|
+
reducedValue = neutral
|
|
99
|
+
enabled = next.enabled ?? enabled
|
|
100
|
+
if (!enabled) value.jump(reducedValue ?? target)
|
|
101
|
+
// Parameter changes take effect at rest, so in-flight momentum is never replaced.
|
|
102
|
+
if (!value.isAnimating()) applyPending()
|
|
103
|
+
},
|
|
104
|
+
subscribe(listener) {
|
|
105
|
+
if (destroyed) return () => {}
|
|
106
|
+
listeners.add(listener)
|
|
107
|
+
return () => {
|
|
108
|
+
listeners.delete(listener)
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
destroy() {
|
|
112
|
+
if (destroyed) return
|
|
113
|
+
destroyed = true
|
|
114
|
+
offChange()
|
|
115
|
+
offComplete()
|
|
116
|
+
value.destroy()
|
|
117
|
+
listeners.clear()
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (!enabled) value.jump(reducedValue ?? target)
|
|
121
|
+
return controller
|
|
122
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { createSpring } from './runtime.js'
|
|
2
|
+
import { bindSpringStyle } from './browser.js'
|
|
3
|
+
import { resolveMotion, type MotionProfile } from './config.js'
|
|
4
|
+
import type { MotionHostBinding } from './host.js'
|
|
5
|
+
|
|
6
|
+
export function bindDisclosureMotion(host: HTMLElement, initial: MotionProfile): MotionHostBinding {
|
|
7
|
+
const node = host as HTMLDetailsElement
|
|
8
|
+
let profile = initial
|
|
9
|
+
const query = node.ownerDocument.defaultView!.matchMedia('(prefers-reduced-motion: reduce)')
|
|
10
|
+
const contents = () =>
|
|
11
|
+
Array.from(node.children).filter(
|
|
12
|
+
(child): child is HTMLElement => child instanceof HTMLElement && child.tagName !== 'SUMMARY'
|
|
13
|
+
)
|
|
14
|
+
const measure = () =>
|
|
15
|
+
contents().reduce((sum, child) => sum + child.getBoundingClientRect().height, 0)
|
|
16
|
+
const previous = node.style.getPropertyValue('--_rad-spring-details-height')
|
|
17
|
+
const spring = createSpring(
|
|
18
|
+
node.open ? measure() : 0,
|
|
19
|
+
resolveMotion(profile, 'disclosure', query.matches)
|
|
20
|
+
)
|
|
21
|
+
const saved = new Map<HTMLElement, { inert: boolean; hidden: string | null }>()
|
|
22
|
+
const render = (value: number) =>
|
|
23
|
+
node.style.setProperty('--_rad-spring-details-height', `${Math.max(0, value)}px`)
|
|
24
|
+
const off = spring.subscribe(render)
|
|
25
|
+
render(spring.get())
|
|
26
|
+
const observed = new Set<HTMLElement>()
|
|
27
|
+
function sync() {
|
|
28
|
+
const current = new Set(contents())
|
|
29
|
+
for (const child of observed) {
|
|
30
|
+
if (current.has(child)) continue
|
|
31
|
+
resize.unobserve(child)
|
|
32
|
+
restore(child)
|
|
33
|
+
observed.delete(child)
|
|
34
|
+
}
|
|
35
|
+
for (const child of current) {
|
|
36
|
+
if (!observed.has(child)) {
|
|
37
|
+
observed.add(child)
|
|
38
|
+
resize.observe(child)
|
|
39
|
+
}
|
|
40
|
+
if (!node.open) {
|
|
41
|
+
if (!saved.has(child))
|
|
42
|
+
saved.set(child, { inert: child.inert, hidden: child.getAttribute('aria-hidden') })
|
|
43
|
+
child.inert = true
|
|
44
|
+
child.setAttribute('aria-hidden', 'true')
|
|
45
|
+
} else restore(child)
|
|
46
|
+
}
|
|
47
|
+
spring.to(node.open ? measure() : 0)
|
|
48
|
+
}
|
|
49
|
+
function restore(child: HTMLElement) {
|
|
50
|
+
const prior = saved.get(child)
|
|
51
|
+
if (!prior) return
|
|
52
|
+
child.inert = prior.inert
|
|
53
|
+
if (prior.hidden === null) child.removeAttribute('aria-hidden')
|
|
54
|
+
else child.setAttribute('aria-hidden', prior.hidden)
|
|
55
|
+
saved.delete(child)
|
|
56
|
+
}
|
|
57
|
+
const observer = new MutationObserver(sync)
|
|
58
|
+
observer.observe(node, { attributes: true, attributeFilter: ['open'], childList: true })
|
|
59
|
+
const resize = new ResizeObserver(sync)
|
|
60
|
+
function update(next: MotionProfile) {
|
|
61
|
+
profile = next
|
|
62
|
+
spring.configure(resolveMotion(profile, 'disclosure', query.matches))
|
|
63
|
+
sync()
|
|
64
|
+
}
|
|
65
|
+
const preference = () => update(profile)
|
|
66
|
+
query.addEventListener('change', preference)
|
|
67
|
+
sync()
|
|
68
|
+
return {
|
|
69
|
+
update,
|
|
70
|
+
destroy() {
|
|
71
|
+
observer.disconnect()
|
|
72
|
+
resize.disconnect()
|
|
73
|
+
observed.clear()
|
|
74
|
+
query.removeEventListener('change', preference)
|
|
75
|
+
off()
|
|
76
|
+
spring.destroy()
|
|
77
|
+
for (const child of saved.keys()) restore(child)
|
|
78
|
+
if (previous) node.style.setProperty('--_rad-spring-details-height', previous)
|
|
79
|
+
else node.style.removeProperty('--_rad-spring-details-height')
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function bindDialogMotion(host: HTMLElement, initial: MotionProfile): MotionHostBinding {
|
|
85
|
+
const node = host as HTMLDialogElement
|
|
86
|
+
let profile = initial
|
|
87
|
+
const query = node.ownerDocument.defaultView!.matchMedia('(prefers-reduced-motion: reduce)')
|
|
88
|
+
let open = node.open
|
|
89
|
+
const geometry = () => {
|
|
90
|
+
const style = getComputedStyle(node)
|
|
91
|
+
return {
|
|
92
|
+
left: node.offsetLeft,
|
|
93
|
+
top: node.offsetTop,
|
|
94
|
+
width: node.offsetWidth,
|
|
95
|
+
height: node.offsetHeight,
|
|
96
|
+
variables: Array.from(style)
|
|
97
|
+
.filter(key => key.startsWith('--'))
|
|
98
|
+
.map(key => [key, style.getPropertyValue(key)])
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
let bounds = node.open ? geometry() : null
|
|
102
|
+
let ghost: HTMLDivElement | null = null
|
|
103
|
+
let exitTimer: number | undefined
|
|
104
|
+
const spring = createSpring(open ? 1 : 0.94, {
|
|
105
|
+
...resolveMotion(profile, 'dialog', query.matches),
|
|
106
|
+
reducedValue: open ? 1 : 0.94
|
|
107
|
+
})
|
|
108
|
+
const unbind = bindSpringStyle(node, spring, 'scale')
|
|
109
|
+
function clear() {
|
|
110
|
+
node.ownerDocument.defaultView!.clearTimeout(exitTimer)
|
|
111
|
+
exitTimer = undefined
|
|
112
|
+
ghost?.remove()
|
|
113
|
+
ghost = null
|
|
114
|
+
}
|
|
115
|
+
function snapshot() {
|
|
116
|
+
clear()
|
|
117
|
+
if (!bounds || bounds.width === 0) return
|
|
118
|
+
const descendants = node.querySelectorAll('*')
|
|
119
|
+
// A visual copy is optional: bound its work and avoid activating nested platform lifecycles.
|
|
120
|
+
if (
|
|
121
|
+
descendants.length > 500 ||
|
|
122
|
+
node.hasAttribute('is') ||
|
|
123
|
+
node.parentElement?.closest('dialog[open]') ||
|
|
124
|
+
Array.from(descendants).some(
|
|
125
|
+
child =>
|
|
126
|
+
child.localName.includes('-') ||
|
|
127
|
+
child.hasAttribute('is') ||
|
|
128
|
+
/^(dialog|script|style|link|iframe|object|embed|canvas|video|audio)$/.test(
|
|
129
|
+
child.localName
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
return
|
|
134
|
+
const copy = node.cloneNode(true) as HTMLDialogElement
|
|
135
|
+
ghost = node.ownerDocument.createElement('div')
|
|
136
|
+
for (const attribute of copy.attributes) ghost.setAttribute(attribute.name, attribute.value)
|
|
137
|
+
while (copy.firstChild) ghost.append(copy.firstChild)
|
|
138
|
+
ghost.setAttribute('open', '')
|
|
139
|
+
ghost.removeAttribute('data-slot')
|
|
140
|
+
ghost.setAttribute('role', 'presentation')
|
|
141
|
+
ghost.setAttribute('data-state', 'open')
|
|
142
|
+
ghost.inert = true
|
|
143
|
+
ghost.setAttribute('aria-hidden', 'true')
|
|
144
|
+
ghost.setAttribute('data-rad-motion-exit', '')
|
|
145
|
+
for (const child of [ghost, ...ghost.querySelectorAll('*')]) {
|
|
146
|
+
for (const attribute of Array.from(child.attributes))
|
|
147
|
+
if (attribute.name.toLowerCase().startsWith('on')) child.removeAttribute(attribute.name)
|
|
148
|
+
for (const attribute of ['id', 'name', 'form', 'autofocus']) child.removeAttribute(attribute)
|
|
149
|
+
if (
|
|
150
|
+
child instanceof HTMLInputElement ||
|
|
151
|
+
child instanceof HTMLButtonElement ||
|
|
152
|
+
child instanceof HTMLSelectElement ||
|
|
153
|
+
child instanceof HTMLTextAreaElement
|
|
154
|
+
)
|
|
155
|
+
child.disabled = true
|
|
156
|
+
}
|
|
157
|
+
for (const [key, value] of bounds.variables) ghost.style.setProperty(key, value)
|
|
158
|
+
ghost.style.font = getComputedStyle(node).font
|
|
159
|
+
ghost.style.colorScheme = getComputedStyle(node).colorScheme
|
|
160
|
+
Object.assign(ghost.style, {
|
|
161
|
+
position: 'fixed',
|
|
162
|
+
margin: '0px',
|
|
163
|
+
left: `${bounds.left}px`,
|
|
164
|
+
top: `${bounds.top}px`,
|
|
165
|
+
width: `${bounds.width}px`,
|
|
166
|
+
height: `${bounds.height}px`,
|
|
167
|
+
maxHeight: 'none',
|
|
168
|
+
pointerEvents: 'none',
|
|
169
|
+
zIndex: '2147483647',
|
|
170
|
+
transition: 'none'
|
|
171
|
+
})
|
|
172
|
+
node.ownerDocument.body.append(ghost)
|
|
173
|
+
// Theme physics can be arbitrarily slow. Never retain an invisible copy or engine work indefinitely.
|
|
174
|
+
exitTimer = node.ownerDocument.defaultView!.setTimeout(() => {
|
|
175
|
+
clear()
|
|
176
|
+
if (!node.open) spring.jump(0.94)
|
|
177
|
+
}, 2000)
|
|
178
|
+
}
|
|
179
|
+
const off = spring.subscribe(value => {
|
|
180
|
+
if (ghost) {
|
|
181
|
+
ghost.style.scale = String(Math.max(0, value))
|
|
182
|
+
ghost.style.opacity = String(Math.max(0, Math.min(1, (value - 0.94) / 0.06)))
|
|
183
|
+
if (!node.open && Math.abs(value - 0.94) < 0.0001) clear()
|
|
184
|
+
}
|
|
185
|
+
})
|
|
186
|
+
function sync() {
|
|
187
|
+
if (node.open === open) return
|
|
188
|
+
open = node.open
|
|
189
|
+
const enabled = resolveMotion(profile, 'dialog', query.matches).enabled
|
|
190
|
+
if (open) {
|
|
191
|
+
clear()
|
|
192
|
+
bounds = geometry()
|
|
193
|
+
spring.configure({ reducedValue: 1 })
|
|
194
|
+
spring.to(1)
|
|
195
|
+
} else {
|
|
196
|
+
if (enabled) snapshot()
|
|
197
|
+
spring.configure({ reducedValue: 0.94 })
|
|
198
|
+
if (ghost) spring.to(0.94)
|
|
199
|
+
else spring.jump(0.94)
|
|
200
|
+
if (!enabled) clear()
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const beforeToggle = () => {
|
|
204
|
+
if (node.open) bounds = geometry()
|
|
205
|
+
}
|
|
206
|
+
node.addEventListener('beforetoggle', beforeToggle)
|
|
207
|
+
const observer = new MutationObserver(sync)
|
|
208
|
+
observer.observe(node, { attributes: true, attributeFilter: ['open'] })
|
|
209
|
+
const resize = new ResizeObserver(() => {
|
|
210
|
+
if (node.open) bounds = geometry()
|
|
211
|
+
})
|
|
212
|
+
resize.observe(node)
|
|
213
|
+
function update(next: MotionProfile) {
|
|
214
|
+
profile = next
|
|
215
|
+
spring.configure({
|
|
216
|
+
...resolveMotion(profile, 'dialog', query.matches),
|
|
217
|
+
reducedValue: node.open ? 1 : 0.94
|
|
218
|
+
})
|
|
219
|
+
if (!resolveMotion(profile, 'dialog', query.matches).enabled) clear()
|
|
220
|
+
sync()
|
|
221
|
+
}
|
|
222
|
+
const preference = () => update(profile)
|
|
223
|
+
query.addEventListener('change', preference)
|
|
224
|
+
return {
|
|
225
|
+
update,
|
|
226
|
+
destroy() {
|
|
227
|
+
observer.disconnect()
|
|
228
|
+
resize.disconnect()
|
|
229
|
+
query.removeEventListener('change', preference)
|
|
230
|
+
off()
|
|
231
|
+
spring.destroy()
|
|
232
|
+
unbind()
|
|
233
|
+
node.removeEventListener('beforetoggle', beforeToggle)
|
|
234
|
+
clear()
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineMotionProfile,
|
|
3
|
+
type MotionProfile,
|
|
4
|
+
type MotionProfileInput
|
|
5
|
+
} from '../motion/config.js'
|
|
1
6
|
import type { CSSProperties } from 'react'
|
|
2
7
|
import {
|
|
3
8
|
flattenTokens,
|
|
@@ -24,6 +29,7 @@ export interface ThemeLayer {
|
|
|
24
29
|
readonly components?: ThemeComponentOverrides
|
|
25
30
|
}
|
|
26
31
|
export interface ThemeDefinition extends ThemeLayer {
|
|
32
|
+
readonly motion?: MotionProfileInput
|
|
27
33
|
readonly id: string
|
|
28
34
|
readonly name: string
|
|
29
35
|
readonly modes?: { readonly light?: ThemeLayer; readonly dark?: ThemeLayer }
|
|
@@ -31,6 +37,7 @@ export interface ThemeDefinition extends ThemeLayer {
|
|
|
31
37
|
|
|
32
38
|
/** Resolved, immutable data. Safe to pass through server/client serialization. */
|
|
33
39
|
export interface Theme {
|
|
40
|
+
readonly motion: MotionProfile
|
|
34
41
|
readonly id: string
|
|
35
42
|
readonly name: string
|
|
36
43
|
readonly modes: {
|
|
@@ -111,7 +118,7 @@ export function defineTheme(definition: ThemeDefinition): Theme {
|
|
|
111
118
|
assertRecord(definition, 'theme')
|
|
112
119
|
assertKeys(
|
|
113
120
|
definition,
|
|
114
|
-
{ id: true, name: true, tokens: true, components: true, modes: true },
|
|
121
|
+
{ id: true, name: true, tokens: true, components: true, modes: true, motion: true },
|
|
115
122
|
'theme'
|
|
116
123
|
)
|
|
117
124
|
if (typeof definition.id !== 'string' || !/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(definition.id)) {
|
|
@@ -144,6 +151,7 @@ export function defineTheme(definition: ThemeDefinition): Theme {
|
|
|
144
151
|
return freezeTree({
|
|
145
152
|
id: definition.id,
|
|
146
153
|
name: definition.name,
|
|
147
|
-
modes
|
|
154
|
+
modes,
|
|
155
|
+
motion: defineMotionProfile(definition.motion)
|
|
148
156
|
})
|
|
149
157
|
}
|