@perkyzz/emvb 0.2.1 → 0.4.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 (150) hide show
  1. package/README.md +4 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +3 -1
  4. package/src/admin/access/role.ts +9 -3
  5. package/src/admin/api.ts +17 -7
  6. package/src/admin/content-api.ts +7 -51
  7. package/src/admin/content-item.ts +22 -0
  8. package/src/admin/design-api.ts +30 -0
  9. package/src/admin/editor/A11yCopilot.tsx +126 -0
  10. package/src/admin/editor/CommandPalette.tsx +118 -0
  11. package/src/admin/editor/Editor.tsx +188 -152
  12. package/src/admin/editor/EditorOverlay.tsx +9 -1
  13. package/src/admin/editor/PerfMeter.tsx +121 -0
  14. package/src/admin/editor/ShareLink.tsx +164 -0
  15. package/src/admin/editor/ShortcutsDialog.tsx +4 -1
  16. package/src/admin/editor/Timeline.tsx +287 -0
  17. package/src/admin/editor/TopBar.tsx +4 -0
  18. package/src/admin/editor/canvas/CanvasFrame.tsx +62 -370
  19. package/src/admin/editor/canvas/DeviceBar.tsx +4 -1
  20. package/src/admin/editor/canvas/SelectionOverlay.tsx +87 -47
  21. package/src/admin/editor/canvas/canvas-scale.ts +20 -0
  22. package/src/admin/editor/canvas/drop-line.ts +24 -0
  23. package/src/admin/editor/canvas/use-canvas-dnd.ts +207 -0
  24. package/src/admin/editor/canvas/use-canvas-session.ts +216 -0
  25. package/src/admin/editor/collection-previews.ts +114 -0
  26. package/src/admin/editor/editor-chrome.tsx +346 -0
  27. package/src/admin/editor/editor-commands.ts +360 -0
  28. package/src/admin/editor/editor-css.ts +5 -3
  29. package/src/admin/editor/element-chrome.ts +89 -0
  30. package/src/admin/editor/feature-css.ts +105 -0
  31. package/src/admin/editor/host.ts +35 -0
  32. package/src/admin/editor/icons/IconLibraryDialog.tsx +64 -218
  33. package/src/admin/editor/icons/library.ts +29 -19
  34. package/src/admin/editor/icons/use-icon-library.ts +315 -0
  35. package/src/admin/editor/live-data.tsx +71 -0
  36. package/src/admin/editor/palette-items.ts +136 -0
  37. package/src/admin/editor/palette.ts +68 -0
  38. package/src/admin/editor/panels/AddPanel.tsx +48 -68
  39. package/src/admin/editor/panels/ClassesSection.tsx +5 -1
  40. package/src/admin/editor/panels/ColorControl.tsx +2 -10
  41. package/src/admin/editor/panels/ElementPanel.tsx +74 -102
  42. package/src/admin/editor/panels/LayersPanel.tsx +72 -63
  43. package/src/admin/editor/panels/LeftPanel.tsx +4 -1
  44. package/src/admin/editor/panels/SettingsPanel.tsx +13 -0
  45. package/src/admin/editor/panels/SiteStylesDrawer.tsx +18 -10
  46. package/src/admin/editor/panels/TokenScales.tsx +168 -0
  47. package/src/admin/editor/panels/VariableSection.tsx +10 -14
  48. package/src/admin/editor/panels/inline-error.tsx +11 -0
  49. package/src/admin/editor/panels/settings/AdvancedFields.tsx +87 -1
  50. package/src/admin/editor/panels/settings/AudienceEditor.tsx +285 -0
  51. package/src/admin/editor/panels/settings/BindingsEditor.tsx +221 -0
  52. package/src/admin/editor/panels/settings/ClassChipInput.tsx +1 -1
  53. package/src/admin/editor/panels/settings/DraftTextField.tsx +4 -0
  54. package/src/admin/editor/panels/settings/EffectsControls.tsx +2 -2
  55. package/src/admin/editor/panels/settings/FormBindControl.tsx +8 -4
  56. package/src/admin/editor/panels/settings/ItemList.tsx +34 -1
  57. package/src/admin/editor/panels/settings/MotionControl.tsx +252 -0
  58. package/src/admin/editor/panels/settings/StateSwitcher.tsx +1 -1
  59. package/src/admin/editor/panels/settings/StyleRow.tsx +26 -2
  60. package/src/admin/editor/panels/settings/StyleSources.tsx +94 -0
  61. package/src/admin/editor/panels/settings/VariableBinding.tsx +1 -1
  62. package/src/admin/editor/panels/settings/VariantEditor.tsx +83 -0
  63. package/src/admin/editor/panels/settings/form-names.ts +7 -11
  64. package/src/admin/editor/panels/settings/length-units.ts +16 -5
  65. package/src/admin/editor/panels/settings/style-sections.ts +7 -2
  66. package/src/admin/editor/panels/style-target.ts +105 -0
  67. package/src/admin/editor/section-templates.ts +43 -21
  68. package/src/admin/editor/shortcuts.ts +6 -1
  69. package/src/admin/editor/store.ts +10 -1
  70. package/src/admin/editor/useClipboardActions.ts +1 -1
  71. package/src/admin/editor/useEditorCommands.ts +61 -13
  72. package/src/admin/editor/useEditorData.ts +7 -1
  73. package/src/admin/editor/useEditorShortcuts.ts +30 -14
  74. package/src/admin/editor/useNodeActions.ts +44 -16
  75. package/src/admin/forms-api.ts +17 -6
  76. package/src/admin/icon-uploads-api.ts +18 -0
  77. package/src/admin/theme-api.ts +5 -18
  78. package/src/admin/ui.ts +4 -4
  79. package/src/astro/content-port.ts +24 -0
  80. package/src/astro/forms/EmVBFormsClient.astro +11 -0
  81. package/src/astro/forms/EmVBFormsRuntime.astro +6 -7
  82. package/src/astro/forms/client.ts +1 -0
  83. package/src/astro/forms-definitions.ts +24 -11
  84. package/src/astro/index.ts +1 -0
  85. package/src/astro/render-session.ts +85 -0
  86. package/src/astro/request-data.ts +109 -0
  87. package/src/astro/resolve-theme.ts +184 -64
  88. package/src/astro/resolve.ts +63 -16
  89. package/src/astro/theme-posts.ts +48 -5
  90. package/src/astro/visitor.ts +204 -0
  91. package/src/constants.ts +1 -1
  92. package/src/core/a11y/audit.ts +282 -0
  93. package/src/core/arrange.ts +150 -34
  94. package/src/core/audience/rules.ts +124 -0
  95. package/src/core/audience/variants.ts +51 -0
  96. package/src/core/canvas-styles.ts +24 -0
  97. package/src/core/clipboard.ts +11 -32
  98. package/src/core/css/generate.ts +29 -2
  99. package/src/core/css/print.ts +12 -0
  100. package/src/core/css/scope.ts +3 -3
  101. package/src/core/css/trace.ts +169 -0
  102. package/src/core/css-keywords.ts +83 -0
  103. package/src/core/data/bindings.ts +255 -0
  104. package/src/core/design/classes.ts +13 -15
  105. package/src/core/design/diff.ts +55 -0
  106. package/src/core/design/merge.ts +127 -0
  107. package/src/core/design/tokens.ts +127 -0
  108. package/src/core/design/variables.ts +25 -21
  109. package/src/core/elements/dynamic-elements.ts +117 -2
  110. package/src/core/elements/form-elements.ts +1 -0
  111. package/src/core/elements/index.ts +185 -7
  112. package/src/core/forms/binding.ts +4 -13
  113. package/src/core/history/diff.ts +152 -0
  114. package/src/core/index.ts +121 -0
  115. package/src/core/local-style.ts +27 -0
  116. package/src/core/migrate/index.ts +12 -4
  117. package/src/core/nesting.ts +4 -22
  118. package/src/core/perf/meter.ts +160 -0
  119. package/src/core/perf/scripts.ts +61 -0
  120. package/src/core/recipes/index.ts +433 -0
  121. package/src/core/record.ts +3 -0
  122. package/src/core/render/context.ts +2 -0
  123. package/src/core/render/dynamic-post.ts +1 -2
  124. package/src/core/render/form.ts +133 -10
  125. package/src/core/render/index.ts +206 -17
  126. package/src/core/render/loop.ts +54 -7
  127. package/src/core/render/pagination.ts +9 -1
  128. package/src/core/render/vnode.ts +12 -2
  129. package/src/core/sanitize/css.ts +129 -80
  130. package/src/core/sanitize/motion.ts +129 -0
  131. package/src/core/sanitize/svg.ts +8 -3
  132. package/src/core/sanitize/url.ts +10 -1
  133. package/src/core/schema/design.ts +29 -8
  134. package/src/core/schema/layout.ts +291 -169
  135. package/src/core/schema/motion.ts +14 -0
  136. package/src/core/schema/style.ts +101 -66
  137. package/src/core/share/link.ts +187 -0
  138. package/src/core/tabs/presence.ts +7 -17
  139. package/src/core/theme/dynamic.ts +242 -32
  140. package/src/core/theme/float.ts +1 -1
  141. package/src/core/theme/pagination.ts +56 -0
  142. package/src/core/tree-ops.ts +57 -0
  143. package/src/index.ts +14 -2
  144. package/src/server/design-routes.ts +4 -1
  145. package/src/server/icon-routes.ts +68 -16
  146. package/src/server/plugin.ts +8 -2
  147. package/src/admin/editor/icons/sets/fontawesome.json +0 -1
  148. package/src/admin/editor/icons/sets/lucide.json +0 -1
  149. package/src/admin/editor/icons/sets/remix.json +0 -1
  150. package/src/admin/editor/icons/sets/tabler.json +0 -1
