@aitrien/motifspec 1.18.1 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +90 -72
  3. package/dist/backdrop-side.html +1 -0
  4. package/dist/codex.css +236 -2
  5. package/dist/codex.js +176 -1
  6. package/dist/plate.js +4 -4
  7. package/dist/tokens.css +5 -1
  8. package/dist/tokens.js +21 -1
  9. package/dist/tokens.json +21 -1
  10. package/docs/components/_template.md +2 -1
  11. package/docs/components/accession-label.md +2 -1
  12. package/docs/components/backdrop.md +20 -8
  13. package/docs/components/button-and-link.md +2 -2
  14. package/docs/components/callout.md +1 -1
  15. package/docs/components/code-block.md +1 -1
  16. package/docs/components/component-preview.md +68 -0
  17. package/docs/components/data-table.md +2 -2
  18. package/docs/components/disclosure.md +1 -1
  19. package/docs/components/docs-shell.md +126 -0
  20. package/docs/components/figure.md +2 -1
  21. package/docs/components/heading-anchor.md +1 -1
  22. package/docs/components/icon.md +5 -1
  23. package/docs/components/keyboard-key.md +1 -1
  24. package/docs/components/ornament.md +3 -2
  25. package/docs/components/page-actions.md +56 -0
  26. package/docs/components/page-footer.md +67 -0
  27. package/docs/components/pagination.md +2 -1
  28. package/docs/components/post-list-item.md +1 -1
  29. package/docs/components/project-card.md +1 -1
  30. package/docs/components/prose.md +2 -1
  31. package/docs/components/search.md +117 -0
  32. package/docs/components/site-footer.md +3 -3
  33. package/docs/components/site-header.md +22 -1
  34. package/docs/components/specimen-plate.md +2 -2
  35. package/docs/components/status.md +2 -1
  36. package/docs/components/steps.md +70 -0
  37. package/docs/components/table-of-contents.md +1 -1
  38. package/docs/components/tabs.md +81 -0
  39. package/docs/components/tag.md +1 -1
  40. package/docs/components/token-table.md +96 -0
  41. package/docs/components/tooltip.md +1 -1
  42. package/docs/hugo.md +72 -4
  43. package/docs/layouts/a-la-carte.md +1 -0
  44. package/docs/layouts/dashboard.md +2 -0
  45. package/docs/layouts/documentation.md +8 -8
  46. package/docs/layouts/portfolio.md +2 -0
  47. package/docs/syntax-highlighting.md +1 -0
  48. package/layouts/_markup/render-blockquote.html +1 -1
  49. package/layouts/_markup/render-codeblock.html +18 -3
  50. package/layouts/_markup/render-heading.html +1 -1
  51. package/layouts/_markup/render-image.html +5 -4
  52. package/layouts/_markup/render-link.html +1 -1
  53. package/layouts/_markup/render-table.html +3 -2
  54. package/layouts/_partials/motifspec/article.html +13 -8
  55. package/layouts/_partials/motifspec/body-start.html +8 -4
  56. package/layouts/_partials/motifspec/docs-nav.html +31 -0
  57. package/layouts/_partials/motifspec/page-actions.html +8 -0
  58. package/layouts/_partials/motifspec/page-footer.html +27 -0
  59. package/layouts/_partials/motifspec/pagination-docs.html +37 -0
  60. package/layouts/_partials/motifspec/search.html +18 -0
  61. package/layouts/_partials/motifspec/site-header.html +11 -2
  62. package/layouts/_partials/motifspec/table-of-contents.html +1 -1
  63. package/layouts/home.markdown.md +7 -0
  64. package/layouts/page.markdown.md +7 -0
  65. package/layouts/section.markdown.md +7 -0
  66. package/package.json +7 -4
  67. package/scripts/check.mjs +16 -19
  68. package/scripts/lib.mjs +40 -2
  69. package/tokens/color.json +13 -0
