@yahoo/uds-create-config 5.88.1 → 5.89.1

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.
@@ -0,0 +1,374 @@
1
+ import { isRef, pathOf, refLeaf } from "../../framework/utils/refs.js";
2
+ import { rootLayerOf } from "./element.js";
3
+ import { createSliceMemo } from "../../framework/memo.js";
4
+ import { UDS_FORCE_STATES } from "../../framework/component-states.js";
5
+ import { authoredBag, defaultSources, propOwner } from "../../framework/projections.js";
6
+ import { propApplies, surfaceProps } from "../../framework/prop-surface.js";
7
+ import { layerDeclarationStacks } from "../../framework/layer-styles.js";
8
+ import { Component } from "./Component.js";
9
+ import { markerKind } from "../../framework/bindings.js";
10
+ //#region src/entities/system/resolve-properties.ts
11
+ /**
12
+ * The property engine: for a selected element, one row per property, saying which state it is in,
13
+ * the value that paints, where that value comes from, and whether the config lets you write it.
14
+ *
15
+ * The states are Donna's (Properties Panel Refactor): Set, Inherited, Default, Read-only and Not
16
+ * declared. A value is the first source that sets the key, in the order the stylesheet ranks them:
17
+ * the element; a rule value of more than one class of specificity (a forced block inside a
18
+ * conditional rule); a composite the element names, whose class the sheet emits after every rule;
19
+ * the remaining rule values by specificity and rule order, which puts a rule a prop drives over the
20
+ * unconditional rule; then the default layers (`defaultSources`). The element's force-state pins
21
+ * are read the way the render reads them.
22
+ *
23
+ * OPEN: a root element only. Drilled layers, ancestors and multi-select are not read yet, so a value
24
+ * from a parent element reads as Default or unset, as the panel shows it today.
25
+ * OPEN: a root layer that is itself a component contributes none of that component's own defaults
26
+ * or rules.
27
+ * OPEN: a prop forwarded to another layer is read against the root layer's rules.
28
+ * OPEN: a composite a rule applies isn't expanded into the style properties it sets.
29
+ * OPEN: when two props write one style property, each row reads only the value stored under its
30
+ * own name.
31
+ * OPEN: an element's own modifier blocks (`_hover: { … }`) aren't read as sources under `forced`.
32
+ * OPEN: a value's token origin and a borrowed component's `system` aren't reported.
33
+ */
34
+ const componentModels = createSliceMemo({
35
+ kinds: [
36
+ "component",
37
+ "style-property",
38
+ "token",
39
+ "composite",
40
+ "modifier",
41
+ "icon",
42
+ "motion",
43
+ "source"
44
+ ],
45
+ compute: (_config) => /* @__PURE__ */ new Map()
46
+ });
47
+ function componentModel({ config, path, layers }) {
48
+ const models = componentModels(config);
49
+ const cached = models.get(path);
50
+ if (cached) return cached;
51
+ const surface = /* @__PURE__ */ new Map();
52
+ const propForStyleKey = /* @__PURE__ */ new Map();
53
+ for (const prop of surfaceProps(config, path)) {
54
+ surface.set(prop.name, prop);
55
+ if (prop.kind === "styleProperty" && !propForStyleKey.has(prop.styleProperty)) propForStyleKey.set(prop.styleProperty, prop.name);
56
+ }
57
+ const [root] = rootLayerOf(layers);
58
+ const model = {
59
+ root,
60
+ surface,
61
+ propForStyleKey
62
+ };
63
+ models.set(path, model);
64
+ return model;
65
+ }
66
+ /** A composite prop's class has one class of specificity, and the sheet emits it after every rule
67
+ * (`compositePropRuleClasses`), so it beats every rule value of that specificity or less. */
68
+ const COMPOSITE_SPECIFICITY = 1;
69
+ /**
70
+ * A row for every property on a root element: every prop the component declares whose condition
71
+ * holds, every key the element stores, every key the component's rules and defaults set on its root
72
+ * layer, and every key in `include`.
73
+ */
74
+ function resolveProperties({ config, target, forced = [], previews = false, include = [] }) {
75
+ const stored = target.props;
76
+ const component = Component.get(config, target.type);
77
+ if (!component) return orderedKeys([storedKeys(stored), include]).map((key) => notDeclared({
78
+ key,
79
+ stored
80
+ }));
81
+ const path = component.path;
82
+ const model = componentModel({
83
+ config,
84
+ path,
85
+ layers: component.layers ?? {}
86
+ });
87
+ const pins = pinnedStates(stored);
88
+ const defaults = defaultSources(config, path, { ...stored }, {
89
+ firstVariants: previews,
90
+ preview: previews
91
+ });
92
+ const values = {
93
+ ...topValues(defaults),
94
+ ...stored,
95
+ ...pins.states
96
+ };
97
+ const rules = ownEntry(layerDeclarationStacks(config, path, values, { forced: [...forced, ...pins.forced] }), model.root) ?? {};
98
+ const composites = compositeValues({
99
+ config,
100
+ model,
101
+ values
102
+ });
103
+ const rowKeyOf = (styleKey) => model.propForStyleKey.get(styleKey) ?? styleKey;
104
+ return orderedKeys([
105
+ [...model.surface.values()].filter((prop) => propApplies(prop, values)).map((prop) => prop.name),
106
+ storedKeys(stored),
107
+ Object.keys(rules).filter(isPropertyKey).map(rowKeyOf),
108
+ Object.keys(defaults).filter(isPropertyKey),
109
+ [...composites.keys()],
110
+ include
111
+ ]).map((key) => {
112
+ const prop = model.surface.get(key);
113
+ const surfaced = !!prop && propApplies(prop, values);
114
+ const styleProperty = prop?.kind === "styleProperty" ? prop.styleProperty : void 0;
115
+ const styleKey = styleProperty ?? key;
116
+ const ruleStack = ownEntry(rules, styleKey) ?? [];
117
+ const fromRules = (declaration) => ruleValue({
118
+ declaration,
119
+ layer: model.root
120
+ });
121
+ const sources = [
122
+ ...Object.hasOwn(stored, key) && stored[key] !== void 0 ? [{
123
+ value: propertyValue(stored[key]),
124
+ source: ELEMENT
125
+ }] : [],
126
+ ...ruleStack.filter(({ specificity }) => specificity > COMPOSITE_SPECIFICITY).map(fromRules),
127
+ ...composites.get(key) ?? [],
128
+ ...ruleStack.filter(({ specificity }) => specificity <= COMPOSITE_SPECIFICITY).map(fromRules),
129
+ ...(ownEntry(defaults, key) ?? []).map((value) => defaultValue({
130
+ config,
131
+ styleKey,
132
+ value
133
+ }))
134
+ ];
135
+ if (!(surfaced || sources.some(({ source }) => source.kind !== "element"))) return notDeclared({
136
+ key,
137
+ stored,
138
+ path,
139
+ styleProperty
140
+ });
141
+ const [winner, ...beneath] = sources;
142
+ const editable = surfaced && winner?.value.kind !== "bound";
143
+ const owner = surfaced ? propOwner(config, path, key) : void 0;
144
+ return {
145
+ key,
146
+ ...styleProperty ? { styleProperty } : {},
147
+ state: stateOf({
148
+ winner,
149
+ surfaced
150
+ }),
151
+ value: winner?.value ?? UNSET,
152
+ source: winner?.source ?? null,
153
+ editable,
154
+ ...owner && owner !== path ? { declaredBy: owner } : {},
155
+ ...!surfaced && winner ? { configAddress: addressOf({
156
+ path,
157
+ key,
158
+ source: winner.source
159
+ }) } : {},
160
+ beneath
161
+ };
162
+ });
163
+ }
164
+ const UNSET = { kind: "unset" };
165
+ const ELEMENT = { kind: "element" };
166
+ function stateOf({ winner, surfaced }) {
167
+ if (!surfaced) return "read-only";
168
+ if (!winner) return "default";
169
+ if (winner.source.kind === "element") return "set";
170
+ if (isInherited(winner.source)) return "inherited";
171
+ return "default";
172
+ }
173
+ /** Whether a source supplies the value from outside the component's own defaults: a rule a prop
174
+ * drives, a forced modifier block, or a composite. */
175
+ function isInherited(source) {
176
+ if (source.kind === "rule") return source.drivenBy.length > 0;
177
+ return source.kind === "modifier" || source.kind === "composite";
178
+ }
179
+ function notDeclared({ key, stored, path, styleProperty }) {
180
+ const has = Object.hasOwn(stored, key) && stored[key] !== void 0;
181
+ return {
182
+ key,
183
+ ...styleProperty ? { styleProperty } : {},
184
+ state: "not-declared",
185
+ value: has ? propertyValue(stored[key]) : UNSET,
186
+ source: has ? ELEMENT : null,
187
+ editable: false,
188
+ ...path ? { configAddress: {
189
+ kind: "component",
190
+ path,
191
+ field: "props"
192
+ } } : {},
193
+ beneath: []
194
+ };
195
+ }
196
+ /** Whether a key names a property rather than a modifier block (`_hover`). */
197
+ function isPropertyKey(key) {
198
+ return !key.startsWith("_");
199
+ }
200
+ /** The keys an element stores that name properties: not its force-state pins or modifier blocks. */
201
+ function storedKeys(stored) {
202
+ return Object.keys(stored).filter((key) => key !== "__udsForceStates" && isPropertyKey(key) && stored[key] !== void 0);
203
+ }
204
+ /** What `record` holds of its own under `key`. A key named like an `Object` member (`toString`)
205
+ * would otherwise read the inherited one. */
206
+ function ownEntry(record, key) {
207
+ return Object.hasOwn(record, key) ? record[key] : void 0;
208
+ }
209
+ /**
210
+ * The states an element's force-state pins hold, read the way the render reads them: a `_` pin
211
+ * (`_hover`) forces that modifier's blocks and holds a rule keyed on it, and any other pin is a
212
+ * component state (`filled`, `validation: 'error'`) the rules test by name.
213
+ */
214
+ function pinnedStates(stored) {
215
+ const pins = stored[UDS_FORCE_STATES];
216
+ const states = {};
217
+ const forced = [];
218
+ if (!pins || typeof pins !== "object") return {
219
+ states,
220
+ forced
221
+ };
222
+ for (const [key, value] of Object.entries(pins)) {
223
+ if (isPropertyKey(key)) {
224
+ states[key] = value;
225
+ continue;
226
+ }
227
+ const held = value === true || value === "true";
228
+ states[key] = held;
229
+ if (held) forced.push(key);
230
+ }
231
+ return {
232
+ states,
233
+ forced
234
+ };
235
+ }
236
+ function orderedKeys(lists) {
237
+ return [...new Set(lists.flat())];
238
+ }
239
+ function topValues(defaults) {
240
+ const out = {};
241
+ for (const [prop, [top]] of Object.entries(defaults)) out[prop] = top?.value;
242
+ return out;
243
+ }
244
+ function propertyValue(value) {
245
+ if (value === "" || value === null) return { kind: "none" };
246
+ if (markerKind(value)) return {
247
+ kind: "bound",
248
+ binding: value
249
+ };
250
+ return {
251
+ kind: "value",
252
+ value
253
+ };
254
+ }
255
+ /** A default as the leaf an author writes. `defaultProps` stores token and value refs, which
256
+ * `authoredBag` reads back through the style property, as it does for a rule's bag. */
257
+ function defaultValue({ config, styleKey, value: { value, source } }) {
258
+ if (!isRef(value)) return {
259
+ value: propertyValue(value),
260
+ source
261
+ };
262
+ const authored = authoredBag(config, { [styleKey]: value })[styleKey];
263
+ return {
264
+ value: propertyValue(isRef(authored) ? refLeaf(authored) : authored),
265
+ source
266
+ };
267
+ }
268
+ function ruleValue({ declaration, layer }) {
269
+ const { value, rule, when, modifier } = declaration;
270
+ const interaction = Object.keys(when).find((prop) => prop.startsWith("_"));
271
+ const state = modifier ?? interaction?.slice(1);
272
+ if (state) return {
273
+ value: propertyValue(value),
274
+ source: {
275
+ kind: "modifier",
276
+ modifier: state,
277
+ rule,
278
+ layer
279
+ }
280
+ };
281
+ return {
282
+ value: propertyValue(value),
283
+ source: {
284
+ kind: "rule",
285
+ key: rule,
286
+ layer,
287
+ when,
288
+ drivenBy: Object.keys(when)
289
+ }
290
+ };
291
+ }
292
+ /** The composite variant a composite prop's value names: a stored ref names it whole, and a leaf
293
+ * names a member of the prop's composite. */
294
+ function compositeVariantPath({ compositeName, chosen }) {
295
+ if (isRef(chosen)) return pathOf(chosen);
296
+ if (typeof chosen !== "string" || chosen === "") return void 0;
297
+ return `${compositeName}/${chosen}`;
298
+ }
299
+ /** The values each composite prop's variant sets, per row key, in declaration order. */
300
+ function compositeValues({ config, model, values }) {
301
+ const out = /* @__PURE__ */ new Map();
302
+ for (const prop of model.surface.values()) {
303
+ if (prop.kind !== "composite" || !propApplies(prop, values)) continue;
304
+ const variant = compositeVariantPath({
305
+ compositeName: prop.compositeName,
306
+ chosen: values[prop.name]
307
+ });
308
+ if (!variant) continue;
309
+ const styles = (config.resolve("composite", variant)?.body)?.styles;
310
+ if (!styles) continue;
311
+ for (const [styleKey, value] of Object.entries(authoredBag(config, styles))) {
312
+ if (!isPropertyKey(styleKey)) continue;
313
+ const key = model.propForStyleKey.get(styleKey) ?? styleKey;
314
+ const list = out.get(key) ?? [];
315
+ list.push({
316
+ value: propertyValue(value),
317
+ source: {
318
+ kind: "composite",
319
+ prop: prop.name,
320
+ composite: prop.compositeName,
321
+ variant: variant.slice(prop.compositeName.length + 1)
322
+ }
323
+ });
324
+ out.set(key, list);
325
+ }
326
+ }
327
+ return out;
328
+ }
329
+ function addressOf({ path, key, source }) {
330
+ switch (source.kind) {
331
+ case "rule": return {
332
+ kind: "component",
333
+ path,
334
+ field: "styles",
335
+ key: source.key
336
+ };
337
+ case "modifier": return {
338
+ kind: "component",
339
+ path,
340
+ field: "styles",
341
+ key: source.rule
342
+ };
343
+ case "composite": return {
344
+ kind: "composite",
345
+ path: `${source.composite}/${source.variant}`
346
+ };
347
+ case "default-props": return {
348
+ kind: "component",
349
+ path,
350
+ field: "defaultProps",
351
+ key
352
+ };
353
+ case "default-props-when": return {
354
+ kind: "component",
355
+ path,
356
+ field: "defaultPropsWhen",
357
+ key: source.key
358
+ };
359
+ case "preview": return {
360
+ kind: "component",
361
+ path,
362
+ field: "preview",
363
+ key: source.key
364
+ };
365
+ default: return {
366
+ kind: "component",
367
+ path,
368
+ field: "props",
369
+ key
370
+ };
371
+ }
372
+ }
373
+ //#endregion
374
+ export { resolveProperties };
@@ -24,6 +24,15 @@ interface Shadow {
24
24
  /** Whether a value is a composed shadow — the test the renderers branch on. Every layer must be a ref
25
25
  * or a shadow's parts, so a record that merely holds a list under `shadow` is not one. */
26
26
  declare function isShadow(value: unknown): value is Shadow;
27
+ /**
28
+ * A CSS `box-shadow` string as its layers' parts: `0 1px 2px rgba(0, 0, 0, .1), inset 0 1px #fff`.
29
+ *
30
+ * Each layer is an optional `inset`, two to four lengths and one colour, with the colour before or
31
+ * after the lengths. The parts are kept as written, so a length keeps its unit and a colour stays
32
+ * the string it was, for the caller to check against what its platform accepts. Throws on anything
33
+ * else, including `none`, which has no layers.
34
+ */
35
+ declare function parseCssShadow(value: string): ShadowParts[];
27
36
  /**
28
37
  * `shadow(Token.ref('insetShadow/md-invert'), Token.ref('dropShadow/md'))`. The layers paint in the
29
38
  * order given, the first on top, as `box-shadow` paints them.
@@ -38,4 +47,4 @@ declare function shadow(...layers: readonly ShadowLayer[]): Shadow;
38
47
  */
39
48
  declare function renderShadow(value: Shadow, render: (part: unknown) => string): string;
40
49
  //#endregion
41
- export { Shadow, ShadowColor, ShadowLayer, ShadowParts, isShadow, renderShadow, shadow };
50
+ export { Shadow, ShadowColor, ShadowLayer, ShadowParts, isShadow, parseCssShadow, renderShadow, shadow };
@@ -38,6 +38,71 @@ function isShadow(value) {
38
38
  const layers = value.shadow;
39
39
  return Array.isArray(layers) && layers.length > 0 && layers.every((layer) => isRef(layer) || isParts(layer));
40
40
  }
41
+ const SHADOW_LENGTH = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:[a-z]+|%)?$/i;
42
+ /**
43
+ * A CSS `box-shadow` string as its layers' parts: `0 1px 2px rgba(0, 0, 0, .1), inset 0 1px #fff`.
44
+ *
45
+ * Each layer is an optional `inset`, two to four lengths and one colour, with the colour before or
46
+ * after the lengths. The parts are kept as written, so a length keeps its unit and a colour stays
47
+ * the string it was, for the caller to check against what its platform accepts. Throws on anything
48
+ * else, including `none`, which has no layers.
49
+ */
50
+ function parseCssShadow(value) {
51
+ return splitTopLevel({
52
+ value,
53
+ separator: ","
54
+ }).map((layer) => {
55
+ const lengths = [];
56
+ let color;
57
+ let inset = false;
58
+ for (const part of splitTopLevel({
59
+ value: layer,
60
+ separator: " "
61
+ })) {
62
+ if (part === "inset" && !inset) {
63
+ inset = true;
64
+ continue;
65
+ }
66
+ if (SHADOW_LENGTH.test(part)) {
67
+ lengths.push(part);
68
+ continue;
69
+ }
70
+ if (color !== void 0) throw new Error(`Unexpected shadow part "${part}"`);
71
+ color = part;
72
+ }
73
+ if (color === void 0 || lengths.length < 2 || lengths.length > 4) throw new Error("Shadow needs a color and two to four lengths");
74
+ const [offsetX, offsetY, blur, spread] = lengths;
75
+ return {
76
+ ...inset ? { inset } : {},
77
+ offsetX,
78
+ offsetY,
79
+ ...blur === void 0 ? {} : { blur },
80
+ ...spread === void 0 ? {} : { spread },
81
+ color
82
+ };
83
+ });
84
+ }
85
+ /** Split on a separator outside parentheses, so `rgba(0, 0, 0, .1)` stays one part. Whitespace
86
+ * counts as the space separator, and empty parts are dropped. */
87
+ function splitTopLevel({ value, separator }) {
88
+ const parts = [];
89
+ let depth = 0;
90
+ let start = 0;
91
+ for (let at = 0; at < value.length; at++) {
92
+ const char = value[at] ?? "";
93
+ if (char === "(") depth++;
94
+ if (char === ")") depth--;
95
+ if (depth < 0) throw new Error("Unbalanced shadow function");
96
+ const splits = separator === " " ? /\s/.test(char) : char === separator;
97
+ if (depth === 0 && splits) {
98
+ parts.push(value.slice(start, at).trim());
99
+ start = at + 1;
100
+ }
101
+ }
102
+ if (depth !== 0) throw new Error("Unbalanced shadow function");
103
+ parts.push(value.slice(start).trim());
104
+ return parts.filter(Boolean);
105
+ }
41
106
  /**
42
107
  * `shadow(Token.ref('insetShadow/md-invert'), Token.ref('dropShadow/md'))`. The layers paint in the
43
108
  * order given, the first on top, as `box-shadow` paints them.
@@ -74,4 +139,4 @@ function renderShadow(value, render) {
74
139
  }).join(", ");
75
140
  }
76
141
  //#endregion
77
- export { isShadow, renderShadow, shadow, shadowAuthoring, shadowValue };
142
+ export { isShadow, parseCssShadow, renderShadow, shadow, shadowAuthoring, shadowValue };
@@ -2470,6 +2470,16 @@ declare class Config {
2470
2470
  private sameEntityThrough;
2471
2471
  /** Whether `other`'s entity at `kind:path` reads as `body`, spelled the way this config spells it. */
