@getcortexlabs/mavis-core 0.1.0-rc.13 → 0.1.0-rc.14

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 (105) hide show
  1. package/README.md +2 -2
  2. package/dist/capabilities.d.ts +1814 -5
  3. package/dist/capabilities.d.ts.map +1 -1
  4. package/dist/capabilities.js +87 -4
  5. package/dist/capabilities.js.map +1 -1
  6. package/dist/collections.d.ts +2 -0
  7. package/dist/collections.d.ts.map +1 -1
  8. package/dist/collections.js +9 -0
  9. package/dist/collections.js.map +1 -1
  10. package/dist/contracts.d.ts +4 -4
  11. package/dist/date.d.ts.map +1 -1
  12. package/dist/date.js +1 -1
  13. package/dist/date.js.map +1 -1
  14. package/dist/experimental-regions.d.ts +12 -0
  15. package/dist/experimental-regions.d.ts.map +1 -1
  16. package/dist/experimental-regions.js +37 -7
  17. package/dist/experimental-regions.js.map +1 -1
  18. package/dist/experimental.d.ts +25 -4
  19. package/dist/experimental.d.ts.map +1 -1
  20. package/dist/experimental.js +75 -7
  21. package/dist/experimental.js.map +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +1 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/macos-capabilities.generated.d.ts +1738 -0
  27. package/dist/macos-capabilities.generated.d.ts.map +1 -0
  28. package/dist/macos-capabilities.generated.js +4191 -0
  29. package/dist/macos-capabilities.generated.js.map +1 -0
  30. package/dist/motion.d.ts +1 -1
  31. package/dist/section-scroll.d.ts +2 -0
  32. package/dist/section-scroll.d.ts.map +1 -1
  33. package/dist/section-scroll.js +2 -0
  34. package/dist/section-scroll.js.map +1 -1
  35. package/dist/vue/advanced-collections.d.ts +16 -16
  36. package/dist/vue/advanced-collections.d.ts.map +1 -1
  37. package/dist/vue/advanced-collections.js +24 -3
  38. package/dist/vue/advanced-collections.js.map +1 -1
  39. package/dist/vue/animated-text.d.ts +4 -4
  40. package/dist/vue/chart.d.ts +5 -5
  41. package/dist/vue/chart.d.ts.map +1 -1
  42. package/dist/vue/chart.js +28 -7
  43. package/dist/vue/chart.js.map +1 -1
  44. package/dist/vue/combobox.d.ts.map +1 -1
  45. package/dist/vue/combobox.js +13 -11
  46. package/dist/vue/combobox.js.map +1 -1
  47. package/dist/vue/command-palette.d.ts +5 -5
  48. package/dist/vue/component-props.d.ts +25 -21
  49. package/dist/vue/component-props.d.ts.map +1 -1
  50. package/dist/vue/composer.d.ts +10 -10
  51. package/dist/vue/configurator.d.ts +15 -15
  52. package/dist/vue/creative-controls.d.ts +10 -10
  53. package/dist/vue/dashboard-charts.d.ts +6 -6
  54. package/dist/vue/dashboard-effects.d.ts +6 -6
  55. package/dist/vue/date-picker.d.ts +48 -48
  56. package/dist/vue/discovery-controls.d.ts +7 -7
  57. package/dist/vue/image-cropper.d.ts +8 -8
  58. package/dist/vue/image-cropper.d.ts.map +1 -1
  59. package/dist/vue/kanban.d.ts +25 -7
  60. package/dist/vue/kanban.d.ts.map +1 -1
  61. package/dist/vue/kanban.js +73 -44
  62. package/dist/vue/kanban.js.map +1 -1
  63. package/dist/vue/list-motion.d.ts.map +1 -1
  64. package/dist/vue/list-motion.js +24 -7
  65. package/dist/vue/list-motion.js.map +1 -1
  66. package/dist/vue/marquee.d.ts +4 -4
  67. package/dist/vue/menu.d.ts +4 -4
  68. package/dist/vue/navigation-props.d.ts +5 -0
  69. package/dist/vue/navigation-props.d.ts.map +1 -1
  70. package/dist/vue/navigation-props.js +2 -0
  71. package/dist/vue/navigation-props.js.map +1 -1
  72. package/dist/vue/number-flow.d.ts +3 -3
  73. package/dist/vue/platform.d.ts +7 -1
  74. package/dist/vue/platform.d.ts.map +1 -1
  75. package/dist/vue/platform.js +5 -4
  76. package/dist/vue/platform.js.map +1 -1
  77. package/dist/vue/props.d.ts +42 -42
  78. package/dist/vue/reveal-state.d.ts +1 -1
  79. package/dist/vue/scheduler.d.ts +10 -10
  80. package/dist/vue/scroll-frame.d.ts +6 -6
  81. package/dist/vue/speed-dial.d.ts +3 -3
  82. package/dist/vue/swipe-actions.d.ts +3 -3
  83. package/dist/vue/swipe-deck.d.ts +3 -3
  84. package/dist/vue/theme-provider.d.ts +1 -1
  85. package/dist/vue/time-picker.d.ts +20 -20
  86. package/dist/vue/tour.d.ts +3 -3
  87. package/dist/vue/tree-view.d.ts +3 -3
  88. package/dist/vue/wayfinding-controls.d.ts +1 -1
  89. package/dist/vue/workflows.d.ts +5 -5
  90. package/package.json +1 -1
  91. package/src/capabilities.ts +89 -5
  92. package/src/collections.ts +22 -0
  93. package/src/date.ts +2 -1
  94. package/src/experimental-regions.ts +47 -7
  95. package/src/experimental.ts +117 -12
  96. package/src/index.ts +6 -1
  97. package/src/macos-capabilities.generated.ts +4190 -0
  98. package/src/section-scroll.ts +4 -0
  99. package/src/vue/advanced-collections.ts +29 -7
  100. package/src/vue/chart.ts +34 -9
  101. package/src/vue/combobox.ts +15 -14
  102. package/src/vue/kanban.ts +99 -59
  103. package/src/vue/list-motion.ts +23 -7
  104. package/src/vue/navigation-props.ts +2 -0
  105. package/src/vue/platform.ts +13 -5
