@designesy/score 0.8.1 → 0.9.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @designesy/score
2
2
 
3
- Design quality gate for AI-generated UI: score any URL on 44 deterministic checks, A–F grade. This is the standalone engine: it fetches a URL, extracts CSS + `:root` tokens, and runs every check that needs no browser locally, with **no Designesy server required**; the browser checks return MANUAL. No required dependencies.
3
+ Design quality gate for AI-generated UI: score any URL on 45 deterministic checks, A–F grade. This is the standalone engine: it fetches a URL, extracts CSS + `:root` tokens, and runs every check that needs no browser locally, with **no Designesy server required**; the browser checks return MANUAL. No required dependencies.
4
4
 
5
5
  ## Install
6
6
 
@@ -54,7 +54,7 @@ console.log(result.fail); // 3
54
54
  console.log(result.checks); // [{ id: 'v01', status: 'PASS', detail: '...' }, ...]
55
55
  ```
56
56
 
57
- ## The 44 checks
57
+ ## The 45 checks
58
58
 
59
59
  | Category | Checks | Weight |
60
60
  |---|---|---|
@@ -85,7 +85,7 @@ Plus 12 anti-slop deductions (S1 to S12) and 7 originality lifts (O1 to O7).
85
85
 
86
86
  ## Scope system
87
87
 
88
- - **contract** (default for designesy.org): All 44 checks active. Absence = WARN/FAIL.
88
+ - **contract** (default for designesy.org): All 45 checks active. Absence = WARN/FAIL.
89
89
  - **universal** (default for external sites): Optional features SKIP on absence instead of penalizing.
90
90
 
91
91
  Auto-detect: `designesy.org` → contract, everything else → universal.
package/dist/cli.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * @designesy/score CLI — Score a URL against the 44-check Designesy engine.
3
+ * @designesy/score CLI — Score a URL against the 45-check Designesy engine.
4
4
  *
5
- * Runs the full 44-check scoring engine locally — no server required.
5
+ * Runs the full 45-check scoring engine locally — no server required.
6
6
  * Fetches the target URL, extracts CSS + :root tokens, runs all checks,
7
7
  * and prints a formatted report. Exits with code 1 when the score drops
8
8
  * below --min-score or the grade drops below --min-grade.
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * @designesy/score CLI — Score a URL against the 44-check Designesy engine.
3
+ * @designesy/score CLI — Score a URL against the 45-check Designesy engine.
4
4
  *
5
- * Runs the full 44-check scoring engine locally — no server required.
5
+ * Runs the full 45-check scoring engine locally — no server required.
6
6
  * Fetches the target URL, extracts CSS + :root tokens, runs all checks,
7
7
  * and prints a formatted report. Exits with code 1 when the score drops
8
8
  * below --min-score or the grade drops below --min-grade.
@@ -98,10 +98,10 @@ function formatReport(result, url) {
98
98
  }
99
99
  function printUsage() {
100
100
  console.log(`
101
- designesy-score: Score a URL against the 44-check Designesy engine.
101
+ designesy-score: Score a URL against the 45-check Designesy engine.
102
102
 
103
103
  Runs locally: no server required. Fetches the URL, extracts CSS + tokens,
104
- and runs all 44 checks in one process.
104
+ and runs all 45 checks in one process.
105
105
 
106
106
  Usage:
107
107
  designesy-score <url> [options]
