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.
- package/dist/browser.cjs +14329 -0
- package/dist/browser.d.cts +131 -0
- package/dist/browser.d.ts +131 -0
- package/dist/browser.js +3180 -0
- package/dist/chunk-2AYNMYMC.js +1554 -0
- package/dist/chunk-KMSN55AE.js +9629 -0
- package/dist/chunk-MWMHSSAD.js +124 -0
- package/dist/chunk-QPT6BMN5.js +25 -0
- package/dist/font-collector-DYooJP6L.d.cts +1345 -0
- package/dist/font-collector-DYooJP6L.d.ts +1345 -0
- package/dist/index.cjs +8965 -8685
- package/dist/index.d.cts +4 -538
- package/dist/index.d.ts +4 -538
- package/dist/index.js +57 -10660
- package/dist/node-6KTAWUIB.js +9 -0
- package/dist/node-font-loader-274G445U.js +45 -0
- package/dist/png-IONMVVDQ.js +53 -0
- package/package.json +10 -3
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collectFontFilePaths
|
|
3
|
+
} from "./chunk-MWMHSSAD.js";
|
|
4
|
+
import "./chunk-2AYNMYMC.js";
|
|
5
|
+
|
|
6
|
+
// src/node-font-loader.ts
|
|
7
|
+
import { readFileSync, statSync } from "fs";
|
|
8
|
+
var cachedFontBuffers = null;
|
|
9
|
+
var cachedFontBuffersKey = null;
|
|
10
|
+
var MAX_TOTAL_FONT_BUFFER_BYTES = 100 * 1024 * 1024;
|
|
11
|
+
function loadFontBuffersFromSystem(fontDirs, skipSystemFonts) {
|
|
12
|
+
const key = `${(fontDirs ?? []).join("\0")}
|
|
13
|
+
${skipSystemFonts ?? false}`;
|
|
14
|
+
if (cachedFontBuffers !== null && cachedFontBuffersKey === key) {
|
|
15
|
+
return cachedFontBuffers;
|
|
16
|
+
}
|
|
17
|
+
const fontPaths = collectFontFilePaths(fontDirs, skipSystemFonts).filter((path) => {
|
|
18
|
+
const lower = path.toLowerCase();
|
|
19
|
+
return lower.endsWith(".ttf") || lower.endsWith(".otf");
|
|
20
|
+
});
|
|
21
|
+
const readableFontPaths = [];
|
|
22
|
+
for (const path of fontPaths) {
|
|
23
|
+
try {
|
|
24
|
+
readableFontPaths.push({ path, size: statSync(path).size });
|
|
25
|
+
} catch {
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
readableFontPaths.sort((a, b) => a.size - b.size || a.path.localeCompare(b.path));
|
|
29
|
+
const buffers = [];
|
|
30
|
+
let totalSize = 0;
|
|
31
|
+
for (const { path, size } of readableFontPaths) {
|
|
32
|
+
if (totalSize + size > MAX_TOTAL_FONT_BUFFER_BYTES) break;
|
|
33
|
+
try {
|
|
34
|
+
buffers.push(new Uint8Array(readFileSync(path)));
|
|
35
|
+
totalSize += size;
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
cachedFontBuffers = buffers;
|
|
40
|
+
cachedFontBuffersKey = key;
|
|
41
|
+
return buffers;
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
loadFontBuffersFromSystem
|
|
45
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
renderSvgToPng
|
|
3
|
+
} from "./chunk-QPT6BMN5.js";
|
|
4
|
+
|
|
5
|
+
// ../renderer/src/png/png-converter.ts
|
|
6
|
+
import { initWasm } from "@resvg/resvg-wasm";
|
|
7
|
+
var wasmInitPromise = null;
|
|
8
|
+
var nodeImportPrefix = "node:";
|
|
9
|
+
var fsModuleName = "fs";
|
|
10
|
+
var fsPromisesSegment = "promises";
|
|
11
|
+
var moduleModuleName = "module";
|
|
12
|
+
function resolveWasmPath(createRequire) {
|
|
13
|
+
const baseUrl = import.meta.url || `file://${__filename}`;
|
|
14
|
+
const require2 = createRequire(baseUrl);
|
|
15
|
+
return require2.resolve("@resvg/resvg-wasm/index_bg.wasm");
|
|
16
|
+
}
|
|
17
|
+
async function loadBundledWasm() {
|
|
18
|
+
const [{ readFile }, { createRequire }] = await Promise.all([
|
|
19
|
+
importNodeFsPromises(),
|
|
20
|
+
importNodeModule()
|
|
21
|
+
]);
|
|
22
|
+
const wasmPath = resolveWasmPath(createRequire);
|
|
23
|
+
return readFile(wasmPath);
|
|
24
|
+
}
|
|
25
|
+
function importNodeFsPromises() {
|
|
26
|
+
return import(`${nodeImportPrefix}${fsModuleName}/${fsPromisesSegment}`);
|
|
27
|
+
}
|
|
28
|
+
function importNodeModule() {
|
|
29
|
+
return import(`${nodeImportPrefix}${moduleModuleName}`);
|
|
30
|
+
}
|
|
31
|
+
async function normalizeWasmInput(wasm) {
|
|
32
|
+
if (wasm instanceof ArrayBuffer || wasm instanceof Uint8Array) {
|
|
33
|
+
return wasm;
|
|
34
|
+
}
|
|
35
|
+
return wasm.arrayBuffer();
|
|
36
|
+
}
|
|
37
|
+
async function initResvgWasm(wasm) {
|
|
38
|
+
if (!wasmInitPromise) {
|
|
39
|
+
wasmInitPromise = (async () => {
|
|
40
|
+
const wasmInput = wasm === void 0 ? await loadBundledWasm() : await normalizeWasmInput(wasm);
|
|
41
|
+
await initWasm(wasmInput);
|
|
42
|
+
})();
|
|
43
|
+
}
|
|
44
|
+
await wasmInitPromise;
|
|
45
|
+
}
|
|
46
|
+
async function svgToPng(svgString, options) {
|
|
47
|
+
await initResvgWasm();
|
|
48
|
+
return renderSvgToPng(svgString, options);
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
initResvgWasm,
|
|
52
|
+
svgToPng
|
|
53
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pptx-glimpse",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A lightweight JavaScript library for rendering PowerPoint (.pptx) files as SVG or PNG in Node.js. No LibreOffice required.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
|
+
"browser": "./dist/browser.js",
|
|
8
9
|
"types": "./dist/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
12
|
+
"browser": {
|
|
13
|
+
"types": "./dist/browser.d.ts",
|
|
14
|
+
"import": "./dist/browser.js",
|
|
15
|
+
"default": "./dist/browser.js"
|
|
16
|
+
},
|
|
11
17
|
"types": "./dist/index.d.ts",
|
|
12
18
|
"import": "./dist/index.js",
|
|
13
19
|
"require": "./dist/index.cjs"
|
|
@@ -43,8 +49,9 @@
|
|
|
43
49
|
"opentype.js": "1.3.4"
|
|
44
50
|
},
|
|
45
51
|
"devDependencies": {
|
|
46
|
-
"@pptx-glimpse/
|
|
47
|
-
"@pptx-glimpse/
|
|
52
|
+
"@pptx-glimpse/document": "0.0.0",
|
|
53
|
+
"@pptx-glimpse/editor-core": "0.0.0",
|
|
54
|
+
"@pptx-glimpse/renderer": "0.0.0"
|
|
48
55
|
},
|
|
49
56
|
"scripts": {
|
|
50
57
|
"build": "tsup"
|