@perkyzz/emvb 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -2
  3. package/THIRD_PARTY_NOTICES.md +32 -0
  4. package/licenses/fontawesome-free.LICENSE +165 -0
  5. package/licenses/lucide-static.LICENSE +43 -0
  6. package/licenses/remixicon.LICENSE +201 -0
  7. package/licenses/tabler-icons.LICENSE +21 -0
  8. package/package.json +76 -4
  9. package/src/admin/access/RequireEditor.tsx +39 -0
  10. package/src/admin/access/role.ts +36 -0
  11. package/src/admin/access/sidebar-shim.ts +108 -0
  12. package/src/admin/api.ts +75 -0
  13. package/src/admin/content-api.ts +210 -0
  14. package/src/admin/editor/Editor.tsx +532 -0
  15. package/src/admin/editor/EditorOverlay.tsx +66 -0
  16. package/src/admin/editor/ShortcutsDialog.tsx +30 -0
  17. package/src/admin/editor/SmallScreenNotice.tsx +21 -0
  18. package/src/admin/editor/TopBar.tsx +243 -0
  19. package/src/admin/editor/canvas/CanvasFrame.tsx +536 -0
  20. package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
  21. package/src/admin/editor/canvas/DeviceBar.tsx +91 -0
  22. package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
  23. package/src/admin/editor/canvas/SelectionOverlay.tsx +239 -0
  24. package/src/admin/editor/canvas/canvas-events.ts +245 -0
  25. package/src/admin/editor/canvas/state-preview.ts +19 -0
  26. package/src/admin/editor/canvas/tab-reveal.ts +101 -0
  27. package/src/admin/editor/canvas/vnode-react.tsx +69 -0
  28. package/src/admin/editor/clipboard-store.ts +44 -0
  29. package/src/admin/editor/dialogs.tsx +164 -0
  30. package/src/admin/editor/dnd/drag-stash.ts +27 -0
  31. package/src/admin/editor/dnd/drop-target.ts +148 -0
  32. package/src/admin/editor/dnd/new-element.ts +107 -0
  33. package/src/admin/editor/editor-css.ts +625 -0
  34. package/src/admin/editor/exit.ts +27 -0
  35. package/src/admin/editor/host.ts +30 -0
  36. package/src/admin/editor/icons/IconLibraryDialog.tsx +850 -0
  37. package/src/admin/editor/icons/library.ts +243 -0
  38. package/src/admin/editor/icons/set-format.ts +29 -0
  39. package/src/admin/editor/icons/sets/fontawesome.json +1 -0
  40. package/src/admin/editor/icons/sets/lucide.json +1 -0
  41. package/src/admin/editor/icons/sets/remix.json +1 -0
  42. package/src/admin/editor/icons/sets/tabler.json +1 -0
  43. package/src/admin/editor/panels/AddPanel.tsx +146 -0
  44. package/src/admin/editor/panels/ClassesSection.tsx +372 -0
  45. package/src/admin/editor/panels/ColorControl.tsx +477 -0
  46. package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
  47. package/src/admin/editor/panels/ElementPanel.tsx +773 -0
  48. package/src/admin/editor/panels/LayersPanel.tsx +573 -0
  49. package/src/admin/editor/panels/LeftPanel.tsx +81 -0
  50. package/src/admin/editor/panels/PageSettings.tsx +255 -0
  51. package/src/admin/editor/panels/SettingsPanel.tsx +113 -0
  52. package/src/admin/editor/panels/SiteStylesDrawer.tsx +548 -0
  53. package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
  54. package/src/admin/editor/panels/TriggersEditor.tsx +214 -0
  55. package/src/admin/editor/panels/VariableSection.tsx +530 -0
  56. package/src/admin/editor/panels/color-space.ts +195 -0
  57. package/src/admin/editor/panels/settings/AdvancedFields.tsx +119 -0
  58. package/src/admin/editor/panels/settings/BackgroundControls.tsx +418 -0
  59. package/src/admin/editor/panels/settings/BackgroundFill.tsx +221 -0
  60. package/src/admin/editor/panels/settings/BoxControl.tsx +271 -0
  61. package/src/admin/editor/panels/settings/ChoiceGroup.tsx +138 -0
  62. package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
  63. package/src/admin/editor/panels/settings/ClassChipInput.tsx +451 -0
  64. package/src/admin/editor/panels/settings/DraftTextField.tsx +242 -0
  65. package/src/admin/editor/panels/settings/EffectsControls.tsx +354 -0
  66. package/src/admin/editor/panels/settings/FieldBindControl.tsx +119 -0
  67. package/src/admin/editor/panels/settings/FieldControl.tsx +270 -0
  68. package/src/admin/editor/panels/settings/FormBindControl.tsx +106 -0
  69. package/src/admin/editor/panels/settings/IconControls.tsx +438 -0
  70. package/src/admin/editor/panels/settings/IconPicker.tsx +170 -0
  71. package/src/admin/editor/panels/settings/ItemList.tsx +199 -0
  72. package/src/admin/editor/panels/settings/LengthRow.tsx +217 -0
  73. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +130 -0
  74. package/src/admin/editor/panels/settings/MediaPicker.tsx +220 -0
  75. package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
  76. package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
  77. package/src/admin/editor/panels/settings/StyleRow.tsx +563 -0
  78. package/src/admin/editor/panels/settings/VariableBinding.tsx +171 -0
  79. package/src/admin/editor/panels/settings/advanced-rules.ts +63 -0
  80. package/src/admin/editor/panels/settings/background-mode.ts +112 -0
  81. package/src/admin/editor/panels/settings/box-link-name.ts +38 -0
  82. package/src/admin/editor/panels/settings/box-sides.ts +153 -0
  83. package/src/admin/editor/panels/settings/button-url.ts +27 -0
  84. package/src/admin/editor/panels/settings/class-suggest.ts +53 -0
  85. package/src/admin/editor/panels/settings/form-names.ts +38 -0
  86. package/src/admin/editor/panels/settings/heading-warning.ts +25 -0
  87. package/src/admin/editor/panels/settings/image-alt.ts +25 -0
  88. package/src/admin/editor/panels/settings/length-units.ts +116 -0
  89. package/src/admin/editor/panels/settings/loop-context.ts +26 -0
  90. package/src/admin/editor/panels/settings/node-props.ts +11 -0
  91. package/src/admin/editor/panels/settings/style-sections.ts +394 -0
  92. package/src/admin/editor/panels/settings/svg-images.ts +14 -0
  93. package/src/admin/editor/panels/site-list.tsx +209 -0
  94. package/src/admin/editor/panels/variable-values.ts +73 -0
  95. package/src/admin/editor/restore-deleted.ts +80 -0
  96. package/src/admin/editor/section-templates.ts +50 -0
  97. package/src/admin/editor/shortcuts.ts +20 -0
  98. package/src/admin/editor/store.ts +240 -0
  99. package/src/admin/editor/useClipboardActions.ts +136 -0
  100. package/src/admin/editor/useEditorCommands.ts +203 -0
  101. package/src/admin/editor/useEditorData.ts +193 -0
  102. package/src/admin/editor/useEditorShortcuts.ts +180 -0
  103. package/src/admin/editor/useMediaQuery.ts +20 -0
  104. package/src/admin/editor/useNodeActions.ts +184 -0
  105. package/src/admin/editor/useSave.ts +242 -0
  106. package/src/admin/entry-status.ts +19 -0
  107. package/src/admin/forms-api.ts +73 -0
  108. package/src/admin/icon-uploads-api.ts +44 -0
  109. package/src/admin/index.tsx +20 -0
  110. package/src/admin/media-api.ts +68 -0
  111. package/src/admin/pages/CreateDialog.tsx +150 -0
  112. package/src/admin/pages/EditorPage.tsx +57 -0
  113. package/src/admin/pages/NewPageDialog.tsx +83 -0
  114. package/src/admin/pages/NewThemePartDialog.tsx +61 -0
  115. package/src/admin/pages/PageList.tsx +91 -0
  116. package/src/admin/pages/PagesPage.tsx +25 -0
  117. package/src/admin/pages/SetupShell.tsx +90 -0
  118. package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
  119. package/src/admin/pages/ThemePartList.tsx +221 -0
  120. package/src/admin/pages/list-kit.tsx +125 -0
  121. package/src/admin/setup/plan.ts +150 -0
  122. package/src/admin/setup/run.ts +61 -0
  123. package/src/admin/setup/spec.ts +107 -0
  124. package/src/admin/setup/useSetupStatus.ts +62 -0
  125. package/src/admin/theme-api.ts +233 -0
  126. package/src/admin/ui.ts +244 -0
  127. package/src/admin/widgets/LayoutField.tsx +67 -0
  128. package/src/astro/EmVBPage.astro +63 -0
  129. package/src/astro/env.d.ts +5 -0
  130. package/src/astro/floats/EmVBFloatsRuntime.astro +9 -0
  131. package/src/astro/floats/index.ts +1 -0
  132. package/src/astro/floats/runtime.ts +78 -0
  133. package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
  134. package/src/astro/forms/index.ts +1 -0
  135. package/src/astro/forms-definitions.ts +126 -0
  136. package/src/astro/index.ts +16 -0
  137. package/src/astro/menu/EmVBMenuRuntime.astro +9 -0
  138. package/src/astro/menu/index.ts +1 -0
  139. package/src/astro/menu/runtime.ts +37 -0
  140. package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
  141. package/src/astro/popups/index.ts +1 -0
  142. package/src/astro/popups/runtime.ts +296 -0
  143. package/src/astro/render.ts +108 -0
  144. package/src/astro/resolve-theme.ts +515 -0
  145. package/src/astro/resolve.ts +65 -0
  146. package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
  147. package/src/astro/tabs/index.ts +1 -0
  148. package/src/astro/tabs/runtime.ts +116 -0
  149. package/src/astro/theme-context.ts +89 -0
  150. package/src/astro/theme-posts.ts +84 -0
  151. package/src/constants.ts +12 -0
  152. package/src/core/arrange.ts +448 -0
  153. package/src/core/clipboard.ts +504 -0
  154. package/src/core/css/generate.ts +236 -0
  155. package/src/core/css/scope.ts +88 -0
  156. package/src/core/design/cascade.ts +28 -0
  157. package/src/core/design/classes.ts +224 -0
  158. package/src/core/design/devices.ts +56 -0
  159. package/src/core/design/states.ts +49 -0
  160. package/src/core/design/transfer.ts +132 -0
  161. package/src/core/design/variables.ts +359 -0
  162. package/src/core/elements/definition.ts +12 -0
  163. package/src/core/elements/dynamic-elements.ts +225 -0
  164. package/src/core/elements/field-id.ts +6 -0
  165. package/src/core/elements/form-elements.ts +219 -0
  166. package/src/core/elements/index.ts +960 -0
  167. package/src/core/elements/menu.ts +190 -0
  168. package/src/core/elements/plain-text.ts +32 -0
  169. package/src/core/forms/binding.ts +61 -0
  170. package/src/core/forms/definition.ts +45 -0
  171. package/src/core/forms/success-layout.ts +63 -0
  172. package/src/core/icons/catalog.ts +273 -0
  173. package/src/core/index.ts +380 -0
  174. package/src/core/limits.ts +9 -0
  175. package/src/core/migrate/index.ts +126 -0
  176. package/src/core/nesting.ts +51 -0
  177. package/src/core/render/context.ts +21 -0
  178. package/src/core/render/dynamic-post.ts +175 -0
  179. package/src/core/render/extras.ts +98 -0
  180. package/src/core/render/form.ts +235 -0
  181. package/src/core/render/index.ts +372 -0
  182. package/src/core/render/loop.ts +43 -0
  183. package/src/core/render/pagination.ts +76 -0
  184. package/src/core/render/section.ts +37 -0
  185. package/src/core/render/tabs.ts +76 -0
  186. package/src/core/render/vnode.ts +87 -0
  187. package/src/core/sanitize/css.ts +771 -0
  188. package/src/core/sanitize/embed-url.ts +160 -0
  189. package/src/core/sanitize/escape.ts +10 -0
  190. package/src/core/sanitize/href.ts +6 -0
  191. package/src/core/sanitize/media-url.ts +7 -0
  192. package/src/core/sanitize/svg-upload.ts +203 -0
  193. package/src/core/sanitize/svg.ts +374 -0
  194. package/src/core/sanitize/url.ts +31 -0
  195. package/src/core/schema/descriptors.ts +37 -0
  196. package/src/core/schema/design.ts +93 -0
  197. package/src/core/schema/layout.ts +1008 -0
  198. package/src/core/schema/state-names.ts +4 -0
  199. package/src/core/schema/style.ts +336 -0
  200. package/src/core/stats.ts +18 -0
  201. package/src/core/tabs/presence.ts +25 -0
  202. package/src/core/theme/conditions.ts +324 -0
  203. package/src/core/theme/dynamic.ts +143 -0
  204. package/src/core/theme/float.ts +113 -0
  205. package/src/core/theme/pagination.ts +97 -0
  206. package/src/core/theme/parse-doc.ts +36 -0
  207. package/src/core/theme/part-types.ts +81 -0
  208. package/src/core/theme/popup-markup.ts +41 -0
  209. package/src/core/theme/popup-rules.ts +62 -0
  210. package/src/core/theme/triggers.ts +104 -0
  211. package/src/core/tree-ops.ts +139 -0
  212. package/src/core/validate.ts +185 -0
  213. package/src/index.ts +18 -0
  214. package/src/server/design-routes.ts +125 -0
  215. package/src/server/hooks.ts +118 -0
  216. package/src/server/icon-routes.ts +79 -0
  217. package/src/server/plugin.ts +43 -0
