@slidev/cli 0.29.1 → 0.30.1

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.
@@ -1,21 +1,20 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
2
 
3
- var _chunkNLYVEPP6js = require('./chunk-NLYVEPP6.js');
3
+ var _chunk3GNNQ2GUjs = require('./chunk-3GNNQ2GU.js');
4
4
 
5
5
 
6
6
 
7
7
 
8
- var _chunk7QXPSYEZjs = require('./chunk-7QXPSYEZ.js');
8
+ var _chunkIXNT7VMKjs = require('./chunk-IXNT7VMK.js');
9
9
 
10
10
  // node/export.ts
11
- _chunk7QXPSYEZjs.init_cjs_shims.call(void 0, );
11
+ _chunkIXNT7VMKjs.init_cjs_shims.call(void 0, );
12
12
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
13
13
  var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
14
- var _pdflib = require('pdf-lib');
15
14
  var _kolorist = require('kolorist');
16
15
  var _cliprogress = require('cli-progress');
17
16
  var _core = require('@slidev/parser/core');
18
- function createSlidevProgress() {
17
+ function createSlidevProgress(indeterminate = false) {
19
18
  function getSpinner(n = 0) {
20
19
  return [_kolorist.cyan.call(void 0, "\u25CF"), _kolorist.green.call(void 0, "\u25C6"), _kolorist.blue.call(void 0, "\u25A0"), _kolorist.yellow.call(void 0, "\u25B2")][n % 4];
21
20
  }
@@ -25,7 +24,7 @@ function createSlidevProgress() {
25
24
  const progress = new (0, _cliprogress.SingleBar)({
26
25
  clearOnComplete: true,
27
26
  hideCursor: true,
28
- format: ` {spin} ${_kolorist.yellow.call(void 0, "rendering")} {bar} {value}/{total}`,
27
+ format: ` {spin} ${_kolorist.yellow.call(void 0, "rendering")}${indeterminate ? _kolorist.dim.call(void 0, _kolorist.yellow.call(void 0, "...")) : " {bar} {value}/{total}"}`,
29
28
  linewrap: false,
30
29
  barsize: 30
31
30
  }, _cliprogress.Presets.shades_grey);
@@ -54,96 +53,102 @@ async function exportSlides({
54
53
  range,
55
54
  format = "pdf",
56
55
  output = "slides",
56
+ slides,
57
57
  base = "/",
58
- timeout = 500,
58
+ timeout = 3e4,
59
59
  dark = false,
60
60
  routerMode = "history",
61
61
  width = 1920,
62
62
  height = 1080,
63
63
  withClicks = false
64
64
  }) {
65
- if (!_chunkNLYVEPP6js.packageExists.call(void 0, "playwright-chromium"))
65
+ if (!_chunk3GNNQ2GUjs.packageExists.call(void 0, "playwright-chromium"))
66
66
  throw new Error("The exporting for Slidev is powered by Playwright, please installed it via `npm i -D playwright-chromium`");
67
- const { chromium } = await Promise.resolve().then(() => _chunk7QXPSYEZjs.__toModule.call(void 0, _chunk7QXPSYEZjs.__require.call(void 0, "playwright-chromium")));
67
+ const pages = _core.parseRangeString.call(void 0, total, range);
68
+ const { chromium } = await Promise.resolve().then(() => _chunkIXNT7VMKjs.__toESM.call(void 0, _chunkIXNT7VMKjs.__require.call(void 0, "playwright-chromium")));
68
69
  const browser = await chromium.launch();
69
70
  const context = await browser.newContext({
70
71
  viewport: {
71
72
  width,
72
- height
73
+ height: height * pages.length
73
74
  },
74
75
  deviceScaleFactor: 1
75
76
  });
76
77
  const page = await context.newPage();
77
- const progress = createSlidevProgress();
78
+ const progress = createSlidevProgress(true);
78
79
  async function go(no, clicks) {
79
- progress.update(no);
80
80
  const path2 = `${no}?print${withClicks ? "=clicks" : ""}${clicks ? `&clicks=${clicks}` : ""}`;
81
81
  const url = routerMode === "hash" ? `http://localhost:${port}${base}#${path2}` : `http://localhost:${port}${base}${path2}`;
82
82
  await page.goto(url, {
83
- waitUntil: "networkidle"
83
+ waitUntil: "networkidle",
84
+ timeout
84
85
  });
85
- await page.waitForTimeout(timeout);
86
86
  await page.waitForLoadState("networkidle");
87
87
  await page.emulateMedia({ colorScheme: dark ? "dark" : "light", media: "screen" });
88
+ const elements = await page.locator("[data-waitfor]");
89
+ const count = await elements.count();
90
+ for (let index = 0; index < count; index++) {
91
+ const element = await elements.nth(index);
92
+ const attribute = await element.getAttribute("data-waitfor");
93
+ if (attribute)
94
+ await element.locator(attribute).waitFor();
95
+ }
96
+ const frames = await page.frames();
97
+ await Promise.all(frames.map((frame) => frame.waitForLoadState()));
88
98
  }
89
- function getClicks(url) {
90
- var _a;
91
- return (_a = url.match(/clicks=([1-9][0-9]*)/)) == null ? void 0 : _a[1];
99
+ async function genPagePdf() {
100
+ if (!output.endsWith(".pdf"))
101
+ output = `${output}.pdf`;
102
+ await go("print");
103
+ await page.pdf({
104
+ path: output,
105
+ width,
106
+ height,
107
+ margin: {
108
+ left: 0,
109
+ top: 0,
110
+ right: 0,
111
+ bottom: 0
112
+ },
113
+ printBackground: true,
114
+ preferCSSPageSize: true
115
+ });
92
116
  }
93
- async function genPageWithClicks(fn, i, clicks) {
94
- await fn(i, clicks);
95
- if (withClicks) {
96
- await page.keyboard.press("ArrowRight", { delay: 100 });
97
- const _clicks = getClicks(page.url());
98
- if (_clicks && clicks !== _clicks)
99
- await genPageWithClicks(fn, i, _clicks);
117
+ async function genPagePng() {
118
+ await go("print");
119
+ const slides2 = await page.locator(".slide-container");
120
+ const count = await slides2.count();
121
+ for (let i = 0; i < count; i++) {
122
+ progress.update(i + 1);
123
+ const buffer = await slides2.nth(i).screenshot();
124
+ await _fsextra2.default.ensureDir(output);
125
+ await _fsextra2.default.writeFile(_path2.default.join(output, `${(i + 1).toString().padStart(2, "0")}.png`), buffer);
100
126
  }
101
127
  }
102
- const pages = _core.parseRangeString.call(void 0, total, range);
128
+ async function genPageMd(pages2, slides2) {
129
+ var _a, _b, _c;
130
+ const mds = [];
131
+ for (const i of pages2) {
132
+ const mdImg = `![${(_a = slides2[i - 1]) == null ? void 0 : _a.title}](./${output}/${i.toString().padStart(2, "0")}.png)
133
+
134
+ `;
135
+ const mdNote = ((_b = slides2[i - 1]) == null ? void 0 : _b.note) ? `${(_c = slides2[i - 1]) == null ? void 0 : _c.note}
136
+
137
+ ` : "";
138
+ mds.push(`${mdImg}${mdNote}`);
139
+ }
140
+ if (!output.endsWith(".md"))
141
+ output = `${output}.md`;
142
+ await _fsextra2.default.writeFile(output, mds.join(""));
143
+ }
103
144
  progress.start(pages.length);
104
145
  if (format === "pdf") {
105
- const buffers = [];
106
- const genPdfBuffer = async (i, clicks) => {
107
- await go(i, clicks);
108
- const pdf = await page.pdf({
109
- width,
110
- height,
111
- margin: {
112
- left: 0,
113
- top: 0,
114
- right: 0,
115
- bottom: 0
116
- },
117
- pageRanges: "1",
118
- printBackground: true,
119
- preferCSSPageSize: true
120
- });
121
- buffers.push(pdf);
122
- };
123
- for (const i of pages)
124
- await genPageWithClicks(genPdfBuffer, i);
125
- const mergedPdf = await _pdflib.PDFDocument.create({});
126
- for (const pdfBytes of buffers) {
127
- const pdf = await _pdflib.PDFDocument.load(pdfBytes);
128
- const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices());
129
- copiedPages.forEach((page2) => {
130
- mergedPdf.addPage(page2);
131
- });
132
- }
133
- const buffer = await mergedPdf.save();
134
- if (!output.endsWith(".pdf"))
135
- output = `${output}.pdf`;
136
- await _fsextra2.default.writeFile(output, buffer);
146
+ await genPagePdf();
137
147
  } else if (format === "png") {
138
- const genScreenshot = async (i, clicks) => {
139
- await go(i, clicks);
140
- await page.screenshot({
141
- omitBackground: false,
142
- path: _path2.default.join(output, `${i.toString().padStart(2, "0")}${clicks ? `-${clicks}` : ""}.png`)
143
- });
144
- };
145
- for (const i of pages)
146
- await genPageWithClicks(genScreenshot, i);
148
+ await genPagePng();
149
+ } else if (format === "md") {
150
+ await genPagePng();
151
+ await genPageMd(pages, slides);
147
152
  } else {
148
153
  throw new Error(`Unsupported exporting format "${format}"`);
149
154
  }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunk5BL2KALHjs = require('./chunk-5BL2KALH.js');
3
+ var _chunkHBDQZUZKjs = require('./chunk-HBDQZUZK.js');
4
4
 
5
5
 
6
6
 
@@ -9,20 +9,20 @@ var _chunk5BL2KALHjs = require('./chunk-5BL2KALH.js');
9
9
 
10
10
 
11
11
 
12
- var _chunkNLYVEPP6js = require('./chunk-NLYVEPP6.js');
12
+ var _chunk3GNNQ2GUjs = require('./chunk-3GNNQ2GU.js');
13
13
 
14
14
 
15
15
 
16
- var _chunk7F2QYO53js = require('./chunk-7F2QYO53.js');
16
+ var _chunk7FQD47HMjs = require('./chunk-7FQD47HM.js');
17
17
 
18
18
 
19
- var _chunk7QXPSYEZjs = require('./chunk-7QXPSYEZ.js');
19
+ var _chunkIXNT7VMKjs = require('./chunk-IXNT7VMK.js');
20
20
 
21
21
  // node/index.ts
22
- _chunk7QXPSYEZjs.init_cjs_shims.call(void 0, );
22
+ _chunkIXNT7VMKjs.init_cjs_shims.call(void 0, );
23
23
 
24
24
  // node/declare.ts
25
- _chunk7QXPSYEZjs.init_cjs_shims.call(void 0, );
25
+ _chunkIXNT7VMKjs.init_cjs_shims.call(void 0, );
26
26
 
27
27
 
28
28
 
@@ -34,4 +34,4 @@ _chunk7QXPSYEZjs.init_cjs_shims.call(void 0, );
34
34
 
35
35
 
36
36
 
37
- exports.ViteSlidevPlugin = _chunk7F2QYO53js.ViteSlidevPlugin; exports.createServer = _chunk5BL2KALHjs.createServer; exports.createWindiCSSPlugin = _chunk7F2QYO53js.createWindiCSSPlugin; exports.getCLIRoot = _chunkNLYVEPP6js.getCLIRoot; exports.getClientRoot = _chunkNLYVEPP6js.getClientRoot; exports.getThemeRoots = _chunkNLYVEPP6js.getThemeRoots; exports.getUserRoot = _chunkNLYVEPP6js.getUserRoot; exports.isPath = _chunkNLYVEPP6js.isPath; exports.parser = _chunkNLYVEPP6js.fs_exports; exports.resolveOptions = _chunkNLYVEPP6js.resolveOptions;
37
+ exports.ViteSlidevPlugin = _chunk7FQD47HMjs.ViteSlidevPlugin; exports.createServer = _chunkHBDQZUZKjs.createServer; exports.createWindiCSSPlugin = _chunk7FQD47HMjs.createWindiCSSPlugin; exports.getCLIRoot = _chunk3GNNQ2GUjs.getCLIRoot; exports.getClientRoot = _chunk3GNNQ2GUjs.getClientRoot; exports.getThemeRoots = _chunk3GNNQ2GUjs.getThemeRoots; exports.getUserRoot = _chunk3GNNQ2GUjs.getUserRoot; exports.isPath = _chunk3GNNQ2GUjs.isPath; exports.parser = _chunk3GNNQ2GUjs.fs_exports; exports.resolveOptions = _chunk3GNNQ2GUjs.resolveOptions;
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createServer
3
- } from "./chunk-G22DGVU7.mjs";
3
+ } from "./chunk-46RYGQQC.mjs";
4
4
  import {
5
5
  fs_exports,
6
6
  getCLIRoot,
@@ -9,14 +9,14 @@ import {
9
9
  getUserRoot,
10
10
  isPath,
11
11
  resolveOptions
12
- } from "./chunk-OJT6Z67R.mjs";
12
+ } from "./chunk-HJCTB5CG.mjs";
13
13
  import {
14
14
  ViteSlidevPlugin,
15
15
  createWindiCSSPlugin
16
- } from "./chunk-UEIFQWPY.mjs";
16
+ } from "./chunk-4AVLCCHB.mjs";
17
17
  import {
18
18
  init_esm_shims
19
- } from "./chunk-VYBQLH2X.mjs";
19
+ } from "./chunk-XMETW2MS.mjs";
20
20
 
21
21
  // node/index.ts
22
22
  init_esm_shims();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slidev/cli",
3
- "version": "0.29.1",
3
+ "version": "0.30.1",
4
4
  "description": "Presentation slides for developers",
5
5
  "homepage": "https://sli.dev",
6
6
  "bugs": "https://github.com/slidevjs/slidev/issues",
@@ -39,14 +39,14 @@
39
39
  }
40
40
  },
