@getcortexlabs/mavis-core 0.1.0-alpha.10 → 0.1.0-alpha.11

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 (100) hide show
  1. package/dist/capabilities.d.ts +7 -7
  2. package/dist/capabilities.d.ts.map +1 -1
  3. package/dist/capabilities.js +16 -4
  4. package/dist/capabilities.js.map +1 -1
  5. package/dist/chart.d.ts +40 -0
  6. package/dist/chart.d.ts.map +1 -0
  7. package/dist/chart.js +73 -0
  8. package/dist/chart.js.map +1 -0
  9. package/dist/discovery.d.ts +49 -0
  10. package/dist/discovery.d.ts.map +1 -0
  11. package/dist/discovery.js +80 -0
  12. package/dist/discovery.js.map +1 -0
  13. package/dist/index.d.ts +3 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +3 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/vue/carousel.d.ts +11 -0
  18. package/dist/vue/carousel.d.ts.map +1 -0
  19. package/dist/vue/carousel.js +115 -0
  20. package/dist/vue/carousel.js.map +1 -0
  21. package/dist/vue/chart.d.ts +194 -0
  22. package/dist/vue/chart.d.ts.map +1 -0
  23. package/dist/vue/chart.js +246 -0
  24. package/dist/vue/chart.js.map +1 -0
  25. package/dist/vue/command-palette.d.ts +129 -0
  26. package/dist/vue/command-palette.d.ts.map +1 -0
  27. package/dist/vue/command-palette.js +187 -0
  28. package/dist/vue/command-palette.js.map +1 -0
  29. package/dist/vue/component-props.d.ts +475 -18
  30. package/dist/vue/component-props.d.ts.map +1 -1
  31. package/dist/vue/component-props.js +14 -0
  32. package/dist/vue/component-props.js.map +1 -1
  33. package/dist/vue/configurator.d.ts +2 -2
  34. package/dist/vue/data-table.d.ts +17 -0
  35. package/dist/vue/data-table.d.ts.map +1 -0
  36. package/dist/vue/data-table.js +133 -0
  37. package/dist/vue/data-table.js.map +1 -0
  38. package/dist/vue/date-picker.d.ts +8 -8
  39. package/dist/vue/date-props.d.ts +6 -0
  40. package/dist/vue/date-props.d.ts.map +1 -1
  41. package/dist/vue/date-props.js +3 -0
  42. package/dist/vue/date-props.js.map +1 -1
  43. package/dist/vue/discovery-components.d.ts +50 -0
  44. package/dist/vue/discovery-components.d.ts.map +1 -0
  45. package/dist/vue/discovery-components.js +2 -0
  46. package/dist/vue/discovery-components.js.map +1 -0
  47. package/dist/vue/discovery-controls.d.ts +197 -0
  48. package/dist/vue/discovery-controls.d.ts.map +1 -0
  49. package/dist/vue/discovery-controls.js +166 -0
  50. package/dist/vue/discovery-controls.js.map +1 -0
  51. package/dist/vue/discovery-props.d.ts +249 -0
  52. package/dist/vue/discovery-props.d.ts.map +1 -0
  53. package/dist/vue/discovery-props.js +87 -0
  54. package/dist/vue/discovery-props.js.map +1 -0
  55. package/dist/vue/global-components.d.ts +61 -0
  56. package/dist/vue/global-components.d.ts.map +1 -1
  57. package/dist/vue/index.d.ts +10 -0
  58. package/dist/vue/index.d.ts.map +1 -1
  59. package/dist/vue/index.js +9 -0
  60. package/dist/vue/index.js.map +1 -1
  61. package/dist/vue/menu.d.ts +1 -1
  62. package/dist/vue/props.d.ts +36 -36
  63. package/dist/vue/time-picker.d.ts +2 -2
  64. package/dist/vue/tree-view.d.ts +111 -0
  65. package/dist/vue/tree-view.d.ts.map +1 -0
  66. package/dist/vue/tree-view.js +180 -0
  67. package/dist/vue/tree-view.js.map +1 -0
  68. package/dist/vue/wayfinding-controls.d.ts +198 -0
  69. package/dist/vue/wayfinding-controls.d.ts.map +1 -0
  70. package/dist/vue/wayfinding-controls.js +310 -0
  71. package/dist/vue/wayfinding-controls.js.map +1 -0
  72. package/dist/vue/wayfinding-props.d.ts +221 -0
  73. package/dist/vue/wayfinding-props.d.ts.map +1 -0
  74. package/dist/vue/wayfinding-props.js +86 -0
  75. package/dist/vue/wayfinding-props.js.map +1 -0
  76. package/dist/vue/workflows.d.ts +2 -2
  77. package/dist/wayfinding.d.ts +50 -0
  78. package/dist/wayfinding.d.ts.map +1 -0
  79. package/dist/wayfinding.js +54 -0
  80. package/dist/wayfinding.js.map +1 -0
  81. package/package.json +1 -1
  82. package/src/capabilities.ts +16 -4
  83. package/src/chart.ts +112 -0
  84. package/src/discovery.ts +139 -0
  85. package/src/index.ts +5 -0
  86. package/src/vue/carousel.ts +173 -0
  87. package/src/vue/chart.ts +338 -0
  88. package/src/vue/command-palette.ts +232 -0
  89. package/src/vue/component-props.ts +28 -0
  90. package/src/vue/data-table.ts +190 -0
  91. package/src/vue/date-props.ts +3 -0
  92. package/src/vue/discovery-components.ts +60 -0
  93. package/src/vue/discovery-controls.ts +218 -0
  94. package/src/vue/discovery-props.ts +92 -0
  95. package/src/vue/global-components.ts +66 -0
  96. package/src/vue/index.ts +13 -0
  97. package/src/vue/tree-view.ts +220 -0
  98. package/src/vue/wayfinding-controls.ts +412 -0
  99. package/src/vue/wayfinding-props.ts +97 -0
  100. package/src/wayfinding.ts +85 -0