@@ -1,52 +1,46 @@
1
+ import {
2
+ ALIGN_ITEMS,
3
+ BACKGROUND_POSITIONS,
4
+ BACKGROUND_REPEATS,
5
+ BACKGROUND_SIZES,
6
+ BORDER_STYLES,
7
+ CURSORS,
8
+ FLEX_DIRECTIONS as FLEX_DIRECTION_VALUES,
9
+ FLEX_WRAPS as FLEX_WRAP_VALUES,
10
+ FONT_WEIGHTS,
11
+ HEX_COLOR,
12
+ JUSTIFY_CONTENT,
13
+ LENGTH_UNITS,
14
+ OBJECT_FITS,
15
+ OVERFLOWS,
16
+ POSITIONS,
17
+ TEXT_ALIGNS,
18
+ TEXT_DECORATIONS,
19
+ TEXT_TRANSFORMS,
20
+ TRANSITION_EASINGS as TRANSITION_EASING_VALUES,
21
+ } from "../css-keywords.ts";
1
22
  import { STYLE_STATES, type StyleStateName } from "../schema/state-names.ts";
2
23
  import type { StyleProps } from "../schema/style.ts";
3
24
  import { sanitizeMediaUrl } from "./media-url.ts";
25
+ import { motionDeclarations, withMotion } from "./motion.ts";
26
+ import { isRecord } from "../record.ts";
4
27
 