@@ -0,0 +1,117 @@
1
+ ---
2
+ name: search
3
+ status: stable
4
+ layouts: [shared]
5
+ tokens:
6
+ - border.focus.offset
7
+ - border.focus.width
8
+ - border.width.hairline
9
+ - color.border.default
10
+ - color.border.strong
11
+ - color.border.subtle
12
+ - color.focus.ring
13
+ - color.scrim
14
+ - color.surface.base
15
+ - color.surface.highlight
16
+ - color.surface.hover
17
+ - color.surface.raised
18
+ - color.text.muted
19
+ - color.text.primary
20
+ - color.text.secondary
21
+ - color.wash.scrim
22
+ - font.family.mono
23
+ - font.line-height.heading
24
+ - font.line-height.ui
25
+ - font.size.body
26
+ - font.size.label
27
+ - font.size.small
28
+ - font.tracking.ui
29
+ - font.weight.strong
30
+ - radius.pill
31
+ - size.column.card
32
+ - size.target.touch
33
+ - space.gutter.page
34
+ - space.inline.sm
35
+ - space.inline.xs
36
+ - space.inset.md
37
+ - space.inset.sm
38
+ - space.inset.xs
39
+ - space.section.sm
40
+ - space.stack.xs
41
+ ---
42
+
43
+ # Search
44
+
45
+ A search control in the header that opens a dialog of results as you type, from an index built with the site.
46
+
47
+ ## When to use
48
+
49
+ - On a documentation site, where readers arrive with a question rather than a page in mind.
50
+ - On any static site with enough pages that the navigation alone is slow to scan.
51
+
52
+ ## When not to use
53
+
54
+ - On a small site; the navigation is quicker.
55
+ - As the only way to reach a page. Every page must also be reachable from the navigation, or from a list of pages, without script.
56
+ - For filtering a list on the page; use a filter (`tag.md`) that changes the list in place.
57
+
58
+ ## Markup
59
+
60
+ The trigger goes first in the header's end (`site-header.md`); the dialog can sit next to it.
61
+
62
+ ```html {preview=true}
63
+ <button class="cx-search-trigger" type="button" data-search-open aria-haspopup="dialog" aria-controls="cx-search" hidden>
64
+ <svg class="cx-icon cx-icon--sm" aria-hidden="true" focusable="false"><use href="#cx-icon-search"></use></svg>
65
+ <span class="cx-search-trigger__label">Search</span>
66
+ <span class="cx-search-trigger__keys" aria-hidden="true"><kbd class="cx-kbd">Ctrl</kbd><kbd class="cx-kbd">K</kbd></span>
67
+ </button>
68
+ <dialog class="cx-search" id="cx-search" aria-labelledby="cx-search-label" data-search="/pagefind/pagefind.js">
69
+ <form class="cx-search__form" role="search" method="dialog">
70
+ <svg class="cx-icon" aria-hidden="true" focusable="false"><use href="#cx-icon-search"></use></svg>
71
+ <label class="cx-visually-hidden" id="cx-search-label" for="cx-search-input">Search the documentation</label>
72
+ <input class="cx-search__input" id="cx-search-input" type="search" autocomplete="off" spellcheck="false" placeholder="Search" aria-describedby="cx-search-status">
73
+ <button class="cx-search__close" type="button" aria-label="Close search" data-search-close><svg class="cx-icon" aria-hidden="true" focusable="false"><use href="#cx-icon-close"></use></svg></button>
74
+ </form>
75
+ <p class="cx-search__status" id="cx-search-status" role="status"></p>
76
+ <ol class="cx-search__results" aria-label="Results"></ol>
77
+ </dialog>
78
+ ```
79
+
80
+ A result, as the script writes it:
81
+
82
+ ```html
83
+ <li><a class="cx-search__result" href="/guide/checking/"><span class="cx-search__title">Checking a site</span><span class="cx-search__excerpt">Run the <mark>checker</mark> before you push…</span></a></li>
84
+ ```
85
+
86
+ `data-search` is the address of Pagefind's script. Pagefind indexes the built site and writes its index and script into it, so search makes no requests to other hosts. In Hugo, set `params.motifspec.search = true` and run Pagefind after the build (`docs/hugo.md`).
87
+
88
+ ## Do
89
+
90
+ - Show the shortcut beside the trigger's label: <kbd class="cx-kbd">Ctrl</kbd> <kbd class="cx-kbd">K</kbd>.
91
+ - Give each result its page title and an excerpt with the matched words marked.
92
+ - Say when there are no results, with the words searched for.
93
+
94
+ ## Don't
95
+
96
+ - Don't ship the trigger visible; search needs script, so it starts `hidden`.
97
+ - Don't style Pagefind's own interface or load its stylesheet; this component is the interface.
98
+ - Don't send queries to a search service; the index is part of the site.
99
+
100
+ ## Accessibility
101
+
102
+ - The trigger is a button with visible text ("Search"); on a phone, the label hides and its name stays in the DOM. The shortcut keys are `aria-hidden`; the shortcut is a convenience, never the only way in.
103
+ - The dialog is a modal `<dialog>`: focus moves into the field when it opens and returns to where it was when it closes; Escape closes it, even from the field; the page behind is inert.
104
+ - The field is labelled by its visually hidden label, which also names the dialog, and described by the status line, a polite live region that says how many results there are.
105
+ - Arrow keys move from the field into the results and between them; Up from the first result returns to the field.
106
+ - Pairs: `color.text.primary` and `color.text.secondary` on `color.surface.raised` and `color.surface.hover` (7:1); `color.text.primary` on `color.surface.highlight` for matched words (7:1); the trigger's boundary `color.border.strong` on `color.surface.base` (3:1).
107
+
108
+ ## Behaviour
109
+
110
+ `dist/codex.js` does all of this; an app that renders search itself does the same.
111
+
112
+ - **Showing the trigger:** every trigger whose `aria-controls` names the dialog is shown.
113
+ - **Opening:** a click on a trigger, Ctrl+K or Cmd+K anywhere, or "/" when focus isn't in a text field. The field's text is selected, and Pagefind's script loads on the first open (`import()` of `data-search`), with `excerptLength: 24`.
114
+ - **Searching:** each input runs `debouncedSearch` (150 ms); the first eight results are shown with their title and excerpt. Only the text and `<mark>` elements of an excerpt are kept. Clearing the field clears the results.
115
+ - **Failing:** if Pagefind's script can't load, the status says "Search isn't available right now." and searching stops.
116
+ - **Closing:** Escape (handled on the dialog, because a search field would otherwise spend the first Escape clearing itself), the close button, or a click on the scrim. Focus returns to the element that had it before opening. Following a result navigates as a link does.
117
+ - **What's indexed:** Pagefind indexes the element with `data-pagefind-body` (the docs shell's `<main>`), skipping anything inside marked `data-pagefind-ignore`; the table of contents, page actions, page footer and pagination are marked.
@@ -48,7 +48,7 @@ The closing band of every page: a knitted ornament band, grouped links, a coloph
48
48
 
49
49
  ## Markup
50
50
 
