@getcortexlabs/mavis-core 0.1.0-alpha.9 → 0.1.0-rc.12

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 (340) hide show
  1. package/README.md +2 -2
  2. package/dist/capabilities.d.ts +7 -7
  3. package/dist/capabilities.d.ts.map +1 -1
  4. package/dist/capabilities.js +48 -4
  5. package/dist/capabilities.js.map +1 -1
  6. package/dist/chart.d.ts +43 -0
  7. package/dist/chart.d.ts.map +1 -0
  8. package/dist/chart.js +105 -0
  9. package/dist/chart.js.map +1 -0
  10. package/dist/collections.d.ts +46 -0
  11. package/dist/collections.d.ts.map +1 -0
  12. package/dist/collections.js +48 -0
  13. package/dist/collections.js.map +1 -0
  14. package/dist/contracts.d.ts +20 -0
  15. package/dist/contracts.d.ts.map +1 -1
  16. package/dist/contracts.js +2 -0
  17. package/dist/contracts.js.map +1 -1
  18. package/dist/creative-controls.d.ts +47 -0
  19. package/dist/creative-controls.d.ts.map +1 -0
  20. package/dist/creative-controls.js +112 -0
  21. package/dist/creative-controls.js.map +1 -0
  22. package/dist/dashboard.d.ts +72 -0
  23. package/dist/dashboard.d.ts.map +1 -0
  24. package/dist/dashboard.js +115 -0
  25. package/dist/dashboard.js.map +1 -0
  26. package/dist/discovery.d.ts +49 -0
  27. package/dist/discovery.d.ts.map +1 -0
  28. package/dist/discovery.js +80 -0
  29. package/dist/discovery.js.map +1 -0
  30. package/dist/experimental-regions.d.ts +10 -0
  31. package/dist/experimental-regions.d.ts.map +1 -1
  32. package/dist/experimental-regions.js +23 -0
  33. package/dist/experimental-regions.js.map +1 -1
  34. package/dist/experimental.d.ts +5 -0
  35. package/dist/experimental.d.ts.map +1 -1
  36. package/dist/experimental.js +29 -0
  37. package/dist/experimental.js.map +1 -1
  38. package/dist/index.d.ts +15 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +13 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/interactive.d.ts +36 -0
  43. package/dist/interactive.d.ts.map +1 -0
  44. package/dist/interactive.js +61 -0
  45. package/dist/interactive.js.map +1 -0
  46. package/dist/link.d.ts +2 -0
  47. package/dist/link.d.ts.map +1 -1
  48. package/dist/link.js.map +1 -1
  49. package/dist/motion.d.ts +8 -0
  50. package/dist/motion.d.ts.map +1 -1
  51. package/dist/motion.js +11 -0
  52. package/dist/motion.js.map +1 -1
  53. package/dist/navigation-transition.d.ts +10 -0
  54. package/dist/navigation-transition.d.ts.map +1 -0
  55. package/dist/navigation-transition.js +10 -0
  56. package/dist/navigation-transition.js.map +1 -0
  57. package/dist/number-flow-format.d.ts +16 -0
  58. package/dist/number-flow-format.d.ts.map +1 -0
  59. package/dist/number-flow-format.js +49 -0
  60. package/dist/number-flow-format.js.map +1 -0
  61. package/dist/popover.d.ts +17 -0
  62. package/dist/popover.d.ts.map +1 -0
  63. package/dist/popover.js +19 -0
  64. package/dist/popover.js.map +1 -0
  65. package/dist/screen-components.d.ts +45 -0
  66. package/dist/screen-components.d.ts.map +1 -0
  67. package/dist/screen-components.js +23 -0
  68. package/dist/screen-components.js.map +1 -0
  69. package/dist/section-scroll.d.ts +14 -0
  70. package/dist/section-scroll.d.ts.map +1 -0
  71. package/dist/section-scroll.js +28 -0
  72. package/dist/section-scroll.js.map +1 -0
  73. package/dist/time.d.ts +34 -0
  74. package/dist/time.d.ts.map +1 -0
  75. package/dist/time.js +78 -0
  76. package/dist/time.js.map +1 -0
  77. package/dist/vue/animated-text.d.ts +101 -0
  78. package/dist/vue/animated-text.d.ts.map +1 -0
  79. package/dist/vue/animated-text.js +56 -0
  80. package/dist/vue/animated-text.js.map +1 -0
  81. package/dist/vue/carousel.d.ts +13 -0
  82. package/dist/vue/carousel.d.ts.map +1 -0
  83. package/dist/vue/carousel.js +136 -0
  84. package/dist/vue/carousel.js.map +1 -0
  85. package/dist/vue/chart.d.ts +194 -0
  86. package/dist/vue/chart.d.ts.map +1 -0
  87. package/dist/vue/chart.js +245 -0
  88. package/dist/vue/chart.js.map +1 -0
  89. package/dist/vue/command-palette.d.ts +129 -0
  90. package/dist/vue/command-palette.d.ts.map +1 -0
  91. package/dist/vue/command-palette.js +190 -0
  92. package/dist/vue/command-palette.js.map +1 -0
  93. package/dist/vue/component-motion.d.ts +17 -0
  94. package/dist/vue/component-motion.d.ts.map +1 -0
  95. package/dist/vue/component-motion.js +83 -0
  96. package/dist/vue/component-motion.js.map +1 -0
  97. package/dist/vue/component-props.d.ts +1708 -21
  98. package/dist/vue/component-props.d.ts.map +1 -1
  99. package/dist/vue/component-props.js +50 -0
  100. package/dist/vue/component-props.js.map +1 -1
  101. package/dist/vue/composer.d.ts +159 -0
  102. package/dist/vue/composer.d.ts.map +1 -0
  103. package/dist/vue/composer.js +142 -0
  104. package/dist/vue/composer.js.map +1 -0
  105. package/dist/vue/configurator.d.ts +2 -2
  106. package/dist/vue/configurator.d.ts.map +1 -1
  107. package/dist/vue/configurator.js +3 -1
  108. package/dist/vue/configurator.js.map +1 -1
  109. package/dist/vue/creative-controls.d.ts +328 -0
  110. package/dist/vue/creative-controls.d.ts.map +1 -0
  111. package/dist/vue/creative-controls.js +396 -0
  112. package/dist/vue/creative-controls.js.map +1 -0
  113. package/dist/vue/creative-props.d.ts +260 -0
  114. package/dist/vue/creative-props.d.ts.map +1 -0
  115. package/dist/vue/creative-props.js +92 -0
  116. package/dist/vue/creative-props.js.map +1 -0
  117. package/dist/vue/dashboard-charts.d.ts +240 -0
  118. package/dist/vue/dashboard-charts.d.ts.map +1 -0
  119. package/dist/vue/dashboard-charts.js +263 -0
  120. package/dist/vue/dashboard-charts.js.map +1 -0
  121. package/dist/vue/dashboard-effects.d.ts +211 -0
  122. package/dist/vue/dashboard-effects.d.ts.map +1 -0
  123. package/dist/vue/dashboard-effects.js +235 -0
  124. package/dist/vue/dashboard-effects.js.map +1 -0
  125. package/dist/vue/dashboard-props.d.ts +244 -0
  126. package/dist/vue/dashboard-props.d.ts.map +1 -0
  127. package/dist/vue/dashboard-props.js +94 -0
  128. package/dist/vue/dashboard-props.js.map +1 -0
  129. package/dist/vue/data-table.d.ts +17 -0
  130. package/dist/vue/data-table.d.ts.map +1 -0
  131. package/dist/vue/data-table.js +133 -0
  132. package/dist/vue/data-table.js.map +1 -0
  133. package/dist/vue/date-calendar.d.ts +2 -0
  134. package/dist/vue/date-calendar.d.ts.map +1 -1
  135. package/dist/vue/date-calendar.js +20 -1
  136. package/dist/vue/date-calendar.js.map +1 -1
  137. package/dist/vue/date-picker.d.ts +8 -8
  138. package/dist/vue/date-props.d.ts +6 -0
  139. package/dist/vue/date-props.d.ts.map +1 -1
  140. package/dist/vue/date-props.js +3 -0
  141. package/dist/vue/date-props.js.map +1 -1
  142. package/dist/vue/discovery-components.d.ts +50 -0
  143. package/dist/vue/discovery-components.d.ts.map +1 -0
  144. package/dist/vue/discovery-components.js +2 -0
  145. package/dist/vue/discovery-components.js.map +1 -0
  146. package/dist/vue/discovery-controls.d.ts +197 -0
  147. package/dist/vue/discovery-controls.d.ts.map +1 -0
  148. package/dist/vue/discovery-controls.js +185 -0
  149. package/dist/vue/discovery-controls.js.map +1 -0
  150. package/dist/vue/discovery-props.d.ts +249 -0
  151. package/dist/vue/discovery-props.d.ts.map +1 -0
  152. package/dist/vue/discovery-props.js +87 -0
  153. package/dist/vue/discovery-props.js.map +1 -0
  154. package/dist/vue/global-components.d.ts +237 -0
  155. package/dist/vue/global-components.d.ts.map +1 -1
  156. package/dist/vue/index.d.ts +41 -0
  157. package/dist/vue/index.d.ts.map +1 -1
  158. package/dist/vue/index.js +37 -0
  159. package/dist/vue/index.js.map +1 -1
  160. package/dist/vue/interactive-components.d.ts +31 -0
  161. package/dist/vue/interactive-components.d.ts.map +1 -0
  162. package/dist/vue/interactive-components.js +2 -0
  163. package/dist/vue/interactive-components.js.map +1 -0
  164. package/dist/vue/interactive-props.d.ts +254 -0
  165. package/dist/vue/interactive-props.d.ts.map +1 -0
  166. package/dist/vue/interactive-props.js +85 -0
  167. package/dist/vue/interactive-props.js.map +1 -0
  168. package/dist/vue/kanban.d.ts +150 -0
  169. package/dist/vue/kanban.d.ts.map +1 -0
  170. package/dist/vue/kanban.js +267 -0
  171. package/dist/vue/kanban.js.map +1 -0
  172. package/dist/vue/list-motion.d.ts +7 -0
  173. package/dist/vue/list-motion.d.ts.map +1 -0
  174. package/dist/vue/list-motion.js +28 -0
  175. package/dist/vue/list-motion.js.map +1 -0
  176. package/dist/vue/marquee.d.ts +96 -0
  177. package/dist/vue/marquee.d.ts.map +1 -0
  178. package/dist/vue/marquee.js +186 -0
  179. package/dist/vue/marquee.js.map +1 -0
  180. package/dist/vue/menu.d.ts +122 -0
  181. package/dist/vue/menu.d.ts.map +1 -0
  182. package/dist/vue/menu.js +79 -0
  183. package/dist/vue/menu.js.map +1 -0
  184. package/dist/vue/navigation-controls.d.ts +125 -0
  185. package/dist/vue/navigation-controls.d.ts.map +1 -0
  186. package/dist/vue/navigation-controls.js +130 -0
  187. package/dist/vue/navigation-controls.js.map +1 -0
  188. package/dist/vue/navigation-props.d.ts +283 -0
  189. package/dist/vue/navigation-props.d.ts.map +1 -0
  190. package/dist/vue/navigation-props.js +82 -0
  191. package/dist/vue/navigation-props.js.map +1 -0
  192. package/dist/vue/number-flow.d.ts +75 -0
  193. package/dist/vue/number-flow.d.ts.map +1 -0
  194. package/dist/vue/number-flow.js +57 -0
  195. package/dist/vue/number-flow.js.map +1 -0
  196. package/dist/vue/partition.d.ts +15 -0
  197. package/dist/vue/partition.d.ts.map +1 -0
  198. package/dist/vue/partition.js +42 -0
  199. package/dist/vue/partition.js.map +1 -0
  200. package/dist/vue/pin-cell.d.ts +14 -0
  201. package/dist/vue/pin-cell.d.ts.map +1 -0
  202. package/dist/vue/pin-cell.js +19 -0
  203. package/dist/vue/pin-cell.js.map +1 -0
  204. package/dist/vue/pin-input.d.ts +14 -0
  205. package/dist/vue/pin-input.d.ts.map +1 -0
  206. package/dist/vue/pin-input.js +23 -0
  207. package/dist/vue/pin-input.js.map +1 -0
  208. package/dist/vue/platform.d.ts +37 -0
  209. package/dist/vue/platform.d.ts.map +1 -0
  210. package/dist/vue/platform.js +46 -0
  211. package/dist/vue/platform.js.map +1 -0
  212. package/dist/vue/props.d.ts +82 -42
  213. package/dist/vue/props.d.ts.map +1 -1
  214. package/dist/vue/props.js +3 -1
  215. package/dist/vue/props.js.map +1 -1
  216. package/dist/vue/screen-component-props.d.ts +236 -0
  217. package/dist/vue/screen-component-props.d.ts.map +1 -0
  218. package/dist/vue/screen-component-props.js +90 -0
  219. package/dist/vue/screen-component-props.js.map +1 -0
  220. package/dist/vue/scroll-frame.d.ts +223 -0
  221. package/dist/vue/scroll-frame.d.ts.map +1 -0
  222. package/dist/vue/scroll-frame.js +346 -0
  223. package/dist/vue/scroll-frame.js.map +1 -0
  224. package/dist/vue/sortable-list.d.ts +24 -0
  225. package/dist/vue/sortable-list.d.ts.map +1 -0
  226. package/dist/vue/sortable-list.js +251 -0
  227. package/dist/vue/sortable-list.js.map +1 -0
  228. package/dist/vue/speed-dial.d.ts +73 -0
  229. package/dist/vue/speed-dial.d.ts.map +1 -0
  230. package/dist/vue/speed-dial.js +78 -0
  231. package/dist/vue/speed-dial.js.map +1 -0
  232. package/dist/vue/swipe-actions.d.ts +96 -0
  233. package/dist/vue/swipe-actions.d.ts.map +1 -0
  234. package/dist/vue/swipe-actions.js +174 -0
  235. package/dist/vue/swipe-actions.js.map +1 -0
  236. package/dist/vue/swipe-deck.d.ts +120 -0
  237. package/dist/vue/swipe-deck.d.ts.map +1 -0
  238. package/dist/vue/swipe-deck.js +229 -0
  239. package/dist/vue/swipe-deck.js.map +1 -0
  240. package/dist/vue/time-picker.d.ts +488 -0
  241. package/dist/vue/time-picker.d.ts.map +1 -0
  242. package/dist/vue/time-picker.js +190 -0
  243. package/dist/vue/time-picker.js.map +1 -0
  244. package/dist/vue/tour.d.ts +120 -0
  245. package/dist/vue/tour.d.ts.map +1 -0
  246. package/dist/vue/tour.js +165 -0
  247. package/dist/vue/tour.js.map +1 -0
  248. package/dist/vue/tree-view.d.ts +111 -0
  249. package/dist/vue/tree-view.d.ts.map +1 -0
  250. package/dist/vue/tree-view.js +204 -0
  251. package/dist/vue/tree-view.js.map +1 -0
  252. package/dist/vue/virtual-list.d.ts +26 -0
  253. package/dist/vue/virtual-list.d.ts.map +1 -0
  254. package/dist/vue/virtual-list.js +2 -0
  255. package/dist/vue/virtual-list.js.map +1 -0
  256. package/dist/vue/wayfinding-controls.d.ts +199 -0
  257. package/dist/vue/wayfinding-controls.d.ts.map +1 -0
  258. package/dist/vue/wayfinding-controls.js +330 -0
  259. package/dist/vue/wayfinding-controls.js.map +1 -0
  260. package/dist/vue/wayfinding-props.d.ts +221 -0
  261. package/dist/vue/wayfinding-props.d.ts.map +1 -0
  262. package/dist/vue/wayfinding-props.js +86 -0
  263. package/dist/vue/wayfinding-props.js.map +1 -0
  264. package/dist/vue/workflows.d.ts +2 -2
  265. package/dist/vue/workflows.d.ts.map +1 -1
  266. package/dist/vue/workflows.js +17 -4
  267. package/dist/vue/workflows.js.map +1 -1
  268. package/dist/wayfinding.d.ts +50 -0
  269. package/dist/wayfinding.d.ts.map +1 -0
  270. package/dist/wayfinding.js +54 -0
  271. package/dist/wayfinding.js.map +1 -0
  272. package/package.json +2 -2
  273. package/src/capabilities.ts +50 -4
  274. package/src/chart.ts +151 -0
  275. package/src/collections.ts +87 -0
  276. package/src/contracts.ts +2 -0
  277. package/src/creative-controls.ts +169 -0
  278. package/src/dashboard.ts +164 -0
  279. package/src/discovery.ts +139 -0
  280. package/src/experimental-regions.ts +29 -0
  281. package/src/experimental.ts +40 -0
  282. package/src/index.ts +23 -1
  283. package/src/interactive.ts +91 -0
  284. package/src/link.ts +2 -0
  285. package/src/motion.ts +14 -0
  286. package/src/navigation-transition.ts +14 -0
  287. package/src/number-flow-format.ts +68 -0
  288. package/src/popover.ts +38 -0
  289. package/src/screen-components.ts +59 -0
  290. package/src/section-scroll.ts +46 -0
  291. package/src/time.ts +83 -0
  292. package/src/vue/animated-text.ts +72 -0
  293. package/src/vue/carousel.ts +198 -0
  294. package/src/vue/chart.ts +337 -0
  295. package/src/vue/command-palette.ts +235 -0
  296. package/src/vue/component-motion.ts +109 -0
  297. package/src/vue/component-props.ts +104 -0
  298. package/src/vue/composer.ts +192 -0
  299. package/src/vue/configurator.ts +3 -1
  300. package/src/vue/creative-controls.ts +524 -0
  301. package/src/vue/creative-props.ts +94 -0
  302. package/src/vue/dashboard-charts.ts +346 -0
  303. package/src/vue/dashboard-effects.ts +304 -0
  304. package/src/vue/dashboard-props.ts +95 -0
  305. package/src/vue/data-table.ts +190 -0
  306. package/src/vue/date-calendar.ts +30 -1
  307. package/src/vue/date-props.ts +3 -0
  308. package/src/vue/discovery-components.ts +60 -0
  309. package/src/vue/discovery-controls.ts +241 -0
  310. package/src/vue/discovery-props.ts +92 -0
  311. package/src/vue/global-components.ts +237 -0
  312. package/src/vue/index.ts +64 -0
  313. package/src/vue/interactive-components.ts +29 -0
  314. package/src/vue/interactive-props.ts +90 -0
  315. package/src/vue/kanban.ts +360 -0
  316. package/src/vue/list-motion.ts +31 -0
  317. package/src/vue/marquee.ts +248 -0
  318. package/src/vue/menu.ts +100 -0
  319. package/src/vue/navigation-controls.ts +159 -0
  320. package/src/vue/navigation-props.ts +87 -0
  321. package/src/vue/number-flow.ts +83 -0
  322. package/src/vue/partition.ts +49 -0
  323. package/src/vue/pin-cell.ts +26 -0
  324. package/src/vue/pin-input.ts +31 -0
  325. package/src/vue/platform.ts +73 -0
  326. package/src/vue/props.ts +3 -1
  327. package/src/vue/screen-component-props.ts +92 -0
  328. package/src/vue/scroll-frame.ts +429 -0
  329. package/src/vue/sortable-list.ts +308 -0
  330. package/src/vue/speed-dial.ts +108 -0
  331. package/src/vue/swipe-actions.ts +226 -0
  332. package/src/vue/swipe-deck.ts +277 -0
  333. package/src/vue/time-picker.ts +227 -0
  334. package/src/vue/tour.ts +239 -0
  335. package/src/vue/tree-view.ts +259 -0
  336. package/src/vue/virtual-list.ts +28 -0
  337. package/src/vue/wayfinding-controls.ts +430 -0
  338. package/src/vue/wayfinding-props.ts +97 -0
  339. package/src/vue/workflows.ts +17 -4
  340. package/src/wayfinding.ts +85 -0
