@getcortexlabs/mavis-core 0.1.0-rc.11.1 → 0.1.0-rc.12.1

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 (167) hide show
  1. package/README.md +2 -2
  2. package/dist/advanced-collections.d.ts +74 -0
  3. package/dist/advanced-collections.d.ts.map +1 -0
  4. package/dist/advanced-collections.js +129 -0
  5. package/dist/advanced-collections.js.map +1 -0
  6. package/dist/capabilities.d.ts +7 -7
  7. package/dist/capabilities.d.ts.map +1 -1
  8. package/dist/capabilities.js +29 -4
  9. package/dist/capabilities.js.map +1 -1
  10. package/dist/creative-controls.d.ts +47 -0
  11. package/dist/creative-controls.d.ts.map +1 -0
  12. package/dist/creative-controls.js +112 -0
  13. package/dist/creative-controls.js.map +1 -0
  14. package/dist/dashboard.d.ts +72 -0
  15. package/dist/dashboard.d.ts.map +1 -0
  16. package/dist/dashboard.js +115 -0
  17. package/dist/dashboard.js.map +1 -0
  18. package/dist/image-crop.d.ts +49 -0
  19. package/dist/image-crop.d.ts.map +1 -0
  20. package/dist/image-crop.js +71 -0
  21. package/dist/image-crop.js.map +1 -0
  22. package/dist/index.d.ts +6 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +6 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/scheduler.d.ts +45 -0
  27. package/dist/scheduler.d.ts.map +1 -0
  28. package/dist/scheduler.js +142 -0
  29. package/dist/scheduler.js.map +1 -0
  30. package/dist/screen-components.d.ts +45 -0
  31. package/dist/screen-components.d.ts.map +1 -0
  32. package/dist/screen-components.js +23 -0
  33. package/dist/screen-components.js.map +1 -0
  34. package/dist/vue/advanced-collections.d.ts +486 -0
  35. package/dist/vue/advanced-collections.d.ts.map +1 -0
  36. package/dist/vue/advanced-collections.js +476 -0
  37. package/dist/vue/advanced-collections.js.map +1 -0
  38. package/dist/vue/advanced-props.d.ts +398 -0
  39. package/dist/vue/advanced-props.d.ts.map +1 -0
  40. package/dist/vue/advanced-props.js +128 -0
  41. package/dist/vue/advanced-props.js.map +1 -0
  42. package/dist/vue/animated-text.d.ts +101 -0
  43. package/dist/vue/animated-text.d.ts.map +1 -0
  44. package/dist/vue/animated-text.js +56 -0
  45. package/dist/vue/animated-text.js.map +1 -0
  46. package/dist/vue/chart.d.ts +1 -1
  47. package/dist/vue/command-palette.d.ts +3 -3
  48. package/dist/vue/component-props.d.ts +1045 -0
  49. package/dist/vue/component-props.d.ts.map +1 -1
  50. package/dist/vue/component-props.js +29 -0
  51. package/dist/vue/component-props.js.map +1 -1
  52. package/dist/vue/composer.d.ts +159 -0
  53. package/dist/vue/composer.d.ts.map +1 -0
  54. package/dist/vue/composer.js +142 -0
  55. package/dist/vue/composer.js.map +1 -0
  56. package/dist/vue/configurator.d.ts +5 -5
  57. package/dist/vue/creative-controls.d.ts +328 -0
  58. package/dist/vue/creative-controls.d.ts.map +1 -0
  59. package/dist/vue/creative-controls.js +396 -0
  60. package/dist/vue/creative-controls.js.map +1 -0
  61. package/dist/vue/creative-props.d.ts +260 -0
  62. package/dist/vue/creative-props.d.ts.map +1 -0
  63. package/dist/vue/creative-props.js +92 -0
  64. package/dist/vue/creative-props.js.map +1 -0
  65. package/dist/vue/dashboard-charts.d.ts +240 -0
  66. package/dist/vue/dashboard-charts.d.ts.map +1 -0
  67. package/dist/vue/dashboard-charts.js +263 -0
  68. package/dist/vue/dashboard-charts.js.map +1 -0
  69. package/dist/vue/dashboard-effects.d.ts +211 -0
  70. package/dist/vue/dashboard-effects.d.ts.map +1 -0
  71. package/dist/vue/dashboard-effects.js +235 -0
  72. package/dist/vue/dashboard-effects.js.map +1 -0
  73. package/dist/vue/dashboard-props.d.ts +244 -0
  74. package/dist/vue/dashboard-props.d.ts.map +1 -0
  75. package/dist/vue/dashboard-props.js +94 -0
  76. package/dist/vue/dashboard-props.js.map +1 -0
  77. package/dist/vue/date-picker.d.ts +8 -8
  78. package/dist/vue/discovery-controls.d.ts +2 -2
  79. package/dist/vue/global-components.d.ts +152 -0
  80. package/dist/vue/global-components.d.ts.map +1 -1
  81. package/dist/vue/image-cropper.d.ts +187 -0
  82. package/dist/vue/image-cropper.d.ts.map +1 -0
  83. package/dist/vue/image-cropper.js +310 -0
  84. package/dist/vue/image-cropper.js.map +1 -0
  85. package/dist/vue/index.d.ts +20 -0
  86. package/dist/vue/index.d.ts.map +1 -1
  87. package/dist/vue/index.js +20 -0
  88. package/dist/vue/index.js.map +1 -1
  89. package/dist/vue/kanban.d.ts +150 -0
  90. package/dist/vue/kanban.d.ts.map +1 -0
  91. package/dist/vue/kanban.js +267 -0
  92. package/dist/vue/kanban.js.map +1 -0
  93. package/dist/vue/marquee.d.ts +96 -0
  94. package/dist/vue/marquee.d.ts.map +1 -0
  95. package/dist/vue/marquee.js +186 -0
  96. package/dist/vue/marquee.js.map +1 -0
  97. package/dist/vue/menu.d.ts +2 -2
  98. package/dist/vue/navigation-controls.d.ts +1 -1
  99. package/dist/vue/pin-cell.d.ts +14 -0
  100. package/dist/vue/pin-cell.d.ts.map +1 -0
  101. package/dist/vue/pin-cell.js +19 -0
  102. package/dist/vue/pin-cell.js.map +1 -0
  103. package/dist/vue/pin-input.d.ts +14 -0
  104. package/dist/vue/pin-input.d.ts.map +1 -0
  105. package/dist/vue/pin-input.js +23 -0
  106. package/dist/vue/pin-input.js.map +1 -0
  107. package/dist/vue/scheduler.d.ts +229 -0
  108. package/dist/vue/scheduler.d.ts.map +1 -0
  109. package/dist/vue/scheduler.js +363 -0
  110. package/dist/vue/scheduler.js.map +1 -0
  111. package/dist/vue/screen-component-props.d.ts +236 -0
  112. package/dist/vue/screen-component-props.d.ts.map +1 -0
  113. package/dist/vue/screen-component-props.js +90 -0
  114. package/dist/vue/screen-component-props.js.map +1 -0
  115. package/dist/vue/scroll-frame.d.ts +223 -0
  116. package/dist/vue/scroll-frame.d.ts.map +1 -0
  117. package/dist/vue/scroll-frame.js +346 -0
  118. package/dist/vue/scroll-frame.js.map +1 -0
  119. package/dist/vue/speed-dial.d.ts +73 -0
  120. package/dist/vue/speed-dial.d.ts.map +1 -0
  121. package/dist/vue/speed-dial.js +78 -0
  122. package/dist/vue/speed-dial.js.map +1 -0
  123. package/dist/vue/swipe-actions.d.ts +1 -1
  124. package/dist/vue/swipe-deck.d.ts +120 -0
  125. package/dist/vue/swipe-deck.d.ts.map +1 -0
  126. package/dist/vue/swipe-deck.js +229 -0
  127. package/dist/vue/swipe-deck.js.map +1 -0
  128. package/dist/vue/time-picker.d.ts +6 -6
  129. package/dist/vue/tour.d.ts +120 -0
  130. package/dist/vue/tour.d.ts.map +1 -0
  131. package/dist/vue/tour.js +165 -0
  132. package/dist/vue/tour.js.map +1 -0
  133. package/dist/vue/tree-view.d.ts +1 -1
  134. package/dist/vue/wayfinding-controls.d.ts +2 -2
  135. package/dist/vue/workflows.d.ts +3 -3
  136. package/package.json +1 -1
  137. package/src/advanced-collections.ts +199 -0
  138. package/src/capabilities.ts +30 -4
  139. package/src/creative-controls.ts +169 -0
  140. package/src/dashboard.ts +164 -0
  141. package/src/image-crop.ts +125 -0
  142. package/src/index.ts +11 -0
  143. package/src/scheduler.ts +194 -0
  144. package/src/screen-components.ts +59 -0
  145. package/src/vue/advanced-collections.ts +679 -0
  146. package/src/vue/advanced-props.ts +144 -0
  147. package/src/vue/animated-text.ts +72 -0
  148. package/src/vue/component-props.ts +61 -0
  149. package/src/vue/composer.ts +192 -0
  150. package/src/vue/creative-controls.ts +524 -0
  151. package/src/vue/creative-props.ts +94 -0
  152. package/src/vue/dashboard-charts.ts +346 -0
  153. package/src/vue/dashboard-effects.ts +304 -0
  154. package/src/vue/dashboard-props.ts +95 -0
  155. package/src/vue/global-components.ts +162 -0
  156. package/src/vue/image-cropper.ts +413 -0
  157. package/src/vue/index.ts +28 -0
  158. package/src/vue/kanban.ts +360 -0
  159. package/src/vue/marquee.ts +248 -0
  160. package/src/vue/pin-cell.ts +26 -0
  161. package/src/vue/pin-input.ts +31 -0
  162. package/src/vue/scheduler.ts +505 -0
  163. package/src/vue/screen-component-props.ts +92 -0
  164. package/src/vue/scroll-frame.ts +429 -0
  165. package/src/vue/speed-dial.ts +108 -0
  166. package/src/vue/swipe-deck.ts +277 -0
  167. package/src/vue/tour.ts +239 -0
