@perkyzz/emvb 0.8.0 → 1.0.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 (179) hide show
  1. package/README.md +3 -3
  2. package/package.json +4 -4
  3. package/src/admin/agents-api.ts +45 -0
  4. package/src/admin/editor/A11yCopilot.tsx +1 -1
  5. package/src/admin/editor/Editor.tsx +325 -239
  6. package/src/admin/editor/FieldPreview.tsx +164 -0
  7. package/src/admin/editor/Timeline.tsx +2 -1
  8. package/src/admin/editor/TopBar.tsx +36 -3
  9. package/src/admin/editor/canvas/CanvasFrame.tsx +2 -2
  10. package/src/admin/editor/canvas/DeviceBar.tsx +17 -9
  11. package/src/admin/editor/canvas/canvas-scale.ts +2 -2
  12. package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
  13. package/src/admin/editor/co-design.ts +190 -0
  14. package/src/admin/editor/dnd/new-element.ts +26 -4
  15. package/src/admin/editor/editor-chrome.tsx +3 -3
  16. package/src/admin/editor/editor-commands.ts +8 -3
  17. package/src/admin/editor/editor-css.ts +3 -0
  18. package/src/admin/editor/element-chrome.ts +3 -1
  19. package/src/admin/editor/extension-manifests.ts +20 -0
  20. package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
  21. package/src/admin/editor/extensions-context.tsx +27 -0
  22. package/src/admin/editor/feature-css.ts +17 -0
  23. package/src/admin/editor/host.ts +6 -0
  24. package/src/admin/editor/palette-items.ts +2 -2
  25. package/src/admin/editor/panels/AddPanel.tsx +31 -1
  26. package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
  27. package/src/admin/editor/panels/ClassesSection.tsx +9 -6
  28. package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
  29. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  30. package/src/admin/editor/panels/ElementPanel.tsx +53 -15
  31. package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
  32. package/src/admin/editor/panels/LayersPanel.tsx +10 -6
  33. package/src/admin/editor/panels/LeftPanel.tsx +33 -5
  34. package/src/admin/editor/panels/PageSettings.tsx +4 -0
  35. package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
  36. package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
  37. package/src/admin/editor/panels/settings/BackgroundControls.tsx +76 -20
  38. package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
  39. package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
  40. package/src/admin/editor/panels/settings/EffectsControls.tsx +104 -9
  41. package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
  42. package/src/admin/editor/panels/settings/IconControls.tsx +14 -11
  43. package/src/admin/editor/panels/settings/LengthRow.tsx +27 -16
  44. package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
  45. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  46. package/src/admin/editor/panels/settings/MediaPicker.tsx +5 -5
  47. package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
  48. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
  49. package/src/admin/editor/panels/settings/StyleRow.tsx +113 -13
  50. package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
  51. package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
  52. package/src/admin/editor/panels/settings/background-mode.ts +14 -11
  53. package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
  54. package/src/admin/editor/panels/settings/box-sides.ts +22 -14
  55. package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
  56. package/src/admin/editor/panels/settings/length-units.ts +55 -2
  57. package/src/admin/editor/panels/settings/query-style.ts +3 -3
  58. package/src/admin/editor/panels/settings/style-sections.ts +51 -10
  59. package/src/admin/editor/panels/style-target.ts +9 -7
  60. package/src/admin/editor/presence.ts +60 -0
  61. package/src/admin/editor/store.ts +6 -2
  62. package/src/admin/editor/useCoDesign.ts +177 -0
  63. package/src/admin/editor/useEditorCommands.ts +4 -4
  64. package/src/admin/editor/useExtensions.ts +45 -0
  65. package/src/admin/editor/useNodeActions.ts +15 -6
  66. package/src/admin/editor/useProposals.ts +81 -0
  67. package/src/admin/index.tsx +5 -1
  68. package/src/admin/languages-api.ts +61 -0
  69. package/src/admin/media-api.ts +27 -0
  70. package/src/admin/pages/AgentSetup.tsx +148 -0
  71. package/src/admin/pages/AgentsPage.tsx +11 -28
  72. package/src/admin/pages/CollectionsPage.tsx +215 -0
  73. package/src/admin/pages/CreateDialog.tsx +15 -0
  74. package/src/admin/pages/ImportButton.tsx +18 -0
  75. package/src/admin/pages/ImportElementorDialog.tsx +669 -0
  76. package/src/admin/pages/ImportPageLinks.tsx +86 -0
  77. package/src/admin/pages/PageList.tsx +15 -1
  78. package/src/admin/pages/ThemePartList.tsx +15 -1
  79. package/src/admin/pages/section-head.tsx +27 -0
  80. package/src/admin/proposals-api.ts +91 -0
  81. package/src/admin/setup/host-collections.ts +100 -0
  82. package/src/admin/ui.ts +39 -2
  83. package/src/admin/widgets/CanvasField.tsx +202 -0
  84. package/src/admin/widgets/convert-body.ts +54 -0
  85. package/src/admin/widgets/field-fetcher.ts +79 -0
  86. package/src/astro/content-port.ts +14 -1
  87. package/src/astro/index.ts +2 -0
  88. package/src/astro/page-count.ts +77 -0
  89. package/src/astro/resolve-theme.ts +58 -3
  90. package/src/astro/resolve.ts +128 -5
  91. package/src/astro/responsive-images.ts +99 -0
  92. package/src/constants.ts +1 -1
  93. package/src/core/a11y/audit.ts +44 -14
  94. package/src/core/arrange.ts +5 -1
  95. package/src/core/bounded-array.ts +31 -0
  96. package/src/core/canvas-collections.ts +20 -0
  97. package/src/core/clipboard.ts +9 -0
  98. package/src/core/contract.ts +285 -0
  99. package/src/core/css/generate.ts +89 -20
  100. package/src/core/css/trace.ts +18 -9
  101. package/src/core/css-keywords.ts +51 -1
  102. package/src/core/design/cascade.ts +12 -9
  103. package/src/core/design/classes.ts +4 -5
  104. package/src/core/design/devices.ts +13 -13
  105. package/src/core/design/states.ts +5 -3
  106. package/src/core/design/transfer.ts +5 -0
  107. package/src/core/design/variables.ts +17 -4
  108. package/src/core/elements/dynamic-elements.ts +19 -4
  109. package/src/core/elements/index.ts +73 -9
  110. package/src/core/extensions/define.ts +13 -0
  111. package/src/core/extensions/index.ts +41 -0
  112. package/src/core/extensions/namespace.ts +82 -0
  113. package/src/core/extensions/normalize.ts +141 -0
  114. package/src/core/extensions/placeholder.ts +41 -0
  115. package/src/core/extensions/registry.ts +94 -0
  116. package/src/core/extensions/render-ext.ts +118 -0
  117. package/src/core/extensions/safe-nodes.ts +93 -0
  118. package/src/core/extensions/schema.ts +112 -0
  119. package/src/core/extensions/types.ts +159 -0
  120. package/src/core/forms/binding.ts +1 -1
  121. package/src/core/history/diff.ts +1 -1
  122. package/src/core/import/elementor/atomic.ts +1595 -0
  123. package/src/core/import/elementor/classes.ts +127 -0
  124. package/src/core/import/elementor/context.ts +429 -0
  125. package/src/core/import/elementor/counter-steps.ts +72 -0
  126. package/src/core/import/elementor/css.ts +445 -0
  127. package/src/core/import/elementor/html.ts +500 -0
  128. package/src/core/import/elementor/index.ts +949 -0
  129. package/src/core/import/elementor/inline-marks.ts +81 -0
  130. package/src/core/import/elementor/snapshots.ts +48 -0
  131. package/src/core/import/elementor/style.ts +409 -0
  132. package/src/core/import/elementor/values.ts +241 -0
  133. package/src/core/import/elementor/widgets.ts +1897 -0
  134. package/src/core/index.ts +84 -0
  135. package/src/core/json-schema.ts +107 -0
  136. package/src/core/limits.ts +19 -0
  137. package/src/core/migrate/index.ts +6 -1
  138. package/src/core/migrate/v18.ts +222 -0
  139. package/src/core/perf/meter.ts +5 -5
  140. package/src/core/portable-text.ts +127 -0
  141. package/src/core/proposals-safety.ts +102 -0
  142. package/src/core/proposals.ts +357 -0
  143. package/src/core/recipes/index.ts +2 -2
  144. package/src/core/render/extras.ts +3 -3
  145. package/src/core/render/index.ts +140 -20
  146. package/src/core/render/loop.ts +1 -1
  147. package/src/core/render/pagination.ts +20 -1
  148. package/src/core/render/section.ts +4 -4
  149. package/src/core/render/vnode.ts +1 -1
  150. package/src/core/sanitize/css.ts +125 -10
  151. package/src/core/sanitize/motion.ts +116 -0
  152. package/src/core/saved-sections.ts +6 -0
  153. package/src/core/schema/descriptors.ts +3 -1
  154. package/src/core/schema/design.ts +2 -1
  155. package/src/core/schema/layout.ts +87 -14
  156. package/src/core/schema/style.ts +251 -114
  157. package/src/core/text-marks.ts +227 -0
  158. package/src/core/theme/dynamic.ts +9 -4
  159. package/src/core/theme/float.ts +1 -0
  160. package/src/core/theme/pagination.ts +9 -0
  161. package/src/core/theme/popup-rules.ts +17 -1
  162. package/src/core/translatable.ts +34 -0
  163. package/src/core/validate.ts +13 -1
  164. package/src/index.ts +35 -1
  165. package/src/mcp/errors.ts +3 -1
  166. package/src/mcp/ports.ts +67 -0
  167. package/src/mcp/prompts.ts +1 -11
  168. package/src/mcp/proposals.ts +281 -0
  169. package/src/mcp/read.ts +10 -9
  170. package/src/mcp/tools.ts +71 -3
  171. package/src/mcp/write.ts +66 -11
  172. package/src/server/agent-settings.ts +21 -2
  173. package/src/server/hooks.ts +81 -0
  174. package/src/server/mcp-routes.ts +15 -0
  175. package/src/server/plugin.ts +53 -5
  176. package/src/server/presence.ts +78 -0
  177. package/src/server/proposals.ts +261 -0
  178. package/src/server/requests.ts +196 -0
  179. package/src/server/tools-served.ts +45 -0
