@perkyzz/emvb 0.6.0 → 0.7.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/package.json +1 -1
- package/src/admin/access/RequireEditor.tsx +7 -7
- package/src/admin/access/role.ts +5 -2
- package/src/admin/content-api.ts +10 -3
- package/src/admin/content-item.ts +1 -1
- package/src/admin/editor/A11yCopilot.tsx +104 -56
- package/src/admin/editor/CommandPalette.tsx +29 -13
- package/src/admin/editor/Editor.tsx +82 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +97 -72
- package/src/admin/editor/ShareLink.tsx +107 -72
- package/src/admin/editor/ShortcutsDialog.tsx +27 -16
- package/src/admin/editor/Timeline.tsx +255 -160
- package/src/admin/editor/TopBar.tsx +71 -14
- package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
- package/src/admin/editor/canvas/drop-line.ts +11 -3
- package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
- package/src/admin/editor/canvas/vnode-react.tsx +7 -0
- package/src/admin/editor/collection-previews.ts +10 -0
- package/src/admin/editor/dialogs.tsx +38 -14
- package/src/admin/editor/dnd/drop-target.ts +26 -1
- package/src/admin/editor/edited-noun.ts +15 -0
- package/src/admin/editor/editor-chrome.tsx +59 -7
- package/src/admin/editor/editor-commands.ts +2 -1
- package/src/admin/editor/editor-css.ts +72 -22
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +45 -13
- package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
- package/src/admin/editor/icons/library.ts +1 -1
- package/src/admin/editor/icons/use-icon-library.ts +5 -2
- package/src/admin/editor/ime.ts +29 -0
- package/src/admin/editor/palette-items.ts +10 -3
- package/src/admin/editor/panels/AddPanel.tsx +35 -10
- package/src/admin/editor/panels/ClassesSection.tsx +18 -7
- package/src/admin/editor/panels/ColorControl.tsx +130 -23
- package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
- package/src/admin/editor/panels/ElementPanel.tsx +134 -24
- package/src/admin/editor/panels/LayersPanel.tsx +55 -19
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
- package/src/admin/editor/panels/TokenScales.tsx +76 -36
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
- package/src/admin/editor/panels/VariableSection.tsx +48 -18
- package/src/admin/editor/panels/color-space.ts +9 -3
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
- package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
- package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
- package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
- package/src/admin/editor/panels/settings/FieldControl.tsx +20 -8
- package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
- package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
- package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
- package/src/admin/editor/panels/settings/MediaPicker.tsx +127 -23
- package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
- package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
- package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +66 -1
- package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
- package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
- package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
- package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
- package/src/admin/editor/panels/settings/query-style.ts +38 -9
- package/src/admin/editor/panels/settings/svg-images.ts +13 -0
- package/src/admin/editor/panels/site-list.tsx +20 -6
- package/src/admin/editor/panels/variable-values.ts +11 -4
- package/src/admin/editor/restore-deleted.ts +21 -2
- package/src/admin/editor/section-templates.ts +81 -12
- package/src/admin/editor/shortcuts.ts +17 -2
- package/src/admin/editor/store.ts +7 -0
- package/src/admin/editor/useEditorCommands.ts +61 -15
- package/src/admin/editor/useEditorData.ts +4 -2
- package/src/admin/editor/useEditorShortcuts.ts +17 -7
- package/src/admin/editor/useNodeActions.ts +61 -6
- package/src/admin/editor/useSave.ts +22 -7
- package/src/admin/forms-api.ts +2 -0
- package/src/admin/image-editor/CurvesPanel.tsx +2 -1
- package/src/admin/image-editor/ExportDialog.tsx +48 -18
- package/src/admin/image-editor/ImageEditorDialog.tsx +49 -7
- package/src/admin/image-editor/MetadataPanel.tsx +15 -4
- package/src/admin/image-editor/crop-geometry.ts +3 -2
- package/src/admin/image-editor/image-editor-css.ts +4 -2
- package/src/admin/image-editor/load.ts +9 -2
- package/src/admin/image-editor/parts.tsx +51 -2
- package/src/admin/image-editor/save.ts +23 -7
- package/src/admin/media-api.ts +2 -1
- package/src/admin/pages/AgentsPage.tsx +138 -27
- package/src/admin/pages/CreateDialog.tsx +97 -30
- package/src/admin/pages/NewPageDialog.tsx +21 -3
- package/src/admin/pages/NewThemePartDialog.tsx +11 -3
- package/src/admin/pages/PageList.tsx +14 -6
- package/src/admin/pages/SetupShell.tsx +28 -12
- package/src/admin/pages/ThemePartList.tsx +27 -7
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +13 -3
- package/src/admin/ui.ts +73 -22
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +33 -3
- package/src/astro/render.ts +3 -0
- package/src/astro/resolve-theme.ts +53 -11
- package/src/astro/resolve.ts +9 -1
- package/src/astro/tabs/runtime.ts +12 -0
- package/src/astro/theme-posts.ts +2 -2
- package/src/astro/visitor.ts +2 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +171 -24
- package/src/core/arrange.ts +27 -6
- package/src/core/audience/rules.ts +5 -1
- package/src/core/audience/variants.ts +29 -3
- package/src/core/clipboard.ts +7 -0
- package/src/core/css/generate.ts +31 -6
- package/src/core/data/bindings.ts +8 -1
- package/src/core/design/classes.ts +16 -7
- package/src/core/design/diff.ts +6 -0
- package/src/core/design/merge.ts +90 -2
- package/src/core/design/tokens.ts +16 -2
- package/src/core/design/transfer.ts +33 -6
- package/src/core/design/variables.ts +30 -9
- package/src/core/elements/dynamic-elements.ts +44 -5
- package/src/core/elements/form-elements.ts +55 -16
- package/src/core/elements/index.ts +83 -38
- package/src/core/elements/menu.ts +37 -19
- package/src/core/elements/select-prompt.ts +3 -0
- package/src/core/elements/svg-ids.ts +39 -0
- package/src/core/forms/binding.ts +57 -16
- package/src/core/forms/definition.ts +72 -0
- package/src/core/history/diff.ts +18 -1
- package/src/core/icons/catalog.ts +3 -2
- package/src/core/image-edit/schema.ts +11 -1
- package/src/core/image-edit/summary.ts +6 -3
- package/src/core/index.ts +15 -1
- package/src/core/limits.ts +12 -1
- package/src/core/perf/meter.ts +42 -7
- package/src/core/recipes/index.ts +5 -4
- package/src/core/render/context.ts +8 -0
- package/src/core/render/dynamic-post.ts +69 -12
- package/src/core/render/extras.ts +77 -4
- package/src/core/render/form.ts +140 -6
- package/src/core/render/index.ts +156 -20
- package/src/core/render/loop.ts +43 -7
- package/src/core/render/pagination.ts +18 -4
- package/src/core/render/section.ts +27 -0
- package/src/core/render/tabs.ts +12 -3
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +15 -2
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/schema/layout.ts +15 -6
- package/src/core/stats.ts +2 -1
- package/src/core/theme/conditions.ts +3 -1
- package/src/core/theme/dynamic.ts +36 -5
- package/src/core/theme/float.ts +9 -2
- package/src/core/theme/pagination.ts +31 -11
- package/src/core/theme/popup-markup.ts +23 -5
- package/src/core/theme/popup-rules.ts +1 -0
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/tree-ops.ts +27 -0
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +14 -2
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/write.ts +174 -10
- package/src/server/agent-settings.ts +1 -1
- package/src/server/hooks.ts +5 -3
- package/src/server/icon-routes.ts +30 -9
- package/src/server/mcp-routes.ts +6 -1
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
validateTriggers,
|
|
20
20
|
wrapFloatMarkup,
|
|
21
21
|
wrapPopupMarkup,
|
|
22
|
+
type ChromeLabels,
|
|
22
23
|
type FloatSettings,
|
|
23
24
|
type Layout,
|
|
24
25
|
type ThemeDynamicData,
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
type TriggersDoc,
|
|
30
31
|
archivePagePath,
|
|
31
32
|
loopPerPage,
|
|
33
|
+
paginationArchiveTitle,
|
|
32
34
|
paginationTitleText,
|
|
33
35
|
type ArchivePagination,
|
|
34
36
|
} from "../core/index.ts";
|
|
@@ -206,15 +208,22 @@ async function loadLoopTemplates(
|
|
|
206
208
|
parts: StoredPart[],
|
|
207
209
|
request?: object,
|
|
208
210
|
): Promise<Record<string, Layout>> {
|
|
209
|
-
const
|
|
210
|
-
if (
|
|
211
|
+
const queue = collectLoopItemPartIds(layout);
|
|
212
|
+
if (queue.length === 0) return {};
|
|
211
213
|
const byId = new Map(parts.map((p) => [p.id, p]));
|
|
212
214
|
const templates: Record<string, Layout> = {};
|
|
213
|
-
|
|
215
|
+
const seen = new Set<string>();
|
|
216
|
+
// W-654: a Loop inside a loop item part can use another loop item part; load those too.
|
|
217
|
+
while (queue.length > 0 && seen.size < 32) {
|
|
218
|
+
const id = queue.shift();
|
|
219
|
+
if (!id || seen.has(id)) continue;
|
|
220
|
+
seen.add(id);
|
|
214
221
|
const part = byId.get(id);
|
|
215
222
|
if (!part || part.partType !== "loop_item") continue;
|
|
216
223
|
const itemLayout = layoutFor(request, part.id, part.layout);
|
|
217
|
-
if (itemLayout)
|
|
224
|
+
if (!itemLayout) continue;
|
|
225
|
+
templates[id] = itemLayout;
|
|
226
|
+
queue.push(...collectLoopItemPartIds(itemLayout));
|
|
218
227
|
}
|
|
219
228
|
return templates;
|
|
220
229
|
}
|
|
@@ -308,6 +317,7 @@ async function loadArchivePosts(
|
|
|
308
317
|
ctx: ThemeRequestContext,
|
|
309
318
|
perPage: number,
|
|
310
319
|
content: ContentPort,
|
|
320
|
+
postsTitle = "Posts",
|
|
311
321
|
): Promise<{
|
|
312
322
|
posts: ThemePostFields[];
|
|
313
323
|
archiveTitle?: string;
|
|
@@ -342,7 +352,7 @@ async function loadArchivePosts(
|
|
|
342
352
|
const archiveTitle = ctx.taxonomy?.slug
|
|
343
353
|
? await termLabel(ctx.taxonomy.type, ctx.taxonomy.slug, content)
|
|
344
354
|
: ctx.collection === "posts"
|
|
345
|
-
?
|
|
355
|
+
? postsTitle
|
|
346
356
|
: undefined;
|
|
347
357
|
return { posts, archiveTitle, pagination: { page, hasMore, basePath: ctx.path } };
|
|
348
358
|
} catch {
|
|
@@ -373,6 +383,8 @@ async function buildDynamicForContent(
|
|
|
373
383
|
ctx,
|
|
374
384
|
loopPerPage(layout),
|
|
375
385
|
content,
|
|
386
|
+
// W-532: the Pagination element's "Posts archive title" words it in the site's language.
|
|
387
|
+
paginationArchiveTitle(layout),
|
|
376
388
|
);
|
|
377
389
|
return { ...referenced, posts, archiveTitle, ...(pagination ? { pagination } : {}) };
|
|
378
390
|
}
|
|
@@ -389,7 +401,13 @@ export async function resolveThemeParts(
|
|
|
389
401
|
astro: AstroLike,
|
|
390
402
|
ctx?: ThemeRequestContext,
|
|
391
403
|
/** What the host knows about the visitor: segments and facts Visitors rules use (W-329). */
|
|
392
|
-
options: {
|
|
404
|
+
options: {
|
|
405
|
+
visitor?: HostVisitor;
|
|
406
|
+
/** The page's language, e.g. "fr-CA", for Post Dates; defaults to Astro's locale (W-688). */
|
|
407
|
+
lang?: string;
|
|
408
|
+
/** Popup and float screen reader names in the site's language (W-690). */
|
|
409
|
+
labels?: ChromeLabels;
|
|
410
|
+
} = {},
|
|
393
411
|
): Promise<ResolvedThemeParts> {
|
|
394
412
|
return resolveThemePartsWith(emdashContent, astro, ctx, options);
|
|
395
413
|
}
|
|
@@ -399,7 +417,13 @@ export async function resolveThemePartsWith(
|
|
|
399
417
|
port: ContentPort,
|
|
400
418
|
astro: AstroLike,
|
|
401
419
|
ctx?: ThemeRequestContext,
|
|
402
|
-
options: {
|
|
420
|
+
options: {
|
|
421
|
+
visitor?: HostVisitor;
|
|
422
|
+
/** The page's language, e.g. "fr-CA", for Post Dates; defaults to Astro's locale (W-688). */
|
|
423
|
+
lang?: string;
|
|
424
|
+
/** Popup and float screen reader names in the site's language (W-690). */
|
|
425
|
+
labels?: ChromeLabels;
|
|
426
|
+
} = {},
|
|
403
427
|
): Promise<ResolvedThemeParts> {
|
|
404
428
|
const context =
|
|
405
429
|
ctx ??
|
|
@@ -490,11 +514,22 @@ export async function resolveThemePartsWith(
|
|
|
490
514
|
...Object.values(dynamic?.loopTemplates ?? {}),
|
|
491
515
|
]),
|
|
492
516
|
);
|
|
493
|
-
const page = renderStored(
|
|
517
|
+
const page = renderStored(
|
|
518
|
+
stored.layout,
|
|
519
|
+
design,
|
|
520
|
+
stored.id,
|
|
521
|
+
formDefinitions,
|
|
522
|
+
dynamic,
|
|
523
|
+
true,
|
|
524
|
+
options.lang ?? astro.currentLocale,
|
|
525
|
+
);
|
|
494
526
|
rendered.push(page);
|
|
495
527
|
// W-216: a header or footer part is the page's banner or contentinfo landmark (hosts put it
|
|
496
528
|
// straight in <body> instead of their own <header>/<footer>).
|
|
497
|
-
|
|
529
|
+
// W-586: a part that already has its own header or footer box keeps that one as the landmark;
|
|
530
|
+
// a second wrapper around it would nest <header> in <header> (invalid, two banners).
|
|
531
|
+
const ownLandmark = /<(?:header|footer)[\s>]/.test(page.html);
|
|
532
|
+
const tag = (!ownLandmark && WRAPPER_TAGS[stored.partType]) || "div";
|
|
498
533
|
const partId = escapeAttr(stored.id);
|
|
499
534
|
const html = page.html
|
|
500
535
|
? `<${tag} class="emvb-theme-${stored.partType}" data-emvb-theme-part="${partId}">${page.html}</${tag}>`
|
|
@@ -581,7 +616,7 @@ export async function resolveThemePartsWith(
|
|
|
581
616
|
const popup: RenderedPopup = {
|
|
582
617
|
id: stored.id,
|
|
583
618
|
title: stored.title,
|
|
584
|
-
html: wrapPopupMarkup(stored.id, html, stored.triggers),
|
|
619
|
+
html: wrapPopupMarkup(stored.id, html, stored.triggers, options.labels),
|
|
585
620
|
css,
|
|
586
621
|
triggers: stored.triggers,
|
|
587
622
|
};
|
|
@@ -605,7 +640,14 @@ export async function resolveThemePartsWith(
|
|
|
605
640
|
const item: RenderedFloat = {
|
|
606
641
|
id: stored.id,
|
|
607
642
|
title: stored.title,
|
|
608
|
-
html: wrapFloatMarkup(
|
|
643
|
+
html: wrapFloatMarkup(
|
|
644
|
+
stored.id,
|
|
645
|
+
stored.title,
|
|
646
|
+
html,
|
|
647
|
+
stored.float,
|
|
648
|
+
surface,
|
|
649
|
+
options.labels?.close,
|
|
650
|
+
),
|
|
609
651
|
css,
|
|
610
652
|
settings: stored.float,
|
|
611
653
|
};
|
package/src/astro/resolve.ts
CHANGED
|
@@ -38,6 +38,8 @@ export async function resolveEmVBPage(
|
|
|
38
38
|
slug?: string;
|
|
39
39
|
/** What the host knows about the visitor: segments and facts Visitors rules use (W-329). */
|
|
40
40
|
visitor?: HostVisitor;
|
|
41
|
+
/** The page's language, e.g. "fr-CA", for Post Dates; defaults to Astro's locale (W-688). */
|
|
42
|
+
lang?: string;
|
|
41
43
|
} = {},
|
|
42
44
|
): Promise<ResolvedEmVBPage | null> {
|
|
43
45
|
return resolveEmVBPageWith(emdashContent, astro, options);
|
|
@@ -51,6 +53,8 @@ export async function resolveEmVBPageWith(
|
|
|
51
53
|
param?: string;
|
|
52
54
|
slug?: string;
|
|
53
55
|
visitor?: HostVisitor;
|
|
56
|
+
/** The page's language, e.g. "fr-CA", for Post Dates; defaults to Astro's locale (W-688). */
|
|
57
|
+
lang?: string;
|
|
54
58
|
} = {},
|
|
55
59
|
): Promise<ResolvedEmVBPage | null> {
|
|
56
60
|
const slug = options.slug ?? content.decodeSlug(astro.params[options.param ?? "slug"]);
|
|
@@ -91,7 +95,9 @@ export async function resolveEmVBPageWith(
|
|
|
91
95
|
layout,
|
|
92
96
|
astro.url,
|
|
93
97
|
astro,
|
|
94
|
-
|
|
98
|
+
// W-666: Loop Item parts too. A Visitors rule, A/B test, bound field or collection Loop in
|
|
99
|
+
// one was never seen, so the visitor was never read and "only for" elements stayed hidden.
|
|
100
|
+
[...Object.values(sectionTemplates), ...Object.values(loopTemplates)],
|
|
95
101
|
options.visitor ? { visitor: options.visitor } : {},
|
|
96
102
|
content,
|
|
97
103
|
)),
|
|
@@ -103,6 +109,8 @@ export async function resolveEmVBPageWith(
|
|
|
103
109
|
String(data["id"] ?? slug),
|
|
104
110
|
formDefinitions,
|
|
105
111
|
Object.keys(dynamic).length > 0 ? dynamic : undefined,
|
|
112
|
+
false,
|
|
113
|
+
options.lang ?? astro.currentLocale,
|
|
106
114
|
),
|
|
107
115
|
entry,
|
|
108
116
|
title: typeof data["title"] === "string" ? data["title"] : "",
|
|
@@ -90,6 +90,8 @@ function enhance(root: HTMLElement): void {
|
|
|
90
90
|
activate(root, selectedIndex(root));
|
|
91
91
|
|
|
92
92
|
list.addEventListener("keydown", (event) => {
|
|
93
|
+
// W-675: Alt+Left is the browser's Back; Ctrl/Cmd+Home and friends belong to the browser too.
|
|
94
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.defaultPrevented) return;
|
|
93
95
|
// W-405: in right-to-left text the first tab is on the right, so the arrows swap.
|
|
94
96
|
const rtl = list.closest("[dir]")?.getAttribute("dir")?.toLowerCase() === "rtl";
|
|
95
97
|
const key =
|
|
@@ -105,6 +107,16 @@ function enhance(root: HTMLElement): void {
|
|
|
105
107
|
activate(root, target(selectedIndex(root), labels.length), true);
|
|
106
108
|
});
|
|
107
109
|
|
|
110
|
+
// W-779: a click on a tab focused its invisible radio (the label's default), so the arrows that
|
|
111
|
+
// followed moved an unseen focus and Tab stopped on the tab again. Select and focus the tab.
|
|
112
|
+
list.addEventListener("click", (event) => {
|
|
113
|
+
const label = (event.target as Element | null)?.closest?.<HTMLElement>(".emvb-tab-label");
|
|
114
|
+
const index = label ? labels.indexOf(label) : -1;
|
|
115
|
+
if (index < 0 || event.defaultPrevented) return;
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
activate(root, index, true);
|
|
118
|
+
});
|
|
119
|
+
|
|
108
120
|
// Keep ARIA in sync when the CSS-only radio path is used (click / label).
|
|
109
121
|
root.addEventListener("change", (event) => {
|
|
110
122
|
const target = event.target as HTMLInputElement | null;
|
package/src/astro/theme-posts.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loopPermalink, type ThemePostFields } from "../core/index.ts";
|
|
1
|
+
import { clipText, loopPermalink, type ThemePostFields } from "../core/index.ts";
|
|
2
2
|
|
|
3
3
|
type MediaLike = {
|
|
4
4
|
src?: unknown;
|
|
@@ -104,7 +104,7 @@ export function plainFieldsOf(
|
|
|
104
104
|
for (const [key, value] of Object.entries(data)) {
|
|
105
105
|
if (Object.keys(fields).length >= 100) break;
|
|
106
106
|
if (!FIELD_NAME.test(key) || MAPPED.has(key)) continue;
|
|
107
|
-
if (typeof value === "string") fields[key] = value
|
|
107
|
+
if (typeof value === "string") fields[key] = clipText(value, 2000);
|
|
108
108
|
else if (typeof value === "number" && Number.isFinite(value)) fields[key] = value;
|
|
109
109
|
else if (typeof value === "boolean") fields[key] = value;
|
|
110
110
|
else if (value instanceof Date) {
|
package/src/astro/visitor.ts
CHANGED
|
@@ -21,6 +21,8 @@ export type VisitorAstro = {
|
|
|
21
21
|
};
|
|
22
22
|
response?: { headers: Headers };
|
|
23
23
|
locals?: unknown;
|
|
24
|
+
/** Astro's i18n locale for this request, e.g. "fr" (W-688). */
|
|
25
|
+
currentLocale?: string | undefined;
|
|
24
26
|
/** Astro's route cache, when the host configured a provider. */
|
|
25
27
|
cache?: { enabled: boolean; set(input: false): void };
|
|
26
28
|
};
|
package/src/constants.ts
CHANGED
package/src/core/a11y/audit.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
import { clipText } from "../limits.ts";
|
|
1
2
|
import type { DesignSystem } from "../schema/design.ts";
|
|
2
3
|
import { isParentNode, type Layout, type LayoutNode } from "../schema/layout.ts";
|
|
4
|
+
import { boxBecomesLink } from "../render/extras.ts";
|
|
3
5
|
import { updateNode } from "../tree-ops.ts";
|
|
4
6
|
|
|
7
|
+
/**
|
|
8
|
+
* W-572: text as a screen reader says it: invisible format characters (zero-width space, word
|
|
9
|
+
* joiner, BOM, bidi marks, soft hyphen) and blank-looking fillers go, then spaces are trimmed.
|
|
10
|
+
* A label of only those reads as nothing.
|
|
11
|
+
*/
|
|
12
|
+
const spoken = (value: unknown): string =>
|
|
13
|
+
String(value ?? "")
|
|
14
|
+
.replace(/[\p{Cf}\u115F\u1160\u2800\u3164\uFFA0]/gu, "")
|
|
15
|
+
.trim();
|
|
16
|
+
|
|
5
17
|
export type A11yFix =
|
|
6
18
|
| { kind: "heading-level"; level: number }
|
|
7
19
|
| { kind: "decorative" }
|
|
@@ -25,7 +37,8 @@ export type A11yIssue = {
|
|
|
25
37
|
| "image-sizes"
|
|
26
38
|
| "control-name"
|
|
27
39
|
| "empty-heading"
|
|
28
|
-
| "landmark-name"
|
|
40
|
+
| "landmark-name"
|
|
41
|
+
| "motion";
|
|
29
42
|
severity: "error" | "warning";
|
|
30
43
|
message: string;
|
|
31
44
|
/** The one-click fix, when there is a safe one. */
|
|
@@ -111,7 +124,14 @@ const TEXT_TYPES = new Set([
|
|
|
111
124
|
const FIELD_TYPES = new Set(["text-input", "textarea", "select", "checkbox", "radio"]);
|
|
112
125
|
const LINKISH = new Set(["link", "button", "menu-item"]);
|
|
113
126
|
|
|
114
|
-
function px(value: unknown): number | undefined {
|
|
127
|
+
function px(value: unknown, design?: DesignSystem): number | undefined {
|
|
128
|
+
// W-651: a font size variable counts at its size; a fluid one at its smallest, where the text
|
|
129
|
+
// is hardest to read.
|
|
130
|
+
if (design && value && typeof value === "object" && "var" in value) {
|
|
131
|
+
const found = design.variables.fontSizes?.find((v) => v.id === (value as { var: unknown }).var);
|
|
132
|
+
if (!found) return undefined;
|
|
133
|
+
return found.fluid ? Math.min(found.fluid.min, found.fluid.max) : px(found.value);
|
|
134
|
+
}
|
|
115
135
|
if (!value || typeof value !== "object" || !("unit" in value)) return undefined;
|
|
116
136
|
const v = value as { value: number; unit: string };
|
|
117
137
|
if (v.unit === "px") return v.value;
|
|
@@ -119,10 +139,44 @@ function px(value: unknown): number | undefined {
|
|
|
119
139
|
return undefined;
|
|
120
140
|
}
|
|
121
141
|
|
|
122
|
-
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
142
|
+
/** Browser default heading sizes in px, H1 to H6 (all bold). */
|
|
143
|
+
const HEADING_PX = [32, 24, 18.72, 16, 13.28, 10.72];
|
|
144
|
+
|
|
145
|
+
const headingLevel = (node: LayoutNode): number | undefined => {
|
|
146
|
+
if (node.type !== "heading") return undefined;
|
|
147
|
+
const level = (node.props as { level?: unknown }).level;
|
|
148
|
+
return typeof level === "number" && level >= 1 && level <= 6 ? level : 2;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The site's starting styles for the tag (W-639), then global classes in stylesheet order, then
|
|
153
|
+
* the element's own style (W-637, W-638).
|
|
154
|
+
*/
|
|
155
|
+
function effectiveStyle(
|
|
156
|
+
node: LayoutNode,
|
|
157
|
+
design: DesignSystem,
|
|
158
|
+
): Record<string, unknown> | undefined {
|
|
159
|
+
const level = headingLevel(node);
|
|
160
|
+
const tagDefaults =
|
|
161
|
+
level === undefined
|
|
162
|
+
? undefined
|
|
163
|
+
: (design.defaults?.[`h${level}` as "h1"] as Record<string, unknown> | undefined);
|
|
164
|
+
const classIds = new Set(node.classes ?? []);
|
|
165
|
+
if (classIds.size === 0 && !tagDefaults) return node.style as Record<string, unknown> | undefined;
|
|
166
|
+
const fromClasses = (design.classes ?? [])
|
|
167
|
+
.filter((c) => classIds.has(c.id))
|
|
168
|
+
.reduce<Record<string, unknown>>((acc, c) => Object.assign(acc, c.style), { ...tagDefaults });
|
|
169
|
+
return { ...fromClasses, ...(node.style as Record<string, unknown> | undefined) };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Large text (24 px, or 18.66 px bold) needs 3:1; other text 4.5:1. H4 to H6 are not large (W-639). */
|
|
173
|
+
function largeText(node: LayoutNode, design: DesignSystem): boolean {
|
|
174
|
+
const style = effectiveStyle(node, design) as
|
|
175
|
+
| { fontSize?: unknown; fontWeight?: unknown }
|
|
176
|
+
| undefined;
|
|
177
|
+
const level = headingLevel(node);
|
|
178
|
+
const size =
|
|
179
|
+
px(style?.fontSize, design) ?? (level === undefined ? 16 : (HEADING_PX[level - 1] ?? 24));
|
|
126
180
|
const weight =
|
|
127
181
|
typeof style?.fontWeight === "number" ? style.fontWeight : node.type === "heading" ? 700 : 400;
|
|
128
182
|
return size >= 24 || (size >= 18.66 && weight >= 700);
|
|
@@ -133,6 +187,24 @@ function largeText(node: LayoutNode): boolean {
|
|
|
133
187
|
* the single H1, link names, vague link text, text contrast against its background, focusable
|
|
134
188
|
* elements hidden with aria-hidden, and unannounced new tabs. Each issue points at an element; most have a safe fix.
|
|
135
189
|
*/
|
|
190
|
+
/**
|
|
191
|
+
* W-798: whether a linked box has anything inside for its link name: text, a heading, a label, a
|
|
192
|
+
* non-decorative image's alt, or an icon's or SVG's title. Bound and dynamic content counts, as
|
|
193
|
+
* its text isn't known here.
|
|
194
|
+
*/
|
|
195
|
+
function boxHasName(node: LayoutNode): boolean {
|
|
196
|
+
if (node.bind || node.type.startsWith("post-") || node.type === "loop" || node.type === "section")
|
|
197
|
+
return true;
|
|
198
|
+
const props = node.props as Record<string, unknown>;
|
|
199
|
+
const decorative = props["decorative"] === true;
|
|
200
|
+
const named =
|
|
201
|
+
node.type === "image" || node.type === "icon" || node.type === "svg"
|
|
202
|
+
? !decorative && spoken(node.type === "image" ? props["alt"] : props["title"]) !== ""
|
|
203
|
+
: ["text", "title", "label", "summary", "caption"].some((key) => spoken(props[key]) !== "");
|
|
204
|
+
if (named) return true;
|
|
205
|
+
return isParentNode(node) && node.children.some(boxHasName);
|
|
206
|
+
}
|
|
207
|
+
|
|
136
208
|
export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
137
209
|
const issues: A11yIssue[] = [];
|
|
138
210
|
const add = (issue: Omit<A11yIssue, "id">) =>
|
|
@@ -164,7 +236,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
164
236
|
const before = variant?.arm === "b" ? beforeA.get(variant.test) : undefined;
|
|
165
237
|
if (before) [h1s, lastLevel] = [[...before[0]], before[1]];
|
|
166
238
|
const outerFade = fade;
|
|
167
|
-
const opacity = (node
|
|
239
|
+
const opacity = effectiveStyle(node, design)?.opacity;
|
|
168
240
|
if (typeof opacity === "number" && opacity >= 0 && opacity < 1) fade *= opacity;
|
|
169
241
|
const outerShown = shownOn;
|
|
170
242
|
shownOn = shownOn.map((shown, i) => shown && !node.hiddenOn?.includes(DEVICES[i] ?? "desktop"));
|
|
@@ -177,11 +249,19 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
177
249
|
};
|
|
178
250
|
const visitNode = (node: LayoutNode, bg: string | undefined, color: string | undefined): void => {
|
|
179
251
|
const props = node.props as Record<string, unknown>;
|
|
180
|
-
const style = node
|
|
181
|
-
| {
|
|
252
|
+
const style = effectiveStyle(node, design) as
|
|
253
|
+
| {
|
|
254
|
+
backgroundColor?: unknown;
|
|
255
|
+
color?: unknown;
|
|
256
|
+
backgroundImage?: unknown;
|
|
257
|
+
backgroundVideo?: unknown;
|
|
258
|
+
gradient?: unknown;
|
|
259
|
+
}
|
|
182
260
|
| undefined;
|
|
183
|
-
// A background image hides the colour behind the text: contrast can't be
|
|
184
|
-
|
|
261
|
+
// A background image, video or gradient hides the colour behind the text: contrast can't be
|
|
262
|
+
// judged below it (W-633: a gradient or video was judged against the colour under it).
|
|
263
|
+
const covered = style?.backgroundImage || style?.backgroundVideo || style?.gradient;
|
|
264
|
+
const ownBg = covered ? "unknown" : hexOf(style?.backgroundColor, design);
|
|
185
265
|
const nextBg =
|
|
186
266
|
ownBg && ownBg !== "unknown" && bg && bg !== "unknown" ? over(ownBg, bg) : (ownBg ?? bg);
|
|
187
267
|
const nextColor = hexOf(style?.color, design) ?? color;
|
|
@@ -196,14 +276,14 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
196
276
|
message: "This image is a link but is marked decorative, so the link has no name.",
|
|
197
277
|
});
|
|
198
278
|
} else if (node.type === "image" && props["decorative"] !== true) {
|
|
199
|
-
const alt = typeof props["alt"] === "string" ? props["alt"]
|
|
279
|
+
const alt = typeof props["alt"] === "string" ? spoken(props["alt"]) : "";
|
|
200
280
|
if (USELESS_ALT.test(alt)) {
|
|
201
281
|
add({
|
|
202
282
|
nodeId: node.id,
|
|
203
283
|
rule: "image-alt",
|
|
204
284
|
severity: "error",
|
|
205
285
|
message: alt
|
|
206
|
-
? `The alt text "${alt
|
|
286
|
+
? `The alt text "${clipText(alt, 40)}" doesn't describe the image.`
|
|
207
287
|
: "This image has no alt text.",
|
|
208
288
|
...(imageLinked
|
|
209
289
|
? {}
|
|
@@ -211,6 +291,38 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
211
291
|
});
|
|
212
292
|
}
|
|
213
293
|
}
|
|
294
|
+
// W-786: a non-decorative SVG renders role="img"; with no Title and no <title> in its markup
|
|
295
|
+
// it reached visitors with no name.
|
|
296
|
+
if (
|
|
297
|
+
node.type === "svg" &&
|
|
298
|
+
props["decorative"] !== true &&
|
|
299
|
+
!spoken(props["title"]) &&
|
|
300
|
+
!/<title\b[^>]*>\s*[^<\s]/i.test(String(props["markup"] ?? ""))
|
|
301
|
+
) {
|
|
302
|
+
add({
|
|
303
|
+
nodeId: node.id,
|
|
304
|
+
rule: "image-alt",
|
|
305
|
+
severity: "error",
|
|
306
|
+
message: "This SVG has no title, so screen readers can't say what it shows.",
|
|
307
|
+
fix: { kind: "decorative" as const },
|
|
308
|
+
fixLabel: "Mark as decorative",
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
// W-791: a spin or pulse loops forever; reduced-motion visitors are spared, but everyone
|
|
312
|
+
// else gets motion they can't pause (WCAG 2.2.2) unless it is essential, like a spinner.
|
|
313
|
+
const looping = [node.style, ...Object.values(node.devices ?? {})].some((st) => {
|
|
314
|
+
const anim = (st as { iconAnimation?: { type?: unknown } } | undefined)?.iconAnimation;
|
|
315
|
+
return anim?.type === "spin" || anim?.type === "pulse";
|
|
316
|
+
});
|
|
317
|
+
if (looping) {
|
|
318
|
+
add({
|
|
319
|
+
nodeId: node.id,
|
|
320
|
+
rule: "motion",
|
|
321
|
+
severity: "warning",
|
|
322
|
+
message:
|
|
323
|
+
"This icon animates without end and visitors can't pause it. Keep it only if the motion is essential, such as a loading spinner.",
|
|
324
|
+
});
|
|
325
|
+
}
|
|
214
326
|
// W-403: with extra sizes but no Width, the main image is left out of srcset, so wide screens
|
|
215
327
|
// can only get the listed copies.
|
|
216
328
|
if (node.type === "image" && Array.isArray(props["sources"]) && props["sources"].length > 0) {
|
|
@@ -243,12 +355,12 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
243
355
|
}
|
|
244
356
|
// W-408: a blank tab label or accordion title renders a tab or summary with no name.
|
|
245
357
|
// W-416: a form field with no label (a placeholder is not one: it goes once you type).
|
|
246
|
-
if (FIELD_TYPES.has(node.type) && !
|
|
358
|
+
if (FIELD_TYPES.has(node.type) && !spoken(props["label"]) && !node.bind) {
|
|
247
359
|
add({
|
|
248
360
|
nodeId: node.id,
|
|
249
361
|
rule: "control-name",
|
|
250
362
|
severity: "error",
|
|
251
|
-
message:
|
|
363
|
+
message: spoken(props["placeholder"])
|
|
252
364
|
? "This field has only a placeholder, which disappears once you type; give it a label."
|
|
253
365
|
: "This field has no label, so screen readers can't say what it's for.",
|
|
254
366
|
});
|
|
@@ -259,7 +371,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
259
371
|
video: "title",
|
|
260
372
|
} as const;
|
|
261
373
|
if (node.type === "tab-panel" || node.type === "accordion-item" || node.type === "video") {
|
|
262
|
-
const name =
|
|
374
|
+
const name = spoken(props[NAME_PROP[node.type]]);
|
|
263
375
|
if (!name && !node.bind) {
|
|
264
376
|
add({
|
|
265
377
|
nodeId: node.id,
|
|
@@ -277,7 +389,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
277
389
|
}
|
|
278
390
|
// W-424: two menus with the same name are two "Menu navigation" landmarks nobody can tell apart.
|
|
279
391
|
if (node.type === "menu" && (node.children?.length ?? 0) > 0) {
|
|
280
|
-
const name =
|
|
392
|
+
const name = spoken(props["label"]) || "Menu";
|
|
281
393
|
const key = name.toLowerCase();
|
|
282
394
|
if (menuNames.some((names, i) => shownOn[i] && names.has(key))) {
|
|
283
395
|
add({
|
|
@@ -292,7 +404,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
292
404
|
});
|
|
293
405
|
}
|
|
294
406
|
// W-419: an empty heading still shows up in screen readers' heading list, with nothing to say.
|
|
295
|
-
if (node.type === "heading" && !
|
|
407
|
+
if (node.type === "heading" && !spoken(props["text"]) && !node.bind) {
|
|
296
408
|
add({
|
|
297
409
|
nodeId: node.id,
|
|
298
410
|
rule: "empty-heading",
|
|
@@ -328,8 +440,16 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
328
440
|
}
|
|
329
441
|
lastLevel = level;
|
|
330
442
|
}
|
|
443
|
+
if (boxBecomesLink(node) && !boxHasName(node)) {
|
|
444
|
+
add({
|
|
445
|
+
nodeId: node.id,
|
|
446
|
+
rule: "link-name",
|
|
447
|
+
severity: "error",
|
|
448
|
+
message: "This box is a link, but nothing inside it has text, so the link has no name.",
|
|
449
|
+
});
|
|
450
|
+
}
|
|
331
451
|
if (LINKISH.has(node.type) || (node.type === "icon" && props["href"])) {
|
|
332
|
-
const text =
|
|
452
|
+
const text = spoken(props["text"] ?? props["title"]);
|
|
333
453
|
const hasHref = typeof props["href"] === "string" && props["href"].trim() !== "";
|
|
334
454
|
if (!text && !node.bind) {
|
|
335
455
|
add({
|
|
@@ -365,7 +485,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
365
485
|
}
|
|
366
486
|
if (TEXT_TYPES.has(node.type) && nextColor && nextBg && nextBg !== "unknown") {
|
|
367
487
|
const ratio = contrastRatio(over(nextColor, nextBg, fade), nextBg);
|
|
368
|
-
const needed = largeText(node) ? 3 : 4.5;
|
|
488
|
+
const needed = largeText(node, design) ? 3 : 4.5;
|
|
369
489
|
if (ratio < needed) {
|
|
370
490
|
const black = contrastRatio("#000000", nextBg);
|
|
371
491
|
const white = contrastRatio("#ffffff", nextBg);
|
|
@@ -373,13 +493,15 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
373
493
|
// W-421: when opacity is what fades the text, a new colour can't fix it; say so instead
|
|
374
494
|
// of offering a fix that leaves the issue in place.
|
|
375
495
|
const fixable = contrastRatio(over(better, nextBg, fade), nextBg) >= needed;
|
|
496
|
+
// W-772: round down, so 4.48:1 reads "4.4:1", never "4.5:1; it needs 4.5:1".
|
|
497
|
+
const shown = (Math.floor(ratio * 10) / 10).toFixed(1);
|
|
376
498
|
add({
|
|
377
499
|
nodeId: node.id,
|
|
378
500
|
rule: "contrast",
|
|
379
501
|
severity: "error",
|
|
380
502
|
message: fixable
|
|
381
|
-
? `Text contrast is ${
|
|
382
|
-
: `Text contrast is ${
|
|
503
|
+
? `Text contrast is ${shown}:1; it needs ${needed}:1.`
|
|
504
|
+
: `Text contrast is ${shown}:1; it needs ${needed}:1. Opacity on this element or a parent fades it; raise the opacity.`,
|
|
383
505
|
...(fixable
|
|
384
506
|
? {
|
|
385
507
|
fix: { kind: "text-color" as const, color: better },
|
|
@@ -389,8 +511,12 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
389
511
|
});
|
|
390
512
|
}
|
|
391
513
|
}
|
|
514
|
+
// W-650: every form control takes keyboard focus, not just a text box.
|
|
392
515
|
const focusable =
|
|
393
|
-
LINKISH.has(node.type) ||
|
|
516
|
+
LINKISH.has(node.type) ||
|
|
517
|
+
FIELD_TYPES.has(node.type) ||
|
|
518
|
+
node.type === "submit" ||
|
|
519
|
+
Boolean(props["href"]);
|
|
394
520
|
const ownAriaHidden = (node.attributes ?? []).some(
|
|
395
521
|
(a) => a.name === "aria-hidden" && a.value === "true",
|
|
396
522
|
);
|
|
@@ -454,5 +580,26 @@ export function applyA11yFix(layout: Layout, issue: A11yIssue): Layout {
|
|
|
454
580
|
|
|
455
581
|
/** Applies every issue's fix at once (W-317). */
|
|
456
582
|
export function applyAllA11yFixes(layout: Layout, issues: A11yIssue[]): Layout {
|
|
457
|
-
|
|
583
|
+
const fixed = issues.reduce((next, issue) => applyA11yFix(next, issue), layout);
|
|
584
|
+
// W-773: each heading-order fix was worked out against the page before any fix, so H1, H4,
|
|
585
|
+
// H6 became H1, H2, H5 and the H5 still skipped. Re-chain the fixed headings in page order.
|
|
586
|
+
const order = new Set(issues.filter((i) => i.rule === "heading-order").map((i) => i.nodeId));
|
|
587
|
+
if (order.size === 0) return fixed;
|
|
588
|
+
const levels = new Map<string, number>();
|
|
589
|
+
let last = 0;
|
|
590
|
+
const walk = (node: LayoutNode) => {
|
|
591
|
+
if (node.type === "heading") {
|
|
592
|
+
const own = typeof node.props["level"] === "number" ? node.props["level"] : 2;
|
|
593
|
+
const level = order.has(node.id) ? Math.min(own, Math.max(2, last + 1)) : own;
|
|
594
|
+
if (level !== own) levels.set(node.id, level);
|
|
595
|
+
last = level;
|
|
596
|
+
}
|
|
597
|
+
if (isParentNode(node)) node.children.forEach(walk);
|
|
598
|
+
};
|
|
599
|
+
walk(fixed.root);
|
|
600
|
+
return [...levels].reduce(
|
|
601
|
+
(next, [id, level]) =>
|
|
602
|
+
updateNode(next, id, (node) => ({ ...node, props: { ...node.props, level } }) as LayoutNode),
|
|
603
|
+
fixed,
|
|
604
|
+
);
|
|
458
605
|
}
|
package/src/core/arrange.ts
CHANGED
|
@@ -266,7 +266,8 @@ export const CSS_ID_KEPT = "The CSS id stays on the original: CSS ids must be un
|
|
|
266
266
|
/** `node` without the CSS id on it or any descendant; returns how many it dropped. */
|
|
267
267
|
function withoutHtmlIds(node: LayoutNode): { node: LayoutNode; dropped: number } {
|
|
268
268
|
let dropped = node.htmlId ? 1 : 0;
|
|
269
|
-
|
|
269
|
+
// A copy is never part of an A/B test: it would join the original's test as an extra arm (W-629).
|
|
270
|
+
const { htmlId: _htmlId, variant: _variant, ...rest } = node;
|
|
270
271
|
const kids = nodeChildren(node);
|
|
271
272
|
if (kids.length === 0) return { node: rest as LayoutNode, dropped };
|
|
272
273
|
const children = kids.map((child) => {
|
|
@@ -511,14 +512,34 @@ export function subtreeSize(layout: Layout, id: string): number {
|
|
|
511
512
|
return node ? size(node) : 0;
|
|
512
513
|
}
|
|
513
514
|
|
|
514
|
-
/**
|
|
515
|
-
|
|
516
|
-
|
|
515
|
+
/**
|
|
516
|
+
* The default A/B test name for an element (W-312): `test-` and its id, lowercased.
|
|
517
|
+
* W-701: `taken` names are skipped (`-2`, `-3`…). Ids that only differ in case, punctuation or
|
|
518
|
+
* after their 12th character ("featurecard01", "featurecard02") made the same name, which merged
|
|
519
|
+
* two tests: ending one deleted the other's elements.
|
|
520
|
+
*/
|
|
521
|
+
export const defaultTestName = (id: string, taken: ReadonlySet<string> = new Set()): string => {
|
|
522
|
+
const base = `test-${
|
|
517
523
|
id
|
|
518
524
|
.toLowerCase()
|
|
519
525
|
.replace(/[^a-z0-9]/g, "")
|
|
520
|
-
.slice(0,
|
|
526
|
+
.slice(0, 20) || "1"
|
|
521
527
|
}`;
|
|
528
|
+
let name = base;
|
|
529
|
+
for (let n = 2; taken.has(name); n++) name = `${base}-${n}`;
|
|
530
|
+
return name;
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
/** The A/B test names already used in a layout. */
|
|
534
|
+
function testNames(layout: Layout): Set<string> {
|
|
535
|
+
const names = new Set<string>();
|
|
536
|
+
const walk = (node: LayoutNode): void => {
|
|
537
|
+
if (node.variant?.test) names.add(node.variant.test);
|
|
538
|
+
for (const child of nodeChildren(node)) walk(child);
|
|
539
|
+
};
|
|
540
|
+
walk(layout.root);
|
|
541
|
+
return names;
|
|
542
|
+
}
|
|
522
543
|
|
|
523
544
|
/**
|
|
524
545
|
* Edge A/B testing (W-312): the element becomes arm A of a new test and a copy right after it
|
|
@@ -533,7 +554,7 @@ export function createVariantB(
|
|
|
533
554
|
if (!found) return refuse(REASONS.missing);
|
|
534
555
|
if (found.node.variant) return refuse("This element is already in an A/B test.");
|
|
535
556
|
if (found.node.type === "loop-empty" || !found.parent) return refuse(REASONS.rootCopy);
|
|
536
|
-
const variant = { test: defaultTestName(found.node.id), arm: "a" as const };
|
|
557
|
+
const variant = { test: defaultTestName(found.node.id, testNames(layout)), arm: "a" as const };
|
|
537
558
|
const marked = updateNode(layout, id, (node) => ({ ...node, variant }) as LayoutNode);
|
|
538
559
|
const copied = duplicateNode(marked, id, random);
|
|
539
560
|
if (!copied.ok) return copied;
|
|
@@ -60,7 +60,11 @@ function matches(audience: Audience, visitor: VisitorInfo): boolean {
|
|
|
60
60
|
if (visitor.now === undefined) return false;
|
|
61
61
|
const { hour, day } = clockIn(visitor.now, audience.timeZone);
|
|
62
62
|
if (audience.hours && !inHours(hour, audience.hours.from, audience.hours.to)) return false;
|
|
63
|
-
|
|
63
|
+
// W-665: the hours past midnight of an overnight window (Fri 22:00–02:00) belong to the day
|
|
64
|
+
// it started; on Saturday at 01:00 a Friday-only rule hid the element mid-window.
|
|
65
|
+
const { from, to } = audience.hours ?? { from: 0, to: 0 };
|
|
66
|
+
const startedDay = from > to && hour < to ? (day + 6) % 7 : day;
|
|
67
|
+
if (audience.days && !audience.days.includes(startedDay)) return false;
|
|
64
68
|
}
|
|
65
69
|
return true;
|
|
66
70
|
}
|