@perkyzz/emvb 1.3.0 → 1.4.1
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/content-item.ts +3 -0
- package/src/admin/copy-rich-text.ts +99 -9
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +28 -3
- 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/collection-previews.ts +7 -8
- 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/extensions/ExtensionPanels.tsx +33 -1
- package/src/admin/editor/extensions-context.tsx +16 -1
- package/src/admin/editor/feature-css.ts +27 -0
- package/src/admin/editor/inert-links.ts +8 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ConditionsEditor.tsx +18 -0
- package/src/admin/editor/panels/ElementPanel.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 +33 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +27 -31
- package/src/admin/editor/panels/settings/ImageFieldControl.tsx +106 -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/loop-context.ts +34 -3
- 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 +27 -2
- package/src/admin/extension-outputs.ts +236 -0
- package/src/admin/font-files-api.ts +38 -0
- package/src/admin/import-forms.ts +133 -0
- package/src/admin/pages/ImportButton.tsx +15 -4
- package/src/admin/pages/ImportElementorDialog.tsx +53 -187
- package/src/admin/pages/ImportForms.tsx +71 -0
- 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/admin/setup/plan.ts +2 -0
- package/src/admin/ui.ts +7 -0
- package/src/admin/widgets/ConvertToRichText.tsx +3 -2
- 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 +25 -4
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/resolve.ts +2 -0
- package/src/astro/theme-posts.ts +17 -23
- package/src/astro/visitor.ts +14 -5
- 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 +41 -2
- package/src/core/css/trace.ts +8 -0
- package/src/core/data/bindings.ts +7 -4
- package/src/core/elements/dynamic-elements.ts +1 -1
- package/src/core/elements/element-nouns.ts +48 -0
- 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 +53 -4
- package/src/core/extensions/classes.ts +114 -0
- package/src/core/extensions/index.ts +19 -2
- package/src/core/extensions/normalize.ts +13 -0
- package/src/core/extensions/placeholder.ts +7 -2
- package/src/core/extensions/registry.ts +134 -10
- package/src/core/extensions/render-ext.ts +115 -36
- 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 +42 -4
- package/src/core/import/elementor/index.ts +55 -23
- package/src/core/import/elementor/widgets.ts +242 -20
- 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 +54 -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 +165 -16
- 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 +118 -6
- 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/media-value.ts +88 -0
- 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/core/visitor-cookie.ts +91 -0
- package/src/extension-build.ts +331 -0
- package/src/index.ts +53 -4
- package/src/mcp/agent-defaults.ts +40 -0
- package/src/mcp/brief.ts +191 -0
- package/src/mcp/extensions.ts +138 -0
- package/src/mcp/prompts.ts +33 -0
- package/src/mcp/read.ts +84 -20
- package/src/mcp/tools.ts +42 -3
- package/src/mcp/write.ts +124 -9
- package/src/server/extension-routes.ts +110 -0
- package/src/server/font-routes.ts +301 -0
- package/src/server/plugin.ts +15 -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,21 @@ 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,
|
|
72
|
+
isExtensionPlaceholder,
|
|
65
73
|
EXTENSION_PLACEHOLDER_CSS,
|
|
74
|
+
type ExtensionOutputs,
|
|
66
75
|
} from "../extensions/index.ts";
|
|
67
76
|
import { classStylesInListOrder, resolveCascade } from "../design/cascade.ts";
|
|
68
77
|
import { applyBindings, hasBindings, type BindingData } from "../data/bindings.ts";
|
|
@@ -93,12 +102,17 @@ export type RenderResult = {
|
|
|
93
102
|
* W-1025: the opt-in widget scripts the page's elements asked for, sorted; empty for most
|
|
94
103
|
* pages. `EmVBPage` loads them; a theme part's go to `EmVBWidgetRuntimes`.
|
|
95
104
|
*/
|
|
96
|
-
runtimes:
|
|
105
|
+
runtimes: PageRuntime[];
|
|
97
106
|
/** The site's text direction when set in Site styles, for the host's `<html dir>` (W-230). */
|
|
98
107
|
dir?: "ltr" | "rtl" | "auto";
|
|
99
108
|
warnings: RenderWarning[];
|
|
100
109
|
/** W-971: the element types whose base rules this sheet holds (see `sharedPartCss`). */
|
|
101
110
|
baseTypes: string[];
|
|
111
|
+
/**
|
|
112
|
+
* W-1086: the extensions whose elements rendered, sorted. With `separateExtensionCss` their
|
|
113
|
+
* stylesheets are not in `css`; write `extensionStylesheets(ids)` once per document instead.
|
|
114
|
+
*/
|
|
115
|
+
extensions: string[];
|
|
102
116
|
};
|
|
103
117
|
|
|
104
118
|
const ID = /^[A-Za-z0-9_-]{4,24}$/;
|
|
@@ -196,7 +210,14 @@ function originHash(origin: string): string {
|
|
|
196
210
|
/** Form fields whose control carries an `emvb-field-<id>` HTML id (W-187). */
|
|
197
211
|
const FIELD_TYPES = new Set<string>(FORM_FIELD_TYPES.filter((type) => type !== "submit"));
|
|
198
212
|
|
|
199
|
-
const ID_ATTRS = [
|
|
213
|
+
const ID_ATTRS = [
|
|
214
|
+
"id",
|
|
215
|
+
"for",
|
|
216
|
+
"aria-controls",
|
|
217
|
+
"aria-labelledby",
|
|
218
|
+
"aria-describedby",
|
|
219
|
+
"popovertarget",
|
|
220
|
+
] as const;
|
|
200
221
|
|
|
201
222
|
/** Rewrites `base` (or `base-…`) to `next` in the id and id-reference attributes of a subtree. */
|
|
202
223
|
function renameIds(vnode: VNode, base: string, next: string): VNode {
|
|
@@ -226,6 +247,46 @@ const MAX_SECTION_ELEMENTS = 20 * MAX_NODES;
|
|
|
226
247
|
const baseCss = new Map(Object.entries(ELEMENTS).map(([type, def]) => [type, def.baseCss]));
|
|
227
248
|
// W-927: placeholder + wrapper styles ship with every page that may hold an extension node.
|
|
228
249
|
baseCss.set("ext", EXTENSION_PLACEHOLDER_CSS);
|
|
250
|
+
// W-1069: mega panel rules, only with a page that renders a mega panel.
|
|
251
|
+
baseCss.set("menu-mega", MEGA_MENU_CSS);
|
|
252
|
+
|
|
253
|
+
type StickyStyle =
|
|
254
|
+
| { motion?: { sticky?: { hide?: unknown } }; stickyMotion?: { hide?: unknown } }
|
|
255
|
+
| undefined;
|
|
256
|
+
|
|
257
|
+
/** W-1070: a style's "Hide while scrolling down" (`motion.sticky`, or flat `stickyMotion`). */
|
|
258
|
+
const stickyHide = (style: StickyStyle): boolean =>
|
|
259
|
+
(style?.stickyMotion ?? style?.motion?.sticky)?.hide === true;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* W-1070: the element asks to slide away while the page scrolls down, on Desktop or any other
|
|
263
|
+
* device. The CSS says at which widths (`--emvb-sticky-hide`); the sticky script reads it.
|
|
264
|
+
*/
|
|
265
|
+
function hidesOnScroll(node: LayoutNode): boolean {
|
|
266
|
+
const devices = (node as { devices?: Record<string, StickyStyle> }).devices;
|
|
267
|
+
return [node.style as StickyStyle, ...Object.values(devices ?? {})].some(stickyHide);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* W-1078: a Menu's dropdowns share a `<details name>` group, so one opens at a time. The name was
|
|
272
|
+
* the menu's id, so the same menu twice (a synced header menu repeated in the footer) shared one
|
|
273
|
+
* group and opening a dropdown in one copy closed the other's. Each copy gets its own names.
|
|
274
|
+
*/
|
|
275
|
+
function uniqueMenuGroups(menu: VNode, uniqueId: (base: string) => string): VNode {
|
|
276
|
+
const renamed = new Map<string, string>();
|
|
277
|
+
const walk = (vnode: VNode): VNode => {
|
|
278
|
+
const name = vnode.tag === "details" ? vnode.attrs["name"] : undefined;
|
|
279
|
+
let attrs = vnode.attrs;
|
|
280
|
+
if (name?.startsWith("emvb-menu-")) {
|
|
281
|
+
const unique = renamed.get(name) ?? uniqueId(name);
|
|
282
|
+
renamed.set(name, unique);
|
|
283
|
+
attrs = { ...attrs, name: unique };
|
|
284
|
+
}
|
|
285
|
+
const children = vnode.children.map((c) => (typeof c === "string" ? c : walk(c)));
|
|
286
|
+
return { ...vnode, attrs, children };
|
|
287
|
+
};
|
|
288
|
+
return walk(menu);
|
|
289
|
+
}
|
|
229
290
|
|
|
230
291
|
/**
|
|
231
292
|
* W-971: theme parts on one page (header, footer, popups, floats) each repeated the scope wrapper
|
|
@@ -280,6 +341,23 @@ export function renderPage(
|
|
|
280
341
|
partIds?: boolean;
|
|
281
342
|
/** The page's language, e.g. "fr-CA": Post Dates are written in it (W-688). */
|
|
282
343
|
lang?: string;
|
|
344
|
+
/**
|
|
345
|
+
* W-1086: extension outputs the server rendered, for the admin, which has no extension code
|
|
346
|
+
* (the editor canvas and the HTML export). The server renders with the live extensions.
|
|
347
|
+
*/
|
|
348
|
+
extensionOutputs?: ExtensionOutputs;
|
|
349
|
+
/**
|
|
350
|
+
* W-1086: leave the extensions' stylesheets out of `css`. Callers that put several renders in
|
|
351
|
+
* one document (a page and its theme parts, an export page) write each stylesheet once from
|
|
352
|
+
* `extensions`.
|
|
353
|
+
*/
|
|
354
|
+
separateExtensionCss?: boolean;
|
|
355
|
+
/**
|
|
356
|
+
* W-1088 (#37): public renders show the placeholder for an extension element that can't
|
|
357
|
+
* render (missing, throwing or illegal output). For the admin's previews of the public page;
|
|
358
|
+
* visitors get nothing in its place. The editor always shows it.
|
|
359
|
+
*/
|
|
360
|
+
extensionPlaceholders?: boolean;
|
|
283
361
|
} = {},
|
|
284
362
|
): RenderResult {
|
|
285
363
|
const mode = opts.mode ?? "public";
|
|
@@ -307,6 +385,7 @@ export function renderPage(
|
|
|
307
385
|
// W-799: each grid child's grid, so a span or start line that doesn't fit a device's columns
|
|
308
386
|
// can be clamped there.
|
|
309
387
|
const gridOf = new Map<string, LayoutNode>();
|
|
388
|
+
const parentOf = new WeakMap<LayoutNode, LayoutNode>();
|
|
310
389
|
someNode(layout.root, (current) => {
|
|
311
390
|
if (current.type === "grid")
|
|
312
391
|
for (const child of nodeChildren(current)) gridOf.set(child.id, current);
|
|
@@ -333,7 +412,9 @@ export function renderPage(
|
|
|
333
412
|
// W-253: runtimes follow what renders, including synced section and loop item contents,
|
|
334
413
|
// which the page's own layout doesn't hold.
|
|
335
414
|
const rendered = { form: false, tabs: false, menuDropdown: false };
|
|
336
|
-
const runtimes = new Set<
|
|
415
|
+
const runtimes = new Set<PageRuntime>();
|
|
416
|
+
// W-1086: the extensions whose elements rendered, for their stylesheet and runtime.
|
|
417
|
+
const extensionsUsed = new Set<string>();
|
|
337
418
|
let sectionBudget = MAX_SECTION_ELEMENTS;
|
|
338
419
|
const ctx: RenderContext = {
|
|
339
420
|
takeSectionBudget: (nodes) => {
|
|
@@ -370,6 +451,7 @@ export function renderPage(
|
|
|
370
451
|
id: string | undefined,
|
|
371
452
|
nodeId: string,
|
|
372
453
|
ruleId: string | undefined,
|
|
454
|
+
parent?: LayoutNode,
|
|
373
455
|
): Record<string, string> => {
|
|
374
456
|
const classes = [...(isRoot ? ["emvb-root"] : []), `emvb-${cssTypeName(node.type)}`];
|
|
375
457
|
for (const classId of node.classes ?? []) {
|
|
@@ -405,6 +487,11 @@ export function renderPage(
|
|
|
405
487
|
? (withInheritedLayers(node.style, classLayers) as typeof node.style)
|
|
406
488
|
: undefined;
|
|
407
489
|
const { declarations, rejected } = styleDeclarations(own);
|
|
490
|
+
// W-1070: hiding set on a narrower device only is off on Desktop (and the element doesn't
|
|
491
|
+
// take the value of a hiding box around it).
|
|
492
|
+
if (hidesOnScroll(node) && !declarations.some((d) => d.property === "--emvb-sticky-hide")) {
|
|
493
|
+
declarations.push({ property: "--emvb-sticky-hide", value: "0" });
|
|
494
|
+
}
|
|
408
495
|
// W-210: a device that sets one background layer keeps the layers it inherits.
|
|
409
496
|
const base = { ...classLayers, ...own };
|
|
410
497
|
// W-956: Laptop between Desktop and Tablet; each narrower device inherits the wider ones.
|
|
@@ -442,6 +529,11 @@ export function renderPage(
|
|
|
442
529
|
const width = props.fullWidth === true ? "none" : cssLength(props.contentWidth);
|
|
443
530
|
if (width) declarations.push({ property: "--emvb-content-width", value: width });
|
|
444
531
|
}
|
|
532
|
+
if (node.type === "menu-item") {
|
|
533
|
+
// W-1069: the Mega panel width, read by the panel's rules.
|
|
534
|
+
const width = cssLength((node as { props: { panelWidth?: unknown } }).props.panelWidth);
|
|
535
|
+
if (width) declarations.push({ property: "--emvb-menu-panel-width", value: width });
|
|
536
|
+
}
|
|
445
537
|
if (node.type === "loop") {
|
|
446
538
|
// W-308: grid and cards columns, as a custom property the Loop's base CSS reads.
|
|
447
539
|
const columns = (node as { props: { columns?: unknown } }).props.columns;
|
|
@@ -495,6 +587,15 @@ export function renderPage(
|
|
|
495
587
|
if (place.tablet.length > 0) tablet.declarations.unshift(...placeAt(place.tablet));
|
|
496
588
|
if (place.mobile.length > 0) mobile.declarations.unshift(...placeAt(place.mobile));
|
|
497
589
|
}
|
|
590
|
+
if (node.type === "spacer") {
|
|
591
|
+
pushSpacerBasis(node, parent, design.classes, {
|
|
592
|
+
desktop: declarations,
|
|
593
|
+
wide: wide.declarations,
|
|
594
|
+
laptop: laptop.declarations,
|
|
595
|
+
tablet: tablet.declarations,
|
|
596
|
+
mobile: mobile.declarations,
|
|
597
|
+
});
|
|
598
|
+
}
|
|
498
599
|
const queryStyle = node.query ? styleDeclarations(node.query.style) : undefined;
|
|
499
600
|
for (const key of queryStyle?.rejected ?? []) {
|
|
500
601
|
warnings.push({ nodeId, code: "rejected-style", detail: key });
|
|
@@ -610,7 +711,9 @@ export function renderPage(
|
|
|
610
711
|
node.htmlId && HTML_ID.test(node.htmlId) && !isShadowingId(node.htmlId)
|
|
611
712
|
? node.htmlId
|
|
612
713
|
: node.type === "heading" && id && layoutHasToc
|
|
613
|
-
?
|
|
714
|
+
? // W-1077: a theme part's anchors get its suffix, as its other generated ids do (W-527),
|
|
715
|
+
// so a header heading never takes the page's own heading's anchor.
|
|
716
|
+
`emvb-h-${id}${idSuffix}`
|
|
614
717
|
: undefined;
|
|
615
718
|
// W-649: a Loop renders its item design once per entry; an id repeated on the page is invalid
|
|
616
719
|
// and every Table of contents link or label would point at the first copy only.
|
|
@@ -641,12 +744,23 @@ export function renderPage(
|
|
|
641
744
|
if (!Object.hasOwn(ELEMENTS, type)) {
|
|
642
745
|
// W-927: extension elements render via the Extensions API, or a placeholder when missing.
|
|
643
746
|
if (isExtensionType(type)) {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
747
|
+
const ext = renderExtensionNode(
|
|
748
|
+
node,
|
|
749
|
+
mode === "editor" ? "editor" : "public",
|
|
750
|
+
(nodes) =>
|
|
751
|
+
nodes
|
|
752
|
+
.map((child) => visit(child, false, dynamic))
|
|
753
|
+
.filter((child): child is VNode => child !== undefined),
|
|
754
|
+
opts.extensionOutputs,
|
|
755
|
+
(pkg) => extensionsUsed.add(pkg),
|
|
649
756
|
);
|
|
757
|
+
// W-1088 (#37): visitors get nothing for an extension element that can't render; the
|
|
758
|
+
// stored element is kept and renders again once its extension is back.
|
|
759
|
+
if (mode === "public" && !opts.extensionPlaceholders && isExtensionPlaceholder(ext)) {
|
|
760
|
+
return undefined;
|
|
761
|
+
}
|
|
762
|
+
usedTypes.add("ext");
|
|
763
|
+
return ext;
|
|
650
764
|
}
|
|
651
765
|
warnings.push({ nodeId, code: "unknown-type", detail: type });
|
|
652
766
|
if (mode === "public") return undefined;
|
|
@@ -663,7 +777,20 @@ export function renderPage(
|
|
|
663
777
|
const runtime = nodeRuntime(node as LayoutNode);
|
|
664
778
|
if (runtime) runtimes.add(runtime);
|
|
665
779
|
const ruleId = id === undefined ? undefined : ruleIdFor(id, dynamic?.idOrigin ?? "");
|
|
666
|
-
|
|
780
|
+
// W-1062: a Spacer's size follows its parent's direction.
|
|
781
|
+
for (const child of nodeChildren(node)) parentOf.set(child, node);
|
|
782
|
+
const attrs = nodeAttrs(node, isRoot, id, nodeId, ruleId, parentOf.get(stored));
|
|
783
|
+
// W-1086: allowlisted classes an extension's render() put on its output node.
|
|
784
|
+
const extClasses = extensionClassesOf(stored);
|
|
785
|
+
if (extClasses) attrs.class = [attrs.class, ...extClasses].filter(Boolean).join(" ");
|
|
786
|
+
// W-1070: hides on scroll down with the opt-in sticky script (any element type).
|
|
787
|
+
if (hidesOnScroll(node as LayoutNode)) {
|
|
788
|
+
attrs["data-emvb-sticky-hide"] = "";
|
|
789
|
+
runtimes.add("sticky");
|
|
790
|
+
}
|
|
791
|
+
// W-1067: the canvas runs no widget scripts, so a Theme toggle waiting for its own stayed
|
|
792
|
+
// hidden there; the editor shows it as it looks once ready.
|
|
793
|
+
if (mode === "editor" && type === "theme-toggle") attrs["data-emvb-ready"] = "";
|
|
667
794
|
if (mode === "editor" && hasBindings(stored)) attrs["data-emvb-bound"] = "";
|
|
668
795
|
if (mode === "editor" && stored.audience) {
|
|
669
796
|
attrs["data-emvb-audience"] = audienceSummary(stored.audience);
|
|
@@ -729,8 +856,19 @@ export function renderPage(
|
|
|
729
856
|
});
|
|
730
857
|
}
|
|
731
858
|
}
|
|
859
|
+
const panelPartId = megaPanelPartId(node);
|
|
860
|
+
if (panelPartId) {
|
|
861
|
+
// W-1069: a mega menu item; a missing, looping or refused part leaves the item's own children.
|
|
862
|
+
const mega = renderPanelPart(panelPartId, ctx, dynamic);
|
|
863
|
+
if (mega) {
|
|
864
|
+
usedTypes.add("menu-mega");
|
|
865
|
+
rendered.menuDropdown = true;
|
|
866
|
+
return finish(node, buildMenuItem(node as MenuItemNode, attrs, [], mega));
|
|
867
|
+
}
|
|
868
|
+
}
|
|
732
869
|
if (isParentNode(node)) {
|
|
733
|
-
|
|
870
|
+
const built = def.build(node as never, attrs, ctx.children(node.children, dynamic));
|
|
871
|
+
return finish(node, node.type === "menu" ? uniqueMenuGroups(built, ctx.uniqueId) : built);
|
|
734
872
|
}
|
|
735
873
|
if (mode === "editor" && node.type === "video") {
|
|
736
874
|
const preview = videoPreview(node, attrs);
|
|
@@ -742,7 +880,11 @@ export function renderPage(
|
|
|
742
880
|
ctx.definitions,
|
|
743
881
|
ctx.formId,
|
|
744
882
|
);
|
|
745
|
-
|
|
883
|
+
if (FIELD_TYPES.has(type) && id) return finish(node, uniqueField(built, controlId(id)));
|
|
884
|
+
// W-1077: a Hotspot's note is a popover found by id; a header, footer or popup copy, or a
|
|
885
|
+
// repeat, gets its own id, as form fields and Tabs do.
|
|
886
|
+
if (type === "hotspot" && id) return finish(node, uniqueField(built, `emvb-hotspot-${id}`));
|
|
887
|
+
return finish(node, built);
|
|
746
888
|
}
|
|
747
889
|
|
|
748
890
|
/** W-249: a field rendered again (synced section, loop item) moves its control to a new id. */
|
|
@@ -817,10 +959,16 @@ export function renderPage(
|
|
|
817
959
|
detail: error.message,
|
|
818
960
|
}),
|
|
819
961
|
});
|
|
962
|
+
// W-1086: each extension stylesheet once, unscoped (it styles its own prefixed classes), before
|
|
963
|
+
// the print rules so the theme parts' shared sheet still finds them at the end.
|
|
964
|
+
const extensions = [...extensionsUsed].toSorted();
|
|
965
|
+
for (const pkg of extensions) if (extensionAssets(pkg)?.runtime) runtimes.add(`ext:${pkg}`);
|
|
966
|
+
const extensionCss = opts.separateExtensionCss ? "" : extensionStylesheets(extensions);
|
|
820
967
|
return {
|
|
821
968
|
vnode,
|
|
822
|
-
|
|
823
|
-
|
|
969
|
+
// W-1067: a public page of a site with dark colours puts back the visitor's choice first.
|
|
970
|
+
html: mode === "public" && designHasDark(design) ? THEME_BOOT_SCRIPT + html : html,
|
|
971
|
+
css: (scope ? scopeWrapperCss() + scopeCss(css, scope) : css) + extensionCss + printCss(),
|
|
824
972
|
needsFormsRuntime: rendered.form || layoutHasForm(layout),
|
|
825
973
|
needsTabsRuntime: rendered.tabs || layoutHasTabs(layout),
|
|
826
974
|
needsMenuRuntime: rendered.menuDropdown || layoutHasMenuDropdown(layout),
|
|
@@ -828,6 +976,7 @@ export function renderPage(
|
|
|
828
976
|
...(design.direction ? { dir: design.direction } : {}),
|
|
829
977
|
warnings,
|
|
830
978
|
baseTypes: [...usedTypes],
|
|
979
|
+
extensions,
|
|
831
980
|
};
|
|
832
981
|
}
|
|
833
982
|
|
|
@@ -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");
|