@@ -0,0 +1,247 @@
1
+ import { Button, Checkbox, Input } from "@cloudflare/kumo";
2
+ import { LinkSimpleIcon, TextBIcon, TextItalicIcon, XIcon } from "@phosphor-icons/react";
3
+ import * as React from "react";
4
+ import {
5
+ hasFormat,
6
+ type LayoutNode,
7
+ MAX_TEXT_MARKS,
8
+ type MarkFormat,
9
+ sanitizeHref,
10
+ setFormat,
11
+ type TextMark,
12
+ unsetFormat,
13
+ } from "../../../../core/index.ts";
14
+ import { BUTTON, FIELD } from "../../../ui.ts";
15
+ import { propsOf, withProp } from "./node-props.ts";
16
+
17
+ type Range = { start: number; end: number };
18
+
19
+ /** The element's Text field, next to this control in the panel. */
20
+ function textField(from: HTMLElement | null): HTMLInputElement | HTMLTextAreaElement | null {
21
+ const scope =
22
+ from?.closest("[data-emvb-fields]") ?? from?.parentElement?.parentElement ?? document;
23
+ const holder = scope.querySelector('[data-emvb-field="text"]');
24
+ if (holder instanceof HTMLInputElement || holder instanceof HTMLTextAreaElement) return holder;
25
+ return holder?.querySelector("textarea, input") ?? null;
26
+ }
27
+
28
+ /** Buttons keep the Text field's selection: pressing one doesn't move focus there first. */
29
+ const keep = (event: React.MouseEvent) => event.preventDefault();
30
+
31
+ const describe = (mark: TextMark): string =>
32
+ [
33
+ mark.bold ? "Bold" : null,
34
+ mark.italic ? "Italic" : null,
35
+ typeof mark.color === "string" ? `Color ${mark.color}` : mark.color ? "Color" : null,
36
+ mark.href ? `Link ${mark.href}${mark.newTab ? " (new tab)" : ""}` : null,
37
+ ]
38
+ .filter(Boolean)
39
+ .join(", ");
40
+
41
+ /**
42
+ * Formatting (W-950): bold, italic, colour and links on the words selected in the Text field.
43
+ * The text stays plain; each format is a range over it, listed below with a Remove button.
44
+ */
45
+ export function TextMarksControl({
46
+ node,
47
+ onChange,
48
+ }: {
49
+ node: LayoutNode;
50
+ onChange: (node: LayoutNode) => void;
51
+ }) {
52
+ const props = propsOf(node);
53
+ const text = typeof props["text"] === "string" ? props["text"] : "";
54
+ const marks = Array.isArray(props["marks"]) ? (props["marks"] as TextMark[]) : [];
55
+ const ref = React.useRef<HTMLDivElement>(null);
56
+ const colorRef = React.useRef<HTMLInputElement>(null);
57
+ const [message, setMessage] = React.useState<string>();
58
+ const [linkFor, setLinkFor] = React.useState<Range>();
59
+ const [href, setHref] = React.useState("");
60
+ const [newTab, setNewTab] = React.useState(false);
61
+ const linkedHeading = node.type === "heading" && typeof props["href"] === "string";
62
+
63
+ /** The selected words, or a message saying why there are none. */
64
+ const selection = (): Range | undefined => {
65
+ const field = textField(ref.current);
66
+ if (!field) return undefined;
67
+ if (field.value !== text) {
68
+ setMessage("Finish editing the text first (press Enter or leave the field).");
69
+ return undefined;
70
+ }
71
+ const start = field.selectionStart ?? 0;
72
+ const end = field.selectionEnd ?? 0;
73
+ if (end <= start) {
74
+ setMessage("Select some words in the Text field first.");
75
+ return undefined;
76
+ }
77
+ setMessage(undefined);
78
+ return { start, end };
79
+ };
80
+
81
+ const save = (next: TextMark[]) => {
82
+ if (next.length > MAX_TEXT_MARKS) {
83
+ setMessage(`A text can have up to ${MAX_TEXT_MARKS} formatted parts.`);
84
+ return;
85
+ }
86
+ onChange(withProp(node, "marks", next.length > 0 ? next : undefined));
87
+ };
88
+
89
+ const toggle = (format: Extract<MarkFormat, "bold" | "italic">) => {
90
+ const range = selection();
91
+ if (!range) return;
92
+ save(
93
+ hasFormat(marks, range.start, range.end, format)
94
+ ? unsetFormat(marks, range.start, range.end, format)
95
+ : setFormat(marks, range.start, range.end, { [format]: true }),
96
+ );
97
+ };
98
+
99
+ // A colour is applied when the picker closes, not on every step of a drag.
100
+ React.useEffect(() => {
101
+ const input = colorRef.current;
102
+ if (!input) return;
103
+ const apply = () => {
104
+ const range = selection();
105
+ if (range) save(setFormat(marks, range.start, range.end, { color: input.value }));
106
+ };
107
+ input.addEventListener("change", apply);
108
+ return () => input.removeEventListener("change", apply);
109
+ });
110
+
111
+ const applyLink = () => {
112
+ if (!linkFor) return;
113
+ const safe = sanitizeHref(href.trim());
114
+ if (!safe) {
115
+ setMessage("Enter a link such as /contact or https://example.com.");
116
+ return;
117
+ }
118
+ save(
119
+ setFormat(marks, linkFor.start, linkFor.end, {
120
+ href: safe,
121
+ ...(newTab ? { newTab: true } : {}),
122
+ }),
123
+ );
124
+ setLinkFor(undefined);
125
+ };
126
+
127
+ const clear = () => {
128
+ const range = selection();
129
+ if (!range) return;
130
+ let next = marks;
131
+ for (const format of ["bold", "italic", "color", "href"] as const)
132
+ next = unsetFormat(next, range.start, range.end, format);
133
+ save(next);
134
+ };
135
+
136
+ return (
137
+ <div ref={ref} className="emvb-marks" data-emvb-field="marks">
138
+ <span className="emvb-import-label">Formatting</span>
139
+ <div className="emvb-marks-bar" role="toolbar" aria-label="Formatting">
140
+ <Button
141
+ type="button"
142
+ variant="secondary"
143
+ className={BUTTON}
144
+ aria-label="Bold"
145
+ icon={<TextBIcon aria-hidden="true" />}
146
+ onMouseDown={keep}
147
+ onClick={() => toggle("bold")}
148
+ />
149
+ <Button
150
+ type="button"
151
+ variant="secondary"
152
+ className={BUTTON}
153
+ aria-label="Italic"
154
+ icon={<TextItalicIcon aria-hidden="true" />}
155
+ onMouseDown={keep}
156
+ onClick={() => toggle("italic")}
157
+ />
158
+ <label className="emvb-marks-color">
159
+ <span className="emvb-helper">Color</span>
160
+ <input
161
+ ref={colorRef}
162
+ type="color"
163
+ aria-label="Color of selected words"
164
+ defaultValue="#000000"
165
+ />
166
+ </label>
167
+ {!linkedHeading && (
168
+ <Button
169
+ type="button"
170
+ variant="secondary"
171
+ className={BUTTON}
172
+ aria-label="Link selected words"
173
+ icon={<LinkSimpleIcon aria-hidden="true" />}
174
+ onMouseDown={keep}
175
+ onClick={() => {
176
+ const range = selection();
177
+ if (!range) return;
178
+ setLinkFor(range);
179
+ setHref("");
180
+ setNewTab(false);
181
+ }}
182
+ />
183
+ )}
184
+ <Button
185
+ type="button"
186
+ variant="secondary"
187
+ className={BUTTON}
188
+ onMouseDown={keep}
189
+ onClick={clear}
190
+ >
191
+ Clear
192
+ </Button>
193
+ </div>
194
+ {linkFor && (
195
+ <div className="emvb-marks-link" data-emvb-marks-link="">
196
+ <Input
197
+ label={`Link for "${text.slice(linkFor.start, linkFor.end)}"`}
198
+ className={FIELD}
199
+ value={href}
200
+ placeholder="/contact"
201
+ onChange={(event) => setHref(event.target.value)}
202
+ />
203
+ <Checkbox
204
+ label="Open in a new tab"
205
+ checked={newTab}
206
+ onCheckedChange={(checked: boolean) => setNewTab(checked)}
207
+ />
208
+ <div className="emvb-marks-bar">
209
+ <Button type="button" variant="primary" className={BUTTON} onClick={applyLink}>
210
+ Apply link
211
+ </Button>
212
+ <Button
213
+ type="button"
214
+ variant="secondary"
215
+ className={BUTTON}
216
+ onClick={() => setLinkFor(undefined)}
217
+ >
218
+ Cancel
219
+ </Button>
220
+ </div>
221
+ </div>
222
+ )}
223
+ <p className="emvb-helper" role="status">
224
+ {message ?? "Select words in the Text field, then choose a format."}
225
+ </p>
226
+ {marks.length > 0 && (
227
+ <ul className="emvb-marks-list" aria-label="Formatted words">
228
+ {marks.map((mark, index) => (
229
+ <li key={`${mark.start}-${mark.end}-${index}`}>
230
+ <span>
231
+ <strong>“{text.slice(mark.start, mark.end) || "…"}”</strong> {describe(mark)}
232
+ </span>
233
+ <Button
234
+ type="button"
235
+ variant="ghost"
236
+ className={BUTTON}
237
+ aria-label={`Remove formatting from "${text.slice(mark.start, mark.end)}"`}
238
+ icon={<XIcon aria-hidden="true" />}
239
+ onClick={() => save(marks.filter((_, i) => i !== index))}
240
+ />
241
+ </li>
242
+ ))}
243
+ </ul>
244
+ )}
245
+ </div>
246
+ );
247
+ }
@@ -1,6 +1,6 @@
1
1
  import { DropdownMenu } from "@cloudflare/kumo";
