pptx-glimpse 2.0.0 → 3.0.0

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.
@@ -0,0 +1,124 @@
1
+ import {
2
+ buildOpentypeSetupFromState,
3
+ buildReverseMapping,
4
+ createFontMapping,
5
+ createOpentypeSetupState,
6
+ getCachedSystemOpentypeSetup,
7
+ parseFontBuffer,
8
+ registerParsedFont,
9
+ setCachedSystemOpentypeSetup,
10
+ toArrayBuffer,
11
+ tryLoadOpentype
12
+ } from "./chunk-2AYNMYMC.js";
13
+
14
+ // ../renderer/src/font/opentype-system-helpers.ts
15
+ import { readFile } from "fs/promises";
16
+
17
+ // ../renderer/src/font/system-font-loader.ts
18
+ import { existsSync, readdirSync } from "fs";
19
+ import { homedir, platform } from "os";
20
+ import { extname, join } from "path";
21
+ var FONT_EXTENSIONS = /* @__PURE__ */ new Set([".ttf", ".otf"]);
22
+ var CJK_TTC_PATTERNS = [
23
+ "NotoSansCJK",
24
+ "NotoSerifCJK",
25
+ // macOS
26
+ "Hiragino",
27
+ "\u30D2\u30E9\u30AE\u30CE",
28
+ // Windows
29
+ "YuGoth",
30
+ "YuMin",
31
+ "meiryo",
32
+ "msgothic",
33
+ "msmincho"
34
+ ];
35
+ var cachedPaths = null;
36
+ var cachedAdditionalDirs = null;
37
+ var cachedSkipSystemFonts = null;
38
+ function getSystemFontDirs() {
39
+ const os = platform();
40
+ if (os === "linux") return ["/usr/share/fonts", "/usr/local/share/fonts"];
41
+ if (os === "darwin") {
42
+ return ["/System/Library/Fonts", "/Library/Fonts", join(homedir(), "Library/Fonts")];
43
+ }
44
+ if (os === "win32") return ["C:\\Windows\\Fonts"];
45
+ return [];
46
+ }
47
+ function isCjkTtc(name) {
48
+ const lower = name.normalize("NFC").toLowerCase();
49
+ return lower.endsWith(".ttc") && CJK_TTC_PATTERNS.some((p) => lower.includes(p.toLowerCase()));
50
+ }
51
+ function walk(dir, result) {
52
+ if (!existsSync(dir)) return;
53
+ try {
54
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
55
+ const fullPath = join(dir, entry.name);
56
+ if (entry.isDirectory()) {
57
+ walk(fullPath, result);
58
+ } else if (FONT_EXTENSIONS.has(extname(entry.name).toLowerCase()) || isCjkTtc(entry.name)) {
59
+ result.push(fullPath);
60
+ }
61
+ }
62
+ } catch {
63
+ }
64
+ }
65
+ function collectFontFilePaths(additionalDirs, skipSystemFonts = false) {
66
+ const dirs = additionalDirs ?? [];
67
+ const dirsKey = dirs.join("\0");
68
+ const cachedKey = cachedAdditionalDirs?.join("\0") ?? null;
69
+ if (cachedPaths !== null && dirsKey === cachedKey && cachedSkipSystemFonts === skipSystemFonts) {
70
+ return cachedPaths;
71
+ }
72
+ const allDirs = skipSystemFonts ? dirs : [...getSystemFontDirs(), ...dirs];
73
+ const result = [];
74
+ for (const dir of allDirs) {
75
+ walk(dir, result);
76
+ }
77
+ result.sort((a, b) => a.localeCompare(b));
78
+ cachedPaths = result;
79
+ cachedAdditionalDirs = dirs;
80
+ cachedSkipSystemFonts = skipSystemFonts;
81
+ return result;
82
+ }
83
+
84
+ // ../renderer/src/font/opentype-system-helpers.ts
85
+ function buildCacheKey(additionalFontDirs, fontMapping, skipSystemFonts = false) {
86
+ const dirsKey = additionalFontDirs ? [...additionalFontDirs].sort().join("\0") : "";
87
+ const mappingKey = fontMapping ? JSON.stringify(fontMapping, Object.keys(fontMapping).sort()) : "";
88
+ return `${dirsKey}
89
+ ${mappingKey}
90
+ ${skipSystemFonts}`;
91
+ }
92
+ async function createOpentypeSetupFromSystem(additionalFontDirs, fontMapping, skipSystemFonts = false) {
93
+ const key = buildCacheKey(additionalFontDirs, fontMapping, skipSystemFonts);
94
+ const cached = getCachedSystemOpentypeSetup(key);
95
+ if (cached !== void 0) {
96
+ return cached;
97
+ }
98
+ const opentype = await tryLoadOpentype();
99
+ if (!opentype) return null;
100
+ const fontFilePaths = collectFontFilePaths(additionalFontDirs, skipSystemFonts);
101
+ if (fontFilePaths.length === 0) return null;
102
+ const reverseMap = buildReverseMapping(createFontMapping(fontMapping));
103
+ const state = createOpentypeSetupState();
104
+ for (const filePath of fontFilePaths) {
105
+ try {
106
+ const data = await readFile(filePath);
107
+ const arrayBuffer = toArrayBuffer(data);
108
+ const fonts = parseFontBuffer(arrayBuffer, opentype);
109
+ for (const font of fonts) {
110
+ registerParsedFont(font, reverseMap, state);
111
+ }
112
+ } catch {
113
+ }
114
+ }
115
+ const setup = buildOpentypeSetupFromState(state);
116
+ if (setup === null) return null;
117
+ setCachedSystemOpentypeSetup(key, setup);
118
+ return setup;
119
+ }
120
+
121
+ export {
122
+ collectFontFilePaths,
123
+ createOpentypeSetupFromSystem
124
+ };
@@ -0,0 +1,25 @@
1
+ // ../renderer/src/png/render-svg.ts
2
+ import { Resvg } from "@resvg/resvg-wasm";
3
+ function renderSvgToPng(svgString, options) {
4
+ const resvgOptions = {};
5
+ if (options?.width) {
6
+ resvgOptions.fitTo = { mode: "width", value: options.width };
7
+ } else if (options?.height) {
8
+ resvgOptions.fitTo = { mode: "height", value: options.height };
9
+ }
10
+ const fontBuffers = options?.fontBuffers;
11
+ if (fontBuffers && fontBuffers.length > 0) {
12
+ resvgOptions.font = { fontBuffers };
13
+ }
14
+ const resvg = new Resvg(svgString, resvgOptions);
15
+ const rendered = resvg.render();
16
+ return {
17
+ png: new Uint8Array(rendered.asPng()),
18
+ width: rendered.width,
19
+ height: rendered.height
20
+ };
21
+ }
22
+
23
+ export {
24
+ renderSvgToPng
25
+ };