@jskit-ai/material-web 0.1.15 → 0.1.16
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 +1 -0
- package/package.json +1 -1
- package/src/client/index.js +25 -1
- package/test/materialWeb.test.js +52 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- `createMaterialVuetifyOptions()` starts loading the theme's typefaces in a browser, Roboto Flex unless the app names its own, at the regular and medium weights Material 3's type roles use (`document.fonts.load`, without waiting), so they are usually in before the app mounts. A face was fetched only when laid-out text first used it, after the app mounted, since the foundations' boot loader draws in system-ui: the page first showed in the fallback font and whatever was measured from text, such as shell-web's content-fitted drawer, changed when it arrived (in shell-web's adaptive shell fixture, Roboto Flex was first asked for 137-161 ms after the shell mounted, and the page then moved 2px). A face that is slow or fails leaves the fallback in place, as `font-display: swap` does.
|
|
5
6
|
- axe judges the text of a tonal alert, an alert with a border, an editable stepper step, a tonal snackbar and an expansion panel's title, the title's in each state that shows its state layer. Vuetify draws each one's own layer (the alert's tint and its border box, the step's state layer and underlay, the snackbar's tint, the title's state layer on hover, on keyboard focus and on an open `focusable` panel) as a positioned box after the text it covers, so axe found it over the text and judged none of it (color-contrast incomplete, bgOverlap). material.css draws the alert's, step's and snackbar's layers under the text, as it already did a button's, chip's, list item's, card's and avatar's: each component is a stacking context with its layers at z-index -1 in it, and each part holding its text is one too. A title's text is the title's own, with no part to lift above a layer, so material.css draws its state as the title's own background, the text's colour at the state's opacity, and hides Vuetify's layer; a title with a background of its own (its `color`, a bg- class or an inline background) keeps Vuetify's layer, since no rule can mix a tint into a background another rule sets. The tints are the text's own colour, so the window's pixels are the same but for rounding, two levels of 255 at most. An icon button's text is judged as Vuetify draws it. A circular progress's reading keeps Vuetify's order: its ring is an svg, which axe takes for an image whether it lies over the reading or under it (bgOverlap, imgNode), so it judges the reading neither way. `underlayStacking.browser.test.js` has axe judge each of these texts, the titles' at rest, hovered and focused, finds a title of its own colour judged on its background at rest and under Vuetify's layer when hovered, and finds the same pixels, but for rounding, as with Vuetify's drawing.
|
|
6
7
|
- A keyboard press's ripple ends with the press on a control whose own key handler moves focus away, as mobilynet's map card does: Enter opens a panel and focuses its title. Vuetify's ripple directive hears a key after the control's own listeners, so the card's blur came before its ripple existed, the ripple then showed on a card that no longer held focus, Enter came up on the panel's title, and nothing ended it. It stayed drawn, axe read its whole box, which reaches past the card, as covering mobilynet's label above it (color-contrast incomplete, bgOverlap), and Vuetify's flag that a keyboard ripple is showing stayed set, so the next control pressed with Enter showed none. `createMaterialVuetifyOptions()`, in a browser, now listens on the window once: when a key comes up, each control around where it went down that shows a ripple but no longer holds focus is sent the blur it missed, and Vuetify's own blur listener ends the ripple and clears the flag. A blur listener of the control's own hears that blur too, a second time. `keyboardRipple.browser.test.js` presses Enter on such a card, then on a button.
|
|
7
8
|
- axe judges the texts of a dialog, menu, tooltip or snackbar open over page content that has a z-index of its own. Vuetify places every overlay in a container (`.v-overlay-container`) with `contain: layout` and `display: contents`, which draws no box, so the browser makes no stacking context of it; axe-core 4.14 counts `contain: layout` as one whatever the element draws, ranked the container at the page's base level, and so ranked every overlay under any content with a z-index of 1 or more. Over such content it found the page over a dialog's text and judged none of it (color-contrast incomplete, bgOverlap): mobilynet's dialogs, over its pages' content at z-index 1. axe-core 4.11 read `contain` too, but ranked the container by its position, an entry the overlay's own stacking context took out of the order; 4.14 keeps a stacking context in the order. material.css sets the container's `contain` to none, which the browser draws the same: `overlayStacking.browser.test.js` opens a dialog over a div at z-index 1, has axe judge each of its texts, and finds the same elements under every text (elementsFromPoint) and the same pixels as with Vuetify's `contain: layout`.
|
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.16",
|
|
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": {
|
package/src/client/index.js
CHANGED
|
@@ -8,6 +8,9 @@ import { materialSymbols } from "./symbols.js";
|
|
|
8
8
|
const DEFAULT_SEED = "#6750A4";
|
|
9
9
|
// Roboto Flex, Material 3's default for both typefaces (material.css loads it).
|
|
10
10
|
const ROBOTO_FLEX = '"Roboto Flex Variable", "Roboto Flex", Roboto, system-ui, sans-serif';
|
|
11
|
+
// The weights Material 3's type roles use: regular for display, headline, title-large and body; medium for the other
|
|
12
|
+
// titles and the labels.
|
|
13
|
+
const TYPE_ROLE_WEIGHTS = Object.freeze([400, 500]);
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* Material 3's two typefaces as Vuetify theme variables: brand for display, headline and title-large (Vuetify's
|
|
@@ -25,6 +28,25 @@ function typefaceVariables({ brand = ROBOTO_FLEX, plain = ROBOTO_FLEX } = {}) {
|
|
|
25
28
|
return { "font-heading": family(brand, "brand"), "font-body": family(plain, "plain") };
|
|
26
29
|
}
|
|
27
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Starts loading the theme's typefaces in a browser as the app boots, without waiting for them. A face is otherwise
|
|
33
|
+
* fetched only when laid-out text first uses it, after the app mounts (a boot loader draws in system-ui), so the page
|
|
34
|
+
* first showed in the fallback font and whatever was measured from text, such as the shell's content-fitted drawer,
|
|
35
|
+
* changed when the face arrived. Started here it is usually in before the app mounts; a face that is slow or fails
|
|
36
|
+
* leaves the fallback in place, as font-display: swap does.
|
|
37
|
+
* @param {Window | undefined} view
|
|
38
|
+
* @param {Record<string, string>} typefaces The theme's font variables, each a CSS font-family value.
|
|
39
|
+
*/
|
|
40
|
+
function startLoadingTypefaces(view, typefaces) {
|
|
41
|
+
const fonts = view?.document?.fonts;
|
|
42
|
+
if (!fonts) return;
|
|
43
|
+
for (const family of new Set(Object.values(typefaces))) {
|
|
44
|
+
for (const weight of TYPE_ROLE_WEIGHTS) {
|
|
45
|
+
fonts.load(`${weight} 1em ${family}`).catch(() => undefined);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
28
50
|
/**
|
|
29
51
|
* An app's own icons as Vuetify aliases: `{ name: "<24x24 path data>" }` becomes `$name`.
|
|
30
52
|
* @param {Record<string, string>} icons
|
|
@@ -47,7 +69,8 @@ function appIconAliases(icons) {
|
|
|
47
69
|
* plain typefaces (Roboto Flex unless the app names its own), Material Symbols Rounded behind every icon alias (plus
|
|
48
70
|
* the app's own), and JSKIT's Material 3 component defaults. Pass the result to createVuetify(); import
|
|
49
71
|
* "@jskit-ai/material-web/client/material.css" after "vuetify/styles". In a browser it also makes a keyboard press's
|
|
50
|
-
* ripple end with the press on a control whose own key handler moves focus away (keyboardRipple.js), once per window
|
|
72
|
+
* ripple end with the press on a control whose own key handler moves focus away (keyboardRipple.js), once per window,
|
|
73
|
+
* and starts loading the typefaces (startLoadingTypefaces), so they are usually in before the app mounts.
|
|
51
74
|
* @param {{ seed?: string, colors?: Record<string, string | { value: string, blend?: boolean }>, icons?: Record<string, string>, typography?: { brand?: string, plain?: string } }} [theme]
|
|
52
75
|
*/
|
|
53
76
|
function createMaterialVuetifyOptions({ seed = DEFAULT_SEED, colors = {}, icons = {}, typography = {} } = {}) {
|
|
@@ -58,6 +81,7 @@ function createMaterialVuetifyOptions({ seed = DEFAULT_SEED, colors = {}, icons
|
|
|
58
81
|
}
|
|
59
82
|
const aliases = { ...materialSymbols, ...appIconAliases(icons) };
|
|
60
83
|
endKeyboardRipplesWithThePress(globalThis.window);
|
|
84
|
+
startLoadingTypefaces(globalThis.window, typefaces);
|
|
61
85
|
return {
|
|
62
86
|
blueprint: md3,
|
|
63
87
|
defaults: materialDefaults,
|
package/test/materialWeb.test.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createHash } from "node:crypto";
|
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import path from "node:path";
|
|
6
|
+
import process from "node:process";
|
|
6
7
|
import test from "node:test";
|
|
7
8
|
import { Hct, argbFromHex } from "@material/material-color-utilities";
|
|
8
9
|
import { materialThemes, createMaterialVuetifyOptions } from "../src/client/index.js";
|
|
@@ -271,6 +272,57 @@ test("a browser that refuses storage still gets its theme", async (t) => {
|
|
|
271
272
|
assert.deepEqual(sandboxed.materialThemes(...VIBE64_INPUT), materialThemes(...VIBE64_INPUT));
|
|
272
273
|
});
|
|
273
274
|
|
|
275
|
+
// A window whose document's fonts list each face asked for, answering with `answer`.
|
|
276
|
+
function fontsWindow(t, answer = () => Promise.resolve([])) {
|
|
277
|
+
const loads = [];
|
|
278
|
+
globalThis.window = {
|
|
279
|
+
addEventListener() {},
|
|
280
|
+
removeEventListener() {},
|
|
281
|
+
document: {
|
|
282
|
+
fonts: {
|
|
283
|
+
load(font) {
|
|
284
|
+
loads.push(font);
|
|
285
|
+
return answer(font);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
t.after(() => delete globalThis.window);
|
|
291
|
+
return loads;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
test("in a browser the Vuetify options start loading the theme's typefaces, regular and medium, without waiting", (t) => {
|
|
295
|
+
const loads = fontsWindow(t, () => new Promise(() => {}));
|
|
296
|
+
const robotoFlex = '"Roboto Flex Variable", "Roboto Flex", Roboto, system-ui, sans-serif';
|
|
297
|
+
|
|
298
|
+
createMaterialVuetifyOptions();
|
|
299
|
+
assert.deepEqual(loads, [`400 1em ${robotoFlex}`, `500 1em ${robotoFlex}`]);
|
|
300
|
+
|
|
301
|
+
loads.length = 0;
|
|
302
|
+
createMaterialVuetifyOptions({ typography: { brand: '"Fraunces", serif', plain: '"Inter", sans-serif' } });
|
|
303
|
+
assert.deepEqual(loads, [
|
|
304
|
+
'400 1em "Fraunces", serif',
|
|
305
|
+
'500 1em "Fraunces", serif',
|
|
306
|
+
'400 1em "Inter", sans-serif',
|
|
307
|
+
'500 1em "Inter", sans-serif'
|
|
308
|
+
]);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
test("a typeface that fails to load leaves the fallback in place, with no unhandled failure", async (t) => {
|
|
312
|
+
const unhandled = [];
|
|
313
|
+
const onUnhandled = (reason) => unhandled.push(reason);
|
|
314
|
+
process.on("unhandledRejection", onUnhandled);
|
|
315
|
+
t.after(() => process.off("unhandledRejection", onUnhandled));
|
|
316
|
+
const loads = fontsWindow(t, () => Promise.reject(new Error("NetworkError: the font did not load")));
|
|
317
|
+
|
|
318
|
+
const options = createMaterialVuetifyOptions();
|
|
319
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
320
|
+
|
|
321
|
+
assert.equal(loads.length, 2);
|
|
322
|
+
assert.equal(options.theme.themes.light.variables["font-body"], '"Roboto Flex Variable", "Roboto Flex", Roboto, system-ui, sans-serif');
|
|
323
|
+
assert.deepEqual(unhandled, []);
|
|
324
|
+
});
|
|
325
|
+
|
|
274
326
|
test("a seed that is not a six-digit hex colour is refused", () => {
|
|
275
327
|
assert.throws(() => materialThemes("purple"), /six-digit hex/u);
|
|
276
328
|
assert.throws(() => createMaterialVuetifyOptions({ seed: "#123" }), /six-digit hex/u);
|