2
2
  import { BracketsCurlyIcon, RulerIcon, TextAaIcon, TextTIcon, XIcon } from "@phosphor-icons/react";
3
- import type { DesignSystem, StyleProps } from "../../../../core/index.ts";
3
+ import type { DesignSystem, FlatStyleProps } from "../../../../core/index.ts";
4
4
  import type { StyleKey } from "./style-sections.ts";
5
5
 
6
6
  /** Variable kinds a length or font property can bind to. Colours bind through ColorControl. */
@@ -77,7 +77,7 @@ export function VariableButton({
77
77
  kind: BindKind;
78
78
  design: DesignSystem;
79
79
  current: string | null;
80
- onBind: (ref: NonNullable<StyleProps["gap"]>) => void;
80
+ onBind: (ref: NonNullable<FlatStyleProps["gap"]>) => void;
81
81
  }) {
82
82
  const list = variablesOf(design, kind);
83
83
  return (
@@ -1,4 +1,4 @@
1
- import type { StyleProps } from "../../../../core/index.ts";
1
+ import type { FlatStyleProps } from "../../../../core/index.ts";
2
2
  import { STYLE_UI } from "./style-sections.ts";
3
3
  import { NEW_GRADIENT } from "./BackgroundControls.tsx";
4
4
 
@@ -11,14 +11,14 @@ const BOXES = new Set([
11
11
  "div-block",
12
12
  "layout-section",
13
13
  "form",
14
- "section",
14
+ "part-ref",
15
15
  "tab-panel",
16
16
  "accordion",
17
17
  "accordion-item",
18
18
  ]);
19
19
 
20
20
  /** Color and gradient everywhere. Image and video on boxes, or when already set. */
21
- export function fillModes(type: string, style?: StyleProps): FillMode[] {
21
+ export function fillModes(type: string, style?: FlatStyleProps): FillMode[] {
22
22
  const modes: FillMode[] = ["color", "gradient"];
23
23
  const box = BOXES.has(type) || !(type in STYLE_UI);
24
24
  if (box || type === "button" || type === "submit" || style?.backgroundImage !== undefined)
@@ -28,7 +28,7 @@ export function fillModes(type: string, style?: StyleProps): FillMode[] {
28
28
  }
29
29
 
30
30
  /** The fill the page is showing. Video wins, then image, then gradient, then a solid color. */
31
- export function activeFill(style: StyleProps | undefined): FillMode {
31
+ export function activeFill(style: FlatStyleProps | undefined): FillMode {
32
32
  if (style?.backgroundVideo) return "video";
33
33
  if (style?.backgroundImage) return "image";
34
34
  if (style?.gradient) return "gradient";
@@ -36,7 +36,7 @@ export function activeFill(style: StyleProps | undefined): FillMode {
36
36
  }
37
37
 
38
38
  /** More than one fill is stored, so the page paints a stack the type switcher will collapse. */
39
- export function fillIsMixed(style: StyleProps | undefined): boolean {
39
+ export function fillIsMixed(style: FlatStyleProps | undefined): boolean {
40
40
  return (
41
41
  [
42
42
  style?.backgroundColor !== undefined,
@@ -59,7 +59,7 @@ const CLEARED = {
59
59
  } as const;
60
60
 
61
61
  /** Choosing a type removes the other fills. Overlay stays with an image or a video. */
62
- function switchFill(style: StyleProps | undefined, mode: FillMode): Partial<StyleProps> {
62
+ function switchFill(style: FlatStyleProps | undefined, mode: FillMode): Partial<FlatStyleProps> {
63
63
  if (mode === "gradient") return { ...CLEARED, gradient: style?.gradient ?? NEW_GRADIENT };
64
64
  if (mode === "image") {
65
65
  return {
@@ -78,7 +78,10 @@ function switchFill(style: StyleProps | undefined, mode: FillMode): Partial<Styl
78
78
  }
79
79
 
80
80
  /** The fields a fill type owns as stored now, or undefined when that type has nothing set. */
81
- function heldFill(style: StyleProps | undefined, mode: FillMode): Partial<StyleProps> | undefined {
81
+ function heldFill(
82
+ style: FlatStyleProps | undefined,
83
+ mode: FillMode,
84
+ ): Partial<FlatStyleProps> | undefined {
82
85
  const main = {
83
86
  color: style?.backgroundColor,
84
87
  gradient: style?.gradient,
@@ -88,22 +91,22 @@ function heldFill(style: StyleProps | undefined, mode: FillMode): Partial<StyleP
88
91
  if (main === undefined) return undefined;
89
92
  return Object.fromEntries(
90
93
  Object.entries(switchFill(style, mode)).filter(([, value]) => value !== undefined),
91
- ) as Partial<StyleProps>;
94
+ ) as Partial<FlatStyleProps>;
92
95
  }
93
96
 
94
97
  /** What each fill type last held while this element was being edited (W-184). */
95
- export type FillMemory = Partial<Record<FillMode, Partial<StyleProps>>>;
98
+ export type FillMemory = Partial<Record<FillMode, Partial<FlatStyleProps>>>;
96
99
 
97
100
  /**
98
101
  * Like `switchFill`, but the type being left is remembered in `memory`, and an empty type being
99
102
  * chosen gets back what it last held, so Gradient → Color → Gradient keeps the gradient (W-184).
100
103
  */
101
104
  export function switchFillRemembered(
102
- style: StyleProps | undefined,
105
+ style: FlatStyleProps | undefined,
103
106
  from: FillMode,
104
107
  to: FillMode,
105
108
  memory: FillMemory,
106
- ): Partial<StyleProps> {
109
+ ): Partial<FlatStyleProps> {
107
110
  const held = heldFill(style, from);
108
111
  if (held) memory[from] = held;
109
112
  const remembered = memory[to];
@@ -5,7 +5,7 @@ import { nodeChildren } from "../../../../core/tree-ops.ts";
5
5
  const TEXT_PROPS = ["text", "label", "summary", "title", "alt"] as const;
6
6
 
7
7
  /** Elements whose text comes from the post or another layout; assume they name the link. */
8
- const DYNAMIC = new Set(["section", "loop"]);
8
+ const DYNAMIC = new Set(["part-ref", "loop"]);
9
9
 
10
10
  const hasName = (node: LayoutNode): boolean => {
11
11
  if (DYNAMIC.has(node.type) || node.type.startsWith("post-")) return true;
@@ -1,5 +1,5 @@
1
- import type { StyleProps } from "../../../../core/index.ts";
2
- import type { LengthUnit } from "./length-units.ts";
1
+ import type { FlatStyleProps } from "../../../../core/index.ts";
2
+ import { fluidDraft, isFluid, type LengthUnit } from "./length-units.ts";
3
3
  import type { StyleKey } from "./style-sections.ts";
4
4
 
5
5
  type Four<T> = readonly [T, T, T, T];
@@ -73,7 +73,7 @@ const groupKeys = (group: BoxGroup): StyleKey[] => [
73
73
  ];
74
74
 
75
75
  /** What each box shows: its own value, else the all-sides value. */
76
- export function sideValues(group: BoxGroup, style: StyleProps | undefined): unknown[] {
76
+ export function sideValues(group: BoxGroup, style: FlatStyleProps | undefined): unknown[] {
77
77
  const all = group.all ? style?.[group.all] : undefined;
78
78
  return group.sides.map((key) => style?.[key] ?? all);
79
79
  }
@@ -84,11 +84,11 @@ const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b)
84
84
  export const allSame = (values: readonly unknown[]) => values.every((v) => same(v, values[0]));
85
85
 
86
86
  /** True when the edited target sets any of the control's keys. */
87
- export const groupSet = (group: BoxGroup, style: StyleProps | undefined) =>
87
+ export const groupSet = (group: BoxGroup, style: FlatStyleProps | undefined) =>
88
88
  groupKeys(group).some((key) => style?.[key] !== undefined);
89
89
 
90
90
  /** One value on every box. Border width and radius use their all-sides key and drop the sides. */
91
- export function linkedPatch(group: BoxGroup, value: unknown): Partial<StyleProps> {
91
+ export function linkedPatch(group: BoxGroup, value: unknown): Partial<FlatStyleProps> {
92
92
  const patch: Record<string, unknown> = {};
93
93
  if (group.all) {
94
94
  patch[group.all] = value;
@@ -96,15 +96,22 @@ export function linkedPatch(group: BoxGroup, value: unknown): Partial<StyleProps
96
96
  } else {
97
97
  for (const key of group.sides) patch[key] = value;
98
98
  }
99
- return patch as Partial<StyleProps>;
99
+ return patch as Partial<FlatStyleProps>;
100
100
  }
101
101
 
102
102
  /** One box's value. */
103
- export const sidePatch = (group: BoxGroup, index: number, value: unknown): Partial<StyleProps> =>
104
- ({ [group.sides[index] as StyleKey]: value }) as Partial<StyleProps>;
103
+ export const sidePatch = (
104
+ group: BoxGroup,
105
+ index: number,
106
+ value: unknown,
107
+ ): Partial<FlatStyleProps> =>
108
+ ({ [group.sides[index] as StyleKey]: value }) as Partial<FlatStyleProps>;
105
109
 
106
110
  /** Linking copies the first box that has a value to all four. */
107
- export function linkPatch(group: BoxGroup, style: StyleProps | undefined): Partial<StyleProps> {
111
+ export function linkPatch(
112
+ group: BoxGroup,
113
+ style: FlatStyleProps | undefined,
114
+ ): Partial<FlatStyleProps> {
108
115
  return linkedPatch(
109
116
  group,
110
117
  sideValues(group, style).find((value) => value !== undefined),
@@ -112,10 +119,10 @@ export function linkPatch(group: BoxGroup, style: StyleProps | undefined): Parti
112
119
  }
113
120
 
114
121
  /** Clears every key of the control. */
115
- export function resetPatch(group: BoxGroup): Partial<StyleProps> {
122
+ export function resetPatch(group: BoxGroup): Partial<FlatStyleProps> {
116
123
  const patch: Record<string, unknown> = {};
117
124
  for (const key of groupKeys(group)) patch[key] = undefined;
118
- return patch as Partial<StyleProps>;
125
+ return patch as Partial<FlatStyleProps>;
119
126
  }
120
127
 
121
128
  const isLiteral = (value: unknown): value is { value: number; unit: LengthUnit } =>
@@ -127,15 +134,15 @@ const isLiteral = (value: unknown): value is { value: number; unit: LengthUnit }
127
134
  /** The shared unit menu: every number the control sets keeps its value in the new unit. */
128
135
  export function unitPatch(
129
136
  group: BoxGroup,
130
- style: StyleProps | undefined,
137
+ style: FlatStyleProps | undefined,
131
138
  unit: LengthUnit,
132
- ): Partial<StyleProps> {
139
+ ): Partial<FlatStyleProps> {
133
140
  const patch: Record<string, unknown> = {};
134
141
  for (const key of groupKeys(group)) {
135
142
  const value = style?.[key];
136
143
  if (isLiteral(value) && value.unit !== unit) patch[key] = { value: value.value, unit };
137
144
  }
138
- return patch as Partial<StyleProps>;
145
+ return patch as Partial<FlatStyleProps>;
139
146
  }
140
147
 
141
148
  /** The unit the shared menu shows: the first box with a number, else `fallback`. */
@@ -148,6 +155,7 @@ export function sideDraft(value: unknown, unit: LengthUnit, varName?: string): s
148
155
  if (isLiteral(value))
149
156
  return value.unit === unit ? String(value.value) : `${value.value}${value.unit}`;
150
157
  if (value === "auto") return "auto";
158
+ if (isFluid(value)) return fluidDraft(value);
151
159
  if (typeof value === "object" && value !== null && "var" in value) return varName ?? "";
152
160
  return "";
153
161
  }
@@ -11,13 +11,17 @@ const SHARED_PARTS: ReadonlySet<ThemePartType> = new Set([
11
11
  "loop_item",
12
12
  ]);
13
13
 
14
+ /** True for a part that lands on pages with their own H1, so a new Heading stays H2 (W-946). */
15
+ export const isSharedPart = (partType: ThemePartType | undefined): boolean =>
16
+ partType !== undefined && SHARED_PARTS.has(partType);
17
+
14
18
  /**
15
19
  * W-208: true for an H1 (a Heading, or a Post title, at level 1) in a header, footer, popup, float,
16
20
  * synced section or loop item. The page it lands on then has two H1s (or one per post), which
17
21
  * confuses screen readers and search engines.
18
22
  */
19
23
  export function sharedPartH1(node: LayoutNode, partType: ThemePartType | undefined): boolean {
20
- if (!partType || !SHARED_PARTS.has(partType)) return false;
24
+ if (!isSharedPart(partType)) return false;
21
25
  const level = (node.props as { level?: number } | undefined)?.level;
22
26
  if (node.type === "heading") return level === 1;
23
27
  if (node.type === "post-title") return (level ?? 1) === 1;
@@ -12,6 +12,7 @@ const BOX_AUTO: readonly UnitChoice[] = [...BOX, "auto"];
12
12
  const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
13
13
  width: BOX_AUTO,
14
14
  height: BOX_AUTO,
15
+ flexBasis: BOX_AUTO,
15
16
  marginTop: BOX_AUTO,
16
17
  marginRight: BOX_AUTO,
17
18
  marginBottom: BOX_AUTO,
@@ -20,10 +21,12 @@ const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
20
21
  right: BOX_AUTO,
21
22
  bottom: BOX_AUTO,
22
23
  left: BOX_AUTO,
23
- fontSize: ["px", "rem", "em", "%", "vw"],
24
+ // vh since W-910, for hero headings sized to the screen height.
25
+ fontSize: ["px", "rem", "em", "%", "vw", "vh"],
24
26
  // em first, so a typed 1.5 means 1.5 times the font size, not 1.5 px (W-125).
25
27
  lineHeight: ["em", "px", "rem", "%", "x"],
26
28
  letterSpacing: ["px", "rem", "em"],
29
+ markerSize: ["em", "px", "rem", "%"],
27
30
  borderWidth: ["px", "rem", "em"],
28
31
  borderTopWidth: ["px", "rem", "em"],
29
32
  borderRightWidth: ["px", "rem", "em"],
@@ -51,8 +54,46 @@ const NEGATIVE = new Set<StyleKey>([
51
54
  "marginLeft",
52
55
  ]);
53
56
 
57
+ /** W-955: a fluid size, px on small screens to px on large ones. */
58
+ export type FluidLiteral = { fluid: { min: number; max: number } };
59
+
60
+ /** Keys that take a fluid size ("32–56"): type, gap, sizes, padding and margins (W-955). */
61
+ const FLUID = new Set<StyleKey>([
62
+ "fontSize",
63
+ "gap",
64
+ "width",
65
+ "minWidth",
66
+ "maxWidth",
67
+ "height",
68
+ "minHeight",
69
+ "maxHeight",
70
+ "paddingTop",
71
+ "paddingRight",
72
+ "paddingBottom",
73
+ "paddingLeft",
74
+ "marginTop",
75
+ "marginRight",
76
+ "marginBottom",
77
+ "marginLeft",
78
+ ]);
79
+
80
+ export const takesFluid = (key: StyleKey) => FLUID.has(key);
81
+
82
+ export const isFluid = (value: unknown): value is FluidLiteral =>
83
+ typeof value === "object" &&
84
+ value !== null &&
85
+ "fluid" in value &&
86
+ typeof (value as FluidLiteral).fluid?.min === "number" &&
87
+ typeof (value as FluidLiteral).fluid?.max === "number";
88
+
89
+ /** How a fluid size reads in a length field: "32–56" (px). */
90
+ export const fluidDraft = (value: FluidLiteral) => `${value.fluid.min}–${value.fluid.max}`;
91
+
92
+ /** "32–56", "32-56px", "32 to 56": small-screen and large-screen px. */
93
+ const FLUID_DRAFT = /^(\d+(?:\.\d+)?)\s*(?:px)?\s*(?:–|—|-|to|→)\s*(\d+(?:\.\d+)?)\s*(?:px)?$/i;
94
+
54
95
  export type ParsedLength =
55
- | { ok: true; value: LengthLiteral | "auto" | number | undefined }
96
+ | { ok: true; value: LengthLiteral | FluidLiteral | "auto" | number | undefined }
56
97
  | { ok: false; message: string };
57
98
 
58
99
  const DRAFT = /^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*(px|rem|em|%|vw|vh|ch)?$/i;
@@ -81,6 +122,18 @@ export function parseLengthDraft(
81
122
  ? { ok: true, value: "auto" }
82
123
  : { ok: false, message: `${label} can't be auto. Enter a number.` };
83
124
  }
125
+ const range = FLUID_DRAFT.exec(text);
126
+ if (range) {
127
+ if (!FLUID.has(key)) {
128
+ return { ok: false, message: `${label} takes one number, not a range.` };
129
+ }
130
+ const min = Number(range[1]);
131
+ const max = Number(range[2]);
132
+ if (min > 10_000 || max > 10_000) {
133
+ return { ok: false, message: `${label} can be up to 10000. Enter a smaller number.` };
134
+ }
135
+ return { ok: true, value: { fluid: { min, max } } };
136
+ }
84
137
  const match = DRAFT.exec(text);
85
138
  const n = match ? Number(match[1]) : Number.NaN;
86
139
  if (!match || !Number.isFinite(n)) {
@@ -1,7 +1,7 @@
1
- import { StyleProps } from "../../../../core/index.ts";
1
+ import { FlatStyleProps } from "../../../../core/index.ts";
2
2
 
3
3
  /** Style keys a container-query style may set (W-398). */
4
- export const QUERY_STYLE_KEYS: readonly string[] = Object.keys(StyleProps.shape).toSorted();
4
+ export const QUERY_STYLE_KEYS: readonly string[] = Object.keys(FlatStyleProps.shape).toSorted();
5
5
 
6
6
  /** A stored style value as one line of text: `16px`, `auto`, `#112233`, `var(--name)` (W-398). */
7
7
  export function formatStyleValue(value: unknown): string {
@@ -77,7 +77,7 @@ function candidates(text: string, key: string): unknown[] {
77
77
  /** The value `key` would store for `text`, or why it can't (W-398). */
78
78
  export function parseStyleValue(key: string, text: string): { value: unknown } | { error: string } {
79
79
  // W-542: an inherited name ("constructor") is not a style property; it used to throw.
80
- const shape = StyleProps.shape as Record<
80
+ const shape = FlatStyleProps.shape as Record<
81
81
  string,
82
82
  { safeParse: (v: unknown) => { success: boolean } }
83
83
  >;