@perkyzz/emvb 0.8.0 → 1.0.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 +3 -3
- package/package.json +4 -4
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/editor/A11yCopilot.tsx +1 -1
- package/src/admin/editor/Editor.tsx +325 -239
- package/src/admin/editor/FieldPreview.tsx +164 -0
- package/src/admin/editor/Timeline.tsx +2 -1
- package/src/admin/editor/TopBar.tsx +36 -3
- package/src/admin/editor/canvas/CanvasFrame.tsx +2 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +17 -9
- package/src/admin/editor/canvas/canvas-scale.ts +2 -2
- 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 +26 -4
- package/src/admin/editor/editor-chrome.tsx +3 -3
- package/src/admin/editor/editor-commands.ts +8 -3
- package/src/admin/editor/editor-css.ts +3 -0
- 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/host.ts +6 -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 +53 -15
- 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 +76 -20
- 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 +104 -9
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +14 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +27 -16
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
- package/src/admin/editor/panels/settings/MediaPicker.tsx +5 -5
- 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 +113 -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 +55 -2
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +51 -10
- package/src/admin/editor/panels/style-target.ts +9 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/store.ts +6 -2
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +4 -4
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +15 -6
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/index.tsx +5 -1
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/media-api.ts +27 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +11 -28
- package/src/admin/pages/CollectionsPage.tsx +215 -0
- package/src/admin/pages/CreateDialog.tsx +15 -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 +15 -1
- package/src/admin/pages/ThemePartList.tsx +15 -1
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/setup/host-collections.ts +100 -0
- package/src/admin/ui.ts +39 -2
- package/src/admin/widgets/CanvasField.tsx +202 -0
- package/src/admin/widgets/convert-body.ts +54 -0
- package/src/admin/widgets/field-fetcher.ts +79 -0
- package/src/astro/content-port.ts +14 -1
- package/src/astro/index.ts +2 -0
- package/src/astro/page-count.ts +77 -0
- package/src/astro/resolve-theme.ts +58 -3
- package/src/astro/resolve.ts +128 -5
- package/src/astro/responsive-images.ts +99 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +44 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/canvas-collections.ts +20 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +285 -0
- package/src/core/css/generate.ts +89 -20
- package/src/core/css/trace.ts +18 -9
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +4 -5
- package/src/core/design/devices.ts +13 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +17 -4
- package/src/core/elements/dynamic-elements.ts +19 -4
- package/src/core/elements/index.ts +73 -9
- 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 +1 -1
- package/src/core/import/elementor/atomic.ts +1595 -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 +949 -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 +409 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +84 -0
- package/src/core/json-schema.ts +107 -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 +5 -5
- package/src/core/portable-text.ts +127 -0
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +140 -20
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/pagination.ts +20 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +125 -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 +2 -1
- package/src/core/schema/layout.ts +87 -14
- package/src/core/schema/style.ts +251 -114
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +1 -0
- package/src/core/theme/pagination.ts +9 -0
- package/src/core/theme/popup-rules.ts +17 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +35 -1
- 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 -9
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +21 -2
- package/src/server/hooks.ts +81 -0
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +53 -5
- 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
package/src/core/render/index.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { renderableDesign, renderableDynamic, renderableLayout } from "../contract.ts";
|
|
2
|
+
import { markColors } from "../text-marks.ts";
|
|
3
|
+
import type { TextMark } from "../schema/layout.ts";
|
|
4
|
+
import { LIST_MARKERS } from "../css-keywords.ts";
|
|
1
5
|
import { MAX_NODES } from "../limits.ts";
|
|
2
6
|
import { loneAbTests, variantShows } from "../audience/variants.ts";
|
|
3
7
|
import { audienceShows, audienceSummary } from "../audience/rules.ts";
|
|
@@ -17,6 +21,7 @@ import {
|
|
|
17
21
|
isParentNode,
|
|
18
22
|
isSectionNode,
|
|
19
23
|
isTabsNode,
|
|
24
|
+
cssTypeName,
|
|
20
25
|
type Layout,
|
|
21
26
|
type LayoutNode,
|
|
22
27
|
type PaginationNode,
|
|
@@ -32,9 +37,10 @@ import {
|
|
|
32
37
|
} from "../sanitize/css.ts";
|
|
33
38
|
import { STYLE_STATES } from "../schema/state-names.ts";
|
|
34
39
|
import { resolveEmbedUrl } from "../sanitize/embed-url.ts";
|
|
40
|
+
import { sanitizeHref } from "../sanitize/href.ts";
|
|
35
41
|
import { resolvePostForRender, type ThemeDynamicData } from "../theme/dynamic.ts";
|
|
36
42
|
import type { FormDefinitions } from "../forms/definition.ts";
|
|
37
|
-
import type
|
|
43
|
+
import { DEVICES, type Device } from "../theme/popup-rules.ts";
|
|
38
44
|
import type { RenderContext, RenderMode } from "./context.ts";
|
|
39
45
|
import { isDynamicPostNode, renderDynamicPost } from "./dynamic-post.ts";
|
|
40
46
|
import { renderForm, withFieldOptions } from "./form.ts";
|
|
@@ -43,6 +49,11 @@ import { renderPagination } from "./pagination.ts";
|
|
|
43
49
|
import { renderSection } from "./section.ts";
|
|
44
50
|
import { renderTabs } from "./tabs.ts";
|
|
45
51
|
import { serialize, type VNode } from "./vnode.ts";
|
|
52
|
+
import {
|
|
53
|
+
isExtensionType,
|
|
54
|
+
renderExtensionNode,
|
|
55
|
+
EXTENSION_PLACEHOLDER_CSS,
|
|
56
|
+
} from "../extensions/index.ts";
|
|
46
57
|
import { classStylesInListOrder, resolveCascade } from "../design/cascade.ts";
|
|
47
58
|
import { applyBindings, hasBindings, type BindingData } from "../data/bindings.ts";
|
|
48
59
|
import {
|
|
@@ -85,6 +96,8 @@ function focalPercent(value: unknown, fallback: number): number | undefined {
|
|
|
85
96
|
return value;
|
|
86
97
|
}
|
|
87
98
|
|
|
99
|
+
const LIST_MARKER_SET: ReadonlySet<string> = new Set(LIST_MARKERS);
|
|
100
|
+
|
|
88
101
|
/** `object-position` only when both axes are whole percentages. A string here would break the sheet. */
|
|
89
102
|
function objectPosition(x: unknown, y: unknown): string | undefined {
|
|
90
103
|
if (x === undefined && y === undefined) return undefined;
|
|
@@ -194,8 +207,8 @@ function renameIds(vnode: VNode, base: string, next: string): VNode {
|
|
|
194
207
|
const MAX_SECTION_ELEMENTS = 20 * MAX_NODES;
|
|
195
208
|
|
|
196
209
|
export function renderPage(
|
|
197
|
-
|
|
198
|
-
|
|
210
|
+
storedLayout: Layout,
|
|
211
|
+
storedDesign: DesignSystem,
|
|
199
212
|
opts: {
|
|
200
213
|
mode?: RenderMode;
|
|
201
214
|
formDefinitions?: FormDefinitions;
|
|
@@ -203,7 +216,7 @@ export function renderPage(
|
|
|
203
216
|
/** Public renders: wrap the markup and scope the CSS to it, so sheets can't override each other (W-112). */
|
|
204
217
|
scope?: string;
|
|
205
218
|
/** Editor canvas: device rules follow this device, not the frame width (W-116). */
|
|
206
|
-
previewDevice?:
|
|
219
|
+
previewDevice?: Device;
|
|
207
220
|
/**
|
|
208
221
|
* Theme parts (header, footer, popup, float) render apart from the page, so a synced section
|
|
209
222
|
* on both gave form fields, honeypots and tab groups the same ids: a label in a popup focused
|
|
@@ -215,13 +228,18 @@ export function renderPage(
|
|
|
215
228
|
} = {},
|
|
216
229
|
): RenderResult {
|
|
217
230
|
const mode = opts.mode ?? "public";
|
|
218
|
-
|
|
231
|
+
// W-925: the renderer reads the 0.x flat style shape and known keys only (D-065), so keys a
|
|
232
|
+
// newer 1.x wrote are never rendered and the output matches 0.x byte for byte.
|
|
233
|
+
const layout = renderableLayout(storedLayout);
|
|
234
|
+
const design = renderableDesign(storedDesign);
|
|
235
|
+
const baseDynamic = renderableDynamic(opts.dynamic);
|
|
219
236
|
const warnings: RenderWarning[] = [];
|
|
220
237
|
const usedTypes = new Set<string>();
|
|
221
238
|
const localRules: {
|
|
222
239
|
id: string;
|
|
223
240
|
declarations: Declaration[];
|
|
224
241
|
states: StateDeclarations;
|
|
242
|
+
laptop?: Declaration[];
|
|
225
243
|
tablet?: Declaration[];
|
|
226
244
|
mobile?: Declaration[];
|
|
227
245
|
hiddenOn?: LayoutNode["hiddenOn"];
|
|
@@ -248,6 +266,8 @@ export function renderPage(
|
|
|
248
266
|
const tocNodes: { node: LayoutNode; vnode: VNode }[] = [];
|
|
249
267
|
const knownVariables = new Set(design.variables.colors.map((c) => c.id));
|
|
250
268
|
let backgroundVideo = false;
|
|
269
|
+
/** W-952: any List drawn as numbered steps, so their rules are sent. */
|
|
270
|
+
let listSteps = false;
|
|
251
271
|
|
|
252
272
|
const domIds = new Map<string, number>();
|
|
253
273
|
const idSuffix = opts.partIds && opts.scope ? `-t${originHash(opts.scope)}` : "";
|
|
@@ -291,7 +311,7 @@ export function renderPage(
|
|
|
291
311
|
nodeId: string,
|
|
292
312
|
ruleId: string | undefined,
|
|
293
313
|
): Record<string, string> => {
|
|
294
|
-
const classes = [...(isRoot ? ["emvb-root"] : []), `emvb-${node.type}`];
|
|
314
|
+
const classes = [...(isRoot ? ["emvb-root"] : []), `emvb-${cssTypeName(node.type)}`];
|
|
295
315
|
for (const classId of node.classes ?? []) {
|
|
296
316
|
const name = styleClassName(classId);
|
|
297
317
|
if (name) classes.push(name);
|
|
@@ -327,12 +347,15 @@ export function renderPage(
|
|
|
327
347
|
const { declarations, rejected } = styleDeclarations(own);
|
|
328
348
|
// W-210: a device that sets one background layer keeps the layers it inherits.
|
|
329
349
|
const base = { ...classLayers, ...own };
|
|
350
|
+
// W-956: Laptop between Desktop and Tablet; each narrower device inherits the wider ones.
|
|
351
|
+
const laptopStyle = node.devices?.laptop;
|
|
352
|
+
const laptop = styleDeclarations(withInheritedLayers(laptopStyle, base));
|
|
330
353
|
const tabletStyle = node.devices?.tablet;
|
|
331
|
-
const tablet = styleDeclarations(withInheritedLayers(tabletStyle, base));
|
|
354
|
+
const tablet = styleDeclarations(withInheritedLayers(tabletStyle, { ...base, ...laptopStyle }));
|
|
332
355
|
const mobile = styleDeclarations(
|
|
333
|
-
withInheritedLayers(node.devices?.mobile, { ...base, ...tabletStyle }),
|
|
356
|
+
withInheritedLayers(node.devices?.mobile, { ...base, ...laptopStyle, ...tabletStyle }),
|
|
334
357
|
);
|
|
335
|
-
for (const key of [...rejected, ...tablet.rejected, ...mobile.rejected]) {
|
|
358
|
+
for (const key of [...rejected, ...laptop.rejected, ...tablet.rejected, ...mobile.rejected]) {
|
|
336
359
|
warnings.push({ nodeId, code: "rejected-style", detail: key });
|
|
337
360
|
}
|
|
338
361
|
if (node.type === "spacer") {
|
|
@@ -371,6 +394,20 @@ export function renderPage(
|
|
|
371
394
|
declarations.push({ property: "object-fit", value: "cover" });
|
|
372
395
|
}
|
|
373
396
|
}
|
|
397
|
+
if (node.type === "heading" || node.type === "text") {
|
|
398
|
+
// W-950: each mark colour as a variable its words read.
|
|
399
|
+
markColors((node.props as { marks?: TextMark[] }).marks).forEach((color, n) =>
|
|
400
|
+
declarations.push({ property: `--emvb-mark-${n}`, value: color }),
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
if (node.type === "list") {
|
|
404
|
+
// W-952: the marker style; items inherit it. Steps draw their own numbers.
|
|
405
|
+
const marker = (node.props as { marker?: unknown }).marker;
|
|
406
|
+
if (marker === "steps") listSteps = true;
|
|
407
|
+
else if (typeof marker === "string" && LIST_MARKER_SET.has(marker)) {
|
|
408
|
+
declarations.push({ property: "list-style-type", value: marker });
|
|
409
|
+
}
|
|
410
|
+
}
|
|
374
411
|
if (node.type === "button") {
|
|
375
412
|
const gap = (node.props as { iconGap?: unknown }).iconGap;
|
|
376
413
|
if (typeof gap === "number" && Number.isInteger(gap) && gap >= 0 && gap <= 64) {
|
|
@@ -396,10 +433,14 @@ export function renderPage(
|
|
|
396
433
|
}
|
|
397
434
|
const grid = gridOf.get(node.id);
|
|
398
435
|
if (grid) {
|
|
399
|
-
|
|
400
|
-
const
|
|
436
|
+
// A grid's laptop columns are its desktop ones (column counts have no laptop value).
|
|
437
|
+
const [desktopCount, tabletCount, mobileCount] = gridColumnCounts(grid);
|
|
438
|
+
const counts = [desktopCount, desktopCount, tabletCount, mobileCount];
|
|
439
|
+
const laptopPlacement = { ...node.style, ...node.devices?.laptop };
|
|
440
|
+
const tabletPlacement = { ...laptopPlacement, ...node.devices?.tablet };
|
|
401
441
|
const levels = [
|
|
402
442
|
node.style ?? {},
|
|
443
|
+
laptopPlacement,
|
|
403
444
|
tabletPlacement,
|
|
404
445
|
{ ...tabletPlacement, ...node.devices?.mobile },
|
|
405
446
|
];
|
|
@@ -410,8 +451,15 @@ export function renderPage(
|
|
|
410
451
|
const at = (i: number) => ({ property: "grid-column", value: fitted[i]?.value ?? "auto" });
|
|
411
452
|
const kept = declarations.filter((d) => d.property !== "grid-column");
|
|
412
453
|
declarations.splice(0, declarations.length, ...kept, at(0));
|
|
413
|
-
|
|
414
|
-
|
|
454
|
+
// On laptop only when it differs from desktop or the laptop style places it itself
|
|
455
|
+
// (released pages, which have no laptop styles, keep their CSS).
|
|
456
|
+
const ownLaptop = laptop.declarations.some((d) => d.property === "grid-column");
|
|
457
|
+
if (ownLaptop || fitted[1]?.value !== fitted[0]?.value) {
|
|
458
|
+
const others = laptop.declarations.filter((d) => d.property !== "grid-column");
|
|
459
|
+
laptop.declarations.splice(0, laptop.declarations.length, ...others, at(1));
|
|
460
|
+
}
|
|
461
|
+
tablet.declarations.push(at(2));
|
|
462
|
+
mobile.declarations.push(at(3));
|
|
415
463
|
}
|
|
416
464
|
}
|
|
417
465
|
const states = stateDeclarations(node.states);
|
|
@@ -426,6 +474,7 @@ export function renderPage(
|
|
|
426
474
|
// W-567: the root is the page itself; hiding it on a device blanked the whole page there.
|
|
427
475
|
const hiddenOn = isRoot ? undefined : node.hiddenOn;
|
|
428
476
|
const responsive =
|
|
477
|
+
laptop.declarations.length > 0 ||
|
|
429
478
|
tablet.declarations.length > 0 ||
|
|
430
479
|
mobile.declarations.length > 0 ||
|
|
431
480
|
(hiddenOn?.length ?? 0) > 0;
|
|
@@ -443,6 +492,7 @@ export function renderPage(
|
|
|
443
492
|
id: ruleId,
|
|
444
493
|
declarations,
|
|
445
494
|
states: states.states,
|
|
495
|
+
laptop: laptop.declarations,
|
|
446
496
|
tablet: tablet.declarations,
|
|
447
497
|
mobile: mobile.declarations,
|
|
448
498
|
hiddenOn,
|
|
@@ -490,6 +540,15 @@ export function renderPage(
|
|
|
490
540
|
const nodeId = id ?? "(invalid id)";
|
|
491
541
|
const type: string = node.type;
|
|
492
542
|
if (!Object.hasOwn(ELEMENTS, type)) {
|
|
543
|
+
// W-927: extension elements render via the Extensions API, or a placeholder when missing.
|
|
544
|
+
if (isExtensionType(type)) {
|
|
545
|
+
usedTypes.add("ext");
|
|
546
|
+
return renderExtensionNode(node, mode === "editor" ? "editor" : "public", (nodes) =>
|
|
547
|
+
nodes
|
|
548
|
+
.map((child) => visit(child, false, dynamic))
|
|
549
|
+
.filter((child): child is VNode => child !== undefined),
|
|
550
|
+
);
|
|
551
|
+
}
|
|
493
552
|
warnings.push({ nodeId, code: "unknown-type", detail: type });
|
|
494
553
|
if (mode === "public") return undefined;
|
|
495
554
|
return {
|
|
@@ -532,6 +591,12 @@ export function renderPage(
|
|
|
532
591
|
);
|
|
533
592
|
}
|
|
534
593
|
if (isTabsNode(node)) return finish(node, renderTabs(node, id, attrs, ctx, dynamic));
|
|
594
|
+
if (node.type === "language-switcher") {
|
|
595
|
+
const links = languageLinks(dynamic?.translations, mode);
|
|
596
|
+
// W-937: a page in one language has nothing to switch to; the public page shows nothing.
|
|
597
|
+
if (!links) return undefined;
|
|
598
|
+
return finish(node, { ...def.build(node as never, attrs, []), children: [links] });
|
|
599
|
+
}
|
|
535
600
|
if (node.type === "toc") {
|
|
536
601
|
const built = def.build(node as never, attrs, []);
|
|
537
602
|
const vnode = { ...built, children: [] as (VNode | string)[] };
|
|
@@ -541,9 +606,7 @@ export function renderPage(
|
|
|
541
606
|
if (node.type === "heading" && pageHeadings?.has(stored) && attrs.id) {
|
|
542
607
|
const text = String((node.props as { text?: unknown }).text ?? "").trim();
|
|
543
608
|
// W-409: a heading hidden on every device has nothing to jump to.
|
|
544
|
-
const hiddenEverywhere =
|
|
545
|
-
node.hiddenOn?.includes(device),
|
|
546
|
-
);
|
|
609
|
+
const hiddenEverywhere = DEVICES.every((device) => node.hiddenOn?.includes(device));
|
|
547
610
|
if (text && !hiddenEverywhere && !renderedHeadings.some((h) => h.id === attrs.id)) {
|
|
548
611
|
// W-793: a heading hidden on some devices (itself or an ancestor) hides its contents
|
|
549
612
|
// entry there too, or the entry was a dead link on those devices.
|
|
@@ -623,6 +686,8 @@ export function renderPage(
|
|
|
623
686
|
}
|
|
624
687
|
}
|
|
625
688
|
const baseCss = new Map(Object.entries(ELEMENTS).map(([type, def]) => [type, def.baseCss]));
|
|
689
|
+
// W-927: placeholder + wrapper styles ship with every page that may hold an extension node.
|
|
690
|
+
baseCss.set("ext", EXTENSION_PLACEHOLDER_CSS);
|
|
626
691
|
const css = generateCss({
|
|
627
692
|
design,
|
|
628
693
|
usedTypes,
|
|
@@ -630,6 +695,7 @@ export function renderPage(
|
|
|
630
695
|
localRules,
|
|
631
696
|
previewStates: mode === "editor",
|
|
632
697
|
backgroundVideo,
|
|
698
|
+
listSteps,
|
|
633
699
|
...(mode === "editor" && opts.previewDevice ? { previewDevice: opts.previewDevice } : {}),
|
|
634
700
|
});
|
|
635
701
|
const scope = opts.scope === undefined ? undefined : cssScopeToken(opts.scope);
|
|
@@ -658,9 +724,9 @@ function treeHasType(node: LayoutNode, type: string): boolean {
|
|
|
658
724
|
* inside an element hidden on every device, which never show, so a contents link has nothing
|
|
659
725
|
* to jump to (W-409 covered only the heading's own visibility).
|
|
660
726
|
*/
|
|
661
|
-
function headingAnchors(root: LayoutNode): { node: LayoutNode; hiddenOn:
|
|
662
|
-
const out: { node: LayoutNode; hiddenOn:
|
|
663
|
-
const walk = (node: LayoutNode, inherited:
|
|
727
|
+
function headingAnchors(root: LayoutNode): { node: LayoutNode; hiddenOn: Device[] }[] {
|
|
728
|
+
const out: { node: LayoutNode; hiddenOn: Device[] }[] = [];
|
|
729
|
+
const walk = (node: LayoutNode, inherited: Device[]) => {
|
|
664
730
|
if (node !== root && HIDDEN_DEVICES.every((device) => node.hiddenOn?.includes(device))) return;
|
|
665
731
|
const own = node === root ? [] : (node.hiddenOn ?? []);
|
|
666
732
|
const hiddenOn = HIDDEN_DEVICES.filter((d) => inherited.includes(d) || own.includes(d));
|
|
@@ -672,7 +738,7 @@ function headingAnchors(root: LayoutNode): { node: LayoutNode; hiddenOn: PopupDe
|
|
|
672
738
|
return out;
|
|
673
739
|
}
|
|
674
740
|
|
|
675
|
-
const HIDDEN_DEVICES =
|
|
741
|
+
const HIDDEN_DEVICES = DEVICES;
|
|
676
742
|
|
|
677
743
|
/** Columns set by custom tracks or a count, or undefined when neither is set. */
|
|
678
744
|
const columnCount = (tracks: unknown, columns: unknown): number | undefined =>
|
|
@@ -755,3 +821,57 @@ function tocChildren(
|
|
|
755
821
|
});
|
|
756
822
|
return children;
|
|
757
823
|
}
|
|
824
|
+
|
|
825
|
+
/** A language's own name for itself ("Français"), or its code when the runtime doesn't know it. */
|
|
826
|
+
function autonym(locale: string): string {
|
|
827
|
+
try {
|
|
828
|
+
const name = new Intl.DisplayNames([locale], { type: "language" }).of(locale);
|
|
829
|
+
return name ? name.charAt(0).toLocaleUpperCase(locale) + name.slice(1) : locale;
|
|
830
|
+
} catch {
|
|
831
|
+
return locale;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* W-937: the Language switcher's list. Hosts pass only published translations (a draft is never
|
|
837
|
+
* linked); each link carries hreflang and lang, and the page being shown is aria-current. The
|
|
838
|
+
* editor shows a note when the page has no other language yet.
|
|
839
|
+
*/
|
|
840
|
+
function languageLinks(
|
|
841
|
+
translations: readonly { locale: string; href: string; current: boolean }[] | undefined,
|
|
842
|
+
mode: RenderMode,
|
|
843
|
+
): VNode | undefined {
|
|
844
|
+
const list = (translations ?? []).filter(
|
|
845
|
+
(t) => typeof t.locale === "string" && t.locale && sanitizeHref(t.href) !== undefined,
|
|
846
|
+
);
|
|
847
|
+
if (list.length < 2) {
|
|
848
|
+
if (mode !== "editor") return undefined;
|
|
849
|
+
return {
|
|
850
|
+
tag: "p",
|
|
851
|
+
attrs: {},
|
|
852
|
+
children: [
|
|
853
|
+
"Links to this page's other languages show here once it has a published translation.",
|
|
854
|
+
],
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
return {
|
|
858
|
+
tag: "ul",
|
|
859
|
+
attrs: {},
|
|
860
|
+
children: list.map((t) => ({
|
|
861
|
+
tag: "li",
|
|
862
|
+
attrs: {},
|
|
863
|
+
children: [
|
|
864
|
+
{
|
|
865
|
+
tag: "a",
|
|
866
|
+
attrs: {
|
|
867
|
+
href: sanitizeHref(t.href) as string,
|
|
868
|
+
hreflang: t.locale,
|
|
869
|
+
lang: t.locale,
|
|
870
|
+
...(t.current ? { "aria-current": "page" } : {}),
|
|
871
|
+
},
|
|
872
|
+
children: [autonym(t.locale)],
|
|
873
|
+
},
|
|
874
|
+
],
|
|
875
|
+
})),
|
|
876
|
+
};
|
|
877
|
+
}
|
package/src/core/render/loop.ts
CHANGED
|
@@ -63,7 +63,7 @@ export function renderLoop(
|
|
|
63
63
|
dynamic: ThemeDynamicData | undefined,
|
|
64
64
|
): VNode | undefined {
|
|
65
65
|
const posts = entriesFor(node, dynamic, ctx.mode);
|
|
66
|
-
const itemPartId = node.props.
|
|
66
|
+
const itemPartId = node.props.partId?.trim() ?? "";
|
|
67
67
|
const loopStack = dynamic?.loopStack ?? [];
|
|
68
68
|
// W-654: a loop item part holding a Loop that uses the same part (or one that leads back to it)
|
|
69
69
|
// recursed until the stack overflowed and the page failed to render.
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { PaginationNode } from "../schema/layout.ts";
|
|
2
2
|
import type { ThemeDynamicData } from "../theme/dynamic.ts";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
lastPagePath,
|
|
5
|
+
pageCountText,
|
|
6
|
+
paginationItems,
|
|
7
|
+
type ArchivePagination,
|
|
8
|
+
} from "../theme/pagination.ts";
|
|
4
9
|
import type { VNode } from "./vnode.ts";
|
|
5
10
|
|
|
6
11
|
/** What the editor canvas shows: page 2 of several, links going nowhere (W-222). */
|
|
@@ -101,6 +106,20 @@ export function renderPagination(
|
|
|
101
106
|
};
|
|
102
107
|
}
|
|
103
108
|
});
|
|
109
|
+
// W-916: the editor sample has no total, so its Last link goes nowhere like the others.
|
|
110
|
+
const last = editor ? "#" : lastPagePath(data);
|
|
111
|
+
if (node.props.showLast && last) {
|
|
112
|
+
const text = label(node.props.lastText, "Last");
|
|
113
|
+
children.push({
|
|
114
|
+
tag: "a",
|
|
115
|
+
attrs: {
|
|
116
|
+
class: "emvb-pagination-last",
|
|
117
|
+
href: last,
|
|
118
|
+
...nameIfSymbols(text, label(node.props.lastLabel, "Last page")),
|
|
119
|
+
},
|
|
120
|
+
children: [text],
|
|
121
|
+
});
|
|
122
|
+
}
|
|
104
123
|
if (node.props.showCount) {
|
|
105
124
|
// W-309: "Page N of M", or "Page N" while the host has no total.
|
|
106
125
|
children.unshift({
|
|
@@ -38,16 +38,16 @@ export function renderSection(
|
|
|
38
38
|
const template =
|
|
39
39
|
partId && dynamic?.sectionTemplates ? dynamic.sectionTemplates[partId] : undefined;
|
|
40
40
|
if (!partId) {
|
|
41
|
-
return ELEMENTS.
|
|
41
|
+
return ELEMENTS["part-ref"].build(node as never, attrs, ctx.children(node.children, dynamic));
|
|
42
42
|
}
|
|
43
43
|
if (!template || stack.includes(partId) || stack.length >= MAX_SECTION_DEPTH) {
|
|
44
|
-
if (ctx.mode !== "editor") return ELEMENTS.
|
|
44
|
+
if (ctx.mode !== "editor") return ELEMENTS["part-ref"].build(node as never, attrs, []);
|
|
45
45
|
return { tag: "div", attrs, children: ["Synced section"] };
|
|
46
46
|
}
|
|
47
47
|
// W-653: past the render's budget a copy renders like a missing part. W-657: the editor
|
|
48
48
|
// says why, instead of the same placeholder a deleted part shows.
|
|
49
49
|
if (ctx.takeSectionBudget && !ctx.takeSectionBudget(partSize(template.root.children))) {
|
|
50
|
-
if (ctx.mode !== "editor") return ELEMENTS.
|
|
50
|
+
if (ctx.mode !== "editor") return ELEMENTS["part-ref"].build(node as never, attrs, []);
|
|
51
51
|
return {
|
|
52
52
|
tag: "div",
|
|
53
53
|
attrs,
|
|
@@ -60,5 +60,5 @@ export function renderSection(
|
|
|
60
60
|
sectionStack: [...stack, partId],
|
|
61
61
|
idOrigin: `${dynamic?.idOrigin ?? ""}/s:${partId}`,
|
|
62
62
|
};
|
|
63
|
-
return ELEMENTS.
|
|
63
|
+
return ELEMENTS["part-ref"].build(node as never, attrs, ctx.children(templateNodes, next));
|
|
64
64
|
}
|
package/src/core/render/vnode.ts
CHANGED
|
@@ -78,7 +78,7 @@ const TAGS = new Set([
|
|
|
78
78
|
const VOID = new Set(["hr", "img", "input", "br"]);
|
|
79
79
|
// iframe/video are not void — they need closing tags.
|
|
80
80
|
const ATTR_NAME =
|
|
81
|
-
/^(?:class|id|href|src|srcset|sizes|alt|width|height|loading|decoding|fetchpriority|dir|role|type|checked|target|rel|aria-[a-z][a-z0-9-]*|title|allow|referrerpolicy|preload|controls|allowfullscreen|sandbox|xmlns|viewBox|fill|stroke|stroke-width|stroke-linecap|stroke-linejoin|stroke-dasharray|stroke-opacity|fill-opacity|opacity|transform|focusable|d|cx|cy|r|x|y|x1|y1|x2|y2|points|rx|ry|xlink:href|preserveAspectRatio|gradientUnits|gradientTransform|offset|stop-color|stop-opacity|clipPathUnits|maskUnits|maskContentUnits|patternUnits|patternContentUnits|patternTransform|markerUnits|markerWidth|markerHeight|refX|refY|orient|font-size|font-family|font-weight|text-anchor|dominant-baseline|dx|dy|clip-path|method|action|name|value|placeholder|for|tabindex|autocomplete|open|datetime|muted|loop|playsinline|autoplay|required|novalidate|minlength|maxlength|min|max|pattern|step|data-[a-z][a-z0-9-]*)$/;
|
|
81
|
+
/^(?:class|id|href|src|srcset|sizes|alt|width|height|loading|decoding|fetchpriority|dir|lang|hreflang|role|type|checked|target|rel|aria-[a-z][a-z0-9-]*|title|allow|referrerpolicy|preload|controls|allowfullscreen|sandbox|xmlns|viewBox|fill|stroke|stroke-width|stroke-linecap|stroke-linejoin|stroke-dasharray|stroke-opacity|fill-opacity|opacity|transform|focusable|d|cx|cy|r|x|y|x1|y1|x2|y2|points|rx|ry|xlink:href|preserveAspectRatio|gradientUnits|gradientTransform|offset|stop-color|stop-opacity|clipPathUnits|maskUnits|maskContentUnits|patternUnits|patternContentUnits|patternTransform|markerUnits|markerWidth|markerHeight|refX|refY|orient|font-size|font-family|font-weight|text-anchor|dominant-baseline|dx|dy|clip-path|method|action|name|value|placeholder|for|tabindex|autocomplete|open|datetime|muted|loop|playsinline|autoplay|required|novalidate|minlength|maxlength|min|max|pattern|step|start|data-[a-z][a-z0-9-]*)$/;
|
|
82
82
|
|
|
83
83
|
export const isAllowedTag = (tag: string) => TAGS.has(tag);
|
|
84
84
|
export const isAllowedAttr = (name: string) => ATTR_NAME.test(name);
|