@perkyzz/emvb 0.1.0 → 0.2.1

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 (154) hide show
  1. package/README.md +6 -4
  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 +9 -5
  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 +25 -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 +168 -24
  106. package/src/astro/tabs/runtime.ts +6 -1
  107. package/src/astro/theme-context.ts +25 -5
  108. package/src/astro/theme-posts.ts +19 -1
  109. package/src/constants.ts +1 -1
  110. package/src/core/arrange.ts +98 -10
  111. package/src/core/clipboard.ts +91 -9
  112. package/src/core/css/generate.ts +21 -4
  113. package/src/core/design/classes.ts +95 -9
  114. package/src/core/design/transfer.ts +101 -2
  115. package/src/core/design/variables.ts +51 -11
  116. package/src/core/elements/dynamic-elements.ts +57 -5
  117. package/src/core/elements/field-id.ts +6 -0
  118. package/src/core/elements/form-elements.ts +23 -8
  119. package/src/core/elements/index.ts +267 -49
  120. package/src/core/elements/menu.ts +190 -0
  121. package/src/core/forms/definition.ts +11 -0
  122. package/src/core/index.ts +67 -3
  123. package/src/core/limits.ts +2 -0
  124. package/src/core/migrate/index.ts +51 -1
  125. package/src/core/nesting.ts +51 -0
  126. package/src/core/render/context.ts +7 -0
  127. package/src/core/render/dynamic-post.ts +39 -11
  128. package/src/core/render/extras.ts +22 -3
  129. package/src/core/render/form.ts +134 -36
  130. package/src/core/render/index.ts +123 -25
  131. package/src/core/render/loop.ts +10 -3
  132. package/src/core/render/pagination.ts +76 -0
  133. package/src/core/render/section.ts +5 -1
  134. package/src/core/render/tabs.ts +8 -4
  135. package/src/core/render/vnode.ts +1 -1
  136. package/src/core/sanitize/css.ts +197 -17
  137. package/src/core/sanitize/embed-url.ts +64 -7
  138. package/src/core/sanitize/svg-upload.ts +203 -0
  139. package/src/core/sanitize/svg.ts +102 -21
  140. package/src/core/schema/descriptors.ts +4 -0
  141. package/src/core/schema/design.ts +7 -2
  142. package/src/core/schema/layout.ts +210 -19
  143. package/src/core/schema/style.ts +87 -8
  144. package/src/core/tabs/presence.ts +9 -0
  145. package/src/core/theme/conditions.ts +4 -1
  146. package/src/core/theme/dynamic.ts +10 -0
  147. package/src/core/theme/float.ts +113 -0
  148. package/src/core/theme/pagination.ts +97 -0
  149. package/src/core/theme/part-types.ts +2 -0
  150. package/src/core/theme/popup-markup.ts +3 -1
  151. package/src/core/theme/popup-rules.ts +4 -3
  152. package/src/server/hooks.ts +20 -0
  153. package/src/server/icon-routes.ts +79 -0
  154. package/src/server/plugin.ts +5 -1
@@ -1,3 +1,4 @@
1
+ import { controlId } from "./field-id.ts";
1
2
  import type {
2
3
  CheckboxNode,
3
4
  FormNode,
@@ -75,6 +76,7 @@ const fieldBox = (attrs: Record<string, string>, children: VNode["children"]): V
75
76
  });
76
77
 
