@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.
Files changed (136) hide show
  1. package/dist/ads-errors.mjs +143 -51
  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/design-usage.mjs +4 -20
  7. package/dist/analysis/factored-classes.mjs +90 -0
  8. package/dist/analysis/helpers.mjs +5 -7
  9. package/dist/analysis/mock-check.mjs +4 -5
  10. package/dist/analysis/native-project.mjs +12 -0
  11. package/dist/analysis/owner-accessibility.mjs +4 -4
  12. package/dist/analysis/owner-analysis-cache.mjs +86 -23
  13. package/dist/analysis/owner-analysis-key.mjs +42 -10
  14. package/dist/analysis/owner-choices.mjs +56 -7
  15. package/dist/analysis/owner-composition.mjs +179 -45
  16. package/dist/analysis/owner-reuse.mjs +8 -6
  17. package/dist/analysis/owner-source.mjs +304 -110
  18. package/dist/analysis/scenario-keys.mjs +10 -7
  19. package/dist/analysis/service.mjs +50 -3
  20. package/dist/analysis/standalone.mjs +7 -4
  21. package/dist/analysis/syntax.mjs +59 -1
  22. package/dist/analysis/worker-protocol.mjs +14 -2
  23. package/dist/analysis/worker.mjs +32 -10
  24. package/dist/architecture-report.mjs +26 -0
  25. package/dist/asset-view-facts.mjs +16 -2
  26. package/dist/boundaries.mjs +26 -10
  27. package/dist/bun-compiler.mjs +2 -2
  28. package/dist/check-service.mjs +29 -17
  29. package/dist/check.mjs +13 -6
  30. package/dist/cli.mjs +1 -1
  31. package/dist/composed-contrast.mjs +143 -62
  32. package/dist/composed-keyline.mjs +2 -2
  33. package/dist/config.mjs +2 -1
  34. package/dist/construction-output.mjs +9 -3
  35. package/dist/construction-spec.d.mts +145 -31
  36. package/dist/construction-spec.mjs +204 -74
  37. package/dist/corner-overpaint.mjs +20 -7
  38. package/dist/derived-states.mjs +182 -0
  39. package/dist/design-foundation.mjs +16 -0
  40. package/dist/design-inputs.mjs +18 -3
  41. package/dist/design-system-closure.mjs +12 -7
  42. package/dist/design-usage.mjs +2 -8
  43. package/dist/emit/contract.mjs +24 -5
  44. package/dist/emit/emission.mjs +6 -9
  45. package/dist/emit/integrity.mjs +8 -2
  46. package/dist/emit/output-watch.mjs +120 -0
  47. package/dist/emit/owner-emission-cache.mjs +4 -4
  48. package/dist/emit/preview-emitter.mjs +4 -2
  49. package/dist/emit/preview-tree.mjs +1 -1
  50. package/dist/emit/service.mjs +8 -2
  51. package/dist/finding-rules.mjs +3 -0
  52. package/dist/form-states.mjs +8 -0
  53. package/dist/frame-regions.mjs +29 -9
  54. package/dist/grid-lowering.mjs +3 -1
  55. package/dist/hover-geometry.mjs +15 -0
  56. package/dist/input-digests.mjs +17 -10
  57. package/dist/linaria/delivery.mjs +2 -0
  58. package/dist/lowering-enter.mjs +6 -6
  59. package/dist/lowering-properties.mjs +5 -0
  60. package/dist/lowering-region-layout.mjs +7 -2
  61. package/dist/lowering-session.mjs +10 -0
  62. package/dist/mcp/build-status.mjs +9 -1
  63. package/dist/mcp/compiler-channel.mjs +11 -4
  64. package/dist/mcp/mutations.mjs +1 -0
  65. package/dist/mcp/preview-http.bundle.js +1 -1
  66. package/dist/mcp/preview-watch.mjs +2 -1
  67. package/dist/mcp/preview-widget.bundle.js +1 -1
  68. package/dist/mcp/server-observation.mjs +6 -4
  69. package/dist/mcp/server-project.mjs +4 -1
  70. package/dist/motion-model.mjs +1 -1
  71. package/dist/owner-analysis-check.mjs +23 -6
  72. package/dist/owner-errors.mjs +6 -3
  73. package/dist/owner-lowering.mjs +78 -13
  74. package/dist/owner-scenarios.mjs +6 -23
  75. package/dist/ownership-model.mjs +24 -8
  76. package/dist/paint-contrast.mjs +6 -0
  77. package/dist/placeholder-contrast.mjs +17 -1
  78. package/dist/platform-features.mjs +10 -1
  79. package/dist/profile-macro.d.mts +7 -0
  80. package/dist/profile-view-facts.mjs +1 -1
  81. package/dist/recipe-macro.d.mts +103 -40
  82. package/dist/recipe-model.mjs +18 -13
  83. package/dist/region-lowering.mjs +266 -123
  84. package/dist/render-audit/layout-shift.page.mjs +24 -0
  85. package/dist/render-audit/render-states.mjs +122 -1
  86. package/dist/render-audit/render-states.page.mjs +140 -0
  87. package/dist/render-audit/worker.mjs +18 -3
  88. package/dist/render-audit.mjs +114 -1
  89. package/dist/role-vocabulary.d.mts +9 -0
  90. package/dist/role-vocabulary.mjs +16 -1
  91. package/dist/runtime-paint-contrast.mjs +5 -2
  92. package/dist/scenarios-compiler.mjs +20 -6
  93. package/dist/showcase/assets-view.mjs +29 -13
  94. package/dist/showcase/client.bundle.js +50 -50
  95. package/dist/showcase/http-client.bundle.js +15 -15
  96. package/dist/showcase/ui/ui.css +1 -1
  97. package/dist/showcase/ui/ui.js +5 -5
  98. package/dist/skills/ads-designer/references/accessibility.md +10 -4
  99. package/dist/skills/ads-designer/references/branding.md +13 -3
  100. package/dist/skills/ads-designer/references/contracts.md +5 -2
  101. package/dist/skills/ads-designer/references/design-data.md +13 -7
  102. package/dist/skills/ads-designer/references/layout.md +12 -4
  103. package/dist/skills/ads-designer/references/motion.md +11 -2
  104. package/dist/skills/ads-designer/references/recipes.md +49 -15
  105. package/dist/skills/ads-import/references/contracts.md +5 -2
  106. package/dist/skills/ads-import/references/design-data.md +13 -7
  107. package/dist/skills/ads-import/references/layout.md +12 -4
  108. package/dist/skills/ads-import/references/recipes.md +49 -15
  109. package/dist/skills/ads-migrate/SKILL.md +2 -0
  110. package/dist/skills/ads-migrate/references/0.5.1-to-0.5.2.md +185 -0
  111. package/dist/skills/ads-migrate/references/0.5.2-to-0.5.3.md +71 -0
  112. package/dist/skills/ads-port/references/contracts.md +5 -2
  113. package/dist/skills/ads-port/references/design-data.md +13 -7
  114. package/dist/skills/ads-port/references/layout.md +12 -4
  115. package/dist/skills/ads-port/references/recipes.md +49 -15
  116. package/dist/spatial-model.mjs +2 -2
  117. package/dist/surface-contrast.mjs +7 -2
  118. package/dist/surface-effects.mjs +5 -3
  119. package/dist/target-size.mjs +21 -3
  120. package/dist/task-cache.mjs +8 -18
  121. package/dist/validation-checks.mjs +1 -1
  122. package/docs/ADS.md +9 -3
  123. package/docs/ARCHITECTURE.md +96 -30
  124. package/docs/CACHING.md +152 -24
  125. package/docs/CHANGELOG.md +307 -23
  126. package/docs/GUIDE.md +109 -20
  127. package/docs/LANGUAGE.md +262 -117
  128. package/docs/MCP.md +5 -1
  129. package/docs/MOTION.md +15 -4
  130. package/docs/PROFILE-KINDS.md +54 -4
  131. package/docs/RULES.md +34 -25
  132. package/docs/TOKEN-ROLES.md +7 -1
  133. package/package.json +1 -1
  134. package/dist/analysis/prose-owners.mjs +0 -57
  135. package/dist/prose-model.d.mts +0 -81
  136. package/dist/prose-model.mjs +0 -101