@@ -0,0 +1,165 @@
1
+ import { computed, defineComponent, h, inject, mergeProps, nextTick, onMounted, onScopeDispose, provide, reactive, ref, watch, } from '@vue/runtime-core';
2
+ import { validateTour } from '../creative-controls.js';
3
+ import { tourProps, tourTargetProps } from './creative-props.js';
4
+ import { useComponentState } from './component-motion.js';
5
+ import { useMavisTheme } from './theme.js';
6
+ const tourKey = Symbol('mavis-tour');
7
+ export const tourHostProps = { active: Boolean, restoreFocus: { type: Boolean, default: true } };
8
+ export function createTour(ui, platform) {
9
+ const MTour = defineComponent({
10
+ name: 'MTour',
11
+ inheritAttrs: false,
12
+ props: tourProps,
13
+ emits: {
14
+ 'update:modelValue': (_id) => true,
15
+ finish: (_reason) => true,
16
+ missing: (_id) => true,
17
+ },
18
+ setup(props, { attrs, slots, emit }) {
19
+ const targets = reactive(new Set());
20
+ const index = computed(() => validateTour(props.steps).findIndex((step) => step.id === props.modelValue));
21
+ const step = computed(() => props.steps[index.value]);
22
+ let mounted = false, generation = 0;
23
+ const closeReason = ref('');
24
+ watch(() => props.modelValue, (value) => {
25
+ if (value !== null)
26
+ closeReason.value = '';
27
+ });
28
+ function close(reason) {
29
+ if (props.modelValue === null)
30
+ return;
31
+ closeReason.value = reason;
32
+ emit('update:modelValue', null);
33
+ emit('finish', reason);
34
+ }
35
+ function move(direction) {
36
+ for (let i = index.value + direction; i >= 0 && i < props.steps.length; i += direction) {
37
+ const next = props.steps[i];
38
+ if (targets.has(next.id)) {
39
+ emit('update:modelValue', next.id);
40
+ return;
41
+ }
42
+ emit('missing', next.id);
43
+ }
44
+ close(direction > 0 ? 'complete' : 'missing');
45
+ }
46
+ async function check() {
47
+ const token = ++generation;
48
+ await nextTick();
49
+ if (!mounted || token !== generation || props.modelValue === null)
50
+ return;
51
+ if (!step.value || !targets.has(step.value.id)) {
52
+ emit('missing', props.modelValue);
53
+ move(1);
54
+ }
55
+ }
56
+ provide(tourKey, {
57
+ current: () => step.value,
58
+ animated: () => props.animated,
59
+ register(id) {
60
+ if (!id.trim() || targets.has(id))
61
+ throw new TypeError('Tour target names must be nonempty and unique within a tour.');
62
+ targets.add(id);
63
+ return () => targets.delete(id);
64
+ },
65
+ close,
66
+ panel: () => h(ui.Column, { gap: 'md' }, {
67
+ default: () => [
68
+ h(ui.Text, {
69
+ text: `${props.label} · ${index.value + 1} / ${props.steps.length}`,
70
+ variant: 'caption',
71
+ tone: 'muted',
72
+ }),
73
+ h(ui.Text, { text: step.value?.title, variant: 'heading' }),
74
+ h(ui.Text, { text: step.value?.description }),
75
+ h(ui.Row, { gap: 'xs', wrap: true }, {
76
+ default: () => [
77
+ h(ui.Button, {
78
+ text: props.backLabel,
79
+ variant: 'secondary',
80
+ disabled: index.value <= 0,
81
+ onClick: () => move(-1),
82
+ }),
83
+ h(ui.Button, {
84
+ text: index.value === props.steps.length - 1
85
+ ? props.finishLabel
86
+ : props.nextLabel,
87
+ onClick: () => move(1),
88
+ }),
89
+ h(ui.Button, {
90
+ text: props.skipLabel,
91
+ variant: 'ghost',
92
+ onClick: () => close('skip'),
93
+ }),
94
+ ],
95
+ }),
96
+ ],
97
+ }),
98
+ });
99
+ watch(() => [props.modelValue, props.steps, [...targets]], check, {
100
+ flush: 'post',
101
+ deep: true,
102
+ });
103
+ onMounted(() => {
104
+ mounted = true;
105
+ void check();
106
+ });
107
+ onScopeDispose(() => {
108
+ mounted = false;
109
+ generation++;
110
+ });
111
+ return () => h(ui.Host, mergeProps(attrs, {
112
+ id: props.id,
113
+ active: props.modelValue !== null,
114
+ restoreFocus: closeReason.value !== 'outside',
115
+ ...(platform === 'web' ? { class: 'm-tour' } : {}),
116
+ }), slots);
117
+ },
118
+ });
119
+ const MTourTarget = defineComponent({
120
+ name: 'MTourTarget',
121
+ inheritAttrs: false,
122
+ props: tourTargetProps,
123
+ setup(props, { attrs, slots }) {
124
+ const context = inject(tourKey);
125
+ if (!context)
126
+ throw new Error('MTourTarget must be inside MTour.');
127
+ const { theme } = useMavisTheme();
128
+ const active = computed(() => context.current()?.id === props.name);
129
+ const surface = useComponentState(() => ({ opacity: active.value ? 1 : 0.55 }), 'selection');
130
+ let release = () => { };
131
+ watch(() => props.name, (name) => {
132
+ release();
133
+ release = context.register(name);
134
+ }, { immediate: true });
135
+ onScopeDispose(() => release());
136
+ return () => h(ui.TargetHost, mergeProps(attrs, {
137
+ active: active.value,
138
+ ...(platform === 'web'
139
+ ? { class: 'm-tour-target', 'data-tour-target': props.name }
140
+ : {}),
141
+ }), {
142
+ default: () => h(ui.Popover, {
143
+ open: active.value,
144
+ label: context.current()?.title ?? props.name,
145
+ triggerLabel: props.name,
146
+ width: 320,
147
+ onClose: (reason) => {
148
+ if (active.value)
149
+ context.close(reason);
150
+ },
151
+ }, {
152
+ anchor: () => h(ui.Box, {
153
+ padding: 'xs',
154
+ radius: 'md',
155
+ borderWidth: 2,
156
+ borderColor: active.value ? theme.value.colors.primary : 'transparent',
157
+ }, { default: () => slots.default?.({ active: active.value }) }),
158
+ default: () => h(ui.Column, { motionSurface: context.animated() ? surface : undefined, gap: 'sm' }, { default: () => context.panel() }),
159
+ }),
160
+ });
161
+ },
162
+ });
163
+ return { MTour, MTourTarget };
164
+ }
165
+ //# sourceMappingURL=tour.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tour.js","sourceRoot":"","sources":["../../src/vue/tour.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,eAAe,EACf,CAAC,EACD,MAAM,EACN,UAAU,EACV,QAAQ,EACR,SAAS,EACT,cAAc,EACd,OAAO,EACP,QAAQ,EACR,GAAG,EACH,KAAK,GAGN,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,YAAY,EAAiB,MAAM,yBAAyB,CAAA;AACrE,OAAO,EAAE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AAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa;qBACvE,EACD,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,CAC7D;oBACH,OAAO,EAAE,GAAG,EAAE,CACZ,CAAC,CACC,EAAE,CAAC,MAAM,EACT,EAAE,aAAa,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,EACtE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CACnC;iBACJ,CACF;aACJ,CACF,CAAA;QACL,CAAC;KACF,CAAC,CAAA;IACF,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAA;AAC/B,CAAC"}
@@ -95,8 +95,8 @@ export declare function createTreeView(ui: {
95
95
  default: string;
96
96
  };
97
97
  }>> & Readonly<{
98
- "onUpdate:modelValue"?: ((_key: ChoiceValue) => any) | undefined;
99
98
  onLoad?: ((_node: TreeNode) => any) | undefined;
99
+ "onUpdate:modelValue"?: ((_key: ChoiceValue) => any) | undefined;
100
100
  "onUpdate:expanded"?: ((_keys: ChoiceValue[]) => any) | undefined;
101
101
  }>, {
102
102
  expandedLabel: string;
@@ -89,9 +89,9 @@ export declare function createWayfindingControls(ui: Primitives, platform: 'web'
89
89
  }>, {
90
90
  disabled: boolean;
91
91
  modelValue: import("../choice.js").ChoiceValue | null;
92
- collapsible: boolean;
93
- collapseLabel: string;
94
92
  expandLabel: string;
93
+ collapseLabel: string;
94
+ collapsible: boolean;
95
95
  collapsed: boolean;
96
96
  currentLabel: string;
97
97
  }, {}, {}, {}, string, import("@vue/runtime-core").ComponentProvideOptions, true, {}, any>;
@@ -132,8 +132,8 @@ export declare function createWorkflows(ui: Primitives, platform: 'web' | 'nativ
132
132
  }>> & Readonly<{
133
133
  "onUpdate:modelValue"?: ((_value: ChoiceValue) => any) | undefined;
134
134
  }>, {
135
- loading: boolean;
136
135
  disabled: boolean;
136
+ loading: boolean;
137
137
  modelValue: ChoiceValue | null;
138
138
  errorLabel: string;
139
139
  currentLabel: string;
@@ -249,12 +249,12 @@ export declare function createWorkflows(ui: Primitives, platform: 'web' | 'nativ
249
249
  "onUpdate:modelValue"?: ((_page: number) => any) | undefined;
250
250
  }>, {
251
251
  label: string;
252
- loading: boolean;
253
252
  disabled: boolean;
253
+ loading: boolean;
254
254
  modelValue: number;
255
+ emptyLabel: string;
255
256
  previousLabel: string;
256
257
  nextLabel: string;
257
- emptyLabel: string;
258
258
  currentLabel: string;
259
259
  pageSize: number;
260
260
  siblingCount: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getcortexlabs/mavis-core",
3
- "version": "0.1.0-rc.11.1",
3
+ "version": "0.1.0-rc.12.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Shared Mavis themes and component contracts.",
@@ -0,0 +1,199 @@
1
+ import { addCivilDays, civilDate, civilWeekday, type CivilDate } from './date.js'
2
+
3
+ export interface TreeSelectNode {
4
+ id: string
5
+ label: string
6
+ disabled?: boolean
7
+ selectable?: boolean
8
+ children?: readonly TreeSelectNode[]
9
+ }
10
+ export interface TreeSelectRow {
11
+ node: TreeSelectNode
12
+ depth: number
13
+ ancestors: readonly string[]
14
+ disabled: boolean
15
+ }
16
+ export function treeSelectRows(nodes: readonly TreeSelectNode[]): TreeSelectRow[] {
17
+ const ids = new Set<string>(),
18
+ rows: TreeSelectRow[] = []
19
+ function visit(items: readonly TreeSelectNode[], ancestors: string[], disabled = false) {
20
+ if (ancestors.length > 32) throw new RangeError('TreeSelect supports at most 32 levels.')
21
+ for (const node of items) {
22
+ if (!node.id || ids.has(node.id) || !node.label.trim())
23
+ throw new TypeError(
24
+ 'TreeSelect requires unique nonempty IDs and labels; cycles are invalid.',
25
+ )
26
+ ids.add(node.id)
27
+ if (ids.size > 2000) throw new RangeError('TreeSelect supports at most 2000 nodes.')
28
+ const unavailable = disabled || !!node.disabled
29
+ rows.push({ node, depth: ancestors.length, ancestors, disabled: unavailable })
30
+ visit(node.children ?? [], [...ancestors, node.id], unavailable)
31
+ }
32
+ }
33
+ visit(nodes, [])
34
+ return rows
35
+ }
36
+ export function visibleTreeSelection(
37
+ rows: readonly TreeSelectRow[],
38
+ expanded: readonly string[],
39
+ query: string,
40
+ ) {
41
+ const text = query.trim().toLocaleLowerCase()
42
+ if (!text) return rows.filter((row) => row.ancestors.every((id) => expanded.includes(id)))
43
+ const visible = new Set<string>()
44
+ for (const row of rows)
45
+ if (row.node.label.toLocaleLowerCase().includes(text)) {
46
+ visible.add(row.node.id)
47
+ row.ancestors.forEach((id) => visible.add(id))
48
+ }
49
+ return rows.filter((row) => visible.has(row.node.id))
50
+ }
51
+ export function toggleTreeSelection(
52
+ nodes: readonly TreeSelectNode[],
53
+ values: readonly string[],
54
+ id: string,
55
+ multiple: boolean,
56
+ ) {
57
+ const row = treeSelectRows(nodes).find((row) => row.node.id === id)
58
+ if (!row || row.disabled || row.node.selectable === false) return [...values]
59
+ if (!multiple) return [id]
60
+ return values.includes(id)
61
+ ? values.filter((value) => value !== id)
62
+ : [...new Set([...values, id])]
63
+ }
64
+ export interface MasonryItem {
65
+ id: string
66
+ estimatedHeight?: number
67
+ }
68
+ export interface MasonryPlacement {
69
+ id: string
70
+ x: number
71
+ y: number
72
+ width: number
73
+ height: number
74
+ column: number
75
+ }
76
+ export function masonryLayout(
77
+ items: readonly MasonryItem[],
78
+ width: number,
79
+ minWidth: number,
80
+ gap: number,
81
+ maxColumns: number,
82
+ heights: ReadonlyMap<string, number> = new Map(),
83
+ ) {
84
+ if (
85
+ ![width, minWidth, gap, maxColumns].every(Number.isFinite) ||
86
+ width < 0 ||
87
+ minWidth < 40 ||
88
+ gap < 0 ||
89
+ !Number.isInteger(maxColumns) ||
90
+ maxColumns < 1 ||
91
+ maxColumns > 12
92
+ )
93
+ throw new RangeError('Masonry needs a nonnegative width/gap, minWidth >= 40 and 1–12 columns.')
94
+ uniqueAdvanced(items, 'Masonry', 500)
95
+ const columns = Math.max(1, Math.min(maxColumns, Math.floor((width + gap) / (minWidth + gap))))
96
+ const itemWidth = Math.max(0, (width - gap * (columns - 1)) / columns),
97
+ bottoms = Array<number>(columns).fill(0)
98
+ const placements = items.map((item) => {
99
+ const height = heights.get(item.id) ?? item.estimatedHeight ?? 180
100
+ if (!Number.isFinite(height) || height < 0)
101
+ throw new RangeError('Masonry heights must be finite and nonnegative.')
102
+ const column = bottoms.indexOf(Math.min(...bottoms)),
103
+ y = bottoms[column]!
104
+ bottoms[column] = y + height + gap
105
+ return { id: item.id, x: column * (itemWidth + gap), y, width: itemWidth, height, column }
106
+ })
107
+ return { columns, placements, height: Math.max(0, ...bottoms) - (items.length ? gap : 0) }
108
+ }
109
+ export interface HeatmapValue {
110
+ date: CivilDate
111
+ value: number | null
112
+ label?: string
113
+ disabled?: boolean
114
+ }
115
+ export function heatmapCalendar(
116
+ start: CivilDate,
117
+ end: CivilDate,
118
+ values: readonly HeatmapValue[],
119
+ weekStartsOn: 0 | 1 = 1,
120
+ ) {
121
+ if (![0, 1].includes(weekStartsOn)) throw new RangeError('Heatmap weekStartsOn must be 0 or 1.')
122
+ civilDate(start)
123
+ civilDate(end)
124
+ if (end < start || end > addCivilDays(start, 365))
125
+ throw new RangeError('Heatmap range must contain 1–366 days.')
126
+ const map = new Map<CivilDate, HeatmapValue>()
127
+ for (const item of values) {
128
+ civilDate(item.date)
129
+ if (
130
+ map.has(item.date) ||
131
+ (item.value !== null && (!Number.isFinite(item.value) || item.value < 0))
132
+ )
133
+ throw new TypeError('Heatmap dates must be unique and values nonnegative, finite or null.')
134
+ map.set(item.date, item)
135
+ }
136
+ const leading = (civilWeekday(start) - weekStartsOn + 7) % 7
137
+ const cells: (HeatmapValue & { index: number; row: number; column: number; missing: boolean })[] =
138
+ []
139
+ for (let day = start, i = 0; ; i++, day = addCivilDays(day, 1)) {
140
+ const entry = map.get(day),
141
+ index = leading + i
142
+ cells.push({
143
+ date: day,
144
+ value: entry?.value ?? null,
145
+ label: entry?.label,
146
+ disabled: entry?.disabled,
147
+ index,
148
+ row: index % 7,
149
+ column: Math.floor(index / 7),
150
+ missing: entry?.value == null,
151
+ })
152
+ if (day === end) break
153
+ }
154
+ const max = Math.max(0, ...cells.map((c) => c.value ?? 0))
155
+ return { cells, columns: cells[cells.length - 1]!.column + 1, max }
156
+ }
157
+ export function heatmapColor(value: number | null, max: number, colors: readonly string[]) {
158
+ if (
159
+ colors.length < 2 ||
160
+ colors.length > 8 ||
161
+ colors.some((color) => !/^#[\da-f]{6}$/i.test(color))
162
+ )
163
+ throw new TypeError('Heatmap colors require 2–8 six-digit HEX values.')
164
+ if (value === null) return 'transparent'
165
+ return colors[
166
+ Math.min(colors.length - 1, Math.floor((max ? value / max : 0) * (colors.length - 1)))
167
+ ]!
168
+ }
169
+ export interface MavisNotification {
170
+ id: string
171
+ title: string
172
+ description?: string
173
+ group?: string
174
+ time?: string
175
+ read?: boolean
176
+ disabled?: boolean
177
+ dismissible?: boolean
178
+ actionLabel?: string
179
+ }
180
+ export function uniqueAdvanced(items: readonly { id: string }[], label: string, limit = 500) {
181
+ const ids = new Set<string>()
182
+ if (items.length > limit) throw new RangeError(`${label} supports at most ${limit} items.`)
183
+ for (const item of items) {
184
+ if (!item.id || ids.has(item.id)) throw new TypeError(`${label} requires unique nonempty IDs.`)
185
+ ids.add(item.id)
186
+ }
187
+ }
188
+ export function updateNotifications<T extends MavisNotification>(
189
+ items: readonly T[],
190
+ ids: readonly string[],
191
+ action: 'read' | 'unread' | 'dismiss',
192
+ ) {
193
+ uniqueAdvanced(items, 'NotificationCenter', 1000)
194
+ return items.flatMap((item) => {
195
+ if (!ids.includes(item.id) || item.disabled) return [item]
196
+ if (action === 'dismiss') return item.dismissible === false ? [item] : []
197
+ return [{ ...item, read: action === 'read' }]
198
+ })
199
+ }
@@ -1,5 +1,31 @@
1
1
  /** Source capabilities, not a promise that every feature is in the last npm release. */
2
2
  export const componentNames = [
3
+ 'MTreeSelect',
4
+ 'MMasonry',
5
+ 'MHeatmap',
6
+ 'MImageCropper',
7
+ 'MScheduler',
8
+ 'MNotificationCenter',
9
+ 'MKanban',
10
+ 'MDonutChart',
11
+ 'MSparkline',
12
+ 'MGradientBackground',
13
+ 'MParticleField',
14
+ 'MConfetti',
15
+ 'MColorPicker',
16
+ 'MSwipeDeck',
17
+ 'MGauge',
18
+ 'MTour',
19
+ 'MTourTarget',
20
+ 'MTransferList',
21
+ 'MMarquee',
22
+ 'MCollapsibleHeader',
23
+ 'MRefreshControl',
24
+ 'MComposer',
25
+ 'MSpeedDial',
26
+ 'MPinInput',
27
+ 'MAnimatedText',
28
+
3
29
  'MSortableList',
4
30
  'MSwipeActions',
5
31
  'MNumberFlow',
@@ -79,11 +105,11 @@ export type CapabilityStatus = 'experimental' | 'planned' | 'unsupported' | 'unv
79
105
  export const targetCapabilities = {
80
106
  version: 1,
81
107
  source: 'repository',
82
- publishedBaseline: '0.1.0-rc.11.1',
108
+ publishedBaseline: '0.1.0-rc.12.1',
83
109
  developmentMotion: {
84
110
  availability: 'published',
85
111
  joltCommit: null,
86
- publishedJoltRelease: '0.1.0-rc.11',
112
+ publishedJoltRelease: '0.1.0-rc.12.1',
87
113
  features: {
88
114
  gradient: ['web', 'ios', 'android'],
89
115
  loadingEffects: ['web', 'ios'],
@@ -109,7 +135,7 @@ export const targetCapabilities = {
109
135
  streaming: 'unverified',
110
136
  rsc: 'unsupported',
111
137
  },
112
- motion: { engine: 'jolt', minimum: '0.1.0-rc.11', start: 'client-mount' },
138
+ motion: { engine: 'jolt', minimum: '0.1.0-rc.12.1', start: 'client-mount' },
113
139
  ssr: {
114
140
  availability: '0.1.0-alpha.5',
115
141
  host: 'nuxt',
@@ -152,7 +178,7 @@ export const targetCapabilities = {
152
178
  streaming: 'unsupported',
153
179
  rsc: 'unsupported',
154
180
  },
155
- motion: { engine: 'jolt', minimum: '0.1.0-rc.11', start: 'native-loaded' },
181
+ motion: { engine: 'jolt', minimum: '0.1.0-rc.12.1', start: 'native-loaded' },
156
182
  },
157
183
  ],
158
184
  planned: [
@@ -0,0 +1,169 @@
1
+ import { validateChoices, type ChoiceOption, type ChoiceValue } from './choice.js'
2
+
3
+ export interface RgbaColor {
4
+ r: number
5
+ g: number
6
+ b: number
7
+ a: number
8
+ }
9
+ export interface HsvColor {
10
+ h: number
11
+ s: number
12
+ v: number
13
+ a: number
14
+ }
15
+ export function bounded(value: number, min: number, max: number) {
16
+ if (![value, min, max].every(Number.isFinite) || max <= min)
17
+ throw new RangeError('Values must be finite and max must exceed min.')
18
+ return Math.min(max, Math.max(min, value))
19
+ }
20
+ /** Deliberately accepts only HEX and numeric RGB(A), never arbitrary CSS. */
21
+ export function parseColor(input: string): RgbaColor | null {
22
+ const hex = /^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i.exec(input.trim())
23
+ if (hex) {
24
+ let value = hex[1]!
25
+ if (value.length <= 4) value = [...value].map((c) => c + c).join('')
26
+ return {
27
+ r: parseInt(value.slice(0, 2), 16),
28
+ g: parseInt(value.slice(2, 4), 16),
29
+ b: parseInt(value.slice(4, 6), 16),
30
+ a: value.length === 8 ? parseInt(value.slice(6), 16) / 255 : 1,
31
+ }
32
+ }
33
+ const rgb =
34
+ /^rgba?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)(?:\s*,\s*(\d*\.?\d+))?\s*\)$/i.exec(
35
+ input.trim(),
36
+ )
37
+ if (!rgb) return null
38
+ const [r, g, b, a] = [
39
+ Number(rgb[1]),
40
+ Number(rgb[2]),
41
+ Number(rgb[3]),
42
+ rgb[4] === undefined ? 1 : Number(rgb[4]),
43
+ ]
44
+ if ([r!, g!, b!].some((v) => v > 255) || a! > 1) return null
45
+ return { r: Math.round(r!), g: Math.round(g!), b: Math.round(b!), a: a! }
46
+ }
47
+ export function colorHex(color: RgbaColor, alpha = false) {
48
+ return (
49
+ '#' +
50
+ [color.r, color.g, color.b, ...(alpha ? [color.a * 255] : [])]
51
+ .map((v) =>
52
+ Math.round(bounded(v, 0, 255))
53
+ .toString(16)
54
+ .padStart(2, '0'),
55
+ )
56
+ .join('')
57
+ .toUpperCase()
58
+ )
59
+ }
60
+ export function colorHsv(color: RgbaColor): HsvColor {
61
+ const [r, g, b] = [color.r / 255, color.g / 255, color.b / 255]
62
+ const max = Math.max(r!, g!, b!),
63
+ min = Math.min(r!, g!, b!),
64
+ delta = max - min
65
+ const h = !delta
66
+ ? 0
67
+ : max === r
68
+ ? ((g! - b!) / delta) % 6
69
+ : max === g
70
+ ? (b! - r!) / delta + 2
71
+ : (r! - g!) / delta + 4
72
+ return { h: (h * 60 + 360) % 360, s: max ? (delta / max) * 100 : 0, v: max * 100, a: color.a }
73
+ }
74
+ export function hsvColor(color: HsvColor): RgbaColor {
75
+ const h = bounded(color.h, 0, 360) / 60,
76
+ s = bounded(color.s, 0, 100) / 100,
77
+ v = bounded(color.v, 0, 100) / 100
78
+ const c = v * s,
79
+ x = c * (1 - Math.abs((h % 2) - 1)),
80
+ m = v - c
81
+ const [r, g, b] =
82
+ h < 1
83
+ ? [c, x, 0]
84
+ : h < 2
85
+ ? [x, c, 0]
86
+ : h < 3
87
+ ? [0, c, x]
88
+ : h < 4
89
+ ? [0, x, c]
90
+ : h < 5
91
+ ? [x, 0, c]
92
+ : [c, 0, x]
93
+ return {
94
+ r: Math.round((r! + m) * 255),
95
+ g: Math.round((g! + m) * 255),
96
+ b: Math.round((b! + m) * 255),
97
+ a: bounded(color.a, 0, 1),
98
+ }
99
+ }
100
+ export interface SwipeCard {
101
+ id: ChoiceValue
102
+ title: string
103
+ description?: string
104
+ image?: string
105
+ }
106
+ export type SwipeDecision = 'accept' | 'reject'
107
+ export function deckDecision(
108
+ distance: number,
109
+ velocity: number,
110
+ threshold: number,
111
+ ): SwipeDecision | null {
112
+ if (![distance, velocity, threshold].every(Number.isFinite) || threshold <= 0)
113
+ throw new RangeError('Invalid swipe geometry.')
114
+ return Math.abs(distance) >= threshold || (Math.abs(distance) > 12 && Math.abs(velocity) > 600)
115
+ ? distance + velocity * 0.08 >= 0
116
+ ? 'accept'
117
+ : 'reject'
118
+ : null
119
+ }
120
+ export function validateCards(items: readonly SwipeCard[]) {
121
+ validateChoices(
122
+ items.map((item) => ({ value: item.id, label: item.title })),
123
+ null,
124
+ )
125
+ return items
126
+ }
127
+ export interface TourStep {
128
+ id: string
129
+ title: string
130
+ description: string
131
+ }
132
+ export function validateTour(steps: readonly TourStep[]) {
133
+ validateChoices(
134
+ steps.map((step) => ({ value: step.id, label: step.title })),
135
+ null,
136
+ )
137
+ if (steps.some((step) => !step.id.trim()))
138
+ throw new TypeError('Tour targets require nonempty ids.')
139
+ return steps
140
+ }
141
+ export interface MarqueeItem {
142
+ id: ChoiceValue
143
+ label: string
144
+ image?: string
145
+ }
146
+ export function transferValues(
147
+ options: readonly ChoiceOption[],
148
+ selected: readonly ChoiceValue[],
149
+ checked: readonly ChoiceValue[],
150
+ direction: 'add' | 'remove',
151
+ ) {
152
+ validateChoices(options, null)
153
+ const enabled = new Set(
154
+ options.filter((option) => !option.disabled).map((option) => option.value),
155
+ )
156
+ const changes = new Set(checked.filter((value) => enabled.has(value)))
157
+ return direction === 'add'
158
+ ? [...new Set([...selected, ...changes])]
159
+ : selected.filter((value) => !changes.has(value))
160
+ }
161
+ export function gaugeGeometry(value: number, min: number, max: number, semi: boolean) {
162
+ const clamped = bounded(value, min, max)
163
+ return {
164
+ value: clamped,
165
+ ratio: (clamped - min) / (max - min),
166
+ path: semi ? 'M 10 50 A 40 40 0 0 1 90 50' : 'M 50 10 A 40 40 0 1 1 49.999 10',
167
+ viewBox: [0, 0, 100, semi ? 58 : 100] as const,
168
+ }
169
+ }