@behavioral-agentic-design-system/core 0.40.0 → 0.45.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/README.md +2 -0
- package/package.json +41 -9
- package/scripts/a11y-lint.cjs +66 -3
- package/scripts/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -0
- package/scripts/health-report.mjs +23 -3
- package/scripts/lib/counted-lint.mjs +100 -0
- package/scripts/lib/marketing-library.mjs +129 -0
- package/scripts/lib/on-system.mjs +249 -0
- package/scripts/lib/random.mjs +22 -0
- package/scripts/lib/spec-parse.d.mts +25 -0
- package/scripts/lib/spec-parse.mjs +188 -0
- package/scripts/lib/tells.mjs +128 -0
- package/scripts/lint-css-vars.mjs +175 -0
- package/scripts/lint-html-nesting.mjs +116 -0
- package/scripts/lint-live-ctas.mjs +138 -0
- package/scripts/lint-slop.mjs +25 -1
- package/scripts/on-system-score.mjs +95 -0
- package/scripts/slop-rules.mjs +1 -1
- package/scripts/source-images.mjs +180 -0
- package/scripts/ux-tells.mjs +78 -0
- package/scripts/wcag-audit.cjs +72 -5
- package/src/api/brand-colors.ts +3 -0
- package/src/api/brand-fonts.ts +3 -0
- package/src/api/brand-mark.ts +6 -1
- package/src/api/dev-write-guard.ts +53 -0
- package/src/api/layers/file.ts +7 -4
- package/src/api/onboarding-extract.ts +85 -30
- package/src/api/onboarding.ts +3 -0
- package/src/api/save-tokens.ts +3 -0
- package/src/app/layout.tsx +6 -0
- package/src/app/opengraph-image.tsx +5 -0
- package/src/app/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +2003 -2
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +168 -49
- package/src/components/Foundations/Motion.stories.tsx +1 -0
- package/src/components/canvas/canvas.tsx +458 -0
- package/src/components/canvas/layout.ts +72 -0
- package/src/components/canvas/parse-canvas.ts +32 -0
- package/src/components/canvas/sample.ts +90 -0
- package/src/components/canvas/spec-frame.tsx +43 -0
- package/src/components/canvas/types.ts +33 -0
- package/src/components/customize/design-controls.tsx +16 -1
- package/src/components/docs-tab.tsx +7 -7
- package/src/components/home-recent.tsx +73 -0
- package/src/components/home-tab.tsx +13 -13
- package/src/components/layers-tab.tsx +2 -2
- package/src/components/markdown-preview.tsx +60 -12
- package/src/components/studio/control-panel.tsx +299 -0
- package/src/components/studio/control-row.tsx +77 -0
- package/src/components/studio/preview-frame.tsx +165 -0
- package/src/components/studio/preview-pane.tsx +247 -0
- package/src/components/studio/studio.tsx +158 -0
- package/src/components/studio/types.ts +218 -0
- package/src/components/studio/use-studio-tweaks.ts +128 -0
- package/src/components/studio/use-studio-view-state.ts +72 -0
- package/src/components/ui/anchor.tsx +37 -3
- package/src/components/ui/attachment.tsx +211 -0
- package/src/components/ui/autocomplete.tsx +1 -1
- package/src/components/ui/chart.tsx +3 -0
- package/src/components/ui/code.tsx +1 -1
- package/src/components/ui/color-picker.tsx +21 -5
- package/src/components/ui/data-table.tsx +64 -3
- package/src/components/ui/date-field.tsx +1 -1
- package/src/components/ui/editable.tsx +1 -0
- package/src/components/ui/faceted-filter.tsx +187 -0
- package/src/components/ui/gauge-chart.tsx +252 -0
- package/src/components/ui/heatmap.tsx +256 -0
- package/src/components/ui/index.ts +9 -0
- package/src/components/ui/infinite-scroll.tsx +103 -0
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/json-input.tsx +351 -0
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/navigation-progress.tsx +281 -0
- package/src/components/ui/number-input.tsx +27 -7
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/password-input.tsx +2 -1
- package/src/components/ui/password-strength-input.tsx +288 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/pill.tsx +140 -0
- package/src/components/ui/popover.tsx +27 -4
- package/src/components/ui/scroll-progress.tsx +100 -0
- package/src/components/ui/search-input.tsx +1 -1
- package/src/components/ui/snackbar.tsx +393 -0
- package/src/components/ui/sortable-list.tsx +342 -0
- package/src/components/ui/squircle.tsx +1 -1
- package/src/components/ui/table.tsx +1 -1
- package/src/components/ui/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- package/src/components/ui/tour.tsx +1 -3
- package/src/components/ui/transfer-list.tsx +13 -26
- package/src/components/ui/week-picker.tsx +1 -1
- package/src/components/ui/year-picker.tsx +1 -1
- package/src/data/component-added.json +958 -0
- package/src/data/docs-index.ts +36 -0
- package/src/hooks/use-global-mono-font.ts +1 -0
- package/src/hooks/use-global-primary-color.ts +1 -0
- package/src/hooks/use-global-sans-font.ts +1 -0
- package/src/hooks/use-global-serif-font.ts +1 -0
- package/src/hooks/use-global-type-scale.ts +17 -2
- package/src/hooks/use-mobile.ts +2 -0
- package/src/hooks/use-sync-type-scale.ts +7 -11
- package/src/lib/clamp.ts +2 -0
- package/src/lib/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- package/src/stories/Anchor.stories.tsx +54 -0
- package/src/stories/Attachment.stories.tsx +189 -0
- package/src/stories/Autocomplete.stories.tsx +2 -0
- package/src/stories/Canvas.stories.tsx +45 -0
- package/src/stories/Chart.stories.tsx +4 -0
- package/src/stories/Code.stories.tsx +1 -0
- package/src/stories/ColorPicker.stories.tsx +41 -0
- package/src/stories/DataTable.stories.tsx +30 -0
- package/src/stories/DateField.stories.tsx +21 -0
- package/src/stories/Editable.stories.tsx +2 -0
- package/src/stories/FacetedFilter.stories.tsx +197 -0
- package/src/stories/GaugeChart.stories.tsx +169 -0
- package/src/stories/Heatmap.stories.tsx +172 -0
- package/src/stories/InfiniteScroll.stories.tsx +225 -0
- package/src/stories/InlineEdit.stories.tsx +106 -0
- package/src/stories/JsonInput.stories.tsx +212 -0
- package/src/stories/MarkdownPreview.stories.tsx +53 -0
- package/src/stories/MonthPicker.stories.tsx +21 -0
- package/src/stories/NavigationProgress.stories.tsx +159 -0
- package/src/stories/NumberInput.stories.tsx +26 -0
- package/src/stories/OtpInput.stories.tsx +110 -0
- package/src/stories/PasswordInput.stories.tsx +4 -0
- package/src/stories/PasswordStrengthInput.stories.tsx +211 -0
- package/src/stories/PhoneInput.stories.tsx +127 -0
- package/src/stories/Pill.stories.tsx +201 -0
- package/src/stories/Popover.stories.tsx +29 -1
- package/src/stories/Portal.stories.tsx +3 -1
- package/src/stories/ScrollProgress.stories.tsx +117 -0
- package/src/stories/SearchInput.stories.tsx +2 -0
- package/src/stories/Snackbar.stories.tsx +315 -0
- package/src/stories/SortableList.stories.tsx +263 -0
- package/src/stories/Squircle.stories.tsx +1 -0
- package/src/stories/Table.stories.tsx +1 -0
- package/src/stories/TagsInput.stories.tsx +2 -0
- package/src/stories/Timer.stories.tsx +26 -0
- package/src/stories/Tour.stories.tsx +1 -0
- package/src/stories/TransferList.stories.tsx +4 -0
- package/src/stories/WeekPicker.stories.tsx +21 -0
- package/src/stories/YearPicker.stories.tsx +21 -0
- package/src/stories/story-groups.json +33 -16
- package/src/tokens.json +82 -54
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* counted-lint — the shared tail of the lints that count findings per file.
|
|
3
|
+
*
|
|
4
|
+
* A lint collects `findings` (what is wrong) and `scanned` (every file it
|
|
5
|
+
* actually looked at, including the clean ones) and hands both here. This module
|
|
6
|
+
* owns the four modes every such lint offers, so each lint stays about its rule:
|
|
7
|
+
*
|
|
8
|
+
* (default) strict: print the findings, exit 1 when there are any
|
|
9
|
+
* --warn the same report, always exit 0
|
|
10
|
+
* --init record today's counts into .bads-ratchet.json under this rule's id
|
|
11
|
+
* --ratchet compare against that baseline using ratchet.mjs: a listed file may
|
|
12
|
+
* not get worse, and no file may join the list
|
|
13
|
+
*
|
|
14
|
+
* `scanned` matters for a reason worth stating: a lint that looked at nothing
|
|
15
|
+
* and found nothing reports the same "clean" as one that looked at everything.
|
|
16
|
+
* Zero files scanned is refused here, loudly, in every mode.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { readBaseline, writeBaseline, runRatchet, BASELINE_FILE, SCHEMA_VERSION } from "../ratchet.mjs";
|
|
20
|
+
|
|
21
|
+
export function flagValue(argv, name, fallback) {
|
|
22
|
+
const i = argv.indexOf(`--${name}`);
|
|
23
|
+
return i >= 0 && argv[i + 1] && !argv[i + 1].startsWith("--") ? argv[i + 1] : fallback;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {object} o
|
|
28
|
+
* @param {string} o.ruleId key in .bads-ratchet.json, e.g. "live-ctas"
|
|
29
|
+
* @param {string} o.bin for messages, e.g. "bads-lint-live-ctas"
|
|
30
|
+
* @param {{file: string, line?: number, text: string}[]} o.findings
|
|
31
|
+
* @param {string[]} o.scanned every file read, relative to root
|
|
32
|
+
* @param {string} o.fix one short paragraph telling the reader how to fix a finding
|
|
33
|
+
* @param {string[]} [o.argv]
|
|
34
|
+
* @param {string} [o.root]
|
|
35
|
+
* @returns {number} the exit code (the caller decides whether to exit)
|
|
36
|
+
*/
|
|
37
|
+
export function finishCountedLint({ ruleId, bin, findings, scanned, fix, argv = process.argv.slice(2), root = process.cwd() }) {
|
|
38
|
+
if (scanned.length === 0) {
|
|
39
|
+
console.error(`${bin}: 0 files were scanned, so nothing was checked. This is NOT "no violations."`);
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const current = Object.fromEntries(scanned.map((f) => [f, 0]));
|
|
44
|
+
for (const f of findings) current[f.file] = (current[f.file] ?? 0) + 1;
|
|
45
|
+
|
|
46
|
+
if (argv.includes("--init")) {
|
|
47
|
+
const withViolations = Object.fromEntries(Object.entries(current).filter(([, n]) => n > 0));
|
|
48
|
+
const baseline = readBaseline(root);
|
|
49
|
+
baseline.version = SCHEMA_VERSION;
|
|
50
|
+
baseline.rules = baseline.rules ?? {};
|
|
51
|
+
baseline.rules[ruleId] = {
|
|
52
|
+
recordedAt: new Date().toISOString().slice(0, 10),
|
|
53
|
+
note: `${bin}. Shrink-only: an entry may be removed once its file is clean, and nothing may be added.`,
|
|
54
|
+
files: withViolations,
|
|
55
|
+
};
|
|
56
|
+
writeBaseline(baseline, root);
|
|
57
|
+
const n = Object.keys(withViolations).length;
|
|
58
|
+
console.log(`ratchet [${ruleId}]: recorded ${n} file(s) with findings into ${BASELINE_FILE}.`);
|
|
59
|
+
console.log(n === 0 ? " Nothing is in violation, so the rule can go straight to strict instead." : " Commit this file. From here the list may only shrink.");
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (argv.includes("--ratchet")) {
|
|
64
|
+
const { report, exitCode } = runRatchet({
|
|
65
|
+
ruleId,
|
|
66
|
+
current,
|
|
67
|
+
root,
|
|
68
|
+
baseRef: flagValue(argv, "base", "origin/main"),
|
|
69
|
+
advisory: argv.includes("--warn"),
|
|
70
|
+
});
|
|
71
|
+
console.log(report);
|
|
72
|
+
return exitCode;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (findings.length === 0) {
|
|
76
|
+
console.log(`${bin}: ${scanned.length} file(s) scanned, no findings.`);
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const byFile = new Map();
|
|
81
|
+
for (const f of findings) byFile.set(f.file, [...(byFile.get(f.file) ?? []), f]);
|
|
82
|
+
console.error(`${bin}: ${findings.length} finding(s) in ${byFile.size} file(s).\n`);
|
|
83
|
+
for (const [file, list] of byFile) {
|
|
84
|
+
console.error(file);
|
|
85
|
+
for (const f of list.slice(0, 20)) console.error(` ${f.line ? `L${f.line} ` : ""}${f.text}`);
|
|
86
|
+
if (list.length > 20) console.error(` …and ${list.length - 20} more`);
|
|
87
|
+
}
|
|
88
|
+
console.error(`\n${fix}`);
|
|
89
|
+
console.error(`\nAdopting on an existing codebase? Run \`${bin} --init\` to record today's counts, then \`${bin} --ratchet\` in CI: listed files may not get worse and no file may join the list.`);
|
|
90
|
+
return argv.includes("--warn") ? 0 : 1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** True when the module is being run as a script, not imported by a test. */
|
|
94
|
+
export function isMain(importMetaUrl) {
|
|
95
|
+
try {
|
|
96
|
+
return importMetaUrl === new URL(`file://${process.argv[1]}`).href || importMetaUrl.endsWith(process.argv[1]);
|
|
97
|
+
} catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The marketing composition library (disciplines/marketing/library/): 20 directions,
|
|
3
|
+
* 48 heroes and 172 sections, derived from taste-skill (MIT; see that folder's
|
|
4
|
+
* NOTICE.md). This module loads it, deals directions, and builds the direction sheet.
|
|
5
|
+
* Pure except for loadLibrary(), which reads the three JSON files.
|
|
6
|
+
*
|
|
7
|
+
* Dealing, not choosing: a model asked to invent a look returns the category default.
|
|
8
|
+
* Three dealt directions make the choice a real one. A sheet then deals a hero and a
|
|
9
|
+
* section per role from the chosen direction's own pool, so the page is composed from
|
|
10
|
+
* parts drawn for each other.
|
|
11
|
+
*/
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import { shuffle } from "./random.mjs";
|
|
15
|
+
|
|
16
|
+
export const LIB_DIR = "disciplines/marketing/library";
|
|
17
|
+
|
|
18
|
+
/** Load the library from a repo root, or null when it isn't there (a fork may delete it). */
|
|
19
|
+
export function loadLibrary(root) {
|
|
20
|
+
const read = (f) => JSON.parse(fs.readFileSync(path.join(root, LIB_DIR, f), "utf8"));
|
|
21
|
+
try { return { directions: read("directions.json"), heroes: read("heroes.json"), sections: read("sections.json") }; } catch { return null; }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const uniq = (a) => [...new Set(a.flat())].sort();
|
|
25
|
+
export function vocab(lib) {
|
|
26
|
+
return { sectors: uniq(lib.directions.map((d) => d.sectors)), tones: uniq(lib.directions.map((d) => d.tones)), roles: uniq(lib.sections.map((s) => s.role)) };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether an entry's asset needs are met. Pictures of the client's world ("photography") are
|
|
31
|
+
* assumed findable with bads-source-images. A software product can show a real interface built
|
|
32
|
+
* from its own components, so "product-ui" is met when `software` is set. "product-photo" must
|
|
33
|
+
* be listed in `have`.
|
|
34
|
+
*/
|
|
35
|
+
export function feasible(entry, { have = [], software = false } = {}) {
|
|
36
|
+
return (entry.needs || []).every((n) => n === "photography" || have.includes(n) || (n === "product-ui" && software));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const trim = (s, n) => { const t = String(s || "").replace(/\s+/g, " ").trim(); return t.length <= n ? t : t.slice(0, t.lastIndexOf(" ", n - 1)) + "…"; };
|
|
40
|
+
|
|
41
|
+
/** Deal `count` directions that fit the sector and tone, skipping the fork's recent ones. */
|
|
42
|
+
export function dealDirections(lib, { sector, tone, have = [], software = false, exclude = [], count = 3, random = Math.random } = {}) {
|
|
43
|
+
const skip = new Set(exclude);
|
|
44
|
+
const ok = (d) => feasible(d, { have, software });
|
|
45
|
+
const base = lib.directions.filter(ok);
|
|
46
|
+
const tiers = [
|
|
47
|
+
(d) => (!sector || d.sectors.includes(sector)) && (!tone || d.tones.includes(tone)),
|
|
48
|
+
(d) => !sector || d.sectors.includes(sector),
|
|
49
|
+
() => true,
|
|
50
|
+
];
|
|
51
|
+
const notes = [];
|
|
52
|
+
let pool = [];
|
|
53
|
+
for (const [i, fits] of tiers.entries()) {
|
|
54
|
+
pool = base.filter((d) => fits(d) && !skip.has(d.id));
|
|
55
|
+
if (pool.length >= count) { if (i === 1) notes.push(`Fewer than ${count} directions fit both the sector and the tone, so the tone was relaxed.`); if (i === 2) notes.push(`Fewer than ${count} directions fit the sector, so the whole library was used.`); break; }
|
|
56
|
+
}
|
|
57
|
+
if (pool.length < count) { pool = base; notes.push("The recent-direction exclusions left too few, so a recent direction may appear. Say why in the sketch."); }
|
|
58
|
+
return { directions: shuffle(pool, random).slice(0, count), notes, skipped: exclude.filter((id) => lib.directions.some((d) => d.id === id)) };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Deal one hero and one section per role for a chosen direction. */
|
|
62
|
+
export function dealSheet(lib, { direction, roles, have = [], software = false, random = Math.random }) {
|
|
63
|
+
const dir = lib.directions.find((d) => d.id === direction);
|
|
64
|
+
if (!dir) throw new Error(`no direction "${direction}". List them with --list directions.`);
|
|
65
|
+
const opts = { have, software };
|
|
66
|
+
const heroes = lib.heroes.filter((h) => h.directions.includes(dir.id) && feasible(h, opts));
|
|
67
|
+
const notes = [];
|
|
68
|
+
if (!heroes.length) throw new Error(`no hero for "${dir.id}" fits the assets you have. Pass --have, or --software for a software product.`);
|
|
69
|
+
const hero = shuffle(heroes, random)[0];
|
|
70
|
+
const used = new Set([hero.archetype]);
|
|
71
|
+
const sections = roles.map((role) => {
|
|
72
|
+
let pool = lib.sections.filter((s) => s.role === role && s.directions.includes(dir.id) && feasible(s, opts));
|
|
73
|
+
let drawnFor = true;
|
|
74
|
+
if (!pool.length) { pool = lib.sections.filter((s) => s.role === role && feasible(s, opts)); drawnFor = false; }
|
|
75
|
+
if (!pool.length) { notes.push(`No section for the role "${role}" fits the assets you have.`); return { role, section: null, drawnFor }; }
|
|
76
|
+
// Prefer a shape not yet used, so the page doesn't repeat one composition.
|
|
77
|
+
const fresh = pool.filter((s) => !used.has(s.shape));
|
|
78
|
+
const pick = shuffle(fresh.length ? fresh : pool, random)[0];
|
|
79
|
+
used.add(pick.shape);
|
|
80
|
+
if (!drawnFor) notes.push(`No "${role}" section is drawn for ${dir.id}; this one comes from the wider library.`);
|
|
81
|
+
return { role, section: pick, drawnFor };
|
|
82
|
+
});
|
|
83
|
+
return { direction: dir, hero, sections, notes };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The sections available for one role under a direction, for swapping a section that can't hold the real content. */
|
|
87
|
+
export function alternatives(lib, { direction, role, have = [], software = false }) {
|
|
88
|
+
return lib.sections.filter((s) => s.role === role && s.directions.includes(direction) && feasible(s, { have, software }));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function formatDirections(result, { sector, tone } = {}) {
|
|
92
|
+
const L = [];
|
|
93
|
+
L.push(`Dealt ${result.directions.length} directions${sector || tone ? ` for ${[sector, tone].filter(Boolean).join(", ")}` : ""}.`);
|
|
94
|
+
L.push(result.skipped.length ? `Skipped this fork's recent: ${result.skipped.join(", ")}.` : "No library direction recorded in ledgers/prototypes.jsonl (libraryDirection), so nothing is skipped.");
|
|
95
|
+
for (const n of result.notes) L.push(n);
|
|
96
|
+
L.push("");
|
|
97
|
+
result.directions.forEach((d, i) => {
|
|
98
|
+
L.push(`${i + 1}. ${d.name} [${d.id}]`);
|
|
99
|
+
L.push(` ${trim(d.idea, 360)}`);
|
|
100
|
+
L.push(` Tones: ${d.tones.join(", ")}.${d.needs.length ? ` Needs: ${d.needs.join(", ")}.` : ""}${d.needsPictures ? " Many pictures: find real ones with bads-source-images." : ""}`);
|
|
101
|
+
L.push(` Watch out: ${trim(d.pitfalls, 220)}`);
|
|
102
|
+
L.push("");
|
|
103
|
+
});
|
|
104
|
+
L.push("Hold each against the subject inventory (prompts/subject-inventory.md): which can carry something only this client has? Choose one and write why in one line. Then deal its sheet:");
|
|
105
|
+
L.push(" bads-deal-directions --surface marketing --direction <id> --sections <roles in the order of your argument>");
|
|
106
|
+
return L.join("\n");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function formatSheet(s) {
|
|
110
|
+
const L = [];
|
|
111
|
+
const { direction: d, hero } = s;
|
|
112
|
+
L.push(`DIRECTION SHEET: ${d.name} [${d.id}]`, "");
|
|
113
|
+
L.push("Brand tokens decide colors and fonts. The fields below give proportions and treatment, not values. Adopt the sheet; don't blend it with the layout you would have made anyway. Redraw a slot only for a reason you can state, such as a brand constraint, and record the redraw.", "");
|
|
114
|
+
L.push("THE IDEA", d.idea, "");
|
|
115
|
+
L.push("COMPOSITION", d.composition, "");
|
|
116
|
+
L.push("TYPE TREATMENT", d.typography, "");
|
|
117
|
+
L.push("COLOUR PROPORTIONS", d.colour, "");
|
|
118
|
+
L.push("IMAGERY", d.imagery, "");
|
|
119
|
+
L.push("WHAT MAKES IT RICH", d.richness, "");
|
|
120
|
+
L.push("PITFALLS", d.pitfalls, "");
|
|
121
|
+
L.push(`HERO: ${hero.name} [${hero.id}] (${hero.archetype})`, hero.blueprint, `Mobile: ${hero.mobile}`, `Headline: ${hero.headline}`, "");
|
|
122
|
+
for (const { role, section } of s.sections) {
|
|
123
|
+
if (!section) { L.push(`SECTION ${role.toUpperCase()}: none available`, ""); continue; }
|
|
124
|
+
L.push(`SECTION ${role.toUpperCase()}: ${section.name} [${section.id}] (${section.shape})`, section.blueprint, `Mobile: ${section.mobile}`, "");
|
|
125
|
+
}
|
|
126
|
+
for (const n of s.notes) L.push(`Note: ${n}`);
|
|
127
|
+
L.push("Next: record the direction id as libraryDirection on the prototype's ledger row. Source the pictures (bads-source-images), build, then run bads-ux-tells on the result.");
|
|
128
|
+
return L.join("\n");
|
|
129
|
+
}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* on-system: classify every styling decision in a source file as on the design system or off it.
|
|
3
|
+
*
|
|
4
|
+
* A design system video called this an "on system %" for a screen: what share of what got styled uses the
|
|
5
|
+
* system's tokens, and what is rogue type, off-scale spacing or a stray color. This is the same idea for code,
|
|
6
|
+
* as a deterministic count, not a judgment.
|
|
7
|
+
*
|
|
8
|
+
* WHAT COUNTS. Five categories: color, spacing, type, radius, shadow. A Tailwind utility is one decision.
|
|
9
|
+
* - ON: a semantic color (bg-primary, text-muted-foreground), a step on the spacing scale (p-4, gap-6), a named
|
|
10
|
+
* type size or weight (text-sm, font-medium), a named radius or shadow, or any arbitrary value that points
|
|
11
|
+
* at a token (bg-[var(--brand)], p-[var(--gutter)]).
|
|
12
|
+
* - OFF: a raw palette color (bg-blue-500, text-white), a literal color (bg-[#fff]), an arbitrary length
|
|
13
|
+
* (p-[13px], text-[15px], rounded-[7px]), an off-scale step (p-13), a literal shadow (shadow-[0_2px_...]),
|
|
14
|
+
* and a hex color written straight into code.
|
|
15
|
+
* Utilities that are not a styling choice against the system (flex, w-full, grid-cols-3, text-center) are not counted.
|
|
16
|
+
*
|
|
17
|
+
* LIMITS, said plainly. It reads class strings, not rendered CSS: a class built at runtime ("p-" + n) is invisible,
|
|
18
|
+
* and prose that happens to contain "gap-4" would count. It reads the source, not what the browser shows, so it
|
|
19
|
+
* cannot see a component that is on-system by itself and wrong in context. Treat the score as a trend and a pointer
|
|
20
|
+
* to the files worth opening, never as a verdict. Escape hatch: `allow-off-system: <reason>` on the line, or the
|
|
21
|
+
* line above, stops that line's off-system tokens from counting.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export const CATEGORIES = ["color", "spacing", "type", "radius", "shadow"];
|
|
25
|
+
|
|
26
|
+
const PALETTE = "slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose";
|
|
27
|
+
const PALETTE_RE = new RegExp(`^(?:${PALETTE})-\\d{2,3}$`);
|
|
28
|
+
const COLOR_LITERAL = /^(?:#[0-9a-fA-F]{3,8}|(?:rgb|rgba|hsl|hsla|oklch|oklab|lab|lch|color)\()/;
|
|
29
|
+
const LENGTH_LITERAL = /^-?\d*\.?\d+(?:px|rem|em|%|vh|vw|dvh|svh|ch|pt)$/;
|
|
30
|
+
|
|
31
|
+
const SPACING_STEPS = new Set(
|
|
32
|
+
["0", "px", "0.5", "1", "1.5", "2", "2.5", "3", "3.5", "4", "5", "6", "7", "8", "9", "10", "11", "12", "14", "16", "20", "24", "28", "32", "36", "40", "44", "48", "52", "56", "60", "64", "72", "80", "96"],
|
|
33
|
+
);
|
|
34
|
+
const SPACING_PREFIXES = new Set(["p", "px", "py", "pt", "pr", "pb", "pl", "ps", "pe", "m", "mx", "my", "mt", "mr", "mb", "ml", "ms", "me", "gap", "gap-x", "gap-y", "space-x", "space-y"]);
|
|
35
|
+
const POSITION_PREFIXES = new Set(["inset", "inset-x", "inset-y", "top", "right", "bottom", "left", "start", "end"]);
|
|
36
|
+
|
|
37
|
+
const TEXT_SIZES = /^(?:xs|sm|base|lg|xl|[2-9]xl)$/;
|
|
38
|
+
const TEXT_NOT_COLOR = /^(?:left|center|right|justify|start|end|wrap|nowrap|balance|pretty|ellipsis|clip|xs|sm|base|lg|xl|[2-9]xl)$/;
|
|
39
|
+
const WEIGHTS = /^(?:thin|extralight|light|normal|medium|semibold|bold|extrabold|black)$/;
|
|
40
|
+
const FONT_FAMILIES = /^(?:sans|serif|mono)$/;
|
|
41
|
+
|
|
42
|
+
const COLOR_PREFIXES = new Set(["bg", "text", "border", "ring", "outline", "fill", "stroke", "divide", "from", "via", "to", "accent", "caret", "decoration", "placeholder"]);
|
|
43
|
+
const NEUTRAL_COLOR_VALUES = /^(?:transparent|current|inherit|none|auto)$/;
|
|
44
|
+
const NOT_A_COLOR = {
|
|
45
|
+
bg: /^(?:cover|contain|center|no-repeat|repeat(?:-[xy]|-round|-space)?|fixed|local|scroll|none|top|bottom|left|right|auto|clip-.+|origin-.+|blend-.+|linear-.+|radial-.+|conic-.+|gradient-.+|size-.+|position-.+|\[(?:url|image|length|position|size).*\])$/,
|
|
46
|
+
border: /^(?:[trblxyse]|[trblxyse]-\d+|\d+|0|px|solid|dashed|dotted|double|hidden|none|collapse|separate|spacing.*)$/,
|
|
47
|
+
divide: /^(?:[xy]|[xy]-\d+|[xy]-reverse|solid|dashed|dotted|double|none)$/,
|
|
48
|
+
ring: /^(?:\d+|0|inset|offset-.+)$/,
|
|
49
|
+
outline: /^(?:\d+|0|none|dashed|dotted|double|hidden|offset-.+)$/,
|
|
50
|
+
stroke: /^(?:\d+|0|none)$/,
|
|
51
|
+
fill: /^(?:none)$/,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** Splits "md:hover:-translate-x-1" style variants off. Returns { utility, important }. */
|
|
55
|
+
function stripVariants(token) {
|
|
56
|
+
let depth = 0;
|
|
57
|
+
let cut = -1;
|
|
58
|
+
for (let i = 0; i < token.length; i++) {
|
|
59
|
+
const c = token[i];
|
|
60
|
+
if (c === "[" || c === "(") depth++;
|
|
61
|
+
else if (c === "]" || c === ")") depth--;
|
|
62
|
+
else if (c === ":" && depth === 0) cut = i;
|
|
63
|
+
}
|
|
64
|
+
let utility = cut === -1 ? token : token.slice(cut + 1);
|
|
65
|
+
if (utility.startsWith("!")) utility = utility.slice(1);
|
|
66
|
+
return utility;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Splits "p-4" into { prefix: "p", value: "4" }, preferring the longest known prefix. */
|
|
70
|
+
function splitUtility(utility) {
|
|
71
|
+
const u = utility.startsWith("-") ? utility.slice(1) : utility;
|
|
72
|
+
const all = [...SPACING_PREFIXES, ...POSITION_PREFIXES, ...COLOR_PREFIXES, "rounded", "shadow", "text", "font", "leading", "tracking"]
|
|
73
|
+
.sort((a, b) => b.length - a.length);
|
|
74
|
+
for (const prefix of all) {
|
|
75
|
+
if (u === prefix) return { prefix, value: "" };
|
|
76
|
+
if (u.startsWith(prefix + "-")) return { prefix, value: u.slice(prefix.length + 1) };
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const refsToken = (arbitrary) => /^\[.*var\(--/.test(arbitrary) || /^\(--/.test(arbitrary);
|
|
82
|
+
const inner = (arbitrary) => arbitrary.replace(/^\[/, "").replace(/\]$/, "");
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Classify one class token. Returns { category, on } or null when it is not a styling decision against the system.
|
|
86
|
+
*/
|
|
87
|
+
export function classifyToken(rawToken) {
|
|
88
|
+
const utility = stripVariants(rawToken.trim());
|
|
89
|
+
if (!utility) return null;
|
|
90
|
+
const parts = splitUtility(utility);
|
|
91
|
+
if (!parts) return null;
|
|
92
|
+
const { prefix } = parts;
|
|
93
|
+
let { value } = parts;
|
|
94
|
+
const arbitrary = value.startsWith("[") || value.startsWith("(");
|
|
95
|
+
|
|
96
|
+
// ---- radius, shadow --------------------------------------------------------------------------------------------
|
|
97
|
+
if (prefix === "rounded") {
|
|
98
|
+
const side = value.replace(/^(?:t|r|b|l|s|e|tl|tr|bl|br|ss|se|ee|es)(?:-|$)/, "");
|
|
99
|
+
if (side === "" || /^(?:none|xs|sm|md|lg|xl|[2-4]xl|full)$/.test(side)) return { category: "radius", on: true };
|
|
100
|
+
if (side.startsWith("[") || side.startsWith("(")) return { category: "radius", on: refsToken(side) };
|
|
101
|
+
return { category: "radius", on: false };
|
|
102
|
+
}
|
|
103
|
+
if (prefix === "shadow") {
|
|
104
|
+
if (value === "" || /^(?:2xs|xs|sm|md|lg|xl|2xl|inner|none)$/.test(value)) return { category: "shadow", on: true };
|
|
105
|
+
if (arbitrary) {
|
|
106
|
+
// shadow-[#fff] is a shadow COLOR; shadow-[0_2px_4px_...] is a literal shadow; shadow-[var(--x)] is a token.
|
|
107
|
+
return { category: COLOR_LITERAL.test(inner(value)) ? "color" : "shadow", on: refsToken(value) };
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ---- type ------------------------------------------------------------------------------------------------------
|
|
113
|
+
if (prefix === "font") {
|
|
114
|
+
if (WEIGHTS.test(value) || FONT_FAMILIES.test(value)) return { category: "type", on: true };
|
|
115
|
+
if (arbitrary) return { category: "type", on: refsToken(value) };
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (prefix === "leading") {
|
|
119
|
+
if (/^(?:none|tight|snug|normal|relaxed|loose|\d+)$/.test(value)) return { category: "type", on: true };
|
|
120
|
+
if (arbitrary) return { category: "type", on: refsToken(value) };
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
if (prefix === "tracking") {
|
|
124
|
+
if (/^(?:tighter|tight|normal|wide|wider|widest)$/.test(value)) return { category: "type", on: true };
|
|
125
|
+
if (arbitrary) return { category: "type", on: refsToken(value) };
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
if (prefix === "text") {
|
|
129
|
+
if (TEXT_SIZES.test(value)) return { category: "type", on: true };
|
|
130
|
+
if (arbitrary) {
|
|
131
|
+
const body = inner(value.replace(/^\(/, "[").replace(/\)$/, "]"));
|
|
132
|
+
if (COLOR_LITERAL.test(body)) return { category: "color", on: false };
|
|
133
|
+
if (LENGTH_LITERAL.test(body)) return { category: "type", on: false };
|
|
134
|
+
return { category: LENGTH_LITERAL.test(body) ? "type" : "color", on: refsToken(value) };
|
|
135
|
+
}
|
|
136
|
+
if (TEXT_NOT_COLOR.test(value)) return null;
|
|
137
|
+
// fall through to color
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ---- spacing ---------------------------------------------------------------------------------------------------
|
|
141
|
+
if (SPACING_PREFIXES.has(prefix) || POSITION_PREFIXES.has(prefix)) {
|
|
142
|
+
const positional = POSITION_PREFIXES.has(prefix);
|
|
143
|
+
if (arbitrary) {
|
|
144
|
+
const body = inner(value);
|
|
145
|
+
if (refsToken(value)) return { category: "spacing", on: true };
|
|
146
|
+
if (LENGTH_LITERAL.test(body)) return { category: "spacing", on: false };
|
|
147
|
+
return null; // calc(), percentages of something else: not decidable here
|
|
148
|
+
}
|
|
149
|
+
if (SPACING_STEPS.has(value)) return { category: "spacing", on: true };
|
|
150
|
+
if (/^\d+(?:\.\d+)?$/.test(value)) return positional ? null : { category: "spacing", on: false };
|
|
151
|
+
return null; // auto, full, fractions, screen
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ---- color -----------------------------------------------------------------------------------------------------
|
|
155
|
+
if (COLOR_PREFIXES.has(prefix)) {
|
|
156
|
+
const notColor = NOT_A_COLOR[prefix];
|
|
157
|
+
if (notColor && notColor.test(value)) return null;
|
|
158
|
+
const color = value.replace(/\/(?:\d+|\[[^\]]+\])$/, ""); // drop an opacity modifier
|
|
159
|
+
if (color === "" || NEUTRAL_COLOR_VALUES.test(color)) return null;
|
|
160
|
+
if (color.startsWith("[") || color.startsWith("(")) {
|
|
161
|
+
if (COLOR_LITERAL.test(inner(color))) return { category: "color", on: false };
|
|
162
|
+
if (refsToken(color)) return { category: "color", on: true };
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
if (PALETTE_RE.test(color) || color === "white" || color === "black") return { category: "color", on: false };
|
|
166
|
+
if (/^[a-z][a-z0-9-]*$/.test(color)) return { category: "color", on: true };
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const STRING_LITERAL = /(["'`])((?:\\[\s\S]|(?!\1)[^\\])*)\1/g;
|
|
172
|
+
const HEX_IN_CODE = /(?<![\w&])#(?:[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?|[0-9a-fA-F]{3})(?![\w-])/g;
|
|
173
|
+
|
|
174
|
+
const emptyCounts = () => Object.fromEntries(CATEGORIES.map((c) => [c, { on: 0, off: 0 }]));
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Score one source file. Returns the counts per category and the off-system decisions with their line numbers.
|
|
178
|
+
*/
|
|
179
|
+
export function scoreSource(source) {
|
|
180
|
+
const counts = emptyCounts();
|
|
181
|
+
const offenders = [];
|
|
182
|
+
const lines = source.split("\n");
|
|
183
|
+
const lineStart = [];
|
|
184
|
+
let pos = 0;
|
|
185
|
+
for (const l of lines) {
|
|
186
|
+
lineStart.push(pos);
|
|
187
|
+
pos += l.length + 1;
|
|
188
|
+
}
|
|
189
|
+
const lineOf = (index) => {
|
|
190
|
+
let lo = 0;
|
|
191
|
+
let hi = lineStart.length - 1;
|
|
192
|
+
while (lo < hi) {
|
|
193
|
+
const mid = Math.ceil((lo + hi) / 2);
|
|
194
|
+
if (lineStart[mid] <= index) lo = mid;
|
|
195
|
+
else hi = mid - 1;
|
|
196
|
+
}
|
|
197
|
+
return lo + 1;
|
|
198
|
+
};
|
|
199
|
+
const allowed = (line) => /allow-off-system/.test(lines[line - 1] ?? "") || /allow-off-system/.test(lines[line - 2] ?? "");
|
|
200
|
+
const record = (category, on, line, what) => {
|
|
201
|
+
if (on) counts[category].on++;
|
|
202
|
+
else if (!allowed(line)) {
|
|
203
|
+
counts[category].off++;
|
|
204
|
+
offenders.push({ category, line, what });
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// Hex colors written straight into code or a style object (outside class strings handled below).
|
|
209
|
+
for (const m of source.matchAll(HEX_IN_CODE)) {
|
|
210
|
+
const line = lineOf(m.index);
|
|
211
|
+
const text = lines[line - 1] ?? "";
|
|
212
|
+
if (/^\s*(?:\/\/|\*|\/\*)/.test(text) || /\b(?:href|id|src)=/.test(text) || /\[#[0-9a-fA-F]+\]/.test(text)) continue;
|
|
213
|
+
record("color", false, line, m[0]);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
for (const m of source.matchAll(STRING_LITERAL)) {
|
|
217
|
+
const body = m[2].replace(/\$\{[^}]*\}/g, " ");
|
|
218
|
+
if (!/\s|-/.test(body) && body.length < 3) continue;
|
|
219
|
+
let offset = 0;
|
|
220
|
+
for (const token of body.split(/(\s+)/)) {
|
|
221
|
+
if (token.trim()) {
|
|
222
|
+
const c = classifyToken(token);
|
|
223
|
+
if (c) record(c.category, c.on, lineOf(m.index + 1 + offset), token);
|
|
224
|
+
}
|
|
225
|
+
offset += token.length;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return { counts, offenders };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Add `b`'s counts into `a`. */
|
|
232
|
+
export function addCounts(a, b) {
|
|
233
|
+
for (const c of CATEGORIES) {
|
|
234
|
+
a[c].on += b[c].on;
|
|
235
|
+
a[c].off += b[c].off;
|
|
236
|
+
}
|
|
237
|
+
return a;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Percentage on-system for a { on, off } pair, or null when nothing in that category was decided. */
|
|
241
|
+
export function percent({ on, off }) {
|
|
242
|
+
const total = on + off;
|
|
243
|
+
return total === 0 ? null : Math.round((on / total) * 1000) / 10;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function overall(counts) {
|
|
247
|
+
const t = CATEGORIES.reduce((s, c) => ({ on: s.on + counts[c].on, off: s.off + counts[c].off }), { on: 0, off: 0 });
|
|
248
|
+
return { ...t, percent: percent(t) };
|
|
249
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Seeded randomness for dealing, so a deal can be repeated. A small PRNG (mulberry32). */
|
|
2
|
+
export function rng(seed) {
|
|
3
|
+
let a = seed >>> 0;
|
|
4
|
+
return () => {
|
|
5
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
6
|
+
let t = a;
|
|
7
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
8
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
9
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Shuffle a copy with the given random source. */
|
|
14
|
+
export function shuffle(list, random) {
|
|
15
|
+
const a = [...list];
|
|
16
|
+
for (let i = a.length - 1; i > 0; i--) {
|
|
17
|
+
const j = Math.floor(random() * (i + 1));
|
|
18
|
+
[a[i], a[j]] = [a[j], a[i]];
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
}
|
|
22
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const REQUIRED_HEADINGS: string[]
|
|
2
|
+
export function slugify(text: string): string
|
|
3
|
+
export function parseFrontMatter(source: string): { data: Record<string, string>; body: string }
|
|
4
|
+
export interface SpecHeading { level: number; title: string; slug: string; line: number }
|
|
5
|
+
export function parseHeadings(body: string): SpecHeading[]
|
|
6
|
+
export function sectionText(body: string, title: string): string | null
|
|
7
|
+
export function parseTable(text: string): Record<string, string>[]
|
|
8
|
+
export interface InventoryRow {
|
|
9
|
+
element: string
|
|
10
|
+
source: string
|
|
11
|
+
built: "yes" | "deferred" | "dropped" | "unmarked"
|
|
12
|
+
notes: string
|
|
13
|
+
view: string | null
|
|
14
|
+
approvedBy: string | null
|
|
15
|
+
approvedOn: string | null
|
|
16
|
+
}
|
|
17
|
+
export interface SpecAnalysis {
|
|
18
|
+
frontMatter: Record<string, string>
|
|
19
|
+
headings: SpecHeading[]
|
|
20
|
+
inventory: InventoryRow[]
|
|
21
|
+
questions: { text: string; owner: string | null }[]
|
|
22
|
+
problems: string[]
|
|
23
|
+
}
|
|
24
|
+
export function analyzeSpec(source: string): SpecAnalysis
|
|
25
|
+
export function linkInventoryViews(body: string): string
|