@@ -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";
@@ -166,7 +172,7 @@ function insideMap(node, ancestor) {
166
172
  return !0;
167
173
  return !1;
168
174
  }
169
- const isLoop = (node) => isForStatement(node) || isForOfStatement(node) || isForInStatement(node) || isWhileStatement(node) || isDoStatement(node), lowercaseTag = (opening) => /^[a-z]/.test(opening.tagName.getText()), NO_CLASSES = { fragments: [], calls: [], markers: [], placement: [], bindings: [] };
175
+ const isLoop = (node) => isForStatement(node) || isForOfStatement(node) || isForInStatement(node) || isWhileStatement(node) || isDoStatement(node), NO_CLASSES = { fragments: [], calls: [], markers: [], placement: [], bindings: [] };
170
176
  function validateReferences(foundation, spec) {
171
177
  if (typeof spec !== "object" || spec === null)
172
178
  return null;
@@ -260,13 +266,14 @@ export async function checkOwners(root, names, options, reuse) {
260
266
  const { program, graph } = walked.value, emitted = new Set(graph.modules.keys());
261
267
  options.stats.analyses++;
262
268
  const outcomes = new Map, facts = new Map, pass = await timing.timeStage("owner-keys", () => reuse.begin(program, graph));
263
- let plain = { modules: new Map, failures: [], placements: [] }, unemitted = [];
269
+ let plain = { modules: new Map, failures: [], placements: [], composition: new Map }, 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
- plain = await checkedPlainModules(root, graph, program, options.publicAlias, emitted, options.assets);
276
+ plain = await checkedPlainModules(root, graph, program, options.publicAlias, emitted, options.assets, options.foundation);
270
277
  unemitted = [
271
278
  ...(await unemittedStyling(root, emitted)).map(stylingFailure),
272
279
  ...await frameworkMismatches(root, options.framework ?? null),
@@ -292,7 +299,8 @@ export async function checkOwners(root, names, options, reuse) {
292
299
  checkProgram: program,
293
300
  facts,
294
301
  plain: plain.modules,
295
- plainPlacements: plain.placements
302
+ plainPlacements: plain.placements,
303
+ plainComposition: plain.composition
296
304
  });
297
305
  }
298
306
  async function checkedOwner(root, emitted, name, program, options, settled, retain) {
@@ -334,8 +342,8 @@ async function plainModules(root, graph, program, publicAlias, emitted, catalog,
334
342
  }
335
343
  return plain;
336
344
  }
337
- async function checkedPlainModules(root, graph, program, publicAlias, emitted, catalog) {
338
- const modules = new Map, failures = [], placements = [], checker = program.getTypeChecker();
345
+ async function checkedPlainModules(root, graph, program, publicAlias, emitted, catalog, foundation) {
346
+ const modules = new Map, failures = [], placements = [], composition = new Map, checker = program.getTypeChecker();
339
347
  for (const module of graph.modules.values()) {
340
348
  if (module.role === "owner")
341
349
  continue;
@@ -345,20 +353,30 @@ async function checkedPlainModules(root, graph, program, publicAlias, emitted, c
345
353
  switch (checked.kind) {
346
354
  case "ok":
347
355
  modules.set(file, checked.value);
348
- placements.push(...await timing.timeStage("plain-placements", () => plainPlacements(root, checked.value.source, (node) => valueSymbolAt(checker, node))));
356
+ const placed = await timing.timeStage("plain-placements", () => plainPlacements(root, checked.value.source, (node) => valueSymbolAt(checker, node)));
357
+ if (placed.length === 0)
358
+ break;
359
+ const facts = await attemptAsync(async (reject) => {
360
+ const source = checked.value.source, values = await choiceValues({ program, source, root, validateSpec: (spec) => validateReferences(foundation, spec), fail: failAt(reject) });
361
+ return timing.timeStage("plain-composition", () => compositionFacts({ root, source, values, checker, foundation }));
362
+ });
363
+ if (facts.kind === "ok")
364
+ composition.set(file, facts.value);
365
+ else
366
+ placements.push(...placed);
349
367
  break;
350
368
  case "err":
351
369
  failures.push(checked.error);
352
370
  break;
353
371
  }
354
372
  }
355
- return { modules, failures, placements };
373
+ return { modules, failures, placements, composition };
356
374
  }
357
375
  async function plainStyling(root, file, program) {
358
376
  return plainModuleStyling(await programSource(program, path.join(root, file)), program, program.getTypeChecker());
359
377
  }
360
378
  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 };
379
+ 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
380
  return { source, role, imports: rewritten.imports, statements: rewritten.statements, edits: macros.edits, artwork };
363
381
  }
364
382
  async function typeDiagnostics(root, program) {
@@ -419,13 +437,13 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
419
437
  const [stylesheet] = ownerStylesheetImports(source);
420
438
  if (stylesheet !== void 0)
421
439
  return fail(stylesheet.node, stylesheet.problem);
422
- const values = await choiceValues({ program, source, root, validateSpec: (spec) => validateReferences(foundation, spec), fail }), checker = program.getTypeChecker(), [styleWrite] = await ownerStyleWrites(source, program, checker);
440
+ const values = await choiceValues({ program, source, root, validateSpec: (spec) => validateReferences(foundation, spec), fail }), lowercaseTag = (opening) => /^[a-z]/.test(values.tag(opening)), checker = program.getTypeChecker(), [styleWrite] = await ownerStyleWrites(source, program, checker);
423
441
  if (styleWrite !== void 0)
424
442
  return fail(styleWrite.node, styleWrite.problem);
425
443
  const [animation] = await scriptAnimations(source, program, checker);
426
444
  if (animation !== void 0)
427
445
  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) => {
446
+ 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
447
  let known = carried.get(glyph);
430
448
  if (known === void 0)
431
449
  carried.set(glyph, known = referenceAssets(checker, assets, glyph, fail));
@@ -434,7 +452,25 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
434
452
  if (at === null || restatements.get(at)?.kind === "changes")
435
453
  return;
436
454
  restatements.set(at, redundancy === null ? { kind: "changes" } : restatements.get(at) ?? { kind: "redundant", redundancy });
437
- }, styles = new Map, exposedRows = new Map, publicRowsOf = async (component) => {
455
+ }, styles = new Map, fragmentIds = new WeakMap;
456
+ let nextFragment = 0;
457
+ const fragmentId = (fragment) => {
458
+ let known = fragmentIds.get(fragment);
459
+ if (known === void 0)
460
+ fragmentIds.set(fragment, known = nextFragment++);
461
+ return known;
462
+ }, recipes = new Map, combinedOf = (fragments) => {
463
+ const id = fragments.map(fragmentId).join(",");
464
+ let known = recipes.get(id);
465
+ if (known === void 0)
466
+ recipes.set(id, known = { combined: combineRecipes(...fragments) });
467
+ return known;
468
+ }, parsedOf = (fragments) => {
469
+ const known = combinedOf(fragments);
470
+ if (known.combined.kind === "err")
471
+ return null;
472
+ return known.parsed ??= parseConstruction(known.combined.value.spec);
473
+ }, exposedRows = new Map, publicRowsOf = async (component) => {
438
474
  const declaration = (await values.symbol(component.tagName))?.valueDeclaration;
439
475
  if (declaration === void 0)
440
476
  return null;
@@ -464,20 +500,26 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
464
500
  if (attributeName === "style" || attributeName === "css")
465
501
  return fail(attribute, { kind: "raw-style", attribute: attributeName });
466
502
  }
467
- async function markup(node, context, resolve) {
503
+ async function markup(node, context, resolve, assumed) {
468
504
  const opening = openingOf(node);
469
505
  if (opening !== null)
470
506
  return [opening];
471
507
  if (isJsxFragment(node))
472
- return (await Promise.all(node.children.map((child) => markup(child, context, resolve)))).flat();
508
+ return (await Promise.all(node.children.map((child) => markup(child, context, resolve, assumed)))).flat();
473
509
  if (isJsxExpression(node))
474
- return node.expression === void 0 ? [] : markup(node.expression, context, resolve);
510
+ return node.expression === void 0 ? [] : markup(node.expression, context, resolve, assumed);
475
511
  if (isParenthesizedExpression(node))
476
- return markup(node.expression, context, resolve);
512
+ return markup(node.expression, context, resolve, assumed);
477
513
  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) : [];
514
+ return markup(values.truthy(await resolve(node.condition, context), node.condition, context) ? node.whenTrue : node.whenFalse, context, resolve, assumed);
515
+ if (isBinaryExpression(node) && node.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken) {
516
+ if (assumed !== void 0) {
517
+ const present = openingOf(node.right) ?? (isParenthesizedExpression(node.right) ? openingOf(node.right.expression) : null);
518
+ if (present !== null && assumed([present]))
519
+ return [present];
520
+ }
521
+ return values.truthy(await resolve(node.left, context), node.left, context) ? markup(node.right, context, resolve, assumed) : [];
522
+ }
481
523
  const mapped = mapCallback(node);
482
524
  if (mapped !== null) {
483
525
  const result = callbackResult(mapped);
@@ -487,9 +529,9 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
487
529
  return fail(node, { kind: "helper-markup" });
488
530
  return [];
489
531
  }
490
- const children = async (opening, context, resolve) => {
532
+ const children = async (opening, context, resolve, assumed) => {
491
533
  const element = elementOf(opening);
492
- return isJsxElement(element) ? (await Promise.all(element.children.map((child) => markup(child, context, resolve)))).flat() : [];
534
+ return isJsxElement(element) ? (await Promise.all(element.children.map((child) => markup(child, context, resolve, assumed)))).flat() : [];
493
535
  };
494
536
  function inlineSource(opening) {
495
537
  const html = expression(attr(opening, "dangerouslySetInnerHTML")), [field] = html !== void 0 && isObjectLiteralExpression(html) && html.properties.length === 1 ? html.properties : [];
@@ -499,7 +541,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
499
541
  }
500
542
  async function intrinsicSource(opening, context, resolve) {
501
543
  const images = await children(opening, context, resolve), [image] = images;
502
- if (images.length !== 1 || image === void 0 || image.tagName.getText() !== "img")
544
+ if (images.length !== 1 || image === void 0 || values.tag(image) !== "img")
503
545
  return fail(opening, { kind: "intrinsic-image-count" });
504
546
  const src = expression(attr(image, "src"));
505
547
  if (src === void 0)
@@ -550,9 +592,9 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
550
592
  const descendants = (opening) => {
551
593
  const element = elementOf(opening);
552
594
  return openings.filter((other) => other !== opening && other.getStart() >= element.getStart() && other.end <= element.end);
553
- }, FOCUSABLE_TAGS = ["a", "button", "input", "select", "textarea", "summary", "iframe"], focusable = (other) => FOCUSABLE_TAGS.includes(other.tagName.getText()) || attr(other, "tabIndex") !== void 0 || attr(other, "href") !== void 0;
595
+ }, FOCUSABLE_TAGS = ["a", "button", "input", "select", "textarea", "summary", "iframe"], focusable = (other) => FOCUSABLE_TAGS.includes(values.tag(other)) || attr(other, "tabIndex") !== void 0 || attr(other, "href") !== void 0;
554
596
  async function textEntryElement(opening, partName, context, resolve) {
555
- const expected = ['<input type="text|email|tel|url|password|search|number">', "<textarea>", "<select>"], tag = opening.tagName.getText();
597
+ const expected = ['<input type="text|email|tel|url|password|search|number">', "<textarea>", "<select>"], tag = values.tag(opening);
556
598
  if (tag === "textarea" || tag === "select")
557
599
  return;
558
600
  if (tag !== "input")
@@ -564,7 +606,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
564
606
  async function nativeElement(opening, element, partName, parent, context, resolve) {
565
607
  if (element === null)
566
608
  return;
567
- const tag = opening.tagName.getText(), tags = elementTags(element);
609
+ const tag = values.tag(opening), tags = elementTags(element);
568
610
  if (!tags.includes(tag))
569
611
  return fail(opening, { kind: "part-element-mismatch", part: partName, expected: tags.map((expected) => `<${expected}>`), actual: `<${tag}>` });
570
612
  switch (element.kind) {
@@ -578,9 +620,9 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
578
620
  let host = parent === null ? elementOf(opening).parent : elementOf(parent);
579
621
  while (host !== void 0 && !isJsxElement(host) && !isJsxSelfClosingElement(host) && (isJsxExpression(host) || isParenthesizedExpression(host) || isJsxFragment(host)))
580
622
  host = host.parent;
581
- if ((host === void 0 ? null : openingOf(host)?.tagName.getText() ?? null) !== "details")
623
+ if ((host === void 0 ? null : openingOf(host) === void 0 ? null : values.tag(openingOf(host))) !== "details")
582
624
  return fail(opening, { kind: "summary-outside-details", part: partName });
583
- if (element.marker === "none" && !descendants(opening).some((other) => !lowercaseTag(other) || other.tagName.getText() === "svg" || attr(other, "aria-hidden") !== void 0))
625
+ if (element.marker === "none" && !descendants(opening).some((other) => !lowercaseTag(other) || values.tag(other) === "svg" || attr(other, "aria-hidden") !== void 0))
584
626
  review(opening, { kind: "marker-none-unlabelled", part: partName });
585
627
  return;
586
628
  }
@@ -628,7 +670,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
628
670
  const classes = split(await resolve(classAttribute, context), classAttribute);
629
671
  if (classes.fragments.length === 0)
630
672
  return null;
631
- const combined = combineRecipes(...classes.fragments), parsed = combined.kind === "ok" ? parseConstruction(combined.value.spec) : null;
673
+ const parsed = parsedOf(classes.fragments);
632
674
  return parsed?.kind === "ok" ? parsed.value : null;
633
675
  };
634
676
  let node = elementOf(opening), below = opening;
@@ -657,7 +699,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
657
699
  const touchDisabled = [], handovers = [];
658
700
  let containerGrids = !1;
659
701
  async function layerRoot(opening, layer, context, resolve) {
660
- const tag = opening.tagName.getText(), named = attr(opening, "aria-label") !== void 0 || attr(opening, "aria-labelledby") !== void 0;
702
+ const tag = values.tag(opening), named = attr(opening, "aria-label") !== void 0 || attr(opening, "aria-labelledby") !== void 0;
661
703
  switch (layer.kind) {
662
704
  case "modal-sheet": {
663
705
  if (tag !== "dialog")
@@ -709,11 +751,58 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
709
751
  }
710
752
  return !0;
711
753
  }
754
+ let markupProps = null;
755
+ const identifiersIn = (root) => {
756
+ const found = [];
757
+ walk(root, (item) => {
758
+ if (isIdentifier(item))
759
+ found.push(item.text);
760
+ });
761
+ return found;
762
+ }, choosingProps = () => {
763
+ if (markupProps !== null)
764
+ return markupProps;
765
+ const parameters = new Set;
766
+ for (const parameter of nodesOfKind(source, SyntaxKind.Parameter, isParameterDeclaration))
767
+ walk(parameter, (item) => {
768
+ if (isBindingElement(item) && item.name !== void 0 && isIdentifier(item.name))
769
+ parameters.add(item.name.text);
770
+ });
771
+ const jsx = (expression) => expression !== void 0 && findNode(expression, (item) => isJsxElement(item) || isJsxSelfClosingElement(item) || isJsxFragment(item)) !== void 0, read = new Set, names = (condition) => {
772
+ for (const name of identifiersIn(condition))
773
+ if (parameters.has(name))
774
+ read.add(name);
775
+ };
776
+ for (const binary of nodesOfKind(source, SyntaxKind.BinaryExpression, isBinaryExpression))
777
+ if (binary.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken && jsx(binary.right))
778
+ names(binary.left);
779
+ for (const conditional of nodesOfKind(source, SyntaxKind.ConditionalExpression, isConditionalExpression))
780
+ if (jsx(conditional.whenTrue) || jsx(conditional.whenFalse))
781
+ names(conditional.condition);
782
+ markupProps = read;
783
+ return read;
784
+ }, contentAttributes = async (opening) => {
785
+ const chosen = choosingProps();
786
+ if (chosen.size === 0)
787
+ return [];
788
+ const found = [];
789
+ for (const attribute of opening.attributes.properties) {
790
+ if (!isJsxAttribute(attribute))
791
+ continue;
792
+ const name = nameText(attribute.name) ?? "";
793
+ if (!/^(?:data|aria)-/.test(name) || attribute.initializer === void 0)
794
+ continue;
795
+ if (identifiersIn(attribute.initializer).some((identifier) => chosen.has(identifier)))
796
+ found.push(name);
797
+ }
798
+ return found;
799
+ };
712
800
  async function styledChoice(opening, node, classes, context, resolve) {
713
- const combined = combineRecipes(...classes.fragments);
801
+ throwIfCancelled();
802
+ const { combined } = combinedOf(classes.fragments);
714
803
  if (combined.kind === "err")
715
804
  return fail(node, { kind: "recipe-rejected", rejection: combined.error });
716
- const { spec } = combined.value, parsed = parseConstruction(spec);
805
+ const { spec } = combined.value, parsed = parsedOf(classes.fragments) ?? parseConstruction(spec);
717
806
  if (parsed.kind === "err")
718
807
  return fail(authoredAt(classes.calls, parsed.error.kind === "parts-unsupported" ? "recipe.parts" : parsed.error.path) ?? node, { kind: "spec", failure: parsed.error });
719
808
  const defaults = recipeDefaults(foundation, parsed.value);
@@ -752,12 +841,35 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
752
841
  if (!declaredRuntime.has(key))
753
842
  declaredRuntime.set(key, { channel, name: valueName, at: authoredAt(classes.calls, specPath) ?? node });
754
843
  }
755
- const childFacts = new Map, factsOf = async (parent) => {
844
+ const childFacts = new Map, declaredNow = declaredParts(parsed.value), markersOf = (child) => {
845
+ const value = expression(attr(child, "className"));
846
+ if (value === void 0)
847
+ return [];
848
+ const text = value.getText(), named = declaredNow.map((part) => part.selector.slice(1)).filter((marker) => new RegExp(`(^|[\\s"'\`])${marker.replace(/[-]/g, "\\-")}($|[\\s"'\`$])`).test(text));
849
+ if (isStringLiteral(value) || value.kind === SyntaxKind.NoSubstitutionTemplateLiteral || value.kind === SyntaxKind.TemplateExpression)
850
+ return named;
851
+ if (isIdentifier(value)) {
852
+ const init = nodesOfKind(source, SyntaxKind.VariableDeclaration, isVariableDeclaration).find((item) => isIdentifier(item.name) && item.name.text === value.text)?.initializer?.getText() ?? "";
853
+ if (/^(?:recipe|combineRecipes)\(/.test(init))
854
+ return [];
855
+ }
856
+ return null;
857
+ }, presenceFree = (openings) => openings.every((child) => {
858
+ if (!lowercaseTag(child) || attr(child, "hidden") !== void 0)
859
+ return !1;
860
+ const markers = markersOf(child);
861
+ if (markers === null)
862
+ return !1;
863
+ const part = declaredNow.find((candidate) => markers.includes(candidate.selector.slice(1)));
864
+ if (part === void 0)
865
+ return parsed.value.kind !== "grid";
866
+ return !part.required && part.kind !== "visual" && part.scheme === null && !(parsed.value.kind === "control" && part.kind === "text");
867
+ }), factsOf = async (parent) => {
756
868
  const known = childFacts.get(parent);
757
869
  if (known !== void 0)
758
870
  return known;
759
871
  const found = [];
760
- for (const child of await children(parent, context, resolve)) {
872
+ for (const child of await children(parent, context, resolve, presenceFree)) {
761
873
  const childClass = expression(attr(child, "className"));
762
874
  found.push({
763
875
  opening: child,
@@ -770,7 +882,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
770
882
  return found;
771
883
  }, allFacts = await factsOf(opening);
772
884
  let hasText = !1, visual;
773
- const assetSources = [];
885
+ const visuals = new Map, several = parsed.value.kind === "region", assetSources = [];
774
886
  let drawings;
775
887
  const hidden = attr(opening, "hidden") === void 0 ? [] : [{ kind: "root" }], guardChild = (fact, selector, within = []) => {
776
888
  if (attr(fact.opening, "hidden") !== void 0 && fact.classes.fragments.length === 0)
@@ -792,7 +904,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
792
904
  const parent = matched.get(part.within.join(" "));
793
905
  if (parent === void 0)
794
906
  continue;
795
- const candidates = (await factsOf(parent)).filter((fact) => !fact.component);
907
+ const candidates = (await factsOf(parent)).filter((fact) => fact.component === (part.kind === "component"));
796
908
  for (const fact of candidates) {
797
909
  const shared = fact.classes.markers.filter((marker) => declaredMarkers.has(marker));
798
910
  if (shared.length > 1)
@@ -803,21 +915,23 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
803
915
  if (part.required && match === void 0)
804
916
  return fail(node, { kind: "part-missing-or-repeated", part: part.name });
805
917
  for (const shape of matches) {
806
- const tag = shape.opening.tagName.getText(), host = parent.tagName.getText();
918
+ const tag = values.tag(shape.opening), host = values.tag(parent);
807
919
  if (!VECTOR_SHAPES.includes(tag) || host !== "svg")
808
920
  return fail(shape.opening, { kind: "part-element-mismatch", part: part.name, expected: VECTOR_SHAPES.map((shapeTag) => `<svg> > <${shapeTag}>`), actual: `<${host}> > <${tag}>` });
809
921
  }
810
922
  continue;
811
923
  }
812
- if (matches.length > 1 || match?.repeated === !0 || part.required && match === void 0)
924
+ if (!part.repeat && (matches.length > 1 || match?.repeated === !0) || part.required && match === void 0)
813
925
  return fail(node, { kind: "part-missing-or-repeated", part: part.name });
814
926
  if (match === void 0)
815
927
  continue;
928
+ if (part.kind === "component")
929
+ continue;
816
930
  matched.set([...part.within, part.selector].join(" "), match.opening);
817
931
  const ariaHidden = attr(match.opening, "aria-hidden");
818
932
  if (tinted.has(part.name) && ariaHidden !== void 0 && (ariaHidden.initializer === void 0 || [!0, "true"].includes(await resolve(expression(ariaHidden), context))))
819
933
  decorative.add(part.name);
820
- const element = match.opening.tagName.getText(), hostless = part.pseudo.find((pseudo) => !PSEUDO_HOSTS[pseudo].includes(element));
934
+ const element = values.tag(match.opening), hostless = part.pseudo.find((pseudo) => !PSEUDO_HOSTS[pseudo].includes(element));
821
935
  if (hostless !== void 0)
822
936
  return fail(match.opening, { kind: "pseudo-host-unsupported", part: part.name, pseudo: hostless, element });
823
937
  await nativeElement(match.opening, part.element, part.name, parent, context, resolve);
@@ -838,13 +952,15 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
838
952
  if ((foundation.profiles.get(sequence)?.fields.repeat ?? "loop") !== "once")
839
953
  review(authoredAt(classes.calls, `${part.path}.play`) ?? node, { kind: "motion-endless", part: part.name, sequence });
840
954
  if (part.clamped) {
841
- const enclosing = part.within.map((_, index) => matched.get(part.within.slice(0, index + 1).join(" "))), control = [match.opening, ...enclosing.reverse(), opening].find((element) => element !== void 0 && CONTROL_TEXT_TAGS.includes(element.tagName.getText()));
955
+ const enclosing = part.within.map((_, index) => matched.get(part.within.slice(0, index + 1).join(" "))), control = [match.opening, ...enclosing.reverse(), opening].find((element) => element !== void 0 && CONTROL_TEXT_TAGS.includes(values.tag(element)));
842
956
  if (control !== void 0)
843
- return fail(match.opening, { kind: "clamp-on-control", part: part.name, element: `<${control.tagName.getText()}>` });
957
+ return fail(match.opening, { kind: "clamp-on-control", part: part.name, element: `<${values.tag(control)}>` });
844
958
  }
845
959
  guardChild(match, part.selector, part.within);
846
960
  if (part.kind === "text")
847
961
  hasText = !0;
962
+ if (parsed.value.kind === "control" && part.kind === "element")
963
+ await pointerTransparent(match.opening, part.name, context, resolve);
848
964
  if (part.kind !== "visual")
849
965
  continue;
850
966
  if (part.scheme !== null) {
@@ -859,13 +975,14 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
859
975
  if (loading === void 0 || await resolve(expression(loading), context) !== "lazy")
860
976
  return fail(loading ?? match.opening, { kind: "scheme-image-not-lazy", part: part.name, scheme: part.scheme, defaultScheme });
861
977
  }
862
- if (visual !== void 0 && !schemed)
978
+ if (visual !== void 0 && !schemed && !several)
863
979
  return fail(match.opening, { kind: "visual-binding-count" });
864
980
  schemed = !0;
865
- visual = { kind: "content-media" };
981
+ visual ??= { kind: "content-media" };
982
+ visuals.set(part.name, { fact: { kind: "content-media" }, drawings: void 0 });
866
983
  continue;
867
984
  }
868
- if (visual !== void 0)
985
+ if (visual !== void 0 && !several)
869
986
  return fail(match.opening, { kind: "visual-binding-count" });
870
987
  if (part.media === "inspected-svg") {
871
988
  if (match.classes.bindings.length > 0)
@@ -876,11 +993,13 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
876
993
  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
994
  return fail(match.opening, { kind: "inspected-svg-inline", part: part.name });
878
995
  inspected = !0;
879
- visual = { kind: "inspected-svg" };
996
+ visual ??= { kind: "inspected-svg" };
997
+ visuals.set(part.name, { fact: { kind: "inspected-svg" }, drawings: void 0 });
880
998
  continue;
881
999
  }
882
- if (match.classes.bindings.length === 0 && parsed.value.kind === "region" && match.opening.tagName.getText() === "img") {
883
- visual = { kind: "content-media" };
1000
+ if (match.classes.bindings.length === 0 && parsed.value.kind === "region" && values.tag(match.opening) === "img") {
1001
+ visual ??= { kind: "content-media" };
1002
+ visuals.set(part.name, { fact: { kind: "content-media" }, drawings: void 0 });
884
1003
  continue;
885
1004
  }
886
1005
  const [binding] = match.classes.bindings, declared = binding === void 0 ? null : visualBinding(binding.part);
@@ -897,18 +1016,18 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
897
1016
  if (typeof selected !== "object" || selected === null || selected.kind !== "asset-source" || selected.handle.node !== binding.handle.node || selected.name !== binding.name)
898
1017
  return fail(target, { kind: "artwork-mismatch" });
899
1018
  };
1019
+ let shown;
900
1020
  switch (declared.kind) {
901
1021
  case "asset": {
902
1022
  const asset = resolveAsset(assets, declared.asset);
903
1023
  if (asset === void 0)
904
1024
  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;
1025
+ shown = { fact: { kind: "asset", asset, state: declared.state, visualProfile: declared.visual, theme }, drawings: asset.name };
907
1026
  boundAssets.add(asset.name);
908
1027
  const target = asset.paint === "intrinsic" ? await intrinsicSource(match.opening, context, resolve) : inlineSource(match.opening);
909
1028
  await bindingSource(target);
910
1029
  await pressedPairing(opening, binding.handle.node, asset, declared.state, context, resolve);
911
- assetSources.push({ kind: "drawing", target });
1030
+ assetSources.push({ kind: "drawing", target, part: part.name, asset: asset.name });
912
1031
  break;
913
1032
  }
914
1033
  case "set": {
@@ -922,38 +1041,48 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
922
1041
  await bindingSource(lookup);
923
1042
  await pressedPairing(opening, binding.handle.node, representative, declared.state, context, resolve);
924
1043
  await checkSetKey(checker, set, key, fail);
925
- visual = { kind: "asset", asset: representative, state: declared.state, visualProfile: declared.visual, theme };
926
- drawings = drawingsIdentity(representative);
1044
+ shown = { fact: { kind: "asset", asset: representative, state: declared.state, visualProfile: declared.visual, theme }, drawings: drawingsIdentity(representative) };
927
1045
  boundSets.add(set.name);
928
- assetSources.push({ kind: "lookup", target: lookup, set, state: declared.state });
1046
+ assetSources.push({ kind: "lookup", target: lookup, set, state: declared.state, part: part.name });
929
1047
  break;
930
1048
  }
931
1049
  case "reference": {
932
1050
  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);
1051
+ shown = { fact: { kind: "asset", asset: representative, state: "normal", visualProfile: declared.visual, theme }, drawings: drawingsIdentity(representative) };
935
1052
  references.add(glyph);
936
1053
  break;
937
1054
  }
938
1055
  }
1056
+ visuals.set(part.name, shown);
1057
+ if (visual === void 0) {
1058
+ visual = shown.fact;
1059
+ drawings = shown.drawings;
1060
+ }
939
1061
  }
940
1062
  for (const fact of allFacts) {
941
1063
  const shared = fact.classes.markers.filter((marker) => declaredMarkers.has(marker));
942
1064
  if (shared.length > 1)
943
1065
  return fail(fact.opening, { kind: "markers-shared", markers: shared });
944
1066
  }
945
- if (parsed.value.kind === "control" && !hasText && visual !== void 0 && !await namedByAttribute(opening, async (condition) => values.truthy(await resolve(condition, context), condition, context)))
946
- 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 });
1067
+ 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)))
1068
+ return fail(opening, { kind: "control-name-missing", element: values.tag(opening) });
1069
+ 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] : [])])];
1070
+ if (rootTheme !== void 0 && boundThemes.length > 0) {
1071
+ const named = await resolve(expression(rootTheme), context), other = boundThemes.find((name) => name !== named);
1072
+ if (other !== void 0)
1073
+ return fail(rootTheme, { kind: "data-theme-mismatch", expected: other });
1074
+ }
950
1075
  if (theme !== void 0)
