@d-zero/print 2.1.4 → 2.2.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 CHANGED
@@ -4,14 +4,14 @@
4
4
 
5
5
  - Puppeteerを実行してページのスクリーンショットを撮影します
6
6
  - `png`、`pdf`、`note`の3つの形式で出力できます
7
- - スクリーンショットはデスクトップとモバイルの2つのサイズでそれぞれ撮影します
7
+ - 複数のデバイスサイズでスクリーンショットを撮影可能(7種類のプリセット + カスタム設定)
8
+ - レスポンシブデザインの検証に最適
8
9
 
9
10
  ## CLI
10
11
 
11
12
  ```sh
12
- npx @d-zero/print -f <listfile> [--type <png|pdf|note>] [--limit <number>] [--debug]
13
-
14
- npx @d-zero/print <url>... [--type <png|pdf|note>] [--limit <number>] [--debug]
13
+ npx @d-zero/print -f <listfile> [options]
14
+ npx @d-zero/print <url>... [options]
15
15
  ```
16
16
 
17
17
  リストをファイルから読み込むか、URLを直接指定して実行します。
@@ -20,14 +20,42 @@ npx @d-zero/print <url>... [--type <png|pdf|note>] [--limit <number>] [--debug]
20
20
 
21
21
  ### オプション
22
22
 
23
- - `-f, --file <filepath>`: URLリストを持つファイルのパス
23
+ - `-f, --listfile <file>`: URLリストを持つファイルのパス
24
24
  - `<url>`: 対象のURL(複数指定可能)
25
- - `-t, --type <png|pdf|note>`: 出力形式(デフォルト: png)
26
- - `png`: PNG画像(モバイルとデスクトップの2つが生成されます)
25
+ - `-t, --type <type>`: 出力形式(デフォルト: png)
26
+ - `png`: PNG画像(指定されたデバイスサイズで生成されます)
27
27
  - `pdf`: PDFファイル(ブラウザの印刷機能を使用、Print CSSが適用されます)
28
28
  - `note`: PNG画像のスクリーンショットに対してメモ欄付きのPDFファイルが生成されます
29
+ - `-d, --devices <devices>`: デバイスプリセット(カンマ区切り、デフォルト: desktop-compact,mobile)
29
30
  - `--limit <number>`: 並列実行数の上限(デフォルト: 10)
30
31
  - `--debug`: デバッグモード(デフォルト: false)
32
+ - `--verbose`: 詳細ログモード(デフォルト: false)
33
+
34
+ ### 利用可能なデバイスプリセット
35
+
36
+ - `desktop`: 1400px幅
37
+ - `tablet`: 768px幅
38
+ - `mobile`: 375px幅(2倍解像度)
39
+ - `desktop-hd`: 1920px幅
40
+ - `desktop-compact`: 1280px幅
41
+ - `mobile-large`: 414px幅(3倍解像度)
42
+ - `mobile-small`: 320px幅(2倍解像度)
43
+
44
+ ### 使用例
45
+
46
+ ```sh
47
+ # デフォルトデバイス(desktop-compact, mobile)
48
+ npx @d-zero/print https://example.com
49
+
50
+ # カスタムデバイス指定
51
+ npx @d-zero/print https://example.com --devices desktop,tablet,mobile
52
+
53
+ # PDF出力
54
+ npx @d-zero/print -f urls.txt --type pdf
55
+
56
+ # ファイルから読み込み + デバイス指定
57
+ npx @d-zero/print -f urls.txt --devices desktop,mobile
58
+ ```
31
59
 
32
60
  #### URLリストのファイルフォーマット
33
61
 
package/dist/cli.js CHANGED
@@ -1,27 +1,48 @@
1
1
  #!/usr/bin/env node
2
- import { createCLI, parseCommonOptions } from '@d-zero/cli-core';
2
+ import { createCLI, parseCommonOptions, parseList } from '@d-zero/cli-core';
3
+ import { parseDevicesOption } from '@d-zero/puppeteer-page-scan';
3
4
  import { print } from './print-main-process.js';
4
5
  import { readConfig } from './read-config.js';
