@perkyzz/emvb 0.1.0 → 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 (153) hide show
  1. package/README.md +4 -2
  2. package/THIRD_PARTY_NOTICES.md +32 -0
  3. package/licenses/fontawesome-free.LICENSE +165 -0
  4. package/licenses/lucide-static.LICENSE +43 -0
  5. package/licenses/remixicon.LICENSE +201 -0
  6. package/licenses/tabler-icons.LICENSE +21 -0
  7. package/package.json +8 -4
  8. package/src/admin/api.ts +27 -0
  9. package/src/admin/content-api.ts +72 -9
  10. package/src/admin/editor/Editor.tsx +89 -14
  11. package/src/admin/editor/EditorOverlay.tsx +12 -0
  12. package/src/admin/editor/SmallScreenNotice.tsx +4 -3
  13. package/src/admin/editor/TopBar.tsx +76 -12
  14. package/src/admin/editor/canvas/CanvasFrame.tsx +224 -43
  15. package/src/admin/editor/canvas/DeviceBar.tsx +43 -2
  16. package/src/admin/editor/canvas/SelectionOverlay.tsx +60 -6
  17. package/src/admin/editor/canvas/canvas-events.ts +20 -7
  18. package/src/admin/editor/canvas/tab-reveal.ts +66 -0
  19. package/src/admin/editor/canvas/vnode-react.tsx +21 -1
  20. package/src/admin/editor/dialogs.tsx +39 -0
  21. package/src/admin/editor/dnd/drop-target.ts +63 -16
  22. package/src/admin/editor/dnd/new-element.ts +76 -1
  23. package/src/admin/editor/editor-css.ts +101 -15
  24. package/src/admin/editor/host.ts +30 -0
  25. package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
  26. package/src/admin/editor/icons/library.ts +243 -0
  27. package/src/admin/editor/icons/set-format.ts +29 -0
  28. package/src/admin/editor/icons/sets/fontawesome.json +1 -0
  29. package/src/admin/editor/icons/sets/lucide.json +1 -0
  30. package/src/admin/editor/icons/sets/remix.json +1 -0
  31. package/src/admin/editor/icons/sets/tabler.json +1 -0
  32. package/src/admin/editor/panels/AddPanel.tsx +7 -3
  33. package/src/admin/editor/panels/ClassesSection.tsx +44 -6
  34. package/src/admin/editor/panels/ColorControl.tsx +268 -21
  35. package/src/admin/editor/panels/ElementPanel.tsx +237 -93
  36. package/src/admin/editor/panels/LayersPanel.tsx +303 -66
  37. package/src/admin/editor/panels/LeftPanel.tsx +4 -0
  38. package/src/admin/editor/panels/PageSettings.tsx +134 -5
  39. package/src/admin/editor/panels/SettingsPanel.tsx +12 -0
  40. package/src/admin/editor/panels/SiteStylesDrawer.tsx +158 -2
  41. package/src/admin/editor/panels/TriggersEditor.tsx +19 -2
  42. package/src/admin/editor/panels/VariableSection.tsx +47 -9
  43. package/src/admin/editor/panels/color-space.ts +195 -0
  44. package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
  45. package/src/admin/editor/panels/settings/BackgroundControls.tsx +153 -55
  46. package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
  47. package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
  48. package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
  49. package/src/admin/editor/panels/settings/ClassChipInput.tsx +104 -2
  50. package/src/admin/editor/panels/settings/DraftTextField.tsx +44 -3
  51. package/src/admin/editor/panels/settings/EffectsControls.tsx +23 -16
  52. package/src/admin/editor/panels/settings/FieldBindControl.tsx +53 -17
  53. package/src/admin/editor/panels/settings/FieldControl.tsx +129 -9
  54. package/src/admin/editor/panels/settings/FormBindControl.tsx +14 -5
  55. package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
  56. package/src/admin/editor/panels/settings/IconPicker.tsx +133 -72
  57. package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
  58. package/src/admin/editor/panels/settings/LengthRow.tsx +97 -61
  59. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +10 -4
  60. package/src/admin/editor/panels/settings/MediaPicker.tsx +4 -2
  61. package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
  62. package/src/admin/editor/panels/settings/StyleRow.tsx +158 -75
  63. package/src/admin/editor/panels/settings/VariableBinding.tsx +5 -1
  64. package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
  65. package/src/admin/editor/panels/settings/background-mode.ts +112 -0
  66. package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
  67. package/src/admin/editor/panels/settings/box-sides.ts +153 -0
  68. package/src/admin/editor/panels/settings/button-url.ts +27 -0
  69. package/src/admin/editor/panels/settings/class-suggest.ts +5 -3
  70. package/src/admin/editor/panels/settings/form-names.ts +38 -0
  71. package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
  72. package/src/admin/editor/panels/settings/image-alt.ts +25 -0
  73. package/src/admin/editor/panels/settings/length-units.ts +40 -7
  74. package/src/admin/editor/panels/settings/loop-context.ts +26 -0
  75. package/src/admin/editor/panels/settings/style-sections.ts +114 -11
  76. package/src/admin/editor/panels/settings/svg-images.ts +14 -0
  77. package/src/admin/editor/panels/site-list.tsx +3 -0
  78. package/src/admin/editor/restore-deleted.ts +80 -0
  79. package/src/admin/editor/shortcuts.ts +1 -1
  80. package/src/admin/editor/store.ts +35 -7
  81. package/src/admin/editor/useEditorCommands.ts +66 -5
  82. package/src/admin/editor/useEditorData.ts +29 -3
  83. package/src/admin/editor/useEditorShortcuts.ts +34 -2
  84. package/src/admin/editor/useNodeActions.ts +68 -6
  85. package/src/admin/editor/useSave.ts +60 -3
  86. package/src/admin/entry-status.ts +19 -0
  87. package/src/admin/icon-uploads-api.ts +44 -0
  88. package/src/admin/pages/PageList.tsx +22 -2
  89. package/src/admin/pages/ThemePartList.tsx +23 -4
  90. package/src/admin/pages/list-kit.tsx +52 -2
  91. package/src/admin/setup/spec.ts +7 -0
  92. package/src/admin/theme-api.ts +61 -14
  93. package/src/admin/ui.ts +17 -4
  94. package/src/astro/EmVBPage.astro +28 -2
  95. package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
  96. package/src/astro/floats/index.ts +1 -0
  97. package/src/astro/floats/runtime.ts +78 -0
  98. package/src/astro/forms-definitions.ts +22 -0
  99. package/src/astro/index.ts +1 -0
  100. package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
  101. package/src/astro/menu/index.ts +1 -0
  102. package/src/astro/menu/runtime.ts +37 -0
  103. package/src/astro/popups/runtime.ts +54 -4
  104. package/src/astro/render.ts +47 -13
  105. package/src/astro/resolve-theme.ts +164 -20
  106. package/src/astro/tabs/runtime.ts +6 -1
  107. package/src/astro/theme-context.ts +11 -3
  108. package/src/constants.ts +1 -1
  109. package/src/core/arrange.ts +98 -10
  110. package/src/core/clipboard.ts +91 -9
  111. package/src/core/css/generate.ts +21 -4
  112. package/src/core/design/classes.ts +95 -9
  113. package/src/core/design/transfer.ts +101 -2
  114. package/src/core/design/variables.ts +51 -11
  115. package/src/core/elements/dynamic-elements.ts +57 -5
  116. package/src/core/elements/field-id.ts +6 -0
  117. package/src/core/elements/form-elements.ts +23 -8
  118. package/src/core/elements/index.ts +267 -49
  119. package/src/core/elements/menu.ts +190 -0
  120. package/src/core/forms/definition.ts +11 -0
  121. package/src/core/index.ts +67 -3
  122. package/src/core/limits.ts +2 -0
  123. package/src/core/migrate/index.ts +51 -1
  124. package/src/core/nesting.ts +51 -0
  125. package/src/core/render/context.ts +7 -0
  126. package/src/core/render/dynamic-post.ts +39 -11
  127. package/src/core/render/extras.ts +22 -3
  128. package/src/core/render/form.ts +134 -36
  129. package/src/core/render/index.ts +123 -25
  130. package/src/core/render/loop.ts +10 -3
  131. package/src/core/render/pagination.ts +76 -0
  132. package/src/core/render/section.ts +5 -1
  133. package/src/core/render/tabs.ts +8 -4
  134. package/src/core/render/vnode.ts +1 -1
  135. package/src/core/sanitize/css.ts +197 -17
  136. package/src/core/sanitize/embed-url.ts +64 -7
  137. package/src/core/sanitize/svg-upload.ts +203 -0
  138. package/src/core/sanitize/svg.ts +102 -21
  139. package/src/core/schema/descriptors.ts +4 -0
  140. package/src/core/schema/design.ts +7 -2
  141. package/src/core/schema/layout.ts +210 -19
  142. package/src/core/schema/style.ts +87 -8
  143. package/src/core/tabs/presence.ts +9 -0
  144. package/src/core/theme/conditions.ts +4 -1
  145. package/src/core/theme/dynamic.ts +10 -0
  146. package/src/core/theme/float.ts +113 -0
  147. package/src/core/theme/pagination.ts +97 -0
  148. package/src/core/theme/part-types.ts +2 -0
  149. package/src/core/theme/popup-markup.ts +3 -1
  150. package/src/core/theme/popup-rules.ts +4 -3
  151. package/src/server/hooks.ts +20 -0
  152. package/src/server/icon-routes.ts +79 -0
  153. package/src/server/plugin.ts +5 -1
