@perkyzz/emvb 0.7.0 → 0.8.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 (71) hide show
  1. package/README.md +2 -2
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/package.json +7 -7
  4. package/src/admin/editor/DialogCloseButton.tsx +16 -0
  5. package/src/admin/editor/Editor.tsx +33 -0
  6. package/src/admin/editor/PerfMeter.tsx +3 -9
  7. package/src/admin/editor/SavedSectionDialogs.tsx +169 -0
  8. package/src/admin/editor/ShareLink.tsx +2 -7
  9. package/src/admin/editor/ShortcutsDialog.tsx +19 -11
  10. package/src/admin/editor/Timeline.tsx +2 -7
  11. package/src/admin/editor/dialogs.tsx +3 -14
  12. package/src/admin/editor/editor-chrome.tsx +8 -24
  13. package/src/admin/editor/editor-commands.ts +15 -1
  14. package/src/admin/editor/editor-css.ts +3 -2
  15. package/src/admin/editor/feature-css.ts +11 -1
  16. package/src/admin/editor/focus-when-lost.ts +23 -0
  17. package/src/admin/editor/icons/IconLibraryDialog.tsx +2 -7
  18. package/src/admin/editor/palette-items.ts +17 -0
  19. package/src/admin/editor/panels/AddPanel.tsx +9 -1
  20. package/src/admin/editor/panels/LayersPanel.tsx +6 -1
  21. package/src/admin/editor/panels/LeftPanel.tsx +9 -1
  22. package/src/admin/editor/panels/SavedSectionsGroup.tsx +246 -0
  23. package/src/admin/editor/panels/SiteStylesDrawer.tsx +54 -10
  24. package/src/admin/editor/panels/TokenScales.tsx +16 -16
  25. package/src/admin/editor/panels/TriggersEditor.tsx +1 -1
  26. package/src/admin/editor/panels/color-space.ts +14 -26
  27. package/src/admin/editor/panels/settings/AudienceEditor.tsx +36 -39
  28. package/src/admin/editor/panels/settings/IconControls.tsx +21 -5
  29. package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
  30. package/src/admin/editor/shortcuts.ts +14 -0
  31. package/src/admin/editor/useSavedSections.ts +197 -0
  32. package/src/admin/image-editor/Canvas.tsx +61 -17
  33. package/src/admin/image-editor/ImageEditorDialog.tsx +130 -1
  34. package/src/admin/image-editor/image-editor-css.ts +11 -8
  35. package/src/admin/image-editor/parts.tsx +18 -17
  36. package/src/admin/image-editor/save.ts +31 -1
  37. package/src/admin/pages/ThemePartList.tsx +32 -4
  38. package/src/admin/saved-sections-api.ts +51 -0
  39. package/src/admin/theme-api.ts +3 -2
  40. package/src/admin/ui.ts +9 -0
  41. package/src/astro/popups/runtime.ts +8 -6
  42. package/src/constants.ts +1 -1
  43. package/src/core/a11y/audit.ts +32 -7
  44. package/src/core/arrange.ts +21 -6
  45. package/src/core/css/print.ts +5 -0
  46. package/src/core/design/classes.ts +23 -9
  47. package/src/core/design/devices.ts +7 -13
  48. package/src/core/design/states.ts +7 -13
  49. package/src/core/elements/dynamic-elements.ts +11 -11
  50. package/src/core/elements/index.ts +1 -1
  51. package/src/core/elements/menu.ts +3 -0
  52. package/src/core/icons/animation-runs.ts +11 -0
  53. package/src/core/index.ts +20 -0
  54. package/src/core/migrate/index.ts +3 -0
  55. package/src/core/render/loop.ts +1 -1
  56. package/src/core/sanitize/css.ts +14 -6
  57. package/src/core/saved-sections.ts +318 -0
  58. package/src/core/schema/design.ts +1 -1
  59. package/src/core/schema/layout.ts +1 -1
  60. package/src/core/schema/style.ts +4 -2
  61. package/src/core/theme/float.ts +3 -0
  62. package/src/core/theme/pagination.ts +25 -24
  63. package/src/core/theme/part-types.ts +4 -4
  64. package/src/mcp/ports.ts +22 -1
  65. package/src/mcp/read.ts +1 -1
  66. package/src/mcp/sections.ts +183 -0
  67. package/src/mcp/tools.ts +44 -0
  68. package/src/mcp/write.ts +4 -4
  69. package/src/server/mcp-routes.ts +2 -0
  70. package/src/server/plugin.ts +14 -0
  71. package/src/server/saved-sections.ts +163 -0
@@ -14,6 +14,8 @@ import {
14
14
  ArrowCounterClockwiseIcon,
15
15
  DotsThreeIcon,
16
16
  DownloadSimpleIcon,
17
+ FileArrowUpIcon,
18
+ ScrollIcon,
17
19
  WarningCircleIcon,
18
20
  XIcon,
19
21
  } from "@phosphor-icons/react";
