ceulen 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +317 -12
- package/README.md +87 -91
- package/extensions/lib/advisor-marker.ts +33 -0
- package/extensions/lib/panel.ts +25 -2
- package/extensions/lib/rate.ts +24 -0
- package/extensions/lib/registry.ts +93 -7
- package/extensions/lib/tools.ts +47 -0
- package/extensions/lib/usage-store.ts +33 -0
- package/extensions/modules/advisor/commands/advisor.ts +244 -0
- package/extensions/modules/advisor/configPanel.ts +194 -0
- package/extensions/modules/advisor/index.ts +217 -0
- package/extensions/modules/advisor/lib/config.ts +248 -0
- package/extensions/modules/advisor/lib/emission-guard.ts +153 -0
- package/extensions/modules/advisor/lib/isolated-model.ts +160 -0
- package/extensions/modules/advisor/lib/model-picker.ts +47 -0
- package/extensions/modules/advisor/lib/watcher.ts +286 -0
- package/extensions/modules/advisor/test/compliance.test.ts +125 -0
- package/extensions/modules/advisor/test/config.test.ts +202 -0
- package/extensions/modules/advisor/test/configPanel.test.ts +223 -0
- package/extensions/modules/advisor/test/emission-guard.test.ts +201 -0
- package/extensions/modules/advisor/test/isolated-model.test.ts +311 -0
- package/extensions/modules/advisor/test/model-picker.test.ts +32 -0
- package/extensions/modules/advisor/test/module.test.ts +586 -0
- package/extensions/modules/advisor/test/watcher.test.ts +478 -0
- package/extensions/modules/classifier/configPanel.ts +104 -0
- package/extensions/modules/classifier/index.ts +297 -0
- package/extensions/modules/classifier/lib/settings.ts +95 -0
- package/extensions/modules/classifier/test/classifier.test.ts +475 -0
- package/extensions/modules/composer/index.ts +152 -3
- package/extensions/modules/composer/lib/footer.ts +119 -0
- package/extensions/modules/composer/lib/shapes.ts +265 -26
- package/extensions/modules/composer/test/editor.test.ts +1 -1
- package/extensions/modules/composer/test/footer.test.ts +96 -0
- package/extensions/modules/composer/test/module.test.ts +113 -11
- package/extensions/modules/composer/test/screen.test.ts +29 -1
- package/extensions/modules/composer/test/shapes.test.ts +224 -8
- package/extensions/modules/config/defaultTools.ts +96 -0
- package/extensions/modules/config/index.ts +147 -7
- package/extensions/modules/config/piSettings.ts +254 -69
- package/extensions/modules/config/test/defaultTools.test.ts +122 -0
- package/extensions/modules/config/test/menu.test.ts +64 -0
- package/extensions/modules/config/test/panel.test.ts +38 -23
- package/extensions/modules/config/test/piSettings.test.ts +130 -3
- package/extensions/modules/config/test/renderTools.test.ts +71 -0
- package/extensions/modules/config/test/tools.test.ts +146 -0
- package/extensions/modules/fff/index.ts +2094 -0
- package/extensions/modules/fff/lib/query.ts +129 -0
- package/extensions/modules/fff/test/index.test.ts +607 -0
- package/extensions/modules/fff/test/query.test.ts +71 -0
- package/extensions/modules/munin/configPanel.ts +105 -0
- package/extensions/modules/munin/index.ts +641 -0
- package/extensions/modules/munin/lib/helpers.ts +471 -0
- package/extensions/modules/munin/lib/retry.ts +20 -0
- package/extensions/modules/munin/lib/sdk.ts +218 -0
- package/extensions/modules/munin/test/config.test.ts +168 -0
- package/extensions/modules/munin/test/configPanel.test.ts +161 -0
- package/extensions/modules/munin/test/extension.test.ts +224 -0
- package/extensions/modules/munin/test/helpers.test.ts +523 -0
- package/extensions/modules/munin/test/retry.test.ts +145 -0
- package/extensions/modules/munin/test/stale-protocol.test.ts +554 -0
- package/extensions/modules/plan/configPanel.ts +152 -0
- package/extensions/modules/plan/index.ts +917 -0
- package/extensions/modules/plan/lib/plan-tools.ts +72 -0
- package/extensions/modules/plan/lib/prompt.ts +65 -0
- package/extensions/modules/plan/lib/settings.ts +166 -0
- package/extensions/modules/plan/lib/shell-gate.ts +200 -0
- package/extensions/modules/plan/test/configPanel.test.ts +96 -0
- package/extensions/modules/plan/test/harness.ts +133 -0
- package/extensions/modules/plan/test/module.test.ts +305 -0
- package/extensions/modules/plan/test/settings.test.ts +114 -0
- package/extensions/modules/plan/test/shell-gate.test.ts +103 -0
- package/extensions/modules/ponytail/index.ts +23 -73
- package/extensions/modules/ponytail/lib/config.ts +1 -6
- package/extensions/modules/ponytail/test/extension.test.ts +1 -85
- package/extensions/modules/repair/configPanel.ts +96 -0
- package/extensions/modules/repair/index.ts +414 -0
- package/extensions/modules/repair/lib/auto-bg.ts +333 -0
- package/extensions/modules/repair/lib/edit-repair.ts +155 -0
- package/extensions/modules/repair/lib/editor.ts +251 -0
- package/extensions/modules/repair/lib/guards.ts +34 -0
- package/extensions/modules/repair/lib/input-repair.ts +324 -0
- package/extensions/modules/repair/lib/patch.ts +481 -0
- package/extensions/modules/repair/lib/settings.ts +114 -0
- package/extensions/modules/repair/test/auto-bg.test.ts +405 -0
- package/extensions/modules/repair/test/edit-repair.test.ts +224 -0
- package/extensions/modules/repair/test/editor.test.ts +141 -0
- package/extensions/modules/repair/test/guards.test.ts +64 -0
- package/extensions/modules/repair/test/input-repair.test.ts +231 -0
- package/extensions/modules/repair/test/patch.test.ts +563 -0
- package/extensions/modules/repair/test/settings.test.ts +167 -0
- package/extensions/modules/repair/test/wrapper.test.ts +210 -0
- package/extensions/modules/router/commands/commands.ts +4 -0
- package/extensions/modules/router/lib/client.ts +61 -0
- package/extensions/modules/router/lib/provider.ts +34 -13
- package/extensions/modules/router/lib/systemone.ts +152 -0
- package/extensions/modules/router/test/unit.test.ts +179 -0
- package/extensions/modules/rtk/findFallback.js +68 -0
- package/extensions/modules/rtk/index.ts +248 -0
- package/extensions/modules/rtk/safe-rewrite.js +74 -0
- package/extensions/modules/rtk/test/findFallback.test.js +66 -0
- package/extensions/modules/rtk/test/index.test.js +131 -0
- package/extensions/modules/rtk/test/safe-rewrite.test.js +96 -0
- package/extensions/modules/rtk/version-gate.js +34 -0
- package/extensions/modules/serena/index.ts +629 -0
- package/extensions/modules/serena/lib/detect.ts +73 -0
- package/extensions/modules/serena/lib/env.ts +76 -0
- package/extensions/modules/serena/lib/guidance.ts +26 -0
- package/extensions/modules/serena/lib/normalize.ts +27 -0
- package/extensions/modules/serena/lib/symbol-key.ts +20 -0
- package/extensions/modules/serena/lib/truncate.ts +20 -0
- package/extensions/modules/serena/test/env.test.ts +122 -0
- package/extensions/modules/serena/test/index.test.ts +347 -0
- package/extensions/modules/serena/test/worker.test.ts +562 -0
- package/extensions/modules/serena/worker.ts +858 -0
- package/extensions/modules/steering/configPanel.ts +122 -0
- package/extensions/modules/steering/index.ts +616 -0
- package/extensions/modules/steering/lib/anchor.ts +175 -0
- package/extensions/modules/steering/lib/errors.ts +253 -0
- package/extensions/modules/steering/lib/family.ts +33 -0
- package/extensions/modules/steering/lib/guidance.ts +172 -0
- package/extensions/modules/steering/lib/history.ts +170 -0
- package/extensions/modules/steering/lib/settings.ts +127 -0
- package/extensions/modules/steering/test/anchor-regressions.test.ts +93 -0
- package/extensions/modules/steering/test/anchor-wiring.test.ts +99 -0
- package/extensions/modules/steering/test/anchor.test.ts +160 -0
- package/extensions/modules/steering/test/cache-stats.test.ts +43 -0
- package/extensions/modules/steering/test/errors.test.ts +309 -0
- package/extensions/modules/steering/test/family.test.ts +43 -0
- package/extensions/modules/steering/test/guidance.test.ts +357 -0
- package/extensions/modules/steering/test/harness.ts +93 -0
- package/extensions/modules/steering/test/history.test.ts +118 -0
- package/extensions/modules/steering/test/settings.test.ts +182 -0
- package/extensions/modules/steering/test/status.test.ts +71 -0
- package/extensions/modules/steering/test/toolCall.test.ts +99 -0
- package/extensions/modules/subagent/agents/planner.md +14 -0
- package/extensions/modules/subagent/agents/reviewer.md +42 -0
- package/extensions/modules/subagent/agents/scout.md +47 -0
- package/extensions/modules/subagent/agents/tester.md +12 -0
- package/extensions/modules/subagent/agents/worker.md +18 -0
- package/extensions/modules/subagent/configPanel.ts +219 -0
- package/extensions/modules/subagent/index.ts +2451 -0
- package/extensions/modules/subagent/lib/agents.ts +408 -0
- package/extensions/modules/subagent/lib/background.ts +383 -0
- package/extensions/modules/subagent/lib/herdr.ts +1019 -0
- package/extensions/modules/subagent/lib/history.ts +126 -0
- package/extensions/modules/subagent/lib/model.ts +156 -0
- package/extensions/modules/subagent/lib/render.ts +335 -0
- package/extensions/modules/subagent/lib/result.ts +110 -0
- package/extensions/modules/subagent/lib/roles.ts +296 -0
- package/extensions/modules/subagent/lib/routing.ts +223 -0
- package/extensions/modules/subagent/lib/runner.ts +559 -0
- package/extensions/modules/subagent/lib/schema.ts +21 -0
- package/extensions/modules/subagent/lib/security.ts +752 -0
- package/extensions/modules/subagent/lib/settings.ts +159 -0
- package/extensions/modules/subagent/lib/thread-viewer.ts +319 -0
- package/extensions/modules/subagent/lib/threads.ts +135 -0
- package/extensions/modules/subagent/lib/types.ts +18 -0
- package/extensions/modules/subagent/lib/widget.ts +475 -0
- package/extensions/modules/subagent/test/configPanel.test.ts +132 -0
- package/extensions/modules/subagent/test/herdr-advisor.test.ts +40 -0
- package/extensions/modules/subagent/test/routing.test.ts +350 -0
- package/extensions/modules/subagent/test/widget.test.ts +208 -0
- package/extensions/modules/usage/index.ts +59 -16
- package/extensions/modules/usage/test/genrate.test.ts +70 -0
- package/extensions/modules/usage/test/parsers.test.ts +13 -0
- package/extensions/modules/ux/UPSTREAM +24 -0
- package/extensions/modules/ux/index.ts +393 -0
- package/extensions/modules/ux/lib/audit.ts +562 -0
- package/extensions/modules/ux/lib/config.ts +136 -0
- package/extensions/modules/ux/lib/instructions.ts +77 -0
- package/extensions/modules/ux/test/audit.test.ts +756 -0
- package/extensions/modules/ux/test/extension.test.ts +394 -0
- package/extensions/modules/ux/test/instructions.test.ts +19 -0
- package/extensions/modules/web/configPanel.ts +193 -0
- package/extensions/modules/web/index.ts +978 -0
- package/extensions/modules/web/lib/agy.ts +209 -0
- package/extensions/modules/web/lib/brave.ts +42 -0
- package/extensions/modules/web/lib/cdp.ts +686 -0
- package/extensions/modules/web/lib/chatapi.ts +101 -0
- package/extensions/modules/web/lib/chatgpt.ts +796 -0
- package/extensions/modules/web/lib/chrome.ts +328 -0
- package/extensions/modules/web/lib/config.ts +136 -0
- package/extensions/modules/web/lib/content.ts +99 -0
- package/extensions/modules/web/lib/crawl4ai.ts +172 -0
- package/extensions/modules/web/lib/extract.ts +235 -0
- package/extensions/modules/web/lib/firecrawl.ts +56 -0
- package/extensions/modules/web/lib/format.ts +197 -0
- package/extensions/modules/web/lib/gemini-auth.ts +286 -0
- package/extensions/modules/web/lib/gemini-dr.ts +338 -0
- package/extensions/modules/web/lib/gemini.ts +551 -0
- package/extensions/modules/web/lib/imageapi.ts +559 -0
- package/extensions/modules/web/lib/retry.ts +71 -0
- package/extensions/modules/web/lib/search.ts +237 -0
- package/extensions/modules/web/lib/searxng.ts +69 -0
- package/extensions/modules/web/lib/settings.ts +148 -0
- package/extensions/modules/web/scripts/cdp-smoke.ts +77 -0
- package/extensions/modules/web/scripts/gemini-smoke.ts +107 -0
- package/extensions/modules/web/test/agy.test.ts +383 -0
- package/extensions/modules/web/test/cdp.test.ts +717 -0
- package/extensions/modules/web/test/chat.test.ts +171 -0
- package/extensions/modules/web/test/chatgpt.test.ts +633 -0
- package/extensions/modules/web/test/chrome.test.ts +282 -0
- package/extensions/modules/web/test/config.test.ts +218 -0
- package/extensions/modules/web/test/configPanel.test.ts +132 -0
- package/extensions/modules/web/test/crawl.test.ts +134 -0
- package/extensions/modules/web/test/crawl4ai.test.ts +105 -0
- package/extensions/modules/web/test/extension.test.ts +118 -0
- package/extensions/modules/web/test/extract.test.ts +436 -0
- package/extensions/modules/web/test/fixtures/dr-confirm.bin +12 -0
- package/extensions/modules/web/test/fixtures/dr-plan.bin +20 -0
- package/extensions/modules/web/test/fixtures/interaction.html +31 -0
- package/extensions/modules/web/test/format.test.ts +230 -0
- package/extensions/modules/web/test/gemini-auth.test.ts +465 -0
- package/extensions/modules/web/test/gemini-dr.test.ts +249 -0
- package/extensions/modules/web/test/gemini.test.ts +472 -0
- package/extensions/modules/web/test/hook.test.ts +101 -0
- package/extensions/modules/web/test/image.test.ts +1089 -0
- package/extensions/modules/web/test/retry.test.ts +119 -0
- package/extensions/modules/web/test/screenshot.test.ts +109 -0
- package/extensions/modules/web/test/search.test.ts +210 -0
- package/extensions/modules/web/test/settings.test.ts +165 -0
- package/extensions/modules/web/test/skill.test.ts +72 -0
- package/extensions/modules/web/types.d.ts +3 -0
- package/extensions/modules/web/vendor/package.json +1 -0
- package/extensions/modules/web/vendor/readability/LICENSE.md +13 -0
- package/extensions/modules/web/vendor/readability/Readability-readerable.js +123 -0
- package/extensions/modules/web/vendor/readability/Readability.js +2787 -0
- package/extensions/modules/web/vendor/readability/index.d.ts +64 -0
- package/extensions/modules/web/vendor/readability/index.js +9 -0
- package/extensions/modules/web/vendor/turndown/LICENSE +21 -0
- package/extensions/modules/web/vendor/turndown/turndown.cjs.js +784 -0
- package/extensions/modules/web/vendor/turndown-plugin-gfm/LICENSE +21 -0
- package/extensions/modules/web/vendor/turndown-plugin-gfm/turndown-plugin-gfm.cjs.js +163 -0
- package/extensions/modules/zai/configPanel.ts +151 -0
- package/extensions/modules/zai/index.ts +186 -0
- package/extensions/modules/zai/lib/anthropic.ts +159 -0
- package/extensions/modules/zai/lib/settings.ts +198 -0
- package/extensions/modules/zai/lib/signing.ts +718 -0
- package/extensions/modules/zai/lib/throttle.ts +198 -0
- package/extensions/modules/zai/test/anthropic.test.ts +132 -0
- package/extensions/modules/zai/test/configPanel.test.ts +207 -0
- package/extensions/modules/zai/test/extension.test.ts +249 -0
- package/extensions/modules/zai/test/settings.test.ts +183 -0
- package/extensions/modules/zai/test/signing-wiring.test.ts +108 -0
- package/extensions/modules/zai/test/signing.test.ts +345 -0
- package/extensions/modules/zai/test/throttle.test.ts +329 -0
- package/package.json +19 -4
- package/scripts/validate-themes.mjs +75 -0
- package/skills/munin/SKILL.md +117 -0
- package/skills/ux-capture/SKILL.md +202 -0
- package/skills/ux-design/SKILL.md +279 -0
- package/skills/ux-presets/SKILL.md +484 -0
- package/skills/ux-routing/SKILL.md +46 -0
- package/skills/web/SKILL.md +153 -0
- package/themes/alabaster.json +93 -0
- package/themes/amethyst.json +96 -0
- package/themes/anthracite.json +93 -0
- package/themes/basalt.json +91 -0
- package/themes/birch.json +95 -0
- package/themes/catppuccin-mocha.json +91 -0
- package/themes/dark-abyss.json +91 -0
- package/themes/dark-arctic.json +104 -0
- package/themes/dark-aurora.json +95 -0
- package/themes/dark-catppuccin.json +107 -0
- package/themes/dark-cavern.json +91 -0
- package/themes/dark-celestial.json +106 -0
- package/themes/dark-copper.json +95 -0
- package/themes/dark-cosmos.json +90 -0
- package/themes/dark-cyberpunk.json +102 -0
- package/themes/dark-dracula.json +98 -0
- package/themes/dark-eclipse.json +91 -0
- package/themes/dark-ember.json +95 -0
- package/themes/dark-equinox.json +90 -0
- package/themes/dark-forest.json +96 -0
- package/themes/dark-github.json +105 -0
- package/themes/dark-gruvbox.json +112 -0
- package/themes/dark-lavender.json +95 -0
- package/themes/dark-lunar.json +89 -0
- package/themes/dark-midnight.json +95 -0
- package/themes/dark-monochrome.json +94 -0
- package/themes/dark-monokai.json +98 -0
- package/themes/dark-nebula.json +90 -0
- package/themes/dark-neon-noir.json +100 -0
- package/themes/dark-nord.json +98 -0
- package/themes/dark-ocean.json +101 -0
- package/themes/dark-one.json +100 -0
- package/themes/dark-poimandres.json +115 -0
- package/themes/dark-rainforest.json +91 -0
- package/themes/dark-reef.json +91 -0
- package/themes/dark-retro.json +92 -0
- package/themes/dark-rose-pine.json +96 -0
- package/themes/dark-sakura.json +95 -0
- package/themes/dark-slate.json +95 -0
- package/themes/dark-solarized.json +97 -0
- package/themes/dark-solstice.json +90 -0
- package/themes/dark-starfall.json +91 -0
- package/themes/dark-sunset.json +99 -0
- package/themes/dark-swamp.json +90 -0
- package/themes/dark-synthwave.json +103 -0
- package/themes/dark-taiga.json +91 -0
- package/themes/dark-terminal.json +95 -0
- package/themes/dark-tokyo-night.json +101 -0
- package/themes/dark-tundra.json +91 -0
- package/themes/dark-twilight.json +91 -0
- package/themes/dark-volcanic.json +91 -0
- package/themes/dark.json +80 -0
- package/themes/graphite.json +92 -0
- package/themes/light-arctic.json +107 -0
- package/themes/light-aurora-day.json +91 -0
- package/themes/light-canyon.json +91 -0
- package/themes/light-catppuccin.json +106 -0
- package/themes/light-cirrus.json +90 -0
- package/themes/light-coral.json +95 -0
- package/themes/light-cyberpunk.json +96 -0
- package/themes/light-dawn.json +90 -0
- package/themes/light-dunes.json +91 -0
- package/themes/light-eucalyptus.json +95 -0
- package/themes/light-forest.json +100 -0
- package/themes/light-frost.json +95 -0
- package/themes/light-github.json +115 -0
- package/themes/light-glacier.json +91 -0
- package/themes/light-gruvbox.json +108 -0
- package/themes/light-haze.json +90 -0
- package/themes/light-honeycomb.json +95 -0
- package/themes/light-lagoon.json +91 -0
- package/themes/light-lavender.json +95 -0
- package/themes/light-meadow.json +91 -0
- package/themes/light-mint.json +95 -0
- package/themes/light-monochrome.json +101 -0
- package/themes/light-ocean.json +99 -0
- package/themes/light-one.json +99 -0
- package/themes/light-opal.json +91 -0
- package/themes/light-orchard.json +91 -0
- package/themes/light-paper.json +95 -0
- package/themes/light-poimandres.json +115 -0
- package/themes/light-prism.json +90 -0
- package/themes/light-retro.json +98 -0
- package/themes/light-sand.json +95 -0
- package/themes/light-savanna.json +91 -0
- package/themes/light-solarized.json +102 -0
- package/themes/light-soleil.json +90 -0
- package/themes/light-sunset.json +99 -0
- package/themes/light-synthwave.json +98 -0
- package/themes/light-tokyo-night.json +111 -0
- package/themes/light-wetland.json +91 -0
- package/themes/light-zenith.json +89 -0
- package/themes/light.json +80 -0
- package/themes/limestone.json +94 -0
- package/themes/mahogany.json +97 -0
- package/themes/marble.json +93 -0
- package/themes/mirage.json +79 -0
- package/themes/obsidian.json +91 -0
- package/themes/onyx.json +91 -0
- package/themes/pearl.json +93 -0
- package/themes/porcelain.json +91 -0
- package/themes/quartz.json +96 -0
- package/themes/sandstone.json +95 -0
- package/themes/titanium.json +90 -0
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
// ux module — deterministic slop-audit engine (no model, no deps).
|
|
2
|
+
// ponytail: vendored from @bacnh85/pi-ux 0.6.6 (hooks/ux-audit.js, CJS → ESM TS).
|
|
3
|
+
//
|
|
4
|
+
// Four gates, all computable:
|
|
5
|
+
// 1. Contrast — APCA Lc (primary, perceptual) + WCAG 2.x ratio (sidecar).
|
|
6
|
+
// 2. Tokens — off-system values (raw hex, magic px, ad-hoc shadows).
|
|
7
|
+
// 3. States — interactive elements missing focus-visible / disabled.
|
|
8
|
+
// 4. SlopTells — named AI signatures (glassmorphism, orbs, glow, default-card).
|
|
9
|
+
//
|
|
10
|
+
// All gates are mechanical linting, not judgement. APCA math is ~25 lines;
|
|
11
|
+
// WCAG is ~10; token scan is regex; state scan is substring; tell scan is
|
|
12
|
+
// co-occurrence heuristics. No wcag-contrast lib, no css parser, no AST.
|
|
13
|
+
|
|
14
|
+
// --- colour parsing -------------------------------------------------------
|
|
15
|
+
// Accepts hex (3/4/6/8-digit) and oklch(L C H) / oklch(L C H / a). Returns
|
|
16
|
+
// [r,g,b] 0-255, or null. oklch support matters because DESIGN.md (Google's
|
|
17
|
+
// open standard) allows oklch() values.
|
|
18
|
+
|
|
19
|
+
export type Rgb = [number, number, number];
|
|
20
|
+
|
|
21
|
+
export function parseHex(hex: unknown): Rgb | null {
|
|
22
|
+
const m = /^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i.exec(String(hex).trim());
|
|
23
|
+
if (!m || !m[1]) return null;
|
|
24
|
+
let h = m[1];
|
|
25
|
+
if (h.length === 8) h = h.slice(0, 6); // drop alpha
|
|
26
|
+
if (h.length === 4) h = h.slice(0, 3);
|
|
27
|
+
if (h.length === 3) h = h.split("").map((c) => c + c).join("");
|
|
28
|
+
return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ponytail: standard oklch->linear-sRGB->sRGB. ~20 lines, no dep. Handles the
|
|
32
|
+
// cases DESIGN.md allows; guards NaN/overflow.
|
|
33
|
+
export function parseOklch(str: unknown): Rgb | null {
|
|
34
|
+
const m = /^oklch\(\s*([0-9.]+%?)\s+([0-9.]+)\s+([0-9.]+)(?:deg)?\s*(?:\/\s*([0-9.]+))?%?\s*\)$/i.exec(String(str).trim());
|
|
35
|
+
if (!m || !m[1] || !m[2] || !m[3]) return null;
|
|
36
|
+
const L = Math.min(Math.max(parseFloat(m[1]) / (String(m[1]).endsWith("%") ? 100 : 1), 0), 1);
|
|
37
|
+
const C = parseFloat(m[2]);
|
|
38
|
+
const Hdeg = parseFloat(m[3]);
|
|
39
|
+
if ([L, C, Hdeg].some(Number.isNaN)) return null;
|
|
40
|
+
const h = (Hdeg * Math.PI) / 180;
|
|
41
|
+
const a = C * Math.cos(h);
|
|
42
|
+
const b = C * Math.sin(h);
|
|
43
|
+
// OKLab -> linear sRGB
|
|
44
|
+
const l_ = L + 0.3963377774 * a + 0.2158037573 * b;
|
|
45
|
+
const m_ = L - 0.1055613458 * a - 0.0638541728 * b;
|
|
46
|
+
const s_ = L - 0.0894841775 * a - 1.291485548 * b;
|
|
47
|
+
const l3 = l_ ** 3, m3 = m_ ** 3, s3 = s_ ** 3;
|
|
48
|
+
let r = 4.0767416621 * l3 - 3.3077115913 * m3 + 0.2309699292 * s3;
|
|
49
|
+
let g = -1.2684380046 * l3 + 2.6097574011 * m3 - 0.3413193965 * s3;
|
|
50
|
+
let bl = -0.0041960863 * l3 - 0.7034186147 * m3 + 1.707614701 * s3;
|
|
51
|
+
// linear -> sRGB gamma encoding, then to 0-255. APCA's sRGBtoY expects
|
|
52
|
+
// gamma-encoded sRGB (same as hex produces); without this, oklch values
|
|
53
|
+
// double-linearize and contrast is wrong.
|
|
54
|
+
const enc = (c: number) => {
|
|
55
|
+
c = Math.min(Math.max(c, 0), 1);
|
|
56
|
+
return c <= 0.0031308 ? 12.92 * c : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
|
|
57
|
+
};
|
|
58
|
+
const to255 = (c: number) => Math.round(enc(c) * 255);
|
|
59
|
+
return [to255(r), to255(g), to255(bl)];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ponytail: standard hsl->rgb, ~15 lines, no dep. Alpha is dropped (contrast
|
|
63
|
+
// gates treat a colour as opaque, matching the hex parser's alpha stripping).
|
|
64
|
+
export function parseHsl(str: unknown): Rgb | null {
|
|
65
|
+
const m = /^hsla?\(\s*([0-9.]+)(?:deg)?(?:\s*,\s*|\s+)([0-9.]+)%(?:\s*,\s*|\s+)([0-9.]+)%\s*(?:(?:,|\/)\s*([0-9.]+%?))?\s*\)$/i.exec(String(str).trim());
|
|
66
|
+
if (!m || !m[1] || !m[2] || !m[3]) return null;
|
|
67
|
+
const h = parseFloat(m[1]) / 360;
|
|
68
|
+
const s = parseFloat(m[2]) / 100;
|
|
69
|
+
const l = parseFloat(m[3]) / 100;
|
|
70
|
+
if ([h, s, l].some(Number.isNaN)) return null;
|
|
71
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
72
|
+
const p = 2 * l - q;
|
|
73
|
+
const hue = (t: number) => {
|
|
74
|
+
let x = t % 1;
|
|
75
|
+
if (x < 0) x += 1;
|
|
76
|
+
if (x < 1 / 6) return p + (q - p) * 6 * x;
|
|
77
|
+
if (x < 1 / 2) return q;
|
|
78
|
+
if (x < 2 / 3) return p + (q - p) * (2 / 3 - x) * 6;
|
|
79
|
+
return p;
|
|
80
|
+
};
|
|
81
|
+
return [hue(h + 1 / 3), hue(h), hue(h - 1 / 3)].map((c) => Math.round(c * 255)) as Rgb;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function parseRgb(str: unknown): Rgb | null {
|
|
85
|
+
const m = /^rgba?\(\s*(\d{1,3})(?:\s*,\s*|\s+)(\d{1,3})(?:\s*,\s*|\s+)(\d{1,3})\s*(?:(?:,|\/)\s*([0-9.]+%?))?\s*\)$/i.exec(String(str).trim());
|
|
86
|
+
if (!m || !m[1] || !m[2] || !m[3]) return null;
|
|
87
|
+
const r = +m[1], g = +m[2], b = +m[3];
|
|
88
|
+
if (r > 255 || g > 255 || b > 255) return null;
|
|
89
|
+
return [r, g, b]; // alpha dropped, like 8-digit hex
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function parseColor(input: unknown): Rgb | null {
|
|
93
|
+
const s = String(input).trim();
|
|
94
|
+
if (s.startsWith("#") || /^[0-9a-f]{3,8}$/i.test(s)) return parseHex(s);
|
|
95
|
+
const lower = s.toLowerCase();
|
|
96
|
+
if (lower.startsWith("oklch")) return parseOklch(s);
|
|
97
|
+
if (lower.startsWith("rgb")) return parseRgb(s);
|
|
98
|
+
if (lower.startsWith("hsl")) return parseHsl(s);
|
|
99
|
+
// ponytail: named colours not supported — DESIGN.md tokens use hex/oklch/rgb/hsl.
|
|
100
|
+
// Tokens with other formats are just not contrast-checkable here; the gate
|
|
101
|
+
// still runs on the pairs that ARE parseable.
|
|
102
|
+
return parseHex(s); // falls back to hex parser (returns null on garbage)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// --- APCA contrast (primary gate) -----------------------------------------
|
|
106
|
+
// Canonical APCA 0.0.98G-4g (W3, constants fixed since Feb 2021). Source:
|
|
107
|
+
// Myndex/apca-w3 master src/apca-w3.js (fetched 2024). Returns signed Lc:
|
|
108
|
+
// positive = dark text on light bg (BoW); negative = light text on dark (WoB).
|
|
109
|
+
// Range ≈ ±106. Polarity matters — text is the FIRST arg, bg the SECOND.
|
|
110
|
+
|
|
111
|
+
const APCA = {
|
|
112
|
+
mainTRC: 2.4, sRco: 0.2126729, sGco: 0.7151522, sBco: 0.072175,
|
|
113
|
+
normBG: 0.56, normTXT: 0.57, revTXT: 0.62, revBG: 0.65,
|
|
114
|
+
blkThrs: 0.022, blkClmp: 1.414, scaleBoW: 1.14, scaleWoB: 1.14,
|
|
115
|
+
loBoWoffset: 0.027, loWoBoffset: 0.027, deltaYmin: 0.0005, loClip: 0.1,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export function sRGBtoY(rgb: readonly number[]): number {
|
|
119
|
+
const [r, g, b] = rgb;
|
|
120
|
+
const exp = (chan: number) => Math.pow(chan / 255.0, APCA.mainTRC);
|
|
121
|
+
return APCA.sRco * exp(r!) + APCA.sGco * exp(g!) + APCA.sBco * exp(b!);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function apcaContrastLc(textColor: unknown, bgColor: unknown): number | null {
|
|
125
|
+
const txtRgb = parseColor(textColor);
|
|
126
|
+
const bgRgb = parseColor(bgColor);
|
|
127
|
+
if (!txtRgb || !bgRgb) return null;
|
|
128
|
+
let txtY = sRGBtoY(txtRgb);
|
|
129
|
+
let bgY = sRGBtoY(bgRgb);
|
|
130
|
+
if (isNaN(txtY) || isNaN(bgY) || Math.min(txtY, bgY) < 0 || Math.max(txtY, bgY) > 1.1) return 0.0;
|
|
131
|
+
// soft black clamp
|
|
132
|
+
txtY = txtY > APCA.blkThrs ? txtY : txtY + Math.pow(APCA.blkThrs - txtY, APCA.blkClmp);
|
|
133
|
+
bgY = bgY > APCA.blkThrs ? bgY : bgY + Math.pow(APCA.blkThrs - bgY, APCA.blkClmp);
|
|
134
|
+
if (Math.abs(bgY - txtY) < APCA.deltaYmin) return 0.0;
|
|
135
|
+
let SAPC: number, out: number;
|
|
136
|
+
if (bgY > txtY) { // BoW: dark text on light
|
|
137
|
+
SAPC = (Math.pow(bgY, APCA.normBG) - Math.pow(txtY, APCA.normTXT)) * APCA.scaleBoW;
|
|
138
|
+
out = SAPC < APCA.loClip ? 0.0 : SAPC - APCA.loBoWoffset;
|
|
139
|
+
} else { // WoB: light text on dark — negative
|
|
140
|
+
SAPC = (Math.pow(bgY, APCA.revBG) - Math.pow(txtY, APCA.revTXT)) * APCA.scaleWoB;
|
|
141
|
+
out = SAPC > -APCA.loClip ? 0.0 : SAPC + APCA.loWoBoffset;
|
|
142
|
+
}
|
|
143
|
+
return out * 100.0;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// APCA threshold for a text/bg pair by font weight + size (px).
|
|
147
|
+
// Spec guidance: Lc 75 body, 60 for 400@18px+, 45 large/bold, 30 non-text.
|
|
148
|
+
// Non-text pairs (min: 3 = WCAG "large/UI" floor, no size/weight given) are
|
|
149
|
+
// graphics, not copy — they gate at Lc 30 per the gate table.
|
|
150
|
+
export function apcaThreshold(weight?: unknown, size?: unknown, isNonText = false): number {
|
|
151
|
+
if (isNonText) return 30;
|
|
152
|
+
const w = typeof weight === "number" ? weight : 400;
|
|
153
|
+
const s = typeof size === "number" ? size : 16;
|
|
154
|
+
const bold = w >= 700;
|
|
155
|
+
// APCA font-Lc lookup: Lc 45 = ≥24px regular or ≥18px bold; Lc 60 = ≥18px
|
|
156
|
+
// regular or bold body (14–17px); Lc 75 = small body. Bold body text is
|
|
157
|
+
// NOT exempt from readability — it stays at Lc 60 until it's also large.
|
|
158
|
+
if (s >= 24 || (bold && s >= 18)) return 45;
|
|
159
|
+
if (s >= 18 || bold) return 60;
|
|
160
|
+
return 75; // body text — strictest
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// --- WCAG 2.x contrast (compliance sidecar) -------------------------------
|
|
164
|
+
// Kept verbatim from v0.3.0 — some orgs must report the WCAG ratio. APCA is
|
|
165
|
+
// the primary gate; WCAG is shown alongside for procurement/legal.
|
|
166
|
+
|
|
167
|
+
export function channelLuminance(c: number): number {
|
|
168
|
+
const s = c / 255;
|
|
169
|
+
return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function relativeLuminance(hex: unknown): number | null {
|
|
173
|
+
const rgb = parseColor(hex);
|
|
174
|
+
if (!rgb) return null;
|
|
175
|
+
return 0.2126 * channelLuminance(rgb[0]) + 0.7152 * channelLuminance(rgb[1]) + 0.0722 * channelLuminance(rgb[2]);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function contrastRatio(fg: unknown, bg: unknown): number | null {
|
|
179
|
+
const l1 = relativeLuminance(fg);
|
|
180
|
+
const l2 = relativeLuminance(bg);
|
|
181
|
+
if (l1 === null || l2 === null) return null;
|
|
182
|
+
const light = Math.max(l1, l2);
|
|
183
|
+
const dark = Math.min(l1, l2);
|
|
184
|
+
return (light + 0.05) / (dark + 0.05);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// --- token coverage -------------------------------------------------------
|
|
188
|
+
|
|
189
|
+
// ponytail: a real CSS parser is overkill. Extract token *names* and *values*
|
|
190
|
+
// from :root { --token: value; } so we can tell generated code apart from the
|
|
191
|
+
// system. :root variants (:root.dark, :root[data-theme], grouped :root, .x)
|
|
192
|
+
// are standard dark-mode patterns (shadcn, Tailwind, MUI). \b after :root
|
|
193
|
+
// avoids false matches like :rootCause.
|
|
194
|
+
export function extractTokens(css: string): Map<string, string> {
|
|
195
|
+
const tokens = new Map<string, string>(); // value -> name(s)
|
|
196
|
+
const rootBlock = /:root\b[^{]*\{([^}]*)\}/g;
|
|
197
|
+
let rootMatch: RegExpExecArray | null;
|
|
198
|
+
while ((rootMatch = rootBlock.exec(css)) !== null) {
|
|
199
|
+
const decls = rootMatch[1] ?? "";
|
|
200
|
+
const declRe = /--([a-zA-Z0-9-]+)\s*:\s*([^;]+);/g;
|
|
201
|
+
let decl: RegExpExecArray | null;
|
|
202
|
+
while ((decl = declRe.exec(decls)) !== null) {
|
|
203
|
+
const name = decl[1]!.trim();
|
|
204
|
+
const value = decl[2]!.trim();
|
|
205
|
+
const key = value.toLowerCase().replace(/\s+/g, " ");
|
|
206
|
+
const existing = tokens.get(key);
|
|
207
|
+
tokens.set(key, existing ? `${existing},--${name}` : `--${name}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return tokens;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// ponytail: negative lookahead (?![0-9a-f]) instead of \b — \b fails between
|
|
214
|
+
// adjacent hex digits so 8-digit alpha hex (#RRGGBBAA) was invisible to this
|
|
215
|
+
// gate. Now matches 3/4/6/8-digit hex without partial-matching longer values.
|
|
216
|
+
const RAW_HEX_RE = /#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})(?![0-9a-f])/gi;
|
|
217
|
+
const BOX_SHADOW_RE = /box-shadow\s*:\s*([^;}]+)/gi;
|
|
218
|
+
|
|
219
|
+
export interface OffSystemFindings {
|
|
220
|
+
hardcodedHex: string[];
|
|
221
|
+
adhocShadow: string[];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function scanOffSystem(css: string, tokens: Map<string, string>): OffSystemFindings {
|
|
225
|
+
const findings: OffSystemFindings = { hardcodedHex: [], adhocShadow: [] };
|
|
226
|
+
|
|
227
|
+
// Comments must not fail the gate (same stripper as scanStates/scanSlopTells):
|
|
228
|
+
// a commented-out `/* color: #ff0000 */` is dead code, not a violation.
|
|
229
|
+
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, " ");
|
|
230
|
+
const rootFree = stripped.replace(/:root\b[^{]*\{[^}]*\}/g, "");
|
|
231
|
+
RAW_HEX_RE.lastIndex = 0;
|
|
232
|
+
let hexMatch: RegExpExecArray | null;
|
|
233
|
+
while ((hexMatch = RAW_HEX_RE.exec(rootFree)) !== null) {
|
|
234
|
+
const hex = hexMatch[0];
|
|
235
|
+
const key = hex.toLowerCase();
|
|
236
|
+
if (!tokens.has(key)) findings.hardcodedHex.push(hex);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
BOX_SHADOW_RE.lastIndex = 0;
|
|
240
|
+
let shadowMatch: RegExpExecArray | null;
|
|
241
|
+
while ((shadowMatch = BOX_SHADOW_RE.exec(rootFree)) !== null) {
|
|
242
|
+
const val = shadowMatch[1] ?? "";
|
|
243
|
+
if (!/var\(--/.test(val)) findings.adhocShadow.push(val.trim());
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return findings;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// --- state coverage -------------------------------------------------------
|
|
250
|
+
|
|
251
|
+
export interface StateFindings {
|
|
252
|
+
missingFocusVisible: string[];
|
|
253
|
+
missingDisabled: string[];
|
|
254
|
+
missingReducedMotion: string[];
|
|
255
|
+
hasInteractive: boolean;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ponytail: presence check, not a CSS parser. Stateful /g regexes with
|
|
259
|
+
// .test() flake across calls, so use plain includes().
|
|
260
|
+
export function scanStates(css: string): StateFindings {
|
|
261
|
+
let stripped = css.replace(/\/\*[\s\S]*?\*\//g, " "); // dead code must not fail the gate
|
|
262
|
+
stripped = stripped.replace(/"[^"]*"|'[^']*'/g, " "); // quoted words ("a b" in grid-template-areas) are not selectors
|
|
263
|
+
stripped = stripped.replace(/:root\b[^{]*\{[^}]*\}/g, " "); // :root token definitions must not trip the gate (FIX v0.6.3)
|
|
264
|
+
stripped = stripped.replace(/var\(--[a-zA-Z0-9-]+(?:\s*,[^)]*)?\)/g, " "); // nor token names used in rules (--input-bg is not an <input>)
|
|
265
|
+
const findings: StateFindings = { missingFocusVisible: [], missingDisabled: [], missingReducedMotion: [], hasInteractive: false };
|
|
266
|
+
|
|
267
|
+
// Motion needs a reduced-motion fallback regardless of interactive elements
|
|
268
|
+
// (a hero fade-in on a page with no buttons still needs one).
|
|
269
|
+
// ponytail: deliberately excludes transition-behavior — inert alone.
|
|
270
|
+
const hasMotion = /transition(?:-(?:property|duration|delay|timing-function))?\s*:|animation(?:-(?:name|duration|delay|timing-function|iteration-count|direction|fill-mode|play-state))?\s*:|@keyframes|scroll-behavior\s*:\s*smooth/i.test(stripped);
|
|
271
|
+
if (hasMotion && !stripped.includes("prefers-reduced-motion")) {
|
|
272
|
+
findings.missingReducedMotion.push("motion (transition/animation) with no prefers-reduced-motion fallback");
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const hasInteractive =
|
|
276
|
+
/\b(?:button|a|input|select|textarea)\b/i.test(stripped) || /\[role\s*=\s*"?button"?\]/i.test(stripped);
|
|
277
|
+
if (!hasInteractive) return findings;
|
|
278
|
+
findings.hasInteractive = true;
|
|
279
|
+
|
|
280
|
+
if (!stripped.includes(":focus-visible")) findings.missingFocusVisible.push("no :focus-visible rule for interactive elements");
|
|
281
|
+
if (!stripped.includes(":disabled")) findings.missingDisabled.push("no :disabled rule for interactive elements");
|
|
282
|
+
|
|
283
|
+
return findings;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// --- slop tells (named AI signatures) -------------------------------------
|
|
287
|
+
// Co-occurrence heuristics, not single-keyword flags, to avoid false positives
|
|
288
|
+
// on legitimate token-based elevation. Each tell is documented with the slop it
|
|
289
|
+
// catches and the conservative pattern that must all match.
|
|
290
|
+
|
|
291
|
+
const PX_PER_UNIT: Record<string, number> = { px: 1, rem: 16, em: 16, pt: 16 / 12 };
|
|
292
|
+
|
|
293
|
+
export function scanSlopTells(css: string): { tells: string[] } {
|
|
294
|
+
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, " "); // dead code must not fail the gate
|
|
295
|
+
const tells: string[] = [];
|
|
296
|
+
const lower = stripped.toLowerCase();
|
|
297
|
+
|
|
298
|
+
// 1. Glassmorphism — backdrop-filter anywhere is the tell.
|
|
299
|
+
if (lower.includes("backdrop-filter")) {
|
|
300
|
+
tells.push("glassmorphism (backdrop-filter) — faux depth implying capability the feature lacks");
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// 2. Gradient orbs — radial-gradient with a violet/purple/indigo hue +
|
|
304
|
+
// large blur. The orb signature is a big diffuse coloured blob: check
|
|
305
|
+
// for a blue-dominant saturated hex (B > R+20 AND B > G+20) and a large
|
|
306
|
+
// blur (filter:blur(NNpx) in the CSS or ≥100px size in the gradient).
|
|
307
|
+
// ponytail: allow one level of nested parens (rgba/hsl stops) so the
|
|
308
|
+
// full gradient value is captured, not truncated at the first inner ).
|
|
309
|
+
const hasBigFilterBlur = /blur\(\s*\d{2,}\s*px/i.test(stripped);
|
|
310
|
+
const radial = /radial-gradient\(([^()]*(?:\([^()]*\)[^()]*)*)\)/gi;
|
|
311
|
+
radial.lastIndex = 0;
|
|
312
|
+
let rm: RegExpExecArray | null;
|
|
313
|
+
while ((rm = radial.exec(stripped)) !== null) {
|
|
314
|
+
const v = rm[0];
|
|
315
|
+
const hasVioletHue = [...v.matchAll(/#(?:[0-9a-f]{3}|[0-9a-f]{6})\b/gi)].some((hm) => {
|
|
316
|
+
const rgb = parseHex(hm[0]);
|
|
317
|
+
if (!rgb) return false;
|
|
318
|
+
return rgb[2] > rgb[0] + 20 && rgb[2] > rgb[1] + 20; // B-dominant
|
|
319
|
+
});
|
|
320
|
+
const bigBlur = hasBigFilterBlur || /\b\d{3,}px\b/.test(v);
|
|
321
|
+
if (hasVioletHue && bigBlur) {
|
|
322
|
+
tells.push("gradient orb (violet/purple radial-gradient with large blur) — the #1 AI-slop signature");
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// 3. Neon glow — coloured box-shadow with large blur (≥20px). Checks BOTH
|
|
328
|
+
// rgba() and hex colours. A normal accent shadow (≤12px blur) is NOT a
|
|
329
|
+
// glow; a large coloured blur is the v0/Cursor tell.
|
|
330
|
+
const shadowRe = /box-shadow\s*:\s*([^;}]+)/gi;
|
|
331
|
+
shadowRe.lastIndex = 0;
|
|
332
|
+
let sm: RegExpExecArray | null;
|
|
333
|
+
while ((sm = shadowRe.exec(stripped)) !== null) {
|
|
334
|
+
const v = sm[1] ?? "";
|
|
335
|
+
const pxVals = [...v.matchAll(/(\d+(?:\.\d+)?)px/gi)].map((mm) => parseFloat(mm[1]!));
|
|
336
|
+
const maxPx = pxVals.length ? Math.max(...pxVals) : 0;
|
|
337
|
+
if (maxPx < 20) continue; // small blur = normal shadow, not glow
|
|
338
|
+
|
|
339
|
+
const colours: number[][] = [];
|
|
340
|
+
for (const cm of v.matchAll(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([0-9.]+))?\s*\)/gi)) {
|
|
341
|
+
colours.push([+cm[1]!, +cm[2]!, +cm[3]!, cm[4] !== undefined ? parseFloat(cm[4]) : 1]);
|
|
342
|
+
}
|
|
343
|
+
for (const hm of v.matchAll(/#(?:[0-9a-f]{3}|[0-9a-f]{6})\b/gi)) {
|
|
344
|
+
const rgb = parseHex(hm[0]);
|
|
345
|
+
if (rgb) colours.push([rgb[0], rgb[1], rgb[2], 1]);
|
|
346
|
+
}
|
|
347
|
+
let foundGlow = false;
|
|
348
|
+
for (const [r, g, b, a] of colours) {
|
|
349
|
+
const greyish = Math.abs(r - g) < 15 && Math.abs(g - b) < 15;
|
|
350
|
+
if (!greyish && a >= 0.3) { foundGlow = true; break; }
|
|
351
|
+
}
|
|
352
|
+
if (foundGlow) {
|
|
353
|
+
tells.push("neon glow (coloured large-blur box-shadow) — v0/Cursor signature");
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// 4. The default card — untouched shadcn reflex. Require rounded-2xl/3xl AND
|
|
359
|
+
// shadow-lg/xl AND p-6/p-8 to co-occur (the actual slop reflex).
|
|
360
|
+
if (/(rounded-(2xl|3xl))/.test(lower) && /(shadow-(lg|xl))/.test(lower) && /\bp-(6|8)\b/.test(lower)) {
|
|
361
|
+
tells.push("default card (rounded-2xl + shadow-lg + p-6 reflex) — separate with whitespace → bg shift → elevation first");
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// 5. 1px gray card border — the most reliable single AI tell. Tailwind
|
|
365
|
+
// border-zinc/gray defaults OR a literal 1px solid near-gray hex.
|
|
366
|
+
const tailwindGray = /\bborder-(zinc|gray|slate|neutral)-(?:100|200)\b/.test(lower);
|
|
367
|
+
const litGrayBorder = /border[^;}]*:\s*1px\s+solid\s+(#(?:e5e7eb|e4e4e7|d4d4d8|f1f5f9|e2e8f0))\b/i.test(stripped);
|
|
368
|
+
if (tailwindGray || litGrayBorder) {
|
|
369
|
+
tells.push("1px gray card border (border-zinc/gray default or near-gray 1px solid) — the most reliable AI tell");
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// 6. Eyebrow labels — tracked-out ALL-CAPS micro-labels above headings are
|
|
373
|
+
// template chrome (anthropics/skills frontend-design). Conservative: only
|
|
374
|
+
// flag when text-transform: uppercase, font-size ≤13px AND wide tracking
|
|
375
|
+
// (letter-spacing ≥ 0.08em) co-occur in the same block — the "tracked-out"
|
|
376
|
+
// part is the slop signature; plain uppercase labels with normal tracking
|
|
377
|
+
// are a legitimate table/label style.
|
|
378
|
+
const ruleRe = /([^{}]+)\{([^}]*)\}/g;
|
|
379
|
+
ruleRe.lastIndex = 0;
|
|
380
|
+
let rm2: RegExpExecArray | null;
|
|
381
|
+
while ((rm2 = ruleRe.exec(stripped)) !== null) {
|
|
382
|
+
const decls = (rm2[2] ?? "").toLowerCase();
|
|
383
|
+
if (!/text-transform\s*:\s*uppercase/.test(decls)) continue;
|
|
384
|
+
const fs = decls.match(/font-size\s*:\s*([0-9.]+)(px|rem|em|pt)/);
|
|
385
|
+
if (!fs || !fs[1] || !fs[2]) continue;
|
|
386
|
+
const px = parseFloat(fs[1]) * (PX_PER_UNIT[fs[2]] ?? 1);
|
|
387
|
+
if (px > 13) continue;
|
|
388
|
+
const ls = decls.match(/letter-spacing\s*:\s*([0-9.]+)(px|rem|em)/);
|
|
389
|
+
// Threshold is documented in em (≥0.08em) and em scales with the element's
|
|
390
|
+
// OWN font-size — so normalise every unit to em before comparing.
|
|
391
|
+
const lsEm = ls && ls[1] && ls[2]
|
|
392
|
+
? parseFloat(ls[1]) * (ls[2] === "em" ? 1 : ls[2] === "rem" ? 16 / px : 1 / px)
|
|
393
|
+
: 0;
|
|
394
|
+
if (lsEm >= 0.08) {
|
|
395
|
+
tells.push("eyebrow label (tracked-out uppercase at ≤13px, letter-spacing ≥0.08em) — template chrome; try sentence-case micro-labels or weight/colour instead");
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// 7. Tinted near-black backgrounds — #0B0B0B/#111 standing in for black is
|
|
401
|
+
// template chrome. Flag background hex where every channel ≤ 0x14 and the
|
|
402
|
+
// channel spread ≤ 3 (a near-neutral tint, not a real colour); pure #000
|
|
403
|
+
// is a deliberate choice and stays allowed. colour: declarations are
|
|
404
|
+
// exempt — near-black copy text is fine.
|
|
405
|
+
const bgRe = /background(?:-color)?\s*:\s*[^;}]*#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})(?![0-9a-f])/gi;
|
|
406
|
+
bgRe.lastIndex = 0;
|
|
407
|
+
let bm: RegExpExecArray | null;
|
|
408
|
+
while ((bm = bgRe.exec(stripped)) !== null) {
|
|
409
|
+
const rgb = parseHex("#" + bm[1]);
|
|
410
|
+
if (!rgb) continue;
|
|
411
|
+
const max = Math.max(rgb[0], rgb[1], rgb[2]);
|
|
412
|
+
const spread = max - Math.min(rgb[0], rgb[1], rgb[2]);
|
|
413
|
+
if (max > 0 && max <= 0x14 && spread <= 3) {
|
|
414
|
+
tells.push("tinted near-black background (#0B0B0B/#111 standing in for black) — template chrome tell");
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return { tells };
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// Contrast pairs auto-extracted from rules that declare both a colour and a
|
|
423
|
+
// background. Var() references resolve through the :root token map. Blocks
|
|
424
|
+
// without an explicit background are skipped — no inherited-bg guessing.
|
|
425
|
+
export function extractContrastPairs(css: string): AuditPair[] {
|
|
426
|
+
const nameToValue = new Map<string, string>();
|
|
427
|
+
const rootBlock = /:root\b[^{]*\{([^}]*)\}/g;
|
|
428
|
+
let rootMatch: RegExpExecArray | null;
|
|
429
|
+
while ((rootMatch = rootBlock.exec(css)) !== null) {
|
|
430
|
+
const declRe = /--([a-zA-Z0-9-]+)\s*:\s*([^;]+);/g;
|
|
431
|
+
let decl: RegExpExecArray | null;
|
|
432
|
+
while ((decl = declRe.exec(rootMatch[1] ?? "")) !== null) {
|
|
433
|
+
nameToValue.set("--" + decl[1]!.trim(), decl[2]!.trim());
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
const resolve = (value: string): string | null => {
|
|
437
|
+
let v = value.trim();
|
|
438
|
+
const varMatch = v.match(/^var\((--[^,)]+)(?:,\s*([^)]*))?\)$/);
|
|
439
|
+
if (varMatch) v = nameToValue.get(varMatch[1] ?? "") || (varMatch[2] ?? "").trim();
|
|
440
|
+
if (/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$|^(?:rgb|hsl)a?\(/i.test(v)) return v;
|
|
441
|
+
// ponytail: layered background values (e.g. "url(x.png) #fff") — pair with
|
|
442
|
+
// the first space-separated token the parsers accept, not just token 0.
|
|
443
|
+
if (/\s/.test(v) && !varMatch) {
|
|
444
|
+
for (const token of v.split(/\s+/)) {
|
|
445
|
+
if (/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$|^(?:rgb|hsl)a?\(/i.test(token)) return token;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
return null;
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
const pairs: AuditPair[] = [];
|
|
452
|
+
const seen = new Set<string>();
|
|
453
|
+
const ruleRe = /([^{}]+)\{([^}]*)\}/g;
|
|
454
|
+
ruleRe.lastIndex = 0;
|
|
455
|
+
let rm: RegExpExecArray | null;
|
|
456
|
+
while ((rm = ruleRe.exec(css)) !== null && pairs.length < 24) {
|
|
457
|
+
const decls = rm[2] ?? "";
|
|
458
|
+
const colorMatch = decls.match(/(?:^|;)\s*color\s*:\s*([^;]+)/);
|
|
459
|
+
const bgMatch = decls.match(/(?:^|;)\s*(?:background|background-color)\s*:\s*([^;]+)/);
|
|
460
|
+
if (!colorMatch || !bgMatch || !colorMatch[1] || !bgMatch[1]) continue;
|
|
461
|
+
const fg = resolve(colorMatch[1]);
|
|
462
|
+
const bg = resolve(bgMatch[1]);
|
|
463
|
+
if (!fg || !bg || fg.toLowerCase() === bg.toLowerCase()) continue;
|
|
464
|
+
// Normalise to rgb triples so #FFFFFF and #fff dedupe to one pair.
|
|
465
|
+
const keyOf = (c: string) => { const p = parseColor(c); return p ? `${p[0]},${p[1]},${p[2]}` : c.toLowerCase(); };
|
|
466
|
+
const key = keyOf(fg) + "|" + keyOf(bg);
|
|
467
|
+
if (seen.has(key)) continue;
|
|
468
|
+
seen.add(key);
|
|
469
|
+
const selector = (rm[1] ?? "").trim().replace(/\s+/g, " ").slice(0, 40);
|
|
470
|
+
pairs.push({ fg, bg, label: `auto: ${selector}` });
|
|
471
|
+
}
|
|
472
|
+
return pairs;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// --- aggregate gate -------------------------------------------------------
|
|
476
|
+
|
|
477
|
+
export interface AuditPair {
|
|
478
|
+
fg: string;
|
|
479
|
+
bg: string;
|
|
480
|
+
label?: string;
|
|
481
|
+
min?: number;
|
|
482
|
+
size?: number;
|
|
483
|
+
weight?: number;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export interface AuditPairResult extends AuditPair {
|
|
487
|
+
apca: number | null;
|
|
488
|
+
apcaMin: number;
|
|
489
|
+
ratio: number | null;
|
|
490
|
+
pass: boolean;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export interface AuditResult {
|
|
494
|
+
autoPairs: boolean;
|
|
495
|
+
gates: {
|
|
496
|
+
contrast: { pass: boolean; results: AuditPairResult[] };
|
|
497
|
+
tokens: { pass: boolean; hardcodedHex: string[]; adhocShadow: string[] };
|
|
498
|
+
states: StateFindings & { pass: boolean };
|
|
499
|
+
slopTells: { pass: boolean; tells: string[] };
|
|
500
|
+
};
|
|
501
|
+
pass: boolean;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export function audit({ css = "", pairs = [] }: { css?: string; pairs?: AuditPair[] }): AuditResult {
|
|
505
|
+
const safeCss = typeof css === "string" ? css : "";
|
|
506
|
+
let safePairs: AuditPair[] = Array.isArray(pairs) ? pairs : [];
|
|
507
|
+
const tokens = extractTokens(safeCss);
|
|
508
|
+
const off = scanOffSystem(safeCss, tokens);
|
|
509
|
+
const states = scanStates(safeCss);
|
|
510
|
+
const tells = scanSlopTells(safeCss);
|
|
511
|
+
|
|
512
|
+
// Silent-gap fix: contrast is only checked for hand-supplied pairs, which
|
|
513
|
+
// callers routinely forget. When none are provided, extract pairs from rules
|
|
514
|
+
// that declare BOTH a colour and a background (resolved via :root tokens).
|
|
515
|
+
// Conservative: no inherited-background guessing.
|
|
516
|
+
let autoPairs = false;
|
|
517
|
+
if (safePairs.length === 0) {
|
|
518
|
+
safePairs = extractContrastPairs(safeCss);
|
|
519
|
+
autoPairs = safePairs.length > 0;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const contrastResults: AuditPairResult[] = safePairs.map((p) => {
|
|
523
|
+
const lc = apcaContrastLc(p.fg, p.bg);
|
|
524
|
+
const ratio = contrastRatio(p.fg, p.bg);
|
|
525
|
+
// min: 3 with no size/weight signals a non-text graphic (WCAG 3:1 floor);
|
|
526
|
+
// anything carrying size/weight is copy and uses the text thresholds.
|
|
527
|
+
const isNonText = p.min === 3 && p.size === undefined && p.weight === undefined;
|
|
528
|
+
const apcaMin = apcaThreshold(p.weight, p.size, isNonText);
|
|
529
|
+
// pass follows APCA (primary). A pair passes if APCA is present and meets
|
|
530
|
+
// its threshold; if APCA is null (unparseable colour), fail on WCAG.
|
|
531
|
+
let pass: boolean;
|
|
532
|
+
if (lc === null) {
|
|
533
|
+
pass = ratio === null ? false : ratio >= (p.min ?? 4.5);
|
|
534
|
+
} else {
|
|
535
|
+
pass = Math.abs(lc) >= apcaMin;
|
|
536
|
+
}
|
|
537
|
+
return {
|
|
538
|
+
...p,
|
|
539
|
+
apca: lc === null ? null : Math.round(lc * 100) / 100,
|
|
540
|
+
apcaMin,
|
|
541
|
+
ratio: ratio === null ? null : Math.round(ratio * 100) / 100,
|
|
542
|
+
pass,
|
|
543
|
+
};
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
const contrastPass = contrastResults.every((r) => r.pass);
|
|
547
|
+
|
|
548
|
+
return {
|
|
549
|
+
autoPairs,
|
|
550
|
+
gates: {
|
|
551
|
+
contrast: { pass: contrastPass, results: contrastResults },
|
|
552
|
+
tokens: { pass: off.hardcodedHex.length === 0 && off.adhocShadow.length === 0, ...off },
|
|
553
|
+
states: { pass: states.missingFocusVisible.length === 0 && states.missingDisabled.length === 0 && states.missingReducedMotion.length === 0, ...states },
|
|
554
|
+
slopTells: { pass: tells.tells.length === 0, ...tells },
|
|
555
|
+
},
|
|
556
|
+
pass: contrastPass
|
|
557
|
+
&& off.hardcodedHex.length === 0 && off.adhocShadow.length === 0
|
|
558
|
+
&& states.missingFocusVisible.length === 0 && states.missingDisabled.length === 0
|
|
559
|
+
&& states.missingReducedMotion.length === 0
|
|
560
|
+
&& tells.tells.length === 0,
|
|
561
|
+
};
|
|
562
|
+
}
|