@@ -0,0 +1,153 @@
1
+ import type { StyleProps } from "../../../../core/index.ts";
2
+ import type { LengthUnit } from "./length-units.ts";
3
+ import type { StyleKey } from "./style-sections.ts";
4
+
5
+ type Four<T> = readonly [T, T, T, T];
6
+
7
+ export type BoxGroupId = "padding" | "margin" | "borderWidth" | "borderRadius";
8
+
9
+ /** One linked four-box control (W-138, D-044): padding, margin, border width or radius. */
10
+ export type BoxGroup = {
11
+ id: BoxGroupId;
12
+ label: string;
13
+ /** Border width and radius keep an all-sides key; a side or corner beats it. */
14
+ all?: StyleKey;
15
+ /** Top, right, bottom, left; or the corners clockwise from top left. */
16
+ sides: Four<StyleKey>;
17
+ /** The short names under the boxes. */
18
+ names: Four<string>;
19
+ noun: "sides" | "corners";
20
+ };
21
+
22
+ export const BOX_GROUPS: readonly BoxGroup[] = [
23
+ {
24
+ id: "padding",
25
+ label: "Padding",
26
+ sides: ["paddingTop", "paddingRight", "paddingBottom", "paddingLeft"],
27
+ names: ["Top", "Right", "Bottom", "Left"],
28
+ noun: "sides",
29
+ },
30
+ {
31
+ id: "margin",
32
+ label: "Margin",
33
+ sides: ["marginTop", "marginRight", "marginBottom", "marginLeft"],
34
+ names: ["Top", "Right", "Bottom", "Left"],
35
+ noun: "sides",
36
+ },
37
+ {
38
+ id: "borderWidth",
39
+ label: "Border width",
40
+ all: "borderWidth",
41
+ sides: ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"],
42
+ names: ["Top", "Right", "Bottom", "Left"],
43
+ noun: "sides",
44
+ },
45
+ {
46
+ id: "borderRadius",
47
+ label: "Radius",
48
+ all: "borderRadius",
49
+ sides: [
50
+ "borderTopLeftRadius",
51
+ "borderTopRightRadius",
52
+ "borderBottomRightRadius",
53
+ "borderBottomLeftRadius",
54
+ ],
55
+ names: ["Top left", "Top right", "Bottom right", "Bottom left"],
56
+ noun: "corners",
57
+ },
58
+ ];
59
+
60
+ const BY_KEY = new Map<StyleKey, BoxGroup>(
61
+ BOX_GROUPS.flatMap((group) =>
62
+ [...(group.all ? [group.all] : []), ...group.sides].map((key) => [key, group] as const),
63
+ ),
64
+ );
65
+
66
+ /** The four-box control a style key belongs to, if any. */
67
+ export const boxGroupOf = (key: StyleKey): BoxGroup | undefined => BY_KEY.get(key);
68
+
69
+ /** Every key the control writes. */
70
+ const groupKeys = (group: BoxGroup): StyleKey[] => [
71
+ ...(group.all ? [group.all] : []),
72
+ ...group.sides,
73
+ ];
74
+
75
+ /** What each box shows: its own value, else the all-sides value. */
76
+ export function sideValues(group: BoxGroup, style: StyleProps | undefined): unknown[] {
77
+ const all = group.all ? style?.[group.all] : undefined;
78
+ return group.sides.map((key) => style?.[key] ?? all);
79
+ }
80
+
81
+ const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
82
+
83
+ /** True when every box shows the same value, unset included. */
84
+ export const allSame = (values: readonly unknown[]) => values.every((v) => same(v, values[0]));
85
+
86
+ /** True when the edited target sets any of the control's keys. */
87
+ export const groupSet = (group: BoxGroup, style: StyleProps | undefined) =>
88
+ groupKeys(group).some((key) => style?.[key] !== undefined);
89
+
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> {
92
+ const patch: Record<string, unknown> = {};
93
+ if (group.all) {
94
+ patch[group.all] = value;
95
+ for (const key of group.sides) patch[key] = undefined;
96
+ } else {
97
+ for (const key of group.sides) patch[key] = value;
98
+ }
99
+ return patch as Partial<StyleProps>;
100
+ }
101
+
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>;
105
+
106
+ /** Linking copies the first box that has a value to all four. */
107
+ export function linkPatch(group: BoxGroup, style: StyleProps | undefined): Partial<StyleProps> {
108
+ return linkedPatch(
109
+ group,
110
+ sideValues(group, style).find((value) => value !== undefined),
111
+ );
112
+ }
113
+
114
+ /** Clears every key of the control. */
115
+ export function resetPatch(group: BoxGroup): Partial<StyleProps> {
116
+ const patch: Record<string, unknown> = {};
117
+ for (const key of groupKeys(group)) patch[key] = undefined;
118
+ return patch as Partial<StyleProps>;
119
+ }
120
+
121
+ const isLiteral = (value: unknown): value is { value: number; unit: LengthUnit } =>
122
+ typeof value === "object" &&
123
+ value !== null &&
124
+ typeof (value as { value?: unknown }).value === "number" &&
125
+ typeof (value as { unit?: unknown }).unit === "string";
126
+
127
+ /** The shared unit menu: every number the control sets keeps its value in the new unit. */
128
+ export function unitPatch(
129
+ group: BoxGroup,
130
+ style: StyleProps | undefined,
131
+ unit: LengthUnit,
132
+ ): Partial<StyleProps> {
133
+ const patch: Record<string, unknown> = {};
134
+ for (const key of groupKeys(group)) {
135
+ const value = style?.[key];
136
+ if (isLiteral(value) && value.unit !== unit) patch[key] = { value: value.value, unit };
137
+ }
138
+ return patch as Partial<StyleProps>;
139
+ }
140
+
141
+ /** The unit the shared menu shows: the first box with a number, else `fallback`. */
142
+ export function sharedUnit(values: readonly unknown[], fallback: LengthUnit): LengthUnit {
143
+ return (values.find(isLiteral) as { unit: LengthUnit } | undefined)?.unit ?? fallback;
144
+ }
145
+
146
+ /** A box's text: the number (with its unit when it differs from the menu), `auto` or "". */
147
+ export function sideDraft(value: unknown, unit: LengthUnit, varName?: string): string {
148
+ if (isLiteral(value))
149
+ return value.unit === unit ? String(value.value) : `${value.value}${value.unit}`;
150
+ if (value === "auto") return "auto";
151
+ if (typeof value === "object" && value !== null && "var" in value) return varName ?? "";
152
+ return "";
153
+ }
@@ -0,0 +1,27 @@
1
+ import { sanitizeHref, type LayoutNode } from "../../../../core/index.ts";
2
+
3
+ /**
4
+ * W-273: a Button without a usable URL renders as a plain `<button>` that does nothing on the
5
+ * live page. That's right when a popup's click trigger or a script targets it, usually by its
6
+ * HTML id or a class, so only a button with neither gets the note.
7
+ */
8
+ export function buttonUrlNote(node: LayoutNode): string | undefined {
9
+ if (node.type === "link") return linkUrlNote(node);
10
+ if (node.type !== "button") return undefined;
11
+ const props = node.props as { href?: string };
12
+ const href = props.href?.trim();
13
+ if (href && sanitizeHref(href)) return undefined;
14
+ if (node.htmlId || (node.classes?.length ?? 0) > 0) return undefined;
15
+ return href
16
+ ? "This URL isn't allowed, so the button does nothing on the live page. Use a full URL or a path such as /contact."
17
+ : "No URL: this button does nothing on the live page. Add a URL, or give it an HTML id (Advanced) for a popup's click trigger.";
18
+ }
19
+
20
+ /** W-276: a Link without a usable URL renders `href="#"`, which only jumps to the top. */
21
+ function linkUrlNote(node: LayoutNode): string | undefined {
22
+ const href = (node.props as { href?: string }).href?.trim();
23
+ if (href && sanitizeHref(href)) return undefined;
24
+ return href
25
+ ? "This URL isn't allowed, so the link only jumps to the top of the page. Use a full URL or a path such as /contact."
26
+ : "No URL: this link only jumps to the top of the page. Add a URL.";
27
+ }
@@ -1,4 +1,4 @@
1
- import type { DesignSystem } from "../../../../core/index.ts";
1
+ import { cleanClassName, type DesignSystem } from "../../../../core/index.ts";
2
2
 
