@jskit-ai/material-web 0.1.0 → 0.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ - Cards have no default `elevation`: Vuetify's elevated variant (the default) keeps its level-1 shadow, and flat, tonal and outlined cards (banners, heroes, containers) have none, as Material 3 draws them; the same for cards in a bottom sheet.
6
+ - FABs keep Material 3's sizes instead of the common button's 40dp: 56dp, small 40dp, large 96dp (36dp icon), and the extended FAB 56dp tall.
7
+ - Small, x-small and large buttons get the 48dp touch target that default and icon buttons have, as a transparent hit area around the unchanged visual; stacked buttons are left as they are. The hit area is ink overflow (layout containment), so a button at the edge of a window or scroll container adds no scrollbar.
8
+ - A button label stays on one line and ends in an ellipsis when it is longer than its button, instead of spilling out of it.
9
+ - 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.
10
+
3
11
  ## 0.1.0
4
12
 
5
13
  - 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; a name that
40
- would replace a scheme role is refused. `defaultTheme` is `"system"`, so the app follows the
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
@@ -60,8 +62,10 @@ export const theme = {
60
62
  fields, 8dp chips that close with `$close`, 4dp menus on `surface-container`,
61
63
  the inverse-surface snackbar, the Material switch and the 16dp
62
64
  `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
+ - **`material.css`.** What props cannot set: 40dp buttons and 40dp icon
66
+ buttons, a 48dp touch target on every button size (small and x-small keep
67
+ their look), one-line labels that end in an ellipsis, 28dp dialogs and
68
+ bottom sheets, square
65
69
  full-screen dialogs on `surface`, a 48dp touch target on clickable chips,
66
70
  inverse-surface tooltips, emphasized easing
67
71
  and reduced motion. Its component rules sit in Vuetify's `vuetify-overrides`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/material-web",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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 (blend).
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: true });
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 values.
212
- * @param {Record<string, string>} colors
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 hex = String(value || "").trim();
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
- return [name, argbFromHex(hex)];
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 name, as hex colours.
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();
@@ -13,9 +13,9 @@ const materialDefaults = Object.freeze({
13
13
  rounded: "pill",
14
14
  variant: "flat"
15
15
  },
16
+ // No elevation: Vuetify's elevated variant (the default) draws level 1, and flat, tonal and outlined cards draw none.
16
17
  VCard: {
17
18
  color: "surface-container-low",
18
- elevation: 1,
19
19
  rounded: 12
20
20
  },
21
21
  VChip: {
@@ -34,7 +34,6 @@ const materialDefaults = Object.freeze({
34
34
  contentClass: "jskit-material-bottom-sheet",
35
35
  VCard: {
36
36
  color: "surface-container-low",
37
- elevation: 1,
38
37
  rounded: 0
39
38
  }
40
39
  },
@@ -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 {
@@ -20,26 +20,26 @@
20
20
  }
21
21
 
22
22
  @layer vuetify-overrides {
23
- /* Common buttons: 40dp tall, full shape, 24dp side padding (16dp beside an icon), a 48dp touch target. */
24
- .v-btn--size-default:not(.v-btn--stacked, .v-btn--icon) {
23
+ /* Common buttons: 40dp tall, full shape, 24dp side padding (16dp beside an icon). */
24
+ .v-btn--size-default:not(.v-btn--stacked, .v-btn--icon, .v-fab .v-btn) {
25
25
  --v-btn-height: 40px;
26
26
  padding-inline: 24px;
27
27
  }
28
28
 
29
- .v-btn--size-default:not(.v-btn--stacked, .v-btn--icon):has(> .v-btn__prepend) {
29
+ .v-btn--size-default:not(.v-btn--stacked, .v-btn--icon, .v-fab .v-btn):has(> .v-btn__prepend) {
30
30
  padding-inline-start: 16px;
31
31
  }
32
32
 
33
- .v-btn--size-default:not(.v-btn--stacked, .v-btn--icon):has(> .v-btn__append) {
33
+ .v-btn--size-default:not(.v-btn--stacked, .v-btn--icon, .v-fab .v-btn):has(> .v-btn__append) {
34
34
  padding-inline-end: 16px;
35
35
  }
36
36
 
37
- .v-btn--size-default.v-btn--variant-text:not(.v-btn--stacked, .v-btn--icon) {
37
+ .v-btn--size-default.v-btn--variant-text:not(.v-btn--stacked, .v-btn--icon, .v-fab .v-btn) {
38
38
  padding-inline: 12px;
39
39
  }
40
40
 
41
41
  /* Icon buttons: a 40dp state layer around a 24dp icon. */
42
- .v-btn--icon.v-btn--size-default {
42
+ .v-btn--icon.v-btn--size-default:not(.v-fab .v-btn) {
43
43
  --v-btn-height: 28px;
44
44
  }
45
45
 
@@ -47,11 +47,45 @@
47
47
  font-size: 24px;
48
48
  }
49
49
 
50
- .v-btn--size-default:not(.v-btn--stacked) {
50
+ /* FABs are not common buttons: 56dp (small 40dp, large 96dp with a 36dp icon), and the extended FAB is 56dp tall. */
51
+ .v-fab .v-btn {
52
+ --jskit-fab-size: 56px;
53
+ }
54
+
55
+ .v-fab .v-btn--size-small {
56
+ --jskit-fab-size: 40px;
57
+ }
58
+
59
+ .v-fab .v-btn--size-large {
60
+ --jskit-fab-size: 96px;
61
+ }
62
+
63
+ .v-fab .v-btn--icon {
64
+ height: var(--jskit-fab-size);
65
+ width: var(--jskit-fab-size);
66
+ }
67
+
68
+ .v-fab--extended .v-btn {
69
+ --v-btn-height: var(--jskit-fab-size);
70
+ }
71
+
72
+ .v-fab .v-btn .v-icon {
73
+ font-size: 24px;
74
+ }
75
+
76
+ .v-fab .v-btn--size-large .v-icon {
77
+ font-size: 36px;
78
+ }
79
+
80
+ /* Every button, small, x-small and icon buttons included, keeps its visual size and gets a 48dp touch target: a
81
+ transparent hit area centred on it. Layout containment makes what reaches outside the button ink overflow, so a
82
+ hit area at the edge of a window or scroll container never adds a scrollbar. */
83
+ .v-btn:not(.v-btn--stacked) {
84
+ contain: layout;
51
85
  overflow: visible;
52
86
  }
53
87
 
54
- .v-btn--size-default:not(.v-btn--stacked)::before {
88
+ .v-btn:not(.v-btn--stacked)::before {
55
89
  content: "";
56
90
  height: max(100%, 48px);
57
91
  left: 50%;
@@ -61,6 +95,14 @@
61
95
  width: max(100%, 48px);
62
96
  }
63
97
 
98
+ /* A label stays on one line, as Material 3 draws it; one longer than its button ends in an ellipsis. */
99
+ .v-btn:not(.v-btn--stacked, .v-btn--icon) > .v-btn__content:not(:has(> *)) {
100
+ display: block;
101
+ min-width: 0;
102
+ overflow: hidden;
103
+ text-overflow: ellipsis;
104
+ }
105
+
64
106
  /* Outlined buttons draw the outline role, chips outline-variant. */
65
107
  .v-btn--variant-outlined:not([class*=" text-"]) {
66
108
  border-color: rgb(var(--v-theme-outline));
@@ -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]) {
@@ -120,6 +139,9 @@ test("the Vuetify options follow the system scheme on the md3 blueprint with Mat
120
139
  assert.equal(options.icons.aliases.arrowBack, materialSymbols.arrowBack);
121
140
  assert.equal(options.icons.aliases.myLeaf, "svg:M1 1h22v22H1z");
122
141
  assert.equal(options.defaults.VCard.rounded, 12);
142
+ // Vuetify's elevated variant draws the card's level 1; a default elevation would also lift flat and tonal cards.
143
+ assert.equal("elevation" in options.defaults.VCard, false);
144
+ assert.equal("elevation" in options.defaults.VBottomSheet.VCard, false);
123
145
  assert.equal(options.defaults.VChip.rounded, 8);
124
146
  assert.equal(options.defaults.VFab.rounded, 16);
125
147
  assert.equal(options.defaults.VChip.closeIcon, "$close");
@@ -154,6 +176,15 @@ test("material.css holds the exact-size rules without Sass or !important", async
154
176
  assert.doesNotMatch(css, /\$[a-z-]+\s*:/u);
155
177
  assert.match(css, /--v-btn-height: 40px/u);
156
178
  assert.match(css, /height: max\(100%, 48px\)/u);
179
+ // Every button size gets the touch target, not only the default one, and a long label ends in an ellipsis.
180
+ assert.match(css, /\.v-btn:not\(\.v-btn--stacked\)::before \{[^}]*width: max\(100%, 48px\);/u);
181
+ assert.match(css, /\.v-btn:not\(\.v-btn--stacked\) \{[^}]*contain: layout;/u);
182
+ // FABs keep their own sizes: the common and icon button sizes leave them out.
183
+ assert.match(css, /\.v-btn--size-default:not\(\.v-btn--stacked, \.v-btn--icon, \.v-fab \.v-btn\) \{[^}]*--v-btn-height: 40px;/u);
184
+ assert.match(css, /\.v-btn--icon\.v-btn--size-default:not\(\.v-fab \.v-btn\) \{[^}]*--v-btn-height: 28px;/u);
185
+ assert.match(css, /\.v-fab--extended \.v-btn \{[^}]*--v-btn-height: var\(--jskit-fab-size\);/u);
186
+ assert.doesNotMatch(css, /\.v-btn--size-default:not\(\.v-btn--stacked\)::before/u);
187
+ assert.match(css, /> \.v-btn__content:not\(:has\(> \*\)\) \{[^}]*text-overflow: ellipsis;/u);
157
188
  assert.match(css, /border-radius: 28px;/u);
158
189
  assert.match(css, /v-dialog--fullscreen[^{]+\{\s*border-radius: 0;/u);
159
190
  assert.match(css, /border-radius: 28px 28px 0 0/u);