@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.
Files changed (127) hide show
  1. package/dist/app-icons.d.ts +27 -0
  2. package/dist/app-icons.d.ts.map +1 -0
  3. package/dist/app-icons.js +42 -0
  4. package/dist/app-icons.js.map +1 -0
  5. package/dist/capabilities.d.ts +7 -7
  6. package/dist/capabilities.d.ts.map +1 -1
  7. package/dist/capabilities.js +9 -4
  8. package/dist/capabilities.js.map +1 -1
  9. package/dist/choice-motion.d.ts +14 -0
  10. package/dist/choice-motion.d.ts.map +1 -0
  11. package/dist/choice-motion.js +5 -0
  12. package/dist/choice-motion.js.map +1 -0
  13. package/dist/contracts.d.ts +61 -1
  14. package/dist/contracts.d.ts.map +1 -1
  15. package/dist/contracts.js +8 -1
  16. package/dist/contracts.js.map +1 -1
  17. package/dist/experimental-playback.d.ts +63 -0
  18. package/dist/experimental-playback.d.ts.map +1 -0
  19. package/dist/experimental-playback.js +46 -0
  20. package/dist/experimental-playback.js.map +1 -0
  21. package/dist/experimental-regions.d.ts +12 -0
  22. package/dist/experimental-regions.d.ts.map +1 -1
  23. package/dist/experimental-regions.js +125 -0
  24. package/dist/experimental-regions.js.map +1 -1
  25. package/dist/experimental.d.ts +38 -4
  26. package/dist/experimental.d.ts.map +1 -1
  27. package/dist/experimental.js +70 -11
  28. package/dist/experimental.js.map +1 -1
  29. package/dist/index.d.ts +8 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +7 -1
  32. package/dist/index.js.map +1 -1
  33. package/dist/link.d.ts +12 -0
  34. package/dist/link.d.ts.map +1 -0
  35. package/dist/link.js +19 -0
  36. package/dist/link.js.map +1 -0
  37. package/dist/motion.d.ts +29 -4
  38. package/dist/motion.d.ts.map +1 -1
  39. package/dist/motion.js +55 -3
  40. package/dist/motion.js.map +1 -1
  41. package/dist/multi-select.d.ts +4 -0
  42. package/dist/multi-select.d.ts.map +1 -0
  43. package/dist/multi-select.js +23 -0
  44. package/dist/multi-select.js.map +1 -0
  45. package/dist/number-input.d.ts +21 -0
  46. package/dist/number-input.d.ts.map +1 -0
  47. package/dist/number-input.js +63 -0
  48. package/dist/number-input.js.map +1 -0
  49. package/dist/responsive.d.ts +18 -0
  50. package/dist/responsive.d.ts.map +1 -0
  51. package/dist/responsive.js +35 -0
  52. package/dist/responsive.js.map +1 -0
  53. package/dist/theme/themes.js +3 -3
  54. package/dist/theme/themes.js.map +1 -1
  55. package/dist/theme/types.d.ts +12 -3
  56. package/dist/theme/types.d.ts.map +1 -1
  57. package/dist/vue/component-props.d.ts +434 -0
  58. package/dist/vue/component-props.d.ts.map +1 -1
  59. package/dist/vue/component-props.js +4 -0
  60. package/dist/vue/component-props.js.map +1 -1
  61. package/dist/vue/configurator-props.d.ts +251 -0
  62. package/dist/vue/configurator-props.d.ts.map +1 -0
  63. package/dist/vue/configurator-props.js +56 -0
  64. package/dist/vue/configurator-props.js.map +1 -0
  65. package/dist/vue/configurator.d.ts +403 -0
  66. package/dist/vue/configurator.d.ts.map +1 -0
  67. package/dist/vue/configurator.js +287 -0
  68. package/dist/vue/configurator.js.map +1 -0
  69. package/dist/vue/contracts.d.ts.map +1 -1
  70. package/dist/vue/contracts.js +7 -1
  71. package/dist/vue/contracts.js.map +1 -1
  72. package/dist/vue/date-picker.d.ts +50 -12
  73. package/dist/vue/date-picker.d.ts.map +1 -1
  74. package/dist/vue/date-picker.js +28 -6
  75. package/dist/vue/date-picker.js.map +1 -1
  76. package/dist/vue/date-props.d.ts +9 -0
  77. package/dist/vue/date-props.d.ts.map +1 -1
  78. package/dist/vue/date-props.js +3 -0
  79. package/dist/vue/date-props.js.map +1 -1
  80. package/dist/vue/global-components.d.ts +19 -0
  81. package/dist/vue/global-components.d.ts.map +1 -1
  82. package/dist/vue/index.d.ts +6 -2
  83. package/dist/vue/index.d.ts.map +1 -1
  84. package/dist/vue/index.js +5 -2
  85. package/dist/vue/index.js.map +1 -1
  86. package/dist/vue/layout-context.d.ts +4 -2
  87. package/dist/vue/layout-context.d.ts.map +1 -1
  88. package/dist/vue/layout-context.js +7 -2
  89. package/dist/vue/layout-context.js.map +1 -1
  90. package/dist/vue/props.d.ts +365 -0
  91. package/dist/vue/props.d.ts.map +1 -1
  92. package/dist/vue/props.js +25 -1
  93. package/dist/vue/props.js.map +1 -1
  94. package/dist/vue/reveal-state.d.ts +18 -0
  95. package/dist/vue/reveal-state.d.ts.map +1 -0
  96. package/dist/vue/reveal-state.js +76 -0
  97. package/dist/vue/reveal-state.js.map +1 -0
  98. package/dist/vue/theme.d.ts +42 -0
  99. package/dist/vue/theme.d.ts.map +1 -1
  100. package/dist/vue/workflows.d.ts +1 -1
  101. package/package.json +1 -1
  102. package/src/app-icons.ts +57 -0
  103. package/src/capabilities.ts +9 -4
  104. package/src/choice-motion.ts +12 -0
  105. package/src/contracts.ts +12 -2
  106. package/src/experimental-playback.ts +115 -0
  107. package/src/experimental-regions.ts +151 -0
  108. package/src/experimental.ts +139 -21
  109. package/src/index.ts +10 -1
  110. package/src/link.ts +28 -0
  111. package/src/motion.ts +61 -3
  112. package/src/multi-select.ts +30 -0
  113. package/src/number-input.ts +80 -0
  114. package/src/responsive.ts +61 -0
  115. package/src/theme/themes.ts +3 -3
  116. package/src/theme/types.ts +13 -1
  117. package/src/vue/component-props.ts +4 -0
  118. package/src/vue/configurator-props.ts +59 -0
  119. package/src/vue/configurator.ts +350 -0
  120. package/src/vue/contracts.ts +7 -1
  121. package/src/vue/date-picker.ts +33 -6
  122. package/src/vue/date-props.ts +3 -0
  123. package/src/vue/global-components.ts +21 -1
  124. package/src/vue/index.ts +9 -1
  125. package/src/vue/layout-context.ts +10 -3
  126. package/src/vue/props.ts +27 -1
  127. package/src/vue/reveal-state.ts +83 -0