3
3
  type StyleClass = NonNullable<DesignSystem["classes"]>[number];
4
4
 
@@ -35,8 +35,10 @@ export function classOptions(
35
35
  .map(({ cls }) => cls)
36
36
  : available;
37
37
  const options: ClassOption[] = found.map((cls) => ({ kind: "class", cls }));
38
- const taken = catalog.some((cls) => cls.name.toLowerCase() === q);
39
- if (q && !taken) options.push({ kind: "create", name: query.trim() });
38
+ // The new name as it will be saved: at most 60 characters, no control characters (W-220).
39
+ const name = cleanClassName(query);
40
+ const taken = catalog.some((cls) => cls.name.toLowerCase() === name.toLowerCase());
41
+ if (name && !taken) options.push({ kind: "create", name });
40
42
  return options;
41
43
  }
42
44
 
@@ -0,0 +1,38 @@
1
+ import {
2
+ findNode,
3
+ isFormNode,
4
+ parentOf,
5
+ type Layout,
6
+ type LayoutNode,
7
+ } from "../../../../core/index.ts";
8
+
9
+ const fieldOf = (node: LayoutNode): string => {
10
+ const value = (node.props as Record<string, unknown> | undefined)?.field;
11
+ return typeof value === "string" ? value.trim() : "";
12
+ };
13
+
14
+ /**
15
+ * W-194: true when another control in the same form submits under this node's field name, so
16
+ * one value would overwrite the other. Controls outside any form are not checked.
17
+ */
18
+ export function duplicateFieldName(layout: Layout, nodeId: string): boolean {
19
+ const self = findNode(layout, nodeId);
20
+ const name = self ? fieldOf(self) : "";
21
+ if (!name) return false;
22
+ let current = parentOf(layout, nodeId);
23
+ while (current) {
24
+ const form = findNode(layout, current);
25
+ if (form && isFormNode(form)) {
26
+ let count = 0;
27
+ const walk = (node: LayoutNode) => {
28
+ if (node.id !== form.id && fieldOf(node) === name) count += 1;
29
+ if ("children" in node && Array.isArray(node.children))
30
+ for (const child of node.children) walk(child);
31
+ };
32
+ walk(form);
33
+ return count > 1;
34
+ }
35
+ current = parentOf(layout, current);
36
+ }
37
+ return false;
38
+ }
@@ -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
+ }
@@ -1,13 +1,14 @@
1
1
  import { STYLE_LABELS, type StyleKey } from "./style-sections.ts";
