@perkyzz/emvb 1.1.0 → 1.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 (83) hide show
  1. package/THIRD_PARTY_NOTICES.md +1 -0
  2. package/package.json +10 -9
  3. package/src/admin/agents-api.ts +5 -1
  4. package/src/admin/content-api.ts +29 -0
  5. package/src/admin/editor/Editor.tsx +6 -1
  6. package/src/admin/editor/ScheduleDialog.tsx +167 -0
  7. package/src/admin/editor/TopBar.tsx +33 -1
  8. package/src/admin/editor/dnd/new-element.ts +46 -0
  9. package/src/admin/editor/editor-chrome.tsx +9 -0
  10. package/src/admin/editor/element-chrome.ts +22 -0
  11. package/src/admin/editor/panels/ElementPanel.tsx +5 -1
  12. package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
  13. package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
  14. package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
  15. package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
  16. package/src/admin/editor/panels/settings/ItemList.tsx +36 -2
  17. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  18. package/src/admin/editor/store.ts +7 -1
  19. package/src/admin/editor/useEditorData.ts +4 -0
  20. package/src/admin/editor/useSave.ts +47 -3
  21. package/src/admin/export-api.ts +20 -3
  22. package/src/admin/menus-api.ts +113 -0
  23. package/src/admin/pages/ImportElementorDialog.tsx +25 -1
  24. package/src/astro/EmVBPage.astro +3 -0
  25. package/src/astro/render.ts +43 -18
  26. package/src/astro/request-data.ts +3 -0
  27. package/src/astro/resolve-theme.ts +77 -44
  28. package/src/astro/visitor.ts +23 -4
  29. package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
  30. package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -0
  31. package/src/astro/widgets/EmVBLightboxRuntime.astro +8 -0
  32. package/src/astro/widgets/EmVBWidgetRuntimes.astro +19 -0
  33. package/src/astro/widgets/alerts.ts +37 -0
  34. package/src/astro/widgets/carousel.ts +167 -0
  35. package/src/astro/widgets/index.ts +1 -0
  36. package/src/astro/widgets/lightbox.ts +123 -0
  37. package/src/constants.ts +1 -1
  38. package/src/core/a11y/audit.ts +101 -2
  39. package/src/core/arrange.ts +57 -1
  40. package/src/core/bounded-array.ts +16 -13
  41. package/src/core/contract.ts +4 -1
  42. package/src/core/elements/icon-svg.ts +135 -0
  43. package/src/core/elements/index.ts +33 -127
  44. package/src/core/elements/widgets.ts +907 -0
  45. package/src/core/export/runtimes.generated.ts +3 -0
  46. package/src/core/export/site.ts +20 -3
  47. package/src/core/extensions/schema.ts +2 -1
  48. package/src/core/geo-trust.ts +18 -0
  49. package/src/core/icons/social.generated.ts +29 -0
  50. package/src/core/image-edit/schema.ts +2 -1
  51. package/src/core/import/elementor/context.ts +18 -0
  52. package/src/core/import/elementor/index.ts +50 -7
  53. package/src/core/import/elementor/widgets.ts +394 -133
  54. package/src/core/issue-cap.ts +19 -0
  55. package/src/core/limits.ts +6 -0
  56. package/src/core/loop-collections.ts +33 -0
  57. package/src/core/proposals.ts +8 -2
  58. package/src/core/render/index.ts +27 -4
  59. package/src/core/render/vnode.ts +44 -6
  60. package/src/core/sanitize/svg-upload.ts +276 -23
  61. package/src/core/sanitize/svg.ts +3 -3
  62. package/src/core/schema/descriptors.ts +4 -0
  63. package/src/core/schema/design.ts +6 -5
  64. package/src/core/schema/layout.ts +395 -15
  65. package/src/core/schema/style.ts +2 -1
  66. package/src/core/shadowing-ids.ts +41 -0
  67. package/src/core/theme/conditions.ts +2 -1
  68. package/src/core/theme/parse-doc.ts +10 -5
  69. package/src/core/theme/triggers.ts +3 -2
  70. package/src/core/validate.ts +3 -2
  71. package/src/index.ts +23 -2
  72. package/src/mcp/ports.ts +18 -7
  73. package/src/mcp/proposals.ts +36 -11
  74. package/src/mcp/tools.ts +1 -1
  75. package/src/server/agent-settings.ts +12 -1
  76. package/src/server/hooks.ts +41 -6
  77. package/src/server/mcp-routes.ts +11 -5
  78. package/src/server/plugin.ts +27 -2
  79. package/src/server/presence.ts +5 -1
  80. package/src/server/proposals.ts +16 -4
  81. package/src/server/requests.ts +60 -11
  82. package/src/server/site-origin.ts +13 -0
  83. package/src/server/targets.ts +26 -0