@@ -45,7 +47,16 @@ import {
45
47
  ToolSwitcher,
46
48
  UndoButton,
47
49
  } from "./parts.tsx";
48
- import { buildImageEdit, editedFileName, hasGps, outputFile, savedRecipe } from "./save.ts";
50
+ import {
51
+ buildImageEdit,
52
+ editedFileName,
53
+ hasGps,
54
+ outputFile,
55
+ parseRecipeFile,
56
+ RECIPE_FILE_MAX_BYTES,
57
+ recipeFileText,
58
+ savedRecipe,
59
+ } from "./save.ts";
49
60
  import { displayName, elementAspectOption, sizeLabel, type ImageEditorToolId } from "./tools.ts";
50
61
  import type { RenderMode } from "./worker.ts";
51
62
  import type { ImageEdit } from "../../core/index.ts";
@@ -115,6 +126,119 @@ function useWidth(ref: React.RefObject<HTMLElement | null>) {
115
126
  return width;
116
127
  }
117
128
 
129
+ /** W-862 (IE-2): download the current edits as a recipe file, or load one onto this picture. */
130
+ function useRecipeFile(name: string) {
131
+ const editor = useImageEditor();
132
+ const fileRef = React.useRef<HTMLInputElement>(null);
133
+ const [error, setError] = React.useState<string | null>(null);
134
+ const current = editor.recipes.current;
135
+ const download = () => {
136
+ if (!current) return;
137
+ const url = URL.createObjectURL(
138
+ new Blob([recipeFileText(current as Parameters<typeof recipeFileText>[0])], {
139
+ type: "application/json",
140
+ }),
141
+ );
142
+ const a = document.createElement("a");
143
+ a.href = url;
144
+ a.download = `${name.replace(/\.[^.]+$/, "") || "image"}.recipe.json`;
145
+ a.click();
146
+ setTimeout(() => URL.revokeObjectURL(url), 0);
147
+ };
148
+ const load = async (file: File | undefined) => {
149
+ if (!file) return;
150
+ // W-881: a huge file picked by mistake isn't read into memory, and a failed apply says so.
151
+ if (file.size > RECIPE_FILE_MAX_BYTES) {
152
+ setError("This file is too large to be an image edit recipe.");
153
+ return;
154
+ }
155
+ try {
156
+ const result = parseRecipeFile(await file.text());
157
+ if (!result.ok) {
158
+ setError(result.error);
159
+ return;
160
+ }
161
+ setError(null);
162
+ await editor.recipes.apply(result.recipe as Parameters<typeof editor.recipes.apply>[0]);
163
+ } catch {
164
+ setError("This recipe couldn't be applied to this picture.");
165
+ }
166
+ };
167
+ const pick = () => fileRef.current?.click();
168
+ // W-884: the phone layout's More menu offers the same two items, so both layouts render these.
169
+ const errorNote = error ? (
170
+ <span className="emvb-ie-recipe-error" role="alert" data-emvb-image-recipe-error="">
171
+ <WarningCircleIcon aria-hidden="true" />
172
+ {error}
173
+ </span>
174
+ ) : null;
175
+ const fileInput = (
176
+ <input
177
+ ref={fileRef}
178
+ type="file"
179
+ accept="application/json,.json"
180
+ hidden
181
+ aria-label="Load recipe file"
182
+ data-emvb-image-recipe-file=""
183
+ onChange={(event) => {
184
+ const input = event.currentTarget;
185
+ void load(input.files?.[0]).finally(() => {
186
+ input.value = "";
187
+ });
188
+ }}
189
+ />
190
+ );
191
+ return { current, download, pick, errorNote, fileInput };
192
+ }
193
+
194
+ function RecipeMenu({ name }: { name: string }) {
195
+ const editor = useImageEditor();
196
+ const recipe = useRecipeFile(name);
197
+ return (
198
+ <>
199
+ {recipe.errorNote}
200
+ <DropdownMenu>
201
+ <DropdownMenu.Trigger
202
+ render={
203
+ <Button
204
+ type="button"
205
+ variant="outline"
206
+ size="sm"
207
+ className="emvb-ie-btn"
208
+ icon={<ScrollIcon aria-hidden="true" />}
209
+ disabled={editor.disabled || !editor.hasImage}
210
+ data-emvb-image-recipe=""
211
+ >
212
+ Recipe
213
+ </Button>
214
+ }
215
+ />
216
+ <DropdownMenu.Content align="end">
217
+ <RecipeItems recipe={recipe} />
218
+ </DropdownMenu.Content>
219
+ </DropdownMenu>
220
+ {recipe.fileInput}
221
+ </>
222
+ );
223
+ }
224
+
225
+ function RecipeItems({ recipe }: { recipe: ReturnType<typeof useRecipeFile> }) {
226
+ return (
227
+ <>
228
+ <DropdownMenu.Item
229
+ icon={DownloadSimpleIcon}
230
+ disabled={!recipe.current}
231
+ onClick={recipe.download}
232
+ >
233
+ Download recipe
234
+ </DropdownMenu.Item>
235
+ <DropdownMenu.Item icon={FileArrowUpIcon} onClick={recipe.pick}>
236
+ Load recipe…
237
+ </DropdownMenu.Item>
238
+ </>
239
+ );
240
+ }
241
+
118
242
  function SaveCopyButton() {
119
243
  const save = React.useContext(SaveContext);
120
244
  const editor = useImageEditor();
@@ -237,6 +361,7 @@ function DesktopLayout({ ready, name }: { ready: Ready; name: string }) {
237
361
  </span>
238
362
  ) : null}
