@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,25 @@
1
+ import type { LayoutNode } from "../../../../core/index.ts";
2
+ import type { ThemePartType } from "../../../../core/theme/part-types.ts";
3
+
4
+ /** Parts that show on, or repeat across, pages that already have their own H1 (W-208). */
5
+ const SHARED_PARTS: ReadonlySet<ThemePartType> = new Set([
6
+ "header",
7
+ "footer",
8
+ "popup",
9
+ "float",
10
+ "section",
11
+ "loop_item",
12
+ ]);
13
+
14
+ /**
15
+ * W-208: true for an H1 (a Heading, or a Post title, at level 1) in a header, footer, popup, float,
16
+ * synced section or loop item. The page it lands on then has two H1s (or one per post), which
17
+ * confuses screen readers and search engines.
18
+ */
19
+ export function sharedPartH1(node: LayoutNode, partType: ThemePartType | undefined): boolean {
20
+ if (!partType || !SHARED_PARTS.has(partType)) return false;
21
+ const level = (node.props as { level?: number } | undefined)?.level;
22
+ if (node.type === "heading") return level === 1;
23
+ if (node.type === "post-title") return (level ?? 1) === 1;
24
+ return false;
25
+ }
@@ -0,0 +1,25 @@
1
+ import type { LayoutNode } from "../../../../core/index.ts";
2
+
3
+ /** Alt text that names the file or the element rather than the picture (W-265). */
4
+ const PLACEHOLDER = /^(image|picture|photo|img)$/i;
5
+ const FILE_NAME =
6
+ /\.(jpe?g|png|gif|webp|avif|svg|bmp|tiff?)$|^(img|dsc|dscn|pxl|image|photo|screenshot|screen shot)[\s_-]*\d/i;
7
+
8
+ /**
9
+ * W-265: a note for an Image whose alt won't help a screen reader user: none on a non-decorative
10
+ * image (it then reads as decorative), the "Image" placeholder, or a camera or file name. Undefined
11
+ * when the alt looks fine, the image is decorative or has no picture yet.
12
+ */
13
+ export function imageAltNote(node: LayoutNode): string | undefined {
14
+ if (node.type !== "image") return undefined;
15
+ const props = node.props as { src?: string; alt?: string; decorative?: boolean };
16
+ if (props.decorative === true || !props.src?.trim()) return undefined;
17
+ const alt = (props.alt ?? "").trim();
18
+ if (!alt) {
19
+ return "This image has no alt text, so screen readers skip it. Describe it, or turn on Decorative if it only decorates.";
20
+ }
21
+ if (PLACEHOLDER.test(alt) || FILE_NAME.test(alt)) {
22
+ return `“${alt}” doesn't say what the image shows. Describe it for people who can't see it.`;
23
+ }
24
+ return undefined;
25
+ }
@@ -0,0 +1,116 @@
1
+ import { STYLE_LABELS, type StyleKey } from "./style-sections.ts";
2
+
3
+ export type LengthUnit = "px" | "rem" | "em" | "%" | "vw" | "vh";
4
+ /** `x` is a unitless number, for Line height only (W-213). */
5
+ export type UnitChoice = LengthUnit | "auto" | "x";
6
+ export type LengthLiteral = { value: number; unit: LengthUnit };
7
+
8
+ const BOX: readonly UnitChoice[] = ["px", "%", "rem", "em", "vw", "vh"];
9
+ const BOX_AUTO: readonly UnitChoice[] = [...BOX, "auto"];
10
+
11
+ /** Units each length property offers in its unit menu. */
12
+ const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
13
+ width: BOX_AUTO,
14
+ height: BOX_AUTO,
15
+ marginTop: BOX_AUTO,
16
+ marginRight: BOX_AUTO,
17
+ marginBottom: BOX_AUTO,
18
+ marginLeft: BOX_AUTO,
19
+ top: BOX_AUTO,
20
+ right: BOX_AUTO,
21
+ bottom: BOX_AUTO,
22
+ left: BOX_AUTO,
23
+ fontSize: ["px", "rem", "em", "%", "vw"],
24
+ // em first, so a typed 1.5 means 1.5 times the font size, not 1.5 px (W-125).
25
+ lineHeight: ["em", "px", "rem", "%", "x"],
26
+ letterSpacing: ["px", "rem", "em"],
27
+ borderWidth: ["px", "rem", "em"],
28
+ borderTopWidth: ["px", "rem", "em"],
29
+ borderRightWidth: ["px", "rem", "em"],
30
+ borderBottomWidth: ["px", "rem", "em"],
31
+ borderLeftWidth: ["px", "rem", "em"],
32
+ borderRadius: ["px", "%", "rem", "em"],
33
+ borderTopLeftRadius: ["px", "%", "rem", "em"],
34
+ borderTopRightRadius: ["px", "%", "rem", "em"],
35
+ borderBottomRightRadius: ["px", "%", "rem", "em"],
36
+ borderBottomLeftRadius: ["px", "%", "rem", "em"],
37
+ };
38
+
39
+ export const unitsFor = (key: StyleKey): readonly UnitChoice[] => UNITS[key] ?? BOX;
40
+
41
+ const NEGATIVE = new Set<StyleKey>(["top", "right", "bottom", "left", "letterSpacing"]);
42
+
43
+ export type ParsedLength =
44
+ | { ok: true; value: LengthLiteral | "auto" | number | undefined }
45
+ | { ok: false; message: string };
46
+
47
+ const DRAFT = /^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*(px|rem|em|%|vw|vh)?$/i;
48
+ /** A number with a unit EmVB doesn't take ("100dvh", "12pt"), or a comma decimal ("1,5") (W-262). */
49
+ const OTHER_UNIT = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)\s*[a-z%]+$/i;
50
+ const COMMA_DECIMAL = /^[+-]?\d*,\d+\s*[a-z%]*$/i;
51
+
52
+ const listed = (units: readonly string[]) =>
53
+ units.length > 1 ? `${units.slice(0, -1).join(", ")} or ${units.at(-1)}` : (units[0] ?? "");
54
+
55
+ /**
56
+ * Parses a length field's text: a number in `unit`, a number with its own unit ("50%",
57
+ * "1.5rem"), `auto` where allowed, or empty for unset.
58
+ */
59
+ export function parseLengthDraft(
60
+ draft: string,
61
+ key: StyleKey,
62
+ unit: LengthUnit | "x",
63
+ ): ParsedLength {
64
+ const text = draft.trim();
65
+ if (text === "") return { ok: true, value: undefined };
66
+ const label = STYLE_LABELS[key];
67
+ const allowed = unitsFor(key);
68
+ if (text.toLowerCase() === "auto") {
69
+ return allowed.includes("auto")
70
+ ? { ok: true, value: "auto" }
71
+ : { ok: false, message: `${label} can't be auto. Enter a number.` };
72
+ }
73
+ const match = DRAFT.exec(text);
74
+ const n = match ? Number(match[1]) : Number.NaN;
75
+ if (!match || !Number.isFinite(n)) {
76
+ if (COMMA_DECIMAL.test(text)) {
77
+ return { ok: false, message: "Use a dot for decimals, such as 1.5." };
78
+ }
79
+ if (OTHER_UNIT.test(text)) {
80
+ return {
81
+ ok: false,
82
+ message: `${label} takes ${listed(allowed.filter((u) => u !== "auto" && u !== "x"))}.`,
83
+ };
84
+ }
85
+ return { ok: false, message: `Enter a number, such as 16 or 16${unit}.` };
86
+ }
87
+ if (unit === "x" && !match[2] && allowed.includes("x")) {
88
+ // W-213: unitless line height, 0–100.
89
+ if (n < 0 || n > 100) {
90
+ return { ok: false, message: `${label} without a unit can be from 0 to 100.` };
91
+ }
92
+ return { ok: true, value: n };
93
+ }
94
+ const typed = (match[2]?.toLowerCase() ?? unit) as LengthUnit;
95
+ if (!allowed.includes(typed)) {
96
+ return {
97
+ ok: false,
98
+ message: `${label} takes ${listed(allowed.filter((u) => u !== "auto"))}.`,
99
+ };
100
+ }
101
+ if (n < 0 && !NEGATIVE.has(key)) {
102
+ return {
103
+ ok: false,
104
+ message: `${label} can't be negative. Enter 0 or more.`,
105
+ };
106
+ }
107
+ if (Math.abs(n) > 10_000) {
108
+ return {
109
+ ok: false,
110
+ message: NEGATIVE.has(key)
111
+ ? `${label} can be from -10000 to 10000.`
112
+ : `${label} can be up to 10000. Enter a smaller number.`,
113
+ };
114
+ }
115
+ return { ok: true, value: { value: n, unit: typed } };
116
+ }
@@ -0,0 +1,26 @@
1
+ import type { LayoutNode } from "../../../../core/index.ts";
2
+ import type { ThemePartType } from "../../../../core/theme/part-types.ts";
3
+
4
+ /**
5
+ * Parts where a Loop can get posts: archive templates, and synced sections (which an archive
6
+ * template may include). Hosts load archive posts only for an archive (W-221).
7
+ */
8
+ const LOOP_PARTS: ReadonlySet<ThemePartType> = new Set(["archive", "section"]);
9
+
10
+ /**
11
+ * W-271: a Loop or Pagination outside an archive template previews sample posts on the canvas,
12
+ * but the live page gets no posts, so it renders nothing there. Undefined where it can work.
13
+ */
14
+ export function loopContextNote(
15
+ node: LayoutNode,
16
+ partType: ThemePartType | undefined,
17
+ ): string | undefined {
18
+ if (partType && LOOP_PARTS.has(partType)) return undefined;
19
+ if (node.type === "loop") {
20
+ return "A Loop lists posts only in an Archive template. Here the editor shows sample posts, but the live page shows nothing. Build post lists in Theme Builder › Archive.";
21
+ }
22
+ if (node.type === "pagination") {
23
+ return "Pagination shows only in an Archive template with more than one page. Here the live page shows nothing.";
24
+ }
25
+ return undefined;
26
+ }
@@ -0,0 +1,11 @@
1
+ import type { LayoutNode } from "../../../../core/index.ts";
2
+
3
+ export const propsOf = (node: LayoutNode): Record<string, unknown> =>
4
+ node.props as Record<string, unknown>;
5
+
6
+ export const withProp = (node: LayoutNode, key: string, value: unknown): LayoutNode => {
7
+ const props = { ...propsOf(node) };
8
+ if (value === undefined) delete props[key];
9
+ else props[key] = value;
10
+ return { ...node, props } as LayoutNode;
11
+ };
@@ -0,0 +1,394 @@
1
+ import type { StyleProps } from "../../../../core/index.ts";
2
+
3
+ export type StyleSectionId =
4
+ | "icon"
5
+ | "layout"
6
+ | "spacing"
7
+ | "size"
8
+ | "position"
9
+ | "typography"
10
+ | "background"
11
+ | "border"
12
+ | "effects"
13
+ | "advanced";
14
+
15
+ export type StyleKey = keyof StyleProps;
16
+
17
+ /** Elementor v4 order (W-088); every list below follows it. */
18
+ const SECTION_ORDER: StyleSectionId[] = [
19
+ "icon", // W-237: Icon only, first like Elementor's Icon style
20
+ "layout",
21
+ "spacing",
22
+ "size",
23
+ "position",
24
+ "typography",
25
+ "background",
26
+ "border",
27
+ "effects",
28
+ "advanced",
29
+ ];
30
+
31
+ const TEXT_SECTIONS: StyleSectionId[] = [
32
+ "spacing",
33
+ "size",
34
+ "position",
35
+ "typography",
36
+ "background",
37
+ "border",
38
+ "effects",
39
+ "advanced",
40
+ ];
41
+
42
+ /** Which Style sections appear, and which opens by default (IA table). */
43
+ export const STYLE_UI: Record<string, { sections: StyleSectionId[]; defaultOpen: StyleSectionId }> =
44
+ {
45
+ // W-159: Typography too, so a page or band sets the font and colour its children inherit,
46
+ // as Flexbox and Div Block already could.
47
+ container: {
48
+ sections: [
49
+ "layout",
50
+ "spacing",
51
+ "size",
52
+ "position",
53
+ "typography",
54
+ "background",
55
+ "border",
56
+ "effects",
57
+ "advanced",
58
+ ],
59
+ defaultOpen: "layout",
60
+ },
61
+ spacer: { sections: ["layout", "advanced"], defaultOpen: "layout" },
62
+ divider: {
63
+ sections: ["spacing", "size", "position", "border", "effects", "advanced"],
64
+ defaultOpen: "border",
65
+ },
66
+ heading: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
67
+ text: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
68
+ label: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
69
+ link: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
70
+ list: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
71
+ button: { sections: ["layout", ...TEXT_SECTIONS], defaultOpen: "background" },
72
+ image: {
73
+ sections: ["spacing", "size", "position", "border", "effects", "advanced"],
74
+ defaultOpen: "size",
75
+ },
76
+ // W-237: Icon first (colour, glyph, hover duration), then the wrapper's box: background,
77
+ // padding and border make the shape behind the glyph.
78
+ icon: {
79
+ sections: [
80
+ "icon",
81
+ "spacing",
82
+ "size",
83
+ "position",
84
+ "background",
85
+ "border",
86
+ "effects",
87
+ "advanced",
88
+ ],
89
+ defaultOpen: "icon",
90
+ },
91
+ video: {
92
+ sections: ["spacing", "size", "position", "border", "effects", "advanced"],
93
+ defaultOpen: "size",
94
+ },
95
+ form: {
96
+ sections: [
97
+ "layout",
98
+ "spacing",
99
+ "size",
100
+ "position",
101
+ "background",
102
+ "border",
103
+ "effects",
104
+ "advanced",
105
+ ],
106
+ defaultOpen: "layout",
107
+ },
108
+ // The field is a flex column (label, then control), so direction, alignment and gap apply.
109
+ "text-input": { sections: ["layout", ...TEXT_SECTIONS], defaultOpen: "typography" },
110
+ textarea: { sections: ["layout", ...TEXT_SECTIONS], defaultOpen: "typography" },
111
+ select: { sections: ["layout", ...TEXT_SECTIONS], defaultOpen: "typography" },
112
+ checkbox: {
113
+ sections: ["layout", "spacing", "size", "position", "typography", "effects", "advanced"],
114
+ defaultOpen: "typography",
115
+ },
116
+ radio: {
117
+ sections: ["layout", "spacing", "size", "position", "typography", "effects", "advanced"],
118
+ defaultOpen: "typography",
119
+ },
120
+ submit: { sections: ["layout", ...TEXT_SECTIONS], defaultOpen: "background" },
121
+ };
122
+
123
+ /** Types without an entry (Flexbox, Div Block, SVG, Tabs, dynamic elements) show every section. */
124
+ export const DEFAULT_UI = {
125
+ sections: SECTION_ORDER,
126
+ defaultOpen: "layout" as StyleSectionId,
127
+ };
128
+
129
+ export const SECTION_LABELS: Record<StyleSectionId, string> = {
130
+ icon: "Icon",
131
+ layout: "Layout",
132
+ spacing: "Spacing",
133
+ size: "Size",
134
+ position: "Position",
135
+ typography: "Typography",
136
+ background: "Background",
137
+ border: "Border",
138
+ effects: "Effects",
139
+ advanced: "Advanced",
140
+ };
141
+
142
+ /** Style property keys shown in each section (subset of StyleProps). */
143
+ const SECTION_KEYS: Record<StyleSectionId, StyleKey[]> = {
144
+ layout: [
145
+ "flexDirection",
146
+ "flexWrap",
147
+ "justifyContent",
148
+ "alignItems",
149
+ "gap",
150
+ "gridColumnSpan",
151
+ "gridRowSpan",
152
+ ],
153
+ spacing: [
154
+ "paddingTop",
155
+ "paddingRight",
156
+ "paddingBottom",
157
+ "paddingLeft",
158
+ "marginTop",
159
+ "marginRight",
160
+ "marginBottom",
161
+ "marginLeft",
162
+ ],
163
+ size: [
164
+ "width",
165
+ "height",
166
+ "minWidth",
167
+ "minHeight",
168
+ "maxWidth",
169
+ "maxHeight",
170
+ "overflow",
171
+ "aspectRatio",
172
+ "objectFit",
173
+ ],
174
+ position: ["position", "top", "right", "bottom", "left", "zIndex"],
175
+ typography: [
176
+ "fontFamily",
177
+ "fontSize",
178
+ "fontWeight",
179
+ "lineHeight",
180
+ "letterSpacing",
181
+ "textAlign",
182
+ "textTransform",
183
+ "textDecoration",
184
+ "color",
185
+ ],
186
+ background: [
187
+ "backgroundColor",
188
+ "backgroundImage",
189
+ "backgroundSize",
190
+ "backgroundPosition",
191
+ "backgroundRepeat",
192
+ "gradient",
193
+ "overlay",
194
+ "backgroundVideo",
195
+ ],
196
+ border: [
197
+ "borderWidth",
198
+ "borderTopWidth",
199
+ "borderRightWidth",
200
+ "borderBottomWidth",
201
+ "borderLeftWidth",
202
+ "borderStyle",
203
+ "borderColor",
204
+ "borderRadius",
205
+ "borderTopLeftRadius",
206
+ "borderTopRightRadius",
207
+ "borderBottomRightRadius",
208
+ "borderBottomLeftRadius",
209
+ ],
210
+ effects: ["opacity", "boxShadow", "filter", "cursor", "entrance", "transition"],
211
+ icon: ["iconRotate", "iconFlip", "iconScale", "iconStrokeWidth", "iconShadow", "iconAnimation"],
212
+ advanced: [],
213
+ };
214
+
215
+ /**
216
+ * W-237: an Icon shows Colour and Transition in its Icon section (colour first, hover duration
217
+ * last), so Typography and Effects leave them out for it.
218
+ */
219
+ const ICON_MOVED: StyleKey[] = ["color", "transition"];
220
+
221
+ /** Keys that only make sense on some element types. */
222
+ const ONLY_FOR: Partial<Record<StyleKey, string[]>> = {
223
+ objectFit: ["image", "video"],
224
+ ...Object.fromEntries(
225
+ ["iconRotate", "iconFlip", "iconScale", "iconStrokeWidth", "iconShadow", "iconAnimation"].map(
226
+ (key) => [key, ["icon"]],
227
+ ),
228
+ ),
229
+ };
230
+
231
+ const SPANS: StyleKey[] = ["gridColumnSpan", "gridRowSpan"];
232
+
233
+ /**
234
+ * Direction, wrap, justify, align and gap only where the element's own box is a flex or grid
235
+ * container (W-163). A block box ignores them, which is why Div Block lost them (W-144).
236
+ * A grid ignores flex direction and wrap; justify, align and gap still lay out its cells.
237
+ */
238
+ const GRID_LAYOUT: StyleKey[] = ["justifyContent", "alignItems", "gap", ...SPANS];
239
+
240
+ /** Block and inline boxes. A stored flex value still shows, so it can be reset (W-088). */
241
+ const SPANS_ONLY = [
242
+ "heading",
243
+ "text",
244
+ "label",
245
+ "link",
246
+ "list",
247
+ "image",
248
+ "video",
249
+ "menu-item",
250
+ "accordion-item",
251
+ "tab-panel",
252
+ "post-title",
253
+ "post-excerpt",
254
+ "post-content",
255
+ "post-image",
256
+ "post-link",
257
+ "post-date",
258
+ "post-author",
259
+ ] as const;
260
+
261
+ /** Per-type filters so Spacer and Divider don't get every control. */
262
+ const TYPE_SECTION_KEYS: Record<string, Partial<Record<StyleSectionId, StyleKey[]>>> = {
263
+ spacer: { layout: [] }, // height is a content prop, shown above sections
264
+ divider: { size: ["width"], layout: SPANS },
265
+ // A Div Block is a plain block box (Elementor v4, D-EV4-01): flex controls would do nothing on
266
+ // the page, so Layout offers only the grid spans (W-144). Use Flexbox or Container for flex.
267
+ "div-block": { layout: SPANS },
268
+ // A block box too: its contents sit in the centred inner box (W-156).
269
+ "layout-section": { layout: SPANS },
270
+ grid: { layout: GRID_LAYOUT },
271
+ ...Object.fromEntries(SPANS_ONLY.map((type) => [type, { layout: SPANS }])),
272
+ };
273
+
274
+ const OFFSETS = new Set<StyleKey>(["top", "right", "bottom", "left"]);
275
+
276
+ /** Offsets only do anything once the element is positioned (W-088). */
277
+ export const offsetsApply = (position: StyleProps["position"]) =>
278
+ position !== undefined && position !== "static";
279
+
280
+ /**
281
+ * The keys a section shows for a type. Offsets need `position` (the value in effect) to be
282
+ * other than static. With `style`, a key that is set there is always shown,
283
+ * even where the type wouldn't offer it, so a stored value can be seen and reset (W-088).
284
+ */
285
+ export function keysFor(
286
+ type: string,
287
+ section: StyleSectionId,
288
+ style?: StyleProps,
289
+ position?: StyleProps["position"],
290
+ ): StyleKey[] {
291
+ const offered = new Set(
292
+ (
293
+ TYPE_SECTION_KEYS[type]?.[section] ??
294
+ SECTION_KEYS[section].filter((key) => ONLY_FOR[key]?.includes(type) ?? true)
295
+ ).filter((key) => !OFFSETS.has(key) || offsetsApply(position)),
296
+ );
297
+ const keys = SECTION_KEYS[section].filter(
298
+ (key) => offered.has(key) || style?.[key] !== undefined,
299
+ );
300
+ if (type !== "icon") return keys;
301
+ if (section !== "icon") return keys.filter((key) => !ICON_MOVED.includes(key));
302
+ return ["color", ...keys, "transition"];
303
+ }
304
+
305
+ /** The type's sections, plus any other section holding a set value, in section order. */
306
+ export function sectionsFor(
307
+ sections: StyleSectionId[],
308
+ style: StyleProps | undefined,
309
+ type?: string,
310
+ ): StyleSectionId[] {
311
+ const moved = type === "icon" ? ICON_MOVED : [];
312
+ return SECTION_ORDER.filter(
313
+ (id) =>
314
+ sections.includes(id) ||
315
+ SECTION_KEYS[id].some((key) => style?.[key] !== undefined && !moved.includes(key)),
316
+ );
317
+ }
318
+
319
+ export const STYLE_LABELS: Record<StyleKey, string> = {
320
+ flexDirection: "Direction",
321
+ flexWrap: "Wrap",
322
+ justifyContent: "Justify",
323
+ alignItems: "Align",
324
+ gap: "Gap",
325
+ gridColumnSpan: "Column span",
326
+ gridRowSpan: "Row span",
327
+ width: "Width",
328
+ minWidth: "Min width",
329
+ maxWidth: "Max width",
330
+ height: "Height",
331
+ minHeight: "Min height",
332
+ maxHeight: "Max height",
333
+ overflow: "Overflow",
334
+ aspectRatio: "Aspect ratio",
335
+ objectFit: "Object fit",
336
+ paddingTop: "Padding top",
337
+ paddingRight: "Padding right",
338
+ paddingBottom: "Padding bottom",
339
+ paddingLeft: "Padding left",
340
+ marginTop: "Margin top",
341
+ marginRight: "Margin right",
342
+ marginBottom: "Margin bottom",
343
+ marginLeft: "Margin left",
344
+ position: "Position",
345
+ top: "Top",
346
+ right: "Right",
347
+ bottom: "Bottom",
348
+ left: "Left",
349
+ zIndex: "Z-index",
350
+ fontFamily: "Font family",
351
+ fontSize: "Font size",
352
+ fontWeight: "Weight",
353
+ lineHeight: "Line height",
354
+ letterSpacing: "Letter spacing",
355
+ textAlign: "Align text",
356
+ textTransform: "Transform",
357
+ textDecoration: "Decoration",
358
+ color: "Color",
359
+ backgroundColor: "Background",
360
+ backgroundImage: "Image",
361
+ backgroundVideo: "Video",
362
+ backgroundSize: "Image size",
363
+ backgroundPosition: "Image position",
364
+ backgroundRepeat: "Repeat",
365
+ gradient: "Gradient",
366
+ overlay: "Overlay",
367
+ borderWidth: "Border width",
368
+ borderTopWidth: "Border top width",
369
+ borderRightWidth: "Border right width",
370
+ borderBottomWidth: "Border bottom width",
371
+ borderLeftWidth: "Border left width",
372
+ borderStyle: "Border style",
373
+ borderColor: "Border color",
374
+ borderRadius: "Radius",
375
+ borderTopLeftRadius: "Radius top left",
376
+ borderTopRightRadius: "Radius top right",
377
+ borderBottomRightRadius: "Radius bottom right",
378
+ borderBottomLeftRadius: "Radius bottom left",
379
+ opacity: "Opacity",
380
+ boxShadow: "Box shadow",
381
+ filter: "Filters",
382
+ cursor: "Cursor",
383
+ entrance: "Entrance",
384
+ iconRotate: "Rotate",
385
+ iconFlip: "Flip",
386
+ iconScale: "Scale",
387
+ iconStrokeWidth: "Stroke width",
388
+ iconShadow: "Drop shadow",
389
+ iconAnimation: "Animation",
390
+ transition: "Transition",
391
+ };
392
+
393
+ /** Every StyleProps key that the settings panel must be able to edit. */
394
+ export const CONTROLLED_STYLE_KEYS: StyleKey[] = Object.values(SECTION_KEYS).flat();
@@ -0,0 +1,14 @@
1
+ import { sanitizeSvgReport, type LayoutNode } from "../../../../core/index.ts";
2
+
3
+ /** W-231: how many external `<image>`s an SVG element's markup loses when it renders. */
4
+ export function svgImagesLeftOut(node: LayoutNode): number {
5
+ if (node.type !== "svg") return 0;
6
+ const markup = (node.props as { markup?: unknown }).markup;
7
+ return typeof markup === "string" ? sanitizeSvgReport(markup).images : 0;
8
+ }
9
+
10
+ /** The note under the SVG markup field when some of its images are left out. */
11
+ export function svgImagesNotice(count: number): string {
12
+ const what = count === 1 ? "1 external image" : `${count} external images`;
13
+ return `Left out ${what}. An SVG can only show pictures from the media library or embedded PNG, JPEG, WebP or GIF data.`;
14
+ }