- 新增可复用的 markdown-echarts 工作区,支持安全的 YAML 围栏、默认值、语义校验、错误占位和 SVG 渲染 - 将 ECharts 接入统一 Markdown、快速预览、精确预览与 PDF 链路,并复用 Mermaid 的不可跨页和超高图单页适配策略 - 默认示例加入 ECharts,增加源文本折叠、顶部文档状态、页码输入跳转与滚动同步 - 快速预览改用外层容器滚动,使滚动条与精确预览统一贴在预览区域右侧,并兼容显示缩放 - 完善 Docker 工作区复制、可配置 Compose 镜像、测试覆盖和进度文档
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import type { ExportConfig } from "@md-to-pdf/core";
|
|
import { fitSvgDiagramsToPage } from "./diagram-page-fit";
|
|
|
|
export function fitOversizedEChartsToPage(
|
|
container: ParentNode,
|
|
config: ExportConfig
|
|
) {
|
|
fitSvgDiagramsToPage(container, config, {
|
|
containerSelector: ".md-echarts",
|
|
svgSelector: ".md-echarts-host svg",
|
|
resolvePageContent(figure, pageContent) {
|
|
const host = figure.querySelector<HTMLElement>(
|
|
".md-echarts-host"
|
|
);
|
|
const figureHeight = figure.getBoundingClientRect().height;
|
|
const hostHeight = host?.getBoundingClientRect().height ?? 0;
|
|
const nonChartHeight = Math.max(
|
|
0,
|
|
figureHeight - hostHeight
|
|
);
|
|
return {
|
|
width: pageContent.width,
|
|
height: Math.max(0, pageContent.height - nonChartHeight)
|
|
};
|
|
},
|
|
onFit(figure, _svg, fit) {
|
|
const host = figure.querySelector<HTMLElement>(
|
|
".md-echarts-host"
|
|
);
|
|
if (!host) {
|
|
return;
|
|
}
|
|
host.style.setProperty(
|
|
"width",
|
|
`${fit.width}px`,
|
|
"important"
|
|
);
|
|
host.style.setProperty(
|
|
"height",
|
|
`${fit.height}px`,
|
|
"important"
|
|
);
|
|
host.style.setProperty("margin-inline", "auto", "important");
|
|
host.style.removeProperty("aspect-ratio");
|
|
}
|
|
});
|
|
}
|