@jskit-ai/material-web 0.1.5 → 0.1.7
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 +3 -0
- package/README.md +44 -4
- package/package.json +3 -2
- package/scripts/patch-vuetify-loaders.mjs +216 -0
- package/src/client/defaults.js +19 -3
- package/src/client/material.css +24 -0
- package/test/fixtures/idle-loaders/App.vue +72 -0
- package/test/fixtures/idle-loaders/index.html +2 -0
- package/test/fixtures/idle-loaders/main.js +10 -0
- package/test/fixtures/sliders/index.html +2 -0
- package/test/fixtures/sliders/main.js +23 -0
- package/test/fixtures/sliders/vite.config.js +7 -0
- package/test/fixtures/vuetify-4.3.3/LICENSE.md +21 -0
- package/test/fixtures/vuetify-4.3.3/lib/components/VProgressCircular/VProgressCircular.js +209 -0
- package/test/fixtures/vuetify-4.3.3/lib/components/VProgressLinear/VProgressLinear.js +322 -0
- package/test/fixtures/vuetify-4.3.3/lib/labs/VLoadingIndicator/VLoadingIndicator.js +76 -0
- package/test/materialWeb.test.js +9 -0
- package/test/sliders.browser.test.js +77 -0
- package/test/vite.config.js +37 -0
- package/test/vuetifyIdleLoaders.browser.test.js +102 -0
- package/test/vuetifyLoaderPatch.test.js +202 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- Sliders and range sliders are Material 3's slider: Vuetify's pill variant by default, Material 3's extra-small (default) slider, with a 16dp track, a 4x44dp handle bar set apart from the track by a gap on either side, and a stop indicator at the end of the inactive track; the active track and the handle are `primary`, and the inactive track is `secondary-container` at full strength (the new `trackColor` default). They were Vuetify's default variant, a 4dp track under a round, raised 20dp handle. The md3 blueprint's `color: "primary"` made Vuetify draw the inactive track in `primary` faded to 38% (`v-slider-track__background--opacity`; 24% for the pill variant), and an app's `track-color` was faded the same way, which left a `secondary-container` track nearly invisible; a range slider had no colour at all, so its tracks and handles were a grey `surface-variant`. On a 4dp track, the pale `secondary-container` alone stays hard to see on a light container (1.05:1 on `surface-container-high`), which is why Material 3 draws it 16dp tall and ends it with the stop indicator. A disabled slider is on-surface at 38% for the active track and the handle and 12% for the inactive track, where Vuetify drew `surface-variant` at 38% and the inactive track at 14%. An invalid slider keeps Vuetify's look. The defaults set only `color`, `trackColor` and `variant`, so an app's `color` prop still sets the active track and the handle, and `variant="default"` brings back Vuetify's round handle. material-web's browser test measures each part's colour and opacity, light and dark, and the track, handle and stop indicator.
|
|
6
|
+
|
|
7
|
+
- Fields open fast again: material-web's install script (`postinstall`) stops Vuetify's idle loaders reading layout as they mount ([vuetifyjs/vuetify#23393](https://github.com/vuetifyjs/vuetify/issues/23393)). Every `VField`-based input mounts an idle `VProgressLinear`, whose `useElementIntersection(root)` read `getBoundingClientRect()` at once, a forced layout per field in a form that writes a style as it mounts: 300 fields took 15.9 s to mount, 1.3 s patched (the package's browser test). The script passes `{ immediate: false }` to the three loaders' calls (`VProgressLinear`, `VProgressCircular`, labs' `VLoadingIndicator`) in the installed Vuetify's `lib/` modules and its `dist/vuetify(-labs).esm.js`, `.cjs` and `.js` builds, all or nothing per Vuetify copy, and only where it finds exactly the calls it expects; otherwise it prints one line naming the issue and changes nothing. It never fails an install. Approve it in the app's root `package.json` (`"allowScripts": { "@jskit-ai/material-web": true }`, which `jskit update` adds): a strict install (`strict-allow-scripts`) fails without the approval, and an install with `--ignore-scripts` leaves Vuetify as published until `npm rebuild @jskit-ai/material-web`. Remove it once a fixed Vuetify is pinned; the README's Upstream workarounds says how.
|
|
5
8
|
- `material.css` draws every `v-bottom-navigation` as Material 3's navigation bar: a destination (each of its stacked buttons) has its icon, its `prepend-icon` or the first icon in its content (bare or in a badge), 24dp in a 64x32 pill that is its active indicator (`secondary-container`, the icon `on-secondary-container`) and holds its hover, focus and pressed state layer, where Vuetify drew its overlay and ripple across the whole button; the label is label-medium, 4dp below, `on-surface-variant` at rest and `on-surface` when active. A comfortable bar (48dp) drops the 4dp and a compact one (40dp) has a 24dp pill, so neither clips a label. The colours apply only where the app set none: a bar's `bg-color` (other than a surface tone) or colour class, and a destination's `color`, `base-color` or colour class, keep the app's colour on label and icon, the active pill drawn in that colour. An append icon, a badge's own icon and `mode="horizontal"` keep Vuetify's look. It was drawn only by the shell's `ShellTabLinkItem`, so an app's own bar of `v-btn`s kept Vuetify's look.
|
|
6
9
|
- **Breaking (visual).** Fields (`v-text-field`, `v-textarea`, `v-select`, `v-autocomplete`, `v-combobox`, `v-file-input`) keep Vuetify's line for their supporting text, as a Material 3 text field does: the defaults no longer set `hideDetails: "auto"`. With it, a field had no line until it had a message, so an error shown on blur or submit pushed the rest of the form down under the person's finger, and forms made up the space with a margin under each field. Upgrading: in a form, remove the `mb-*` margin under each field (the line is the gap now); a field outside a form (a search box, a filter, a toolbar select, a composer) sets `hide-details`, or `hide-details="auto"` to show a message only when it has one.
|
|
7
10
|
- `material.css` has a `text-on-*` class for every `on-*` role of the scheme. It had them for the main roles, success, warning and info, but not for the fixed roles' (`on-primary-fixed`, `on-primary-fixed-variant` and the secondary and tertiary ones) or the surface tones' (`on-surface-dim`, `on-surface-bright`, `on-surface-container-lowest` to `-highest`), so `color="on-primary-fixed-variant"` found no class. Vuetify names an `on-*` role's class `.on-<role>` only; an app colour's `on-*` roles keep that class alone. material-web's node test checks the classes against the generated scheme's roles.
|
package/README.md
CHANGED
|
@@ -65,14 +65,19 @@ export const theme = {
|
|
|
65
65
|
- **Components.** The md3 blueprint plus JSKIT's defaults: full-shape filled
|
|
66
66
|
buttons (with `to`, active only on exactly their route), cards that rest
|
|
67
67
|
flat on `surface-container-low` (`variant="elevated"` for level 1), flat expansion panels, outlined fields, 8dp chips that close with
|
|
68
|
-
`$close`, the inverse-surface snackbar, the Material switch
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
`$close`, the inverse-surface snackbar, the Material switch, Material 3's
|
|
69
|
+
slider and range slider (Vuetify's pill variant: a 16dp track, a 4x44dp
|
|
70
|
+
handle bar set apart from it and a stop indicator) in `primary` with a
|
|
71
|
+
`secondary-container` inactive track, and the 16dp `primary-container` FAB;
|
|
72
|
+
`v-btn-toggle` as a segmented button and `v-chip-group` as filter chips,
|
|
73
|
+
selected in `secondary-container`.
|
|
71
74
|
- **`material.css`.** What props cannot set: 40dp buttons and 40dp icon
|
|
72
75
|
buttons (none under 32dp, whatever its density), a 48dp touch target on
|
|
73
76
|
every button size (small and x-small keep their look, and their state
|
|
74
77
|
layers keep their corners) that stops at a neighbouring button, disabled container
|
|
75
|
-
buttons in on-surface at 12% and 38%, a
|
|
78
|
+
buttons in on-surface at 12% and 38%, a slider's inactive track at full
|
|
79
|
+
strength (Vuetify fades it to 24%) and a disabled slider in on-surface at
|
|
80
|
+
38% with its inactive track at 12%, a pagination's current page in the
|
|
76
81
|
activated layer, placeholders, text field labels and supporting text and list
|
|
77
82
|
item subtitles in on-surface-variant, one-line labels that
|
|
78
83
|
end in an ellipsis, 12dp card corners, 28dp dialogs on
|
|
@@ -130,6 +135,41 @@ Each one comes off when the upstream fix ships; its test says when.
|
|
|
130
135
|
would make an inline style). shell-web's browser test "a virtual-scroll list
|
|
131
136
|
in a dialog reaches its last item after the page around it re-renders"
|
|
132
137
|
guards it; it fails with `VDialog: { VCard: {} }` in the defaults.
|
|
138
|
+
- **Vuetify 4.3.2 and 4.3.3 (measured): idle loaders read layout as they
|
|
139
|
+
mount.** Every field built on `VField` (`v-text-field`, `v-select`,
|
|
140
|
+
`v-textarea` and the others) mounts an idle `VProgressLinear` in its loader
|
|
141
|
+
slot, and Vuetify's loaders (`VProgressLinear`, `VProgressCircular` and labs'
|
|
142
|
+
`VLoadingIndicator`) call `useElementIntersection(root)`, whose first check
|
|
143
|
+
runs at once and reads `getBoundingClientRect()`. In a form that writes a
|
|
144
|
+
style as it mounts, that is a forced layout per field: in this package's
|
|
145
|
+
browser test, 300 fields took 15.9 s to mount as Vuetify publishes them and
|
|
146
|
+
1.3 s patched. Upstream issue:
|
|
147
|
+
[vuetifyjs/vuetify#23393](https://github.com/vuetifyjs/vuetify/issues/23393).
|
|
148
|
+
material-web's install script (`scripts/patch-vuetify-loaders.mjs`, its
|
|
149
|
+
`postinstall`) passes `{ immediate: false }` to those three calls in the
|
|
150
|
+
installed Vuetify: its `lib/` modules and the builds `vuetify/dist/vuetify.js`
|
|
151
|
+
and `vuetify/dist/vuetify-labs.js` resolve to (`.esm.js`, `.cjs` and the UMD
|
|
152
|
+
build at that path). The intersection observer still reports what is in
|
|
153
|
+
view, so a loading field's bar still shows and a bar scrolled into view still
|
|
154
|
+
animates; no form needs a workaround of its own. `dist/vuetify.min.js` stays
|
|
155
|
+
as published: no export names it (it is the CDN script build), and its
|
|
156
|
+
minified names would need a looser match. So do Vuetify's other callers
|
|
157
|
+
(`VOtpInput`, `VAlert`'s auto-dismiss, `VInfiniteScroll`, `VParallax`). The
|
|
158
|
+
script patches a Vuetify copy only where it finds exactly the calls it
|
|
159
|
+
expects, all of them or none, and otherwise prints one line naming the issue
|
|
160
|
+
and changes nothing; a second run changes nothing, and it never fails an
|
|
161
|
+
install. It patches the Vuetify the installing project resolves and the
|
|
162
|
+
copies nested under that project's other packages.
|
|
163
|
+
|
|
164
|
+
The app's root `package.json` approves the script, as `jskit update` writes
|
|
165
|
+
it: `"allowScripts": { "@jskit-ai/material-web": true }`. Without it npm 11
|
|
166
|
+
runs it with a warning, and a strict install (`strict-allow-scripts`, as
|
|
167
|
+
JSKIT's CI runs) fails. An install with `--ignore-scripts` leaves Vuetify as
|
|
168
|
+
published; `npm rebuild @jskit-ai/material-web` patches it afterwards. The
|
|
169
|
+
browser test "300 fields mount with no layout read from their idle loaders
|
|
170
|
+
once patched; Vuetify as published reads one per field" fails once a Vuetify
|
|
171
|
+
release fixes the issue; then pin it and delete the script, its tests, the
|
|
172
|
+
`postinstall` and `jskit update`'s approval.
|
|
133
173
|
|
|
134
174
|
## Maintaining the icon set
|
|
135
175
|
|
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.7",
|
|
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": {
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
|
-
"
|
|
37
|
+
"postinstall": "node ./scripts/patch-vuetify-loaders.mjs",
|
|
38
|
+
"test": "jskit test test/*.test.js",
|
|
38
39
|
"symbols:generate": "node ./scripts/generate-symbols.mjs"
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// material-web's postinstall: stops Vuetify's idle loaders reading layout as they mount.
|
|
3
|
+
// https://github.com/vuetifyjs/vuetify/issues/23393 (open). Remove once a fixed Vuetify is pinned.
|
|
4
|
+
//
|
|
5
|
+
// Since Vuetify 4.3.0 every field (VTextField, VTextarea, VSelect, VAutocomplete, VCombobox, VNumberInput, VFileInput)
|
|
6
|
+
// renders an idle VProgressLinear, which, like VProgressCircular and the labs VLoadingIndicator, calls @vuetify/v0's
|
|
7
|
+
// useElementIntersection(root). Its default `immediate: true` calls root.getBoundingClientRect() on mount for a first
|
|
8
|
+
// entry that hard-codes isIntersecting: false, so the read tells it nothing; the IntersectionObserver sends its own
|
|
9
|
+
// first entry anyway. When anything writes to the page between two fields mounting, each read forces a layout: 300
|
|
10
|
+
// fields took about 15 s to mount instead of 0.4 s. This script passes `{ immediate: false }` to those three calls and
|
|
11
|
+
// to no other, in the copies of Vuetify the project installed:
|
|
12
|
+
// - lib/, which `vuetify`, `vuetify/components`, `vuetify/labs/*` and the auto-imports resolve to;
|
|
13
|
+
// - the dist/ bundles that `vuetify/dist/vuetify.js` and `vuetify/dist/vuetify-labs.js` resolve to (.esm.js on import,
|
|
14
|
+
// .cjs on require), and the UMD builds at those paths, which a tool that ignores `exports` loads for them.
|
|
15
|
+
// dist/vuetify.min.js stays as published: no export names it (only the `./*` catch-all, which reaches every file), it is
|
|
16
|
+
// the CDN script build, and its minified names would need a second, looser matcher.
|
|
17
|
+
// It changes a file only where it finds exactly the calls it expects, and nothing at all in a Vuetify where any is
|
|
18
|
+
// missing or different (fixed upstream, or rewritten). It never fails an install: every outcome is one line, exit 0.
|
|
19
|
+
import { realpathSync } from "node:fs";
|
|
20
|
+
import { chmod, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
21
|
+
import path from "node:path";
|
|
22
|
+
import process from "node:process";
|
|
23
|
+
import { fileURLToPath } from "node:url";
|
|
24
|
+
|
|
25
|
+
const ISSUE = "vuetifyjs/vuetify#23393";
|
|
26
|
+
// What the patch adds inside each call. The comment marks a call as patched here, so a second run changes nothing and
|
|
27
|
+
// a Vuetify that passes the option itself reads as changed, not as patched.
|
|
28
|
+
const PATCH = ", { immediate: false } /* @jskit-ai/material-web: vuetifyjs/vuetify#23393 */";
|
|
29
|
+
const LOADERS = Object.freeze(["VProgressLinear", "VProgressCircular", "VLoadingIndicator"]);
|
|
30
|
+
const CORE_LOADERS = LOADERS.slice(0, 2);
|
|
31
|
+
// Each file the patch changes, relative to the Vuetify package, with the loaders it defines.
|
|
32
|
+
const TARGETS = Object.freeze({
|
|
33
|
+
"lib/components/VProgressLinear/VProgressLinear.js": ["VProgressLinear"],
|
|
34
|
+
"lib/components/VProgressCircular/VProgressCircular.js": ["VProgressCircular"],
|
|
35
|
+
"lib/labs/VLoadingIndicator/VLoadingIndicator.js": ["VLoadingIndicator"],
|
|
36
|
+
"dist/vuetify.esm.js": CORE_LOADERS,
|
|
37
|
+
"dist/vuetify.cjs": CORE_LOADERS,
|
|
38
|
+
"dist/vuetify.js": CORE_LOADERS,
|
|
39
|
+
"dist/vuetify-labs.esm.js": LOADERS,
|
|
40
|
+
"dist/vuetify-labs.cjs": LOADERS,
|
|
41
|
+
"dist/vuetify-labs.js": LOADERS
|
|
42
|
+
});
|
|
43
|
+
const CALL = "useElementIntersection(";
|
|
44
|
+
const CALL_HEAD = /^useElementIntersection\([A-Za-z_$][\w$]*/u;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Where component `name` calls useElementIntersection in `source`: its definition runs from its one `name: '<name>'`
|
|
48
|
+
* line to the next line at its `const <name> = ...` indentation that is not a closing bracket (the next statement).
|
|
49
|
+
* It must hold exactly one call, on one variable, as published (`patched: false`) or as patched here (`patched: true`).
|
|
50
|
+
* @param {string} source
|
|
51
|
+
* @param {string} name
|
|
52
|
+
* @returns {{ end?: number, patched: boolean } | string} the published call's closing parenthesis, or what differs
|
|
53
|
+
*/
|
|
54
|
+
function findLoaderCall(source, name) {
|
|
55
|
+
const definitions = [...source.matchAll(new RegExp(`^([ \\t]*)name: ['"]${name}['"],$`, "gmu"))];
|
|
56
|
+
if (definitions.length !== 1) return `${definitions.length} definitions of ${name}`;
|
|
57
|
+
const [{ index: start, 1: indent }] = definitions;
|
|
58
|
+
const nextStatement = new RegExp(`^${indent.replace(/ {2}$/u, "")}[^\\s})\\]]`, "gmu");
|
|
59
|
+
nextStatement.lastIndex = start + indent.length;
|
|
60
|
+
const definition = source.slice(start, nextStatement.exec(source)?.index ?? source.length);
|
|
61
|
+
const at = definition.indexOf(CALL);
|
|
62
|
+
if (at < 0 || definition.indexOf(CALL, at + 1) >= 0) return `${name} does not call useElementIntersection exactly once`;
|
|
63
|
+
const call = definition.slice(at);
|
|
64
|
+
const head = CALL_HEAD.exec(call)?.[0] ?? "";
|
|
65
|
+
if (head && call.startsWith(")", head.length)) return { end: start + at + head.length, patched: false };
|
|
66
|
+
if (head && call.startsWith(`${PATCH})`, head.length)) return { patched: true };
|
|
67
|
+
return `${name} calls useElementIntersection with other arguments`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The patched text of one Vuetify file that defines `loaders`.
|
|
72
|
+
* @param {string} source
|
|
73
|
+
* @param {ReadonlyArray<string>} loaders
|
|
74
|
+
* @returns {{ source: string, patched: number } | { changed: string }} `patched` counts the calls patched now
|
|
75
|
+
*/
|
|
76
|
+
function patchSource(source, loaders) {
|
|
77
|
+
const calls = [];
|
|
78
|
+
for (const name of loaders) {
|
|
79
|
+
const call = findLoaderCall(source, name);
|
|
80
|
+
if (typeof call === "string") return { changed: call };
|
|
81
|
+
calls.push(call);
|
|
82
|
+
}
|
|
83
|
+
const pending = calls.filter((call) => !call.patched).sort((left, right) => right.end - left.end);
|
|
84
|
+
let text = source;
|
|
85
|
+
for (const { end } of pending) text = `${text.slice(0, end)}${PATCH}${text.slice(end)}`;
|
|
86
|
+
return { source: text, patched: pending.length };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Writes beside the file and renames it into place: an interrupted install leaves the old file, and a file
|
|
90
|
+
// hard-linked from a package store is replaced in this project only.
|
|
91
|
+
async function replaceFile(file, text) {
|
|
92
|
+
const { mode } = await stat(file);
|
|
93
|
+
const temporary = `${file}.jskit-${process.pid}.tmp`;
|
|
94
|
+
try {
|
|
95
|
+
await writeFile(temporary, text, "utf8");
|
|
96
|
+
await chmod(temporary, mode);
|
|
97
|
+
await rename(temporary, file);
|
|
98
|
+
} finally {
|
|
99
|
+
await rm(temporary, { force: true });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Patches the Vuetify package in `directory`, or changes nothing in it when any target file differs from what the
|
|
105
|
+
* patch expects.
|
|
106
|
+
* @param {string} directory
|
|
107
|
+
* @returns {Promise<{ version: string, patched: string[] } | { version: string, changed: string }>}
|
|
108
|
+
*/
|
|
109
|
+
async function patchVuetify(directory) {
|
|
110
|
+
const { version } = JSON.parse(await readFile(path.join(directory, "package.json"), "utf8"));
|
|
111
|
+
const files = [];
|
|
112
|
+
for (const [file, loaders] of Object.entries(TARGETS)) {
|
|
113
|
+
const source = await readFile(path.join(directory, file), "utf8").catch((error) => {
|
|
114
|
+
if (error.code === "ENOENT") return null;
|
|
115
|
+
throw error;
|
|
116
|
+
});
|
|
117
|
+
const result = source === null ? { changed: "missing" } : patchSource(source, loaders);
|
|
118
|
+
if (result.changed) return { version, changed: `${file}: ${result.changed}` };
|
|
119
|
+
if (result.patched > 0) files.push({ file, source: result.source });
|
|
120
|
+
}
|
|
121
|
+
for (const { file, source } of files) await replaceFile(path.join(directory, file), source);
|
|
122
|
+
return { version, patched: files.map(({ file }) => file) };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function isFile(file) {
|
|
126
|
+
return stat(file).then((stats) => stats.isFile(), () => false);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function nearestVuetify(start) {
|
|
130
|
+
for (let directory = path.resolve(start); ; directory = path.dirname(directory)) {
|
|
131
|
+
const candidate = path.join(directory, "node_modules", "vuetify");
|
|
132
|
+
if (await isFile(path.join(candidate, "package.json"))) return candidate;
|
|
133
|
+
if (path.dirname(directory) === directory) return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// The copies nested in the packages under `nodeModules` (<package>/node_modules/vuetify, at any depth), which those
|
|
138
|
+
// packages import instead of the app's. Linked packages (workspaces) are not followed.
|
|
139
|
+
async function nestedVuetify(nodeModules) {
|
|
140
|
+
const copies = [];
|
|
141
|
+
const entries = (directory) => readdir(directory, { withFileTypes: true }).then(
|
|
142
|
+
(found) => found.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")),
|
|
143
|
+
() => []
|
|
144
|
+
);
|
|
145
|
+
for (const entry of await entries(nodeModules)) {
|
|
146
|
+
const packages = entry.name.startsWith("@")
|
|
147
|
+
? (await entries(path.join(nodeModules, entry.name))).map((scoped) => path.join(entry.name, scoped.name))
|
|
148
|
+
: [entry.name];
|
|
149
|
+
for (const name of packages) {
|
|
150
|
+
const inner = path.join(nodeModules, name, "node_modules");
|
|
151
|
+
if (await isFile(path.join(inner, "vuetify", "package.json"))) copies.push(path.join(inner, "vuetify"));
|
|
152
|
+
copies.push(...await nestedVuetify(inner));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return copies;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The Vuetify copies the project uses: the one each start directory resolves `vuetify` to, and the copies nested under
|
|
160
|
+
* that one's node_modules, each once.
|
|
161
|
+
* @param {ReadonlyArray<string>} starts
|
|
162
|
+
* @returns {Promise<string[]>}
|
|
163
|
+
*/
|
|
164
|
+
async function findVuetifyCopies(starts) {
|
|
165
|
+
const copies = new Map();
|
|
166
|
+
for (const start of starts) {
|
|
167
|
+
const found = await nearestVuetify(start);
|
|
168
|
+
if (!found) continue;
|
|
169
|
+
for (const copy of [found, ...await nestedVuetify(path.dirname(found))]) {
|
|
170
|
+
const real = await realpath(copy);
|
|
171
|
+
if (!copies.has(real)) copies.set(real, copy);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return [...copies.values()];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Patches the Vuetify of the project being installed (INIT_CWD, and npm's project root) and reports one line per copy.
|
|
179
|
+
* Never throws: an error is reported in one line too.
|
|
180
|
+
* @param {{ env?: Record<string, string | undefined>, cwd?: string, log?: (line: string) => void }} [options]
|
|
181
|
+
*/
|
|
182
|
+
async function main({ env = process.env, cwd = process.cwd(), log = console.log } = {}) {
|
|
183
|
+
const prefix = "@jskit-ai/material-web:";
|
|
184
|
+
const failed = (error) => {
|
|
185
|
+
log(`${prefix} could not patch Vuetify's idle loaders for ${ISSUE}: ${String(error?.message || error).split("\n")[0]}`);
|
|
186
|
+
};
|
|
187
|
+
try {
|
|
188
|
+
const project = env.INIT_CWD || cwd;
|
|
189
|
+
for (const directory of await findVuetifyCopies([project, env.npm_config_local_prefix].filter(Boolean))) {
|
|
190
|
+
const where = path.relative(project, directory) || directory;
|
|
191
|
+
const result = await patchVuetify(directory).catch((error) => ({ error }));
|
|
192
|
+
const vuetify = `Vuetify ${result.version} (${where})`;
|
|
193
|
+
if (result.error) failed(result.error);
|
|
194
|
+
else if (result.changed) log(`${prefix} ${vuetify} does not have the idle-loader code patched for ${ISSUE} (${result.changed}); left it unchanged.`);
|
|
195
|
+
else if (result.patched.length > 0) log(`${prefix} patched the idle loaders of ${vuetify} in ${result.patched.length} files for ${ISSUE}.`);
|
|
196
|
+
else log(`${prefix} the idle loaders of ${vuetify} are already patched for ${ISSUE}.`);
|
|
197
|
+
}
|
|
198
|
+
} catch (error) {
|
|
199
|
+
failed(error);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function isEntrypoint() {
|
|
204
|
+
try {
|
|
205
|
+
return Boolean(process.argv[1]) && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
206
|
+
} catch {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (isEntrypoint()) {
|
|
212
|
+
await main();
|
|
213
|
+
process.exitCode = 0;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export { ISSUE, LOADERS, PATCH, TARGETS, findVuetifyCopies, main, patchSource, patchVuetify };
|
package/src/client/defaults.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// JSKIT's Material 3 component defaults, on top of Vuetify's md3 blueprint: full-shape filled buttons, cards that rest
|
|
2
2
|
// flat on surface-container-low, flat expansion panels, outlined fields, 8dp chips that close with $close, segmented buttons and
|
|
3
|
-
// filter chips that select in secondary-container, the inverse-surface snackbar, the Material switch,
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// filter chips that select in secondary-container, the inverse-surface snackbar, the Material switch, Material 3's
|
|
4
|
+
// slider (Vuetify's pill variant) with a secondary-container inactive track, and the 16dp primary-container FAB. A
|
|
5
|
+
// number for `rounded` is an exact corner in dp. Card, dialog and bottom sheet corners and colours, a menu's own list,
|
|
6
|
+
// and the sizes and states props cannot set, are in material.css. No VMenu sub-component
|
|
6
7
|
// defaults: under them, in Vuetify 4.2.1 to 4.3.2, an ancestor's re-render makes the menu's virtual list lose its item
|
|
7
8
|
// heights, so a v-select's typeahead never scrolls to its match (https://github.com/vuetifyjs/vuetify/issues/23366;
|
|
8
9
|
// README, Upstream workarounds).
|
|
@@ -74,6 +75,21 @@ const materialDefaults = Object.freeze({
|
|
|
74
75
|
variant: "text"
|
|
75
76
|
}
|
|
76
77
|
},
|
|
78
|
+
// Material 3 sliders: Vuetify's pill variant, Material 3's slider at its default (extra-small) size, with a 16dp track,
|
|
79
|
+
// a 4x44dp handle bar set apart from the track by a gap, and a stop indicator at the end of the track. The active
|
|
80
|
+
// track and the handle follow `color`, so an app's color prop still sets them, and the inactive track is
|
|
81
|
+
// secondary-container, which material.css draws at full strength: on Vuetify's 4dp track that pale role all but
|
|
82
|
+
// vanished on a light container. The md3 blueprint gives a range slider no colour at all.
|
|
83
|
+
VSlider: {
|
|
84
|
+
color: "primary",
|
|
85
|
+
trackColor: "secondary-container",
|
|
86
|
+
variant: "pill"
|
|
87
|
+
},
|
|
88
|
+
VRangeSlider: {
|
|
89
|
+
color: "primary",
|
|
90
|
+
trackColor: "secondary-container",
|
|
91
|
+
variant: "pill"
|
|
92
|
+
},
|
|
77
93
|
VSwitch: {
|
|
78
94
|
color: "primary",
|
|
79
95
|
inset: "material"
|
package/src/client/material.css
CHANGED
|
@@ -77,6 +77,30 @@
|
|
|
77
77
|
padding-inline: 0 16px;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/* Sliders and range sliders: the inactive track (secondary-container, the track-color default) at full strength, as
|
|
81
|
+
Material 3 draws it. Vuetify fades it to 38% (24% for the pill variant) whenever the slider has a colour, which the
|
|
82
|
+
md3 blueprint always gives it, so an app's own track-color was faded too: a secondary-container track all but
|
|
83
|
+
vanished on a light surface. An invalid slider keeps Vuetify's faded track in the error colour, which tells its
|
|
84
|
+
two parts apart. */
|
|
85
|
+
.v-slider:not(.v-input--disabled, .v-input--error) .v-slider-track__background--opacity {
|
|
86
|
+
opacity: 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* A disabled slider is Material 3's on-surface: 38% for the active track and the handle (Vuetify's fade of the whole
|
|
90
|
+
slider, --v-disabled-opacity, which keeps the handle opaque over the track) and 12% for the inactive track, where
|
|
91
|
+
Vuetify faded surface-variant parts to 38% and the inactive track again, to 14%. */
|
|
92
|
+
.v-slider.v-input--disabled :is(.v-slider-track__background, .v-slider-track__fill) {
|
|
93
|
+
background-color: rgb(var(--v-theme-on-surface));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.v-slider.v-input--disabled .v-slider-track__background {
|
|
97
|
+
opacity: calc(0.12 / var(--v-disabled-opacity));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.v-slider.v-input--disabled .v-slider-thumb {
|
|
101
|
+
color: rgb(var(--v-theme-on-surface));
|
|
102
|
+
}
|
|
103
|
+
|
|
80
104
|
/* FABs are not common buttons: 56dp (small 40dp, large 96dp with a 36dp icon), and the extended FAB is 56dp tall. */
|
|
81
105
|
.v-fab .v-btn {
|
|
82
106
|
--jskit-fab-size: 56px;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { defineComponent, h, nextTick, ref, shallowRef, watch } from "vue";
|
|
3
|
+
|
|
4
|
+
// `?view=fields` mounts fields on request and counts the layout reads their idle loaders make
|
|
5
|
+
// (vuetifyjs/vuetify#23393); `?view=loaders` shows a loading field, a circular progress and, below the fold, an
|
|
6
|
+
// indeterminate bar.
|
|
7
|
+
const view = new URLSearchParams(window.location.search).get("view");
|
|
8
|
+
const shownCount = ref(0);
|
|
9
|
+
const list = ref();
|
|
10
|
+
|
|
11
|
+
// getBoundingClientRect() calls while fields mount: on a progress bar (the loaders') or on anything else.
|
|
12
|
+
const reads = { on: false, progress: 0, other: 0 };
|
|
13
|
+
const getBoundingClientRect = Element.prototype.getBoundingClientRect;
|
|
14
|
+
Element.prototype.getBoundingClientRect = function countedGetBoundingClientRect() {
|
|
15
|
+
if (reads.on) {
|
|
16
|
+
if (this.classList?.contains("v-progress-linear")) reads.progress += 1;
|
|
17
|
+
else reads.other += 1;
|
|
18
|
+
}
|
|
19
|
+
return getBoundingClientRect.call(this);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// A row part that writes a style on the list when its element appears, as row code often does: after each write, the
|
|
23
|
+
// next field's read lays the page out again.
|
|
24
|
+
const RowStamp = defineComponent({
|
|
25
|
+
props: { index: { type: Number, required: true } },
|
|
26
|
+
setup(props) {
|
|
27
|
+
const element = shallowRef();
|
|
28
|
+
watch(element, (node) => {
|
|
29
|
+
if (node) list.value.style.setProperty("--rows-mounted", String(props.index));
|
|
30
|
+
});
|
|
31
|
+
return () => h("span", { ref: element, class: "stamp" });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
window.mountFields = async (count) => {
|
|
36
|
+
Object.assign(reads, { on: true, progress: 0, other: 0 });
|
|
37
|
+
const started = performance.now();
|
|
38
|
+
shownCount.value = count;
|
|
39
|
+
await nextTick();
|
|
40
|
+
const milliseconds = performance.now() - started;
|
|
41
|
+
reads.on = false;
|
|
42
|
+
return { progressReads: reads.progress, otherReads: reads.other, milliseconds };
|
|
43
|
+
};
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
<template>
|
|
47
|
+
<v-app>
|
|
48
|
+
<div v-if="view === 'fields'" ref="list">
|
|
49
|
+
<div v-for="row in shownCount" :key="row" class="field-row">
|
|
50
|
+
<v-text-field :label="`Field ${row}`" density="compact" hide-details />
|
|
51
|
+
<RowStamp :index="row" />
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
<div v-else>
|
|
55
|
+
<div data-testid="loading-field">
|
|
56
|
+
<v-text-field label="Loading" loading />
|
|
57
|
+
</div>
|
|
58
|
+
<div data-testid="circular">
|
|
59
|
+
<v-progress-circular indeterminate />
|
|
60
|
+
</div>
|
|
61
|
+
<div class="below-fold" data-testid="below-fold">
|
|
62
|
+
<v-progress-linear indeterminate />
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
</v-app>
|
|
66
|
+
</template>
|
|
67
|
+
|
|
68
|
+
<style>
|
|
69
|
+
.field-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
|
|
70
|
+
.stamp { min-width: 64px; }
|
|
71
|
+
.below-fold { margin-top: 200vh; }
|
|
72
|
+
</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createApp } from "vue";
|
|
2
|
+
import { createVuetify } from "vuetify";
|
|
3
|
+
import { VApp } from "vuetify/components/VApp";
|
|
4
|
+
import { VProgressCircular } from "vuetify/components/VProgressCircular";
|
|
5
|
+
import { VProgressLinear } from "vuetify/components/VProgressLinear";
|
|
6
|
+
import { VTextField } from "vuetify/components/VTextField";
|
|
7
|
+
import "vuetify/styles";
|
|
8
|
+
import App from "./App.vue";
|
|
9
|
+
|
|
10
|
+
createApp(App).use(createVuetify({ components: { VApp, VProgressCircular, VProgressLinear, VTextField } })).mount("#app");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createApp, h } from "vue";
|
|
2
|
+
import { createVuetify } from "vuetify";
|
|
3
|
+
import { VApp } from "vuetify/components/VApp";
|
|
4
|
+
import { VMain } from "vuetify/components/VMain";
|
|
5
|
+
import { VRangeSlider } from "vuetify/components/VRangeSlider";
|
|
6
|
+
import { VSlider } from "vuetify/components/VSlider";
|
|
7
|
+
import "vuetify/styles";
|
|
8
|
+
import "../../../src/client/material.css";
|
|
9
|
+
import { createMaterialVuetifyOptions } from "../../../src/client/index.js";
|
|
10
|
+
|
|
11
|
+
// A slider, a range slider and a disabled slider with JSKIT's Material 3 options and stylesheet, as an app draws them,
|
|
12
|
+
// in the browser's light or dark scheme (sliders.browser.test.js).
|
|
13
|
+
const sliders = [
|
|
14
|
+
{ testId: "slider", component: VSlider, props: { label: "Slider", modelValue: 40 } },
|
|
15
|
+
{ testId: "range-slider", component: VRangeSlider, props: { label: "Range", modelValue: [20, 70] } },
|
|
16
|
+
{ testId: "disabled-slider", component: VSlider, props: { label: "Disabled", modelValue: 40, disabled: true } }
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const App = () => h(VApp, () => h(VMain, { class: "pa-6" }, () => sliders.map(({ testId, component, props }) => (
|
|
20
|
+
h("div", { "data-testid": testId }, h(component, props))
|
|
21
|
+
))));
|
|
22
|
+
|
|
23
|
+
createApp(App).use(createVuetify(createMaterialVuetifyOptions())).mount("#app");
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-now Vuetify, LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|