@jskit-ai/material-web 0.0.0-stage → 0.1.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - New package: exact Material 3 for JSKIT Vuetify apps. `createMaterialVuetifyOptions({ seed, colors, icons })` generates the light and dark schemes from one seed with Material Color Utilities (the app's own `colors` as harmonized custom colours, light and dark), follows the system scheme, maps every icon alias to Material Symbols Rounded, and sets JSKIT's Material 3 component defaults; `client/material.css` adds the exact sizes and shapes (40dp buttons and 32dp chips inside 48dp touch targets, outline-variant dividers), Roboto Flex and motion.
package/README.md CHANGED
@@ -1,3 +1,76 @@
1
- # Temporary Holding Version
1
+ # Material 3 for JSKIT apps
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@jskit-ai/material-web` makes a JSKIT Vuetify app exact Material 3 out of the
4
+ box, in light and dark: no app CSS, overrides or patches. It has no client
5
+ provider and registers nothing; the app's `src/main.js` passes its options to
6
+ `createVuetify()`.
7
+
8
+ ```js
9
+ import "vuetify/styles";
10
+ import "@jskit-ai/material-web/client/material.css";
11
+ import { createVuetify } from "vuetify";
12
+ import { createMaterialVuetifyOptions } from "@jskit-ai/material-web/client";
13
+ import { theme } from "./theme/index.js";
14
+
15
+ const vuetify = createVuetify(createMaterialVuetifyOptions(theme));
16
+ ```
17
+
18
+ The app's only theme file is `src/theme/index.js`:
19
+
20
+ ```js
21
+ export const theme = {
22
+ seed: "#6750A4",
23
+ colors: {},
24
+ icons: {}
25
+ };
26
+ ```
27
+
28
+ ## What it sets
29
+
30
+ - **Colour.** One seed colour generates the light and dark schemes with
31
+ Material Color Utilities (`SchemeTonalSpot`, the Material 3 default). Every
32
+ Material 3 role is a Vuetify theme colour in kebab-case (`primary`,
33
+ `on-primary-container`, `surface-container-high`, `outline-variant`, ...).
34
+ `success`, `warning` and `info` are custom colours harmonized to the seed
35
+ (`customColor` with `blend`), each with `on-`, `-container` and
36
+ `on-…-container` roles. An app's own colours go in `theme.colors` by
37
+ camelCase name and become custom colours the same way: `partner: "#0A7D3E"`
38
+ gives `partner`, `on-partner`, `partner-container` and
39
+ `on-partner-container`, harmonized to the seed, in both schemes; a name that
40
+ would replace a scheme role is refused. `defaultTheme` is `"system"`, so the app follows the
41
+ device's light or dark setting. Theme variables carry the Material 3 state
42
+ layers (hover 8%, focus 10%, pressed 10%, dragged 16%) and `border-color` and
43
+ `shadow-color` as channel strings (`outline-variant` and `shadow`). There is no
44
+ hand-picked colour and no generator command: change the seed and both schemes
45
+ follow.
46
+ - **Icons.** Every Vuetify alias and JSKIT's own aliases are Material Symbols
47
+ Rounded glyphs (outlined, Material Symbols' default; `$<name>Filled` for the
48
+ active navigation item). JSKIT names are the symbol in camelCase: `$arrowBack`,
49
+ `$add`, `$edit`, `$delete` (the trash can), `$search`, `$moreVert`,
50
+ `$filterList`, `$home`, `$settings`, `$person`, ... The full list is
51
+ `@jskit-ai/material-web/client/symbols`. An app adds its own in
52
+ `theme.icons` as `{ name: "<24x24 path data>" }`, copied from the Material
53
+ Symbols Rounded glyph (the `material-symbols:<name>-rounded` path in
54
+ `@iconify-json/material-symbols`); `$name` then works everywhere.
55
+ - **Type.** Roboto Flex (variable weight) for every Vuetify text style; the
56
+ Material 3 type scale is Vuetify's `text-display-*`, `text-headline-*`,
57
+ `text-title-*`, `text-body-*` and `text-label-*` classes.
58
+ - **Components.** The md3 blueprint plus JSKIT's defaults: full-shape filled
59
+ buttons, elevated cards on `surface-container-low` with 12dp corners, outlined
60
+ fields, 8dp chips that close with `$close`, 4dp menus on `surface-container`,
61
+ the inverse-surface snackbar, the Material switch and the 16dp
62
+ `primary-container` FAB.
63
+ - **`material.css`.** What props cannot set: 40dp buttons with a 48dp touch
64
+ target and 40dp icon buttons, 28dp dialogs and bottom sheets, square
65
+ full-screen dialogs on `surface`, a 48dp touch target on clickable chips,
66
+ inverse-surface tooltips, emphasized easing
67
+ and reduced motion. Its component rules sit in Vuetify's `vuetify-overrides`
68
+ cascade layer, so an app's own props and utility classes still win; nothing
69
+ uses `!important` or Sass.
70
+
71
+ ## Maintaining the icon set
72
+
73
+ `src/client/symbols.js` is generated. Add a glyph to
74
+ `scripts/generate-symbols.mjs`, then run
75
+ `npm run symbols:generate --workspace @jskit-ai/material-web`; the package test
76
+ fails while the file is stale.
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@jskit-ai/material-web",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Exact Material 3 for JSKIT Vuetify apps: seed-generated light and dark schemes, Material Symbols Rounded icon aliases, Roboto Flex and Material 3 component defaults.",
6
+ "exports": {
7
+ "./client": "./src/client/index.js",
8
+ "./client/symbols": "./src/client/symbols.js",
9
+ "./client/material.css": "./src/client/material.css"
10
+ },
11
+ "dependencies": {
12
+ "@fontsource-variable/roboto-flex": "^5.3.0",
13
+ "@material/material-color-utilities": "0.3.0"
14
+ },
15
+ "devDependencies": {
16
+ "@iconify-json/material-symbols": "1.2.97"
17
+ },
18
+ "peerDependencies": {
19
+ "vuetify": "^4.3.0"
20
+ },
21
+ "jskit": {
22
+ "kind": "runtime",
23
+ "capabilities": {
24
+ "provides": [],
25
+ "requires": []
26
+ },
27
+ "runtime": {
28
+ "server": {
29
+ "providers": []
30
+ },
31
+ "client": {
32
+ "providers": []
33
+ }
34
+ }
35
+ },
36
+ "scripts": {
37
+ "test": "node --test --test-concurrency=1",
38
+ "symbols:generate": "node ./scripts/generate-symbols.mjs"
39
+ }
40
+ }
@@ -0,0 +1,284 @@
1
+ #!/usr/bin/env node
2
+ // Writes src/client/symbols.js: the Material Symbols Rounded glyphs JSKIT's icon aliases name, as Vuetify "svg:" paths.
3
+ // The glyphs come from @iconify-json/material-symbols (Google's Material Symbols, Apache-2.0, on a 24x24 grid).
4
+ // Each alias takes the outlined glyph (Material Symbols' default, FILL 0) unless it asks for the filled one; an alias
5
+ // listed in FILLED_VARIANTS also gets a `<name>Filled` alias, which the shell uses for the active navigation item.
6
+ // Run: node packages/material-web/scripts/generate-symbols.mjs [--check]
7
+ import { readFile, writeFile } from "node:fs/promises";
8
+ import { createRequire } from "node:module";
9
+ import path from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+
12
+ const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
13
+ const OUTPUT_PATH = path.join(PACKAGE_ROOT, "src/client/symbols.js");
14
+
15
+ // Vuetify's own aliases, every one of them, so no component falls back to an icon font.
16
+ const VUETIFY_ALIASES = Object.freeze({
17
+ collapse: "keyboard-arrow-up",
18
+ complete: "check",
19
+ cancel: { symbol: "cancel", fill: true },
20
+ close: "close",
21
+ delete: "delete",
22
+ clear: { symbol: "cancel", fill: true },
23
+ success: "check-circle",
24
+ info: "info",
25
+ warning: "warning",
26
+ error: "error",
27
+ prev: "chevron-left",
28
+ next: "chevron-right",
29
+ checkboxOn: { symbol: "check-box", fill: true },
30
+ checkboxOff: "check-box-outline-blank",
31
+ checkboxIndeterminate: { symbol: "indeterminate-check-box", fill: true },
32
+ delimiter: { symbol: "circle", fill: true },
33
+ sortAsc: "arrow-upward",
34
+ sortDesc: "arrow-downward",
35
+ expand: "keyboard-arrow-down",
36
+ menu: "menu",
37
+ subgroup: "arrow-drop-down",
38
+ dropdown: "arrow-drop-down",
39
+ radioOn: "radio-button-checked",
40
+ radioOff: "radio-button-unchecked",
41
+ edit: "edit",
42
+ ratingEmpty: "star",
43
+ ratingFull: { symbol: "star", fill: true },
44
+ ratingHalf: "star-half",
45
+ loading: "cached",
46
+ first: "first-page",
47
+ last: "last-page",
48
+ unfold: "unfold-more",
49
+ file: "attach-file",
50
+ plus: "add",
51
+ minus: "remove",
52
+ calendar: "calendar-today",
53
+ clock: "schedule",
54
+ treeviewCollapse: "arrow-drop-down",
55
+ treeviewExpand: "arrow-right",
56
+ tableGroupCollapse: "keyboard-arrow-down",
57
+ tableGroupExpand: "keyboard-arrow-right",
58
+ eyeDropper: "colorize",
59
+ upload: "cloud-upload",
60
+ color: "palette",
61
+ command: "keyboard-command-key",
62
+ ctrl: "keyboard-control-key",
63
+ space: "space-bar",
64
+ shift: "shift",
65
+ alt: "keyboard-option-key",
66
+ enter: "keyboard-return",
67
+ arrowup: "arrow-upward",
68
+ arrowdown: "arrow-downward",
69
+ arrowleft: "arrow-back",
70
+ arrowright: "arrow-forward",
71
+ backspace: "backspace",
72
+ play: "play-arrow",
73
+ pause: "pause",
74
+ fullscreen: "fullscreen",
75
+ fullscreenExit: "fullscreen-exit",
76
+ volumeHigh: "volume-up",
77
+ volumeMedium: "volume-down",
78
+ volumeLow: "volume-mute",
79
+ volumeOff: "volume-off",
80
+ search: "search"
81
+ });
82
+
83
+ // The icons JSKIT's screens use, named after the symbol in camelCase.
84
+ const JSKIT_ALIASES = Object.freeze({
85
+ accountCircle: "account-circle",
86
+ add: "add",
87
+ adminPanelSettings: "admin-panel-settings",
88
+ apps: "apps",
89
+ arrowBack: "arrow-back",
90
+ arrowCircleRight: "arrow-circle-right",
91
+ arrowForward: "arrow-forward",
92
+ assignment: "assignment",
93
+ attachFile: "attach-file",
94
+ cached: "cached",
95
+ calendarToday: "calendar-today",
96
+ chat: "chat",
97
+ check: "check",
98
+ checkCircle: "check-circle",
99
+ chevronLeft: "chevron-left",
100
+ chevronRight: "chevron-right",
101
+ cloudDone: "cloud-done",
102
+ cloudOff: "cloud-off",
103
+ contentCopy: "content-copy",
104
+ dashboard: "dashboard",
105
+ description: "description",
106
+ download: "download",
107
+ event: "event",
108
+ filterList: "filter-list",
109
+ folder: "folder",
110
+ group: "group",
111
+ headsetMic: "headset-mic",
112
+ help: "help",
113
+ history: "history",
114
+ home: "home",
115
+ image: "image",
116
+ inbox: "inbox",
117
+ key: "key",
118
+ lightbulb: "lightbulb",
119
+ link: "link",
120
+ lock: "lock",
121
+ login: "login",
122
+ logout: "logout",
123
+ mail: "mail",
124
+ manageAccounts: "manage-accounts",
125
+ markEmailUnread: "mark-email-unread",
126
+ menuOpen: "menu-open",
127
+ mic: "mic",
128
+ micOff: "mic-off",
129
+ moreVert: "more-vert",
130
+ notifications: "notifications",
131
+ openInNew: "open-in-new",
132
+ payments: "payments",
133
+ person: "person",
134
+ psychology: "psychology",
135
+ receiptLong: "receipt-long",
136
+ refresh: "refresh",
137
+ remove: "remove",
138
+ save: "save",
139
+ schedule: "schedule",
140
+ searchOff: "search-off",
141
+ send: "send",
142
+ settings: "settings",
143
+ smartToy: "smart-toy",
144
+ sort: "sort",
145
+ stop: "stop",
146
+ stopCircle: "stop-circle",
147
+ swapHoriz: "swap-horiz",
148
+ sync: "sync",
149
+ terminal: "terminal",
150
+ translate: "translate",
151
+ tune: "tune",
152
+ viewList: "view-list",
153
+ visibility: "visibility",
154
+ visibilityOff: "visibility-off",
155
+ volumeUp: "volume-up",
156
+ work: "work"
157
+ });
158
+
159
+ // Navigation destinations show the filled glyph while active.
160
+ const FILLED_VARIANTS = Object.freeze([
161
+ "accountCircle",
162
+ "adminPanelSettings",
163
+ "assignment",
164
+ "chat",
165
+ "dashboard",
166
+ "description",
167
+ "folder",
168
+ "group",
169
+ "home",
170
+ "manageAccounts",
171
+ "person",
172
+ "settings",
173
+ "smartToy",
174
+ "viewList",
175
+ "work"
176
+ ]);
177
+
178
+ // Material Symbols has no brand marks. The Google "G" for Google sign-in is Simple Icons' google.svg (CC0-1.0).
179
+ const BRAND_ALIASES = Object.freeze({
180
+ google:
181
+ "M12.48 10.92v3.28h7.84c-.24 1.84-.853 3.187-1.787 4.133-1.147 1.147-2.933 2.4-6.053 2.4-4.827 0-8.6-3.893-8.6-8.72s3.773-8.72 8.6-8.72c2.6 0 4.507 1.027 5.907 2.347l2.307-2.307C18.747 1.44 16.133 0 12.48 0 5.867 0 .307 5.387.307 12s5.56 12 12.173 12c3.573 0 6.267-1.173 8.373-3.36 2.16-2.16 2.84-5.213 2.84-7.667 0-.76-.053-1.467-.173-2.053H12.48z"
182
+ });
183
+
184
+ const PATH_BODY = /^<path fill="currentColor" d="([^"]+)"\/>$/u;
185
+
186
+ function resolveIcon(iconSet, name) {
187
+ const seen = new Set();
188
+ let current = name;
189
+ while (!iconSet.icons[current]) {
190
+ const alias = iconSet.aliases?.[current];
191
+ if (!alias || seen.has(current)) {
192
+ return null;
193
+ }
194
+ const transforms = Object.keys(alias).filter((key) => key !== "parent");
195
+ if (transforms.length > 0) {
196
+ throw new Error(`Material Symbols alias "${name}" transforms its parent (${transforms.join(", ")}); pick another glyph.`);
197
+ }
198
+ seen.add(current);
199
+ current = alias.parent;
200
+ }
201
+ const icon = iconSet.icons[current];
202
+ if (icon.width || icon.height || icon.left || icon.top || icon.rotate || icon.hFlip || icon.vFlip) {
203
+ throw new Error(`Material Symbols glyph "${current}" is not on the plain 24x24 grid.`);
204
+ }
205
+ const match = PATH_BODY.exec(icon.body);
206
+ if (!match) {
207
+ throw new Error(`Material Symbols glyph "${current}" is not a single path.`);
208
+ }
209
+ return match[1];
210
+ }
211
+
212
+ function resolveGlyph(iconSet, spec) {
213
+ const { symbol, fill = false } = typeof spec === "string" ? { symbol: spec } : spec;
214
+ const candidates = fill ? [`${symbol}-rounded`] : [`${symbol}-outline-rounded`, `${symbol}-rounded`];
215
+ for (const candidate of candidates) {
216
+ const glyph = resolveIcon(iconSet, candidate);
217
+ if (glyph) {
218
+ return glyph;
219
+ }
220
+ }
221
+ throw new Error(`Material Symbols Rounded has no "${symbol}".`);
222
+ }
223
+
224
+ function buildSymbols(iconSet) {
225
+ const symbols = {};
226
+ for (const [alias, spec] of Object.entries({ ...VUETIFY_ALIASES, ...JSKIT_ALIASES })) {
227
+ symbols[alias] = resolveGlyph(iconSet, spec);
228
+ }
229
+ for (const alias of FILLED_VARIANTS) {
230
+ const spec = JSKIT_ALIASES[alias];
231
+ if (!spec) {
232
+ throw new Error(`Filled variant "${alias}" has no JSKIT alias.`);
233
+ }
234
+ symbols[`${alias}Filled`] = resolveGlyph(iconSet, { symbol: spec, fill: true });
235
+ }
236
+ Object.assign(symbols, BRAND_ALIASES);
237
+ return Object.fromEntries(Object.entries(symbols).sort(([left], [right]) => left.localeCompare(right)));
238
+ }
239
+
240
+ async function buildSymbolsSource() {
241
+ const require = createRequire(import.meta.url);
242
+ const iconSetPath = require.resolve("@iconify-json/material-symbols/icons.json");
243
+ const iconSetPackage = JSON.parse(
244
+ await readFile(path.join(path.dirname(iconSetPath), "package.json"), "utf8")
245
+ );
246
+ const iconSet = JSON.parse(await readFile(iconSetPath, "utf8"));
247
+ const symbols = buildSymbols(iconSet);
248
+ const lines = Object.entries(symbols).map(([alias, glyph]) => ` ${alias}: "svg:${glyph}"`);
249
+ return [
250
+ "// Generated by packages/material-web/scripts/generate-symbols.mjs; do not edit.",
251
+ `// Material Symbols Rounded (Apache-2.0) from @iconify-json/material-symbols ${iconSetPackage.version};`,
252
+ "// the google mark is Simple Icons' google.svg (CC0-1.0).",
253
+ "",
254
+ "/** Every icon alias JSKIT defines, as Vuetify svg paths on a 24x24 grid. */",
255
+ "const materialSymbols = Object.freeze({",
256
+ lines.join(",\n"),
257
+ "});",
258
+ "",
259
+ "/** The Vuetify aliases JSKIT replaces, so no component falls back to an icon font. */",
260
+ `const vuetifyAliasNames = Object.freeze(${JSON.stringify(Object.keys(VUETIFY_ALIASES))});`,
261
+ "",
262
+ "export { materialSymbols, vuetifyAliasNames };",
263
+ ""
264
+ ].join("\n");
265
+ }
266
+
267
+ async function main() {
268
+ const source = await buildSymbolsSource();
269
+ if (process.argv.includes("--check")) {
270
+ const current = await readFile(OUTPUT_PATH, "utf8");
271
+ if (current !== source) {
272
+ console.error("src/client/symbols.js is out of date; run node packages/material-web/scripts/generate-symbols.mjs");
273
+ process.exitCode = 1;
274
+ }
275
+ return;
276
+ }
277
+ await writeFile(OUTPUT_PATH, source);
278
+ }
279
+
280
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
281
+ await main();
282
+ }
283
+
284
+ export { buildSymbolsSource };
@@ -0,0 +1,255 @@
1
+ import {
2
+ Hct,
3
+ MaterialDynamicColors,
4
+ SchemeTonalSpot,
5
+ argbFromHex,
6
+ customColor,
7
+ hexFromArgb,
8
+ redFromArgb,
9
+ greenFromArgb,
10
+ blueFromArgb
11
+ } from "@material/material-color-utilities";
12
+
13
+ // The Material 3 colour roles, by their Material Color Utilities names. The palette key colours are inputs, not roles.
14
+ const ROLE_NAMES = Object.freeze([
15
+ "background",
16
+ "onBackground",
17
+ "surface",
18
+ "surfaceDim",
19
+ "surfaceBright",
20
+ "surfaceContainerLowest",
21
+ "surfaceContainerLow",
22
+ "surfaceContainer",
23
+ "surfaceContainerHigh",
24
+ "surfaceContainerHighest",
25
+ "onSurface",
26
+ "surfaceVariant",
27
+ "onSurfaceVariant",
28
+ "inverseSurface",
29
+ "inverseOnSurface",
30
+ "outline",
31
+ "outlineVariant",
32
+ "shadow",
33
+ "scrim",
34
+ "surfaceTint",
35
+ "primary",
36
+ "onPrimary",
37
+ "primaryContainer",
38
+ "onPrimaryContainer",
39
+ "inversePrimary",
40
+ "secondary",
41
+ "onSecondary",
42
+ "secondaryContainer",
43
+ "onSecondaryContainer",
44
+ "tertiary",
45
+ "onTertiary",
46
+ "tertiaryContainer",
47
+ "onTertiaryContainer",
48
+ "error",
49
+ "onError",
50
+ "errorContainer",
51
+ "onErrorContainer",
52
+ "primaryFixed",
53
+ "primaryFixedDim",
54
+ "onPrimaryFixed",
55
+ "onPrimaryFixedVariant",
56
+ "secondaryFixed",
57
+ "secondaryFixedDim",
58
+ "onSecondaryFixed",
59
+ "onSecondaryFixedVariant",
60
+ "tertiaryFixed",
61
+ "tertiaryFixedDim",
62
+ "onTertiaryFixed",
63
+ "onTertiaryFixedVariant"
64
+ ]);
65
+
66
+ // Status colours Material 3 leaves to the app, as HCT hues harmonized toward the seed (customColor with blend), so a
67
+ // success, warning or info colour sits in the seed's family the way Material Theme Builder's custom colours do.
68
+ const STATUS_COLOR_HCT = Object.freeze({
69
+ success: Object.freeze({
70
+ hue: 145,
71
+ chroma: 48,
72
+ tone: 40
73
+ }),
74
+ warning: Object.freeze({
75
+ hue: 70,
76
+ chroma: 60,
77
+ tone: 60
78
+ }),
79
+ info: Object.freeze({
80
+ hue: 250,
81
+ chroma: 48,
82
+ tone: 40
83
+ })
84
+ });
85
+
86
+ // Material 3 state layers (hover 8%, focus 10%, pressed 10%, dragged 16%); Vuetify's other opacities follow them.
87
+ const STATE_LAYER_VARIABLES = Object.freeze({
88
+ "hover-opacity": 0.08,
89
+ "focus-opacity": 0.1,
90
+ "pressed-opacity": 0.1,
91
+ "dragged-opacity": 0.16,
92
+ "selected-opacity": 0.08,
93
+ "activated-opacity": 0.1,
94
+ "idle-opacity": 0,
95
+ "disabled-opacity": 0.38,
96
+ "high-emphasis-opacity": 1,
97
+ "border-opacity": 1,
98
+ // Material 3 elevation is a shadow only; the surface-container roles carry the tone, so no tint overlay.
99
+ "elevation-overlay-opacity-step": "0%"
100
+ });
101
+
102
+ const SURFACE_TONES = Object.freeze([
103
+ "surface-dim",
104
+ "surface-bright",
105
+ "surface-container-lowest",
106
+ "surface-container-low",
107
+ "surface-container",
108
+ "surface-container-high",
109
+ "surface-container-highest",
110
+ "surface-light"
111
+ ]);
112
+
113
+ function kebabCase(name) {
114
+ return name.replace(/[A-Z]/gu, (letter) => `-${letter.toLowerCase()}`);
115
+ }
116
+
117
+ function channels(argb) {
118
+ return `${redFromArgb(argb)}, ${greenFromArgb(argb)}, ${blueFromArgb(argb)}`;
119
+ }
120
+
121
+ /**
122
+ * A custom colour's four roles, as Material Theme Builder names them: the colour, on it, its container and on the
123
+ * container.
124
+ * @param {string} name A camelCase colour name.
125
+ */
126
+ function customColorRoleNames(name) {
127
+ const role = kebabCase(name);
128
+ return [role, `on-${role}`, `${role}-container`, `on-${role}-container`];
129
+ }
130
+
131
+ /**
132
+ * Adds a colour's four roles, from customColor harmonized toward the seed (blend).
133
+ * @param {Record<string, number>} roles
134
+ * @param {number} seedArgb
135
+ * @param {boolean} dark
136
+ * @param {string} name
137
+ * @param {number} argb
138
+ */
139
+ function addCustomColorRoles(roles, seedArgb, dark, name, argb) {
140
+ const custom = customColor(seedArgb, { name, value: argb, blend: true });
141
+ const tones = dark ? custom.dark : custom.light;
142
+ const [role, onRole, containerRole, onContainerRole] = customColorRoleNames(name);
143
+ roles[role] = tones.color;
144
+ roles[onRole] = tones.onColor;
145
+ roles[containerRole] = tones.colorContainer;
146
+ roles[onContainerRole] = tones.onColorContainer;
147
+ }
148
+
149
+ /**
150
+ * One scheme's colours: every Material 3 role in kebab-case, the status colours and the app's own colours with their
151
+ * containers, and the Vuetify-only names mapped onto Material 3 roles.
152
+ * @param {SchemeTonalSpot} scheme
153
+ * @param {number} seedArgb
154
+ * @param {boolean} dark
155
+ * @param {Array<[string, number]>} appColors
156
+ */
157
+ function schemeColors(scheme, seedArgb, dark, appColors) {
158
+ const roles = {};
159
+ for (const name of ROLE_NAMES) {
160
+ roles[kebabCase(name)] = MaterialDynamicColors[name].getArgb(scheme);
161
+ }
162
+ for (const [name, { hue, chroma, tone }] of Object.entries(STATUS_COLOR_HCT)) {
163
+ addCustomColorRoles(roles, seedArgb, dark, name, Hct.from(hue, chroma, tone).toInt());
164
+ }
165
+ // Vuetify paints fields, alerts, toolbars and timelines with surface-light; Material 3 uses the highest container.
166
+ roles["surface-light"] = roles["surface-container-highest"];
167
+ // Content on every surface tone is on-surface in Material 3; Vuetify would otherwise pick black or white for a
168
+ // bg-surface-container-* or bg-surface-dim/bright element.
169
+ for (const surface of SURFACE_TONES) {
170
+ roles[`on-${surface}`] = roles["on-surface"];
171
+ }
172
+ roles["primary-darken-1"] = roles["on-primary-container"];
173
+ roles["secondary-darken-1"] = roles["on-secondary-container"];
174
+ for (const [name, argb] of appColors) {
175
+ addCustomColorRoles(roles, seedArgb, dark, name, argb);
176
+ }
177
+ return roles;
178
+ }
179
+
180
+ /**
181
+ * One Vuetify theme from one Material 3 scheme.
182
+ * @param {number} seedArgb
183
+ * @param {boolean} dark
184
+ * @param {Array<[string, number]>} appColors
185
+ */
186
+ function vuetifyTheme(seedArgb, dark, appColors) {
187
+ const scheme = new SchemeTonalSpot(Hct.fromInt(seedArgb), dark, 0);
188
+ const roles = schemeColors(scheme, seedArgb, dark, appColors);
189
+ const colors = Object.fromEntries(Object.entries(roles).map(([name, argb]) => [name, hexFromArgb(argb)]));
190
+ return {
191
+ dark,
192
+ colors,
193
+ variables: {
194
+ ...STATE_LAYER_VARIABLES,
195
+ // Channel strings: Vuetify writes them as rgba(var(--v-border-color), var(--v-border-opacity)).
196
+ "border-color": channels(roles["outline-variant"]),
197
+ "shadow-color": channels(roles.shadow),
198
+ "theme-kbd": colors["surface-container-highest"],
199
+ "theme-on-kbd": colors["on-surface"],
200
+ "theme-code": colors["surface-container"],
201
+ "theme-on-code": colors["on-surface"],
202
+ // The text Vuetify puts on a colour that has no on- role: the light or the dark end of the neutral palette.
203
+ "theme-on-dark": dark ? colors["on-surface"] : colors.surface,
204
+ "theme-on-light": dark ? colors.surface : colors["on-surface"]
205
+ }
206
+ };
207
+ }
208
+
209
+ /**
210
+ * The app's own colours, such as a brand or partner colour, checked: camelCase names whose roles are not already
211
+ * scheme roles, six-digit hex values.
212
+ * @param {Record<string, string>} colors
213
+ * @param {Set<string>} schemeRoles
214
+ * @returns {Array<[string, number]>}
215
+ */
216
+ function normalizeAppColors(colors, schemeRoles) {
217
+ return Object.entries(colors).map(([name, value]) => {
218
+ if (!/^[a-z][A-Za-z0-9]*$/u.test(name)) {
219
+ throw new TypeError(`Theme colour "${name}" needs a camelCase name, such as "partner" or "brandAccent".`);
220
+ }
221
+ const clash = customColorRoleNames(name).find((role) => schemeRoles.has(role));
222
+ if (clash) {
223
+ throw new TypeError(`Theme colour "${name}" would replace the scheme's "${clash}" role; choose another name.`);
224
+ }
225
+ const hex = String(value || "").trim();
226
+ if (!/^#[0-9a-f]{6}$/iu.test(hex)) {
227
+ throw new TypeError(`Theme colour "${name}" must be a six-digit hex colour, not "${hex}".`);
228
+ }
229
+ return [name, argbFromHex(hex)];
230
+ });
231
+ }
232
+
233
+ /**
234
+ * The light and dark Material 3 schemes generated from one seed colour with Material Color Utilities
235
+ * (SchemeTonalSpot, the Material 3 default), as Vuetify themes named light and dark. Each of the app's own colours
236
+ * adds four roles in both schemes, harmonized toward the seed as Material Theme Builder's custom colours are:
237
+ * `partner: "#0A7D3E"` gives partner, on-partner, partner-container and on-partner-container.
238
+ * @param {string} seed A hex colour such as "#6750A4".
239
+ * @param {Record<string, string>} [colors] The app's own colours by camelCase name, as hex colours.
240
+ */
241
+ function materialThemes(seed, colors = {}) {
242
+ const normalizedSeed = String(seed || "").trim();
243
+ if (!/^#[0-9a-f]{6}$/iu.test(normalizedSeed)) {
244
+ throw new TypeError(`The Material theme seed must be a six-digit hex colour, not "${normalizedSeed}".`);
245
+ }
246
+ const seedArgb = argbFromHex(normalizedSeed);
247
+ const schemeRoles = new Set(Object.keys(vuetifyTheme(seedArgb, false, []).colors));
248
+ const appColors = normalizeAppColors(colors, schemeRoles);
249
+ return {
250
+ light: vuetifyTheme(seedArgb, false, appColors),
251
+ dark: vuetifyTheme(seedArgb, true, appColors)
252
+ };
253
+ }
254
+
255
+ export { materialThemes };