screenitshot 0.4.1 → 0.6.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/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/detector.d.ts.map +1 -1
- package/dist/detector.js +90 -0
- package/dist/detector.js.map +1 -1
- package/dist/renderer.d.ts.map +1 -1
- package/dist/renderer.js +102 -21
- package/dist/renderer.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +3 -2
- package/src/detector.ts +90 -0
- package/src/renderer.ts +117 -23
- package/src/types.ts +2 -1
package/dist/cli.js
CHANGED
|
@@ -15,8 +15,8 @@ program
|
|
|
15
15
|
.argument('<input>', 'Input file path')
|
|
16
16
|
.argument('[output]', 'Output image path')
|
|
17
17
|
.option('-f, --format <format>', 'Output image format (png, jpeg, webp)', 'png')
|
|
18
|
-
.option('-w, --width <width>', 'Viewport width', '
|
|
19
|
-
.option('-h, --height <height>', 'Viewport height', '
|
|
18
|
+
.option('-w, --width <width>', 'Viewport width', '1280')
|
|
19
|
+
.option('-h, --height <height>', 'Viewport height', '960')
|
|
20
20
|
.option('-p, --page <page>', 'Page number for multi-page documents', '1')
|
|
21
21
|
.action(async (input, output, options) => {
|
|
22
22
|
try {
|
|
@@ -29,6 +29,7 @@ program
|
|
|
29
29
|
page: parseInt(options.page),
|
|
30
30
|
});
|
|
31
31
|
console.log(`✓ Screenshot saved to ${result.path}`);
|
|
32
|
+
console.log(` Renderer: ${result.renderer}`);
|
|
32
33
|
console.log(` Format: ${result.format}`);
|
|
33
34
|
console.log(` Size: ${result.width}x${result.height}`);
|
|
34
35
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC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E,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC1C,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;YAEvC,iCAAiC;YACjC,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;gBACtB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/detector.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAoHxE"}
|
package/dist/detector.js
CHANGED
|
@@ -7,6 +7,96 @@ export async function detectFormat(filePath) {
|
|
|
7
7
|
'.pdf': 'pdf',
|
|
8
8
|
'.epub': 'epub',
|
|
9
9
|
'.docx': 'docx',
|
|
10
|
+
'.xlsx': 'xlsx',
|
|
11
|
+
'.pptx': 'pptx',
|
|
12
|
+
'.md': 'md',
|
|
13
|
+
'.markdown': 'md',
|
|
14
|
+
'.html': 'html',
|
|
15
|
+
'.htm': 'html',
|
|
16
|
+
'.csv': 'csv',
|
|
17
|
+
'.tsv': 'csv',
|
|
18
|
+
'.rtf': 'rtf',
|
|
19
|
+
'.ipynb': 'ipynb',
|
|
20
|
+
'.tex': 'tex',
|
|
21
|
+
'.latex': 'tex',
|
|
22
|
+
// Source code extensions
|
|
23
|
+
'.js': 'code',
|
|
24
|
+
'.jsx': 'code',
|
|
25
|
+
'.ts': 'code',
|
|
26
|
+
'.tsx': 'code',
|
|
27
|
+
'.py': 'code',
|
|
28
|
+
'.rb': 'code',
|
|
29
|
+
'.java': 'code',
|
|
30
|
+
'.c': 'code',
|
|
31
|
+
'.cpp': 'code',
|
|
32
|
+
'.cc': 'code',
|
|
33
|
+
'.cxx': 'code',
|
|
34
|
+
'.h': 'code',
|
|
35
|
+
'.hpp': 'code',
|
|
36
|
+
'.cs': 'code',
|
|
37
|
+
'.go': 'code',
|
|
38
|
+
'.rs': 'code',
|
|
39
|
+
'.swift': 'code',
|
|
40
|
+
'.kt': 'code',
|
|
41
|
+
'.kts': 'code',
|
|
42
|
+
'.scala': 'code',
|
|
43
|
+
'.php': 'code',
|
|
44
|
+
'.sh': 'code',
|
|
45
|
+
'.bash': 'code',
|
|
46
|
+
'.zsh': 'code',
|
|
47
|
+
'.fish': 'code',
|
|
48
|
+
'.ps1': 'code',
|
|
49
|
+
'.sql': 'code',
|
|
50
|
+
'.json': 'code',
|
|
51
|
+
'.yaml': 'code',
|
|
52
|
+
'.yml': 'code',
|
|
53
|
+
'.xml': 'code',
|
|
54
|
+
'.css': 'code',
|
|
55
|
+
'.scss': 'code',
|
|
56
|
+
'.sass': 'code',
|
|
57
|
+
'.less': 'code',
|
|
58
|
+
'.vue': 'code',
|
|
59
|
+
'.svelte': 'code',
|
|
60
|
+
'.r': 'code',
|
|
61
|
+
'.lua': 'code',
|
|
62
|
+
'.perl': 'code',
|
|
63
|
+
'.pl': 'code',
|
|
64
|
+
'.ex': 'code',
|
|
65
|
+
'.exs': 'code',
|
|
66
|
+
'.erl': 'code',
|
|
67
|
+
'.hs': 'code',
|
|
68
|
+
'.ml': 'code',
|
|
69
|
+
'.fs': 'code',
|
|
70
|
+
'.fsx': 'code',
|
|
71
|
+
'.clj': 'code',
|
|
72
|
+
'.cljs': 'code',
|
|
73
|
+
'.dart': 'code',
|
|
74
|
+
'.zig': 'code',
|
|
75
|
+
'.nim': 'code',
|
|
76
|
+
'.v': 'code',
|
|
77
|
+
'.toml': 'code',
|
|
78
|
+
'.ini': 'code',
|
|
79
|
+
'.conf': 'code',
|
|
80
|
+
'.graphql': 'code',
|
|
81
|
+
'.gql': 'code',
|
|
82
|
+
'.proto': 'code',
|
|
83
|
+
'.tf': 'code',
|
|
84
|
+
'.hcl': 'code',
|
|
85
|
+
'.asm': 'code',
|
|
86
|
+
'.s': 'code',
|
|
87
|
+
'.diff': 'code',
|
|
88
|
+
'.patch': 'code',
|
|
89
|
+
'.mdx': 'code',
|
|
90
|
+
'.astro': 'code',
|
|
91
|
+
// URL file extension
|
|
92
|
+
'.url': 'url',
|
|
93
|
+
// Mermaid diagram extension
|
|
94
|
+
'.mmd': 'mmd',
|
|
95
|
+
'.mermaid': 'mmd',
|
|
96
|
+
// GeoJSON extension
|
|
97
|
+
'.geojson': 'geojson',
|
|
98
|
+
// GPX extension
|
|
99
|
+
'.gpx': 'gpx',
|
|
10
100
|
};
|
|
11
101
|
if (ext in extensionMap) {
|
|
12
102
|
return extensionMap[ext];
|
package/dist/detector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAG/B,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,QAAgB;IACjD,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IAE5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AU,EAAE,KAAK;QACjB,oBAAoB;QACpB,UAAU,EAAE,SAAS;QACrB,gBAAgB;QAChB,MAAM,EAAE,KAAK;KACd,CAAC;IAEF,IAAI,GAAG,IAAI,YAAY,EAAE,CAAC;QACxB,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,8BAA8B;IAC9B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACxC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEjD,IAAI,KAAK,KAAK,UAAU;YAAE,OAAO,KAAK,CAAC,CAAE,OAAO;QAChD,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,IAAI;YAAE,OAAO,MAAM,CAAC,CAAE,YAAY;IAC1E,CAAC;IAAC,MAAM,CAAC;QACP,qBAAqB;IACvB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/renderer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAKlF,qBAAa,QAAQ;IACnB,OAAO,CAAC,eAAe;
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAKlF,qBAAa,QAAQ;IACnB,OAAO,CAAC,eAAe;YA4BT,kBAAkB;IAe1B,MAAM,CACV,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,gBAAgB,CAAC;CAqJ7B"}
|
package/dist/renderer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { chromium } from 'playwright';
|
|
2
2
|
import { readFile } from 'fs/promises';
|
|
3
|
-
import { resolve, dirname } from 'path';
|
|
3
|
+
import { resolve, dirname, basename } from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
6
6
|
const __dirname = dirname(__filename);
|
|
@@ -10,6 +10,19 @@ export class Renderer {
|
|
|
10
10
|
pdf: resolve(__dirname, '../templates/pdf.html'),
|
|
11
11
|
epub: resolve(__dirname, '../templates/epub.html'),
|
|
12
12
|
docx: resolve(__dirname, '../templates/docx.html'),
|
|
13
|
+
xlsx: resolve(__dirname, '../templates/xlsx.html'),
|
|
14
|
+
pptx: resolve(__dirname, '../templates/pptx.html'),
|
|
15
|
+
md: resolve(__dirname, '../templates/md.html'),
|
|
16
|
+
html: resolve(__dirname, '../templates/html.html'),
|
|
17
|
+
csv: resolve(__dirname, '../templates/csv.html'),
|
|
18
|
+
rtf: resolve(__dirname, '../templates/rtf.html'),
|
|
19
|
+
ipynb: resolve(__dirname, '../templates/ipynb.html'),
|
|
20
|
+
tex: resolve(__dirname, '../templates/tex.html'),
|
|
21
|
+
code: resolve(__dirname, '../templates/code.html'),
|
|
22
|
+
url: resolve(__dirname, '../templates/url.html'),
|
|
23
|
+
mmd: resolve(__dirname, '../templates/mmd.html'),
|
|
24
|
+
geojson: resolve(__dirname, '../templates/geojson.html'),
|
|
25
|
+
gpx: resolve(__dirname, '../templates/gpx.html'),
|
|
13
26
|
unknown: '',
|
|
14
27
|
};
|
|
15
28
|
const path = templateMap[format];
|
|
@@ -18,30 +31,65 @@ export class Renderer {
|
|
|
18
31
|
}
|
|
19
32
|
return path;
|
|
20
33
|
}
|
|
21
|
-
async injectDataIntoPage(page, fileBase64, pageNumber = 1) {
|
|
34
|
+
async injectDataIntoPage(page, fileBase64, pageNumber = 1, fileName = '') {
|
|
22
35
|
// Inject data into page globals before template loads
|
|
23
|
-
await page.addInitScript(({ fileBase64: fb64, pageNum }) => {
|
|
36
|
+
await page.addInitScript(({ fileBase64: fb64, pageNum, fName }) => {
|
|
24
37
|
// Override the placeholder values
|
|
25
38
|
globalThis.fileBase64 = fb64;
|
|
26
39
|
globalThis.pageNumber = pageNum;
|
|
27
|
-
|
|
40
|
+
globalThis.fileName = fName;
|
|
41
|
+
}, { fileBase64, pageNum: pageNumber, fName: fileName });
|
|
28
42
|
}
|
|
29
43
|
async render(inputPath, format, options = {}) {
|
|
30
|
-
const { output, format: imageFormat = 'png', width
|
|
44
|
+
const { output, format: imageFormat = 'png', width, height, page: pageNumber = 1, } = options;
|
|
45
|
+
// Use small initial viewport - content will determine final size
|
|
46
|
+
// For formats like XLSX, large viewport causes table to expand to fill it
|
|
47
|
+
const initialWidth = width || 800;
|
|
48
|
+
const initialHeight = height || 600;
|
|
31
49
|
const outputPath = output || inputPath.replace(/\.[^.]+$/, `.${imageFormat}`);
|
|
32
50
|
// Launch browser
|
|
33
51
|
const browser = await chromium.launch({
|
|
34
52
|
headless: true,
|
|
35
53
|
});
|
|
36
54
|
try {
|
|
55
|
+
// Use deviceScaleFactor for high-quality rendering (2x = retina quality)
|
|
56
|
+
const deviceScaleFactor = 2;
|
|
37
57
|
const page = await browser.newPage({
|
|
38
|
-
viewport: { width, height },
|
|
58
|
+
viewport: { width: initialWidth, height: initialHeight },
|
|
59
|
+
deviceScaleFactor,
|
|
39
60
|
});
|
|
61
|
+
// Special handling for URL format - navigate directly to the URL
|
|
62
|
+
if (format === 'url') {
|
|
63
|
+
// Read URL from file (file contains just the URL string)
|
|
64
|
+
const fileData = await readFile(inputPath);
|
|
65
|
+
const url = fileData.toString('utf-8').trim();
|
|
66
|
+
// Set a reasonable viewport for webpage screenshots
|
|
67
|
+
const webWidth = width || 1280;
|
|
68
|
+
const webHeight = height || 800;
|
|
69
|
+
await page.setViewportSize({ width: webWidth, height: webHeight });
|
|
70
|
+
// Navigate to URL and wait for network idle
|
|
71
|
+
await page.goto(url, { waitUntil: 'networkidle' });
|
|
72
|
+
// Take screenshot
|
|
73
|
+
await page.screenshot({
|
|
74
|
+
path: outputPath,
|
|
75
|
+
type: imageFormat,
|
|
76
|
+
fullPage: false,
|
|
77
|
+
});
|
|
78
|
+
await browser.close();
|
|
79
|
+
return {
|
|
80
|
+
path: outputPath,
|
|
81
|
+
format: imageFormat,
|
|
82
|
+
width: webWidth * deviceScaleFactor,
|
|
83
|
+
height: webHeight * deviceScaleFactor,
|
|
84
|
+
renderer: format,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
40
87
|
// Read and encode file as base64
|
|
41
88
|
const fileData = await readFile(inputPath);
|
|
42
89
|
const fileBase64 = fileData.toString('base64');
|
|
43
|
-
// Inject data before loading template
|
|
44
|
-
|
|
90
|
+
// Inject data before loading template (include filename for code format)
|
|
91
|
+
const fileName = basename(inputPath);
|
|
92
|
+
await this.injectDataIntoPage(page, fileBase64, pageNumber, fileName);
|
|
45
93
|
// Load template
|
|
46
94
|
const templatePath = this.getTemplatePath(format);
|
|
47
95
|
await page.goto(`file://${templatePath}`);
|
|
@@ -54,23 +102,56 @@ export class Renderer {
|
|
|
54
102
|
// Await the promise to get metadata
|
|
55
103
|
return await renderComplete;
|
|
56
104
|
});
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
105
|
+
// Check if we need to clip (for EPUB content cropping)
|
|
106
|
+
const clipX = metadata.clipX;
|
|
107
|
+
const clipY = metadata.clipY;
|
|
108
|
+
if (clipX !== undefined && clipY !== undefined) {
|
|
109
|
+
// Resize viewport to ensure clip area is fully visible
|
|
110
|
+
const requiredWidth = clipX + metadata.width;
|
|
111
|
+
const requiredHeight = clipY + metadata.height;
|
|
112
|
+
await page.setViewportSize({
|
|
113
|
+
width: Math.max(requiredWidth, initialWidth),
|
|
114
|
+
height: Math.max(requiredHeight, initialHeight),
|
|
115
|
+
});
|
|
116
|
+
// Wait for layout to stabilize
|
|
117
|
+
await page.waitForTimeout(100);
|
|
118
|
+
// Use clip to capture just the content area
|
|
119
|
+
await page.screenshot({
|
|
120
|
+
path: outputPath,
|
|
121
|
+
type: imageFormat,
|
|
122
|
+
clip: {
|
|
123
|
+
x: clipX,
|
|
124
|
+
y: clipY,
|
|
125
|
+
width: metadata.width,
|
|
126
|
+
height: metadata.height
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// Resize viewport to match actual rendered content
|
|
132
|
+
await page.setViewportSize({
|
|
133
|
+
width: metadata.width,
|
|
134
|
+
height: metadata.height,
|
|
135
|
+
});
|
|
136
|
+
// Wait for layout to stabilize after viewport resize
|
|
137
|
+
await page.waitForTimeout(100);
|
|
138
|
+
// Take screenshot at exact rendered size
|
|
139
|
+
await page.screenshot({
|
|
140
|
+
path: outputPath,
|
|
141
|
+
type: imageFormat,
|
|
142
|
+
fullPage: false,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
68
145
|
await browser.close();
|
|
146
|
+
// Actual image size is viewport * deviceScaleFactor
|
|
147
|
+
const actualWidth = metadata.width * deviceScaleFactor;
|
|
148
|
+
const actualHeight = metadata.height * deviceScaleFactor;
|
|
69
149
|
return {
|
|
70
150
|
path: outputPath,
|
|
71
151
|
format: imageFormat,
|
|
72
|
-
width:
|
|
73
|
-
height:
|
|
152
|
+
width: actualWidth,
|
|
153
|
+
height: actualHeight,
|
|
154
|
+
renderer: format,
|
|
74
155
|
};
|
|
75
156
|
}
|
|
76
157
|
catch (error) {
|
package/dist/renderer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],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,KAAK,GAAG,iBAAiB,CAAC;YACvD,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,GAAG,iBAAiB,CAAC;YAEzD,OAAO;gBACL,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,WAAW;gBACnB,KAAK,EAAE,WAAW;gBAClB,MAAM,EAAE,YAAY;gBACpB,QAAQ,EAAE,MAAM;aACjB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;YACtB,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface ScreenshotResult {
|
|
|
10
10
|
format: string;
|
|
11
11
|
width: number;
|
|
12
12
|
height: number;
|
|
13
|
+
renderer: string;
|
|
13
14
|
}
|
|
14
15
|
export interface RenderMetadata {
|
|
15
16
|
width: number;
|
|
@@ -18,5 +19,5 @@ export interface RenderMetadata {
|
|
|
18
19
|
pageNumber: number;
|
|
19
20
|
scale: number;
|
|
20
21
|
}
|
|
21
|
-
export type FileFormat = 'pdf' | 'epub' | 'docx' | 'unknown';
|
|
22
|
+
export type FileFormat = 'pdf' | 'epub' | 'docx' | 'xlsx' | 'pptx' | 'md' | 'html' | 'csv' | 'rtf' | 'ipynb' | 'tex' | 'code' | 'url' | 'mmd' | 'geojson' | 'gpx' | 'unknown';
|
|
22
23
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "screenitshot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Convert various file formats to high-quality screenshots",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "tsc && npm run copy-templates",
|
|
13
|
-
"copy-templates": "mkdir -p templates && cp ../render/dist
|
|
13
|
+
"copy-templates": "mkdir -p templates && cp ../render/dist/*.html templates/",
|
|
14
14
|
"dev": "tsc --watch",
|
|
15
15
|
"start": "npm run build && node dist/cli.js",
|
|
16
16
|
"lint": "eslint \"src/**/*.ts\"",
|
package/src/cli.ts
CHANGED
|
@@ -22,8 +22,8 @@ program
|
|
|
22
22
|
.argument('<input>', 'Input file path')
|
|
23
23
|
.argument('[output]', 'Output image path')
|
|
24
24
|
.option('-f, --format <format>', 'Output image format (png, jpeg, webp)', 'png')
|
|
25
|
-
.option('-w, --width <width>', 'Viewport width', '
|
|
26
|
-
.option('-h, --height <height>', 'Viewport height', '
|
|
25
|
+
.option('-w, --width <width>', 'Viewport width', '1280')
|
|
26
|
+
.option('-h, --height <height>', 'Viewport height', '960')
|
|
27
27
|
.option('-p, --page <page>', 'Page number for multi-page documents', '1')
|
|
28
28
|
.action(async (input: string, output: string | undefined, options: any) => {
|
|
29
29
|
try {
|
|
@@ -38,6 +38,7 @@ program
|
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
console.log(`✓ Screenshot saved to ${result.path}`);
|
|
41
|
+
console.log(` Renderer: ${result.renderer}`);
|
|
41
42
|
console.log(` Format: ${result.format}`);
|
|
42
43
|
console.log(` Size: ${result.width}x${result.height}`);
|
|
43
44
|
} catch (error) {
|
package/src/detector.ts
CHANGED
|
@@ -10,6 +10,96 @@ export async function detectFormat(filePath: string): Promise<FileFormat> {
|
|
|
10
10
|
'.pdf': 'pdf',
|
|
11
11
|
'.epub': 'epub',
|
|
12
12
|
'.docx': 'docx',
|
|
13
|
+
'.xlsx': 'xlsx',
|
|
14
|
+
'.pptx': 'pptx',
|
|
15
|
+
'.md': 'md',
|
|
16
|
+
'.markdown': 'md',
|
|
17
|
+
'.html': 'html',
|
|
18
|
+
'.htm': 'html',
|
|
19
|
+
'.csv': 'csv',
|
|
20
|
+
'.tsv': 'csv',
|
|
21
|
+
'.rtf': 'rtf',
|
|
22
|
+
'.ipynb': 'ipynb',
|
|
23
|
+
'.tex': 'tex',
|
|
24
|
+
'.latex': 'tex',
|
|
25
|
+
// Source code extensions
|
|
26
|
+
'.js': 'code',
|
|
27
|
+
'.jsx': 'code',
|
|
28
|
+
'.ts': 'code',
|
|
29
|
+
'.tsx': 'code',
|
|
30
|
+
'.py': 'code',
|
|
31
|
+
'.rb': 'code',
|
|
32
|
+
'.java': 'code',
|
|
33
|
+
'.c': 'code',
|
|
34
|
+
'.cpp': 'code',
|
|
35
|
+
'.cc': 'code',
|
|
36
|
+
'.cxx': 'code',
|
|
37
|
+
'.h': 'code',
|
|
38
|
+
'.hpp': 'code',
|
|
39
|
+
'.cs': 'code',
|
|
40
|
+
'.go': 'code',
|
|
41
|
+
'.rs': 'code',
|
|
42
|
+
'.swift': 'code',
|
|
43
|
+
'.kt': 'code',
|
|
44
|
+
'.kts': 'code',
|
|
45
|
+
'.scala': 'code',
|
|
46
|
+
'.php': 'code',
|
|
47
|
+
'.sh': 'code',
|
|
48
|
+
'.bash': 'code',
|
|
49
|
+
'.zsh': 'code',
|
|
50
|
+
'.fish': 'code',
|
|
51
|
+
'.ps1': 'code',
|
|
52
|
+
'.sql': 'code',
|
|
53
|
+
'.json': 'code',
|
|
54
|
+
'.yaml': 'code',
|
|
55
|
+
'.yml': 'code',
|
|
56
|
+
'.xml': 'code',
|
|
57
|
+
'.css': 'code',
|
|
58
|
+
'.scss': 'code',
|
|
59
|
+
'.sass': 'code',
|
|
60
|
+
'.less': 'code',
|
|
61
|
+
'.vue': 'code',
|
|
62
|
+
'.svelte': 'code',
|
|
63
|
+
'.r': 'code',
|
|
64
|
+
'.lua': 'code',
|
|
65
|
+
'.perl': 'code',
|
|
66
|
+
'.pl': 'code',
|
|
67
|
+
'.ex': 'code',
|
|
68
|
+
'.exs': 'code',
|
|
69
|
+
'.erl': 'code',
|
|
70
|
+
'.hs': 'code',
|
|
71
|
+
'.ml': 'code',
|
|
72
|
+
'.fs': 'code',
|
|
73
|
+
'.fsx': 'code',
|
|
74
|
+
'.clj': 'code',
|
|
75
|
+
'.cljs': 'code',
|
|
76
|
+
'.dart': 'code',
|
|
77
|
+
'.zig': 'code',
|
|
78
|
+
'.nim': 'code',
|
|
79
|
+
'.v': 'code',
|
|
80
|
+
'.toml': 'code',
|
|
81
|
+
'.ini': 'code',
|
|
82
|
+
'.conf': 'code',
|
|
83
|
+
'.graphql': 'code',
|
|
84
|
+
'.gql': 'code',
|
|
85
|
+
'.proto': 'code',
|
|
86
|
+
'.tf': 'code',
|
|
87
|
+
'.hcl': 'code',
|
|
88
|
+
'.asm': 'code',
|
|
89
|
+
'.s': 'code',
|
|
90
|
+
'.diff': 'code',
|
|
91
|
+
'.patch': 'code',
|
|
92
|
+
'.mdx': 'code',
|
|
93
|
+
'.astro': 'code',
|
|
94
|
+
// URL file extension
|
|
95
|
+
'.url': 'url',
|
|
96
|
+
// Mermaid diagram extension
|
|
97
|
+
'.mmd': 'mmd',
|
|
98
|
+
'.mermaid': 'mmd',
|
|
99
|
+
// GeoJSON extension
|
|
100
|
+
'.geojson': 'geojson',
|
|
101
|
+
// GPX extension
|
|
102
|
+
'.gpx': 'gpx',
|
|
13
103
|
};
|
|
14
104
|
|
|
15
105
|
if (ext in extensionMap) {
|
package/src/renderer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { chromium, type Page } from 'playwright';
|
|
2
2
|
import { readFile } from 'fs/promises';
|
|
3
|
-
import { resolve, dirname } from 'path';
|
|
3
|
+
import { resolve, dirname, basename } from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import type { FileFormat, ScreenshotOptions, ScreenshotResult } from './types.js';
|
|
6
6
|
|
|
@@ -13,6 +13,19 @@ export class Renderer {
|
|
|
13
13
|
pdf: resolve(__dirname, '../templates/pdf.html'),
|
|
14
14
|
epub: resolve(__dirname, '../templates/epub.html'),
|
|
15
15
|
docx: resolve(__dirname, '../templates/docx.html'),
|
|
16
|
+
xlsx: resolve(__dirname, '../templates/xlsx.html'),
|
|
17
|
+
pptx: resolve(__dirname, '../templates/pptx.html'),
|
|
18
|
+
md: resolve(__dirname, '../templates/md.html'),
|
|
19
|
+
html: resolve(__dirname, '../templates/html.html'),
|
|
20
|
+
csv: resolve(__dirname, '../templates/csv.html'),
|
|
21
|
+
rtf: resolve(__dirname, '../templates/rtf.html'),
|
|
22
|
+
ipynb: resolve(__dirname, '../templates/ipynb.html'),
|
|
23
|
+
tex: resolve(__dirname, '../templates/tex.html'),
|
|
24
|
+
code: resolve(__dirname, '../templates/code.html'),
|
|
25
|
+
url: resolve(__dirname, '../templates/url.html'),
|
|
26
|
+
mmd: resolve(__dirname, '../templates/mmd.html'),
|
|
27
|
+
geojson: resolve(__dirname, '../templates/geojson.html'),
|
|
28
|
+
gpx: resolve(__dirname, '../templates/gpx.html'),
|
|
16
29
|
unknown: '',
|
|
17
30
|
};
|
|
18
31
|
|
|
@@ -26,14 +39,16 @@ export class Renderer {
|
|
|
26
39
|
private async injectDataIntoPage(
|
|
27
40
|
page: Page,
|
|
28
41
|
fileBase64: string,
|
|
29
|
-
pageNumber: number = 1
|
|
42
|
+
pageNumber: number = 1,
|
|
43
|
+
fileName: string = ''
|
|
30
44
|
): Promise<void> {
|
|
31
45
|
// Inject data into page globals before template loads
|
|
32
|
-
await page.addInitScript(({ fileBase64: fb64, pageNum }: { fileBase64: string; pageNum: number }) => {
|
|
46
|
+
await page.addInitScript(({ fileBase64: fb64, pageNum, fName }: { fileBase64: string; pageNum: number; fName: string }) => {
|
|
33
47
|
// Override the placeholder values
|
|
34
48
|
(globalThis as any).fileBase64 = fb64;
|
|
35
49
|
(globalThis as any).pageNumber = pageNum;
|
|
36
|
-
|
|
50
|
+
(globalThis as any).fileName = fName;
|
|
51
|
+
}, { fileBase64, pageNum: pageNumber, fName: fileName });
|
|
37
52
|
}
|
|
38
53
|
|
|
39
54
|
async render(
|
|
@@ -44,11 +59,16 @@ export class Renderer {
|
|
|
44
59
|
const {
|
|
45
60
|
output,
|
|
46
61
|
format: imageFormat = 'png',
|
|
47
|
-
width
|
|
48
|
-
height
|
|
62
|
+
width,
|
|
63
|
+
height,
|
|
49
64
|
page: pageNumber = 1,
|
|
50
65
|
} = options;
|
|
51
66
|
|
|
67
|
+
// Use small initial viewport - content will determine final size
|
|
68
|
+
// For formats like XLSX, large viewport causes table to expand to fill it
|
|
69
|
+
const initialWidth = width || 800;
|
|
70
|
+
const initialHeight = height || 600;
|
|
71
|
+
|
|
52
72
|
const outputPath = output || inputPath.replace(/\.[^.]+$/, `.${imageFormat}`);
|
|
53
73
|
|
|
54
74
|
// Launch browser
|
|
@@ -57,16 +77,53 @@ export class Renderer {
|
|
|
57
77
|
});
|
|
58
78
|
|
|
59
79
|
try {
|
|
80
|
+
// Use deviceScaleFactor for high-quality rendering (2x = retina quality)
|
|
81
|
+
const deviceScaleFactor = 2;
|
|
82
|
+
|
|
60
83
|
const page = await browser.newPage({
|
|
61
|
-
viewport: { width, height },
|
|
84
|
+
viewport: { width: initialWidth, height: initialHeight },
|
|
85
|
+
deviceScaleFactor,
|
|
62
86
|
});
|
|
63
87
|
|
|
88
|
+
// Special handling for URL format - navigate directly to the URL
|
|
89
|
+
if (format === 'url') {
|
|
90
|
+
// Read URL from file (file contains just the URL string)
|
|
91
|
+
const fileData = await readFile(inputPath);
|
|
92
|
+
const url = fileData.toString('utf-8').trim();
|
|
93
|
+
|
|
94
|
+
// Set a reasonable viewport for webpage screenshots
|
|
95
|
+
const webWidth = width || 1280;
|
|
96
|
+
const webHeight = height || 800;
|
|
97
|
+
await page.setViewportSize({ width: webWidth, height: webHeight });
|
|
98
|
+
|
|
99
|
+
// Navigate to URL and wait for network idle
|
|
100
|
+
await page.goto(url, { waitUntil: 'networkidle' });
|
|
101
|
+
|
|
102
|
+
// Take screenshot
|
|
103
|
+
await page.screenshot({
|
|
104
|
+
path: outputPath,
|
|
105
|
+
type: imageFormat as 'png' | 'jpeg',
|
|
106
|
+
fullPage: false,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await browser.close();
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
path: outputPath,
|
|
113
|
+
format: imageFormat,
|
|
114
|
+
width: webWidth * deviceScaleFactor,
|
|
115
|
+
height: webHeight * deviceScaleFactor,
|
|
116
|
+
renderer: format,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
64
120
|
// Read and encode file as base64
|
|
65
121
|
const fileData = await readFile(inputPath);
|
|
66
122
|
const fileBase64 = fileData.toString('base64');
|
|
67
123
|
|
|
68
|
-
// Inject data before loading template
|
|
69
|
-
|
|
124
|
+
// Inject data before loading template (include filename for code format)
|
|
125
|
+
const fileName = basename(inputPath);
|
|
126
|
+
await this.injectDataIntoPage(page, fileBase64, pageNumber, fileName);
|
|
70
127
|
|
|
71
128
|
// Load template
|
|
72
129
|
const templatePath = this.getTemplatePath(format);
|
|
@@ -84,26 +141,63 @@ export class Renderer {
|
|
|
84
141
|
return await renderComplete;
|
|
85
142
|
});
|
|
86
143
|
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
144
|
+
// Check if we need to clip (for EPUB content cropping)
|
|
145
|
+
const clipX = (metadata as any).clipX;
|
|
146
|
+
const clipY = (metadata as any).clipY;
|
|
147
|
+
|
|
148
|
+
if (clipX !== undefined && clipY !== undefined) {
|
|
149
|
+
// Resize viewport to ensure clip area is fully visible
|
|
150
|
+
const requiredWidth = clipX + metadata.width;
|
|
151
|
+
const requiredHeight = clipY + metadata.height;
|
|
152
|
+
await page.setViewportSize({
|
|
153
|
+
width: Math.max(requiredWidth, initialWidth),
|
|
154
|
+
height: Math.max(requiredHeight, initialHeight),
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Wait for layout to stabilize
|
|
158
|
+
await page.waitForTimeout(100);
|
|
159
|
+
|
|
160
|
+
// Use clip to capture just the content area
|
|
161
|
+
await page.screenshot({
|
|
162
|
+
path: outputPath,
|
|
163
|
+
type: imageFormat as 'png' | 'jpeg',
|
|
164
|
+
clip: {
|
|
165
|
+
x: clipX,
|
|
166
|
+
y: clipY,
|
|
167
|
+
width: metadata.width,
|
|
168
|
+
height: metadata.height
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
} else {
|
|
172
|
+
// Resize viewport to match actual rendered content
|
|
173
|
+
await page.setViewportSize({
|
|
174
|
+
width: metadata.width,
|
|
175
|
+
height: metadata.height,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Wait for layout to stabilize after viewport resize
|
|
179
|
+
await page.waitForTimeout(100);
|
|
180
|
+
|
|
181
|
+
// Take screenshot at exact rendered size
|
|
182
|
+
await page.screenshot({
|
|
183
|
+
path: outputPath,
|
|
184
|
+
type: imageFormat as 'png' | 'jpeg',
|
|
185
|
+
fullPage: false,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
99
188
|
|
|
100
189
|
await browser.close();
|
|
101
190
|
|
|
191
|
+
// Actual image size is viewport * deviceScaleFactor
|
|
192
|
+
const actualWidth = metadata.width * deviceScaleFactor;
|
|
193
|
+
const actualHeight = metadata.height * deviceScaleFactor;
|
|
194
|
+
|
|
102
195
|
return {
|
|
103
196
|
path: outputPath,
|
|
104
197
|
format: imageFormat,
|
|
105
|
-
width:
|
|
106
|
-
height:
|
|
198
|
+
width: actualWidth,
|
|
199
|
+
height: actualHeight,
|
|
200
|
+
renderer: format,
|
|
107
201
|
};
|
|
108
202
|
} catch (error) {
|
|
109
203
|
await browser.close();
|
package/src/types.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface ScreenshotResult {
|
|
|
11
11
|
format: string;
|
|
12
12
|
width: number;
|
|
13
13
|
height: number;
|
|
14
|
+
renderer: string;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export interface RenderMetadata {
|
|
@@ -21,4 +22,4 @@ export interface RenderMetadata {
|
|
|
21
22
|
scale: number;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export type FileFormat = 'pdf' | 'epub' | 'docx' | 'unknown';
|
|
25
|
+
export type FileFormat = 'pdf' | 'epub' | 'docx' | 'xlsx' | 'pptx' | 'md' | 'html' | 'csv' | 'rtf' | 'ipynb' | 'tex' | 'code' | 'url' | 'mmd' | 'geojson' | 'gpx' | 'unknown';
|