@slidev/cli 0.38.5 → 0.38.8

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.
@@ -2,7 +2,7 @@ import {
2
2
  ViteSlidevPlugin,
3
3
  getIndexHtml,
4
4
  mergeViteConfigs
5
- } from "./chunk-MDHB5JSE.mjs";
5
+ } from "./chunk-NOJBQ6MT.mjs";
6
6
  import {
7
7
  __require,
8
8
  __toESM,
@@ -648,7 +648,7 @@ function build_default(dir, opts = {}) {
648
648
 
649
649
  // node/build.ts
650
650
  import { blue, yellow } from "kolorist";
651
- async function build(options, viteConfig = {}) {
651
+ async function build(options, viteConfig = {}, args) {
652
652
  const indexPath = resolve3(options.userRoot, "index.html");
653
653
  const rawConfig = await resolveConfig({}, "build", options.entry);
654
654
  const pluginOptions = rawConfig.slidev || {};
@@ -718,14 +718,13 @@ async function build(options, viteConfig = {}) {
718
718
  await fs2.unlink(indexPath);
719
719
  }
720
720
  const outDir = resolve3(options.userRoot, config.build.outDir);
721
- const outFilename = options.data.config.exportFilename || "slidev-exported.pdf";
722
721
  await fs2.copyFile(resolve3(outDir, "index.html"), resolve3(outDir, "404.html"));
723
722
  const redirectsPath = resolve3(outDir, "_redirects");
724
723
  if (!fs2.existsSync(redirectsPath))
725
724
  await fs2.writeFile(redirectsPath, `${config.base}* ${config.base}index.html 200
726
725
  `, "utf-8");
727
726
  if ([true, "true", "auto"].includes(options.data.config.download)) {
728
- const { exportSlides } = await Promise.resolve().then(() => __toESM(__require("./export-2OSN6D4K.mjs")));
727
+ const { exportSlides, getExportOptions } = await Promise.resolve().then(() => __toESM(__require("./export-P6VFSLAQ.mjs")));
729
728
  const port = 12445;
730
729
  const app = connect();
731
730
  const server = http.createServer(app);
@@ -740,15 +739,8 @@ async function build(options, viteConfig = {}) {
740
739
  server.listen(port);
741
740
  await exportSlides({
742
741
  port,
743
- slides: options.data.slides,
744
- total: options.data.slides.length,
745
- format: "pdf",
746
- output: join3(outDir, outFilename),
747
742
  base: config.base,
748
- dark: options.data.config.colorSchema === "dark",
749
- width: options.data.config.canvasWidth,
750
- height: Math.round(options.data.config.canvasWidth / options.data.config.aspectRatio),
751
- routerMode: options.data.config.routerMode
743
+ ...getExportOptions(args, options, outDir, "slidev-exported.pdf")
752
744
  });
753
745
  server.close();
754
746
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkSJ7FI34Ejs = require('./chunk-SJ7FI34E.js');
5
+ var _chunkHHR7Q56Zjs = require('./chunk-HHR7Q56Z.js');
6
6
 
7
7
 
8
8
 
@@ -648,23 +648,23 @@ function build_default(dir, opts = {}) {
648
648
 
649
649
  // node/build.ts
650
650
  var _kolorist = require('kolorist');
651
- async function build(options, viteConfig = {}) {
651
+ async function build(options, viteConfig = {}, args) {
652
652
  const indexPath = _path.resolve.call(void 0, options.userRoot, "index.html");
653
653
  const rawConfig = await _vite.resolveConfig.call(void 0, {}, "build", options.entry);
654
654
  const pluginOptions = rawConfig.slidev || {};
655
655
  let originalIndexHTML;
656
656
  if (_fsextra2.default.existsSync(indexPath))
657
657
  originalIndexHTML = await _fsextra2.default.readFile(indexPath, "utf-8");
658
- await _fsextra2.default.writeFile(indexPath, await _chunkSJ7FI34Ejs.getIndexHtml.call(void 0, options), "utf-8");
658
+ await _fsextra2.default.writeFile(indexPath, await _chunkHHR7Q56Zjs.getIndexHtml.call(void 0, options), "utf-8");
659
659
  let config = void 0;
660
660
  try {
661
- const inlineConfig = await _chunkSJ7FI34Ejs.mergeViteConfigs.call(void 0,
661
+ const inlineConfig = await _chunkHHR7Q56Zjs.mergeViteConfigs.call(void 0,
662
662
  options,
663
663
  viteConfig,
664
664
  {
665
665
  root: options.userRoot,
666
666
  plugins: [
667
- await _chunkSJ7FI34Ejs.ViteSlidevPlugin.call(void 0, options, pluginOptions),
667
+ await _chunkHHR7Q56Zjs.ViteSlidevPlugin.call(void 0, options, pluginOptions),
668
668
  {
669
669
  name: "resolve-config",
670
670
  configResolved(_config) {
@@ -685,7 +685,7 @@ async function build(options, viteConfig = {}) {
685
685
  } else {
686
686
  console.log(_kolorist.blue.call(void 0, " building for Monaco...\n"));
687
687
  await _vite.build.call(void 0,
688
- await _chunkSJ7FI34Ejs.mergeViteConfigs.call(void 0,
688
+ await _chunkHHR7Q56Zjs.mergeViteConfigs.call(void 0,
689
689
  options,
690
690
  inlineConfig,
691
691
  {
@@ -718,14 +718,13 @@ async function build(options, viteConfig = {}) {
718
718
  await _fsextra2.default.unlink(indexPath);
719
719
  }
720
720
  const outDir = _path.resolve.call(void 0, options.userRoot, config.build.outDir);
721
- const outFilename = options.data.config.exportFilename || "slidev-exported.pdf";
722
721
  await _fsextra2.default.copyFile(_path.resolve.call(void 0, outDir, "index.html"), _path.resolve.call(void 0, outDir, "404.html"));
723
722
  const redirectsPath = _path.resolve.call(void 0, outDir, "_redirects");
724
723
  if (!_fsextra2.default.existsSync(redirectsPath))
725
724
  await _fsextra2.default.writeFile(redirectsPath, `${config.base}* ${config.base}index.html 200
726
725
  `, "utf-8");
727
726
  if ([true, "true", "auto"].includes(options.data.config.download)) {
728
- const { exportSlides } = await Promise.resolve().then(() => _chunkOVFYMGU6js.__toESM.call(void 0, _chunkOVFYMGU6js.__require.call(void 0, "./export-RNJ27D27.js")));
727
+ const { exportSlides, getExportOptions } = await Promise.resolve().then(() => _chunkOVFYMGU6js.__toESM.call(void 0, _chunkOVFYMGU6js.__require.call(void 0, "./export-2BM4EQEA.js")));
729
728
  const port = 12445;
730
729
  const app = _connect2.default.call(void 0, );
731
730
  const server = _http2.default.createServer(app);
@@ -740,15 +739,8 @@ async function build(options, viteConfig = {}) {
740
739
  server.listen(port);
741
740
  await exportSlides({
742
741
  port,
743
- slides: options.data.slides,
744
- total: options.data.slides.length,
745
- format: "pdf",
746
- output: _path.join.call(void 0, outDir, outFilename),
747
742
  base: config.base,
748
- dark: options.data.config.colorSchema === "dark",
749
- width: options.data.config.canvasWidth,
750
- height: Math.round(options.data.config.canvasWidth / options.data.config.aspectRatio),
751
- routerMode: options.data.config.routerMode
743
+ ...getExportOptions(args, options, outDir, "slidev-exported.pdf")
752
744
  });
753
745
  server.close();
754
746
  }
@@ -982,7 +982,6 @@ export default {
982
982
  _chunkOVFYMGU6js.init_cjs_shims.call(void 0, );
983
983
 
984
984
 
985
-
986
985
  function createMonacoTypesLoader() {
987
986
  return {
988
987
  name: "slidev:monaco-types-loader",
@@ -991,11 +990,12 @@ function createMonacoTypesLoader() {
991
990
  return id;
992
991
  return null;
993
992
  },
994
- load(id) {
993
+ async load(id) {
995
994
  const match = id.match(/^\/\@slidev-monaco-types\/(.*)$/);
996
995
  if (match) {
997
996
  const pkg = match[1];
998
- const info = _vite.resolvePackageData.call(void 0, pkg, process.cwd());
997
+ const { resolvePackageData } = await Promise.resolve().then(() => _chunkOVFYMGU6js.__toESM.call(void 0, _chunkOVFYMGU6js.__require.call(void 0, "vite")));
998
+ const info = resolvePackageData(pkg, process.cwd());
999
999
  if (!info)
1000
1000
  return;
1001
1001
  const typePath = info.data.types || info.data.typings;
@@ -1076,7 +1076,7 @@ var _jsbase64 = require('js-base64'); var base64 = _interopRequireWildcard(_jsba
1076
1076
 
1077
1077
 
1078
1078
  var _markdownitfootnote = require('markdown-it-footnote'); var _markdownitfootnote2 = _interopRequireDefault(_markdownitfootnote);
1079
- var _markdownittasklists = require('@hedgedoc/markdown-it-task-lists'); var _markdownittasklists2 = _interopRequireDefault(_markdownittasklists);
1079
+ var _markdownitplugins = require('@hedgedoc/markdown-it-plugins');
1080
1080
  var _shiki = require('shiki'); var Shiki = _interopRequireWildcard(_shiki);
1081
1081
  var _plantumlencoder = require('plantuml-encoder');
1082
1082
 
@@ -1387,7 +1387,7 @@ async function createMarkdownPlugin({ data: { config }, roots, mode, entry }, {
1387
1387
  }
1388
1388
  });
1389
1389
  md2.use(_markdownitfootnote2.default);
1390
- md2.use(_markdownittasklists2.default, { enabled: true, lineNumber: true, label: true });
1390
+ md2.use(_markdownitplugins.taskLists, { enabled: true, lineNumber: true, label: true });
1391
1391
  md2.use(math_plugin, KatexOptions);
1392
1392
  setups.forEach((i) => i(md2));
1393
1393
  (_a = mdOptions == null ? void 0 : mdOptions.markdownItSetup) == null ? void 0 : _a.call(mdOptions, md2);
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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
3
 
4
- var _chunkSJ7FI34Ejs = require('./chunk-SJ7FI34E.js');
4
+ var _chunkHHR7Q56Zjs = require('./chunk-HHR7Q56Z.js');
5
5
 
6
6
 
7
7
 
@@ -2426,7 +2426,7 @@ async function createServer(options, viteConfig = {}, serverOptions = {}) {
2426
2426
  const pluginOptions = rawConfig.slidev || {};
2427
2427
  process.env.EDITOR = process.env.EDITOR || "code";
2428
2428
  const server = await _vite.createServer.call(void 0,
2429
- await _chunkSJ7FI34Ejs.mergeViteConfigs.call(void 0,
2429
+ await _chunkHHR7Q56Zjs.mergeViteConfigs.call(void 0,
2430
2430
  options,
2431
2431
  viteConfig,
2432
2432
  {
@@ -2436,7 +2436,7 @@ async function createServer(options, viteConfig = {}, serverOptions = {}) {
2436
2436
  ]
2437
2437
  },
2438
2438
  plugins: [
2439
- await _chunkSJ7FI34Ejs.ViteSlidevPlugin.call(void 0, options, pluginOptions, serverOptions)
2439
+ await _chunkHHR7Q56Zjs.ViteSlidevPlugin.call(void 0, options, pluginOptions, serverOptions)
2440
2440
  ]
2441
2441
  },
2442
2442
  "serve"
@@ -2450,7 +2450,7 @@ _chunkOVFYMGU6js.init_cjs_shims.call(void 0, );
2450
2450
  var _fs = require('@slidev/parser/fs'); var parser = _interopRequireWildcard(_fs);
2451
2451
 
2452
2452
  // package.json
2453
- var version = "0.38.5";
2453
+ var version = "0.38.8";
2454
2454
 
2455
2455
  // node/themes.ts
2456
2456
  _chunkOVFYMGU6js.init_cjs_shims.call(void 0, );
@@ -983,7 +983,6 @@ export default {
983
983
  init_esm_shims();
984
984
  import { join as join6 } from "path";
985
985
  import { slash as slash3 } from "@antfu/utils";
986
- import { resolvePackageData } from "vite";
987
986
  function createMonacoTypesLoader() {
988
987
  return {
989
988
  name: "slidev:monaco-types-loader",
@@ -992,10 +991,11 @@ function createMonacoTypesLoader() {
992
991
  return id;
993
992
  return null;
994
993
  },
995
- load(id) {
994
+ async load(id) {
996
995
  const match = id.match(/^\/\@slidev-monaco-types\/(.*)$/);
997
996
  if (match) {
998
997
  const pkg = match[1];
998
+ const { resolvePackageData } = await Promise.resolve().then(() => __toESM(__require("vite")));
999
999
  const info = resolvePackageData(pkg, process.cwd());
1000
1000
  if (!info)
1001
1001
  return;
@@ -1077,7 +1077,7 @@ import * as base64 from "js-base64";
1077
1077
  import { slash as slash5 } from "@antfu/utils";
1078
1078
  import mila2 from "markdown-it-link-attributes";
1079
1079
  import mif from "markdown-it-footnote";
1080
- import mitl from "@hedgedoc/markdown-it-task-lists";
1080
+ import { taskLists } from "@hedgedoc/markdown-it-plugins";
1081
1081
  import * as Shiki from "shiki";
1082
1082
  import { encode as encode2 } from "plantuml-encoder";
1083
1083
 
@@ -1388,7 +1388,7 @@ async function createMarkdownPlugin({ data: { config }, roots, mode, entry }, {
1388
1388
  }
1389
1389
  });
1390
1390
  md2.use(mif);
1391
- md2.use(mitl, { enabled: true, lineNumber: true, label: true });
1391
+ md2.use(taskLists, { enabled: true, lineNumber: true, label: true });
1392
1392
  md2.use(math_plugin, KatexOptions);
1393
1393
  setups.forEach((i) => i(md2));
1394
1394
  (_a = mdOptions == null ? void 0 : mdOptions.markdownItSetup) == null ? void 0 : _a.call(mdOptions, md2);
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ViteSlidevPlugin,
3
3
  mergeViteConfigs
4
- } from "./chunk-MDHB5JSE.mjs";
4
+ } from "./chunk-NOJBQ6MT.mjs";
5
5
  import {
6
6
  __commonJS,
7
7
  __dirname,
@@ -2451,7 +2451,7 @@ init_esm_shims();
2451
2451
  import * as parser from "@slidev/parser/fs";
2452
2452
 
2453
2453
  // package.json
2454
- var version = "0.38.5";
2454
+ var version = "0.38.8";
2455
2455
 
2456
2456
  // node/themes.ts
2457
2457
  init_esm_shims();
package/dist/cli.js CHANGED
@@ -9,11 +9,11 @@
9
9
 
10
10
 
11
11
 
12
- var _chunkFENLKXMBjs = require('./chunk-FENLKXMB.js');
12
+ var _chunkLC4O3TXIjs = require('./chunk-LC4O3TXI.js');
13
13
 
14
14
 
15
15
 
16
- var _chunkSJ7FI34Ejs = require('./chunk-SJ7FI34E.js');
16
+ var _chunkHHR7Q56Zjs = require('./chunk-HHR7Q56Z.js');
17
17
 
18
18
 
19
19
 
@@ -22,9 +22,8 @@ var _chunkOVFYMGU6js = require('./chunk-OVFYMGU6.js');
22
22
 
23
23
  // node/cli.ts
24
24
  _chunkOVFYMGU6js.init_cjs_shims.call(void 0, );
25
- var import_fast_deep_equal = _chunkOVFYMGU6js.__toESM.call(void 0, _chunkSJ7FI34Ejs.require_fast_deep_equal.call(void 0, ));
25
+ var import_fast_deep_equal = _chunkOVFYMGU6js.__toESM.call(void 0, _chunkHHR7Q56Zjs.require_fast_deep_equal.call(void 0, ));
26
26
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
27
- var _net = require('net'); var _net2 = _interopRequireDefault(_net);
28
27
  var _os = require('os'); var _os2 = _interopRequireDefault(_os);
29
28
  var _child_process = require('child_process');
30
29
  var _readline = require('readline'); var readline = _interopRequireWildcard(_readline);
@@ -36,6 +35,7 @@ var _kolorist = require('kolorist');
36
35
  var _isinstalledglobally = require('is-installed-globally'); var _isinstalledglobally2 = _interopRequireDefault(_isinstalledglobally);
37
36
  var _parser = require('@slidev/parser');
38
37
  var _fs = require('@slidev/parser/fs');
38
+ var _getportplease = require('get-port-please');
39
39
  var CONFIG_RESTART_FIELDS = [
40
40
  "highlighter",
41
41
  "monaco",
@@ -47,14 +47,14 @@ _fs.injectPreparserExtensionLoader.call(void 0, async (headmatter, filepath) =>
47
47
  var _a;
48
48
  const addons = (_a = headmatter == null ? void 0 : headmatter.addons) != null ? _a : [];
49
49
  const roots = [
50
- _chunkFENLKXMBjs.getUserRoot.call(void 0, {}).userRoot,
51
- ..._chunkFENLKXMBjs.getAddonRoots.call(void 0, addons, ""),
52
- _chunkFENLKXMBjs.getClientRoot.call(void 0, )
50
+ _chunkLC4O3TXIjs.getUserRoot.call(void 0, {}).userRoot,
51
+ ..._chunkLC4O3TXIjs.getAddonRoots.call(void 0, addons, ""),
52
+ _chunkLC4O3TXIjs.getClientRoot.call(void 0, )
53
53
  ];
54
54
  const mergeArrays = (a, b) => a.concat(b);
55
- return await _chunkSJ7FI34Ejs.loadSetups.call(void 0, roots, "preparser.ts", { filepath, headmatter }, [], false, mergeArrays);
55
+ return await _chunkHHR7Q56Zjs.loadSetups.call(void 0, roots, "preparser.ts", { filepath, headmatter }, [], false, mergeArrays);
56
56
  });
57
- var cli = _yargs2.default.scriptName("slidev").usage("$0 [args]").version(_chunkFENLKXMBjs.version).strict().showHelpOnFail(false).alias("h", "help").alias("v", "version");
57
+ var cli = _yargs2.default.scriptName("slidev").usage("$0 [args]").version(_chunkLC4O3TXIjs.version).strict().showHelpOnFail(false).alias("h", "help").alias("v", "version");
58
58
  cli.command(
59
59
  "* [entry]",
60
60
  "Start a local server for Slidev",
@@ -105,9 +105,9 @@ cli.command(
105
105
  async function initServer() {
106
106
  if (server)
107
107
  await server.close();
108
- const options = await _chunkFENLKXMBjs.resolveOptions.call(void 0, { entry, remote, theme, inspect }, "dev");
108
+ const options = await _chunkLC4O3TXIjs.resolveOptions.call(void 0, { entry, remote, theme, inspect }, "dev");
109
109
  port = userPort || await findFreePort(3030);
110
- server = await _chunkFENLKXMBjs.createServer.call(void 0,
110
+ server = await _chunkLC4O3TXIjs.createServer.call(void 0,
111
111
  options,
112
112
  {
113
113
  server: {
@@ -121,7 +121,7 @@ cli.command(
121
121
  },
122
122
  {
123
123
  onDataReload(newData, data) {
124
- if (!theme && _chunkFENLKXMBjs.resolveThemeName.call(void 0, newData.config.theme) !== _chunkFENLKXMBjs.resolveThemeName.call(void 0, data.config.theme)) {
124
+ if (!theme && _chunkLC4O3TXIjs.resolveThemeName.call(void 0, newData.config.theme) !== _chunkLC4O3TXIjs.resolveThemeName.call(void 0, data.config.theme)) {
125
125
  console.log(_kolorist.yellow.call(void 0, "\n restarting on theme change\n"));
126
126
  initServer();
127
127
  } else if (CONFIG_RESTART_FIELDS.some((i) => !(0, import_fast_deep_equal.default)(newData.config[i], data.config[i]))) {
@@ -185,7 +185,7 @@ cli.command(
185
185
  cli.command(
186
186
  "build [entry]",
187
187
  "Build hostable SPA",
188
- (args) => commonOptions(args).option("watch", {
188
+ (args) => exportOptions(commonOptions(args)).option("watch", {
189
189
  alias: "w",
190
190
  default: false,
191
191
  describe: "build watch"
@@ -206,9 +206,10 @@ cli.command(
206
206
  type: "boolean",
207
207
  describe: "enable the inspect plugin for debugging"
208
208
  }).strict().help(),
209
- async ({ entry, theme, watch, base, download, out, inspect }) => {
210
- const { build } = await Promise.resolve().then(() => _chunkOVFYMGU6js.__toESM.call(void 0, _chunkOVFYMGU6js.__require.call(void 0, "./build-MNMMWCV6.js")));
211
- const options = await _chunkFENLKXMBjs.resolveOptions.call(void 0, { entry, theme, inspect }, "build");
209
+ async (args) => {
210
+ const { entry, theme, watch, base, download, out, inspect } = args;
211
+ const { build } = await Promise.resolve().then(() => _chunkOVFYMGU6js.__toESM.call(void 0, _chunkOVFYMGU6js.__require.call(void 0, "./build-XTITLXMQ.js")));
212
+ const options = await _chunkLC4O3TXIjs.resolveOptions.call(void 0, { entry, theme, inspect }, "build");
212
213
  if (download && !options.data.config.download)
213
214
  options.data.config.download = download;
214
215
  printInfo(options);
@@ -218,7 +219,7 @@ cli.command(
218
219
  watch: watch ? {} : void 0,
219
220
  outDir: out
220
221
  }
221
- });
222
+ }, args);
222
223
  }
223
224
  );
224
225
  cli.command(
@@ -226,9 +227,9 @@ cli.command(
226
227
  "Format the markdown file",
227
228
  (args) => commonOptions(args).strict().help(),
228
229
  async ({ entry }) => {
229
- const data = await _chunkFENLKXMBjs.parser.load(entry);
230
- _chunkFENLKXMBjs.parser.prettify(data);
231
- await _chunkFENLKXMBjs.parser.save(data);
230
+ const data = await _chunkLC4O3TXIjs.parser.load(entry);
231
+ _chunkLC4O3TXIjs.parser.prettify(data);
232
+ await _chunkLC4O3TXIjs.parser.save(data);
232
233
  }
233
234
  );
234
235
  cli.command(
@@ -243,17 +244,17 @@ cli.command(
243
244
  default: "theme"
244
245
  }),
245
246
  async ({ entry, dir, theme: themeInput }) => {
246
- const data = await _chunkFENLKXMBjs.parser.load(entry);
247
- const theme = _chunkFENLKXMBjs.resolveThemeName.call(void 0, themeInput || data.config.theme);
247
+ const data = await _chunkLC4O3TXIjs.parser.load(entry);
248
+ const theme = _chunkLC4O3TXIjs.resolveThemeName.call(void 0, themeInput || data.config.theme);
248
249
  if (theme === "none") {
249
250
  console.error('Cannot eject theme "none"');
250
251
  process.exit(1);
251
252
  }
252
- if (_chunkFENLKXMBjs.isPath.call(void 0, theme)) {
253
+ if (_chunkLC4O3TXIjs.isPath.call(void 0, theme)) {
253
254
  console.error("Theme is already ejected");
254
255
  process.exit(1);
255
256
  }
256
- const roots = _chunkFENLKXMBjs.getThemeRoots.call(void 0, theme, entry);
257
+ const roots = _chunkLC4O3TXIjs.getThemeRoots.call(void 0, theme, entry);
257
258
  if (!roots.length) {
258
259
  console.error(`Could not find theme "${theme}"`);
259
260
  process.exit(1);
@@ -265,7 +266,7 @@ cli.command(
265
266
  const dirPath = `./${dir}`;
266
267
  data.slides[0].frontmatter.theme = dirPath;
267
268
  data.slides[0].raw = null;
268
- await _chunkFENLKXMBjs.parser.save(data);
269
+ await _chunkLC4O3TXIjs.parser.save(data);
269
270
  console.log(`Theme "${theme}" ejected successfully to "${dirPath}"`);
270
271
  }
271
272
  );
@@ -278,56 +279,14 @@ cli.command(
278
279
  cli.command(
279
280
  "export [entry]",
280
281
  "Export slides to PDF",
281
- (args) => commonOptions(args).option("output", {
282
- type: "string",
283
- describe: "path to the output"
284
- }).option("format", {
285
- default: "pdf",
286
- type: "string",
287
- choices: ["pdf", "png", "md"],
288
- describe: "output format"
289
- }).option("timeout", {
290
- default: 3e4,
291
- type: "number",
292
- describe: "timeout for rendering the print page"
293
- }).option("range", {
294
- type: "string",
295
- describe: 'page ranges to export, for example "1,4-5,6"'
296
- }).option("dark", {
297
- default: false,
298
- type: "boolean",
299
- describe: "export as dark theme"
300
- }).option("with-clicks", {
301
- alias: "c",
302
- default: false,
303
- type: "boolean",
304
- describe: "export pages for every clicks"
305
- }).option("executable-path", {
306
- type: "string",
307
- describe: "executable to override playwright bundled browser"
308
- }).option("with-toc", {
309
- default: false,
310
- type: "boolean",
311
- describe: "export pages with outline"
312
- }).strict().help(),
313
- async ({
314
- entry,
315
- theme,
316
- output,
317
- format,
318
- timeout,
319
- range,
320
- dark,
321
- "with-clicks": withClicks,
322
- "executable-path": executablePath,
323
- "with-toc": withTOC
324
- }) => {
282
+ (args) => exportOptions(commonOptions(args)).strict().help(),
283
+ async (args) => {
284
+ const { entry, theme } = args;
325
285
  process.env.NODE_ENV = "production";
326
- const { exportSlides } = await Promise.resolve().then(() => _chunkOVFYMGU6js.__toESM.call(void 0, _chunkOVFYMGU6js.__require.call(void 0, "./export-RNJ27D27.js")));
286
+ const { exportSlides, getExportOptions } = await Promise.resolve().then(() => _chunkOVFYMGU6js.__toESM.call(void 0, _chunkOVFYMGU6js.__require.call(void 0, "./export-2BM4EQEA.js")));
327
287
  const port = await findFreePort(12445);
328
- const options = await _chunkFENLKXMBjs.resolveOptions.call(void 0, { entry, theme }, "export");
329
- output = output || options.data.config.exportFilename || `${_path2.default.basename(entry, ".md")}-export`;
330
- const server = await _chunkFENLKXMBjs.createServer.call(void 0,
288
+ const options = await _chunkLC4O3TXIjs.resolveOptions.call(void 0, { entry, theme }, "export");
289
+ const server = await _chunkLC4O3TXIjs.createServer.call(void 0,
331
290
  options,
332
291
  {
333
292
  server: { port },
@@ -336,24 +295,10 @@ cli.command(
336
295
  );
337
296
  await server.listen(port);
338
297
  printInfo(options);
339
- _chunkFENLKXMBjs.parser.filterDisabled(options.data);
340
- const width = options.data.config.canvasWidth;
341
- const height = Math.round(width / options.data.config.aspectRatio);
342
- output = await exportSlides({
298
+ _chunkLC4O3TXIjs.parser.filterDisabled(options.data);
299
+ const output = await exportSlides({
343
300
  port,
344
- slides: options.data.slides,
345
- total: options.data.slides.length,
346
- range,
347
- format,
348
- output,
349
- timeout,
350
- dark,
351
- routerMode: options.data.config.routerMode,
352
- width,
353
- height,
354
- withClicks,
355
- executablePath,
356
- withTOC
301
+ ...getExportOptions(args, options)
357
302
  });
358
303
  console.log(`${_kolorist.green.call(void 0, " \u2713 ")}${_kolorist.dim.call(void 0, "exported to ")}./${output}
359
304
  `);
@@ -382,12 +327,12 @@ cli.command(
382
327
  timeout
383
328
  }) => {
384
329
  process.env.NODE_ENV = "production";
385
- const { exportNotes } = await Promise.resolve().then(() => _chunkOVFYMGU6js.__toESM.call(void 0, _chunkOVFYMGU6js.__require.call(void 0, "./export-RNJ27D27.js")));
330
+ const { exportNotes } = await Promise.resolve().then(() => _chunkOVFYMGU6js.__toESM.call(void 0, _chunkOVFYMGU6js.__require.call(void 0, "./export-2BM4EQEA.js")));
386
331
  const port = await findFreePort(12445);
387
- const options = await _chunkFENLKXMBjs.resolveOptions.call(void 0, { entry }, "export");
332
+ const options = await _chunkLC4O3TXIjs.resolveOptions.call(void 0, { entry }, "export");
388
333
  if (!output)
389
334
  output = options.data.config.exportFilename ? `${options.data.config.exportFilename}-notes` : `${_path2.default.basename(entry, ".md")}-export-notes`;
390
- const server = await _chunkFENLKXMBjs.createServer.call(void 0,
335
+ const server = await _chunkLC4O3TXIjs.createServer.call(void 0,
391
336
  options,
392
337
  {
393
338
  server: { port },
@@ -396,7 +341,7 @@ cli.command(
396
341
  );
397
342
  await server.listen(port);
398
343
  printInfo(options);
399
- _chunkFENLKXMBjs.parser.filterDisabled(options.data);
344
+ _chunkLC4O3TXIjs.parser.filterDisabled(options.data);
400
345
  output = await exportNotes({
401
346
  port,
402
347
  output,
@@ -420,11 +365,43 @@ function commonOptions(args) {
420
365
  describe: "override theme"
421
366
  });
422
367
  }
368
+ function exportOptions(args) {
369
+ return args.option("output", {
370
+ type: "string",
371
+ describe: "path to the output"
372
+ }).option("format", {
373
+ type: "string",
374
+ choices: ["pdf", "png", "md"],
375
+ describe: "output format"
376
+ }).option("timeout", {
377
+ type: "number",
378
+ describe: "timeout for rendering the print page"
379
+ }).option("range", {
380
+ type: "string",
381
+ describe: 'page ranges to export, for example "1,4-5,6"'
382
+ }).option("dark", {
383
+ type: "boolean",
384
+ describe: "export as dark theme"
385
+ }).option("with-clicks", {
386
+ alias: "c",
387
+ type: "boolean",
388
+ describe: "export pages for every clicks"
389
+ }).option("executable-path", {
390
+ type: "string",
391
+ describe: "executable to override playwright bundled browser"
392
+ }).option("with-toc", {
393
+ type: "boolean",
394
+ describe: "export pages with outline"
395
+ }).option("per-slide", {
396
+ type: "boolean",
397
+ describe: "slide slides slide by slide. Works better with global components, but will break cross slide links and TOC in PDF"
398
+ });
399
+ }
423
400
  function printInfo(options, port, remote) {
424
401
  console.log();
425
402
  console.log();
426
403
  console.log(` ${_kolorist.cyan.call(void 0, "\u25CF") + _kolorist.blue.call(void 0, "\u25A0") + _kolorist.yellow.call(void 0, "\u25B2")}`);
427
- console.log(`${_kolorist.bold.call(void 0, " Slidev")} ${_kolorist.blue.call(void 0, `v${_chunkFENLKXMBjs.version}`)} ${_isinstalledglobally2.default ? _kolorist.yellow.call(void 0, "(global)") : ""}`);
404
+ console.log(`${_kolorist.bold.call(void 0, " Slidev")} ${_kolorist.blue.call(void 0, `v${_chunkLC4O3TXIjs.version}`)} ${_isinstalledglobally2.default ? _kolorist.yellow.call(void 0, "(global)") : ""}`);
428
405
  console.log();
429
406
  console.log(_kolorist.dim.call(void 0, " theme ") + (options.theme ? _kolorist.green.call(void 0, options.theme) : _kolorist.gray.call(void 0, "none")));
430
407
  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));
@@ -454,24 +431,8 @@ function printInfo(options, port, remote) {
454
431
  _parser.verifyConfig.call(void 0, options.data.config, options.data.themeMeta, (v) => console.warn(_kolorist.yellow.call(void 0, ` ! ${v}`)));
455
432
  console.log();
456
433
  }
457
- function isPortFree(port) {
458
- return new Promise((resolve) => {
459
- const server = _net2.default.createServer((socket) => {
460
- socket.write("Echo server\r\n");
461
- socket.pipe(socket);
462
- });
463
- server.listen(port, "127.0.0.1");
464
- server.on("error", () => {
465
- resolve(false);
466
- });
467
- server.on("listening", () => {
468
- server.close();
469
- resolve(true);
470
- });
471
- });
472
- }
473
434
  async function findFreePort(start) {
474
- if (await isPortFree(start))
435
+ if (await _getportplease.checkPort.call(void 0, start) !== false)
475
436
  return start;
476
437
  return findFreePort(start + 1);
477
438
  }
package/dist/cli.mjs CHANGED
@@ -9,11 +9,11 @@ import {
9
9
  resolveOptions,
10
10
  resolveThemeName,
11
11
  version
12
- } from "./chunk-RWZQGJHC.mjs";
12
+ } from "./chunk-S7VB5HAT.mjs";
13
13
  import {
14
14
  loadSetups,
15
15
  require_fast_deep_equal
16
- } from "./chunk-MDHB5JSE.mjs";
16
+ } from "./chunk-NOJBQ6MT.mjs";
17
17
  import {
18
18
  __dirname,
19
19
  __require,
@@ -25,7 +25,6 @@ import {
25
25
  init_esm_shims();
26
26
  var import_fast_deep_equal = __toESM(require_fast_deep_equal());
27
27
  import path from "path";
28
- import net from "net";
29
28
  import os from "os";
30
29
  import { exec } from "child_process";
31
30
  import * as readline from "readline";
@@ -37,6 +36,7 @@ import { blue, bold, cyan, dim, gray, green, underline, yellow } from "kolorist"
37
36
  import isInstalledGlobally from "is-installed-globally";
38
37
  import { verifyConfig } from "@slidev/parser";
39
38
  import { injectPreparserExtensionLoader } from "@slidev/parser/fs";
39
+ import { checkPort } from "get-port-please";
40
40
  var CONFIG_RESTART_FIELDS = [
41
41
  "highlighter",
42
42
  "monaco",
@@ -186,7 +186,7 @@ cli.command(
186
186
  cli.command(
187
187
  "build [entry]",
188
188
  "Build hostable SPA",
189
- (args) => commonOptions(args).option("watch", {
189
+ (args) => exportOptions(commonOptions(args)).option("watch", {
190
190
  alias: "w",
191
191
  default: false,
192
192
  describe: "build watch"
@@ -207,8 +207,9 @@ cli.command(
207
207
  type: "boolean",
208
208
  describe: "enable the inspect plugin for debugging"
209
209
  }).strict().help(),
210
- async ({ entry, theme, watch, base, download, out, inspect }) => {
211
- const { build } = await Promise.resolve().then(() => __toESM(__require("./build-NROT64YL.mjs")));
210
+ async (args) => {
211
+ const { entry, theme, watch, base, download, out, inspect } = args;
212
+ const { build } = await Promise.resolve().then(() => __toESM(__require("./build-GNCYENZG.mjs")));
212
213
  const options = await resolveOptions({ entry, theme, inspect }, "build");
213
214
  if (download && !options.data.config.download)
214
215
  options.data.config.download = download;
@@ -219,7 +220,7 @@ cli.command(
219
220
  watch: watch ? {} : void 0,
220
221
  outDir: out
221
222
  }
222
- });
223
+ }, args);
223
224
  }
224
225
  );
225
226
  cli.command(
@@ -279,55 +280,13 @@ cli.command(
279
280
  cli.command(
280
281
  "export [entry]",
281
282
  "Export slides to PDF",
282
- (args) => commonOptions(args).option("output", {
283
- type: "string",
284
- describe: "path to the output"
285
- }).option("format", {
286
- default: "pdf",
287
- type: "string",
288
- choices: ["pdf", "png", "md"],
289
- describe: "output format"
290
- }).option("timeout", {
291
- default: 3e4,
292
- type: "number",
293
- describe: "timeout for rendering the print page"
294
- }).option("range", {
295
- type: "string",
296
- describe: 'page ranges to export, for example "1,4-5,6"'
297
- }).option("dark", {
298
- default: false,
299
- type: "boolean",
300
- describe: "export as dark theme"
301
- }).option("with-clicks", {
302
- alias: "c",
303
- default: false,
304
- type: "boolean",
305
- describe: "export pages for every clicks"
306
- }).option("executable-path", {
307
- type: "string",
308
- describe: "executable to override playwright bundled browser"
309
- }).option("with-toc", {
310
- default: false,
311
- type: "boolean",
312
- describe: "export pages with outline"
313
- }).strict().help(),
314
- async ({
315
- entry,
316
- theme,
317
- output,
318
- format,
319
- timeout,
320
- range,
321
- dark,
322
- "with-clicks": withClicks,
323
- "executable-path": executablePath,
324
- "with-toc": withTOC
325
- }) => {
283
+ (args) => exportOptions(commonOptions(args)).strict().help(),
284
+ async (args) => {
285
+ const { entry, theme } = args;
326
286
  process.env.NODE_ENV = "production";
327
- const { exportSlides } = await Promise.resolve().then(() => __toESM(__require("./export-2OSN6D4K.mjs")));
287
+ const { exportSlides, getExportOptions } = await Promise.resolve().then(() => __toESM(__require("./export-P6VFSLAQ.mjs")));
328
288
  const port = await findFreePort(12445);
329
289
  const options = await resolveOptions({ entry, theme }, "export");
330
- output = output || options.data.config.exportFilename || `${path.basename(entry, ".md")}-export`;
331
290
  const server = await createServer(
332
291
  options,
333
292
  {
@@ -338,23 +297,9 @@ cli.command(
338
297
  await server.listen(port);
339
298
  printInfo(options);
340
299
  parser.filterDisabled(options.data);
341
- const width = options.data.config.canvasWidth;
342
- const height = Math.round(width / options.data.config.aspectRatio);
343
- output = await exportSlides({
300
+ const output = await exportSlides({
344
301
  port,
345
- slides: options.data.slides,
346
- total: options.data.slides.length,
347
- range,
348
- format,
349
- output,
350
- timeout,
351
- dark,
352
- routerMode: options.data.config.routerMode,
353
- width,
354
- height,
355
- withClicks,
356
- executablePath,
357
- withTOC
302
+ ...getExportOptions(args, options)
358
303
  });
359
304
  console.log(`${green(" \u2713 ")}${dim("exported to ")}./${output}
360
305
  `);
@@ -383,7 +328,7 @@ cli.command(
383
328
  timeout
384
329
  }) => {
385
330
  process.env.NODE_ENV = "production";
386
- const { exportNotes } = await Promise.resolve().then(() => __toESM(__require("./export-2OSN6D4K.mjs")));
331
+ const { exportNotes } = await Promise.resolve().then(() => __toESM(__require("./export-P6VFSLAQ.mjs")));
387
332
  const port = await findFreePort(12445);
388
333
  const options = await resolveOptions({ entry }, "export");
389
334
  if (!output)
@@ -421,6 +366,38 @@ function commonOptions(args) {
421
366
  describe: "override theme"
422
367
  });
423
368
  }
369
+ function exportOptions(args) {
370
+ return args.option("output", {
371
+ type: "string",
372
+ describe: "path to the output"
373
+ }).option("format", {
374
+ type: "string",
375
+ choices: ["pdf", "png", "md"],
376
+ describe: "output format"
377
+ }).option("timeout", {
378
+ type: "number",
379
+ describe: "timeout for rendering the print page"
380
+ }).option("range", {
381
+ type: "string",
382
+ describe: 'page ranges to export, for example "1,4-5,6"'
383
+ }).option("dark", {
384
+ type: "boolean",
385
+ describe: "export as dark theme"
386
+ }).option("with-clicks", {
387
+ alias: "c",
388
+ type: "boolean",
389
+ describe: "export pages for every clicks"
390
+ }).option("executable-path", {
391
+ type: "string",
392
+ describe: "executable to override playwright bundled browser"
393
+ }).option("with-toc", {
394
+ type: "boolean",
395
+ describe: "export pages with outline"
396
+ }).option("per-slide", {
397
+ type: "boolean",
398
+ describe: "slide slides slide by slide. Works better with global components, but will break cross slide links and TOC in PDF"
399
+ });
400
+ }
424
401
  function printInfo(options, port, remote) {
425
402
  console.log();
426
403
  console.log();
@@ -455,24 +432,8 @@ function printInfo(options, port, remote) {
455
432
  verifyConfig(options.data.config, options.data.themeMeta, (v) => console.warn(yellow(` ! ${v}`)));
456
433
  console.log();
457
434
  }
458
- function isPortFree(port) {
459
- return new Promise((resolve) => {
460
- const server = net.createServer((socket) => {
461
- socket.write("Echo server\r\n");
462
- socket.pipe(socket);
463
- });
464
- server.listen(port, "127.0.0.1");
465
- server.on("error", () => {
466
- resolve(false);
467
- });
468
- server.on("listening", () => {
469
- server.close();
470
- resolve(true);
471
- });
472
- });
473
- }
474
435
  async function findFreePort(start) {
475
- if (await isPortFree(start))
436
+ if (await checkPort(start) !== false)
476
437
  return start;
477
438
  return findFreePort(start + 1);
478
439
  }
@@ -122,7 +122,8 @@ async function exportSlides({
122
122
  height = 1080,
123
123
  withClicks = false,
124
124
  executablePath = void 0,
125
- withTOC = false
125
+ withToc = false,
126
+ perSlide = false
126
127
  }) {
127
128
  if (!_chunkOVFYMGU6js.packageExists.call(void 0, "playwright-chromium"))
128
129
  throw new Error("The exporting for Slidev is powered by Playwright, please installed it via `npm i -D playwright-chromium`");
@@ -134,12 +135,12 @@ async function exportSlides({
134
135
  const context = await browser.newContext({
135
136
  viewport: {
136
137
  width,
137
- height: height * pages.length
138
+ height: perSlide ? height : height * pages.length
138
139
  },
139
140
  deviceScaleFactor: 1
140
141
  });
141
142
  const page = await context.newPage();
142
- const progress = createSlidevProgress(true);
143
+ const progress = createSlidevProgress(!perSlide);
143
144
  async function go(no, clicks) {
144
145
  const path2 = `${no}?print${withClicks ? "=clicks" : ""}${clicks ? `&clicks=${clicks}` : ""}${range ? `&range=${range}` : ""}`;
145
146
  const url = routerMode === "hash" ? `http://localhost:${port}${base}#${path2}` : `http://localhost:${port}${base}${path2}`;
@@ -149,20 +150,20 @@ async function exportSlides({
149
150
  });
150
151
  await page.waitForLoadState("networkidle");
151
152
  await page.emulateMedia({ colorScheme: dark ? "dark" : "light", media: "screen" });
152
- const elements = await page.locator("[data-waitfor]");
153
+ const elements = page.locator("[data-waitfor]");
153
154
  const count = await elements.count();
154
155
  for (let index = 0; index < count; index++) {
155
- const element = await elements.nth(index);
156
+ const element = elements.nth(index);
156
157
  const attribute = await element.getAttribute("data-waitfor");
157
158
  if (attribute)
158
159
  await element.locator(attribute).waitFor();
159
160
  }
160
- const frames = await page.frames();
161
+ const frames = page.frames();
161
162
  await Promise.all(frames.map((frame) => frame.waitForLoadState()));
162
163
  }
163
164
  async function getSlidesIndex() {
164
165
  const clicksBySlide = {};
165
- const slides2 = await page.locator(".slide-container");
166
+ const slides2 = page.locator(".print-slide-container");
166
167
  const count = await slides2.count();
167
168
  for (let i = 0; i < count; i++) {
168
169
  const id = await slides2.nth(i).getAttribute("id") || "";
@@ -176,10 +177,56 @@ async function exportSlides({
176
177
  }, []));
177
178
  return slideIndexes;
178
179
  }
179
- async function genPagePdf() {
180
+ function getClicksFromUrl(url) {
181
+ var _a;
182
+ return (_a = url.match(/clicks=([1-9][0-9]*)/)) == null ? void 0 : _a[1];
183
+ }
184
+ async function genPageWithClicks(fn, i, clicks) {
185
+ await fn(i, clicks);
186
+ if (withClicks) {
187
+ await page.keyboard.press("ArrowRight", { delay: 100 });
188
+ const _clicks = getClicksFromUrl(page.url());
189
+ if (_clicks && clicks !== _clicks)
190
+ await genPageWithClicks(fn, i, _clicks);
191
+ }
192
+ }
193
+ async function genPagePdfPerSlide() {
194
+ const buffers = [];
195
+ const genPdfBuffer = async (i, clicks) => {
196
+ await go(i, clicks);
197
+ const pdf = await page.pdf({
198
+ width,
199
+ height,
200
+ margin: {
201
+ left: 0,
202
+ top: 0,
203
+ right: 0,
204
+ bottom: 0
205
+ },
206
+ pageRanges: "1",
207
+ printBackground: true,
208
+ preferCSSPageSize: true
209
+ });
210
+ buffers.push(pdf);
211
+ };
212
+ let idx = 0;
213
+ for (const i of pages) {
214
+ await genPageWithClicks(genPdfBuffer, i);
215
+ progress.update(++idx);
216
+ }
217
+ const mergedPdf = await _pdflib.PDFDocument.create({});
218
+ for (const pdfBytes of buffers) {
219
+ const pdf = await _pdflib.PDFDocument.load(pdfBytes);
220
+ const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices());
221
+ copiedPages.forEach((page2) => {
222
+ mergedPdf.addPage(page2);
223
+ });
224
+ }
225
+ const buffer = await mergedPdf.save();
226
+ await _fsextra2.default.writeFile(output, buffer);
227
+ }
228
+ async function genPagePdfOnePiece() {
180
229
  var _a;
181
- if (!output.endsWith(".pdf"))
182
- output = `${output}.pdf`;
183
230
  await go("print");
184
231
  const slideIndexes = await getSlidesIndex();
185
232
  await page.pdf({
@@ -202,7 +249,7 @@ async function exportSlides({
202
249
  pdf.setTitle(titleSlide.title);
203
250
  if ((_a = titleSlide == null ? void 0 : titleSlide.frontmatter) == null ? void 0 : _a.info)
204
251
  pdf.setSubject(titleSlide.frontmatter.info);
205
- if (withTOC) {
252
+ if (withToc) {
206
253
  const outlinePdf = _outlinepdf.outlinePdfFactory.call(void 0, pdfLib);
207
254
  const tocTree = slides.filter((slide) => slide.title).reduce((acc, slide) => {
208
255
  addToTree(acc, slide, slideIndexes);
@@ -214,10 +261,10 @@ async function exportSlides({
214
261
  pdfData = Buffer.from(await pdf.save());
215
262
  await _fsextra2.default.writeFile(output, pdfData);
216
263
  }
217
- async function genPagePng() {
264
+ async function genPagePngOnePiece() {
218
265
  await go("print");
219
266
  await _fsextra2.default.emptyDir(output);
220
- const slides2 = await page.locator(".slide-container");
267
+ const slides2 = await page.locator(".print-slide-container");
221
268
  const count = await slides2.count();
222
269
  for (let i = 0; i < count; i++) {
223
270
  progress.update(i + 1);
@@ -227,6 +274,28 @@ async function exportSlides({
227
274
  await _fsextra2.default.writeFile(_path2.default.join(output, `${id}.png`), buffer);
228
275
  }
229
276
  }
277
+ async function genPagePngPerSlide() {
278
+ const genScreenshot = async (i, clicks) => {
279
+ await go(i, clicks);
280
+ await page.screenshot({
281
+ omitBackground: false,
282
+ path: _path2.default.join(
283
+ output,
284
+ `${i.toString().padStart(2, "0")}${clicks ? `-${clicks}` : ""}.png`
285
+ )
286
+ });
287
+ };
288
+ for (const i of pages)
289
+ await genPageWithClicks(genScreenshot, i);
290
+ }
291
+ function genPagePdf() {
292
+ if (!output.endsWith(".pdf"))
293
+ output = `${output}.pdf`;
294
+ return perSlide ? genPagePdfPerSlide() : genPagePdfOnePiece();
295
+ }
296
+ function genPagePng() {
297
+ return perSlide ? genPagePngPerSlide() : genPagePngOnePiece();
298
+ }
230
299
  async function genPageMd(slides2) {
231
300
  const files = await _fsextra2.default.readdir(output);
232
301
  const mds = files.map((file, i, files2) => {
@@ -264,7 +333,49 @@ async function exportSlides({
264
333
  browser.close();
265
334
  return output;
266
335
  }
336
+ function getExportOptions(args, options, outDir, outFilename) {
337
+ const config = {
338
+ ...options.data.config.export,
339
+ ...args,
340
+ withClicks: args["with-clicks"],
341
+ executablePath: args["executable-path"],
342
+ withToc: args["with-toc"],
343
+ perSlide: args["per-slide"]
344
+ };
345
+ const {
346
+ entry,
347
+ output,
348
+ format,
349
+ timeout,
350
+ range,
351
+ dark,
352
+ withClicks,
353
+ executablePath,
354
+ withToc,
355
+ perSlide
356
+ } = config;
357
+ outFilename = output || options.data.config.exportFilename || outFilename || `${_path2.default.basename(entry, ".md")}-export`;
358
+ if (outDir)
359
+ outFilename = _path2.default.join(outDir, outFilename);
360
+ return {
361
+ output: outFilename,
362
+ slides: options.data.slides,
363
+ total: options.data.slides.length,
364
+ range,
365
+ format: format || "pdf",
366
+ timeout: timeout != null ? timeout : 3e4,
367
+ dark: dark || options.data.config.colorSchema === "dark",
368
+ routerMode: options.data.config.routerMode,
369
+ width: options.data.config.canvasWidth,
370
+ height: Math.round(options.data.config.canvasWidth / options.data.config.aspectRatio),
371
+ withClicks: withClicks || false,
372
+ executablePath,
373
+ withToc: withToc || false,
374
+ perSlide: perSlide || false
375
+ };
376
+ }
377
+
267
378
 
268
379
 
269
380
 
270
- exports.exportNotes = exportNotes; exports.exportSlides = exportSlides;
381
+ exports.exportNotes = exportNotes; exports.exportSlides = exportSlides; exports.getExportOptions = getExportOptions;
@@ -122,7 +122,8 @@ async function exportSlides({
122
122
  height = 1080,
123
123
  withClicks = false,
124
124
  executablePath = void 0,
125
- withTOC = false
125
+ withToc = false,
126
+ perSlide = false
126
127
  }) {
127
128
  if (!packageExists("playwright-chromium"))
128
129
  throw new Error("The exporting for Slidev is powered by Playwright, please installed it via `npm i -D playwright-chromium`");
@@ -134,12 +135,12 @@ async function exportSlides({
134
135
  const context = await browser.newContext({
135
136
  viewport: {
136
137
  width,
137
- height: height * pages.length
138
+ height: perSlide ? height : height * pages.length
138
139
  },
139
140
  deviceScaleFactor: 1
140
141
  });
141
142
  const page = await context.newPage();
142
- const progress = createSlidevProgress(true);
143
+ const progress = createSlidevProgress(!perSlide);
143
144
  async function go(no, clicks) {
144
145
  const path2 = `${no}?print${withClicks ? "=clicks" : ""}${clicks ? `&clicks=${clicks}` : ""}${range ? `&range=${range}` : ""}`;
145
146
  const url = routerMode === "hash" ? `http://localhost:${port}${base}#${path2}` : `http://localhost:${port}${base}${path2}`;
@@ -149,20 +150,20 @@ async function exportSlides({
149
150
  });
150
151
  await page.waitForLoadState("networkidle");
151
152
  await page.emulateMedia({ colorScheme: dark ? "dark" : "light", media: "screen" });
152
- const elements = await page.locator("[data-waitfor]");
153
+ const elements = page.locator("[data-waitfor]");
153
154
  const count = await elements.count();
154
155
  for (let index = 0; index < count; index++) {
155
- const element = await elements.nth(index);
156
+ const element = elements.nth(index);
156
157
  const attribute = await element.getAttribute("data-waitfor");
157
158
  if (attribute)
158
159
  await element.locator(attribute).waitFor();
159
160
  }
160
- const frames = await page.frames();
161
+ const frames = page.frames();
161
162
  await Promise.all(frames.map((frame) => frame.waitForLoadState()));
162
163
  }
163
164
  async function getSlidesIndex() {
164
165
  const clicksBySlide = {};
165
- const slides2 = await page.locator(".slide-container");
166
+ const slides2 = page.locator(".print-slide-container");
166
167
  const count = await slides2.count();
167
168
  for (let i = 0; i < count; i++) {
168
169
  const id = await slides2.nth(i).getAttribute("id") || "";
@@ -176,10 +177,56 @@ async function exportSlides({
176
177
  }, []));
177
178
  return slideIndexes;
178
179
  }
179
- async function genPagePdf() {
180
+ function getClicksFromUrl(url) {
181
+ var _a;
182
+ return (_a = url.match(/clicks=([1-9][0-9]*)/)) == null ? void 0 : _a[1];
183
+ }
184
+ async function genPageWithClicks(fn, i, clicks) {
185
+ await fn(i, clicks);
186
+ if (withClicks) {
187
+ await page.keyboard.press("ArrowRight", { delay: 100 });
188
+ const _clicks = getClicksFromUrl(page.url());
189
+ if (_clicks && clicks !== _clicks)
190
+ await genPageWithClicks(fn, i, _clicks);
191
+ }
192
+ }
193
+ async function genPagePdfPerSlide() {
194
+ const buffers = [];
195
+ const genPdfBuffer = async (i, clicks) => {
196
+ await go(i, clicks);
197
+ const pdf = await page.pdf({
198
+ width,
199
+ height,
200
+ margin: {
201
+ left: 0,
202
+ top: 0,
203
+ right: 0,
204
+ bottom: 0
205
+ },
206
+ pageRanges: "1",
207
+ printBackground: true,
208
+ preferCSSPageSize: true
209
+ });
210
+ buffers.push(pdf);
211
+ };
212
+ let idx = 0;
213
+ for (const i of pages) {
214
+ await genPageWithClicks(genPdfBuffer, i);
215
+ progress.update(++idx);
216
+ }
217
+ const mergedPdf = await PDFDocument.create({});
218
+ for (const pdfBytes of buffers) {
219
+ const pdf = await PDFDocument.load(pdfBytes);
220
+ const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices());
221
+ copiedPages.forEach((page2) => {
222
+ mergedPdf.addPage(page2);
223
+ });
224
+ }
225
+ const buffer = await mergedPdf.save();
226
+ await fs.writeFile(output, buffer);
227
+ }
228
+ async function genPagePdfOnePiece() {
180
229
  var _a;
181
- if (!output.endsWith(".pdf"))
182
- output = `${output}.pdf`;
183
230
  await go("print");
184
231
  const slideIndexes = await getSlidesIndex();
185
232
  await page.pdf({
@@ -202,7 +249,7 @@ async function exportSlides({
202
249
  pdf.setTitle(titleSlide.title);
203
250
  if ((_a = titleSlide == null ? void 0 : titleSlide.frontmatter) == null ? void 0 : _a.info)
204
251
  pdf.setSubject(titleSlide.frontmatter.info);
205
- if (withTOC) {
252
+ if (withToc) {
206
253
  const outlinePdf = outlinePdfFactory(pdfLib);
207
254
  const tocTree = slides.filter((slide) => slide.title).reduce((acc, slide) => {
208
255
  addToTree(acc, slide, slideIndexes);
@@ -214,10 +261,10 @@ async function exportSlides({
214
261
  pdfData = Buffer.from(await pdf.save());
215
262
  await fs.writeFile(output, pdfData);
216
263
  }
217
- async function genPagePng() {
264
+ async function genPagePngOnePiece() {
218
265
  await go("print");
219
266
  await fs.emptyDir(output);
220
- const slides2 = await page.locator(".slide-container");
267
+ const slides2 = await page.locator(".print-slide-container");
221
268
  const count = await slides2.count();
222
269
  for (let i = 0; i < count; i++) {
223
270
  progress.update(i + 1);
@@ -227,6 +274,28 @@ async function exportSlides({
227
274
  await fs.writeFile(path.join(output, `${id}.png`), buffer);
228
275
  }
229
276
  }
277
+ async function genPagePngPerSlide() {
278
+ const genScreenshot = async (i, clicks) => {
279
+ await go(i, clicks);
280
+ await page.screenshot({
281
+ omitBackground: false,
282
+ path: path.join(
283
+ output,
284
+ `${i.toString().padStart(2, "0")}${clicks ? `-${clicks}` : ""}.png`
285
+ )
286
+ });
287
+ };
288
+ for (const i of pages)
289
+ await genPageWithClicks(genScreenshot, i);
290
+ }
291
+ function genPagePdf() {
292
+ if (!output.endsWith(".pdf"))
293
+ output = `${output}.pdf`;
294
+ return perSlide ? genPagePdfPerSlide() : genPagePdfOnePiece();
295
+ }
296
+ function genPagePng() {
297
+ return perSlide ? genPagePngPerSlide() : genPagePngOnePiece();
298
+ }
230
299
  async function genPageMd(slides2) {
231
300
  const files = await fs.readdir(output);
232
301
  const mds = files.map((file, i, files2) => {
@@ -264,7 +333,49 @@ async function exportSlides({
264
333
  browser.close();
265
334
  return output;
266
335
  }
336
+ function getExportOptions(args, options, outDir, outFilename) {
337
+ const config = {
338
+ ...options.data.config.export,
339
+ ...args,
340
+ withClicks: args["with-clicks"],
341
+ executablePath: args["executable-path"],
342
+ withToc: args["with-toc"],
343
+ perSlide: args["per-slide"]
344
+ };
345
+ const {
346
+ entry,
347
+ output,
348
+ format,
349
+ timeout,
350
+ range,
351
+ dark,
352
+ withClicks,
353
+ executablePath,
354
+ withToc,
355
+ perSlide
356
+ } = config;
357
+ outFilename = output || options.data.config.exportFilename || outFilename || `${path.basename(entry, ".md")}-export`;
358
+ if (outDir)
359
+ outFilename = path.join(outDir, outFilename);
360
+ return {
361
+ output: outFilename,
362
+ slides: options.data.slides,
363
+ total: options.data.slides.length,
364
+ range,
365
+ format: format || "pdf",
366
+ timeout: timeout != null ? timeout : 3e4,
367
+ dark: dark || options.data.config.colorSchema === "dark",
368
+ routerMode: options.data.config.routerMode,
369
+ width: options.data.config.canvasWidth,
370
+ height: Math.round(options.data.config.canvasWidth / options.data.config.aspectRatio),
371
+ withClicks: withClicks || false,
372
+ executablePath,
373
+ withToc: withToc || false,
374
+ perSlide: perSlide || false
375
+ };
376
+ }
267
377
  export {
268
378
  exportNotes,
269
- exportSlides
379
+ exportSlides,
380
+ getExportOptions
270
381
  };
package/dist/index.js CHANGED
@@ -9,11 +9,11 @@
9
9
 
10
10
 
11
11
 
12
- var _chunkFENLKXMBjs = require('./chunk-FENLKXMB.js');
12
+ var _chunkLC4O3TXIjs = require('./chunk-LC4O3TXI.js');
13
13
 
14
14
 
15
15
 
16
- var _chunkSJ7FI34Ejs = require('./chunk-SJ7FI34E.js');
16
+ var _chunkHHR7Q56Zjs = require('./chunk-HHR7Q56Z.js');
17
17
 
18
18
 
19
19
  var _chunkOVFYMGU6js = require('./chunk-OVFYMGU6.js');
@@ -36,4 +36,4 @@ _chunkOVFYMGU6js.init_cjs_shims.call(void 0, );
36
36
 
37
37
 
38
38
 
39
- exports.ViteSlidevPlugin = _chunkSJ7FI34Ejs.ViteSlidevPlugin; exports.createServer = _chunkFENLKXMBjs.createServer; exports.createWindiCSSPlugin = _chunkSJ7FI34Ejs.createWindiCSSPlugin; exports.getAddonRoots = _chunkFENLKXMBjs.getAddonRoots; exports.getCLIRoot = _chunkFENLKXMBjs.getCLIRoot; exports.getClientRoot = _chunkFENLKXMBjs.getClientRoot; exports.getRoot = _chunkFENLKXMBjs.getRoot; exports.getThemeRoots = _chunkFENLKXMBjs.getThemeRoots; exports.getUserRoot = _chunkFENLKXMBjs.getUserRoot; exports.isPath = _chunkFENLKXMBjs.isPath; exports.parser = _chunkFENLKXMBjs.parser; exports.resolveOptions = _chunkFENLKXMBjs.resolveOptions;
39
+ exports.ViteSlidevPlugin = _chunkHHR7Q56Zjs.ViteSlidevPlugin; exports.createServer = _chunkLC4O3TXIjs.createServer; exports.createWindiCSSPlugin = _chunkHHR7Q56Zjs.createWindiCSSPlugin; exports.getAddonRoots = _chunkLC4O3TXIjs.getAddonRoots; exports.getCLIRoot = _chunkLC4O3TXIjs.getCLIRoot; exports.getClientRoot = _chunkLC4O3TXIjs.getClientRoot; exports.getRoot = _chunkLC4O3TXIjs.getRoot; exports.getThemeRoots = _chunkLC4O3TXIjs.getThemeRoots; exports.getUserRoot = _chunkLC4O3TXIjs.getUserRoot; exports.isPath = _chunkLC4O3TXIjs.isPath; exports.parser = _chunkLC4O3TXIjs.parser; exports.resolveOptions = _chunkLC4O3TXIjs.resolveOptions;
package/dist/index.mjs CHANGED
@@ -9,11 +9,11 @@ import {
9
9
  isPath,
10
10
  parser,
11
11
  resolveOptions
12
- } from "./chunk-RWZQGJHC.mjs";
12
+ } from "./chunk-S7VB5HAT.mjs";
13
13
  import {
14
14
  ViteSlidevPlugin,
15
15
  createWindiCSSPlugin
16
- } from "./chunk-MDHB5JSE.mjs";
16
+ } from "./chunk-NOJBQ6MT.mjs";
17
17
  import {
18
18
  init_esm_shims
19
19
  } from "./chunk-T5WFA52O.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slidev/cli",
3
- "version": "0.38.5",
3
+ "version": "0.38.8",
4
4
  "description": "Presentation slides for developers",
5
5
  "author": "antfu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@antfu/utils": "^0.7.2",
46
- "@hedgedoc/markdown-it-task-lists": "^2.0.1",
46
+ "@hedgedoc/markdown-it-plugins": "^2.0.0",
47
47
  "@iconify-json/carbon": "^1.1.14",
48
48
  "@iconify-json/ph": "^1.1.3",
49
49
  "@lillallol/outline-pdf": "^4.0.0",
@@ -56,6 +56,7 @@
56
56
  "debug": "^4.3.4",
57
57
  "fast-glob": "^3.2.12",
58
58
  "fs-extra": "^11.1.0",
59
+ "get-port-please": "^3.0.1",
59
60
  "global-dirs": "^3.0.1",
60
61
  "import-from": "^4.0.0",
61
62
  "is-installed-globally": "^0.4.0",
@@ -90,9 +91,9 @@
90
91
  "vue": "^3.2.45",
91
92
  "windicss": "^3.5.6",
92
93
  "yargs": "^17.6.2",
93
- "@slidev/client": "0.38.5",
94
- "@slidev/parser": "0.38.5",
95
- "@slidev/types": "0.38.5"
94
+ "@slidev/client": "0.38.8",
95
+ "@slidev/parser": "0.38.8",
96
+ "@slidev/types": "0.38.8"
96
97
  },
97
98
  "devDependencies": {
98
99
  "@types/plantuml-encoder": "^1.4.0",