2
2
 
3
3
  export type LengthUnit = "px" | "rem" | "em" | "%" | "vw" | "vh";
4
- export type UnitChoice = LengthUnit | "auto";
4
+ /** `x` is a unitless number, for Line height only (W-213). */
5
+ export type UnitChoice = LengthUnit | "auto" | "x";
5
6
  export type LengthLiteral = { value: number; unit: LengthUnit };
6
7
 
7
8
  const BOX: readonly UnitChoice[] = ["px", "%", "rem", "em", "vw", "vh"];
8
9
  const BOX_AUTO: readonly UnitChoice[] = [...BOX, "auto"];
9
10
 
10
- /** Units each length property offers in its unit menu (DESIGN.md § Inputs). */
11
+ /** Units each length property offers in its unit menu. */
11
12
  const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
12
13
  width: BOX_AUTO,
13
14
  height: BOX_AUTO,
@@ -20,21 +21,33 @@ const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
20
21
  bottom: BOX_AUTO,
21
22
  left: BOX_AUTO,
22
23
  fontSize: ["px", "rem", "em", "%", "vw"],
23
- lineHeight: ["px", "rem", "em", "%"],
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"],
24
26
  letterSpacing: ["px", "rem", "em"],
25
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"],
26
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"],
27
37
  };
