@m3ui-vue/m3ui-vue 0.9.1 → 0.9.3

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 (139) hide show
  1. package/README.md +43 -0
  2. package/dist/API.md +266 -60
  3. package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
  4. package/dist/MIcon-DLOkQduI.js.map +1 -0
  5. package/dist/{MTextField-pJU1vFaR.js → MTextField-DKtgPymd.js} +422 -206
  6. package/dist/MTextField-DKtgPymd.js.map +1 -0
  7. package/dist/THIRD_PARTY_LICENSES.md +547 -0
  8. package/dist/api.json +1 -1
  9. package/dist/code-editor.js +2 -2
  10. package/dist/components/MBox.vue.d.ts +3 -3
  11. package/dist/components/MButton.vue.d.ts +4 -2
  12. package/dist/components/MButtonGroup.vue.d.ts +2 -0
  13. package/dist/components/MColorPicker.vue.d.ts +13 -1
  14. package/dist/components/MColorPickerModal.vue.d.ts +14 -2
  15. package/dist/components/MDragHandle.vue.d.ts +12 -0
  16. package/dist/components/MEmojiSelector.vue.d.ts +1 -1
  17. package/dist/components/MFab.vue.d.ts +5 -3
  18. package/dist/components/MFabMenu.vue.d.ts +1 -1
  19. package/dist/components/MIcon.vue.d.ts +3 -0
  20. package/dist/components/MIconButton.vue.d.ts +15 -1
  21. package/dist/components/MListItem.vue.d.ts +5 -5
  22. package/dist/components/MMenuItem.vue.d.ts +17 -4
  23. package/dist/components/MOverlay.vue.d.ts +1 -1
  24. package/dist/components/MScrollField.vue.d.ts +40 -0
  25. package/dist/components/MScrollable.vue.d.ts +9 -0
  26. package/dist/components/MSplitButton.vue.d.ts +2 -0
  27. package/dist/components/MSplitter.vue.d.ts +2 -2
  28. package/dist/components/MSwipeToDismiss.vue.d.ts +49 -0
  29. package/dist/components/MTabs.vue.d.ts +6 -0
  30. package/dist/components/MTimePickerModal.vue.d.ts +3 -0
  31. package/dist/components/MTimeScroll.vue.d.ts +22 -0
  32. package/dist/components/MToggleButton.vue.d.ts +2 -0
  33. package/dist/components/MTransition.vue.d.ts +34 -0
  34. package/dist/components/MTree.vue.d.ts +2 -2
  35. package/dist/components/MWindow.vue.d.ts +1 -1
  36. package/dist/components/_MColorPanel.vue.d.ts +18 -0
  37. package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
  38. package/dist/composables/_colorUtils.d.ts +34 -0
  39. package/dist/composables/_themeColor.d.ts +1 -0
  40. package/dist/composables/_useSpring.d.ts +17 -0
  41. package/dist/composables/dynamicColor.d.ts +18 -0
  42. package/dist/composables/useColorPalette.d.ts +27 -0
  43. package/dist/composables/useLocale.d.ts +16 -0
  44. package/dist/directives/vRipple.d.ts +16 -0
  45. package/dist/emoji-names-de-BphO5XpV.js.map +1 -1
  46. package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -1
  47. package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -1
  48. package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -1
  49. package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -1
  50. package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -1
  51. package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -1
  52. package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -1
  53. package/dist/index.d.ts +12 -1
  54. package/dist/locales/index.js +112 -0
  55. package/dist/locales/index.js.map +1 -1
  56. package/dist/m3ui-vue.css +1 -1
  57. package/dist/m3ui.js +7443 -6150
  58. package/dist/m3ui.js.map +1 -1
  59. package/dist/material-color-utilities-Cktu8DBU.js +3160 -0
  60. package/dist/material-color-utilities-Cktu8DBU.js.map +1 -0
  61. package/dist/plugin.d.ts +18 -0
  62. package/dist/rich-text-editor.js +22 -22
  63. package/dist/styles/palettes.css +546 -0
  64. package/dist/styles/theme.css +90 -0
  65. package/dist/styles.css +1 -1
  66. package/dist/terminal.js +1 -1
  67. package/dist/{useLocale-Drihe5G2.js → useLocale-Cn9MVIdw.js} +17 -1
  68. package/dist/useLocale-Cn9MVIdw.js.map +1 -0
  69. package/package.json +3 -2
  70. package/src/__tests__/MButtonGroup.test.ts +51 -0
  71. package/src/__tests__/MColorPicker.test.ts +141 -0
  72. package/src/__tests__/MDragHandle.test.ts +57 -0
  73. package/src/__tests__/MIconButton.test.ts +60 -0
  74. package/src/__tests__/MListItemShape.test.ts +76 -0
  75. package/src/__tests__/MMenuItem.test.ts +84 -0
  76. package/src/__tests__/MScrollField.test.ts +69 -0
  77. package/src/__tests__/MScrollable.test.ts +42 -0
  78. package/src/__tests__/MSwipeToDismiss.test.ts +104 -0
  79. package/src/__tests__/MTabs.test.ts +39 -0
  80. package/src/__tests__/MTimePickerModal.test.ts +52 -0
  81. package/src/__tests__/MTimeScroll.test.ts +44 -0
  82. package/src/__tests__/MTransition.test.ts +27 -0
  83. package/src/__tests__/dynamicColor.test.ts +191 -0
  84. package/src/__tests__/vRipple.test.ts +92 -0
  85. package/src/components/MBox.vue +4 -2
  86. package/src/components/MButton.vue +4 -13
  87. package/src/components/MButtonGroup.vue +118 -44
  88. package/src/components/MColorPicker.vue +114 -210
  89. package/src/components/MColorPickerModal.vue +50 -251
  90. package/src/components/MDragHandle.vue +54 -0
  91. package/src/components/MFab.vue +8 -15
  92. package/src/components/MIcon.vue +4 -2
  93. package/src/components/MIconButton.vue +96 -24
  94. package/src/components/MList.vue +33 -3
  95. package/src/components/MListItem.vue +75 -5
  96. package/src/components/MMenuItem.vue +115 -13
  97. package/src/components/MScrollField.vue +310 -0
  98. package/src/components/MScrollable.vue +160 -5
  99. package/src/components/MSplitButton.vue +5 -12
  100. package/src/components/MSplitter.vue +33 -10
  101. package/src/components/MSwipeToDismiss.vue +247 -0
  102. package/src/components/MTabs.vue +16 -5
  103. package/src/components/MTimePickerModal.vue +48 -8
  104. package/src/components/MTimeScroll.vue +161 -0
  105. package/src/components/MToggleButton.vue +5 -12
  106. package/src/components/MTransition.vue +149 -0
  107. package/src/components/_MColorPanel.vue +478 -0
  108. package/src/composables/_carouselStrategy.ts +3 -0
  109. package/src/composables/_colorUtils.ts +107 -0
  110. package/src/composables/_themeColor.ts +33 -0
  111. package/src/composables/_useSpring.ts +91 -0
  112. package/src/composables/dynamicColor.ts +85 -0
  113. package/src/composables/useColorPalette.ts +171 -25
  114. package/src/composables/useFieldBg.ts +6 -0
  115. package/src/composables/useLocale.ts +34 -0
  116. package/src/data/emoji-names/emoji-names-de.ts +1 -0
  117. package/src/data/emoji-names/emoji-names-en.ts +1 -0
  118. package/src/data/emoji-names/emoji-names-es.ts +1 -0
  119. package/src/data/emoji-names/emoji-names-fr.ts +1 -0
  120. package/src/data/emoji-names/emoji-names-ja.ts +1 -0
  121. package/src/data/emoji-names/emoji-names-ko.ts +1 -0
  122. package/src/data/emoji-names/emoji-names-pt.ts +1 -0
  123. package/src/data/emoji-names/emoji-names-zh.ts +1 -0
  124. package/src/data/emojis.ts +1 -0
  125. package/src/directives/vRipple.ts +73 -0
  126. package/src/index.ts +14 -1
  127. package/src/locales/de.ts +16 -0
  128. package/src/locales/es.ts +16 -0
  129. package/src/locales/fr.ts +16 -0
  130. package/src/locales/ja.ts +16 -0
  131. package/src/locales/ko.ts +16 -0
  132. package/src/locales/pt.ts +16 -0
  133. package/src/locales/zh.ts +16 -0
  134. package/src/plugin.ts +30 -7
  135. package/src/styles/palettes.css +546 -0
  136. package/src/styles/theme.css +90 -0
  137. package/dist/MIcon-CaEooCmZ.js.map +0 -1
  138. package/dist/MTextField-pJU1vFaR.js.map +0 -1
  139. package/dist/useLocale-Drihe5G2.js.map +0 -1
