@bettercms-ai/types 1.68.0 → 1.70.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 +710 -6
- package/dist/index.js +1068 -96
- 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 ?? {};
|
|
@@ -82,20 +82,20 @@ function withVisibleChildren(block, now) {
|
|
|
82
82
|
// A slide or a tab panel: `{ id, children }`.
|
|
83
83
|
mapSame(held, (row) => {
|
|
84
84
|
const children = row?.children;
|
|
85
|
-
const
|
|
86
|
-
return
|
|
85
|
+
const shown2 = visibleBlocks(children, now);
|
|
86
|
+
return shown2 === children ? row : { ...row, children: shown2 };
|
|
87
87
|
})
|
|
88
88
|
);
|
|
89
89
|
return next === held ? block : { ...block, props: { ...p, [key]: next } };
|
|
90
90
|
}
|
|
91
91
|
function visibleBlocks(blocks, now) {
|
|
92
92
|
if (!Array.isArray(blocks)) return blocks;
|
|
93
|
-
const
|
|
93
|
+
const shown2 = blocks.filter((block) => inWindow(block, now) && !hiddenEverywhere(block));
|
|
94
94
|
const pruned = mapSame(
|
|
95
|
-
|
|
95
|
+
shown2,
|
|
96
96
|
(block) => block && typeof block === "object" ? withVisibleChildren(block, now) : block
|
|
97
97
|
);
|
|
98
|
-
return
|
|
98
|
+
return shown2.length === blocks.length && pruned === shown2 ? blocks : pruned;
|
|
99
99
|
}
|
|
100
100
|
function isBlock(value) {
|
|
101
101
|
return typeof value === "object" && value !== null && "type" in value && typeof value["type"] === "string";
|
|
@@ -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
|
}
|
|
@@ -4504,25 +4504,50 @@ var LANDMARK_SELECTOR = "header,nav,footer";
|
|
|
4504
4504
|
var LANDMARK_TAGS = /* @__PURE__ */ new Set(["HEADER", "NAV", "FOOTER"]);
|
|
4505
4505
|
var DIALOG_SELECTOR = 'dialog,[role="dialog"]';
|
|
4506
4506
|
var MAIN_SELECTOR = 'main,[role="main"]';
|
|
4507
|
-
function isChromeLandmark(el, landmarks) {
|
|
4507
|
+
function isChromeLandmark(el, landmarks, wrapped = false) {
|
|
4508
4508
|
if (!LANDMARK_TAGS.has(el.tagName)) return false;
|
|
4509
4509
|
if (!landmarks) return true;
|
|
4510
4510
|
const fence = el.parentElement?.closest(MAIN_SELECTOR);
|
|
4511
|
-
|
|
4511
|
+
if (!fence || fence === el.parentElement && isPageShell(fence)) return true;
|
|
4512
|
+
if (!wrapped) return false;
|
|
4513
|
+
const node = el;
|
|
4514
|
+
return el.tagName === "FOOTER" ? closesMain(node, fence, "last") : isPageShell(fence, true) && closesMain(node, fence, "first");
|
|
4512
4515
|
}
|
|
4513
4516
|
var INERT_TAGS = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT", "LINK"]);
|
|
4514
|
-
|
|
4515
|
-
|
|
4517
|
+
var shown = (el) => Array.from(el.children).filter((k) => !INERT_TAGS.has(k.tagName));
|
|
4518
|
+
function closesMain(el, main, end) {
|
|
4519
|
+
for (let at = el; at !== main; at = at.parentElement) {
|
|
4520
|
+
const parent = at.parentElement;
|
|
4521
|
+
if (!parent || parent !== main && parent.tagName !== "DIV") return false;
|
|
4522
|
+
const kids = shown(parent);
|
|
4523
|
+
if ((end === "first" ? kids[0] : kids[kids.length - 1]) !== at) return false;
|
|
4524
|
+
}
|
|
4525
|
+
return true;
|
|
4526
|
+
}
|
|
4527
|
+
var endOf = (main, end) => {
|
|
4528
|
+
let at = main;
|
|
4529
|
+
do {
|
|
4530
|
+
const kids = shown(at);
|
|
4531
|
+
at = end === "first" ? kids[0] : kids[kids.length - 1];
|
|
4532
|
+
} while (at?.tagName === "DIV");
|
|
4533
|
+
return at;
|
|
4534
|
+
};
|
|
4535
|
+
function isPageShell(main, wrapped = false) {
|
|
4536
|
+
const kids = shown(main);
|
|
4537
|
+
if (wrapped) {
|
|
4538
|
+
const first2 = endOf(main, "first")?.tagName;
|
|
4539
|
+
return kids.length > 1 && (first2 === "HEADER" || first2 === "NAV") && endOf(main, "last")?.tagName === "FOOTER";
|
|
4540
|
+
}
|
|
4516
4541
|
const first = kids[0]?.tagName;
|
|
4517
4542
|
return (first === "HEADER" || first === "NAV") && kids.length > 1 && kids[kids.length - 1].tagName === "FOOTER";
|
|
4518
4543
|
}
|
|
4519
|
-
function locatorFor(el, region, landmarks = false) {
|
|
4544
|
+
function locatorFor(el, region, landmarks = false, wrapped = false) {
|
|
4520
4545
|
const ancestors = [];
|
|
4521
4546
|
for (
|
|
4522
4547
|
let parent = el.parentElement;
|
|
4523
4548
|
// The cast is the overloads' promise: `landmarks` is only ever true for a `LandmarkChainElement`,
|
|
4524
4549
|
// and `isChromeLandmark` never reads past the tag with it false.
|
|
4525
|
-
parent && parent.tagName !== "BODY" && !isChromeLandmark(parent, landmarks);
|
|
4550
|
+
parent && parent.tagName !== "BODY" && !isChromeLandmark(parent, landmarks, wrapped);
|
|
4526
4551
|
parent = parent.parentElement
|
|
4527
4552
|
) {
|
|
4528
4553
|
ancestors.unshift(parent.tagName.toLowerCase());
|
|
@@ -4541,15 +4566,15 @@ function siblingIndexOf(el) {
|
|
|
4541
4566
|
for (let s = linked.previousElementSibling; s; s = s.previousElementSibling ?? null) i += 1;
|
|
4542
4567
|
return i;
|
|
4543
4568
|
}
|
|
4544
|
-
function locatorPath(el, landmarks = false) {
|
|
4569
|
+
function locatorPath(el, landmarks = false, wrapped = false) {
|
|
4545
4570
|
const path = [];
|
|
4546
|
-
for (let parent = el.parentElement; parent && parent.tagName !== "BODY" && !isChromeLandmark(parent, landmarks); parent = parent.parentElement) {
|
|
4571
|
+
for (let parent = el.parentElement; parent && parent.tagName !== "BODY" && !isChromeLandmark(parent, landmarks, wrapped); parent = parent.parentElement) {
|
|
4547
4572
|
path.unshift(parent.parentElement ? siblingIndexOf(parent) : 0);
|
|
4548
4573
|
}
|
|
4549
4574
|
return path;
|
|
4550
4575
|
}
|
|
4551
4576
|
var LOCATOR_PATH = /* @__PURE__ */ Symbol.for("bcms.locator.path");
|
|
4552
|
-
function landmarkRegions(doc, dialogs = false, landmarks = false) {
|
|
4577
|
+
function landmarkRegions(doc, dialogs = false, landmarks = false, wrapped = false) {
|
|
4553
4578
|
const counts = /* @__PURE__ */ new Map();
|
|
4554
4579
|
const out = [];
|
|
4555
4580
|
const selector = dialogs ? `${LANDMARK_SELECTOR},${DIALOG_SELECTOR}` : LANDMARK_SELECTOR;
|
|
@@ -4557,14 +4582,14 @@ function landmarkRegions(doc, dialogs = false, landmarks = false) {
|
|
|
4557
4582
|
if (!landmarks) {
|
|
4558
4583
|
if (el.parentElement?.closest(selector)) continue;
|
|
4559
4584
|
} else if (LANDMARK_TAGS.has(el.tagName)) {
|
|
4560
|
-
if (!isChromeLandmark(el, true) || el.parentElement?.closest(selector)) continue;
|
|
4585
|
+
if (!isChromeLandmark(el, true, wrapped) || el.parentElement?.closest(selector)) continue;
|
|
4561
4586
|
} else if (el.parentElement?.closest(DIALOG_SELECTOR)) {
|
|
4562
4587
|
continue;
|
|
4563
4588
|
}
|
|
4564
|
-
const
|
|
4565
|
-
const n = counts.get(
|
|
4566
|
-
counts.set(
|
|
4567
|
-
out.push({ slot: `${
|
|
4589
|
+
const name2 = !LANDMARK_TAGS.has(el.tagName) && el.matches(DIALOG_SELECTOR) ? "dialog" : el.tagName.toLowerCase();
|
|
4590
|
+
const n = counts.get(name2) ?? 0;
|
|
4591
|
+
counts.set(name2, n + 1);
|
|
4592
|
+
out.push({ slot: `${name2}#${n}`, el });
|
|
4568
4593
|
}
|
|
4569
4594
|
return out;
|
|
4570
4595
|
}
|
|
@@ -4574,6 +4599,383 @@ function regionOf(regions, el) {
|
|
|
4574
4599
|
return slot;
|
|
4575
4600
|
}
|
|
4576
4601
|
|
|
4602
|
+
// src/local-setup.ts
|
|
4603
|
+
var LOCAL_SETUP_VERSION = 1;
|
|
4604
|
+
var SITE_MAP_VERSION = 3;
|
|
4605
|
+
var SITE_MAP_VERSIONS = [1, 2, 3];
|
|
4606
|
+
var LOCAL_FRAMEWORKS = ["astro", "next", "sveltekit", "nuxt", "react", "html"];
|
|
4607
|
+
var LAYOUT_ROLES = ["layout", "header", "footer", "nav"];
|
|
4608
|
+
var BLOCKED_REASONS = [
|
|
4609
|
+
"CLIENT_ONLY_ISLAND",
|
|
4610
|
+
"INNER_HTML",
|
|
4611
|
+
"COMPUTED_STRING",
|
|
4612
|
+
"DIALECT_UNSUPPORTED",
|
|
4613
|
+
"FILE_TOO_LARGE",
|
|
4614
|
+
"OVER_ROUTE_CAP",
|
|
4615
|
+
"UNRESOLVED_IMPORT",
|
|
4616
|
+
"PARSE_FAILED",
|
|
4617
|
+
"I18N_DICTIONARY"
|
|
4618
|
+
];
|
|
4619
|
+
var MAX_SITE_MAP_BYTES = 4 * 1024 * 1024;
|
|
4620
|
+
var MAX_LOCAL_SETUP_BYTES = 20 * 1024 * 1024;
|
|
4621
|
+
var LOCAL_SETUP_LIMITS = {
|
|
4622
|
+
routes: 2e4,
|
|
4623
|
+
templates: 5e3,
|
|
4624
|
+
components: 1e4,
|
|
4625
|
+
collections: 500,
|
|
4626
|
+
entryFiles: 2e4,
|
|
4627
|
+
fieldsPerCollection: 500,
|
|
4628
|
+
forms: 2e3,
|
|
4629
|
+
blocked: 5e3,
|
|
4630
|
+
partialDefault: 500,
|
|
4631
|
+
pages: 2e4,
|
|
4632
|
+
entriesPerCollection: 2e4,
|
|
4633
|
+
evidenceRows: 2e4,
|
|
4634
|
+
timings: 64,
|
|
4635
|
+
styleTokens: 2e3,
|
|
4636
|
+
/** Per `styleGuide.used` group, and the families the typography names. */
|
|
4637
|
+
styleValues: 50,
|
|
4638
|
+
/** Section candidates per template, and sections per page in the manifest. */
|
|
4639
|
+
sections: 200,
|
|
4640
|
+
/** Field keys one section holds. */
|
|
4641
|
+
sectionFields: 500
|
|
4642
|
+
};
|
|
4643
|
+
var MAX_ISSUES = 20;
|
|
4644
|
+
var SECTION_KINDS = ["element", "component", "expression", "fragment", "text"];
|
|
4645
|
+
var STYLE_TOKEN_GROUPS = ["color", "font", "fontSize", "fontWeight", "lineHeight", "letterSpacing", "spacing", "radius", "shadow", "breakpoint", "other"];
|
|
4646
|
+
var STYLE_USED_GROUPS = ["color", "fontSize", "spacing", "radius", "shadow", "breakpoint"];
|
|
4647
|
+
var fail = (out, at, message) => {
|
|
4648
|
+
if (out.length < MAX_ISSUES) out.push({ path: at || "(root)", message });
|
|
4649
|
+
};
|
|
4650
|
+
var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
4651
|
+
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
4652
|
+
var HEX_SHA = /^[0-9a-f]{7,64}$/;
|
|
4653
|
+
var CODE = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
4654
|
+
var REPO_PATH = 2048;
|
|
4655
|
+
var NAME = 256;
|
|
4656
|
+
var str = (max, min = 0) => (v, at, out) => {
|
|
4657
|
+
if (typeof v !== "string") fail(out, at, "must be a string");
|
|
4658
|
+
else if (v.length < min || v.length > max) fail(out, at, `must be ${min}-${max} characters (got ${v.length})`);
|
|
4659
|
+
};
|
|
4660
|
+
var matching = (re, what) => (v, at, out) => {
|
|
4661
|
+
if (typeof v !== "string" || !re.test(v)) fail(out, at, `must be ${what}`);
|
|
4662
|
+
};
|
|
4663
|
+
var repoPath = (v, at, out) => {
|
|
4664
|
+
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`);
|
|
4665
|
+
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)})`);
|
|
4666
|
+
};
|
|
4667
|
+
var route = (v, at, out) => {
|
|
4668
|
+
if (typeof v !== "string" || !v.startsWith("/") || v.length > REPO_PATH) fail(out, at, "must be a route starting with /");
|
|
4669
|
+
};
|
|
4670
|
+
var count = (max = Number.MAX_SAFE_INTEGER) => (v, at, out) => {
|
|
4671
|
+
if (typeof v !== "number" || !Number.isInteger(v) || v < 0 || v > max) fail(out, at, `must be a whole number from 0 to ${max}`);
|
|
4672
|
+
};
|
|
4673
|
+
var positive = (v, at, out) => {
|
|
4674
|
+
if (typeof v !== "number" || !Number.isInteger(v) || v < 1) fail(out, at, "must be a whole number from 1");
|
|
4675
|
+
};
|
|
4676
|
+
var bool = (v, at, out) => {
|
|
4677
|
+
if (typeof v !== "boolean") fail(out, at, "must be true or false");
|
|
4678
|
+
};
|
|
4679
|
+
var literal = (value) => (v, at, out) => {
|
|
4680
|
+
if (v !== value) fail(out, at, `must be ${JSON.stringify(value)}`);
|
|
4681
|
+
};
|
|
4682
|
+
var oneOf = (values) => (v, at, out) => {
|
|
4683
|
+
if (!values.includes(v)) fail(out, at, `must be one of ${values.join(", ")}`);
|
|
4684
|
+
};
|
|
4685
|
+
var nullable = (check) => (v, at, out) => {
|
|
4686
|
+
if (v !== null) check(v, at, out);
|
|
4687
|
+
};
|
|
4688
|
+
var list = (max, item) => (v, at, out) => {
|
|
4689
|
+
if (!Array.isArray(v)) return fail(out, at, "must be a list");
|
|
4690
|
+
if (v.length > max) return fail(out, at, `must hold at most ${max} items (got ${v.length})`);
|
|
4691
|
+
for (let i = 0; i < v.length && out.length < MAX_ISSUES; i += 1) item(v[i], `${at}[${i}]`, out);
|
|
4692
|
+
};
|
|
4693
|
+
var keysSafe = (v, at, out) => {
|
|
4694
|
+
for (const k of Object.keys(v)) if (UNSAFE_KEYS.has(k)) fail(out, `${at}.${k}`, "is not an allowed key");
|
|
4695
|
+
};
|
|
4696
|
+
var record = (maxKeys, value) => (v, at, out) => {
|
|
4697
|
+
if (!isObject(v)) return fail(out, at, "must be an object");
|
|
4698
|
+
const keys = Object.keys(v);
|
|
4699
|
+
if (keys.length > maxKeys) return fail(out, at, `must hold at most ${maxKeys} keys (got ${keys.length})`);
|
|
4700
|
+
keysSafe(v, at, out);
|
|
4701
|
+
for (const k of keys) {
|
|
4702
|
+
if (k.length === 0 || k.length > NAME) fail(out, `${at}.${k.slice(0, 40)}`, `key must be 1-${NAME} characters`);
|
|
4703
|
+
value(v[k], `${at}.${k}`, out);
|
|
4704
|
+
}
|
|
4705
|
+
};
|
|
4706
|
+
var object = (required, optional = {}) => (v, at, out) => {
|
|
4707
|
+
if (!isObject(v)) return fail(out, at, "must be an object");
|
|
4708
|
+
keysSafe(v, at, out);
|
|
4709
|
+
for (const [k, check] of Object.entries(required)) {
|
|
4710
|
+
if (!(k in v)) fail(out, `${at}.${k}`, "is required");
|
|
4711
|
+
else check(v[k], `${at}.${k}`, out);
|
|
4712
|
+
}
|
|
4713
|
+
for (const [k, check] of Object.entries(optional)) if (k in v && v[k] !== void 0) check(v[k], `${at}.${k}`, out);
|
|
4714
|
+
};
|
|
4715
|
+
var anyObject = (v, at, out) => {
|
|
4716
|
+
if (!isObject(v)) fail(out, at, "must be an object");
|
|
4717
|
+
else keysSafe(v, at, out);
|
|
4718
|
+
};
|
|
4719
|
+
var name = str(NAME, 1);
|
|
4720
|
+
var names = (max) => list(max, name);
|
|
4721
|
+
var literals = object({ text: count(), image: count(), link: count(), video: count() });
|
|
4722
|
+
var SECTION_TYPE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
4723
|
+
var sectionType = (v, at, out) => {
|
|
4724
|
+
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)");
|
|
4725
|
+
};
|
|
4726
|
+
var candidate = (v, at, out) => {
|
|
4727
|
+
object({
|
|
4728
|
+
id: name,
|
|
4729
|
+
file: repoPath,
|
|
4730
|
+
start: count(),
|
|
4731
|
+
end: count(),
|
|
4732
|
+
line: positive,
|
|
4733
|
+
kind: oneOf(SECTION_KINDS),
|
|
4734
|
+
sectionType,
|
|
4735
|
+
label: str(200, 1),
|
|
4736
|
+
fields: names(LOCAL_SETUP_LIMITS.sectionFields),
|
|
4737
|
+
component: nullable(name),
|
|
4738
|
+
props: names(500),
|
|
4739
|
+
repeats: names(LOCAL_SETUP_LIMITS.templates),
|
|
4740
|
+
variants: names(LOCAL_SETUP_LIMITS.components)
|
|
4741
|
+
})(v, at, out);
|
|
4742
|
+
if (isObject(v) && typeof v.start === "number" && typeof v.end === "number" && v.end <= v.start) fail(out, `${at}.end`, "must be after start");
|
|
4743
|
+
};
|
|
4744
|
+
var template = (v, at, out) => {
|
|
4745
|
+
object(
|
|
4746
|
+
{ id: name, file: repoPath, pattern: route, components: names(LOCAL_SETUP_LIMITS.components), literals, collection: nullable(name) },
|
|
4747
|
+
{
|
|
4748
|
+
routes: list(LOCAL_SETUP_LIMITS.routes, route),
|
|
4749
|
+
routeCount: count(LOCAL_SETUP_LIMITS.routes),
|
|
4750
|
+
sections: list(LOCAL_SETUP_LIMITS.sections, candidate),
|
|
4751
|
+
sectionsRefused: object({ code: matching(CODE, "an UPPER_SNAKE reason code"), message: str(1024) }),
|
|
4752
|
+
sectionsWrapped: bool
|
|
4753
|
+
}
|
|
4754
|
+
)(v, at, out);
|
|
4755
|
+
if (isObject(v) && "routes" in v === "routeCount" in v) fail(out, at, "must carry exactly one of routes and routeCount");
|
|
4756
|
+
};
|
|
4757
|
+
var color = object({ value: matching(/^#[0-9A-F]{6}$/, "a #RRGGBB colour"), token: nullable(name) });
|
|
4758
|
+
var styleGuide = object({
|
|
4759
|
+
tokens: list(
|
|
4760
|
+
LOCAL_SETUP_LIMITS.styleTokens,
|
|
4761
|
+
object({ name, group: oneOf(STYLE_TOKEN_GROUPS), value: nullable(str(1024)), source: repoPath, scope: str(NAME, 1) }, { alias: name })
|
|
4762
|
+
),
|
|
4763
|
+
primary: object({ primary: nullable(color), accent: nullable(color), background: nullable(color), text: nullable(color) }),
|
|
4764
|
+
typography: object({
|
|
4765
|
+
heading: nullable(name),
|
|
4766
|
+
body: nullable(name),
|
|
4767
|
+
families: names(LOCAL_SETUP_LIMITS.styleValues),
|
|
4768
|
+
faces: list(200, object({ family: name, source: repoPath }, { weight: str(16, 1), style: str(16, 1) })),
|
|
4769
|
+
scale: list(100, object({ name, size: str(256, 1), source: repoPath }))
|
|
4770
|
+
}),
|
|
4771
|
+
used: object(Object.fromEntries(STYLE_USED_GROUPS.map((g) => [g, list(LOCAL_SETUP_LIMITS.styleValues, str(256, 1))]))),
|
|
4772
|
+
components: object({ buttons: names(LOCAL_SETUP_LIMITS.components), cards: names(LOCAL_SETUP_LIMITS.components), headings: names(LOCAL_SETUP_LIMITS.components) }),
|
|
4773
|
+
reference: nullable(object({ route, file: repoPath, components: names(LOCAL_SETUP_LIMITS.components) })),
|
|
4774
|
+
sources: list(500, repoPath)
|
|
4775
|
+
});
|
|
4776
|
+
var siteMapShape = object({
|
|
4777
|
+
version: oneOf(SITE_MAP_VERSIONS),
|
|
4778
|
+
toolVersion: str(64, 1),
|
|
4779
|
+
sha: nullable(matching(HEX_SHA, "a git commit sha (7-64 hex)")),
|
|
4780
|
+
framework: oneOf(LOCAL_FRAMEWORKS),
|
|
4781
|
+
build: object({ command: nullable(str(1024, 1)), outDir: nullable(repoPath) }),
|
|
4782
|
+
templates: list(LOCAL_SETUP_LIMITS.templates, template),
|
|
4783
|
+
components: list(
|
|
4784
|
+
LOCAL_SETUP_LIMITS.components,
|
|
4785
|
+
object({ id: name, file: repoPath, usedBy: names(LOCAL_SETUP_LIMITS.templates), props: names(500), literals, sectionCandidate: bool })
|
|
4786
|
+
),
|
|
4787
|
+
layout: list(200, object({ file: repoPath, role: oneOf(LAYOUT_ROLES) })),
|
|
4788
|
+
collections: list(
|
|
4789
|
+
LOCAL_SETUP_LIMITS.collections,
|
|
4790
|
+
object({
|
|
4791
|
+
id: name,
|
|
4792
|
+
source: repoPath,
|
|
4793
|
+
fields: list(LOCAL_SETUP_LIMITS.fieldsPerCollection, object({ key: name, type: str(64, 1) }, { required: bool })),
|
|
4794
|
+
entries: count(LOCAL_SETUP_LIMITS.entriesPerCollection),
|
|
4795
|
+
files: list(LOCAL_SETUP_LIMITS.entryFiles, repoPath)
|
|
4796
|
+
})
|
|
4797
|
+
),
|
|
4798
|
+
locales: object({ default: nullable(str(35, 1)), locales: list(500, str(35, 1)), dictionaries: list(2e3, repoPath), readBy: names(LOCAL_SETUP_LIMITS.templates) }),
|
|
4799
|
+
forms: list(
|
|
4800
|
+
LOCAL_SETUP_LIMITS.forms,
|
|
4801
|
+
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) })
|
|
4802
|
+
),
|
|
4803
|
+
media: object({ images: count(), videos: count(), remoteHosts: list(500, str(253, 1)), overPolicy: list(5e3, object({ file: repoPath, bytes: count() })) }),
|
|
4804
|
+
styles: object({ tailwind: bool, files: list(500, repoPath), colors: list(500, object({ name, value: str(256, 1) })) }),
|
|
4805
|
+
blocked: list(
|
|
4806
|
+
LOCAL_SETUP_LIMITS.blocked,
|
|
4807
|
+
object({ file: repoPath, reason: matching(CODE, "an UPPER_SNAKE reason code") }, { line: positive, message: str(1024) })
|
|
4808
|
+
),
|
|
4809
|
+
partialDefault: list(LOCAL_SETUP_LIMITS.partialDefault, route)
|
|
4810
|
+
}, { styleGuide });
|
|
4811
|
+
function siteMapRefs(map, at, out) {
|
|
4812
|
+
const unique = (ids, where) => {
|
|
4813
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4814
|
+
ids.forEach((id, i) => {
|
|
4815
|
+
if (seen.has(id)) fail(out, `${at}.${where}[${i}].id`, `"${id.slice(0, 80)}" is not unique`);
|
|
4816
|
+
seen.add(id);
|
|
4817
|
+
});
|
|
4818
|
+
return seen;
|
|
4819
|
+
};
|
|
4820
|
+
const templates = unique(map.templates.map((t) => t.id), "templates");
|
|
4821
|
+
const components = unique(map.components.map((c) => c.id), "components");
|
|
4822
|
+
const collections = unique(map.collections.map((c) => c.id), "collections");
|
|
4823
|
+
const known = (set, ids, where, what) => ids.forEach((id, i) => {
|
|
4824
|
+
if (!set.has(id)) fail(out, `${at}.${where}[${i}]`, `names ${what} "${id.slice(0, 80)}", which is not in the map`);
|
|
4825
|
+
});
|
|
4826
|
+
let routes = 0;
|
|
4827
|
+
map.templates.forEach((t, i) => {
|
|
4828
|
+
known(components, t.components, `templates[${i}].components`, "the component");
|
|
4829
|
+
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`);
|
|
4830
|
+
routes += t.routes?.length ?? t.routeCount ?? 0;
|
|
4831
|
+
});
|
|
4832
|
+
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`);
|
|
4833
|
+
map.templates.forEach((t, i) => {
|
|
4834
|
+
const ids = /* @__PURE__ */ new Set();
|
|
4835
|
+
(t.sections ?? []).forEach((c, n) => {
|
|
4836
|
+
const where = `templates[${i}].sections[${n}]`;
|
|
4837
|
+
if (ids.has(c.id)) fail(out, `${at}.${where}.id`, `"${c.id.slice(0, 80)}" is not unique in its template`);
|
|
4838
|
+
ids.add(c.id);
|
|
4839
|
+
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`);
|
|
4840
|
+
known(templates, c.repeats, `${where}.repeats`, "the template");
|
|
4841
|
+
known(components, c.variants, `${where}.variants`, "the component");
|
|
4842
|
+
});
|
|
4843
|
+
});
|
|
4844
|
+
map.components.forEach((c, i) => known(templates, c.usedBy, `components[${i}].usedBy`, "the template"));
|
|
4845
|
+
map.forms.forEach((f, i) => known(templates, f.templates, `forms[${i}].templates`, "the template"));
|
|
4846
|
+
known(templates, map.locales.readBy, "locales.readBy", "the template");
|
|
4847
|
+
const guide = map.styleGuide;
|
|
4848
|
+
if (guide) {
|
|
4849
|
+
const rendered = /* @__PURE__ */ new Set([...components, ...templates]);
|
|
4850
|
+
for (const kind of ["buttons", "cards", "headings"]) known(rendered, guide.components[kind], `styleGuide.components.${kind}`, "the component");
|
|
4851
|
+
if (guide.reference) {
|
|
4852
|
+
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`);
|
|
4853
|
+
known(components, guide.reference.components, "styleGuide.reference.components", "the component");
|
|
4854
|
+
}
|
|
4855
|
+
}
|
|
4856
|
+
}
|
|
4857
|
+
var proofRow = object({ path: str(512, 1) }, { route, file: str(REPO_PATH), line: positive, reason: str(1024) });
|
|
4858
|
+
var proofRows = list(LOCAL_SETUP_LIMITS.evidenceRows, proofRow);
|
|
4859
|
+
var manifestShape = object({
|
|
4860
|
+
version: literal(LOCAL_SETUP_VERSION),
|
|
4861
|
+
toolVersion: str(64, 1),
|
|
4862
|
+
sha: matching(HEX_SHA, "a git commit sha (7-64 hex)"),
|
|
4863
|
+
framework: oneOf(LOCAL_FRAMEWORKS),
|
|
4864
|
+
scope: (v, at, out) => {
|
|
4865
|
+
if (isObject(v) && v.mode === "full") return;
|
|
4866
|
+
if (isObject(v) && v.mode === "partial") return list(LOCAL_SETUP_LIMITS.routes, route)(v.routes, `${at}.routes`, out);
|
|
4867
|
+
fail(out, at, 'must be { mode: "full" } or { mode: "partial", routes: [...] }');
|
|
4868
|
+
},
|
|
4869
|
+
siteMap: siteMapShape,
|
|
4870
|
+
doc: object(
|
|
4871
|
+
{},
|
|
4872
|
+
{
|
|
4873
|
+
schema: record(LOCAL_SETUP_LIMITS.pages, object({ fields: list(LOCAL_SETUP_LIMITS.fieldsPerCollection, anyObject) }, { name: str(NAME) })),
|
|
4874
|
+
collections: record(LOCAL_SETUP_LIMITS.collections, list(LOCAL_SETUP_LIMITS.entriesPerCollection, object({ slug: str(NAME, 1), data: anyObject }, { status: oneOf(["draft", "published"]) }))),
|
|
4875
|
+
derivedCollections: literal(true),
|
|
4876
|
+
forms: list(LOCAL_SETUP_LIMITS.forms, anyObject),
|
|
4877
|
+
pages: list(LOCAL_SETUP_LIMITS.pages, anyObject),
|
|
4878
|
+
components: list(LOCAL_SETUP_LIMITS.components, anyObject)
|
|
4879
|
+
}
|
|
4880
|
+
),
|
|
4881
|
+
receipt: object({
|
|
4882
|
+
briefDigest: matching(/^sha256:[0-9a-f]{64}$/, "a sha256: brief digest"),
|
|
4883
|
+
paths: object({ declared: count(), rewritten: count(), alreadyDeclared: count(), pending: list(LOCAL_SETUP_LIMITS.routes, anyObject) })
|
|
4884
|
+
}),
|
|
4885
|
+
evidence: object({
|
|
4886
|
+
xray: list(
|
|
4887
|
+
LOCAL_SETUP_LIMITS.evidenceRows,
|
|
4888
|
+
object({ route, template: nullable(name), visible: count(), unaddressable: count(), unbound: list(500, object({ section: str(NAME), tag: str(32), text: str(256) })) })
|
|
4889
|
+
),
|
|
4890
|
+
proof: object({ sha: nullable(matching(HEX_SHA, "a git commit sha")), matched: count(), formatted: count(), indirect: proofRows, mismatched: proofRows, inert: proofRows, conflicts: proofRows }),
|
|
4891
|
+
renderEqual: list(LOCAL_SETUP_LIMITS.evidenceRows, object({ route, equal: bool }, { difference: object({ at: count(), was: str(512), now: str(512) }) }))
|
|
4892
|
+
}),
|
|
4893
|
+
timings: record(LOCAL_SETUP_LIMITS.timings, count())
|
|
4894
|
+
}, {
|
|
4895
|
+
sections: list(
|
|
4896
|
+
LOCAL_SETUP_LIMITS.pages,
|
|
4897
|
+
object(
|
|
4898
|
+
{
|
|
4899
|
+
page: matching(/^[a-z0-9][a-z0-9-/]{0,254}$/, "a page slug"),
|
|
4900
|
+
file: repoPath,
|
|
4901
|
+
sections: list(
|
|
4902
|
+
LOCAL_SETUP_LIMITS.sections,
|
|
4903
|
+
object({ id: name, name: str(200, 1), sectionType }, { variant: str(120, 1), component: nullable(name) })
|
|
4904
|
+
)
|
|
4905
|
+
},
|
|
4906
|
+
{ template: bool }
|
|
4907
|
+
)
|
|
4908
|
+
)
|
|
4909
|
+
});
|
|
4910
|
+
function utf8Bytes(s) {
|
|
4911
|
+
let n = 0;
|
|
4912
|
+
for (let i = 0; i < s.length; i += 1) {
|
|
4913
|
+
const c = s.charCodeAt(i);
|
|
4914
|
+
if (c < 128) n += 1;
|
|
4915
|
+
else if (c < 2048) n += 2;
|
|
4916
|
+
else if (c >= 55296 && c <= 56319) {
|
|
4917
|
+
n += 4;
|
|
4918
|
+
i += 1;
|
|
4919
|
+
} else n += 3;
|
|
4920
|
+
}
|
|
4921
|
+
return n;
|
|
4922
|
+
}
|
|
4923
|
+
function parsed(input, maxBytes, out) {
|
|
4924
|
+
if (typeof input !== "string") return input;
|
|
4925
|
+
const bytes = utf8Bytes(input);
|
|
4926
|
+
if (bytes > maxBytes) {
|
|
4927
|
+
fail(out, "", `is ${bytes} bytes; the cap is ${maxBytes}`);
|
|
4928
|
+
return void 0;
|
|
4929
|
+
}
|
|
4930
|
+
try {
|
|
4931
|
+
return JSON.parse(input);
|
|
4932
|
+
} catch (err) {
|
|
4933
|
+
fail(out, "", `is not JSON: ${err instanceof Error ? err.message.slice(0, 200) : "unreadable"}`);
|
|
4934
|
+
return void 0;
|
|
4935
|
+
}
|
|
4936
|
+
}
|
|
4937
|
+
function versionIssue(v, known) {
|
|
4938
|
+
if (!isObject(v)) return { path: "(root)", message: "must be an object" };
|
|
4939
|
+
const newest = known[known.length - 1];
|
|
4940
|
+
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}.` };
|
|
4941
|
+
}
|
|
4942
|
+
function parseSiteMap(input) {
|
|
4943
|
+
const out = [];
|
|
4944
|
+
const v = parsed(input, MAX_SITE_MAP_BYTES, out);
|
|
4945
|
+
if (out.length) return { ok: false, issues: out };
|
|
4946
|
+
const version = versionIssue(v, SITE_MAP_VERSIONS);
|
|
4947
|
+
if (version) return { ok: false, issues: [version] };
|
|
4948
|
+
siteMapShape(v, "", out);
|
|
4949
|
+
if (!out.length) siteMapRefs(v, "", out);
|
|
4950
|
+
return out.length ? { ok: false, issues: out.map(rooted) } : { ok: true, value: v };
|
|
4951
|
+
}
|
|
4952
|
+
function parseLocalSetupManifest(input) {
|
|
4953
|
+
const out = [];
|
|
4954
|
+
const v = parsed(input, MAX_LOCAL_SETUP_BYTES, out);
|
|
4955
|
+
if (out.length) return { ok: false, issues: out };
|
|
4956
|
+
const version = versionIssue(v, [LOCAL_SETUP_VERSION]);
|
|
4957
|
+
if (version) return { ok: false, issues: [version] };
|
|
4958
|
+
manifestShape(v, "", out);
|
|
4959
|
+
if (!out.length) {
|
|
4960
|
+
const m = v;
|
|
4961
|
+
siteMapRefs(m.siteMap, ".siteMap", out);
|
|
4962
|
+
if (m.siteMap.framework !== m.framework) fail(out, ".framework", `is ${m.framework}, but the site map says ${m.siteMap.framework}`);
|
|
4963
|
+
const pagesSeen = /* @__PURE__ */ new Set();
|
|
4964
|
+
(m.sections ?? []).forEach((p, i) => {
|
|
4965
|
+
const key = `${p.template === true ? "template:" : ""}${p.page}`;
|
|
4966
|
+
if (pagesSeen.has(key)) fail(out, `.sections[${i}].page`, `"${p.page}" is sent twice`);
|
|
4967
|
+
pagesSeen.add(key);
|
|
4968
|
+
const ids = /* @__PURE__ */ new Set();
|
|
4969
|
+
p.sections.forEach((x, n) => {
|
|
4970
|
+
if (ids.has(x.id)) fail(out, `.sections[${i}].sections[${n}].id`, `"${x.id.slice(0, 80)}" is not unique on its page`);
|
|
4971
|
+
ids.add(x.id);
|
|
4972
|
+
});
|
|
4973
|
+
});
|
|
4974
|
+
}
|
|
4975
|
+
return out.length ? { ok: false, issues: out.map(rooted) } : { ok: true, value: v };
|
|
4976
|
+
}
|
|
4977
|
+
var rooted = (i) => ({ ...i, path: i.path.startsWith(".") ? i.path.slice(1) : i.path });
|
|
4978
|
+
|
|
4577
4979
|
// src/sections.ts
|
|
4578
4980
|
var TAG_HEADS = /* @__PURE__ */ new Set([
|
|
4579
4981
|
"h1",
|
|
@@ -4866,7 +5268,9 @@ var UI_REFUSAL_CODES = {
|
|
|
4866
5268
|
"size_exceeded",
|
|
4867
5269
|
// CMS-stored UI (dock-ui.ts): an import off the allow-list; one name in both the repo and the CMS
|
|
4868
5270
|
"import_denied",
|
|
4869
|
-
"name_conflict"
|
|
5271
|
+
"name_conflict",
|
|
5272
|
+
// CMS-stored UI: a raw form element where the kit has the control (dock UI is kit only)
|
|
5273
|
+
"raw_control"
|
|
4870
5274
|
],
|
|
4871
5275
|
protocol: ["unsupported", "handshake_timeout", "origin_mismatch", "write_denied"],
|
|
4872
5276
|
runtime: ["crashed", "blank", "csp_violation"],
|
|
@@ -4922,9 +5326,9 @@ function canonicalJson(value) {
|
|
|
4922
5326
|
if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
4923
5327
|
if (Array.isArray(value)) return `[${value.map((child) => skipped(child) ? "null" : canonicalJson(child)).join(",")}]`;
|
|
4924
5328
|
if (typeof value === "object") {
|
|
4925
|
-
const
|
|
4926
|
-
const keys = Object.keys(
|
|
4927
|
-
return `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJson(
|
|
5329
|
+
const record2 = value;
|
|
5330
|
+
const keys = Object.keys(record2).filter((key) => !skipped(record2[key])).sort();
|
|
5331
|
+
return `{${keys.map((key) => `${JSON.stringify(key)}:${canonicalJson(record2[key])}`).join(",")}}`;
|
|
4928
5332
|
}
|
|
4929
5333
|
throw new TypeError(`Unsupported canonical JSON value: ${typeof value}`);
|
|
4930
5334
|
}
|
|
@@ -4953,7 +5357,7 @@ var isDockUiImportAllowed = (specifier) => {
|
|
|
4953
5357
|
if (specifier === "@bettercms-ai/dock-input") return true;
|
|
4954
5358
|
return specifier.startsWith("@bettercms-ai/kit/") && specifier.length > "@bettercms-ai/kit/".length;
|
|
4955
5359
|
};
|
|
4956
|
-
var dockUiMerkleKey = (
|
|
5360
|
+
var dockUiMerkleKey = (name2, version) => `cms:${name2}@${version}`;
|
|
4957
5361
|
|
|
4958
5362
|
// src/richtext-features.ts
|
|
4959
5363
|
var RICHTEXT_MARK_FEATURES = ["bold", "italic", "underline", "strikethrough", "code", "highlight"];
|
|
@@ -4991,13 +5395,13 @@ var RICHTEXT_FEATURE_ALIASES = {
|
|
|
4991
5395
|
headings: RICHTEXT_HEADING_FEATURES
|
|
4992
5396
|
};
|
|
4993
5397
|
var KNOWN = new Set(RICHTEXT_FEATURES);
|
|
4994
|
-
function normaliseRichTextFeatures(
|
|
5398
|
+
function normaliseRichTextFeatures(names2) {
|
|
4995
5399
|
const want = /* @__PURE__ */ new Set();
|
|
4996
5400
|
const unknown = [];
|
|
4997
|
-
for (const
|
|
4998
|
-
if (Object.hasOwn(RICHTEXT_FEATURE_ALIASES,
|
|
4999
|
-
else if (KNOWN.has(
|
|
5000
|
-
else if (!unknown.includes(
|
|
5401
|
+
for (const name2 of names2) {
|
|
5402
|
+
if (Object.hasOwn(RICHTEXT_FEATURE_ALIASES, name2)) for (const f of RICHTEXT_FEATURE_ALIASES[name2]) want.add(f);
|
|
5403
|
+
else if (KNOWN.has(name2)) want.add(name2);
|
|
5404
|
+
else if (!unknown.includes(name2)) unknown.push(name2);
|
|
5001
5405
|
}
|
|
5002
5406
|
return { features: RICHTEXT_FEATURES.filter((f) => want.has(f)), unknown };
|
|
5003
5407
|
}
|
|
@@ -5095,7 +5499,7 @@ function embedMarkerHtml(m) {
|
|
|
5095
5499
|
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
5500
|
}
|
|
5097
5501
|
var MARKER_RE = /<div\b([^>]*\bdata-bcms-embed="[^"]*"[^>]*)>\s*<\/div>/g;
|
|
5098
|
-
var attr = (attrs,
|
|
5502
|
+
var attr = (attrs, name2) => attrs.match(new RegExp(`\\b${name2}="([^"]*)"`))?.[1];
|
|
5099
5503
|
function parseEmbedMarkers(html) {
|
|
5100
5504
|
const out = [];
|
|
5101
5505
|
for (const m of html.matchAll(MARKER_RE)) {
|
|
@@ -5134,7 +5538,7 @@ function variantOptionsFromUnion(typeText) {
|
|
|
5134
5538
|
function evaluateShowIf(showIf, values, sourceTypes) {
|
|
5135
5539
|
const rules = Array.isArray(showIf?.rules) ? showIf.rules : [];
|
|
5136
5540
|
if (!rules.length) return true;
|
|
5137
|
-
const
|
|
5541
|
+
const str2 = (v) => String(v ?? "");
|
|
5138
5542
|
const test = (r) => {
|
|
5139
5543
|
const type = sourceTypes?.get(r.field);
|
|
5140
5544
|
if (sourceTypes && type === void 0) return true;
|
|
@@ -5148,13 +5552,13 @@ function evaluateShowIf(showIf, values, sourceTypes) {
|
|
|
5148
5552
|
if (!Number.isFinite(n) || !Number.isFinite(bound)) return false;
|
|
5149
5553
|
return r.op === "gt" ? n > bound : n < bound;
|
|
5150
5554
|
}
|
|
5151
|
-
const s = type === "boolean" || type === "toggle" ? String(raw === true || raw === "true") :
|
|
5555
|
+
const s = type === "boolean" || type === "toggle" ? String(raw === true || raw === "true") : str2(raw);
|
|
5152
5556
|
if (r.op === "in" || r.op === "notIn") {
|
|
5153
|
-
const hit = (Array.isArray(r.value) ? r.value : [r.value]).map(
|
|
5557
|
+
const hit = (Array.isArray(r.value) ? r.value : [r.value]).map(str2).includes(s);
|
|
5154
5558
|
return r.op === "in" ? hit : !hit;
|
|
5155
5559
|
}
|
|
5156
|
-
if (r.op === "neq") return s !==
|
|
5157
|
-
return s ===
|
|
5560
|
+
if (r.op === "neq") return s !== str2(r.value);
|
|
5561
|
+
return s === str2(r.value);
|
|
5158
5562
|
};
|
|
5159
5563
|
return showIf.match === "any" ? rules.some(test) : rules.every(test);
|
|
5160
5564
|
}
|
|
@@ -5165,6 +5569,546 @@ function isVariantVisible(prop, values, props) {
|
|
|
5165
5569
|
// src/heading-id.ts
|
|
5166
5570
|
var slugify = (s) => s.toLowerCase().normalize("NFKD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "section";
|
|
5167
5571
|
|
|
5572
|
+
// src/name-judge.ts
|
|
5573
|
+
var LABEL_CARRIER = {
|
|
5574
|
+
NAV: "navigation",
|
|
5575
|
+
BUTTON: "button",
|
|
5576
|
+
A: "link",
|
|
5577
|
+
IMG: "image",
|
|
5578
|
+
svg: "image",
|
|
5579
|
+
FIGURE: "image",
|
|
5580
|
+
PICTURE: "image",
|
|
5581
|
+
INPUT: "field",
|
|
5582
|
+
TEXTAREA: "field",
|
|
5583
|
+
SELECT: "field",
|
|
5584
|
+
HEADER: "header",
|
|
5585
|
+
FOOTER: "footer",
|
|
5586
|
+
ASIDE: "aside",
|
|
5587
|
+
SECTION: "section",
|
|
5588
|
+
H1: "heading",
|
|
5589
|
+
H2: "heading",
|
|
5590
|
+
H3: "heading",
|
|
5591
|
+
H4: "heading",
|
|
5592
|
+
H5: "heading",
|
|
5593
|
+
H6: "heading"
|
|
5594
|
+
};
|
|
5595
|
+
var ROLE_VOCABULARY = [.../* @__PURE__ */ new Set([
|
|
5596
|
+
// A top-level field's role in its section.
|
|
5597
|
+
"headline",
|
|
5598
|
+
"heading",
|
|
5599
|
+
"subheading",
|
|
5600
|
+
"eyebrow",
|
|
5601
|
+
"intro",
|
|
5602
|
+
"paragraph",
|
|
5603
|
+
"text",
|
|
5604
|
+
"primary-button",
|
|
5605
|
+
"secondary-button",
|
|
5606
|
+
"button",
|
|
5607
|
+
"button-label",
|
|
5608
|
+
"link",
|
|
5609
|
+
"home-link",
|
|
5610
|
+
"image",
|
|
5611
|
+
"icon",
|
|
5612
|
+
"logo",
|
|
5613
|
+
"background-image",
|
|
5614
|
+
"video-poster",
|
|
5615
|
+
"video",
|
|
5616
|
+
"embed",
|
|
5617
|
+
"audio",
|
|
5618
|
+
"body",
|
|
5619
|
+
"content",
|
|
5620
|
+
"copyright",
|
|
5621
|
+
"email",
|
|
5622
|
+
"phone",
|
|
5623
|
+
"price",
|
|
5624
|
+
"percentage",
|
|
5625
|
+
"number",
|
|
5626
|
+
"date",
|
|
5627
|
+
"stat-value",
|
|
5628
|
+
"stat-label",
|
|
5629
|
+
"quote",
|
|
5630
|
+
"attribution",
|
|
5631
|
+
"caption",
|
|
5632
|
+
"label",
|
|
5633
|
+
"summary",
|
|
5634
|
+
"address",
|
|
5635
|
+
"code",
|
|
5636
|
+
"term",
|
|
5637
|
+
"definition",
|
|
5638
|
+
"table-heading",
|
|
5639
|
+
"table-cell",
|
|
5640
|
+
"list-item",
|
|
5641
|
+
"list",
|
|
5642
|
+
"links",
|
|
5643
|
+
"band",
|
|
5644
|
+
// A column's role in its row.
|
|
5645
|
+
"title",
|
|
5646
|
+
"subtitle",
|
|
5647
|
+
"description",
|
|
5648
|
+
"value",
|
|
5649
|
+
// What a band's shape calls an element.
|
|
5650
|
+
"plan-name",
|
|
5651
|
+
"cents",
|
|
5652
|
+
"billing-period",
|
|
5653
|
+
"badge",
|
|
5654
|
+
"features",
|
|
5655
|
+
"question",
|
|
5656
|
+
"answer",
|
|
5657
|
+
"author",
|
|
5658
|
+
"role",
|
|
5659
|
+
// The parts of a plan's price object. @see foldPrice in derive-schema.ts
|
|
5660
|
+
"amount",
|
|
5661
|
+
"period",
|
|
5662
|
+
// What an attribute is, by what carries it.
|
|
5663
|
+
"tooltip",
|
|
5664
|
+
"placeholder",
|
|
5665
|
+
"image-description",
|
|
5666
|
+
"counter-target",
|
|
5667
|
+
"attribute",
|
|
5668
|
+
...Object.values(LABEL_CARRIER).map((carrier) => `${carrier}-label`),
|
|
5669
|
+
// What a list's rows are.
|
|
5670
|
+
"plans",
|
|
5671
|
+
"questions",
|
|
5672
|
+
"quotes",
|
|
5673
|
+
"testimonials",
|
|
5674
|
+
"stats",
|
|
5675
|
+
"logos",
|
|
5676
|
+
"cards",
|
|
5677
|
+
"items"
|
|
5678
|
+
])];
|
|
5679
|
+
var VOCABULARY = new Set(ROLE_VOCABULARY);
|
|
5680
|
+
var BOX_WORDS = /* @__PURE__ */ new Set([
|
|
5681
|
+
"wrap",
|
|
5682
|
+
"wrapper",
|
|
5683
|
+
"fixed",
|
|
5684
|
+
"sticky",
|
|
5685
|
+
"static",
|
|
5686
|
+
"container",
|
|
5687
|
+
"inner",
|
|
5688
|
+
"outer",
|
|
5689
|
+
"main",
|
|
5690
|
+
"content",
|
|
5691
|
+
"section",
|
|
5692
|
+
"block",
|
|
5693
|
+
"flex",
|
|
5694
|
+
"grid",
|
|
5695
|
+
"row",
|
|
5696
|
+
"col",
|
|
5697
|
+
"column",
|
|
5698
|
+
"columns",
|
|
5699
|
+
"box",
|
|
5700
|
+
"layout",
|
|
5701
|
+
"page",
|
|
5702
|
+
"body",
|
|
5703
|
+
"root",
|
|
5704
|
+
"app",
|
|
5705
|
+
"site",
|
|
5706
|
+
"isolate",
|
|
5707
|
+
"relative",
|
|
5708
|
+
"absolute",
|
|
5709
|
+
"group",
|
|
5710
|
+
"item",
|
|
5711
|
+
"items",
|
|
5712
|
+
"overflow",
|
|
5713
|
+
"hidden",
|
|
5714
|
+
"visible",
|
|
5715
|
+
"prose",
|
|
5716
|
+
"astro",
|
|
5717
|
+
"div",
|
|
5718
|
+
"area",
|
|
5719
|
+
"shell",
|
|
5720
|
+
"panel",
|
|
5721
|
+
"stack",
|
|
5722
|
+
"cluster",
|
|
5723
|
+
"frame",
|
|
5724
|
+
"band",
|
|
5725
|
+
"region"
|
|
5726
|
+
]);
|
|
5727
|
+
var PLACEHOLDER_WORDS = /* @__PURE__ */ new Set(["sec", "span"]);
|
|
5728
|
+
var GENERIC_ROLES = "text|paragraph|number|link|links|icon|image|item|items|list|attribute|span|element|logo|logos|stat|stats";
|
|
5729
|
+
var GENERIC_SCOPE = "(?:dialog|modal|popup|overlay|drawer)(?:\\s+\\d{1,3})?|section\\s+\\d{1,3}";
|
|
5730
|
+
var GENERIC_ROLE_NAME = new RegExp(
|
|
5731
|
+
`^(?:(?<scope>${GENERIC_SCOPE})\\s+)?(?:${GENERIC_ROLES})(?<n>\\s+\\d{1,3})?(?:\\s+(?:url|label))?$`,
|
|
5732
|
+
"i"
|
|
5733
|
+
);
|
|
5734
|
+
var WORD_ITEMS = new RegExp("^\\p{L}+\\s+items?$", "iu");
|
|
5735
|
+
function isArtifactName(name2) {
|
|
5736
|
+
const l = name2.trim();
|
|
5737
|
+
if (!l) return true;
|
|
5738
|
+
if (/^[a-z0-9]+([-_][a-z0-9]+)+$/.test(l) || /[[\]{}|]/.test(l)) return true;
|
|
5739
|
+
if (/\b(?=[a-z0-9]*\d)(?=[a-z0-9]*[a-z])[a-z0-9]{5,}\b/i.test(l) || /\d{5,}/.test(l)) return true;
|
|
5740
|
+
const counted = /^([a-z]+)[\s-]?\d*$/i.exec(l);
|
|
5741
|
+
if (counted !== null && (BOX_WORDS.has(counted[1].toLowerCase()) || PLACEHOLDER_WORDS.has(counted[1].toLowerCase()))) return true;
|
|
5742
|
+
const role = GENERIC_ROLE_NAME.exec(l);
|
|
5743
|
+
if (role && (role.groups?.scope || role.groups?.n)) return true;
|
|
5744
|
+
const head = /^(.+?)\s+›\s+/.exec(l)?.[1];
|
|
5745
|
+
if (head) {
|
|
5746
|
+
const headRole = GENERIC_ROLE_NAME.exec(head);
|
|
5747
|
+
if (headRole && (headRole.groups?.scope || headRole.groups?.n)) return true;
|
|
5748
|
+
}
|
|
5749
|
+
return WORD_ITEMS.test(l);
|
|
5750
|
+
}
|
|
5751
|
+
var isCountedName = (name2) => /\S\s+\d{1,3}$/.test(name2.trim());
|
|
5752
|
+
var TRAILING = /* @__PURE__ */ new Set(["a", "an", "the", "and", "or", "of", "to", "for", "with", "by", "in", "on", "at", "your", "our", "from", "is", "are"]);
|
|
5753
|
+
var PHRASE_MAX = 40;
|
|
5754
|
+
var FILLER_EN = [
|
|
5755
|
+
...TRAILING,
|
|
5756
|
+
"as",
|
|
5757
|
+
"into",
|
|
5758
|
+
"over",
|
|
5759
|
+
"than",
|
|
5760
|
+
"so",
|
|
5761
|
+
"but",
|
|
5762
|
+
"nor",
|
|
5763
|
+
"my",
|
|
5764
|
+
"their",
|
|
5765
|
+
"its",
|
|
5766
|
+
"his",
|
|
5767
|
+
"her",
|
|
5768
|
+
"we",
|
|
5769
|
+
"you",
|
|
5770
|
+
"it",
|
|
5771
|
+
"us",
|
|
5772
|
+
"they",
|
|
5773
|
+
"i",
|
|
5774
|
+
"we've",
|
|
5775
|
+
"we're",
|
|
5776
|
+
"you're",
|
|
5777
|
+
"you'll",
|
|
5778
|
+
"it's",
|
|
5779
|
+
"let's",
|
|
5780
|
+
"lets",
|
|
5781
|
+
"be",
|
|
5782
|
+
"was",
|
|
5783
|
+
"were",
|
|
5784
|
+
"this",
|
|
5785
|
+
"that",
|
|
5786
|
+
"these",
|
|
5787
|
+
"those",
|
|
5788
|
+
"something",
|
|
5789
|
+
"everything",
|
|
5790
|
+
"anything",
|
|
5791
|
+
"more",
|
|
5792
|
+
"most",
|
|
5793
|
+
"very",
|
|
5794
|
+
"just",
|
|
5795
|
+
"all",
|
|
5796
|
+
"can",
|
|
5797
|
+
"could",
|
|
5798
|
+
"will",
|
|
5799
|
+
"would",
|
|
5800
|
+
"should",
|
|
5801
|
+
"may",
|
|
5802
|
+
"might",
|
|
5803
|
+
"must",
|
|
5804
|
+
"do",
|
|
5805
|
+
"does",
|
|
5806
|
+
"did",
|
|
5807
|
+
"don't",
|
|
5808
|
+
"not",
|
|
5809
|
+
"never",
|
|
5810
|
+
"still",
|
|
5811
|
+
"only",
|
|
5812
|
+
"even",
|
|
5813
|
+
"also",
|
|
5814
|
+
"own",
|
|
5815
|
+
"ever",
|
|
5816
|
+
"already",
|
|
5817
|
+
"have",
|
|
5818
|
+
"has",
|
|
5819
|
+
"had"
|
|
5820
|
+
];
|
|
5821
|
+
var LANGS = {
|
|
5822
|
+
en: { filler: new Set(FILLER_EN), tail: /* @__PURE__ */ new Set(["of", "in", "for", "from", "with", "by", "on", "at", "into", "over", "about"]) },
|
|
5823
|
+
de: {
|
|
5824
|
+
filler: /* @__PURE__ */ new Set(["der", "die", "das", "den", "dem", "des", "ein", "eine", "einen", "einem", "einer", "und", "oder", "f\xFCr", "mit", "von", "zu", "zum", "zur", "im", "in", "am", "an", "auf", "aus", "bei", "nach", "\xFCber", "unter", "um", "wir", "sie", "ihr", "ihre", "unser", "unsere", "unseren", "unserer", "mein", "es", "ist", "sind", "sich", "uns"]),
|
|
5825
|
+
tail: /* @__PURE__ */ new Set(["von", "f\xFCr", "mit", "im", "in", "am", "auf", "aus", "bei", "nach", "\xFCber", "unter", "um", "zu", "zum", "zur"])
|
|
5826
|
+
},
|
|
5827
|
+
fr: {
|
|
5828
|
+
filler: /* @__PURE__ */ new Set(["le", "la", "les", "l'", "un", "une", "des", "de", "du", "d'", "et", "ou", "pour", "avec", "en", "au", "aux", "dans", "sur", "par", "\xE0", "nous", "vous", "notre", "nos", "votre", "vos", "leur", "leurs", "ce", "cette", "ces", "est", "sont", "qui", "que"]),
|
|
5829
|
+
tail: /* @__PURE__ */ new Set(["de", "du", "des", "pour", "avec", "en", "dans", "sur", "par", "\xE0", "au", "aux"])
|
|
5830
|
+
},
|
|
5831
|
+
es: {
|
|
5832
|
+
filler: /* @__PURE__ */ new Set(["el", "la", "los", "las", "un", "una", "unos", "unas", "de", "del", "y", "o", "para", "con", "en", "al", "por", "a", "nuestro", "nuestra", "nuestros", "nuestras", "su", "sus", "que", "es", "son", "lo"]),
|
|
5833
|
+
tail: /* @__PURE__ */ new Set(["de", "del", "para", "con", "en", "por", "a", "al"])
|
|
5834
|
+
}
|
|
5835
|
+
};
|
|
5836
|
+
var LAST_ADVERBS = /* @__PURE__ */ new Set(["today", "now", "here", "below", "together", "again", "forever", "worldwide", "ahead", "well", "too", "instead", "anywhere", "everywhere", "online"]);
|
|
5837
|
+
var INTERROGATIVE = /* @__PURE__ */ new Set(["what", "how", "why", "who", "when", "where", "which"]);
|
|
5838
|
+
var LEAD = /* @__PURE__ */ new Set(["a", "an", "the", "our", "your", "my", "their", "his", "her", "its", "unser", "unsere", "nos", "notre", "vos", "votre", "nuestro", "nuestra", "nuestros", "nuestras"]);
|
|
5839
|
+
var langOf = (lang) => lang?.trim().toLowerCase().split(/[-_]/)[0] || void 0;
|
|
5840
|
+
var titleCase = (s) => s.replace(new RegExp("(^|\\s)(\\p{Ll})", "gu"), (_, gap, ch) => gap + ch.toUpperCase());
|
|
5841
|
+
function tokensOf(text2) {
|
|
5842
|
+
return text2.split(" ").map((w) => w === "&" ? w : w.replace(/^[^\p{L}\p{M}\p{N}\p{Sc}]+|[^\p{L}\p{M}\p{N}%+]+$/gu, "")).filter((w) => w === "&" || /[\p{L}\p{N}]/u.test(w));
|
|
5843
|
+
}
|
|
5844
|
+
var hasLetter = (w) => new RegExp("\\p{L}", "u").test(w);
|
|
5845
|
+
function sectionPhrase(heading, { copy = false, lang } = {}) {
|
|
5846
|
+
let whole = heading.replace(/\s+/g, " ").trim();
|
|
5847
|
+
if (!new RegExp("\\p{Ll}", "u").test(whole) && new RegExp("\\p{Lu}", "u").test(whole) && whole.includes(" ")) whole = whole.toLowerCase();
|
|
5848
|
+
const say = (words) => {
|
|
5849
|
+
const named = words.join(" ");
|
|
5850
|
+
const phrase = (copy ? named.charAt(0).toUpperCase() + named.slice(1) : titleCase(named)).slice(0, PHRASE_MAX);
|
|
5851
|
+
return hasLetter(phrase) ? phrase : void 0;
|
|
5852
|
+
};
|
|
5853
|
+
const table = LANGS[langOf(lang) ?? "en"];
|
|
5854
|
+
const split = /([,;:.!?])\s|\s([—–-])\s/u.exec(whole);
|
|
5855
|
+
const clause = tokensOf(split ? whole.slice(0, split.index) : whole);
|
|
5856
|
+
if (split && clause.length === 1 && split[1] !== "," && hasLetter(clause[0]) && !table?.filler.has(clause[0].toLowerCase())) return say(clause);
|
|
5857
|
+
const commaJoined = split?.[1] === "," && clause.length < 2;
|
|
5858
|
+
const said = clause.length >= 2 ? clause : tokensOf(whole);
|
|
5859
|
+
if (said.length === 0) return void 0;
|
|
5860
|
+
if (!table) return say(said.slice(0, 3));
|
|
5861
|
+
const lower = said.map((w) => w.toLowerCase());
|
|
5862
|
+
let meaning = said.flatMap((w, i) => hasLetter(w) && !table.filler.has(lower[i]) ? [i] : []);
|
|
5863
|
+
const short = LEAD.has(lower[0]) && said.length > 1 ? 1 : 0;
|
|
5864
|
+
const rest = said.length - short;
|
|
5865
|
+
const fourOk = rest === 4 && (INTERROGATIVE.has(lower[short]) || meaning.length <= 1);
|
|
5866
|
+
if (!copy && !commaJoined && (rest <= 3 || fourOk) && meaning.length <= 3 && (meaning.length >= 2 || INTERROGATIVE.has(lower[short]) || table.filler.has(lower[short]))) {
|
|
5867
|
+
return say(said.slice(short));
|
|
5868
|
+
}
|
|
5869
|
+
if (meaning.length === 0) return say(said.slice(0, 2));
|
|
5870
|
+
while (meaning.length > 2 && LAST_ADVERBS.has(lower[meaning.at(-1)])) meaning = meaning.slice(0, -1);
|
|
5871
|
+
const [first, last] = [meaning[0], meaning.at(-1)];
|
|
5872
|
+
const end = last + 1 < said.length && !hasLetter(said[last + 1]) ? last + 2 : last + 1;
|
|
5873
|
+
if (meaning.length <= 2 && last - first <= 2) return say(said.slice(first, end));
|
|
5874
|
+
if (copy) return say(meaning.slice(0, 2).map((i) => said[i]));
|
|
5875
|
+
const tail = lower.findIndex((w, i) => i > first && table.tail.has(w));
|
|
5876
|
+
const head = tail < 0 ? meaning : meaning.filter((i) => i < tail);
|
|
5877
|
+
const verbLike = !/(?:[^s]s|ing)$/iu.test(lower[first]);
|
|
5878
|
+
if (tail > 0 && head.length < 2 && first === 0 && said.length >= 4 && verbLike) {
|
|
5879
|
+
const after = meaning.filter((i) => i > tail);
|
|
5880
|
+
const run = after.filter((i, n) => n === 0 || n === 1 && i === after[0] + 1);
|
|
5881
|
+
const kept = run.length > 1 && LAST_ADVERBS.has(lower[run[1]]) ? run.slice(0, 1) : run;
|
|
5882
|
+
if (kept.length > 0) return say(kept.map((i) => said[i]));
|
|
5883
|
+
}
|
|
5884
|
+
return say(head.slice(-2).map((i) => said[i]));
|
|
5885
|
+
}
|
|
5886
|
+
function headingClause(heading) {
|
|
5887
|
+
const whole = heading.replace(/\s+/g, " ").trim();
|
|
5888
|
+
const clause = whole.split(/[,;:.!?]\s|\s[—–-]\s/)[0];
|
|
5889
|
+
const said = clause.split(" ").length >= 3 ? clause : whole;
|
|
5890
|
+
const cut = said.split(" ").filter(Boolean);
|
|
5891
|
+
if (said.length > PHRASE_MAX) {
|
|
5892
|
+
while (cut.length > 1 && cut.join(" ").length > PHRASE_MAX) cut.pop();
|
|
5893
|
+
while (cut.length > 1 && TRAILING.has(cut.at(-1).toLowerCase().replace(/[^\p{L}']/gu, ""))) cut.pop();
|
|
5894
|
+
}
|
|
5895
|
+
const phrase = titleCase(cut.join(" ").replace(/[\p{P}\s]+$/u, "")).slice(0, PHRASE_MAX);
|
|
5896
|
+
return phrase || void 0;
|
|
5897
|
+
}
|
|
5898
|
+
var BOUND = {
|
|
5899
|
+
// "Häufig Gestellte Fragen", "Why Choose Us": a short heading kept whole is a name.
|
|
5900
|
+
block: { words: 4, meaning: 3 },
|
|
5901
|
+
// The block, then the element, then a modifier: "Get In Touch heading", "Header home link URL".
|
|
5902
|
+
field: { words: 7, meaning: 5 }
|
|
5903
|
+
};
|
|
5904
|
+
var FIELD_ROLE_BOX_WORDS = /* @__PURE__ */ new Set(["body", "content"]);
|
|
5905
|
+
var NAME_PART_SEP = " \u203A ";
|
|
5906
|
+
function namingProblem(name2, kind, { copy, lang } = {}) {
|
|
5907
|
+
const filler = (LANGS[langOf(lang) ?? "en"] ?? LANGS.en).filler;
|
|
5908
|
+
const parts = name2.split(NAME_PART_SEP);
|
|
5909
|
+
for (const [n, raw] of parts.entries()) {
|
|
5910
|
+
const part = raw.trim();
|
|
5911
|
+
const as = n < parts.length - 1 ? "block" : kind;
|
|
5912
|
+
const words = tokensOf(part).filter(hasLetter);
|
|
5913
|
+
const suggest = (rule) => {
|
|
5914
|
+
if (rule === "artifact") return { part, rule };
|
|
5915
|
+
const suggested = sectionPhrase(part, { copy: rule === "copy", lang });
|
|
5916
|
+
return { part, rule, ...suggested && suggested !== part && !namingProblem(suggested, as, { lang }) ? { suggested } : {} };
|
|
5917
|
+
};
|
|
5918
|
+
if (isArtifactName(part) && !(as === "field" && FIELD_ROLE_BOX_WORDS.has(part.toLowerCase()))) return suggest("artifact");
|
|
5919
|
+
if (/[.!?]$/u.test(part) || words.length > BOUND[as].words || words.some((w) => w.length > PHRASE_MAX)) return suggest("sentence");
|
|
5920
|
+
if (words.filter((w) => !filler.has(w.toLowerCase())).length > BOUND[as].meaning) return suggest("too-many-words");
|
|
5921
|
+
const said = (copy ?? "").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim().toLowerCase();
|
|
5922
|
+
if (as === "field" && words.length >= 3 && said.startsWith(part.toLowerCase())) return suggest("copy");
|
|
5923
|
+
}
|
|
5924
|
+
return void 0;
|
|
5925
|
+
}
|
|
5926
|
+
var ACRONYMS = { cta: "CTA", faq: "FAQ", seo: "SEO", url: "URL", api: "API", ai: "AI" };
|
|
5927
|
+
var acronymOf = (word) => {
|
|
5928
|
+
const l = word.toLowerCase();
|
|
5929
|
+
return ACRONYMS[l] ?? (l.endsWith("s") && ACRONYMS[l.slice(0, -1)] ? `${ACRONYMS[l.slice(0, -1)]}s` : void 0);
|
|
5930
|
+
};
|
|
5931
|
+
var CODE_WORDS = { href: "link", src: "image", alt: "alt text", id: "", key: "", attr: "" };
|
|
5932
|
+
var CONTROL_WORDS = /* @__PURE__ */ new Set(["link", "links", "button", "menu", "nav"]);
|
|
5933
|
+
function sentenceCase(name2, keep = properNounsOf([name2])) {
|
|
5934
|
+
return name2.split(NAME_PART_SEP).map(
|
|
5935
|
+
(part) => part.trim().split(/\s+/).map((w, i) => acronymOf(w) ?? (i === 0 ? w.charAt(0).toUpperCase() + w.slice(1) : new RegExp("^\\p{Lu}\\p{Ll}+$", "u").test(w) && !keep.has(w) ? w.toLowerCase() : w)).join(" ")
|
|
5936
|
+
).join(NAME_PART_SEP);
|
|
5937
|
+
}
|
|
5938
|
+
var SMALL_WORDS = /* @__PURE__ */ new Set(["a", "an", "and", "at", "by", "for", "from", "in", "of", "on", "the", "to", "with"]);
|
|
5939
|
+
function properNounsOf(labels, { across = false } = {}) {
|
|
5940
|
+
const firsts = /* @__PURE__ */ new Map();
|
|
5941
|
+
for (const label of labels) {
|
|
5942
|
+
for (const part of label.split(NAME_PART_SEP)) {
|
|
5943
|
+
const [first = "", ...rest] = part.trim().split(/\s+/);
|
|
5944
|
+
if (!rest.some((w) => new RegExp("^\\p{Ll}", "u").test(w) && !SMALL_WORDS.has(w)) || rest.some((w) => new RegExp("^\\p{Lu}", "u").test(w) && SMALL_WORDS.has(w.toLowerCase()))) continue;
|
|
5945
|
+
for (const w of rest) {
|
|
5946
|
+
if (!new RegExp("^\\p{Lu}\\p{Ll}+$", "u").test(w) || acronymOf(w) !== void 0 || VOCABULARY.has(w.toLowerCase())) continue;
|
|
5947
|
+
firsts.set(w, (firsts.get(w) ?? /* @__PURE__ */ new Set()).add(first.toLowerCase()));
|
|
5948
|
+
}
|
|
5949
|
+
}
|
|
5950
|
+
}
|
|
5951
|
+
return new Set([...firsts].filter(([, at]) => !across || at.size >= 2).map(([w]) => w));
|
|
5952
|
+
}
|
|
5953
|
+
function readabilityProblem(name2, opts = {}) {
|
|
5954
|
+
const { tag, button = false, inHeading = false, keep = properNounsOf([name2]) } = opts;
|
|
5955
|
+
const parts = name2.split(NAME_PART_SEP).map((p) => p.trim());
|
|
5956
|
+
const field = parts.at(-1);
|
|
5957
|
+
const words = field.split(/\s+/).filter(Boolean);
|
|
5958
|
+
const final = words.at(-1) ?? "";
|
|
5959
|
+
const fixed = (said) => {
|
|
5960
|
+
if (said.length === 0) return void 0;
|
|
5961
|
+
const next = sentenceCase([...parts.slice(0, -1), said.join(" ")].join(NAME_PART_SEP), keep);
|
|
5962
|
+
return next !== name2 && !readabilityProblem(next, opts) && !namingProblem(next, "field") ? next : void 0;
|
|
5963
|
+
};
|
|
5964
|
+
const problem = (part, rule, suggested) => ({ part, rule, ...suggested ? { suggested } : {} });
|
|
5965
|
+
const code = CODE_WORDS[final.toLowerCase()];
|
|
5966
|
+
if (code !== void 0 && final !== final.toUpperCase()) {
|
|
5967
|
+
const before = words.slice(0, -1);
|
|
5968
|
+
return problem(field, "code-word", fixed(code && before.at(-1)?.toLowerCase() !== code ? [...before, code] : before));
|
|
5969
|
+
}
|
|
5970
|
+
const shouted = parts.find((p) => p.split(/\s+/).some((w) => acronymOf(w) !== void 0 && acronymOf(w) !== w));
|
|
5971
|
+
if (shouted !== void 0) {
|
|
5972
|
+
const next = sentenceCase(name2, keep);
|
|
5973
|
+
const then = next !== name2 ? readabilityProblem(next, { ...opts, keep }) : void 0;
|
|
5974
|
+
return problem(shouted, "acronym-case", next === name2 ? void 0 : then ? then.suggested : next);
|
|
5975
|
+
}
|
|
5976
|
+
const isButton = /^BUTTON$/i.test(tag ?? "");
|
|
5977
|
+
const isAnchor = /^A$/i.test(tag ?? "");
|
|
5978
|
+
const heading = inHeading || isAnchor && /^heading$/i.test(final);
|
|
5979
|
+
if ((isButton || isAnchor) && !heading && /^(?:text|heading)$/i.test(final) && !words.some((w) => CONTROL_WORDS.has(w.toLowerCase()))) {
|
|
5980
|
+
return problem(field, "role-mismatch", fixed([...words.slice(0, -1), ...isButton || button ? ["button", "label"] : ["link", "text"]]));
|
|
5981
|
+
}
|
|
5982
|
+
return void 0;
|
|
5983
|
+
}
|
|
5984
|
+
function caseTwins(labels) {
|
|
5985
|
+
const said = /* @__PURE__ */ new Map();
|
|
5986
|
+
for (const label of labels) {
|
|
5987
|
+
const l = label.trim();
|
|
5988
|
+
said.set(l.toLowerCase(), (said.get(l.toLowerCase()) ?? /* @__PURE__ */ new Set()).add(l));
|
|
5989
|
+
}
|
|
5990
|
+
return new Set([...said.values()].filter((s) => s.size > 1).flatMap((s) => [...s]));
|
|
5991
|
+
}
|
|
5992
|
+
var ORDINAL = /^(?:second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|no\.\s*\d{1,3})\s+(.+)$/i;
|
|
5993
|
+
var ROLE_WORDS = new Set(ROLE_VOCABULARY.map((r) => r.replace(/-/g, " ")));
|
|
5994
|
+
var GLUE_HEADS = [
|
|
5995
|
+
"section",
|
|
5996
|
+
"block",
|
|
5997
|
+
"wrapper",
|
|
5998
|
+
"wrap",
|
|
5999
|
+
"container",
|
|
6000
|
+
"content",
|
|
6001
|
+
"layout",
|
|
6002
|
+
"column",
|
|
6003
|
+
"shell",
|
|
6004
|
+
"region",
|
|
6005
|
+
"cluster",
|
|
6006
|
+
"hero",
|
|
6007
|
+
"features",
|
|
6008
|
+
"feature",
|
|
6009
|
+
"pricing",
|
|
6010
|
+
"testimonials",
|
|
6011
|
+
"faq",
|
|
6012
|
+
"cta",
|
|
6013
|
+
"stats",
|
|
6014
|
+
"logos",
|
|
6015
|
+
"gallery",
|
|
6016
|
+
"contact",
|
|
6017
|
+
"newsletter",
|
|
6018
|
+
"banner"
|
|
6019
|
+
];
|
|
6020
|
+
var BAND_WORDS = /* @__PURE__ */ new Set([...GLUE_HEADS, ...BOX_WORDS]);
|
|
6021
|
+
var gluedApart = (word) => {
|
|
6022
|
+
if (!new RegExp("^\\p{Lu}?\\p{Ll}{6,}$", "u").test(word)) return void 0;
|
|
6023
|
+
const l = word.toLowerCase();
|
|
6024
|
+
if (VOCABULARY.has(l) || BAND_WORDS.has(l)) return void 0;
|
|
6025
|
+
const head = GLUE_HEADS.find((h) => l.startsWith(h) && l.length - h.length >= 3 && (BAND_WORDS.has(l.slice(h.length)) || BAND_WORDS.has(l.slice(h.length).replace(/s$/, ""))));
|
|
6026
|
+
return head ? `${head} ${l.slice(head.length)}` : void 0;
|
|
6027
|
+
};
|
|
6028
|
+
var ROLE_COUNTED = new RegExp("^(\\p{L}+(?:\\s\\p{L}+)?)\\s+(?:\\d{1,3}|\\p{Ll})$", "u");
|
|
6029
|
+
var gluedKey = (name2, key) => {
|
|
6030
|
+
const parts = (key ?? "").toLowerCase().split(/[^\p{L}]+/u).filter(Boolean);
|
|
6031
|
+
const l = name2.toLowerCase();
|
|
6032
|
+
return parts.length > 1 && new RegExp("^\\p{L}+$", "u").test(name2) && l === parts.join("") && !VOCABULARY.has(l) && !BAND_WORDS.has(l) ? parts.join(" ") : void 0;
|
|
6033
|
+
};
|
|
6034
|
+
var BARE_ROLE = /^(?:text|paragraph|number|link|icon|image|item|element|attribute)$/i;
|
|
6035
|
+
var runOf = (name2) => name2.trim().toLowerCase().replace(/\b\d{1,3}\b/g, "#");
|
|
6036
|
+
var uncounted = (name2) => {
|
|
6037
|
+
const l = name2.trim().toLowerCase();
|
|
6038
|
+
const digit = /^(.*\S)[\s-]+\d{1,3}$/.exec(l)?.[1];
|
|
6039
|
+
return digit ?? ORDINAL.exec(l)?.[1];
|
|
6040
|
+
};
|
|
6041
|
+
function judgeName(name2, kind, ctx = {}) {
|
|
6042
|
+
const { siblings, copy, type, lang, key, ...element } = ctx;
|
|
6043
|
+
const own2 = namingProblem(name2, kind, { copy, lang }) ?? readabilityProblem(name2, element);
|
|
6044
|
+
if (own2) return own2;
|
|
6045
|
+
const parts = name2.split(NAME_PART_SEP).map((p) => p.trim());
|
|
6046
|
+
for (const part of parts) {
|
|
6047
|
+
const ordinal = ORDINAL.exec(part);
|
|
6048
|
+
if (ordinal && ROLE_WORDS.has(ordinal[1].toLowerCase())) return { part, rule: "ordinal" };
|
|
6049
|
+
const twice = new RegExp("(?:^|\\s)(\\p{L}+)\\s+\\1(?=\\s|$)", "iu").exec(part);
|
|
6050
|
+
if (twice) {
|
|
6051
|
+
const once = part.replace(new RegExp(`(^|\\s)(${twice[1]})\\s+${twice[1]}(?=\\s|$)`, "iu"), "$1$2");
|
|
6052
|
+
return { part, rule: "repeated-word", ...judgeName(name2.replace(part, once), kind, { lang }) ? {} : { suggested: name2.replace(part, once) } };
|
|
6053
|
+
}
|
|
6054
|
+
const word = part.split(/\s+/).find((w) => gluedApart(w) !== void 0);
|
|
6055
|
+
const apart = word ? gluedApart(word) : gluedKey(part, key);
|
|
6056
|
+
if (apart) {
|
|
6057
|
+
const next = sentenceCase(name2.replace(word ?? part, apart));
|
|
6058
|
+
return { part, rule: "glued", ...judgeName(next, kind, { lang }) ? {} : { suggested: next } };
|
|
6059
|
+
}
|
|
6060
|
+
const role = ROLE_COUNTED.exec(part);
|
|
6061
|
+
if (role && ROLE_WORDS.has(role[1].toLowerCase())) return { part, rule: "counted" };
|
|
6062
|
+
}
|
|
6063
|
+
if (kind === "block" && isCountedName(name2)) return { part: name2, rule: "counted" };
|
|
6064
|
+
if (!siblings) return void 0;
|
|
6065
|
+
const l = name2.trim();
|
|
6066
|
+
const at = besideOf(siblings);
|
|
6067
|
+
const other = (bucket) => !!bucket?.some((s) => s.name !== l && (!type || !s.type || s.type === type));
|
|
6068
|
+
if (at.byLower.get(l.toLowerCase())?.some((s) => s.name !== l)) return { part: l, rule: "case-twin" };
|
|
6069
|
+
if (type && (at.byLower.get(l.toLowerCase())?.filter((s) => s.name === l && s.type === type).length ?? 0) > 1) return { part: l, rule: "twin" };
|
|
6070
|
+
const run = runOf(l);
|
|
6071
|
+
const ownWords = !!copy && copy.trim().startsWith(l);
|
|
6072
|
+
const bare = uncounted(l);
|
|
6073
|
+
if (!ownWords && run !== l.toLowerCase() && other(at.byRun.get(run))) return { part: l, rule: "counted" };
|
|
6074
|
+
if (!ownWords && bare !== void 0 && other(at.byLower.get(bare))) return { part: l, rule: "counted" };
|
|
6075
|
+
if (!/\d/.test(l) && other(at.byUncounted.get(l.toLowerCase()))) return { part: l, rule: "bare-role" };
|
|
6076
|
+
const ofType = type ? at.byType.get(type) : void 0;
|
|
6077
|
+
if (ofType && BARE_ROLE.test(l) && ofType.size > (ofType.has(l) ? 1 : 0)) return { part: l, rule: "bare-role" };
|
|
6078
|
+
const said = copy ? sentenceOf(copy) : void 0;
|
|
6079
|
+
if (said && l.startsWith(`${said} `)) return { part: said, rule: "copy-sentence" };
|
|
6080
|
+
for (let i = l.indexOf(" "); i > 0; i = l.indexOf(" ", i + 1)) if (at.sentences.has(l.slice(0, i))) return { part: l.slice(0, i), rule: "copy-sentence" };
|
|
6081
|
+
return void 0;
|
|
6082
|
+
}
|
|
6083
|
+
var sentenceOf = (said) => {
|
|
6084
|
+
const whole = headingClause(said);
|
|
6085
|
+
return whole && whole.split(" ").length >= 3 && whole !== sectionPhrase(said) ? whole : void 0;
|
|
6086
|
+
};
|
|
6087
|
+
var prepared = /* @__PURE__ */ new WeakMap();
|
|
6088
|
+
function besideOf(siblings) {
|
|
6089
|
+
const known = prepared.get(siblings);
|
|
6090
|
+
if (known) return known;
|
|
6091
|
+
const at = { byLower: /* @__PURE__ */ new Map(), byRun: /* @__PURE__ */ new Map(), byUncounted: /* @__PURE__ */ new Map(), byType: /* @__PURE__ */ new Map(), sentences: /* @__PURE__ */ new Set() };
|
|
6092
|
+
const add = (map, key, s) => {
|
|
6093
|
+
const bucket = map.get(key);
|
|
6094
|
+
if (bucket) bucket.push(s);
|
|
6095
|
+
else map.set(key, [s]);
|
|
6096
|
+
};
|
|
6097
|
+
for (const raw of siblings) {
|
|
6098
|
+
const one = typeof raw === "string" ? { name: raw } : raw;
|
|
6099
|
+
const s = { name: one.name.trim(), ...one.type ? { type: one.type } : {} };
|
|
6100
|
+
add(at.byLower, s.name.toLowerCase(), s);
|
|
6101
|
+
add(at.byRun, runOf(s.name), s);
|
|
6102
|
+
const bare = uncounted(s.name);
|
|
6103
|
+
if (bare !== void 0) add(at.byUncounted, bare, s);
|
|
6104
|
+
if (s.type) at.byType.set(s.type, (at.byType.get(s.type) ?? /* @__PURE__ */ new Set()).add(s.name));
|
|
6105
|
+
const sentence = typeof raw === "string" || !raw.copy ? void 0 : sentenceOf(raw.copy);
|
|
6106
|
+
if (sentence) at.sentences.add(sentence);
|
|
6107
|
+
}
|
|
6108
|
+
prepared.set(siblings, at);
|
|
6109
|
+
return at;
|
|
6110
|
+
}
|
|
6111
|
+
|
|
5168
6112
|
// src/icon-value.ts
|
|
5169
6113
|
import { iconSvg as iconSvg2 } from "@bettercms-ai/icons/markup";
|
|
5170
6114
|
var ICON_SOURCES = ["pack", "library", "upload"];
|
|
@@ -5242,10 +6186,12 @@ function iconHtml(v, className = "") {
|
|
|
5242
6186
|
export {
|
|
5243
6187
|
BG_TOKENS,
|
|
5244
6188
|
BG_TOKEN_CSS,
|
|
6189
|
+
BLOCKED_REASONS,
|
|
5245
6190
|
BLOCK_BINDINGS,
|
|
5246
6191
|
BLOCK_FIELD_TYPES,
|
|
5247
6192
|
BLOCK_FIELD_TYPES_RENDERABLE_NOW,
|
|
5248
6193
|
BODY_SCHEMA_ORIGINS,
|
|
6194
|
+
BOX_WORDS,
|
|
5249
6195
|
BREAKPOINTS,
|
|
5250
6196
|
BUTTON_ACTIONS,
|
|
5251
6197
|
BUTTON_FULL_WIDTH_INVALID,
|
|
@@ -5301,19 +6247,27 @@ export {
|
|
|
5301
6247
|
KEY_RESERVED_PREFIX,
|
|
5302
6248
|
KIT_CATEGORIES,
|
|
5303
6249
|
LANDMARK_SELECTOR,
|
|
6250
|
+
LAYOUT_ROLES,
|
|
5304
6251
|
LAYOUT_SECTION_ICONS,
|
|
5305
6252
|
LAYOUT_SECTION_ICON_SET,
|
|
5306
6253
|
LINK_RELS,
|
|
5307
6254
|
LINK_VALUE_TYPES,
|
|
5308
6255
|
LIST_ITEMS_CAP,
|
|
5309
6256
|
LIST_PREVIEW_SLOTS,
|
|
6257
|
+
LOCAL_FRAMEWORKS,
|
|
6258
|
+
LOCAL_SETUP_LIMITS,
|
|
6259
|
+
LOCAL_SETUP_VERSION,
|
|
5310
6260
|
LOCATOR_PATH,
|
|
5311
6261
|
MAIN_SELECTOR,
|
|
6262
|
+
MAX_LOCAL_SETUP_BYTES,
|
|
6263
|
+
MAX_SITE_MAP_BYTES,
|
|
6264
|
+
NAME_PART_SEP,
|
|
5312
6265
|
NAVIGATION_SECTION_ID,
|
|
5313
6266
|
OPEN_MODES,
|
|
5314
6267
|
OPEN_MODE_TYPES,
|
|
5315
6268
|
OPTION_DESCRIPTION_MAX,
|
|
5316
6269
|
PAGE_CONTENT_ANCHOR_ID,
|
|
6270
|
+
PHRASE_MAX,
|
|
5317
6271
|
PRIMITIVE_ARRAY_RULE,
|
|
5318
6272
|
REFERENCE_CREATE_REFUSAL_CODES,
|
|
5319
6273
|
RESPONSIVE_CSS,
|
|
@@ -5328,16 +6282,20 @@ export {
|
|
|
5328
6282
|
RICHTEXT_MARK_FEATURES,
|
|
5329
6283
|
RICHTEXT_TOGGLE_FEATURES,
|
|
5330
6284
|
ROLE_KEYS,
|
|
6285
|
+
ROLE_VOCABULARY,
|
|
5331
6286
|
SCHEMA_HASH_INPUTS,
|
|
5332
6287
|
SECTION_ANCHOR,
|
|
5333
6288
|
SECTION_CSS_CLASS,
|
|
5334
6289
|
SECTION_DOCTRINE,
|
|
6290
|
+
SECTION_KINDS,
|
|
5335
6291
|
SECTION_SPACE_TOKENS,
|
|
5336
6292
|
SEGMENTED_MAX,
|
|
5337
6293
|
SEGMENTED_MIN,
|
|
5338
6294
|
SHOW_IF_SCOPES,
|
|
5339
6295
|
SIDE_SPACE_MIN_PX,
|
|
5340
6296
|
SIDE_SPACE_TOKENS,
|
|
6297
|
+
SITE_MAP_VERSION,
|
|
6298
|
+
SITE_MAP_VERSIONS,
|
|
5341
6299
|
SLOT_CHILD_KEYS,
|
|
5342
6300
|
SLOT_ITEMS_CAP,
|
|
5343
6301
|
SLOT_MAX_ITEMS,
|
|
@@ -5346,6 +6304,8 @@ export {
|
|
|
5346
6304
|
SOURCE_RANK,
|
|
5347
6305
|
SPACE_BOTTOM_TOKENS,
|
|
5348
6306
|
SPACE_STEP_TOKENS,
|
|
6307
|
+
STYLE_TOKEN_GROUPS,
|
|
6308
|
+
STYLE_USED_GROUPS,
|
|
5349
6309
|
TABLE_COLUMN_TYPES,
|
|
5350
6310
|
TABLE_CSS,
|
|
5351
6311
|
TABLE_JSONLD_TYPES,
|
|
@@ -5387,6 +6347,7 @@ export {
|
|
|
5387
6347
|
buttonVariantOf,
|
|
5388
6348
|
candidateRole,
|
|
5389
6349
|
canonicalJson,
|
|
6350
|
+
caseTwins,
|
|
5390
6351
|
compactIcon,
|
|
5391
6352
|
componentInstanceAddresses,
|
|
5392
6353
|
componentPropTargetKey,
|
|
@@ -5411,6 +6372,7 @@ export {
|
|
|
5411
6372
|
formatNumber,
|
|
5412
6373
|
formatPropsAttribute,
|
|
5413
6374
|
getBlockType,
|
|
6375
|
+
headingClause,
|
|
5414
6376
|
headingPaintCss,
|
|
5415
6377
|
hiddenEverywhere,
|
|
5416
6378
|
hideOnAttr,
|
|
@@ -5420,11 +6382,13 @@ export {
|
|
|
5420
6382
|
iconValueProblem,
|
|
5421
6383
|
imageFrameCss,
|
|
5422
6384
|
inWindow,
|
|
6385
|
+
isArtifactName,
|
|
5423
6386
|
isBlock,
|
|
5424
6387
|
isButtonLookValue,
|
|
5425
6388
|
isChromeLandmark,
|
|
5426
6389
|
isCodeButton,
|
|
5427
6390
|
isComponentGateCode,
|
|
6391
|
+
isCountedName,
|
|
5428
6392
|
isDeriveReservedKey,
|
|
5429
6393
|
isDockUiImportAllowed,
|
|
5430
6394
|
isEmbedReason,
|
|
@@ -5439,6 +6403,7 @@ export {
|
|
|
5439
6403
|
isTableValue,
|
|
5440
6404
|
isUiRefusal,
|
|
5441
6405
|
isVariantVisible,
|
|
6406
|
+
judgeName,
|
|
5442
6407
|
keyWords,
|
|
5443
6408
|
landmarkRegions,
|
|
5444
6409
|
linkAnchorOf,
|
|
@@ -5448,20 +6413,25 @@ export {
|
|
|
5448
6413
|
locatorFor,
|
|
5449
6414
|
locatorPath,
|
|
5450
6415
|
mayOverwrite,
|
|
6416
|
+
namingProblem,
|
|
5451
6417
|
normaliseRichTextFeatures,
|
|
5452
6418
|
normalizeIcon,
|
|
5453
6419
|
normalizeLinkValue,
|
|
5454
6420
|
normalizeTableValue,
|
|
5455
6421
|
normalizeWindow,
|
|
5456
6422
|
parseEmbedMarkers,
|
|
6423
|
+
parseLocalSetupManifest,
|
|
5457
6424
|
parseNumberText,
|
|
5458
6425
|
parsePropsAttribute,
|
|
6426
|
+
parseSiteMap,
|
|
5459
6427
|
pickFieldStyle,
|
|
5460
6428
|
placementBindOf,
|
|
5461
6429
|
planSections,
|
|
6430
|
+
properNounsOf,
|
|
5462
6431
|
readButtonValue,
|
|
5463
6432
|
readNumberFormat,
|
|
5464
6433
|
readPath,
|
|
6434
|
+
readabilityProblem,
|
|
5465
6435
|
referenceCreateRefusal,
|
|
5466
6436
|
regionOf,
|
|
5467
6437
|
renderTableHtml,
|
|
@@ -5471,6 +6441,8 @@ export {
|
|
|
5471
6441
|
safeCssUrl,
|
|
5472
6442
|
schemaHashInput,
|
|
5473
6443
|
sectionIdentityAttrs,
|
|
6444
|
+
sectionPhrase,
|
|
6445
|
+
sentenceCase,
|
|
5474
6446
|
sideFloorApplies,
|
|
5475
6447
|
sideSpaceCss,
|
|
5476
6448
|
slotBindOf,
|