@behavioral-agentic-design-system/core 0.42.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/LICENSE +21 -0
- package/package.json +25 -9
- package/scripts/a11y-lint.cjs +25 -1
- package/scripts/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -0
- package/scripts/health-report.mjs +20 -14
- 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/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/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/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +734 -0
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +160 -44
- 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/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 +133 -128
- 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/autocomplete.tsx +1 -1
- package/src/components/ui/color-picker.tsx +20 -4
- 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 +18 -4
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/number-input.tsx +28 -5
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/search-input.tsx +1 -1
- package/src/components/ui/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- 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 +13 -1
- 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/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- package/src/stories/Autocomplete.stories.tsx +2 -0
- package/src/stories/Canvas.stories.tsx +45 -0
- package/src/stories/ColorPicker.stories.tsx +40 -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 +9 -3
- package/src/stories/InlineEdit.stories.tsx +106 -0
- package/src/stories/MarkdownPreview.stories.tsx +53 -0
- package/src/stories/MonthPicker.stories.tsx +21 -0
- package/src/stories/NumberInput.stories.tsx +25 -0
- package/src/stories/OtpInput.stories.tsx +110 -0
- package/src/stories/PhoneInput.stories.tsx +127 -0
- package/src/stories/SearchInput.stories.tsx +2 -0
- package/src/stories/TagsInput.stories.tsx +2 -0
- package/src/stories/Timer.stories.tsx +26 -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 +22 -16
- package/src/tokens.json +82 -54
|
@@ -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
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prototype spec parser. One source for the rules that read `spec.md`:
|
|
3
|
+
* the `bads-check-spec` gate (Node) and the canvas Spec frame (React, through
|
|
4
|
+
* `src/lib/spec-parse.ts`). Plain ESM with no dependencies so both can import it.
|
|
5
|
+
*
|
|
6
|
+
* A spec is markdown with a small front matter block and fixed `##` headings.
|
|
7
|
+
* See templates/prototype-repo/spec.template.md.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const REQUIRED_HEADINGS = [
|
|
11
|
+
"Audience and problem",
|
|
12
|
+
"What it does",
|
|
13
|
+
"Element inventory",
|
|
14
|
+
"States",
|
|
15
|
+
"Decisions",
|
|
16
|
+
"Open questions",
|
|
17
|
+
"Out of scope",
|
|
18
|
+
"Handoff",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
const BUILT_VALUES = new Set(["yes", "deferred", "dropped"])
|
|
22
|
+
const APPROVER = /approved by\s+([^\s<][^\n]*?)\s+on\s+(\d{4}-\d{2}-\d{2})/i
|
|
23
|
+
const PLACEHOLDER = /<[A-Za-z][^>\n]*>/
|
|
24
|
+
|
|
25
|
+
/** Heading text to an anchor id. GitHub-style: lowercase, words joined by hyphens. */
|
|
26
|
+
export function slugify(text) {
|
|
27
|
+
return String(text)
|
|
28
|
+
.toLowerCase()
|
|
29
|
+
.replace(/[`*_~]/g, "")
|
|
30
|
+
.replace(/[^a-z0-9\s-]/g, "")
|
|
31
|
+
.trim()
|
|
32
|
+
.replace(/\s+/g, "-")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Split a leading `---` block into key/value pairs. Values are plain strings. */
|
|
36
|
+
export function parseFrontMatter(source) {
|
|
37
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(source)
|
|
38
|
+
if (!match) return { data: {}, body: source }
|
|
39
|
+
const data = {}
|
|
40
|
+
for (const line of match[1].split(/\r?\n/)) {
|
|
41
|
+
const kv = /^([A-Za-z][\w-]*)\s*:\s*(.*)$/.exec(line)
|
|
42
|
+
if (kv) data[kv[1]] = kv[2].trim()
|
|
43
|
+
}
|
|
44
|
+
return { data, body: source.slice(match[0].length) }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function stripComments(text) {
|
|
48
|
+
return text.replace(/<!--[\s\S]*?-->/g, "")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Level 1 to 6 headings outside code fences, in order. */
|
|
52
|
+
export function parseHeadings(body) {
|
|
53
|
+
const out = []
|
|
54
|
+
let fenced = false
|
|
55
|
+
body.split(/\r?\n/).forEach((line, index) => {
|
|
56
|
+
if (/^\s*```/.test(line)) fenced = !fenced
|
|
57
|
+
if (fenced) return
|
|
58
|
+
const m = /^(#{1,6})\s+(.+?)\s*#*\s*$/.exec(line)
|
|
59
|
+
if (m) out.push({ level: m[1].length, title: m[2], slug: slugify(m[2]), line: index })
|
|
60
|
+
})
|
|
61
|
+
return out
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The text under a `##` heading, up to the next `##` or `#`. Null when absent. */
|
|
65
|
+
export function sectionText(body, title) {
|
|
66
|
+
const lines = body.split(/\r?\n/)
|
|
67
|
+
const heads = parseHeadings(body).filter((h) => h.level <= 2)
|
|
68
|
+
const at = heads.findIndex((h) => h.level === 2 && h.title.toLowerCase() === title.toLowerCase())
|
|
69
|
+
if (at === -1) return null
|
|
70
|
+
const end = heads[at + 1] ? heads[at + 1].line : lines.length
|
|
71
|
+
return lines.slice(heads[at].line + 1, end).join("\n")
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** GitHub-flavored table to rows of objects keyed by lowercase header. */
|
|
75
|
+
export function parseTable(text) {
|
|
76
|
+
const rows = text
|
|
77
|
+
.split(/\r?\n/)
|
|
78
|
+
.filter((l) => l.trim().startsWith("|"))
|
|
79
|
+
.map((l) => l.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((c) => c.trim()))
|
|
80
|
+
if (rows.length < 2) return []
|
|
81
|
+
const header = rows[0].map((h) => h.toLowerCase())
|
|
82
|
+
return rows
|
|
83
|
+
.slice(2)
|
|
84
|
+
.map((cells) => Object.fromEntries(header.map((h, i) => [h, cells[i] ?? ""])))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function bullets(text) {
|
|
88
|
+
return text
|
|
89
|
+
.split(/\r?\n/)
|
|
90
|
+
.map((l) => /^\s*[-*]\s+(.*)$/.exec(l))
|
|
91
|
+
.filter(Boolean)
|
|
92
|
+
.map((m) => m[1].trim())
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Read a spec and report what is wrong with it. `problems` lists every defect;
|
|
97
|
+
* the gate treats them as errors only for a prototype at review or later.
|
|
98
|
+
*/
|
|
99
|
+
export function analyzeSpec(source) {
|
|
100
|
+
const { data, body: raw } = parseFrontMatter(source)
|
|
101
|
+
const body = stripComments(raw)
|
|
102
|
+
const problems = []
|
|
103
|
+
|
|
104
|
+
for (const key of ["prototype", "path"]) {
|
|
105
|
+
if (!data[key]) problems.push(`front matter is missing \`${key}\``)
|
|
106
|
+
else if (PLACEHOLDER.test(data[key])) problems.push(`front matter \`${key}\` is still a placeholder`)
|
|
107
|
+
}
|
|
108
|
+
if (data.path && !["A", "B"].includes(data.path)) problems.push("front matter `path` must be A or B")
|
|
109
|
+
|
|
110
|
+
const headings = parseHeadings(body)
|
|
111
|
+
for (const title of REQUIRED_HEADINGS) {
|
|
112
|
+
if (!headings.some((h) => h.level === 2 && h.title.toLowerCase() === title.toLowerCase())) {
|
|
113
|
+
problems.push(`missing the \`## ${title}\` section`)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const inventoryText = sectionText(body, "Element inventory") ?? ""
|
|
118
|
+
const inventory = parseTable(inventoryText).map((row) => {
|
|
119
|
+
const built = (row.built ?? "").toLowerCase()
|
|
120
|
+
const approver = APPROVER.exec(row.notes ?? "")
|
|
121
|
+
return {
|
|
122
|
+
element: row.element ?? "",
|
|
123
|
+
source: row.source ?? "",
|
|
124
|
+
built: BUILT_VALUES.has(built) ? built : "unmarked",
|
|
125
|
+
notes: row.notes ?? "",
|
|
126
|
+
view: row.view || null,
|
|
127
|
+
approvedBy: approver ? approver[1] : null,
|
|
128
|
+
approvedOn: approver ? approver[2] : null,
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
if (inventory.length === 0 && sectionText(body, "Element inventory") !== null) {
|
|
132
|
+
problems.push("the element inventory has no rows")
|
|
133
|
+
}
|
|
134
|
+
for (const row of inventory) {
|
|
135
|
+
const label = row.element || "(blank element)"
|
|
136
|
+
if (row.built === "unmarked") problems.push(`inventory row "${label}" is not marked yes, deferred, or dropped`)
|
|
137
|
+
if ((row.built === "deferred" || row.built === "dropped") && !row.approvedBy) {
|
|
138
|
+
problems.push(`inventory row "${label}" is ${row.built} but names no approver ("Approved by <name> on YYYY-MM-DD")`)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const questionsText = sectionText(body, "Open questions") ?? ""
|
|
143
|
+
const questions = bullets(questionsText)
|
|
144
|
+
.filter((q) => !/^none\.?$/i.test(q))
|
|
145
|
+
.map((q) => {
|
|
146
|
+
const m = /^([^:<][^:]{0,40}):\s+(\S.*)$/.exec(q)
|
|
147
|
+
return { text: q, owner: m ? m[1].trim() : null }
|
|
148
|
+
})
|
|
149
|
+
for (const q of questions) {
|
|
150
|
+
if (!q.owner) problems.push(`open question has no owner: "${q.text}"`)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return { frontMatter: data, headings, inventory, questions, problems }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Turn each name in the inventory's `View` column into a `frame:` link, so the
|
|
158
|
+
* rendered Spec frame can pan the canvas to that frame. Leaves every other part of
|
|
159
|
+
* the markdown untouched. Rows with an empty View cell stay plain.
|
|
160
|
+
*/
|
|
161
|
+
export function linkInventoryViews(body) {
|
|
162
|
+
const lines = body.split(/\r?\n/)
|
|
163
|
+
const heads = parseHeadings(body).filter((h) => h.level <= 2)
|
|
164
|
+
const at = heads.findIndex((h) => h.level === 2 && h.title.toLowerCase() === "element inventory")
|
|
165
|
+
if (at === -1) return body
|
|
166
|
+
const end = heads[at + 1] ? heads[at + 1].line : lines.length
|
|
167
|
+
let viewCol = -1
|
|
168
|
+
let seenSeparator = false
|
|
169
|
+
for (let i = heads[at].line + 1; i < end; i++) {
|
|
170
|
+
const line = lines[i]
|
|
171
|
+
if (!line.trim().startsWith("|")) continue
|
|
172
|
+
const cells = line.trim().replace(/^\|/, "").replace(/\|$/, "").split("|")
|
|
173
|
+
if (viewCol === -1 && !seenSeparator) {
|
|
174
|
+
viewCol = cells.findIndex((c) => c.trim().toLowerCase() === "view")
|
|
175
|
+
continue
|
|
176
|
+
}
|
|
177
|
+
if (!seenSeparator) {
|
|
178
|
+
seenSeparator = true
|
|
179
|
+
continue
|
|
180
|
+
}
|
|
181
|
+
if (viewCol === -1 || viewCol >= cells.length) continue
|
|
182
|
+
const name = cells[viewCol].trim()
|
|
183
|
+
if (!name || name.startsWith("[")) continue
|
|
184
|
+
cells[viewCol] = ` [${name}](frame:${name}) `
|
|
185
|
+
lines[i] = "|" + cells.join("|") + "|"
|
|
186
|
+
}
|
|
187
|
+
return lines.join("\n")
|
|
188
|
+
}
|