951
1076
  artworkThemed.add(opening);
952
1077
  const inherited = new Map, aligned = new Map;
953
1078
  for (const selector of declaredCells(parsed.value)) {
954
- const cells = allFacts.filter((fact) => fact.classes.markers.includes(selector.slice(1))), [cell] = cells, single = cells.length === 1 && cell?.repeated === !1;
955
- if (!/^\.[\w-]+$/.test(selector) || cell === void 0 || !single && !autoPlaced(parsed.value, selector))
1079
+ const cells = allFacts.filter((fact) => fact.classes.markers.includes(selector.slice(1))), [cell] = cells, declared = parsed.value.kind === "grid" ? parsed.value.cells.find((item) => item.selector === selector) : void 0, single = cells.length === 1 && cell?.repeated === !1, many = declared?.repeat === !0 || autoPlaced(parsed.value, selector);
1080
+ if (!/^\.[\w-]+$/.test(selector) || cell === void 0 && declared?.required !== !1 || cell !== void 0 && !single && !many)
956
1081
  return fail(node, { kind: "cell-missing-or-repeated", cell: selector });
1082
+ if (declared !== void 0 && !declared.required && [declared.values, ...declared.at.map(([, values]) => values)].some((values) => values.some(([field]) => field === "row")))
1083
+ review(authoredAt(classes.calls, `recipe.cells.${selector}.row`) ?? node, { kind: "optional-cell-row", cell: selector });
1084
+ if (cell === void 0)
1085
+ continue;
957
1086
  for (const each of cells)
958
1087
  guardChild(each, selector);
959
1088
  if (cell.classes.fragments.length === 0)
@@ -985,37 +1114,54 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
985
1114
  ...inherited.size > 0 ? [[...inherited].map(([selector, nested]) => [selector, nested.source])] : [],
986
1115
  ...aligned.size > 0 ? [[...aligned]] : [],
987
1116
  ...writesInline ? [scope] : [],
988
- ...decorative.size > 0 ? [["decorative", ...decorative]] : []
1117
+ ...decorative.size > 0 ? [["decorative", ...decorative]] : [],
1118
+ ...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
1119
  ], 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
