@perkyzz/emvb 1.1.0 → 1.3.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 (99) hide show
  1. package/THIRD_PARTY_NOTICES.md +3 -2
  2. package/package.json +11 -10
  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/canvas/vnode-react.tsx +3 -0
  9. package/src/admin/editor/dnd/new-element.ts +106 -0
  10. package/src/admin/editor/editor-chrome.tsx +9 -0
  11. package/src/admin/editor/element-chrome.ts +50 -0
  12. package/src/admin/editor/panels/ElementPanel.tsx +5 -1
  13. package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
  14. package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
  15. package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
  16. package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
  17. package/src/admin/editor/panels/settings/ItemList.tsx +69 -2
  18. package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
  19. package/src/admin/editor/store.ts +7 -1
  20. package/src/admin/editor/useEditorData.ts +4 -0
  21. package/src/admin/editor/useSave.ts +47 -3
  22. package/src/admin/export-api.ts +20 -3
  23. package/src/admin/menus-api.ts +113 -0
  24. package/src/admin/pages/ImportElementorDialog.tsx +25 -1
  25. package/src/astro/EmVBPage.astro +3 -0
  26. package/src/astro/render.ts +43 -18
  27. package/src/astro/request-data.ts +9 -0
  28. package/src/astro/resolve-theme.ts +77 -44
  29. package/src/astro/resolve.ts +9 -0
  30. package/src/astro/visitor.ts +23 -4
  31. package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
  32. package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -0
  33. package/src/astro/widgets/EmVBCountdownRuntime.astro +8 -0
  34. package/src/astro/widgets/EmVBCounterRuntime.astro +8 -0
  35. package/src/astro/widgets/EmVBHeadlineRuntime.astro +9 -0
  36. package/src/astro/widgets/EmVBLightboxRuntime.astro +8 -0
  37. package/src/astro/widgets/EmVBMapRuntime.astro +8 -0
  38. package/src/astro/widgets/EmVBShareRuntime.astro +9 -0
  39. package/src/astro/widgets/EmVBWidgetRuntimes.astro +29 -0
  40. package/src/astro/widgets/alerts.ts +37 -0
  41. package/src/astro/widgets/carousel.ts +167 -0
  42. package/src/astro/widgets/countdown.ts +80 -0
  43. package/src/astro/widgets/counter.ts +98 -0
  44. package/src/astro/widgets/headline.ts +90 -0
  45. package/src/astro/widgets/index.ts +1 -0
  46. package/src/astro/widgets/lightbox.ts +123 -0
  47. package/src/astro/widgets/map.ts +37 -0
  48. package/src/astro/widgets/share.ts +21 -0
  49. package/src/constants.ts +1 -1
  50. package/src/core/a11y/audit.ts +127 -5
  51. package/src/core/arrange.ts +109 -1
  52. package/src/core/bounded-array.ts +16 -13
  53. package/src/core/canvas-collections.ts +28 -0
  54. package/src/core/contract.ts +4 -1
  55. package/src/core/elements/counter-format.ts +15 -0
  56. package/src/core/elements/icon-svg.ts +135 -0
  57. package/src/core/elements/index.ts +63 -127
  58. package/src/core/elements/marketing.ts +1490 -0
  59. package/src/core/elements/widgets.ts +932 -0
  60. package/src/core/export/runtimes.generated.ts +8 -0
  61. package/src/core/export/site.ts +25 -3
  62. package/src/core/extensions/schema.ts +2 -1
  63. package/src/core/geo-trust.ts +18 -0
  64. package/src/core/icons/social.generated.ts +29 -0
  65. package/src/core/image-edit/schema.ts +2 -1
  66. package/src/core/import/elementor/context.ts +18 -0
  67. package/src/core/import/elementor/index.ts +50 -7
  68. package/src/core/import/elementor/widgets.ts +783 -385
  69. package/src/core/issue-cap.ts +19 -0
  70. package/src/core/limits.ts +12 -0
  71. package/src/core/loop-collections.ts +33 -0
  72. package/src/core/proposals.ts +8 -2
  73. package/src/core/render/index.ts +48 -5
  74. package/src/core/render/vnode.ts +44 -6
  75. package/src/core/sanitize/svg-upload.ts +276 -23
  76. package/src/core/sanitize/svg.ts +3 -3
  77. package/src/core/schema/descriptors.ts +4 -0
  78. package/src/core/schema/design.ts +6 -5
  79. package/src/core/schema/layout.ts +798 -15
  80. package/src/core/schema/style.ts +2 -1
  81. package/src/core/shadowing-ids.ts +41 -0
  82. package/src/core/theme/conditions.ts +2 -1
  83. package/src/core/theme/dynamic.ts +2 -0
  84. package/src/core/theme/parse-doc.ts +10 -5
  85. package/src/core/theme/triggers.ts +3 -2
  86. package/src/core/validate.ts +3 -2
  87. package/src/index.ts +23 -2
  88. package/src/mcp/ports.ts +18 -7
  89. package/src/mcp/proposals.ts +36 -11
  90. package/src/mcp/tools.ts +1 -1
  91. package/src/server/agent-settings.ts +12 -1
  92. package/src/server/hooks.ts +41 -6
  93. package/src/server/mcp-routes.ts +11 -5
  94. package/src/server/plugin.ts +29 -3
  95. package/src/server/presence.ts +5 -1
  96. package/src/server/proposals.ts +16 -4
  97. package/src/server/requests.ts +60 -11
  98. package/src/server/site-origin.ts +13 -0
  99. 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,9 @@ export type A11yIssue = {
42
44
  | "control-name"
43
45
  | "empty-heading"
44
46
  | "landmark-name"
45
- | "motion";
47
+ | "motion"
48
+ | "empty-alert"
49
+ | "counter-title";
46
50
  severity: "error" | "warning";
47
51
  message: string;
48
52
  /** The one-click fix, when there is a safe one. */
@@ -147,7 +151,8 @@ function px(value: unknown, design?: DesignSystem): number | undefined {
147
151
  const HEADING_PX = [32, 24, 18.72, 16, 13.28, 10.72];
148
152
 
149
153
  const headingLevel = (node: LayoutNode): number | undefined => {
150
- if (node.type !== "heading") return undefined;
154
+ // W-1046: an Animated headline is a heading too.
155
+ if (node.type !== "heading" && node.type !== "headline") return undefined;
151
156
  const level = (node.props as { level?: unknown }).level;
152
157
  return typeof level === "number" && level >= 1 && level <= 6 ? level : 2;
153
158
  };
@@ -303,7 +308,13 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
303
308
  severity: "error",
304
309
  message: "This image is a link but is marked decorative, so the link has no name.",
305
310
  });