239
363
  <div className="emvb-ie-toolbar-end">
364
+ <RecipeMenu name={name} />
240
365
  <ResetAllButton />
241
366
  <CompareButton />
242
367
  <CancelButton />
@@ -402,6 +527,7 @@ function PanelSheet({
402
527
 
403
528
  function CompactLayout({ name }: { name: string }) {
404
529
  const editor = useImageEditor();
530
+ const recipe = useRecipeFile(name);
405
531
  const rootRef = React.useRef<HTMLDivElement | null>(null);
406
532
  const [rootHeight, setRootHeight] = React.useState<number | null>(null);
407
533
  React.useLayoutEffect(() => {
@@ -468,11 +594,14 @@ function CompactLayout({ name }: { name: string }) {
468
594
  >
469
595
  Reset all edits
470
596
  </DropdownMenu.Item>
597
+ <RecipeItems recipe={recipe} />
471
598
  </DropdownMenu.Content>
472
599
  </DropdownMenu>
600
+ {recipe.fileInput}
473
601
  <CancelButton compact />
474
602
  </div>
475
603
  </header>
604
+ {recipe.errorNote ? <div className="emvb-ie-compact-note">{recipe.errorNote}</div> : null}
476
605
  <div className="emvb-ie-compact-canvas" style={{ paddingBottom: inset }}>
477
606
  <EditorCanvas alt={name} padding={12} />
478
607
  </div>
@@ -71,7 +71,6 @@ export const IMAGE_EDITOR_CSS = `
71
71
  flex: 1 1 0; min-width: 0; max-width: 40px; height: 32px; display: grid; place-items: center;
72
72
  border: 1px solid var(--color-kumo-line); border-radius: 8px; background: var(--color-kumo-base);
73
73
  color: var(--text-color-kumo-default); cursor: pointer; padding: 0;
74
- transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
75
74
  }
76
75
  .emvb-ie-switch svg { width: 16px; height: 16px; transition: transform 120ms ease; }
77
76
  .emvb-ie-switch:hover { background: var(--color-kumo-tint); }
@@ -89,9 +88,9 @@ export const IMAGE_EDITOR_CSS = `
89
88
  }
90
89
  .emvb-ie-histogram-head {
91
90
  display: flex; justify-content: space-between; font-size: 10px; line-height: 14px;
92
- text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-color-kumo-subtle);
91
+ color: var(--text-color-kumo-subtle);
93
92
  }
94
- .emvb-ie-mono { font-family: var(--font-mono, ui-monospace, monospace); text-transform: none; letter-spacing: 0; font-variant-numeric: tabular-nums; }
93
+ .emvb-ie-mono { font-family: var(--font-mono, ui-monospace, monospace); font-variant-numeric: tabular-nums; }
95
94
  .emvb-ie-histogram canvas { display: block; width: 100%; height: 64px; border-radius: 4px; background: var(--color-kumo-base); }
96
95
 
97
96
  /* Panels (photocn panel-header.tsx, crop-panel.tsx). */
@@ -189,7 +188,9 @@ export const IMAGE_EDITOR_CSS = `
189
188
  border-top-color: var(--text-color-kumo-default); animation: emvb-ie-spin 0.9s linear infinite;
190
189
  }
191
190
  @keyframes emvb-ie-spin { to { transform: rotate(360deg); } }
192
- .emvb-ie .emvb-ie-fit { position: absolute; right: 8px; bottom: 8px; }
191
+ .emvb-ie .emvb-ie-compact-note { padding: 4px 12px; }
192
+ .emvb-ie .emvb-ie-recipe-error { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--color-kumo-danger); }
193
+ .emvb-ie .emvb-ie-zoom { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: var(--color-kumo-base); box-shadow: 0 1px 3px var(--color-kumo-shadow-drop, rgb(0 0 0 / 0.15)); }
193
194
  .emvb-ie-error {
194
195
  display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 420px; margin: 24px;
195
196
  padding: 20px 24px; border-radius: 12px; text-align: center;
@@ -258,10 +259,10 @@ export const IMAGE_EDITOR_CSS = `
258
259
  display: flex; flex: none; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
259
260
  min-width: 56px; min-height: 44px; padding: 0 8px; border: 0; border-radius: 10px; background: none;
260
261
  color: var(--text-color-kumo-subtle); font-size: 11px; line-height: 14px; cursor: pointer;
261
- transition: background-color 120ms ease, color 120ms ease;
262
262
  }
263
263
  .emvb-ie-compact-tool svg { width: 20px; height: 20px; }
264
- .emvb-ie-compact-tool[aria-pressed="true"] { background: var(--color-kumo-brand); color: #fff; }
264
+ .emvb-ie-compact-tool[aria-pressed="true"] { background: var(--color-kumo-brand); color: #fff; box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.2); }
265
+ .emvb-ie-compact-tool[aria-pressed="true"] svg { transform: scale(1.1); }
265
266
  .emvb-ie-compact-tool:focus-visible { outline: 2px solid var(--color-kumo-focus, var(--color-kumo-brand)); }
266
267
  .emvb-ie-compact-tool:disabled { opacity: 0.5; }
267
268
  .emvb-ie-sheet {
@@ -280,7 +281,9 @@ export const IMAGE_EDITOR_CSS = `
280
281
  .emvb-ie-sheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: env(safe-area-inset-bottom); }
281
282
  /* Tone panels (W-484; photocn adjustments-panel, filters-panel, curves-panel, blur-panel). */
282
283
  .emvb-ie-tabs-wrap { padding: 12px 16px; }
283
- .emvb-ie-tabs [role="tablist"] { width: 100%; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
284
+ /* W-872: Kumo's small tab list has a fixed 26px height, but an icon-and-text tab is taller, so the
285
+ underline (bottom: 0 of the list) cut through the label. The list now grows to its tabs. */
286
+ .emvb-ie-tabs [role="tablist"] { width: 100%; height: auto; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
284
287
  .emvb-ie-tabs [role="tab"] { justify-content: center; font-size: 13px; }
285
288
  .emvb-ie-tab-label { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
286
289
  .emvb-ie-tab-label svg { width: 16px; height: 16px; }
@@ -303,7 +306,7 @@ export const IMAGE_EDITOR_CSS = `
303
306
  .emvb-ie .emvb-ie-chip[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--color-kumo-line); }
304
307
  .emvb-ie-spin { animation: emvb-ie-spin 0.9s linear infinite; }
305
308
  .emvb-ie-subgroup { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; border: 0; min-width: 0; }
306
- .emvb-ie-caps { padding: 0; margin-bottom: 0; font-size: 12px; line-height: 16px; font-weight: 600; text-transform: uppercase; color: var(--text-color-kumo-subtle); }
309
+ .emvb-ie-caps { padding: 0; margin-bottom: 0; font-size: 12px; line-height: 16px; font-weight: 600; color: var(--text-color-kumo-subtle); }
307
310
  .emvb-ie-group-curves { gap: 12px; }
308
311
  .emvb-ie-curves { display: flex; flex-direction: column; align-items: center; gap: 8px; }
309
312
  .emvb-ie-curves-box {
@@ -236,24 +236,25 @@ export function ToolSwitcher() {
236
236
  {IMAGE_EDITOR_TOOLS.map((tool, i) => {
237
237
  const ToolIcon = TOOL_ICONS[tool.id];
238
238
  const active = tool.id === editor.tool;
239
+ // W-860 (IE-3): a Kumo tooltip names each tool, as photocn's ToggleGroup does.
239
240
  return (
240
- <button
241
- key={tool.id}
242
- ref={(el) => {
243
- buttons.current[i] = el;
244
- }}
245
- type="button"
246
- className="emvb-ie-switch"
247
- aria-label={tool.label}
248
- aria-pressed={active}
249
- title={tool.label}
250
- tabIndex={active || (index < 0 && i === 0) ? 0 : -1}
251
- disabled={disabled}
252
- data-emvb-image-tool={tool.id}
253
- onClick={() => editor.setTool(tool.id)}
254
- >
255
- <ToolIcon aria-hidden="true" weight={active ? "bold" : "regular"} />
256
- </button>
241
+ <Tooltip key={tool.id} content={tool.label} side="bottom" asChild>
242
+ <button
243
+ ref={(el) => {
244
+ buttons.current[i] = el;
245
+ }}
246
+ type="button"
247
+ className="emvb-ie-switch"
248
+ aria-label={tool.label}
249
+ aria-pressed={active}
250
+ tabIndex={active || (index < 0 && i === 0) ? 0 : -1}
251
+ disabled={disabled}
252
+ data-emvb-image-tool={tool.id}
253
+ onClick={() => editor.setTool(tool.id)}
254
+ >
255
+ <ToolIcon aria-hidden="true" weight={active ? "bold" : "regular"} />
256
+ </button>
257
+ </Tooltip>
257
258
  );
258
259
  })}
259
260
  </div>
@@ -2,7 +2,7 @@
2
2
  * Saving an edited picture (W-485): export settings, the output file and the `edit` record.
3
3
  * No photocn import here, so this stays testable without WebGL.
4
4
  */
5
- import { ImageEdit, type ImageEditRecipe } from "../../core/index.ts";
5
+ import { IMAGE_EDIT_RECIPE_MAX_BYTES, ImageEdit, ImageEditRecipe } from "../../core/index.ts";
6
6
  import type { ImageEditOutput } from "../../core/image-edit/schema.ts";
7
7
  import { stripJpegGps } from "./exif.ts";
8
8
 
@@ -139,3 +139,33 @@ export function savedRecipe(imageProps: Record<string, unknown>): ImageEditRecip
139
139
  const { recipe } = parsed.data;
140
140
  return Object.keys(recipe).some((k) => k !== "version" && k !== "name") ? recipe : null;
141
141
  }
142
+
143
+ /** W-862 (IE-2): the edit recipe as a JSON file, as photocn's recipe export. */
144
+ export function recipeFileText(recipe: ImageEditRecipe): string {
145
+ return `${JSON.stringify({ emvbImageRecipe: 1, photocn: PHOTOCN_VERSION, recipe }, null, 2)}\n`;
146
+ }
147
+
148
+ /** A recipe file larger than this isn't read at all (W-881). */
149
+ export const RECIPE_FILE_MAX_BYTES = IMAGE_EDIT_RECIPE_MAX_BYTES * 4;
150
+
151
+ export type RecipeFileResult = { ok: true; recipe: ImageEditRecipe } | { ok: false; error: string };
152
+
153
+ /** Reads a recipe file (ours, or a bare photocn recipe) and checks it like a saved edit. */
154
+ export function parseRecipeFile(text: string): RecipeFileResult {
155
+ const bad = { ok: false, error: "This file isn't an image edit recipe." } as const;
156
+ if (text.length > RECIPE_FILE_MAX_BYTES) return bad;
157
+ let raw: unknown;
158
+ try {
159
+ raw = JSON.parse(text);
160
+ } catch {
161
+ return bad;
162
+ }
163
+ const inner =
164
+ raw && typeof raw === "object" && "recipe" in raw ? (raw as { recipe: unknown }).recipe : raw;
165
+ const parsed = ImageEditRecipe.safeParse(inner);
166
+ if (!parsed.success) return bad;
167
+ if (new TextEncoder().encode(JSON.stringify(parsed.data)).length > IMAGE_EDIT_RECIPE_MAX_BYTES) {
168
+ return { ok: false, error: "This recipe is too large." };
169
+ }
170
+ return { ok: true, recipe: parsed.data };
171
+ }
@@ -29,11 +29,11 @@ const FILTERS: { value: Filter; label: string }[] = [
29
29
  { value: "header", label: "Headers" },
30
30
  { value: "footer", label: "Footers" },
31
31
  { value: "error_404", label: "Error 404" },
32
- { value: "search_results", label: "Search Results" },
33
- { value: "single_page", label: "Single Page" },
34
- { value: "single_post", label: "Single Post" },
32
+ { value: "search_results", label: "Search results" },
33
+ { value: "single_page", label: "Single page" },
34
+ { value: "single_post", label: "Single post" },
35
35
  { value: "archive", label: "Archive" },
36
- { value: "loop_item", label: "Loop Item" },
36
+ { value: "loop_item", label: "Loop item" },
37
37
  { value: "section", label: "Sections" },
38
38
  { value: "page_template", label: "Page templates" },
39
39
  { value: "popup", label: "Popups" },
@@ -80,8 +80,10 @@ function FilterTabs({
80
80
  refs.current.get(next)?.focus();
81
81
  };
82
82
 
83
+ const rowRef = useEdgeHints<HTMLDivElement>();
83
84
  return (
84
85
  <div
86
+ ref={rowRef}
85
87
  className="emvb-theme-filters"
86
88
  role="tablist"
87
89
  aria-label="Filter by type"
@@ -239,3 +241,29 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
239
241
  </>
240
242
  );
241
243
  }
244
+
245
+ /**
246
+ * W-863: marks which edges of a scrolling row hide more tabs (data-more-start / data-more-end),
247
+ * so browsers without scroll-driven animations still get the UX-038 edge fade.
248
+ */
249
+ export function useEdgeHints<T extends HTMLElement>() {
250
+ const ref = React.useRef<T>(null);
251
+ React.useEffect(() => {
252
+ const node = ref.current;
253
+ if (!node) return;
254
+ const update = () => {
255
+ const max = node.scrollWidth - node.clientWidth;
256
+ node.toggleAttribute("data-more-start", max > 1 && node.scrollLeft > 1);
257
+ node.toggleAttribute("data-more-end", max > 1 && node.scrollLeft < max - 1);
258
+ };
259
+ update();
260
+ node.addEventListener("scroll", update, { passive: true });
261
+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(update);
262
+ observer?.observe(node);
263
+ return () => {
264
+ node.removeEventListener("scroll", update);
265
+ observer?.disconnect();
266
+ };
267
+ }, []);
268
+ return ref;
269
+ }
@@ -0,0 +1,51 @@
1
+ import { PLUGIN_ID } from "../constants.ts";
2
+ import type { SavedSection, SavedSectionRecord, SavedSectionSummary } from "../core/index.ts";
3
+ import { requestJson, type Fetcher } from "./api.ts";
4
+
5
+ export type { SavedSectionSummary };
6
+
7
+ const BASE = `/_emdash/api/plugins/${PLUGIN_ID}/saved-sections`;
8
+
9
+ /** My sections, newest first (W-876). */
10
+ export async function listSavedSections(fetcher: Fetcher): Promise<SavedSectionSummary[]> {
11
+ const data = await requestJson<{ items?: SavedSectionSummary[] }>(fetcher, BASE);
12
+ return data?.items ?? [];
13
+ }
14
+
15
+ /** One section, read and upgraded by the server. */
16
+ export async function getSavedSection(fetcher: Fetcher, id: string): Promise<SavedSection> {
17
+ const data = await requestJson<{ section: SavedSection }>(fetcher, `${BASE}/get`, {
18
+ method: "POST",
19
+ body: { id },
20
+ });
21
+ return data.section;
22
+ }
23
+
24
+ /** Stores a snapshot; the server checks it again whatever the browser sent. */
25
+ export async function saveSavedSection(
26
+ fetcher: Fetcher,
27
+ record: SavedSectionRecord,
28
+ ): Promise<string> {
29
+ const data = await requestJson<{ id: string }>(fetcher, `${BASE}/save`, {
30
+ method: "POST",
31
+ body: { record },
32
+ });
33
+ return data.id;
34
+ }
35
+
36
+ export async function renameSavedSection(
37
+ fetcher: Fetcher,
38
+ id: string,
39
+ name: string,
40
+ ): Promise<SavedSectionSummary> {
41
+ const data = await requestJson<{ item: SavedSectionSummary }>(fetcher, `${BASE}/rename`, {
42
+ method: "POST",
43
+ body: { id, name },
44
+ });
45
+ return data.item;
46
+ }
47
+
48
+ /** Pages that already hold a copy keep it. */
49
+ export async function deleteSavedSection(fetcher: Fetcher, id: string): Promise<void> {
50
+ await requestJson(fetcher, `${BASE}/delete`, { method: "POST", body: { id } });
51
+ }
@@ -158,14 +158,15 @@ function starterPartLayout(title: string, partType: ThemePartType): Layout {
158
158
 
159
159
  export async function createThemePart(
160
160
  fetcher: Fetcher,
161
- input: { title: string; slug: string; partType: ThemePartType },
161
+ input: { title: string; slug: string; partType: ThemePartType; layout?: Layout },
162
162
  ): Promise<string> {
163
163
  const body = await requestJson<{ item: ContentItem }>(fetcher, CONTENT, {
164
164
  method: "POST",
165
165
  body: {
166
166
  data: {
167
167
  title: input.title,
168
- layout: starterPartLayout(input.title, input.partType),
168
+ // W-876: a synced section starts from the element it was made from.
169
+ layout: input.layout ?? starterPartLayout(input.title, input.partType),
169
170
  part_type: input.partType,
170
171
  conditions: defaultConditionsFor(input.partType),
171
172
  triggers: defaultTriggers(),
package/src/admin/ui.ts CHANGED
@@ -213,6 +213,15 @@ export const UI_CSS = `
213
213
  mask-image: linear-gradient(to right, transparent, #000 var(--emvb-fade-start), #000 calc(100% - var(--emvb-fade-end)), transparent);
214
214
  }
215
215
  }
216
+ /* W-863: without scroll timelines (Firefox, older Safari) the row's data-more-* hints fade it. */
217
+ @supports not (animation-timeline: scroll()) {
218
+ .emvb-theme-filters[data-more-start] { --emvb-fade-start: 32px; }
219
+ .emvb-theme-filters[data-more-end] { --emvb-fade-end: 32px; }
220
+ .emvb-theme-filters[data-more-start],
221
+ .emvb-theme-filters[data-more-end] {
222
+ mask-image: linear-gradient(to right, transparent, #000 var(--emvb-fade-start), #000 calc(100% - var(--emvb-fade-end)), transparent);
223
+ }
224
+ }
216
225
 
217
226
  /* EmVB-owned dialog body (Kumo Dialog keeps host radius/shadow) */
218
227
  .emvb-dialog { display: flex; flex-direction: column; gap: 10px; }
@@ -81,10 +81,11 @@ function isValidSelector(selector: string): boolean {
81
81
  }
82
82
  }
83
83
 
84
- function canOpen(config: PopupConfig): boolean {
84
+ /** W-846 (D-055): a click is the visitor asking, so "Show at most" neither stops nor counts it. */
85
+ function canOpen(config: PopupConfig, byClick: boolean): boolean {
85
86
  const advanced = config.triggers.advanced;
86
87
  if (!matchesPopupDevices(advanced, window.innerWidth)) return false;
87
- if (!withinShowTimes(advanced, timesShown(config.id))) return false;
88
+ if (!byClick && !withinShowTimes(advanced, timesShown(config.id))) return false;
88
89
  return true;
89
90
  }
90
91
 
@@ -240,10 +241,10 @@ function bindA11y(ctrl: Controller): void {
240
241
  }
241
242
 
242
243
  /** Opens a closed popup and counts the show; a trigger while it's open does neither (W-092). */
243
- function openOnce(ctrl: Controller, config: PopupConfig): void {
244
- if (ctrl.opened || !canOpen(config)) return;
244
+ function openOnce(ctrl: Controller, config: PopupConfig, byClick: boolean): void {
245
+ if (ctrl.opened || !canOpen(config, byClick)) return;
245
246
  ctrl.open();
246
- bumpTimesShown(config.id);
247
+ if (!byClick) bumpTimesShown(config.id);
247
248
  }
248
249
 
249
250
  const IDLE_EVENTS = ["mousemove", "mousedown", "keydown", "touchstart", "scroll"] as const;
@@ -314,7 +315,8 @@ const ARM: { [T in OpenTrigger["type"]]: Arm<T> } = {
314
315
 
315
316
  function registerTrigger(ctrl: Controller, config: PopupConfig, trigger: OpenTrigger): void {
316
317
  const arm = (ARM as Record<string, Arm<OpenTrigger["type"]> | undefined>)[trigger.type];
317
- arm?.(() => openOnce(ctrl, config), trigger as never);
318
+ const byClick = trigger.type === "click";
319
+ arm?.(() => openOnce(ctrl, config, byClick), trigger as never);
318
320
  }
319
321
 
320
322
  /**
package/src/constants.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const PLUGIN_ID = "emvb";
2
- export const PLUGIN_VERSION = "0.7.0";
2
+ export const PLUGIN_VERSION = "0.8.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";
@@ -2,6 +2,7 @@ import { clipText } from "../limits.ts";
2
2
  import type { DesignSystem } from "../schema/design.ts";
3
3
  import { isParentNode, type Layout, type LayoutNode } from "../schema/layout.ts";
4
4
  import { boxBecomesLink } from "../render/extras.ts";
5
+ import { ICON_ANIMATION_LIMIT_MS, iconAnimationRuns } from "../icons/animation-runs.ts";
5
6
  import { updateNode } from "../tree-ops.ts";
6
7
 
7
8
  /**
@@ -169,6 +170,22 @@ function effectiveStyle(
169
170
  return { ...fromClasses, ...(node.style as Record<string, unknown> | undefined) };
170
171
  }
171
172
 
173
+ /** Each device's style with the node's classes under the node's own (W-882). */
174
+ function deviceStyles(node: LayoutNode, design: DesignSystem): Record<string, unknown>[] {
175
+ const ids = new Set(node.classes ?? []);
176
+ const merged: Record<string, Record<string, unknown>> = {};
177
+ const layers = [
178
+ ...(design.classes ?? []).filter((c) => ids.has(c.id)).map((c) => c.devices),
179
+ node.devices,
180
+ ];
181
+ for (const devices of layers) {
182
+ for (const [key, st] of Object.entries(devices ?? {})) {
183
+ merged[key] = { ...merged[key], ...(st as Record<string, unknown>) };
184
+ }
185
+ }
186
+ return Object.values(merged);
187
+ }
188
+
172
189
  /** Large text (24 px, or 18.66 px bold) needs 3:1; other text 4.5:1. H4 to H6 are not large (W-639). */
173
190
  function largeText(node: LayoutNode, design: DesignSystem): boolean {
174
191
  const style = effectiveStyle(node, design) as
@@ -308,19 +325,27 @@ export function auditPage(layout: Layout, design: DesignSystem): A11yReport {
308
325
  fixLabel: "Mark as decorative",
309
326
  });
310
327
  }
311
- // W-791: a spin or pulse loops forever; reduced-motion visitors are spared, but everyone
312
- // else gets motion they can't pause (WCAG 2.2.2) unless it is essential, like a spinner.
313
- const looping = [node.style, ...Object.values(node.devices ?? {})].some((st) => {
314
- const anim = (st as { iconAnimation?: { type?: unknown } } | undefined)?.iconAnimation;
315
- return anim?.type === "spin" || anim?.type === "pulse";
328
+ // W-791: motion visitors can't pause breaks WCAG 2.2.2 past 5 seconds, unless it is essential.
329
+ // W-848: a spin or pulse now stops by itself after about 5 s, so only one whose single run
330
+ // (a pulse's there and back) is longer than that is still flagged.
331
+ // W-882: an animation from a class counts too, and the element's own style wins over it.
332
+ const tooLong = [effectiveStyle(node, design), ...deviceStyles(node, design)].some((st) => {
333
+ const anim = (
334
+ st as { iconAnimation?: { type?: unknown; duration?: unknown; loop?: unknown } } | undefined
335
+ )?.iconAnimation;
336
+ if (anim?.type !== "spin" && anim?.type !== "pulse") return false;
337
+ // W-853: Loop forever is motion without end, so it is flagged like before W-848.
338
+ if (anim.loop === true) return true;
339
+ const ms = typeof anim.duration === "number" ? anim.duration : 0;
340
+ return iconAnimationRuns(anim.type, ms) * ms > ICON_ANIMATION_LIMIT_MS;
316
341
  });
317
- if (looping) {
342
+ if (tooLong) {
318
343
  add({
319
344
  nodeId: node.id,
320
345
  rule: "motion",
321
346
  severity: "warning",
322
347
  message:
323
- "This icon animates without end and visitors can't pause it. Keep it only if the motion is essential, such as a loading spinner.",
348
+ "This icon animates for more than 5 seconds and visitors can't pause it. Shorten the duration, or keep it only if the motion is essential.",
324
349
  });
325
350
  }
326
351
  // W-403: with extra sizes but no Width, the main image is left out of srcset, so wide screens
@@ -319,16 +319,31 @@ export function wrapNode(
319
319
  type: WrapType,
320
320
  random: () => number = Math.random,
321
321
  ): Arranged {
322
+ return wrapWith(layout, id, {
323
+ id: newNodeId(random),
324
+ type,
325
+ props: type === "grid" ? { columns: 2 } : {},
326
+ } as LayoutNode);
327
+ }
328
+
329
+ /**
330
+ * W-876: puts `id` inside a Theme section that embeds the Section theme part `partId`. The element
331
+ * stays as the Theme section's own content, so the page looks the same until the part is published.
332
+ */
333
+ export const wrapInThemeSection = (
334
+ layout: Layout,
335
+ id: string,
336
+ partId: string,
337
+ random: () => number = Math.random,
338
+ ): Arranged =>
339
+ wrapWith(layout, id, { id: newNodeId(random), type: "section", props: { partId } } as LayoutNode);
340
+
341
+ function wrapWith(layout: Layout, id: string, shell: LayoutNode): Arranged {
322
342
  const found = locate(layout, id);
323
343
  if (!found) return refuse(REASONS.missing);
324
344
  if (!found.parent) return refuse(REASONS.rootFixed);
325
345
  if (size(layout.root) + 1 > MAX_NODES) return refuse(REASONS.tooMany);
326
- const wrapper: LayoutNode = {
327
- id: newNodeId(random),
328
- type,
329
- props: type === "grid" ? { columns: 2 } : {},
330
- children: [found.node],
331
- } as LayoutNode;
346
+ const wrapper = { ...shell, children: [found.node] } as LayoutNode;
332
347
  // W-389: the same parent/child rules as a drop, so an accordion item, tab panel or menu item
333
348
  // isn't wrapped into a page that can't save, and the extra level stays within the depth cap.
334
349
  const inForm = underForm(layout, found.parent.id);
@@ -2,11 +2,16 @@
2
2
  * Print stylesheet (W-335). Chrome that only makes sense on screen is hidden.
3
3
  * Appended after scoped page CSS so the selectors stay global: a header, float or popup
4
4
  * is not inside the page's scope wrapper.
5
+ * W-845 (D-054): every tab panel and accordion panel prints, not just the open one. The tab rule
6
+ * matches the specificity of the screen rule that hides the other panels and comes later. A
7
+ * closed <details> opens through ::details-content, so a browser without it prints the summary.
5
8
  */
6
9
  export function printCss(): string {
7
10
  return (
8
11
  "@media print{" +
9
12
  ".emvb-theme-header,.emvb-theme-footer,.emvb-float,.emvb-popup{display:none!important}" +
13
+ ".emvb-tabs:has(> .emvb-tab-input:nth-of-type(n):checked) > .emvb-tab-panels > .emvb-tab-panel:nth-of-type(n){display:block!important}" +
14
+ ".emvb-accordion-item::details-content{content-visibility:visible;display:block}" +
10
15
  "}"
11
16
  );
12
17
  }