51
- ```html preview
51
+ ```html {preview=true}
52
52
  <footer class="cx-footer">
53
53
  <span class="cx-band" aria-hidden="true"></span>
54
54
  <div class="cx-container">
@@ -71,7 +71,7 @@ The closing band of every page: a knitted ornament band, grouped links, a coloph
71
71
  <div class="cx-container">
72
72
  <div class="cx-footer__base">
73
73
  <span>© 2026 Liam Marshall</span>
74
- <a class="cx-version" href="https://motifspec.com" aria-label="Version 1.16.0: view the MotifSpec showcase">MotifSpec v1.16.0<svg class="cx-icon cx-icon--sm" aria-hidden="true" focusable="false"><use href="#cx-icon-arrow-outward"></use></svg><span class="cx-tooltip cx-tooltip--above" aria-hidden="true">View showcase</span></a>
74
+ <a class="cx-version" href="https://motifspec.com" aria-label="Version 1.16.0: view the MotifSpec docs">MotifSpec v1.16.0<svg class="cx-icon cx-icon--sm" aria-hidden="true" focusable="false"><use href="#cx-icon-arrow-outward"></use></svg><span class="cx-tooltip cx-tooltip--above" aria-hidden="true">View MotifSpec docs</span></a>
75
75
  <a href="#top">Back to top<svg class="cx-icon cx-icon--sm" aria-hidden="true" focusable="false"><use href="#cx-icon-arrow-upward"></use></svg></a>
76
76
  </div>
77
77
  </div>
@@ -84,7 +84,7 @@ The closing band of every page: a knitted ornament band, grouped links, a coloph
84
84
  - Keep two to four columns; the grid wraps on its own.
85
85
  - Use the footer band as the page's single ornament when the page has no other.
86
86
  - On a backdrop page, let the footer sit on the frost: `cx-backdrop-page` removes its raised surface, and the bottom fade starts above it.
87
- - Put the MotifSpec version in the base row on sites that consume it, as a `cx-version` link to the showcase (`showcase` in `package.json`, also served in `dist/tokens.json`). The showcase's own footer links its version to the changelog instead. Its tooltip opens above (`cx-tooltip--above`) because it sits at the bottom of the page.
87
+ - Put the MotifSpec version in the base row on sites that consume it, as a `cx-version` link to motifspec.com (`showcase` in `package.json`, also served in `dist/tokens.json`). Its tooltip opens above (`cx-tooltip--above`) because it sits at the bottom of the page.
88
88
  - Point "Back to top" at `#top` and give no element that id. With no `#top` element, the browser scrolls to the top of the document; an id on the sticky header would leave the page where it is, because a stuck header is already in view.
89
89
 
90
90
  ## Don't
@@ -58,7 +58,7 @@ The bar at the top of every page: wordmark, primary nav and the theme toggle. On
58
58
 
59
59
  ## Markup
60
60
 
61
- ```html preview
61
+ ```html {preview=true}
62
62
  <a class="cx-skip-link" href="#main">Skip to content</a>
63
63
  <header class="cx-header">
64
64
  <div class="cx-container cx-header__inner">
@@ -81,6 +81,27 @@ The bar at the top of every page: wordmark, primary nav and the theme toggle. On
81
81
  </header>
82
82
  ```
83
83
 
84
+ ### In a documentation site
85
+
86
+ A documentation site's header can also carry search (first, before the nav; `search.md`), a link out to the source repository in the nav, with the outward arrow, and the version before the theme toggle, linking to the changelog:
87
+
88
+ ```html
89
+ <div class="cx-header__end">
90
+ <button class="cx-search-trigger" type="button" data-search-open aria-haspopup="dialog" aria-controls="cx-search" hidden>…</button>
91
+ <nav class="cx-nav" aria-label="Main">
92
+ <ul>
93
+ <li><a href="/guide/" aria-current="page">Guide</a></li>
94
+ <li><a href="/reference/">Reference</a></li>
95
+ <li><a href="https://github.com/owner/repo">GitHub<svg class="cx-icon cx-icon--sm" aria-hidden="true" focusable="false"><use href="#cx-icon-arrow-outward"></use></svg></a></li>
96
+ </ul>
97
+ </nav>
98
+ <a class="cx-header__version" href="/reference/changelog/">v1.19.0<span class="cx-visually-hidden">, changelog</span></a>
99
+ <button class="cx-theme-toggle" type="button" data-theme-toggle hidden aria-label="Switch to dark theme">…</button>
100
+ </div>
101
+ ```
102
+
103
+ A portfolio's header has none of these.
104
+
84
105
  ### Scripts
85
106
 
86
107
  The toggle needs two scripts, both shipped in `dist/`. The first is a one-line snippet (`dist/theme-init.js`) inlined in `<head>` before the stylesheet, so a stored choice is on `<html>` before the first paint and the page never flashes the wrong theme. The second is `dist/codex.js`, loaded with `defer`, which reveals the toggle and wires it up (it also sets the header's scroll state on backdrop pages, and runs copy buttons, tooltip dismissal and the table of contents).
@@ -47,7 +47,7 @@ A contour survey of generated terrain: simplex-noise height lines drawn as a sta
47
47
 
48
48
  ## When not to use
49
49
 
50
- - On a page with the backdrop (`backdrop.md`), which already draws the survey behind it: one kind of contour field per page. The showcase, which documents both, is the only exception.
50
+ - On a page with the backdrop (`backdrop.md`), which already draws the survey behind it: one kind of contour field per page.
51
51
  - On article, index or 404 pages.
52
52
  - As a loading indicator, or as a map of a real place. It is generated, not surveyed.
53
53
  - Without its pause control.
@@ -56,7 +56,7 @@ A contour survey of generated terrain: simplex-noise height lines drawn as a sta
56
56
 
57
57
  The build writes the plate to `dist/plate.html` (the contours at time zero) and ships the script as `dist/plate.js`. In Hugo, inline the markup and load the script; it finds every `.cx-plate[data-plate-seed]` on its own:
58
58
 
59
- ```html preview
59
+ ```html {preview=true}
60
60
  <figure class="cx-plate-frame">
61
61
  <label class="cx-plate__pause" hidden>
62
62
  <input class="cx-visually-hidden" type="checkbox" aria-label="Pause animation">
@@ -36,7 +36,7 @@ A short mono label with a dot that names a state: online, degraded, down, live,
36
36
 
37
37
  ## Markup
38
38
 
39
- ```html preview
39
+ ```html {preview=true}
40
40
  <span class="cx-status cx-status--success">Online</span>
41
41
  <span class="cx-status cx-status--warning">Degraded</span>
42
42
  <span class="cx-status cx-status--danger">Down</span>
@@ -44,6 +44,7 @@ A short mono label with a dot that names a state: online, degraded, down, live,
44
44
  <span class="cx-status cx-status--muted">Scheduled</span>
45
45
  ```
