@aitrien/motifspec 1.17.3 → 1.18.1

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 (56) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +37 -9
  3. package/dist/codex.css +26 -6
  4. package/dist/contrast.md +5 -1
  5. package/dist/icons.svg +13 -0
  6. package/dist/tokens.css +1 -1
  7. package/dist/tokens.js +17 -1
  8. package/dist/tokens.json +17 -1
  9. package/docs/components/_template.md +5 -0
  10. package/docs/components/accession-label.md +5 -1
  11. package/docs/components/backdrop.md +3 -1
  12. package/docs/components/button-and-link.md +10 -1
  13. package/docs/components/callout.md +1 -0
  14. package/docs/components/code-block.md +10 -0
  15. package/docs/components/data-table.md +22 -1
  16. package/docs/components/disclosure.md +73 -0
  17. package/docs/components/figure.md +1 -0
  18. package/docs/components/heading-anchor.md +3 -1
  19. package/docs/components/icon.md +3 -2
  20. package/docs/components/keyboard-key.md +53 -0
  21. package/docs/components/ornament.md +2 -0
  22. package/docs/components/pagination.md +1 -0
  23. package/docs/components/post-list-item.md +1 -0
  24. package/docs/components/project-card.md +1 -0
  25. package/docs/components/prose.md +1 -0
  26. package/docs/components/site-footer.md +1 -0
  27. package/docs/components/site-header.md +10 -0
  28. package/docs/components/specimen-plate.md +1 -0
  29. package/docs/components/status.md +74 -0
  30. package/docs/components/table-of-contents.md +9 -0
  31. package/docs/components/tag.md +2 -1
  32. package/docs/components/tooltip.md +6 -0
  33. package/docs/hugo.md +2 -2
  34. package/docs/layouts/a-la-carte.md +36 -0
  35. package/docs/layouts/dashboard.md +58 -0
  36. package/docs/layouts/documentation.md +48 -0
  37. package/docs/{templates.md → layouts/portfolio.md} +34 -2
  38. package/icons/manifest.json +52 -0
  39. package/icons/svg/apps.svg +1 -0
  40. package/icons/svg/close.svg +1 -0
  41. package/icons/svg/dashboard.svg +1 -0
  42. package/icons/svg/dns.svg +1 -0
  43. package/icons/svg/edit.svg +1 -0
  44. package/icons/svg/lan.svg +1 -0
  45. package/icons/svg/menu.svg +1 -0
  46. package/icons/svg/notifications.svg +1 -0
  47. package/icons/svg/restart_alt.svg +1 -0
  48. package/icons/svg/search.svg +1 -0
  49. package/icons/svg/settings.svg +1 -0
  50. package/icons/svg/storage.svg +1 -0
  51. package/icons/svg/terminal.svg +1 -0
  52. package/layouts/_partials/motifspec/filed-under.html +1 -1
  53. package/package.json +1 -1
  54. package/scripts/check.mjs +208 -23
  55. package/scripts/lib.mjs +64 -0
  56. package/tokens/color.json +16 -0
@@ -70,6 +70,58 @@
70
70
  "play": {
71
71
  "symbol": "play_arrow",
72
72
  "use": "Resume control for ambient motion while it is paused."
73
+ },
74
+ "search": {
75
+ "symbol": "search",
76
+ "use": "The search field and the control that opens search."
77
+ },
78
+ "menu": {
79
+ "symbol": "menu",
80
+ "use": "The Menu control that opens the navigation on a phone, in the dashboard and documentation layouts."
81
+ },
82
+ "close": {
83
+ "symbol": "close",
84
+ "use": "Closing a dialog, the search panel or an opened menu."
85
+ },
86
+ "edit": {
87
+ "symbol": "edit",
88
+ "use": "\"Edit this page\" links in the documentation layout, and edit actions in a dashboard."
89
+ },
90
+ "dashboard": {
91
+ "symbol": "dashboard",
92
+ "use": "Before the overview item in a dashboard's side navigation."
93
+ },
94
+ "notifications": {
95
+ "symbol": "notifications",
96
+ "use": "Before alerts in a dashboard's side navigation."
97
+ },
98
+ "dns": {
99
+ "symbol": "dns",
100
+ "use": "Before servers, nodes and hosts in a dashboard's side navigation."
101
+ },
102
+ "storage": {
103
+ "symbol": "storage",
104
+ "use": "Before storage, pools and disks in a dashboard's side navigation."
105
+ },
106
+ "lan": {
107
+ "symbol": "lan",
108
+ "use": "Before networks in a dashboard's side navigation."
109
+ },
110
+ "apps": {
111
+ "symbol": "apps",
112
+ "use": "Before applications and services in a dashboard's side navigation."
113
+ },
114
+ "settings": {
115
+ "symbol": "settings",
116
+ "use": "Before settings in a side navigation, and settings controls in a toolbar."
117
+ },
118
+ "restart": {
119
+ "symbol": "restart_alt",
120
+ "use": "Restart actions, such as restarting a service."
121
+ },
122
+ "logs": {
123
+ "symbol": "terminal",
124
+ "use": "Logs and consoles: a link or action that opens them."
73
125
  }
74
126
  }