@@ -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): MotionPlayback
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<Record<keyof MotionValues, MotionReadable>>
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: { x?: readonly number[]; y?: readonly number[] }
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: Partial<Record<keyof MotionValues, Pick<MotionReadable, 'get' | 'dispose'>>>): {
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(input: readonly number[], output: readonly number[], options?: { clamp?: boolean }) {
337
- if (!binding.adapter.map) throw new Error('Numeric mappings are unavailable.')
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
- ![...input, ...output].every(Number.isFinite)
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('A numeric map needs 2–1024 finite input/output pairs.')
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
- return ownValue(binding, binding.adapter.map(raw, input, output, options), false, state)
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 = (invoke: (adapter: MotionSurfaceAdapter) => MotionPlayback): MotionPlayback => {
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
- void playback.finished.then(() => binding.active.delete(playback))
398
- return {
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(scale: number) {
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: [{ scale: resolvePressScale(scale) }, { type: 'spring', duration: 200, bounce: 0 }],
15
- released: [{ scale: 1 }, { type: 'spring', duration: 450, bounce: 0.35 }],
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
+ }
@@ -5,7 +5,7 @@ import {
5
5
  validateShadow,
6
6
  freezeFamily,
7
7
  } from './typography.js'
8
- import { resolvePressScale } from '../motion.js'
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: { pressScale: 0.97 },
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
- resolvePressScale(theme.motion.pressScale)
144
+ validateMotion(theme.motion)
145
145
  return Object.freeze(theme)
146
146
  }
147
147
 
@@ -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<{ pressScale: number }>
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,