@reqvire-org/ads 0.5.1 → 0.5.3
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/dist/ads-errors.mjs +143 -51
- package/dist/analysis/composition-axes.mjs +48 -0
- package/dist/analysis/construction-memo.mjs +38 -0
- package/dist/analysis/context.mjs +19 -0
- package/dist/analysis/design-reads.mjs +177 -0
- package/dist/analysis/design-usage.mjs +4 -20
- package/dist/analysis/factored-classes.mjs +90 -0
- package/dist/analysis/helpers.mjs +5 -7
- package/dist/analysis/mock-check.mjs +4 -5
- package/dist/analysis/native-project.mjs +12 -0
- package/dist/analysis/owner-accessibility.mjs +4 -4
- package/dist/analysis/owner-analysis-cache.mjs +86 -23
- package/dist/analysis/owner-analysis-key.mjs +42 -10
- package/dist/analysis/owner-choices.mjs +56 -7
- package/dist/analysis/owner-composition.mjs +179 -45
- package/dist/analysis/owner-reuse.mjs +8 -6
- package/dist/analysis/owner-source.mjs +304 -110
- package/dist/analysis/scenario-keys.mjs +10 -7
- package/dist/analysis/service.mjs +50 -3
- package/dist/analysis/standalone.mjs +7 -4
- package/dist/analysis/syntax.mjs +59 -1
- package/dist/analysis/worker-protocol.mjs +14 -2
- package/dist/analysis/worker.mjs +32 -10
- package/dist/architecture-report.mjs +26 -0
- package/dist/asset-view-facts.mjs +16 -2
- package/dist/boundaries.mjs +26 -10
- package/dist/bun-compiler.mjs +2 -2
- package/dist/check-service.mjs +29 -17
- package/dist/check.mjs +13 -6
- package/dist/cli.mjs +1 -1
- package/dist/composed-contrast.mjs +143 -62
- package/dist/composed-keyline.mjs +2 -2
- package/dist/config.mjs +2 -1
- package/dist/construction-output.mjs +9 -3
- package/dist/construction-spec.d.mts +145 -31
- package/dist/construction-spec.mjs +204 -74
- package/dist/corner-overpaint.mjs +20 -7
- package/dist/derived-states.mjs +182 -0
- package/dist/design-foundation.mjs +16 -0
- package/dist/design-inputs.mjs +18 -3
- package/dist/design-system-closure.mjs +12 -7
- package/dist/design-usage.mjs +2 -8
- package/dist/emit/contract.mjs +24 -5
- package/dist/emit/emission.mjs +6 -9
- package/dist/emit/integrity.mjs +8 -2
- package/dist/emit/output-watch.mjs +120 -0
- package/dist/emit/owner-emission-cache.mjs +4 -4
- package/dist/emit/preview-emitter.mjs +4 -2
- package/dist/emit/preview-tree.mjs +1 -1
- package/dist/emit/service.mjs +8 -2
- package/dist/finding-rules.mjs +3 -0
- package/dist/form-states.mjs +8 -0
- package/dist/frame-regions.mjs +29 -9
- package/dist/grid-lowering.mjs +3 -1
- package/dist/hover-geometry.mjs +15 -0
- package/dist/input-digests.mjs +17 -10
- package/dist/linaria/delivery.mjs +2 -0
- package/dist/lowering-enter.mjs +6 -6
- package/dist/lowering-properties.mjs +5 -0
- package/dist/lowering-region-layout.mjs +7 -2
- package/dist/lowering-session.mjs +10 -0
- package/dist/mcp/build-status.mjs +9 -1
- package/dist/mcp/compiler-channel.mjs +11 -4
- package/dist/mcp/mutations.mjs +1 -0
- package/dist/mcp/preview-http.bundle.js +1 -1
- package/dist/mcp/preview-watch.mjs +2 -1
- package/dist/mcp/preview-widget.bundle.js +1 -1
- package/dist/mcp/server-observation.mjs +6 -4
- package/dist/mcp/server-project.mjs +4 -1
- package/dist/motion-model.mjs +1 -1
- package/dist/owner-analysis-check.mjs +23 -6
- package/dist/owner-errors.mjs +6 -3
- package/dist/owner-lowering.mjs +78 -13
- package/dist/owner-scenarios.mjs +6 -23
- package/dist/ownership-model.mjs +24 -8
- package/dist/paint-contrast.mjs +6 -0
- package/dist/placeholder-contrast.mjs +17 -1
- package/dist/platform-features.mjs +10 -1
- package/dist/profile-macro.d.mts +7 -0
- package/dist/profile-view-facts.mjs +1 -1
- package/dist/recipe-macro.d.mts +103 -40
- package/dist/recipe-model.mjs +18 -13
- package/dist/region-lowering.mjs +266 -123
- package/dist/render-audit/layout-shift.page.mjs +24 -0
- package/dist/render-audit/render-states.mjs +122 -1
- package/dist/render-audit/render-states.page.mjs +140 -0
- package/dist/render-audit/worker.mjs +18 -3
- package/dist/render-audit.mjs +114 -1
- package/dist/role-vocabulary.d.mts +9 -0
- package/dist/role-vocabulary.mjs +16 -1
- package/dist/runtime-paint-contrast.mjs +5 -2
- package/dist/scenarios-compiler.mjs +20 -6
- package/dist/showcase/assets-view.mjs +29 -13
- package/dist/showcase/client.bundle.js +50 -50
- package/dist/showcase/http-client.bundle.js +15 -15
- package/dist/showcase/ui/ui.css +1 -1
- package/dist/showcase/ui/ui.js +5 -5
- package/dist/skills/ads-designer/references/accessibility.md +10 -4
- package/dist/skills/ads-designer/references/branding.md +13 -3
- package/dist/skills/ads-designer/references/contracts.md +5 -2
- package/dist/skills/ads-designer/references/design-data.md +13 -7
- package/dist/skills/ads-designer/references/layout.md +12 -4
- package/dist/skills/ads-designer/references/motion.md +11 -2
- package/dist/skills/ads-designer/references/recipes.md +49 -15
- package/dist/skills/ads-import/references/contracts.md +5 -2
- package/dist/skills/ads-import/references/design-data.md +13 -7
- package/dist/skills/ads-import/references/layout.md +12 -4
- package/dist/skills/ads-import/references/recipes.md +49 -15
- package/dist/skills/ads-migrate/SKILL.md +2 -0
- package/dist/skills/ads-migrate/references/0.5.1-to-0.5.2.md +185 -0
- package/dist/skills/ads-migrate/references/0.5.2-to-0.5.3.md +71 -0
- package/dist/skills/ads-port/references/contracts.md +5 -2
- package/dist/skills/ads-port/references/design-data.md +13 -7
- package/dist/skills/ads-port/references/layout.md +12 -4
- package/dist/skills/ads-port/references/recipes.md +49 -15
- package/dist/spatial-model.mjs +2 -2
- package/dist/surface-contrast.mjs +7 -2
- package/dist/surface-effects.mjs +5 -3
- package/dist/target-size.mjs +21 -3
- package/dist/task-cache.mjs +8 -18
- package/dist/validation-checks.mjs +1 -1
- package/docs/ADS.md +9 -3
- package/docs/ARCHITECTURE.md +96 -30
- package/docs/CACHING.md +152 -24
- package/docs/CHANGELOG.md +307 -23
- package/docs/GUIDE.md +109 -20
- package/docs/LANGUAGE.md +262 -117
- package/docs/MCP.md +5 -1
- package/docs/MOTION.md +15 -4
- package/docs/PROFILE-KINDS.md +54 -4
- package/docs/RULES.md +34 -25
- package/docs/TOKEN-ROLES.md +7 -1
- package/package.json +1 -1
- package/dist/analysis/prose-owners.mjs +0 -57
- package/dist/prose-model.d.mts +0 -81
- package/dist/prose-model.mjs +0 -101
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { digest } from "../digest.mjs";
|
|
2
|
+
import { canonical, rootRelative } from "./owner-analysis-key.mjs";
|
|
3
|
+
const ABSORB = Symbol("design-reads.absorb"), groupOf = (map) => map === "profiles" ? "profiles" : "assets", valueDigests = new WeakMap;
|
|
4
|
+
export function designValueDigest(value, root) {
|
|
5
|
+
return digestOf(value, root);
|
|
6
|
+
}
|
|
7
|
+
function digestOf(value, root) {
|
|
8
|
+
if (value === null || typeof value !== "object")
|
|
9
|
+
return digest(canonical(value === void 0 ? { $undefined: !0 } : value));
|
|
10
|
+
const byRoot = valueDigests.get(value) ?? new Map;
|
|
11
|
+
valueDigests.set(value, byRoot);
|
|
12
|
+
if (byRoot.has(root))
|
|
13
|
+
return byRoot.get(root) ?? null;
|
|
14
|
+
let computed;
|
|
15
|
+
try {
|
|
16
|
+
computed = digest(rootRelative(canonical(value), root));
|
|
17
|
+
} catch {
|
|
18
|
+
computed = null;
|
|
19
|
+
}
|
|
20
|
+
byRoot.set(root, computed);
|
|
21
|
+
return computed;
|
|
22
|
+
}
|
|
23
|
+
const profilesDigests = new WeakMap;
|
|
24
|
+
export function wholeDesignDigests(foundation, assetsDigest) {
|
|
25
|
+
let profiles = profilesDigests.get(foundation.profiles);
|
|
26
|
+
if (profiles === void 0)
|
|
27
|
+
profilesDigests.set(foundation.profiles, profiles = digest(canonical(foundation.profiles)));
|
|
28
|
+
return { profiles, assets: assetsDigest };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class RecordingMap {
|
|
32
|
+
inner;
|
|
33
|
+
note;
|
|
34
|
+
all;
|
|
35
|
+
constructor(inner, note, all) {
|
|
36
|
+
this.inner = inner;
|
|
37
|
+
this.note = note;
|
|
38
|
+
this.all = all;
|
|
39
|
+
}
|
|
40
|
+
get(key) {
|
|
41
|
+
const value = this.inner.get(key);
|
|
42
|
+
this.note("get", key, value);
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
has(key) {
|
|
46
|
+
const value = this.inner.has(key);
|
|
47
|
+
this.note("has", key, value);
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
get size() {
|
|
51
|
+
this.all();
|
|
52
|
+
return this.inner.size;
|
|
53
|
+
}
|
|
54
|
+
forEach(callback, thisArg) {
|
|
55
|
+
this.all();
|
|
56
|
+
this.inner.forEach((value, key) => callback.call(thisArg, value, key, this));
|
|
57
|
+
}
|
|
58
|
+
entries() {
|
|
59
|
+
this.all();
|
|
60
|
+
return this.inner.entries();
|
|
61
|
+
}
|
|
62
|
+
keys() {
|
|
63
|
+
this.all();
|
|
64
|
+
return this.inner.keys();
|
|
65
|
+
}
|
|
66
|
+
values() {
|
|
67
|
+
this.all();
|
|
68
|
+
return this.inner.values();
|
|
69
|
+
}
|
|
70
|
+
[Symbol.iterator]() {
|
|
71
|
+
return this.entries();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function traceDesignReads(foundation, assets, root, whole) {
|
|
75
|
+
const reads = new Map, wholes = {}, readAll = (group) => {
|
|
76
|
+
wholes[group] = whole[group];
|
|
77
|
+
}, noteMap = (map) => (op, key, value) => {
|
|
78
|
+
const id = `map:${map}:${op}:${key}`;
|
|
79
|
+
if (!reads.has(id) && wholes[groupOf(map)] === void 0)
|
|
80
|
+
reads.set(id, { kind: "map", map, op, key, value });
|
|
81
|
+
}, modelRead = (op, args, run) => {
|
|
82
|
+
const value = run(), id = `model:${op}:${args}`;
|
|
83
|
+
if (!reads.has(id) && wholes.profiles === void 0)
|
|
84
|
+
reads.set(id, { kind: "model", op, args, value });
|
|
85
|
+
return value;
|
|
86
|
+
}, catalogMap = (map, inner) => new RecordingMap(inner, noteMap(map), () => readAll("assets")), view = {
|
|
87
|
+
get hash() {
|
|
88
|
+
readAll("profiles");
|
|
89
|
+
return foundation.hash;
|
|
90
|
+
},
|
|
91
|
+
get defaults() {
|
|
92
|
+
return foundation.defaults;
|
|
93
|
+
},
|
|
94
|
+
get tokens() {
|
|
95
|
+
return foundation.tokens;
|
|
96
|
+
},
|
|
97
|
+
get sheets() {
|
|
98
|
+
return foundation.sheets;
|
|
99
|
+
},
|
|
100
|
+
get registrations() {
|
|
101
|
+
return foundation.registrations;
|
|
102
|
+
},
|
|
103
|
+
contexts: foundation.contexts,
|
|
104
|
+
profiles: new RecordingMap(foundation.profiles, noteMap("profiles"), () => readAll("profiles")),
|
|
105
|
+
model: {
|
|
106
|
+
compose: (name) => modelRead("compose", name, () => foundation.model.compose(name)),
|
|
107
|
+
select: (reference, bindings) => modelRead("select", JSON.stringify([reference, bindings ?? null]), () => foundation.model.select(reference, bindings)),
|
|
108
|
+
variants: (reference) => modelRead("variants", reference, () => foundation.model.variants(reference))
|
|
109
|
+
}
|
|
110
|
+
}, catalog = {
|
|
111
|
+
records: catalogMap("records", assets.records),
|
|
112
|
+
names: catalogMap("names", assets.names),
|
|
113
|
+
sites: catalogMap("sites", assets.sites),
|
|
114
|
+
sets: catalogMap("sets", assets.sets)
|
|
115
|
+
}, absorb = (evidence, group) => {
|
|
116
|
+
if (evidence.whole[group] !== void 0)
|
|
117
|
+
readAll(group);
|
|
118
|
+
if (wholes[group] !== void 0)
|
|
119
|
+
return;
|
|
120
|
+
for (const read of evidence.reads) {
|
|
121
|
+
if ((read.kind === "model" ? "profiles" : groupOf(read.map)) !== group)
|
|
122
|
+
continue;
|
|
123
|
+
const id = read.kind === "model" ? `model:${read.op}:${read.args}` : `map:${read.map}:${read.op}:${read.key}`;
|
|
124
|
+
if (!reads.has(id))
|
|
125
|
+
reads.set(id, read);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
Object.defineProperty(view, ABSORB, { value: absorb });
|
|
129
|
+
Object.defineProperty(catalog, ABSORB, { value: absorb });
|
|
130
|
+
return {
|
|
131
|
+
foundation: view,
|
|
132
|
+
assets: catalog,
|
|
133
|
+
evidence: () => ({
|
|
134
|
+
whole: { ...wholes },
|
|
135
|
+
reads: [...reads.values()].filter((read) => wholes[read.kind === "model" ? "profiles" : groupOf(read.map)] === void 0),
|
|
136
|
+
at: whole,
|
|
137
|
+
root
|
|
138
|
+
})
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const readWhole = (map) => map.size;
|
|
142
|
+
export function designReadsMatch(evidence, foundation, assets, root, whole) {
|
|
143
|
+
const unchanged = (group) => evidence.at[group] === whole[group];
|
|
144
|
+
for (const group of ["profiles", "assets"]) {
|
|
145
|
+
if (!unchanged(group))
|
|
146
|
+
continue;
|
|
147
|
+
(group === "profiles" ? foundation : assets)[ABSORB]?.(evidence, group);
|
|
148
|
+
}
|
|
149
|
+
for (const group of ["profiles", "assets"]) {
|
|
150
|
+
if (unchanged(group))
|
|
151
|
+
continue;
|
|
152
|
+
const recorded = evidence.whole[group];
|
|
153
|
+
if (recorded === void 0)
|
|
154
|
+
continue;
|
|
155
|
+
readWhole(group === "profiles" ? foundation.profiles : assets.records);
|
|
156
|
+
if (recorded !== whole[group])
|
|
157
|
+
return !1;
|
|
158
|
+
}
|
|
159
|
+
for (const read of evidence.reads) {
|
|
160
|
+
if (unchanged(read.kind === "model" ? "profiles" : groupOf(read.map)))
|
|
161
|
+
continue;
|
|
162
|
+
const value = (() => {
|
|
163
|
+
if (read.kind === "model") {
|
|
164
|
+
if (read.op === "select") {
|
|
165
|
+
const [reference, bindings] = JSON.parse(read.args);
|
|
166
|
+
return foundation.model.select(reference, bindings ?? void 0);
|
|
167
|
+
}
|
|
168
|
+
return read.op === "compose" ? foundation.model.compose(read.args) : foundation.model.variants(read.args);
|
|
169
|
+
}
|
|
170
|
+
const map = read.map === "profiles" ? foundation.profiles : assets[read.map];
|
|
171
|
+
return read.op === "get" ? map.get(read.key) : map.has(read.key);
|
|
172
|
+
})(), now = digestOf(value, root);
|
|
173
|
+
if (now === null || now !== digestOf(read.value, evidence.root))
|
|
174
|
+
return !1;
|
|
175
|
+
}
|
|
176
|
+
return !0;
|
|
177
|
+
}
|
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
isStringLiteral,
|
|
21
21
|
isVariableDeclaration
|
|
22
22
|
} from "typescript/ast";
|
|
23
|
-
import { isProseTag } from "../prose-model.mjs";
|
|
24
23
|
function walk(node, visit) {
|
|
25
24
|
visit(node);
|
|
26
25
|
node.forEachChild((child) => walk(child, visit));
|
|
@@ -89,7 +88,7 @@ function isMetadata(node) {
|
|
|
89
88
|
return !0;
|
|
90
89
|
return !node.attributes.properties.some((attribute) => isJsxAttribute(attribute) && attribute.name.getText() === "rel" && attribute.initializer !== void 0 && /stylesheet/.test(attribute.initializer.getText()));
|
|
91
90
|
}
|
|
92
|
-
export function designUsageProblems(source, { publicEntry, patterns
|
|
91
|
+
export function designUsageProblems(source, { publicEntry, patterns }, allowance = {}) {
|
|
93
92
|
const problems = [], { names, namespaces } = designSystemImports(source, publicEntry), allowed = allowedImports(source, allowance.components ?? new Map), isAllowed = (node) => isIdentifier(node) && allowed.has(node.text) || allowance.metadata === !0 && isMetadata(node.parent), exportedName = (tag) => isIdentifier(tag) ? names.get(tag.text) : isPropertyAccessExpression(tag) && isIdentifier(tag.expression) && namespaces.has(tag.expression.text) ? tag.name.text : void 0, fromDesignSystem = (tag) => exportedName(tag) !== void 0, isPattern = (tag) => tag !== void 0 && patterns.has(exportedName(tag) ?? ""), insidePattern = (node) => {
|
|
94
93
|
for (let current = node.parent;current !== void 0; current = current.parent) {
|
|
95
94
|
if (isJsxElement(current) && current.openingElement === node)
|
|
@@ -98,17 +97,6 @@ export function designUsageProblems(source, { publicEntry, patterns, prose = new
|
|
|
98
97
|
return !0;
|
|
99
98
|
}
|
|
100
99
|
return !1;
|
|
101
|
-
}, proseOwner = (node) => {
|
|
102
|
-
for (let current = node.parent;current !== void 0; current = current.parent) {
|
|
103
|
-
if (!isJsxElement(current) || current.openingElement === node)
|
|
104
|
-
continue;
|
|
105
|
-
const tag = current.openingElement.tagName;
|
|
106
|
-
if (isIdentifier(tag) && isProseTag(tag.text))
|
|
107
|
-
continue;
|
|
108
|
-
const name = exportedName(tag), tags = name === void 0 ? void 0 : prose.get(name);
|
|
109
|
-
return name === void 0 || tags === void 0 ? void 0 : { name, tags };
|
|
110
|
-
}
|
|
111
|
-
return;
|
|
112
100
|
};
|
|
113
101
|
for (const statement of source.statements)
|
|
114
102
|
if (isImportDeclaration(statement) && isStringLiteral(statement.moduleSpecifier) && statement.importClause?.phaseModifier !== SyntaxKind.TypeKeyword && authorsDesign(statement.moduleSpecifier.text))
|
|
@@ -117,13 +105,9 @@ export function designUsageProblems(source, { publicEntry, patterns, prose = new
|
|
|
117
105
|
if (isJsxOpeningElement(node) || isJsxSelfClosingElement(node)) {
|
|
118
106
|
if (isAllowed(node.tagName))
|
|
119
107
|
;
|
|
120
|
-
else if (!fromDesignSystem(node.tagName))
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
problems.push({ node, problem: { kind: "local-markup", tag } });
|
|
124
|
-
else if (!owner.tags.has(tag))
|
|
125
|
-
problems.push({ node, problem: { kind: "prose-element-undeclared", tag, owner: owner.name } });
|
|
126
|
-
} else if (!isPattern(node.tagName) && !insidePattern(node) && inScreenFunction(node))
|
|
108
|
+
else if (!fromDesignSystem(node.tagName))
|
|
109
|
+
problems.push({ node, problem: { kind: "local-markup", tag: node.tagName.getText() } });
|
|
110
|
+
else if (!isPattern(node.tagName) && !insidePattern(node) && inScreenFunction(node))
|
|
127
111
|
problems.push({ node, problem: { kind: "component-outside-pattern", name: exportedName(node.tagName) ?? node.tagName.getText() } });
|
|
128
112
|
for (const attribute of node.attributes.properties)
|
|
129
113
|
if (isJsxSpreadAttribute(attribute))
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const key = (values) => JSON.stringify(values);
|
|
2
|
+
export function factorClasses(all, declared) {
|
|
3
|
+
const leaves = all.filter((leaf) => leaf.value !== null), [sample] = leaves;
|
|
4
|
+
if (sample === void 0)
|
|
5
|
+
return null;
|
|
6
|
+
const assignedIds = new Set(sample.assignment.map(([id]) => id)), axes = declared.filter((axis) => assignedIds.has(axis.id));
|
|
7
|
+
if (leaves.length < 2 || axes.length < 2)
|
|
8
|
+
return null;
|
|
9
|
+
const ids = axes.map((axis) => axis.id), rows = [];
|
|
10
|
+
for (const leaf of leaves) {
|
|
11
|
+
if (leaf.value === null)
|
|
12
|
+
return null;
|
|
13
|
+
const assigned = new Map(leaf.assignment);
|
|
14
|
+
if (ids.some((id) => !assigned.has(id)) || assigned.size !== ids.length)
|
|
15
|
+
return null;
|
|
16
|
+
rows.push({ values: ids.map((id) => assigned.get(id)), classes: new Set(leaf.value.split(/\s+/).filter((item) => item !== "")) });
|
|
17
|
+
}
|
|
18
|
+
const [first] = rows;
|
|
19
|
+
if (first === void 0)
|
|
20
|
+
return null;
|
|
21
|
+
const base = [...first.classes].filter((item) => rows.every((row) => row.classes.has(item))), varying = [...new Set(rows.flatMap((row) => [...row.classes]))].filter((item) => !base.includes(item)), support = new Map;
|
|
22
|
+
for (const item of varying)
|
|
23
|
+
support.set(item, new Set);
|
|
24
|
+
for (let axis = 0;axis < ids.length; axis++) {
|
|
25
|
+
const others = new Map;
|
|
26
|
+
for (const row of rows) {
|
|
27
|
+
const rest = key(row.values.filter((_, index) => index !== axis));
|
|
28
|
+
others.set(rest, [...others.get(rest) ?? [], row]);
|
|
29
|
+
}
|
|
30
|
+
for (const group of others.values()) {
|
|
31
|
+
if (group.length < 2)
|
|
32
|
+
continue;
|
|
33
|
+
for (const item of varying) {
|
|
34
|
+
const present = group.map((row) => row.classes.has(item));
|
|
35
|
+
if (present.some((value) => value !== present[0]))
|
|
36
|
+
support.get(item)?.add(axis);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const parent = ids.map((_, index) => index), find = (index) => parent[index] === index ? index : parent[index] = find(parent[index] ?? index);
|
|
41
|
+
for (const axesOf of support.values()) {
|
|
42
|
+
const [head, ...rest] = [...axesOf];
|
|
43
|
+
if (head === void 0)
|
|
44
|
+
return null;
|
|
45
|
+
for (const other of rest)
|
|
46
|
+
parent[find(other)] = find(head);
|
|
47
|
+
}
|
|
48
|
+
const components = new Map;
|
|
49
|
+
for (const axesOf of support.values())
|
|
50
|
+
for (const axis of axesOf)
|
|
51
|
+
components.set(find(axis), [...new Set([...components.get(find(axis)) ?? [], ...axesOf])]);
|
|
52
|
+
const groups = [...components.values()].map((members) => members.sort((a, b) => a - b));
|
|
53
|
+
if (groups.length < 2)
|
|
54
|
+
return null;
|
|
55
|
+
const tables = groups.map((members) => {
|
|
56
|
+
const owned = varying.filter((item) => [...support.get(item) ?? []].every((axis) => members.includes(axis))), table = new Map;
|
|
57
|
+
for (const row of rows) {
|
|
58
|
+
const values = key(members.map((axis) => row.values[axis])), classes = owned.filter((item) => row.classes.has(item)).join(" "), known = table.get(values);
|
|
59
|
+
if (known !== void 0 && known !== classes)
|
|
60
|
+
return null;
|
|
61
|
+
table.set(values, classes);
|
|
62
|
+
}
|
|
63
|
+
return { members, owned, table };
|
|
64
|
+
});
|
|
65
|
+
if (tables.some((table) => table === null))
|
|
66
|
+
return null;
|
|
67
|
+
const complete = tables;
|
|
68
|
+
for (const row of rows) {
|
|
69
|
+
const rebuilt = new Set([...base, ...complete.flatMap(({ members, table }) => (table.get(key(members.map((axis) => row.values[axis]))) ?? "").split(" ").filter((item) => item !== ""))]);
|
|
70
|
+
if (rebuilt.size !== row.classes.size || [...row.classes].some((item) => !rebuilt.has(item)))
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
base: base.join(" "),
|
|
75
|
+
groups: complete.map(({ members, table }) => {
|
|
76
|
+
const groupAxes = members.map((axis) => axes[axis]), build = (depth, prefix) => {
|
|
77
|
+
if (depth === members.length) {
|
|
78
|
+
const classes = table.get(key(prefix));
|
|
79
|
+
return classes === void 0 ? null : { kind: "leaf", value: classes, assignment: [] };
|
|
80
|
+
}
|
|
81
|
+
const axis = groupAxes[depth], options = axis.domain.flatMap((value) => {
|
|
82
|
+
const child = build(depth + 1, [...prefix, value]);
|
|
83
|
+
return child === null ? [] : [[value, child]];
|
|
84
|
+
});
|
|
85
|
+
return options.length === 0 ? null : { kind: "choice", axis, options };
|
|
86
|
+
};
|
|
87
|
+
return { axes: groupAxes, tree: build(0, []) ?? { kind: "leaf", value: "", assignment: [] } };
|
|
88
|
+
})
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -2,7 +2,7 @@ import { readFileSync, readdirSync } from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import postcss from "postcss";
|
|
4
4
|
import ts from "./syntax.mjs";
|
|
5
|
-
import { currentAnalysis, memoFact, memoProgram } from "./context.mjs";
|
|
5
|
+
import { currentAnalysis, memoFact, memoProgram, revisionText } from "./context.mjs";
|
|
6
6
|
import { binaryContentBytes, isAnalysisBinary } from "./captured-content.mjs";
|
|
7
7
|
export { memoFact, memoProgram } from "./context.mjs";
|
|
8
8
|
|
|
@@ -22,13 +22,11 @@ export function sourceText(file) {
|
|
|
22
22
|
return text;
|
|
23
23
|
}
|
|
24
24
|
export function optionalSourceText(file) {
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
return memoFact(context, key, () => revision ? memoProgram(revision, key, read) : read());
|
|
29
|
-
}
|
|
25
|
+
const captured = revisionText(file);
|
|
26
|
+
if (captured !== void 0)
|
|
27
|
+
return captured.text;
|
|
30
28
|
try {
|
|
31
|
-
return readFileSync(
|
|
29
|
+
return readFileSync(path.resolve(file), "utf8");
|
|
32
30
|
} catch (error) {
|
|
33
31
|
if (isMissing(error))
|
|
34
32
|
return null;
|
|
@@ -3,7 +3,6 @@ import { isTestFile } from "../config.mjs";
|
|
|
3
3
|
import { SyntaxKind, isCallExpression, isExportDeclaration, isIdentifier, isImportDeclaration, isNamedExports, isNewExpression, isStringLiteral, isTaggedTemplateExpression } from "typescript/ast";
|
|
4
4
|
import { PUBLIC_BARREL } from "./owner-source.mjs";
|
|
5
5
|
import { designUsageProblems } from "./design-usage.mjs";
|
|
6
|
-
import { publicProse } from "./prose-owners.mjs";
|
|
7
6
|
import { capturedTreeFiles, inRevision, location, sourceAst, walk } from "./helpers.mjs";
|
|
8
7
|
export const MOCK_FOLDER = "mocks";
|
|
9
8
|
const PUBLIC_ENTRY = "@ds", DYNAMIC_CALLS = ["require", "eval", "Function"], MEDIA = /\.(svg|png|jpe?g|webp|avif)$/, SCRIPT = /\.[cm]?[jt]sx?$/;
|
|
@@ -34,7 +33,7 @@ function mockMedia(dsRoot, file, statement, specifier) {
|
|
|
34
33
|
const target = path.resolve(path.dirname(file), specifier), clause = statement.importClause;
|
|
35
34
|
return MEDIA.test(target) && target.startsWith(path.join(dsRoot, MOCK_FOLDER) + path.sep) && target.split(path.sep).includes("media") && clause !== void 0 && clause.phaseModifier !== SyntaxKind.TypeKeyword && clause.name !== void 0 && clause.namedBindings === void 0;
|
|
36
35
|
}
|
|
37
|
-
async function checkFile(dsRoot, file, patterns,
|
|
36
|
+
async function checkFile(dsRoot, file, patterns, helpers) {
|
|
38
37
|
const source = await sourceAst(file), findings = [], report = (node, problem) => {
|
|
39
38
|
const at = location(node);
|
|
40
39
|
findings.push({ file, line: at.line, column: at.column, problem });
|
|
@@ -76,7 +75,7 @@ async function checkFile(dsRoot, file, patterns, prose, helpers) {
|
|
|
76
75
|
report(node, { kind: "dynamic-dependency", form: "Function" });
|
|
77
76
|
return;
|
|
78
77
|
});
|
|
79
|
-
for (const { node, problem } of designUsageProblems(source, { publicEntry: PUBLIC_ENTRY, patterns
|
|
78
|
+
for (const { node, problem } of designUsageProblems(source, { publicEntry: PUBLIC_ENTRY, patterns }))
|
|
80
79
|
report(node, problem);
|
|
81
80
|
return findings.sort((a, b) => a.line - b.line || a.column - b.column);
|
|
82
81
|
}
|
|
@@ -87,13 +86,13 @@ export async function mockFindings(dsRoot) {
|
|
|
87
86
|
const test = (file) => isTestFile(path.relative(dsRoot, file)), entries = listed.filter((file) => SCRIPT.test(file) && !file.endsWith(".d.ts") && !test(file)).sort();
|
|
88
87
|
if (entries.length === 0)
|
|
89
88
|
return [];
|
|
90
|
-
const patterns = await publicPatterns(dsRoot),
|
|
89
|
+
const patterns = await publicPatterns(dsRoot), pending = [...entries], visited = new Set, findings = [];
|
|
91
90
|
while (pending.length > 0) {
|
|
92
91
|
const file = pending.shift();
|
|
93
92
|
if (file === void 0 || visited.has(file) || test(file))
|
|
94
93
|
continue;
|
|
95
94
|
visited.add(file);
|
|
96
|
-
findings.push(...await checkFile(dsRoot, file, patterns,
|
|
95
|
+
findings.push(...await checkFile(dsRoot, file, patterns, (helper) => void pending.push(helper)));
|
|
97
96
|
}
|
|
98
97
|
return findings;
|
|
99
98
|
}
|
|
@@ -84,6 +84,12 @@ function openProjects() {
|
|
|
84
84
|
holder[OPEN_PROJECTS] ??= new Set;
|
|
85
85
|
return holder[OPEN_PROJECTS];
|
|
86
86
|
}
|
|
87
|
+
function compilerHandles(api) {
|
|
88
|
+
const child = api.client?.process;
|
|
89
|
+
if (child === void 0)
|
|
90
|
+
return [];
|
|
91
|
+
return [child, child.stdin, child.stdout].filter((handle) => handle !== null && handle !== void 0);
|
|
92
|
+
}
|
|
87
93
|
|
|
88
94
|
export class NativeProject {
|
|
89
95
|
root;
|
|
@@ -402,6 +408,12 @@ export class NativeProject {
|
|
|
402
408
|
await snapshot.dispose();
|
|
403
409
|
state.snapshots.clear();
|
|
404
410
|
}
|
|
411
|
+
holdsProcess(hold) {
|
|
412
|
+
const handles = compilerHandles(this.#api);
|
|
413
|
+
for (const handle of handles)
|
|
414
|
+
(hold ? handle.ref : handle.unref)?.call(handle);
|
|
415
|
+
return handles.length > 0;
|
|
416
|
+
}
|
|
405
417
|
close() {
|
|
406
418
|
this.#closing ??= this.#close();
|
|
407
419
|
return this.#closing;
|
|
@@ -24,19 +24,19 @@ function literal(opening, name) {
|
|
|
24
24
|
return value !== void 0 && (isStringLiteral(value) || isNoSubstitutionTemplateLiteral(value)) ? value.text : null;
|
|
25
25
|
}
|
|
26
26
|
const literalRole = (opening) => literal(opening, "role"), NOT_TEXT = new Set(["checkbox", "radio", "file", "range", "color", "date", "datetime-local", "month", "time", "week", "button", "submit", "reset", "hidden", "image", "number"]);
|
|
27
|
-
export function missingAutocomplete(opening, component) {
|
|
27
|
+
export function missingAutocomplete(opening, component, tag = opening.tagName.getText()) {
|
|
28
28
|
if (attribute(opening, "autoComplete") !== void 0)
|
|
29
29
|
return null;
|
|
30
|
-
const
|
|
30
|
+
const type = literal(opening, "type");
|
|
31
31
|
if (!component && tag !== "textarea" && !(tag === "input" && (type === null || !NOT_TEXT.has(type.toLowerCase()))))
|
|
32
32
|
return null;
|
|
33
33
|
if (!component && tag === "input" && type === null && attribute(opening, "type") !== void 0)
|
|
34
34
|
return null;
|
|
35
35
|
return suggestedAutocomplete({ name: literal(opening, "name"), id: literal(opening, "id"), type });
|
|
36
36
|
}
|
|
37
|
-
export function clickWithoutKeyboard(opening) {
|
|
37
|
+
export function clickWithoutKeyboard(opening, tag = opening.tagName.getText()) {
|
|
38
38
|
const click = attribute(opening, "onClick");
|
|
39
|
-
if (click === void 0 || !NON_INTERACTIVE.has(
|
|
39
|
+
if (click === void 0 || !NON_INTERACTIVE.has(tag))
|
|
40
40
|
return !1;
|
|
41
41
|
if (/\bcurrentTarget\b/.test(click.getText()))
|
|
42
42
|
return !1;
|
|
@@ -5,55 +5,96 @@ const within = (file, root) => {
|
|
|
5
5
|
return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
6
6
|
};
|
|
7
7
|
export function createOwnerAnalysisCache(bounds = DEFAULT_OWNER_CACHE_BOUNDS) {
|
|
8
|
-
const slots = new Map,
|
|
8
|
+
const slots = new Map, keysByRoot = new Map, useRoot = (key, slot, root) => {
|
|
9
|
+
slot.roots.add(root);
|
|
10
|
+
let keys = keysByRoot.get(root);
|
|
11
|
+
if (keys === void 0)
|
|
12
|
+
keysByRoot.set(root, keys = new Set);
|
|
13
|
+
keys.add(key);
|
|
14
|
+
}, dropSlot = (key) => {
|
|
15
|
+
const slot = slots.get(key);
|
|
16
|
+
if (slot === void 0)
|
|
17
|
+
return;
|
|
18
|
+
slots.delete(key);
|
|
19
|
+
for (const root of slot.roots) {
|
|
20
|
+
const keys = keysByRoot.get(root);
|
|
21
|
+
keys?.delete(key);
|
|
22
|
+
if (keys?.size === 0)
|
|
23
|
+
keysByRoot.delete(root);
|
|
24
|
+
}
|
|
25
|
+
}, pending = new Map, pendingRoots = new Map, touch = (key, slot) => {
|
|
9
26
|
slots.delete(key);
|
|
10
27
|
slots.set(key, slot);
|
|
11
|
-
}, settled = (lookup) => {
|
|
28
|
+
}, settled = (lookup, { relocate, accept }) => {
|
|
12
29
|
const slot = slots.get(lookup.key);
|
|
13
30
|
if (slot === void 0)
|
|
14
31
|
return;
|
|
32
|
+
const moved = (entries) => {
|
|
33
|
+
if (slot.origin !== lookup.root && relocate === void 0)
|
|
34
|
+
return;
|
|
35
|
+
const index = accept === void 0 ? 0 : entries.findIndex((entry) => accept(entry.design)), entry = entries[index];
|
|
36
|
+
if (entry === void 0)
|
|
37
|
+
return;
|
|
38
|
+
entries.splice(index, 1);
|
|
39
|
+
entries.unshift(entry);
|
|
40
|
+
if (slot.origin === lookup.root)
|
|
41
|
+
return entry.outcome;
|
|
42
|
+
useRoot(lookup.key, slot, lookup.root);
|
|
43
|
+
return relocate?.(entry.outcome, slot.origin, lookup.root);
|
|
44
|
+
};
|
|
15
45
|
switch (slot.kind) {
|
|
16
46
|
case "token-independent":
|
|
17
47
|
touch(lookup.key, slot);
|
|
18
|
-
return slot.
|
|
48
|
+
return moved(slot.entries);
|
|
19
49
|
case "token-dependent": {
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
50
|
+
const entries = slot.variants.get(lookup.tokens);
|
|
51
|
+
if (entries === void 0)
|
|
22
52
|
return;
|
|
23
53
|
slot.variants.delete(lookup.tokens);
|
|
24
|
-
slot.variants.set(lookup.tokens,
|
|
54
|
+
slot.variants.set(lookup.tokens, entries);
|
|
25
55
|
touch(lookup.key, slot);
|
|
26
|
-
return
|
|
56
|
+
return moved(entries);
|
|
27
57
|
}
|
|
28
58
|
}
|
|
29
59
|
}, store = (lookup, result) => {
|
|
30
|
-
const previous = slots.get(lookup.key);
|
|
60
|
+
const previous = slots.get(lookup.key), entry = { outcome: result.outcome, design: result.design }, withEntry = (earlier) => [entry, ...earlier ?? []].slice(0, bounds.variants);
|
|
31
61
|
switch (result.tokens.kind) {
|
|
32
|
-
case "token-independent":
|
|
33
|
-
|
|
62
|
+
case "token-independent": {
|
|
63
|
+
const kept = previous?.kind === "token-independent" && previous.origin === lookup.root;
|
|
64
|
+
if (!kept)
|
|
65
|
+
dropSlot(lookup.key);
|
|
66
|
+
const slot = { kind: "token-independent", origin: lookup.root, roots: kept ? previous.roots : new Set, entries: withEntry(kept ? previous.entries : void 0) };
|
|
67
|
+
touch(lookup.key, slot);
|
|
68
|
+
useRoot(lookup.key, slot, lookup.root);
|
|
34
69
|
break;
|
|
70
|
+
}
|
|
35
71
|
case "token-dependent": {
|
|
36
|
-
const
|
|
72
|
+
const kept = previous?.kind === "token-dependent" && previous.origin === lookup.root, variants = kept ? previous.variants : new Map, earlier = variants.get(lookup.tokens);
|
|
37
73
|
variants.delete(lookup.tokens);
|
|
38
|
-
variants.set(lookup.tokens,
|
|
74
|
+
variants.set(lookup.tokens, withEntry(earlier));
|
|
39
75
|
for (const oldest of variants.keys()) {
|
|
40
76
|
if (variants.size <= bounds.variants)
|
|
41
77
|
break;
|
|
42
78
|
variants.delete(oldest);
|
|
43
79
|
}
|
|
44
|
-
|
|
80
|
+
if (!kept)
|
|
81
|
+
dropSlot(lookup.key);
|
|
82
|
+
const slot = { kind: "token-dependent", origin: lookup.root, roots: kept ? previous.roots : new Set, variants };
|
|
83
|
+
touch(lookup.key, slot);
|
|
84
|
+
useRoot(lookup.key, slot, lookup.root);
|
|
45
85
|
break;
|
|
46
86
|
}
|
|
47
87
|
}
|
|
48
88
|
for (const oldest of slots.keys()) {
|
|
49
89
|
if (slots.size <= bounds.limit)
|
|
50
90
|
break;
|
|
51
|
-
|
|
91
|
+
dropSlot(oldest);
|
|
52
92
|
}
|
|
53
93
|
}, analyzeOnce = (lookup, analyze) => {
|
|
54
94
|
const id = `${lookup.key}\x00${lookup.tokens}`, shared = pending.get(id);
|
|
55
95
|
if (shared !== void 0)
|
|
56
96
|
return shared;
|
|
97
|
+
pendingRoots.set(id, lookup.root);
|
|
57
98
|
const started = (async () => {
|
|
58
99
|
try {
|
|
59
100
|
const result = await analyze();
|
|
@@ -61,27 +102,44 @@ export function createOwnerAnalysisCache(bounds = DEFAULT_OWNER_CACHE_BOUNDS) {
|
|
|
61
102
|
return result;
|
|
62
103
|
} finally {
|
|
63
104
|
pending.delete(id);
|
|
105
|
+
pendingRoots.delete(id);
|
|
64
106
|
}
|
|
65
107
|
})();
|
|
66
108
|
pending.set(id, started);
|
|
67
109
|
return started;
|
|
68
110
|
};
|
|
69
111
|
return {
|
|
70
|
-
async obtain(lookup, analyze) {
|
|
71
|
-
const known = settled(lookup);
|
|
112
|
+
async obtain(lookup, analyze, given) {
|
|
113
|
+
const rules = typeof given === "function" ? { relocate: given } : given ?? {}, { relocate, accept } = rules, known = settled(lookup, rules);
|
|
72
114
|
if (known !== void 0)
|
|
73
115
|
return { kind: "reused", outcome: known };
|
|
74
|
-
const id = `${lookup.key}\x00${lookup.tokens}`, joined = pending.get(id);
|
|
75
|
-
if (joined !== void 0)
|
|
116
|
+
const id = `${lookup.key}\x00${lookup.tokens}`, joined = pending.get(id), from = pendingRoots.get(id);
|
|
117
|
+
if (joined !== void 0 && from !== void 0 && (relocate !== void 0 || from === lookup.root))
|
|
76
118
|
try {
|
|
77
|
-
|
|
119
|
+
const shared = await joined, { outcome } = shared;
|
|
120
|
+
if (accept !== void 0 && !accept(shared.design))
|
|
121
|
+
return { kind: "analyzed", outcome: (await analyzeOnce(lookup, analyze)).outcome };
|
|
122
|
+
if (from === lookup.root || relocate === void 0)
|
|
123
|
+
return { kind: "reused", outcome };
|
|
124
|
+
const stored = slots.get(lookup.key);
|
|
125
|
+
if (stored !== void 0)
|
|
126
|
+
useRoot(lookup.key, stored, lookup.root);
|
|
127
|
+
return { kind: "reused", outcome: relocate(outcome, from, lookup.root) };
|
|
78
128
|
} catch {}
|
|
79
129
|
return { kind: "analyzed", outcome: (await analyzeOnce(lookup, analyze)).outcome };
|
|
80
130
|
},
|
|
81
131
|
release(root) {
|
|
82
|
-
for (const [
|
|
83
|
-
if (within(
|
|
84
|
-
|
|
132
|
+
for (const [used, keys] of keysByRoot) {
|
|
133
|
+
if (!within(used, root))
|
|
134
|
+
continue;
|
|
135
|
+
keysByRoot.delete(used);
|
|
136
|
+
for (const key of keys) {
|
|
137
|
+
const slot = slots.get(key);
|
|
138
|
+
slot?.roots.delete(used);
|
|
139
|
+
if (slot !== void 0 && slot.roots.size === 0)
|
|
140
|
+
dropSlot(key);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
85
143
|
},
|
|
86
144
|
size: () => slots.size
|
|
87
145
|
};
|
|
@@ -108,7 +166,10 @@ function projectRegistry(bounds) {
|
|
|
108
166
|
clear: () => projects.clear()
|
|
109
167
|
};
|
|
110
168
|
}
|
|
111
|
-
const ownerProjects = projectRegistry(DEFAULT_OWNER_CACHE_BOUNDS), scenarioProjects = projectRegistry({ limit: 2048, variants: 1 });
|
|
169
|
+
const ownerProjects = projectRegistry(DEFAULT_OWNER_CACHE_BOUNDS), scenarioProjects = projectRegistry({ limit: 2048, variants: 1 }), constructionProjects = projectRegistry({ limit: 8192, variants: 2 });
|
|
170
|
+
export function projectConstructionCache(owner) {
|
|
171
|
+
return constructionProjects.of(owner);
|
|
172
|
+
}
|
|
112
173
|
export function projectOwnerCache(owner) {
|
|
113
174
|
return ownerProjects.of(owner);
|
|
114
175
|
}
|
|
@@ -118,8 +179,10 @@ export function projectScenarioCache(owner) {
|
|
|
118
179
|
export function releaseOwnerAnalyses(root) {
|
|
119
180
|
ownerProjects.release(root);
|
|
120
181
|
scenarioProjects.release(root);
|
|
182
|
+
constructionProjects.release(root);
|
|
121
183
|
}
|
|
122
184
|
export function clearOwnerAnalyses() {
|
|
123
185
|
ownerProjects.clear();
|
|
124
186
|
scenarioProjects.clear();
|
|
187
|
+
constructionProjects.clear();
|
|
125
188
|
}
|