@@ -0,0 +1,107 @@
1
+ // Internal color math shared by MColorPicker and MColorPickerModal (through _MColorPanel).
2
+ // Not exported from index.ts.
3
+ import { ref } from 'vue'
4
+
5
+ export interface Rgba { r: number; g: number; b: number; a: number }
6
+ /** h 0–360, s/v 0–100 */
7
+ export interface Hsv { h: number; s: number; v: number }
8
+ /** h 0–360, s/l 0–100 */
9
+ export interface Hsl { h: number; s: number; l: number }
10
+
11
+ /** Parses `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa` (the `#` is optional). r/g/b 0–255, a 0–1. */
12
+ export function parseHex(input: string): Rgba | null {
13
+ let c = input.trim().replace(/^#/, '')
14
+ if (!/^([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(c)) return null
15
+ if (c.length <= 4) c = [...c].map((ch) => ch + ch).join('')
16
+ const n = (i: number) => parseInt(c.substring(i, i + 2), 16)
17
+ return { r: n(0), g: n(2), b: n(4), a: c.length === 8 ? n(6) / 255 : 1 }
18
+ }
19
+
20
+ /** `#rrggbb`, or `#rrggbbaa` when a < 1. Lowercase. */
21
+ export function toHex({ r, g, b, a }: Rgba): string {
22
+ const h = (n: number) => Math.round(Math.max(0, Math.min(255, n))).toString(16).padStart(2, '0')
23
+ return `#${h(r)}${h(g)}${h(b)}${a < 1 ? h(a * 255) : ''}`
24
+ }
25
+
26
+ /** Lowercase canonical form of a hex string, or '' when it isn't one. */
27
+ export function normalizeHex(input: string): string {
28
+ const c = parseHex(input)
29
+ return c ? toHex(c) : ''
30
+ }
31
+
32
+ export function rgbToHsv({ r, g, b }: Rgba): Hsv {
33
+ r /= 255; g /= 255; b /= 255
34
+ const max = Math.max(r, g, b), d = max - Math.min(r, g, b)
35
+ let h = 0
36
+ if (d !== 0) {
37
+ if (max === r) h = ((g - b) / d + 6) % 6
38
+ else if (max === g) h = (b - r) / d + 2
39
+ else h = (r - g) / d + 4
40
+ h *= 60
41
+ }
42
+ return { h, s: max === 0 ? 0 : (d / max) * 100, v: max * 100 }
43
+ }
44
+
45
+ export function hsvToRgb({ h, s, v }: Hsv, a = 1): Rgba {
46
+ s /= 100; v /= 100
47
+ const f = (n: number) => {
48
+ const k = (n + h / 60) % 6
49
+ return (v - v * s * Math.max(0, Math.min(k, 4 - k, 1))) * 255
50
+ }
51
+ return { r: f(5), g: f(3), b: f(1), a }
52
+ }
53
+
54
+ export function hsvToHsl({ h, s, v }: Hsv): Hsl {
55
+ s /= 100; v /= 100
56
+ const l = v * (1 - s / 2)
57
+ const sl = l === 0 || l === 1 ? 0 : (v - l) / Math.min(l, 1 - l)
58
+ return { h, s: sl * 100, l: l * 100 }
59
+ }
60
+
61
+ export function hslToHsv({ h, s, l }: Hsl): Hsv {
62
+ s /= 100; l /= 100
63
+ const v = l + s * Math.min(l, 1 - l)
64
+ return { h, s: v === 0 ? 0 : 2 * (1 - l / v) * 100, v: v * 100 }
65
+ }
66
+
67
+ /** Black or white, whichever reads better on the color (WCAG relative luminance). */
68
+ export function inkFor(hex: string): '#000000' | '#ffffff' {
69
+ const c = parseHex(hex)
70
+ if (!c) return '#000000'
71
+ const lin = (n: number) => {
72
+ n /= 255
73
+ return n <= 0.03928 ? n / 12.92 : ((n + 0.055) / 1.055) ** 2.4
74
+ }
75
+ const lum = 0.2126 * lin(c.r) + 0.7152 * lin(c.g) + 0.0722 * lin(c.b)
76
+ // Contrast against black beats contrast against white above ~0.179
77
+ return lum > 0.179 ? '#000000' : '#ffffff'
78
+ }
79
+
80
+ // ── Recent colors (per viewer, localStorage, shared by every picker on the page) ──────────────
81
+
82
+ const RECENT_KEY = 'm3-color-recent'
83
+
84
+ function readRecents(): string[] {
85
+ try {
86
+ const v = JSON.parse(localStorage.getItem(RECENT_KEY) ?? '[]')
87
+ return Array.isArray(v) ? v.filter((x): x is string => typeof x === 'string' && !!parseHex(x)) : []
88
+ } catch {
89
+ return []
90
+ }
91
+ }
92
+
93
+ export const recentColors = ref<string[]>(readRecents())
94
+
95
+ export function pushRecentColor(hex: string, limit: number) {
96
+ const c = normalizeHex(hex)
97
+ if (!c) return
98
+ recentColors.value = [c, ...recentColors.value.filter((x) => x !== c)].slice(0, Math.max(limit, 0))
99
+ try { localStorage.setItem(RECENT_KEY, JSON.stringify(recentColors.value)) } catch { /* storage blocked */ }
100
+ }
101
+
102
+ /** Default swatches for both pickers: the Material 2014 palette's 500 tones plus grey, black and white (3 rows of 7) */
103
+ export const defaultColorPresets = [
104
+ '#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3', '#03a9f4',
105
+ '#00bcd4', '#009688', '#4caf50', '#8bc34a', '#cddc39', '#ffeb3b', '#ffc107',
106
+ '#ff9800', '#ff5722', '#795548', '#607d8b', '#9e9e9e', '#000000', '#ffffff',
107
+ ]
@@ -0,0 +1,33 @@
1
+ // Internal: keeps <meta name="theme-color"> (the browser bar / status bar color on phones) in sync with a color
2
+ // role of the active palette, dark mode and seed included. Started by createM3UI({ themeColor }).
3
+
4
+ let observer: MutationObserver | undefined
5
+
6
+ function metas(): HTMLMetaElement[] {
7
+ const found = Array.from(document.querySelectorAll<HTMLMetaElement>('meta[name="theme-color"]'))
8
+ if (found.length) return found
9
+ const meta = document.createElement('meta')
10
+ meta.name = 'theme-color'
11
+ document.head.appendChild(meta)
12
+ return [meta]
13
+ }
14
+
15
+ function update(role: string) {
16
+ const color = getComputedStyle(document.documentElement).getPropertyValue(`--color-${role}`).trim()
17
+ if (!color) return
18
+ for (const meta of metas()) {
19
+ // A media-scoped pair (light/dark) would fight the live value: one meta, kept current, replaces them
20
+ meta.removeAttribute('media')
21
+ if (meta.content !== color) meta.content = color
22
+ }
23
+ }
24
+
25
+ export function syncThemeColor(role: string) {
26
+ if (typeof document === 'undefined') return
27
+ observer?.disconnect()
28
+ update(role)
29
+ // Palette (data-palette), dark mode and palette switches (class: dark, theme-transitioning) all land on <html>;
30
+ // a new seed also toggles theme-transitioning, after its CSS is in place
31
+ observer = new MutationObserver(() => update(role))
32
+ observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'data-palette'] })
33
+ }
@@ -0,0 +1,91 @@
1
+ // Internal: a set of numbers (corner radii, sizes...) that springs toward a target, written to the DOM
2
+ // once per frame through `apply`. Same integration as the rest of the library (semi-implicit Euler),
3
+ // in fixed 4ms substeps so a stiff spring stays stable on a dropped frame. Not exported from index.ts.
4
+ import { onMounted, onUnmounted, watch } from 'vue'
5
+
6
+ export interface SpringSpec { dampingRatio: number; stiffness: number }
7
+
8
+ /** MotionSchemeKeyTokens.FastSpatial in the Standard scheme (StandardMotionTokens.SpringFastSpatial*) */
9
+ export const FAST_SPATIAL: SpringSpec = { dampingRatio: 0.9, stiffness: 1400 }
10
+ /** MotionSchemeKeyTokens.FastEffects in the Standard scheme */
11
+ export const FAST_EFFECTS: SpringSpec = { dampingRatio: 1, stiffness: 3800 }
12
+ /** MotionSchemeKeyTokens.DefaultEffects in the Standard scheme */
13
+ export const DEFAULT_EFFECTS: SpringSpec = { dampingRatio: 1, stiffness: 1600 }
14
+ /** MotionSchemeKeyTokens.DefaultSpatial in the Standard scheme */
15
+ export const DEFAULT_SPATIAL: SpringSpec = { dampingRatio: 0.9, stiffness: 700 }
16
+
17
+ const SUBSTEP = 0.004
18
+
19
+ export function useSpring(
20
+ target: () => number[],
21
+ apply: (values: readonly number[]) => void,
22
+ spec: SpringSpec = FAST_SPATIAL,
23
+ ) {
24
+ let current = [...target()]
25
+ let velocity = current.map(() => 0)
26
+ let raf = 0
27
+ let last = 0
28
+
29
+ function frame(now: number) {
30
+ let dt = Math.min((now - last) / 1000, 1 / 30)
31
+ last = now
32
+ const t = target()
33
+ if (t.length !== current.length) {
34
+ current = [...t]
35
+ velocity = t.map(() => 0)
36
+ }
37
+ const k = spec.stiffness
38
+ const c = 2 * spec.dampingRatio * Math.sqrt(k)
39
+ while (dt > 0) {
40
+ const h = Math.min(dt, SUBSTEP)
41
+ dt -= h
42
+ for (let i = 0; i < t.length; i++) {
43
+ velocity[i]! += (-k * (current[i]! - t[i]!) - c * velocity[i]!) * h
44
+ current[i]! += velocity[i]! * h
45
+ }
46
+ }
47
+ const settled = t.every((v, i) => Math.abs(v - current[i]!) < 0.05 && Math.abs(velocity[i]!) < 0.05)
48
+ if (settled) {
49
+ current = [...t]
50
+ velocity = t.map(() => 0)
51
+ }
52
+ apply(current)
53
+ raf = settled ? 0 : requestAnimationFrame(frame)
54
+ }
55
+
56
+ function start() {
57
+ if (raf) return
58
+ last = performance.now()
59
+ raf = requestAnimationFrame(frame)
60
+ }
61
+
62
+ /** Jumps to the target without animating (e.g. when the layout context changes). */
63
+ function snap() {
64
+ cancelAnimationFrame(raf)
65
+ raf = 0
66
+ current = [...target()]
67
+ velocity = current.map(() => 0)
68
+ apply(current)
69
+ }
70
+
71
+ watch(() => target().join(','), start)
72
+ onMounted(() => apply(current))
73
+ onUnmounted(() => cancelAnimationFrame(raf))
74
+
75
+ return { snap }
76
+ }
77
+
78
+ /** Compose's FastOutSlowInEasing, cubic-bezier(0.4, 0, 0.2, 1) — the easing of a default tween() */
79
+ export function fastOutSlowIn(t: number): number {
80
+ if (t <= 0) return 0
81
+ if (t >= 1) return 1
82
+ // Solve x(u) = t for the curve parameter u (Newton), then return y(u)
83
+ let u = t
84
+ for (let i = 0; i < 8; i++) {
85
+ const x = 3 * u * (1 - u) ** 2 * 0.4 + 3 * u ** 2 * (1 - u) * 0.2 + u ** 3 - t
86
+ const dx = 3 * (1 - u) ** 2 * 0.4 + 6 * u * (1 - u) * (0.2 - 0.4) + 3 * u ** 2 * 0.8
87
+ if (Math.abs(dx) < 1e-6) break
88
+ u -= x / dx
89
+ }
90
+ return 3 * u ** 2 * (1 - u) + u ** 3
91
+ }
@@ -0,0 +1,85 @@
1
+ // Dynamic color: a full M3 color scheme (light and dark) generated from one seed color with Google's
2
+ // material-color-utilities (HCT, DynamicScheme). The package is loaded with a dynamic import, so apps that
3
+ // never use a seed don't download it; it's bundled into the library (its 0.4.0 ESM build has an extensionless
4
+ // import that Node can't resolve, which would break SSR and tests if it were left external).
5
+
6
+ export type SchemeVariant =
7
+ | 'tonal-spot'
8
+ | 'expressive'
9
+ | 'vibrant'
10
+ | 'fidelity'
11
+ | 'content'
12
+ | 'neutral'
13
+ | 'monochrome'
14
+ | 'rainbow'
15
+ | 'fruit-salad'
16
+
17
+ export interface SeedOptions {
18
+ /** How the seed spreads into the scheme. `tonal-spot` is Android's default (calm, seed-led). */
19
+ variant?: SchemeVariant
20
+ /** Contrast level: 0 standard, 0.5 medium, 1 high (-1 reduced). */
21
+ contrast?: number
22
+ }
23
+
24
+ /** Token name (as in `--color-<name>`) → hex, for each scheme. */
25
+ export interface GeneratedScheme {
26
+ light: Record<string, string>
27
+ dark: Record<string, string>
28
+ }
29
+
30
+ /** The `--color-*` roles a generated scheme sets. `success*` is a library extension and stays as themed. */
31
+ export const schemeRoles = [
32
+ 'primary', 'on-primary', 'primary-container', 'on-primary-container',
33
+ 'secondary', 'on-secondary', 'secondary-container', 'on-secondary-container',
34
+ 'tertiary', 'on-tertiary', 'tertiary-container', 'on-tertiary-container',
35
+ 'error', 'on-error', 'error-container', 'on-error-container',
36
+ 'background', 'on-background',
37
+ 'surface', 'on-surface', 'surface-variant', 'on-surface-variant',
38
+ 'surface-dim', 'surface-bright',
39
+ 'surface-container-lowest', 'surface-container-low', 'surface-container',
40
+ 'surface-container-high', 'surface-container-highest',
41
+ 'outline', 'outline-variant',
42
+ 'inverse-surface', 'inverse-on-surface', 'inverse-primary',
43
+ 'scrim', 'shadow',
44
+ 'primary-fixed', 'primary-fixed-dim', 'on-primary-fixed', 'on-primary-fixed-variant',
45
+ 'secondary-fixed', 'secondary-fixed-dim', 'on-secondary-fixed', 'on-secondary-fixed-variant',
46
+ 'tertiary-fixed', 'tertiary-fixed-dim', 'on-tertiary-fixed', 'on-tertiary-fixed-variant',
47
+ ] as const
48
+
49
+ const camel = (role: string) => role.replace(/-([a-z])/g, (_, c: string) => c.toUpperCase())
50
+
51
+ /** Generates the light and dark schemes for a seed color (`#rrggbb`). */
52
+ export async function generateScheme(seed: string, options: SeedOptions = {}): Promise<GeneratedScheme> {
53
+ const mcu = await import('@material/material-color-utilities')
54
+ const variants = {
55
+ 'tonal-spot': mcu.SchemeTonalSpot,
56
+ expressive: mcu.SchemeExpressive,
57
+ vibrant: mcu.SchemeVibrant,
58
+ fidelity: mcu.SchemeFidelity,
59
+ content: mcu.SchemeContent,
60
+ neutral: mcu.SchemeNeutral,
61
+ monochrome: mcu.SchemeMonochrome,
62
+ rainbow: mcu.SchemeRainbow,
63
+ 'fruit-salad': mcu.SchemeFruitSalad,
64
+ }
65
+ const Scheme = variants[options.variant ?? 'tonal-spot'] ?? mcu.SchemeTonalSpot
66
+ const source = mcu.Hct.fromInt(mcu.argbFromHex(seed))
67
+ const colors = new mcu.MaterialDynamicColors() as unknown as Record<string, () => { getArgb(s: unknown): number }>
68
+ const build = (dark: boolean) => {
69
+ const scheme = new Scheme(source, dark, options.contrast ?? 0)
70
+ const out: Record<string, string> = {}
71
+ for (const role of schemeRoles) {
72
+ const color = colors[camel(role)]?.call(colors)
73
+ if (color) out[role] = mcu.hexFromArgb(color.getArgb(scheme))
74
+ }
75
+ return out
76
+ }
77
+ return { light: build(false), dark: build(true) }
78
+ }
79
+
80
+ /** CSS for a scheme under `[data-palette='<id>']` (light) and `[data-palette='<id>'].dark`, like palettes.css. */
81
+ export function schemeToCss(scheme: GeneratedScheme, id: string): string {
82
+ const block = (tokens: Record<string, string>) =>
83
+ Object.entries(tokens).map(([k, v]) => ` --color-${k}: ${v};`).join('\n')
84
+ return `[data-palette='${id}'] {\n${block(scheme.light)}\n}\n[data-palette='${id}'].dark {\n color-scheme: dark;\n${block(scheme.dark)}\n}\n`
85
+ }
@@ -1,8 +1,13 @@
1
- import { ref, watchEffect } from 'vue'
1
+ import { readonly, ref, watchEffect } from 'vue'
2
+ import { generateScheme, schemeToCss, type SeedOptions } from './dynamicColor'
2
3
 
