@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
@@ -26,16 +26,12 @@ import {
26
26
  writeStateText
27
27
  } from "./construction-output.mjs";
28
28
  import { settled } from "./lowering-enter.mjs";
29
- import { paintContrast } from "./paint-contrast.mjs";
30
- import { PROSE_BLOCKS, PROSE_COMPONENT, PROSE_ELEMENTS, PROSE_ELEMENT_NAMES, PROSE_FIRST, proseContents, proseDefaults, proseSelector, proseState } from "./prose-model.mjs";
31
- import { textMinimum } from "./surface-contrast.mjs";
32
- import { tokenValueContexts } from "./design-foundation.mjs";
33
- import { checkPlaceholderContrast } from "./placeholder-contrast.mjs";
29
+ import { checkPlaceholderContrast, checkProgressContrast } from "./placeholder-contrast.mjs";
34
30
  import { fixedLength, lowerLayer, openState, ownsPlacement } from "./lowering-layer.mjs";
35
31
  import { RATIO_SUFFIX, focalPosition, intrinsicInlineSize, measuredFallback, measuredProperty, measuredWrites, positions } from "./measured-geometry.mjs";
36
32
  import { paintProperty, paintTokens, paintWrites } from "./runtime-paint.mjs";
37
33
  import { conditionBound, conditionQueries, geometryOf, tierBelowQuery } from "./spatial-reading.mjs";
