From faadf5b850f9a0700da5d078fb94936d587c033a Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 18 Oct 2026 22:36:32 +0200 Subject: [PATCH] refactor(design): compose the per-app sheet and script from one SPOT sys-front-inj-design now renders templates/css/app.css.j2 ahead of the role's stylesheet and templates/js/design.js.j2 ahead of its script. The branding URLs, the slot dimensions and the logo guard live there instead of being repeated per role: the guard that stood in 41 sheets is one condition in the composing template, and a sheet reads branding through --design-url-* / --design-slot-* custom properties. 29 stylesheets and 43 design scripts lose their Jinja and move to static files. Roles whose sheet carries app-specific URLs declare them as design_css_urls and read them as --design-url-app-*. The script prelude is prepended only when the role script references it, and it carries urls only while a logo is configured, so every role that needs neither is emitted byte for byte as before. Five checks keep the mechanism honest: a composed sheet may only read design custom properties that app.css.j2 declares for its role, a template may not carry Jinja expression text outside its delimiters, a design script may not quote its config object, and the injected-script parse check now covers the design channel. Co-Authored-By: Claude Opus 5 (1M context) --- .github/PULL_REQUEST_TEMPLATE/server.md | 2 +- cli/meta/roles/design/__init__.py | 1 + docs/agents/action/design.md | 6 +- docs/agents/files/role/style.css.md | 2 +- .../artefact/files/role/style.css.md | 9 +- eslint.config.js | 5 +- roles/sys-front-inj-design/README.md | 2 +- roles/sys-front-inj-design/defaults/main.yml | 2 + roles/sys-front-inj-design/tasks/main.yml | 20 +- .../templates/css/app.css.j2 | 20 ++ .../templates/head_sub.j2 | 2 +- .../templates/js/design.js.j2 | 7 + roles/web-app-akaunting/files/logo.css | 3 + .../style.css.j2 => files/style.css} | 7 - roles/web-app-baserow/files/logo.css | 11 + .../style.css.j2 => files/style.css} | 14 - .../style.css.j2 => files/style.css} | 0 roles/web-app-bluesky/files/logo.css | 9 + .../style.css.j2 => files/style.css} | 13 - roles/web-app-bluesky/templates/design.js | 36 +++ roles/web-app-bluesky/templates/design.js.j2 | 37 --- .../templates/{design.js.j2 => design.js} | 6 +- .../style.css.j2 => files/style.css} | 0 .../web-app-confluence/templates/style.css.j2 | 0 roles/web-app-decidim/files/logo.css | 3 + .../style.css.j2 => files/style.css} | 7 - .../templates/{design.js.j2 => design.js} | 16 +- .../web-app-discourse/templates/style.css.j2 | 0 roles/web-app-docs/files/logo.css | 6 + .../style.css.j2 => files/style.css} | 9 - roles/web-app-docs/templates/design.js | 22 ++ roles/web-app-docs/templates/design.js.j2 | 23 -- .../theme.css.j2 => files/theme.css} | 0 roles/web-app-erpnext/tasks/04_design.yml | 2 +- .../templates/{design.js.j2 => design.js} | 4 +- roles/web-app-fediwall/templates/design.js | 30 ++ roles/web-app-fediwall/templates/design.js.j2 | 31 -- .../templates/{design.js.j2 => design.js} | 18 +- roles/web-app-flowise/files/logo.css | 3 + .../style.css.j2 => files/style.css} | 7 - roles/web-app-flowise/templates/design.js | 81 ++++++ roles/web-app-flowise/templates/design.js.j2 | 82 ------ .../style.css.j2 => files/style.css} | 0 roles/web-app-funkwhale/templates/design.js | 47 +++ .../web-app-funkwhale/templates/design.js.j2 | 48 --- .../templates/{design.js.j2 => design.js} | 4 +- .../templates/{design.js.j2 => design.js} | 6 +- .../templates/dashboard-theme.css.j2 | 7 +- roles/web-app-hermes/templates/style.css.j2 | 23 +- roles/web-app-homeassistant/README.md | 2 +- .../web-app-homeassistant/templates/design.js | 77 +++++ .../templates/design.js.j2 | 78 ----- .../templates/style.css.j2 | 7 +- .../templates/{design.js.j2 => design.js} | 6 +- roles/web-app-jenkins/files/logo.css | 29 ++ .../style.css.j2 => files/style.css} | 33 --- roles/web-app-jenkins/templates/design.js | 37 +++ roles/web-app-jenkins/templates/design.js.j2 | 42 --- .../style.css.j2 => files/style.css} | 0 .../templates/{design.js.j2 => design.js} | 6 +- .../sso_proxy/style.css} | 0 .../templates/{design.js.j2 => design.js} | 4 +- roles/web-app-kix/TODO.md | 2 +- roles/web-app-kix/files/logo.css | 3 + .../style.css.j2 => files/style.css} | 6 - roles/web-app-litellm/templates/style.css.j2 | 42 ++- roles/web-app-littlejs/templates/design.js | 79 +++++ roles/web-app-littlejs/templates/design.js.j2 | 80 ----- roles/web-app-magento/templates/style.css.j2 | 7 +- .../style.css.j2 => files/style.css} | 0 .../templates/{design.js.j2 => design.js} | 4 +- .../templates/{design.js.j2 => design.js} | 4 +- .../style.css.j2 => files/style.css} | 0 .../templates/{design.js.j2 => design.js} | 8 +- .../templates/{design.js.j2 => design.js} | 10 +- .../web-app-mattermost/templates/style.css.j2 | 39 ++- .../style.css.j2 => files/style.css} | 0 .../templates/{design.js.j2 => design.js} | 4 +- roles/web-app-mini-qr/templates/design.js | 38 +++ roles/web-app-mini-qr/templates/design.js.j2 | 39 --- roles/web-app-mini-qr/templates/style.css.j2 | 24 +- .../style.css.j2 => files/style.css} | 0 .../templates/{design.js.j2 => design.js} | 8 +- .../templates/{design.js.j2 => design.js} | 6 +- roles/web-app-n8n/templates/design.js | 72 +++++ roles/web-app-n8n/templates/design.js.j2 | 73 ----- .../templates/{design.js.j2 => design.js} | 10 +- .../files/playwright/test-design.js | 3 +- roles/web-app-openbao/files/logo.css | 10 + .../style.css.j2 => files/style.css} | 13 - roles/web-app-openclaw/templates/style.css.j2 | 21 +- roles/web-app-openproject/files/logo.css | 7 + .../style.css.j2 => files/style.css} | 24 +- .../templates/{design.js.j2 => design.js} | 10 +- roles/web-app-opentalk/files/logo.css | 6 + .../style.css.j2 => files/style.css} | 10 - .../templates/{design.js.j2 => design.js} | 39 ++- .../templates/{design.js.j2 => design.js} | 6 +- .../custom.css.j2 => files/custom.css} | 0 .../templates/{design.js.j2 => design.js} | 6 +- roles/web-app-peertube/templates/env.j2 | 2 +- roles/web-app-peertube/templates/style.css.j2 | 0 roles/web-app-penpot/templates/design.js | 81 ++++++ roles/web-app-penpot/templates/design.js.j2 | 82 ------ roles/web-app-pgadmin/files/logo.css | 7 + roles/web-app-pgadmin/files/style.css | 197 +++++++++++++ .../templates/{design.js.j2 => design.js} | 35 ++- roles/web-app-pgadmin/templates/style.css.j2 | 209 ------------- roles/web-app-pihole/templates/design.js | 59 ++++ roles/web-app-pihole/templates/design.js.j2 | 62 ---- roles/web-app-pihole/templates/style.css.j2 | 5 +- roles/web-app-pixelfed/files/logo.css | 10 + .../style.css.j2 => files/style.css} | 16 +- .../templates/{design.js.j2 => design.js} | 33 +-- roles/web-app-pixelfed/vars/main.yml | 3 + roles/web-app-postmarks/TODO.md | 2 +- roles/web-app-postmarks/files/logo.css | 3 + .../style.css.j2 => files/style.css} | 6 - roles/web-app-postmarks/templates/design.js | 40 +++ .../web-app-postmarks/templates/design.js.j2 | 45 --- roles/web-app-prometheus/templates/design.js | 35 +++ .../web-app-prometheus/templates/design.js.j2 | 36 --- .../web-app-prometheus/templates/style.css.j2 | 35 ++- .../templates/{design.js.j2 => design.js} | 99 +++---- roles/web-app-seaweedfs/files/logo.css | 5 + .../style.css.j2 => files/style.css} | 8 - .../templates/{design.js.j2 => design.js} | 53 ++-- .../web-app-semaphore/templates/style.css.j2 | 275 +++++++++--------- .../custom_css.css} | 0 .../style.css.j2 => files/style.css} | 0 .../templates/{design.js.j2 => design.js} | 10 +- roles/web-app-snipe-it/vars/main.yml | 2 +- roles/web-app-socialhome/files/logo.css | 27 ++ .../style.css.j2 => files/style.css} | 31 -- roles/web-app-stalwart/templates/design.js | 55 ++++ roles/web-app-stalwart/templates/design.js.j2 | 56 ---- .../legacy.css.j2 => files/legacy.css} | 0 roles/web-app-suitecrm/tasks/02_design.yml | 2 +- roles/web-app-suitecrm/vars/main.yml | 2 +- .../style.css.j2 => files/style.css} | 0 roles/web-app-yourls/files/logo.css | 4 + .../style.css.j2 => files/style.css} | 21 +- roles/web-app-yourls/vars/main.yml | 9 + .../templates/{design.js.j2 => design.js} | 29 +- roles/web-svc-libretranslate/files/logo.css | 18 ++ .../style.css.j2 => files/style.css} | 22 -- .../templates/design.js | 59 ++++ .../templates/design.js.j2 | 60 ---- .../jinja/test_no_leaked_jinja_expression.py | 56 ++++ .../test_design_custom_properties.py | 133 +++++++++ .../test_design_script_config_reads.py | 47 +++ .../test_injected_javascript.py | 9 +- 152 files changed, 2002 insertions(+), 1820 deletions(-) create mode 100644 roles/sys-front-inj-design/defaults/main.yml create mode 100644 roles/sys-front-inj-design/templates/css/app.css.j2 create mode 100644 roles/sys-front-inj-design/templates/js/design.js.j2 create mode 100644 roles/web-app-akaunting/files/logo.css rename roles/web-app-akaunting/{templates/style.css.j2 => files/style.css} (99%) create mode 100644 roles/web-app-baserow/files/logo.css rename roles/web-app-baserow/{templates/style.css.j2 => files/style.css} (99%) rename roles/web-app-bigbluebutton/{templates/style.css.j2 => files/style.css} (100%) create mode 100644 roles/web-app-bluesky/files/logo.css rename roles/web-app-bluesky/{templates/style.css.j2 => files/style.css} (79%) create mode 100644 roles/web-app-bluesky/templates/design.js delete mode 100644 roles/web-app-bluesky/templates/design.js.j2 rename roles/web-app-bookwyrm/templates/{design.js.j2 => design.js} (63%) rename roles/web-app-chess/{templates/style.css.j2 => files/style.css} (100%) delete mode 100644 roles/web-app-confluence/templates/style.css.j2 create mode 100644 roles/web-app-decidim/files/logo.css rename roles/web-app-decidim/{templates/style.css.j2 => files/style.css} (99%) rename roles/web-app-discourse/templates/{design.js.j2 => design.js} (58%) delete mode 100644 roles/web-app-discourse/templates/style.css.j2 create mode 100644 roles/web-app-docs/files/logo.css rename roles/web-app-docs/{templates/style.css.j2 => files/style.css} (77%) create mode 100644 roles/web-app-docs/templates/design.js delete mode 100644 roles/web-app-docs/templates/design.js.j2 rename roles/web-app-erpnext/{templates/theme.css.j2 => files/theme.css} (100%) rename roles/web-app-erpnext/templates/{design.js.j2 => design.js} (77%) create mode 100644 roles/web-app-fediwall/templates/design.js delete mode 100644 roles/web-app-fediwall/templates/design.js.j2 rename roles/web-app-fider/templates/{design.js.j2 => design.js} (75%) create mode 100644 roles/web-app-flowise/files/logo.css rename roles/web-app-flowise/{templates/style.css.j2 => files/style.css} (97%) create mode 100644 roles/web-app-flowise/templates/design.js delete mode 100644 roles/web-app-flowise/templates/design.js.j2 rename roles/web-app-funkwhale/{templates/style.css.j2 => files/style.css} (100%) create mode 100644 roles/web-app-funkwhale/templates/design.js delete mode 100644 roles/web-app-funkwhale/templates/design.js.j2 rename roles/web-app-gitea/templates/{design.js.j2 => design.js} (66%) rename roles/web-app-gitlab/templates/{design.js.j2 => design.js} (85%) create mode 100644 roles/web-app-homeassistant/templates/design.js delete mode 100644 roles/web-app-homeassistant/templates/design.js.j2 rename roles/web-app-hugo/templates/{design.js.j2 => design.js} (91%) create mode 100644 roles/web-app-jenkins/files/logo.css rename roles/web-app-jenkins/{templates/style.css.j2 => files/style.css} (87%) create mode 100644 roles/web-app-jenkins/templates/design.js delete mode 100644 roles/web-app-jenkins/templates/design.js.j2 rename roles/web-app-jitsi/{templates/style.css.j2 => files/style.css} (100%) rename roles/web-app-joomla/templates/{design.js.j2 => design.js} (87%) rename roles/web-app-keycloak/{templates/sso_proxy/style.css.j2 => files/sso_proxy/style.css} (100%) rename roles/web-app-keycloak/templates/{design.js.j2 => design.js} (63%) create mode 100644 roles/web-app-kix/files/logo.css rename roles/web-app-kix/{templates/style.css.j2 => files/style.css} (99%) create mode 100644 roles/web-app-littlejs/templates/design.js delete mode 100644 roles/web-app-littlejs/templates/design.js.j2 rename roles/web-app-mailu/{templates/style.css.j2 => files/style.css} (100%) rename roles/web-app-mastodon/templates/{design.js.j2 => design.js} (82%) rename roles/web-app-matomo/templates/{design.js.j2 => design.js} (81%) rename roles/web-app-matrix/{templates/style.css.j2 => files/style.css} (100%) rename roles/web-app-matrix/templates/{design.js.j2 => design.js} (62%) rename roles/web-app-mattermost/templates/{design.js.j2 => design.js} (66%) rename roles/web-app-mediawiki/{templates/style.css.j2 => files/style.css} (100%) rename roles/web-app-mediawiki/templates/{design.js.j2 => design.js} (86%) create mode 100644 roles/web-app-mini-qr/templates/design.js delete mode 100644 roles/web-app-mini-qr/templates/design.js.j2 rename roles/web-app-mobilizon/{templates/style.css.j2 => files/style.css} (100%) rename roles/web-app-mobilizon/templates/{design.js.j2 => design.js} (81%) rename roles/web-app-moodle/templates/{design.js.j2 => design.js} (71%) create mode 100644 roles/web-app-n8n/templates/design.js delete mode 100644 roles/web-app-n8n/templates/design.js.j2 rename roles/web-app-nextcloud/templates/{design.js.j2 => design.js} (68%) create mode 100644 roles/web-app-openbao/files/logo.css rename roles/web-app-openbao/{templates/style.css.j2 => files/style.css} (99%) create mode 100644 roles/web-app-openproject/files/logo.css rename roles/web-app-openproject/{templates/style.css.j2 => files/style.css} (84%) rename roles/web-app-openproject/templates/{design.js.j2 => design.js} (79%) create mode 100644 roles/web-app-opentalk/files/logo.css rename roles/web-app-opentalk/{templates/style.css.j2 => files/style.css} (98%) rename roles/web-app-opentalk/templates/{design.js.j2 => design.js} (51%) rename roles/web-app-openwebui/templates/{design.js.j2 => design.js} (89%) rename roles/web-app-peertube/{templates/custom.css.j2 => files/custom.css} (100%) rename roles/web-app-peertube/templates/{design.js.j2 => design.js} (69%) delete mode 100644 roles/web-app-peertube/templates/style.css.j2 create mode 100644 roles/web-app-penpot/templates/design.js delete mode 100644 roles/web-app-penpot/templates/design.js.j2 create mode 100644 roles/web-app-pgadmin/files/logo.css create mode 100644 roles/web-app-pgadmin/files/style.css rename roles/web-app-pgadmin/templates/{design.js.j2 => design.js} (51%) delete mode 100644 roles/web-app-pgadmin/templates/style.css.j2 create mode 100644 roles/web-app-pihole/templates/design.js delete mode 100644 roles/web-app-pihole/templates/design.js.j2 create mode 100644 roles/web-app-pixelfed/files/logo.css rename roles/web-app-pixelfed/{templates/style.css.j2 => files/style.css} (99%) rename roles/web-app-pixelfed/templates/{design.js.j2 => design.js} (53%) create mode 100644 roles/web-app-postmarks/files/logo.css rename roles/web-app-postmarks/{templates/style.css.j2 => files/style.css} (90%) create mode 100644 roles/web-app-postmarks/templates/design.js delete mode 100644 roles/web-app-postmarks/templates/design.js.j2 create mode 100644 roles/web-app-prometheus/templates/design.js delete mode 100644 roles/web-app-prometheus/templates/design.js.j2 rename roles/web-app-roulette-wheel/templates/{design.js.j2 => design.js} (63%) create mode 100644 roles/web-app-seaweedfs/files/logo.css rename roles/web-app-seaweedfs/{templates/style.css.j2 => files/style.css} (91%) rename roles/web-app-semaphore/templates/{design.js.j2 => design.js} (53%) rename roles/web-app-snipe-it/{templates/custom_css.css.j2 => files/custom_css.css} (100%) rename roles/web-app-snipe-it/{templates/style.css.j2 => files/style.css} (100%) rename roles/web-app-snipe-it/templates/{design.js.j2 => design.js} (76%) create mode 100644 roles/web-app-socialhome/files/logo.css rename roles/web-app-socialhome/{templates/style.css.j2 => files/style.css} (84%) create mode 100644 roles/web-app-stalwart/templates/design.js delete mode 100644 roles/web-app-stalwart/templates/design.js.j2 rename roles/web-app-suitecrm/{templates/legacy.css.j2 => files/legacy.css} (100%) rename roles/web-app-taiga/{templates/style.css.j2 => files/style.css} (100%) create mode 100644 roles/web-app-yourls/files/logo.css rename roles/web-app-yourls/{templates/style.css.j2 => files/style.css} (90%) rename roles/web-app-zammad/templates/{design.js.j2 => design.js} (56%) create mode 100644 roles/web-svc-libretranslate/files/logo.css rename roles/web-svc-libretranslate/{templates/style.css.j2 => files/style.css} (99%) create mode 100644 roles/web-svc-libretranslate/templates/design.js delete mode 100644 roles/web-svc-libretranslate/templates/design.js.j2 create mode 100644 tests/lint/ansible/jinja/test_no_leaked_jinja_expression.py create mode 100644 tests/lint/filesystem/test_design_custom_properties.py create mode 100644 tests/lint/filesystem/test_design_script_config_reads.py diff --git a/.github/PULL_REQUEST_TEMPLATE/server.md b/.github/PULL_REQUEST_TEMPLATE/server.md index 356f707f2c..2f0e6fcebb 100644 --- a/.github/PULL_REQUEST_TEMPLATE/server.md +++ b/.github/PULL_REQUEST_TEMPLATE/server.md @@ -94,7 +94,7 @@ Check the relevant rows and explain intentional omissions in `Additional Notes`. | [ ] | `tasks/main.yml` | Usually | Acts as the role entry point and includes the main task flow. | | [ ] | `templates/compose.yml.j2` | For containerized app roles | Defines the service, volume, environment, port, and network wiring. | | [ ] | `templates/env.j2` | When the app uses environment files | Renders the app environment configuration. | -| [ ] | `templates/style.css.j2` or `files/style.css` | When the role injects custom branding or theming | Defines the role-local CSS overrides that adapt the UI to the repository design system. See [Contributing `style.css`](../../docs/contributing/artefact/files/role/style.css.md). | +| [ ] | `files/style.css` plus optional `files/logo.css`, or `templates/style.css.j2` when it needs Jinja | When the role injects custom branding or theming | Defines the role-local CSS overrides that adapt the UI to the repository design system. See [Contributing `style.css`](../../docs/contributing/artefact/files/role/style.css.md). | | [ ] | `templates/javascript.js.j2` or `files/javascript.js` | When the role injects custom frontend behavior | Defines the role-local JavaScript that adapts UI behavior or integration glue in the browser. See [Contributing `javascript.js`](../../docs/contributing/artefact/files/role/javascript.js.md). | | [ ] | `meta/users.yml` | When the role bootstraps users or identities | Role-local user definitions (file root IS the users map; no `users:` wrapper). | | [ ] | `files/Dockerfile` | When a custom image is required | Provides a custom image build path. Prefer this over `Dockerfile.j2`. | diff --git a/cli/meta/roles/design/__init__.py b/cli/meta/roles/design/__init__.py index b273641c12..efda1cd811 100644 --- a/cli/meta/roles/design/__init__.py +++ b/cli/meta/roles/design/__init__.py @@ -42,6 +42,7 @@ SPEC_FILE = ( ) BASE_PATHS: tuple[str, ...] = ( "roles/sys-front-inj-design/templates/css", + "roles/sys-front-inj-design/templates/js", "utils/design/palette.py", ) UI_PREFIXES: tuple[str, ...] = ("web-app-", "web-svc-") diff --git a/docs/agents/action/design.md b/docs/agents/action/design.md index 4e9eb9ebd9..8d02ac04e1 100644 --- a/docs/agents/action/design.md +++ b/docs/agents/action/design.md @@ -70,10 +70,10 @@ On the operator's order up to four role passes run at the same time on the one s - Bootstrap app: set `bootstrap: true` in the role's `design:` entry to link the shared component mapping. Replace the app's hard-coded colors in the role stylesheet, as [web-app-dashboard](../../../roles/web-app-dashboard/files/style.css) does. - No design of its own: the shared element defaults apply. The role stylesheet only covers what stays hard-coded. 5. Set logo and title through the app's own mechanism from `lookup('design', application_id)`. Declare the slot sizes the app renders in the role's `design:` entry: measure the box the app gives its logo in every place (expanded and collapsed navigation, sign-in page) and size one slot per shape. Where the app shows a symbol plus a wordmark, declare a wide slot, so the generated lockup carries the title next to the logo. A lone symbol in a wide box is a defect. A slot the app shows on brand-colored chrome (a header, sidebar or sign-in background mapped onto `--design-frame`) gets `frame: true`: its text is then rendered in the frame text color. A slot on a page or panel stays without it. -6. An app with its own theme switch ships `templates/design.js.j2` that mirrors the chosen theme into `data-design-theme` on ``. +6. An app with its own theme switch ships `templates/design.js` that mirrors the chosen theme into `data-design-theme` on ``. It reads branding through the injected `INFINITO_DESIGN` object and branches on it at runtime; only a script that needs Jinja stays a `.j2`. 7. Iterate without a further full deploy: - a changed stylesheet or logo: `make design-sync app= variant=0`, - - a changed `design.js.j2`, task, template or `meta/` file: `make compose-role-sync role= variant=0`, which re-runs only the app role against the running stack, + - a changed `design.js`, task, template or `meta/` file: `make compose-role-sync role= variant=0`, which re-runs only the app role against the running stack, - a changed spec or `playwright.env.j2`: add `pw="--grep design: --grep-invert gallery"` to that call. It stages the spec again, renders its `.env` again and runs the design assertions. - a changed spec alone: `make compose-playwright role= pw="--grep design: --grep-invert gallery"`. It reuses the rendered `.env` and also works for a deployed role that a later deploy dropped from the inventory. 8. Write `files/playwright/test-design.js` and register it in `playwright.spec.js`: @@ -130,5 +130,5 @@ On the operator's order up to four role passes run at the same time on the one s - **Plain side of the gallery.** With `before=true`, a view whose "before" side still carries the injected snippets fails with that message. Give the view the URL its document ends on, and reach a page behind a redirect through its URL instead of a click inside `prepare`. - **Negative control without a sync.** For a stylesheet fix, strip the fixed rule from the response with `page.route()` in a temporary copy of the test, watch the assertion fail, then delete the route. The stack stays untouched. - **A deploy that hangs in `Apply state` for `hlth-csp`.** The unit checks every domain on the stack, so the blocked resource can belong to a role of an earlier pass. Read it with `make compose-exec cmd="journalctl -u --no-pager -n 40 -o cat"`, fix that role, and add the test "every image the role stylesheet references is served" of the XWiki design tests to its spec. -- **Apps that walk `document.styleSheets`.** The injected sheets are linked without `crossorigin`, so app code can neither read nor rewrite their rules, and an app that reads `cssRules` unguarded throws on them. Keep the links that way: with readable sheets LibreTranslate rewrites the `prefers-color-scheme` rule of the shared sheet at load and the tokens stop following the system. Shield such an app in the role's design script, as `roles/web-svc-libretranslate/templates/design.js.j2` does, and pin it with the test "the app's theme switch raises no page error and leaves the injected sheets alone". +- **Apps that walk `document.styleSheets`.** The injected sheets are linked without `crossorigin`, so app code can neither read nor rewrite their rules, and an app that reads `cssRules` unguarded throws on them. Keep the links that way: with readable sheets LibreTranslate rewrites the `prefers-color-scheme` rule of the shared sheet at load and the tokens stop following the system. Shield such an app in the role's design script, as `roles/web-svc-libretranslate/templates/design.js` does, and pin it with the test "the app's theme switch raises no page error and leaves the injected sheets alone". - **Gallery links.** An Artifact whose sharing the operator changed can stop accepting updates from the session. Publish a new one, tell the operator that the old link stays on the old state, and update the README link. diff --git a/docs/agents/files/role/style.css.md b/docs/agents/files/role/style.css.md index b4e2ea7377..6b65fc15aa 100644 --- a/docs/agents/files/role/style.css.md +++ b/docs/agents/files/role/style.css.md @@ -19,7 +19,7 @@ For repository wiring, inventory keys, and the generated palette contract, see [ - You MUST map the app's status colors onto `--design-success`, `--design-warning`, `--design-danger` and `--design-info`, and the text on filled status surfaces onto the matching `--design-on-*` token. - You MUST map brand-colored app chrome (sidebar, masthead, top bar) onto `--design-frame`, its text and icons onto `--design-on-frame`, and its hovered and selected entries onto `--design-frame-hover` and `--design-frame-active`. `--design-primary` is the accent of controls and MUST NOT fill a large area. On the frame element you MUST set `--design-focus: var(--design-on-frame)`, and set it back to `var(--design-link)` on a surface the frame hosts (a popup, a menu). - You MUST NOT add your own `prefers-color-scheme` block for colors. The tokens switch with the mode. -- If the app has its own theme switch, you MUST mirror its state onto `` from `templates/design.js.j2` so the tokens follow the app, not only the browser. +- If the app has its own theme switch, you MUST mirror its state onto `` from `templates/design.js` so the tokens follow the app, not only the browser. ## Replace diff --git a/docs/contributing/artefact/files/role/style.css.md b/docs/contributing/artefact/files/role/style.css.md index 7b6c520380..21e25f6ac2 100644 --- a/docs/contributing/artefact/files/role/style.css.md +++ b/docs/contributing/artefact/files/role/style.css.md @@ -7,14 +7,17 @@ For browser-side validation requirements after visible UI changes, see [Playwrig ## `style.css.j2` โš™๏ธ -- A role ships its override as `templates/style.css.j2` or `files/style.css`. +- A role ships its override as `files/style.css` when it needs no Jinja, otherwise as `templates/style.css.j2`. +- Rules that apply only while the role ships a logo go into `files/logo.css`. `sys-front-inj-design` appends that file only when `design.logo` resolves to a path, so the guard lives in one place instead of in every sheet. +- `sys-front-inj-design` renders `templates/css/app.css.j2` ahead of both: a `:root` block declaring `--design-url--`, `--design-url-favicon-ico`, `--design-slot--` and `--design-url-app-` for every entry of the role's `design_css_urls`. A sheet reads the branding through those properties instead of interpolating a URL. +- Those properties reach the composed sheet only, meaning `templates/style.css.j2` or `files/style.css`, plus `files/logo.css`. A sheet the role deploys on its own path never sees them, so reading one there leaves the declaration invalid and the rule silently does nothing. - `sys-front-inj-design` renders it when `services.design.enabled` is enabled. - The shared element styles (`body`, links, buttons, form fields, tables, focus outline) sit in the cascade layer `infinito-design`. `layer.css` is linked first in `` and declares that layer before the app's own stylesheets, so every rule of the app wins over them, layered or not. They only style what the app leaves unstyled. - The app's own configuration outranks the role stylesheet. A theming configuration carries the palette first (Nextcloud takes the primary color, logo, name and slogan via `occ theming:config` and ships no stylesheet), then an in-house theme or custom CSS option. - An in-house theme carries a variable mapping natively (see [web-app-gitea](../../../../../roles/web-app-gitea/templates/theme.css.j2)). The role stylesheet maps the app's CSS variables onto the tokens only for what no in-house option reaches. - The Bootstrap component mapping in `bootstrap.css` is unlayered. A role built on Bootstrap links it by setting `bootstrap: true` in its `design:` entry. Set in `web-svc-design`, the value applies to every role. - A role stylesheet or design script that renders empty counts as absent: nothing is deployed, linked or injected for it. -- A role MAY ship `templates/design.js.j2`. `sys-front-inj-design` collapses it, adds its CSP hash and injects it whenever `services.design.enabled` is enabled, independent of `services.javascript.enabled`. +- A role MAY ship `templates/design.js`, or `templates/design.js.j2` when it needs Jinja. `sys-front-inj-design` prepends the per-app config `var INFINITO_DESIGN = {logo, title, urls, slots}`, collapses the result, adds its CSP hash and injects it whenever `services.design.enabled` is enabled, independent of `services.javascript.enabled`. A static script branches on `INFINITO_DESIGN.logo` and `INFINITO_DESIGN.title` at runtime instead of on Jinja at render time. ## Inventory ๐Ÿ“‹ @@ -56,5 +59,5 @@ The [design_palette](../../../../../plugins/lookup/design_palette.py) lookup der - Every color token also exists as `-rgb` for `rgba()` use. - Scale step `50` sits next to the surface and `950` next to the text in light and dark mode, so a mapping onto the scale follows dark mode without a media query. -- Dark mode follows `prefers-color-scheme`. A role whose app has its own theme switch sets `data-design-theme="light"` or `data-design-theme="dark"` on `` from its `design.js.j2`; the attribute wins over the browser preference. +- Dark mode follows `prefers-color-scheme`. A role whose app has its own theme switch sets `data-design-theme="light"` or `data-design-theme="dark"` on `` from its design script; the attribute wins over the browser preference. - Role CSS MUST use only `--design-*` tokens for colors. Hard-coded colors break the base color override. diff --git a/eslint.config.js b/eslint.config.js index 12b0c0e170..8c3ff1c521 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -9,8 +9,6 @@ module.exports = [ "venv/**", ".venv/**", "**/__pycache__/**", - // Jinja2-templated JS โ€” not valid JS until rendered. - "roles/*/templates/**/*.js", "roles/web-app-bigbluebutton/files/javascript/ep_redis_publisher_index.js", ], }, @@ -29,7 +27,7 @@ module.exports = [ }, }, { - files: ["roles/**/files/**/*.js"], + files: ["roles/**/files/**/*.js", "roles/**/templates/**/*.js"], languageOptions: { ecmaVersion: 2023, sourceType: "commonjs", @@ -40,6 +38,7 @@ module.exports = [ // adding the browser globals avoids a sea of `no-undef` false // positives. ...globals.browser, + INFINITO_DESIGN: "readonly", }, }, rules: { diff --git a/roles/sys-front-inj-design/README.md b/roles/sys-front-inj-design/README.md index 548943cc7b..1d0735b63f 100644 --- a/roles/sys-front-inj-design/README.md +++ b/roles/sys-front-inj-design/README.md @@ -21,7 +21,7 @@ It makes all applications feel like part of the same ecosystem, visually and fun - โ™ฟ **WCAG 2.2 contrast** guaranteed for text, links, controls and status colors - ๐Ÿ“ **Unified CSS Base Configuration** deployment for all NGINX applications - ๐ŸŒ’ **Dark mode** via `prefers-color-scheme` or an app-native switch -- ๐Ÿงฉ **Design script channel** for a role's `design.js.j2` +- ๐Ÿงฉ **Design script channel** for a role's `design.js`, behind the per-app `INFINITO_DESIGN` config - ๐Ÿšซ **No duplication** โ€“ tasks run once per deployment - โฑ๏ธ **Versioning logic** to bust browser cache - ๐ŸŽฏ **Bootstrap override compatibility** diff --git a/roles/sys-front-inj-design/defaults/main.yml b/roles/sys-front-inj-design/defaults/main.yml new file mode 100644 index 0000000000..a970113ea8 --- /dev/null +++ b/roles/sys-front-inj-design/defaults/main.yml @@ -0,0 +1,2 @@ +--- +design_css_urls: {} diff --git a/roles/sys-front-inj-design/tasks/main.yml b/roles/sys-front-inj-design/tasks/main.yml index eb52737ae0..7a4b8ea0c9 100644 --- a/roles/sys-front-inj-design/tasks/main.yml +++ b/roles/sys-front-inj-design/tasks/main.yml @@ -10,7 +10,17 @@ 'files': ['templates/style.css.j2','files/style.css'], 'paths': [app_role_dir] }, errors='ignore') | default('', true) }} - _app_style_css: "{{ (lookup('template', _app_style_src) | trim) if _app_style_src | length > 0 else '' }}" + _app_logo_src: >- + {{ lookup('first_found', { + 'files': ['files/logo.css'], + 'paths': [app_role_dir] + }, errors='ignore') | default('', true) }} + app_body_css: "{{ (lookup('template', _app_style_src) | trim) if _app_style_src | length > 0 else '' }}" + app_logo_css: "{{ (lookup('template', _app_logo_src) | trim) if _app_logo_src | length > 0 else '' }}" + _app_compose_src: "{{ lookup('path_absolute', 'roles', 'sys-front-inj-design', 'templates', 'css', 'app.css.j2') }}" + _app_style_css: >- + {{ (lookup('template', _app_compose_src) | trim) + if (app_body_css ~ app_logo_css) | length > 0 else '' }} set_fact: app_style_src: "{{ _app_style_src }}" app_style_css: "{{ _app_style_css }}" @@ -40,10 +50,14 @@ vars: _design_js_src: >- {{ lookup('first_found', { - 'files': ['templates/design.js.j2'], + 'files': ['templates/design.js.j2','templates/design.js'], 'paths': [lookup('path_absolute', 'roles', application_id)] }, errors='ignore') | default('', true) }} - _design_js: "{{ (lookup('template', _design_js_src) | trim) if _design_js_src | length > 0 else '' }}" + _design_compose_src: "{{ lookup('path_absolute', 'roles', 'sys-front-inj-design', 'templates', 'js', 'design.js.j2') }}" + design_body_js: "{{ (lookup('template', _design_js_src) | trim) if _design_js_src | length > 0 else '' }}" + _design_js: >- + {{ (lookup('template', _design_compose_src) | trim) + if 'INFINITO_DESIGN' in design_body_js else design_body_js }} set_fact: design_js_one_liner: "{{ (_design_js | to_one_liner) if _design_js | length > 0 else '' }}" diff --git a/roles/sys-front-inj-design/templates/css/app.css.j2 b/roles/sys-front-inj-design/templates/css/app.css.j2 new file mode 100644 index 0000000000..fcad32835c --- /dev/null +++ b/roles/sys-front-inj-design/templates/css/app.css.j2 @@ -0,0 +1,20 @@ +{% set design = lookup('design', application_id) %} +:root { + --design-url-favicon-ico: url("{{ design.urls.favicon_ico }}"); +{% for slot, urls in design.urls | dictsort if slot != 'favicon_ico' %} +{% for kind, url in urls | dictsort %} + --design-url-{{ slot }}-{{ kind }}: url("{{ url }}"); +{% endfor %} +{% endfor %} +{% for slot, box in design.slots | dictsort %} + --design-slot-{{ slot }}-width: {{ box.width }}px; + --design-slot-{{ slot }}-height: {{ box.height }}px; +{% endfor %} +{% for name, url in design_css_urls | dictsort %} + --design-url-app-{{ name }}: url("{{ url }}"); +{% endfor %} +} +{{ app_body_css }} +{% if design.logo is string %} +{{ app_logo_css }} +{% endif %} diff --git a/roles/sys-front-inj-design/templates/head_sub.j2 b/roles/sys-front-inj-design/templates/head_sub.j2 index 953bf53393..30991260fb 100644 --- a/roles/sys-front-inj-design/templates/head_sub.j2 +++ b/roles/sys-front-inj-design/templates/head_sub.j2 @@ -4,7 +4,7 @@ {% endfor %} {% if app_style_present | default(false) | bool %} - + {% endif %} {% if design_js_one_liner | length > 0 %} diff --git a/roles/sys-front-inj-design/templates/js/design.js.j2 b/roles/sys-front-inj-design/templates/js/design.js.j2 new file mode 100644 index 0000000000..705f54b8c1 --- /dev/null +++ b/roles/sys-front-inj-design/templates/js/design.js.j2 @@ -0,0 +1,7 @@ +{% set design = lookup('design', application_id) %} +var INFINITO_DESIGN = {{ { + 'logo': design.logo is string, + 'title': design.title if design.title is string else none, + 'urls': design.urls if design.logo is string else {}, +} | to_json }}; +{{ design_body_js }} diff --git a/roles/web-app-akaunting/files/logo.css b/roles/web-app-akaunting/files/logo.css new file mode 100644 index 0000000000..f024e15450 --- /dev/null +++ b/roles/web-app-akaunting/files/logo.css @@ -0,0 +1,3 @@ +img[src*="akaunting-logo-green.svg"] { + content: var(--design-url-logo-svg); +} diff --git a/roles/web-app-akaunting/templates/style.css.j2 b/roles/web-app-akaunting/files/style.css similarity index 99% rename from roles/web-app-akaunting/templates/style.css.j2 rename to roles/web-app-akaunting/files/style.css index c4ad0ac2ab..2dd9ba9762 100644 --- a/roles/web-app-akaunting/templates/style.css.j2 +++ b/roles/web-app-akaunting/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} .material-icons.text-red, .material-icons-outlined.text-red, .material-icons-round.text-red, @@ -963,9 +962,3 @@ body, background-color: var(--design-primary) !important; color: var(--design-on-primary) !important; } -{% if design.logo is string %} - -img[src*="akaunting-logo-green.svg"] { - content: url("{{ design.urls.logo.svg }}"); -} -{% endif %} diff --git a/roles/web-app-baserow/files/logo.css b/roles/web-app-baserow/files/logo.css new file mode 100644 index 0000000000..04fe11cbde --- /dev/null +++ b/roles/web-app-baserow/files/logo.css @@ -0,0 +1,11 @@ +.logo > img { + content: var(--design-url-logo-svg); +} +.auth__logo { + height: 32px; +} +.sidebar--collapsed .sidebar__logo .logo > img { + content: var(--design-url-symbol-svg); + width: 16px; + height: 16px; +} diff --git a/roles/web-app-baserow/templates/style.css.j2 b/roles/web-app-baserow/files/style.css similarity index 99% rename from roles/web-app-baserow/templates/style.css.j2 rename to roles/web-app-baserow/files/style.css index 3b6a7eb1bb..fc77f8cdaa 100644 --- a/roles/web-app-baserow/templates/style.css.j2 +++ b/roles/web-app-baserow/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} a { background-color: rgba(var(--design-text-rgb), 0); } @@ -6390,16 +6389,3 @@ span[data-type=mention] { .api-docs__example-request-type.api-docs__example-request-type--warning { color: var(--design-on-warning); } -{% if design.logo is string %} -.logo > img { - content: url("{{ design.urls.logo.svg }}"); -} -.auth__logo { - height: 32px; -} -.sidebar--collapsed .sidebar__logo .logo > img { - content: url("{{ design.urls.symbol.svg }}"); - width: 16px; - height: 16px; -} -{% endif %} diff --git a/roles/web-app-bigbluebutton/templates/style.css.j2 b/roles/web-app-bigbluebutton/files/style.css similarity index 100% rename from roles/web-app-bigbluebutton/templates/style.css.j2 rename to roles/web-app-bigbluebutton/files/style.css diff --git a/roles/web-app-bluesky/files/logo.css b/roles/web-app-bluesky/files/logo.css new file mode 100644 index 0000000000..e642d53db5 --- /dev/null +++ b/roles/web-app-bluesky/files/logo.css @@ -0,0 +1,9 @@ +svg[viewBox='0 0 64 57'], +#splash svg { + background: var(--design-url-symbol-svg) center / contain no-repeat; +} + +svg[viewBox='0 0 64 57'] path, +#splash svg path { + fill: transparent; +} diff --git a/roles/web-app-bluesky/templates/style.css.j2 b/roles/web-app-bluesky/files/style.css similarity index 79% rename from roles/web-app-bluesky/templates/style.css.j2 rename to roles/web-app-bluesky/files/style.css index 26e83b886a..b28e5a1a02 100644 --- a/roles/web-app-bluesky/templates/style.css.j2 +++ b/roles/web-app-bluesky/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} :root, html.theme--light, html.theme--light body, @@ -51,15 +50,3 @@ svg[data-testid='userAvatarFallback'] [fill='#ffffff' i], svg[data-testid='userAvatarFallback'] [fill='white' i] { fill: var(--design-on-primary); } -{% if design.logo is string %} - -svg[viewBox='0 0 64 57'], -#splash svg { - background: url("{{ design.urls.symbol.svg }}") center / contain no-repeat; -} - -svg[viewBox='0 0 64 57'] path, -#splash svg path { - fill: transparent; -} -{% endif %} diff --git a/roles/web-app-bluesky/templates/design.js b/roles/web-app-bluesky/templates/design.js new file mode 100644 index 0000000000..bef2b7ea26 --- /dev/null +++ b/roles/web-app-bluesky/templates/design.js @@ -0,0 +1,36 @@ +(function () { + const root = document.documentElement; + const prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); + function mirror() { + const match = /(?:^|\s)theme--(light|dark|dim)(?:\s|$)/.exec(root.className); + const mode = match ? (match[1] === "light" ? "light" : "dark") : null; + if (mode === null || mode === (prefersDark.matches ? "dark" : "light")) { + if (root.hasAttribute("data-design-theme")) { + root.removeAttribute("data-design-theme"); + } + } else if (root.getAttribute("data-design-theme") !== mode) { + root.setAttribute("data-design-theme", mode); + } + } + mirror(); + new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["class"] }); + prefersDark.addEventListener("change", function () { + root.removeAttribute("data-design-theme"); + window.setTimeout(mirror, 500); + }); + if (INFINITO_DESIGN.logo) { + function icons() { + const links = document.querySelectorAll("link[rel~='icon'], link[rel='apple-touch-icon']"); + for (let index = 0; index < links.length; index += 1) { + const touch = links[index].getAttribute("rel") === "apple-touch-icon"; + const href = touch ? INFINITO_DESIGN.urls['apple-touch-icon'].png : INFINITO_DESIGN.urls.favicon_ico; + if (links[index].getAttribute("href") !== href) { + links[index].setAttribute("type", touch ? "image/png" : "image/x-icon"); + links[index].setAttribute("href", href); + } + } + } + icons(); + document.addEventListener("DOMContentLoaded", icons); + } +})(); diff --git a/roles/web-app-bluesky/templates/design.js.j2 b/roles/web-app-bluesky/templates/design.js.j2 deleted file mode 100644 index c4b9beea0a..0000000000 --- a/roles/web-app-bluesky/templates/design.js.j2 +++ /dev/null @@ -1,37 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var root = document.documentElement; - var prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); - function mirror() { - var match = /(?:^|\s)theme--(light|dark|dim)(?:\s|$)/.exec(root.className); - var mode = match ? (match[1] === "light" ? "light" : "dark") : null; - if (mode === null || mode === (prefersDark.matches ? "dark" : "light")) { - if (root.hasAttribute("data-design-theme")) { - root.removeAttribute("data-design-theme"); - } - } else if (root.getAttribute("data-design-theme") !== mode) { - root.setAttribute("data-design-theme", mode); - } - } - mirror(); - new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["class"] }); - prefersDark.addEventListener("change", function () { - root.removeAttribute("data-design-theme"); - window.setTimeout(mirror, 500); - }); -{% if design.logo is string %} - function icons() { - var links = document.querySelectorAll("link[rel~='icon'], link[rel='apple-touch-icon']"); - for (var index = 0; index < links.length; index += 1) { - var touch = links[index].getAttribute("rel") === "apple-touch-icon"; - var href = touch ? {{ design.urls['apple-touch-icon'].png | to_json }} : {{ design.urls.favicon_ico | to_json }}; - if (links[index].getAttribute("href") !== href) { - links[index].setAttribute("type", touch ? "image/png" : "image/x-icon"); - links[index].setAttribute("href", href); - } - } - } - icons(); - document.addEventListener("DOMContentLoaded", icons); -{% endif %} -})(); diff --git a/roles/web-app-bookwyrm/templates/design.js.j2 b/roles/web-app-bookwyrm/templates/design.js similarity index 63% rename from roles/web-app-bookwyrm/templates/design.js.j2 rename to roles/web-app-bookwyrm/templates/design.js index 6214fde3b7..7cf940dc86 100644 --- a/roles/web-app-bookwyrm/templates/design.js.j2 +++ b/roles/web-app-bookwyrm/templates/design.js @@ -1,7 +1,7 @@ (function () { - var link = document.querySelector('link[rel="stylesheet"][href*="/css/themes/"]'); - var href = link ? link.getAttribute("href") : ""; - var root = document.documentElement; + const link = document.querySelector('link[rel="stylesheet"][href*="/css/themes/"]'); + const href = link ? link.getAttribute("href") : ""; + const root = document.documentElement; if (href.indexOf("/css/themes/bookwyrm-dark") !== -1) { root.setAttribute("data-design-theme", "dark"); } else if (href.indexOf("/css/themes/bookwyrm-light") !== -1) { diff --git a/roles/web-app-chess/templates/style.css.j2 b/roles/web-app-chess/files/style.css similarity index 100% rename from roles/web-app-chess/templates/style.css.j2 rename to roles/web-app-chess/files/style.css diff --git a/roles/web-app-confluence/templates/style.css.j2 b/roles/web-app-confluence/templates/style.css.j2 deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/roles/web-app-decidim/files/logo.css b/roles/web-app-decidim/files/logo.css new file mode 100644 index 0000000000..8e21bc4148 --- /dev/null +++ b/roles/web-app-decidim/files/logo.css @@ -0,0 +1,3 @@ +.layout-nav .logo img { + content: var(--design-url-icon-png); +} diff --git a/roles/web-app-decidim/templates/style.css.j2 b/roles/web-app-decidim/files/style.css similarity index 99% rename from roles/web-app-decidim/templates/style.css.j2 rename to roles/web-app-decidim/files/style.css index e31930c920..0de017f47a 100644 --- a/roles/web-app-decidim/templates/style.css.j2 +++ b/roles/web-app-decidim/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} *, :before, :after, @@ -3547,9 +3546,3 @@ header .admin-bar__button.is-hover svg, header .admin-bar__button:not([disabled]):not([class*="button__text"]):not(label):hover svg { fill: var(--design-on-frame); } -{% if design.logo %} - -.layout-nav .logo img { - content: url("{{ design.urls.icon.png }}"); -} -{% endif %} diff --git a/roles/web-app-discourse/templates/design.js.j2 b/roles/web-app-discourse/templates/design.js similarity index 58% rename from roles/web-app-discourse/templates/design.js.j2 rename to roles/web-app-discourse/templates/design.js index 44de0c9653..73bfc039af 100644 --- a/roles/web-app-discourse/templates/design.js.j2 +++ b/roles/web-app-discourse/templates/design.js @@ -1,15 +1,15 @@ (function () { - var root = document.documentElement; + const root = document.documentElement; function mirror() { - var light = document.querySelector("link.light-scheme"); - var dark = document.querySelector("link.dark-scheme"); - var mode = null; + const light = document.querySelector("link.light-scheme"); + const dark = document.querySelector("link.dark-scheme"); + let mode = null; if (dark) { if (dark.media === "all") mode = "dark"; else if (dark.media === "none") mode = "light"; } else if (light) { - var meta = document.querySelector('meta[name="color-scheme"]'); + const meta = document.querySelector('meta[name="color-scheme"]'); mode = meta && meta.content.trim() === "dark" ? "dark" : "light"; } if (mode) root.setAttribute("data-design-theme", mode); @@ -18,9 +18,9 @@ function watch() { mirror(); - var links = document.querySelectorAll("link.light-scheme, link.dark-scheme"); - var observer = new MutationObserver(mirror); - for (var i = 0; i < links.length; i += 1) { + const links = document.querySelectorAll("link.light-scheme, link.dark-scheme"); + const observer = new MutationObserver(mirror); + for (let i = 0; i < links.length; i += 1) { observer.observe(links[i], { attributes: true, attributeFilter: ["media"] }); } } diff --git a/roles/web-app-discourse/templates/style.css.j2 b/roles/web-app-discourse/templates/style.css.j2 deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/roles/web-app-docs/files/logo.css b/roles/web-app-docs/files/logo.css new file mode 100644 index 0000000000..8349dba190 --- /dev/null +++ b/roles/web-app-docs/files/logo.css @@ -0,0 +1,6 @@ +img[alt="Logo"][src$="_static/logo.png"] { + content: var(--design-url-icon-svg); +} +.sidebar-logo img { + content: var(--design-url-sidebar-logo-svg); +} diff --git a/roles/web-app-docs/templates/style.css.j2 b/roles/web-app-docs/files/style.css similarity index 77% rename from roles/web-app-docs/templates/style.css.j2 rename to roles/web-app-docs/files/style.css index 59c17ffe7c..95354ed78d 100644 --- a/roles/web-app-docs/templates/style.css.j2 +++ b/roles/web-app-docs/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} :root { --color-background: var(--design-surface-1); --color-foreground: var(--design-text); @@ -26,11 +25,3 @@ img.toggler { filter: invert(var(--design-invert)); } -{% if design.logo is string %} -img[alt="Logo"][src$="_static/logo.png"] { - content: url("{{ design.urls.icon.svg }}"); -} -.sidebar-logo img { - content: url("{{ design.urls['sidebar-logo'].svg }}"); -} -{% endif %} diff --git a/roles/web-app-docs/templates/design.js b/roles/web-app-docs/templates/design.js new file mode 100644 index 0000000000..6541fa0ee9 --- /dev/null +++ b/roles/web-app-docs/templates/design.js @@ -0,0 +1,22 @@ +(function () { + const root = document.documentElement; + function mirror() { + const theme = root.classList.contains("dark") ? "dark" : "light"; + if (root.getAttribute("data-design-theme") !== theme) root.setAttribute("data-design-theme", theme); + } + if (/darkMode/.test(root.getAttribute("x-data") || "")) { + mirror(); + new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["class"] }); + } + if (INFINITO_DESIGN.logo) { + function favicon() { + const link = document.querySelector("link[rel~='icon']"); + if (link) link.setAttribute("href", INFINITO_DESIGN.urls.favicon_ico); + } + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", favicon); + } else { + favicon(); + } + } +})(); diff --git a/roles/web-app-docs/templates/design.js.j2 b/roles/web-app-docs/templates/design.js.j2 deleted file mode 100644 index cc9e5cda58..0000000000 --- a/roles/web-app-docs/templates/design.js.j2 +++ /dev/null @@ -1,23 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var root = document.documentElement; - function mirror() { - var theme = root.classList.contains("dark") ? "dark" : "light"; - if (root.getAttribute("data-design-theme") !== theme) root.setAttribute("data-design-theme", theme); - } - if (/darkMode/.test(root.getAttribute("x-data") || "")) { - mirror(); - new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["class"] }); - } -{% if design.logo is string %} - function favicon() { - var link = document.querySelector("link[rel~='icon']"); - if (link) link.setAttribute("href", "{{ design.urls.favicon_ico }}"); - } - if (document.readyState === "loading") { - document.addEventListener("DOMContentLoaded", favicon); - } else { - favicon(); - } -{% endif %} -})(); diff --git a/roles/web-app-erpnext/templates/theme.css.j2 b/roles/web-app-erpnext/files/theme.css similarity index 100% rename from roles/web-app-erpnext/templates/theme.css.j2 rename to roles/web-app-erpnext/files/theme.css diff --git a/roles/web-app-erpnext/tasks/04_design.yml b/roles/web-app-erpnext/tasks/04_design.yml index dd6f55accd..ba4b2bedfe 100644 --- a/roles/web-app-erpnext/tasks/04_design.yml +++ b/roles/web-app-erpnext/tasks/04_design.yml @@ -13,7 +13,7 @@ DESIGN_TITLE: "{{ ERPNEXT_DESIGN_TITLE }}" DESIGN_LOGO_URL: "{{ ERPNEXT_DESIGN_LOGO_URL }}" DESIGN_FAVICON_URL: "{{ ERPNEXT_DESIGN_FAVICON_URL }}" - DESIGN_THEME_CSS: "{{ lookup('ansible.builtin.template', 'theme.css.j2') if ERPNEXT_DESIGN_ENABLED | bool else '' }}" + DESIGN_THEME_CSS: "{{ lookup('ansible.builtin.file', 'theme.css', rstrip=False) if ERPNEXT_DESIGN_ENABLED | bool else '' }}" register: erpnext_design_apply changed_when: "'DESIGN_CHANGED' in erpnext_design_apply.stdout" timeout: "{{ lookup('timeout', 60) | int }}" diff --git a/roles/web-app-erpnext/templates/design.js.j2 b/roles/web-app-erpnext/templates/design.js similarity index 77% rename from roles/web-app-erpnext/templates/design.js.j2 rename to roles/web-app-erpnext/templates/design.js index 4d714584cc..39b831cc60 100644 --- a/roles/web-app-erpnext/templates/design.js.j2 +++ b/roles/web-app-erpnext/templates/design.js @@ -1,7 +1,7 @@ (function () { - var root = document.documentElement; + const root = document.documentElement; function mirror() { - var mode = root.getAttribute("data-theme-mode"); + const mode = root.getAttribute("data-theme-mode"); if (mode === "light" || mode === "dark") { root.setAttribute("data-design-theme", mode); } else { diff --git a/roles/web-app-fediwall/templates/design.js b/roles/web-app-fediwall/templates/design.js new file mode 100644 index 0000000000..15385010f4 --- /dev/null +++ b/roles/web-app-fediwall/templates/design.js @@ -0,0 +1,30 @@ +(function () { + const root = document.documentElement; + const prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); + function mirror() { + const theme = root.getAttribute("data-bs-theme"); + const explicit = theme === "light" || theme === "dark"; + if (explicit && (theme === "dark") !== prefersDark.matches) { + root.setAttribute("data-design-theme", theme); + } else { + root.removeAttribute("data-design-theme"); + } + } + new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["data-bs-theme"] }); + prefersDark.addEventListener("change", mirror); + mirror(); + if (INFINITO_DESIGN.logo) { + const icons = { + "image/png": INFINITO_DESIGN.urls.favicon.png, + "image/svg+xml": INFINITO_DESIGN.urls.favicon.svg, + "image/vnd.microsoft.icon": INFINITO_DESIGN.urls.favicon_ico + }; + const links = document.querySelectorAll("link[rel~='icon']"); + for (let index = 0; index < links.length; index += 1) { + const href = icons[links[index].getAttribute("type")] || icons["image/vnd.microsoft.icon"]; + if (links[index].getAttribute("href") !== href) { + links[index].setAttribute("href", href); + } + } + } +})(); diff --git a/roles/web-app-fediwall/templates/design.js.j2 b/roles/web-app-fediwall/templates/design.js.j2 deleted file mode 100644 index 3eb04b4ca2..0000000000 --- a/roles/web-app-fediwall/templates/design.js.j2 +++ /dev/null @@ -1,31 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var root = document.documentElement; - var prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); - function mirror() { - var theme = root.getAttribute("data-bs-theme"); - var explicit = theme === "light" || theme === "dark"; - if (explicit && (theme === "dark") !== prefersDark.matches) { - root.setAttribute("data-design-theme", theme); - } else { - root.removeAttribute("data-design-theme"); - } - } - new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["data-bs-theme"] }); - prefersDark.addEventListener("change", mirror); - mirror(); -{% if design.logo is string %} - var icons = { - "image/png": {{ design.urls.favicon.png | to_json }}, - "image/svg+xml": {{ design.urls.favicon.svg | to_json }}, - "image/vnd.microsoft.icon": {{ design.urls.favicon_ico | to_json }} - }; - var links = document.querySelectorAll("link[rel~='icon']"); - for (var index = 0; index < links.length; index += 1) { - var href = icons[links[index].getAttribute("type")] || icons["image/vnd.microsoft.icon"]; - if (links[index].getAttribute("href") !== href) { - links[index].setAttribute("href", href); - } - } -{% endif %} -})(); diff --git a/roles/web-app-fider/templates/design.js.j2 b/roles/web-app-fider/templates/design.js similarity index 75% rename from roles/web-app-fider/templates/design.js.j2 rename to roles/web-app-fider/templates/design.js index 0ead899f6a..1315bd0ac6 100644 --- a/roles/web-app-fider/templates/design.js.j2 +++ b/roles/web-app-fider/templates/design.js @@ -1,19 +1,19 @@ (function () { - var root = document.documentElement; - var media = window.matchMedia("(prefers-color-scheme: dark)"); - var THEME = "theme"; - var CHOSEN = "infinito-design-theme-chosen"; + const root = document.documentElement; + const media = window.matchMedia("(prefers-color-scheme: dark)"); + const THEME = "theme"; + const CHOSEN = "infinito-design-theme-chosen"; function read(key) { try { return window.localStorage.getItem(key); - } catch (error) { + } catch { return null; } } function write(key, value) { try { window.localStorage.setItem(key, value); - } catch (error) { + } catch { return; } } @@ -21,9 +21,9 @@ return media.matches ? "dark" : "light"; } function sync() { - var body = document.body; + const body = document.body; if (read(CHOSEN) === "1") { - var mode = (body && body.getAttribute("data-theme")) || read(THEME); + const mode = (body && body.getAttribute("data-theme")) || read(THEME); if (mode === "light" || mode === "dark") root.setAttribute("data-design-theme", mode); return; } @@ -35,7 +35,7 @@ sync(); new MutationObserver(sync).observe(document.body, { attributes: true, attributeFilter: ["data-theme"] }); } - var requested = new URLSearchParams(window.location.search).get("theme"); + const requested = new URLSearchParams(window.location.search).get("theme"); if (requested === "light" || requested === "dark") write(CHOSEN, "1"); sync(); document.addEventListener( diff --git a/roles/web-app-flowise/files/logo.css b/roles/web-app-flowise/files/logo.css new file mode 100644 index 0000000000..b432d4ccd3 --- /dev/null +++ b/roles/web-app-flowise/files/logo.css @@ -0,0 +1,3 @@ +img[alt="Flowise"] { + content: var(--design-url-brand-svg); +} diff --git a/roles/web-app-flowise/templates/style.css.j2 b/roles/web-app-flowise/files/style.css similarity index 97% rename from roles/web-app-flowise/templates/style.css.j2 rename to roles/web-app-flowise/files/style.css index 1e95dabd6f..f6e4008fbb 100644 --- a/roles/web-app-flowise/templates/style.css.j2 +++ b/roles/web-app-flowise/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} html body { background-color: var(--design-surface-1); color: var(--design-text); @@ -334,9 +333,3 @@ a[href="https://github.com/FlowiseAI/Flowise"] .MuiTypography-root { max-width: 100%; } } -{% if design.logo is string %} - -img[alt="Flowise"] { - content: url("{{ design.urls.brand.svg }}"); -} -{% endif %} diff --git a/roles/web-app-flowise/templates/design.js b/roles/web-app-flowise/templates/design.js new file mode 100644 index 0000000000..c402ef31ec --- /dev/null +++ b/roles/web-app-flowise/templates/design.js @@ -0,0 +1,81 @@ +(function () { + const KEY = "isDarkMode"; + const SEED = "infinito-design-seeded-dark-mode"; + const root = document.documentElement; + function read(name) { + try { + return window.localStorage.getItem(name); + } catch { + return null; + } + } + function write(name, value) { + try { + if (value === null) { + window.localStorage.removeItem(name); + } else { + window.localStorage.setItem(name, value); + } + } catch { + return; + } + } + function boot() { + const stored = read(KEY); + const seeded = read(SEED); + if (stored === null || stored === seeded) { + const value = window.matchMedia("(prefers-color-scheme: dark)").matches ? "true" : "false"; + write(KEY, value); + write(SEED, value); + root.removeAttribute("data-design-theme"); + return; + } + write(SEED, null); + root.setAttribute("data-design-theme", stored === "true" ? "dark" : "light"); + } + function picked(event) { + if (!event.target.closest || !event.target.closest(".MuiAppBar-root .MuiSwitch-root")) { + return; + } + window.setTimeout(function () { + write(SEED, null); + root.setAttribute("data-design-theme", read(KEY) === "true" ? "dark" : "light"); + }, 0); + } + boot(); + document.addEventListener("change", picked, true); + if (INFINITO_DESIGN.title) { + const title = INFINITO_DESIGN.title; + function brandTitle() { + if (document.title !== title) { + document.title = title; + } + } + function watchTitle() { + const element = document.querySelector("title"); + if (!element) { + return false; + } + new MutationObserver(brandTitle).observe(element, { childList: true, characterData: true, subtree: true }); + brandTitle(); + return true; + } + if (!watchTitle()) { + document.addEventListener("DOMContentLoaded", watchTitle); + } + } + if (INFINITO_DESIGN.logo) { + function brandIcon() { + const icons = document.querySelectorAll("link[rel~='icon']"); + for (let index = 0; index < icons.length; index += 1) { + if (icons[index].getAttribute("href") !== INFINITO_DESIGN.urls.favicon_ico) { + icons[index].setAttribute("type", "image/x-icon"); + icons[index].setAttribute("href", INFINITO_DESIGN.urls.favicon_ico); + } + } + } + new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); + brandIcon(); + document.addEventListener("DOMContentLoaded", brandIcon); + } +})(); diff --git a/roles/web-app-flowise/templates/design.js.j2 b/roles/web-app-flowise/templates/design.js.j2 deleted file mode 100644 index 0c5e130291..0000000000 --- a/roles/web-app-flowise/templates/design.js.j2 +++ /dev/null @@ -1,82 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var KEY = "isDarkMode"; - var SEED = "infinito-design-seeded-dark-mode"; - var root = document.documentElement; - function read(name) { - try { - return window.localStorage.getItem(name); - } catch (error) { - return null; - } - } - function write(name, value) { - try { - if (value === null) { - window.localStorage.removeItem(name); - } else { - window.localStorage.setItem(name, value); - } - } catch (error) { - return; - } - } - function boot() { - var stored = read(KEY); - var seeded = read(SEED); - if (stored === null || stored === seeded) { - var value = window.matchMedia("(prefers-color-scheme: dark)").matches ? "true" : "false"; - write(KEY, value); - write(SEED, value); - root.removeAttribute("data-design-theme"); - return; - } - write(SEED, null); - root.setAttribute("data-design-theme", stored === "true" ? "dark" : "light"); - } - function picked(event) { - if (!event.target.closest || !event.target.closest(".MuiAppBar-root .MuiSwitch-root")) { - return; - } - window.setTimeout(function () { - write(SEED, null); - root.setAttribute("data-design-theme", read(KEY) === "true" ? "dark" : "light"); - }, 0); - } - boot(); - document.addEventListener("change", picked, true); -{% if design.title is string %} - var title = {{ design.title | to_json }}; - function brandTitle() { - if (document.title !== title) { - document.title = title; - } - } - function watchTitle() { - var element = document.querySelector("title"); - if (!element) { - return false; - } - new MutationObserver(brandTitle).observe(element, { childList: true, characterData: true, subtree: true }); - brandTitle(); - return true; - } - if (!watchTitle()) { - document.addEventListener("DOMContentLoaded", watchTitle); - } -{% endif %} -{% if design.logo is string %} - function brandIcon() { - var icons = document.querySelectorAll("link[rel~='icon']"); - for (var index = 0; index < icons.length; index += 1) { - if (icons[index].getAttribute("href") !== {{ design.urls.favicon_ico | to_json }}) { - icons[index].setAttribute("type", "image/x-icon"); - icons[index].setAttribute("href", {{ design.urls.favicon_ico | to_json }}); - } - } - } - new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); - brandIcon(); - document.addEventListener("DOMContentLoaded", brandIcon); -{% endif %} -})(); diff --git a/roles/web-app-funkwhale/templates/style.css.j2 b/roles/web-app-funkwhale/files/style.css similarity index 100% rename from roles/web-app-funkwhale/templates/style.css.j2 rename to roles/web-app-funkwhale/files/style.css diff --git a/roles/web-app-funkwhale/templates/design.js b/roles/web-app-funkwhale/templates/design.js new file mode 100644 index 0000000000..8f4aa5923f --- /dev/null +++ b/roles/web-app-funkwhale/templates/design.js @@ -0,0 +1,47 @@ +(function () { + const root = document.documentElement; + function mirror() { + const body = document.body; + const admin = root.getAttribute("data-theme"); + if (body && body.classList.contains("theme-dark")) { + root.setAttribute("data-design-theme", "dark"); + } else if (body && body.classList.contains("theme-light")) { + root.setAttribute("data-design-theme", "light"); + } else if (admin === "dark" || admin === "light") { + root.setAttribute("data-design-theme", admin); + } else { + root.removeAttribute("data-design-theme"); + } + } + function watchBody() { + new MutationObserver(mirror).observe(document.body, { attributes: true, attributeFilter: ["class"] }); + mirror(); + } + new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["data-theme"] }); + mirror(); + if (document.body) { + watchBody(); + } else { + document.addEventListener("DOMContentLoaded", watchBody); + } + if (INFINITO_DESIGN.logo) { + const icons = { + icon: INFINITO_DESIGN.urls.favicon_ico, + "apple-touch-icon": INFINITO_DESIGN.urls['apple-touch-icon'].png + }; + function brandIcons() { + const links = document.head.querySelectorAll("link[rel~='icon'], link[rel='apple-touch-icon']"); + for (let index = 0; index < links.length; index += 1) { + const link = links[index]; + const href = link.getAttribute("rel") === "apple-touch-icon" ? icons["apple-touch-icon"] : icons.icon; + if (link.getAttribute("href") !== href) { + link.removeAttribute("sizes"); + link.setAttribute("type", link.getAttribute("rel") === "apple-touch-icon" ? "image/png" : "image/x-icon"); + link.setAttribute("href", href); + } + } + } + new MutationObserver(brandIcons).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); + brandIcons(); + } +})(); diff --git a/roles/web-app-funkwhale/templates/design.js.j2 b/roles/web-app-funkwhale/templates/design.js.j2 deleted file mode 100644 index 4c5c799d89..0000000000 --- a/roles/web-app-funkwhale/templates/design.js.j2 +++ /dev/null @@ -1,48 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var root = document.documentElement; - function mirror() { - var body = document.body; - var admin = root.getAttribute("data-theme"); - if (body && body.classList.contains("theme-dark")) { - root.setAttribute("data-design-theme", "dark"); - } else if (body && body.classList.contains("theme-light")) { - root.setAttribute("data-design-theme", "light"); - } else if (admin === "dark" || admin === "light") { - root.setAttribute("data-design-theme", admin); - } else { - root.removeAttribute("data-design-theme"); - } - } - function watchBody() { - new MutationObserver(mirror).observe(document.body, { attributes: true, attributeFilter: ["class"] }); - mirror(); - } - new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["data-theme"] }); - mirror(); - if (document.body) { - watchBody(); - } else { - document.addEventListener("DOMContentLoaded", watchBody); - } -{% if design.logo is string %} - var icons = { - icon: {{ design.urls.favicon_ico | to_json }}, - "apple-touch-icon": {{ design.urls['apple-touch-icon'].png | to_json }} - }; - function brandIcons() { - var links = document.head.querySelectorAll("link[rel~='icon'], link[rel='apple-touch-icon']"); - for (var index = 0; index < links.length; index += 1) { - var link = links[index]; - var href = link.getAttribute("rel") === "apple-touch-icon" ? icons["apple-touch-icon"] : icons.icon; - if (link.getAttribute("href") !== href) { - link.removeAttribute("sizes"); - link.setAttribute("type", link.getAttribute("rel") === "apple-touch-icon" ? "image/png" : "image/x-icon"); - link.setAttribute("href", href); - } - } - } - new MutationObserver(brandIcons).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); - brandIcons(); -{% endif %} -})(); diff --git a/roles/web-app-gitea/templates/design.js.j2 b/roles/web-app-gitea/templates/design.js similarity index 66% rename from roles/web-app-gitea/templates/design.js.j2 rename to roles/web-app-gitea/templates/design.js index 9afca80d97..097d47c34d 100644 --- a/roles/web-app-gitea/templates/design.js.j2 +++ b/roles/web-app-gitea/templates/design.js @@ -1,6 +1,6 @@ (function () { - var root = document.documentElement; - var theme = root.getAttribute("data-theme") || ""; + const root = document.documentElement; + const theme = root.getAttribute("data-theme") || ""; if (/dark/.test(theme)) { root.setAttribute("data-design-theme", "dark"); } else if (/light/.test(theme)) { diff --git a/roles/web-app-gitlab/templates/design.js.j2 b/roles/web-app-gitlab/templates/design.js similarity index 85% rename from roles/web-app-gitlab/templates/design.js.j2 rename to roles/web-app-gitlab/templates/design.js index 673f8475ae..f96755bbbc 100644 --- a/roles/web-app-gitlab/templates/design.js.j2 +++ b/roles/web-app-gitlab/templates/design.js @@ -1,7 +1,7 @@ (function () { - var root = document.documentElement; + const root = document.documentElement; function chosen() { - var classes = root.classList; + const classes = root.classList; if (classes.contains("gl-system")) { return null; } @@ -11,7 +11,7 @@ return classes.contains("gl-light") ? "light" : null; } function mirror() { - var theme = chosen(); + const theme = chosen(); if (theme) { if (root.getAttribute("data-design-theme") !== theme) { root.setAttribute("data-design-theme", theme); diff --git a/roles/web-app-hermes/templates/dashboard-theme.css.j2 b/roles/web-app-hermes/templates/dashboard-theme.css.j2 index e7c12d9fd5..e39de4e685 100644 --- a/roles/web-app-hermes/templates/dashboard-theme.css.j2 +++ b/roles/web-app-hermes/templates/dashboard-theme.css.j2 @@ -1,5 +1,4 @@ {% set design = lookup('design', application_id) %} -{% set primary_button = '[class~="bg-midground"][class~="text-background-base"]:not(:disabled)' %} {% set statuses = [ { 'token': 'danger', @@ -94,15 +93,15 @@ a[class~="text-primary"] { background-color: var(--design-surface-active); filter: none; } -{{ primary_button }} { +[class~="bg-midground"][class~="text-background-base"]:not(:disabled) { --tw-shadow: 0 0 transparent; background-color: var(--design-primary); color: var(--design-on-primary); } -{{ primary_button }}:hover { +[class~="bg-midground"][class~="text-background-base"]:not(:disabled):hover { background-color: var(--design-primary-hover); } -{{ primary_button }}:active { +[class~="bg-midground"][class~="text-background-base"]:not(:disabled):active { background-color: var(--design-primary-active); filter: none; } diff --git a/roles/web-app-hermes/templates/style.css.j2 b/roles/web-app-hermes/templates/style.css.j2 index 02f1ce9d21..25decc1131 100644 --- a/roles/web-app-hermes/templates/style.css.j2 +++ b/roles/web-app-hermes/templates/style.css.j2 @@ -1,7 +1,6 @@ {% if lookup('config', application_id, 'services.webui.enabled') | bool %} {% set design = lookup('design', application_id) %} -{% set sign_in = ':root:has(.provider-list)' %} -{{ sign_in }} { +:root:has(.provider-list) { --background: var(--design-surface-1); --background-base: var(--design-surface-1); --midground: var(--design-link); @@ -9,41 +8,41 @@ --hairline: var(--design-border); --hairline-strong: var(--design-border-strong); } -{{ sign_in }} body { +:root:has(.provider-list) body { background-image: none; } -{{ sign_in }} :is(.card, .field-input) { +:root:has(.provider-list) :is(.card, .field-input) { background: var(--design-surface-2); } -{{ sign_in }} .card { +:root:has(.provider-list) .card { box-shadow: var(--design-shadow-3); } -{{ sign_in }} :is(.subtitle, .form-title, .field-label, footer) { +:root:has(.provider-list) :is(.subtitle, .form-title, .field-label, footer) { color: var(--design-text-muted); } -{{ sign_in }} .form-error { +:root:has(.provider-list) .form-error { color: var(--design-danger); } -{{ sign_in }} .provider-btn { +:root:has(.provider-list) .provider-btn { background: var(--design-primary); color: var(--design-on-primary); box-shadow: none; } -{{ sign_in }} .provider-btn:hover { +:root:has(.provider-list) .provider-btn:hover { background: var(--design-primary-hover); filter: none; } -{{ sign_in }} .provider-btn:active { +:root:has(.provider-list) .provider-btn:active { background: var(--design-primary-active); filter: none; } {% if design.logo is string %} -{{ sign_in }} .brand { +:root:has(.provider-list) .brand { height: 3rem; font-size: 0; background: url("{{ design.urls.brand.svg }}") center / contain no-repeat; } -{{ sign_in }} .brand .dot { +:root:has(.provider-list) .brand .dot { display: none; } {% endif %} diff --git a/roles/web-app-homeassistant/README.md b/roles/web-app-homeassistant/README.md index ec2d4c890f..30769750f3 100644 --- a/roles/web-app-homeassistant/README.md +++ b/roles/web-app-homeassistant/README.md @@ -15,7 +15,7 @@ This role deploys Home Assistant as a container on its own canonical domain behi - **Persistent configuration:** Mounts `/config` as a named volume and hands it to the container backup service when volume backups are part of the deployment. - **Owner provisioned on every deploy:** Once the hub answers, the deploy runs `files/python/provision.py` inside the container with `HA_OWNER_ONLY=1`. On a fresh hub the script creates the owner from the platform administrator's username and `credentials.administrator_password`, names the hub after the corporate design title when the design service is on, and closes the remaining onboarding steps. On every later deploy it signs in with the same credentials and reports no change. When the hub refuses them, the deploy writes the password into the hub's auth store with Home Assistant's `auth` script, restarts the hub and signs in again. Both calls receive their values on standard input. - **Closed onboarding wizard:** A Playwright spec asserts that every onboarding step is done and that `/onboarding.html` hands a visitor over to the sign-in page. -- **Corporate design:** With the design service on, `configuration.yaml` carries a theme whose variables point at the design tokens, and a start-up automation selects it as the default theme for light and dark mode. The sign-in page takes the same variables from the role stylesheet; logo, favicon and page title come from the design assets through the stylesheet and `templates/design.js.j2`. A theme or mode picked in the profile keeps its own palette, and the script mirrors the picked mode onto the design tokens. +- **Corporate design:** With the design service on, `configuration.yaml` carries a theme whose variables point at the design tokens, and a start-up automation selects it as the default theme for light and dark mode. The sign-in page takes the same variables from the role stylesheet; logo, favicon and page title come from the design assets through the stylesheet and `templates/design.js`. A theme or mode picked in the profile keeps its own palette, and the script mirrors the picked mode onto the design tokens. - **MCP server contract:** Declares the built-in MCP server at `/api/mcp` over streamable HTTP as an internal, bearer-token-authenticated endpoint, and generates the token that MCP clients present. Adding the MCP Server integration itself stays a Home Assistant onboarding step. - **Token verified against the hub:** Every deploy asks the hub whether the stored token still authenticates and re-mints it when the hub rejects it, then fails the deploy if the fresh token is rejected too. A hub whose `.storage/auth` was recreated leaves a stored token pointing at a deleted refresh token, and clients would receive a 401 on every call. - **Two-layer tool policy:** Home Assistant offers no per-tool filter of its own; enabling the Assist API always publishes its actuating intents (`HassTurnOn`, `HassTurnOff`, the todo-list writers). The role names those in `tools.mutating`, and `mutating_tools_enabled: false` withholds them from every client's include list, so an agent is offered the read tools only. Entity exposure bounds the rest: the role exposes no entity to Assist, and making the hub actuate anything is an explicit operator step per entity. diff --git a/roles/web-app-homeassistant/templates/design.js b/roles/web-app-homeassistant/templates/design.js new file mode 100644 index 0000000000..c760bdb52d --- /dev/null +++ b/roles/web-app-homeassistant/templates/design.js @@ -0,0 +1,77 @@ +(function () { + const root = document.documentElement; + const prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); + if (INFINITO_DESIGN.title) { + const title = INFINITO_DESIGN.title; + const product = "Home Assistant"; + function brandTitle() { + if (document.title.indexOf(title) === -1 && document.title.indexOf(product) !== -1) { + document.title = document.title.split(product).join(title); + } + } + function watchTitle() { + const element = document.querySelector("title"); + if (!element) { + return false; + } + new MutationObserver(brandTitle).observe(element, { childList: true, characterData: true, subtree: true }); + brandTitle(); + return true; + } + if (!watchTitle()) { + document.addEventListener("DOMContentLoaded", watchTitle); + } + } + if (INFINITO_DESIGN.logo) { + function brandIcons() { + const icon = document.querySelector("link[rel='icon']") || document.head.appendChild(document.createElement("link")); + icon.rel = "icon"; + icon.type = "image/x-icon"; + icon.href = INFINITO_DESIGN.urls.favicon_ico; + const touch = document.querySelector("link[rel='apple-touch-icon']"); + if (touch) { + touch.href = INFINITO_DESIGN.urls['apple-touch-icon'].png; + } + } + brandIcons(); + document.addEventListener("DOMContentLoaded", brandIcons); + } + const visitor = /^\/(onboarding\.html|auth\/)/.test(window.location.pathname); + function storedMode() { + if (visitor) { + return undefined; + } + try { + const selected = JSON.parse(window.localStorage.getItem("selectedTheme")); + return selected ? selected.dark : undefined; + } catch { + return undefined; + } + } + function applyMode(dark) { + if (typeof dark === "boolean" && dark !== prefersDark.matches) { + root.setAttribute("data-design-theme", dark ? "dark" : "light"); + } else { + root.removeAttribute("data-design-theme"); + } + } + function mirrorMode() { + const app = document.querySelector("home-assistant"); + const themes = app && app.hass && app.hass.themes; + applyMode(themes && typeof themes.darkMode === "boolean" ? themes.darkMode : storedMode()); + } + window.addEventListener( + "settheme", + function (event) { + if (event.detail && "dark" in event.detail) { + applyMode(event.detail.dark); + } + }, + true + ); + prefersDark.addEventListener("change", function () { + applyMode(storedMode()); + }); + new MutationObserver(mirrorMode).observe(root, { attributes: true, attributeFilter: ["style"] }); + mirrorMode(); +})(); diff --git a/roles/web-app-homeassistant/templates/design.js.j2 b/roles/web-app-homeassistant/templates/design.js.j2 deleted file mode 100644 index ac21c35f98..0000000000 --- a/roles/web-app-homeassistant/templates/design.js.j2 +++ /dev/null @@ -1,78 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var root = document.documentElement; - var prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); -{% if design.title is string %} - var title = {{ design.title | to_json }}; - var product = "Home Assistant"; - function brandTitle() { - if (document.title.indexOf(title) === -1 && document.title.indexOf(product) !== -1) { - document.title = document.title.split(product).join(title); - } - } - function watchTitle() { - var element = document.querySelector("title"); - if (!element) { - return false; - } - new MutationObserver(brandTitle).observe(element, { childList: true, characterData: true, subtree: true }); - brandTitle(); - return true; - } - if (!watchTitle()) { - document.addEventListener("DOMContentLoaded", watchTitle); - } -{% endif %} -{% if design.logo is string %} - function brandIcons() { - var icon = document.querySelector("link[rel='icon']") || document.head.appendChild(document.createElement("link")); - icon.rel = "icon"; - icon.type = "image/x-icon"; - icon.href = {{ design.urls.favicon_ico | to_json }}; - var touch = document.querySelector("link[rel='apple-touch-icon']"); - if (touch) { - touch.href = {{ design.urls['apple-touch-icon'].png | to_json }}; - } - } - brandIcons(); - document.addEventListener("DOMContentLoaded", brandIcons); -{% endif %} - var visitor = /^\/(onboarding\.html|auth\/)/.test(window.location.pathname); - function storedMode() { - if (visitor) { - return undefined; - } - try { - var selected = JSON.parse(window.localStorage.getItem("selectedTheme")); - return selected ? selected.dark : undefined; - } catch (error) { - return undefined; - } - } - function applyMode(dark) { - if (typeof dark === "boolean" && dark !== prefersDark.matches) { - root.setAttribute("data-design-theme", dark ? "dark" : "light"); - } else { - root.removeAttribute("data-design-theme"); - } - } - function mirrorMode() { - var app = document.querySelector("home-assistant"); - var themes = app && app.hass && app.hass.themes; - applyMode(themes && typeof themes.darkMode === "boolean" ? themes.darkMode : storedMode()); - } - window.addEventListener( - "settheme", - function (event) { - if (event.detail && "dark" in event.detail) { - applyMode(event.detail.dark); - } - }, - true - ); - prefersDark.addEventListener("change", function () { - applyMode(storedMode()); - }); - new MutationObserver(mirrorMode).observe(root, { attributes: true, attributeFilter: ["style"] }); - mirrorMode(); -})(); diff --git a/roles/web-app-homeassistant/templates/style.css.j2 b/roles/web-app-homeassistant/templates/style.css.j2 index 8fea095a19..bfaca366a2 100644 --- a/roles/web-app-homeassistant/templates/style.css.j2 +++ b/roles/web-app-homeassistant/templates/style.css.j2 @@ -1,10 +1,9 @@ {% set design = lookup('design', application_id) %} -{% set sign_in = ':root:has(ha-authorize)' %} -{{ sign_in }} { +:root:has(ha-authorize) { background-color: var(--design-surface-1); color: var(--design-text); } -{{ sign_in }} body { +:root:has(ha-authorize) body { {% for name, value in HOMEASSISTANT_DESIGN_VARIABLES | dictsort %} --{{ name }}: {{ value }}; {% endfor %} @@ -31,7 +30,7 @@ --wa-form-control-placeholder-color: var(--ha-color-text-secondary); } {% if design.logo is string %} -{{ sign_in }} .header img { +:root:has(ha-authorize) .header img { content: url("{{ design.urls.logo.svg }}"); } {% endif %} diff --git a/roles/web-app-hugo/templates/design.js.j2 b/roles/web-app-hugo/templates/design.js similarity index 91% rename from roles/web-app-hugo/templates/design.js.j2 rename to roles/web-app-hugo/templates/design.js index 5f1a8d91d9..f6eec2b059 100644 --- a/roles/web-app-hugo/templates/design.js.j2 +++ b/roles/web-app-hugo/templates/design.js @@ -1,14 +1,14 @@ (function () { - var root = document.documentElement; + const root = document.documentElement; function chosenScheme() { try { return JSON.parse(window.localStorage.getItem("hugoDocsUserSettings") || "{}").colorScheme; - } catch (error) { + } catch { return 0; } } function mirror() { - var chosen = chosenScheme(); + const chosen = chosenScheme(); if (chosen === 2) { root.setAttribute("data-design-theme", "light"); } else if (chosen === 3) { diff --git a/roles/web-app-jenkins/files/logo.css b/roles/web-app-jenkins/files/logo.css new file mode 100644 index 0000000000..76467069e7 --- /dev/null +++ b/roles/web-app-jenkins/files/logo.css @@ -0,0 +1,29 @@ +.app-branding .app-branding__conic img { + content: var(--design-url-branding-svg); +} + +.app-sign-in-register__content-logo { + content: var(--design-url-icon-svg); +} + +.jenkins-header .app-jenkins-logo #jenkins-head-icon { + content: var(--design-url-masthead-svg); + width: auto; + height: 2.25rem; +} + +.jenkins-header .app-jenkins-logo span { + position: absolute; + width: 1px; + height: 1px; + overflow: hidden; + clip-path: inset(50%); + white-space: nowrap; +} + +@media (width <= 767px) { + .jenkins-header .app-jenkins-logo #jenkins-head-icon { + content: var(--design-url-icon-svg); + height: 2rem; + } +} diff --git a/roles/web-app-jenkins/templates/style.css.j2 b/roles/web-app-jenkins/files/style.css similarity index 87% rename from roles/web-app-jenkins/templates/style.css.j2 rename to roles/web-app-jenkins/files/style.css index 37191c5fdb..e4c6561efc 100644 --- a/roles/web-app-jenkins/templates/style.css.j2 +++ b/roles/web-app-jenkins/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} :root { --background: var(--design-surface-1); --header-background: var(--design-surface-1); @@ -119,35 +118,3 @@ .app-branding .app-branding__conic::before { display: none; } -{% if design.logo is string %} - -.app-branding .app-branding__conic img { - content: url("{{ design.urls.branding.svg }}"); -} - -.app-sign-in-register__content-logo { - content: url("{{ design.urls.icon.svg }}"); -} - -.jenkins-header .app-jenkins-logo #jenkins-head-icon { - content: url("{{ design.urls.masthead.svg }}"); - width: auto; - height: 2.25rem; -} - -.jenkins-header .app-jenkins-logo span { - position: absolute; - width: 1px; - height: 1px; - overflow: hidden; - clip-path: inset(50%); - white-space: nowrap; -} - -@media (width <= 767px) { - .jenkins-header .app-jenkins-logo #jenkins-head-icon { - content: url("{{ design.urls.icon.svg }}"); - height: 2rem; - } -} -{% endif %} diff --git a/roles/web-app-jenkins/templates/design.js b/roles/web-app-jenkins/templates/design.js new file mode 100644 index 0000000000..97d116dad9 --- /dev/null +++ b/roles/web-app-jenkins/templates/design.js @@ -0,0 +1,37 @@ +(function () { + const title = INFINITO_DESIGN.title; + function brandTitle() { + const current = document.title; + if (current.indexOf(title) !== -1) { + return; + } + document.title = /(^|\s-\s)Jenkins$/.test(current) ? current.replace(/Jenkins$/, title) : current; + const name = document.querySelector(".app-jenkins-logo span"); + if (name && name.textContent.trim() === "Jenkins") { + name.textContent = title; + } + } + function brandIcon() { + const icons = document.querySelectorAll("link[rel~='icon'], link[rel='apple-touch-icon'], link[rel='mask-icon']"); + for (let index = 0; index < icons.length; index += 1) { + const icon = icons[index]; + const target = icon.rel === "apple-touch-icon" ? INFINITO_DESIGN.urls['apple-touch-icon'].png : INFINITO_DESIGN.urls.favicon_ico; + if (icon.rel === "mask-icon") { + icon.remove(); + } else if (icon.getAttribute("href") !== target) { + icon.setAttribute("type", icon.rel === "apple-touch-icon" ? "image/png" : "image/x-icon"); + icon.setAttribute("href", target); + } + } + } + function brand() { + if (INFINITO_DESIGN.title) { + brandTitle(); + } + if (INFINITO_DESIGN.logo) { + brandIcon(); + } + } + brand(); + document.addEventListener("DOMContentLoaded", brand); +})(); diff --git a/roles/web-app-jenkins/templates/design.js.j2 b/roles/web-app-jenkins/templates/design.js.j2 deleted file mode 100644 index 6e77d08d30..0000000000 --- a/roles/web-app-jenkins/templates/design.js.j2 +++ /dev/null @@ -1,42 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { -{% if design.title is string %} - var title = {{ design.title | to_json }}; - function brandTitle() { - var current = document.title; - if (current.indexOf(title) !== -1) { - return; - } - document.title = /(^|\s-\s)Jenkins$/.test(current) ? current.replace(/Jenkins$/, title) : current; - var name = document.querySelector(".app-jenkins-logo span"); - if (name && name.textContent.trim() === "Jenkins") { - name.textContent = title; - } - } -{% endif %} -{% if design.logo is string %} - function brandIcon() { - var icons = document.querySelectorAll("link[rel~='icon'], link[rel='apple-touch-icon'], link[rel='mask-icon']"); - for (var index = 0; index < icons.length; index += 1) { - var icon = icons[index]; - var target = icon.rel === "apple-touch-icon" ? {{ design.urls['apple-touch-icon'].png | to_json }} : {{ design.urls.favicon_ico | to_json }}; - if (icon.rel === "mask-icon") { - icon.remove(); - } else if (icon.getAttribute("href") !== target) { - icon.setAttribute("type", icon.rel === "apple-touch-icon" ? "image/png" : "image/x-icon"); - icon.setAttribute("href", target); - } - } - } -{% endif %} - function brand() { -{% if design.title is string %} - brandTitle(); -{% endif %} -{% if design.logo is string %} - brandIcon(); -{% endif %} - } - brand(); - document.addEventListener("DOMContentLoaded", brand); -})(); diff --git a/roles/web-app-jitsi/templates/style.css.j2 b/roles/web-app-jitsi/files/style.css similarity index 100% rename from roles/web-app-jitsi/templates/style.css.j2 rename to roles/web-app-jitsi/files/style.css diff --git a/roles/web-app-joomla/templates/design.js.j2 b/roles/web-app-joomla/templates/design.js similarity index 87% rename from roles/web-app-joomla/templates/design.js.j2 rename to roles/web-app-joomla/templates/design.js index f3dd1fb0be..6822bad587 100644 --- a/roles/web-app-joomla/templates/design.js.j2 +++ b/roles/web-app-joomla/templates/design.js @@ -1,10 +1,10 @@ (function () { - var root = document.documentElement; + const root = document.documentElement; if (!root.hasAttribute("data-color-scheme-os") && !root.hasAttribute("data-color-scheme")) { return; } function mark(element) { - var scheme = root.getAttribute("data-color-scheme"); + const scheme = root.getAttribute("data-color-scheme"); if (scheme === "dark" || scheme === "light") { element.setAttribute("data-design-theme", scheme); } else { @@ -12,7 +12,7 @@ } } function editor(frame) { - var inner = frame.contentDocument; + const inner = frame.contentDocument; if (inner && inner.documentElement) { mark(inner.documentElement); } diff --git a/roles/web-app-keycloak/templates/sso_proxy/style.css.j2 b/roles/web-app-keycloak/files/sso_proxy/style.css similarity index 100% rename from roles/web-app-keycloak/templates/sso_proxy/style.css.j2 rename to roles/web-app-keycloak/files/sso_proxy/style.css diff --git a/roles/web-app-keycloak/templates/design.js.j2 b/roles/web-app-keycloak/templates/design.js similarity index 63% rename from roles/web-app-keycloak/templates/design.js.j2 rename to roles/web-app-keycloak/templates/design.js index 496b5fc36f..bc34c93f76 100644 --- a/roles/web-app-keycloak/templates/design.js.j2 +++ b/roles/web-app-keycloak/templates/design.js @@ -1,6 +1,6 @@ (function () { - var root = document.documentElement; - var scheme = document.querySelector('meta[name="color-scheme"]'); + const root = document.documentElement; + const scheme = document.querySelector('meta[name="color-scheme"]'); root.setAttribute("data-design-palette", ""); if (scheme && !/dark/.test(scheme.getAttribute("content") || "")) { root.setAttribute("data-design-theme", "light"); diff --git a/roles/web-app-kix/TODO.md b/roles/web-app-kix/TODO.md index 4e2f3e908d..b23e67fc97 100644 --- a/roles/web-app-kix/TODO.md +++ b/roles/web-app-kix/TODO.md @@ -1,5 +1,5 @@ # TODO - `tasks/01_admin.yml` realigns the declared administrator password on every deploy, so `INITIAL_ADMIN_PW` is only still needed for the very first installation. The backend image hands it to `kix.Console.pl Admin::User::SetPassword admin` as a command argument (`/usr/local/bin/docker-entrypoint.sh` line 194), so the value is part of the process argument list inside the backend container while that installation runs. Cause: upstream entrypoint, the console command `Admin::User::SetPassword` takes the password as an argument only. Options: find out what `install_kix()` stores when `INITIAL_ADMIN_PW` is unset and drop the variable from `templates/env.j2` if the realign covers it; or report it upstream. -- Behind the front proxy every object icon the app loads by URL is a broken image, among them the header logo as soon as the object icon `agent-portal-logo` exists. The frontend serves such an icon at `/objecticons//image%2Fpng` (route `/objecticons/:iconId/:contentType`), and the request reaches it with the encoded slash decoded, so the route does not match and the application document answers. Measured from inside the stack without a session: `http://127.0.0.1:8083/objecticons/1/image%2Fpng` (the role's own proxy) answers 200, `http://127.0.0.1:8083/objecticons/1/image/png` answers 302 and `https://kix.infinito.test/objecticons/1/image%2Fpng` answers 302; signed in, the header logo URL answered 200 with `text/html` and 86854 bytes. Cause: the front proxy vhost normalises the request path, shared code outside this role. Until that is fixed the role stylesheet carries the header logo from the CDN (`#kix-header #logo` in `templates/style.css.j2`). Options: hand the request URI to this app unchanged in the front proxy and then drop that stylesheet rule; or keep the rule. +- Behind the front proxy every object icon the app loads by URL is a broken image, among them the header logo as soon as the object icon `agent-portal-logo` exists. The frontend serves such an icon at `/objecticons//image%2Fpng` (route `/objecticons/:iconId/:contentType`), and the request reaches it with the encoded slash decoded, so the route does not match and the application document answers. Measured from inside the stack without a session: `http://127.0.0.1:8083/objecticons/1/image%2Fpng` (the role's own proxy) answers 200, `http://127.0.0.1:8083/objecticons/1/image/png` answers 302 and `https://kix.infinito.test/objecticons/1/image%2Fpng` answers 302; signed in, the header logo URL answered 200 with `text/html` and 86854 bytes. Cause: the front proxy vhost normalises the request path, shared code outside this role. Until that is fixed the role stylesheet carries the header logo from the CDN (`#kix-header #logo` in `files/style.css`). Options: hand the request URI to this app unchanged in the front proxy and then drop that stylesheet rule; or keep the rule. - On a fresh instance the object icons `agent-portal-logo` and `agent-portal-icon` do not exist: before the design import the sign-in page and the header served `/static/img/kix_default.png` as logo and favicon, the fallback of the frontend. The backend console offers `Admin::ObjectIcon::Import` and `Admin::ObjectIcon::SyncAllToFS` only, so `tasks/02_design.yml` can write an icon but not delete one. With `design` switched off again the role therefore imports the images the frontend ships as its seed (`/opt/kix/static/img/kix_start.png`, `kix_start_icon.png`) over the icons it marked, instead of returning to the state without icons. Options: delete the two icons through the backend's Perl API (`Kernel::System::ObjectIcon`) in that case; or keep the seed images. diff --git a/roles/web-app-kix/files/logo.css b/roles/web-app-kix/files/logo.css new file mode 100644 index 0000000000..b0de8b8a62 --- /dev/null +++ b/roles/web-app-kix/files/logo.css @@ -0,0 +1,3 @@ +#kix-header #logo { + content: var(--design-url-logo-png); +} diff --git a/roles/web-app-kix/templates/style.css.j2 b/roles/web-app-kix/files/style.css similarity index 99% rename from roles/web-app-kix/templates/style.css.j2 rename to roles/web-app-kix/files/style.css index cf7afa951f..55ff776db2 100644 --- a/roles/web-app-kix/templates/style.css.j2 +++ b/roles/web-app-kix/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} .login-wrapper { background-color: var(--design-surface-1); } @@ -4016,8 +4015,3 @@ th.selectedCell { .tui-full-calendar-layout { filter: invert(var(--design-invert)) hue-rotate(calc(var(--design-invert) * 180deg)); } -{% if design.logo is string %} -#kix-header #logo { - content: url("{{ design.urls.logo.png }}"); -} -{% endif %} diff --git a/roles/web-app-litellm/templates/style.css.j2 b/roles/web-app-litellm/templates/style.css.j2 index 70fccbd7e6..62dbf01e0a 100644 --- a/roles/web-app-litellm/templates/style.css.j2 +++ b/roles/web-app-litellm/templates/style.css.j2 @@ -1,9 +1,7 @@ {% set design = lookup('design', application_id) %} -{% set sign_in = 'form[action$="/login"]' %} {% set neutral = ['gray', 'slate'] %} {% set brand = ['blue', 'indigo'] %} {% set status = [('red', 'danger'), ('green', 'success'), ('emerald', 'success'), ('yellow', 'warning'), ('amber', 'warning'), ('orange', 'warning'), ('teal', 'info')] %} -{% set code_block = 'pre:has(> code[class*="language-"])' %} {% set code_tokens = [ ('112, 128, 144', 'text-muted'), ('153, 153, 153', 'text-muted'), @@ -476,75 +474,75 @@ button[id^="headlessui-listbox-button"] { .to-tremor-background { --tw-gradient-to: var(--design-surface-2) var(--tw-gradient-to-position); } -{{ code_block }} { +pre:has(> code[class*="language-"]) { background: var(--design-surface-3) !important; } -{{ code_block }}, -{{ code_block }} > code { +pre:has(> code[class*="language-"]), +pre:has(> code[class*="language-"]) > code { color: var(--design-text) !important; text-shadow: none !important; } -{{ code_block }} .token { +pre:has(> code[class*="language-"]) .token { background: none !important; color: inherit !important; } {% for rgb, token in code_tokens %} -{{ code_block }} .token[style*="rgb({{ rgb }})"] { +pre:has(> code[class*="language-"]) .token[style*="rgb({{ rgb }})"] { color: var(--design-{{ token }}) !important; } {% endfor %} -:root:has({{ sign_in }}) body { +:root:has(form[action$="/login"]) body { background-color: var(--design-surface-1); color: var(--design-text); } -{{ sign_in }} { +form[action$="/login"] { background-color: var(--design-surface-2); box-shadow: var(--design-shadow-3); } -{{ sign_in }} :is(.logo, h2, label, .info-box p) { +form[action$="/login"] :is(.logo, h2, label, .info-box p) { color: var(--design-text); } -{{ sign_in }} :is(.subtitle, .help-text) { +form[action$="/login"] :is(.subtitle, .help-text) { color: var(--design-text-muted); } -{{ sign_in }} .info-box { +form[action$="/login"] .info-box { background-color: var(--design-info-subtle); border-left-color: var(--design-info); } -{{ sign_in }} .info-header { +form[action$="/login"] .info-header { color: var(--design-info); } -{{ sign_in }} .required { +form[action$="/login"] .required { color: var(--design-danger); } -{{ sign_in }} :is(input[type="text"], input[type="password"]) { +form[action$="/login"] :is(input[type="text"], input[type="password"]) { border-color: var(--design-border-strong); background-color: var(--design-surface-2); color: var(--design-text); } -{{ sign_in }} :is(input[type="text"], input[type="password"]):focus { +form[action$="/login"] :is(input[type="text"], input[type="password"]):focus { border-color: var(--design-link); box-shadow: var(--design-focus-ring); } -{{ sign_in }} input[type="submit"] { +form[action$="/login"] input[type="submit"] { background-color: var(--design-primary); color: var(--design-on-primary); } -{{ sign_in }} input[type="submit"]:hover { +form[action$="/login"] input[type="submit"]:hover { background-color: var(--design-primary-hover); } -{{ sign_in }} input[type="submit"]:active { +form[action$="/login"] input[type="submit"]:active { background-color: var(--design-primary-active); } -{{ sign_in }} a { +form[action$="/login"] a { color: var(--design-link); } -{{ sign_in }} code { +form[action$="/login"] code { background-color: var(--design-surface-3); color: var(--design-text); } {% if design.logo is string %} -{{ sign_in }} .logo { +form[action$="/login"] .logo { height: 3rem; font-size: 0; background: url("{{ design.urls.logo.svg }}") center / contain no-repeat; diff --git a/roles/web-app-littlejs/templates/design.js b/roles/web-app-littlejs/templates/design.js new file mode 100644 index 0000000000..038b37889e --- /dev/null +++ b/roles/web-app-littlejs/templates/design.js @@ -0,0 +1,79 @@ +(function () { + const root = document.documentElement; + const prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); + let picked = ""; + function stored() { + try { + const value = window.localStorage.getItem("theme"); + return value === "light" || value === "dark" ? value : ""; + } catch { + return ""; + } + } + function apply() { + if (picked) { + root.setAttribute("data-design-theme", picked); + return; + } + root.removeAttribute("data-design-theme"); + const browser = prefersDark.matches ? "dark" : "light"; + if (root.getAttribute("data-theme") !== browser) { + root.setAttribute("data-theme", browser); + } + } + if (/^\/examples\/(index\.html)?$/.test(window.location.pathname)) { + picked = stored(); + prefersDark.addEventListener("change", apply); + window.addEventListener("storage", function () { + picked = stored(); + apply(); + }); + document.addEventListener( + "click", + function (event) { + if (event.target && event.target.closest && event.target.closest("#buttonTheme")) { + window.setTimeout(function () { + const theme = root.getAttribute("data-theme"); + picked = theme === "light" || theme === "dark" ? theme : ""; + apply(); + }, 0); + } + }, + true + ); + apply(); + } + if (INFINITO_DESIGN.title || INFINITO_DESIGN.logo) { + function brand() { + if (INFINITO_DESIGN.title) { + const title = INFINITO_DESIGN.title; + if (document.title.indexOf(title) === -1) { + document.title = document.title ? `${document.title } | ${ title}` : title; + } + } + if (INFINITO_DESIGN.logo) { + const icon = INFINITO_DESIGN.urls.favicon.png; + const links = document.querySelectorAll("link[rel~='icon']"); + for (let index = 0; index < links.length; index += 1) { + if (links[index].getAttribute("href") !== icon) { + links[index].setAttribute("type", "image/png"); + links[index].setAttribute("href", icon); + } + } + if (links.length === 0 && document.head) { + const link = document.createElement("link"); + link.setAttribute("rel", "icon"); + link.setAttribute("type", "image/png"); + link.setAttribute("href", icon); + document.head.appendChild(link); + } + const symbol = document.querySelector("#topBar .brand img"); + if (symbol && symbol.getAttribute("src") !== icon) { + symbol.setAttribute("src", icon); + } + } + } + document.addEventListener("DOMContentLoaded", brand); + brand(); + } +})(); diff --git a/roles/web-app-littlejs/templates/design.js.j2 b/roles/web-app-littlejs/templates/design.js.j2 deleted file mode 100644 index 11dcb19085..0000000000 --- a/roles/web-app-littlejs/templates/design.js.j2 +++ /dev/null @@ -1,80 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var root = document.documentElement; - var prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); - var picked = ""; - function stored() { - try { - var value = window.localStorage.getItem("theme"); - return value === "light" || value === "dark" ? value : ""; - } catch (error) { - return ""; - } - } - function apply() { - if (picked) { - root.setAttribute("data-design-theme", picked); - return; - } - root.removeAttribute("data-design-theme"); - var browser = prefersDark.matches ? "dark" : "light"; - if (root.getAttribute("data-theme") !== browser) { - root.setAttribute("data-theme", browser); - } - } - if (/^\/examples\/(index\.html)?$/.test(window.location.pathname)) { - picked = stored(); - prefersDark.addEventListener("change", apply); - window.addEventListener("storage", function () { - picked = stored(); - apply(); - }); - document.addEventListener( - "click", - function (event) { - if (event.target && event.target.closest && event.target.closest("#buttonTheme")) { - window.setTimeout(function () { - var theme = root.getAttribute("data-theme"); - picked = theme === "light" || theme === "dark" ? theme : ""; - apply(); - }, 0); - } - }, - true - ); - apply(); - } -{% if design.title is string or design.logo is string %} - function brand() { -{% if design.title is string %} - var title = {{ design.title | to_json }}; - if (document.title.indexOf(title) === -1) { - document.title = document.title ? document.title + " | " + title : title; - } -{% endif %} -{% if design.logo is string %} - var icon = {{ design.urls.favicon.png | to_json }}; - var links = document.querySelectorAll("link[rel~='icon']"); - for (var index = 0; index < links.length; index += 1) { - if (links[index].getAttribute("href") !== icon) { - links[index].setAttribute("type", "image/png"); - links[index].setAttribute("href", icon); - } - } - if (links.length === 0 && document.head) { - var link = document.createElement("link"); - link.setAttribute("rel", "icon"); - link.setAttribute("type", "image/png"); - link.setAttribute("href", icon); - document.head.appendChild(link); - } - var symbol = document.querySelector("#topBar .brand img"); - if (symbol && symbol.getAttribute("src") !== icon) { - symbol.setAttribute("src", icon); - } -{% endif %} - } - document.addEventListener("DOMContentLoaded", brand); - brand(); -{% endif %} -})(); diff --git a/roles/web-app-magento/templates/style.css.j2 b/roles/web-app-magento/templates/style.css.j2 index a529c936e9..ac35acdccd 100644 --- a/roles/web-app-magento/templates/style.css.j2 +++ b/roles/web-app-magento/templates/style.css.j2 @@ -1,6 +1,5 @@ {% set design = lookup('design', application_id) %} {% set static = MAGENTO_URL | regex_replace('/+$', '') ~ '/static' %} -{% set shop = ':where(html:not(:has(> head > link[href*="/adminhtml/"])))' %} {% set admin = ':where(html:has(> head > link[href*="/adminhtml/"]))' %} :where(html:not(:has(> head > link[href*="/adminhtml/"]))) { & body { @@ -7479,8 +7478,8 @@ } } -{{ shop }} .page-header .panel.wrapper, -{{ shop }} .copyright, +:where(html:not(:has(> head > link[href*="/adminhtml/"]))) .page-header .panel.wrapper, +:where(html:not(:has(> head > link[href*="/adminhtml/"]))) .copyright, {{ admin }} .menu-wrapper, {{ admin }} body.page-layout-admin-login { --design-focus: var(--design-on-frame); @@ -7490,7 +7489,7 @@ --design-focus: var(--design-link); } -{{ shop }} body._keyfocus .page-header .panel.wrapper :focus, +:where(html:not(:has(> head > link[href*="/adminhtml/"]))) body._keyfocus .page-header .panel.wrapper :focus, {{ admin }} body._keyfocus .menu-wrapper a:focus, {{ admin }} body._keyfocus .menu-wrapper a.logo:focus { box-shadow: inset 0 0 0 2px var(--design-on-frame); diff --git a/roles/web-app-mailu/templates/style.css.j2 b/roles/web-app-mailu/files/style.css similarity index 100% rename from roles/web-app-mailu/templates/style.css.j2 rename to roles/web-app-mailu/files/style.css diff --git a/roles/web-app-mastodon/templates/design.js.j2 b/roles/web-app-mastodon/templates/design.js similarity index 82% rename from roles/web-app-mastodon/templates/design.js.j2 rename to roles/web-app-mastodon/templates/design.js index 0a86a6c71f..1364d0ffc3 100644 --- a/roles/web-app-mastodon/templates/design.js.j2 +++ b/roles/web-app-mastodon/templates/design.js @@ -1,7 +1,7 @@ (function () { - var root = document.documentElement; + const root = document.documentElement; function mirror() { - var scheme = root.getAttribute("data-color-scheme"); + const scheme = root.getAttribute("data-color-scheme"); if (root.getAttribute("data-system-theme") === "true" || (scheme !== "dark" && scheme !== "light")) { root.removeAttribute("data-design-theme"); } else if (root.getAttribute("data-design-theme") !== scheme) { diff --git a/roles/web-app-matomo/templates/design.js.j2 b/roles/web-app-matomo/templates/design.js similarity index 81% rename from roles/web-app-matomo/templates/design.js.j2 rename to roles/web-app-matomo/templates/design.js index 61c1ab20bb..d3cd0e6ad9 100644 --- a/roles/web-app-matomo/templates/design.js.j2 +++ b/roles/web-app-matomo/templates/design.js @@ -1,7 +1,7 @@ (function () { - var root = document.documentElement; + const root = document.documentElement; function mirror() { - var mode = root.getAttribute("data-theme-mode"); + const mode = root.getAttribute("data-theme-mode"); if (mode === "light" || mode === "dark") { if (root.getAttribute("data-design-theme") !== mode) root.setAttribute("data-design-theme", mode); } else if (root.hasAttribute("data-design-theme")) { diff --git a/roles/web-app-matrix/templates/style.css.j2 b/roles/web-app-matrix/files/style.css similarity index 100% rename from roles/web-app-matrix/templates/style.css.j2 rename to roles/web-app-matrix/files/style.css diff --git a/roles/web-app-matrix/templates/design.js.j2 b/roles/web-app-matrix/templates/design.js similarity index 62% rename from roles/web-app-matrix/templates/design.js.j2 rename to roles/web-app-matrix/templates/design.js index d5ed4bf0c8..9bbf0411b2 100644 --- a/roles/web-app-matrix/templates/design.js.j2 +++ b/roles/web-app-matrix/templates/design.js @@ -1,9 +1,9 @@ (function () { - var root = document.documentElement; - var system = window.matchMedia("(prefers-color-scheme: dark)"); + const root = document.documentElement; + const system = window.matchMedia("(prefers-color-scheme: dark)"); function mirror() { - var classes = document.body.className || ""; - var app = /\bcpd-theme-dark(-hc)?\b/.test(classes) ? "dark" : /\bcpd-theme-light(-hc)?\b/.test(classes) ? "light" : ""; + const classes = document.body.className || ""; + const app = /\bcpd-theme-dark(-hc)?\b/.test(classes) ? "dark" : /\bcpd-theme-light(-hc)?\b/.test(classes) ? "light" : ""; if (app && app !== (system.matches ? "dark" : "light")) { root.setAttribute("data-design-theme", app); } else { diff --git a/roles/web-app-mattermost/templates/design.js.j2 b/roles/web-app-mattermost/templates/design.js similarity index 66% rename from roles/web-app-mattermost/templates/design.js.j2 rename to roles/web-app-mattermost/templates/design.js index aaa73eabc6..514de9fe7a 100644 --- a/roles/web-app-mattermost/templates/design.js.j2 +++ b/roles/web-app-mattermost/templates/design.js @@ -1,6 +1,6 @@ (function () { - var root = document.documentElement; - var denim = { "--sidebar-bg": "#1e325c", "--center-channel-bg": "#ffffff", "--button-bg": "#1c58d9" }; + const root = document.documentElement; + const denim = { "--sidebar-bg": "#1e325c", "--center-channel-bg": "#ffffff", "--button-bg": "#1c58d9" }; function channel(hex, index) { return parseInt(hex.substr(1 + 2 * index, 2), 16) / 255; @@ -11,9 +11,9 @@ } function mirror() { - var surface = root.style.getPropertyValue("--center-channel-bg").trim().toLowerCase(); - var isDefault = Object.keys(denim).every(function (name) { - var value = root.style.getPropertyValue(name).trim().toLowerCase(); + const surface = root.style.getPropertyValue("--center-channel-bg").trim().toLowerCase(); + const isDefault = Object.keys(denim).every(function (name) { + const value = root.style.getPropertyValue(name).trim().toLowerCase(); return value === "" || value === denim[name]; }); if (isDefault || !/^#[0-9a-f]{6}$/.test(surface)) { diff --git a/roles/web-app-mattermost/templates/style.css.j2 b/roles/web-app-mattermost/templates/style.css.j2 index e696ce6a22..0ac08d079c 100644 --- a/roles/web-app-mattermost/templates/style.css.j2 +++ b/roles/web-app-mattermost/templates/style.css.j2 @@ -1,5 +1,4 @@ {% set design = lookup('design', application_id) %} -{% set scope = 'html:not([data-design-app-theme="custom"])' %} {% set colors = { 'center-channel-bg': 'surface-1', 'center-channel-color': 'text', @@ -39,7 +38,7 @@ } %} {% set opacity_exceptions = {'button-bg-30': '32'} %} {% set fills = {'button-bg': 'primary', 'button-color': 'on-primary'} %} -{{ scope }} body { +html:not([data-design-app-theme="custom"]) body { {% for name, token in colors.items() %} --{{ name }}: var(--design-{{ token }}); --{{ triplet_names.get(name, name) }}-rgb: var(--design-{{ token }}-rgb); @@ -107,8 +106,8 @@ --elevation-6: var(--design-shadow-3); } -{{ scope }} body .btn-primary, -{{ scope }} body .SendMessageButton { +html:not([data-design-app-theme="custom"]) body .btn-primary, +html:not([data-design-app-theme="custom"]) body .SendMessageButton { {% for name, token in fills.items() %} --{{ name }}: var(--design-{{ token }}); --{{ name }}-rgb: var(--design-{{ token }}-rgb); @@ -8991,46 +8990,46 @@ html:not([data-design-app-theme="custom"]) .app__body .post .post-collapse__show background-color: var(--design-primary-hover); } -{{ scope }} body #global-header, -{{ scope }} body #SidebarContainer, -{{ scope }} body #navbar, -{{ scope }} body .admin-sidebar { +html:not([data-design-app-theme="custom"]) body #global-header, +html:not([data-design-app-theme="custom"]) body #SidebarContainer, +html:not([data-design-app-theme="custom"]) body #navbar, +html:not([data-design-app-theme="custom"]) body .admin-sidebar { --design-focus: var(--design-on-frame); --border-default: solid 1px var(--design-frame-active); --border-light: solid 1px var(--design-frame-active); --border-dark: solid 1px var(--design-frame-active); } -{{ scope }} body #global-header .Menu__content, -{{ scope }} body #global-header .dropdown-menu, -{{ scope }} body #SidebarContainer .Menu__content, -{{ scope }} body #SidebarContainer .dropdown-menu { +html:not([data-design-app-theme="custom"]) body #global-header .Menu__content, +html:not([data-design-app-theme="custom"]) body #global-header .dropdown-menu, +html:not([data-design-app-theme="custom"]) body #SidebarContainer .Menu__content, +html:not([data-design-app-theme="custom"]) body #SidebarContainer .dropdown-menu { --design-focus: var(--design-link); --border-default: solid 1px var(--design-border); --border-light: solid 1px var(--design-border); --border-dark: solid 1px var(--design-border-strong); } -{{ scope }} body #root .main-wrapper { +html:not([data-design-app-theme="custom"]) body #root .main-wrapper { border-color: var(--design-frame-active); } -{{ scope }} body #global-header .a11y--focused, -{{ scope }} body #SidebarContainer .a11y--focused, -{{ scope }} body #navbar .a11y--focused { +html:not([data-design-app-theme="custom"]) body #global-header .a11y--focused, +html:not([data-design-app-theme="custom"]) body #SidebarContainer .a11y--focused, +html:not([data-design-app-theme="custom"]) body #navbar .a11y--focused { box-shadow: 0 0 1px 3px rgba(var(--design-on-frame-rgb), 0.5), 0 0 0 1px var(--design-on-frame); } -{{ scope }} body #SidebarContainer .SidebarChannel.active .SidebarLink { +html:not([data-design-app-theme="custom"]) body #SidebarContainer .SidebarChannel.active .SidebarLink { background-color: var(--design-frame-active); } -{{ scope }} body .header-footer-route .header-footer-route-container { +html:not([data-design-app-theme="custom"]) body .header-footer-route .header-footer-route-container { background-image: none; } {% if design.logo is string %} -{{ scope }} body #global-header [aria-controls="product-switcher-menu"] > span > svg { +html:not([data-design-app-theme="custom"]) body #global-header [aria-controls="product-switcher-menu"] > span > svg { width: {{ (24 * design.slots['logo-frame'].width / design.slots['logo-frame'].height) | round | int }}px; height: 24px; background: url("{{ design.urls['logo-frame'].svg }}") left center / contain no-repeat; @@ -9042,7 +9041,7 @@ body .hfroute-header .header-main .header-logo-link > svg { background: url("{{ design.urls.logo.svg }}") left center / contain no-repeat; } -{{ scope }} body #global-header [aria-controls="product-switcher-menu"] > span > svg > *, +html:not([data-design-app-theme="custom"]) body #global-header [aria-controls="product-switcher-menu"] > span > svg > *, body .hfroute-header .header-logo-link > svg > * { visibility: hidden; } diff --git a/roles/web-app-mediawiki/templates/style.css.j2 b/roles/web-app-mediawiki/files/style.css similarity index 100% rename from roles/web-app-mediawiki/templates/style.css.j2 rename to roles/web-app-mediawiki/files/style.css diff --git a/roles/web-app-mediawiki/templates/design.js.j2 b/roles/web-app-mediawiki/templates/design.js similarity index 86% rename from roles/web-app-mediawiki/templates/design.js.j2 rename to roles/web-app-mediawiki/templates/design.js index aae372517c..60c464562d 100644 --- a/roles/web-app-mediawiki/templates/design.js.j2 +++ b/roles/web-app-mediawiki/templates/design.js @@ -1,7 +1,7 @@ (function () { - var root = document.documentElement; + const root = document.documentElement; function mirror() { - var classes = root.classList; + const classes = root.classList; if (classes.contains("skin-theme-clientpref-night")) { root.setAttribute("data-design-theme", "dark"); } else if (classes.contains("skin-theme-clientpref-day") || classes.contains("skin-theme-clientpref--excluded")) { diff --git a/roles/web-app-mini-qr/templates/design.js b/roles/web-app-mini-qr/templates/design.js new file mode 100644 index 0000000000..ac9b795418 --- /dev/null +++ b/roles/web-app-mini-qr/templates/design.js @@ -0,0 +1,38 @@ +(function () { + const root = document.documentElement; + if (INFINITO_DESIGN.title) { + document.title = INFINITO_DESIGN.title; + } + if (INFINITO_DESIGN.logo) { + const icon = document.querySelector("link[rel='icon']") || document.head.appendChild(document.createElement("link")); + icon.rel = "icon"; + icon.type = "image/svg+xml"; + icon.href = INFINITO_DESIGN.urls.favicon.svg; + const touch = document.querySelector("link[rel='apple-touch-icon']") || document.head.appendChild(document.createElement("link")); + touch.rel = "apple-touch-icon"; + touch.href = INFINITO_DESIGN.urls['apple-touch-icon'].png; + } + function mirror() { + let choice; + try { + choice = window.localStorage.getItem("dark-mode-preference"); + } catch { + 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/design.js.j2 b/roles/web-app-mini-qr/templates/design.js.j2 deleted file mode 100644 index 02047f72b4..0000000000 --- a/roles/web-app-mini-qr/templates/design.js.j2 +++ /dev/null @@ -1,39 +0,0 @@ -{% 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/style.css.j2 b/roles/web-app-mini-qr/templates/style.css.j2 index b81458a0a5..831c48493f 100644 --- a/roles/web-app-mini-qr/templates/style.css.j2 +++ b/roles/web-app-mini-qr/templates/style.css.j2 @@ -1,7 +1,5 @@ {% 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 ' {' }} @@ -14,9 +12,9 @@ body, background-color: var(--design-surface-1); color: var(--design-text); } -{{ chrome }}, -{{ chrome }}::before, -{{ chrome }}::after { +:where(:not(#element-to-export, #element-to-export *, #drawer-preview-container .origin-center *)), +:where(:not(#element-to-export, #element-to-export *, #drawer-preview-container .origin-center *))::before, +:where(:not(#element-to-export, #element-to-export *, #drawer-preview-container .origin-center *))::after { border-color: var(--design-border); } {{ paint('background-color', 'var(--design-surface-2)', ['bg-white', 'bg-zinc-50', 'bg-background', 'bg-popover']) }} @@ -51,24 +49,24 @@ a:visited, a:active { color: var(--design-link); } -:root p{{ chrome }}, +:root p:where(:not(#element-to-export, #element-to-export *, #drawer-preview-container .origin-center *)), :root label, :root legend, :root .radio > label, :root .radio > * > label { color: var(--design-text); } -:root {{ chrome }}::selection { +:root :where(:not(#element-to-export, #element-to-export *, #drawer-preview-container .origin-center *))::selection { background-color: var(--design-surface-active); color: var(--design-text); } -:root {{ chrome }}::-webkit-scrollbar-track { +:root :where(:not(#element-to-export, #element-to-export *, #drawer-preview-container .origin-center *))::-webkit-scrollbar-track { background-color: var(--design-surface-3); } -:root {{ chrome }}::-webkit-scrollbar-thumb { +:root :where(:not(#element-to-export, #element-to-export *, #drawer-preview-container .origin-center *))::-webkit-scrollbar-thumb { background-color: var(--design-border-strong); } -:root {{ chrome }}::-webkit-scrollbar-thumb:hover { +:root :where(:not(#element-to-export, #element-to-export *, #drawer-preview-container .origin-center *))::-webkit-scrollbar-thumb:hover { background-color: var(--design-text-muted); } :root input::placeholder, @@ -141,11 +139,11 @@ a:active { #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"]) { +:is(.icon-button, .button, .secondary-button, [role="combobox"], [aria-labelledby="data-to-encode-modal-title"]) 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"]) { +:is(.icon-button, .button, .secondary-button, [role="combobox"], [aria-labelledby="data-to-encode-modal-title"]) svg[stroke="#abcbca"], +:is(.icon-button, .button, .secondary-button, [role="combobox"], [aria-labelledby="data-to-encode-modal-title"]) svg :is([stroke="#abcbca"], [stroke="#888888"]) { stroke: currentColor; } .prose { diff --git a/roles/web-app-mobilizon/templates/style.css.j2 b/roles/web-app-mobilizon/files/style.css similarity index 100% rename from roles/web-app-mobilizon/templates/style.css.j2 rename to roles/web-app-mobilizon/files/style.css diff --git a/roles/web-app-mobilizon/templates/design.js.j2 b/roles/web-app-mobilizon/templates/design.js similarity index 81% rename from roles/web-app-mobilizon/templates/design.js.j2 rename to roles/web-app-mobilizon/templates/design.js index ceb3d76c7e..7b005b2224 100644 --- a/roles/web-app-mobilizon/templates/design.js.j2 +++ b/roles/web-app-mobilizon/templates/design.js @@ -1,16 +1,16 @@ (function () { - var root = document.documentElement; + const root = document.documentElement; function stored() { try { return window.localStorage.getItem("theme"); - } catch (error) { + } catch { return null; } } function mirror() { - var theme = stored(); + const theme = stored(); if (theme === "dark" || theme === "light") { - var wanted = root.classList.contains("dark") ? "dark" : "light"; + const wanted = root.classList.contains("dark") ? "dark" : "light"; if (root.getAttribute("data-design-theme") !== wanted) root.setAttribute("data-design-theme", wanted); } else if (root.hasAttribute("data-design-theme")) { root.removeAttribute("data-design-theme"); diff --git a/roles/web-app-moodle/templates/design.js.j2 b/roles/web-app-moodle/templates/design.js similarity index 71% rename from roles/web-app-moodle/templates/design.js.j2 rename to roles/web-app-moodle/templates/design.js index 12fec080d6..74f459b439 100644 --- a/roles/web-app-moodle/templates/design.js.j2 +++ b/roles/web-app-moodle/templates/design.js @@ -1,7 +1,7 @@ (function () { - var root = document.documentElement; - var sync = function () { - var mode = root.getAttribute("data-colourmode"); + const root = document.documentElement; + const sync = function () { + const mode = root.getAttribute("data-colourmode"); if (mode === "light" || mode === "dark") { root.setAttribute("data-design-theme", mode); } else { diff --git a/roles/web-app-n8n/templates/design.js b/roles/web-app-n8n/templates/design.js new file mode 100644 index 0000000000..811ad96aee --- /dev/null +++ b/roles/web-app-n8n/templates/design.js @@ -0,0 +1,72 @@ +(function () { + const root = document.documentElement; + function stored() { + try { + return new URLSearchParams(window.location.search).get("theme") || window.localStorage.getItem("N8N_THEME"); + } catch { + return null; + } + } + function chosen() { + const body = document.body; + if (body && body.hasAttribute("data-theme")) { + return body.getAttribute("data-theme"); + } + return document.getElementById("n8n-app") ? null : stored(); + } + function mirror() { + const theme = chosen(); + if (theme === "light" || theme === "dark") { + root.setAttribute("data-design-theme", theme); + } else { + root.removeAttribute("data-design-theme"); + } + } + function watchBody() { + new MutationObserver(mirror).observe(document.body, { attributes: true, attributeFilter: ["data-theme"] }); + mirror(); + } + mirror(); + if (document.body) { + watchBody(); + } else { + document.addEventListener("DOMContentLoaded", watchBody); + } + if (INFINITO_DESIGN.title) { + const title = INFINITO_DESIGN.title; + function brandTitle() { + const current = document.title; + if (current.indexOf(title) !== -1) { + return; + } + const page = current.replace(/\s*-\s*n8n(\[[A-Z]+\])?$/, "").replace(/^n8n\.io\s*-\s*/, ""); + document.title = page && page !== "Workflow Automation" ? `${page } - ${ title}` : title; + } + function watchTitle() { + const element = document.querySelector("title"); + if (!element) { + return false; + } + new MutationObserver(brandTitle).observe(element, { childList: true, characterData: true, subtree: true }); + brandTitle(); + return true; + } + if (!watchTitle()) { + document.addEventListener("DOMContentLoaded", watchTitle); + } + } + if (INFINITO_DESIGN.logo) { + function brandIcon() { + const icons = document.querySelectorAll("link[rel~='icon']"); + for (let index = 0; index < icons.length; index += 1) { + if (icons[index].getAttribute("href") !== INFINITO_DESIGN.urls.favicon_ico) { + icons[index].setAttribute("type", "image/x-icon"); + icons[index].setAttribute("href", INFINITO_DESIGN.urls.favicon_ico); + } + } + } + new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); + brandIcon(); + document.addEventListener("DOMContentLoaded", brandIcon); + } +})(); diff --git a/roles/web-app-n8n/templates/design.js.j2 b/roles/web-app-n8n/templates/design.js.j2 deleted file mode 100644 index 2a65b5bc7b..0000000000 --- a/roles/web-app-n8n/templates/design.js.j2 +++ /dev/null @@ -1,73 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var root = document.documentElement; - function stored() { - try { - return new URLSearchParams(window.location.search).get("theme") || window.localStorage.getItem("N8N_THEME"); - } catch (error) { - return null; - } - } - function chosen() { - var body = document.body; - if (body && body.hasAttribute("data-theme")) { - return body.getAttribute("data-theme"); - } - return document.getElementById("n8n-app") ? null : stored(); - } - function mirror() { - var theme = chosen(); - if (theme === "light" || theme === "dark") { - root.setAttribute("data-design-theme", theme); - } else { - root.removeAttribute("data-design-theme"); - } - } - function watchBody() { - new MutationObserver(mirror).observe(document.body, { attributes: true, attributeFilter: ["data-theme"] }); - mirror(); - } - mirror(); - if (document.body) { - watchBody(); - } else { - document.addEventListener("DOMContentLoaded", watchBody); - } -{% if design.title is string %} - var title = {{ design.title | to_json }}; - function brandTitle() { - var current = document.title; - if (current.indexOf(title) !== -1) { - return; - } - var page = current.replace(/\s*-\s*n8n(\[[A-Z]+\])?$/, "").replace(/^n8n\.io\s*-\s*/, ""); - document.title = page && page !== "Workflow Automation" ? page + " - " + title : title; - } - function watchTitle() { - var element = document.querySelector("title"); - if (!element) { - return false; - } - new MutationObserver(brandTitle).observe(element, { childList: true, characterData: true, subtree: true }); - brandTitle(); - return true; - } - if (!watchTitle()) { - document.addEventListener("DOMContentLoaded", watchTitle); - } -{% endif %} -{% if design.logo is string %} - function brandIcon() { - var icons = document.querySelectorAll("link[rel~='icon']"); - for (var index = 0; index < icons.length; index += 1) { - if (icons[index].getAttribute("href") !== {{ design.urls.favicon_ico | to_json }}) { - icons[index].setAttribute("type", "image/x-icon"); - icons[index].setAttribute("href", {{ design.urls.favicon_ico | to_json }}); - } - } - } - new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); - brandIcon(); - document.addEventListener("DOMContentLoaded", brandIcon); -{% endif %} -})(); diff --git a/roles/web-app-nextcloud/templates/design.js.j2 b/roles/web-app-nextcloud/templates/design.js similarity index 68% rename from roles/web-app-nextcloud/templates/design.js.j2 rename to roles/web-app-nextcloud/templates/design.js index 4e448df054..7bdf7c1e9b 100644 --- a/roles/web-app-nextcloud/templates/design.js.j2 +++ b/roles/web-app-nextcloud/templates/design.js @@ -1,15 +1,15 @@ (function () { - var root = document.documentElement; - var DARK = ["dark", "dark-highcontrast"]; - var LIGHT = ["light", "light-highcontrast"]; + const root = document.documentElement; + const DARK = ["dark", "dark-highcontrast"]; + const LIGHT = ["light", "light-highcontrast"]; function picked(ids, wanted) { return ids.some(function (id) { return wanted.indexOf(id) !== -1; }); } function mirror() { - var ids = (document.body.getAttribute("data-themes") || "").split(","); - var mode = picked(ids, DARK) ? "dark" : picked(ids, LIGHT) ? "light" : null; + const ids = (document.body.getAttribute("data-themes") || "").split(","); + const mode = picked(ids, DARK) ? "dark" : picked(ids, LIGHT) ? "light" : null; if (mode === null) { if (root.hasAttribute("data-design-theme")) root.removeAttribute("data-design-theme"); } else if (root.getAttribute("data-design-theme") !== mode) { diff --git a/roles/web-app-odoo/files/playwright/test-design.js b/roles/web-app-odoo/files/playwright/test-design.js index c16cb24155..bc260e239d 100644 --- a/roles/web-app-odoo/files/playwright/test-design.js +++ b/roles/web-app-odoo/files/playwright/test-design.js @@ -15,7 +15,8 @@ const { resolveTimeout } = require("./timeouts"); const title = decodeDotenvQuotedValue(process.env.DESIGN_TITLE || ""); const logoEnabled = decodeDotenvQuotedValue(process.env.DESIGN_LOGO_ENABLED || "") === "true"; -const odooMajor = Number.parseInt(decodeDotenvQuotedValue(process.env.ODOO_VERSION || ""), 10); +const odooVersion = decodeDotenvQuotedValue(process.env.ODOO_VERSION || ""); +const odooMajor = odooVersion ? Number.parseInt(odooVersion, 10) : 0; const rendersSearchPanelHeaderClass = odooMajor >= 20; const rendersDangerConfirmButton = odooMajor >= 20; diff --git a/roles/web-app-openbao/files/logo.css b/roles/web-app-openbao/files/logo.css new file mode 100644 index 0000000000..2fa7a38948 --- /dev/null +++ b/roles/web-app-openbao/files/logo.css @@ -0,0 +1,10 @@ +.hds-side-nav__home-link { + background: var(--design-url-logo-svg) center / auto 2rem no-repeat; +} +.brand-icon-large { + background: var(--design-url-logo-svg) center / contain no-repeat; +} +.hds-side-nav__home-link .hs-icon, +.brand-icon-large .hs-icon { + visibility: hidden; +} diff --git a/roles/web-app-openbao/templates/style.css.j2 b/roles/web-app-openbao/files/style.css similarity index 99% rename from roles/web-app-openbao/templates/style.css.j2 rename to roles/web-app-openbao/files/style.css index 4622a5629e..5c835eb6f3 100644 --- a/roles/web-app-openbao/templates/style.css.j2 +++ b/roles/web-app-openbao/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} .ember-basic-dropdown-content { background-color: var(--design-surface-2); } @@ -2468,15 +2467,3 @@ input.has-error:hover { --token-color-focus-action-internal: var(--design-on-frame); --token-color-focus-action-external: var(--design-on-frame); } -{% if design.logo is string %} -.hds-side-nav__home-link { - background: url("{{ design.urls.logo.svg }}") center / auto 2rem no-repeat; -} -.brand-icon-large { - background: url("{{ design.urls.logo.svg }}") center / contain no-repeat; -} -.hds-side-nav__home-link .hs-icon, -.brand-icon-large .hs-icon { - visibility: hidden; -} -{% endif %} diff --git a/roles/web-app-openclaw/templates/style.css.j2 b/roles/web-app-openclaw/templates/style.css.j2 index 513611a604..f10d6ecc31 100644 --- a/roles/web-app-openclaw/templates/style.css.j2 +++ b/roles/web-app-openclaw/templates/style.css.j2 @@ -1,5 +1,4 @@ {% set design = lookup('design', application_id) %} -{% set corporate = ':root[data-design-corporate]' %} {% set brand_fills = [ '.btn.primary', '.btn.cron-refresh-btn--loading', @@ -11,9 +10,7 @@ '.sw-btn--primary', '.sw-today__big--primary', ] %} -{% set brand_buttons = ':is(.btn.primary, .sw-btn--primary, .sw-today__big--primary)' %} -{% set brand_texts = ':is(.login-gate__title, .sidebar-brand__title, .topbar-brand__title, .dashboard-header__breadcrumb-link)' %} -{{ corporate }} { +:root[data-design-corporate] { --ok: var(--design-success); --ok-muted: color-mix(in srgb, var(--design-success) 75%, transparent); --ok-subtle: var(--design-success-subtle); @@ -32,38 +29,38 @@ --shadow-lg: var(--design-shadow-3); --shadow-xl: var(--design-shadow-3); } -{{ corporate }} :is({{ brand_fills | join(', ') }}) { +:root[data-design-corporate] :is({{ brand_fills | join(', ') }}) { border-color: var(--design-primary); background: var(--design-primary); color: var(--design-on-primary); } -{{ corporate }} {{ brand_buttons }}:hover:not(:disabled) { +:root[data-design-corporate] :is(.btn.primary, .sw-btn--primary, .sw-today__big--primary):hover:not(:disabled) { border-color: var(--design-primary-hover); background: var(--design-primary-hover); } -{{ corporate }} {{ brand_buttons }}:active:not(:disabled) { +:root[data-design-corporate] :is(.btn.primary, .sw-btn--primary, .sw-today__big--primary):active:not(:disabled) { border-color: var(--design-primary-active); background: var(--design-primary-active); } {% for name, status in [('danger', 'danger'), ('warn', 'warning'), ('info', 'info'), ('success', 'success')] %} -{{ corporate }} .callout.{{ name }} { +:root[data-design-corporate] .callout.{{ name }} { border-color: var(--design-{{ status }}-border); background: var(--design-{{ status }}-subtle); color: color-mix(in srgb, var(--design-{{ status }}) 82%, var(--design-text)); } {% endfor %} -{{ corporate }} .callout a { +:root[data-design-corporate] .callout a { color: inherit; text-decoration: underline; } -{{ corporate }} :is(.nav-item.active, .nav-item--active, .sidebar-recent-session--active) { +:root[data-design-corporate] :is(.nav-item.active, .nav-item--active, .sidebar-recent-session--active) { background: var(--design-surface-active); } {% if design.title is string %} -:root {{ brand_texts }} { +:root :is(.login-gate__title, .sidebar-brand__title, .topbar-brand__title, .dashboard-header__breadcrumb-link) { font-size: 0; } -:root {{ brand_texts }}::after { +:root :is(.login-gate__title, .sidebar-brand__title, .topbar-brand__title, .dashboard-header__breadcrumb-link)::after { content: {{ design.title | to_json(ensure_ascii=False) }}; } :root .login-gate__title::after { diff --git a/roles/web-app-openproject/files/logo.css b/roles/web-app-openproject/files/logo.css new file mode 100644 index 0000000000..8638b8149d --- /dev/null +++ b/roles/web-app-openproject/files/logo.css @@ -0,0 +1,7 @@ +body:is([data-color-mode='light'][data-light-theme='light'], [data-color-mode='dark'][data-dark-theme='dark']) .op-app-header .op-logo--link { + background-image: var(--design-url-logo-svg); +} + +body:is([data-color-mode='light'][data-light-theme='light'], [data-color-mode='dark'][data-dark-theme='dark']) .op-app-header :is(.op-logo--icon, .op-logo--icon_white) { + background-image: var(--design-url-icon-svg); +} diff --git a/roles/web-app-openproject/templates/style.css.j2 b/roles/web-app-openproject/files/style.css similarity index 84% rename from roles/web-app-openproject/templates/style.css.j2 rename to roles/web-app-openproject/files/style.css index 18de846a65..066a7b2da3 100644 --- a/roles/web-app-openproject/templates/style.css.j2 +++ b/roles/web-app-openproject/files/style.css @@ -1,6 +1,4 @@ -{% set design = lookup('design', application_id) %} -{% set themed = "body:is([data-color-mode='light'][data-light-theme='light'], [data-color-mode='dark'][data-dark-theme='dark'])" %} -{{ themed }} { +body:is([data-color-mode='light'][data-light-theme='light'], [data-color-mode='dark'][data-dark-theme='dark']) { --body-background: var(--design-surface-1); --bgColor-default: var(--design-surface-1); --main-menu-bg-color: var(--design-surface-1); @@ -80,7 +78,7 @@ --focus-outline: 2px solid var(--design-link); } -{{ themed }} .op-app-header { +body:is([data-color-mode='light'][data-light-theme='light'], [data-color-mode='dark'][data-dark-theme='dark']) .op-app-header { --design-focus: var(--design-on-frame); --focus-outlineColor: var(--design-on-frame); --focus-outline: 2px solid var(--design-on-frame); @@ -88,7 +86,7 @@ --control-transparent-bgColor-active: var(--design-frame-active); } -{{ themed }} .op-app-header :is([role='menu'], .Overlay) { +body:is([data-color-mode='light'][data-light-theme='light'], [data-color-mode='dark'][data-dark-theme='dark']) .op-app-header :is([role='menu'], .Overlay) { --design-focus: var(--design-link); --focus-outlineColor: var(--design-link); --focus-outline: 2px solid var(--design-link); @@ -96,25 +94,15 @@ --control-transparent-bgColor-active: var(--design-surface-active); } -{{ themed }} :is(.op-submenu--item-action_active, .op-submenu--item-action_active-child) { +body:is([data-color-mode='light'][data-light-theme='light'], [data-color-mode='dark'][data-dark-theme='dark']) :is(.op-submenu--item-action_active, .op-submenu--item-action_active-child) { --main-menu-bg-selected-background: var(--design-surface-active); } -{{ themed }} .menu-blocks--container .menu-block { +body:is([data-color-mode='light'][data-light-theme='light'], [data-color-mode='dark'][data-dark-theme='dark']) .menu-blocks--container .menu-block { background: var(--design-surface-2); } -{{ themed }} .menu-blocks--container .menu-block:hover { +body:is([data-color-mode='light'][data-light-theme='light'], [data-color-mode='dark'][data-dark-theme='dark']) .menu-blocks--container .menu-block:hover { background: var(--design-surface-hover); outline-color: var(--design-border-strong); } -{% if design.logo is string %} - -{{ themed }} .op-app-header .op-logo--link { - background-image: url("{{ design.urls.logo.svg }}"); -} - -{{ themed }} .op-app-header :is(.op-logo--icon, .op-logo--icon_white) { - background-image: url("{{ design.urls.icon.svg }}"); -} -{% endif %} diff --git a/roles/web-app-openproject/templates/design.js.j2 b/roles/web-app-openproject/templates/design.js similarity index 79% rename from roles/web-app-openproject/templates/design.js.j2 rename to roles/web-app-openproject/templates/design.js index a75bb90012..d9629690ce 100644 --- a/roles/web-app-openproject/templates/design.js.j2 +++ b/roles/web-app-openproject/templates/design.js @@ -1,11 +1,11 @@ (function () { - var root = document.documentElement; - var watched = null; - var observer = new MutationObserver(mirror); + const root = document.documentElement; + let watched = null; + const observer = new MutationObserver(mirror); function mirror() { - var body = document.body; + const body = document.body; if (!body) return; - var mode = body.getAttribute("data-color-mode"); + const mode = body.getAttribute("data-color-mode"); if (body.getAttribute("data-auto-theme-switcher-theme-value") === "sync_with_os" || (mode !== "light" && mode !== "dark")) { root.removeAttribute("data-design-theme"); } else if (root.getAttribute("data-design-theme") !== mode) { diff --git a/roles/web-app-opentalk/files/logo.css b/roles/web-app-opentalk/files/logo.css new file mode 100644 index 0000000000..47f99eed51 --- /dev/null +++ b/roles/web-app-opentalk/files/logo.css @@ -0,0 +1,6 @@ +svg[viewBox="0 0 206.392 45.061"] { + background: var(--design-url-logo-svg) left center / contain no-repeat; +} +svg[viewBox="0 0 206.392 45.061"] > * { + display: none; +} diff --git a/roles/web-app-opentalk/templates/style.css.j2 b/roles/web-app-opentalk/files/style.css similarity index 98% rename from roles/web-app-opentalk/templates/style.css.j2 rename to roles/web-app-opentalk/files/style.css index 97444c2685..f2df9b1f41 100644 --- a/roles/web-app-opentalk/templates/style.css.j2 +++ b/roles/web-app-opentalk/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} body, .loading-container { background: var(--design-frame); @@ -374,12 +373,3 @@ body:has([data-testid="toolbarEndCallButton"]) header > div > * > .MuiStack-root body:has([data-testid="toolbarEndCallButton"]) header > div > .MuiStack-root:not(:has(> .MuiStack-root)) svg { fill: var(--design-text); } -{% if design.logo is string %} - -svg[viewBox="0 0 206.392 45.061"] { - background: url("{{ design.urls.logo.svg }}") left center / contain no-repeat; -} -svg[viewBox="0 0 206.392 45.061"] > * { - display: none; -} -{% endif %} diff --git a/roles/web-app-opentalk/templates/design.js.j2 b/roles/web-app-opentalk/templates/design.js similarity index 51% rename from roles/web-app-opentalk/templates/design.js.j2 rename to roles/web-app-opentalk/templates/design.js index 7db54973f6..4d44d43ab8 100644 --- a/roles/web-app-opentalk/templates/design.js.j2 +++ b/roles/web-app-opentalk/templates/design.js @@ -1,20 +1,19 @@ -{% set design = lookup('design', application_id) %} (function () { - var root = document.documentElement; - var prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); - var recheck = 0; + const root = document.documentElement; + const prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); + let recheck = 0; function appMode() { if (!document.body) { return null; } - var channels = (getComputedStyle(document.body).color.match(/[\d.]+/g) || []).slice(0, 3).map(Number); + const channels = (getComputedStyle(document.body).color.match(/[\d.]+/g) || []).slice(0, 3).map(Number); if (channels.length < 3) { return null; } return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2] > 127 ? "dark" : "light"; } function mirror() { - var mode = appMode(); + const mode = appMode(); if (mode === null || mode === (prefersDark.matches ? "dark" : "light")) { root.removeAttribute("data-design-theme"); } else if (root.getAttribute("data-design-theme") !== mode) { @@ -22,21 +21,21 @@ } } function brand() { -{% if design.title is string %} - var wanted = document.title.replace(/OpenTalk/g, {{ design.title | to_json }}); - if (document.title !== wanted) { - document.title = wanted; - } -{% endif %} -{% if design.logo is string %} - var icons = document.querySelectorAll("link[rel~='icon'], link[rel='apple-touch-icon']"); - for (var index = 0; index < icons.length; index += 1) { - if (icons[index].getAttribute("href") !== {{ design.urls.favicon_ico | to_json }}) { - icons[index].setAttribute("type", "image/x-icon"); - icons[index].setAttribute("href", {{ design.urls.favicon_ico | to_json }}); + if (INFINITO_DESIGN.title) { + const wanted = document.title.replace(/OpenTalk/g, INFINITO_DESIGN.title); + if (document.title !== wanted) { + document.title = wanted; } - } -{% endif %} + } + if (INFINITO_DESIGN.logo) { + const icons = document.querySelectorAll("link[rel~='icon'], link[rel='apple-touch-icon']"); + for (let index = 0; index < icons.length; index += 1) { + if (icons[index].getAttribute("href") !== INFINITO_DESIGN.urls.favicon_ico) { + icons[index].setAttribute("type", "image/x-icon"); + icons[index].setAttribute("href", INFINITO_DESIGN.urls.favicon_ico); + } + } + } } function refresh() { mirror(); diff --git a/roles/web-app-openwebui/templates/design.js.j2 b/roles/web-app-openwebui/templates/design.js similarity index 89% rename from roles/web-app-openwebui/templates/design.js.j2 rename to roles/web-app-openwebui/templates/design.js index 6c2d52dde5..3a80e7a7a5 100644 --- a/roles/web-app-openwebui/templates/design.js.j2 +++ b/roles/web-app-openwebui/templates/design.js @@ -1,10 +1,10 @@ (function () { - var root = document.documentElement; + const root = document.documentElement; function chosen() { try { return window.localStorage.getItem("theme") || "system"; - } catch (error) { + } catch { return "system"; } } @@ -18,7 +18,7 @@ } function mirror() { - var theme = chosen(); + const theme = chosen(); assign("data-design-app-theme", theme); assign("data-design-theme", theme === "system" ? null : root.classList.contains("dark") ? "dark" : "light"); } diff --git a/roles/web-app-peertube/templates/custom.css.j2 b/roles/web-app-peertube/files/custom.css similarity index 100% rename from roles/web-app-peertube/templates/custom.css.j2 rename to roles/web-app-peertube/files/custom.css diff --git a/roles/web-app-peertube/templates/design.js.j2 b/roles/web-app-peertube/templates/design.js similarity index 69% rename from roles/web-app-peertube/templates/design.js.j2 rename to roles/web-app-peertube/templates/design.js index 854614a67a..17447f9b18 100644 --- a/roles/web-app-peertube/templates/design.js.j2 +++ b/roles/web-app-peertube/templates/design.js @@ -1,8 +1,8 @@ (function () { - var root = document.documentElement; - var browserDark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; + const root = document.documentElement; + const browserDark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; function mirror() { - var theme = root.getAttribute("data-pt-theme") || ""; + const theme = root.getAttribute("data-pt-theme") || ""; if (theme === "peertube-core-light-beige") { root.setAttribute("data-design-theme", "light"); } else if (theme === "peertube-core-dark-brown" && !browserDark) { diff --git a/roles/web-app-peertube/templates/env.j2 b/roles/web-app-peertube/templates/env.j2 index a16f832d7c..51a0d728b2 100644 --- a/roles/web-app-peertube/templates/env.j2 +++ b/roles/web-app-peertube/templates/env.j2 @@ -65,7 +65,7 @@ PT_INITIAL_ROOT_PASSWORD={{ PEERTUBE_ROOT_PASSWORD | dotenv_quote }} {% for key, token in PEERTUBE_DESIGN_THEME.items() %} PEERTUBE_THEME_CUSTOMIZATION_{{ key }}={{ ('var(' ~ token ~ ')') | to_json | dotenv_quote }} {% endfor %} -PEERTUBE_INSTANCE_CUSTOMIZATIONS_CSS={{ lookup('template', 'custom.css.j2') | regex_replace('\\s*\\n\\s*', ' ') | trim | dotenv_quote }} +PEERTUBE_INSTANCE_CUSTOMIZATIONS_CSS={{ lookup('file', 'custom.css') | regex_replace('\\s*\\n\\s*', ' ') | trim | dotenv_quote }} {% if PEERTUBE_DESIGN.title is string %} PEERTUBE_INSTANCE_NAME={{ PEERTUBE_DESIGN.title | dotenv_quote }} {% endif %} diff --git a/roles/web-app-peertube/templates/style.css.j2 b/roles/web-app-peertube/templates/style.css.j2 deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/roles/web-app-penpot/templates/design.js b/roles/web-app-penpot/templates/design.js new file mode 100644 index 0000000000..7c9cd95487 --- /dev/null +++ b/roles/web-app-penpot/templates/design.js @@ -0,0 +1,81 @@ +(function () { + const root = document.documentElement; + function visitor() { + return window.location.hash.indexOf("#/auth/") === 0; + } + function mirror() { + const body = document.body; + let theme = null; + if (body && !visitor()) { + if (body.classList.contains("light")) { + theme = "light"; + } else if (body.classList.contains("default")) { + theme = "dark"; + } + } + if (theme) { + root.setAttribute("data-design-theme", theme); + } else { + root.removeAttribute("data-design-theme"); + } + } + function watchBody() { + new MutationObserver(mirror).observe(document.body, { attributes: true, attributeFilter: ["class"] }); + mirror(); + } + ["pushState", "replaceState"].forEach(function (name) { + const original = window.history[name]; + window.history[name] = function () { + const result = original.apply(this, arguments); + mirror(); + return result; + }; + }); + window.addEventListener("hashchange", mirror); + window.addEventListener("popstate", mirror); + if (document.body) { + watchBody(); + } else { + document.addEventListener("DOMContentLoaded", watchBody); + } + if (INFINITO_DESIGN.title) { + const title = INFINITO_DESIGN.title; + function brandTitle() { + const current = document.title; + let page = current.replace(/\s*\|\s*Full-stack design$/, ""); + if (page.slice(-title.length) !== title) { + page = page.replace(/(^|\s-\s)Penpot$/, ""); + page = page ? `${page } - ${ title}` : title; + } + if (page !== current) { + document.title = page; + } + } + function watchTitle() { + const element = document.querySelector("title"); + if (!element) { + return false; + } + new MutationObserver(brandTitle).observe(element, { childList: true, characterData: true, subtree: true }); + brandTitle(); + return true; + } + if (!watchTitle()) { + document.addEventListener("DOMContentLoaded", watchTitle); + } + } + if (INFINITO_DESIGN.logo) { + function brandIcon() { + const icons = document.querySelectorAll("link[rel~='icon']"); + for (let index = 0; index < icons.length; index += 1) { + if (icons[index].getAttribute("href") !== INFINITO_DESIGN.urls.favicon_ico) { + icons[index].setAttribute("type", "image/x-icon"); + icons[index].setAttribute("href", INFINITO_DESIGN.urls.favicon_ico); + } + } + } + new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); + brandIcon(); + document.addEventListener("DOMContentLoaded", brandIcon); + } +})(); diff --git a/roles/web-app-penpot/templates/design.js.j2 b/roles/web-app-penpot/templates/design.js.j2 deleted file mode 100644 index da72236dee..0000000000 --- a/roles/web-app-penpot/templates/design.js.j2 +++ /dev/null @@ -1,82 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var root = document.documentElement; - function visitor() { - return window.location.hash.indexOf("#/auth/") === 0; - } - function mirror() { - var body = document.body; - var theme = null; - if (body && !visitor()) { - if (body.classList.contains("light")) { - theme = "light"; - } else if (body.classList.contains("default")) { - theme = "dark"; - } - } - if (theme) { - root.setAttribute("data-design-theme", theme); - } else { - root.removeAttribute("data-design-theme"); - } - } - function watchBody() { - new MutationObserver(mirror).observe(document.body, { attributes: true, attributeFilter: ["class"] }); - mirror(); - } - ["pushState", "replaceState"].forEach(function (name) { - var original = window.history[name]; - window.history[name] = function () { - var result = original.apply(this, arguments); - mirror(); - return result; - }; - }); - window.addEventListener("hashchange", mirror); - window.addEventListener("popstate", mirror); - if (document.body) { - watchBody(); - } else { - document.addEventListener("DOMContentLoaded", watchBody); - } -{% if design.title is string %} - var title = {{ design.title | to_json }}; - function brandTitle() { - var current = document.title; - var page = current.replace(/\s*\|\s*Full-stack design$/, ""); - if (page.slice(-title.length) !== title) { - page = page.replace(/(^|\s-\s)Penpot$/, ""); - page = page ? page + " - " + title : title; - } - if (page !== current) { - document.title = page; - } - } - function watchTitle() { - var element = document.querySelector("title"); - if (!element) { - return false; - } - new MutationObserver(brandTitle).observe(element, { childList: true, characterData: true, subtree: true }); - brandTitle(); - return true; - } - if (!watchTitle()) { - document.addEventListener("DOMContentLoaded", watchTitle); - } -{% endif %} -{% if design.logo is string %} - function brandIcon() { - var icons = document.querySelectorAll("link[rel~='icon']"); - for (var index = 0; index < icons.length; index += 1) { - if (icons[index].getAttribute("href") !== {{ design.urls.favicon_ico | to_json }}) { - icons[index].setAttribute("type", "image/x-icon"); - icons[index].setAttribute("href", {{ design.urls.favicon_ico | to_json }}); - } - } - } - new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); - brandIcon(); - document.addEventListener("DOMContentLoaded", brandIcon); -{% endif %} -})(); diff --git a/roles/web-app-pgadmin/files/logo.css b/roles/web-app-pgadmin/files/logo.css new file mode 100644 index 0000000000..4d366d4a02 --- /dev/null +++ b/roles/web-app-pgadmin/files/logo.css @@ -0,0 +1,7 @@ +html body #root [data-test="app-menu-bar"] .AppMenuBar-logo { + background: var(--design-url-logo-svg) center / contain no-repeat; +} + +html body #root .BasePage-logo { + background: var(--design-url-login-logo-svg) center / contain no-repeat; +} diff --git a/roles/web-app-pgadmin/files/style.css b/roles/web-app-pgadmin/files/style.css new file mode 100644 index 0000000000..4fe3b4f5af --- /dev/null +++ b/roles/web-app-pgadmin/files/style.css @@ -0,0 +1,197 @@ +html:not([data-pgadmin-theme="high_contrast"]) body { + background-color: var(--design-surface-1); + color: var(--design-text); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .dock-layout .dock-content, +html:not([data-pgadmin-theme="high_contrast"]) body .dock-layout .dock-bar, +html:not([data-pgadmin-theme="high_contrast"]) body .dock-layout .dock-panel .dock-tabpane { + background-color: var(--design-surface-1); + color: var(--design-text); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .dock-layout .dock-tab { + color: var(--design-text-muted); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .dock-layout .dock-tab.dock-tab-active { + color: var(--design-link); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .dock-layout .dock-ink-bar { + background-color: var(--design-primary); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .dock-layout .dock-divider::before { + background-color: var(--design-border); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .file-tree { + color: var(--design-text) !important; + background-color: var(--design-surface-1) !important; +} + +html:not([data-pgadmin-theme="high_contrast"]) body .file-entry:hover, +html:not([data-pgadmin-theme="high_contrast"]) body .file-entry.pseudo-active { + color: var(--design-text) !important; + background-color: var(--design-surface-hover) !important; +} + +html:not([data-pgadmin-theme="high_contrast"]) body .file-entry.active, +html:not([data-pgadmin-theme="high_contrast"]) body .file-entry.prompt { + color: var(--design-text) !important; + background-color: var(--design-surface-active) !important; +} + +html:not([data-pgadmin-theme="high_contrast"]) body [data-test="app-menu-bar"] { + --design-focus: var(--design-on-frame); + background-color: var(--design-frame); + color: var(--design-on-frame); +} + +html:not([data-pgadmin-theme="high_contrast"]) body [data-test="app-menu-bar"] .MuiButton-root { + background-color: var(--design-frame); + color: var(--design-on-frame); + border-color: var(--design-frame); +} + +html:not([data-pgadmin-theme="high_contrast"]) body [data-test="app-menu-bar"] .MuiButton-root:hover { + background-color: var(--design-frame-hover); +} + +html:not([data-pgadmin-theme="high_contrast"]) body [data-test="app-menu-bar"] .MuiButton-root[aria-expanded="true"] { + background-color: var(--design-frame-active); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .szh-menu { + --design-focus: var(--design-link); + background-color: var(--design-surface-2); + color: var(--design-text); + border-color: var(--design-border); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiPaper-root, +html:not([data-pgadmin-theme="high_contrast"]) body .MuiDialog-paper { + background-color: var(--design-surface-2); + color: var(--design-text); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiTabs-root, +html:not([data-pgadmin-theme="high_contrast"]) body .MuiAccordionSummary-root, +html:not([data-pgadmin-theme="high_contrast"]) body .MuiCardHeader-root { + background-color: var(--design-surface-2); + border-color: var(--design-border); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiTab-root.Mui-selected { + color: var(--design-link); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiTabs-indicator { + background-color: var(--design-primary); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiInputBase-root, +html:not([data-pgadmin-theme="high_contrast"]) body .MuiInputBase-input { + background-color: var(--design-surface-2); + color: var(--design-text); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiOutlinedInput-notchedOutline { + border-color: var(--design-border-strong); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiInputBase-root.Mui-disabled, +html:not([data-pgadmin-theme="high_contrast"]) body .MuiInputBase-input[readonly] { + background-color: var(--design-surface-3); + color: var(--design-text-muted); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiFormLabel-root { + color: var(--design-text); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiFormHelperText-root, +html:not([data-pgadmin-theme="high_contrast"]) body .text-muted { + color: var(--design-text-muted); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiButton-containedPrimary { + background-color: var(--design-primary); + color: var(--design-on-primary); + border-color: var(--design-primary); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiButton-containedPrimary:hover { + background-color: var(--design-primary-hover); + border-color: var(--design-primary-hover); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiButton-outlined { + background-color: var(--design-surface-2); + color: var(--design-text); + border-color: var(--design-border-strong); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiButton-outlined:hover { + background-color: var(--design-surface-hover); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiListItemButton-root.Mui-selected, +html:not([data-pgadmin-theme="high_contrast"]) body .MuiToggleButton-root.Mui-selected { + background-color: var(--design-surface-active); + color: var(--design-text); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .MuiTooltip-tooltip { + background-color: var(--design-text); + color: var(--design-surface-1); +} + +html:not([data-pgadmin-theme="high_contrast"]) body a { + color: var(--design-link); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .cm-editor { + background-color: var(--design-surface-1); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .cm-editor .cm-gutters { + background-color: var(--design-surface-3); + color: var(--design-text-muted); + border-color: var(--design-border); +} + +html:not([data-pgadmin-theme="high_contrast"]) body .cm-editor .cm-activeLine { + background-color: var(--design-surface-hover); +} + +html:not([data-pgadmin-theme="high_contrast"]) body [data-test="app-menu-bar"] .MuiButton-root:focus-visible, +html:not([data-pgadmin-theme="high_contrast"]) body [data-test="app-menu-bar"] .MuiButton-root.Mui-focusVisible { + outline: 2px solid var(--design-focus); + outline-offset: -2px; +} + +html body #root > div:has(> div > .BasePage-pageContent) { + background-color: var(--design-frame); + color: var(--design-on-frame); +} + +html body #root .BasePage-pageContent { + background-color: var(--design-frame-active); + color: var(--design-on-frame); +} + +html body #root .BasePage-pageContent a { + color: var(--design-on-frame); +} + +html body #root .BasePage-pageContent .MuiButton-root.MuiButton-outlinedPrimary { + background-color: var(--design-primary); + border-color: var(--design-primary); + color: var(--design-on-primary); +} + +html body #root .BasePage-pageContent .MuiButton-root.MuiButton-outlinedPrimary:hover { + background-color: var(--design-primary-hover); +} diff --git a/roles/web-app-pgadmin/templates/design.js.j2 b/roles/web-app-pgadmin/templates/design.js similarity index 51% rename from roles/web-app-pgadmin/templates/design.js.j2 rename to roles/web-app-pgadmin/templates/design.js index 8076112ea7..5f62f5e094 100644 --- a/roles/web-app-pgadmin/templates/design.js.j2 +++ b/roles/web-app-pgadmin/templates/design.js @@ -1,6 +1,5 @@ -{% set design = lookup('design', application_id) %} (function () { - var root = document.documentElement; + const root = document.documentElement; function mirror(theme) { if (theme === "light" || theme === "dark") { root.setAttribute("data-design-theme", theme); @@ -14,13 +13,13 @@ } } function picked(message) { - var data = message && message.data; + const data = message && message.data; if (!data || typeof data !== "object") { return; } - var entries = Array.isArray(data) ? data : Object.keys(data).map(function (key) { return data[key]; }); - for (var index = 0; index < entries.length; index += 1) { - var entry = entries[index]; + const entries = Array.isArray(data) ? data : Object.keys(data).map(function (key) { return data[key]; }); + for (let index = 0; index < entries.length; index += 1) { + const entry = entries[index]; if (entry && entry.module === "misc" && entry.name === "theme") { mirror(entry.value); return; @@ -36,24 +35,24 @@ } }); if (typeof window.BroadcastChannel === "function") { - var channel = new window.BroadcastChannel("preference-change"); + const channel = new window.BroadcastChannel("preference-change"); channel.onmessage = function (event) { picked(event.data); }; channel.postMessage("sync"); } -{% if design.logo is string %} - var favicon = {{ design.urls.favicon_ico | to_json }}; - function brandIcon() { - var icons = document.querySelectorAll("link[rel~='icon']"); - for (var index = 0; index < icons.length; index += 1) { - if (icons[index].getAttribute("href") !== favicon) { - icons[index].setAttribute("type", "image/x-icon"); - icons[index].setAttribute("href", favicon); + if (INFINITO_DESIGN.logo) { + const favicon = INFINITO_DESIGN.urls.favicon_ico; + function brandIcon() { + const icons = document.querySelectorAll("link[rel~='icon']"); + for (let index = 0; index < icons.length; index += 1) { + if (icons[index].getAttribute("href") !== favicon) { + icons[index].setAttribute("type", "image/x-icon"); + icons[index].setAttribute("href", favicon); + } } } + new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); + brandIcon(); } - new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); - brandIcon(); -{% endif %} })(); diff --git a/roles/web-app-pgadmin/templates/style.css.j2 b/roles/web-app-pgadmin/templates/style.css.j2 deleted file mode 100644 index f8b8eb15ef..0000000000 --- a/roles/web-app-pgadmin/templates/style.css.j2 +++ /dev/null @@ -1,209 +0,0 @@ -{% set design = lookup('design', application_id) %} -{% set scope = 'html:not([data-pgadmin-theme="high_contrast"]) body' %} -{{ scope }} { - background-color: var(--design-surface-1); - color: var(--design-text); -} - -{{ scope }} .dock-layout .dock-content, -{{ scope }} .dock-layout .dock-bar, -{{ scope }} .dock-layout .dock-panel .dock-tabpane { - background-color: var(--design-surface-1); - color: var(--design-text); -} - -{{ scope }} .dock-layout .dock-tab { - color: var(--design-text-muted); -} - -{{ scope }} .dock-layout .dock-tab.dock-tab-active { - color: var(--design-link); -} - -{{ scope }} .dock-layout .dock-ink-bar { - background-color: var(--design-primary); -} - -{{ scope }} .dock-layout .dock-divider::before { - background-color: var(--design-border); -} - -{{ scope }} .file-tree { - color: var(--design-text) !important; - background-color: var(--design-surface-1) !important; -} - -{{ scope }} .file-entry:hover, -{{ scope }} .file-entry.pseudo-active { - color: var(--design-text) !important; - background-color: var(--design-surface-hover) !important; -} - -{{ scope }} .file-entry.active, -{{ scope }} .file-entry.prompt { - color: var(--design-text) !important; - background-color: var(--design-surface-active) !important; -} - -{{ scope }} [data-test="app-menu-bar"] { - --design-focus: var(--design-on-frame); - background-color: var(--design-frame); - color: var(--design-on-frame); -} - -{{ scope }} [data-test="app-menu-bar"] .MuiButton-root { - background-color: var(--design-frame); - color: var(--design-on-frame); - border-color: var(--design-frame); -} - -{{ scope }} [data-test="app-menu-bar"] .MuiButton-root:hover { - background-color: var(--design-frame-hover); -} - -{{ scope }} [data-test="app-menu-bar"] .MuiButton-root[aria-expanded="true"] { - background-color: var(--design-frame-active); -} - -{{ scope }} .szh-menu { - --design-focus: var(--design-link); - background-color: var(--design-surface-2); - color: var(--design-text); - border-color: var(--design-border); -} - -{{ scope }} .MuiPaper-root, -{{ scope }} .MuiDialog-paper { - background-color: var(--design-surface-2); - color: var(--design-text); -} - -{{ scope }} .MuiTabs-root, -{{ scope }} .MuiAccordionSummary-root, -{{ scope }} .MuiCardHeader-root { - background-color: var(--design-surface-2); - border-color: var(--design-border); -} - -{{ scope }} .MuiTab-root.Mui-selected { - color: var(--design-link); -} - -{{ scope }} .MuiTabs-indicator { - background-color: var(--design-primary); -} - -{{ scope }} .MuiInputBase-root, -{{ scope }} .MuiInputBase-input { - background-color: var(--design-surface-2); - color: var(--design-text); -} - -{{ scope }} .MuiOutlinedInput-notchedOutline { - border-color: var(--design-border-strong); -} - -{{ scope }} .MuiInputBase-root.Mui-disabled, -{{ scope }} .MuiInputBase-input[readonly] { - background-color: var(--design-surface-3); - color: var(--design-text-muted); -} - -{{ scope }} .MuiFormLabel-root { - color: var(--design-text); -} - -{{ scope }} .MuiFormHelperText-root, -{{ scope }} .text-muted { - color: var(--design-text-muted); -} - -{{ scope }} .MuiButton-containedPrimary { - background-color: var(--design-primary); - color: var(--design-on-primary); - border-color: var(--design-primary); -} - -{{ scope }} .MuiButton-containedPrimary:hover { - background-color: var(--design-primary-hover); - border-color: var(--design-primary-hover); -} - -{{ scope }} .MuiButton-outlined { - background-color: var(--design-surface-2); - color: var(--design-text); - border-color: var(--design-border-strong); -} - -{{ scope }} .MuiButton-outlined:hover { - background-color: var(--design-surface-hover); -} - -{{ scope }} .MuiListItemButton-root.Mui-selected, -{{ scope }} .MuiToggleButton-root.Mui-selected { - background-color: var(--design-surface-active); - color: var(--design-text); -} - -{{ scope }} .MuiTooltip-tooltip { - background-color: var(--design-text); - color: var(--design-surface-1); -} - -{{ scope }} a { - color: var(--design-link); -} - -{{ scope }} .cm-editor { - background-color: var(--design-surface-1); -} - -{{ scope }} .cm-editor .cm-gutters { - background-color: var(--design-surface-3); - color: var(--design-text-muted); - border-color: var(--design-border); -} - -{{ scope }} .cm-editor .cm-activeLine { - background-color: var(--design-surface-hover); -} - -{{ scope }} [data-test="app-menu-bar"] .MuiButton-root:focus-visible, -{{ scope }} [data-test="app-menu-bar"] .MuiButton-root.Mui-focusVisible { - outline: 2px solid var(--design-focus); - outline-offset: -2px; -} - -html body #root > div:has(> div > .BasePage-pageContent) { - background-color: var(--design-frame); - color: var(--design-on-frame); -} - -html body #root .BasePage-pageContent { - background-color: var(--design-frame-active); - color: var(--design-on-frame); -} - -html body #root .BasePage-pageContent a { - color: var(--design-on-frame); -} - -html body #root .BasePage-pageContent .MuiButton-root.MuiButton-outlinedPrimary { - background-color: var(--design-primary); - border-color: var(--design-primary); - color: var(--design-on-primary); -} - -html body #root .BasePage-pageContent .MuiButton-root.MuiButton-outlinedPrimary:hover { - background-color: var(--design-primary-hover); -} -{% if design.logo is string %} - -html body #root [data-test="app-menu-bar"] .AppMenuBar-logo { - background: url("{{ design.urls.logo.svg }}") center / contain no-repeat; -} - -html body #root .BasePage-logo { - background: url("{{ design.urls['login-logo'].svg }}") center / contain no-repeat; -} -{% endif %} diff --git a/roles/web-app-pihole/templates/design.js b/roles/web-app-pihole/templates/design.js new file mode 100644 index 0000000000..5456b0e83c --- /dev/null +++ b/roles/web-app-pihole/templates/design.js @@ -0,0 +1,59 @@ +(function () { + const root = document.documentElement; + const modes = { + "default-light": "light", + "high-contrast": "light", + "default-dark": "dark", + "default-darker": "dark", + "high-contrast-dark": "dark", + "lcars": "dark" + }; + function mirror() { + const links = document.querySelectorAll("link[rel='stylesheet'][href*='style/themes/']"); + let theme = null; + if (links.length === 1) { + const name = (links[0].getAttribute("href") || "").split("style/themes/")[1].split(".css")[0]; + theme = Object.prototype.hasOwnProperty.call(modes, name) ? modes[name] : null; + } + if (theme) { + root.setAttribute("data-design-theme", theme); + } else { + root.removeAttribute("data-design-theme"); + } + } + function brand() { + if (INFINITO_DESIGN.title) { + if (document.title !== INFINITO_DESIGN.title) { + document.title = INFINITO_DESIGN.title; + } + const marks = document.querySelectorAll(".main-header .logo .logo-lg, .login-logo .logo-lg"); + for (let mark = 0; mark < marks.length; mark += 1) { + if (marks[mark].textContent !== INFINITO_DESIGN.title) { + marks[mark].textContent = INFINITO_DESIGN.title; + } + } + } + if (INFINITO_DESIGN.logo) { + const icons = document.querySelectorAll("link[rel~='icon']"); + for (let icon = 0; icon < icons.length; icon += 1) { + if (icons[icon].getAttribute("href") !== INFINITO_DESIGN.urls.favicon_ico) { + icons[icon].removeAttribute("sizes"); + icons[icon].setAttribute("type", "image/x-icon"); + icons[icon].setAttribute("href", INFINITO_DESIGN.urls.favicon_ico); + } + } + const touch = document.querySelector("link[rel='apple-touch-icon']"); + if (touch && touch.getAttribute("href") !== INFINITO_DESIGN.urls['apple-touch-icon'].png) { + touch.setAttribute("href", INFINITO_DESIGN.urls['apple-touch-icon'].png); + } + } + } + function apply() { + mirror(); + if (INFINITO_DESIGN.title || INFINITO_DESIGN.logo) { + brand(); + } + } + apply(); + document.addEventListener("DOMContentLoaded", apply); +})(); diff --git a/roles/web-app-pihole/templates/design.js.j2 b/roles/web-app-pihole/templates/design.js.j2 deleted file mode 100644 index 885f4e689b..0000000000 --- a/roles/web-app-pihole/templates/design.js.j2 +++ /dev/null @@ -1,62 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var root = document.documentElement; - var modes = { - "default-light": "light", - "high-contrast": "light", - "default-dark": "dark", - "default-darker": "dark", - "high-contrast-dark": "dark", - "lcars": "dark" - }; - function mirror() { - var links = document.querySelectorAll("link[rel='stylesheet'][href*='style/themes/']"); - var theme = null; - if (links.length === 1) { - var name = (links[0].getAttribute("href") || "").split("style/themes/")[1].split(".css")[0]; - theme = Object.prototype.hasOwnProperty.call(modes, name) ? modes[name] : null; - } - if (theme) { - root.setAttribute("data-design-theme", theme); - } else { - root.removeAttribute("data-design-theme"); - } - } -{% if design.title is string or design.logo is string %} - function brand() { -{% if design.title is string %} - if (document.title !== {{ design.title | to_json }}) { - document.title = {{ design.title | to_json }}; - } - var marks = document.querySelectorAll(".main-header .logo .logo-lg, .login-logo .logo-lg"); - for (var mark = 0; mark < marks.length; mark += 1) { - if (marks[mark].textContent !== {{ design.title | to_json }}) { - marks[mark].textContent = {{ design.title | to_json }}; - } - } -{% endif %} -{% if design.logo is string %} - var icons = document.querySelectorAll("link[rel~='icon']"); - for (var icon = 0; icon < icons.length; icon += 1) { - if (icons[icon].getAttribute("href") !== {{ design.urls.favicon_ico | to_json }}) { - icons[icon].removeAttribute("sizes"); - icons[icon].setAttribute("type", "image/x-icon"); - icons[icon].setAttribute("href", {{ design.urls.favicon_ico | to_json }}); - } - } - var touch = document.querySelector("link[rel='apple-touch-icon']"); - if (touch && touch.getAttribute("href") !== {{ design.urls['apple-touch-icon'].png | to_json }}) { - touch.setAttribute("href", {{ design.urls['apple-touch-icon'].png | to_json }}); - } -{% endif %} - } -{% endif %} - function apply() { - mirror(); -{% if design.title is string or design.logo is string %} - brand(); -{% endif %} - } - apply(); - document.addEventListener("DOMContentLoaded", apply); -})(); diff --git a/roles/web-app-pihole/templates/style.css.j2 b/roles/web-app-pihole/templates/style.css.j2 index 36274fcc47..fd6e4d281b 100644 --- a/roles/web-app-pihole/templates/style.css.j2 +++ b/roles/web-app-pihole/templates/style.css.j2 @@ -1,10 +1,9 @@ {% set design = lookup('design', application_id) %} -{% set default_theme = 'html:has(link[href*="style/themes/default-light.css"], link[href*="style/themes/default-dark.css"])' %} {% set fills = ['primary', 'success', 'info', 'warning', 'danger'] %} {% set statuses = ['success', 'info', 'warning', 'danger'] %} {% set named_fills = [('red', 'danger'), ('yellow', 'warning'), ('aqua', 'info'), ('green', 'success'), ('light-blue', 'primary')] %} {% set named_texts = [('red', 'danger'), ('green', 'success'), ('green-light', 'success'), ('orange', 'warning'), ('yellow', 'warning'), ('aqua', 'info'), ('blue', 'info'), ('light-blue', 'info'), ('vivid-blue', 'info'), ('danger', 'danger'), ('success', 'success'), ('warning', 'warning'), ('info', 'info')] %} -{{ default_theme }} { +html:has(link[href*="style/themes/default-light.css"], link[href*="style/themes/default-dark.css"]) { --datatable-bgcolor: var(--design-surface-active); --overlay-bgcolor: rgba(var(--design-surface-3-rgb), 0.85); --allowed-color: var(--design-success); @@ -13,7 +12,7 @@ --other-color: var(--design-neutral-500); background-color: var(--design-surface-3); } -:where({{ default_theme }}) { +:where(html:has(link[href*="style/themes/default-light.css"], link[href*="style/themes/default-dark.css"])) { & body, .layout-boxed { background: var(--design-surface-3); diff --git a/roles/web-app-pixelfed/files/logo.css b/roles/web-app-pixelfed/files/logo.css new file mode 100644 index 0000000000..43e1f5b952 --- /dev/null +++ b/roles/web-app-pixelfed/files/logo.css @@ -0,0 +1,10 @@ +nav.metro-nav .navbar-brand img, +nav.navbar-laravel .navbar-brand img, +#content > nav.navbar.fixed-top .navbar-brand img, +.page-wrapper a > img[src*="pixelfed-icon-white"] { + content: var(--design-url-logo-svg); +} + +.sidenav .navbar-brand .navbar-brand-img { + content: var(--design-url-brand-svg); +} diff --git a/roles/web-app-pixelfed/templates/style.css.j2 b/roles/web-app-pixelfed/files/style.css similarity index 99% rename from roles/web-app-pixelfed/templates/style.css.j2 rename to roles/web-app-pixelfed/files/style.css index eb6a1584e3..2a18cfbf90 100644 --- a/roles/web-app-pixelfed/templates/style.css.j2 +++ b/roles/web-app-pixelfed/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} :where(html:has(> head > link[href*="/css/app.css"])) { & .form-control.focus { background-color: var(--design-surface-2); @@ -10923,7 +10922,7 @@ } & .page-wrapper { background-color: var(--design-surface-3) !important; - background-image: url({{ PIXELFED_URL }}/_landing/bg.jpg); + background-image: var(--design-url-app-landing-bg); } & .bg-glass { background-color: rgba(var(--design-surface-2-rgb), 0.05); @@ -11364,16 +11363,3 @@ main#content .settings-nav { background: var(--design-primary); color: var(--design-on-primary); } -{% if design.logo is string %} - -nav.metro-nav .navbar-brand img, -nav.navbar-laravel .navbar-brand img, -#content > nav.navbar.fixed-top .navbar-brand img, -.page-wrapper a > img[src*="pixelfed-icon-white"] { - content: url("{{ design.urls.logo.svg }}"); -} - -.sidenav .navbar-brand .navbar-brand-img { - content: url("{{ design.urls.brand.svg }}"); -} -{% endif %} diff --git a/roles/web-app-pixelfed/templates/design.js.j2 b/roles/web-app-pixelfed/templates/design.js similarity index 53% rename from roles/web-app-pixelfed/templates/design.js.j2 rename to roles/web-app-pixelfed/templates/design.js index 424f8d0d19..552083f7e2 100644 --- a/roles/web-app-pixelfed/templates/design.js.j2 +++ b/roles/web-app-pixelfed/templates/design.js @@ -1,27 +1,26 @@ -{% set design = lookup('design', application_id) %} (function () { - var root = document.documentElement; - var key = "pf_m2s.color-scheme"; + const root = document.documentElement; + const key = "pf_m2s.color-scheme"; function stored() { try { return window.localStorage.getItem(key); - } catch (error) { + } catch { return null; } } function chosen() { - var body = document.body; + const body = document.body; if (body && body.classList.contains("force-dark-mode")) { return "dark"; } if (body && body.classList.contains("force-light-mode")) { return "light"; } - var value = stored(); + const value = stored(); return value === "dark" || value === "light" ? value : null; } function mirror() { - var theme = chosen(); + const theme = chosen(); if (theme) { root.setAttribute("data-design-theme", theme); } else { @@ -43,17 +42,17 @@ } else { document.addEventListener("DOMContentLoaded", watchBody); } -{% if design.logo is string %} - function brandIcon() { - var icons = document.querySelectorAll("link[rel~='icon'], link[rel='apple-touch-icon']"); - for (var index = 0; index < icons.length; index += 1) { - if (icons[index].getAttribute("href") !== {{ design.urls.favicon_ico | to_json }}) { - icons[index].setAttribute("type", "image/x-icon"); - icons[index].setAttribute("href", {{ design.urls.favicon_ico | to_json }}); + if (INFINITO_DESIGN.logo) { + function brandIcon() { + const icons = document.querySelectorAll("link[rel~='icon'], link[rel='apple-touch-icon']"); + for (let index = 0; index < icons.length; index += 1) { + if (icons[index].getAttribute("href") !== INFINITO_DESIGN.urls.favicon_ico) { + icons[index].setAttribute("type", "image/x-icon"); + icons[index].setAttribute("href", INFINITO_DESIGN.urls.favicon_ico); + } } } + new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); + brandIcon(); } - new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); - brandIcon(); -{% endif %} })(); diff --git a/roles/web-app-pixelfed/vars/main.yml b/roles/web-app-pixelfed/vars/main.yml index 6dfdd2808d..ad126cf192 100644 --- a/roles/web-app-pixelfed/vars/main.yml +++ b/roles/web-app-pixelfed/vars/main.yml @@ -26,3 +26,6 @@ PIXELFED_ADMIN_EMAIL: "{{ lookup('users', IAM_PLATFORM_ADMIN_USER_KEY).email }}" PIXELFED_ADMIN_PASSWORD: "{{ lookup('users', IAM_PLATFORM_ADMIN_USER_KEY).password }}" PIXELFED_ADMIN_NAME: "{{ (lookup('users', IAM_PLATFORM_ADMIN_USER_KEY).firstname ~ ' ' ~ lookup('users', IAM_PLATFORM_ADMIN_USER_KEY).lastname) | trim }}" PIXELFED_ADMIN_OIDC_ID: "{{ PIXELFED_ADMIN_USERNAME }}" + +design_css_urls: + landing-bg: "{{ PIXELFED_URL }}/_landing/bg.jpg" diff --git a/roles/web-app-postmarks/TODO.md b/roles/web-app-postmarks/TODO.md index 0d099622f2..beeac0687c 100644 --- a/roles/web-app-postmarks/TODO.md +++ b/roles/web-app-postmarks/TODO.md @@ -4,5 +4,5 @@ - `PUBLIC_BASE_URL` is not rendered into `templates/env.j2`, so the app falls back to `localhost`: every page links its feed and OpenSearch description as `https://localhost/index.xml` and `https://localhost/opensearch.xml` (measured on `/about`), and the bookmarklet on `/admin` is built from the same domain (upstream `src/routes/admin.js`). Option: render `PUBLIC_BASE_URL` from the role's canonical domain. - The CSP blocks the inline `onsubmit` confirm of "Clear bookmarks" on `/admin/data` (upstream `src/pages/admin/data.hbs`; measured console error "Executing inline event handler violates ... script-src-attr 'self'"), so one click deletes every bookmark without a confirmation. Options: allow that handler's hash in `meta/csp.yml`, or replace the handler in the image build. - `meta/services.yml` builds `ref: main`, an unpinned branch (head `3437b8e` on 2026-10-10), so any rebuild can change the markup the design stylesheet and spec select on. Option: pin the commit. -- The site name has no setting of its own upstream: `server.js` sets `site_name` once at start from `actorInfo.displayName || 'Postmarks'`, and `actorInfo` comes only from `/app/account.json`, whose presence switches Postmarks into fediverse mode (`src/util.js`), so `templates/design.js.j2` rewrites the page title and the header name in the browser while the server-rendered HTML and both Atom feed titles keep `Postmarks`. Option: an upstream `SITE_NAME` setting that does not require `account.json`, e.g. `process.env.SITE_NAME || actorInfo.displayName || 'Postmarks'` in `server.js`, rendered from the design title. +- The site name has no setting of its own upstream: `server.js` sets `site_name` once at start from `actorInfo.displayName || 'Postmarks'`, and `actorInfo` comes only from `/app/account.json`, whose presence switches Postmarks into fediverse mode (`src/util.js`), so `templates/design.js` rewrites the page title and the header name in the browser while the server-rendered HTML and both Atom feed titles keep `Postmarks`. Option: an upstream `SITE_NAME` setting that does not require `account.json`, e.g. `process.env.SITE_NAME || actorInfo.displayName || 'Postmarks'` in `server.js`, rendered from the design title. - The owner key `ADMIN_KEY` is a role-generated secret (`secrets.credentials.admin_key`) independent of the administrator account, so with `sso` off a rotated administrator password never reaches Postmarks and the native sign-in needs a second credential. Option: render `ADMIN_KEY` from `lookup('users', 'administrator').password` so it converges on every deploy. diff --git a/roles/web-app-postmarks/files/logo.css b/roles/web-app-postmarks/files/logo.css new file mode 100644 index 0000000000..573b679ab6 --- /dev/null +++ b/roles/web-app-postmarks/files/logo.css @@ -0,0 +1,3 @@ +.header .logo img { + content: var(--design-url-logo-svg); +} diff --git a/roles/web-app-postmarks/templates/style.css.j2 b/roles/web-app-postmarks/files/style.css similarity index 90% rename from roles/web-app-postmarks/templates/style.css.j2 rename to roles/web-app-postmarks/files/style.css index bc8ccd3bd6..9f933b1820 100644 --- a/roles/web-app-postmarks/templates/style.css.j2 +++ b/roles/web-app-postmarks/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} :root { --color-background: var(--design-surface-1); --color-accent: var(--design-link); @@ -59,8 +58,3 @@ p.error { .bookmark .tags .tag-remove { color: var(--design-danger); } -{% if design.logo is string %} -.header .logo img { - content: url("{{ design.urls.logo.svg }}"); -} -{% endif %} diff --git a/roles/web-app-postmarks/templates/design.js b/roles/web-app-postmarks/templates/design.js new file mode 100644 index 0000000000..06efdf71d0 --- /dev/null +++ b/roles/web-app-postmarks/templates/design.js @@ -0,0 +1,40 @@ +(function () { + function brandIcon() { + const icons = document.querySelectorAll("link[rel~='icon'], link[rel='apple-touch-icon']"); + for (let index = 0; index < icons.length; index += 1) { + const wanted = icons[index].rel === "apple-touch-icon" ? INFINITO_DESIGN.urls['apple-touch-icon'].png : INFINITO_DESIGN.urls.favicon_ico; + if (icons[index].getAttribute("href") !== wanted) { + icons[index].setAttribute("href", wanted); + } + } + } + const title = INFINITO_DESIGN.title; + function brandTitle() { + const parts = document.title.split(" | "); + if (parts.length > 1 && parts[parts.length - 1] !== title) { + parts[parts.length - 1] = title; + document.title = parts.join(" | "); + } + const name = document.querySelector(".header .logo a, .header .title h1 a"); + if (name) { + for (let node = name.firstChild; node; node = node.nextSibling) { + if (node.nodeType === 3 && node.nodeValue.trim() && node.nodeValue.trim() !== title) { + node.nodeValue = ` ${ title } `; + } + } + } + } + function apply() { + if (INFINITO_DESIGN.logo) { + brandIcon(); + } + if (INFINITO_DESIGN.title) { + brandTitle(); + } + } + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", apply); + } else { + apply(); + } +})(); diff --git a/roles/web-app-postmarks/templates/design.js.j2 b/roles/web-app-postmarks/templates/design.js.j2 deleted file mode 100644 index e539b35008..0000000000 --- a/roles/web-app-postmarks/templates/design.js.j2 +++ /dev/null @@ -1,45 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { -{% if design.logo is string %} - function brandIcon() { - var icons = document.querySelectorAll("link[rel~='icon'], link[rel='apple-touch-icon']"); - for (var index = 0; index < icons.length; index += 1) { - var wanted = icons[index].rel === "apple-touch-icon" ? {{ design.urls['apple-touch-icon'].png | to_json }} : {{ design.urls.favicon_ico | to_json }}; - if (icons[index].getAttribute("href") !== wanted) { - icons[index].setAttribute("href", wanted); - } - } - } -{% endif %} -{% if design.title is string %} - var title = {{ design.title | to_json }}; - function brandTitle() { - var parts = document.title.split(" | "); - if (parts.length > 1 && parts[parts.length - 1] !== title) { - parts[parts.length - 1] = title; - document.title = parts.join(" | "); - } - var name = document.querySelector(".header .logo a, .header .title h1 a"); - if (name) { - for (var node = name.firstChild; node; node = node.nextSibling) { - if (node.nodeType === 3 && node.nodeValue.trim() && node.nodeValue.trim() !== title) { - node.nodeValue = " " + title + " "; - } - } - } - } -{% endif %} - function apply() { -{% if design.logo is string %} - brandIcon(); -{% endif %} -{% if design.title is string %} - brandTitle(); -{% endif %} - } - if (document.readyState === "loading") { - document.addEventListener("DOMContentLoaded", apply); - } else { - apply(); - } -})(); diff --git a/roles/web-app-prometheus/templates/design.js b/roles/web-app-prometheus/templates/design.js new file mode 100644 index 0000000000..c9384b1daf --- /dev/null +++ b/roles/web-app-prometheus/templates/design.js @@ -0,0 +1,35 @@ +(function () { + const root = document.documentElement; + function stored() { + try { + return window.localStorage.getItem("mantine-color-scheme-value"); + } catch { + return null; + } + } + function mirror() { + const theme = stored(); + if (theme === "light" || theme === "dark") { + root.setAttribute("data-design-theme", theme); + } else { + root.removeAttribute("data-design-theme"); + } + } + new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["data-mantine-color-scheme"] }); + window.addEventListener("storage", mirror); + mirror(); + if (INFINITO_DESIGN.logo) { + function brandIcon() { + const icons = document.querySelectorAll("link[rel~='icon']"); + for (let index = 0; index < icons.length; index += 1) { + if (icons[index].getAttribute("href") !== INFINITO_DESIGN.urls.favicon_ico) { + icons[index].setAttribute("type", "image/x-icon"); + icons[index].setAttribute("href", INFINITO_DESIGN.urls.favicon_ico); + } + } + } + new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); + brandIcon(); + document.addEventListener("DOMContentLoaded", brandIcon); + } +})(); diff --git a/roles/web-app-prometheus/templates/design.js.j2 b/roles/web-app-prometheus/templates/design.js.j2 deleted file mode 100644 index dacf5f1010..0000000000 --- a/roles/web-app-prometheus/templates/design.js.j2 +++ /dev/null @@ -1,36 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var root = document.documentElement; - function stored() { - try { - return window.localStorage.getItem("mantine-color-scheme-value"); - } catch (error) { - return null; - } - } - function mirror() { - var theme = stored(); - if (theme === "light" || theme === "dark") { - root.setAttribute("data-design-theme", theme); - } else { - root.removeAttribute("data-design-theme"); - } - } - new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["data-mantine-color-scheme"] }); - window.addEventListener("storage", mirror); - mirror(); -{% if design.logo is string %} - function brandIcon() { - var icons = document.querySelectorAll("link[rel~='icon']"); - for (var index = 0; index < icons.length; index += 1) { - if (icons[index].getAttribute("href") !== {{ design.urls.favicon_ico | to_json }}) { - icons[index].setAttribute("type", "image/x-icon"); - icons[index].setAttribute("href", {{ design.urls.favicon_ico | to_json }}); - } - } - } - new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true, attributes: true, attributeFilter: ["href"] }); - brandIcon(); - document.addEventListener("DOMContentLoaded", brandIcon); -{% endif %} -})(); diff --git a/roles/web-app-prometheus/templates/style.css.j2 b/roles/web-app-prometheus/templates/style.css.j2 index a2ee3e116e..677b6bfff2 100644 --- a/roles/web-app-prometheus/templates/style.css.j2 +++ b/roles/web-app-prometheus/templates/style.css.j2 @@ -1,5 +1,4 @@ {% set design = lookup('design', application_id) %} -{% set any_scheme = 'html:root[data-mantine-color-scheme]' %} {% set frame = ':root :is(.mantine-AppShell-header, .mantine-AppShell-navbar)' %} {% set filled = ['.mantine-Button-root', '.mantine-ActionIcon-root', '.mantine-Badge-root', '[data-combobox-selected]'] %} {% set status = [('red', 'danger'), ('green', 'success'), ('teal', 'success'), ('lime', 'success'), ('yellow', 'warning'), ('orange', 'warning')] %} @@ -7,7 +6,7 @@ {% set light_steps = [(0, '-subtle'), (1, '-subtle'), (2, '-subtle'), (3, '-border'), (4, '-border'), (5, ''), (6, ''), (7, ''), (8, ''), (9, '')] %} {% set dark_steps = [(0, ''), (1, ''), (2, ''), (3, ''), (4, ''), (5, ''), (6, ''), (7, '-border'), (8, '-border'), (9, '-subtle')] %} html:root, -{{ any_scheme }} { +html:root[data-mantine-color-scheme] { --mantine-color-body: var(--design-surface-1); --mantine-color-text: var(--design-text); --mantine-color-bright: var(--design-text); @@ -130,31 +129,31 @@ html:root[data-mantine-color-scheme="dark"] [style*="color: var(--mantine-color- :root .mantine-Input-wrapper[data-variant="default"] { --input-bd: var(--design-border-strong); } -{{ any_scheme }} [class*="_panelHealthErr_"] { +html:root[data-mantine-color-scheme] [class*="_panelHealthErr_"] { border-left-color: var(--design-danger-border) !important; } -{{ any_scheme }} [class*="_panelHealthWarn_"] { +html:root[data-mantine-color-scheme] [class*="_panelHealthWarn_"] { border-left-color: var(--design-warning-border) !important; } -{{ any_scheme }} [class*="_healthErr_"], -{{ any_scheme }} [class*="_nodeText_"][class*="_nodeTextError_"] { +html:root[data-mantine-color-scheme] [class*="_healthErr_"], +html:root[data-mantine-color-scheme] [class*="_nodeText_"][class*="_nodeTextError_"] { background-color: var(--design-danger-subtle); } -{{ any_scheme }} [class*="_typeLabel_"] { +html:root[data-mantine-color-scheme] [class*="_typeLabel_"] { color: var(--design-info); } -{{ any_scheme }} [class*="_helpLabel_"] { +html:root[data-mantine-color-scheme] [class*="_helpLabel_"] { color: var(--design-text-muted); } -{{ any_scheme }} [class*="_chartWrapper_"], -{{ any_scheme }} [class*="_tableWrapper_"] { +html:root[data-mantine-color-scheme] [class*="_chartWrapper_"], +html:root[data-mantine-color-scheme] [class*="_tableWrapper_"] { border-color: var(--design-border); } -{{ any_scheme }} [class*="_nodeText_"][class*="_nodeTextSelected_"] { +html:root[data-mantine-color-scheme] [class*="_nodeText_"][class*="_nodeTextSelected_"] { background-color: var(--design-surface-active); border-color: var(--design-border-strong); } -{{ any_scheme }} [class*="_labelPair_"]:hover { +html:root[data-mantine-color-scheme] [class*="_labelPair_"]:hover { background-color: var(--design-surface-active); color: var(--design-text); } @@ -208,20 +207,20 @@ html:root[data-mantine-color-scheme="dark"] [style*="color: var(--mantine-color- :root .cm-editor .cm-completionMatchedText { color: var(--design-link); } -{{ any_scheme }} .uplot .u-under { +html:root[data-mantine-color-scheme] .uplot .u-under { background-color: var(--design-surface-2); } -{{ any_scheme }} .uplot .u-over { +html:root[data-mantine-color-scheme] .uplot .u-over { box-shadow: 0 0 0 0.5px var(--design-border); } -{{ any_scheme }} .uplot .u-select { +html:root[data-mantine-color-scheme] .uplot .u-select { background: rgba(var(--design-primary-rgb), 0.2); } -{{ any_scheme }} .uplot .u-cursor-x, -{{ any_scheme }} .uplot .u-cursor-y { +html:root[data-mantine-color-scheme] .uplot .u-cursor-x, +html:root[data-mantine-color-scheme] .uplot .u-cursor-y { border-color: var(--design-text-muted); } -{{ any_scheme }} .u-tooltip { +html:root[data-mantine-color-scheme] .u-tooltip { background: var(--design-surface-2); border-color: var(--design-border-strong); color: var(--design-text); diff --git a/roles/web-app-roulette-wheel/templates/design.js.j2 b/roles/web-app-roulette-wheel/templates/design.js similarity index 63% rename from roles/web-app-roulette-wheel/templates/design.js.j2 rename to roles/web-app-roulette-wheel/templates/design.js index f4c9ebd426..30e861581b 100644 --- a/roles/web-app-roulette-wheel/templates/design.js.j2 +++ b/roles/web-app-roulette-wheel/templates/design.js @@ -1,9 +1,8 @@ -{% set design = lookup('design', application_id) %} (function () { - var root = document.documentElement; - var dark = window.matchMedia("(prefers-color-scheme: dark)"); - var BUSY = "rgb(192, 192, 192)"; - var SEGMENTS = [ + const root = document.documentElement; + const dark = window.matchMedia("(prefers-color-scheme: dark)"); + const BUSY = "rgb(192, 192, 192)"; + const SEGMENTS = [ "rgba(255, 0, 0, 0.5)", "rgba(0, 255, 0, 0.5)", "rgba(0, 0, 255, 0.5)", @@ -21,42 +20,42 @@ "rgba(250, 128, 114, 0.5)", "rgba(0, 255, 127, 0.5)" ]; - var FILLS = [ + const FILLS = [ "frame", "danger-active", "warning-active", "info-active", "frame-active", "primary-hover", "success-hover", "danger-hover", "warning-hover", "info-hover", "frame-hover", "primary", "success", "danger", "warning", "info" ]; - var POINTER = "#c4b454"; - var LABEL = "#000000"; - var DRAWS = ["clearRect", "beginPath", "save", "restore", "translate", "rotate", "lineTo", "arc", "fill", "stroke", "fillText"]; - var palette = null; - var frame = []; - var replaying = false; - var label = null; + const POINTER = "#c4b454"; + const LABEL = "#000000"; + const DRAWS = ["clearRect", "beginPath", "save", "restore", "translate", "rotate", "lineTo", "arc", "fill", "stroke", "fillText"]; + let palette = null; + let frame = []; + let replaying = false; + let label = null; function wheel(context) { return Boolean(context.canvas && context.canvas.closest && context.canvas.closest(".roulette-wheel")); } function tokens() { if (palette === null) { - var probe = document.createElement("span"); - var read = function (name) { - probe.style.color = "var(--design-" + name + ")"; + const probe = document.createElement("span"); + const read = function (name) { + probe.style.color = `var(--design-${ name })`; return getComputedStyle(probe).color; }; (document.body || root).appendChild(probe); palette = { fill: {}, on: {}, pointer: read("primary"), line: read("border-strong") }; FILLS.forEach(function (name) { palette.fill[name] = read(name); - palette.on[name] = read("on-" + name.replace(/-(hover|active)$/, "")); + palette.on[name] = read(`on-${ name.replace(/-(hover|active)$/, "")}`); }); probe.remove(); } return palette; } function recolor(context, name) { - var colors = tokens(); + const colors = tokens(); if (name === "fill") { - var slot = SEGMENTS.indexOf(context.fillStyle); + const slot = SEGMENTS.indexOf(context.fillStyle); if (slot !== -1) { context.fillStyle = colors.fill[FILLS[slot]]; label = colors.on[FILLS[slot]]; @@ -71,8 +70,8 @@ } if (window.CanvasRenderingContext2D) { DRAWS.forEach(function (name) { - var proto = window.CanvasRenderingContext2D.prototype; - var native = proto[name]; + const proto = window.CanvasRenderingContext2D.prototype; + const native = proto[name]; proto[name] = function () { if (wheel(this)) { if (!replaying) { @@ -89,11 +88,11 @@ } function repaint() { palette = null; - var canvas = document.querySelector(".roulette-wheel canvas"); + const canvas = document.querySelector(".roulette-wheel canvas"); if (!canvas || frame.length === 0) { return; } - var context = canvas.getContext("2d"); + const context = canvas.getContext("2d"); replaying = true; frame.forEach(function (draw) { context.fillStyle = draw[2]; @@ -103,29 +102,29 @@ replaying = false; } function effective() { - var chosen = root.getAttribute("data-design-theme"); + const chosen = root.getAttribute("data-design-theme"); if (chosen === "light" || chosen === "dark") { return chosen; } return dark.matches ? "dark" : "light"; } function icon() { - var image = document.querySelector(".light-dark-mode img.moon-sun"); - var wanted = effective() === "light" ? "static/sun.png" : "static/moon.png"; + const image = document.querySelector(".light-dark-mode img.moon-sun"); + const wanted = effective() === "light" ? "static/sun.png" : "static/moon.png"; if (image && image.getAttribute("src") !== wanted) { image.setAttribute("src", wanted); } } function clean() { - var body = document.body; + const body = document.body; if (body && (body.style.backgroundColor || body.style.color)) { body.style.removeProperty("background-color"); body.style.removeProperty("color"); } - var buttons = document.querySelectorAll(".add-item-button, .remove-all-items-button"); - for (var index = 0; index < buttons.length; index += 1) { - var button = buttons[index]; - var fill = button.style.getPropertyValue("background-color"); + const buttons = document.querySelectorAll(".add-item-button, .remove-all-items-button"); + for (let index = 0; index < buttons.length; index += 1) { + const button = buttons[index]; + const fill = button.style.getPropertyValue("background-color"); if (!fill) { continue; } @@ -136,31 +135,29 @@ } button.style.removeProperty("background"); } - var rows = document.querySelectorAll(".menu-item"); - for (var row = 0; row < rows.length; row += 1) { - var shade = FILLS[SEGMENTS.indexOf(rows[row].style.backgroundColor)]; + const rows = document.querySelectorAll(".menu-item"); + for (let row = 0; row < rows.length; row += 1) { + const shade = FILLS[SEGMENTS.indexOf(rows[row].style.backgroundColor)]; if (shade && rows[row].getAttribute("data-design-fill") !== shade) { rows[row].setAttribute("data-design-fill", shade); } } } -{% if design.title is string or design.logo is string %} function brand() { -{% if design.title is string %} - document.title = {{ design.title | to_json }}; -{% endif %} -{% if design.logo is string %} - var href = {{ design.urls.favicon.png | to_json }}; - var links = document.querySelectorAll("link[rel~='icon']"); - for (var index = 0; index < links.length; index += 1) { - if (links[index].getAttribute("href") !== href) { - links[index].setAttribute("type", "image/png"); - links[index].setAttribute("href", href); + if (INFINITO_DESIGN.title) { + document.title = INFINITO_DESIGN.title; + } + if (INFINITO_DESIGN.logo) { + const href = INFINITO_DESIGN.urls.favicon.png; + const links = document.querySelectorAll("link[rel~='icon']"); + for (let index = 0; index < links.length; index += 1) { + if (links[index].getAttribute("href") !== href) { + links[index].setAttribute("type", "image/png"); + links[index].setAttribute("href", href); + } } - } -{% endif %} + } } -{% endif %} document.addEventListener("click", function (event) { if (!event.target.closest || !event.target.closest(".light-dark-mode")) { return; @@ -171,9 +168,9 @@ repaint(); }); document.addEventListener("DOMContentLoaded", function () { -{% if design.title is string or design.logo is string %} - brand(); -{% endif %} + if (INFINITO_DESIGN.title || INFINITO_DESIGN.logo) { + brand(); + } clean(); icon(); new MutationObserver(clean).observe(document.body, { diff --git a/roles/web-app-seaweedfs/files/logo.css b/roles/web-app-seaweedfs/files/logo.css new file mode 100644 index 0000000000..bafb2c0aa0 --- /dev/null +++ b/roles/web-app-seaweedfs/files/logo.css @@ -0,0 +1,5 @@ +.page-header h1 > a > img { + content: var(--design-url-logo-svg); + width: 50px; + height: 50px; +} diff --git a/roles/web-app-seaweedfs/templates/style.css.j2 b/roles/web-app-seaweedfs/files/style.css similarity index 91% rename from roles/web-app-seaweedfs/templates/style.css.j2 rename to roles/web-app-seaweedfs/files/style.css index e29e0c1772..4414053fe6 100644 --- a/roles/web-app-seaweedfs/templates/style.css.j2 +++ b/roles/web-app-seaweedfs/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} body { background-color: var(--design-surface-1); color: var(--design-text); @@ -90,10 +89,3 @@ code { color: var(--design-text-muted); border-color: var(--design-border-strong); } -{% if design.logo is string %} -.page-header h1 > a > img { - content: url("{{ design.urls.logo.svg }}"); - width: 50px; - height: 50px; -} -{% endif %} diff --git a/roles/web-app-semaphore/templates/design.js.j2 b/roles/web-app-semaphore/templates/design.js similarity index 53% rename from roles/web-app-semaphore/templates/design.js.j2 rename to roles/web-app-semaphore/templates/design.js index 0ed8b5b29f..c1648111c3 100644 --- a/roles/web-app-semaphore/templates/design.js.j2 +++ b/roles/web-app-semaphore/templates/design.js @@ -1,13 +1,12 @@ -{% set design = lookup('design', application_id) %} (function () { - var root = document.documentElement; - var prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); - var choiceKey = "infinito.design.theme"; - var themeKey = "darkMode"; + const root = document.documentElement; + const prefersDark = window.matchMedia("(prefers-color-scheme: dark)"); + const choiceKey = "infinito.design.theme"; + const themeKey = "darkMode"; function read(key) { try { return window.localStorage.getItem(key); - } catch (error) { + } catch { return null; } } @@ -18,7 +17,7 @@ } else { window.localStorage.setItem(key, value); } - } catch (error) { + } catch { return; } } @@ -42,9 +41,9 @@ } follow(); mirror(); - var last = appDark(); + let last = appDark(); function toggled() { - var now = appDark(); + const now = appDark(); if (now !== last) { last = now; write(choiceKey, "explicit"); @@ -66,25 +65,25 @@ follow(); last = appDark(); }); -{% if design.title is string or design.logo is string %} - function brand() { -{% if design.title is string %} - if (document.title !== {{ design.title | to_json }}) { - document.title = {{ design.title | to_json }}; + if (INFINITO_DESIGN.title || INFINITO_DESIGN.logo) { + function brand() { + if (INFINITO_DESIGN.title) { + if (document.title !== INFINITO_DESIGN.title) { + document.title = INFINITO_DESIGN.title; + } } -{% endif %} -{% if design.logo is string %} - var icons = document.querySelectorAll("link[rel~='icon']"); - for (var index = 0; index < icons.length; index += 1) { - if (icons[index].getAttribute("href") !== {{ design.urls.favicon_ico | to_json }}) { - icons[index].setAttribute("type", "image/x-icon"); - icons[index].setAttribute("href", {{ design.urls.favicon_ico | to_json }}); - } + if (INFINITO_DESIGN.logo) { + const icons = document.querySelectorAll("link[rel~='icon']"); + for (let index = 0; index < icons.length; index += 1) { + if (icons[index].getAttribute("href") !== INFINITO_DESIGN.urls.favicon_ico) { + icons[index].setAttribute("type", "image/x-icon"); + icons[index].setAttribute("href", INFINITO_DESIGN.urls.favicon_ico); + } + } } -{% endif %} + } + new MutationObserver(brand).observe(document.head, { childList: true, subtree: true, characterData: true }); + brand(); + document.addEventListener("DOMContentLoaded", brand); } - new MutationObserver(brand).observe(document.head, { childList: true, subtree: true, characterData: true }); - brand(); - document.addEventListener("DOMContentLoaded", brand); -{% endif %} })(); diff --git a/roles/web-app-semaphore/templates/style.css.j2 b/roles/web-app-semaphore/templates/style.css.j2 index d6597af3f7..c8859fcb1c 100644 --- a/roles/web-app-semaphore/templates/style.css.j2 +++ b/roles/web-app-semaphore/templates/style.css.j2 @@ -1,318 +1,315 @@ {% set design = lookup('design', application_id) %} -{% set app = '.v-application' %} -{% set theme = ':is(.theme--light, .theme--dark)' %} {% set frame = '.v-application .NavDrawer' %} -{% set shade = ':is([class*="darken-"], [class*="lighten-"], [class*="accent-"])' %} {% set fills = [('primary', 'primary'), ('accent', 'primary'), ('error', 'danger'), ('success', 'success'), ('warning', 'warning'), ('info', 'info')] %} {% set statuses = [('error', 'danger'), ('success', 'success'), ('warning', 'warning'), ('info', 'info')] %} {% set static_fills = [('red', 'danger'), ('green', 'success'), ('orange', 'warning'), ('amber', 'warning'), ('blue', 'info')] %} -{{ app }}{{ theme }}, -{{ app }} {{ theme }} { +.v-application:is(.theme--light, .theme--dark), +.v-application :is(.theme--light, .theme--dark) { --highlighted-card-bg-color: var(--design-surface-3); --v-background-base: var(--design-surface-2); --v-primary-base: var(--design-primary); } -{{ app }}{{ theme }} { +.v-application:is(.theme--light, .theme--dark) { background: var(--design-surface-1); color: var(--design-text); } -html {{ app }} a { +html .v-application a { color: var(--design-link); } -{{ app }}{{ theme }} .text--primary { +.v-application:is(.theme--light, .theme--dark) .text--primary { color: var(--design-text) !important; } -{{ app }}{{ theme }} :is(.text--secondary, .text--disabled), -html {{ app }} .grey--text { +.v-application:is(.theme--light, .theme--dark) :is(.text--secondary, .text--disabled), +html .v-application .grey--text { color: var(--design-text-muted) !important; } {% for name, token in fills %} -html {{ app }} .{{ name }}, -html {{ app }} .{{ name }}{{ shade }} { +html .v-application .{{ name }}, +html .v-application .{{ name }}:is([class*="darken-"], [class*="lighten-"], [class*="accent-"]) { background-color: var(--design-{{ token }}) !important; border-color: var(--design-{{ token }}) !important; } -html {{ app }} .{{ name }}--text, -html {{ app }} .{{ name }}--text{{ shade }} { +html .v-application .{{ name }}--text, +html .v-application .{{ name }}--text:is([class*="darken-"], [class*="lighten-"], [class*="accent-"]) { color: var(--design-{{ 'link' if token == 'primary' else token }}) !important; caret-color: var(--design-{{ 'link' if token == 'primary' else token }}) !important; } -{{ app }} :is(.v-btn:not(.v-btn--outlined), .v-chip, .v-alert, .v-snack__wrapper, .v-avatar).{{ name }} { +.v-application :is(.v-btn:not(.v-btn--outlined), .v-chip, .v-alert, .v-snack__wrapper, .v-avatar).{{ name }} { color: var(--design-on-{{ token }}); } -{{ app }} .v-btn.{{ name }}:hover { +.v-application .v-btn.{{ name }}:hover { background-color: var(--design-{{ token }}-hover) !important; border-color: var(--design-{{ token }}-hover) !important; } -{{ app }} .v-btn.{{ name }}:active { +.v-application .v-btn.{{ name }}:active { background-color: var(--design-{{ token }}-active) !important; border-color: var(--design-{{ token }}-active) !important; } -{{ app }} .v-btn.{{ name }}::before { +.v-application .v-btn.{{ name }}::before { opacity: 0; } -{{ app }} :is(.v-chip, .v-alert, .v-snack__wrapper).{{ name }} .v-icon { +.v-application :is(.v-chip, .v-alert, .v-snack__wrapper).{{ name }} .v-icon { color: inherit; } {% endfor %} -html {{ app }} .secondary { +html .v-application .secondary { background-color: var(--design-surface-3) !important; border-color: var(--design-border-strong) !important; } -html {{ app }} .secondary--text { +html .v-application .secondary--text { color: var(--design-text-muted) !important; caret-color: var(--design-text-muted) !important; } -{{ app }} .v-btn:not(.v-btn--outlined).secondary { +.v-application .v-btn:not(.v-btn--outlined).secondary { color: var(--design-text); } -{{ app }} .v-btn.secondary:hover { +.v-application .v-btn.secondary:hover { background-color: var(--design-surface-hover) !important; } -{{ app }} .v-btn.secondary:active { +.v-application .v-btn.secondary:active { background-color: var(--design-surface-active) !important; } {% for name, token in static_fills %} -html {{ app }} .{{ name }}, -html {{ app }} .{{ name }}{{ shade }} { +html .v-application .{{ name }}, +html .v-application .{{ name }}:is([class*="darken-"], [class*="lighten-"], [class*="accent-"]) { background-color: var(--design-{{ token }}) !important; border-color: var(--design-{{ token }}) !important; } -{{ app }} :is(.v-chip:not(.v-chip--outlined), .v-avatar, .v-btn:not(.v-btn--outlined)).{{ name }}, -{{ app }} .v-avatar.{{ name }} .white--text { +.v-application :is(.v-chip:not(.v-chip--outlined), .v-avatar, .v-btn:not(.v-btn--outlined)).{{ name }}, +.v-application .v-avatar.{{ name }} .white--text { color: var(--design-on-{{ token }}) !important; } -html {{ app }} .{{ name }}--text, -html {{ app }} .{{ name }}--text{{ shade }} { +html .v-application .{{ name }}--text, +html .v-application .{{ name }}--text:is([class*="darken-"], [class*="lighten-"], [class*="accent-"]) { color: var(--design-{{ 'link' if name == 'blue' else token }}) !important; caret-color: var(--design-{{ 'link' if name == 'blue' else token }}) !important; } {% endfor %} -html {{ app }} :is(.blue-grey, .grey), -html {{ app }} :is(.blue-grey, .grey){{ shade }} { +html .v-application :is(.blue-grey, .grey), +html .v-application :is(.blue-grey, .grey):is([class*="darken-"], [class*="lighten-"], [class*="accent-"]) { background-color: var(--design-surface-3) !important; border-color: var(--design-border-strong) !important; } -{{ app }} :is(.v-chip, .v-btn:not(.v-btn--outlined)):is(.blue-grey, .grey) { +.v-application :is(.v-chip, .v-btn:not(.v-btn--outlined)):is(.blue-grey, .grey) { color: var(--design-text); } -{{ app }} :is([style*="color: gray"], [style*="color: grey"]), -{{ app }} .SingleLineEditable__content.SingleLineEditable__content--placeholder { +.v-application :is([style*="color: gray"], [style*="color: grey"]), +.v-application .SingleLineEditable__content.SingleLineEditable__content--placeholder { color: var(--design-text-muted) !important; } -{{ app }} [style*="color: rgb(255, 82, 82)"] { +.v-application [style*="color: rgb(255, 82, 82)"] { color: var(--design-danger) !important; } -{{ app }} .v-icon[style*="color: rgb(241, 70, 104)"] { +.v-application .v-icon[style*="color: rgb(241, 70, 104)"] { color: var(--design-link) !important; } -html {{ app }} .blue-grey--text, -html {{ app }} .blue-grey--text{{ shade }} { +html .v-application .blue-grey--text, +html .v-application .blue-grey--text:is([class*="darken-"], [class*="lighten-"], [class*="accent-"]) { color: var(--design-text-muted) !important; caret-color: var(--design-text-muted) !important; } -{{ app }} {{ theme }}:is(.v-card, .v-sheet, .v-list, .v-btn-toggle:not(.v-btn-toggle--group)) { +.v-application :is(.theme--light, .theme--dark):is(.v-card, .v-sheet, .v-list, .v-btn-toggle:not(.v-btn-toggle--group)) { background-color: var(--design-surface-2); border-color: var(--design-border); color: var(--design-text); } -{{ app }} {{ theme }}.v-toolbar.v-sheet, -{{ app }} {{ theme }}:is(.v-data-table, .v-tabs-items), -{{ app }} {{ theme }}.v-tabs > .v-tabs-bar { +.v-application :is(.theme--light, .theme--dark).v-toolbar.v-sheet, +.v-application :is(.theme--light, .theme--dark):is(.v-data-table, .v-tabs-items), +.v-application :is(.theme--light, .theme--dark).v-tabs > .v-tabs-bar { background-color: transparent; color: var(--design-text); } -{{ app }} {{ theme }}.v-card > :is(.v-card__text, .v-card__subtitle), -{{ app }} {{ theme }}:is(.v-subheader, .v-label, .v-messages, .v-counter), -{{ app }} {{ theme }}.v-list-item:not(.v-list-item--disabled) :is(.v-list-item__subtitle, .v-list-item__action-text) { +.v-application :is(.theme--light, .theme--dark).v-card > :is(.v-card__text, .v-card__subtitle), +.v-application :is(.theme--light, .theme--dark):is(.v-subheader, .v-label, .v-messages, .v-counter), +.v-application :is(.theme--light, .theme--dark).v-list-item:not(.v-list-item--disabled) :is(.v-list-item__subtitle, .v-list-item__action-text) { color: var(--design-text-muted); } -{{ app }} .v-card[style*="background"], -{{ app }} [style*="background: rgba(133, 133, 133, 0.06)"] { +.v-application .v-card[style*="background"], +.v-application [style*="background: rgba(133, 133, 133, 0.06)"] { background: var(--design-surface-3) !important; border-color: var(--design-border) !important; } -{{ app }} {{ theme }} .item-dialog__title-actions, -{{ app }} .v-bottom-sheet > .v-sheet{{ theme }} { +.v-application :is(.theme--light, .theme--dark) .item-dialog__title-actions, +.v-application .v-bottom-sheet > .v-sheet:is(.theme--light, .theme--dark) { background: var(--design-surface-2); } -{{ app }} .v-overlay .v-overlay__scrim { +.v-application .v-overlay .v-overlay__scrim { background-color: var(--design-text) !important; } -{{ app }} .v-tooltip__content, -{{ app }} .v-snack__wrapper{{ theme }} { +.v-application .v-tooltip__content, +.v-application .v-snack__wrapper:is(.theme--light, .theme--dark) { background-color: var(--design-text); color: var(--design-surface-1); } -{{ app }} {{ theme }}.v-divider, -{{ app }} {{ theme }}.v-data-table .v-data-footer { +.v-application :is(.theme--light, .theme--dark).v-divider, +.v-application :is(.theme--light, .theme--dark).v-data-table .v-data-footer { border-color: var(--design-border); } -{{ app }} {{ theme }}.v-btn-toggle:not(.v-btn-toggle--group) .v-btn.v-btn { +.v-application :is(.theme--light, .theme--dark).v-btn-toggle:not(.v-btn-toggle--group) .v-btn.v-btn { border-color: var(--design-border) !important; } -html {{ app }} .white { +html .v-application .white { background-color: var(--design-surface-2) !important; border-color: var(--design-surface-2) !important; } -{{ app }} .auth__divider::before, -{{ app }} .auth__divider::after { +.v-application .auth__divider::before, +.v-application .auth__divider::after { border-top-color: var(--design-border); } -{{ app }} {{ theme }}.v-icon, -{{ app }} {{ theme }}.v-btn.v-btn--icon, -{{ app }} {{ theme }}.v-btn-toggle:not(.v-btn-toggle--group) .v-btn.v-btn .v-icon { +.v-application :is(.theme--light, .theme--dark).v-icon, +.v-application :is(.theme--light, .theme--dark).v-btn.v-btn--icon, +.v-application :is(.theme--light, .theme--dark).v-btn-toggle:not(.v-btn-toggle--group) .v-btn.v-btn .v-icon { color: var(--design-text-muted); } -{{ app }} {{ theme }}.v-btn { +.v-application :is(.theme--light, .theme--dark).v-btn { color: var(--design-text); } -{{ app }} {{ theme }}.v-btn.v-btn--disabled, -{{ app }} {{ theme }}.v-btn.v-btn--disabled :is(.v-icon, .v-btn__loading), -{{ app }} {{ theme }}.v-icon.v-icon.v-icon--disabled { +.v-application :is(.theme--light, .theme--dark).v-btn.v-btn--disabled, +.v-application :is(.theme--light, .theme--dark).v-btn.v-btn--disabled :is(.v-icon, .v-btn__loading), +.v-application :is(.theme--light, .theme--dark).v-icon.v-icon.v-icon--disabled { color: var(--design-text-muted) !important; } -{{ app }} {{ theme }}.v-btn.v-btn--disabled.v-btn--has-bg { +.v-application :is(.theme--light, .theme--dark).v-btn.v-btn--disabled.v-btn--has-bg { background-color: var(--design-surface-3) !important; } -{{ app }} {{ theme }}.v-btn:not(.v-btn--has-bg):hover, -{{ app }} {{ theme }}.v-list-item--link:hover, -{{ app }} {{ theme }}.v-tabs .v-tab:hover { +.v-application :is(.theme--light, .theme--dark).v-btn:not(.v-btn--has-bg):hover, +.v-application :is(.theme--light, .theme--dark).v-list-item--link:hover, +.v-application :is(.theme--light, .theme--dark).v-tabs .v-tab:hover { background-color: var(--design-surface-hover); } -{{ app }} {{ theme }}.v-btn:not(.v-btn--has-bg):active, -{{ app }} {{ theme }}.v-btn.v-btn--active:not(.v-btn--has-bg), -{{ app }} {{ theme }}.v-list-item--active, -{{ app }} {{ theme }}.v-list-item--link:active { +.v-application :is(.theme--light, .theme--dark).v-btn:not(.v-btn--has-bg):active, +.v-application :is(.theme--light, .theme--dark).v-btn.v-btn--active:not(.v-btn--has-bg), +.v-application :is(.theme--light, .theme--dark).v-list-item--active, +.v-application :is(.theme--light, .theme--dark).v-list-item--link:active { background-color: var(--design-surface-active); } -{{ app }} {{ theme }}.v-btn:not(.v-btn--has-bg)::before, -{{ app }} {{ theme }}.v-list-item.v-list-item::before, -{{ app }} {{ theme }}.v-tabs .v-tab.v-tab::before, -{{ app }} .v-alert--text::before { +.v-application :is(.theme--light, .theme--dark).v-btn:not(.v-btn--has-bg)::before, +.v-application :is(.theme--light, .theme--dark).v-list-item.v-list-item::before, +.v-application :is(.theme--light, .theme--dark).v-tabs .v-tab.v-tab::before, +.v-application .v-alert--text::before { opacity: 0; } -{{ app }} :is(.v-btn, .v-list-item, .v-tab, .v-chip, .v-icon.v-icon--link):focus-visible { +.v-application :is(.v-btn, .v-list-item, .v-tab, .v-chip, .v-icon.v-icon--link):focus-visible { outline: 2px solid var(--design-focus, var(--design-link)); outline-offset: -2px; } -{{ app }} .v-input--switch:has(input:focus-visible) .v-input--switch__track { +.v-application .v-input--switch:has(input:focus-visible) .v-input--switch__track { outline: 2px solid var(--design-focus, var(--design-link)); outline-offset: 2px; } -{{ app }} {{ theme }}.v-list-item:not(.v-list-item--active):not(.v-list-item--disabled), -{{ app }} {{ theme }}.v-list-item--active { +.v-application :is(.theme--light, .theme--dark).v-list-item:not(.v-list-item--active):not(.v-list-item--disabled), +.v-application :is(.theme--light, .theme--dark).v-list-item--active { color: var(--design-text); } -{{ app }} {{ theme }}.v-list-item--disabled, -{{ app }} {{ theme }}.v-data-table .v-data-table__empty-wrapper, -{{ app }} {{ theme }}.v-data-table .v-data-table-header th.sortable .v-data-table-header__icon, -{{ app }} {{ theme }}.v-data-table > .v-data-table__wrapper > table > thead > tr > th, -{{ app }} {{ theme }}.v-tabs > .v-tabs-bar :is(.v-tab:not(.v-tab--active), .v-tab:not(.v-tab--active) > .v-icon, .v-tab--disabled) { +.v-application :is(.theme--light, .theme--dark).v-list-item--disabled, +.v-application :is(.theme--light, .theme--dark).v-data-table .v-data-table__empty-wrapper, +.v-application :is(.theme--light, .theme--dark).v-data-table .v-data-table-header th.sortable .v-data-table-header__icon, +.v-application :is(.theme--light, .theme--dark).v-data-table > .v-data-table__wrapper > table > thead > tr > th, +.v-application :is(.theme--light, .theme--dark).v-tabs > .v-tabs-bar :is(.v-tab:not(.v-tab--active), .v-tab:not(.v-tab--active) > .v-icon, .v-tab--disabled) { color: var(--design-text-muted); } -{{ app }} {{ theme }}.v-data-table > .v-data-table__wrapper > table > thead > tr:last-child > th, -{{ app }} {{ theme }}.v-data-table > .v-data-table__wrapper > table > tbody > tr:not(:last-child) > :is(td, th):not(.v-data-table__mobile-row), -{{ app }} {{ theme }}.v-data-table > .v-data-table__wrapper > table > tbody > tr:not(:last-child) > :is(td, th):last-child { +.v-application :is(.theme--light, .theme--dark).v-data-table > .v-data-table__wrapper > table > thead > tr:last-child > th, +.v-application :is(.theme--light, .theme--dark).v-data-table > .v-data-table__wrapper > table > tbody > tr:not(:last-child) > :is(td, th):not(.v-data-table__mobile-row), +.v-application :is(.theme--light, .theme--dark).v-data-table > .v-data-table__wrapper > table > tbody > tr:not(:last-child) > :is(td, th):last-child { border-bottom-color: var(--design-border); } -{{ app }} {{ theme }}.v-data-table > .v-data-table__wrapper > table > tfoot > tr > :is(td, th):not(.v-data-table__mobile-row) { +.v-application :is(.theme--light, .theme--dark).v-data-table > .v-data-table__wrapper > table > tfoot > tr > :is(td, th):not(.v-data-table__mobile-row) { border-top-color: var(--design-border); } -{{ app }} .v-data-table .v-data-table__wrapper > table > tbody > tr:hover:not(.v-data-table__expanded__content):not(.v-data-table__empty-wrapper) { +.v-application .v-data-table .v-data-table__wrapper > table > tbody > tr:hover:not(.v-data-table__expanded__content):not(.v-data-table__empty-wrapper) { background-color: var(--design-surface-hover) !important; } -{{ app }} .v-data-table .v-data-table__wrapper > table > tbody > tr:is(.active, .v-data-table__selected) { +.v-application .v-data-table .v-data-table__wrapper > table > tbody > tr:is(.active, .v-data-table__selected) { background-color: var(--design-surface-active) !important; } -{{ app }} {{ theme }}.v-input, -{{ app }} {{ theme }}.v-input :is(input, textarea), -{{ app }} {{ theme }}.v-select .v-select__selections { +.v-application :is(.theme--light, .theme--dark).v-input, +.v-application :is(.theme--light, .theme--dark).v-input :is(input, textarea), +.v-application :is(.theme--light, .theme--dark).v-select .v-select__selections { color: var(--design-text); } -{{ app }} {{ theme }}.v-input :is(input, textarea)::placeholder, -{{ app }} {{ theme }}.v-input--is-disabled, -{{ app }} {{ theme }}.v-input--is-disabled :is(input, textarea), -{{ app }} {{ theme }}.v-select.v-input--is-disabled .v-select__selections { +.v-application :is(.theme--light, .theme--dark).v-input :is(input, textarea)::placeholder, +.v-application :is(.theme--light, .theme--dark).v-input--is-disabled, +.v-application :is(.theme--light, .theme--dark).v-input--is-disabled :is(input, textarea), +.v-application :is(.theme--light, .theme--dark).v-select.v-input--is-disabled .v-select__selections { color: var(--design-text-muted); } -{{ app }} {{ theme }}.v-text-field > .v-input__control > .v-input__slot::before { +.v-application :is(.theme--light, .theme--dark).v-text-field > .v-input__control > .v-input__slot::before { border-color: var(--design-border-strong); } -{{ app }} {{ theme }}.v-text-field:not(.v-input--has-state):hover > .v-input__control > .v-input__slot::before { +.v-application :is(.theme--light, .theme--dark).v-text-field:not(.v-input--has-state):hover > .v-input__control > .v-input__slot::before { border-color: var(--design-text); } -{{ app }} .v-input .v-input__slot fieldset { +.v-application .v-input .v-input__slot fieldset { background-color: var(--design-surface-3); border-color: var(--design-border-strong); color: var(--design-border-strong); } -{{ app }} .v-input.primary--text .v-input__slot fieldset { +.v-application .v-input.primary--text .v-input__slot fieldset { border-color: var(--design-link); } -{{ app }} .v-input.error--text .v-input__slot fieldset { +.v-application .v-input.error--text .v-input__slot fieldset { border-color: var(--design-danger); } -{{ app }} {{ theme }} .v-input .v-label--active { +.v-application :is(.theme--light, .theme--dark) .v-input .v-label--active { text-shadow: 0 0 2px var(--design-surface-2); } -{{ app }} .InputWithAppendedButton .v-input__append-outer .v-btn { +.v-application .InputWithAppendedButton .v-input__append-outer .v-btn { border-color: var(--design-border-strong); } -{{ app }} {{ theme }}.v-input--switch .v-input--switch__thumb { +.v-application :is(.theme--light, .theme--dark).v-input--switch .v-input--switch__thumb { color: var(--design-surface-2); } -{{ app }} {{ theme }}.v-input--switch .v-input--switch__track { +.v-application :is(.theme--light, .theme--dark).v-input--switch .v-input--switch__track { color: var(--design-border-strong); } -{{ app }} {{ theme }}.v-chip { +.v-application :is(.theme--light, .theme--dark).v-chip { border-color: var(--design-border); color: var(--design-text); } -{{ app }} {{ theme }}.v-chip:not(.v-chip--active):not([class*="--text"]) { +.v-application :is(.theme--light, .theme--dark).v-chip:not(.v-chip--active):not([class*="--text"]) { background: var(--design-surface-3); } {% for name, token in statuses %} -{{ app }} .v-alert:is(.v-alert--text, .v-alert--outlined).{{ name }}--text { +.v-application .v-alert:is(.v-alert--text, .v-alert--outlined).{{ name }}--text { background-color: var(--design-{{ token }}-subtle) !important; border-color: var(--design-{{ token }}-border) !important; } {% endfor %} -html {{ app }}{{ theme }} code { +html .v-application:is(.theme--light, .theme--dark) code { background-color: var(--design-surface-3); } -{{ app }} .CodeMirror, -{{ app }} .CodeMirror-gutters { +.v-application .CodeMirror, +.v-application .CodeMirror-gutters { background: var(--design-surface-3); border-color: var(--design-border); color: var(--design-text); } -{{ app }} .EnvironmentEditor { +.v-application .EnvironmentEditor { border-color: var(--design-border) !important; } -{{ app }} .CodeMirror-linenumber, -{{ app }} .CodeMirror pre.CodeMirror-placeholder { +.v-application .CodeMirror-linenumber, +.v-application .CodeMirror pre.CodeMirror-placeholder { color: var(--design-text-muted); } -{{ app }} .CodeMirror-cursor { +.v-application .CodeMirror-cursor { border-left-color: var(--design-text); } -{{ app }} .CodeMirror-selected { +.v-application .CodeMirror-selected { background: var(--design-surface-active); } -{{ app }} .cm-s-default :is(.cm-string, .cm-string-2) { +.v-application .cm-s-default :is(.cm-string, .cm-string-2) { color: var(--design-success); } -{{ app }} .cm-s-default :is(.cm-keyword, .cm-atom, .cm-number, .cm-def) { +.v-application .cm-s-default :is(.cm-keyword, .cm-atom, .cm-number, .cm-def) { color: var(--design-info); } -{{ app }} .cm-s-default :is(.cm-property, .cm-variable, .cm-variable-2, .cm-tag) { +.v-application .cm-s-default :is(.cm-property, .cm-variable, .cm-variable-2, .cm-tag) { color: var(--design-text); } -{{ app }} .cm-s-default :is(.cm-comment, .cm-meta) { +.v-application .cm-s-default :is(.cm-comment, .cm-meta) { color: var(--design-text-muted); } -{{ app }} .cm-s-default .cm-error { +.v-application .cm-s-default .cm-error { color: var(--design-danger); } {{ frame }}.v-navigation-drawer { @@ -321,31 +318,31 @@ html {{ app }}{{ theme }} code { border-color: var(--design-frame) !important; color: var(--design-on-frame); } -{{ frame }} {{ theme }}:is(.v-list, .v-sheet) { +{{ frame }} :is(.theme--light, .theme--dark):is(.v-list, .v-sheet) { background: transparent; color: var(--design-on-frame); } -{{ frame }} {{ theme }}.v-list-item:not(.v-list-item--active):not(.v-list-item--disabled), -{{ frame }} {{ theme }}.v-list-item--active, -{{ frame }} {{ theme }}:is(.v-icon, .v-btn, .v-btn.v-btn--icon) { +{{ frame }} :is(.theme--light, .theme--dark).v-list-item:not(.v-list-item--active):not(.v-list-item--disabled), +{{ frame }} :is(.theme--light, .theme--dark).v-list-item--active, +{{ frame }} :is(.theme--light, .theme--dark):is(.v-icon, .v-btn, .v-btn.v-btn--icon) { color: var(--design-on-frame); } -{{ frame }} {{ theme }}.v-list-item:not(.v-list-item--disabled) .v-list-item__subtitle, +{{ frame }} :is(.theme--light, .theme--dark).v-list-item:not(.v-list-item--disabled) .v-list-item__subtitle, {{ frame }} .nav-more-toggle .nav-more-title { color: rgba(var(--design-on-frame-rgb), 0.75); opacity: 1; } -{{ frame }} {{ theme }}.v-list-item--link:hover, -{{ frame }} {{ theme }}.v-btn:not(.v-btn--has-bg):hover { +{{ frame }} :is(.theme--light, .theme--dark).v-list-item--link:hover, +{{ frame }} :is(.theme--light, .theme--dark).v-btn:not(.v-btn--has-bg):hover { background-color: var(--design-frame-hover); } -{{ frame }} {{ theme }}.v-list-item--active, -{{ frame }} {{ theme }}.v-list-item--link:active, -{{ frame }} {{ theme }}.v-list-item[aria-expanded="true"] { +{{ frame }} :is(.theme--light, .theme--dark).v-list-item--active, +{{ frame }} :is(.theme--light, .theme--dark).v-list-item--link:active, +{{ frame }} :is(.theme--light, .theme--dark).v-list-item[aria-expanded="true"] { background-color: var(--design-frame-active); } -{{ frame }} {{ theme }}.v-divider, -{{ frame }}{{ theme }}:not(.v-navigation-drawer--floating) .v-navigation-drawer__border { +{{ frame }} :is(.theme--light, .theme--dark).v-divider, +{{ frame }}:is(.theme--light, .theme--dark):not(.v-navigation-drawer--floating) .v-navigation-drawer__border { background-color: transparent; border-color: rgba(var(--design-on-frame-rgb), 0.2) !important; } @@ -368,12 +365,12 @@ html {{ app }}{{ theme }} code { color: var(--design-on-frame) !important; background-color: var(--design-frame-active); } -{{ app }} .auth { +.v-application .auth { background-color: var(--design-frame); background-image: none; } {% if design.logo is string %} -{{ app }} .auth .v-image__image { +.v-application .auth .v-image__image { background-image: url("{{ design.urls.logo.png }}") !important; background-size: contain; } diff --git a/roles/web-app-snipe-it/templates/custom_css.css.j2 b/roles/web-app-snipe-it/files/custom_css.css similarity index 100% rename from roles/web-app-snipe-it/templates/custom_css.css.j2 rename to roles/web-app-snipe-it/files/custom_css.css diff --git a/roles/web-app-snipe-it/templates/style.css.j2 b/roles/web-app-snipe-it/files/style.css similarity index 100% rename from roles/web-app-snipe-it/templates/style.css.j2 rename to roles/web-app-snipe-it/files/style.css diff --git a/roles/web-app-snipe-it/templates/design.js.j2 b/roles/web-app-snipe-it/templates/design.js similarity index 76% rename from roles/web-app-snipe-it/templates/design.js.j2 rename to roles/web-app-snipe-it/templates/design.js index 1b30e7e68f..fbd83c4156 100644 --- a/roles/web-app-snipe-it/templates/design.js.j2 +++ b/roles/web-app-snipe-it/templates/design.js @@ -1,21 +1,21 @@ (function () { - var root = document.documentElement; - var query = window.matchMedia("(prefers-color-scheme: dark)"); + const root = document.documentElement; + const query = window.matchMedia("(prefers-color-scheme: dark)"); function stored() { try { return localStorage.getItem("theme"); - } catch (e) { + } catch { return null; } } function sync() { - var choice = stored(); + const choice = stored(); if (choice === "light" || choice === "dark") { if (root.getAttribute("data-design-theme") !== choice) root.setAttribute("data-design-theme", choice); return; } if (root.hasAttribute("data-design-theme")) root.removeAttribute("data-design-theme"); - var system = query.matches ? "dark" : "light"; + const system = query.matches ? "dark" : "light"; if (root.getAttribute("data-theme") !== system) root.setAttribute("data-theme", system); } sync(); diff --git a/roles/web-app-snipe-it/vars/main.yml b/roles/web-app-snipe-it/vars/main.yml index 7ea4860988..5416e4a49e 100644 --- a/roles/web-app-snipe-it/vars/main.yml +++ b/roles/web-app-snipe-it/vars/main.yml @@ -45,7 +45,7 @@ SNIPE_IT_DESIGN_COLORS: nav_link_color: "{{ SNIPE_IT_DESIGN_PALETTE.light['--design-on-frame'] }}" link_light_color: "{{ SNIPE_IT_DESIGN_PALETTE.light['--design-link'] }}" link_dark_color: "{{ SNIPE_IT_DESIGN_PALETTE.dark['--design-link'] }}" - custom_css: "{{ lookup('template', 'custom_css.css.j2') }}" + custom_css: "{{ lookup('file', 'custom_css.css', rstrip=False) }}" SNIPE_IT_DESIGN_SETTINGS: >- {{ SNIPE_IT_DESIGN_COLORS diff --git a/roles/web-app-socialhome/files/logo.css b/roles/web-app-socialhome/files/logo.css new file mode 100644 index 0000000000..5dcf3f4de5 --- /dev/null +++ b/roles/web-app-socialhome/files/logo.css @@ -0,0 +1,27 @@ +.sh-sidenav .sh-wordmark.sh-sidenav-brand, +.sh-login-hero .sh-wordmark { + box-sizing: content-box; + background-repeat: no-repeat; + background-size: contain; + background-origin: content-box; +} + +.sh-sidenav .sh-wordmark.sh-sidenav-brand { + flex-shrink: 0; + width: var(--design-slot-sidebar-width); + height: var(--design-slot-sidebar-height); + background-image: var(--design-url-sidebar-svg); + background-position: left center; +} + +.sh-login-hero .sh-wordmark { + width: var(--design-slot-login-width); + height: var(--design-slot-login-height); + background-image: var(--design-url-login-svg); + background-position: center; +} + +.sh-sidenav .sh-wordmark.sh-sidenav-brand > *, +.sh-login-hero .sh-wordmark > * { + display: none; +} diff --git a/roles/web-app-socialhome/templates/style.css.j2 b/roles/web-app-socialhome/files/style.css similarity index 84% rename from roles/web-app-socialhome/templates/style.css.j2 rename to roles/web-app-socialhome/files/style.css index 8ac488c1c6..c0f543d500 100644 --- a/roles/web-app-socialhome/templates/style.css.j2 +++ b/roles/web-app-socialhome/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} html:root, html.sh-theme-light, html.sh-theme-dark { @@ -184,33 +183,3 @@ mark { background: var(--design-surface-active); color: var(--design-text); } -{% if design.logo is string %} - -.sh-sidenav .sh-wordmark.sh-sidenav-brand, -.sh-login-hero .sh-wordmark { - box-sizing: content-box; - background-repeat: no-repeat; - background-size: contain; - background-origin: content-box; -} - -.sh-sidenav .sh-wordmark.sh-sidenav-brand { - flex-shrink: 0; - width: {{ design.slots.sidebar.width }}px; - height: {{ design.slots.sidebar.height }}px; - background-image: url("{{ design.urls.sidebar.svg }}"); - background-position: left center; -} - -.sh-login-hero .sh-wordmark { - width: {{ design.slots.login.width }}px; - height: {{ design.slots.login.height }}px; - background-image: url("{{ design.urls.login.svg }}"); - background-position: center; -} - -.sh-sidenav .sh-wordmark.sh-sidenav-brand > *, -.sh-login-hero .sh-wordmark > * { - display: none; -} -{% endif %} diff --git a/roles/web-app-stalwart/templates/design.js b/roles/web-app-stalwart/templates/design.js new file mode 100644 index 0000000000..4aaaa02564 --- /dev/null +++ b/roles/web-app-stalwart/templates/design.js @@ -0,0 +1,55 @@ +(function () { + const root = document.documentElement; + function persisted() { + try { + const saved = JSON.parse(window.localStorage.getItem("stalwart-ui") || "null"); + return (saved && saved.state && saved.state.theme) || null; + } catch { + return null; + } + } + function stored() { + const cookie = /(?:^|;\s*)colorMode=(dark|light)/.exec(document.cookie); + const theme = cookie ? cookie[1] : persisted(); + return theme === "dark" || theme === "light" ? theme : null; + } + function mirror() { + const theme = root.classList.contains("dark") || root.classList.contains("dark-mode") ? "dark" : stored(); + if (theme) { + root.setAttribute("data-design-theme", theme); + } else { + root.removeAttribute("data-design-theme"); + } + } + new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["class"] }); + mirror(); + if (INFINITO_DESIGN.title) { + function brandTitle() { + const title = INFINITO_DESIGN.title; + const next = document.title === "Portal" ? title : document.title.replace(/(^|\sยท\s)Stalwart WebUI$/, function (match, prefix) { + return prefix + title; + }); + if (next !== document.title) { + document.title = next; + } + } + new MutationObserver(brandTitle).observe(document.head, { childList: true, subtree: true, characterData: true }); + brandTitle(); + document.addEventListener("DOMContentLoaded", brandTitle); + } + if (INFINITO_DESIGN.logo) { + function brandIcon() { + const href = INFINITO_DESIGN.urls.favicon_ico; + const icons = document.querySelectorAll("link[rel~='icon']"); + for (let index = 0; index < icons.length; index += 1) { + if (icons[index].getAttribute("href") !== href) { + icons[index].setAttribute("type", "image/x-icon"); + icons[index].setAttribute("href", href); + } + } + } + new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true }); + brandIcon(); + document.addEventListener("DOMContentLoaded", brandIcon); + } +})(); diff --git a/roles/web-app-stalwart/templates/design.js.j2 b/roles/web-app-stalwart/templates/design.js.j2 deleted file mode 100644 index e52c7971e6..0000000000 --- a/roles/web-app-stalwart/templates/design.js.j2 +++ /dev/null @@ -1,56 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var root = document.documentElement; - function persisted() { - try { - var saved = JSON.parse(window.localStorage.getItem("stalwart-ui") || "null"); - return (saved && saved.state && saved.state.theme) || null; - } catch (error) { - return null; - } - } - function stored() { - var cookie = /(?:^|;\s*)colorMode=(dark|light)/.exec(document.cookie); - var theme = cookie ? cookie[1] : persisted(); - return theme === "dark" || theme === "light" ? theme : null; - } - function mirror() { - var theme = root.classList.contains("dark") || root.classList.contains("dark-mode") ? "dark" : stored(); - if (theme) { - root.setAttribute("data-design-theme", theme); - } else { - root.removeAttribute("data-design-theme"); - } - } - new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["class"] }); - mirror(); -{% if design.title is string %} - function brandTitle() { - var title = {{ design.title | to_json }}; - var next = document.title === "Portal" ? title : document.title.replace(/(^|\sยท\s)Stalwart WebUI$/, function (match, prefix) { - return prefix + title; - }); - if (next !== document.title) { - document.title = next; - } - } - new MutationObserver(brandTitle).observe(document.head, { childList: true, subtree: true, characterData: true }); - brandTitle(); - document.addEventListener("DOMContentLoaded", brandTitle); -{% endif %} -{% if design.logo is string %} - function brandIcon() { - var href = {{ design.urls.favicon_ico | to_json }}; - var icons = document.querySelectorAll("link[rel~='icon']"); - for (var index = 0; index < icons.length; index += 1) { - if (icons[index].getAttribute("href") !== href) { - icons[index].setAttribute("type", "image/x-icon"); - icons[index].setAttribute("href", href); - } - } - } - new MutationObserver(brandIcon).observe(document.head, { childList: true, subtree: true }); - brandIcon(); - document.addEventListener("DOMContentLoaded", brandIcon); -{% endif %} -})(); diff --git a/roles/web-app-suitecrm/templates/legacy.css.j2 b/roles/web-app-suitecrm/files/legacy.css similarity index 100% rename from roles/web-app-suitecrm/templates/legacy.css.j2 rename to roles/web-app-suitecrm/files/legacy.css diff --git a/roles/web-app-suitecrm/tasks/02_design.yml b/roles/web-app-suitecrm/tasks/02_design.yml index 2935d6c25f..7be5cdbee8 100644 --- a/roles/web-app-suitecrm/tasks/02_design.yml +++ b/roles/web-app-suitecrm/tasks/02_design.yml @@ -17,7 +17,7 @@ suitecrm_design_payload: app_dir: "{{ SUITECRM_APP_DIR }}" enabled: "{{ SUITECRM_DESIGN_ENABLED | bool }}" - css: "{{ lookup('ansible.builtin.template', SUITECRM_DESIGN_LEGACY_CSS) if SUITECRM_DESIGN_ENABLED | bool else '' }}" + css: "{{ lookup('ansible.builtin.file', SUITECRM_DESIGN_LEGACY_CSS, rstrip=False) if SUITECRM_DESIGN_ENABLED | bool else '' }}" title: "{{ SUITECRM_DESIGN_TITLE }}" logo: "{{ suitecrm_design_assets.results[0].content if SUITECRM_DESIGN_LOGO_ENABLED | bool else '' }}" favicon: "{{ suitecrm_design_assets.results[1].content if SUITECRM_DESIGN_LOGO_ENABLED | bool else '' }}" diff --git a/roles/web-app-suitecrm/vars/main.yml b/roles/web-app-suitecrm/vars/main.yml index d54ecc388b..f6315ecaa1 100644 --- a/roles/web-app-suitecrm/vars/main.yml +++ b/roles/web-app-suitecrm/vars/main.yml @@ -55,7 +55,7 @@ SUITECRM_DESIGN_LOGO_ENABLED: "{{ SUITECRM_DESIGN_ENABLED | bool and lookup('des SUITECRM_DESIGN_TITLE: "{{ lookup('design', application_id).title if SUITECRM_DESIGN_ENABLED | bool and lookup('design', application_id).title is string else '' }}" SUITECRM_DESIGN_ASSETS_DIR: "{{ lookup('design', application_id).dest }}" SUITECRM_DESIGN_SCRIPT: "{{ [role_path, 'files/php/design.php'] | path_join }}" -SUITECRM_DESIGN_LEGACY_CSS: "legacy.css.j2" +SUITECRM_DESIGN_LEGACY_CSS: "legacy.css" SUITECRM_MAX_OLD_SPACE_SIZE: "{{ lookup('node_max_old_space_size', application_id, entity_name) }}" SUITECRM_PHP_MEMORY_LIMIT: "{{ lookup('service_memory_mb', application_id, entity_name, 0.25) }}M" diff --git a/roles/web-app-taiga/templates/style.css.j2 b/roles/web-app-taiga/files/style.css similarity index 100% rename from roles/web-app-taiga/templates/style.css.j2 rename to roles/web-app-taiga/files/style.css diff --git a/roles/web-app-yourls/files/logo.css b/roles/web-app-yourls/files/logo.css new file mode 100644 index 0000000000..b78116e755 --- /dev/null +++ b/roles/web-app-yourls/files/logo.css @@ -0,0 +1,4 @@ +#yourls-logo { + content: var(--design-url-logo-svg); + height: auto; +} diff --git a/roles/web-app-yourls/templates/style.css.j2 b/roles/web-app-yourls/files/style.css similarity index 90% rename from roles/web-app-yourls/templates/style.css.j2 rename to roles/web-app-yourls/files/style.css index 579dd4fff1..5acef5a447 100644 --- a/roles/web-app-yourls/templates/style.css.j2 +++ b/roles/web-app-yourls/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} body { color: var(--design-text); background-color: var(--design-surface-1); @@ -92,16 +91,16 @@ td.actions .button.loading, color: var(--design-warning); } td.actions .button_share { - background: transparent url({{ YOURLS_URL }}/images/share.svg) center no-repeat; + background: transparent var(--design-url-app-share) center no-repeat; } td.actions .button_edit { - background: transparent url({{ YOURLS_URL }}/images/pencil.svg) center no-repeat; + background: transparent var(--design-url-app-pencil) center no-repeat; } td.actions .button_delete { - background: transparent url({{ YOURLS_URL }}/images/delete.svg) center no-repeat; + background: transparent var(--design-url-app-delete) center no-repeat; } td.actions .button_stats { - background: transparent url({{ YOURLS_URL }}/images/chart_bar.svg) center no-repeat; + background: transparent var(--design-url-app-chart-bar) center no-repeat; } .error { color: var(--design-danger); @@ -264,13 +263,13 @@ div.share { color: var(--design-danger); } #share_tw { - background: transparent url({{ YOURLS_URL }}/images/twitter.svg) left center no-repeat; + background: transparent var(--design-url-app-twitter) left center no-repeat; } #share_fb { - background: transparent url({{ YOURLS_URL }}/images/facebook.svg) left center no-repeat; + background: transparent var(--design-url-app-facebook) left center no-repeat; } #copylink { - background: transparent url({{ YOURLS_URL }}/images/copy.svg) 130% center no-repeat; + background: transparent var(--design-url-app-copy) 130% center no-repeat; } .datepicker { border-color: var(--design-border-strong); @@ -292,9 +291,3 @@ div.share { #historical_clicks li:nth-child(even):not(:hover) { background-color: var(--design-surface-3) !important; } -{% if design.logo is string %} -#yourls-logo { - content: url("{{ design.urls.logo.svg }}"); - height: auto; -} -{% endif %} diff --git a/roles/web-app-yourls/vars/main.yml b/roles/web-app-yourls/vars/main.yml index 964f4c869b..5a34d50263 100644 --- a/roles/web-app-yourls/vars/main.yml +++ b/roles/web-app-yourls/vars/main.yml @@ -18,3 +18,12 @@ YOURLS_SSO_PROXY_GATED: "{{ lookup('sso', application_id, 'is_proxy_gated') }}" YOURLS_SSO_ADMIN_GROUP: "/{{ lookup('rbac_group_path', application_id=application_id, role='administrator') }}" container_port: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.ports.internal.http') }}" + +design_css_urls: + share: "{{ YOURLS_URL }}/images/share.svg" + pencil: "{{ YOURLS_URL }}/images/pencil.svg" + delete: "{{ YOURLS_URL }}/images/delete.svg" + chart-bar: "{{ YOURLS_URL }}/images/chart_bar.svg" + twitter: "{{ YOURLS_URL }}/images/twitter.svg" + facebook: "{{ YOURLS_URL }}/images/facebook.svg" + copy: "{{ YOURLS_URL }}/images/copy.svg" diff --git a/roles/web-app-zammad/templates/design.js.j2 b/roles/web-app-zammad/templates/design.js similarity index 56% rename from roles/web-app-zammad/templates/design.js.j2 rename to roles/web-app-zammad/templates/design.js index 408eb91426..3d1a6e6cac 100644 --- a/roles/web-app-zammad/templates/design.js.j2 +++ b/roles/web-app-zammad/templates/design.js @@ -1,8 +1,7 @@ -{% set design = lookup('design', application_id) %} (function () { - var root = document.documentElement; - var path = window.location.pathname; - var surface = "legacy"; + const root = document.documentElement; + const path = window.location.pathname; + let surface = "legacy"; if (/^\/mobile(\/|$)/.test(path)) { surface = "mobile"; } else if (/^\/desktop(\/|$)/.test(path)) { @@ -11,9 +10,9 @@ surface = "help"; } root.setAttribute("data-design-surface", surface); - var media = window.matchMedia("(prefers-color-scheme: dark)"); + const media = window.matchMedia("(prefers-color-scheme: dark)"); function mirror() { - var theme = root.getAttribute("data-theme"); + const theme = root.getAttribute("data-theme"); if ((theme === "light" || theme === "dark") && theme !== (media.matches ? "dark" : "light")) { root.setAttribute("data-design-theme", theme); } else { @@ -24,23 +23,23 @@ new MutationObserver(mirror).observe(root, { attributes: true, attributeFilter: ["data-theme"] }); mirror(); } -{% if design.logo is string %} - var favicon = {{ design.urls.favicon_ico | to_json }}; - var touchIcon = {{ design.urls['apple-touch-icon'].png | to_json }}; - var icons = document.querySelectorAll("link[rel~='icon']"); + if (INFINITO_DESIGN.logo) { + const favicon = INFINITO_DESIGN.urls.favicon_ico; + const touchIcon = INFINITO_DESIGN.urls['apple-touch-icon'].png; + let icons = document.querySelectorAll("link[rel~='icon']"); if (icons.length === 0) { - var icon = document.createElement("link"); + const icon = document.createElement("link"); icon.rel = "icon"; document.head.appendChild(icon); icons = [icon]; } - for (var index = 0; index < icons.length; index += 1) { + for (let index = 0; index < icons.length; index += 1) { icons[index].setAttribute("type", "image/x-icon"); icons[index].setAttribute("href", favicon); } - var touch = document.querySelectorAll("link[rel='apple-touch-icon']"); - for (var position = 0; position < touch.length; position += 1) { + const touch = document.querySelectorAll("link[rel='apple-touch-icon']"); + for (let position = 0; position < touch.length; position += 1) { touch[position].setAttribute("href", touchIcon); } -{% endif %} + } })(); diff --git a/roles/web-svc-libretranslate/files/logo.css b/roles/web-svc-libretranslate/files/logo.css new file mode 100644 index 0000000000..8e8af0f067 --- /dev/null +++ b/roles/web-svc-libretranslate/files/logo.css @@ -0,0 +1,18 @@ +#logo-container img.logo, +.swagger-ui .topbar a.link img { + content: var(--design-url-logo-svg); + height: 40px; + width: auto; +} + +#logo-container img.logo { + vertical-align: middle; +} + +.swagger-ui .topbar a.link { + flex: 0 1 auto; +} + +#logo-container span { + display: none; +} diff --git a/roles/web-svc-libretranslate/templates/style.css.j2 b/roles/web-svc-libretranslate/files/style.css similarity index 99% rename from roles/web-svc-libretranslate/templates/style.css.j2 rename to roles/web-svc-libretranslate/files/style.css index 7ee4fc92ca..9faba1a757 100644 --- a/roles/web-svc-libretranslate/templates/style.css.j2 +++ b/roles/web-svc-libretranslate/files/style.css @@ -1,4 +1,3 @@ -{% set design = lookup('design', application_id) %} :root { --pri-bg-color: var(--design-surface-1); --sec-bg-color: var(--design-surface-2); @@ -1727,24 +1726,3 @@ body { .swagger-ui .microlight span[style*="252, 194, 140"] { color: var(--design-link) !important; } -{% if design.logo is string %} - -#logo-container img.logo, -.swagger-ui .topbar a.link img { - content: url("{{ design.urls.logo.svg }}"); - height: 40px; - width: auto; -} - -#logo-container img.logo { - vertical-align: middle; -} - -.swagger-ui .topbar a.link { - flex: 0 1 auto; -} - -#logo-container span { - display: none; -} -{% endif %} diff --git a/roles/web-svc-libretranslate/templates/design.js b/roles/web-svc-libretranslate/templates/design.js new file mode 100644 index 0000000000..cbdd703d2e --- /dev/null +++ b/roles/web-svc-libretranslate/templates/design.js @@ -0,0 +1,59 @@ +(function () { + const root = document.documentElement; + if (INFINITO_DESIGN.title) { + if (window.location.pathname.indexOf("/docs") === 0) { + document.title = INFINITO_DESIGN.title; + } + } + if (INFINITO_DESIGN.logo) { + const icons = document.querySelectorAll("link[rel~='icon']"); + for (let index = 1; index < icons.length; index += 1) { + icons[index].parentNode.removeChild(icons[index]); + } + const icon = icons[0] || document.head.appendChild(document.createElement("link")); + icon.rel = "icon"; + icon.type = "image/x-icon"; + icon.removeAttribute("sizes"); + icon.href = INFINITO_DESIGN.urls.favicon_ico; + } + const rules = Object.getOwnPropertyDescriptor(CSSStyleSheet.prototype, "cssRules"); + Object.defineProperty(CSSStyleSheet.prototype, "cssRules", { + configurable: true, + enumerable: rules.enumerable, + get: function () { + try { + return rules.get.call(this); + } catch { + return []; + } + }, + }); + function chosen() { + try { + const scheme = window.localStorage.getItem("scheme"); + return scheme === "light" || scheme === "dark" ? scheme : null; + } catch { + return null; + } + } + function mirror() { + const scheme = chosen(); + if (scheme) { + root.setAttribute("data-design-theme", scheme); + } else { + root.removeAttribute("data-design-theme"); + } + } + mirror(); + document.addEventListener("DOMContentLoaded", function () { + const save = window.savePreferredColorScheme; + if (typeof save === "function") { + window.savePreferredColorScheme = function (scheme) { + save(scheme); + mirror(); + }; + } + mirror(); + }); + window.addEventListener("storage", mirror); +})(); diff --git a/roles/web-svc-libretranslate/templates/design.js.j2 b/roles/web-svc-libretranslate/templates/design.js.j2 deleted file mode 100644 index b9aa6b7d20..0000000000 --- a/roles/web-svc-libretranslate/templates/design.js.j2 +++ /dev/null @@ -1,60 +0,0 @@ -{% set design = lookup('design', application_id) %} -(function () { - var root = document.documentElement; -{% if design.title is string %} - if (window.location.pathname.indexOf("/docs") === 0) { - document.title = {{ design.title | to_json }}; - } -{% endif %} -{% if design.logo is string %} - var icons = document.querySelectorAll("link[rel~='icon']"); - for (var index = 1; index < icons.length; index += 1) { - icons[index].parentNode.removeChild(icons[index]); - } - var icon = icons[0] || document.head.appendChild(document.createElement("link")); - icon.rel = "icon"; - icon.type = "image/x-icon"; - icon.removeAttribute("sizes"); - icon.href = {{ design.urls.favicon_ico | to_json }}; -{% endif %} - var rules = Object.getOwnPropertyDescriptor(CSSStyleSheet.prototype, "cssRules"); - Object.defineProperty(CSSStyleSheet.prototype, "cssRules", { - configurable: true, - enumerable: rules.enumerable, - get: function () { - try { - return rules.get.call(this); - } catch (error) { - return []; - } - }, - }); - function chosen() { - try { - var scheme = window.localStorage.getItem("scheme"); - return scheme === "light" || scheme === "dark" ? scheme : null; - } catch (error) { - return null; - } - } - function mirror() { - var scheme = chosen(); - if (scheme) { - root.setAttribute("data-design-theme", scheme); - } else { - root.removeAttribute("data-design-theme"); - } - } - mirror(); - document.addEventListener("DOMContentLoaded", function () { - var save = window.savePreferredColorScheme; - if (typeof save === "function") { - window.savePreferredColorScheme = function (scheme) { - save(scheme); - mirror(); - }; - } - mirror(); - }); - window.addEventListener("storage", mirror); -})(); diff --git a/tests/lint/ansible/jinja/test_no_leaked_jinja_expression.py b/tests/lint/ansible/jinja/test_no_leaked_jinja_expression.py new file mode 100644 index 0000000000..814d348b35 --- /dev/null +++ b/tests/lint/ansible/jinja/test_no_leaked_jinja_expression.py @@ -0,0 +1,56 @@ +"""Lint: Jinja expression syntax never appears outside a Jinja delimiter. + +Inlining a ``{% set name = '' %}`` selector into the places that read +it is a common cleanup, and it is safe only while the right-hand side really is +one literal. Against a concatenation or a conditional, a regex that stops at +the first closing quote captures the *source text* of the expression instead of +its value, and writes it into the template body: + + {% set resting = ':where(' ~ scope ~ ')' %} -> :where(' ~ scope ~ ') + {% set s = '.a' if x else '.b' %} -> .a' if x else '.b + +Both render as literal text. In CSS that is a selector parse error, so the rule +is dropped and the page silently loses it; nothing downstream complains, +because the template is still valid Jinja and the stylesheet still parses as a +stylesheet with one rule fewer. + +A template that genuinely needs ``if`` or ``~`` writes it inside ``{{ }}`` or +``{% %}``, which this lint strips before looking. +""" + +from __future__ import annotations + +import re +import unittest + +from utils.cache.files import PROJECT_ROOT, read_text + +ROLES = PROJECT_ROOT / "roles" +DELIMITED = re.compile(r"\{\{.*?\}\}|\{%.*?%\}|\{#.*?#\}", re.DOTALL) +LEAKED = re.compile(r"'\s*~\s*\w|\w\s*~\s*'|'\s+if\s+.+\s+else\s+'") +RULE = "no-leaked-jinja-expression" + + +class TestNoLeakedJinjaExpression(unittest.TestCase): + def test_no_template_carries_raw_expression_text(self) -> None: + templates = sorted(ROLES.glob("*/**/*.j2")) + self.assertTrue(templates, f"[{RULE}] no template found under {ROLES}") + offenders = [] + for path in templates: + body = DELIMITED.sub( + lambda match: "\n" * match.group(0).count("\n"), read_text(str(path)) + ) + for number, line in enumerate(body.splitlines(), start=1): + if LEAKED.search(line): + offenders.append( + f"{path.relative_to(PROJECT_ROOT)}:{number}: {line.strip()[:90]}" + ) + self.assertFalse( + offenders, + f"[{RULE}] Jinja expression text stands outside a delimiter and " + "will render literally:\n " + "\n ".join(offenders), + ) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/lint/filesystem/test_design_custom_properties.py b/tests/lint/filesystem/test_design_custom_properties.py new file mode 100644 index 0000000000..e165bcec9e --- /dev/null +++ b/tests/lint/filesystem/test_design_custom_properties.py @@ -0,0 +1,133 @@ +"""Lint: a role stylesheet only reads design custom properties that reach it. + +``sys-front-inj-design`` builds the per-app stylesheet by rendering +``templates/css/app.css.j2`` - a ``:root{}`` block of ``--design-url-*``, +``--design-slot-*`` and ``--design-url-app-*`` declarations - and appending the +role's sheet and, when the role ships a logo, its ``files/logo.css``. The sheet +is whichever of ``templates/style.css.j2`` and ``files/style.css`` the +``first_found`` in that role's ``tasks/main.yml`` resolves, in that order. +Those three files are the only ones that block reaches. + +A sheet the role deploys on its own path never sees it. Reading a design +custom property there is invisible: an undefined custom property makes the +whole declaration invalid at computed-value time, so the rule silently paints +nothing and no test, no lint and no colour-asserting Playwright spec notices. +That is how a FusionDirectory tree-list lost its guide lines. + +The same silence hides a typo. ``var(--design-url-sidbar-svg)`` is a valid +stylesheet; it just never matches. So every referenced slot is checked against +the slots the role actually declares - its own ``meta/services.yml`` +``design.slots`` merged over the global set in ``web-svc-design`` - and every +``--design-url-app-`` against the ``design_css_urls`` of its role. +""" + +from __future__ import annotations + +import re +import unittest +from typing import TYPE_CHECKING + +from utils.cache.files import PROJECT_ROOT, read_text +from utils.cache.yaml import load_yaml_str +from utils.roles.mapping import ROLE_FILE_META_SERVICES, ROLE_FILE_VARS_MAIN + +if TYPE_CHECKING: + from pathlib import Path + +ROLES = PROJECT_ROOT / "roles" +GLOBAL_SLOTS_ROLE = "web-svc-design" +COMPOSED = ("templates/style.css.j2", "files/style.css", "files/logo.css") +KINDS = ("png", "svg") +DIMENSIONS = ("width", "height") +FAVICON = "favicon-ico" +REFERENCE = re.compile(r"var\(\s*--design-(url|slot)-([A-Za-z0-9_-]+)\s*[,)]") +RULE = "design-custom-properties" + + +def _design(role: str) -> dict: + """Return the ``design`` service entry of one role. + + :param role: role directory name. + :return: the mapping, empty when the role declares none. + """ + path = ROLES / role / ROLE_FILE_META_SERVICES + if not path.is_file(): + return {} + parsed = load_yaml_str(read_text(str(path))) or {} + entry = parsed.get("design") + return entry if isinstance(entry, dict) else {} + + +def _slots(role: str) -> set[str]: + """Return every design slot the role resolves, global ones included.""" + names = set(_design(GLOBAL_SLOTS_ROLE).get("slots") or {}) + return names | set(_design(role).get("slots") or {}) + + +def _app_urls(role: str) -> set[str]: + """Return the keys of the role's ``design_css_urls``.""" + path = ROLES / role / ROLE_FILE_VARS_MAIN + if not path.is_file(): + return set() + try: + parsed = load_yaml_str(read_text(str(path))) or {} + except Exception: + return set() + entry = parsed.get("design_css_urls") + return set(entry) if isinstance(entry, dict) else set() + + +def _emitted(role: str) -> set[str]: + """Return every custom property ``app.css.j2`` declares for this role.""" + names = {f"url-{FAVICON}"} + for slot in _slots(role): + names.update(f"url-{slot}-{kind}" for kind in KINDS) + names.update(f"slot-{slot}-{dimension}" for dimension in DIMENSIONS) + names.update(f"url-app-{key}" for key in _app_urls(role)) + return names + + +def _referenced(path: Path) -> set[str]: + return {f"{kind}-{name}" for kind, name in REFERENCE.findall(read_text(str(path)))} + + +class TestDesignCustomProperties(unittest.TestCase): + def test_only_composed_sheets_read_design_properties(self) -> None: + candidates = sorted(ROLES.glob("*/**/*.css*")) + self.assertTrue(candidates, f"[{RULE}] no role stylesheet found under {ROLES}") + offenders = [ + str(path.relative_to(PROJECT_ROOT)) + for path in candidates + if _referenced(path) + and "/".join(path.relative_to(ROLES).parts[1:]) not in COMPOSED + ] + self.assertFalse( + offenders, + f"[{RULE}] these read a design custom property, but " + "sys-front-inj-design prepends the declarations only to " + f"{', '.join(COMPOSED)}, so the value never arrives and the " + "declaration is dropped:\n " + "\n ".join(offenders), + ) + + def test_every_referenced_property_is_declared(self) -> None: + sheets = [ + path for name in COMPOSED for path in sorted(ROLES.glob(f"*/{name}")) + ] + self.assertTrue(sheets, f"[{RULE}] no composed sheet found under {ROLES}") + offenders = [] + for path in sheets: + role = path.relative_to(ROLES).parts[0] + missing = sorted(_referenced(path) - _emitted(role)) + if missing: + offenders.append(f"{path.relative_to(PROJECT_ROOT)}: {missing}") + self.assertFalse( + offenders, + f"[{RULE}] these read custom properties that app.css.j2 never " + "declares for their role. Add the slot to the role's " + "meta/services.yml design.slots, or the key to its " + "design_css_urls:\n " + "\n ".join(offenders), + ) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/lint/filesystem/test_design_script_config_reads.py b/tests/lint/filesystem/test_design_script_config_reads.py new file mode 100644 index 0000000000..9ceeee9df1 --- /dev/null +++ b/tests/lint/filesystem/test_design_script_config_reads.py @@ -0,0 +1,47 @@ +"""Lint: a design script reads its config object, it does not quote it. + +``sys-front-inj-design`` prepends ``var INFINITO_DESIGN = {โ€ฆ};`` to the role's +design script, so the script reads branding through that object. Writing the +reference inside a string literal produces valid JavaScript that assigns the +34-character text ``INFINITO_DESIGN.urls.favicon_ico`` instead of the URL. + +Nothing downstream sees it: the file parses, ``to_one_liner`` collapses it, +eslint accepts a string literal, and the CSP hash matches the broken script. +Only the rendered page shows it, as a favicon that resolves against the page +URL. That is how the documentation role lost its favicon. +""" + +from __future__ import annotations + +import re +import unittest + +from utils.cache.files import PROJECT_ROOT, read_text + +ROLES = PROJECT_ROOT / "roles" +PATTERNS = ("*/templates/design.js", "*/templates/design.js.j2", "*/templates/js/design.js.j2") +LITERAL = re.compile(r"\"[^\"\n]*\"|'[^'\n]*'|`[^`\n]*`") +RULE = "design-script-config-reads" + + +class TestDesignScriptConfigReads(unittest.TestCase): + def test_no_script_quotes_its_config_object(self) -> None: + scripts = [path for pattern in PATTERNS for path in sorted(ROLES.glob(pattern))] + self.assertTrue(scripts, f"[{RULE}] no design script matched {PATTERNS}") + offenders = [] + for path in scripts: + for number, line in enumerate(read_text(str(path)).splitlines(), start=1): + if any("INFINITO_DESIGN" in text for text in LITERAL.findall(line)): + offenders.append( + f"{path.relative_to(PROJECT_ROOT)}:{number}: {line.strip()[:90]}" + ) + self.assertFalse( + offenders, + f"[{RULE}] the config object is quoted here, so the script assigns " + "its own source text instead of the branding value:\n " + + "\n ".join(offenders), + ) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/unit/python/roles/sys-front-inj-all/test_injected_javascript.py b/tests/unit/python/roles/sys-front-inj-all/test_injected_javascript.py index d9c86d9237..979843813f 100644 --- a/tests/unit/python/roles/sys-front-inj-all/test_injected_javascript.py +++ b/tests/unit/python/roles/sys-front-inj-all/test_injected_javascript.py @@ -1,8 +1,10 @@ """Injected JavaScript must still parse after ``to_one_liner`` collapses it. ``sys-front-inj-javascript`` loads a role's ``javascript.js`` or its ``.j2`` -template, runs it through ``to_one_liner`` - which strips every comment and -newline - and inlines the result under a CSP hash. A script that parses only +template and ``sys-front-inj-design`` loads its ``design.js`` behind the +per-app config prelude, runs it through ``to_one_liner`` - which strips every +comment and newline - and inlines the result under a CSP hash. A script that +parses only before that collapse is served broken *with a matching hash*: the browser rejects nothing and executes nothing, so the page loses its injection without a single error anywhere in the deploy. Parsing the collapsed form is the only @@ -33,6 +35,9 @@ PATTERNS = ( "*/templates/javascript.js.j2", "*/templates/javascript.js", "*/files/javascript/javascript.js", + "*/templates/design.js.j2", + "*/templates/design.js", + "*/templates/js/design.js.j2", ) EXPRESSION = re.compile(r"\{\{.*?\}\}", re.DOTALL) STATEMENT = re.compile(r"\{%.*?%\}", re.DOTALL)