5
- const HEX_COLOR = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
28
+ const setOf = (values: readonly string[]) => new Set<string>(values);
6
29
  const VAR_ID = /^[a-z0-9-]{1,40}$/;
7
- const UNITS = new Set(["px", "rem", "em", "%", "vw", "vh"]);
8
- const FLEX_DIRECTIONS = new Set(["row", "column", "row-reverse", "column-reverse"]);
9
- const FLEX_WRAPS = new Set(["nowrap", "wrap", "wrap-reverse"]);
10
- const JUSTIFY = new Set([
11
- "flex-start",
12
- "flex-end",
13
- "center",
14
- "space-between",
15
- "space-around",
16
- "space-evenly",
17
- ]);
18
- const ALIGN = new Set(["stretch", "flex-start", "flex-end", "center", "baseline"]);
19
- const TEXT_TRANSFORM = new Set(["none", "uppercase", "lowercase", "capitalize"]);
20
- const TEXT_DECORATION = new Set(["none", "underline", "overline", "line-through"]);
21
- const BORDER_STYLE = new Set(["none", "solid", "dashed", "dotted"]);
22
- const OVERFLOW = new Set(["visible", "hidden", "clip", "scroll", "auto"]);
23
- const OBJECT_FIT = new Set(["fill", "contain", "cover", "none", "scale-down"]);
24
- const POSITION = new Set(["static", "relative", "absolute", "fixed", "sticky"]);
25
- const CURSOR = new Set([
26
- "default",
27
- "pointer",
28
- "text",
29
- "move",
30
- "grab",
31
- "not-allowed",
32
- "help",
33
- "crosshair",
34
- "zoom-in",
35
- ]);
30
+ const UNITS = setOf(LENGTH_UNITS);
31
+ const FLEX_DIRECTIONS = setOf(FLEX_DIRECTION_VALUES);
32
+ const FLEX_WRAPS = setOf(FLEX_WRAP_VALUES);
33
+ const JUSTIFY = setOf(JUSTIFY_CONTENT);
34
+ const ALIGN = setOf(ALIGN_ITEMS);
35
+ const TEXT_TRANSFORM = setOf(TEXT_TRANSFORMS);
36
+ const TEXT_DECORATION = setOf(TEXT_DECORATIONS);
37
+ const BORDER_STYLE = setOf(BORDER_STYLES);
38
+ const OVERFLOW = setOf(OVERFLOWS);
39
+ const OBJECT_FIT = setOf(OBJECT_FITS);
40
+ const POSITION = setOf(POSITIONS);
41
+ const CURSOR = setOf(CURSORS);
36
42
  const ASPECT_RATIO = /^([1-9]\d{0,3})\/([1-9]\d{0,3})$/;
