@perkyzz/emvb 1.2.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/THIRD_PARTY_NOTICES.md +2 -2
- package/package.json +4 -4
- 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 +5 -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 +76 -0
- package/src/admin/editor/editor-css.ts +9 -1
- package/src/admin/editor/element-chrome.ts +34 -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/ItemList.tsx +33 -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/request-data.ts +6 -0
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/resolve.ts +9 -0
- package/src/astro/widgets/EmVBCountdownRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCounterRuntime.astro +8 -0
- package/src/astro/widgets/EmVBHeadlineRuntime.astro +9 -0
- package/src/astro/widgets/EmVBMapRuntime.astro +8 -0
- package/src/astro/widgets/EmVBShareRuntime.astro +9 -0
- package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
- package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +22 -0
- package/src/astro/widgets/alerts.ts +16 -2
- package/src/astro/widgets/carousel.ts +65 -24
- package/src/astro/widgets/countdown.ts +91 -0
- package/src/astro/widgets/counter.ts +98 -0
- package/src/astro/widgets/extension-runtimes.ts +27 -0
- package/src/astro/widgets/headline.ts +99 -0
- package/src/astro/widgets/map.ts +37 -0
- package/src/astro/widgets/share.ts +21 -0
- 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 +177 -6
- package/src/core/arrange.ts +71 -1
- package/src/core/canvas-collections.ts +28 -0
- package/src/core/css/font-face.ts +72 -0
- package/src/core/css/generate.ts +35 -1
- package/src/core/elements/counter-format.ts +15 -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 +54 -4
- package/src/core/elements/input-limits.ts +44 -0
- package/src/core/elements/marketing.ts +1490 -0
- package/src/core/elements/menu.ts +109 -47
- package/src/core/elements/site.ts +108 -0
- package/src/core/elements/widgets.ts +40 -5
- package/src/core/export/runtimes.generated.ts +10 -3
- package/src/core/export/site.ts +55 -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 +532 -293
- 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/limits.ts +6 -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 +172 -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 +534 -22
- 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 +11 -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 +11 -1
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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isShadowingId } from "../shadowing-ids.ts";
|
|
2
2
|
import { renderableDesign, renderableDynamic, renderableLayout } from "../contract.ts";
|
|
3
3
|
import { markColors } from "../text-marks.ts";
|
|
4
|
-
import type { TextMark } from "../schema/layout.ts";
|
|
4
|
+
import type { HotspotNode, ShareLinkNode, TextMark } from "../schema/layout.ts";
|
|
5
5
|
import { LIST_MARKERS } from "../css-keywords.ts";
|
|
6
6
|
import { MAX_NODES } from "../limits.ts";
|
|
7
7
|
import { loneAbTests, variantShows } from "../audience/variants.ts";
|
|
@@ -16,7 +16,8 @@ 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
|
+
import { hotspotPlace, shareLinkVNode } from "../elements/marketing.ts";
|
|
20
21
|
import { controlId } from "../elements/field-id.ts";
|
|
21
22
|
import { layoutHasForm } from "../forms/binding.ts";
|
|
22
23
|
import { nodeChildren, someNode } from "../tree-ops.ts";
|
|
@@ -32,6 +33,7 @@ import {
|
|
|
32
33
|
cssTypeName,
|
|
33
34
|
type Layout,
|
|
34
35
|
type LayoutNode,
|
|
36
|
+
type MenuItemNode,
|
|
35
37
|
type PaginationNode,
|
|
36
38
|
} from "../schema/layout.ts";
|
|
37
39
|
import {
|
|
@@ -55,13 +57,20 @@ import { isDynamicPostNode, renderDynamicPost } from "./dynamic-post.ts";
|
|
|
55
57
|
import { renderForm, withFieldOptions } from "./form.ts";
|
|
56
58
|
import { renderLoop } from "./loop.ts";
|
|
57
59
|
import { renderPagination } from "./pagination.ts";
|
|
58
|
-
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";
|
|
59
63
|
import { renderTabs } from "./tabs.ts";
|
|
64
|
+
import { designHasDark, THEME_BOOT_SCRIPT } from "./theme-boot.ts";
|
|
60
65
|
import { serialize, type VNode } from "./vnode.ts";
|
|
61
66
|
import {
|
|
67
|
+
extensionAssets,
|
|
68
|
+
extensionClassesOf,
|
|
69
|
+
extensionStylesheets,
|
|
62
70
|
isExtensionType,
|
|
63
71
|
renderExtensionNode,
|
|
64
72
|
EXTENSION_PLACEHOLDER_CSS,
|
|
73
|
+
type ExtensionOutputs,
|
|
65
74
|
} from "../extensions/index.ts";
|
|
66
75
|
import { classStylesInListOrder, resolveCascade } from "../design/cascade.ts";
|
|
67
76
|
import { applyBindings, hasBindings, type BindingData } from "../data/bindings.ts";
|
|
@@ -92,12 +101,17 @@ export type RenderResult = {
|
|
|
92
101
|
* W-1025: the opt-in widget scripts the page's elements asked for, sorted; empty for most
|
|
93
102
|
* pages. `EmVBPage` loads them; a theme part's go to `EmVBWidgetRuntimes`.
|
|
94
103
|
*/
|
|
95
|
-
runtimes:
|
|
104
|
+
runtimes: PageRuntime[];
|
|
96
105
|
/** The site's text direction when set in Site styles, for the host's `<html dir>` (W-230). */
|
|
97
106
|
dir?: "ltr" | "rtl" | "auto";
|
|
98
107
|
warnings: RenderWarning[];
|
|
99
108
|
/** W-971: the element types whose base rules this sheet holds (see `sharedPartCss`). */
|
|
100
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[];
|
|
101
115
|
};
|
|
102
116
|
|
|
103
117
|
const ID = /^[A-Za-z0-9_-]{4,24}$/;
|
|
@@ -195,7 +209,14 @@ function originHash(origin: string): string {
|
|
|
195
209
|
/** Form fields whose control carries an `emvb-field-<id>` HTML id (W-187). */
|
|
196
210
|
const FIELD_TYPES = new Set<string>(FORM_FIELD_TYPES.filter((type) => type !== "submit"));
|
|
197
211
|
|
|
198
|
-
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;
|
|
199
220
|
|
|
200
221
|
/** Rewrites `base` (or `base-…`) to `next` in the id and id-reference attributes of a subtree. */
|
|
201
222
|
function renameIds(vnode: VNode, base: string, next: string): VNode {
|
|
@@ -225,6 +246,46 @@ const MAX_SECTION_ELEMENTS = 20 * MAX_NODES;
|
|
|
225
246
|
const baseCss = new Map(Object.entries(ELEMENTS).map(([type, def]) => [type, def.baseCss]));
|
|
226
247
|
// W-927: placeholder + wrapper styles ship with every page that may hold an extension node.
|
|
227
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
|
+
}
|
|
228
289
|
|
|
229
290
|
/**
|
|
230
291
|
* W-971: theme parts on one page (header, footer, popups, floats) each repeated the scope wrapper
|
|
@@ -279,6 +340,17 @@ export function renderPage(
|
|
|
279
340
|
partIds?: boolean;
|
|
280
341
|
/** The page's language, e.g. "fr-CA": Post Dates are written in it (W-688). */
|
|
281
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;
|
|
282
354
|
} = {},
|
|
283
355
|
): RenderResult {
|
|
284
356
|
const mode = opts.mode ?? "public";
|
|
@@ -306,6 +378,7 @@ export function renderPage(
|
|
|
306
378
|
// W-799: each grid child's grid, so a span or start line that doesn't fit a device's columns
|
|
307
379
|
// can be clamped there.
|
|
308
380
|
const gridOf = new Map<string, LayoutNode>();
|
|
381
|
+
const parentOf = new WeakMap<LayoutNode, LayoutNode>();
|
|
309
382
|
someNode(layout.root, (current) => {
|
|
310
383
|
if (current.type === "grid")
|
|
311
384
|
for (const child of nodeChildren(current)) gridOf.set(child.id, current);
|
|
@@ -332,7 +405,9 @@ export function renderPage(
|
|
|
332
405
|
// W-253: runtimes follow what renders, including synced section and loop item contents,
|
|
333
406
|
// which the page's own layout doesn't hold.
|
|
334
407
|
const rendered = { form: false, tabs: false, menuDropdown: false };
|
|
335
|
-
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>();
|
|
336
411
|
let sectionBudget = MAX_SECTION_ELEMENTS;
|
|
337
412
|
const ctx: RenderContext = {
|
|
338
413
|
takeSectionBudget: (nodes) => {
|
|
@@ -369,6 +444,7 @@ export function renderPage(
|
|
|
369
444
|
id: string | undefined,
|
|
370
445
|
nodeId: string,
|
|
371
446
|
ruleId: string | undefined,
|
|
447
|
+
parent?: LayoutNode,
|
|
372
448
|
): Record<string, string> => {
|
|
373
449
|
const classes = [...(isRoot ? ["emvb-root"] : []), `emvb-${cssTypeName(node.type)}`];
|
|
374
450
|
for (const classId of node.classes ?? []) {
|
|
@@ -404,6 +480,11 @@ export function renderPage(
|
|
|
404
480
|
? (withInheritedLayers(node.style, classLayers) as typeof node.style)
|
|
405
481
|
: undefined;
|
|
406
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
|
+
}
|
|
407
488
|
// W-210: a device that sets one background layer keeps the layers it inherits.
|
|
408
489
|
const base = { ...classLayers, ...own };
|
|
409
490
|
// W-956: Laptop between Desktop and Tablet; each narrower device inherits the wider ones.
|
|
@@ -441,6 +522,11 @@ export function renderPage(
|
|
|
441
522
|
const width = props.fullWidth === true ? "none" : cssLength(props.contentWidth);
|
|
442
523
|
if (width) declarations.push({ property: "--emvb-content-width", value: width });
|
|
443
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
|
+
}
|
|
444
530
|
if (node.type === "loop") {
|
|
445
531
|
// W-308: grid and cards columns, as a custom property the Loop's base CSS reads.
|
|
446
532
|
const columns = (node as { props: { columns?: unknown } }).props.columns;
|
|
@@ -487,6 +573,22 @@ export function renderPage(
|
|
|
487
573
|
declarations.push({ property: "gap", value: `${gap}px` });
|
|
488
574
|
}
|
|
489
575
|
}
|
|
576
|
+
if (node.type === "hotspot") {
|
|
577
|
+
// W-1048: each marker sits at its own place on the picture, per device.
|
|
578
|
+
const place = hotspotPlace(node.props as HotspotNode["props"]);
|
|
579
|
+
declarations.push(...placeAt(place.desktop));
|
|
580
|
+
if (place.tablet.length > 0) tablet.declarations.unshift(...placeAt(place.tablet));
|
|
581
|
+
if (place.mobile.length > 0) mobile.declarations.unshift(...placeAt(place.mobile));
|
|
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
|
+
}
|
|
490
592
|
const queryStyle = node.query ? styleDeclarations(node.query.style) : undefined;
|
|
491
593
|
for (const key of queryStyle?.rejected ?? []) {
|
|
492
594
|
warnings.push({ nodeId, code: "rejected-style", detail: key });
|
|
@@ -602,7 +704,9 @@ export function renderPage(
|
|
|
602
704
|
node.htmlId && HTML_ID.test(node.htmlId) && !isShadowingId(node.htmlId)
|
|
603
705
|
? node.htmlId
|
|
604
706
|
: node.type === "heading" && id && layoutHasToc
|
|
605
|
-
?
|
|
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}`
|
|
606
710
|
: undefined;
|
|
607
711
|
// W-649: a Loop renders its item design once per entry; an id repeated on the page is invalid
|
|
608
712
|
// and every Table of contents link or label would point at the first copy only.
|
|
@@ -634,10 +738,15 @@ export function renderPage(
|
|
|
634
738
|
// W-927: extension elements render via the Extensions API, or a placeholder when missing.
|
|
635
739
|
if (isExtensionType(type)) {
|
|
636
740
|
usedTypes.add("ext");
|
|
637
|
-
return renderExtensionNode(
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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),
|
|
641
750
|
);
|
|
642
751
|
}
|
|
643
752
|
warnings.push({ nodeId, code: "unknown-type", detail: type });
|
|
@@ -655,7 +764,20 @@ export function renderPage(
|
|
|
655
764
|
const runtime = nodeRuntime(node as LayoutNode);
|
|
656
765
|
if (runtime) runtimes.add(runtime);
|
|
657
766
|
const ruleId = id === undefined ? undefined : ruleIdFor(id, dynamic?.idOrigin ?? "");
|
|
658
|
-
|
|
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"] = "";
|
|
659
781
|
if (mode === "editor" && hasBindings(stored)) attrs["data-emvb-bound"] = "";
|
|
660
782
|
if (mode === "editor" && stored.audience) {
|
|
661
783
|
attrs["data-emvb-audience"] = audienceSummary(stored.audience);
|
|
@@ -684,6 +806,12 @@ export function renderPage(
|
|
|
684
806
|
);
|
|
685
807
|
}
|
|
686
808
|
if (isTabsNode(node)) return finish(node, renderTabs(node, id, attrs, ctx, dynamic));
|
|
809
|
+
// W-1047: share links point at this page; a public page without its address shows none.
|
|
810
|
+
if (node.type === "share-link") {
|
|
811
|
+
const url = dynamic?.pageUrl ?? (mode === "editor" ? "https://example.com/" : undefined);
|
|
812
|
+
if (!url) return undefined;
|
|
813
|
+
return finish(node, shareLinkVNode(node as ShareLinkNode, attrs, url));
|
|
814
|
+
}
|
|
687
815
|
if (node.type === "language-switcher") {
|
|
688
816
|
const links = languageLinks(dynamic?.translations, mode);
|
|
689
817
|
// W-937: a page in one language has nothing to switch to; the public page shows nothing.
|
|
@@ -715,8 +843,19 @@ export function renderPage(
|
|
|
715
843
|
});
|
|
716
844
|
}
|
|
717
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
|
+
}
|
|
718
856
|
if (isParentNode(node)) {
|
|
719
|
-
|
|
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);
|
|
720
859
|
}
|
|
721
860
|
if (mode === "editor" && node.type === "video") {
|
|
722
861
|
const preview = videoPreview(node, attrs);
|
|
@@ -728,7 +867,11 @@ export function renderPage(
|
|
|
728
867
|
ctx.definitions,
|
|
729
868
|
ctx.formId,
|
|
730
869
|
);
|
|
731
|
-
|
|
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);
|
|
732
875
|
}
|
|
733
876
|
|
|
734
877
|
/** W-249: a field rendered again (synced section, loop item) moves its control to a new id. */
|
|
@@ -803,10 +946,16 @@ export function renderPage(
|
|
|
803
946
|
detail: error.message,
|
|
804
947
|
}),
|
|
805
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);
|
|
806
954
|
return {
|
|
807
955
|
vnode,
|
|
808
|
-
|
|
809
|
-
|
|
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(),
|
|
810
959
|
needsFormsRuntime: rendered.form || layoutHasForm(layout),
|
|
811
960
|
needsTabsRuntime: rendered.tabs || layoutHasTabs(layout),
|
|
812
961
|
needsMenuRuntime: rendered.menuDropdown || layoutHasMenuDropdown(layout),
|
|
@@ -814,6 +963,7 @@ export function renderPage(
|
|
|
814
963
|
...(design.direction ? { dir: design.direction } : {}),
|
|
815
964
|
warnings,
|
|
816
965
|
baseTypes: [...usedTypes],
|
|
966
|
+
extensions,
|
|
817
967
|
};
|
|
818
968
|
}
|
|
819
969
|
|
|
@@ -851,6 +1001,12 @@ const columnCount = (tracks: unknown, columns: unknown): number | undefined =>
|
|
|
851
1001
|
: undefined;
|
|
852
1002
|
|
|
853
1003
|
/** A grid's column count on desktop, tablet and mobile; unset follows the next wider device. */
|
|
1004
|
+
/** W-1048: a Hotspot marker's left and top. */
|
|
1005
|
+
const placeAt = ([left, top]: string[]) => [
|
|
1006
|
+
{ property: "left", value: left ?? "50%" },
|
|
1007
|
+
{ property: "top", value: top ?? "50%" },
|
|
1008
|
+
];
|
|
1009
|
+
|
|
854
1010
|
function gridColumnCounts(grid: LayoutNode): [number, number, number] {
|
|
855
1011
|
const props = grid.props as Record<string, unknown>;
|
|
856
1012
|
const desktop = columnCount(props["columnTracks"], props["columns"]) ?? 1;
|
|
@@ -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
|
+
}
|