package/src/popover.ts ADDED
@@ -0,0 +1,38 @@
1
+ export type PopoverPlacement = 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end'
2
+ export type PopoverCloseReason = 'trigger' | 'outside' | 'escape' | 'back' | 'select' | 'program'
3
+ export interface PopoverRect {
4
+ x: number
5
+ y: number
6
+ width: number
7
+ height: number
8
+ }
9
+
10
+ /** Coordinates share one CSS-pixel/DIP space. Flip vertically, then clamp to the viewport. */
11
+ export function placePopover(
12
+ anchor: PopoverRect,
13
+ panel: { width: number; height: number },
14
+ viewport: PopoverRect,
15
+ placement: PopoverPlacement,
16
+ rtl = false,
17
+ gap = 8,
18
+ margin = 8,
19
+ ) {
20
+ const bottom = anchor.y + anchor.height + gap
21
+ const top = anchor.y - gap - panel.height
22
+ const lower = viewport.y + viewport.height - margin
23
+ const upper = viewport.y + margin
24
+ let above = placement.startsWith('top')
25
+ if (above && top < upper && bottom + panel.height <= lower) above = false
26
+ else if (!above && bottom + panel.height > lower && top >= upper) above = true
27
+ const end = placement.endsWith('end') !== rtl
28
+ const clamp = (value: number, min: number, max: number) =>
29
+ Math.max(min, Math.min(value, Math.max(min, max)))
30
+ return {
31
+ x: clamp(
32
+ end ? anchor.x + anchor.width - panel.width : anchor.x,
33
+ viewport.x + margin,
34
+ viewport.x + viewport.width - panel.width - margin,
35
+ ),
36
+ y: clamp(above ? top : bottom, upper, lower - panel.height),
37
+ }
38
+ }
@@ -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
+ }
@@ -0,0 +1,46 @@
1
+ export type ScrollEdge = 'start' | 'center' | 'end'
2
+ export interface SectionScrollOptions {
3
+ /** [section edge, viewport edge]. Default: ['start', 'end']. */
4
+ start?: readonly [ScrollEdge, ScrollEdge]
5
+ /** [section edge, viewport edge]. Default: ['end', 'start']. */
6
+ end?: readonly [ScrollEdge, ScrollEdge]
7
+ }
8
+ const edge = { start: 0, center: 0.5, end: 1 } as const
9
+ export function validateSectionScroll(options: SectionScrollOptions) {
10
+ for (const value of [options.start, options.end])
11
+ if (
12
+ value !== undefined &&
13
+ (!Array.isArray(value) ||
14
+ value.length !== 2 ||
15
+ value.some((part) => !Object.hasOwn(edge, part)))
16
+ )
17
+ throw new TypeError(
18
+ 'Section points must pair start, center or end for the section and viewport.',
19
+ )
20
+ }
21
+ /** Renderer geometry only; Jolt owns interpolation, scheduling and reduced motion. */
22
+ export function sectionScrollRange(
23
+ top: number,
24
+ height: number,
25
+ viewport: number,
26
+ maximum: number,
27
+ options: SectionScrollOptions,
28
+ ) {
29
+ validateSectionScroll(options)
30
+ if (
31
+ ![top, height, viewport, maximum].every(Number.isFinite) ||
32
+ height < 0 ||
33
+ viewport < 0 ||
34
+ maximum < 0
35
+ )
36
+ throw new RangeError('Section geometry must be finite.')
37
+ const position = ([section, screen]: readonly [ScrollEdge, ScrollEdge]) =>
38
+ top + height * edge[section] - viewport * edge[screen]
39
+ const start = position(options.start ?? ['start', 'end'])
40
+ const end = position(options.end ?? ['end', 'start'])
41
+ if (end < start) throw new RangeError('Section end must follow its start.')
42
+ const clamp = (value: number) => Math.max(0, Math.min(maximum, value))
43
+ const range = [clamp(start), clamp(end)] as const
44
+ // A section with no traversable range settles; never divide by zero or add a clock.
45
+ return { range: range[1] > range[0] ? range : ([0, 1] as const), settled: range[1] <= range[0] }
46
+ }
package/src/time.ts ADDED
@@ -0,0 +1,83 @@
1
+ /** A wall-clock time, independent of date, timezone and daylight-saving transitions. */
2
+ export type LocalTime = string
3
+ export type TimeLocale = 'en-US' | 'pt-BR'
4
+ export type HourCycle = 'h12' | 'h23'
5
+ export interface TimeOptions {
6
+ locale?: TimeLocale
7
+ hourCycle?: HourCycle
8
+ min?: LocalTime
9
+ max?: LocalTime
10
+ minuteStep?: number
11
+ }
12
+ export type TimeValidation =
13
+ | { status: 'empty'; value: null }
14
+ | { status: 'valid'; value: LocalTime }
15
+ | { status: 'incomplete' | 'invalid' | 'range' | 'step'; value: null }
16
+
17
+ export function timeMinutes(value: LocalTime): number {
18
+ if (!/^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value))
19
+ throw new RangeError('Time must use HH:mm between 00:00 and 23:59.')
20
+ return Number(value.slice(0, 2)) * 60 + Number(value.slice(3))
21
+ }
22
+ export function localTime(minutes: number): LocalTime {
23
+ if (!Number.isInteger(minutes) || minutes < 0 || minutes >= 1440)
24
+ throw new RangeError('Time requires an integer minute within one day.')
25
+ return `${String(Math.floor(minutes / 60)).padStart(2, '0')}:${String(minutes % 60).padStart(2, '0')}`
26
+ }
27
+ export function timeOptions(options: TimeOptions = {}) {
28
+ const min = options.min === undefined ? 0 : timeMinutes(options.min)
29
+ const max = options.max === undefined ? 1439 : timeMinutes(options.max)
30
+ const step = options.minuteStep ?? 1
31
+ if (min > max)
32
+ throw new RangeError('Time min must not exceed max; overnight ranges are not supported.')
33
+ if (!Number.isInteger(step) || step < 1 || step > 30 || 60 % step)
34
+ throw new RangeError('minuteStep must be a divisor of 60 between 1 and 30.')
35
+ if (Math.ceil(min / step) * step > max)
36
+ throw new RangeError('Time bounds contain no selectable time.')
37
+ const locale = options.locale ?? 'en-US'
38
+ const cycle = options.hourCycle ?? (locale === 'pt-BR' ? 'h23' : 'h12')
39
+ if (!['en-US', 'pt-BR'].includes(locale) || !['h12', 'h23'].includes(cycle))
40
+ throw new RangeError('Unsupported time locale or hour cycle.')
41
+ return { min, max, step, cycle }
42
+ }
43
+ export function validateTime(value: LocalTime | null, options: TimeOptions = {}): TimeValidation {
44
+ const { min, max, step } = timeOptions(options)
45
+ if (value === null) return { status: 'empty', value: null }
46
+ let minutes: number
47
+ try {
48
+ minutes = timeMinutes(value)
49
+ } catch {
50
+ return { status: 'invalid', value: null }
51
+ }
52
+ if (minutes < min || minutes > max) return { status: 'range', value: null }
53
+ if (minutes % step) return { status: 'step', value: null }
54
+ return { status: 'valid', value }
55
+ }
56
+ /** Deterministic during SSR and on native runtimes without Intl. Never constructs a Date. */
57
+ export function formatTime(value: LocalTime | null, options: TimeOptions = {}): string {
58
+ const { cycle } = timeOptions(options)
59
+ if (value === null) return ''
60
+ const minutes = timeMinutes(value)
61
+ if (cycle === 'h23') return value
62
+ const hour = Math.floor(minutes / 60)
63
+ return `${hour % 12 || 12}:${value.slice(3)} ${hour < 12 ? 'AM' : 'PM'}`
64
+ }
65
+ export function parseTime(draft: string, options: TimeOptions = {}): TimeValidation {
66
+ const { cycle } = timeOptions(options)
67
+ const text = draft.trim()
68
+ if (!text) return { status: 'empty', value: null }
69
+ const match =
70
+ cycle === 'h23' ? /^(\d{1,2}):(\d{2})$/.exec(text) : /^(\d{1,2}):(\d{2})\s*(AM|PM)$/i.exec(text)
71
+ if (!match)
72
+ return {
73
+ status: /^\d{0,2}(?::\d{0,2})?\s*[apm]{0,2}$/i.test(text) ? 'incomplete' : 'invalid',
74
+ value: null,
75
+ }
76
+ let hour = Number(match[1])
77
+ if (Number(match[2]) > 59) return { status: 'invalid', value: null }
78
+ if (cycle === 'h12') {
79
+ if (hour < 1 || hour > 12) return { status: 'invalid', value: null }
80
+ hour = (hour % 12) + (match[3]!.toUpperCase() === 'PM' ? 12 : 0)
81
+ } else if (hour > 23) return { status: 'invalid', value: null }
82
+ return validateTime(localTime(hour * 60 + Number(match[2])), options)
83
+ }
@@ -0,0 +1,72 @@
1
+ import {
2
+ defineComponent,
3
+ h,
4
+ markRaw,
5
+ mergeProps,
6
+ onScopeDispose,
7
+ watch,
8
+ type Component,
9
+ } from '@vue/runtime-core'
10
+ import { createMotionSurface, type MotionPlayback } from '../experimental.js'
11
+ import { animatedTextProps } from './screen-component-props.js'
12
+
13
+ export function createAnimatedText(Text: Component) {
14
+ return defineComponent({
15
+ name: 'MAnimatedText',
16
+ inheritAttrs: false,
17
+ props: animatedTextProps,
18
+ setup(props, { attrs, expose }) {
19
+ const surface = markRaw(createMotionSurface())
20
+ let playback: MotionPlayback | undefined
21
+ const validate = () => {
22
+ if (
23
+ !Number.isFinite(props.duration) ||
24
+ props.duration <= 0 ||
25
+ !Number.isFinite(props.stagger) ||
26
+ props.stagger < 0 ||
27
+ !Number.isFinite(props.distance) ||
28
+ !['word', 'letter'].includes(props.by)
29
+ )
30
+ throw new RangeError(
31
+ 'MAnimatedText requires a positive duration, nonnegative stagger and finite distance.',
32
+ )
33
+ }
34
+ function play() {
35
+ validate()
36
+ playback?.stop()
37
+ if (surface.available && props.animated && props.text)
38
+ playback = surface.animateText({
39
+ by: props.by,
40
+ duration: props.duration,
41
+ stagger: props.stagger,
42
+ y: props.distance,
43
+ })
44
+ }
45
+ onScopeDispose(
46
+ surface.use(() => {
47
+ if (props.appear) play()
48
+ return () => {
49
+ playback?.stop()
50
+ playback = undefined
51
+ }
52
+ }),
53
+ )
54
+ watch(() => [props.text, props.replayKey, props.by, props.animated], play, { flush: 'post' })
55
+ onScopeDispose(() => playback?.stop())
56
+ expose({ replay: play })
57
+ return () => {
58
+ validate()
59
+ return h(
60
+ Text,
61
+ mergeProps(attrs, {
62
+ id: props.id,
63
+ text: props.text,
64
+ variant: props.variant,
65
+ tone: props.tone,
66
+ motionSurface: surface,
67
+ }),
68
+ )
69
+ }
70
+ },
71
+ })
72
+ }
@@ -0,0 +1,198 @@
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 { componentMotion } from '../motion.js'
16
+ import { createMotionSurface } from '../experimental.js'
17
+ import { carouselProps } from './discovery-props.js'
18
+ import { useMavisTheme } from './theme.js'
19
+
20
+ export function createCarousel(
21
+ ui: {
22
+ Column: Component
23
+ Row: Component
24
+ Box: Component
25
+ Text: Component
26
+ Button: Component
27
+ gestures: (
28
+ move: (direction: number) => void,
29
+ direction: { value: number },
30
+ ) => Record<string, unknown>
31
+ },
32
+ platform: 'web' | 'native',
33
+ ) {
34
+ return defineComponent({
35
+ name: 'MCarousel',
36
+ inheritAttrs: false,
37
+ props: carouselProps,
38
+ emits: { 'update:modelValue': (_value: ChoiceValue) => true },
39
+ setup(props, { attrs, slots, emit }) {
40
+ const { theme } = useMavisTheme()
41
+ const keys = computed(() => collectionKeys(props.items, props.itemKey))
42
+ const index = computed(() =>
43
+ Math.max(
44
+ 0,
45
+ keys.value.findIndex((key) => key === props.modelValue),
46
+ ),
47
+ )
48
+ const direction = ref(1)
49
+ const surface = markRaw(createMotionSurface())
50
+ const readingDirection = ref(1)
51
+ let first = true
52
+ onScopeDispose(
53
+ surface.use((motion) => {
54
+ if (!first)
55
+ motion.animate(
56
+ { x: [direction.value * readingDirection.value * 48, 0], opacity: [0.7, 1] },
57
+ componentMotion(theme.value, 'layout'),
58
+ )
59
+ first = false
60
+ const drag = motion.drag({
61
+ axis: 'x',
62
+ snap: { x: [0] },
63
+ onRelease: ({ x, velocityX }) => {
64
+ if (props.disabled) return
65
+ const projected = x + velocityX * 0.12
66
+ if (Math.abs(x) >= 40 || (Math.abs(x) >= 8 && Math.abs(projected) >= 60))
67
+ move((projected < 0 ? 1 : -1) * readingDirection.value)
68
+ },
69
+ })
70
+ const stop = watch(
71
+ () => props.disabled || keys.value.length < 2,
72
+ (disabled) => {
73
+ if (disabled) {
74
+ drag.cancel()
75
+ drag.pause()
76
+ motion.set({ x: 0 })
77
+ } else drag.resume()
78
+ },
79
+ { immediate: true },
80
+ )
81
+ return stop
82
+ }),
83
+ )
84
+ function choose(next: number) {
85
+ if (props.disabled || next === index.value || !keys.value.length) return
86
+ direction.value = next > index.value ? 1 : -1
87
+ emit('update:modelValue', keys.value[next]!)
88
+ }
89
+ function move(amount: number) {
90
+ const count = keys.value.length
91
+ if (!count) return
92
+ const next = props.loop
93
+ ? (index.value + amount + count) % count
94
+ : Math.max(0, Math.min(count - 1, index.value + amount))
95
+ choose(next)
96
+ }
97
+ watch(index, (next, previous) => {
98
+ direction.value = next > previous ? 1 : -1
99
+ })
100
+ const gestures = ui.gestures(move, readingDirection)
101
+ return () =>
102
+ h(
103
+ ui.Column,
104
+ mergeProps(
105
+ { id: props.id, gap: 'md' },
106
+ attrs,
107
+ platform === 'web'
108
+ ? {
109
+ class: 'm-carousel',
110
+ role: 'region',
111
+ 'aria-roledescription': 'carousel',
112
+ 'aria-label': props.label,
113
+ }
114
+ : {},
115
+ ),
116
+ () => [
117
+ h(ui.Row, { justify: 'between', gap: 'md', wrap: true }, () => [
118
+ h(ui.Text, { as: 'h2', text: props.label, variant: 'heading' }),
119
+ h(ui.Text, {
120
+ text: keys.value.length ? `${index.value + 1} / ${keys.value.length}` : '0 / 0',
121
+ tone: 'muted',
122
+ variant: 'caption',
123
+ ...(platform === 'web'
124
+ ? { role: 'status', 'aria-live': 'polite', 'aria-atomic': 'true' }
125
+ : { accessibilityLiveRegion: 'polite' }),
126
+ }),
127
+ ]),
128
+ keys.value.length
129
+ ? h(
130
+ ui.Box,
131
+ mergeProps(
132
+ { radius: 'lg' },
133
+ gestures,
134
+ platform === 'web' ? { style: { overflow: 'clip', touchAction: 'pan-y' } } : {},
135
+ ),
136
+ () =>
137
+ h(
138
+ ui.Box,
139
+ {
140
+ key: choiceKey(keys.value[index.value]!),
141
+ motionSurface: surface,
142
+ ...(platform === 'web'
143
+ ? {
144
+ role: 'group',
145
+ 'aria-roledescription': 'slide',
146
+ 'aria-label': `${props.slideLabel} ${index.value + 1} / ${keys.value.length}`,
147
+ }
148
+ : {}),
149
+ },
150
+ () =>
151
+ slots.default?.({
152
+ item: props.items[index.value],
153
+ index: index.value,
154
+ itemKey: keys.value[index.value],
155
+ }),
156
+ ),
157
+ )
158
+ : (slots.empty?.() ?? h(ui.Text, { text: props.emptyLabel, tone: 'muted' })),
159
+ h(ui.Row, { justify: 'between', gap: 'sm' }, () => [
160
+ h(ui.Button, {
161
+ icon: 'arrow-left',
162
+ variant: 'secondary',
163
+ accessibilityLabel: props.previousLabel,
164
+ disabled:
165
+ props.disabled || keys.value.length < 2 || (!props.loop && index.value === 0),
166
+ onClick: () => move(-1),
167
+ }),
168
+ h(ui.Row, { gap: 'xs', wrap: true, justify: 'center', shrink: 1 }, () =>
169
+ keys.value.map((key, n) =>
170
+ h(ui.Button, {
171
+ key: choiceKey(key),
172
+ text: String(n + 1),
173
+ variant: n === index.value ? 'primary' : 'ghost',
174
+ accessibilityLabel: `${props.slideLabel} ${n + 1}`,
175
+ disabled: props.disabled,
176
+ ...(platform === 'web'
177
+ ? { 'aria-current': n === index.value ? 'true' : undefined }
178
+ : {}),
179
+ onClick: () => choose(n),
180
+ }),
181
+ ),
182
+ ),
183
+ h(ui.Button, {
184
+ icon: 'arrow-right',
185
+ variant: 'secondary',
186
+ accessibilityLabel: props.nextLabel,
187
+ disabled:
188
+ props.disabled ||
189
+ keys.value.length < 2 ||
190
+ (!props.loop && index.value === keys.value.length - 1),
191
+ onClick: () => move(1),
192
+ }),
193
+ ]),
194
+ ],
195
+ )
196
+ },
197
+ }) as unknown as CarouselComponent
198
+ }