@m3ui-vue/m3ui-vue 0.9.1 → 0.9.2
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 +41 -0
- package/dist/API.md +199 -54
- package/dist/{MTextField-pJU1vFaR.js → MTextField-Ck0oWDMk.js} +8 -2
- package/dist/MTextField-Ck0oWDMk.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MBox.vue.d.ts +3 -3
- package/dist/components/MColorPicker.vue.d.ts +13 -1
- package/dist/components/MColorPickerModal.vue.d.ts +14 -2
- package/dist/components/MDragHandle.vue.d.ts +12 -0
- package/dist/components/MEmojiSelector.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +1 -1
- package/dist/components/MFabMenu.vue.d.ts +1 -1
- package/dist/components/MListItem.vue.d.ts +5 -5
- package/dist/components/MOverlay.vue.d.ts +1 -1
- package/dist/components/MScrollField.vue.d.ts +40 -0
- package/dist/components/MScrollable.vue.d.ts +9 -0
- package/dist/components/MSplitter.vue.d.ts +2 -2
- package/dist/components/MSwipeToDismiss.vue.d.ts +49 -0
- package/dist/components/MTransition.vue.d.ts +34 -0
- package/dist/components/MWindow.vue.d.ts +1 -1
- package/dist/components/_MColorPanel.vue.d.ts +18 -0
- package/dist/composables/_colorUtils.d.ts +34 -0
- package/dist/composables/_themeColor.d.ts +1 -0
- package/dist/composables/_useSpring.d.ts +15 -0
- package/dist/composables/dynamicColor.d.ts +18 -0
- package/dist/composables/useColorPalette.d.ts +27 -0
- package/dist/composables/useLocale.d.ts +10 -0
- package/dist/index.d.ts +9 -1
- package/dist/locales/index.js +70 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +4808 -3622
- package/dist/m3ui.js.map +1 -1
- package/dist/material-color-utilities-Cktu8DBU.js +3160 -0
- package/dist/material-color-utilities-Cktu8DBU.js.map +1 -0
- package/dist/plugin.d.ts +18 -0
- package/dist/rich-text-editor.js +2 -2
- package/dist/styles/palettes.css +546 -0
- package/dist/styles/theme.css +77 -0
- package/dist/styles.css +1 -1
- package/dist/{useLocale-Drihe5G2.js → useLocale-CFW8cIzL.js} +11 -1
- package/dist/useLocale-CFW8cIzL.js.map +1 -0
- package/package.json +2 -1
- package/src/__tests__/MButtonGroup.test.ts +51 -0
- package/src/__tests__/MColorPicker.test.ts +141 -0
- package/src/__tests__/MDragHandle.test.ts +57 -0
- package/src/__tests__/MListItemShape.test.ts +76 -0
- package/src/__tests__/MScrollField.test.ts +41 -0
- package/src/__tests__/MScrollable.test.ts +42 -0
- package/src/__tests__/MSwipeToDismiss.test.ts +104 -0
- package/src/__tests__/MTransition.test.ts +27 -0
- package/src/__tests__/dynamicColor.test.ts +191 -0
- package/src/components/MBox.vue +4 -2
- package/src/components/MButtonGroup.vue +116 -35
- package/src/components/MColorPicker.vue +114 -210
- package/src/components/MColorPickerModal.vue +50 -251
- package/src/components/MDragHandle.vue +54 -0
- package/src/components/MList.vue +33 -3
- package/src/components/MListItem.vue +75 -5
- package/src/components/MScrollField.vue +302 -0
- package/src/components/MScrollable.vue +160 -5
- package/src/components/MSplitter.vue +33 -10
- package/src/components/MSwipeToDismiss.vue +247 -0
- package/src/components/MTransition.vue +149 -0
- package/src/components/_MColorPanel.vue +478 -0
- package/src/composables/_colorUtils.ts +107 -0
- package/src/composables/_themeColor.ts +33 -0
- package/src/composables/_useSpring.ts +89 -0
- package/src/composables/dynamicColor.ts +85 -0
- package/src/composables/useColorPalette.ts +171 -25
- package/src/composables/useFieldBg.ts +6 -0
- package/src/composables/useLocale.ts +22 -0
- package/src/index.ts +9 -1
- package/src/locales/de.ts +10 -0
- package/src/locales/es.ts +10 -0
- package/src/locales/fr.ts +10 -0
- package/src/locales/ja.ts +10 -0
- package/src/locales/ko.ts +10 -0
- package/src/locales/pt.ts +10 -0
- package/src/locales/zh.ts +10 -0
- package/src/plugin.ts +28 -7
- package/src/styles/palettes.css +546 -0
- package/src/styles/theme.css +77 -0
- package/dist/MTextField-pJU1vFaR.js.map +0 -1
- package/dist/useLocale-Drihe5G2.js.map +0 -1
|
@@ -0,0 +1,89 @@
|
|
|
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.DefaultEffects in the Standard scheme */
|
|
11
|
+
export const DEFAULT_EFFECTS: SpringSpec = { dampingRatio: 1, stiffness: 1600 }
|
|
12
|
+
/** MotionSchemeKeyTokens.DefaultSpatial in the Standard scheme */
|
|
13
|
+
export const DEFAULT_SPATIAL: SpringSpec = { dampingRatio: 0.9, stiffness: 700 }
|
|
14
|
+
|
|
15
|
+
const SUBSTEP = 0.004
|
|
16
|
+
|
|
17
|
+
export function useSpring(
|
|
18
|
+
target: () => number[],
|
|
19
|
+
apply: (values: readonly number[]) => void,
|
|
20
|
+
spec: SpringSpec = FAST_SPATIAL,
|
|
21
|
+
) {
|
|
22
|
+
let current = [...target()]
|
|
23
|
+
let velocity = current.map(() => 0)
|
|
24
|
+
let raf = 0
|
|
25
|
+
let last = 0
|
|
26
|
+
|
|
27
|
+
function frame(now: number) {
|
|
28
|
+
let dt = Math.min((now - last) / 1000, 1 / 30)
|
|
29
|
+
last = now
|
|
30
|
+
const t = target()
|
|
31
|
+
if (t.length !== current.length) {
|
|
32
|
+
current = [...t]
|
|
33
|
+
velocity = t.map(() => 0)
|
|
34
|
+
}
|
|
35
|
+
const k = spec.stiffness
|
|
36
|
+
const c = 2 * spec.dampingRatio * Math.sqrt(k)
|
|
37
|
+
while (dt > 0) {
|
|
38
|
+
const h = Math.min(dt, SUBSTEP)
|
|
39
|
+
dt -= h
|
|
40
|
+
for (let i = 0; i < t.length; i++) {
|
|
41
|
+
velocity[i]! += (-k * (current[i]! - t[i]!) - c * velocity[i]!) * h
|
|
42
|
+
current[i]! += velocity[i]! * h
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const settled = t.every((v, i) => Math.abs(v - current[i]!) < 0.05 && Math.abs(velocity[i]!) < 0.05)
|
|
46
|
+
if (settled) {
|
|
47
|
+
current = [...t]
|
|
48
|
+
velocity = t.map(() => 0)
|
|
49
|
+
}
|
|
50
|
+
apply(current)
|
|
51
|
+
raf = settled ? 0 : requestAnimationFrame(frame)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function start() {
|
|
55
|
+
if (raf) return
|
|
56
|
+
last = performance.now()
|
|
57
|
+
raf = requestAnimationFrame(frame)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Jumps to the target without animating (e.g. when the layout context changes). */
|
|
61
|
+
function snap() {
|
|
62
|
+
cancelAnimationFrame(raf)
|
|
63
|
+
raf = 0
|
|
64
|
+
current = [...target()]
|
|
65
|
+
velocity = current.map(() => 0)
|
|
66
|
+
apply(current)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
watch(() => target().join(','), start)
|
|
70
|
+
onMounted(() => apply(current))
|
|
71
|
+
onUnmounted(() => cancelAnimationFrame(raf))
|
|
72
|
+
|
|
73
|
+
return { snap }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Compose's FastOutSlowInEasing, cubic-bezier(0.4, 0, 0.2, 1) — the easing of a default tween() */
|
|
77
|
+
export function fastOutSlowIn(t: number): number {
|
|
78
|
+
if (t <= 0) return 0
|
|
79
|
+
if (t >= 1) return 1
|
|
80
|
+
// Solve x(u) = t for the curve parameter u (Newton), then return y(u)
|
|
81
|
+
let u = t
|
|
82
|
+
for (let i = 0; i < 8; i++) {
|
|
83
|
+
const x = 3 * u * (1 - u) ** 2 * 0.4 + 3 * u ** 2 * (1 - u) * 0.2 + u ** 3 - t
|
|
84
|
+
const dx = 3 * (1 - u) ** 2 * 0.4 + 6 * u * (1 - u) * (0.2 - 0.4) + 3 * u ** 2 * 0.8
|
|
85
|
+
if (Math.abs(dx) < 1e-6) break
|
|
86
|
+
u -= x / dx
|
|
87
|
+
}
|
|
88
|
+
return 3 * u ** 2 * (1 - u) + u ** 3
|
|
89
|
+
}
|
|
@@ -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
|
-
|
|
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)
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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)
|
|
202
|
+
if (enabled) write(PALETTE_KEY, current.value)
|
|
81
203
|
}
|
|
82
204
|
|
|
83
|
-
return {
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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',
|
|
@@ -45,6 +45,18 @@ export interface M3Locale {
|
|
|
45
45
|
previousMonth: string
|
|
46
46
|
nextMonth: string
|
|
47
47
|
|
|
48
|
+
// Color picker
|
|
49
|
+
selectColor: string
|
|
50
|
+
colorHue: string
|
|
51
|
+
colorSaturation: string
|
|
52
|
+
colorBrightness: string
|
|
53
|
+
colorAlpha: string
|
|
54
|
+
colorEyedropper: string
|
|
55
|
+
colorOriginal: string
|
|
56
|
+
colorFormat: string
|
|
57
|
+
colorRecent: string
|
|
58
|
+
colorPresets: string
|
|
59
|
+
|
|
48
60
|
// Scheduler
|
|
49
61
|
dayView: string
|
|
50
62
|
weekView: string
|
|
@@ -205,6 +217,16 @@ export const defaultLocale: M3Locale = {
|
|
|
205
217
|
pickEnd: 'Select end',
|
|
206
218
|
previousMonth: 'Previous month',
|
|
207
219
|
nextMonth: 'Next month',
|
|
220
|
+
selectColor: 'Select color',
|
|
221
|
+
colorHue: 'Hue',
|
|
222
|
+
colorSaturation: 'Saturation',
|
|
223
|
+
colorBrightness: 'Brightness',
|
|
224
|
+
colorAlpha: 'Opacity',
|
|
225
|
+
colorEyedropper: 'Pick a color from the screen',
|
|
226
|
+
colorOriginal: 'Original color',
|
|
227
|
+
colorFormat: 'Color format',
|
|
228
|
+
colorRecent: 'Recent',
|
|
229
|
+
colorPresets: 'Presets',
|
|
208
230
|
|
|
209
231
|
dayView: 'Day',
|
|
210
232
|
weekView: 'Week',
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,10 @@ export type { M3UIOptions } from './plugin'
|
|
|
6
6
|
export { useTheme } from './composables/useTheme'
|
|
7
7
|
export type { Theme } from './composables/useTheme'
|
|
8
8
|
export { useColorPalette, palettes } from './composables/useColorPalette'
|
|
9
|
-
export type { Palette } from './composables/useColorPalette'
|
|
9
|
+
export type { Palette, ActiveSeed } from './composables/useColorPalette'
|
|
10
|
+
export { SEED_PALETTE } from './composables/useColorPalette'
|
|
11
|
+
export { generateScheme, schemeToCss, schemeRoles } from './composables/dynamicColor'
|
|
12
|
+
export type { SchemeVariant, SeedOptions, GeneratedScheme } from './composables/dynamicColor'
|
|
10
13
|
export { useToast } from './composables/useToast'
|
|
11
14
|
export type { Toast, ToastVariant, ToastPosition, ToastAction, ToastOptions } from './composables/useToast'
|
|
12
15
|
export { useFieldBg } from './composables/useFieldBg'
|
|
@@ -60,6 +63,7 @@ export { default as MDateRangePicker } from './components/MDateRangePicker.vue'
|
|
|
60
63
|
export { default as MDateRangePickerModal } from './components/MDateRangePickerModal.vue'
|
|
61
64
|
export { default as MDialog } from './components/MDialog.vue'
|
|
62
65
|
export { default as MDivider } from './components/MDivider.vue'
|
|
66
|
+
export { default as MDragHandle } from './components/MDragHandle.vue'
|
|
63
67
|
export { default as MDragDropList } from './components/MDragDropList.vue'
|
|
64
68
|
export { default as MEmoji } from './components/MEmoji.vue'
|
|
65
69
|
export { default as MEmojiButton } from './components/MEmojiButton.vue'
|
|
@@ -130,6 +134,7 @@ export { default as MScrollable } from './components/MScrollable.vue'
|
|
|
130
134
|
export { default as MSearchBar } from './components/MSearchBar.vue'
|
|
131
135
|
export { default as MSection } from './components/MSection.vue'
|
|
132
136
|
export { default as MSegmentedButton } from './components/MSegmentedButton.vue'
|
|
137
|
+
export { default as MScrollField } from './components/MScrollField.vue'
|
|
133
138
|
export { default as MSelect } from './components/MSelect.vue'
|
|
134
139
|
export type { SelectOption } from './components/MSelect.vue'
|
|
135
140
|
export { default as MShader } from './components/MShader.vue'
|
|
@@ -156,6 +161,8 @@ export { default as MStatCard } from './components/MStatCard.vue'
|
|
|
156
161
|
export { default as MStepper } from './components/MStepper.vue'
|
|
157
162
|
export { default as MSticky } from './components/MSticky.vue'
|
|
158
163
|
export { default as MSubtitle } from './components/MSubtitle.vue'
|
|
164
|
+
export { default as MSwipeToDismiss } from './components/MSwipeToDismiss.vue'
|
|
165
|
+
export type { SwipeToDismissValue } from './components/MSwipeToDismiss.vue'
|
|
159
166
|
export { default as MSwitch } from './components/MSwitch.vue'
|
|
160
167
|
export { default as MTable } from './components/MTable.vue'
|
|
161
168
|
export { default as MTagInput } from './components/MTagInput.vue'
|
|
@@ -174,6 +181,7 @@ export { default as MTopAppBar } from './components/MTopAppBar.vue'
|
|
|
174
181
|
export { default as MTour } from './components/MTour.vue'
|
|
175
182
|
export { default as MTransferList } from './components/MTransferList.vue'
|
|
176
183
|
export { default as MTree } from './components/MTree.vue'
|
|
184
|
+
export { default as MTransition } from './components/MTransition.vue'
|
|
177
185
|
export { default as MTreeTable } from './components/MTreeTable.vue'
|
|
178
186
|
export { default as MVirtualTable } from './components/MVirtualTable.vue'
|
|
179
187
|
export { default as MWindow } from './components/MWindow.vue'
|
package/src/locales/de.ts
CHANGED
|
@@ -43,6 +43,16 @@ export const deLocale: M3Locale = {
|
|
|
43
43
|
pickEnd: 'Ende auswählen',
|
|
44
44
|
previousMonth: 'Vorheriger Monat',
|
|
45
45
|
nextMonth: 'Nächster Monat',
|
|
46
|
+
selectColor: 'Farbe auswählen',
|
|
47
|
+
colorHue: 'Farbton',
|
|
48
|
+
colorSaturation: 'Sättigung',
|
|
49
|
+
colorBrightness: 'Helligkeit',
|
|
50
|
+
colorAlpha: 'Deckkraft',
|
|
51
|
+
colorEyedropper: 'Farbe vom Bildschirm aufnehmen',
|
|
52
|
+
colorOriginal: 'Ursprüngliche Farbe',
|
|
53
|
+
colorFormat: 'Farbformat',
|
|
54
|
+
colorRecent: 'Zuletzt verwendet',
|
|
55
|
+
colorPresets: 'Vorgaben',
|
|
46
56
|
|
|
47
57
|
// Scheduler
|
|
48
58
|
dayView: 'Tag',
|
package/src/locales/es.ts
CHANGED
|
@@ -43,6 +43,16 @@ export const esLocale: M3Locale = {
|
|
|
43
43
|
pickEnd: 'Seleccionar fin',
|
|
44
44
|
previousMonth: 'Mes anterior',
|
|
45
45
|
nextMonth: 'Mes siguiente',
|
|
46
|
+
selectColor: 'Seleccionar color',
|
|
47
|
+
colorHue: 'Tono',
|
|
48
|
+
colorSaturation: 'Saturación',
|
|
49
|
+
colorBrightness: 'Brillo',
|
|
50
|
+
colorAlpha: 'Opacidad',
|
|
51
|
+
colorEyedropper: 'Tomar un color de la pantalla',
|
|
52
|
+
colorOriginal: 'Color original',
|
|
53
|
+
colorFormat: 'Formato de color',
|
|
54
|
+
colorRecent: 'Recientes',
|
|
55
|
+
colorPresets: 'Predefinidos',
|
|
46
56
|
|
|
47
57
|
// Scheduler
|
|
48
58
|
dayView: 'Día',
|
package/src/locales/fr.ts
CHANGED
|
@@ -43,6 +43,16 @@ export const frLocale: M3Locale = {
|
|
|
43
43
|
pickEnd: 'Sélectionner la fin',
|
|
44
44
|
previousMonth: 'Mois précédent',
|
|
45
45
|
nextMonth: 'Mois suivant',
|
|
46
|
+
selectColor: 'Choisir une couleur',
|
|
47
|
+
colorHue: 'Teinte',
|
|
48
|
+
colorSaturation: 'Saturation',
|
|
49
|
+
colorBrightness: 'Luminosité',
|
|
50
|
+
colorAlpha: 'Opacité',
|
|
51
|
+
colorEyedropper: 'Prélever une couleur à l\'écran',
|
|
52
|
+
colorOriginal: 'Couleur d’origine',
|
|
53
|
+
colorFormat: 'Format de couleur',
|
|
54
|
+
colorRecent: 'Récentes',
|
|
55
|
+
colorPresets: 'Prédéfinies',
|
|
46
56
|
|
|
47
57
|
// Scheduler
|
|
48
58
|
dayView: 'Jour',
|
package/src/locales/ja.ts
CHANGED
|
@@ -43,6 +43,16 @@ export const jaLocale: M3Locale = {
|
|
|
43
43
|
pickEnd: '終了を選択',
|
|
44
44
|
previousMonth: '前月',
|
|
45
45
|
nextMonth: '翌月',
|
|
46
|
+
selectColor: '色を選択',
|
|
47
|
+
colorHue: '色相',
|
|
48
|
+
colorSaturation: '彩度',
|
|
49
|
+
colorBrightness: '明度',
|
|
50
|
+
colorAlpha: '不透明度',
|
|
51
|
+
colorEyedropper: '画面から色を取得',
|
|
52
|
+
colorOriginal: '元の色',
|
|
53
|
+
colorFormat: 'カラー形式',
|
|
54
|
+
colorRecent: '最近使用',
|
|
55
|
+
colorPresets: 'プリセット',
|
|
46
56
|
|
|
47
57
|
// Scheduler
|
|
48
58
|
dayView: '日',
|
package/src/locales/ko.ts
CHANGED
|
@@ -43,6 +43,16 @@ export const koLocale: M3Locale = {
|
|
|
43
43
|
pickEnd: '종료 선택',
|
|
44
44
|
previousMonth: '이전 달',
|
|
45
45
|
nextMonth: '다음 달',
|
|
46
|
+
selectColor: '색상 선택',
|
|
47
|
+
colorHue: '색조',
|
|
48
|
+
colorSaturation: '채도',
|
|
49
|
+
colorBrightness: '밝기',
|
|
50
|
+
colorAlpha: '불투명도',
|
|
51
|
+
colorEyedropper: '화면에서 색상 가져오기',
|
|
52
|
+
colorOriginal: '원래 색상',
|
|
53
|
+
colorFormat: '색상 형식',
|
|
54
|
+
colorRecent: '최근 사용',
|
|
55
|
+
colorPresets: '프리셋',
|
|
46
56
|
|
|
47
57
|
// Scheduler
|
|
48
58
|
dayView: '일',
|
package/src/locales/pt.ts
CHANGED
|
@@ -43,6 +43,16 @@ export const ptLocale: M3Locale = {
|
|
|
43
43
|
pickEnd: 'Selecionar fim',
|
|
44
44
|
previousMonth: 'Mês anterior',
|
|
45
45
|
nextMonth: 'Próximo mês',
|
|
46
|
+
selectColor: 'Selecionar cor',
|
|
47
|
+
colorHue: 'Matiz',
|
|
48
|
+
colorSaturation: 'Saturação',
|
|
49
|
+
colorBrightness: 'Brilho',
|
|
50
|
+
colorAlpha: 'Opacidade',
|
|
51
|
+
colorEyedropper: 'Capturar uma cor da tela',
|
|
52
|
+
colorOriginal: 'Cor original',
|
|
53
|
+
colorFormat: 'Formato de cor',
|
|
54
|
+
colorRecent: 'Recentes',
|
|
55
|
+
colorPresets: 'Predefinidas',
|
|
46
56
|
|
|
47
57
|
// Scheduler
|
|
48
58
|
dayView: 'Dia',
|
package/src/locales/zh.ts
CHANGED
|
@@ -43,6 +43,16 @@ export const zhLocale: M3Locale = {
|
|
|
43
43
|
pickEnd: '选择结束',
|
|
44
44
|
previousMonth: '上个月',
|
|
45
45
|
nextMonth: '下个月',
|
|
46
|
+
selectColor: '选择颜色',
|
|
47
|
+
colorHue: '色相',
|
|
48
|
+
colorSaturation: '饱和度',
|
|
49
|
+
colorBrightness: '亮度',
|
|
50
|
+
colorAlpha: '不透明度',
|
|
51
|
+
colorEyedropper: '从屏幕取色',
|
|
52
|
+
colorOriginal: '原始颜色',
|
|
53
|
+
colorFormat: '颜色格式',
|
|
54
|
+
colorRecent: '最近使用',
|
|
55
|
+
colorPresets: '预设',
|
|
46
56
|
|
|
47
57
|
// Scheduler
|
|
48
58
|
dayView: '日',
|