2472
2472
  private sameEntityAs;
2473
+ /**
2474
+ * Whether `body` is what `slug`'s entity at `kind:path` becomes when it is inlined here
2475
+ * ({@link withInlinedSources}), which follows their aliases and spells the result in this config's
2476
+ * terms. A pin that survives the inlining still offers the path, and this is the same entity.
2477
+ */
2478
+ private inlinedFrom;
2479
+ /** Whether two bodies of `kind` are the same entity, leaving out the fields that say where a body
2480
+ * came from: the kind's computed fields (`borrowedFrom`, `sources`) and a copy's `copiedFrom`. A
2481
+ * resolved body carries them where a stored one doesn't. */
2482
+ private readsAs;
2473
2483
  /** How `slug`'s source joins this config ({@link EntityKind.sourceType}): `linked` unless its pin
2474
2484
  * says otherwise. */
2475
2485
  sourceTypeOf(slug: string): SourceType;
@@ -15,7 +15,7 @@ import { isAuthoringPhantom, phantomsIn } from "./utils/authoring-phantom.js";
15
15
  import { configSchemas } from "./config-ops.js";
16
16
  import { isAuthored } from "./authoring.js";
17
17
  import { Entity } from "./Entity.js";
18
- import { inlineAllSources } from "./inline-sources.js";
18
+ import { inlineAllSources, inlineWholeEntity } from "./inline-sources.js";
19
19
  import { CURRENT_SCHEMA_VERSION, SchemaVersionTooNew, schemaVersionOf, upgradeSerializedConfig } from "./schema-version.js";