41
41
  "dependencies": {
42
- "@antfu/utils": "^0.5.0",
43
- "@iconify-json/carbon": "^1.1.2",
42
+ "@antfu/utils": "^0.5.1",
43
+ "@iconify-json/carbon": "^1.1.3",
44
44
  "@iconify-json/ph": "^1.1.1",
45
- "@slidev/client": "0.29.1",
46
- "@slidev/parser": "0.29.1",
47
- "@slidev/types": "0.29.1",
48
- "@vitejs/plugin-vue": "^2.2.4",
49
- "@vue/compiler-sfc": "^3.2.31",
45
+ "@slidev/client": "0.30.1",
46
+ "@slidev/parser": "0.30.1",
47
+ "@slidev/types": "0.30.1",
48
+ "@vitejs/plugin-vue": "^2.3.1",
49
+ "@vue/compiler-sfc": "^3.2.32",
50
50
  "cli-progress": "^3.10.0",
51
51
  "codemirror": "^5.65.2",
52
52
  "connect": "^3.7.0",
@@ -64,9 +64,8 @@
64
64
  "markdown-it-footnote": "^3.0.3",
65
65
  "markdown-it-link-attributes": "^4.0.0",
66
66
  "monaco-editor": "^0.33.0",
67
- "nanoid": "^3.3.1",
67
+ "nanoid": "^3.3.2",
68
68
  "open": "^8.4.0",
69
- "pdf-lib": "^1.17.1",
70
69
  "plantuml-encoder": "^1.4.0",
71
70
  "prismjs": "^1.27.0",
72
71
  "prompts": "^2.4.2",
@@ -74,21 +73,21 @@
74
73
  "resolve-from": "^5.0.0",
75
74
  "resolve-global": "^1.0.0",
76
75
  "shiki": "^0.10.1",
77
- "unplugin-icons": "^0.14.0",
78
- "unplugin-vue-components": "^0.18.3",
79
- "vite": "^2.8.6",
80
- "vite-plugin-md": "^0.12.3",
76
+ "unplugin-icons": "^0.14.1",
77
+ "unplugin-vue-components": "^0.19.2",
78
+ "vite": "^2.9.1",
79
+ "vite-plugin-md": "^0.12.4",
81
80
  "vite-plugin-remote-assets": "^0.2.2",
82
81
  "vite-plugin-vue-server-ref": "^0.2.4",
83
- "vite-plugin-windicss": "^1.8.3",
84
- "vue": "^3.2.31",
82
+ "vite-plugin-windicss": "^1.8.4",
83
+ "vue": "^3.2.32",
85
84
  "windicss": "^3.5.1",
86
- "yargs": "^17.4.0"
85
+ "yargs": "^17.4.1"
87
86
  },
88
87
  "devDependencies": {
89
88
  "@types/plantuml-encoder": "^1.4.0",
90
89
  "fast-deep-equal": "^3.1.3",
91
- "semver": "^7.3.5",
90
+ "semver": "^7.3.7",
92
91
  "sirv": "^2.0.2"
93
92
  },
94
93
  "engines": {