@@ -0,0 +1,438 @@
1
+ import { Button, Select, Switch } from "@cloudflare/kumo";
2
+ import {
3
+ FlipHorizontalIcon,
4
+ FlipVerticalIcon,
5
+ PlusIcon,
6
+ ProhibitIcon,
7
+ } from "@phosphor-icons/react";
8
+ import * as React from "react";
9
+ import type { DesignSystem, StyleProps } from "../../../../core/index.ts";
10
+ import { BUTTON, FIELD } from "../../../ui.ts";
11
+ import { ColorControl } from "../ColorControl.tsx";
12
+ import { radioGroupKeys } from "./ChoiceGroup.tsx";
13
+ import { NumberField, ResetButton, type NumberSpec } from "./NumberRow.tsx";
14
+
15
+ /** W-237: the Icon section's own controls (glyph rotation, flip, drop shadow, loop). */
16
+
17
+ type Flip = NonNullable<StyleProps["iconFlip"]>;
18
+ type IconShadow = NonNullable<StyleProps["iconShadow"]>;
19
+ type IconAnimation = NonNullable<StyleProps["iconAnimation"]>;
20
+
21
+ const ICON_ROTATE: NumberSpec = {
22
+ min: -360,
23
+ max: 360,
24
+ integer: true,
25
+ example: "45",
26
+ suffix: "°",
27
+ placeholder: "0",
28
+ };
29
+ export const ICON_SCALE: NumberSpec = {
30
+ min: 0.1,
31
+ max: 4,
32
+ example: "1.2",
33
+ suffix: "×",
34
+ placeholder: "1",
35
+ };
36
+ export const ICON_STROKE: NumberSpec = { min: 0.25, max: 6, example: "1.5", placeholder: "2" };
37
+
38
+ /** Rotation in degrees: a number field over a -360…360 slider. */
39
+ export function IconRotateRow({
40
+ value,
41
+ inherited,
42
+ onChange,
43
+ }: {
44
+ value: number | undefined;
45
+ inherited?: number;
46
+ onChange: (next: number | undefined) => void;
47
+ }) {
48
+ const set = value !== undefined;
49
+ return (
50
+ <div
51
+ className="emvb-style-row"
52
+ data-emvb-style="iconRotate"
53
+ data-set={set ? "true" : undefined}
54
+ data-inherited={!set && inherited !== undefined ? "true" : undefined}
55
+ >
56
+ <div className="emvb-length-stack">
57
+ <NumberField
58
+ fieldKey="iconRotate"
59
+ label="Rotate"
60
+ value={value}
61
+ spec={ICON_ROTATE}
62
+ inherited={inherited}
63
+ onCommit={onChange}
64
+ />
65
+ <input
66
+ className="emvb-gap-slider"
67
+ type="range"
68
+ min={-360}
69
+ max={360}
70
+ step={1}
71
+ aria-label="Rotate slider"
72
+ value={value ?? inherited ?? 0}
73
+ onChange={(event) => onChange(Number(event.target.value))}
74
+ />
75
+ </div>
76
+ <ResetButton label="Rotate" set={set} onReset={() => onChange(undefined)} />
77
+ </div>
78
+ );
79
+ }
80
+
81
+ const flipParts = (flip: Flip | undefined) => ({
82
+ h: flip === "horizontal" || flip === "both",
83
+ v: flip === "vertical" || flip === "both",
84
+ });
85
+
86
+ /** Two toggles stored as one value; both off saves `none` so a device can undo Desktop's flip. */
87
+ export function IconFlipRow({
88
+ value,
89
+ inherited,
90
+ onChange,
91
+ }: {
92
+ value: Flip | undefined;
93
+ inherited?: Flip;
94
+ onChange: (next: Flip | undefined) => void;
95
+ }) {
96
+ const set = value !== undefined;
97
+ const { h, v } = flipParts(value ?? inherited);
98
+ const pick = (nextH: boolean, nextV: boolean) =>
99
+ onChange(nextH && nextV ? "both" : nextH ? "horizontal" : nextV ? "vertical" : "none");
100
+ return (
101
+ <div
102
+ className="emvb-style-row"
103
+ data-emvb-style="iconFlip"
104
+ data-set={set ? "true" : undefined}
105
+ data-inherited={!set && inherited !== undefined ? "true" : undefined}
106
+ >
107
+ <div className="emvb-choice">
108
+ <span className="emvb-choice-label">Flip</span>
109
+ <div className="emvb-choice-group" role="group" aria-label="Flip">
110
+ <button
111
+ type="button"
112
+ aria-pressed={h}
113
+ aria-label="Flip horizontal"
114
+ title="Flip horizontal"
115
+ data-emvb-flip="horizontal"
116
+ onClick={() => pick(!h, v)}
117
+ >
118
+ <FlipHorizontalIcon size={16} aria-hidden="true" />
119
+ </button>
120
+ <button
121
+ type="button"
122
+ aria-pressed={v}
123
+ aria-label="Flip vertical"
124
+ title="Flip vertical"
125
+ data-emvb-flip="vertical"
126
+ onClick={() => pick(h, !v)}
127
+ >
128
+ <FlipVerticalIcon size={16} aria-hidden="true" />
129
+ </button>
130
+ </div>
131
+ </div>
132
+ <ResetButton label="Flip" set={set} onReset={() => onChange(undefined)} />
133
+ </div>
134
+ );
135
+ }
136
+
137
+ /** Add drop shadow starts at 0 2 4, 25 % black: soft, and it follows the glyph's outline. */
138
+ const NEW_ICON_SHADOW: IconShadow = { x: 0, y: 2, blur: 4, color: "#00000040" };
139
+ const SHADOW_OFFSET: NumberSpec = { min: -100, max: 100, example: "2" };
140
+ const ICON_SHADOW_FIELDS: ReadonlyArray<[key: "x" | "y" | "blur", label: string, NumberSpec]> = [
141
+ ["x", "Horizontal", SHADOW_OFFSET],
142
+ ["y", "Vertical", SHADOW_OFFSET],
143
+ ["blur", "Blur", { min: 0, max: 100, example: "4" }],
144
+ ];
145
+
146
+ export function IconShadowControl({
147
+ value,
148
+ design,
149
+ onChange,
150
+ onDesignChange,
151
+ }: {
152
+ value: IconShadow | undefined;
153
+ design: DesignSystem;
154
+ onChange: (next: IconShadow | undefined) => void;
155
+ onDesignChange: (design: DesignSystem) => Promise<void>;
156
+ }) {
157
+ const patch = (part: Partial<IconShadow>) => {
158
+ if (!value) return;
159
+ const next: Record<string, unknown> = { ...value, ...part };
160
+ for (const key of Object.keys(next)) if (next[key] === undefined) delete next[key];
161
+ onChange(next as IconShadow);
162
+ };
163
+ return (
164
+ <div
165
+ className="emvb-style-row"
166
+ data-emvb-style="iconShadow"
167
+ data-set={value ? "true" : undefined}
168
+ >
169
+ <div className="emvb-field-group emvb-shadow">
170
+ <span className="emvb-var-field-label">Drop shadow</span>
171
+ {value ? (
172
+ <>
173
+ <ColorControl
174
+ label="Drop shadow color"
175
+ value={value.color}
176
+ design={design}
177
+ onChange={(color) => patch({ color })}
178
+ onDesignChange={onDesignChange}
179
+ />
180
+ <div className="emvb-shadow-grid">
181
+ {ICON_SHADOW_FIELDS.map(([key, label, spec]) => (
182
+ <NumberField
183
+ key={key}
184
+ fieldKey={`iconShadow.${key}`}
185
+ label={label}
186
+ value={value[key]}
187
+ spec={spec}
188
+ onCommit={(n) => patch({ [key]: n ?? 0 })}
189
+ />
190
+ ))}
191
+ </div>
192
+ </>
193
+ ) : (
194
+ <Button
195
+ type="button"
196
+ variant="secondary"
197
+ className={`${BUTTON} emvb-add-shadow`}
198
+ icon={<PlusIcon aria-hidden="true" />}
199
+ onClick={() => onChange(NEW_ICON_SHADOW)}
200
+ >
201
+ Add drop shadow
202
+ </Button>
203
+ )}
204
+ </div>
205
+ <ResetButton
206
+ label="Drop shadow"
207
+ set={value !== undefined}
208
+ onReset={() => onChange(undefined)}
209
+ />
210
+ </div>
211
+ );
212
+ }
213
+
214
+ const DURATION: NumberSpec = {
215
+ min: 200,
216
+ max: 10_000,
217
+ integer: true,
218
+ example: "2000",
219
+ suffix: "ms",
220
+ };
221
+ type Looping = Extract<IconAnimation, { duration: number }>;
222
+ const DEFAULT_DURATION: Record<Looping["type"], number> = { spin: 2000, pulse: 1000 };
223
+
224
+ const looping = (a: IconAnimation | undefined): Looping | undefined =>
225
+ a && a.type !== "none" ? a : undefined;
226
+
227
+ /** A looping spin or pulse (Normal only); visitors who prefer reduced motion see it still. */
228
+ const ANIMATION_LABELS: Record<string, string> = { none: "None", spin: "Spin", pulse: "Pulse" };
229
+
230
+ /**
231
+ * W-248: on Tablet or Mobile, `inherited` is the animation from a wider device. With nothing set
232
+ * here the select shows it, and None stores `{ type: "none" }` so the device can stop it.
233
+ */
234
+ export function IconAnimationControl({
235
+ value,
236
+ inherited,
237
+ onChange,
238
+ }: {
239
+ value: IconAnimation | undefined;
240
+ inherited?: IconAnimation;
241
+ onChange: (next: IconAnimation | undefined) => void;
242
+ }) {
243
+ const own = looping(value);
244
+ const from = looping(inherited);
245
+ const shown = value?.type ?? inherited?.type ?? "none";
246
+ const [type, setType] = React.useState<string>(shown);
247
+ React.useEffect(() => setType(shown), [shown]);
248
+ return (
249
+ <div
250
+ className="emvb-style-row"
251
+ data-emvb-style="iconAnimation"
252
+ data-set={value ? "true" : undefined}
253
+ data-inherited={!value && from ? "true" : undefined}
254
+ >
255
+ <div className="emvb-field-group">
256
+ <Select
257
+ label="Animation"
258
+ className={FIELD}
259
+ value={type}
260
+ renderValue={(v: unknown) => ANIMATION_LABELS[String(v)] ?? "None"}
261
+ onValueChange={(next) => {
262
+ const picked = String(next);
263
+ setType(picked);
264
+ if (picked === "spin" || picked === "pulse") {
265
+ const duration = own?.duration ?? from?.duration ?? DEFAULT_DURATION[picked];
266
+ onChange({ type: picked, duration });
267
+ } else onChange(from ? { type: "none" } : undefined);
268
+ }}
269
+ >
270
+ <Select.Option value="none">None</Select.Option>
271
+ <Select.Option value="spin">Spin</Select.Option>
272
+ <Select.Option value="pulse">Pulse</Select.Option>
273
+ </Select>
274
+ {own && (
275
+ <NumberField
276
+ fieldKey="iconAnimation.duration"
277
+ label="Duration"
278
+ value={own.duration}
279
+ spec={DURATION}
280
+ onCommit={(n) => onChange({ ...own, duration: n ?? DEFAULT_DURATION[own.type] })}
281
+ />
282
+ )}
283
+ {own && <p className="emvb-helper">Off for visitors who prefer reduced motion.</p>}
284
+ {!value && from && (
285
+ <p className="emvb-helper">
286
+ Inherited from a wider device ({ANIMATION_LABELS[from.type]}, {from.duration} ms). Pick
287
+ None to stop it on this one.
288
+ </p>
289
+ )}
290
+ {value?.type === "none" && from && (
291
+ <p className="emvb-helper">Stopped on this device. Reset to inherit it again.</p>
292
+ )}
293
+ </div>
294
+ <ResetButton
295
+ label="Animation"
296
+ set={value !== undefined}
297
+ onReset={() => onChange(undefined)}
298
+ />
299
+ </div>
300
+ );
301
+ }
302
+
303
+ /** W-238: Force single colour, a content prop shown under Colour for multi-colour SVGs. */
304
+ export function IconSingleColorRow({
305
+ checked,
306
+ onChange,
307
+ }: {
308
+ checked: boolean;
309
+ onChange: (next: boolean) => void;
310
+ }) {
311
+ return (
312
+ <div className="emvb-field-group" data-emvb-icon-single-color="">
313
+ <Switch label="Force single color" checked={checked} onCheckedChange={onChange} />
314
+ <p className="emvb-helper">
315
+ {checked
316
+ ? "Every part of this SVG uses the icon color, so details drawn over filled shapes can disappear."
317
+ : "This SVG keeps its own colors. Turn on to paint it in the icon color."}
318
+ </p>
319
+ </div>
320
+ );
321
+ }
322
+
323
+ type IconShape = "none" | "circle" | "rounded" | "square";
324
+
325
+ const SHAPE_PADDING = { value: 12, unit: "px" } as const;
326
+ /** A light neutral, so the default icon colour (the text colour) reads on it. */
327
+ const SHAPE_BACKGROUND = "#f1f5f9";
328
+ const SHAPE_RADIUS: Record<Exclude<IconShape, "none">, StyleProps["borderRadius"]> = {
329
+ circle: { value: 50, unit: "%" },
330
+ rounded: { value: 12, unit: "px" },
331
+ square: { value: 0, unit: "px" },
332
+ };
333
+ const PADDINGS = ["paddingTop", "paddingRight", "paddingBottom", "paddingLeft"] as const;
334
+ const CORNERS = [
335
+ "borderTopLeftRadius",
336
+ "borderTopRightRadius",
337
+ "borderBottomRightRadius",
338
+ "borderBottomLeftRadius",
339
+ ] as const;
340
+
341
+ /** The shape the styles in effect make: a background or border, and the corner radius. */
342
+ function iconShapeOf(style: StyleProps | undefined): IconShape {
343
+ if (!style || (style.backgroundColor === undefined && style.borderWidth === undefined))
344
+ return "none";
345
+ const radius = style.borderRadius;
346
+ if (radius && typeof radius === "object" && "value" in radius) {
347
+ if (radius.unit === "%" && radius.value >= 50) return "circle";
348
+ if (radius.value === 0) return "square";
349
+ return "rounded";
350
+ }
351
+ return radius === undefined ? "square" : "rounded";
352
+ }
353
+
354
+ /**
355
+ * The patch a shape choice makes (Elementor's Shape: None, Circle, Rounded, Square). A shape
356
+ * keeps a background or border already set, and adds 12 px padding only where none is set.
357
+ * None clears the background, radius and padding it would have added.
358
+ */
359
+ function iconShapePatch(shape: IconShape, style: StyleProps | undefined): Partial<StyleProps> {
360
+ const patch: Partial<StyleProps> = {};
361
+ for (const corner of CORNERS) if (style?.[corner] !== undefined) patch[corner] = undefined;
362
+ if (shape === "none") {
363
+ patch.backgroundColor = undefined;
364
+ patch.borderRadius = undefined;
365
+ for (const side of PADDINGS) patch[side] = undefined;
366
+ return patch;
367
+ }
368
+ if (style?.backgroundColor === undefined && style?.borderWidth === undefined)
369
+ patch.backgroundColor = SHAPE_BACKGROUND;
370
+ patch.borderRadius = SHAPE_RADIUS[shape];
371
+ if (PADDINGS.every((side) => style?.[side] === undefined))
372
+ for (const side of PADDINGS) patch[side] = SHAPE_PADDING;
373
+ return patch;
374
+ }
375
+
376
+ const SHAPES: { value: IconShape; label: string }[] = [
377
+ { value: "none", label: "None" },
378
+ { value: "circle", label: "Circle" },
379
+ { value: "rounded", label: "Rounded square" },
380
+ { value: "square", label: "Square" },
381
+ ];
382
+
383
+ /** Background shape presets; colour, padding and border stay editable in their sections. */
384
+ export function IconShapeRow({
385
+ style,
386
+ inherited,
387
+ onPatch,
388
+ }: {
389
+ style: StyleProps | undefined;
390
+ inherited?: StyleProps;
391
+ onPatch: (patch: Partial<StyleProps>) => void;
392
+ }) {
393
+ const effective = { ...inherited, ...style };
394
+ const current = iconShapeOf(effective);
395
+ const keys = radioGroupKeys(
396
+ SHAPES.map((shape) => shape.value),
397
+ current,
398
+ (value) => onPatch(iconShapePatch(value as IconShape, effective)),
399
+ );
400
+ return (
401
+ <div className="emvb-style-row" data-emvb-icon-shape={current}>
402
+ <div className="emvb-choice">
403
+ <span className="emvb-choice-label" id="emvb-icon-shape-label">
404
+ Shape
405
+ </span>
406
+ <div
407
+ className="emvb-choice-group"
408
+ role="radiogroup"
409
+ aria-labelledby="emvb-icon-shape-label"
410
+ onKeyDown={keys.onKeyDown}
411
+ >
412
+ {SHAPES.map((shape) => (
413
+ <button
414
+ key={shape.value}
415
+ type="button"
416
+ role="radio"
417
+ aria-checked={current === shape.value}
418
+ aria-label={shape.label}
419
+ title={shape.label}
420
+ data-emvb-choice={shape.value}
421
+ tabIndex={keys.tabIndexOf(shape.value)}
422
+ onClick={() => onPatch(iconShapePatch(shape.value, effective))}
423
+ >
424
+ {shape.value === "none" ? (
425
+ <ProhibitIcon size={16} aria-hidden="true" />
426
+ ) : (
427
+ <span className="emvb-shape-swatch" data-shape={shape.value} aria-hidden="true" />
428
+ )}
429
+ </button>
430
+ ))}
431
+ </div>
432
+ <p className="emvb-helper">
433
+ Color, padding and border: Background, Spacing and Border below.
434
+ </p>
435
+ </div>
436
+ </div>
437
+ );
438
+ }
@@ -0,0 +1,170 @@
1
+ import { Button } from "@cloudflare/kumo";
2
+ import * as React from "react";
3
+ import { getBundledIcon, sanitizeSvgMarkup, type LayoutNode } from "../../../../core/index.ts";
4
+ import { serialize, type VNode } from "../../../../core/render/vnode.ts";
5
+ import type { Fetcher } from "../../../api.ts";
6
+ import { BUTTON } from "../../../ui.ts";
7
+ import { IconLibraryDialog } from "../../icons/IconLibraryDialog.tsx";
8
+ import {
9
+ ICON_SETS,
10
+ locateIcon,
11
+ UPLOADS,
12
+ UPLOADS_CATEGORY,
13
+ type LibraryIcon,
14
+ } from "../../icons/library.ts";
15
+
16
+ const propsOf = (node: LayoutNode): Record<string, unknown> =>
17
+ node.props as Record<string, unknown>;
18
+
19
+ const withProps = (node: LayoutNode, patch: Record<string, unknown>): LayoutNode => {
20
+ const props = { ...propsOf(node), ...patch };
21
+ return { ...node, props } as LayoutNode;
22
+ };
23
+
24
+ const preview = (tree: VNode): string =>
25
+ serialize({
26
+ tag: "svg",
27
+ attrs: {
28
+ viewBox: "0 0 24 24",
29
+ ...tree.attrs,
30
+ width: "20",
31
+ height: "20",
32
+ "aria-hidden": "true",
33
+ focusable: "false",
34
+ },
35
+ children: tree.children,
36
+ });
37
+
38
+ /** The 20px preview of the stored icon: its saved SVG, else the bundled glyph. */
39
+ export function currentIconPreview(iconId: string, iconSvg: unknown): string {
40
+ const picked = typeof iconSvg === "string" && iconSvg ? sanitizeSvgMarkup(iconSvg) : undefined;
41
+ if (picked) return preview(picked);
42
+ const bundled = getBundledIcon(iconId);
43
+ if (!bundled) return "";
44
+ return preview({
45
+ tag: "svg",
46
+ attrs: {
47
+ xmlns: "http://www.w3.org/2000/svg",
48
+ fill: "none",
49
+ stroke: "currentColor",
50
+ "stroke-width": "2",
51
+ "stroke-linecap": "round",
52
+ "stroke-linejoin": "round",
53
+ },
54
+ children: bundled.children.map((child) => ({
55
+ tag: child.tag,
56
+ attrs: { ...child.attrs },
57
+ children: [],
58
+ })),
59
+ });
60
+ }
61
+
62
+ /** "fa-solid:arrow-right" → "Arrow right"; a bundled id gives its own label. */
63
+ export function iconNameLabel(iconId: string): string {
64
+ const bundled = getBundledIcon(iconId);
65
+ if (bundled) return bundled.label;
66
+ const name = iconId.slice(iconId.indexOf(":") + 1).replaceAll("-", " ");
67
+ return name.charAt(0).toUpperCase() + name.slice(1);
68
+ }
69
+
70
+ /** "Font Awesome · Solid" for a stored id, or undefined when the id names no known set. */
71
+ function sourceLabel(iconId: string): string | undefined {
72
+ const at = locateIcon(iconId);
73
+ if (!at) return undefined;
74
+ if (at.set === UPLOADS) return UPLOADS_CATEGORY.label;
75
+ const set = ICON_SETS.find((item) => item.id === at.set);
76
+ if (!set) return undefined;
77
+ const style = set.styles.find((item) => item.id === at.style);
78
+ return style && style.label !== set.label ? `${set.label} · ${style.label}` : set.label;
79
+ }
80
+
81
+ /**
82
+ * The Icon element's icon field (W-025 / W-236): the current icon and a button that opens the
83
+ * icon library. Inserting stores the set-prefixed id (so the library reopens on it) and the
84
+ * icon's SVG (so the published page needs no icon set).
85
+ */
86
+ export function IconPicker({
87
+ node,
88
+ fetcher,
89
+ onChange,
90
+ }: {
91
+ node: LayoutNode;
92
+ /** Enables My uploads in the library (W-239). */
93
+ fetcher?: Fetcher;
94
+ onChange: (node: LayoutNode) => void;
95
+ }) {
96
+ const props = propsOf(node);
97
+ const current = typeof props.iconId === "string" ? props.iconId : "";
98
+ const [open, setOpen] = React.useState(false);
99
+ const field = React.useRef<HTMLDivElement | null>(null);
100
+ // However the library closes (Insert, Close, Escape), focus comes back to Choose. Done once the
101
+ // dialog has finished closing: during its exit animation the focus trap still holds focus.
102
+ const refocus = () =>
103
+ field.current?.querySelector<HTMLButtonElement>("[data-emvb-icon-open]")?.focus();
104
+ const markup = currentIconPreview(current, props.iconSvg);
105
+ // An upload's id is random; its title names it (set from the file name on insert).
106
+ const name =
107
+ current && locateIcon(current)?.set === UPLOADS
108
+ ? (typeof props.title === "string" && props.title) || UPLOADS_CATEGORY.label
109
+ : current
110
+ ? iconNameLabel(current)
111
+ : undefined;
112
+ const source = current ? sourceLabel(current) : undefined;
113
+
114
+ const insert = (icon: LibraryIcon) => {
115
+ const title = typeof props.title === "string" ? props.title : "";
116
+ const previous = name?.toLowerCase();
117
+ const patch: Record<string, unknown> = { iconId: icon.id, iconSvg: icon.markup };
118
+ // Keep the title in step with the glyph while it is still a default or the old icon's name
119
+ // (new Icon elements ship title "Star" with iconId "star"); a written title stays.
120
+ if (!title || title === "Icon" || title.toLowerCase() === previous) patch.title = icon.label;
121
+ onChange(withProps(node, patch));
122
+ };
123
+
124
+ return (
125
+ <div ref={field} className="emvb-field-group" data-emvb-field="iconId" data-emvb-icon-picker="">
126
+ <span className="emvb-field-label">Icon</span>
127
+ <div className="emvb-icon-current" data-emvb-icon-current={current}>
128
+ <button
129
+ type="button"
130
+ className="emvb-icon-current-preview"
131
+ aria-label={`Change icon (now ${name ?? "none"})`}
132
+ onClick={() => setOpen(true)}
133
+ >
134
+ {markup ? (
135
+ <span aria-hidden="true" dangerouslySetInnerHTML={{ __html: markup }} />
136
+ ) : (
137
+ <span aria-hidden="true">?</span>
138
+ )}
139
+ </button>
140
+ <span className="emvb-icon-current-text">
141
+ <strong>{name ?? "No icon"}</strong>
142
+ <span>
143
+ {markup
144
+ ? (source ?? "Saved SVG")
145
+ : current
146
+ ? "Not found — choose another"
147
+ : "Choose one"}
148
+ </span>
149
+ </span>
150
+ <Button
151
+ variant="secondary"
152
+ size="sm"
153
+ className={BUTTON}
154
+ data-emvb-icon-open=""
155
+ onClick={() => setOpen(true)}
156
+ >
157
+ Choose…
158
+ </Button>
159
+ </div>
160
+ <IconLibraryDialog
161
+ open={open}
162
+ onOpenChange={setOpen}
163
+ onClosed={refocus}
164
+ currentId={current || undefined}
165
+ fetcher={fetcher}
166
+ onInsert={insert}
167
+ />
168
+ </div>
169
+ );
170
+ }