@getcortexlabs/mavis-core 0.1.0-rc.12.2 → 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 (130) 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 +12 -4
  11. package/dist/contracts.d.ts.map +1 -1
  12. package/dist/contracts.js +1 -0
  13. package/dist/contracts.js.map +1 -1
  14. package/dist/date.d.ts.map +1 -1
  15. package/dist/date.js +1 -1
  16. package/dist/date.js.map +1 -1
  17. package/dist/experimental-depth.d.ts +45 -0
  18. package/dist/experimental-depth.d.ts.map +1 -0
  19. package/dist/experimental-depth.js +179 -0
  20. package/dist/experimental-depth.js.map +1 -0
  21. package/dist/experimental-effects.d.ts +1 -1
  22. package/dist/experimental-effects.d.ts.map +1 -1
  23. package/dist/experimental-effects.js.map +1 -1
  24. package/dist/experimental-playback.d.ts +3 -3
  25. package/dist/experimental-playback.d.ts.map +1 -1
  26. package/dist/experimental-playback.js.map +1 -1
  27. package/dist/experimental-regions.d.ts +25 -3
  28. package/dist/experimental-regions.d.ts.map +1 -1
  29. package/dist/experimental-regions.js +37 -7
  30. package/dist/experimental-regions.js.map +1 -1
  31. package/dist/experimental-sensors.d.ts +2 -1
  32. package/dist/experimental-sensors.d.ts.map +1 -1
  33. package/dist/experimental.d.ts +45 -9
  34. package/dist/experimental.d.ts.map +1 -1
  35. package/dist/experimental.js +94 -9
  36. package/dist/experimental.js.map +1 -1
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/macos-capabilities.generated.d.ts +1738 -0
  42. package/dist/macos-capabilities.generated.d.ts.map +1 -0
  43. package/dist/macos-capabilities.generated.js +4191 -0
  44. package/dist/macos-capabilities.generated.js.map +1 -0
  45. package/dist/motion.d.ts +1 -1
  46. package/dist/section-scroll.d.ts +2 -0
  47. package/dist/section-scroll.d.ts.map +1 -1
  48. package/dist/section-scroll.js +2 -0
  49. package/dist/section-scroll.js.map +1 -1
  50. package/dist/vue/advanced-collections.d.ts +16 -16
  51. package/dist/vue/advanced-collections.d.ts.map +1 -1
  52. package/dist/vue/advanced-collections.js +24 -3
  53. package/dist/vue/advanced-collections.js.map +1 -1
  54. package/dist/vue/animated-text.d.ts +4 -4
  55. package/dist/vue/chart.d.ts +5 -5
  56. package/dist/vue/chart.d.ts.map +1 -1
  57. package/dist/vue/chart.js +28 -7
  58. package/dist/vue/chart.js.map +1 -1
  59. package/dist/vue/combobox.d.ts.map +1 -1
  60. package/dist/vue/combobox.js +13 -11
  61. package/dist/vue/combobox.js.map +1 -1
  62. package/dist/vue/command-palette.d.ts +5 -5
  63. package/dist/vue/component-motion.d.ts.map +1 -1
  64. package/dist/vue/component-motion.js +4 -2
  65. package/dist/vue/component-motion.js.map +1 -1
  66. package/dist/vue/component-props.d.ts +30 -21
  67. package/dist/vue/component-props.d.ts.map +1 -1
  68. package/dist/vue/composer.d.ts +10 -10
  69. package/dist/vue/configurator.d.ts +15 -15
  70. package/dist/vue/creative-controls.d.ts +10 -10
  71. package/dist/vue/dashboard-charts.d.ts +6 -6
  72. package/dist/vue/dashboard-effects.d.ts +6 -6
  73. package/dist/vue/date-picker.d.ts +48 -48
  74. package/dist/vue/discovery-controls.d.ts +7 -7
  75. package/dist/vue/image-cropper.d.ts +8 -8
  76. package/dist/vue/image-cropper.d.ts.map +1 -1
  77. package/dist/vue/kanban.d.ts +25 -7
  78. package/dist/vue/kanban.d.ts.map +1 -1
  79. package/dist/vue/kanban.js +73 -44
  80. package/dist/vue/kanban.js.map +1 -1
  81. package/dist/vue/list-motion.d.ts.map +1 -1
  82. package/dist/vue/list-motion.js +24 -7
  83. package/dist/vue/list-motion.js.map +1 -1
  84. package/dist/vue/marquee.d.ts +4 -4
  85. package/dist/vue/menu.d.ts +4 -4
  86. package/dist/vue/navigation-props.d.ts +5 -0
  87. package/dist/vue/navigation-props.d.ts.map +1 -1
  88. package/dist/vue/navigation-props.js +2 -0
  89. package/dist/vue/navigation-props.js.map +1 -1
  90. package/dist/vue/number-flow.d.ts +3 -3
  91. package/dist/vue/platform.d.ts +7 -1
  92. package/dist/vue/platform.d.ts.map +1 -1
  93. package/dist/vue/platform.js +5 -4
  94. package/dist/vue/platform.js.map +1 -1
  95. package/dist/vue/props.d.ts +52 -42
  96. package/dist/vue/props.d.ts.map +1 -1
  97. package/dist/vue/reveal-state.d.ts +1 -1
  98. package/dist/vue/scheduler.d.ts +10 -10
  99. package/dist/vue/scroll-frame.d.ts +6 -6
  100. package/dist/vue/speed-dial.d.ts +3 -3
  101. package/dist/vue/swipe-actions.d.ts +3 -3
  102. package/dist/vue/swipe-deck.d.ts +3 -3
  103. package/dist/vue/theme-provider.d.ts +1 -1
  104. package/dist/vue/time-picker.d.ts +20 -20
  105. package/dist/vue/tour.d.ts +3 -3
  106. package/dist/vue/tree-view.d.ts +3 -3
  107. package/dist/vue/wayfinding-controls.d.ts +1 -1
  108. package/dist/vue/workflows.d.ts +5 -5
  109. package/package.json +1 -1
  110. package/src/capabilities.ts +89 -5
  111. package/src/collections.ts +22 -0
  112. package/src/contracts.ts +1 -0
  113. package/src/date.ts +2 -1
  114. package/src/experimental-depth.ts +215 -0
  115. package/src/experimental-effects.ts +1 -0
  116. package/src/experimental-playback.ts +4 -3
  117. package/src/experimental-regions.ts +60 -10
  118. package/src/experimental-sensors.ts +2 -1
  119. package/src/experimental.ts +166 -19
  120. package/src/index.ts +6 -1
  121. package/src/macos-capabilities.generated.ts +4190 -0
  122. package/src/section-scroll.ts +4 -0
  123. package/src/vue/advanced-collections.ts +29 -7
  124. package/src/vue/chart.ts +34 -9
  125. package/src/vue/combobox.ts +15 -14
  126. package/src/vue/component-motion.ts +4 -2
  127. package/src/vue/kanban.ts +99 -59
  128. package/src/vue/list-motion.ts +23 -7
  129. package/src/vue/navigation-props.ts +2 -0
  130. package/src/vue/platform.ts +13 -5
