@aitrien/motifspec 1.17.3 → 1.18.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.
- package/CHANGELOG.md +26 -0
- package/README.md +37 -9
- package/dist/codex.css +26 -6
- package/dist/contrast.md +5 -1
- package/dist/icons.svg +13 -0
- package/dist/tokens.css +1 -1
- package/dist/tokens.js +17 -1
- package/dist/tokens.json +17 -1
- package/docs/components/_template.md +5 -0
- package/docs/components/accession-label.md +5 -1
- package/docs/components/backdrop.md +3 -1
- package/docs/components/button-and-link.md +10 -1
- package/docs/components/callout.md +1 -0
- package/docs/components/code-block.md +10 -0
- package/docs/components/data-table.md +22 -1
- package/docs/components/disclosure.md +73 -0
- package/docs/components/figure.md +1 -0
- package/docs/components/heading-anchor.md +3 -1
- package/docs/components/icon.md +3 -2
- package/docs/components/keyboard-key.md +53 -0
- package/docs/components/ornament.md +2 -0
- package/docs/components/pagination.md +1 -0
- package/docs/components/post-list-item.md +1 -0
- package/docs/components/project-card.md +1 -0
- package/docs/components/prose.md +1 -0
- package/docs/components/site-footer.md +1 -0
- package/docs/components/site-header.md +10 -0
- package/docs/components/specimen-plate.md +1 -0
- package/docs/components/status.md +74 -0
- package/docs/components/table-of-contents.md +9 -0
- package/docs/components/tag.md +2 -1
- package/docs/components/tooltip.md +6 -0
- package/docs/hugo.md +2 -2
- package/docs/layouts/a-la-carte.md +36 -0
- package/docs/layouts/dashboard.md +58 -0
- package/docs/layouts/documentation.md +48 -0
- package/docs/{templates.md → layouts/portfolio.md} +34 -2
- package/icons/manifest.json +52 -0
- package/icons/svg/apps.svg +1 -0
- package/icons/svg/close.svg +1 -0
- package/icons/svg/dashboard.svg +1 -0
- package/icons/svg/dns.svg +1 -0
- package/icons/svg/edit.svg +1 -0
- package/icons/svg/lan.svg +1 -0
- package/icons/svg/menu.svg +1 -0
- package/icons/svg/notifications.svg +1 -0
- package/icons/svg/restart_alt.svg +1 -0
- package/icons/svg/search.svg +1 -0
- package/icons/svg/settings.svg +1 -0
- package/icons/svg/storage.svg +1 -0
- package/icons/svg/terminal.svg +1 -0
- package/layouts/_partials/motifspec/filed-under.html +1 -1
- package/package.json +1 -1
- package/scripts/check.mjs +171 -23
- package/scripts/lib.mjs +64 -0
- package/tokens/color.json +16 -0
|
@@ -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/
|
|
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
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
|
-
*
|
|
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+/))
|
|
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,65 @@ function* walk(dir) {
|
|
|
104
197
|
}
|
|
105
198
|
}
|
|
106
199
|
|
|
107
|
-
/**
|
|
108
|
-
|
|
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
|
+
const table = text.match(new RegExp(`^\\[${isParams ? '' : 'params\\.'}motifspec\\]\\s*$([\\s\\S]*?)(?=^\\[|(?![\\s\\S]))`, 'm'))?.[1];
|
|
218
|
+
if (table) found = { layout: table.match(/^\s*layout\s*=\s*["']([^"']+)["']/m)?.[1], components: list(table.match(/^\s*components\s*=\s*\[([\s\S]*?)\]/m)?.[1]) };
|
|
219
|
+
} else {
|
|
220
|
+
const block = text.match(isParams ? /^motifspec:\s*\n((?:[ \t]+.*\n?)*)/m : /^[ \t]+motifspec:\s*\n((?:[ \t]+.*\n?)*)/m)?.[1];
|
|
221
|
+
if (block) {
|
|
222
|
+
const inline = block.match(/^\s*components:\s*\[(.*)\]/m)?.[1];
|
|
223
|
+
const dashed = block.match(/^\s*components:\s*\n((?:\s*-\s*.+\n?)*)/m)?.[1]?.match(/-\s*(.+)/g)?.map((x) => x.replace(/^-\s*/, ''));
|
|
224
|
+
found = { layout: block.match(/^\s*layout:\s*["']?([a-z-]+)/m)?.[1], components: inline ? list(inline) : list(dashed?.join(',')) };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (found?.layout || found?.components) return { layout: found.layout, components: found.components, from: f };
|
|
228
|
+
}
|
|
229
|
+
return {};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Check a project that uses MotifSpec: no stylesheets anywhere (except an à la carte project's own, held to tokens),
|
|
234
|
+
* and every file in `dirs` checked by checkText against the project's layout.
|
|
235
|
+
*/
|
|
236
|
+
export function checkProject(root, { dirs = ['layouts', 'content'], layout, components } = {}) {
|
|
109
237
|
const problems = [];
|
|
238
|
+
const declared = declaredLayout(root);
|
|
239
|
+
const fromConfig = (v) => (v === undefined ? declared.from : undefined);
|
|
240
|
+
const layoutFrom = fromConfig(layout) ?? '<options>';
|
|
241
|
+
const componentsFrom = fromConfig(components) ?? '<options>';
|
|
242
|
+
layout ??= declared.layout ?? 'portfolio';
|
|
243
|
+
components ??= declared.components;
|
|
244
|
+
const add = (file, rule, match) => problems.push({ file, line: 0, rule, match, message: RULES[rule], severity: WARNINGS.has(rule) ? 'warning' : 'error' });
|
|
245
|
+
if (!LAYOUTS.includes(layout)) { add(layoutFrom, 'unknown-layout', layout); return problems; }
|
|
246
|
+
const { docs } = load();
|
|
247
|
+
for (const c of components ?? []) if (!docs.has(c)) add(componentsFrom, 'unknown-component', c);
|
|
110
248
|
for (const file of walk(root)) {
|
|
111
|
-
if (['.css', '.scss', '.sass', '.less'].includes(extname(file)))
|
|
112
|
-
|
|
113
|
-
|
|
249
|
+
if (!['.css', '.scss', '.sass', '.less'].includes(extname(file))) continue;
|
|
250
|
+
if (layout === 'a-la-carte') problems.push(...checkText(readFileSync(file, 'utf8'), { file: relative(root, file), kind: 'css', projectCss: true }));
|
|
251
|
+
else add(relative(root, file), 'stylesheet', extname(file));
|
|
114
252
|
}
|
|
115
253
|
for (const dir of dirs) {
|
|
116
254
|
const abs = join(root, dir);
|
|
117
255
|
if (!existsSync(abs)) continue;
|
|
118
256
|
for (const file of walk(abs)) {
|
|
119
257
|
const kind = KIND[extname(file)];
|
|
120
|
-
if (kind && kind !== 'css') problems.push(...checkText(readFileSync(file, 'utf8'), { file: relative(root, file), kind }));
|
|
258
|
+
if (kind && kind !== 'css') problems.push(...checkText(readFileSync(file, 'utf8'), { file: relative(root, file), kind, layout, components }));
|
|
121
259
|
}
|
|
122
260
|
}
|
|
123
261
|
return problems;
|
|
@@ -131,23 +269,33 @@ export function format(p) {
|
|
|
131
269
|
const isMain = process.argv[1] && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
132
270
|
if (isMain) {
|
|
133
271
|
const args = process.argv.slice(2);
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
272
|
+
const VALUED = ['--dirs', '--layout', '--components'];
|
|
273
|
+
const opt = (flag) => {
|
|
274
|
+
const at = args.indexOf(flag);
|
|
275
|
+
if (at < 0) return undefined;
|
|
276
|
+
const v = args[at + 1];
|
|
277
|
+
if (!v || v.startsWith('--')) { console.error(`${flag} needs a value, e.g. ${flag === '--layout' ? '--layout dashboard' : `${flag} a,b`}`); process.exit(2); }
|
|
278
|
+
return v;
|
|
279
|
+
};
|
|
280
|
+
const dirs = opt('--dirs')?.split(',').filter(Boolean);
|
|
281
|
+
const layout = opt('--layout');
|
|
282
|
+
const components = opt('--components')?.split(',').filter(Boolean);
|
|
283
|
+
const root = resolve(args.find((a, i) => !a.startsWith('--') && !VALUED.includes(args[i - 1])) ?? '.');
|
|
138
284
|
if (!existsSync(root)) { console.error(`No such folder: ${root}`); process.exit(2); }
|
|
139
|
-
const problems = checkProject(root, dirs
|
|
285
|
+
const problems = checkProject(root, { ...(dirs && { dirs }), layout, components });
|
|
286
|
+
const errors = problems.filter((p) => p.severity === 'error');
|
|
140
287
|
const version = JSON.parse(read('dist', 'tokens.json')).version;
|
|
141
288
|
if (args.includes('--json')) {
|
|
142
289
|
console.log(JSON.stringify({ version, problems }, null, 2));
|
|
143
|
-
} else
|
|
290
|
+
} else {
|
|
144
291
|
for (const p of problems) {
|
|
145
|
-
console.error(
|
|
146
|
-
if (process.env.GITHUB_ACTIONS) console.log(
|
|
292
|
+
console.error(`${p.severity === 'error' ? '✗' : '⚠'} ${format(p)}`);
|
|
293
|
+
if (process.env.GITHUB_ACTIONS) console.log(`::${p.severity} file=${p.file},line=${p.line || 1},title=MotifSpec ${p.rule}::${p.message}`);
|
|
147
294
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
console.
|
|
295
|
+
const where = relative(process.cwd(), root) || '.';
|
|
296
|
+
const warnings = problems.length - errors.length;
|
|
297
|
+
if (errors.length) console.error(`${errors.length} problem(s)${warnings ? ` and ${warnings} warning(s)` : ''}, checked against MotifSpec ${version}.`);
|
|
298
|
+
else console.log(`No problems in ${where}${warnings ? `, ${warnings} warning(s)` : ''}: checked against MotifSpec ${version}.`);
|
|
151
299
|
}
|
|
152
|
-
process.exit(
|
|
300
|
+
process.exit(errors.length ? 1 : 0);
|
|
153
301
|
}
|
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
|
}
|