@perkyzz/emvb 0.9.0 → 1.1.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 (187) hide show
  1. package/README.md +10 -1
  2. package/package.json +2 -2
  3. package/src/admin/agents-api.ts +45 -0
  4. package/src/admin/bulk-api.ts +67 -0
  5. package/src/admin/content-api.ts +10 -6
  6. package/src/admin/copy-rich-text.ts +119 -0
  7. package/src/admin/dialog-tab-wrap.ts +78 -0
  8. package/src/admin/editor/A11yCopilot.tsx +3 -1
  9. package/src/admin/editor/Editor.tsx +311 -250
  10. package/src/admin/editor/Timeline.tsx +8 -3
  11. package/src/admin/editor/TopBar.tsx +29 -7
  12. package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
  13. package/src/admin/editor/canvas/DeviceBar.tsx +31 -10
  14. package/src/admin/editor/canvas/canvas-scale.ts +3 -3
  15. package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
  16. package/src/admin/editor/co-design.ts +190 -0
  17. package/src/admin/editor/dnd/new-element.ts +48 -4
  18. package/src/admin/editor/editor-chrome.tsx +8 -6
  19. package/src/admin/editor/editor-commands.ts +15 -4
  20. package/src/admin/editor/editor-css.ts +2 -1
  21. package/src/admin/editor/element-chrome.ts +3 -1
  22. package/src/admin/editor/extension-manifests.ts +20 -0
  23. package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
  24. package/src/admin/editor/extensions-context.tsx +27 -0
  25. package/src/admin/editor/feature-css.ts +17 -0
  26. package/src/admin/editor/palette-items.ts +2 -2
  27. package/src/admin/editor/panels/AddPanel.tsx +31 -1
  28. package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
  29. package/src/admin/editor/panels/ClassesSection.tsx +9 -6
  30. package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
  31. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  32. package/src/admin/editor/panels/ElementPanel.tsx +68 -20
  33. package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
  34. package/src/admin/editor/panels/LayersPanel.tsx +10 -6
  35. package/src/admin/editor/panels/LeftPanel.tsx +33 -5
  36. package/src/admin/editor/panels/PageSettings.tsx +4 -0
  37. package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
  38. package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
  39. package/src/admin/editor/panels/settings/BackgroundControls.tsx +72 -15
  40. package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
  41. package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
  42. package/src/admin/editor/panels/settings/EffectsControls.tsx +183 -10
  43. package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
  44. package/src/admin/editor/panels/settings/IconControls.tsx +25 -11
  45. package/src/admin/editor/panels/settings/LengthRow.tsx +63 -19
  46. package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
  47. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +19 -1
  48. package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
  49. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
  50. package/src/admin/editor/panels/settings/StyleRow.tsx +120 -13
  51. package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
  52. package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
  53. package/src/admin/editor/panels/settings/background-mode.ts +14 -11
  54. package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
  55. package/src/admin/editor/panels/settings/box-sides.ts +22 -14
  56. package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
  57. package/src/admin/editor/panels/settings/length-units.ts +68 -4
  58. package/src/admin/editor/panels/settings/query-style.ts +3 -3
  59. package/src/admin/editor/panels/settings/style-sections.ts +52 -10
  60. package/src/admin/editor/panels/style-target.ts +22 -7
  61. package/src/admin/editor/presence.ts +60 -0
  62. package/src/admin/editor/section-templates.ts +26 -4
  63. package/src/admin/editor/store.ts +14 -4
  64. package/src/admin/editor/useCoDesign.ts +177 -0
  65. package/src/admin/editor/useEditorCommands.ts +7 -5
  66. package/src/admin/editor/useExtensions.ts +45 -0
  67. package/src/admin/editor/useNodeActions.ts +18 -7
  68. package/src/admin/editor/useProposals.ts +81 -0
  69. package/src/admin/export-api.ts +221 -0
  70. package/src/admin/index.tsx +6 -1
  71. package/src/admin/languages-api.ts +61 -0
  72. package/src/admin/pages/AgentSetup.tsx +148 -0
  73. package/src/admin/pages/AgentsPage.tsx +9 -26
  74. package/src/admin/pages/CreateDialog.tsx +15 -0
  75. package/src/admin/pages/ExportDialog.tsx +395 -0
  76. package/src/admin/pages/ImportButton.tsx +18 -0
  77. package/src/admin/pages/ImportElementorDialog.tsx +669 -0
  78. package/src/admin/pages/ImportPageLinks.tsx +86 -0
  79. package/src/admin/pages/PageList.tsx +82 -3
  80. package/src/admin/pages/ThemePartList.tsx +52 -2
  81. package/src/admin/pages/bulk.tsx +303 -0
  82. package/src/admin/pages/section-head.tsx +27 -0
  83. package/src/admin/proposals-api.ts +91 -0
  84. package/src/admin/search.ts +20 -0
  85. package/src/admin/theme-api.ts +4 -0
  86. package/src/admin/ui.ts +50 -4
  87. package/src/admin/widgets/CanvasField.tsx +8 -0
  88. package/src/admin/widgets/ConvertToRichText.tsx +136 -0
  89. package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
  90. package/src/admin/widgets/convert-body.ts +73 -2
  91. package/src/astro/content-port.ts +14 -1
  92. package/src/astro/render.ts +6 -6
  93. package/src/astro/resolve-theme.ts +25 -8
  94. package/src/astro/resolve.ts +89 -2
  95. package/src/astro/tabs/runtime.ts +16 -6
  96. package/src/constants.ts +1 -1
  97. package/src/core/a11y/audit.ts +45 -14
  98. package/src/core/arrange.ts +5 -1
  99. package/src/core/bounded-array.ts +31 -0
  100. package/src/core/clipboard.ts +9 -0
  101. package/src/core/contract.ts +305 -0
  102. package/src/core/css/generate.ts +151 -20
  103. package/src/core/css/scope.ts +10 -2
  104. package/src/core/css/trace.ts +47 -13
  105. package/src/core/css-keywords.ts +51 -1
  106. package/src/core/design/cascade.ts +12 -9
  107. package/src/core/design/classes.ts +28 -9
  108. package/src/core/design/devices.ts +89 -13
  109. package/src/core/design/states.ts +5 -3
  110. package/src/core/design/transfer.ts +5 -0
  111. package/src/core/design/variables.ts +31 -5
  112. package/src/core/elements/dynamic-elements.ts +3 -3
  113. package/src/core/elements/index.ts +73 -9
  114. package/src/core/export/runtimes.generated.ts +9 -0
  115. package/src/core/export/site.ts +562 -0
  116. package/src/core/export/zip.ts +95 -0
  117. package/src/core/extensions/define.ts +13 -0
  118. package/src/core/extensions/index.ts +41 -0
  119. package/src/core/extensions/namespace.ts +82 -0
  120. package/src/core/extensions/normalize.ts +141 -0
  121. package/src/core/extensions/placeholder.ts +41 -0
  122. package/src/core/extensions/registry.ts +94 -0
  123. package/src/core/extensions/render-ext.ts +118 -0
  124. package/src/core/extensions/safe-nodes.ts +93 -0
  125. package/src/core/extensions/schema.ts +112 -0
  126. package/src/core/extensions/types.ts +159 -0
  127. package/src/core/forms/binding.ts +1 -1
  128. package/src/core/history/diff.ts +26 -1
  129. package/src/core/import/elementor/atomic.ts +1608 -0
  130. package/src/core/import/elementor/classes.ts +127 -0
  131. package/src/core/import/elementor/context.ts +429 -0
  132. package/src/core/import/elementor/counter-steps.ts +72 -0
  133. package/src/core/import/elementor/css.ts +445 -0
  134. package/src/core/import/elementor/html.ts +500 -0
  135. package/src/core/import/elementor/index.ts +967 -0
  136. package/src/core/import/elementor/inline-marks.ts +81 -0
  137. package/src/core/import/elementor/snapshots.ts +48 -0
  138. package/src/core/import/elementor/style.ts +429 -0
  139. package/src/core/import/elementor/values.ts +241 -0
  140. package/src/core/import/elementor/widgets.ts +1897 -0
  141. package/src/core/index.ts +96 -0
  142. package/src/core/json-schema.ts +114 -0
  143. package/src/core/limits.ts +19 -0
  144. package/src/core/migrate/index.ts +6 -1
  145. package/src/core/migrate/v18.ts +222 -0
  146. package/src/core/perf/meter.ts +42 -24
  147. package/src/core/portable-text-export.ts +243 -0
  148. package/src/core/proposals-safety.ts +102 -0
  149. package/src/core/proposals.ts +357 -0
  150. package/src/core/public-attributes.ts +30 -0
  151. package/src/core/recipes/index.ts +2 -2
  152. package/src/core/render/extras.ts +3 -3
  153. package/src/core/render/index.ts +222 -23
  154. package/src/core/render/loop.ts +1 -1
  155. package/src/core/render/section.ts +4 -4
  156. package/src/core/render/tabs.ts +18 -11
  157. package/src/core/render/vnode.ts +1 -1
  158. package/src/core/sanitize/css.ts +151 -10
  159. package/src/core/sanitize/motion.ts +116 -0
  160. package/src/core/saved-sections.ts +6 -0
  161. package/src/core/schema/descriptors.ts +3 -1
  162. package/src/core/schema/design.ts +4 -3
  163. package/src/core/schema/layout.ts +92 -16
  164. package/src/core/schema/style.ts +296 -112
  165. package/src/core/search-text.ts +70 -0
  166. package/src/core/text-marks.ts +227 -0
  167. package/src/core/theme/dynamic.ts +9 -4
  168. package/src/core/theme/float.ts +2 -0
  169. package/src/core/theme/popup-rules.ts +33 -1
  170. package/src/core/translatable.ts +34 -0
  171. package/src/core/validate.ts +13 -1
  172. package/src/index.ts +24 -0
  173. package/src/mcp/errors.ts +3 -1
  174. package/src/mcp/ports.ts +67 -0
  175. package/src/mcp/prompts.ts +1 -11
  176. package/src/mcp/proposals.ts +281 -0
  177. package/src/mcp/read.ts +10 -10
  178. package/src/mcp/tools.ts +71 -3
  179. package/src/mcp/write.ts +66 -11
  180. package/src/server/agent-settings.ts +5 -1
  181. package/src/server/icon-routes.ts +52 -12
  182. package/src/server/mcp-routes.ts +15 -0
  183. package/src/server/plugin.ts +35 -2
  184. package/src/server/presence.ts +78 -0
  185. package/src/server/proposals.ts +261 -0
  186. package/src/server/requests.ts +196 -0
  187. package/src/server/tools-served.ts +45 -0
