@getcortexlabs/mavis-web 0.1.0-alpha.6 → 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 (68) hide show
  1. package/README.md +4 -4
  2. package/dist/components/ChoicePaint.d.ts +17 -0
  3. package/dist/components/ChoicePaint.d.ts.map +1 -0
  4. package/dist/components/ChoicePaint.js +81 -0
  5. package/dist/components/ChoicePaint.js.map +1 -0
  6. package/dist/components/DateCalendar.d.ts +3 -3
  7. package/dist/components/MBadge.d.ts +1 -1
  8. package/dist/components/MButton.d.ts +6 -6
  9. package/dist/components/MCard.d.ts +6 -5
  10. package/dist/components/MCard.d.ts.map +1 -1
  11. package/dist/components/MCard.js +9 -2
  12. package/dist/components/MCard.js.map +1 -1
  13. package/dist/components/MCheckbox.d.ts.map +1 -1
  14. package/dist/components/MCheckbox.js +8 -3
  15. package/dist/components/MCheckbox.js.map +1 -1
  16. package/dist/components/MChip.d.ts +2 -2
  17. package/dist/components/MDatePicker.d.ts +16 -16
  18. package/dist/components/MDialog.d.ts +1 -1
  19. package/dist/components/MEmptyState.d.ts +1 -1
  20. package/dist/components/MFilePicker.d.ts +2 -2
  21. package/dist/components/MIcon.d.ts +1 -1
  22. package/dist/components/MImage.d.ts +192 -0
  23. package/dist/components/MImage.d.ts.map +1 -0
  24. package/dist/components/MImage.js +97 -0
  25. package/dist/components/MImage.js.map +1 -0
  26. package/dist/components/MInput.d.ts +2 -2
  27. package/dist/components/MLink.d.ts +1 -1
  28. package/dist/components/MProgress.d.ts +2 -2
  29. package/dist/components/MRadioGroup.d.ts.map +1 -1
  30. package/dist/components/MRadioGroup.js +5 -3
  31. package/dist/components/MRadioGroup.js.map +1 -1
  32. package/dist/components/MReveal.d.ts +1 -1
  33. package/dist/components/MSeparator.d.ts +1 -1
  34. package/dist/components/MSheet.d.ts +1 -1
  35. package/dist/components/MStack.d.ts +3 -3
  36. package/dist/components/MSwitch.d.ts.map +1 -1
  37. package/dist/components/MSwitch.js +9 -2
  38. package/dist/components/MSwitch.js.map +1 -1
  39. package/dist/components/MText.d.ts +5 -5
  40. package/dist/components/configurator.d.ts +541 -0
  41. package/dist/components/configurator.d.ts.map +1 -0
  42. package/dist/components/configurator.js +20 -0
  43. package/dist/components/configurator.js.map +1 -0
  44. package/dist/components/layout.d.ts +3 -3
  45. package/dist/components/workflows.d.ts +1 -1
  46. package/dist/index.d.ts +3 -1
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +6 -1
  49. package/dist/index.js.map +1 -1
  50. package/dist/motion-surface.d.ts +4 -0
  51. package/dist/motion-surface.d.ts.map +1 -1
  52. package/dist/motion-surface.js +62 -2
  53. package/dist/motion-surface.js.map +1 -1
  54. package/dist/scroll-motion.d.ts.map +1 -1
  55. package/dist/scroll-motion.js +17 -4
  56. package/dist/scroll-motion.js.map +1 -1
  57. package/package.json +3 -3
  58. package/src/components/ChoicePaint.ts +96 -0
  59. package/src/components/MCard.ts +9 -1
  60. package/src/components/MCheckbox.ts +14 -3
  61. package/src/components/MImage.ts +108 -0
  62. package/src/components/MRadioGroup.ts +9 -3
  63. package/src/components/MSwitch.ts +14 -3
  64. package/src/components/configurator.ts +24 -0
  65. package/src/index.ts +8 -0
  66. package/src/motion-surface.ts +60 -3
  67. package/src/scroll-motion.ts +15 -3
  68. package/src/style.css +7 -10
@@ -1,3 +1,4 @@
1
+ import { ChoicePaintSurface } from './ChoicePaint.js'
1
2
  import { fontFamily } from '@getcortexlabs/mavis-core'
2
3
  import { defineComponent, h, mergeProps, useId } from 'vue'
3
4
  import {
@@ -98,9 +99,19 @@ export const MSwitch = defineComponent({
98
99
  : null,
99
100
  ],
100
101
  ),
101
- h('span', { class: 'm-switch-track', 'aria-hidden': 'true' }, [
102
- h('span', { class: 'm-switch-thumb' }),
103
- ]),
102
+ h(
103
+ ChoicePaintSurface,
104
+ {
105
+ class: 'm-switch-track',
106
+ paint: { backgroundColor: props.modelValue ? colors.primary : colors.muted },
107
+ },
108
+ () => [
109
+ h(ChoicePaintSurface, {
110
+ class: 'm-switch-thumb',
111
+ paint: { backgroundColor: props.modelValue ? colors.onPrimary : colors.surface },
112
+ }),
113
+ ],
114
+ ),
104
115
  ],
