@perkyzz/emvb 1.3.0 → 1.4.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 (161) hide show
  1. package/README.md +2 -2
  2. package/package.json +2 -2
  3. package/src/admin/bulk-api.ts +5 -1
  4. package/src/admin/content-item.ts +3 -0
  5. package/src/admin/copy-rich-text.ts +99 -9
  6. package/src/admin/editor/A11yCopilot.tsx +3 -1
  7. package/src/admin/editor/Editor.tsx +28 -3
  8. package/src/admin/editor/Timeline.tsx +1 -8
  9. package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
  10. package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
  11. package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
  12. package/src/admin/editor/canvas/vnode-react.tsx +2 -0
  13. package/src/admin/editor/co-design.ts +36 -1
  14. package/src/admin/editor/collection-previews.ts +7 -8
  15. package/src/admin/editor/dnd/dragged-source.ts +22 -0
  16. package/src/admin/editor/dnd/layer-drop.ts +141 -0
  17. package/src/admin/editor/dnd/new-element.ts +16 -0
  18. package/src/admin/editor/editor-css.ts +9 -1
  19. package/src/admin/editor/element-chrome.ts +6 -0
  20. package/src/admin/editor/extensions/ExtensionPanels.tsx +33 -1
  21. package/src/admin/editor/extensions-context.tsx +16 -1
  22. package/src/admin/editor/feature-css.ts +27 -0
  23. package/src/admin/editor/inert-links.ts +8 -0
  24. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  25. package/src/admin/editor/panels/ConditionsEditor.tsx +18 -0
  26. package/src/admin/editor/panels/ElementPanel.tsx +2 -2
  27. package/src/admin/editor/panels/FontFaces.tsx +342 -0
  28. package/src/admin/editor/panels/LayersPanel.tsx +56 -6
  29. package/src/admin/editor/panels/LeftPanel.tsx +153 -29
  30. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  31. package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
  32. package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
  33. package/src/admin/editor/panels/TokenScales.tsx +2 -0
  34. package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
  35. package/src/admin/editor/panels/VariableSection.tsx +111 -7
  36. package/src/admin/editor/panels/color-space.ts +71 -6
  37. package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
  38. package/src/admin/editor/panels/settings/FieldControl.tsx +33 -0
  39. package/src/admin/editor/panels/settings/FormBindControl.tsx +27 -31
  40. package/src/admin/editor/panels/settings/ImageFieldControl.tsx +106 -0
  41. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
  42. package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
  43. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
  44. package/src/admin/editor/panels/settings/loop-context.ts +34 -3
  45. package/src/admin/editor/panels/settings/style-sections.ts +19 -2
  46. package/src/admin/editor/panels/url-rules.ts +43 -0
  47. package/src/admin/editor/panels/use-layers-drop.ts +232 -0
  48. package/src/admin/editor/store.ts +4 -2
  49. package/src/admin/editor/useExtensions.ts +3 -1
  50. package/src/admin/editor/useNodeActions.ts +74 -1
  51. package/src/admin/editor/useSave.ts +116 -85
  52. package/src/admin/export-api.ts +27 -2
  53. package/src/admin/extension-outputs.ts +236 -0
  54. package/src/admin/font-files-api.ts +38 -0
  55. package/src/admin/import-forms.ts +133 -0
  56. package/src/admin/pages/ImportButton.tsx +15 -4
  57. package/src/admin/pages/ImportElementorDialog.tsx +53 -187
  58. package/src/admin/pages/ImportForms.tsx +71 -0
  59. package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
  60. package/src/admin/pages/ImportImageCopies.tsx +167 -0
  61. package/src/admin/pages/ImportReport.tsx +63 -0
  62. package/src/admin/pages/NewPageDialog.tsx +54 -32
  63. package/src/admin/pages/PageList.tsx +9 -0
  64. package/src/admin/pages/ThemePartList.tsx +9 -0
  65. package/src/admin/setup/plan.ts +2 -0
  66. package/src/admin/ui.ts +7 -0
  67. package/src/admin/widgets/ConvertToRichText.tsx +3 -2
  68. package/src/astro/EmVBPage.astro +5 -2
  69. package/src/astro/extension-styles.ts +35 -0
  70. package/src/astro/forms/EmVBFormsClient.astro +3 -0
  71. package/src/astro/forms/enhance.ts +107 -0
  72. package/src/astro/popups/runtime.ts +47 -2
  73. package/src/astro/render.ts +25 -4
  74. package/src/astro/resolve-theme.ts +11 -4
  75. package/src/astro/resolve.ts +2 -0
  76. package/src/astro/theme-posts.ts +17 -23
  77. package/src/astro/visitor.ts +14 -5
  78. package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
  79. package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
  80. package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
  81. package/src/astro/widgets/alerts.ts +16 -2
  82. package/src/astro/widgets/carousel.ts +65 -24
  83. package/src/astro/widgets/countdown.ts +18 -7
  84. package/src/astro/widgets/extension-runtimes.ts +27 -0
  85. package/src/astro/widgets/headline.ts +14 -5
  86. package/src/astro/widgets/sticky.ts +87 -0
  87. package/src/astro/widgets/theme.ts +52 -0
  88. package/src/constants.ts +1 -1
  89. package/src/core/a11y/audit.ts +150 -2
  90. package/src/core/arrange.ts +19 -1
  91. package/src/core/css/font-face.ts +72 -0
  92. package/src/core/css/generate.ts +41 -2
  93. package/src/core/css/trace.ts +8 -0
  94. package/src/core/data/bindings.ts +7 -4
  95. package/src/core/elements/dynamic-elements.ts +1 -1
  96. package/src/core/elements/element-nouns.ts +48 -0
  97. package/src/core/elements/form-elements.ts +119 -9
  98. package/src/core/elements/icon-svg.ts +14 -0
  99. package/src/core/elements/index.ts +24 -4
  100. package/src/core/elements/input-limits.ts +44 -0
  101. package/src/core/elements/menu.ts +109 -47
  102. package/src/core/elements/site.ts +108 -0
  103. package/src/core/elements/widgets.ts +13 -3
  104. package/src/core/export/runtimes.generated.ts +7 -5
  105. package/src/core/export/site.ts +53 -4
  106. package/src/core/extensions/classes.ts +114 -0
  107. package/src/core/extensions/index.ts +19 -2
  108. package/src/core/extensions/normalize.ts +13 -0
  109. package/src/core/extensions/placeholder.ts +7 -2
  110. package/src/core/extensions/registry.ts +134 -10
  111. package/src/core/extensions/render-ext.ts +115 -36
  112. package/src/core/extensions/safe-nodes.ts +67 -11
  113. package/src/core/extensions/types.ts +48 -1
  114. package/src/core/fonts/files.ts +74 -0
  115. package/src/core/fonts/google.ts +112 -0
  116. package/src/core/fonts/test-font.ts +9 -0
  117. package/src/core/import/elementor/context.ts +42 -4
  118. package/src/core/import/elementor/index.ts +55 -23
  119. package/src/core/import/elementor/widgets.ts +242 -20
  120. package/src/core/import/html/blocks.ts +602 -0
  121. package/src/core/import/html/index.ts +155 -0
  122. package/src/core/import/html/map.ts +958 -0
  123. package/src/core/import/html/parse.ts +430 -0
  124. package/src/core/index.ts +54 -0
  125. package/src/core/migrate/v18.ts +3 -0
  126. package/src/core/public-attributes.ts +17 -0
  127. package/src/core/render/extras.ts +31 -7
  128. package/src/core/render/form.ts +103 -10
  129. package/src/core/render/index.ts +165 -16
  130. package/src/core/render/section.ts +31 -1
  131. package/src/core/render/spacer-basis.ts +102 -0
  132. package/src/core/render/theme-boot.ts +16 -0
  133. package/src/core/render/vnode.ts +1 -1
  134. package/src/core/sanitize/css.ts +68 -3
  135. package/src/core/sanitize/motion.ts +12 -0
  136. package/src/core/schema/design.ts +40 -0
  137. package/src/core/schema/layout.ts +118 -6
  138. package/src/core/schema/style.ts +28 -0
  139. package/src/core/templates/index.ts +218 -0
  140. package/src/core/templates/pages.ts +29 -0
  141. package/src/core/templates/sections.ts +794 -0
  142. package/src/core/templates/types.ts +9 -0
  143. package/src/core/theme/dynamic.ts +9 -6
  144. package/src/core/theme/media-value.ts +88 -0
  145. package/src/core/theme/popup-markup.ts +21 -2
  146. package/src/core/theme/popup-rules.ts +36 -0
  147. package/src/core/theme/triggers.ts +64 -5
  148. package/src/core/translatable.ts +5 -2
  149. package/src/core/visitor-cookie.ts +91 -0
  150. package/src/extension-build.ts +331 -0
  151. package/src/index.ts +53 -4
  152. package/src/mcp/agent-defaults.ts +40 -0
  153. package/src/mcp/brief.ts +191 -0
  154. package/src/mcp/extensions.ts +138 -0
  155. package/src/mcp/prompts.ts +33 -0
  156. package/src/mcp/read.ts +84 -20
  157. package/src/mcp/tools.ts +42 -3
  158. package/src/mcp/write.ts +124 -9
  159. package/src/server/extension-routes.ts +110 -0
  160. package/src/server/font-routes.ts +301 -0
  161. package/src/server/plugin.ts +15 -0
