@perkyzz/emvb 1.0.0 → 1.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 (80) hide show
  1. package/README.md +9 -0
  2. package/package.json +2 -2
  3. package/src/admin/bulk-api.ts +67 -0
  4. package/src/admin/content-api.ts +10 -6
  5. package/src/admin/copy-rich-text.ts +119 -0
  6. package/src/admin/dialog-tab-wrap.ts +78 -0
  7. package/src/admin/editor/A11yCopilot.tsx +2 -0
  8. package/src/admin/editor/Editor.tsx +18 -6
  9. package/src/admin/editor/Timeline.tsx +6 -2
  10. package/src/admin/editor/TopBar.tsx +27 -7
  11. package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
  12. package/src/admin/editor/canvas/DeviceBar.tsx +22 -9
  13. package/src/admin/editor/canvas/canvas-scale.ts +3 -3
  14. package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
  15. package/src/admin/editor/dnd/new-element.ts +22 -0
  16. package/src/admin/editor/editor-chrome.tsx +7 -5
  17. package/src/admin/editor/editor-commands.ts +10 -4
  18. package/src/admin/editor/editor-css.ts +2 -1
  19. package/src/admin/editor/panels/ElementPanel.tsx +29 -16
  20. package/src/admin/editor/panels/SettingsPanel.tsx +2 -2
  21. package/src/admin/editor/panels/settings/EffectsControls.tsx +79 -1
  22. package/src/admin/editor/panels/settings/IconControls.tsx +11 -0
  23. package/src/admin/editor/panels/settings/LengthRow.tsx +36 -3
  24. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +18 -0
  25. package/src/admin/editor/panels/settings/StyleRow.tsx +7 -0
  26. package/src/admin/editor/panels/settings/length-units.ts +15 -3
  27. package/src/admin/editor/panels/settings/style-sections.ts +1 -0
  28. package/src/admin/editor/panels/style-target.ts +17 -4
  29. package/src/admin/editor/section-templates.ts +26 -4
  30. package/src/admin/editor/store.ts +8 -2
  31. package/src/admin/editor/useEditorCommands.ts +7 -5
  32. package/src/admin/editor/useNodeActions.ts +4 -2
  33. package/src/admin/export-api.ts +221 -0
  34. package/src/admin/index.tsx +6 -1
  35. package/src/admin/pages/ExportDialog.tsx +395 -0
  36. package/src/admin/pages/PageList.tsx +67 -2
  37. package/src/admin/pages/ThemePartList.tsx +37 -1
  38. package/src/admin/pages/bulk.tsx +303 -0
  39. package/src/admin/search.ts +20 -0
  40. package/src/admin/theme-api.ts +4 -0
  41. package/src/admin/ui.ts +11 -2
  42. package/src/admin/widgets/CanvasField.tsx +8 -0
  43. package/src/admin/widgets/ConvertToRichText.tsx +136 -0
  44. package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
  45. package/src/admin/widgets/convert-body.ts +73 -2
  46. package/src/astro/render.ts +6 -6
  47. package/src/astro/resolve-theme.ts +11 -7
  48. package/src/astro/tabs/runtime.ts +16 -6
  49. package/src/constants.ts +1 -1
  50. package/src/core/a11y/audit.ts +2 -1
  51. package/src/core/contract.ts +22 -2
  52. package/src/core/css/generate.ts +83 -21
  53. package/src/core/css/scope.ts +10 -2
  54. package/src/core/css/trace.ts +33 -8
  55. package/src/core/design/classes.ts +25 -5
  56. package/src/core/design/devices.ts +78 -2
  57. package/src/core/design/variables.ts +14 -1
  58. package/src/core/export/runtimes.generated.ts +9 -0
  59. package/src/core/export/site.ts +562 -0
  60. package/src/core/export/zip.ts +95 -0
  61. package/src/core/history/diff.ts +25 -0
  62. package/src/core/import/elementor/atomic.ts +22 -9
  63. package/src/core/import/elementor/index.ts +22 -4
  64. package/src/core/import/elementor/style.ts +21 -1
  65. package/src/core/index.ts +14 -0
  66. package/src/core/json-schema.ts +8 -1
  67. package/src/core/perf/meter.ts +37 -19
  68. package/src/core/portable-text-export.ts +243 -0
  69. package/src/core/public-attributes.ts +30 -0
  70. package/src/core/render/index.ts +88 -9
  71. package/src/core/render/tabs.ts +18 -11
  72. package/src/core/sanitize/css.ts +26 -0
  73. package/src/core/schema/design.ts +2 -2
  74. package/src/core/schema/layout.ts +11 -3
  75. package/src/core/schema/style.ts +47 -0
  76. package/src/core/search-text.ts +70 -0
  77. package/src/core/theme/float.ts +1 -0
  78. package/src/core/theme/popup-rules.ts +16 -0
  79. package/src/mcp/read.ts +2 -3
  80. package/src/server/icon-routes.ts +52 -12