46
46
 
47
+ <!-- caption: Status tones -->
47
48
  | Tone | For | Example words |
48
49
  |---|---|---|
49
50
  | `--success` | Working, passing, done | Online, Running, Passed, Done |
@@ -0,0 +1,70 @@
1
+ ---
2
+ name: steps
3
+ status: stable
4
+ layouts: [shared]
5
+ tokens:
6
+ - border.width.hairline
7
+ - color.border.subtle
8
+ - color.text.accent
9
+ - font.family.mono
10
+ - font.line-height.body
11
+ - font.line-height.heading
12
+ - font.size.body
13
+ - font.size.label
14
+ - font.tracking.ui
15
+ - font.weight.strong
16
+ - size.target.min
17
+ - space.inline.md
18
+ - space.stack.md
19
+ - space.stack.xs
20
+ ---
21
+
22
+ # Steps
23
+
24
+ A numbered procedure: each step a short title and what to do, in order.
25
+
26
+ ## When to use
27
+
28
+ - For a task the reader follows from start to finish: installing, setting up, releasing.
29
+ - When the order matters and the reader needs to keep their place.
30
+
31
+ ## When not to use
32
+
33
+ - For items in no particular order; that is a list.
34
+ - For a single action; write it as a sentence.
35
+ - For more than about eight steps; split the task into stages with headings.
36
+
37
+ ## Markup
38
+
39
+ ```html {preview=true}
40
+ <ol class="cx-steps">
41
+ <li><h3 class="cx-steps__title">Import the module</h3><p>Add it to your site's config.</p></li>
42
+ <li><h3 class="cx-steps__title">Pin a version</h3><p>Run <code>hugo mod get</code> with the version you want.</p></li>
43
+ <li><h3 class="cx-steps__title">Check the site</h3><p>Run the checker before you push.</p></li>
44
+ </ol>
45
+ ```
46
+
47
+ In Markdown, write an ordered list whose items start with a bold lead-in, and put `{.cx-steps}` on the line after it. The site needs Goldmark's block attributes on (`docs/hugo.md`):
48
+
49
+ ```markdown
50
+ 1. **Import the module.** Add it to your site's config.
51
+ 2. **Pin a version.** Run `hugo mod get` with the version you want.
52
+ {.cx-steps}
53
+ ```
54
+
55
+ ## Do
56
+
57
+ - Start each step with what the reader does, as a short imperative title.
58
+ - Keep one action per step; a step with "then" in it is two.
59
+ - Use the heading level that fits the page's outline for HTML titles (`h3` under an `h2`).
60
+
61
+ ## Don't
62
+
63
+ - Don't nest steps inside steps.
64
+ - Don't number steps by hand; the list numbers them.
65
+
66
+ ## Accessibility
67
+
68
+ - It is an `<ol>`, so the count and each step's position are announced.
69
+ - The visible numbers are generated, so they're not read twice.
70
+ - Pairs: `color.text.accent` on `color.surface.base` (4.5:1) for the numbers; `color.text.primary` on `color.surface.base` (7:1).
@@ -48,7 +48,7 @@ A numbered list of an article's sections, beside the text on wide screens and ab
48
48
 
49
49
  ## Markup
50
50
 
51
- ```html preview
51
+ ```html {preview=true}
52
52
  <div class="cx-article">
53
53
  <nav class="cx-toc" aria-labelledby="toc-title">
54
54
  <details open>