@@ -230,7 +230,7 @@ export const loop: ElementDefinition<LoopNode> = {
230
230
  label: "Image field",
231
231
  optional: true,
232
232
  message:
233
- "The field Post image shows, such as photo. Leave it empty for the featured image.",
233
+ "The field Post image shows, such as photo. Leave it empty for the featured image, or else the collection's first image field.",
234
234
  },
235
235
  {
236
236
  key: "excerptField",
@@ -0,0 +1,48 @@
1
+ import { ELEMENTS } from "./index.ts";
2
+
3
+ /** Words that keep their capitals in running text (acronyms, brands), as element names do. */
4
+ const KEEP = /^([A-Z0-9]{2,}s?|YouTube|Vimeo|Lottie|Markdown|Google|OpenStreetMap)$/;
5
+
6
+ /**
7
+ * W-1091 (#39): plurals English can't guess from the name. Names already plural ("Tabs",
8
+ * "Social icons") are one element each, so several of them are sets.
9
+ */
10
+ const PLURALS: Record<string, string> = {
11
+ "call to action": "calls to action",
12
+ "table of contents": "tables of contents",
13
+ tabs: "tab sets",
14
+ hotspots: "hotspot images",
15
+ "social icons": "social icon sets",
16
+ "share buttons": "share button sets",
17
+ };
18
+
19
+ /** "icon-box" → "icon box": the element's name in running text, or its type when it has none. */
20
+ export function elementNoun(type: string): string {
21
+ const name = (ELEMENTS as Record<string, { descriptor: { name: string } } | undefined>)[type]
22
+ ?.descriptor.name;
23
+ const words = (name ?? type.replaceAll(/[-_]+/g, " ")).trim().split(/\s+/);
24
+ return words.map((word) => (KEEP.test(word) ? word : word.toLowerCase())).join(" ");
25
+ }
26
+
27
+ /** English plural of the last word: box → boxes, gallery → galleries, SVG → SVGs. */
28
+ function pluralWord(word: string): string {
29
+ if (/^[A-Z0-9]{2,}$/.test(word)) return `${word}s`;
30
+ if (/(?:s|x|z|ch|sh)$/i.test(word)) return `${word}es`;
31
+ if (/[^aeiou]y$/i.test(word)) return `${word.slice(0, -1)}ies`;
32
+ return `${word}s`;
33
+ }
34
+
35
+ /** "icon boxes": several of an element type, by its name. */
36
+ export function elementPlural(type: string): string {
37
+ const noun = elementNoun(type);
38
+ const irregular = PLURALS[noun];
39
+ if (irregular) return irregular;
40
+ const words = noun.split(" ");
41
+ const last = words.pop() ?? noun;
42
+ return [...words, pluralWord(last)].join(" ");
43
+ }
44
+
45
+ /** "icon box" for one, "12 icon boxes" for more. */
46
+ export function elementCount(type: string, n: number): string {
47
+ return n === 1 ? elementNoun(type) : `${n} ${elementPlural(type)}`;
48
+ }
@@ -1,14 +1,17 @@
1
1
  import { selectPrompt } from "./select-prompt.ts";
2
2
  import { controlId } from "./field-id.ts";
3
+ import { typedInputAttrs } from "./input-limits.ts";
3
4
  import type {
4
5
  CheckboxNode,
5
6
  FormNode,
7
+ FormStepNode,
6
8
  RadioNode,
7
9
  SelectNode,
8
10
  SubmitNode,
9
11
  TextInputNode,
10
12
  TextareaNode,
11
13
  } from "../schema/layout.ts";
14
+ import { MAX_INPUT_NUMBER } from "../schema/layout.ts";
12
15
  import type { VNode } from "../render/vnode.ts";
13
16
  import type { ElementDescriptor } from "../schema/descriptors.ts";
14
17
  import type { ElementDefinition } from "./definition.ts";
@@ -57,6 +60,20 @@ export const form: ElementDefinition<FormNode> = {
57
60
  defaults: () => ({ type: "form", props: { formId: "" }, children: [] }),
58
61
  descriptor: fieldDescriptor("form", "Form", [
59
62
  { key: "formId", kind: "text", label: "Form id", message: "Paste a forms-plugin form id." },
63
+ {
64
+ key: "nextLabel",
65
+ kind: "text",
66
+ label: "Next button",
67
+ optional: true,
68
+ message: 'For a form with steps. Leave it empty for "Next".',
69
+ },
70
+ {
71
+ key: "prevLabel",
72
+ kind: "text",
73
+ label: "Previous button",
74
+ optional: true,
75
+ message: 'For a form with steps. Leave it empty for "Previous".',
76
+ },
60
77
  ]),
61
78
  build: (_node, attrs, children) => ({
62
79
  tag: "form",
@@ -65,6 +82,44 @@ export const form: ElementDefinition<FormNode> = {
65
82
  }),
66
83
  };
67
84
 
85
+ /**
86
+ * W-1065: a form step. The form renders it as a page of the forms plugin's multi-page markup
87
+ * (`data-page`, render/form.ts); on its own it is a fieldset named by its title.
88
+ */
89
+ export const formStep: ElementDefinition<FormStepNode> = {
90
+ baseCss:
91
+ ".emvb-form-step{display:flex;flex-direction:column;gap:12px;min-width:0;margin:0;padding:0;border:0}.emvb-form-step[hidden]{display:none!important}.emvb-form-step:focus{outline:none}" +
92
+ ":where(.emvb-form-step-title){float:left;width:100%;margin:0 0 4px;padding:0;font-weight:700;font-size:1.125em}" +
93
+ ".emvb-form-step-nav{display:flex;flex-wrap:wrap;gap:8px}.emvb-form-step-nav [hidden],.emvb-form .ec-form-submit[hidden]{display:none!important}" +
94
+ ":where(.emvb-form-step-nav button){padding:.5em 1em;font:inherit;color:inherit;background:transparent;border:1px solid currentColor;border-radius:6px;cursor:pointer}" +
95
+ ":where(.emvb-form-step-nav button:focus-visible){outline:2px solid currentColor;outline-offset:2px}" +
96
+ ".emvb-form-step-progress{margin:0}.emvb-form-step-progress:empty{display:none}" +
97
+ "@media (prefers-reduced-motion:no-preference){.emvb-form-step[data-page]:not([hidden]){animation:emvb-form-step-in .2s ease-out}}@keyframes emvb-form-step-in{from{opacity:0;transform:translateY(6px)}}",
98
+ defaults: () => ({ type: "form-step", props: { title: "Step" }, children: [] }),
99
+ descriptor: fieldDescriptor("form-step", "Form step", [
100
+ {
101
+ key: "title",
102
+ kind: "text",
103
+ label: "Title",
104
+ optional: true,
105
+ message: 'Read out when the step opens. Leave it empty for "Step 2".',
106
+ },
107
+ ]),
108
+ build: (node, attrs, children) => {
109
+ const title = node.props.title?.trim();
110
+ return {
111
+ tag: "fieldset",
112
+ attrs,
113
+ children: [
114
+ ...(title
115
+ ? [{ tag: "legend", attrs: { class: "emvb-form-step-title" }, children: [title] }]
116
+ : []),
117
+ ...children,
118
+ ],
119
+ };
120
+ },
121
+ };
122
+
68
123
  /** Where the forms runtime writes a field's validation message. */
69
124
  const errorSlot = (name: string, controlFor: string): VNode => ({
70
125
  tag: "span",
@@ -146,15 +201,70 @@ const textControl = (
146
201
  export const textInput: ElementDefinition<TextInputNode> = {
147
202
  baseCss: ".emvb-text-input{display:flex;flex-direction:column;gap:4px}",
148
203
  defaults: () => ({ type: "text-input", props: { field: "name", label: "Name" } }),
149
- descriptor: fieldDescriptor("text-input", "Text input", TEXT_FIELDS),
150
- build: (node, attrs) =>
151
- fieldWrap(
152
- controlId(node.id),
153
- node.props.field,
154
- node.props.label,
155
- textControl("input", node.props, controlId(node.id)),
156
- attrs,
157
- ),
204
+ descriptor: fieldDescriptor("text-input", "Text input", [
205
+ ...TEXT_FIELDS,
206
+ {
207
+ key: "inputType",
208
+ kind: "select",
209
+ label: "Asks for",
210
+ optional: true,
211
+ options: [
212
+ { value: "number", label: "A number" },
213
+ { value: "date", label: "A date" },
214
+ ],
215
+ message: "Unset: text. A form field that is an email, number or date keeps its own type.",
216
+ },
217
+ {
218
+ key: "min",
219
+ kind: "decimal",
220
+ label: "Lowest number",
221
+ optional: true,
222
+ min: -MAX_INPUT_NUMBER,
223
+ max: MAX_INPUT_NUMBER,
224
+ },
225
+ {
226
+ key: "max",
227
+ kind: "decimal",
228
+ label: "Highest number",
229
+ optional: true,
230
+ min: -MAX_INPUT_NUMBER,
231
+ max: MAX_INPUT_NUMBER,
232
+ },
233
+ {
234
+ key: "step",
235
+ kind: "decimal",
236
+ label: "Step",
237
+ optional: true,
238
+ min: 0.000001,
239
+ max: MAX_INPUT_NUMBER,
240
+ message: "Allowed numbers go up by this much, such as 1 or 0.5. Leave it empty for any.",
241
+ },
242
+ {
243
+ key: "minDate",
244
+ kind: "text",
245
+ label: "Earliest date",
246
+ optional: true,
247
+ message: "As YYYY-MM-DD, such as 2026-01-31.",
248
+ },
249
+ {
250
+ key: "maxDate",
251
+ kind: "text",
252
+ label: "Latest date",
253
+ optional: true,
254
+ message: "As YYYY-MM-DD, such as 2026-12-31.",
255
+ },
256
+ ]),
257
+ build: (node, attrs) => {
258
+ const control = textControl("input", node.props, controlId(node.id));
259
+ const type = node.props.inputType;
260
+ const typed: VNode = type
261
+ ? {
262
+ ...control,
263
+ attrs: { ...control.attrs, type, ...typedInputAttrs(type, node.props) },
264
+ }
265
+ : control;
266
+ return fieldWrap(controlId(node.id), node.props.field, node.props.label, typed, attrs);
267
+ },
158
268
  };
159
269
 
160
270
  export const textareaEl: ElementDefinition<TextareaNode> = {
@@ -92,6 +92,18 @@ function pickedIconAttrs(attrs: Record<string, string>): Record<string, string>
92
92
  * W-1020: an icon's `<svg>` at `size` px with `aria` (its name, or `aria-hidden`), or undefined
93
93
  * when the id is unknown and no SVG is stored.
94
94
  */
95
+ /**
96
+ * W-1079: an icon that points along the reading direction (an arrow, chevron, caret or angle to
97
+ * the left or right). On a right-to-left page it is mirrored, so "next" still points forward.
98
+ */
99
+ export function isDirectionalIcon(iconId: string): boolean {
100
+ const name = (iconId.split(":").pop() ?? "").toLowerCase();
101
+ return (
102
+ /(^|[-_])(arrows?|chevrons?|carets?|angles?|triangle)([-_]|$)/.test(name) &&
103
+ /(^|[-_])(left|right)([-_]|$)/.test(name)
104
+ );
105
+ }
106
+
95
107
  export function iconGlyph(
96
108
  props: { iconId: string; iconSvg?: string | undefined; singleColor?: boolean | undefined },
97
109
  size: number,
@@ -129,6 +141,8 @@ export function iconGlyph(
129
141
  children: [],
130
142
  }));
131
143
  strokeClass(svgAttrs);
144
+ if (isDirectionalIcon(props.iconId))
145
+ svgAttrs.class = svgAttrs.class ? `${svgAttrs.class} emvb-icon-dir` : "emvb-icon-dir";
132
146
  const single = picked !== undefined && props.singleColor === true;
133
147
  if (single) monochromeRoot(svgAttrs);
134
148
  return { tag: "svg", attrs: svgAttrs, children: single ? monochrome(children) : children };
@@ -36,9 +36,10 @@ import { resolveEmbedUrl } from "../sanitize/embed-url.ts";
36
36
  import type { VNode } from "../render/vnode.ts";
37
37
 
38
38
  import type { ElementDefinition } from "./definition.ts";
39
- import { ICON_STROKE_WIDTHS, iconGlyph } from "./icon-svg.ts";
39
+ import { ICON_STROKE_WIDTHS, iconGlyph, isDirectionalIcon } from "./icon-svg.ts";
40
40
  export { iconHasAdjustableStroke, iconHasOwnColors } from "./icon-svg.ts";
41
41
  import { menu, menuItem } from "./menu.ts";
42
+ import { searchForm, themeToggle } from "./site.ts";
42
43
  import {
43
44
  countdown,
44
45
  counter,
@@ -68,7 +69,16 @@ import {
68
69
  socialLink,
69
70
  testimonial,
70
71
  } from "./widgets.ts";
71
- import { checkbox, form, radio, selectEl, submit, textInput, textareaEl } from "./form-elements.ts";
72
+ import {
73
+ checkbox,
74
+ form,
75
+ formStep,
76
+ radio,
77
+ selectEl,
78
+ submit,
79
+ textInput,
80
+ textareaEl,
81
+ } from "./form-elements.ts";
72
82
  import {
73
83
  loop,
74
84
  loopEmpty,
@@ -316,7 +326,7 @@ const link: ElementDefinition<LinkNode> = {
316
326
  const button: ElementDefinition<ButtonNode> = {
317
327
  baseCss:
318
328
  // The look sits in :where() so site tag defaults, classes and local styles all win (W-148).
319
- ".emvb-button{display:inline-flex;align-items:center;justify-content:center;gap:0.5em;overflow-wrap:anywhere;text-align: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}.emvb-button-icon{display:inline-flex;flex:none}.emvb-button-icon svg{width:100%;height:100%;display:block}.emvb-button-icon--sm{width:1em;height:1em}.emvb-button-icon--md{width:1.25em;height:1.25em}.emvb-button-icon--lg{width:1.5em;height:1.5em}",
329
+ ".emvb-button{display:inline-flex;align-items:center;justify-content:center;gap:0.5em;overflow-wrap:anywhere;text-align: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}.emvb-button-icon{display:inline-flex;flex:none}.emvb-button-icon svg{width:100%;height:100%;display:block}.emvb-button-icon--sm{width:1em;height:1em}.emvb-button-icon--md{width:1.25em;height:1.25em}.emvb-button-icon--lg{width:1.5em;height:1.5em}.emvb-icon-dir:dir(rtl){transform:scaleX(-1)}",
320
330
  defaults: () => ({ type: "button", props: { text: "Button" } }),
321
331
  descriptor: {
322
332
  type: "button",
@@ -404,6 +414,10 @@ function buttonChildren(node: ButtonNode): (VNode | string)[] {
404
414
  children: [],
405
415
  })),
406
416
  };
417
+ // W-1079: an arrow points forward on a right-to-left page too, as on an Icon.
418
+ if (node.props.iconId && isDirectionalIcon(node.props.iconId)) {
419
+ svg.attrs.class = svg.attrs.class ? `${svg.attrs.class} emvb-icon-dir` : "emvb-icon-dir";
420
+ }
407
421
  const size = node.props.iconSize ?? "md";
408
422
  const icon: VNode = {
409
423
  tag: "span",
@@ -644,12 +658,15 @@ const icon: ElementDefinition<IconNode> = {
644
658
  // W-237: the glyph reads the wrapper's icon custom properties (rotate, flip, shadow, loop,
645
659
  // stroke); unset they change nothing. The svg inherits the wrapper's transition for hover.
646
660
  // W-803: an icon larger than its box (512 px on a phone) shrinks to fit, keeping its shape.
661
+ // W-1079: the right-to-left mirror is a transform, and the spin and pulse keyframes set
662
+ // transform too; `add` composes them onto the mirror instead of dropping it while animating
663
+ // (`scale` already holds the Flip setting, so the mirror can't go there).
647
664
  ".emvb-icon{display:inline-flex;align-items:center;justify-content:center;line-height:0;color:inherit}.emvb-icon-link{display:inline-flex;max-width:100%;color:inherit}.emvb-icon svg{display:block;max-width:100%;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}" +
648
665
  ICON_STROKE_WIDTHS.map(
649
666
  (width) =>
650
667
  `.emvb-icon-sw${width.replace(".", "_")}{stroke-width:var(--emvb-icon-stroke,${width})}`,
651
668
  ).join("") +
652
- "@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)}",
669
+ "@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-dir:dir(rtl){transform:scaleX(-1)}.emvb-icon svg.emvb-icon-dir{animation-composition:add}.emvb-icon-missing{min-width:1em;min-height:1em;background:var(--color-kumo-tint,#eee)}",
653
670
  defaults: () => ({
654
671
  type: "icon",
655
672
  props: { iconId: "star", title: "Star", decorative: false, size: 24 },
@@ -1154,6 +1171,8 @@ export const ELEMENTS = {
1154
1171
  "share-link": shareLink,
1155
1172
  hotspots,
1156
1173
  hotspot,
1174
+ "search-form": searchForm,
1175
+ "theme-toggle": themeToggle,
1157
1176
  container,
1158
1177
  "layout-section": layoutSection,
1159
1178
  spacer,
@@ -1167,6 +1186,7 @@ export const ELEMENTS = {
1167
1186
  icon,
1168
1187
  video,
1169
1188
  form,
1189
+ "form-step": formStep,
1170
1190
  "text-input": textInput,
1171
1191
  textarea: textareaEl,
1172
1192
  select: selectEl,
@@ -0,0 +1,44 @@
1
+ import { MAX_INPUT_NUMBER, type TextInputNode } from "../schema/layout.ts";
2
+
3
+ /** A finite number inside the schema's bounds, as an attribute value; anything else is dropped. */
4
+ const numberAttr = (value: unknown): string | undefined =>
5
+ typeof value === "number" && Number.isFinite(value) && Math.abs(value) <= MAX_INPUT_NUMBER
6
+ ? String(value)
7
+ : undefined;
8
+
9
+ const DATE = /^[1-9]\d{3}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/;
10
+ const dateAttr = (value: unknown): string | undefined =>
11
+ typeof value === "string" && DATE.test(value) ? value : undefined;
12
+
13
+ /** Both ends of a range, unless the lowest is above the highest: no answer could pass then. */
14
+ function range(lo: string | undefined, hi: string | undefined, above: boolean) {
15
+ if (lo !== undefined && hi !== undefined && above) return {};
16
+ return { ...(lo === undefined ? {} : { min: lo }), ...(hi === undefined ? {} : { max: hi }) };
17
+ }
18
+
19
+ /**
20
+ * W-1065: the type and limits of a Text input that asks for a number or a date. Every value is
21
+ * untrusted: a limit that isn't a finite number (or a YYYY-MM-DD date) is left off, and so is a
22
+ * range with nothing in it. Without a step a number takes decimals (W-578).
23
+ */
24
+ export function typedInputAttrs(
25
+ type: "number" | "date",
26
+ props: TextInputNode["props"],
27
+ defined: { min?: unknown; max?: unknown } = {},
28
+ ): Record<string, string> {
29
+ if (type === "date") {
30
+ const lo = dateAttr(props.minDate);
31
+ const hi = dateAttr(props.maxDate);
32
+ return range(lo, hi, lo !== undefined && hi !== undefined && lo > hi);
33
+ }
34
+ // The form field's own limits are the ones the forms plugin checks; they win.
35
+ const loValue = numberAttr(defined.min) !== undefined ? defined.min : props.min;
36
+ const hiValue = numberAttr(defined.max) !== undefined ? defined.max : props.max;
37
+ const lo = numberAttr(loValue);
38
+ const hi = numberAttr(hiValue);
39
+ const step = numberAttr(props.step);
40
+ return {
41
+ ...range(lo, hi, Number(lo) > Number(hi)),
42
+ step: step !== undefined && Number(step) > 0 ? step : "any",
43
+ };
44
+ }
@@ -1,8 +1,15 @@
1
- import type { MenuItemNode, MenuNode } from "../schema/layout.ts";
1
+ import type { LayoutNode, MenuItemNode, MenuNode } from "../schema/layout.ts";
2
2
  import { sanitizeHref } from "../sanitize/href.ts";
3
3
  import type { VNode } from "../render/vnode.ts";
4
4
  import type { ElementDefinition } from "./definition.ts";
5
5
 
6
+ /** W-1069: the Section part a mega menu item shows, trimmed; "" for anything else. */
7
+ export function megaPanelPartId(node: LayoutNode): string {
8
+ if (node.type !== "menu-item") return "";
9
+ const value = (node.props as { panelPartId?: unknown }).panelPartId;
10
+ return typeof value === "string" ? value.trim() : "";
11
+ }
12
+
6
13
  const newTabAttrs = (newTab: boolean | undefined): Record<string, string> =>
7
14
  newTab ? { target: "_blank", rel: "noopener noreferrer" } : {};
8
15
 
@@ -91,6 +98,27 @@ const MENU_CSS = [
91
98
  "@media (max-width: 767.98px){.emvb-menu--column .emvb-menu-panel,.emvb-menu--column .emvb-menu-panel--wide{top:100%;inset-inline:auto;inset-inline-start:0;min-width:min(12rem,calc(100vw - 2rem));max-width:calc(100vw - 2rem)}}",
92
99
  ].join("");
93
100
 
101
+ /**
102
+ * W-1069: mega panels. Sent only with a page that renders one (base type `menu-mega`), so pages
103
+ * without one keep their CSS byte for byte. `--emvb-menu-panel-width` is the item's Mega panel
104
+ * width. On phones the panel stacks inline under its item, as part of the menu, instead of
105
+ * floating over the page.
106
+ */
107
+ export const MEGA_MENU_CSS = [
108
+ ".emvb-menu-panel--mega{width:var(--emvb-menu-panel-width,max-content);max-width:calc(100vw - 2rem);padding:1rem}",
109
+ ".emvb-menu-panel--mega.emvb-menu-panel--wide{width:auto;max-width:var(--emvb-menu-panel-width,none);margin-inline:auto}",
110
+ ".emvb-menu--column .emvb-menu-panel--mega.emvb-menu-panel--wide{inset-inline-end:auto;width:var(--emvb-menu-panel-width,max-content);max-width:calc(100vw - 2rem)}",
111
+ "@media (max-width: 767.98px){" +
112
+ ".emvb-menu .emvb-menu-item--mega{position:relative}" +
113
+ ".emvb-menu .emvb-menu-item--mega:has(>.emvb-menu-item__bar>.emvb-menu-item__disclosure[open]){flex-basis:100%}" +
114
+ ".emvb-menu .emvb-menu-item--mega>.emvb-menu-item__bar{position:relative;flex-wrap:wrap;row-gap:0;width:auto;min-height:1.75rem}" +
115
+ ".emvb-menu .emvb-menu-item--mega>.emvb-menu-item__bar>.emvb-menu-item__disclosure{flex:1 1 100%}" +
116
+ ".emvb-menu .emvb-menu-item--mega>.emvb-menu-item__bar>.emvb-menu-item__link{padding-inline-end:2rem}" +
117
+ ".emvb-menu .emvb-menu-item--mega>.emvb-menu-item__bar>.emvb-menu-item__link+.emvb-menu-item__disclosure>.emvb-menu-item__toggle{position:absolute;top:0;inset-inline-end:0}" +
118
+ ".emvb-menu .emvb-menu-item--mega .emvb-menu-panel--mega{position:static;width:auto;min-width:0;max-width:none;margin:0;padding:.5rem 0 .75rem;border:0;box-shadow:none;background:none;color:inherit}" +
119
+ "}",
120
+ ].join("");
121
+
94
122
  export const menu: ElementDefinition<MenuNode> = {
95
123
  baseCss: MENU_CSS,
96
124
  defaults: () => ({ type: "menu", props: { direction: "row" }, children: [] }),
@@ -160,52 +188,86 @@ export const menuItem: ElementDefinition<MenuItemNode> = {
160
188
  },
161
189
  { key: "newTab", kind: "boolean", label: "Open in a new tab", optional: true },
162
190
  { key: "wide", kind: "boolean", label: "Wide panel", optional: true },
191
+ {
192
+ key: "panelPartId",
193
+ kind: "text",
194
+ label: "Mega panel",
195
+ optional: true,
196
+ message:
197
+ "Optional published Section theme part. Its layout fills this item's panel in place of the items under it.",
198
+ },
199
+ {
200
+ key: "panelWidth",
201
+ kind: "number",
202
+ label: "Mega panel width",
203
+ optional: true,
204
+ message: "Panel width can't be negative. Leave it empty to fit the panel's content.",
205
+ },
163
206
  ],
164
207
  },
165
- build: (node, attrs, children) => {
166
- const wide = node.props.wide === true;
167
- const classes = [attrs.class, wide ? "emvb-menu-item--wide" : ""].filter(Boolean).join(" ");
168
- const href = node.props.href?.trim() ? sanitizeHref(node.props.href) : undefined;
169
- const label: VNode = href
170
- ? {
171
- tag: "a",
172
- attrs: { class: "emvb-menu-item__link", href, ...newTabAttrs(node.props.newTab) },
173
- children: [node.props.text],
174
- }
175
- : { tag: "span", attrs: { class: "emvb-menu-item__label" }, children: [node.props.text] };
176
- // W-614: with no link, the item's text is the dropdown's toggle, so tapping "Shop" opens it
177
- // (the chevron alone was a 28 px target, and the text did nothing on touch screens).
178
- const textToggle = !href && children.length > 0;
179
- const bar: VNode["children"] = textToggle ? [] : [label];
180
- if (children.length > 0) {
181
- const panelClass = wide ? "emvb-menu-panel emvb-menu-panel--wide" : "emvb-menu-panel";
182
- bar.push({
183
- tag: "details",
184
- attrs: { class: "emvb-menu-item__disclosure" },
185
- children: [
186
- textToggle
187
- ? {
188
- tag: "summary",
189
- attrs: { class: "emvb-menu-item__toggle emvb-menu-item__toggle--label" },
190
- children: [node.props.text],
191
- }
192
- : {
193
- tag: "summary",
194
- attrs: { class: "emvb-menu-item__toggle", "aria-label": `Open ${node.props.text}` },
195
- children: [],
196
- },
197
- {
198
- tag: "div",
199
- attrs: { class: panelClass },
200
- children: groupItems(stampGroup(children, `emvb-menu-${node.id}`)),
201
- },
202
- ],
203
- });
204
- }
205
- return {
206
- tag: "li",
207
- attrs: { ...attrs, class: classes },
208
- children: [{ tag: "div", attrs: { class: "emvb-menu-item__bar" }, children: bar }],
209
- };
210
- },
208
+ build: (node, attrs, children) => buildMenuItem(node, attrs, children),
211
209
  };
210
+
211
+ /**
212
+ * A menu item's markup. W-1069: with `mega` (its Section part's rendered elements), the panel
213
+ * holds those instead of the children, in the same `<details>`, so it opens by click, tap,
214
+ * keyboard and hover like any dropdown, without a script.
215
+ */
216
+ export function buildMenuItem(
217
+ node: MenuItemNode,
218
+ attrs: Record<string, string>,
219
+ children: VNode[],
220
+ mega?: VNode[],
221
+ ): VNode {
222
+ const wide = node.props.wide === true;
223
+ const classes = [
224
+ attrs.class,
225
+ wide ? "emvb-menu-item--wide" : "",
226
+ mega ? "emvb-menu-item--mega" : "",
227
+ ]
228
+ .filter(Boolean)
229
+ .join(" ");
230
+ const href = node.props.href?.trim() ? sanitizeHref(node.props.href) : undefined;
231
+ const label: VNode = href
232
+ ? {
233
+ tag: "a",
234
+ attrs: { class: "emvb-menu-item__link", href, ...newTabAttrs(node.props.newTab) },
235
+ children: [node.props.text],
236
+ }
237
+ : { tag: "span", attrs: { class: "emvb-menu-item__label" }, children: [node.props.text] };
238
+ const panelChildren = mega ?? children;
239
+ // W-614: with no link, the item's text is the dropdown's toggle, so tapping "Shop" opens it
240
+ // (the chevron alone was a 28 px target, and the text did nothing on touch screens).
241
+ const textToggle = !href && panelChildren.length > 0;
242
+ const bar: VNode["children"] = textToggle ? [] : [label];
243
+ if (panelChildren.length > 0) {
244
+ const panelClass = wide ? "emvb-menu-panel emvb-menu-panel--wide" : "emvb-menu-panel";
245
+ bar.push({
246
+ tag: "details",
247
+ attrs: { class: "emvb-menu-item__disclosure" },
248
+ children: [
249
+ textToggle
250
+ ? {
251
+ tag: "summary",
252
+ attrs: { class: "emvb-menu-item__toggle emvb-menu-item__toggle--label" },
253
+ children: [node.props.text],
254
+ }
255
+ : {
256
+ tag: "summary",
257
+ attrs: { class: "emvb-menu-item__toggle", "aria-label": `Open ${node.props.text}` },
258
+ children: [],
259
+ },
260
+ {
261
+ tag: "div",
262
+ attrs: { class: mega ? `${panelClass} emvb-menu-panel--mega` : panelClass },
263
+ children: mega ?? groupItems(stampGroup(children, `emvb-menu-${node.id}`)),
264
+ },
265
+ ],
266
+ });
267
+ }
268
+ return {
269
+ tag: "li",
270
+ attrs: { ...attrs, class: classes },
271
+ children: [{ tag: "div", attrs: { class: "emvb-menu-item__bar" }, children: bar }],
272
+ };
273
+ }
@@ -0,0 +1,108 @@
1
+ import type { SearchFormNode, ThemeToggleNode } from "../schema/layout.ts";
2
+ import { sanitizeHref } from "../sanitize/href.ts";
3
+ import type { ElementDefinition } from "./definition.ts";
4
+
5
+ /**
6
+ * W-1073: where a Search form sends the words: a site path or a web address; anything else
7
+ * (another scheme, a refused link) falls back to EmDash's own search page.
8
+ */
9
+ export function searchAction(action: string | undefined): string {
10
+ const safe = action?.trim() ? sanitizeHref(action.trim()) : undefined;
11
+ return safe && !/^(mailto|tel):/i.test(safe) ? safe : "/search";
12
+ }
13
+
14
+ export const searchForm: ElementDefinition<SearchFormNode> = {
15
+ baseCss:
16
+ ".emvb-search-form{display:flex;align-items:stretch;gap:0.5em;max-width:100%}.emvb-search-input{flex:1 1 12em;min-width:0;padding:0.5em 0.75em;border:1px solid currentColor;border-radius:4px;background:transparent;color:inherit;font:inherit}.emvb-search-button{padding:0.5em 1em;border:1px solid currentColor;border-radius:4px;background:none;color:inherit;font:inherit;cursor:pointer}.emvb-search-input:focus-visible,.emvb-search-button:focus-visible{outline:2px solid currentColor;outline-offset:2px}",
17
+ defaults: () => ({ type: "search-form", props: { placeholder: "Search this site" } }),
18
+ descriptor: {
19
+ type: "search-form",
20
+ name: "Search form",
21
+ group: "content",
22
+ defaultTab: "content",
23
+ fields: [
24
+ {
25
+ key: "label",
26
+ kind: "text",
27
+ label: "Name for screen readers",
28
+ optional: true,
29
+ message: "Leave it empty for Search.",
30
+ },
31
+ { key: "placeholder", kind: "text", label: "Placeholder", optional: true },
32
+ { key: "buttonText", kind: "text", label: "Button text", optional: true },
33
+ {
34
+ key: "action",
35
+ kind: "text",
36
+ label: "Search page",
37
+ optional: true,
38
+ message:
39
+ "The page the words are sent to, as ?q=…. Anything after a ? here is dropped by the browser. Leave it empty for /search.",
40
+ },
41
+ ],
42
+ },
43
+ build: (node, attrs) => {
44
+ const label = node.props.label?.trim() || "Search";
45
+ const placeholder = node.props.placeholder?.trim();
46
+ return {
47
+ tag: "form",
48
+ attrs: {
49
+ ...attrs,
50
+ role: "search",
51
+ "aria-label": label,
52
+ method: "get",
53
+ action: searchAction(node.props.action),
54
+ },
55
+ children: [
56
+ {
57
+ tag: "input",
58
+ attrs: {
59
+ class: "emvb-search-input",
60
+ type: "search",
61
+ name: "q",
62
+ "aria-label": label,
63
+ ...(placeholder ? { placeholder } : {}),
64
+ },
65
+ children: [],
66
+ },
67
+ {
68
+ tag: "button",
69
+ attrs: { class: "emvb-search-button", type: "submit" },
70
+ children: [node.props.buttonText?.trim() || "Search"],
71
+ },
72
+ ],
73
+ };
74
+ },
75
+ };
76
+
77
+ export const themeToggle: ElementDefinition<ThemeToggleNode> = {
78
+ baseCss:
79
+ ".emvb-theme-toggle{display:inline-flex;align-items:center;gap:0.5em;padding:0.4em 0.9em;border:1px solid currentColor;border-radius:999px;background:none;color:inherit;font:inherit;cursor:pointer}.emvb-theme-toggle:not([data-emvb-ready]){display:none}.emvb-theme-toggle:focus-visible{outline:2px solid currentColor;outline-offset:2px}",
80
+ defaults: () => ({ type: "theme-toggle", props: {} }),
81
+ descriptor: {
82
+ type: "theme-toggle",
83
+ name: "Theme toggle",
84
+ group: "content",
85
+ defaultTab: "content",
86
+ fields: [
87
+ {
88
+ key: "label",
89
+ kind: "text",
90
+ label: "Text",
91
+ optional: true,
92
+ message:
93
+ "Leave it empty for Dark mode. Give colour variables a Dark mode value in Site styles.",
94
+ },
95
+ ],
96
+ },
97
+ build: (node, attrs) => ({
98
+ tag: "button",
99
+ attrs: {
100
+ ...attrs,
101
+ type: "button",
102
+ "aria-pressed": "false",
103
+ // The theme script marks it ready and so shows it: without the script, no dead button.
104
+ "data-emvb-theme-toggle": "",
105
+ },
106
+ children: [node.props.label?.trim() || "Dark mode"],
107
+ }),
108
+ };