diff --git a/roles/web-app-mini-qr/README.md b/roles/web-app-mini-qr/README.md index 17bf19a4fa..5a7ad0444d 100644 --- a/roles/web-app-mini-qr/README.md +++ b/roles/web-app-mini-qr/README.md @@ -101,6 +101,7 @@ docker run --rm -it \ - 🧩 Upstream project: [lyqht/mini-qr](https://github.com/lyqht/mini-qr) - 📦 Upstream Dockerfile: [View on GitHub](https://github.com/lyqht/mini-qr/blob/main/Dockerfile) - 🌐 Docker Image: `ghcr.io/lyqht/mini-qr:latest` +- 🎨 [Corporate design review: before/after screenshots in light, dark, desktop and mobile](https://claude.ai/artifact/Cd8zt8mspm6aZUzKxcpRgS) ## Persona contract opt-outs diff --git a/roles/web-app-mini-qr/TODO.md b/roles/web-app-mini-qr/TODO.md index 59113c964d..7b11a6ef6c 100644 --- a/roles/web-app-mini-qr/TODO.md +++ b/roles/web-app-mini-qr/TODO.md @@ -1,3 +1,6 @@ # To-dos - Remove clarity.ms +- The preview shows its background box without a code until the data changes: in the bottom sheet trigger below 768 px and right after "Add frame" is switched on. Measured on `v0.26.3` with and without the injected design. Cause: upstream, the remounted preview component draws only on a property change. Options: an upstream fix, or a newer image. +- The PWA manifest keeps `name: MiniQR` and `theme_color: #ffffff`, and the `og:` images stay upstream. They are compiled into the image; the injected stylesheet and script do not reach them. Options: build the image in the role, or mount replacements over `/app/dist`. +- The camera view of the scanner keeps upstream colors (`.scanner-container`, `.spinner`, the scoped `.button`, the overlay buttons with `bg-white/80`). It opens only with a camera, which the test browser lacks. Options: a fake media device in the shared Playwright configuration, then a mapping in `templates/style.css.j2`. diff --git a/roles/web-app-mini-qr/files/playwright/playwright.spec.js b/roles/web-app-mini-qr/files/playwright/playwright.spec.js index 3c47664e10..75c8fe0fef 100644 --- a/roles/web-app-mini-qr/files/playwright/playwright.spec.js +++ b/roles/web-app-mini-qr/files/playwright/playwright.spec.js @@ -65,3 +65,5 @@ test("administrator: app → universal logout", async ({ page }) => { }, }); }); + +require("./test-design").register(); diff --git a/roles/web-app-mini-qr/files/playwright/test-design.js b/roles/web-app-mini-qr/files/playwright/test-design.js new file mode 100644 index 0000000000..187782a7fc --- /dev/null +++ b/roles/web-app-mini-qr/files/playwright/test-design.js @@ -0,0 +1,500 @@ +const fs = require("node:fs"); + +const { test, expect } = require("@playwright/test"); + +const { + assertDesignTokens, + assertLightAndDark, + assertReadable, + assertToken, + captureDesignGallery, + galleryEnabled, + tokenValue, +} = require("./design"); +const { apiGetOnion, decodeDotenvQuotedValue, gotoOnion } = require("./personas"); +const { skipUnlessServiceEnabled } = require("./service-gating"); +const { resolveTimeout } = require("./timeouts"); + +const STORAGE_KEYS = ["dark-mode-preference", "qrCodeConfig", "qr-scanner-camera-preference"]; +const INJECTED_SNIPPETS = /[\s\S]*?/g; +const READY = "#settings #data"; +const PAGE = "#app > main > .min-h-screen"; +const PREVIEW = "#element-to-export"; +const QR = "[role='img'][aria-label^='QR code'] svg"; +const TOGGLE = "button[aria-label='Toggle dark mode']:visible"; +const MENU = "button[aria-label='Menu']"; +const MODAL = "[role='dialog'][aria-labelledby='data-to-encode-modal-title']"; +const SAVE = `${MODAL} .border-t > .button`; +const SELECTED_MODE = "button[aria-label='Switch to Create Mode']:visible"; +const HEADER_ICON = "#app a.icon-button:visible"; +const RADIO = "#settings input[type='radio']"; +const EXPORT_PNG = "#download-qr-image-button-png"; +const POPOVER = "[cmdk-input-wrapper] input"; +const CSV_INPUT = "input[type='file'][accept='.csv,.txt']"; +const IMAGE_INPUT = "input[type='file'][accept='image/*']"; +const ROLE_SHEET = "link[rel='stylesheet'][href*='web-app-mini-qr'][href*='style.css']"; +const SAMPLE = "https://example.org/design"; +const BLANK_PNG = Buffer.from( + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==", + "base64", +); +const BATCH_CSV = ["url,frameText,fileName", "https://example.org/a,Scan A,code-a", "https://example.org/b,Scan B,code-b"].join( + "\n", +); + +function baseUrl() { + return decodeDotenvQuotedValue(process.env.APP_BASE_URL || "").replace(/\/$/, ""); +} + +function designTitle() { + return decodeDotenvQuotedValue(process.env.DESIGN_TITLE || ""); +} + +function designFaviconUrl() { + return decodeDotenvQuotedValue(process.env.DESIGN_FAVICON_URL || ""); +} + +function designLogoUrl() { + return decodeDotenvQuotedValue(process.env.DESIGN_LOGO_URL || ""); +} + +async function fresh(page) { + await page.addInitScript((keys) => { + try { + for (const key of keys) window.localStorage.removeItem(key); + window.localStorage.setItem("preferred-language", "en"); + } catch (error) { + void error; + } + }, STORAGE_KEYS); +} + +async function open(page) { + await gotoOnion(page, `${baseUrl()}/`); + await page.locator(READY).first().waitFor({ state: "visible", timeout: resolveTimeout(20_000) }); +} + +async function stripInjectedSnippets(route) { + if (route.request().resourceType() !== "document") return route.continue(); + const response = await route.fetch(); + return route.fulfill({ response, body: (await response.text()).replace(INJECTED_SNIPPETS, "") }); +} + +async function quiet(page) { + await page.waitForFunction( + () => + document + .getAnimations() + .every((a) => a.playState !== "running" || a.effect?.getComputedTiming().iterations === Infinity), + null, + { timeout: resolveTimeout(10_000) }, + ); +} + +function narrow(page) { + return page.viewportSize().width < 768; +} + +async function darkClass(page) { + return page.evaluate(() => document.documentElement.classList.contains("dark")); +} + +async function openTools(page) { + if (!narrow(page)) return; + await page.locator(MENU).click({ timeout: resolveTimeout(10_000) }); + await page.locator(TOGGLE).waitFor({ state: "visible", timeout: resolveTimeout(10_000) }); + await quiet(page); +} + +async function pickScheme(page, clicks) { + await openTools(page); + for (let count = 0; count < clicks; count += 1) { + await page.locator(TOGGLE).click({ timeout: resolveTimeout(10_000) }); + } +} + +async function setData(page, text) { + const code = page.locator(QR).first(); + const before = narrow(page) ? null : await code.innerHTML(); + await page.locator("#data").fill(text); + if (before === null) return; + await expect.poll(() => code.innerHTML(), { timeout: resolveTimeout(10_000) }).not.toBe(before); +} + +async function openExport(page) { + if (narrow(page)) { + await page.locator("#drawer-preview-container").click({ timeout: resolveTimeout(10_000) }); + } + await page.locator(`${EXPORT_PNG}:enabled`).waitFor({ state: "visible", timeout: resolveTimeout(10_000) }); + await quiet(page); +} + +async function enableFrame(page) { + await page.locator("#frame-settings-title").click({ timeout: resolveTimeout(10_000) }); + await page.locator("#show-frame").check({ timeout: resolveTimeout(10_000) }); + await page.locator("#frame-text").waitFor({ state: "visible", timeout: resolveTimeout(10_000) }); + await quiet(page); +} + +async function openCombobox(page, label) { + await page.locator(`button[role='combobox'][aria-label='${label}']:visible`).click({ timeout: resolveTimeout(10_000) }); + await page.locator(POPOVER).waitFor({ state: "visible", timeout: resolveTimeout(10_000) }); + await quiet(page); +} + +async function openModal(page, type) { + await page.locator("button[aria-label='Open data type generator']").click({ timeout: resolveTimeout(10_000) }); + await page.locator(MODAL).waitFor({ state: "visible", timeout: resolveTimeout(10_000) }); + await page.locator("#dataType").selectOption(type); + await quiet(page); +} + +async function failModal(page) { + await openModal(page, "url"); + await page.locator(SAVE).click({ timeout: resolveTimeout(10_000) }); + await page.locator(`${MODAL} p.text-red-500`).first().waitFor({ state: "visible", timeout: resolveTimeout(10_000) }); + await page.mouse.move(0, 0); +} + +async function toBatch(page) { + await page.getByRole("button", { name: "Batch export", exact: true }).click({ timeout: resolveTimeout(10_000) }); + await page.locator(CSV_INPUT).waitFor({ state: "attached", timeout: resolveTimeout(10_000) }); +} + +async function openGuide(page) { + await toBatch(page); + await page.getByRole("button", { name: "CSV Format Guide" }).click({ timeout: resolveTimeout(10_000) }); + await page.getByRole("button", { name: "vCard Contact" }).waitFor({ state: "visible", timeout: resolveTimeout(10_000) }); + await quiet(page); +} + +async function toScan(page) { + await page.locator("button[aria-label='Switch to Scan Mode']:visible").click({ timeout: resolveTimeout(10_000) }); + await page.locator(".capture-controls").waitFor({ state: "visible", timeout: resolveTimeout(10_000) }); +} + +async function openChangelog(page) { + await openTools(page); + await page.locator("button[aria-label='View changelog']:visible").click({ timeout: resolveTimeout(10_000) }); + await page.locator("[role='dialog'] .prose h2").first().waitFor({ state: "visible", timeout: resolveTimeout(20_000) }); + await quiet(page); +} + +async function qrPaint(page) { + return page.evaluate((preview) => { + const ctx = document.createElement("canvas").getContext("2d"); + const rgb = (value) => { + ctx.fillStyle = "#000"; + ctx.fillStyle = value; + return ctx.fillStyle; + }; + return { + background: rgb(getComputedStyle(document.querySelector(preview)).backgroundColor), + expectedBackground: rgb(document.querySelector("#background-color").value), + fills: Array.from(document.querySelectorAll(`${preview} svg [fill]`), (node) => [ + rgb(node.getAttribute("fill")), + rgb(getComputedStyle(node).fill), + ]).filter(([attribute]) => /^#/.test(attribute)), + }; + }, PREVIEW); +} + +async function roleSheet(page, request) { + const href = await page.locator(ROLE_SHEET).first().getAttribute("href"); + const response = await apiGetOnion(request, href, { timeout: resolveTimeout(30_000) }); + expect(response.status(), "mini-qr: the role stylesheet must be served").toBe(200); + return response.text(); +} + +async function rulesInsidePreview(page, css) { + const selectors = css + .replace(/\/\*[\s\S]*?\*\//g, "") + .split("}") + .map((rule) => rule.split("{")[0].trim()) + .filter(Boolean); + expect(selectors.length, "mini-qr: the role stylesheet must carry rules").toBeGreaterThan(20); + return page.evaluate( + ([list, preview]) => { + const nodes = Array.from(document.querySelectorAll(`${preview}, ${preview} *`)); + return list.filter((selector) => { + try { + return nodes.some((node) => node.matches(selector.replace(/::[\w-]+/g, ""))); + } catch (error) { + void error; + return true; + } + }); + }, + [selectors, PREVIEW], + ); +} + +async function exportPng(page) { + await setData(page, SAMPLE); + const [download] = await Promise.all([ + page.waitForEvent("download", { timeout: resolveTimeout(30_000) }), + page.locator(EXPORT_PNG).click({ timeout: resolveTimeout(10_000) }), + ]); + return fs.readFileSync(await download.path()); +} + +function view(name, prepare) { + return { + name, + url: `${baseUrl()}/`, + prepare: async (page) => { + await page.locator(READY).first().waitFor({ state: "visible", timeout: resolveTimeout(20_000) }); + if (prepare) await prepare(page); + }, + }; +} + +function views() { + const hover = (selector) => (page) => page.locator(selector).first().hover({ timeout: resolveTimeout(10_000) }); + return [ + view("create"), + view("create-with-data", (page) => setData(page, SAMPLE)), + view("data-focus", (page) => page.locator("#data").focus()), + view("export-panel", async (page) => { + await setData(page, SAMPLE); + await openExport(page); + }), + view("export-button-hover", async (page) => { + await setData(page, SAMPLE); + await openExport(page); + await hover(EXPORT_PNG)(page); + }), + view("frame-enabled", async (page) => { + await setData(page, SAMPLE); + await enableFrame(page); + }), + view("frame-preset-open", async (page) => { + await setData(page, SAMPLE); + await enableFrame(page); + await openCombobox(page, "Select frame preset"); + }), + view("preset-open", (page) => openCombobox(page, "Select QR code preset")), + view("settings-colors", (page) => page.locator("#with-background").uncheck({ timeout: resolveTimeout(10_000) })), + view("settings-types", (page) => + page.locator("#dots-squares-settings fieldset").last().scrollIntoViewIfNeeded({ timeout: resolveTimeout(10_000) }), + ), + view("data-templates-wifi", (page) => openModal(page, "wifi")), + view("data-templates-vcard", (page) => openModal(page, "vcard")), + view("data-templates-error", failModal), + view("batch-guide", openGuide), + view("batch-preview", async (page) => { + await toBatch(page); + await page.locator(CSV_INPUT).setInputFiles({ name: "batch.csv", mimeType: "text/csv", buffer: Buffer.from(BATCH_CSV) }); + await page.locator("#settings code").first().waitFor({ state: "visible", timeout: resolveTimeout(10_000) }); + }), + view("scan", toScan), + view("scan-error", async (page) => { + await toScan(page); + await page.locator(IMAGE_INPUT).setInputFiles({ name: "blank.png", mimeType: "image/png", buffer: BLANK_PNG }); + await page.locator(".capture-controls p.text-red-500").waitFor({ state: "visible", timeout: resolveTimeout(20_000) }); + }), + view("header-tools", async (page) => { + await openTools(page); + await hover(TOGGLE)(page); + }), + view("language-open", async (page) => { + await openTools(page); + await openCombobox(page, "Select language"); + }), + view("theme-forced-dark", (page) => pickScheme(page, 2)), + view("changelog", openChangelog), + ]; +} + +exports.register = function () { + test.describe("design", () => { + test.use({ serviceWorkers: "block" }); + + test("design: corporate tokens apply in light and dark mode", async ({ page }) => { + skipUnlessServiceEnabled("design"); + await fresh(page); + await open(page); + await assertDesignTokens(page, "mini-qr"); + }); + + test("design: page, fields, controls, primary action and divider take the tokens in both modes", async ({ page }) => { + skipUnlessServiceEnabled("design"); + await fresh(page); + await open(page); + await failModal(page); + for (const mode of ["light", "dark"]) { + const label = `mini-qr ${mode}`; + await page.emulateMedia({ colorScheme: mode }); + await expect.poll(() => darkClass(page)).toBe(mode === "dark"); + await assertToken(page, "body", "background-color", "--design-surface-1", label); + await assertToken(page, PAGE, "background-color", "--design-surface-1", label); + await assertToken(page, "label[for='data']", "color", "--design-text", label); + await assertToken(page, "#data", "background-color", "--design-surface-2", label); + await assertToken(page, "#data", "color", "--design-text", label); + await assertToken(page, "#copy-qr-image-button", "background-color", "--design-surface-3", label); + await assertToken(page, "#settings .secondary-button", "background-color", "--design-surface-2", label); + await assertToken(page, SELECTED_MODE, "background-color", "--design-surface-2", label); + await assertToken(page, SAVE, "background-color", "--design-surface-3", label); + await assertToken(page, SAVE, "color", "--design-text", label); + await assertToken(page, `${MODAL} p.text-red-500`, "color", "--design-danger", label); + await assertToken(page, `${MODAL} .border-t`, "border-top-color", "--design-border", label); + await assertToken(page, EXPORT_PNG, "background-color", "--design-primary", label); + await assertToken(page, EXPORT_PNG, "color", "--design-on-primary", label); + await assertToken(page, HEADER_ICON, "color", "--design-text", label); + const primary = await tokenValue(page, "--design-primary", "color"); + await expect + .poll(() => page.locator(RADIO).first().evaluate((radio) => getComputedStyle(radio, "::before").color), { + message: `${label}: the radio mark must take --design-primary`, + }) + .toBe(primary); + await expect + .poll(() => page.locator(HEADER_ICON).first().evaluate((icon) => getComputedStyle(icon).backgroundColor), { + message: `${label}: a header icon button must not carry a fill`, + }) + .toBe("rgba(0, 0, 0, 0)"); + await expect + .poll( + () => + page.locator(`${HEADER_ICON} svg path`).first().evaluate((path) => { + const style = getComputedStyle(path); + return style.fill === getComputedStyle(path.closest("a, button")).color; + }), + { message: `${label}: a header icon must take the color of its control` }, + ) + .toBe(true); + } + await page.emulateMedia({ colorScheme: null }); + }); + + test("design: the generator stays readable in light and dark mode", async ({ page }) => { + skipUnlessServiceEnabled("design"); + await fresh(page); + await open(page); + await assertLightAndDark(page, "#settings", "mini-qr generator"); + await assertReadable( + page, + [ + "label[for='data']", + "#data", + "#copy-qr-image-button", + EXPORT_PNG, + "#frame-settings-title", + "#settings .secondary-button", + "#settings .radio label", + "#settings legend", + "button[aria-label='Switch to Create Mode']", + "button[aria-label='Switch to Scan Mode']", + "#export-options p", + { selector: "footer a", optional: true }, + ], + "mini-qr generator", + ); + await failModal(page); + await assertReadable(page, [`${MODAL} h2`, `${MODAL} label`, `${MODAL} input`, SAVE, `${MODAL} p.text-red-500`], "mini-qr dialog"); + }); + + test("design: the theme switch drives the tokens", async ({ page }) => { + skipUnlessServiceEnabled("design"); + await fresh(page); + await page.emulateMedia({ colorScheme: "light" }); + await open(page); + const light = await tokenValue(page, "--design-surface-1", "color"); + await expect(page.locator("html")).not.toHaveAttribute("data-design-theme", /.+/); + await pickScheme(page, 2); + await expect(page.locator("html")).toHaveClass(/(^|\s)dark(\s|$)/); + await expect(page.locator("html")).toHaveAttribute("data-design-theme", "dark"); + await expect.poll(() => tokenValue(page, "--design-surface-1", "color")).not.toBe(light); + await assertToken(page, PAGE, "background-color", "--design-surface-1", "mini-qr forced dark"); + await assertToken(page, "#data", "color", "--design-text", "mini-qr forced dark"); + await page.locator(TOGGLE).click({ timeout: resolveTimeout(10_000) }); + await expect(page.locator("html")).not.toHaveAttribute("data-design-theme", /.+/); + await page.emulateMedia({ colorScheme: "dark" }); + await expect.poll(() => darkClass(page)).toBe(true); + await page.locator(TOGGLE).click({ timeout: resolveTimeout(10_000) }); + await expect(page.locator("html")).toHaveAttribute("data-design-theme", "light"); + await expect.poll(() => darkClass(page)).toBe(false); + await expect.poll(() => tokenValue(page, "--design-surface-1", "color")).toBe(light); + await assertToken(page, PAGE, "background-color", "--design-surface-1", "mini-qr forced light"); + await page.emulateMedia({ colorScheme: null }); + }); + + test("design: the QR code keeps the colors the user chose", async ({ page, request }) => { + skipUnlessServiceEnabled("design"); + await fresh(page); + await open(page); + await page.locator(`${PREVIEW} svg`).waitFor({ state: "visible", timeout: resolveTimeout(20_000) }); + for (const mode of ["light", "dark"]) { + await page.emulateMedia({ colorScheme: mode }); + await expect.poll(() => darkClass(page)).toBe(mode === "dark"); + const paint = await qrPaint(page); + expect(paint.background, `mini-qr ${mode}: the preview background is the chosen one`).toBe(paint.expectedBackground); + expect(paint.fills.length, `mini-qr ${mode}: the preview must carry fill colors`).toBeGreaterThan(0); + for (const [attribute, computed] of paint.fills) { + expect(computed, `mini-qr ${mode}: a QR fill must stay ${attribute}`).toBe(attribute); + } + } + await page.emulateMedia({ colorScheme: null }); + await enableFrame(page); + await expect(page.locator(`${PREVIEW} p`).first()).toBeVisible(); + expect( + await rulesInsidePreview(page, await roleSheet(page, request)), + "mini-qr: no rule of the role stylesheet may match inside the preview", + ).toEqual([]); + }); + + test("design: an exported image is the same with and without the design", async ({ page }) => { + skipUnlessServiceEnabled("design"); + await fresh(page); + await open(page); + await expect(page.locator(ROLE_SHEET)).toHaveCount(1); + const designed = await exportPng(page); + await page.route("**/*", stripInjectedSnippets); + await open(page); + await expect(page.locator(ROLE_SHEET)).toHaveCount(0); + const plain = await exportPng(page); + await page.unroute("**/*", stripInjectedSnippets); + expect(designed.length, "mini-qr: the export must carry an image").toBeGreaterThan(1000); + expect(designed.equals(plain), "mini-qr: the exported PNG must not depend on the design").toBe(true); + }); + + test("design: logo, favicon and title are the configured ones", async ({ page }) => { + skipUnlessServiceEnabled("design"); + test.skip(!designLogoUrl() || !designTitle(), "logo or title replacement is switched off"); + await fresh(page); + await open(page); + await expect.poll(() => page.title()).toBe(designTitle()); + await expect + .poll(() => page.evaluate(() => document.querySelector("link[rel='icon']").href)) + .toBe(designFaviconUrl()); + for (const size of [{ width: 1440, height: 900 }, { width: 390, height: 844 }]) { + await page.setViewportSize(size); + await openTools(page); + const brand = page.locator("#app h1:visible").first(); + await expect(brand).toBeVisible(); + expect(await brand.evaluate((heading) => getComputedStyle(heading).backgroundImage)).toContain(designLogoUrl()); + const box = await brand.boundingBox(); + expect(box.width, `mini-qr ${size.width}: the brand box must be wider than high`).toBeGreaterThan(box.height * 1.5); + } + const lockup = await page.evaluate( + (source) => + new Promise((resolve) => { + const image = new Image(); + image.onload = () => resolve(image.naturalWidth); + image.onerror = () => resolve(0); + image.src = source; + }), + designLogoUrl(), + ); + expect(lockup, "mini-qr: the lockup must load").toBeGreaterThan(0); + }); + + test("design: gallery of the generator and the scanner", async ({ page }) => { + skipUnlessServiceEnabled("design"); + test.skip(!galleryEnabled(), "INFINITO_PLAYWRIGHT_KEEP is not true"); + test.setTimeout(resolveTimeout(1_800_000)); + await fresh(page); + await captureDesignGallery(page, views()); + }); + + }); +}; diff --git a/roles/web-app-mini-qr/meta/services.yml b/roles/web-app-mini-qr/meta/services.yml index 0dba71ec05..8b22b27bf6 100644 --- a/roles/web-app-mini-qr/meta/services.yml +++ b/roles/web-app-mini-qr/meta/services.yml @@ -46,6 +46,16 @@ design: bond: 1 enabled: "{{ 'web-svc-design' in group_names }}" shared: "{{ 'web-svc-design' in group_names }}" + slots: + favicon: + width: 64 + height: 64 + apple-touch-icon: + width: 180 + height: 180 + logo: + width: 200 + height: 48 prometheus: bond: 1 enabled: "{{ 'web-app-prometheus' in group_names }}" diff --git a/roles/web-app-mini-qr/templates/design.js.j2 b/roles/web-app-mini-qr/templates/design.js.j2 new file mode 100644 index 0000000000..02047f72b4 --- /dev/null +++ b/roles/web-app-mini-qr/templates/design.js.j2 @@ -0,0 +1,39 @@ +{% set design = lookup('design', application_id) %} +(function () { + var root = document.documentElement; +{% if design.title is string %} + document.title = {{ design.title | to_json }}; +{% endif %} +{% if design.logo is string %} + var icon = document.querySelector("link[rel='icon']") || document.head.appendChild(document.createElement("link")); + icon.rel = "icon"; + icon.type = "image/svg+xml"; + icon.href = {{ design.urls.favicon.svg | to_json }}; + var touch = document.querySelector("link[rel='apple-touch-icon']") || document.head.appendChild(document.createElement("link")); + touch.rel = "apple-touch-icon"; + touch.href = {{ design.urls['apple-touch-icon'].png | to_json }}; +{% endif %} + function mirror() { + var choice = null; + try { + choice = window.localStorage.getItem("dark-mode-preference"); + } catch (error) { + choice = null; + } + if (choice === "light" || choice === "dark") { + root.setAttribute("data-design-theme", choice); + } else { + root.removeAttribute("data-design-theme"); + } + } + new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["class"] }); + document.addEventListener( + "click", + function () { + window.setTimeout(mirror, 0); + }, + true + ); + window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", mirror); + mirror(); +})(); diff --git a/roles/web-app-mini-qr/templates/playwright.env.j2 b/roles/web-app-mini-qr/templates/playwright.env.j2 index 2901c264ce..0d50d5aab5 100644 --- a/roles/web-app-mini-qr/templates/playwright.env.j2 +++ b/roles/web-app-mini-qr/templates/playwright.env.j2 @@ -2,9 +2,14 @@ APP_BASE_URL={{ lookup('tls', application_id, 'url.base') | dotenv_quote }} CANONICAL_DOMAIN={{ lookup('domain', application_id) | dotenv_quote }} -# nocheck: playwright-service-gate — assertCspInjections resolves this injector through a computed loop variable (personas/utils/csp.js), never a literal gate argument, so this rule's literal-only regex cannot see the gate +DESIGN_FAVICON_URL={{ (lookup('design', application_id).urls.favicon.svg if lookup('design', application_id).logo is string else '') | dotenv_quote }} + +DESIGN_LOGO_URL={{ (lookup('design', application_id).urls.logo.svg if lookup('design', application_id).logo is string else '') | dotenv_quote }} + DESIGN_SERVICE_ENABLED={{ lookup('config', application_id, 'services.design.enabled') | string | lower }} +DESIGN_TITLE={{ (lookup('design', application_id).title if lookup('design', application_id).title is string else '') | dotenv_quote }} + LOGOUT_SERVICE_ENABLED={{ lookup('config', application_id, 'services.logout.enabled') | string | lower }} MATOMO_BASE_URL={{ lookup('tls', 'web-app-matomo', 'url.base') | dotenv_quote }} diff --git a/roles/web-app-mini-qr/templates/style.css.j2 b/roles/web-app-mini-qr/templates/style.css.j2 new file mode 100644 index 0000000000..7ccb083ee6 --- /dev/null +++ b/roles/web-app-mini-qr/templates/style.css.j2 @@ -0,0 +1,197 @@ +{% set design = lookup('design', application_id) %} +{% set focus = 'var(--design-focus, var(--design-link))' %} +{% set modal = '[aria-labelledby="data-to-encode-modal-title"]' %} +{% set chrome = ':where(:not(#element-to-export, #element-to-export *, #drawer-preview-container .origin-center *))' %} +{% macro paint(property, value, classes, state='') %} +{% for cls in classes %} +:root [class~="{{ cls }}"]{{ state }}{{ ',' if not loop.last else ' {' }} +{% endfor %} + {{ property }}: {{ value }}; +} +{% endmacro %} +body, +#app > main > .min-h-screen { + background-color: var(--design-surface-1); + color: var(--design-text); +} +{{ chrome }}, +{{ chrome }}::before, +{{ chrome }}::after { + border-color: var(--design-border); +} +{{ paint('background-color', 'var(--design-surface-2)', ['bg-white', 'bg-zinc-50', 'bg-background', 'bg-popover']) }} +{{ paint('background-color', 'var(--design-surface-3)', ['bg-zinc-100', 'bg-gray-100', 'bg-gray-50', 'bg-gray-200']) }} +{{ paint('background-color', 'var(--design-border)', ['bg-zinc-200', 'bg-border']) }} +{{ paint('background-color', 'var(--design-border-strong)', ['bg-gray-300', 'bg-muted']) }} +{{ paint('background-color', 'var(--design-info-subtle)', ['bg-blue-50']) }} +{{ paint('background-color', 'var(--design-surface-hover)', ['hover:bg-zinc-100', 'hover:bg-zinc-200', 'hover:bg-gray-50', 'hover:bg-accent'], ':hover') }} +{{ paint('background-color', 'var(--design-surface-hover)', ['data-[highlighted]:bg-accent'], '[data-highlighted]') }} +{{ paint('background-color', 'var(--design-surface-active)', ['data-[state=open]:bg-accent'], '[data-state="open"]') }} +{{ paint('color', 'var(--design-text)', ['text-zinc-900', 'text-zinc-800', 'text-zinc-700', 'text-gray-800', 'text-gray-700', 'text-foreground', 'text-popover-foreground']) }} +{{ paint('color', 'var(--design-text)', ['hover:text-zinc-900', 'hover:text-zinc-700', 'hover:text-gray-700', 'hover:text-accent-foreground'], ':hover') }} +{{ paint('color', 'var(--design-text-muted)', ['text-zinc-600', 'text-zinc-500', 'text-gray-600', 'text-gray-500', 'text-gray-400', 'text-muted-foreground']) }} +{{ paint('color', 'var(--design-text-muted)', ['placeholder:text-muted-foreground'], '::placeholder') }} +{{ paint('color', 'var(--design-text-muted)', ['data-[state=open]:text-muted-foreground'], '[data-state="open"]') }} +{{ paint('color', 'var(--design-danger)', ['text-red-500']) }} +{{ paint('color', 'var(--design-link)', ['text-blue-600']) }} +{{ paint('border-color', 'var(--design-border)', ['border-zinc-200', 'border-gray-200', 'border-gray-100']) }} +{{ paint('border-color', 'var(--design-border-strong)', ['border-zinc-300', 'border-gray-300', 'border-slate-300', 'border-input']) }} +{{ paint('border-color', 'var(--design-text-muted)', ['hover:border-gray-400'], ':hover') }} +{{ paint('border-color', 'var(--design-primary)', ['border-zinc-900', 'border-gray-900']) }} +{{ paint('border-top-color', 'var(--design-primary)', ['border-t-blue-500']) }} +{{ paint('border-color', 'var(--design-danger)', ['border-red-500']) }} +{{ paint('border-color', 'var(--design-danger)', ['focus:border-red-500'], ':focus') }} +{{ paint('border-color', 'var(--design-info-border)', ['border-blue-200', 'border-blue-400']) }} +{{ paint('--tw-ring-color', focus, ['focus-visible:ring-zinc-700', 'focus-visible:ring-ring'], ':focus-visible') }} +{{ paint('--tw-ring-color', focus, ['focus:ring-ring'], ':focus') }} +{{ paint('--tw-ring-color', 'var(--design-danger)', ['focus:ring-red-500'], ':focus') }} +{{ paint('--tw-ring-offset-color', 'var(--design-surface-1)', ['ring-offset-background']) }} +a, +a:visited, +a:active { + color: var(--design-link); +} +:root p{{ chrome }}, +:root label, +:root legend, +:root .radio > label, +:root .radio > * > label { + color: var(--design-text); +} +:root {{ chrome }}::selection { + background-color: var(--design-surface-active); + color: var(--design-text); +} +:root {{ chrome }}::-webkit-scrollbar-track { + background-color: var(--design-surface-3); +} +:root {{ chrome }}::-webkit-scrollbar-thumb { + background-color: var(--design-border-strong); +} +:root {{ chrome }}::-webkit-scrollbar-thumb:hover { + background-color: var(--design-text-muted); +} +:root input::placeholder, +:root textarea::placeholder { + color: var(--design-text-muted); +} +:root .text-input, +:root .secondary-button { + background-color: var(--design-surface-2); + color: var(--design-text); +} +:root .button { + background-color: var(--design-surface-3); + color: var(--design-text); +} +:root .button:hover:not(:disabled), +:root .secondary-button:hover:not(:disabled) { + background-color: var(--design-surface-hover); +} +:root .button:active:not(:disabled), +:root .secondary-button:active:not(:disabled) { + background-color: var(--design-surface-active); +} +#export-options .button { + background-color: var(--design-primary); + color: var(--design-on-primary); +} +#export-options .button:hover:not(:disabled) { + background-color: var(--design-primary-hover); +} +#export-options .button:active:not(:disabled) { + background-color: var(--design-primary-active); +} +#app .icon-button { + background-color: transparent; + color: var(--design-text); +} +#app .icon-button:hover { + background-color: var(--design-surface-hover); +} +:root .text-input:focus-visible, +:root .button:focus-visible, +:root .secondary-button:focus-visible, +:root .icon-button:focus-visible, +:root input[type="color"]:focus-visible, +:root input[type="checkbox"]:focus, +:root .radio:focus-within { + --tw-ring-color: {{ focus }}; +} +:root fieldset:focus-visible { + outline-color: {{ focus }}; +} +:root input[type="color"] { + border-color: var(--design-border-strong); + color: var(--design-text); +} +:root input[type="radio"], +:root input[type="checkbox"] { + background-color: var(--design-surface-2); + border-color: var(--design-border-strong); +} +:root input[type="checkbox"]:hover { + border-color: var(--design-text-muted); +} +:root input[type="radio"]::before, +:root input[type="checkbox"]::before { + background-color: var(--design-primary); + color: var(--design-primary); +} +#app footer { + background-color: rgba(var(--design-surface-1-rgb), 0.8); +} +:is(.icon-button, .button, .secondary-button, [role="combobox"], {{ modal }}) svg :is([fill="#abcbca"], [fill="#abcabc"], [fill="#888888"]) { + fill: currentColor; +} +:is(.icon-button, .button, .secondary-button, [role="combobox"], {{ modal }}) svg[stroke="#abcbca"], +:is(.icon-button, .button, .secondary-button, [role="combobox"], {{ modal }}) svg :is([stroke="#abcbca"], [stroke="#888888"]) { + stroke: currentColor; +} +.prose { + --tw-prose-body: var(--design-text); + --tw-prose-headings: var(--design-text); + --tw-prose-lead: var(--design-text-muted); + --tw-prose-links: var(--design-link); + --tw-prose-bold: var(--design-text); + --tw-prose-counters: var(--design-text-muted); + --tw-prose-bullets: var(--design-text-muted); + --tw-prose-hr: var(--design-border); + --tw-prose-quotes: var(--design-text); + --tw-prose-quote-borders: var(--design-border); + --tw-prose-captions: var(--design-text-muted); + --tw-prose-code: var(--design-text); + --tw-prose-pre-code: var(--design-text); + --tw-prose-pre-bg: var(--design-surface-3); + --tw-prose-th-borders: var(--design-border-strong); + --tw-prose-td-borders: var(--design-border); + --tw-prose-invert-body: var(--design-text); + --tw-prose-invert-headings: var(--design-text); + --tw-prose-invert-lead: var(--design-text-muted); + --tw-prose-invert-links: var(--design-link); + --tw-prose-invert-bold: var(--design-text); + --tw-prose-invert-counters: var(--design-text-muted); + --tw-prose-invert-bullets: var(--design-text-muted); + --tw-prose-invert-hr: var(--design-border); + --tw-prose-invert-quotes: var(--design-text); + --tw-prose-invert-quote-borders: var(--design-border); + --tw-prose-invert-captions: var(--design-text-muted); + --tw-prose-invert-code: var(--design-text); + --tw-prose-invert-pre-code: var(--design-text); + --tw-prose-invert-pre-bg: var(--design-surface-3); + --tw-prose-invert-th-borders: var(--design-border-strong); + --tw-prose-invert-td-borders: var(--design-border); +} +{% if design.logo is string %} +#app h1 { + width: 200px; + height: 48px; + overflow: hidden; + font-size: 0; + background: url("{{ design.urls.logo.svg }}") left center / contain no-repeat; +} +#app h1.text-xl { + width: 150px; + height: 36px; +} +{% endif %}