105
116
  )
106
117
  }
@@ -0,0 +1,24 @@
1
+ import { createConfiguratorControls } from '@getcortexlabs/mavis-core/vue'
2
+ import { MText } from './MText.js'
3
+ import { MButton } from './MButton.js'
4
+ import { MInput } from './MInput.js'
5
+ import { MChip } from './MChip.js'
6
+ import { MCheckbox } from './MCheckbox.js'
7
+ import { MSheet } from './MSheet.js'
8
+ import { MColumn, MRow } from './layout.js'
9
+
10
+ export const { MNumberInput, MMultiSelect } = createConfiguratorControls(
11
+ {
12
+ Column: MColumn,
13
+ Row: MRow,
14
+ Text: MText,
15
+ Button: MButton,
16
+ Input: MInput,
17
+ Chip: MChip,
18
+ Checkbox: MCheckbox,
19
+ Sheet: MSheet,
20
+ focusTrigger: (component) =>
21
+ (component as { $el?: HTMLElement } | undefined)?.$el?.focus({ preventScroll: true }),
22
+ },
23
+ 'web',
24
+ )
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { MNumberInput, MMultiSelect } from './components/configurator.js'
2
+ import { MImage } from './components/MImage.js'
1
3
  import { MStack } from './components/MStack.js'
2
4
  export { themeVariables, useMavisTokens } from './tokens.js'
3
5
  import { MLink } from './components/MLink.js'
