@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
@@ -1,5 +1,13 @@
1
- import { portableTextToLayout, type Layout } from "../../core/index.ts";
2
- import { requestJson, type Fetcher } from "../api.ts";
1
+ import {
2
+ collectSectionPartIds,
3
+ portableTextToLayout,
4
+ validateLayout,
5
+ type Layout,
6
+ } from "../../core/index.ts";
7
+ import { layoutToPortableText, type PortableTextBlock } from "../../core/portable-text-export.ts";
8
+ import { THEME_PARTS_COLLECTION } from "../../constants.ts";
9
+ import { listAllItems, requestJson, type Fetcher } from "../api.ts";
10
+ import type { ContentItem } from "../content-item.ts";
3
11
  import { readCollection } from "../setup/run.ts";
4
12
 
5
13
  const SLUG = /^[a-z][a-z0-9_-]{0,63}$/;
@@ -52,3 +60,66 @@ export async function convertEntryBody(
52
60
  return { ok: false, message: "Nothing in the saved body could be converted." };
53
61
  return { ok: true, ...result, field: field.slug };
54
62
  }
63
+
64
+ export type RichTextPlan =
65
+ | {
66
+ ok: true;
67
+ field: string;
68
+ body: PortableTextBlock[];
69
+ converted: number;
70
+ skipped: Record<string, number>;
71
+ /** The field already holds content that this replaces. */
72
+ replaces: boolean;
73
+ }
74
+ | { ok: false; message: string };
75
+
76
+ /**
77
+ * W-963: the reverse of Convert to EmVB, planned but not written: the layout as rich text for the
78
+ * entry's first Portable Text field (`content` first), with synced sections resolved.
79
+ */
80
+ export async function planRichText(
81
+ fetcher: Fetcher,
82
+ entry: { collection: string; id: string },
83
+ layout: Layout,
84
+ ): Promise<RichTextPlan> {
85
+ const schema = await readCollection(fetcher, entry.collection);
86
+ const rich = (schema?.fields ?? []).filter((f) => f.type === "portableText");
87
+ const field = rich.find((f) => f.slug === "content") ?? rich[0];
88
+ if (!field)
89
+ return { ok: false, message: "This collection has no rich-text field to convert into." };
90
+ const [data, parts] = await Promise.all([
91
+ requestJson<{ item: { data?: Record<string, unknown> } }>(fetcher, entryPath(entry)),
92
+ collectSectionPartIds(layout).length > 0
93
+ ? listAllItems<ContentItem>(fetcher, `/_emdash/api/content/${THEME_PARTS_COLLECTION}`)
94
+ : Promise.resolve([]),
95
+ ]);
96
+ const sectionTemplates: Record<string, Layout> = {};
97
+ for (const part of parts) {
98
+ if (part.status !== "published" || part.data?.["part_type"] !== "section") continue;
99
+ const checked = validateLayout(part.data["layout"]);
100
+ if (checked.ok) sectionTemplates[part.id] = checked.layout;
101
+ }
102
+ const result = layoutToPortableText(layout, { sectionTemplates });
103
+ if (result.body.length === 0)
104
+ return { ok: false, message: "This layout has no words or images to convert." };
105
+ const current = data.item.data?.[field.slug];
106
+ const replaces =
107
+ (Array.isArray(current) && current.length > 0) ||
108
+ (typeof current === "string" && current.trim() !== "" && current.trim() !== "[]");
109
+ return { ok: true, field: field.slug, ...result, replaces };
110
+ }
111
+
112
+ /** Writes a planned body into the entry's rich-text field. Nothing else on the entry changes. */
113
+ export async function writeRichText(
114
+ fetcher: Fetcher,
115
+ entry: { collection: string; id: string },
116
+ plan: Extract<RichTextPlan, { ok: true }>,
117
+ ): Promise<void> {
118
+ await requestJson(fetcher, entryPath(entry), {
119
+ method: "PUT",
120
+ body: { data: { [plan.field]: plan.body } },
121
+ });
122
+ }
123
+
124
+ const entryPath = (entry: { collection: string; id: string }) =>
125
+ `/_emdash/api/content/${encodeURIComponent(entry.collection)}/${encodeURIComponent(entry.id)}`;
@@ -19,6 +19,8 @@ export type RenderedPage = {
19
19
  needsMenuRuntime: boolean;
20
20
  /** The site's text direction when set, for the host's `<html dir>` (W-230). */
21
21
  dir?: "ltr" | "rtl" | "auto";
22
+ /** W-971: the element types whose base rules `css` holds, for `sharedPartCss`. */
23
+ baseTypes?: string[];
22
24
  };