@@ -7,6 +7,8 @@ import { ICON_ANIMATION_LIMIT_MS, iconAnimationRuns } from "../icons/animation-r
7
7
  import { updateNode } from "../tree-ops.ts";
8
8
  import { DEVICES } from "../theme/popup-rules.ts";
9
9
  import { hiddenOnEveryDevice } from "../design/devices.ts";
10
+ import { sanitizeHref } from "../sanitize/href.ts";
11
+ import { SOCIAL_COLORS, SOCIAL_NAMES } from "../elements/widgets.ts";
10
12
 
11
13
  /**
12
14
  * W-572: text as a screen reader says it: invisible format characters (zero-width space, word
@@ -42,7 +44,8 @@ export type A11yIssue = {
42
44
  | "control-name"
43
45
  | "empty-heading"
44
46
  | "landmark-name"
45
- | "motion";
47
+ | "motion"
48
+ | "empty-alert";
46
49
  severity: "error" | "warning";
47
50
  message: string;
48
51
  /** The one-click fix, when there is a safe one. */
@@ -303,7 +306,12 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
303
306
  severity: "error",
304
307
  message: "This image is a link but is marked decorative, so the link has no name.",
305
308
  });
306
- } else if (node.type === "image" && props["decorative"] !== true) {
309
+ } else if (
310
+ // W-1021: an image box's picture needs real alt text as an Image does, once it has one.
311
+ (node.type === "image" ||
312
+ ((node.type === "image-box" || node.type === "gallery-image") && spoken(props["src"]))) &&
313
+ props["decorative"] !== true
314
+ ) {
307
315
  const alt = typeof props["alt"] === "string" ? spoken(props["alt"]) : "";
308
316
  if (USELESS_ALT.test(alt)) {
309
317
  add({
@@ -459,6 +467,97 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
459
467
  if (shownOn[i]) names.add(key);
460
468
  });
461
469
  }
470
+ // W-1023: a Rating is an image of stars; its screen-reader text is the only way to hear the
471
+ // rating, so a custom one has to say it ({value}, or the number written out).
472
+ if (node.type === "rating") {
473
+ const label = spoken(props["label"]);
474
+ if (label && !label.includes("{value}") && !/\d/.test(label)) {
475
+ add({
476
+ nodeId: node.id,
477
+ rule: "image-alt",
478
+ severity: "warning",
479
+ message:
480
+ "This rating's text for screen readers doesn't say the rating. Add {value}, such as \"Rated {value} out of {max}\".",
481
+ });
482
+ }
483
+ }
484
+ // W-1020: a box's link is its title; with no title the link is left out of the page.
485
+ if (
486
+ (node.type === "icon-box" || node.type === "image-box") &&
487
+ spoken(props["href"]) &&
488
+ !spoken(props["title"]) &&
489
+ !node.bind
490
+ ) {
491
+ add({
492
+ nodeId: node.id,
493
+ rule: "link-name",
494
+ severity: "warning",
495
+ message:
496
+ "This box has a link but no title. The title is the link, so the link is left out.",
497
+ });
498
+ }
499
+ // W-1022: a testimonial without words is an empty quotation.
500
+ if (node.type === "testimonial" && !spoken(props["quote"]) && !node.bind) {
501
+ add({
502
+ nodeId: node.id,
503
+ rule: "empty-alert",
504
+ severity: "warning",
505
+ message: "This testimonial has no quote, so screen readers find an empty quotation.",
506
+ });
507
+ }
508
+ // W-1024: a Social link without a usable address shows a dimmed icon that goes nowhere.
509
+ if (node.type === "social-link" && !node.bind) {
510
+ const href = typeof props["href"] === "string" ? props["href"].trim() : "";
511
+ if (!href || !sanitizeHref(href)) {
512
+ add({
513
+ nodeId: node.id,
514
+ rule: "link-name",
515
+ severity: "warning",
516
+ message:
517
+ "This social link has no address it can use, so it shows a dimmed icon and links nowhere.",
518
+ });
519
+ }
520
+ }
521
+ // W-1024: some networks' own colours are too faint on white for an icon (under 3:1).
522
+ if (node.type === "social-icons" && props["brandColors"] === true && isParentNode(node)) {
523
+ const faint = node.children
524
+ .map((child) => (child.props as { network?: string }).network)
525
+ .filter(
526
+ (network): network is keyof typeof SOCIAL_COLORS =>
527
+ typeof network === "string" &&
528
+ network in SOCIAL_COLORS &&
529
+ contrastRatio(SOCIAL_COLORS[network as keyof typeof SOCIAL_COLORS], "#ffffff") < 3,
530
+ );
531
+ if (faint.length > 0) {
532
+ add({
533
+ nodeId: node.id,
534
+ rule: "contrast",
535
+ severity: "warning",
536
+ message: `On a light background, ${[...new Set(faint)].map((n) => SOCIAL_NAMES[n]).join(", ")} in brand colours is under 3:1, as an icon or as a badge behind a white icon. Turn Brand colours off or put the icons on a dark background.`,
537
+ });
538
+ }
539
+ }
540
+ // W-1018: slides that move on by themselves faster than about 5 seconds are hard to read.
541
+ if (node.type === "carousel" && props["autoplay"] === true) {
542
+ const seconds = typeof props["interval"] === "number" ? props["interval"] : 6;
543
+ if (seconds < 5) {
544
+ add({
545
+ nodeId: node.id,
546
+ rule: "motion",
547
+ severity: "warning",
548
+ message: `Slides change every ${seconds} seconds; many people need longer to read them. Use 5 seconds or more.`,
549
+ });
550
+ }
551
+ }
552
+ // W-1025: a notice with neither title nor text is a coloured box screen readers call a note.
553
+ if (node.type === "alert" && !spoken(props["title"]) && !spoken(props["text"]) && !node.bind) {
554
+ add({
555
+ nodeId: node.id,
556
+ rule: "empty-alert",
557
+ severity: "warning",
558
+ message: "This alert has no title or text, so it shows an empty box and says nothing.",
559
+ });
560
+ }
462
561
  // W-419: an empty heading still shows up in screen readers' heading list, with nothing to say.
463
562
  if (node.type === "heading" && !spoken(props["text"]) && !node.bind) {
464
563
  add({
@@ -1,4 +1,11 @@
1
- import { MAX_DEPTH, MAX_NODES, MAX_TABS } from "./limits.ts";
1
+ import {
2
+ MAX_CAROUSEL_SLIDES,
3
+ MAX_DEPTH,
4
+ MAX_GALLERY_IMAGES,
5
+ MAX_NODES,
6
+ MAX_SOCIAL_LINKS,
7
+ MAX_TABS,
8
+ } from "./limits.ts";
2
9
  import {
3
10
  isContainerNode,
4
11
  isFormFieldType,
@@ -64,6 +71,15 @@ export const REASONS = {
64
71
  onlyAccordionItems: "An accordion can only hold accordion items.",
65
72
  itemOutsideMenu: "Menu items can only go inside a Menu.",
66
73
  onlyMenuItems: "A menu can only hold menu items.",
74
+ linkOutsideSocial: "Social links can only go inside Social icons.",
75
+ onlySocialLinks: "Social icons can only hold social links.",
76
+ tooManySocialLinks: `Social icons can hold up to ${MAX_SOCIAL_LINKS} links.`,
77
+ imageOutsideGallery: "Gallery images can only go inside a Gallery.",
78
+ onlyGalleryImages: "A gallery can only hold gallery images.",
79
+ tooManyGalleryImages: `A gallery can hold up to ${MAX_GALLERY_IMAGES} pictures.`,
80
+ slideOutsideCarousel: "Slides can only go inside a Carousel.",
81
+ onlySlides: "A carousel can only hold slides.",
82
+ tooManySlides: `A carousel can hold up to ${MAX_CAROUSEL_SLIDES} slides.`,
67
83
  emptyOutsideLoop: "An Empty state can only go inside a Loop.",
68
84
  } as const;
69
85
 
@@ -143,6 +159,22 @@ export function parentChildRefusal(
143
159
  return REASONS.itemOutsideMenu;
144
160
  }
145
161
  if (parent.type === "menu" && child.type !== "menu-item") return REASONS.onlyMenuItems;
162
+ if (child.type === "social-link" && parent.type !== "social-icons") {
163
+ return REASONS.linkOutsideSocial;
164
+ }
165
+ if (parent.type === "social-icons" && child.type !== "social-link") {
166
+ return REASONS.onlySocialLinks;
167
+ }
168
+ if (child.type === "gallery-image" && parent.type !== "gallery") {
169
+ return REASONS.imageOutsideGallery;
170
+ }
171
+ if (parent.type === "gallery" && child.type !== "gallery-image") {
172
+ return REASONS.onlyGalleryImages;
173
+ }
174
+ if (child.type === "carousel-slide" && parent.type !== "carousel") {
175
+ return REASONS.slideOutsideCarousel;
176
+ }
177
+ if (parent.type === "carousel" && child.type !== "carousel-slide") return REASONS.onlySlides;
146
178
  if (isFormNode(child) && inForm) return REASONS.nestedForm;
147
179
  if (isFormFieldType(child.type) && !inForm) return REASONS.fieldOutsideForm;
148
180
  return undefined;
@@ -159,6 +191,30 @@ const DROP_RULES: [breaks: (drop: Drop) => boolean, reason: string][] = [
159
191
  nodeChildren(into.node).length >= MAX_TABS,
160
192
  REASONS.tooManyTabs,
161
193
  ],
194
+ // W-1024: as Tabs, a full Social icons takes no new link; moving within it is fine.
195
+ [
196
+ ({ node, into }) =>
197
+ into.node.type === "social-icons" &&
198
+ !nodeChildren(into.node).some((child) => child.id === node.id) &&
199
+ nodeChildren(into.node).length >= MAX_SOCIAL_LINKS,
200
+ REASONS.tooManySocialLinks,
201
+ ],
202
+ // W-1019: a full Gallery takes no new picture; moving within it is fine.
203
+ [
204
+ ({ node, into }) =>
205
+ into.node.type === "gallery" &&
206
+ !nodeChildren(into.node).some((child) => child.id === node.id) &&
207
+ nodeChildren(into.node).length >= MAX_GALLERY_IMAGES,
208
+ REASONS.tooManyGalleryImages,
209
+ ],
210
+ // W-1018: a full Carousel takes no new slide; moving within it is fine.
211
+ [
212
+ ({ node, into }) =>
213
+ into.node.type === "carousel" &&
214
+ !nodeChildren(into.node).some((child) => child.id === node.id) &&
215
+ nodeChildren(into.node).length >= MAX_CAROUSEL_SLIDES,
216
+ REASONS.tooManySlides,
217
+ ],
162
218
  [({ node, into }) => into.depth + height(node) > MAX_DEPTH, REASONS.tooDeep],
163
219
  [
164
220
  ({ node, layout, isNew }) => isNew && size(layout.root) + size(node) > MAX_NODES,
@@ -8,24 +8,27 @@ import { z } from "zod";
8
8
  * JSON Schema output (MCP `tools/list`) is the plain array, with minItems/maxItems.
9
9
  */
10
10
  export function boundedArray<T extends z.ZodType>(item: T, max: number, min = 0) {
11
- return z
12
- .unknown()
13
- .check((ctx) => {
14
- const value = ctx.value;
15
- if (!Array.isArray(value)) return;
16
- if (value.length > max || value.length < min) {
11
+ // S-03: a transform in front (not a check) keeps the JSON Schema the plain array for input
12
+ // and output alike, so the published layout schemas are unchanged.
13
+ const schema = z
14
+ .transform((value: unknown, ctx) => {
15
+ if (Array.isArray(value) && value.length > max) {
17
16
  ctx.issues.push({
18
- code: value.length > max ? "too_big" : "too_small",
17
+ code: "too_big",
19
18
  origin: "array",
20
- ...(value.length > max ? { maximum: max } : { minimum: min }),
19
+ maximum: max,
21
20
  inclusive: true,
22
21
  input: value,
23
- message:
24
- value.length > max
25
- ? `Too many items: at most ${max}.`
26
- : `Too few items: at least ${min}.`,
22
+ message: `Too many items: at most ${max}.`,
27
23
  } as never);
24
+ return z.NEVER;
28
25
  }
26
+ return value;
29
27
  })
30
- .pipe(z.array(item).min(min).max(max));
28
+ .pipe((min > 0 ? z.array(item).min(min) : z.array(item)).max(max));
29
+ // A transform counts as an optional input, which would make a tuple slot holding this array
30
+ // optional in the JSON Schema; the array itself is required.
31
+ // oxlint-disable-next-line no-underscore-dangle -- zod keeps the flag on its internals
32
+ Object.defineProperty(schema._zod, "optin", { value: undefined, configurable: true });
33
+ return schema;
31
34
  }
@@ -52,7 +52,10 @@ function depthOf(value: unknown, limit: number): number {
52
52
  if (typeof v !== "object" || v === null) continue;
53
53
  max = Math.max(max, depth);
54
54
  if (max > limit) return max;
55
- for (const child of Object.values(v)) stack.push({ value: child, depth: depth + 1 });
55
+ // S-03: only objects go on the stack; a long array of numbers held one entry per item.
56
+ for (const child of Array.isArray(v) ? v : Object.values(v))
57
+ if (typeof child === "object" && child !== null)
58
+ stack.push({ value: child, depth: depth + 1 });
56
59
  }
57
60
  return max;
58
61
  }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * The SVG of an icon (W-025, W-234, W-237, W-238): a bundled Lucide icon or a picked one, sized,
3
+ * its stroke width themable and, when asked, painted in one colour. The Icon element and the
4
+ * 1.2 widgets that show an icon (W-1020) draw it here.
5
+ */
6
+ import { getBundledIcon } from "../icons/catalog.ts";
7
+ import type { VNode } from "../render/vnode.ts";
8
+ import { sanitizeSvgMarkup } from "../sanitize/svg.ts";
9
+
10
+ /** Root stroke widths the Stroke width control can override (W-237); Lucide and Tabler use 2. */
11
+ export const ICON_STROKE_WIDTHS = ["1", "1.5", "2", "2.5", "3"] as const;
12
+
13
+ /**
14
+ * W-237: a stroke icon's root `stroke-width` moves into a class whose CSS reads the wrapper's
15
+ * `--emvb-icon-stroke` with the original width as fallback; any other width stays as it was.
16
+ */
17
+ function strokeClass(svgAttrs: Record<string, string>): void {
18
+ const width = svgAttrs["stroke-width"];
19
+ if (!width || !(ICON_STROKE_WIDTHS as readonly string[]).includes(width)) return;
20
+ if (!svgAttrs.stroke || svgAttrs.stroke === "none") return;
21
+ delete svgAttrs["stroke-width"];
22
+ const cls = `emvb-icon-sw${width.replace(".", "_")}`;
23
+ svgAttrs.class = svgAttrs.class ? `${svgAttrs.class} ${cls}` : cls;
24
+ }
25
+
26
+ /** Whether an icon's SVG is stroke-drawn with an adjustable width (the panel shows the control). */
27
+ export function iconHasAdjustableStroke(svg: string | undefined): boolean {
28
+ if (!svg) return true; // bundled Lucide
29
+ const picked = sanitizeSvgMarkup(svg);
30
+ if (!picked) return false;
31
+ const attrs = pickedIconAttrs(picked.attrs);
32
+ const before = attrs["stroke-width"];
33
+ strokeClass(attrs);
34
+ return before !== undefined && attrs["stroke-width"] === undefined;
35
+ }
36
+
37
+ /** Paint attributes a multi-colour SVG sets its colours with (W-238). */
38
+ const PAINT_ATTRS = ["fill", "stroke", "stop-color"] as const;
39
+
40
+ const ownColor = (value: string | undefined) =>
41
+ value !== undefined && value !== "none" && value.toLowerCase() !== "currentcolor";
42
+
43
+ /** W-238: every fill, stroke and gradient stop becomes the icon's colour; `none` stays none. */
44
+ function monochrome(nodes: (VNode | string)[]): (VNode | string)[] {
45
+ return nodes.map((child) => {
46
+ if (typeof child === "string") return child;
47
+ const attrs = { ...child.attrs };
48
+ for (const name of PAINT_ATTRS) if (ownColor(attrs[name])) attrs[name] = "currentColor";
49
+ return { ...child, attrs, children: monochrome(child.children) };
50
+ });
51
+ }
52
+
53
+ /** The root too; without a fill, SVG paints black, so it gets the icon's colour. */
54
+ function monochromeRoot(attrs: Record<string, string>): void {
55
+ if (attrs.fill === undefined || ownColor(attrs.fill)) attrs.fill = "currentColor";
56
+ if (ownColor(attrs.stroke)) attrs.stroke = "currentColor";
57
+ }
58
+
59
+ /**
60
+ * Whether an icon's SVG paints with its own colours (W-238): any fill, stroke or stop other than
61
+ * `none`/`currentColor`, or a root without a fill (SVG's default is black). The panel offers
62
+ * Force single colour only then. Bundled Lucide icons follow the icon's colour already.
63
+ */
64
+ export function iconHasOwnColors(svg: string | undefined): boolean {
65
+ if (!svg) return false;
66
+ const picked = sanitizeSvgMarkup(svg);
67
+ if (!picked) return false;
68
+ if (picked.attrs.fill === undefined || PAINT_ATTRS.some((name) => ownColor(picked.attrs[name])))
69
+ return true;
70
+ const walk = (nodes: (VNode | string)[]): boolean =>
71
+ nodes.some(
72
+ (child) =>
73
+ typeof child !== "string" &&
74
+ (PAINT_ATTRS.some((name) => ownColor(child.attrs[name])) || walk(child.children)),
75
+ );
76
+ return walk(picked.children);
77
+ }
78
+
79
+ /** A picked icon's root attributes minus what the element sets itself (size, name, id). */
80
+ function pickedIconAttrs(attrs: Record<string, string>): Record<string, string> {
81
+ const kept: Record<string, string> = { xmlns: "http://www.w3.org/2000/svg" };
82
+ for (const [name, value] of Object.entries(attrs)) {
83
+ if (name === "width" || name === "height" || name === "id" || name === "role") continue;
84
+ if (name.startsWith("aria-") || name === "focusable") continue;
85
+ kept[name] = value;
86
+ }
87
+ if (!kept.viewBox) kept.viewBox = "0 0 24 24";
88
+ return kept;
89
+ }
90
+
91
+ /**
92
+ * W-1020: an icon's `<svg>` at `size` px with `aria` (its name, or `aria-hidden`), or undefined
93
+ * when the id is unknown and no SVG is stored.
94
+ */
95
+ export function iconGlyph(
96
+ props: { iconId: string; iconSvg?: string | undefined; singleColor?: boolean | undefined },
97
+ size: number,
98
+ aria: Record<string, string>,
99
+ ): VNode | undefined {
100
+ // W-234: a picked library icon carries its own SVG; the allowlist checks it on every render.
101
+ const picked = props.iconSvg ? sanitizeSvgMarkup(props.iconSvg) : undefined;
102
+ const bundled = picked ? undefined : getBundledIcon(props.iconId);
103
+ if (!picked && !bundled) return undefined;
104
+ const svgAttrs: Record<string, string> = picked
105
+ ? {
106
+ ...pickedIconAttrs(picked.attrs),
107
+ width: String(size),
108
+ height: String(size),
109
+ focusable: "false",
110
+ }
111
+ : {
112
+ xmlns: "http://www.w3.org/2000/svg",
113
+ width: String(size),
114
+ height: String(size),
115
+ viewBox: "0 0 24 24",
116
+ fill: "none",
117
+ stroke: "currentColor",
118
+ "stroke-width": "2",
119
+ "stroke-linecap": "round",
120
+ "stroke-linejoin": "round",
121
+ focusable: "false",
122
+ };
123
+ Object.assign(svgAttrs, aria);
124
+ const children: (VNode | string)[] = picked
125
+ ? picked.children
126
+ : (bundled?.children ?? []).map((child) => ({
127
+ tag: child.tag,
128
+ attrs: { ...child.attrs },
129
+ children: [],
130
+ }));
131
+ strokeClass(svgAttrs);
132
+ const single = picked !== undefined && props.singleColor === true;
133
+ if (single) monochromeRoot(svgAttrs);
134
+ return { tag: "svg", attrs: svgAttrs, children: single ? monochrome(children) : children };
135
+ }
@@ -36,7 +36,22 @@ 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";
40
+ export { iconHasAdjustableStroke, iconHasOwnColors } from "./icon-svg.ts";
39
41
  import { menu, menuItem } from "./menu.ts";
42
+ import {
43
+ alert,
44
+ carousel,
45
+ carouselSlide,
46
+ gallery,
47
+ galleryImage,
48
+ iconBox,
49
+ imageBox,
50
+ rating,
51
+ socialIcons,
52
+ socialLink,
53
+ testimonial,
54
+ } from "./widgets.ts";
40
55
  import { checkbox, form, radio, selectEl, submit, textInput, textareaEl } from "./form-elements.ts";
41
56
  import {
42
57
  loop,
@@ -608,9 +623,6 @@ function imageSources(
608
623
  return parts.join(", ");
609
624
  }
610
625
 
611
- /** Root stroke widths the Stroke width control can override (W-237); Lucide and Tabler use 2. */
612
- const ICON_STROKE_WIDTHS = ["1", "1.5", "2", "2.5", "3"] as const;
613
-
614
626
  const icon: ElementDefinition<IconNode> = {
615
627
  baseCss:
616
628
  // W-237: the glyph reads the wrapper's icon custom properties (rotate, flip, shadow, loop,
@@ -651,10 +663,12 @@ const icon: ElementDefinition<IconNode> = {
651
663
  ],
652
664
  },
653
665
  build: (node, attrs) => {
654
- // W-234: a picked library icon carries its own SVG; the allowlist checks it on every render.
655
- const picked = node.props.iconSvg ? sanitizeSvgMarkup(node.props.iconSvg) : undefined;
656
- const bundled = picked ? undefined : getBundledIcon(node.props.iconId);
657
- if (!picked && !bundled) {
666
+ const decorative = node.props.decorative === true;
667
+ const aria: Record<string, string> = decorative
668
+ ? { "aria-hidden": "true" }
669
+ : { role: "img", ...(node.props.title ? { "aria-label": node.props.title } : {}) };
670
+ const svg = iconGlyph(node.props, node.props.size ?? 24, aria);
671
+ if (!svg) {
658
672
  // Never treat iconId as a URL or raw HTML (R-032 / R-033).
659
673
  return {
660
674
  tag: "span",
@@ -666,48 +680,7 @@ const icon: ElementDefinition<IconNode> = {
666
680
  children: [],
667
681
  };
668
682
  }
669
- const decorative = node.props.decorative === true;
670
- const size = node.props.size ?? 24;
671
- const svgAttrs: Record<string, string> = picked
672
- ? {
673
- ...pickedIconAttrs(picked.attrs),
674
- width: String(size),
675
- height: String(size),
676
- focusable: "false",
677
- }
678
- : {
679
- xmlns: "http://www.w3.org/2000/svg",
680
- width: String(size),
681
- height: String(size),
682
- viewBox: "0 0 24 24",
683
- fill: "none",
684
- stroke: "currentColor",
685
- "stroke-width": "2",
686
- "stroke-linecap": "round",
687
- "stroke-linejoin": "round",
688
- focusable: "false",
689
- };
690
- if (decorative) {
691
- svgAttrs["aria-hidden"] = "true";
692
- } else {
693
- svgAttrs.role = "img";
694
- if (node.props.title) svgAttrs["aria-label"] = node.props.title;
695
- }
696
- const children: (VNode | string)[] = picked
697
- ? picked.children
698
- : (bundled?.children ?? []).map((child) => ({
699
- tag: child.tag,
700
- attrs: { ...child.attrs },
701
- children: [],
702
- }));
703
- strokeClass(svgAttrs);
704
- const single = picked !== undefined && node.props.singleColor === true;
705
- if (single) monochromeRoot(svgAttrs);
706
- const svg: VNode = {
707
- tag: "svg",
708
- attrs: svgAttrs,
709
- children: single ? monochrome(children) : children,
710
- };
683
+ const svgAttrs = svg.attrs;
711
684
  // A linked icon is named by its title on the link, so the svg inside is hidden.
712
685
  const title = node.props.title?.trim();
713
686
  const { role: _role, "aria-label": _label, ...plain } = svgAttrs;
@@ -721,84 +694,6 @@ const icon: ElementDefinition<IconNode> = {
721
694
  },
722
695
  };
723
696
 
724
- /**
725
- * W-237: a stroke icon's root `stroke-width` moves into a class whose CSS reads the wrapper's
726
- * `--emvb-icon-stroke` with the original width as fallback; any other width stays as it was.
727
- */
728
- function strokeClass(svgAttrs: Record<string, string>): void {
729
- const width = svgAttrs["stroke-width"];
730
- if (!width || !(ICON_STROKE_WIDTHS as readonly string[]).includes(width)) return;
731
- if (!svgAttrs.stroke || svgAttrs.stroke === "none") return;
732
- delete svgAttrs["stroke-width"];
733
- const cls = `emvb-icon-sw${width.replace(".", "_")}`;
734
- svgAttrs.class = svgAttrs.class ? `${svgAttrs.class} ${cls}` : cls;
735
- }
736
-
737
- /** Whether an icon's SVG is stroke-drawn with an adjustable width (the panel shows the control). */
738
- export function iconHasAdjustableStroke(svg: string | undefined): boolean {
739
- if (!svg) return true; // bundled Lucide
740
- const picked = sanitizeSvgMarkup(svg);
741
- if (!picked) return false;
742
- const attrs = pickedIconAttrs(picked.attrs);
743
- const before = attrs["stroke-width"];
744
- strokeClass(attrs);
745
- return before !== undefined && attrs["stroke-width"] === undefined;
746
- }
747
-
748
- /** Paint attributes a multi-colour SVG sets its colours with (W-238). */
749
- const PAINT_ATTRS = ["fill", "stroke", "stop-color"] as const;
750
-
751
- const ownColor = (value: string | undefined) =>
752
- value !== undefined && value !== "none" && value.toLowerCase() !== "currentcolor";
753
-
754
- /** W-238: every fill, stroke and gradient stop becomes the icon's colour; `none` stays none. */
755
- function monochrome(nodes: (VNode | string)[]): (VNode | string)[] {
756
- return nodes.map((child) => {
757
- if (typeof child === "string") return child;
758
- const attrs = { ...child.attrs };
759
- for (const name of PAINT_ATTRS) if (ownColor(attrs[name])) attrs[name] = "currentColor";
760
- return { ...child, attrs, children: monochrome(child.children) };
761
- });
762
- }
763
-
764
- /** The root too; without a fill, SVG paints black, so it gets the icon's colour. */
765
- function monochromeRoot(attrs: Record<string, string>): void {
766
- if (attrs.fill === undefined || ownColor(attrs.fill)) attrs.fill = "currentColor";
767
- if (ownColor(attrs.stroke)) attrs.stroke = "currentColor";
768
- }
769
-
770
- /**
771
- * Whether an icon's SVG paints with its own colours (W-238): any fill, stroke or stop other than
772
- * `none`/`currentColor`, or a root without a fill (SVG's default is black). The panel offers
773
- * Force single colour only then. Bundled Lucide icons follow the icon's colour already.
774
- */
775
- export function iconHasOwnColors(svg: string | undefined): boolean {
776
- if (!svg) return false;
777
- const picked = sanitizeSvgMarkup(svg);
778
- if (!picked) return false;
779
- if (picked.attrs.fill === undefined || PAINT_ATTRS.some((name) => ownColor(picked.attrs[name])))
780
- return true;
781
- const walk = (nodes: (VNode | string)[]): boolean =>
782
- nodes.some(
783
- (child) =>
784
- typeof child !== "string" &&
785
- (PAINT_ATTRS.some((name) => ownColor(child.attrs[name])) || walk(child.children)),
786
- );
787
- return walk(picked.children);
788
- }
789
-
790
- /** A picked icon's root attributes minus what the element sets itself (size, name, id). */
791
- function pickedIconAttrs(attrs: Record<string, string>): Record<string, string> {
792
- const kept: Record<string, string> = { xmlns: "http://www.w3.org/2000/svg" };
793
- for (const [name, value] of Object.entries(attrs)) {
794
- if (name === "width" || name === "height" || name === "id" || name === "role") continue;
795
- if (name.startsWith("aria-") || name === "focusable") continue;
796
- kept[name] = value;
797
- }
798
- if (!kept.viewBox) kept.viewBox = "0 0 24 24";
799
- return kept;
800
- }
801
-
802
697
  const video: ElementDefinition<VideoNode> = {
803
698
  baseCss:
804
699
  // W-266: the iframe or <video> is the .emvb-video element itself, so the 16:9 size sits on it
@@ -1218,6 +1113,17 @@ export const ELEMENTS = {
1218
1113
  heading,
1219
1114
  toc,
1220
1115
  "language-switcher": languageSwitcher,
1116
+ rating,
1117
+ alert,
1118
+ "icon-box": iconBox,
1119
+ "image-box": imageBox,
1120
+ testimonial,
1121
+ "social-icons": socialIcons,
1122
+ "social-link": socialLink,
1123
+ gallery,
1124
+ "gallery-image": galleryImage,
1125
+ carousel,
1126
+ "carousel-slide": carouselSlide,
1221
1127
  container,
1222
1128
  "layout-section": layoutSection,
1223
1129
  spacer,