@slidev/cli 0.29.0 → 0.30.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/{build-NHXJRHBN.mjs → build-C73NWEPF.mjs} +5 -5
- package/dist/{build-VM52TR6Q.js → build-ZQJFWYTE.js} +12 -12
- package/dist/{chunk-G22DGVU7.mjs → chunk-46RYGQQC.mjs} +2 -2
- package/dist/{chunk-UEIFQWPY.mjs → chunk-4AVLCCHB.mjs} +81 -15
- package/dist/{chunk-7F2QYO53.js → chunk-7FQD47HM.js} +133 -67
- package/dist/{chunk-5BL2KALH.js → chunk-HBDQZUZK.js} +4 -4
- package/dist/{chunk-7QXPSYEZ.js → chunk-IXNT7VMK.js} +16 -16
- package/dist/{chunk-WMQA2JLO.mjs → chunk-KZHGLGA5.mjs} +1868 -1896
- package/dist/{chunk-VYBQLH2X.mjs → chunk-XMETW2MS.mjs} +12 -16
- package/dist/{chunk-OOHN7CTS.js → chunk-ZDBME6IC.js} +1962 -1989
- package/dist/cli.js +29 -28
- package/dist/cli.mjs +12 -11
- package/dist/{export-OVSG7H7S.mjs → export-OZQCWKXN.mjs} +69 -64
- package/dist/{export-GML5GDLW.js → export-SQVJKP3A.js} +69 -64
- package/dist/index.js +7 -7
- package/dist/index.mjs +4 -4
- package/package.json +17 -18
- package/template.md +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict"; function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkHBDQZUZKjs = require('./chunk-HBDQZUZK.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -8,19 +8,19 @@ var _chunk5BL2KALHjs = require('./chunk-5BL2KALH.js');
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkZDBME6ICjs = require('./chunk-ZDBME6IC.js');
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunk7FQD47HMjs = require('./chunk-7FQD47HM.js');
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var _chunkIXNT7VMKjs = require('./chunk-IXNT7VMK.js');
|
|
20
20
|
|
|
21
21
|
// node/cli.ts
|
|
22
|
-
|
|
23
|
-
var import_fast_deep_equal =
|
|
22
|
+
_chunkIXNT7VMKjs.init_cjs_shims.call(void 0, );
|
|
23
|
+
var import_fast_deep_equal = _chunkIXNT7VMKjs.__toESM.call(void 0, _chunk7FQD47HMjs.require_fast_deep_equal.call(void 0, ));
|
|
24
24
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
25
25
|
var _net = require('net'); var _net2 = _interopRequireDefault(_net);
|
|
26
26
|
var _os = require('os'); var _os2 = _interopRequireDefault(_os);
|
|
@@ -38,7 +38,7 @@ var CONFIG_RESTART_FIELDS = [
|
|
|
38
38
|
"routerMode",
|
|
39
39
|
"fonts"
|
|
40
40
|
];
|
|
41
|
-
var cli = _yargs2.default.scriptName("slidev").usage("$0 [args]").version(
|
|
41
|
+
var cli = _yargs2.default.scriptName("slidev").usage("$0 [args]").version(_chunkZDBME6ICjs.version).strict().showHelpOnFail(false).alias("h", "help").alias("v", "version");
|
|
42
42
|
cli.command("* [entry]", "Start a local server for Slidev", (args) => commonOptions(args).option("port", {
|
|
43
43
|
alias: "p",
|
|
44
44
|
type: "number",
|
|
@@ -82,9 +82,9 @@ cli.command("* [entry]", "Start a local server for Slidev", (args) => commonOpti
|
|
|
82
82
|
async function initServer() {
|
|
83
83
|
if (server)
|
|
84
84
|
await server.close();
|
|
85
|
-
const options = await
|
|
85
|
+
const options = await _chunkZDBME6ICjs.resolveOptions.call(void 0, { entry, theme }, "dev");
|
|
86
86
|
port = userPort || await findFreePort(3030);
|
|
87
|
-
server = await
|
|
87
|
+
server = await _chunkHBDQZUZKjs.createServer.call(void 0, options, {
|
|
88
88
|
server: {
|
|
89
89
|
port,
|
|
90
90
|
strictPort: true,
|
|
@@ -95,7 +95,7 @@ cli.command("* [entry]", "Start a local server for Slidev", (args) => commonOpti
|
|
|
95
95
|
logLevel: log
|
|
96
96
|
}, {
|
|
97
97
|
onDataReload(newData, data) {
|
|
98
|
-
if (!theme &&
|
|
98
|
+
if (!theme && _chunkZDBME6ICjs.resolveThemeName.call(void 0, newData.config.theme) !== _chunkZDBME6ICjs.resolveThemeName.call(void 0, data.config.theme)) {
|
|
99
99
|
console.log(_kolorist.yellow.call(void 0, "\n restarting on theme change\n"));
|
|
100
100
|
initServer();
|
|
101
101
|
} else if (CONFIG_RESTART_FIELDS.some((i) => !(0, import_fast_deep_equal.default)(newData.config[i], data.config[i]))) {
|
|
@@ -171,8 +171,8 @@ cli.command("build [entry]", "Build hostable SPA", (args) => commonOptions(args)
|
|
|
171
171
|
type: "boolean",
|
|
172
172
|
describe: "allow download as PDF"
|
|
173
173
|
}).strict().help(), async ({ entry, theme, watch, base, download, out }) => {
|
|
174
|
-
const { build } = await Promise.resolve().then(() =>
|
|
175
|
-
const options = await
|
|
174
|
+
const { build } = await Promise.resolve().then(() => _chunkIXNT7VMKjs.__toESM.call(void 0, _chunkIXNT7VMKjs.__require.call(void 0, "./build-ZQJFWYTE.js")));
|
|
175
|
+
const options = await _chunkZDBME6ICjs.resolveOptions.call(void 0, { entry, theme }, "build");
|
|
176
176
|
if (download && !options.data.config.download)
|
|
177
177
|
options.data.config.download = download;
|
|
178
178
|
printInfo(options);
|
|
@@ -185,26 +185,26 @@ cli.command("build [entry]", "Build hostable SPA", (args) => commonOptions(args)
|
|
|
185
185
|
});
|
|
186
186
|
});
|
|
187
187
|
cli.command("format [entry]", "Format the markdown file", (args) => commonOptions(args).strict().help(), async ({ entry }) => {
|
|
188
|
-
const data = await
|
|
189
|
-
|
|
190
|
-
await
|
|
188
|
+
const data = await _chunkZDBME6ICjs.fs_exports.load(entry);
|
|
189
|
+
_chunkZDBME6ICjs.fs_exports.prettify(data);
|
|
190
|
+
await _chunkZDBME6ICjs.fs_exports.save(data);
|
|
191
191
|
});
|
|
192
192
|
cli.command("theme [subcommand]", "Theme related operations", (command) => {
|
|
193
193
|
return command.command("eject", "Eject current theme into local file system", (args) => commonOptions(args).option("dir", {
|
|
194
194
|
type: "string",
|
|
195
195
|
default: "theme"
|
|
196
196
|
}), async ({ entry, dir, theme: themeInput }) => {
|
|
197
|
-
const data = await
|
|
198
|
-
const theme =
|
|
197
|
+
const data = await _chunkZDBME6ICjs.fs_exports.load(entry);
|
|
198
|
+
const theme = _chunkZDBME6ICjs.resolveThemeName.call(void 0, themeInput || data.config.theme);
|
|
199
199
|
if (theme === "none") {
|
|
200
200
|
console.error('Can not eject theme "none"');
|
|
201
201
|
process.exit(1);
|
|
202
202
|
}
|
|
203
|
-
if (
|
|
203
|
+
if (_chunkZDBME6ICjs.isPath.call(void 0, theme)) {
|
|
204
204
|
console.error("Theme is already ejected");
|
|
205
205
|
process.exit(1);
|
|
206
206
|
}
|
|
207
|
-
const roots =
|
|
207
|
+
const roots = _chunkZDBME6ICjs.getThemeRoots.call(void 0, theme, entry);
|
|
208
208
|
if (!roots.length) {
|
|
209
209
|
console.error(`Does not found theme "${theme}"`);
|
|
210
210
|
process.exit(1);
|
|
@@ -216,7 +216,7 @@ cli.command("theme [subcommand]", "Theme related operations", (command) => {
|
|
|
216
216
|
const dirPath = `./${dir}`;
|
|
217
217
|
data.slides[0].frontmatter.theme = dirPath;
|
|
218
218
|
data.slides[0].raw = null;
|
|
219
|
-
await
|
|
219
|
+
await _chunkZDBME6ICjs.fs_exports.save(data);
|
|
220
220
|
console.log(`Theme "${theme}" ejected successfully to "${dirPath}"`);
|
|
221
221
|
});
|
|
222
222
|
}, () => {
|
|
@@ -229,10 +229,10 @@ cli.command("export [entry]", "Export slides to PDF", (args) => commonOptions(ar
|
|
|
229
229
|
}).option("format", {
|
|
230
230
|
default: "pdf",
|
|
231
231
|
type: "string",
|
|
232
|
-
choices: ["pdf", "png"],
|
|
232
|
+
choices: ["pdf", "png", "md"],
|
|
233
233
|
describe: "output format"
|
|
234
234
|
}).option("timeout", {
|
|
235
|
-
default:
|
|
235
|
+
default: 500,
|
|
236
236
|
type: "number",
|
|
237
237
|
describe: "timeout for rendering each page"
|
|
238
238
|
}).option("range", {
|
|
@@ -259,20 +259,21 @@ cli.command("export [entry]", "Export slides to PDF", (args) => commonOptions(ar
|
|
|
259
259
|
}) => {
|
|
260
260
|
output = output || `${_path2.default.basename(entry, ".md")}-export`;
|
|
261
261
|
process.env.NODE_ENV = "production";
|
|
262
|
-
const { exportSlides } = await Promise.resolve().then(() =>
|
|
262
|
+
const { exportSlides } = await Promise.resolve().then(() => _chunkIXNT7VMKjs.__toESM.call(void 0, _chunkIXNT7VMKjs.__require.call(void 0, "./export-SQVJKP3A.js")));
|
|
263
263
|
const port = await findFreePort(12445);
|
|
264
|
-
const options = await
|
|
265
|
-
const server = await
|
|
264
|
+
const options = await _chunkZDBME6ICjs.resolveOptions.call(void 0, { entry, theme }, "build");
|
|
265
|
+
const server = await _chunkHBDQZUZKjs.createServer.call(void 0, options, {
|
|
266
266
|
server: { port },
|
|
267
267
|
clearScreen: false
|
|
268
268
|
});
|
|
269
269
|
await server.listen(port);
|
|
270
270
|
printInfo(options);
|
|
271
|
-
|
|
272
|
-
const width =
|
|
271
|
+
_chunkZDBME6ICjs.fs_exports.filterDisabled(options.data);
|
|
272
|
+
const width = options.data.config.canvasWidth;
|
|
273
273
|
const height = Math.round(width / options.data.config.aspectRatio);
|
|
274
274
|
output = await exportSlides({
|
|
275
275
|
port,
|
|
276
|
+
slides: options.data.slides,
|
|
276
277
|
total: options.data.slides.length,
|
|
277
278
|
range,
|
|
278
279
|
format,
|
|
@@ -305,7 +306,7 @@ function printInfo(options, port, remote) {
|
|
|
305
306
|
console.log();
|
|
306
307
|
console.log();
|
|
307
308
|
console.log(` ${_kolorist.cyan.call(void 0, "\u25CF") + _kolorist.blue.call(void 0, "\u25A0") + _kolorist.yellow.call(void 0, "\u25B2")}`);
|
|
308
|
-
console.log(`${_kolorist.bold.call(void 0, " Slidev")} ${_kolorist.blue.call(void 0, `v${
|
|
309
|
+
console.log(`${_kolorist.bold.call(void 0, " Slidev")} ${_kolorist.blue.call(void 0, `v${_chunkZDBME6ICjs.version}`)} ${_isinstalledglobally2.default ? _kolorist.yellow.call(void 0, "(global)") : ""}`);
|
|
309
310
|
console.log();
|
|
310
311
|
console.log(_kolorist.dim.call(void 0, " theme ") + (options.theme ? _kolorist.green.call(void 0, options.theme) : _kolorist.gray.call(void 0, "none")));
|
|
311
312
|
console.log(_kolorist.dim.call(void 0, " entry ") + _kolorist.dim.call(void 0, _path2.default.dirname(options.entry) + _path2.default.sep) + _path2.default.basename(options.entry));
|
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createServer
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-46RYGQQC.mjs";
|
|
4
4
|
import {
|
|
5
5
|
fs_exports,
|
|
6
6
|
getThemeRoots,
|
|
@@ -8,20 +8,20 @@ import {
|
|
|
8
8
|
resolveOptions,
|
|
9
9
|
resolveThemeName,
|
|
10
10
|
version
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-KZHGLGA5.mjs";
|
|
12
12
|
import {
|
|
13
13
|
require_fast_deep_equal
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-4AVLCCHB.mjs";
|
|
15
15
|
import {
|
|
16
16
|
__dirname,
|
|
17
17
|
__require,
|
|
18
|
-
|
|
18
|
+
__toESM,
|
|
19
19
|
init_esm_shims
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-XMETW2MS.mjs";
|
|
21
21
|
|
|
22
22
|
// node/cli.ts
|
|
23
23
|
init_esm_shims();
|
|
24
|
-
var import_fast_deep_equal =
|
|
24
|
+
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
|
25
25
|
import path from "path";
|
|
26
26
|
import net from "net";
|
|
27
27
|
import os from "os";
|
|
@@ -172,7 +172,7 @@ cli.command("build [entry]", "Build hostable SPA", (args) => commonOptions(args)
|
|
|
172
172
|
type: "boolean",
|
|
173
173
|
describe: "allow download as PDF"
|
|
174
174
|
}).strict().help(), async ({ entry, theme, watch, base, download, out }) => {
|
|
175
|
-
const { build } = await Promise.resolve().then(() =>
|
|
175
|
+
const { build } = await Promise.resolve().then(() => __toESM(__require("./build-C73NWEPF.mjs")));
|
|
176
176
|
const options = await resolveOptions({ entry, theme }, "build");
|
|
177
177
|
if (download && !options.data.config.download)
|
|
178
178
|
options.data.config.download = download;
|
|
@@ -230,10 +230,10 @@ cli.command("export [entry]", "Export slides to PDF", (args) => commonOptions(ar
|
|
|
230
230
|
}).option("format", {
|
|
231
231
|
default: "pdf",
|
|
232
232
|
type: "string",
|
|
233
|
-
choices: ["pdf", "png"],
|
|
233
|
+
choices: ["pdf", "png", "md"],
|
|
234
234
|
describe: "output format"
|
|
235
235
|
}).option("timeout", {
|
|
236
|
-
default:
|
|
236
|
+
default: 500,
|
|
237
237
|
type: "number",
|
|
238
238
|
describe: "timeout for rendering each page"
|
|
239
239
|
}).option("range", {
|
|
@@ -260,7 +260,7 @@ cli.command("export [entry]", "Export slides to PDF", (args) => commonOptions(ar
|
|
|
260
260
|
}) => {
|
|
261
261
|
output = output || `${path.basename(entry, ".md")}-export`;
|
|
262
262
|
process.env.NODE_ENV = "production";
|
|
263
|
-
const { exportSlides } = await Promise.resolve().then(() =>
|
|
263
|
+
const { exportSlides } = await Promise.resolve().then(() => __toESM(__require("./export-OZQCWKXN.mjs")));
|
|
264
264
|
const port = await findFreePort(12445);
|
|
265
265
|
const options = await resolveOptions({ entry, theme }, "build");
|
|
266
266
|
const server = await createServer(options, {
|
|
@@ -270,10 +270,11 @@ cli.command("export [entry]", "Export slides to PDF", (args) => commonOptions(ar
|
|
|
270
270
|
await server.listen(port);
|
|
271
271
|
printInfo(options);
|
|
272
272
|
fs_exports.filterDisabled(options.data);
|
|
273
|
-
const width =
|
|
273
|
+
const width = options.data.config.canvasWidth;
|
|
274
274
|
const height = Math.round(width / options.data.config.aspectRatio);
|
|
275
275
|
output = await exportSlides({
|
|
276
276
|
port,
|
|
277
|
+
slides: options.data.slides,
|
|
277
278
|
total: options.data.slides.length,
|
|
278
279
|
range,
|
|
279
280
|
format,
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
packageExists
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KZHGLGA5.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__require,
|
|
6
|
-
|
|
6
|
+
__toESM,
|
|
7
7
|
init_esm_shims
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-XMETW2MS.mjs";
|
|
9
9
|
|
|
10
10
|
// node/export.ts
|
|
11
11
|
init_esm_shims();
|
|
12
12
|
import path from "path";
|
|
13
13
|
import fs from "fs-extra";
|
|
14
|
-
import {
|
|
15
|
-
import { blue, cyan, green, yellow } from "kolorist";
|
|
14
|
+
import { blue, cyan, dim, green, yellow } from "kolorist";
|
|
16
15
|
import { Presets, SingleBar } from "cli-progress";
|
|
17
16
|
import { parseRangeString } from "@slidev/parser/core";
|
|
18
|
-
function createSlidevProgress() {
|
|
17
|
+
function createSlidevProgress(indeterminate = false) {
|
|
19
18
|
function getSpinner(n = 0) {
|
|
20
19
|
return [cyan("\u25CF"), green("\u25C6"), blue("\u25A0"), yellow("\u25B2")][n % 4];
|
|
21
20
|
}
|
|
@@ -25,7 +24,7 @@ function createSlidevProgress() {
|
|
|
25
24
|
const progress = new SingleBar({
|
|
26
25
|
clearOnComplete: true,
|
|
27
26
|
hideCursor: true,
|
|
28
|
-
format: ` {spin} ${yellow("rendering")} {bar} {value}/{total}`,
|
|
27
|
+
format: ` {spin} ${yellow("rendering")}${indeterminate ? dim(yellow("...")) : " {bar} {value}/{total}"}`,
|
|
29
28
|
linewrap: false,
|
|
30
29
|
barsize: 30
|
|
31
30
|
}, Presets.shades_grey);
|
|
@@ -54,6 +53,7 @@ async function exportSlides({
|
|
|
54
53
|
range,
|
|
55
54
|
format = "pdf",
|
|
56
55
|
output = "slides",
|
|
56
|
+
slides,
|
|
57
57
|
base = "/",
|
|
58
58
|
timeout = 500,
|
|
59
59
|
dark = false,
|
|
@@ -64,86 +64,91 @@ async function exportSlides({
|
|
|
64
64
|
}) {
|
|
65
65
|
if (!packageExists("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
|
|
67
|
+
const pages = parseRangeString(total, range);
|
|
68
|
+
const { chromium } = await Promise.resolve().then(() => __toESM(__require("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
83
|
waitUntil: "networkidle"
|
|
84
84
|
});
|
|
85
|
-
await page.waitForTimeout(timeout);
|
|
86
85
|
await page.waitForLoadState("networkidle");
|
|
87
86
|
await page.emulateMedia({ colorScheme: dark ? "dark" : "light", media: "screen" });
|
|
87
|
+
const elements = await page.locator("[data-waitfor]");
|
|
88
|
+
const count = await elements.count();
|
|
89
|
+
for (let index = 0; index < count; index++) {
|
|
90
|
+
const element = await elements.nth(index);
|
|
91
|
+
const attribute = await element.getAttribute("data-waitfor");
|
|
92
|
+
if (attribute)
|
|
93
|
+
await element.locator(attribute).waitFor();
|
|
94
|
+
}
|
|
95
|
+
const frames = await page.frames();
|
|
96
|
+
await Promise.all(frames.map((frame) => frame.waitForLoadState()));
|
|
97
|
+
await page.waitForTimeout(timeout);
|
|
98
|
+
}
|
|
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
|
+
});
|
|
88
116
|
}
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
|
|
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 fs.ensureDir(output);
|
|
125
|
+
await fs.writeFile(path.join(output, `${(i + 1).toString().padStart(2, "0")}.png`), buffer);
|
|
126
|
+
}
|
|
92
127
|
}
|
|
93
|
-
async function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
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}`);
|
|
100
139
|
}
|
|
140
|
+
if (!output.endsWith(".md"))
|
|
141
|
+
output = `${output}.md`;
|
|
142
|
+
await fs.writeFile(output, mds.join(""));
|
|
101
143
|
}
|
|
102
|
-
const pages = parseRangeString(total, range);
|
|
103
144
|
progress.start(pages.length);
|
|
104
145
|
if (format === "pdf") {
|
|
105
|
-
|
|
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 PDFDocument.create({});
|
|
126
|
-
for (const pdfBytes of buffers) {
|
|
127
|
-
const pdf = await 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 fs.writeFile(output, buffer);
|
|
146
|
+
await genPagePdf();
|
|
137
147
|
} else if (format === "png") {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
path: path.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
|
}
|
|
@@ -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
|
|
3
|
+
var _chunkZDBME6ICjs = require('./chunk-ZDBME6IC.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkIXNT7VMKjs = require('./chunk-IXNT7VMK.js');
|
|
9
9
|
|
|
10
10
|
// node/export.ts
|
|
11
|
-
|
|
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,6 +53,7 @@ async function exportSlides({
|
|
|
54
53
|
range,
|
|
55
54
|
format = "pdf",
|
|
56
55
|
output = "slides",
|
|
56
|
+
slides,
|
|
57
57
|
base = "/",
|
|
58
58
|
timeout = 500,
|
|
59
59
|
dark = false,
|
|
@@ -62,88 +62,93 @@ async function exportSlides({
|
|
|
62
62
|
height = 1080,
|
|
63
63
|
withClicks = false
|
|
64
64
|
}) {
|
|
65
|
-
if (!
|
|
65
|
+
if (!_chunkZDBME6ICjs.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
|
|
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
83
|
waitUntil: "networkidle"
|
|
84
84
|
});
|
|
85
|
-
await page.waitForTimeout(timeout);
|
|
86
85
|
await page.waitForLoadState("networkidle");
|
|
87
86
|
await page.emulateMedia({ colorScheme: dark ? "dark" : "light", media: "screen" });
|
|
87
|
+
const elements = await page.locator("[data-waitfor]");
|
|
88
|
+
const count = await elements.count();
|
|
89
|
+
for (let index = 0; index < count; index++) {
|
|
90
|
+
const element = await elements.nth(index);
|
|
91
|
+
const attribute = await element.getAttribute("data-waitfor");
|
|
92
|
+
if (attribute)
|
|
93
|
+
await element.locator(attribute).waitFor();
|
|
94
|
+
}
|
|
95
|
+
const frames = await page.frames();
|
|
96
|
+
await Promise.all(frames.map((frame) => frame.waitForLoadState()));
|
|
97
|
+
await page.waitForTimeout(timeout);
|
|
98
|
+
}
|
|
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
|
+
});
|
|
88
116
|
}
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
|
|
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);
|
|
126
|
+
}
|
|
92
127
|
}
|
|
93
|
-
async function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
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}`);
|
|
100
139
|
}
|
|
140
|
+
if (!output.endsWith(".md"))
|
|
141
|
+
output = `${output}.md`;
|
|
142
|
+
await _fsextra2.default.writeFile(output, mds.join(""));
|
|
101
143
|
}
|
|
102
|
-
const pages = _core.parseRangeString.call(void 0, total, range);
|
|
103
144
|
progress.start(pages.length);
|
|
104
145
|
if (format === "pdf") {
|
|
105
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
|
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
|
|
12
|
+
var _chunkZDBME6ICjs = require('./chunk-ZDBME6IC.js');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _chunk7FQD47HMjs = require('./chunk-7FQD47HM.js');
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var _chunkIXNT7VMKjs = require('./chunk-IXNT7VMK.js');
|
|
20
20
|
|
|
21
21
|
// node/index.ts
|
|
22
|
-
|
|
22
|
+
_chunkIXNT7VMKjs.init_cjs_shims.call(void 0, );
|
|
23
23
|
|
|
24
24
|
// node/declare.ts
|
|
25
|
-
|
|
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 =
|
|
37
|
+
exports.ViteSlidevPlugin = _chunk7FQD47HMjs.ViteSlidevPlugin; exports.createServer = _chunkHBDQZUZKjs.createServer; exports.createWindiCSSPlugin = _chunk7FQD47HMjs.createWindiCSSPlugin; exports.getCLIRoot = _chunkZDBME6ICjs.getCLIRoot; exports.getClientRoot = _chunkZDBME6ICjs.getClientRoot; exports.getThemeRoots = _chunkZDBME6ICjs.getThemeRoots; exports.getUserRoot = _chunkZDBME6ICjs.getUserRoot; exports.isPath = _chunkZDBME6ICjs.isPath; exports.parser = _chunkZDBME6ICjs.fs_exports; exports.resolveOptions = _chunkZDBME6ICjs.resolveOptions;
|