@@ -81,6 +83,9 @@ export {
81
83
  MSheet,
82
84
  MDatePicker,
83
85
  MDateRangePicker,
86
+ MNumberInput,
87
+ MMultiSelect,
88
+ MImage,
84
89
  MCombobox,
85
90
  MFilePicker,
86
91
  MFormGroup,
@@ -152,6 +157,9 @@ export function createMavis(options: MavisOptions = {}) {
152
157
  MSheet,
153
158
  MDatePicker,
154
159
  MDateRangePicker,
160
+ MNumberInput,
161
+ MMultiSelect,
162
+ MImage,
155
163
  MCombobox,
156
164
  MFilePicker,
157
165
  MFormGroup,
@@ -8,6 +8,26 @@ import type {
8
8
  import type { MotionSurfaceAdapter } from '@getcortexlabs/mavis-core/experimental'
9
9
  import { webRegion } from './motion-region.js'
10
10
 
11
+ const boundPaint = new WeakMap<HTMLElement, Map<string, number>>()
12
+ const paintKeys = new Set([
13
+ 'backgroundColor',
14
+ 'borderColor',
15
+ 'color',
16
+ 'borderRadius',
17
+ 'borderWidth',
18
+ ])
19
+ /** Vue may rerender slots while an application value owns paint on this element. */
20
+ export function preserveBoundPaint(target: HTMLElement | undefined) {
21
+ return target
22
+ ? Object.fromEntries(
23
+ [...(boundPaint.get(target)?.keys() ?? [])].map((key) => [
24
+ key,
25
+ target.style[key as 'backgroundColor'],
26
+ ]),
27
+ )
28
+ : {}
29
+ }
30
+
11
31
  const targets = new WeakMap<MotionSurfaceAdapter, { runtime: WebRuntime; target: HTMLElement }>()
12
32
  export function webSurfaceTarget(adapter: MotionSurfaceAdapter) {
13
33
  const target = targets.get(adapter)
@@ -81,6 +101,10 @@ export function webMotionSurface(
81
101
  ? owner.map(value, input, output, options)
82
102
  : value.to(input, output, options)
83
103
  },
104
+ mapColor(source, input, output) {
105
+ const value = sources.get(source) ?? (source as WebReadableValue)
106
+ return 'map' in owner ? owner.map(value, input, output) : value.to(input, output)
107
+ },
84
108
  springValue(source, options) {
85
109
  // Keep the runtime's private value identity; it rejects values from other contexts.
86
110
  const spring = owner.springValue(source as ReturnType<WebRuntime['motionValue']>, options)
@@ -112,15 +136,48 @@ export function webMotionSurface(
112
136
  motionValue: (initial) => owner.motionValue(initial),
113
137
  bind(values) {
114
138
  // Spring wrappers retain their public handle, rather than registering a second clock.
115
- return owner.bind(
139
+ const binding = owner.bind(
116
140
  target,
117
141
  Object.fromEntries(
118
142
  Object.entries(values).map(([key, value]) => [key, sources.get(value) ?? value]),
119
- ) as Partial<Record<keyof typeof values, WebReadableValue>>,
143
+ ) as Parameters<WebRuntime['bind']>[1],
120
144
  )
145
+ let counts = boundPaint.get(target)
146
+ if (!counts) boundPaint.set(target, (counts = new Map()))
147
+ const keys = Object.keys(values).filter((key) => paintKeys.has(key))
148
+ for (const key of keys) counts.set(key, (counts.get(key) ?? 0) + 1)
149
+ let disposed = false
150
+ return {
151
+ dispose() {
152
+ if (disposed) return
153
+ disposed = true
154
+ try {
155
+ binding.dispose()
156
+ } finally {
157
+ for (const key of keys) {
158
+ const count = counts!.get(key)! - 1
159
+ if (count) counts!.set(key, count)
160
+ else counts!.delete(key)
161
+ }
162
+ if (!counts!.size) boundPaint.delete(target)
163
+ }
164
+ },
165
+ }
121
166
  },
122
167
  drag(options) {
123
- const drag = owner.drag(target, { ...options, disabled: !enabled() })
168
+ const drag = owner.drag(target, {
169
+ ...options,
170
+ disabled: !enabled(),
171
+ onRelease: options.onRelease
172
+ ? (event) =>
173
+ options.onRelease!({
174
+ x: event.x,
175
+ y: event.y,
176
+ velocityX: event.velocity.x,
177
+ velocityY: event.velocity.y,
178
+ })
179
+ : undefined,
180
+ })
124
181
  let paused = false
125
182
  const refresh = () => {
126
183
  const disabled = paused || !enabled()
@@ -39,10 +39,21 @@ export function useScrollMotion(
39
39
  // A ScrollTimeline can become inactive when content no longer overflows. Rebase
40
40
  // its retained pose on layout changes too, without observing values every frame.
41
41
  const resize = new view.ResizeObserver(refresh)
42
+ const observed = new Set<Element>()
42
43
  const observe = () => {
43
- resize.disconnect()
44
- resize.observe(target)
45
- for (const child of target.children) resize.observe(child)
44
+ // Keep existing observations across text/subtree mutations. Re-observing an
45
+ // unchanged ancestor during resize delivery can trigger a WebKit resize loop.
46
+ const wanted = new Set<Element>([target, ...target.children])
47
+ for (const node of observed) {
48
+ if (wanted.has(node)) continue
49
+ resize.unobserve(node)
50
+ observed.delete(node)
51
+ }
52
+ for (const node of wanted) {
53
+ if (observed.has(node)) continue
54
+ resize.observe(node)
55
+ observed.add(node)
56
+ }
46
57
  }
47
58
  const mutations = new view.MutationObserver(() => {
48
59
  observe()
@@ -55,6 +66,7 @@ export function useScrollMotion(
55
66
  release = () => {
56
67
  disposed = true
57
68
  resize.disconnect()
69
+ observed.clear()
58
70
  mutations.disconnect()
59
71
  target.ownerDocument.fonts?.removeEventListener('loadingdone', refresh)
60
72
  view.removeEventListener('resize', refresh)
package/src/style.css CHANGED
@@ -222,7 +222,6 @@ html:has(.m-sheet[open]) {
222
222
  flex-shrink: 0;
223
223
  border-radius: 999px;
224
224
  background: var(--m-switch-track);
225
- transition: background-color 160ms ease;
226
225
  }
227
226
  .m-switch-thumb {
228
227
  display: block;
@@ -236,8 +235,7 @@ html:has(.m-sheet[open]) {
236
235
  box-shadow: 0 1px 3px #0003;
237
236
  transition:
238
237
  inset-inline-start 180ms ease,
239
- transform 120ms ease,
240
- background-color 160ms ease;
238
+ transform 120ms ease;
241
239
  }
242
240
  .m-switch[aria-checked='true'] .m-switch-thumb {
243
241
  inset-inline-start: 24px;
@@ -283,6 +281,8 @@ html:has(.m-sheet[open]) {
283
281
  outline-offset: 2px;
284
282
  }
285
283
  .m-checkbox-box {
284
+ position: relative;
285
+ --m-choice-border: 2px;
286
286
  display: flex;
287
287
  align-items: center;
288
288
  justify-content: center;
@@ -292,10 +292,7 @@ html:has(.m-sheet[open]) {
292
292
  flex-shrink: 0;
293
293
  border: 2px solid var(--m-checkbox-border);
294
294
  border-radius: 7px;
295
- transition:
296
- transform 120ms ease,
297
- background-color 140ms ease,
298
- border-color 140ms ease;
295
+ transition: transform 120ms ease;
299
296
  }
300
297
  .m-checkbox-mark {
301
298
  display: none;
@@ -383,6 +380,8 @@ html:has(.m-sheet[open]) {
383
380
  outline-offset: 2px;
384
381
  }
385
382
  .m-radio-indicator {
383
+ position: relative;
384
+ --m-choice-border: 2px;
386
385
  width: 24px;
387
386
  height: 24px;
388
387
  flex-shrink: 0;
@@ -392,9 +391,7 @@ html:has(.m-sheet[open]) {
392
391
  display: flex;
393
392
  align-items: center;
394
393
  justify-content: center;
395
- transition:
396
- transform 120ms ease,
397
- border-color 140ms ease;
394
+ transition: transform 120ms ease;
398
395
  }
399
396
  .m-radio-dot {
400
397
  width: 12px;