3
4
  export interface Palette {
4
5
  id: string
5
6
  label: string
7
+ /**
8
+ * The palette's key color. A custom palette (`createM3UI({ customPalettes })`) with no CSS of its own gets its
9
+ * scheme generated from it; one with `[data-palette='<id>']` rules keeps them.
10
+ */
6
11
  seed: string
7
12
  }
8
13
 
@@ -49,44 +54,171 @@ export const palettes: Palette[] = [
49
54
  { id: 'mauve', label: 'Mauve', seed: '#914277' },
50
55
  ]
51
56
 
52
- const current = ref(localStorage.getItem('m3-palette') ?? 'purple')
57
+ // Ids whose CSS ships in palettes.css (plus 'purple', the theme.css baseline): never generated
58
+ const builtInIds = new Set(palettes.map((p) => p.id))
59
+
60
+ /** The palette id used while a seed color is active (`useColorPalette().setSeed()`). */
61
+ export const SEED_PALETTE = 'seed'
62
+
63
+ export interface ActiveSeed extends SeedOptions {
64
+ seed: string
65
+ }
66
+
67
+ const PALETTE_KEY = 'm3-palette'
68
+ const SEED_KEY = 'm3-seed'
69
+ // The generated CSS of the active palette, so a reload applies it before the generator has loaded
70
+ const CSS_KEY = 'm3-palette-css'
71
+
72
+ function read<T>(key: string): T | null {
73
+ try {
74
+ const v = localStorage.getItem(key)
75
+ return v == null ? null : (key === PALETTE_KEY ? v : JSON.parse(v)) as T
76
+ } catch {
77
+ return null
78
+ }
79
+ }
80
+ function write(key: string, value: unknown) {
81
+ try {
82
+ if (value == null) localStorage.removeItem(key)
83
+ else localStorage.setItem(key, typeof value === 'string' ? value : JSON.stringify(value))
84
+ } catch { /* storage blocked */ }
85
+ }
86
+
87
+ const current = ref(read<string>(PALETTE_KEY) ?? 'purple')
88
+ const activeSeed = ref<ActiveSeed | null>(read<ActiveSeed>(SEED_KEY))
53
89
 