23
25
 
24
26
  /** The design document through the in-process public route (no HTTP round trip, D-013). */
@@ -92,17 +94,14 @@ export function renderStored(
92
94
  ...(design.direction ? { dir: design.direction } : {}),
93
95
  };
94
96
  }
95
- const { html, css, needsFormsRuntime, needsTabsRuntime, needsMenuRuntime } = renderPage(
96
- layout,
97
- design,
98
- {
97
+ const { html, css, needsFormsRuntime, needsTabsRuntime, needsMenuRuntime, baseTypes } =
98
+ renderPage(layout, design, {
99
99
  formDefinitions,
100
100
  dynamic,
101
101
  scope: pageId,
102
102
  ...(partIds ? { partIds } : {}),
103
103
  ...(lang ? { lang } : {}),
104
- },
105
- );
104
+ });
106
105
  return {
107
106
  html,
108
107
  css,
@@ -110,5 +109,6 @@ export function renderStored(
110
109
  needsTabsRuntime,
111
110
  needsMenuRuntime,
112
111
  ...(design.direction ? { dir: design.direction } : {}),
112
+ baseTypes,
113
113
  };
114
114
  }
@@ -14,6 +14,7 @@ import {
14
14
  parseThemePartType,
15
15
  pickThemePartWinner,
16
16
  POPUP_CHROME_CSS,
17
+ sharedPartCss,
17
18
  validateConditions,
18
19
  validateFloatSettings,
19
20
  validateTriggers,
@@ -528,6 +529,8 @@ export async function resolveThemePartsWith(
528
529
 
529
530
  const byId = new Map(parts.map((part) => [part.id, part]));
530
531
  const rendered: RenderedPage[] = [];
532
+ // W-971: each part's scoped sheet, to write the shared rules once in `css`.
533
+ const sheets = new Map<string, { css: string; scope: string; baseTypes: readonly string[] }>();
531
534
  // W-307: bound fields in a part read site settings and URL parameters too.
532
535
  // W-312/W-313: synced sections and Loop items the part uses count too.
533
536
  const boundFor = (stored: StoredPart, referenced: ThemeDynamicData | undefined) =>
@@ -571,6 +574,8 @@ export async function resolveThemePartsWith(
571
574
  options.lang ?? astro.currentLocale,
572
575
  );
573
576
  rendered.push(page);
577
+ if (page.css)
578
+ sheets.set(stored.id, { css: page.css, scope: stored.id, baseTypes: page.baseTypes ?? [] });
574
579
  // W-216: a header or footer part is the page's banner or contentinfo landmark (hosts put it
575
580
  // straight in <body> instead of their own <header>/<footer>).
576
581
  // W-586: a part that already has its own header or footer box keeps that one as the landmark;
@@ -711,13 +716,12 @@ export async function resolveThemePartsWith(
711
716
  )
712
717
  ).filter((item): item is RenderedFloat => item !== null);
713
718
 
714
- const cssParts = [
715
- header?.css,
716
- content?.css,
717
- footer?.css,
718
- ...popups.map((p) => p.css),
719
- ...floats.map((item) => item.css),
720
- ];
719
+ // W-971: the parts' shared rules (scope wrapper, element base rules, print) are written once.
720
+ const ordered = [header, content, footer, ...popups, ...floats].flatMap((part) => {
721
+ const sheet = part ? sheets.get(part.id) : undefined;
722
+ return sheet ? [sheet] : [];
723
+ });
724
+ const cssParts = [sharedPartCss(ordered)];
721
725
  if (popups.length > 0) cssParts.push(POPUP_CHROME_CSS);
722
726
  if (floats.length > 0) cssParts.push(FLOAT_CHROME_CSS);
723
727
  const css = cssParts.filter(Boolean).join("\n");
@@ -24,6 +24,13 @@ const KEY_TARGETS: Record<string, (current: number, count: number) => number> =
24
24
  End: (_current, count) => count - 1,
25
25
  };