77
78
  const fieldWrap = (
79
+ controlFor: string,
78
80
  name: string,
79
81
  labelText: string | undefined,
80
82
  control: VNode,
@@ -85,7 +87,7 @@ const fieldWrap = (
85
87
  ? [
86
88
  {
87
89
  tag: "label",
88
- attrs: { class: "emvb-form-label", for: name },
90
+ attrs: { class: "emvb-form-label", for: controlFor },
89
91
  children: [labelText],
90
92
  } as VNode,
91
93
  ]
@@ -98,12 +100,13 @@ const fieldWrap = (
98
100
  const textControl = (
99
101
  tag: "input" | "textarea",
100
102
  props: { field: string; placeholder?: string | undefined },
103
+ id: string,
101
104
  ): VNode => ({
102
105
  tag,
103
106
  attrs: {
104
107
  ...(tag === "input" ? { type: "text" } : {}),
105
108
  class: "ec-form-input",
106
- id: props.field,
109
+ id,
107
110
  name: props.field,
108
111
  ...(props.placeholder ? { placeholder: props.placeholder } : {}),
109
112
  },
@@ -115,7 +118,13 @@ export const textInput: ElementDefinition<TextInputNode> = {
115
118
  defaults: () => ({ type: "text-input", props: { field: "name", label: "Name" } }),
116
119
  descriptor: fieldDescriptor("text-input", "Text input", TEXT_FIELDS),
117
120
  build: (node, attrs) =>
118
- fieldWrap(node.props.field, node.props.label, textControl("input", node.props), attrs),
121
+ fieldWrap(
122
+ controlId(node.id),
123
+ node.props.field,
124
+ node.props.label,
125
+ textControl("input", node.props, controlId(node.id)),
126
+ attrs,
127
+ ),
119
128
  };
120
129
 
121
130
  export const textareaEl: ElementDefinition<TextareaNode> = {
@@ -123,7 +132,13 @@ export const textareaEl: ElementDefinition<TextareaNode> = {
123
132
  defaults: () => ({ type: "textarea", props: { field: "message", label: "Message" } }),
124
133
  descriptor: fieldDescriptor("textarea", "Textarea", TEXT_FIELDS),
125
134
  build: (node, attrs) =>
126
- fieldWrap(node.props.field, node.props.label, textControl("textarea", node.props), attrs),
135
+ fieldWrap(
136
+ controlId(node.id),
137
+ node.props.field,
138
+ node.props.label,
139
+ textControl("textarea", node.props, controlId(node.id)),
140
+ attrs,
141
+ ),
127
142
  };
128
143
 
129
144
  export const selectEl: ElementDefinition<SelectNode> = {
@@ -134,10 +149,10 @@ export const selectEl: ElementDefinition<SelectNode> = {
134
149
  const name = node.props.field;
135
150
  const control: VNode = {
136
151
  tag: "select",
137
- attrs: { class: "ec-form-input", id: name, name },
152
+ attrs: { class: "ec-form-input", id: controlId(node.id), name },
138
153
  children: [{ tag: "option", attrs: { value: "" }, children: ["Choose…"] }],
139
154
  };
140
- return fieldWrap(name, node.props.label, control, attrs);
155
+ return fieldWrap(controlId(node.id), name, node.props.label, control, attrs);
141
156
  },
142
157
  };
143
158
 
@@ -149,7 +164,7 @@ export const checkbox: ElementDefinition<CheckboxNode> = {
149
164
  const name = node.props.field;
150
165
  const input: VNode = {
151
166
  tag: "input",
152
- attrs: { type: "checkbox", id: name, name, value: "true" },
167
+ attrs: { type: "checkbox", id: controlId(node.id), name, value: "true" },
153
168
  children: [],
154
169
  };
155
170
  const labelEl: VNode = {
@@ -182,7 +197,7 @@ export const radio: ElementDefinition<RadioNode> = {
182
197
  },
183
198
  ],
184
199
  };
185
- return fieldWrap(name, node.props.label, control, attrs);
200
+ return fieldWrap(controlId(node.id), name, node.props.label, control, attrs);
186
201
  },
187
202
  };
188
203
 
@@ -2,6 +2,7 @@ import type {
2
2
  ButtonNode,
3
3
  ContainerNode,
4
4
  DivBlockNode,
5
+ LayoutSectionNode,
5
6
  FlexboxNode,
6
7
  GridNode,
7
8
  SvgNode,
@@ -30,9 +31,11 @@ import { resolveEmbedUrl } from "../sanitize/embed-url.ts";
30
31
  import type { VNode } from "../render/vnode.ts";
31
32
 
32
33
  import type { ElementDefinition } from "./definition.ts";
34
+ import { menu, menuItem } from "./menu.ts";
33
35
  import { checkbox, form, radio, selectEl, submit, textInput, textareaEl } from "./form-elements.ts";
34
36
  import {
35
37
  loop,
38
+ pagination,
36
39
  section,
37
40
  postContent,
38
41
  postExcerpt,
@@ -48,8 +51,33 @@ const HEADING_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6"] as const;
48
51
  const newTabAttrs = (newTab: boolean | undefined): Record<string, string> =>
49
52
  newTab ? { target: "_blank", rel: "noopener noreferrer" } : {};
50
53
 
54
+ const LINK_MESSAGE = "Use a full URL such as https://example.com or a path such as /pricing.";
55
+
56
+ /** Optional Link and new-tab fields for elements that wrap their content in a link (W-141). */
57
+ const INNER_LINK_FIELDS = [
58
+ { key: "href", kind: "href" as const, label: "Link", optional: true, message: LINK_MESSAGE },
59
+ { key: "newTab", kind: "boolean" as const, label: "Open in a new tab", optional: true },
60
+ ];
61
+
62
+ /** The safe link for an optional href, or undefined when there is none or it is refused. */
63
+ const innerLink = (
64
+ href: string | undefined,
65
+ newTab: boolean | undefined,
66
+ className: string,
67
+ children: VNode["children"],
68
+ extra: Record<string, string> = {},
69
+ ): VNode | undefined => {
70
+ const safe = href?.trim() ? sanitizeHref(href) : undefined;
71
+ if (!safe) return undefined;
72
+ return {
73
+ tag: "a",
74
+ attrs: { class: className, href: safe, ...newTabAttrs(newTab), ...extra },
75
+ children,
76
+ };
77
+ };
78
+
51
79
  const heading: ElementDefinition<HeadingNode> = {
52
- baseCss: ".emvb-heading{margin:0}",
80
+ baseCss: ".emvb-heading{margin:0}.emvb-heading-link{color:inherit;text-decoration:inherit}",
53
81
  defaults: () => ({ type: "heading", props: { text: "Heading", level: 2 } }),
54
82
  descriptor: {
55
83
  type: "heading",
@@ -64,28 +92,31 @@ const heading: ElementDefinition<HeadingNode> = {
64
92
  label: "Level",
65
93
  options: [1, 2, 3, 4, 5, 6].map((n) => ({ value: n, label: `H${n}` })),
66
94
  },
95
+ ...INNER_LINK_FIELDS,
67
96
  ],
68
97
  },
69
- build: (node, attrs) => ({
70
- tag: HEADING_TAGS[node.props.level - 1] ?? "h2",
71
- attrs,
72
- children: [node.props.text],
73
- }),
98
+ build: (node, attrs) => {
99
+ const linked = innerLink(node.props.href, node.props.newTab, "emvb-heading-link", [
100
+ node.props.text,
101
+ ]);
102
+ return {
103
+ tag: HEADING_TAGS[node.props.level - 1] ?? "h2",
104
+ attrs,
105
+ children: [linked ?? node.props.text],
106
+ };
107
+ },
74
108
  };
75
109
 
110
+ /** A box link is checked like any link, so a bad URL gets an inline error, not a silent drop (W-176). */
76
111
  const BOX_LINK_FIELDS = [
77
- {
78
- key: "href",
79
- kind: "text" as const,
80
- label: "Link",
81
- optional: true,
82
- message: "Makes this box the link when it is a div. A link already inside stays as it is.",
83
- },
112
+ { key: "href", kind: "href" as const, label: "Link", optional: true, message: LINK_MESSAGE },
84
113
  { key: "newTab", kind: "boolean" as const, label: "Open in new tab", optional: true },
85
114
  ];
86
115
 
87
116
  const container: ElementDefinition<ContainerNode> = {
88
- baseCss: ".emvb-container{display:flex;flex-direction:column;min-width:0}",
117
+ // W-299: a word longer than the line (a pasted URL) breaks instead of widening the page on a phone.
118
+ baseCss:
119
+ ".emvb-container{display:flex;flex-direction:column;min-width:0;overflow-wrap:break-word}",
89
120
  defaults: () => ({ type: "container", props: {}, children: [] }),
90
121
  descriptor: {
91
122
  type: "container",
@@ -136,7 +167,11 @@ const spacer: ElementDefinition<SpacerNode> = {
136
167
  };
137
168
 
138
169
  const divider: ElementDefinition<DividerNode> = {
139
- baseCss: ".emvb-divider{border:0;border-top:1px solid currentColor;margin:0}",
170
+ // W-266: full width by default; an <hr> has no content width, so in a centred column it was 0 wide.
171
+ baseCss:
172
+ // W-270: a Divider is its top border. Border style on the other sides stays none (the tag in
173
+ // the selector outranks an element's class), so "dashed" draws a dashed line, not a box.
174
+ ".emvb-divider{border:0;border-top:1px solid currentColor;margin:0}:where(.emvb-divider){width:100%}hr.emvb-divider{border-right-style:none;border-bottom-style:none;border-left-style:none}",
140
175
  defaults: () => ({ type: "divider", props: {} }),
141
176
  descriptor: {
142
177
  type: "divider",
@@ -149,7 +184,8 @@ const divider: ElementDefinition<DividerNode> = {
149
184
  };
150
185
 
151
186
  const text: ElementDefinition<TextNode> = {
152
- baseCss: ".emvb-text{margin:0}",
187
+ // W-264: a paragraph's line breaks show (pre-line), in :where() so classes and styles win.
188
+ baseCss: ".emvb-text{margin:0}:where(.emvb-text){white-space:pre-line}",
153
189
  defaults: () => ({ type: "text", props: { text: "Text" } }),
154
190
  descriptor: {
155
191
  type: "text",
@@ -207,10 +243,11 @@ const link: ElementDefinition<LinkNode> = {
207
243
  ],
208
244
  },
209
245
  build: (node, attrs) => {
210
- const href = sanitizeHref(node.props.href) ?? "#";
246
+ const safe = sanitizeHref(node.props.href);
247
+ // W-276: without a usable URL the link falls back to "#", which mustn't open a new tab.
211
248
  return {
212
249
  tag: "a",
213
- attrs: { ...attrs, href, ...newTabAttrs(node.props.newTab) },
250
+ attrs: { ...attrs, href: safe ?? "#", ...(safe ? newTabAttrs(node.props.newTab) : {}) },
214
251
  children: [node.props.text],
215
252
  };
216
253
  },
@@ -218,7 +255,8 @@ const link: ElementDefinition<LinkNode> = {
218
255
 
219
256
  const button: ElementDefinition<ButtonNode> = {
220
257
  baseCss:
221
- ".emvb-button{display:inline-flex;align-items:center;justify-content:center;margin:0;font:inherit;text-decoration:none;cursor:pointer}",
258
+ // The look sits in :where() so site tag defaults, classes and local styles all win (W-148).
259
+ ".emvb-button{display:inline-flex;align-items:center;justify-content:center;margin:0;font:inherit;text-decoration:none;cursor:pointer}:where(.emvb-button){color:inherit;background:transparent;border:1px solid currentColor;border-radius:6px;padding:0.625em 1.25em;line-height:1.2}",
222
260
  defaults: () => ({ type: "button", props: { text: "Button" } }),
223
261
  descriptor: {
224
262
  type: "button",
@@ -270,12 +308,18 @@ const list: ElementDefinition<ListNode> = {
270
308
  build: (node, attrs) => ({
271
309
  tag: node.props.ordered ? "ol" : "ul",
272
310
  attrs,
273
- children: node.props.items.map((item) => ({ tag: "li", attrs: {}, children: [item] })),
311
+ // W-275: blank items would be empty bullets on the page; a list of only blanks has none.
312
+ children: node.props.items
313
+ .filter((item) => item.trim() !== "")
314
+ .map((item) => ({ tag: "li", attrs: {}, children: [item] })),
274
315
  }),
275
316
  };
276
317
 
277
318
  const image: ElementDefinition<ImageNode> = {
278
- baseCss: ".emvb-image{display:block;max-width:100%;height:auto}",
319
+ // W-269: natural size, at most the container's width. A container's default stretch made a
320
+ // 400 px image 1184 px wide (blurry); a Width (px) attribute or a style width still sets it.
321
+ baseCss:
322
+ ".emvb-image{display:block;max-width:100%;height:auto}:where(img.emvb-image:not([width])){width:fit-content}",
279
323
  defaults: () => ({
280
324
  type: "image",
281
325
  props: { src: "", alt: "Image", decorative: false },
@@ -300,6 +344,8 @@ const image: ElementDefinition<ImageNode> = {
300
344
  label: "Decorative (empty alt)",
301
345
  optional: true,
302
346
  },
347
+ // The first big image people see (hero, LCP) shouldn't wait for lazy loading (W-226).
348
+ { key: "priority", kind: "boolean", label: "Load right away", optional: true },
303
349
  {
304
350
  key: "width",
305
351
  kind: "int",
@@ -330,8 +376,9 @@ const image: ElementDefinition<ImageNode> = {
330
376
  ...attrs,
331
377
  src,
332
378
  alt: decorative ? "" : node.props.alt,
333
- loading: "lazy",
334
- decoding: "async",
379
+ ...(node.props.priority === true
380
+ ? { loading: "eager", fetchpriority: "high" }
381
+ : { loading: "lazy", decoding: "async" }),
335
382
  };
336
383
  if (decorative) imgAttrs.role = "presentation";
337
384
  if (node.props.width !== undefined) imgAttrs.width = String(node.props.width);
@@ -340,9 +387,19 @@ const image: ElementDefinition<ImageNode> = {
340
387
  },
341
388
  };
342
389
 
390
+ /** Root stroke widths the Stroke width control can override (W-237); Lucide and Tabler use 2. */
391
+ const ICON_STROKE_WIDTHS = ["1", "1.5", "2", "2.5", "3"] as const;
392
+
343
393
  const icon: ElementDefinition<IconNode> = {
344
394
  baseCss:
345
- ".emvb-icon{display:inline-flex;align-items:center;justify-content:center;line-height:0;color:inherit}.emvb-icon svg{display:block;width:1em;height:1em}.emvb-icon-missing{min-width:1em;min-height:1em;background:var(--color-kumo-tint,#eee)}",
395
+ // W-237: the glyph reads the wrapper's icon custom properties (rotate, flip, shadow, loop,
396
+ // stroke); unset they change nothing. The svg inherits the wrapper's transition for hover.
397
+ ".emvb-icon{display:inline-flex;align-items:center;justify-content:center;line-height:0;color:inherit}.emvb-icon-link{display:inline-flex;color:inherit}.emvb-icon svg{display:block;rotate:var(--emvb-icon-rotate,0deg);scale:var(--emvb-icon-flip,1 1);filter:var(--emvb-icon-shadow,none);animation:var(--emvb-icon-animation,none);transition:inherit}" +
398
+ ICON_STROKE_WIDTHS.map(
399
+ (width) =>
400
+ `.emvb-icon-sw${width.replace(".", "_")}{stroke-width:var(--emvb-icon-stroke,${width})}`,
401
+ ).join("") +
402
+ "@keyframes emvb-icon-spin{to{transform:rotate(360deg)}}@keyframes emvb-icon-pulse{from{transform:scale(1)}to{transform:scale(1.15)}}@media (prefers-reduced-motion: reduce){.emvb-icon svg{animation:none}}.emvb-icon-missing{min-width:1em;min-height:1em;background:var(--color-kumo-tint,#eee)}",
346
403
  defaults: () => ({
347
404
  type: "icon",
348
405
  props: { iconId: "star", title: "Star", decorative: false, size: 24 },
@@ -368,11 +425,14 @@ const icon: ElementDefinition<IconNode> = {
368
425
  optional: true,
369
426
  message: "Size must be a positive whole number.",
370
427
  },
428
+ ...INNER_LINK_FIELDS,
371
429
  ],
372
430
  },
373
431
  build: (node, attrs) => {
374
- const bundled = getBundledIcon(node.props.iconId);
375
- if (!bundled) {
432
+ // W-234: a picked library icon carries its own SVG; the allowlist checks it on every render.
433
+ const picked = node.props.iconSvg ? sanitizeSvgMarkup(node.props.iconSvg) : undefined;
434
+ const bundled = picked ? undefined : getBundledIcon(node.props.iconId);
435
+ if (!picked && !bundled) {
376
436
  // Never treat iconId as a URL or raw HTML (R-032 / R-033).
377
437
  return {
378
438
  tag: "span",
@@ -386,40 +446,142 @@ const icon: ElementDefinition<IconNode> = {
386
446
  }
387
447
  const decorative = node.props.decorative === true;
388
448
  const size = node.props.size ?? 24;
389
- const svgAttrs: Record<string, string> = {
390
- xmlns: "http://www.w3.org/2000/svg",
391
- width: String(size),
392
- height: String(size),
393
- viewBox: "0 0 24 24",
394
- fill: "none",
395
- stroke: "currentColor",
396
- "stroke-width": "2",
397
- "stroke-linecap": "round",
398
- "stroke-linejoin": "round",
399
- focusable: "false",
400
- };
449
+ const svgAttrs: Record<string, string> = picked
450
+ ? {
451
+ ...pickedIconAttrs(picked.attrs),
452
+ width: String(size),
453
+ height: String(size),
454
+ focusable: "false",
455
+ }
456
+ : {
457
+ xmlns: "http://www.w3.org/2000/svg",
458
+ width: String(size),
459
+ height: String(size),
460
+ viewBox: "0 0 24 24",
461
+ fill: "none",
462
+ stroke: "currentColor",
463
+ "stroke-width": "2",
464
+ "stroke-linecap": "round",
465
+ "stroke-linejoin": "round",
466
+ focusable: "false",
467
+ };
401
468
  if (decorative) {
402
469
  svgAttrs["aria-hidden"] = "true";
403
470
  } else {
404
471
  svgAttrs.role = "img";
405
472
  if (node.props.title) svgAttrs["aria-label"] = node.props.title;
406
473
  }
407
- const children: VNode[] = bundled.children.map((child) => ({
408
- tag: child.tag,
409
- attrs: { ...child.attrs },
410
- children: [],
411
- }));
412
- return {
413
- tag: "span",
414
- attrs,
415
- children: [{ tag: "svg", attrs: svgAttrs, children }],
474
+ const children: (VNode | string)[] = picked
475
+ ? picked.children
476
+ : (bundled?.children ?? []).map((child) => ({
477
+ tag: child.tag,
478
+ attrs: { ...child.attrs },
479
+ children: [],
480
+ }));
481
+ strokeClass(svgAttrs);
482
+ const single = picked !== undefined && node.props.singleColor === true;
483
+ if (single) monochromeRoot(svgAttrs);
484
+ const svg: VNode = {
485
+ tag: "svg",
486
+ attrs: svgAttrs,
487
+ children: single ? monochrome(children) : children,
416
488
  };
489
+ // A linked icon is named by its title on the link, so the svg inside is hidden.
490
+ const title = node.props.title?.trim();
491
+ const { role: _role, "aria-label": _label, ...plain } = svgAttrs;
492
+ const hidden: VNode = { ...svg, attrs: { ...plain, "aria-hidden": "true" } };
493
+ const linked = title
494
+ ? innerLink(node.props.href, node.props.newTab, "emvb-icon-link", [hidden], {
495
+ "aria-label": title,
496
+ })
497
+ : undefined;
498
+ return { tag: "span", attrs, children: [linked ?? svg] };
417
499
  },
418
500
  };
419
501
 
502
+ /**
503
+ * W-237: a stroke icon's root `stroke-width` moves into a class whose CSS reads the wrapper's
504
+ * `--emvb-icon-stroke` with the original width as fallback; any other width stays as it was.
505
+ */
506
+ function strokeClass(svgAttrs: Record<string, string>): void {
507
+ const width = svgAttrs["stroke-width"];
508
+ if (!width || !(ICON_STROKE_WIDTHS as readonly string[]).includes(width)) return;
509
+ if (!svgAttrs.stroke || svgAttrs.stroke === "none") return;
510
+ delete svgAttrs["stroke-width"];
511
+ const cls = `emvb-icon-sw${width.replace(".", "_")}`;
512
+ svgAttrs.class = svgAttrs.class ? `${svgAttrs.class} ${cls}` : cls;
513
+ }
514
+
515
+ /** Whether an icon's SVG is stroke-drawn with an adjustable width (the panel shows the control). */
516
+ export function iconHasAdjustableStroke(svg: string | undefined): boolean {
517
+ if (!svg) return true; // bundled Lucide
518
+ const picked = sanitizeSvgMarkup(svg);
519
+ if (!picked) return false;
520
+ const attrs = pickedIconAttrs(picked.attrs);
521
+ const before = attrs["stroke-width"];
522
+ strokeClass(attrs);
523
+ return before !== undefined && attrs["stroke-width"] === undefined;
524
+ }
525
+
526
+ /** Paint attributes a multi-colour SVG sets its colours with (W-238). */
527
+ const PAINT_ATTRS = ["fill", "stroke", "stop-color"] as const;
528
+
529
+ const ownColor = (value: string | undefined) =>
530
+ value !== undefined && value !== "none" && value.toLowerCase() !== "currentcolor";
531
+
532
+ /** W-238: every fill, stroke and gradient stop becomes the icon's colour; `none` stays none. */
533
+ function monochrome(nodes: (VNode | string)[]): (VNode | string)[] {
534
+ return nodes.map((child) => {
535
+ if (typeof child === "string") return child;
536
+ const attrs = { ...child.attrs };
537
+ for (const name of PAINT_ATTRS) if (ownColor(attrs[name])) attrs[name] = "currentColor";
538
+ return { ...child, attrs, children: monochrome(child.children) };
539
+ });
540
+ }
541
+
542
+ /** The root too; without a fill, SVG paints black, so it gets the icon's colour. */
543
+ function monochromeRoot(attrs: Record<string, string>): void {
544
+ if (attrs.fill === undefined || ownColor(attrs.fill)) attrs.fill = "currentColor";
545
+ if (ownColor(attrs.stroke)) attrs.stroke = "currentColor";
546
+ }
547
+
548
+ /**
549
+ * Whether an icon's SVG paints with its own colours (W-238): any fill, stroke or stop other than
550
+ * `none`/`currentColor`, or a root without a fill (SVG's default is black). The panel offers
551
+ * Force single colour only then. Bundled Lucide icons follow the icon's colour already.
552
+ */
553
+ export function iconHasOwnColors(svg: string | undefined): boolean {
554
+ if (!svg) return false;
555
+ const picked = sanitizeSvgMarkup(svg);
556
+ if (!picked) return false;
557
+ if (picked.attrs.fill === undefined || PAINT_ATTRS.some((name) => ownColor(picked.attrs[name])))
558
+ return true;
559
+ const walk = (nodes: (VNode | string)[]): boolean =>
560
+ nodes.some(
561
+ (child) =>
562
+ typeof child !== "string" &&
563
+ (PAINT_ATTRS.some((name) => ownColor(child.attrs[name])) || walk(child.children)),
564
+ );
565
+ return walk(picked.children);
566
+ }
567
+
568
+ /** A picked icon's root attributes minus what the element sets itself (size, name, id). */
569
+ function pickedIconAttrs(attrs: Record<string, string>): Record<string, string> {
570
+ const kept: Record<string, string> = { xmlns: "http://www.w3.org/2000/svg" };
571
+ for (const [name, value] of Object.entries(attrs)) {
572
+ if (name === "width" || name === "height" || name === "id" || name === "role") continue;
573
+ if (name.startsWith("aria-") || name === "focusable") continue;
574
+ kept[name] = value;
575
+ }
576
+ if (!kept.viewBox) kept.viewBox = "0 0 24 24";
577
+ return kept;
578
+ }
579
+
420
580
  const video: ElementDefinition<VideoNode> = {
421
581
  baseCss:
422
- ".emvb-video{display:block;max-width:100%;border:0}.emvb-video iframe,.emvb-video video{display:block;width:100%;aspect-ratio:16/9;border:0;background:#000}.emvb-video-missing,.emvb-video-preview{display:flex;align-items:center;justify-content:center;min-height:120px;padding:12px;text-align:center;color:var(--text-color-kumo-subtle,#666);background:var(--color-kumo-tint,#eee)}",
582
+ // W-266: the iframe or <video> is the .emvb-video element itself, so the 16:9 size sits on it
583
+ // (the old descendant rule matched nothing: players were 300×150). :where() lets styles win.
584
+ ".emvb-video{display:block;max-width:100%;border:0}:where(.emvb-video){box-sizing:border-box;width:100%;aspect-ratio:16/9;background:#000}.emvb-video-missing,.emvb-video-preview{display:flex;align-items:center;justify-content:center;min-height:120px;padding:12px;text-align:center;color:var(--text-color-kumo-subtle,#666);background:var(--color-kumo-tint,#eee)}",
423
585
  defaults: () => ({
424
586
  type: "video",
425
587
  props: { url: "", title: "Video" },
@@ -486,7 +648,7 @@ const DEFAULT_SVG =
486
648
 
487
649
  const svgEl: ElementDefinition<SvgNode> = {
488
650
  baseCss:
489
- ".emvb-svg{display:inline-flex;align-items:center;justify-content:center;line-height:0;color:inherit}.emvb-svg svg{display:block;width:1em;height:1em}.emvb-svg-missing{min-width:1em;min-height:1em;background:var(--color-kumo-tint,#eee)}",
651
+ ".emvb-svg{display:inline-flex;align-items:center;justify-content:center;line-height:0;color:inherit}.emvb-svg svg{display:block}.emvb-svg-missing{min-width:1em;min-height:1em;background:var(--color-kumo-tint,#eee)}",
490
652
  defaults: () => ({
491
653
  type: "svg",
492
654
  props: { markup: DEFAULT_SVG, title: "SVG", decorative: false, size: 48 },
@@ -607,6 +769,57 @@ const divBlock: ElementDefinition<DivBlockNode> = {
607
769
  build: (_node, attrs, children) => ({ tag: "div", attrs, children }),
608
770
  };
609
771
 
772
+ /**
773
+ * A layout Section (W-156, D-045): a full-width band (background and padding on it) whose
774
+ * contents sit in a centred inner box at most the content width wide. The width is a custom
775
+ * property set by the renderer; each section resets it so a nested one doesn't inherit it.
776
+ */
777
+ const layoutSection: ElementDefinition<LayoutSectionNode> = {
778
+ baseCss:
779
+ ".emvb-layout-section{--emvb-content-width:1140px;display:block;min-width:0}.emvb-layout-section-inner{box-sizing:border-box;width:100%;max-width:var(--emvb-content-width);margin-inline:auto;min-width:0}",
780
+ defaults: () => ({
781
+ type: "layout-section",
782
+ props: {},
783
+ style: {
784
+ paddingTop: { value: 64, unit: "px" },
785
+ paddingRight: { value: 24, unit: "px" },
786
+ paddingBottom: { value: 64, unit: "px" },
787
+ paddingLeft: { value: 24, unit: "px" },
788
+ },
789
+ children: [],
790
+ }),
791
+ descriptor: {
792
+ type: "layout-section",
793
+ name: "Section",
794
+ group: "layout",
795
+ defaultTab: "content",
796
+ fields: [
797
+ {
798
+ key: "contentWidth",
799
+ kind: "number",
800
+ label: "Content width",
801
+ optional: true,
802
+ message: "Content width can't be negative. Leave it empty for 1140 px.",
803
+ },
804
+ { key: "fullWidth", kind: "boolean", label: "Full-width content", optional: true },
805
+ {
806
+ key: "tag",
807
+ kind: "select",
808
+ label: "HTML tag",
809
+ optional: true,
810
+ options: CONTAINER_TAGS.map((tag) => ({ value: tag, label: tag })),
811
+ message: "Pick a landmark or div. A section is a section by default.",
812
+ },
813
+ ],
814
+ },
815
+ build: (node, attrs, children) => {
816
+ const tag = node.props.tag ?? "section";
817
+ const safe = (CONTAINER_TAGS as readonly string[]).includes(tag) ? tag : "section";
818
+ const inner: VNode = { tag: "div", attrs: { class: "emvb-layout-section-inner" }, children };
819
+ return { tag: safe, attrs, children: [inner] };
820
+ },
821
+ };
822
+
610
823
  const grid: ElementDefinition<GridNode> = {
611
824
  baseCss: ".emvb-grid{display:grid;min-width:0}",
612
825
  defaults: () => ({ type: "grid", props: { columns: 3 }, children: [] }),
@@ -620,6 +833,7 @@ const grid: ElementDefinition<GridNode> = {
620
833
  key: "columns",
621
834
  kind: "select",
622
835
  label: "Columns",
836
+ devices: { tablet: "columnsTablet", mobile: "columnsMobile" },
623
837
  options: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map((n) => ({
624
838
  value: n,
625
839
  label: String(n),
@@ -691,6 +905,7 @@ const accordionItem: ElementDefinition<AccordionItemNode> = {
691
905
  export const ELEMENTS = {
692
906
  heading,
693
907
  container,
908
+ "layout-section": layoutSection,
694
909
  spacer,
695
910
  divider,
696
911
  text,
@@ -716,6 +931,7 @@ export const ELEMENTS = {
716
931
  "post-date": postDate,
717
932
  "post-author": postAuthor,
718
933
  loop,
934
+ pagination,
719
935
  section,
720
936
  "div-block": divBlock,
721
937
  flexbox,
@@ -725,6 +941,8 @@ export const ELEMENTS = {
725
941
  "tab-panel": tabPanel,
726
942
  accordion,
727
943
  "accordion-item": accordionItem,
944
+ menu,
945
+ "menu-item": menuItem,
728
946
  } as const;
729
947
 
730
948
  export type ElementType = keyof typeof ELEMENTS;