@@ -0,0 +1,81 @@
1
+ ---
2
+ name: tabs
3
+ status: stable
4
+ layouts: [shared]
5
+ tokens:
6
+ - border.focus.offset
7
+ - border.focus.width
8
+ - border.width.emphasis
9
+ - border.width.hairline
10
+ - color.accent.border
11
+ - color.border.default
12
+ - color.border.strong
13
+ - color.focus.ring
14
+ - color.text.muted
15
+ - color.text.primary
16
+ - color.text.secondary
17
+ - font.family.mono
18
+ - font.size.label
19
+ - font.size.small
20
+ - font.tracking.label
21
+ - font.weight.strong
22
+ - font.weight.ui
23
+ - size.target.control
24
+ - space.inline.xs
25
+ - space.inset.md
26
+ - space.stack.lg
27
+ - space.stack.sm
28
+ ---
29
+
30
+ # Tabs
31
+
32
+ The same content in two to four forms, such as Hugo and npm, with one shown at a time.
33
+
34
+ ## When to use
35
+
36
+ - When readers need one of several equivalent forms and the rest are noise to them: install commands for different stacks, an example as HTML or JSX.
37
+ - When the forms have the same purpose and similar length.
38
+
39
+ ## When not to use
40
+
41
+ - For content a reader needs more than one of; show it all.
42
+ - For navigation between pages or sections; use links.
43
+ - For more than four forms, or labels longer than a word or two.
44
+
45
+ ## Markup
46
+
47
+ ```html {preview=true}
48
+ <div class="cx-tabs" data-tabs="stack" aria-label="Stack">
49
+ <section class="cx-tabs__panel"><h3 class="cx-tabs__label">Hugo</h3><p>Import the module and call the partials.</p></section>
50
+ <section class="cx-tabs__panel"><h3 class="cx-tabs__label">npm</h3><p>Install the package and copy the markup.</p></section>
51
+ </div>
52
+ ```
53
+
54
+ `data-tabs` names the choice. Every set with the same name on a page changes together, and the choice is remembered for the next page.
55
+
56
+ ## Do
57
+
58
+ - Label each panel with the form's name, short and parallel: "Hugo", "npm".
59
+ - Put the form most readers need first.
60
+ - Give sets of the same choice the same `data-tabs` name, so a reader picks once.
61
+
62
+ ## Don't
63
+
64
+ - Don't hide content that isn't the same thing in another form.
65
+ - Don't nest tabs.
66
+ - Don't write the tab list yourself; the script builds it from the labels.
67
+
68
+ ## Accessibility
69
+
70
+ - Without script, every panel shows under its heading, so nothing is hidden from anyone.
71
+ - With script, it follows the ARIA tabs pattern: a `tablist` named by the set's `aria-label`, each tab with `aria-selected` and `aria-controls`, each panel a `tabpanel` named by its tab and focusable.
72
+ - Left and Right move between tabs (wrapping), Home and End go to the first and last; the selected tab is the only one in the Tab order.
73
+ - The selected tab is marked by weight and the accent rule, not colour alone. Pairs: `color.text.primary` and `color.text.secondary` on `color.surface.base` (7:1); `color.accent.border` (3:1).
74
+
75
+ ## Behaviour
76
+
77
+ `dist/codex.js` does this; an app that renders tabs itself does the same.
78
+
79
+ - **Building:** in each `.cx-tabs` with two or more `.cx-tabs__panel` children, a tab list is inserted before the first panel, with one button per panel, named by its `.cx-tabs__label`. The set gets `is-tabbed`, which hides the labels.
80
+ - **Choosing:** a click, or the arrow keys, Home and End, selects a tab and shows its panel; the others get `hidden`. Selection follows focus.
81
+ - **Keeping in step:** choosing in a set with `data-tabs` selects the same label in every other set with that name, and stores it as `cx-tabs:<name>` in `localStorage`, which the next page reads. Storage that's blocked is ignored.
@@ -44,7 +44,7 @@ A small mono label for a topic or technology, optionally linking to its index.
44
44
 
45
45
  ## Markup
46
46
 
47
- ```html preview
47
+ ```html {preview=true}
48
48
  <ul class="cx-tags">
49
49
  <li><a class="cx-tag" href="/tags/webgl/">webgl<span class="cx-tag__count">4</span></a></li>
50
50
  <li><a class="cx-tag" href="/tags/accessibility/" aria-current="page">accessibility</a></li>
