@eldrajs/theme-core 0.0.0 → 0.2.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/CHANGELOG.md +311 -0
- package/LICENSE +21 -0
- package/README.md +68 -1
- package/dist/bridge-CLi2P6Wh.js +314 -0
- package/dist/bridge.d.ts +2 -0
- package/dist/bridge.js +2 -0
- package/dist/design-tokens.d.ts +68 -0
- package/dist/design-tokens.js +486 -0
- package/dist/dynamic-route.d.ts +2 -0
- package/dist/dynamic-route.js +3 -0
- package/dist/dynamicRoute-CxXY-Y_8.js +126 -0
- package/dist/dynamicRoute-pRTBoYT6.d.ts +55 -0
- package/dist/i18n.d.ts +107 -0
- package/dist/i18n.js +192 -0
- package/dist/image-framing.d.ts +2 -0
- package/dist/image-framing.js +109 -0
- package/dist/imageFraming-BUZ-yqho.d.ts +51 -0
- package/dist/index-DxrkKyG4.d.ts +488 -0
- package/dist/index.d.ts +449 -0
- package/dist/index.js +1141 -0
- package/dist/layout-CWq_v6ws.d.ts +244 -0
- package/dist/layout.d.ts +2 -0
- package/dist/layout.js +930 -0
- package/dist/links.d.ts +113 -0
- package/dist/links.js +184 -0
- package/dist/overlay-Bgi0tIbN.d.ts +201 -0
- package/dist/overlay-C8-F1jzU.js +2908 -0
- package/dist/overlay.d.ts +2 -0
- package/dist/overlay.js +6 -0
- package/dist/preview-router.d.ts +2 -0
- package/dist/preview-router.js +130 -0
- package/dist/reusable.d.ts +66 -0
- package/dist/reusable.js +92 -0
- package/dist/reusableExpansion-Bqm83nCJ.js +229 -0
- package/dist/reusableExpansion-CXvs_ckx.d.ts +42 -0
- package/dist/stega.d.ts +17 -0
- package/dist/stega.js +69 -0
- package/dist/template-layout.d.ts +3 -0
- package/dist/template-layout.js +3 -0
- package/dist/templateLayout-CpZb6EEg.js +382 -0
- package/dist/templateLayout-MjNs0gbF.d.ts +254 -0
- package/package.json +89 -2
package/dist/layout.js
ADDED
|
@@ -0,0 +1,930 @@
|
|
|
1
|
+
//#region src/layout.ts
|
|
2
|
+
/** The theme's breakpoints when it configures none — today's numbers,
|
|
3
|
+
* unchanged, so an unconfigured theme's CSS is byte-identical to before this
|
|
4
|
+
* type existed. */
|
|
5
|
+
const DEFAULT_LAYOUT_BREAKPOINTS = {
|
|
6
|
+
tablet: 768,
|
|
7
|
+
normal: 1024
|
|
8
|
+
};
|
|
9
|
+
const MIN_TABLET_BREAKPOINT = 320;
|
|
10
|
+
const MAX_NORMAL_BREAKPOINT = 4096;
|
|
11
|
+
/**
|
|
12
|
+
* Validates a theme-configured breakpoints pair and falls back to
|
|
13
|
+
* `DEFAULT_LAYOUT_BREAKPOINTS`, with a console warning, on anything that
|
|
14
|
+
* cannot be turned into three non-overlapping, non-empty ranges: both must be
|
|
15
|
+
* finite integers, `320 <= tablet < normal <= 4096`. `undefined`/`null` (not
|
|
16
|
+
* configured) resolves to the defaults silently — that is the common case,
|
|
17
|
+
* not a mistake worth warning about.
|
|
18
|
+
*/
|
|
19
|
+
function resolveLayoutBreakpoints(breakpoints) {
|
|
20
|
+
if (breakpoints === void 0 || breakpoints === null) return DEFAULT_LAYOUT_BREAKPOINTS;
|
|
21
|
+
const { tablet, normal } = breakpoints;
|
|
22
|
+
if (Number.isInteger(tablet) && Number.isInteger(normal) && tablet >= MIN_TABLET_BREAKPOINT && tablet < normal && normal <= MAX_NORMAL_BREAKPOINT) return {
|
|
23
|
+
tablet,
|
|
24
|
+
normal
|
|
25
|
+
};
|
|
26
|
+
console.warn(`[eldra] invalid layout breakpoints ${JSON.stringify(breakpoints)} (expected integers with ${MIN_TABLET_BREAKPOINT} <= tablet < normal <= ${MAX_NORMAL_BREAKPOINT}); falling back to the defaults (${DEFAULT_LAYOUT_BREAKPOINTS.tablet}/${DEFAULT_LAYOUT_BREAKPOINTS.normal}).`);
|
|
27
|
+
return DEFAULT_LAYOUT_BREAKPOINTS;
|
|
28
|
+
}
|
|
29
|
+
/** @deprecated derived px ranges for `DEFAULT_LAYOUT_BREAKPOINTS`, kept for
|
|
30
|
+
* existing consumers. A theme with custom breakpoints is not reflected here —
|
|
31
|
+
* read `resolveLayoutBreakpoints`'s result instead. */
|
|
32
|
+
const LAYOUT_BREAKPOINTS = {
|
|
33
|
+
mobileMax: DEFAULT_LAYOUT_BREAKPOINTS.tablet - 1,
|
|
34
|
+
tabletMin: DEFAULT_LAYOUT_BREAKPOINTS.tablet,
|
|
35
|
+
tabletMax: DEFAULT_LAYOUT_BREAKPOINTS.normal - 1,
|
|
36
|
+
normalMin: DEFAULT_LAYOUT_BREAKPOINTS.normal
|
|
37
|
+
};
|
|
38
|
+
var LayoutValidationError = class extends Error {
|
|
39
|
+
issue;
|
|
40
|
+
constructor(issue) {
|
|
41
|
+
super(`invalid layout at ${JSON.stringify(issue.path)}: ${issue.code}`);
|
|
42
|
+
this.name = "LayoutValidationError";
|
|
43
|
+
this.issue = issue;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const MAX_BYTES = 262144;
|
|
47
|
+
const MAX_NODES = 500;
|
|
48
|
+
const MAX_DEPTH = 12;
|
|
49
|
+
const MAX_SLOTS_PER_NODE = 12;
|
|
50
|
+
const MAX_SLOT_CHILDREN = 20;
|
|
51
|
+
const SLOT_ID = /^[a-z][a-z0-9-]{0,47}$/;
|
|
52
|
+
const NODE_ID = /^[A-Za-z][A-Za-z0-9_-]{0,95}$/;
|
|
53
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
54
|
+
const LENGTH = /^(0|[1-9][0-9]*)(\.[0-9]{1,4})?(px|rem|%)$/;
|
|
55
|
+
const BREAKPOINT_KEYS = [
|
|
56
|
+
"normal",
|
|
57
|
+
"tablet",
|
|
58
|
+
"mobile"
|
|
59
|
+
];
|
|
60
|
+
const SPACING_KEYS = [
|
|
61
|
+
"top",
|
|
62
|
+
"right",
|
|
63
|
+
"bottom",
|
|
64
|
+
"left"
|
|
65
|
+
];
|
|
66
|
+
const STYLE_KEYS = [
|
|
67
|
+
"container",
|
|
68
|
+
"margin",
|
|
69
|
+
"padding",
|
|
70
|
+
"width",
|
|
71
|
+
"minWidth",
|
|
72
|
+
"maxWidth",
|
|
73
|
+
"minHeight",
|
|
74
|
+
"alignSelf",
|
|
75
|
+
"visible"
|
|
76
|
+
];
|
|
77
|
+
var Validator = class {
|
|
78
|
+
allowedEntryIds;
|
|
79
|
+
allowedContainerIds;
|
|
80
|
+
slotContext;
|
|
81
|
+
blockEntryIds = [];
|
|
82
|
+
active = /* @__PURE__ */ new WeakSet();
|
|
83
|
+
ids = /* @__PURE__ */ new Set();
|
|
84
|
+
nodeCount = 0;
|
|
85
|
+
documentVersion = 1;
|
|
86
|
+
constructor(allowedEntryIds, allowedContainerIds, slotContext) {
|
|
87
|
+
this.allowedEntryIds = allowedEntryIds;
|
|
88
|
+
this.allowedContainerIds = allowedContainerIds;
|
|
89
|
+
this.slotContext = slotContext;
|
|
90
|
+
}
|
|
91
|
+
document(value) {
|
|
92
|
+
const object = this.object(value, "");
|
|
93
|
+
return this.withActive(object, "", () => {
|
|
94
|
+
this.keys(object, ["version", "root"], "");
|
|
95
|
+
if (!has(object, "version")) fail("/version", "REQUIRED");
|
|
96
|
+
if (typeof object.version !== "number" || !Number.isInteger(object.version)) fail("/version", "INVALID_TYPE");
|
|
97
|
+
if (object.version !== 1 && object.version !== 2 && object.version !== 3) fail("/version", "INVALID_VALUE");
|
|
98
|
+
this.documentVersion = object.version;
|
|
99
|
+
if (!has(object, "root")) fail("/root", "REQUIRED");
|
|
100
|
+
const root = this.node(object.root, "/root", 1);
|
|
101
|
+
if (root.type === "block") fail("/root/type", "INVALID_VALUE");
|
|
102
|
+
return {
|
|
103
|
+
version: this.documentVersion,
|
|
104
|
+
root
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
node(value, path, depth) {
|
|
109
|
+
if (depth > MAX_DEPTH) fail(path, "LIMIT_EXCEEDED");
|
|
110
|
+
this.nodeCount += 1;
|
|
111
|
+
if (this.nodeCount > MAX_NODES) fail(path, "LIMIT_EXCEEDED");
|
|
112
|
+
const object = this.object(value, path);
|
|
113
|
+
return this.withActive(object, path, () => {
|
|
114
|
+
if (!has(object, "id")) fail(`${path}/id`, "REQUIRED");
|
|
115
|
+
if (typeof object.id !== "string") fail(`${path}/id`, "INVALID_TYPE");
|
|
116
|
+
if (!NODE_ID.test(object.id)) fail(`${path}/id`, "INVALID_VALUE");
|
|
117
|
+
if (this.ids.has(object.id)) fail(`${path}/id`, "DUPLICATE_ID");
|
|
118
|
+
this.ids.add(object.id);
|
|
119
|
+
if (!has(object, "type")) fail(`${path}/type`, "REQUIRED");
|
|
120
|
+
if (typeof object.type !== "string") fail(`${path}/type`, "INVALID_TYPE");
|
|
121
|
+
if (object.type === "block") return this.block(object, path, object.id, depth);
|
|
122
|
+
if (object.type === "flex" || object.type === "grid") return this.container(object, path, depth, object.id, object.type);
|
|
123
|
+
fail(`${path}/type`, "INVALID_VALUE");
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
block(object, path, id, depth) {
|
|
127
|
+
this.keys(object, [
|
|
128
|
+
"id",
|
|
129
|
+
"type",
|
|
130
|
+
"entryId",
|
|
131
|
+
"style",
|
|
132
|
+
"slots",
|
|
133
|
+
"locked"
|
|
134
|
+
], path);
|
|
135
|
+
if (has(object, "locked") && typeof object.locked !== "boolean") fail(`${path}/locked`, "INVALID_TYPE");
|
|
136
|
+
if (!has(object, "entryId")) fail(`${path}/entryId`, "REQUIRED");
|
|
137
|
+
if (typeof object.entryId !== "string") fail(`${path}/entryId`, "INVALID_TYPE");
|
|
138
|
+
if (!UUID.test(object.entryId)) fail(`${path}/entryId`, "INVALID_VALUE");
|
|
139
|
+
if (this.allowedEntryIds && !this.allowedEntryIds.has(object.entryId)) fail(`${path}/entryId`, "BLOCK_NOT_FOUND");
|
|
140
|
+
this.blockEntryIds.push(object.entryId);
|
|
141
|
+
const normalized = {
|
|
142
|
+
id,
|
|
143
|
+
type: "block",
|
|
144
|
+
entryId: object.entryId
|
|
145
|
+
};
|
|
146
|
+
if (has(object, "style")) normalized.style = this.style(object.style, `${path}/style`);
|
|
147
|
+
if (has(object, "slots")) {
|
|
148
|
+
if (this.documentVersion !== 3) fail(`${path}/slots`, "SLOT_VERSION");
|
|
149
|
+
normalized.slots = this.validateSlots(this.object(object.slots, `${path}/slots`), path, depth, object.entryId);
|
|
150
|
+
}
|
|
151
|
+
return normalized;
|
|
152
|
+
}
|
|
153
|
+
validateSlots(raw, path, depth, hostEntryId) {
|
|
154
|
+
if (!this.slotContext) fail(`${path}/slots`, "SLOT_UNKNOWN");
|
|
155
|
+
const hostApiId = this.slotContext.entryApiId(hostEntryId);
|
|
156
|
+
const catalog = hostApiId === void 0 ? void 0 : this.slotContext.slotCatalog[hostApiId];
|
|
157
|
+
if (catalog === void 0) fail(`${path}/slots`, "SLOT_UNKNOWN");
|
|
158
|
+
const docKeys = Object.keys(raw);
|
|
159
|
+
if (docKeys.length > MAX_SLOTS_PER_NODE) fail(`${path}/slots`, "LIMIT_EXCEEDED");
|
|
160
|
+
const catalogById = new Map(catalog.map((slot) => [slot.id, slot]));
|
|
161
|
+
for (const slotId of docKeys) {
|
|
162
|
+
if (!SLOT_ID.test(slotId)) fail(`${path}/slots/${pointerToken(slotId)}`, "INVALID_VALUE");
|
|
163
|
+
if (!catalogById.has(slotId)) fail(`${path}/slots/${pointerToken(slotId)}`, "SLOT_UNKNOWN");
|
|
164
|
+
}
|
|
165
|
+
const out = {};
|
|
166
|
+
for (const def of catalog) {
|
|
167
|
+
if (!has(raw, def.id)) continue;
|
|
168
|
+
const childrenRaw = raw[def.id];
|
|
169
|
+
if (!Array.isArray(childrenRaw)) fail(`${path}/slots/${pointerToken(def.id)}`, "INVALID_TYPE");
|
|
170
|
+
if (childrenRaw.length > MAX_SLOT_CHILDREN) fail(`${path}/slots/${pointerToken(def.id)}`, "LIMIT_EXCEEDED");
|
|
171
|
+
if (childrenRaw.length > def.maxItems) fail(`${path}/slots/${pointerToken(def.id)}`, "SLOT_FULL");
|
|
172
|
+
const children = [];
|
|
173
|
+
for (let index = 0; index < childrenRaw.length; index += 1) {
|
|
174
|
+
const childPath = `${path}/slots/${pointerToken(def.id)}/${index}`;
|
|
175
|
+
const child = childrenRaw[index];
|
|
176
|
+
if (typeof child !== "object" || child === null || child.type !== "block") fail(`${childPath}/type`, "INVALID_TYPE");
|
|
177
|
+
const childNode = this.node(child, childPath, depth + 1);
|
|
178
|
+
const childApiId = this.slotContext.entryApiId(childNode.entryId);
|
|
179
|
+
let allowed = childApiId !== void 0 && childApiId !== hostApiId;
|
|
180
|
+
if (def.allowedBlockApiIds && def.allowedBlockApiIds.length > 0) allowed = def.allowedBlockApiIds.includes(childApiId ?? "");
|
|
181
|
+
if (!allowed) fail(childPath, "SLOT_DISALLOWED");
|
|
182
|
+
children.push(childNode);
|
|
183
|
+
}
|
|
184
|
+
out[def.id] = children;
|
|
185
|
+
}
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
container(object, path, depth, id, type) {
|
|
189
|
+
this.keys(object, [
|
|
190
|
+
"id",
|
|
191
|
+
"type",
|
|
192
|
+
"children",
|
|
193
|
+
"style",
|
|
194
|
+
"layout"
|
|
195
|
+
], path);
|
|
196
|
+
if (!has(object, "children")) fail(`${path}/children`, "REQUIRED");
|
|
197
|
+
if (!Array.isArray(object.children)) fail(`${path}/children`, "INVALID_TYPE");
|
|
198
|
+
const childValues = object.children;
|
|
199
|
+
const children = this.withActive(childValues, `${path}/children`, () => {
|
|
200
|
+
this.arrayKeys(childValues, `${path}/children`);
|
|
201
|
+
return childValues.map((child, index) => this.node(child, `${path}/children/${index}`, depth + 1));
|
|
202
|
+
});
|
|
203
|
+
const style = has(object, "style") ? this.style(object.style, `${path}/style`) : void 0;
|
|
204
|
+
if (!has(object, "layout")) fail(`${path}/layout`, "REQUIRED");
|
|
205
|
+
if (type === "flex") {
|
|
206
|
+
const node = {
|
|
207
|
+
id,
|
|
208
|
+
type,
|
|
209
|
+
children,
|
|
210
|
+
layout: this.flexLayout(object.layout, `${path}/layout`)
|
|
211
|
+
};
|
|
212
|
+
if (style) node.style = style;
|
|
213
|
+
return node;
|
|
214
|
+
}
|
|
215
|
+
const node = {
|
|
216
|
+
id,
|
|
217
|
+
type,
|
|
218
|
+
children,
|
|
219
|
+
layout: this.gridLayout(object.layout, `${path}/layout`)
|
|
220
|
+
};
|
|
221
|
+
if (style) node.style = style;
|
|
222
|
+
return node;
|
|
223
|
+
}
|
|
224
|
+
style(value, path) {
|
|
225
|
+
const object = this.object(value, path);
|
|
226
|
+
return this.withActive(object, path, () => {
|
|
227
|
+
this.keys(object, [...STYLE_KEYS], path);
|
|
228
|
+
const result = {};
|
|
229
|
+
if (has(object, "container")) result.container = this.responsive(object.container, `${path}/container`, (item, itemPath) => {
|
|
230
|
+
if (typeof item !== "string") fail(itemPath, "INVALID_TYPE");
|
|
231
|
+
if (!/^[a-z][a-z0-9-]{0,48}$/.test(item)) fail(itemPath, "INVALID_VALUE");
|
|
232
|
+
if (!this.allowedContainerIds?.has(item)) fail(itemPath, "INVALID_VALUE");
|
|
233
|
+
return item;
|
|
234
|
+
});
|
|
235
|
+
if (has(object, "margin")) result.margin = this.spacing(object.margin, `${path}/margin`);
|
|
236
|
+
if (has(object, "padding")) result.padding = this.spacing(object.padding, `${path}/padding`);
|
|
237
|
+
if (has(object, "width")) result.width = this.responsive(object.width, `${path}/width`, widthLength);
|
|
238
|
+
if (has(object, "minWidth")) result.minWidth = this.responsive(object.minWidth, `${path}/minWidth`, sizingLength);
|
|
239
|
+
if (has(object, "maxWidth")) result.maxWidth = this.responsive(object.maxWidth, `${path}/maxWidth`, sizingLength);
|
|
240
|
+
if (has(object, "minHeight")) result.minHeight = this.responsive(object.minHeight, `${path}/minHeight`, sizingLength);
|
|
241
|
+
if (has(object, "alignSelf")) result.alignSelf = this.responsive(object.alignSelf, `${path}/alignSelf`, enumeration([
|
|
242
|
+
"auto",
|
|
243
|
+
"start",
|
|
244
|
+
"center",
|
|
245
|
+
"end",
|
|
246
|
+
"stretch"
|
|
247
|
+
]));
|
|
248
|
+
if (has(object, "visible")) result.visible = this.responsive(object.visible, `${path}/visible`, booleanValue);
|
|
249
|
+
return result;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
flexLayout(value, path) {
|
|
253
|
+
const object = this.object(value, path);
|
|
254
|
+
return this.withActive(object, path, () => {
|
|
255
|
+
this.keys(object, [
|
|
256
|
+
"direction",
|
|
257
|
+
"wrap",
|
|
258
|
+
"gap",
|
|
259
|
+
"justify",
|
|
260
|
+
"align"
|
|
261
|
+
], path);
|
|
262
|
+
if (!has(object, "direction")) fail(`${path}/direction`, "REQUIRED");
|
|
263
|
+
const result = { direction: this.responsive(object.direction, `${path}/direction`, enumeration(["row", "column"])) };
|
|
264
|
+
if (has(object, "wrap")) result.wrap = this.responsive(object.wrap, `${path}/wrap`, enumeration(["nowrap", "wrap"]));
|
|
265
|
+
if (has(object, "gap")) result.gap = this.responsive(object.gap, `${path}/gap`, cssLength);
|
|
266
|
+
if (has(object, "justify")) result.justify = this.responsive(object.justify, `${path}/justify`, enumeration([
|
|
267
|
+
"start",
|
|
268
|
+
"center",
|
|
269
|
+
"end",
|
|
270
|
+
"space-between",
|
|
271
|
+
"space-around",
|
|
272
|
+
"space-evenly"
|
|
273
|
+
]));
|
|
274
|
+
if (has(object, "align")) result.align = this.responsive(object.align, `${path}/align`, enumeration([
|
|
275
|
+
"start",
|
|
276
|
+
"center",
|
|
277
|
+
"end",
|
|
278
|
+
"stretch",
|
|
279
|
+
"baseline"
|
|
280
|
+
]));
|
|
281
|
+
return result;
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
gridLayout(value, path) {
|
|
285
|
+
const object = this.object(value, path);
|
|
286
|
+
return this.withActive(object, path, () => {
|
|
287
|
+
this.keys(object, [
|
|
288
|
+
"columns",
|
|
289
|
+
"rows",
|
|
290
|
+
"columnGap",
|
|
291
|
+
"rowGap",
|
|
292
|
+
"justifyItems",
|
|
293
|
+
"alignItems"
|
|
294
|
+
], path);
|
|
295
|
+
if (!has(object, "columns")) fail(`${path}/columns`, "REQUIRED");
|
|
296
|
+
const result = { columns: this.responsive(object.columns, `${path}/columns`, gridInteger(false)) };
|
|
297
|
+
if (has(object, "rows")) result.rows = this.responsive(object.rows, `${path}/rows`, gridInteger(true));
|
|
298
|
+
if (has(object, "columnGap")) result.columnGap = this.responsive(object.columnGap, `${path}/columnGap`, cssLength);
|
|
299
|
+
if (has(object, "rowGap")) result.rowGap = this.responsive(object.rowGap, `${path}/rowGap`, cssLength);
|
|
300
|
+
if (has(object, "justifyItems")) result.justifyItems = this.responsive(object.justifyItems, `${path}/justifyItems`, enumeration([
|
|
301
|
+
"start",
|
|
302
|
+
"center",
|
|
303
|
+
"end",
|
|
304
|
+
"stretch"
|
|
305
|
+
]));
|
|
306
|
+
if (has(object, "alignItems")) result.alignItems = this.responsive(object.alignItems, `${path}/alignItems`, enumeration([
|
|
307
|
+
"start",
|
|
308
|
+
"center",
|
|
309
|
+
"end",
|
|
310
|
+
"stretch"
|
|
311
|
+
]));
|
|
312
|
+
return result;
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
responsive(value, path, normalize) {
|
|
316
|
+
const object = this.object(value, path);
|
|
317
|
+
return this.withActive(object, path, () => {
|
|
318
|
+
this.keys(object, [...BREAKPOINT_KEYS], path);
|
|
319
|
+
if (!has(object, "normal")) fail(`${path}/normal`, "REQUIRED");
|
|
320
|
+
const result = { normal: normalize(object.normal, `${path}/normal`) };
|
|
321
|
+
if (has(object, "tablet")) result.tablet = normalize(object.tablet, `${path}/tablet`);
|
|
322
|
+
if (has(object, "mobile")) result.mobile = normalize(object.mobile, `${path}/mobile`);
|
|
323
|
+
return result;
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
spacing(value, path) {
|
|
327
|
+
return this.responsive(value, path, (spacing, spacingPath) => {
|
|
328
|
+
const object = this.object(spacing, spacingPath);
|
|
329
|
+
return this.withActive(object, spacingPath, () => {
|
|
330
|
+
this.keys(object, [...SPACING_KEYS], spacingPath);
|
|
331
|
+
const result = {};
|
|
332
|
+
for (const side of SPACING_KEYS) if (has(object, side)) result[side] = cssLength(object[side], `${spacingPath}/${side}`);
|
|
333
|
+
return result;
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
object(value, path) {
|
|
338
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) fail(path, "INVALID_TYPE");
|
|
339
|
+
return value;
|
|
340
|
+
}
|
|
341
|
+
keys(object, allowed, path) {
|
|
342
|
+
const allowedSet = new Set(allowed);
|
|
343
|
+
const unknown = Object.keys(object).filter((key) => !allowedSet.has(key)).sort()[0];
|
|
344
|
+
if (unknown !== void 0) fail(`${path}/${pointerToken(unknown)}`, "UNKNOWN_KEY");
|
|
345
|
+
}
|
|
346
|
+
arrayKeys(array, path) {
|
|
347
|
+
const unknown = Object.keys(array).filter((key) => !/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= array.length).sort()[0];
|
|
348
|
+
if (unknown !== void 0) fail(`${path}/${pointerToken(unknown)}`, "UNKNOWN_KEY");
|
|
349
|
+
}
|
|
350
|
+
withActive(object, path, visit) {
|
|
351
|
+
if (this.active.has(object)) fail(path, "INVALID_VALUE");
|
|
352
|
+
this.active.add(object);
|
|
353
|
+
try {
|
|
354
|
+
return visit();
|
|
355
|
+
} finally {
|
|
356
|
+
this.active.delete(object);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
function validateLayoutDocument(value, allowedEntryIds, allowedContainerIds, slotContext) {
|
|
361
|
+
try {
|
|
362
|
+
normalizeLayoutDocument(value, allowedEntryIds, allowedContainerIds, slotContext);
|
|
363
|
+
return null;
|
|
364
|
+
} catch (error) {
|
|
365
|
+
if (error instanceof LayoutValidationError) return error.issue;
|
|
366
|
+
throw error;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function normalizeLayoutDocument(value, allowedEntryIds, allowedContainerIds, slotContext) {
|
|
370
|
+
const validator = new Validator(allowedEntryIds, allowedContainerIds, slotContext);
|
|
371
|
+
const document = validator.document(value);
|
|
372
|
+
if (new TextEncoder().encode(canonicalJson(document)).byteLength > MAX_BYTES) fail("", "LIMIT_EXCEEDED");
|
|
373
|
+
return {
|
|
374
|
+
document,
|
|
375
|
+
blockEntryIds: validator.blockEntryIds
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function resolveLayoutDocument(value, breakpoint, allowedEntryIds, allowedContainerIds) {
|
|
379
|
+
const { document } = normalizeLayoutDocument(value, allowedEntryIds, allowedContainerIds);
|
|
380
|
+
return {
|
|
381
|
+
version: 1,
|
|
382
|
+
breakpoint,
|
|
383
|
+
root: resolveNode(document.root, breakpoint)
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function layoutNodeClass(nodeId) {
|
|
387
|
+
if (!NODE_ID.test(nodeId)) throw new TypeError("layout node id must be canonical");
|
|
388
|
+
return `eldra-layout-${sha256Hex(new TextEncoder().encode(nodeId))}`;
|
|
389
|
+
}
|
|
390
|
+
/** A canonical, collision-resistant node id for framework render identities. */
|
|
391
|
+
function layoutRenderNodeId(identity) {
|
|
392
|
+
if (typeof identity !== "string" || identity.length === 0) throw new TypeError("layout render identity must be non-empty");
|
|
393
|
+
return `r${sha256Hex(new TextEncoder().encode(identity))}`;
|
|
394
|
+
}
|
|
395
|
+
function generateLayoutCss(value, allowedEntryIds, allowedContainerIds, breakpoints) {
|
|
396
|
+
const { document } = normalizeLayoutDocument(value, allowedEntryIds, allowedContainerIds);
|
|
397
|
+
return cssForDocument(document, breakpoints);
|
|
398
|
+
}
|
|
399
|
+
function createLayoutRenderModel(value, allowedEntryIds, allowedContainerIds, slotContext, breakpoints) {
|
|
400
|
+
const normalized = normalizeLayoutDocument(value, allowedEntryIds, allowedContainerIds, slotContext);
|
|
401
|
+
return {
|
|
402
|
+
...normalized,
|
|
403
|
+
root: renderNode(normalized.document.root),
|
|
404
|
+
css: cssForDocument(normalized.document, breakpoints)
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
function resolveNode(node, breakpoint) {
|
|
408
|
+
const style = resolveStyle(node.style, breakpoint);
|
|
409
|
+
if (node.type === "block") return {
|
|
410
|
+
id: node.id,
|
|
411
|
+
type: node.type,
|
|
412
|
+
entryId: node.entryId,
|
|
413
|
+
style
|
|
414
|
+
};
|
|
415
|
+
if (node.type === "flex") return {
|
|
416
|
+
id: node.id,
|
|
417
|
+
type: node.type,
|
|
418
|
+
children: node.children.map((child) => resolveNode(child, breakpoint)),
|
|
419
|
+
style,
|
|
420
|
+
layout: {
|
|
421
|
+
direction: scalar(node.layout.direction, breakpoint),
|
|
422
|
+
...node.layout.wrap ? { wrap: scalar(node.layout.wrap, breakpoint) } : {},
|
|
423
|
+
...node.layout.gap ? { gap: scalar(node.layout.gap, breakpoint) } : {},
|
|
424
|
+
...node.layout.justify ? { justify: scalar(node.layout.justify, breakpoint) } : {},
|
|
425
|
+
...node.layout.align ? { align: scalar(node.layout.align, breakpoint) } : {}
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
return {
|
|
429
|
+
id: node.id,
|
|
430
|
+
type: node.type,
|
|
431
|
+
children: node.children.map((child) => resolveNode(child, breakpoint)),
|
|
432
|
+
style,
|
|
433
|
+
layout: {
|
|
434
|
+
columns: scalar(node.layout.columns, breakpoint),
|
|
435
|
+
...node.layout.rows ? { rows: scalar(node.layout.rows, breakpoint) } : {},
|
|
436
|
+
...node.layout.columnGap ? { columnGap: scalar(node.layout.columnGap, breakpoint) } : {},
|
|
437
|
+
...node.layout.rowGap ? { rowGap: scalar(node.layout.rowGap, breakpoint) } : {},
|
|
438
|
+
...node.layout.justifyItems ? { justifyItems: scalar(node.layout.justifyItems, breakpoint) } : {},
|
|
439
|
+
...node.layout.alignItems ? { alignItems: scalar(node.layout.alignItems, breakpoint) } : {}
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
function resolveStyle(style, breakpoint) {
|
|
444
|
+
if (!style) return { visible: true };
|
|
445
|
+
return {
|
|
446
|
+
...style.container ? { container: scalar(style.container, breakpoint) } : {},
|
|
447
|
+
...style.margin ? { margin: spacing(style.margin, breakpoint) } : {},
|
|
448
|
+
...style.padding ? { padding: spacing(style.padding, breakpoint) } : {},
|
|
449
|
+
...style.width ? { width: scalar(style.width, breakpoint) } : {},
|
|
450
|
+
...style.minWidth ? { minWidth: scalar(style.minWidth, breakpoint) } : {},
|
|
451
|
+
...style.maxWidth ? { maxWidth: scalar(style.maxWidth, breakpoint) } : {},
|
|
452
|
+
...style.minHeight ? { minHeight: scalar(style.minHeight, breakpoint) } : {},
|
|
453
|
+
...style.alignSelf ? { alignSelf: scalar(style.alignSelf, breakpoint) } : {},
|
|
454
|
+
visible: style.visible ? scalar(style.visible, breakpoint) : true
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* How visible a hidden node is on the Studio canvas in edit mode — the design's
|
|
459
|
+
* 35 %: dim enough to read as "not on this device", solid enough to click,
|
|
460
|
+
* drag and see what it is.
|
|
461
|
+
*/
|
|
462
|
+
const EDIT_MODE_HIDDEN_OPACITY = .35;
|
|
463
|
+
/**
|
|
464
|
+
* Which of the three breakpoint ranges a viewport width falls in — the same
|
|
465
|
+
* ranges `cssForDocument` emits its `@media` blocks for, read from the one
|
|
466
|
+
* place that knows them, so a runtime asking "which breakpoint is in force?"
|
|
467
|
+
* and the browser evaluating the stylesheet cannot drift apart. `width` is the
|
|
468
|
+
* viewport width in CSS pixels (`window.innerWidth`), which is what a width
|
|
469
|
+
* media query is evaluated against.
|
|
470
|
+
*/
|
|
471
|
+
function activeLayoutBreakpoint(width, breakpoints) {
|
|
472
|
+
const resolved = resolveLayoutBreakpoints(breakpoints);
|
|
473
|
+
if (width >= resolved.normal) return "normal";
|
|
474
|
+
if (width >= resolved.tablet) return "tablet";
|
|
475
|
+
return "mobile";
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* The breakpoints at which `style` hides its node, in `normal, tablet, mobile`
|
|
479
|
+
* order, resolved through the grammar's own inheritance (a `visible` a
|
|
480
|
+
* breakpoint does not restate is inherited from the wider one). Empty when the
|
|
481
|
+
* node is visible everywhere.
|
|
482
|
+
*
|
|
483
|
+
* This is the value of the `data-eldra-hidden` attribute a framework binding
|
|
484
|
+
* puts on the layout node, space-separated: it is rendered identically on the
|
|
485
|
+
* server and the client, carries no styling of its own, and is what the overlay
|
|
486
|
+
* finds the hidden nodes by when it marks them for edit mode.
|
|
487
|
+
*/
|
|
488
|
+
function hiddenLayoutBreakpoints(style) {
|
|
489
|
+
const visible = style?.visible;
|
|
490
|
+
if (visible === void 0) return [];
|
|
491
|
+
return BREAKPOINT_KEYS.filter((breakpoint) => !scalar(visible, breakpoint));
|
|
492
|
+
}
|
|
493
|
+
function scalar(responsive, breakpoint) {
|
|
494
|
+
if (breakpoint === "mobile") return responsive.mobile ?? responsive.tablet ?? responsive.normal;
|
|
495
|
+
if (breakpoint === "tablet") return responsive.tablet ?? responsive.normal;
|
|
496
|
+
return responsive.normal;
|
|
497
|
+
}
|
|
498
|
+
function spacing(responsive, breakpoint) {
|
|
499
|
+
const normal = responsive.normal;
|
|
500
|
+
if (breakpoint === "normal") return { ...normal };
|
|
501
|
+
const tablet = {
|
|
502
|
+
...normal,
|
|
503
|
+
...responsive.tablet
|
|
504
|
+
};
|
|
505
|
+
return breakpoint === "tablet" ? tablet : {
|
|
506
|
+
...tablet,
|
|
507
|
+
...responsive.mobile
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
function renderNode(node) {
|
|
511
|
+
const className = layoutNodeClass(node.id);
|
|
512
|
+
if (node.type === "block") {
|
|
513
|
+
if (!node.slots) return {
|
|
514
|
+
...node,
|
|
515
|
+
className
|
|
516
|
+
};
|
|
517
|
+
const slots = {};
|
|
518
|
+
for (const [slotId, children] of Object.entries(node.slots)) slots[slotId] = children.map((child) => renderNode(child));
|
|
519
|
+
return {
|
|
520
|
+
...node,
|
|
521
|
+
className,
|
|
522
|
+
slots
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
return {
|
|
526
|
+
...node,
|
|
527
|
+
className,
|
|
528
|
+
children: node.children.map(renderNode)
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
function cssForDocument(document, breakpoints) {
|
|
532
|
+
const { tablet, normal } = resolveLayoutBreakpoints(breakpoints);
|
|
533
|
+
const entries = [];
|
|
534
|
+
walk(document.root, null, null, (node, parent, host) => entries.push({
|
|
535
|
+
node,
|
|
536
|
+
parent,
|
|
537
|
+
host
|
|
538
|
+
}));
|
|
539
|
+
const nodes = entries.map(({ node }) => node);
|
|
540
|
+
const resolved = BREAKPOINT_KEYS.map((breakpoint) => {
|
|
541
|
+
const intrinsicById = /* @__PURE__ */ new Map();
|
|
542
|
+
return entries.map(({ node, parent, host }) => {
|
|
543
|
+
const resolvedNode = resolveNode(node, breakpoint);
|
|
544
|
+
const parentCtx = parentContext(parent, breakpoint);
|
|
545
|
+
const enclosing = parent ?? host;
|
|
546
|
+
const enclosingIntrinsic = enclosing === null ? false : intrinsicById.get(enclosing.id) ?? false;
|
|
547
|
+
const intrinsic = intrinsicInlineSize(resolvedNode.style, parentCtx, enclosingIntrinsic);
|
|
548
|
+
intrinsicById.set(node.id, intrinsic);
|
|
549
|
+
return {
|
|
550
|
+
own: {
|
|
551
|
+
...declarations(resolvedNode, node, breakpoint, parentCtx),
|
|
552
|
+
...containerTypeDeclarations(node, intrinsic)
|
|
553
|
+
},
|
|
554
|
+
child: node.type === "block" && intrinsic ? { "container-type": "normal" } : {},
|
|
555
|
+
hidden: !resolvedNode.style.visible
|
|
556
|
+
};
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
const rulesAt = (index) => nodes.map((node, position) => rule(node, resolved[index][position].own) + childRule(node, resolved[index][position].child) + hiddenRule(node, resolved[index][position].hidden)).join("");
|
|
560
|
+
const normalRules = rulesAt(0);
|
|
561
|
+
const tabletRules = rulesAt(1);
|
|
562
|
+
const mobileRules = rulesAt(2);
|
|
563
|
+
return `${normalRules ? `@media (min-width:${normal}px){${normalRules}}` : ""}${tabletRules ? `@media (min-width:${tablet}px) and (max-width:${normal - 1}px){${tabletRules}}` : ""}${mobileRules ? `@media (max-width:${tablet - 1}px){${mobileRules}}` : ""}`;
|
|
564
|
+
}
|
|
565
|
+
function parentContext(parent, breakpoint) {
|
|
566
|
+
if (parent === null) return { type: "none" };
|
|
567
|
+
if (parent.type === "grid") return { type: "grid" };
|
|
568
|
+
return {
|
|
569
|
+
type: "flex",
|
|
570
|
+
direction: scalar(parent.layout.direction, breakpoint)
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
function declarations(node, source, breakpoint, parent) {
|
|
574
|
+
const result = {};
|
|
575
|
+
if (node.type === "flex") {
|
|
576
|
+
result.display = "flex";
|
|
577
|
+
result["flex-direction"] = node.layout.direction;
|
|
578
|
+
if (node.layout.wrap !== void 0) result["flex-wrap"] = node.layout.wrap;
|
|
579
|
+
if (node.layout.gap !== void 0) result.gap = node.layout.gap;
|
|
580
|
+
if (node.layout.justify !== void 0) result["justify-content"] = node.layout.justify;
|
|
581
|
+
if (node.layout.align !== void 0) result["align-items"] = node.layout.align;
|
|
582
|
+
} else if (node.type === "grid") {
|
|
583
|
+
result.display = "grid";
|
|
584
|
+
result["grid-template-columns"] = `repeat(${node.layout.columns},minmax(0,1fr))`;
|
|
585
|
+
if (node.layout.rows !== void 0) result["grid-template-rows"] = node.layout.rows === "auto" ? "auto" : `repeat(${node.layout.rows},minmax(0,1fr))`;
|
|
586
|
+
if (node.layout.columnGap !== void 0) result["column-gap"] = node.layout.columnGap;
|
|
587
|
+
if (node.layout.rowGap !== void 0) result["row-gap"] = node.layout.rowGap;
|
|
588
|
+
if (node.layout.justifyItems !== void 0) result["justify-items"] = node.layout.justifyItems;
|
|
589
|
+
if (node.layout.alignItems !== void 0) result["align-items"] = node.layout.alignItems;
|
|
590
|
+
}
|
|
591
|
+
const style = node.style;
|
|
592
|
+
if (style.container !== void 0) {
|
|
593
|
+
result.width = "100%";
|
|
594
|
+
result["max-width"] = `var(--eldra-container-${style.container}-max-width)`;
|
|
595
|
+
result["margin-left"] = "auto";
|
|
596
|
+
result["margin-right"] = "auto";
|
|
597
|
+
result["padding-left"] = `var(--eldra-container-${style.container}-gutter-${breakpoint})`;
|
|
598
|
+
result["padding-right"] = `var(--eldra-container-${style.container}-gutter-${breakpoint})`;
|
|
599
|
+
}
|
|
600
|
+
for (const side of SPACING_KEYS) {
|
|
601
|
+
const margin = style.margin?.[side];
|
|
602
|
+
const padding = style.padding?.[side];
|
|
603
|
+
if (margin !== void 0) result[`margin-${side}`] = margin;
|
|
604
|
+
if (padding !== void 0) result[`padding-${side}`] = padding;
|
|
605
|
+
}
|
|
606
|
+
if (style.width !== void 0) Object.assign(result, widthDeclarations(style.width, parent));
|
|
607
|
+
if (style.minWidth !== void 0) result["min-width"] = style.minWidth;
|
|
608
|
+
if (style.maxWidth !== void 0) result["max-width"] = style.maxWidth;
|
|
609
|
+
if (style.minHeight !== void 0) result["min-height"] = style.minHeight;
|
|
610
|
+
if (style.alignSelf !== void 0) result["align-self"] = style.alignSelf;
|
|
611
|
+
if (style.visible && node.type === "block" && source.style?.visible !== void 0) result.display = "block";
|
|
612
|
+
return result;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* The `display:none` for a node hidden at this breakpoint, plus the edit-mode
|
|
616
|
+
* treatment that replaces it.
|
|
617
|
+
*
|
|
618
|
+
* `:not([data-eldra-edit-mode])` is the gate: the overlay sets that attribute on
|
|
619
|
+
* hidden nodes after mount when the bridge mode is `edit` (never during render,
|
|
620
|
+
* so server and client emit the same DOM), and removes it on any other mode.
|
|
621
|
+
* Preview, static generation and the published site never carry it, so they
|
|
622
|
+
* hide the node outright, exactly as before. Under the editor the node is drawn
|
|
623
|
+
* at reduced opacity instead, which is what keeps it selectable on the canvas.
|
|
624
|
+
*
|
|
625
|
+
* Both selectors add an attribute selector's specificity on top of the class,
|
|
626
|
+
* so they outrank the node's own `.class` rule (its `display:flex`/`grid`)
|
|
627
|
+
* wherever they land in the stylesheet.
|
|
628
|
+
*
|
|
629
|
+
* `:not([data-eldra-edit-mode] *)` on the dimming rule is what keeps the opacity
|
|
630
|
+
* from compounding. The marker goes on every element carrying a hidden node's
|
|
631
|
+
* class — it has to, because the `display:none` gate is per element and a
|
|
632
|
+
* framework binding may render a node's class on more than one nested element
|
|
633
|
+
* (a slot child's wrapper and the block div inside it both carry it) — and
|
|
634
|
+
* `opacity` multiplies through nesting where `display:none` was idempotent.
|
|
635
|
+
* Dimming only a marked element that has no marked ancestor applies the 35 %
|
|
636
|
+
* once per hidden subtree, so a hidden node inside a hidden node, and a hidden
|
|
637
|
+
* slot child, all land at 0.35 rather than 0.1225.
|
|
638
|
+
*/
|
|
639
|
+
function hiddenRule(node, hidden) {
|
|
640
|
+
if (!hidden) return "";
|
|
641
|
+
const selector = `.${layoutNodeClass(node.id)}`;
|
|
642
|
+
return `${selector}:not([data-eldra-edit-mode]){display:none;}${selector}[data-eldra-edit-mode]:not([data-eldra-edit-mode] *){opacity:${EDIT_MODE_HIDDEN_OPACITY};}`;
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* A length/`auto` `width` emits exactly as before (`width:<value>`), so
|
|
646
|
+
* existing documents are byte-identical. The two intrinsic-sizing keywords
|
|
647
|
+
* depend on the immediate parent context (a plain length/`auto` never does):
|
|
648
|
+
*
|
|
649
|
+
* - `fill`: parent flex row -> `flex:1 1 0%; min-width:0` (no `width` at
|
|
650
|
+
* all — a flex item's width comes from `flex-basis`); parent flex column
|
|
651
|
+
* or no flex parent -> `width:100%`; parent grid -> `justify-self:stretch;
|
|
652
|
+
* width:100%`.
|
|
653
|
+
* - `fit-content`: parent flex row -> `flex:0 0 auto; width:fit-content`;
|
|
654
|
+
* parent flex column or no flex parent -> `width:fit-content`; parent grid
|
|
655
|
+
* -> `justify-self:start; width:fit-content`.
|
|
656
|
+
*
|
|
657
|
+
* A node whose inline size is *intrinsic* (`fit-content`, or `auto`/unset in
|
|
658
|
+
* a flex row, or anything but a fixed length inside such a node) can only
|
|
659
|
+
* measure its content if nothing in it applies inline-size containment — see
|
|
660
|
+
* `intrinsicInlineSize` and `containerTypeDeclarations`, which move the
|
|
661
|
+
* container-query root off such a block.
|
|
662
|
+
*
|
|
663
|
+
* An explicit `minWidth`/`maxWidth`/`minHeight` on the same node is applied
|
|
664
|
+
* by the caller after this (unconditionally, from `style`), so it always
|
|
665
|
+
* wins over the implicit `min-width:0` a flex-row `fill` sets here.
|
|
666
|
+
*/
|
|
667
|
+
function widthDeclarations(width, parent) {
|
|
668
|
+
if (width !== "fill" && width !== "fit-content") return { width };
|
|
669
|
+
const flexRow = parent.type === "flex" && parent.direction === "row";
|
|
670
|
+
if (width === "fill") {
|
|
671
|
+
if (flexRow) return {
|
|
672
|
+
flex: "1 1 0%",
|
|
673
|
+
"min-width": "0"
|
|
674
|
+
};
|
|
675
|
+
if (parent.type === "grid") return {
|
|
676
|
+
"justify-self": "stretch",
|
|
677
|
+
width: "100%"
|
|
678
|
+
};
|
|
679
|
+
return { width: "100%" };
|
|
680
|
+
}
|
|
681
|
+
if (flexRow) return {
|
|
682
|
+
flex: "0 0 auto",
|
|
683
|
+
width: "fit-content"
|
|
684
|
+
};
|
|
685
|
+
if (parent.type === "grid") return {
|
|
686
|
+
"justify-self": "start",
|
|
687
|
+
width: "fit-content"
|
|
688
|
+
};
|
|
689
|
+
return { width: "fit-content" };
|
|
690
|
+
}
|
|
691
|
+
const FIXED_LENGTH = /^\d+(?:\.\d+)?(?:px|rem)$/;
|
|
692
|
+
/**
|
|
693
|
+
* Whether a node's inline size is *intrinsic* — measured from its content —
|
|
694
|
+
* at this breakpoint. That is the case for `fit-content`; for an unset or
|
|
695
|
+
* `auto` width when the node is an item of a flex row (an `auto` basis is
|
|
696
|
+
* max-content); and for anything but a fixed `px`/`rem` length inside a node
|
|
697
|
+
* that is itself intrinsically sized (a percentage, `fill`, a container
|
|
698
|
+
* preset or an unset width all resolve against the enclosing box, which has
|
|
699
|
+
* no size of its own until its content is measured). A determinate node —
|
|
700
|
+
* a fixed length, a `fill`, a percentage, a stretched flex-column or grid
|
|
701
|
+
* item — is sized by its parent and never needs to measure its content.
|
|
702
|
+
*/
|
|
703
|
+
function intrinsicInlineSize(style, parent, enclosingIntrinsic) {
|
|
704
|
+
const width = style.width;
|
|
705
|
+
if (width !== void 0 && FIXED_LENGTH.test(width)) return false;
|
|
706
|
+
if (width === "fit-content") return true;
|
|
707
|
+
if (enclosingIntrinsic) return true;
|
|
708
|
+
if (style.container !== void 0) return false;
|
|
709
|
+
if (width === void 0 || width === "auto") return parent.type === "flex" && parent.direction === "row";
|
|
710
|
+
return false;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Container queries are how a block adapts to the width it is given, and a
|
|
714
|
+
* query container is what a block's own `@container` root establishes — but
|
|
715
|
+
* `container-type: inline-size` also applies inline-size *containment*, under
|
|
716
|
+
* which an element has no intrinsic inline size at all: it contributes 0 to a
|
|
717
|
+
* `fit-content` width and to a flex item's `auto` basis. A block whose width
|
|
718
|
+
* is intrinsic therefore cannot be its own query container, or it collapses
|
|
719
|
+
* to 0px. For such a block the generated CSS turns containment off on the
|
|
720
|
+
* block root (`.<node>>*{container-type:normal}`, emitted by the caller) and
|
|
721
|
+
* the block's queries resolve against the nearest determinate ancestor
|
|
722
|
+
* instead: every determinately sized container node is made a query
|
|
723
|
+
* container here, the document root included, so there always is one — the
|
|
724
|
+
* block then responds to the width of the region it sits in, which is the
|
|
725
|
+
* closest thing to "its own width" a content-sized box can be measured by.
|
|
726
|
+
* A determinate block keeps its own root as the query container, exactly as
|
|
727
|
+
* before; an intrinsically sized container node stays a plain box for the
|
|
728
|
+
* same reason its blocks do.
|
|
729
|
+
*/
|
|
730
|
+
function containerTypeDeclarations(node, intrinsic) {
|
|
731
|
+
if (node.type === "block" || intrinsic) return {};
|
|
732
|
+
return { "container-type": "inline-size" };
|
|
733
|
+
}
|
|
734
|
+
function childRule(node, values) {
|
|
735
|
+
const body = Object.entries(values).map(([property, value]) => `${property}:${value};`).join("");
|
|
736
|
+
return body ? `.${layoutNodeClass(node.id)}>*{${body}}` : "";
|
|
737
|
+
}
|
|
738
|
+
function rule(node, values) {
|
|
739
|
+
const body = Object.entries(values).map(([property, value]) => `${property}:${value};`).join("");
|
|
740
|
+
return body ? `.${layoutNodeClass(node.id)}{${body}}` : "";
|
|
741
|
+
}
|
|
742
|
+
function walk(node, parent, host, visit) {
|
|
743
|
+
visit(node, parent, host);
|
|
744
|
+
if (node.type === "block") {
|
|
745
|
+
Object.values(node.slots ?? {}).flat().forEach((child) => walk(child, null, node, visit));
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
node.children.forEach((child) => walk(child, node, null, visit));
|
|
749
|
+
}
|
|
750
|
+
function has(object, key) {
|
|
751
|
+
return Object.prototype.hasOwnProperty.call(object, key);
|
|
752
|
+
}
|
|
753
|
+
function fail(path, code) {
|
|
754
|
+
throw new LayoutValidationError({
|
|
755
|
+
path,
|
|
756
|
+
code
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
function pointerToken(value) {
|
|
760
|
+
return value.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
761
|
+
}
|
|
762
|
+
function cssLength(value, path) {
|
|
763
|
+
if (typeof value !== "string") fail(path, "INVALID_TYPE");
|
|
764
|
+
const match = LENGTH.exec(value);
|
|
765
|
+
if (!match) fail(path, "INVALID_VALUE");
|
|
766
|
+
const magnitude = Number(`${match[1]}${match[2] ?? ""}`);
|
|
767
|
+
const unit = match[3];
|
|
768
|
+
if (magnitude > (unit === "px" ? 4096 : unit === "rem" ? 256 : 100)) fail(path, "INVALID_VALUE");
|
|
769
|
+
return `${String(magnitude)}${unit}`;
|
|
770
|
+
}
|
|
771
|
+
function sizingLength(value, path) {
|
|
772
|
+
return value === "auto" ? value : cssLength(value, path);
|
|
773
|
+
}
|
|
774
|
+
/** `width` only — a `SizingLength` plus `fill`/`fit-content`. Rejected on
|
|
775
|
+
* `minWidth`/`maxWidth`/`minHeight`, which stay plain `sizingLength`. */
|
|
776
|
+
function widthLength(value, path) {
|
|
777
|
+
if (value === "fill" || value === "fit-content") return value;
|
|
778
|
+
return sizingLength(value, path);
|
|
779
|
+
}
|
|
780
|
+
function booleanValue(value, path) {
|
|
781
|
+
if (typeof value !== "boolean") fail(path, "INVALID_TYPE");
|
|
782
|
+
return value;
|
|
783
|
+
}
|
|
784
|
+
function enumeration(allowed) {
|
|
785
|
+
return (value, path) => {
|
|
786
|
+
if (typeof value !== "string") fail(path, "INVALID_TYPE");
|
|
787
|
+
if (!allowed.includes(value)) fail(path, "INVALID_VALUE");
|
|
788
|
+
return value;
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
function gridInteger(allowAuto) {
|
|
792
|
+
return (value, path) => {
|
|
793
|
+
if (allowAuto && value === "auto") return value;
|
|
794
|
+
if (typeof value !== "number" || !Number.isInteger(value)) fail(path, "INVALID_TYPE");
|
|
795
|
+
if (value < 1 || value > 24) fail(path, "LIMIT_EXCEEDED");
|
|
796
|
+
return value;
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
function canonicalJson(value) {
|
|
800
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
801
|
+
if (typeof value === "object" && value !== null) return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`).join(",")}}`;
|
|
802
|
+
return JSON.stringify(value);
|
|
803
|
+
}
|
|
804
|
+
function sha256Hex(bytes) {
|
|
805
|
+
const constants = [
|
|
806
|
+
1116352408,
|
|
807
|
+
1899447441,
|
|
808
|
+
3049323471,
|
|
809
|
+
3921009573,
|
|
810
|
+
961987163,
|
|
811
|
+
1508970993,
|
|
812
|
+
2453635748,
|
|
813
|
+
2870763221,
|
|
814
|
+
3624381080,
|
|
815
|
+
310598401,
|
|
816
|
+
607225278,
|
|
817
|
+
1426881987,
|
|
818
|
+
1925078388,
|
|
819
|
+
2162078206,
|
|
820
|
+
2614888103,
|
|
821
|
+
3248222580,
|
|
822
|
+
3835390401,
|
|
823
|
+
4022224774,
|
|
824
|
+
264347078,
|
|
825
|
+
604807628,
|
|
826
|
+
770255983,
|
|
827
|
+
1249150122,
|
|
828
|
+
1555081692,
|
|
829
|
+
1996064986,
|
|
830
|
+
2554220882,
|
|
831
|
+
2821834349,
|
|
832
|
+
2952996808,
|
|
833
|
+
3210313671,
|
|
834
|
+
3336571891,
|
|
835
|
+
3584528711,
|
|
836
|
+
113926993,
|
|
837
|
+
338241895,
|
|
838
|
+
666307205,
|
|
839
|
+
773529912,
|
|
840
|
+
1294757372,
|
|
841
|
+
1396182291,
|
|
842
|
+
1695183700,
|
|
843
|
+
1986661051,
|
|
844
|
+
2177026350,
|
|
845
|
+
2456956037,
|
|
846
|
+
2730485921,
|
|
847
|
+
2820302411,
|
|
848
|
+
3259730800,
|
|
849
|
+
3345764771,
|
|
850
|
+
3516065817,
|
|
851
|
+
3600352804,
|
|
852
|
+
4094571909,
|
|
853
|
+
275423344,
|
|
854
|
+
430227734,
|
|
855
|
+
506948616,
|
|
856
|
+
659060556,
|
|
857
|
+
883997877,
|
|
858
|
+
958139571,
|
|
859
|
+
1322822218,
|
|
860
|
+
1537002063,
|
|
861
|
+
1747873779,
|
|
862
|
+
1955562222,
|
|
863
|
+
2024104815,
|
|
864
|
+
2227730452,
|
|
865
|
+
2361852424,
|
|
866
|
+
2428436474,
|
|
867
|
+
2756734187,
|
|
868
|
+
3204031479,
|
|
869
|
+
3329325298
|
|
870
|
+
];
|
|
871
|
+
const initial = [
|
|
872
|
+
1779033703,
|
|
873
|
+
3144134277,
|
|
874
|
+
1013904242,
|
|
875
|
+
2773480762,
|
|
876
|
+
1359893119,
|
|
877
|
+
2600822924,
|
|
878
|
+
528734635,
|
|
879
|
+
1541459225
|
|
880
|
+
];
|
|
881
|
+
const bitLength = bytes.length * 8;
|
|
882
|
+
const paddedLength = Math.ceil((bytes.length + 9) / 64) * 64;
|
|
883
|
+
const padded = new Uint8Array(paddedLength);
|
|
884
|
+
padded.set(bytes);
|
|
885
|
+
padded[bytes.length] = 128;
|
|
886
|
+
const view = new DataView(padded.buffer);
|
|
887
|
+
view.setUint32(paddedLength - 8, Math.floor(bitLength / 4294967296));
|
|
888
|
+
view.setUint32(paddedLength - 4, bitLength >>> 0);
|
|
889
|
+
const hash = initial.slice();
|
|
890
|
+
const words = /* @__PURE__ */ new Uint32Array(64);
|
|
891
|
+
for (let offset = 0; offset < paddedLength; offset += 64) {
|
|
892
|
+
for (let index = 0; index < 16; index += 1) words[index] = view.getUint32(offset + index * 4);
|
|
893
|
+
for (let index = 16; index < 64; index += 1) {
|
|
894
|
+
const x = words[index - 15];
|
|
895
|
+
const y = words[index - 2];
|
|
896
|
+
const s0 = rotate(x, 7) ^ rotate(x, 18) ^ x >>> 3;
|
|
897
|
+
const s1 = rotate(y, 17) ^ rotate(y, 19) ^ y >>> 10;
|
|
898
|
+
words[index] = words[index - 16] + s0 + words[index - 7] + s1 >>> 0;
|
|
899
|
+
}
|
|
900
|
+
let [a, b, c, d, e, f, g, h] = hash;
|
|
901
|
+
for (let index = 0; index < 64; index += 1) {
|
|
902
|
+
const sum1 = rotate(e, 6) ^ rotate(e, 11) ^ rotate(e, 25);
|
|
903
|
+
const choice = e & f ^ ~e & g;
|
|
904
|
+
const temp1 = h + sum1 + choice + constants[index] + words[index] >>> 0;
|
|
905
|
+
const temp2 = (rotate(a, 2) ^ rotate(a, 13) ^ rotate(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
|
|
906
|
+
h = g;
|
|
907
|
+
g = f;
|
|
908
|
+
f = e;
|
|
909
|
+
e = d + temp1 >>> 0;
|
|
910
|
+
d = c;
|
|
911
|
+
c = b;
|
|
912
|
+
b = a;
|
|
913
|
+
a = temp1 + temp2 >>> 0;
|
|
914
|
+
}
|
|
915
|
+
hash[0] = hash[0] + a >>> 0;
|
|
916
|
+
hash[1] = hash[1] + b >>> 0;
|
|
917
|
+
hash[2] = hash[2] + c >>> 0;
|
|
918
|
+
hash[3] = hash[3] + d >>> 0;
|
|
919
|
+
hash[4] = hash[4] + e >>> 0;
|
|
920
|
+
hash[5] = hash[5] + f >>> 0;
|
|
921
|
+
hash[6] = hash[6] + g >>> 0;
|
|
922
|
+
hash[7] = hash[7] + h >>> 0;
|
|
923
|
+
}
|
|
924
|
+
return hash.map((value) => value.toString(16).padStart(8, "0")).join("");
|
|
925
|
+
}
|
|
926
|
+
function rotate(value, bits) {
|
|
927
|
+
return value >>> bits | value << 32 - bits;
|
|
928
|
+
}
|
|
929
|
+
//#endregion
|
|
930
|
+
export { DEFAULT_LAYOUT_BREAKPOINTS, EDIT_MODE_HIDDEN_OPACITY, LAYOUT_BREAKPOINTS, LayoutValidationError, activeLayoutBreakpoint, createLayoutRenderModel, generateLayoutCss, hiddenLayoutBreakpoints, layoutNodeClass, layoutRenderNodeId, normalizeLayoutDocument, resolveLayoutBreakpoints, resolveLayoutDocument, validateLayoutDocument };
|