@perkyzz/emvb 0.0.0-stage → 0.1.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 (170) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +57 -2
  3. package/package.json +72 -4
  4. package/src/admin/access/RequireEditor.tsx +39 -0
  5. package/src/admin/access/role.ts +36 -0
  6. package/src/admin/access/sidebar-shim.ts +108 -0
  7. package/src/admin/api.ts +48 -0
  8. package/src/admin/content-api.ts +147 -0
  9. package/src/admin/editor/Editor.tsx +457 -0
  10. package/src/admin/editor/EditorOverlay.tsx +54 -0
  11. package/src/admin/editor/ShortcutsDialog.tsx +30 -0
  12. package/src/admin/editor/SmallScreenNotice.tsx +20 -0
  13. package/src/admin/editor/TopBar.tsx +179 -0
  14. package/src/admin/editor/canvas/CanvasFrame.tsx +355 -0
  15. package/src/admin/editor/canvas/CanvasTextEdit.tsx +87 -0
  16. package/src/admin/editor/canvas/DeviceBar.tsx +50 -0
  17. package/src/admin/editor/canvas/EmptyCanvas.tsx +49 -0
  18. package/src/admin/editor/canvas/SelectionOverlay.tsx +185 -0
  19. package/src/admin/editor/canvas/canvas-events.ts +232 -0
  20. package/src/admin/editor/canvas/state-preview.ts +19 -0
  21. package/src/admin/editor/canvas/tab-reveal.ts +35 -0
  22. package/src/admin/editor/canvas/vnode-react.tsx +49 -0
  23. package/src/admin/editor/clipboard-store.ts +44 -0
  24. package/src/admin/editor/dialogs.tsx +125 -0
  25. package/src/admin/editor/dnd/drag-stash.ts +27 -0
  26. package/src/admin/editor/dnd/drop-target.ts +101 -0
  27. package/src/admin/editor/dnd/new-element.ts +32 -0
  28. package/src/admin/editor/editor-css.ts +539 -0
  29. package/src/admin/editor/exit.ts +27 -0
  30. package/src/admin/editor/panels/AddPanel.tsx +142 -0
  31. package/src/admin/editor/panels/ClassesSection.tsx +334 -0
  32. package/src/admin/editor/panels/ColorControl.tsx +230 -0
  33. package/src/admin/editor/panels/ConditionsEditor.tsx +201 -0
  34. package/src/admin/editor/panels/ElementPanel.tsx +629 -0
  35. package/src/admin/editor/panels/LayersPanel.tsx +336 -0
  36. package/src/admin/editor/panels/LeftPanel.tsx +77 -0
  37. package/src/admin/editor/panels/PageSettings.tsx +126 -0
  38. package/src/admin/editor/panels/SettingsPanel.tsx +101 -0
  39. package/src/admin/editor/panels/SiteStylesDrawer.tsx +392 -0
  40. package/src/admin/editor/panels/TriggerSettings.tsx +132 -0
  41. package/src/admin/editor/panels/TriggersEditor.tsx +197 -0
  42. package/src/admin/editor/panels/VariableSection.tsx +492 -0
  43. package/src/admin/editor/panels/settings/BackgroundControls.tsx +320 -0
  44. package/src/admin/editor/panels/settings/ClassChip.tsx +167 -0
  45. package/src/admin/editor/panels/settings/ClassChipInput.tsx +349 -0
  46. package/src/admin/editor/panels/settings/DraftTextField.tsx +201 -0
  47. package/src/admin/editor/panels/settings/EffectsControls.tsx +347 -0
  48. package/src/admin/editor/panels/settings/FieldBindControl.tsx +83 -0
  49. package/src/admin/editor/panels/settings/FieldControl.tsx +150 -0
  50. package/src/admin/editor/panels/settings/FormBindControl.tsx +97 -0
  51. package/src/admin/editor/panels/settings/IconPicker.tsx +109 -0
  52. package/src/admin/editor/panels/settings/LengthRow.tsx +181 -0
  53. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +124 -0
  54. package/src/admin/editor/panels/settings/MediaPicker.tsx +218 -0
  55. package/src/admin/editor/panels/settings/NumberRow.tsx +154 -0
  56. package/src/admin/editor/panels/settings/StateSwitcher.tsx +87 -0
  57. package/src/admin/editor/panels/settings/StyleRow.tsx +480 -0
  58. package/src/admin/editor/panels/settings/VariableBinding.tsx +167 -0
  59. package/src/admin/editor/panels/settings/class-suggest.ts +51 -0
  60. package/src/admin/editor/panels/settings/length-units.ts +83 -0
  61. package/src/admin/editor/panels/settings/node-props.ts +11 -0
  62. package/src/admin/editor/panels/settings/style-sections.ts +291 -0
  63. package/src/admin/editor/panels/site-list.tsx +206 -0
  64. package/src/admin/editor/panels/variable-values.ts +73 -0
  65. package/src/admin/editor/section-templates.ts +50 -0
  66. package/src/admin/editor/shortcuts.ts +20 -0
  67. package/src/admin/editor/store.ts +212 -0
  68. package/src/admin/editor/useClipboardActions.ts +136 -0
  69. package/src/admin/editor/useEditorCommands.ts +142 -0
  70. package/src/admin/editor/useEditorData.ts +167 -0
  71. package/src/admin/editor/useEditorShortcuts.ts +148 -0
  72. package/src/admin/editor/useMediaQuery.ts +20 -0
  73. package/src/admin/editor/useNodeActions.ts +122 -0
  74. package/src/admin/editor/useSave.ts +185 -0
  75. package/src/admin/forms-api.ts +73 -0
  76. package/src/admin/index.tsx +20 -0
  77. package/src/admin/media-api.ts +68 -0
  78. package/src/admin/pages/CreateDialog.tsx +150 -0
  79. package/src/admin/pages/EditorPage.tsx +57 -0
  80. package/src/admin/pages/NewPageDialog.tsx +83 -0
  81. package/src/admin/pages/NewThemePartDialog.tsx +61 -0
  82. package/src/admin/pages/PageList.tsx +71 -0
  83. package/src/admin/pages/PagesPage.tsx +25 -0
  84. package/src/admin/pages/SetupShell.tsx +90 -0
  85. package/src/admin/pages/ThemeBuilderPage.tsx +25 -0
  86. package/src/admin/pages/ThemePartList.tsx +202 -0
  87. package/src/admin/pages/list-kit.tsx +75 -0
  88. package/src/admin/setup/plan.ts +150 -0
  89. package/src/admin/setup/run.ts +61 -0
  90. package/src/admin/setup/spec.ts +100 -0
  91. package/src/admin/setup/useSetupStatus.ts +62 -0
  92. package/src/admin/theme-api.ts +186 -0
  93. package/src/admin/ui.ts +231 -0
  94. package/src/admin/widgets/LayoutField.tsx +67 -0
  95. package/src/astro/EmVBPage.astro +37 -0
  96. package/src/astro/env.d.ts +5 -0
  97. package/src/astro/forms/EmVBFormsRuntime.astro +9 -0
  98. package/src/astro/forms/index.ts +1 -0
  99. package/src/astro/forms-definitions.ts +104 -0
  100. package/src/astro/index.ts +15 -0
  101. package/src/astro/popups/EmVBPopupsRuntime.astro +9 -0
  102. package/src/astro/popups/index.ts +1 -0
  103. package/src/astro/popups/runtime.ts +246 -0
  104. package/src/astro/render.ts +74 -0
  105. package/src/astro/resolve-theme.ts +371 -0
  106. package/src/astro/resolve.ts +65 -0
  107. package/src/astro/tabs/EmVBTabsRuntime.astro +10 -0
  108. package/src/astro/tabs/index.ts +1 -0
  109. package/src/astro/tabs/runtime.ts +111 -0
  110. package/src/astro/theme-context.ts +81 -0
  111. package/src/astro/theme-posts.ts +84 -0
  112. package/src/constants.ts +12 -0
  113. package/src/core/arrange.ts +360 -0
  114. package/src/core/clipboard.ts +422 -0
  115. package/src/core/css/generate.ts +219 -0
  116. package/src/core/css/scope.ts +88 -0
  117. package/src/core/design/cascade.ts +28 -0
  118. package/src/core/design/classes.ts +138 -0
  119. package/src/core/design/devices.ts +56 -0
  120. package/src/core/design/states.ts +49 -0
  121. package/src/core/design/transfer.ts +33 -0
  122. package/src/core/design/variables.ts +319 -0
  123. package/src/core/elements/definition.ts +12 -0
  124. package/src/core/elements/dynamic-elements.ts +173 -0
  125. package/src/core/elements/form-elements.ts +204 -0
  126. package/src/core/elements/index.ts +742 -0
  127. package/src/core/elements/plain-text.ts +32 -0
  128. package/src/core/forms/binding.ts +61 -0
  129. package/src/core/forms/definition.ts +34 -0
  130. package/src/core/forms/success-layout.ts +63 -0
  131. package/src/core/icons/catalog.ts +273 -0
  132. package/src/core/index.ts +316 -0
  133. package/src/core/limits.ts +7 -0
  134. package/src/core/migrate/index.ts +76 -0
  135. package/src/core/render/context.ts +14 -0
  136. package/src/core/render/dynamic-post.ts +147 -0
  137. package/src/core/render/extras.ts +79 -0
  138. package/src/core/render/form.ts +137 -0
  139. package/src/core/render/index.ts +274 -0
  140. package/src/core/render/loop.ts +36 -0
  141. package/src/core/render/section.ts +33 -0
  142. package/src/core/render/tabs.ts +72 -0
  143. package/src/core/render/vnode.ts +87 -0
  144. package/src/core/sanitize/css.ts +591 -0
  145. package/src/core/sanitize/embed-url.ts +103 -0
  146. package/src/core/sanitize/escape.ts +10 -0
  147. package/src/core/sanitize/href.ts +6 -0
  148. package/src/core/sanitize/media-url.ts +7 -0
  149. package/src/core/sanitize/svg.ts +293 -0
  150. package/src/core/sanitize/url.ts +31 -0
  151. package/src/core/schema/descriptors.ts +33 -0
  152. package/src/core/schema/design.ts +88 -0
  153. package/src/core/schema/layout.ts +817 -0
  154. package/src/core/schema/state-names.ts +4 -0
  155. package/src/core/schema/style.ts +257 -0
  156. package/src/core/stats.ts +18 -0
  157. package/src/core/tabs/presence.ts +16 -0
  158. package/src/core/theme/conditions.ts +321 -0
  159. package/src/core/theme/dynamic.ts +133 -0
  160. package/src/core/theme/parse-doc.ts +36 -0
  161. package/src/core/theme/part-types.ts +79 -0
  162. package/src/core/theme/popup-markup.ts +39 -0
  163. package/src/core/theme/popup-rules.ts +61 -0
  164. package/src/core/theme/triggers.ts +104 -0
  165. package/src/core/tree-ops.ts +139 -0
  166. package/src/core/validate.ts +185 -0
  167. package/src/index.ts +18 -0
  168. package/src/server/design-routes.ts +125 -0
  169. package/src/server/hooks.ts +98 -0
  170. package/src/server/plugin.ts +39 -0