38
- import { FRAME_CORNERS } from "./construction-spec.mjs";
34
+ import { CORNER_RADIUS_FIELDS, cornerRadius, FRAME_CORNERS } from "./construction-spec.mjs";
39
35
  import {
40
36
  LAYER,
41
37
  MARKER_HIDDEN,
@@ -44,6 +40,7 @@ import {
44
40
  conditionValues,
45
41
  elementNormalization,
46
42
  extentValues,
43
+ growsWithContent,
47
44
  frameInsets,
48
45
  frameRules,
49
46
  layeredValues,
@@ -70,8 +67,6 @@ function arrangementValues(arrangement, slots, profile, overflow = { kind: "visi
70
67
  const values = {}, scrolls = (axis) => overflow.kind === "scroll" && (overflow.axis === axis || overflow.axis === "both"), { layout } = arrangement;
71
68
  if (layout === "native")
72
69
  return values;
73
- if (layout === "prose")
74
- return { display: "flow-root" };
75
70
  if (layout === "layered")
76
71
  return { ...layeredValues(arrangement.align, arrangement.justify) };
77
72
  if (layout === "inline" || layout === "stack") {
@@ -89,12 +84,92 @@ function arrangementValues(arrangement, slots, profile, overflow = { kind: "visi
89
84
  const spacingReference = slots["spacing-profile"];
90
85
  if (spacingReference !== void 0) {
91
86
  const spacing = profile.of(spacingReference, "spacing"), field = arrangement.gap === null ? "content-gap" : kebab(arrangement.gap.field);
92
- values[layout === "flow" ? "row-gap" : "gap"] = profile.field(spacing, "spacing", field);
87
+ if (arrangement.overlap === null)
88
+ values[layout === "flow" ? "row-gap" : "gap"] = profile.field(spacing, "spacing", field);
93
89
  } else if (arrangement.gap !== null)
94
90
  profile.field({}, "spacing-profile", kebab(arrangement.gap.field));
95
91
  return values;
96
92
  }
97
- const FRAME_FIELDS = [...FRAME_INSET_FIELDS, ...FRAME_SIDE_WIDTH_FIELDS, BORDER_STYLE, "border-width", "radius", "min-block-size", "block-size", "max-block-size", "inline-size", "min-inline-size", "max-inline-size", ...HIT_AREA_FIELDS], isHitAreaField = (field) => HIT_AREA_FIELDS.some((name) => name === field);
93
+ function overlapValue(arrangement, slots, profile) {
94
+ if (arrangement === null || arrangement.overlap === null)
95
+ return null;
96
+ return profile.field(profile.of(slots["spacing-profile"], "spacing", "overlap"), "spacing", kebab(arrangement.overlap.by.field));
97
+ }
98
+ const OVERLAPPED = "> * + *", overlapMargin = (arrangement) => arrangement.layout === "stack" ? "margin-block-start" : "margin-inline-start";
99
+ function geometryChannel(property) {
100
+ if (/^(?:min-|max-)?(?:inline|block)-size$/.test(property) || property === "grid-template-columns" || property === "grid-template-rows")
101
+ return "size";
102
+ if (property.startsWith("padding-"))
103
+ return "inset";
104
+ if (property === "gap" || property === "row-gap")
105
+ return "gap";
106
+ if (property.includes("radius"))
107
+ return "radius";
108
+ if (/^border-.*width$/.test(property))
109
+ return "border-width";
110
+ return null;
111
+ }
112
+ const collapsedValues = (collapsed, axis) => ({
113
+ [`${axis}-size`]: collapsed ? "0" : "auto",
114
+ opacity: collapsed ? "0" : "1",
115
+ visibility: collapsed ? "hidden" : "visible"
116
+ }), collapsibleValues = (axis) => ({ "flex-grow": "0", "flex-shrink": "0", "flex-basis": "auto", [`min-${axis}-size`]: "0", overflow: "clip", "interpolate-size": "allow-keywords" });
117
+ function writeStateGeometry(path, element, rest, states, transition, frameOf, context) {
118
+ const { out, profile, slots, reject } = context, unsupported = (reason, detail) => reject({ kind: "state-geometry-unsupported", element, reason, detail }), changed = new Set, overlapStates = new Map, gaps = [], restOverlap = overlapValue(rest.arrangement, slots, profile), differing = (base, state) => Object.fromEntries(Object.entries(state).filter(([property, value]) => base[property] !== value));
119
+ for (const state of states) {
120
+ const values = {};
121
+ if (state.frame !== null) {
122
+ if (rest.frame === null)
123
+ return unsupported("frame-missing", state.frame);
124
+ const framed = frameOf(state.frame), dropped = Object.keys(rest.frame).find((property) => framed[property] === void 0);
125
+ if (dropped !== void 0)
126
+ return unsupported("field-dropped", dropped);
127
+ Object.assign(values, differing(rest.frame, framed));
128
+ }
129
+ if (state.spacing !== null && rest.arrangement !== null) {
130
+ const stated = { ...slots, "spacing-profile": state.spacing };
131
+ Object.assign(values, differing(rest.arranged, arrangementValues(rest.arrangement, stated, profile)));
132
+ const overlap = overlapValue(rest.arrangement, stated, profile);
133
+ if (overlap !== null && overlap !== restOverlap) {
134
+ out.rule(`${under(state.condition, path)} ${OVERLAPPED}`, { [overlapMargin(rest.arrangement)]: `calc(-1 * ${overlap})` });
135
+ overlapStates.set(state.condition, `calc(-1 * ${overlap})`);
136
+ }
137
+ }
138
+ if (state.collapsed !== null && rest.collapsed !== null && rest.axis !== null && state.collapsed !== rest.collapsed)
139
+ Object.assign(values, collapsedValues(state.collapsed, rest.axis));
140
+ for (const property of Object.keys(values))
141
+ changed.add(property);
142
+ if (values.gap !== void 0)
143
+ gaps.push(values.gap);
144
+ if (Object.keys(values).length > 0)
145
+ out.rule(under(state.condition, path), values);
146
+ if (state.condition.includes(":hover")) {
147
+ const same = (other) => other.frame === state.frame && other.spacing === state.spacing && other.collapsed === state.collapsed;
148
+ if (!states.some((other) => other !== state && same(other) && !other.condition.includes(":hover") && /:focus|\[/.test(other.condition)))
149
+ return unsupported("hover-only", state.condition);
150
+ }
151
+ }
152
+ const overlapChanges = overlapStates.size > 0, parentOverlap = (group) => restOverlap === null || rest.arrangement === null ? null : { property: overlapMargin(rest.arrangement), base: `calc(-1 * ${restOverlap})`, states: overlapStates, group };
153
+ if (transition === null)
154
+ return { group: null, overlap: parentOverlap(null), gaps };
155
+ const timing = transitionTiming(motionFields(transition.motion, slots, profile), profile, reject), channelOf = (property) => geometryChannel(property);
156
+ for (const channel of transition.channels) {
157
+ if (channel === "overlap")
158
+ continue;
159
+ if (!([...changed].some((property) => channelOf(property) === channel) || channel === "gap" && overlapChanges))
160
+ return unsupported("channel-unused", channel);
161
+ }
162
+ const listed = (property) => {
163
+ const channel = channelOf(property);
164
+ return channel !== null && transition.channels.includes(channel);
165
+ }, fading = [...changed].filter((property) => (property === "opacity" || property === "visibility") && transition.channels.includes("size")), placed = transition.channels.includes("overlap") ? ["margin-inline-start", "margin-block-start"] : [], properties = [...[...changed].filter(listed), ...fading, ...placed];
166
+ return {
167
+ group: properties.length === 0 ? null : { properties, timing },
168
+ overlap: parentOverlap(overlapChanges && transition.channels.includes("gap") && rest.arrangement !== null ? { properties: [overlapMargin(rest.arrangement)], timing } : null),
169
+ gaps
170
+ };
171
+ }
172
+ const CORNER_FIELDS = Object.values(CORNER_RADIUS_FIELDS), FRAME_FIELDS = [...FRAME_INSET_FIELDS, ...FRAME_SIDE_WIDTH_FIELDS, BORDER_STYLE, "border-width", "radius", ...CORNER_FIELDS, "min-block-size", "block-size", "max-block-size", "inline-size", "min-inline-size", "max-inline-size", ...HIT_AREA_FIELDS], isHitAreaField = (field) => HIT_AREA_FIELDS.some((name) => name === field);
98
173
  export function frameValues(frame, profile, reject, sides = { kind: "profile" }) {
99
174
  profile.only(frame, "frame", FRAME_FIELDS);
100
175
  const insets = frameInsets(frame);
@@ -110,13 +185,23 @@ export function frameValues(frame, profile, reject, sides = { kind: "profile" })
110
185
  Object.assign(values, border(value));
111
186
  for (const side of ["top", "right", "bottom", "left"])
112
187
  values[`border-${side}-style`] = frame[BORDER_STYLE] ?? "solid";
113
- } else if (property === BORDER_STYLE)
188
+ } else if (property === BORDER_STYLE || CORNER_FIELDS.includes(property))
114
189
  continue;
115
190
  else if (property === "radius")
116
191
  values["border-radius"] = value;
117
192
  else
118
193
  values[property] = value;
119
194
  }
195
+ if (CORNER_FIELDS.some((field) => frame[field] !== void 0)) {
196
+ delete values["border-radius"];
197
+ for (const corner of FRAME_CORNERS)
198
+ values[`border-${corner}-radius`] = cornerRadius((field) => frame[field], corner) ?? "0";
199
+ }
200
+ for (const axis of ["inline", "block"]) {
201
+ const size = values[`${axis}-size`];
202
+ if (size !== void 0 && values[`min-${axis}-size`] === void 0 && values[`max-${axis}-size`] === void 0)
203
+ values[`min-${axis}-size`] = size;
204
+ }
120
205
  return values;
121
206
  }
122
207
  function permittedRatio(ratio, slots, profile, reject) {
@@ -147,10 +232,10 @@ function regionFrameValues(frame, slots, surface, profile, reject) {
147
232
  Object.assign(values, rules.value);
148
233
  }
149
234
  if (frame.corners !== null) {
150
- const radius = values["border-radius"] ?? reject({ kind: "profile-field-missing", profile: frameReference ?? "frame", field: "radius" });
235
+ const named = frame.corners, radius = (corner) => cornerRadius((field) => fields[field], corner) ?? reject({ kind: "profile-field-missing", profile: frameReference ?? "frame", field: "radius" });
151
236
  delete values["border-radius"];
152
237
  for (const corner of FRAME_CORNERS)
153
- values[`border-${corner}-radius`] = frame.corners.includes(corner) ? radius : "0";
238
+ values[`border-${corner}-radius`] = named.includes(corner) ? radius(corner) : "0";
154
239
  }
155
240
  if (frame.container) {
156
241
  values["container-type"] = "inline-size";
@@ -196,80 +281,16 @@ function stickyValues(sticky, { profile, slots }) {
196
281
  ...layer["sticky-layer"] === void 0 ? {} : { "z-index": layer["sticky-layer"] }
197
282
  };
198
283
  }
199
- function lowerProse(prose, root, context) {
200
- const { out, profile, slots, foundation, reject } = context, spacing = (binding) => profile.field(profile.of(slots["spacing-profile"], "spacing", "prose"), "spacing", kebab(binding.field)), rhythm = prose.rhythm === null ? null : spacing(prose.rhythm), declared = new Map(prose.elements.map((element) => [element.name, element])), paints = new Map;
201
- for (const name of PROSE_ELEMENT_NAMES) {
202
- const element = declared.get(name), block = PROSE_BLOCKS.includes(name);
203
- if (element === void 0 && (!block || rhythm === null) && Object.keys(proseDefaults(name)).length === 0)
204
- continue;
205
- const text = element?.text == null ? {} : profile.of(element.text, "text"), surface = element?.surface == null ? {} : profile.of(element.surface, "surface"), states = (element?.when ?? []).map(([condition, state]) => [condition, profile.of(state, "surface")]);
206
- if (element !== void 0)
207
- checkSurfaceEffects(foundation, profile, [element.surface, ...element.when.map(([, state]) => state)], name === "media" ? "visual" : name === "pre" ? "scroller" : "container", reject);
208
- const frame = element?.frame == null ? {} : frameValues(profile.of(element.frame, "frame"), profile, reject), before = element?.spaceBefore == null ? rhythm : spacing(element.spaceBefore), values = {
209
- ...proseDefaults(name),
210
- ...block && (before !== null || element !== void 0) ? { "margin-block-start": before ?? "0", "margin-block-end": "0" } : {},
211
- ...element?.indent == null ? {} : { "padding-inline-start": spacing(element.indent) },
212
- ...text,
213
- ...frame,
214
- ...surface
215
- };
216
- for (const tag of PROSE_ELEMENTS[name]) {
217
- const selector = proseSelector(tag);
218
- if (Object.keys(values).length > 0)
219
- out.rule(selector, { ...values });
220
- for (const [condition, fields] of states)
221
- out.rule(proseState(selector, condition), { ...fields });
222
- if (element?.marker != null) {
223
- const fields = profile.of(element.marker, "surface"), other = Object.keys(fields).find((field) => field !== "color");
224
- if (other !== void 0 || fields.color === void 0)
225
- return reject({ kind: "profile-field-unsupported", profile: element.marker, field: other ?? "color", value: other === void 0 ? "" : fields[other] ?? "" });
226
- out.rule(`${selector}::marker`, { color: fields.color });
227
- }
228
- }
229
- if (element !== void 0)
230
- paints.set(name, { paints: [surface, ...states.map(([, fields]) => fields)].map((fields) => ({ color: fields.color ?? null, background: fields.background ?? null })), text });
231
- }
232
- if (rhythm !== null || prose.elements.some((element) => element.spaceBefore !== null))
233
- for (const selector of PROSE_FIRST)
234
- out.rule(selector, { "margin-block-start": "0" });
235
- if (rhythm !== null)
236
- out.rule(PROSE_COMPONENT, { "margin-block-start": rhythm });
237
- const base = { color: root.color ?? null, background: root.background ?? null }, colored = [...paints].filter(([, entry]) => entry.paints.some((paint) => paint.color !== null || paint.background !== null));
238
- if (colored.length === 0)
239
- return;
240
- const contexts = tokenValueContexts(foundation), prove = (name, text, foreground, background, on) => {
241
- if (foreground === null || background === null)
242
- return;
243
- for (const tokens of contexts) {
244
- const minimum = textMinimum({ fontSize: text["font-size"] ?? null, fontWeight: text["font-weight"] ?? null }, tokens), outcome = paintContrast(tokens, { foreground, background }, minimum);
245
- if (outcome.kind === "insufficient")
246
- return reject({ kind: "prose-contrast-insufficient", element: name, on, foreground, background, ratio: outcome.ratio, minimum: outcome.minimum, context: tokens.label });
247
- }
248
- };
249
- for (const [name, entry] of colored) {
250
- if (name === "rule" || name === "media")
251
- continue;
252
- for (const paint of entry.paints)
253
- prove(name, entry.text, paint.color ?? base.color, paint.background ?? base.background, "the prose root");
254
- }
255
- for (const [container, outer] of colored) {
256
- const [around] = outer.paints;
257
- if (around === void 0)
258
- continue;
259
- for (const inner of proseContents(container)) {
260
- const entry = paints.get(inner);
261
- if (entry === void 0 || inner === "rule" || inner === "media")
262
- continue;
263
- for (const paint of entry.paints)
264
- prove(inner, entry.text, paint.color ?? around.color ?? base.color, paint.background ?? around.background ?? base.background, `inside ${container}`);
265
- }
266
- }
284
+ function anchorClearValues(binding, { profile, slots }) {
285
+ if (binding === null)
286
+ return {};
287
+ return { "scroll-margin-block-start": binding.slot === "layer" ? profile.field(profile.of(slots["layer-profile"], "layer", "anchorClear"), "layer", "clear-block-start") : profile.field(profile.of(slots["spacing-profile"], "spacing", "anchorClear"), "spacing", "anchor-gap") };
267
288
  }
268
289
  function partMotion(path, effects, { out, profile, slots, reject }) {
269
290
  if (effects === null)
270
291
  return null;
271
292
  const motion = motionFields(effects.motion, slots, profile), timing = transitionTiming(motion, profile, reject), channels = new Set(effects.when.flatMap(([, names]) => names.map((name) => PART_EFFECTS[name].channel)));
272
- out.rule(path, { ...channels.has("translate") ? { translate: "0px" } : {}, ...channels.has("scale") ? { scale: "1" } : {} });
293
+ out.rule(path, { ...channels.has("translate") ? { translate: "0px" } : {}, ...channels.has("scale") ? { scale: "1" } : {}, ...channels.has("rotate") ? { rotate: "0deg" } : {} });
273
294
  const distance = () => profile.field(motion, "motion", "distance");
274
295
  for (const [condition, names] of effects.when) {
275
296
  const selector = under(condition, path), inline = names.includes("translateInline"), block = names.includes("translateBlock"), travel = (sign) => block ? `${inline ? sign : "0px"} ${distance()}` : sign, values = {};
@@ -278,6 +299,8 @@ function partMotion(path, effects, { out, profile, slots, reject }) {
278
299
  const scaled = names.find((name) => PART_EFFECTS[name].channel === "scale");
279
300
  if (scaled === "scale" || scaled === "scaleInline" || scaled === "scaleBlock")
280
301
  values.scale = scaleValue(scaled, profile.field(motion, "motion", "scale"));
302
+ if (names.includes("rotate"))
303
+ values.rotate = profile.field(motion, "motion", "angle");
281
304
  out.rule(selector, values);
282
305
  const mirrored = under(`${condition}:dir(rtl)`, path);
283
306
  if (inline)
@@ -313,22 +336,41 @@ function pseudoColor(treatment, surface, profile, reject) {
313
336
  return fields.color ?? reject({ kind: "pseudo-surface-unsupported", pseudo: treatment.pseudo, surface, field: null });
314
337
  }
315
338
  function pseudoRules(part, path, context) {
316
- const { out, profile, reject, foundation } = context;
317
- for (const treatment of part.pseudo) {
318
- const suffix = `::${treatment.pseudo}`, base = pseudoColor(treatment, treatment.surface, profile, reject), states = treatment.when.map(([condition, surface]) => ({ condition, value: pseudoColor(treatment, surface, profile, reject) }));
319
- out.rule(`${path}${suffix}`, { color: base, opacity: "1" });
320
- for (const { condition, value } of states)
321
- out.rule(`${under(condition, path)}${suffix}`, { color: value });
322
- const colors = [{ condition: null, value: base }, ...states];
339
+ const { out, profile, reject, foundation } = context, background = (surface) => surface === null ? null : profile.of(surface, "surface").background ?? null, fills = [{ condition: null, value: background(part.surface) }, ...part.when.map(([condition, surface]) => ({ condition, value: background(surface) }))];
340
+ for (const treatment of part.pseudo)
323
341
  switch (treatment.pseudo) {
324
342
  case "placeholder": {
325
- const background = (surface) => surface === null ? null : profile.of(surface, "surface").background ?? null, fills = [{ condition: null, value: background(part.surface) }, ...part.when.map(([condition, surface]) => ({ condition, value: background(surface) }))], checked = checkPlaceholderContrast(foundation, part.name, colors, fills);
343
+ const suffix = "::placeholder", base = pseudoColor(treatment, treatment.surface, profile, reject), states = treatment.when.map(([condition, surface]) => ({ condition, value: pseudoColor(treatment, surface, profile, reject) }));
344
+ out.rule(`${path}${suffix}`, { color: base, opacity: "1" });
345
+ for (const { condition, value } of states)
346
+ out.rule(`${under(condition, path)}${suffix}`, { color: value });
347
+ const checked = checkPlaceholderContrast(foundation, part.name, [{ condition: null, value: base }, ...states], fills);
348
+ if (checked.kind === "err")
349
+ return reject(checked.error);
350
+ break;
351
+ }
352
+ case "progressValue": {
353
+ const base = pseudoFill(treatment, treatment.surface, profile, reject), states = treatment.when.map(([condition, surface]) => ({ condition, value: pseudoFill(treatment, surface, profile, reject) }));
354
+ out.rule(path, { appearance: "none", "-webkit-appearance": "none", ...part.box === null ? { "border-style": "none" } : {} });
355
+ out.rule(`${path}::-webkit-progress-bar`, { background: "transparent" });
356
+ for (const suffix of PROGRESS_FILLS) {
357
+ out.rule(`${path}${suffix}`, { background: base, "border-radius": "inherit" });
358
+ for (const { condition, value } of states)
359
+ out.rule(`${under(condition, path)}${suffix}`, { background: value });
360
+ }
361
+ const checked = checkProgressContrast(foundation, part.name, [{ condition: null, value: base }, ...states], fills);
326
362
  if (checked.kind === "err")
327
363
  return reject(checked.error);
328
364
  break;
329
365
  }
330
366
  }
331
- }
367
+ }
368
+ const PROGRESS_FILLS = ["::-webkit-progress-value", "::-moz-progress-bar"];
369
+ function pseudoFill(treatment, surface, profile, reject) {
370
+ const fields = profile.of(surface, "surface"), other = Object.keys(fields).find((field) => field !== "background");
371
+ if (other !== void 0)
372
+ return reject({ kind: "pseudo-surface-unsupported", pseudo: treatment.pseudo, surface, field: other });
373
+ return fields.background ?? reject({ kind: "pseudo-surface-unsupported", pseudo: treatment.pseudo, surface, field: null });
332
374
  }
333
375
  const covers = (visual) => visual.fit === "cover", COVER_FILL = { display: "block", "inline-size": "100%", "block-size": "100%", "min-block-size": "0", "object-fit": "cover" };
334
376
  function normalizeElement(spec, name, path, values, provided, context) {
@@ -367,29 +409,111 @@ function lowerVector(part, stroke, path, context) {
367
409
  out.rule(under(condition, path), { ...checked(vectorStateValues(part.name, surface, profile.of(surface, "surface")), reject) });
368
410
  writeConditioned(part, path, {}, context);
369
411
  }
370
- function lowerParts(parts, parent, layout, gap, context) {
371
- const lowered = parts.map((part) => lowerPart(part, parent, layout, context));
412
+ function lowerParts(parts, parent, layout, gap, context, parentGrows = !1, overlapping = null, stateGaps = []) {
413
+ for (const part of parts) {
414
+ const source = part.focusOf === null ? void 0 : parts.find((other) => other.name === part.focusOf);
415
+ if (source === void 0)
416
+ continue;
417
+ const focus = context.profile.of(context.slots["focus-profile"], "focus", part.name);
418
+ context.out.rule(`${parent}:has(> ${source.selector}:focus-visible) > ${part.selector}`, {
419
+ "outline-width": context.profile.field(focus, "focus", "width"),
420
+ "outline-color": context.profile.field(focus, "focus", "color"),
421
+ "outline-offset": context.profile.field(focus, "focus", "offset"),
422
+ "outline-style": "solid"
423
+ });
424
+ }
425
+ for (const part of parts) {
426
+ const drawing = part.drawnBy === null ? void 0 : parts.find((other) => other.name === part.drawnBy);
427
+ if (drawing === void 0)
428
+ continue;
429
+ const size = drawing.box === null ? {} : frameValues(context.profile.of(drawing.box, "frame"), context.profile, context.reject), inline = size["inline-size"], block = size["block-size"];
430
+ if (inline === void 0 || block === void 0)
431
+ return context.reject({ kind: "profile-field-missing", profile: drawing.box ?? drawing.name, field: inline === void 0 ? "inlineSize" : "blockSize" });
432
+ context.out.rule(`${parent} > ${part.selector}`, { position: "absolute", "inline-size": inline, "block-size": block, "margin-block": "0", "margin-inline": "0", opacity: "0", "z-index": "1" });
433
+ }
434
+ writePartSpace(parts, parent, layout, gap, context);
435
+ const lowered = parts.map((part) => lowerPart(part, parent, layout, context, parentGrows, overlapping));
372
436
  if (layout !== "inline" && layout !== "stack")
373
437
  return;
374
438
  const axes = layout === "inline" ? ["inline"] : ["block"];
375
- lowered.forEach((first, index) => {
376
- const second = lowered[index + 1];
377
- if (first === null || second === null || second === void 0)
378
- return;
439
+ lowered.flatMap((first, index) => {
440
+ const own = first !== null && parts[index]?.repeat === !0 ? [[first, first]] : [], second = lowered[index + 1];
441
+ return first === null || second === null || second === void 0 ? own : [...own, [first, second]];
442
+ }).forEach(([first, second]) => {
443
+ if (overlapping !== null)
444
+ return context.reject({ kind: "state-geometry-unsupported", element: parent === "&" ? "&" : parent, reason: "targets-overlap", detail: `${first.element} and ${second.element}` });
379
445
  for (const axis of axes)
380
- context.neighbours.push({ axis, gap: gap ?? "0px", first, second });
446
+ for (const between of [gap ?? "0px", ...stateGaps])
447
+ context.neighbours.push({ axis, gap: between, first, second });
381
448
  });
382
449
  }
383
- function lowerPart(part, parent, parentLayout, context) {
450
+ function writePartSpace(parts, parent, layout, gap, context) {
451
+ const spaced = parts.filter((part) => part.spaceBefore !== null || part.spaceAfter !== null);
452
+ if (spaced.length === 0)
453
+ return;
454
+ const [first] = spaced;
455
+ if (layout !== "stack" && layout !== "native" && first !== void 0)
456
+ return context.reject({ kind: "space-parent-unsupported", part: first.name, layout });
457
+ const { out, profile, slots } = context, spacing = (binding) => profile.field(profile.of(slots["spacing-profile"], "spacing", "space"), "spacing", kebab(binding.field)), between = gap ?? "0px", margin = (space) => ({ "margin-block-start": `calc(${space} - ${between})` });
458
+ for (const part of spaced) {
459
+ if (part.spaceBefore !== null)
460
+ out.rule(`${parent} > * + ${part.selector}`, margin(spacing(part.spaceBefore)));
461
+ if (part.spaceAfter !== null)
462
+ out.rule(`${parent} > ${part.selector} + :not(:first-child)`, margin(spacing(part.spaceAfter)));
463
+ }
464
+ for (const before of spaced)
465
+ for (const after of spaced)
466
+ if (before.spaceAfter !== null && after.spaceBefore !== null)
467
+ out.rule(`${parent} > ${before.selector} + ${after.selector}:not(:first-child)`, margin(`max(${spacing(before.spaceAfter)}, ${spacing(after.spaceBefore)})`));
468
+ }
469
+ function lowerPart(part, parent, parentLayout, context, parentGrows, overlapping = null) {
384
470
  const { out, profile, slots, reject } = context, path = `${parent} > ${part.selector}`;
385
471
  if (part.content.kind === "vector") {
386
472
  lowerVector(part, part.content.stroke, path, context);
387
473
  return null;
388
474
  }
389
- const partSurface = part.surface === null ? {} : profile.of(part.surface, "surface"), moving = partMotion(path, part.effects, context), partGroups = [...moving === null ? [] : [moving], ...measuredMotion(part.measured, profile, reject)], moved = part.effects === null ? [] : [...new Set(part.effects.when.flatMap(([, names]) => names.map((name) => PART_EFFECTS[name].channel)))], entering = writeEnter(out, profile, path, part.enter, partSurface, stateSurfaces(path, part.when, profile), slots, [...transitioned(part.paintTransition, partGroups), ...moved], reject);
475
+ if (part.content.kind === "component") {
476
+ writeConditioned(part, path, checked(extentValues(part.extent, parentLayout, part.name, parentGrows), reject), context);
477
+ return null;
478
+ }
479
+ const partSurface = part.surface === null ? {} : profile.of(part.surface, "surface"), moving = partMotion(path, part.effects, context), collapsible = part.collapsed || part.geometryWhen.some((state) => state.collapsed !== null), axis = parentLayout === "inline" ? "inline" : parentLayout === "stack" ? "block" : null;
480
+ if (collapsible) {
481
+ if (axis === null)
482
+ return reject({ kind: "state-geometry-unsupported", element: part.name, reason: "collapsed-parent", detail: parentLayout });
483
+ const own = part.box !== null || part.frame !== null ? "a frame" : part.arrangement !== null ? "an arrangement" : part.overflow.kind !== "visible" ? "an overflow" : part.extent.kind === "fill" ? "a filling extent" : null;
484
+ if (own !== null)
485
+ return reject({ kind: "state-geometry-unsupported", element: part.name, reason: "collapsed-box", detail: own });
486
+ }
487
+ const restBox = part.box === null ? null : frameValues(profile.of(part.box, "frame"), profile, reject), partGeometry = writeStateGeometry(path, part.name, {
488
+ frame: restBox,
489
+ arrangement: part.arrangement,
490
+ arranged: part.arrangement === null ? {} : arrangementValues(part.arrangement, slots, profile, part.overflow),
491
+ collapsed: collapsible ? part.collapsed : null,
492
+ axis
493
+ }, part.geometryWhen, part.geometryTransition, (name) => frameValues(profile.of(name, "frame"), profile, reject), context);
494
+ if (partGeometry.overlap !== null)
495
+ out.rule(`${path} ${OVERLAPPED}`, { [partGeometry.overlap.property]: partGeometry.overlap.base });
496
+ if (collapsible && overlapping !== null) {
497
+ const own = `${path}:not(:first-child)`;
498
+ if (part.collapsed)
499
+ out.rule(own, { [overlapping.property]: "0px" });
500
+ for (const state of part.geometryWhen) {
501
+ if (state.collapsed === null)
502
+ continue;
503
+ out.rule(under(state.condition, own), { [overlapping.property]: state.collapsed ? "0px" : overlapping.states.get(state.condition) ?? overlapping.base });
504
+ }
505
+ }
506
+ const partGroups = [
507
+ ...moving === null ? [] : [moving],
508
+ ...measuredMotion(part.measured, profile, reject),
509
+ ...partGeometry.group === null ? [] : [partGeometry.group],
510
+ ...overlapping === null || overlapping.group === null || partGeometry.group?.properties.includes(overlapping.property) === !0 ? [] : [overlapping.group]
511
+ ], moved = part.effects === null ? [] : [...new Set(part.effects.when.flatMap(([, names]) => names.map((name) => PART_EFFECTS[name].channel)))], entering = writeEnter(out, profile, path, part.enter, partSurface, stateSurfaces(path, part.when, profile), slots, [...transitioned(part.paintTransition, partGroups), ...moved], reject);
390
512
  transitionRules(path, part.paintTransition, part.surface === null ? null : { name: part.surface, fields: partSurface }, part.when, context, entering === null ? partGroups : [...partGroups, entering.group]);
391
513
  writePlays(out, profile, context.foundation, part.name, part.plays, path, [...transitioned(part.paintTransition, entering === null ? [] : [entering.group]), ...moved], reject);
392
514
  const values = part.arrangement === null ? {} : { "box-sizing": "border-box", "min-inline-size": "0", ...arrangementValues(part.arrangement, slots, profile, part.overflow) };
515
+ if (collapsible && axis !== null)
516
+ Object.assign(values, collapsibleValues(axis), collapsedValues(part.collapsed, axis));
393
517
  if (part.arrangement?.layout === "layered")
394
518
  checked(checkLayers(part.name, part.parts.length), reject);
395
519
  const text = part.text !== null ? textOf(part.text, slots, profile) : part.content.kind === "text" && slots["text-profile"] !== void 0 ? profile.of(slots["text-profile"], "text") : {};
@@ -400,9 +524,10 @@ function lowerPart(part, parent, parentLayout, context) {
400
524
  checkSurfaceEffects(context.foundation, profile, [part.surface, ...part.when.map(([, name]) => name)], part.content.kind === "visual" ? "visual" : part.overflow.kind === "scroll" ? "scroller" : "container", reject);
401
525
  if (part.surface !== null)
402
526
  Object.assign(values, settled(partSurface, entering?.blurred ?? !1));
403
- Object.assign(values, stickyValues(part.sticky, context));
527
+ Object.assign(values, stickyValues(part.sticky, context), anchorClearValues(part.anchorClear, context));
528
+ const boxFields = part.box === null ? {} : frameValues(profile.of(part.box, "frame"), profile, reject);
404
529
  if (part.box !== null)
405
- Object.assign(values, { "box-sizing": "border-box" }, frameValues(profile.of(part.box, "frame"), profile, reject));
530
+ Object.assign(values, { "box-sizing": "border-box" }, boxFields);
406
531
  let target = null, frameFields = {};
407
532
  if (part.frame !== null) {
408
533
  const lineHeight = profile.field(text, "text", "line-height"), frame = profile.of(slots["frame-profile"], "frame", "control"), box = controlBox(frame, LINE_BOX, profile.field, reject);
@@ -441,38 +566,40 @@ function lowerPart(part, parent, parentLayout, context) {
441
566
  const partSnap = part.arrangement?.snap ?? null, snapped = partSnap === null ? null : checked(snapValues(partSnap, part.overflow, part.name), reject);
442
567
  if (snapped !== null)
443
568
  add(snapped.container, "snap");
444
- add(checked(extentValues(part.extent, parentLayout, part.name), reject), "extent");
569
+ add(checked(extentValues(part.extent, parentLayout, part.name, parentGrows), reject), "extent");
445
570
  if (parentLayout === "layered")
446
571
  add(LAYER, "layer");
447
572
  if (part.outset !== null) {
448
573
  if (parentLayout !== "layered" || part.parts.length > 0 || part.content.kind === "text")
449
574
  return reject({ kind: "outset-unsupported", part: part.name });
450
- const spacing = (binding) => binding === null ? null : profile.field(profile.of(slots["spacing-profile"], "spacing", "outset"), "spacing", kebab(binding.field)), [block, inline] = [spacing(part.outset.block), spacing(part.outset.inline)];
451
- add({ ...block === null ? {} : { "margin-block": `calc(-1 * ${block})` }, ...inline === null ? {} : { "margin-inline": `calc(-1 * ${inline})` } }, "outset");
575
+ const spacing = (binding) => binding === null ? null : profile.field(profile.of(slots["spacing-profile"], "spacing", "outset"), "spacing", kebab(binding.field)), [block, inline] = [spacing(part.outset.block), spacing(part.outset.inline)], share = (value) => context.foundation.tokens.get(/^var\(\s*(--[\w-]+)\s*\)$/.exec(value)?.[1] ?? "")?.role === "box-share", outset = (axis, value) => value === null ? {} : axis === "block" && share(value) ? { "block-size": `calc(100% + 2 * ${value})`, "align-self": "center" } : { [`margin-${axis}`]: `calc(-1 * ${value})` };
576
+ add({ ...outset("block", block), ...outset("inline", inline) }, "outset");
452
577
  }
453
578
  normalizeElement(part, part.name, path, values, provided, context);
454
579
  const twice = part.normalize.find(([property]) => context.rootNormalized.get(path)?.includes(property));
455
580
  if (twice !== void 0)
456
581
  return reject({ kind: "extent-conflict", element: part.name, property: twice[0], providers: ["recipe.normalize.when", "normalize"] });
457
582
  add(normalizedDeclarations(part.normalize), "normalize");
458
- const media = part.measured.some((value) => value.type === "position" || value.type === "intrinsic-size") && part.content.kind === "visual" && context.input.visual?.kind === "content-media" ? covers(profile.of(slots["visual-profile"], "visual", "visual")) ? "cover" : "contain" : null;
583
+ const media = part.measured.some((value) => value.type === "position" || value.type === "intrinsic-size") && part.content.kind === "visual" && visualOf(context.input, part.name)?.kind === "content-media" ? covers(profile.of(slots["visual-profile"], "visual", "visual")) ? "cover" : "contain" : null;
459
584
  Object.assign(values, checked(measuredWrites(context.input.scope, part.measured, part.name, values, part.frame !== null ? supplied(slots, frameFields) : null, media), reject));
460
585
  Object.assign(values, paintValues(part.name, part.paints, "box", [part.surface], part.when, context));
461
586
  writeConditioned(part, path, values, context);
462
587
  const conditioned = conditionedVisual(part, context);
463
- if (part.scheme !== null && context.input.visual?.kind !== "content-media")
588
+ if (part.scheme !== null && visualOf(context.input, part.name)?.kind !== "content-media")
464
589
  return reject({ kind: "scheme-unsupported", part: part.name });
465
- if (part.content.kind === "visual")
466
- lowerVisual(path, context, part.measured.find((value) => value.type === "intrinsic-size") ?? null, conditioned, part.scheme);
590
+ const unrendered = part.content.kind === "visual" && !part.required && visualOf(context.input, part.name) === null;
591
+ if (part.content.kind === "visual" && !unrendered)
592
+ lowerVisual(path, context, part.measured.find((value) => value.type === "intrinsic-size") ?? null, conditioned, part.scheme, boxFields, part.name);
467
593
  if (snapped !== null)
468
594
  out.rule(`${path} > *`, { ...snapped.children });
469
595
  stateRules(out, path, part.when, profile, entering?.blurred ?? !1);
470
596
  for (const [condition, normalized] of part.normalizeWhen)
471
597
  out.rule(under(condition, path), normalizedDeclarations(normalized));
472
598
  pseudoRules(part, path, context);
473
- lowerParts(part.parts, path, part.arrangement?.layout ?? "native", values.gap, context);
599
+ lowerParts(part.parts, path, part.arrangement?.layout ?? "native", values.gap, context, growsWithContent(values), partGeometry.overlap, partGeometry.gaps);
474
600
  return target;
475
601
  }
602
+ const visualOf = (input, part) => input.visuals?.get(part) ?? input.visual;
476
603
  function conditionedVisual(part, context) {
477
604
  const { profile, slots, foundation, reject } = context, [condition] = part.at;
478
605
  if (condition === void 0 || condition.visual === null)
@@ -484,8 +611,8 @@ function conditionedVisual(part, context) {
484
611
  return reject({ kind: "condition-unknown", part: part.name, condition: condition.condition, spatial: spatial ?? null });
485
612
  return { part: part.name, condition: condition.condition, profile: condition.visual, query: ["media", conditionQueries(bound).inside] };
486
613
  }
487
- function lowerVisual(path, context, intrinsic, conditioned = null, scheme = null) {
488
- const { out, profile, slots, input, reject } = context, { visual } = input;
614
+ function lowerVisual(path, context, intrinsic, conditioned = null, scheme = null, box = {}, partName = null) {
615
+ const { out, profile, slots, input, reject } = context, inBox = (part) => Object.fromEntries(Object.entries(part).filter(([property]) => !((property === "inline-size" || property === "block-size") && box[property] !== void 0))), visual = partName === null ? input.visual : visualOf(input, partName);
489
616
  if (visual === null)
490
617
  return reject({ kind: "artwork-binding-missing" });
491
618
  if (scheme !== null)
@@ -531,21 +658,25 @@ function lowerVisual(path, context, intrinsic, conditioned = null, scheme = null
531
658
  out.rule(path, { display: "block", "inline-size": "100%", "block-size": "100%", "min-block-size": "0" });
532
659
  out.rule(`${path} > ${artwork.element}`, { ...COVER_FILL, "object-position": focalPosition(artwork.drawing.center) });
533
660
  context.placedArtwork.push(artwork);
661
+ if (partName !== null)
662
+ context.placedByPart.set(partName, artwork);
534
663
  return;
535
664
  }
536
665
  const geometry = visualPart(visual.asset, visualProfile, visual.state, visual.theme, reject);
537
- out.rule(path, geometry.part);
666
+ out.rule(path, inBox(geometry.part));
538
667
  out.rule(`${path} > ${geometry.element}`, geometry.media);
539
668
  if (conditioned !== null && inCondition !== null) {
540
669
  const other = visualPart(visual.asset, inCondition, visual.state, visual.theme, reject);
541
670
  if (other.source !== geometry.source || other.element !== geometry.element)
542
671
  return unsupported("drawing-differs");
543
- out.rule(path, other.part, conditioned.query);
672
+ out.rule(path, inBox(other.part), conditioned.query);
544
673
  out.rule(`${path} > ${other.element}`, other.media, conditioned.query);
545
674
  }
546
675
  if (visual.asset.paint === "slots")
547
676
  out.paint(path.replace(/^& > /, ""), [...visual.asset.slots].map(([slot, value]) => ({ slot, paint: value === "currentColor" ? { kind: "current-color" } : { kind: "token", name: value } })));
548
677
  context.placedArtwork.push(placed(geometry));
678
+ if (partName !== null)
679
+ context.placedByPart.set(partName, placed(geometry));
549
680
  }
550
681
  function layerInput(layer, spec, root, slots, profile, foundation, reject) {
551
682
  if ((slots["surface-profile"] ?? spec.surface) === null)
@@ -618,9 +749,25 @@ export function lowerRegion(spec, foundation, input) {
618
749
  out.own(paintProperty(input.scope, paint.name));
619
750
  for (const token of paintTokens(paints))
620
751
  out.use(`var(${token})`);
621
- const placedArtwork = [], targets = [], neighbours = [], rootNormalized = new Map(spec.normalizeWhen.map(([selector, normalized]) => [selector, normalized.map(([property]) => property)])), coverBox = spec.frame !== null && (spec.frame.kind === "fields" && spec.frame.ratio !== null || slots["frame-profile"] !== void 0 && profile.of(slots["frame-profile"], "frame")["block-size"] !== void 0), context = { out, profile, slots, input, reject, placedArtwork, foundation, targets, neighbours, rootNormalized, coverBox }, surface = slots["surface-profile"] ?? spec.surface;
752
+ const placedArtwork = [], placedByPart = new Map, targets = [], neighbours = [], rootNormalized = new Map(spec.normalizeWhen.map(([selector, normalized]) => [selector, normalized.map(([property]) => property)])), coverBox = spec.frame !== null && (spec.frame.kind === "fields" && spec.frame.ratio !== null || slots["frame-profile"] !== void 0 && profile.of(slots["frame-profile"], "frame")["block-size"] !== void 0), context = { out, profile, slots, input, reject, placedArtwork, placedByPart, foundation, targets, neighbours, rootNormalized, coverBox }, surface = slots["surface-profile"] ?? spec.surface;
622
753
  checkSurfaceEffects(foundation, profile, [slots["surface-profile"], spec.surface, ...spec.when.map(([, name]) => name)], spec.overflow.kind === "scroll" ? "scroller" : "container", reject);
623
- const press = spec.press.when.length === 0 ? null : writeRootPress(out, spec.press, profile.of(slots["motion-profile"], "motion", spec.profile ?? "recipe"), profile, reject), rootSurface = surface === null ? {} : profile.of(surface, "surface"), rootGroups = [...press === null ? [] : [press], ...measuredMotion(spec.measured, profile, reject)], entering = writeEnter(out, profile, "&", spec.enter, rootSurface, stateSurfaces("&", spec.when, profile), slots, transitioned(spec.paintTransition, rootGroups), reject);
754
+ const press = spec.press.when.length === 0 ? null : writeRootPress(out, spec.press, profile.of(slots["motion-profile"], "motion", spec.profile ?? "recipe"), profile, reject), rootSurface = surface === null ? {} : profile.of(surface, "surface"), restFramed = spec.frame === null || spec.frameAt === null || spec.frameAt.corners === null ? spec.frame : { ...spec.frame, corners: spec.frame.corners ?? FRAME_CORNERS }, rootGeometry = writeStateGeometry("&", "&", {
755
+ frame: restFramed === null ? null : regionFrameValues(restFramed, slots, surface, profile, reject).values,
756
+ arrangement: spec.arrangement,
757
+ arranged: spec.arrangement.layout === "native" ? {} : arrangementValues(spec.arrangement, slots, profile, spec.overflow),
758
+ collapsed: null,
759
+ axis: null
760
+ }, spec.geometryWhen, spec.geometryTransition, (name) => {
761
+ if (restFramed === null)
762
+ return {};
763
+ const stated = regionFrameValues(restFramed, { ...slots, "frame-profile": name }, surface, profile, reject);
764
+ if (JSON.stringify(stated.hitArea) !== JSON.stringify(regionFrameValues(restFramed, slots, surface, profile, reject).hitArea))
765
+ return reject({ kind: "state-geometry-unsupported", element: "&", reason: "hit-area", detail: name });
766
+ return stated.values;
767
+ }, { out, profile, slots, reject });
768
+ if (rootGeometry.overlap !== null)
769
+ out.rule(`& ${OVERLAPPED}`, { [rootGeometry.overlap.property]: rootGeometry.overlap.base });
770
+ const rootGroups = [...press === null ? [] : [press], ...measuredMotion(spec.measured, profile, reject), ...rootGeometry.group === null ? [] : [rootGeometry.group]], entering = writeEnter(out, profile, "&", spec.enter, rootSurface, stateSurfaces("&", spec.when, profile), slots, transitioned(spec.paintTransition, rootGroups), reject);
624
771
  transitionRules("&", spec.paintTransition, surface === null ? null : { name: surface, fields: rootSurface }, spec.when, context, entering === null ? rootGroups : [...rootGroups, entering.group]);
625
772
  writePlays(out, profile, foundation, "&", spec.plays, "&", transitioned(spec.paintTransition, entering === null ? rootGroups : [...rootGroups, entering.group]), reject);
626
773
  const { arrangement } = spec, values = arrangement.layout !== "native" || spec.frame !== null ? { "box-sizing": "border-box", "min-inline-size": "0" } : {};
@@ -700,7 +847,7 @@ export function lowerRegion(spec, foundation, input) {
700
847
  if (Object.keys(measured).length > 0)
701
848
  out.rule(openState(layer.kind), measured);
702
849
  } else {
703
- Object.assign(values, stickyValues(spec.sticky, context), checked(measuredWrites(input.scope, spec.measured, "&", values, frameSupplied), reject), rootPaints);
850
+ Object.assign(values, stickyValues(spec.sticky, context), anchorClearValues(spec.anchorClear, context), checked(measuredWrites(input.scope, spec.measured, "&", values, frameSupplied), reject), rootPaints);
704
851
  if (Object.keys(values).length > 0)
705
852
  out.rule("&", { ...settled(values, entering?.blurred ?? !1) });
706
853
  if (spec.normalize.length > 0)
@@ -712,12 +859,8 @@ export function lowerRegion(spec, foundation, input) {
712
859
  for (const [selector, normalized] of spec.normalizeWhen)
713
860
  out.rule(selector, normalizedDeclarations(normalized));
714
861
  stateRules(out, "&", spec.when, profile, entering?.blurred ?? !1);
715
- if (spec.prose !== null)
716
- lowerProse(spec.prose, rootSurface, context);
717
862
  const partLayout = spec.exposeRows.length > 0 ? "grid" : arrangement.layout;
718
- lowerParts(spec.parts, "&", partLayout, values.gap, context);
719
- if (placedArtwork.length > 1)
720
- return reject({ kind: "parts-visual-repeated" });
721
- return out.finish({ kind: "region", artwork: placedArtwork[0] ?? null, exposed, targets: { elements: targets, neighbours } }, input.hidden);
863
+ lowerParts(spec.parts, "&", partLayout, values.gap, context, growsWithContent(values), rootGeometry.overlap, rootGeometry.gaps);
864
+ return out.finish({ kind: "region", artwork: placedArtwork[0] ?? null, artworks: placedByPart, exposed, targets: { elements: targets, neighbours } }, input.hidden);
722
865
  });
723
866
  }
@@ -34,3 +34,27 @@ export async function layoutShift({ nodeLimit }) {
34
34
  }
35
35
  return { value: Math.round(best.value * 1e4) / 1e4, nodes: [...best.nodes].slice(0, nodeLimit) };
36
36
  }
37
+ export async function stateShift({ nodeLimit, quietMs }) {
38
+ if (!PerformanceObserver.supportedEntryTypes?.includes("layout-shift"))
39
+ return null;
40
+ let value = 0;
41
+ const nodes = [], observer = new PerformanceObserver((list) => {
42
+ for (const entry of list.getEntries()) {
43
+ if (entry.hadRecentInput)
44
+ continue;
45
+ value += entry.value;
46
+ for (const source of entry.sources ?? []) {
47
+ const node = source.node;
48
+ if (node instanceof Element && nodes.length < nodeLimit)
49
+ nodes.push(`${node.localName}${node.id ? `#${node.id}` : ""}${node.classList.length ? `.${[...node.classList].slice(0, 2).join(".")}` : ""}`);
50
+ }
51
+ }
52
+ });
53
+ observer.observe({ type: "layout-shift" });
54
+ await new Promise((resolve) => setTimeout(resolve, quietMs));
55
+ for (const entry of observer.takeRecords())
56
+ if (!entry.hadRecentInput)
57
+ value += entry.value;
58
+ observer.disconnect();
59
+ return { value, nodes };
60
+ }