first commit

This commit is contained in:
douboer
2026-03-21 18:57:10 +08:00
commit c49aa1a5e9
570 changed files with 107167 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import { describe, expect, it } from "vitest";
const { toSvgDataUri } = require("./svgDataUri.js");
function decodeSvgFromDataUri(uri: string) {
const prefix = "data:image/svg+xml;base64,";
expect(uri.startsWith(prefix)).toBe(true);
return Buffer.from(uri.slice(prefix.length), "base64").toString("utf8");
}
describe("svgDataUri", () => {
it("把 SVG 编码为 base64 data URI", () => {
const svg = '<svg xmlns="http://www.w3.org/2000/svg"><path fill="#67D1FF" d="M0 0h10v10H0z"/></svg>';
const uri = toSvgDataUri(svg);
expect(decodeSvgFromDataUri(uri)).toBe(svg);
});
it("对非 ASCII 字符使用 UTF-8 编码,避免 data URI 损坏", () => {
const svg = '<svg xmlns="http://www.w3.org/2000/svg"><text>终端</text></svg>';
const uri = toSvgDataUri(svg);
expect(decodeSvgFromDataUri(uri)).toContain("终端");
});
});