@perkyzz/emvb 1.2.0 → 1.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 +2 -2
  2. package/THIRD_PARTY_NOTICES.md +2 -2
  3. package/package.json +4 -4
  4. package/src/admin/bulk-api.ts +5 -1
  5. package/src/admin/editor/A11yCopilot.tsx +3 -1
  6. package/src/admin/editor/Editor.tsx +22 -2
  7. package/src/admin/editor/Timeline.tsx +1 -8
  8. package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
  9. package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
  10. package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
  11. package/src/admin/editor/canvas/vnode-react.tsx +5 -0
  12. package/src/admin/editor/co-design.ts +36 -1
  13. package/src/admin/editor/dnd/dragged-source.ts +22 -0
  14. package/src/admin/editor/dnd/layer-drop.ts +141 -0
  15. package/src/admin/editor/dnd/new-element.ts +76 -0
  16. package/src/admin/editor/editor-css.ts +9 -1
  17. package/src/admin/editor/element-chrome.ts +34 -0
  18. package/src/admin/editor/feature-css.ts +22 -0
  19. package/src/admin/editor/inert-links.ts +8 -0
  20. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  21. package/src/admin/editor/panels/FontFaces.tsx +342 -0
  22. package/src/admin/editor/panels/LayersPanel.tsx +56 -6
  23. package/src/admin/editor/panels/LeftPanel.tsx +153 -29
  24. package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
  25. package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
  26. package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
  27. package/src/admin/editor/panels/TokenScales.tsx +2 -0
  28. package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
  29. package/src/admin/editor/panels/VariableSection.tsx +111 -7
  30. package/src/admin/editor/panels/color-space.ts +71 -6
  31. package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
  32. package/src/admin/editor/panels/settings/FieldControl.tsx +18 -0
  33. package/src/admin/editor/panels/settings/ItemList.tsx +33 -0
  34. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
  35. package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
  36. package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
  37. package/src/admin/editor/panels/settings/style-sections.ts +19 -2
  38. package/src/admin/editor/panels/url-rules.ts +43 -0
  39. package/src/admin/editor/panels/use-layers-drop.ts +232 -0
  40. package/src/admin/editor/store.ts +4 -2
  41. package/src/admin/editor/useExtensions.ts +3 -1
  42. package/src/admin/editor/useNodeActions.ts +74 -1
  43. package/src/admin/editor/useSave.ts +116 -85
  44. package/src/admin/export-api.ts +25 -2
  45. package/src/admin/extension-outputs.ts +179 -0
  46. package/src/admin/font-files-api.ts +38 -0
  47. package/src/admin/pages/ImportButton.tsx +15 -4
  48. package/src/admin/pages/ImportElementorDialog.tsx +22 -188
  49. package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
  50. package/src/admin/pages/ImportImageCopies.tsx +167 -0
  51. package/src/admin/pages/ImportReport.tsx +63 -0
  52. package/src/admin/pages/NewPageDialog.tsx +54 -32
  53. package/src/admin/pages/PageList.tsx +9 -0
  54. package/src/admin/pages/ThemePartList.tsx +9 -0
  55. package/src/astro/EmVBPage.astro +5 -2
  56. package/src/astro/extension-styles.ts +35 -0
  57. package/src/astro/forms/EmVBFormsClient.astro +3 -0
  58. package/src/astro/forms/enhance.ts +107 -0
  59. package/src/astro/popups/runtime.ts +47 -2
  60. package/src/astro/render.ts +19 -4
  61. package/src/astro/request-data.ts +6 -0
  62. package/src/astro/resolve-theme.ts +11 -4
  63. package/src/astro/resolve.ts +9 -0
  64. package/src/astro/widgets/EmVBCountdownRuntime.astro +8 -0
  65. package/src/astro/widgets/EmVBCounterRuntime.astro +8 -0
  66. package/src/astro/widgets/EmVBHeadlineRuntime.astro +9 -0
  67. package/src/astro/widgets/EmVBMapRuntime.astro +8 -0
  68. package/src/astro/widgets/EmVBShareRuntime.astro +9 -0
  69. package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
  70. package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
  71. package/src/astro/widgets/EmVBWidgetRuntimes.astro +22 -0
  72. package/src/astro/widgets/alerts.ts +16 -2
  73. package/src/astro/widgets/carousel.ts +65 -24
  74. package/src/astro/widgets/countdown.ts +91 -0
  75. package/src/astro/widgets/counter.ts +98 -0
  76. package/src/astro/widgets/extension-runtimes.ts +27 -0
  77. package/src/astro/widgets/headline.ts +99 -0
  78. package/src/astro/widgets/map.ts +37 -0
  79. package/src/astro/widgets/share.ts +21 -0
  80. package/src/astro/widgets/sticky.ts +87 -0
  81. package/src/astro/widgets/theme.ts +52 -0
  82. package/src/constants.ts +1 -1
  83. package/src/core/a11y/audit.ts +177 -6
  84. package/src/core/arrange.ts +71 -1
  85. package/src/core/canvas-collections.ts +28 -0
  86. package/src/core/css/font-face.ts +72 -0
  87. package/src/core/css/generate.ts +35 -1
  88. package/src/core/elements/counter-format.ts +15 -0
  89. package/src/core/elements/form-elements.ts +119 -9
  90. package/src/core/elements/icon-svg.ts +14 -0
  91. package/src/core/elements/index.ts +54 -4
  92. package/src/core/elements/input-limits.ts +44 -0
  93. package/src/core/elements/marketing.ts +1490 -0
  94. package/src/core/elements/menu.ts +109 -47
  95. package/src/core/elements/site.ts +108 -0
  96. package/src/core/elements/widgets.ts +40 -5
  97. package/src/core/export/runtimes.generated.ts +10 -3
  98. package/src/core/export/site.ts +55 -4
  99. package/src/core/extensions/classes.ts +114 -0
  100. package/src/core/extensions/index.ts +17 -2
  101. package/src/core/extensions/normalize.ts +13 -0
  102. package/src/core/extensions/registry.ts +134 -10
  103. package/src/core/extensions/render-ext.ts +66 -21
  104. package/src/core/extensions/safe-nodes.ts +67 -11
  105. package/src/core/extensions/types.ts +48 -1
  106. package/src/core/fonts/files.ts +74 -0
  107. package/src/core/fonts/google.ts +112 -0
  108. package/src/core/fonts/test-font.ts +9 -0
  109. package/src/core/import/elementor/context.ts +13 -4
  110. package/src/core/import/elementor/index.ts +32 -21
  111. package/src/core/import/elementor/widgets.ts +532 -293
  112. package/src/core/import/html/blocks.ts +602 -0
  113. package/src/core/import/html/index.ts +155 -0
  114. package/src/core/import/html/map.ts +958 -0
  115. package/src/core/import/html/parse.ts +430 -0
  116. package/src/core/index.ts +45 -0
  117. package/src/core/limits.ts +6 -0
  118. package/src/core/migrate/v18.ts +3 -0
  119. package/src/core/public-attributes.ts +17 -0
  120. package/src/core/render/extras.ts +31 -7
  121. package/src/core/render/form.ts +103 -10
  122. package/src/core/render/index.ts +172 -16
  123. package/src/core/render/section.ts +31 -1
  124. package/src/core/render/spacer-basis.ts +102 -0
  125. package/src/core/render/theme-boot.ts +16 -0
  126. package/src/core/render/vnode.ts +1 -1
  127. package/src/core/sanitize/css.ts +68 -3
  128. package/src/core/sanitize/motion.ts +12 -0
  129. package/src/core/schema/design.ts +40 -0
  130. package/src/core/schema/layout.ts +534 -22
  131. package/src/core/schema/style.ts +28 -0
  132. package/src/core/templates/index.ts +218 -0
  133. package/src/core/templates/pages.ts +29 -0
  134. package/src/core/templates/sections.ts +794 -0
  135. package/src/core/templates/types.ts +9 -0
  136. package/src/core/theme/dynamic.ts +11 -6
  137. package/src/core/theme/popup-markup.ts +21 -2
  138. package/src/core/theme/popup-rules.ts +36 -0
  139. package/src/core/theme/triggers.ts +64 -5
  140. package/src/core/translatable.ts +5 -2
  141. package/src/extension-build.ts +331 -0
  142. package/src/index.ts +25 -3
  143. package/src/mcp/brief.ts +191 -0
  144. package/src/mcp/prompts.ts +33 -0
  145. package/src/mcp/read.ts +29 -1
  146. package/src/mcp/tools.ts +40 -1
  147. package/src/mcp/write.ts +41 -1
  148. package/src/server/extension-routes.ts +73 -0
  149. package/src/server/font-routes.ts +301 -0
  150. package/src/server/plugin.ts +11 -1