@@ -95,17 +95,17 @@ export declare function createTreeView(ui: {
95
95
  default: string;
96
96
  };
97
97
  }>> & Readonly<{
98
- onLoad?: ((_node: TreeNode) => any) | undefined;
99
98
  "onUpdate:modelValue"?: ((_key: ChoiceValue) => any) | undefined;
99
+ onLoad?: ((_node: TreeNode) => any) | undefined;
100
100
  "onUpdate:expanded"?: ((_keys: ChoiceValue[]) => any) | undefined;
101
101
  }>, {
102
102
  expandedLabel: string;
103
103
  collapsedLabel: string;
104
104
  disabled: boolean;
105
- expanded: readonly ChoiceValue[];
106
105
  modelValue: ChoiceValue | null;
107
- loadingLabel: string;
108
106
  emptyLabel: string;
107
+ loadingLabel: string;
108
+ expanded: readonly ChoiceValue[];
109
109
  loadingKeys: readonly ChoiceValue[];
110
110
  }, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
111
111
  //# sourceMappingURL=tree-view.d.ts.map
@@ -91,8 +91,8 @@ export declare function createWayfindingControls(ui: Primitives, platform: 'web'
91
91
  modelValue: import("../choice.js").ChoiceValue | null;
92
92
  expandLabel: string;
93
93
  collapseLabel: string;
94
- collapsible: boolean;
95
94
  collapsed: boolean;
95
+ collapsible: boolean;
96
96
  currentLabel: string;
97
97
  }, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
