@perkyzz/emvb 0.9.0 → 1.0.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 (160) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -2
  3. package/src/admin/agents-api.ts +45 -0
  4. package/src/admin/editor/A11yCopilot.tsx +1 -1
  5. package/src/admin/editor/Editor.tsx +297 -248
  6. package/src/admin/editor/Timeline.tsx +2 -1
  7. package/src/admin/editor/TopBar.tsx +4 -2
  8. package/src/admin/editor/canvas/CanvasFrame.tsx +2 -2
  9. package/src/admin/editor/canvas/DeviceBar.tsx +17 -9
  10. package/src/admin/editor/canvas/canvas-scale.ts +2 -2
  11. package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
  12. package/src/admin/editor/co-design.ts +190 -0
  13. package/src/admin/editor/dnd/new-element.ts +26 -4
  14. package/src/admin/editor/editor-chrome.tsx +3 -3
  15. package/src/admin/editor/editor-commands.ts +8 -3
  16. package/src/admin/editor/element-chrome.ts +3 -1
  17. package/src/admin/editor/extension-manifests.ts +20 -0
  18. package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
  19. package/src/admin/editor/extensions-context.tsx +27 -0
  20. package/src/admin/editor/feature-css.ts +17 -0
  21. package/src/admin/editor/palette-items.ts +2 -2
  22. package/src/admin/editor/panels/AddPanel.tsx +31 -1
  23. package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
  24. package/src/admin/editor/panels/ClassesSection.tsx +9 -6
  25. package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
  26. package/src/admin/editor/panels/ColorControl.tsx +2 -2
  27. package/src/admin/editor/panels/ElementPanel.tsx +49 -14
  28. package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
  29. package/src/admin/editor/panels/LayersPanel.tsx +10 -6
  30. package/src/admin/editor/panels/LeftPanel.tsx +33 -5
  31. package/src/admin/editor/panels/PageSettings.tsx +4 -0
  32. package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
  33. package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
  34. package/src/admin/editor/panels/settings/BackgroundControls.tsx +72 -15
  35. package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
  36. package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
  37. package/src/admin/editor/panels/settings/EffectsControls.tsx +104 -9
  38. package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
  39. package/src/admin/editor/panels/settings/IconControls.tsx +14 -11
  40. package/src/admin/editor/panels/settings/LengthRow.tsx +27 -16
  41. package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
  42. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  43. package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
  44. package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
  45. package/src/admin/editor/panels/settings/StyleRow.tsx +113 -13
  46. package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
  47. package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
  48. package/src/admin/editor/panels/settings/background-mode.ts +14 -11
  49. package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
  50. package/src/admin/editor/panels/settings/box-sides.ts +22 -14
  51. package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
  52. package/src/admin/editor/panels/settings/length-units.ts +53 -1
  53. package/src/admin/editor/panels/settings/query-style.ts +3 -3
  54. package/src/admin/editor/panels/settings/style-sections.ts +51 -10
  55. package/src/admin/editor/panels/style-target.ts +9 -7
  56. package/src/admin/editor/presence.ts +60 -0
  57. package/src/admin/editor/store.ts +6 -2
  58. package/src/admin/editor/useCoDesign.ts +177 -0
  59. package/src/admin/editor/useEditorCommands.ts +4 -4
  60. package/src/admin/editor/useExtensions.ts +45 -0
  61. package/src/admin/editor/useNodeActions.ts +15 -6
  62. package/src/admin/editor/useProposals.ts +81 -0
  63. package/src/admin/languages-api.ts +61 -0
  64. package/src/admin/pages/AgentSetup.tsx +148 -0
  65. package/src/admin/pages/AgentsPage.tsx +9 -26
  66. package/src/admin/pages/CreateDialog.tsx +15 -0
  67. package/src/admin/pages/ImportButton.tsx +18 -0
  68. package/src/admin/pages/ImportElementorDialog.tsx +669 -0
  69. package/src/admin/pages/ImportPageLinks.tsx +86 -0
  70. package/src/admin/pages/PageList.tsx +15 -1
  71. package/src/admin/pages/ThemePartList.tsx +15 -1
  72. package/src/admin/pages/section-head.tsx +27 -0
  73. package/src/admin/proposals-api.ts +91 -0
  74. package/src/admin/ui.ts +39 -2
  75. package/src/astro/content-port.ts +14 -1
  76. package/src/astro/resolve-theme.ts +14 -1
  77. package/src/astro/resolve.ts +89 -2
  78. package/src/constants.ts +1 -1
  79. package/src/core/a11y/audit.ts +44 -14
  80. package/src/core/arrange.ts +5 -1
  81. package/src/core/bounded-array.ts +31 -0
  82. package/src/core/clipboard.ts +9 -0
  83. package/src/core/contract.ts +285 -0
  84. package/src/core/css/generate.ts +89 -20
  85. package/src/core/css/trace.ts +18 -9
  86. package/src/core/css-keywords.ts +51 -1
  87. package/src/core/design/cascade.ts +12 -9
  88. package/src/core/design/classes.ts +4 -5
  89. package/src/core/design/devices.ts +13 -13
  90. package/src/core/design/states.ts +5 -3
  91. package/src/core/design/transfer.ts +5 -0
  92. package/src/core/design/variables.ts +17 -4
  93. package/src/core/elements/dynamic-elements.ts +3 -3
  94. package/src/core/elements/index.ts +73 -9
  95. package/src/core/extensions/define.ts +13 -0
  96. package/src/core/extensions/index.ts +41 -0
  97. package/src/core/extensions/namespace.ts +82 -0
  98. package/src/core/extensions/normalize.ts +141 -0
  99. package/src/core/extensions/placeholder.ts +41 -0
  100. package/src/core/extensions/registry.ts +94 -0
  101. package/src/core/extensions/render-ext.ts +118 -0
  102. package/src/core/extensions/safe-nodes.ts +93 -0
  103. package/src/core/extensions/schema.ts +112 -0
  104. package/src/core/extensions/types.ts +159 -0
  105. package/src/core/forms/binding.ts +1 -1
  106. package/src/core/history/diff.ts +1 -1
  107. package/src/core/import/elementor/atomic.ts +1595 -0
  108. package/src/core/import/elementor/classes.ts +127 -0
  109. package/src/core/import/elementor/context.ts +429 -0
  110. package/src/core/import/elementor/counter-steps.ts +72 -0
  111. package/src/core/import/elementor/css.ts +445 -0
  112. package/src/core/import/elementor/html.ts +500 -0
  113. package/src/core/import/elementor/index.ts +949 -0
  114. package/src/core/import/elementor/inline-marks.ts +81 -0
  115. package/src/core/import/elementor/snapshots.ts +48 -0
  116. package/src/core/import/elementor/style.ts +409 -0
  117. package/src/core/import/elementor/values.ts +241 -0
  118. package/src/core/import/elementor/widgets.ts +1897 -0
  119. package/src/core/index.ts +82 -0
  120. package/src/core/json-schema.ts +107 -0
  121. package/src/core/limits.ts +19 -0
  122. package/src/core/migrate/index.ts +6 -1
  123. package/src/core/migrate/v18.ts +222 -0
  124. package/src/core/perf/meter.ts +5 -5
  125. package/src/core/proposals-safety.ts +102 -0
  126. package/src/core/proposals.ts +357 -0
  127. package/src/core/recipes/index.ts +2 -2
  128. package/src/core/render/extras.ts +3 -3
  129. package/src/core/render/index.ts +140 -20
  130. package/src/core/render/loop.ts +1 -1
  131. package/src/core/render/section.ts +4 -4
  132. package/src/core/render/vnode.ts +1 -1
  133. package/src/core/sanitize/css.ts +125 -10
  134. package/src/core/sanitize/motion.ts +116 -0
  135. package/src/core/saved-sections.ts +6 -0
  136. package/src/core/schema/descriptors.ts +3 -1
  137. package/src/core/schema/design.ts +2 -1
  138. package/src/core/schema/layout.ts +82 -14
  139. package/src/core/schema/style.ts +251 -114
  140. package/src/core/text-marks.ts +227 -0
  141. package/src/core/theme/dynamic.ts +9 -4
  142. package/src/core/theme/float.ts +1 -0
  143. package/src/core/theme/popup-rules.ts +17 -1
  144. package/src/core/translatable.ts +34 -0
  145. package/src/core/validate.ts +13 -1
  146. package/src/index.ts +24 -0
  147. package/src/mcp/errors.ts +3 -1
  148. package/src/mcp/ports.ts +67 -0
  149. package/src/mcp/prompts.ts +1 -11
  150. package/src/mcp/proposals.ts +281 -0
  151. package/src/mcp/read.ts +10 -9
  152. package/src/mcp/tools.ts +71 -3
  153. package/src/mcp/write.ts +66 -11
  154. package/src/server/agent-settings.ts +5 -1
  155. package/src/server/mcp-routes.ts +15 -0
  156. package/src/server/plugin.ts +35 -2
  157. package/src/server/presence.ts +78 -0
  158. package/src/server/proposals.ts +261 -0
  159. package/src/server/requests.ts +196 -0
  160. package/src/server/tools-served.ts +45 -0
