@perkyzz/emvb 0.0.0-stage → 0.2.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.
Files changed (217) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -2
  3. package/THIRD_PARTY_NOTICES.md +32 -0
  4. package/licenses/fontawesome-free.LICENSE +165 -0
  5. package/licenses/lucide-static.LICENSE +43 -0
  6. package/licenses/remixicon.LICENSE +201 -0
  7. package/licenses/tabler-icons.LICENSE +21 -0
  8. package/package.json +76 -4
  9. package/src/admin/access/RequireEditor.tsx +39 -0
  10. package/src/admin/access/role.ts +36 -0
  11. package/src/admin/access/sidebar-shim.ts +108 -0
  12. package/src/admin/api.ts +75 -0
  13. package/src/admin/content-api.ts +210 -0
  14. package/src/admin/editor/Editor.tsx +532 -0
  15. package/src/admin/editor/EditorOverlay.tsx +66 -0
  16. package/src/admin/editor/ShortcutsDialog.tsx +30 -0
  17. package/src/admin/editor/SmallScreenNotice.tsx +21 -0
  18. package/src/admin/editor/TopBar.tsx +243 -0
  19. package/src/admin/editor/canvas/CanvasFrame.tsx +536 -0
  20. package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
  21. package/src/admin/editor/canvas/DeviceBar.tsx +91 -0
  22. package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
  23. package/src/admin/editor/canvas/SelectionOverlay.tsx +239 -0
  24. package/src/admin/editor/canvas/canvas-events.ts +245 -0
  25. package/src/admin/editor/canvas/state-preview.ts +19 -0
  26. package/src/admin/editor/canvas/tab-reveal.ts +101 -0
  27. package/src/admin/editor/canvas/vnode-react.tsx +69 -0
  28. package/src/admin/editor/clipboard-store.ts +44 -0
  29. package/src/admin/editor/dialogs.tsx +164 -0
  30. package/src/admin/editor/dnd/drag-stash.ts +27 -0
  31. package/src/admin/editor/dnd/drop-target.ts +148 -0
  32. package/src/admin/editor/dnd/new-element.ts +107 -0
  33. package/src/admin/editor/editor-css.ts +625 -0
  34. package/src/admin/editor/exit.ts +27 -0
  35. package/src/admin/editor/host.ts +30 -0
  36. package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
  37. package/src/admin/editor/icons/library.ts +243 -0
  38. package/src/admin/editor/icons/set-format.ts +29 -0
  39. package/src/admin/editor/icons/sets/fontawesome.json +1 -0
  40. package/src/admin/editor/icons/sets/lucide.json +1 -0
  41. package/src/admin/editor/icons/sets/remix.json +1 -0
  42. package/src/admin/editor/icons/sets/tabler.json +1 -0
  43. package/src/admin/editor/panels/AddPanel.tsx +146 -0
  44. package/src/admin/editor/panels/ClassesSection.tsx +372 -0
  45. package/src/admin/editor/panels/ColorControl.tsx +477 -0
  46. package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
  47. package/src/admin/editor/panels/ElementPanel.tsx +773 -0
  48. package/src/admin/editor/panels/LayersPanel.tsx +573 -0
  49. package/src/admin/editor/panels/LeftPanel.tsx +81 -0
  50. package/src/admin/editor/panels/PageSettings.tsx +255 -0
  51. package/src/admin/editor/panels/SettingsPanel.tsx +113 -0
  52. package/src/admin/editor/panels/SiteStylesDrawer.tsx +548 -0
  53. package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
  54. package/src/admin/editor/panels/TriggersEditor.tsx +214 -0
  55. package/src/admin/editor/panels/VariableSection.tsx +530 -0
  56. package/src/admin/editor/panels/color-space.ts +195 -0
  57. package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
  58. package/src/admin/editor/panels/settings/BackgroundControls.tsx +418 -0
  59. package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
  60. package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
  61. package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
  62. package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
  63. package/src/admin/editor/panels/settings/ClassChipInput.tsx +451 -0
  64. package/src/admin/editor/panels/settings/DraftTextField.tsx +242 -0
  65. package/src/admin/editor/panels/settings/EffectsControls.tsx +354 -0
  66. package/src/admin/editor/panels/settings/FieldBindControl.tsx +119 -0
  67. package/src/admin/editor/panels/settings/FieldControl.tsx +270 -0
  68. package/src/admin/editor/panels/settings/FormBindControl.tsx +106 -0
  69. package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
  70. package/src/admin/editor/panels/settings/IconPicker.tsx +170 -0
  71. package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
  72. package/src/admin/editor/panels/settings/LengthRow.tsx +217 -0
  73. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +130 -0
  74. package/src/admin/editor/panels/settings/MediaPicker.tsx +220 -0
  75. package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
  76. package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
  77. package/src/admin/editor/panels/settings/StyleRow.tsx +563 -0
  78. package/src/admin/editor/panels/settings/VariableBinding.tsx +171 -0
  79. package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
  80. package/src/admin/editor/panels/settings/background-mode.ts +112 -0
  81. package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
  82. package/src/admin/editor/panels/settings/box-sides.ts +153 -0
  83. package/src/admin/editor/panels/settings/button-url.ts +27 -0
  84. package/src/admin/editor/panels/settings/class-suggest.ts +53 -0
  85. package/src/admin/editor/panels/settings/form-names.ts +38 -0
  86. package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
  87. package/src/admin/editor/panels/settings/image-alt.ts +25 -0
  88. package/src/admin/editor/panels/settings/length-units.ts +116 -0
  89. package/src/admin/editor/panels/settings/loop-context.ts +26 -0
  90. package/src/admin/editor/panels/settings/node-props.ts +11 -0
  91. package/src/admin/editor/panels/settings/style-sections.ts +394 -0
  92. package/src/admin/editor/panels/settings/svg-images.ts +14 -0
  93. package/src/admin/editor/panels/site-list.tsx +209 -0
  94. package/src/admin/editor/panels/variable-values.ts +73 -0
  95. package/src/admin/editor/restore-deleted.ts +80 -0
  96. package/src/admin/editor/section-templates.ts +50 -0
  97. package/src/admin/editor/shortcuts.ts +20 -0
  98. package/src/admin/editor/store.ts +240 -0
  99. package/src/admin/editor/useClipboardActions.ts +136 -0
  100. package/src/admin/editor/useEditorCommands.ts +203 -0
  101. package/src/admin/editor/useEditorData.ts +193 -0
  102. package/src/admin/editor/useEditorShortcuts.ts +180 -0
  103. package/src/admin/editor/useMediaQuery.ts +20 -0
  104. package/src/admin/editor/useNodeActions.ts +184 -0
  105. package/src/admin/editor/useSave.ts +242 -0
  106. package/src/admin/entry-status.ts +19 -0
  107. package/src/admin/forms-api.ts +73 -0
  108. package/src/admin/icon-uploads-api.ts +44 -0
  109. package/src/admin/index.tsx +20 -0
  110. package/src/admin/media-api.ts +68 -0
  111. package/src/admin/pages/CreateDialog.tsx +150 -0
  112. package/src/admin/pages/EditorPage.tsx +57 -0
  113. package/src/admin/pages/NewPageDialog.tsx +83 -0
  114. package/src/admin/pages/NewThemePartDialog.tsx +61 -0
  115. package/src/admin/pages/PageList.tsx +91 -0
  116. package/src/admin/pages/PagesPage.tsx +25 -0
  117. package/src/admin/pages/SetupShell.tsx +90 -0
  118. package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
  119. package/src/admin/pages/ThemePartList.tsx +221 -0
  120. package/src/admin/pages/list-kit.tsx +125 -0
  121. package/src/admin/setup/plan.ts +150 -0
  122. package/src/admin/setup/run.ts +61 -0
  123. package/src/admin/setup/spec.ts +107 -0
  124. package/src/admin/setup/useSetupStatus.ts +62 -0
  125. package/src/admin/theme-api.ts +233 -0
  126. package/src/admin/ui.ts +244 -0
  127. package/src/admin/widgets/LayoutField.tsx +67 -0
  128. package/src/astro/EmVBPage.astro +63 -0
  129. package/src/astro/env.d.ts +5 -0
  130. package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
  131. package/src/astro/floats/index.ts +1 -0
  132. package/src/astro/floats/runtime.ts +78 -0
  133. package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
  134. package/src/astro/forms/index.ts +1 -0
  135. package/src/astro/forms-definitions.ts +126 -0
  136. package/src/astro/index.ts +16 -0
  137. package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
  138. package/src/astro/menu/index.ts +1 -0
  139. package/src/astro/menu/runtime.ts +37 -0
  140. package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
  141. package/src/astro/popups/index.ts +1 -0
  142. package/src/astro/popups/runtime.ts +296 -0
  143. package/src/astro/render.ts +108 -0
  144. package/src/astro/resolve-theme.ts +515 -0
  145. package/src/astro/resolve.ts +65 -0
  146. package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
  147. package/src/astro/tabs/index.ts +1 -0
  148. package/src/astro/tabs/runtime.ts +116 -0
  149. package/src/astro/theme-context.ts +89 -0
  150. package/src/astro/theme-posts.ts +84 -0
  151. package/src/constants.ts +12 -0
  152. package/src/core/arrange.ts +448 -0
  153. package/src/core/clipboard.ts +504 -0
  154. package/src/core/css/generate.ts +236 -0
  155. package/src/core/css/scope.ts +88 -0
  156. package/src/core/design/cascade.ts +28 -0
  157. package/src/core/design/classes.ts +224 -0
  158. package/src/core/design/devices.ts +56 -0
  159. package/src/core/design/states.ts +49 -0
  160. package/src/core/design/transfer.ts +132 -0
  161. package/src/core/design/variables.ts +359 -0
  162. package/src/core/elements/definition.ts +12 -0
  163. package/src/core/elements/dynamic-elements.ts +225 -0
  164. package/src/core/elements/field-id.ts +6 -0
  165. package/src/core/elements/form-elements.ts +219 -0
  166. package/src/core/elements/index.ts +960 -0
  167. package/src/core/elements/menu.ts +190 -0
  168. package/src/core/elements/plain-text.ts +32 -0
  169. package/src/core/forms/binding.ts +61 -0
  170. package/src/core/forms/definition.ts +45 -0
  171. package/src/core/forms/success-layout.ts +63 -0
  172. package/src/core/icons/catalog.ts +273 -0
  173. package/src/core/index.ts +380 -0
  174. package/src/core/limits.ts +9 -0
  175. package/src/core/migrate/index.ts +126 -0
  176. package/src/core/nesting.ts +51 -0
  177. package/src/core/render/context.ts +21 -0
  178. package/src/core/render/dynamic-post.ts +175 -0
  179. package/src/core/render/extras.ts +98 -0
  180. package/src/core/render/form.ts +235 -0
  181. package/src/core/render/index.ts +372 -0
  182. package/src/core/render/loop.ts +43 -0
  183. package/src/core/render/pagination.ts +76 -0
  184. package/src/core/render/section.ts +37 -0
  185. package/src/core/render/tabs.ts +76 -0
  186. package/src/core/render/vnode.ts +87 -0
  187. package/src/core/sanitize/css.ts +771 -0
  188. package/src/core/sanitize/embed-url.ts +160 -0
  189. package/src/core/sanitize/escape.ts +10 -0
  190. package/src/core/sanitize/href.ts +6 -0
  191. package/src/core/sanitize/media-url.ts +7 -0
  192. package/src/core/sanitize/svg-upload.ts +203 -0
  193. package/src/core/sanitize/svg.ts +374 -0
  194. package/src/core/sanitize/url.ts +31 -0
  195. package/src/core/schema/descriptors.ts +37 -0
  196. package/src/core/schema/design.ts +93 -0
  197. package/src/core/schema/layout.ts +1008 -0
  198. package/src/core/schema/state-names.ts +4 -0
  199. package/src/core/schema/style.ts +336 -0
  200. package/src/core/stats.ts +18 -0
  201. package/src/core/tabs/presence.ts +25 -0
  202. package/src/core/theme/conditions.ts +324 -0
  203. package/src/core/theme/dynamic.ts +143 -0
  204. package/src/core/theme/float.ts +113 -0
  205. package/src/core/theme/pagination.ts +97 -0
  206. package/src/core/theme/parse-doc.ts +36 -0
  207. package/src/core/theme/part-types.ts +81 -0
  208. package/src/core/theme/popup-markup.ts +41 -0
  209. package/src/core/theme/popup-rules.ts +62 -0
  210. package/src/core/theme/triggers.ts +104 -0
  211. package/src/core/tree-ops.ts +139 -0
  212. package/src/core/validate.ts +185 -0
  213. package/src/index.ts +18 -0
  214. package/src/server/design-routes.ts +125 -0
  215. package/src/server/hooks.ts +118 -0
  216. package/src/server/icon-routes.ts +79 -0
  217. package/src/server/plugin.ts +43 -0