@@ -0,0 +1,96 @@
1
+ ---
2
+ name: token-table
3
+ status: stable
4
+ layouts: [documentation]
5
+ tokens:
6
+ - border.width.hairline
7
+ - color.accent.fill.rest
8
+ - color.border.default
9
+ - color.border.subtle
10
+ - color.surface.base
11
+ - color.surface.sunken
12
+ - color.text.primary
13
+ - font.family.body
14
+ - font.family.mono
15
+ - font.line-height.heading
16
+ - font.line-height.ui
17
+ - font.size.label
18
+ - font.weight.strong
19
+ - size.target.control
20
+ - size.target.min
21
+ - size.target.touch
22
+ - space.inline.sm
23
+ - space.inline.xs
24
+ - space.inset.sm
25
+ - space.inset.xs
26
+ - space.stack.xs
27
+ ---
28
+
29
+ # Token table
30
+
31
+ A token shown as it looks, beside its name, value and rule: colour tiles, a primitive palette, type samples, spacing bars and contrast samples.
32
+
33
+ ## When to use
34
+
35
+ - On the reference pages of a design system's documentation, where a reader compares tokens by eye as well as by name.
36
+ - Inside a data table (`data-table.md`), one sample per row, or as a palette of one hue's steps.
37
+
38
+ ## When not to use
39
+
40
+ - To decorate a page; a swatch stands for a token and is always labelled with its name.
41
+ - For a colour that isn't a token. Show only what the tokens define.
42
+
43
+ ## Markup
44
+
45
+ ```html {preview=true}
46
+ <div class="cx-table cx-token-table" role="region" aria-labelledby="tokens-example" tabindex="0">
47
+ <table>
48
+ <caption id="tokens-example">Text colours</caption>
49
+ <thead><tr><th scope="col">Token</th><th scope="col">Light</th><th scope="col">Dark</th><th scope="col">Rule</th></tr></thead>
50
+ <tbody>
51
+ <tr><th scope="row"><code>color.text.primary</code></th><td><span class="cx-swatch cx-swatch--tile"><b>ash.950</b><span>light value</span></span></td><td><span class="cx-swatch cx-swatch--tile"><b>ash.100</b><span>dark value</span></span></td><td>Body copy, headings and any text a reader must read.</td></tr>
52
+ </tbody>
53
+ </table>
54
+ </div>
55
+ <ol class="cx-palette" aria-label="ash">
56
+ <li><span class="cx-swatch cx-swatch--tile"><b>50</b><span>value</span></span></li>
57
+ <li><span class="cx-swatch cx-swatch--tile"><b>100</b><span>value</span></span></li>
58
+ </ol>
59
+ <span class="cx-pair-sample">Aa</span>
60
+ <span class="cx-token-sample">Type sample</span>
61
+ <span class="cx-token-bar"></span>
62
+ ```
63
+
64
+ <!-- caption: Token table parts -->
65
+ | Class | Shows | Set by the generator |
66
+ |---|---|---|
67
+ | `cx-token-table` | On a data table: keeps each token's name, in the row header, on one line | |
68
+ | `cx-swatch` | A small colour chip | `--_swatch` |
69
+ | `cx-swatch--tile` | A colour tile: the colour as the background, with its name and value written on it | `--_swatch`, and `--_ink` for the text |
70
+ | `cx-palette` | One hue's steps as a grid of tiles, lightest first | Each tile's |
71
+ | `cx-pair-sample` | "Aa" in a foreground on a background, beside the pair's ratio | `--_fg` and `--_bg` |
72
+ | `cx-token-sample` | Text at a size or in a family | `--_size`, `--_family` |
73
+ | `cx-token-bar` | A length, as a bar | `--_width` |
74
+
75
+ The value each part shows comes from a private custom property on the element, set in a `style` attribute by MotifSpec's docs generator (`scripts/docs-reference.mjs`) from `dist/tokens.json`. That's the only place MotifSpec writes a style attribute, and only in generated pages, which the checker doesn't read. Hand-written markup can't set them (the checker fails any `style` attribute), so it shows the neutral fallback, as above.
76
+
77
+ ## Do
78
+
79
+ - Name the token in the same row as its sample, in `<code>`, and write the colour's value on its tile: a reader who can't tell the colours apart reads the value.
80
+ - Write a tile's text in the ink that reads best on it, the darkest or the lightest neutral. The generator measures both and picks the higher contrast; a primitive keeps its value in both themes, so the choice holds in each.
81
+ - Show a semantic colour's light and dark values side by side, so a reader can check both themes in one view.
82
+ - Generate the tables from the tokens, so a changed value shows on the next build.
83
+
84
+ ## Don't
85
+
86
+ - Don't write token tables by hand; they go out of date.
87
+ - Don't show a primitive outside the palette. Pages and components use semantic tokens.
88
+ - Don't let a sample carry meaning the text doesn't.
89
+
90
+ ## Accessibility
91
+
92
+ - Swatches, bars and samples repeat what the text in the same row says; each table has a caption that names it (`data-table.md`).
93
+ - A palette is an ordered list named by its hue (`aria-label`).
94
+ - A tile's text is in whichever of the darkest and lightest neutral contrasts more with the tile. Against black or white, the better of the two is at least 4.5:1 on any colour, so every tile's label meets the label size's target.
95
+ - A pair sample's own contrast is the pair's: it is drawn in the colours it measures, so a failing pair looks like one.
96
+ - Pairs: the text around each sample is `color.text.primary` and `color.text.muted` on `color.surface.raised` (7:1 and 4.5:1); a chip's edge is `color.border.default`.
@@ -38,7 +38,7 @@ A short label that appears beside an icon-only control on hover or keyboard focu
38
38
 
39
39
  The tooltip is a child of the control, so hover and focus on the control reveal it:
40
40
 
41
- ```html preview
41
+ ```html {preview=true}
42
42
  <button class="cx-theme-toggle" type="button" aria-label="Switch to dark theme">
43
43
  <svg class="cx-icon" aria-hidden="true" focusable="false"><use href="#cx-icon-theme-dark"></use></svg>
44
44
  <span class="cx-tooltip" aria-hidden="true">Switch to dark theme</span>
package/docs/hugo.md CHANGED
@@ -41,22 +41,83 @@ Pin a release with `hugo mod get github.com/aitrien/motifspec@vX.Y.Z`. The modul
41
41
  </html>