1120
  let owned = styles.get(key);
991
1121
  if (owned === void 0) {
992
1122
  if (styles.size >= choiceLimits.alternatives)
993
1123
  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) };
1124
+ 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) => {
1125
+ const reviews = [], failed = (failure, at = null) => ({ kind: "failed", failure: { path: at, item: failure }, reviews }), lowered = lower(spec, read, rootName, input);
1126
+ if (lowered.kind === "err")
1127
+ return failed(lowered.error);
1128
+ const misused = inactiveSurfaceActive(read, spec);
1129
+ if (misused !== null)
1130
+ return failed(misused);
1131
+ const contrast = stateContrast(read, spec, paintedBy);
1132
+ if (contrast.kind === "err")
1133
+ return failed(contrast.error);
1134
+ for (const unresolved of contrast.value)
1135
+ reviews.push({ path: null, item: unresolved });
1136
+ const nonText = nonTextContrast(read, spec);
1137
+ if (nonText.kind === "err")
1138
+ return failed(nonText.error);
1139
+ for (const unresolved of nonText.value)
1140
+ reviews.push({ path: null, item: unresolved });
1141
+ const overpaint = cornerOverpaint(read, spec);
1142
+ if (overpaint !== null)
1143
+ return failed(overpaint, `recipe.parts.${overpaint.part}`);
1144
+ const painted = runtimePaintContrast(read, spec);
1145
+ if (painted.kind === "err")
1146
+ return failed(painted.error);
1147
+ for (const unresolved of painted.value)
1148
+ reviews.push({ path: null, item: unresolved });
1149
+ for (const shifted of hoverGeometry(spec))
1150
+ reviews.push({ path: shifted.path, item: { kind: "hover-geometry-shift", element: shifted.element, condition: shifted.condition } });
1151
+ return { kind: "built", owned: {
1152
+ ...lowered.value,
1153
+ origins: [],
1154
+ surfaceUses: surfaceUses(read, spec, lowered.value.profiles, paintedBy),
1155
+ paints: declaredPaints(spec).map((paint) => ({ name: paint.name, property: paintProperty(scope, paint.name), values: paint.values })),
1156
+ glyphs: [],
1157
+ content: []
1158
+ }, reviews };
1159
+ }), at = (path) => path === null ? node : authoredAt(classes.calls, path) ?? node;
1160
+ for (const noted of built.reviews)
1161
+ review(at(noted.path), noted.item);
1162
+ if (built.kind === "failed")
1163
+ return fail(at(built.failure.path), { kind: "construction", failure: built.failure.item });
1164
+ owned = { ...built.owned, origins: [], glyphs: [], content: [] };
1019
1165
  styles.set(key, owned);