28
38
 
29
39
  export const unitsFor = (key: StyleKey): readonly UnitChoice[] => UNITS[key] ?? BOX;
30
40
 
31
- const NEGATIVE = new Set<StyleKey>(["top", "right", "bottom", "left"]);
41
+ const NEGATIVE = new Set<StyleKey>(["top", "right", "bottom", "left", "letterSpacing"]);
32
42
 
33
43
  export type ParsedLength =
34
- | { ok: true; value: LengthLiteral | "auto" | undefined }
44
+ | { ok: true; value: LengthLiteral | "auto" | number | undefined }
35
45
  | { ok: false; message: string };
36
46
 
37
- const DRAFT = /^(-?(?:\d+(?:\.\d*)?|\.\d+))\s*(px|rem|em|%|vw|vh)?$/i;
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;
38
51
 
39
52
  const listed = (units: readonly string[]) =>
40
53
  units.length > 1 ? `${units.slice(0, -1).join(", ")} or ${units.at(-1)}` : (units[0] ?? "");
@@ -43,7 +56,11 @@ const listed = (units: readonly string[]) =>
43
56
  * Parses a length field's text: a number in `unit`, a number with its own unit ("50%",
44
57
  * "1.5rem"), `auto` where allowed, or empty for unset.
45
58
  */
