@getcortexlabs/mavis-core 0.1.0-alpha.3 → 0.1.0-alpha.5
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/accordion.d.ts +17 -0
- package/dist/accordion.d.ts.map +1 -0
- package/dist/accordion.js +42 -0
- package/dist/accordion.js.map +1 -0
- package/dist/alert.d.ts +21 -0
- package/dist/alert.d.ts.map +1 -0
- package/dist/alert.js +13 -0
- package/dist/alert.js.map +1 -0
- package/dist/avatar.d.ts +10 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/avatar.js +11 -0
- package/dist/avatar.js.map +1 -0
- package/dist/badge.d.ts +7 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +11 -0
- package/dist/badge.js.map +1 -0
- package/dist/capabilities.d.ts +119 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +142 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/chip.d.ts +9 -0
- package/dist/chip.d.ts.map +1 -0
- package/dist/chip.js +16 -0
- package/dist/chip.js.map +1 -0
- package/dist/choice.d.ts +15 -0
- package/dist/choice.d.ts.map +1 -0
- package/dist/choice.js +27 -0
- package/dist/choice.js.map +1 -0
- package/dist/combobox.d.ts +42 -0
- package/dist/combobox.d.ts.map +1 -0
- package/dist/combobox.js +159 -0
- package/dist/combobox.js.map +1 -0
- package/dist/contracts.d.ts +1201 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +242 -0
- package/dist/contracts.js.map +1 -0
- package/dist/date.d.ts +96 -0
- package/dist/date.d.ts.map +1 -0
- package/dist/date.js +235 -0
- package/dist/date.js.map +1 -0
- package/dist/dialog.d.ts +4 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +20 -0
- package/dist/dialog.js.map +1 -0
- package/dist/empty-state.d.ts +2 -0
- package/dist/empty-state.d.ts.map +1 -0
- package/dist/empty-state.js +5 -0
- package/dist/empty-state.js.map +1 -0
- package/dist/experimental-regions.d.ts +142 -0
- package/dist/experimental-regions.d.ts.map +1 -0
- package/dist/experimental-regions.js +315 -0
- package/dist/experimental-regions.js.map +1 -0
- package/dist/experimental.d.ts +134 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +502 -0
- package/dist/experimental.js.map +1 -0
- package/dist/files.d.ts +87 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +328 -0
- package/dist/files.js.map +1 -0
- package/dist/form.d.ts +39 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +170 -0
- package/dist/form.js.map +1 -0
- package/dist/index.d.ts +38 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -1
- package/dist/index.js.map +1 -1
- package/dist/input.d.ts +10 -0
- package/dist/input.d.ts.map +1 -1
- package/dist/input.js +12 -0
- package/dist/input.js.map +1 -1
- package/dist/list-item.d.ts +3 -0
- package/dist/list-item.d.ts.map +1 -0
- package/dist/list-item.js +7 -0
- package/dist/list-item.js.map +1 -0
- package/dist/motion.d.ts +33 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +21 -0
- package/dist/motion.js.map +1 -0
- package/dist/navigation.d.ts +22 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +54 -0
- package/dist/navigation.js.map +1 -0
- package/dist/progress.d.ts +19 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +19 -0
- package/dist/progress.js.map +1 -0
- package/dist/segmented.d.ts +11 -0
- package/dist/segmented.d.ts.map +1 -0
- package/dist/segmented.js +30 -0
- package/dist/segmented.js.map +1 -0
- package/dist/sheet.d.ts +8 -1
- package/dist/sheet.d.ts.map +1 -1
- package/dist/sheet.js +4 -3
- package/dist/sheet.js.map +1 -1
- package/dist/tabs.d.ts +11 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +28 -0
- package/dist/tabs.js.map +1 -0
- package/dist/theme/themes.d.ts.map +1 -1
- package/dist/theme/themes.js +84 -11
- package/dist/theme/themes.js.map +1 -1
- package/dist/theme/types.d.ts +52 -1
- package/dist/theme/types.d.ts.map +1 -1
- package/dist/theme/typography.d.ts +10 -0
- package/dist/theme/typography.d.ts.map +1 -0
- package/dist/theme/typography.js +90 -0
- package/dist/theme/typography.js.map +1 -0
- package/dist/toast.d.ts +43 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +228 -0
- package/dist/toast.js.map +1 -0
- package/dist/vue/button-content.d.ts +10 -0
- package/dist/vue/button-content.d.ts.map +1 -0
- package/dist/vue/button-content.js +54 -0
- package/dist/vue/button-content.js.map +1 -0
- package/dist/vue/cached-activity.d.ts +3 -0
- package/dist/vue/cached-activity.d.ts.map +1 -0
- package/dist/vue/cached-activity.js +13 -0
- package/dist/vue/cached-activity.js.map +1 -0
- package/dist/vue/combobox.d.ts +155 -0
- package/dist/vue/combobox.d.ts.map +1 -0
- package/dist/vue/combobox.js +195 -0
- package/dist/vue/combobox.js.map +1 -0
- package/dist/vue/component-props.d.ts +1989 -0
- package/dist/vue/component-props.d.ts.map +1 -0
- package/dist/vue/component-props.js +18 -0
- package/dist/vue/component-props.js.map +1 -0
- package/dist/vue/contracts.d.ts +18 -0
- package/dist/vue/contracts.d.ts.map +1 -0
- package/dist/vue/contracts.js +18 -0
- package/dist/vue/contracts.js.map +1 -0
- package/dist/vue/date-calendar.d.ts +64 -0
- package/dist/vue/date-calendar.d.ts.map +1 -0
- package/dist/vue/date-calendar.js +65 -0
- package/dist/vue/date-calendar.js.map +1 -0
- package/dist/vue/date-picker.d.ts +927 -0
- package/dist/vue/date-picker.d.ts.map +1 -0
- package/dist/vue/date-picker.js +319 -0
- package/dist/vue/date-picker.js.map +1 -0
- package/dist/vue/date-props.d.ts +254 -0
- package/dist/vue/date-props.d.ts.map +1 -0
- package/dist/vue/date-props.js +74 -0
- package/dist/vue/date-props.js.map +1 -0
- package/dist/vue/dialog.d.ts +21 -0
- package/dist/vue/dialog.d.ts.map +1 -0
- package/dist/vue/dialog.js +58 -0
- package/dist/vue/dialog.js.map +1 -0
- package/dist/vue/files.d.ts +53 -0
- package/dist/vue/files.d.ts.map +1 -0
- package/dist/vue/files.js +40 -0
- package/dist/vue/files.js.map +1 -0
- package/dist/vue/forms.d.ts +4 -0
- package/dist/vue/forms.d.ts.map +1 -0
- package/dist/vue/forms.js +15 -0
- package/dist/vue/forms.js.map +1 -0
- package/dist/vue/global-components.d.ts +129 -3
- package/dist/vue/global-components.d.ts.map +1 -1
- package/dist/vue/index.d.ts +28 -2
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +24 -1
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/inline-content.d.ts +54 -0
- package/dist/vue/inline-content.d.ts.map +1 -0
- package/dist/vue/inline-content.js +64 -0
- package/dist/vue/inline-content.js.map +1 -0
- package/dist/vue/props.d.ts +2654 -637
- package/dist/vue/props.d.ts.map +1 -1
- package/dist/vue/props.js +228 -86
- package/dist/vue/props.js.map +1 -1
- package/dist/vue/theme-provider.d.ts +58 -0
- package/dist/vue/theme-provider.d.ts.map +1 -0
- package/dist/vue/theme-provider.js +69 -0
- package/dist/vue/theme-provider.js.map +1 -0
- package/dist/vue/theme.d.ts +962 -12
- package/dist/vue/theme.d.ts.map +1 -1
- package/dist/vue/theme.js +17 -7
- package/dist/vue/theme.js.map +1 -1
- package/dist/vue/toast.d.ts +29 -0
- package/dist/vue/toast.d.ts.map +1 -0
- package/dist/vue/toast.js +79 -0
- package/dist/vue/toast.js.map +1 -0
- package/dist/vue/workflow-props.d.ts +110 -0
- package/dist/vue/workflow-props.d.ts.map +1 -0
- package/dist/vue/workflow-props.js +37 -0
- package/dist/vue/workflow-props.js.map +1 -0
- package/dist/vue/workflows.d.ts +267 -0
- package/dist/vue/workflows.d.ts.map +1 -0
- package/dist/vue/workflows.js +200 -0
- package/dist/vue/workflows.js.map +1 -0
- package/package.json +5 -1
- package/src/accordion.ts +66 -0
- package/src/alert.ts +16 -0
- package/src/avatar.ts +11 -0
- package/src/badge.ts +11 -0
- package/src/capabilities.ts +145 -0
- package/src/chip.ts +20 -0
- package/src/choice.ts +41 -0
- package/src/combobox.ts +198 -0
- package/src/contracts.ts +295 -0
- package/src/date.ts +280 -0
- package/src/dialog.ts +20 -0
- package/src/empty-state.ts +4 -0
- package/src/experimental-regions.ts +463 -0
- package/src/experimental.ts +643 -0
- package/src/files.ts +408 -0
- package/src/form.ts +190 -0
- package/src/index.ts +64 -3
- package/src/input.ts +22 -0
- package/src/list-item.ts +5 -0
- package/src/motion.ts +22 -0
- package/src/navigation.ts +61 -0
- package/src/progress.ts +22 -0
- package/src/segmented.ts +39 -0
- package/src/sheet.ts +6 -3
- package/src/tabs.ts +35 -0
- package/src/theme/themes.ts +88 -11
- package/src/theme/types.ts +42 -1
- package/src/theme/typography.ts +84 -0
- package/src/toast.ts +249 -0
- package/src/vue/button-content.ts +60 -0
- package/src/vue/cached-activity.ts +13 -0
- package/src/vue/combobox.ts +238 -0
- package/src/vue/component-props.ts +24 -0
- package/src/vue/contracts.ts +33 -0
- package/src/vue/date-calendar.ts +76 -0
- package/src/vue/date-picker.ts +387 -0
- package/src/vue/date-props.ts +81 -0
- package/src/vue/dialog.ts +63 -0
- package/src/vue/files.ts +53 -0
- package/src/vue/forms.ts +20 -0
- package/src/vue/global-components.ts +120 -3
- package/src/vue/index.ts +46 -2
- package/src/vue/inline-content.ts +71 -0
- package/src/vue/props.ts +258 -95
- package/src/vue/theme-provider.ts +74 -0
- package/src/vue/theme.ts +17 -6
- package/src/vue/toast.ts +99 -0
- package/src/vue/workflow-props.ts +41 -0
- package/src/vue/workflows.ts +257 -0
package/src/input.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import { iconGlyph, type IconName } from './icon.js'
|
|
2
|
+
|
|
3
|
+
export interface InputAction {
|
|
4
|
+
icon: IconName
|
|
5
|
+
label: string
|
|
6
|
+
disabled?: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Icon-only actions have a fixed touch target, independent of the accessible label length. */
|
|
10
|
+
export const inputActionSize = 48
|
|
11
|
+
|
|
1
12
|
export interface InputHandle {
|
|
2
13
|
focus(): void
|
|
3
14
|
blur(): void
|
|
@@ -9,7 +20,18 @@ export function validateInput(options: {
|
|
|
9
20
|
type: string
|
|
10
21
|
rows: number
|
|
11
22
|
maxLength?: number
|
|
23
|
+
trailingIcon?: IconName
|
|
24
|
+
trailingAction?: InputAction
|
|
12
25
|
}) {
|
|
26
|
+
if (options.trailingAction) {
|
|
27
|
+
iconGlyph(options.trailingAction.icon)
|
|
28
|
+
if (typeof options.trailingAction.label !== 'string' || !options.trailingAction.label.trim()) {
|
|
29
|
+
throw new RangeError('An input action needs a nonempty label')
|
|
30
|
+
}
|
|
31
|
+
if (options.trailingIcon) {
|
|
32
|
+
throw new RangeError('Use either trailingIcon or trailingAction on an input')
|
|
33
|
+
}
|
|
34
|
+
}
|
|
13
35
|
if (!Number.isSafeInteger(options.rows) || options.rows < 1) {
|
|
14
36
|
throw new RangeError('rows must be a positive integer')
|
|
15
37
|
}
|
package/src/list-item.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Slot content needs an explicit label when it adds meaning to an interactive row. */
|
|
2
|
+
export function listItemLabel(title: string, description: string, label?: string): string {
|
|
3
|
+
if (!title?.trim()) throw new RangeError('ListItem requires a non-empty title.')
|
|
4
|
+
return label?.trim() || [title.trim(), description.trim()].filter(Boolean).join('. ')
|
|
5
|
+
}
|
package/src/motion.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Theme input shared by recipes and theme validation. */
|
|
2
|
+
export function resolvePressScale(scale: number): number {
|
|
3
|
+
if (!Number.isFinite(scale) || scale <= 0 || scale > 1) {
|
|
4
|
+
throw new RangeError('pressScale must be a finite number greater than 0 and at most 1')
|
|
5
|
+
}
|
|
6
|
+
return scale
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Recipes describe motion, not input or lifecycle. Adapters own reduced-motion detection:
|
|
10
|
+
// native follows Jolt configuration; Web follows prefers-reduced-motion. See guide/motion.
|
|
11
|
+
export function pressMotion(scale: number) {
|
|
12
|
+
return {
|
|
13
|
+
composition: 'multiply',
|
|
14
|
+
pressed: [{ scale: resolvePressScale(scale) }, { type: 'spring', duration: 200, bounce: 0 }],
|
|
15
|
+
released: [{ scale: 1 }, { type: 'spring', duration: 450, bounce: 0.35 }],
|
|
16
|
+
} as const
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const revealMotion = {
|
|
20
|
+
enter: [{ opacity: [0, 1], y: [8, 0] }, { duration: 180 }],
|
|
21
|
+
leave: [{ opacity: 0 }, { duration: 120 }],
|
|
22
|
+
} as const
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { validateChoices, type ChoiceOption, type ChoiceValue } from './choice.js'
|
|
2
|
+
|
|
3
|
+
export interface StepOption extends ChoiceOption {
|
|
4
|
+
status?: 'pending' | 'complete' | 'error'
|
|
5
|
+
}
|
|
6
|
+
export function validateSteps(steps: readonly StepOption[], current: ChoiceValue | null) {
|
|
7
|
+
validateChoices(steps, current)
|
|
8
|
+
if (!steps.length) throw new RangeError('Steps require at least one item.')
|
|
9
|
+
if (current !== null && !steps.some((step) => step.value === current))
|
|
10
|
+
throw new RangeError('The current step must exist in steps.')
|
|
11
|
+
for (const step of steps)
|
|
12
|
+
if (step.status && !['pending', 'complete', 'error'].includes(step.status))
|
|
13
|
+
throw new RangeError(`Unknown step status: ${step.status}`)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type PaginationItem = { kind: 'page'; page: number } | { kind: 'gap'; key: string }
|
|
17
|
+
export function pageCount(total: number, pageSize: number) {
|
|
18
|
+
if (!Number.isSafeInteger(total) || total < 0)
|
|
19
|
+
throw new RangeError('total must be a non-negative safe integer.')
|
|
20
|
+
if (!Number.isSafeInteger(pageSize) || pageSize < 1)
|
|
21
|
+
throw new RangeError('pageSize must be a positive safe integer.')
|
|
22
|
+
return Math.ceil(total / pageSize)
|
|
23
|
+
}
|
|
24
|
+
/** 1-based pages. Empty results retain page 1 without inventing a result page. */
|
|
25
|
+
export function pagination(total: number, pageSize: number, page: number, siblingCount = 1) {
|
|
26
|
+
const count = pageCount(total, pageSize)
|
|
27
|
+
if (!Number.isSafeInteger(page) || page < 1)
|
|
28
|
+
throw new RangeError('page must be a positive safe integer.')
|
|
29
|
+
if (!Number.isInteger(siblingCount) || siblingCount < 0 || siblingCount > 2)
|
|
30
|
+
throw new RangeError('siblingCount must be 0, 1 or 2.')
|
|
31
|
+
// A changed total can temporarily make the parent's page stale. Report it without mutation.
|
|
32
|
+
const outOfRange = page > Math.max(1, count)
|
|
33
|
+
const pages = new Set<number>()
|
|
34
|
+
if (count > 0) {
|
|
35
|
+
pages.add(1)
|
|
36
|
+
pages.add(count)
|
|
37
|
+
}
|
|
38
|
+
const anchor = Math.min(page, count)
|
|
39
|
+
for (
|
|
40
|
+
let value = Math.max(1, anchor - siblingCount);
|
|
41
|
+
value <= Math.min(count, anchor + siblingCount);
|
|
42
|
+
value++
|
|
43
|
+
)
|
|
44
|
+
pages.add(value)
|
|
45
|
+
const items: PaginationItem[] = []
|
|
46
|
+
let previous = 0
|
|
47
|
+
for (const value of [...pages].sort((a, b) => a - b)) {
|
|
48
|
+
if (previous && value - previous === 2) items.push({ kind: 'page', page: previous + 1 })
|
|
49
|
+
else if (previous && value - previous > 2)
|
|
50
|
+
items.push({ kind: 'gap', key: `${previous}-${value}` })
|
|
51
|
+
items.push({ kind: 'page', page: value })
|
|
52
|
+
previous = value
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
count,
|
|
56
|
+
items,
|
|
57
|
+
outOfRange,
|
|
58
|
+
previous: count > 0 && page > 1 ? Math.min(page - 1, count) : null,
|
|
59
|
+
next: page < count ? page + 1 : null,
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/progress.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const progressSizes = { sm: 4, md: 8, lg: 12 } as const
|
|
2
|
+
export type ProgressSize = keyof typeof progressSizes
|
|
3
|
+
export type ProgressTone = 'primary' | 'accent' | 'success' | 'warning' | 'danger'
|
|
4
|
+
|
|
5
|
+
export const progressMotion = Object.freeze({ segment: 0.32, duration: 1600 })
|
|
6
|
+
|
|
7
|
+
/** A bounded reading; task ownership and completion stay with the application. */
|
|
8
|
+
export function progressState(value: number, max: number) {
|
|
9
|
+
if (!Number.isFinite(max) || max <= 0)
|
|
10
|
+
throw new RangeError('Progress max must be positive and finite')
|
|
11
|
+
if (!Number.isFinite(value)) throw new RangeError('Progress value must be finite')
|
|
12
|
+
const current = Math.min(max, Math.max(0, value))
|
|
13
|
+
const ratio = current / max
|
|
14
|
+
return { value: current, ratio, text: `${Number((ratio * 100).toFixed(1))}%` }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function checkProgressLabels(label: string, indeterminateLabel: string) {
|
|
18
|
+
if (typeof label !== 'string' || !label.trim())
|
|
19
|
+
throw new TypeError('Progress label must be a non-empty string')
|
|
20
|
+
if (typeof indeterminateLabel !== 'string' || !indeterminateLabel.trim())
|
|
21
|
+
throw new TypeError('Progress indeterminateLabel must be a non-empty string')
|
|
22
|
+
}
|
package/src/segmented.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { validateChoices, type ChoiceOption, type ChoiceValue } from './choice.js'
|
|
2
|
+
|
|
3
|
+
export type SegmentedOption = Pick<ChoiceOption, 'value' | 'label' | 'disabled'>
|
|
4
|
+
export const segmentedMotion = Object.freeze({
|
|
5
|
+
duration: 180,
|
|
6
|
+
ease: 'easeOut',
|
|
7
|
+
cssEase: 'ease-out',
|
|
8
|
+
} as const)
|
|
9
|
+
|
|
10
|
+
export function validateSegments(
|
|
11
|
+
options: readonly SegmentedOption[],
|
|
12
|
+
value: ChoiceValue | null,
|
|
13
|
+
label: string,
|
|
14
|
+
) {
|
|
15
|
+
validateChoices(options, value)
|
|
16
|
+
if (typeof label !== 'string' || !label.trim())
|
|
17
|
+
throw new TypeError('SegmentedControl needs a non-empty label.')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A segmented choice follows radio behavior: arrows both focus and request selection. */
|
|
21
|
+
export function segmentedFocusTarget(
|
|
22
|
+
options: readonly SegmentedOption[],
|
|
23
|
+
value: ChoiceValue,
|
|
24
|
+
key: string,
|
|
25
|
+
rtl = false,
|
|
26
|
+
): SegmentedOption | undefined {
|
|
27
|
+
const enabled = options.filter((option) => !option.disabled)
|
|
28
|
+
if (key === 'Home') return enabled[0]
|
|
29
|
+
if (key === 'End') return enabled[enabled.length - 1]
|
|
30
|
+
const direction = {
|
|
31
|
+
ArrowRight: rtl ? -1 : 1,
|
|
32
|
+
ArrowLeft: rtl ? 1 : -1,
|
|
33
|
+
ArrowDown: 1,
|
|
34
|
+
ArrowUp: -1,
|
|
35
|
+
}[key]
|
|
36
|
+
if (!direction) return
|
|
37
|
+
const index = enabled.findIndex((option) => option.value === value)
|
|
38
|
+
return enabled[(index + direction + enabled.length) % enabled.length]
|
|
39
|
+
}
|
package/src/sheet.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/** Why a sheet closed: the component's own control, a platform dismissal, or `open` set to false. */
|
|
2
2
|
export type SheetCloseReason = 'button' | 'backdrop' | 'escape' | 'back' | 'swipe' | 'program'
|
|
3
3
|
|
|
4
|
+
export type SheetName =
|
|
5
|
+
{ title: string; accessibilityLabel?: string } | { title?: string; accessibilityLabel: string }
|
|
6
|
+
|
|
4
7
|
export const sheetCloseReasons: readonly SheetCloseReason[] = [
|
|
5
8
|
'button',
|
|
6
9
|
'backdrop',
|
|
@@ -11,7 +14,7 @@ export const sheetCloseReasons: readonly SheetCloseReason[] = [
|
|
|
11
14
|
]
|
|
12
15
|
|
|
13
16
|
export function checkSheetName(title: string | undefined, label: string | undefined) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
const name = title?.trim() || label?.trim()
|
|
18
|
+
if (!name) throw new RangeError('A sheet needs a nonempty title or accessibilityLabel')
|
|
19
|
+
return name
|
|
17
20
|
}
|
package/src/tabs.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { validateChoices, type ChoiceOption, type ChoiceValue } from './choice.js'
|
|
2
|
+
|
|
3
|
+
export type TabOption = Pick<ChoiceOption, 'value' | 'label' | 'disabled'>
|
|
4
|
+
export interface TabPanelProps {
|
|
5
|
+
value: ChoiceValue
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function validateTabs(tabs: readonly TabOption[], value: ChoiceValue | null, label: string) {
|
|
9
|
+
validateChoices(tabs, value)
|
|
10
|
+
if (typeof label !== 'string' || !label.trim())
|
|
11
|
+
throw new TypeError('Tabs need a non-empty label.')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Keyboard navigation moves focus; activation remains an explicit action. */
|
|
15
|
+
export function tabFocusTarget(
|
|
16
|
+
tabs: readonly TabOption[],
|
|
17
|
+
value: ChoiceValue,
|
|
18
|
+
key: string,
|
|
19
|
+
rtl = false,
|
|
20
|
+
): TabOption | undefined {
|
|
21
|
+
const enabled = tabs.filter((tab) => !tab.disabled)
|
|
22
|
+
if (key === 'Home') return enabled[0]
|
|
23
|
+
if (key === 'End') return enabled[enabled.length - 1]
|
|
24
|
+
if (key !== 'ArrowLeft' && key !== 'ArrowRight') return
|
|
25
|
+
const step = (key === 'ArrowRight' ? 1 : -1) * (rtl ? -1 : 1)
|
|
26
|
+
const index = enabled.findIndex((tab) => tab.value === value)
|
|
27
|
+
return enabled[(index + step + enabled.length) % enabled.length]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Reveal the nearest edge without changing a surrounding vertical scroll view. */
|
|
31
|
+
export function tabScrollOffset(left: number, width: number, offset: number, viewport: number) {
|
|
32
|
+
if (left < offset || width >= viewport) return Math.max(0, left)
|
|
33
|
+
if (left + width > offset + viewport) return Math.max(0, left + width - viewport)
|
|
34
|
+
return offset
|
|
35
|
+
}
|
package/src/theme/themes.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { MavisTheme, ThemeOptions } from './types.js'
|
|
2
|
+
import {
|
|
3
|
+
validateTypography,
|
|
4
|
+
validateComponentTheme,
|
|
5
|
+
validateShadow,
|
|
6
|
+
freezeFamily,
|
|
7
|
+
} from './typography.js'
|
|
8
|
+
import { resolvePressScale } from '../motion.js'
|
|
2
9
|
|
|
3
10
|
const foundation: MavisTheme = {
|
|
4
11
|
name: 'mavis',
|
|
@@ -16,24 +23,72 @@ const foundation: MavisTheme = {
|
|
|
16
23
|
onAccent: '#FFFFFF',
|
|
17
24
|
accentSoft: '#E8EEFF',
|
|
18
25
|
border: '#EAE3ED',
|
|
26
|
+
warning: '#9A5A10',
|
|
19
27
|
success: '#237354',
|
|
20
28
|
danger: '#B33545',
|
|
21
29
|
},
|
|
22
30
|
space: { none: 0, xs: 4, sm: 8, md: 16, lg: 24, xl: 32, '2xl': 48 },
|
|
23
31
|
radius: { none: 0, sm: 10, md: 16, lg: 24, full: 999 },
|
|
24
32
|
typography: {
|
|
25
|
-
display: {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
display: {
|
|
34
|
+
fontSize: 56,
|
|
35
|
+
fontWeight: '600',
|
|
36
|
+
letterSpacing: -0.04,
|
|
37
|
+
fontFamily: 'system',
|
|
38
|
+
lineHeight: 1.3,
|
|
39
|
+
},
|
|
40
|
+
title: {
|
|
41
|
+
fontSize: 34,
|
|
42
|
+
fontWeight: '600',
|
|
43
|
+
letterSpacing: -0.035,
|
|
44
|
+
fontFamily: 'system',
|
|
45
|
+
lineHeight: 1.3,
|
|
46
|
+
},
|
|
47
|
+
heading: {
|
|
48
|
+
fontSize: 20,
|
|
49
|
+
fontWeight: '600',
|
|
50
|
+
letterSpacing: -0.02,
|
|
51
|
+
fontFamily: 'system',
|
|
52
|
+
lineHeight: 1.3,
|
|
53
|
+
},
|
|
54
|
+
body: {
|
|
55
|
+
fontSize: 16,
|
|
56
|
+
fontWeight: 'normal',
|
|
57
|
+
letterSpacing: 0,
|
|
58
|
+
fontFamily: 'system',
|
|
59
|
+
lineHeight: 1.3,
|
|
60
|
+
},
|
|
61
|
+
caption: {
|
|
62
|
+
fontSize: 13,
|
|
63
|
+
fontWeight: 'normal',
|
|
64
|
+
letterSpacing: 0,
|
|
65
|
+
fontFamily: 'system',
|
|
66
|
+
lineHeight: 1.3,
|
|
67
|
+
},
|
|
68
|
+
overline: {
|
|
69
|
+
fontSize: 11,
|
|
70
|
+
fontWeight: '600',
|
|
71
|
+
letterSpacing: 0.12,
|
|
72
|
+
fontFamily: 'system',
|
|
73
|
+
lineHeight: 1.3,
|
|
74
|
+
},
|
|
31
75
|
},
|
|
32
76
|
control: {
|
|
33
77
|
sm: { height: 44, fontSize: 14, padding: 16 },
|
|
34
78
|
md: { height: 52, fontSize: 16, padding: 20 },
|
|
35
79
|
lg: { height: 60, fontSize: 17, padding: 24 },
|
|
36
80
|
},
|
|
81
|
+
elevation: {
|
|
82
|
+
none: { x: 0, y: 0, blur: 0, spread: 0, color: 'transparent' },
|
|
83
|
+
sm: { x: 0, y: 2, blur: 6, spread: 0, color: 'rgba(37, 30, 50, 0.10)' },
|
|
84
|
+
md: { x: 0, y: 8, blur: 24, spread: 0, color: 'rgba(37, 30, 50, 0.14)' },
|
|
85
|
+
lg: { x: 0, y: 16, blur: 40, spread: 0, color: 'rgba(37, 30, 50, 0.20)' },
|
|
86
|
+
},
|
|
87
|
+
components: {
|
|
88
|
+
button: { fontWeight: '600', lineHeight: 1.3, paddingY: 12, radius: 'md', elevation: 'none' },
|
|
89
|
+
input: { fontWeight: 'normal', lineHeight: 1.5, paddingX: 16, paddingY: 14, radius: 'md' },
|
|
90
|
+
card: { padding: 'lg', radius: 'lg', elevation: 'none' },
|
|
91
|
+
},
|
|
37
92
|
motion: { pressScale: 0.97 },
|
|
38
93
|
}
|
|
39
94
|
|
|
@@ -41,15 +96,32 @@ const foundation: MavisTheme = {
|
|
|
41
96
|
export function defineTheme(options: ThemeOptions, base: MavisTheme = foundation): MavisTheme {
|
|
42
97
|
const typography = { ...base.typography }
|
|
43
98
|
for (const variant of Object.keys(typography) as (keyof typeof typography)[]) {
|
|
44
|
-
|
|
99
|
+
const type = {
|
|
45
100
|
...typography[variant],
|
|
46
101
|
...options.typography?.[variant],
|
|
47
|
-
}
|
|
102
|
+
}
|
|
103
|
+
validateTypography(type)
|
|
104
|
+
typography[variant] = Object.freeze({ ...type, fontFamily: freezeFamily(type.fontFamily) })
|
|
48
105
|
}
|
|
49
106
|
const control = { ...base.control }
|
|
50
107
|
for (const size of Object.keys(control) as (keyof typeof control)[]) {
|
|
51
108
|
control[size] = Object.freeze({ ...control[size], ...options.control?.[size] })
|
|
52
109
|
}
|
|
110
|
+
const elevation = { ...base.elevation }
|
|
111
|
+
for (const level of Object.keys(elevation) as (keyof typeof elevation)[]) {
|
|
112
|
+
const shadow = { ...elevation[level], ...options.elevation?.[level] }
|
|
113
|
+
validateShadow(shadow)
|
|
114
|
+
elevation[level] = Object.freeze(shadow)
|
|
115
|
+
}
|
|
116
|
+
const components = {
|
|
117
|
+
button: { ...base.components.button, ...options.components?.button },
|
|
118
|
+
input: { ...base.components.input, ...options.components?.input },
|
|
119
|
+
card: { ...base.components.card, ...options.components?.card },
|
|
120
|
+
}
|
|
121
|
+
validateComponentTheme(components)
|
|
122
|
+
for (const component of [components.button, components.input]) {
|
|
123
|
+
if (component.fontFamily) component.fontFamily = freezeFamily(component.fontFamily)
|
|
124
|
+
}
|
|
53
125
|
const theme: MavisTheme = {
|
|
54
126
|
name: options.name,
|
|
55
127
|
appearance: options.appearance ?? base.appearance,
|
|
@@ -58,14 +130,18 @@ export function defineTheme(options: ThemeOptions, base: MavisTheme = foundation
|
|
|
58
130
|
radius: Object.freeze({ ...base.radius, ...options.radius }),
|
|
59
131
|
typography: Object.freeze(typography),
|
|
60
132
|
control: Object.freeze(control),
|
|
133
|
+
elevation: Object.freeze(elevation),
|
|
134
|
+
components: Object.freeze({
|
|
135
|
+
button: Object.freeze(components.button),
|
|
136
|
+
input: Object.freeze(components.input),
|
|
137
|
+
card: Object.freeze(components.card),
|
|
138
|
+
}),
|
|
61
139
|
motion: Object.freeze({ ...base.motion, ...options.motion }),
|
|
62
140
|
}
|
|
63
141
|
for (const [key, value] of [...Object.entries(theme.space), ...Object.entries(theme.radius)]) {
|
|
64
142
|
if (!Number.isFinite(value) || value < 0) throw new RangeError(`Invalid theme token: ${key}`)
|
|
65
143
|
}
|
|
66
|
-
|
|
67
|
-
throw new RangeError('pressScale must be greater than 0 and at most 1')
|
|
68
|
-
}
|
|
144
|
+
resolvePressScale(theme.motion.pressScale)
|
|
69
145
|
return Object.freeze(theme)
|
|
70
146
|
}
|
|
71
147
|
|
|
@@ -87,6 +163,7 @@ export const midnight = defineTheme({
|
|
|
87
163
|
onAccent: '#172247',
|
|
88
164
|
accentSoft: '#242E4A',
|
|
89
165
|
border: '#3C3046',
|
|
166
|
+
warning: '#F4C579',
|
|
90
167
|
success: '#9FD5BE',
|
|
91
168
|
danger: '#FFA8A8',
|
|
92
169
|
},
|
package/src/theme/types.ts
CHANGED
|
@@ -18,13 +18,50 @@ export interface Palette {
|
|
|
18
18
|
onAccent: string
|
|
19
19
|
accentSoft: string
|
|
20
20
|
border: string
|
|
21
|
+
warning: string
|
|
21
22
|
success: string
|
|
22
23
|
danger: string
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
export type FontWeight =
|
|
27
|
+
'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'
|
|
28
|
+
/** A shared installed family, or explicit platform names/stacks. Empty native names use the system font. */
|
|
29
|
+
export type FontFamily = string | Readonly<{ web: string; ios: string; android: string }>
|
|
30
|
+
export type Elevation = 'none' | 'sm' | 'md' | 'lg'
|
|
31
|
+
export interface Shadow {
|
|
32
|
+
x: number
|
|
33
|
+
y: number
|
|
34
|
+
blur: number
|
|
35
|
+
spread: number
|
|
36
|
+
color: string
|
|
37
|
+
}
|
|
38
|
+
export interface ComponentTheme {
|
|
39
|
+
button: {
|
|
40
|
+
fontFamily?: FontFamily
|
|
41
|
+
fontWeight: FontWeight
|
|
42
|
+
lineHeight: number
|
|
43
|
+
paddingY: number
|
|
44
|
+
radius: Radius | number
|
|
45
|
+
elevation: Elevation
|
|
46
|
+
}
|
|
47
|
+
input: {
|
|
48
|
+
fontFamily?: FontFamily
|
|
49
|
+
fontSize?: number
|
|
50
|
+
fontWeight: FontWeight
|
|
51
|
+
lineHeight: number
|
|
52
|
+
paddingX: number
|
|
53
|
+
paddingY: number
|
|
54
|
+
radius: Radius | number
|
|
55
|
+
}
|
|
56
|
+
card: { padding: Spacing; radius: Radius | number; elevation: Elevation }
|
|
57
|
+
}
|
|
58
|
+
|
|
25
59
|
export interface Typography {
|
|
26
60
|
fontSize: number
|
|
27
|
-
fontWeight:
|
|
61
|
+
fontWeight: FontWeight
|
|
62
|
+
fontFamily: FontFamily
|
|
63
|
+
/** Unitless line rhythm, at least 1; native renderers add leading to font metrics. */
|
|
64
|
+
lineHeight: number
|
|
28
65
|
letterSpacing: number
|
|
29
66
|
}
|
|
30
67
|
|
|
@@ -38,6 +75,8 @@ export interface MavisTheme {
|
|
|
38
75
|
readonly control: Readonly<
|
|
39
76
|
Record<Size, Readonly<{ height: number; fontSize: number; padding: number }>>
|
|
40
77
|
>
|
|
78
|
+
readonly elevation: Readonly<Record<Elevation, Readonly<Shadow>>>
|
|
79
|
+
readonly components: { readonly [K in keyof ComponentTheme]: Readonly<ComponentTheme[K]> }
|
|
41
80
|
readonly motion: Readonly<{ pressScale: number }>
|
|
42
81
|
}
|
|
43
82
|
|
|
@@ -49,5 +88,7 @@ export interface ThemeOptions {
|
|
|
49
88
|
radius?: Partial<MavisTheme['radius']>
|
|
50
89
|
typography?: Partial<Record<TextVariant, Partial<Typography>>>
|
|
51
90
|
control?: Partial<Record<Size, Partial<MavisTheme['control'][Size]>>>
|
|
91
|
+
elevation?: Partial<Record<Elevation, Partial<Shadow>>>
|
|
92
|
+
components?: { [K in keyof ComponentTheme]?: Partial<ComponentTheme[K]> }
|
|
52
93
|
motion?: Partial<MavisTheme['motion']>
|
|
53
94
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ComponentTheme, FontFamily, FontWeight, Shadow, Typography } from './types.js'
|
|
2
|
+
|
|
3
|
+
export const fontWeights: readonly FontWeight[] = [
|
|
4
|
+
'normal',
|
|
5
|
+
'bold',
|
|
6
|
+
'100',
|
|
7
|
+
'200',
|
|
8
|
+
'300',
|
|
9
|
+
'400',
|
|
10
|
+
'500',
|
|
11
|
+
'600',
|
|
12
|
+
'700',
|
|
13
|
+
'800',
|
|
14
|
+
'900',
|
|
15
|
+
]
|
|
16
|
+
export function validateWeight(value: FontWeight) {
|
|
17
|
+
if (!fontWeights.includes(value)) throw new RangeError(`Invalid font weight: ${String(value)}`)
|
|
18
|
+
return value
|
|
19
|
+
}
|
|
20
|
+
export function freezeFamily(value: FontFamily): FontFamily {
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
if (!value.trim()) throw new RangeError('A font family must not be blank')
|
|
23
|
+
return value
|
|
24
|
+
}
|
|
25
|
+
if (
|
|
26
|
+
!value ||
|
|
27
|
+
typeof value.web !== 'string' ||
|
|
28
|
+
!value.web.trim() ||
|
|
29
|
+
typeof value.ios !== 'string' ||
|
|
30
|
+
typeof value.android !== 'string'
|
|
31
|
+
) {
|
|
32
|
+
throw new TypeError('A font family needs web, ios and android names')
|
|
33
|
+
}
|
|
34
|
+
return Object.freeze({ ...value })
|
|
35
|
+
}
|
|
36
|
+
export function fontFamily(value: FontFamily, platform: 'web' | 'ios' | 'android') {
|
|
37
|
+
if (value === 'system')
|
|
38
|
+
return platform === 'web'
|
|
39
|
+
? 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'
|
|
40
|
+
: ''
|
|
41
|
+
return typeof value === 'string' ? value : value[platform]
|
|
42
|
+
}
|
|
43
|
+
function finite(value: number, name: string, minimum = 0) {
|
|
44
|
+
if (!Number.isFinite(value) || value < minimum) throw new RangeError(`Invalid ${name}: ${value}`)
|
|
45
|
+
}
|
|
46
|
+
export function validateTypography(value: Typography) {
|
|
47
|
+
finite(value.fontSize, 'fontSize', Number.EPSILON)
|
|
48
|
+
finite(value.lineHeight, 'lineHeight', 1)
|
|
49
|
+
if (!Number.isFinite(value.letterSpacing)) throw new RangeError('Invalid letterSpacing')
|
|
50
|
+
validateWeight(value.fontWeight)
|
|
51
|
+
freezeFamily(value.fontFamily)
|
|
52
|
+
}
|
|
53
|
+
export function validateShadow(value: Shadow) {
|
|
54
|
+
for (const key of ['x', 'y', 'spread'] as const) finite(value[key], `shadow ${key}`, -Infinity)
|
|
55
|
+
finite(value.blur, 'shadow blur')
|
|
56
|
+
if (typeof value.color !== 'string' || !value.color.trim())
|
|
57
|
+
throw new RangeError('A shadow needs a color')
|
|
58
|
+
}
|
|
59
|
+
export function validateComponentTheme(value: ComponentTheme) {
|
|
60
|
+
for (const component of [value.button, value.input]) {
|
|
61
|
+
validateWeight(component.fontWeight)
|
|
62
|
+
finite(component.lineHeight, 'lineHeight', 1)
|
|
63
|
+
finite(component.paddingY, 'paddingY')
|
|
64
|
+
if (component.fontFamily !== undefined) freezeFamily(component.fontFamily)
|
|
65
|
+
}
|
|
66
|
+
finite(value.input.paddingX, 'paddingX')
|
|
67
|
+
if (value.input.fontSize !== undefined) finite(value.input.fontSize, 'fontSize', Number.EPSILON)
|
|
68
|
+
for (const component of [value.button, value.input, value.card]) {
|
|
69
|
+
if (typeof component.radius === 'number') finite(component.radius, 'radius')
|
|
70
|
+
else if (!['none', 'sm', 'md', 'lg', 'full'].includes(component.radius))
|
|
71
|
+
throw new RangeError('Invalid component radius')
|
|
72
|
+
}
|
|
73
|
+
for (const component of [value.button, value.card]) {
|
|
74
|
+
if (!['none', 'sm', 'md', 'lg'].includes(component.elevation))
|
|
75
|
+
throw new RangeError('Invalid elevation')
|
|
76
|
+
}
|
|
77
|
+
if (typeof value.card.padding === 'number') finite(value.card.padding, 'padding')
|
|
78
|
+
else if (!['none', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'].includes(value.card.padding))
|
|
79
|
+
throw new RangeError('Invalid card padding')
|
|
80
|
+
}
|
|
81
|
+
export function shadowStyle(value: Shadow, platform: 'web' | 'native' = 'web') {
|
|
82
|
+
const unit = platform === 'web' ? 'px' : 'dip'
|
|
83
|
+
return `${value.x}${unit} ${value.y}${unit} ${value.blur}${unit} ${value.spread}${unit} ${value.color}`
|
|
84
|
+
}
|