- 新增可复用的 markdown-echarts 工作区,支持安全的 YAML 围栏、默认值、语义校验、错误占位和 SVG 渲染 - 将 ECharts 接入统一 Markdown、快速预览、精确预览与 PDF 链路,并复用 Mermaid 的不可跨页和超高图单页适配策略 - 默认示例加入 ECharts,增加源文本折叠、顶部文档状态、页码输入跳转与滚动同步 - 快速预览改用外层容器滚动,使滚动条与精确预览统一贴在预览区域右侧,并兼容显示缩放 - 完善 Docker 工作区复制、可配置 Compose 镜像、测试覆盖和进度文档
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
// @vitest-environment happy-dom
|
|
|
|
import { defaultExportConfig } from "@md-to-pdf/core";
|
|
import { describe, expect, it } from "vitest";
|
|
import { fitOversizedEChartsToPage } from "../src/echarts-page-fit";
|
|
|
|
describe("ECharts 单页高度适配", () => {
|
|
it("将超高 SVG 和宿主同步缩放到单页内容区", () => {
|
|
const root = document.createElement("div");
|
|
root.innerHTML = `
|
|
<figure class="md-echarts">
|
|
<div class="md-echarts-host" style="height: 2000px">
|
|
<svg width="1000" height="2000"></svg>
|
|
</div>
|
|
</figure>
|
|
`;
|
|
|
|
fitOversizedEChartsToPage(root, defaultExportConfig);
|
|
|
|
const figure = root.querySelector<HTMLElement>(".md-echarts");
|
|
const host = root.querySelector<HTMLElement>(
|
|
".md-echarts-host"
|
|
);
|
|
const svg = root.querySelector<SVGSVGElement>("svg");
|
|
expect(figure?.dataset.pageHeightFitted).toBe("true");
|
|
expect(Number.parseFloat(host?.style.height ?? "0")).toBeCloseTo(
|
|
1000.5748,
|
|
3
|
|
);
|
|
expect(host?.style.aspectRatio).toBe("");
|
|
expect(svg?.getAttribute("viewBox")).toBe("0 0 1000 2000");
|
|
expect(Number.parseFloat(svg?.style.height ?? "0")).toBeCloseTo(
|
|
1000.5748,
|
|
3
|
|
);
|
|
});
|
|
|
|
it("普通高度图表不改变作者设置的宿主高度", () => {
|
|
const root = document.createElement("div");
|
|
root.innerHTML = `
|
|
<figure class="md-echarts">
|
|
<div class="md-echarts-host" style="height: 300px">
|
|
<svg viewBox="0 0 1000 400"></svg>
|
|
</div>
|
|
</figure>
|
|
`;
|
|
|
|
fitOversizedEChartsToPage(root, defaultExportConfig);
|
|
|
|
const figure = root.querySelector<HTMLElement>(".md-echarts");
|
|
const host = root.querySelector<HTMLElement>(
|
|
".md-echarts-host"
|
|
);
|
|
expect(figure?.dataset.pageHeightFitted).toBeUndefined();
|
|
expect(host?.style.height).toBe("300px");
|
|
});
|
|
});
|