@@ -1,15 +1,15 @@
1
1
  import * as React from "react";
2
2
  import { Button, Select } from "@cloudflare/kumo";
3
3
  import { PlusIcon } from "@phosphor-icons/react";
4
- import type { DesignSystem, StyleProps } from "../../../../core/index.ts";
4
+ import type { DesignSystem, FlatStyleProps } from "../../../../core/index.ts";
5
5
  import { BUTTON, FIELD } from "../../../ui.ts";
6
6
  import { ColorControl } from "../ColorControl.tsx";
7
7
  import { NumberField, NumberRow, type NumberSpec } from "./NumberRow.tsx";
8
8
 
9
- type Shadow = NonNullable<StyleProps["boxShadow"]>;
10
- type Filter = NonNullable<StyleProps["filter"]>;
11
- type Transition = NonNullable<StyleProps["transition"]>;
12
- type Entrance = NonNullable<StyleProps["entrance"]>;
9
+ type Shadow = NonNullable<FlatStyleProps["boxShadow"]>;
10
+ type Filter = NonNullable<FlatStyleProps["filter"]>;
11
+ type Transition = NonNullable<FlatStyleProps["transition"]>;
12
+ type Entrance = NonNullable<FlatStyleProps["entrance"]>;
13
13
 
14
14
  /** DESIGN.md: Add shadow starts at 0 4 12 0, 18 % black. */