@@ -0,0 +1,305 @@
1
+ import { MAX_UNKNOWN_DEPTH, MAX_UNKNOWN_KEYS, UNKNOWN_KEY_PATTERN } from "./limits.ts";
2
+ import { flattenMotion, isFlatMotionKey, withoutStrayMotionKeys } from "./migrate/v18.ts";
3
+ import { isRecord } from "./record.ts";
4
+ import { KNOWN_NODE_SCHEMAS } from "./schema/layout.ts";
5
+ import { FlatStyleProps, OwnStyle, StyleProps, WideStyle } from "./schema/style.ts";
6
+
7
+ /**
8
+ * D-065 (W-925, contract 1.0): a 1.x document may carry keys this version does not know, on a
9
+ * node, its props, or a style record (style, states, devices, query style; a class or tag
10
+ * default in the design). They are set aside before the strict parse, checked against the
11
+ * limits in limits.ts, put back untouched after it, and never rendered: `renderableLayout` and
12
+ * `renderableDesign` keep known keys only. Everywhere else stays strict.
13
+ */
14
+
15
+ export type Path = readonly (string | number)[];
16
+ export type UnknownKey = { path: Path; key: string; value: unknown };
17
+ type ContractIssue = { path: string; code: string; message: string };
18
+
19
+ function shapeKeys(schema: unknown): Set<string> {
20
+ const shape = (schema as { shape?: Record<string, unknown> }).shape;
21
+ return new Set(shape ? Object.keys(shape) : []);
22
+ }
23
+
24
+ const NODE_KEYS = new Set<string>(["children"]);
25
+ const PROP_KEYS = new Map<string, Set<string>>();
26
+ for (const schema of KNOWN_NODE_SCHEMAS) {
27
+ const shape = (schema as unknown as { shape: Record<string, unknown> }).shape;
28
+ for (const key of Object.keys(shape)) NODE_KEYS.add(key);
29
+ const type = (shape["type"] as { value?: unknown }).value;
30
+ if (typeof type === "string") PROP_KEYS.set(type, shapeKeys(shape["props"]));
31
+ }
32
+ const STYLE_KEYS = shapeKeys(StyleProps);
33
+ /** W-959: an element's or class's own style also knows `wide`, whose record is open too. */
34
+ const OWN_STYLE_KEYS = shapeKeys(OwnStyle);
35
+ const WIDE_KEYS = shapeKeys(WideStyle);
36
+ const FLAT_STYLE_KEYS = shapeKeys(FlatStyleProps);
37
+ const STATES = ["hover", "focus", "active"] as const;
38
+ const DEVICES = ["laptop", "tablet", "mobile"] as const;
39
+
40
+ function formatPath(path: Path): string {
41
+ return path.reduce<string>((out, key) => {
42
+ if (typeof key === "number") return `${out}[${key}]`;
43
+ return out ? `${out}.${key}` : key;
44
+ }, "");
45
+ }
46
+
47
+ function depthOf(value: unknown, limit: number): number {
48
+ let max = 0;
49
+ const stack: { value: unknown; depth: number }[] = [{ value, depth: 1 }];
50
+ while (stack.length > 0) {
51
+ const { value: v, depth } = stack.pop() as { value: unknown; depth: number };
52
+ if (typeof v !== "object" || v === null) continue;
53
+ max = Math.max(max, depth);
54
+ if (max > limit) return max;
55
+ for (const child of Object.values(v)) stack.push({ value: child, depth: depth + 1 });
56
+ }
57
+ return max;
58
+ }
59
+
60
+ class Splitter {
61
+ readonly extras: UnknownKey[] = [];
62
+ readonly issues: ContractIssue[] = [];
63
+
64
+ /** Moves keys not in `knownKeys` out of `record` (mutated: it is the upgrader's private copy). */
65
+ take(record: unknown, knownKeys: ReadonlySet<string>, path: Path): void {
66
+ if (!isRecord(record)) return;
67
+ let count = 0;
68
+ for (const key of Object.keys(record)) {
69
+ if (knownKeys.has(key)) continue;
70
+ const where = formatPath([...path, key]);
71
+ count++;
72
+ if (!UNKNOWN_KEY_PATTERN.test(key)) {
73
+ this.issues.push({
74
+ path: where,
75
+ code: "unknown_key",
76
+ message: `"${key.slice(0, 40)}" is not a key EmVB can keep. Names start with a letter and use letters, digits and _ . : / @ -.`,
77
+ });
78
+ } else if (count > MAX_UNKNOWN_KEYS) {
79
+ this.issues.push({
80
+ path: where,
81
+ code: "unknown_key",
82
+ message: `At most ${MAX_UNKNOWN_KEYS} keys this EmVB does not know can be kept in one place.`,
83
+ });
84
+ } else if (depthOf(record[key], MAX_UNKNOWN_DEPTH) > MAX_UNKNOWN_DEPTH) {
85
+ this.issues.push({
86
+ path: where,
87
+ code: "unknown_key",
88
+ message: `A key this EmVB does not know can nest at most ${MAX_UNKNOWN_DEPTH} levels.`,
89
+ });
90
+ } else {
91
+ this.extras.push({ path, key, value: record[key] });
92
+ }
93
+ delete record[key];
94
+ }
95
+ }
96
+
97
+ styleRecords(owner: Record<string, unknown>, path: Path): void {
98
+ this.take(owner["style"], OWN_STYLE_KEYS, [...path, "style"]);
99
+ const style = owner["style"];
100
+ if (isRecord(style)) this.take(style["wide"], WIDE_KEYS, [...path, "style", "wide"]);
101
+ const states = owner["states"];
102
+ if (isRecord(states)) {
103
+ // `motion` is a known key here so the schema refuses it in a state, not kept as unknown.
104
+ for (const state of STATES) this.take(states[state], STYLE_KEYS, [...path, "states", state]);
105
+ }
106
+ const devices = owner["devices"];
107
+ if (isRecord(devices)) {
108
+ for (const device of DEVICES)
109
+ this.take(devices[device], STYLE_KEYS, [...path, "devices", device]);
110
+ }
111
+ }
112
+
113
+ node(node: unknown, path: Path): void {
114
+ if (!isRecord(node)) return;
115
+ const type = typeof node["type"] === "string" ? node["type"] : "";
116
+ const props = PROP_KEYS.get(type);
117
+ if (props) this.take(node["props"], props, [...path, "props"]);
118
+ this.styleRecords(node, path);
119
+ const query = node["query"];
120
+ if (isRecord(query)) this.take(query["style"], STYLE_KEYS, [...path, "query", "style"]);
121
+ this.take(node, NODE_KEYS, path);
122
+ const children = node["children"];
123
+ if (Array.isArray(children)) {
124
+ children.forEach((child, i) => this.node(child, [...path, "children", i]));
125
+ }
126
+ }
127
+ }
128
+
129
+ /** Sets aside a layout's unknown keys. `doc` must be a private copy; it is changed in place. */
130
+ export function splitLayoutExtras(doc: Record<string, unknown>): Splitter {
131
+ const splitter = new Splitter();
132
+ splitter.node(doc["root"], ["root"]);
133
+ return splitter;
134
+ }
135
+
136
+ /** Sets aside a design's unknown keys (class and tag-default style records). Changes `doc`. */
137
+ export function splitDesignExtras(doc: Record<string, unknown>): Splitter {
138
+ const splitter = new Splitter();
139
+ const classes = doc["classes"];
140
+ if (Array.isArray(classes)) {
141
+ classes.forEach((cls, i) => {
142
+ if (isRecord(cls)) splitter.styleRecords(cls, ["classes", i]);
143
+ });
144
+ }
145
+ const defaults = doc["defaults"];
146
+ if (isRecord(defaults)) {
147
+ for (const [tag, style] of Object.entries(defaults))
148
+ splitter.take(style, STYLE_KEYS, ["defaults", tag]);
149
+ }
150
+ return splitter;
151
+ }
152
+
153
+ /** Puts the set-aside keys back on the parsed document, untouched. Changes `doc`. */
154
+ export function restoreExtras<T>(doc: T, extras: readonly UnknownKey[]): T {
155
+ for (const { path, key, value } of extras) {
156
+ let target: unknown = doc;
157
+ for (const step of path) target = (target as Record<string | number, unknown>)?.[step];
158
+ if (isRecord(target)) target[key] = value;
159
+ }
160
+ return doc;
161
+ }
162
+
163
+ function known<T>(record: T, keys: ReadonlySet<string>): T {
164
+ if (!isRecord(record)) return record;
165
+ let extra = false;
166
+ for (const key of Object.keys(record)) if (!keys.has(key)) extra = true;
167
+ if (!extra) return record;
168
+ const out: Record<string, unknown> = {};
169
+ for (const [key, value] of Object.entries(record)) if (keys.has(key)) out[key] = value;
170
+ return out as T;
171
+ }
172
+
173
+ const FLAT_RANK = new Map([...FLAT_STYLE_KEYS].map((key, i) => [key, i]));
174
+ const rankOf = (key: string): number => FLAT_RANK.get(key) ?? -1;
175
+
176
+ /**
177
+ * The motion parts back where 0.x listed them among the other keys. A parsed style is in schema
178
+ * order, so this gives exactly the 0.x order, and with it the same CSS.
179
+ */
180
+ function inFlatOrder<T>(style: T, nested: unknown): T {
181
+ if (!isRecord(style) || !isRecord(nested) || !("motion" in nested)) return style;
182
+ const parts = Object.entries(style)
183
+ .filter(([key]) => isFlatMotionKey(key))
184
+ .toSorted(([a], [b]) => rankOf(a) - rankOf(b));
185
+ const out: Record<string, unknown> = {};
186
+ let next = 0;
187
+ for (const [key, value] of Object.entries(style)) {
188
+ if (isFlatMotionKey(key)) continue;
189
+ while (next < parts.length && rankOf((parts[next] as [string, unknown])[0]) < rankOf(key)) {
190
+ const [part, partValue] = parts[next++] as [string, unknown];
191
+ out[part] = partValue;
192
+ }
193
+ out[key] = value;
194
+ }
195
+ for (; next < parts.length; next++) {
196
+ const [part, partValue] = parts[next] as [string, unknown];
197
+ out[part] = partValue;
198
+ }
199
+ return out as T;
200
+ }
201
+
202
+ /** A stored style as the renderer reads it: 0.x flat motion keys, known keys only. */
203
+ export function renderableStyle<T>(style: T): T {
204
+ return inFlatOrder(known(flattenMotion(withoutStrayMotionKeys(style)), FLAT_STYLE_KEYS), style);
205
+ }
206
+
207
+ /**
208
+ * W-959: the renderer reads Wide screen as one more device: `style.wide` becomes `devices.wide`
209
+ * (known keys only) and its `hidden` becomes `wideHidden`. Without `style.wide` nothing changes.
210
+ */
211
+ function wideAsDevice(owner: Record<string, unknown>, out: Record<string, unknown>): void {
212
+ const style = owner["style"];
213
+ const wide = isRecord(style) ? style["wide"] : undefined;
214
+ if (!isRecord(wide)) return;
215
+ const { hidden, ...rest } = wide;
216
+ const devices = isRecord(out["devices"]) ? out["devices"] : {};
217
+ if (Object.keys(rest).length > 0) out["devices"] = { ...devices, wide: renderableStyle(rest) };
218
+ if (typeof hidden === "boolean") out["wideHidden"] = hidden;
219
+ }
220
+
221
+ function renderableStyles<T extends Record<string, unknown>>(owner: T): T {
222
+ const out: Record<string, unknown> = { ...owner };
223
+ if ("style" in owner) out["style"] = renderableStyle(owner["style"]);
224
+ const states = owner["states"];
225
+ if (isRecord(states)) {
226
+ const next: Record<string, unknown> = {};
227
+ // A state never takes motion; a forged `motion` is flattened so the CSS writer refuses its
228
+ // parts with a warning, as it did for the 0.x flat keys.
229
+ for (const [state, style] of Object.entries(states))
230
+ next[state] = known(flattenMotion(withoutStrayMotionKeys(style)), FLAT_STYLE_KEYS);
231
+ out["states"] = next;
232
+ }
233
+ const devices = owner["devices"];
234
+ if (isRecord(devices)) {
235
+ const next: Record<string, unknown> = {};
236
+ for (const [device, style] of Object.entries(devices)) next[device] = renderableStyle(style);
237
+ out["devices"] = next;
238
+ }
239
+ wideAsDevice(owner, out);
240
+ return out as T;
241
+ }
242
+
243
+ /** A node as the renderer reads it: known keys only, motion flattened (D-065). */
244
+ export function renderableNode<T>(input: T): T {
245
+ if (!isRecord(input)) return input;
246
+ const node: Record<string, unknown> = input;
247
+ const type = typeof node["type"] === "string" ? node["type"] : "";
248
+ const propKeys = PROP_KEYS.get(type);
249
+ const out: Record<string, unknown> = renderableStyles(propKeys ? known(node, NODE_KEYS) : node);
250
+ if (propKeys && isRecord(out["props"])) out["props"] = known(out["props"], propKeys);
251
+ const query = out["query"];
252
+ if (isRecord(query) && "style" in query)
253
+ out["query"] = { ...query, style: renderableStyle(query["style"]) };
254
+ const children = out["children"];
255
+ if (Array.isArray(children)) out["children"] = children.map((child) => renderableNode(child));
256
+ return out as T;
257
+ }
258
+
259
+ export function renderableLayout<T extends { root: unknown }>(layout: T): T {
260
+ return { ...layout, root: renderableNode(layout.root) };
261
+ }
262
+
263
+ export function renderableDesign<T>(design: T): T {
264
+ if (!isRecord(design)) return design;
265
+ const out: Record<string, unknown> = { ...design };
266
+ if (Array.isArray(design["classes"])) {
267
+ out["classes"] = design["classes"].map((cls: unknown) =>
268
+ isRecord(cls) ? renderableStyles(cls) : cls,
269
+ );
270
+ }
271
+ if (isRecord(design["defaults"])) {
272
+ const defaults: Record<string, unknown> = {};
273
+ for (const [tag, style] of Object.entries(design["defaults"]))
274
+ defaults[tag] = renderableStyle(style);
275
+ out["defaults"] = defaults;
276
+ }
277
+ return out as T;
278
+ }
279
+
280
+ function lazyTemplates<T>(templates: Record<string, T> | undefined): Record<string, T> | undefined {
281
+ if (!templates) return templates;
282
+ const out: Record<string, T> = {};
283
+ for (const id of Object.keys(templates)) {
284
+ let cached: T | undefined;
285
+ Object.defineProperty(out, id, {
286
+ enumerable: true,
287
+ get: () => (cached ??= renderableLayout(templates[id] as T & { root: unknown })),
288
+ });
289
+ }
290
+ return out;
291
+ }
292
+
293
+ /** Theme templates as the renderer reads them, converted when first used. */
294
+ export function renderableDynamic<
295
+ T extends { sectionTemplates?: Record<string, unknown>; loopTemplates?: Record<string, unknown> },
296
+ >(dynamic: T | undefined): T | undefined {
297
+ if (!dynamic || (!dynamic.sectionTemplates && !dynamic.loopTemplates)) return dynamic;
298
+ return {
299
+ ...dynamic,
300
+ ...(dynamic.sectionTemplates
301
+ ? { sectionTemplates: lazyTemplates(dynamic.sectionTemplates) }
302
+ : {}),
303
+ ...(dynamic.loopTemplates ? { loopTemplates: lazyTemplates(dynamic.loopTemplates) } : {}),
304
+ };
305
+ }
@@ -1,3 +1,5 @@
1
+ import { cssTypeName } from "../schema/layout.ts";
2
+ import { MARK_CSS } from "../text-marks.ts";
1
3
  import { DEFAULT_FLUID_RANGE, fluidClamp } from "../design/tokens.ts";