@@ -5,9 +5,15 @@ import { LIST_MARKERS } from "../css-keywords.ts";
5
5
  import { MAX_NODES } from "../limits.ts";
6
6
  import { loneAbTests, variantShows } from "../audience/variants.ts";
7
7
  import { audienceShows, audienceSummary } from "../audience/rules.ts";
8
- import { generateCss } from "../css/generate.ts";
8
+ import { baseRulesFor, generateCss } from "../css/generate.ts";
9
9
  import { printCss } from "../css/print.ts";
10
- import { cssScopeToken, scopeClassName, scopeCss, scopeWrapperCss } from "../css/scope.ts";
10
+ import {
11
+ cssScopeToken,
12
+ scopeClassName,
13
+ scopeCss,
14
+ scopeCssAll,
15
+ scopeWrapperCss,
16
+ } from "../css/scope.ts";
11
17
  import { ELEMENTS } from "../elements/index.ts";
12
18
  import { controlId } from "../elements/field-id.ts";
13
19
  import { layoutHasForm } from "../forms/binding.ts";
@@ -40,7 +46,8 @@ import { resolveEmbedUrl } from "../sanitize/embed-url.ts";
40
46
  import { sanitizeHref } from "../sanitize/href.ts";
41
47
  import { resolvePostForRender, type ThemeDynamicData } from "../theme/dynamic.ts";
42
48
  import type { FormDefinitions } from "../forms/definition.ts";
43
- import { DEVICES, type Device } from "../theme/popup-rules.ts";
49
+ import { DEVICES, type Device, type EditorDevice } from "../theme/popup-rules.ts";
50
+ import { hiddenOnEveryDevice } from "../design/devices.ts";
44
51
  import type { RenderContext, RenderMode } from "./context.ts";
45
52
  import { isDynamicPostNode, renderDynamicPost } from "./dynamic-post.ts";
46
53
  import { renderForm, withFieldOptions } from "./form.ts";
@@ -82,6 +89,8 @@ export type RenderResult = {
82
89
  /** The site's text direction when set in Site styles, for the host's `<html dir>` (W-230). */
83
90
  dir?: "ltr" | "rtl" | "auto";
84
91
  warnings: RenderWarning[];
92
+ /** W-971: the element types whose base rules this sheet holds (see `sharedPartCss`). */
93
+ baseTypes: string[];
85
94
  };
86
95
 
87
96
  const ID = /^[A-Za-z0-9_-]{4,24}$/;
