From 0c166534e97925f834ce6f7b9e14035a8ba0c5a8 Mon Sep 17 00:00:00 2001 From: Rim Zabarov Date: Tue, 17 Nov 2026 17:48:44 +0300 Subject: [PATCH] Align the home hero with the gutter, keep the effect off the text on phones, keep header tools on narrow screens - Full-width landing blocks left out a classic scrollbar: 100vw counts it, so the hero sat half a scrollbar to the left (heading at 5 px instead of the 12 px gutter at 390, 41 instead of 48 at 1440). The shell measures the scrollbar into --docara-scrollbar-inline-size and the block leaves it out. - Hero effect_narrow (hide by default, or show): below md (44rem) the hero text spans the block, so the background effect is not shown there; the hero keeps its pre-effect surface, the pause button is hidden and the effect is paused. - sf-header-site 1.11 moves the slotted tools element that holds the language picker into its panel when collapsed; search and reader settings were in that same element, so a narrow page with a language picker kept only the menu and the logo. The language picker is now a tools element of its own. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 22 ++++++++++ docs/site/content/en/components/effects.md | 22 +++++++++- docs/site/content/en/components/hero.md | 1 + .../content/en/reference/errors/content.md | 2 +- docs/site/content/ru/components/effects.md | 22 +++++++++- docs/site/content/ru/components/hero.md | 1 + .../content/ru/reference/errors/content.md | 2 +- .../component-catalog/descriptions/ru.json | 1 + .../parameter-vocabulary.json | 4 ++ .../component-catalog/source-metadata.json | 6 +-- .../component-catalog/typed/docara.hero.json | 3 +- resources/portable/declarative-shell.css | 12 +++--- resources/portable/declarative-shell.js | 33 +++++++++++++-- src/PortableSite/PortableMarkdownRenderer.php | 14 +++++-- src/PortableSite/PortableSiteHeader.php | 40 +++++++++++++++++-- tests/PortableSiteBuilderTest.php | 7 ++-- tests/Unit/ArticleLayoutContractTest.php | 18 +++++++-- tests/Unit/FrameworkNativeSurfaceTest.php | 4 +- tests/Unit/HeroEffectTest.php | 33 +++++++++++++++ tests/Unit/PortableSiteHeaderTest.php | 39 ++++++++++++++++++ 20 files changed, 252 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6a9c73d..6b341212 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,30 @@ All notable changes to Docara are recorded here. The format follows ## [Unreleased] +### Added + +- Hero `effect_narrow` (`hide` by default, or `show`): below 704 px (the + Framework's md), where the hero is one column and its text spans the block, + a background effect is no longer drawn under the heading, the text and the + buttons. The hero keeps the surface it has before an effect runs, the pause + button is not shown and the effect is paused; from md it runs again. + `effect_narrow=show` keeps the effect at every width. + ### Fixed +- Full-width landing blocks (the home hero) no longer sit half a scrollbar to + the left with a classic vertical scrollbar: 100vw counts the scrollbar, so + the shell measures it into `--docara-scrollbar-inline-size` and the block + leaves it out. The hero heading now starts at the page gutter (12 px at + 390 px, 48 px at 1440 px; it was 5 and 41). +- With SIMAI Framework `sf-header-site` 1.11, a collapsed header kept only the + menu button and the logo on a page with a language picker (the home page): + the bar moves the slotted tools element that holds the language picker into + its panel, and the search and reader settings were in that same element. + The language picker is now a tools element of its own, so search and + reader settings stay in the narrow header as on documentation pages, and + only the language moves to the panel. + - Link previews: pages state the share image's type, width, height and alt text (`og:image:type`, `og:image:width`, `og:image:height`, `og:image:alt`), so messengers and social networks draw the card at once. diff --git a/docs/site/content/en/components/effects.md b/docs/site/content/en/components/effects.md index 6d7c97cb..bfa8e23d 100644 --- a/docs/site/content/en/components/effects.md +++ b/docs/site/content/en/components/effects.md @@ -74,6 +74,7 @@ or `media=background`. | `effect` | An effect identifier from the catalogue, 2 to 41 characters, or the `https` address of its `effect.json` file inside the catalogue. | | `effect_theme` | The light or dark version of the effect: `auto` follows the page (the default), `dark` or `light`. | | `effect_settings` | The effect settings — a JSON object in single quotes, for example `'{"speed": 80}'`. effects.simai.io shows which settings an effect has. | +| `effect_narrow` | The effect on a narrow screen, below 704 px: `hide` does not show it (the default), `show` shows it. | ```markdown :::hero {layout=centered effect=aurora-curtain effect_theme=dark effect_settings='{"speed": 80}'} @@ -136,6 +137,23 @@ Elevation lines, as on a topographic map. All the catalogue's effects and their settings are shown on [effects.simai.io](https://effects.simai.io/). +## Narrow screens + +Below 704 px the Hero is one column, and its text spans the whole width. The +effect would be drawn under the heading, the text and the buttons, so by +default it is not shown there: the Hero keeps the background it has before +the effect starts, the pause button does not appear, and the effect itself +is paused. From 704 px the effect is visible again. + +To show the effect at every width, for example a calm background under a +short heading, set `effect_narrow=show`: + +```markdown +:::hero {layout=centered effect=aurora-curtain effect_narrow=show} +# Documentation that is easy to read +::: +``` + ## Pause and reduced motion While the effect moves, the bottom right corner of the Hero (the left one in @@ -199,10 +217,10 @@ each error are in the reference: | Code | When it occurs | | --- | --- | | `MARKDOWN_HERO_EFFECT_INVALID` | `effect` is neither an effect identifier nor an `effect.json` address. | -| `MARKDOWN_HERO_EFFECT_REQUIRED` | `effect_theme` or `effect_settings` are set without `effect`. | +| `MARKDOWN_HERO_EFFECT_REQUIRED` | `effect_theme`, `effect_settings` or `effect_narrow` are set without `effect`. | | `MARKDOWN_HERO_EFFECT_SETTINGS_INVALID` | `effect_settings` is not a JSON object. | | `MARKDOWN_HERO_EFFECT_MEDIA_CONFLICT` | One Hero has both an effect and a background image. | -| `MARKDOWN_COMPONENT_ATTRIBUTE_VALUE_INVALID` | `effect_theme` has a value other than `auto`, `dark` or `light`. | +| `MARKDOWN_COMPONENT_ATTRIBUTE_VALUE_INVALID` | `effect_theme` has a value other than `auto`, `dark` or `light`, or `effect_narrow` other than `hide` or `show`. | | `EFFECTS_CATALOGUE_REQUIRED` | A page uses an effect, but `docara.json` has no `effects.catalogue`. | | `EFFECTS_OUTSIDE_CATALOGUE` | The effect is given by an address outside the connected catalogue. Docara builds only the catalogue's effects. | | `EFFECTS_CATALOGUE_INVALID` | The catalogue address is not `https://`, does not end with `/` or contains invalid characters. | diff --git a/docs/site/content/en/components/hero.md b/docs/site/content/en/components/hero.md index 55ad1408..92e31251 100644 --- a/docs/site/content/en/components/hero.md +++ b/docs/site/content/en/components/hero.md @@ -200,6 +200,7 @@ motion is turned on in the system, the effect shows a still frame. | `effect` | string | — | The name of a SIMAI Framework background effect. | | `effect_theme` | `auto`, `dark`, `light` | `auto` | The effect theme: follows the page theme, always dark or always light. | | `effect_settings` | string | — | The effect settings as JSON. | +| `effect_narrow` | `hide`, `show` | `hide` | The effect below 704 px: hidden, since the text spans the Hero there, or shown. | diff --git a/docs/site/content/en/reference/errors/content.md b/docs/site/content/en/reference/errors/content.md index 350272de..beb76399 100644 --- a/docs/site/content/en/reference/errors/content.md +++ b/docs/site/content/en/reference/errors/content.md @@ -175,7 +175,7 @@ Markdown blocks start with a `:::name` line and end with a `:::` line. | `MARKDOWN_HERO_SIDE_IMAGE_CASE_MISMATCH`, `MARKDOWN_HERO_BACKGROUND_CASE_MISMATCH` | The letter case in the path does not match the file name. **What to do:** Fix the path. | | `MARKDOWN_HERO_SIDE_IMAGE_CONTEXT_INVALID`, `MARKDOWN_HERO_BACKGROUND_CONTEXT_INVALID` | An image from `/assets/` is used by a file outside `content//`. **What to do:** Use the hero on pages in a language folder. | | `MARKDOWN_HERO_EFFECT_INVALID` | `effect` is neither an effect name from the catalogue nor an `https://.../effect.json` address. **What to do:** Give an effect name, for example `aurora-curtain`. | -| `MARKDOWN_HERO_EFFECT_REQUIRED` | `effect_theme` or `effect_settings` is given without `effect`. **What to do:** Add `effect` or remove these attributes. | +| `MARKDOWN_HERO_EFFECT_REQUIRED` | `effect_theme`, `effect_settings` or `effect_narrow` is given without `effect`. **What to do:** Add `effect` or remove these attributes. | | `MARKDOWN_HERO_EFFECT_SETTINGS_INVALID` | `effect_settings` is not a JSON object. **What to do:** Write the settings as `{"speed": 0.5}`. | | `MARKDOWN_HERO_EFFECT_MEDIA_CONFLICT` | A background effect and a background image at once. **What to do:** Keep one of them. | diff --git a/docs/site/content/ru/components/effects.md b/docs/site/content/ru/components/effects.md index e281efd0..48164b80 100644 --- a/docs/site/content/ru/components/effects.md +++ b/docs/site/content/ru/components/effects.md @@ -74,6 +74,7 @@ Hero, но не с фоновой картинкой: укажите либо `e | `effect` | Идентификатор эффекта из каталога, от 2 до 41 символа, или `https`-адрес его файла `effect.json` внутри каталога. | | `effect_theme` | Светлая или тёмная версия эффекта: `auto` — как у страницы (по умолчанию), `dark` или `light`. | | `effect_settings` | Настройки эффекта — объект JSON в одинарных кавычках, например `'{"speed": 80}'`. Какие настройки есть у эффекта, показано на effects.simai.io. | +| `effect_narrow` | Эффект на узком экране, уже 704 px: `hide` — не показывать (по умолчанию), `show` — показывать. | ```markdown :::hero {layout=centered effect=aurora-curtain effect_theme=dark effect_settings='{"speed": 80}'} @@ -134,6 +135,23 @@ Hero, но не с фоновой картинкой: укажите либо `e Все эффекты каталога и их настройки показаны на [effects.simai.io](https://effects.simai.io/). +## Узкий экран + +На экране уже 704 px Hero занимает одну колонку, и текст идёт во всю его +ширину. Эффект оказался бы под заголовком, текстом и кнопками, поэтому там он +по умолчанию не показывается: Hero остаётся с фоном, который у него до запуска +эффекта, кнопки паузы нет, а сам эффект стоит на паузе. Шире 704 px эффект +снова виден. + +Чтобы эффект был виден на любой ширине, например спокойный фон под коротким +заголовком, задайте `effect_narrow=show`: + +```markdown +:::hero {layout=centered effect=aurora-curtain effect_narrow=show} +# Документация, которую легко читать +::: +``` + ## Пауза и уменьшение движения Пока эффект движется, в правом нижнем углу Hero (на языках с письмом справа @@ -192,10 +210,10 @@ Docara не задаёт заголовок Content-Security-Policy. Если в | Код | Когда возникает | | --- | --- | | `MARKDOWN_HERO_EFFECT_INVALID` | `effect` — не идентификатор эффекта и не адрес `effect.json`. | -| `MARKDOWN_HERO_EFFECT_REQUIRED` | `effect_theme` или `effect_settings` указаны без `effect`. | +| `MARKDOWN_HERO_EFFECT_REQUIRED` | `effect_theme`, `effect_settings` или `effect_narrow` указаны без `effect`. | | `MARKDOWN_HERO_EFFECT_SETTINGS_INVALID` | `effect_settings` — не объект JSON. | | `MARKDOWN_HERO_EFFECT_MEDIA_CONFLICT` | В одном Hero и эффект, и фоновая картинка. | -| `MARKDOWN_COMPONENT_ATTRIBUTE_VALUE_INVALID` | У `effect_theme` значение не `auto`, `dark` или `light`. | +| `MARKDOWN_COMPONENT_ATTRIBUTE_VALUE_INVALID` | У `effect_theme` значение не `auto`, `dark` или `light`, или у `effect_narrow` — не `hide` или `show`. | | `EFFECTS_CATALOGUE_REQUIRED` | Страница использует эффект, а в `docara.json` нет `effects.catalogue`. | | `EFFECTS_OUTSIDE_CATALOGUE` | Эффект указан адресом вне подключённого каталога. Docara собирает только эффекты каталога. | | `EFFECTS_CATALOGUE_INVALID` | Адрес каталога не `https://`, не заканчивается на `/` или содержит недопустимые символы. | diff --git a/docs/site/content/ru/components/hero.md b/docs/site/content/ru/components/hero.md index 66c2ca83..3d512747 100644 --- a/docs/site/content/ru/components/hero.md +++ b/docs/site/content/ru/components/hero.md @@ -198,6 +198,7 @@ Content-Security-Policy, описано на странице | `effect` | строка | — | Имя фонового эффекта SIMAI Framework. | | `effect_theme` | `auto`, `dark`, `light` | `auto` | Тема эффекта: по теме страницы, всегда тёмная или всегда светлая. | | `effect_settings` | строка | — | Настройки эффекта в виде JSON. | +| `effect_narrow` | `hide`, `show` | `hide` | Эффект на экране уже 704 px: скрыт, потому что текст идёт во всю ширину Hero, или показан. | diff --git a/docs/site/content/ru/reference/errors/content.md b/docs/site/content/ru/reference/errors/content.md index e633d4fc..1974095a 100644 --- a/docs/site/content/ru/reference/errors/content.md +++ b/docs/site/content/ru/reference/errors/content.md @@ -174,7 +174,7 @@ Front matter — блок между двумя строками `---` в нач | `MARKDOWN_HERO_SIDE_IMAGE_CASE_MISMATCH`, `MARKDOWN_HERO_BACKGROUND_CASE_MISMATCH` | Регистр букв в пути не совпадает с именем файла. **Что сделать:** Исправьте путь. | | `MARKDOWN_HERO_SIDE_IMAGE_CONTEXT_INVALID`, `MARKDOWN_HERO_BACKGROUND_CONTEXT_INVALID` | Картинку из `/assets/` использует файл вне `content/<язык>/`. **Что сделать:** Используйте hero на страницах в каталоге языка. | | `MARKDOWN_HERO_EFFECT_INVALID` | `effect` — не имя эффекта из каталога и не адрес `https://.../effect.json`. **Что сделать:** Укажите имя эффекта, например `aurora-curtain`. | -| `MARKDOWN_HERO_EFFECT_REQUIRED` | `effect_theme` или `effect_settings` указаны без `effect`. **Что сделать:** Добавьте `effect` или уберите эти атрибуты. | +| `MARKDOWN_HERO_EFFECT_REQUIRED` | `effect_theme`, `effect_settings` или `effect_narrow` указаны без `effect`. **Что сделать:** Добавьте `effect` или уберите эти атрибуты. | | `MARKDOWN_HERO_EFFECT_SETTINGS_INVALID` | `effect_settings` не является объектом JSON. **Что сделать:** Запишите настройки как `{"speed": 0.5}`. | | `MARKDOWN_HERO_EFFECT_MEDIA_CONFLICT` | Одновременно фоновый эффект и фоновая картинка. **Что сделать:** Оставьте что-то одно. | diff --git a/resources/component-catalog/descriptions/ru.json b/resources/component-catalog/descriptions/ru.json index 6609f780..17c1fb37 100644 --- a/resources/component-catalog/descriptions/ru.json +++ b/resources/component-catalog/descriptions/ru.json @@ -91,6 +91,7 @@ "docara.hero.effect": "Имя фонового эффекта SIMAI Framework.", "docara.hero.effect_theme": "Тема эффекта: по теме страницы, всегда тёмная или всегда светлая.", "docara.hero.effect_settings": "Настройки эффекта в виде JSON.", + "docara.hero.effect_narrow": "Эффект на экране уже 704 px: скрыт, потому что текст идёт во всю ширину Hero, или показан.", "docara.internal_preview.size": "Высота окна предпросмотра.", "docara.internal_preview.title": "Название предпросмотра.", "docara.logos.tone": "`muted` приглушает логотипы, чтобы они не спорили с основным содержимым.", diff --git a/resources/component-catalog/parameter-vocabulary.json b/resources/component-catalog/parameter-vocabulary.json index cb0a5659..0454da26 100644 --- a/resources/component-catalog/parameter-vocabulary.json +++ b/resources/component-catalog/parameter-vocabulary.json @@ -205,6 +205,10 @@ "components": ["hero"], "reason": "JSON settings passed to the background effect." }, + "effect_narrow": { + "components": ["hero"], + "reason": "Whether the background effect is drawn below md, where the hero text spans the block." + }, "display": { "components": ["math"], "reason": "Inline or block formula, the TeX term for the same choice." diff --git a/resources/component-catalog/source-metadata.json b/resources/component-catalog/source-metadata.json index aa98209c..4e802d64 100644 --- a/resources/component-catalog/source-metadata.json +++ b/resources/component-catalog/source-metadata.json @@ -150,7 +150,7 @@ }, { "source_ref": "docs/site/content/ru/components/hero.md", - "source_sha256": "80094d6b3968052da1e042d7c640a826baf8f14315eb4ad2f0a9fc1d151bae7b", + "source_sha256": "9774a922129854ac0cbcd28310dde2fd3e4390096a57fceb2ecdc8972f79c5a0", "release": "3.16.0", "source_url": "https://github.com/simai/docara/blob/v3.16.0/docs/site/content/ru/components/hero.md", "history_url": "https://github.com/simai/docara/commits/v3.16.0/docs/site/content/ru/components/hero.md", @@ -454,7 +454,7 @@ }, { "source_ref": "resources/component-catalog/typed/docara.hero.json", - "source_sha256": "401b919a62deb57d3934200f8951c02aaa7e566ee7318e659c4a738b963573a7", + "source_sha256": "3ae8932c5523aac55829bd1bb22b857d7b03d8c72a6489d9ffb3db84701d90ed", "release": "3.16.0", "source_url": "https://github.com/simai/docara/blob/v3.16.0/resources/component-catalog/typed/docara.hero.json", "history_url": "https://github.com/simai/docara/commits/v3.16.0/resources/component-catalog/typed/docara.hero.json", @@ -573,5 +573,5 @@ "history_exact": false } ], - "content_sha256": "532ab62b4b8e19b2fc9e12fd79f87ed5ca722572dbc481fee655f3ddb9946ad9" + "content_sha256": "3be4454c4a71faad4f4fd8aa6eba3c5215e541af69157992d1cd90421d60d0a2" } diff --git a/resources/component-catalog/typed/docara.hero.json b/resources/component-catalog/typed/docara.hero.json index 2fd21214..a484b101 100644 --- a/resources/component-catalog/typed/docara.hero.json +++ b/resources/component-catalog/typed/docara.hero.json @@ -23,7 +23,8 @@ {"name": "overlay_strength", "type": "enum", "required": false, "default": "medium", "values": ["soft", "medium", "strong"], "available_when": {"media": "background"}}, {"name": "effect", "type": "string", "required": false}, {"name": "effect_theme", "type": "enum", "required": false, "default": "auto", "values": ["auto", "dark", "light"]}, - {"name": "effect_settings", "type": "string", "required": false} + {"name": "effect_settings", "type": "string", "required": false}, + {"name": "effect_narrow", "type": "enum", "required": false, "default": "hide", "values": ["hide", "show"]} ] }, "states": [ diff --git a/resources/portable/declarative-shell.css b/resources/portable/declarative-shell.css index 92585f86..b2f9b8e1 100644 --- a/resources/portable/declarative-shell.css +++ b/resources/portable/declarative-shell.css @@ -8,9 +8,9 @@ body[data-docara-shell]{opacity:1!important} .docara-outline-mobile{display:none} /* The header is the Framework sf-header-site (PortableSiteHeader): the navigation fills the bar between the brand and the tools. */ .docara-header-content{flex:1 1 auto} -/* Until sf-language has drawn its trigger (it then sets data-look), it holds the place of that trigger, so the tools do not shift while its script loads. From sf-language 1.4 (owner decision C142) the trigger is a size-1 button with the language icon, the two-letter code and a chevron: 120 px from the Framework lg breakpoint (60rem), 100 px below it, where the size-1 control is smaller. */ -.docara-header-tools>sf-language[data-docara-language]:not([data-look]){display:inline-block;inline-size:7.5rem;block-size:2.5rem} -@media(max-width:59.99rem){.docara-header-tools>sf-language[data-docara-language]:not([data-look]){inline-size:6.25rem}} +/* Until sf-language has drawn its trigger (it then sets data-look), it holds the place of that trigger, so the tools do not shift while its script loads. From sf-language 1.4 (owner decision C142) the trigger is a size-1 button with the language icon, the two-letter code and a chevron: 120 px from the Framework lg breakpoint (60rem), 100 px below it, where the size-1 control is smaller. The picker is a tools element of its own (PortableSiteHeader::splitTools), so in the drawn bar it stands in the bar's tools row. */ +.sf-site-header-tools>sf-language[data-docara-language]:not([data-look]){display:inline-block;inline-size:7.5rem;block-size:2.5rem} +@media(max-width:59.99rem){.sf-site-header-tools>sf-language[data-docara-language]:not([data-look]){inline-size:6.25rem}} /* The language menu is positioned for its popup, so it would paint over the open panel and its scrim that come before it; they are lifted over the bar's own controls. */ .docara-header .sf-site-header--open .sf-site-header-scrim,.docara-header .sf-site-header--open .sf-site-header-panel{z-index:1} /* The search field follows the Framework size-1 control height, which is smaller on phones, like the icon buttons beside it. */ @@ -203,12 +203,14 @@ body[data-docara-shell] sf-button:not(:where(.docara-example-inline *)){display: [data-docara-block="hero"][data-sf-effect]:not([data-sf-effect-state="running"]){background-color:var(--sf-surface-1)} [data-docara-block="hero"]>.docara-effect-toggle{position:absolute;z-index:1;inset-block-end:var(--sf-space-1\/3);inset-inline-end:var(--sf-space-1);margin:0;--sf-icon-button-background-color:var(--sf-surface-0);--sf-icon-button-border-color:var(--sf-outline-variant)} [data-docara-block="hero"]>.docara-effect-toggle[hidden]{display:none} +/* Below md a hero is one column and its text spans the block, so a background effect would be drawn under the heading, the text and the buttons. With effect_narrow=hide (the default) the hero shows no effect there: the layer and its pause button are not shown, the shell pauses the effect, and the hero keeps the surface it has before an effect runs. effect_narrow=show keeps the effect at every width. */ +@media not all and (min-width:44rem){[data-docara-block="hero"][data-sf-effect]:not([data-docara-effect-narrow="show"])>[data-sf-effect-layer],[data-docara-block="hero"][data-sf-effect]:not([data-docara-effect-narrow="show"])>.docara-effect-toggle{display:none}[data-docara-block="hero"][data-sf-effect]:not([data-docara-effect-narrow="show"]){background-color:var(--sf-surface-1)}} [data-docara-block="hero"]:has(>.docara-padding-2xl)>.docara-effect-toggle{inset-block-end:min(var(--sf-space-1),(var(--docara-padding-2xl) - var(--sf-ui-1--control-height))/2)} @media (prefers-reduced-motion:no-preference){[data-docara-block="hero"]:has(>.docara-effect-toggle)>[data-docara-container]:not(.docara-padding-2xl){padding-block-end:calc(var(--sf-ui-1--control-height) + 2*var(--sf-space-1\/3))}} .docara-landing .docara-content{width:100%} .docara-landing .docara-content>[data-docara-section][data-docara-region-owner="main"]{box-sizing:border-box;width:100%;max-width:none;margin:0;padding:0} -/* A full-width block reaches the edges of the main region. On a landing the main region spans the window, so the block takes the window width centred on the article; in the documentation layout the article already fills the main region, so the block keeps the column width. */ -.docara-landing .docara-content>[data-docara-width="full"],.docara-landing .docara-content>[data-docara-section][data-docara-region-owner="main"]>[data-docara-width="full"]{box-sizing:border-box;width:100vw;margin-inline:calc(50% - 50vw)} +/* A full-width block reaches the edges of the main region. On a landing the main region spans the window, so the block takes the window width centred on the article; in the documentation layout the article already fills the main region, so the block keeps the column width. 100vw counts a classic vertical scrollbar, which the main region does not have: the shell measures the scrollbar into --docara-scrollbar-inline-size and the block leaves it out, so its content lines up with the page gutter instead of sitting half a scrollbar to the left. */ +.docara-landing .docara-content>[data-docara-width="full"],.docara-landing .docara-content>[data-docara-section][data-docara-region-owner="main"]>[data-docara-width="full"]{box-sizing:border-box;width:calc(100vw - var(--docara-scrollbar-inline-size,0px));margin-inline:calc(50% - 50vw + var(--docara-scrollbar-inline-size,0px)/2)} .docara-docs-layout [data-docara-region="main"]>.docara-prose>[data-docara-width="full"],.docara-docs-layout [data-docara-region="main"]>.docara-prose>[data-docara-section][data-docara-region-owner="main"]>[data-docara-width="full"]{box-sizing:border-box;width:100%;margin-inline:0} .docara-landing [data-docara-container]{box-sizing:border-box;width:100%} .docara-surface>[data-docara-surface-background],.docara-surface>[data-docara-surface-overlay]{position:absolute;inset:0;inline-size:100%;block-size:100%;pointer-events:none} diff --git a/resources/portable/declarative-shell.js b/resources/portable/declarative-shell.js index 93436044..039fab10 100644 --- a/resources/portable/declarative-shell.js +++ b/resources/portable/declarative-shell.js @@ -28,6 +28,18 @@ if(typeof MutationObserver==='function'){new MutationObserver(measure).observe(host,{childList:true})} if(!resize){window.addEventListener('resize',measure)} })(); + /* A landing's full-width block takes the window width, and 100vw counts a classic vertical scrollbar the main region does not have. The shell measures the scrollbar into --docara-scrollbar-inline-size, which the stylesheet leaves out of the block, and measures again when the scrollbar comes or goes or the window changes. Overlay scrollbars measure 0. */ + (function(){ + if(!document.querySelector('.docara-landing'))return; + var root=document.documentElement,current=null; + function measure(){ + var size=Math.max(0,window.innerWidth-root.clientWidth)+'px'; + if(size!==current){current=size;root.style.setProperty('--docara-scrollbar-inline-size',size)} + } + measure(); + if(typeof ResizeObserver==='function'){new ResizeObserver(measure).observe(root)} + window.addEventListener('resize',measure); + })(); var copyNode=document.getElementById('docara-runtime-copy'),messages={}; try{messages=JSON.parse(copyNode?copyNode.textContent:'{}')}catch(error){messages={}} function message(id,parameters){ @@ -1393,16 +1405,21 @@ function sync(entry){ var running=entry.hero.getAttribute('data-sf-effect-state')==='running'; var reduced=Boolean(reducedMotion&&reducedMotion.matches); - entry.button.hidden=!running||reduced||!(entry.handle||effects()); + var narrow=hiddenNarrow(entry); + entry.button.hidden=!running||reduced||narrow||!(entry.handle||effects()); var label=message(paused?'effects.play':'effects.pause'); if(entry.button.getAttribute('aria-label')!==label){entry.button.setAttribute('aria-label',label)} if(entry.button.title!==label){entry.button.title=label} var name=paused?'play_arrow':'pause'; if(entry.icon.textContent!==name){entry.icon.textContent=name} if(entry.handle){ - if(paused){entry.handle.pause()}else{entry.handle.resume()} + if(paused||narrow){entry.handle.pause()}else{entry.handle.resume()} } } + /* Below md the stylesheet does not show the effect of a hero with effect_narrow=hide (the default), since the text spans the block there; the effect is paused too, so it draws no frames nobody sees. */ + function hiddenNarrow(entry){ + return Boolean(entry.wide&&!entry.wide.matches); + } function place(entry){ var api=effects(); if(!api)return; @@ -1421,8 +1438,16 @@ button.className='docara-effect-toggle sf-icon-button sf-icon-button--icon sf-icon-button--surface sf-icon-button--on-surface sf-icon-button--size-1 inline-grid items-cross-center content-main-center m-0'; button.innerHTML=''; hero.appendChild(button); - var entry={hero:hero,button:button,icon:button.firstChild,handle:null,placing:null}; + var wide=hero.getAttribute('data-docara-effect-narrow')!=='show'&&window.matchMedia?window.matchMedia('(min-width: 44rem)'):null; + var entry={hero:hero,button:button,icon:button.firstChild,handle:null,placing:null,wide:wide}; entries.push(entry); + if(wide){ + var onWidth=function(){ + if(!entry.handle&&hiddenNarrow(entry))place(entry); + sync(entry); + }; + if(wide.addEventListener){wide.addEventListener('change',onWidth)}else if(wide.addListener){wide.addListener(onWidth)} + } button.addEventListener('click',function(){ paused=!paused; try{localStorage.setItem(storageKey,paused?'true':'false')}catch(error){} @@ -1437,7 +1462,7 @@ }); function start(){ entries.forEach(function(entry){ - if(!entry.hero.hasAttribute('data-sf-effect-state')||paused)place(entry); + if(!entry.hero.hasAttribute('data-sf-effect-state')||paused||hiddenNarrow(entry))place(entry); sync(entry); }); } diff --git a/src/PortableSite/PortableMarkdownRenderer.php b/src/PortableSite/PortableMarkdownRenderer.php index 278bcf0c..7be23802 100644 --- a/src/PortableSite/PortableMarkdownRenderer.php +++ b/src/PortableSite/PortableMarkdownRenderer.php @@ -3185,17 +3185,20 @@ static function (array $match) use (&$actionIndex): string { * effect.json, `effect_theme` the placement's theme mode and * `effect_settings` a JSON object of stored settings. The Framework * Loader mounts the effect and gives the hero the theme it draws, so the - * hero text follows that theme. Returns the escaped attributes, or ''. + * hero text follows that theme. `effect_narrow` says whether the effect + * is drawn below md, where the hero is one column and its text spans the + * block: `hide` (the default, no attribute) or `show`. Returns the + * escaped attributes, or ''. * * @param array $attributes */ private function heroEffect(array $attributes): string { if (! isset($attributes['effect'])) { - if (isset($attributes['effect_theme']) || isset($attributes['effect_settings'])) { + if (isset($attributes['effect_theme']) || isset($attributes['effect_settings']) || isset($attributes['effect_narrow'])) { throw new PortableConfigurationException( 'MARKDOWN_HERO_EFFECT_REQUIRED', - 'Hero effect_theme and effect_settings require effect.', + 'Hero effect_theme, effect_settings and effect_narrow require effect.', ); } @@ -3238,6 +3241,11 @@ private function heroEffect(array $attributes): string 'UTF-8', ) . '"'; } + if (isset($attributes['effect_narrow']) + && $this->catalogueChoice($attributes['effect_narrow'], 'hero', 'effect_narrow') === 'show' + ) { + $html .= ' data-docara-effect-narrow="show"'; + } return $html; } diff --git a/src/PortableSite/PortableSiteHeader.php b/src/PortableSite/PortableSiteHeader.php index 490a10ee..de640123 100644 --- a/src/PortableSite/PortableSiteHeader.php +++ b/src/PortableSite/PortableSiteHeader.php @@ -31,7 +31,7 @@ /** * @param string $headerRegion the rendered header region: the docara.header section and any section the site adds * @param array{url:string,label:string}|null $portalHome escaped - * @param string $tools the search, language, reader settings and repository controls in one element + * @param string $tools the search, language, reader settings and repository controls in one element; the language picker is split out of it (splitTools) * @param string $sheet the navigation sheet content, or '' * @param array $copy escaped UI copy * @param string $collapse the Framework breakpoint below which the bar collapses: xl, lg or none @@ -53,7 +53,7 @@ public function render( $brand = trim($brand) === '' ? '' : '
' . $brand . '
'; $content = trim($content) === '' ? '' : '
' . $content . '
'; $actions = trim($actions) === '' ? '' : '
' . $actions . '
'; - $tools = trim($tools); + $tools = $this->splitTools(trim($tools)); $sheet = trim($sheet); $picture = '
' @@ -67,7 +67,7 @@ public function render( . ($content === '' ? '' : '
' . $this->copyOf($content) . '
') . ($actions === '' ? '' : '
' . $this->copyOf($actions) . '
') . '' - . ($tools === '' ? '' : '
' . $this->copyOf($tools) . '
') + . ($tools === [] ? '' : '
' . $this->copyOf(implode('', $tools)) . '
') . '
'; return '' @@ -75,7 +75,7 @@ public function render( . $this->held($brand, 'brand') . $this->held($content, null) . $this->held($actions, 'actions') - . $this->held($tools, 'tools') + . implode('', array_map(fn (string $part): string => $this->held($part, 'tools'), $tools)) . $this->held($sheet, 'sheet') . ''; } @@ -105,6 +105,38 @@ private function split(string $region): array return [$brand, trim($inner), trim($added)]; } + /** + * The tools as the bar's tools slot takes them. Collapsed, sf-header-site + * moves a setting among the tools (the language picker) into its panel, + * and moves the whole slotted element that holds it: one element with + * the search, the language and the reader settings would leave the + * collapsed bar with no tools at all. So the language picker is a tools + * element of its own, between the tools before it and the tools after + * it, each kept in Docara's tools row; wide, the bar shows them in that + * order as before. + * + * @return list + */ + private function splitTools(string $tools): array + { + if ($tools === '') { + return []; + } + if (preg_match('~\A(
)(.*?)()(.*)
\z~s', $tools, $match) !== 1) { + return [$tools]; + } + [, $open, $before, $language, $after] = $match; + + return array_values(array_filter( + [ + trim($before) === '' ? '' : $open . $before . '', + $language, + trim($after) === '' ? '' : $open . $after . '', + ], + fn (string $part): bool => $part !== '', + )); + } + /** A slotted original, held out of view while the picture stands. */ private function held(string $html, ?string $slot): string { diff --git a/tests/PortableSiteBuilderTest.php b/tests/PortableSiteBuilderTest.php index e6fb3abd..df662690 100644 --- a/tests/PortableSiteBuilderTest.php +++ b/tests/PortableSiteBuilderTest.php @@ -506,7 +506,8 @@ public function it_builds_arbitrary_bcp47_locale_trees_with_rtl_switching_and_al self::assertStringContainsString('position="right"', $russian); self::assertStringContainsString('إعدادات القراءة', $arabic); self::assertStringContainsString('data-docara-smart="docara.navigation"', $arabic); self::assertStringContainsString('aria-label="الأقسام"', $arabic); @@ -525,7 +526,7 @@ public function it_builds_arbitrary_bcp47_locale_trees_with_rtl_switching_and_al ] as $alternate) { self::assertStringContainsString($alternate, $arabic); } - self::assertStringContainsString('jsonFile($this->tmpPath('build_local/_docara/search-index.json')); @@ -885,7 +886,7 @@ public function it_builds_docs_landing_inheritance_components_and_explainable_pl 'The declarative main-region wrapper must not inset full-width landing blocks.', ); self::assertStringContainsString( - '.docara-landing .docara-content>[data-docara-width="full"],.docara-landing .docara-content>[data-docara-section][data-docara-region-owner="main"]>[data-docara-width="full"]{box-sizing:border-box;width:100vw;margin-inline:calc(50% - 50vw)}', + '.docara-landing .docara-content>[data-docara-width="full"],.docara-landing .docara-content>[data-docara-section][data-docara-region-owner="main"]>[data-docara-width="full"]{box-sizing:border-box;width:calc(100vw - var(--docara-scrollbar-inline-size,0px));margin-inline:calc(50% - 50vw + var(--docara-scrollbar-inline-size,0px)/2)}', $shellCss, 'Direct and Section-wrapped full-width landing surfaces must reach the window edges.', ); diff --git a/tests/Unit/ArticleLayoutContractTest.php b/tests/Unit/ArticleLayoutContractTest.php index 02f55800..9a63c4fe 100644 --- a/tests/Unit/ArticleLayoutContractTest.php +++ b/tests/Unit/ArticleLayoutContractTest.php @@ -23,6 +23,14 @@ private function shellCss(): string return $css; } + private function shellRuntime(): string + { + $js = file_get_contents(dirname(__DIR__, 2) . '/resources/portable/declarative-shell.js'); + self::assertIsString($js); + + return $js; + } + #[Test] public function no_element_around_the_article_is_a_size_container(): void { @@ -52,11 +60,15 @@ public function full_width_blocks_reach_the_window_on_a_landing_and_the_column_i $css = $this->shellCss(); self::assertStringContainsString( - '.docara-landing .docara-content>[data-docara-width="full"],.docara-landing .docara-content>[data-docara-section][data-docara-region-owner="main"]>[data-docara-width="full"]{box-sizing:border-box;width:100vw;margin-inline:calc(50% - 50vw)}', + '.docara-landing .docara-content>[data-docara-width="full"],.docara-landing .docara-content>[data-docara-section][data-docara-region-owner="main"]>[data-docara-width="full"]{box-sizing:border-box;width:calc(100vw - var(--docara-scrollbar-inline-size,0px));margin-inline:calc(50% - 50vw + var(--docara-scrollbar-inline-size,0px)/2)}', $css, ); - // A classic scrollbar makes 100vw wider than the page: the landing - // clips the excess instead of scrolling sideways. + // The shell measures a classic scrollbar, which 100vw counts, so the + // block content lines up with the page gutter. + self::assertStringContainsString("root.style.setProperty('--docara-scrollbar-inline-size',size)", $this->shellRuntime()); + self::assertStringContainsString('Math.max(0,window.innerWidth-root.clientWidth)', $this->shellRuntime()); + // Before the shell measures it, 100vw is wider than the page: the + // landing clips the excess instead of scrolling sideways. self::assertStringContainsString('.docara-landing{display:block;min-height:auto;overflow-x:clip}', $css); self::assertStringContainsString( '.docara-docs-layout [data-docara-region="main"]>.docara-prose>[data-docara-width="full"],.docara-docs-layout [data-docara-region="main"]>.docara-prose>[data-docara-section][data-docara-region-owner="main"]>[data-docara-width="full"]{box-sizing:border-box;width:100%;margin-inline:0}', diff --git a/tests/Unit/FrameworkNativeSurfaceTest.php b/tests/Unit/FrameworkNativeSurfaceTest.php index 1c8917d6..a097b874 100644 --- a/tests/Unit/FrameworkNativeSurfaceTest.php +++ b/tests/Unit/FrameworkNativeSurfaceTest.php @@ -29,8 +29,8 @@ public function locale_navigation_uses_an_icon_disclosure_instead_of_a_form_sele self::assertStringNotContainsString('.docara-language-menu', $css); // The reserve holds the sf-language 1.4 trigger's measured width (C142): // 120 px from 60rem, 100 px below it, not a 40 px icon. - self::assertStringContainsString('.docara-header-tools>sf-language[data-docara-language]:not([data-look]){display:inline-block;inline-size:7.5rem;block-size:2.5rem}', $css); - self::assertStringContainsString('@media(max-width:59.99rem){.docara-header-tools>sf-language[data-docara-language]:not([data-look]){inline-size:6.25rem}}', $css); + self::assertStringContainsString('.sf-site-header-tools>sf-language[data-docara-language]:not([data-look]){display:inline-block;inline-size:7.5rem;block-size:2.5rem}', $css); + self::assertStringContainsString('@media(max-width:59.99rem){.sf-site-header-tools>sf-language[data-docara-language]:not([data-look]){inline-size:6.25rem}}', $css); self::assertStringContainsString('[data-docara-block="features"]>li>.docara-icon{align-self:flex-start}', $css); self::assertStringContainsString("head.classList.add('docara-code-header')", $runtime); self::assertStringContainsString('title&&title.textContent!==languageLabel', $runtime); diff --git a/tests/Unit/HeroEffectTest.php b/tests/Unit/HeroEffectTest.php index a20edf11..852eab0c 100644 --- a/tests/Unit/HeroEffectTest.php +++ b/tests/Unit/HeroEffectTest.php @@ -51,6 +51,37 @@ public function the_effect_attributes_land_on_the_hero_section_escaped(): void ); } + #[Test] + public function a_hero_effect_is_not_shown_under_the_text_on_a_narrow_screen_unless_asked(): void + { + // hide is the default and adds no attribute; show marks the hero. + self::assertStringNotContainsString('data-docara-effect-narrow', $this->render(":::hero {media=none effect=assembly}\n# Hero\n\nDescription.\n:::")); + self::assertStringNotContainsString('data-docara-effect-narrow', $this->render(":::hero {media=none effect=assembly effect_narrow=hide}\n# Hero\n\nDescription.\n:::")); + self::assertStringStartsWith( + '
render(":::hero {media=none effect=assembly effect_narrow=show}\n# Hero\n\nDescription.\n:::"), + ); + + // Below md (44rem) the layer and its pause button are not shown and + // the hero keeps its surface from before the effect runs; the shell + // pauses the effect there and takes it up again from md. + $css = (string) file_get_contents(dirname(__DIR__, 2) . '/resources/portable/declarative-shell.css'); + self::assertStringContainsString( + '@media not all and (min-width:44rem){[data-docara-block="hero"][data-sf-effect]:not([data-docara-effect-narrow="show"])>[data-sf-effect-layer],' + . '[data-docara-block="hero"][data-sf-effect]:not([data-docara-effect-narrow="show"])>.docara-effect-toggle{display:none}' + . '[data-docara-block="hero"][data-sf-effect]:not([data-docara-effect-narrow="show"]){background-color:var(--sf-surface-1)}}', + $css, + ); + $shell = (string) file_get_contents(dirname(__DIR__, 2) . '/resources/portable/declarative-shell.js'); + foreach ([ + "hero.getAttribute('data-docara-effect-narrow')!=='show'&&window.matchMedia?window.matchMedia('(min-width: 44rem)'):null", + 'if(paused||narrow){entry.handle.pause()}else{entry.handle.resume()}', + 'entry.button.hidden=!running||reduced||narrow||', + ] as $needle) { + self::assertStringContainsString($needle, $shell); + } + } + #[Test] public function a_running_hero_effect_can_be_paused_with_a_localized_control(): void { @@ -119,6 +150,8 @@ public function invalid_effect_inputs_are_refused(): void "effect=aurora-curtain effect_settings='{speed: 80}'" => 'MARKDOWN_HERO_EFFECT_SETTINGS_INVALID', "effect=aurora-curtain effect_settings='\"text\"'" => 'MARKDOWN_HERO_EFFECT_SETTINGS_INVALID', 'effect_theme=dark' => 'MARKDOWN_HERO_EFFECT_REQUIRED', + 'effect_narrow=show' => 'MARKDOWN_HERO_EFFECT_REQUIRED', + 'effect=aurora-curtain effect_narrow=always' => 'MARKDOWN_COMPONENT_ATTRIBUTE_VALUE_INVALID', 'effect=aurora-curtain media=background' => 'MARKDOWN_HERO_EFFECT_MEDIA_CONFLICT', ] as $attributes => $code) { try { diff --git a/tests/Unit/PortableSiteHeaderTest.php b/tests/Unit/PortableSiteHeaderTest.php index 75a278e4..411c07d8 100644 --- a/tests/Unit/PortableSiteHeaderTest.php +++ b/tests/Unit/PortableSiteHeaderTest.php @@ -47,4 +47,43 @@ public function a_header_without_added_sections_has_no_actions_slot(): void self::assertStringNotContainsString('sf-site-header-actions', $html); self::assertStringNotContainsString('slot="actions"', $html); } + + #[Test] + public function the_language_picker_is_a_tools_element_of_its_own(): void + { + // Collapsed, sf-header-site 1.11 moves a slotted tools element that + // holds a setting (the language picker) into its panel. Held in one + // element with the search and the reader settings, it took them along + // and left the narrow bar with no tools. + $region = '
Brand
'; + $tools = '
' + . "\n Search" + . "\n " + . "\n \n
"; + + $html = (new PortableSiteHeader)->render($region, null, $tools, '', self::COPY, 'xl'); + $held = substr($html, (int) strpos($html, '')); + + self::assertSame(3, substr_count($held, 'slot="tools" data-sf-held')); + self::assertStringContainsString('
' . "\n Search\n
", $held); + self::assertStringContainsString('', $held); + self::assertStringContainsString('
' . "\n \n
", $held); + // The order stays search, language, settings, in the picture as well. + $picture = substr($html, 0, (int) strpos($html, '')); + self::assertLessThan(strpos($picture, 'render($region, null, $tools, '', self::COPY, 'xl'); + + self::assertSame(1, substr_count($html, 'slot="tools"')); + self::assertStringContainsString('
Search
', $html); + } }