20
20
  import { stamp } from "./overlay.js";
21
21
  import { deltaUnderCurrentFields, foldRetiredFields, keptThroughContainerWrite, withEmptiedContainersCleared, withoutClearsInsideClears } from "./retired-fields.js";
@@ -5099,14 +5099,57 @@ var Config = class Config {
5099
5099
  const reaching = this.sourceFor(other);
5100
5100
  const copy = reaching?.resolve(kind, path);
5101
5101
  if (!reaching || !copy) return false;
5102
+ const bare = [...new Set([...reaching.sourceSlugs(), ...collectRefs(copy.body).flatMap((marker) => sourceOf(marker) ?? [])])].reduce((body, slug) => rewriteRefSource(body, slug, void 0), copy.body);
5103
+ const ours = rewriteRefSource(body, other, void 0);
5104
+ return this.readsAs({
5105
+ kind,
5106
+ body: bare,
5107
+ as: ours
5108
+ });
5109
+ }
5110
+ /**
5111
+ * Whether `body` is what `slug`'s entity at `kind:path` becomes when it is inlined here
5112
+ * ({@link withInlinedSources}), which follows their aliases and spells the result in this config's
5113
+ * terms. A pin that survives the inlining still offers the path, and this is the same entity.
5114
+ */
5115
+ inlinedFrom({ body, slug, kind, path }) {
5116
+ let borrowed;
5117
+ try {
5118
+ borrowed = this.extensionBody(kind, {
5119
+ __ref: ref(kind, path, slug).__ref,
5120
+ extend: {}
5121
+ });
5122
+ } catch {
5123
+ return false;
5124
+ }
5125
+ if (!borrowed) return false;
5126
+ let inlined;
5127
+ try {
5128
+ inlined = inlineWholeEntity({
5129
+ body: borrowed,
5130
+ kind,
5131
+ config: this,
5132
+ options: { keepIdentityRefs: true }
5133
+ });
5134
+ } catch {
5135
+ return false;
5136
+ }
5137
+ return this.readsAs({
5138
+ kind,
5139
+ body: inlined,
5140
+ as: body
5141
+ });
5142
+ }
5143
+ /** Whether two bodies of `kind` are the same entity, leaving out the fields that say where a body
5144
+ * came from: the kind's computed fields (`borrowedFrom`, `sources`) and a copy's `copiedFrom`. A
5145
+ * resolved body carries them where a stored one doesn't. */
5146
+ readsAs({ kind, body, as }) {
5102
5147
  const provenance = Object.fromEntries([...this.entityOf(kind)?.computedKeys ?? [], "copiedFrom"].map((key) => [key, void 0]));
5103
- const entityOf = (body) => JSON.stringify({
5104
- ...body,
5148
+ const entityOf = (fields) => JSON.stringify({
5149
+ ...fields,
5105
5150
  ...provenance
5106
5151
  });
5107
- const bare = [...new Set([...reaching.sourceSlugs(), ...collectRefs(copy.body).flatMap((marker) => sourceOf(marker) ?? [])])].reduce((body, slug) => rewriteRefSource(body, slug, void 0), copy.body);
5108
- const ours = rewriteRefSource(body, other, void 0);
5109
- return entityOf(bare) === entityOf(ours);
5152
+ return entityOf(body) === entityOf(as);
5110
5153
  }
5111
5154
  /** How `slug`'s source joins this config ({@link EntityKind.sourceType}): `linked` unless its pin
5112
5155
  * says otherwise. */
@@ -5332,6 +5375,11 @@ var Config = class Config {
5332
5375
  other: slug,
5333
5376
  kind,
5334
5377
  path
5378
+ }) && !this.inlinedFrom({
5379
+ body: current.body,
5380
+ slug,
5381
+ kind,
5382
+ path
5335
5383
  })) ownedAgainst.set(target, [...ownedAgainst.get(target) ?? [], slug]);