@@ -218,8 +218,8 @@ export declare function createTimePicker(ui: {
218
218
  };
219
219
  }>> & Readonly<{
220
220
  onFocus?: (() => any) | undefined;
221
- onBlur?: (() => any) | undefined;
222
221
  "onUpdate:modelValue"?: ((_value: string | null) => any) | undefined;
222
+ onBlur?: (() => any) | undefined;
223
223
  "onUpdate:draft"?: ((_value: string) => any) | undefined;
224
224
  onValidityChange?: ((_value: TimeValidation) => any) | undefined;
225
225
  }>, {
@@ -228,23 +228,23 @@ export declare function createTimePicker(ui: {
228
228
  disabled: boolean;
229
229
  error: string;
230
230
  id: string;
231
+ grow: number;
231
232
  modelValue: string | null;
232
233
  width: import("../layout.js").Dimension;
233
- grow: number;
234
- placeholder: string;
235
- helperText: string;
236
- required: boolean;
237
- readonly: boolean;
238
234
  locale: import("../time.js").TimeLocale;
239
- confirmLabel: string;
240
- cancelLabel: string;
235
+ readonly: boolean;
241
236
  clearLabel: string;
242
- draft: string;
237
+ helperText: string;
243
238
  invalidLabel: string;
244
- minuteStep: number;
239
+ placeholder: string;
240
+ draft: string;
241
+ cancelLabel: string;
242
+ confirmLabel: string;
245
243
  chooseLabel: string;
244
+ required: boolean;
246
245
  hourLabel: string;
247
246
  minuteLabel: string;
247
+ minuteStep: number;
248
248
  periodLabel: string;
249
249
  }, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any> & {
250
250
  new (): InstanceType<import("@vue/runtime-core").DefineComponent<import("@vue/runtime-core").ExtractPropTypes<{
@@ -455,8 +455,8 @@ export declare function createTimePicker(ui: {
455
455
  };
456
456
  }>> & Readonly<{
457
457
  onFocus?: (() => any) | undefined;
458
- onBlur?: (() => any) | undefined;
459
458
  "onUpdate:modelValue"?: ((_value: string | null) => any) | undefined;
459
+ onBlur?: (() => any) | undefined;
460
460
  "onUpdate:draft"?: ((_value: string) => any) | undefined;
461
461
  onValidityChange?: ((_value: TimeValidation) => any) | undefined;
462
462
  }>, {
@@ -465,23 +465,23 @@ export declare function createTimePicker(ui: {
465
465
  disabled: boolean;
466
466
  error: string;
467
467
  id: string;
468
+ grow: number;
468
469
  modelValue: string | null;
469
470
  width: import("../layout.js").Dimension;
470
- grow: number;
471
- placeholder: string;
472
- helperText: string;
473
- required: boolean;
474
- readonly: boolean;
475
471
  locale: import("../time.js").TimeLocale;
476
- confirmLabel: string;
477
- cancelLabel: string;
472
+ readonly: boolean;
478
473
  clearLabel: string;
479
- draft: string;
474
+ helperText: string;
480
475
  invalidLabel: string;
481
- minuteStep: number;
476
+ placeholder: string;
477
+ draft: string;
478
+ cancelLabel: string;
479
+ confirmLabel: string;
482
480
  chooseLabel: string;
481
+ required: boolean;
483
482
  hourLabel: string;
484
483
  minuteLabel: string;
484
+ minuteStep: number;
485
485
  periodLabel: string;
486
486
  }, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>> & InputHandle;
487
487
  };
@@ -93,15 +93,15 @@ export declare function createTour(ui: {
93
93
  };
94
94
  }>> & Readonly<{
95
95
  onMissing?: ((_id: string) => any) | undefined;
96
- onFinish?: ((_reason: string) => any) | undefined;
97
96
  "onUpdate:modelValue"?: ((_id: string | null) => any) | undefined;
97
+ onFinish?: ((_reason: string) => any) | undefined;
98
98
  }>, {
99
99
  modelValue: string | null;
100
100
  animated: boolean;
101
- nextLabel: string;
102
101
  backLabel: string;
103
- skipLabel: string;
102
+ nextLabel: string;
104
103
  finishLabel: string;
104
+ skipLabel: string;
105
105
  }, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
106
106
  MTourTarget: import("@vue/runtime-core").DefineComponent<import("@vue/runtime-core").ExtractPropTypes<{
107
107
  name: {
@@ -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.12.2",
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.12.2',
111
+ publishedBaseline: '0.1.0-rc.14',
109
112
  developmentMotion: {
110
113
  availability: 'published',
111
114
  joltCommit: null,
112
- publishedJoltRelease: '0.1.0-rc.12.1',
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.12.1', 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.12.1', 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/contracts.ts CHANGED
@@ -89,6 +89,7 @@ export const motionBoxContract = {
89
89
  runtimeOnly: true,
90
90
  }),
91
91
  motionRegion: property<MotionRegion>()({ kind: 'object', default: undefined, runtimeOnly: true }),
92
+ perspective: number({ kind: 'number', default: undefined }),
92
93
  }
93
94
  export type Align = 'start' | 'center' | 'end' | 'stretch'
94
95
  export type Justify = 'start' | 'center' | 'end' | 'between' | 'around'
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))
@@ -0,0 +1,215 @@
1
+ import type { MotionVector } from './experimental-platforms.js'
2
+ import type { Shadow } from './theme/types.js'
3
+
4
+ export type MotionPathSegment =
5
+ | { to: MotionVector; control?: undefined }
6
+ | { to: MotionVector; control: MotionVector }
7
+ | { to: MotionVector; control: readonly [MotionVector, MotionVector] }
8
+ export interface MotionPathBounds {
9
+ readonly left: number
10
+ readonly top: number
11
+ readonly right: number
12
+ readonly bottom: number
13
+ }
14
+ /** A translation path in CSS pixels on Web and device-independent pixels on NativeScript. */
15
+ export interface MotionPath {
16
+ readonly data: string
17
+ readonly bounds: MotionPathBounds
18
+ /** Where the surface rests afterwards, with the forward tangent in degrees. */
19
+ readonly end: Readonly<MotionVector & { rotate: number }>
20
+ }
21
+ export type MotionShadowValues = Partial<
22
+ Record<'shadowOpacity' | 'shadowRadius' | 'shadowOffsetX' | 'shadowOffsetY', number>
23
+ >
24
+
25
+ const paths = new WeakSet<MotionPath>()
26
+ const limit = 1e5
27
+ const round = (value: number) => Number(value.toFixed(3))
28
+ const point = (value: MotionVector | undefined, name: string): MotionVector => {
29
+ if (
30
+ !value ||
31
+ typeof value !== 'object' ||
32
+ !Number.isFinite(value.x) ||
33
+ !Number.isFinite(value.y) ||
34
+ Math.abs(value.x) > limit ||
35
+ Math.abs(value.y) > limit
36
+ )
37
+ throw new RangeError(`Path ${name} needs finite x and y within ${limit} pixels/DIPs.`)
38
+ return { x: round(value.x), y: round(value.y) }
39
+ }
40
+ const bezier = (points: readonly number[], t: number) => {
41
+ let values = [...points]
42
+ while (values.length > 1)
43
+ values = values.slice(1).map((value, index) => values[index]! + (value - values[index]!) * t)
44
+ return values[0]!
45
+ }
46
+ const turns = (points: readonly number[]) => {
47
+ if (points.length === 3) {
48
+ const divisor = points[0]! - 2 * points[1]! + points[2]!
49
+ return divisor === 0 ? [] : [(points[0]! - points[1]!) / divisor]
50
+ }
51
+ const a = -points[0]! + 3 * points[1]! - 3 * points[2]! + points[3]!
52
+ const b = 2 * (points[0]! - 2 * points[1]! + points[2]!)
53
+ const c = points[1]! - points[0]!
54
+ if (a === 0) return b === 0 ? [] : [-c / b]
55
+ const root = b * b - 4 * a * c
56
+ if (root < 0) return []
57
+ return [(-b + Math.sqrt(root)) / (2 * a), (-b - Math.sqrt(root)) / (2 * a)]
58
+ }
59
+
60
+ /** Lines, quadratic and cubic curves in one continuous path, with bounds known up front. */
61
+ export function motionPath(start: MotionVector, ...segments: MotionPathSegment[]): MotionPath {
62
+ if (segments.length < 1 || segments.length > 64)
63
+ throw new RangeError('A motion path needs between 1 and 64 segments.')
64
+ let from = point(start, 'start')
65
+ let data = `M ${from.x} ${from.y}`
66
+ const xs = [from.x]
67
+ const ys = [from.y]
68
+ let rotate = 0
69
+ segments.forEach((segment, index) => {
70
+ const to = point(segment?.to, `segment ${index + 1} end`)
71
+ const controls = (
72
+ segment.control === undefined
73
+ ? []
74
+ : Array.isArray(segment.control)
75
+ ? segment.control
76
+ : [segment.control]
77
+ ).map((value, at) => point(value as MotionVector, `segment ${index + 1} control ${at + 1}`))
78
+ if (controls.length > 2) throw new RangeError('A path segment takes one or two control points.')
79
+ const all = [from, ...controls, to]
80
+ if (all.every((value) => value.x === from.x && value.y === from.y))
81
+ throw new RangeError(`Path segment ${index + 1} has no length.`)
82
+ data += ` ${'LQC'[controls.length]} ${[...controls, to].map((value) => `${value.x} ${value.y}`).join(' ')}`
83
+ for (const [axis, values] of [
84
+ ['x', xs],
85
+ ['y', ys],
86
+ ] as const) {
87
+ const line = all.map((value) => value[axis])
88
+ values.push(to[axis])
89
+ if (controls.length)
90
+ for (const t of turns(line)) if (t > 0 && t < 1) values.push(bezier(line, t))
91
+ }
92
+ const tangent = all
93
+ .slice(0, -1)
94
+ .reverse()
95
+ .find((value) => value.x !== to.x || value.y !== to.y)!
96
+ rotate = (Math.atan2(to.y - tangent.y, to.x - tangent.x) * 180) / Math.PI
97
+ from = to
98
+ })
99
+ const path: MotionPath = Object.freeze({
100
+ data,
101
+ bounds: Object.freeze({
102
+ left: round(Math.min(...xs)),
103
+ top: round(Math.min(...ys)),
104
+ right: round(Math.max(...xs)),
105
+ bottom: round(Math.max(...ys)),
106
+ }),
107
+ end: Object.freeze({ x: from.x, y: from.y, rotate: round(rotate) }),
108
+ })
109
+ paths.add(path)
110
+ return path
111
+ }
112
+
113
+ const planar = ['x', 'y', 'rotate', 'scale', 'scaleX', 'scaleY', 'opacity', 'rotateX', 'rotateY']
114
+ const shadows = ['shadowOpacity', 'shadowRadius', 'shadowOffsetX', 'shadowOffsetY']
115
+ /** The channels a path replaces, so renderers can release them from other owners. */
116
+ export function motionChannels(values: Record<string, unknown>) {
117
+ return Object.keys(values).flatMap((key) =>
118
+ key === 'path' ? ['x', 'y', ...(values.orient ? ['rotate'] : [])] : key === 'orient' ? [] : key,
119
+ )
120
+ }
121
+ /** Renderer input: the descriptor becomes the path string both engines read. */
122
+ export function motionKeyframes<T extends { path?: MotionPath }>(
123
+ values: T,
124
+ ): Omit<T, 'path'> & { path?: string } {
125
+ const { path, ...channels } = values
126
+ return path === undefined ? channels : { ...channels, path: path.data }
127
+ }
128
+
129
+ /** Rejects a request before a renderer replaces the motion already running. */
130
+ export function validateMotion(
131
+ values: Record<string, unknown>,
132
+ frames: boolean,
133
+ supportsShadow: () => boolean,
134
+ ) {
135
+ if (!values || typeof values !== 'object') throw new TypeError('Motion needs an object.')
136
+ const keys = Object.keys(values).filter((key) => values[key] !== undefined)
137
+ for (const key of keys) {
138
+ const value = values[key]
139
+ if (frames && key === 'path') {
140
+ if (!paths.has(value as MotionPath))
141
+ throw new TypeError('Use motionPath() to declare a path.')
142
+ continue
143
+ }
144
+ if (frames && key === 'orient') {
145
+ if (typeof value !== 'boolean') throw new TypeError('Path orient must be a boolean.')
146
+ continue
147
+ }
148
+ if (!planar.includes(key) && !shadows.includes(key))
149
+ throw new TypeError(`Unsupported motion property "${key}".`)
150
+ const list = frames && Array.isArray(value) ? value : [value]
151
+ if (
152
+ !list.length ||
153
+ list.length > 1024 ||
154
+ list.some((entry) => !(frames && entry === null) && !Number.isFinite(entry))
155
+ )
156
+ throw new TypeError(`Motion property "${key}" needs finite numbers.`)
157
+ const numbers = list.filter((entry): entry is number => entry !== null)
158
+ if (key === 'shadowOpacity' && numbers.some((entry) => entry < 0 || entry > 1))
159
+ throw new RangeError('Shadow opacity must be between 0 and 1.')
160
+ if (key === 'shadowRadius' && numbers.some((entry) => entry < 0))
161
+ throw new RangeError('Shadow radius cannot be negative.')
162
+ }
163
+ if (keys.includes('orient') && !keys.includes('path'))
164
+ throw new TypeError('Path orient needs a path.')
165
+ if (keys.includes('path')) {
166
+ if (keys.includes('x') || keys.includes('y'))
167
+ throw new TypeError('A path owns x and y. Remove them or drop the path.')
168
+ if (values.orient === true && keys.includes('rotate'))
169
+ throw new TypeError('An oriented path owns rotate. Remove it or turn orient off.')
170
+ }
171
+ if (keys.some((key) => shadows.includes(key)) && !supportsShadow())
172
+ throw new Error(
173
+ 'Shadow motion is unavailable on this surface. Check supports("shadow") and keep the static shadow.',
174
+ )
175
+ }
176
+
177
+ /** Projection distance for the rotateX/rotateY of a box's direct children. */
178
+ export function resolvePerspective(value: number | undefined) {
179
+ if (value === undefined) return undefined
180
+ if (!Number.isFinite(value) || value < 1 || value > limit)
181
+ throw new RangeError('Perspective must be between 1 and 100000 pixels/DIPs.')
182
+ return value
183
+ }
184
+
185
+ /** A theme elevation as shadow channels, so a recipe moves between the theme's own shadows. */
186
+ export function elevationMotion(shadow: Readonly<Shadow>): Required<MotionShadowValues> {
187
+ if (shadow.spread !== 0) throw new RangeError('Shadow motion needs an elevation without spread.')
188
+ const color = shadow.color.trim().toLowerCase()
189
+ const parts = /^rgba?\(([^)]*)\)$/
190
+ .exec(color)?.[1]
191
+ ?.split(/[\s,/]+/)
192
+ .filter(Boolean)
193
+ const alpha =
194
+ color === 'transparent'
195
+ ? 0
196
+ : parts
197
+ ? parts.length > 3
198
+ ? parts[3]!.endsWith('%')
199
+ ? parseFloat(parts[3]!) / 100
200
+ : Number(parts[3])
201
+ : 1
202
+ : /^#(?:[\da-f]{4}|[\da-f]{8})$/.test(color)
203
+ ? parseInt(color.length === 5 ? color[4]!.repeat(2) : color.slice(7), 16) / 255
204
+ : /^#(?:[\da-f]{3}|[\da-f]{6})$/.test(color)
205
+ ? 1
206
+ : Number.NaN
207
+ if (!Number.isFinite(alpha) || alpha < 0 || alpha > 1)
208
+ throw new TypeError('Shadow motion reads rgb(), rgba(), hex or transparent colors.')
209
+ return {
210
+ shadowOpacity: round(alpha),
211
+ shadowRadius: shadow.blur / 2,
212
+ shadowOffsetX: shadow.x,
213
+ shadowOffsetY: shadow.y,
214
+ }
215
+ }
@@ -22,6 +22,7 @@ export type MotionEffectKind =
22
22
  | 'image'
23
23
  | 'symbol'
24
24
  | 'keyboard'
25
+ | 'shadow'
25
26
  export interface MotionGradientValues {
26
27
  colors?: readonly string[]
27
28
  stops?: readonly number[]
@@ -1,6 +1,6 @@
1
1
  import type {
2
2
  MotionPlayback,
3
- MotionFrames,
3
+ MotionChannelFrames,
4
4
  MotionOptions,
5
5
  MotionSurface,
6
6
  MotionSurfaceAdapter,
@@ -31,9 +31,10 @@ export interface MotionDecayOptions {
31
31
  }
32
32
  export type MotionPosition = number | '<' | `${'+' | '-'}${number}`
33
33
  export type MotionStep<T = MotionSurface> =
34
- readonly [T, MotionFrames, (MotionOptions & { at?: MotionPosition })?] | (() => MotionPlayback)
34
+ | readonly [T, MotionChannelFrames, (MotionOptions & { at?: MotionPosition })?]
35
+ | (() => MotionPlayback)
35
36
  export type MotionTimelineStep<T = MotionSurface> =
36
- | readonly [T, MotionFrames, (MotionOptions & { at?: MotionPosition })?]
37
+ | readonly [T, MotionChannelFrames, (MotionOptions & { at?: MotionPosition })?]
37
38
  | (() => MotionControlledPlayback)
38
39
  | { at?: MotionPosition; run: () => MotionControlledPlayback }
39
40
  export type MotionStateDefinitions<K extends string = string> = Record<