2
4
  import type { FluidRange, LengthVariable } from "../schema/design.ts";
3
5
  import type { DesignSystem } from "../schema/design.ts";
@@ -17,8 +19,8 @@ import {
17
19
  type StateDeclarations,
18
20
  } from "../sanitize/css.ts";
19
21
  import { STYLE_STATES, type StyleStateName } from "../schema/state-names.ts";
20
- import { DEVICE_MEDIA, type PopupDevice } from "../theme/popup-rules.ts";
21
- import { MOTION_KEYFRAMES } from "../sanitize/motion.ts";
22
+ import { DEVICE_MEDIA, type Device, type EditorDevice } from "../theme/popup-rules.ts";
23
+ import { LOOP_KEYFRAMES, MOTION_KEYFRAMES } from "../sanitize/motion.ts";
22
24
 
23
25
  export type CssInput = {
24
26
  design: DesignSystem;
@@ -28,10 +30,14 @@ export type CssInput = {
28
30
  id: string;
29
31
  declarations: Declaration[];
30
32
  states?: StateDeclarations;
31
- /** Tablet and mobile overrides (W-096). Desktop stays in `declarations`. */
33
+ /** W-959: Wide screen overrides (2400 px and up), and its hide override. */
34
+ wide?: Declaration[];
35
+ wideHidden?: boolean;
36
+ /** Laptop (W-956), tablet and mobile overrides (W-096). Desktop stays in `declarations`. */
37
+ laptop?: Declaration[];
32
38
  tablet?: Declaration[];
33
39
  mobile?: Declaration[];
34
- hiddenOn?: readonly PopupDevice[];
40
+ hiddenOn?: readonly Device[];
35
41
  /** W-443: an image with a caption, rendered inside a figure that hides with it. */
36
42
  figure?: boolean;
37
43
  /** Container-query overrides (W-346). */
@@ -42,14 +48,34 @@ export type CssInput = {
42
48
  previewStates?: boolean;
43
49
  /** When a node rendered a background video (W-110). */
44
50
  backgroundVideo?: boolean;
51
+ /** W-952: when a List is drawn as numbered steps. */
52
+ listSteps?: boolean;
45
53
  /**
46
54
  * Editor canvas only (W-116): the device the canvas previews. Device rules then follow this
47
55
  * device instead of the frame's width, so the Desktop canvas never picks up tablet styles in a
48
56
  * narrow window. Without it, the rules sit in their media queries as usual.
49
57
  */
50
- previewDevice?: PopupDevice;
58
+ previewDevice?: EditorDevice;
51
59
  };
52
60
 
61
+ /**
62
+ * W-959: a class's Wide screen overrides and hide. `renderableDesign` moved the class's
63
+ * `style.wide` to `devices.wide` and `wideHidden`; the values build on Desktop's.
64
+ */
65
+ function classWide(cls: unknown): { wide: Declaration[]; wideHidden?: boolean } {
66
+ const { style, devices, wideHidden } = cls as {
67
+ style?: unknown;
68
+ devices?: { wide?: unknown };
69
+ wideHidden?: unknown;
70
+ };
71
+ return {
72
+ wide: devices?.wide
73
+ ? styleDeclarations(withInheritedLayers(devices.wide, style ?? {})).declarations
74
+ : [],
75
+ ...(typeof wideHidden === "boolean" ? { wideHidden } : {}),
76
+ };
77
+ }
78
+
53
79
  /** Focus is keyboard focus (W-089): `:focus-visible`, never `:focus`. */
54
80
  const STATE_PSEUDO: Readonly<Record<StyleStateName, string>> = {
55
81
  hover: ":hover",
@@ -123,6 +149,10 @@ function declare<T extends { id: string }>(
123
149
  const usesMotion = (declarations: readonly Declaration[]) =>
124
150
  declarations.some((d) => d.property === "animation" && /\bemvb-m[otsrb]\b/.test(d.value));
125
151
 
152
+ /** W-938: declarations that play a loop. */
153
+ const usesLoop = (declarations: readonly Declaration[]) =>
154
+ declarations.some((d) => d.property === "animation" && /\bemvb-l[otsrb]\b/.test(d.value));
155
+
126
156
  /**
127
157
  * Cascade order (R-021 / W-030 / W-089): variables on `.emvb-root`, base CSS, shared
128
158
  * `.emvb-k-<id>` class rules, then local `.emvb-e-<id>` (local wins). Each selector's `:hover`,
@@ -130,6 +160,22 @@ const usesMotion = (declarations: readonly Declaration[]) =>
130
160
  * local states beat class states, and Active beats Hover when both apply. Transitions sit on the
131
161
  * base rule, and one closing `prefers-reduced-motion: reduce` block turns them all off.
132
162
  */
163
+ /**
164
+ * The element base rules for these types, in the order every sheet writes them (W-971 reads
165
+ * the same order to write them once for all theme parts on a page).
166
+ */
167
+ export function baseRulesFor(
168
+ types: Iterable<string>,
169
+ baseCss: ReadonlyMap<string, string>,
170
+ ): string {
171
+ return [...types]
172
+ .toSorted((a, b) =>
173
+ cssTypeName(a) < cssTypeName(b) ? -1 : cssTypeName(a) > cssTypeName(b) ? 1 : 0,
174
+ )
175
+ .map((type) => baseCss.get(type) ?? "")
176
+ .join("");
177
+ }
178
+
133
179
  export function generateCss({
134
180
  design,
135
181
  usedTypes,
@@ -137,6 +183,7 @@ export function generateCss({
137
183
  localRules,
138
184
  previewStates = false,
139
185
  backgroundVideo = false,
186
+ listSteps = false,
140
187
  previewDevice,
141
188
  }: CssInput): string {
142
189
  const { colors, fonts, fontSizes, spacings } = design.variables;
@@ -150,6 +197,8 @@ export function generateCss({
150
197
  const entrances: string[] = [];
151
198
  /** W-319: any scroll motion on the page, so its keyframes are sent. */
152
199
  let motion = false;
200
+ /** W-938: any loop on the page, so its keyframes are sent. */
201
+ let loops = false;
153
202
  const rules = (selector: string, declarations: Declaration[], states: StateDeclarations) => [
154
203
  block(selector, declarations),
155
204
  ...STYLE_STATES.map((state) =>
@@ -165,6 +214,7 @@ export function generateCss({
165
214
  if (declarations.some((d) => d.property === "transition")) animated.push(selector);
166
215
  if (declarations.some((d) => d.property === "animation")) entrances.push(selector);
167
216
  if (usesMotion(declarations)) motion = true;
217
+ if (usesLoop(declarations)) loops = true;
168
218
  return declarations;
169
219
  };
170
220
  const classes = (design.classes ?? []).flatMap((cls) => {
@@ -187,11 +237,19 @@ export function generateCss({
187
237
  ? [
188
238
  {
189
239
  selector: `.${className}`,
240
+ ...classWide(cls),
190
241
  // W-210: a device that sets one background layer keeps the layers it inherits.
191
- tablet: styleDeclarations(withInheritedLayers(cls.devices?.tablet, cls.style ?? {}))
242
+ laptop: styleDeclarations(withInheritedLayers(cls.devices?.laptop, cls.style ?? {}))
192
243
  .declarations,
244
+ tablet: styleDeclarations(
245
+ withInheritedLayers(cls.devices?.tablet, { ...cls.style, ...cls.devices?.laptop }),
246
+ ).declarations,
193
247
  mobile: styleDeclarations(
194
- withInheritedLayers(cls.devices?.mobile, { ...cls.style, ...cls.devices?.tablet }),
248
+ withInheritedLayers(cls.devices?.mobile, {
249
+ ...cls.style,
250
+ ...cls.devices?.laptop,
251
+ ...cls.devices?.tablet,
252
+ }),
195
253
  ).declarations,
196
254
  hiddenOn: cls.hiddenOn,
197
255
  // W-571: the page root is never hidden (W-567), not even by a class.
@@ -202,6 +260,9 @@ export function generateCss({
202
260
  }),
203
261
  ...localRules.map((rule) => ({
204
262
  selector: `.emvb-e-${rule.id}`,
263
+ wide: rule.wide ?? [],
264
+ wideHidden: rule.wideHidden,
265
+ laptop: rule.laptop ?? [],
205
266
  tablet: rule.tablet ?? [],
206
267
  mobile: rule.mobile ?? [],
207
268
  hiddenOn: rule.hiddenOn,
@@ -209,37 +270,77 @@ export function generateCss({
209
270
  })),
210
271
  ];
211
272
  /** A device block: in its media query, or, for a previewed device, on or off outright. */
212
- const forDevices = (devices: readonly PopupDevice[], query: string, body: string) => {
273
+ const forDevices = (devices: readonly EditorDevice[], query: string, body: string) => {
213
274
  if (!body) return "";
214
275
  if (previewDevice === undefined) return `@media ${query}{${body}}`;
215
276
  return devices.includes(previewDevice) ? body : "";
216
277
  };
217
- const at = (query: string, which: "tablet" | "mobile") =>
278
+ const at = (query: string, which: "wide" | "laptop" | "tablet" | "mobile") =>
218
279
  forDevices(
219
- which === "tablet" ? ["tablet", "mobile"] : ["mobile"],
280
+ which === "wide"
281
+ ? ["wide"]
282
+ : which === "laptop"
283
+ ? ["laptop", "tablet", "mobile"]
284
+ : which === "tablet"
285
+ ? ["tablet", "mobile"]
286
+ : ["mobile"],
220
287
  query,
221
288
  responsive.map((rule) => block(rule.selector, rule[which])).join(""),
222
289
  );
223
- const hide = (device: PopupDevice, query: string) => {
290
+ /**
291
+ * W-956: Desktop and Laptop hidden together keep the one `min-width: 1025px` rule every page
292
+ * saved before Laptop had; hidden on only one of them, each gets its own range.
293
+ */
294
+ /**
295
+ * W-959: Wide screen follows Desktop's hide unless `wide.hidden` says otherwise. An element
296
+ * that Wide screen shows again gets a Desktop range that stops at 2399.98 px (`notWide`); one
297
+ * hidden on Wide screen only gets the Wide screen rule. Rules without `wide.hidden` keep the
298
+ * CSS they had.
299
+ */
300
+ type HideRule = { hiddenOn?: readonly Device[] | undefined; wideHidden?: boolean | undefined };
301
+ const hide = (
302
+ devices: readonly Device[],
303
+ query: string,
304
+ wide: "follows" | "notWide" | "only" = "follows",
305
+ ) => {
306
+ const hidden = (rule: HideRule) => {
307
+ const on = rule.hiddenOn ?? [];
308
+ if (wide === "only") return rule.wideHidden === true && !on.includes("desktop");
309
+ if (devices.includes("desktop") && (rule.wideHidden === false) !== (wide === "notWide"))
310
+ return false;
311
+ if (devices.includes("desktop") && devices.includes("laptop"))
312
+ return on.includes("desktop") && on.includes("laptop");
313
+ if (devices[0] === "desktop") return on.includes("desktop") && !on.includes("laptop");
314
+ if (devices[0] === "laptop") return on.includes("laptop") && !on.includes("desktop");
315
+ return on.includes(devices[0] as Device);
316
+ };
317
+ const previewed: EditorDevice[] =
318
+ wide === "only"
319
+ ? ["wide"]
320
+ : wide === "follows" && devices.includes("desktop")
321
+ ? ["wide", ...devices]
322
+ : [...devices];
224
323
  // W-443: a captioned image hides its figure too, or the caption stayed on its own.
225
324
  const selectors = responsive
226
- .filter((rule) => rule.hiddenOn?.includes(device))
325
+ .filter(hidden)
227
326
  .flatMap((rule) =>
228
327
  "figure" in rule && rule.figure
229
328
  ? [rule.selector, `.emvb-figure:has(>${rule.selector},>a>${rule.selector})`]
230
329
  : ["hideSelector" in rule && rule.hideSelector ? rule.hideSelector : rule.selector],
231
330
  );
232
331
  return forDevices(
233
- [device],
332
+ previewed,
234
333
  query,
235
334
  selectors.length > 0 ? `${selectors.join(",")}{display:none}` : "",
236
335
  );
237
336
  };
238
337
  for (const rule of responsive) {
239
- if (usesMotion(rule.tablet) || usesMotion(rule.mobile)) motion = true;
338
+ const devices = [rule.wide ?? [], rule.laptop, rule.tablet, rule.mobile];
339
+ if (devices.some(usesMotion)) motion = true;
340
+ if (devices.some(usesLoop)) loops = true;
240
341
  if (
241
342
  !entrances.includes(rule.selector) &&
242
- [...rule.tablet, ...rule.mobile].some((d) => d.property === "animation")
343
+ devices.flat().some((d) => d.property === "animation")
243
344
  ) {
244
345
  entrances.push(rule.selector);
245
346
  }
@@ -251,6 +352,7 @@ export function generateCss({
251
352
  const query = rule.query ?? [];
252
353
  const selector = `.emvb-e-${rule.id}`;
253
354
  if (usesMotion(query)) motion = true;
355
+ if (usesLoop(query)) loops = true;
254
356
  if (!entrances.includes(selector) && query.some((d) => d.property === "animation")) {
255
357
  entrances.push(selector);
256
358
  }
@@ -258,11 +360,12 @@ export function generateCss({
258
360
  animated.push(selector);
259
361
  }
260
362
  }
261
- return [
363
+ const sheet = [
262
364
  entrances.length > 0
263
365
  ? "@keyframes emvb-fade{from{opacity:0}to{opacity:1}}@keyframes emvb-fade-up{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}@keyframes emvb-fade-down{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:none}}@keyframes emvb-slide-up{from{opacity:0;transform:translateY(16px)}to{opacity:1;transform:none}}@keyframes emvb-slide-down{from{opacity:0;transform:translateY(-16px)}to{opacity:1;transform:none}}@keyframes emvb-scale{from{opacity:0;transform:scale(0.96)}to{opacity:1;transform:none}}"
264
366
  : "",
265
367
  entrances.length > 0 && motion ? MOTION_KEYFRAMES : "",
368
+ entrances.length > 0 && loops ? LOOP_KEYFRAMES : "",
266
369
  block(".emvb-root", variables),
267
370
  defaultsCss,
268
371
  backgroundVideo
@@ -272,7 +375,7 @@ export function generateCss({
272
375
  // W-801: a looping video kept playing for visitors who ask for reduced motion.
273
376
  "@media (prefers-reduced-motion: reduce){.emvb-bg-video{display:none}}"
274
377
  : "",
275
- ...[...usedTypes].toSorted().map((type) => baseCss.get(type) ?? ""),
378
+ baseRulesFor(usedTypes, baseCss),
276
379
  ...classes,
277
380
  ...locals,
278
381
  ...localRules
@@ -281,11 +384,18 @@ export function generateCss({
281
384
  (rule) =>
282
385
  `@container (min-width:${rule.queryMin}px){${block(`.emvb-e-${rule.id}`, rule.query ?? [])}}`,
283
386
  ),
387
+ at(DEVICE_MEDIA.wide, "wide"),
388
+ at(DEVICE_MEDIA.laptop, "laptop"),
284
389
  at(DEVICE_MEDIA.tablet, "tablet"),
285
390
  at(DEVICE_MEDIA.mobile, "mobile"),
286
- hide("desktop", DEVICE_MEDIA.hideDesktop),
287
- hide("tablet", DEVICE_MEDIA.hideTablet),
288
- hide("mobile", DEVICE_MEDIA.hideMobile),
391
+ hide(["desktop", "laptop"], DEVICE_MEDIA.hideDesktop),
392
+ hide(["desktop"], DEVICE_MEDIA.hideDesktopOnly),
393
+ hide(["desktop", "laptop"], DEVICE_MEDIA.hideDesktopNotWide, "notWide"),
394
+ hide(["desktop"], DEVICE_MEDIA.hideDesktopOnlyNotWide, "notWide"),
395
+ hide([], DEVICE_MEDIA.wide, "only"),
396
+ hide(["laptop"], DEVICE_MEDIA.hideLaptop),
397
+ hide(["tablet"], DEVICE_MEDIA.hideTablet),
398
+ hide(["mobile"], DEVICE_MEDIA.hideMobile),
289
399
  animated.length > 0
290
400
  ? `@media (prefers-reduced-motion: reduce){${animated.join(",")}{transition:none}}`
291
401
  : "",
@@ -293,4 +403,25 @@ export function generateCss({
293
403
  ? `@media (prefers-reduced-motion: reduce){${entrances.join(",")}{animation:none}}`
294
404
  : "",
295
405
  ].join("");
406
+ // W-952: list marker colour and size, and numbered steps, only on pages that use them, so
407
+ // every page saved before them keeps the exact CSS it had.
408
+ return [
409
+ sheet,
410
+ sheet.includes("--emvb-marker-") ? LIST_MARKER_CSS : "",
411
+ listSteps ? LIST_STEPS_CSS : "",
412
+ sheet.includes("--emvb-mark-") ? MARK_CSS : "",
413
+ ].join("");
296
414
  }
415
+
416
+ /** Markers take the list's marker colour and size when it sets them (W-952). */
417
+ const LIST_MARKER_CSS =
418
+ ".emvb-list>li::marker{color:var(--emvb-marker-color,inherit);font-size:var(--emvb-marker-size,inherit)}";
419
+
420
+ /**
421
+ * Numbered steps (W-952): each number in a circle beside its item, counted by the list's own
422
+ * `list-item` counter so Start at still applies.
423
+ */
424
+ const LIST_STEPS_CSS =
425
+ ".emvb-list--steps{list-style:none;padding-inline-start:0;display:flex;flex-direction:column;gap:0.75em}" +
426
+ ".emvb-list--steps>li{display:flex;align-items:flex-start;gap:0.75em;counter-increment:list-item}" +
427
+ ".emvb-list--steps>li::before{content:counter(list-item);flex:none;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;min-width:2em;height:2em;padding:0 0.4em;border-radius:999px;border:2px solid var(--emvb-marker-color,currentColor);color:var(--emvb-marker-color,currentColor);font-size:var(--emvb-marker-size,1em);font-weight:600;line-height:1}";
@@ -61,7 +61,15 @@ const GROUPING_AT_RULE = /^@(media|supports|container|layer)\b/;
61
61
 
62
62
  /** Prefixes every style rule in `css`, inside `@media` and `@supports` too. Keyframes stay as they are. */
63
63
  export function scopeCss(css: string, token: string): string {
64
- const prefix = `:where(.${scopeClass(token)}) `;
64
+ return scopeWith(css, `:where(.${scopeClass(token)}) `);
65
+ }
66
+
67
+ /** W-971: the same, scoped to several renders at once (`:where(.emvb-s-a,.emvb-s-b) `). */
68
+ export function scopeCssAll(css: string, tokens: readonly string[]): string {
69
+ return scopeWith(css, `:where(${tokens.map((t) => `.${scopeClass(t)}`).join(",")}) `);
70
+ }
71
+
72
+ function scopeWith(css: string, prefix: string): string {
65
73
  let out = "";
66
74
  let i = 0;
67
75
  while (i < css.length) {
@@ -74,7 +82,7 @@ export function scopeCss(css: string, token: string): string {
74
82
  const end = blockEnd(css, open);
75
83
  const body = css.slice(open + 1, end - 1);
76
84
  if (GROUPING_AT_RULE.test(prelude)) {
77
- out += `${prelude}{${scopeCss(body, token)}}`;
85
+ out += `${prelude}{${scopeWith(body, prefix)}}`;
78
86
  } else if (prelude.startsWith("@")) {
79
87
  out += css.slice(i, end).trim();
80
88
  } else {