@jskit-ai/uploads-image-web 0.2.10 → 0.2.12

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,10 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ - The image dialog (Uppy's dashboard and image editor) takes the app's Material 3 roles and typeface, in light and dark: its panel is `surface-container-high` with 28dp corners and no outline, text `on-surface`, "browse files" a `primary` link underlined only under the pointer, filled buttons primary and full-shape, all in the theme's `--v-font-body`, instead of Uppy's light grey panel, blue underlined link and system font in both schemes. `@jskit-ai/uploads-image-web/client/styles` loads it after Uppy's stylesheets.
6
+ - The image dialog is modal over the whole app: its `scrim` covers the top app bar, navigation and Vuetify's own overlays (Uppy's z-index 1001 sat under the app bar), and its close button sits inside the dialog in a 56dp header row, an `on-surface-variant` 48dp icon button, instead of above the container (hidden under the app bar at 390 and 768) or beside it (at 1280). At compact width (below 600dp) it is a full-screen dialog with the close button at the leading edge; at medium width it keeps 24dp from every edge. Its hint text is `on-surface-variant` (Uppy's #757575 on its grey panel was 4.2:1).
7
+
3
8
  ## 0.2.0 - 2026-10-29
4
9
 
5
10
  - Translation ready: every user-visible text is a message key with its English in `locales/en.json`, so an app translates it by supplying translation files only. With no translations, texts and behaviour are unchanged. See the guide "Translating a JSKIT app".
@@ -70,8 +70,8 @@ const AvatarPage = {
70
70
  }
71
71
  };
72
72
 
