@markdy/renderer-dom 1.4.15 → 1.4.17

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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { EdgeKind, RenderPlan, BeatRange, ThemeTokens, PlayerControlsConfig, Diagnostic, PositionedNode, DiagramAST } from '@markdy/core';
1
+ import { EdgeKind, RenderPlan, BeatRange, ThemeTokens, DefaultThemesConfig, PlayerControlsConfig, Diagnostic, PositionedNode, DiagramAST } from '@markdy/core';
2
+ export { DefaultThemesConfig } from '@markdy/core';
2
3
 
3
4
  /**
4
5
  * Pure 2-D geometry helpers for node bounds, hit-testing, and orthogonal
@@ -131,6 +132,15 @@ interface DiagramOptions {
131
132
  autoplay?: boolean;
132
133
  loop?: boolean;
133
134
  copyright?: boolean;
135
+ /**
136
+ * Configurable default themes for light and dark modes when the script theme is auto or undeclared.
137
+ * e.g. { light: "doodle", dark: "nebula" }
138
+ */
139
+ defaultThemes?: DefaultThemesConfig;
140
+ /** Custom default light theme for auto mode (e.g. "doodle", "paper"). */
141
+ defaultLightTheme?: string;
142
+ /** Custom default dark theme for auto mode (e.g. "nebula", "midnight"). */
143
+ defaultDarkTheme?: string;
134
144
  /**
135
145
  * Maps node `image=`/`logo=` values to resolved URLs. Lets a host (Astro,
136
146
  * MDX) remap DSL asset references to CDN/data URLs. Values not present here
@@ -221,13 +231,21 @@ interface Diagram {
221
231
  syncFullscreen(isFull?: boolean): void;
222
232
  destroy(): void;
223
233
  }
234
+ /**
235
+ * Resolves default light and dark themes from diagram options, container data attributes,
236
+ * document-level attributes, global window defaults, or fallback to "paper" and "nebula".
237
+ */
238
+ declare function resolveDefaultThemes(container?: HTMLElement, customDefaults?: DefaultThemesConfig): {
239
+ light: string;
240
+ dark: string;
241
+ };
224
242
  /**
225
243
  * Detects the host environment's theme mode (dark vs light).
226
244
  * Universal support for Tailwind, Next.js, Starlight, Docusaurus, Bootstrap 5.3,
227
245
  * GitHub Markdown, VS Code webviews, computed background lightness, and OS color schemes.
228
- * Default light mode is "paper", default dark mode is "nebula".
246
+ * Default light mode is "paper", default dark mode is "nebula" (or configurable via defaults / DOM / global window).
229
247
  */