@@ -206,6 +215,44 @@ function renameIds(vnode: VNode, base: string, next: string): VNode {
206
215
  /** Elements synced sections may add to one render, all copies together (W-653): 20 full pages. */
207
216
  const MAX_SECTION_ELEMENTS = 20 * MAX_NODES;
208
217
 
218
+ const baseCss = new Map(Object.entries(ELEMENTS).map(([type, def]) => [type, def.baseCss]));
219
+ // W-927: placeholder + wrapper styles ship with every page that may hold an extension node.
220
+ baseCss.set("ext", EXTENSION_PLACEHOLDER_CSS);
221
+
222
+ /**
223
+ * W-971: theme parts on one page (header, footer, popups, floats) each repeated the scope wrapper
224
+ * rule, the print rules and the base rules of their element types. Given their sheets (each the
225
+ * `css` of a scoped `renderPage`), this writes the wrapper and the union of base rules once, scoped
226
+ * to every part, then each part's own rules, then the print rules once. Base rules have no
227
+ * specificity of their own beyond their element class and came before every class and local rule
228
+ * in each sheet, so writing them first keeps the cascade.
229
+ */
230
+ export function sharedPartCss(
231
+ sheets: readonly { css: string; scope: string; baseTypes: readonly string[] }[],
232
+ ): string {
233
+ const scopes = sheets.flatMap((s) => {
234
+ const token = cssScopeToken(s.scope);
235
+ return token ? [token] : [];
236
+ });
237
+ if (scopes.length !== sheets.length || sheets.length < 2)
238
+ return sheets.map((s) => s.css).join("\n");
239
+ const wrapper = scopeWrapperCss();
240
+ const print = printCss();
241
+ const own: string[] = [];
242
+ for (const sheet of sheets) {
243
+ const token = cssScopeToken(sheet.scope) as string;
244
+ const base = scopeCss(baseRulesFor(sheet.baseTypes, baseCss), token);
245
+ let css = sheet.css;
246
+ if (!css.startsWith(wrapper) || !css.endsWith(print) || (base && !css.includes(base)))
247
+ return sheets.map((s) => s.css).join("\n");
248
+ css = css.slice(wrapper.length, css.length - print.length);
249
+ own.push(base ? css.replace(base, "") : css);
250
+ }
251
+ const union = new Set(sheets.flatMap((s) => s.baseTypes));
252
+ const shared = scopeCssAll(baseRulesFor(union, baseCss), scopes);
253
+ return [wrapper + shared, ...own, print].filter(Boolean).join("\n");
254
+ }
255
+
209
256
  export function renderPage(
210
257
  storedLayout: Layout,
211
258
  storedDesign: DesignSystem,
@@ -216,7 +263,7 @@ export function renderPage(
216
263
  /** Public renders: wrap the markup and scope the CSS to it, so sheets can't override each other (W-112). */
217
264
  scope?: string;
218
265
  /** Editor canvas: device rules follow this device, not the frame width (W-116). */
219
- previewDevice?: Device;
266
+ previewDevice?: EditorDevice;
220
267
  /**
221
268
  * Theme parts (header, footer, popup, float) render apart from the page, so a synced section
222
269
  * on both gave form fields, honeypots and tab groups the same ids: a label in a popup focused
@@ -239,6 +286,8 @@ export function renderPage(
239
286
  id: string;
240
287
  declarations: Declaration[];
241
288
  states: StateDeclarations;
289
+ wide?: Declaration[];
290
+ wideHidden?: boolean;
242
291
  laptop?: Declaration[];
243
292
  tablet?: Declaration[];
244
293
  mobile?: Declaration[];
@@ -355,7 +404,21 @@ export function renderPage(
355
404
  const mobile = styleDeclarations(
356
405
  withInheritedLayers(node.devices?.mobile, { ...base, ...laptopStyle, ...tabletStyle }),
357
406
  );
358
- for (const key of [...rejected, ...laptop.rejected, ...tablet.rejected, ...mobile.rejected]) {
407
+ // W-959: Wide screen (2400 px and up) builds on Desktop; `renderableNode` moved `style.wide`
408
+ // here. The narrower devices never overlap it, so they don't inherit it.
409
+ const { devices: wideDevices, wideHidden } = node as {
410
+ devices?: { wide?: unknown };
411
+ wideHidden?: boolean;
412
+ };
413
+ const wideStyle = wideDevices?.wide;
414
+ const wide = styleDeclarations(withInheritedLayers(wideStyle, base));
415
+ for (const key of [
416
+ ...rejected,
417
+ ...wide.rejected,
418
+ ...laptop.rejected,
419
+ ...tablet.rejected,
420
+ ...mobile.rejected,
421
+ ]) {
359
422
  warnings.push({ nodeId, code: "rejected-style", detail: key });
360
423
  }
361
424
  if (node.type === "spacer") {
@@ -461,6 +524,20 @@ export function renderPage(
461
524
  tablet.declarations.push(at(2));
462
525
  mobile.declarations.push(at(3));
463
526
  }
527
+ // W-959: a Wide screen placement of its own, on the Desktop column count.
528
+ const wideOwn = wideStyle as { gridColumnStart?: unknown; gridColumnSpan?: unknown };
529
+ if (
530
+ wideOwn &&
531
+ (wideOwn.gridColumnStart !== undefined || wideOwn.gridColumnSpan !== undefined)
532
+ ) {
533
+ const place = { ...node.style, ...wideOwn } as typeof node.style & object;
534
+ const fit = fitGridColumn(place.gridColumnStart, place.gridColumnSpan, desktopCount);
535
+ const others = wide.declarations.filter((d) => d.property !== "grid-column");
536
+ wide.declarations.splice(0, wide.declarations.length, ...others, {
537
+ property: "grid-column",
538
+ value: fit.value ?? "auto",
539
+ });
540
+ }
464
541
  }
465
542
  const states = stateDeclarations(node.states);
466
543
  for (const key of states.rejected) {
@@ -474,6 +551,8 @@ export function renderPage(
474
551
  // W-567: the root is the page itself; hiding it on a device blanked the whole page there.
475
552
  const hiddenOn = isRoot ? undefined : node.hiddenOn;
476
553
  const responsive =
554
+ wide.declarations.length > 0 ||
555
+ (!isRoot && wideHidden !== undefined) ||
477
556
  laptop.declarations.length > 0 ||
478
557
  tablet.declarations.length > 0 ||
479
558
  mobile.declarations.length > 0 ||
@@ -492,6 +571,8 @@ export function renderPage(
492
571
  id: ruleId,
493
572
  declarations,
494
573
  states: states.states,
574
+ ...(wide.declarations.length > 0 ? { wide: wide.declarations } : {}),
575
+ ...(!isRoot && wideHidden !== undefined ? { wideHidden } : {}),
495
576
  laptop: laptop.declarations,
496
577
  tablet: tablet.declarations,
497
578
  mobile: mobile.declarations,
@@ -606,7 +687,7 @@ export function renderPage(
606
687
  if (node.type === "heading" && pageHeadings?.has(stored) && attrs.id) {
607
688
  const text = String((node.props as { text?: unknown }).text ?? "").trim();
608
689
  // W-409: a heading hidden on every device has nothing to jump to.
609
- const hiddenEverywhere = DEVICES.every((device) => node.hiddenOn?.includes(device));
690
+ const hiddenEverywhere = hiddenOnEveryDevice(node);
610
691
  if (text && !hiddenEverywhere && !renderedHeadings.some((h) => h.id === attrs.id)) {
611
692
  // W-793: a heading hidden on some devices (itself or an ancestor) hides its contents
612
693
  // entry there too, or the entry was a dead link on those devices.
@@ -685,9 +766,6 @@ export function renderPage(
685
766
  toc.vnode.children = [];
686
767
  }
687
768
  }
688
- const baseCss = new Map(Object.entries(ELEMENTS).map(([type, def]) => [type, def.baseCss]));
689
- // W-927: placeholder + wrapper styles ship with every page that may hold an extension node.
690
- baseCss.set("ext", EXTENSION_PLACEHOLDER_CSS);
691
769
  const css = generateCss({
692
770
  design,
693
771
  usedTypes,
@@ -712,6 +790,7 @@ export function renderPage(
712
790
  needsMenuRuntime: rendered.menuDropdown || layoutHasMenuDropdown(layout),
713
791
  ...(design.direction ? { dir: design.direction } : {}),
714
792
  warnings,
793
+ baseTypes: [...usedTypes],
715
794
  };
716
795
  }
717
796
 
@@ -29,19 +29,26 @@ export function renderTabs(
29
29
  inputs.push({ tag: "input", attrs: inputAttrs, children: [] });
30
30
  const panelDomId = `${group}-panel-${i}`;
31
31
  const tabDomId = `${group}-tab-${i}`;
32
+ // W-975: ARIA allows no role on a <label>, so the tab is a span inside it; the label still
33
+ // switches the radio, which keeps the tabs working without the script.
32
34
  labels.push({
33
35
  tag: "label",
34
- attrs: {
35
- class: "emvb-tab-label",
36
- for: inputId,
37
- id: tabDomId,
38
- role: "tab",
39
- "aria-selected": i === 0 ? "true" : "false",
40
- "aria-controls": panelDomId,
41
- tabindex: i === 0 ? "0" : "-1",
42
- },
43
- // W-664: a label of only spaces made a zero-width tab nobody could click or hear.
44
- children: [panel.props.label.trim() || `Tab ${i + 1}`],
36
+ attrs: { class: "emvb-tab-label", for: inputId },
37
+ children: [
38
+ {
39
+ tag: "span",
40
+ attrs: {
41
+ class: "emvb-tab",
42
+ id: tabDomId,
43
+ role: "tab",
44
+ "aria-selected": i === 0 ? "true" : "false",
45
+ "aria-controls": panelDomId,
46
+ tabindex: i === 0 ? "0" : "-1",
47
+ },
48
+ // W-664: a label of only spaces made a zero-width tab nobody could click or hear.
49
+ children: [panel.props.label.trim() || `Tab ${i + 1}`],
50
+ },
51
+ ],
45
52
  });
46
53
  // W-598: the panel renders like any element, so its own style, classes and device
47
54
  // visibility reach the page; the tab wiring is added on top.
@@ -738,6 +738,8 @@ const PROPERTY_MAP: {
738
738
  iconScale: { css: "scale", toValue: cssIconScale },
739
739
  iconStrokeWidth: { css: "--emvb-icon-stroke", toValue: cssIconStroke },
740
740
  iconShadow: { css: "--emvb-icon-shadow", toValue: cssIconShadow },
741
+ // W-974: applied by `withViewportUnits` to the record's lengths; never a declaration of its own.
742
+ viewportUnits: { css: "--emvb-viewport-units", toValue: () => undefined },
741
743
  iconAnimation: { css: "--emvb-icon-animation", toValue: cssIconAnimation },
742
744
  };
743
745
 
@@ -787,6 +789,28 @@ function transformDeclarations(value: unknown): Declaration[] | undefined {
787
789
  return out;
788
790
  }
789
791
 
792
+ const VH_LENGTH = /^(-?\d+(?:\.\d+)?)vh$/;
793
+
794
+ /**
795
+ * W-974: a `vh` length the record marks as `dvh` or `svh` is written in that unit. Only a plain
796
+ * number with `vh` changes; a variable, `clamp()` or `auto` is left alone.
797
+ */
798
+ function withViewportUnits(declarations: Declaration[], units: unknown): void {
799
+ if (!isRecord(units)) return;
800
+ for (const [key, unit] of Object.entries(units)) {
801
+ if (unit !== "dvh" && unit !== "svh") continue;
802
+ const entry = Object.hasOwn(PROPERTY_MAP, key)
803
+ ? PROPERTY_MAP[key as keyof FlatStyleProps]
804
+ : undefined;
805
+ if (!entry) continue;
806
+ for (const declaration of declarations) {
807
+ if (declaration.property !== entry.css) continue;
808
+ const match = VH_LENGTH.exec(declaration.value);
809
+ if (match) declaration.value = `${match[1]}${unit}`;
810
+ }
811
+ }
812
+ }
813
+
790
814
  export function styleDeclarations(style: unknown): {
791
815
  declarations: Declaration[];
792
816
  rejected: string[];
@@ -807,6 +831,7 @@ export function styleDeclarations(style: unknown): {
807
831
  ) {
808
832
  continue;
809
833
  }
834
+ if (key === "viewportUnits") continue;
810
835
  if (key === "loopMotion") {
811
836
  const found = loopDeclarations(raw);
812
837
  if (found && found.every((d) => isSafeCssValue(d.value))) loop = found;
@@ -847,6 +872,7 @@ export function styleDeclarations(style: unknown): {
847
872
  rejected.push(key);
848
873
  }
849
874
  }
875
+ withViewportUnits(declarations, record["viewportUnits"]);
850
876
  const background = composeBackground(record);
851
877
  declarations.push(...background.declarations);
852
878
  rejected.push(...background.rejected);
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { HEX_COLOR } from "../css-keywords.ts";
3
- import { DeviceStyles, HiddenOn, StyleProps, StyleStates } from "./style.ts";
3
+ import { DeviceStyles, HiddenOn, OwnStyle, StyleProps, StyleStates } from "./style.ts";
4
4
 
5
5
  /**
6
6
  * 17 since W-925 (contract 1.0): the motion style keys sit under one `motion` record.
@@ -65,7 +65,7 @@ export type FluidRange = z.infer<typeof FluidRange>;
65
65
  const StyleClass = z.strictObject({
66
66
  id: VariableId,
67
67
  name: z.string().min(1).max(60),
68
- style: StyleProps,
68
+ style: OwnStyle,
69
69
  states: StyleStates.optional(),
70
70
  devices: DeviceStyles.optional(),
71
71
  hiddenOn: HiddenOn.optional(),
@@ -2,7 +2,15 @@ import { z } from "zod";
2
2
  import { LIST_MARKERS } from "../css-keywords.ts";
3
3
  import { MAX_TEXT_LENGTH } from "../limits.ts";
4
4
  import { ImageEdit } from "../image-edit/schema.ts";
5
- import { ColorValue, DeviceStyles, HiddenOn, Length, StyleProps, StyleStates } from "./style.ts";
5
+ import {
6
+ ColorValue,
7
+ DeviceStyles,
8
+ HiddenOn,
9
+ Length,
10
+ OwnStyle,
11
+ StyleProps,
12
+ StyleStates,
13
+ } from "./style.ts";
6
14
 
7
15
  /**
8
16
  * 16 since W-481 (D-061): an optional editor-only `edit` record on images (image editor).
@@ -167,7 +175,7 @@ const BoxLink = {
167
175
  * `dir`, `container` and `query` before this.
168
176
  */
169
177
  const sharedNodeFields = {
170
- style: StyleProps.optional(),
178
+ style: OwnStyle.optional(),
171
179
  states: StyleStates.optional(),
172
180
  devices: DeviceStyles.optional(),
173
181
  hiddenOn: HiddenOn.optional(),
@@ -903,7 +911,7 @@ export type NodeExtras = {
903
911
  /** Identity, style and extras shared by every node type (W-352). */
904
912
  type NodeEnvelope = {
905
913
  id: IdOf;
906
- style?: StyleOf;
914
+ style?: z.infer<typeof OwnStyle>;
907
915
  states?: StatesOf;
908
916
  devices?: DevicesOf;
909
917
  hiddenOn?: HiddenOnOf;
@@ -268,6 +268,32 @@ const Overlay = z.union([
268
268
  * Style properties for layout and text elements (W-017 / R-012). Unknown keys are refused here;
269
269
  * `validateLayout` and `validateDesign` keep a newer 1.x key aside and puts it back untouched (D-065, W-925).
270
270
  */
271
+ /** W-974: the length keys whose `vh` can be drawn as `dvh` or `svh`. */
272
+ const VIEWPORT_UNIT_KEYS = [
273
+ "width",
274
+ "minWidth",
275
+ "maxWidth",
276
+ "height",
277
+ "minHeight",
278
+ "maxHeight",
279
+ "flexBasis",
280
+ "gap",
281
+ "fontSize",
282
+ "paddingTop",
283
+ "paddingRight",
284
+ "paddingBottom",
285
+ "paddingLeft",
286
+ "marginTop",
287
+ "marginRight",
288
+ "marginBottom",
289
+ "marginLeft",
290
+ "top",
291
+ "right",
292
+ "bottom",
293
+ "left",
294
+ ] as const;
295
+ const VIEWPORT_UNITS = ["dvh", "svh"] as const;
296
+
271
297
  export const StyleProps = z.strictObject({
272
298
  flexDirection: z.enum(FLEX_DIRECTIONS).optional(),
273
299
  flexWrap: z.enum(FLEX_WRAPS).optional(),
@@ -438,11 +464,32 @@ export const StyleProps = z.strictObject({
438
464
  color: ColorValue.optional(),
439
465
  })
440
466
  .optional(),
467
+ /**
468
+ * W-974 (1.1): which `vh` lengths in this record are drawn in dynamic (`dvh`) or small (`svh`)
469
+ * viewport units, for full-height sections on phones. The length itself stays `vh`, so 1.0
470
+ * (which ignores this key) still draws it in `vh`.
471
+ */
472
+ viewportUnits: z.partialRecord(z.enum(VIEWPORT_UNIT_KEYS), z.enum(VIEWPORT_UNITS)).optional(),
441
473
  motion: Motion.optional(),
442
474
  });
443
475
 
444
476
  export type StyleProps = z.infer<typeof StyleProps>;
445
477
 
478
+ /**
479
+ * W-959 (1.1): Wide screen, 2400 px and up (Elementor's widescreen breakpoint). Its overrides sit
480
+ * in the element's or class's own `style` as `style.wide`, a key 1.0 keeps and ignores, so a 1.1
481
+ * page still opens in 1.0 and shows its Desktop look on wide screens. `hidden` overrides the
482
+ * Desktop hide on wide screens: true hides it there, false shows it; unset follows Desktop.
483
+ */
484
+ export const WideStyle = StyleProps.extend({ hidden: z.boolean().optional() });
485
+
486
+ export type WideStyle = z.infer<typeof WideStyle>;
487
+
488
+ /** An element's or class's own `style`: the Desktop values plus the Wide screen ones. */
489
+ export const OwnStyle = StyleProps.extend({ wide: WideStyle.optional() });
490
+
491
+ export type OwnStyle = z.infer<typeof OwnStyle>;
492
+
446
493
  /**
447
494
  * The pre-1.0 flat style shape: `motion`'s parts as the top-level keys `entrance`, `scrollMotion`,
448
495
  * `transition` and `iconAnimation` (W-925). The editor's style rows and the CSS sanitizer work on
@@ -0,0 +1,70 @@
1
+ import { isRecord } from "./record.ts";
2
+
3
+ /** Props whose strings are words a visitor reads (W-978), not ids, URLs or settings. */
4
+ const WORD_KEYS: ReadonlySet<string> = new Set([
5
+ "text",
6
+ "label",
7
+ "summary",
8
+ "alt",
9
+ "caption",
10
+ "placeholder",
11
+ "title",
12
+ "description",
13
+ "items",
14
+ "quote",
15
+ "author",
16
+ "role",
17
+ "prefix",
18
+ "suffix",
19
+ ]);
20
+
21
+ /** At most this many characters per layout, so a huge page can't slow the list down. */
22
+ const MAX_SEARCH_TEXT = 20_000;
23
+
24
+ /**
25
+ * W-978: the words of a stored layout (headings, text, buttons, list items, labels, alt text),
26
+ * for searching lists by content. Reads raw JSON (or a JSON string), so an unreadable layout
27
+ * gives "" rather than an error. Synced sections are read where they live, not here.
28
+ */
29
+ export function layoutSearchText(layout: unknown): string {
30
+ let value = layout;
31
+ if (typeof value === "string") {
32
+ try {
33
+ value = JSON.parse(value) as unknown;
34
+ } catch {
35
+ return "";
36
+ }
37
+ }
38
+ if (!isRecord(value)) return "";
39
+ const out: string[] = [];
40
+ let length = 0;
41
+ const push = (text: string) => {
42
+ if (length >= MAX_SEARCH_TEXT) return;
43
+ const trimmed = text.trim();
44
+ if (!trimmed) return;
45
+ out.push(trimmed);
46
+ length += trimmed.length + 1;
47
+ };
48
+ const stack: unknown[] = [value["root"]];
49
+ while (stack.length > 0) {
50
+ if (length >= MAX_SEARCH_TEXT) break;
51
+ const node = stack.pop();
52
+ if (!isRecord(node)) continue;
53
+ const props = node["props"];
54
+ if (isRecord(props)) {
55
+ for (const [key, prop] of Object.entries(props)) {
56
+ if (!WORD_KEYS.has(key)) continue;
57
+ if (typeof prop === "string") push(prop);
58
+ else if (Array.isArray(prop))
59
+ for (const item of prop) {
60
+ if (typeof item === "string") push(item);
61
+ else if (isRecord(item) && typeof item["label"] === "string") push(item["label"]);
62
+ }
63
+ }
64
+ }
65
+ const children = node["children"];
66
+ if (Array.isArray(children))
67
+ for (let i = children.length - 1; i >= 0; i -= 1) stack.push(children[i]);
68
+ }
69
+ return out.join(" ").slice(0, MAX_SEARCH_TEXT);
70
+ }
@@ -90,6 +90,7 @@ export function floatHasOwnSurface(layout: Layout, design: DesignSystem): boolea
90
90
  return [root, ...classes].some(
91
91
  (item) =>
92
92
  paintsBackground(item.style) ||
93
+ paintsBackground(item.style?.wide) ||
93
94
  paintsBackground(item.devices?.laptop) ||
94
95
  paintsBackground(item.devices?.tablet) ||
95
96
  paintsBackground(item.devices?.mobile),
@@ -30,6 +30,17 @@ export type StyleDevice = (typeof STYLE_DEVICES)[number];
30
30
  */
31
31
  export const DEVICE_PREVIEW_PX = { desktop: 1280, laptop: 1200, tablet: 768, mobile: 390 } as const;
32
32
 
33
+ /**
34
+ * W-959 (1.1): the devices the editor shows, Wide screen first. Wide screen is not a `hiddenOn`
35
+ * value (1.0 would refuse it): its values and hide live in the own style's `wide` record.
36
+ */
37
+ export const EDITOR_DEVICES = ["wide", ...DEVICES] as const;
38
+ export type EditorDevice = (typeof EDITOR_DEVICES)[number];
39
+
40
+ /** W-959: Wide screen starts at 2400 px (Elementor's widescreen); the canvas lays it out at 2560. */
41
+ export const WIDE_MIN_PX = 2400;
42
+ export const WIDE_PREVIEW_PX = 2560;
43
+
33
44
  /**
34
45
  * Public CSS queries. Bounds match `deviceForWidth`: below 768 mobile, below 1025 tablet.
35
46
  * W-506: zoom and display scaling give fractional viewport widths; with whole-pixel bounds a
@@ -47,6 +58,11 @@ export const DEVICE_MEDIA = {
47
58
  hideLaptop: "(min-width: 1025px) and (max-width: 1366.98px)",
48
59
  hideTablet: "(min-width: 768px) and (max-width: 1024.98px)",
49
60
  hideMobile: "(max-width: 767.98px)",
61
+ /** W-959: Wide screen, 2400 px and up. */
62
+ wide: "(min-width: 2400px)",
63
+ /** An element hidden on Desktop that Wide screen shows again (`wide.hidden: false`). */
64
+ hideDesktopNotWide: "(min-width: 1025px) and (max-width: 2399.98px)",
65
+ hideDesktopOnlyNotWide: "(min-width: 1367px) and (max-width: 2399.98px)",
50
66
  } as const;
51
67
 
52
68
  /** A scroll percent as a number from 0 to 100; anything unreadable is 0. */
package/src/mcp/read.ts CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  type ElementType,
16
16
  type Layout,
17
17
  type LayoutNode,
18
- DEVICES,
18
+ hiddenOnEveryDevice,
19
19
  } from "../core/index.ts";
20
20
  import { parentChildRefusal } from "../core/arrange.ts";
21
21
  import { clipText } from "../core/limits.ts";
@@ -317,8 +317,7 @@ function imagesOf(root: LayoutNode) {
317
317
  function hiddenEverywhere(root: LayoutNode) {
318
318
  const warnings: { nodeId: string; message: string }[] = [];
319
319
  const walk = (node: LayoutNode) => {
320
- const hidden = new Set((node as { hiddenOn?: string[] }).hiddenOn ?? []);
321
- if (DEVICES.every((device) => hidden.has(device))) {
320
+ if (hiddenOnEveryDevice(node)) {
322
321
  warnings.push({
323
322
  nodeId: node.id,
324
323
  message:
@@ -24,16 +24,40 @@ type IconStore = {
24
24
  query(options?: {
25
25
  orderBy?: Record<string, "asc" | "desc">;
26
26
  limit?: number;
27
- }): Promise<{ items: Array<{ id: string; data: UploadedIcon }>; hasMore: boolean }>;
27
+ cursor?: string;
28
+ }): Promise<{
29
+ items: Array<{ id: string; data: UploadedIcon }>;
30
+ hasMore: boolean;
31
+ cursor?: string;
32
+ }>;
28
33
  };
29
34
 
30
35
  const store = (ctx: RouteContext<unknown>) => ctx.storage["icons"] as unknown as IconStore;
31
36
 
32
37
  /**
33
- * The uploads the picker lists, and the most My uploads holds (W-535): past it the oldest
34
- * uploads dropped off the list and could no longer be seen or deleted.
38
+ * The most My uploads holds, and the uploads the picker lists (W-535; 500 since W-972). EmDash
39
+ * returns plugin storage 100 rows at a time, so the list is read page by page.
35
40
  */
36
- export const UPLOAD_LIST_LIMIT = 100;
41
+ export const UPLOAD_LIST_LIMIT = 500;
42
+ const STORAGE_PAGE = 100;
43
+
44
+ /** Every upload, newest first, up to the limit, following EmDash's storage cursor (W-972). */
45
+ async function allUploads(ctx: RouteContext<unknown>) {
46
+ const items: Array<{ id: string; data: UploadedIcon }> = [];
47
+ let cursor: string | undefined;
48
+ for (let page = 0; page < UPLOAD_LIST_LIMIT / STORAGE_PAGE; page += 1) {
49
+ // oxlint-disable-next-line no-await-in-loop -- each page needs the previous page's cursor
50
+ const result = await store(ctx).query({
51
+ orderBy: { uploadedAt: "desc" },
52
+ limit: STORAGE_PAGE,
53
+ ...(cursor ? { cursor } : {}),
54
+ });
55
+ items.push(...result.items);
56
+ if (!result.hasMore || !result.cursor) break;
57
+ cursor = result.cursor;
58
+ }
59
+ return items.slice(0, UPLOAD_LIST_LIMIT);
60
+ }
37
61
 
38
62
  /** An icon's label as typed: trimmed and capped (W-655: a rename may hold a slash, as in "AC/DC"). */
39
63
  // W-656: control characters become spaces and invisible or direction-changing marks go, so a
@@ -75,11 +99,7 @@ export function publicUploadedIcon(id: string, data: UploadedIcon): UploadedIcon
75
99
  export const iconsRoute: PluginRoute = {
76
100
  permission: "content:edit_any",
77
101
  handler: async (ctx) => {
78
- const page = await store(ctx).query({
79
- orderBy: { uploadedAt: "desc" },
80
- limit: UPLOAD_LIST_LIMIT,
81
- });
82
- const items = page.items.flatMap(({ id, data }) => {
102
+ const items = (await allUploads(ctx)).flatMap(({ id, data }) => {
83
103
  const item = publicUploadedIcon(id, data);
84
104
  return item ? [item] : [];
85
105
  });
@@ -100,15 +120,27 @@ export const iconUploadRoute: PluginRoute<z.infer<typeof UploadInput>> = {
100
120
  handler: async (ctx) => {
101
121
  const prepared = prepareUploadedSvg(ctx.input.svg);
102
122
  if (!prepared.ok) throw new PluginRouteError("INVALID_SVG", prepared.message, 422);
103
- const held = await store(ctx).query({ limit: UPLOAD_LIST_LIMIT });
104
- if (held.items.length >= UPLOAD_LIST_LIMIT) {
123
+ const held = await allUploads(ctx);
124
+ // W-972: the same SVG uploaded again (twice at once from two tabs, or later) is the icon
125
+ // already in My uploads; the check runs on the sanitized markup, so it is the same drawing.
126
+ const same = held.find(({ data }) => data.svg === prepared.svg);
127
+ if (same) {
128
+ return {
129
+ item: { id: same.id, ...same.data },
130
+ imagesLeftOut: prepared.imagesLeftOut,
131
+ duplicate: true,
132
+ };
133
+ }
134
+ if (held.length >= UPLOAD_LIST_LIMIT) {
105
135
  throw new PluginRouteError(
106
136
  "UPLOADS_FULL",
107
137
  `My uploads holds up to ${UPLOAD_LIST_LIMIT} icons. Delete one you no longer use, then upload again.`,
108
138
  409,
109
139
  );
110
140
  }
111
- const id = crypto.randomUUID().replaceAll("-", "").slice(0, 16);
141
+ // W-972: the id is the drawing's hash, so two uploads of the same SVG at the same moment
142
+ // land on one row instead of two.
143
+ const id = await svgId(prepared.svg);
112
144
  const item: UploadedIcon = {
113
145
  name: uploadName(ctx.input.name),
114
146
  svg: prepared.svg,
@@ -119,6 +151,14 @@ export const iconUploadRoute: PluginRoute<z.infer<typeof UploadInput>> = {
119
151
  },
120
152
  };
121
153
 
154
+ /** The first 16 hex digits of the SHA-256 of the sanitized markup. */
155
+ async function svgId(svg: string): Promise<string> {
156
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(svg));
157
+ return [...new Uint8Array(digest).slice(0, 8)]
158
+ .map((b) => b.toString(16).padStart(2, "0"))
159
+ .join("");
160
+ }
161
+
122
162
  const IdInput = z.object({
123
163
  id: z.string().regex(/^[0-9a-f]{16}$/, "Unknown icon"),
124
164
  });