@bettercms-ai/types 1.68.0 → 1.69.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/index.d.ts +498 -1
- package/dist/index.js +471 -80
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -64,14 +64,14 @@ function hiddenEverywhere(item) {
|
|
|
64
64
|
const raw = style && typeof style === "object" ? style.hideOn : void 0;
|
|
65
65
|
return Array.isArray(raw) && raw.includes("mobile") && raw.includes("tablet") && raw.includes("desktop");
|
|
66
66
|
}
|
|
67
|
-
function mapSame(
|
|
67
|
+
function mapSame(list2, fn) {
|
|
68
68
|
let changed = false;
|
|
69
|
-
const out =
|
|
69
|
+
const out = list2.map((item) => {
|
|
70
70
|
const next = fn(item);
|
|
71
71
|
if (next !== item) changed = true;
|
|
72
72
|
return next;
|
|
73
73
|
});
|
|
74
|
-
return changed ? out :
|
|
74
|
+
return changed ? out : list2;
|
|
75
75
|
}
|
|
76
76
|
function withVisibleChildren(block, now) {
|
|
77
77
|
const p = block.props ?? {};
|
|
@@ -428,8 +428,8 @@ function sectionIdentityAttrs(style) {
|
|
|
428
428
|
const out = {};
|
|
429
429
|
if (typeof s.anchor === "string" && SECTION_ANCHOR.test(s.anchor)) out.id = s.anchor;
|
|
430
430
|
if (typeof s.cssClass === "string" && SECTION_CSS_CLASS.test(s.cssClass)) {
|
|
431
|
-
const
|
|
432
|
-
if (
|
|
431
|
+
const names2 = s.cssClass.split(" ").filter(Boolean);
|
|
432
|
+
if (names2.length) out.className = names2.join(" ");
|
|
433
433
|
}
|
|
434
434
|
return out;
|
|
435
435
|
}
|
|
@@ -692,9 +692,9 @@ var SLOT_MAX_ITEMS = 12;
|
|
|
692
692
|
var SLOT_ITEMS_CAP = 50;
|
|
693
693
|
var LIST_ITEMS_CAP = 500;
|
|
694
694
|
function slotItems(value) {
|
|
695
|
-
const
|
|
695
|
+
const list2 = Array.isArray(value) ? value : [value];
|
|
696
696
|
const out = [];
|
|
697
|
-
for (const item of
|
|
697
|
+
for (const item of list2) {
|
|
698
698
|
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
|
699
699
|
const o = item;
|
|
700
700
|
if (typeof o.componentId === "string" && o.componentId !== "") out.push(item);
|
|
@@ -3421,9 +3421,9 @@ function keyWords(key) {
|
|
|
3421
3421
|
const leaf = key.split(".").pop() ?? "";
|
|
3422
3422
|
return leaf.replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").split(/[\s_-]+/).filter(Boolean).map((word) => word.toLowerCase());
|
|
3423
3423
|
}
|
|
3424
|
-
function roleFromWords(
|
|
3425
|
-
const type = (
|
|
3426
|
-
const value =
|
|
3424
|
+
function roleFromWords(candidate2, words) {
|
|
3425
|
+
const type = (candidate2.type ?? "").toLowerCase();
|
|
3426
|
+
const value = candidate2.value;
|
|
3427
3427
|
if (!(value === void 0 || value === null || typeof value === "string")) return null;
|
|
3428
3428
|
if (!words.length) return null;
|
|
3429
3429
|
const last = words[words.length - 1];
|
|
@@ -3432,18 +3432,18 @@ function roleFromWords(candidate, words) {
|
|
|
3432
3432
|
if (LINK_TYPES.has(type)) return { role: "link", stems: LINK_ROLES.has(last) ? [stem] : [stem, full] };
|
|
3433
3433
|
if (!TEXT_TYPES.has(type)) return null;
|
|
3434
3434
|
if (LINK_ROLES.has(last)) {
|
|
3435
|
-
if (MEDIA.test(
|
|
3435
|
+
if (MEDIA.test(candidate2.key) || MEDIA.test(candidate2.label ?? "")) return null;
|
|
3436
3436
|
return { role: "link", stems: [stem] };
|
|
3437
3437
|
}
|
|
3438
3438
|
if (TEXT_ROLES.has(last)) return { role: "text", stems: BUTTON_NOUNS.has(last) ? [stem, full] : [stem] };
|
|
3439
3439
|
return null;
|
|
3440
3440
|
}
|
|
3441
|
-
function candidateRole(
|
|
3442
|
-
const fromKey = roleFromWords(
|
|
3441
|
+
function candidateRole(candidate2) {
|
|
3442
|
+
const fromKey = roleFromWords(candidate2, keyWords(candidate2.key));
|
|
3443
3443
|
if (fromKey) return fromKey;
|
|
3444
|
-
const label =
|
|
3444
|
+
const label = candidate2.label?.trim();
|
|
3445
3445
|
if (!label) return null;
|
|
3446
|
-
const fromLabel = roleFromWords(
|
|
3446
|
+
const fromLabel = roleFromWords(candidate2, keyWords(label.replace(/\s+/g, "_")));
|
|
3447
3447
|
return fromLabel ? { role: fromLabel.role, stems: fromLabel.stems.map((stem) => `label:${stem}`) } : null;
|
|
3448
3448
|
}
|
|
3449
3449
|
var TAG_SEGMENTS = /* @__PURE__ */ new Set(["a", "span", "button", "div", "strong"]);
|
|
@@ -3484,9 +3484,9 @@ function derivedPairs(candidates) {
|
|
|
3484
3484
|
}
|
|
3485
3485
|
function buttonLinkPairs(candidates) {
|
|
3486
3486
|
const derived = derivedPairs(candidates);
|
|
3487
|
-
const roles = candidates.map((
|
|
3487
|
+
const roles = candidates.map((candidate2, index) => {
|
|
3488
3488
|
const half = derived.get(index);
|
|
3489
|
-
return half ? { role: half.role, stems: [`derived:${half.pair}`] } : candidateRole(
|
|
3489
|
+
return half ? { role: half.role, stems: [`derived:${half.pair}`] } : candidateRole(candidate2);
|
|
3490
3490
|
});
|
|
3491
3491
|
const byStem = /* @__PURE__ */ new Map();
|
|
3492
3492
|
roles.forEach((role, index) => {
|
|
@@ -3521,8 +3521,8 @@ function buttonLinkPairs(candidates) {
|
|
|
3521
3521
|
var LINK_TYPES2 = /* @__PURE__ */ new Set(["link", "url"]);
|
|
3522
3522
|
var nameOf = (s) => s.name ?? s.key;
|
|
3523
3523
|
function rulePartnerOf(labelKey, siblings) {
|
|
3524
|
-
const
|
|
3525
|
-
for (const n of
|
|
3524
|
+
const names2 = labelKey === "label" ? ["label-href", "href", "url", "link"] : [`${labelKey}-href`];
|
|
3525
|
+
for (const n of names2) {
|
|
3526
3526
|
const s = siblings.find((f) => nameOf(f) === n);
|
|
3527
3527
|
if (s && LINK_TYPES2.has(s.type ?? "")) return n;
|
|
3528
3528
|
}
|
|
@@ -3605,7 +3605,7 @@ var LOOK_VALUE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
|
3605
3605
|
function buttonSiteLookOf(value) {
|
|
3606
3606
|
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
3607
3607
|
const v = value;
|
|
3608
|
-
const tokens = (
|
|
3608
|
+
const tokens = (list2) => Array.isArray(list2) ? list2.filter((c) => typeof c === "string" && SITE_CLASS.test(c)) : [];
|
|
3609
3609
|
const variant = v.attrs?.["data-variant"];
|
|
3610
3610
|
const classes = tokens(v.classes);
|
|
3611
3611
|
const also = tokens(v.also);
|
|
@@ -3630,8 +3630,8 @@ function isButtonLookValue(value) {
|
|
|
3630
3630
|
function buttonIconOf(value) {
|
|
3631
3631
|
return typeof value === "string" && DOCK_ICON_NAME_SET.has(value) ? value : null;
|
|
3632
3632
|
}
|
|
3633
|
-
function buttonIconSvg(
|
|
3634
|
-
return iconSvg(
|
|
3633
|
+
function buttonIconSvg(name2, cls) {
|
|
3634
|
+
return iconSvg(name2, cls);
|
|
3635
3635
|
}
|
|
3636
3636
|
var BUTTON_SIZES = ["sm", "md", "lg"];
|
|
3637
3637
|
function anchorTargetRel(newTab, rel) {
|
|
@@ -3756,9 +3756,9 @@ function buttonBlockProps(value) {
|
|
|
3756
3756
|
}
|
|
3757
3757
|
function soleButtonId(blockJson) {
|
|
3758
3758
|
const ids = [];
|
|
3759
|
-
const walk = (
|
|
3760
|
-
if (!Array.isArray(
|
|
3761
|
-
for (const b of
|
|
3759
|
+
const walk = (list2) => {
|
|
3760
|
+
if (!Array.isArray(list2)) return;
|
|
3761
|
+
for (const b of list2) {
|
|
3762
3762
|
if (b?.type === "button" && typeof b.id === "string") ids.push(b.id);
|
|
3763
3763
|
walk(b?.props?.children);
|
|
3764
3764
|
if (Array.isArray(b?.props?.columns)) for (const column of b.props.columns) walk(column);
|
|
@@ -3811,9 +3811,9 @@ function buttonValueOfInstance(def, overrides) {
|
|
|
3811
3811
|
const blockId = soleButtonId(def.blockJson);
|
|
3812
3812
|
if (!blockId) return null;
|
|
3813
3813
|
const found = [];
|
|
3814
|
-
const walk = (
|
|
3815
|
-
if (!Array.isArray(
|
|
3816
|
-
for (const b of
|
|
3814
|
+
const walk = (list2) => {
|
|
3815
|
+
if (!Array.isArray(list2)) return;
|
|
3816
|
+
for (const b of list2) {
|
|
3817
3817
|
if (b?.id === blockId) found.push(b);
|
|
3818
3818
|
walk(b?.props?.children);
|
|
3819
3819
|
if (Array.isArray(b?.props?.columns)) for (const column of b.props.columns) walk(column);
|
|
@@ -3890,53 +3890,53 @@ function tableValueProblems(value, opts = {}) {
|
|
|
3890
3890
|
const unknownKeys = (o, allowed, at) => {
|
|
3891
3891
|
for (const k of Object.keys(o)) if (!allowed.has(k)) bad([...at, k], `unknown key "${k}" (${[...allowed].join(", ")})`);
|
|
3892
3892
|
};
|
|
3893
|
-
const
|
|
3893
|
+
const str2 = (v, at, what, max, required = false) => {
|
|
3894
3894
|
if (v === void 0 && !required) return;
|
|
3895
3895
|
if (typeof v !== "string") bad(at, `${what} must be a string`);
|
|
3896
3896
|
else if (v.length > max) bad(at, `${what} is ${v.length} characters; at most ${max}`, "table_limit_exceeded");
|
|
3897
3897
|
};
|
|
3898
|
-
const
|
|
3898
|
+
const bool2 = (v, at, what) => {
|
|
3899
3899
|
if (v !== void 0 && typeof v !== "boolean") bad(at, `${what} must be true or false`);
|
|
3900
3900
|
};
|
|
3901
|
-
const
|
|
3901
|
+
const oneOf2 = (v, at, what, allowed) => {
|
|
3902
3902
|
if (v !== void 0 && !allowed.includes(v)) bad(at, `${what} must be one of ${allowed.join(", ")}`);
|
|
3903
3903
|
};
|
|
3904
3904
|
unknownKeys(t, TOP_KEYS, []);
|
|
3905
|
-
|
|
3906
|
-
|
|
3905
|
+
str2(t.id, ["id"], "id", TABLE_LIMITS.keyChars);
|
|
3906
|
+
str2(t.caption, ["caption"], "caption", TABLE_LIMITS.captionChars, true);
|
|
3907
3907
|
if (typeof t.caption === "string" && t.caption.trim() === "" && opts.requireCaption !== false) {
|
|
3908
3908
|
bad(["caption"], "give the table a caption that says what it compares (it names the table for screen readers and search)", "table_caption_required");
|
|
3909
3909
|
}
|
|
3910
|
-
|
|
3910
|
+
str2(t.notes, ["notes"], "notes", TABLE_LIMITS.notesChars);
|
|
3911
3911
|
if (t.notes !== void 0 && opts.allowNote === false && typeof t.notes === "string" && t.notes.trim() !== "") bad(["notes"], "this table takes no note (config.allowNote is false)");
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3912
|
+
bool2(t.headerRow, ["headerRow"], "headerRow");
|
|
3913
|
+
bool2(t.headerColumn, ["headerColumn"], "headerColumn");
|
|
3914
|
+
bool2(t.filterable, ["filterable"], "filterable");
|
|
3915
3915
|
if (t.design !== void 0) {
|
|
3916
3916
|
if (!isObj(t.design)) bad(["design"], "design must be an object");
|
|
3917
3917
|
else {
|
|
3918
3918
|
const d = t.design;
|
|
3919
3919
|
unknownKeys(d, DESIGN_KEYS, ["design"]);
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
for (const k of ["sticky", "striped", "hideCaption"])
|
|
3920
|
+
oneOf2(d.responsive, ["design", "responsive"], "design.responsive", TABLE_RESPONSIVE);
|
|
3921
|
+
oneOf2(d.density, ["design", "density"], "design.density", ["compact", "comfortable"]);
|
|
3922
|
+
for (const k of ["sticky", "striped", "hideCaption"]) bool2(d[k], ["design", k], `design.${k}`);
|
|
3923
3923
|
}
|
|
3924
3924
|
}
|
|
3925
|
-
const keyed = (
|
|
3925
|
+
const keyed = (list2, at, keys, textKey, allowed) => {
|
|
3926
3926
|
const seen = /* @__PURE__ */ new Set();
|
|
3927
|
-
if (
|
|
3928
|
-
if (!Array.isArray(
|
|
3927
|
+
if (list2 === void 0) return seen;
|
|
3928
|
+
if (!Array.isArray(list2)) {
|
|
3929
3929
|
bad([at], `${at} must be an array`);
|
|
3930
3930
|
return seen;
|
|
3931
3931
|
}
|
|
3932
|
-
if (!allowed &&
|
|
3933
|
-
|
|
3932
|
+
if (!allowed && list2.length > 0) bad([at], `this table takes no ${at === "footnotes" ? "footnotes (config.allowFootnotes is false)" : "row groups (config.allowGroups is false)"}`);
|
|
3933
|
+
list2.forEach((g, i) => {
|
|
3934
3934
|
if (!isObj(g)) return bad([at, i], `${at}[${i}] must be an object`);
|
|
3935
3935
|
unknownKeys(g, keys, [at, i]);
|
|
3936
3936
|
if (typeof g._key !== "string" || g._key === "" || g._key.length > TABLE_LIMITS.keyChars) bad([at, i, "_key"], `needs a _key string of 1 to ${TABLE_LIMITS.keyChars} characters`);
|
|
3937
3937
|
else if (seen.has(g._key)) bad([at, i, "_key"], `_key "${g._key}" is used twice`);
|
|
3938
3938
|
else seen.add(g._key);
|
|
3939
|
-
|
|
3939
|
+
str2(g[textKey], [at, i, textKey], textKey, textKey === "text" ? TABLE_LIMITS.notesChars : TABLE_LIMITS.labelChars, true);
|
|
3940
3940
|
});
|
|
3941
3941
|
return seen;
|
|
3942
3942
|
};
|
|
@@ -3953,20 +3953,20 @@ function tableValueProblems(value, opts = {}) {
|
|
|
3953
3953
|
unknownKeys(c, COLUMN_KEYS, at);
|
|
3954
3954
|
if (typeof c._key !== "string" || c._key === "" || c._key.length > TABLE_LIMITS.keyChars) bad([...at, "_key"], `needs a _key string of 1 to ${TABLE_LIMITS.keyChars} characters`);
|
|
3955
3955
|
else if (cols.has(c._key)) bad([...at, "_key"], `_key "${c._key}" is used twice`);
|
|
3956
|
-
|
|
3956
|
+
str2(c.label, [...at, "label"], "label", TABLE_LIMITS.labelChars, true);
|
|
3957
3957
|
if (!TABLE_COLUMN_TYPES.includes(c.type)) bad([...at, "type"], `type must be one of ${TABLE_COLUMN_TYPES.join(", ")}`);
|
|
3958
3958
|
else if (opts.columnTypes && !opts.columnTypes.includes(c.type)) {
|
|
3959
3959
|
bad([...at, "type"], `a ${String(c.type)} column is not offered here (config.columnTypes: ${opts.columnTypes.join(", ")})`, "table_column_type_not_allowed");
|
|
3960
3960
|
}
|
|
3961
|
-
|
|
3962
|
-
|
|
3961
|
+
str2(c.description, [...at, "description"], "description", TABLE_LIMITS.notesChars);
|
|
3962
|
+
str2(c.unit, [...at, "unit"], "unit", 16);
|
|
3963
3963
|
if (c.currency !== void 0 && (typeof c.currency !== "string" || !/^[A-Z]{3}$/.test(c.currency))) bad([...at, "currency"], "currency must be an ISO 4217 code such as USD");
|
|
3964
3964
|
if (c.decimals !== void 0 && (!Number.isInteger(c.decimals) || c.decimals < 0 || c.decimals > 10)) bad([...at, "decimals"], "decimals must be a whole number from 0 to 10");
|
|
3965
3965
|
if (c.max !== void 0 && (!Number.isInteger(c.max) || c.max < 1 || c.max > 10)) bad([...at, "max"], "max must be a whole number from 1 to 10");
|
|
3966
|
-
|
|
3967
|
-
for (const k of ["sortable", "highlight"])
|
|
3968
|
-
|
|
3969
|
-
|
|
3966
|
+
oneOf2(c.align, [...at, "align"], "align", ["start", "center", "end"]);
|
|
3967
|
+
for (const k of ["sortable", "highlight"]) bool2(c[k], [...at, k], k);
|
|
3968
|
+
str2(c.trueLabel, [...at, "trueLabel"], "trueLabel", TABLE_LIMITS.labelChars);
|
|
3969
|
+
str2(c.falseLabel, [...at, "falseLabel"], "falseLabel", TABLE_LIMITS.labelChars);
|
|
3970
3970
|
if (c.group !== void 0 && (typeof c.group !== "string" || !colGroups.has(c.group))) bad([...at, "group"], `group "${String(c.group)}" is not a key of columnGroups`);
|
|
3971
3971
|
if (c.refTo !== void 0 && (!Array.isArray(c.refTo) || c.refTo.some((r) => typeof r !== "string" || r === ""))) bad([...at, "refTo"], 'refTo must be a list of collection ids or "page"');
|
|
3972
3972
|
if (typeof c._key === "string" && c._key !== "" && !cols.has(c._key)) cols.set(c._key, c);
|
|
@@ -3990,9 +3990,9 @@ function tableValueProblems(value, opts = {}) {
|
|
|
3990
3990
|
else if (rowKeys.has(r._key)) bad([...at, "_key"], `_key "${r._key}" is used twice`);
|
|
3991
3991
|
else rowKeys.add(r._key);
|
|
3992
3992
|
if (r.group !== void 0 && (typeof r.group !== "string" || !rowGroups.has(r.group))) bad([...at, "group"], `group "${String(r.group)}" is not a key of rowGroups`);
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3993
|
+
bool2(r.footer, [...at, "footer"], "footer");
|
|
3994
|
+
bool2(r.highlight, [...at, "highlight"], "highlight");
|
|
3995
|
+
oneOf2(r.type, [...at, "type"], "type", TABLE_COLUMN_TYPES);
|
|
3996
3996
|
if (!isObj(r.cells)) return bad([...at, "cells"], "cells must be an object keyed by column _key");
|
|
3997
3997
|
for (const [k, cell] of Object.entries(r.cells)) {
|
|
3998
3998
|
const cAt = [...at, "cells", k];
|
|
@@ -4144,8 +4144,8 @@ function sanitizeInline(html) {
|
|
|
4144
4144
|
return html.replace(/<(script|style|iframe|object|embed|template)\b[\s\S]*?<\/\1>/gi, "").replace(/<\/?([a-z][a-z0-9]*)\b([^>]*)>/gi, (m, tag, attrs) => {
|
|
4145
4145
|
const t = tag.toLowerCase();
|
|
4146
4146
|
if (!INLINE_TAGS.has(t)) return "";
|
|
4147
|
-
const
|
|
4148
|
-
if (m.startsWith("</")) return `</${
|
|
4147
|
+
const name2 = t === "b" ? "strong" : t === "i" ? "em" : t;
|
|
4148
|
+
if (m.startsWith("</")) return `</${name2}>`;
|
|
4149
4149
|
if (t === "a") {
|
|
4150
4150
|
const href = attrs.match(/href\s*=\s*("([^"]*)"|'([^']*)')/i);
|
|
4151
4151
|
return `<a href="${escAttr(safeHref(href ? href[2] ?? href[3] ?? "" : ""))}">`;
|
|
@@ -4154,7 +4154,7 @@ function sanitizeInline(html) {
|
|
|
4154
4154
|
const title = attrs.match(/title\s*=\s*"([^"]*)"/i);
|
|
4155
4155
|
return title ? `<abbr title="${escAttr(title[1])}">` : "<abbr>";
|
|
4156
4156
|
}
|
|
4157
|
-
return `<${
|
|
4157
|
+
return `<${name2}>`;
|
|
4158
4158
|
});
|
|
4159
4159
|
}
|
|
4160
4160
|
var alignOf = (col, t) => col.align ?? (t === "number" || t === "money" || t === "rating" ? "end" : "start");
|
|
@@ -4479,8 +4479,8 @@ var FORM_UPLOAD_REFUSED_EXTENSIONS = [
|
|
|
4479
4479
|
function isRefusedUploadExtension(ext) {
|
|
4480
4480
|
return FORM_UPLOAD_REFUSED_EXTENSIONS.includes(ext.toLowerCase());
|
|
4481
4481
|
}
|
|
4482
|
-
function fileExtension(
|
|
4483
|
-
const base =
|
|
4482
|
+
function fileExtension(name2) {
|
|
4483
|
+
const base = name2.slice(Math.max(name2.lastIndexOf("/"), name2.lastIndexOf("\\")) + 1);
|
|
4484
4484
|
const dot = base.lastIndexOf(".");
|
|
4485
4485
|
return dot <= 0 || dot === base.length - 1 ? "" : base.slice(dot + 1).toLowerCase();
|
|
4486
4486
|
}
|
|
@@ -4561,10 +4561,10 @@ function landmarkRegions(doc, dialogs = false, landmarks = false) {
|
|
|
4561
4561
|
} else if (el.parentElement?.closest(DIALOG_SELECTOR)) {
|
|
4562
4562
|
continue;
|
|
4563
4563
|
}
|
|
4564
|
-
const
|
|
4565
|
-
const n = counts.get(
|
|
4566
|
-
counts.set(
|
|
4567
|
-
out.push({ slot: `${
|
|
4564
|
+
const name2 = !LANDMARK_TAGS.has(el.tagName) && el.matches(DIALOG_SELECTOR) ? "dialog" : el.tagName.toLowerCase();
|
|
4565
|
+
const n = counts.get(name2) ?? 0;
|
|
4566
|
+
counts.set(name2, n + 1);
|
|
4567
|
+
out.push({ slot: `${name2}#${n}`, el });
|
|
4568
4568
|
}
|
|
4569
4569
|
return out;
|
|
4570
4570
|
}
|
|
@@ -4574,6 +4574,383 @@ function regionOf(regions, el) {
|
|
|
4574
4574
|
return slot;
|
|
4575
4575
|
}
|
|
4576
4576
|
|
|
4577
|
+
// src/local-setup.ts
|
|
4578
|
+
var LOCAL_SETUP_VERSION = 1;
|
|
4579
|
+
var SITE_MAP_VERSION = 3;
|
|
4580
|
+
var SITE_MAP_VERSIONS = [1, 2, 3];
|
|
4581
|
+
var LOCAL_FRAMEWORKS = ["astro", "next", "sveltekit", "nuxt", "react", "html"];
|
|
4582
|
+
var LAYOUT_ROLES = ["layout", "header", "footer", "nav"];
|
|
4583
|
+
var BLOCKED_REASONS = [
|
|
4584
|
+
"CLIENT_ONLY_ISLAND",
|
|
4585
|
+
"INNER_HTML",
|
|
4586
|
+
"COMPUTED_STRING",
|
|
4587
|
+
"DIALECT_UNSUPPORTED",
|
|
4588
|
+
"FILE_TOO_LARGE",
|
|
4589
|
+
"OVER_ROUTE_CAP",
|
|
4590
|
+
"UNRESOLVED_IMPORT",
|
|
4591
|
+
"PARSE_FAILED",
|
|
4592
|
+
"I18N_DICTIONARY"
|
|
4593
|
+
];
|
|
4594
|
+
var MAX_SITE_MAP_BYTES = 4 * 1024 * 1024;
|
|
4595
|
+
var MAX_LOCAL_SETUP_BYTES = 20 * 1024 * 1024;
|
|
4596
|
+
var LOCAL_SETUP_LIMITS = {
|
|
4597
|
+
routes: 2e4,
|
|
4598
|
+
templates: 5e3,
|
|
4599
|
+
components: 1e4,
|
|
4600
|
+
collections: 500,
|
|
4601
|
+
entryFiles: 2e4,
|
|
4602
|
+
fieldsPerCollection: 500,
|
|
4603
|
+
forms: 2e3,
|
|
4604
|
+
blocked: 5e3,
|
|
4605
|
+
partialDefault: 500,
|
|
4606
|
+
pages: 2e4,
|
|
4607
|
+
entriesPerCollection: 2e4,
|
|
4608
|
+
evidenceRows: 2e4,
|
|
4609
|
+
timings: 64,
|
|
4610
|
+
styleTokens: 2e3,
|
|
4611
|
+
/** Per `styleGuide.used` group, and the families the typography names. */
|
|
4612
|
+
styleValues: 50,
|
|
4613
|
+
/** Section candidates per template, and sections per page in the manifest. */
|
|
4614
|
+
sections: 200,
|
|
4615
|
+
/** Field keys one section holds. */
|
|
4616
|
+
sectionFields: 500
|
|
4617
|
+
};
|
|
4618
|
+
var MAX_ISSUES = 20;
|
|
4619
|
+
var SECTION_KINDS = ["element", "component", "expression", "fragment", "text"];
|
|
4620
|
+
var STYLE_TOKEN_GROUPS = ["color", "font", "fontSize", "fontWeight", "lineHeight", "letterSpacing", "spacing", "radius", "shadow", "breakpoint", "other"];
|
|
4621
|
+
var STYLE_USED_GROUPS = ["color", "fontSize", "spacing", "radius", "shadow", "breakpoint"];
|
|
4622
|
+
var fail = (out, at, message) => {
|
|
4623
|
+
if (out.length < MAX_ISSUES) out.push({ path: at || "(root)", message });
|
|
4624
|
+
};
|
|
4625
|
+
var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4626
|
+
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
4627
|
+
var HEX_SHA = /^[0-9a-f]{7,64}$/;
|
|
4628
|
+
var CODE = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
4629
|
+
var REPO_PATH = 2048;
|
|
4630
|
+
var NAME = 256;
|
|
4631
|
+
var str = (max, min = 0) => (v, at, out) => {
|
|
4632
|
+
if (typeof v !== "string") fail(out, at, "must be a string");
|
|
4633
|
+
else if (v.length < min || v.length > max) fail(out, at, `must be ${min}-${max} characters (got ${v.length})`);
|
|
4634
|
+
};
|
|
4635
|
+
var matching = (re, what) => (v, at, out) => {
|
|
4636
|
+
if (typeof v !== "string" || !re.test(v)) fail(out, at, `must be ${what}`);
|
|
4637
|
+
};
|
|
4638
|
+
var repoPath = (v, at, out) => {
|
|
4639
|
+
if (typeof v !== "string" || v.length === 0 || v.length > REPO_PATH) return fail(out, at, `must be a repo-relative path of 1-${REPO_PATH} characters`);
|
|
4640
|
+
if (v.startsWith("/") || v.includes("\\") || /^[a-z]:/i.test(v) || v.split("/").includes("..")) fail(out, at, `must be repo-relative with forward slashes, never absolute or climbing out (${v.slice(0, 80)})`);
|
|
4641
|
+
};
|
|
4642
|
+
var route = (v, at, out) => {
|
|
4643
|
+
if (typeof v !== "string" || !v.startsWith("/") || v.length > REPO_PATH) fail(out, at, "must be a route starting with /");
|
|
4644
|
+
};
|
|
4645
|
+
var count = (max = Number.MAX_SAFE_INTEGER) => (v, at, out) => {
|
|
4646
|
+
if (typeof v !== "number" || !Number.isInteger(v) || v < 0 || v > max) fail(out, at, `must be a whole number from 0 to ${max}`);
|
|
4647
|
+
};
|
|
4648
|
+
var positive = (v, at, out) => {
|
|
4649
|
+
if (typeof v !== "number" || !Number.isInteger(v) || v < 1) fail(out, at, "must be a whole number from 1");
|
|
4650
|
+
};
|
|
4651
|
+
var bool = (v, at, out) => {
|
|
4652
|
+
if (typeof v !== "boolean") fail(out, at, "must be true or false");
|
|
4653
|
+
};
|
|
4654
|
+
var literal = (value) => (v, at, out) => {
|
|
4655
|
+
if (v !== value) fail(out, at, `must be ${JSON.stringify(value)}`);
|
|
4656
|
+
};
|
|
4657
|
+
var oneOf = (values) => (v, at, out) => {
|
|
4658
|
+
if (!values.includes(v)) fail(out, at, `must be one of ${values.join(", ")}`);
|
|
4659
|
+
};
|
|
4660
|
+
var nullable = (check) => (v, at, out) => {
|
|
4661
|
+
if (v !== null) check(v, at, out);
|
|
4662
|
+
};
|
|
4663
|
+
var list = (max, item) => (v, at, out) => {
|
|
4664
|
+
if (!Array.isArray(v)) return fail(out, at, "must be a list");
|
|
4665
|
+
if (v.length > max) return fail(out, at, `must hold at most ${max} items (got ${v.length})`);
|
|
4666
|
+
for (let i = 0; i < v.length && out.length < MAX_ISSUES; i += 1) item(v[i], `${at}[${i}]`, out);
|
|
4667
|
+
};
|
|
4668
|
+
var keysSafe = (v, at, out) => {
|
|
4669
|
+
for (const k of Object.keys(v)) if (UNSAFE_KEYS.has(k)) fail(out, `${at}.${k}`, "is not an allowed key");
|
|
4670
|
+
};
|
|
4671
|
+
var record = (maxKeys, value) => (v, at, out) => {
|
|
4672
|
+
if (!isObject(v)) return fail(out, at, "must be an object");
|
|
4673
|
+
const keys = Object.keys(v);
|
|
4674
|
+
if (keys.length > maxKeys) return fail(out, at, `must hold at most ${maxKeys} keys (got ${keys.length})`);
|
|
4675
|
+
keysSafe(v, at, out);
|
|
4676
|
+
for (const k of keys) {
|
|
4677
|
+
if (k.length === 0 || k.length > NAME) fail(out, `${at}.${k.slice(0, 40)}`, `key must be 1-${NAME} characters`);
|
|
4678
|
+
value(v[k], `${at}.${k}`, out);
|
|
4679
|
+
}
|
|
4680
|
+
};
|
|
4681
|
+
var object = (required, optional = {}) => (v, at, out) => {
|
|
4682
|
+
if (!isObject(v)) return fail(out, at, "must be an object");
|
|
4683
|
+
keysSafe(v, at, out);
|
|
4684
|
+
for (const [k, check] of Object.entries(required)) {
|
|
4685
|
+
if (!(k in v)) fail(out, `${at}.${k}`, "is required");
|
|
4686
|
+
else check(v[k], `${at}.${k}`, out);
|
|
4687
|
+
}
|
|
4688
|
+
for (const [k, check] of Object.entries(optional)) if (k in v && v[k] !== void 0) check(v[k], `${at}.${k}`, out);
|
|
4689
|
+
};
|
|
4690
|
+
var anyObject = (v, at, out) => {
|
|
4691
|
+
if (!isObject(v)) fail(out, at, "must be an object");
|
|
4692
|
+
else keysSafe(v, at, out);
|
|
4693
|
+
};
|
|
4694
|
+
var name = str(NAME, 1);
|
|
4695
|
+
var names = (max) => list(max, name);
|
|
4696
|
+
var literals = object({ text: count(), image: count(), link: count(), video: count() });
|
|
4697
|
+
var SECTION_TYPE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
4698
|
+
var sectionType = (v, at, out) => {
|
|
4699
|
+
if (typeof v !== "string" || v.length > 64 || !SECTION_TYPE.test(v)) fail(out, at, "must be a section family: lowercase words joined by hyphens, at most 64 characters (call-to-action)");
|
|
4700
|
+
};
|
|
4701
|
+
var candidate = (v, at, out) => {
|
|
4702
|
+
object({
|
|
4703
|
+
id: name,
|
|
4704
|
+
file: repoPath,
|
|
4705
|
+
start: count(),
|
|
4706
|
+
end: count(),
|
|
4707
|
+
line: positive,
|
|
4708
|
+
kind: oneOf(SECTION_KINDS),
|
|
4709
|
+
sectionType,
|
|
4710
|
+
label: str(200, 1),
|
|
4711
|
+
fields: names(LOCAL_SETUP_LIMITS.sectionFields),
|
|
4712
|
+
component: nullable(name),
|
|
4713
|
+
props: names(500),
|
|
4714
|
+
repeats: names(LOCAL_SETUP_LIMITS.templates),
|
|
4715
|
+
variants: names(LOCAL_SETUP_LIMITS.components)
|
|
4716
|
+
})(v, at, out);
|
|
4717
|
+
if (isObject(v) && typeof v.start === "number" && typeof v.end === "number" && v.end <= v.start) fail(out, `${at}.end`, "must be after start");
|
|
4718
|
+
};
|
|
4719
|
+
var template = (v, at, out) => {
|
|
4720
|
+
object(
|
|
4721
|
+
{ id: name, file: repoPath, pattern: route, components: names(LOCAL_SETUP_LIMITS.components), literals, collection: nullable(name) },
|
|
4722
|
+
{
|
|
4723
|
+
routes: list(LOCAL_SETUP_LIMITS.routes, route),
|
|
4724
|
+
routeCount: count(LOCAL_SETUP_LIMITS.routes),
|
|
4725
|
+
sections: list(LOCAL_SETUP_LIMITS.sections, candidate),
|
|
4726
|
+
sectionsRefused: object({ code: matching(CODE, "an UPPER_SNAKE reason code"), message: str(1024) }),
|
|
4727
|
+
sectionsWrapped: bool
|
|
4728
|
+
}
|
|
4729
|
+
)(v, at, out);
|
|
4730
|
+
if (isObject(v) && "routes" in v === "routeCount" in v) fail(out, at, "must carry exactly one of routes and routeCount");
|
|
4731
|
+
};
|
|
4732
|
+
var color = object({ value: matching(/^#[0-9A-F]{6}$/, "a #RRGGBB colour"), token: nullable(name) });
|
|
4733
|
+
var styleGuide = object({
|
|
4734
|
+
tokens: list(
|
|
4735
|
+
LOCAL_SETUP_LIMITS.styleTokens,
|
|
4736
|
+
object({ name, group: oneOf(STYLE_TOKEN_GROUPS), value: nullable(str(1024)), source: repoPath, scope: str(NAME, 1) }, { alias: name })
|
|
4737
|
+
),
|
|
4738
|
+
primary: object({ primary: nullable(color), accent: nullable(color), background: nullable(color), text: nullable(color) }),
|
|
4739
|
+
typography: object({
|
|
4740
|
+
heading: nullable(name),
|
|
4741
|
+
body: nullable(name),
|
|
4742
|
+
families: names(LOCAL_SETUP_LIMITS.styleValues),
|
|
4743
|
+
faces: list(200, object({ family: name, source: repoPath }, { weight: str(16, 1), style: str(16, 1) })),
|
|
4744
|
+
scale: list(100, object({ name, size: str(256, 1), source: repoPath }))
|
|
4745
|
+
}),
|
|
4746
|
+
used: object(Object.fromEntries(STYLE_USED_GROUPS.map((g) => [g, list(LOCAL_SETUP_LIMITS.styleValues, str(256, 1))]))),
|
|
4747
|
+
components: object({ buttons: names(LOCAL_SETUP_LIMITS.components), cards: names(LOCAL_SETUP_LIMITS.components), headings: names(LOCAL_SETUP_LIMITS.components) }),
|
|
4748
|
+
reference: nullable(object({ route, file: repoPath, components: names(LOCAL_SETUP_LIMITS.components) })),
|
|
4749
|
+
sources: list(500, repoPath)
|
|
4750
|
+
});
|
|
4751
|
+
var siteMapShape = object({
|
|
4752
|
+
version: oneOf(SITE_MAP_VERSIONS),
|
|
4753
|
+
toolVersion: str(64, 1),
|
|
4754
|
+
sha: nullable(matching(HEX_SHA, "a git commit sha (7-64 hex)")),
|
|
4755
|
+
framework: oneOf(LOCAL_FRAMEWORKS),
|
|
4756
|
+
build: object({ command: nullable(str(1024, 1)), outDir: nullable(repoPath) }),
|
|
4757
|
+
templates: list(LOCAL_SETUP_LIMITS.templates, template),
|
|
4758
|
+
components: list(
|
|
4759
|
+
LOCAL_SETUP_LIMITS.components,
|
|
4760
|
+
object({ id: name, file: repoPath, usedBy: names(LOCAL_SETUP_LIMITS.templates), props: names(500), literals, sectionCandidate: bool })
|
|
4761
|
+
),
|
|
4762
|
+
layout: list(200, object({ file: repoPath, role: oneOf(LAYOUT_ROLES) })),
|
|
4763
|
+
collections: list(
|
|
4764
|
+
LOCAL_SETUP_LIMITS.collections,
|
|
4765
|
+
object({
|
|
4766
|
+
id: name,
|
|
4767
|
+
source: repoPath,
|
|
4768
|
+
fields: list(LOCAL_SETUP_LIMITS.fieldsPerCollection, object({ key: name, type: str(64, 1) }, { required: bool })),
|
|
4769
|
+
entries: count(LOCAL_SETUP_LIMITS.entriesPerCollection),
|
|
4770
|
+
files: list(LOCAL_SETUP_LIMITS.entryFiles, repoPath)
|
|
4771
|
+
})
|
|
4772
|
+
),
|
|
4773
|
+
locales: object({ default: nullable(str(35, 1)), locales: list(500, str(35, 1)), dictionaries: list(2e3, repoPath), readBy: names(LOCAL_SETUP_LIMITS.templates) }),
|
|
4774
|
+
forms: list(
|
|
4775
|
+
LOCAL_SETUP_LIMITS.forms,
|
|
4776
|
+
object({ file: repoPath, line: positive, templates: names(LOCAL_SETUP_LIMITS.templates), action: nullable(str(REPO_PATH)), method: nullable(str(16)), handler: nullable(str(64, 1)), fields: count(1e3) })
|
|
4777
|
+
),
|
|
4778
|
+
media: object({ images: count(), videos: count(), remoteHosts: list(500, str(253, 1)), overPolicy: list(5e3, object({ file: repoPath, bytes: count() })) }),
|
|
4779
|
+
styles: object({ tailwind: bool, files: list(500, repoPath), colors: list(500, object({ name, value: str(256, 1) })) }),
|
|
4780
|
+
blocked: list(
|
|
4781
|
+
LOCAL_SETUP_LIMITS.blocked,
|
|
4782
|
+
object({ file: repoPath, reason: matching(CODE, "an UPPER_SNAKE reason code") }, { line: positive, message: str(1024) })
|
|
4783
|
+
),
|
|
4784
|
+
partialDefault: list(LOCAL_SETUP_LIMITS.partialDefault, route)
|
|
4785
|
+
}, { styleGuide });
|
|
4786
|
+
function siteMapRefs(map, at, out) {
|
|
4787
|
+
const unique = (ids, where) => {
|
|
4788
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4789
|
+
ids.forEach((id, i) => {
|
|
4790
|
+
if (seen.has(id)) fail(out, `${at}.${where}[${i}].id`, `"${id.slice(0, 80)}" is not unique`);
|
|
4791
|
+
seen.add(id);
|
|
4792
|
+
});
|
|
4793
|
+
return seen;
|
|
4794
|
+
};
|
|
4795
|
+
const templates = unique(map.templates.map((t) => t.id), "templates");
|
|
4796
|
+
const components = unique(map.components.map((c) => c.id), "components");
|
|
4797
|
+
const collections = unique(map.collections.map((c) => c.id), "collections");
|
|
4798
|
+
const known = (set, ids, where, what) => ids.forEach((id, i) => {
|
|
4799
|
+
if (!set.has(id)) fail(out, `${at}.${where}[${i}]`, `names ${what} "${id.slice(0, 80)}", which is not in the map`);
|
|
4800
|
+
});
|
|
4801
|
+
let routes = 0;
|
|
4802
|
+
map.templates.forEach((t, i) => {
|
|
4803
|
+
known(components, t.components, `templates[${i}].components`, "the component");
|
|
4804
|
+
if (t.collection !== null && !collections.has(t.collection)) fail(out, `${at}.templates[${i}].collection`, `names the collection "${t.collection.slice(0, 80)}", which is not in the map`);
|
|
4805
|
+
routes += t.routes?.length ?? t.routeCount ?? 0;
|
|
4806
|
+
});
|
|
4807
|
+
if (routes > LOCAL_SETUP_LIMITS.routes) fail(out, `${at}.templates`, `render at most ${LOCAL_SETUP_LIMITS.routes} routes in all (got ${routes}); list the rest in blocked as OVER_ROUTE_CAP`);
|
|
4808
|
+
map.templates.forEach((t, i) => {
|
|
4809
|
+
const ids = /* @__PURE__ */ new Set();
|
|
4810
|
+
(t.sections ?? []).forEach((c, n) => {
|
|
4811
|
+
const where = `templates[${i}].sections[${n}]`;
|
|
4812
|
+
if (ids.has(c.id)) fail(out, `${at}.${where}.id`, `"${c.id.slice(0, 80)}" is not unique in its template`);
|
|
4813
|
+
ids.add(c.id);
|
|
4814
|
+
if (c.component !== null && !components.has(c.component)) fail(out, `${at}.${where}.component`, `names the component "${c.component.slice(0, 80)}", which is not in the map`);
|
|
4815
|
+
known(templates, c.repeats, `${where}.repeats`, "the template");
|
|
4816
|
+
known(components, c.variants, `${where}.variants`, "the component");
|
|
4817
|
+
});
|
|
4818
|
+
});
|
|
4819
|
+
map.components.forEach((c, i) => known(templates, c.usedBy, `components[${i}].usedBy`, "the template"));
|
|
4820
|
+
map.forms.forEach((f, i) => known(templates, f.templates, `forms[${i}].templates`, "the template"));
|
|
4821
|
+
known(templates, map.locales.readBy, "locales.readBy", "the template");
|
|
4822
|
+
const guide = map.styleGuide;
|
|
4823
|
+
if (guide) {
|
|
4824
|
+
const rendered = /* @__PURE__ */ new Set([...components, ...templates]);
|
|
4825
|
+
for (const kind of ["buttons", "cards", "headings"]) known(rendered, guide.components[kind], `styleGuide.components.${kind}`, "the component");
|
|
4826
|
+
if (guide.reference) {
|
|
4827
|
+
if (!templates.has(guide.reference.file)) fail(out, `${at}.styleGuide.reference.file`, `names the template "${guide.reference.file.slice(0, 80)}", which is not in the map`);
|
|
4828
|
+
known(components, guide.reference.components, "styleGuide.reference.components", "the component");
|
|
4829
|
+
}
|
|
4830
|
+
}
|
|
4831
|
+
}
|
|
4832
|
+
var proofRow = object({ path: str(512, 1) }, { route, file: str(REPO_PATH), line: positive, reason: str(1024) });
|
|
4833
|
+
var proofRows = list(LOCAL_SETUP_LIMITS.evidenceRows, proofRow);
|
|
4834
|
+
var manifestShape = object({
|
|
4835
|
+
version: literal(LOCAL_SETUP_VERSION),
|
|
4836
|
+
toolVersion: str(64, 1),
|
|
4837
|
+
sha: matching(HEX_SHA, "a git commit sha (7-64 hex)"),
|
|
4838
|
+
framework: oneOf(LOCAL_FRAMEWORKS),
|
|
4839
|
+
scope: (v, at, out) => {
|
|
4840
|
+
if (isObject(v) && v.mode === "full") return;
|
|
4841
|
+
if (isObject(v) && v.mode === "partial") return list(LOCAL_SETUP_LIMITS.routes, route)(v.routes, `${at}.routes`, out);
|
|
4842
|
+
fail(out, at, 'must be { mode: "full" } or { mode: "partial", routes: [...] }');
|
|
4843
|
+
},
|
|
4844
|
+
siteMap: siteMapShape,
|
|
4845
|
+
doc: object(
|
|
4846
|
+
{},
|
|
4847
|
+
{
|
|
4848
|
+
schema: record(LOCAL_SETUP_LIMITS.pages, object({ fields: list(LOCAL_SETUP_LIMITS.fieldsPerCollection, anyObject) }, { name: str(NAME) })),
|
|
4849
|
+
collections: record(LOCAL_SETUP_LIMITS.collections, list(LOCAL_SETUP_LIMITS.entriesPerCollection, object({ slug: str(NAME, 1), data: anyObject }, { status: oneOf(["draft", "published"]) }))),
|
|
4850
|
+
derivedCollections: literal(true),
|
|
4851
|
+
forms: list(LOCAL_SETUP_LIMITS.forms, anyObject),
|
|
4852
|
+
pages: list(LOCAL_SETUP_LIMITS.pages, anyObject),
|
|
4853
|
+
components: list(LOCAL_SETUP_LIMITS.components, anyObject)
|
|
4854
|
+
}
|
|
4855
|
+
),
|
|
4856
|
+
receipt: object({
|
|
4857
|
+
briefDigest: matching(/^sha256:[0-9a-f]{64}$/, "a sha256: brief digest"),
|
|
4858
|
+
paths: object({ declared: count(), rewritten: count(), alreadyDeclared: count(), pending: list(LOCAL_SETUP_LIMITS.routes, anyObject) })
|
|
4859
|
+
}),
|
|
4860
|
+
evidence: object({
|
|
4861
|
+
xray: list(
|
|
4862
|
+
LOCAL_SETUP_LIMITS.evidenceRows,
|
|
4863
|
+
object({ route, template: nullable(name), visible: count(), unaddressable: count(), unbound: list(500, object({ section: str(NAME), tag: str(32), text: str(256) })) })
|
|
4864
|
+
),
|
|
4865
|
+
proof: object({ sha: nullable(matching(HEX_SHA, "a git commit sha")), matched: count(), formatted: count(), indirect: proofRows, mismatched: proofRows, inert: proofRows, conflicts: proofRows }),
|
|
4866
|
+
renderEqual: list(LOCAL_SETUP_LIMITS.evidenceRows, object({ route, equal: bool }, { difference: object({ at: count(), was: str(512), now: str(512) }) }))
|
|
4867
|
+
}),
|
|
4868
|
+
timings: record(LOCAL_SETUP_LIMITS.timings, count())
|
|
4869
|
+
}, {
|
|
4870
|
+
sections: list(
|
|
4871
|
+
LOCAL_SETUP_LIMITS.pages,
|
|
4872
|
+
object(
|
|
4873
|
+
{
|
|
4874
|
+
page: matching(/^[a-z0-9][a-z0-9-/]{0,254}$/, "a page slug"),
|
|
4875
|
+
file: repoPath,
|
|
4876
|
+
sections: list(
|
|
4877
|
+
LOCAL_SETUP_LIMITS.sections,
|
|
4878
|
+
object({ id: name, name: str(200, 1), sectionType }, { variant: str(120, 1), component: nullable(name) })
|
|
4879
|
+
)
|
|
4880
|
+
},
|
|
4881
|
+
{ template: bool }
|
|
4882
|
+
)
|
|
4883
|
+
)
|
|
4884
|
+
});
|
|
4885
|
+
function utf8Bytes(s) {
|
|
4886
|
+
let n = 0;
|
|
4887
|
+
for (let i = 0; i < s.length; i += 1) {
|
|
4888
|
+
const c = s.charCodeAt(i);
|
|
4889
|
+
if (c < 128) n += 1;
|
|
4890
|
+
else if (c < 2048) n += 2;
|
|
4891
|
+
else if (c >= 55296 && c <= 56319) {
|
|
4892
|
+
n += 4;
|
|
4893
|
+
i += 1;
|
|
4894
|
+
} else n += 3;
|
|
4895
|
+
}
|
|
4896
|
+
return n;
|
|
4897
|
+
}
|
|
4898
|
+
function parsed(input, maxBytes, out) {
|
|
4899
|
+
if (typeof input !== "string") return input;
|
|
4900
|
+
const bytes = utf8Bytes(input);
|
|
4901
|
+
if (bytes > maxBytes) {
|
|
4902
|
+
fail(out, "", `is ${bytes} bytes; the cap is ${maxBytes}`);
|
|
4903
|
+
return void 0;
|
|
4904
|
+
}
|
|
4905
|
+
try {
|
|
4906
|
+
return JSON.parse(input);
|
|
4907
|
+
} catch (err) {
|
|
4908
|
+
fail(out, "", `is not JSON: ${err instanceof Error ? err.message.slice(0, 200) : "unreadable"}`);
|
|
4909
|
+
return void 0;
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
function versionIssue(v, known) {
|
|
4913
|
+
if (!isObject(v)) return { path: "(root)", message: "must be an object" };
|
|
4914
|
+
const newest = known[known.length - 1];
|
|
4915
|
+
return known.includes(v.version) ? null : { path: "version", message: `is ${JSON.stringify(v.version)}; this reader understands version ${known.join(" or ")}. Upgrade the reader, or write version ${newest}.` };
|
|
4916
|
+
}
|
|
4917
|
+
function parseSiteMap(input) {
|
|
4918
|
+
const out = [];
|
|
4919
|
+
const v = parsed(input, MAX_SITE_MAP_BYTES, out);
|
|
4920
|
+
if (out.length) return { ok: false, issues: out };
|
|
4921
|
+
const version = versionIssue(v, SITE_MAP_VERSIONS);
|
|
4922
|
+
if (version) return { ok: false, issues: [version] };
|
|
4923
|
+
siteMapShape(v, "", out);
|
|
4924
|
+
if (!out.length) siteMapRefs(v, "", out);
|
|
4925
|
+
return out.length ? { ok: false, issues: out.map(rooted) } : { ok: true, value: v };
|
|
4926
|
+
}
|
|
4927
|
+
function parseLocalSetupManifest(input) {
|
|
4928
|
+
const out = [];
|
|
4929
|
+
const v = parsed(input, MAX_LOCAL_SETUP_BYTES, out);
|
|
4930
|
+
if (out.length) return { ok: false, issues: out };
|
|
4931
|
+
const version = versionIssue(v, [LOCAL_SETUP_VERSION]);
|
|
4932
|
+
if (version) return { ok: false, issues: [version] };
|
|
4933
|
+
manifestShape(v, "", out);
|
|
4934
|
+
if (!out.length) {
|
|
4935
|
+
const m = v;
|
|
4936
|
+
siteMapRefs(m.siteMap, ".siteMap", out);
|
|
4937
|
+
if (m.siteMap.framework !== m.framework) fail(out, ".framework", `is ${m.framework}, but the site map says ${m.siteMap.framework}`);
|
|
4938
|
+
const pagesSeen = /* @__PURE__ */ new Set();
|
|
4939
|
+
(m.sections ?? []).forEach((p, i) => {
|
|
4940
|
+
const key = `${p.template === true ? "template:" : ""}${p.page}`;
|
|
4941
|
+
if (pagesSeen.has(key)) fail(out, `.sections[${i}].page`, `"${p.page}" is sent twice`);
|
|
4942
|
+
pagesSeen.add(key);
|
|
4943
|
+
const ids = /* @__PURE__ */ new Set();
|
|
4944
|
+
p.sections.forEach((x, n) => {
|
|
4945
|
+
if (ids.has(x.id)) fail(out, `.sections[${i}].sections[${n}].id`, `"${x.id.slice(0, 80)}" is not unique on its page`);
|
|
4946
|
+
ids.add(x.id);
|
|
4947
|
+
});
|
|
4948
|
+
});
|
|
4949
|
+
}
|
|
4950
|
+
return out.length ? { ok: false, issues: out.map(rooted) } : { ok: true, value: v };
|
|
4951
|
+
}
|
|
4952
|
+
var rooted = (i) => ({ ...i, path: i.path.startsWith(".") ? i.path.slice(1) : i.path });
|
|
4953
|
+
|
|
4577
4954
|
// src/sections.ts
|
|
4578
4955
|
var TAG_HEADS = /* @__PURE__ */ new Set([
|
|
4579
4956
|
"h1",
|
|
@@ -4922,9 +5299,9 @@ function canonicalJson(value) {
|
|
|
4922
5299
|
if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
4923
5300
|
if (Array.isArray(value)) return `[${value.map((child) => skipped(child) ? "null" : canonicalJson(child)).join(",")}]`;
|
|
4924
5301
|
if (typeof value === "object") {
|
|
4925
|
-
const
|
|
4926
|
-
const keys = Object.keys(
|
|
4927
|
-
return `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJson(
|
|
5302
|
+
const record2 = value;
|
|
5303
|
+
const keys = Object.keys(record2).filter((key) => !skipped(record2[key])).sort();
|
|
5304
|
+
return `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJson(record2[key])}`).join(",")}}`;
|
|
4928
5305
|
}
|
|
4929
5306
|
throw new TypeError(`Unsupported canonical JSON value: ${typeof value}`);
|
|
4930
5307
|
}
|
|
@@ -4953,7 +5330,7 @@ var isDockUiImportAllowed = (specifier) => {
|
|
|
4953
5330
|
if (specifier === "@bettercms-ai/dock-input") return true;
|
|
4954
5331
|
return specifier.startsWith("@bettercms-ai/kit/") && specifier.length > "@bettercms-ai/kit/".length;
|
|
4955
5332
|
};
|
|
4956
|
-
var dockUiMerkleKey = (
|
|
5333
|
+
var dockUiMerkleKey = (name2, version) => `cms:${name2}@${version}`;
|
|
4957
5334
|
|
|
4958
5335
|
// src/richtext-features.ts
|
|
4959
5336
|
var RICHTEXT_MARK_FEATURES = ["bold", "italic", "underline", "strikethrough", "code", "highlight"];
|
|
@@ -4991,13 +5368,13 @@ var RICHTEXT_FEATURE_ALIASES = {
|
|
|
4991
5368
|
headings: RICHTEXT_HEADING_FEATURES
|
|
4992
5369
|
};
|
|
4993
5370
|
var KNOWN = new Set(RICHTEXT_FEATURES);
|
|
4994
|
-
function normaliseRichTextFeatures(
|
|
5371
|
+
function normaliseRichTextFeatures(names2) {
|
|
4995
5372
|
const want = /* @__PURE__ */ new Set();
|
|
4996
5373
|
const unknown = [];
|
|
4997
|
-
for (const
|
|
4998
|
-
if (Object.hasOwn(RICHTEXT_FEATURE_ALIASES,
|
|
4999
|
-
else if (KNOWN.has(
|
|
5000
|
-
else if (!unknown.includes(
|
|
5374
|
+
for (const name2 of names2) {
|
|
5375
|
+
if (Object.hasOwn(RICHTEXT_FEATURE_ALIASES, name2)) for (const f of RICHTEXT_FEATURE_ALIASES[name2]) want.add(f);
|
|
5376
|
+
else if (KNOWN.has(name2)) want.add(name2);
|
|
5377
|
+
else if (!unknown.includes(name2)) unknown.push(name2);
|
|
5001
5378
|
}
|
|
5002
5379
|
return { features: RICHTEXT_FEATURES.filter((f) => want.has(f)), unknown };
|
|
5003
5380
|
}
|
|
@@ -5095,7 +5472,7 @@ function embedMarkerHtml(m) {
|
|
|
5095
5472
|
return `<div class="bcms-block" data-bcms-schema-key="component" data-bcms-embed="${esc2(m.ptKey)}" data-bcms-component="${esc2(m.componentId)}"` + (m.hidden ? " data-bcms-embed-hidden" : "") + (m.reason ? ` data-bcms-embed-reason="${m.reason}"` : "") + "></div>";
|
|
5096
5473
|
}
|
|
5097
5474
|
var MARKER_RE = /<div\b([^>]*\bdata-bcms-embed="[^"]*"[^>]*)>\s*<\/div>/g;
|
|
5098
|
-
var attr = (attrs,
|
|
5475
|
+
var attr = (attrs, name2) => attrs.match(new RegExp(`\\b${name2}="([^"]*)"`))?.[1];
|
|
5099
5476
|
function parseEmbedMarkers(html) {
|
|
5100
5477
|
const out = [];
|
|
5101
5478
|
for (const m of html.matchAll(MARKER_RE)) {
|
|
@@ -5134,7 +5511,7 @@ function variantOptionsFromUnion(typeText) {
|
|
|
5134
5511
|
function evaluateShowIf(showIf, values, sourceTypes) {
|
|
5135
5512
|
const rules = Array.isArray(showIf?.rules) ? showIf.rules : [];
|
|
5136
5513
|
if (!rules.length) return true;
|
|
5137
|
-
const
|
|
5514
|
+
const str2 = (v) => String(v ?? "");
|
|
5138
5515
|
const test = (r) => {
|
|
5139
5516
|
const type = sourceTypes?.get(r.field);
|
|
5140
5517
|
if (sourceTypes && type === void 0) return true;
|
|
@@ -5148,13 +5525,13 @@ function evaluateShowIf(showIf, values, sourceTypes) {
|
|
|
5148
5525
|
if (!Number.isFinite(n) || !Number.isFinite(bound)) return false;
|
|
5149
5526
|
return r.op === "gt" ? n > bound : n < bound;
|
|
5150
5527
|
}
|
|
5151
|
-
const s = type === "boolean" || type === "toggle" ? String(raw === true || raw === "true") :
|
|
5528
|
+
const s = type === "boolean" || type === "toggle" ? String(raw === true || raw === "true") : str2(raw);
|
|
5152
5529
|
if (r.op === "in" || r.op === "notIn") {
|
|
5153
|
-
const hit = (Array.isArray(r.value) ? r.value : [r.value]).map(
|
|
5530
|
+
const hit = (Array.isArray(r.value) ? r.value : [r.value]).map(str2).includes(s);
|
|
5154
5531
|
return r.op === "in" ? hit : !hit;
|
|
5155
5532
|
}
|
|
5156
|
-
if (r.op === "neq") return s !==
|
|
5157
|
-
return s ===
|
|
5533
|
+
if (r.op === "neq") return s !== str2(r.value);
|
|
5534
|
+
return s === str2(r.value);
|
|
5158
5535
|
};
|
|
5159
5536
|
return showIf.match === "any" ? rules.some(test) : rules.every(test);
|
|
5160
5537
|
}
|
|
@@ -5242,6 +5619,7 @@ function iconHtml(v, className = "") {
|
|
|
5242
5619
|
export {
|
|
5243
5620
|
BG_TOKENS,
|
|
5244
5621
|
BG_TOKEN_CSS,
|
|
5622
|
+
BLOCKED_REASONS,
|
|
5245
5623
|
BLOCK_BINDINGS,
|
|
5246
5624
|
BLOCK_FIELD_TYPES,
|
|
5247
5625
|
BLOCK_FIELD_TYPES_RENDERABLE_NOW,
|
|
@@ -5301,14 +5679,20 @@ export {
|
|
|
5301
5679
|
KEY_RESERVED_PREFIX,
|
|
5302
5680
|
KIT_CATEGORIES,
|
|
5303
5681
|
LANDMARK_SELECTOR,
|
|
5682
|
+
LAYOUT_ROLES,
|
|
5304
5683
|
LAYOUT_SECTION_ICONS,
|
|
5305
5684
|
LAYOUT_SECTION_ICON_SET,
|
|
5306
5685
|
LINK_RELS,
|
|
5307
5686
|
LINK_VALUE_TYPES,
|
|
5308
5687
|
LIST_ITEMS_CAP,
|
|
5309
5688
|
LIST_PREVIEW_SLOTS,
|
|
5689
|
+
LOCAL_FRAMEWORKS,
|
|
5690
|
+
LOCAL_SETUP_LIMITS,
|
|
5691
|
+
LOCAL_SETUP_VERSION,
|
|
5310
5692
|
LOCATOR_PATH,
|
|
5311
5693
|
MAIN_SELECTOR,
|
|
5694
|
+
MAX_LOCAL_SETUP_BYTES,
|
|
5695
|
+
MAX_SITE_MAP_BYTES,
|
|
5312
5696
|
NAVIGATION_SECTION_ID,
|
|
5313
5697
|
OPEN_MODES,
|
|
5314
5698
|
OPEN_MODE_TYPES,
|
|
@@ -5332,12 +5716,15 @@ export {
|
|
|
5332
5716
|
SECTION_ANCHOR,
|
|
5333
5717
|
SECTION_CSS_CLASS,
|
|
5334
5718
|
SECTION_DOCTRINE,
|
|
5719
|
+
SECTION_KINDS,
|
|
5335
5720
|
SECTION_SPACE_TOKENS,
|
|
5336
5721
|
SEGMENTED_MAX,
|
|
5337
5722
|
SEGMENTED_MIN,
|
|
5338
5723
|
SHOW_IF_SCOPES,
|
|
5339
5724
|
SIDE_SPACE_MIN_PX,
|
|
5340
5725
|
SIDE_SPACE_TOKENS,
|
|
5726
|
+
SITE_MAP_VERSION,
|
|
5727
|
+
SITE_MAP_VERSIONS,
|
|
5341
5728
|
SLOT_CHILD_KEYS,
|
|
5342
5729
|
SLOT_ITEMS_CAP,
|
|
5343
5730
|
SLOT_MAX_ITEMS,
|
|
@@ -5346,6 +5733,8 @@ export {
|
|
|
5346
5733
|
SOURCE_RANK,
|
|
5347
5734
|
SPACE_BOTTOM_TOKENS,
|
|
5348
5735
|
SPACE_STEP_TOKENS,
|
|
5736
|
+
STYLE_TOKEN_GROUPS,
|
|
5737
|
+
STYLE_USED_GROUPS,
|
|
5349
5738
|
TABLE_COLUMN_TYPES,
|
|
5350
5739
|
TABLE_CSS,
|
|
5351
5740
|
TABLE_JSONLD_TYPES,
|
|
@@ -5454,8 +5843,10 @@ export {
|
|
|
5454
5843
|
normalizeTableValue,
|
|
5455
5844
|
normalizeWindow,
|
|
5456
5845
|
parseEmbedMarkers,
|
|
5846
|
+
parseLocalSetupManifest,
|
|
5457
5847
|
parseNumberText,
|
|
5458
5848
|
parsePropsAttribute,
|
|
5849
|
+
parseSiteMap,
|
|
5459
5850
|
pickFieldStyle,
|
|
5460
5851
|
placementBindOf,
|
|
5461
5852
|
planSections,
|