230
- declare function detectHostTheme(container?: HTMLElement): "nebula" | "paper";
248
+ declare function detectHostTheme(container?: HTMLElement, defaults?: DefaultThemesConfig): string;
231
249
  declare function computeDiagramContentBounds(plan: RenderPlan, options?: {
232
250
  tight?: boolean;
233
251
  padding?: number;
@@ -362,4 +380,4 @@ declare function exportRouteShareCard(containerEl: HTMLElement, route: RouteCard
362
380
  */
363
381
  declare function exportReachShareCard(containerEl: HTMLElement, reach: ReachCardOptions, options?: ShareCardOptions): Promise<Blob>;
364
382
 
365
- export { type AnimationRecordFrame, type BlastRadiusResult, type ControllerOptions, type Diagram, type DiagramOptions, DiagramPresentationController, type GifDiagramExportOptions, type GifExportOptions, ICON_REGISTRY, type IconSpec, type PngExportOptions, type ReachCardOptions, type RouteCardOptions, type ShareCardOptions, type SvgExportOptions, type TimelineController, applyImpactHighlight, calculateBlastRadius, clearImpactHighlight, computeDiagramContentBounds, createDiagram, detectHostTheme, encodeGifSequence, exportDiagramAsGif, exportDiagramAsPng, exportDiagramAsShareCard, exportDiagramAsVectorSvg, exportLiveSceneAsPureVectorSvg, exportReachShareCard, exportRouteShareCard, findShortestRoute, iconKeyForNode, renderPureVectorSvg, renderShareCardSvg };
383
+ export { type AnimationRecordFrame, type BlastRadiusResult, type ControllerOptions, type Diagram, type DiagramOptions, DiagramPresentationController, type GifDiagramExportOptions, type GifExportOptions, ICON_REGISTRY, type IconSpec, type PngExportOptions, type ReachCardOptions, type RouteCardOptions, type ShareCardOptions, type SvgExportOptions, type TimelineController, applyImpactHighlight, calculateBlastRadius, clearImpactHighlight, computeDiagramContentBounds, createDiagram, detectHostTheme, encodeGifSequence, exportDiagramAsGif, exportDiagramAsPng, exportDiagramAsShareCard, exportDiagramAsVectorSvg, exportLiveSceneAsPureVectorSvg, exportReachShareCard, exportRouteShareCard, findShortestRoute, iconKeyForNode, renderPureVectorSvg, renderShareCardSvg, resolveDefaultThemes };
package/dist/index.js CHANGED
@@ -3886,6 +3886,8 @@ function ensureSceneStyles(doc) {
3886
3886
  position: relative;
3887
3887
  pointer-events: auto;
3888
3888
  isolation: isolate;
3889
+ overflow: hidden;
3890
+ text-overflow: ellipsis;
3889
3891
  }
3890
3892
  .markdy-controls button:hover:not([aria-pressed="true"]) {
3891
3893
  position: relative;
@@ -4035,10 +4037,32 @@ function ensureSceneStyles(doc) {
4035
4037
  color: #ffffff !important;
4036
4038
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12) !important;
4037
4039
  }
4040
+ @keyframes markdy-spin {
4041
+ from {
4042
+ transform: rotate(0deg);
4043
+ }
4044
+ to {
4045
+ transform: rotate(360deg);
4046
+ }
4047
+ }
4048
+ .markdy-icon-spin {
4049
+ animation: markdy-spin 0.8s linear infinite;
4050
+ }
4038
4051
  .markdy-btn-flashed {
4039
- background: rgba(37, 99, 235, 0.15) !important;
4040
- color: #2563eb !important;
4052
+ background: rgba(16, 185, 129, 0.12) !important;
4053
+ color: #10b981 !important;
4054
+ border-color: rgba(16, 185, 129, 0.4) !important;
4055
+ }
4056
+ .markdy-btn-busy {
4057
+ opacity: 0.85;
4058
+ cursor: wait !important;
4041
4059
  border-color: #2563eb !important;
4060
+ color: #2563eb !important;
4061
+ }
4062
+ .markdy-btn-failed {
4063
+ background: rgba(239, 68, 68, 0.12) !important;
4064
+ color: #ef4444 !important;
4065
+ border-color: rgba(239, 68, 68, 0.4) !important;
4042
4066
  }
4043
4067
  /* \u2500\u2500 Code panel overlay \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
4044
4068
  .markdy-code-panel-overlay {
@@ -6284,33 +6308,72 @@ function isDarkBgColor(colorStr) {
6284
6308
  const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
6285
6309
  return luma < 128;
6286
6310
  }
6287
- function checkElementTheme(el) {
6311
+ function checkElementTheme(el, lightTheme = "paper", darkTheme = "nebula") {
6288
6312
  const themeAttr = el.getAttribute("data-theme") || el.dataset.theme || el.getAttribute("data-mode") || el.getAttribute("data-bs-theme") || el.getAttribute("data-color-mode") || el.getAttribute("data-color-scheme");
6289
6313
  if (themeAttr) {
6290
6314
  const lower = themeAttr.toLowerCase();
6291
- if (lower.includes("dark")) return "nebula";
6292
- if (lower.includes("light")) return "paper";
6315
+ if (lower.includes("dark")) return darkTheme;
6316
+ if (lower.includes("light")) return lightTheme;
6293
6317
  }
6294
6318
  const cls = el.className;
6295
6319
  if (typeof cls === "string" && cls.length > 0) {
6296
- if (/\b(dark|dark-mode|dark-theme|theme-dark|vscode-dark)\b/i.test(cls)) return "nebula";
6297
- if (/\b(light|light-mode|light-theme|theme-light|vscode-light)\b/i.test(cls)) return "paper";
6320
+ if (/\b(dark|dark-mode|dark-theme|theme-dark|vscode-dark)\b/i.test(cls)) return darkTheme;
6321
+ if (/\b(light|light-mode|light-theme|theme-light|vscode-light)\b/i.test(cls)) return lightTheme;
6298
6322
  }
6299
6323
  return null;
6300
6324
  }
6301
- function detectHostTheme(container) {
6302
- if (typeof document === "undefined") return "nebula";
6325
+ function resolveDefaultThemes(container, customDefaults) {
6326
+ let globalLight;
6327
+ let globalDark;
6328
+ if (typeof window !== "undefined") {
6329
+ const win = window;
6330
+ if (win.__MARKDY_DEFAULT_THEMES__) {
6331
+ if (typeof win.__MARKDY_DEFAULT_THEMES__.light === "string") {
6332
+ globalLight = win.__MARKDY_DEFAULT_THEMES__.light;
6333
+ }
6334
+ if (typeof win.__MARKDY_DEFAULT_THEMES__.dark === "string") {
6335
+ globalDark = win.__MARKDY_DEFAULT_THEMES__.dark;
6336
+ }
6337
+ }
6338
+ if (!globalLight && typeof win.__MARKDY_DEFAULT_LIGHT_THEME__ === "string") {
6339
+ globalLight = win.__MARKDY_DEFAULT_LIGHT_THEME__;
6340
+ }
6341
+ if (!globalDark && typeof win.__MARKDY_DEFAULT_DARK_THEME__ === "string") {
6342
+ globalDark = win.__MARKDY_DEFAULT_DARK_THEME__;
6343
+ }
6344
+ }
6345
+ let docLight;
6346
+ let docDark;
6347
+ if (typeof document !== "undefined" && document.documentElement) {
6348
+ docLight = document.documentElement.getAttribute("data-markdy-theme-light") || document.documentElement.dataset?.markdyThemeLight || void 0;
6349
+ docDark = document.documentElement.getAttribute("data-markdy-theme-dark") || document.documentElement.dataset?.markdyThemeDark || void 0;
6350
+ }
6351
+ let containerLight;
6352
+ let containerDark;
6353
+ if (container) {
6354
+ containerLight = container.getAttribute("data-markdy-theme-light") || container.dataset?.markdyThemeLight || void 0;
6355
+ containerDark = container.getAttribute("data-markdy-theme-dark") || container.dataset?.markdyThemeDark || void 0;
6356
+ }
6357
+ const light = customDefaults?.light || containerLight || docLight || globalLight || "paper";
6358
+ const dark = customDefaults?.dark || containerDark || docDark || globalDark || "nebula";
6359
+ return { light, dark };
6360
+ }
6361
+ function detectHostTheme(container, defaults) {
6362
+ const resolvedDefaults = resolveDefaultThemes(container, defaults);
6363
+ const lightTheme = resolvedDefaults.light;
6364
+ const darkTheme = resolvedDefaults.dark;
6365
+ if (typeof document === "undefined") return darkTheme;
6303
6366
  let current = container ?? null;
6304
6367
  while (current) {
6305
- const check = checkElementTheme(current);
6368
+ const check = checkElementTheme(current, lightTheme, darkTheme);
6306
6369
  if (check) return check;
6307
6370
  current = current.parentElement;
6308
6371
  }
6309
6372
  const docRoot = document.documentElement;
6310
- const rootCheck = checkElementTheme(docRoot);
6373
+ const rootCheck = checkElementTheme(docRoot, lightTheme, darkTheme);
6311
6374
  if (rootCheck) return rootCheck;
6312
6375
  if (document.body) {
6313
- const bodyCheck = checkElementTheme(document.body);
6376
+ const bodyCheck = checkElementTheme(document.body, lightTheme, darkTheme);
6314
6377
  if (bodyCheck) return bodyCheck;
6315
6378
  }
6316
6379
  if (typeof window !== "undefined" && typeof window.getComputedStyle === "function") {
@@ -6319,17 +6382,17 @@ function detectHostTheme(container) {
6319
6382
  try {
6320
6383
  const bg = window.getComputedStyle(bgEl).backgroundColor;
6321
6384
  const isDark = isDarkBgColor(bg);
6322
- if (isDark === true) return "nebula";
6323
- if (isDark === false) return "paper";
6385
+ if (isDark === true) return darkTheme;
6386
+ if (isDark === false) return lightTheme;
6324
6387
  } catch {
6325
6388
  }
6326
6389
  bgEl = bgEl.parentElement;
6327
6390
  }
6328
6391
  }
6329
6392
  if (typeof window !== "undefined" && window.matchMedia?.("(prefers-color-scheme: dark)").matches) {
6330
- return "nebula";
6393
+ return darkTheme;
6331
6394
  }
6332
- return "paper";
6395
+ return lightTheme;
6333
6396
  }
6334
6397
  var CANVAS_WIDE_ARCHETYPES = /* @__PURE__ */ new Set([
6335
6398
  "quadrant",
@@ -6491,7 +6554,10 @@ function createDiagram(opts) {
6491
6554
  targetWidthRatio = 0.96,
6492
6555
  contentPadding,
6493
6556
  defaultFit,
6494
- fit: explicitFitOption
6557
+ fit: explicitFitOption,
6558
+ defaultThemes,
6559
+ defaultLightTheme,
6560
+ defaultDarkTheme
6495
6561
  } = opts;
6496
6562
  const initialContainerHeight = container.clientHeight || 0;
6497
6563
  const hasInitialHeightConstraint = initialContainerHeight > 0 && !container.style.aspectRatio;
@@ -6531,7 +6597,13 @@ function createDiagram(opts) {
6531
6597
  if (!ast.meta.explicitHeight) ast.meta.height = dims.height;
6532
6598
  }
6533
6599
  const hasExplicitTheme = Boolean(ast.meta.explicitTheme === true && ast.meta.theme !== "auto");
6534
- const initialTheme = hasExplicitTheme ? ast.meta.theme : detectHostTheme(container);
6600
+ const optionsDefaultLight = defaultThemes?.light ?? defaultLightTheme;
6601
+ const optionsDefaultDark = defaultThemes?.dark ?? defaultDarkTheme;
6602
+ const explicitDefaults = {
6603
+ light: ast.meta.defaultThemes?.light ?? optionsDefaultLight,
6604
+ dark: ast.meta.defaultThemes?.dark ?? optionsDefaultDark
6605
+ };
6606
+ const initialTheme = hasExplicitTheme ? ast.meta.theme : detectHostTheme(container, explicitDefaults);
6535
6607
  const plan = compilePlan(ast, resolveTheme2(initialTheme));
6536
6608
  let hostThemeObserver = null;
6537
6609
  let mediaQueryListener = null;
@@ -7198,7 +7270,8 @@ function createDiagram(opts) {
7198
7270
  share: '<svg class="markdy-icon" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>',
7199
7271
  code: '<svg class="markdy-icon" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>',
7200
7272
  theme: '<svg class="markdy-icon" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 3v18"/><path d="M12 3a9 9 0 0 1 0 18z" fill="currentColor"/></svg>',
7201
- check: '<svg class="markdy-icon" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="#10b981" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>'
7273
+ check: '<svg class="markdy-icon" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="#10b981" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>',
7274
+ spinner: '<svg class="markdy-icon markdy-icon-spin" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>'
7202
7275
  };
7203
7276
  function applyViewportTransform() {
7204
7277
  viewportTransform.style.transform = `translate(${viewportPanX}px, ${viewportPanY}px) scale(${viewportScale})`;
@@ -7583,7 +7656,11 @@ function createDiagram(opts) {
7583
7656
  };
7584
7657
  if (!hasExplicitTheme && typeof document !== "undefined") {
7585
7658
  const syncWithHost = () => {
7586
- const nextTheme = detectHostTheme(container);
7659
+ const currentDefaults = {
7660
+ light: ast.meta.defaultThemes?.light ?? optionsDefaultLight,
7661
+ dark: ast.meta.defaultThemes?.dark ?? optionsDefaultDark
7662
+ };
7663
+ const nextTheme = detectHostTheme(container, currentDefaults);
7587
7664
  diagram.setTheme(nextTheme);
7588
7665
  };
7589
7666
  const attributeFilter = [
@@ -7592,6 +7669,8 @@ function createDiagram(opts) {
7592
7669
  "data-bs-theme",
7593
7670
  "data-color-mode",
7594
7671
  "data-color-scheme",
7672
+ "data-markdy-theme-light",
7673
+ "data-markdy-theme-dark",
7595
7674
  "class",
7596
7675
  "style"
7597
7676
  ];
@@ -7612,6 +7691,12 @@ function createDiagram(opts) {
7612
7691
  attributeFilter
7613
7692
  });
7614
7693
  }
7694
+ if (container) {
7695
+ hostThemeObserver.observe(container, {
7696
+ attributes: true,
7697
+ attributeFilter
7698
+ });
7699
+ }
7615
7700
  if (typeof window !== "undefined" && window.matchMedia) {
7616
7701
  colorSchemeQuery = window.matchMedia("(prefers-color-scheme: dark)");
7617
7702
  mediaQueryListener = syncWithHost;
@@ -7713,20 +7798,89 @@ function createDiagram(opts) {
7713
7798
  return button;
7714
7799
  });
7715
7800
  }
7801
+ function flashControlState(button, options) {
7802
+ const existingTimer = button._flashTimer;
7803
+ if (existingTimer) {
7804
+ clearTimeout(existingTimer);
7805
+ delete button._flashTimer;
7806
+ }
7807
+ if (!button.dataset.origTitle) {
7808
+ button.dataset.origTitle = button.title || "";
7809
+ }
7810
+ if (!button.dataset.origAria) {
7811
+ button.dataset.origAria = button.getAttribute("aria-label") || "";
7812
+ }
7813
+ const iconContainer = button.querySelector("svg.markdy-icon");
7814
+ const labelContainer = button.querySelector(".markdy-btn-label");
7815
+ if (iconContainer && !button.dataset.origIcon) {
7816
+ button.dataset.origIcon = iconContainer.outerHTML;
7817
+ }
7818
+ if (labelContainer && button.dataset.origLabel === void 0) {
7819
+ button.dataset.origLabel = labelContainer.textContent || "";
7820
+ }
7821
+ if (options.icon && iconContainer) {
7822
+ const temp = document.createElement("div");
7823
+ temp.innerHTML = options.icon.trim();
7824
+ const newIcon = temp.firstElementChild;
7825
+ if (newIcon) {
7826
+ iconContainer.replaceWith(newIcon);
7827
+ }
7828
+ }
7829
+ if (options.label !== void 0 && labelContainer) {
7830
+ labelContainer.textContent = options.label;
7831
+ }
7832
+ if (options.title) {
7833
+ button.title = options.title;
7834
+ button.setAttribute("aria-label", options.title);
7835
+ }
7836
+ button.classList.remove("markdy-btn-flashed", "markdy-btn-busy", "markdy-btn-failed");
7837
+ const activeClass = options.stateClass ?? (options.busy ? "markdy-btn-busy" : "markdy-btn-flashed");
7838
+ button.classList.add(activeClass);
7839
+ const reset = () => {
7840
+ if (button._flashTimer) {
7841
+ clearTimeout(button._flashTimer);
7842
+ delete button._flashTimer;
7843
+ }
7844
+ button.classList.remove("markdy-btn-flashed", "markdy-btn-busy", "markdy-btn-failed");
7845
+ if (button.dataset.origTitle !== void 0) {
7846
+ button.title = button.dataset.origTitle;
7847
+ delete button.dataset.origTitle;
7848
+ }
7849
+ if (button.dataset.origAria !== void 0) {
7850
+ button.setAttribute("aria-label", button.dataset.origAria);
7851
+ delete button.dataset.origAria;
7852
+ }
7853
+ const currentIcon = button.querySelector("svg.markdy-icon");
7854
+ if (currentIcon && button.dataset.origIcon) {
7855
+ const temp = document.createElement("div");
7856
+ temp.innerHTML = button.dataset.origIcon.trim();
7857
+ const origIconEl = temp.firstElementChild;
7858
+ if (origIconEl) currentIcon.replaceWith(origIconEl);
7859
+ delete button.dataset.origIcon;
7860
+ }
7861
+ const currentLabel = button.querySelector(".markdy-btn-label");
7862
+ if (currentLabel && button.dataset.origLabel !== void 0) {
7863
+ currentLabel.textContent = button.dataset.origLabel;
7864
+ delete button.dataset.origLabel;
7865
+ }
7866
+ };
7867
+ if (options.duration && options.duration > 0) {
7868
+ button._flashTimer = setTimeout(reset, options.duration);
7869
+ }
7870
+ return reset;
7871
+ }
7716
7872
  function flashControlLabel(button, message) {
7717
- const originalHtml = button.dataset.originalHtml ?? button.innerHTML;
7718
- button.dataset.originalHtml = originalHtml;
7719
7873
  const isSuccess = !message.toLowerCase().includes("fail");
7720
- button.innerHTML = isSuccess ? `${ICONS2.check}<span class="markdy-btn-label">${message}</span>` : `<span class="markdy-btn-label">${message}</span>`;
7721
- button.classList.add("markdy-btn-flashed");
7722
- setTimeout(() => {
7723
- button.innerHTML = button.dataset.originalHtml ?? originalHtml;
7724
- delete button.dataset.originalHtml;
7725
- button.classList.remove("markdy-btn-flashed");
7726
- }, 1500);
7874
+ flashControlState(button, {
7875
+ icon: isSuccess ? ICONS2.check : void 0,
7876
+ label: message,
7877
+ title: message,
7878
+ stateClass: isSuccess ? "markdy-btn-flashed" : "markdy-btn-failed",
7879
+ duration: 1500
7880
+ });
7727
7881
  }
7728
7882
  function downloadFile(filename, contents, type) {
7729
- const blob = new Blob([contents], { type });
7883
+ const blob = contents instanceof Blob ? contents : new Blob([contents], { type });
7730
7884
  const url = URL.createObjectURL(blob);
7731
7885
  const link = document.createElement("a");
7732
7886
  link.href = url;
@@ -7750,10 +7904,20 @@ function createDiagram(opts) {
7750
7904
  const svg = exportDiagramAsVectorSvg(container);
7751
7905
  const name = (plan.title || "markdy-diagram").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
7752
7906
  downloadFile(`${name || "markdy-diagram"}.svg`, svg, "image/svg+xml");
7753
- flashControlLabel(button, "Saved");
7907
+ flashControlState(button, {
7908
+ icon: ICONS2.check,
7909
+ label: "Saved",
7910
+ title: "SVG exported successfully",
7911
+ duration: 1500
7912
+ });
7754
7913
  } catch (error) {
7755
7914
  onWarning({ severity: "warning", message: `SVG export failed: ${String(error)}`, line: 0 });
7756
- flashControlLabel(button, "Failed");
7915
+ flashControlState(button, {
7916
+ label: "Failed",
7917
+ title: "SVG export failed",
7918
+ stateClass: "markdy-btn-failed",
7919
+ duration: 2e3
7920
+ });
7757
7921
  } finally {
7758
7922
  diagram.seek(resumeAt / 1e3);
7759
7923
  if (wasPlaying) diagram.play();
@@ -7766,27 +7930,37 @@ function createDiagram(opts) {
7766
7930
  const button = makeControlButton("GIF", "Export diagram as animated GIF", ICONS2.gif);
7767
7931
  button.className = "markdy-control-gif";
7768
7932
  let exporting = false;
7933
+ let cancelBusy = null;
7769
7934
  button.addEventListener("click", async () => {
7770
7935
  if (exporting) return;
7771
7936
  exporting = true;
7772
- flashControlLabel(button, "Recording...");
7773
7937
  button.setAttribute("disabled", "true");
7938
+ cancelBusy = flashControlState(button, {
7939
+ icon: ICONS2.spinner,
7940
+ label: "Recording...",
7941
+ title: "Recording animated GIF...",
7942
+ busy: true
7943
+ });
7774
7944
  try {
7775
7945
  const blob = await diagram.exportGif();
7776
7946
  const name = (plan.title || "markdy-diagram").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
7777
- const url = URL.createObjectURL(blob);
7778
- const link = document.createElement("a");
7779
- link.href = url;
7780
- link.download = `${name || "markdy-diagram"}.gif`;
7781
- link.style.display = "none";
7782
- document.body.appendChild(link);
7783
- link.click();
7784
- document.body.removeChild(link);
7785
- URL.revokeObjectURL(url);
7786
- flashControlLabel(button, "Saved");
7947
+ downloadFile(`${name || "markdy-diagram"}.gif`, blob, "image/gif");
7948
+ cancelBusy?.();
7949
+ flashControlState(button, {
7950
+ icon: ICONS2.check,
7951
+ label: "Saved",
7952
+ title: "GIF exported successfully",
7953
+ duration: 1500
7954
+ });
7787
7955
  } catch (error) {
7788
7956
  onWarning({ severity: "warning", message: `GIF export failed: ${String(error)}`, line: 0 });
7789
- flashControlLabel(button, "Failed");
7957
+ cancelBusy?.();
7958
+ flashControlState(button, {
7959
+ label: "Failed",
7960
+ title: "GIF export failed",
7961
+ stateClass: "markdy-btn-failed",
7962
+ duration: 2e3
7963
+ });
7790
7964
  } finally {
7791
7965
  exporting = false;
7792
7966
  button.removeAttribute("disabled");
@@ -7803,10 +7977,20 @@ function createDiagram(opts) {
7803
7977
  const hash = await compressMarkdyToUrlHash(code);
7804
7978
  const base = shareUrl ?? MARKDY_PLAYGROUND_URL;
7805
7979
  await navigator.clipboard.writeText(`${base}#code=${hash}`);
7806
- flashControlLabel(button, "Copied");
7980
+ flashControlState(button, {
7981
+ icon: ICONS2.check,
7982
+ label: "Copied",
7983
+ title: "Share link copied to clipboard",
7984
+ duration: 1500
7985
+ });
7807
7986
  } catch (error) {
7808
7987
  onWarning({ severity: "warning", message: `Share link failed: ${String(error)}`, line: 0 });
7809
- flashControlLabel(button, "Failed");
7988
+ flashControlState(button, {
7989
+ label: "Failed",
7990
+ title: "Failed to copy share link",
7991
+ stateClass: "markdy-btn-failed",
7992
+ duration: 2e3
7993
+ });
7810
7994
  }
7811
7995
  });
7812
7996
  toolbar.appendChild(button);
@@ -7822,7 +8006,10 @@ function createDiagram(opts) {
7822
8006
  const isDark = darkThemes.includes(currentName);
7823
8007
  const targetThemes = isDark ? lightThemes : darkThemes;
7824
8008
  const nextTheme = targetThemes[Math.floor(Math.random() * targetThemes.length)];
7825
- flashControlLabel(button, nextTheme);
8009
+ flashControlState(button, {
8010
+ title: `Theme: ${nextTheme}`,
8011
+ duration: 400
8012
+ });
7826
8013
  diagram.setTheme(nextTheme);
7827
8014
  container.dispatchEvent(
7828
8015
  new CustomEvent("markdy-theme-switch", {
@@ -7867,7 +8054,7 @@ function createDiagram(opts) {
7867
8054
  }
7868
8055
  function mountCodeControl(toolbar) {
7869
8056
  if (!codeButton) return;
7870
- const button = makeControlButton("Code", "View MarkdyScript source");
8057
+ const button = makeControlButton("Code", "View MarkdyScript source", ICONS2.code);
7871
8058
  button.className = "markdy-control-code";
7872
8059
  button.setAttribute("aria-haspopup", "dialog");
7873
8060
  button.setAttribute("aria-expanded", "false");
@@ -8756,5 +8943,6 @@ export {
8756
8943
  findShortestRoute,
8757
8944
  iconKeyForNode,
8758
8945
  renderPureVectorSvg,
8759
- renderShareCardSvg
8946
+ renderShareCardSvg,
8947
+ resolveDefaultThemes
8760
8948
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/renderer-dom",
3
- "version": "1.4.15",
3
+ "version": "1.4.17",
4
4
  "description": "Browser renderer for diagram-native animated MarkdyScript architecture diagrams, built on the Web Animations API.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -46,14 +46,14 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "html2canvas": "^1.4.1",
49
- "@markdy/core": "1.4.15"
49
+ "@markdy/core": "1.4.17"
50
50
  },
51
51
  "devDependencies": {
52
52
  "jsdom": "^29.1.1",
53
53
  "tsup": "^8.5.1",
54
54
  "typescript": "^5.9.3",
55
55
  "vitest": "^4.1.7",
56
- "@markdy/stdlib-systems": "1.4.15"
56
+ "@markdy/stdlib-systems": "1.4.17"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsup",