@whzxc/agent-design-gallery 0.8.0 → 0.10.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 +27 -1
- package/package.json +4 -1
- package/src/cli-output.mjs +40 -1
- package/src/cli.mjs +57 -8
- package/src/toolkit/arch-git.mjs +19 -0
- package/src/toolkit/build-store.mjs +6 -4
- package/src/toolkit/build-worker.mjs +5 -2
- package/src/toolkit/build.mjs +20 -5
- package/src/toolkit/commands.mjs +44 -14
- package/src/toolkit/config.mjs +6 -5
- package/src/toolkit/diff-inputs.mjs +5 -5
- package/src/toolkit/diff.mjs +14 -10
- package/src/toolkit/frame-document.mjs +6 -0
- package/src/toolkit/impact-eligibility.mjs +136 -0
- package/src/toolkit/impact-inputs.mjs +71 -0
- package/src/toolkit/impact-output.mjs +46 -0
- package/src/toolkit/impact-proof.mjs +67 -0
- package/src/toolkit/impact-selection.mjs +96 -0
- package/src/toolkit/impact.mjs +403 -0
- package/src/toolkit/implementation-map.mjs +129 -0
- package/src/toolkit/implementation-query.mjs +53 -0
- package/src/toolkit/index-store.mjs +99 -0
- package/src/toolkit/json-locations.mjs +28 -0
- package/src/toolkit/owner-authoring.mjs +39 -0
- package/src/toolkit/owner-colors.mjs +70 -0
- package/src/toolkit/owner-locators.mjs +73 -0
- package/src/toolkit/owner-observation.mjs +271 -0
- package/src/toolkit/owner-search.mjs +156 -0
- package/src/toolkit/owner.mjs +159 -0
- package/src/toolkit/project-index.mjs +188 -0
- package/src/toolkit/results.mjs +2 -2
- package/src/toolkit/runtime.d.ts +1 -1
- package/src/toolkit/runtime.mjs +1 -0
- package/src/toolkit/source-facts.mjs +25 -0
- package/src/toolkit/token-reachability.mjs +71 -0
- package/src/toolkit/tokens.mjs +9 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { decodeHTML } from 'entities';
|
|
2
|
+
import { parseTokens } from './tokens.mjs';
|
|
3
|
+
|
|
4
|
+
export function decodeCssEscapes(text) {
|
|
5
|
+
return text.replace(/\\(?:([\da-f]{1,6})(?:\r\n|[ \t\r\n\f])?|(\r\n|[\r\n\f])|([\s\S]))/gi, (_, hex, newline, char) => {
|
|
6
|
+
if (hex) {
|
|
7
|
+
const code = Number.parseInt(hex, 16);
|
|
8
|
+
return String.fromCodePoint(!code || code > 0x10ffff || code >= 0xd800 && code <= 0xdfff ? 0xfffd : code);
|
|
9
|
+
}
|
|
10
|
+
return newline ? '' : char;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function forms(text) {
|
|
15
|
+
const css = decodeCssEscapes(text), html = decodeHTML(text);
|
|
16
|
+
return [...new Set([text, css, html, decodeCssEscapes(html), decodeHTML(css)])];
|
|
17
|
+
}
|
|
18
|
+
// Decoding only adds candidates; raw spellings, text and inactive rules still participate.
|
|
19
|
+
const identifiers = text => [...new Set(forms(text).flatMap(value => [...value.matchAll(/--[\p{L}\p{N}_-]+/gu)].map(match => match[0])))];
|
|
20
|
+
|
|
21
|
+
function unbalancedVar(value) {
|
|
22
|
+
const stack = [];
|
|
23
|
+
let quote = null;
|
|
24
|
+
for (let i = 0; i < value.length; i++) {
|
|
25
|
+
const char = value[i];
|
|
26
|
+
if (char === '\\') { i++; continue; }
|
|
27
|
+
if (quote) { if (char === quote) quote = null; continue; }
|
|
28
|
+
if (char === '"' || char === "'") { quote = char; continue; }
|
|
29
|
+
if (char === '(') stack.push(/\bvar$/i.test(value.slice(Math.max(0, i - 3), i)));
|
|
30
|
+
else if (char === ')') stack.pop();
|
|
31
|
+
}
|
|
32
|
+
return stack.includes(true);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Conservative names/declarations (including absence), shared by candidates and later proofs. */
|
|
36
|
+
export function tokenReachability(document, tokenSource, theme) {
|
|
37
|
+
return reachability(identifiers(document).sort(), tokenSource, theme);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function entryTokenReachability(css, tokenSource) {
|
|
41
|
+
const shared = identifiers(css);
|
|
42
|
+
let parsed;
|
|
43
|
+
try { parsed = parseTokens(tokenSource); } catch {}
|
|
44
|
+
return markup => {
|
|
45
|
+
const roots = [...new Set([...shared, ...identifiers(markup)])].sort();
|
|
46
|
+
return theme => reachability(roots, tokenSource, theme, parsed);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function reachability(roots, tokenSource, theme, parsed) {
|
|
51
|
+
let tokens, definitions;
|
|
52
|
+
const result = (mode, names, via, fallbackReasons) => ({ mode, names, via,
|
|
53
|
+
declarations: definitions ? Object.fromEntries(names.map(name => [name, definitions.get(name) ?? null])) : {}, fallbackReasons });
|
|
54
|
+
const fallback = reason => result('full_sheet', [...new Set([...roots, ...identifiers(tokenSource)])].sort(), {}, [reason]);
|
|
55
|
+
try { tokens = parsed ?? parseTokens(tokenSource); } catch { return fallback('tokens_parse_failed'); }
|
|
56
|
+
definitions = new Map(tokens.light);
|
|
57
|
+
if (theme === 'dark') for (const [name, value] of tokens.dark) definitions.set(name, value);
|
|
58
|
+
const via = {}, queue = roots.map(name => ({ name, route: [] }));
|
|
59
|
+
for (let i = 0; i < queue.length; i++) {
|
|
60
|
+
const { name, route } = queue[i];
|
|
61
|
+
if (Object.hasOwn(via, name)) continue;
|
|
62
|
+
via[name] = route;
|
|
63
|
+
const value = definitions.get(name);
|
|
64
|
+
if (value === undefined) continue;
|
|
65
|
+
const variants = forms(value);
|
|
66
|
+
if (variants.some(unbalancedVar)) return fallback('unbalanced_var');
|
|
67
|
+
const targets = new Set(variants.flatMap(value => [...value.matchAll(/\bvar\(\s*(--[\p{L}\p{N}_-]+)/giu)].map(match => match[1])));
|
|
68
|
+
for (const target of targets) queue.push({ name: target, route: [...route, name] });
|
|
69
|
+
}
|
|
70
|
+
return result('reachable_declarations', Object.keys(via).sort(), via, []);
|
|
71
|
+
}
|
package/src/toolkit/tokens.mjs
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { CliError } from '../cli-output.mjs';
|
|
2
|
+
export function tokenLocations(css) {
|
|
3
|
+
const clean = css.replace(/\/\*[\s\S]*?\*\//g, comment => comment.replace(/[^\n]/g, ' '));
|
|
4
|
+
const blocks = [...clean.matchAll(/([^{}]+)\{([^{}]*)\}/g)];
|
|
5
|
+
const maps = blocks.map(block => {
|
|
6
|
+
const start = block.index + block[0].indexOf('{') + 1;
|
|
7
|
+
return new Map([...block[2].matchAll(/(--[\w-]+)\s*:/g)].map(match => [match[1], clean.slice(0, start + match.index).split('\n').length]));
|
|
8
|
+
});
|
|
9
|
+
return { light: maps[0] ?? new Map(), dark: maps[1] ?? new Map() };
|
|
10
|
+
}
|
|
2
11
|
export function parseTokens(css) {
|
|
3
12
|
const source = css.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
4
13
|
const blocks = [...source.matchAll(/([^{}]+)\{([^{}]*)\}/g)];
|