@@ -100,6 +100,7 @@ export const EDITOR_CSS = `${UI_CSS}
100
100
  .emvb-check > input { width: 16px; height: 16px; margin: 0; }
101
101
  @keyframes emvb-panel-enter { from { opacity: 0; } to { opacity: 1; } }
102
102
  .emvb-left-panel > [data-emvb-panel],
103
+ .emvb-left-panel > .emvb-add-holder > [data-emvb-panel],
103
104
  .emvb-panel-right [data-emvb-tab],
104
105
  .emvb-site-styles-body { animation: emvb-panel-enter 150ms cubic-bezier(0, 0, 0.2, 1); }
105
106
  /* UX-010: a section's rows fade in as it opens (closing stays instant); the Site styles drawer slides in. */
@@ -177,7 +178,7 @@ export const EDITOR_CSS = `${UI_CSS}
177
178
  .emvb-gradient-stop { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; box-shadow: inset 0 1px 0 var(--color-kumo-line); }
178
179
  .emvb-row-actions { display: flex; justify-content: flex-end; gap: 8px; }
179
180
  .emvb-layers { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 1px; }
180
- .emvb-layer-row { display: flex; align-items: center; gap: 6px; width: 100%; height: var(--emvb-control); padding-right: 4px; border-radius: 6px; color: var(--text-color-kumo-default); font-size: 13px; }
181
+ .emvb-layer-row { display: flex; align-items: center; gap: 6px; width: 100%; height: var(--emvb-control); padding-inline-end: 4px; border-radius: 6px; color: var(--text-color-kumo-default); font-size: 13px; }
181
182
  .emvb-layer-select { display: flex; align-items: center; gap: 6px; flex: 1 1 auto; min-width: 0; height: var(--emvb-control); padding: 0 4px 0 0; border: 0; border-radius: 6px; background: transparent; color: inherit; font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
182
183
  .emvb-layer-row:hover, .emvb-layer-row:hover .emvb-layer-select { background: var(--color-kumo-tint); }
183
184
  .emvb-layers:empty::after, .emvb-panel-body > .emvb-helper { color: var(--text-color-kumo-subtle); }
@@ -192,6 +193,13 @@ export const EDITOR_CSS = `${UI_CSS}
192
193
  .emvb-layer-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
193
194
  .emvb-layer-preview { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-color-kumo-subtle); }
194
195
  .emvb-layer-select[aria-current="true"] .emvb-layer-preview { color: inherit; }
196
+ /* W-1080: drops on Layers. The line tracks the pointer without easing, like the canvas drop line.
197
+ Indents, the line and the refusal use logical sides so Layers reads right to left in RTL. */
198
+ .emvb-layers-body { position: relative; }
199
+ .emvb-layer-drop-line { position: absolute; inset-inline-end: 4px; height: 2px; border-radius: 1px; background: var(--color-kumo-brand); box-shadow: 0 0 0 1px var(--color-kumo-base, #fff); pointer-events: none; z-index: 2; }
200
+ .emvb-layer-row[data-emvb-drop="inside"] { box-shadow: inset 0 0 0 1px var(--color-kumo-brand); background: var(--color-kumo-tint); }
201
+ .emvb-layer-row[data-emvb-drop="invalid"] { outline: 1px dashed var(--color-kumo-danger); outline-offset: -1px; cursor: not-allowed; }
202
+ .emvb-layer-drop-refusal { inset-inline-end: 4px; height: auto; min-height: 24px; padding: 4px 6px; white-space: normal; }
195
203
  .emvb-canvas { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--color-kumo-canvas); }
196
204
  .emvb-device-bar { display: flex; flex: none; align-items: center; justify-content: center; gap: 12px; height: 36px; border-bottom: 1px solid var(--color-kumo-line); background: var(--color-kumo-surface); }
197
205
  /* W-127: the segmented control hugs its three options; a fixed width left a gap on the right. */
@@ -1,4 +1,5 @@
1
1
  import {
2
+ ArrowsClockwiseIcon,
2
3
  ArrowsLeftRightIcon,
3
4
  ArrowsVerticalIcon,
4
5
  ArticleIcon,
@@ -13,29 +14,44 @@ import {
13
14
  CaretRightIcon,
14
15
  CheckSquareIcon,
15
16
  ColumnsIcon,
17
+ CurrencyDollarIcon,
18
+ CrosshairIcon,
16
19
  CursorClickIcon,
17
20
  FrameCornersIcon,
18
21
  GraphIcon,
22
+ GaugeIcon,
19
23
  GridFourIcon,
24
+ HighlighterIcon,
25
+ TimerIcon,
26
+ HashIcon,
20
27
  ImageIcon,
21
28
  ImagesIcon,
22
29
  ImageSquareIcon,
23
30
  LinkIcon,
24
31
  ListBulletsIcon,
32
+ ListDashesIcon,
25
33
  ListIcon,
26
34
  ListNumbersIcon,
27
35
  TranslateIcon,
36
+ MagnifyingGlassIcon,
37
+ MoonIcon,
38
+ MapPinIcon,
39
+ MegaphoneIcon,
28
40
  MinusIcon,
29
41
  NotePencilIcon,
42
+ NumberCircleOneIcon,
30
43
  PaperPlaneRightIcon,
31
44
  QuotesIcon,
32
45
  RadioButtonIcon,
33
46
  RepeatIcon,
34
47
  RowsIcon,
35
48
  LinkSimpleIcon,
49
+ ShareFatIcon,
50
+ ShareIcon,
36
51
  ShareNetworkIcon,
37
52
  SmileyIcon,
38
53
  SquareIcon,
54
+ TagIcon,
39
55
  SquaresFourIcon,
40
56
  SquareHalfBottomIcon,
41
57
  StackIcon,
@@ -49,6 +65,7 @@ import {
49
65
  VideoCameraIcon,
50
66
  WarningCircleIcon,
51
67
  type Icon,
68
+ StepsIcon,
52
69
  } from "@phosphor-icons/react";
53
70
  import { ELEMENT_DESCRIPTORS } from "../../core/index.ts";
54
71
 
@@ -98,8 +115,25 @@ export const ELEMENT_ICONS: Record<string, Icon> = {
98
115
  "gallery-image": FrameCornersIcon,
99
116
  carousel: SlideshowIcon,
100
117
  "carousel-slide": CardsIcon,
118
+ counter: HashIcon,
119
+ progress: GaugeIcon,
120
+ countdown: TimerIcon,
121
+ map: MapPinIcon,
122
+ "search-form": MagnifyingGlassIcon,
123
+ "theme-toggle": MoonIcon,
124
+ "price-table": TagIcon,
125
+ "price-list": ListDashesIcon,
126
+ "price-list-item": CurrencyDollarIcon,
127
+ cta: MegaphoneIcon,
128
+ "flip-box": ArrowsClockwiseIcon,
129
+ headline: HighlighterIcon,
130
+ "share-buttons": ShareFatIcon,
131
+ "share-link": ShareIcon,
132
+ hotspots: CrosshairIcon,
133
+ hotspot: NumberCircleOneIcon,
101
134
  video: VideoCameraIcon,
102
135
  form: ArticleIcon,
136
+ "form-step": StepsIcon,
103
137
  "text-input": TextboxIcon,
104
138
  textarea: TextAaIcon,
105
139
  select: CaretCircleDownIcon,
@@ -150,6 +150,20 @@ export const FEATURE_CSS = `
150
150
  .emvb-recipe-tile:hover, .emvb-recipe-tile:focus-visible { border-color: var(--color-kumo-brand); }
151
151
  .emvb-recipe-name { font-weight: 600; font-size: 13px; }
152
152
  .emvb-recipe-desc { font-size: 12px; color: var(--text-color-kumo-subtle); }
153
+ /* W-1068: Add panel Elements | Templates, and the starter template tiles with their pictures. */
154
+ .emvb-add-switch-tabs { width: 100%; }
155
+ .emvb-add-switch-tabs [role="tablist"] { width: 100%; height: var(--emvb-control); min-height: var(--emvb-control); }
156
+ .emvb-add-switch-tabs [role="tab"] { flex: 1 1 0; justify-content: center; height: 100%; font-size: 13px; line-height: 18px; }
157
+ .emvb-add-switch-tabs [role="tab"][aria-selected="false"] { color: var(--text-color-kumo-default); }
158
+ .emvb-template-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
159
+ .emvb-template-tile { position: relative; display: grid; gap: 2px; padding: 0 0 8px; border-radius: 8px; border: 1px solid var(--color-kumo-line); background: var(--color-kumo-base, transparent); overflow: hidden; }
160
+ .emvb-template-tile:hover, .emvb-template-tile:has(.emvb-template-insert:focus-visible) { border-color: var(--color-kumo-brand); }
161
+ .emvb-template-tile:has(.emvb-template-insert:focus-visible) { outline: 2px solid var(--color-kumo-brand); outline-offset: 1px; }
162
+ .emvb-template-preview { position: relative; height: 104px; overflow: hidden; border-bottom: 1px solid var(--color-kumo-line); background: var(--color-kumo-recessed, transparent); }
163
+ .emvb-template-preview iframe { position: absolute; top: 0; left: 0; width: 1280px; height: 640px; border: 0; transform-origin: 0 0; pointer-events: none; }
164
+ .emvb-template-insert { all: unset; padding: 6px 10px 0; font-weight: 600; font-size: 13px; line-height: 18px; cursor: grab; }
165
+ .emvb-template-insert::after { content: ""; position: absolute; inset: 0; }
166
+ .emvb-template-desc { margin: 0; padding: 0 10px; font-size: 12px; line-height: 16px; color: var(--text-color-kumo-subtle); }
153
167
  /* W-876: My sections, names only (D-060). */
154
168
  .emvb-saved-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
155
169
  .emvb-saved-row { display: flex; align-items: center; gap: 2px; min-width: 0; }
@@ -180,4 +194,12 @@ export const FEATURE_CSS = `
180
194
  .emvb-codesign-ask-form { display: grid; gap: 6px; }
181
195
  .emvb-codesign-ask-form .emvb-helper { margin: 0; }
182
196
  .emvb-codesign-preview { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 12px 0; padding: 8px 8px 8px 12px; border: 1px solid var(--color-kumo-line); border-radius: 10px; background: var(--color-kumo-tint); font-size: 13px; line-height: 18px; }
197
+ /* W-1072: a font variable's own files (Site styles, Fonts). */
198
+ .emvb-font-faces .emvb-bind-label { margin: 4px 0 0; }
199
+ .emvb-font-face-list { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
200
+ .emvb-font-face-list > li { display: flex; align-items: center; gap: 6px; min-height: 28px; font-size: 13px; }
201
+ .emvb-font-face-list > li > span:first-child { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
202
+ .emvb-font-face-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
203
+ .emvb-font-weights { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 0; padding: 0; border: 0; font-size: 12px; }
204
+ .emvb-font-weights > legend { width: 100%; padding: 0; margin-bottom: 2px; }
183
205
  `;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * W-752: a preview picture is not a page to browse. A link in it took keyboard focus and Enter
3
+ * loaded the site (or the admin, for an in-page anchor) inside the picture. Inside a tag, core
4
+ * escapes `"` and `>` in attribute values, so the tag and its href are found exactly; text is
5
+ * left alone. Used by the version timeline and the template previews (W-1068).
6
+ */
7
+ export const inertLinks = (html: string) =>
8
+ html.replaceAll(/<a\b[^>]*>/g, (tag) => tag.replace(/ href="[^"]*"/, ""));
@@ -338,8 +338,8 @@ function CustomColor({
338
338
  />
339
339
  {clipped !== null && clipped === draft && !error && (
340
340
  <p className="emvb-helper" role="status" data-emvb-clipped="">
341
- Clipped to {clipped}: that OKLCH colour is outside sRGB, so its out-of-range channels were
342
- cut to fit.
341
+ Mapped to {clipped}: that OKLCH colour is outside sRGB, so it keeps its lightness and hue
342
+ with less chroma.
343
343
  </p>
344
344
  )}
345
345
  </div>
@@ -0,0 +1,342 @@
1
+ import { Button, Checkbox, Input } from "@cloudflare/kumo";
2
+ import { TrashIcon, UploadSimpleIcon } from "@phosphor-icons/react";
3
+ import * as React from "react";
4
+ import {
5
+ FONT_FAMILY_NAME,
6
+ fontFaceRules,
7
+ GOOGLE_FAMILY,
8
+ GOOGLE_WEIGHTS,
9
+ type FontFace,
10
+ type FontVariable,
11
+ } from "../../../core/index.ts";
12
+ import type { Fetcher } from "../../api.ts";
13
+ import { importGoogleFont, uploadFontFile } from "../../font-files-api.ts";
14
+ import { BUTTON, FIELD } from "../../ui.ts";
15
+ import { InlineError } from "./inline-error.tsx";
16
+ import { PanelSelect } from "./settings/PanelSelect.tsx";
17
+
18
+ const WEIGHT_NAMES: Record<number, string> = {
19
+ 100: "Thin",
20
+ 200: "Extra light",
21
+ 300: "Light",
22
+ 400: "Regular",
23
+ 500: "Medium",
24
+ 600: "Semibold",
25
+ 700: "Bold",
26
+ 800: "Extra bold",
27
+ 900: "Black",
28
+ };
29
+
30
+ /** Subsets offered for Google fonts besides Latin, which is always downloaded. */
31
+ const EXTRA_SUBSETS = [
32
+ { value: "latin-ext", label: "Latin Extended" },
33
+ { value: "cyrillic", label: "Cyrillic" },
34
+ { value: "greek", label: "Greek" },
35
+ { value: "vietnamese", label: "Vietnamese" },
36
+ ] as const;
37
+
38
+ const faceLabel = (weight: number, style: string) =>
39
+ `${WEIGHT_NAMES[weight] ?? "Weight"} ${weight}${style === "italic" ? " italic" : ""}`;
40
+
41
+ /** The first family of a font stack, unquoted, when it can name a custom font. */
42
+ function firstFamily(stack: string): string {
43
+ const first = (stack.split(",")[0] ?? "").trim().replace(/^(['"])(.*)\1$/, "$2");
44
+ return FONT_FAMILY_NAME.test(first) ? first : "";
45
+ }
46
+
47
+ /** The stack with `family` first (quoted), unless it already starts with it. */
48
+ export function stackWithFamily(stack: string, family: string): string {
49
+ if (firstFamily(stack) === family) return stack;
50
+ const next = `'${family}', ${stack}`;
51
+ return next.length <= 200 ? next : `'${family}', sans-serif`;
52
+ }
53
+
54
+ /** Faces of one weight and style replace the ones the variable had for it. */
55
+ function mergeFaces(current: readonly FontFace[], added: readonly FontFace[]): FontFace[] {
56
+ const replaced = new Set(added.map((face) => `${face.weight}/${face.style}`));
57
+ return [...current.filter((face) => !replaced.has(`${face.weight}/${face.style}`)), ...added];
58
+ }
59
+
60
+ /**
61
+ * W-1072: a font variable's own font files. Uploaded WOFF2 files, or a Google font downloaded
62
+ * once by the server, are served from this site, so pages make no request to another host.
63
+ */
64
+ export function FontFaces({
65
+ font,
66
+ fetcher,
67
+ onSave,
68
+ }: {
69
+ font: FontVariable;
70
+ fetcher: Fetcher;
71
+ onSave: (next: FontVariable) => Promise<boolean | void>;
72
+ }) {
73
+ const id = React.useId();
74
+ const fileRef = React.useRef<HTMLInputElement | null>(null);
75
+ const [family, setFamily] = React.useState(font.family ?? firstFamily(font.value));
76
+ const [weight, setWeight] = React.useState("400");
77
+ const [style, setStyle] = React.useState<"normal" | "italic">("normal");
78
+ const [google, setGoogle] = React.useState(font.source === "google" ? (font.family ?? "") : "");
79
+ const [weights, setWeights] = React.useState<number[]>([400, 700]);
80
+ const [italic, setItalic] = React.useState(false);
81
+ const [subsets, setSubsets] = React.useState<string[]>(["latin-ext"]);
82
+ const [busy, setBusy] = React.useState<string | null>(null);
83
+ const [error, setError] = React.useState<string | null>(null);
84
+ const [done, setDone] = React.useState<string | null>(null);
85
+ const faces = font.faces ?? [];
86
+ const groups = [...new Set(faces.map((face) => `${face.weight}/${face.style}`))].map((key) => {
87
+ const [w, s] = key.split("/");
88
+ return {
89
+ weight: Number(w),
90
+ style: s ?? "normal",
91
+ files: faces.filter((f) => `${f.weight}/${f.style}` === key).length,
92
+ };
93
+ });
94
+
95
+ const save = async (next: FontVariable, message: string) => {
96
+ if ((await onSave(next)) === false) return;
97
+ setDone(message);
98
+ };
99
+
100
+ const upload = async (file: File) => {
101
+ const name = (font.family ?? family).trim();
102
+ if (!FONT_FAMILY_NAME.test(name)) {
103
+ setError("Name the font family first: letters, digits, spaces, _ . or -.");
104
+ return;
105
+ }
106
+ setError(null);
107
+ setDone(null);
108
+ setBusy("Uploading…");
109
+ try {
110
+ const { url } = await uploadFontFile(fetcher, file);
111
+ const face: FontFace = { weight: Number(weight), style, src: url };
112
+ const sameFamily = font.family === name;
113
+ await save(
114
+ {
115
+ ...font,
116
+ value: stackWithFamily(font.value, name),
117
+ family: name,
118
+ faces: mergeFaces(sameFamily ? faces : [], [face]),
119
+ source: "upload",
120
+ },
121
+ `Added ${faceLabel(face.weight, face.style)}.`,
122
+ );
123
+ } catch (failure) {
124
+ setError(failure instanceof Error ? failure.message : "Couldn't upload the font.");
125
+ } finally {
126
+ setBusy(null);
127
+ }
128
+ };
129
+
130
+ const download = async () => {
131
+ const name = google.trim().replace(/\s+/g, " ");
132
+ if (!GOOGLE_FAMILY.test(name)) {
133
+ setError("Type a Google Fonts family name, such as Open Sans.");
134
+ return;
135
+ }
136
+ if (weights.length === 0) {
137
+ setError("Pick at least one weight.");
138
+ return;
139
+ }
140
+ setError(null);
141
+ setDone(null);
142
+ const styles: ("normal" | "italic")[] = italic ? ["normal", "italic"] : ["normal"];
143
+ const wanted = weights.flatMap((w) => styles.map((s) => ({ weight: w, style: s })));
144
+ let added: FontFace[] = [];
145
+ try {
146
+ // One weight and style per request keeps each server call small (Workers limits).
147
+ for (const [index, face] of wanted.entries()) {
148
+ setBusy(`Downloading ${index + 1} of ${wanted.length}…`);
149
+ // oxlint-disable-next-line no-await-in-loop -- one request at a time, with progress
150
+ const got = await importGoogleFont(fetcher, {
151
+ family: name,
152
+ ...face,
153
+ subsets: ["latin", ...subsets],
154
+ });
155
+ added = mergeFaces(added, got);
156
+ }
157
+ } catch (failure) {
158
+ setError(failure instanceof Error ? failure.message : "Couldn't download the font.");
159
+ setBusy(null);
160
+ return;
161
+ }
162
+ setBusy(null);
163
+ await save(
164
+ {
165
+ ...font,
166
+ value: stackWithFamily(font.value, name),
167
+ family: name,
168
+ faces: mergeFaces(font.family === name ? faces : [], added),
169
+ source: "google",
170
+ },
171
+ `Downloaded ${name}. Pages load it from this site.`,
172
+ );
173
+ };
174
+
175
+ const removeFace = (w: number, s: string) => {
176
+ const left = faces.filter((face) => !(face.weight === w && face.style === s));
177
+ const { family: _family, faces: _faces, source: _source, ...plain } = font;
178
+ void save(left.length > 0 ? { ...font, faces: left } : plain, `Removed ${faceLabel(w, s)}.`);
179
+ };
180
+
181
+ const previewCss = fontFaceRules(font).join("");
182
+ return (
183
+ <div className="emvb-site-item-body emvb-font-faces" data-emvb-font-faces="">
184
+ {previewCss ? <style>{previewCss}</style> : null}
185
+ <h4 className="emvb-bind-label">Custom font</h4>
186
+ {font.family && groups.length > 0 ? (
187
+ <>
188
+ <p className="emvb-helper" data-emvb-font-family="">
189
+ {`${font.family} · ${font.source === "google" ? "from Google Fonts, " : ""}served by this site`}
190
+ </p>
191
+ <ul className="emvb-font-face-list" data-emvb-font-face-list="">
192
+ {groups.map((group) => (
193
+ <li
194
+ key={`${group.weight}/${group.style}`}
195
+ data-emvb-font-face={`${group.weight}/${group.style}`}
196
+ >
197
+ <span
198
+ style={{
199
+ fontFamily: `'${font.family}'`,
200
+ fontWeight: group.weight,
201
+ fontStyle: group.style,
202
+ }}
203
+ >
204
+ {faceLabel(group.weight, group.style)}
205
+ </span>
206
+ {group.files > 1 ? (
207
+ <span className="emvb-helper">{` · ${group.files} files`}</span>
208
+ ) : null}
209
+ <button
210
+ type="button"
211
+ className="emvb-site-menu-btn"
212
+ aria-label={`Remove ${faceLabel(group.weight, group.style)}`}
213
+ onClick={() => removeFace(group.weight, group.style)}
214
+ >
215
+ <TrashIcon size={14} aria-hidden="true" />
216
+ </button>
217
+ </li>
218
+ ))}
219
+ </ul>
220
+ </>
221
+ ) : (
222
+ <p className="emvb-helper">
223
+ Upload WOFF2 files or download a Google font. Pages load it from this site only.
224
+ </p>
225
+ )}
226
+ {!font.family && (
227
+ <Input
228
+ label="Font family name"
229
+ className={FIELD}
230
+ value={family}
231
+ data-emvb-font-family-input=""
232
+ onChange={(event) => setFamily(event.target.value)}
233
+ />
234
+ )}
235
+ <div className="emvb-font-face-row">
236
+ <PanelSelect
237
+ label="Weight"
238
+ value={weight}
239
+ data={{ "data-emvb-font-weight": "" }}
240
+ options={GOOGLE_WEIGHTS.map((w) => ({ value: String(w), label: faceLabel(w, "normal") }))}
241
+ onChange={setWeight}
242
+ />
243
+ <PanelSelect
244
+ label="Style"
245
+ value={style}
246
+ data={{ "data-emvb-font-style": "" }}
247
+ options={[
248
+ { value: "normal", label: "Normal" },
249
+ { value: "italic", label: "Italic" },
250
+ ]}
251
+ onChange={(value) => setStyle(value === "italic" ? "italic" : "normal")}
252
+ />
253
+ </div>
254
+ <Button
255
+ type="button"
256
+ variant="secondary"
257
+ size="sm"
258
+ className={BUTTON}
259
+ icon={<UploadSimpleIcon size={14} aria-hidden="true" />}
260
+ disabled={busy !== null}
261
+ onClick={() => fileRef.current?.click()}
262
+ >
263
+ Upload WOFF2
264
+ </Button>
265
+ <input
266
+ ref={fileRef}
267
+ type="file"
268
+ accept=".woff2,font/woff2"
269
+ hidden
270
+ data-emvb-font-upload=""
271
+ onChange={(event) => {
272
+ const file = event.target.files?.[0];
273
+ event.target.value = "";
274
+ if (file) void upload(file);
275
+ }}
276
+ />
277
+ <h4 className="emvb-bind-label" id={`${id}-google`}>
278
+ Google font
279
+ </h4>
280
+ <Input
281
+ label="Family"
282
+ className={FIELD}
283
+ placeholder="Open Sans"
284
+ value={google}
285
+ data-emvb-font-google=""
286
+ onChange={(event) => setGoogle(event.target.value)}
287
+ />
288
+ <fieldset className="emvb-font-weights" aria-labelledby={`${id}-google`}>
289
+ <legend className="emvb-bind-label">Weights</legend>
290
+ {GOOGLE_WEIGHTS.map((w) => (
291
+ <Checkbox
292
+ key={w}
293
+ label={String(w)}
294
+ checked={weights.includes(w)}
295
+ onCheckedChange={(checked) =>
296
+ setWeights((now) =>
297
+ checked
298
+ ? [...new Set([...now, w])].toSorted((a, b) => a - b)
299
+ : now.filter((x) => x !== w),
300
+ )
301
+ }
302
+ />
303
+ ))}
304
+ </fieldset>
305
+ <Checkbox label="Italic too" checked={italic} onCheckedChange={setItalic} />
306
+ <fieldset className="emvb-font-weights">
307
+ <legend className="emvb-bind-label">Also for</legend>
308
+ {EXTRA_SUBSETS.map((subset) => (
309
+ <Checkbox
310
+ key={subset.value}
311
+ label={subset.label}
312
+ checked={subsets.includes(subset.value)}
313
+ onCheckedChange={(checked) =>
314
+ setSubsets((now) =>
315
+ checked ? [...now, subset.value] : now.filter((x) => x !== subset.value),
316
+ )
317
+ }
318
+ />
319
+ ))}
320
+ </fieldset>
321
+ <Button
322
+ type="button"
323
+ variant="secondary"
324
+ size="sm"
325
+ className={BUTTON}
326
+ disabled={busy !== null}
327
+ data-emvb-font-google-go=""
328
+ onClick={() => void download()}
329
+ >
330
+ Download from Google Fonts
331
+ </Button>
332
+ <p className="emvb-helper">
333
+ The files are copied to this site once; visitors never contact Google. Google fonts are open
334
+ source (mostly the SIL Open Font License), so self-hosting them is allowed.
335
+ </p>
336
+ <p className="emvb-helper" aria-live="polite" data-emvb-font-status="">
337
+ {busy ?? done ?? ""}
338
+ </p>
339
+ {error ? <InlineError>{error}</InlineError> : null}
340
+ </div>
341
+ );
342
+ }
@@ -1,4 +1,4 @@
1
- import { CaretDownIcon, CaretRightIcon, DotsThreeIcon } from "@phosphor-icons/react";
1
+ import { CaretDownIcon, CaretRightIcon, DotsThreeIcon, ProhibitIcon } from "@phosphor-icons/react";
2
2
  import * as React from "react";
3
3
  import {
4
4
  firstChild,
@@ -21,6 +21,7 @@ import { ELEMENT_NAMES, elementIcon } from "../element-chrome.ts";
21
21
  import { editorCommands } from "../editor-commands.ts";
22
22
  import { dragStash } from "../dnd/drag-stash.ts";
23
23
  import { StateDot } from "./settings/StateSwitcher.tsx";
24
+ import { useLayersDrop, type LayersDropCallbacks } from "./use-layers-drop.ts";
24
25
  import type { ClipboardActions } from "../useClipboardActions.ts";
25
26
 
26
27
  /**
@@ -199,11 +200,14 @@ export function layerPreview(node: LayoutNode): string | undefined {
199
200
  export function LayersPanel({
200
201
  layout,
201
202
  selectedId,
203
+ onDropNew,
204
+ onMoveTo,
202
205
  ...actions
203
206
  }: {
204
207
  layout: Layout | null;
205
208
  selectedId: string | null;
206
- } & LayerActions) {
209
+ } & LayerActions &
210
+ LayersDropCallbacks) {
207
211
  const [collapsed, setCollapsed] = React.useState<Set<string>>(() => new Set());
208
212
  const [menuId, setMenuId] = React.useState<string | null>(null);
209
213
  const listRef = React.useRef<HTMLUListElement>(null);
@@ -230,6 +234,29 @@ export function LayersPanel({
230
234
  [],
231
235
  );
232
236
  const toggle = React.useMemo(() => toggleIn(setCollapsed), []);
237
+ const expand = React.useCallback(
238
+ (id: string) =>
239
+ setCollapsed((current) => {
240
+ if (!current.has(id)) return current;
241
+ const next = new Set(current);
242
+ next.delete(id);
243
+ return next;
244
+ }),
245
+ [],
246
+ );
247
+ const items = layout ? rows(layout.root, 0, collapsed) : [];
248
+ const drag = useLayersDrop(
249
+ {
250
+ layout,
251
+ depths: new Map(items.map((row) => [row.node.id, row.depth])),
252
+ collapsed,
253
+ expand,
254
+ onDropNew,
255
+ onMoveTo,
256
+ },
257
+ layerIndent,
258
+ listRef,
259
+ );
233
260
 
234
261
  // W-612: an open row menu closes when a press lands outside it, focus leaves the panel's
235
262
  // window (a click in the canvas frame), or focus moves out of it (Tab).
@@ -279,11 +306,10 @@ export function LayersPanel({
279
306
  }, [selectedId]);
280
307
 
281
308
  if (!layout) return <p className="emvb-helper">This page is empty.</p>;
282
-
283
- const items = rows(layout.root, 0, collapsed);
309
+ const shown = drag.shown;
284
310
 
285
311
  return (
286
- <div className="emvb-panel-body" data-emvb-panel="layers">
312
+ <div className="emvb-panel-body emvb-layers-body" data-emvb-panel="layers" {...drag.handlers}>
287
313
  <ul
288
314
  ref={listRef}
289
315
  className="emvb-layers"
@@ -315,9 +341,29 @@ export function LayersPanel({
315
341
  actions={rowActions}
316
342
  hasClipboard={!!actions.clipboard}
317
343
  clip={menuId === node.id ? actions.clipboard : undefined}
344
+ dropMark={shown?.mark?.id === node.id ? shown.mark.kind : undefined}
318
345
  />
319
346
  ))}
320
347
  </ul>
348
+ {shown?.line && (
349
+ <div
350
+ className="emvb-layer-drop-line"
351
+ data-emvb-layer-drop-line=""
352
+ aria-hidden="true"
353
+ style={{ top: shown.line.top, insetInlineStart: shown.line.start }}
354
+ />
355
+ )}
356
+ {shown?.refusal && (
357
+ <div
358
+ className="emvb-invalid-label emvb-layer-drop-refusal"
359
+ data-emvb-layer-drop-refusal=""
360
+ aria-hidden="true"
361
+ style={{ top: shown.refusal.top, insetInlineStart: shown.refusal.start }}
362
+ >
363
+ <ProhibitIcon size={14} aria-hidden="true" />
364
+ <span>{shown.refusal.reason}</span>
365
+ </div>
366
+ )}
321
367
  </div>
322
368
  );
323
369
  }
@@ -344,6 +390,7 @@ const LayerRow = React.memo(function LayerRow({
344
390
  actions,
345
391
  hasClipboard,
346
392
  clip,
393
+ dropMark,
347
394
  }: {
348
395
  node: LayoutNode;
349
396
  depth: number;
@@ -358,6 +405,8 @@ const LayerRow = React.memo(function LayerRow({
358
405
  hasClipboard: boolean;
359
406
  /** The clipboard, passed only to the row whose menu is open so the other rows stay memoized. */
360
407
  clip: ClipboardActions | undefined;
408
+ /** W-1080: outlined as the drop's container, or as a refused drop. */
409
+ dropMark?: "inside" | "invalid";
361
410
  }) {
362
411
  const onToggle = () => toggleRow(node.id);
363
412
  const onMenu = (open: boolean) => menuRow(node.id, open);
@@ -446,7 +495,8 @@ const LayerRow = React.memo(function LayerRow({
446
495
  <div
447
496
  className="emvb-layer-row"
448
497
  data-emvb-layer={node.id}
449
- style={{ paddingLeft: layerIndent(depth) }}
498
+ data-emvb-drop={dropMark}
499
+ style={{ paddingInlineStart: layerIndent(depth) }}
450
500
  onClick={() => actions.onSelect(node.id)}
451
501
  >
452
502
  {hasChildren ? (