73
- // The upload runtime as whs2 calls it: an endpoint and the four callbacks every application supplies, leaving
74
- // onSelectedFileNameChanged, onInvalidResponse and onUnavailable to their defaults.
73
+ // The upload runtime as an application calls it: an endpoint and the four callbacks every application supplies,
74
+ // leaving onSelectedFileNameChanged, onInvalidResponse and onUnavailable to their defaults.
75
75
  const SignaturePage = {
76
76
  setup() {
77
77
  const events = reactive([]);
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@jskit-ai/uploads-image-web",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "type": "module",
5
5
  "scripts": {
6
- "test": "node --test --test-concurrency=1"
6
+ "test": "jskit test"
7
7
  },
8
8
  "exports": {
9
9
  "./client": "./src/client/index.js",
@@ -15,7 +15,7 @@
15
15
  "./locales/en.json": "./locales/en.json"
16
16
  },
17
17
  "dependencies": {
18
- "@jskit-ai/uploads-runtime": "0.2.10",
18
+ "@jskit-ai/uploads-runtime": "0.2.12",
19
19
  "@uppy/compressor": "^3.1.0",
20
20
  "@uppy/core": "^5.2.0",
21
21
  "@uppy/dashboard": "^5.1.1",
@@ -23,7 +23,7 @@
23
23
  "@uppy/xhr-upload": "^5.1.1"
24
24
  },
25
25
  "peerDependencies": {
26
- "@jskit-ai/kernel": "0.2.10",
26
+ "@jskit-ai/kernel": "0.2.12",
27
27
  "vue": "^3.5.13"
28
28
  },
29
29
  "description": "Reusable client-side image upload runtime with pre-upload image editing.",
@@ -1,5 +1,7 @@
1
1
  import "@uppy/core/css/style.min.css";
2
2
  import "@uppy/dashboard/css/style.min.css";
3
3
  import "@uppy/image-editor/css/style.min.css";
4
+ // After Uppy's own: the dialog in the app's Material 3 roles and typeface, in both schemes.
5
+ import "./material.css";
4
6
 
5
7
  export {};
@@ -0,0 +1,155 @@
1
+ /*
2
+ * Uppy's dashboard and image editor in Material 3 roles. They read the app's Vuetify theme (its --v-theme-* roles and
3
+ * --v-font-body typeface, which Vuetify sets for the current theme on :root, where Uppy's modal lives), so the dialog
4
+ * follows the light and dark schemes: Uppy's grey panel, blue link and system font give way. Loaded after Uppy's
5
+ * stylesheets; the .uppy-Root prefix outranks Uppy's [data-uppy-theme] rules.
6
+ */
7
+ .uppy-Root {
8
+ color: rgb(var(--v-theme-on-surface));
9
+ font-family: var(--v-font-body);
10
+ }
11
+
12
+ .uppy-Root .uppy-Dashboard-inner,
13
+ .uppy-Root .uppy-DashboardContent-panel,
14
+ .uppy-Root .uppy-Dashboard-FileCard,
15
+ .uppy-Root .uppy-StatusBar {
16
+ background-color: rgb(var(--v-theme-surface-container-high));
17
+ color: rgb(var(--v-theme-on-surface));
18
+ }
19
+
20
+ /* The dialog: Material 3's 28dp corners, without an outline over its surface. */
21
+ .uppy-Root .uppy-Dashboard-inner {
22
+ border: 0;
23
+ border-radius: 28px;
24
+ }
25
+
26
+ /*
27
+ * A modal dialog sits above the whole app: its scrim covers the top app bar, navigation and Vuetify's own overlays
28
+ * (from z-index 2000), which Uppy's 1001 sits under. The close button lives inside the dialog, in a 56dp header row
29
+ * above Uppy's content, instead of above or beside the container.
30
+ */
31
+ .uppy-Root .uppy-Dashboard--modal .uppy-Dashboard-overlay {
32
+ z-index: 2400;
33
+ background-color: rgba(var(--v-theme-scrim, 0, 0, 0), 0.32);
34
+ }
35
+
36
+ .uppy-Root .uppy-Dashboard--modal .uppy-Dashboard-inner {
37
+ z-index: 2401;
38
+ padding-top: 56px;
39
+ }
40
+
41
+ .uppy-Root .uppy-Dashboard--modal .uppy-Dashboard-close {
42
+ top: 4px;
43
+ display: flex;
44
+ align-items: center;
45
+ justify-content: center;
46
+ width: 48px;
47
+ height: 48px;
48
+ border-radius: 9999px;
49
+ color: rgb(var(--v-theme-on-surface-variant));
50
+ font-size: 28px;
51
+ line-height: 1;
52
+ inset-inline-end: 4px;
53
+ }
54
+
55
+ .uppy-Root .uppy-Dashboard--modal .uppy-Dashboard-close:hover {
56
+ background-color: rgba(var(--v-theme-on-surface-variant), 0.08);
57
+ }
58
+
59
+ .uppy-Root .uppy-Dashboard--modal .uppy-Dashboard-close:focus-visible {
60
+ outline: 2px solid rgb(var(--v-theme-primary));
61
+ outline-offset: -2px;
62
+ }
63
+
64
+ /* Compact width: a full-screen dialog, its close button at the leading edge. */
65
+ @media (max-width: 599.98px) {
66
+ .uppy-Root .uppy-Dashboard--modal .uppy-Dashboard-inner {
67
+ top: 0;
68
+ right: 0;
69
+ bottom: 0;
70
+ left: 0;
71
+ border-radius: 0;
72
+ }
73
+
74
+ .uppy-Root .uppy-Dashboard--modal .uppy-Dashboard-close {
75
+ inset-inline-start: 4px;
76
+ inset-inline-end: auto;
77
+ }
78
+ }
79
+
80
+ /* Medium width, below Uppy's own centred layout from 820px: the dialog keeps a 24dp margin on every side. */
81
+ @media (min-width: 600px) and (max-width: 819.98px) {
82
+ .uppy-Root .uppy-Dashboard--modal .uppy-Dashboard-inner {
83
+ top: 24px;
84
+ right: 24px;
85
+ bottom: 24px;
86
+ left: 24px;
87
+ }
88
+ }
89
+
90
+ .uppy-Root .uppy-DashboardContent-bar {
91
+ background-color: transparent;
92
+ border-bottom: 1px solid rgb(var(--v-theme-outline-variant));
93
+ }
94
+
95
+ .uppy-Root .uppy-DashboardContent-title,
96
+ .uppy-Root .uppy-Dashboard-AddFiles-title,
97
+ .uppy-Root .uppy-Dashboard-Item-name {
98
+ color: rgb(var(--v-theme-on-surface));
99
+ }
100
+
101
+ .uppy-Root .uppy-Dashboard-AddFiles {
102
+ border-color: rgb(var(--v-theme-outline-variant));
103
+ border-radius: 12px;
104
+ }
105
+
106
+ .uppy-Root .uppy-Dashboard-note,
107
+ .uppy-Root .uppy-Dashboard-Item-status,
108
+ .uppy-Root .uppy-StatusBar-statusSecondary {
109
+ color: rgb(var(--v-theme-on-surface-variant));
110
+ }
111
+
112
+ /* "browse files" is a link in the primary role, underlined only under the pointer. */
113
+ .uppy-Root .uppy-Dashboard-browse,
114
+ .uppy-Root .uppy-DashboardContent-back,
115
+ .uppy-Root .uppy-DashboardContent-addMore,
116
+ .uppy-Root .uppy-DashboardContent-save,
117
+ .uppy-Root .uppy-c-btn-link {
118
+ color: rgb(var(--v-theme-primary));
119
+ font-weight: 500;
120
+ }
121
+
122
+ .uppy-Root .uppy-Dashboard-browse:hover,
123
+ .uppy-Root .uppy-Dashboard-browse:focus {
124
+ border-bottom: 0;
125
+ }
126
+
127
+ .uppy-Root .uppy-Dashboard-browse:hover {
128
+ text-decoration: underline;
129
+ }
130
+
131
+ .uppy-Root .uppy-Dashboard-browse:focus-visible {
132
+ border-radius: 4px;
133
+ outline: 2px solid rgb(var(--v-theme-primary));
134
+ outline-offset: 2px;
135
+ }
136
+
137
+ /* Filled buttons (Upload, Save) are Material 3's: primary, full shape, the app's typeface. */
138
+ .uppy-Root .uppy-c-btn-primary,
139
+ .uppy-Root .uppy-StatusBar-actionBtn--upload,
140
+ .uppy-Root .uppy-StatusBar:not(.is-waiting) .uppy-StatusBar-actionBtn--upload {
141
+ background-color: rgb(var(--v-theme-primary));
142
+ border-radius: 9999px;
143
+ color: rgb(var(--v-theme-on-primary));
144
+ font-family: inherit;
145
+ }
146
+
147
+ .uppy-Root .uppy-c-btn-primary:not(:disabled):hover,
148
+ .uppy-Root .uppy-StatusBar:not(.is-waiting) .uppy-StatusBar-actionBtn--upload:hover {
149
+ background-color: rgb(var(--v-theme-primary));
150
+ background-image: linear-gradient(rgba(var(--v-theme-on-primary), 0.08), rgba(var(--v-theme-on-primary), 0.08));
151
+ }
152
+
153
+ .uppy-Root .uppy-StatusBar-progress {
154
+ background-color: rgb(var(--v-theme-primary));
155
+ }
@@ -127,6 +127,146 @@ function chooseFile(dashboard, file) {
127
127
  return dashboard.locator(".uppy-Dashboard-input[type=\"file\"]").first().setInputFiles(file);
128
128
  }
129
129
 
130
+ // The roles and typeface Vuetify's theme sets on :root, for each scheme; the fixture has no Vuetify of its own.
131
+ const SCHEMES = Object.freeze({
132
+ light: {
133
+ surface: "236, 230, 240",
134
+ onSurface: "29, 27, 32",
135
+ onSurfaceVariant: "73, 69, 79",
136
+ outlineVariant: "202, 196, 208",
137
+ primary: "103, 80, 164",
138
+ font: "\"Fixture Sans\", sans-serif"
139
+ },
140
+ dark: {
141
+ surface: "43, 41, 48",
142
+ onSurface: "230, 225, 229",
143
+ onSurfaceVariant: "202, 196, 208",
144
+ outlineVariant: "73, 69, 79",
145
+ primary: "208, 188, 255",
146
+ font: "\"Fixture Sans\", sans-serif"
147
+ }
148
+ });
149
+
150
+ function schemeCss({ surface, onSurface, onSurfaceVariant, outlineVariant, primary, font }) {
151
+ return `:root { --v-theme-surface-container-high: ${surface}; --v-theme-on-surface: ${onSurface}; ` +
152
+ `--v-theme-primary: ${primary}; --v-theme-on-primary: 255, 255, 255; --v-theme-outline-variant: ${outlineVariant}; ` +
153
+ `--v-theme-on-surface-variant: ${onSurfaceVariant}; --v-theme-scrim: 0, 0, 0; --v-font-body: ${font}; }`;
154
+ }
155
+
156
+ // Waits for the dialog's open animation and colour transitions to finish.
157
+ function settle(page) {
158
+ // Only animations that end: an endless one (a spinner) would never settle.
159
+ return page.evaluate(() => Promise.all(document.getAnimations()
160
+ .filter((animation) => Number.isFinite(animation.effect?.getComputedTiming().endTime ?? Infinity))
161
+ .map((animation) => animation.finished.catch(() => null))));
162
+ }
163
+
164
+ function contrastRatio(foreground, background) {
165
+ const luminance = (rgb) => {
166
+ const [r, g, b] = rgb.match(/\d+(\.\d+)?/gu).slice(0, 3).map((channel) => {
167
+ const value = Number(channel) / 255;
168
+ return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
169
+ });
170
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
171
+ };
172
+ const [lighter, darker] = [luminance(foreground), luminance(background)].sort((a, b) => b - a);
173
+ return (lighter + 0.05) / (darker + 0.05);
174
+ }
175
+
176
+ // Where the dialog sits at one viewport: its box, its close button's, what the scrim leaves on top of the app bar.
177
+ function readPlacement(dashboard) {
178
+ return dashboard.evaluate((inner) => {
179
+ const box = (node) => {
180
+ const { top, right, bottom, left } = node.getBoundingClientRect();
181
+ return { top: Math.round(top), right: Math.round(right), bottom: Math.round(bottom), left: Math.round(left) };
182
+ };
183
+ const close = inner.querySelector(".uppy-Dashboard-close");
184
+ const onAppBar = document.elementFromPoint(window.innerWidth - 2, 32);
185
+ return {
186
+ viewport: { width: window.innerWidth, height: window.innerHeight },
187
+ inner: box(inner),
188
+ radius: window.getComputedStyle(inner).borderTopLeftRadius,
189
+ close: box(close),
190
+ appBarCovered: !onAppBar.closest("[data-testid=fixture-app-bar]")
191
+ };
192
+ });
193
+ }
194
+
195
+ function assertPlacement(placement, { fullScreen }) {
196
+ const { viewport, inner, close } = placement;
197
+ assert.equal(placement.appBarCovered, true, `the scrim covers the app bar at ${viewport.width}px`);
198
+ assert.ok(inner.top >= 0 && inner.left >= 0 && inner.right <= viewport.width && inner.bottom <= viewport.height,
199
+ `the dialog fits the viewport at ${viewport.width}px: ${JSON.stringify(placement)}`);
200
+ assert.ok(close.top >= inner.top && close.left >= inner.left && close.right <= inner.right && close.bottom <= inner.bottom,
201
+ `the close button lies inside the dialog at ${viewport.width}px: ${JSON.stringify(placement)}`);
202
+ if (fullScreen) {
203
+ assert.deepEqual({ inner, radius: placement.radius },
204
+ { inner: { top: 0, right: viewport.width, bottom: viewport.height, left: 0 }, radius: "0px" });
205
+ } else {
206
+ assert.equal(placement.radius, "28px");
207
+ }
208
+ }
209
+
210
+ // The dialog takes the app's Material 3 roles and typeface in both schemes, instead of Uppy's light grey panel, blue
211
+ // underlined link, low-contrast hint and system font. It is modal over the whole app: the scrim covers a top app bar,
212
+ // the close button lies inside the dialog, and at compact width it is a full-screen dialog.
213
+ async function checkMaterialRoles(page) {
214
+ await page.route("**/api/**", (route) => route.fulfill({ json: { csrfToken: "fixture-csrf" } }));
215
+ await page.goto("/avatar");
216
+ const scheme = await page.addStyleTag({ content: schemeCss(SCHEMES.light) });
217
+ // Where Vuetify draws its app bar: fixed at the top, z-index 1004, with the page's content below it as v-main puts it.
218
+ await page.evaluate(() => {
219
+ const bar = document.createElement("header");
220
+ bar.dataset.testid = "fixture-app-bar";
221
+ bar.style.cssText = "position: fixed; top: 0; right: 0; left: 0; height: 64px; z-index: 1004; background: #888;";
222
+ document.body.style.paddingTop = "64px";
223
+ document.body.append(bar);
224
+ });
225
+ await page.getByRole("button", { name: "Change avatar", exact: true }).click();
226
+ const dashboard = dashboardOf(page);
227
+ await expect(dashboard).toBeVisible();
228
+ const read = () => dashboard.evaluate((inner) => {
229
+ const root = inner.closest(".uppy-Root");
230
+ const browse = root.querySelector(".uppy-Dashboard-browse");
231
+ const note = root.querySelector(".uppy-Dashboard-note");
232
+ const style = (node) => window.getComputedStyle(node);
233
+ return {
234
+ panel: style(inner).backgroundColor,
235
+ text: style(root).color,
236
+ font: style(browse).fontFamily,
237
+ link: style(browse).color,
238
+ underline: [style(browse).borderBottomStyle, style(browse).textDecorationLine],
239
+ note: style(note).color
240
+ };
241
+ });
242
+ await page.mouse.move(0, 0);
243
+ for (const name of ["light", "dark"]) {
244
+ const { surface, onSurface, onSurfaceVariant, primary, font } = SCHEMES[name];
245
+ await scheme.evaluate((element, css) => { element.textContent = css; }, schemeCss(SCHEMES[name]));
246
+ await settle(page);
247
+ const roles = await read();
248
+ assert.deepEqual({ scheme: name, ...roles }, {
249
+ scheme: name,
250
+ panel: `rgb(${surface})`,
251
+ text: `rgb(${onSurface})`,
252
+ font,
253
+ link: `rgb(${primary})`,
254
+ underline: ["none", "none"],
255
+ note: `rgb(${onSurfaceVariant})`
256
+ });
257
+ const noteContrast = contrastRatio(roles.note, roles.panel);
258
+ assert.ok(noteContrast >= 4.5, `the ${name} hint text has ${noteContrast.toFixed(2)}:1 contrast`);
259
+ }
260
+
261
+ for (const [width, height, fullScreen] of [[1280, 900, false], [768, 1024, false], [390, 844, true]]) {
262
+ await page.setViewportSize({ width, height });
263
+ await settle(page);
264
+ assertPlacement(await readPlacement(dashboard), { fullScreen });
265
+ }
266
+ await dashboard.getByRole("button", { name: "Close Modal", exact: true }).click();
267
+ await expect(dashboard).toHaveCount(0);
268
+ }
269
+
130
270
  async function checkManagedAvatar(page) {
131
271
  const uploads = [];
132
272
  const deletes = [];
@@ -286,29 +426,27 @@ test("Image uploads run on real Uppy in a real browser", {
286
426
  skip: process.env.JSKIT_UPLOADS_IMAGE_WEB_BROWSER !== "1",
287
427
  timeout: 240_000
288
428
  }, async (t) => {
429
+ // Stopped in after hooks, which run when a check fails or times out too (a body's `finally` doesn't after a timeout).
289
430
  const runtime = await startViteFixture({ fixtureRoot: fileURLToPath(new URL("../fixtures/image-upload/", import.meta.url)) });
290
- let browser;
291
- try {
292
- browser = await chromium.launch(createChromiumLaunchOptions());
293
- for (const [name, check] of [
294
- ["the managed avatar runtime refuses, edits, uploads, reports a server error and deletes", checkManagedAvatar],
295
- ["the upload runtime given only its four required callbacks refuses, uploads compressed and reports a server error", checkUploadRuntime]
296
- ]) {
297
- await t.test(name, async () => {
298
- const { page, errors } = await openPage(browser, runtime.baseURL);
299
- try {
300
- await check(page);
301
- assert.deepEqual(errors, []);
302
- } catch (error) {
303
- console.error(await page.locator("body").innerText().catch(() => ""));
304
- throw error;
305
- } finally {
306
- await page.close();
307
- }
308
- });
309
- }
310
- } finally {
311
- if (browser) await browser.close();
312
- await stopProcess(runtime);
431
+ t.after(() => stopProcess(runtime));
432
+ const browser = await chromium.launch(createChromiumLaunchOptions());
433
+ t.after(() => browser.close());
434
+ for (const [name, check] of [
435
+ ["the managed avatar runtime refuses, edits, uploads, reports a server error and deletes", checkManagedAvatar],
436
+ ["the dialog takes the app's Material 3 roles and typeface in light and dark", checkMaterialRoles],
437
+ ["the upload runtime given only its four required callbacks refuses, uploads compressed and reports a server error", checkUploadRuntime]
438
+ ]) {
439
+ await t.test(name, async () => {
440
+ const { page, errors } = await openPage(browser, runtime.baseURL);
441
+ try {
442
+ await check(page);
443
+ assert.deepEqual(errors, []);
444
+ } catch (error) {
445
+ console.error(await page.locator("body").innerText().catch(() => ""));
446
+ throw error;
447
+ } finally {
448
+ await page.close();
449
+ }
450
+ });
313
451
  }
314
452
  });