306
- } else if (node.type === "image" && props["decorative"] !== true) {
311
+ } else if (
312
+ // W-1021: an image box's picture needs real alt text as an Image does, once it has one.
313
+ (node.type === "image" ||
314
+ ((node.type === "image-box" || node.type === "gallery-image" || node.type === "hotspots") &&
315
+ spoken(props["src"]))) &&
316
+ props["decorative"] !== true
317
+ ) {
307
318
  const alt = typeof props["alt"] === "string" ? spoken(props["alt"]) : "";
308
319
  if (USELESS_ALT.test(alt)) {
309
320
  add({
@@ -459,6 +470,117 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
459
470
  if (shownOn[i]) names.add(key);
460
471
  });
461
472
  }
473
+ // W-1023: a Rating is an image of stars; its screen-reader text is the only way to hear the
474
+ // rating, so a custom one has to say it ({value}, or the number written out).
475
+ if (node.type === "rating") {
476
+ const label = spoken(props["label"]);
477
+ if (label && !label.includes("{value}") && !/\d/.test(label)) {
478
+ add({
479
+ nodeId: node.id,
480
+ rule: "image-alt",
481
+ severity: "warning",
482
+ message:
483
+ "This rating's text for screen readers doesn't say the rating. Add {value}, such as \"Rated {value} out of {max}\".",
484
+ });
485
+ }
486
+ }
487
+ // W-1020: a box's link is its title; with no title the link is left out of the page.
488
+ if (
489
+ (node.type === "icon-box" || node.type === "image-box") &&
490
+ spoken(props["href"]) &&
491
+ !spoken(props["title"]) &&
492
+ !node.bind
493
+ ) {
494
+ add({
495
+ nodeId: node.id,
496
+ rule: "link-name",
497
+ severity: "warning",
498
+ message:
499
+ "This box has a link but no title. The title is the link, so the link is left out.",
500
+ });
501
+ }
502
+ // W-1022: a testimonial without words is an empty quotation.
503
+ if (node.type === "testimonial" && !spoken(props["quote"]) && !node.bind) {
504
+ add({
505
+ nodeId: node.id,
506
+ rule: "empty-alert",
507
+ severity: "warning",
508
+ message: "This testimonial has no quote, so screen readers find an empty quotation.",
509
+ });
510
+ }
511
+ // W-1024: a Social link without a usable address shows a dimmed icon that goes nowhere.
512
+ if (node.type === "social-link" && !node.bind) {
513
+ const href = typeof props["href"] === "string" ? props["href"].trim() : "";
514
+ if (!href || !sanitizeHref(href)) {
515
+ add({
516
+ nodeId: node.id,
517
+ rule: "link-name",
518
+ severity: "warning",
519
+ message:
520
+ "This social link has no address it can use, so it shows a dimmed icon and links nowhere.",
521
+ });
522
+ }
523
+ }
524
+ // W-1024: some networks' own colours are too faint on white for an icon (under 3:1).
525
+ if (node.type === "social-icons" && props["brandColors"] === true && isParentNode(node)) {
526
+ const faint = node.children
527
+ .map((child) => (child.props as { network?: string }).network)
528
+ .filter(
529
+ (network): network is keyof typeof SOCIAL_COLORS =>
530
+ typeof network === "string" &&
531
+ network in SOCIAL_COLORS &&
532
+ contrastRatio(SOCIAL_COLORS[network as keyof typeof SOCIAL_COLORS], "#ffffff") < 3,
533
+ );
534
+ if (faint.length > 0) {
535
+ add({
536
+ nodeId: node.id,
537
+ rule: "contrast",
538
+ severity: "warning",
539
+ 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.`,
540
+ });
541
+ }
542
+ }
543
+ // W-1018: slides that move on by themselves faster than about 5 seconds are hard to read.
544
+ if (node.type === "carousel" && props["autoplay"] === true) {
545
+ const seconds = typeof props["interval"] === "number" ? props["interval"] : 6;
546
+ if (seconds < 5) {
547
+ add({
548
+ nodeId: node.id,
549
+ rule: "motion",
550
+ severity: "warning",
551
+ message: `Slides change every ${seconds} seconds; many people need longer to read them. Use 5 seconds or more.`,
552
+ });
553
+ }
554
+ }
555
+ // W-1025: a notice with neither title nor text is a coloured box screen readers call a note.
556
+ if (node.type === "alert" && !spoken(props["title"]) && !spoken(props["text"]) && !node.bind) {
557
+ add({
558
+ nodeId: node.id,
559
+ rule: "empty-alert",
560
+ severity: "warning",
561
+ message: "This alert has no title or text, so it shows an empty box and says nothing.",
562
+ });
563
+ }
564
+ // W-1039: a bar without a title is a meter screen readers can't name.
565
+ if (node.type === "progress" && !spoken(props["label"]) && !node.bind) {
566
+ add({
567
+ nodeId: node.id,
568
+ rule: "control-name",
569
+ severity: "warning",
570
+ message:
571
+ 'This progress bar has no title, so screen readers can\'t say what it measures. Add a title such as "Design".',
572
+ });
573
+ }
574
+ // W-1038: a Counter's number alone ("1,200+") doesn't say what was counted.
575
+ if (node.type === "counter" && !spoken(props["title"]) && !node.bind) {
576
+ add({
577
+ nodeId: node.id,
578
+ rule: "counter-title",
579
+ severity: "warning",
580
+ message:
581
+ 'This counter has no title, so its number doesn\'t say what it counts. Add a title such as "Happy clients".',
582
+ });
583
+ }
462
584
  // W-419: an empty heading still shows up in screen readers' heading list, with nothing to say.
463
585
  if (node.type === "heading" && !spoken(props["text"]) && !node.bind) {
464
586
  add({
@@ -468,7 +590,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
468
590
  message: "This heading is empty; screen readers list it as a heading with no words.",
469
591
  });
470
592
  }
471
- if (node.type === "heading") {
593
+ if (node.type === "heading" || node.type === "headline") {
472
594
  const level = typeof props["level"] === "number" ? props["level"] : 2;
473
595
  if (level === 1) {
474
596
  h1s = h1s.map((count, i) => count + (shownOn[i] ? 1 : 0));
@@ -644,7 +766,7 @@ export function applyAllA11yFixes(layout: Layout, issues: A11yIssue[]): Layout {
644
766
  const levels = new Map<string, number>();
645
767
  let last = 0;
646
768
  const walk = (node: LayoutNode) => {
647
- if (node.type === "heading") {
769
+ if (node.type === "heading" || node.type === "headline") {
648
770
  const own = typeof node.props["level"] === "number" ? node.props["level"] : 2;
649
771
  const level = order.has(node.id) ? Math.min(own, Math.max(2, last + 1)) : own;
650
772
  if (level !== own) levels.set(node.id, level);
@@ -1,4 +1,14 @@
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_HOTSPOTS,
7
+ MAX_PRICE_ITEMS,
8
+ MAX_SHARE_LINKS,
9
+ MAX_SOCIAL_LINKS,
10
+ MAX_TABS,
11
+ } from "./limits.ts";
2
12
  import {
3
13
  isContainerNode,
4
14
  isFormFieldType,
@@ -64,6 +74,24 @@ export const REASONS = {
64
74
  onlyAccordionItems: "An accordion can only hold accordion items.",
65
75
  itemOutsideMenu: "Menu items can only go inside a Menu.",
66
76
  onlyMenuItems: "A menu can only hold menu items.",
77
+ linkOutsideSocial: "Social links can only go inside Social icons.",
78
+ onlySocialLinks: "Social icons can only hold social links.",
79
+ tooManySocialLinks: `Social icons can hold up to ${MAX_SOCIAL_LINKS} links.`,
80
+ imageOutsideGallery: "Gallery images can only go inside a Gallery.",
81
+ onlyGalleryImages: "A gallery can only hold gallery images.",
82
+ tooManyGalleryImages: `A gallery can hold up to ${MAX_GALLERY_IMAGES} pictures.`,
83
+ slideOutsideCarousel: "Slides can only go inside a Carousel.",
84
+ onlySlides: "A carousel can only hold slides.",
85
+ tooManySlides: `A carousel can hold up to ${MAX_CAROUSEL_SLIDES} slides.`,
86
+ itemOutsidePriceList: "Price list items can only go inside a Price list.",
87
+ onlyPriceItems: "A price list can only hold price list items.",
88
+ tooManyPriceItems: `A price list can hold up to ${MAX_PRICE_ITEMS} items.`,
89
+ shareOutsideButtons: "Share links can only go inside Share buttons.",
90
+ onlyShareLinks: "Share buttons can only hold share links.",
91
+ tooManyShareLinks: `Share buttons can hold up to ${MAX_SHARE_LINKS} links.`,
92
+ hotspotOutsidePicture: "Hotspots can only go inside a Hotspots picture.",
93
+ onlyHotspots: "A Hotspots picture can only hold hotspots.",
94
+ tooManyHotspots: `A Hotspots picture can hold up to ${MAX_HOTSPOTS} markers.`,
67
95
  emptyOutsideLoop: "An Empty state can only go inside a Loop.",
68
96
  } as const;
69
97
 
@@ -143,6 +171,38 @@ export function parentChildRefusal(
143
171
  return REASONS.itemOutsideMenu;
144
172
  }
145
173
  if (parent.type === "menu" && child.type !== "menu-item") return REASONS.onlyMenuItems;
174
+ if (child.type === "social-link" && parent.type !== "social-icons") {
175
+ return REASONS.linkOutsideSocial;
176
+ }
177
+ if (parent.type === "social-icons" && child.type !== "social-link") {
178
+ return REASONS.onlySocialLinks;
179
+ }
180
+ if (child.type === "gallery-image" && parent.type !== "gallery") {
181
+ return REASONS.imageOutsideGallery;
182
+ }
183
+ if (parent.type === "gallery" && child.type !== "gallery-image") {
184
+ return REASONS.onlyGalleryImages;
185
+ }
186
+ if (child.type === "carousel-slide" && parent.type !== "carousel") {
187
+ return REASONS.slideOutsideCarousel;
188
+ }
189
+ if (parent.type === "carousel" && child.type !== "carousel-slide") return REASONS.onlySlides;
190
+ if (child.type === "price-list-item" && parent.type !== "price-list") {
191
+ return REASONS.itemOutsidePriceList;
192
+ }
193
+ if (parent.type === "price-list" && child.type !== "price-list-item") {
194
+ return REASONS.onlyPriceItems;
195
+ }
196
+ if (child.type === "share-link" && parent.type !== "share-buttons") {
197
+ return REASONS.shareOutsideButtons;
198
+ }
199
+ if (parent.type === "share-buttons" && child.type !== "share-link") {
200
+ return REASONS.onlyShareLinks;
201
+ }
202
+ if (child.type === "hotspot" && parent.type !== "hotspots") {
203
+ return REASONS.hotspotOutsidePicture;
204
+ }
205
+ if (parent.type === "hotspots" && child.type !== "hotspot") return REASONS.onlyHotspots;
146
206
  if (isFormNode(child) && inForm) return REASONS.nestedForm;
147
207
  if (isFormFieldType(child.type) && !inForm) return REASONS.fieldOutsideForm;
148
208
  return undefined;
@@ -159,6 +219,54 @@ const DROP_RULES: [breaks: (drop: Drop) => boolean, reason: string][] = [
159
219
  nodeChildren(into.node).length >= MAX_TABS,
160
220
  REASONS.tooManyTabs,
161
221
  ],
222
+ // W-1024: as Tabs, a full Social icons takes no new link; moving within it is fine.
223
+ [
224
+ ({ node, into }) =>
225
+ into.node.type === "social-icons" &&
226
+ !nodeChildren(into.node).some((child) => child.id === node.id) &&
227
+ nodeChildren(into.node).length >= MAX_SOCIAL_LINKS,
228
+ REASONS.tooManySocialLinks,
229
+ ],
230
+ // W-1019: a full Gallery takes no new picture; moving within it is fine.
231
+ [
232
+ ({ node, into }) =>
233
+ into.node.type === "gallery" &&
234
+ !nodeChildren(into.node).some((child) => child.id === node.id) &&
235
+ nodeChildren(into.node).length >= MAX_GALLERY_IMAGES,
236
+ REASONS.tooManyGalleryImages,
237
+ ],
238
+ // W-1018: a full Carousel takes no new slide; moving within it is fine.
239
+ [
240
+ ({ node, into }) =>
241
+ into.node.type === "carousel" &&
242
+ !nodeChildren(into.node).some((child) => child.id === node.id) &&
243
+ nodeChildren(into.node).length >= MAX_CAROUSEL_SLIDES,
244
+ REASONS.tooManySlides,
245
+ ],
246
+ // W-1043: a full Price list takes no new item; moving within it is fine.
247
+ [
248
+ ({ node, into }) =>
249
+ into.node.type === "price-list" &&
250
+ !nodeChildren(into.node).some((child) => child.id === node.id) &&
251
+ nodeChildren(into.node).length >= MAX_PRICE_ITEMS,
252
+ REASONS.tooManyPriceItems,
253
+ ],
254
+ // W-1047: a full Share buttons takes no new link; moving within it is fine.
255
+ [
256
+ ({ node, into }) =>
257
+ into.node.type === "share-buttons" &&
258
+ !nodeChildren(into.node).some((child) => child.id === node.id) &&
259
+ nodeChildren(into.node).length >= MAX_SHARE_LINKS,
260
+ REASONS.tooManyShareLinks,
261
+ ],
262
+ // W-1048: a full Hotspots picture takes no new marker; moving within it is fine.
263
+ [
264
+ ({ node, into }) =>
265
+ into.node.type === "hotspots" &&
266
+ !nodeChildren(into.node).some((child) => child.id === node.id) &&
267
+ nodeChildren(into.node).length >= MAX_HOTSPOTS,
268
+ REASONS.tooManyHotspots,
269
+ ],
162
270
  [({ node, into }) => into.depth + height(node) > MAX_DEPTH, REASONS.tooDeep],
163
271
  [
164
272
  ({ 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
  }
@@ -18,3 +18,31 @@ export function canvasCollectionSlugs(input: unknown): string[] {
18
18
  }
19
19
  return out;
20
20
  }
21
+
22
+ /**
23
+ * W-1036 (S-08, render side): the running site's list, set when the plugin starts and read when
24
+ * `resolveEmVBPage` renders a host collection. Kept on globalThis like core/geo-trust.ts. Unset
25
+ * (the plugin never started in this process, as in unit tests) means "unknown", never "unlisted".
26
+ */
27
+ const KEY = Symbol.for("emvb.canvasCollections");
28
+ const WARNED = Symbol.for("emvb.canvasCollectionsWarned");
29
+
30
+ type Holder = { [KEY]?: readonly string[]; [WARNED]?: Set<string> };
31
+
32
+ export function setCanvasCollections(input: unknown): void {
33
+ (globalThis as Holder)[KEY] = canvasCollectionSlugs(input);
34
+ }
35
+
36
+ /**
37
+ * True the first time a layout from `collection` renders while the site's `canvasCollections`
38
+ * leaves it out: the caller logs one warning per collection and process (1.3; 2.0 refuses).
39
+ */
40
+ export function unlistedCanvasCollectionFirstSeen(collection: string): boolean {
41
+ const holder = globalThis as Holder;
42
+ const listed = holder[KEY];
43
+ if (listed === undefined || listed.includes(collection) || OWN.has(collection)) return false;
44
+ const warned = (holder[WARNED] ??= new Set());
45
+ if (warned.has(collection)) return false;
46
+ warned.add(collection);
47
+ return true;
48
+ }
@@ -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,15 @@
1
+ /**
2
+ * W-1038: how a Counter writes its number. Shared by the renderer and the opt-in counter runtime,
3
+ * so the count-up ends on exactly the text the page was rendered with.
4
+ */
5
+
6
+ /** `value` with `decimals` digits after a "." and `separator` between thousands. */
7
+ export function formatCounter(value: number, decimals = 0, separator = ""): string {
8
+ const fixed = Math.abs(value).toFixed(decimals);
9
+ const [whole = "0", fraction] = fixed.split(".");
10
+ const grouped = separator ? whole.replace(/\B(?=(\d{3})+(?!\d))/g, separator) : whole;
11
+ // With "." between thousands, the decimal mark is ",", as people write it.
12
+ const mark = separator === "." ? "," : ".";
13
+ const sign = value < 0 && Number(fixed) !== 0 ? "-" : "";
14
+ return `${sign}${grouped}${fraction === undefined ? "" : `${mark}${fraction}`}`;
15
+ }
@@ -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
+ }