@jskit-ai/material-web 0.1.0 → 0.1.1
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 +4 -0
- package/README.md +4 -2
- package/package.json +1 -1
- package/src/client/colorSchemes.js +24 -14
- package/src/client/index.js +1 -1
- package/test/materialWeb.test.js +19 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
- A theme colour can keep its own hue: `colors: { learning: { value: "#F5C518", blend: false } }` still gets its four roles, light and dark, without the shift toward the seed (Material Theme Builder's Blend switched off). A hex string, or `{ value }`, stays harmonized as before.
|
|
6
|
+
|
|
3
7
|
## 0.1.0
|
|
4
8
|
|
|
5
9
|
- 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
|
@@ -36,8 +36,10 @@ export const theme = {
|
|
|
36
36
|
`on-…-container` roles. An app's own colours go in `theme.colors` by
|
|
37
37
|
camelCase name and become custom colours the same way: `partner: "#0A7D3E"`
|
|
38
38
|
gives `partner`, `on-partner`, `partner-container` and
|
|
39
|
-
`on-partner-container`, harmonized to the seed, in both schemes;
|
|
40
|
-
|
|
39
|
+
`on-partner-container`, harmonized to the seed, in both schemes;
|
|
40
|
+
`{ value: "#F5C518", blend: false }` keeps the colour's own hue (Material
|
|
41
|
+
Theme Builder's Blend switched off); a name that would replace a scheme role
|
|
42
|
+
is refused. `defaultTheme` is `"system"`, so the app follows the
|
|
41
43
|
device's light or dark setting. Theme variables carry the Material 3 state
|
|
42
44
|
layers (hover 8%, focus 10%, pressed 10%, dragged 16%) and `border-color` and
|
|
43
45
|
`shadow-color` as channel strings (`outline-variant` and `shadow`). There is no
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/material-web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
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
6
|
"exports": {
|
|
@@ -129,15 +129,17 @@ function customColorRoleNames(name) {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
* Adds a colour's four roles, from customColor harmonized toward the seed
|
|
132
|
+
* Adds a colour's four roles, from customColor: harmonized toward the seed unless `blend` is false, as Material Theme
|
|
133
|
+
* Builder's per-colour Blend toggle does.
|
|
133
134
|
* @param {Record<string, number>} roles
|
|
134
135
|
* @param {number} seedArgb
|
|
135
136
|
* @param {boolean} dark
|
|
136
137
|
* @param {string} name
|
|
137
138
|
* @param {number} argb
|
|
139
|
+
* @param {boolean} [blend]
|
|
138
140
|
*/
|
|
139
|
-
function addCustomColorRoles(roles, seedArgb, dark, name, argb) {
|
|
140
|
-
const custom = customColor(seedArgb, { name, value: argb, blend
|
|
141
|
+
function addCustomColorRoles(roles, seedArgb, dark, name, argb, blend = true) {
|
|
142
|
+
const custom = customColor(seedArgb, { name, value: argb, blend });
|
|
141
143
|
const tones = dark ? custom.dark : custom.light;
|
|
142
144
|
const [role, onRole, containerRole, onContainerRole] = customColorRoleNames(name);
|
|
143
145
|
roles[role] = tones.color;
|
|
@@ -152,7 +154,7 @@ function addCustomColorRoles(roles, seedArgb, dark, name, argb) {
|
|
|
152
154
|
* @param {SchemeTonalSpot} scheme
|
|
153
155
|
* @param {number} seedArgb
|
|
154
156
|
* @param {boolean} dark
|
|
155
|
-
* @param {Array<[string, number]>} appColors
|
|
157
|
+
* @param {Array<[string, number, boolean]>} appColors
|
|
156
158
|
*/
|
|
157
159
|
function schemeColors(scheme, seedArgb, dark, appColors) {
|
|
158
160
|
const roles = {};
|
|
@@ -171,8 +173,8 @@ function schemeColors(scheme, seedArgb, dark, appColors) {
|
|
|
171
173
|
}
|
|
172
174
|
roles["primary-darken-1"] = roles["on-primary-container"];
|
|
173
175
|
roles["secondary-darken-1"] = roles["on-secondary-container"];
|
|
174
|
-
for (const [name, argb] of appColors) {
|
|
175
|
-
addCustomColorRoles(roles, seedArgb, dark, name, argb);
|
|
176
|
+
for (const [name, argb, blend] of appColors) {
|
|
177
|
+
addCustomColorRoles(roles, seedArgb, dark, name, argb, blend);
|
|
176
178
|
}
|
|
177
179
|
return roles;
|
|
178
180
|
}
|
|
@@ -181,7 +183,7 @@ function schemeColors(scheme, seedArgb, dark, appColors) {
|
|
|
181
183
|
* One Vuetify theme from one Material 3 scheme.
|
|
182
184
|
* @param {number} seedArgb
|
|
183
185
|
* @param {boolean} dark
|
|
184
|
-
* @param {Array<[string, number]>} appColors
|
|
186
|
+
* @param {Array<[string, number, boolean]>} appColors
|
|
185
187
|
*/
|
|
186
188
|
function vuetifyTheme(seedArgb, dark, appColors) {
|
|
187
189
|
const scheme = new SchemeTonalSpot(Hct.fromInt(seedArgb), dark, 0);
|
|
@@ -208,10 +210,11 @@ function vuetifyTheme(seedArgb, dark, appColors) {
|
|
|
208
210
|
|
|
209
211
|
/**
|
|
210
212
|
* 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
|
|
212
|
-
*
|
|
213
|
+
* scheme roles, and each a six-digit hex value (harmonized toward the seed) or `{ value, blend }`, where
|
|
214
|
+
* `blend: false` keeps the colour's own hue.
|
|
215
|
+
* @param {Record<string, string | { value: string, blend?: boolean }>} colors
|
|
213
216
|
* @param {Set<string>} schemeRoles
|
|
214
|
-
* @returns {Array<[string, number]>}
|
|
217
|
+
* @returns {Array<[string, number, boolean]>}
|
|
215
218
|
*/
|
|
216
219
|
function normalizeAppColors(colors, schemeRoles) {
|
|
217
220
|
return Object.entries(colors).map(([name, value]) => {
|
|
@@ -222,11 +225,16 @@ function normalizeAppColors(colors, schemeRoles) {
|
|
|
222
225
|
if (clash) {
|
|
223
226
|
throw new TypeError(`Theme colour "${name}" would replace the scheme's "${clash}" role; choose another name.`);
|
|
224
227
|
}
|
|
225
|
-
const
|
|
228
|
+
const entry = value !== null && typeof value === "object" ? value : { value };
|
|
229
|
+
const hex = String(entry.value || "").trim();
|
|
226
230
|
if (!/^#[0-9a-f]{6}$/iu.test(hex)) {
|
|
227
231
|
throw new TypeError(`Theme colour "${name}" must be a six-digit hex colour, not "${hex}".`);
|
|
228
232
|
}
|
|
229
|
-
|
|
233
|
+
const blend = entry.blend ?? true;
|
|
234
|
+
if (typeof blend !== "boolean") {
|
|
235
|
+
throw new TypeError(`Theme colour "${name}" takes blend: true or false, not ${JSON.stringify(blend)}.`);
|
|
236
|
+
}
|
|
237
|
+
return [name, argbFromHex(hex), blend];
|
|
230
238
|
});
|
|
231
239
|
}
|
|
232
240
|
|
|
@@ -234,9 +242,11 @@ function normalizeAppColors(colors, schemeRoles) {
|
|
|
234
242
|
* The light and dark Material 3 schemes generated from one seed colour with Material Color Utilities
|
|
235
243
|
* (SchemeTonalSpot, the Material 3 default), as Vuetify themes named light and dark. Each of the app's own colours
|
|
236
244
|
* 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.
|
|
245
|
+
* `partner: "#0A7D3E"` gives partner, on-partner, partner-container and on-partner-container. A brand or partner
|
|
246
|
+
* colour that must keep its hue is `{ value: "#F5C518", blend: false }`, Theme Builder's Blend switched off.
|
|
238
247
|
* @param {string} seed A hex colour such as "#6750A4".
|
|
239
|
-
* @param {Record<string, string>} [colors] The app's own colours by camelCase
|
|
248
|
+
* @param {Record<string, string | { value: string, blend?: boolean }>} [colors] The app's own colours by camelCase
|
|
249
|
+
* name: hex colours, or `{ value, blend }`.
|
|
240
250
|
*/
|
|
241
251
|
function materialThemes(seed, colors = {}) {
|
|
242
252
|
const normalizedSeed = String(seed || "").trim();
|
package/src/client/index.js
CHANGED
|
@@ -27,7 +27,7 @@ function appIconAliases(icons) {
|
|
|
27
27
|
* the app's own colours as harmonized custom colours), following the system's light or dark setting, Material Symbols
|
|
28
28
|
* Rounded behind every icon alias (plus the app's own), and JSKIT's Material 3 component defaults. Pass the result to
|
|
29
29
|
* createVuetify(); import "@jskit-ai/material-web/client/material.css" after "vuetify/styles".
|
|
30
|
-
* @param {{ seed?: string, colors?: Record<string, string>, icons?: Record<string, string> }} [theme]
|
|
30
|
+
* @param {{ seed?: string, colors?: Record<string, string | { value: string, blend?: boolean }>, icons?: Record<string, string> }} [theme]
|
|
31
31
|
*/
|
|
32
32
|
function createMaterialVuetifyOptions({ seed = DEFAULT_SEED, colors = {}, icons = {} } = {}) {
|
|
33
33
|
return {
|
package/test/materialWeb.test.js
CHANGED
|
@@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises";
|
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import test from "node:test";
|
|
6
|
+
import { Hct, argbFromHex } from "@material/material-color-utilities";
|
|
6
7
|
import { materialThemes, createMaterialVuetifyOptions } from "../src/client/index.js";
|
|
7
8
|
import { materialSymbols, vuetifyAliasNames } from "../src/client/symbols.js";
|
|
8
9
|
import { buildSymbolsSource } from "../scripts/generate-symbols.mjs";
|
|
@@ -90,6 +91,24 @@ test("an app's own colours become harmonized custom colour roles, light and dark
|
|
|
90
91
|
);
|
|
91
92
|
});
|
|
92
93
|
|
|
94
|
+
test("an app colour with blend: false keeps its own hue; a hex string or { value } stays harmonized", () => {
|
|
95
|
+
const hue = (hex) => Hct.fromInt(argbFromHex(hex)).hue;
|
|
96
|
+
const learning = "#F5C518";
|
|
97
|
+
const kept = materialThemes("#6750A4", { learning: { value: learning, blend: false } });
|
|
98
|
+
const blended = materialThemes("#6750A4", { learning });
|
|
99
|
+
for (const scheme of ["light", "dark"]) {
|
|
100
|
+
for (const role of ["learning", "learning-container"]) {
|
|
101
|
+
assert.ok(Math.abs(hue(kept[scheme].colors[role]) - hue(learning)) < 3, `${scheme} ${role} keeps the colour's hue`);
|
|
102
|
+
assert.ok(Math.abs(hue(blended[scheme].colors[role]) - hue(learning)) > 5, `${scheme} ${role} moves toward the seed`);
|
|
103
|
+
}
|
|
104
|
+
assert.match(kept[scheme].colors["on-learning-container"], HEX);
|
|
105
|
+
}
|
|
106
|
+
assert.deepEqual(materialThemes("#6750A4", { learning: { value: learning } }), blended);
|
|
107
|
+
assert.deepEqual(materialThemes("#6750A4", { learning: { value: learning, blend: true } }), blended);
|
|
108
|
+
assert.throws(() => materialThemes("#6750A4", { learning: { value: learning, blend: "no" } }), /blend: true or false/u);
|
|
109
|
+
assert.throws(() => materialThemes("#6750A4", { learning: { blend: false } }), /six-digit hex/u);
|
|
110
|
+
});
|
|
111
|
+
|
|
93
112
|
test("theme variables carry Material 3 state layers and channel strings for border and shadow", () => {
|
|
94
113
|
const { light, dark } = materialThemes("#6750A4");
|
|
95
114
|
for (const theme of [light, dark]) {
|