@perkyzz/emvb 0.9.0 → 1.1.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 +10 -1
- package/package.json +2 -2
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/bulk-api.ts +67 -0
- package/src/admin/content-api.ts +10 -6
- package/src/admin/copy-rich-text.ts +119 -0
- package/src/admin/dialog-tab-wrap.ts +78 -0
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +311 -250
- package/src/admin/editor/Timeline.tsx +8 -3
- package/src/admin/editor/TopBar.tsx +29 -7
- package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +31 -10
- package/src/admin/editor/canvas/canvas-scale.ts +3 -3
- package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
- package/src/admin/editor/co-design.ts +190 -0
- package/src/admin/editor/dnd/new-element.ts +48 -4
- package/src/admin/editor/editor-chrome.tsx +8 -6
- package/src/admin/editor/editor-commands.ts +15 -4
- package/src/admin/editor/editor-css.ts +2 -1
- package/src/admin/editor/element-chrome.ts +3 -1
- package/src/admin/editor/extension-manifests.ts +20 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
- package/src/admin/editor/extensions-context.tsx +27 -0
- package/src/admin/editor/feature-css.ts +17 -0
- package/src/admin/editor/palette-items.ts +2 -2
- package/src/admin/editor/panels/AddPanel.tsx +31 -1
- package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
- package/src/admin/editor/panels/ClassesSection.tsx +9 -6
- package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ElementPanel.tsx +68 -20
- package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
- package/src/admin/editor/panels/LayersPanel.tsx +10 -6
- package/src/admin/editor/panels/LeftPanel.tsx +33 -5
- package/src/admin/editor/panels/PageSettings.tsx +4 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +72 -15
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
- package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
- package/src/admin/editor/panels/settings/EffectsControls.tsx +183 -10
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +25 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +63 -19
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +19 -1
- package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
- package/src/admin/editor/panels/settings/StyleRow.tsx +120 -13
- package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
- package/src/admin/editor/panels/settings/background-mode.ts +14 -11
- package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
- package/src/admin/editor/panels/settings/box-sides.ts +22 -14
- package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
- package/src/admin/editor/panels/settings/length-units.ts +68 -4
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +52 -10
- package/src/admin/editor/panels/style-target.ts +22 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/section-templates.ts +26 -4
- package/src/admin/editor/store.ts +14 -4
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +7 -5
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +18 -7
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/export-api.ts +221 -0
- package/src/admin/index.tsx +6 -1
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +9 -26
- package/src/admin/pages/CreateDialog.tsx +15 -0
- package/src/admin/pages/ExportDialog.tsx +395 -0
- package/src/admin/pages/ImportButton.tsx +18 -0
- package/src/admin/pages/ImportElementorDialog.tsx +669 -0
- package/src/admin/pages/ImportPageLinks.tsx +86 -0
- package/src/admin/pages/PageList.tsx +82 -3
- package/src/admin/pages/ThemePartList.tsx +52 -2
- package/src/admin/pages/bulk.tsx +303 -0
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/search.ts +20 -0
- package/src/admin/theme-api.ts +4 -0
- package/src/admin/ui.ts +50 -4
- package/src/admin/widgets/CanvasField.tsx +8 -0
- package/src/admin/widgets/ConvertToRichText.tsx +136 -0
- package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
- package/src/admin/widgets/convert-body.ts +73 -2
- package/src/astro/content-port.ts +14 -1
- package/src/astro/render.ts +6 -6
- package/src/astro/resolve-theme.ts +25 -8
- package/src/astro/resolve.ts +89 -2
- package/src/astro/tabs/runtime.ts +16 -6
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +45 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +305 -0
- package/src/core/css/generate.ts +151 -20
- package/src/core/css/scope.ts +10 -2
- package/src/core/css/trace.ts +47 -13
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +28 -9
- package/src/core/design/devices.ts +89 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +31 -5
- package/src/core/elements/dynamic-elements.ts +3 -3
- package/src/core/elements/index.ts +73 -9
- package/src/core/export/runtimes.generated.ts +9 -0
- package/src/core/export/site.ts +562 -0
- package/src/core/export/zip.ts +95 -0
- package/src/core/extensions/define.ts +13 -0
- package/src/core/extensions/index.ts +41 -0
- package/src/core/extensions/namespace.ts +82 -0
- package/src/core/extensions/normalize.ts +141 -0
- package/src/core/extensions/placeholder.ts +41 -0
- package/src/core/extensions/registry.ts +94 -0
- package/src/core/extensions/render-ext.ts +118 -0
- package/src/core/extensions/safe-nodes.ts +93 -0
- package/src/core/extensions/schema.ts +112 -0
- package/src/core/extensions/types.ts +159 -0
- package/src/core/forms/binding.ts +1 -1
- package/src/core/history/diff.ts +26 -1
- package/src/core/import/elementor/atomic.ts +1608 -0
- package/src/core/import/elementor/classes.ts +127 -0
- package/src/core/import/elementor/context.ts +429 -0
- package/src/core/import/elementor/counter-steps.ts +72 -0
- package/src/core/import/elementor/css.ts +445 -0
- package/src/core/import/elementor/html.ts +500 -0
- package/src/core/import/elementor/index.ts +967 -0
- package/src/core/import/elementor/inline-marks.ts +81 -0
- package/src/core/import/elementor/snapshots.ts +48 -0
- package/src/core/import/elementor/style.ts +429 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +96 -0
- package/src/core/json-schema.ts +114 -0
- package/src/core/limits.ts +19 -0
- package/src/core/migrate/index.ts +6 -1
- package/src/core/migrate/v18.ts +222 -0
- package/src/core/perf/meter.ts +42 -24
- package/src/core/portable-text-export.ts +243 -0
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/public-attributes.ts +30 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +222 -23
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/tabs.ts +18 -11
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +151 -10
- package/src/core/sanitize/motion.ts +116 -0
- package/src/core/saved-sections.ts +6 -0
- package/src/core/schema/descriptors.ts +3 -1
- package/src/core/schema/design.ts +4 -3
- package/src/core/schema/layout.ts +92 -16
- package/src/core/schema/style.ts +296 -112
- package/src/core/search-text.ts +70 -0
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +2 -0
- package/src/core/theme/popup-rules.ts +33 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +24 -0
- package/src/mcp/errors.ts +3 -1
- package/src/mcp/ports.ts +67 -0
- package/src/mcp/prompts.ts +1 -11
- package/src/mcp/proposals.ts +281 -0
- package/src/mcp/read.ts +10 -10
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +5 -1
- package/src/server/icon-routes.ts +52 -12
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +35 -2
- package/src/server/presence.ts +78 -0
- package/src/server/proposals.ts +261 -0
- package/src/server/requests.ts +196 -0
- package/src/server/tools-served.ts +45 -0
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
parseThemePartType,
|
|
15
15
|
pickThemePartWinner,
|
|
16
16
|
POPUP_CHROME_CSS,
|
|
17
|
+
sharedPartCss,
|
|
17
18
|
validateConditions,
|
|
18
19
|
validateFloatSettings,
|
|
19
20
|
validateTriggers,
|
|
@@ -430,6 +431,11 @@ export async function resolveThemeParts(
|
|
|
430
431
|
* uses EmVB's own one-row probe queries, or pass a counter (e.g. an EmDash count API).
|
|
431
432
|
*/
|
|
432
433
|
pageCount?: boolean | PostCounter;
|
|
434
|
+
/**
|
|
435
|
+
* W-937: the page's languages, for a Language switcher in a header or footer. Pass
|
|
436
|
+
* `resolveEmVBPage(...)?.translations` (or your own list of published translations).
|
|
437
|
+
*/
|
|
438
|
+
translations?: readonly { locale: string; href: string; current: boolean }[];
|
|
433
439
|
} = {},
|
|
434
440
|
): Promise<ResolvedThemeParts> {
|
|
435
441
|
return resolveThemePartsWith(emdashContent, astro, ctx, options);
|
|
@@ -451,6 +457,11 @@ export async function resolveThemePartsWith(
|
|
|
451
457
|
* uses EmVB's own one-row probe queries, or pass a counter (e.g. an EmDash count API).
|
|
452
458
|
*/
|
|
453
459
|
pageCount?: boolean | PostCounter;
|
|
460
|
+
/**
|
|
461
|
+
* W-937: the page's languages, for a Language switcher in a header or footer. Pass
|
|
462
|
+
* `resolveEmVBPage(...)?.translations` (or your own list of published translations).
|
|
463
|
+
*/
|
|
464
|
+
translations?: readonly { locale: string; href: string; current: boolean }[];
|
|
454
465
|
} = {},
|
|
455
466
|
): Promise<ResolvedThemeParts> {
|
|
456
467
|
const counter =
|
|
@@ -518,6 +529,8 @@ export async function resolveThemePartsWith(
|
|
|
518
529
|
|
|
519
530
|
const byId = new Map(parts.map((part) => [part.id, part]));
|
|
520
531
|
const rendered: RenderedPage[] = [];
|
|
532
|
+
// W-971: each part's scoped sheet, to write the shared rules once in `css`.
|
|
533
|
+
const sheets = new Map<string, { css: string; scope: string; baseTypes: readonly string[] }>();
|
|
521
534
|
// W-307: bound fields in a part read site settings and URL parameters too.
|
|
522
535
|
// W-312/W-313: synced sections and Loop items the part uses count too.
|
|
523
536
|
const boundFor = (stored: StoredPart, referenced: ThemeDynamicData | undefined) =>
|
|
@@ -537,7 +550,10 @@ export async function resolveThemePartsWith(
|
|
|
537
550
|
partDynamic: ThemeDynamicData | undefined,
|
|
538
551
|
bound: Awaited<ReturnType<typeof bindingDataFor>>,
|
|
539
552
|
) => {
|
|
540
|
-
const
|
|
553
|
+
const withBound = Object.keys(bound).length > 0 ? { ...partDynamic, ...bound } : partDynamic;
|
|
554
|
+
const dynamic = options.translations
|
|
555
|
+
? { ...withBound, translations: options.translations }
|
|
556
|
+
: withBound;
|
|
541
557
|
const formDefinitions = await formsFor(
|
|
542
558
|
astro,
|
|
543
559
|
handler,
|
|
@@ -558,6 +574,8 @@ export async function resolveThemePartsWith(
|
|
|
558
574
|
options.lang ?? astro.currentLocale,
|
|
559
575
|
);
|
|
560
576
|
rendered.push(page);
|
|
577
|
+
if (page.css)
|
|
578
|
+
sheets.set(stored.id, { css: page.css, scope: stored.id, baseTypes: page.baseTypes ?? [] });
|
|
561
579
|
// W-216: a header or footer part is the page's banner or contentinfo landmark (hosts put it
|
|
562
580
|
// straight in <body> instead of their own <header>/<footer>).
|
|
563
581
|
// W-586: a part that already has its own header or footer box keeps that one as the landmark;
|
|
@@ -698,13 +716,12 @@ export async function resolveThemePartsWith(
|
|
|
698
716
|
)
|
|
699
717
|
).filter((item): item is RenderedFloat => item !== null);
|
|
700
718
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
];
|
|
719
|
+
// W-971: the parts' shared rules (scope wrapper, element base rules, print) are written once.
|
|
720
|
+
const ordered = [header, content, footer, ...popups, ...floats].flatMap((part) => {
|
|
721
|
+
const sheet = part ? sheets.get(part.id) : undefined;
|
|
722
|
+
return sheet ? [sheet] : [];
|
|
723
|
+
});
|
|
724
|
+
const cssParts = [sharedPartCss(ordered)];
|
|
708
725
|
if (popups.length > 0) cssParts.push(POPUP_CHROME_CSS);
|
|
709
726
|
if (floats.length > 0) cssParts.push(FLOAT_CHROME_CSS);
|
|
710
727
|
const css = cssParts.filter(Boolean).join("\n");
|
package/src/astro/resolve.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { PAGES_COLLECTION } from "../constants.ts";
|
|
2
|
+
import { forEachNode } from "../core/tree-ops.ts";
|
|
3
|
+
import type { Layout, LayoutNode } from "../core/schema/layout.ts";
|
|
2
4
|
import { emdashContent, type ContentPort } from "./content-port.ts";
|
|
3
5
|
import { formIdsInLayouts } from "./forms-definitions.ts";
|
|
4
6
|
import { readLayout, renderStored, type RenderedPage } from "./render.ts";
|
|
@@ -19,6 +21,18 @@ export type ResolvedEmVBPage = RenderedPage & {
|
|
|
19
21
|
canvasMode: "site-layout" | "blank";
|
|
20
22
|
/** A valid `_preview` token is serving the draft: don't cache the response. */
|
|
21
23
|
isPreview: boolean;
|
|
24
|
+
/** W-935 (D-068): the locale asked for (option or Astro's), when the site has one. */
|
|
25
|
+
locale?: string;
|
|
26
|
+
/**
|
|
27
|
+
* W-935: set when that locale has no translation of the page and EmDash served this one from
|
|
28
|
+
* its fallback chain instead. Hosts can say so, or link to the requested language's home.
|
|
29
|
+
*/
|
|
30
|
+
fallbackLocale?: string;
|
|
31
|
+
/**
|
|
32
|
+
* W-937: this page in each published language (the shown one marked current), when the site
|
|
33
|
+
* has languages. Pass it to `resolveThemeParts` for a Language switcher in the header.
|
|
34
|
+
*/
|
|
35
|
+
translations?: { locale: string; href: string; current: boolean }[];
|
|
22
36
|
};
|
|
23
37
|
|
|
24
38
|
type AstroLike = VisitorAstro & {
|
|
@@ -55,6 +69,16 @@ export async function resolveEmVBPage(
|
|
|
55
69
|
* from the host's image service (authorise the site origin in `image.remotePatterns`).
|
|
56
70
|
*/
|
|
57
71
|
getImage?: ResponsiveGetImage;
|
|
72
|
+
/**
|
|
73
|
+
* W-935: which translation to read (EmDash's row-per-locale model, D-068). Defaults to
|
|
74
|
+
* Astro's `currentLocale`; EmDash falls back along its chain when there is none.
|
|
75
|
+
*/
|
|
76
|
+
locale?: string;
|
|
77
|
+
/**
|
|
78
|
+
* W-937: where a translation of this page lives, for the Language switcher. Defaults to
|
|
79
|
+
* `/<slug>` for the default locale and `/<locale>/<slug>` for the others.
|
|
80
|
+
*/
|
|
81
|
+
translationHref?: (translation: { locale: string; slug: string }) => string;
|
|
58
82
|
} = {},
|
|
59
83
|
): Promise<ResolvedEmVBPage | null> {
|
|
60
84
|
return resolveEmVBPageWith(emdashContent, astro, options);
|
|
@@ -82,13 +106,25 @@ export async function resolveEmVBPageWith(
|
|
|
82
106
|
* from the host's image service (authorise the site origin in `image.remotePatterns`).
|
|
83
107
|
*/
|
|
84
108
|
getImage?: ResponsiveGetImage;
|
|
109
|
+
/** W-935: which translation to read; defaults to Astro's `currentLocale`. */
|
|
110
|
+
locale?: string;
|
|
111
|
+
/**
|
|
112
|
+
* W-937: where a translation of this page lives, for the Language switcher. Defaults to
|
|
113
|
+
* `/<slug>` for the default locale and `/<locale>/<slug>` for the others.
|
|
114
|
+
*/
|
|
115
|
+
translationHref?: (translation: { locale: string; slug: string }) => string;
|
|
85
116
|
} = {},
|
|
86
117
|
): Promise<ResolvedEmVBPage | null> {
|
|
87
118
|
const slug = options.slug ?? content.decodeSlug(astro.params[options.param ?? "slug"]);
|
|
88
119
|
if (!slug) return null;
|
|
120
|
+
const locale = options.locale ?? astro.currentLocale;
|
|
89
121
|
let found: Awaited<ReturnType<ContentPort["getEntry"]>>;
|
|
90
122
|
try {
|
|
91
|
-
found = await content.getEntry(
|
|
123
|
+
found = await content.getEntry(
|
|
124
|
+
options.collection ?? PAGES_COLLECTION,
|
|
125
|
+
slug,
|
|
126
|
+
locale ? { locale } : undefined,
|
|
127
|
+
);
|
|
92
128
|
} catch {
|
|
93
129
|
// No emvb_pages collection yet (EmVB not set up): not an EmVB page.
|
|
94
130
|
return null;
|
|
@@ -119,7 +155,18 @@ export async function resolveEmVBPageWith(
|
|
|
119
155
|
]),
|
|
120
156
|
)
|
|
121
157
|
: undefined;
|
|
158
|
+
const translations =
|
|
159
|
+
content.getI18nConfig?.() ||
|
|
160
|
+
(layout &&
|
|
161
|
+
[layout, ...Object.values(sectionTemplates)].some((l) => hasType(l, "language-switcher")))
|
|
162
|
+
? await translationLinks(content, {
|
|
163
|
+
collection: options.collection ?? PAGES_COLLECTION,
|
|
164
|
+
entryId: String(data["id"] ?? entry.id),
|
|
165
|
+
...(options.translationHref ? { hrefOf: options.translationHref } : {}),
|
|
166
|
+
})
|
|
167
|
+
: undefined;
|
|
122
168
|
const dynamic = {
|
|
169
|
+
...(translations ? { translations } : {}),
|
|
123
170
|
...(Object.keys(sectionTemplates).length > 0 ? { sectionTemplates } : {}),
|
|
124
171
|
...(Object.keys(loopTemplates).length > 0 ? { loopTemplates } : {}),
|
|
125
172
|
...(await bindingDataFor(
|
|
@@ -145,12 +192,52 @@ export async function resolveEmVBPageWith(
|
|
|
145
192
|
formDefinitions,
|
|
146
193
|
Object.keys(dynamic).length > 0 ? dynamic : undefined,
|
|
147
194
|
false,
|
|
148
|
-
options.lang ??
|
|
195
|
+
options.lang ?? found.fallbackLocale ?? locale,
|
|
149
196
|
),
|
|
150
197
|
entry,
|
|
151
198
|
collection: hosted ? (options.collection as string) : PAGES_COLLECTION,
|
|
152
199
|
title: typeof data["title"] === "string" ? data["title"] : "",
|
|
153
200
|
canvasMode: !hosted && data["canvas_mode"] === "blank" ? "blank" : "site-layout",
|
|
154
201
|
isPreview: Boolean(found.isPreview),
|
|
202
|
+
...(locale ? { locale } : {}),
|
|
203
|
+
...(found.fallbackLocale ? { fallbackLocale: found.fallbackLocale } : {}),
|
|
204
|
+
...(translations ? { translations } : {}),
|
|
155
205
|
};
|
|
156
206
|
}
|
|
207
|
+
|
|
208
|
+
function hasType(layout: Layout, type: string): boolean {
|
|
209
|
+
let found = false;
|
|
210
|
+
forEachNode(layout.root as LayoutNode, (node) => {
|
|
211
|
+
if (node.type === type) found = true;
|
|
212
|
+
});
|
|
213
|
+
return found;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* W-937: the page's languages for its Language switcher. Only published translations are
|
|
218
|
+
* linked (a draft never is); the page being shown is always listed and marked current.
|
|
219
|
+
*/
|
|
220
|
+
async function translationLinks(
|
|
221
|
+
content: ContentPort,
|
|
222
|
+
input: {
|
|
223
|
+
collection: string;
|
|
224
|
+
entryId: string;
|
|
225
|
+
hrefOf?: (translation: { locale: string; slug: string }) => string;
|
|
226
|
+
},
|
|
227
|
+
): Promise<{ locale: string; href: string; current: boolean }[] | undefined> {
|
|
228
|
+
if (!content.getTranslations) return undefined;
|
|
229
|
+
const found = await content.getTranslations(input.collection, input.entryId).catch(() => null);
|
|
230
|
+
if (!found || found.error) return undefined;
|
|
231
|
+
const defaultLocale = content.getI18nConfig?.()?.defaultLocale;
|
|
232
|
+
const hrefOf =
|
|
233
|
+
input.hrefOf ??
|
|
234
|
+
((t: { locale: string; slug: string }) =>
|
|
235
|
+
t.locale === defaultLocale ? `/${t.slug}` : `/${t.locale}/${t.slug}`);
|
|
236
|
+
return found.translations
|
|
237
|
+
.filter((t) => t.slug && (t.status === "published" || t.id === input.entryId))
|
|
238
|
+
.map((t) => ({
|
|
239
|
+
locale: t.locale,
|
|
240
|
+
href: hrefOf({ locale: t.locale, slug: t.slug as string }),
|
|
241
|
+
current: t.id === input.entryId,
|
|
242
|
+
}));
|
|
243
|
+
}
|
|
@@ -24,6 +24,13 @@ const KEY_TARGETS: Record<string, (current: number, count: number) => number> =
|
|
|
24
24
|
End: (_current, count) => count - 1,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* W-975: the element with the tab role: a span inside the label since 1.1; the label itself on
|
|
29
|
+
* pages rendered before.
|
|
30
|
+
*/
|
|
31
|
+
const tabOf = (label: HTMLElement): HTMLElement =>
|
|
32
|
+
label.querySelector<HTMLElement>(":scope > [role='tab']") ?? label;
|
|
33
|
+
|
|
27
34
|
/** Selects tab `index`; only keyboard navigation moves focus, never load or a radio change. */
|
|
28
35
|
function activate(root: HTMLElement, index: number, focus = false): void {
|
|
29
36
|
if (root.dataset["emvbTabsActivating"] === "1") return;
|
|
@@ -37,11 +44,13 @@ function activate(root: HTMLElement, index: number, focus = false): void {
|
|
|
37
44
|
if (!input.checked) input.checked = true;
|
|
38
45
|
for (const [i, label] of labels.entries()) {
|
|
39
46
|
const selected = i === next;
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
const tab = tabOf(label);
|
|
48
|
+
tab.setAttribute("aria-selected", String(selected));
|
|
49
|
+
tab.tabIndex = selected ? 0 : -1;
|
|
42
50
|
panels[i]?.setAttribute("aria-hidden", String(!selected));
|
|
43
51
|
}
|
|
44
|
-
const
|
|
52
|
+
const focusLabel = focus ? labels[next] : undefined;
|
|
53
|
+
const focusTarget = focusLabel ? tabOf(focusLabel) : undefined;
|
|
45
54
|
if (focusTarget && document.activeElement !== focusTarget) {
|
|
46
55
|
try {
|
|
47
56
|
focusTarget.focus({ preventScroll: true });
|
|
@@ -63,13 +72,14 @@ function selectedIndex(root: HTMLElement): number {
|
|
|
63
72
|
function linkTabs(root: HTMLElement, labels: HTMLElement[], panels: HTMLElement[]): void {
|
|
64
73
|
const prefix = root.id || "emvb-tabs";
|
|
65
74
|
for (const [i, label] of labels.entries()) {
|
|
75
|
+
const tab = tabOf(label);
|
|
66
76
|
const panel = panels[i];
|
|
67
77
|
const panelId = panel?.id || `${prefix}-panel-${i}`;
|
|
68
78
|
if (panel && !panel.id) panel.id = panelId;
|
|
69
|
-
|
|
79
|
+
tab.setAttribute("aria-controls", panelId);
|
|
70
80
|
if (panel) {
|
|
71
|
-
if (!
|
|
72
|
-
panel.setAttribute("aria-labelledby",
|
|
81
|
+
if (!tab.id) tab.id = `${prefix}-tab-${i}`;
|
|
82
|
+
panel.setAttribute("aria-labelledby", tab.id);
|
|
73
83
|
}
|
|
74
84
|
}
|
|
75
85
|
}
|
package/src/constants.ts
CHANGED
package/src/core/a11y/audit.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { flattenMotion } from "../migrate/v18.ts";
|
|
1
2
|
import { clipText } from "../limits.ts";
|
|
2
3
|
import type { DesignSystem } from "../schema/design.ts";
|
|
3
4
|
import { isParentNode, type Layout, type LayoutNode } from "../schema/layout.ts";
|
|
4
5
|
import { boxBecomesLink } from "../render/extras.ts";
|
|
5
6
|
import { ICON_ANIMATION_LIMIT_MS, iconAnimationRuns } from "../icons/animation-runs.ts";
|
|
6
7
|
import { updateNode } from "../tree-ops.ts";
|
|
8
|
+
import { DEVICES } from "../theme/popup-rules.ts";
|
|
9
|
+
import { hiddenOnEveryDevice } from "../design/devices.ts";
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* W-572: text as a screen reader says it: invisible format characters (zero-width space, word
|
|
@@ -161,13 +164,19 @@ function effectiveStyle(
|
|
|
161
164
|
const tagDefaults =
|
|
162
165
|
level === undefined
|
|
163
166
|
? undefined
|
|
164
|
-
: (design.defaults?.[`h${level}` as "h1"] as
|
|
167
|
+
: (flattenMotion(design.defaults?.[`h${level}` as "h1"]) as
|
|
168
|
+
| Record<string, unknown>
|
|
169
|
+
| undefined);
|
|
165
170
|
const classIds = new Set(node.classes ?? []);
|
|
166
|
-
|
|
171
|
+
// W-925: read by the flat motion keys (`iconAnimation`), as the renderer does.
|
|
172
|
+
const own = flattenMotion(node.style) as Record<string, unknown> | undefined;
|
|
173
|
+
if (classIds.size === 0 && !tagDefaults) return own;
|
|
167
174
|
const fromClasses = (design.classes ?? [])
|
|
168
175
|
.filter((c) => classIds.has(c.id))
|
|
169
|
-
.reduce<Record<string, unknown>>((acc, c) => Object.assign(acc, c.style), {
|
|
170
|
-
|
|
176
|
+
.reduce<Record<string, unknown>>((acc, c) => Object.assign(acc, flattenMotion(c.style)), {
|
|
177
|
+
...tagDefaults,
|
|
178
|
+
});
|
|
179
|
+
return { ...fromClasses, ...own };
|
|
171
180
|
}
|
|
172
181
|
|
|
173
182
|
/** Each device's style with the node's classes under the node's own (W-882). */
|
|
@@ -180,7 +189,7 @@ function deviceStyles(node: LayoutNode, design: DesignSystem): Record<string, un
|
|
|
180
189
|
];
|
|
181
190
|
for (const devices of layers) {
|
|
182
191
|
for (const [key, st] of Object.entries(devices ?? {})) {
|
|
183
|
-
merged[key] = { ...merged[key], ...(st as Record<string, unknown>) };
|
|
192
|
+
merged[key] = { ...merged[key], ...(flattenMotion(st) as Record<string, unknown>) };
|
|
184
193
|
}
|
|
185
194
|
}
|
|
186
195
|
return Object.values(merged);
|
|
@@ -210,7 +219,12 @@ function largeText(node: LayoutNode, design: DesignSystem): boolean {
|
|
|
210
219
|
* its text isn't known here.
|
|
211
220
|
*/
|
|
212
221
|
function boxHasName(node: LayoutNode): boolean {
|
|
213
|
-
if (
|
|
222
|
+
if (
|
|
223
|
+
node.bind ||
|
|
224
|
+
node.type.startsWith("post-") ||
|
|
225
|
+
node.type === "loop" ||
|
|
226
|
+
node.type === "part-ref"
|
|
227
|
+
)
|
|
214
228
|
return true;
|
|
215
229
|
const props = node.props as Record<string, unknown>;
|
|
216
230
|
const decorative = props["decorative"] === true;
|
|
@@ -228,9 +242,9 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
228
242
|
issues.push({ ...issue, id: `${issue.rule}:${issue.nodeId}` });
|
|
229
243
|
let lastLevel = 0;
|
|
230
244
|
// W-444: H1s counted per device, so a desktop H1 and a mobile H1 that swap places aren't two.
|
|
231
|
-
|
|
232
|
-
let h1s =
|
|
233
|
-
let shownOn =
|
|
245
|
+
// W-956: Laptop counts as its own device.
|
|
246
|
+
let h1s = DEVICES.map(() => 0);
|
|
247
|
+
let shownOn = DEVICES.map(() => true);
|
|
234
248
|
// W-446: aria-hidden on a box hides everything inside it from screen readers, links included.
|
|
235
249
|
let ariaHiddenAbove = false;
|
|
236
250
|
// W-312 variants are alternatives: B is judged as if it stood where A does, so a page whose
|
|
@@ -239,13 +253,10 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
239
253
|
const afterA = new Map<string, [number[], number]>();
|
|
240
254
|
let fade = 1;
|
|
241
255
|
// W-445: per device, like H1s, so a desktop menu and a mobile menu may share a name.
|
|
242
|
-
const menuNames =
|
|
256
|
+
const menuNames = DEVICES.map(() => new Set<string>());
|
|
243
257
|
const walk = (node: LayoutNode, bg: string | undefined, color: string | undefined): void => {
|
|
244
258
|
// W-413: an element hidden on every device (and what's inside it) is never shown or read.
|
|
245
|
-
if (
|
|
246
|
-
node !== layout.root &&
|
|
247
|
-
(["desktop", "tablet", "mobile"] as const).every((d) => node.hiddenOn?.includes(d))
|
|
248
|
-
) {
|
|
259
|
+
if (node !== layout.root && hiddenOnEveryDevice(node)) {
|
|
249
260
|
return;
|
|
250
261
|
}
|
|
251
262
|
const variant = node.variant;
|
|
@@ -348,6 +359,26 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
|
|
|
348
359
|
"This icon animates for more than 5 seconds and visitors can't pause it. Shorten the duration, or keep it only if the motion is essential.",
|
|
349
360
|
});
|
|
350
361
|
}
|
|
362
|
+
// W-938: an element's loop is held to the same rule: it stops after about 5 s unless it loops
|
|
363
|
+
// forever, so only Loop forever or a single run longer than 5 s is flagged.
|
|
364
|
+
const loopsTooLong = [effectiveStyle(node, design), ...deviceStyles(node, design)].some(
|
|
365
|
+
(st) => {
|
|
366
|
+
const loop = (st as { loopMotion?: { duration?: unknown; loop?: unknown } } | undefined)
|
|
367
|
+
?.loopMotion;
|
|
368
|
+
if (!loop || !("duration" in loop)) return false;
|
|
369
|
+
if (loop.loop === true) return true;
|
|
370
|
+
return typeof loop.duration === "number" && loop.duration > ICON_ANIMATION_LIMIT_MS;
|
|
371
|
+
},
|
|
372
|
+
);
|
|
373
|
+
if (loopsTooLong) {
|
|
374
|
+
add({
|
|
375
|
+
nodeId: node.id,
|
|
376
|
+
rule: "motion",
|
|
377
|
+
severity: "warning",
|
|
378
|
+
message:
|
|
379
|
+
"This element's loop keeps moving for more than 5 seconds and visitors can't pause it. Turn off Loop forever, or keep it only if the motion is essential.",
|
|
380
|
+
});
|
|
381
|
+
}
|
|
351
382
|
// W-403: with extra sizes but no Width, the main image is left out of srcset, so wide screens
|
|
352
383
|
// can only get the listed copies.
|
|
353
384
|
if (node.type === "image" && Array.isArray(props["sources"]) && props["sources"].length > 0) {
|
package/src/core/arrange.ts
CHANGED
|
@@ -336,7 +336,11 @@ export const wrapInThemeSection = (
|
|
|
336
336
|
partId: string,
|
|
337
337
|
random: () => number = Math.random,
|
|
338
338
|
): Arranged =>
|
|
339
|
-
wrapWith(layout, id, {
|
|
339
|
+
wrapWith(layout, id, {
|
|
340
|
+
id: newNodeId(random),
|
|
341
|
+
type: "part-ref",
|
|
342
|
+
props: { partId },
|
|
343
|
+
} as LayoutNode);
|
|
340
344
|
|
|
341
345
|
function wrapWith(layout: Layout, id: string, shell: LayoutNode): Arranged {
|
|
342
346
|
const found = locate(layout, id);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* D-070 (GHSA-mrhx-c7xc-m3w5): zod before 4.6.6 parses every element of an array, collecting an
|
|
5
|
+
* issue for each bad one, before `.max()` is checked. A 10 MB request of bad items held about 2 GB.
|
|
6
|
+
* EmDash 1.4 pins zod 4.5.4, and it parses EmVB's route and MCP tool inputs before any EmVB code
|
|
7
|
+
* runs, so every array in such an input checks its length first and stops with a single issue.
|
|
8
|
+
* JSON Schema output (MCP `tools/list`) is the plain array, with minItems/maxItems.
|
|
9
|
+
*/
|
|
10
|
+
export function boundedArray<T extends z.ZodType>(item: T, max: number, min = 0) {
|
|
11
|
+
return z
|
|
12
|
+
.unknown()
|
|
13
|
+
.check((ctx) => {
|
|
14
|
+
const value = ctx.value;
|
|
15
|
+
if (!Array.isArray(value)) return;
|
|
16
|
+
if (value.length > max || value.length < min) {
|
|
17
|
+
ctx.issues.push({
|
|
18
|
+
code: value.length > max ? "too_big" : "too_small",
|
|
19
|
+
origin: "array",
|
|
20
|
+
...(value.length > max ? { maximum: max } : { minimum: min }),
|
|
21
|
+
inclusive: true,
|
|
22
|
+
input: value,
|
|
23
|
+
message:
|
|
24
|
+
value.length > max
|
|
25
|
+
? `Too many items: at most ${max}.`
|
|
26
|
+
: `Too few items: at least ${min}.`,
|
|
27
|
+
} as never);
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
.pipe(z.array(item).min(min).max(max));
|
|
31
|
+
}
|
package/src/core/clipboard.ts
CHANGED
|
@@ -203,6 +203,7 @@ function refsInStyle(style: StyleProps | undefined): Ref[] {
|
|
|
203
203
|
const refsOf = (owner: CopiedStyle): Ref[] => [
|
|
204
204
|
...refsInStyle(owner.style),
|
|
205
205
|
...STYLE_STATES.flatMap((state) => refsInStyle(owner.states?.[state])),
|
|
206
|
+
...refsInStyle(owner.devices?.laptop),
|
|
206
207
|
...refsInStyle(owner.devices?.tablet),
|
|
207
208
|
...refsInStyle(owner.devices?.mobile),
|
|
208
209
|
// W-643: a container-query override (W-346) can use a variable too.
|
|
@@ -377,6 +378,14 @@ function withoutIconKeys(style: object | undefined): object | undefined {
|
|
|
377
378
|
removed = true;
|
|
378
379
|
}
|
|
379
380
|
}
|
|
381
|
+
// W-925: the Icon animation is `motion.icon` since schema 18.
|
|
382
|
+
const motion = next["motion"];
|
|
383
|
+
if (isRecord(motion) && "icon" in motion) {
|
|
384
|
+
const { icon: _icon, ...rest } = motion;
|
|
385
|
+
if (Object.keys(rest).length > 0) next["motion"] = rest;
|
|
386
|
+
else delete next["motion"];
|
|
387
|
+
removed = true;
|
|
388
|
+
}
|
|
380
389
|
if (!removed) return style;
|
|
381
390
|
return Object.keys(next).length > 0 ? next : undefined;
|
|
382
391
|
}
|