46
- export function parseLengthDraft(draft: string, key: StyleKey, unit: LengthUnit): ParsedLength {
59
+ export function parseLengthDraft(
60
+ draft: string,
61
+ key: StyleKey,
62
+ unit: LengthUnit | "x",
63
+ ): ParsedLength {
47
64
  const text = draft.trim();
48
65
  if (text === "") return { ok: true, value: undefined };
49
66
  const label = STYLE_LABELS[key];
@@ -56,8 +73,24 @@ export function parseLengthDraft(draft: string, key: StyleKey, unit: LengthUnit)
56
73
  const match = DRAFT.exec(text);
57
74
  const n = match ? Number(match[1]) : Number.NaN;
58
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
+ }
59
85
  return { ok: false, message: `Enter a number, such as 16 or 16${unit}.` };
60
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
+ }
61
94
  const typed = (match[2]?.toLowerCase() ?? unit) as LengthUnit;
62
95
  if (!allowed.includes(typed)) {
63
96
  return {
@@ -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
+ }
@@ -1,6 +1,7 @@
1
1
  import type { StyleProps } from "../../../../core/index.ts";
2
2
 
3
3
  export type StyleSectionId =
4
+ | "icon"
4
5
  | "layout"
5
6
  | "spacing"
6
7
  | "size"
@@ -15,6 +16,7 @@ export type StyleKey = keyof StyleProps;
15
16
 
16
17
  /** Elementor v4 order (W-088); every list below follows it. */
17
18
  const SECTION_ORDER: StyleSectionId[] = [
19
+ "icon", // W-237: Icon only, first like Elementor's Icon style
18
20
  "layout",
19
21
  "spacing",
20
22
  "size",
@@ -40,12 +42,15 @@ const TEXT_SECTIONS: StyleSectionId[] = [
40
42
  /** Which Style sections appear, and which opens by default (IA table). */
41
43
  export const STYLE_UI: Record<string, { sections: StyleSectionId[]; defaultOpen: StyleSectionId }> =
42
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.
43
47
  container: {
44
48
  sections: [
45
49
  "layout",
46
50
  "spacing",
47
51
  "size",
48
52
  "position",
53
+ "typography",
49
54
  "background",
50
55
  "border",
51
56
  "effects",
@@ -63,14 +68,25 @@ export const STYLE_UI: Record<string, { sections: StyleSectionId[]; defaultOpen:
63
68
  label: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
64
69
  link: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
65
70
  list: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
66
- button: { sections: TEXT_SECTIONS, defaultOpen: "background" },
71
+ button: { sections: ["layout", ...TEXT_SECTIONS], defaultOpen: "background" },
67
72
  image: {
68
73
  sections: ["spacing", "size", "position", "border", "effects", "advanced"],
69
74
  defaultOpen: "size",
70
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.
71
78
  icon: {
72
- sections: ["spacing", "size", "position", "typography", "effects", "advanced"],
73
- defaultOpen: "typography",
79
+ sections: [
80
+ "icon",
81
+ "spacing",
82
+ "size",
83
+ "position",
84
+ "background",
85
+ "border",
86
+ "effects",
87
+ "advanced",
88
+ ],
89
+ defaultOpen: "icon",
74
90
  },
75
91
  video: {
76
92
  sections: ["spacing", "size", "position", "border", "effects", "advanced"],
@@ -89,9 +105,10 @@ export const STYLE_UI: Record<string, { sections: StyleSectionId[]; defaultOpen:
89
105
  ],
90
106
  defaultOpen: "layout",
91
107
  },
92
- "text-input": { sections: TEXT_SECTIONS, defaultOpen: "typography" },
93
- textarea: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
94
- select: { sections: TEXT_SECTIONS, defaultOpen: "typography" },
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" },
95
112
  checkbox: {
96
113
  sections: ["layout", "spacing", "size", "position", "typography", "effects", "advanced"],
97
114
  defaultOpen: "typography",
@@ -100,7 +117,7 @@ export const STYLE_UI: Record<string, { sections: StyleSectionId[]; defaultOpen:
100
117
  sections: ["layout", "spacing", "size", "position", "typography", "effects", "advanced"],
101
118
  defaultOpen: "typography",
102
119
  },
103
- submit: { sections: TEXT_SECTIONS, defaultOpen: "background" },
120
+ submit: { sections: ["layout", ...TEXT_SECTIONS], defaultOpen: "background" },
104
121
  };
105
122
 
106
123
  /** Types without an entry (Flexbox, Div Block, SVG, Tabs, dynamic elements) show every section. */
@@ -110,6 +127,7 @@ export const DEFAULT_UI = {
110
127
  };
111
128
 
112
129
  export const SECTION_LABELS: Record<StyleSectionId, string> = {
130
+ icon: "Icon",
113
131
  layout: "Layout",
114
132
  spacing: "Spacing",
115
133
  size: "Size",
@@ -175,20 +193,82 @@ const SECTION_KEYS: Record<StyleSectionId, StyleKey[]> = {
175
193
  "overlay",
176
194
  "backgroundVideo",
177
195
  ],
178
- border: ["borderWidth", "borderStyle", "borderColor", "borderRadius"],
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
+ ],
179
210
  effects: ["opacity", "boxShadow", "filter", "cursor", "entrance", "transition"],
211
+ icon: ["iconRotate", "iconFlip", "iconScale", "iconStrokeWidth", "iconShadow", "iconAnimation"],
180
212
  advanced: [],
181
213
  };
182
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
+
183
221
  /** Keys that only make sense on some element types. */
184
222
  const ONLY_FOR: Partial<Record<StyleKey, string[]>> = {
185
223
  objectFit: ["image", "video"],
224
+ ...Object.fromEntries(
225
+ ["iconRotate", "iconFlip", "iconScale", "iconStrokeWidth", "iconShadow", "iconAnimation"].map(
226
+ (key) => [key, ["icon"]],
227
+ ),
228
+ ),
186
229
  };
187
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
+
188
261
  /** Per-type filters so Spacer and Divider don't get every control. */
189
262
  const TYPE_SECTION_KEYS: Record<string, Partial<Record<StyleSectionId, StyleKey[]>>> = {
190
263
  spacer: { layout: [] }, // height is a content prop, shown above sections
191
- divider: { size: ["width"] },
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 }])),
192
272
  };
193
273
 
194
274
  const OFFSETS = new Set<StyleKey>(["top", "right", "bottom", "left"]);
@@ -214,16 +294,25 @@ export function keysFor(
214
294
  SECTION_KEYS[section].filter((key) => ONLY_FOR[key]?.includes(type) ?? true)
215
295
  ).filter((key) => !OFFSETS.has(key) || offsetsApply(position)),
216
296
  );
217
- return SECTION_KEYS[section].filter((key) => offered.has(key) || style?.[key] !== undefined);
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"];
218
303
  }