package/src/chart.ts ADDED
@@ -0,0 +1,112 @@
1
+ import { collectionKeys } from './discovery.js'
2
+ import type { ChoiceValue } from './choice.js'
3
+
4
+ export interface ChartCategory {
5
+ key: ChoiceValue
6
+ label: string
7
+ }
8
+ export interface ChartSeries {
9
+ key: ChoiceValue
10
+ label: string
11
+ values: readonly (number | null)[]
12
+ /** A shared CSS/native hex color; the theme supplies defaults. */
13
+ color?: string
14
+ }
15
+ export interface ChartSelection {
16
+ category: ChoiceValue
17
+ series: ChoiceValue
18
+ }
19
+ export interface ChartPoint {
20
+ x: number
21
+ y: number
22
+ value: number
23
+ index: number
24
+ }
25
+ export interface ChartGeometry {
26
+ min: number
27
+ max: number
28
+ zero: number
29
+ ticks: readonly number[]
30
+ series: readonly { key: ChoiceValue; points: readonly (ChartPoint | null)[] }[]
31
+ }
32
+
33
+ /** Hit testing uses normalized plot coordinates, independent of DOM/native geometry. */
34
+ export function chartHitTest(geometry: ChartGeometry, type: 'line' | 'bar', x: number, y: number) {
35
+ const count = geometry.series[0]?.points.length ?? 0
36
+ if (!count || !Number.isFinite(x) || !Number.isFinite(y)) return null
37
+ const category = Math.max(0, Math.min(count - 1, Math.floor(x * count)))
38
+ if (type === 'bar') {
39
+ const within = x * count - category
40
+ const series = Math.max(
41
+ 0,
42
+ Math.min(
43
+ geometry.series.length - 1,
44
+ Math.floor(((within - 0.15) / 0.7) * geometry.series.length),
45
+ ),
46
+ )
47
+ return geometry.series[series]?.points[category] ? { category, series } : null
48
+ }
49
+ let nearest = -1,
50
+ distance = Infinity
51
+ geometry.series.forEach((series, index) => {
52
+ const point = series.points[category]
53
+ if (point && Math.abs(point.y - y) < distance) {
54
+ nearest = index
55
+ distance = Math.abs(point.y - y)
56
+ }
57
+ })
58
+ return nearest < 0 ? null : { category, series: nearest }
59
+ }
60
+
61
+ /** Category positions and values normalized to [0,1], identical in both renderers. */
62
+ export function chartGeometry(
63
+ categories: readonly ChartCategory[],
64
+ series: readonly ChartSeries[],
65
+ domain?: readonly [number, number],
66
+ ): ChartGeometry {
67
+ collectionKeys(categories, 'key')
68
+ collectionKeys(series, 'key')
69
+ // This first renderer targets small product charts, not unbounded telemetry streams.
70
+ if (categories.length > 100 || series.length > 8)
71
+ throw new RangeError('Chart supports up to 100 categories and 8 series.')
72
+ for (const category of categories)
73
+ if (!category.label.trim()) throw new TypeError('Chart categories require labels.')
74
+ const values: number[] = []
75
+ for (const item of series) {
76
+ if (!item.label.trim() || item.values.length !== categories.length)
77
+ throw new TypeError('Chart series require labels and one value per category.')
78
+ if (item.color && !/^#[\da-f]{6}$/i.test(item.color))
79
+ throw new TypeError('Chart colors must be six digit hex values.')
80
+ for (const value of item.values) {
81
+ if (value !== null && !Number.isFinite(value))
82
+ throw new RangeError('Chart values must be finite numbers or null.')
83
+ if (value !== null) values.push(value)
84
+ }
85
+ }
86
+ let min = Math.min(0, ...values),
87
+ max = Math.max(0, ...values)
88
+ if (domain) {
89
+ if (domain.length !== 2 || !domain.every(Number.isFinite) || domain[0] >= domain[1])
90
+ throw new RangeError('Chart domain requires two increasing finite values.')
91
+ ;[min, max] = domain
92
+ if (values.some((value) => value < min || value > max))
93
+ throw new RangeError('Chart domain must contain every value.')
94
+ } else if (min === max) max = min + 1
95
+ const span = max - min
96
+ if (!Number.isFinite(span)) throw new RangeError('Chart domain span must be finite.')
97
+ const y = (value: number) => 1 - (value - min) / span
98
+ return {
99
+ min,
100
+ max,
101
+ zero: y(Math.max(min, Math.min(max, 0))),
102
+ ticks: Array.from({ length: 5 }, (_, i) => min + span * (i / 4)),
103
+ series: series.map((item) => ({
104
+ key: item.key,
105
+ points: item.values.map((value, index) =>
106
+ value === null
107
+ ? null
108
+ : { value, index, x: (index + 0.5) / Math.max(1, categories.length), y: y(value) },
109
+ ),
110
+ })),
111
+ }
112
+ }
@@ -0,0 +1,139 @@
1
+ import { choiceKey, type ChoiceValue } from './choice.js'
2
+ import { virtualKeys, type VirtualItemKey } from './collections.js'
3
+ import { sliderScale } from './slider.js'
4
+
5
+ export type RangeValue = readonly [number, number]
6
+ export function rangeValue(
7
+ value: RangeValue,
8
+ min: number,
9
+ max: number,
10
+ step: number,
11
+ ): [number, number] {
12
+ const scale = sliderScale(min, max, step)
13
+ if (!Array.isArray(value) || value.length !== 2 || value[0]! > value[1]!)
14
+ throw new RangeError('RangeSlider requires an ordered pair.')
15
+ return [scale.fromNative(scale.toNative(value[0]!)), scale.fromNative(scale.toNative(value[1]!))]
16
+ }
17
+ export function moveRange(
18
+ value: RangeValue,
19
+ thumb: 0 | 1,
20
+ next: number,
21
+ min: number,
22
+ max: number,
23
+ step: number,
24
+ ): [number, number] {
25
+ const pair = rangeValue(value, min, max, step)
26
+ const scale = sliderScale(min, max, step)
27
+ const snapped = scale.fromNative(scale.toNative(next))
28
+ pair[thumb] = thumb === 0 ? Math.min(snapped, pair[1]) : Math.max(snapped, pair[0])
29
+ return pair
30
+ }
31
+
32
+ export interface DataColumn<T = Record<string, unknown>> {
33
+ key: string
34
+ label: string
35
+ /** Display text; sorting remains an application-owned operation. */
36
+ value?: (item: T) => string | number | null | undefined
37
+ sortable?: boolean
38
+ width?: number
39
+ align?: 'start' | 'end'
40
+ }
41
+ export interface DataSort {
42
+ key: string
43
+ direction: 'ascending' | 'descending'
44
+ }
45
+ export interface DataCellSlot<T = Record<string, unknown>> {
46
+ item: T
47
+ itemKey: ChoiceValue
48
+ column: DataColumn<T>
49
+ value: string | number | null | undefined
50
+ index: number
51
+ }
52
+ export function validateColumns(columns: readonly DataColumn[]) {
53
+ const seen = new Set<string>()
54
+ if (!columns.length) throw new RangeError('DataTable requires at least one column.')
55
+ for (const column of columns) {
56
+ if (!column.key || !column.label.trim() || seen.has(column.key))
57
+ throw new TypeError('DataTable columns require unique keys and nonempty labels.')
58
+ if (column.width !== undefined && (!Number.isFinite(column.width) || column.width < 44))
59
+ throw new RangeError('Column width must be at least 44.')
60
+ seen.add(column.key)
61
+ }
62
+ }
63
+ export function nextDataSort(current: DataSort | null, key: string): DataSort | null {
64
+ return current?.key !== key
65
+ ? { key, direction: 'ascending' }
66
+ : current.direction === 'ascending'
67
+ ? { key, direction: 'descending' }
68
+ : null
69
+ }
70
+ /** Page selection preserves keys from other pages and does not mutate the input. */
71
+ export function selectPage(
72
+ selected: readonly ChoiceValue[],
73
+ page: readonly ChoiceValue[],
74
+ checked: boolean,
75
+ ) {
76
+ const pageIds = new Set(page.map(choiceKey))
77
+ const result = selected.filter((key) => !pageIds.has(choiceKey(key)))
78
+ return checked ? [...result, ...page] : result
79
+ }
80
+ export function collectionKeys<T>(items: readonly T[], itemKey: VirtualItemKey<T>) {
81
+ return virtualKeys(items, itemKey)
82
+ }
83
+
84
+ export interface TreeNode {
85
+ key: ChoiceValue
86
+ label: string
87
+ disabled?: boolean
88
+ children?: readonly TreeNode[]
89
+ /** True with undefined children requests loading on expansion. An empty array is loaded. */
90
+ hasChildren?: boolean
91
+ }
92
+ export interface TreeEntry {
93
+ node: TreeNode
94
+ parent: ChoiceValue | null
95
+ level: number
96
+ position: number
97
+ siblings: number
98
+ }
99
+ export function treeEntries(
100
+ nodes: readonly TreeNode[],
101
+ expanded: readonly ChoiceValue[],
102
+ ): TreeEntry[] {
103
+ const seen = new Set<string>()
104
+ const open = new Set(expanded.map(choiceKey))
105
+ const visible: TreeEntry[] = []
106
+ function visit(
107
+ children: readonly TreeNode[],
108
+ parent: ChoiceValue | null,
109
+ level: number,
110
+ show: boolean,
111
+ ) {
112
+ if (level > 100) throw new RangeError('TreeView depth exceeds 100 levels.')
113
+ for (const [index, node] of children.entries()) {
114
+ if (
115
+ (typeof node.key !== 'string' && typeof node.key !== 'number') ||
116
+ (typeof node.key === 'number' && !Number.isFinite(node.key)) ||
117
+ !node.label.trim()
118
+ )
119
+ throw new TypeError('Tree nodes require a finite key and label.')
120
+ const id = choiceKey(node.key)
121
+ if (seen.has(id)) throw new RangeError('Tree keys must be unique; cycles are not allowed.')
122
+ seen.add(id)
123
+ if (show)
124
+ visible.push({ node, parent, level, position: index + 1, siblings: children.length })
125
+ if (node.children) visit(node.children, node.key, level + 1, show && open.has(id))
126
+ }
127
+ }
128
+ visit(nodes, null, 1, true)
129
+ return visible
130
+ }
131
+ export function treeBranch(node: TreeNode) {
132
+ return node.children === undefined ? !!node.hasChildren : node.children.length > 0
133
+ }
134
+ export function ratingValue(value: number, max: number, step: number) {
135
+ if (!Number.isInteger(max) || max < 1 || max > 10 || (step !== 1 && step !== 0.5))
136
+ throw new RangeError('Rating requires max 1–10 and step 1 or 0.5.')
137
+ if (!Number.isFinite(value)) throw new RangeError('Rating must be finite.')
138
+ return Math.max(0, Math.min(max, Math.round(value / step) * step))
139
+ }
package/src/index.ts CHANGED
@@ -103,3 +103,8 @@ export * from './collections.js'
103
103
 
104
104
  export { defineNavigationTransition } from './navigation-transition.js'
105
105
  export type { NavigationTransition } from './navigation-transition.js'
106
+
107
+ export * from './discovery.js'
108
+
109
+ export * from './wayfinding.js'
110
+ export * from './chart.js'
@@ -0,0 +1,173 @@
1
+ import type { CarouselComponent } from './discovery-components.js'
2
+ import {
3
+ computed,
4
+ defineComponent,
5
+ h,
6
+ markRaw,
7
+ mergeProps,
8
+ onScopeDispose,
9
+ ref,
10
+ watch,
11
+ type Component,
12
+ } from '@vue/runtime-core'
13
+ import { choiceKey, type ChoiceValue } from '../choice.js'
14
+ import { collectionKeys } from '../discovery.js'
15
+ import { createMotionSurface } from '../experimental.js'
16
+ import { carouselProps } from './discovery-props.js'
17
+ import { useMavisTheme } from './theme.js'
18
+
19
+ export function createCarousel(
20
+ ui: {
21
+ Column: Component
22
+ Row: Component
23
+ Box: Component
24
+ Text: Component
25
+ Button: Component
26
+ gestures: (move: (direction: number) => void) => Record<string, unknown>
27
+ },
28
+ platform: 'web' | 'native',
29
+ ) {
30
+ return defineComponent({
31
+ name: 'MCarousel',
32
+ inheritAttrs: false,
33
+ props: carouselProps,
34
+ emits: { 'update:modelValue': (_value: ChoiceValue) => true },
35
+ setup(props, { attrs, slots, emit }) {
36
+ const { theme } = useMavisTheme()
37
+ const keys = computed(() => collectionKeys(props.items, props.itemKey))
38
+ const index = computed(() =>
39
+ Math.max(
40
+ 0,
41
+ keys.value.findIndex((key) => key === props.modelValue),
42
+ ),
43
+ )
44
+ const direction = ref(1)
45
+ const surface = markRaw(createMotionSurface())
46
+ let first = true
47
+ onScopeDispose(
48
+ surface.use((motion) => {
49
+ if (first) {
50
+ first = false
51
+ return
52
+ }
53
+ motion.animate(
54
+ { x: [direction.value * 24, 0], opacity: [0.4, 1] },
55
+ { type: 'spring', duration: theme.value.motion.enterDuration, bounce: 0.12 },
56
+ )
57
+ }),
58
+ )
59
+ function choose(next: number) {
60
+ if (props.disabled || next === index.value || !keys.value.length) return
61
+ direction.value = next > index.value ? 1 : -1
62
+ emit('update:modelValue', keys.value[next]!)
63
+ }
64
+ function move(amount: number) {
65
+ const count = keys.value.length
66
+ if (!count) return
67
+ const next = props.loop
68
+ ? (index.value + amount + count) % count
69
+ : Math.max(0, Math.min(count - 1, index.value + amount))
70
+ choose(next)
71
+ }
72
+ watch(index, (next, previous) => {
73
+ direction.value = next > previous ? 1 : -1
74
+ })
75
+ const gestures = ui.gestures(move)
76
+ return () =>
77
+ h(
78
+ ui.Column,
79
+ mergeProps(
80
+ { id: props.id, gap: 'md' },
81
+ attrs,
82
+ platform === 'web'
83
+ ? {
84
+ class: 'm-carousel',
85
+ role: 'region',
86
+ 'aria-roledescription': 'carousel',
87
+ 'aria-label': props.label,
88
+ }
89
+ : {},
90
+ ),
91
+ () => [
92
+ h(ui.Row, { justify: 'between', gap: 'md', wrap: true }, () => [
93
+ h(ui.Text, { as: 'h2', text: props.label, variant: 'heading' }),
94
+ h(ui.Text, {
95
+ text: keys.value.length ? `${index.value + 1} / ${keys.value.length}` : '0 / 0',
96
+ tone: 'muted',
97
+ variant: 'caption',
98
+ ...(platform === 'web'
99
+ ? { role: 'status', 'aria-live': 'polite', 'aria-atomic': 'true' }
100
+ : { accessibilityLiveRegion: 'polite' }),
101
+ }),
102
+ ]),
103
+ keys.value.length
104
+ ? h(
105
+ ui.Box,
106
+ mergeProps(
107
+ { radius: 'lg' },
108
+ gestures,
109
+ platform === 'web' ? { style: { overflow: 'clip', touchAction: 'pan-y' } } : {},
110
+ ),
111
+ () =>
112
+ h(
113
+ ui.Box,
114
+ {
115
+ key: choiceKey(keys.value[index.value]!),
116
+ motionSurface: surface,
117
+ ...(platform === 'web'
118
+ ? {
119
+ role: 'group',
120
+ 'aria-roledescription': 'slide',
121
+ 'aria-label': `${props.slideLabel} ${index.value + 1} / ${keys.value.length}`,
122
+ }
123
+ : {}),
124
+ },
125
+ () =>
126
+ slots.default?.({
127
+ item: props.items[index.value],
128
+ index: index.value,
129
+ itemKey: keys.value[index.value],
130
+ }),
131
+ ),
132
+ )
133
+ : (slots.empty?.() ?? h(ui.Text, { text: props.emptyLabel, tone: 'muted' })),
134
+ h(ui.Row, { justify: 'between', gap: 'sm' }, () => [
135
+ h(ui.Button, {
136
+ icon: 'arrow-left',
137
+ variant: 'secondary',
138
+ accessibilityLabel: props.previousLabel,
139
+ disabled:
140
+ props.disabled || keys.value.length < 2 || (!props.loop && index.value === 0),
141
+ onClick: () => move(-1),
142
+ }),
143
+ h(ui.Row, { gap: 'xs', wrap: true, justify: 'center', shrink: 1 }, () =>
144
+ keys.value.map((key, n) =>
145
+ h(ui.Button, {
146
+ key: choiceKey(key),
147
+ text: String(n + 1),
148
+ variant: n === index.value ? 'primary' : 'ghost',
149
+ accessibilityLabel: `${props.slideLabel} ${n + 1}`,
150
+ disabled: props.disabled,
151
+ ...(platform === 'web'
152
+ ? { 'aria-current': n === index.value ? 'true' : undefined }
153
+ : {}),
154
+ onClick: () => choose(n),
155
+ }),
156
+ ),
157
+ ),
158
+ h(ui.Button, {
159
+ icon: 'arrow-right',
160
+ variant: 'secondary',
161
+ accessibilityLabel: props.nextLabel,
162
+ disabled:
163
+ props.disabled ||
164
+ keys.value.length < 2 ||
165
+ (!props.loop && index.value === keys.value.length - 1),
166
+ onClick: () => move(1),
167
+ }),
168
+ ]),
169
+ ],
170
+ )
171
+ },
172
+ }) as unknown as CarouselComponent
173
+ }