1020
1166
  }
1021
1167
  if (owned.facts.kind === "region" && owned.facts.exposed !== null)
@@ -1028,7 +1174,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1028
1174
  const classes = split(await resolve(classAttribute, context), classAttribute);
1029
1175
  if (classes.fragments.length === 0)
1030
1176
  return null;
1031
- const combined = combineRecipes(...classes.fragments), spec = combined.kind === "ok" ? parseConstruction(combined.value.spec) : null;
1177
+ const spec = parsedOf(classes.fragments);
1032
1178
  return spec?.kind === "ok" ? spec.value : null;
1033
1179
  }, report = (finding, host) => {
1034
1180
  const at = expression(attr(host, "className")) ?? host;
@@ -1044,7 +1190,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1044
1190
  fail(expression(attr(host, "className")) ?? host, missed);
1045
1191
  }, check = (place, spec, component) => tiles ? tileFrameFinding(foundation, place, spec, component, regions) : component !== null ? componentCellFinding(foundation, place.cell, component, regions) : spec === null ? null : frameRegionFinding(foundation, place, spec, regions, moved), inside = async (cell, host, path) => {
1046
1192
  for (const child of await children(host, context, resolve)) {
1047
- const step = lowercaseTag(child) ? { kind: "element", tag: child.tagName.getText(), spec: await constructionOf(child) } : { kind: "component", name: child.tagName.getText() };
1193
+ const step = lowercaseTag(child) ? { kind: "element", tag: values.tag(child), spec: await constructionOf(child) } : { kind: "component", name: values.tag(child) };
1048
1194
  if (step.kind === "element") {
1049
1195
  if (step.spec?.kind === "grid")
1050
1196
  continue;
@@ -1056,14 +1202,14 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1056
1202
  }
1057
1203
  }, visit = async (cell, opening) => {
1058
1204
  if (!lowercaseTag(opening)) {
1059
- report(check({ cell, element: null, path: [] }, null, opening.tagName.getText()), opening);
1205
+ report(check({ cell, element: null, path: [] }, null, values.tag(opening)), opening);
1060
1206
  return;
1061
1207
  }
1062
1208
  const own = await constructionOf(opening);
1063
1209
  report(check({ cell, element: null, path: [] }, own, null), opening);
1064
1210
  aligned({ cell, element: null, path: [] }, own, opening);
1065
1211
  if (own?.kind !== "grid")
1066
- return inside(cell, opening, [{ kind: "element", tag: opening.tagName.getText(), spec: own }]);
1212
+ return inside(cell, opening, [{ kind: "element", tag: values.tag(opening), spec: own }]);
1067
1213
  if (own.mode !== "inherited")
1068
1214
  return;
1069
1215
  for (const child of await children(opening, context, resolve)) {
@@ -1075,7 +1221,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1075
1221
  };
1076
1222
  if (tiles)
1077
1223
  for (const fact of allFacts)
1078
- await visit(`a tile <${fact.opening.tagName.getText()}>`, fact.opening);
1224
+ await visit(`a tile <${values.tag(fact.opening)}>`, fact.opening);
1079
1225
  else
1080
1226
  for (const selector of declaredCells(parsed.value))
1081
1227
  for (const fact of allFacts.filter((item) => item.classes.markers.includes(selector.slice(1))))
@@ -1084,15 +1230,29 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1084
1230
  const at = location(node);
1085
1231
  if (!owned.origins.some((origin) => origin.kind === "point" && origin.position.line === at.line && origin.position.column === at.column))
1086
1232
  owned.origins.push({ kind: "point", file: name, position: { line: at.line, column: at.column } });
1087
- const lowered = owned, code = (pending) => {
1233
+ const lowered = owned;
1234
+ for (const attribute of await contentAttributes(opening))
1235
+ if (!(owned.content ?? []).includes(attribute))
1236
+ owned.content?.push(attribute);
1237
+ const placedFor = (part) => lowered.facts.kind === "region" ? lowered.facts.artworks.get(part) ?? placedArtwork(lowered) : placedArtwork(lowered), code = (pending) => {
1088
1238
  switch (pending.kind) {
1089
- case "drawing":
1090
- return JSON.stringify(artworkSource(lowered));
1239
+ case "drawing": {
1240
+ const placedArt = placedFor(pending.part);
1241
+ if (placedArt !== null)
1242
+ used(pending.asset, placedArt.size);
1243
+ return JSON.stringify(placedArt?.source ?? "");
1244
+ }
1091
1245
  case "lookup": {
1092
- const drawing = placedArtwork(lowered)?.drawing;
1246
+ const drawing = placedFor(pending.part)?.drawing;
1093
1247
  if (drawing === void 0 || theme === void 0)
1094
1248
  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);
1249
+ const lookup = setLookupCode(assets, pending.set, parsed.value.kind === "control" ? LIGHT : theme, drawing, pending.state);
1250
+ for (const member of pending.set.members)
1251
+ used(member, placedFor(pending.part)?.size ?? null);
1252
+ const selector = declaredParts(parsed.value).find((part) => part.name === pending.part)?.selector;
1253
+ if (selector !== void 0 && !(owned.glyphs ?? []).some((known) => known.part === selector))
1254
+ owned.glyphs?.push({ part: selector, members: JSON.parse(lookup.slice(1, -1)) });
1255
+ return lookup;
1096
1256
  }
1097
1257
  }
1098
1258
  };
@@ -1255,10 +1415,10 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1255
1415
  for (const opening of openings) {
1256
1416
  if (!lowercaseTag(opening))
1257
1417
  continue;
1258
- const tag = opening.tagName.getText();
1418
+ const tag = values.tag(opening);
1259
1419
  if (tag === "img" && attr(opening, "alt") === void 0)
1260
1420
  return fail(opening, { kind: "image-alt-missing" });
1261
- if (clickWithoutKeyboard(opening))
1421
+ if (clickWithoutKeyboard(opening, tag))
1262
1422
  review(opening, { kind: "click-without-keyboard", element: tag });
1263
1423
  if (!sections && !artworkThemed.has(opening))
1264
1424
  for (const attribute of ["data-theme", "data-brand"]) {
@@ -1268,10 +1428,10 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1268
1428
  }
1269
1429
  }
1270
1430
  for (const opening of openings) {
1271
- const component = !lowercaseTag(opening), suggestion = missingAutocomplete(opening, component);
1431
+ const component = !lowercaseTag(opening), suggestion = missingAutocomplete(opening, component, values.tag(opening));
1272
1432
  if (suggestion === null || component && !await takesAutocomplete(opening))
1273
1433
  continue;
1274
- review(opening, { kind: "autocomplete-missing", element: opening.tagName.getText(), suggestion });
1434
+ review(opening, { kind: "autocomplete-missing", element: values.tag(opening), suggestion });
1275
1435
  }
1276
1436
  if (!openings.some((opening) => opening.attributes.properties.some((attribute) => isJsxAttribute(attribute) && /^on(?:Pointer|Touch)[A-Z]/.test(nameText(attribute.name) ?? ""))))
1277
1437
  for (const { at, element } of touchDisabled)
@@ -1293,7 +1453,7 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1293
1453
  if (declaration !== void 0 && (isBindingElement(declaration) || isParameterDeclaration(declaration)) && declaration.name === identifier)
1294
1454
  continue;
1295
1455
  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)))
