@yahoo/uds-create-config 5.88.1 → 5.89.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__fixtures__/yos-native.d.ts +410 -0
- package/dist/__fixtures__/yos-web-source.d.ts +32 -0
- package/dist/entities/system/resolve-properties.d.ts +97 -0
- package/dist/entities/system/resolve-properties.js +374 -0
- package/dist/framework/default-conditions.js +26 -8
- package/dist/framework/layer-styles.d.ts +7 -0
- package/dist/framework/layer-styles.js +75 -19
- package/dist/framework/projections.d.ts +17 -1
- package/dist/framework/projections.js +81 -3
- package/dist/framework/utils/refs.js +5 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -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 };
|
|
@@ -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
|
|
25
|
-
|
|
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 {
|
|
29
|
-
|
|
30
|
-
|
|
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 };
|
|
@@ -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
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRef, refLeaf } from "./utils/refs.js";
|
|
1
|
+
import { isRef, refLeaf, whenLeaves } from "./utils/refs.js";
|
|
2
2
|
import { defaultsFor } from "./default-conditions.js";
|
|
3
3
|
import { authoredBag } from "./projections.js";
|
|
4
4
|
import { resolveAppliedComposites } from "../entities/system/applied-composites.js";
|
|
@@ -81,21 +81,25 @@ function resolvedBag({ config, bag }) {
|
|
|
81
81
|
* author wrote rather than the ref the bag stores — this projection answers "what is this layer styled
|
|
82
82
|
* with" for a panel and a matrix cell, and a picker's options are leaves.
|
|
83
83
|
*/
|
|
84
|
-
function collectBag({ bag, forced, specificity, push }) {
|
|
84
|
+
function collectBag({ bag, forced, specificity, under, push }) {
|
|
85
85
|
const forcedBlocks = [];
|
|
86
86
|
for (const [key, value] of Object.entries(bag)) {
|
|
87
87
|
const modifier = key.startsWith("_") ? key.slice(1) : void 0;
|
|
88
88
|
if (modifier && value && typeof value === "object" && !isRef(value)) {
|
|
89
|
-
if (forced.includes(modifier)) forcedBlocks.push(
|
|
90
|
-
|
|
89
|
+
if (forced.includes(modifier)) forcedBlocks.push({
|
|
90
|
+
modifier,
|
|
91
|
+
block: value
|
|
92
|
+
});
|
|
93
|
+
else push(key, value, specificity, under);
|
|
91
94
|
continue;
|
|
92
95
|
}
|
|
93
|
-
push(key, value, specificity);
|
|
96
|
+
push(key, value, specificity, under);
|
|
94
97
|
}
|
|
95
|
-
for (const block of forcedBlocks) collectBag({
|
|
98
|
+
for (const { modifier, block } of forcedBlocks) collectBag({
|
|
96
99
|
bag: block,
|
|
97
100
|
forced,
|
|
98
101
|
specificity: specificity + 1,
|
|
102
|
+
under: modifier,
|
|
99
103
|
push
|
|
100
104
|
});
|
|
101
105
|
}
|
|
@@ -129,17 +133,19 @@ function preparedRules({ config, path, styles, forced }) {
|
|
|
129
133
|
}),
|
|
130
134
|
forced,
|
|
131
135
|
specificity: ruleSpecificity(rule.when),
|
|
132
|
-
push: (name, value, specificity) => collected.push({
|
|
136
|
+
push: (name, value, specificity, modifier) => collected.push({
|
|
133
137
|
layer,
|
|
134
138
|
key: name,
|
|
135
139
|
value,
|
|
136
140
|
specificity,
|
|
137
141
|
rule: index,
|
|
138
|
-
order: collected.length
|
|
142
|
+
order: collected.length,
|
|
143
|
+
...modifier ? { modifier } : {}
|
|
139
144
|
})
|
|
140
145
|
});
|
|
141
146
|
return {
|
|
142
147
|
when: rule.when,
|
|
148
|
+
leaves: whenLeaves(rule.when),
|
|
143
149
|
collected
|
|
144
150
|
};
|
|
145
151
|
});
|
|
@@ -150,11 +156,9 @@ function preparedRules({ config, path, styles, forced }) {
|
|
|
150
156
|
byComponent.set(key, answer);
|
|
151
157
|
return answer;
|
|
152
158
|
}
|
|
153
|
-
/**
|
|
154
|
-
*
|
|
155
|
-
|
|
156
|
-
*/
|
|
157
|
-
function layerDeclarations(config, path, props = {}, options = {}) {
|
|
159
|
+
/** The values of every rule that applies to an instance, lowest first: by specificity, then where the
|
|
160
|
+
* rule sits in the sheet, then where the value sits in its rule. */
|
|
161
|
+
function applyingDeclarations({ config, path, props, options }) {
|
|
158
162
|
const body = config.resolve("component", path)?.toJSON();
|
|
159
163
|
const { styles = {} } = body ?? {};
|
|
160
164
|
const state = {
|
|
@@ -175,17 +179,69 @@ function layerDeclarations(config, path, props = {}, options = {}) {
|
|
|
175
179
|
const declarations = [];
|
|
176
180
|
for (const { when, collected } of rules) if (ruleApplies(when, state)) declarations.push(...collected);
|
|
177
181
|
declarations.sort((a, b) => a.specificity - b.specificity || a.rule - b.rule || a.order - b.order);
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
out[layer] ??= {};
|
|
181
|
-
out[layer][key] = {
|
|
182
|
+
const describe = ({ value, specificity, rule, modifier }) => {
|
|
183
|
+
const described = {
|
|
182
184
|
value,
|
|
183
|
-
rule: keys[rule] ?? "*"
|
|
185
|
+
rule: keys[rule] ?? "*",
|
|
186
|
+
when: rules[rule]?.leaves ?? NO_CONDITION,
|
|
187
|
+
specificity
|
|
188
|
+
};
|
|
189
|
+
return modifier === void 0 ? described : {
|
|
190
|
+
...described,
|
|
191
|
+
modifier
|
|
184
192
|
};
|
|
193
|
+
};
|
|
194
|
+
return {
|
|
195
|
+
declarations,
|
|
196
|
+
describe
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
const NO_CONDITION = {};
|
|
200
|
+
/** The bag `record` holds under `key`, made when it holds none of its own there. A layer or key
|
|
201
|
+
* named like an `Object` member (`toString`) would otherwise read the inherited one. */
|
|
202
|
+
function ownBag(record, key) {
|
|
203
|
+
const held = Object.hasOwn(record, key) ? record[key] : void 0;
|
|
204
|
+
if (held) return held;
|
|
205
|
+
const made = {};
|
|
206
|
+
record[key] = made;
|
|
207
|
+
return made;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Every value the applying rules set on each layer and key, highest first: the first entry is what
|
|
211
|
+
* paints, and the rest are what would paint if the ones above them went.
|
|
212
|
+
*/
|
|
213
|
+
function layerDeclarationStacks(config, path, props = {}, options = {}) {
|
|
214
|
+
const { declarations, describe } = applyingDeclarations({
|
|
215
|
+
config,
|
|
216
|
+
path,
|
|
217
|
+
props,
|
|
218
|
+
options
|
|
219
|
+
});
|
|
220
|
+
const out = {};
|
|
221
|
+
for (const declaration of declarations) {
|
|
222
|
+
const bag = ownBag(out, declaration.layer);
|
|
223
|
+
const stack = Object.hasOwn(bag, declaration.key) ? bag[declaration.key] : [];
|
|
224
|
+
stack.unshift(describe(declaration));
|
|
225
|
+
bag[declaration.key] = stack;
|
|
185
226
|
}
|
|
186
227
|
return out;
|
|
187
228
|
}
|
|
188
229
|
/**
|
|
230
|
+
* The resolved style bag per layer, for the props an instance was given, with the rule each value
|
|
231
|
+
* came from: what a lint reports at, and writes a fix into.
|
|
232
|
+
*/
|
|
233
|
+
function layerDeclarations(config, path, props = {}, options = {}) {
|
|
234
|
+
const { declarations, describe } = applyingDeclarations({
|
|
235
|
+
config,
|
|
236
|
+
path,
|
|
237
|
+
props,
|
|
238
|
+
options
|
|
239
|
+
});
|
|
240
|
+
const out = {};
|
|
241
|
+
for (const declaration of declarations) ownBag(out, declaration.layer)[declaration.key] = describe(declaration);
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
189
245
|
* The resolved style bag per layer, for the props an instance was given.
|
|
190
246
|
*
|
|
191
247
|
* Layers with nothing to say are absent rather than empty, so a caller can tell "no styling" from
|
|
@@ -197,4 +253,4 @@ function layerStyles(config, path, props = {}, options = {}) {
|
|
|
197
253
|
return out;
|
|
198
254
|
}
|
|
199
255
|
//#endregion
|
|
200
|
-
export { compareComponentRules, conditionHolds, layerDeclarations, layerStyles, ruleApplies, ruleSpecificity };
|
|
256
|
+
export { compareComponentRules, conditionHolds, layerDeclarationStacks, layerDeclarations, layerStyles, ruleApplies, ruleSpecificity };
|
|
@@ -811,6 +811,22 @@ cell?: Record<string, unknown>,
|
|
|
811
811
|
options?: {
|
|
812
812
|
readonly firstVariants?: boolean;
|
|
813
813
|
}): Record<string, unknown>;
|
|
814
|
+
/** Which of a component's default layers a value comes from. */
|
|
815
|
+
type DefaultSource = {
|
|
816
|
+
/** A `preview` entry: `*` for the one every cell reads, else a conditional entry's key. */readonly kind: 'preview';
|
|
817
|
+
readonly key: string;
|
|
818
|
+
readonly when: Readonly<Record<string, unknown>>;
|
|
819
|
+
} | {
|
|
820
|
+
/** A `defaultPropsWhen` entry whose condition holds. */readonly kind: 'default-props-when';
|
|
821
|
+
readonly key: string;
|
|
822
|
+
readonly when: Readonly<Record<string, unknown>>;
|
|
823
|
+
} | {
|
|
824
|
+
readonly kind: 'default-props';
|
|
825
|
+
} /** A prop declaration's own `value`. */ | {
|
|
826
|
+
readonly kind: 'declared-default';
|
|
827
|
+
} /** A variant nothing names, starting at its first value. */ | {
|
|
828
|
+
readonly kind: 'first-variant';
|
|
829
|
+
};
|
|
814
830
|
/**
|
|
815
831
|
* Only what the conditional preview rules add for a cell — the props of every condition that holds
|
|
816
832
|
* for the cell's values over the defaults, later entries over earlier. Nothing else: a caller that
|
|
@@ -884,4 +900,4 @@ declare function propValueFromAxis(config: Config, path: string, prop: string, v
|
|
|
884
900
|
/** The `value` a string, number or boolean prop declares as its default, per prop. */
|
|
885
901
|
declare function declaredPropDefaults(props: Record<string, unknown> | undefined): Record<string, unknown>;
|
|
886
902
|
//#endregion
|
|
887
|
-
export { IconTool, IndexedPreviewCondition, LinkedDraw, PreviewMatrix, PropDeclaration, StyleDeclarationGroup, StylePropEntry, StylePropertyItem, VarNaming, authoredBag, authoredValue, bodyNumberLeaves, bodyNumberUnit, className, cssPropValue, cssVar, cssVarRef, declarationKeyName, declaredPropDefaults, declaredPropRouting, declaresCssVariable, glyphComponentOf, glyphLibrariesOf, glyphPropsOf, heldLinked, holdingPreviewConditions, iconToolAxisOptions, iconToolFor, iconToolOf, iconToolsOf, isCustomPropertyKey, keyedPreviewConditions, linkedDraw, linkedLocalRow, linkedVarNaming, literalValueOf, memberFromLeaf, memberLeaves, nameStyleNumbers, negatedCssValue, opacityPercentage, pinStyleNumbers, previewConditionalProps, previewConditions, previewDefaults, previewMatrix, propOwner, propValueDomain, propValueFromAxis, refListOf, renderInterpolated, renderStyleValue, resolveComponentProps, resolveFieldValue, resolveTokenValue, resolveTokenValueUnder, rewriteStyleNumbers, routedBag, sourceVarPrefix, styleAliasesOf, styleDeclarationGroups, styleDeclarations, styleNumberAsPainted, styleNumberReadingChanges, stylePropEntries, stylePropLeafForToken, stylePropNegates, stylePropNumberCss, stylePropNumberLeaf, stylePropNumberLeaves, stylePropNumberName, stylePropNumberNamedLeaves, stylePropNumberUnit, stylePropNumberUnitRefusal, stylePropTokenGroup, stylePropTokenPath, stylePropTokenValues, stylePropValueFromLeaf, stylePropValueLeaves, stylePropValues, stylePropertiesWriting, stylePropertyAccepts, stylePropertyFor, stylePropertyPathFor, tokenConditions, tokenReference, validateComponentProps };
|
|
903
|
+
export { DefaultSource, IconTool, IndexedPreviewCondition, LinkedDraw, PreviewMatrix, PropDeclaration, StyleDeclarationGroup, StylePropEntry, StylePropertyItem, VarNaming, authoredBag, authoredValue, bodyNumberLeaves, bodyNumberUnit, className, cssPropValue, cssVar, cssVarRef, declarationKeyName, declaredPropDefaults, declaredPropRouting, declaresCssVariable, glyphComponentOf, glyphLibrariesOf, glyphPropsOf, heldLinked, holdingPreviewConditions, iconToolAxisOptions, iconToolFor, iconToolOf, iconToolsOf, isCustomPropertyKey, keyedPreviewConditions, linkedDraw, linkedLocalRow, linkedVarNaming, literalValueOf, memberFromLeaf, memberLeaves, nameStyleNumbers, negatedCssValue, opacityPercentage, pinStyleNumbers, previewConditionalProps, previewConditions, previewDefaults, previewMatrix, propOwner, propValueDomain, propValueFromAxis, refListOf, renderInterpolated, renderStyleValue, resolveComponentProps, resolveFieldValue, resolveTokenValue, resolveTokenValueUnder, rewriteStyleNumbers, routedBag, sourceVarPrefix, styleAliasesOf, styleDeclarationGroups, styleDeclarations, styleNumberAsPainted, styleNumberReadingChanges, stylePropEntries, stylePropLeafForToken, stylePropNegates, stylePropNumberCss, stylePropNumberLeaf, stylePropNumberLeaves, stylePropNumberName, stylePropNumberNamedLeaves, stylePropNumberUnit, stylePropNumberUnitRefusal, stylePropTokenGroup, stylePropTokenPath, stylePropTokenValues, stylePropValueFromLeaf, stylePropValueLeaves, stylePropValues, stylePropertiesWriting, stylePropertyAccepts, stylePropertyFor, stylePropertyPathFor, tokenConditions, tokenReference, validateComponentProps };
|