75
127
  }
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M191.12-191.12q-15.73-15.73-15.73-38.73 0-23 15.73-38.73 15.73-15.73 38.73-15.73 23 0 38.73 15.73 15.73 15.73 15.73 38.73 0 23-15.73 38.73-15.73 15.73-38.73 15.73-23 0-38.73-15.73Zm250.15 0q-15.73-15.73-15.73-38.73 0-23 15.73-38.73Q457-284.31 480-284.31q23 0 38.73 15.73 15.73 15.73 15.73 38.73 0 23-15.73 38.73Q503-175.39 480-175.39q-23 0-38.73-15.73Zm250.15 0q-15.73-15.73-15.73-38.73 0-23 15.73-38.73 15.73-15.73 38.73-15.73 23 0 38.73 15.73 15.73 15.73 15.73 38.73 0 23-15.73 38.73-15.73 15.73-38.73 15.73-23 0-38.73-15.73Zm-500.3-250.15Q175.39-457 175.39-480q0-23 15.73-38.73 15.73-15.73 38.73-15.73 23 0 38.73 15.73Q284.31-503 284.31-480q0 23-15.73 38.73-15.73 15.73-38.73 15.73-23 0-38.73-15.73Zm250.15 0Q425.54-457 425.54-480q0-23 15.73-38.73Q457-534.46 480-534.46q23 0 38.73 15.73Q534.46-503 534.46-480q0 23-15.73 38.73Q503-425.54 480-425.54q-23 0-38.73-15.73Zm250.15 0Q675.69-457 675.69-480q0-23 15.73-38.73 15.73-15.73 38.73-15.73 23 0 38.73 15.73Q784.61-503 784.61-480q0 23-15.73 38.73-15.73 15.73-38.73 15.73-23 0-38.73-15.73Zm-500.3-250.15q-15.73-15.73-15.73-38.73 0-23 15.73-38.73 15.73-15.73 38.73-15.73 23 0 38.73 15.73 15.73 15.73 15.73 38.73 0 23-15.73 38.73-15.73 15.73-38.73 15.73-23 0-38.73-15.73Zm250.15 0q-15.73-15.73-15.73-38.73 0-23 15.73-38.73Q457-784.61 480-784.61q23 0 38.73 15.73 15.73 15.73 15.73 38.73 0 23-15.73 38.73Q503-675.69 480-675.69q-23 0-38.73-15.73Zm250.15 0q-15.73-15.73-15.73-38.73 0-23 15.73-38.73 15.73-15.73 38.73-15.73 23 0 38.73 15.73 15.73 15.73 15.73 38.73 0 23-15.73 38.73-15.73 15.73-38.73 15.73-23 0-38.73-15.73Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="m250.92-218.92-32-32L448-480 218.92-709.08l32-32L480-512l229.08-229.08 32 32L512-480l229.08 229.08-32 32L480-448 250.92-218.92Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M522.69-578.08V-820H820v241.92H522.69ZM140-467.31V-820h297.31v352.69H140ZM522.69-140v-352.69H820V-140H522.69ZM140-140v-241.92h297.31V-140H140Zm45.39-372.69h206.53v-261.92H185.39v261.92Zm382.69 327.3h206.53v-261.92H568.08v261.92Zm0-438.07h206.53v-151.15H568.08v151.15ZM185.39-185.39h206.53v-151.15H185.39v151.15Zm206.53-327.3Zm176.16-110.77Zm0 176.15ZM391.92-336.54Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M290.37-695.46q-17.83 0-30.22 12.48-12.38 12.48-12.38 30.31 0 17.82 12.48 30.21 12.48 12.38 30.31 12.38 17.82 0 30.21-12.48 12.38-12.48 12.38-30.3 0-17.83-12.48-30.22-12.48-12.38-30.3-12.38Zm0 385.54q-17.83 0-30.22 12.48-12.38 12.48-12.38 30.3 0 17.83 12.48 30.22 12.48 12.38 30.31 12.38 17.82 0 30.21-12.48 12.38-12.48 12.38-30.31 0-17.82-12.48-30.21-12.48-12.38-30.3-12.38ZM140-497.85v-309.22h680v309.22H140Zm45.39-263.84v218.46h589.22v-218.46H185.39ZM140-112.31v-309.84h680v309.84H140Zm45.39-264.46v219.08h589.22v-219.08H185.39Zm0-384.92v218.46-218.46Zm0 384.92v219.08-219.08Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M185.39-185.39h40.92l468.54-467.92-40.93-40.92-468.53 467.92v40.92ZM140-140v-104.54l593.54-593.69 105.69 105.31L244.54-140H140Zm634-593.92L734.54-773 774-733.92Zm-99.37 60.29-20.71-20.6 40.93 40.92-20.22-20.32Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M130-90v-252.69h120v-160h207.31v-114.62h-120V-870h285.38v252.69h-120v114.62H710v160h120V-90H544.62v-252.69h120v-114.62H295.38v114.62h120V-90H130Zm252.69-572.69h194.62v-161.93H382.69v161.93ZM175.38-135.38H370v-161.93H175.38v161.93Zm414.62 0h194.62v-161.93H590v161.93ZM480-662.69ZM370-297.31Zm220 0Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M140-254.62V-300h680v45.38H140Zm0-202.69v-45.38h680v45.38H140ZM140-660v-45.38h680V-660H140Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M180-204.62V-250h72.31v-315.92q0-81.31 49.31-144.93 49.3-63.61 128.38-78.69V-860h100v70.46q79.08 15.08 128.38 78.69 49.31 63.62 49.31 144.93V-250H780v45.38H180Zm300-294.69Zm-.07 407q-29.85 0-51.04-21.24-21.2-21.24-21.2-51.07h144.62q0 29.93-21.26 51.12-21.26 21.19-51.12 21.19ZM297.69-250h364.62v-315.92q0-75.77-53.27-129.04-53.27-53.27-129.04-53.27-75.77 0-129.04 53.27-53.27 53.27-53.27 129.04V-250Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M447.92-142.77q-113.77-11.15-190.84-96Q180-323.62 180-439.38q0-68.93 31.08-130.2 31.07-61.26 86.23-102.34l32.23 32.61q-49.85 33-77 86.46-27.15 53.47-27.15 113.47 0 96.92 63.49 167.99 63.5 71.08 159.04 83.24v45.38Zm65.39.77v-45.39q96.15-14.3 159.04-84.88 62.88-70.58 62.88-167.11 0-106.7-73.96-180.66T480.62-694h-26.54l65.77 65.77-32.62 32.61-121.07-121.07 121.07-121.08 32.62 32.62-65.77 65.77h26.54q125.53 0 212.76 87.73 87.23 87.73 87.23 212.27 0 115.76-76.76 200.42-76.77 84.65-190.54 96.96Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M790.61-137.54 531.08-397.08q-29.85 26.42-69.65 40.71-39.81 14.29-82.28 14.29-101.62 0-172.31-70.57-70.68-70.58-70.68-171 0-100.43 70.57-171 70.58-70.58 171.72-70.58 100.14 0 170.69 70.58 70.55 70.57 70.55 170.86 0 42.17-14.38 81.98-14.39 39.81-41.62 72.12l260.15 258.54-33.23 33.61ZM378.54-387.46q81.7 0 138.74-57.12 57.03-57.11 57.03-139.07 0-81.97-57.03-139.08-57.04-57.12-138.74-57.12-82.39 0-139.69 57.12-57.31 57.11-57.31 139.08 0 81.96 57.31 139.07 57.3 57.12 139.69 57.12Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="m400.69-100-18.07-120.23q-20.54-7-44.23-20.35-23.7-13.34-40.85-28.27l-111.85 50.93-79.92-141.31 101.08-74.38q-2-10.54-2.89-23.01-.88-12.46-.88-23 0-10.15.88-22.61.89-12.46 2.89-24.16l-101.08-74.76 79.92-140.16 111.46 50.16q18.31-14.93 41.24-28.08 22.92-13.15 43.84-19.54L400.69-860h158.62l18.07 120.62q22.08 8.15 44.16 20.23 22.07 12.07 39.77 28l113.38-50.16 79.54 140.16-102.62 74.3q2.77 11.93 3.47 24 .69 12.08.69 22.85 0 10.38-.89 22.15-.88 11.77-3.27 24.47l102.23 74.15-79.92 141.31-112.61-51.31q-18.7 15.69-40.35 28.96-21.65 13.27-43.58 19.65L559.31-100H400.69Zm36.46-45.39h85.31L536.85-257q31.84-8 59.42-23.85 27.58-15.84 52.73-40.23l104.46 45.23 40-70.84L701-414.92q4-17.77 6.31-33.5 2.3-15.73 2.3-31.58 0-16.62-2-31.96-2-15.35-6.61-32.35l93.23-69-40-70.84-105.62 45.23q-21.07-23.69-50.84-41.77Q568-698.77 536.46-703l-13.61-111.61h-85.7l-13.23 111.23q-33.23 6.61-61.19 22.65t-52.11 41.42l-104.85-44.84-40 70.84 92.46 67.85q-4.38 15.84-6.69 32.15-2.31 16.31-2.31 33.69 0 16.62 2.31 32.54 2.31 15.93 6.31 32.16l-92.08 68.23 40 70.84 104.46-44.84q24 24.38 52.15 40.23 28.16 15.84 61.16 23.84l13.61 111.23Zm41.7-221.92q47.07 0 79.88-32.81 32.81-32.8 32.81-79.88t-32.81-79.88q-32.81-32.81-79.88-32.81-46.7 0-79.7 32.81-32.99 32.8-32.99 79.88t32.99 79.88q33 32.81 79.7 32.81ZM480-480Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M134.62-168.46v-134.15h690.76v134.15H134.62Zm56.15-33.77h66.62v-66.62h-66.62v66.62Zm-56.15-455.16v-134.15h690.76v134.15H134.62Zm56.15-33.76h66.62v-66.62h-66.62v66.62Zm-56.15 278.23v-134.16h690.76v134.16H134.62Zm56.15-33.77h66.62v-66.62h-66.62v66.62Z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 -960 960 960"><path d="M100-180v-600h760v600H100Zm45.39-45.39h669.22v-426.38H145.39v426.38ZM300-303.15l-31.61-31.23 103-104-104-104L300-574l135.61 135.62L300-303.15Zm197.31 7.46v-45.39h205.38v45.39H497.31Z"/></svg>
@@ -1,4 +1,4 @@
1
- {{- /* The "Filed under" tags after an article (docs/templates.md, tag.md). Context: a page. */ -}}
1
+ {{- /* The "Filed under" tags after an article (docs/layouts/portfolio.md, tag.md). Context: a page. */ -}}
2
2
  <div class="cx-stack">
