@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.
- package/README.md +2 -2
- package/dist/capabilities.d.ts +7 -7
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +48 -4
- package/dist/capabilities.js.map +1 -1
- package/dist/chart.d.ts +43 -0
- package/dist/chart.d.ts.map +1 -0
- package/dist/chart.js +105 -0
- package/dist/chart.js.map +1 -0
- package/dist/collections.d.ts +46 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +48 -0
- package/dist/collections.js.map +1 -0
- package/dist/contracts.d.ts +20 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +2 -0
- package/dist/contracts.js.map +1 -1
- package/dist/creative-controls.d.ts +47 -0
- package/dist/creative-controls.d.ts.map +1 -0
- package/dist/creative-controls.js +112 -0
- package/dist/creative-controls.js.map +1 -0
- package/dist/dashboard.d.ts +72 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +115 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/discovery.d.ts +49 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +80 -0
- package/dist/discovery.js.map +1 -0
- package/dist/experimental-regions.d.ts +10 -0
- package/dist/experimental-regions.d.ts.map +1 -1
- package/dist/experimental-regions.js +23 -0
- package/dist/experimental-regions.js.map +1 -1
- package/dist/experimental.d.ts +5 -0
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +29 -0
- package/dist/experimental.js.map +1 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/interactive.d.ts +36 -0
- package/dist/interactive.d.ts.map +1 -0
- package/dist/interactive.js +61 -0
- package/dist/interactive.js.map +1 -0
- package/dist/link.d.ts +2 -0
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js.map +1 -1
- package/dist/motion.d.ts +8 -0
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +11 -0
- package/dist/motion.js.map +1 -1
- package/dist/navigation-transition.d.ts +10 -0
- package/dist/navigation-transition.d.ts.map +1 -0
- package/dist/navigation-transition.js +10 -0
- package/dist/navigation-transition.js.map +1 -0
- package/dist/number-flow-format.d.ts +16 -0
- package/dist/number-flow-format.d.ts.map +1 -0
- package/dist/number-flow-format.js +49 -0
- package/dist/number-flow-format.js.map +1 -0
- package/dist/popover.d.ts +17 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/popover.js +19 -0
- package/dist/popover.js.map +1 -0
- package/dist/screen-components.d.ts +45 -0
- package/dist/screen-components.d.ts.map +1 -0
- package/dist/screen-components.js +23 -0
- package/dist/screen-components.js.map +1 -0
- package/dist/section-scroll.d.ts +14 -0
- package/dist/section-scroll.d.ts.map +1 -0
- package/dist/section-scroll.js +28 -0
- package/dist/section-scroll.js.map +1 -0
- package/dist/time.d.ts +34 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +78 -0
- package/dist/time.js.map +1 -0
- package/dist/vue/animated-text.d.ts +101 -0
- package/dist/vue/animated-text.d.ts.map +1 -0
- package/dist/vue/animated-text.js +56 -0
- package/dist/vue/animated-text.js.map +1 -0
- package/dist/vue/carousel.d.ts +13 -0
- package/dist/vue/carousel.d.ts.map +1 -0
- package/dist/vue/carousel.js +136 -0
- package/dist/vue/carousel.js.map +1 -0
- package/dist/vue/chart.d.ts +194 -0
- package/dist/vue/chart.d.ts.map +1 -0
- package/dist/vue/chart.js +245 -0
- package/dist/vue/chart.js.map +1 -0
- package/dist/vue/command-palette.d.ts +129 -0
- package/dist/vue/command-palette.d.ts.map +1 -0
- package/dist/vue/command-palette.js +190 -0
- package/dist/vue/command-palette.js.map +1 -0
- package/dist/vue/component-motion.d.ts +17 -0
- package/dist/vue/component-motion.d.ts.map +1 -0
- package/dist/vue/component-motion.js +83 -0
- package/dist/vue/component-motion.js.map +1 -0
- package/dist/vue/component-props.d.ts +1708 -21
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/component-props.js +50 -0
- package/dist/vue/component-props.js.map +1 -1
- package/dist/vue/composer.d.ts +159 -0
- package/dist/vue/composer.d.ts.map +1 -0
- package/dist/vue/composer.js +142 -0
- package/dist/vue/composer.js.map +1 -0
- package/dist/vue/configurator.d.ts +2 -2
- package/dist/vue/configurator.d.ts.map +1 -1
- package/dist/vue/configurator.js +3 -1
- package/dist/vue/configurator.js.map +1 -1
- package/dist/vue/creative-controls.d.ts +328 -0
- package/dist/vue/creative-controls.d.ts.map +1 -0
- package/dist/vue/creative-controls.js +396 -0
- package/dist/vue/creative-controls.js.map +1 -0
- package/dist/vue/creative-props.d.ts +260 -0
- package/dist/vue/creative-props.d.ts.map +1 -0
- package/dist/vue/creative-props.js +92 -0
- package/dist/vue/creative-props.js.map +1 -0
- package/dist/vue/dashboard-charts.d.ts +240 -0
- package/dist/vue/dashboard-charts.d.ts.map +1 -0
- package/dist/vue/dashboard-charts.js +263 -0
- package/dist/vue/dashboard-charts.js.map +1 -0
- package/dist/vue/dashboard-effects.d.ts +211 -0
- package/dist/vue/dashboard-effects.d.ts.map +1 -0
- package/dist/vue/dashboard-effects.js +235 -0
- package/dist/vue/dashboard-effects.js.map +1 -0
- package/dist/vue/dashboard-props.d.ts +244 -0
- package/dist/vue/dashboard-props.d.ts.map +1 -0
- package/dist/vue/dashboard-props.js +94 -0
- package/dist/vue/dashboard-props.js.map +1 -0
- package/dist/vue/data-table.d.ts +17 -0
- package/dist/vue/data-table.d.ts.map +1 -0
- package/dist/vue/data-table.js +133 -0
- package/dist/vue/data-table.js.map +1 -0
- package/dist/vue/date-calendar.d.ts +2 -0
- package/dist/vue/date-calendar.d.ts.map +1 -1
- package/dist/vue/date-calendar.js +20 -1
- package/dist/vue/date-calendar.js.map +1 -1
- package/dist/vue/date-picker.d.ts +8 -8
- package/dist/vue/date-props.d.ts +6 -0
- package/dist/vue/date-props.d.ts.map +1 -1
- package/dist/vue/date-props.js +3 -0
- package/dist/vue/date-props.js.map +1 -1
- package/dist/vue/discovery-components.d.ts +50 -0
- package/dist/vue/discovery-components.d.ts.map +1 -0
- package/dist/vue/discovery-components.js +2 -0
- package/dist/vue/discovery-components.js.map +1 -0
- package/dist/vue/discovery-controls.d.ts +197 -0
- package/dist/vue/discovery-controls.d.ts.map +1 -0
- package/dist/vue/discovery-controls.js +185 -0
- package/dist/vue/discovery-controls.js.map +1 -0
- package/dist/vue/discovery-props.d.ts +249 -0
- package/dist/vue/discovery-props.d.ts.map +1 -0
- package/dist/vue/discovery-props.js +87 -0
- package/dist/vue/discovery-props.js.map +1 -0
- package/dist/vue/global-components.d.ts +237 -0
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +41 -0
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +37 -0
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/interactive-components.d.ts +31 -0
- package/dist/vue/interactive-components.d.ts.map +1 -0
- package/dist/vue/interactive-components.js +2 -0
- package/dist/vue/interactive-components.js.map +1 -0
- package/dist/vue/interactive-props.d.ts +254 -0
- package/dist/vue/interactive-props.d.ts.map +1 -0
- package/dist/vue/interactive-props.js +85 -0
- package/dist/vue/interactive-props.js.map +1 -0
- package/dist/vue/kanban.d.ts +150 -0
- package/dist/vue/kanban.d.ts.map +1 -0
- package/dist/vue/kanban.js +267 -0
- package/dist/vue/kanban.js.map +1 -0
- package/dist/vue/list-motion.d.ts +7 -0
- package/dist/vue/list-motion.d.ts.map +1 -0
- package/dist/vue/list-motion.js +28 -0
- package/dist/vue/list-motion.js.map +1 -0
- package/dist/vue/marquee.d.ts +96 -0
- package/dist/vue/marquee.d.ts.map +1 -0
- package/dist/vue/marquee.js +186 -0
- package/dist/vue/marquee.js.map +1 -0
- package/dist/vue/menu.d.ts +122 -0
- package/dist/vue/menu.d.ts.map +1 -0
- package/dist/vue/menu.js +79 -0
- package/dist/vue/menu.js.map +1 -0
- package/dist/vue/navigation-controls.d.ts +125 -0
- package/dist/vue/navigation-controls.d.ts.map +1 -0
- package/dist/vue/navigation-controls.js +130 -0
- package/dist/vue/navigation-controls.js.map +1 -0
- package/dist/vue/navigation-props.d.ts +283 -0
- package/dist/vue/navigation-props.d.ts.map +1 -0
- package/dist/vue/navigation-props.js +82 -0
- package/dist/vue/navigation-props.js.map +1 -0
- package/dist/vue/number-flow.d.ts +75 -0
- package/dist/vue/number-flow.d.ts.map +1 -0
- package/dist/vue/number-flow.js +57 -0
- package/dist/vue/number-flow.js.map +1 -0
- package/dist/vue/partition.d.ts +15 -0
- package/dist/vue/partition.d.ts.map +1 -0
- package/dist/vue/partition.js +42 -0
- package/dist/vue/partition.js.map +1 -0
- package/dist/vue/pin-cell.d.ts +14 -0
- package/dist/vue/pin-cell.d.ts.map +1 -0
- package/dist/vue/pin-cell.js +19 -0
- package/dist/vue/pin-cell.js.map +1 -0
- package/dist/vue/pin-input.d.ts +14 -0
- package/dist/vue/pin-input.d.ts.map +1 -0
- package/dist/vue/pin-input.js +23 -0
- package/dist/vue/pin-input.js.map +1 -0
- package/dist/vue/platform.d.ts +37 -0
- package/dist/vue/platform.d.ts.map +1 -0
- package/dist/vue/platform.js +46 -0
- package/dist/vue/platform.js.map +1 -0
- package/dist/vue/props.d.ts +82 -42
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +3 -1
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/screen-component-props.d.ts +236 -0
- package/dist/vue/screen-component-props.d.ts.map +1 -0
- package/dist/vue/screen-component-props.js +90 -0
- package/dist/vue/screen-component-props.js.map +1 -0
- package/dist/vue/scroll-frame.d.ts +223 -0
- package/dist/vue/scroll-frame.d.ts.map +1 -0
- package/dist/vue/scroll-frame.js +346 -0
- package/dist/vue/scroll-frame.js.map +1 -0
- package/dist/vue/sortable-list.d.ts +24 -0
- package/dist/vue/sortable-list.d.ts.map +1 -0
- package/dist/vue/sortable-list.js +251 -0
- package/dist/vue/sortable-list.js.map +1 -0
- package/dist/vue/speed-dial.d.ts +73 -0
- package/dist/vue/speed-dial.d.ts.map +1 -0
- package/dist/vue/speed-dial.js +78 -0
- package/dist/vue/speed-dial.js.map +1 -0
- package/dist/vue/swipe-actions.d.ts +96 -0
- package/dist/vue/swipe-actions.d.ts.map +1 -0
- package/dist/vue/swipe-actions.js +174 -0
- package/dist/vue/swipe-actions.js.map +1 -0
- package/dist/vue/swipe-deck.d.ts +120 -0
- package/dist/vue/swipe-deck.d.ts.map +1 -0
- package/dist/vue/swipe-deck.js +229 -0
- package/dist/vue/swipe-deck.js.map +1 -0
- package/dist/vue/time-picker.d.ts +488 -0
- package/dist/vue/time-picker.d.ts.map +1 -0
- package/dist/vue/time-picker.js +190 -0
- package/dist/vue/time-picker.js.map +1 -0
- package/dist/vue/tour.d.ts +120 -0
- package/dist/vue/tour.d.ts.map +1 -0
- package/dist/vue/tour.js +165 -0
- package/dist/vue/tour.js.map +1 -0
- package/dist/vue/tree-view.d.ts +111 -0
- package/dist/vue/tree-view.d.ts.map +1 -0
- package/dist/vue/tree-view.js +204 -0
- package/dist/vue/tree-view.js.map +1 -0
- package/dist/vue/virtual-list.d.ts +26 -0
- package/dist/vue/virtual-list.d.ts.map +1 -0
- package/dist/vue/virtual-list.js +2 -0
- package/dist/vue/virtual-list.js.map +1 -0
- package/dist/vue/wayfinding-controls.d.ts +199 -0
- package/dist/vue/wayfinding-controls.d.ts.map +1 -0
- package/dist/vue/wayfinding-controls.js +330 -0
- package/dist/vue/wayfinding-controls.js.map +1 -0
- package/dist/vue/wayfinding-props.d.ts +221 -0
- package/dist/vue/wayfinding-props.d.ts.map +1 -0
- package/dist/vue/wayfinding-props.js +86 -0
- package/dist/vue/wayfinding-props.js.map +1 -0
- package/dist/vue/workflows.d.ts +2 -2
- package/dist/vue/workflows.d.ts.map +1 -1
- package/dist/vue/workflows.js +17 -4
- package/dist/vue/workflows.js.map +1 -1
- package/dist/wayfinding.d.ts +50 -0
- package/dist/wayfinding.d.ts.map +1 -0
- package/dist/wayfinding.js +54 -0
- package/dist/wayfinding.js.map +1 -0
- package/package.json +2 -2
- package/src/capabilities.ts +50 -4
- package/src/chart.ts +151 -0
- package/src/collections.ts +87 -0
- package/src/contracts.ts +2 -0
- package/src/creative-controls.ts +169 -0
- package/src/dashboard.ts +164 -0
- package/src/discovery.ts +139 -0
- package/src/experimental-regions.ts +29 -0
- package/src/experimental.ts +40 -0
- package/src/index.ts +23 -1
- package/src/interactive.ts +91 -0
- package/src/link.ts +2 -0
- package/src/motion.ts +14 -0
- package/src/navigation-transition.ts +14 -0
- package/src/number-flow-format.ts +68 -0
- package/src/popover.ts +38 -0
- package/src/screen-components.ts +59 -0
- package/src/section-scroll.ts +46 -0
- package/src/time.ts +83 -0
- package/src/vue/animated-text.ts +72 -0
- package/src/vue/carousel.ts +198 -0
- package/src/vue/chart.ts +337 -0
- package/src/vue/command-palette.ts +235 -0
- package/src/vue/component-motion.ts +109 -0
- package/src/vue/component-props.ts +104 -0
- package/src/vue/composer.ts +192 -0
- package/src/vue/configurator.ts +3 -1
- package/src/vue/creative-controls.ts +524 -0
- package/src/vue/creative-props.ts +94 -0
- package/src/vue/dashboard-charts.ts +346 -0
- package/src/vue/dashboard-effects.ts +304 -0
- package/src/vue/dashboard-props.ts +95 -0
- package/src/vue/data-table.ts +190 -0
- package/src/vue/date-calendar.ts +30 -1
- package/src/vue/date-props.ts +3 -0
- package/src/vue/discovery-components.ts +60 -0
- package/src/vue/discovery-controls.ts +241 -0
- package/src/vue/discovery-props.ts +92 -0
- package/src/vue/global-components.ts +237 -0
- package/src/vue/index.ts +64 -0
- package/src/vue/interactive-components.ts +29 -0
- package/src/vue/interactive-props.ts +90 -0
- package/src/vue/kanban.ts +360 -0
- package/src/vue/list-motion.ts +31 -0
- package/src/vue/marquee.ts +248 -0
- package/src/vue/menu.ts +100 -0
- package/src/vue/navigation-controls.ts +159 -0
- package/src/vue/navigation-props.ts +87 -0
- package/src/vue/number-flow.ts +83 -0
- package/src/vue/partition.ts +49 -0
- package/src/vue/pin-cell.ts +26 -0
- package/src/vue/pin-input.ts +31 -0
- package/src/vue/platform.ts +73 -0
- package/src/vue/props.ts +3 -1
- package/src/vue/screen-component-props.ts +92 -0
- package/src/vue/scroll-frame.ts +429 -0
- package/src/vue/sortable-list.ts +308 -0
- package/src/vue/speed-dial.ts +108 -0
- package/src/vue/swipe-actions.ts +226 -0
- package/src/vue/swipe-deck.ts +277 -0
- package/src/vue/time-picker.ts +227 -0
- package/src/vue/tour.ts +239 -0
- package/src/vue/tree-view.ts +259 -0
- package/src/vue/virtual-list.ts +28 -0
- package/src/vue/wayfinding-controls.ts +430 -0
- package/src/vue/wayfinding-props.ts +97 -0
- package/src/vue/workflows.ts +17 -4
- 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
|
+
}
|