diff --git a/docs/agents/files/role/style.css.md b/docs/agents/files/role/style.css.md index 7c64878ddf..b4e2ea7377 100644 --- a/docs/agents/files/role/style.css.md +++ b/docs/agents/files/role/style.css.md @@ -6,6 +6,7 @@ For repository wiring, inventory keys, and the generated palette contract, see [ ## Goal +- You MUST use the app's own configuration before the role stylesheet. An in-house theming, theme or custom CSS option outranks injected CSS. - You MUST add the smallest possible theming layer on top of the role's existing CSS. - You MUST prefer token mapping over selector rewrites so the role keeps its native structure. - The result MUST feel like one coherent brand theme, not a collection of unrelated overrides. @@ -16,6 +17,7 @@ For repository wiring, inventory keys, and the generated palette contract, see [ - You MUST use the semantic `--design-*` tokens listed in [Contributing `style.css`](../../../contributing/artefact/files/role/style.css.md#design-tokens-) for every color. Hard-coded colors are forbidden. - You MUST prefer semantic tokens (`--design-surface-*`, `--design-text*`, `--design-border*`, `--design-primary`, `--design-link`, status tokens) over the `--design-primary-*` and `--design-neutral-*` scales. Use a scale step only for brand accents a semantic token does not cover. - 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. @@ -37,10 +39,11 @@ For repository wiring, inventory keys, and the generated palette contract, see [ ## Workflow 1. Preserve the role's base CSS so the application styling stays intact, including its contrast relations (frame against content, panel against page, selected against unselected). -2. When the app has its own theming mechanism (config, CLI or API), feed the palette through it and ship no stylesheet. -3. Otherwise inspect which variables the role or framework already exposes (semantic tokens, palette variables, custom properties). -4. Map the design tokens onto those variables. Add selector overrides only for surfaces that cannot be reached through variables. -5. Keep transparency, text contrast, and surface hierarchy aligned. Replace upstream gradients with flat token surfaces. +2. When the app has its own theming configuration (config, CLI, API or admin setting), feed the palette through it and ship no stylesheet. +3. When the app has an in-house theme or custom CSS option (theme file, custom CSS setting), ship the mapping through that option instead of the role stylesheet. +4. Use the role stylesheet only for what no in-house option reaches. Inspect which variables the role or framework already exposes (semantic tokens, palette variables, custom properties). +5. Map the design tokens onto those variables. Add selector overrides only for surfaces that cannot be reached through variables. +6. Keep transparency, text contrast, and surface hierarchy aligned. Replace upstream gradients with flat token surfaces. The full role pass, the review gallery and the work queue are described in the [Design Loop](../../action/design.md). diff --git a/docs/contributing/artefact/files/role/style.css.md b/docs/contributing/artefact/files/role/style.css.md index 78444acb43..cfe0303bfe 100644 --- a/docs/contributing/artefact/files/role/style.css.md +++ b/docs/contributing/artefact/files/role/style.css.md @@ -9,9 +9,11 @@ For browser-side validation requirements after visible UI changes, see [Playwrig - A role ships its override as `templates/style.css.j2` or `files/style.css`. - `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`. Every unlayered rule of the app wins over them, so they only style what the app leaves unstyled. -- An app with its own design system gets the corporate palette by mapping its CSS variables onto the tokens in the role stylesheet (see [web-app-gitea](../../../../../roles/web-app-gitea/templates/style.css.j2)), or through its own theming mechanism (Nextcloud takes the primary color, logo, name and slogan via `occ theming:config` and ships no stylesheet). -- The Bootstrap mapping in `bootstrap.css` is unlayered and applies to every Bootstrap app. +- 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`. ## Inventory ๐Ÿ“‹ @@ -29,14 +31,17 @@ The [design_palette](../../../../../plugins/lookup/design_palette.py) lookup der | `--design-surface-1` | Page background | | `--design-surface-2` | Cards, panels, inputs | | `--design-surface-3` | Hover, selected and inset areas, table heads | -| `--design-surface-hover`, `--design-surface-active` | Hovered and pressed or open neutral controls; body text stays AAA and muted text AA on both | +| `--design-surface-hover`, `--design-surface-active` | Hovered and pressed or open neutral controls; body text stays AAA, muted text, links and status colors AA on both | | `--design-text` | Body text, AAA against every surface | | `--design-text-muted` | Secondary text, AA against every surface | | `--design-border` | Decorative dividers | -| `--design-border-strong` | Input and control boundaries, 3:1 against surfaces | -| `--design-primary` / `--design-on-primary` | Brand surfaces and the text on them | -| `--design-link` | Links and focus, AA against surfaces | -| `--design-success`, `--design-warning`, `--design-danger`, `--design-info` | Status text and icons, AA against surfaces | +| `--design-border-strong` | Input and control boundaries, 3:1 against `--design-surface-1` and `--design-surface-2` | +| `--design-primary` / `--design-on-primary` | Brand surfaces, 3:1 against `--design-surface-1` and `--design-surface-2`, and the text on them | +| `--design-frame` / `--design-on-frame` | Large brand surfaces such as a sidebar, masthead or top bar: a deep brand tone in light and dark mode, and the text on it at AAA | +| `--design-frame-hover`, `--design-frame-active` | Hovered and selected entries inside the frame; the on-color stays AAA | +| `--design-focus` | Color of the default focus outline. Unset, the outline uses `--design-link`. A frame sets it to `--design-on-frame` on its own element; every focusable it hosts then draws its outline in that color | +| `--design-link` | Links and focus, AA against every surface | +| `--design-success`, `--design-warning`, `--design-danger`, `--design-info` | Status text and icons, AA against every surface and against their own `-subtle` background | | `--design-on-` | Text on a filled status surface | | `--design-primary-hover`, `--design-primary-active`, `--design--hover`, `--design--active` | Hovered and pressed filled controls, shifted away from their on-color so its contrast only grows | | `--design--subtle`, `--design--border` | Alert backgrounds and borders | diff --git a/roles/sys-front-inj-all/filter_plugins/inj_snippets.py b/roles/sys-front-inj-all/filter_plugins/inj_snippets.py index 9550a136fd..c3adc185b3 100644 --- a/roles/sys-front-inj-all/filter_plugins/inj_snippets.py +++ b/roles/sys-front-inj-all/filter_plugins/inj_snippets.py @@ -2,6 +2,7 @@ Jinja filter: `inj_features(kind)` filters a list of features to only those that actually provide the corresponding snippet template file. +- kind='top' -> roles/sys-front-inj-/templates/top_sub.j2 - kind='head' -> roles/sys-front-inj-/templates/head_sub.j2 - kind='body' -> roles/sys-front-inj-/templates/body_sub.j2 @@ -24,8 +25,8 @@ def _feature_role_dir(feature: str) -> str: def _has_snippet(feature: str, kind: str) -> bool: - if kind not in ("head", "body"): - raise ValueError("kind must be 'head' or 'body'") + if kind not in ("top", "head", "body"): + raise ValueError("kind must be 'top', 'head' or 'body'") role_dir = _feature_role_dir(feature) if not Path(role_dir).is_dir(): diff --git a/roles/sys-front-inj-all/tasks/main.yml b/roles/sys-front-inj-all/tasks/main.yml index 799146ba90..b00fb1ec24 100644 --- a/roles/sys-front-inj-all/tasks/main.yml +++ b/roles/sys-front-inj-all/tasks/main.yml @@ -13,6 +13,7 @@ - name: ๐Ÿ”จ Build injection facts for '{{ domain }}' set_fact: inj_enabled: "{{ lookup('applications') | inj_enabled(application_id, SRV_WEB_INJ_COMP_FEATURES_ALL) }}" + inj_top_features: "{{ SRV_WEB_INJ_COMP_FEATURES_ALL | inj_features('top') }}" inj_head_features: "{{ SRV_WEB_INJ_COMP_FEATURES_ALL | inj_features('head') }}" inj_body_features: "{{ SRV_WEB_INJ_COMP_FEATURES_ALL | inj_features('body') }}" diff --git a/roles/sys-front-inj-all/templates/body_filter.lua.j2 b/roles/sys-front-inj-all/templates/body_filter.lua.j2 index 7ea7590bfa..42e62507db 100644 --- a/roles/sys-front-inj-all/templates/body_filter.lua.j2 +++ b/roles/sys-front-inj-all/templates/body_filter.lua.j2 @@ -76,6 +76,17 @@ end local meta_re = [[]+http-equiv=["']Content-Security-Policy["'][^>]*>\s*]] whole = ngx.re.gsub(whole, meta_re, "", "ijo") +local top_snippets = {} +{{ push_snippets('top_snippets', inj_top_features) }} +if #top_snippets > 0 then + local top_payload = onionize(marked(top_snippets)) + local function repl_top(m) return m[0] .. top_payload end + local with_top = ngx.re.sub(whole, [[]*>]], repl_top, "ijo") + if with_top then + whole = with_top + end +end + -- Build head snippets (rendered by Jinja at template time) local head_snippets = {} {{ push_snippets('head_snippets', inj_head_features) }} diff --git a/roles/sys-front-inj-design/tasks/main.yml b/roles/sys-front-inj-design/tasks/main.yml index 6d1c2547f3..58ad401980 100644 --- a/roles/sys-front-inj-design/tasks/main.yml +++ b/roles/sys-front-inj-design/tasks/main.yml @@ -10,17 +10,25 @@ '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 '' }}" set_fact: app_style_src: "{{ _app_style_src }}" - app_style_present: "{{ _app_style_src | length > 0 }}" + app_style_css: "{{ _app_style_css }}" + app_style_present: "{{ _app_style_css | length > 0 }}" - name: "๐Ÿš€ Deploy per-app '{{ app_style_src }}' to '{{ css_app_dst }}'" when: app_style_present | bool copy: - content: "{{ lookup('template', app_style_src) }}" + content: "{{ app_style_css }}" dest: "{{ css_app_dst }}" mode: "0644" +- name: "๐Ÿงน Remove the per-app stylesheet '{{ css_app_dst }}' a role no longer ships" + when: not (app_style_present | bool) + ansible.builtin.file: + path: "{{ css_app_dst }}" + state: absent + - name: "๐Ÿ–ผ๏ธ Publish corporate branding assets of '{{ application_id }}' on the CDN" include_tasks: assets.yml vars: @@ -33,8 +41,9 @@ 'files': ['templates/design.js.j2'], '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 '' }}" set_fact: - design_js_one_liner: "{{ (lookup('template', _design_js_src) | to_one_liner) if _design_js_src | length > 0 else '' }}" + design_js_one_liner: "{{ (_design_js | to_one_liner) if _design_js | length > 0 else '' }}" - name: "โž• Append design script CSP hash for '{{ application_id }}'" when: design_js_one_liner | length > 0 diff --git a/roles/sys-front-inj-design/templates/css/layer.css.j2 b/roles/sys-front-inj-design/templates/css/layer.css.j2 new file mode 100644 index 0000000000..084173e1aa --- /dev/null +++ b/roles/sys-front-inj-design/templates/css/layer.css.j2 @@ -0,0 +1 @@ +@layer infinito-design; diff --git a/roles/sys-front-inj-design/templates/head_sub.j2 b/roles/sys-front-inj-design/templates/head_sub.j2 index 7e1cd34b39..953bf53393 100644 --- a/roles/sys-front-inj-design/templates/head_sub.j2 +++ b/roles/sys-front-inj-design/templates/head_sub.j2 @@ -1,6 +1,6 @@ {% set __css_tpl_dir = lookup('path_absolute', 'roles', 'sys-front-inj-design', 'templates', 'css') %} -{% for css_file in ['default.css','bootstrap.css'] %} +{% for css_file in ['default.css'] + (['bootstrap.css'] if lookup('design', application_id).bootstrap else []) %} {% endfor %} {% if app_style_present | default(false) | bool %} diff --git a/roles/sys-front-inj-design/templates/top_sub.j2 b/roles/sys-front-inj-design/templates/top_sub.j2 new file mode 100644 index 0000000000..af6bf2876b --- /dev/null +++ b/roles/sys-front-inj-design/templates/top_sub.j2 @@ -0,0 +1 @@ + diff --git a/roles/sys-front-inj-design/vars/main.yml b/roles/sys-front-inj-design/vars/main.yml index dad0b3950d..7b27dea0ef 100644 --- a/roles/sys-front-inj-design/vars/main.yml +++ b/roles/sys-front-inj-design/vars/main.yml @@ -1,6 +1,6 @@ --- # Constants -CSS_FILES: ["default.css", "bootstrap.css"] +CSS_FILES: ["layer.css", "default.css", "bootstrap.css"] CSS_BASE_COLOR: "{{ lookup('config', 'web-svc-design', 'services.design.colors.base') }}" CSS_FONT: "{{ lookup('config', 'web-svc-design', 'services.design.font') }}" diff --git a/tests/unit/python/roles/sys-front-inj-all/filter_plugins/test_inj_snippets.py b/tests/unit/python/roles/sys-front-inj-all/filter_plugins/test_inj_snippets.py index ee3357c12e..67db581fd4 100644 --- a/tests/unit/python/roles/sys-front-inj-all/filter_plugins/test_inj_snippets.py +++ b/tests/unit/python/roles/sys-front-inj-all/filter_plugins/test_inj_snippets.py @@ -49,20 +49,26 @@ class TestInjSnippets(unittest.TestCase): cls.mod = module + cls.feature_top_only = "zz_toponly" cls.feature_head_only = "zz_headonly" cls.feature_body_only = "zz_bodyonly" cls.feature_both = "zz_both" cls.feature_missing = "zz_missing" + cls._mkrole(cls.feature_top_only, top=True) cls._mkrole(cls.feature_head_only, head=True, body=False) cls._mkrole(cls.feature_body_only, head=False, body=True) cls._mkrole(cls.feature_both, head=True, body=True) @classmethod - def _mkrole(cls, feature, head=False, body=False): + def _mkrole(cls, feature, head=False, body=False, top=False): role_dir = str(Path(cls.roles_dir) / f"sys-front-inj-{feature}") tmpl_dir = str(Path(role_dir) / "templates") Path(tmpl_dir).mkdir(parents=True, exist_ok=True) + if top: + (Path(tmpl_dir) / "top_sub.j2").write_text( + "\n", encoding="utf-8" + ) if head: with Path(str(Path(tmpl_dir) / "head_sub.j2")).open( "w", encoding="utf-8" @@ -78,6 +84,15 @@ class TestInjSnippets(unittest.TestCase): def tearDownClass(cls): cls.tmp.cleanup() + def test_top_features_filter(self): + features = [self.feature_top_only, self.feature_head_only, self.feature_both] + result = self.mod.inj_features_filter(features, kind="top") + self.assertEqual(result, [self.feature_top_only]) + + def test_unknown_kind_is_rejected(self): + with self.assertRaises(ValueError): + self.mod.inj_features_filter([self.feature_both], kind="footer") + def test_head_features_filter(self): features = [self.feature_head_only, self.feature_both, self.feature_body_only] result = self.mod.inj_features_filter(features, kind="head")