3
3
  <p class="cx-eyebrow">Filed under</p>
4
4
  {{ partial "motifspec/tags.html" (dict "page" . "max" 5) }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aitrien/motifspec",
3
- "version": "1.17.3",
3
+ "version": "1.18.1",
4
4
  "description": "Liam Marshall's design system: DTCG tokens, component rules, generated CSS, Hugo templates and a rule checker.",
5
5
  "keywords": [
6
6
  "design-system",
package/scripts/check.mjs CHANGED
@@ -5,6 +5,12 @@
5
5
  // node scripts/check.mjs [project-root] check a consuming project's layouts/ and content/
6
6
  // node scripts/check.mjs [project-root] --dirs src,app check other folders instead (a non-Hugo project)
7
7
  // node scripts/check.mjs [project-root] --json print the problems as JSON
8
+ // node scripts/check.mjs [project-root] --layout dashboard check against a layout (docs/layouts/)
9
+ // node scripts/check.mjs [project-root] --layout a-la-carte --components table-of-contents,heading-anchor
10
+ //
11
+ // Without --layout, a Hugo site's layout comes from [params.motifspec] in its config (hugo.toml, hugo.yaml,
12
+ // hugo.json, config.*, or config/_default/), and a project that declares nothing is checked as portfolio.
13
+ // A component used outside its layouts is a warning in this release, not a failure.
8
14
  // npx motifspec-check [same options] the same, from the npm package
9
15
  //
10
16
  // Rules come from the files of this release: class names from dist/codex.css, tokens from dist/tokens.json, icons
@@ -25,7 +31,16 @@ export const RULES = {
25
31
  'unknown-class': 'Not a MotifSpec class. Copy the markup from docs/components/*.md; don\'t invent cx- classes.',
26
32
  'unknown-icon': 'Not an approved icon. Use a key from icons/manifest.json, for its listed role.',
27
33
  separator: 'Separate inline metadata with <span class="cx-sep" aria-hidden="true">|</span>, never "·".',
34
+ 'wrong-layout': 'This component belongs to another layout. Use a component of this layout, or declare à la carte and list it (docs/layouts/a-la-carte.md).',
35
+ 'unlisted-component': 'An à la carte project uses only shared components and the ones it lists. Add this one to the list if you mean to use it.',
36
+ 'cx-override': 'Project CSS can\'t target or define cx- classes: MotifSpec\'s components aren\'t restyled, and the project\'s own classes don\'t start with cx-.',
37
+ 'unknown-layout': 'Not a MotifSpec layout. Use portfolio, dashboard, documentation or a-la-carte (docs/layouts/).',
38
+ 'unknown-component': 'Not a MotifSpec component. Use a doc name from docs/components/, without .md.',
28
39
  };
40
+ // Problems that warn rather than fail. Using a component outside its layouts fails from a later release.
41
+ export const WARNINGS = new Set(['wrong-layout', 'unlisted-component']);
42
+ // One file each in docs/layouts/. Fixed here rather than read from the folder, because the MCP tools' schemas list them.
43
+ export const LAYOUTS = ['portfolio', 'dashboard', 'documentation', 'a-la-carte'];
29
44
 
30
45
  const read = (...p) => readFileSync(join(ROOT, ...p), 'utf8');
31
46
  let data;
@@ -42,10 +57,68 @@ function load() {
42
57
  icons: new Set(Object.keys(JSON.parse(read('icons', 'manifest.json')).icons)),
43
58
  tokens: new Map(tokens.map((t) => [t.css, t])),
44
59
  breakpoints: new Set(Object.entries(sizes.primitive.size.breakpoint).filter(([k]) => !k.startsWith('$')).map(([, t]) => `${t.$value.value}${t.$value.unit}`)),
60
+ ...componentLayouts(),
45
61
  };
46
62
  return data;
47
63
  }
48
64
 
65
+ /**
66
+ * Which layouts each class and Hugo partial belongs to, from the component docs: a doc's layouts (its front matter)
67
+ * apply to every cx- class in its HTML examples, and to the partials docs/hugo.md lists for it. A class in any shared
68
+ * doc is shared; a partial is restricted by every doc its row names.
69
+ */
70
+ function componentLayouts() {
71
+ const dir = join(ROOT, 'docs', 'components');
72
+ const docs = new Map(); // doc name -> layouts, or null when shared
73
+ const classDocs = new Map(); // class -> doc names that use it
74
+ for (const f of readdirSync(dir).filter((x) => x.endsWith('.md') && !x.startsWith('_'))) {
75
+ const md = readFileSync(join(dir, f), 'utf8');
76
+ const name = f.replace(/\.md$/, '');
77
+ const layouts = md.match(/^layouts: \[(.*)\]/m)?.[1].split(',').map((l) => l.trim()) ?? ['shared'];
78
+ docs.set(name, layouts.includes('shared') ? null : layouts);
79
+ for (const block of md.matchAll(/```html[^\n]*\n([\s\S]*?)```/g)) {
80
+ for (const m of block[1].matchAll(CLASS_ATTR)) {
81
+ for (const c of m[1].split(/\s+/)) if (c.startsWith('cx-')) classDocs.set(c, new Set([...(classDocs.get(c) ?? []), name]));
82
+ }
83
+ }
84
+ }
85
+ const restrictedClasses = new Map(); // class -> restricted doc names (only classes no shared doc uses)
86
+ for (const [c, names] of classDocs) if ([...names].every((n) => docs.get(n))) restrictedClasses.set(c, [...names]);
87
+ const partials = new Map(); // partial file -> restricted doc names it renders
88
+ for (const row of read('docs', 'hugo.md').split('\n').filter((l) => /^\| `[a-z0-9/_-]+\.html` \|/.test(l))) {
89
+ const [file, related] = row.split('|').slice(1, 3).map((c) => c.trim());
90
+ const names = [...related.matchAll(/`([a-z0-9-]+)\.md`/g)].map((m) => m[1]).filter((n) => docs.get(n));
91
+ if (names.length) partials.set(file.replace(/`/g, ''), names);
92
+ }
93
+ return { docs, restrictedClasses, partials };
94
+ }
95
+
96
+ /** A problem for using restricted docs `names` (all of which `thing` needs) under a layout, or null if allowed. */
97
+ function layoutProblem(thing, names, { layout, components }) {
98
+ const { docs } = load();
99
+ if (layout === 'a-la-carte') {
100
+ const missing = names.filter((n) => !components?.includes(n));
101
+ // A class from several docs is fine if any of them is listed; a partial needs every doc it renders.
102
+ if (thing.startsWith('cx-') ? missing.length < names.length : !missing.length) return null;
103
+ return ['unlisted-component', `${thing} (${missing.map((n) => `${n}.md`).join(', ')})`];
104
+ }
105
+ const allowed = thing.startsWith('cx-') ? names.some((n) => docs.get(n).includes(layout)) : names.every((n) => docs.get(n).includes(layout));
106
+ if (allowed) return null;
107
+ const from = names.map((n) => `${n}.md: ${docs.get(n).join(', ')}`).join('; ');
108
+ return ['wrong-layout', `${thing} (${from}; this project is ${layout})`];
109
+ }
110
+
111
+ // Selectors in CSS (the text before each "{" that opens a rule), with the line each starts on.
112
+ function* selectors(css) {
113
+ let start = 0;
114
+ const text = css.replace(/\/\*[\s\S]*?\*\//g, (c) => c.replace(/[^\n]/g, ' '));
115
+ for (let i = 0; i < text.length; i++) {
116
+ const ch = text[i];
117
+ if (ch === '{') { yield [text.slice(start, i), text.slice(0, start).split('\n').length]; start = i + 1; }
118
+ else if (ch === '}' || ch === ';') start = i + 1;
119
+ }
120
+ }
121
+
49
122
  // A hex colour that isn't part of a fragment link such as href="#cx-icon-add" or an HTML entity.
50
123
  const RAW_COLOR = /(?<![\w&/."-])#(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3,4})(?![\w-])|\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\(/g;
51
124
  // A number with a length or time unit. Zero is allowed (0px is not a size).
@@ -58,12 +131,18 @@ const TEMPLATE = /\{\{.*?\}\}/g; // Hugo actions; replaced by a placeholder so a
58
131
 
59
132
  /**
60
133
  * Check one file's text. kind: "html" (templates and markup), "md" (content) or "css".
61
- * Returns [{ file, line, rule, match, message }].
134
+ * layout (optional): check that components belong to it; components: the doc names an à la carte project lists.
135
+ * projectCss: the text is a project's own stylesheet (à la carte), so it may not target or define cx- classes.
136
+ * Returns [{ file, line, rule, match, message, severity }], severity "error" or "warning".
62
137
  */
63
- export function checkText(text, { file = '<input>', kind = 'html' } = {}) {
64
- const { classes, icons, tokens, breakpoints } = load();
138
+ export function checkText(text, { file = '<input>', kind = 'html', layout, components, projectCss = false } = {}) {
139
+ const { classes, icons, tokens, breakpoints, restrictedClasses, partials } = load();
65
140
  const problems = [];
66
- const add = (line, rule, match) => problems.push({ file, line, rule, match, message: RULES[rule] });
141
+ const add = (line, rule, match) => problems.push({ file, line, rule, match, message: RULES[rule], severity: WARNINGS.has(rule) ? 'warning' : 'error' });
142
+ const declared = { layout, components };
143
+ if (kind === 'css' && projectCss) {
144
+ for (const [sel, n] of selectors(text)) for (const m of sel.matchAll(/\.cx-[a-z0-9_-]+/g)) add(n + sel.slice(0, m.index).split('\n').length - 1, 'cx-override', m[0]);
145
+ }
67
146
  text.split('\n').forEach((raw, i) => {
68
147
  const n = i + 1;
69
148
  // In CSS, a breakpoint value in an @media condition is the build's own output and allowed.
@@ -80,7 +159,21 @@ export function checkText(text, { file = '<input>', kind = 'html' } = {}) {
80
159
  if (line.includes('·')) add(n, 'separator', '·');
81
160
  const plain = line.replace(TEMPLATE, '§');
82
161
  for (const m of plain.matchAll(CLASS_ATTR)) {
83
- for (const c of m[1].split(/\s+/)) if (c.startsWith('cx-') && !c.includes('§') && !classes.has(c)) add(n, 'unknown-class', c);
162
+ for (const c of m[1].split(/\s+/)) {
163
+ if (!c.startsWith('cx-') || c.includes('§')) continue;
164
+ if (!classes.has(c)) add(n, 'unknown-class', c);
165
+ else if (layout && restrictedClasses.has(c)) {
166
+ const p = layoutProblem(c, restrictedClasses.get(c), declared);
167
+ if (p) add(n, ...p);
168
+ }
169
+ }
170
+ }
171
+ if (layout) {
172
+ for (const m of line.matchAll(/partial(?:Cached)?\s+"motifspec\/([a-z0-9/_-]+\.html)"/g)) {
173
+ if (!partials.has(m[1])) continue;
174
+ const p = layoutProblem(`motifspec/${m[1]}`, partials.get(m[1]), declared);
175
+ if (p) add(n, ...p);
176
+ }
84
177
  }
85
178
  for (const m of plain.matchAll(ICON_REF)) {
86
179
  if (m[1] && plain[m.index + m[0].length] !== '§' && !icons.has(m[1])) add(n, 'unknown-icon', `cx-icon-${m[1]}`);
@@ -104,20 +197,102 @@ function* walk(dir) {
104
197
  }
105
198
  }
106
199
 
107
- /** Check a project that uses MotifSpec: no stylesheets anywhere, and every file in `dirs` checked by checkText. */
108
- export function checkProject(root, { dirs = ['layouts', 'content'] } = {}) {
200
+ /**
201
+ * A Hugo site's [params.motifspec] (layout, components) from its config, or {} when it declares nothing.
202
+ * Reads hugo/config .toml, .yaml, .yml or .json at the root, and config/_default/ (hugo, config or params files).
203
+ */
204
+ export function declaredLayout(root) {
205
+ const files = ['hugo', 'config'].flatMap((n) => ['toml', 'yaml', 'yml', 'json'].map((e) => [`${n}.${e}`, false]))
206
+ .concat(['hugo', 'config', 'params'].flatMap((n) => ['toml', 'yaml', 'yml', 'json'].map((e) => [join('config', '_default', `${n}.${e}`), n === 'params'])));
207
+ const list = (v) => v?.split(',').map((x) => x.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
208
+ for (const [f, isParams] of files) {
209
+ const path = join(root, f);
210
+ if (!existsSync(path)) continue;
211
+ const text = readFileSync(path, 'utf8');
212
+ let found;
213
+ if (f.endsWith('.json')) {
214
+ const json = JSON.parse(text);
215
+ found = (isParams ? json : json.params)?.motifspec;
216
+ } else if (f.endsWith('.toml')) {
217
+ found = tomlMotifspec(text, isParams ? '' : 'params');
218
+ } else {
219
+ const block = text.match(isParams ? /^motifspec:\s*\n((?:[ \t]+.*\n?)*)/m : /^[ \t]+motifspec:\s*\n((?:[ \t]+.*\n?)*)/m)?.[1];
220
+ if (block) {
221
+ const inline = block.match(/^\s*components:\s*\[(.*)\]/m)?.[1];
222
+ const dashed = block.match(/^\s*components:\s*\n((?:\s*-\s*.+\n?)*)/m)?.[1]?.match(/-\s*(.+)/g)?.map((x) => x.replace(/^-\s*/, ''));
223
+ found = { layout: block.match(/^\s*layout:\s*["']?([a-z-]+)/m)?.[1], components: inline ? list(inline) : list(dashed?.join(',')) };
224
+ }
225
+ }
226
+ if (found?.layout || found?.components) return { layout: found.layout, components: found.components, from: f };
227
+ }
228
+ return {};
229
+ }
230
+
231
+ /**
232
+ * [params.motifspec] from Hugo TOML, however it's written: as its own table (indented or not), as dotted keys
233
+ * (motifspec.layout = "…" under [params], or params.motifspec.layout at the top), or as an inline table
234
+ * (motifspec = { layout = "…" }). `parent` is "params" for a site config, "" for a params file.
235
+ */
236
+ function tomlMotifspec(text, parent) {
237
+ const sections = new Map([['', '']]);
238
+ let current = '';
239
+ for (const line of text.split('\n')) {
240
+ const header = line.match(/^\s*\[\s*([^\[\]]+?)\s*\]\s*(?:#.*)?$/);
241
+ if (header) { current = header[1]; sections.set(current, sections.get(current) ?? ''); continue; }
242
+ sections.set(current, sections.get(current) + line + '\n');
243
+ }
244
+ const own = parent ? `${parent}.motifspec` : 'motifspec';
245
+ const value = (body, key) => body.match(new RegExp(`^\\s*${key.replace(/\./g, '\\.')}\\s*=\\s*["']([^"']+)["']`, 'm'))?.[1];
246
+ const array = (body, key) => body.match(new RegExp(`^\\s*${key.replace(/\./g, '\\.')}\\s*=\\s*\\[([\\s\\S]*?)\\]`, 'm'))?.[1];
247
+ const list = (v) => v?.split(',').map((x) => x.replace(/#.*$/gm, '').trim().replace(/^["']|["']$/g, '')).filter(Boolean);
248
+ // Its own table.
249
+ if (sections.has(own)) {
250
+ const body = sections.get(own);
251
+ return { layout: value(body, 'layout'), components: list(array(body, 'components')) };
252
+ }
253
+ // Dotted keys or an inline table, in the parent table or (for a site config) at the top level.
254
+ for (const [section, prefix] of [[parent, 'motifspec.'], ...(parent ? [['', `${parent}.motifspec.`]] : [])]) {
255
+ const body = sections.get(section);
256
+ if (!body) continue;
257
+ const inline = body.match(new RegExp(`^\\s*${prefix.replace(/\./g, '\\.').replace(/\\\.$/, '')}\\s*=\\s*\\{([\\s\\S]*?)\\}`, 'm'))?.[1];
258
+ if (inline) {
259
+ const lines = inline.replace(/,\s*(?=[a-z]+\s*=)/g, '\n');
260
+ return { layout: value(lines, 'layout'), components: list(array(lines, 'components')) };
261
+ }
262
+ const layout = value(body, `${prefix}layout`);
263
+ const components = list(array(body, `${prefix}components`));
264
+ if (layout || components) return { layout, components };
265
+ }
266
+ return undefined;
267
+ }
268
+
269
+ /**
270
+ * Check a project that uses MotifSpec: no stylesheets anywhere (except an à la carte project's own, held to tokens),
271
+ * and every file in `dirs` checked by checkText against the project's layout.
272
+ */
273
+ export function checkProject(root, { dirs = ['layouts', 'content'], layout, components } = {}) {
109
274
  const problems = [];
275
+ const declared = declaredLayout(root);
276
+ const fromConfig = (v) => (v === undefined ? declared.from : undefined);
277
+ const layoutFrom = fromConfig(layout) ?? '<options>';
278
+ const componentsFrom = fromConfig(components) ?? '<options>';
279
+ layout ??= declared.layout ?? 'portfolio';
280
+ components ??= declared.components;
281
+ const add = (file, rule, match) => problems.push({ file, line: 0, rule, match, message: RULES[rule], severity: WARNINGS.has(rule) ? 'warning' : 'error' });
282
+ if (!LAYOUTS.includes(layout)) { add(layoutFrom, 'unknown-layout', layout); return problems; }
283
+ const { docs } = load();
284
+ for (const c of components ?? []) if (!docs.has(c)) add(componentsFrom, 'unknown-component', c);
110
285
  for (const file of walk(root)) {
111
- if (['.css', '.scss', '.sass', '.less'].includes(extname(file))) {
112
- problems.push({ file: relative(root, file), line: 0, rule: 'stylesheet', match: extname(file), message: RULES.stylesheet });
113
- }
286
+ if (!['.css', '.scss', '.sass', '.less'].includes(extname(file))) continue;
287
+ if (layout === 'a-la-carte') problems.push(...checkText(readFileSync(file, 'utf8'), { file: relative(root, file), kind: 'css', projectCss: true }));
288
+ else add(relative(root, file), 'stylesheet', extname(file));
114
289
  }
115
290
  for (const dir of dirs) {
116
291
  const abs = join(root, dir);
117
292
  if (!existsSync(abs)) continue;
118
293
  for (const file of walk(abs)) {
119
294
  const kind = KIND[extname(file)];
120
- if (kind && kind !== 'css') problems.push(...checkText(readFileSync(file, 'utf8'), { file: relative(root, file), kind }));
295
+ if (kind && kind !== 'css') problems.push(...checkText(readFileSync(file, 'utf8'), { file: relative(root, file), kind, layout, components }));
121
296
  }
122
297
  }
123
298
  return problems;
@@ -131,23 +306,33 @@ export function format(p) {
131
306
  const isMain = process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url);
132
307
  if (isMain) {
133
308
  const args = process.argv.slice(2);
134
- const at = args.indexOf('--dirs');
135
- const dirs = at >= 0 ? args[at + 1]?.split(',').filter(Boolean) : undefined;
136
- if (at >= 0 && !dirs?.length) { console.error('--dirs needs a comma-separated list, e.g. --dirs src,app'); process.exit(2); }
137
- const root = resolve(args.find((a, i) => !a.startsWith('--') && (at < 0 || i !== at + 1)) ?? '.');
309
+ const VALUED = ['--dirs', '--layout', '--components'];
310
+ const opt = (flag) => {
311
+ const at = args.indexOf(flag);
312
+ if (at < 0) return undefined;
313
+ const v = args[at + 1];
314
+ if (!v || v.startsWith('--')) { console.error(`${flag} needs a value, e.g. ${flag === '--layout' ? '--layout dashboard' : `${flag} a,b`}`); process.exit(2); }
315
+ return v;
316
+ };
317
+ const dirs = opt('--dirs')?.split(',').filter(Boolean);
318
+ const layout = opt('--layout');
319
+ const components = opt('--components')?.split(',').filter(Boolean);
320
+ const root = resolve(args.find((a, i) => !a.startsWith('--') && !VALUED.includes(args[i - 1])) ?? '.');
138
321
  if (!existsSync(root)) { console.error(`No such folder: ${root}`); process.exit(2); }
139
- const problems = checkProject(root, dirs ? { dirs } : undefined);
322
+ const problems = checkProject(root, { ...(dirs && { dirs }), layout, components });
323
+ const errors = problems.filter((p) => p.severity === 'error');
140
324
  const version = JSON.parse(read('dist', 'tokens.json')).version;
141
325
  if (args.includes('--json')) {
142
326
  console.log(JSON.stringify({ version, problems }, null, 2));
143
- } else if (problems.length) {
327
+ } else {
144
328
  for (const p of problems) {
145
- console.error(`✗ ${format(p)}`);
146
- if (process.env.GITHUB_ACTIONS) console.log(`::error file=${p.file},line=${p.line || 1},title=MotifSpec ${p.rule}::${p.message}`);
329
+ console.error(`${p.severity === 'error' ? '✗' : '⚠'} ${format(p)}`);
330
+ if (process.env.GITHUB_ACTIONS) console.log(`::${p.severity} file=${p.file},line=${p.line || 1},title=MotifSpec ${p.rule}::${p.message}`);
147
331
  }
148
- console.error(`${problems.length} problem(s), checked against MotifSpec ${version}.`);
149
- } else {
150
- console.log(`No problems in ${relative(process.cwd(), root) || '.'}: checked against MotifSpec ${version}.`);
332
+ const where = relative(process.cwd(), root) || '.';
333
+ const warnings = problems.length - errors.length;
334
+ if (errors.length) console.error(`${errors.length} problem(s)${warnings ? ` and ${warnings} warning(s)` : ''}, checked against MotifSpec ${version}.`);
335
+ else console.log(`No problems in ${where}${warnings ? `, ${warnings} warning(s)` : ''}: checked against MotifSpec ${version}.`);
151
336
  }
152
- process.exit(problems.length ? 1 : 0);
337
+ process.exit(errors.length ? 1 : 0);
153
338
  }
package/scripts/lib.mjs CHANGED
@@ -174,3 +174,67 @@ export function contrastReport(tokens) {
174
174
  }
175
175
  return rows;
176
176
  }
177
+
178
+ // ------------------------------------------------------------------ JSX: the components' markup for React and similar
179
+ // HTML attribute names that differ in JSX. Anything else (aria-*, data-*, viewBox, href) keeps its name.
180
+ const JSX_NAMES = {
181
+ class: 'className', for: 'htmlFor', tabindex: 'tabIndex', datetime: 'dateTime', readonly: 'readOnly', maxlength: 'maxLength',
182
+ minlength: 'minLength', colspan: 'colSpan', rowspan: 'rowSpan', autocomplete: 'autoComplete', autofocus: 'autoFocus',
183
+ inputmode: 'inputMode', enterkeyhint: 'enterKeyHint', spellcheck: 'spellCheck', srcset: 'srcSet', crossorigin: 'crossOrigin',
184
+ novalidate: 'noValidate', accesskey: 'accessKey', contenteditable: 'contentEditable', fetchpriority: 'fetchPriority',
185
+ 'text-anchor': 'textAnchor', 'marker-end': 'markerEnd', 'marker-start': 'markerStart', 'stroke-width': 'strokeWidth',
186
+ 'stroke-linecap': 'strokeLinecap', 'stroke-linejoin': 'strokeLinejoin', 'stroke-dasharray': 'strokeDasharray',
187
+ 'fill-rule': 'fillRule', 'clip-rule': 'clipRule', 'vector-effect': 'vectorEffect', 'xlink:href': 'href',
188
+ };
189
+ const VOID = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'source', 'track', 'wbr']);
190
+ const FORM_FIELDS = new Set(['input', 'textarea', 'select']);
191
+ const ATTR = /\s*([^\s=/>]+)(?:\s*=\s*("[^"]*"|'[^']*'|[^\s>]+))?/g;
192
+
193
+ /**
194
+ * A component's HTML example as JSX, converted mechanically: renamed attributes, void elements closed, comments as
195
+ * {/* *\/}, braces in text escaped, uncontrolled form values as defaultValue and defaultChecked, and more than one root
196
+ * wrapped in a fragment. Returns null for an example written in Hugo template syntax ({{ }}), which has no JSX form.
197
+ */
198
+ export function htmlToJsx(html) {
199
+ if (html.includes('{{')) return null;
200
+ let roots = 0;
201
+ let depth = 0;
202
+ const out = [];
203
+ let last = 0;
204
+ const text = (t) => {
205
+ if (depth === 0 && t.trim()) roots++;
206
+ return t.replace(/[{}]/g, (b) => `{'${b}'}`);
207
+ };
208
+ for (const m of html.matchAll(/<!--([\s\S]*?)-->|<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:\s+[^<>]*?)?)\s*(\/?)>/g)) {
209
+ out.push(text(html.slice(last, m.index)));
210
+ last = m.index + m[0].length;
211
+ if (m[1] !== undefined) { if (depth === 0) roots++; out.push(`{/*${m[1].replace(/\*\//g, '* /')}*/}`); continue; }
212
+ const [, , closing, tag, attrs = '', selfClosed] = m;
213
+ if (closing) { depth--; out.push(`</${tag}>`); continue; }
214
+ if (depth === 0) roots++;
215
+ const parts = [...attrs.matchAll(ATTR)].filter((a) => a[1]).map(([, name, value]) => {
216
+ let n = JSX_NAMES[name.toLowerCase()] ?? name;
217
+ if (FORM_FIELDS.has(tag) && n === 'value') n = 'defaultValue';
218
+ if (FORM_FIELDS.has(tag) && n === 'checked') n = 'defaultChecked';
219
+ if (FORM_FIELDS.has(tag) && n === 'selected') n = 'defaultValue';
220
+ if (value === undefined) return n;
221
+ return `${n}=${/^["']/.test(value) ? value : `"${value}"`}`;
222
+ });
223
+ const isVoid = VOID.has(tag.toLowerCase()) || selfClosed;
224
+ if (!isVoid) depth++;
225
+ out.push(`<${tag}${parts.length ? ' ' + parts.join(' ') : ''}${isVoid ? ' />' : '>'}`);
226
+ }
227
+ out.push(text(html.slice(last)));
228
+ const jsx = out.join('').trim();
229
+ return roots > 1 ? `<>\n${jsx}\n</>` : jsx;
230
+ }
231
+
232
+ /** A component doc with each `html preview` example replaced by its JSX form (see htmlToJsx). */
233
+ export function docAsJsx(md) {
234
+ return md.replace(/```html preview\n([\s\S]*?)```/g, (block, html) => {
235
+ const jsx = htmlToJsx(html);
236
+ return jsx === null
237
+ ? `This example is written for Hugo, so it has no JSX form. Outside Hugo, use the files the README's npm table lists.\n\n${block}`
238
+ : `\`\`\`jsx\n${jsx}\n\`\`\``;
239
+ });
240
+ }
package/tokens/color.json CHANGED
@@ -1320,6 +1320,10 @@
1320
1320
  {
1321
1321
  "token": "color.surface.raised",
1322
1322
  "min": 4.5
1323
+ },
1324
+ {
1325
+ "token": "color.surface.hover",
1326
+ "min": 4.5
1323
1327
  }
1324
1328
  ]
1325
1329
  }
@@ -1369,6 +1373,10 @@
1369
1373
  {
1370
1374
  "token": "color.surface.raised",
1371
1375
  "min": 4.5
1376
+ },
1377
+ {
1378
+ "token": "color.surface.hover",
1379
+ "min": 4.5
1372
1380
  }
1373
1381
  ]
1374
1382
  }
@@ -1418,6 +1426,10 @@
1418
1426
  {
1419
1427
  "token": "color.surface.raised",
1420
1428
  "min": 4.5
1429
+ },
1430
+ {
1431
+ "token": "color.surface.hover",
1432
+ "min": 4.5
1421
1433
  }
1422
1434
  ]
1423
1435
  }
@@ -1467,6 +1479,10 @@
1467
1479
  {
1468
1480
  "token": "color.surface.raised",
1469
1481
  "min": 4.5
1482
+ },
1483
+ {
1484
+ "token": "color.surface.hover",
1485
+ "min": 4.5
1470
1486
  }
1471
1487
  ]
1472
1488
  }