37
- const FONT_WEIGHT = new Set([
38
- "normal",
39
- "bold",
40
- "100",
41
- "200",
42
- "300",
43
- "400",
44
- "500",
45
- "600",
46
- "700",
47
- "800",
48
- "900",
49
- ]);
43
+ const FONT_WEIGHT = setOf(FONT_WEIGHTS);
50
44
  const FORBIDDEN = /[{};<>\\"'`]|\/\*|url\(|expression\(|@import|javascript:/i;
51
45
 
52
46
  /** Last line of defence on every emitted value, even ones built by the typed validators below. */
@@ -191,11 +185,13 @@ function cssEntrance(value: unknown): string | undefined {
191
185
  return `emvb-${type} ${duration}ms ease-out${wait} both`;
192
186
  }
193
187
 
188
+ const TEXT_ALIGN = setOf(TEXT_ALIGNS);
189
+
194
190
  function cssTextAlign(value: unknown): string | undefined {
191
+ if (typeof value !== "string" || !TEXT_ALIGN.has(value)) return undefined;
195
192
  if (value === "left") return "start";
196
193
  if (value === "right") return "end";
197
- if (value === "center" || value === "justify") return value;
198
- return undefined;
194
+ return value;
199
195
  }
200
196
 
201
197
  const cssGridSpan = (value: unknown): string | undefined =>
@@ -203,6 +199,28 @@ const cssGridSpan = (value: unknown): string | undefined =>
203
199
  ? `span ${value}`
204
200
  : undefined;
205
201
 
202
+ const cssGridStart = (value: unknown): number | undefined =>
203
+ Number.isInteger(value) && (value as number) >= 1 && (value as number) <= 13
204
+ ? (value as number)
205
+ : undefined;
206
+
207
+ /** `span N`, a line number, or `start / span N` when both are set. */
208
+ function gridPlacement(
209
+ start: unknown,
210
+ span: unknown,
211
+ ): { value?: string; badStart: boolean; badSpan: boolean } {
212
+ const badStart = start !== undefined && cssGridStart(start) === undefined;
213
+ const badSpan = span !== undefined && cssGridSpan(span) === undefined;
214
+ const line = cssGridStart(start);
215
+ const across = cssGridSpan(span);
216
+ if (line !== undefined && across !== undefined) {
217
+ return { value: `${line} / ${across}`, badStart, badSpan };
218
+ }
219
+ if (line !== undefined) return { value: String(line), badStart, badSpan };
220
+ if (across !== undefined) return { value: across, badStart, badSpan };
221
+ return { badStart, badSpan };
222
+ }
223
+
206
224
  const inRange = (value: unknown, min: number, max: number): value is number =>
207
225
  typeof value === "number" && Number.isFinite(value) && value >= min && value <= max;
208
226
 
@@ -282,7 +300,7 @@ function cssFontWeight(value: unknown): string | undefined {
282
300
  return undefined;
283
301
  }
284
302
 
285
- const TRANSITION_EASINGS = new Set(["ease", "ease-in", "ease-out", "ease-in-out", "linear"]);
303
+ const TRANSITION_EASINGS = setOf(TRANSITION_EASING_VALUES);
286
304
  const TRANSITION_PROPERTIES: Readonly<Record<string, readonly string[]>> = {
287
305
  all: ["all"],
288
306
  colors: ["color", "background-color", "border-color"],
@@ -370,19 +388,9 @@ function cssIconAnimation(value: unknown): string | undefined {
370
388
 
371
389
  export type Declaration = { property: string; value: string };
372
390
 
373
- const BACKGROUND_SIZE = new Set(["auto", "cover", "contain"]);
374
- const BACKGROUND_POSITION = new Set([
375
- "center",
376
- "top",
377
- "bottom",
378
- "left",
379
- "right",
380
- "top left",
381
- "top right",
382
- "bottom left",
383
- "bottom right",
384
- ]);
385
- const BACKGROUND_REPEAT = new Set(["no-repeat", "repeat", "repeat-x", "repeat-y"]);
391
+ const BACKGROUND_SIZE = setOf(BACKGROUND_SIZES);
392
+ const BACKGROUND_POSITION = setOf(BACKGROUND_POSITIONS);
393
+ const BACKGROUND_REPEAT = setOf(BACKGROUND_REPEATS);
386
394
  const BACKGROUND_KEYS = new Set([
387
395
  "backgroundImage",
388
396
  "backgroundSize",
@@ -398,9 +406,6 @@ function isSafeBackground(value: string): boolean {
398
406
  return value.length > 0 && value.length <= 4096 && !/[{};<>\\`]|\/\*|\n|\r/.test(value);
399
407
  }
400
408
 
401
- const isRecord = (value: unknown): value is Record<string, unknown> =>
402
- typeof value === "object" && value !== null && !Array.isArray(value);
403
-
404
409
  /** A media URL wrapped for CSS. The schema already refuses quotes, spaces and parentheses. */
405
410
  function cssBackgroundImage(value: unknown): string | undefined {
406
411
  if (typeof value !== "string") return undefined;
@@ -409,17 +414,7 @@ function cssBackgroundImage(value: unknown): string | undefined {
409
414
  return isSafeBackground(css) ? css : undefined;
410
415
  }
411
416
 
412
- const GRADIENT_POSITION = new Set([
413
- "center",
414
- "top",
415
- "bottom",
416
- "left",
417
- "right",
418
- "top left",
419
- "top right",
420
- "bottom left",
421
- "bottom right",
422
- ]);
417
+ const GRADIENT_POSITION = setOf(BACKGROUND_POSITIONS);
423
418
 
424
419
  function cssAngle(value: unknown, fallback: number): number | undefined {
425
420
  const angle = value === undefined ? fallback : value;
@@ -587,6 +582,9 @@ const PROPERTY_MAP: {
587
582
  gap: { css: "gap", toValue: cssLength },
588
583
  gridColumnSpan: { css: "grid-column", toValue: cssGridSpan },
589
584
  gridRowSpan: { css: "grid-row", toValue: cssGridSpan },
585
+ // Composed with the span in `styleDeclarations` (`start / span n`).
586
+ gridColumnStart: { css: "grid-column", toValue: () => undefined },
587
+ gridRowStart: { css: "grid-row", toValue: () => undefined },
590
588
  width: { css: "width", toValue: cssLengthOrAuto },
591
589
  minWidth: { css: "min-width", toValue: cssLength },
592
590
  maxWidth: { css: "max-width", toValue: cssLength },
@@ -600,10 +598,10 @@ const PROPERTY_MAP: {
600
598
  paddingRight: { css: "padding-inline-end", toValue: cssLength },
601
599
  paddingBottom: { css: "padding-bottom", toValue: cssLength },
602
600
  paddingLeft: { css: "padding-inline-start", toValue: cssLength },
603
- marginTop: { css: "margin-top", toValue: cssLengthOrAuto },
604
- marginRight: { css: "margin-inline-end", toValue: cssLengthOrAuto },
605
- marginBottom: { css: "margin-bottom", toValue: cssLengthOrAuto },
606
- marginLeft: { css: "margin-inline-start", toValue: cssLengthOrAuto },
601
+ marginTop: { css: "margin-top", toValue: cssOffset },
602
+ marginRight: { css: "margin-inline-end", toValue: cssOffset },
603
+ marginBottom: { css: "margin-bottom", toValue: cssOffset },
604
+ marginLeft: { css: "margin-inline-start", toValue: cssOffset },
607
605
  position: { css: "position", toValue: keyword(POSITION) },
608
606
  top: { css: "top", toValue: cssOffset },
609
607
  right: { css: "inset-inline-end", toValue: cssOffset },
@@ -645,6 +643,8 @@ const PROPERTY_MAP: {
645
643
  cursor: { css: "cursor", toValue: keyword(CURSOR) },
646
644
  transition: { css: "transition", toValue: cssTransition },
647
645
  entrance: { css: "animation", toValue: cssEntrance },
646
+ // W-319: written by `motionDeclarations` in `styleDeclarations`; this entry only names it.
647
+ scrollMotion: { css: "animation", toValue: () => undefined },
648
648
  iconRotate: { css: "--emvb-icon-rotate", toValue: cssIconRotate },
649
649
  iconFlip: { css: "--emvb-icon-flip", toValue: cssIconFlip },
650
650
  iconScale: { css: "scale", toValue: cssIconScale },
@@ -677,8 +677,23 @@ export function styleDeclarations(style: unknown): {
677
677
  const rejected: string[] = [];
678
678
  if (typeof style !== "object" || style === null) return { declarations, rejected };
679
679
  const record = style as Record<string, unknown>;
680
+ let motion: Declaration[] = [];
680
681
  for (const [key, raw] of shorthandsFirst(record)) {
681
682
  if (BACKGROUND_KEYS.has(key)) continue;
683
+ if (
684
+ key === "gridColumnSpan" ||
685
+ key === "gridRowSpan" ||
686
+ key === "gridColumnStart" ||
687
+ key === "gridRowStart"
688
+ ) {
689
+ continue;
690
+ }
691
+ if (key === "scrollMotion") {
692
+ const found = motionDeclarations(raw);
693
+ if (found && found.every((d) => isSafeCssValue(d.value))) motion = found;
694
+ else rejected.push(key);
695
+ continue;
696
+ }
682
697
  const entry = Object.hasOwn(PROPERTY_MAP, key)
683
698
  ? PROPERTY_MAP[key as keyof StyleProps]
684
699
  : undefined;
@@ -704,15 +719,28 @@ export function styleDeclarations(style: unknown): {
704
719
  const background = composeBackground(record);
705
720
  declarations.push(...background.declarations);
706
721
  rejected.push(...background.rejected);
707
- return { declarations, rejected };
722
+ const column = gridPlacement(record["gridColumnStart"], record["gridColumnSpan"]);
723
+ const row = gridPlacement(record["gridRowStart"], record["gridRowSpan"]);
724
+ if (column.value) declarations.push({ property: "grid-column", value: column.value });
725
+ if (row.value) declarations.push({ property: "grid-row", value: row.value });
726
+ if (column.badStart) rejected.push("gridColumnStart");
727
+ if (column.badSpan) rejected.push("gridColumnSpan");
728
+ if (row.badStart) rejected.push("gridRowStart");
729
+ if (row.badSpan) rejected.push("gridRowSpan");
730
+ return { declarations: withMotion(declarations, motion), rejected };
708
731
  }
709
732
 
710
733
  /** Normal only (W-089, W-237): a state's `transition` and `iconAnimation` are dropped and reported. */
711
- const NORMAL_ONLY = ["transition", "iconAnimation"] as const;
734
+ const NORMAL_ONLY = ["transition", "iconAnimation", "scrollMotion"] as const;
712
735
  const withoutTransition = (style: unknown): unknown => {
713
736
  if (typeof style !== "object" || style === null) return style;
714
737
  if (!NORMAL_ONLY.some((key) => key in style)) return style;
715
- const { transition: _drop, iconAnimation: _loop, ...rest } = style as Record<string, unknown>;
738
+ const {
739
+ transition: _drop,
740
+ iconAnimation: _loop,
741
+ scrollMotion: _scroll,
742
+ ...rest
743
+ } = style as Record<string, unknown>;
716
744
  return rest;
717
745
  };
718
746
 
@@ -760,7 +788,28 @@ const BACKGROUND_LAYER_KEYS = [
760
788
  * whole `background-image` stack for that device, so the layers it inherits (the desktop image or
761
789
  * gradient) are filled in from `inherited` here. Otherwise they vanish on that device.
762
790
  */
791
+ /** Both write `animation` (W-319), so one set alone would drop the other it inherits. */
792
+ const ANIMATION_KEYS = ["entrance", "scrollMotion"] as const;
793
+
794
+ /**
795
+ * A style that sets an entrance or scroll motion keeps the other one it inherits from a wider
796
+ * device or its classes (W-319): both are one `animation` list in CSS.
797
+ */
798
+ export function withInheritedAnimation(style: unknown, inherited: unknown): unknown {
799
+ if (!isRecord(style) || !isRecord(inherited)) return style;
800
+ if (!ANIMATION_KEYS.some((key) => style[key] !== undefined)) return style;
801
+ const next: Record<string, unknown> = { ...style };
802
+ for (const key of ANIMATION_KEYS) {
803
+ if (next[key] === undefined && inherited[key] !== undefined) next[key] = inherited[key];
804
+ }
805
+ return next;
806
+ }
807
+
763
808
  export function withInheritedLayers(device: unknown, inherited: unknown): unknown {
809
+ return withInheritedBackground(withInheritedAnimation(device, inherited), inherited);
810
+ }
811
+
812
+ function withInheritedBackground(device: unknown, inherited: unknown): unknown {
764
813
  if (!isRecord(device) || !isRecord(inherited)) return device;
765
814
  if (!BACKGROUND_LAYER_KEYS.some((key) => device[key] !== undefined)) return device;
766
815
  const next: Record<string, unknown> = { ...device };
@@ -0,0 +1,129 @@
1
+ import { MOTION_EFFECTS, MOTION_LIMITS, type MotionEffect } from "../schema/motion.ts";
2
+ import type { Declaration } from "./css.ts";
3
+
4
+ type Effect = { type: MotionEffect; from: number; to: number };
5
+ type Range = "enter" | "cross" | "exit" | "page";
6
+
7
+ const RANGES: Record<Range, string> = {
8
+ enter: "entry 0% entry 100%",
9
+ cross: "cover 0% cover 100%",
10
+ exit: "exit 0% exit 100%",
11
+ page: "normal",
12
+ };
13
+
14
+ /** One keyframes per CSS property, so an unused effect never pins that property. */
15
+ const KEYFRAMES: Record<string, string> = {
16
+ mo: "opacity",
17
+ mt: "translate",
18
+ ms: "scale",
19
+ mr: "rotate",
20
+ mb: "filter",
21
+ };
22
+
23
+ /**
24
+ * The scroll motion keyframes (W-319). They exist only where scroll-driven animations do and the
25
+ * visitor has not asked for reduced motion, so anywhere else `emvb-m*` names nothing and the
26
+ * element stays still in its normal place.
27
+ */
28
+ export const MOTION_KEYFRAMES = `@media (prefers-reduced-motion: no-preference){@supports (animation-timeline: view()){${Object.entries(
29
+ KEYFRAMES,
30
+ )
31
+ .map(
32
+ ([name, prop]) =>
33
+ `@keyframes emvb-${name}{from{${prop}:var(--emvb-${name}0)}to{${prop}:var(--emvb-${name}1)}}`,
34
+ )
35
+ .join("")}}}`;
36
+
37
+ const isEffect = (value: unknown): value is Effect => {
38
+ if (typeof value !== "object" || value === null) return false;
39
+ const { type, from, to } = value as Record<string, unknown>;
40
+ if (typeof type !== "string" || !(MOTION_EFFECTS as readonly string[]).includes(type)) {
41
+ return false;
42
+ }
43
+ const [min, max] = MOTION_LIMITS[type as MotionEffect];
44
+ return [from, to].every(
45
+ (n) => typeof n === "number" && Number.isFinite(n) && n >= min && n <= max,
46
+ );
47
+ };
48
+
49
+ const num = (n: number) => String(Math.round(n * 100) / 100);
50
+
51
+ /**
52
+ * Declarations for a `scrollMotion` value (W-319): `animation` (one per animated property), its
53
+ * timeline and range, and the `--emvb-m*` values the keyframes read. Undefined for a bad value;
54
+ * `{ type: "none" }` is `animation: none`.
55
+ */
56
+ export function motionDeclarations(value: unknown): Declaration[] | undefined {
57
+ if (typeof value !== "object" || value === null) return undefined;
58
+ const record = value as Record<string, unknown>;
59
+ if (record["type"] === "none" && Object.keys(record).length === 1) {
60
+ return [{ property: "animation", value: "none" }];
61
+ }
62
+ const { effects, range } = record as { effects?: unknown; range?: unknown };
63
+ if (typeof range !== "string" || !Object.hasOwn(RANGES, range)) return undefined;
64
+ if (!Array.isArray(effects) || effects.length === 0 || effects.length > MOTION_EFFECTS.length) {
65
+ return undefined;
66
+ }
67
+ if (!effects.every(isEffect)) return undefined;
68
+ const by = new Map(effects.map((e) => [e.type, e]));
69
+ if (by.size !== effects.length) return undefined;
70
+ const frames: [string, string, string][] = [];
71
+ const fade = by.get("fade");
72
+ if (fade) frames.push(["mo", num(fade.from / 100), num(fade.to / 100)]);
73
+ const x = by.get("move-x");
74
+ const y = by.get("move-y");
75
+ if (x || y) {
76
+ frames.push([
77
+ "mt",
78
+ `${num(x?.from ?? 0)}px ${num(y?.from ?? 0)}px`,
79
+ `${num(x?.to ?? 0)}px ${num(y?.to ?? 0)}px`,
80
+ ]);
81
+ }
82
+ const scale = by.get("scale");
83
+ if (scale) frames.push(["ms", num(scale.from / 100), num(scale.to / 100)]);
84
+ const rotate = by.get("rotate");
85
+ if (rotate) frames.push(["mr", `${num(rotate.from)}deg`, `${num(rotate.to)}deg`]);
86
+ const blur = by.get("blur");
87
+ if (blur) frames.push(["mb", `blur(${num(blur.from)}px)`, `blur(${num(blur.to)}px)`]);
88
+ const timeline = range === "page" ? "scroll(root)" : "view()";
89
+ const rangeValue = RANGES[range as Range];
90
+ return [
91
+ { property: "animation", value: frames.map(([n]) => `emvb-${n} linear both`).join(", ") },
92
+ { property: "animation-timeline", value: frames.map(() => timeline).join(", ") },
93
+ { property: "animation-range", value: frames.map(() => rangeValue).join(", ") },
94
+ ...frames.flatMap(([n, from, to]) => [
95
+ { property: `--emvb-${n}0`, value: from },
96
+ { property: `--emvb-${n}1`, value: to },
97
+ ]),
98
+ ];
99
+ }
100
+
101
+ /**
102
+ * Adds scroll motion to an element's declarations (W-319). An entrance and scroll motion share
103
+ * `animation`, so they are joined, entrance first, with matching timeline and range lists; motion
104
+ * `none` leaves an entrance on the same style alone.
105
+ */
106
+ export function withMotion(declarations: Declaration[], motion: Declaration[]): Declaration[] {
107
+ const entrance = declarations.find((d) => d.property === "animation");
108
+ if (!entrance) return [...declarations, ...motion];
109
+ const [animation, timeline, range, ...vars] = motion;
110
+ if (!animation || animation.value === "none" || !timeline || !range) return declarations;
111
+ const entranceTimeline = declarations.find((d) => d.property === "animation-timeline");
112
+ const entranceRange = declarations.find((d) => d.property === "animation-range");
113
+ const rest = declarations.filter(
114
+ (d) => d !== entrance && d !== entranceTimeline && d !== entranceRange,
115
+ );
116
+ return [
117
+ ...rest,
118
+ { property: "animation", value: `${entrance.value}, ${animation.value}` },
119
+ {
120
+ property: "animation-timeline",
121
+ value: `${entranceTimeline?.value ?? "auto"}, ${timeline.value}`,
122
+ },
123
+ {
124
+ property: "animation-range",
125
+ value: `${entranceRange?.value ?? "normal"}, ${range.value}`,
126
+ },
127
+ ...vars,
128
+ ];
129
+ }
@@ -198,9 +198,14 @@ function isSafeHref(tag: string, name: string, value: string): boolean {
198
198
  const isHrefName = (name: string) => name === "href" || name === "xlink:href";
199
199
 
200
200
  function isSafeUrlRefAttr(name: string, value: string): boolean {
201
- if (name !== "clip-path" && name !== "mask") return true;
202
- if (value === "none") return true;
203
- return URL_HASH_REF.test(value);
201
+ if (name === "clip-path" || name === "mask") {
202
+ if (value === "none") return true;
203
+ return URL_HASH_REF.test(value);
204
+ }
205
+ // fill, stroke and the rest: `url(https://…)` is a request from the visitor's browser.
206
+ // A fragment (`url(#id)`) stays inside this SVG.
207
+ if (/url\s*\(/i.test(value)) return URL_HASH_REF.test(value);
208
+ return true;
204
209
  }
205
210
 
206
211
  type ParsedAttrs = { attrs: Record<string, string>; external: boolean };
@@ -16,16 +16,25 @@ export function sanitizeUrl(value: string, schemes: ReadonlySet<string>): string
16
16
  if (!hasScheme) {
17
17
  // Browsers resolve `//host` and `/\host` to another site; EmDash 1.0 refuses them for `url` fields too.
18
18
  if (/^\/[/\\]/.test(trimmed)) return undefined;
19
+ // A normal space can sit in a relative path. Any other whitespace, or a backslash, is how a
20
+ // second address hides in the same string.
21
+ if (/[^\S ]|\\/.test(trimmed)) return undefined;
19
22
  // Relative: /path, ./path, ../path, ?query, #hash, or bare path segment
20
23
  if (/^(?:[/?#.]|[A-Za-z0-9._~-])/.test(trimmed)) return trimmed;
21
24
  return undefined;
22
25
  }
23
26
 
27
+ // Parse the string we will return. Stripping whitespace first, then returning the original,
28
+ // accepted `https://site/a.png 1w, https://evil/x` because only the stripped copy was checked.
29
+ if (/[\s\\]/.test(trimmed)) return undefined;
30
+
24
31
  let parsed: URL;
25
32
  try {
26
- parsed = new URL(trimmed.replace(/\s+/g, ""));
33
+ parsed = new URL(trimmed);
27
34
  } catch {
28
35
  return undefined;
29
36
  }
37
+ // `user:pass@host` would publish the password in the page.
38
+ if (parsed.username || parsed.password) return undefined;
30
39
  return schemes.has(parsed.protocol.toLowerCase()) ? trimmed : undefined;
31
40
  }
@@ -1,8 +1,14 @@
1
1
  import { z } from "zod";
2
+ import { HEX_COLOR } from "../css-keywords.ts";
2
3
  import { DeviceStyles, HiddenOn, StyleProps, StyleStates } from "./style.ts";
3
4
 
4
- /** 12 since W-160: class gradients use the same stops as layouts. v11 `{ angle, from, to }` upgrades on read. */
5
- export const DESIGN_SCHEMA_VERSION = 12;
5
+ /**
6
+ * 15 since W-341, in step with layouts (optional fields only; the design document itself is unchanged).
7
+ * 14 since W-329, in step with layouts (optional fields only: `ch` lengths, negative margins).
8
+ * 13 since W-307, in step with layouts (the W-307 batch only adds optional fields).
9
+ * 12 since W-160: class gradients use the same stops as layouts. v11 `{ angle, from, to }` upgrades on read.
10
+ */
11
+ export const DESIGN_SCHEMA_VERSION = 15;
6
12
 
7
13
  /** Tags a site can give a starting style. Classes and local styles still win. */
8
14
  export const DEFAULT_STYLE_TAGS = ["h1", "h2", "h3", "h4", "h5", "h6", "p", "a", "button"] as const;
@@ -16,12 +22,7 @@ const VariableId = z
16
22
  export const ColorVariable = z.strictObject({
17
23
  id: VariableId,
18
24
  name: z.string().min(1).max(60),
19
- value: z
20
- .string()
21
- .regex(
22
- /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i,
23
- "Use a hex color such as #1a2b3c",
24
- ),
25
+ value: z.string().regex(HEX_COLOR, "Use a hex color such as #1a2b3c"),
25
26
  });
26
27
 
27
28
  /** Font stack string — commas and quoted family names allowed; `generateCss` drops an unsafe one. */
@@ -31,6 +32,15 @@ export const FontVariable = z.strictObject({
31
32
  value: z.string().min(1).max(200),
32
33
  });
33
34
 
35
+ /**
36
+ * A fluid size (W-316): `min` px on small screens growing to `max` px on large ones, emitted as
37
+ * `clamp()` between the site's fluid range. `value` stays as the fixed fallback the editor shows.
38
+ */
39
+ const FluidSize = z.strictObject({
40
+ min: z.number().finite().min(0).max(1000),
41
+ max: z.number().finite().min(0).max(1000),
42
+ });
43
+
34
44
  export const LengthVariable = z.strictObject({
35
45
  id: VariableId,
36
46
  name: z.string().min(1).max(60),
@@ -38,8 +48,18 @@ export const LengthVariable = z.strictObject({
38
48
  value: z.number().finite().min(0).max(10_000),
39
49
  unit: z.enum(["px", "rem", "em", "%"]),
40
50
  }),
51
+ fluid: FluidSize.optional(),
41
52
  });
42
53
 
54
+ /** Screen widths fluid sizes grow between (W-316). Unset = 360 to 1280 px. */
55
+ const FluidRange = z
56
+ .strictObject({
57
+ minWidth: z.number().int().min(240).max(1200),
58
+ maxWidth: z.number().int().min(480).max(3840),
59
+ })
60
+ .refine((range) => range.minWidth < range.maxWidth, "The small screen must be narrower");
61
+ export type FluidRange = z.infer<typeof FluidRange>;
62
+
43
63
  /** Shared style class (R-021 / W-030). CSS selector is always `.emvb-k-<id>`. */
44
64
  const StyleClass = z.strictObject({
45
65
  id: VariableId,
@@ -60,6 +80,7 @@ export const DesignSystem = z.strictObject({
60
80
  spacings: z.array(LengthVariable).max(100).optional(),
61
81
  }),
62
82
  classes: z.array(StyleClass).max(100).optional(),
83
+ fluidRange: FluidRange.optional(),
63
84
  /**
64
85
  * Site text direction (W-230). Unset is left to right. Rendered as `dir` on every EmVB root
65
86
  * and returned to hosts for `<html dir>`. Layout uses logical properties, so styles flip.