@d-zero/print 2.4.8 → 2.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/README.md +12 -0
- package/dist/cli.js +10 -0
- package/dist/modules/print-pdf-with-note.js +3 -3
- package/dist/modules/print-pdf.d.ts +2 -1
- package/dist/modules/print-pdf.js +3 -1
- package/dist/modules/print-png.d.ts +2 -1
- package/dist/modules/print-png.js +3 -1
- package/dist/print-child-process.d.ts +1 -0
- package/dist/print-child-process.js +3 -3
- package/dist/print-main-process.d.ts +1 -0
- package/dist/print-main-process.js +6 -0
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ npx @d-zero/print <url>... [options]
|
|
|
20
20
|
|
|
21
21
|
### オプション
|
|
22
22
|
|
|
23
|
+
- `-v, --version`: バージョンを表示
|
|
23
24
|
- `-f, --listfile <file>`: URLリストを持つファイルのパス
|
|
24
25
|
- `<url>`: 対象のURL(複数指定可能)
|
|
25
26
|
- `-t, --type <type>`: 出力形式(デフォルト: png)
|
|
@@ -27,7 +28,14 @@ npx @d-zero/print <url>... [options]
|
|
|
27
28
|
- `pdf`: PDFファイル(ブラウザの印刷機能を使用、Print CSSが適用されます)
|
|
28
29
|
- `note`: PNG画像のスクリーンショットに対してメモ欄付きのPDFファイルが生成されます
|
|
29
30
|
- `-d, --devices <devices>`: デバイスプリセット(カンマ区切り、デフォルト: desktop-compact,mobile)
|
|
31
|
+
- `-T, --timeout <ms>`: リクエストタイムアウト(ミリ秒、デフォルト: 30000)
|
|
32
|
+
- `-o, --open-disclosures`: キャプチャ前にすべての`<details>`要素を開き、すべての`button[aria-expanded="false"]`要素をクリックします
|
|
33
|
+
- 新しい要素が見つからなくなるまで繰り返し処理(最大1000回、各イテレーション後500ms待機)
|
|
34
|
+
- ネストされた要素や動的に生成される要素にも対応
|
|
35
|
+
- 最大イテレーション数に達した場合はエラーで終了
|
|
30
36
|
- `--limit <number>`: 並列実行数の上限(デフォルト: 10)
|
|
37
|
+
- `--interval <ms>`: 並列実行間の間隔(デフォルト: なし)
|
|
38
|
+
- 数値または"min-max"形式でランダム範囲を指定可能
|
|
31
39
|
- `--debug`: デバッグモード(デフォルト: false)
|
|
32
40
|
- `--verbose`: 詳細ログモード(デフォルト: false)
|
|
33
41
|
|
|
@@ -55,6 +63,10 @@ npx @d-zero/print -f urls.txt --type pdf
|
|
|
55
63
|
|
|
56
64
|
# ファイルから読み込み + デバイス指定
|
|
57
65
|
npx @d-zero/print -f urls.txt --devices desktop,mobile
|
|
66
|
+
|
|
67
|
+
# disclosure要素を展開してキャプチャ
|
|
68
|
+
npx @d-zero/print https://example.com --open-disclosures
|
|
69
|
+
npx @d-zero/print https://example.com -o
|
|
58
70
|
```
|
|
59
71
|
|
|
60
72
|
#### URLリストのファイルフォーマット
|
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
2
3
|
import { createCLI, parseCommonOptions, parseList } from '@d-zero/cli-core';
|
|
3
4
|
import { parseDevicesOption } from '@d-zero/puppeteer-page-scan';
|
|
4
5
|
import { print } from './print-main-process.js';
|
|
5
6
|
import { readConfig } from './read-config.js';
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const pkg = require('../package.json');
|
|
6
9
|
const { options, args, hasConfigFile } = createCLI({
|
|
10
|
+
name: pkg.name,
|
|
11
|
+
version: pkg.version,
|
|
7
12
|
aliases: {
|
|
8
13
|
f: 'listfile',
|
|
9
14
|
t: 'type',
|
|
10
15
|
d: 'devices',
|
|
11
16
|
T: 'timeout',
|
|
17
|
+
o: 'openDisclosures',
|
|
12
18
|
},
|
|
13
19
|
usage: [
|
|
14
20
|
'Usage:',
|
|
@@ -20,6 +26,7 @@ const { options, args, hasConfigFile } = createCLI({
|
|
|
20
26
|
'\t-t, --type <type> Output type: png|pdf|note (default: png)',
|
|
21
27
|
'\t-d, --devices <devices> Device presets (comma-separated, default: desktop-compact,mobile)',
|
|
22
28
|
'\t-T, --timeout <ms> Request timeout in milliseconds (default: 30000)',
|
|
29
|
+
'\t-o, --open-disclosures Open all <details> and aria-expanded elements before capture',
|
|
23
30
|
'\t--limit <number> Limit concurrent processes',
|
|
24
31
|
'\t--interval <ms> Interval between parallel executions (default: none)',
|
|
25
32
|
'\t Format: number or "min-max" for random range',
|
|
@@ -40,6 +47,7 @@ const { options, args, hasConfigFile } = createCLI({
|
|
|
40
47
|
type: cli.type,
|
|
41
48
|
devices: cli.devices,
|
|
42
49
|
timeout: cli.timeout ? Number(cli.timeout) : undefined,
|
|
50
|
+
openDisclosures: cli['open-disclosures'] === true || cli.o === true ? true : undefined,
|
|
43
51
|
}),
|
|
44
52
|
validateArgs: (options, cli) => {
|
|
45
53
|
return !!(options.listfile?.length || cli._.length > 0);
|
|
@@ -59,6 +67,7 @@ if (hasConfigFile) {
|
|
|
59
67
|
devices,
|
|
60
68
|
timeout: options.timeout,
|
|
61
69
|
interval: options.interval,
|
|
70
|
+
openDisclosures: options.openDisclosures,
|
|
62
71
|
});
|
|
63
72
|
process.exit(0);
|
|
64
73
|
}
|
|
@@ -71,6 +80,7 @@ if (args.length > 0) {
|
|
|
71
80
|
devices,
|
|
72
81
|
timeout: options.timeout,
|
|
73
82
|
interval: options.interval,
|
|
83
|
+
openDisclosures: options.openDisclosures,
|
|
74
84
|
});
|
|
75
85
|
process.exit(0);
|
|
76
86
|
}
|
|
@@ -10,7 +10,7 @@ import dayjs from 'dayjs';
|
|
|
10
10
|
*/
|
|
11
11
|
export async function printPdfWithNote(page, { id, filePath, url, title }) {
|
|
12
12
|
if (!filePath) {
|
|
13
|
-
throw new Error(`No file path (ID: ${id}): ${url}`);
|
|
13
|
+
throw new Error(`No file path (ID: "${id}"): ${url}`);
|
|
14
14
|
}
|
|
15
15
|
const datetime = dayjs().format('YYYY-MM-DD HH:mm');
|
|
16
16
|
await page.evaluate(() => {
|
|
@@ -37,7 +37,7 @@ export async function printPdfWithNote(page, { id, filePath, url, title }) {
|
|
|
37
37
|
<div style="font-size: 0.6em">Printed: ${datetime}</div>
|
|
38
38
|
</div>
|
|
39
39
|
<div>
|
|
40
|
-
<div style="font-size: 3mm; margin-bottom: 1mm; text-align: right;">[
|
|
40
|
+
<div style="font-size: 3mm; margin-bottom: 1mm; text-align: right;">[${id}]</div>
|
|
41
41
|
<div style="text-align: right; background-color: #000; color: #fff;">Note:</div>
|
|
42
42
|
</div>
|
|
43
43
|
</div>
|
|
@@ -45,7 +45,7 @@ export async function printPdfWithNote(page, { id, filePath, url, title }) {
|
|
|
45
45
|
footerTemplate: `
|
|
46
46
|
<div style="font-size: 2mm; width: 100%; display: flex; justify-content: space-between; margin: 0 1cm; font-family: monospace;">
|
|
47
47
|
<div>
|
|
48
|
-
<span>[
|
|
48
|
+
<span>[${id}] ${url}</span>
|
|
49
49
|
</div>
|
|
50
50
|
<div>
|
|
51
51
|
<span class="pageNumber"></span>/<span class="totalPages"></span>
|
|
@@ -9,5 +9,6 @@ import type { Page } from 'puppeteer';
|
|
|
9
9
|
* @param hooks
|
|
10
10
|
* @param devices
|
|
11
11
|
* @param timeout
|
|
12
|
+
* @param openDisclosures
|
|
12
13
|
*/
|
|
13
|
-
export declare function printPdf(page: Page, url: string, filePath: string, update: (log: string) => void, hooks?: readonly PageHook[], devices?: Sizes, timeout?: number): Promise<void>;
|
|
14
|
+
export declare function printPdf(page: Page, url: string, filePath: string, update: (log: string) => void, hooks?: readonly PageHook[], devices?: Sizes, timeout?: number, openDisclosures?: boolean): Promise<void>;
|
|
@@ -8,8 +8,9 @@ import { beforePageScan, pageScanListener, devicePresets, } from '@d-zero/puppet
|
|
|
8
8
|
* @param hooks
|
|
9
9
|
* @param devices
|
|
10
10
|
* @param timeout
|
|
11
|
+
* @param openDisclosures
|
|
11
12
|
*/
|
|
12
|
-
export async function printPdf(page, url, filePath, update, hooks, devices, timeout) {
|
|
13
|
+
export async function printPdf(page, url, filePath, update, hooks, devices, timeout, openDisclosures) {
|
|
13
14
|
// Use the first desktop device or fallback to desktop preset
|
|
14
15
|
const defaultWidth = devicePresets.desktop.width;
|
|
15
16
|
let pdfWidth = defaultWidth;
|
|
@@ -32,6 +33,7 @@ export async function printPdf(page, url, filePath, update, hooks, devices, time
|
|
|
32
33
|
listener: pageScanListener(update),
|
|
33
34
|
hooks,
|
|
34
35
|
timeout,
|
|
36
|
+
openDisclosures,
|
|
35
37
|
});
|
|
36
38
|
update('📄 Save as PDF');
|
|
37
39
|
await page.pdf({
|
|
@@ -11,5 +11,6 @@ import type { Page } from 'puppeteer';
|
|
|
11
11
|
* @param hooks
|
|
12
12
|
* @param devices
|
|
13
13
|
* @param timeout
|
|
14
|
+
* @param openDisclosures
|
|
14
15
|
*/
|
|
15
|
-
export declare function printPng(page: Page, url: string, fileId: string, filePath: string, update: (log: string) => void, hooks?: readonly PageHook[], devices?: Sizes, timeout?: number): Promise<Record<string, import("@d-zero/puppeteer-screenshot").Screenshot>>;
|
|
16
|
+
export declare function printPng(page: Page, url: string, fileId: string, filePath: string, update: (log: string) => void, hooks?: readonly PageHook[], devices?: Sizes, timeout?: number, openDisclosures?: boolean): Promise<Record<string, import("@d-zero/puppeteer-screenshot").Screenshot>>;
|
|
@@ -10,8 +10,9 @@ import { screenshot, screenshotListener } from '@d-zero/puppeteer-screenshot';
|
|
|
10
10
|
* @param hooks
|
|
11
11
|
* @param devices
|
|
12
12
|
* @param timeout
|
|
13
|
+
* @param openDisclosures
|
|
13
14
|
*/
|
|
14
|
-
export function printPng(page, url, fileId, filePath, update, hooks, devices, timeout) {
|
|
15
|
+
export function printPng(page, url, fileId, filePath, update, hooks, devices, timeout, openDisclosures) {
|
|
15
16
|
const defaultSizes = {
|
|
16
17
|
'desktop-compact': devicePresets['desktop-compact'],
|
|
17
18
|
mobile: devicePresets.mobile,
|
|
@@ -23,5 +24,6 @@ export function printPng(page, url, fileId, filePath, update, hooks, devices, ti
|
|
|
23
24
|
listener: screenshotListener(update),
|
|
24
25
|
hooks,
|
|
25
26
|
timeout,
|
|
27
|
+
openDisclosures,
|
|
26
28
|
});
|
|
27
29
|
}
|
|
@@ -4,18 +4,18 @@ import { pngToPdf } from './modules/png-to-pdf.js';
|
|
|
4
4
|
import { printPdf } from './modules/print-pdf.js';
|
|
5
5
|
import { printPng } from './modules/print-png.js';
|
|
6
6
|
createChildProcess((param) => {
|
|
7
|
-
const { dir, type, hooks, devices, timeout } = param;
|
|
7
|
+
const { dir, type, hooks, devices, timeout, openDisclosures } = param;
|
|
8
8
|
return {
|
|
9
9
|
async eachPage({ page, id, url }, logger) {
|
|
10
10
|
const ext = type === 'pdf' ? 'pdf' : 'png';
|
|
11
11
|
const fileName = `${id}.${ext}`;
|
|
12
12
|
const filePath = path.resolve(dir, fileName);
|
|
13
13
|
if (type === 'pdf') {
|
|
14
|
-
await printPdf(page, url, filePath, logger, hooks, devices, timeout);
|
|
14
|
+
await printPdf(page, url, filePath, logger, hooks, devices, timeout, openDisclosures);
|
|
15
15
|
logger('🔚 Closing');
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
const result = await printPng(page, url, id, filePath, logger, hooks, devices, timeout);
|
|
18
|
+
const result = await printPng(page, url, id, filePath, logger, hooks, devices, timeout, openDisclosures);
|
|
19
19
|
if (type === 'png') {
|
|
20
20
|
logger('🔚 Closing');
|
|
21
21
|
return;
|
|
@@ -25,9 +25,15 @@ export async function print(urlList, options) {
|
|
|
25
25
|
hooks: options?.hooks,
|
|
26
26
|
devices: options?.devices,
|
|
27
27
|
timeout: options?.timeout,
|
|
28
|
+
openDisclosures: options?.openDisclosures,
|
|
28
29
|
}, {
|
|
29
30
|
...options,
|
|
30
31
|
interval: options?.interval,
|
|
31
32
|
});
|
|
33
|
+
}, {
|
|
34
|
+
limit: options?.limit,
|
|
35
|
+
debug: options?.debug,
|
|
36
|
+
verbose: options?.verbose,
|
|
37
|
+
interval: options?.interval,
|
|
32
38
|
});
|
|
33
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/print",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Print web pages to PDF or image files.",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
"clean": "tsc --build --clean"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@d-zero/cli-core": "1.
|
|
28
|
-
"@d-zero/html-distiller": "2.0.
|
|
29
|
-
"@d-zero/puppeteer-dealer": "0.6.
|
|
30
|
-
"@d-zero/puppeteer-page-scan": "4.
|
|
31
|
-
"@d-zero/puppeteer-screenshot": "3.
|
|
32
|
-
"@d-zero/readtext": "1.1.
|
|
27
|
+
"@d-zero/cli-core": "1.3.0",
|
|
28
|
+
"@d-zero/html-distiller": "2.0.4",
|
|
29
|
+
"@d-zero/puppeteer-dealer": "0.6.5",
|
|
30
|
+
"@d-zero/puppeteer-page-scan": "4.4.0",
|
|
31
|
+
"@d-zero/puppeteer-screenshot": "3.3.0",
|
|
32
|
+
"@d-zero/readtext": "1.1.16",
|
|
33
33
|
"@d-zero/shared": "0.17.1",
|
|
34
34
|
"ansi-colors": "4.1.3",
|
|
35
35
|
"dayjs": "1.11.19",
|
|
36
36
|
"front-matter": "4.0.2",
|
|
37
37
|
"minimist": "1.2.8",
|
|
38
|
-
"puppeteer": "24.
|
|
38
|
+
"puppeteer": "24.36.0"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "e2189e6878674b8fef5fa3c121ad109c448040fe"
|
|
41
41
|
}
|