26
26
 
27
+ /**
28
+ * W-975: the element with the tab role: a span inside the label since 1.1; the label itself on
29
+ * pages rendered before.
30
+ */
31
+ const tabOf = (label: HTMLElement): HTMLElement =>
32
+ label.querySelector<HTMLElement>(":scope > [role='tab']") ?? label;
33
+
27
34
  /** Selects tab `index`; only keyboard navigation moves focus, never load or a radio change. */
28
35
  function activate(root: HTMLElement, index: number, focus = false): void {
29
36
  if (root.dataset["emvbTabsActivating"] === "1") return;
@@ -37,11 +44,13 @@ function activate(root: HTMLElement, index: number, focus = false): void {
37
44
  if (!input.checked) input.checked = true;
38
45
  for (const [i, label] of labels.entries()) {
39
46
  const selected = i === next;
40
- label.setAttribute("aria-selected", String(selected));
41
- label.tabIndex = selected ? 0 : -1;
47
+ const tab = tabOf(label);
48
+ tab.setAttribute("aria-selected", String(selected));
49
+ tab.tabIndex = selected ? 0 : -1;
42
50
  panels[i]?.setAttribute("aria-hidden", String(!selected));
43
51
  }
44
- const focusTarget = focus ? labels[next] : undefined;
52
+ const focusLabel = focus ? labels[next] : undefined;
53
+ const focusTarget = focusLabel ? tabOf(focusLabel) : undefined;
45
54
  if (focusTarget && document.activeElement !== focusTarget) {
46
55
  try {
47
56
  focusTarget.focus({ preventScroll: true });
@@ -63,13 +72,14 @@ function selectedIndex(root: HTMLElement): number {
63
72
  function linkTabs(root: HTMLElement, labels: HTMLElement[], panels: HTMLElement[]): void {
64
73
  const prefix = root.id || "emvb-tabs";
65
74
  for (const [i, label] of labels.entries()) {
75
+ const tab = tabOf(label);
66
76
  const panel = panels[i];
67
77
  const panelId = panel?.id || `${prefix}-panel-${i}`;
68
78
  if (panel && !panel.id) panel.id = panelId;
69
- label.setAttribute("aria-controls", panelId);
79
+ tab.setAttribute("aria-controls", panelId);
70
80
  if (panel) {
71
- if (!label.id) label.id = `${prefix}-tab-${i}`;
72
- panel.setAttribute("aria-labelledby", label.id);
81
+ if (!tab.id) tab.id = `${prefix}-tab-${i}`;
82
+ panel.setAttribute("aria-labelledby", tab.id);
73
83
  }
74
84
  }
75
85
  }
package/src/constants.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const PLUGIN_ID = "emvb";
2
- export const PLUGIN_VERSION = "1.0.0";
2
+ export const PLUGIN_VERSION = "1.1.0";
3
3
  export const PACKAGE_NAME = "@perkyzz/emvb";
4
4
  export const ADMIN_ENTRY = `${PACKAGE_NAME}/admin`;
5
5
  export const PAGES_COLLECTION = "emvb_pages";
@@ -6,6 +6,7 @@ import { boxBecomesLink } from "../render/extras.ts";
6
6
  import { ICON_ANIMATION_LIMIT_MS, iconAnimationRuns } from "../icons/animation-runs.ts";
7
7
  import { updateNode } from "../tree-ops.ts";
8
8
  import { DEVICES } from "../theme/popup-rules.ts";
9
+ import { hiddenOnEveryDevice } from "../design/devices.ts";
9
10
 
10
11
  /**
11
12
  * W-572: text as a screen reader says it: invisible format characters (zero-width space, word
@@ -255,7 +256,7 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
255
256
  const menuNames = DEVICES.map(() => new Set<string>());
256
257
  const walk = (node: LayoutNode, bg: string | undefined, color: string | undefined): void => {
257
258
  // W-413: an element hidden on every device (and what's inside it) is never shown or read.
258
- if (node !== layout.root && DEVICES.every((d) => node.hiddenOn?.includes(d))) {
259
+ if (node !== layout.root && hiddenOnEveryDevice(node)) {
259
260
  return;
260
261
  }
261
262
  const variant = node.variant;
@@ -2,7 +2,7 @@ import { MAX_UNKNOWN_DEPTH, MAX_UNKNOWN_KEYS, UNKNOWN_KEY_PATTERN } from "./limi
2
2
  import { flattenMotion, isFlatMotionKey, withoutStrayMotionKeys } from "./migrate/v18.ts";
3
3
  import { isRecord } from "./record.ts";
4
4
  import { KNOWN_NODE_SCHEMAS } from "./schema/layout.ts";
5
- import { FlatStyleProps, StyleProps } from "./schema/style.ts";
5
+ import { FlatStyleProps, OwnStyle, StyleProps, WideStyle } from "./schema/style.ts";
6
6
 
7
7
  /**
8
8
  * D-065 (W-925, contract 1.0): a 1.x document may carry keys this version does not know, on a
@@ -30,6 +30,9 @@ for (const schema of KNOWN_NODE_SCHEMAS) {
30
30
  if (typeof type === "string") PROP_KEYS.set(type, shapeKeys(shape["props"]));
31
31
  }
32
32
  const STYLE_KEYS = shapeKeys(StyleProps);
33
+ /** W-959: an element's or class's own style also knows `wide`, whose record is open too. */
34
+ const OWN_STYLE_KEYS = shapeKeys(OwnStyle);
35
+ const WIDE_KEYS = shapeKeys(WideStyle);
33
36
  const FLAT_STYLE_KEYS = shapeKeys(FlatStyleProps);
34
37
  const STATES = ["hover", "focus", "active"] as const;
35
38
  const DEVICES = ["laptop", "tablet", "mobile"] as const;
@@ -92,7 +95,9 @@ class Splitter {
92
95
  }
93
96
 
94
97
  styleRecords(owner: Record<string, unknown>, path: Path): void {
95
- this.take(owner["style"], STYLE_KEYS, [...path, "style"]);
98
+ this.take(owner["style"], OWN_STYLE_KEYS, [...path, "style"]);
99
+ const style = owner["style"];
100
+ if (isRecord(style)) this.take(style["wide"], WIDE_KEYS, [...path, "style", "wide"]);
96
101
  const states = owner["states"];
97
102
  if (isRecord(states)) {
98
103
  // `motion` is a known key here so the schema refuses it in a state, not kept as unknown.
@@ -199,6 +204,20 @@ export function renderableStyle<T>(style: T): T {
199
204
  return inFlatOrder(known(flattenMotion(withoutStrayMotionKeys(style)), FLAT_STYLE_KEYS), style);
200
205
  }
201
206
 
207
+ /**
208
+ * W-959: the renderer reads Wide screen as one more device: `style.wide` becomes `devices.wide`
209
+ * (known keys only) and its `hidden` becomes `wideHidden`. Without `style.wide` nothing changes.
210
+ */
211
+ function wideAsDevice(owner: Record<string, unknown>, out: Record<string, unknown>): void {
212
+ const style = owner["style"];
213
+ const wide = isRecord(style) ? style["wide"] : undefined;
214
+ if (!isRecord(wide)) return;
215
+ const { hidden, ...rest } = wide;
216
+ const devices = isRecord(out["devices"]) ? out["devices"] : {};
217
+ if (Object.keys(rest).length > 0) out["devices"] = { ...devices, wide: renderableStyle(rest) };
218
+ if (typeof hidden === "boolean") out["wideHidden"] = hidden;
219
+ }
220
+
202
221
  function renderableStyles<T extends Record<string, unknown>>(owner: T): T {
203
222
  const out: Record<string, unknown> = { ...owner };
204
223
  if ("style" in owner) out["style"] = renderableStyle(owner["style"]);
@@ -217,6 +236,7 @@ function renderableStyles<T extends Record<string, unknown>>(owner: T): T {
217
236
  for (const [device, style] of Object.entries(devices)) next[device] = renderableStyle(style);
218
237
  out["devices"] = next;
219
238
  }
239
+ wideAsDevice(owner, out);
220
240
  return out as T;
221
241
  }
222
242
 
@@ -19,7 +19,7 @@ import {
19
19
  type StateDeclarations,
20
20
  } from "../sanitize/css.ts";
21
21
  import { STYLE_STATES, type StyleStateName } from "../schema/state-names.ts";
22
- import { DEVICE_MEDIA, type Device } from "../theme/popup-rules.ts";
22
+ import { DEVICE_MEDIA, type Device, type EditorDevice } from "../theme/popup-rules.ts";
23
23
  import { LOOP_KEYFRAMES, MOTION_KEYFRAMES } from "../sanitize/motion.ts";
24
24
 
25
25
  export type CssInput = {
@@ -30,6 +30,9 @@ export type CssInput = {
30
30
  id: string;
31
31
  declarations: Declaration[];
32
32
  states?: StateDeclarations;
33
+ /** W-959: Wide screen overrides (2400 px and up), and its hide override. */
34
+ wide?: Declaration[];
35
+ wideHidden?: boolean;
33
36
  /** Laptop (W-956), tablet and mobile overrides (W-096). Desktop stays in `declarations`. */
34
37
  laptop?: Declaration[];
35
38
  tablet?: Declaration[];
@@ -52,9 +55,27 @@ export type CssInput = {
52
55
  * device instead of the frame's width, so the Desktop canvas never picks up tablet styles in a
53
56
  * narrow window. Without it, the rules sit in their media queries as usual.
54
57
  */
55
- previewDevice?: Device;
58
+ previewDevice?: EditorDevice;
56
59
  };
57
60
 
61
+ /**
62
+ * W-959: a class's Wide screen overrides and hide. `renderableDesign` moved the class's
63
+ * `style.wide` to `devices.wide` and `wideHidden`; the values build on Desktop's.
64
+ */
65
+ function classWide(cls: unknown): { wide: Declaration[]; wideHidden?: boolean } {
66
+ const { style, devices, wideHidden } = cls as {
67
+ style?: unknown;
68
+ devices?: { wide?: unknown };
69
+ wideHidden?: unknown;
70
+ };
71
+ return {
72
+ wide: devices?.wide
73
+ ? styleDeclarations(withInheritedLayers(devices.wide, style ?? {})).declarations
74
+ : [],
75
+ ...(typeof wideHidden === "boolean" ? { wideHidden } : {}),
76
+ };
77
+ }
78
+
58
79
  /** Focus is keyboard focus (W-089): `:focus-visible`, never `:focus`. */
59
80
  const STATE_PSEUDO: Readonly<Record<StyleStateName, string>> = {
60
81
  hover: ":hover",
@@ -139,6 +160,22 @@ const usesLoop = (declarations: readonly Declaration[]) =>
139
160
  * local states beat class states, and Active beats Hover when both apply. Transitions sit on the
140
161
  * base rule, and one closing `prefers-reduced-motion: reduce` block turns them all off.
141
162
  */
163
+ /**
164
+ * The element base rules for these types, in the order every sheet writes them (W-971 reads
165
+ * the same order to write them once for all theme parts on a page).
166
+ */
167
+ export function baseRulesFor(
168
+ types: Iterable<string>,
169
+ baseCss: ReadonlyMap<string, string>,
170
+ ): string {
171
+ return [...types]
172
+ .toSorted((a, b) =>
173
+ cssTypeName(a) < cssTypeName(b) ? -1 : cssTypeName(a) > cssTypeName(b) ? 1 : 0,
174
+ )
175
+ .map((type) => baseCss.get(type) ?? "")
176
+ .join("");
177
+ }
178
+
142
179
  export function generateCss({
143
180
  design,
144
181
  usedTypes,
@@ -200,6 +237,7 @@ export function generateCss({
200
237
  ? [
201
238
  {
202
239
  selector: `.${className}`,
240
+ ...classWide(cls),
203
241
  // W-210: a device that sets one background layer keeps the layers it inherits.
204
242
  laptop: styleDeclarations(withInheritedLayers(cls.devices?.laptop, cls.style ?? {}))
205
243
  .declarations,
@@ -222,6 +260,8 @@ export function generateCss({
222
260
  }),
223
261
  ...localRules.map((rule) => ({
224
262
  selector: `.emvb-e-${rule.id}`,
263
+ wide: rule.wide ?? [],
264
+ wideHidden: rule.wideHidden,
225
265
  laptop: rule.laptop ?? [],
226
266
  tablet: rule.tablet ?? [],
227
267
  mobile: rule.mobile ?? [],
@@ -230,18 +270,20 @@ export function generateCss({
230
270
  })),
231
271
  ];
232
272
  /** A device block: in its media query, or, for a previewed device, on or off outright. */
233
- const forDevices = (devices: readonly Device[], query: string, body: string) => {
273
+ const forDevices = (devices: readonly EditorDevice[], query: string, body: string) => {
234
274
  if (!body) return "";
235
275
  if (previewDevice === undefined) return `@media ${query}{${body}}`;
236
276
  return devices.includes(previewDevice) ? body : "";
237
277
  };
238
- const at = (query: string, which: "laptop" | "tablet" | "mobile") =>
278
+ const at = (query: string, which: "wide" | "laptop" | "tablet" | "mobile") =>
239
279
  forDevices(
240
- which === "laptop"
241
- ? ["laptop", "tablet", "mobile"]
242
- : which === "tablet"
243
- ? ["tablet", "mobile"]
244
- : ["mobile"],
280
+ which === "wide"
281
+ ? ["wide"]
282
+ : which === "laptop"
283
+ ? ["laptop", "tablet", "mobile"]
284
+ : which === "tablet"
285
+ ? ["tablet", "mobile"]
286
+ : ["mobile"],
245
287
  query,
246
288
  responsive.map((rule) => block(rule.selector, rule[which])).join(""),
247
289
  );
@@ -249,15 +291,35 @@ export function generateCss({
249
291
  * W-956: Desktop and Laptop hidden together keep the one `min-width: 1025px` rule every page
250
292
  * saved before Laptop had; hidden on only one of them, each gets its own range.
251
293
  */
252
- const hide = (devices: readonly Device[], query: string) => {
253
- const hidden = (rule: { hiddenOn?: readonly Device[] | undefined }) => {
294
+ /**
295
+ * W-959: Wide screen follows Desktop's hide unless `wide.hidden` says otherwise. An element
296
+ * that Wide screen shows again gets a Desktop range that stops at 2399.98 px (`notWide`); one
297
+ * hidden on Wide screen only gets the Wide screen rule. Rules without `wide.hidden` keep the
298
+ * CSS they had.
299
+ */
300
+ type HideRule = { hiddenOn?: readonly Device[] | undefined; wideHidden?: boolean | undefined };
301
+ const hide = (
302
+ devices: readonly Device[],
303
+ query: string,
304
+ wide: "follows" | "notWide" | "only" = "follows",
305
+ ) => {
306
+ const hidden = (rule: HideRule) => {
254
307
  const on = rule.hiddenOn ?? [];
308
+ if (wide === "only") return rule.wideHidden === true && !on.includes("desktop");
309
+ if (devices.includes("desktop") && (rule.wideHidden === false) !== (wide === "notWide"))
310
+ return false;
255
311
  if (devices.includes("desktop") && devices.includes("laptop"))
256
312
  return on.includes("desktop") && on.includes("laptop");
257
313
  if (devices[0] === "desktop") return on.includes("desktop") && !on.includes("laptop");
258
314
  if (devices[0] === "laptop") return on.includes("laptop") && !on.includes("desktop");
259
315
  return on.includes(devices[0] as Device);
260
316
  };
317
+ const previewed: EditorDevice[] =
318
+ wide === "only"
319
+ ? ["wide"]
320
+ : wide === "follows" && devices.includes("desktop")
321
+ ? ["wide", ...devices]
322
+ : [...devices];
261
323
  // W-443: a captioned image hides its figure too, or the caption stayed on its own.
262
324
  const selectors = responsive
263
325
  .filter(hidden)
@@ -267,18 +329,18 @@ export function generateCss({
267
329
  : ["hideSelector" in rule && rule.hideSelector ? rule.hideSelector : rule.selector],
268
330
  );
269
331
  return forDevices(
270
- devices,
332
+ previewed,
271
333
  query,
272
334
  selectors.length > 0 ? `${selectors.join(",")}{display:none}` : "",
273
335
  );
274
336
  };
275
337
  for (const rule of responsive) {
276
- if (usesMotion(rule.laptop) || usesMotion(rule.tablet) || usesMotion(rule.mobile))
277
- motion = true;
278
- if (usesLoop(rule.laptop) || usesLoop(rule.tablet) || usesLoop(rule.mobile)) loops = true;
338
+ const devices = [rule.wide ?? [], rule.laptop, rule.tablet, rule.mobile];
339
+ if (devices.some(usesMotion)) motion = true;
340
+ if (devices.some(usesLoop)) loops = true;
279
341
  if (
280
342
  !entrances.includes(rule.selector) &&
281
- [...rule.laptop, ...rule.tablet, ...rule.mobile].some((d) => d.property === "animation")
343
+ devices.flat().some((d) => d.property === "animation")
282
344
  ) {
283
345
  entrances.push(rule.selector);
284
346
  }
@@ -313,11 +375,7 @@ export function generateCss({
313
375
  // W-801: a looping video kept playing for visitors who ask for reduced motion.
314
376
  "@media (prefers-reduced-motion: reduce){.emvb-bg-video{display:none}}"
315
377
  : "",
316
- ...[...usedTypes]
317
- .toSorted((a, b) =>
318
- cssTypeName(a) < cssTypeName(b) ? -1 : cssTypeName(a) > cssTypeName(b) ? 1 : 0,
319
- )
320
- .map((type) => baseCss.get(type) ?? ""),
378
+ baseRulesFor(usedTypes, baseCss),
321
379
  ...classes,
322
380
  ...locals,
323
381
  ...localRules
@@ -326,11 +384,15 @@ export function generateCss({
326
384
  (rule) =>
327
385
  `@container (min-width:${rule.queryMin}px){${block(`.emvb-e-${rule.id}`, rule.query ?? [])}}`,
328
386
  ),
387
+ at(DEVICE_MEDIA.wide, "wide"),
329
388
  at(DEVICE_MEDIA.laptop, "laptop"),
330
389
  at(DEVICE_MEDIA.tablet, "tablet"),
331
390
  at(DEVICE_MEDIA.mobile, "mobile"),
332
391
  hide(["desktop", "laptop"], DEVICE_MEDIA.hideDesktop),
333
392
  hide(["desktop"], DEVICE_MEDIA.hideDesktopOnly),
393
+ hide(["desktop", "laptop"], DEVICE_MEDIA.hideDesktopNotWide, "notWide"),
394
+ hide(["desktop"], DEVICE_MEDIA.hideDesktopOnlyNotWide, "notWide"),
395
+ hide([], DEVICE_MEDIA.wide, "only"),
334
396
  hide(["laptop"], DEVICE_MEDIA.hideLaptop),
335
397
  hide(["tablet"], DEVICE_MEDIA.hideTablet),
336
398
  hide(["mobile"], DEVICE_MEDIA.hideMobile),
@@ -61,7 +61,15 @@ const GROUPING_AT_RULE = /^@(media|supports|container|layer)\b/;
61
61
 
62
62
  /** Prefixes every style rule in `css`, inside `@media` and `@supports` too. Keyframes stay as they are. */
63
63
  export function scopeCss(css: string, token: string): string {
64
- const prefix = `:where(.${scopeClass(token)}) `;
64
+ return scopeWith(css, `:where(.${scopeClass(token)}) `);
65
+ }
66
+
67
+ /** W-971: the same, scoped to several renders at once (`:where(.emvb-s-a,.emvb-s-b) `). */
68
+ export function scopeCssAll(css: string, tokens: readonly string[]): string {
69
+ return scopeWith(css, `:where(${tokens.map((t) => `.${scopeClass(t)}`).join(",")}) `);
70
+ }
71
+
72
+ function scopeWith(css: string, prefix: string): string {
65
73
  let out = "";
66
74
  let i = 0;
67
75
  while (i < css.length) {
@@ -74,7 +82,7 @@ export function scopeCss(css: string, token: string): string {
74
82
  const end = blockEnd(css, open);
75
83
  const body = css.slice(open + 1, end - 1);
76
84
  if (GROUPING_AT_RULE.test(prelude)) {
77
- out += `${prelude}{${scopeCss(body, token)}}`;
85
+ out += `${prelude}{${scopeWith(body, prefix)}}`;
78
86
  } else if (prelude.startsWith("@")) {
79
87
  out += css.slice(i, end).trim();
80
88
  } else {
@@ -2,9 +2,9 @@ import type { DefaultStyleTag, DesignSystem } from "../schema/design.ts";
2
2
  import type { LayoutNode } from "../schema/layout.ts";
3
3
  import type { StyleStateName } from "../schema/state-names.ts";
4
4
  import { flattenMotion } from "../migrate/v18.ts";
5
- import type { FlatStyleProps, StyleProps } from "../schema/style.ts";
5
+ import type { FlatStyleProps, OwnStyle, StyleProps } from "../schema/style.ts";
6
6
 
7
- export type TraceDevice = "desktop" | "laptop" | "tablet" | "mobile";
7
+ export type TraceDevice = "wide" | "desktop" | "laptop" | "tablet" | "mobile";
8
8
 
9
9
  /** Where one style value comes from (W-318). */
10
10
  export type StyleSource = {
@@ -39,7 +39,24 @@ export function defaultTagFor(node: LayoutNode): DefaultStyleTag | undefined {
39
39
  }
40
40
  }
41
41
 
42
- const LAYER = { desktop: "Desktop", laptop: "Laptop", tablet: "Tablet", mobile: "Mobile" } as const;
42
+ const LAYER = {
43
+ wide: "Wide screen",
44
+ desktop: "Desktop",
45
+ laptop: "Laptop",
46
+ tablet: "Tablet",
47
+ mobile: "Mobile",
48
+ } as const;
49
+
50
+ /** W-959: an own style's Desktop values and its Wide screen ones (without `hidden`), apart. */
51
+ function splitWide(style: OwnStyle | undefined): { desktop?: StyleProps; wide?: StyleProps } {
52
+ if (!style) return {};
53
+ const { wide, ...desktop } = style;
54
+ const { hidden: _hidden, ...values } = wide ?? {};
55
+ return {
56
+ desktop,
57
+ ...(Object.keys(values).length > 0 ? { wide: values } : {}),
58
+ };
59
+ }
43
60
  const STATE_LABEL: Record<StyleStateName, string> = {
44
61
  hover: "Hover",
45
62
  focus: "Focus",
@@ -50,7 +67,8 @@ type Owner = {
50
67
  kind: "class" | "local";
51
68
  label: string;
52
69
  classId?: string;
53
- style?: StyleProps;
70
+ desktop?: StyleProps;
71
+ wide?: StyleProps;
54
72
  devices?: { laptop?: StyleProps; tablet?: StyleProps; mobile?: StyleProps };
55
73
  states?: Partial<Record<StyleStateName, StyleProps>>;
56
74
  };
@@ -84,7 +102,7 @@ export function styleLayers(
84
102
  kind: "class",
85
103
  label: `.${cls.name}`,
86
104
  classId: cls.id,
87
- style: cls.style,
105
+ ...splitWide(cls.style),
88
106
  };
89
107
  if (cls.devices) owner.devices = cls.devices;
90
108
  if (cls.states) owner.states = cls.states;
@@ -93,7 +111,7 @@ export function styleLayers(
93
111
  owners.push({
94
112
  kind: "local",
95
113
  label: "This element",
96
- ...(node.style ? { style: node.style } : {}),
114
+ ...(node.style ? splitWide(node.style) : {}),
97
115
  ...(node.devices ? { devices: node.devices } : {}),
98
116
  ...(node.states ? { states: node.states as Owner["states"] } : {}),
99
117
  });
@@ -103,8 +121,15 @@ export function styleLayers(
103
121
  label: owner.label,
104
122
  ...(owner.classId ? { classId: owner.classId } : {}),
105
123
  };
106
- if (owner.style) layers.push({ source: { ...base, layer: LAYER.desktop }, style: owner.style });
107
- if (device !== "desktop" && owner.devices?.laptop) {
124
+ if (owner.desktop)
125
+ layers.push({ source: { ...base, layer: LAYER.desktop }, style: owner.desktop });
126
+ if (device === "wide" && owner.wide) {
127
+ layers.push({ source: { ...base, layer: LAYER.wide }, style: owner.wide });
128
+ }
129
+ if (
130
+ (device === "laptop" || device === "tablet" || device === "mobile") &&
131
+ owner.devices?.laptop
132
+ ) {
108
133
  layers.push({ source: { ...base, layer: LAYER.laptop }, style: owner.devices.laptop });
109
134
  }
110
135
  if ((device === "tablet" || device === "mobile") && owner.devices?.tablet) {