@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.
Files changed (242) hide show
  1. package/README.md +2 -2
  2. package/dist/accordion.d.ts +17 -0
  3. package/dist/accordion.d.ts.map +1 -0
  4. package/dist/accordion.js +42 -0
  5. package/dist/accordion.js.map +1 -0
  6. package/dist/alert.d.ts +21 -0
  7. package/dist/alert.d.ts.map +1 -0
  8. package/dist/alert.js +13 -0
  9. package/dist/alert.js.map +1 -0
  10. package/dist/avatar.d.ts +10 -0
  11. package/dist/avatar.d.ts.map +1 -0
  12. package/dist/avatar.js +11 -0
  13. package/dist/avatar.js.map +1 -0
  14. package/dist/badge.d.ts +7 -0
  15. package/dist/badge.d.ts.map +1 -0
  16. package/dist/badge.js +11 -0
  17. package/dist/badge.js.map +1 -0
  18. package/dist/capabilities.d.ts +119 -0
  19. package/dist/capabilities.d.ts.map +1 -0
  20. package/dist/capabilities.js +142 -0
  21. package/dist/capabilities.js.map +1 -0
  22. package/dist/chip.d.ts +9 -0
  23. package/dist/chip.d.ts.map +1 -0
  24. package/dist/chip.js +16 -0
  25. package/dist/chip.js.map +1 -0
  26. package/dist/choice.d.ts +15 -0
  27. package/dist/choice.d.ts.map +1 -0
  28. package/dist/choice.js +27 -0
  29. package/dist/choice.js.map +1 -0
  30. package/dist/combobox.d.ts +42 -0
  31. package/dist/combobox.d.ts.map +1 -0
  32. package/dist/combobox.js +159 -0
  33. package/dist/combobox.js.map +1 -0
  34. package/dist/contracts.d.ts +1201 -0
  35. package/dist/contracts.d.ts.map +1 -0
  36. package/dist/contracts.js +242 -0
  37. package/dist/contracts.js.map +1 -0
  38. package/dist/date.d.ts +96 -0
  39. package/dist/date.d.ts.map +1 -0
  40. package/dist/date.js +235 -0
  41. package/dist/date.js.map +1 -0
  42. package/dist/dialog.d.ts +4 -0
  43. package/dist/dialog.d.ts.map +1 -0
  44. package/dist/dialog.js +20 -0
  45. package/dist/dialog.js.map +1 -0
  46. package/dist/empty-state.d.ts +2 -0
  47. package/dist/empty-state.d.ts.map +1 -0
  48. package/dist/empty-state.js +5 -0
  49. package/dist/empty-state.js.map +1 -0
  50. package/dist/experimental-regions.d.ts +142 -0
  51. package/dist/experimental-regions.d.ts.map +1 -0
  52. package/dist/experimental-regions.js +315 -0
  53. package/dist/experimental-regions.js.map +1 -0
  54. package/dist/experimental.d.ts +134 -0
  55. package/dist/experimental.d.ts.map +1 -0
  56. package/dist/experimental.js +502 -0
  57. package/dist/experimental.js.map +1 -0
  58. package/dist/files.d.ts +87 -0
  59. package/dist/files.d.ts.map +1 -0
  60. package/dist/files.js +328 -0
  61. package/dist/files.js.map +1 -0
  62. package/dist/form.d.ts +39 -0
  63. package/dist/form.d.ts.map +1 -0
  64. package/dist/form.js +170 -0
  65. package/dist/form.js.map +1 -0
  66. package/dist/index.d.ts +38 -4
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +23 -1
  69. package/dist/index.js.map +1 -1
  70. package/dist/input.d.ts +10 -0
  71. package/dist/input.d.ts.map +1 -1
  72. package/dist/input.js +12 -0
  73. package/dist/input.js.map +1 -1
  74. package/dist/list-item.d.ts +3 -0
  75. package/dist/list-item.d.ts.map +1 -0
  76. package/dist/list-item.js +7 -0
  77. package/dist/list-item.js.map +1 -0
  78. package/dist/motion.d.ts +33 -0
  79. package/dist/motion.d.ts.map +1 -0
  80. package/dist/motion.js +21 -0
  81. package/dist/motion.js.map +1 -0
  82. package/dist/navigation.d.ts +22 -0
  83. package/dist/navigation.d.ts.map +1 -0
  84. package/dist/navigation.js +54 -0
  85. package/dist/navigation.js.map +1 -0
  86. package/dist/progress.d.ts +19 -0
  87. package/dist/progress.d.ts.map +1 -0
  88. package/dist/progress.js +19 -0
  89. package/dist/progress.js.map +1 -0
  90. package/dist/segmented.d.ts +11 -0
  91. package/dist/segmented.d.ts.map +1 -0
  92. package/dist/segmented.js +30 -0
  93. package/dist/segmented.js.map +1 -0
  94. package/dist/sheet.d.ts +8 -1
  95. package/dist/sheet.d.ts.map +1 -1
  96. package/dist/sheet.js +4 -3
  97. package/dist/sheet.js.map +1 -1
  98. package/dist/tabs.d.ts +11 -0
  99. package/dist/tabs.d.ts.map +1 -0
  100. package/dist/tabs.js +28 -0
  101. package/dist/tabs.js.map +1 -0
  102. package/dist/theme/themes.d.ts.map +1 -1
  103. package/dist/theme/themes.js +84 -11
  104. package/dist/theme/themes.js.map +1 -1
  105. package/dist/theme/types.d.ts +52 -1
  106. package/dist/theme/types.d.ts.map +1 -1
  107. package/dist/theme/typography.d.ts +10 -0
  108. package/dist/theme/typography.d.ts.map +1 -0
  109. package/dist/theme/typography.js +90 -0
  110. package/dist/theme/typography.js.map +1 -0
  111. package/dist/toast.d.ts +43 -0
  112. package/dist/toast.d.ts.map +1 -0
  113. package/dist/toast.js +228 -0
  114. package/dist/toast.js.map +1 -0
  115. package/dist/vue/button-content.d.ts +10 -0
  116. package/dist/vue/button-content.d.ts.map +1 -0
  117. package/dist/vue/button-content.js +54 -0
  118. package/dist/vue/button-content.js.map +1 -0
  119. package/dist/vue/cached-activity.d.ts +3 -0
  120. package/dist/vue/cached-activity.d.ts.map +1 -0
  121. package/dist/vue/cached-activity.js +13 -0
  122. package/dist/vue/cached-activity.js.map +1 -0
  123. package/dist/vue/combobox.d.ts +155 -0
  124. package/dist/vue/combobox.d.ts.map +1 -0
  125. package/dist/vue/combobox.js +195 -0
  126. package/dist/vue/combobox.js.map +1 -0
  127. package/dist/vue/component-props.d.ts +1989 -0
  128. package/dist/vue/component-props.d.ts.map +1 -0
  129. package/dist/vue/component-props.js +18 -0
  130. package/dist/vue/component-props.js.map +1 -0
  131. package/dist/vue/contracts.d.ts +18 -0
  132. package/dist/vue/contracts.d.ts.map +1 -0
  133. package/dist/vue/contracts.js +18 -0
  134. package/dist/vue/contracts.js.map +1 -0
  135. package/dist/vue/date-calendar.d.ts +64 -0
  136. package/dist/vue/date-calendar.d.ts.map +1 -0
  137. package/dist/vue/date-calendar.js +65 -0
  138. package/dist/vue/date-calendar.js.map +1 -0
  139. package/dist/vue/date-picker.d.ts +927 -0
  140. package/dist/vue/date-picker.d.ts.map +1 -0
  141. package/dist/vue/date-picker.js +319 -0
  142. package/dist/vue/date-picker.js.map +1 -0
  143. package/dist/vue/date-props.d.ts +254 -0
  144. package/dist/vue/date-props.d.ts.map +1 -0
  145. package/dist/vue/date-props.js +74 -0
  146. package/dist/vue/date-props.js.map +1 -0
  147. package/dist/vue/dialog.d.ts +21 -0
  148. package/dist/vue/dialog.d.ts.map +1 -0
  149. package/dist/vue/dialog.js +58 -0
  150. package/dist/vue/dialog.js.map +1 -0
  151. package/dist/vue/files.d.ts +53 -0
  152. package/dist/vue/files.d.ts.map +1 -0
  153. package/dist/vue/files.js +40 -0
  154. package/dist/vue/files.js.map +1 -0
  155. package/dist/vue/forms.d.ts +4 -0
  156. package/dist/vue/forms.d.ts.map +1 -0
  157. package/dist/vue/forms.js +15 -0
  158. package/dist/vue/forms.js.map +1 -0
  159. package/dist/vue/global-components.d.ts +129 -3
  160. package/dist/vue/global-components.d.ts.map +1 -1
  161. package/dist/vue/index.d.ts +28 -2
  162. package/dist/vue/index.d.ts.map +1 -1
  163. package/dist/vue/index.js +24 -1
  164. package/dist/vue/index.js.map +1 -1
  165. package/dist/vue/inline-content.d.ts +54 -0
  166. package/dist/vue/inline-content.d.ts.map +1 -0
  167. package/dist/vue/inline-content.js +64 -0
  168. package/dist/vue/inline-content.js.map +1 -0
  169. package/dist/vue/props.d.ts +2654 -637
  170. package/dist/vue/props.d.ts.map +1 -1
  171. package/dist/vue/props.js +228 -86
  172. package/dist/vue/props.js.map +1 -1
  173. package/dist/vue/theme-provider.d.ts +58 -0
  174. package/dist/vue/theme-provider.d.ts.map +1 -0
  175. package/dist/vue/theme-provider.js +69 -0
  176. package/dist/vue/theme-provider.js.map +1 -0
  177. package/dist/vue/theme.d.ts +962 -12
  178. package/dist/vue/theme.d.ts.map +1 -1
  179. package/dist/vue/theme.js +17 -7
  180. package/dist/vue/theme.js.map +1 -1
  181. package/dist/vue/toast.d.ts +29 -0
  182. package/dist/vue/toast.d.ts.map +1 -0
  183. package/dist/vue/toast.js +79 -0
  184. package/dist/vue/toast.js.map +1 -0
  185. package/dist/vue/workflow-props.d.ts +110 -0
  186. package/dist/vue/workflow-props.d.ts.map +1 -0
  187. package/dist/vue/workflow-props.js +37 -0
  188. package/dist/vue/workflow-props.js.map +1 -0
  189. package/dist/vue/workflows.d.ts +267 -0
  190. package/dist/vue/workflows.d.ts.map +1 -0
  191. package/dist/vue/workflows.js +200 -0
  192. package/dist/vue/workflows.js.map +1 -0
  193. package/package.json +5 -1
  194. package/src/accordion.ts +66 -0
  195. package/src/alert.ts +16 -0
  196. package/src/avatar.ts +11 -0
  197. package/src/badge.ts +11 -0
  198. package/src/capabilities.ts +145 -0
  199. package/src/chip.ts +20 -0
  200. package/src/choice.ts +41 -0
  201. package/src/combobox.ts +198 -0
  202. package/src/contracts.ts +295 -0
  203. package/src/date.ts +280 -0
  204. package/src/dialog.ts +20 -0
  205. package/src/empty-state.ts +4 -0
  206. package/src/experimental-regions.ts +463 -0
  207. package/src/experimental.ts +643 -0
  208. package/src/files.ts +408 -0
  209. package/src/form.ts +190 -0
  210. package/src/index.ts +64 -3
  211. package/src/input.ts +22 -0
  212. package/src/list-item.ts +5 -0
  213. package/src/motion.ts +22 -0
  214. package/src/navigation.ts +61 -0
  215. package/src/progress.ts +22 -0
  216. package/src/segmented.ts +39 -0
  217. package/src/sheet.ts +6 -3
  218. package/src/tabs.ts +35 -0
  219. package/src/theme/themes.ts +88 -11
  220. package/src/theme/types.ts +42 -1
  221. package/src/theme/typography.ts +84 -0
  222. package/src/toast.ts +249 -0
  223. package/src/vue/button-content.ts +60 -0
  224. package/src/vue/cached-activity.ts +13 -0
  225. package/src/vue/combobox.ts +238 -0
  226. package/src/vue/component-props.ts +24 -0
  227. package/src/vue/contracts.ts +33 -0
  228. package/src/vue/date-calendar.ts +76 -0
  229. package/src/vue/date-picker.ts +387 -0
  230. package/src/vue/date-props.ts +81 -0
  231. package/src/vue/dialog.ts +63 -0
  232. package/src/vue/files.ts +53 -0
  233. package/src/vue/forms.ts +20 -0
  234. package/src/vue/global-components.ts +120 -3
  235. package/src/vue/index.ts +46 -2
  236. package/src/vue/inline-content.ts +71 -0
  237. package/src/vue/props.ts +258 -95
  238. package/src/vue/theme-provider.ts +74 -0
  239. package/src/vue/theme.ts +17 -6
  240. package/src/vue/toast.ts +99 -0
  241. package/src/vue/workflow-props.ts +41 -0
  242. 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
  }
@@ -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
+ }
@@ -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
+ }
@@ -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
- if (!title && !label) {
15
- throw new RangeError('A sheet needs a title or an accessibilityLabel')
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
+ }
@@ -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: { fontSize: 56, fontWeight: '600', letterSpacing: -0.04 },
26
- title: { fontSize: 34, fontWeight: '600', letterSpacing: -0.035 },
27
- heading: { fontSize: 20, fontWeight: '600', letterSpacing: -0.02 },
28
- body: { fontSize: 16, fontWeight: 'normal', letterSpacing: 0 },
29
- caption: { fontSize: 13, fontWeight: 'normal', letterSpacing: 0 },
30
- overline: { fontSize: 11, fontWeight: '600', letterSpacing: 0.12 },
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
- typography[variant] = Object.freeze({
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
- if (!(theme.motion.pressScale > 0 && theme.motion.pressScale <= 1)) {
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
  },
@@ -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: 'normal' | '500' | '600' | 'bold'
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
+ }