54
90
  // Whether palette changes are written to localStorage. Defaults to true (existing behavior).
55
91
  // An app can disable it via `createM3UI({ persistPalette: false })` or `useColorPalette().setPersistPalette(false)`
56
92
  // so its chosen palette can't be overridden by a stored value on the next boot.
57
93
  const persistEnabled = ref(true)
58
94
 
95
+ function applyAttribute(id: string) {
96
+ if (id === 'purple') document.documentElement.removeAttribute('data-palette')
97
+ else document.documentElement.setAttribute('data-palette', id)
98
+ }
99
+
100
+ // ── Generated palettes ──────────────────────────────────────────────────────────────────────────
101
+ // One <style> element holds the generated CSS of the active palette (a seed, or a custom palette
102
+ // without CSS of its own).
103
+
104
+ const STYLE_ID = 'm3-dynamic-palette'
105
+
106
+ function injectCss(css: string) {
107
+ let el = document.getElementById(STYLE_ID) as HTMLStyleElement | null
108
+ if (!el) {
109
+ el = document.createElement('style')
110
+ el.id = STYLE_ID
111
+ document.head.appendChild(el)
112
+ }
113
+ el.textContent = css
114
+ }
115
+
116
+ /** Whether a stylesheet (other than our generated one) already styles `[data-palette='<id>']`. */
117
+ function hasPaletteCss(id: string): boolean {
118
+ const needles = [`[data-palette="${id}"]`, `[data-palette='${id}']`, `[data-palette=${id}]`]
119
+ const scan = (rules: CSSRuleList): boolean => {
120
+ for (const rule of Array.from(rules)) {
121
+ const selector = (rule as CSSStyleRule).selectorText
122
+ if (selector && needles.some((n) => selector.includes(n))) return true
123
+ const nested = (rule as CSSGroupingRule).cssRules
124
+ if (nested && scan(nested)) return true
125
+ }
126
+ return false
127
+ }
128
+ for (const sheet of Array.from(document.styleSheets)) {
129
+ if ((sheet.ownerNode as Element | null)?.id === STYLE_ID) continue
130
+ try {
131
+ if (scan(sheet.cssRules)) return true
132
+ } catch { /* cross-origin sheet */ }
133
+ }
134
+ return false
135
+ }
136
+
137
+ let generation = 0
138
+
139
+ /** Generates and injects the CSS for a palette id from a seed. Resolves false if a newer request won. */
140
+ async function generateInto(id: string, seed: ActiveSeed): Promise<boolean> {
141
+ const mine = ++generation
142
+ const css = schemeToCss(await generateScheme(seed.seed, seed), id)
143
+ if (mine !== generation) return false
144
+ injectCss(css)
145
+ if (persistEnabled.value) write(CSS_KEY, { id, css })
146
+ return true
147
+ }
148
+
149
+ /** Switches to a palette id with the theme transition. Applied directly, not only through useColorPalette()'s
150
+ * watcher, so it also works when no component uses the composable (createM3UI's defaults). */
151
+ function switchTo(id: string) {
152
+ document.documentElement.classList.add('theme-transitioning')
153
+ void document.documentElement.offsetHeight
154
+ current.value = id
155
+ applyAttribute(id)
156
+ if (persistEnabled.value) write(PALETTE_KEY, id)
157
+ setTimeout(() => document.documentElement.classList.remove('theme-transitioning'), 300)
158
+ }
159
+
160
+ /** Picks a palette by id; a custom one with a seed and no CSS of its own is generated first. */
161
+ async function selectPalette(id: string) {
162
+ generation++
163
+ const custom = palettes.find((p) => p.id === id)
164
+ if (custom && !builtInIds.has(id) && custom.seed && !hasPaletteCss(id)) {
165
+ if (!(await generateInto(id, { seed: custom.seed }))) return
166
+ }
167
+ switchTo(id)
168
+ }
169
+
170
+ /** Activates a seed color: generates its scheme and switches to it. */
171
+ async function selectSeed(seed: string, options: SeedOptions = {}) {
172
+ const next: ActiveSeed = { seed, ...options }
173
+ if (!(await generateInto(SEED_PALETTE, next))) return
174
+ activeSeed.value = next
175
+ if (persistEnabled.value) write(SEED_KEY, next)
176
+ switchTo(SEED_PALETTE)
177
+ }
178
+
59
179
  export function useColorPalette() {
60
180
  watchEffect(() => {
61
181
  const id = current.value
62
- if (persistEnabled.value) localStorage.setItem('m3-palette', id)
63
-
64
- if (id === 'purple') {
65
- document.documentElement.removeAttribute('data-palette')
66
- } else {
67
- document.documentElement.setAttribute('data-palette', id)
68
- }
182
+ if (persistEnabled.value) write(PALETTE_KEY, id)
183
+ applyAttribute(id)
69
184
  })
70
185
 
186
+ /** Switches to a palette by id. */
71
187
  function set(id: string) {
72
- document.documentElement.classList.add('theme-transitioning')
73
- void document.documentElement.offsetHeight
74
- current.value = id
75
- setTimeout(() => document.documentElement.classList.remove('theme-transitioning'), 300)
188
+ void selectPalette(id)
189
+ }
190
+
191
+ /**
192
+ * Switches to a scheme generated from a seed color (Google's dynamic color: HCT, `tonal-spot` by default).
193
+ * `palette` becomes `'seed'`. The last choice wins: `set(id)` afterwards switches back to that palette, and
194
+ * `seed` keeps the last seed so a picker can offer it again.
195
+ */
196
+ function setSeed(seed: string, options?: SeedOptions) {
197
+ return selectSeed(seed, options)
76
198
  }
77
199
 
78
200
  function setPersistPalette(enabled: boolean) {
79
201
  persistEnabled.value = enabled
80
- if (enabled) localStorage.setItem('m3-palette', current.value)
202
+ if (enabled) write(PALETTE_KEY, current.value)
81
203
  }
82
204
 
83
- return { palette: current, palettes, set, persistPalette: persistEnabled, setPersistPalette }
205
+ return {
206
+ palette: current,
207
+ palettes,
208
+ set,
209
+ seed: readonly(activeSeed),
210
+ setSeed,
211
+ persistPalette: persistEnabled,
212
+ setPersistPalette,
213
+ }
84
214
  }