@@ -0,0 +1,480 @@
1
+ import { Input, Select } from "@cloudflare/kumo";
2
+ import { isSafeFontStack, type DesignSystem, type StyleProps } from "../../../../core/index.ts";
3
+ import type { Fetcher } from "../../../api.ts";
4
+ import { FIELD } from "../../../ui.ts";
5
+ import { ColorControl } from "../ColorControl.tsx";
6
+ import { BackgroundImageControl, GradientControl, OverlayControl } from "./BackgroundControls.tsx";
7
+ import { STYLE_LABELS, type StyleKey } from "./style-sections.ts";
8
+ import { LengthRow } from "./LengthRow.tsx";
9
+ import {
10
+ EntranceControl,
11
+ FiltersControl,
12
+ ShadowControl,
13
+ TransitionControl,
14
+ } from "./EffectsControls.tsx";
15
+ import { NumberRow, ResetButton, type NumberSpec } from "./NumberRow.tsx";
16
+ import { boundRef, VariableButton, VariableChip } from "./VariableBinding.tsx";
17
+
18
+ const LENGTH_KEYS = new Set<StyleKey>([
19
+ "gap",
20
+ "width",
21
+ "minWidth",
22
+ "maxWidth",
23
+ "height",
24
+ "minHeight",
25
+ "maxHeight",
26
+ "paddingTop",
27
+ "paddingRight",
28
+ "paddingBottom",
29
+ "paddingLeft",
30
+ "marginTop",
31
+ "marginRight",
32
+ "marginBottom",
33
+ "marginLeft",
34
+ "top",
35
+ "right",
36
+ "bottom",
37
+ "left",
38
+ "fontSize",
39
+ "lineHeight",
40
+ "letterSpacing",
41
+ "borderWidth",
42
+ "borderRadius",
43
+ ]);
44
+
45
+ const Z_INDEX: NumberSpec = { min: -9999, max: 9999, integer: true, example: "10" };
46
+ const GRID_SPAN: NumberSpec = { min: 1, max: 12, integer: true, example: "2" };
47
+ const OPACITY: NumberSpec = { min: 0, max: 100, scale: 100, example: "50", suffix: "%" };
48
+
49
+ const COLOR_KEYS = new Set<StyleKey>(["color", "backgroundColor", "borderColor"]);
50
+
51
+ const SELECT_OPTIONS: Partial<Record<StyleKey, { value: string; label: string }[]>> = {
52
+ flexDirection: [
53
+ { value: "column", label: "Column" },
54
+ { value: "row", label: "Row" },
55
+ { value: "column-reverse", label: "Column reverse" },
56
+ { value: "row-reverse", label: "Row reverse" },
57
+ ],
58
+ flexWrap: [
59
+ { value: "nowrap", label: "No wrap" },
60
+ { value: "wrap", label: "Wrap" },
61
+ { value: "wrap-reverse", label: "Wrap reverse" },
62
+ ],
63
+ justifyContent: [
64
+ { value: "flex-start", label: "Start" },
65
+ { value: "center", label: "Center" },
66
+ { value: "flex-end", label: "End" },
67
+ { value: "space-between", label: "Space between" },
68
+ { value: "space-around", label: "Space around" },
69
+ { value: "space-evenly", label: "Space evenly" },
70
+ ],
71
+ alignItems: [
72
+ { value: "stretch", label: "Stretch" },
73
+ { value: "flex-start", label: "Start" },
74
+ { value: "center", label: "Center" },
75
+ { value: "flex-end", label: "End" },
76
+ { value: "baseline", label: "Baseline" },
77
+ ],
78
+ textAlign: [
79
+ { value: "left", label: "Left" },
80
+ { value: "center", label: "Center" },
81
+ { value: "right", label: "Right" },
82
+ { value: "justify", label: "Justify" },
83
+ ],
84
+ textTransform: [
85
+ { value: "none", label: "None" },
86
+ { value: "uppercase", label: "Uppercase" },
87
+ { value: "lowercase", label: "Lowercase" },
88
+ { value: "capitalize", label: "Capitalize" },
89
+ ],
90
+ textDecoration: [
91
+ { value: "none", label: "None" },
92
+ { value: "underline", label: "Underline" },
93
+ { value: "overline", label: "Overline" },
94
+ { value: "line-through", label: "Line-through" },
95
+ ],
96
+ position: [
97
+ { value: "static", label: "Static" },
98
+ { value: "relative", label: "Relative" },
99
+ { value: "absolute", label: "Absolute" },
100
+ { value: "fixed", label: "Fixed" },
101
+ { value: "sticky", label: "Sticky" },
102
+ ],
103
+ overflow: [
104
+ { value: "visible", label: "Visible" },
105
+ { value: "hidden", label: "Hidden" },
106
+ { value: "clip", label: "Clip" },
107
+ { value: "scroll", label: "Scroll" },
108
+ { value: "auto", label: "Auto" },
109
+ ],
110
+ aspectRatio: [
111
+ { value: "auto", label: "Auto" },
112
+ ...["1/1", "4/3", "3/2", "16/9", "21/9", "3/4", "2/3", "9/16"].map((ratio) => ({
113
+ value: ratio,
114
+ label: ratio.replace("/", ":"),
115
+ })),
116
+ ],
117
+ objectFit: [
118
+ { value: "fill", label: "Fill" },
119
+ { value: "contain", label: "Contain" },
120
+ { value: "cover", label: "Cover" },
121
+ { value: "none", label: "None" },
122
+ { value: "scale-down", label: "Scale down" },
123
+ ],
124
+ cursor: [
125
+ { value: "default", label: "Default" },
126
+ { value: "pointer", label: "Pointer" },
127
+ { value: "text", label: "Text" },
128
+ { value: "move", label: "Move" },
129
+ { value: "grab", label: "Grab" },
130
+ { value: "not-allowed", label: "Not allowed" },
131
+ { value: "help", label: "Help" },
132
+ { value: "crosshair", label: "Crosshair" },
133
+ { value: "zoom-in", label: "Zoom in" },
134
+ ],
135
+ borderStyle: [
136
+ { value: "none", label: "None" },
137
+ { value: "solid", label: "Solid" },
138
+ { value: "dashed", label: "Dashed" },
139
+ { value: "dotted", label: "Dotted" },
140
+ ],
141
+ backgroundSize: [
142
+ { value: "cover", label: "Cover" },
143
+ { value: "contain", label: "Contain" },
144
+ { value: "auto", label: "Auto" },
145
+ ],
146
+ backgroundPosition: [
147
+ { value: "center", label: "Center" },
148
+ { value: "top", label: "Top" },
149
+ { value: "bottom", label: "Bottom" },
150
+ { value: "left", label: "Left" },
151
+ { value: "right", label: "Right" },
152
+ { value: "top left", label: "Top left" },
153
+ { value: "top right", label: "Top right" },
154
+ { value: "bottom left", label: "Bottom left" },
155
+ { value: "bottom right", label: "Bottom right" },
156
+ ],
157
+ backgroundRepeat: [
158
+ { value: "no-repeat", label: "No repeat" },
159
+ { value: "repeat", label: "Repeat" },
160
+ { value: "repeat-x", label: "Repeat horizontally" },
161
+ { value: "repeat-y", label: "Repeat vertically" },
162
+ ],
163
+ fontWeight: [
164
+ { value: "400", label: "Regular" },
165
+ { value: "500", label: "Medium" },
166
+ { value: "600", label: "Semibold" },
167
+ { value: "700", label: "Bold" },
168
+ ],
169
+ };
170
+
171
+ const isLengthLiteral = (value: unknown): value is { value: number; unit: string } =>
172
+ typeof value === "object" && value !== null && "value" in value && "unit" in value;
173
+
174
+ /** A value as placeholder text: a literal, a keyword, or the variable's name (W-089). */
175
+ function placeholderOf(value: unknown, design: DesignSystem): string | undefined {
176
+ if (typeof value === "string" || typeof value === "number") return String(value);
177
+ if (isLengthLiteral(value)) return `${value.value}${value.unit}`;
178
+ if (typeof value === "object" && value !== null && "var" in value) {
179
+ const { colors, fonts, fontSizes, spacings } = design.variables;
180
+ const id = (value as { var: unknown }).var;
181
+ return [...colors, ...(fonts ?? []), ...(fontSizes ?? []), ...(spacings ?? [])].find(
182
+ (v) => v.id === id,
183
+ )?.name;
184
+ }
185
+ return undefined;
186
+ }
187
+
188
+ /** One Style property row: control, set marker, reset (W-021). */
189
+ export function StyleRow({
190
+ styleKey,
191
+ style,
192
+ inherited,
193
+ design,
194
+ fetcher,
195
+ onPatch,
196
+ onDesignChange,
197
+ }: {
198
+ styleKey: StyleKey;
199
+ style: StyleProps | undefined;
200
+ /** The Normal styles while a state is edited (W-089): shown as placeholders, never saved. */
201
+ inherited?: StyleProps;
202
+ design: DesignSystem;
203
+ /** Present on an element, so a background image can use the media library. */
204
+ fetcher?: Fetcher;
205
+ onPatch: (patch: Partial<StyleProps>) => void;
206
+ onDesignChange: (design: DesignSystem) => Promise<void>;
207
+ }) {
208
+ const value = style?.[styleKey];
209
+ const set = value !== undefined;
210
+ const label = STYLE_LABELS[styleKey];
211
+ const normalValue = inherited?.[styleKey];
212
+ const placeholder = set ? undefined : placeholderOf(normalValue, design);
213
+ const inheriting = !set && normalValue !== undefined ? "true" : undefined;
214
+
215
+ const reset = (
216
+ <ResetButton label={label} set={set} onReset={() => onPatch({ [styleKey]: undefined })} />
217
+ );
218
+
219
+ if (styleKey === "backgroundImage") {
220
+ return (
221
+ <BackgroundImageControl
222
+ value={typeof value === "string" ? value : undefined}
223
+ fetcher={fetcher}
224
+ onChange={(next) => onPatch({ backgroundImage: next })}
225
+ reset={reset}
226
+ />
227
+ );
228
+ }
229
+
230
+ if (styleKey === "backgroundVideo") {
231
+ const video = typeof value === "string" ? value : "";
232
+ return (
233
+ <div className="emvb-style-row" data-emvb-style="backgroundVideo" data-set={set || undefined}>
234
+ <Input
235
+ label="Background video"
236
+ className={FIELD}
237
+ value={video}
238
+ placeholder="https:// or /path"
239
+ onChange={(event) => {
240
+ const next = event.target.value.trim();
241
+ onPatch({ backgroundVideo: next === "" ? undefined : next });
242
+ }}
243
+ />
244
+ {reset}
245
+ </div>
246
+ );
247
+ }
248
+
249
+ if (styleKey === "gradient") {
250
+ return (
251
+ <GradientControl
252
+ value={style?.gradient}
253
+ design={design}
254
+ onChange={(next) => onPatch({ gradient: next })}
255
+ onDesignChange={onDesignChange}
256
+ reset={reset}
257
+ />
258
+ );
259
+ }
260
+
261
+ if (styleKey === "overlay") {
262
+ return (
263
+ <OverlayControl
264
+ value={style?.overlay}
265
+ design={design}
266
+ onChange={(next) => onPatch({ overlay: next })}
267
+ onDesignChange={onDesignChange}
268
+ reset={reset}
269
+ />
270
+ );
271
+ }
272
+
273
+ if (COLOR_KEYS.has(styleKey)) {
274
+ return (
275
+ <div
276
+ className="emvb-style-row"
277
+ data-emvb-style={styleKey}
278
+ data-set={set ? "true" : undefined}
279
+ data-inherited={inheriting}
280
+ >
281
+ <ColorControl
282
+ label={label}
283
+ value={value as StyleProps["color"]}
284
+ placeholder={placeholder}
285
+ design={design}
286
+ onChange={(color) => onPatch({ [styleKey]: color })}
287
+ onDesignChange={onDesignChange}
288
+ />
289
+ {reset}
290
+ </div>
291
+ );
292
+ }
293
+
294
+ const options = SELECT_OPTIONS[styleKey];
295
+ if (options) {
296
+ const shown = value ?? normalValue;
297
+ const current =
298
+ styleKey === "fontWeight" && typeof shown === "number"
299
+ ? String(shown)
300
+ : ((shown as string | undefined) ?? options[0]?.value ?? "");
301
+ return (
302
+ <div
303
+ className="emvb-style-row"
304
+ data-emvb-style={styleKey}
305
+ data-set={set ? "true" : undefined}
306
+ data-inherited={inheriting}
307
+ >
308
+ <Select
309
+ label={label}
310
+ className={FIELD}
311
+ value={current}
312
+ onValueChange={(next) => {
313
+ if (styleKey === "fontWeight") {
314
+ const n = Number(next);
315
+ onPatch({
316
+ fontWeight: Number.isFinite(n) ? (n as 400 | 500 | 600 | 700) : undefined,
317
+ });
318
+ return;
319
+ }
320
+ onPatch({ [styleKey]: next === options[0]?.value && !set ? next : next });
321
+ }}
322
+ renderValue={(v: unknown) =>
323
+ options.find((o) => o.value === String(v))?.label ?? String(v)
324
+ }
325
+ >
326
+ {options.map((option) => (
327
+ <Select.Option key={option.value} value={option.value}>
328
+ {option.label}
329
+ </Select.Option>
330
+ ))}
331
+ </Select>
332
+ {reset}
333
+ </div>
334
+ );
335
+ }
336
+
337
+ if (styleKey === "fontFamily") {
338
+ const text = typeof value === "string" ? value : "";
339
+ const ref = boundRef(value, "font");
340
+ return (
341
+ <div
342
+ className="emvb-style-row"
343
+ data-emvb-style={styleKey}
344
+ data-set={set ? "true" : undefined}
345
+ data-inherited={inheriting}
346
+ >
347
+ {ref ? (
348
+ <VariableChip
349
+ label={label}
350
+ kind="font"
351
+ design={design}
352
+ id={ref.var}
353
+ onDetach={(literal) =>
354
+ onPatch({
355
+ fontFamily:
356
+ typeof literal === "string" && isSafeFontStack(literal) ? literal : undefined,
357
+ })
358
+ }
359
+ />
360
+ ) : (
361
+ <Input
362
+ label={label}
363
+ className={FIELD}
364
+ value={text}
365
+ placeholder={placeholder ?? "Noto Sans, system-ui, sans-serif"}
366
+ onChange={(event) => {
367
+ const next = event.target.value.trim();
368
+ onPatch({ fontFamily: next === "" ? undefined : next });
369
+ }}
370
+ />
371
+ )}
372
+ <VariableButton
373
+ label={label}
374
+ kind="font"
375
+ design={design}
376
+ current={ref?.var ?? null}
377
+ onBind={(next) => onPatch({ fontFamily: next as StyleProps["fontFamily"] })}
378
+ />
379
+ {reset}
380
+ </div>
381
+ );
382
+ }
383
+
384
+ if (
385
+ styleKey === "zIndex" ||
386
+ styleKey === "opacity" ||
387
+ styleKey === "gridColumnSpan" ||
388
+ styleKey === "gridRowSpan"
389
+ ) {
390
+ const spec = styleKey === "zIndex" ? Z_INDEX : styleKey === "opacity" ? OPACITY : GRID_SPAN;
391
+ return (
392
+ <NumberRow
393
+ rowKey={styleKey}
394
+ label={label}
395
+ value={typeof value === "number" ? value : undefined}
396
+ inherited={typeof normalValue === "number" ? normalValue : undefined}
397
+ spec={spec}
398
+ onCommit={(next) => onPatch({ [styleKey]: next })}
399
+ />
400
+ );
401
+ }
402
+
403
+ if (styleKey === "boxShadow") {
404
+ return (
405
+ <ShadowControl
406
+ value={style?.boxShadow}
407
+ design={design}
408
+ onChange={(boxShadow) => onPatch({ boxShadow })}
409
+ onDesignChange={onDesignChange}
410
+ reset={reset}
411
+ />
412
+ );
413
+ }
414
+
415
+ if (styleKey === "entrance") {
416
+ return (
417
+ <EntranceControl
418
+ value={style?.entrance}
419
+ onChange={(entrance) => onPatch({ entrance })}
420
+ reset={reset}
421
+ />
422
+ );
423
+ }
424
+
425
+ if (styleKey === "transition") {
426
+ return (
427
+ <TransitionControl
428
+ value={style?.transition}
429
+ onChange={(transition) => onPatch({ transition })}
430
+ reset={reset}
431
+ />
432
+ );
433
+ }
434
+
435
+ if (styleKey === "filter") {
436
+ return (
437
+ <FiltersControl
438
+ value={style?.filter}
439
+ inherited={inherited?.filter}
440
+ onChange={(filter) => onPatch({ filter })}
441
+ />
442
+ );
443
+ }
444
+
445
+ if (LENGTH_KEYS.has(styleKey)) {
446
+ return (
447
+ <LengthRow
448
+ styleKey={styleKey}
449
+ label={label}
450
+ value={value}
451
+ design={design}
452
+ set={set}
453
+ placeholder={placeholder}
454
+ onPatch={onPatch}
455
+ reset={reset}
456
+ />
457
+ );
458
+ }
459
+
460
+ return null;
461
+ }
462
+
463
+ export const IMPLEMENTED_STYLE_KEYS: StyleKey[] = [
464
+ ...LENGTH_KEYS,
465
+ ...COLOR_KEYS,
466
+ "fontFamily",
467
+ "zIndex",
468
+ "gridColumnSpan",
469
+ "gridRowSpan",
470
+ "opacity",
471
+ "boxShadow",
472
+ "filter",
473
+ "entrance",
474
+ "transition",
475
+ "backgroundImage",
476
+ "backgroundVideo",
477
+ "gradient",
478
+ "overlay",
479
+ ...(Object.keys(SELECT_OPTIONS) as StyleKey[]),
480
+ ];
@@ -0,0 +1,167 @@
1
+ import { DropdownMenu } from "@cloudflare/kumo";
2
+ import { BracketsCurlyIcon, RulerIcon, TextAaIcon, TextTIcon, XIcon } from "@phosphor-icons/react";
3
+ import type { DesignSystem, StyleProps } from "../../../../core/index.ts";
4
+ import type { StyleKey } from "./style-sections.ts";
5
+
6
+ /** Variable kinds a length or font property can bind to. Colours bind through ColorControl. */
7
+ export type BindKind = "font" | "fontSize" | "spacing";
8
+
9
+ const SPACING_KEYS = new Set<StyleKey>([
10
+ "gap",
11
+ "paddingTop",
12
+ "paddingRight",
13
+ "paddingBottom",
14
+ "paddingLeft",
15
+ "marginTop",
16
+ "marginRight",
17
+ "marginBottom",
18
+ "marginLeft",
19
+ "top",
20
+ "right",
21
+ "bottom",
22
+ "left",
23
+ "borderRadius",
24
+ ]);
25
+
26
+ /** The variable kind a style property takes, or null when it has no variable button. */
27
+ export function bindKind(key: StyleKey): BindKind | null {
28
+ if (key === "fontFamily") return "font";
29
+ if (key === "fontSize") return "fontSize";
30
+ return SPACING_KEYS.has(key) ? "spacing" : null;
31
+ }
32
+
33
+ type Variable = { id: string; name: string; value: string | { value: number; unit: string } };
34
+
35
+ const LIST = { font: "fonts", fontSize: "fontSizes", spacing: "spacings" } as const;
36
+ const NOUN = { font: "font", fontSize: "font size", spacing: "spacing" } as const;
37
+ const KIND_ICON = { font: TextTIcon, fontSize: TextAaIcon, spacing: RulerIcon } as const;
38
+
39
+ const variablesOf = (design: DesignSystem, kind: BindKind): readonly Variable[] =>
40
+ design.variables[LIST[kind]] ?? [];
41
+
42
+ const shown = (value: Variable["value"]) =>
43
+ typeof value === "string" ? value : `${value.value}${value.unit}`;
44
+
45
+ /** A bound `{ var }` reference of `kind`, if `value` is one. */
46
+ export function boundRef(value: unknown, kind: BindKind): { var: string } | null {
47
+ if (!value || typeof value !== "object" || !("var" in value)) return null;
48
+ const ref = value as { var: string; from?: string };
49
+ return ref.from === kind ? ref : null;
50
+ }
51
+
52
+ /**
53
+ * Any length variable a value is bound to, whatever the row's own kind: a spacing variable on
54
+ * Font size still renders as `var(--emvb-s-…)`, so it shows as a spacing chip (W-088).
55
+ */
56
+ export function lengthRef(value: unknown): { var: string; kind: "fontSize" | "spacing" } | null {
57
+ if (!value || typeof value !== "object" || !("var" in value)) return null;
58
+ const ref = value as { var: string; from?: string };
59
+ return ref.from === "fontSize" || ref.from === "spacing"
60
+ ? { var: ref.var, kind: ref.from }
61
+ : null;
62
+ }
63
+
64
+ /** The variable button (Phosphor BracketsCurly): lists the site's variables of the kind. */
65
+ export function VariableButton({
66
+ label,
67
+ kind,
68
+ design,
69
+ current,
70
+ onBind,
71
+ }: {
72
+ label: string;
73
+ kind: BindKind;
74
+ design: DesignSystem;
75
+ current: string | null;
76
+ onBind: (ref: NonNullable<StyleProps["gap"]>) => void;
77
+ }) {
78
+ const list = variablesOf(design, kind);
79
+ return (
80
+ <DropdownMenu>
81
+ <DropdownMenu.Trigger>
82
+ <button
83
+ type="button"
84
+ className="emvb-var-btn"
85
+ aria-label={`Use a variable for ${label}`}
86
+ title="Use a variable"
87
+ data-active={current ? "true" : undefined}
88
+ >
89
+ <BracketsCurlyIcon size={16} aria-hidden="true" />
90
+ </button>
91
+ </DropdownMenu.Trigger>
92
+ <DropdownMenu.Content data-emvb-var-menu={kind}>
93
+ {list.length === 0 ? (
94
+ <DropdownMenu.Item disabled>
95
+ No {NOUN[kind]} variables yet. Add them in Site styles.
96
+ </DropdownMenu.Item>
97
+ ) : (
98
+ list.map((variable) => (
99
+ <DropdownMenu.Item
100
+ key={variable.id}
101
+ data-emvb-var-option={variable.id}
102
+ data-selected={variable.id === current ? "true" : undefined}
103
+ onClick={() => onBind({ var: variable.id, from: kind })}
104
+ >
105
+ <span className="emvb-var-option">
106
+ <span
107
+ className="emvb-var-option-sample"
108
+ aria-hidden="true"
109
+ style={kind === "font" ? { fontFamily: shown(variable.value) } : undefined}
110
+ >
111
+ {kind === "font" ? "Ag" : kind === "fontSize" ? "Aa" : ""}
112
+ </span>
113
+ <span className="emvb-var-option-name">{variable.name}</span>
114
+ <span className="emvb-var-option-value">{shown(variable.value)}</span>
115
+ </span>
116
+ </DropdownMenu.Item>
117
+ ))
118
+ )}
119
+ </DropdownMenu.Content>
120
+ </DropdownMenu>
121
+ );
122
+ }
123
+
124
+ /**
125
+ * The variable chip that stands in for a bound value (DESIGN.md): the kind icon, the variable's
126
+ * name and an × that detaches it, keeping the variable's current value as a literal.
127
+ */
128
+ export function VariableChip({
129
+ label,
130
+ kind,
131
+ design,
132
+ id,
133
+ onDetach,
134
+ }: {
135
+ label: string;
136
+ kind: BindKind;
137
+ design: DesignSystem;
138
+ id: string;
139
+ onDetach: (literal: Variable["value"] | undefined) => void;
140
+ }) {
141
+ const variable = variablesOf(design, kind).find((v) => v.id === id);
142
+ const Icon = KIND_ICON[kind];
143
+ return (
144
+ <div className="emvb-var-field" data-emvb-var-bound={id}>
145
+ <span className="emvb-var-field-label">{label}</span>
146
+ <span
147
+ className="emvb-var-chip"
148
+ data-missing={variable ? undefined : "true"}
149
+ title={
150
+ variable ? `${variable.name} · ${shown(variable.value)}` : "This variable was deleted"
151
+ }
152
+ >
153
+ <Icon size={14} aria-hidden="true" />
154
+ <span className="emvb-var-chip-name">{variable?.name ?? `Missing (${id})`}</span>
155
+ {variable && <span className="emvb-var-chip-value">{shown(variable.value)}</span>}
156
+ <button
157
+ type="button"
158
+ className="emvb-var-chip-x"
159
+ aria-label={`Detach ${variable?.name ?? id} from ${label}`}
160
+ onClick={() => onDetach(variable?.value)}
161
+ >
162
+ <XIcon size={12} aria-hidden="true" />
163
+ </button>
164
+ </span>
165
+ </div>
166
+ );
167
+ }
@@ -0,0 +1,51 @@
1
+ import type { DesignSystem } from "../../../../core/index.ts";
2
+
3
+ type StyleClass = NonNullable<DesignSystem["classes"]>[number];
4
+
5
+ export type ClassOption = { kind: "class"; cls: StyleClass } | { kind: "create"; name: string };
6
+
7
+ /** Site-wide class cap (design schema) and per-element cap (layout schema). */
8
+ export const MAX_SITE_CLASSES = 100;
9
+ export const MAX_ELEMENT_CLASSES = 20;
10
+
11
+ const rank = (cls: StyleClass, q: string) => {
12
+ const name = cls.name.toLowerCase();
13
+ if (name === q) return 0;
14
+ if (name.startsWith(q) || cls.id.startsWith(q)) return 1;
15
+ return 2;
16
+ };
17
+
18
+ /**
19
+ * Suggestions for the class chip input (W-087): classes not yet on the element whose name or id
20
+ * contains the query, exact and prefix matches first, then "Create class" when no class has
21
+ * that exact name.
22
+ */
23
+ export function classOptions(
24
+ catalog: readonly StyleClass[],
25
+ applied: readonly string[],
26
+ query: string,
27
+ ): ClassOption[] {
28
+ const q = query.trim().toLowerCase();
29
+ const available = catalog.filter((cls) => !applied.includes(cls.id));
30
+ const found = q
31
+ ? available
32
+ .filter((cls) => cls.name.toLowerCase().includes(q) || cls.id.includes(q))
33
+ .map((cls, index) => ({ cls, index, rank: rank(cls, q) }))
34
+ .toSorted((a, b) => a.rank - b.rank || a.index - b.index)
35
+ .map(({ cls }) => cls)
36
+ : available;
37
+ const options: ClassOption[] = found.map((cls) => ({ kind: "class", cls }));
38
+ const taken = catalog.some((cls) => cls.name.toLowerCase() === q);
39
+ if (q && !taken) options.push({ kind: "create", name: query.trim() });
40
+ return options;
41
+ }
42
+
43
+ /** The applied class whose name is exactly `query`, ignoring case, if any. */
44
+ export const appliedByName = (
45
+ catalog: readonly StyleClass[],
46
+ applied: readonly string[],
47
+ query: string,
48
+ ) => {
49
+ const q = query.trim().toLowerCase();
50
+ return catalog.find((cls) => applied.includes(cls.id) && cls.name.toLowerCase() === q);
51
+ };