@perkyzz/emvb 1.3.0 → 1.4.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 +2 -2
- package/package.json +2 -2
- package/src/admin/bulk-api.ts +5 -1
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +22 -2
- package/src/admin/editor/Timeline.tsx +1 -8
- package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
- package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
- package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
- package/src/admin/editor/canvas/vnode-react.tsx +2 -0
- package/src/admin/editor/co-design.ts +36 -1
- package/src/admin/editor/dnd/dragged-source.ts +22 -0
- package/src/admin/editor/dnd/layer-drop.ts +141 -0
- package/src/admin/editor/dnd/new-element.ts +16 -0
- package/src/admin/editor/editor-css.ts +9 -1
- package/src/admin/editor/element-chrome.ts +6 -0
- package/src/admin/editor/feature-css.ts +22 -0
- package/src/admin/editor/inert-links.ts +8 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/FontFaces.tsx +342 -0
- package/src/admin/editor/panels/LayersPanel.tsx +56 -6
- package/src/admin/editor/panels/LeftPanel.tsx +153 -29
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
- package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
- package/src/admin/editor/panels/TokenScales.tsx +2 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
- package/src/admin/editor/panels/VariableSection.tsx +111 -7
- package/src/admin/editor/panels/color-space.ts +71 -6
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +18 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
- package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
- package/src/admin/editor/panels/settings/style-sections.ts +19 -2
- package/src/admin/editor/panels/url-rules.ts +43 -0
- package/src/admin/editor/panels/use-layers-drop.ts +232 -0
- package/src/admin/editor/store.ts +4 -2
- package/src/admin/editor/useExtensions.ts +3 -1
- package/src/admin/editor/useNodeActions.ts +74 -1
- package/src/admin/editor/useSave.ts +116 -85
- package/src/admin/export-api.ts +25 -2
- package/src/admin/extension-outputs.ts +179 -0
- package/src/admin/font-files-api.ts +38 -0
- package/src/admin/pages/ImportButton.tsx +15 -4
- package/src/admin/pages/ImportElementorDialog.tsx +22 -188
- package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
- package/src/admin/pages/ImportImageCopies.tsx +167 -0
- package/src/admin/pages/ImportReport.tsx +63 -0
- package/src/admin/pages/NewPageDialog.tsx +54 -32
- package/src/admin/pages/PageList.tsx +9 -0
- package/src/admin/pages/ThemePartList.tsx +9 -0
- package/src/astro/EmVBPage.astro +5 -2
- package/src/astro/extension-styles.ts +35 -0
- package/src/astro/forms/EmVBFormsClient.astro +3 -0
- package/src/astro/forms/enhance.ts +107 -0
- package/src/astro/popups/runtime.ts +47 -2
- package/src/astro/render.ts +19 -4
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
- package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
- package/src/astro/widgets/alerts.ts +16 -2
- package/src/astro/widgets/carousel.ts +65 -24
- package/src/astro/widgets/countdown.ts +18 -7
- package/src/astro/widgets/extension-runtimes.ts +27 -0
- package/src/astro/widgets/headline.ts +14 -5
- package/src/astro/widgets/sticky.ts +87 -0
- package/src/astro/widgets/theme.ts +52 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +150 -2
- package/src/core/arrange.ts +19 -1
- package/src/core/css/font-face.ts +72 -0
- package/src/core/css/generate.ts +35 -1
- package/src/core/elements/form-elements.ts +119 -9
- package/src/core/elements/icon-svg.ts +14 -0
- package/src/core/elements/index.ts +24 -4
- package/src/core/elements/input-limits.ts +44 -0
- package/src/core/elements/menu.ts +109 -47
- package/src/core/elements/site.ts +108 -0
- package/src/core/elements/widgets.ts +13 -3
- package/src/core/export/runtimes.generated.ts +7 -5
- package/src/core/export/site.ts +50 -4
- package/src/core/extensions/classes.ts +114 -0
- package/src/core/extensions/index.ts +17 -2
- package/src/core/extensions/normalize.ts +13 -0
- package/src/core/extensions/registry.ts +134 -10
- package/src/core/extensions/render-ext.ts +66 -21
- package/src/core/extensions/safe-nodes.ts +67 -11
- package/src/core/extensions/types.ts +48 -1
- package/src/core/fonts/files.ts +74 -0
- package/src/core/fonts/google.ts +112 -0
- package/src/core/fonts/test-font.ts +9 -0
- package/src/core/import/elementor/context.ts +13 -4
- package/src/core/import/elementor/index.ts +32 -21
- package/src/core/import/elementor/widgets.ts +114 -12
- package/src/core/import/html/blocks.ts +602 -0
- package/src/core/import/html/index.ts +155 -0
- package/src/core/import/html/map.ts +958 -0
- package/src/core/import/html/parse.ts +430 -0
- package/src/core/index.ts +45 -0
- package/src/core/migrate/v18.ts +3 -0
- package/src/core/public-attributes.ts +17 -0
- package/src/core/render/extras.ts +31 -7
- package/src/core/render/form.ts +103 -10
- package/src/core/render/index.ts +151 -15
- package/src/core/render/section.ts +31 -1
- package/src/core/render/spacer-basis.ts +102 -0
- package/src/core/render/theme-boot.ts +16 -0
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +68 -3
- package/src/core/sanitize/motion.ts +12 -0
- package/src/core/schema/design.ts +40 -0
- package/src/core/schema/layout.ts +114 -5
- package/src/core/schema/style.ts +28 -0
- package/src/core/templates/index.ts +218 -0
- package/src/core/templates/pages.ts +29 -0
- package/src/core/templates/sections.ts +794 -0
- package/src/core/templates/types.ts +9 -0
- package/src/core/theme/dynamic.ts +9 -6
- package/src/core/theme/popup-markup.ts +21 -2
- package/src/core/theme/popup-rules.ts +36 -0
- package/src/core/theme/triggers.ts +64 -5
- package/src/core/translatable.ts +5 -2
- package/src/extension-build.ts +331 -0
- package/src/index.ts +25 -3
- package/src/mcp/brief.ts +191 -0
- package/src/mcp/prompts.ts +33 -0
- package/src/mcp/read.ts +29 -1
- package/src/mcp/tools.ts +40 -1
- package/src/mcp/write.ts +41 -1
- package/src/server/extension-routes.ts +73 -0
- package/src/server/font-routes.ts +301 -0
- package/src/server/plugin.ts +9 -0
package/src/core/render/form.ts
CHANGED
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
type PublicFormDefinition,
|
|
6
6
|
type PublicFormField,
|
|
7
7
|
} from "../forms/definition.ts";
|
|
8
|
-
import type { FormNode, LayoutNode } from "../schema/layout.ts";
|
|
8
|
+
import type { FormNode, LayoutNode, TextInputNode } from "../schema/layout.ts";
|
|
9
|
+
import { typedInputAttrs } from "../elements/input-limits.ts";
|
|
9
10
|
import { selectPrompt } from "../elements/select-prompt.ts";
|
|
10
11
|
import type { ThemeDynamicData } from "../theme/dynamic.ts";
|
|
11
12
|
import { nodeChildren } from "../tree-ops.ts";
|
|
@@ -98,13 +99,15 @@ export function renderForm(
|
|
|
98
99
|
"Submit";
|
|
99
100
|
const previousForm = ctx.formId;
|
|
100
101
|
ctx.formId = formId;
|
|
101
|
-
const
|
|
102
|
-
ctx.formId = previousForm;
|
|
102
|
+
const stepped = node.children.some((child) => child.type === "form-step");
|
|
103
103
|
const page: VNode = {
|
|
104
104
|
tag: "div",
|
|
105
105
|
attrs: { "data-page": "0" },
|
|
106
|
-
children:
|
|
106
|
+
children: stepped ? [] : ctx.children(node.children, dynamic),
|
|
107
107
|
};
|
|
108
|
+
// W-1065: a form with steps has a page per step instead of one around everything.
|
|
109
|
+
const pages = stepped ? steppedChildren(node, ctx, dynamic) : [page];
|
|
110
|
+
ctx.formId = previousForm;
|
|
108
111
|
return {
|
|
109
112
|
tag: "form",
|
|
110
113
|
attrs: {
|
|
@@ -120,7 +123,7 @@ export function renderForm(
|
|
|
120
123
|
"data-submit-label": submitLabel,
|
|
121
124
|
},
|
|
122
125
|
children: [
|
|
123
|
-
|
|
126
|
+
...pages,
|
|
124
127
|
{ tag: "input", attrs: { type: "hidden", name: "formId", value: formId }, children: [] },
|
|
125
128
|
...hiddenFields(ctx.definitions.get(formId)),
|
|
126
129
|
// One id per form element, so the same form placed twice keeps unique ids (W-187), also
|
|
@@ -135,6 +138,85 @@ export function renderForm(
|
|
|
135
138
|
};
|
|
136
139
|
}
|
|
137
140
|
|
|
141
|
+
/** W-1065: what the Next and Previous buttons say when the form element doesn't set it. */
|
|
142
|
+
const FORM_STEP_LABELS = { next: "Next", prev: "Previous" } as const;
|
|
143
|
+
|
|
144
|
+
const stepLabel = (value: string | undefined, fallback: string) => value?.trim() || fallback;
|
|
145
|
+
|
|
146
|
+
/** A Previous or Next button, hidden until the forms script shows it. */
|
|
147
|
+
const stepButton = (data: string, text: string, cls: string): VNode => ({
|
|
148
|
+
tag: "button",
|
|
149
|
+
attrs: { type: "button", class: cls, [data]: "", hidden: "" },
|
|
150
|
+
children: [text],
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* W-1065: a form with steps, in the forms plugin's multi-page markup. Each step is a page
|
|
155
|
+
* (`data-page`, in order); the plugin's script shows one at a time, checks a page's fields before
|
|
156
|
+
* Next, and writes "Step 2 of 3" into `data-ec-progress`. Its Previous and Next buttons are
|
|
157
|
+
* hidden until the script shows them, so without it every step shows, as one long form, and the
|
|
158
|
+
* Submit button sends it. Anything outside the steps (an intro, the Submit button) stays put.
|
|
159
|
+
*/
|
|
160
|
+
function steppedChildren(
|
|
161
|
+
node: FormNode,
|
|
162
|
+
ctx: RenderContext,
|
|
163
|
+
dynamic: ThemeDynamicData | undefined,
|
|
164
|
+
): VNode[] {
|
|
165
|
+
const out: VNode[] = [];
|
|
166
|
+
let page = 0;
|
|
167
|
+
let lastStep = -1;
|
|
168
|
+
for (const child of node.children) {
|
|
169
|
+
for (const vnode of ctx.children([child], dynamic)) {
|
|
170
|
+
if (child.type !== "form-step") {
|
|
171
|
+
out.push(vnode);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const titled = vnode.children.some(
|
|
175
|
+
(part) => typeof part !== "string" && part.tag === "legend",
|
|
176
|
+
);
|
|
177
|
+
out.push({
|
|
178
|
+
...vnode,
|
|
179
|
+
attrs: {
|
|
180
|
+
...vnode.attrs,
|
|
181
|
+
class: `${vnode.attrs.class ?? ""} ec-form-page`.trim(),
|
|
182
|
+
"data-page": String(page),
|
|
183
|
+
// The forms script moves focus here when the step opens (astro/forms/enhance.ts).
|
|
184
|
+
tabindex: "-1",
|
|
185
|
+
...(titled ? {} : { "aria-label": `Step ${page + 1}` }),
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
page += 1;
|
|
189
|
+
lastStep = out.length - 1;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (lastStep === -1) return out;
|
|
193
|
+
const nav: VNode = {
|
|
194
|
+
tag: "div",
|
|
195
|
+
attrs: { class: "emvb-form-step-nav" },
|
|
196
|
+
children: [
|
|
197
|
+
stepButton(
|
|
198
|
+
"data-ec-prev",
|
|
199
|
+
stepLabel(node.props.prevLabel, FORM_STEP_LABELS.prev),
|
|
200
|
+
"emvb-form-step-prev",
|
|
201
|
+
),
|
|
202
|
+
stepButton(
|
|
203
|
+
"data-ec-next",
|
|
204
|
+
stepLabel(node.props.nextLabel, FORM_STEP_LABELS.next),
|
|
205
|
+
"emvb-form-step-next",
|
|
206
|
+
),
|
|
207
|
+
],
|
|
208
|
+
};
|
|
209
|
+
const progress: VNode = {
|
|
210
|
+
tag: "p",
|
|
211
|
+
attrs: { class: "emvb-form-step-progress", "data-ec-progress": "", "aria-live": "polite" },
|
|
212
|
+
children: [],
|
|
213
|
+
};
|
|
214
|
+
const first = out.findIndex((vnode) => vnode.attrs["data-page"] === "0");
|
|
215
|
+
out.splice(lastStep + 1, 0, nav);
|
|
216
|
+
out.splice(first, 0, progress);
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
|
|
138
220
|
/**
|
|
139
221
|
* W-595: the definition's hidden fields (a source tag, a campaign id) have no control to place,
|
|
140
222
|
* so the form carries them with their default value, as the forms plugin's own embed does.
|
|
@@ -352,7 +434,15 @@ function lengthLimit(value: unknown, round: (n: number) => number): string | und
|
|
|
352
434
|
* the label. Without them the forms client found nothing to check before sending.
|
|
353
435
|
*/
|
|
354
436
|
function withFieldMeta(vnode: VNode, node: LayoutNode, meta: PublicFormField): VNode {
|
|
355
|
-
const
|
|
437
|
+
const own = node.type === "text-input" ? (node as TextInputNode).props : undefined;
|
|
438
|
+
// W-1065: a plain text field may be asked for as a number or a date; the forms plugin takes
|
|
439
|
+
// either as text. A field with its own type (email, number, date) keeps it.
|
|
440
|
+
const type =
|
|
441
|
+
node.type === "text-input" && INPUT_TYPES.has(meta.type)
|
|
442
|
+
? meta.type
|
|
443
|
+
: meta.type === "text"
|
|
444
|
+
? own?.inputType
|
|
445
|
+
: undefined;
|
|
356
446
|
const rules = meta.validation ?? {};
|
|
357
447
|
const kind = type ?? (node.type === "textarea" ? "textarea" : meta.type);
|
|
358
448
|
const limits: Record<string, string> = {};
|
|
@@ -365,11 +455,12 @@ function withFieldMeta(vnode: VNode, node: LayoutNode, meta: PublicFormField): V
|
|
|
365
455
|
if (lo !== undefined) limits.minlength = lo;
|
|
366
456
|
if (hi !== undefined) limits.maxlength = hi;
|
|
367
457
|
}
|
|
368
|
-
if (kind === "number") {
|
|
458
|
+
if (own && (kind === "number" || kind === "date")) {
|
|
459
|
+
// W-578: unless the element sets a step, a number takes decimals, as the forms plugin does.
|
|
460
|
+
Object.assign(limits, typedInputAttrs(kind, own, kind === "number" ? rules : {}));
|
|
461
|
+
} else if (kind === "number") {
|
|
369
462
|
if (rules.min !== undefined) limits.min = String(rules.min);
|
|
370
463
|
if (rules.max !== undefined) limits.max = String(rules.max);
|
|
371
|
-
// W-578: the forms plugin accepts any number; the browser's default step of 1 refused
|
|
372
|
-
// decimals (and, counted from a fractional min, every whole number).
|
|
373
464
|
limits.step = "any";
|
|
374
465
|
}
|
|
375
466
|
if (node.type === "text-input" && kind !== "number" && kind !== "date" && rules.pattern) {
|
|
@@ -384,10 +475,12 @@ function withFieldMeta(vnode: VNode, node: LayoutNode, meta: PublicFormField): V
|
|
|
384
475
|
};
|
|
385
476
|
return mapNodes(vnode, (child) => {
|
|
386
477
|
if (isControl(child)) {
|
|
478
|
+
// The element's own number or date limits were for the type it asked for, not this one.
|
|
479
|
+
const { min: _min, max: _max, step: _step, ...rest } = child.attrs;
|
|
387
480
|
return {
|
|
388
481
|
...child,
|
|
389
482
|
attrs: {
|
|
390
|
-
...child.attrs,
|
|
483
|
+
...(own ? rest : child.attrs),
|
|
391
484
|
...(type ? { type } : {}),
|
|
392
485
|
...(meta.required ? { required: "" } : {}),
|
|
393
486
|
...limits,
|
package/src/core/render/index.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
scopeWrapperCss,
|
|
17
17
|
} from "../css/scope.ts";
|
|
18
18
|
import { ELEMENTS } from "../elements/index.ts";
|
|
19
|
-
import { nodeRuntime, type
|
|
19
|
+
import { nodeRuntime, type PageRuntime } from "../elements/widgets.ts";
|
|
20
20
|
import { hotspotPlace, shareLinkVNode } from "../elements/marketing.ts";
|
|
21
21
|
import { controlId } from "../elements/field-id.ts";
|
|
22
22
|
import { layoutHasForm } from "../forms/binding.ts";
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
cssTypeName,
|
|
34
34
|
type Layout,
|
|
35
35
|
type LayoutNode,
|
|
36
|
+
type MenuItemNode,
|
|
36
37
|
type PaginationNode,
|
|
37
38
|
} from "../schema/layout.ts";
|
|
38
39
|
import {
|
|
@@ -56,13 +57,20 @@ import { isDynamicPostNode, renderDynamicPost } from "./dynamic-post.ts";
|
|
|
56
57
|
import { renderForm, withFieldOptions } from "./form.ts";
|
|
57
58
|
import { renderLoop } from "./loop.ts";
|
|
58
59
|
import { renderPagination } from "./pagination.ts";
|
|
59
|
-
import {
|
|
60
|
+
import { pushSpacerBasis } from "./spacer-basis.ts";
|
|
61
|
+
import { renderPanelPart, renderSection } from "./section.ts";
|
|
62
|
+
import { buildMenuItem, MEGA_MENU_CSS, megaPanelPartId } from "../elements/menu.ts";
|
|
60
63
|
import { renderTabs } from "./tabs.ts";
|
|
64
|
+
import { designHasDark, THEME_BOOT_SCRIPT } from "./theme-boot.ts";
|
|
61
65
|
import { serialize, type VNode } from "./vnode.ts";
|
|
62
66
|
import {
|
|
67
|
+
extensionAssets,
|
|
68
|
+
extensionClassesOf,
|
|
69
|
+
extensionStylesheets,
|
|
63
70
|
isExtensionType,
|
|
64
71
|
renderExtensionNode,
|
|
65
72
|
EXTENSION_PLACEHOLDER_CSS,
|
|
73
|
+
type ExtensionOutputs,
|
|
66
74
|
} from "../extensions/index.ts";
|
|
67
75
|
import { classStylesInListOrder, resolveCascade } from "../design/cascade.ts";
|
|
68
76
|
import { applyBindings, hasBindings, type BindingData } from "../data/bindings.ts";
|
|
@@ -93,12 +101,17 @@ export type RenderResult = {
|
|
|
93
101
|
* W-1025: the opt-in widget scripts the page's elements asked for, sorted; empty for most
|
|
94
102
|
* pages. `EmVBPage` loads them; a theme part's go to `EmVBWidgetRuntimes`.
|
|
95
103
|
*/
|
|
96
|
-
runtimes:
|
|
104
|
+
runtimes: PageRuntime[];
|
|
97
105
|
/** The site's text direction when set in Site styles, for the host's `<html dir>` (W-230). */
|
|
98
106
|
dir?: "ltr" | "rtl" | "auto";
|
|
99
107
|
warnings: RenderWarning[];
|
|
100
108
|
/** W-971: the element types whose base rules this sheet holds (see `sharedPartCss`). */
|
|
101
109
|
baseTypes: string[];
|
|
110
|
+
/**
|
|
111
|
+
* W-1086: the extensions whose elements rendered, sorted. With `separateExtensionCss` their
|
|
112
|
+
* stylesheets are not in `css`; write `extensionStylesheets(ids)` once per document instead.
|
|
113
|
+
*/
|
|
114
|
+
extensions: string[];
|
|
102
115
|
};
|
|
103
116
|
|
|
104
117
|
const ID = /^[A-Za-z0-9_-]{4,24}$/;
|
|
@@ -196,7 +209,14 @@ function originHash(origin: string): string {
|
|
|
196
209
|
/** Form fields whose control carries an `emvb-field-<id>` HTML id (W-187). */
|
|
197
210
|
const FIELD_TYPES = new Set<string>(FORM_FIELD_TYPES.filter((type) => type !== "submit"));
|
|
198
211
|
|
|
199
|
-
const ID_ATTRS = [
|
|
212
|
+
const ID_ATTRS = [
|
|
213
|
+
"id",
|
|
214
|
+
"for",
|
|
215
|
+
"aria-controls",
|
|
216
|
+
"aria-labelledby",
|
|
217
|
+
"aria-describedby",
|
|
218
|
+
"popovertarget",
|
|
219
|
+
] as const;
|
|
200
220
|
|
|
201
221
|
/** Rewrites `base` (or `base-…`) to `next` in the id and id-reference attributes of a subtree. */
|
|
202
222
|
function renameIds(vnode: VNode, base: string, next: string): VNode {
|
|
@@ -226,6 +246,46 @@ const MAX_SECTION_ELEMENTS = 20 * MAX_NODES;
|
|
|
226
246
|
const baseCss = new Map(Object.entries(ELEMENTS).map(([type, def]) => [type, def.baseCss]));
|
|
227
247
|
// W-927: placeholder + wrapper styles ship with every page that may hold an extension node.
|
|
228
248
|
baseCss.set("ext", EXTENSION_PLACEHOLDER_CSS);
|
|
249
|
+
// W-1069: mega panel rules, only with a page that renders a mega panel.
|
|
250
|
+
baseCss.set("menu-mega", MEGA_MENU_CSS);
|
|
251
|
+
|
|
252
|
+
type StickyStyle =
|
|
253
|
+
| { motion?: { sticky?: { hide?: unknown } }; stickyMotion?: { hide?: unknown } }
|
|
254
|
+
| undefined;
|
|
255
|
+
|
|
256
|
+
/** W-1070: a style's "Hide while scrolling down" (`motion.sticky`, or flat `stickyMotion`). */
|
|
257
|
+
const stickyHide = (style: StickyStyle): boolean =>
|
|
258
|
+
(style?.stickyMotion ?? style?.motion?.sticky)?.hide === true;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* W-1070: the element asks to slide away while the page scrolls down, on Desktop or any other
|
|
262
|
+
* device. The CSS says at which widths (`--emvb-sticky-hide`); the sticky script reads it.
|
|
263
|
+
*/
|
|
264
|
+
function hidesOnScroll(node: LayoutNode): boolean {
|
|
265
|
+
const devices = (node as { devices?: Record<string, StickyStyle> }).devices;
|
|
266
|
+
return [node.style as StickyStyle, ...Object.values(devices ?? {})].some(stickyHide);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* W-1078: a Menu's dropdowns share a `<details name>` group, so one opens at a time. The name was
|
|
271
|
+
* the menu's id, so the same menu twice (a synced header menu repeated in the footer) shared one
|
|
272
|
+
* group and opening a dropdown in one copy closed the other's. Each copy gets its own names.
|
|
273
|
+
*/
|
|
274
|
+
function uniqueMenuGroups(menu: VNode, uniqueId: (base: string) => string): VNode {
|
|
275
|
+
const renamed = new Map<string, string>();
|
|
276
|
+
const walk = (vnode: VNode): VNode => {
|
|
277
|
+
const name = vnode.tag === "details" ? vnode.attrs["name"] : undefined;
|
|
278
|
+
let attrs = vnode.attrs;
|
|
279
|
+
if (name?.startsWith("emvb-menu-")) {
|
|
280
|
+
const unique = renamed.get(name) ?? uniqueId(name);
|
|
281
|
+
renamed.set(name, unique);
|
|
282
|
+
attrs = { ...attrs, name: unique };
|
|
283
|
+
}
|
|
284
|
+
const children = vnode.children.map((c) => (typeof c === "string" ? c : walk(c)));
|
|
285
|
+
return { ...vnode, attrs, children };
|
|
286
|
+
};
|
|
287
|
+
return walk(menu);
|
|
288
|
+
}
|
|
229
289
|
|
|
230
290
|
/**
|
|
231
291
|
* W-971: theme parts on one page (header, footer, popups, floats) each repeated the scope wrapper
|
|
@@ -280,6 +340,17 @@ export function renderPage(
|
|
|
280
340
|
partIds?: boolean;
|
|
281
341
|
/** The page's language, e.g. "fr-CA": Post Dates are written in it (W-688). */
|
|
282
342
|
lang?: string;
|
|
343
|
+
/**
|
|
344
|
+
* W-1086: extension outputs the server rendered, for the admin, which has no extension code
|
|
345
|
+
* (the editor canvas and the HTML export). The server renders with the live extensions.
|
|
346
|
+
*/
|
|
347
|
+
extensionOutputs?: ExtensionOutputs;
|
|
348
|
+
/**
|
|
349
|
+
* W-1086: leave the extensions' stylesheets out of `css`. Callers that put several renders in
|
|
350
|
+
* one document (a page and its theme parts, an export page) write each stylesheet once from
|
|
351
|
+
* `extensions`.
|
|
352
|
+
*/
|
|
353
|
+
separateExtensionCss?: boolean;
|
|
283
354
|
} = {},
|
|
284
355
|
): RenderResult {
|
|
285
356
|
const mode = opts.mode ?? "public";
|
|
@@ -307,6 +378,7 @@ export function renderPage(
|
|
|
307
378
|
// W-799: each grid child's grid, so a span or start line that doesn't fit a device's columns
|
|
308
379
|
// can be clamped there.
|
|
309
380
|
const gridOf = new Map<string, LayoutNode>();
|
|
381
|
+
const parentOf = new WeakMap<LayoutNode, LayoutNode>();
|
|
310
382
|
someNode(layout.root, (current) => {
|
|
311
383
|
if (current.type === "grid")
|
|
312
384
|
for (const child of nodeChildren(current)) gridOf.set(child.id, current);
|
|
@@ -333,7 +405,9 @@ export function renderPage(
|
|
|
333
405
|
// W-253: runtimes follow what renders, including synced section and loop item contents,
|
|
334
406
|
// which the page's own layout doesn't hold.
|
|
335
407
|
const rendered = { form: false, tabs: false, menuDropdown: false };
|
|
336
|
-
const runtimes = new Set<
|
|
408
|
+
const runtimes = new Set<PageRuntime>();
|
|
409
|
+
// W-1086: the extensions whose elements rendered, for their stylesheet and runtime.
|
|
410
|
+
const extensionsUsed = new Set<string>();
|
|
337
411
|
let sectionBudget = MAX_SECTION_ELEMENTS;
|
|
338
412
|
const ctx: RenderContext = {
|
|
339
413
|
takeSectionBudget: (nodes) => {
|
|
@@ -370,6 +444,7 @@ export function renderPage(
|
|
|
370
444
|
id: string | undefined,
|
|
371
445
|
nodeId: string,
|
|
372
446
|
ruleId: string | undefined,
|
|
447
|
+
parent?: LayoutNode,
|
|
373
448
|
): Record<string, string> => {
|
|
374
449
|
const classes = [...(isRoot ? ["emvb-root"] : []), `emvb-${cssTypeName(node.type)}`];
|
|
375
450
|
for (const classId of node.classes ?? []) {
|
|
@@ -405,6 +480,11 @@ export function renderPage(
|
|
|
405
480
|
? (withInheritedLayers(node.style, classLayers) as typeof node.style)
|
|
406
481
|
: undefined;
|
|
407
482
|
const { declarations, rejected } = styleDeclarations(own);
|
|
483
|
+
// W-1070: hiding set on a narrower device only is off on Desktop (and the element doesn't
|
|
484
|
+
// take the value of a hiding box around it).
|
|
485
|
+
if (hidesOnScroll(node) && !declarations.some((d) => d.property === "--emvb-sticky-hide")) {
|
|
486
|
+
declarations.push({ property: "--emvb-sticky-hide", value: "0" });
|
|
487
|
+
}
|
|
408
488
|
// W-210: a device that sets one background layer keeps the layers it inherits.
|
|
409
489
|
const base = { ...classLayers, ...own };
|
|
410
490
|
// W-956: Laptop between Desktop and Tablet; each narrower device inherits the wider ones.
|
|
@@ -442,6 +522,11 @@ export function renderPage(
|
|
|
442
522
|
const width = props.fullWidth === true ? "none" : cssLength(props.contentWidth);
|
|
443
523
|
if (width) declarations.push({ property: "--emvb-content-width", value: width });
|
|
444
524
|
}
|
|
525
|
+
if (node.type === "menu-item") {
|
|
526
|
+
// W-1069: the Mega panel width, read by the panel's rules.
|
|
527
|
+
const width = cssLength((node as { props: { panelWidth?: unknown } }).props.panelWidth);
|
|
528
|
+
if (width) declarations.push({ property: "--emvb-menu-panel-width", value: width });
|
|
529
|
+
}
|
|
445
530
|
if (node.type === "loop") {
|
|
446
531
|
// W-308: grid and cards columns, as a custom property the Loop's base CSS reads.
|
|
447
532
|
const columns = (node as { props: { columns?: unknown } }).props.columns;
|
|
@@ -495,6 +580,15 @@ export function renderPage(
|
|
|
495
580
|
if (place.tablet.length > 0) tablet.declarations.unshift(...placeAt(place.tablet));
|
|
496
581
|
if (place.mobile.length > 0) mobile.declarations.unshift(...placeAt(place.mobile));
|
|
497
582
|
}
|
|
583
|
+
if (node.type === "spacer") {
|
|
584
|
+
pushSpacerBasis(node, parent, design.classes, {
|
|
585
|
+
desktop: declarations,
|
|
586
|
+
wide: wide.declarations,
|
|
587
|
+
laptop: laptop.declarations,
|
|
588
|
+
tablet: tablet.declarations,
|
|
589
|
+
mobile: mobile.declarations,
|
|
590
|
+
});
|
|
591
|
+
}
|
|
498
592
|
const queryStyle = node.query ? styleDeclarations(node.query.style) : undefined;
|
|
499
593
|
for (const key of queryStyle?.rejected ?? []) {
|
|
500
594
|
warnings.push({ nodeId, code: "rejected-style", detail: key });
|
|
@@ -610,7 +704,9 @@ export function renderPage(
|
|
|
610
704
|
node.htmlId && HTML_ID.test(node.htmlId) && !isShadowingId(node.htmlId)
|
|
611
705
|
? node.htmlId
|
|
612
706
|
: node.type === "heading" && id && layoutHasToc
|
|
613
|
-
?
|
|
707
|
+
? // W-1077: a theme part's anchors get its suffix, as its other generated ids do (W-527),
|
|
708
|
+
// so a header heading never takes the page's own heading's anchor.
|
|
709
|
+
`emvb-h-${id}${idSuffix}`
|
|
614
710
|
: undefined;
|
|
615
711
|
// W-649: a Loop renders its item design once per entry; an id repeated on the page is invalid
|
|
616
712
|
// and every Table of contents link or label would point at the first copy only.
|
|
@@ -642,10 +738,15 @@ export function renderPage(
|
|
|
642
738
|
// W-927: extension elements render via the Extensions API, or a placeholder when missing.
|
|
643
739
|
if (isExtensionType(type)) {
|
|
644
740
|
usedTypes.add("ext");
|
|
645
|
-
return renderExtensionNode(
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
741
|
+
return renderExtensionNode(
|
|
742
|
+
node,
|
|
743
|
+
mode === "editor" ? "editor" : "public",
|
|
744
|
+
(nodes) =>
|
|
745
|
+
nodes
|
|
746
|
+
.map((child) => visit(child, false, dynamic))
|
|
747
|
+
.filter((child): child is VNode => child !== undefined),
|
|
748
|
+
opts.extensionOutputs,
|
|
749
|
+
(pkg) => extensionsUsed.add(pkg),
|
|
649
750
|
);
|
|
650
751
|
}
|
|
651
752
|
warnings.push({ nodeId, code: "unknown-type", detail: type });
|
|
@@ -663,7 +764,20 @@ export function renderPage(
|
|
|
663
764
|
const runtime = nodeRuntime(node as LayoutNode);
|
|
664
765
|
if (runtime) runtimes.add(runtime);
|
|
665
766
|
const ruleId = id === undefined ? undefined : ruleIdFor(id, dynamic?.idOrigin ?? "");
|
|
666
|
-
|
|
767
|
+
// W-1062: a Spacer's size follows its parent's direction.
|
|
768
|
+
for (const child of nodeChildren(node)) parentOf.set(child, node);
|
|
769
|
+
const attrs = nodeAttrs(node, isRoot, id, nodeId, ruleId, parentOf.get(stored));
|
|
770
|
+
// W-1086: allowlisted classes an extension's render() put on its output node.
|
|
771
|
+
const extClasses = extensionClassesOf(stored);
|
|
772
|
+
if (extClasses) attrs.class = [attrs.class, ...extClasses].filter(Boolean).join(" ");
|
|
773
|
+
// W-1070: hides on scroll down with the opt-in sticky script (any element type).
|
|
774
|
+
if (hidesOnScroll(node as LayoutNode)) {
|
|
775
|
+
attrs["data-emvb-sticky-hide"] = "";
|
|
776
|
+
runtimes.add("sticky");
|
|
777
|
+
}
|
|
778
|
+
// W-1067: the canvas runs no widget scripts, so a Theme toggle waiting for its own stayed
|
|
779
|
+
// hidden there; the editor shows it as it looks once ready.
|
|
780
|
+
if (mode === "editor" && type === "theme-toggle") attrs["data-emvb-ready"] = "";
|
|
667
781
|
if (mode === "editor" && hasBindings(stored)) attrs["data-emvb-bound"] = "";
|
|
668
782
|
if (mode === "editor" && stored.audience) {
|
|
669
783
|
attrs["data-emvb-audience"] = audienceSummary(stored.audience);
|
|
@@ -729,8 +843,19 @@ export function renderPage(
|
|
|
729
843
|
});
|
|
730
844
|
}
|
|
731
845
|
}
|
|
846
|
+
const panelPartId = megaPanelPartId(node);
|
|
847
|
+
if (panelPartId) {
|
|
848
|
+
// W-1069: a mega menu item; a missing, looping or refused part leaves the item's own children.
|
|
849
|
+
const mega = renderPanelPart(panelPartId, ctx, dynamic);
|
|
850
|
+
if (mega) {
|
|
851
|
+
usedTypes.add("menu-mega");
|
|
852
|
+
rendered.menuDropdown = true;
|
|
853
|
+
return finish(node, buildMenuItem(node as MenuItemNode, attrs, [], mega));
|
|
854
|
+
}
|
|
855
|
+
}
|
|
732
856
|
if (isParentNode(node)) {
|
|
733
|
-
|
|
857
|
+
const built = def.build(node as never, attrs, ctx.children(node.children, dynamic));
|
|
858
|
+
return finish(node, node.type === "menu" ? uniqueMenuGroups(built, ctx.uniqueId) : built);
|
|
734
859
|
}
|
|
735
860
|
if (mode === "editor" && node.type === "video") {
|
|
736
861
|
const preview = videoPreview(node, attrs);
|
|
@@ -742,7 +867,11 @@ export function renderPage(
|
|
|
742
867
|
ctx.definitions,
|
|
743
868
|
ctx.formId,
|
|
744
869
|
);
|
|
745
|
-
|
|
870
|
+
if (FIELD_TYPES.has(type) && id) return finish(node, uniqueField(built, controlId(id)));
|
|
871
|
+
// W-1077: a Hotspot's note is a popover found by id; a header, footer or popup copy, or a
|
|
872
|
+
// repeat, gets its own id, as form fields and Tabs do.
|
|
873
|
+
if (type === "hotspot" && id) return finish(node, uniqueField(built, `emvb-hotspot-${id}`));
|
|
874
|
+
return finish(node, built);
|
|
746
875
|
}
|
|
747
876
|
|
|
748
877
|
/** W-249: a field rendered again (synced section, loop item) moves its control to a new id. */
|
|
@@ -817,10 +946,16 @@ export function renderPage(
|
|
|
817
946
|
detail: error.message,
|
|
818
947
|
}),
|
|
819
948
|
});
|
|
949
|
+
// W-1086: each extension stylesheet once, unscoped (it styles its own prefixed classes), before
|
|
950
|
+
// the print rules so the theme parts' shared sheet still finds them at the end.
|
|
951
|
+
const extensions = [...extensionsUsed].toSorted();
|
|
952
|
+
for (const pkg of extensions) if (extensionAssets(pkg)?.runtime) runtimes.add(`ext:${pkg}`);
|
|
953
|
+
const extensionCss = opts.separateExtensionCss ? "" : extensionStylesheets(extensions);
|
|
820
954
|
return {
|
|
821
955
|
vnode,
|
|
822
|
-
|
|
823
|
-
|
|
956
|
+
// W-1067: a public page of a site with dark colours puts back the visitor's choice first.
|
|
957
|
+
html: mode === "public" && designHasDark(design) ? THEME_BOOT_SCRIPT + html : html,
|
|
958
|
+
css: (scope ? scopeWrapperCss() + scopeCss(css, scope) : css) + extensionCss + printCss(),
|
|
824
959
|
needsFormsRuntime: rendered.form || layoutHasForm(layout),
|
|
825
960
|
needsTabsRuntime: rendered.tabs || layoutHasTabs(layout),
|
|
826
961
|
needsMenuRuntime: rendered.menuDropdown || layoutHasMenuDropdown(layout),
|
|
@@ -828,6 +963,7 @@ export function renderPage(
|
|
|
828
963
|
...(design.direction ? { dir: design.direction } : {}),
|
|
829
964
|
warnings,
|
|
830
965
|
baseTypes: [...usedTypes],
|
|
966
|
+
extensions,
|
|
831
967
|
};
|
|
832
968
|
}
|
|
833
969
|
|
|
@@ -36,7 +36,9 @@ export function renderSection(
|
|
|
36
36
|
const partId = node.props.partId?.trim() ?? "";
|
|
37
37
|
const stack = dynamic?.sectionStack ?? [];
|
|
38
38
|
const template =
|
|
39
|
-
partId && dynamic?.sectionTemplates
|
|
39
|
+
partId && dynamic?.sectionTemplates && Object.hasOwn(dynamic.sectionTemplates, partId)
|
|
40
|
+
? dynamic.sectionTemplates[partId]
|
|
41
|
+
: undefined;
|
|
40
42
|
if (!partId) {
|
|
41
43
|
return ELEMENTS["part-ref"].build(node as never, attrs, ctx.children(node.children, dynamic));
|
|
42
44
|
}
|
|
@@ -62,3 +64,31 @@ export function renderSection(
|
|
|
62
64
|
};
|
|
63
65
|
return ELEMENTS["part-ref"].build(node as never, attrs, ctx.children(templateNodes, next));
|
|
64
66
|
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* W-1069: a mega menu item's panel, the Section part's elements rendered under the same guards as
|
|
70
|
+
* a synced section (the part stack against cycles, the depth limit, the render's budget).
|
|
71
|
+
* Undefined when the part is missing, refused or empty, so the item renders as it would without.
|
|
72
|
+
*/
|
|
73
|
+
export function renderPanelPart(
|
|
74
|
+
partId: string,
|
|
75
|
+
ctx: RenderContext,
|
|
76
|
+
dynamic: ThemeDynamicData | undefined,
|
|
77
|
+
): VNode[] | undefined {
|
|
78
|
+
const id = partId.trim();
|
|
79
|
+
const stack = dynamic?.sectionStack ?? [];
|
|
80
|
+
const templates = dynamic?.sectionTemplates;
|
|
81
|
+
// An own key only: a part id such as "constructor" must not reach Object.prototype.
|
|
82
|
+
const template = id && templates && Object.hasOwn(templates, id) ? templates[id] : undefined;
|
|
83
|
+
if (!template?.root || stack.includes(id) || stack.length >= MAX_SECTION_DEPTH) return undefined;
|
|
84
|
+
const nodes = template.root.children;
|
|
85
|
+
if (nodes.length === 0) return undefined;
|
|
86
|
+
if (ctx.takeSectionBudget && !ctx.takeSectionBudget(partSize(nodes))) return undefined;
|
|
87
|
+
const next: ThemeDynamicData = {
|
|
88
|
+
...dynamic,
|
|
89
|
+
sectionStack: [...stack, id],
|
|
90
|
+
idOrigin: `${dynamic?.idOrigin ?? ""}/s:${id}`,
|
|
91
|
+
};
|
|
92
|
+
const children = ctx.children(nodes, next);
|
|
93
|
+
return children.length > 0 ? children : undefined;
|
|
94
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Declaration } from "../sanitize/css.ts";
|
|
2
|
+
import type { DesignSystem } from "../schema/design.ts";
|
|
3
|
+
import type { LayoutNode } from "../schema/layout.ts";
|
|
4
|
+
|
|
5
|
+
type Level = "desktop" | "wide" | "laptop" | "tablet" | "mobile";
|
|
6
|
+
type Narrower = Exclude<Level, "desktop">;
|
|
7
|
+
|
|
8
|
+
/** The device styles each level reads on top of the desktop style (W-956, W-959). */
|
|
9
|
+
const CASCADE: Record<Level, readonly Narrower[]> = {
|
|
10
|
+
desktop: [],
|
|
11
|
+
wide: ["wide"],
|
|
12
|
+
laptop: ["laptop"],
|
|
13
|
+
tablet: ["laptop", "tablet"],
|
|
14
|
+
mobile: ["laptop", "tablet", "mobile"],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type Styled = {
|
|
18
|
+
style?: Record<string, unknown>;
|
|
19
|
+
devices?: Partial<Record<Narrower, Record<string, unknown> | undefined>>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function styleKeyAt(owner: Styled, level: Level, key: string): unknown {
|
|
23
|
+
let value = owner.style?.[key];
|
|
24
|
+
for (const device of CASCADE[level]) {
|
|
25
|
+
const own = owner.devices?.[device]?.[key];
|
|
26
|
+
if (own !== undefined) value = own;
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A node's style key at a device: its own styles win over its classes (later classes win). */
|
|
32
|
+
function cascadedKey(
|
|
33
|
+
node: LayoutNode,
|
|
34
|
+
classes: DesignSystem["classes"],
|
|
35
|
+
level: Level,
|
|
36
|
+
key: string,
|
|
37
|
+
): unknown {
|
|
38
|
+
const own = styleKeyAt(node as Styled, level, key);
|
|
39
|
+
if (own !== undefined) return own;
|
|
40
|
+
const applied = new Set(node.classes ?? []);
|
|
41
|
+
let fromClass: unknown;
|
|
42
|
+
for (const cls of classes ?? []) {
|
|
43
|
+
if (!applied.has(cls.id)) continue;
|
|
44
|
+
const value = styleKeyAt(cls as Styled, level, key);
|
|
45
|
+
if (value !== undefined) fromClass = value;
|
|
46
|
+
}
|
|
47
|
+
return fromClass;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const ROW_DIRECTIONS = new Set(["row", "row-reverse"]);
|
|
51
|
+
|
|
52
|
+
function lastValue(lists: readonly Declaration[][], property: string): string | undefined {
|
|
53
|
+
let value: string | undefined;
|
|
54
|
+
for (const list of lists) {
|
|
55
|
+
for (const d of list) if (d.property === property) value = d.value;
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* W-1062: in a flex row a Spacer's width is its flex-basis, so there it gets its height as the
|
|
62
|
+
* basis and makes a gap as wide as it is tall. Only where its parent lays out as a row at that
|
|
63
|
+
* device: in a column the basis is the height and would override a device's own height. Each
|
|
64
|
+
* device follows its own height, and the Spacer's own (or class) width or basis wins.
|
|
65
|
+
* Pushes onto the level lists after their own declarations.
|
|
66
|
+
*/
|
|
67
|
+
export function pushSpacerBasis(
|
|
68
|
+
spacer: LayoutNode,
|
|
69
|
+
parent: LayoutNode | undefined,
|
|
70
|
+
classes: DesignSystem["classes"],
|
|
71
|
+
lists: Record<Level, Declaration[]>,
|
|
72
|
+
): void {
|
|
73
|
+
if (!parent) return;
|
|
74
|
+
const parentRow = (level: Level) => {
|
|
75
|
+
const direction =
|
|
76
|
+
cascadedKey(parent, classes, level, "flexDirection") ??
|
|
77
|
+
(parent.type === "flexbox" ? "row" : undefined);
|
|
78
|
+
return typeof direction === "string" && ROW_DIRECTIONS.has(direction);
|
|
79
|
+
};
|
|
80
|
+
const sized = (level: Level) =>
|
|
81
|
+
cascadedKey(spacer, classes, level, "width") !== undefined ||
|
|
82
|
+
cascadedKey(spacer, classes, level, "flexBasis") !== undefined;
|
|
83
|
+
const chain = (level: Level) => [lists.desktop, ...CASCADE[level].map((d) => lists[d])];
|
|
84
|
+
const want = (level: Level) =>
|
|
85
|
+
parentRow(level) && !sized(level) ? lastValue(chain(level), "height") : undefined;
|
|
86
|
+
const ownBasis = (level: Narrower) => lists[level].some((d) => d.property === "flex-basis");
|
|
87
|
+
|
|
88
|
+
const desktop = want("desktop");
|
|
89
|
+
if (desktop) lists.desktop.push({ property: "flex-basis", value: desktop });
|
|
90
|
+
const wide = want("wide");
|
|
91
|
+
if (wide !== desktop && !ownBasis("wide")) {
|
|
92
|
+
lists.wide.push({ property: "flex-basis", value: wide ?? "auto" });
|
|
93
|
+
}
|
|
94
|
+
let previous = desktop;
|
|
95
|
+
for (const level of ["laptop", "tablet", "mobile"] as const) {
|
|
96
|
+
const value = want(level);
|
|
97
|
+
if (value !== previous && !ownBasis(level)) {
|
|
98
|
+
lists[level].push({ property: "flex-basis", value: value ?? "auto" });
|
|
99
|
+
}
|
|
100
|
+
previous = value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DesignSystem } from "../schema/design.ts";
|
|
2
|
+
|
|
3
|
+
/** W-1067: where a Theme toggle keeps the visitor's light or dark choice in this browser. */
|
|
4
|
+
export const THEME_STORAGE_KEY = "emvb-theme";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* W-1067: puts back a saved light or dark choice before the page is drawn. The opt-in Theme
|
|
8
|
+
* toggle script runs after the first paint and only on pages with a toggle, so a saved choice
|
|
9
|
+
* flashed the system's look first and was ignored on pages without one. Inline and constant, so
|
|
10
|
+
* a site with a Content Security Policy can allow it by its hash (docs/guides/widgets.md).
|
|
11
|
+
*/
|
|
12
|
+
export const THEME_BOOT_SCRIPT = `<script>try{var t=localStorage.getItem("${THEME_STORAGE_KEY}");if(t==="light"||t==="dark")document.documentElement.setAttribute("data-emvb-theme",t)}catch(e){}</script>`;
|
|
13
|
+
|
|
14
|
+
/** Whether the design has any dark colour value, and so a light or dark choice to put back. */
|
|
15
|
+
export const designHasDark = (design: DesignSystem): boolean =>
|
|
16
|
+
(design.variables?.colors ?? []).some((color) => typeof color.dark === "string");
|
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|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|mask|method|action|name|value|placeholder|for|tabindex|autocomplete|open|popover|popovertarget|popovertargetaction|datetime|muted|loop|playsinline|autoplay|required|novalidate|minlength|maxlength|min|max|pattern|step|start|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|mask|method|action|name|value|placeholder|for|tabindex|autocomplete|open|popover|popovertarget|popovertargetaction|datetime|muted|loop|playsinline|autoplay|required|novalidate|hidden|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);
|