@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,164 @@
1
+ import { chartGeometry } from './chart.js'
2
+
3
+ export interface KanbanColumn {
4
+ id: string
5
+ title: string
6
+ limit?: number
7
+ }
8
+ export interface KanbanCard {
9
+ id: string
10
+ column: string
11
+ title: string
12
+ description?: string
13
+ disabled?: boolean
14
+ }
15
+ export interface KanbanMove {
16
+ id: string
17
+ from: string
18
+ to: string
19
+ before: string | null
20
+ }
21
+ export interface DonutSegment {
22
+ id: string
23
+ label: string
24
+ value: number
25
+ color?: string
26
+ }
27
+ export interface SparklinePoint {
28
+ id: string
29
+ label: string
30
+ value: number | null
31
+ }
32
+ export interface DashboardRect {
33
+ x: number
34
+ y: number
35
+ width: number
36
+ height: number
37
+ }
38
+ export function dashboardNumber(value: number, min: number, max: number, name: string) {
39
+ if (!Number.isFinite(value) || value < min || value > max)
40
+ throw new RangeError(`${name} must be between ${min} and ${max}.`)
41
+ return value
42
+ }
43
+ function unique(items: readonly { id: string }[], name: string) {
44
+ const keys = new Set<string>()
45
+ for (const item of items) {
46
+ if (!item.id || keys.has(item.id)) throw new TypeError(`${name} requires unique, nonempty IDs.`)
47
+ keys.add(item.id)
48
+ }
49
+ }
50
+ export function validateKanban(columns: readonly KanbanColumn[], cards: readonly KanbanCard[]) {
51
+ unique(columns, 'Kanban columns')
52
+ unique(cards, 'Kanban cards')
53
+ if (!columns.length || columns.length > 12 || cards.length > 500)
54
+ throw new RangeError('Kanban supports 1–12 columns and at most 500 cards.')
55
+ for (const column of columns) {
56
+ if (!column.title.trim()) throw new TypeError('Kanban columns need a title.')
57
+ if (column.limit !== undefined && (!Number.isInteger(column.limit) || column.limit < 1))
58
+ throw new RangeError('Column limits must be positive integers.')
59
+ }
60
+ for (const card of cards)
61
+ if (!card.title.trim() || !columns.some((c) => c.id === card.column))
62
+ throw new TypeError('Cards require a title and an existing column.')
63
+ }
64
+ /** Keeps hidden cards and consumer metadata intact; limits apply to all cards, not the filtered view. */
65
+ export function moveKanban<T extends KanbanCard>(
66
+ columns: readonly KanbanColumn[],
67
+ cards: readonly T[],
68
+ id: string,
69
+ to: string,
70
+ before: string | null = null,
71
+ ): { cards: T[]; move: KanbanMove } | null {
72
+ validateKanban(columns, cards)
73
+ const card = cards.find((c) => c.id === id),
74
+ column = columns.find((c) => c.id === to)
75
+ if (!card || card.disabled || !column || before === id) return null
76
+ if (before !== null && !cards.some((c) => c.id === before && c.column === to)) return null
77
+ if (
78
+ card.column !== to &&
79
+ column.limit !== undefined &&
80
+ cards.filter((c) => c.column === to).length >= column.limit
81
+ )
82
+ return null
83
+ const next = cards.filter((c) => c.id !== id)
84
+ const index = before === null ? next.length : next.findIndex((c) => c.id === before)
85
+ next.splice(index, 0, { ...card, column: to })
86
+ const oldOrder = cards
87
+ .filter((c) => c.column === to)
88
+ .map((c) => c.id)
89
+ .join('\0')
90
+ const newOrder = next
91
+ .filter((c) => c.column === to)
92
+ .map((c) => c.id)
93
+ .join('\0')
94
+ if (card.column === to && oldOrder === newOrder) return null
95
+ return { cards: next, move: { id, from: card.column, to, before } }
96
+ }
97
+ export function donutGeometry(segments: readonly DonutSegment[]) {
98
+ unique(segments, 'Donut segments')
99
+ if (segments.length > 24) throw new RangeError('Donut supports at most 24 segments.')
100
+ let total = 0
101
+ for (const segment of segments) {
102
+ if (!segment.label.trim() || !Number.isFinite(segment.value) || segment.value < 0)
103
+ throw new TypeError('Donut segments require a label and finite nonnegative value.')
104
+ if (segment.color && !/^#[\da-f]{6}$/i.test(segment.color))
105
+ throw new TypeError('Segment colors must be six-digit HEX.')
106
+ total += segment.value
107
+ }
108
+ if (!Number.isFinite(total)) throw new RangeError('Donut total must be finite.')
109
+ let offset = 0
110
+ return {
111
+ total,
112
+ segments: segments.map((segment) => {
113
+ const ratio = total ? segment.value / total : 0,
114
+ start = offset
115
+ offset = Math.min(1, offset + ratio)
116
+ return { ...segment, ratio, start, end: offset }
117
+ }),
118
+ }
119
+ }
120
+ export const donutPath = 'M 50 10 A 40 40 0 1 1 50 90 A 40 40 0 1 1 50 10'
121
+ /** Uses the chart domain/null conventions. A zero-length line is extended for a single point. */
122
+ export function sparklineGeometry(
123
+ points: readonly SparklinePoint[],
124
+ domain?: readonly [number, number],
125
+ width = 100,
126
+ height = 40,
127
+ ) {
128
+ unique(points, 'Sparkline points')
129
+ const geometry = chartGeometry(
130
+ points.map((p) => ({ key: p.id, label: p.label })),
131
+ [{ key: 'sparkline', label: 'Values', values: points.map((p) => p.value) }],
132
+ domain,
133
+ )
134
+ const paths: { id: string; d: string }[] = []
135
+ let d = '',
136
+ id = '',
137
+ count = 0,
138
+ last = ''
139
+ const flush = () => {
140
+ if (d) paths.push({ id, d: count === 1 ? `${d} L${last}` : d })
141
+ d = ''
142
+ count = 0
143
+ }
144
+ for (const point of geometry.series[0]?.points ?? []) {
145
+ if (!point) {
146
+ flush()
147
+ continue
148
+ }
149
+ if (!d) id = points[point.index]!.id
150
+ const x =
151
+ (points.length === 1 ? 0.5 : 0.02 + (point.index / (points.length - 1)) * 0.96) * width
152
+ const y = (0.1 + point.y * 0.8) * height
153
+ last = `${Math.min(width * 0.98, x + 0.01)} ${y}`
154
+ d += `${d ? ' L' : 'M'}${x} ${y}`
155
+ count++
156
+ }
157
+ flush()
158
+ return { ...geometry, paths }
159
+ }
160
+ export function effectColors(colors: readonly string[]) {
161
+ if (colors.length < 2 || colors.length > 8 || colors.some((c) => !/^#[\da-f]{6}$/i.test(c)))
162
+ throw new TypeError('Effects require 2–8 six-digit HEX colors.')
163
+ return colors
164
+ }
@@ -0,0 +1,125 @@
1
+ export type CropRotation = 0 | 90 | 180 | 270
2
+ /** Coordinates in the decoded image after applying the clockwise quarter rotation. */
3
+ export interface ImageCrop {
4
+ x: number
5
+ y: number
6
+ width: number
7
+ height: number
8
+ rotation: CropRotation
9
+ }
10
+ export interface CropImage {
11
+ width: number
12
+ height: number
13
+ }
14
+ export interface CropExportOptions {
15
+ mimeType: 'image/png' | 'image/jpeg'
16
+ quality: number
17
+ width?: number
18
+ }
19
+ /** Web returns a data URI; NativeScript returns a temporary file owned by the caller. */
20
+ export interface CropExport {
21
+ uri: string
22
+ width: number
23
+ height: number
24
+ mimeType: 'image/png' | 'image/jpeg'
25
+ dispose(): Promise<void>
26
+ }
27
+ export interface CropSource extends CropImage {
28
+ readonly preview: unknown
29
+ export(crop: ImageCrop, options: CropExportOptions): Promise<CropExport>
30
+ dispose(): void
31
+ }
32
+ export function rotatedImage(image: CropImage, rotation: CropRotation) {
33
+ if (
34
+ ![0, 90, 180, 270].includes(rotation) ||
35
+ !Number.isFinite(image.width) ||
36
+ !Number.isFinite(image.height) ||
37
+ image.width <= 0 ||
38
+ image.height <= 0
39
+ )
40
+ throw new RangeError('Crop source dimensions and quarter rotation must be valid.')
41
+ return rotation === 90 || rotation === 270 ? { width: image.height, height: image.width } : image
42
+ }
43
+ export function fitImageCrop(
44
+ image: CropImage,
45
+ aspectRatio: number,
46
+ rotation: CropRotation = 0,
47
+ ): ImageCrop {
48
+ const size = rotatedImage(image, rotation)
49
+ if (!Number.isFinite(aspectRatio) || aspectRatio < 0.1 || aspectRatio > 10)
50
+ throw new RangeError('Crop aspectRatio must be between 0.1 and 10.')
51
+ const width = Math.min(size.width, size.height * aspectRatio),
52
+ height = width / aspectRatio
53
+ return { x: (size.width - width) / 2, y: (size.height - height) / 2, width, height, rotation }
54
+ }
55
+ export function validateImageCrop(image: CropImage, crop: ImageCrop, aspectRatio?: number) {
56
+ const size = rotatedImage(image, crop.rotation)
57
+ if (
58
+ ![crop.x, crop.y, crop.width, crop.height].every(Number.isFinite) ||
59
+ crop.x < 0 ||
60
+ crop.y < 0 ||
61
+ crop.width < 1 ||
62
+ crop.height < 1 ||
63
+ crop.x + crop.width > size.width + 0.001 ||
64
+ crop.y + crop.height > size.height + 0.001 ||
65
+ (aspectRatio !== undefined && Math.abs(crop.width / crop.height - aspectRatio) > 0.001)
66
+ )
67
+ throw new RangeError('Crop must stay inside the rotated source and respect the aspect ratio.')
68
+ return crop
69
+ }
70
+ export function moveImageCrop(
71
+ image: CropImage,
72
+ crop: ImageCrop,
73
+ dx: number,
74
+ dy: number,
75
+ ): ImageCrop {
76
+ validateImageCrop(image, crop)
77
+ if (![dx, dy].every(Number.isFinite)) throw new RangeError('Crop offsets must be finite.')
78
+ const size = rotatedImage(image, crop.rotation)
79
+ return {
80
+ ...crop,
81
+ x: Math.max(0, Math.min(size.width - crop.width, crop.x + dx)),
82
+ y: Math.max(0, Math.min(size.height - crop.height, crop.y + dy)),
83
+ }
84
+ }
85
+ export function zoomImageCrop(image: CropImage, crop: ImageCrop, zoom: number): ImageCrop {
86
+ validateImageCrop(image, crop)
87
+ if (!Number.isFinite(zoom) || zoom < 1 || zoom > 8)
88
+ throw new RangeError('Crop zoom must be between 1 and 8.')
89
+ const fit = fitImageCrop(image, crop.width / crop.height, crop.rotation),
90
+ width = fit.width / Math.min(zoom, fit.width, fit.height),
91
+ height = fit.height / Math.min(zoom, fit.width, fit.height)
92
+ return moveImageCrop(
93
+ image,
94
+ { ...crop, x: 0, y: 0, width, height },
95
+ crop.x + crop.width / 2 - width / 2,
96
+ crop.y + crop.height / 2 - height / 2,
97
+ )
98
+ }
99
+ export function cropOutputSize(crop: ImageCrop, options: CropExportOptions) {
100
+ if (
101
+ !['image/png', 'image/jpeg'].includes(options.mimeType) ||
102
+ !Number.isFinite(options.quality) ||
103
+ options.quality < 0 ||
104
+ options.quality > 1
105
+ )
106
+ throw new RangeError('Invalid crop output format or quality.')
107
+ const width = options.width ?? Math.round(crop.width),
108
+ height = Math.round((width * crop.height) / crop.width)
109
+ if (!Number.isInteger(width) || width < 1 || width > 4096 || height < 1 || height > 4096)
110
+ throw new RangeError('Crop output dimensions must be between 1 and 4096 pixels.')
111
+ return { width, height }
112
+ }
113
+ /** Original-image center and scale within the crop viewport; rotation is about the center. */
114
+ export function cropPresentation(image: CropImage, crop: ImageCrop, viewportWidth: number) {
115
+ validateImageCrop(image, crop)
116
+ const size = rotatedImage(image, crop.rotation),
117
+ scale = viewportWidth / crop.width
118
+ return {
119
+ width: image.width * scale,
120
+ height: image.height * scale,
121
+ x: (size.width / 2 - crop.x - image.width / 2) * scale,
122
+ y: (size.height / 2 - crop.y - image.height / 2) * scale,
123
+ rotation: crop.rotation,
124
+ }
125
+ }
package/src/index.ts CHANGED
@@ -113,3 +113,14 @@ export * from './chart.js'
113
113
  export * from './interactive.js'
114
114
 
115
115
  export * from './number-flow-format.js'
116
+
117
+ export * from './screen-components.js'
118
+ export * from './creative-controls.js'
119
+
120
+ export * from './dashboard.js'
121
+
122
+ export * from './advanced-collections.js'
123
+
124
+ export * from './image-crop.js'
125
+
126
+ export * from './scheduler.js'
@@ -0,0 +1,194 @@
1
+ import { addCivilDays, civilDate, parseCivilDate, formatCivilDate, type CivilDate } from './date.js'
2
+ import { uniqueAdvanced } from './advanced-collections.js'
3
+ export interface SchedulerEvent {
4
+ id: string
5
+ title: string
6
+ start: number
7
+ end: number
8
+ color?: string
9
+ disabled?: boolean
10
+ }
11
+ export interface SchedulerCivilTime {
12
+ date: CivilDate
13
+ minute: number
14
+ }
15
+ export interface SchedulerClock {
16
+ parts(instant: number, timeZone: string): SchedulerCivilTime
17
+ }
18
+ export type SchedulerDisambiguation = 'reject' | 'earlier' | 'later'
19
+ export interface SchedulerChange {
20
+ id: string
21
+ start: number
22
+ end: number
23
+ kind: 'move' | 'resize'
24
+ }
25
+ function civilMilliseconds(value: SchedulerCivilTime) {
26
+ const parts = parseCivilDate(value.date)
27
+ if (!parts || !Number.isInteger(value.minute) || value.minute < 0 || value.minute >= 1440)
28
+ throw new RangeError('Invalid scheduler civil time.')
29
+ const date = new Date(0)
30
+ date.setUTCFullYear(parts.year, parts.month - 1, parts.day)
31
+ date.setUTCHours(0, value.minute, 0, 0)
32
+ return date.getTime()
33
+ }
34
+ export function schedulerCivilFromUTC(value: number): SchedulerCivilTime {
35
+ const date = new Date(value)
36
+ return {
37
+ date: formatCivilDate({
38
+ year: date.getUTCFullYear(),
39
+ month: date.getUTCMonth() + 1,
40
+ day: date.getUTCDate(),
41
+ }),
42
+ minute: date.getUTCHours() * 60 + date.getUTCMinutes(),
43
+ }
44
+ }
45
+ /** Resolve wall time by testing actual zone offsets around the date; never guess a DST gap. */
46
+ export function schedulerInstant(
47
+ value: SchedulerCivilTime,
48
+ timeZone: string,
49
+ clock: SchedulerClock,
50
+ disambiguation: SchedulerDisambiguation = 'reject',
51
+ ) {
52
+ if (!['reject', 'earlier', 'later'].includes(disambiguation))
53
+ throw new RangeError('Invalid scheduler disambiguation.')
54
+ if (!timeZone.trim()) throw new RangeError('Scheduler requires an explicit timeZone.')
55
+ const nominal = civilMilliseconds(value),
56
+ offsets = new Set<number>()
57
+ for (let hours = -36; hours <= 36; hours += 6) {
58
+ const instant = nominal + hours * 3600000
59
+ offsets.add(civilMilliseconds(clock.parts(instant, timeZone)) - instant)
60
+ }
61
+ const matches = [...offsets]
62
+ .map((offset) => nominal - offset)
63
+ .filter((instant) => {
64
+ const parts = clock.parts(instant, timeZone)
65
+ return parts.date === value.date && parts.minute === value.minute
66
+ })
67
+ .sort((a, b) => a - b)
68
+ if (!matches.length)
69
+ throw new RangeError('This local time does not exist in the selected time zone.')
70
+ if (matches.length > 1 && disambiguation === 'reject')
71
+ throw new RangeError('This local time occurs twice. Choose earlier or later explicitly.')
72
+ return matches[disambiguation === 'later' ? matches.length - 1 : 0]!
73
+ }
74
+ export function validateSchedulerEvents(events: readonly SchedulerEvent[]) {
75
+ uniqueAdvanced(events, 'Scheduler', 500)
76
+ for (const event of events)
77
+ if (
78
+ !event.title.trim() ||
79
+ !Number.isFinite(event.start) ||
80
+ !Number.isFinite(event.end) ||
81
+ event.end <= event.start ||
82
+ event.end - event.start > 31 * 86400000 ||
83
+ Math.abs(event.start) > 8640000000000000 ||
84
+ Math.abs(event.end) > 8640000000000000 ||
85
+ (event.color && !/^#[\da-f]{6}$/i.test(event.color))
86
+ )
87
+ throw new RangeError(
88
+ 'Scheduler events require a title, ordered epoch milliseconds (duration <=31 days) and optional HEX color.',
89
+ )
90
+ }
91
+ export function changeSchedulerEvent<T extends SchedulerEvent>(
92
+ events: readonly T[],
93
+ change: SchedulerChange,
94
+ ) {
95
+ validateSchedulerEvents(events)
96
+ const event = events.find((event) => event.id === change.id)
97
+ if (!event || event.disabled) return [...events]
98
+ const next = events.map((event) =>
99
+ event.id === change.id ? { ...event, start: change.start, end: change.end } : event,
100
+ )
101
+ validateSchedulerEvents(next)
102
+ return next
103
+ }
104
+ export function schedulerLayout(
105
+ events: readonly SchedulerEvent[],
106
+ date: CivilDate,
107
+ days: number,
108
+ timeZone: string,
109
+ clock: SchedulerClock,
110
+ startHour = 0,
111
+ endHour = 24,
112
+ ) {
113
+ civilDate(date)
114
+ clock.parts(new Date(`${date}T12:00:00.000Z`).getTime(), timeZone)
115
+ validateSchedulerEvents(events)
116
+ if (
117
+ ![1, 7].includes(days) ||
118
+ !Number.isInteger(startHour) ||
119
+ !Number.isInteger(endHour) ||
120
+ startHour < 0 ||
121
+ endHour > 24 ||
122
+ startHour >= endHour
123
+ )
124
+ throw new RangeError('Scheduler needs a day/week and ordered whole-hour bounds.')
125
+ return Array.from({ length: days }, (_, day) => {
126
+ const civil = addCivilDays(date, day)
127
+ const segments = events
128
+ .flatMap((event) => {
129
+ const start = clock.parts(event.start, timeZone),
130
+ end = clock.parts(event.end, timeZone)
131
+ if (start.date > civil || end.date < civil || (end.date === civil && end.minute === 0))
132
+ return []
133
+ const top = Math.max(startHour * 60, start.date < civil ? 0 : start.minute),
134
+ bottom = Math.min(endHour * 60, end.date > civil ? 1440 : end.minute)
135
+ // A repeated-hour event may finish at an earlier wall time; retain its elapsed duration.
136
+ const finish =
137
+ end.minute <= start.minute &&
138
+ start.minute >= startHour * 60 &&
139
+ start.minute < endHour * 60 &&
140
+ event.end > event.start &&
141
+ start.date === civil &&
142
+ end.date === civil
143
+ ? Math.min(endHour * 60, top + (event.end - event.start) / 60000)
144
+ : bottom
145
+ return finish > top
146
+ ? [
147
+ {
148
+ event,
149
+ day,
150
+ date: civil,
151
+ top,
152
+ bottom: finish,
153
+ lane: 0,
154
+ lanes: 1,
155
+ startsHere: start.date === civil,
156
+ endsHere: end.date === civil,
157
+ },
158
+ ]
159
+ : []
160
+ })
161
+ .sort(
162
+ (a, b) =>
163
+ a.top - b.top || a.event.start - b.event.start || a.event.id.localeCompare(b.event.id),
164
+ )
165
+ let group: typeof segments = [],
166
+ ends: number[] = [],
167
+ groupEnd = 0
168
+ function finish() {
169
+ for (const segment of group) segment.lanes = ends.length
170
+ group = []
171
+ ends = []
172
+ }
173
+ for (const segment of segments) {
174
+ if (group.length && segment.top >= groupEnd) finish()
175
+ let lane = ends.findIndex((end) => end <= segment.top)
176
+ if (lane < 0) lane = ends.length
177
+ ends[lane] = segment.bottom
178
+ segment.lane = lane
179
+ group.push(segment)
180
+ groupEnd = Math.max(...ends)
181
+ }
182
+ finish()
183
+ return { date: civil, segments }
184
+ })
185
+ }
186
+
187
+ /** Offset distinguishes the two occurrences of a repeated local time. */
188
+ export function schedulerOffset(instant: number, timeZone: string, clock: SchedulerClock) {
189
+ const minutes = Math.round(
190
+ (civilMilliseconds(clock.parts(instant, timeZone)) - Math.floor(instant / 60000) * 60000) /
191
+ 60000,
192
+ )
193
+ return `UTC${minutes >= 0 ? '+' : '−'}${String(Math.floor(Math.abs(minutes) / 60)).padStart(2, '0')}:${String(Math.abs(minutes) % 60).padStart(2, '0')}`
194
+ }
@@ -0,0 +1,59 @@
1
+ import type { IconName } from './icon.js'
2
+ import type { ChoiceValue } from './choice.js'
3
+
4
+ export interface SpeedDialAction {
5
+ value: ChoiceValue
6
+ label: string
7
+ icon?: IconName
8
+ disabled?: boolean
9
+ }
10
+ export interface ComposerAttachment {
11
+ id: string
12
+ name: string
13
+ }
14
+ export interface ComposerMessage {
15
+ text: string
16
+ attachments: readonly ComposerAttachment[]
17
+ }
18
+ /** Native/core-only consumers need no DOM typings; Web retains fetch's full signal type. */
19
+ export type RefreshSignal = typeof globalThis extends {
20
+ AbortController: { prototype: { signal: infer Signal } }
21
+ }
22
+ ? Signal
23
+ : {
24
+ readonly aborted: boolean
25
+ readonly reason: unknown
26
+ throwIfAborted(): void
27
+ addEventListener(type: 'abort', listener: () => void, options?: { once?: boolean }): void
28
+ removeEventListener(type: 'abort', listener: () => void): void
29
+ }
30
+ export interface RefreshContext {
31
+ readonly signal: RefreshSignal
32
+ readonly cancelled: boolean
33
+ /** Apply results only while this refresh still owns the component. */
34
+ commit(change: () => void | Promise<void>): Promise<boolean>
35
+ }
36
+ export type RefreshAction = (context: RefreshContext) => void | Promise<void>
37
+ export type RefreshState = 'idle' | 'refreshing' | 'success' | 'error'
38
+ export function pinLength(length: number) {
39
+ if (!Number.isInteger(length) || length < 2 || length > 12)
40
+ throw new RangeError('MPinInput length must be an integer between 2 and 12.')
41
+ return length
42
+ }
43
+ /** Accept pasted separators and full-width digits without accepting arbitrary code. */
44
+ export function normalizePin(value: string, length: number) {
45
+ return value
46
+ .replace(/[0-9]/g, (digit) => String.fromCharCode(digit.charCodeAt(0) - 0xfee0))
47
+ .replace(/[^0-9]/g, '')
48
+ .slice(0, pinLength(length))
49
+ }
50
+ export function uniqueActions(actions: readonly SpeedDialAction[]) {
51
+ const keys = new Set<string>()
52
+ for (const action of actions) {
53
+ const key = `${typeof action.value}:${action.value}`
54
+ if (!action.label.trim() || keys.has(key))
55
+ throw new TypeError('Speed dial actions require unique values and nonempty labels.')
56
+ keys.add(key)
57
+ }
58
+ return actions
59
+ }