@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
|
@@ -56,7 +56,10 @@ export function renderPagination(
|
|
|
56
56
|
class: "emvb-pagination-prev",
|
|
57
57
|
href: href(item.href),
|
|
58
58
|
rel: "prev",
|
|
59
|
-
...nameIfSymbols(
|
|
59
|
+
...nameIfSymbols(
|
|
60
|
+
label(node.props.prevText, "Previous"),
|
|
61
|
+
label(node.props.prevLabel, "Previous page"),
|
|
62
|
+
),
|
|
60
63
|
},
|
|
61
64
|
children: [label(node.props.prevText, "Previous")],
|
|
62
65
|
};
|
|
@@ -67,7 +70,10 @@ export function renderPagination(
|
|
|
67
70
|
class: "emvb-pagination-next",
|
|
68
71
|
href: href(item.href),
|
|
69
72
|
rel: "next",
|
|
70
|
-
...nameIfSymbols(
|
|
73
|
+
...nameIfSymbols(
|
|
74
|
+
label(node.props.nextText, "Next"),
|
|
75
|
+
label(node.props.nextLabel, "Next page"),
|
|
76
|
+
),
|
|
71
77
|
},
|
|
72
78
|
children: [label(node.props.nextText, "Next")],
|
|
73
79
|
};
|
|
@@ -84,7 +90,11 @@ export function renderPagination(
|
|
|
84
90
|
class: "emvb-pagination-page",
|
|
85
91
|
href: href(item.href),
|
|
86
92
|
// W-426: a bare "2" says nothing out of context; screen readers hear "Page 2".
|
|
87
|
-
|
|
93
|
+
// W-689: in the site's language when "Page number name" is set.
|
|
94
|
+
"aria-label": label(node.props.pageLabel, "Page {page}").replaceAll(
|
|
95
|
+
"{page}",
|
|
96
|
+
String(item.n),
|
|
97
|
+
),
|
|
88
98
|
...(item.current ? { "aria-current": "page" } : {}),
|
|
89
99
|
},
|
|
90
100
|
children: [String(item.n)],
|
|
@@ -99,5 +109,9 @@ export function renderPagination(
|
|
|
99
109
|
children: [pageCountText(data, node.props.countText)],
|
|
100
110
|
});
|
|
101
111
|
}
|
|
102
|
-
return {
|
|
112
|
+
return {
|
|
113
|
+
tag: "nav",
|
|
114
|
+
attrs: { ...attrs, "aria-label": label(node.props.navLabel, "Pagination") },
|
|
115
|
+
children,
|
|
116
|
+
};
|
|
103
117
|
}
|
|
@@ -6,6 +6,23 @@ import type { VNode } from "./vnode.ts";
|
|
|
6
6
|
|
|
7
7
|
const MAX_SECTION_DEPTH = 8;
|
|
8
8
|
|
|
9
|
+
const sizes = new WeakMap<object, number>();
|
|
10
|
+
/** Elements in a part's layout, counted once per layout object. */
|
|
11
|
+
function partSize(nodes: readonly object[]): number {
|
|
12
|
+
const cached = sizes.get(nodes);
|
|
13
|
+
if (cached !== undefined) return cached;
|
|
14
|
+
let count = 0;
|
|
15
|
+
const stack: unknown[] = [...nodes];
|
|
16
|
+
while (stack.length > 0) {
|
|
17
|
+
const node = stack.pop() as { children?: unknown } | null;
|
|
18
|
+
if (!node || typeof node !== "object") continue;
|
|
19
|
+
count++;
|
|
20
|
+
if (Array.isArray(node.children)) for (const child of node.children) stack.push(child);
|
|
21
|
+
}
|
|
22
|
+
sizes.set(nodes, count);
|
|
23
|
+
return count;
|
|
24
|
+
}
|
|
25
|
+
|
|
9
26
|
/**
|
|
10
27
|
* A section with `partId` renders that theme part's children.
|
|
11
28
|
* A missing part stays empty on the public site (local children would drift from the source).
|
|
@@ -27,6 +44,16 @@ export function renderSection(
|
|
|
27
44
|
if (ctx.mode !== "editor") return ELEMENTS.section.build(node as never, attrs, []);
|
|
28
45
|
return { tag: "div", attrs, children: ["Synced section"] };
|
|
29
46
|
}
|
|
47
|
+
// W-653: past the render's budget a copy renders like a missing part. W-657: the editor
|
|
48
|
+
// says why, instead of the same placeholder a deleted part shows.
|
|
49
|
+
if (ctx.takeSectionBudget && !ctx.takeSectionBudget(partSize(template.root.children))) {
|
|
50
|
+
if (ctx.mode !== "editor") return ELEMENTS.section.build(node as never, attrs, []);
|
|
51
|
+
return {
|
|
52
|
+
tag: "div",
|
|
53
|
+
attrs,
|
|
54
|
+
children: ["Synced section not shown: this page already holds too many synced copies."],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
30
57
|
const templateNodes = template.root.children;
|
|
31
58
|
const next: ThemeDynamicData = {
|
|
32
59
|
...dynamic,
|
package/src/core/render/tabs.ts
CHANGED
|
@@ -40,10 +40,19 @@ export function renderTabs(
|
|
|
40
40
|
"aria-controls": panelDomId,
|
|
41
41
|
tabindex: i === 0 ? "0" : "-1",
|
|
42
42
|
},
|
|
43
|
-
|
|
43
|
+
// W-664: a label of only spaces made a zero-width tab nobody could click or hear.
|
|
44
|
+
children: [panel.props.label.trim() || `Tab ${i + 1}`],
|
|
44
45
|
});
|
|
46
|
+
// W-598: the panel renders like any element, so its own style, classes and device
|
|
47
|
+
// visibility reach the page; the tab wiring is added on top.
|
|
48
|
+
const built = ctx.children([panel], dynamic)[0];
|
|
49
|
+
const own = built?.attrs ?? {};
|
|
45
50
|
const panelAttrs: Record<string, string> = {
|
|
46
|
-
|
|
51
|
+
...own,
|
|
52
|
+
class: `emvb-tab-panel ${own.class ?? ""}`
|
|
53
|
+
.split(/\s+/)
|
|
54
|
+
.filter((c, at, all) => c && all.indexOf(c) === at)
|
|
55
|
+
.join(" "),
|
|
47
56
|
id: panelDomId,
|
|
48
57
|
role: "tabpanel",
|
|
49
58
|
"aria-labelledby": tabDomId,
|
|
@@ -52,7 +61,7 @@ export function renderTabs(
|
|
|
52
61
|
panelNodes.push({
|
|
53
62
|
tag: "div",
|
|
54
63
|
attrs: panelAttrs,
|
|
55
|
-
children: ctx.children(panel.children, dynamic),
|
|
64
|
+
children: built ? built.children : ctx.children(panel.children, dynamic),
|
|
56
65
|
});
|
|
57
66
|
});
|
|
58
67
|
return {
|
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|data-[a-z][a-z0-9-]*)$/;
|
|
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-]*)$/;
|
|
82
82
|
|
|
83
83
|
export const isAllowedTag = (tag: string) => TAGS.has(tag);
|
|
84
84
|
export const isAllowedAttr = (name: string) => ATTR_NAME.test(name);
|
package/src/core/sanitize/css.ts
CHANGED
|
@@ -51,6 +51,15 @@ export function isSafeCssValue(value: string): boolean {
|
|
|
51
51
|
const FAMILY = String.raw`(?:'[\p{L}\p{N} _.-]+'|"[\p{L}\p{N} _.-]+"|[\p{L}\p{N}_-]+(?: [\p{L}\p{N}_-]+)*)`;
|
|
52
52
|
const FONT_STACK = new RegExp(String.raw`^${FAMILY}(?:\s*,\s*${FAMILY})*$`, "u");
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* A font stack that can be written as a `font-family` declaration (W-648): `!important` would let
|
|
56
|
+
* a class's font beat the element's own, and control characters aren't part of any family name.
|
|
57
|
+
* Checked on output only, so a layout saved with one still loads; the declaration is dropped.
|
|
58
|
+
*/
|
|
59
|
+
function isEmittableFontStack(value: string): boolean {
|
|
60
|
+
return !/[!\p{Cc}]/u.test(value) && isSafeFontStack(value);
|
|
61
|
+
}
|
|
62
|
+
|
|
54
63
|
/**
|
|
55
64
|
* A comma-separated font stack whose family names may be quoted. Quoted names hold only letters,
|
|
56
65
|
* digits, spaces, `_`, `.` and `-`, so a quote can never open or close anything else.
|
|
@@ -700,7 +709,7 @@ export function styleDeclarations(style: unknown): {
|
|
|
700
709
|
const value = entry?.toValue(raw);
|
|
701
710
|
const safe =
|
|
702
711
|
value !== undefined &&
|
|
703
|
-
(entry?.css === "font-family" ?
|
|
712
|
+
(entry?.css === "font-family" ? isEmittableFontStack(value) : isSafeCssValue(value));
|
|
704
713
|
if (entry && safe) {
|
|
705
714
|
declarations.push({ property: entry.css, value });
|
|
706
715
|
if (key === "entrance") {
|
|
@@ -719,6 +728,10 @@ export function styleDeclarations(style: unknown): {
|
|
|
719
728
|
const background = composeBackground(record);
|
|
720
729
|
declarations.push(...background.declarations);
|
|
721
730
|
rejected.push(...background.rejected);
|
|
731
|
+
// W-802: a background video is drawn above the element's background, overlay included, so
|
|
732
|
+
// the overlay is also handed to the layer the video box paints above its video.
|
|
733
|
+
const overlayLayer = cssOverlay(record["overlay"]);
|
|
734
|
+
if (overlayLayer) declarations.push({ property: "--emvb-bg-overlay", value: overlayLayer });
|
|
722
735
|
const column = gridPlacement(record["gridColumnStart"], record["gridColumnSpan"]);
|
|
723
736
|
const row = gridPlacement(record["gridRowStart"], record["gridRowSpan"]);
|
|
724
737
|
if (column.value) declarations.push({ property: "grid-column", value: column.value });
|
|
@@ -795,7 +808,7 @@ const ANIMATION_KEYS = ["entrance", "scrollMotion"] as const;
|
|
|
795
808
|
* A style that sets an entrance or scroll motion keeps the other one it inherits from a wider
|
|
796
809
|
* device or its classes (W-319): both are one `animation` list in CSS.
|
|
797
810
|
*/
|
|
798
|
-
|
|
811
|
+
function withInheritedAnimation(style: unknown, inherited: unknown): unknown {
|
|
799
812
|
if (!isRecord(style) || !isRecord(inherited)) return style;
|
|
800
813
|
if (!ANIMATION_KEYS.some((key) => style[key] !== undefined)) return style;
|
|
801
814
|
const next: Record<string, unknown> = { ...style };
|
|
@@ -13,6 +13,8 @@ const YT_HOSTS = new Set([
|
|
|
13
13
|
"youtube.com",
|
|
14
14
|
"www.youtube.com",
|
|
15
15
|
"m.youtube.com",
|
|
16
|
+
// W-546: YouTube Music links play the same video ids.
|
|
17
|
+
"music.youtube.com",
|
|
16
18
|
"youtu.be",
|
|
17
19
|
"www.youtu.be",
|
|
18
20
|
"youtube-nocookie.com",
|
|
@@ -27,9 +29,26 @@ const YT_ID = /^[\w-]{6,}$/;
|
|
|
27
29
|
const VIMEO_ID = /^\d{6,}$/;
|
|
28
30
|
const firstSegment = (path: string) => path.split("/").find(Boolean);
|
|
29
31
|
|
|
32
|
+
/** A YouTube playlist id (PL…, UU…, OLAK5uy_…). */
|
|
33
|
+
const YT_LIST = /^[\w-]{10,64}$/;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* W-691: a playlist (`/embed/videoseries?list=…`, `/playlist?list=…`) embeds as
|
|
37
|
+
* `videoseries?list=…`. "videoseries" was taken for a video id and the list dropped, so the
|
|
38
|
+
* player showed "Video unavailable".
|
|
39
|
+
*/
|
|
40
|
+
function youtubePlaylist(parsed: URL): string | undefined | null {
|
|
41
|
+
const path = parsed.pathname.replace(/\/+$/, "");
|
|
42
|
+
if (path !== "/embed/videoseries" && path !== "/playlist") return null;
|
|
43
|
+
const list = matching(parsed.searchParams.get("list") ?? undefined, YT_LIST);
|
|
44
|
+
return list ? `videoseries?list=${list}` : undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
30
47
|
function youtubeId(parsed: URL): string | undefined {
|
|
31
48
|
const host = parsed.hostname.toLowerCase();
|
|
32
49
|
const path = parsed.pathname;
|
|
50
|
+
const playlist = youtubePlaylist(parsed);
|
|
51
|
+
if (playlist !== null) return playlist;
|
|
33
52
|
if (host === "youtu.be" || host === "www.youtu.be") return matching(firstSegment(path), YT_ID);
|
|
34
53
|
// W-215: /live/ links (a stream or its replay) too.
|
|
35
54
|
for (const prefix of ["/embed/", "/shorts/", "/live/"]) {
|
|
@@ -56,7 +75,9 @@ function vimeoId(parsed: URL): string | undefined {
|
|
|
56
75
|
: 0
|
|
57
76
|
: parts[0] === "channels"
|
|
58
77
|
? 2
|
|
59
|
-
: parts[0] === "groups" && parts[2] === "videos"
|
|
78
|
+
: (parts[0] === "groups" && parts[2] === "videos") ||
|
|
79
|
+
// W-546: a video opened from a showcase.
|
|
80
|
+
(parts[0] === "showcase" && parts[2] === "video")
|
|
60
81
|
? 3
|
|
61
82
|
: 0;
|
|
62
83
|
const id = matching(parts[at], VIMEO_ID);
|
|
@@ -93,7 +114,7 @@ const withStart = (provider: "youtube" | "vimeo", src: string, start: number | u
|
|
|
93
114
|
start === undefined
|
|
94
115
|
? src
|
|
95
116
|
: provider === "youtube"
|
|
96
|
-
? `${src}?start=${start}`
|
|
117
|
+
? `${src}${src.includes("?") ? "&" : "?"}start=${start}`
|
|
97
118
|
: `${src}#t=${start}s`;
|
|
98
119
|
|
|
99
120
|
/**
|
|
@@ -116,16 +137,32 @@ const PROVIDERS = [
|
|
|
116
137
|
*/
|
|
117
138
|
// W-448: "youtube.com/watch?v=…" typed without https:// was taken for a video file path on this
|
|
118
139
|
// site, so the page showed a broken player. Known video hosts get their scheme.
|
|
119
|
-
|
|
120
|
-
|
|
140
|
+
// W-659: every host the providers accept, not a hand-kept subset (youtube-nocookie.com and
|
|
141
|
+
// www.youtu.be still became a broken file player).
|
|
142
|
+
function bareVideoHost(typed: string): boolean {
|
|
143
|
+
const slash = typed.indexOf("/");
|
|
144
|
+
if (slash <= 0) return false;
|
|
145
|
+
const host = typed.slice(0, slash).toLowerCase();
|
|
146
|
+
return YT_HOSTS.has(host) || VIMEO_HOSTS.has(host);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** A site path (not `//host`) to a .mp4/.webm/.ogg file, or the media file route. */
|
|
150
|
+
function isVideoFilePath(value: string): boolean {
|
|
151
|
+
if (value.startsWith("//")) return false;
|
|
152
|
+
const path = value.split(/[?#]/)[0] ?? "";
|
|
153
|
+
return /\.(mp4|webm|ogg)$/i.test(path) || path.startsWith("/_emdash/api/media/file/");
|
|
154
|
+
}
|
|
121
155
|
|
|
122
156
|
export function resolveEmbedUrl(value: string): EmbedTarget | undefined {
|
|
123
157
|
const typed = value.trim();
|
|
124
|
-
const trimmed =
|
|
158
|
+
const trimmed = bareVideoHost(typed) ? `https://${typed}` : typed;
|
|
125
159
|
if (trimmed.length === 0 || trimmed.length > 2000) return undefined;
|
|
126
160
|
|
|
127
161
|
const hasScheme = /^[a-z][a-z0-9+.-]*:/i.test(trimmed);
|
|
128
162
|
if (!hasScheme) {
|
|
163
|
+
// W-795: a bare word such as "nonsense" became a page-relative <video> (a black player).
|
|
164
|
+
// A relative value must name a video file or the media route, as absolute ones must.
|
|
165
|
+
if (!isVideoFilePath(trimmed)) return undefined;
|
|
129
166
|
const media = sanitizeMediaUrl(trimmed);
|
|
130
167
|
if (!media) return undefined;
|
|
131
168
|
return { kind: "video", src: media };
|
package/src/core/sanitize/url.ts
CHANGED
|
@@ -20,7 +20,8 @@ export function sanitizeUrl(value: string, schemes: ReadonlySet<string>): string
|
|
|
20
20
|
// second address hides in the same string.
|
|
21
21
|
if (/[^\S ]|\\/.test(trimmed)) return undefined;
|
|
22
22
|
// Relative: /path, ./path, ../path, ?query, #hash, or bare path segment
|
|
23
|
-
|
|
23
|
+
// W-683: or one that starts in another script ("über-uns", "контакты"), like page slugs (W-554).
|
|
24
|
+
if (/^(?:[/?#.]|[\p{L}\p{N}._~-])/u.test(trimmed)) return trimmed;
|
|
24
25
|
return undefined;
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { MAX_TEXT_LENGTH } from "../limits.ts";
|
|
3
|
+
import { ImageEdit } from "../image-edit/schema.ts";
|
|
3
4
|
import { DeviceStyles, HiddenOn, Length, StyleProps, StyleStates } from "./style.ts";
|
|
4
5
|
|
|
5
6
|
/**
|
|
7
|
+
* 16 since W-481 (D-061): an optional editor-only `edit` record on images (image editor).
|
|
8
|
+
* Every other value is unchanged.
|
|
6
9
|
* 15 since W-341: optional per-element `dir`, image link/caption/focal point/sources, button icons,
|
|
7
10
|
* a table-of-contents element, and container queries. Every other value is unchanged.
|
|
8
11
|
* 14 since W-329: optional visitor `segments` in an element's audience (the host names them);
|
|
@@ -14,7 +17,7 @@ import { DeviceStyles, HiddenOn, Length, StyleProps, StyleStates } from "./style
|
|
|
14
17
|
* (`{ angle, from, to }`) become a linear gradient on read.
|
|
15
18
|
* 11 since W-156 and W-157 (D-045): the layout Section element and an editor-only node label.
|
|
16
19
|
*/
|
|
17
|
-
export const LAYOUT_SCHEMA_VERSION =
|
|
20
|
+
export const LAYOUT_SCHEMA_VERSION = 16;
|
|
18
21
|
|
|
19
22
|
export const NodeId = z
|
|
20
23
|
.string()
|
|
@@ -104,7 +107,7 @@ export const AUDIENCE_DEVICES = ["mobile", "tablet", "desktop"] as const;
|
|
|
104
107
|
/** A visitor segment name the host passes and a Visitors rule matches (W-329). */
|
|
105
108
|
/** A host segment name: letters, digits, and `:` `_` `-`, up to 64 characters (`plan:pro`). */
|
|
106
109
|
export const AUDIENCE_SEGMENT = /^[a-z0-9][a-z0-9:_-]{0,63}$/;
|
|
107
|
-
const SEGMENT_HINT = "Segments are lowercase letters, digits, :, - or _,
|
|
110
|
+
const SEGMENT_HINT = "Segments are lowercase letters, digits, :, - or _, such as plan:pro";
|
|
108
111
|
|
|
109
112
|
/**
|
|
110
113
|
* Who sees an element (W-313): visitors from these countries, on these devices, new or
|
|
@@ -114,7 +117,7 @@ const SEGMENT_HINT = "Segments are lowercase letters, digits, :, - or _, e.g. pl
|
|
|
114
117
|
*/
|
|
115
118
|
export const Audience = z.strictObject({
|
|
116
119
|
countries: z
|
|
117
|
-
.array(z.string().regex(/^[A-Z]{2}$/, "Two-letter country codes,
|
|
120
|
+
.array(z.string().regex(/^[A-Z]{2}$/, "Two-letter country codes, such as CA"))
|
|
118
121
|
.min(1)
|
|
119
122
|
.max(50)
|
|
120
123
|
.optional(),
|
|
@@ -339,6 +342,8 @@ export const ImageNode = leafNode(
|
|
|
339
342
|
)
|
|
340
343
|
.max(6)
|
|
341
344
|
.optional(),
|
|
345
|
+
/** Editor-only record of an image-editor edit; never rendered (W-481). */
|
|
346
|
+
edit: ImageEdit.optional(),
|
|
342
347
|
}),
|
|
343
348
|
).refine((node) => node.props.decorative === true || node.props.alt.length > 0, {
|
|
344
349
|
message: "Alt text is required unless the image is marked decorative.",
|
|
@@ -562,7 +567,7 @@ export const PostLinkNode = leafNode(
|
|
|
562
567
|
export const LOOP_DISPLAYS = ["list", "grid", "cards"] as const;
|
|
563
568
|
/** A collection field's slug, e.g. `photo` (W-330). */
|
|
564
569
|
const FIELD_SLUG = /^[a-z][a-z0-9_]{0,63}$/;
|
|
565
|
-
const FIELD_SLUG_HINT = "Use the field's slug,
|
|
570
|
+
const FIELD_SLUG_HINT = "Use the field's slug, such as photo";
|
|
566
571
|
/** A site path with `{slug}` or `{id}`, and no other placeholders (W-330). */
|
|
567
572
|
export const LOOP_PERMALINK =
|
|
568
573
|
/^(?=.*\{(?:slug|id)\})\/(?!\/)(?:[A-Za-z0-9._~/-]|\{slug\}|\{id\})*$/;
|
|
@@ -588,7 +593,7 @@ export const LoopNode = parentNode(
|
|
|
588
593
|
*/
|
|
589
594
|
collection: z
|
|
590
595
|
.string()
|
|
591
|
-
.regex(/^[a-z][a-z0-9_]{0,63}$/, "Use the collection's slug,
|
|
596
|
+
.regex(/^[a-z][a-z0-9_]{0,63}$/, "Use the collection's slug, such as team")
|
|
592
597
|
.optional(),
|
|
593
598
|
/** How many entries a collection Loop shows, 1–50. Unset = 6. */
|
|
594
599
|
limit: z.number().int().min(1).max(50).optional(),
|
|
@@ -603,7 +608,7 @@ export const LoopNode = parentNode(
|
|
|
603
608
|
permalink: z
|
|
604
609
|
.string()
|
|
605
610
|
.max(200)
|
|
606
|
-
.regex(LOOP_PERMALINK, "A site path with {slug} or {id},
|
|
611
|
+
.regex(LOOP_PERMALINK, "A site path with {slug} or {id}, such as /team/{slug}")
|
|
607
612
|
.optional(),
|
|
608
613
|
/** The entry field holding the image Post Image shows (W-330). Unset = featured_image. */
|
|
609
614
|
imageField: z.string().regex(FIELD_SLUG, FIELD_SLUG_HINT).optional(),
|
|
@@ -640,6 +645,19 @@ export const PaginationNode = leafNode(
|
|
|
640
645
|
showCount: z.boolean().optional(),
|
|
641
646
|
/** The count's text; `{page}` and `{total}` are filled in. Unset = "Page {page} of {total}". */
|
|
642
647
|
countText: z.string().max(60).optional(),
|
|
648
|
+
/**
|
|
649
|
+
* The page title of archive page 2 onward (W-529); `{title}` and `{page}` are filled in.
|
|
650
|
+
* Unset = "{title} – page {page}". Hosts read it with `archivePageTitle`.
|
|
651
|
+
*/
|
|
652
|
+
titleText: z.string().max(60).optional(),
|
|
653
|
+
archiveTitle: z.string().max(60).optional(),
|
|
654
|
+
/** W-689: screen reader names in the site's language. Unset = "Pagination". */
|
|
655
|
+
navLabel: z.string().max(60).optional(),
|
|
656
|
+
/** Each number's name; `{page}` is filled in. Unset = "Page {page}". */
|
|
657
|
+
pageLabel: z.string().max(60).optional(),
|
|
658
|
+
/** Previous / Next names when their text is only an arrow. Unset = "Previous page" / "Next page". */
|
|
659
|
+
prevLabel: z.string().max(60).optional(),
|
|
660
|
+
nextLabel: z.string().max(60).optional(),
|
|
643
661
|
}),
|
|
644
662
|
);
|
|
645
663
|
|
|
@@ -900,7 +918,8 @@ export type TabPanelNode = NodeEnvelope & {
|
|
|
900
918
|
|
|
901
919
|
export type TabsNode = NodeEnvelope & {
|
|
902
920
|
type: "tabs";
|
|
903
|
-
|
|
921
|
+
/** W-790: read from TabsNodeSchema, so the type can't drift from what the schema accepts. */
|
|
922
|
+
props: z.infer<typeof TabsNodeSchema>["props"];
|
|
904
923
|
children: LayoutNode[];
|
|
905
924
|
};
|
|
906
925
|
|
package/src/core/share/link.ts
CHANGED
|
@@ -17,6 +17,9 @@ const MAX_TITLE = 120;
|
|
|
17
17
|
/** Unpacked text: a layout and a design at their limits, plus a little JSON. */
|
|
18
18
|
const MAX_UNPACKED_BYTES = MAX_LAYOUT_BYTES + MAX_DESIGN_BYTES + 4096;
|
|
19
19
|
|
|
20
|
+
/** W-507: the title cap counts whole characters, so an emoji at the limit isn't cut in half. */
|
|
21
|
+
const clipTitle = (title: string): string => Array.from(title).slice(0, MAX_TITLE).join("");
|
|
22
|
+
|
|
20
23
|
export type SharedPage = { title: string; layout: Layout; design?: DesignSystem };
|
|
21
24
|
|
|
22
25
|
export type ShareRead =
|
|
@@ -120,7 +123,7 @@ export async function pipeBytes(
|
|
|
120
123
|
*/
|
|
121
124
|
export async function encodeSharedPage(page: SharedPage): Promise<string> {
|
|
122
125
|
const json = JSON.stringify({
|
|
123
|
-
t: page.title
|
|
126
|
+
t: clipTitle(page.title),
|
|
124
127
|
l: page.layout,
|
|
125
128
|
...(page.design ? { d: page.design } : {}),
|
|
126
129
|
});
|
|
@@ -176,7 +179,7 @@ export async function decodeSharedPage(encoded: string): Promise<ShareRead> {
|
|
|
176
179
|
return { ok: false, reason: "invalid", detail: layout.issues[0]?.message ?? "Bad layout" };
|
|
177
180
|
}
|
|
178
181
|
const page: SharedPage = {
|
|
179
|
-
title: typeof t === "string" && t.trim() ? t.trim()
|
|
182
|
+
title: typeof t === "string" && t.trim() ? clipTitle(t.trim()) : "Shared page",
|
|
180
183
|
layout: layout.layout,
|
|
181
184
|
};
|
|
182
185
|
if (d !== undefined) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Keys sorted at every level: a saved copy comes back in schema order, not edit order. */
|
|
2
|
+
function sorted(value: unknown): unknown {
|
|
3
|
+
if (Array.isArray(value)) return value.map(sorted);
|
|
4
|
+
if (!value || typeof value !== "object") return value;
|
|
5
|
+
const entries = Object.entries(value as Record<string, unknown>).toSorted(([a], [b]) =>
|
|
6
|
+
a < b ? -1 : a > b ? 1 : 0,
|
|
7
|
+
);
|
|
8
|
+
return Object.fromEntries(entries.map(([k, v]) => [k, sorted(v)]));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** JSON text that ignores key order, to compare a saved copy with an edited one (W-518, W-519). */
|
|
12
|
+
export const stableJson = (value: unknown): string => JSON.stringify(sorted(value));
|
|
13
|
+
|
|
14
|
+
/** Same content, whatever the key order (W-519). */
|
|
15
|
+
export const sameJson = (a: unknown, b: unknown): boolean => stableJson(a) === stableJson(b);
|
package/src/core/stats.ts
CHANGED
|
@@ -12,7 +12,8 @@ export function summarizeLayout(input: unknown): LayoutSummary | undefined {
|
|
|
12
12
|
if (typeof node !== "object" || node === null) continue;
|
|
13
13
|
nodes++;
|
|
14
14
|
const children = (node as { children?: unknown }).children;
|
|
15
|
-
|
|
15
|
+
// No spread: a huge children list would overflow the call stack (W-646).
|
|
16
|
+
if (Array.isArray(children)) for (const child of children) stack.push(child);
|
|
16
17
|
}
|
|
17
18
|
return { nodes, schemaVersion };
|
|
18
19
|
}
|
|
@@ -142,8 +142,10 @@ export function conditionSpecificity(rule: ConditionRule): number {
|
|
|
142
142
|
if (
|
|
143
143
|
rule.group === "archive" &&
|
|
144
144
|
rule.name === "taxonomy" &&
|
|
145
|
-
typeof rule.args["slug"] === "string"
|
|
145
|
+
typeof rule.args["slug"] === "string" &&
|
|
146
|
+
rule.args["slug"] !== ""
|
|
146
147
|
) {
|
|
148
|
+
// A blank slug matches every term (taxonomyMatches), so it is not more specific (W-584).
|
|
147
149
|
score += 5;
|
|
148
150
|
}
|
|
149
151
|
return score;
|
|
@@ -41,6 +41,8 @@ export type ThemeDynamicData = {
|
|
|
41
41
|
sectionTemplates?: Record<string, Layout>;
|
|
42
42
|
/** Section part ids already being expanded, so a section cannot include itself. */
|
|
43
43
|
sectionStack?: readonly string[];
|
|
44
|
+
/** Loop item parts being rendered, outermost first, so a part that lists itself stops (W-654). */
|
|
45
|
+
loopStack?: readonly string[];
|
|
44
46
|
/**
|
|
45
47
|
* Where the nodes being rendered come from (W-250): unset for the page itself, else the synced
|
|
46
48
|
* section and loop item parts they were expanded from. Another layout can reuse an id.
|
|
@@ -99,27 +101,37 @@ function linkDefs(block: Record<string, unknown>): Map<string, string> {
|
|
|
99
101
|
return links;
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
/**
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
):
|
|
104
|
+
/** Text with its line breaks as `<br>`. */
|
|
105
|
+
function withBreaks(text: string): (VNode | string)[] {
|
|
106
|
+
const out: (VNode | string)[] = [];
|
|
107
|
+
text.split("\n").forEach((part, i) => {
|
|
108
|
+
if (i > 0) out.push({ tag: "br", attrs: {}, children: [] });
|
|
109
|
+
if (part) out.push(part);
|
|
110
|
+
});
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* A span's text wrapped in its marks; unknown marks and unsafe links leave plain text. Line
|
|
116
|
+
* breaks become `<br>` inside the marks too: a bold or linked line break was lost (W-525).
|
|
117
|
+
*/
|
|
118
|
+
function spanNodes(span: Record<string, unknown>, links: Map<string, string>): (VNode | string)[] {
|
|
107
119
|
const text = typeof span["text"] === "string" ? span["text"] : "";
|
|
108
|
-
if (!text) return
|
|
120
|
+
if (!text) return [];
|
|
109
121
|
const marks = Array.isArray(span["marks"])
|
|
110
122
|
? span["marks"].filter((m) => typeof m === "string")
|
|
111
123
|
: [];
|
|
112
|
-
let
|
|
124
|
+
let nodes = withBreaks(text);
|
|
113
125
|
// W-392: a link can't hold a link, so only the span's first (outermost) link mark is kept.
|
|
114
126
|
const link = marks.find((mark) => !DECORATORS[mark] && links.has(mark));
|
|
115
127
|
for (const mark of new Set(marks.toReversed())) {
|
|
116
128
|
const tag = DECORATORS[mark];
|
|
117
|
-
if (tag)
|
|
129
|
+
if (tag) nodes = [{ tag, attrs: {}, children: nodes }];
|
|
118
130
|
else if (mark === link) {
|
|
119
|
-
|
|
131
|
+
nodes = [{ tag: "a", attrs: { href: links.get(mark) as string }, children: nodes }];
|
|
120
132
|
}
|
|
121
133
|
}
|
|
122
|
-
return
|
|
134
|
+
return nodes;
|
|
123
135
|
}
|
|
124
136
|
|
|
125
137
|
/** A block's spans, with line breaks kept as `<br>`. */
|
|
@@ -129,14 +141,7 @@ function inlineNodes(block: Record<string, unknown>): (VNode | string)[] {
|
|
|
129
141
|
const out: (VNode | string)[] = [];
|
|
130
142
|
for (const child of children) {
|
|
131
143
|
if (!isRecord(child) || (child["_type"] !== undefined && child["_type"] !== "span")) continue;
|
|
132
|
-
|
|
133
|
-
if (node === null) continue;
|
|
134
|
-
if (typeof node === "string" && node.includes("\n")) {
|
|
135
|
-
node.split("\n").forEach((part, i) => {
|
|
136
|
-
if (i > 0) out.push({ tag: "br", attrs: {}, children: [] });
|
|
137
|
-
if (part) out.push(part);
|
|
138
|
-
});
|
|
139
|
-
} else out.push(node);
|
|
144
|
+
out.push(...spanNodes(child, links));
|
|
140
145
|
}
|
|
141
146
|
return out;
|
|
142
147
|
}
|
|
@@ -167,8 +172,14 @@ const hasText = (nodes: readonly (VNode | string)[]): boolean =>
|
|
|
167
172
|
*/
|
|
168
173
|
export function portableTextToVNodes(value: unknown): VNode[] {
|
|
169
174
|
if (typeof value === "string") {
|
|
170
|
-
|
|
171
|
-
|
|
175
|
+
// W-662: plain-text content kept its blank lines and line breaks as raw newlines, which
|
|
176
|
+
// the page collapses, so every paragraph ran together into one.
|
|
177
|
+
return value
|
|
178
|
+
.replaceAll("\r\n", "\n")
|
|
179
|
+
.split(/\n[ \t]*\n/)
|
|
180
|
+
.map((para) => para.trim())
|
|
181
|
+
.filter(Boolean)
|
|
182
|
+
.map((para) => ({ tag: "p", attrs: {}, children: withBreaks(para) }));
|
|
172
183
|
}
|
|
173
184
|
if (!Array.isArray(value)) return [];
|
|
174
185
|
const out: VNode[] = [];
|
|
@@ -211,9 +222,32 @@ export function portableTextToVNodes(value: unknown): VNode[] {
|
|
|
211
222
|
const tag = style === "normal" ? "p" : style;
|
|
212
223
|
out.push({ tag, attrs: {}, children: inline });
|
|
213
224
|
}
|
|
214
|
-
return out
|
|
215
|
-
|
|
216
|
-
|
|
225
|
+
return pruneEmptyLists(out);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Lists with no items dropped at every depth (W-585): a blank nested item used to leave an empty
|
|
230
|
+
* `<ul>` inside its parent item, or an `<li>` holding only that empty list.
|
|
231
|
+
*/
|
|
232
|
+
const isList = (n: VNode): boolean => n.tag === "ul" || n.tag === "ol";
|
|
233
|
+
|
|
234
|
+
function pruneEmptyLists(nodes: VNode[]): VNode[] {
|
|
235
|
+
const keep: VNode[] = [];
|
|
236
|
+
for (const node of nodes) {
|
|
237
|
+
if (isList(node)) {
|
|
238
|
+
const items: VNode[] = [];
|
|
239
|
+
for (const li of node.children) {
|
|
240
|
+
if (typeof li === "string") continue;
|
|
241
|
+
li.children = li.children.flatMap((c) =>
|
|
242
|
+
typeof c !== "string" && isList(c) ? pruneEmptyLists([c]) : [c],
|
|
243
|
+
);
|
|
244
|
+
if (li.children.length > 0) items.push(li);
|
|
245
|
+
}
|
|
246
|
+
node.children = items;
|
|
247
|
+
if (items.length > 0) keep.push(node);
|
|
248
|
+
} else keep.push(node);
|
|
249
|
+
}
|
|
250
|
+
return keep;
|
|
217
251
|
}
|
|
218
252
|
|
|
219
253
|
/** Collect `loop.itemPartId` values so hosts can load Loop Item templates. */
|
package/src/core/theme/float.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { chromeLabel } from "./popup-markup.ts";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { escapeAttr } from "../sanitize/escape.ts";
|
|
3
4
|
import type { DesignSystem } from "../schema/design.ts";
|
|
@@ -43,6 +44,8 @@ export function validateFloatSettings(raw: unknown): FloatValidation {
|
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* Chrome for pinned bars and corner floats. Loaded only when a float matches.
|
|
47
|
+
* W-759: a corner float keeps its 1rem gap on both sides and never grows past the screen; a long
|
|
48
|
+
* one scrolls inside (on a phone it ran off the top, taking its close button and heading with it).
|
|
46
49
|
* Bars reserve their height through the two custom properties the runtime sets.
|
|
47
50
|
*/
|
|
48
51
|
export const FLOAT_CHROME_CSS = `
|
|
@@ -57,9 +60,11 @@ export const FLOAT_CHROME_CSS = `
|
|
|
57
60
|
:where(.emvb-float--surface){background:#fff;color:#0f172a;box-shadow:0 4px 16px -4px rgba(15,23,42,.25);padding:.5rem 1rem}
|
|
58
61
|
:where(.emvb-float--surface:is(.emvb-float--start-top,.emvb-float--end-top,.emvb-float--start-bottom,.emvb-float--end-bottom)){border-radius:.75rem;padding:.75rem 1rem}
|
|
59
62
|
.emvb-float__body{min-width:0;flex:1}
|
|
63
|
+
.emvb-float:is(.emvb-float--start-top,.emvb-float--end-top,.emvb-float--start-bottom,.emvb-float--end-bottom){max-width:calc(100% - 2rem)}
|
|
64
|
+
.emvb-float:is(.emvb-float--start-top,.emvb-float--end-top,.emvb-float--start-bottom,.emvb-float--end-bottom) .emvb-float__body{max-height:calc(100vh - 3.5rem);max-height:calc(100dvh - 3.5rem);overflow:auto}
|
|
60
65
|
.emvb-float__close{flex:none;width:2rem;height:2rem;border:0;border-radius:999px;background:transparent;color:inherit;font-size:1.5rem;line-height:1;cursor:pointer}
|
|
61
66
|
.emvb-float__close:focus-visible{outline:2px solid #2563eb;outline-offset:2px}
|
|
62
|
-
html{--emvb-float-top:0px;--emvb-float-bottom:0px}
|
|
67
|
+
html{--emvb-float-top:0px;--emvb-float-bottom:0px;scroll-padding-top:var(--emvb-float-top);scroll-padding-bottom:var(--emvb-float-bottom)}
|
|
63
68
|
body{padding-top:var(--emvb-float-top);padding-bottom:var(--emvb-float-bottom)}
|
|
64
69
|
`
|
|
65
70
|
.replace(/\n+/g, "")
|
|
@@ -97,12 +102,14 @@ export function wrapFloatMarkup(
|
|
|
97
102
|
bodyHtml: string,
|
|
98
103
|
settings: FloatSettings,
|
|
99
104
|
surface = true,
|
|
105
|
+
/** W-690: the close button's name in the site's language. Unset is "Close". */
|
|
106
|
+
closeLabel?: string,
|
|
100
107
|
): string {
|
|
101
108
|
const safeId = escapeAttr(id);
|
|
102
109
|
const label = escapeAttr(title.trim() || "Notice");
|
|
103
110
|
const edge = escapeAttr(settings.edge);
|
|
104
111
|
const close = settings.dismiss
|
|
105
|
-
? `<button type="button" class="emvb-float__close" data-emvb-float-dismiss aria-label="Close"><span aria-hidden="true">×</span></button>`
|
|
112
|
+
? `<button type="button" class="emvb-float__close" data-emvb-float-dismiss aria-label="${chromeLabel(closeLabel, "Close")}"><span aria-hidden="true">×</span></button>`
|
|
106
113
|
: "";
|
|
107
114
|
return [
|
|
108
115
|
`<aside class="emvb-float emvb-float--${edge}${surface ? " emvb-float--surface" : ""}" id="emvb-float-${safeId}" data-emvb-float="${safeId}" data-emvb-float-edge="${edge}" role="region" aria-label="${label}">`,
|