85
215
 
86
- // Apply on module load so palette is visible before any component mounts
87
- const saved = localStorage.getItem('m3-palette')
88
- if (saved && saved !== 'purple') {
89
- document.documentElement.setAttribute('data-palette', saved)
216
+ // Apply on module load so the palette is visible before any component mounts, a generated one included
217
+ {
218
+ const saved = read<string>(PALETTE_KEY)
219
+ const cached = read<{ id: string; css: string }>(CSS_KEY)
220
+ if (saved && cached && cached.id === saved) injectCss(cached.css)
221
+ if (saved && saved !== 'purple') document.documentElement.setAttribute('data-palette', saved)
90
222
  }
91
223
 
92
224
  /**
@@ -98,10 +230,24 @@ if (saved && saved !== 'purple') {
98
230
  export function __forcePalette(id: string, persist: boolean) {
99
231
  persistEnabled.value = persist
100
232
  current.value = id
101
- if (id === 'purple') {
102
- document.documentElement.removeAttribute('data-palette')
103
- } else {
104
- document.documentElement.setAttribute('data-palette', id)
105
- }
106
- if (persist) localStorage.setItem('m3-palette', id)
233
+ applyAttribute(id)
234
+ if (persist) write(PALETTE_KEY, id)
235
+ if (palettes.some((p) => p.id === id) && !builtInIds.has(id)) void selectPalette(id)
236
+ }
237
+
238
+ /**
239
+ * Internal: `createM3UI({ palette })`'s first-visit default. Sets `current` too, so a later `useColorPalette()`
240
+ * doesn't write its stale initial value back over it.
241
+ */
242
+ export function __defaultPalette(id: string) {
243
+ current.value = id
244
+ applyAttribute(id)
245
+ write(PALETTE_KEY, id)
246
+ if (palettes.some((p) => p.id === id) && !builtInIds.has(id)) void selectPalette(id)
247
+ }
248
+
249
+ /** Internal: `createM3UI({ seed })`. */
250
+ export function __defaultSeed(seed: string, options: SeedOptions | undefined, persist: boolean) {
251
+ persistEnabled.value = persist
252
+ return selectSeed(seed, options)
107
253
  }
@@ -16,6 +16,12 @@ const M3_BG_CLASSES = [
16
16
  'bg-secondary-container',
17
17
  'bg-tertiary-container',
18
18
  'bg-error-container',
19
+ 'bg-primary-fixed',
20
+ 'bg-primary-fixed-dim',
21
+ 'bg-secondary-fixed',
22
+ 'bg-secondary-fixed-dim',
23
+ 'bg-tertiary-fixed',
24
+ 'bg-tertiary-fixed-dim',
19
25
  'bg-primary',
20
26
  'bg-secondary',
21
27
  'bg-tertiary',
@@ -39,12 +39,30 @@ export interface M3Locale {
39
39
  // Pickers
40
40
  selectDate: string
41
41
  selectTime: string
42
+ timeHourSelection: string
43
+ timeMinuteSelection: string
44
+ timePeriodToggle: string
45
+ timeToggleKeyboard: string
46
+ timeToggleDial: string
47
+ timeToggleScroll: string
42
48
  selectRange: string
43
49
  pickStart: string
44
50
  pickEnd: string
45
51
  previousMonth: string
46
52
  nextMonth: string
47
53
 
54
+ // Color picker
55
+ selectColor: string
56
+ colorHue: string
57
+ colorSaturation: string
58
+ colorBrightness: string
59
+ colorAlpha: string
60
+ colorEyedropper: string
61
+ colorOriginal: string
62
+ colorFormat: string
63
+ colorRecent: string
64
+ colorPresets: string
65
+
48
66
  // Scheduler
49
67
  dayView: string
50
68
  weekView: string
@@ -200,11 +218,27 @@ export const defaultLocale: M3Locale = {
200
218
 
201
219
  selectDate: 'Select date',
202
220
  selectTime: 'Select time',
221
+ timeHourSelection: 'Select hour',
222
+ timeMinuteSelection: 'Select minutes',
223
+ timePeriodToggle: 'Select AM or PM',
224
+ timeToggleKeyboard: 'Switch to text input mode',
225
+ timeToggleDial: 'Switch to clock mode',
226
+ timeToggleScroll: 'Switch to scroll mode',
203
227
  selectRange: 'Select range',
204
228
  pickStart: 'Select start',
205
229
  pickEnd: 'Select end',
206
230
  previousMonth: 'Previous month',
207
231
  nextMonth: 'Next month',
232
+ selectColor: 'Select color',
233
+ colorHue: 'Hue',
234
+ colorSaturation: 'Saturation',
235
+ colorBrightness: 'Brightness',
236
+ colorAlpha: 'Opacity',
237
+ colorEyedropper: 'Pick a color from the screen',
238
+ colorOriginal: 'Original color',
239
+ colorFormat: 'Color format',
240
+ colorRecent: 'Recent',
241
+ colorPresets: 'Presets',
208
242
 
209
243
  dayView: 'Day',
210
244
  weekView: 'Week',
@@ -1,4 +1,5 @@
1
1
  // Generated by scripts/generate-emoji-data.mjs from CLDR 48.2.0 annotations (de). Don't edit by hand.
2
+ // Emoji data © Unicode, Inc., under the Unicode License v3 (dist/THIRD_PARTY_LICENSES.md, scripts/licenses/unicode-license-v3.txt).
2
3
  // "name|keyword|keyword…" per emoji.
3
4
  const names: Record<string, string> = {
4
5
  '😀': 'grinsendes Gesicht|froh|fröhlich|Gesicht|grinsen|haha|lachen|lol|lustig|Smiley',
@@ -1,4 +1,5 @@
1
1
  // Generated by scripts/generate-emoji-data.mjs from CLDR 48.2.0 annotations (en). Don't edit by hand.
2
+ // Emoji data © Unicode, Inc., under the Unicode License v3 (dist/THIRD_PARTY_LICENSES.md, scripts/licenses/unicode-license-v3.txt).
2
3
  // "name|keyword|keyword…" per emoji.
3
4
  const names: Record<string, string> = {
4
5
  '😀': 'grinning face|cheerful|cheery|face|grin|grinning|happy|laugh|nice|smile|smiling|teeth',
@@ -1,4 +1,5 @@
1
1
  // Generated by scripts/generate-emoji-data.mjs from CLDR 48.2.0 annotations (es). Don't edit by hand.
2
+ // Emoji data © Unicode, Inc., under the Unicode License v3 (dist/THIRD_PARTY_LICENSES.md, scripts/licenses/unicode-license-v3.txt).
2
3
  // "name|keyword|keyword…" per emoji.
3
4
  const names: Record<string, string> = {
4
5
  '😀': 'cara sonriendo|cara|divertido|feliz|sonrisa',
@@ -1,4 +1,5 @@
1
1
  // Generated by scripts/generate-emoji-data.mjs from CLDR 48.2.0 annotations (fr). Don't edit by hand.
2
+ // Emoji data © Unicode, Inc., under the Unicode License v3 (dist/THIRD_PARTY_LICENSES.md, scripts/licenses/unicode-license-v3.txt).
2
3
  // "name|keyword|keyword…" per emoji.
3
4
  const names: Record<string, string> = {
4
5
  '😀': 'visage rieur|content|dents|émoticône|grand sourire|heureux|joyeux|rire|sourire|super|visage|visage très souriant',
@@ -1,4 +1,5 @@
1
1
  // Generated by scripts/generate-emoji-data.mjs from CLDR 48.2.0 annotations (ja). Don't edit by hand.
2
+ // Emoji data © Unicode, Inc., under the Unicode License v3 (dist/THIRD_PARTY_LICENSES.md, scripts/licenses/unicode-license-v3.txt).
2
3
  // "name|keyword|keyword…" per emoji.
3
4
  const names: Record<string, string> = {
4
5
  '😀': 'にっこり笑う|スマイル|ナイス|にっこり|ハッピー|笑う|笑顔|顔',
@@ -1,4 +1,5 @@
1
1
  // Generated by scripts/generate-emoji-data.mjs from CLDR 48.2.0 annotations (ko). Don't edit by hand.
2
+ // Emoji data © Unicode, Inc., under the Unicode License v3 (dist/THIRD_PARTY_LICENSES.md, scripts/licenses/unicode-license-v3.txt).
2
3
  // "name|keyword|keyword…" per emoji.
3
4
  const names: Record<string, string> = {
4
5
  '😀': '활짝 웃는 얼굴|미소|발랄함|스마일|얼굴|웃음|치아|행복|환호',