@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
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
//#region src/designTokens.ts
|
|
2
|
+
var DesignTokenValidationError = class extends Error {
|
|
3
|
+
path;
|
|
4
|
+
code;
|
|
5
|
+
constructor(path, code) {
|
|
6
|
+
super(`invalid design tokens at ${JSON.stringify(path)}: ${code}`);
|
|
7
|
+
this.path = path;
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.name = "DesignTokenValidationError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const TOKEN_ID = /^[a-z][a-z0-9-]{0,48}$/;
|
|
13
|
+
const LENGTH = /^(0|[1-9][0-9]*)(\.[0-9]{1,4})?(px|rem|%)$/;
|
|
14
|
+
const HEX = /^#[0-9a-f]{6}(?:[0-9a-f]{2})?$/;
|
|
15
|
+
const OKLCH = /^oklch\(([0-9]+(?:\.\d{1,4})?) ([0-9]+(?:\.\d{1,4})?) ([0-9]+(?:\.\d{1,4})?)(?: \/ ([0-9]+(?:\.\d{1,4})?))?\)$/;
|
|
16
|
+
const REQUIRED_CONTAINERS = [
|
|
17
|
+
"narrow",
|
|
18
|
+
"content",
|
|
19
|
+
"wide",
|
|
20
|
+
"full"
|
|
21
|
+
];
|
|
22
|
+
const BREAKPOINTS = [
|
|
23
|
+
"normal",
|
|
24
|
+
"tablet",
|
|
25
|
+
"mobile"
|
|
26
|
+
];
|
|
27
|
+
const MAX_COLORS = 100;
|
|
28
|
+
const MAX_CONTAINERS = 16;
|
|
29
|
+
const FORBIDDEN_KEYS = /* @__PURE__ */ new Set([
|
|
30
|
+
"__proto__",
|
|
31
|
+
"prototype",
|
|
32
|
+
"constructor"
|
|
33
|
+
]);
|
|
34
|
+
function normalizeThemeDesignTokens(value) {
|
|
35
|
+
const root = object(value, "");
|
|
36
|
+
rejectKeys(root, [
|
|
37
|
+
"colors",
|
|
38
|
+
"containers",
|
|
39
|
+
"allowCustomColors",
|
|
40
|
+
"fonts",
|
|
41
|
+
"spacing"
|
|
42
|
+
], "");
|
|
43
|
+
if (!own(root, "containers") && !own(root, "allowCustomColors")) return normalizeLegacyTokens(root);
|
|
44
|
+
rejectKeys(root, [
|
|
45
|
+
"colors",
|
|
46
|
+
"containers",
|
|
47
|
+
"allowCustomColors"
|
|
48
|
+
], "");
|
|
49
|
+
if (!own(root, "colors")) fail("/colors", "REQUIRED");
|
|
50
|
+
if (!own(root, "containers")) fail("/containers", "REQUIRED");
|
|
51
|
+
const colors = normalizeColorTokens(root.colors, "/colors");
|
|
52
|
+
const containers = normalizeContainerPresets(root.containers, "/containers");
|
|
53
|
+
const emptyCatalog = Object.keys(colors).length === 0 && Object.keys(containers).length === 0 && root.allowCustomColors !== true;
|
|
54
|
+
for (const id of REQUIRED_CONTAINERS) if (!emptyCatalog && !own(containers, id)) fail(`/containers/${id}`, "REQUIRED");
|
|
55
|
+
if (!emptyCatalog && containers.full.maxWidth !== "none") fail("/containers/full/maxWidth", "INVALID_VALUE");
|
|
56
|
+
const result = {
|
|
57
|
+
colors,
|
|
58
|
+
containers
|
|
59
|
+
};
|
|
60
|
+
if (own(root, "allowCustomColors")) {
|
|
61
|
+
if (typeof root.allowCustomColors !== "boolean") fail("/allowCustomColors", "INVALID_TYPE");
|
|
62
|
+
if (root.allowCustomColors) result.allowCustomColors = true;
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
function normalizeSiteDesignTokenOverrides(value, theme) {
|
|
67
|
+
const root = object(value, "");
|
|
68
|
+
rejectKeys(root, ["colors", "containers"], "");
|
|
69
|
+
if (!own(root, "colors")) fail("/colors", "REQUIRED");
|
|
70
|
+
if (!own(root, "containers")) fail("/containers", "REQUIRED");
|
|
71
|
+
const rawColors = record(root.colors, "/colors", MAX_COLORS);
|
|
72
|
+
const rawContainers = record(root.containers, "/containers", MAX_CONTAINERS);
|
|
73
|
+
const colors = Object.create(null);
|
|
74
|
+
const containers = Object.create(null);
|
|
75
|
+
for (const id of sortedKeys(rawColors)) {
|
|
76
|
+
tokenId(id, `/colors/${pointer(id)}`);
|
|
77
|
+
const definition = theme.colors[id];
|
|
78
|
+
if (!definition) fail(`/colors/${id}`, "TOKEN_NOT_FOUND");
|
|
79
|
+
if (definition.allowSiteOverride !== true) fail(`/colors/${id}`, "OVERRIDE_FORBIDDEN");
|
|
80
|
+
colors[id] = normalizeColorLiteral(rawColors[id], `/colors/${id}`);
|
|
81
|
+
}
|
|
82
|
+
for (const id of sortedKeys(rawContainers)) {
|
|
83
|
+
tokenId(id, `/containers/${pointer(id)}`);
|
|
84
|
+
const definition = theme.containers[id];
|
|
85
|
+
if (!definition) fail(`/containers/${id}`, "TOKEN_NOT_FOUND");
|
|
86
|
+
if (definition.allowSiteOverride !== true) fail(`/containers/${id}`, "OVERRIDE_FORBIDDEN");
|
|
87
|
+
containers[id] = normalizeContainerValue(rawContainers[id], `/containers/${id}`, false);
|
|
88
|
+
if (id === "full" && containers[id].maxWidth !== "none") fail("/containers/full/maxWidth", "INVALID_VALUE");
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
colors: plain(colors),
|
|
92
|
+
containers: plain(containers)
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function resolveDesignTokenCatalog(value) {
|
|
96
|
+
const root = object(value, "");
|
|
97
|
+
rejectKeys(root, [
|
|
98
|
+
"revision",
|
|
99
|
+
"theme",
|
|
100
|
+
"overrides",
|
|
101
|
+
"resolved"
|
|
102
|
+
], "");
|
|
103
|
+
for (const key of [
|
|
104
|
+
"revision",
|
|
105
|
+
"theme",
|
|
106
|
+
"overrides",
|
|
107
|
+
"resolved"
|
|
108
|
+
]) if (!own(root, key)) fail(`/${key}`, "REQUIRED");
|
|
109
|
+
if (typeof root.revision !== "number" || !Number.isSafeInteger(root.revision) || root.revision < 1) fail("/revision", "INVALID_VALUE");
|
|
110
|
+
const theme = normalizeThemeDesignTokens(root.theme);
|
|
111
|
+
const overrides = normalizeSiteDesignTokenOverrides(root.overrides, theme);
|
|
112
|
+
const resolved = applyNormalizedOverrides(theme, overrides);
|
|
113
|
+
if (canonicalJson(normalizeThemeDesignTokens(root.resolved)) !== canonicalJson(resolved)) fail("/resolved", "INVALID_VALUE");
|
|
114
|
+
return {
|
|
115
|
+
revision: root.revision,
|
|
116
|
+
theme,
|
|
117
|
+
overrides,
|
|
118
|
+
resolved
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function applyDesignTokenOverrides(themeValue, overridesValue) {
|
|
122
|
+
const theme = normalizeThemeDesignTokens(themeValue);
|
|
123
|
+
return applyNormalizedOverrides(theme, normalizeSiteDesignTokenOverrides(overridesValue, theme));
|
|
124
|
+
}
|
|
125
|
+
function applyNormalizedOverrides(theme, overrides) {
|
|
126
|
+
return {
|
|
127
|
+
colors: mapSorted(theme.colors, (id, token) => ({
|
|
128
|
+
...token,
|
|
129
|
+
value: overrides.colors[id] ?? token.value
|
|
130
|
+
})),
|
|
131
|
+
containers: mapSorted(theme.containers, (id, preset) => ({
|
|
132
|
+
...preset,
|
|
133
|
+
...overrides.containers[id]
|
|
134
|
+
})),
|
|
135
|
+
...theme.allowCustomColors === true ? { allowCustomColors: true } : {}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function normalizeColorSelection(value, tokens, opts = {}) {
|
|
139
|
+
if (typeof value === "string") {
|
|
140
|
+
if (!opts.allowCustomColors || tokens.allowCustomColors !== true) fail("", "OVERRIDE_FORBIDDEN");
|
|
141
|
+
return {
|
|
142
|
+
kind: "custom",
|
|
143
|
+
value: normalizeColorLiteral(value, "/value")
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const root = object(value, "");
|
|
147
|
+
if (root.kind === "token") {
|
|
148
|
+
rejectKeys(root, ["kind", "token"], "");
|
|
149
|
+
if (typeof root.token !== "string") fail("/token", "INVALID_TYPE");
|
|
150
|
+
tokenId(root.token, "/token");
|
|
151
|
+
if (!tokens.colors[root.token]) fail("/token", "TOKEN_NOT_FOUND");
|
|
152
|
+
return {
|
|
153
|
+
kind: "token",
|
|
154
|
+
token: root.token
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (root.kind === "custom") {
|
|
158
|
+
rejectKeys(root, ["kind", "value"], "");
|
|
159
|
+
if (!opts.allowCustomColors || tokens.allowCustomColors !== true) fail("", "OVERRIDE_FORBIDDEN");
|
|
160
|
+
return {
|
|
161
|
+
kind: "custom",
|
|
162
|
+
value: normalizeColorLiteral(root.value, "/value")
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
fail("/kind", "INVALID_VALUE");
|
|
166
|
+
}
|
|
167
|
+
function resolveColorSelection(selection, tokens) {
|
|
168
|
+
const normalized = normalizeColorSelection(selection, tokens, { allowCustomColors: true });
|
|
169
|
+
return normalized.kind === "token" ? `var(--eldra-color-${normalized.token})` : normalized.value;
|
|
170
|
+
}
|
|
171
|
+
function generateDesignTokenCss(value, opts = {}) {
|
|
172
|
+
const tokens = "resolved" in value ? value.resolved : value;
|
|
173
|
+
const scope = opts.scope ?? ":root";
|
|
174
|
+
if (scope !== ":root" && !/^\[data-eldra-theme="[a-z][a-z0-9-]{0,48}"\]$/.test(scope)) fail("/scope", "INVALID_VALUE");
|
|
175
|
+
const declarations = [];
|
|
176
|
+
for (const id of sortedKeys(tokens.colors)) declarations.push(`--eldra-color-${id}:${tokens.colors[id].value};`);
|
|
177
|
+
for (const id of sortedKeys(tokens.containers)) {
|
|
178
|
+
const preset = tokens.containers[id];
|
|
179
|
+
declarations.push(`--eldra-container-${id}-max-width:${preset.maxWidth === "none" ? "none" : preset.maxWidth};`);
|
|
180
|
+
for (const breakpoint of BREAKPOINTS) declarations.push(`--eldra-container-${id}-gutter-${breakpoint}:${responsiveValue(preset.gutter, breakpoint)};`);
|
|
181
|
+
}
|
|
182
|
+
return declarations.length === 0 ? "" : `${scope}{${declarations.join("")}}`;
|
|
183
|
+
}
|
|
184
|
+
function generateTailwindThemeCss(value) {
|
|
185
|
+
const declarations = sortedKeys(("resolved" in value ? value.resolved : value).colors).map((id) => `--color-${id}:var(--eldra-color-${id});`).join("");
|
|
186
|
+
return declarations === "" ? "" : `@theme static{${declarations}}`;
|
|
187
|
+
}
|
|
188
|
+
function designTokenRevisionHash(value) {
|
|
189
|
+
const tokens = "resolved" in value ? value.resolved : value;
|
|
190
|
+
return sha256Hex(new TextEncoder().encode(canonicalJson(tokens)));
|
|
191
|
+
}
|
|
192
|
+
function responsiveValue(value, breakpoint) {
|
|
193
|
+
if (breakpoint === "mobile") return value.mobile ?? value.tablet ?? value.normal;
|
|
194
|
+
if (breakpoint === "tablet") return value.tablet ?? value.normal;
|
|
195
|
+
return value.normal;
|
|
196
|
+
}
|
|
197
|
+
function normalizeLegacyTokens(root) {
|
|
198
|
+
const raw = own(root, "colors") ? record(root.colors, "/colors", MAX_COLORS) : {};
|
|
199
|
+
const colors = Object.create(null);
|
|
200
|
+
for (const id of sortedKeys(raw)) {
|
|
201
|
+
tokenId(id, `/colors/${pointer(id)}`);
|
|
202
|
+
colors[id] = {
|
|
203
|
+
label: titleFromId(id),
|
|
204
|
+
value: normalizeColorLiteral(raw[id], `/colors/${id}`)
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
if (own(root, "fonts")) stringRecord(root.fonts, "/fonts");
|
|
208
|
+
if (own(root, "spacing")) stringRecord(root.spacing, "/spacing");
|
|
209
|
+
return {
|
|
210
|
+
colors: plain(colors),
|
|
211
|
+
containers: {}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function normalizeColorTokens(value, path) {
|
|
215
|
+
const raw = record(value, path, MAX_COLORS);
|
|
216
|
+
const result = Object.create(null);
|
|
217
|
+
for (const id of sortedKeys(raw)) {
|
|
218
|
+
tokenId(id, `${path}/${pointer(id)}`);
|
|
219
|
+
const token = object(raw[id], `${path}/${id}`);
|
|
220
|
+
rejectKeys(token, [
|
|
221
|
+
"label",
|
|
222
|
+
"value",
|
|
223
|
+
"group",
|
|
224
|
+
"allowSiteOverride"
|
|
225
|
+
], `${path}/${id}`);
|
|
226
|
+
if (!own(token, "label")) fail(`${path}/${id}/label`, "REQUIRED");
|
|
227
|
+
if (!own(token, "value")) fail(`${path}/${id}/value`, "REQUIRED");
|
|
228
|
+
const normalized = {
|
|
229
|
+
label: plainText(token.label, 80, `${path}/${id}/label`),
|
|
230
|
+
value: normalizeColorLiteral(token.value, `${path}/${id}/value`)
|
|
231
|
+
};
|
|
232
|
+
if (own(token, "group")) normalized.group = plainText(token.group, 40, `${path}/${id}/group`);
|
|
233
|
+
if (own(token, "allowSiteOverride")) {
|
|
234
|
+
if (typeof token.allowSiteOverride !== "boolean") fail(`${path}/${id}/allowSiteOverride`, "INVALID_TYPE");
|
|
235
|
+
if (token.allowSiteOverride) normalized.allowSiteOverride = true;
|
|
236
|
+
}
|
|
237
|
+
result[id] = normalized;
|
|
238
|
+
}
|
|
239
|
+
return plain(result);
|
|
240
|
+
}
|
|
241
|
+
function normalizeContainerPresets(value, path) {
|
|
242
|
+
const raw = record(value, path, MAX_CONTAINERS);
|
|
243
|
+
const result = Object.create(null);
|
|
244
|
+
for (const id of sortedKeys(raw)) {
|
|
245
|
+
tokenId(id, `${path}/${pointer(id)}`);
|
|
246
|
+
result[id] = normalizeContainerValue(raw[id], `${path}/${id}`, true);
|
|
247
|
+
}
|
|
248
|
+
return plain(result);
|
|
249
|
+
}
|
|
250
|
+
function normalizeContainerValue(value, path, descriptor) {
|
|
251
|
+
const root = object(value, path);
|
|
252
|
+
rejectKeys(root, descriptor ? [
|
|
253
|
+
"label",
|
|
254
|
+
"maxWidth",
|
|
255
|
+
"gutter",
|
|
256
|
+
"allowSiteOverride"
|
|
257
|
+
] : ["maxWidth", "gutter"], path);
|
|
258
|
+
if (descriptor && !own(root, "label")) fail(`${path}/label`, "REQUIRED");
|
|
259
|
+
if (!own(root, "maxWidth")) fail(`${path}/maxWidth`, "REQUIRED");
|
|
260
|
+
if (!own(root, "gutter")) fail(`${path}/gutter`, "REQUIRED");
|
|
261
|
+
const common = {
|
|
262
|
+
maxWidth: root.maxWidth === "none" ? "none" : normalizeLength(root.maxWidth, `${path}/maxWidth`),
|
|
263
|
+
gutter: normalizeResponsiveLength(root.gutter, `${path}/gutter`)
|
|
264
|
+
};
|
|
265
|
+
if (!descriptor) return common;
|
|
266
|
+
const result = {
|
|
267
|
+
label: plainText(root.label, 80, `${path}/label`),
|
|
268
|
+
...common
|
|
269
|
+
};
|
|
270
|
+
if (own(root, "allowSiteOverride")) {
|
|
271
|
+
if (typeof root.allowSiteOverride !== "boolean") fail(`${path}/allowSiteOverride`, "INVALID_TYPE");
|
|
272
|
+
if (root.allowSiteOverride) result.allowSiteOverride = true;
|
|
273
|
+
}
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
function normalizeResponsiveLength(value, path) {
|
|
277
|
+
const root = object(value, path);
|
|
278
|
+
rejectKeys(root, [...BREAKPOINTS], path);
|
|
279
|
+
if (!own(root, "normal")) fail(`${path}/normal`, "REQUIRED");
|
|
280
|
+
const result = { normal: normalizeLength(root.normal, `${path}/normal`) };
|
|
281
|
+
if (own(root, "tablet")) result.tablet = normalizeLength(root.tablet, `${path}/tablet`);
|
|
282
|
+
if (own(root, "mobile")) result.mobile = normalizeLength(root.mobile, `${path}/mobile`);
|
|
283
|
+
return result;
|
|
284
|
+
}
|
|
285
|
+
function normalizeColorLiteral(value, path) {
|
|
286
|
+
if (typeof value !== "string") fail(path, "INVALID_TYPE");
|
|
287
|
+
if (HEX.test(value)) return value;
|
|
288
|
+
const match = OKLCH.exec(value);
|
|
289
|
+
if (!match) fail(path, "INVALID_VALUE");
|
|
290
|
+
const numbers = match.slice(1).filter((part) => part !== void 0).map(Number);
|
|
291
|
+
if (numbers.some((part) => !Number.isFinite(part))) fail(path, "INVALID_VALUE");
|
|
292
|
+
const [lightness, chroma, hue, alpha] = numbers;
|
|
293
|
+
if (lightness < 0 || lightness > 1 || chroma < 0 || chroma > .5 || hue < 0 || hue >= 360 || alpha !== void 0 && (alpha < 0 || alpha > 1)) fail(path, "INVALID_VALUE");
|
|
294
|
+
return `oklch(${`${canonicalNumber(lightness)} ${canonicalNumber(chroma)} ${canonicalNumber(hue)}`}${alpha === void 0 ? "" : ` / ${canonicalNumber(alpha)}`})`;
|
|
295
|
+
}
|
|
296
|
+
function normalizeLength(value, path) {
|
|
297
|
+
if (typeof value !== "string") fail(path, "INVALID_TYPE");
|
|
298
|
+
const match = LENGTH.exec(value);
|
|
299
|
+
if (!match) fail(path, "INVALID_VALUE");
|
|
300
|
+
const magnitude = Number(`${match[1]}${match[2] ?? ""}`);
|
|
301
|
+
const unit = match[3];
|
|
302
|
+
const maximum = unit === "px" ? 4096 : unit === "rem" ? 256 : 100;
|
|
303
|
+
if (!Number.isFinite(magnitude) || magnitude > maximum) fail(path, "INVALID_VALUE");
|
|
304
|
+
return `${canonicalNumber(magnitude)}${unit}`;
|
|
305
|
+
}
|
|
306
|
+
function plainText(value, max, path) {
|
|
307
|
+
if (typeof value !== "string") fail(path, "INVALID_TYPE");
|
|
308
|
+
const length = [...value].length;
|
|
309
|
+
const hasControl = [...value].some((character) => {
|
|
310
|
+
const codePoint = character.codePointAt(0);
|
|
311
|
+
return codePoint <= 31 || codePoint === 127;
|
|
312
|
+
});
|
|
313
|
+
if (length < 1 || length > max || hasControl) fail(path, "INVALID_VALUE");
|
|
314
|
+
return value;
|
|
315
|
+
}
|
|
316
|
+
function stringRecord(value, path) {
|
|
317
|
+
const root = record(value, path, 100);
|
|
318
|
+
for (const key of Object.keys(root)) if (typeof root[key] !== "string") fail(`${path}/${pointer(key)}`, "INVALID_TYPE");
|
|
319
|
+
}
|
|
320
|
+
function tokenId(value, path) {
|
|
321
|
+
if (!TOKEN_ID.test(value) || FORBIDDEN_KEYS.has(value)) fail(path, "INVALID_VALUE");
|
|
322
|
+
}
|
|
323
|
+
function object(value, path) {
|
|
324
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) fail(path, "INVALID_TYPE");
|
|
325
|
+
return value;
|
|
326
|
+
}
|
|
327
|
+
function record(value, path, max) {
|
|
328
|
+
const result = object(value, path);
|
|
329
|
+
const keys = Object.keys(result);
|
|
330
|
+
if (keys.length > max) fail(path, "LIMIT_EXCEEDED");
|
|
331
|
+
for (const key of keys) if (FORBIDDEN_KEYS.has(key)) fail(`${path}/${pointer(key)}`, "INVALID_VALUE");
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
334
|
+
function rejectKeys(value, allowed, path) {
|
|
335
|
+
const allowedSet = new Set(allowed);
|
|
336
|
+
const unknown = Object.keys(value).filter((key) => !allowedSet.has(key)).sort()[0];
|
|
337
|
+
if (unknown !== void 0) fail(`${path}/${pointer(unknown)}`, "UNKNOWN_KEY");
|
|
338
|
+
}
|
|
339
|
+
function mapSorted(source, map) {
|
|
340
|
+
return Object.fromEntries(sortedKeys(source).map((id) => [id, map(id, source[id])]));
|
|
341
|
+
}
|
|
342
|
+
function plain(value) {
|
|
343
|
+
return Object.fromEntries(sortedKeys(value).map((key) => [key, value[key]]));
|
|
344
|
+
}
|
|
345
|
+
function sortedKeys(value) {
|
|
346
|
+
return Object.keys(value).sort((a, b) => a.localeCompare(b));
|
|
347
|
+
}
|
|
348
|
+
function own(value, key) {
|
|
349
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
350
|
+
}
|
|
351
|
+
function pointer(value) {
|
|
352
|
+
return value.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
353
|
+
}
|
|
354
|
+
function canonicalNumber(value) {
|
|
355
|
+
return Object.is(value, -0) ? "0" : String(value);
|
|
356
|
+
}
|
|
357
|
+
function titleFromId(id) {
|
|
358
|
+
return id.split("-").map((part) => part ? part[0].toUpperCase() + part.slice(1) : "").join(" ");
|
|
359
|
+
}
|
|
360
|
+
function fail(path, code) {
|
|
361
|
+
throw new DesignTokenValidationError(path, code);
|
|
362
|
+
}
|
|
363
|
+
function canonicalJson(value) {
|
|
364
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
365
|
+
if (typeof value === "object" && value !== null) return `{${sortedKeys(value).map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`).join(",")}}`;
|
|
366
|
+
return JSON.stringify(value);
|
|
367
|
+
}
|
|
368
|
+
function sha256Hex(bytes) {
|
|
369
|
+
const constants = [
|
|
370
|
+
1116352408,
|
|
371
|
+
1899447441,
|
|
372
|
+
3049323471,
|
|
373
|
+
3921009573,
|
|
374
|
+
961987163,
|
|
375
|
+
1508970993,
|
|
376
|
+
2453635748,
|
|
377
|
+
2870763221,
|
|
378
|
+
3624381080,
|
|
379
|
+
310598401,
|
|
380
|
+
607225278,
|
|
381
|
+
1426881987,
|
|
382
|
+
1925078388,
|
|
383
|
+
2162078206,
|
|
384
|
+
2614888103,
|
|
385
|
+
3248222580,
|
|
386
|
+
3835390401,
|
|
387
|
+
4022224774,
|
|
388
|
+
264347078,
|
|
389
|
+
604807628,
|
|
390
|
+
770255983,
|
|
391
|
+
1249150122,
|
|
392
|
+
1555081692,
|
|
393
|
+
1996064986,
|
|
394
|
+
2554220882,
|
|
395
|
+
2821834349,
|
|
396
|
+
2952996808,
|
|
397
|
+
3210313671,
|
|
398
|
+
3336571891,
|
|
399
|
+
3584528711,
|
|
400
|
+
113926993,
|
|
401
|
+
338241895,
|
|
402
|
+
666307205,
|
|
403
|
+
773529912,
|
|
404
|
+
1294757372,
|
|
405
|
+
1396182291,
|
|
406
|
+
1695183700,
|
|
407
|
+
1986661051,
|
|
408
|
+
2177026350,
|
|
409
|
+
2456956037,
|
|
410
|
+
2730485921,
|
|
411
|
+
2820302411,
|
|
412
|
+
3259730800,
|
|
413
|
+
3345764771,
|
|
414
|
+
3516065817,
|
|
415
|
+
3600352804,
|
|
416
|
+
4094571909,
|
|
417
|
+
275423344,
|
|
418
|
+
430227734,
|
|
419
|
+
506948616,
|
|
420
|
+
41191284,
|
|
421
|
+
883997877,
|
|
422
|
+
958139571,
|
|
423
|
+
1322822218,
|
|
424
|
+
1537002063,
|
|
425
|
+
1747873779,
|
|
426
|
+
1955562222,
|
|
427
|
+
2024104815,
|
|
428
|
+
2227730452,
|
|
429
|
+
2361852424,
|
|
430
|
+
2428436474,
|
|
431
|
+
2756734187,
|
|
432
|
+
3204031479,
|
|
433
|
+
3329325298
|
|
434
|
+
];
|
|
435
|
+
const hash = [
|
|
436
|
+
1779033703,
|
|
437
|
+
3144134277,
|
|
438
|
+
1013904242,
|
|
439
|
+
2773480762,
|
|
440
|
+
1359893119,
|
|
441
|
+
2600822924,
|
|
442
|
+
528734635,
|
|
443
|
+
1541459225
|
|
444
|
+
];
|
|
445
|
+
const bitLength = bytes.length * 8;
|
|
446
|
+
const paddedLength = Math.ceil((bytes.length + 9) / 64) * 64;
|
|
447
|
+
const padded = new Uint8Array(paddedLength);
|
|
448
|
+
padded.set(bytes);
|
|
449
|
+
padded[bytes.length] = 128;
|
|
450
|
+
const view = new DataView(padded.buffer);
|
|
451
|
+
view.setUint32(paddedLength - 8, Math.floor(bitLength / 4294967296));
|
|
452
|
+
view.setUint32(paddedLength - 4, bitLength >>> 0);
|
|
453
|
+
const words = /* @__PURE__ */ new Uint32Array(64);
|
|
454
|
+
const rotate = (value, bits) => value >>> bits | value << 32 - bits;
|
|
455
|
+
for (let offset = 0; offset < paddedLength; offset += 64) {
|
|
456
|
+
for (let index = 0; index < 16; index += 1) words[index] = view.getUint32(offset + index * 4);
|
|
457
|
+
for (let index = 16; index < 64; index += 1) {
|
|
458
|
+
const x = words[index - 15], y = words[index - 2];
|
|
459
|
+
words[index] = words[index - 16] + (rotate(x, 7) ^ rotate(x, 18) ^ x >>> 3) + words[index - 7] + (rotate(y, 17) ^ rotate(y, 19) ^ y >>> 10) >>> 0;
|
|
460
|
+
}
|
|
461
|
+
let [a, b, c, d, e, f, g, h] = hash;
|
|
462
|
+
for (let index = 0; index < 64; index += 1) {
|
|
463
|
+
const t1 = h + (rotate(e, 6) ^ rotate(e, 11) ^ rotate(e, 25)) + (e & f ^ ~e & g) + constants[index] + words[index] >>> 0;
|
|
464
|
+
const t2 = (rotate(a, 2) ^ rotate(a, 13) ^ rotate(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
|
|
465
|
+
h = g;
|
|
466
|
+
g = f;
|
|
467
|
+
f = e;
|
|
468
|
+
e = d + t1 >>> 0;
|
|
469
|
+
d = c;
|
|
470
|
+
c = b;
|
|
471
|
+
b = a;
|
|
472
|
+
a = t1 + t2 >>> 0;
|
|
473
|
+
}
|
|
474
|
+
hash[0] = hash[0] + a >>> 0;
|
|
475
|
+
hash[1] = hash[1] + b >>> 0;
|
|
476
|
+
hash[2] = hash[2] + c >>> 0;
|
|
477
|
+
hash[3] = hash[3] + d >>> 0;
|
|
478
|
+
hash[4] = hash[4] + e >>> 0;
|
|
479
|
+
hash[5] = hash[5] + f >>> 0;
|
|
480
|
+
hash[6] = hash[6] + g >>> 0;
|
|
481
|
+
hash[7] = hash[7] + h >>> 0;
|
|
482
|
+
}
|
|
483
|
+
return hash.map((value) => value.toString(16).padStart(8, "0")).join("");
|
|
484
|
+
}
|
|
485
|
+
//#endregion
|
|
486
|
+
export { DesignTokenValidationError, applyDesignTokenOverrides, designTokenRevisionHash, generateDesignTokenCss, generateTailwindThemeCss, normalizeColorSelection, normalizeSiteDesignTokenOverrides, normalizeThemeDesignTokens, resolveColorSelection, resolveDesignTokenCatalog, responsiveValue };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as buildDynamicRoutePath, c as parseDynamicRoutePattern, i as RouteTemplateLike, l as resolveRoute, n as MAX_DYNAMIC_ROUTE_PATTERN_BYTES, o as catalogRouteTarget, r as ParsedDynamicRoutePattern, s as matchDynamicRoutePattern, t as DynamicRouteResolution } from "./dynamicRoute-pRTBoYT6.js";
|
|
2
|
+
export { DynamicRouteResolution, MAX_DYNAMIC_ROUTE_PATTERN_BYTES, ParsedDynamicRoutePattern, RouteTemplateLike, buildDynamicRoutePath, catalogRouteTarget, matchDynamicRoutePattern, parseDynamicRoutePattern, resolveRoute };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import "./stega.js";
|
|
2
|
+
import { a as parseDynamicRoutePattern, i as matchDynamicRoutePattern, n as buildDynamicRoutePath, o as resolveRoute, r as catalogRouteTarget, t as MAX_DYNAMIC_ROUTE_PATTERN_BYTES } from "./dynamicRoute-CxXY-Y_8.js";
|
|
3
|
+
export { MAX_DYNAMIC_ROUTE_PATTERN_BYTES, buildDynamicRoutePath, catalogRouteTarget, matchDynamicRoutePattern, parseDynamicRoutePattern, resolveRoute };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { stripStega } from "./stega.js";
|
|
2
|
+
//#region src/pagePath.ts
|
|
3
|
+
/** contracts §6: path = "/" + ancestor slugs (parent-first) + own slug.
|
|
4
|
+
* A no-parent page with slug "home" contributes nothing — so home itself is "/"
|
|
5
|
+
* and children of home are "/<child>". Parent may be an id string or a resolved doc. */
|
|
6
|
+
function resolvePagePath(page, allPages) {
|
|
7
|
+
const byId = new Map(allPages.map((p) => [p.id, p]));
|
|
8
|
+
const slugs = [];
|
|
9
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10
|
+
let current = page;
|
|
11
|
+
while (current !== void 0) {
|
|
12
|
+
if (seen.has(current.id)) throw new Error(`resolvePagePath: parent cycle at page ${current.id}`);
|
|
13
|
+
seen.add(current.id);
|
|
14
|
+
const rawSlug = current.data.slug;
|
|
15
|
+
const slug = typeof rawSlug === "string" ? stripStega(rawSlug).trim() : "";
|
|
16
|
+
const parentId = parentIdOf(current.data.parent);
|
|
17
|
+
if (!(parentId === null && slug === "home") && slug !== "") slugs.unshift(slug);
|
|
18
|
+
current = parentId !== null ? byId.get(parentId) : void 0;
|
|
19
|
+
}
|
|
20
|
+
return "/" + slugs.join("/");
|
|
21
|
+
}
|
|
22
|
+
function parentIdOf(parent) {
|
|
23
|
+
if (typeof parent === "string" && parent !== "") return parent;
|
|
24
|
+
if (typeof parent === "object" && parent !== null && typeof parent.id === "string") return parent.id;
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/dynamicRoute.ts
|
|
29
|
+
const MAX_DYNAMIC_ROUTE_PATTERN_BYTES = 255;
|
|
30
|
+
function parseDynamicRoutePattern(value) {
|
|
31
|
+
if (typeof value !== "string" || value === "" || new TextEncoder().encode(value).byteLength > 255 || !value.startsWith("/") || value === "/" || value.endsWith("/") || value.includes("//") || /[?#\\]/.test(value)) return null;
|
|
32
|
+
const segments = value.slice(1).split("/");
|
|
33
|
+
const parameter = segments.at(-1) ?? "";
|
|
34
|
+
const prefixSegments = segments.slice(0, -1);
|
|
35
|
+
if (prefixSegments.some((segment) => segment === "" || /[:*]/.test(segment)) || !parameter.startsWith(":") || parameter.slice(1).includes(":")) return null;
|
|
36
|
+
const catchAll = parameter.endsWith("*");
|
|
37
|
+
const paramName = catchAll ? parameter.slice(1, -1) : parameter.slice(1);
|
|
38
|
+
if (!/^[a-z][a-zA-Z0-9]{0,48}$/.test(paramName)) return null;
|
|
39
|
+
return {
|
|
40
|
+
value,
|
|
41
|
+
prefixSegments,
|
|
42
|
+
paramName,
|
|
43
|
+
catchAll
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function matchDynamicRoutePattern(pattern, path) {
|
|
47
|
+
const parsed = parseDynamicRoutePattern(pattern);
|
|
48
|
+
const segments = decodeRequestPath(path);
|
|
49
|
+
if (parsed === null || segments === null) return null;
|
|
50
|
+
const prefixLength = parsed.prefixSegments.length;
|
|
51
|
+
if (parsed.catchAll ? segments.length < prefixLength + 1 : segments.length !== prefixLength + 1) return null;
|
|
52
|
+
if (parsed.prefixSegments.some((segment, index) => segment !== segments[index])) return null;
|
|
53
|
+
const rest = segments.slice(prefixLength);
|
|
54
|
+
const value = parsed.catchAll ? rest.join("/") : rest[0] ?? "";
|
|
55
|
+
return value === "" ? null : { [parsed.paramName]: value };
|
|
56
|
+
}
|
|
57
|
+
function resolveRoute(path, input) {
|
|
58
|
+
const segments = decodeRequestPath(path);
|
|
59
|
+
if (segments === null) return null;
|
|
60
|
+
const normalizedPath = "/" + segments.join("/");
|
|
61
|
+
const staticEntry = input.pages.find((page) => resolvePagePath(page, [...input.pages]) === normalizedPath);
|
|
62
|
+
if (staticEntry !== void 0) return {
|
|
63
|
+
kind: "static",
|
|
64
|
+
entry: staticEntry
|
|
65
|
+
};
|
|
66
|
+
for (const template of input.templates) {
|
|
67
|
+
const pattern = stripTemplateString(template.data.routePattern);
|
|
68
|
+
const slugField = stripTemplateString(template.data.slugField);
|
|
69
|
+
const parsed = parseDynamicRoutePattern(pattern);
|
|
70
|
+
if (parsed === null || parsed.paramName !== slugField) continue;
|
|
71
|
+
const params = matchDynamicRoutePattern(pattern, normalizedPath);
|
|
72
|
+
if (params !== null) return {
|
|
73
|
+
kind: "template",
|
|
74
|
+
template,
|
|
75
|
+
params
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
function buildDynamicRoutePath(pattern, slugValue) {
|
|
81
|
+
const parsed = parseDynamicRoutePattern(pattern);
|
|
82
|
+
const value = stripTemplateString(slugValue);
|
|
83
|
+
if (parsed === null || value === "" || /[\\?#]/.test(value) || /[\p{Cc}\p{Cf}]/u.test(value)) return null;
|
|
84
|
+
if (!parsed.catchAll) {
|
|
85
|
+
if (value.includes("/")) return null;
|
|
86
|
+
return `/${[...parsed.prefixSegments, encodeURIComponent(value)].join("/")}`;
|
|
87
|
+
}
|
|
88
|
+
const rest = value.split("/");
|
|
89
|
+
if (rest.some((segment) => segment === "")) return null;
|
|
90
|
+
return `/${[...parsed.prefixSegments, ...rest.map((s) => encodeURIComponent(s))].join("/")}`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Recognises a catalog route template's schema id (e.g. a route template's
|
|
94
|
+
* `data.schemaApiId`) as a product, collection or category target,
|
|
95
|
+
* stega-stripped and matched exactly. Anything else — including a related but
|
|
96
|
+
* different id, or a non-string — returns null.
|
|
97
|
+
*/
|
|
98
|
+
function catalogRouteTarget(schemaApiId) {
|
|
99
|
+
const value = stripTemplateString(schemaApiId);
|
|
100
|
+
if (value === "catalog:product") return "product";
|
|
101
|
+
if (value === "catalog:collection") return "collection";
|
|
102
|
+
if (value === "catalog:category") return "category";
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
function decodeRequestPath(path) {
|
|
106
|
+
if (typeof path !== "string" || !path.startsWith("/") || path.includes("//") || /[?#\\]/.test(path)) return null;
|
|
107
|
+
const canonicalPath = path !== "/" && path.endsWith("/") ? path.slice(0, -1) : path;
|
|
108
|
+
if (canonicalPath === "/") return [];
|
|
109
|
+
const rawSegments = canonicalPath.slice(1).split("/");
|
|
110
|
+
const segments = [];
|
|
111
|
+
try {
|
|
112
|
+
for (const raw of rawSegments) {
|
|
113
|
+
const decoded = decodeURIComponent(raw);
|
|
114
|
+
if (decoded === "" || /[/\\]/.test(decoded) || /[\p{Cc}\p{Cf}]/u.test(decoded)) return null;
|
|
115
|
+
segments.push(decoded);
|
|
116
|
+
}
|
|
117
|
+
} catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
return segments;
|
|
121
|
+
}
|
|
122
|
+
function stripTemplateString(value) {
|
|
123
|
+
return typeof value === "string" ? stripStega(value).trim() : "";
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { parseDynamicRoutePattern as a, matchDynamicRoutePattern as i, buildDynamicRoutePath as n, resolveRoute as o, catalogRouteTarget as r, resolvePagePath as s, MAX_DYNAMIC_ROUTE_PATTERN_BYTES as t };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//#region src/pagePath.d.ts
|
|
2
|
+
interface PageLike {
|
|
3
|
+
id: string;
|
|
4
|
+
data: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
/** contracts §6: path = "/" + ancestor slugs (parent-first) + own slug.
|
|
7
|
+
* A no-parent page with slug "home" contributes nothing — so home itself is "/"
|
|
8
|
+
* and children of home are "/<child>". Parent may be an id string or a resolved doc. */
|
|
9
|
+
declare function resolvePagePath(page: PageLike, allPages: PageLike[]): string;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/dynamicRoute.d.ts
|
|
12
|
+
declare const MAX_DYNAMIC_ROUTE_PATTERN_BYTES = 255;
|
|
13
|
+
interface ParsedDynamicRoutePattern {
|
|
14
|
+
value: string;
|
|
15
|
+
prefixSegments: string[];
|
|
16
|
+
paramName: string;
|
|
17
|
+
/**
|
|
18
|
+
* A trailing catch-all parameter (`/categories/:path*`): it matches **one or
|
|
19
|
+
* more** segments rather than exactly one, and the parameter's value is the
|
|
20
|
+
* remainder joined with `/` and no leading slash.
|
|
21
|
+
*
|
|
22
|
+
* `*` is forbidden everywhere else in a pattern, which is what keeps this the
|
|
23
|
+
* only wildcard a route template can carry: one, last, immediately after the
|
|
24
|
+
* parameter name.
|
|
25
|
+
*/
|
|
26
|
+
catchAll: boolean;
|
|
27
|
+
}
|
|
28
|
+
interface RouteTemplateLike {
|
|
29
|
+
id: string;
|
|
30
|
+
data: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
type DynamicRouteResolution<P extends PageLike, T extends RouteTemplateLike> = {
|
|
33
|
+
kind: 'static';
|
|
34
|
+
entry: P;
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'template';
|
|
37
|
+
template: T;
|
|
38
|
+
params: Record<string, string>;
|
|
39
|
+
} | null;
|
|
40
|
+
declare function parseDynamicRoutePattern(value: unknown): ParsedDynamicRoutePattern | null;
|
|
41
|
+
declare function matchDynamicRoutePattern(pattern: unknown, path: unknown): Record<string, string> | null;
|
|
42
|
+
declare function resolveRoute<P extends PageLike, T extends RouteTemplateLike>(path: unknown, input: {
|
|
43
|
+
pages: readonly P[];
|
|
44
|
+
templates: readonly T[];
|
|
45
|
+
}): DynamicRouteResolution<P, T>;
|
|
46
|
+
declare function buildDynamicRoutePath(pattern: unknown, slugValue: unknown): string | null;
|
|
47
|
+
/**
|
|
48
|
+
* Recognises a catalog route template's schema id (e.g. a route template's
|
|
49
|
+
* `data.schemaApiId`) as a product, collection or category target,
|
|
50
|
+
* stega-stripped and matched exactly. Anything else — including a related but
|
|
51
|
+
* different id, or a non-string — returns null.
|
|
52
|
+
*/
|
|
53
|
+
declare function catalogRouteTarget(schemaApiId: unknown): 'product' | 'collection' | 'category' | null;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { buildDynamicRoutePath as a, parseDynamicRoutePattern as c, resolvePagePath as d, RouteTemplateLike as i, resolveRoute as l, MAX_DYNAMIC_ROUTE_PATTERN_BYTES as n, catalogRouteTarget as o, ParsedDynamicRoutePattern as r, matchDynamicRoutePattern as s, DynamicRouteResolution as t, PageLike as u };
|