5336
5384
  continue;
5337
5385
  }
@@ -21,16 +21,34 @@ function storedDefaultConditions(body) {
21
21
  * Values compare by leaf, so a stored value ref and the bare name a call site writes match.
22
22
  */
23
23
  function defaultsFor({ body, given }) {
24
- const defaults = body?.defaultProps ?? {};
25
- const conditions = Object.values(storedDefaultConditions(body));
26
- if (conditions.length === 0) return defaults;
24
+ const defaults = unconditionalDefaults(body);
25
+ if (Object.keys(storedDefaultConditions(body)).length === 0) return defaults;
27
26
  const out = { ...defaults };
28
- for (const { when, props } of conditions) if (Object.entries(when).every(([prop, value]) => {
29
- const current = given[prop] !== void 0 ? given[prop] : defaults[prop];
30
- return String(refLeaf(current)) === String(refLeaf(value));
31
- })) Object.assign(out, props);
27
+ for (const { condition } of holdingDefaultConditions({
28
+ body,
29
+ given
30
+ })) Object.assign(out, condition.props);
32
31
  return out;
33
32
  }
33
+ /**
34
+ * The `defaultPropsWhen` entries whose condition holds for the props given, in stored order, each
35
+ * with its key. A condition reads a prop's given value, else its unconditional default.
36
+ */
37
+ function holdingDefaultConditions({ body, given }) {
38
+ const defaults = unconditionalDefaults(body);
39
+ return Object.entries(storedDefaultConditions(body)).flatMap(([key, condition]) => {
40
+ return Object.entries(condition.when).every(([prop, value]) => {
41
+ const current = given[prop] !== void 0 ? given[prop] : defaults[prop];
42
+ return String(refLeaf(current)) === String(refLeaf(value));
43
+ }) ? [{
44
+ key,
45
+ condition
46
+ }] : [];
47
+ });
48
+ }
49
+ function unconditionalDefaults(body) {
50
+ return body?.defaultProps ?? {};
51
+ }
34
52
  /** The conditions one prop defaults under, in stored order, each with the value it gives the prop. */
35
53
  function propDefaultConditions({ defaultPropsWhen, prop }) {
36
54
  return Object.values(defaultPropsWhen ?? {}).flatMap(({ when, props }) => props && Object.hasOwn(props, prop) ? [{
@@ -69,4 +87,4 @@ function withPropDefaultConditions({ defaultPropsWhen, prop, entries }) {
69
87
  return out;
70
88
  }
71
89
  //#endregion
72
- export { defaultsFor, propDefaultConditions, storedDefaultConditions, withPropDefaultConditions };
90
+ export { defaultsFor, holdingDefaultConditions, propDefaultConditions, storedDefaultConditions, withPropDefaultConditions };
@@ -101,11 +101,20 @@ function inlineWholeEntity({ body, kind, config, slug, options }) {
101
101
  source: owner
102
102
  });
103
103
  const { [primary]: _ourRef, ...ourFields } = body;
104
- const merged = {
105
- ...inlineSourcedRefs(theirFields, owner, void 0, options),
106
- ...inlineSourcedRefs(ourFields, config, slug, options),
104
+ const carried = inlineSourcedRefs(theirFields, owner, void 0, options);
105
+ const ours = inlineSourcedRefs(ourFields, config, slug, options);
106
+ const borrowed = {
107
+ ...carried,
108
+ ...ours,
107
109
  [primary]: inlineSourcedRefs(theirValue, owner, void 0, options)
108
110
  };
111
+ const merged = config.entityOf(kind)?.prepareLinkedBody?.({
112
+ path: pathOf(pointer),
113
+ body: borrowed,
114
+ source: owner,
115
+ config,
116
+ extend: ours
117
+ }) ?? borrowed;
109
118
  assertCarriedRefsResolve(merged, config, pointer.__ref);
110
119
  return merged;
111
120
  }
@@ -407,4 +416,4 @@ function detachedGroupMeta({ config, kind, groupPath, slug, options }) {
407
416
  };
408
417
  }
409
418
  //#endregion
410
- export { inlineAllSources };
419
+ export { inlineAllSources, inlineWholeEntity };
@@ -30,6 +30,13 @@ interface LayerStyleOptions {
30
30
  interface LayerDeclaration {
31
31
  readonly value: unknown;
32
32
  readonly rule: string;
33
+ /** The rule's condition, as the leaves an instance's props are compared against. Empty for an
34
+ * unconditional rule. */
35
+ readonly when: Readonly<Record<string, unknown>>;
36
+ /** Where the value ranks in the sheet: its rule's selector, plus one per forced block it sits in. */
37
+ readonly specificity: number;
38
+ /** The forced modifier whose block the value sits under, the innermost one when blocks nest. */
39
+ readonly modifier?: string;
33
40
  }
34
41
  /**
35
42
  * The resolved style bag per layer, for the props an instance was given, with the rule each value