1456
+ if (!(identifier.parent !== void 0 && isJsxExpression(identifier.parent) && host !== null && !lowercaseTag(host)) && !presenceTest(identifier))
1297
1457
  return fail(identifier, { kind: "glyph-reference-read", name: identifier.text });
1298
1458
  }
1299
1459
  const assetEdits = new Map;
@@ -1315,14 +1475,20 @@ async function analyzeOwner(root, emitted, name, program, options, rowsOf, fail)
1315
1475
  const rewritten = await publicImports({ root, file: name, source, publicModule: options.publicAlias, symbolOf: values.symbol, emitted, fail }), imports = [...rewritten.imports];
1316
1476
  for (const statement of rewritten.statements)
1317
1477
  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 };
1478
+ 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) => {
1479
+ const [asset = "", size = ""] = key.split("\x00");
1480
+ return { asset, size: size === "" ? null : size };
1481
+ }), artwork = { assets: [...boundAssets].sort(), sets: [...boundSets].sort(), glyphs: macros.glyphs, support: macros.support, uses };
1319
1482
  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
1483
  }
1484
+ function drawnRecords(input, root) {
1485
+ return [input.visual, ...input.visuals.values()].map((fact) => fact !== null && fact.kind === "asset" ? designValueDigest(fact.asset, root) : null);
1486
+ }
1321
1487
  function lower(spec, foundation, root, input) {
1322
1488
  const asset = input.visual?.kind === "asset" ? input.visual : null;
1323
1489
  switch (spec.kind) {
1324
1490
  case "control":
1325
- return lowerControl(spec, foundation, { root, asset: asset?.asset ?? null, state: asset?.state ?? "normal", hasText: input.hasText, hidden: input.hidden });
1491
+ 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
1492
  case "artwork":
1327
1493
  return lowerArtwork(spec, foundation, {
1328
1494
  root,
@@ -1333,7 +1499,7 @@ function lower(spec, foundation, root, input) {
1333
1499
  hidden: input.hidden
1334
1500
  });
1335
1501
  case "region":
1336
- return lowerRegion(spec, foundation, { root, visual: input.visual, hidden: input.hidden, scope: input.scope });
1502
+ return lowerRegion(spec, foundation, { root, visual: input.visual, visuals: input.visuals, hidden: input.hidden, scope: input.scope });
1337
1503
  case "grid":
1338
1504
  return lowerGrid(spec, foundation, { root, hidden: input.hidden, inherited: input.inherited, aligned: input.aligned, scope: input.scope });
1339
1505
  }
@@ -1351,7 +1517,16 @@ function placedArtwork(construction) {
1351
1517
  return null;
1352
1518
  }
1353
1519
  }
1354
- const artworkSource = (construction) => placedArtwork(construction)?.source ?? "", AUTHORING_LEAK = /@reqvire-org\/ads|type:\s*"macro"|__adsRecipe/, jsxRuntime = (framework) => `${framework ?? "react"}/jsx-runtime`;
1520
+ const AUTHORING_LEAK = /@reqvire-org\/ads|type:\s*"macro"|__adsRecipe/, jsxRuntime = (framework) => `${framework ?? "react"}/jsx-runtime`, FACTOR_FROM_LEAVES = 32;
1521
+ function emitClasses(result, classFor) {
1522
+ const full = () => emitChoice(result.tree, (value) => value.kind === "absent" ? null : JSON.stringify(classFor(value))) ?? '""';
1523
+ if (result.leaves.length < FACTOR_FROM_LEAVES)
1524
+ return full();
1525
+ const factored = factorClasses(result.leaves.map((leaf) => ({ ...leaf, value: leaf.value.kind === "absent" ? null : classFor(leaf.value) })), result.axes);
1526
+ if (factored === null)
1527
+ return full();
1528
+ return `(${[JSON.stringify(factored.base), ...factored.groups.map((group) => emitChoice(group.tree, (value) => JSON.stringify(value)) ?? '""')].join(' + " " + ')})`;
1529
+ }
1355
1530
  export async function emitOwners(analysis, target = { kind: "compiled" }, dependencies = { packageManifest: null }) {
1356
1531
  const { foundation, compiled } = analysis, scoped = target.kind === "scoped";
1357
1532
  return attemptAsync(async (reject) => {
@@ -1451,7 +1626,7 @@ export async function ownerModuleSource(name, owner, classOf, fail) {
1451
1626
  return [...value.markers, compiledClass].join(" ");
1452
1627
  };
1453
1628
  for (const { node, result } of selections) {
1454
- let text = emitChoice(result.tree, (value) => value.kind === "absent" ? null : JSON.stringify(classFor(value))) ?? '""';
1629
+ let text = emitClasses(result, classFor);
1455
1630
  const placements = [...new Set(result.leaves.flatMap((leaf) => leaf.value.kind === "styled" && leaf.value.placement !== null ? [leaf.value.placement] : []))], [placement] = placements;
1456
1631
  if (placements.length > 1)
1457
1632
  fail(node, { kind: "placement-repeated" });
@@ -1553,3 +1728,22 @@ export async function emissionFacts(root, outcomes, selected, options) {
1553
1728
  return owners;
1554
1729
  });
1555
1730
  }
1731
+ function presenceTest(identifier) {
1732
+ let node = identifier;
1733
+ while (node.parent !== void 0 && isParenthesizedExpression(node.parent))
1734
+ node = node.parent;
1735
+ const parent = node.parent;
1736
+ if (parent === void 0)
1737
+ return !1;
1738
+ if (isPrefixUnaryExpression(parent))
1739
+ return parent.operator === SyntaxKind.ExclamationToken;
1740
+ if (isConditionalExpression(parent))
1741
+ return parent.condition === node;
1742
+ if (!isBinaryExpression(parent))
1743
+ return !1;
1744
+ const operator = parent.operatorToken.kind;
1745
+ if (operator === SyntaxKind.AmpersandAmpersandToken)
1746
+ return parent.left === node || presenceTest(parent);
1747
+ const equality = [SyntaxKind.EqualsEqualsEqualsToken, SyntaxKind.ExclamationEqualsEqualsToken, SyntaxKind.EqualsEqualsToken, SyntaxKind.ExclamationEqualsToken].includes(operator), other = parent.left === node ? parent.right : parent.left;
1748
+ return equality && (isIdentifier(other) && other.text === "undefined" || other.kind === SyntaxKind.NullKeyword);
1749
+ }