42
42
  ```
43
43
 
44
+ <!-- caption: Page shell partials -->
44
45
  | Partial | What it writes |
45
46
  |---|---|
46
47
  | `motifspec/head.html` | The stored-theme snippet, font preloads, `codex.css` and `codex.js`, in that order. |
47
- | `motifspec/body-start.html` | Call with the page. On the home page, the head of the backdrop; then the icon sprite and the skip link to `#main`. |
48
- | `motifspec/site-header.html` | `site-header.md`: wordmark from `site.Title` and `site.Params.role`, nav from `site.Menus.main` and the theme toggle. A menu entry is current when its `identifier` is the page's section. |
48
+ | `motifspec/body-start.html` | Call with the page. On the home page, the head of the backdrop (on a documentation site's other pages, the side); then the icon sprite and the skip link to `#main`. |
49
+ | `motifspec/site-header.html` | `site-header.md`: wordmark from `site.Title` and `site.Params.role`, nav from `site.Menus.main` and the theme toggle. A menu entry is current when its `identifier` is the page's section; one whose URL starts with `http` gets the outward arrow. With `params.motifspec.search = true`, search comes first (`search.md`); with `params.motifspec.version` (and `changelog`, a URL), the version comes before the theme toggle. |
49
50
  | `motifspec/body-end.html` | The foot of the backdrop, behind the footer, and `plate.js`, which settles the home page's contours and lets the pointer warm them. |
50
51
 
51
52
  The footer stays in the site: its columns are the site's own links and colophon. Use the markup in `site-footer.md`.
52
53
 
54
+ ### A documentation page
55
+
56
+ A site using the documentation layout (`docs/layouts/documentation.md`) puts the docs shell inside `<main>`'s place, so the page shell above changes to:
57
+
58
+ ```go-html-template
59
+ <body class="cx-backdrop-page cx-backdrop-page--side">
60
+ {{ partial "motifspec/body-start.html" . }}
61
+ {{ partial "motifspec/site-header.html" . }}
62
+ <div class="cx-container cx-docs">
63
+ {{ partial "motifspec/docs-nav.html" . }}
64
+ <main id="main" class="cx-docs__main" tabindex="-1" data-pagefind-body>{{ block "main" . }}{{ end }}</main>
65
+ </div>
66
+ {{/* the site's footer (site-footer.md) */}}
67
+ {{ partial "motifspec/body-end.html" . }}
68
+ </body>
69
+ ```
70
+
71
+ With `params.motifspec.layout = "documentation"`, `body-start.html` writes the side of the backdrop on every page but the home page, and `cx-backdrop-page--side` puts it down the left edge; on a phone the foot shows instead (`backdrop.md`). The home page is the landing page: full width, outside the docs shell, with `<body class="cx-backdrop-page">` and the head of the backdrop, as in the page shell above.
72
+
73
+ An article page's `main` block, in order: the page head with `page-actions.html` after the lede, `article.html`, `page-footer.html`, then `pagination-docs.html`.
74
+
75
+ ### A Markdown copy of each page
76
+
77
+ The module defines a `markdown` output format that writes `index.md` beside each page's `index.html`: the title, the description and the page's Markdown source. Copy page and View as Markdown use it, and so can an AI assistant. A site turns it on for the kinds of page it wants:
78
+
79
+ ```toml {file="hugo.toml"}
80
+ enableGitInfo = true # Lastmod from Git, for "Last updated"
81
+
82
+ [outputs]
83
+ home = ["html", "markdown"]
84
+ page = ["html", "markdown"]
85
+ section = ["html", "markdown"]
86
+
87
+ [params.motifspec]
88
+ layout = "documentation"
89
+ editURL = "https://github.com/owner/repo/edit/main/"
90
+ ```
91
+
92
+ The templates are `layouts/page.markdown.md`, `section.markdown.md` and `home.markdown.md`; a site's own file at the same path wins.
93
+
94
+ ### Steps from Markdown
95
+
96
+ Steps (`steps.md`) come from an ordered list with `{.cx-steps}` on the line after it, which needs Goldmark's block attributes:
97
+
98
+ ```toml {file="hugo.toml"}
99
+ [markup.goldmark.parser.attribute]
100
+ block = true
101
+ ```
102
+
103
+ ### Search
104
+
105
+ Search (`search.md`) reads a Pagefind index of the built site. Turn it on in the header with `params.motifspec.search = true`, and run Pagefind after Hugo, at an exact version, so the index and its script are written into the site:
106
+
107
+ ```sh
108
+ hugo --gc --minify && npx pagefind@1.5.0 --site public
109
+ ```
110
+
111
+ `data-pagefind-body` on the docs shell's `<main>` (above) tells Pagefind to index only the page's own content, so the header, navigation and site footer stay out of the results; the partials mark the table of contents, page actions, page footer and pagination `data-pagefind-ignore`. Pagefind then indexes only pages that have it, so give it to every page that should be found. Search needs script; without it the trigger stays hidden, and the navigation reaches every page.
112
+
53
113
  ## Component partials
54
114
 
55
115
  Every partial below is called as `partial "motifspec/<name>.html" <context>`.
56
116
 
117
+ <!-- caption: Component partials -->
57
118
  | Partial | Doc | Context |
58
119
  |---|---|---|
59
- | `article.html` | `prose.md`, `table-of-contents.md`, `ornament.md` | `dict "page" . "toc" "always"` or `"auto"` (auto shows the TOC at three or more h2s). Ends the prose with the end mark, so the content must end with a paragraph. |
120
+ | `article.html` | `prose.md`, `table-of-contents.md`, `ornament.md` | `dict "page" . "toc" "always"`, `"auto"` (the TOC at three or more h2s) or `"never"` (for a page such as a changelog, whose headings repeat). Ends the prose with the end mark, so the content must end with a paragraph; on a documentation site, no end mark (`docs/layouts/documentation.md`, Decoration). |
60
121
  | `project-card.html` | `project-card.md` | `dict "page" . "level" 2` (the heading level that fits the page outline; default 3). |
61
122
  | `post-list-item.html` | `post-list-item.md` | `dict "page" . "level" 3`. Writes an `<li>`, so put it in `<ol class="cx-posts">`. |
62
123
  | `accession/label.html` | `accession-label.md` | `dict "page" . "variant" "lead"` above the title, or `"card"` after the article (shown on a phone). |
@@ -69,6 +130,11 @@ Every partial below is called as `partial "motifspec/<name>.html" <context>`.
69
130
  | `filed-under.html` | `tag.md`, `docs/layouts/portfolio.md` | A page. "Filed under" and its tags, after an article. |
70
131
  | `pagination-entries.html` | `pagination.md` | `dict "page" . "label" "Post navigation" "noun" "Post"`. Previous and next in the page's section, oldest first. |
71
132
  | `pagination-pages.html` | `pagination.md` | `dict "pager" $pager "label" "Writing pages"`. Pages of a paginated list; nothing when it fits on one page. |
133
+ | `docs-nav.html` | `docs-shell.md` | A page. The documentation layout's navigation: top-level pages, then a group per top-level section in weight order. `docs_nav: false` in front matter leaves a page or section out. |
134
+ | `page-actions.html` | `page-actions.md` | A page. Copy page and View as Markdown, when the page has the markdown output format; nothing otherwise. |
135
+ | `page-footer.html` | `page-footer.md` | A page. Last updated (its `Lastmod`) and Edit this page, from `params.motifspec.editURL` and, for a site in a folder of its repository, `params.motifspec.siteDir`; a page with no file of its own uses its `source` param, the repository path of the file it was made from. |
136
+ | `pagination-docs.html` | `pagination.md`, `page-footer.md` | A page. Previous and next in the order `docs-nav.html` lists the pages. |
137
+ | `search.html` | `search.md` | A page. The search trigger and dialog; `site-header.html` calls it when `params.motifspec.search` is true. |
72
138
  | `back-link.html` | `button-and-link.md` | `dict "href" "…" "label" "All work"`. |
73
139
  | `section-heading.html` | `heading-anchor.md` | `dict "id" "work" "title" "Selected work"`, inside a `<section id="work" aria-labelledby="work-title">`. |
74
140
  | `tokens.html` | | Call with `partialCached "motifspec/tokens.html" "tokens"`. A map from token name to its entry in `dist/tokens.json`, for templates that need a token's value at build time. |
@@ -88,6 +154,7 @@ tags: [react, webgl, a11y]
88
154
  hero: { src: hero.png, alt: "…", caption: "…" }
89
155
  ```
90
156
 
157
+ <!-- caption: Front matter -->
91
158
  | Field | Used by | Notes |
92
159
  |---|---|---|
93
160
  | `summary` | cards, rows | The lede and the card or row summary. |
@@ -102,12 +169,13 @@ hero: { src: hero.png, alt: "…", caption: "…" }
102
169
 
103
170
  These apply to all Markdown content once the module is imported.
104
171
 
172
+ <!-- caption: Render hooks -->
105
173
  | Hook | Markdown | Doc |
106
174
  |---|---|---|
107
175
  | `render-heading.html` | Headings get ids; h2s get a `#` anchor. | `heading-anchor.md` |
108
176
  | `render-image.html` | A standalone image is a numbered figure: `![alt](file.png "caption")`, image in the page bundle, alt and caption required. `{width="prose"}` on the next line keeps it to the text measure. Inline images stay plain. An `.svg` on its own line becomes a diagram figure, inlined so its `cx-diagram` classes follow the theme. | `figure.md` |
109
177
  | `render-table.html` | `{caption="Title \| subtitle"}` on the line after a table is required. Numeric columns align right; more than four columns break out. | `data-table.md` |
110
- | `render-codeblock.html` | Header bar with language, optional `{file="path"}` and copy button. Breaks out when a line is longer than the prose measure. | `code-block.md` |
178
+ | `render-codeblock.html` | Header bar with language, optional `{file="path"}` and copy button. Breaks out when a line is longer than the prose measure. An `html` fence with `{preview=true}` also shows the example live, above its code. | `code-block.md`, `component-preview.md` |
111
179
  | `render-blockquote.html` | `> [!NOTE]`, `[!TIP]`, `[!WARNING]` and `[!CAUTION]` become callouts. A quotation must end with a line `— Name \| Source title`. | `callout.md`, `prose.md` |
112
180
  | `render-link.html` | Internal links are resolved, and a broken one fails the build. External links get the outward arrow. | `icon.md` |
113
181
 
@@ -29,6 +29,7 @@ One `<h1>` per page. Use heading anchors only on headings that start sections of
29
29
 
30
30
  ## Choosing a stack
31
31
 
32
+ <!-- caption: Choosing a stack -->
32
33
  | The project | Use |
33
34
  |---|---|
34
35
  | Already has a stack | Keep it. MotifSpec adapts to the project, not the reverse. |
@@ -17,6 +17,7 @@ Planned: a side navigation column (wordmark, grouped links, the theme toggle and
17
17
 
18
18
  ## Page templates
19
19
 
20
+ <!-- caption: Page templates -->
20
21
  | Template | Order | Dominant | Secondary |
21
22
  |---|---|---|---|
22
23
  | **Overview** | Page head (title, when the readings were last updated, page-wide controls) → alerts as callouts → headline figures → the main column and a side column of sections | Alerts and headline figures | Detail sections |
@@ -51,6 +52,7 @@ MotifSpec doesn't fetch data; where an app gets its readings is the project's de
51
52
 
52
53
  ## Choosing a stack
53
54
 
55
+ <!-- caption: Choosing a stack -->
54
56
  | The project | Use |
55
57
  |---|---|
56
58
  | Already has a stack | Keep it. MotifSpec adapts to the project, not the reverse. |