@markdy/renderer-dom 1.4.16 → 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 +22 -4
- package/dist/index.js +79 -18
- package/package.json +3 -3
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):
|
|
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
|
@@ -6308,33 +6308,72 @@ function isDarkBgColor(colorStr) {
|
|
|
6308
6308
|
const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
6309
6309
|
return luma < 128;
|
|
6310
6310
|
}
|
|
6311
|
-
function checkElementTheme(el) {
|
|
6311
|
+
function checkElementTheme(el, lightTheme = "paper", darkTheme = "nebula") {
|
|
6312
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");
|
|
6313
6313
|
if (themeAttr) {
|
|
6314
6314
|
const lower = themeAttr.toLowerCase();
|
|
6315
|
-
if (lower.includes("dark")) return
|
|
6316
|
-
if (lower.includes("light")) return
|
|
6315
|
+
if (lower.includes("dark")) return darkTheme;
|
|
6316
|
+
if (lower.includes("light")) return lightTheme;
|
|
6317
6317
|
}
|
|
6318
6318
|
const cls = el.className;
|
|
6319
6319
|
if (typeof cls === "string" && cls.length > 0) {
|
|
6320
|
-
if (/\b(dark|dark-mode|dark-theme|theme-dark|vscode-dark)\b/i.test(cls)) return
|
|
6321
|
-
if (/\b(light|light-mode|light-theme|theme-light|vscode-light)\b/i.test(cls)) return
|
|
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;
|
|
6322
6322
|
}
|
|
6323
6323
|
return null;
|
|
6324
6324
|
}
|
|
6325
|
-
function
|
|
6326
|
-
|
|
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;
|
|
6327
6366
|
let current = container ?? null;
|
|
6328
6367
|
while (current) {
|
|
6329
|
-
const check = checkElementTheme(current);
|
|
6368
|
+
const check = checkElementTheme(current, lightTheme, darkTheme);
|
|
6330
6369
|
if (check) return check;
|
|
6331
6370
|
current = current.parentElement;
|
|
6332
6371
|
}
|
|
6333
6372
|
const docRoot = document.documentElement;
|
|
6334
|
-
const rootCheck = checkElementTheme(docRoot);
|
|
6373
|
+
const rootCheck = checkElementTheme(docRoot, lightTheme, darkTheme);
|
|
6335
6374
|
if (rootCheck) return rootCheck;
|
|
6336
6375
|
if (document.body) {
|
|
6337
|
-
const bodyCheck = checkElementTheme(document.body);
|
|
6376
|
+
const bodyCheck = checkElementTheme(document.body, lightTheme, darkTheme);
|
|
6338
6377
|
if (bodyCheck) return bodyCheck;
|
|
6339
6378
|
}
|
|
6340
6379
|
if (typeof window !== "undefined" && typeof window.getComputedStyle === "function") {
|
|
@@ -6343,17 +6382,17 @@ function detectHostTheme(container) {
|
|
|
6343
6382
|
try {
|
|
6344
6383
|
const bg = window.getComputedStyle(bgEl).backgroundColor;
|
|
6345
6384
|
const isDark = isDarkBgColor(bg);
|
|
6346
|
-
if (isDark === true) return
|
|
6347
|
-
if (isDark === false) return
|
|
6385
|
+
if (isDark === true) return darkTheme;
|
|
6386
|
+
if (isDark === false) return lightTheme;
|
|
6348
6387
|
} catch {
|
|
6349
6388
|
}
|
|
6350
6389
|
bgEl = bgEl.parentElement;
|
|
6351
6390
|
}
|
|
6352
6391
|
}
|
|
6353
6392
|
if (typeof window !== "undefined" && window.matchMedia?.("(prefers-color-scheme: dark)").matches) {
|
|
6354
|
-
return
|
|
6393
|
+
return darkTheme;
|
|
6355
6394
|
}
|
|
6356
|
-
return
|
|
6395
|
+
return lightTheme;
|
|
6357
6396
|
}
|
|
6358
6397
|
var CANVAS_WIDE_ARCHETYPES = /* @__PURE__ */ new Set([
|
|
6359
6398
|
"quadrant",
|
|
@@ -6515,7 +6554,10 @@ function createDiagram(opts) {
|
|
|
6515
6554
|
targetWidthRatio = 0.96,
|
|
6516
6555
|
contentPadding,
|
|
6517
6556
|
defaultFit,
|
|
6518
|
-
fit: explicitFitOption
|
|
6557
|
+
fit: explicitFitOption,
|
|
6558
|
+
defaultThemes,
|
|
6559
|
+
defaultLightTheme,
|
|
6560
|
+
defaultDarkTheme
|
|
6519
6561
|
} = opts;
|
|
6520
6562
|
const initialContainerHeight = container.clientHeight || 0;
|
|
6521
6563
|
const hasInitialHeightConstraint = initialContainerHeight > 0 && !container.style.aspectRatio;
|
|
@@ -6555,7 +6597,13 @@ function createDiagram(opts) {
|
|
|
6555
6597
|
if (!ast.meta.explicitHeight) ast.meta.height = dims.height;
|
|
6556
6598
|
}
|
|
6557
6599
|
const hasExplicitTheme = Boolean(ast.meta.explicitTheme === true && ast.meta.theme !== "auto");
|
|
6558
|
-
const
|
|
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);
|
|
6559
6607
|
const plan = compilePlan(ast, resolveTheme2(initialTheme));
|
|
6560
6608
|
let hostThemeObserver = null;
|
|
6561
6609
|
let mediaQueryListener = null;
|
|
@@ -7608,7 +7656,11 @@ function createDiagram(opts) {
|
|
|
7608
7656
|
};
|
|
7609
7657
|
if (!hasExplicitTheme && typeof document !== "undefined") {
|
|
7610
7658
|
const syncWithHost = () => {
|
|
7611
|
-
const
|
|
7659
|
+
const currentDefaults = {
|
|
7660
|
+
light: ast.meta.defaultThemes?.light ?? optionsDefaultLight,
|
|
7661
|
+
dark: ast.meta.defaultThemes?.dark ?? optionsDefaultDark
|
|
7662
|
+
};
|
|
7663
|
+
const nextTheme = detectHostTheme(container, currentDefaults);
|
|
7612
7664
|
diagram.setTheme(nextTheme);
|
|
7613
7665
|
};
|
|
7614
7666
|
const attributeFilter = [
|
|
@@ -7617,6 +7669,8 @@ function createDiagram(opts) {
|
|
|
7617
7669
|
"data-bs-theme",
|
|
7618
7670
|
"data-color-mode",
|
|
7619
7671
|
"data-color-scheme",
|
|
7672
|
+
"data-markdy-theme-light",
|
|
7673
|
+
"data-markdy-theme-dark",
|
|
7620
7674
|
"class",
|
|
7621
7675
|
"style"
|
|
7622
7676
|
];
|
|
@@ -7637,6 +7691,12 @@ function createDiagram(opts) {
|
|
|
7637
7691
|
attributeFilter
|
|
7638
7692
|
});
|
|
7639
7693
|
}
|
|
7694
|
+
if (container) {
|
|
7695
|
+
hostThemeObserver.observe(container, {
|
|
7696
|
+
attributes: true,
|
|
7697
|
+
attributeFilter
|
|
7698
|
+
});
|
|
7699
|
+
}
|
|
7640
7700
|
if (typeof window !== "undefined" && window.matchMedia) {
|
|
7641
7701
|
colorSchemeQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
7642
7702
|
mediaQueryListener = syncWithHost;
|
|
@@ -8883,5 +8943,6 @@ export {
|
|
|
8883
8943
|
findShortestRoute,
|
|
8884
8944
|
iconKeyForNode,
|
|
8885
8945
|
renderPureVectorSvg,
|
|
8886
|
-
renderShareCardSvg
|
|
8946
|
+
renderShareCardSvg,
|
|
8947
|
+
resolveDefaultThemes
|
|
8887
8948
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdy/renderer-dom",
|
|
3
|
-
"version": "1.4.
|
|
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.
|
|
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.
|
|
56
|
+
"@markdy/stdlib-systems": "1.4.17"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsup",
|