@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.
Files changed (114) hide show
  1. package/dist/ads-errors.mjs +110 -25
  2. package/dist/analysis/composition-axes.mjs +48 -0
  3. package/dist/analysis/construction-memo.mjs +38 -0
  4. package/dist/analysis/context.mjs +19 -0
  5. package/dist/analysis/design-reads.mjs +177 -0
  6. package/dist/analysis/factored-classes.mjs +90 -0
  7. package/dist/analysis/helpers.mjs +5 -7
  8. package/dist/analysis/native-project.mjs +12 -0
  9. package/dist/analysis/owner-analysis-cache.mjs +86 -23
  10. package/dist/analysis/owner-analysis-key.mjs +42 -10
  11. package/dist/analysis/owner-choices.mjs +23 -4
  12. package/dist/analysis/owner-composition.mjs +118 -33
  13. package/dist/analysis/owner-reuse.mjs +8 -6
  14. package/dist/analysis/owner-source.mjs +253 -76
  15. package/dist/analysis/scenario-keys.mjs +10 -7
  16. package/dist/analysis/service.mjs +50 -3
  17. package/dist/analysis/standalone.mjs +7 -4
  18. package/dist/analysis/syntax.mjs +59 -1
  19. package/dist/analysis/worker-protocol.mjs +14 -2
  20. package/dist/analysis/worker.mjs +32 -10
  21. package/dist/architecture-report.mjs +26 -0
  22. package/dist/asset-view-facts.mjs +16 -2
  23. package/dist/boundaries.mjs +26 -10
  24. package/dist/bun-compiler.mjs +2 -2
  25. package/dist/check-service.mjs +29 -17
  26. package/dist/check.mjs +13 -6
  27. package/dist/cli.mjs +1 -1
  28. package/dist/composed-keyline.mjs +2 -2
  29. package/dist/config.mjs +2 -1
  30. package/dist/construction-output.mjs +3 -2
  31. package/dist/construction-spec.d.mts +111 -6
  32. package/dist/construction-spec.mjs +172 -30
  33. package/dist/corner-overpaint.mjs +16 -4
  34. package/dist/derived-states.mjs +182 -0
  35. package/dist/design-inputs.mjs +18 -3
  36. package/dist/design-system-closure.mjs +12 -7
  37. package/dist/emit/contract.mjs +24 -5
  38. package/dist/emit/emission.mjs +6 -4
  39. package/dist/emit/integrity.mjs +8 -2
  40. package/dist/emit/output-watch.mjs +120 -0
  41. package/dist/emit/owner-emission-cache.mjs +4 -4
  42. package/dist/emit/preview-emitter.mjs +4 -2
  43. package/dist/emit/preview-tree.mjs +1 -1
  44. package/dist/emit/service.mjs +8 -2
  45. package/dist/finding-rules.mjs +3 -0
  46. package/dist/form-states.mjs +8 -0
  47. package/dist/frame-regions.mjs +29 -9
  48. package/dist/hover-geometry.mjs +15 -0
  49. package/dist/input-digests.mjs +17 -10
  50. package/dist/linaria/delivery.mjs +2 -0
  51. package/dist/lowering-properties.mjs +5 -0
  52. package/dist/lowering-region-layout.mjs +7 -2
  53. package/dist/mcp/build-status.mjs +9 -1
  54. package/dist/mcp/compiler-channel.mjs +11 -4
  55. package/dist/mcp/mutations.mjs +1 -0
  56. package/dist/mcp/preview-http.bundle.js +1 -1
  57. package/dist/mcp/preview-watch.mjs +2 -1
  58. package/dist/mcp/preview-widget.bundle.js +1 -1
  59. package/dist/motion-model.mjs +1 -1
  60. package/dist/owner-analysis-check.mjs +19 -5
  61. package/dist/owner-errors.mjs +4 -2
  62. package/dist/owner-lowering.mjs +71 -12
  63. package/dist/owner-scenarios.mjs +4 -1
  64. package/dist/ownership-model.mjs +18 -4
  65. package/dist/placeholder-contrast.mjs +17 -1
  66. package/dist/platform-features.mjs +10 -1
  67. package/dist/profile-view-facts.mjs +1 -1
  68. package/dist/recipe-macro.d.mts +72 -13
  69. package/dist/recipe-model.mjs +9 -5
  70. package/dist/region-lowering.mjs +238 -40
  71. package/dist/render-audit/layout-shift.page.mjs +24 -0
  72. package/dist/render-audit/render-states.mjs +122 -1
  73. package/dist/render-audit/render-states.page.mjs +140 -0
  74. package/dist/render-audit/worker.mjs +18 -3
  75. package/dist/render-audit.mjs +114 -1
  76. package/dist/role-vocabulary.d.mts +5 -0
  77. package/dist/role-vocabulary.mjs +12 -1
  78. package/dist/scenarios-compiler.mjs +20 -6
  79. package/dist/showcase/assets-view.mjs +29 -13
  80. package/dist/showcase/client.bundle.js +32 -32
  81. package/dist/showcase/http-client.bundle.js +15 -15
  82. package/dist/showcase/ui/ui.css +1 -1
  83. package/dist/showcase/ui/ui.js +4 -4
  84. package/dist/skills/ads-designer/references/accessibility.md +7 -0
  85. package/dist/skills/ads-designer/references/branding.md +13 -3
  86. package/dist/skills/ads-designer/references/contracts.md +5 -2
  87. package/dist/skills/ads-designer/references/design-data.md +1 -1
  88. package/dist/skills/ads-designer/references/layout.md +5 -1
  89. package/dist/skills/ads-designer/references/motion.md +9 -1
  90. package/dist/skills/ads-designer/references/recipes.md +27 -3
  91. package/dist/skills/ads-import/references/contracts.md +5 -2
  92. package/dist/skills/ads-import/references/design-data.md +1 -1
  93. package/dist/skills/ads-import/references/layout.md +5 -1
  94. package/dist/skills/ads-import/references/recipes.md +27 -3
  95. package/dist/skills/ads-migrate/SKILL.md +1 -0
  96. package/dist/skills/ads-migrate/references/0.5.1-to-0.5.2.md +185 -0
  97. package/dist/skills/ads-port/references/contracts.md +5 -2
  98. package/dist/skills/ads-port/references/design-data.md +1 -1
  99. package/dist/skills/ads-port/references/layout.md +5 -1
  100. package/dist/skills/ads-port/references/recipes.md +27 -3
  101. package/dist/surface-contrast.mjs +1 -0
  102. package/dist/surface-effects.mjs +5 -3
  103. package/dist/task-cache.mjs +8 -18
  104. package/dist/validation-checks.mjs +1 -1
  105. package/docs/ARCHITECTURE.md +63 -7
  106. package/docs/CACHING.md +152 -24
  107. package/docs/CHANGELOG.md +200 -23
  108. package/docs/GUIDE.md +45 -1
  109. package/docs/LANGUAGE.md +146 -8
  110. package/docs/MOTION.md +10 -2
  111. package/docs/PROFILE-KINDS.md +9 -1
  112. package/docs/RULES.md +22 -14
  113. package/docs/TOKEN-ROLES.md +7 -1
  114. package/package.json +1 -1
