@getcortexlabs/mavis-core 0.1.0-alpha.5 → 0.1.0-alpha.6
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/dist/app-icons.d.ts +27 -0
- package/dist/app-icons.d.ts.map +1 -0
- package/dist/app-icons.js +42 -0
- package/dist/app-icons.js.map +1 -0
- package/dist/capabilities.d.ts +7 -7
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +6 -4
- package/dist/capabilities.js.map +1 -1
- package/dist/contracts.d.ts +61 -1
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +8 -1
- package/dist/contracts.js.map +1 -1
- package/dist/experimental-playback.d.ts +63 -0
- package/dist/experimental-playback.d.ts.map +1 -0
- package/dist/experimental-playback.js +46 -0
- package/dist/experimental-playback.js.map +1 -0
- package/dist/experimental-regions.d.ts +12 -0
- package/dist/experimental-regions.d.ts.map +1 -1
- package/dist/experimental-regions.js +125 -0
- package/dist/experimental-regions.js.map +1 -1
- package/dist/experimental.d.ts +29 -2
- package/dist/experimental.d.ts.map +1 -1
- package/dist/experimental.js +47 -7
- package/dist/experimental.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/link.d.ts +12 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +19 -0
- package/dist/link.js.map +1 -0
- package/dist/motion.d.ts +29 -4
- package/dist/motion.d.ts.map +1 -1
- package/dist/motion.js +55 -3
- package/dist/motion.js.map +1 -1
- package/dist/responsive.d.ts +18 -0
- package/dist/responsive.d.ts.map +1 -0
- package/dist/responsive.js +35 -0
- package/dist/responsive.js.map +1 -0
- package/dist/theme/themes.js +3 -3
- package/dist/theme/themes.js.map +1 -1
- package/dist/theme/types.d.ts +12 -3
- package/dist/theme/types.d.ts.map +1 -1
- package/dist/vue/component-props.d.ts +187 -0
- package/dist/vue/component-props.d.ts.map +1 -1
- package/dist/vue/contracts.d.ts.map +1 -1
- package/dist/vue/contracts.js +7 -1
- package/dist/vue/contracts.js.map +1 -1
- package/dist/vue/date-picker.d.ts +42 -4
- package/dist/vue/date-picker.d.ts.map +1 -1
- package/dist/vue/date-picker.js +28 -6
- package/dist/vue/date-picker.js.map +1 -1
- package/dist/vue/date-props.d.ts +9 -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/global-components.d.ts +5 -0
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +4 -2
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +3 -2
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/layout-context.d.ts +4 -2
- package/dist/vue/layout-context.d.ts.map +1 -1
- package/dist/vue/layout-context.js +7 -2
- package/dist/vue/layout-context.js.map +1 -1
- package/dist/vue/props.d.ts +365 -0
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +25 -1
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/reveal-state.d.ts +18 -0
- package/dist/vue/reveal-state.d.ts.map +1 -0
- package/dist/vue/reveal-state.js +76 -0
- package/dist/vue/reveal-state.js.map +1 -0
- package/dist/vue/theme.d.ts +42 -0
- package/dist/vue/theme.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/app-icons.ts +57 -0
- package/src/capabilities.ts +6 -4
- package/src/contracts.ts +12 -2
- package/src/experimental-playback.ts +115 -0
- package/src/experimental-regions.ts +151 -0
- package/src/experimental.ts +81 -9
- package/src/index.ts +6 -1
- package/src/link.ts +28 -0
- package/src/motion.ts +61 -3
- package/src/responsive.ts +61 -0
- package/src/theme/themes.ts +3 -3
- package/src/theme/types.ts +13 -1
- package/src/vue/contracts.ts +7 -1
- package/src/vue/date-picker.ts +33 -6
- package/src/vue/date-props.ts +3 -0
- package/src/vue/global-components.ts +5 -1
- package/src/vue/index.ts +6 -1
- package/src/vue/layout-context.ts +10 -3
- package/src/vue/props.ts +27 -1
- package/src/vue/reveal-state.ts +83 -0
package/src/experimental.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
controlledMotionPlayback,
|
|
3
|
+
motionPlaybackAdapter,
|
|
4
|
+
type MotionControlledPlayback,
|
|
5
|
+
type MotionValueOptions,
|
|
6
|
+
type MotionDecayOptions,
|
|
7
|
+
} from './experimental-playback.js'
|
|
8
|
+
export * from './experimental-playback.js'
|
|
1
9
|
/** Experimental, single-surface motion contract. No platform objects cross this boundary. */
|
|
2
10
|
import {
|
|
3
11
|
regionState,
|
|
@@ -26,13 +34,24 @@ export interface MotionPlayback {
|
|
|
26
34
|
}
|
|
27
35
|
export interface MotionSurface {
|
|
28
36
|
readonly available: boolean
|
|
29
|
-
animate(values: MotionFrames, options?: MotionOptions):
|
|
37
|
+
animate(values: MotionFrames, options?: MotionOptions): MotionControlledPlayback
|
|
30
38
|
set(values: MotionValues): MotionPlayback
|
|
31
39
|
/** Runs once per mount/load. Its resources belong to that presentation. */
|
|
32
40
|
onAvailable(setup: () => void | (() => void)): () => void
|
|
33
41
|
/** A child owner, recreated on mount/load. Late work must use the supplied child. */
|
|
34
42
|
use(setup: (motion: MotionSurface) => void | (() => void)): () => void
|
|
35
43
|
pointerFollow(region: MotionRegion, options?: MotionPointerOptions): MotionPointer
|
|
44
|
+
animateValue(
|
|
45
|
+
value: MotionValue,
|
|
46
|
+
frames: number | readonly (number | null)[],
|
|
47
|
+
options?: MotionValueOptions,
|
|
48
|
+
): MotionControlledPlayback
|
|
49
|
+
stopValue(value: MotionValue, options?: { layer?: string }): void
|
|
50
|
+
playbackProgress(playback: MotionControlledPlayback): MotionReadable
|
|
51
|
+
decay(
|
|
52
|
+
velocity: { x?: number; y?: number },
|
|
53
|
+
options?: MotionDecayOptions,
|
|
54
|
+
): MotionControlledPlayback
|
|
36
55
|
motionValue(initial: number): MotionValue
|
|
37
56
|
springValue(source: MotionValue, options?: MotionSpringOptions): MotionSpring
|
|
38
57
|
bind(values: MotionBindings): MotionBinding
|
|
@@ -79,7 +98,9 @@ export type MotionBindings = Partial<Record<keyof MotionValues, MotionReadable>>
|
|
|
79
98
|
export interface MotionDragOptions {
|
|
80
99
|
axis: 'x' | 'y'
|
|
81
100
|
bounds?: { left?: number; right?: number; top?: number; bottom?: number }
|
|
82
|
-
snap
|
|
101
|
+
snap?: { x?: readonly number[]; y?: readonly number[] }
|
|
102
|
+
friction?: number
|
|
103
|
+
onRelease?: (event: { x: number; y: number; velocityX: number; velocityY: number }) => void
|
|
83
104
|
}
|
|
84
105
|
export interface MotionDrag extends MotionBinding {
|
|
85
106
|
readonly dragging: boolean
|
|
@@ -98,6 +119,14 @@ export interface MotionSurfaceAdapter {
|
|
|
98
119
|
pointerFollow?(region: MotionRegionAdapter, options: MotionPointerOptions): MotionPointerAdapter
|
|
99
120
|
animate(values: MotionFrames, options?: MotionOptions): MotionPlayback
|
|
100
121
|
set(values: MotionValues): MotionPlayback
|
|
122
|
+
animateValue?(
|
|
123
|
+
value: MotionValueAdapter,
|
|
124
|
+
frames: number | readonly (number | null)[],
|
|
125
|
+
options?: MotionValueOptions,
|
|
126
|
+
): MotionPlayback
|
|
127
|
+
stopValue?(value: MotionValueAdapter, options?: { layer?: string }): void
|
|
128
|
+
playbackProgress?(playback: MotionPlayback): Pick<MotionReadable, 'get' | 'dispose'>
|
|
129
|
+
decay?(velocity: { x?: number; y?: number }, options?: MotionDecayOptions): MotionPlayback
|
|
101
130
|
motionValue?(initial: number): MotionValueAdapter
|
|
102
131
|
springValue?(source: MotionValueAdapter, options?: MotionSpringOptions): MotionSpringAdapter
|
|
103
132
|
bind?(values: Partial<Record<keyof MotionValues, Pick<MotionReadable, 'get' | 'dispose'>>>): {
|
|
@@ -276,6 +305,7 @@ type ValueState = {
|
|
|
276
305
|
}
|
|
277
306
|
const values = new WeakMap<MotionReadable, ValueState>()
|
|
278
307
|
const dependencies = new WeakMap<Resource, Set<Set<Resource>>>()
|
|
308
|
+
const playbackOwners = new WeakMap<MotionPlayback, Binding>()
|
|
279
309
|
function depend(parent: ValueState, resource: Resource) {
|
|
280
310
|
parent.dependents.add(resource)
|
|
281
311
|
let groups = dependencies.get(resource)
|
|
@@ -390,17 +420,19 @@ export function createMotionSurface(): MotionSurface {
|
|
|
390
420
|
throw new TypeError('Use a live value from this surface and presentation.')
|
|
391
421
|
return state
|
|
392
422
|
}
|
|
393
|
-
const run = (
|
|
423
|
+
const run = (
|
|
424
|
+
invoke: (adapter: MotionSurfaceAdapter) => MotionPlayback,
|
|
425
|
+
): MotionControlledPlayback => {
|
|
394
426
|
const binding = current()
|
|
395
427
|
const playback = invoke(binding.adapter)
|
|
396
428
|
binding.active.add(playback)
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
finished: playback.finished,
|
|
400
|
-
stop() {
|
|
401
|
-
if (binding.valid) playback.stop()
|
|
402
|
-
},
|
|
429
|
+
const forget = () => {
|
|
430
|
+
binding.active.delete(playback)
|
|
403
431
|
}
|
|
432
|
+
void playback.finished.then(forget, forget)
|
|
433
|
+
const handle = controlledMotionPlayback(playback, () => binding.valid)
|
|
434
|
+
playbackOwners.set(handle, binding)
|
|
435
|
+
return handle
|
|
404
436
|
}
|
|
405
437
|
const surface: MotionSurface = {
|
|
406
438
|
get available() {
|
|
@@ -518,6 +550,46 @@ export function createMotionSurface(): MotionSurface {
|
|
|
518
550
|
cleanup = undefined
|
|
519
551
|
}
|
|
520
552
|
},
|
|
553
|
+
animateValue(value, frames, options) {
|
|
554
|
+
const binding = current()
|
|
555
|
+
const parent = source(value, binding, true)
|
|
556
|
+
if (!binding.adapter.animateValue) throw new Error('Scalar playback is unavailable.')
|
|
557
|
+
const handle = run((adapter) =>
|
|
558
|
+
adapter.animateValue!(parent.raw as MotionValueAdapter, frames, options),
|
|
559
|
+
)
|
|
560
|
+
const dependent = { dispose: () => handle.stop() }
|
|
561
|
+
depend(parent, dependent)
|
|
562
|
+
const forget = () => {
|
|
563
|
+
parent.dependents.delete(dependent)
|
|
564
|
+
dependencies.delete(dependent)
|
|
565
|
+
}
|
|
566
|
+
void handle.finished.then(forget, forget)
|
|
567
|
+
return handle
|
|
568
|
+
},
|
|
569
|
+
stopValue(value, options) {
|
|
570
|
+
const binding = current()
|
|
571
|
+
const parent = source(value, binding, true)
|
|
572
|
+
if (!binding.adapter.stopValue) throw new Error('Scalar playback is unavailable.')
|
|
573
|
+
binding.adapter.stopValue(parent.raw as MotionValueAdapter, options)
|
|
574
|
+
},
|
|
575
|
+
playbackProgress(playback) {
|
|
576
|
+
const binding = current()
|
|
577
|
+
const owner = playbackOwners.get(playback)
|
|
578
|
+
if (!owner?.valid || owner.context !== binding.context)
|
|
579
|
+
throw new TypeError('Use playback from this surface and presentation.')
|
|
580
|
+
if (!binding.adapter.playbackProgress) throw new Error('Playback progress is unavailable.')
|
|
581
|
+
return ownValue(
|
|
582
|
+
binding,
|
|
583
|
+
binding.adapter.playbackProgress(motionPlaybackAdapter(playback)),
|
|
584
|
+
false,
|
|
585
|
+
)
|
|
586
|
+
},
|
|
587
|
+
decay(velocity, options) {
|
|
588
|
+
return run((adapter) => {
|
|
589
|
+
if (!adapter.decay) throw new Error('Decay playback is unavailable.')
|
|
590
|
+
return adapter.decay(velocity, options)
|
|
591
|
+
})
|
|
592
|
+
},
|
|
521
593
|
motionValue(initial) {
|
|
522
594
|
const binding = current()
|
|
523
595
|
if (!binding.adapter.motionValue) throw new Error('Continuous motion is unavailable.')
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { defineTheme, mavis, midnight } from './theme/themes.js'
|
|
2
2
|
export { resolveSpace } from './theme/resolve.js'
|
|
3
|
-
export { pressMotion, revealMotion } from './motion.js'
|
|
3
|
+
export { pressMotion, revealMotion, motionRecipe } from './motion.js'
|
|
4
4
|
export type {
|
|
5
5
|
FontFamily,
|
|
6
|
+
MotionTheme,
|
|
7
|
+
MotionEase,
|
|
6
8
|
FontWeight,
|
|
7
9
|
Elevation,
|
|
8
10
|
Shadow,
|
|
@@ -83,3 +85,6 @@ export * from './combobox.js'
|
|
|
83
85
|
export * from './files.js'
|
|
84
86
|
export * from './form.js'
|
|
85
87
|
export * from './navigation.js'
|
|
88
|
+
export * from './link.js'
|
|
89
|
+
export * from './responsive.js'
|
|
90
|
+
export * from './app-icons.js'
|
package/src/link.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type LinkTarget = '_self' | '_blank'
|
|
2
|
+
export type LinkNavigate = (href: string) => void | Promise<unknown>
|
|
3
|
+
export interface NavigationOptions {
|
|
4
|
+
href?: string
|
|
5
|
+
navigate?: LinkNavigate
|
|
6
|
+
target?: LinkTarget
|
|
7
|
+
rel?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Navigation belongs to the host; the shared contract only validates its destination. */
|
|
11
|
+
export function linkDestination(href: string): string {
|
|
12
|
+
const value = href.trim()
|
|
13
|
+
if (!value || /[\u0000-\u001f\u007f]/.test(value))
|
|
14
|
+
throw new TypeError('MLink requires a nonempty destination without control characters.')
|
|
15
|
+
if (/^(?:javascript|data|vbscript):/i.test(value))
|
|
16
|
+
throw new TypeError('MLink does not accept executable destinations.')
|
|
17
|
+
return value
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function linkRel(target: LinkTarget, rel = ''): string | undefined {
|
|
21
|
+
const tokens = new Set(rel.split(/\s+/).filter(Boolean))
|
|
22
|
+
if (target === '_blank') {
|
|
23
|
+
tokens.delete('opener')
|
|
24
|
+
tokens.add('noopener')
|
|
25
|
+
tokens.add('noreferrer')
|
|
26
|
+
}
|
|
27
|
+
return [...tokens].join(' ') || undefined
|
|
28
|
+
}
|
package/src/motion.ts
CHANGED
|
@@ -8,15 +8,73 @@ export function resolvePressScale(scale: number): number {
|
|
|
8
8
|
|
|
9
9
|
// Recipes describe motion, not input or lifecycle. Adapters own reduced-motion detection:
|
|
10
10
|
// native follows Jolt configuration; Web follows prefers-reduced-motion. See guide/motion.
|
|
11
|
-
export function pressMotion(
|
|
11
|
+
export function pressMotion(value: number | Readonly<MotionTheme>) {
|
|
12
|
+
if (value === null || (typeof value !== 'number' && typeof value !== 'object'))
|
|
13
|
+
throw new RangeError('Press motion needs a valid scale or motion theme')
|
|
14
|
+
const motion = typeof value === 'number' ? { ...defaultMotion, pressScale: value } : value
|
|
15
|
+
validateMotion(motion)
|
|
12
16
|
return {
|
|
13
17
|
composition: 'multiply',
|
|
14
|
-
pressed: [
|
|
15
|
-
|
|
18
|
+
pressed: [
|
|
19
|
+
{ scale: motion.pressScale },
|
|
20
|
+
{ type: 'spring', duration: motion.pressDuration, bounce: 0 },
|
|
21
|
+
],
|
|
22
|
+
released: [
|
|
23
|
+
{ scale: 1 },
|
|
24
|
+
{ type: 'spring', duration: motion.releaseDuration, bounce: motion.releaseBounce },
|
|
25
|
+
],
|
|
16
26
|
} as const
|
|
17
27
|
}
|
|
18
28
|
|
|
29
|
+
/** Platform-neutral recipe. The host supplies the target and owns the Jolt playback. */
|
|
30
|
+
export function motionRecipe(theme: MavisTheme, name: 'enter' | 'exit') {
|
|
31
|
+
const motion = theme.motion
|
|
32
|
+
validateMotion(motion)
|
|
33
|
+
return name === 'enter'
|
|
34
|
+
? {
|
|
35
|
+
keyframes: { opacity: [0, 1], y: [motion.enterOffset, 0] },
|
|
36
|
+
transition: { type: 'tween' as const, duration: motion.enterDuration, ease: motion.ease },
|
|
37
|
+
}
|
|
38
|
+
: {
|
|
39
|
+
keyframes: { opacity: [1, 0] },
|
|
40
|
+
transition: { type: 'tween' as const, duration: motion.exitDuration, ease: motion.ease },
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
19
44
|
export const revealMotion = {
|
|
20
45
|
enter: [{ opacity: [0, 1], y: [8, 0] }, { duration: 180 }],
|
|
21
46
|
leave: [{ opacity: 0 }, { duration: 120 }],
|
|
22
47
|
} as const
|
|
48
|
+
import type { MotionTheme, MavisTheme } from './theme/types.js'
|
|
49
|
+
|
|
50
|
+
export const defaultMotion: Readonly<MotionTheme> = Object.freeze({
|
|
51
|
+
pressScale: 0.97,
|
|
52
|
+
pressDuration: 200,
|
|
53
|
+
releaseDuration: 450,
|
|
54
|
+
releaseBounce: 0.35,
|
|
55
|
+
enterDuration: 180,
|
|
56
|
+
exitDuration: 120,
|
|
57
|
+
enterOffset: 8,
|
|
58
|
+
ease: 'easeOut',
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
export function validateMotion(motion: Readonly<MotionTheme>) {
|
|
62
|
+
resolvePressScale(motion.pressScale)
|
|
63
|
+
for (const key of [
|
|
64
|
+
'pressDuration',
|
|
65
|
+
'releaseDuration',
|
|
66
|
+
'enterDuration',
|
|
67
|
+
'exitDuration',
|
|
68
|
+
'enterOffset',
|
|
69
|
+
] as const)
|
|
70
|
+
if (!Number.isFinite(motion[key]) || motion[key] < 0)
|
|
71
|
+
throw new RangeError(`${key} must be a finite nonnegative number`)
|
|
72
|
+
if (
|
|
73
|
+
!Number.isFinite(motion.releaseBounce) ||
|
|
74
|
+
motion.releaseBounce < 0 ||
|
|
75
|
+
motion.releaseBounce > 1
|
|
76
|
+
)
|
|
77
|
+
throw new RangeError('releaseBounce must be between 0 and 1')
|
|
78
|
+
if (!['linear', 'easeIn', 'easeOut', 'easeInOut'].includes(motion.ease))
|
|
79
|
+
throw new RangeError('Unknown motion easing')
|
|
80
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Spacing } from './theme/types.js'
|
|
2
|
+
|
|
3
|
+
export type StackDirection = 'row' | 'column'
|
|
4
|
+
export interface StackLayout {
|
|
5
|
+
direction?: StackDirection
|
|
6
|
+
gap?: Spacing
|
|
7
|
+
align?: 'start' | 'end' | 'center' | 'stretch'
|
|
8
|
+
justify?: 'start' | 'end' | 'center' | 'between' | 'around'
|
|
9
|
+
wrap?: boolean
|
|
10
|
+
}
|
|
11
|
+
export interface StackBreakpoint extends StackLayout {
|
|
12
|
+
/** Content width in CSS pixels on Web and DIPs on NativeScript. */
|
|
13
|
+
at: number
|
|
14
|
+
}
|
|
15
|
+
export type StackResponsive = StackBreakpoint | readonly StackBreakpoint[]
|
|
16
|
+
|
|
17
|
+
/** Sorted min-width overrides; the input order never changes the resulting layout. */
|
|
18
|
+
export function stackLayout(
|
|
19
|
+
base: StackLayout,
|
|
20
|
+
responsive: StackResponsive | undefined,
|
|
21
|
+
width?: number,
|
|
22
|
+
): StackLayout {
|
|
23
|
+
const points =
|
|
24
|
+
responsive === undefined
|
|
25
|
+
? []
|
|
26
|
+
: Array.isArray(responsive)
|
|
27
|
+
? [...responsive]
|
|
28
|
+
: [responsive as StackBreakpoint]
|
|
29
|
+
const seen = new Set<number>()
|
|
30
|
+
const result = { ...base }
|
|
31
|
+
for (const point of points.sort((a, b) => a.at - b.at)) {
|
|
32
|
+
if (!Number.isFinite(point.at) || point.at <= 0 || seen.has(point.at))
|
|
33
|
+
throw new RangeError('Stack breakpoints must be distinct positive content widths.')
|
|
34
|
+
seen.add(point.at)
|
|
35
|
+
if (point.direction !== undefined && !['row', 'column'].includes(point.direction))
|
|
36
|
+
throw new TypeError('Unknown responsive stack direction.')
|
|
37
|
+
if (point.align !== undefined && !['start', 'end', 'center', 'stretch'].includes(point.align))
|
|
38
|
+
throw new TypeError('Unknown responsive alignment.')
|
|
39
|
+
if (
|
|
40
|
+
point.justify !== undefined &&
|
|
41
|
+
!['start', 'end', 'center', 'between', 'around'].includes(point.justify)
|
|
42
|
+
)
|
|
43
|
+
throw new TypeError('Unknown responsive distribution.')
|
|
44
|
+
if (point.wrap !== undefined && typeof point.wrap !== 'boolean')
|
|
45
|
+
throw new TypeError('wrap must be boolean.')
|
|
46
|
+
if (width !== undefined && width >= point.at) {
|
|
47
|
+
const { at, ...override } = point
|
|
48
|
+
Object.assign(result, override)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function stackDirection(
|
|
55
|
+
base: StackDirection,
|
|
56
|
+
responsive: StackResponsive | undefined,
|
|
57
|
+
width?: number,
|
|
58
|
+
): StackDirection {
|
|
59
|
+
if (!['row', 'column'].includes(base)) throw new TypeError('Unknown stack direction.')
|
|
60
|
+
return stackLayout({ direction: base }, responsive, width).direction ?? base
|
|
61
|
+
}
|
package/src/theme/themes.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
validateShadow,
|
|
6
6
|
freezeFamily,
|
|
7
7
|
} from './typography.js'
|
|
8
|
-
import {
|
|
8
|
+
import { defaultMotion, validateMotion } from '../motion.js'
|
|
9
9
|
|
|
10
10
|
const foundation: MavisTheme = {
|
|
11
11
|
name: 'mavis',
|
|
@@ -89,7 +89,7 @@ const foundation: MavisTheme = {
|
|
|
89
89
|
input: { fontWeight: 'normal', lineHeight: 1.5, paddingX: 16, paddingY: 14, radius: 'md' },
|
|
90
90
|
card: { padding: 'lg', radius: 'lg', elevation: 'none' },
|
|
91
91
|
},
|
|
92
|
-
motion:
|
|
92
|
+
motion: defaultMotion,
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/** Derive a complete theme without changing the original. */
|
|
@@ -141,7 +141,7 @@ export function defineTheme(options: ThemeOptions, base: MavisTheme = foundation
|
|
|
141
141
|
for (const [key, value] of [...Object.entries(theme.space), ...Object.entries(theme.radius)]) {
|
|
142
142
|
if (!Number.isFinite(value) || value < 0) throw new RangeError(`Invalid theme token: ${key}`)
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
validateMotion(theme.motion)
|
|
145
145
|
return Object.freeze(theme)
|
|
146
146
|
}
|
|
147
147
|
|
package/src/theme/types.ts
CHANGED
|
@@ -65,6 +65,18 @@ export interface Typography {
|
|
|
65
65
|
letterSpacing: number
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
export type MotionEase = 'linear' | 'easeIn' | 'easeOut' | 'easeInOut'
|
|
69
|
+
export interface MotionTheme {
|
|
70
|
+
pressScale: number
|
|
71
|
+
pressDuration: number
|
|
72
|
+
releaseDuration: number
|
|
73
|
+
releaseBounce: number
|
|
74
|
+
enterDuration: number
|
|
75
|
+
exitDuration: number
|
|
76
|
+
enterOffset: number
|
|
77
|
+
ease: MotionEase
|
|
78
|
+
}
|
|
79
|
+
|
|
68
80
|
export interface MavisTheme {
|
|
69
81
|
readonly name: string
|
|
70
82
|
readonly appearance: 'light' | 'dark'
|
|
@@ -77,7 +89,7 @@ export interface MavisTheme {
|
|
|
77
89
|
>
|
|
78
90
|
readonly elevation: Readonly<Record<Elevation, Readonly<Shadow>>>
|
|
79
91
|
readonly components: { readonly [K in keyof ComponentTheme]: Readonly<ComponentTheme[K]> }
|
|
80
|
-
readonly motion: Readonly<
|
|
92
|
+
readonly motion: Readonly<MotionTheme>
|
|
81
93
|
}
|
|
82
94
|
|
|
83
95
|
export interface ThemeOptions {
|
package/src/vue/contracts.ts
CHANGED
|
@@ -8,7 +8,13 @@ type VueProperty<P extends Property> = { type: PropType<PropertyValue<P>> } & (P
|
|
|
8
8
|
: unknown) &
|
|
9
9
|
(P extends { required: true } ? { required: true } : unknown)
|
|
10
10
|
|
|
11
|
-
const constructors = {
|
|
11
|
+
const constructors = {
|
|
12
|
+
string: String,
|
|
13
|
+
number: Number,
|
|
14
|
+
boolean: Boolean,
|
|
15
|
+
object: Object,
|
|
16
|
+
function: Function,
|
|
17
|
+
}
|
|
12
18
|
|
|
13
19
|
/** Vue owns coercion and warnings; portable metadata owns names, defaults and allowed values. */
|
|
14
20
|
export function vueProperty<P extends Property>(definition: P): VueProperty<P> {
|
package/src/vue/date-picker.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
mergeProps,
|
|
6
6
|
nextTick,
|
|
7
7
|
onBeforeUnmount,
|
|
8
|
+
onMounted,
|
|
8
9
|
ref,
|
|
9
10
|
watch,
|
|
10
11
|
type Component,
|
|
@@ -32,8 +33,9 @@ import {
|
|
|
32
33
|
} from './date-props.js'
|
|
33
34
|
import { useButtonAction } from './button-content.js'
|
|
34
35
|
|
|
35
|
-
type EntryProps = Omit<ExtractPropTypes<typeof dateRangePickerProps>, 'modelValue'> & {
|
|
36
|
+
type EntryProps = Omit<ExtractPropTypes<typeof dateRangePickerProps>, 'modelValue' | 'draft'> & {
|
|
36
37
|
modelValue: CivilDate | null | DateRange
|
|
38
|
+
draft?: string | DateRangeDraft
|
|
37
39
|
name?: string
|
|
38
40
|
}
|
|
39
41
|
interface DatePrimitives {
|
|
@@ -46,6 +48,8 @@ interface DatePrimitives {
|
|
|
46
48
|
/** Internal adapter boundary: capture a focusable opener and dismiss the native keyboard. */
|
|
47
49
|
beforeOpen(opener: unknown): void
|
|
48
50
|
afterClose(opener: unknown): void
|
|
51
|
+
deferActions?: boolean
|
|
52
|
+
openerAttrs?: Record<string, unknown>
|
|
49
53
|
}
|
|
50
54
|
interface EntryEvents {
|
|
51
55
|
model(value: CivilDate | null | DateRange): void
|
|
@@ -64,6 +68,10 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
64
68
|
const end = ref('')
|
|
65
69
|
const touched = ref(false)
|
|
66
70
|
const open = ref(false)
|
|
71
|
+
const ready = ref(!primitives.deferActions)
|
|
72
|
+
onMounted(() => {
|
|
73
|
+
ready.value = true
|
|
74
|
+
})
|
|
67
75
|
const endpoint = ref<'start' | 'end'>('start')
|
|
68
76
|
const activeDate = ref<CivilDate>('2000-01-01')
|
|
69
77
|
const first = ref<InputHandle>()
|
|
@@ -90,13 +98,22 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
90
98
|
return { start: (props.modelValue as CivilDate | null) ?? '', end: '' }
|
|
91
99
|
}
|
|
92
100
|
function restore() {
|
|
93
|
-
|
|
101
|
+
// A controlled draft owns the editor. The canonical model remains independently valid.
|
|
102
|
+
const canonical = snapshot()
|
|
103
|
+
const value =
|
|
104
|
+
props.draft === undefined
|
|
105
|
+
? canonical
|
|
106
|
+
: range
|
|
107
|
+
? (props.draft as DateRangeDraft)
|
|
108
|
+
: { start: props.draft as string, end: '' }
|
|
109
|
+
if (!value || typeof value.start !== 'string' || typeof value.end !== 'string')
|
|
110
|
+
throw new TypeError('A date draft must contain text for each endpoint')
|
|
94
111
|
start.value = value.start
|
|
95
112
|
end.value = value.end
|
|
96
113
|
}
|
|
97
114
|
restore()
|
|
98
115
|
watch(
|
|
99
|
-
() => props.modelValue,
|
|
116
|
+
() => [props.modelValue, props.draft],
|
|
100
117
|
() => {
|
|
101
118
|
revision++
|
|
102
119
|
restore()
|
|
@@ -137,6 +154,11 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
137
154
|
const current = ++revision
|
|
138
155
|
const draft = { start: start.value, end: end.value }
|
|
139
156
|
events.draft(range ? { ...draft } : draft.start)
|
|
157
|
+
if (props.draft !== undefined) {
|
|
158
|
+
void nextTick(() => {
|
|
159
|
+
if (alive && revision === current) restore()
|
|
160
|
+
})
|
|
161
|
+
}
|
|
140
162
|
if (!validity.value.valid) return
|
|
141
163
|
const previous = snapshot()
|
|
142
164
|
if (previous.start === draft.start && previous.end === draft.end) return
|
|
@@ -157,7 +179,7 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
157
179
|
})
|
|
158
180
|
}
|
|
159
181
|
function show(which: 'start' | 'end') {
|
|
160
|
-
if (props.disabled || props.readonly || open.value) return
|
|
182
|
+
if (!ready.value || props.disabled || props.readonly || open.value) return
|
|
161
183
|
endpoint.value = which
|
|
162
184
|
const draft = which === 'end' ? end.value : start.value
|
|
163
185
|
let target = isCivilDate(draft) ? draft : (props.min ?? civilDate(`${props.initialMonth}-01`))
|
|
@@ -249,11 +271,12 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
249
271
|
},
|
|
250
272
|
}),
|
|
251
273
|
h(Button, {
|
|
274
|
+
...primitives.openerAttrs,
|
|
252
275
|
ref: which === 'start' ? firstOpener : secondOpener,
|
|
253
276
|
icon: 'calendar-days',
|
|
254
277
|
variant: 'secondary',
|
|
255
278
|
accessibilityLabel: `${props.calendarLabel ?? translations.calendar}: ${label(which)}`,
|
|
256
|
-
disabled: props.disabled || props.readonly,
|
|
279
|
+
disabled: !ready.value || props.disabled || props.readonly,
|
|
257
280
|
onClick: () => show(which),
|
|
258
281
|
}),
|
|
259
282
|
],
|
|
@@ -278,7 +301,11 @@ export function createDatePickers(primitives: DatePrimitives) {
|
|
|
278
301
|
text: props.clearLabel ?? `${translations.clear}: ${props.label}`,
|
|
279
302
|
variant: 'ghost',
|
|
280
303
|
size: 'sm',
|
|
281
|
-
disabled:
|
|
304
|
+
disabled:
|
|
305
|
+
!ready.value ||
|
|
306
|
+
props.disabled ||
|
|
307
|
+
props.readonly ||
|
|
308
|
+
(!start.value && !end.value),
|
|
282
309
|
onClick: () => {
|
|
283
310
|
if (props.disabled || props.readonly) return
|
|
284
311
|
start.value = ''
|
package/src/vue/date-props.ts
CHANGED
|
@@ -32,11 +32,14 @@ const common = {
|
|
|
32
32
|
}
|
|
33
33
|
export const datePickerProps = {
|
|
34
34
|
...common,
|
|
35
|
+
/** Optional controlled editor text, including incomplete or invalid dates. */
|
|
36
|
+
draft: { type: String, default: undefined },
|
|
35
37
|
modelValue: { type: String as PropType<CivilDate | null>, default: null },
|
|
36
38
|
name: { type: String, default: undefined },
|
|
37
39
|
}
|
|
38
40
|
export const dateRangePickerProps = {
|
|
39
41
|
...common,
|
|
42
|
+
draft: { type: Object as PropType<DateRangeDraft>, default: undefined },
|
|
40
43
|
modelValue: {
|
|
41
44
|
type: Object as PropType<DateRange>,
|
|
42
45
|
default: (): DateRange => ({ start: null, end: null }),
|
|
@@ -8,7 +8,7 @@ import type { DialogCloseReason } from '../dialog.js'
|
|
|
8
8
|
import type { SheetCloseReason } from '../sheet.js'
|
|
9
9
|
import type { InputHandle } from '../input.js'
|
|
10
10
|
|
|
11
|
-
type Action = { onClick?: () => void }
|
|
11
|
+
type Action = { onClick?: () => void; onError?: (error: unknown) => void }
|
|
12
12
|
type Model = { 'onUpdate:modelValue'?: (value: number) => void }
|
|
13
13
|
type InputEvents = {
|
|
14
14
|
onAction?: () => void
|
|
@@ -75,6 +75,10 @@ declare module '@vue/runtime-core' {
|
|
|
75
75
|
MScreen: DefineComponent<ComponentProps['MScreen']>
|
|
76
76
|
MRow: DefineComponent<ComponentProps['MRow']>
|
|
77
77
|
MColumn: DefineComponent<ComponentProps['MColumn']>
|
|
78
|
+
MStack: DefineComponent<ComponentProps['MStack']>
|
|
79
|
+
MLink: DefineComponent<
|
|
80
|
+
ComponentProps['MLink'] & Action & { onError?: (error: unknown) => void }
|
|
81
|
+
>
|
|
78
82
|
MBox: DefineComponent<ComponentProps['MBox']>
|
|
79
83
|
MCard: DefineComponent<ComponentProps['MCard'] & Action>
|
|
80
84
|
MText: DefineComponent<ComponentProps['MText']>
|
package/src/vue/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type {
|
|
|
6
6
|
AppearanceSource,
|
|
7
7
|
ThemeContextOptions,
|
|
8
8
|
} from './theme.js'
|
|
9
|
-
export { layoutDirection, useDefaultShrink } from './layout-context.js'
|
|
9
|
+
export { layoutDirection, useDefaultShrink, useLayoutShrink } from './layout-context.js'
|
|
10
10
|
export { textContent } from './text-content.js'
|
|
11
11
|
export type {} from './global-components.js'
|
|
12
12
|
export type { InputPlatformAttributes } from './global-components.js'
|
|
@@ -16,6 +16,9 @@ export {
|
|
|
16
16
|
spacingProp,
|
|
17
17
|
rowProps,
|
|
18
18
|
columnProps,
|
|
19
|
+
stackProps,
|
|
20
|
+
linkProps,
|
|
21
|
+
linkEmits,
|
|
19
22
|
cardProps,
|
|
20
23
|
buttonProps,
|
|
21
24
|
textProps,
|
|
@@ -75,3 +78,5 @@ export * from './files.js'
|
|
|
75
78
|
export * from './forms.js'
|
|
76
79
|
export * from './workflow-props.js'
|
|
77
80
|
export * from './workflows.js'
|
|
81
|
+
export { useRevealState } from './reveal-state.js'
|
|
82
|
+
export type { RevealHost } from './reveal-state.js'
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { inject, type InjectionKey } from '@vue/runtime-core'
|
|
1
|
+
import { computed, inject, unref, type InjectionKey, type Ref } from '@vue/runtime-core'
|
|
2
2
|
|
|
3
|
-
export const layoutDirection: InjectionKey<'row' | 'column'
|
|
3
|
+
export const layoutDirection: InjectionKey<'row' | 'column' | Readonly<Ref<'row' | 'column'>>> =
|
|
4
|
+
Symbol('mavis.layout')
|
|
4
5
|
|
|
5
6
|
/** Rows may wrap text to fit their width; columns preserve the natural height of content. */
|
|
6
7
|
export function useDefaultShrink(): number {
|
|
7
|
-
return inject(layoutDirection, 'column') === 'row' ? 1 : 0
|
|
8
|
+
return unref(inject(layoutDirection, 'column')) === 'row' ? 1 : 0
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** A responsive parent changes direction without replacing its children. */
|
|
12
|
+
export function useLayoutShrink() {
|
|
13
|
+
const direction = inject(layoutDirection, 'column')
|
|
14
|
+
return computed(() => (unref(direction) === 'row' ? 1 : 0))
|
|
8
15
|
}
|
package/src/vue/props.ts
CHANGED
|
@@ -24,6 +24,9 @@ import type { SheetName } from '../sheet.js'
|
|
|
24
24
|
import { dialogCloseReasons, type DialogCloseReason } from '../dialog.js'
|
|
25
25
|
import type { ExtractPropTypes, ExtractPublicPropTypes, PropType } from '@vue/runtime-core'
|
|
26
26
|
import type { Palette, Elevation } from '../theme/types.js'
|
|
27
|
+
import type { LinkNavigate } from '../link.js'
|
|
28
|
+
import { navigationContract } from '../contracts.js'
|
|
29
|
+
import type { StackResponsive } from '../responsive.js'
|
|
27
30
|
import { isChoiceValue, type ChoiceValue, type ChoiceOption } from '../choice.js'
|
|
28
31
|
import type { ToastController } from '../toast.js'
|
|
29
32
|
import { iconSizes, type IconName, type IconSize } from '../icon.js'
|
|
@@ -53,6 +56,21 @@ export function viewAttrs(props: ExtractPropTypes<typeof viewProps>) {
|
|
|
53
56
|
export const flexProps = vueProps(flexContract)
|
|
54
57
|
export const boxProps = vueProps(boxContract)
|
|
55
58
|
export const motionBoxProps = vueProps(motionBoxContract)
|
|
59
|
+
export const linkProps = {
|
|
60
|
+
...viewProps,
|
|
61
|
+
...flexProps,
|
|
62
|
+
href: { type: String, required: true as const },
|
|
63
|
+
text: { type: String, default: undefined },
|
|
64
|
+
navigate: { type: Function as PropType<LinkNavigate>, default: undefined },
|
|
65
|
+
target: choice(['_self', '_blank'] as const, '_self'),
|
|
66
|
+
rel: { type: String, default: undefined },
|
|
67
|
+
disabled: Boolean,
|
|
68
|
+
inline: Boolean,
|
|
69
|
+
}
|
|
70
|
+
export const linkEmits = {
|
|
71
|
+
click: () => true,
|
|
72
|
+
error: (_error: unknown) => true,
|
|
73
|
+
}
|
|
56
74
|
export const listItemProps = {
|
|
57
75
|
...viewProps,
|
|
58
76
|
...flexProps,
|
|
@@ -151,7 +169,13 @@ export const skeletonProps = {
|
|
|
151
169
|
}
|
|
152
170
|
export const rowProps = vueProps(rowContract)
|
|
153
171
|
export const columnProps = vueProps(columnContract)
|
|
172
|
+
export const stackProps = {
|
|
173
|
+
...columnProps,
|
|
174
|
+
direction: choice(['row', 'column'] as const, 'column'),
|
|
175
|
+
responsive: { type: [Object, Array] as PropType<StackResponsive>, default: undefined },
|
|
176
|
+
}
|
|
154
177
|
export const cardProps = {
|
|
178
|
+
...vueProps(navigationContract),
|
|
155
179
|
motionSurface: { type: Object as PropType<MotionSurface>, default: undefined },
|
|
156
180
|
...boxProps,
|
|
157
181
|
padding: spacingProp,
|
|
@@ -332,13 +356,15 @@ export const sheetEmits = {
|
|
|
332
356
|
close: (reason: SheetCloseReason) => sheetCloseReasons.includes(reason),
|
|
333
357
|
opened: () => true,
|
|
334
358
|
}
|
|
335
|
-
export const actionEmits = { click: () => true }
|
|
359
|
+
export const actionEmits = { click: () => true, error: (_error: unknown) => true }
|
|
336
360
|
export const sliderEmits = { 'update:modelValue': (value: number) => Number.isFinite(value) }
|
|
337
361
|
|
|
338
362
|
export const componentProps = {
|
|
339
363
|
MScreen: screenProps,
|
|
340
364
|
MRow: rowProps,
|
|
341
365
|
MColumn: columnProps,
|
|
366
|
+
MStack: stackProps,
|
|
367
|
+
MLink: linkProps,
|
|
342
368
|
MBox: motionBoxProps,
|
|
343
369
|
MCard: cardProps,
|
|
344
370
|
MText: textProps,
|