5
6
  const { options, args, hasConfigFile } = createCLI({
6
7
  aliases: {
7
8
  f: 'listfile',
8
9
  t: 'type',
10
+ d: 'devices',
9
11
  },
10
12
  usage: [
11
13
  'Usage:',
12
- '\tprint -f <listfile> [--type <png|pdf|note>] [--limit <number>] [--debug]',
13
- '\tprint <url>... [--type <png|pdf|note>] [--limit <number>] [--debug]',
14
+ '\tprint -f <listfile> [options]',
15
+ '\tprint <url>... [options]',
16
+ '',
17
+ 'Options:',
18
+ '\t-f, --listfile <file> File containing URLs to print',
19
+ '\t-t, --type <type> Output type: png|pdf|note (default: png)',
20
+ '\t-d, --devices <devices> Device presets (comma-separated, default: desktop-compact,mobile)',
21
+ '\t--limit <number> Limit concurrent processes',
22
+ '\t--debug Enable debug mode',
23
+ '\t--verbose Enable verbose logging',
24
+ '',
25
+ 'Available device presets:',
26
+ '\tdesktop, tablet, mobile, desktop-hd, desktop-compact, mobile-large, mobile-small',
27
+ '',
28
+ 'Examples:',
29
+ '\tprint https://example.com',
30
+ '\tprint -f urls.txt --type pdf',
31
+ '\tprint https://example.com --devices desktop,mobile',
14
32
  ],
15
33
  parseArgs: (cli) => ({
16
34
  ...parseCommonOptions(cli),
17
35
  listfile: cli.listfile,
18
36
  type: cli.type,
37
+ devices: cli.devices,
19
38
  }),
20
39
  validateArgs: (options, cli) => {
21
40
  return !!(options.listfile?.length || cli._.length > 0);
22
41
  },
23
42
  });
24
43
  const type = options.type === 'note' ? 'note' : options.type === 'pdf' ? 'pdf' : 'png';
44
+ const deviceNames = options.devices ? parseList(options.devices) : undefined;
45
+ const devices = parseDevicesOption(deviceNames);
25
46
  if (hasConfigFile) {
26
47
  const { urlList, hooks } = await readConfig(options.listfile);
27
48
  await print(urlList, {
@@ -30,6 +51,7 @@ if (hasConfigFile) {
30
51
  debug: options.debug,
31
52
  verbose: options.verbose,
32
53
  hooks,
54
+ devices,
33
55
  });
34
56
  process.exit(0);
35
57
  }
@@ -39,6 +61,7 @@ if (args.length > 0) {
39
61
  limit: options.limit,
40
62
  verbose: options.verbose,
41
63
  debug: options.debug,
64
+ devices,
42
65
  });
43
66
  process.exit(0);
44
67
  }
@@ -1,4 +1,4 @@
1
- import type { PageHook } from '@d-zero/puppeteer-page-scan';
1
+ import type { PageHook, Sizes } from '@d-zero/puppeteer-page-scan';
2
2
  import type { Page } from 'puppeteer';
3
3
  /**
4
4
  *
@@ -7,5 +7,6 @@ import type { Page } from 'puppeteer';
7
7
  * @param filePath
8
8
  * @param update
9
9
  * @param hooks
10
+ * @param devices
10
11
  */
11
- export declare function printPdf(page: Page, url: string, filePath: string, update: (log: string) => void, hooks?: readonly PageHook[]): Promise<void>;
12
+ export declare function printPdf(page: Page, url: string, filePath: string, update: (log: string) => void, hooks?: readonly PageHook[], devices?: Sizes): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { beforePageScan, pageScanListener } from '@d-zero/puppeteer-page-scan';
1
+ import { beforePageScan, pageScanListener, devicePresets, } from '@d-zero/puppeteer-page-scan';
2
2
  /**
3
3
  *
4
4
  * @param page
@@ -6,11 +6,28 @@ import { beforePageScan, pageScanListener } from '@d-zero/puppeteer-page-scan';
6
6
  * @param filePath
7
7
  * @param update
8
8
  * @param hooks
9
+ * @param devices
9
10
  */