98
98
  MBreadcrumb: import("@vue/runtime-core").DefineComponent<import("@vue/runtime-core").ExtractPropTypes<{
@@ -133,8 +133,8 @@ export declare function createWorkflows(ui: Primitives, platform: 'web' | 'nativ
133
133
  "onUpdate:modelValue"?: ((_value: ChoiceValue) => any) | undefined;
134
134
  }>, {
135
135
  disabled: boolean;
136
- loading: boolean;
137
136
  modelValue: ChoiceValue | null;
137
+ loading: boolean;
138
138
  errorLabel: string;
139
139
  currentLabel: string;
140
140
  completeLabel: string;
@@ -250,17 +250,17 @@ export declare function createWorkflows(ui: Primitives, platform: 'web' | 'nativ
250
250
  }>, {
251
251
  label: string;
252
252
  disabled: boolean;
253
- loading: boolean;
254
253
  modelValue: number;
254
+ loading: boolean;
255
255
  emptyLabel: string;
256
- previousLabel: string;
257
256
  nextLabel: string;
257
+ previousLabel: string;
258
258
  currentLabel: string;
259
+ invalidPageLabel: string;
260
+ pageLabel: string;
259
261
  pageSize: number;
260
262
  siblingCount: number;
261
- pageLabel: string;
262
263
  statusText: string;
263
- invalidPageLabel: string;
264
264
  }, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
265
265
  };
266
266
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getcortexlabs/mavis-core",
3
- "version": "0.1.0-rc.13",
3
+ "version": "0.1.0-rc.14",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Shared Mavis themes and component contracts.",
@@ -1,3 +1,6 @@
1
+ import { macosCapabilities } from './macos-capabilities.generated.js'
2
+ export { macosCapabilities } from './macos-capabilities.generated.js'
3
+
1
4
  /** Source capabilities, not a promise that every feature is in the last npm release. */
2
5
  export const componentNames = [
3
6
  'MTreeSelect',
@@ -100,16 +103,74 @@ export const componentNames = [
100
103
  'MChart',
101
104
  ] as const
102
105
  export type ComponentName = (typeof componentNames)[number]
103
- export type CapabilityStatus = 'experimental' | 'planned' | 'unsupported' | 'unverified'
106
+ export type CapabilityStatus = 'experimental' | 'partial' | 'planned' | 'unsupported' | 'unverified'
104
107
 
105
108
  export const targetCapabilities = {
106
109
  version: 1,
107
110
  source: 'repository',
108
- publishedBaseline: '0.1.0-rc.13',
111
+ publishedBaseline: '0.1.0-rc.14',
109
112
  developmentMotion: {
110
113
  availability: 'published',
111
114
  joltCommit: null,
112
- publishedJoltRelease: '0.1.0-rc.13',
115
+ publishedJoltRelease: '0.1.0-rc.15',
116
+ macos: {
117
+ availability: 'published',
118
+ joltSwiftRelease: '0.1.0-rc.15',
119
+ reveal: 'experimental',
120
+ textEffects: { status: 'experimental', minimumOS: 15, macOS14: 'static' },
121
+ numberFlow: { status: 'experimental', minimumOS: 15, macOS14: 'static' },
122
+ confetti: 'experimental',
123
+ marquee: 'experimental',
124
+ surface: {
125
+ status: 'partial',
126
+ targets: ['MBox', 'MIcon', 'MImage:loaded-artwork'],
127
+ methods: ['available', 'onAvailable', 'use', 'set', 'animate', 'refresh'],
128
+ playback: ['finished', 'stop', 'pause', 'resume', 'paused', 'duration', 'progress:read'],
129
+ channels: [
130
+ 'x',
131
+ 'y',
132
+ 'scale',
133
+ 'scaleX',
134
+ 'scaleY',
135
+ 'rotate',
136
+ 'rotateX',
137
+ 'rotateY',
138
+ 'opacity',
139
+ ],
140
+ timing: ['spring', 'tween'],
141
+ interruptedSpringVelocity: {
142
+ status: 'not-inherited',
143
+ upstreamIssue: 'https://github.com/rafaelaugustos/jolt/issues/505',
144
+ },
145
+ maximumFrames: 2,
146
+ cleanupCallbacks: 'definite-cleanup-or-void',
147
+ whenMotionAvailable: ['surfaces', 'regions'],
148
+ trackingIssue: 354,
149
+ },
150
+ region: {
151
+ status: 'partial',
152
+ targets: ['MBox'],
153
+ methods: ['available', 'onAvailable', 'timeline', 'sequence'],
154
+ steps: 'surface-tuples',
155
+ positions: ['next', 'previous-start', 'absolute-forward', 'relative-forward'],
156
+ callbackSteps: 'unsupported',
157
+ durationRead: 'unsupported',
158
+ trackingIssue: 354,
159
+ },
160
+ shapes: {
161
+ status: 'unsupported',
162
+ upstreamIssue: 'https://github.com/rafaelaugustos/jolt/issues/504',
163
+ trackingIssue: 354,
164
+ },
165
+ particles: {
166
+ status: 'partial',
167
+ finite: true,
168
+ continuous: 'unsupported',
169
+ maximumDurationIncludingLifetime: 60000,
170
+ upstreamIssue: 'https://github.com/rafaelaugustos/jolt/issues/503',
171
+ trackingIssue: 354,
172
+ },
173
+ },
113
174
  features: {
114
175
  gradient: ['web', 'ios', 'android'],
115
176
  loadingEffects: ['web', 'ios'],
@@ -135,7 +196,7 @@ export const targetCapabilities = {
135
196
  streaming: 'unverified',
136
197
  rsc: 'unsupported',
137
198
  },
138
- motion: { engine: 'jolt', minimum: '0.1.0-rc.13', start: 'client-mount' },
199
+ motion: { engine: 'jolt', minimum: '0.1.0-rc.15', start: 'client-mount' },
139
200
  ssr: {
140
201
  availability: '0.1.0-alpha.5',
141
202
  host: 'nuxt',
@@ -178,7 +239,30 @@ export const targetCapabilities = {
178
239
  streaming: 'unsupported',
179
240
  rsc: 'unsupported',
180
241
  },
181
- motion: { engine: 'jolt', minimum: '0.1.0-rc.13', start: 'native-loaded' },
242
+ motion: { engine: 'jolt', minimum: '0.1.0-rc.15', start: 'native-loaded' },
243
+ },
244
+ {
245
+ id: 'macos-swiftui',
246
+ framework: 'shared',
247
+ authoring: macosCapabilities.authoring,
248
+ renderer: 'swiftui',
249
+ status: 'experimental',
250
+ source: macosCapabilities.source,
251
+ minimumOS: macosCapabilities.minimumOS,
252
+ validation: macosCapabilities.validation,
253
+ components: Object.keys(macosCapabilities.components),
254
+ componentCapabilities: macosCapabilities.components,
255
+ limitations: macosCapabilities.sharedLimits,
256
+ rendering: {
257
+ client: 'experimental',
258
+ serverImport: 'unsupported',
259
+ serverHTML: 'unsupported',
260
+ hydration: 'unsupported',
261
+ ssg: 'unsupported',
262
+ streaming: 'unsupported',
263
+ rsc: 'unsupported',
264
+ },
265
+ motion: { engine: 'jolt-swiftui', minimum: '0.1.0-rc.15', start: 'native-view' },
182
266
  },
183
267
  ],
184
268
  planned: [
@@ -59,6 +59,28 @@ export function virtualKeys<T>(items: readonly T[], itemKey: VirtualItemKey<T>):
59
59
  return key
60
60
  })
61
61
  }
62
+ /** Preserve the first visible identity and its intra-row offset; removed anchors use the nearest index. */
63
+ export function virtualAnchor(
64
+ previous: readonly ChoiceValue[],
65
+ next: readonly ChoiceValue[],
66
+ rowHeight: number,
67
+ height: number,
68
+ offset: number,
69
+ ): number {
70
+ const before = virtualWindow(previous.length, rowHeight, height, offset, 0).scrollTop
71
+ const index = Math.floor(before / rowHeight)
72
+ const key = previous[index]
73
+ const found = key === undefined ? -1 : next.indexOf(key)
74
+ const destination = found < 0 ? Math.min(index, Math.max(0, next.length - 1)) : found
75
+ return virtualWindow(
76
+ next.length,
77
+ rowHeight,
78
+ height,
79
+ destination * rowHeight + (before % rowHeight),
80
+ 0,
81
+ ).scrollTop
82
+ }
83
+
62
84
  export function virtualWindow(
63
85
  count: number,
64
86
  rowHeight: number,
package/src/date.ts CHANGED
@@ -43,7 +43,8 @@ export function daysInMonth(year: number, month: number): number {
43
43
  }
44
44
 
45
45
  export function parseCivilDate(value: unknown): CivilDateParts | null {
46
- if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null
46
+ if (typeof value !== 'string' || value.length !== 10 || !/^\d{4}-\d{2}-\d{2}$/.test(value))
47
+ return null
47
48
  const year = Number(value.slice(0, 4))
48
49
  const month = Number(value.slice(5, 7))
49
50
  const day = Number(value.slice(8, 10))
@@ -113,6 +113,48 @@ export interface MotionLayoutOptions {
113
113
  transition?: Exclude<MotionOptions, { type: 'gravity' }>
114
114
  size?: 'scale' | false
115
115
  enter?: boolean
116
+ /** Removed direct children leave as static copies. Disabled by default; never for recycled rows. */
117
+ exit?: false | 'fadeOut' | { opacity?: number; x?: number; y?: number; scale?: number }
118
+ /** Concurrent exit copies share this pixel budget (1–32,000,000; default 8,000,000). */
119
+ maxSnapshotPixels?: number
120
+ }
121
+
122
+ /** Keep the shared recipe bounded before a host mutation, including the SSR fallback. */
123
+ export function validateMotionLayoutOptions(options: MotionLayoutOptions) {
124
+ if (!options || typeof options !== 'object' || Array.isArray(options))
125
+ throw new TypeError('Layout options must be an object.')
126
+ if (options.size !== undefined && options.size !== false && options.size !== 'scale')
127
+ throw new TypeError('Layout size must be scale or false.')
128
+ if (options.enter !== undefined && typeof options.enter !== 'boolean')
129
+ throw new TypeError('Layout enter must be a boolean.')
130
+ const exit = options.exit
131
+ if (exit !== undefined && exit !== false && exit !== 'fadeOut') {
132
+ if (
133
+ !exit ||
134
+ typeof exit !== 'object' ||
135
+ Array.isArray(exit) ||
136
+ Object.keys(exit).some((key) => !['opacity', 'x', 'y', 'scale'].includes(key))
137
+ )
138
+ throw new TypeError('Layout exit must be false, fadeOut, or opacity/x/y/scale.')
139
+ if (
140
+ Object.values(exit).some((value) => value !== undefined && !Number.isFinite(value)) ||
141
+ (exit.opacity !== undefined && (exit.opacity < 0 || exit.opacity > 1)) ||
142
+ (exit.scale !== undefined && exit.scale <= 0)
143
+ )
144
+ throw new RangeError('Layout exit needs finite values, opacity in [0,1] and positive scale.')
145
+ }
146
+ if (
147
+ options.maxSnapshotPixels !== undefined &&
148
+ (!Number.isSafeInteger(options.maxSnapshotPixels) ||
149
+ options.maxSnapshotPixels <= 0 ||
150
+ options.maxSnapshotPixels > 32_000_000)
151
+ )
152
+ throw new RangeError('Layout maxSnapshotPixels must be an integer in [1,32000000].')
153
+ }
154
+
155
+ export function validateMotionLayoutChange(change: unknown): asserts change is () => void {
156
+ if (typeof change !== 'function' || change.constructor?.name === 'AsyncFunction')
157
+ throw new TypeError('Layout motion needs a synchronous change callback.')
116
158
  }
117
159
  export interface MotionSharedLayout extends MotionBinding {
118
160
  readonly active: boolean
@@ -416,16 +458,14 @@ export function createMotionRegion(): MotionRegion {
416
458
  const region: MotionRegion = {
417
459
  animateLayout(change, options = {}) {
418
460
  const state = regionState(region)
419
- if (typeof change !== 'function')
420
- throw new TypeError('Layout motion needs a synchronous change callback.')
421
- if (options.size !== undefined && options.size !== false && options.size !== 'scale')
422
- throw new TypeError('Layout size must be scale or false.')
423
- if (options.enter !== undefined && typeof options.enter !== 'boolean')
424
- throw new TypeError('Layout enter must be a boolean.')
461
+ validateMotionLayoutChange(change)
462
+ validateMotionLayoutOptions(options)
425
463
  if (!state.adapter.animateLayout) throw new Error('Layout motion is unavailable.')
426
464
  const raw = state.adapter.animateLayout(change, options)
427
465
  const resource = { dispose: () => raw.stop() }
428
- state.resources.add(resource)
466
+ // A synchronous mutation may also remove its host. Do not attach work to that old owner.
467
+ if (state.valid) state.resources.add(resource)
468
+ else raw.stop()
429
469
  const forget = () => state.resources.delete(resource)
430
470
  void raw.finished.then(forget, forget)
431
471
  return {
@@ -123,7 +123,7 @@ export interface MotionSurface extends MotionVisualSurface {
123
123
  options?: MotionDecayOptions,
124
124
  ): MotionControlledPlayback
125
125
  motionValue(initial: number): MotionValue
126
- springValue(source: MotionValue, options?: MotionSpringOptions): MotionSpring
126
+ springValue(source: MotionReadable, options?: MotionSpringOptions): MotionSpring
127
127
  bind(values: MotionBindings): MotionBinding
128
128
  drag(options: MotionDragOptions): MotionDrag
129
129
  /** Re-read a supported size/pivot change without replacing this presentation. */
@@ -147,8 +147,26 @@ export interface MotionBinding {
147
147
  export interface MotionColor extends MotionBinding {
148
148
  get(): string
149
149
  }
150
- export interface MotionReadable extends MotionBinding {
150
+ /** Jolt evaluates these operations. Angles use radians; velocity uses source units/second. */
151
+ export interface MotionScalarOperations {
152
+ add(value: MotionReadable | number): MotionReadable
153
+ sub(value: MotionReadable | number): MotionReadable
154
+ mul(value: MotionReadable | number): MotionReadable
155
+ div(value: MotionReadable | number): MotionReadable
156
+ min(value: MotionReadable | number): MotionReadable
157
+ max(value: MotionReadable | number): MotionReadable
158
+ clamp(minimum: number, maximum: number): MotionReadable
159
+ abs(): MotionReadable
160
+ sin(): MotionReadable
161
+ cos(): MotionReadable
162
+ /** A first-derivative source. Its own velocity is zero, not estimated acceleration. */
163
+ velocity(): MotionReadable
164
+ }
165
+ export type MotionScalarOperation = keyof MotionScalarOperations
166
+ export interface MotionReadable extends MotionBinding, MotionScalarOperations {
151
167
  get(): number
168
+ /** Snapshot of the derivative; reading installs no subscription or frame loop. */
169
+ getVelocity(): number
152
170
  to(
153
171
  input: readonly number[],
154
172
  output: readonly number[],
@@ -193,8 +211,12 @@ export interface MotionDrag extends MotionBinding {
193
211
  }
194
212
 
195
213
  /** Renderer contracts. Values never expose their DOM/native target. */
214
+ export type MotionReadableAdapter = Pick<MotionReadable, 'get' | 'dispose'>
196
215
  export type MotionValueAdapter = Pick<MotionValue, 'get' | 'set' | 'dispose'>
197
- export type MotionSpringAdapter = Omit<MotionSpring, 'disposed' | 'to'>
216
+ export type MotionSpringAdapter = Pick<
217
+ MotionSpring,
218
+ 'get' | 'getVelocity' | 'dispose' | 'moving' | 'paused' | 'pause' | 'resume'
219
+ >
198
220
  export type MotionDragAdapter = Omit<MotionDrag, 'disposed'>
199
221
  export interface MotionSurfaceAdapter extends Partial<MotionVisualAdapter> {
200
222
  sensor?(kind: MotionSensorKind, options?: MotionSensorOptions): MotionSensorAdapter
@@ -212,7 +234,14 @@ export interface MotionSurfaceAdapter extends Partial<MotionVisualAdapter> {
212
234
  playbackProgress?(playback: MotionPlayback): Pick<MotionReadable, 'get' | 'dispose'>
213
235
  decay?(velocity: { x?: number; y?: number }, options?: MotionDecayOptions): MotionPlayback
214
236
  motionValue?(initial: number): MotionValueAdapter
215
- springValue?(source: MotionValueAdapter, options?: MotionSpringOptions): MotionSpringAdapter
237
+ springValue?(source: MotionReadableAdapter, options?: MotionSpringOptions): MotionSpringAdapter
238
+ scalar?(
239
+ source: MotionReadableAdapter,
240
+ operation: MotionScalarOperation,
241
+ operand?: MotionReadableAdapter | number,
242
+ maximum?: number,
243
+ ): MotionReadableAdapter
244
+ readVelocity?(source: MotionReadableAdapter): number
216
245
  bind?(values: {
217
246
  [K in keyof MotionBindings]?: Pick<NonNullable<MotionBindings[K]>, 'get' | 'dispose'>
218
247
  }): {
@@ -397,6 +426,7 @@ type ValueState = {
397
426
  binding: Binding
398
427
  raw: Pick<MotionReadable, 'get' | 'dispose'> | Pick<MotionColor, 'get' | 'dispose'>
399
428
  input: boolean
429
+ numeric: boolean
400
430
  depth: number
401
431
  dependents: Set<Resource>
402
432
  }
@@ -457,9 +487,66 @@ function ownValue<T extends Pick<MotionReadable, 'get' | 'dispose'>>(
457
487
  binding: Binding,
458
488
  raw: T,
459
489
  input: boolean,
460
- parent?: ValueState,
490
+ parents: readonly ValueState[] = [],
461
491
  ): T & MotionReadable {
492
+ const scalar = (
493
+ operation: MotionScalarOperation,
494
+ operand?: MotionReadable | number,
495
+ maximum?: number,
496
+ ) => {
497
+ const state = values.get(value)!
498
+ const dependencies = [state]
499
+ let other: MotionReadableAdapter | number | undefined
500
+ if (typeof operand === 'number') {
501
+ if (!Number.isFinite(operand)) throw new RangeError('A scalar operand must be finite.')
502
+ other = operand
503
+ } else if (operand !== undefined) {
504
+ const candidate = values.get(operand)
505
+ if (
506
+ !candidate?.numeric ||
507
+ !candidate.binding.valid ||
508
+ candidate.binding.context !== binding.context ||
509
+ operand.disposed
510
+ )
511
+ throw new TypeError('Use a live numeric value from this surface and presentation.')
512
+ other = candidate.raw as MotionReadableAdapter
513
+ dependencies.push(candidate)
514
+ } else if (['add', 'sub', 'mul', 'div', 'min', 'max', 'clamp'].includes(operation)) {
515
+ throw new TypeError('A scalar operation needs an operand.')
516
+ }
517
+ if (
518
+ operation === 'clamp' &&
519
+ (typeof operand !== 'number' || !Number.isFinite(maximum) || operand > maximum!)
520
+ )
521
+ throw new RangeError('Scalar bounds must be finite and ordered.')
522
+ if (dependencies.some((parent) => parent.depth >= 32))
523
+ throw new RangeError('Motion values support at most 32 derived levels.')
524
+ if (!binding.adapter.scalar) throw new Error('Combined motion values are unavailable.')
525
+ return ownValue(
526
+ binding,
527
+ binding.adapter.scalar(raw, operation, other, maximum),
528
+ false,
529
+ dependencies,
530
+ )
531
+ }
462
532
  const mapped = Object.assign({}, raw, {
533
+ add: (operand: MotionReadable | number) => scalar('add', operand),
534
+ sub: (operand: MotionReadable | number) => scalar('sub', operand),
535
+ mul: (operand: MotionReadable | number) => scalar('mul', operand),
536
+ div: (operand: MotionReadable | number) => scalar('div', operand),
537
+ min: (operand: MotionReadable | number) => scalar('min', operand),
538
+ max: (operand: MotionReadable | number) => scalar('max', operand),
539
+ clamp: (minimum: number, maximum: number) => scalar('clamp', minimum, maximum),
540
+ abs: () => scalar('abs'),
541
+ sin: () => scalar('sin'),
542
+ cos: () => scalar('cos'),
543
+ velocity: () => scalar('velocity'),
544
+ getVelocity() {
545
+ if (binding.adapter.readVelocity) return binding.adapter.readVelocity(raw)
546
+ if ('getVelocity' in raw && typeof raw.getVelocity === 'function')
547
+ return raw.getVelocity() as number
548
+ throw new Error('Motion velocity is unavailable.')
549
+ },
463
550
  to(
464
551
  input: readonly number[],
465
552
  output: readonly (number | string)[],
@@ -500,6 +587,7 @@ function ownValue<T extends Pick<MotionReadable, 'get' | 'dispose'>>(
500
587
  binding,
501
588
  raw: rawColor,
502
589
  input: false,
590
+ numeric: false,
503
591
  depth: state.depth + 1,
504
592
  dependents: new Set(),
505
593
  })
@@ -511,23 +599,39 @@ function ownValue<T extends Pick<MotionReadable, 'get' | 'dispose'>>(
511
599
  binding,
512
600
  binding.adapter.map(raw, input, output as readonly number[], options),
513
601
  false,
514
- state,
602
+ [state],
515
603
  )
516
604
  },
517
605
  })
518
606
  // Preserve getters such as moving/paused; Object.assign would snapshot them.
519
607
  const descriptors = Object.getOwnPropertyDescriptors(raw)
520
- delete (descriptors as Record<string, PropertyDescriptor>).to
608
+ for (const key of [
609
+ 'to',
610
+ 'getVelocity',
611
+ 'add',
612
+ 'sub',
613
+ 'mul',
614
+ 'div',
615
+ 'min',
616
+ 'max',
617
+ 'clamp',
618
+ 'abs',
619
+ 'sin',
620
+ 'cos',
621
+ 'velocity',
622
+ ])
623
+ delete (descriptors as Record<string, PropertyDescriptor>)[key]
521
624
  Object.defineProperties(mapped, descriptors)
522
625
  const value = own(binding, mapped) as T & MotionReadable
523
626
  values.set(value, {
524
627
  binding,
525
628
  raw,
526
629
  input,
527
- depth: parent ? parent.depth + 1 : 0,
630
+ numeric: true,
631
+ depth: parents.length ? Math.max(...parents.map((parent) => parent.depth)) + 1 : 0,
528
632
  dependents: new Set(),
529
633
  })
530
- if (parent) depend(parent, value)
634
+ for (const parent of parents) depend(parent, value)
531
635
  return value as T & MotionReadable
532
636
  }
533
637
 
@@ -1002,10 +1106,11 @@ export function createMotionSurface(): MotionSurface {
1002
1106
  },
1003
1107
  springValue(input, options) {
1004
1108
  const binding = current()
1005
- const parent = source(input, binding, true)
1109
+ const parent = source(input, binding)
1110
+ if (!parent.numeric) throw new TypeError('A spring needs a live numeric value.')
1006
1111
  if (!binding.adapter.springValue) throw new Error('Continuous motion is unavailable.')
1007
- const raw = binding.adapter.springValue(parent.raw as MotionValueAdapter, options)
1008
- return ownValue(binding, raw, false, parent)
1112
+ const raw = binding.adapter.springValue(parent.raw as MotionReadableAdapter, options)
1113
+ return ownValue(binding, raw, false, [parent])
1009
1114
  },
1010
1115
  bind(input) {
1011
1116
  const binding = current()
package/src/index.ts CHANGED
@@ -78,7 +78,12 @@ export type {
78
78
  ButtonEvents,
79
79
  TextInputHandle,
80
80
  } from './contracts.js'
81
- export { targetCapabilities, componentNames, themeContract } from './capabilities.js'
81
+ export {
82
+ targetCapabilities,
83
+ componentNames,
84
+ themeContract,
85
+ macosCapabilities,
86
+ } from './capabilities.js'
82
87
  export type { ComponentName, CapabilityStatus } from './capabilities.js'
83
88
 
84
89
  export * from './date.js'