@@ -192,7 +192,7 @@ async function main() {
192
192
  // Progress and the gate verdict go to stderr: stdout carries only the
193
193
  // result, so --json and the JSON formats pipe straight into a parser.
194
194
  if (!args.quiet) {
195
- console.error(`${DIM}Scoring ${url} locally (44-check engine, scope=${scope || 'auto'})…${RESET}`);
195
+ console.error(`${DIM}Scoring ${url} locally (45-check engine, scope=${scope || 'auto'})…${RESET}`);
196
196
  }
197
197
  let result;
198
198
  try {
package/dist/engine.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @designesy/score — 44-check design-contract scoring engine.
2
+ * @designesy/score — 45-check design-contract scoring engine.
3
3
  *
4
4
  * Scores a URL against the Designesy design-system contract: fetches the page,
5
- * extracts CSS + :root tokens, runs 44 checks (41 scored, 3 that need a
5
+ * extracts CSS + :root tokens, runs 45 checks (42 scored, 3 that need a
6
6
  * browser), computes a weighted score (0-100), assigns a letter grade (A-F),
7
7
  * and applies anti-slop deductions + originality lifts.
8
8
  *
@@ -159,7 +159,7 @@ export declare function scoreFromParts(input: ScorePartsInput): Promise<ScoreRes
159
159
  * the site served v0.4.3; test/engine-1-2-0.test.mjs now reads the site's
160
160
  * contract source and fails when the two differ.
161
161
  */
162
- export declare const CONTRACT_VERSION = "v0.4.5";
162
+ export declare const CONTRACT_VERSION = "v0.4.6";
163
163
  /**
164
164
  * The one verdict rule, shared by every emission format.
165
165
  *
package/dist/engine.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @designesy/score — 44-check design-contract scoring engine.
2
+ * @designesy/score — 45-check design-contract scoring engine.
3
3
  *
4
4
  * Scores a URL against the Designesy design-system contract: fetches the page,
5
- * extracts CSS + :root tokens, runs 44 checks (41 scored, 3 that need a
5
+ * extracts CSS + :root tokens, runs 45 checks (42 scored, 3 that need a
6
6
  * browser), computes a weighted score (0-100), assigns a letter grade (A-F),
7
7
  * and applies anti-slop deductions + originality lifts.
8
8
  *
@@ -481,10 +481,11 @@ const REMEDIATION = {
481
481
  v43: 'Express UI states as semantic color roles: --ok/--success (verification pass), --warn/--warning (caution), --error/--danger (failure), --info (notice). The contract ships --ok, --warn, and --error for exactly this. Status colors named by state let components consume meaning (a score badge, a form error, and a toast all read the same token) and stay legible when the palette evolves.',
482
482
  v44: 'Give each status hue a text token for words and keep the hue itself for marks. A color that marks a state (a dot, a bar, a tint) needs 3:1, while the word for that state needs 4.5:1 (3:1 at 24px, or 18.66px bold) in every theme the site declares. Mix the hue toward your ink for text, for example --warn-ink: color-mix(in oklab, var(--warn) 70%, var(--ink)), measure it on the page and on each surface it sits on in every theme, and paint status words with it.',
483
483
  v45: 'Let every entrance that starts invisible run to its end when motion is paused. Under the pause rule, give one-shot entrances whose first keyframe is opacity 0 a negative delay longer than the animation, for example html[data-motion="paused"] :is(.fade-up, .reveal) { animation-delay: -3600s !important; }, or remove them with animation: none. Loops can stay held. Test by pausing motion and reloading: every page should still show its content.',
484
+ v46: 'Size text from the type scale. Use a type token (font-size: var(--text-body)) or a size that sits on the scale your tokens declare; keep deliberate fluid type in clamp() with a viewport or container unit, and keep its lower bound at or above the smallest type token. A static size between two steps reads as a one-off and drifts the rhythm the scale exists to hold.',
484
485
  v34: 'If the page hosts an AI chatbot or agent, tell people they are talking to an AI no later than their first interaction, in a form assistive technology announces. EU AI Act Article 50(1), which applies from 2026-08-02, places this duty on the provider of the AI system (the organisation that develops it and places it on the market or puts it into service under its own name); it does not apply where the AI nature is obvious from the context, and Article 50(5) asks for the information to be clear and accessible. The check reads any one of: visible "AI assistant" or "Chatbot" text, aria-label="AI assistant" on the chat container, or a data-ai-disclosure attribute on the widget. A live chat answered by people needs no AI disclosure: if the check flagged one for review, confirm who answers. US laws differ in scope: California\'s bot-disclosure law (SB 1001, Bus. & Prof. Code §§17940-17943) covers bots that mislead people about being bots to drive a sale or influence a vote; Colorado SB 24-205 was repealed and re-enacted by SB 26-189 (signed 2026-05-14, obligations from 2027-01-01), which governs automated decision-making in consequential decisions. This is not legal advice.',
485
486
  v35: 'Add a forced-colors readiness block: @media (forced-colors: active) { ... } with forced-color-adjust: none on elements that must preserve brand identity (logos, charts, semantic-color indicators). Windows High Contrast Mode and Chrome forced-colors recolor the page: without this media query, critical UI becomes illegible. Also ensure borders/outlines use currentColor or system colors so they adapt. Test with Windows HCM (Settings > Accessibility > Contrast themes).',
486
487
  v36: 'Remove UTS #39 confusable characters from CSS identifiers and token names. Confusables are Unicode characters from different scripts (Cyrillic, Greek, fullwidth) that look identical to ASCII letters; Cyrillic а (U+0430), for example, looks like Latin a (U+0061). In token names they enable shadowing attacks (--соlor-bg with Cyrillic с vs --color-bg). Audit all custom property names, class names, and url() paths for non-ASCII characters using a Unicode confusable detector. Provenance: Unicode Technical Standard #39, Unicode 16.0.0. Designesy is the only design verification engine that checks this surface.',
487
- v37: 'Publish a DESIGN.md file at /DESIGN.md in your repo root and serve it publicly. Google\'s @google/design.md CLI (v0.4.0, Apache-2.0) validates the file format: 11 lint rules covering broken token refs, missing primary colors, WCAG contrast, orphaned tokens, section order, and more. Designesy integrates Google\'s linter as the spec layer and runs its own 44-check contract verification as the layer above. Install the CLI: npm install -g @google/design.md. Lint locally: npx @google/design.md lint DESIGN.md. Export to W3C DTCG: npx @google/design.md export --format dtcg DESIGN.md. Note: DESIGN.md uses sRGB hex only; for OKLCH/Display P3 color spaces, use the W3C DTCG JSON format directly.',
488
+ v37: 'Publish a DESIGN.md file at /DESIGN.md in your repo root and serve it publicly. Google\'s @google/design.md CLI (v0.4.0, Apache-2.0) validates the file format: 11 lint rules covering broken token refs, missing primary colors, WCAG contrast, orphaned tokens, section order, and more. Designesy integrates Google\'s linter as the spec layer and runs its own 45-check contract verification as the layer above. Install the CLI: npm install -g @google/design.md. Lint locally: npx @google/design.md lint DESIGN.md. Export to W3C DTCG: npx @google/design.md export --format dtcg DESIGN.md. Note: DESIGN.md uses sRGB hex only; for OKLCH/Display P3 color spaces, use the W3C DTCG JSON format directly.',
488
489
  v38: 'Rewrite button labels to start with a verb or recognized command. NN/g: "Lead with verbs or verb phrases that clearly outline what will happen after the command is selected." Use "Save changes" not "Changes", "Delete file" not "File". Recognized commands: Save, Cancel, Delete, Edit, Share, Close, Back, Next, etc. This is a WARN (heuristic): review flagged buttons manually.',
489
490
  v39: 'Remove trailing periods from button text, labels, and tab text. Microsoft Fluent: "Don\'t end text for buttons, radio buttons, labels, or checkboxes with a period." Periods are for full sentences in tooltips, error messages, and dialog bodies only.',
490
491
  v40: 'Replace non-descriptive link text with destination-revealing text. WCAG 2.4.4 Link Purpose: link text should describe the destination. Use "Read the typography guide" not "Click here". Use "View the leaderboard" not "Learn more". NN/g: non-descriptive links force users to read surrounding context to understand the destination.',
@@ -2842,6 +2843,143 @@ function isDocumentScope(compound) {
2842
2843
  return simple.every((s) => s.startsWith('.') || s.startsWith('['))
2843
2844
  && simple.some((s) => V45_TOGGLE_ATTR.test(s) || V45_TOGGLE_CLASS.test(s));
2844
2845
  }
2846
+ // v46 — Type sizes come from the scale (engine 1.4.0).
2847
+ //
2848
+ // v16 asks that sizes be written in rem; it cannot tell a rem that sits on the
2849
+ // type scale from one that sits between steps, so a page can pass v16 while its
2850
+ // sizes drift off the scale its own tokens declare. v46 reads the scale from the
2851
+ // page itself: the :root type-size tokens (a name such as --text-*, --font-size-*,
2852
+ // --fs-* or --type-*, whose value resolves to a static rem or px length; colour
2853
+ // tokens named --text-muted never resolve to a length, so they never count). The
2854
+ // steps are every token value plus the token ratio (the median of consecutive
2855
+ // token ratios) extended four steps below and ten above the token nearest 16px.
2856
+ // The floor is the smallest type token.
2857
+ //
2858
+ // Fluid type is a deliberate design move, so a clamp(), min() or max() that
2859
+ // moves with a viewport or container unit is accepted as written; only its lower
2860
+ // bound is held to the floor. Relative sizes (em, %, inherit, keywords) follow
2861
+ // their parent, not the global scale, and are not judged. A static rem or px
2862
+ // size is judged: off the scale when it sits more than 2.5% from every step,
2863
+ // below the floor when it is smaller than the smallest type token.
2864
+ //
2865
+ // WARN only: an off-scale size is a hygiene finding, not a broken page.
2866
+ const V46_ITEM = 'Type sizes come from the scale';
2867
+ const V46_TOLERANCE = 0.025;
2868
+ const V46_FLUID = /(?:^|[^a-z-])(?:[sld]?v[wh]|v[ib]|vmin|vmax|cq[iwhb]|cqmin|cqmax)\b/i;
2869
+ function v46StaticPx(value) {
2870
+ const m = value.trim().match(/^(\d*\.?\d+)(rem|px)$/i);
2871
+ if (!m)
2872
+ return null;
2873
+ return parseFloat(m[1]) * (m[2].toLowerCase() === 'rem' ? 16 : 1);
2874
+ }
2875
+ function v46TypeScale(tokens) {
2876
+ const values = [];
2877
+ for (const [name, raw] of Object.entries(tokens)) {
2878
+ if (!/^--(?:text|font-size|fs|type)-[\w-]+$/i.test(name))
2879
+ continue;
2880
+ const px = v46StaticPx(resolveVar(raw, tokens));
2881
+ if (px !== null && px > 0)
2882
+ values.push(px);
2883
+ }
2884
+ const unique = [...new Set(values.map((v) => Math.round(v * 1000) / 1000))].sort((a, b) => a - b);
2885
+ if (unique.length < 3)
2886
+ return null;
2887
+ const ratios = [];
2888
+ for (let i = 1; i < unique.length; i++) {
2889
+ const r = unique[i] / unique[i - 1];
2890
+ if (r >= 1.05 && r <= 1.7)
2891
+ ratios.push(r);
2892
+ }
2893
+ ratios.sort((a, b) => a - b);
2894
+ const ratio = ratios.length ? ratios[Math.floor(ratios.length / 2)] : 1.25;
2895
+ const base = unique.reduce((best, v) => (Math.abs(v - 16) < Math.abs(best - 16) ? v : best), unique[0]);
2896
+ const steps = new Set(unique);
2897
+ for (let n = -4; n <= 10; n++)
2898
+ steps.add(Math.round(base * Math.pow(ratio, n) * 1000) / 1000);
2899
+ return { steps: [...steps].sort((a, b) => a - b), floor: unique[0], ratio, count: unique.length };
2900
+ }
2901
+ /** Lower bound in px of a fluid size: clamp()'s first argument, or the largest static argument of max(). */
2902
+ function v46FluidFloor(value) {
2903
+ const fn = value.trim().match(/^(clamp|max)\((.*)\)$/i);
2904
+ if (!fn)
2905
+ return null;
2906
+ const args = splitCssTopLevel(fn[2], ',').map((a) => v46StaticPx(a));
2907
+ if (fn[1].toLowerCase() === 'clamp')
2908
+ return args.length === 3 ? args[0] : null;
2909
+ const statics = args.filter((a) => a !== null);
2910
+ return statics.length ? Math.max(...statics) : null;
2911
+ }
2912
+ function v46Selector(css, at) {
2913
+ const open = css.lastIndexOf('{', at);
2914
+ if (open < 0)
2915
+ return '';
2916
+ const start = Math.max(css.lastIndexOf('}', open), css.lastIndexOf(';', open), css.lastIndexOf('{', open - 1)) + 1; // stop at an enclosing @media brace too
2917
+ return css.slice(start, open).replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/\s+/g, ' ').trim().slice(0, 80);
2918
+ }
2919
+ function checkTypeScale(css, tokens) {
2920
+ const scale = v46TypeScale(tokens);
2921
+ if (!scale) {
2922
+ return { id: 'v46', item: V46_ITEM, category: 'cadence', status: 'SKIP', detail: 'fewer than 3 type-size tokens in :root: no scale to measure against' };
2923
+ }
2924
+ const { steps, floor, ratio } = scale;
2925
+ const nearest = (px) => steps.reduce((best, s) => (Math.abs(s - px) < Math.abs(best - px) ? s : best), steps[0]);
2926
+ const onScale = (px) => steps.some((s) => Math.abs(px - s) / s <= V46_TOLERANCE);
2927
+ const below = (px) => px < floor * (1 - V46_TOLERANCE);
2928
+ const findings = [];
2929
+ const seen = new Set(); // one finding per rule: a bundle repeats rules across @media copies
2930
+ const add = (f) => {
2931
+ const key = `${f.selector}|${f.value}|${f.issue}`;
2932
+ if (!seen.has(key)) {
2933
+ seen.add(key);
2934
+ findings.push(f);
2935
+ }
2936
+ };
2937
+ let judged = 0;
2938
+ let fluid = 0;
2939
+ const re = /font-size\s*:\s*([^;}]+)/gi;
2940
+ let m;
2941
+ while ((m = re.exec(css)) !== null) {
2942
+ const written = m[1].replace(/\/\*[\s\S]*?\*\//g, '').replace(/!important/i, '').trim();
2943
+ const value = resolveVar(written, tokens);
2944
+ if (/^var\(/i.test(value))
2945
+ continue; // an alias the token table cannot resolve
2946
+ if (/^(?:clamp|min|max)\(/i.test(value) && V46_FLUID.test(value)) {
2947
+ fluid++;
2948
+ const low = v46FluidFloor(value);
2949
+ if (low !== null && below(low)) {
2950
+ add({ selector: v46Selector(css, m.index), value: written, px: Math.round(low * 100) / 100, issue: 'fluid minimum below the floor', nearest: floor });
2951
+ }
2952
+ continue;
2953
+ }
2954
+ const px = v46StaticPx(value);
2955
+ if (px === null)
2956
+ continue; // em, %, keywords, calc(): relative or not static
2957
+ judged++;
2958
+ if (below(px)) {
2959
+ add({ selector: v46Selector(css, m.index), value: written, px: Math.round(px * 100) / 100, issue: 'below the floor', nearest: floor });
2960
+ }
2961
+ else if (!onScale(px)) {
2962
+ add({ selector: v46Selector(css, m.index), value: written, px: Math.round(px * 100) / 100, issue: 'off the scale', nearest: nearest(px) });
2963
+ }
2964
+ }
2965
+ const scaleText = `${steps.length}-step scale (ratio ${ratio.toFixed(3)}, ${scale.count} type tokens, floor ${floor}px)`;
2966
+ if (judged + fluid === 0) {
2967
+ return { id: 'v46', item: V46_ITEM, category: 'cadence', status: 'SKIP', detail: `no static or fluid font sizes outside the tokens to measure against the ${scaleText}` };
2968
+ }
2969
+ const offScale = findings.filter((f) => f.issue === 'off the scale').length;
2970
+ const underFloor = findings.length - offScale;
2971
+ if (findings.length === 0) {
2972
+ return { id: 'v46', item: V46_ITEM, category: 'cadence', status: 'PASS', detail: `${judged} static and ${fluid} fluid sizes sit on the ${scaleText}` };
2973
+ }
2974
+ return {
2975
+ id: 'v46', item: V46_ITEM, category: 'cadence', status: 'WARN',
2976
+ detail: `${offScale} static size(s) off the ${scaleText} and ${underFloor} below its floor, of ${judged} static and ${fluid} fluid sizes measured`,
2977
+ evidence: {
2978
+ findings: findings.slice(0, 20).map((f) => ({ selector: f.selector, value: f.value, px: f.px, issue: f.issue, nearest: f.nearest })),
2979
+ truncated: Math.max(0, findings.length - 20),
2980
+ },
2981
+ };
2982
+ }
2845
2983
  function checkPausedEntrances(css) {
2846
2984
  const ID = 'v45';
2847
2985
  const ITEM = 'Pausing motion keeps content visible';
@@ -4340,6 +4478,7 @@ export async function scoreFromParts(input) {
4340
4478
  checkNoAllCaps(html),
4341
4479
  checkStatusTextContrast(css),
4342
4480
  checkPausedEntrances(css),
4481
+ checkTypeScale(css, rawTokens),
4343
4482
  ];
4344
4483
  // v37 is async — added after the synchronous checks array
4345
4484
  //
@@ -4835,7 +4974,7 @@ export async function scoreFromParts(input) {
4835
4974
  * the site served v0.4.3; test/engine-1-2-0.test.mjs now reads the site's
4836
4975
  * contract source and fails when the two differ.
4837
4976
  */
4838
- export const CONTRACT_VERSION = 'v0.4.5';
4977
+ export const CONTRACT_VERSION = 'v0.4.6';
4839
4978
  /**
4840
4979
  * The one verdict rule, shared by every emission format.
4841
4980
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@designesy/score",
3
- "version": "0.8.1",
4
- "description": "Design quality gate for AI-generated UI: score any URL on 44 deterministic checks, A–F grade. Runs locally; browser checks return MANUAL. No required dependencies.",
3
+ "version": "0.9.0",
4
+ "description": "Design quality gate for AI-generated UI: score any URL on 45 deterministic checks, A–F grade. Runs locally; browser checks return MANUAL. No required dependencies.",
5
5
  "license": "MIT",
6
6
  "author": "Designesy <hello@designesy.org>",
7
7
  "homepage": "https://www.designesy.org/score",