10
- export async function printPdf(page, url, filePath, update, hooks) {
11
+ export async function printPdf(page, url, filePath, update, hooks, devices) {
12
+ // Use the first desktop device or fallback to desktop preset
13
+ const defaultWidth = devicePresets.desktop.width;
14
+ let pdfWidth = defaultWidth;
15
+ if (devices) {
16
+ // Find the first desktop-like device (width >= 1000) or use the first device
17
+ const desktopDevice = Object.values(devices).find((device) => device.width >= 1000);
18
+ if (desktopDevice) {
19
+ pdfWidth = desktopDevice.width;
20
+ }
21
+ else if (Object.values(devices).length > 0) {
22
+ const firstDevice = Object.values(devices)[0];
23
+ if (firstDevice) {
24
+ pdfWidth = firstDevice.width;
25
+ }
26
+ }
27
+ }
11
28
  await beforePageScan(page, url, {
12
29
  name: 'pdf',
13
- width: 1400,
30
+ width: pdfWidth,
14
31
  listener: pageScanListener(update),
15
32
  hooks,
16
33
  });
@@ -1,3 +1,4 @@
1
+ import type { Sizes } from '@d-zero/puppeteer-page-scan';
1
2
  import type { PageHook } from '@d-zero/puppeteer-screenshot';
2
3
  import type { Page } from 'puppeteer';
3
4
  /**
@@ -8,5 +9,6 @@ import type { Page } from 'puppeteer';
8
9
  * @param filePath
9
10
  * @param update
10
11
  * @param hooks
12
+ * @param devices
11
13
  */
12
- export declare function printPng(page: Page, url: string, fileId: string, filePath: string, update: (log: string) => void, hooks?: readonly PageHook[]): Promise<Record<string, import("@d-zero/puppeteer-screenshot").Screenshot>>;
14
+ export declare function printPng(page: Page, url: string, fileId: string, filePath: string, update: (log: string) => void, hooks?: readonly PageHook[], devices?: Sizes): Promise<Record<string, import("@d-zero/puppeteer-screenshot").Screenshot>>;
@@ -1,3 +1,4 @@
1
+ import { devicePresets } from '@d-zero/puppeteer-page-scan';
1
2
  import { screenshot, screenshotListener } from '@d-zero/puppeteer-screenshot';
2
3
  /**
3
4
  *
@@ -7,20 +8,17 @@ import { screenshot, screenshotListener } from '@d-zero/puppeteer-screenshot';
7
8
  * @param filePath
8
9
  * @param update
9
10
  * @param hooks
11
+ * @param devices
10
12
  */
11
- export function printPng(page, url, fileId, filePath, update, hooks) {
13
+ export function printPng(page, url, fileId, filePath, update, hooks, devices) {
14
+ const defaultSizes = {
15
+ 'desktop-compact': devicePresets['desktop-compact'],
16
+ mobile: devicePresets.mobile,
17
+ };
12
18
  return screenshot(page, url, {
13
19
  id: fileId,
14
20
  path: filePath,
15
- sizes: {
16
- desktop: {
17
- width: 1280,
18
- },
19
- mobile: {
20
- width: 375,
21
- resolution: 2,
22
- },
23
- },
21
+ sizes: devices ?? defaultSizes,
24
22
  listener: screenshotListener(update),
25
23
  hooks,
26
24
  });
@@ -1,7 +1,8 @@
1
1
  import type { PrintType } from './types.js';
2
- import type { PageHook } from '@d-zero/puppeteer-page-scan';
2
+ import type { PageHook, Sizes } from '@d-zero/puppeteer-page-scan';
3
3
  export type ChildProcessParams = {
4
4
  dir: string;
5
5
  type: PrintType;
6
6
  hooks?: readonly PageHook[];
7
+ devices?: Sizes;
7
8
  };
@@ -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 } = param;
7
+ const { dir, type, hooks, devices } = 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);
14
+ await printPdf(page, url, filePath, logger, hooks, devices);
15
15
  logger('🔚 Closing');
16
16
  return;
17
17
  }
18
- const result = await printPng(page, url, id, filePath, logger, hooks);
18
+ const result = await printPng(page, url, id, filePath, logger, hooks, devices);
19
19
  if (type === 'png') {
20
20
  logger('🔚 Closing');
21
21
  return;
@@ -1,5 +1,5 @@
1
1
  import type { PrintType } from './types.js';
2
- import type { PageHook } from '@d-zero/puppeteer-page-scan';
2
+ import type { PageHook, Sizes } from '@d-zero/puppeteer-page-scan';
3
3
  import type { LaunchOptions } from 'puppeteer';
4
4
  export interface PrintOptions {
5
5
  readonly type?: PrintType;
@@ -7,6 +7,7 @@ export interface PrintOptions {
7
7
  readonly debug?: boolean;
8
8
  readonly verbose?: boolean;
9
9
  readonly hooks?: readonly PageHook[];
10
+ readonly devices?: Sizes;
10
11
  }
11
12
  /**
12
13
  *
@@ -23,6 +23,7 @@ export async function print(urlList, options) {
23
23
  dir,
24
24
  type,
25
25
  hooks: options?.hooks,
26
+ devices: options?.devices,
26
27
  }, {
27
28
  ...options,
28
29
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-zero/print",
3
- "version": "2.1.4",
3
+ "version": "2.2.0",
4
4
  "description": "Print web pages to PDF or image files.",
5
5
  "author": "D-ZERO",
6
6
  "license": "MIT",
@@ -26,16 +26,16 @@
26
26
  "dependencies": {
27
27
  "@d-zero/cli-core": "1.1.1",
28
28
  "@d-zero/html-distiller": "2.0.1",
29
- "@d-zero/puppeteer-dealer": "0.5.3",
30
- "@d-zero/puppeteer-page-scan": "4.0.4",
31
- "@d-zero/puppeteer-screenshot": "3.1.3",
29
+ "@d-zero/puppeteer-dealer": "0.5.4",
30
+ "@d-zero/puppeteer-page-scan": "4.1.0",
31
+ "@d-zero/puppeteer-screenshot": "3.1.4",
32
32
  "@d-zero/readtext": "1.1.8",
33
33
  "@d-zero/shared": "0.9.2",
34
34
  "ansi-colors": "4.1.3",
35
35
  "dayjs": "1.11.18",
36
36
  "front-matter": "4.0.2",
37
37
  "minimist": "1.2.8",
38
- "puppeteer": "24.17.1"
38
+ "puppeteer": "24.18.0"
39
39
  },
40
- "gitHead": "6fa0fd190c54351762a70039cd8dfcafc51caa0b"
40
+ "gitHead": "8081edac801400fed7c0b7ebeccc0ce66ccfe131"
41
41
  }