@perkyzz/emvb 0.5.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/README.md +4 -0
- package/THIRD_PARTY_NOTICES.md +23 -1
- package/licenses/exif-js.LICENSE +21 -0
- package/licenses/fflate.LICENSE +21 -0
- package/licenses/glfx.js.LICENSE +19 -0
- package/licenses/mini-photo-editor.LICENSE +21 -0
- package/licenses/photocn.LICENSE +21 -0
- package/package.json +2 -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 +88 -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 +16 -1
- 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 +108 -7
- package/src/admin/editor/editor-commands.ts +15 -1
- package/src/admin/editor/editor-css.ts +75 -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 +135 -27
- 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 +68 -22
- 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 +53 -21
- 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 +38 -15
- 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 +274 -20
- 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 +141 -0
- 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 +25 -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 +14 -3
- 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/BlurFocus.tsx +112 -0
- package/src/admin/image-editor/Canvas.tsx +261 -0
- package/src/admin/image-editor/CropOverlay.tsx +390 -0
- package/src/admin/image-editor/CurvesPanel.tsx +395 -0
- package/src/admin/image-editor/ExportDialog.tsx +384 -0
- package/src/admin/image-editor/ImageEditButton.tsx +83 -0
- package/src/admin/image-editor/ImageEditorDialog.tsx +828 -0
- package/src/admin/image-editor/MetadataPanel.tsx +194 -0
- package/src/admin/image-editor/announce.tsx +65 -0
- package/src/admin/image-editor/crop-geometry.ts +162 -0
- package/src/admin/image-editor/curve-math.ts +177 -0
- package/src/admin/image-editor/data-url-fetch.ts +59 -0
- package/src/admin/image-editor/engine.ts +55 -0
- package/src/admin/image-editor/exif.ts +82 -0
- package/src/admin/image-editor/flatten.ts +54 -0
- package/src/admin/image-editor/gpu-fit.ts +81 -0
- package/src/admin/image-editor/image-editor-css.ts +400 -0
- package/src/admin/image-editor/load.ts +116 -0
- package/src/admin/image-editor/panels.tsx +287 -0
- package/src/admin/image-editor/parts.tsx +614 -0
- package/src/admin/image-editor/save.ts +141 -0
- package/src/admin/image-editor/tone-panels.tsx +338 -0
- package/src/admin/image-editor/tools.ts +59 -0
- package/src/admin/image-editor/worker.ts +111 -0
- package/src/admin/media-api.ts +114 -3
- 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 +78 -22
- package/src/astro/EmVBPage.astro +11 -2
- 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 +6 -0
- package/src/astro/resolve-theme.ts +67 -14
- 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 +6 -3
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +171 -24
- package/src/core/arrange.ts +29 -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 +19 -6
- package/src/core/design/classes.ts +20 -9
- package/src/core/design/diff.ts +9 -1
- package/src/core/design/merge.ts +93 -3
- package/src/core/design/tokens.ts +16 -2
- package/src/core/design/transfer.ts +46 -8
- package/src/core/design/variables.ts +32 -10
- package/src/core/elements/dynamic-elements.ts +53 -6
- package/src/core/elements/form-elements.ts +68 -30
- package/src/core/elements/index.ts +83 -38
- package/src/core/elements/menu.ts +37 -19
- package/src/core/elements/plain-text.ts +2 -2
- package/src/core/elements/select-prompt.ts +3 -0
- package/src/core/elements/svg-ids.ts +39 -0
- package/src/core/forms/binding.ts +190 -2
- package/src/core/forms/definition.ts +72 -0
- package/src/core/history/diff.ts +49 -4
- package/src/core/icons/catalog.ts +3 -2
- package/src/core/image-edit/schema.ts +155 -0
- package/src/core/image-edit/summary.ts +61 -0
- package/src/core/index.ts +29 -1
- package/src/core/limits.ts +21 -0
- package/src/core/migrate/index.ts +3 -1
- package/src/core/perf/meter.ts +51 -8
- package/src/core/recipes/index.ts +5 -4
- package/src/core/render/context.ts +8 -0
- package/src/core/render/dynamic-post.ts +71 -13
- package/src/core/render/extras.ts +77 -4
- package/src/core/render/form.ts +164 -12
- package/src/core/render/index.ts +179 -22
- 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 +26 -7
- package/src/core/share/link.ts +5 -2
- package/src/core/stable-json.ts +15 -0
- package/src/core/stats.ts +2 -1
- package/src/core/theme/conditions.ts +3 -1
- package/src/core/theme/dynamic.ts +57 -23
- package/src/core/theme/float.ts +9 -2
- package/src/core/theme/pagination.ts +57 -10
- package/src/core/theme/popup-markup.ts +23 -5
- package/src/core/theme/popup-rules.ts +11 -5
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/tree-ops.ts +27 -0
- package/src/mcp/ports.ts +8 -1
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +82 -3
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/tools.ts +1 -1
- package/src/mcp/write.ts +271 -25
- package/src/server/agent-settings.ts +29 -4
- package/src/server/hooks.ts +5 -3
- package/src/server/icon-routes.ts +33 -9
- package/src/server/mcp-routes.ts +74 -11
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
|
};
|
|
@@ -108,6 +110,8 @@ function requestCookie(astro: VisitorAstro, name: string): string | undefined {
|
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
const COUNTRY = /^[A-Z]{2}$/;
|
|
113
|
+
/** XX is Cloudflare's "unknown" and T1 is Tor: neither is a country (W-514: host facts too). */
|
|
114
|
+
const isCountry = (code: string) => COUNTRY.test(code) && code !== "XX" && code !== "T1";
|
|
111
115
|
|
|
112
116
|
/**
|
|
113
117
|
* The visitor's country from the edge: Cloudflare's header or `request.cf`, or Vercel's header.
|
|
@@ -123,8 +127,7 @@ function countryOf(astro: VisitorAstro): string | undefined {
|
|
|
123
127
|
];
|
|
124
128
|
for (const value of candidates) {
|
|
125
129
|
const code = typeof value === "string" ? value.trim().toUpperCase() : "";
|
|
126
|
-
|
|
127
|
-
if (COUNTRY.test(code) && code !== "XX" && code !== "T1") return code;
|
|
130
|
+
if (isCountry(code)) return code;
|
|
128
131
|
}
|
|
129
132
|
return undefined;
|
|
130
133
|
}
|
|
@@ -159,7 +162,7 @@ export function hostVisitorFacts(host: HostVisitor | undefined): Partial<Visitor
|
|
|
159
162
|
facts.segments = segments;
|
|
160
163
|
}
|
|
161
164
|
const country = typeof host.country === "string" ? host.country.trim().toUpperCase() : "";
|
|
162
|
-
if (
|
|
165
|
+
if (isCountry(country)) facts.country = country;
|
|
163
166
|
if (host.device === "mobile" || host.device === "tablet" || host.device === "desktop")
|
|
164
167
|
facts.device = host.device;
|
|
165
168
|
if (typeof host.returning === "boolean") facts.returning = host.returning;
|
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
|
@@ -204,6 +204,8 @@ export function moveNode(layout: Layout, id: string, parentId: string, index: nu
|
|
|
204
204
|
const from = locate(layout, id) as Located & { parent: ContainerNode | FormNode | LoopNode };
|
|
205
205
|
const sameParent = from.parent.id === parentId;
|
|
206
206
|
const at = sameParent && from.index < index ? index - 1 : index;
|
|
207
|
+
// W-521: a drop on its own spot is no edit; the same layout tells callers nothing changed.
|
|
208
|
+
if (sameParent && at === from.index) return { ok: true, layout, selected: id };
|
|
207
209
|
const { layout: without, removed } = removeNode(layout, id);
|
|
208
210
|
if (!removed) return refuse(REASONS.missing);
|
|
209
211
|
return { ok: true, layout: insertNode(without, parentId, at, removed.node), selected: id };
|
|
@@ -264,7 +266,8 @@ export const CSS_ID_KEPT = "The CSS id stays on the original: CSS ids must be un
|
|
|
264
266
|
/** `node` without the CSS id on it or any descendant; returns how many it dropped. */
|
|
265
267
|
function withoutHtmlIds(node: LayoutNode): { node: LayoutNode; dropped: number } {
|
|
266
268
|
let dropped = node.htmlId ? 1 : 0;
|
|
267
|
-
|
|
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;
|
|
268
271
|
const kids = nodeChildren(node);
|
|
269
272
|
if (kids.length === 0) return { node: rest as LayoutNode, dropped };
|
|
270
273
|
const children = kids.map((child) => {
|
|
@@ -509,14 +512,34 @@ export function subtreeSize(layout: Layout, id: string): number {
|
|
|
509
512
|
return node ? size(node) : 0;
|
|
510
513
|
}
|
|
511
514
|
|
|
512
|
-
/**
|
|
513
|
-
|
|
514
|
-
|
|
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-${
|
|
515
523
|
id
|
|
516
524
|
.toLowerCase()
|
|
517
525
|
.replace(/[^a-z0-9]/g, "")
|
|
518
|
-
.slice(0,
|
|
526
|
+
.slice(0, 20) || "1"
|
|
519
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
|
+
}
|
|
520
543
|
|
|
521
544
|
/**
|
|
522
545
|
* Edge A/B testing (W-312): the element becomes arm A of a new test and a copy right after it
|
|
@@ -531,7 +554,7 @@ export function createVariantB(
|
|
|
531
554
|
if (!found) return refuse(REASONS.missing);
|
|
532
555
|
if (found.node.variant) return refuse("This element is already in an A/B test.");
|
|
533
556
|
if (found.node.type === "loop-empty" || !found.parent) return refuse(REASONS.rootCopy);
|
|
534
|
-
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 };
|
|
535
558
|
const marked = updateNode(layout, id, (node) => ({ ...node, variant }) as LayoutNode);
|
|
536
559
|
const copied = duplicateNode(marked, id, random);
|
|
537
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
|
}
|
|
@@ -8,12 +8,37 @@ export type AbTest = { test: string; split: number };
|
|
|
8
8
|
/** The cookie that keeps a visitor on one arm of a test (W-312). */
|
|
9
9
|
export const abCookieName = (test: string) => `emvb_ab_${test.replaceAll("-", "_")}`;
|
|
10
10
|
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Tests in the layout that have only one arm (W-625): the other was deleted, cut or moved away.
|
|
13
|
+
* Such a test isn't run and its remaining elements show to every visitor, so nobody sees a gap.
|
|
14
|
+
*/
|
|
15
|
+
export function loneAbTests(layout: Layout): Set<string> {
|
|
16
|
+
const arms = new Map<string, Set<AbArm>>();
|
|
17
|
+
const walk = (node: LayoutNode): void => {
|
|
18
|
+
const v = node.variant;
|
|
19
|
+
if (v) {
|
|
20
|
+
const seen = arms.get(v.test) ?? new Set<AbArm>();
|
|
21
|
+
seen.add(v.arm);
|
|
22
|
+
arms.set(v.test, seen);
|
|
23
|
+
}
|
|
24
|
+
if (isParentNode(node)) for (const child of node.children) walk(child);
|
|
25
|
+
};
|
|
26
|
+
walk(layout.root);
|
|
27
|
+
return new Set([...arms].filter(([, seen]) => seen.size < 2).map(([test]) => test));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Every A/B test in the layout with both arms, at most 10, with B's split (default 50 %). */
|
|
12
31
|
export function collectAbTests(layout: Layout): AbTest[] {
|
|
32
|
+
const lone = loneAbTests(layout);
|
|
13
33
|
const tests = new Map<string, number>();
|
|
14
34
|
const walk = (node: LayoutNode): void => {
|
|
15
35
|
const v = node.variant;
|
|
16
|
-
if (
|
|
36
|
+
if (
|
|
37
|
+
v &&
|
|
38
|
+
!lone.has(v.test) &&
|
|
39
|
+
AB_TEST_NAME.test(v.test) &&
|
|
40
|
+
(tests.has(v.test) || tests.size < 10)
|
|
41
|
+
) {
|
|
17
42
|
const known = tests.get(v.test);
|
|
18
43
|
if (v.arm === "b" && v.split !== undefined) tests.set(v.test, v.split);
|
|
19
44
|
else if (known === undefined) tests.set(v.test, 50);
|
|
@@ -44,8 +69,9 @@ export function pickArm(
|
|
|
44
69
|
export function variantShows(
|
|
45
70
|
node: LayoutNode,
|
|
46
71
|
arms: Readonly<Record<string, AbArm>> | undefined,
|
|
72
|
+
lone?: ReadonlySet<string>,
|
|
47
73
|
): boolean {
|
|
48
74
|
const v = node.variant;
|
|
49
|
-
if (!v) return true;
|
|
75
|
+
if (!v || lone?.has(v.test)) return true;
|
|
50
76
|
return (arms?.[v.test] ?? "a") === v.arm;
|
|
51
77
|
}
|
package/src/core/clipboard.ts
CHANGED
|
@@ -205,6 +205,8 @@ const refsOf = (owner: CopiedStyle): Ref[] => [
|
|
|
205
205
|
...STYLE_STATES.flatMap((state) => refsInStyle(owner.states?.[state])),
|
|
206
206
|
...refsInStyle(owner.devices?.tablet),
|
|
207
207
|
...refsInStyle(owner.devices?.mobile),
|
|
208
|
+
// W-643: a container-query override (W-346) can use a variable too.
|
|
209
|
+
...refsInStyle((owner as { query?: { style?: StyleProps } }).query?.style),
|
|
208
210
|
];
|
|
209
211
|
|
|
210
212
|
const hasVariable = (design: DesignSystem, ref: Ref) =>
|
|
@@ -311,6 +313,11 @@ function cleanNode(
|
|
|
311
313
|
next = { ...next };
|
|
312
314
|
delete next.htmlId;
|
|
313
315
|
}
|
|
316
|
+
if (next.variant) {
|
|
317
|
+
// A pasted copy is never part of an A/B test, like a duplicate (W-632).
|
|
318
|
+
next = { ...next };
|
|
319
|
+
delete next.variant;
|
|
320
|
+
}
|
|
314
321
|
const kids = nodeChildren(next);
|
|
315
322
|
if (kids.length === 0) return next;
|
|
316
323
|
return {
|
package/src/core/css/generate.ts
CHANGED
|
@@ -75,15 +75,20 @@ const block = (selector: string, declarations: Declaration[]) =>
|
|
|
75
75
|
: `${selector}{${declarations.map((d) => `${d.property}:${d.value}`).join(";")}}`;
|
|
76
76
|
|
|
77
77
|
/** Tag defaults sit under `:where` so a class (0,1,0) still beats the tag (0,0,1). */
|
|
78
|
-
function tagDefaultCss(
|
|
78
|
+
function tagDefaultCss(
|
|
79
|
+
design: DesignSystem,
|
|
80
|
+
track: (selector: string, declarations: Declaration[]) => Declaration[],
|
|
81
|
+
): string {
|
|
79
82
|
const defaults = design.defaults;
|
|
80
83
|
if (!defaults) return "";
|
|
81
84
|
let css = "";
|
|
82
85
|
for (const tag of DEFAULT_STYLE_TAGS) {
|
|
83
86
|
const style = defaults[tag];
|
|
84
87
|
if (!style) continue;
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
// W-670: tracked like classes, so a tag default's entrance gets its keyframes and turns off
|
|
89
|
+
// for reduced motion.
|
|
90
|
+
const selector = `:where(.emvb-root) ${tag}`;
|
|
91
|
+
css += block(selector, track(selector, styleDeclarations(style).declarations));
|
|
87
92
|
}
|
|
88
93
|
return css;
|
|
89
94
|
}
|
|
@@ -189,6 +194,8 @@ export function generateCss({
|
|
|
189
194
|
withInheritedLayers(cls.devices?.mobile, { ...cls.style, ...cls.devices?.tablet }),
|
|
190
195
|
).declarations,
|
|
191
196
|
hiddenOn: cls.hiddenOn,
|
|
197
|
+
// W-571: the page root is never hidden (W-567), not even by a class.
|
|
198
|
+
hideSelector: `.${className}:not(.emvb-root)`,
|
|
192
199
|
},
|
|
193
200
|
]
|
|
194
201
|
: [];
|
|
@@ -220,7 +227,7 @@ export function generateCss({
|
|
|
220
227
|
.flatMap((rule) =>
|
|
221
228
|
"figure" in rule && rule.figure
|
|
222
229
|
? [rule.selector, `.emvb-figure:has(>${rule.selector},>a>${rule.selector})`]
|
|
223
|
-
: [rule.selector],
|
|
230
|
+
: ["hideSelector" in rule && rule.hideSelector ? rule.hideSelector : rule.selector],
|
|
224
231
|
);
|
|
225
232
|
return forDevices(
|
|
226
233
|
[device],
|
|
@@ -237,15 +244,33 @@ export function generateCss({
|
|
|
237
244
|
entrances.push(rule.selector);
|
|
238
245
|
}
|
|
239
246
|
}
|
|
247
|
+
const defaultsCss = tagDefaultCss(design, track);
|
|
248
|
+
// W-670: an entrance or scroll motion set only in a container query override pointed at
|
|
249
|
+
// keyframes that were never sent (no animation at all) and ignored reduced motion.
|
|
250
|
+
for (const rule of localRules) {
|
|
251
|
+
const query = rule.query ?? [];
|
|
252
|
+
const selector = `.emvb-e-${rule.id}`;
|
|
253
|
+
if (usesMotion(query)) motion = true;
|
|
254
|
+
if (!entrances.includes(selector) && query.some((d) => d.property === "animation")) {
|
|
255
|
+
entrances.push(selector);
|
|
256
|
+
}
|
|
257
|
+
if (!animated.includes(selector) && query.some((d) => d.property === "transition")) {
|
|
258
|
+
animated.push(selector);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
240
261
|
return [
|
|
241
262
|
entrances.length > 0
|
|
242
263
|
? "@keyframes emvb-fade{from{opacity:0}to{opacity:1}}@keyframes emvb-fade-up{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}@keyframes emvb-fade-down{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:none}}@keyframes emvb-slide-up{from{opacity:0;transform:translateY(16px)}to{opacity:1;transform:none}}@keyframes emvb-slide-down{from{opacity:0;transform:translateY(-16px)}to{opacity:1;transform:none}}@keyframes emvb-scale{from{opacity:0;transform:scale(0.96)}to{opacity:1;transform:none}}"
|
|
243
264
|
: "",
|
|
244
265
|
entrances.length > 0 && motion ? MOTION_KEYFRAMES : "",
|
|
245
266
|
block(".emvb-root", variables),
|
|
246
|
-
|
|
267
|
+
defaultsCss,
|
|
247
268
|
backgroundVideo
|
|
248
|
-
? ".emvb-has-bg-video{position:relative;overflow:hidden}.emvb-bg-video{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;z-index:0;pointer-events:none}.emvb-has-bg-video>:not(.emvb-bg-video){position:relative;z-index:1}"
|
|
269
|
+
? ".emvb-has-bg-video{position:relative;overflow:hidden}.emvb-bg-video{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;z-index:0;pointer-events:none}.emvb-has-bg-video>:not(.emvb-bg-video){position:relative;z-index:1}" +
|
|
270
|
+
// W-802: the overlay above the video, under the content; reset so a nested box's own wins.
|
|
271
|
+
'.emvb-has-bg-video{--emvb-bg-overlay:none}.emvb-has-bg-video::after{content:"";position:absolute;inset:0;z-index:0;pointer-events:none;background:var(--emvb-bg-overlay)}' +
|
|
272
|
+
// W-801: a looping video kept playing for visitors who ask for reduced motion.
|
|
273
|
+
"@media (prefers-reduced-motion: reduce){.emvb-bg-video{display:none}}"
|
|
249
274
|
: "",
|
|
250
275
|
...[...usedTypes].toSorted().map((type) => baseCss.get(type) ?? ""),
|
|
251
276
|
...classes,
|