@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
@@ -0,0 +1,9 @@
1
+ /** W-1068: a template node as stored: layout JSON whose styles may hold `tpl-*` references. */
2
+ export type TemplateData = {
3
+ id: string;
4
+ type: string;
5
+ props: Record<string, unknown>;
6
+ style?: Record<string, unknown>;
7
+ classes?: string[];
8
+ children?: TemplateData[];
9
+ };
@@ -364,15 +364,18 @@ export function collectCollectionLoops(layout: Layout): CollectionLoop[] {
364
364
  return loops;
365
365
  }
366
366
 
367
- /** Collect `section.partId` values so hosts can load Section templates. */
367
+ /**
368
+ * Collect `section.partId` values so hosts can load Section templates. W-1069: and the Section
369
+ * parts mega menu items show (`menu-item` `panelPartId`).
370
+ */
368
371
  export function collectSectionPartIds(layout: Layout): string[] {
369
372
  const ids = new Set<string>();
370
373
  const walk = (node: LayoutNode): void => {
371
- if (node.type === "part-ref") {
372
- const id =
373
- typeof (node.props as { partId?: unknown }).partId === "string"
374
- ? (node.props as { partId: string }).partId.trim()
375
- : "";
374
+ const key =
375
+ node.type === "part-ref" ? "partId" : node.type === "menu-item" ? "panelPartId" : undefined;
376
+ if (key) {
377
+ const value = (node.props as Record<string, unknown>)[key];
378
+ const id = typeof value === "string" ? value.trim() : "";
376
379
  if (id) ids.add(id);
377
380
  }
378
381
  };
@@ -0,0 +1,88 @@
1
+ /**
2
+ * W-1090 (#32): reading an EmDash image field's value. EmDash's admin stores a local upload as
3
+ * `{ id, provider: "local", meta: { storageKey }, mimeType }` with no `src`, and builds its URL
4
+ * at render time, so a reader that only looked at `src` found no image at all.
5
+ */
6
+
7
+ /** EmDash's own route for local media files (its `INTERNAL_MEDIA_PREFIX`). */
8
+ const LOCAL_MEDIA = "/_emdash/api/media/file/";
9
+ /** The field EmVB has always read when a Loop names none. */
10
+ export const DEFAULT_IMAGE_FIELD = "featured_image";
11
+ const IMAGE_PATH = /\.(?:avif|gif|jpe?g|png|svg|webp)(?:[?#]|$)/i;
12
+
13
+ type MediaLike = {
14
+ id?: unknown;
15
+ provider?: unknown;
16
+ src?: unknown;
17
+ url?: unknown;
18
+ previewUrl?: unknown;
19
+ mimeType?: unknown;
20
+ meta?: unknown;
21
+ };
22
+
23
+ const text = (value: unknown): string | undefined =>
24
+ typeof value === "string" && value.trim() ? value.trim() : undefined;
25
+
26
+ /** A storage key as a path under the media route, or undefined for one that leaves it. */
27
+ function keyPath(key: string): string | undefined {
28
+ const segments = key.split("/");
29
+ if (segments.some((s) => s === "" || s === "." || s === "..")) return undefined;
30
+ return segments.map(encodeURIComponent).join("/");
31
+ }
32
+
33
+ /** The URL an EmDash media value points at: its own URL, else a local file's route. */
34
+ export function mediaUrlOf(value: unknown): string | undefined {
35
+ if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
36
+ const media = value as MediaLike;
37
+ const direct = text(media.src) ?? text(media.url) ?? text(media.previewUrl);
38
+ if (direct) return direct;
39
+ const provider = text(media.provider);
40
+ if (provider && provider !== "local") return undefined;
41
+ const meta = media.meta && typeof media.meta === "object" ? (media.meta as MediaLike) : {};
42
+ const storageKey = text((meta as { storageKey?: unknown }).storageKey);
43
+ const path = storageKey ? keyPath(storageKey) : undefined;
44
+ if (path) return `${LOCAL_MEDIA}${path}`;
45
+ // As EmDash's own image component: a local item without a storage key goes by its id.
46
+ const id = text(media.id);
47
+ return id ? `${LOCAL_MEDIA}${encodeURIComponent(id)}` : undefined;
48
+ }
49
+
50
+ /** True for an image field's value: a media value with an image type or an image file name. */
51
+ export function isImageValue(value: unknown): boolean {
52
+ const url = mediaUrlOf(value);
53
+ if (!url) return false;
54
+ const mimeType = text((value as MediaLike).mimeType);
55
+ if (mimeType) return mimeType.toLowerCase().startsWith("image/");
56
+ return IMAGE_PATH.test(url) || url.startsWith(LOCAL_MEDIA);
57
+ }
58
+
59
+ /**
60
+ * The image an entry shows when its Loop or post names no field: `featured_image` when it has
61
+ * one, else the entry's first field holding an image (the collection's first image field).
62
+ */
63
+ export function automaticImageField(data: Record<string, unknown>): string | undefined {
64
+ if (isImageValue(data[DEFAULT_IMAGE_FIELD])) return DEFAULT_IMAGE_FIELD;
65
+ return Object.keys(data).find((key) => isImageValue(data[key]));
66
+ }
67
+
68
+ /** The image value an entry shows: the named field's, or the automatic one's. */
69
+ export function entryImageValue(data: Record<string, unknown>, field?: string): unknown {
70
+ if (field) return data[field];
71
+ const auto = automaticImageField(data);
72
+ return auto ? data[auto] : undefined;
73
+ }
74
+
75
+ /**
76
+ * The image fields a collection's schema lists, for the editor's picker: `featured_image` first
77
+ * when it is one, as the automatic choice reads it first.
78
+ */
79
+ export function imageFieldsOf(
80
+ fields: readonly { slug: string; type: string; label?: string | null }[],
81
+ ): { slug: string; label: string }[] {
82
+ const images = fields
83
+ .filter((f) => f.type === "image")
84
+ .map((f) => ({ slug: f.slug, label: f.label?.trim() || f.slug }));
85
+ const preferred = images.findIndex((f) => f.slug === DEFAULT_IMAGE_FIELD);
86
+ if (preferred > 0) images.unshift(...images.splice(preferred, 1));
87
+ return images;
88
+ }
@@ -5,7 +5,9 @@ import type { TriggersDoc } from "./triggers.ts";
5
5
  /**
6
6
  * Minimal chrome styles for public popups (loaded only when popups match). W-758: the close
7
7
  * button sticks to the top of a long popup (it scrolled away with the content on phones) and
8
- * floats, so a long heading wraps beside it instead of running under it.
8
+ * floats, so a long heading wraps beside it instead of running under it. Panels (W-1071) sit at
9
+ * their edge by physical auto margins: flex-start and flex-end follow `dir`, so on a right-to-left
10
+ * site a left panel opened at the right while its slide came from the left.
9
11
  */
10
12
  export const POPUP_CHROME_CSS = `
11
13
  .emvb-popup{position:fixed;inset:0;z-index:10000;display:flex;align-items:center;justify-content:center;padding:1.5rem;box-sizing:border-box}
@@ -15,6 +17,16 @@ export const POPUP_CHROME_CSS = `
15
17
  .emvb-popup__close{position:sticky;top:-1rem;z-index:1;float:right;margin:-1rem -1rem 0 .5rem;width:2rem;height:2rem;border:0;border-radius:999px;background:inherit;color:inherit;font-size:1.5rem;line-height:1;cursor:pointer}
16
18
  .emvb-popup__close:focus-visible{outline:2px solid #2563eb;outline-offset:2px}
17
19
  .emvb-popup__content{min-width:12rem}
20
+ .emvb-popup--panel{padding:0;justify-content:flex-start}
21
+ .emvb-popup--right{justify-content:flex-end}
22
+ .emvb-popup--left .emvb-popup__dialog{margin-right:auto}
23
+ .emvb-popup--right .emvb-popup__dialog{margin-left:auto}
24
+ .emvb-popup--panel .emvb-popup__dialog{box-sizing:border-box;width:min(var(--emvb-panel-w,24rem),calc(100vw - 3rem));max-width:none;height:100%;max-height:none;border-radius:0}
25
+ .emvb-popup--narrow{--emvb-panel-w:20rem}
26
+ .emvb-popup--wide{--emvb-panel-w:32rem}
27
+ @media (prefers-reduced-motion:no-preference){.emvb-popup--left .emvb-popup__dialog{animation:emvb-panel-left .25s ease-out}.emvb-popup--right .emvb-popup__dialog{animation:emvb-panel-right .25s ease-out}}
28
+ @keyframes emvb-panel-left{from{translate:-100% 0}}
29
+ @keyframes emvb-panel-right{from{translate:100% 0}}
18
30
  `
19
31
  .replace(/\n+/g, "")
20
32
  .trim();
@@ -46,8 +58,15 @@ export function wrapPopupMarkup(
46
58
  const configJson = escapeAttr(JSON.stringify(config));
47
59
  const safeId = escapeAttr(id);
48
60
  const titleId = `emvb-popup-title-${safeId}`;
61
+ // W-1071: an off-canvas panel is the same dialog, laid out at an edge.
62
+ const panel = triggers.panel;
63
+ const kind = panel
64
+ ? ` emvb-popup--panel emvb-popup--${panel.edge === "right" ? "right" : "left"}${
65
+ panel.size === "narrow" || panel.size === "wide" ? ` emvb-popup--${panel.size}` : ""
66
+ }`
67
+ : "";
49
68
  return [
50
- `<div class="emvb-popup" id="emvb-popup-${safeId}" data-emvb-popup="${safeId}" data-emvb-popup-config="${configJson}" hidden>`,
69
+ `<div class="emvb-popup${kind}" id="emvb-popup-${safeId}" data-emvb-popup="${safeId}" data-emvb-popup-config="${configJson}" hidden>`,
51
70
  `<div class="emvb-popup__backdrop" data-emvb-popup-dismiss tabindex="-1"></div>`,
52
71
  // W-282: named "Popup" until the runtime points the name at the content's first heading;
53
72
  // naming it after the whole content read every word as the dialog's name.
@@ -98,3 +98,39 @@ export function withinShowTimes(
98
98
  if (limit === null || limit === undefined) return true;
99
99
  return timesShown < limit;
100
100
  }
101
+
102
+ /** W-1081: a query parameter name a URL rule can test. */
103
+ export const URL_PARAM_NAME = /^[A-Za-z0-9_.\-[\]]{1,64}$/;
104
+ export const MAX_URL_PARAM_RULES = 5;
105
+
106
+ export type UrlParamRule = { name: string; value?: string | undefined; absent?: true | undefined };
107
+
108
+ /**
109
+ * W-1081: true when every URL rule holds for the page address's query (`location.search`);
110
+ * no rules always hold.
111
+ */
112
+ export function matchesUrlParams(
113
+ advanced: { urlParams?: readonly UrlParamRule[] | null | undefined } | undefined,
114
+ search: string,
115
+ ): boolean {
116
+ const rules = advanced?.urlParams;
117
+ if (!rules || rules.length === 0) return true;
118
+ const params = new URLSearchParams(search);
119
+ return rules.every((rule) => {
120
+ const values = params.getAll(rule.name);
121
+ const has = rule.value === undefined ? values.length > 0 : values.includes(rule.value);
122
+ return rule.absent ? !has : has;
123
+ });
124
+ }
125
+
126
+ /** W-1081: true from `from` (inclusive) until `until` (exclusive); unset ends are open. */
127
+ export function withinShowDates(
128
+ advanced: { from?: string | null | undefined; until?: string | null | undefined } | undefined,
129
+ now: number,
130
+ ): boolean {
131
+ const from = advanced?.from ? Date.parse(advanced.from) : Number.NaN;
132
+ const until = advanced?.until ? Date.parse(advanced.until) : Number.NaN;
133
+ if (!Number.isNaN(from) && now < from) return false;
134
+ if (!Number.isNaN(until) && now >= until) return false;
135
+ return true;
136
+ }
@@ -1,14 +1,20 @@
1
1
  import { boundedArray } from "../bounded-array.ts";
2
2
  import { z } from "zod";
3
3
  import { parseDoc } from "./parse-doc.ts";
4
- import { POPUP_DEVICES, TRIGGER_LIMITS } from "./popup-rules.ts";
4
+ import { COUNTDOWN_TARGET } from "../schema/layout.ts";
5
+ import {
6
+ MAX_URL_PARAM_RULES,
7
+ POPUP_DEVICES,
8
+ TRIGGER_LIMITS,
9
+ URL_PARAM_NAME,
10
+ } from "./popup-rules.ts";
5
11
 
6
12
  export const TRIGGERS_SCHEMA_VERSION = 1;
7
13
  export const MAX_POPUP_TRIGGERS = 8;
8
14
  const MAX_CLICK_SELECTOR_LENGTH = TRIGGER_LIMITS.maxClickSelectorLength;
9
15
  const MAX_SHOW_TIMES = 100;
10
16
 
11
- /** Open triggers (Elementor-inspired). URL rules / scheduling / A/B deferred (W-081). */
17
+ /** Open triggers (Elementor-inspired). A/B stays deferred (W-081). */
12
18
  const PageLoadTrigger = z.strictObject({ type: z.literal("page_load") });
13
19
  const DelayTrigger = z.strictObject({
14
20
  type: z.literal("delay"),
@@ -45,17 +51,70 @@ const DeviceSchema = z.enum(POPUP_DEVICES);
45
51
  * Advanced rules — MVP-thin (D-TB-11).
46
52
  * `showTimes` null = unlimited; `devices` null/empty = all devices.
47
53
  */
48
- const AdvancedRulesSchema = z.strictObject({
49
- showTimes: z.number().int().min(1).max(MAX_SHOW_TIMES).nullable().optional(),
50
- devices: boundedArray(DeviceSchema, 3).nullable().optional(),
54
+ /**
55
+ * W-1081: one rule on the page address's query. With `value`, the parameter has that value;
56
+ * without, it is there at all. `absent` turns the rule round: the parameter (or that value) isn't.
57
+ */
58
+ const UrlParamRuleSchema = z.strictObject({
59
+ name: z.string().regex(URL_PARAM_NAME, "Use letters, digits, - _ . [ or ] (up to 64)"),
60
+ value: z.string().max(200).optional(),
61
+ absent: z.literal(true).optional(),
51
62
  });
52
63
 
64
+ /** W-1081: a date and time with its UTC offset, as for a Countdown. */
65
+ const ShowDate = z
66
+ .string()
67
+ .regex(COUNTDOWN_TARGET, "Use a date, time and UTC offset such as 2026-12-01T09:00-05:00")
68
+ .refine(onTheCalendar, "This date doesn't exist");
69
+
70
+ /**
71
+ * W-1081: the day exists in its month. `Date.parse` rolls 30 February over to 2 March in Bun and
72
+ * Node, so it can't tell. (A Countdown's target keeps its looser check: tightening it would
73
+ * refuse pages saved by 1.3, D-065.)
74
+ */
75
+ function onTheCalendar(value: string): boolean {
76
+ const match = COUNTDOWN_TARGET.exec(value);
77
+ if (!match) return false;
78
+ const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])];
79
+ return day <= new Date(Date.UTC(year, month, 0)).getUTCDate();
80
+ }
81
+
82
+ const AdvancedRulesSchema = z
83
+ .strictObject({
84
+ showTimes: z.number().int().min(1).max(MAX_SHOW_TIMES).nullable().optional(),
85
+ devices: boundedArray(DeviceSchema, 3).nullable().optional(),
86
+ urlParams: boundedArray(UrlParamRuleSchema, MAX_URL_PARAM_RULES).nullable().optional(),
87
+ /** W-1081: shown from this moment on. */
88
+ from: ShowDate.nullable().optional(),
89
+ /** W-1081: no longer shown from this moment. */
90
+ until: ShowDate.nullable().optional(),
91
+ })
92
+ .refine((a) => !a.from || !a.until || Date.parse(a.until) > Date.parse(a.from), {
93
+ message: "The end must come after the start.",
94
+ path: ["until"],
95
+ });
96
+
53
97
  export type PopupAdvancedRules = z.infer<typeof AdvancedRulesSchema>;
54
98
 
99
+ /** W-1071: the edges an off-canvas panel slides in from, and its widths. */
100
+ const PANEL_EDGES = ["left", "right"] as const;
101
+ export const PANEL_SIZES = ["narrow", "medium", "wide"] as const;
102
+
103
+ /**
104
+ * W-1071: shows the popup as an off-canvas panel: full height at the `edge`, sliding in (not for
105
+ * reduced motion), `size` narrow 20rem, medium 24rem (unset) or wide 32rem, never wider than the
106
+ * screen less 3rem. Unset: a centred popup.
107
+ */
108
+ const PanelSchema = z.strictObject({
109
+ edge: z.enum(PANEL_EDGES),
110
+ size: z.enum(PANEL_SIZES).optional(),
111
+ });
112
+
55
113
  const TriggersDocSchema = z.strictObject({
56
114
  schemaVersion: z.literal(TRIGGERS_SCHEMA_VERSION),
57
115
  open: boundedArray(PopupOpenTriggerSchema, MAX_POPUP_TRIGGERS, 1),
58
116
  advanced: AdvancedRulesSchema.default({}),
117
+ panel: PanelSchema.optional(),
59
118
  });
60
119
 
61
120
  export type TriggersDoc = z.infer<typeof TriggersDocSchema>;
@@ -2,8 +2,11 @@ import { ELEMENT_DESCRIPTORS } from "./elements/index.ts";
2
2
  import type { Layout, LayoutNode } from "./schema/layout.ts";
3
3
  import { forEachNode } from "./tree-ops.ts";
4
4
 
5
- /** Text fields that name things rather than say things: never offered for translation. */
6
- const NOT_TEXT = new Set(["formId", "field"]);
5
+ /**
6
+ * Text fields that name things rather than say things: never offered for translation. A Search
7
+ * form's `action` is an address (W-1073); a translated page sets its own by hand.
8
+ */
9
+ const NOT_TEXT = new Set(["formId", "field", "action"]);
7
10
 
8
11
  export type TranslatableString = { nodeId: string; key: string; text: string };
9
12
 
@@ -0,0 +1,91 @@
1
+ /**
2
+ * W-1092 (#34): when EmVB may set the `emvb_seen` cookie that new/returning Visitors rules use.
3
+ * Set from `emvb({ visitorCookie, visitorCookieConsent })` when the plugin starts; read when a
4
+ * page with such a rule renders. Kept on globalThis for the same reason as the geo-header setting
5
+ * (core/geo-trust.ts): the plugin and the page renderer can load this module twice.
6
+ *
7
+ * - `"always"` (default, as before 1.4.1): set it on a first visit to a page with such a rule.
8
+ * - `"consent"`: only when the request carries the site's own consent cookie with an accepted
9
+ * value. Without consent, EmVB neither reads nor sets it and everyone counts as new.
10
+ * - `"never"`: never read or set; everyone counts as new.
11
+ */
12
+ export type VisitorCookieMode = "always" | "consent" | "never";
13
+
14
+ /** The first-party cookie a site's consent banner sets, and the value(s) that mean "yes". */
15
+ export type VisitorCookieConsent = { cookie: string; value?: string | string[] };
16
+
17
+ export type VisitorCookieSetting = {
18
+ mode: VisitorCookieMode;
19
+ /** Only in "consent" mode; without a valid one, "consent" behaves as "never". */
20
+ consent?: { cookie: string; values: string[] };
21
+ };
22
+
23
+ /** Values that count as consent when the site doesn't name its own (compared case-insensitively). */
24
+ const DEFAULT_CONSENT_VALUES = new Set(["1", "true", "yes", "granted", "accepted", "allow", "all"]);
25
+
26
+ /** A cookie name (an RFC 6265 token), as a site owner would type it. */
27
+ const COOKIE_NAME = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]{1,128}$/;
28
+ const MAX_VALUES = 20;
29
+ const MAX_VALUE_LENGTH = 256;
30
+
31
+ const KEY = Symbol.for("emvb.visitorCookie");
32
+ type Holder = { [KEY]?: VisitorCookieSetting };
33
+
34
+ /** The setting from the two options; anything unrecognised falls back to the safe reading. */
35
+ export function visitorCookieSetting(mode: unknown, consent?: unknown): VisitorCookieSetting {
36
+ if (mode === "never") return { mode: "never" };
37
+ if (mode !== "consent") return { mode: "always" };
38
+ const parsed = consentOption(consent);
39
+ return parsed ? { mode: "consent", consent: parsed } : { mode: "never" };
40
+ }
41
+
42
+ function consentOption(input: unknown): VisitorCookieSetting["consent"] {
43
+ if (!input || typeof input !== "object") return undefined;
44
+ const { cookie, value } = input as { cookie?: unknown; value?: unknown };
45
+ if (typeof cookie !== "string" || !COOKIE_NAME.test(cookie.trim())) return undefined;
46
+ const given = (Array.isArray(value) ? value : [value])
47
+ .filter((v): v is string => typeof v === "string")
48
+ .filter((v) => v.length > 0 && v.length <= MAX_VALUE_LENGTH)
49
+ .slice(0, MAX_VALUES);
50
+ if (value !== undefined && given.length === 0) return undefined;
51
+ return { cookie: cookie.trim(), values: value === undefined ? [] : given };
52
+ }
53
+
54
+ /** The options as `emvb()` passes them to the plugin: only what was set, and only when valid. */
55
+ export function visitorCookieOptions(
56
+ mode: unknown,
57
+ consent: unknown,
58
+ ): { visitorCookie?: VisitorCookieMode; visitorCookieConsent?: VisitorCookieConsent } {
59
+ if (mode !== "always" && mode !== "consent" && mode !== "never") return {};
60
+ const setting = visitorCookieSetting(mode, consent);
61
+ if (setting.mode !== "consent" || !setting.consent) return { visitorCookie: setting.mode };
62
+ const { cookie, values } = setting.consent;
63
+ return {
64
+ visitorCookie: "consent",
65
+ visitorCookieConsent: values.length > 0 ? { cookie, value: values } : { cookie },
66
+ };
67
+ }
68
+
69
+ export function setVisitorCookie(mode: unknown, consent?: unknown): void {
70
+ (globalThis as Holder)[KEY] = visitorCookieSetting(mode, consent);
71
+ }
72
+
73
+ export function visitorCookie(): VisitorCookieSetting {
74
+ return (globalThis as Holder)[KEY] ?? { mode: "always" };
75
+ }
76
+
77
+ /**
78
+ * Whether this request may read and set `emvb_seen`. `readCookie` returns a cookie as the
79
+ * browser sent it. The site's named values match exactly; the defaults ignore case.
80
+ */
81
+ export function visitorCookieAllowed(
82
+ setting: VisitorCookieSetting,
83
+ readCookie: (name: string) => string | undefined,
84
+ ): boolean {
85
+ if (setting.mode === "always") return true;
86
+ if (setting.mode === "never" || !setting.consent) return false;
87
+ const sent = readCookie(setting.consent.cookie);
88
+ if (sent === undefined) return false;
89
+ if (setting.consent.values.length > 0) return setting.consent.values.includes(sent);
90
+ return DEFAULT_CONSENT_VALUES.has(sent.trim().toLowerCase());
91
+ }