@@ -0,0 +1,372 @@
1
+ import { generateCss } from "../css/generate.ts";
2
+ import { cssScopeToken, scopeAttribute, scopeCss, scopeWrapperCss } from "../css/scope.ts";
3
+ import { ELEMENTS } from "../elements/index.ts";
4
+ import { controlId } from "../elements/field-id.ts";
5
+ import { layoutHasForm } from "../forms/binding.ts";
6
+ import { layoutHasMenuDropdown, layoutHasTabs } from "../tabs/presence.ts";
7
+ import type { DesignSystem } from "../schema/design.ts";
8
+ import {
9
+ isFormNode,
10
+ isLoopNode,
11
+ isParentNode,
12
+ isSectionNode,
13
+ isTabsNode,
14
+ type Layout,
15
+ type LayoutNode,
16
+ type PaginationNode,
17
+ } from "../schema/layout.ts";
18
+ import {
19
+ cssLength,
20
+ stateDeclarations,
21
+ styleClassName,
22
+ styleDeclarations,
23
+ withInheritedLayers,
24
+ type Declaration,
25
+ type StateDeclarations,
26
+ } from "../sanitize/css.ts";
27
+ import { STYLE_STATES } from "../schema/state-names.ts";
28
+ import { resolveEmbedUrl } from "../sanitize/embed-url.ts";
29
+ import { resolvePostForRender, type ThemeDynamicData } from "../theme/dynamic.ts";
30
+ import type { FormDefinitions } from "../forms/definition.ts";
31
+ import type { PopupDevice } from "../theme/popup-rules.ts";
32
+ import type { RenderContext, RenderMode } from "./context.ts";
33
+ import { isDynamicPostNode, renderDynamicPost } from "./dynamic-post.ts";
34
+ import { renderForm, withFieldOptions } from "./form.ts";
35
+ import { renderLoop } from "./loop.ts";
36
+ import { renderPagination } from "./pagination.ts";
37
+ import { renderSection } from "./section.ts";
38
+ import { renderTabs } from "./tabs.ts";
39
+ import { serialize, type VNode } from "./vnode.ts";
40
+ import { classStylesInListOrder } from "../design/cascade.ts";
41
+ import {
42
+ applyBackgroundVideo,
43
+ applyBoxLink,
44
+ customAttributes,
45
+ safeBackgroundVideo,
46
+ } from "./extras.ts";
47
+
48
+ export type { RenderMode } from "./context.ts";
49
+ export { FORMS_SUBMIT_PATH } from "./form.ts";
50
+
51
+ export type RenderWarning = {
52
+ nodeId: string;
53
+ code: "unknown-type" | "rejected-style" | "unknown-variable";
54
+ detail: string;
55
+ };
56
+ export type RenderResult = {
57
+ vnode: VNode;
58
+ html: string;
59
+ css: string;
60
+ needsFormsRuntime: boolean;
61
+ needsTabsRuntime: boolean;
62
+ /** A Menu has a dropdown: hosts load `EmVBMenuRuntime` (W-197). */
63
+ needsMenuRuntime: boolean;
64
+ /** The site's text direction when set in Site styles, for the host's `<html dir>` (W-230). */
65
+ dir?: "ltr" | "rtl" | "auto";
66
+ warnings: RenderWarning[];
67
+ };
68
+
69
+ const ID = /^[A-Za-z0-9_-]{4,24}$/;
70
+ const HTML_ID = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
71
+
72
+ // Canvas iframe has no allow-scripts (D-011): live YouTube/Vimeo players fail there.
73
+ function videoPreview(node: LayoutNode, attrs: Record<string, string>): VNode | undefined {
74
+ const target = resolveEmbedUrl((node.props as { url: string }).url);
75
+ if (target?.kind !== "iframe") return undefined;
76
+ const label =
77
+ (node.props as { title?: string }).title?.trim() ||
78
+ (target.provider === "youtube" ? "YouTube video" : "Vimeo video");
79
+ return {
80
+ tag: "div",
81
+ attrs: {
82
+ ...attrs,
83
+ class: `${attrs.class} emvb-video-preview`.trim(),
84
+ "data-emvb-video-preview": target.provider,
85
+ },
86
+ children: [`${label} — plays on the published page`],
87
+ };
88
+ }
89
+
90
+ /**
91
+ * Renders a validated layout to lean HTML and CSS (R-031, R-032). Walks defensively: unknown types
92
+ * render nothing publicly and a placeholder in the editor (R-033); unsafe style values are dropped.
93
+ */
94
+ /** `grid-template-columns` for a whole column count from 1 to 12; anything else emits nothing. */
95
+ const gridTracks = (columns: unknown): Declaration[] =>
96
+ typeof columns === "number" && Number.isInteger(columns) && columns >= 1 && columns <= 12
97
+ ? [{ property: "grid-template-columns", value: `repeat(${columns}, minmax(0, 1fr))` }]
98
+ : [];
99
+
100
+ /** A node with at least one child; tolerant of a malformed node without a children array. */
101
+ const hasChildren = (node: LayoutNode): boolean => {
102
+ const children: unknown = (node as { children?: unknown }).children;
103
+ return Array.isArray(children) && children.length > 0;
104
+ };
105
+
106
+ /** A short, stable hash of a node origin, for its suffixed rule id (W-250). */
107
+ function originHash(origin: string): string {
108
+ let hash = 0x811c9dc5;
109
+ for (let i = 0; i < origin.length; i += 1) {
110
+ hash ^= origin.charCodeAt(i);
111
+ hash = Math.imul(hash, 0x01000193) >>> 0;
112
+ }
113
+ return hash.toString(36);
114
+ }
115
+
116
+ /** Form fields whose control carries an `emvb-field-<id>` HTML id (W-187). */
117
+ const FIELD_TYPES = new Set(["text-input", "textarea", "select", "checkbox", "radio"]);
118
+
119
+ const ID_ATTRS = ["id", "for", "aria-controls", "aria-labelledby", "aria-describedby"] as const;
120
+
121
+ /** Rewrites `base` (or `base-…`) to `next` in the id and id-reference attributes of a subtree. */
122
+ function renameIds(vnode: VNode, base: string, next: string): VNode {
123
+ const attrs = { ...vnode.attrs };
124
+ for (const key of ID_ATTRS) {
125
+ const value = attrs[key];
126
+ if (value === undefined) continue;
127
+ attrs[key] = value
128
+ .split(" ")
129
+ .map((ref) =>
130
+ ref === base || ref.startsWith(`${base}-`) ? next + ref.slice(base.length) : ref,
131
+ )
132
+ .join(" ");
133
+ }
134
+ return {
135
+ ...vnode,
136
+ attrs,
137
+ children: vnode.children.map((child) =>
138
+ typeof child === "string" ? child : renameIds(child, base, next),
139
+ ),
140
+ };
141
+ }
142
+
143
+ export function renderPage(
144
+ layout: Layout,
145
+ design: DesignSystem,
146
+ opts: {
147
+ mode?: RenderMode;
148
+ formDefinitions?: FormDefinitions;
149
+ dynamic?: ThemeDynamicData;
150
+ /** Public renders: wrap the markup and scope the CSS to it, so sheets can't override each other (W-112). */
151
+ scope?: string;
152
+ /** Editor canvas: device rules follow this device, not the frame width (W-116). */
153
+ previewDevice?: PopupDevice;
154
+ } = {},
155
+ ): RenderResult {
156
+ const mode = opts.mode ?? "public";
157
+ const baseDynamic = opts.dynamic;
158
+ const warnings: RenderWarning[] = [];
159
+ const usedTypes = new Set<string>();
160
+ const localRules: {
161
+ id: string;
162
+ declarations: Declaration[];
163
+ states: StateDeclarations;
164
+ tablet?: Declaration[];
165
+ mobile?: Declaration[];
166
+ hiddenOn?: LayoutNode["hiddenOn"];
167
+ }[] = [];
168
+ const knownVariables = new Set(design.variables.colors.map((c) => c.id));
169
+ let backgroundVideo = false;
170
+
171
+ const domIds = new Map<string, number>();
172
+ // W-253: runtimes follow what renders, including synced section and loop item contents,
173
+ // which the page's own layout doesn't hold.
174
+ const rendered = { form: false, tabs: false, menuDropdown: false };
175
+ const ctx: RenderContext = {
176
+ mode,
177
+ definitions: opts.formDefinitions ?? new Map(),
178
+ children: (nodes, dynamic) =>
179
+ nodes
180
+ .map((child) => visit(child, false, dynamic))
181
+ .filter((child): child is VNode => child !== undefined),
182
+ uniqueId: (base) => {
183
+ const count = (domIds.get(base) ?? 0) + 1;
184
+ domIds.set(base, count);
185
+ return count === 1 ? base : `${base}-r${count}`;
186
+ },
187
+ };
188
+
189
+ // W-250: the first origin (page, synced section, loop item part) to use each element id.
190
+ const idOrigins = new Map<string, string>();
191
+ /** The id in `.emvb-e-<id>`: suffixed when another layout already used this id here. */
192
+ const ruleIdFor = (id: string, origin: string): string => {
193
+ const first = idOrigins.get(id);
194
+ if (first === undefined) idOrigins.set(id, origin);
195
+ return first === undefined || first === origin ? id : `${id}-o${originHash(origin)}`;
196
+ };
197
+
198
+ const nodeAttrs = (
199
+ node: LayoutNode,
200
+ isRoot: boolean,
201
+ id: string | undefined,
202
+ nodeId: string,
203
+ ruleId: string | undefined,
204
+ ): Record<string, string> => {
205
+ const classes = [...(isRoot ? ["emvb-root"] : []), `emvb-${node.type}`];
206
+ for (const classId of node.classes ?? []) {
207
+ const name = styleClassName(classId);
208
+ if (name) classes.push(name);
209
+ }
210
+ const { declarations, rejected } = styleDeclarations(node.style);
211
+ // W-210: a device that sets one background layer keeps the layers it inherits.
212
+ const base = node.style ?? {};
213
+ const tabletStyle = node.devices?.tablet;
214
+ const tablet = styleDeclarations(withInheritedLayers(tabletStyle, base));
215
+ const mobile = styleDeclarations(
216
+ withInheritedLayers(node.devices?.mobile, { ...base, ...tabletStyle }),
217
+ );
218
+ for (const key of [...rejected, ...tablet.rejected, ...mobile.rejected]) {
219
+ warnings.push({ nodeId, code: "rejected-style", detail: key });
220
+ }
221
+ if (node.type === "spacer") {
222
+ const height = cssLength((node as { props: { height: unknown } }).props.height);
223
+ if (height) declarations.push({ property: "height", value: height });
224
+ }
225
+ if (node.type === "layout-section") {
226
+ // The inner box's width (W-156): full width, or a length; unset keeps the 1140 px default.
227
+ const props = (node as { props: { contentWidth?: unknown; fullWidth?: unknown } }).props;
228
+ const width = props.fullWidth === true ? "none" : cssLength(props.contentWidth);
229
+ if (width) declarations.push({ property: "--emvb-content-width", value: width });
230
+ }
231
+ if (node.type === "grid") {
232
+ const props = (node as { props: Record<string, unknown> }).props;
233
+ declarations.push(...gridTracks(props["columns"]));
234
+ // Tablet and mobile counts go in their media queries (W-139).
235
+ tablet.declarations.unshift(...gridTracks(props["columnsTablet"]));
236
+ mobile.declarations.unshift(...gridTracks(props["columnsMobile"]));
237
+ }
238
+ const states = stateDeclarations(node.states);
239
+ for (const key of states.rejected) {
240
+ warnings.push({ nodeId, code: "rejected-style", detail: key });
241
+ }
242
+ for (const color of [node.style?.color, ...STYLE_STATES.map((s) => node.states?.[s]?.color)]) {
243
+ if (typeof color === "object" && !knownVariables.has(color.var)) {
244
+ warnings.push({ nodeId, code: "unknown-variable", detail: color.var });
245
+ }
246
+ }
247
+ const hiddenOn = node.hiddenOn;
248
+ const responsive =
249
+ tablet.declarations.length > 0 ||
250
+ mobile.declarations.length > 0 ||
251
+ (hiddenOn?.length ?? 0) > 0;
252
+ if (
253
+ ruleId &&
254
+ (declarations.length > 0 || Object.keys(states.states).length > 0 || responsive)
255
+ ) {
256
+ classes.push(`emvb-e-${ruleId}`);
257
+ localRules.push({
258
+ id: ruleId,
259
+ declarations,
260
+ states: states.states,
261
+ tablet: tablet.declarations,
262
+ mobile: mobile.declarations,
263
+ hiddenOn,
264
+ });
265
+ }
266
+ const attrs: Record<string, string> = { class: classes.join(" "), ...customAttributes(node) };
267
+ if (mode === "editor" && id) attrs["data-emvb-id"] = id;
268
+ if (node.htmlId && HTML_ID.test(node.htmlId)) attrs.id = node.htmlId;
269
+ // W-230: the site's text direction on the root, also a fallback when the host's <html> has none.
270
+ if (isRoot && design.direction) attrs.dir = design.direction;
271
+ return attrs;
272
+ };
273
+
274
+ function visit(
275
+ node: LayoutNode,
276
+ isRoot: boolean,
277
+ dynamic: ThemeDynamicData | undefined = baseDynamic,
278
+ ): VNode | undefined {
279
+ const id = ID.test(node.id) ? node.id : undefined;
280
+ const nodeId = id ?? "(invalid id)";
281
+ const type: string = node.type;
282
+ if (!Object.hasOwn(ELEMENTS, type)) {
283
+ warnings.push({ nodeId, code: "unknown-type", detail: type });
284
+ if (mode === "public") return undefined;
285
+ return {
286
+ tag: "div",
287
+ attrs: { class: "emvb-unknown", ...(id ? { "data-emvb-id": id } : {}) },
288
+ children: [`Unknown element "${type}"`],
289
+ };
290
+ }
291
+ usedTypes.add(type);
292
+ if (isFormNode(node) && node.props.formId.trim()) rendered.form = true;
293
+ if (isTabsNode(node)) rendered.tabs = true;
294
+ if (type === "menu-item" && hasChildren(node)) rendered.menuDropdown = true;
295
+ const ruleId = id === undefined ? undefined : ruleIdFor(id, dynamic?.idOrigin ?? "");
296
+ const attrs = nodeAttrs(node, isRoot, id, nodeId, ruleId);
297
+ const def = ELEMENTS[type as keyof typeof ELEMENTS];
298
+ if (isFormNode(node)) return finish(node, renderForm(node, attrs, ctx, dynamic));
299
+ if (isLoopNode(node)) return finish(node, renderLoop(node, attrs, ctx, dynamic));
300
+ if (node.type === "pagination") {
301
+ return finish(node, renderPagination(node as PaginationNode, attrs, dynamic, mode));
302
+ }
303
+ if (isSectionNode(node)) return finish(node, renderSection(node, attrs, ctx, dynamic));
304
+ if (isDynamicPostNode(node)) {
305
+ return finish(
306
+ node,
307
+ renderDynamicPost(node, attrs, resolvePostForRender(dynamic, mode), mode),
308
+ );
309
+ }
310
+ if (isTabsNode(node)) return finish(node, renderTabs(node, id, attrs, ctx, dynamic));
311
+ if (isParentNode(node)) {
312
+ return finish(node, def.build(node as never, attrs, ctx.children(node.children, dynamic)));
313
+ }
314
+ if (mode === "editor" && node.type === "video") {
315
+ const preview = videoPreview(node, attrs);
316
+ if (preview) return finish(node, preview);
317
+ }
318
+ const built = withFieldOptions(def.build(node as never, attrs, []), node, ctx.definitions);
319
+ return finish(node, FIELD_TYPES.has(type) && id ? uniqueField(built, controlId(id)) : built);
320
+ }
321
+
322
+ /** W-249: a field rendered again (synced section, loop item) moves its control to a new id. */
323
+ function uniqueField(vnode: VNode, base: string): VNode {
324
+ const unique = ctx.uniqueId(base);
325
+ return unique === base ? vnode : renameIds(vnode, base, unique);
326
+ }
327
+
328
+ function videoOf(node: LayoutNode): string | undefined {
329
+ let found: string | undefined;
330
+ for (const style of classStylesInListOrder(design.classes, node.classes ?? [])) {
331
+ const safe = safeBackgroundVideo(style?.backgroundVideo);
332
+ if (safe) found = safe;
333
+ }
334
+ const own = safeBackgroundVideo(node.style?.backgroundVideo);
335
+ return own ?? found;
336
+ }
337
+
338
+ function finish(node: LayoutNode, vnode: VNode | undefined): VNode | undefined {
339
+ if (!vnode) return undefined;
340
+ const src = videoOf(node);
341
+ if (src) backgroundVideo = true;
342
+ return applyBackgroundVideo(applyBoxLink(node, vnode), src);
343
+ }
344
+
345
+ const vnode = visit(layout.root, true) ?? {
346
+ tag: "div",
347
+ attrs: { class: "emvb-root" },
348
+ children: [],
349
+ };
350
+ const baseCss = new Map(Object.entries(ELEMENTS).map(([type, def]) => [type, def.baseCss]));
351
+ const html = serialize(vnode);
352
+ const css = generateCss({
353
+ design,
354
+ usedTypes,
355
+ baseCss,
356
+ localRules,
357
+ previewStates: mode === "editor",
358
+ backgroundVideo,
359
+ ...(mode === "editor" && opts.previewDevice ? { previewDevice: opts.previewDevice } : {}),
360
+ });
361
+ const scope = opts.scope === undefined ? undefined : cssScopeToken(opts.scope);
362
+ return {
363
+ vnode,
364
+ html: scope ? `<div ${scopeAttribute(scope)}>${html}</div>` : html,
365
+ css: scope ? scopeWrapperCss() + scopeCss(css, scope) : css,
366
+ needsFormsRuntime: rendered.form || layoutHasForm(layout),
367
+ needsTabsRuntime: rendered.tabs || layoutHasTabs(layout),
368
+ needsMenuRuntime: rendered.menuDropdown || layoutHasMenuDropdown(layout),
369
+ ...(design.direction ? { dir: design.direction } : {}),
370
+ warnings,
371
+ };
372
+ }
@@ -0,0 +1,43 @@
1
+ import { ELEMENTS } from "../elements/index.ts";
2
+ import type { LayoutNode, LoopNode } from "../schema/layout.ts";
3
+ import { resolvePostsForLoop, type ThemeDynamicData } from "../theme/dynamic.ts";
4
+ import type { RenderContext } from "./context.ts";
5
+ import type { VNode } from "./vnode.ts";
6
+
7
+ /** One item per post, from the chosen loop-item part or the loop's own children. */
8
+ export function renderLoop(
9
+ node: LoopNode,
10
+ attrs: Record<string, string>,
11
+ ctx: RenderContext,
12
+ dynamic: ThemeDynamicData | undefined,
13
+ ): VNode | undefined {
14
+ const posts = resolvePostsForLoop(dynamic, ctx.mode);
15
+ const itemPartId = node.props.itemPartId?.trim() ?? "";
16
+ const templateLayout =
17
+ itemPartId && dynamic?.loopTemplates ? dynamic.loopTemplates[itemPartId] : undefined;
18
+ const templateNodes: LayoutNode[] = templateLayout ? templateLayout.root.children : node.children;
19
+ // Editor mode always has a sample post, so an empty item template would paint a zero-height box.
20
+ if (posts.length === 0 || (ctx.mode === "editor" && templateNodes.length === 0)) {
21
+ if (ctx.mode !== "editor") return undefined;
22
+ return {
23
+ tag: "div",
24
+ attrs: { ...attrs, "data-emvb-loop-empty": "" },
25
+ children: ["Choose a Loop Item, or add elements here to design the item."],
26
+ };
27
+ }
28
+ const children: VNode[] = [];
29
+ // Items don't get the archive's page data: a Pagination belongs after the Loop (W-228).
30
+ const { pagination: _pagination, ...rest } = dynamic ?? {};
31
+ // A loop item part is another layout, so its ids may match the page's (W-250).
32
+ const itemDynamic = templateLayout
33
+ ? { ...rest, idOrigin: `${rest.idOrigin ?? ""}/l:${itemPartId}` }
34
+ : rest;
35
+ for (const post of posts) {
36
+ children.push({
37
+ tag: "div",
38
+ attrs: { class: "emvb-loop-item", "data-emvb-loop-item": post.id },
39
+ children: ctx.children(templateNodes, { ...itemDynamic, post, inLoopItem: true }),
40
+ });
41
+ }
42
+ return ELEMENTS.loop.build(node as never, attrs, children);
43
+ }
@@ -0,0 +1,76 @@
1
+ import type { PaginationNode } from "../schema/layout.ts";
2
+ import type { ThemeDynamicData } from "../theme/dynamic.ts";
3
+ import { paginationItems, type ArchivePagination } from "../theme/pagination.ts";
4
+ import type { VNode } from "./vnode.ts";
5
+
6
+ /** What the editor canvas shows: page 2 of several, links going nowhere (W-222). */
7
+ const EDITOR_SAMPLE: ArchivePagination = { page: 2, hasMore: true, basePath: "/posts" };
8
+
9
+ const label = (text: string | undefined, fallback: string) => text?.trim() || fallback;
10
+
11
+ /**
12
+ * Previous, page numbers and Next as plain links in a `nav` (W-222). No JS. Nothing on the page
13
+ * when there is no archive page data or only one page; the editor shows a sample.
14
+ */
15
+ export function renderPagination(
16
+ node: PaginationNode,
17
+ attrs: Record<string, string>,
18
+ dynamic: ThemeDynamicData | undefined,
19
+ mode: "editor" | "public",
20
+ ): VNode | undefined {
21
+ const editor = mode === "editor";
22
+ // Inside a Loop's item it would repeat once per post; it goes after the Loop (W-228).
23
+ if (dynamic?.inLoopItem) {
24
+ if (!editor) return undefined;
25
+ return {
26
+ tag: "div",
27
+ attrs: { ...attrs, "data-emvb-pagination-empty": "" },
28
+ children: ["Put Pagination after the Loop, not inside its item."],
29
+ };
30
+ }
31
+ const data = dynamic?.pagination ?? (editor ? EDITOR_SAMPLE : undefined);
32
+ if (!data) return undefined;
33
+ const items = paginationItems(data);
34
+ if (items.length === 0) {
35
+ if (!editor) return undefined;
36
+ return {
37
+ tag: "div",
38
+ attrs: { ...attrs, "data-emvb-pagination-empty": "" },
39
+ children: ["Pagination shows when the archive has more than one page."],
40
+ };
41
+ }
42
+ const href = (path: string) => (editor ? "#" : path);
43
+ const children: VNode[] = items.map((item): VNode => {
44
+ switch (item.kind) {
45
+ case "prev":
46
+ return {
47
+ tag: "a",
48
+ attrs: { class: "emvb-pagination-prev", href: href(item.href), rel: "prev" },
49
+ children: [label(node.props.prevText, "Previous")],
50
+ };
51
+ case "next":
52
+ return {
53
+ tag: "a",
54
+ attrs: { class: "emvb-pagination-next", href: href(item.href), rel: "next" },
55
+ children: [label(node.props.nextText, "Next")],
56
+ };
57
+ case "gap":
58
+ return {
59
+ tag: "span",
60
+ attrs: { class: "emvb-pagination-gap", "aria-hidden": "true" },
61
+ children: ["…"],
62
+ };
63
+ default:
64
+ return {
65
+ tag: "a",
66
+ attrs: {
67
+ class: "emvb-pagination-page",
68
+ href: href(item.href),
69
+ ...(item.current ? { "aria-current": "page" } : {}),
70
+ },
71
+ children: [String(item.n)],
72
+ };
73
+ }
74
+ });
75
+ return { tag: "nav", attrs: { ...attrs, "aria-label": "Pagination" }, children };
76
+ }
@@ -0,0 +1,37 @@
1
+ import { ELEMENTS } from "../elements/index.ts";
2
+ import type { SectionNode } from "../schema/layout.ts";
3
+ import type { ThemeDynamicData } from "../theme/dynamic.ts";
4
+ import type { RenderContext } from "./context.ts";
5
+ import type { VNode } from "./vnode.ts";
6
+
7
+ const MAX_SECTION_DEPTH = 8;
8
+
9
+ /**
10
+ * A section with `partId` renders that theme part's children.
11
+ * A missing part stays empty on the public site (local children would drift from the source).
12
+ */
13
+ export function renderSection(
14
+ node: SectionNode,
15
+ attrs: Record<string, string>,
16
+ ctx: RenderContext,
17
+ dynamic: ThemeDynamicData | undefined,
18
+ ): VNode {
19
+ const partId = node.props.partId?.trim() ?? "";
20
+ const stack = dynamic?.sectionStack ?? [];
21
+ const template =
22
+ partId && dynamic?.sectionTemplates ? dynamic.sectionTemplates[partId] : undefined;
23
+ if (!partId) {
24
+ return ELEMENTS.section.build(node as never, attrs, ctx.children(node.children, dynamic));
25
+ }
26
+ if (!template || stack.includes(partId) || stack.length >= MAX_SECTION_DEPTH) {
27
+ if (ctx.mode !== "editor") return ELEMENTS.section.build(node as never, attrs, []);
28
+ return { tag: "div", attrs, children: ["Synced section"] };
29
+ }
30
+ const templateNodes = template.root.children;
31
+ const next: ThemeDynamicData = {
32
+ ...dynamic,
33
+ sectionStack: [...stack, partId],
34
+ idOrigin: `${dynamic?.idOrigin ?? ""}/s:${partId}`,
35
+ };
36
+ return ELEMENTS.section.build(node as never, attrs, ctx.children(templateNodes, next));
37
+ }
@@ -0,0 +1,76 @@
1
+ import { MAX_TABS } from "../limits.ts";
2
+ import { isTabPanelNode, type TabsNode } from "../schema/layout.ts";
3
+ import type { ThemeDynamicData } from "../theme/dynamic.ts";
4
+ import type { RenderContext } from "./context.ts";
5
+ import type { VNode } from "./vnode.ts";
6
+
7
+ /** CSS-only tabs (radio inputs and labels) that the optional tabs script enhances. */
8
+ export function renderTabs(
9
+ node: TabsNode,
10
+ id: string | undefined,
11
+ attrs: Record<string, string>,
12
+ ctx: RenderContext,
13
+ dynamic: ThemeDynamicData | undefined,
14
+ ): VNode {
15
+ const panels = node.children.filter(isTabPanelNode).slice(0, MAX_TABS);
16
+ const group = ctx.uniqueId(`emvb-tabs-${id ?? "x"}`);
17
+ const inputs: VNode[] = [];
18
+ const labels: VNode[] = [];
19
+ const panelNodes: VNode[] = [];
20
+ panels.forEach((panel, i) => {
21
+ const inputId = `${group}-${i}`;
22
+ const inputAttrs: Record<string, string> = {
23
+ type: "radio",
24
+ name: group,
25
+ id: inputId,
26
+ class: "emvb-tab-input",
27
+ };
28
+ if (i === 0) inputAttrs.checked = "checked";
29
+ inputs.push({ tag: "input", attrs: inputAttrs, children: [] });
30
+ const panelDomId = `${group}-panel-${i}`;
31
+ const tabDomId = `${group}-tab-${i}`;
32
+ labels.push({
33
+ tag: "label",
34
+ attrs: {
35
+ class: "emvb-tab-label",
36
+ for: inputId,
37
+ id: tabDomId,
38
+ role: "tab",
39
+ "aria-selected": i === 0 ? "true" : "false",
40
+ "aria-controls": panelDomId,
41
+ tabindex: i === 0 ? "0" : "-1",
42
+ },
43
+ children: [panel.props.label],
44
+ });
45
+ const panelAttrs: Record<string, string> = {
46
+ class: "emvb-tab-panel",
47
+ id: panelDomId,
48
+ role: "tabpanel",
49
+ "aria-labelledby": tabDomId,
50
+ };
51
+ if (ctx.mode === "editor") panelAttrs["data-emvb-id"] = panel.id;
52
+ panelNodes.push({
53
+ tag: "div",
54
+ attrs: panelAttrs,
55
+ children: ctx.children(panel.children, dynamic),
56
+ });
57
+ });
58
+ return {
59
+ tag: "div",
60
+ attrs,
61
+ children: [
62
+ ...inputs,
63
+ {
64
+ tag: "div",
65
+ // W-275: a tablist needs tabs (axe aria-required-children); Tabs with no panels yet get
66
+ // a plain box.
67
+ attrs:
68
+ labels.length > 0
69
+ ? { class: "emvb-tab-list", role: "tablist", "aria-orientation": "horizontal" }
70
+ : { class: "emvb-tab-list" },
71
+ children: labels,
72
+ },
73
+ { tag: "div", attrs: { class: "emvb-tab-panels" }, children: panelNodes },
74
+ ],
75
+ };
76
+ }