15
15
  const NEW_SHADOW: Shadow = { x: 0, y: 4, blur: 12, spread: 0, color: "#0000002e" };
@@ -121,15 +121,108 @@ const FILTER_ROWS: ReadonlyArray<[key: keyof Filter, label: string, NumberSpec]>
121
121
  ["hueRotate", "Hue rotation", { min: 0, max: 360, example: "90", suffix: "°", placeholder: "0" }],
122
122
  ];
123
123
 
124
+ type Transform = NonNullable<FlatStyleProps["transform"]>;
125
+
126
+ /** One full turn, in degrees. */
127
+ const TURN = 360;
128
+
129
+ const TRANSFORM_ROWS: ReadonlyArray<[key: keyof Transform, label: string, NumberSpec]> = [
130
+ [
131
+ "x",
132
+ "Move X",
133
+ { min: -2000, max: 2000, integer: true, example: "8", suffix: "px", placeholder: "0" },
134
+ ],
135
+ [
136
+ "y",
137
+ "Move Y",
138
+ { min: -2000, max: 2000, integer: true, example: "-4", suffix: "px", placeholder: "0" },
139
+ ],
140
+ [
141
+ "scale",
142
+ "Scale",
143
+ { min: 10, max: 400, integer: true, example: "105", suffix: "%", placeholder: "100" },
144
+ ],
145
+ [
146
+ "rotate",
147
+ "Rotate",
148
+ { min: -360, max: TURN, integer: true, example: "15", suffix: "°", placeholder: "0" },
149
+ ],
150
+ ];
151
+
152
+ /**
153
+ * W-953: move, scale and rotate, one number row each; clearing the last row unsets Transform.
154
+ * In the Hover state it lifts or nudges the element (with a Transform transition to animate it).
155
+ */
156
+ export function TransformControl({
157
+ value,
158
+ inherited,
159
+ onChange,
160
+ }: {
161
+ value: Transform | undefined;
162
+ inherited?: Transform;
163
+ onChange: (next: Transform | undefined) => void;
164
+ }) {
165
+ const patch = (key: keyof Transform, n: number | undefined) => {
166
+ const next: Record<string, number> = {};
167
+ for (const [k, v] of Object.entries({ ...value, [key]: n })) {
168
+ if (typeof v === "number") next[k] = v;
169
+ }
170
+ onChange(Object.keys(next).length > 0 ? (next as Transform) : undefined);
171
+ };
172
+ const [open, setOpen] = React.useState(value !== undefined || inherited !== undefined);
173
+ const rows = React.useRef<HTMLDivElement>(null);
174
+ return (
175
+ <div
176
+ className="emvb-filters"
177
+ data-emvb-style="transform"
178
+ data-set={value ? "true" : undefined}
179
+ ref={rows}
180
+ >
181
+ <p className="emvb-sub-label">Transform</p>
182
+ {value || inherited || open ? (
183
+ TRANSFORM_ROWS.map(([key, label, spec]) => (
184
+ <NumberRow
185
+ key={key}
186
+ rowKey={`transform.${key}`}
187
+ label={label}
188
+ value={value?.[key]}
189
+ spec={spec}
190
+ inherited={inherited?.[key]}
191
+ onCommit={(n) => patch(key, n)}
192
+ />
193
+ ))
194
+ ) : (
195
+ <Button
196
+ type="button"
197
+ variant="secondary"
198
+ className={`${BUTTON} emvb-add-transform`}
199
+ icon={<PlusIcon aria-hidden="true" />}
200
+ onClick={() => {
201
+ setOpen(true);
202
+ requestAnimationFrame(() => rows.current?.querySelector<HTMLElement>("input")?.focus());
203
+ }}
204
+ >
205
+ Add transform
206
+ </Button>
207
+ )}
208
+ </div>
209
+ );
210
+ }
211
+
124
212
  /** The filter functions, one number row each; clearing the last one unsets Filters. */
