@reqvire-org/ads 0.5.1 → 0.5.2
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 +110 -25
- 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/factored-classes.mjs +90 -0
- package/dist/analysis/helpers.mjs +5 -7
- package/dist/analysis/native-project.mjs +12 -0
- package/dist/analysis/owner-analysis-cache.mjs +86 -23
- package/dist/analysis/owner-analysis-key.mjs +42 -10
- package/dist/analysis/owner-choices.mjs +23 -4
- package/dist/analysis/owner-composition.mjs +118 -33
- package/dist/analysis/owner-reuse.mjs +8 -6
- package/dist/analysis/owner-source.mjs +253 -76
- 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-keyline.mjs +2 -2
- package/dist/config.mjs +2 -1
- package/dist/construction-output.mjs +3 -2
- package/dist/construction-spec.d.mts +111 -6
- package/dist/construction-spec.mjs +172 -30
- package/dist/corner-overpaint.mjs +16 -4
- package/dist/derived-states.mjs +182 -0
- package/dist/design-inputs.mjs +18 -3
- package/dist/design-system-closure.mjs +12 -7
- package/dist/emit/contract.mjs +24 -5
- package/dist/emit/emission.mjs +6 -4
- 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/hover-geometry.mjs +15 -0
- package/dist/input-digests.mjs +17 -10
- package/dist/linaria/delivery.mjs +2 -0
- package/dist/lowering-properties.mjs +5 -0
- package/dist/lowering-region-layout.mjs +7 -2
- 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/motion-model.mjs +1 -1
- package/dist/owner-analysis-check.mjs +19 -5
- package/dist/owner-errors.mjs +4 -2
- package/dist/owner-lowering.mjs +71 -12
- package/dist/owner-scenarios.mjs +4 -1
- package/dist/ownership-model.mjs +18 -4
- package/dist/placeholder-contrast.mjs +17 -1
- package/dist/platform-features.mjs +10 -1
- package/dist/profile-view-facts.mjs +1 -1
- package/dist/recipe-macro.d.mts +72 -13
- package/dist/recipe-model.mjs +9 -5
- package/dist/region-lowering.mjs +238 -40
- 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 +5 -0
- package/dist/role-vocabulary.mjs +12 -1
- package/dist/scenarios-compiler.mjs +20 -6
- package/dist/showcase/assets-view.mjs +29 -13
- package/dist/showcase/client.bundle.js +32 -32
- package/dist/showcase/http-client.bundle.js +15 -15
- package/dist/showcase/ui/ui.css +1 -1
- package/dist/showcase/ui/ui.js +4 -4
- package/dist/skills/ads-designer/references/accessibility.md +7 -0
- 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 +1 -1
- package/dist/skills/ads-designer/references/layout.md +5 -1
- package/dist/skills/ads-designer/references/motion.md +9 -1
- package/dist/skills/ads-designer/references/recipes.md +27 -3
- package/dist/skills/ads-import/references/contracts.md +5 -2
- package/dist/skills/ads-import/references/design-data.md +1 -1
- package/dist/skills/ads-import/references/layout.md +5 -1
- package/dist/skills/ads-import/references/recipes.md +27 -3
- package/dist/skills/ads-migrate/SKILL.md +1 -0
- package/dist/skills/ads-migrate/references/0.5.1-to-0.5.2.md +185 -0
- package/dist/skills/ads-port/references/contracts.md +5 -2
- package/dist/skills/ads-port/references/design-data.md +1 -1
- package/dist/skills/ads-port/references/layout.md +5 -1
- package/dist/skills/ads-port/references/recipes.md +27 -3
- package/dist/surface-contrast.mjs +1 -0
- package/dist/surface-effects.mjs +5 -3
- package/dist/task-cache.mjs +8 -18
- package/dist/validation-checks.mjs +1 -1
- package/docs/ARCHITECTURE.md +63 -7
- package/docs/CACHING.md +152 -24
- package/docs/CHANGELOG.md +200 -23
- package/docs/GUIDE.md +45 -1
- package/docs/LANGUAGE.md +146 -8
- package/docs/MOTION.md +10 -2
- package/docs/PROFILE-KINDS.md +9 -1
- package/docs/RULES.md +22 -14
- package/docs/TOKEN-ROLES.md +7 -1
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -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
|
}
|
|
@@ -2,7 +2,7 @@ import path from "node:path";
|
|
|
2
2
|
import { SyntaxKind, isExportAssignment, isExportDeclaration, isImportDeclaration } from "typescript/ast";
|
|
3
3
|
import { digest } from "../digest.mjs";
|
|
4
4
|
import { memoProgram } from "./context.mjs";
|
|
5
|
-
export const OWNER_ANALYSIS_SCHEMA = "ads-owner-analysis/
|
|
5
|
+
export const OWNER_ANALYSIS_SCHEMA = "ads-owner-analysis/11";
|
|
6
6
|
export function canonical(value) {
|
|
7
7
|
return JSON.stringify(value, (_key, item) => {
|
|
8
8
|
if (item instanceof Map)
|
|
@@ -17,17 +17,19 @@ export function canonical(value) {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
const assetDigests = new WeakMap;
|
|
20
|
-
export function assetsDigest(assets) {
|
|
21
|
-
const
|
|
20
|
+
export function assetsDigest(assets, root = "") {
|
|
21
|
+
const byRoot = assetDigests.get(assets) ?? new Map;
|
|
22
|
+
assetDigests.set(assets, byRoot);
|
|
23
|
+
const known = byRoot.get(root);
|
|
22
24
|
if (known !== void 0)
|
|
23
25
|
return known;
|
|
24
|
-
const computed = digest(canonical(assets));
|
|
25
|
-
|
|
26
|
+
const computed = digest(rootRelative(canonical(assets), root));
|
|
27
|
+
byRoot.set(root, computed);
|
|
26
28
|
return computed;
|
|
27
29
|
}
|
|
28
|
-
export function designDigests(captured, assets) {
|
|
30
|
+
export function designDigests(captured, assets, root = "") {
|
|
29
31
|
const under = (folder) => digest([...captured].filter(([name]) => name.startsWith(`${folder}/`)));
|
|
30
|
-
return { profiles: under("profiles"), tokens: under("tokens"), assets: assetsDigest(assets) };
|
|
32
|
+
return { profiles: under("profiles"), tokens: under("tokens"), assets: assetsDigest(assets, root) };
|
|
31
33
|
}
|
|
32
34
|
const AUGMENTATION = /\bdeclare\s+(?:global|module)\b/, exported = (statement) => ("modifiers" in statement) && Array.isArray(statement.modifiers) && statement.modifiers.some((modifier) => modifier.kind === SyntaxKind.ExportKeyword);
|
|
33
35
|
export function declaresGlobally(source) {
|
|
@@ -69,8 +71,6 @@ export function ownerAnalysisKey(facts, graph, owner, barrel, owners, settled, c
|
|
|
69
71
|
contexts: facts.contexts,
|
|
70
72
|
sources: files.map(facts.source),
|
|
71
73
|
globals: facts.globals,
|
|
72
|
-
profiles: facts.design.profiles,
|
|
73
|
-
assets: facts.design.assets,
|
|
74
74
|
rows
|
|
75
75
|
};
|
|
76
76
|
}
|
|
@@ -84,7 +84,39 @@ function closureRows(owner, settled) {
|
|
|
84
84
|
return { kind: "unavailable", owner };
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
export const keyDigest = (key) => digest(canonical(key));
|
|
87
|
+
export const keyDigest = (key) => digest(rootRelative(canonical({ ...key, root: "" }), key.root));
|
|
88
|
+
export function rootRelative(text, root) {
|
|
89
|
+
if (root === "")
|
|
90
|
+
return text;
|
|
91
|
+
const escaped = JSON.stringify(root).slice(1, -1);
|
|
92
|
+
return text.split(escaped).join("<root>");
|
|
93
|
+
}
|
|
94
|
+
export function relocateOutcome(outcome, from, to) {
|
|
95
|
+
if (from === to)
|
|
96
|
+
return outcome;
|
|
97
|
+
const move = (value) => {
|
|
98
|
+
if (typeof value === "string")
|
|
99
|
+
return value === from ? to : value.includes(from) ? value.split(`${from}${path.sep}`).join(`${to}${path.sep}`) : value;
|
|
100
|
+
if (Array.isArray(value)) {
|
|
101
|
+
const items = value.map(move);
|
|
102
|
+
return items.some((item, index) => item !== value[index]) ? items : value;
|
|
103
|
+
}
|
|
104
|
+
if (value instanceof Map) {
|
|
105
|
+
const entries = [...value].map(([key, item]) => [key, item, move(key), move(item)]);
|
|
106
|
+
return entries.some(([key, item, movedKey, movedItem]) => key !== movedKey || item !== movedItem) ? new Map(entries.map(([, , key, item]) => [key, item])) : value;
|
|
107
|
+
}
|
|
108
|
+
if (value instanceof Set) {
|
|
109
|
+
const items = [...value].map((item) => [item, move(item)]);
|
|
110
|
+
return items.some(([item, moved]) => item !== moved) ? new Set(items.map(([, moved]) => moved)) : value;
|
|
111
|
+
}
|
|
112
|
+
if (value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) {
|
|
113
|
+
const entries = Object.entries(value).map(([key, item]) => [key, item, move(item)]);
|
|
114
|
+
return entries.some(([, item, moved]) => item !== moved) ? Object.fromEntries(entries.map(([key, , moved]) => [key, moved])) : value;
|
|
115
|
+
}
|
|
116
|
+
return value;
|
|
117
|
+
};
|
|
118
|
+
return move(outcome);
|
|
119
|
+
}
|
|
88
120
|
export function traceTokenReads(foundation) {
|
|
89
121
|
let read = !1;
|
|
90
122
|
const mark = (value) => {
|
|
@@ -43,7 +43,21 @@ import {
|
|
|
43
43
|
import { isJsonObject, jsonObject } from "../json.mjs";
|
|
44
44
|
import { combineRecipes, recipe } from "../recipe-model.mjs";
|
|
45
45
|
import { normalizeValueFailure } from "../construction-spec.mjs";
|
|
46
|
-
|
|
46
|
+
function nestedParts(parts, name) {
|
|
47
|
+
const found = [], visit = (declared, top) => {
|
|
48
|
+
if (declared === void 0 || !isJsonObject(declared))
|
|
49
|
+
return;
|
|
50
|
+
for (const [key, part] of Object.entries(declared)) {
|
|
51
|
+
if (!top && key === name)
|
|
52
|
+
found.push(part);
|
|
53
|
+
if (isJsonObject(part))
|
|
54
|
+
visit(part.parts, !1);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
visit(parts, !0);
|
|
58
|
+
return found;
|
|
59
|
+
}
|
|
60
|
+
export const choiceLimits = Object.freeze({ depth: 64, steps: 20000, branches: 16384, alternatives: 4096 }), RECIPE_MODULE = "@reqvire-org/ads/recipe";
|
|
47
61
|
const tagged = (value) => typeof value === "object" && value !== null;
|
|
48
62
|
export function authoredAt(calls, specPath) {
|
|
49
63
|
const keys = specPath.split(".").slice(1);
|
|
@@ -459,7 +473,10 @@ export async function choiceValues({ program, source, root, validateSpec, fail }
|
|
|
459
473
|
return incomplete(context, node, { kind: "recipe-access-unsupported", key });
|
|
460
474
|
case "parts":
|
|
461
475
|
case "assets": {
|
|
462
|
-
const parts = object.handle.descriptor.spec.parts,
|
|
476
|
+
const parts = object.handle.descriptor.spec.parts, top = parts !== void 0 && isJsonObject(parts) ? parts[key] : void 0, nested = top === void 0 ? nestedParts(parts, key) : [];
|
|
477
|
+
if (nested.length > 1)
|
|
478
|
+
return incomplete(context, node, { kind: "part-ambiguous", name: key });
|
|
479
|
+
const part = top ?? nested[0];
|
|
463
480
|
if (part === void 0)
|
|
464
481
|
return incomplete(context, node, { kind: "part-unknown", name: key });
|
|
465
482
|
return { kind: object.kind === "parts" ? "asset-class" : "asset", handle: object.handle, part, name: key };
|
|
@@ -821,8 +838,10 @@ export async function choiceValues({ program, source, root, validateSpec, fail }
|
|
|
821
838
|
let branches = 0;
|
|
822
839
|
const leaves = [], selectedAxes = new Map;
|
|
823
840
|
async function visit(assignment) {
|
|
824
|
-
if (++branches > choiceLimits.branches)
|
|
825
|
-
|
|
841
|
+
if (++branches > choiceLimits.branches) {
|
|
842
|
+
const axes = [...selectedAxes.values()].map((axis) => ({ name: axis.name ?? axis.expression, values: axis.domain.length })).sort((a, b) => b.values - a.values || (a.name < b.name ? -1 : 1));
|
|
843
|
+
return failure(node, { kind: "choice", problem: { kind: "branch-limit", limit: choiceLimits.branches, axes } });
|
|
844
|
+
}
|
|
826
845
|
if (!await possible(assignment, [...selectedAxes.values()], tolerant))
|
|
827
846
|
return null;
|
|
828
847
|
const outcome = await attemptAsync((need) => resolve({ assignment, memo: new Map, stack: new Set, budget: { steps: 0 }, depth: 0, need, ...tolerant === void 0 ? {} : { fail: tolerant } }, evaluate));
|
|
@@ -45,8 +45,9 @@ import { TypeFlags } from "typescript/async";
|
|
|
45
45
|
import { selectedProfile } from "../design-foundation.mjs";
|
|
46
46
|
import { parseConstruction } from "../construction-spec.mjs";
|
|
47
47
|
import { combineRecipes } from "../recipe-model.mjs";
|
|
48
|
+
import { relevantAxes } from "./composition-axes.mjs";
|
|
48
49
|
import { surfacedElements } from "../surface-contrast.mjs";
|
|
49
|
-
import { frameInlinePadding, gridKeylineOf } from "../frame-regions.mjs";
|
|
50
|
+
import { frameInlinePadding, gridKeylineOf, rootFrames } from "../frame-regions.mjs";
|
|
50
51
|
import { attemptAsync } from "../result.mjs";
|
|
51
52
|
import { location, nodesOfKind } from "./native-boundary.mjs";
|
|
52
53
|
import { authoredAt, classItems, mapCallback, nameText, presenceDomain, truthiness } from "./owner-choices.mjs";
|
|
@@ -330,13 +331,51 @@ export async function compositionFacts(inputs) {
|
|
|
330
331
|
return !0;
|
|
331
332
|
const last = isBlock(statement) ? statement.statements.at(-1) : void 0;
|
|
332
333
|
return last !== void 0 && isReturnStatement(last);
|
|
333
|
-
},
|
|
334
|
+
}, reads = new Map, inputKey = (assignment, inputs) => inputs.map((id) => assignment.has(id) ? JSON.stringify(assignment.get(id) ?? null) : "\x01").join("\x00");
|
|
335
|
+
async function byInputs(cache, node, context, compute) {
|
|
336
|
+
const known = cache.get(node) ?? [];
|
|
337
|
+
for (const entry of known) {
|
|
338
|
+
const hit = entry.results.get(inputKey(context.assignment, entry.inputs));
|
|
339
|
+
if (hit !== void 0)
|
|
340
|
+
return hit;
|
|
341
|
+
}
|
|
342
|
+
const inputs = new Set;
|
|
343
|
+
let whole = !1;
|
|
344
|
+
const all = (value) => (whole = !0, value), recording = {
|
|
345
|
+
get: (id) => (inputs.add(id), context.assignment.get(id)),
|
|
346
|
+
has: (id) => (inputs.add(id), context.assignment.has(id)),
|
|
347
|
+
get size() {
|
|
348
|
+
return all(context.assignment.size);
|
|
349
|
+
},
|
|
350
|
+
forEach: (callback, thisArg) => all(context.assignment.forEach(callback, thisArg)),
|
|
351
|
+
entries: () => all(context.assignment.entries()),
|
|
352
|
+
keys: () => all(context.assignment.keys()),
|
|
353
|
+
values: () => all(context.assignment.values()),
|
|
354
|
+
[Symbol.iterator]: () => all(context.assignment[Symbol.iterator]())
|
|
355
|
+
}, result = await compute({ ...context, assignment: recording });
|
|
356
|
+
if (whole)
|
|
357
|
+
return result;
|
|
358
|
+
const listed = [...inputs].sort();
|
|
359
|
+
let entry = known.find((candidate) => candidate.inputs.join("\x00") === listed.join("\x00"));
|
|
360
|
+
if (entry === void 0) {
|
|
361
|
+
known.push(entry = { inputs: listed, results: new Map });
|
|
362
|
+
cache.set(node, known);
|
|
363
|
+
}
|
|
364
|
+
entry.results.set(inputKey(context.assignment, listed), result);
|
|
365
|
+
return result;
|
|
366
|
+
}
|
|
367
|
+
const optional = async (node, context, evaluate) => {
|
|
334
368
|
if (node === void 0)
|
|
335
369
|
return { known: !0, value: void 0 };
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
370
|
+
return byInputs(reads, node, context, async (recorded) => {
|
|
371
|
+
const read = await attemptAsync((reject) => evaluate(node, { ...recorded, fail: () => reject(null) }));
|
|
372
|
+
return read.kind === "ok" ? { known: !0, value: read.value } : { known: !1 };
|
|
373
|
+
});
|
|
374
|
+
}, elements = new Map, holds = (read) => read.known ? truthiness(read.value) : null, truthy = (value) => truthiness(value) === !0;
|
|
375
|
+
function rawElement(opening, context, evaluate) {
|
|
376
|
+
return byInputs(elements, opening, context, (recorded) => readElement(opening, recorded, evaluate));
|
|
377
|
+
}
|
|
378
|
+
async function readElement(opening, context, evaluate) {
|
|
340
379
|
const tag = tagOf(opening), classAttribute = attributeOf(opening, "className");
|
|
341
380
|
let classes = { fragments: [], calls: [], markers: [] };
|
|
342
381
|
if (classAttribute !== void 0) {
|
|
@@ -444,7 +483,10 @@ export async function compositionFacts(inputs) {
|
|
|
444
483
|
const node = raw.opening;
|
|
445
484
|
if (raw.classes === null)
|
|
446
485
|
return { surfaces: null, text: null, scope: null, flow: "in", parts: null, grid: null, frame: void 0, keyline: void 0 };
|
|
447
|
-
const { markers, calls } = raw.classes, part = parent?.parts?.list.find((candidate) => markers.includes(candidate.selector.slice(1))) ?? null, cell = parent?.grid?.spec.cells.find((candidate) => markers.includes(candidate.selector.slice(1))) ?? null, overlay = cell !== null && [cell.values, ...cell.at.map(([, values]) => values)].some((values) => values.some(([key, value]) => key === "overlay" && value !== "none")), own = constructionOf(raw.classes), framed = own === null ? null : frameInlinePadding(foundation, own),
|
|
486
|
+
const { markers, calls } = raw.classes, part = parent?.parts?.list.find((candidate) => markers.includes(candidate.selector.slice(1))) ?? null, cell = parent?.grid?.spec.cells.find((candidate) => markers.includes(candidate.selector.slice(1))) ?? null, overlay = cell !== null && [cell.values, ...cell.at.map(([, values]) => values)].some((values) => values.some(([key, value]) => key === "overlay" && value !== "none")), own = constructionOf(raw.classes), framed = own === null ? null : frameInlinePadding(foundation, own), stated = framed === null ? [] : rootFrames(own).flatMap((under) => {
|
|
487
|
+
const selected = under === void 0 ? null : frameInlinePadding(foundation, own, under);
|
|
488
|
+
return selected === null ? [] : [{ name: selected.frame, padding: selected.padding }];
|
|
489
|
+
}), frame = framed === null ? void 0 : { name: framed.frame, padding: framed.padding, ...stated.length === 0 ? {} : { states: stated } }, keyline = own?.kind === "grid" ? gridKeylineOf(foundation, own) ?? void 0 : void 0, scope = String(node.getStart(source));
|
|
448
490
|
let surfaces = [], text = null, flow = overlay ? "overlay" : "in", parts = null, grid = null, ownScope = null;
|
|
449
491
|
if (part !== null && parent?.parts !== null && parent?.parts !== void 0) {
|
|
450
492
|
const { spec, prefix, calls: partCalls } = parent.parts, partPath = `${prefix}.${part.name}`;
|
|
@@ -587,7 +629,30 @@ export async function compositionFacts(inputs) {
|
|
|
587
629
|
if (item.opening !== null)
|
|
588
630
|
placementIndex.set(item.opening, index);
|
|
589
631
|
});
|
|
590
|
-
const positions = []
|
|
632
|
+
const positions = [], byPath = new Map, nodeIds = new WeakMap, nodeId = (node) => {
|
|
633
|
+
let known = nodeIds.get(node);
|
|
634
|
+
if (known === void 0)
|
|
635
|
+
nodeIds.set(node, known = nextNode++);
|
|
636
|
+
return known;
|
|
637
|
+
};
|
|
638
|
+
let nextNode = 0;
|
|
639
|
+
const pathSignature = (pathed) => JSON.stringify([
|
|
640
|
+
pathed.steps.map((step) => {
|
|
641
|
+
switch (step.kind) {
|
|
642
|
+
case "element":
|
|
643
|
+
return ["e", nodeId(step.opening)];
|
|
644
|
+
case "slot":
|
|
645
|
+
return ["s", nodeId(step.opening), step.prop];
|
|
646
|
+
case "and":
|
|
647
|
+
return ["a", nodeId(step.left)];
|
|
648
|
+
case "branch":
|
|
649
|
+
return ["b", nodeId(step.condition), step.when];
|
|
650
|
+
case "returns":
|
|
651
|
+
return ["r", step.conditions.map(nodeId)];
|
|
652
|
+
}
|
|
653
|
+
}),
|
|
654
|
+
pathed.end.kind === "root" ? ["root", pathed.end.component, nodeId(pathed.end.fn)] : ["unknown", pathed.end.reason, nodeId(pathed.end.at)]
|
|
655
|
+
]);
|
|
591
656
|
for (const item of pending) {
|
|
592
657
|
const { path: pathed } = item, component = pathed.end.kind === "root" ? pathed.end.component : pathed.end.component;
|
|
593
658
|
if (component === null) {
|
|
@@ -595,42 +660,62 @@ export async function compositionFacts(inputs) {
|
|
|
595
660
|
positions.push({ component: "", content: item.content, at: point(item.at), leaves: { kind: "known", leaves: [{ segments: [{ elements: [], end }], props: [] }] } });
|
|
596
661
|
continue;
|
|
597
662
|
}
|
|
663
|
+
const signature = pathSignature(pathed);
|
|
664
|
+
let shared = byPath.get(signature);
|
|
665
|
+
if (shared === void 0)
|
|
666
|
+
byPath.set(signature, shared = leavesOf(pathed, item.node));
|
|
667
|
+
positions.push({ component, content: item.content, at: point(item.at), leaves: await shared });
|
|
668
|
+
}
|
|
669
|
+
return { positions };
|
|
670
|
+
async function leavesOf(pathed, node) {
|
|
598
671
|
const props = pathed.end.kind === "root" ? propsOf(pathed.end.fn) : null, enumerated = await attemptAsync((reject) => {
|
|
599
672
|
const tolerant = (_node, problem) => reject(problem.kind === "choice" ? problem.problem.kind : problem.kind);
|
|
600
|
-
return values.choices(
|
|
673
|
+
return values.choices(node, (context, evaluate) => resolveLeaf(pathed, context, evaluate), tolerant);
|
|
601
674
|
});
|
|
602
|
-
if (enumerated.kind === "err")
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
const axes = new Map(enumerated.value.axes.map((axis) => [axis.id, axis])), leaves = new Map;
|
|
607
|
-
for (const leaf of enumerated.value.leaves) {
|
|
675
|
+
if (enumerated.kind === "err")
|
|
676
|
+
return enumerated.error === "no-reachable-choice" ? { kind: "known", leaves: [] } : { kind: "limit" };
|
|
677
|
+
const axes = new Map(enumerated.value.axes.map((axis) => [axis.id, axis])), rootEnd = pathed.end.kind === "root" ? { kind: "root" } : { kind: "unknown", reason: pathed.end.reason, at: point(pathed.end.at) }, chains = new Map, built = enumerated.value.leaves.map((leaf) => {
|
|
608
678
|
if (leaf.value.kind === "absent")
|
|
609
|
-
|
|
610
|
-
const
|
|
611
|
-
let
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
continue;
|
|
616
|
-
}
|
|
617
|
-
const index = placementIndex.get(step.opening), end = index === void 0 ? { kind: "unknown", reason: "not-in-place", at: point(step.opening) } : { kind: "slot", placement: index, prop: step.prop };
|
|
618
|
-
segments.push({ elements: chainElements(run), end });
|
|
619
|
-
run = [];
|
|
679
|
+
return { leaf, chain: null };
|
|
680
|
+
const raw = rawSignature(leaf.value.steps);
|
|
681
|
+
let chain = chains.get(raw);
|
|
682
|
+
if (chain === void 0) {
|
|
683
|
+
const segments = segmentsOf(leaf.value.steps, rootEnd);
|
|
684
|
+
chains.set(raw, chain = { segments, text: JSON.stringify(segments) });
|
|
620
685
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
686
|
+
return { leaf, chain };
|
|
687
|
+
}), relevant = relevantAxes(built.map(({ leaf, chain }) => ({ assignment: leaf.assignment, outcome: chain === null ? "absent" : chain.text }))), leaves = new Map;
|
|
688
|
+
for (const { leaf, chain } of built) {
|
|
689
|
+
if (chain === null)
|
|
690
|
+
continue;
|
|
691
|
+
const { segments } = chain, leafProps = [];
|
|
624
692
|
for (const [id, value] of leaf.assignment) {
|
|
625
693
|
const axis = axes.get(id);
|
|
626
|
-
if (axis === void 0 || axis.name === null || props === null || axis.parameter !== props)
|
|
694
|
+
if (!relevant.has(id) || axis === void 0 || axis.name === null || props === null || axis.parameter !== props)
|
|
627
695
|
continue;
|
|
628
696
|
leafProps.push({ prop: axis.name, test: axis.test, value: literal(value) });
|
|
629
697
|
}
|
|
630
698
|
const fact = { segments, props: leafProps };
|
|
631
|
-
leaves.set(JSON.stringify(
|
|
699
|
+
leaves.set(`${chain.text}\x00${JSON.stringify(leafProps)}`, fact);
|
|
632
700
|
}
|
|
633
|
-
|
|
701
|
+
return leaves.size > LEAF_LIMIT ? { kind: "limit" } : { kind: "known", leaves: [...leaves.values()] };
|
|
702
|
+
}
|
|
703
|
+
function rawSignature(steps) {
|
|
704
|
+
return steps.map((step) => step.kind === "slot" ? `s${objectId(step.opening)}:${step.prop}` : `e${objectId(step.element)}`).join("|");
|
|
705
|
+
}
|
|
706
|
+
function segmentsOf(steps, rootEnd) {
|
|
707
|
+
const segments = [];
|
|
708
|
+
let run = [];
|
|
709
|
+
for (const step of steps) {
|
|
710
|
+
if (step.kind === "element") {
|
|
711
|
+
run.push(step.element);
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
const index = placementIndex.get(step.opening), end = index === void 0 ? { kind: "unknown", reason: "not-in-place", at: point(step.opening) } : { kind: "slot", placement: index, prop: step.prop };
|
|
715
|
+
segments.push({ elements: chainElements(run), end });
|
|
716
|
+
run = [];
|
|
717
|
+
}
|
|
718
|
+
segments.push({ elements: chainElements(run), end: rootEnd });
|
|
719
|
+
return segments;
|
|
634
720
|
}
|
|
635
|
-
return { positions };
|
|
636
721
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { designReadsMatch, traceDesignReads, wholeDesignDigests } from "./design-reads.mjs";
|
|
2
3
|
import { digest } from "../digest.mjs";
|
|
3
4
|
import { optionalSourceText } from "./helpers.mjs";
|
|
4
5
|
import {
|
|
5
6
|
canonical,
|
|
6
7
|
keyDigest,
|
|
8
|
+
relocateOutcome,
|
|
7
9
|
ownerAnalysisKey,
|
|
8
10
|
programGlobals,
|
|
9
11
|
rowsDigest,
|
|
@@ -37,7 +39,7 @@ async function pass(inputs, program, graph, keys) {
|
|
|
37
39
|
return {
|
|
38
40
|
owner: async ({ name, analyze }) => {
|
|
39
41
|
analyzed.push(name);
|
|
40
|
-
return analyze(inputs.foundation);
|
|
42
|
+
return analyze(inputs.foundation, inputs.assets);
|
|
41
43
|
},
|
|
42
44
|
scenarioStyling: (_file, compute) => obtainScenarioResult(null, inputs.root, void 0, "styling", compute),
|
|
43
45
|
tally
|
|
@@ -58,17 +60,17 @@ async function pass(inputs, program, graph, keys) {
|
|
|
58
60
|
digests.set(file, computed);
|
|
59
61
|
return computed;
|
|
60
62
|
}
|
|
61
|
-
}, rows = new Map, owner = async ({ name, settled, analyze }) => {
|
|
63
|
+
}, whole = wholeDesignDigests(inputs.foundation, inputs.design.assets), rows = new Map, owner = async ({ name, settled, analyze }) => {
|
|
62
64
|
const key = keyDigest(ownerAnalysisKey(facts, graph, name, PUBLIC_BARREL, owners, rowsOf(settled, rows), text));
|
|
63
65
|
keys.set(name, key);
|
|
64
66
|
const obtained = await inputs.cache.obtain({ key, root: inputs.root, tokens: inputs.design.tokens }, async () => {
|
|
65
|
-
const traced = traceTokenReads(inputs.foundation);
|
|
66
|
-
return { outcome: await analyze(
|
|
67
|
-
});
|
|
67
|
+
const traced = traceTokenReads(inputs.foundation), design = traceDesignReads(traced.foundation, inputs.assets, inputs.root, whole);
|
|
68
|
+
return { outcome: await analyze(design.foundation, design.assets), tokens: traced.evidence(), design: design.evidence() };
|
|
69
|
+
}, { relocate: relocateOutcome, accept: (evidence) => evidence !== void 0 && designReadsMatch(evidence, inputs.foundation, inputs.assets, inputs.root, whole) });
|
|
68
70
|
switch (obtained.kind) {
|
|
69
71
|
case "reused":
|
|
70
72
|
reused.push(name);
|
|
71
|
-
if (verifying() && canonical(await analyze(inputs.foundation)) !== canonical(obtained.outcome))
|
|
73
|
+
if (verifying() && canonical(await analyze(inputs.foundation, inputs.assets)) !== canonical(obtained.outcome))
|
|
72
74
|
throw new OwnerReuseMismatch(name);
|
|
73
75
|
break;
|
|
74
76
|
case "analyzed":
|