@@ -28,6 +28,7 @@ import {
28
28
  isObjectLiteralExpression,
29
29
  isParameterDeclaration,
30
30
  isParenthesizedExpression,
31
+ isPrefixUnaryExpression,
31
32
  isPropertyAccessExpression,
32
33
  isPropertyAssignment,
33
34
  isReturnStatement,
@@ -86,7 +87,8 @@ import {
86
87
  import { recipeDefaults, visualBindingRedundancy } from "../recipe-defaults.mjs";
87
88
  import { ownerScope } from "../runtime-style.mjs";
88
89
  import { runtimePaintContrast } from "../runtime-paint-contrast.mjs";
89
- import { paintUnion } from "../runtime-paint.mjs";
90
+ import { paintProperty, paintUnion } from "../runtime-paint.mjs";
91
+ import { hoverGeometry } from "../hover-geometry.mjs";
90
92
  import { checkPaintValue, declaredNames as runtimeNames, paintTypeReads, runtimeChannel, runtimeDeclarations, runtimePaths, runtimeSetter, undeclared, unused } from "./runtime-setters.mjs";
91
93
  import { digest } from "../digest.mjs";
92
94
  import { FOUNDATION_DECLARATION } from "../design-contexts.mjs";
@@ -105,8 +107,12 @@ import { appIconPlan, describeAppIcon } from "../app-icon-checks.mjs";
105
107
  import { appIconEmission, withAppIconsModule } from "../emit/app-icon-emission.mjs";
106
108
  import { withOutputPackage } from "../emit/output-package.mjs";
107
109
  import { analyzedOwners, outcomeCounts, rowsRead } from "./owner-outcomes.mjs";
108
- import { capturedTreeFiles } from "./helpers.mjs";
110
+ import { capturedTreeFiles, findNode, walk } from "./helpers.mjs";
111
+ import { factorClasses } from "./factored-classes.mjs";
109
112
  import { programGlobals } from "./owner-analysis-key.mjs";
113
+ import { memoizedConstruction } from "./construction-memo.mjs";
114
+ import { throwIfCancelled } from "./context.mjs";
115
+ import { designValueDigest } from "./design-reads.mjs";
110
116
  import { isScenarioFile } from "../config.mjs";
111
117
  import { frameworkMismatches } from "./framework-imports.mjs";
112
118
  import { CONTROLLER_FOLDER, controllerGateFailures } from "./controller-gates.mjs";
@@ -263,7 +269,8 @@ export async function checkOwners(root, names, options, reuse) {
263
269
  let plain = { modules: new Map, failures: [], placements: [] }, unemitted = [];
264
270
  await timing.timeStage("owner-facts", async () => {
265
271
  for (const name of names) {
266
- const analyze = (foundation) => checkedOwner(root, emitted, name, program, { ...options, foundation }, outcomes, (analyzed) => facts.set(name, analyzed));
272
+ throwIfCancelled();
273
+ const analyze = (foundation, assets) => checkedOwner(root, emitted, name, program, { ...options, foundation, assets }, outcomes, (analyzed) => facts.set(name, analyzed));
267
274
  outcomes.set(name, await pass.owner({ name, settled: outcomes, analyze }));
268
275
  }
269
276
  plain = await checkedPlainModules(root, graph, program, options.publicAlias, emitted, options.assets);
@@ -358,7 +365,7 @@ async function plainStyling(root, file, program) {
358
365
  return plainModuleStyling(await programSource(program, path.join(root, file)), program, program.getTypeChecker());
359
366
  }
360
367
  async function plainModule(root, file, role, program, publicAlias, emitted, catalog, fail) {
361
- const checker = program.getTypeChecker(), source = await programSource(program, path.join(root, file)), symbol = (node) => valueSymbolAt(checker, node), rewritten = await publicImports({ root, file, source, publicModule: publicAlias, symbolOf: symbol, emitted, fail }), macros = await assetMacroUse({ root, file, source, checker, symbol, catalog, fail }), artwork = { assets: [], sets: [], glyphs: macros.glyphs, support: macros.support };
368
+ const checker = program.getTypeChecker(), source = await programSource(program, path.join(root, file)), symbol = (node) => valueSymbolAt(checker, node), rewritten = await publicImports({ root, file, source, publicModule: publicAlias, symbolOf: symbol, emitted, fail }), macros = await assetMacroUse({ root, file, source, checker, symbol, catalog, fail }), artwork = { assets: [], sets: [], glyphs: macros.glyphs, support: macros.support, uses: [] };
362
369
  return { source, role, imports: rewritten.imports, statements: rewritten.statements, edits: macros.edits, artwork };
363
370
  }
364
371
  async function typeDiagnostics(root, program) {
@@ -425,7 +432,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
425
432
  const [animation] = await scriptAnimations(source, program, checker);
426
433
  if (animation !== void 0)
427
434
  return fail(animation.node, animation.problem);
428
- const scope = ownerScope(name), runtimeKey = (channel, valueName) => `${channel}:${valueName}`, declaredRuntime = new Map, macros = await assetMacroUse({ root, file: name, source, checker, symbol: values.symbol, catalog: assets, fail }), boundAssets = new Set, boundSets = new Set, references = new Set, carried = new Map, receivable = (glyph) => {
435
+ const scope = ownerScope(name), runtimeKey = (channel, valueName) => `${channel}:${valueName}`, declaredRuntime = new Map, macros = await assetMacroUse({ root, file: name, source, checker, symbol: values.symbol, catalog: assets, fail }), boundAssets = new Set, artworkUses = new Set, used = (asset, size) => void artworkUses.add(`${asset}\x00${size ?? ""}`), boundSets = new Set, references = new Set, carried = new Map, receivable = (glyph) => {
429
436
  let known = carried.get(glyph);
430
437
  if (known === void 0)
431
438
  carried.set(glyph, known = referenceAssets(checker, assets, glyph, fail));
@@ -434,7 +441,25 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
434
441
  if (at === null || restatements.get(at)?.kind === "changes")
435
442
  return;
436
443
  restatements.set(at, redundancy === null ? { kind: "changes" } : restatements.get(at) ?? { kind: "redundant", redundancy });
437
- }, styles = new Map, exposedRows = new Map, publicRowsOf = async (component) => {
444
+ }, styles = new Map, fragmentIds = new WeakMap;
445
+ let nextFragment = 0;
446
+ const fragmentId = (fragment) => {
447
+ let known = fragmentIds.get(fragment);
448
+ if (known === void 0)
449
+ fragmentIds.set(fragment, known = nextFragment++);
450
+ return known;
451
+ }, recipes = new Map, combinedOf = (fragments) => {
452
+ const id = fragments.map(fragmentId).join(",");
453
+ let known = recipes.get(id);
454
+ if (known === void 0)
455
+ recipes.set(id, known = { combined: combineRecipes(...fragments) });
456
+ return known;
457
+ }, parsedOf = (fragments) => {
458
+ const known = combinedOf(fragments);
459
+ if (known.combined.kind === "err")
460
+ return null;
461
+ return known.parsed ??= parseConstruction(known.combined.value.spec);
462
+ }, exposedRows = new Map, publicRowsOf = async (component) => {
438
463
  const declaration = (await values.symbol(component.tagName))?.valueDeclaration;
439
464
  if (declaration === void 0)
440
465
  return null;
@@ -464,20 +489,26 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
464
489
  if (attributeName === "style" || attributeName === "css")
465
490
  return fail(attribute, { kind: "raw-style", attribute: attributeName });
466
491
  }
467
- async function markup(node, context, resolve) {
492
+ async function markup(node, context, resolve, assumed) {
468
493
  const opening = openingOf(node);
469
494
  if (opening !== null)
470
495
  return [opening];
471
496
  if (isJsxFragment(node))
472
- return (await Promise.all(node.children.map((child) => markup(child, context, resolve)))).flat();
497
+ return (await Promise.all(node.children.map((child) => markup(child, context, resolve, assumed)))).flat();
473
498
  if (isJsxExpression(node))
474
- return node.expression === void 0 ? [] : markup(node.expression, context, resolve);
499
+ return node.expression === void 0 ? [] : markup(node.expression, context, resolve, assumed);
475
500
  if (isParenthesizedExpression(node))
476
- return markup(node.expression, context, resolve);
501
+ return markup(node.expression, context, resolve, assumed);
477
502
  if (isConditionalExpression(node))
478
- return markup(values.truthy(await resolve(node.condition, context), node.condition, context) ? node.whenTrue : node.whenFalse, context, resolve);
479
- if (isBinaryExpression(node) && node.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken)
480
- return values.truthy(await resolve(node.left, context), node.left, context) ? markup(node.right, context, resolve) : [];
503
+ return markup(values.truthy(await resolve(node.condition, context), node.condition, context) ? node.whenTrue : node.whenFalse, context, resolve, assumed);
504
+ if (isBinaryExpression(node) && node.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken) {
505
+ if (assumed !== void 0) {
506
+ const present = openingOf(node.right) ?? (isParenthesizedExpression(node.right) ? openingOf(node.right.expression) : null);
507
+ if (present !== null && assumed([present]))
508
+ return [present];
509
+ }
510
+ return values.truthy(await resolve(node.left, context), node.left, context) ? markup(node.right, context, resolve, assumed) : [];
511
+ }
481
512
  const mapped = mapCallback(node);
482
513
  if (mapped !== null) {
483
514
  const result = callbackResult(mapped);
@@ -487,9 +518,9 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
487
518
  return fail(node, { kind: "helper-markup" });
488
519
  return [];
489
520
  }
490
- const children = async (opening, context, resolve) => {
521
+ const children = async (opening, context, resolve, assumed) => {
491
522
  const element = elementOf(opening);
492
- return isJsxElement(element) ? (await Promise.all(element.children.map((child) => markup(child, context, resolve)))).flat() : [];
523
+ return isJsxElement(element) ? (await Promise.all(element.children.map((child) => markup(child, context, resolve, assumed)))).flat() : [];
493
524
  };
494
525
  function inlineSource(opening) {
495
526
  const html = expression(attr(opening, "dangerouslySetInnerHTML")), [field] = html !== void 0 && isObjectLiteralExpression(html) && html.properties.length === 1 ? html.properties : [];
@@ -628,7 +659,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
628
659
  const classes = split(await resolve(classAttribute, context), classAttribute);
629
660
  if (classes.fragments.length === 0)
630
661
  return null;
631
- const combined = combineRecipes(...classes.fragments), parsed = combined.kind === "ok" ? parseConstruction(combined.value.spec) : null;
662
+ const parsed = parsedOf(classes.fragments);
632
663
  return parsed?.kind === "ok" ? parsed.value : null;
633
664
  };
634
665
  let node = elementOf(opening), below = opening;
@@ -709,11 +740,58 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
709
740
  }
710
741
  return !0;
711
742
  }
743
+ let markupProps = null;
744
+ const identifiersIn = (root) => {
745
+ const found = [];
746
+ walk(root, (item) => {
747
+ if (isIdentifier(item))
748
+ found.push(item.text);
749
+ });
750
+ return found;
751
+ }, choosingProps = () => {
752
+ if (markupProps !== null)
753
+ return markupProps;
754
+ const parameters = new Set;
755
+ for (const parameter of nodesOfKind(source, SyntaxKind.Parameter, isParameterDeclaration))
756
+ walk(parameter, (item) => {
757
+ if (isBindingElement(item) && item.name !== void 0 && isIdentifier(item.name))
758
+ parameters.add(item.name.text);
759
+ });
760
+ const jsx = (expression) => expression !== void 0 && findNode(expression, (item) => isJsxElement(item) || isJsxSelfClosingElement(item) || isJsxFragment(item)) !== void 0, read = new Set, names = (condition) => {
761
+ for (const name of identifiersIn(condition))
762
+ if (parameters.has(name))
763
+ read.add(name);
764
+ };
765
+ for (const binary of nodesOfKind(source, SyntaxKind.BinaryExpression, isBinaryExpression))
766
+ if (binary.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken && jsx(binary.right))
767
+ names(binary.left);
768
+ for (const conditional of nodesOfKind(source, SyntaxKind.ConditionalExpression, isConditionalExpression))
769
+ if (jsx(conditional.whenTrue) || jsx(conditional.whenFalse))
770
+ names(conditional.condition);
771
+ markupProps = read;
772
+ return read;
773
+ }, contentAttributes = async (opening) => {
774
+ const chosen = choosingProps();
775
+ if (chosen.size === 0)
776
+ return [];
777
+ const found = [];
778
+ for (const attribute of opening.attributes.properties) {
779
+ if (!isJsxAttribute(attribute))
780
+ continue;
781
+ const name = nameText(attribute.name) ?? "";
782
+ if (!/^(?:data|aria)-/.test(name) || attribute.initializer === void 0)
783
+ continue;
784
+ if (identifiersIn(attribute.initializer).some((identifier) => chosen.has(identifier)))
785
+ found.push(name);
786
+ }
787
+ return found;
788
+ };
712
789
  async function styledChoice(opening, node, classes, context, resolve) {
713
- const combined = combineRecipes(...classes.fragments);
790
+ throwIfCancelled();
791
+ const { combined } = combinedOf(classes.fragments);
714
792
  if (combined.kind === "err")
715
793
  return fail(node, { kind: "recipe-rejected", rejection: combined.error });
716
- const { spec } = combined.value, parsed = parseConstruction(spec);
794
+ const { spec } = combined.value, parsed = parsedOf(classes.fragments) ?? parseConstruction(spec);
717
795
  if (parsed.kind === "err")
718
796
  return fail(authoredAt(classes.calls, parsed.error.kind === "parts-unsupported" ? "recipe.parts" : parsed.error.path) ?? node, { kind: "spec", failure: parsed.error });
719
797
  const defaults = recipeDefaults(foundation, parsed.value);
@@ -752,12 +830,35 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
752
830
  if (!declaredRuntime.has(key))
753
831
  declaredRuntime.set(key, { channel, name: valueName, at: authoredAt(classes.calls, specPath) ?? node });
754
832
  }
755
- const childFacts = new Map, factsOf = async (parent) => {
833
+ const childFacts = new Map, declaredNow = declaredParts(parsed.value), markersOf = (child) => {
834
+ const value = expression(attr(child, "className"));
835
+ if (value === void 0)
836
+ return [];
837
+ const text = value.getText(), named = declaredNow.map((part) => part.selector.slice(1)).filter((marker) => new RegExp(`(^|[\\s"'\`])${marker.replace(/[-]/g, "\\-")}($|[\\s"'\`$])`).test(text));
838
+ if (isStringLiteral(value) || value.kind === SyntaxKind.NoSubstitutionTemplateLiteral || value.kind === SyntaxKind.TemplateExpression)
839
+ return named;
840
+ if (isIdentifier(value)) {
841
+ const init = nodesOfKind(source, SyntaxKind.VariableDeclaration, isVariableDeclaration).find((item) => isIdentifier(item.name) && item.name.text === value.text)?.initializer?.getText() ?? "";
842
+ if (/^(?:recipe|combineRecipes)\(/.test(init))
843
+ return [];
844
+ }
845
+ return null;
846
+ }, presenceFree = (openings) => openings.every((child) => {
847
+ if (!lowercaseTag(child) || attr(child, "hidden") !== void 0)
848
+ return !1;
849
+ const markers = markersOf(child);
850
+ if (markers === null)
851
+ return !1;
852
+ const part = declaredNow.find((candidate) => markers.includes(candidate.selector.slice(1)));
853
+ if (part === void 0)
854
+ return parsed.value.kind !== "grid";
855
+ return !part.required && part.kind !== "visual" && part.scheme === null && !(parsed.value.kind === "control" && part.kind === "text");
856
+ }), factsOf = async (parent) => {
756
857
  const known = childFacts.get(parent);
757
858
  if (known !== void 0)
758
859
  return known;
759
860
  const found = [];
760
- for (const child of await children(parent, context, resolve)) {
861
+ for (const child of await children(parent, context, resolve, presenceFree)) {
761
862
  const childClass = expression(attr(child, "className"));
762
863
  found.push({
763
864
  opening: child,
@@ -770,7 +871,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
770
871
  return found;
771
872
  }, allFacts = await factsOf(opening);
772
873
  let hasText = !1, visual;
773
- const assetSources = [];
874
+ const visuals = new Map, several = parsed.value.kind === "region", assetSources = [];
774
875
  let drawings;
775
876
  const hidden = attr(opening, "hidden") === void 0 ? [] : [{ kind: "root" }], guardChild = (fact, selector, within = []) => {
776
877
  if (attr(fact.opening, "hidden") !== void 0 && fact.classes.fragments.length === 0)
@@ -845,6 +946,8 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
845
946
  guardChild(match, part.selector, part.within);
846
947
  if (part.kind === "text")
847
948
  hasText = !0;
949
+ if (parsed.value.kind === "control" && part.kind === "element")
950
+ await pointerTransparent(match.opening, part.name, context, resolve);
848
951
  if (part.kind !== "visual")
849
952
  continue;
850
953
  if (part.scheme !== null) {
@@ -859,13 +962,14 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
859
962
  if (loading === void 0 || await resolve(expression(loading), context) !== "lazy")
860
963
  return fail(loading ?? match.opening, { kind: "scheme-image-not-lazy", part: part.name, scheme: part.scheme, defaultScheme });
861
964
  }
862
- if (visual !== void 0 && !schemed)
965
+ if (visual !== void 0 && !schemed && !several)
863
966
  return fail(match.opening, { kind: "visual-binding-count" });
864
967
  schemed = !0;
865
- visual = { kind: "content-media" };
968
+ visual ??= { kind: "content-media" };
969
+ visuals.set(part.name, { fact: { kind: "content-media" }, drawings: void 0 });
866
970
  continue;
867
971
  }
868
- if (visual !== void 0)
972
+ if (visual !== void 0 && !several)
869
973
  return fail(match.opening, { kind: "visual-binding-count" });
870
974
  if (part.media === "inspected-svg") {
871
975
  if (match.classes.bindings.length > 0)
@@ -876,11 +980,13 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
876
980
  if ((await children(match.opening, context, resolve)).length > 0 || isJsxElement(elementOf(match.opening)) && elementOf(match.opening).children.some((child) => !isJsxText(child) || child.text.trim() !== ""))
877
981
  return fail(match.opening, { kind: "inspected-svg-inline", part: part.name });
878
982
  inspected = !0;
879
- visual = { kind: "inspected-svg" };
983
+ visual ??= { kind: "inspected-svg" };
984
+ visuals.set(part.name, { fact: { kind: "inspected-svg" }, drawings: void 0 });
880
985
  continue;
881
986
  }
882
987
  if (match.classes.bindings.length === 0 && parsed.value.kind === "region" && match.opening.tagName.getText() === "img") {
883
- visual = { kind: "content-media" };
988
+ visual ??= { kind: "content-media" };
989
+ visuals.set(part.name, { fact: { kind: "content-media" }, drawings: void 0 });
884
990
  continue;
885
991
  }
886
992
  const [binding] = match.classes.bindings, declared = binding === void 0 ? null : visualBinding(binding.part);
@@ -897,18 +1003,18 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
897
1003
  if (typeof selected !== "object" || selected === null || selected.kind !== "asset-source" || selected.handle.node !== binding.handle.node || selected.name !== binding.name)
898
1004
  return fail(target, { kind: "artwork-mismatch" });
899
1005
  };
1006
+ let shown;
900
1007
  switch (declared.kind) {
901
1008
  case "asset": {
902
1009
  const asset = resolveAsset(assets, declared.asset);
903
1010
  if (asset === void 0)
904
1011
  return fail(match.opening, { kind: "asset-unknown", asset: declared.asset });
905
- visual = { kind: "asset", asset, state: declared.state, visualProfile: declared.visual, theme };
906
- drawings = asset.name;
1012
+ shown = { fact: { kind: "asset", asset, state: declared.state, visualProfile: declared.visual, theme }, drawings: asset.name };
907
1013
  boundAssets.add(asset.name);
908
1014
  const target = asset.paint === "intrinsic" ? await intrinsicSource(match.opening, context, resolve) : inlineSource(match.opening);
909
1015
  await bindingSource(target);
910
1016
  await pressedPairing(opening, binding.handle.node, asset, declared.state, context, resolve);
911
- assetSources.push({ kind: "drawing", target });
1017
+ assetSources.push({ kind: "drawing", target, part: part.name, asset: asset.name });
912
1018
  break;
913
1019
  }
914
1020
  case "set": {
@@ -922,31 +1028,37 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
922
1028
  await bindingSource(lookup);
923
1029
  await pressedPairing(opening, binding.handle.node, representative, declared.state, context, resolve);
924
1030
  await checkSetKey(checker, set, key, fail);
925
- visual = { kind: "asset", asset: representative, state: declared.state, visualProfile: declared.visual, theme };
926
- drawings = drawingsIdentity(representative);
1031
+ shown = { fact: { kind: "asset", asset: representative, state: declared.state, visualProfile: declared.visual, theme }, drawings: drawingsIdentity(representative) };
927
1032
  boundSets.add(set.name);
928
- assetSources.push({ kind: "lookup", target: lookup, set, state: declared.state });
1033
+ assetSources.push({ kind: "lookup", target: lookup, set, state: declared.state, part: part.name });
929
1034
  break;
930
1035
  }
931
1036
  case "reference": {
932
1037
  const glyph = referenceForm(inlineSource(match.opening), fail), [representative] = await receivable(glyph);
933
- visual = { kind: "asset", asset: representative, state: "normal", visualProfile: declared.visual, theme };
934
- drawings = drawingsIdentity(representative);
1038
+ shown = { fact: { kind: "asset", asset: representative, state: "normal", visualProfile: declared.visual, theme }, drawings: drawingsIdentity(representative) };
935
1039
  references.add(glyph);
936
1040
  break;
937
1041
  }
938
1042
  }
1043
+ visuals.set(part.name, shown);
1044
+ if (visual === void 0) {
1045
+ visual = shown.fact;
1046
+ drawings = shown.drawings;
1047
+ }
939
1048
  }
940
1049
  for (const fact of allFacts) {
941
1050
  const shared = fact.classes.markers.filter((marker) => declaredMarkers.has(marker));
942
1051
  if (shared.length > 1)
943
1052
  return fail(fact.opening, { kind: "markers-shared", markers: shared });
944
1053
  }
945
- if (parsed.value.kind === "control" && !hasText && visual !== void 0 && !await namedByAttribute(opening, async (condition) => values.truthy(await resolve(condition, context), condition, context)))
1054
+ if (parsed.value.kind === "control" && !hasText && (visual !== void 0 || parsed.value.decor.length > 0) && !await namedByAttribute(opening, async (condition) => values.truthy(await resolve(condition, context), condition, context)))
946
1055
  return fail(opening, { kind: "control-name-missing", element: opening.tagName.getText() });
947
- const theme = visual?.kind === "asset" ? visual.theme : void 0, rootTheme = attr(opening, "data-theme");
948
- if (rootTheme !== void 0 && theme !== void 0 && await resolve(expression(rootTheme), context) !== theme.name)
949
- return fail(rootTheme, { kind: "data-theme-mismatch", expected: theme.name });
1056
+ const theme = visual?.kind === "asset" ? visual.theme : void 0, rootTheme = attr(opening, "data-theme"), boundThemes = [...new Set([...theme === void 0 ? [] : [theme.name], ...[...visuals.values()].flatMap(({ fact }) => fact.kind === "asset" ? [fact.theme.name] : [])])];
1057
+ if (rootTheme !== void 0 && boundThemes.length > 0) {
1058
+ const named = await resolve(expression(rootTheme), context), other = boundThemes.find((name) => name !== named);
1059
+ if (other !== void 0)
1060
+ return fail(rootTheme, { kind: "data-theme-mismatch", expected: other });
1061
+ }
950
1062
  if (theme !== void 0)
951
1063
  artworkThemed.add(opening);
952
1064
  const inherited = new Map, aligned = new Map;
@@ -985,37 +1097,54 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
985
1097
  ...inherited.size > 0 ? [[...inherited].map(([selector, nested]) => [selector, nested.source])] : [],
986
1098
  ...aligned.size > 0 ? [[...aligned]] : [],
987
1099
  ...writesInline ? [scope] : [],
988
- ...decorative.size > 0 ? [["decorative", ...decorative]] : []
1100
+ ...decorative.size > 0 ? [["decorative", ...decorative]] : [],
1101
+ ...visuals.size > 1 ? [[...visuals].map(([name, { fact, drawings: drawn }]) => fact.kind === "asset" ? [name, drawn, fact.state, fact.visualProfile, fact.theme.name] : [name, fact.kind])] : []
989
1102
  ], paintedBy = (element) => parsed.value.kind === "control" ? hasText ? "text" : "graphic" : element.visual ? decorative.has(element.element) ? "decorative" : "graphic" : "text", key = constructionId(digest(hidden.length > 0 ? [...identity, hidden] : identity));
990
1103
  let owned = styles.get(key);
991
1104
  if (owned === void 0) {
992
1105
  if (styles.size >= choiceLimits.alternatives)
993
1106
  return fail(node, { kind: "choice", problem: { kind: "construction-limit" } });
994
- const lowered = lower(parsed.value, foundation, `owner_${key.slice(0, 16)}`, { visual: visual ?? null, hasText, hidden, inherited, aligned, scope });
995
- if (lowered.kind === "err")
996
- return fail(node, { kind: "construction", failure: lowered.error });
997
- const misused = inactiveSurfaceActive(foundation, parsed.value);
998
- if (misused !== null)
999
- return fail(node, { kind: "construction", failure: misused });
1000
- const contrast = stateContrast(foundation, parsed.value, paintedBy);
1001
- if (contrast.kind === "err")
1002
- return fail(node, { kind: "construction", failure: contrast.error });
1003
- for (const unresolved of contrast.value)
1004
- review(node, unresolved);
1005
- const nonText = nonTextContrast(foundation, parsed.value);
1006
- if (nonText.kind === "err")
1007
- return fail(node, { kind: "construction", failure: nonText.error });
1008
- for (const unresolved of nonText.value)
1009
- review(node, unresolved);
1010
- const overpaint = cornerOverpaint(foundation, parsed.value);
1011
- if (overpaint !== null)
1012
- return fail(authoredAt(classes.calls, `recipe.parts.${overpaint.part}`) ?? node, { kind: "construction", failure: overpaint });
1013
- const painted = runtimePaintContrast(foundation, parsed.value);
1014
- if (painted.kind === "err")
1015
- return fail(node, { kind: "construction", failure: painted.error });
1016
- for (const unresolved of painted.value)
1017
- review(node, unresolved);
1018
- owned = { ...lowered.value, origins: [], surfaceUses: surfaceUses(foundation, parsed.value, lowered.value.profiles, paintedBy) };
1107
+ const rootName = `owner_${key.slice(0, 16)}`, input = { visual: visual ?? null, visuals: new Map([...visuals].map(([name, { fact }]) => [name, fact])), hasText, hidden, inherited, aligned, scope }, spec = parsed.value, built = await memoizedConstruction(options.constructions, foundation, [key, scope, drawnRecords(input, root)], (read) => {
1108
+ const reviews = [], failed = (failure, at = null) => ({ kind: "failed", failure: { path: at, item: failure }, reviews }), lowered = lower(spec, read, rootName, input);
1109
+ if (lowered.kind === "err")
1110
+ return failed(lowered.error);
1111
+ const misused = inactiveSurfaceActive(read, spec);
1112
+ if (misused !== null)
1113
+ return failed(misused);
1114
+ const contrast = stateContrast(read, spec, paintedBy);
1115
+ if (contrast.kind === "err")
1116
+ return failed(contrast.error);
1117
+ for (const unresolved of contrast.value)
1118
+ reviews.push({ path: null, item: unresolved });
1119
+ const nonText = nonTextContrast(read, spec);
1120
+ if (nonText.kind === "err")
1121
+ return failed(nonText.error);
1122
+ for (const unresolved of nonText.value)
1123
+ reviews.push({ path: null, item: unresolved });
1124
+ const overpaint = cornerOverpaint(read, spec);
1125
+ if (overpaint !== null)
1126
+ return failed(overpaint, `recipe.parts.${overpaint.part}`);
1127
+ const painted = runtimePaintContrast(read, spec);
1128
+ if (painted.kind === "err")
1129
+ return failed(painted.error);
1130
+ for (const unresolved of painted.value)
1131
+ reviews.push({ path: null, item: unresolved });
1132
+ for (const shifted of hoverGeometry(spec))
1133
+ reviews.push({ path: shifted.path, item: { kind: "hover-geometry-shift", element: shifted.element, condition: shifted.condition } });
1134
+ return { kind: "built", owned: {
1135
+ ...lowered.value,
1136
+ origins: [],
1137
+ surfaceUses: surfaceUses(read, spec, lowered.value.profiles, paintedBy),
1138
+ paints: declaredPaints(spec).map((paint) => ({ name: paint.name, property: paintProperty(scope, paint.name), values: paint.values })),
1139
+ glyphs: [],
1140
+ content: []
1141
+ }, reviews };
1142
+ }), at = (path) => path === null ? node : authoredAt(classes.calls, path) ?? node;
1143
+ for (const noted of built.reviews)
1144
+ review(at(noted.path), noted.item);
1145
+ if (built.kind === "failed")
1146
+ return fail(at(built.failure.path), { kind: "construction", failure: built.failure.item });
1147
+ owned = { ...built.owned, origins: [], glyphs: [], content: [] };
1019
1148
  styles.set(key, owned);
1020
1149
  }
1021
1150
  if (owned.facts.kind === "region" && owned.facts.exposed !== null)
@@ -1028,7 +1157,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1028
1157
  const classes = split(await resolve(classAttribute, context), classAttribute);
1029
1158
  if (classes.fragments.length === 0)
1030
1159
  return null;
1031
- const combined = combineRecipes(...classes.fragments), spec = combined.kind === "ok" ? parseConstruction(combined.value.spec) : null;
1160
+ const spec = parsedOf(classes.fragments);
1032
1161
  return spec?.kind === "ok" ? spec.value : null;
1033
1162
  }, report = (finding, host) => {
1034
1163
  const at = expression(attr(host, "className")) ?? host;
@@ -1084,15 +1213,29 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1084
1213
  const at = location(node);
1085
1214
  if (!owned.origins.some((origin) => origin.kind === "point" && origin.position.line === at.line && origin.position.column === at.column))
1086
1215
  owned.origins.push({ kind: "point", file: name, position: { line: at.line, column: at.column } });
1087
- const lowered = owned, code = (pending) => {
1216
+ const lowered = owned;
1217
+ for (const attribute of await contentAttributes(opening))
1218
+ if (!(owned.content ?? []).includes(attribute))
1219
+ owned.content?.push(attribute);
1220
+ const placedFor = (part) => lowered.facts.kind === "region" ? lowered.facts.artworks.get(part) ?? placedArtwork(lowered) : placedArtwork(lowered), code = (pending) => {
1088
1221
  switch (pending.kind) {
1089
- case "drawing":
1090
- return JSON.stringify(artworkSource(lowered));
1222
+ case "drawing": {
1223
+ const placedArt = placedFor(pending.part);
1224
+ if (placedArt !== null)
1225
+ used(pending.asset, placedArt.size);
1226
+ return JSON.stringify(placedArt?.source ?? "");
1227
+ }
1091
1228
  case "lookup": {
1092
- const drawing = placedArtwork(lowered)?.drawing;
1229
+ const drawing = placedFor(pending.part)?.drawing;
1093
1230
  if (drawing === void 0 || theme === void 0)
1094
1231
  throw Error("A set binding's construction placed no artwork.");
1095
- return setLookupCode(assets, pending.set, parsed.value.kind === "control" ? LIGHT : theme, drawing, pending.state);
1232
+ const lookup = setLookupCode(assets, pending.set, parsed.value.kind === "control" ? LIGHT : theme, drawing, pending.state);
1233
+ for (const member of pending.set.members)
1234
+ used(member, placedFor(pending.part)?.size ?? null);
1235
+ const selector = declaredParts(parsed.value).find((part) => part.name === pending.part)?.selector;
1236
+ if (selector !== void 0 && !(owned.glyphs ?? []).some((known) => known.part === selector))
1237
+ owned.glyphs?.push({ part: selector, members: JSON.parse(lookup.slice(1, -1)) });
1238
+ return lookup;
1096
1239
  }
1097
1240
  }
1098
1241
  };
@@ -1293,7 +1436,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1293
1436
  if (declaration !== void 0 && (isBindingElement(declaration) || isParameterDeclaration(declaration)) && declaration.name === identifier)
1294
1437
  continue;
1295
1438
  const passed = identifier.parent?.parent, tag = passed !== void 0 && isJsxAttribute(passed) ? passed.parent.parent : void 0, host = tag !== void 0 && (isJsxOpeningElement(tag) || isJsxSelfClosingElement(tag)) ? tag : null;
1296
- if (!(identifier.parent !== void 0 && isJsxExpression(identifier.parent) && host !== null && !lowercaseTag(host)))
1439
+ if (!(identifier.parent !== void 0 && isJsxExpression(identifier.parent) && host !== null && !lowercaseTag(host)) && !presenceTest(identifier))
1297
1440
  return fail(identifier, { kind: "glyph-reference-read", name: identifier.text });
1298
1441
  }
1299
1442
  const assetEdits = new Map;
@@ -1315,14 +1458,20 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1315
1458
  const rewritten = await publicImports({ root, file: name, source, publicModule: options.publicAlias, symbolOf: values.symbol, emitted, fail }), imports = [...rewritten.imports];
1316
1459
  for (const statement of rewritten.statements)
1317
1460
  edits.push({ node: statement, text: "" });
1318
- const coveredLeaves = selections.reduce((sum, { result }) => sum + result.leaves.filter((leaf) => leaf.value.kind === "styled").length, 0), [rows] = exposedRows.values(), publicRows = exposedRows.size === 1 && rows !== void 0 ? rows : null, artwork = { assets: [...boundAssets].sort(), sets: [...boundSets].sort(), glyphs: macros.glyphs, support: macros.support };
1461
+ const coveredLeaves = selections.reduce((sum, { result }) => sum + result.leaves.filter((leaf) => leaf.value.kind === "styled").length, 0), [rows] = exposedRows.values(), publicRows = exposedRows.size === 1 && rows !== void 0 ? rows : null, uses = [...artworkUses].sort().map((key) => {
1462
+ const [asset = "", size = ""] = key.split("\x00");
1463
+ return { asset, size: size === "" ? null : size };
1464
+ }), artwork = { assets: [...boundAssets].sort(), sets: [...boundSets].sort(), glyphs: macros.glyphs, support: macros.support, uses };
1319
1465
  return { source, values, selections, styles, edits, assetEdits, imports, coverage: { constructions: styles.size, coveredLeaves }, publicRows, controls: ownerControls(selections.flatMap((selection) => selection.result.axes)), reviews, artwork, design: ownerDesign([...styles.values()].flatMap((construction) => construction.profiles)) };
1320
1466
  }
1467
+ function drawnRecords(input, root) {
1468
+ return [input.visual, ...input.visuals.values()].map((fact) => fact !== null && fact.kind === "asset" ? designValueDigest(fact.asset, root) : null);
1469
+ }
1321
1470
  function lower(spec, foundation, root, input) {
1322
1471
  const asset = input.visual?.kind === "asset" ? input.visual : null;
1323
1472
  switch (spec.kind) {
1324
1473
  case "control":
1325
- return lowerControl(spec, foundation, { root, asset: asset?.asset ?? null, state: asset?.state ?? "normal", hasText: input.hasText, hidden: input.hidden });
1474
+ return lowerControl(spec, foundation, { root, asset: asset?.asset ?? null, state: asset?.state ?? "normal", ...asset === null ? {} : { theme: asset.theme }, hasText: input.hasText, hidden: input.hidden });
1326
1475
  case "artwork":
1327
1476
  return lowerArtwork(spec, foundation, {
1328
1477
  root,
@@ -1333,7 +1482,7 @@ function lower(spec, foundation, root, input) {
1333
1482
  hidden: input.hidden
1334
1483
  });
1335
1484
  case "region":
1336
- return lowerRegion(spec, foundation, { root, visual: input.visual, hidden: input.hidden, scope: input.scope });
1485
+ return lowerRegion(spec, foundation, { root, visual: input.visual, visuals: input.visuals, hidden: input.hidden, scope: input.scope });
1337
1486
  case "grid":
1338
1487
  return lowerGrid(spec, foundation, { root, hidden: input.hidden, inherited: input.inherited, aligned: input.aligned, scope: input.scope });
1339
1488
  }
@@ -1351,7 +1500,16 @@ function placedArtwork(construction) {
1351
1500
  return null;
1352
1501
  }
1353
1502
  }
1354
- const artworkSource = (construction) => placedArtwork(construction)?.source ?? "", AUTHORING_LEAK = /@reqvire-org\/ads|type:\s*"macro"|__adsRecipe/, jsxRuntime = (framework) => `${framework ?? "react"}/jsx-runtime`;
1503
+ const AUTHORING_LEAK = /@reqvire-org\/ads|type:\s*"macro"|__adsRecipe/, jsxRuntime = (framework) => `${framework ?? "react"}/jsx-runtime`, FACTOR_FROM_LEAVES = 32;
1504
+ function emitClasses(result, classFor) {
1505
+ const full = () => emitChoice(result.tree, (value) => value.kind === "absent" ? null : JSON.stringify(classFor(value))) ?? '""';
1506
+ if (result.leaves.length < FACTOR_FROM_LEAVES)
1507
+ return full();
1508
+ const factored = factorClasses(result.leaves.map((leaf) => ({ ...leaf, value: leaf.value.kind === "absent" ? null : classFor(leaf.value) })), result.axes);
1509
+ if (factored === null)
1510
+ return full();
1511
+ return `(${[JSON.stringify(factored.base), ...factored.groups.map((group) => emitChoice(group.tree, (value) => JSON.stringify(value)) ?? '""')].join(' + " " + ')})`;
1512
+ }
1355
1513
  export async function emitOwners(analysis, target = { kind: "compiled" }, dependencies = { packageManifest: null }) {
1356
1514
  const { foundation, compiled } = analysis, scoped = target.kind === "scoped";
1357
1515
  return attemptAsync(async (reject) => {
@@ -1451,7 +1609,7 @@ export async function ownerModuleSource(name, owner, classOf, fail) {
1451
1609
  return [...value.markers, compiledClass].join(" ");
1452
1610
  };
1453
1611
  for (const { node, result } of selections) {
1454
- let text = emitChoice(result.tree, (value) => value.kind === "absent" ? null : JSON.stringify(classFor(value))) ?? '""';
1612
+ let text = emitClasses(result, classFor);
1455
1613
  const placements = [...new Set(result.leaves.flatMap((leaf) => leaf.value.kind === "styled" && leaf.value.placement !== null ? [leaf.value.placement] : []))], [placement] = placements;
1456
1614
  if (placements.length > 1)
1457
1615
  fail(node, { kind: "placement-repeated" });
@@ -1553,3 +1711,22 @@ export async function emissionFacts(root, outcomes, selected, options) {
1553
1711
  return owners;
1554
1712
  });
1555
1713
  }
1714
+ function presenceTest(identifier) {
1715
+ let node = identifier;
1716
+ while (node.parent !== void 0 && isParenthesizedExpression(node.parent))
1717
+ node = node.parent;
1718
+ const parent = node.parent;
1719
+ if (parent === void 0)
1720
+ return !1;
1721
+ if (isPrefixUnaryExpression(parent))
1722
+ return parent.operator === SyntaxKind.ExclamationToken;
1723
+ if (isConditionalExpression(parent))
1724
+ return parent.condition === node;
1725
+ if (!isBinaryExpression(parent))
1726
+ return !1;
1727
+ const operator = parent.operatorToken.kind;
1728
+ if (operator === SyntaxKind.AmpersandAmpersandToken)
1729
+ return parent.left === node;
1730
+ const equality = [SyntaxKind.EqualsEqualsEqualsToken, SyntaxKind.ExclamationEqualsEqualsToken, SyntaxKind.EqualsEqualsToken, SyntaxKind.ExclamationEqualsToken].includes(operator), other = parent.left === node ? parent.right : parent.left;
1731
+ return equality && (isIdentifier(other) && other.text === "undefined" || other.kind === SyntaxKind.NullKeyword);
1732
+ }
@@ -4,7 +4,7 @@ import { moduleSpecifiers } from "../design-system-closure.mjs";
4
4
  import { digest } from "../digest.mjs";
5
5
  import { currentAnalysis, memoFact } from "./context.mjs";
6
6
  import { capturedTreeFiles, optionalSourceText, resolveModuleDetails, sourceAst, walk } from "./helpers.mjs";
7
- import { canonical, importClosure } from "./owner-analysis-key.mjs";
7
+ import { canonical, importClosure, relocateOutcome, rootRelative } from "./owner-analysis-key.mjs";
8
8
  import { barrelDeclarations } from "./owner-discovery.mjs";
9
9
  import { PUBLIC_BARREL, ownerCompilerOptions } from "./owner-source.mjs";
10
10
  import ts from "./syntax.mjs";
@@ -19,9 +19,12 @@ export async function obtainScenarioResult(cache, root, key, kind, compute) {
19
19
  };
20
20
  if (cache === null || key === void 0)
21
21
  return counted();
22
- const obtained = await cache.obtain({ key: `${kind}:${key}`, root, tokens: "" }, async () => ({ outcome: await counted(), tokens: { kind: "token-independent" } }));
23
- if (obtained.kind === "reused")
22
+ const projectRoot = currentAnalysis()?.root ?? root, obtained = await cache.obtain({ key: `${kind}:${key}`, root: projectRoot, tokens: "" }, async () => ({ outcome: await counted(), tokens: { kind: "token-independent" } }), relocateOutcome);
23
+ if (obtained.kind === "reused") {
24
24
  scenarioWork[kind].reused++;
25
+ if (process.env.ADS_VERIFY_OWNER_REUSE === "1" && canonical(await compute()) !== canonical(obtained.outcome))
26
+ throw Error(`A reused scenario ${kind} result differs from a fresh one (ADS_VERIFY_OWNER_REUSE=1).`);
27
+ }
25
28
  return obtained.outcome;
26
29
  }
27
30
  export function revisionScenarioKeys(inputs) {
@@ -30,7 +33,7 @@ export function revisionScenarioKeys(inputs) {
30
33
  return Promise.resolve(null);
31
34
  return memoFact(context, `scenario-keys:${inputs.dsRoot}:${inputs.publicAlias}`, () => scenarioKeys(context.root, inputs));
32
35
  }
33
- const SCENARIO_FACTS_SCHEMA = "ads-scenario-facts/3";
36
+ const SCENARIO_FACTS_SCHEMA = "ads-scenario-facts/4";
34
37
  async function scenarioKeys(root, inputs) {
35
38
  const provide = currentAnalysis()?.environment, captured = capturedTreeFiles(root);
36
39
  if (provide === void 0 || captured === null)
@@ -53,10 +56,10 @@ async function scenarioKeys(root, inputs) {
53
56
  environment,
54
57
  membership: digest([...captured].map((file) => toRelative(root, file)).sort()),
55
58
  digestOf
56
- }, fixed = { schema: SCENARIO_FACTS_SCHEMA, root, dsRoot, publicAlias, framework, environment, globals: await inputs.globals(), exports: [...declarations] }, keys = new Map;
59
+ }, fixed = { schema: SCENARIO_FACTS_SCHEMA, dsRoot: toRelative(root, dsRoot), publicAlias, framework, environment, globals: await inputs.globals(), exports: [...declarations] }, keys = new Map;
57
60
  for (const file of files) {
58
61
  const sources = [...await scenarioClosure(scope, inputs.graph, declarations, file)].sort();
59
- keys.set(file, digest(canonical({ ...fixed, file, sources: sources.map((source) => ({ file: source, digest: digestOf(source) })) })));
62
+ keys.set(file, digest(rootRelative(canonical({ ...fixed, file, sources: sources.map((source) => ({ file: source, digest: digestOf(source) })) }), root)));
60
63
  }
61
64
  return keys;
62
65
  }
@@ -97,7 +100,7 @@ function moduleEdges(scope, module) {
97
100
  const file = path.resolve(scope.dsRoot, module), contents = scope.digestOf(module);
98
101
  if (contents === "absent" || !isInside(scope.root, file))
99
102
  return Promise.resolve({ local: [], public: [], listed: [] });
100
- const key = digest(canonical({ schema: SCENARIO_FACTS_SCHEMA, root: scope.root, dsRoot: scope.dsRoot, publicAlias: scope.publicAlias, framework: scope.framework, environment: scope.environment, membership: scope.membership, module, contents })), known = moduleEdgeCache.get(key);
103
+ const key = digest(canonical({ schema: SCENARIO_FACTS_SCHEMA, dsRoot: toRelative(scope.root, scope.dsRoot), publicAlias: scope.publicAlias, framework: scope.framework, environment: scope.environment, membership: scope.membership, module, contents })), known = moduleEdgeCache.get(key);
101
104
  if (known !== void 0) {
102
105
  moduleEdgeCache.delete(key);
103
106
  moduleEdgeCache.set(key, known);