125
213
  export function FiltersControl({
126
214
  value,
127
215
  inherited,
128
216
  onChange,
217
+ styleKey = "filter",
218
+ label: heading = "Filters",
129
219
  }: {
130
220
  value: Filter | undefined;
131
221
  inherited?: Filter;
132
222
  onChange: (next: Filter | undefined) => void;
223
+ /** W-957: the same rows edit `backdropFilter` (what's behind the element). */
224
+ styleKey?: "filter" | "backdropFilter";
225
+ label?: string;
133
226
  }) {
134
227
  const patch = (key: keyof Filter, n: number | undefined) => {
135
228
  const next: Record<string, number> = {};
@@ -144,16 +237,16 @@ export function FiltersControl({
144
237
  return (
145
238
  <div
146
239
  className="emvb-filters"
147
- data-emvb-style="filter"
240
+ data-emvb-style={styleKey}
148
241
  data-set={value ? "true" : undefined}
149
242
  ref={rows}
150
243
  >
151
- <p className="emvb-sub-label">Filters</p>
244
+ <p className="emvb-sub-label">{heading}</p>
152
245
  {open || value || inherited ? (
153
246
  FILTER_ROWS.map(([key, label, spec]) => (
154
247
  <NumberRow
155
248
  key={key}
156
- rowKey={`filter.${key}`}
249
+ rowKey={`${styleKey}.${key}`}
157
250
  label={label}
158
251
  value={value?.[key]}
159
252
  spec={spec}
@@ -172,7 +265,7 @@ export function FiltersControl({
172
265
  requestAnimationFrame(() => rows.current?.querySelector<HTMLElement>("input")?.focus());
173
266
  }}
174
267
  >
175
- Add filters
268
+ {`Add ${heading.toLowerCase()}`}
176
269
  </Button>
177
270
  )}
178
271
  </div>
@@ -195,6 +288,8 @@ const APPLIES_TO: ReadonlyArray<{ value: Transition["property"]; label: string }
195
288
  { value: "opacity", label: "Opacity" },
196
289
  { value: "shadow", label: "Shadow" },
197
290
  { value: "filter", label: "Filters" },
291
+ // W-953: move, scale and rotate (use it with a hover transform for a lift).
292
+ { value: "transform", label: "Transform" },
198
293
  ];
199
294
 
200
295
  export function TransitionSelect<T extends string>({
@@ -13,6 +13,7 @@ import { IconPicker } from "./IconPicker.tsx";
13
13
  import { ImageSourcesField } from "./ImageSourcesField.tsx";
14
14
  import { MediaPicker } from "./MediaPicker.tsx";
15
15
  import { propsOf, withProp } from "./node-props.ts";
16
+ import { TextMarksControl } from "./TextMarksControl.tsx";
16
17
 
17
18
  /** Content-tab control driven by a FieldDescriptor (W-021 / W-024). */
18
19
  export function FieldControl({
@@ -52,18 +53,18 @@ export function FieldControl({
52
53
  );
53
54
  }
54
55
 
55
- if (field.key === "itemPartId" && fetcher) {
56
+ if (field.key === "partId" && node.type === "loop" && fetcher) {
56
57
  return (
57
58
  <LoopItemBindControl
58
59
  key={field.key}
59
60
  value={typeof raw === "string" ? raw : ""}
60
61
  fetcher={fetcher}
61
- onChange={(itemPartId) => onChange(withProp(node, "itemPartId", itemPartId || undefined))}
62
+ onChange={(partId) => onChange(withProp(node, "partId", partId || undefined))}
62
63
  />
63
64
  );
64
65
  }
65
66
 
66
- if (field.key === "partId" && node.type === "section" && fetcher) {
67
+ if (field.key === "partId" && node.type === "part-ref" && fetcher) {
67
68
  return (
68
69
  <LoopItemBindControl
69
70
  key={field.key}
@@ -105,6 +106,10 @@ export function FieldControl({
105
106
  return <IconPicker key={field.key} node={node} fetcher={fetcher} onChange={onChange} />;
106
107
  }
107
108
 
109
+ if (field.kind === "marks") {
110
+ return <TextMarksControl key={field.key} node={node} onChange={onChange} />;
111
+ }
112
+
108
113
  if (field.kind === "image-sources") {
109
114
  return <ImageSourcesField key={field.key} node={node} onChange={onChange} />;
110
115
  }
@@ -296,4 +301,5 @@ export const IMPLEMENTED_FIELD_KINDS = [
296
301
  "icon",
297
302
  "list-items",
298
303
  "image-sources",
304
+ "marks",
299
305
  ] as const;
@@ -6,7 +6,7 @@ import {
6
6
  ProhibitIcon,
7
7
  } from "@phosphor-icons/react";
8
8
  import * as React from "react";
9
- import type { DesignSystem, StyleProps } from "../../../../core/index.ts";
9
+ import type { DesignSystem, FlatStyleProps } from "../../../../core/index.ts";
10
10
  import { BUTTON, FIELD } from "../../../ui.ts";
11
11
  import { ColorControl } from "../ColorControl.tsx";
12
12
  import { radioGroupKeys } from "./ChoiceGroup.tsx";
@@ -15,9 +15,9 @@ import { HintedSwitch } from "./HintedSwitch.tsx";
15
15
 
16
16
  /** W-237: the Icon section's own controls (glyph rotation, flip, drop shadow, loop). */
17
17
 
18
- type Flip = NonNullable<StyleProps["iconFlip"]>;
19
- type IconShadow = NonNullable<StyleProps["iconShadow"]>;
20
- type IconAnimation = NonNullable<StyleProps["iconAnimation"]>;
18
+ type Flip = NonNullable<FlatStyleProps["iconFlip"]>;
19
+ type IconShadow = NonNullable<FlatStyleProps["iconShadow"]>;
20
+ type IconAnimation = NonNullable<FlatStyleProps["iconAnimation"]>;
21
21
 
22
22
  const ICON_ROTATE: NumberSpec = {
23
23
  min: -360,
@@ -345,7 +345,7 @@ type IconShape = "none" | "circle" | "rounded" | "square";
345
345
  const SHAPE_PADDING = { value: 12, unit: "px" } as const;
346
346
  /** A light neutral, so the default icon colour (the text colour) reads on it. */
347
347
  const SHAPE_BACKGROUND = "#f1f5f9";
348
- const SHAPE_RADIUS: Record<Exclude<IconShape, "none">, StyleProps["borderRadius"]> = {
348
+ const SHAPE_RADIUS: Record<Exclude<IconShape, "none">, FlatStyleProps["borderRadius"]> = {
349
349
  circle: { value: 50, unit: "%" },
350
350
  rounded: { value: 12, unit: "px" },
351
351
  square: { value: 0, unit: "px" },
@@ -359,7 +359,7 @@ const CORNERS = [
359
359
  ] as const;
360
360
 
361
361
  /** The shape the styles in effect make: a background or border, and the corner radius. */
362
- function iconShapeOf(style: StyleProps | undefined): IconShape {
362
+ function iconShapeOf(style: FlatStyleProps | undefined): IconShape {
363
363
  if (!style || (style.backgroundColor === undefined && style.borderWidth === undefined))
364
364
  return "none";
365
365
  const radius = style.borderRadius;
@@ -376,8 +376,11 @@ function iconShapeOf(style: StyleProps | undefined): IconShape {
376
376
  * keeps a background or border already set, and adds 12 px padding only where none is set.
377
377
  * None clears the background, radius and padding it would have added.
378
378
  */
379
- function iconShapePatch(shape: IconShape, style: StyleProps | undefined): Partial<StyleProps> {
380
- const patch: Partial<StyleProps> = {};
379
+ function iconShapePatch(
380
+ shape: IconShape,
381
+ style: FlatStyleProps | undefined,
382
+ ): Partial<FlatStyleProps> {
383
+ const patch: Partial<FlatStyleProps> = {};
381
384
  for (const corner of CORNERS) if (style?.[corner] !== undefined) patch[corner] = undefined;
382
385
  if (shape === "none") {
383
386
  patch.backgroundColor = undefined;
@@ -406,9 +409,9 @@ export function IconShapeRow({
406
409
  inherited,
407
410
  onPatch,
408
411
  }: {
409
- style: StyleProps | undefined;
410
- inherited?: StyleProps;
411
- onPatch: (patch: Partial<StyleProps>) => void;
412
+ style: FlatStyleProps | undefined;
413
+ inherited?: FlatStyleProps;
414
+ onPatch: (patch: Partial<FlatStyleProps>) => void;
412
415
  }) {
413
416
  const effective = { ...inherited, ...style };
414
417
  const current = iconShapeOf(effective);
@@ -1,11 +1,15 @@
1
1
  import { DropdownMenu, InputGroup } from "@cloudflare/kumo";
2
2
  import { CaretDownIcon } from "@phosphor-icons/react";
3
3
  import * as React from "react";
4
- import type { DesignSystem, StyleProps } from "../../../../core/index.ts";
4
+ import type { DesignSystem, FlatStyleProps } from "../../../../core/index.ts";
5
5
  import { FIELD } from "../../../ui.ts";
6
6
  import {
7
+ fluidDraft,
8
+ isFluid,
7
9
  parseLengthDraft,
10
+ takesFluid,
8
11
  unitsFor,
12
+ type FluidLiteral,
9
13
  type LengthLiteral,
10
14
  type LengthUnit,
11
15
  type UnitChoice,
@@ -21,7 +25,9 @@ const isLiteral = (value: unknown): value is LengthLiteral =>
21
25
  typeof (value as { unit?: unknown }).unit === "string";
22
26
 
23
27
  const same = (a: unknown, b: unknown) =>
24
- a === b || (isLiteral(a) && isLiteral(b) && a.value === b.value && a.unit === b.unit);
28
+ a === b ||
29
+ (isLiteral(a) && isLiteral(b) && a.value === b.value && a.unit === b.unit) ||
30
+ (isFluid(a) && isFluid(b) && a.fluid.min === b.fluid.min && a.fluid.max === b.fluid.max);
25
31
 
26
32
  type NumericUnit = LengthUnit | "x";
27
33
 
@@ -49,7 +55,7 @@ export function LengthRow({
49
55
  placeholder?: string;
50
56
  /** Gap: a slider for the common range. The number field still accepts the full length. */
51
57
  slider?: boolean;
52
- onPatch: (patch: Partial<StyleProps>) => void;
58
+ onPatch: (patch: Partial<FlatStyleProps>) => void;
53
59
  reset: React.ReactNode;
54
60
  }) {
55
61
  const units = unitsFor(styleKey);
@@ -60,19 +66,22 @@ export function LengthRow({
60
66
  () => (isLiteral(value) ? value : typeof value === "number" ? { value, unit: "x" } : undefined),
61
67
  [value],
62
68
  );
63
- const numericUnit = literal?.unit ?? firstNumeric(units);
64
- const [draft, setDraft] = React.useState(literal ? String(literal.value) : "");
69
+ // W-955: a fluid size shows as "32–56" in px.
70
+ const fluid = isFluid(value) ? value : undefined;
71
+ const textOf = (): string => (fluid ? fluidDraft(fluid) : literal ? String(literal.value) : "");
72
+ const numericUnit = literal?.unit ?? (fluid ? "px" : firstNumeric(units));
73
+ const [draft, setDraft] = React.useState(textOf);
65
74
  const [unit, setUnit] = React.useState<UnitChoice>(value === "auto" ? "auto" : numericUnit);
66
75
  const lastNumeric = React.useRef<NumericUnit>(numericUnit);
67
76
  const [error, setError] = React.useState<string | null>(null);
68
77
  React.useEffect(() => {
69
- setDraft(literal ? String(literal.value) : "");
70
- setUnit(value === "auto" ? "auto" : (literal?.unit ?? lastNumeric.current));
78
+ setDraft(textOf());
79
+ setUnit(value === "auto" ? "auto" : (literal?.unit ?? (fluid ? "px" : lastNumeric.current)));
71
80
  if (literal) lastNumeric.current = literal.unit;
72
81
  setError(null);
73
82
  }, [value, literal]);
74
83
 
75
- const send = (next: LengthLiteral | "auto" | number | undefined) => {
84
+ const send = (next: LengthLiteral | FluidLiteral | "auto" | number | undefined) => {
76
85
  if (!same(next, value)) onPatch({ [styleKey]: next });
77
86
  };
78
87
 
@@ -97,13 +106,15 @@ export function LengthRow({
97
106
  }
98
107
  lastNumeric.current = next;
99
108
  const parsed = parseLengthDraft(draft, styleKey, next);
100
- if (parsed.ok && parsed.value !== undefined && parsed.value !== "auto") {
101
- const n = typeof parsed.value === "number" ? parsed.value : parsed.value.value;
102
- if (next === "x") {
103
- if (n <= 100) send(n);
104
- else setError("Line height without a unit can be from 0 to 100.");
105
- } else send({ value: n, unit: next });
106
- }
109
+ if (!parsed.ok) return;
110
+ const typed = parsed.value;
111
+ // A fluid range is always px; the unit menu leaves it as it is.
112
+ if (typed === undefined || typed === "auto" || isFluid(typed)) return;
113
+ const n = typeof typed === "number" ? typed : typed.value;
114
+ if (next === "x") {
115
+ if (n <= 100) send(n);
116
+ else setError("Line height without a unit can be from 0 to 100.");
117
+ } else send({ value: n, unit: next });
107
118
  };
108
119
 
109
120
  const kind = bindKind(styleKey);
@@ -140,7 +151,7 @@ export function LengthRow({
140
151
  placeholder={unit === "auto" ? "auto" : placeholder}
141
152
  title={`A number in ${unit === "auto" ? lastNumeric.current : unit}, or with its own unit (2rem, 50%)${
142
153
  units.includes("auto") ? ", or auto" : ""
143
- }`}
154
+ }${takesFluid(styleKey) ? ". A range such as 32–56 grows from phones to large screens (px)" : ""}`}
144
155
  aria-invalid={error ? true : undefined}
145
156
  onChange={(event) => {
146
157
  if (unit === "auto") setUnit(lastNumeric.current);
@@ -0,0 +1,269 @@
1
+ import { Button, DropdownMenu } from "@cloudflare/kumo";
2
+ import { PlusIcon, XIcon } from "@phosphor-icons/react";
3
+ import type * as React from "react";
4
+ import { MOTION_EFFECTS, type FlatStyleProps } from "../../../../core/index.ts";
5
+ import { BUTTON } from "../../../ui.ts";
6
+ import { TransitionSelect } from "./EffectsControls.tsx";
7
+ import { HintedSwitch } from "./HintedSwitch.tsx";
8
+ import { EFFECT_LABELS, specFor } from "./MotionControl.tsx";
9
+ import { NumberField, type NumberSpec } from "./NumberRow.tsx";
10
+
11
+ type Loop = NonNullable<FlatStyleProps["loopMotion"]>;
12
+ type Playing = Extract<Loop, { effects: unknown }>;
13
+ type Effect = Playing["effects"][number];
14
+ type Easing = NonNullable<Playing["easing"]>;
15
+
16
+ const DURATION: NumberSpec = {
17
+ min: 200,
18
+ max: 20_000,
19
+ integer: true,
20
+ example: "1600",
21
+ suffix: "ms",
22
+ };
23
+
24
+ const EASINGS: { value: Easing; label: string }[] = [
25
+ { value: "ease-in-out", label: "Smooth" },
26
+ { value: "ease", label: "Ease" },
27
+ { value: "ease-in", label: "Speed up" },
28
+ { value: "ease-out", label: "Slow down" },
29
+ { value: "linear", label: "Steady" },
30
+ ];
31
+
32
+ /**
33
+ * Ready-made loops (W-939). Each is a plain value: pick one, then tune it. They play back and
34
+ * forth, except Spin, which turns all the way round.
35
+ */
36
+ export const LOOP_PRESETS: { id: string; label: string; value: Playing }[] = [
37
+ {
38
+ id: "float",
39
+ label: "Float",
40
+ value: { duration: 1600, effects: [{ type: "move-y", from: 0, to: -8 }] },
41
+ },
42
+ {
43
+ id: "pulse",
44
+ label: "Pulse",
45
+ value: { duration: 900, effects: [{ type: "scale", from: 100, to: 106 }] },
46
+ },
47
+ {
48
+ id: "breathe",
49
+ label: "Breathe",
50
+ value: { duration: 1800, effects: [{ type: "fade", from: 100, to: 60 }] },
51
+ },
52
+ {
53
+ id: "wiggle",
54
+ label: "Wiggle",
55
+ value: { duration: 300, effects: [{ type: "rotate", from: -3, to: 3 }] },
56
+ },
57
+ {
58
+ id: "drift",
59
+ label: "Drift sideways",
60
+ value: { duration: 2400, effects: [{ type: "move-x", from: -6, to: 6 }] },
61
+ },
62
+ {
63
+ id: "spin",
64
+ label: "Spin",
65
+ value: {
66
+ duration: 2000,
67
+ easing: "linear",
68
+ alternate: false,
69
+ effects: [{ type: "rotate", from: 0, to: 360 }],
70
+ },
71
+ },
72
+ ];
73
+
74
+ const presetOf = (value: Playing): string => {
75
+ const { loop: _loop, ...rest } = value;
76
+ const key = JSON.stringify(rest);
77
+ return LOOP_PRESETS.find((p) => JSON.stringify(p.value) === key)?.id ?? "custom";
78
+ };
79
+
80
+ /**
81
+ * A looping animation (W-938, W-939, Normal only): a preset, its speed and each effect's two ends.
82
+ * Plays back and forth unless turned off; stops after about 5 seconds unless it loops forever
83
+ * (D-057, D-059); never for visitors who prefer reduced motion. Plays live on the canvas.
84
+ */
85
+ export function LoopControl({
86
+ value,
87
+ onChange,
88
+ reset,
89
+ }: {
90
+ value: Loop | undefined;
91
+ onChange: (next: Loop | undefined) => void;
92
+ reset: React.ReactNode;
93
+ }) {
94
+ const playing = value && "effects" in value ? value : undefined;
95
+ const update = (patch: Partial<Playing>) => playing && onChange({ ...playing, ...patch });
96
+ const setEffects = (effects: Effect[]) => {
97
+ if (!playing) return;
98
+ onChange(effects.length > 0 ? { ...playing, effects } : undefined);
99
+ };
100
+ const unused = MOTION_EFFECTS.filter((t) => !playing?.effects.some((e) => e.type === t));
101
+ const presetOptions = [
102
+ ...LOOP_PRESETS.map((p) => ({ value: p.id, label: p.label })),
103
+ ...(playing && presetOf(playing) === "custom" ? [{ value: "custom", label: "Custom" }] : []),
104
+ ];
105
+ return (
106
+ <div
107
+ className="emvb-style-row"
108
+ data-emvb-style="loopMotion"
109
+ data-set={value ? "true" : undefined}
110
+ >
111
+ <div className="emvb-field-group emvb-transition emvb-motion">
112
+ <span className="emvb-var-field-label">Loop</span>
113
+ {value && !playing && (
114
+ <p className="emvb-helper" data-emvb-loop-off="">
115
+ Off on this screen.
116
+ </p>
117
+ )}
118
+ {playing && (
119
+ <>
120
+ <TransitionSelect
121
+ label="Motion"
122
+ value={presetOf(playing)}
123
+ options={presetOptions}
124
+ onChange={(id) => {
125
+ const preset = LOOP_PRESETS.find((p) => p.id === id);
126
+ if (preset)
127
+ onChange({
128
+ ...structuredClone(preset.value),
129
+ ...(playing.loop ? { loop: true as const } : {}),
130
+ });
131
+ }}
132
+ />
133
+ <NumberField
134
+ fieldKey="loopMotion.duration"
135
+ label="Duration"
136
+ value={playing.duration}
137
+ spec={DURATION}
138
+ onCommit={(n) => update({ duration: n ?? 1600 })}
139
+ />
140
+ <TransitionSelect
141
+ label="Easing"
142
+ value={playing.easing ?? "ease-in-out"}
143
+ options={EASINGS}
144
+ onChange={(easing) => update({ easing })}
145
+ />
146
+ <HintedSwitch
147
+ label="Back and forth"
148
+ checked={playing.alternate !== false}
149
+ onCheckedChange={(on) => {
150
+ const { alternate: _a, ...rest } = playing;
151
+ onChange(on ? rest : { ...rest, alternate: false });
152
+ }}
153
+ data={{ "data-emvb-loop-alternate": "" }}
154
+ hint="Off: it jumps back to the start each time, as a spin does."
155
+ />
156
+ {playing.effects.map((effect, index) => (
157
+ <div className="emvb-motion-effect" key={effect.type} data-emvb-loop={effect.type}>
158
+ <span className="emvb-motion-name">{EFFECT_LABELS[effect.type].label}</span>
159
+ <NumberField
160
+ fieldKey={`loopMotion.${effect.type}.from`}
161
+ label="From"
162
+ value={effect.from}
163
+ spec={specFor(effect.type)}
164
+ onCommit={(n) =>
165
+ setEffects(
166
+ playing.effects.with(index, {
167
+ ...effect,
168
+ from: n ?? EFFECT_LABELS[effect.type].neutral,
169
+ }),
170
+ )
171
+ }
172
+ />
173
+ <NumberField
174
+ fieldKey={`loopMotion.${effect.type}.to`}
175
+ label="To"
176
+ value={effect.to}
177
+ spec={specFor(effect.type)}
178
+ onCommit={(n) =>
179
+ setEffects(
180
+ playing.effects.with(index, {
181
+ ...effect,
182
+ to: n ?? EFFECT_LABELS[effect.type].neutral,
183
+ }),
184
+ )
185
+ }
186
+ />
187
+ <Button
188
+ type="button"
189
+ variant="ghost"
190
+ shape="square"
191
+ className={BUTTON}
192
+ aria-label={`Remove ${EFFECT_LABELS[effect.type].label}`}
193
+ icon={<XIcon aria-hidden="true" />}
194
+ onClick={() => setEffects(playing.effects.filter((_, i) => i !== index))}
195
+ />
196
+ </div>
197
+ ))}
198
+ {unused.length > 0 && (
199
+ <DropdownMenu>
200
+ <DropdownMenu.Trigger>
201
+ <Button
202
+ type="button"
203
+ variant="secondary"
204
+ className={`${BUTTON} emvb-add-effect`}
205
+ icon={<PlusIcon aria-hidden="true" />}
206
+ >
207
+ Add effect
208
+ </Button>
209
+ </DropdownMenu.Trigger>
210
+ <DropdownMenu.Content data-emvb-add-loop-effect="">
211
+ {unused.map((type) => (
212
+ <DropdownMenu.Item
213
+ key={type}
214
+ onClick={() => {
215
+ const n = EFFECT_LABELS[type].neutral;
216
+ setEffects([...playing.effects, { type, from: n, to: n }]);
217
+ }}
218
+ >
219
+ {EFFECT_LABELS[type].label}
220
+ </DropdownMenu.Item>
221
+ ))}
222
+ </DropdownMenu.Content>
223
+ </DropdownMenu>
224
+ )}
225
+ <HintedSwitch
226
+ label="Loop forever"
227
+ checked={playing.loop === true}
228
+ onCheckedChange={(loop) => {
229
+ const { loop: _old, ...rest } = playing;
230
+ onChange(loop ? { ...rest, loop: true } : rest);
231
+ }}
232
+ data={{ "data-emvb-loop-forever": "" }}
233
+ hint={
234
+ playing.loop
235
+ ? "Keeps going. Moving content that never stops can distract; the accessibility check flags it. Off for visitors who prefer reduced motion."
236
+ : "Stops on its own after about 5 seconds. Off for visitors who prefer reduced motion."
237
+ }
238
+ />
239
+ </>
240
+ )}
241
+ {!value && (
242
+ <Button
243
+ type="button"
244
+ variant="secondary"
245
+ className={`${BUTTON} emvb-add-shadow`}
246
+ icon={<PlusIcon aria-hidden="true" />}
247
+ data-emvb-add-loop=""
248
+ onClick={() =>
249
+ onChange(structuredClone((LOOP_PRESETS[0] as (typeof LOOP_PRESETS)[number]).value))
250
+ }
251
+ >
252
+ Add loop
253
+ </Button>
254
+ )}
255
+ {playing && (
256
+ <Button
257
+ type="button"
258
+ variant="ghost"
259
+ className={BUTTON}
260
+ onClick={() => onChange({ type: "none" })}
261
+ >
262
+ Turn off loop
263
+ </Button>
264
+ )}
265
+ </div>
266
+ {reset}
267
+ </div>
268
+ );
269
+ }
@@ -24,7 +24,7 @@ export function LoopItemBindControl({
24
24
  }: {
25
25
  value: string;
26
26
  fetcher: Fetcher;
27
- onChange: (itemPartId: string) => void;
27
+ onChange: (partId: string) => void;
28
28
  partType?: ThemePartType;
29
29
  label?: string;
30
30
  emptyLabel?: string;