@markdy/renderer-dom 1.4.16 → 1.4.18
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 +95 -26
- 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
|
@@ -6301,59 +6301,106 @@ function buildBeatCaptionAnimations(beats, layer) {
|
|
|
6301
6301
|
function isDarkBgColor(colorStr) {
|
|
6302
6302
|
if (!colorStr || colorStr === "transparent" || colorStr === "rgba(0, 0, 0, 0)") return null;
|
|
6303
6303
|
const match = colorStr.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/i);
|
|
6304
|
-
if (
|
|
6305
|
-
|
|
6306
|
-
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
}
|
|
6311
|
-
|
|
6304
|
+
if (match) {
|
|
6305
|
+
const r = parseInt(match[1], 10);
|
|
6306
|
+
const g = parseInt(match[2], 10);
|
|
6307
|
+
const b = parseInt(match[3], 10);
|
|
6308
|
+
const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
6309
|
+
return luma < 128;
|
|
6310
|
+
}
|
|
6311
|
+
const oklMatch = colorStr.match(/ok(?:lch|lab)\(\s*([\d.]+)(%?)/i);
|
|
6312
|
+
if (oklMatch) {
|
|
6313
|
+
let l = parseFloat(oklMatch[1]);
|
|
6314
|
+
if (oklMatch[2] === "%") l /= 100;
|
|
6315
|
+
return l < 0.5;
|
|
6316
|
+
}
|
|
6317
|
+
return null;
|
|
6318
|
+
}
|
|
6319
|
+
function checkElementTheme(el, lightTheme = "paper", darkTheme = "nebula") {
|
|
6312
6320
|
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
6321
|
if (themeAttr) {
|
|
6314
6322
|
const lower = themeAttr.toLowerCase();
|
|
6315
|
-
if (lower.includes("dark")) return
|
|
6316
|
-
if (lower.includes("light")) return
|
|
6323
|
+
if (lower.includes("dark")) return darkTheme;
|
|
6324
|
+
if (lower.includes("light")) return lightTheme;
|
|
6317
6325
|
}
|
|
6318
6326
|
const cls = el.className;
|
|
6319
6327
|
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
|
|
6328
|
+
if (/\b(dark|dark-mode|dark-theme|theme-dark|vscode-dark)\b/i.test(cls)) return darkTheme;
|
|
6329
|
+
if (/\b(light|light-mode|light-theme|theme-light|vscode-light)\b/i.test(cls)) return lightTheme;
|
|
6322
6330
|
}
|
|
6323
6331
|
return null;
|
|
6324
6332
|
}
|
|
6325
|
-
function
|
|
6326
|
-
|
|
6333
|
+
function resolveDefaultThemes(container, customDefaults) {
|
|
6334
|
+
let globalLight;
|
|
6335
|
+
let globalDark;
|
|
6336
|
+
if (typeof window !== "undefined") {
|
|
6337
|
+
const win = window;
|
|
6338
|
+
if (win.__MARKDY_DEFAULT_THEMES__) {
|
|
6339
|
+
if (typeof win.__MARKDY_DEFAULT_THEMES__.light === "string") {
|
|
6340
|
+
globalLight = win.__MARKDY_DEFAULT_THEMES__.light;
|
|
6341
|
+
}
|
|
6342
|
+
if (typeof win.__MARKDY_DEFAULT_THEMES__.dark === "string") {
|
|
6343
|
+
globalDark = win.__MARKDY_DEFAULT_THEMES__.dark;
|
|
6344
|
+
}
|
|
6345
|
+
}
|
|
6346
|
+
if (!globalLight && typeof win.__MARKDY_DEFAULT_LIGHT_THEME__ === "string") {
|
|
6347
|
+
globalLight = win.__MARKDY_DEFAULT_LIGHT_THEME__;
|
|
6348
|
+
}
|
|
6349
|
+
if (!globalDark && typeof win.__MARKDY_DEFAULT_DARK_THEME__ === "string") {
|
|
6350
|
+
globalDark = win.__MARKDY_DEFAULT_DARK_THEME__;
|
|
6351
|
+
}
|
|
6352
|
+
}
|
|
6353
|
+
let docLight;
|
|
6354
|
+
let docDark;
|
|
6355
|
+
if (typeof document !== "undefined" && document.documentElement) {
|
|
6356
|
+
docLight = document.documentElement.getAttribute("data-markdy-theme-light") || document.documentElement.dataset?.markdyThemeLight || void 0;
|
|
6357
|
+
docDark = document.documentElement.getAttribute("data-markdy-theme-dark") || document.documentElement.dataset?.markdyThemeDark || void 0;
|
|
6358
|
+
}
|
|
6359
|
+
let containerLight;
|
|
6360
|
+
let containerDark;
|
|
6361
|
+
if (container) {
|
|
6362
|
+
containerLight = container.getAttribute("data-markdy-theme-light") || container.dataset?.markdyThemeLight || void 0;
|
|
6363
|
+
containerDark = container.getAttribute("data-markdy-theme-dark") || container.dataset?.markdyThemeDark || void 0;
|
|
6364
|
+
}
|
|
6365
|
+
const light = customDefaults?.light || containerLight || docLight || globalLight || "paper";
|
|
6366
|
+
const dark = customDefaults?.dark || containerDark || docDark || globalDark || "nebula";
|
|
6367
|
+
return { light, dark };
|
|
6368
|
+
}
|
|
6369
|
+
function detectHostTheme(container, defaults) {
|
|
6370
|
+
const resolvedDefaults = resolveDefaultThemes(container, defaults);
|
|
6371
|
+
const lightTheme = resolvedDefaults.light;
|
|
6372
|
+
const darkTheme = resolvedDefaults.dark;
|
|
6373
|
+
if (typeof document === "undefined") return darkTheme;
|
|
6327
6374
|
let current = container ?? null;
|
|
6328
6375
|
while (current) {
|
|
6329
|
-
const check = checkElementTheme(current);
|
|
6376
|
+
const check = checkElementTheme(current, lightTheme, darkTheme);
|
|
6330
6377
|
if (check) return check;
|
|
6331
6378
|
current = current.parentElement;
|
|
6332
6379
|
}
|
|
6333
6380
|
const docRoot = document.documentElement;
|
|
6334
|
-
const rootCheck = checkElementTheme(docRoot);
|
|
6381
|
+
const rootCheck = checkElementTheme(docRoot, lightTheme, darkTheme);
|
|
6335
6382
|
if (rootCheck) return rootCheck;
|
|
6336
6383
|
if (document.body) {
|
|
6337
|
-
const bodyCheck = checkElementTheme(document.body);
|
|
6384
|
+
const bodyCheck = checkElementTheme(document.body, lightTheme, darkTheme);
|
|
6338
6385
|
if (bodyCheck) return bodyCheck;
|
|
6339
6386
|
}
|
|
6340
6387
|
if (typeof window !== "undefined" && typeof window.getComputedStyle === "function") {
|
|
6341
|
-
let bgEl = container ?? document.body ?? null;
|
|
6388
|
+
let bgEl = (container ? container.parentElement : null) ?? document.body ?? null;
|
|
6342
6389
|
while (bgEl) {
|
|
6343
6390
|
try {
|
|
6344
6391
|
const bg = window.getComputedStyle(bgEl).backgroundColor;
|
|
6345
6392
|
const isDark = isDarkBgColor(bg);
|
|
6346
|
-
if (isDark === true) return
|
|
6347
|
-
if (isDark === false) return
|
|
6393
|
+
if (isDark === true) return darkTheme;
|
|
6394
|
+
if (isDark === false) return lightTheme;
|
|
6348
6395
|
} catch {
|
|
6349
6396
|
}
|
|
6350
6397
|
bgEl = bgEl.parentElement;
|
|
6351
6398
|
}
|
|
6352
6399
|
}
|
|
6353
6400
|
if (typeof window !== "undefined" && window.matchMedia?.("(prefers-color-scheme: dark)").matches) {
|
|
6354
|
-
return
|
|
6401
|
+
return darkTheme;
|
|
6355
6402
|
}
|
|
6356
|
-
return
|
|
6403
|
+
return lightTheme;
|
|
6357
6404
|
}
|
|
6358
6405
|
var CANVAS_WIDE_ARCHETYPES = /* @__PURE__ */ new Set([
|
|
6359
6406
|
"quadrant",
|
|
@@ -6515,7 +6562,10 @@ function createDiagram(opts) {
|
|
|
6515
6562
|
targetWidthRatio = 0.96,
|
|
6516
6563
|
contentPadding,
|
|
6517
6564
|
defaultFit,
|
|
6518
|
-
fit: explicitFitOption
|
|
6565
|
+
fit: explicitFitOption,
|
|
6566
|
+
defaultThemes,
|
|
6567
|
+
defaultLightTheme,
|
|
6568
|
+
defaultDarkTheme
|
|
6519
6569
|
} = opts;
|
|
6520
6570
|
const initialContainerHeight = container.clientHeight || 0;
|
|
6521
6571
|
const hasInitialHeightConstraint = initialContainerHeight > 0 && !container.style.aspectRatio;
|
|
@@ -6555,7 +6605,13 @@ function createDiagram(opts) {
|
|
|
6555
6605
|
if (!ast.meta.explicitHeight) ast.meta.height = dims.height;
|
|
6556
6606
|
}
|
|
6557
6607
|
const hasExplicitTheme = Boolean(ast.meta.explicitTheme === true && ast.meta.theme !== "auto");
|
|
6558
|
-
const
|
|
6608
|
+
const optionsDefaultLight = defaultThemes?.light ?? defaultLightTheme;
|
|
6609
|
+
const optionsDefaultDark = defaultThemes?.dark ?? defaultDarkTheme;
|
|
6610
|
+
const explicitDefaults = {
|
|
6611
|
+
light: ast.meta.defaultThemes?.light ?? optionsDefaultLight,
|
|
6612
|
+
dark: ast.meta.defaultThemes?.dark ?? optionsDefaultDark
|
|
6613
|
+
};
|
|
6614
|
+
const initialTheme = hasExplicitTheme ? ast.meta.theme : detectHostTheme(container, explicitDefaults);
|
|
6559
6615
|
const plan = compilePlan(ast, resolveTheme2(initialTheme));
|
|
6560
6616
|
let hostThemeObserver = null;
|
|
6561
6617
|
let mediaQueryListener = null;
|
|
@@ -7608,7 +7664,11 @@ function createDiagram(opts) {
|
|
|
7608
7664
|
};
|
|
7609
7665
|
if (!hasExplicitTheme && typeof document !== "undefined") {
|
|
7610
7666
|
const syncWithHost = () => {
|
|
7611
|
-
const
|
|
7667
|
+
const currentDefaults = {
|
|
7668
|
+
light: ast.meta.defaultThemes?.light ?? optionsDefaultLight,
|
|
7669
|
+
dark: ast.meta.defaultThemes?.dark ?? optionsDefaultDark
|
|
7670
|
+
};
|
|
7671
|
+
const nextTheme = detectHostTheme(container, currentDefaults);
|
|
7612
7672
|
diagram.setTheme(nextTheme);
|
|
7613
7673
|
};
|
|
7614
7674
|
const attributeFilter = [
|
|
@@ -7617,6 +7677,8 @@ function createDiagram(opts) {
|
|
|
7617
7677
|
"data-bs-theme",
|
|
7618
7678
|
"data-color-mode",
|
|
7619
7679
|
"data-color-scheme",
|
|
7680
|
+
"data-markdy-theme-light",
|
|
7681
|
+
"data-markdy-theme-dark",
|
|
7620
7682
|
"class",
|
|
7621
7683
|
"style"
|
|
7622
7684
|
];
|
|
@@ -7637,6 +7699,12 @@ function createDiagram(opts) {
|
|
|
7637
7699
|
attributeFilter
|
|
7638
7700
|
});
|
|
7639
7701
|
}
|
|
7702
|
+
if (container) {
|
|
7703
|
+
hostThemeObserver.observe(container, {
|
|
7704
|
+
attributes: true,
|
|
7705
|
+
attributeFilter
|
|
7706
|
+
});
|
|
7707
|
+
}
|
|
7640
7708
|
if (typeof window !== "undefined" && window.matchMedia) {
|
|
7641
7709
|
colorSchemeQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
7642
7710
|
mediaQueryListener = syncWithHost;
|
|
@@ -8883,5 +8951,6 @@ export {
|
|
|
8883
8951
|
findShortestRoute,
|
|
8884
8952
|
iconKeyForNode,
|
|
8885
8953
|
renderPureVectorSvg,
|
|
8886
|
-
renderShareCardSvg
|
|
8954
|
+
renderShareCardSvg,
|
|
8955
|
+
resolveDefaultThemes
|
|
8887
8956
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markdy/renderer-dom",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.18",
|
|
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.18"
|
|
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.18"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsup",
|