@formepdf/cli 0.4.1 → 0.4.4
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/dev.js +29 -2
- package/dist/preview/index.html +2 -2
- package/package.json +3 -3
package/dist/dev.js
CHANGED
|
@@ -165,8 +165,11 @@ export function startDevServer(inputPath, options) {
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
// Resolve font file paths
|
|
169
|
-
await
|
|
168
|
+
// Resolve font file paths and image URLs before rendering
|
|
169
|
+
await Promise.all([
|
|
170
|
+
resolveFontPaths(doc, absoluteInput),
|
|
171
|
+
resolveImageUrls(doc),
|
|
172
|
+
]);
|
|
170
173
|
const { pdf, layout } = await renderPdfWithLayout(JSON.stringify(doc));
|
|
171
174
|
// Skip if a newer build started
|
|
172
175
|
if (buildId !== buildCounter)
|
|
@@ -310,6 +313,30 @@ function hasAnySourceLocation(doc) {
|
|
|
310
313
|
function uint8ArrayToBase64(bytes) {
|
|
311
314
|
return Buffer.from(bytes).toString('base64');
|
|
312
315
|
}
|
|
316
|
+
async function resolveImageUrls(doc) {
|
|
317
|
+
const children = doc.children;
|
|
318
|
+
if (!children?.length)
|
|
319
|
+
return;
|
|
320
|
+
await Promise.all(children.map(resolveImageUrlsInNode));
|
|
321
|
+
}
|
|
322
|
+
async function resolveImageUrlsInNode(node) {
|
|
323
|
+
const kind = node.kind;
|
|
324
|
+
if (kind?.type === 'Image' && typeof kind.src === 'string') {
|
|
325
|
+
const src = kind.src;
|
|
326
|
+
if (src.startsWith('http://') || src.startsWith('https://')) {
|
|
327
|
+
const res = await fetch(src);
|
|
328
|
+
if (!res.ok)
|
|
329
|
+
throw new Error(`Failed to fetch image: ${src} (${res.status})`);
|
|
330
|
+
const contentType = res.headers.get('content-type') || 'image/png';
|
|
331
|
+
const buf = new Uint8Array(await res.arrayBuffer());
|
|
332
|
+
kind.src = `data:${contentType};base64,${uint8ArrayToBase64(buf)}`;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const children = node.children;
|
|
336
|
+
if (children?.length) {
|
|
337
|
+
await Promise.all(children.map(resolveImageUrlsInNode));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
313
340
|
async function resolveFontPaths(doc, templatePath) {
|
|
314
341
|
const fonts = doc.fonts;
|
|
315
342
|
if (!fonts?.length)
|
package/dist/preview/index.html
CHANGED
|
@@ -2283,8 +2283,8 @@
|
|
|
2283
2283
|
|
|
2284
2284
|
// -- Keyboard shortcuts ------------------------------------------
|
|
2285
2285
|
document.addEventListener('keydown', (e) => {
|
|
2286
|
-
// Don't intercept when typing in data editor
|
|
2287
|
-
if (e.target === dataEditor) return;
|
|
2286
|
+
// Don't intercept when typing in inputs or data editor
|
|
2287
|
+
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target === dataEditor) return;
|
|
2288
2288
|
|
|
2289
2289
|
if (!e.metaKey && !e.ctrlKey && !e.altKey) {
|
|
2290
2290
|
if (e.key === '1') { e.preventDefault(); setMode('preview'); }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formepdf/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "CLI for Forme PDF rendering engine — dev server with live preview and build command",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@formepdf/core": "0.4.
|
|
18
|
-
"@formepdf/react": "0.4.
|
|
17
|
+
"@formepdf/core": "0.4.4",
|
|
18
|
+
"@formepdf/react": "0.4.4",
|
|
19
19
|
"esbuild": "^0.24.0",
|
|
20
20
|
"chokidar": "^4.0.0",
|
|
21
21
|
"ws": "^8.18.0",
|