@getcortexlabs/mavis-core 0.1.0-alpha.5 → 0.1.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-icons.d.ts +27 -0
- package/dist/app-icons.d.ts.map +1 -0
- package/dist/app-icons.js +42 -0
- package/dist/app-icons.js.map +1 -0
- package/dist/capabilities.d.ts +7 -7
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +9 -4
- package/dist/capabilities.js.map +1 -1
- package/dist/choice-motion.d.ts +14 -0
- package/dist/choice-motion.d.ts.map +1 -0
- package/dist/choice-motion.js +5 -0
- package/dist/choice-motion.js.map +1 -0
- package/dist/contracts.d.ts +61 -1
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +8 -1
- package/dist/contracts.js.map +1 -1
- package/dist/experimental-playback.d.ts +63 -0
- package/dist/experimental-playback.d.ts.map +1 -0
- package/dist/experimental-playback.js +46 -0
- package/dist/experimental-playback.js.map +1 -0
- package/dist/experimental-regions.d.ts +12 -0
- package/dist/experimental-regions.d.ts.map +1 -1
- package/dist/experimental-regions.js +125 -0
- package/dist/experimental-regions.js.map +1 -1
- package/dist/experimental.d.ts +38 -4
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +70 -11
- package/dist/experimental.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/link.d.ts +12 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +19 -0
- package/dist/link.js.map +1 -0
- package/dist/motion.d.ts +29 -4
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +55 -3
- package/dist/motion.js.map +1 -1
- package/dist/multi-select.d.ts +4 -0
- package/dist/multi-select.d.ts.map +1 -0
- package/dist/multi-select.js +23 -0
- package/dist/multi-select.js.map +1 -0
- package/dist/number-input.d.ts +21 -0
- package/dist/number-input.d.ts.map +1 -0
- package/dist/number-input.js +63 -0
- package/dist/number-input.js.map +1 -0
- package/dist/responsive.d.ts +18 -0
- package/dist/responsive.d.ts.map +1 -0
- package/dist/responsive.js +35 -0
- package/dist/responsive.js.map +1 -0
- package/dist/theme/themes.js +3 -3
- package/dist/theme/themes.js.map +1 -1
- package/dist/theme/types.d.ts +12 -3
- package/dist/theme/types.d.ts.map +1 -1
- package/dist/vue/component-props.d.ts +434 -0
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +4 -0
- package/dist/vue/component-props.js.map +1 -1
- package/dist/vue/configurator-props.d.ts +251 -0
- package/dist/vue/configurator-props.d.ts.map +1 -0
- package/dist/vue/configurator-props.js +56 -0
- package/dist/vue/configurator-props.js.map +1 -0
- package/dist/vue/configurator.d.ts +403 -0
- package/dist/vue/configurator.d.ts.map +1 -0
- package/dist/vue/configurator.js +287 -0
- package/dist/vue/configurator.js.map +1 -0
- package/dist/vue/contracts.d.ts.map +1 -1
- package/dist/vue/contracts.js +7 -1
- package/dist/vue/contracts.js.map +1 -1
- package/dist/vue/date-picker.d.ts +50 -12
- package/dist/vue/date-picker.d.ts.map +1 -1
- package/dist/vue/date-picker.js +28 -6
- package/dist/vue/date-picker.js.map +1 -1
- package/dist/vue/date-props.d.ts +9 -0
- package/dist/vue/date-props.d.ts.map +1 -1
- package/dist/vue/date-props.js +3 -0
- package/dist/vue/date-props.js.map +1 -1
- package/dist/vue/global-components.d.ts +19 -0
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +6 -2
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +5 -2
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/layout-context.d.ts +4 -2
- package/dist/vue/layout-context.d.ts.map +1 -1
- package/dist/vue/layout-context.js +7 -2
- package/dist/vue/layout-context.js.map +1 -1
- package/dist/vue/props.d.ts +365 -0
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +25 -1
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/reveal-state.d.ts +18 -0
- package/dist/vue/reveal-state.d.ts.map +1 -0
- package/dist/vue/reveal-state.js +76 -0
- package/dist/vue/reveal-state.js.map +1 -0
- package/dist/vue/theme.d.ts +42 -0
- package/dist/vue/theme.d.ts.map +1 -1
- package/dist/vue/workflows.d.ts +1 -1
- package/package.json +1 -1
- package/src/app-icons.ts +57 -0
- package/src/capabilities.ts +9 -4
- package/src/choice-motion.ts +12 -0
- package/src/contracts.ts +12 -2
- package/src/experimental-playback.ts +115 -0
- package/src/experimental-regions.ts +151 -0
- package/src/experimental.ts +139 -21
- package/src/index.ts +10 -1
- package/src/link.ts +28 -0
- package/src/motion.ts +61 -3
- package/src/multi-select.ts +30 -0
- package/src/number-input.ts +80 -0
- package/src/responsive.ts +61 -0
- package/src/theme/themes.ts +3 -3
- package/src/theme/types.ts +13 -1
- package/src/vue/component-props.ts +4 -0
- package/src/vue/configurator-props.ts +59 -0
- package/src/vue/configurator.ts +350 -0
- package/src/vue/contracts.ts +7 -1
- package/src/vue/date-picker.ts +33 -6
- package/src/vue/date-props.ts +3 -0
- package/src/vue/global-components.ts +21 -1
- package/src/vue/index.ts +9 -1
- package/src/vue/layout-context.ts +10 -3
- package/src/vue/props.ts +27 -1
- package/src/vue/reveal-state.ts +83 -0
package/src/experimental.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
controlledMotionPlayback,
|
|
3
|
+
motionPlaybackAdapter,
|
|
4
|
+
type MotionControlledPlayback,
|
|
5
|
+
type MotionValueOptions,
|
|
6
|
+
type MotionDecayOptions,
|
|
7
|
+
} from './experimental-playback.js'
|
|
8
|
+
export * from './experimental-playback.js'
|
|
1
9
|
/** Experimental, single-surface motion contract. No platform objects cross this boundary. */
|
|
2
10
|
import {
|
|
3
11
|
regionState,
|
|
@@ -26,13 +34,24 @@ export interface MotionPlayback {
|
|
|
26
34
|
}
|
|
27
35
|
export interface MotionSurface {
|
|
28
36
|
readonly available: boolean
|
|
29
|
-
animate(values: MotionFrames, options?: MotionOptions):
|
|
37
|
+
animate(values: MotionFrames, options?: MotionOptions): MotionControlledPlayback
|
|
30
38
|
set(values: MotionValues): MotionPlayback
|
|
31
39
|
/** Runs once per mount/load. Its resources belong to that presentation. */
|
|
32
40
|
onAvailable(setup: () => void | (() => void)): () => void
|
|
33
41
|
/** A child owner, recreated on mount/load. Late work must use the supplied child. */
|
|
34
42
|
use(setup: (motion: MotionSurface) => void | (() => void)): () => void
|
|
35
43
|
pointerFollow(region: MotionRegion, options?: MotionPointerOptions): MotionPointer
|
|
44
|
+
animateValue(
|
|
45
|
+
value: MotionValue,
|
|
46
|
+
frames: number | readonly (number | null)[],
|
|
47
|
+
options?: MotionValueOptions,
|
|
48
|
+
): MotionControlledPlayback
|
|
49
|
+
stopValue(value: MotionValue, options?: { layer?: string }): void
|
|
50
|
+
playbackProgress(playback: MotionControlledPlayback): MotionReadable
|
|
51
|
+
decay(
|
|
52
|
+
velocity: { x?: number; y?: number },
|
|
53
|
+
options?: MotionDecayOptions,
|
|
54
|
+
): MotionControlledPlayback
|
|
36
55
|
motionValue(initial: number): MotionValue
|
|
37
56
|
springValue(source: MotionValue, options?: MotionSpringOptions): MotionSpring
|
|
38
57
|
bind(values: MotionBindings): MotionBinding
|
|
@@ -49,6 +68,9 @@ export interface MotionBinding {
|
|
|
49
68
|
readonly disposed: boolean
|
|
50
69
|
dispose(): void
|
|
51
70
|
}
|
|
71
|
+
export interface MotionColor extends MotionBinding {
|
|
72
|
+
get(): string
|
|
73
|
+
}
|
|
52
74
|
export interface MotionReadable extends MotionBinding {
|
|
53
75
|
get(): number
|
|
54
76
|
to(
|
|
@@ -56,6 +78,7 @@ export interface MotionReadable extends MotionBinding {
|
|
|
56
78
|
output: readonly number[],
|
|
57
79
|
options?: { clamp?: boolean },
|
|
58
80
|
): MotionReadable
|
|
81
|
+
to(input: readonly number[], output: readonly string[]): MotionColor
|
|
59
82
|
}
|
|
60
83
|
export interface MotionValue extends MotionReadable {
|
|
61
84
|
set(value: number): void
|
|
@@ -75,11 +98,16 @@ export interface MotionSpringOptions {
|
|
|
75
98
|
restDelta?: number
|
|
76
99
|
restSpeed?: number
|
|
77
100
|
}
|
|
78
|
-
export type MotionBindings = Partial<
|
|
101
|
+
export type MotionBindings = Partial<
|
|
102
|
+
Record<keyof MotionValues | 'borderRadius' | 'borderWidth', MotionReadable>
|
|
103
|
+
> &
|
|
104
|
+
Partial<Record<'backgroundColor' | 'borderColor' | 'color', MotionColor>>
|
|
79
105
|
export interface MotionDragOptions {
|
|
80
106
|
axis: 'x' | 'y'
|
|
81
107
|
bounds?: { left?: number; right?: number; top?: number; bottom?: number }
|
|
82
|
-
snap
|
|
108
|
+
snap?: { x?: readonly number[]; y?: readonly number[] }
|
|
109
|
+
friction?: number
|
|
110
|
+
onRelease?: (event: { x: number; y: number; velocityX: number; velocityY: number }) => void
|
|
83
111
|
}
|
|
84
112
|
export interface MotionDrag extends MotionBinding {
|
|
85
113
|
readonly dragging: boolean
|
|
@@ -98,9 +126,19 @@ export interface MotionSurfaceAdapter {
|
|
|
98
126
|
pointerFollow?(region: MotionRegionAdapter, options: MotionPointerOptions): MotionPointerAdapter
|
|
99
127
|
animate(values: MotionFrames, options?: MotionOptions): MotionPlayback
|
|
100
128
|
set(values: MotionValues): MotionPlayback
|
|
129
|
+
animateValue?(
|
|
130
|
+
value: MotionValueAdapter,
|
|
131
|
+
frames: number | readonly (number | null)[],
|
|
132
|
+
options?: MotionValueOptions,
|
|
133
|
+
): MotionPlayback
|
|
134
|
+
stopValue?(value: MotionValueAdapter, options?: { layer?: string }): void
|
|
135
|
+
playbackProgress?(playback: MotionPlayback): Pick<MotionReadable, 'get' | 'dispose'>
|
|
136
|
+
decay?(velocity: { x?: number; y?: number }, options?: MotionDecayOptions): MotionPlayback
|
|
101
137
|
motionValue?(initial: number): MotionValueAdapter
|
|
102
138
|
springValue?(source: MotionValueAdapter, options?: MotionSpringOptions): MotionSpringAdapter
|
|
103
|
-
bind?(values:
|
|
139
|
+
bind?(values: {
|
|
140
|
+
[K in keyof MotionBindings]?: Pick<NonNullable<MotionBindings[K]>, 'get' | 'dispose'>
|
|
141
|
+
}): {
|
|
104
142
|
dispose(): void
|
|
105
143
|
}
|
|
106
144
|
drag?(options: MotionDragOptions): MotionDragAdapter
|
|
@@ -110,6 +148,11 @@ export interface MotionSurfaceAdapter {
|
|
|
110
148
|
frames: MotionScrollFrames,
|
|
111
149
|
options: MotionScrollOptions,
|
|
112
150
|
): Omit<MotionScrollLink, 'disposed'>
|
|
151
|
+
mapColor?(
|
|
152
|
+
source: Pick<MotionReadable, 'get' | 'dispose'>,
|
|
153
|
+
input: readonly number[],
|
|
154
|
+
output: readonly string[],
|
|
155
|
+
): Pick<MotionColor, 'get' | 'dispose'>
|
|
113
156
|
map?(
|
|
114
157
|
source: Pick<MotionReadable, 'get' | 'dispose'>,
|
|
115
158
|
input: readonly number[],
|
|
@@ -269,13 +312,14 @@ export function motionSurfaceAdapter(surface: MotionSurface): MotionSurfaceAdapt
|
|
|
269
312
|
const setups = new WeakMap<MotionSurface, Set<() => void | (() => void)>>()
|
|
270
313
|
type ValueState = {
|
|
271
314
|
binding: Binding
|
|
272
|
-
raw: Pick<MotionReadable, 'get' | 'dispose'>
|
|
315
|
+
raw: Pick<MotionReadable, 'get' | 'dispose'> | Pick<MotionColor, 'get' | 'dispose'>
|
|
273
316
|
input: boolean
|
|
274
317
|
depth: number
|
|
275
318
|
dependents: Set<Resource>
|
|
276
319
|
}
|
|
277
|
-
const values = new WeakMap<MotionReadable, ValueState>()
|
|
320
|
+
const values = new WeakMap<MotionReadable | MotionColor, ValueState>()
|
|
278
321
|
const dependencies = new WeakMap<Resource, Set<Set<Resource>>>()
|
|
322
|
+
const playbackOwners = new WeakMap<MotionPlayback, Binding>()
|
|
279
323
|
function depend(parent: ValueState, resource: Resource) {
|
|
280
324
|
parent.dependents.add(resource)
|
|
281
325
|
let groups = dependencies.get(resource)
|
|
@@ -333,8 +377,11 @@ function ownValue<T extends Pick<MotionReadable, 'get' | 'dispose'>>(
|
|
|
333
377
|
parent?: ValueState,
|
|
334
378
|
): T & MotionReadable {
|
|
335
379
|
const mapped = Object.assign({}, raw, {
|
|
336
|
-
to(
|
|
337
|
-
|
|
380
|
+
to(
|
|
381
|
+
input: readonly number[],
|
|
382
|
+
output: readonly (number | string)[],
|
|
383
|
+
options?: { clamp?: boolean },
|
|
384
|
+
) {
|
|
338
385
|
const state = values.get(value)!
|
|
339
386
|
if (state.depth >= 32)
|
|
340
387
|
throw new RangeError('Motion mappings support at most 32 derived levels.')
|
|
@@ -344,23 +391,52 @@ function ownValue<T extends Pick<MotionReadable, 'get' | 'dispose'>>(
|
|
|
344
391
|
input.length < 2 ||
|
|
345
392
|
input.length > 1024 ||
|
|
346
393
|
input.length !== output.length ||
|
|
347
|
-
!
|
|
394
|
+
!input.every(Number.isFinite) ||
|
|
395
|
+
!(
|
|
396
|
+
output.every(Number.isFinite) ||
|
|
397
|
+
output.every(
|
|
398
|
+
(value) => typeof value === 'string' && /^#[0-9a-f]{6}(?:[0-9a-f]{2})?$/i.test(value),
|
|
399
|
+
)
|
|
400
|
+
)
|
|
348
401
|
)
|
|
349
|
-
throw new TypeError(
|
|
402
|
+
throw new TypeError(
|
|
403
|
+
'A map needs 2–1024 finite input/output pairs of numbers or hex colors.',
|
|
404
|
+
)
|
|
350
405
|
if (
|
|
351
406
|
options &&
|
|
352
407
|
(Object.keys(options).some((key) => key !== 'clamp') ||
|
|
353
408
|
(options.clamp !== undefined && typeof options.clamp !== 'boolean'))
|
|
354
409
|
)
|
|
355
410
|
throw new TypeError('Mapping options support only a boolean clamp.')
|
|
356
|
-
|
|
411
|
+
if (typeof output[0] === 'string') {
|
|
412
|
+
if (options) throw new TypeError('Color maps use clamped ranges without options.')
|
|
413
|
+
if (!binding.adapter.mapColor) throw new Error('Color mappings are unavailable.')
|
|
414
|
+
const rawColor = binding.adapter.mapColor(raw, input, output as readonly string[])
|
|
415
|
+
const color = own(binding, rawColor)
|
|
416
|
+
values.set(color, {
|
|
417
|
+
binding,
|
|
418
|
+
raw: rawColor,
|
|
419
|
+
input: false,
|
|
420
|
+
depth: state.depth + 1,
|
|
421
|
+
dependents: new Set(),
|
|
422
|
+
})
|
|
423
|
+
depend(state, color)
|
|
424
|
+
return color
|
|
425
|
+
}
|
|
426
|
+
if (!binding.adapter.map) throw new Error('Numeric mappings are unavailable.')
|
|
427
|
+
return ownValue(
|
|
428
|
+
binding,
|
|
429
|
+
binding.adapter.map(raw, input, output as readonly number[], options),
|
|
430
|
+
false,
|
|
431
|
+
state,
|
|
432
|
+
)
|
|
357
433
|
},
|
|
358
434
|
})
|
|
359
435
|
// Preserve getters such as moving/paused; Object.assign would snapshot them.
|
|
360
436
|
const descriptors = Object.getOwnPropertyDescriptors(raw)
|
|
361
437
|
delete (descriptors as Record<string, PropertyDescriptor>).to
|
|
362
438
|
Object.defineProperties(mapped, descriptors)
|
|
363
|
-
const value = own(binding, mapped)
|
|
439
|
+
const value = own(binding, mapped) as T & MotionReadable
|
|
364
440
|
values.set(value, {
|
|
365
441
|
binding,
|
|
366
442
|
raw,
|
|
@@ -369,7 +445,7 @@ function ownValue<T extends Pick<MotionReadable, 'get' | 'dispose'>>(
|
|
|
369
445
|
dependents: new Set(),
|
|
370
446
|
})
|
|
371
447
|
if (parent) depend(parent, value)
|
|
372
|
-
return value
|
|
448
|
+
return value as T & MotionReadable
|
|
373
449
|
}
|
|
374
450
|
|
|
375
451
|
export function createMotionSurface(): MotionSurface {
|
|
@@ -379,7 +455,7 @@ export function createMotionSurface(): MotionSurface {
|
|
|
379
455
|
throw new Error('Motion surface is unavailable. Wait for the component to mount/load.')
|
|
380
456
|
return binding
|
|
381
457
|
}
|
|
382
|
-
const source = (value: MotionReadable, binding: Binding, input = false) => {
|
|
458
|
+
const source = (value: MotionReadable | MotionColor, binding: Binding, input = false) => {
|
|
383
459
|
const state = values.get(value)
|
|
384
460
|
if (
|
|
385
461
|
!state ||
|
|
@@ -390,17 +466,19 @@ export function createMotionSurface(): MotionSurface {
|
|
|
390
466
|
throw new TypeError('Use a live value from this surface and presentation.')
|
|
391
467
|
return state
|
|
392
468
|
}
|
|
393
|
-
const run = (
|
|
469
|
+
const run = (
|
|
470
|
+
invoke: (adapter: MotionSurfaceAdapter) => MotionPlayback,
|
|
471
|
+
): MotionControlledPlayback => {
|
|
394
472
|
const binding = current()
|
|
395
473
|
const playback = invoke(binding.adapter)
|
|
396
474
|
binding.active.add(playback)
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
finished: playback.finished,
|
|
400
|
-
stop() {
|
|
401
|
-
if (binding.valid) playback.stop()
|
|
402
|
-
},
|
|
475
|
+
const forget = () => {
|
|
476
|
+
binding.active.delete(playback)
|
|
403
477
|
}
|
|
478
|
+
void playback.finished.then(forget, forget)
|
|
479
|
+
const handle = controlledMotionPlayback(playback, () => binding.valid)
|
|
480
|
+
playbackOwners.set(handle, binding)
|
|
481
|
+
return handle
|
|
404
482
|
}
|
|
405
483
|
const surface: MotionSurface = {
|
|
406
484
|
get available() {
|
|
@@ -518,6 +596,46 @@ export function createMotionSurface(): MotionSurface {
|
|
|
518
596
|
cleanup = undefined
|
|
519
597
|
}
|
|
520
598
|
},
|
|
599
|
+
animateValue(value, frames, options) {
|
|
600
|
+
const binding = current()
|
|
601
|
+
const parent = source(value, binding, true)
|
|
602
|
+
if (!binding.adapter.animateValue) throw new Error('Scalar playback is unavailable.')
|
|
603
|
+
const handle = run((adapter) =>
|
|
604
|
+
adapter.animateValue!(parent.raw as MotionValueAdapter, frames, options),
|
|
605
|
+
)
|
|
606
|
+
const dependent = { dispose: () => handle.stop() }
|
|
607
|
+
depend(parent, dependent)
|
|
608
|
+
const forget = () => {
|
|
609
|
+
parent.dependents.delete(dependent)
|
|
610
|
+
dependencies.delete(dependent)
|
|
611
|
+
}
|
|
612
|
+
void handle.finished.then(forget, forget)
|
|
613
|
+
return handle
|
|
614
|
+
},
|
|
615
|
+
stopValue(value, options) {
|
|
616
|
+
const binding = current()
|
|
617
|
+
const parent = source(value, binding, true)
|
|
618
|
+
if (!binding.adapter.stopValue) throw new Error('Scalar playback is unavailable.')
|
|
619
|
+
binding.adapter.stopValue(parent.raw as MotionValueAdapter, options)
|
|
620
|
+
},
|
|
621
|
+
playbackProgress(playback) {
|
|
622
|
+
const binding = current()
|
|
623
|
+
const owner = playbackOwners.get(playback)
|
|
624
|
+
if (!owner?.valid || owner.context !== binding.context)
|
|
625
|
+
throw new TypeError('Use playback from this surface and presentation.')
|
|
626
|
+
if (!binding.adapter.playbackProgress) throw new Error('Playback progress is unavailable.')
|
|
627
|
+
return ownValue(
|
|
628
|
+
binding,
|
|
629
|
+
binding.adapter.playbackProgress(motionPlaybackAdapter(playback)),
|
|
630
|
+
false,
|
|
631
|
+
)
|
|
632
|
+
},
|
|
633
|
+
decay(velocity, options) {
|
|
634
|
+
return run((adapter) => {
|
|
635
|
+
if (!adapter.decay) throw new Error('Decay playback is unavailable.')
|
|
636
|
+
return adapter.decay(velocity, options)
|
|
637
|
+
})
|
|
638
|
+
},
|
|
521
639
|
motionValue(initial) {
|
|
522
640
|
const binding = current()
|
|
523
641
|
if (!binding.adapter.motionValue) throw new Error('Continuous motion is unavailable.')
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
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
|
+
export { pressMotion, revealMotion, motionRecipe } from './motion.js'
|
|
4
4
|
export type {
|
|
5
5
|
FontFamily,
|
|
6
|
+
MotionTheme,
|
|
7
|
+
MotionEase,
|
|
6
8
|
FontWeight,
|
|
7
9
|
Elevation,
|
|
8
10
|
Shadow,
|
|
@@ -83,3 +85,10 @@ export * from './combobox.js'
|
|
|
83
85
|
export * from './files.js'
|
|
84
86
|
export * from './form.js'
|
|
85
87
|
export * from './navigation.js'
|
|
88
|
+
export * from './link.js'
|
|
89
|
+
export * from './responsive.js'
|
|
90
|
+
export * from './app-icons.js'
|
|
91
|
+
|
|
92
|
+
export * from './number-input.js'
|
|
93
|
+
export * from './multi-select.js'
|
|
94
|
+
export * from './choice-motion.js'
|
package/src/link.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type LinkTarget = '_self' | '_blank'
|
|
2
|
+
export type LinkNavigate = (href: string) => void | Promise<unknown>
|
|
3
|
+
export interface NavigationOptions {
|
|
4
|
+
href?: string
|
|
5
|
+
navigate?: LinkNavigate
|
|
6
|
+
target?: LinkTarget
|
|
7
|
+
rel?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Navigation belongs to the host; the shared contract only validates its destination. */
|
|
11
|
+
export function linkDestination(href: string): string {
|
|
12
|
+
const value = href.trim()
|
|
13
|
+
if (!value || /[\u0000-\u001f\u007f]/.test(value))
|
|
14
|
+
throw new TypeError('MLink requires a nonempty destination without control characters.')
|
|
15
|
+
if (/^(?:javascript|data|vbscript):/i.test(value))
|
|
16
|
+
throw new TypeError('MLink does not accept executable destinations.')
|
|
17
|
+
return value
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function linkRel(target: LinkTarget, rel = ''): string | undefined {
|
|
21
|
+
const tokens = new Set(rel.split(/\s+/).filter(Boolean))
|
|
22
|
+
if (target === '_blank') {
|
|
23
|
+
tokens.delete('opener')
|
|
24
|
+
tokens.add('noopener')
|
|
25
|
+
tokens.add('noreferrer')
|
|
26
|
+
}
|
|
27
|
+
return [...tokens].join(' ') || undefined
|
|
28
|
+
}
|
package/src/motion.ts
CHANGED
|
@@ -8,15 +8,73 @@ export function resolvePressScale(scale: number): number {
|
|
|
8
8
|
|
|
9
9
|
// Recipes describe motion, not input or lifecycle. Adapters own reduced-motion detection:
|
|
10
10
|
// native follows Jolt configuration; Web follows prefers-reduced-motion. See guide/motion.
|
|
11
|
-
export function pressMotion(
|
|
11
|
+
export function pressMotion(value: number | Readonly<MotionTheme>) {
|
|
12
|
+
if (value === null || (typeof value !== 'number' && typeof value !== 'object'))
|
|
13
|
+
throw new RangeError('Press motion needs a valid scale or motion theme')
|
|
14
|
+
const motion = typeof value === 'number' ? { ...defaultMotion, pressScale: value } : value
|
|
15
|
+
validateMotion(motion)
|
|
12
16
|
return {
|
|
13
17
|
composition: 'multiply',
|
|
14
|
-
pressed: [
|
|
15
|
-
|
|
18
|
+
pressed: [
|
|
19
|
+
{ scale: motion.pressScale },
|
|
20
|
+
{ type: 'spring', duration: motion.pressDuration, bounce: 0 },
|
|
21
|
+
],
|
|
22
|
+
released: [
|
|
23
|
+
{ scale: 1 },
|
|
24
|
+
{ type: 'spring', duration: motion.releaseDuration, bounce: motion.releaseBounce },
|
|
25
|
+
],
|
|
16
26
|
} as const
|
|
17
27
|
}
|
|
18
28
|
|
|
29
|
+
/** Platform-neutral recipe. The host supplies the target and owns the Jolt playback. */
|
|
30
|
+
export function motionRecipe(theme: MavisTheme, name: 'enter' | 'exit') {
|
|
31
|
+
const motion = theme.motion
|
|
32
|
+
validateMotion(motion)
|
|
33
|
+
return name === 'enter'
|
|
34
|
+
? {
|
|
35
|
+
keyframes: { opacity: [0, 1], y: [motion.enterOffset, 0] },
|
|
36
|
+
transition: { type: 'tween' as const, duration: motion.enterDuration, ease: motion.ease },
|
|
37
|
+
}
|
|
38
|
+
: {
|
|
39
|
+
keyframes: { opacity: [1, 0] },
|
|
40
|
+
transition: { type: 'tween' as const, duration: motion.exitDuration, ease: motion.ease },
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
19
44
|
export const revealMotion = {
|
|
20
45
|
enter: [{ opacity: [0, 1], y: [8, 0] }, { duration: 180 }],
|
|
21
46
|
leave: [{ opacity: 0 }, { duration: 120 }],
|
|
22
47
|
} as const
|
|
48
|
+
import type { MotionTheme, MavisTheme } from './theme/types.js'
|
|
49
|
+
|
|
50
|
+
export const defaultMotion: Readonly<MotionTheme> = Object.freeze({
|
|
51
|
+
pressScale: 0.97,
|
|
52
|
+
pressDuration: 200,
|
|
53
|
+
releaseDuration: 450,
|
|
54
|
+
releaseBounce: 0.35,
|
|
55
|
+
enterDuration: 180,
|
|
56
|
+
exitDuration: 120,
|
|
57
|
+
enterOffset: 8,
|
|
58
|
+
ease: 'easeOut',
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
export function validateMotion(motion: Readonly<MotionTheme>) {
|
|
62
|
+
resolvePressScale(motion.pressScale)
|
|
63
|
+
for (const key of [
|
|
64
|
+
'pressDuration',
|
|
65
|
+
'releaseDuration',
|
|
66
|
+
'enterDuration',
|
|
67
|
+
'exitDuration',
|
|
68
|
+
'enterOffset',
|
|
69
|
+
] as const)
|
|
70
|
+
if (!Number.isFinite(motion[key]) || motion[key] < 0)
|
|
71
|
+
throw new RangeError(`${key} must be a finite nonnegative number`)
|
|
72
|
+
if (
|
|
73
|
+
!Number.isFinite(motion.releaseBounce) ||
|
|
74
|
+
motion.releaseBounce < 0 ||
|
|
75
|
+
motion.releaseBounce > 1
|
|
76
|
+
)
|
|
77
|
+
throw new RangeError('releaseBounce must be between 0 and 1')
|
|
78
|
+
if (!['linear', 'easeIn', 'easeOut', 'easeInOut'].includes(motion.ease))
|
|
79
|
+
throw new RangeError('Unknown motion easing')
|
|
80
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { choiceKey, validateChoices, type ChoiceOption, type ChoiceValue } from './choice.js'
|
|
2
|
+
|
|
3
|
+
export function validateMultiSelection(
|
|
4
|
+
options: readonly ChoiceOption[],
|
|
5
|
+
values: readonly ChoiceValue[],
|
|
6
|
+
max?: number,
|
|
7
|
+
) {
|
|
8
|
+
validateChoices(options, null)
|
|
9
|
+
if (max !== undefined && (!Number.isInteger(max) || max < 1))
|
|
10
|
+
throw new RangeError('maxSelected must be a positive integer.')
|
|
11
|
+
const keys = values.map(choiceKey)
|
|
12
|
+
if (new Set(keys).size !== keys.length) throw new RangeError('Selected values must be unique.')
|
|
13
|
+
if (values.some((value) => !options.some((option) => option.value === value)))
|
|
14
|
+
throw new RangeError('Each selected value needs a matching option.')
|
|
15
|
+
if (max !== undefined && values.length > max)
|
|
16
|
+
throw new RangeError('Selection exceeds maxSelected.')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function toggleMultiSelection(
|
|
20
|
+
options: readonly ChoiceOption[],
|
|
21
|
+
values: readonly ChoiceValue[],
|
|
22
|
+
value: ChoiceValue,
|
|
23
|
+
max?: number,
|
|
24
|
+
) {
|
|
25
|
+
validateMultiSelection(options, values, max)
|
|
26
|
+
const option = options.find((item) => item.value === value)
|
|
27
|
+
if (!option || option.disabled) return null
|
|
28
|
+
if (values.includes(value)) return values.filter((item) => item !== value)
|
|
29
|
+
return max !== undefined && values.length >= max ? null : [...values, value]
|
|
30
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export type NumberLocale = 'en-US' | 'pt-BR'
|
|
2
|
+
export type NumberDraft =
|
|
3
|
+
| { status: 'valid'; value: number }
|
|
4
|
+
| { status: 'empty'; value: null }
|
|
5
|
+
| { status: 'incomplete' | 'invalid' | 'range'; value: null }
|
|
6
|
+
|
|
7
|
+
export interface NumberConstraints {
|
|
8
|
+
min?: number
|
|
9
|
+
max?: number
|
|
10
|
+
step: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function validateNumberConstraints({ min, max, step }: NumberConstraints) {
|
|
14
|
+
if (!Number.isFinite(step) || step <= 0) throw new RangeError('step must be finite and positive.')
|
|
15
|
+
if ([min, max].some((value) => value !== undefined && !Number.isFinite(value)))
|
|
16
|
+
throw new RangeError('Numeric bounds must be finite.')
|
|
17
|
+
if (min !== undefined && max !== undefined && min > max)
|
|
18
|
+
throw new RangeError('min must not exceed max.')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function formatNumber(value: number | null, locale: NumberLocale) {
|
|
22
|
+
if (value === null) return ''
|
|
23
|
+
if (!Number.isFinite(value)) throw new RangeError('NumberInput requires a finite number or null.')
|
|
24
|
+
const [coefficient, exponent] = String(value).split('e')
|
|
25
|
+
let text = coefficient!
|
|
26
|
+
if (exponent) {
|
|
27
|
+
const negative = text.startsWith('-')
|
|
28
|
+
const [whole, fraction = ''] = text.replace('-', '').split('.')
|
|
29
|
+
const digits = whole! + fraction
|
|
30
|
+
const point = whole!.length + Number(exponent)
|
|
31
|
+
text =
|
|
32
|
+
point <= 0
|
|
33
|
+
? `0.${'0'.repeat(-point)}${digits}`
|
|
34
|
+
: point >= digits.length
|
|
35
|
+
? digits + '0'.repeat(point - digits.length)
|
|
36
|
+
: `${digits.slice(0, point)}.${digits.slice(point)}`
|
|
37
|
+
if (negative) text = `-${text}`
|
|
38
|
+
}
|
|
39
|
+
return locale === 'pt-BR' ? text.replace('.', ',') : text
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function parseNumberDraft(
|
|
43
|
+
text: string,
|
|
44
|
+
locale: NumberLocale,
|
|
45
|
+
bounds: NumberConstraints,
|
|
46
|
+
): NumberDraft {
|
|
47
|
+
const value = text.trim()
|
|
48
|
+
if (!value) return { status: 'empty', value: null }
|
|
49
|
+
const normalized = locale === 'pt-BR' ? value.replace(',', '.') : value
|
|
50
|
+
if (/^[+-]?$/.test(normalized) || /^[+-]?(?:\d+)?\.$/.test(normalized))
|
|
51
|
+
return { status: 'incomplete', value: null }
|
|
52
|
+
if (!/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/.test(normalized)) return { status: 'invalid', value: null }
|
|
53
|
+
const number = Number(normalized)
|
|
54
|
+
if (!Number.isFinite(number)) return { status: 'invalid', value: null }
|
|
55
|
+
if (
|
|
56
|
+
(bounds.min !== undefined && number < bounds.min) ||
|
|
57
|
+
(bounds.max !== undefined && number > bounds.max)
|
|
58
|
+
)
|
|
59
|
+
return { status: 'range', value: null }
|
|
60
|
+
return { status: 'valid', value: number }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function stepNumber(value: number | null, direction: -1 | 1, bounds: NumberConstraints) {
|
|
64
|
+
validateNumberConstraints(bounds)
|
|
65
|
+
const base = value ?? Math.max(bounds.min ?? 0, Math.min(0, bounds.max ?? 0))
|
|
66
|
+
// Scale ordinary decimal steps only while the integer arithmetic remains exact.
|
|
67
|
+
// Large or very small values retain JavaScript number precision without rounding to 15 digits.
|
|
68
|
+
const decimals = (number: number) => formatNumber(number, 'en-US').split('.')[1]?.length ?? 0
|
|
69
|
+
const factor = 10 ** Math.max(decimals(base), decimals(bounds.step))
|
|
70
|
+
const scaledBase = Math.round(base * factor),
|
|
71
|
+
scaledStep = Math.round(bounds.step * factor)
|
|
72
|
+
const scaledNext = scaledBase + direction * scaledStep
|
|
73
|
+
const next = [scaledBase, scaledStep, scaledNext].every(Number.isSafeInteger)
|
|
74
|
+
? scaledNext / factor
|
|
75
|
+
: base + direction * bounds.step
|
|
76
|
+
return Math.max(
|
|
77
|
+
bounds.min ?? -Infinity,
|
|
78
|
+
Math.min(bounds.max ?? Infinity, Number.isFinite(next) ? next : base),
|
|
79
|
+
)
|
|
80
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Spacing } from './theme/types.js'
|
|
2
|
+
|
|
3
|
+
export type StackDirection = 'row' | 'column'
|
|
4
|
+
export interface StackLayout {
|
|
5
|
+
direction?: StackDirection
|
|
6
|
+
gap?: Spacing
|
|
7
|
+
align?: 'start' | 'end' | 'center' | 'stretch'
|
|
8
|
+
justify?: 'start' | 'end' | 'center' | 'between' | 'around'
|
|
9
|
+
wrap?: boolean
|
|
10
|
+
}
|
|
11
|
+
export interface StackBreakpoint extends StackLayout {
|
|
12
|
+
/** Content width in CSS pixels on Web and DIPs on NativeScript. */
|
|
13
|
+
at: number
|
|
14
|
+
}
|
|
15
|
+
export type StackResponsive = StackBreakpoint | readonly StackBreakpoint[]
|
|
16
|
+
|
|
17
|
+
/** Sorted min-width overrides; the input order never changes the resulting layout. */
|
|
18
|
+
export function stackLayout(
|
|
19
|
+
base: StackLayout,
|
|
20
|
+
responsive: StackResponsive | undefined,
|
|
21
|
+
width?: number,
|
|
22
|
+
): StackLayout {
|
|
23
|
+
const points =
|
|
24
|
+
responsive === undefined
|
|
25
|
+
? []
|
|
26
|
+
: Array.isArray(responsive)
|
|
27
|
+
? [...responsive]
|
|
28
|
+
: [responsive as StackBreakpoint]
|
|
29
|
+
const seen = new Set<number>()
|
|
30
|
+
const result = { ...base }
|
|
31
|
+
for (const point of points.sort((a, b) => a.at - b.at)) {
|
|
32
|
+
if (!Number.isFinite(point.at) || point.at <= 0 || seen.has(point.at))
|
|
33
|
+
throw new RangeError('Stack breakpoints must be distinct positive content widths.')
|
|
34
|
+
seen.add(point.at)
|
|
35
|
+
if (point.direction !== undefined && !['row', 'column'].includes(point.direction))
|
|
36
|
+
throw new TypeError('Unknown responsive stack direction.')
|
|
37
|
+
if (point.align !== undefined && !['start', 'end', 'center', 'stretch'].includes(point.align))
|
|
38
|
+
throw new TypeError('Unknown responsive alignment.')
|
|
39
|
+
if (
|
|
40
|
+
point.justify !== undefined &&
|
|
41
|
+
!['start', 'end', 'center', 'between', 'around'].includes(point.justify)
|
|
42
|
+
)
|
|
43
|
+
throw new TypeError('Unknown responsive distribution.')
|
|
44
|
+
if (point.wrap !== undefined && typeof point.wrap !== 'boolean')
|
|
45
|
+
throw new TypeError('wrap must be boolean.')
|
|
46
|
+
if (width !== undefined && width >= point.at) {
|
|
47
|
+
const { at, ...override } = point
|
|
48
|
+
Object.assign(result, override)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function stackDirection(
|
|
55
|
+
base: StackDirection,
|
|
56
|
+
responsive: StackResponsive | undefined,
|
|
57
|
+
width?: number,
|
|
58
|
+
): StackDirection {
|
|
59
|
+
if (!['row', 'column'].includes(base)) throw new TypeError('Unknown stack direction.')
|
|
60
|
+
return stackLayout({ direction: base }, responsive, width).direction ?? base
|
|
61
|
+
}
|
package/src/theme/themes.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
validateShadow,
|
|
6
6
|
freezeFamily,
|
|
7
7
|
} from './typography.js'
|
|
8
|
-
import {
|
|
8
|
+
import { defaultMotion, validateMotion } from '../motion.js'
|
|
9
9
|
|
|
10
10
|
const foundation: MavisTheme = {
|
|
11
11
|
name: 'mavis',
|
|
@@ -89,7 +89,7 @@ const foundation: MavisTheme = {
|
|
|
89
89
|
input: { fontWeight: 'normal', lineHeight: 1.5, paddingX: 16, paddingY: 14, radius: 'md' },
|
|
90
90
|
card: { padding: 'lg', radius: 'lg', elevation: 'none' },
|
|
91
91
|
},
|
|
92
|
-
motion:
|
|
92
|
+
motion: defaultMotion,
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/** Derive a complete theme without changing the original. */
|
|
@@ -141,7 +141,7 @@ export function defineTheme(options: ThemeOptions, base: MavisTheme = foundation
|
|
|
141
141
|
for (const [key, value] of [...Object.entries(theme.space), ...Object.entries(theme.radius)]) {
|
|
142
142
|
if (!Number.isFinite(value) || value < 0) throw new RangeError(`Invalid theme token: ${key}`)
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
validateMotion(theme.motion)
|
|
145
145
|
return Object.freeze(theme)
|
|
146
146
|
}
|
|
147
147
|
|
package/src/theme/types.ts
CHANGED
|
@@ -65,6 +65,18 @@ export interface Typography {
|
|
|
65
65
|
letterSpacing: number
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
export type MotionEase = 'linear' | 'easeIn' | 'easeOut' | 'easeInOut'
|
|
69
|
+
export interface MotionTheme {
|
|
70
|
+
pressScale: number
|
|
71
|
+
pressDuration: number
|
|
72
|
+
releaseDuration: number
|
|
73
|
+
releaseBounce: number
|
|
74
|
+
enterDuration: number
|
|
75
|
+
exitDuration: number
|
|
76
|
+
enterOffset: number
|
|
77
|
+
ease: MotionEase
|
|
78
|
+
}
|
|
79
|
+
|
|
68
80
|
export interface MavisTheme {
|
|
69
81
|
readonly name: string
|
|
70
82
|
readonly appearance: 'light' | 'dark'
|
|
@@ -77,7 +89,7 @@ export interface MavisTheme {
|
|
|
77
89
|
>
|
|
78
90
|
readonly elevation: Readonly<Record<Elevation, Readonly<Shadow>>>
|
|
79
91
|
readonly components: { readonly [K in keyof ComponentTheme]: Readonly<ComponentTheme[K]> }
|
|
80
|
-
readonly motion: Readonly<
|
|
92
|
+
readonly motion: Readonly<MotionTheme>
|
|
81
93
|
}
|
|
82
94
|
|
|
83
95
|
export interface ThemeOptions {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { numberInputProps, multiSelectProps, imageProps } from './configurator-props.js'
|
|
1
2
|
import type { ExtractPublicPropTypes } from '@vue/runtime-core'
|
|
2
3
|
import type { SheetName } from '../sheet.js'
|
|
3
4
|
import { componentProps as foundationProps } from './props.js'
|
|
@@ -9,6 +10,9 @@ import { formGroupProps, formErrorsProps, stepsProps, paginationProps } from './
|
|
|
9
10
|
/** Complete registry, kept separate from the primitives used to compose controls. */
|
|
10
11
|
export const componentProps = {
|
|
11
12
|
...foundationProps,
|
|
13
|
+
MNumberInput: numberInputProps,
|
|
14
|
+
MMultiSelect: multiSelectProps,
|
|
15
|
+
MImage: imageProps,
|
|
12
16
|
MDatePicker: datePickerProps,
|
|
13
17
|
MDateRangePicker: dateRangePickerProps,
|
|
14
18
|
MCombobox: comboboxProps,
|