219
304
 
220
305
  /** The type's sections, plus any other section holding a set value, in section order. */
221
306
  export function sectionsFor(
222
307
  sections: StyleSectionId[],
223
308
  style: StyleProps | undefined,
309
+ type?: string,
224
310
  ): StyleSectionId[] {
311
+ const moved = type === "icon" ? ICON_MOVED : [];
225
312
  return SECTION_ORDER.filter(
226
- (id) => sections.includes(id) || SECTION_KEYS[id].some((key) => style?.[key] !== undefined),
313
+ (id) =>
314
+ sections.includes(id) ||
315
+ SECTION_KEYS[id].some((key) => style?.[key] !== undefined && !moved.includes(key)),
227
316
  );
228
317
  }
229
318
 
@@ -276,14 +365,28 @@ export const STYLE_LABELS: Record<StyleKey, string> = {
276
365
  gradient: "Gradient",
277
366
  overlay: "Overlay",
278
367
  borderWidth: "Border width",
368
+ borderTopWidth: "Border top width",
369
+ borderRightWidth: "Border right width",
370
+ borderBottomWidth: "Border bottom width",
371
+ borderLeftWidth: "Border left width",
279
372
  borderStyle: "Border style",
280
373
  borderColor: "Border color",
281
374
  borderRadius: "Radius",
375
+ borderTopLeftRadius: "Radius top left",
376
+ borderTopRightRadius: "Radius top right",
377
+ borderBottomRightRadius: "Radius bottom right",
378
+ borderBottomLeftRadius: "Radius bottom left",
282
379
  opacity: "Opacity",
283
380
  boxShadow: "Box shadow",
284
381
  filter: "Filters",
285
382
  cursor: "Cursor",
286
383
  entrance: "Entrance",
384
+ iconRotate: "Rotate",
385
+ iconFlip: "Flip",
386
+ iconScale: "Scale",
387
+ iconStrokeWidth: "Stroke width",
388
+ iconShadow: "Drop shadow",
389
+ iconAnimation: "Animation",
287
390
  transition: "Transition",
288
391
  };
289
392
 
@@ -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
+ }