@getcortexlabs/mavis-core 0.1.0-alpha.3 → 0.1.0-alpha.4
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 +2 -2
- package/dist/accordion.d.ts +17 -0
- package/dist/accordion.d.ts.map +1 -0
- package/dist/accordion.js +42 -0
- package/dist/accordion.js.map +1 -0
- package/dist/alert.d.ts +21 -0
- package/dist/alert.d.ts.map +1 -0
- package/dist/alert.js +13 -0
- package/dist/alert.js.map +1 -0
- package/dist/avatar.d.ts +10 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +11 -0
- package/dist/avatar.js.map +1 -0
- package/dist/badge.d.ts +7 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +11 -0
- package/dist/badge.js.map +1 -0
- package/dist/chip.d.ts +9 -0
- package/dist/chip.d.ts.map +1 -0
- package/dist/chip.js +16 -0
- package/dist/chip.js.map +1 -0
- package/dist/choice.d.ts +15 -0
- package/dist/choice.d.ts.map +1 -0
- package/dist/choice.js +27 -0
- package/dist/choice.js.map +1 -0
- package/dist/dialog.d.ts +4 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +20 -0
- package/dist/dialog.js.map +1 -0
- package/dist/empty-state.d.ts +2 -0
- package/dist/empty-state.d.ts.map +1 -0
- package/dist/empty-state.js +5 -0
- package/dist/empty-state.js.map +1 -0
- package/dist/experimental.d.ts +122 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +372 -0
- package/dist/experimental.js.map +1 -0
- package/dist/index.d.ts +29 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/input.d.ts +10 -0
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +12 -0
- package/dist/input.js.map +1 -1
- package/dist/list-item.d.ts +3 -0
- package/dist/list-item.d.ts.map +1 -0
- package/dist/list-item.js +7 -0
- package/dist/list-item.js.map +1 -0
- package/dist/motion.d.ts +33 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +21 -0
- package/dist/motion.js.map +1 -0
- package/dist/progress.d.ts +19 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +19 -0
- package/dist/progress.js.map +1 -0
- package/dist/segmented.d.ts +11 -0
- package/dist/segmented.d.ts.map +1 -0
- package/dist/segmented.js +30 -0
- package/dist/segmented.js.map +1 -0
- package/dist/sheet.d.ts +8 -1
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +4 -3
- package/dist/sheet.js.map +1 -1
- package/dist/tabs.d.ts +11 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +28 -0
- package/dist/tabs.js.map +1 -0
- package/dist/theme/themes.d.ts.map +1 -1
- package/dist/theme/themes.js +84 -11
- package/dist/theme/themes.js.map +1 -1
- package/dist/theme/types.d.ts +52 -1
- package/dist/theme/types.d.ts.map +1 -1
- package/dist/theme/typography.d.ts +10 -0
- package/dist/theme/typography.d.ts.map +1 -0
- package/dist/theme/typography.js +90 -0
- package/dist/theme/typography.js.map +1 -0
- package/dist/toast.d.ts +43 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +228 -0
- package/dist/toast.js.map +1 -0
- package/dist/vue/button-content.d.ts +10 -0
- package/dist/vue/button-content.d.ts.map +1 -0
- package/dist/vue/button-content.js +54 -0
- package/dist/vue/button-content.js.map +1 -0
- package/dist/vue/cached-activity.d.ts +3 -0
- package/dist/vue/cached-activity.d.ts.map +1 -0
- package/dist/vue/cached-activity.js +13 -0
- package/dist/vue/cached-activity.js.map +1 -0
- package/dist/vue/dialog.d.ts +21 -0
- package/dist/vue/dialog.d.ts.map +1 -0
- package/dist/vue/dialog.js +58 -0
- package/dist/vue/dialog.js.map +1 -0
- package/dist/vue/global-components.d.ts +95 -2
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +17 -1
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +15 -1
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/inline-content.d.ts +52 -0
- package/dist/vue/inline-content.d.ts.map +1 -0
- package/dist/vue/inline-content.js +64 -0
- package/dist/vue/inline-content.js.map +1 -0
- package/dist/vue/props.d.ts +1983 -497
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +245 -2
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/theme-provider.d.ts +58 -0
- package/dist/vue/theme-provider.d.ts.map +1 -0
- package/dist/vue/theme-provider.js +69 -0
- package/dist/vue/theme-provider.js.map +1 -0
- package/dist/vue/theme.d.ts +962 -12
- package/dist/vue/theme.d.ts.map +1 -1
- package/dist/vue/theme.js +17 -7
- package/dist/vue/theme.js.map +1 -1
- package/dist/vue/toast.d.ts +29 -0
- package/dist/vue/toast.d.ts.map +1 -0
- package/dist/vue/toast.js +79 -0
- package/dist/vue/toast.js.map +1 -0
- package/package.json +5 -1
- package/src/accordion.ts +66 -0
- package/src/alert.ts +16 -0
- package/src/avatar.ts +11 -0
- package/src/badge.ts +11 -0
- package/src/chip.ts +20 -0
- package/src/choice.ts +41 -0
- package/src/dialog.ts +20 -0
- package/src/empty-state.ts +4 -0
- package/src/experimental.ts +501 -0
- package/src/index.ts +47 -3
- package/src/input.ts +22 -0
- package/src/list-item.ts +5 -0
- package/src/motion.ts +22 -0
- package/src/progress.ts +22 -0
- package/src/segmented.ts +39 -0
- package/src/sheet.ts +6 -3
- package/src/tabs.ts +35 -0
- package/src/theme/themes.ts +88 -11
- package/src/theme/types.ts +42 -1
- package/src/theme/typography.ts +84 -0
- package/src/toast.ts +249 -0
- package/src/vue/button-content.ts +60 -0
- package/src/vue/cached-activity.ts +13 -0
- package/src/vue/dialog.ts +63 -0
- package/src/vue/global-components.ts +77 -2
- package/src/vue/index.ts +33 -0
- package/src/vue/inline-content.ts +71 -0
- package/src/vue/props.ts +263 -4
- package/src/vue/theme-provider.ts +74 -0
- package/src/vue/theme.ts +17 -6
- package/src/vue/toast.ts +99 -0
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
/** Experimental, single-surface motion contract. No platform objects cross this boundary. */
|
|
2
|
+
export type MotionValues = Partial<
|
|
3
|
+
Record<'scale' | 'scaleX' | 'scaleY' | 'x' | 'y' | 'rotate' | 'opacity', number>
|
|
4
|
+
>
|
|
5
|
+
export type MotionFrames = { [K in keyof MotionValues]?: number | readonly (number | null)[] }
|
|
6
|
+
export interface MotionOptions {
|
|
7
|
+
type?: 'spring' | 'tween'
|
|
8
|
+
duration?: number
|
|
9
|
+
bounce?: number
|
|
10
|
+
ease?: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut'
|
|
11
|
+
}
|
|
12
|
+
export interface MotionPlayback {
|
|
13
|
+
readonly finished: Promise<boolean>
|
|
14
|
+
stop(): void
|
|
15
|
+
}
|
|
16
|
+
export interface MotionSurface {
|
|
17
|
+
readonly available: boolean
|
|
18
|
+
animate(values: MotionFrames, options?: MotionOptions): MotionPlayback
|
|
19
|
+
set(values: MotionValues): MotionPlayback
|
|
20
|
+
/** Runs once per mount/load. Its resources belong to that presentation. */
|
|
21
|
+
onAvailable(setup: () => void | (() => void)): () => void
|
|
22
|
+
motionValue(initial: number): MotionValue
|
|
23
|
+
springValue(source: MotionValue, options?: MotionSpringOptions): MotionSpring
|
|
24
|
+
bind(values: MotionBindings): MotionBinding
|
|
25
|
+
drag(options: MotionDragOptions): MotionDrag
|
|
26
|
+
/** Re-read a supported size/pivot change without replacing this presentation. */
|
|
27
|
+
refresh(): void
|
|
28
|
+
scrollLinked(
|
|
29
|
+
source: MotionScrollSource,
|
|
30
|
+
frames: MotionScrollFrames,
|
|
31
|
+
options: MotionScrollOptions,
|
|
32
|
+
): MotionScrollLink
|
|
33
|
+
}
|
|
34
|
+
export interface MotionBinding {
|
|
35
|
+
readonly disposed: boolean
|
|
36
|
+
dispose(): void
|
|
37
|
+
}
|
|
38
|
+
export interface MotionReadable extends MotionBinding {
|
|
39
|
+
get(): number
|
|
40
|
+
to(
|
|
41
|
+
input: readonly number[],
|
|
42
|
+
output: readonly number[],
|
|
43
|
+
options?: { clamp?: boolean },
|
|
44
|
+
): MotionReadable
|
|
45
|
+
}
|
|
46
|
+
export interface MotionValue extends MotionReadable {
|
|
47
|
+
set(value: number): void
|
|
48
|
+
}
|
|
49
|
+
export interface MotionSpring extends MotionReadable {
|
|
50
|
+
readonly moving: boolean
|
|
51
|
+
readonly paused: boolean
|
|
52
|
+
getVelocity(): number
|
|
53
|
+
pause(): void
|
|
54
|
+
resume(): void
|
|
55
|
+
}
|
|
56
|
+
export interface MotionSpringOptions {
|
|
57
|
+
stiffness?: number
|
|
58
|
+
damping?: number
|
|
59
|
+
mass?: number
|
|
60
|
+
initial?: number
|
|
61
|
+
restDelta?: number
|
|
62
|
+
restSpeed?: number
|
|
63
|
+
}
|
|
64
|
+
export type MotionBindings = Partial<Record<keyof MotionValues, MotionReadable>>
|
|
65
|
+
export interface MotionDragOptions {
|
|
66
|
+
axis: 'x' | 'y'
|
|
67
|
+
bounds?: { left?: number; right?: number; top?: number; bottom?: number }
|
|
68
|
+
snap: { x?: readonly number[]; y?: readonly number[] }
|
|
69
|
+
}
|
|
70
|
+
export interface MotionDrag extends MotionBinding {
|
|
71
|
+
readonly dragging: boolean
|
|
72
|
+
pause(): void
|
|
73
|
+
resume(): void
|
|
74
|
+
cancel(): void
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Renderer contracts. Values never expose their DOM/native target. */
|
|
78
|
+
export type MotionValueAdapter = Pick<MotionValue, 'get' | 'set' | 'dispose'>
|
|
79
|
+
export type MotionSpringAdapter = Omit<MotionSpring, 'disposed' | 'to'>
|
|
80
|
+
export type MotionDragAdapter = Omit<MotionDrag, 'disposed'>
|
|
81
|
+
export interface MotionSurfaceAdapter {
|
|
82
|
+
animate(values: MotionFrames, options?: MotionOptions): MotionPlayback
|
|
83
|
+
set(values: MotionValues): MotionPlayback
|
|
84
|
+
motionValue?(initial: number): MotionValueAdapter
|
|
85
|
+
springValue?(source: MotionValueAdapter, options?: MotionSpringOptions): MotionSpringAdapter
|
|
86
|
+
bind?(values: Partial<Record<keyof MotionValues, Pick<MotionReadable, 'get' | 'dispose'>>>): {
|
|
87
|
+
dispose(): void
|
|
88
|
+
}
|
|
89
|
+
drag?(options: MotionDragOptions): MotionDragAdapter
|
|
90
|
+
refresh?(): void
|
|
91
|
+
scrollLinked?(
|
|
92
|
+
source: MotionScrollAdapter,
|
|
93
|
+
frames: MotionScrollFrames,
|
|
94
|
+
options: MotionScrollOptions,
|
|
95
|
+
): Omit<MotionScrollLink, 'disposed'>
|
|
96
|
+
map?(
|
|
97
|
+
source: Pick<MotionReadable, 'get' | 'dispose'>,
|
|
98
|
+
input: readonly number[],
|
|
99
|
+
output: readonly number[],
|
|
100
|
+
options?: { clamp?: boolean },
|
|
101
|
+
): Pick<MotionReadable, 'get' | 'dispose'>
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** CSS pixels on Web, device-independent pixels on NativeScript. Vertical only. */
|
|
105
|
+
export type MotionScrollFrames = Partial<Record<keyof MotionValues, readonly number[]>>
|
|
106
|
+
export interface MotionScrollOptions {
|
|
107
|
+
range: readonly [number, number]
|
|
108
|
+
execution?: 'auto' | 'scheduler'
|
|
109
|
+
}
|
|
110
|
+
export interface MotionScrollLink extends MotionBinding {
|
|
111
|
+
readonly execution: 'scroll-timeline' | 'scheduler' | 'native' | 'released'
|
|
112
|
+
refresh(): void
|
|
113
|
+
}
|
|
114
|
+
export interface MotionScrollSource {
|
|
115
|
+
readonly available: boolean
|
|
116
|
+
onAvailable(setup: () => void | (() => void)): () => void
|
|
117
|
+
/** Re-read deep overflow changes not reported by layout/font observers. */
|
|
118
|
+
refresh(): void
|
|
119
|
+
}
|
|
120
|
+
/** Renderer identity only. The actual scrolling node stays in the renderer's WeakMap. */
|
|
121
|
+
export interface MotionScrollAdapter {
|
|
122
|
+
readonly kind: 'web' | 'native'
|
|
123
|
+
}
|
|
124
|
+
type ScrollState = {
|
|
125
|
+
adapter: MotionScrollAdapter
|
|
126
|
+
links: Set<MotionScrollLink>
|
|
127
|
+
cleanup: Set<() => void>
|
|
128
|
+
}
|
|
129
|
+
const scrollSources = new WeakMap<MotionScrollSource, ScrollState | undefined>()
|
|
130
|
+
const scrollSetups = new WeakMap<MotionScrollSource, Set<() => void | (() => void)>>()
|
|
131
|
+
|
|
132
|
+
export function createMotionScrollSource(): MotionScrollSource {
|
|
133
|
+
const source: MotionScrollSource = {
|
|
134
|
+
get available() {
|
|
135
|
+
return Boolean(scrollSources.get(source))
|
|
136
|
+
},
|
|
137
|
+
refresh() {
|
|
138
|
+
const state = scrollSources.get(source)
|
|
139
|
+
if (!state) throw new Error('Scroll source is unavailable. Mount a scrolling MScreen first.')
|
|
140
|
+
for (const link of state.links) if (!link.disposed) link.refresh()
|
|
141
|
+
},
|
|
142
|
+
onAvailable(setup) {
|
|
143
|
+
let cleanup: (() => void) | undefined
|
|
144
|
+
const invoke = () => {
|
|
145
|
+
const result = setup()
|
|
146
|
+
let ended = false
|
|
147
|
+
cleanup = () => {
|
|
148
|
+
if (ended) return
|
|
149
|
+
ended = true
|
|
150
|
+
result?.()
|
|
151
|
+
}
|
|
152
|
+
return cleanup
|
|
153
|
+
}
|
|
154
|
+
scrollSetups.get(source)!.add(invoke)
|
|
155
|
+
const state = scrollSources.get(source)
|
|
156
|
+
if (state) {
|
|
157
|
+
try {
|
|
158
|
+
state.cleanup.add(invoke())
|
|
159
|
+
} catch (error) {
|
|
160
|
+
scrollSetups.get(source)!.delete(invoke)
|
|
161
|
+
throw error
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return () => {
|
|
165
|
+
scrollSetups.get(source)!.delete(invoke)
|
|
166
|
+
cleanup?.()
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
}
|
|
170
|
+
scrollSources.set(source, undefined)
|
|
171
|
+
scrollSetups.set(source, new Set())
|
|
172
|
+
return source
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function bindMotionScrollSource(
|
|
176
|
+
source: MotionScrollSource,
|
|
177
|
+
adapter: MotionScrollAdapter,
|
|
178
|
+
): () => void {
|
|
179
|
+
if (!scrollSources.has(source)) throw new TypeError('Use createMotionScrollSource().')
|
|
180
|
+
const clear = (state: ScrollState) => {
|
|
181
|
+
if (scrollSources.get(source) === state) scrollSources.set(source, undefined)
|
|
182
|
+
for (const link of [...state.links]) link.dispose()
|
|
183
|
+
for (const cleanup of state.cleanup) cleanup()
|
|
184
|
+
state.links.clear()
|
|
185
|
+
state.cleanup.clear()
|
|
186
|
+
}
|
|
187
|
+
const previous = scrollSources.get(source)
|
|
188
|
+
if (previous) clear(previous)
|
|
189
|
+
const state: ScrollState = { adapter, links: new Set(), cleanup: new Set() }
|
|
190
|
+
scrollSources.set(source, state)
|
|
191
|
+
try {
|
|
192
|
+
for (const setup of scrollSetups.get(source)!) {
|
|
193
|
+
const cleanup = setup()
|
|
194
|
+
if (cleanup) state.cleanup.add(cleanup)
|
|
195
|
+
}
|
|
196
|
+
} catch (error) {
|
|
197
|
+
clear(state)
|
|
198
|
+
throw error
|
|
199
|
+
}
|
|
200
|
+
return () => clear(state)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function validateScroll(frames: MotionScrollFrames, options: MotionScrollOptions) {
|
|
204
|
+
const range = options?.range
|
|
205
|
+
if (
|
|
206
|
+
!Array.isArray(range) ||
|
|
207
|
+
range.length !== 2 ||
|
|
208
|
+
!range.every(Number.isFinite) ||
|
|
209
|
+
range[0] < 0 ||
|
|
210
|
+
range[1] <= range[0] ||
|
|
211
|
+
range[1] > 1e9
|
|
212
|
+
)
|
|
213
|
+
throw new RangeError('Scroll range must increase between 0 and 1e9 pixels/DIPs.')
|
|
214
|
+
if (options.execution !== undefined && !['auto', 'scheduler'].includes(options.execution))
|
|
215
|
+
throw new TypeError('Unsupported scroll execution.')
|
|
216
|
+
const entries = Object.entries(frames)
|
|
217
|
+
if (
|
|
218
|
+
!entries.length ||
|
|
219
|
+
entries.some(
|
|
220
|
+
([key, output]) =>
|
|
221
|
+
!['x', 'y', 'rotate', 'scale', 'scaleX', 'scaleY', 'opacity'].includes(key) ||
|
|
222
|
+
!Array.isArray(output) ||
|
|
223
|
+
output.length < 2 ||
|
|
224
|
+
output.length > 1024 ||
|
|
225
|
+
!output.every(Number.isFinite),
|
|
226
|
+
)
|
|
227
|
+
)
|
|
228
|
+
throw new TypeError('Scroll frames need numeric transform/opacity ranges.')
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
type Resource = { dispose(): void }
|
|
232
|
+
type Binding = {
|
|
233
|
+
adapter: MotionSurfaceAdapter
|
|
234
|
+
active: Set<MotionPlayback>
|
|
235
|
+
resources: Set<Resource>
|
|
236
|
+
valid: boolean
|
|
237
|
+
}
|
|
238
|
+
const bindings = new WeakMap<MotionSurface, Binding | undefined>()
|
|
239
|
+
const setups = new WeakMap<MotionSurface, Set<() => void | (() => void)>>()
|
|
240
|
+
type ValueState = {
|
|
241
|
+
binding: Binding
|
|
242
|
+
raw: Pick<MotionReadable, 'get' | 'dispose'>
|
|
243
|
+
input: boolean
|
|
244
|
+
depth: number
|
|
245
|
+
dependents: Set<Resource>
|
|
246
|
+
}
|
|
247
|
+
const values = new WeakMap<MotionReadable, ValueState>()
|
|
248
|
+
const dependencies = new WeakMap<Resource, Set<Set<Resource>>>()
|
|
249
|
+
function depend(parent: ValueState, resource: Resource) {
|
|
250
|
+
parent.dependents.add(resource)
|
|
251
|
+
let groups = dependencies.get(resource)
|
|
252
|
+
if (!groups) dependencies.set(resource, (groups = new Set()))
|
|
253
|
+
groups.add(parent.dependents)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function own<T extends Resource>(binding: Binding, raw: T): T & MotionBinding {
|
|
257
|
+
let disposed = false
|
|
258
|
+
const handle = new Proxy(raw, {
|
|
259
|
+
get(target, key) {
|
|
260
|
+
if (key === 'disposed') return disposed || !binding.valid
|
|
261
|
+
if (key === 'dispose')
|
|
262
|
+
return () => {
|
|
263
|
+
if (disposed) return
|
|
264
|
+
disposed = true
|
|
265
|
+
binding.resources.delete(handle)
|
|
266
|
+
for (const group of dependencies.get(handle) ?? []) group.delete(handle)
|
|
267
|
+
dependencies.delete(handle)
|
|
268
|
+
const state = values.get(handle as unknown as MotionReadable)
|
|
269
|
+
for (const dependent of state?.dependents ?? []) dependent.dispose()
|
|
270
|
+
state?.dependents.clear()
|
|
271
|
+
target.dispose()
|
|
272
|
+
}
|
|
273
|
+
if (disposed || !binding.valid) throw new Error('This motion resource is disposed.')
|
|
274
|
+
const value = Reflect.get(target, key, target)
|
|
275
|
+
return typeof value === 'function'
|
|
276
|
+
? (...args: unknown[]) => {
|
|
277
|
+
if (disposed || !binding.valid) throw new Error('This motion resource is disposed.')
|
|
278
|
+
return value.apply(target, args)
|
|
279
|
+
}
|
|
280
|
+
: value
|
|
281
|
+
},
|
|
282
|
+
}) as T & MotionBinding
|
|
283
|
+
binding.resources.add(handle)
|
|
284
|
+
return handle
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function ownValue<T extends Pick<MotionReadable, 'get' | 'dispose'>>(
|
|
288
|
+
binding: Binding,
|
|
289
|
+
raw: T,
|
|
290
|
+
input: boolean,
|
|
291
|
+
parent?: ValueState,
|
|
292
|
+
): T & MotionReadable {
|
|
293
|
+
const mapped = Object.assign({}, raw, {
|
|
294
|
+
to(input: readonly number[], output: readonly number[], options?: { clamp?: boolean }) {
|
|
295
|
+
if (!binding.adapter.map) throw new Error('Numeric mappings are unavailable.')
|
|
296
|
+
const state = values.get(value)!
|
|
297
|
+
if (state.depth >= 32)
|
|
298
|
+
throw new RangeError('Motion mappings support at most 32 derived levels.')
|
|
299
|
+
if (
|
|
300
|
+
!Array.isArray(input) ||
|
|
301
|
+
!Array.isArray(output) ||
|
|
302
|
+
input.length < 2 ||
|
|
303
|
+
input.length > 1024 ||
|
|
304
|
+
input.length !== output.length ||
|
|
305
|
+
![...input, ...output].every(Number.isFinite)
|
|
306
|
+
)
|
|
307
|
+
throw new TypeError('A numeric map needs 2–1024 finite input/output pairs.')
|
|
308
|
+
if (
|
|
309
|
+
options &&
|
|
310
|
+
(Object.keys(options).some((key) => key !== 'clamp') ||
|
|
311
|
+
(options.clamp !== undefined && typeof options.clamp !== 'boolean'))
|
|
312
|
+
)
|
|
313
|
+
throw new TypeError('Mapping options support only a boolean clamp.')
|
|
314
|
+
return ownValue(binding, binding.adapter.map(raw, input, output, options), false, state)
|
|
315
|
+
},
|
|
316
|
+
})
|
|
317
|
+
// Preserve getters such as moving/paused; Object.assign would snapshot them.
|
|
318
|
+
const descriptors = Object.getOwnPropertyDescriptors(raw)
|
|
319
|
+
delete (descriptors as Record<string, PropertyDescriptor>).to
|
|
320
|
+
Object.defineProperties(mapped, descriptors)
|
|
321
|
+
const value = own(binding, mapped)
|
|
322
|
+
values.set(value, {
|
|
323
|
+
binding,
|
|
324
|
+
raw,
|
|
325
|
+
input,
|
|
326
|
+
depth: parent ? parent.depth + 1 : 0,
|
|
327
|
+
dependents: new Set(),
|
|
328
|
+
})
|
|
329
|
+
if (parent) depend(parent, value)
|
|
330
|
+
return value
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function createMotionSurface(): MotionSurface {
|
|
334
|
+
const current = () => {
|
|
335
|
+
const binding = bindings.get(surface)
|
|
336
|
+
if (!binding?.valid)
|
|
337
|
+
throw new Error('Motion surface is unavailable. Wait for the component to mount/load.')
|
|
338
|
+
return binding
|
|
339
|
+
}
|
|
340
|
+
const source = (value: MotionReadable, binding: Binding, input = false) => {
|
|
341
|
+
const state = values.get(value)
|
|
342
|
+
if (!state || state.binding !== binding || value.disposed || (input && !state.input))
|
|
343
|
+
throw new TypeError('Use a live value from this surface and presentation.')
|
|
344
|
+
return state
|
|
345
|
+
}
|
|
346
|
+
const run = (invoke: (adapter: MotionSurfaceAdapter) => MotionPlayback): MotionPlayback => {
|
|
347
|
+
const binding = current()
|
|
348
|
+
const playback = invoke(binding.adapter)
|
|
349
|
+
binding.active.add(playback)
|
|
350
|
+
void playback.finished.then(() => binding.active.delete(playback))
|
|
351
|
+
return {
|
|
352
|
+
finished: playback.finished,
|
|
353
|
+
stop() {
|
|
354
|
+
if (binding.valid) playback.stop()
|
|
355
|
+
},
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
const surface: MotionSurface = {
|
|
359
|
+
get available() {
|
|
360
|
+
return Boolean(bindings.get(surface)?.valid)
|
|
361
|
+
},
|
|
362
|
+
animate: (values, options) => run((adapter) => adapter.animate(values, options)),
|
|
363
|
+
set: (values) => run((adapter) => adapter.set(values)),
|
|
364
|
+
onAvailable(setup) {
|
|
365
|
+
let cleanup: (() => void) | undefined
|
|
366
|
+
const invoke = () => {
|
|
367
|
+
const binding = current()
|
|
368
|
+
const before = new Set(binding.resources)
|
|
369
|
+
const active = new Set(binding.active)
|
|
370
|
+
let release: void | (() => void)
|
|
371
|
+
try {
|
|
372
|
+
release = setup()
|
|
373
|
+
} catch (error) {
|
|
374
|
+
for (const resource of [...binding.resources].reverse())
|
|
375
|
+
if (!before.has(resource)) resource.dispose()
|
|
376
|
+
for (const handle of binding.active) if (!active.has(handle)) handle.stop()
|
|
377
|
+
throw error
|
|
378
|
+
}
|
|
379
|
+
const resources = [...binding.resources].filter((resource) => !before.has(resource))
|
|
380
|
+
const playback = [...binding.active].filter((handle) => !active.has(handle))
|
|
381
|
+
let disposed = false
|
|
382
|
+
cleanup = () => {
|
|
383
|
+
if (disposed) return
|
|
384
|
+
disposed = true
|
|
385
|
+
try {
|
|
386
|
+
release?.()
|
|
387
|
+
} finally {
|
|
388
|
+
for (const resource of resources.reverse()) resource.dispose()
|
|
389
|
+
for (const handle of playback) if (binding.active.has(handle)) handle.stop()
|
|
390
|
+
cleanup = undefined
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return cleanup
|
|
394
|
+
}
|
|
395
|
+
setups.get(surface)!.add(invoke)
|
|
396
|
+
if (surface.available) {
|
|
397
|
+
try {
|
|
398
|
+
own(current(), { dispose: invoke() })
|
|
399
|
+
} catch (error) {
|
|
400
|
+
setups.get(surface)!.delete(invoke)
|
|
401
|
+
throw error
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return () => {
|
|
405
|
+
setups.get(surface)!.delete(invoke)
|
|
406
|
+
cleanup?.()
|
|
407
|
+
cleanup = undefined
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
motionValue(initial) {
|
|
411
|
+
const binding = current()
|
|
412
|
+
if (!binding.adapter.motionValue) throw new Error('Continuous motion is unavailable.')
|
|
413
|
+
const raw = binding.adapter.motionValue(initial)
|
|
414
|
+
return ownValue(binding, raw, true)
|
|
415
|
+
},
|
|
416
|
+
springValue(input, options) {
|
|
417
|
+
const binding = current()
|
|
418
|
+
const parent = source(input, binding, true)
|
|
419
|
+
if (!binding.adapter.springValue) throw new Error('Continuous motion is unavailable.')
|
|
420
|
+
const raw = binding.adapter.springValue(parent.raw as MotionValueAdapter, options)
|
|
421
|
+
return ownValue(binding, raw, false, parent)
|
|
422
|
+
},
|
|
423
|
+
bind(input) {
|
|
424
|
+
const binding = current()
|
|
425
|
+
const entries = Object.entries(input).map(
|
|
426
|
+
([key, value]) => [key, source(value, binding)] as const,
|
|
427
|
+
)
|
|
428
|
+
if (!binding.adapter.bind) throw new Error('Continuous motion is unavailable.')
|
|
429
|
+
const handle = own(
|
|
430
|
+
binding,
|
|
431
|
+
binding.adapter.bind(Object.fromEntries(entries.map(([key, state]) => [key, state.raw]))),
|
|
432
|
+
)
|
|
433
|
+
for (const [, state] of entries) depend(state, handle)
|
|
434
|
+
return handle
|
|
435
|
+
},
|
|
436
|
+
scrollLinked(source, frames, options) {
|
|
437
|
+
const binding = current()
|
|
438
|
+
const state = scrollSources.get(source)
|
|
439
|
+
if (!state) throw new Error('Scroll source is unavailable.')
|
|
440
|
+
validateScroll(frames, options)
|
|
441
|
+
if (!binding.adapter.scrollLinked) throw new Error('Scroll motion is unavailable.')
|
|
442
|
+
const raw = binding.adapter.scrollLinked(state.adapter, frames, options)
|
|
443
|
+
const link = own(binding, {
|
|
444
|
+
get execution() {
|
|
445
|
+
return raw.execution
|
|
446
|
+
},
|
|
447
|
+
refresh: () => raw.refresh(),
|
|
448
|
+
dispose() {
|
|
449
|
+
state.links.delete(link)
|
|
450
|
+
raw.dispose()
|
|
451
|
+
},
|
|
452
|
+
})
|
|
453
|
+
state.links.add(link)
|
|
454
|
+
return link
|
|
455
|
+
},
|
|
456
|
+
refresh() {
|
|
457
|
+
current().adapter.refresh?.()
|
|
458
|
+
},
|
|
459
|
+
drag(options) {
|
|
460
|
+
const binding = current()
|
|
461
|
+
if (!binding.adapter.drag) throw new Error('Drag input is unavailable.')
|
|
462
|
+
return own(binding, binding.adapter.drag(options))
|
|
463
|
+
},
|
|
464
|
+
}
|
|
465
|
+
bindings.set(surface, undefined)
|
|
466
|
+
setups.set(surface, new Set())
|
|
467
|
+
return surface
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** Renderer-only binding. Replacement invalidates old handles before exposing the new surface. */
|
|
471
|
+
export function bindMotionSurface(
|
|
472
|
+
surface: MotionSurface,
|
|
473
|
+
adapter: MotionSurfaceAdapter,
|
|
474
|
+
): () => void {
|
|
475
|
+
if (!bindings.has(surface)) throw new TypeError('Use createMotionSurface() to declare a surface.')
|
|
476
|
+
const invalidate = (binding: Binding) => {
|
|
477
|
+
binding.valid = false
|
|
478
|
+
for (const playback of binding.active) playback.stop()
|
|
479
|
+
binding.active.clear()
|
|
480
|
+
for (const resource of [...binding.resources].reverse()) resource.dispose()
|
|
481
|
+
binding.resources.clear()
|
|
482
|
+
}
|
|
483
|
+
const previous = bindings.get(surface)
|
|
484
|
+
if (previous) invalidate(previous)
|
|
485
|
+
const binding: Binding = { adapter, active: new Set(), resources: new Set(), valid: true }
|
|
486
|
+
bindings.set(surface, binding)
|
|
487
|
+
try {
|
|
488
|
+
for (const setup of setups.get(surface)!) {
|
|
489
|
+
const dispose = setup()
|
|
490
|
+
if (dispose) own(binding, { dispose })
|
|
491
|
+
}
|
|
492
|
+
} catch (error) {
|
|
493
|
+
invalidate(binding)
|
|
494
|
+
throw error
|
|
495
|
+
}
|
|
496
|
+
return () => {
|
|
497
|
+
if (!binding.valid) return
|
|
498
|
+
invalidate(binding)
|
|
499
|
+
if (bindings.get(surface) === binding) bindings.set(surface, undefined)
|
|
500
|
+
}
|
|
501
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export { defineTheme, mavis, midnight } from './theme/themes.js'
|
|
2
2
|
export { resolveSpace } from './theme/resolve.js'
|
|
3
|
+
export { pressMotion, revealMotion } from './motion.js'
|
|
3
4
|
export type {
|
|
5
|
+
FontFamily,
|
|
6
|
+
FontWeight,
|
|
7
|
+
Elevation,
|
|
8
|
+
Shadow,
|
|
9
|
+
ComponentTheme,
|
|
4
10
|
MavisTheme,
|
|
5
11
|
ThemeOptions,
|
|
6
12
|
Palette,
|
|
@@ -12,13 +18,51 @@ export type {
|
|
|
12
18
|
ButtonVariant,
|
|
13
19
|
Size,
|
|
14
20
|
} from './theme/types.js'
|
|
21
|
+
export { listItemLabel } from './list-item.js'
|
|
22
|
+
export { avatarSizes, avatarInitials } from './avatar.js'
|
|
23
|
+
export type { AvatarSize } from './avatar.js'
|
|
24
|
+
export { badgeColors } from './badge.js'
|
|
25
|
+
export type { BadgeTone } from './badge.js'
|
|
15
26
|
export { sliderScale } from './slider.js'
|
|
16
27
|
export { resolveDimension, resolveRadius, nonNegative } from './layout.js'
|
|
17
28
|
export type { Dimension } from './layout.js'
|
|
18
|
-
export { validateInput } from './input.js'
|
|
29
|
+
export { validateInput, inputActionSize } from './input.js'
|
|
19
30
|
export { icons, iconFontVersion } from './icons.js'
|
|
20
31
|
export { iconGlyph, iconFontFamily, iconSizes, resolveIconSize, checkIconOnly } from './icon.js'
|
|
21
32
|
export type { IconName, IconSize } from './icon.js'
|
|
22
|
-
export type { InputHandle } from './input.js'
|
|
33
|
+
export type { InputHandle, InputAction } from './input.js'
|
|
23
34
|
export { checkSheetName, sheetCloseReasons } from './sheet.js'
|
|
24
|
-
export type { SheetCloseReason } from './sheet.js'
|
|
35
|
+
export type { SheetCloseReason, SheetName } from './sheet.js'
|
|
36
|
+
export { isChoiceValue, choiceKey, validateChoices, canChoose } from './choice.js'
|
|
37
|
+
export type { ChoiceValue, ChoiceOption } from './choice.js'
|
|
38
|
+
|
|
39
|
+
export { createToastController, connectToast, disposeToast } from './toast.js'
|
|
40
|
+
export type {
|
|
41
|
+
ToastTone,
|
|
42
|
+
ToastOptions,
|
|
43
|
+
ToastMessage,
|
|
44
|
+
ToastController,
|
|
45
|
+
ToastSnapshot,
|
|
46
|
+
ToastConnection,
|
|
47
|
+
} from './toast.js'
|
|
48
|
+
|
|
49
|
+
export { checkDialogLabels, dialogCloseReasons } from './dialog.js'
|
|
50
|
+
export type { DialogCloseReason } from './dialog.js'
|
|
51
|
+
|
|
52
|
+
export { validateTabs, tabFocusTarget, tabScrollOffset } from './tabs.js'
|
|
53
|
+
export type { TabOption, TabPanelProps } from './tabs.js'
|
|
54
|
+
|
|
55
|
+
export { progressSizes, progressMotion, progressState, checkProgressLabels } from './progress.js'
|
|
56
|
+
export type { ProgressSize, ProgressTone } from './progress.js'
|
|
57
|
+
export { alertAppearance, checkAlertLabels } from './alert.js'
|
|
58
|
+
export type { AlertTone } from './alert.js'
|
|
59
|
+
|
|
60
|
+
export { validateAccordion, toggleAccordion, accordionFocusTarget } from './accordion.js'
|
|
61
|
+
export type { AccordionItem, AccordionPanelProps } from './accordion.js'
|
|
62
|
+
export { validateSegments, segmentedFocusTarget, segmentedMotion } from './segmented.js'
|
|
63
|
+
export type { SegmentedOption } from './segmented.js'
|
|
64
|
+
|
|
65
|
+
export { checkChipLabels, chipColors, type ChipTone } from './chip.js'
|
|
66
|
+
export { checkEmptyStateTitle } from './empty-state.js'
|
|
67
|
+
|
|
68
|
+
export { fontFamily, shadowStyle, validateWeight } from './theme/typography.js'
|
package/src/input.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import { iconGlyph, type IconName } from './icon.js'
|
|
2
|
+
|
|
3
|
+
export interface InputAction {
|
|
4
|
+
icon: IconName
|
|
5
|
+
label: string
|
|
6
|
+
disabled?: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Icon-only actions have a fixed touch target, independent of the accessible label length. */
|
|
10
|
+
export const inputActionSize = 48
|
|
11
|
+
|
|
1
12
|
export interface InputHandle {
|
|
2
13
|
focus(): void
|
|
3
14
|
blur(): void
|
|
@@ -9,7 +20,18 @@ export function validateInput(options: {
|
|
|
9
20
|
type: string
|
|
10
21
|
rows: number
|
|
11
22
|
maxLength?: number
|
|
23
|
+
trailingIcon?: IconName
|
|
24
|
+
trailingAction?: InputAction
|
|
12
25
|
}) {
|
|
26
|
+
if (options.trailingAction) {
|
|
27
|
+
iconGlyph(options.trailingAction.icon)
|
|
28
|
+
if (typeof options.trailingAction.label !== 'string' || !options.trailingAction.label.trim()) {
|
|
29
|
+
throw new RangeError('An input action needs a nonempty label')
|
|
30
|
+
}
|
|
31
|
+
if (options.trailingIcon) {
|
|
32
|
+
throw new RangeError('Use either trailingIcon or trailingAction on an input')
|
|
33
|
+
}
|
|
34
|
+
}
|
|
13
35
|
if (!Number.isSafeInteger(options.rows) || options.rows < 1) {
|
|
14
36
|
throw new RangeError('rows must be a positive integer')
|
|
15
37
|
}
|
package/src/list-item.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Slot content needs an explicit label when it adds meaning to an interactive row. */
|
|
2
|
+
export function listItemLabel(title: string, description: string, label?: string): string {
|
|
3
|
+
if (!title?.trim()) throw new RangeError('ListItem requires a non-empty title.')
|
|
4
|
+
return label?.trim() || [title.trim(), description.trim()].filter(Boolean).join('. ')
|
|
5
|
+
}
|
package/src/motion.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Theme input shared by recipes and theme validation. */
|
|
2
|
+
export function resolvePressScale(scale: number): number {
|
|
3
|
+
if (!Number.isFinite(scale) || scale <= 0 || scale > 1) {
|
|
4
|
+
throw new RangeError('pressScale must be a finite number greater than 0 and at most 1')
|
|
5
|
+
}
|
|
6
|
+
return scale
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Recipes describe motion, not input or lifecycle. Adapters own reduced-motion detection:
|
|
10
|
+
// native follows Jolt configuration; Web follows prefers-reduced-motion. See guide/motion.
|
|
11
|
+
export function pressMotion(scale: number) {
|
|
12
|
+
return {
|
|
13
|
+
composition: 'multiply',
|
|
14
|
+
pressed: [{ scale: resolvePressScale(scale) }, { type: 'spring', duration: 200, bounce: 0 }],
|
|
15
|
+
released: [{ scale: 1 }, { type: 'spring', duration: 450, bounce: 0.35 }],
|
|
16
|
+
} as const
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const revealMotion = {
|
|
20
|
+
enter: [{ opacity: [0, 1], y: [8, 0] }, { duration: 180 }],
|
|
21
|
+
leave: [{ opacity: 0 }, { duration: 120 }],
|
|
22
|
+
} as const
|
package/src/progress.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const progressSizes = { sm: 4, md: 8, lg: 12 } as const
|
|
2
|
+
export type ProgressSize = keyof typeof progressSizes
|
|
3
|
+
export type ProgressTone = 'primary' | 'accent' | 'success' | 'warning' | 'danger'
|
|
4
|
+
|
|
5
|
+
export const progressMotion = Object.freeze({ segment: 0.32, duration: 1600 })
|
|
6
|
+
|
|
7
|
+
/** A bounded reading; task ownership and completion stay with the application. */
|
|
8
|
+
export function progressState(value: number, max: number) {
|
|
9
|
+
if (!Number.isFinite(max) || max <= 0)
|
|
10
|
+
throw new RangeError('Progress max must be positive and finite')
|
|
11
|
+
if (!Number.isFinite(value)) throw new RangeError('Progress value must be finite')
|
|
12
|
+
const current = Math.min(max, Math.max(0, value))
|
|
13
|
+
const ratio = current / max
|
|
14
|
+
return { value: current, ratio, text: `${Number((ratio * 100).toFixed(1))}%` }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function checkProgressLabels(label: string, indeterminateLabel: string) {
|
|
18
|
+
if (typeof label !== 'string' || !label.trim())
|
|
19
|
+
throw new TypeError('Progress label must be a non-empty string')
|
|
20
|
+
if (typeof indeterminateLabel !== 'string' || !indeterminateLabel.trim())
|
|
21
|
+
throw new TypeError('Progress indeterminateLabel must be a non-empty string')
|
|
22
|
+
}
|
package/src/segmented.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { validateChoices, type ChoiceOption, type ChoiceValue } from './choice.js'
|
|
2
|
+
|
|
3
|
+
export type SegmentedOption = Pick<ChoiceOption, 'value' | 'label' | 'disabled'>
|
|
4
|
+
export const segmentedMotion = Object.freeze({
|
|
5
|
+
duration: 180,
|
|
6
|
+
ease: 'easeOut',
|
|
7
|
+
cssEase: 'ease-out',
|
|
8
|
+
} as const)
|
|
9
|
+
|
|
10
|
+
export function validateSegments(
|
|
11
|
+
options: readonly SegmentedOption[],
|
|
12
|
+
value: ChoiceValue | null,
|
|
13
|
+
label: string,
|
|
14
|
+
) {
|
|
15
|
+
validateChoices(options, value)
|
|
16
|
+
if (typeof label !== 'string' || !label.trim())
|
|
17
|
+
throw new TypeError('SegmentedControl needs a non-empty label.')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A segmented choice follows radio behavior: arrows both focus and request selection. */
|
|
21
|
+
export function segmentedFocusTarget(
|
|
22
|
+
options: readonly SegmentedOption[],
|
|
23
|
+
value: ChoiceValue,
|
|
24
|
+
key: string,
|
|
25
|
+
rtl = false,
|
|
26
|
+
): SegmentedOption | undefined {
|
|
27
|
+
const enabled = options.filter((option) => !option.disabled)
|
|
28
|
+
if (key === 'Home') return enabled[0]
|
|
29
|
+
if (key === 'End') return enabled[enabled.length - 1]
|
|
30
|
+
const direction = {
|
|
31
|
+
ArrowRight: rtl ? -1 : 1,
|
|
32
|
+
ArrowLeft: rtl ? 1 : -1,
|
|
33
|
+
ArrowDown: 1,
|
|
34
|
+
ArrowUp: -1,
|
|
35
|
+
}[key]
|
|
36
|
+
if (!direction) return
|
|
37
|
+
const index = enabled.findIndex((option) => option.value === value)
|
|
38
|
+
return enabled[(index + direction + enabled.length) % enabled.length]
|
|
39
|
+
}
|