@slidev/cli 0.38.7 → 0.39.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.
@@ -11,9 +11,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
11
11
  return require.apply(this, arguments);
12
12
  throw new Error('Dynamic require of "' + x + '" is not supported');
13
13
  });
14
- var __esm = (fn, res) => function __init() {
15
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
16
- };
17
14
  var __commonJS = (cb, mod) => function __require2() {
18
15
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
19
16
  };
@@ -47,25 +44,16 @@ var __privateSet = (obj, member, value, setter) => {
47
44
  setter ? setter.call(obj, value) : member.set(obj, value);
48
45
  return value;
49
46
  };
50
- var __privateWrapper = (obj, member, setter, getter) => {
51
- return {
52
- set _(value) {
53
- __privateSet(obj, member, value, setter);
54
- },
55
- get _() {
56
- return __privateGet(obj, member, getter);
57
- }
58
- };
59
- };
60
-
61
- // ../../node_modules/.pnpm/tsup@5.12.9_typescript@4.9.4/node_modules/tsup/assets/cjs_shims.js
62
- var init_cjs_shims = __esm({
63
- "../../node_modules/.pnpm/tsup@5.12.9_typescript@4.9.4/node_modules/tsup/assets/cjs_shims.js"() {
47
+ var __privateWrapper = (obj, member, setter, getter) => ({
48
+ set _(value) {
49
+ __privateSet(obj, member, value, setter);
50
+ },
51
+ get _() {
52
+ return __privateGet(obj, member, getter);
64
53
  }
65
54
  });
66
55
 
67
56
  // node/utils.ts
68
- init_cjs_shims();
69
57
  var _path = require('path');
70
58
  var _utils = require('@antfu/utils');
71
59
  var _isinstalledglobally = require('is-installed-globally'); var _isinstalledglobally2 = _interopRequireDefault(_isinstalledglobally);
@@ -143,5 +131,4 @@ function packageExists(name) {
143
131
 
144
132
 
145
133
 
146
-
147
- exports.__require = __require; exports.__commonJS = __commonJS; exports.__toESM = __toESM; exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet; exports.__privateWrapper = __privateWrapper; exports.init_cjs_shims = init_cjs_shims; exports.toAtFS = toAtFS; exports.resolveImportPath = resolveImportPath; exports.resolveGlobalImportPath = resolveGlobalImportPath; exports.stringifyMarkdownTokens = stringifyMarkdownTokens; exports.generateGoogleFontsUrl = generateGoogleFontsUrl; exports.packageExists = packageExists;
134
+ exports.__require = __require; exports.__commonJS = __commonJS; exports.__toESM = __toESM; exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet; exports.__privateWrapper = __privateWrapper; exports.toAtFS = toAtFS; exports.resolveImportPath = resolveImportPath; exports.resolveGlobalImportPath = resolveGlobalImportPath; exports.stringifyMarkdownTokens = stringifyMarkdownTokens; exports.generateGoogleFontsUrl = generateGoogleFontsUrl; exports.packageExists = packageExists;
@@ -11,9 +11,6 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
11
11
  return require.apply(this, arguments);
12
12
  throw new Error('Dynamic require of "' + x + '" is not supported');
13
13
  });
14
- var __esm = (fn, res) => function __init() {
15
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
16
- };
17
14
  var __commonJS = (cb, mod) => function __require2() {
18
15
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
19
16
  };
@@ -47,39 +44,23 @@ var __privateSet = (obj, member, value, setter) => {
47
44
  setter ? setter.call(obj, value) : member.set(obj, value);
48
45
  return value;
49
46
  };
50
- var __privateWrapper = (obj, member, setter, getter) => {
51
- return {
52
- set _(value) {
53
- __privateSet(obj, member, value, setter);
54
- },
55
- get _() {
56
- return __privateGet(obj, member, getter);
57
- }
58
- };
59
- };
60
-
61
- // ../../node_modules/.pnpm/tsup@5.12.9_typescript@4.9.4/node_modules/tsup/assets/esm_shims.js
62
- import { fileURLToPath } from "url";
63
- import path from "path";
64
- var getFilename, getDirname, __dirname, __filename;
65
- var init_esm_shims = __esm({
66
- "../../node_modules/.pnpm/tsup@5.12.9_typescript@4.9.4/node_modules/tsup/assets/esm_shims.js"() {
67
- getFilename = () => fileURLToPath(import.meta.url);
68
- getDirname = () => path.dirname(getFilename());
69
- __dirname = /* @__PURE__ */ getDirname();
70
- __filename = /* @__PURE__ */ getFilename();
47
+ var __privateWrapper = (obj, member, setter, getter) => ({
48
+ set _(value) {
49
+ __privateSet(obj, member, value, setter);
50
+ },
51
+ get _() {
52
+ return __privateGet(obj, member, getter);
71
53
  }
72
54
  });
73
55
 
74
56
  // node/utils.ts
75
- init_esm_shims();
76
57
  import { join } from "path";
77
58
  import { ensurePrefix, slash } from "@antfu/utils";
78
59
  import isInstalledGlobally from "is-installed-globally";
79
60
  import { sync as resolve } from "resolve";
80
61
  import globalDirs from "global-dirs";
81
- function toAtFS(path2) {
82
- return `/@fs${ensurePrefix("/", slash(path2))}`;
62
+ function toAtFS(path) {
63
+ return `/@fs${ensurePrefix("/", slash(path))}`;
83
64
  }
84
65
  function resolveImportPath(importName, ensure = false) {
85
66
  try {
@@ -144,9 +125,6 @@ export {
144
125
  __privateAdd,
145
126
  __privateSet,
146
127
  __privateWrapper,
147
- __dirname,
148
- __filename,
149
- init_esm_shims,
150
128
  toAtFS,
151
129
  resolveImportPath,
152
130
  resolveGlobalImportPath,
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
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 }; }
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 }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
3
 
4
4
 
@@ -9,22 +9,18 @@
9
9
 
10
10
 
11
11
 
12
- var _chunk35GWFKPPjs = require('./chunk-35GWFKPP.js');
12
+ var _chunkIM22HCOOjs = require('./chunk-IM22HCOO.js');
13
13
 
14
14
 
15
15
 
16
- var _chunkHHR7Q56Zjs = require('./chunk-HHR7Q56Z.js');
16
+ var _chunkDTAZRAWWjs = require('./chunk-DTAZRAWW.js');
17
17
 
18
18
 
19
-
20
-
21
- var _chunkOVFYMGU6js = require('./chunk-OVFYMGU6.js');
19
+ var _chunkUJ5GHVIIjs = require('./chunk-UJ5GHVII.js');
22
20
 
23
21
  // node/cli.ts
24
- _chunkOVFYMGU6js.init_cjs_shims.call(void 0, );
25
- var import_fast_deep_equal = _chunkOVFYMGU6js.__toESM.call(void 0, _chunkHHR7Q56Zjs.require_fast_deep_equal.call(void 0, ));
22
+ var import_fast_deep_equal = _chunkUJ5GHVIIjs.__toESM.call(void 0, _chunkDTAZRAWWjs.require_fast_deep_equal.call(void 0, ));
26
23
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
27
- var _net = require('net'); var _net2 = _interopRequireDefault(_net);
28
24
  var _os = require('os'); var _os2 = _interopRequireDefault(_os);
29
25
  var _child_process = require('child_process');
30
26
  var _readline = require('readline'); var readline = _interopRequireWildcard(_readline);
@@ -36,6 +32,7 @@ var _kolorist = require('kolorist');
36
32
  var _isinstalledglobally = require('is-installed-globally'); var _isinstalledglobally2 = _interopRequireDefault(_isinstalledglobally);
37
33
  var _parser = require('@slidev/parser');
38
34
  var _fs = require('@slidev/parser/fs');
35
+ var _getportplease = require('get-port-please');
39
36
  var CONFIG_RESTART_FIELDS = [
40
37
  "highlighter",
41
38
  "monaco",
@@ -44,17 +41,16 @@ var CONFIG_RESTART_FIELDS = [
44
41
  "css"
45
42
  ];
46
43
  _fs.injectPreparserExtensionLoader.call(void 0, async (headmatter, filepath) => {
47
- var _a;
48
- const addons = (_a = headmatter == null ? void 0 : headmatter.addons) != null ? _a : [];
44
+ const addons = _nullishCoalesce((headmatter == null ? void 0 : headmatter.addons), () => ( []));
49
45
  const roots = [
50
- _chunk35GWFKPPjs.getUserRoot.call(void 0, {}).userRoot,
51
- ..._chunk35GWFKPPjs.getAddonRoots.call(void 0, addons, ""),
52
- _chunk35GWFKPPjs.getClientRoot.call(void 0, )
46
+ _chunkIM22HCOOjs.getUserRoot.call(void 0, {}).userRoot,
47
+ ..._chunkIM22HCOOjs.getAddonRoots.call(void 0, addons, ""),
48
+ _chunkIM22HCOOjs.getClientRoot.call(void 0, )
53
49
  ];
54
50
  const mergeArrays = (a, b) => a.concat(b);
55
- return await _chunkHHR7Q56Zjs.loadSetups.call(void 0, roots, "preparser.ts", { filepath, headmatter }, [], false, mergeArrays);
51
+ return await _chunkDTAZRAWWjs.loadSetups.call(void 0, roots, "preparser.ts", { filepath, headmatter }, [], false, mergeArrays);
56
52
  });
57
- var cli = _yargs2.default.scriptName("slidev").usage("$0 [args]").version(_chunk35GWFKPPjs.version).strict().showHelpOnFail(false).alias("h", "help").alias("v", "version");
53
+ var cli = _yargs2.default.scriptName("slidev").usage("$0 [args]").version(_chunkIM22HCOOjs.version).strict().showHelpOnFail(false).alias("h", "help").alias("v", "version");
58
54
  cli.command(
59
55
  "* [entry]",
60
56
  "Start a local server for Slidev",
@@ -105,9 +101,9 @@ cli.command(
105
101
  async function initServer() {
106
102
  if (server)
107
103
  await server.close();
108
- const options = await _chunk35GWFKPPjs.resolveOptions.call(void 0, { entry, remote, theme, inspect }, "dev");
104
+ const options = await _chunkIM22HCOOjs.resolveOptions.call(void 0, { entry, remote, theme, inspect }, "dev");
109
105
  port = userPort || await findFreePort(3030);
110
- server = await _chunk35GWFKPPjs.createServer.call(void 0,
106
+ server = await _chunkIM22HCOOjs.createServer.call(void 0,
111
107
  options,
112
108
  {
113
109
  server: {
@@ -121,7 +117,7 @@ cli.command(
121
117
  },
122
118
  {
123
119
  onDataReload(newData, data) {
124
- if (!theme && _chunk35GWFKPPjs.resolveThemeName.call(void 0, newData.config.theme) !== _chunk35GWFKPPjs.resolveThemeName.call(void 0, data.config.theme)) {
120
+ if (!theme && _chunkIM22HCOOjs.resolveThemeName.call(void 0, newData.config.theme) !== _chunkIM22HCOOjs.resolveThemeName.call(void 0, data.config.theme)) {
125
121
  console.log(_kolorist.yellow.call(void 0, "\n restarting on theme change\n"));
126
122
  initServer();
127
123
  } else if (CONFIG_RESTART_FIELDS.some((i) => !(0, import_fast_deep_equal.default)(newData.config[i], data.config[i]))) {
@@ -208,8 +204,8 @@ cli.command(
208
204
  }).strict().help(),
209
205
  async (args) => {
210
206
  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-S6XIJ3EO.js")));
212
- const options = await _chunk35GWFKPPjs.resolveOptions.call(void 0, { entry, theme, inspect }, "build");
207
+ const { build } = await Promise.resolve().then(() => require("./build-XQGKVESO.js"));
208
+ const options = await _chunkIM22HCOOjs.resolveOptions.call(void 0, { entry, theme, inspect }, "build");
213
209
  if (download && !options.data.config.download)
214
210
  options.data.config.download = download;
215
211
  printInfo(options);
@@ -227,9 +223,9 @@ cli.command(
227
223
  "Format the markdown file",
228
224
  (args) => commonOptions(args).strict().help(),
229
225
  async ({ entry }) => {
230
- const data = await _chunk35GWFKPPjs.parser.load(entry);
231
- _chunk35GWFKPPjs.parser.prettify(data);
232
- await _chunk35GWFKPPjs.parser.save(data);
226
+ const data = await _chunkIM22HCOOjs.parser.load(entry);
227
+ _chunkIM22HCOOjs.parser.prettify(data);
228
+ await _chunkIM22HCOOjs.parser.save(data);
233
229
  }
234
230
  );
235
231
  cli.command(
@@ -244,17 +240,17 @@ cli.command(
244
240
  default: "theme"
245
241
  }),
246
242
  async ({ entry, dir, theme: themeInput }) => {
247
- const data = await _chunk35GWFKPPjs.parser.load(entry);
248
- const theme = _chunk35GWFKPPjs.resolveThemeName.call(void 0, themeInput || data.config.theme);
243
+ const data = await _chunkIM22HCOOjs.parser.load(entry);
244
+ const theme = _chunkIM22HCOOjs.resolveThemeName.call(void 0, themeInput || data.config.theme);
249
245
  if (theme === "none") {
250
246
  console.error('Cannot eject theme "none"');
251
247
  process.exit(1);
252
248
  }
253
- if (_chunk35GWFKPPjs.isPath.call(void 0, theme)) {
249
+ if (_chunkIM22HCOOjs.isPath.call(void 0, theme)) {
254
250
  console.error("Theme is already ejected");
255
251
  process.exit(1);
256
252
  }
257
- const roots = _chunk35GWFKPPjs.getThemeRoots.call(void 0, theme, entry);
253
+ const roots = _chunkIM22HCOOjs.getThemeRoots.call(void 0, theme, entry);
258
254
  if (!roots.length) {
259
255
  console.error(`Could not find theme "${theme}"`);
260
256
  process.exit(1);
@@ -266,7 +262,7 @@ cli.command(
266
262
  const dirPath = `./${dir}`;
267
263
  data.slides[0].frontmatter.theme = dirPath;
268
264
  data.slides[0].raw = null;
269
- await _chunk35GWFKPPjs.parser.save(data);
265
+ await _chunkIM22HCOOjs.parser.save(data);
270
266
  console.log(`Theme "${theme}" ejected successfully to "${dirPath}"`);
271
267
  }
272
268
  );
@@ -283,10 +279,10 @@ cli.command(
283
279
  async (args) => {
284
280
  const { entry, theme } = args;
285
281
  process.env.NODE_ENV = "production";
286
- const { exportSlides, getExportOptions } = await Promise.resolve().then(() => _chunkOVFYMGU6js.__toESM.call(void 0, _chunkOVFYMGU6js.__require.call(void 0, "./export-BWNX2QVG.js")));
282
+ const { exportSlides, getExportOptions } = await Promise.resolve().then(() => require("./export-BRPXINGP.js"));
287
283
  const port = await findFreePort(12445);
288
- const options = await _chunk35GWFKPPjs.resolveOptions.call(void 0, { entry, theme }, "export");
289
- const server = await _chunk35GWFKPPjs.createServer.call(void 0,
284
+ const options = await _chunkIM22HCOOjs.resolveOptions.call(void 0, { entry, theme }, "export");
285
+ const server = await _chunkIM22HCOOjs.createServer.call(void 0,
290
286
  options,
291
287
  {
292
288
  server: { port },
@@ -295,7 +291,7 @@ cli.command(
295
291
  );
296
292
  await server.listen(port);
297
293
  printInfo(options);
298
- _chunk35GWFKPPjs.parser.filterDisabled(options.data);
294
+ _chunkIM22HCOOjs.parser.filterDisabled(options.data);
299
295
  const output = await exportSlides({
300
296
  port,
301
297
  ...getExportOptions(args, options)
@@ -327,12 +323,12 @@ cli.command(
327
323
  timeout
328
324
  }) => {
329
325
  process.env.NODE_ENV = "production";
330
- const { exportNotes } = await Promise.resolve().then(() => _chunkOVFYMGU6js.__toESM.call(void 0, _chunkOVFYMGU6js.__require.call(void 0, "./export-BWNX2QVG.js")));
326
+ const { exportNotes } = await Promise.resolve().then(() => require("./export-BRPXINGP.js"));
331
327
  const port = await findFreePort(12445);
332
- const options = await _chunk35GWFKPPjs.resolveOptions.call(void 0, { entry }, "export");
328
+ const options = await _chunkIM22HCOOjs.resolveOptions.call(void 0, { entry }, "export");
333
329
  if (!output)
334
330
  output = options.data.config.exportFilename ? `${options.data.config.exportFilename}-notes` : `${_path2.default.basename(entry, ".md")}-export-notes`;
335
- const server = await _chunk35GWFKPPjs.createServer.call(void 0,
331
+ const server = await _chunkIM22HCOOjs.createServer.call(void 0,
336
332
  options,
337
333
  {
338
334
  server: { port },
@@ -341,7 +337,7 @@ cli.command(
341
337
  );
342
338
  await server.listen(port);
343
339
  printInfo(options);
344
- _chunk35GWFKPPjs.parser.filterDisabled(options.data);
340
+ _chunkIM22HCOOjs.parser.filterDisabled(options.data);
345
341
  output = await exportNotes({
346
342
  port,
347
343
  output,
@@ -392,13 +388,16 @@ function exportOptions(args) {
392
388
  }).option("with-toc", {
393
389
  type: "boolean",
394
390
  describe: "export pages with outline"
391
+ }).option("per-slide", {
392
+ type: "boolean",
393
+ describe: "slide slides slide by slide. Works better with global components, but will break cross slide links and TOC in PDF"
395
394
  });
396
395
  }
397
396
  function printInfo(options, port, remote) {
398
397
  console.log();
399
398
  console.log();
400
399
  console.log(` ${_kolorist.cyan.call(void 0, "\u25CF") + _kolorist.blue.call(void 0, "\u25A0") + _kolorist.yellow.call(void 0, "\u25B2")}`);
401
- console.log(`${_kolorist.bold.call(void 0, " Slidev")} ${_kolorist.blue.call(void 0, `v${_chunk35GWFKPPjs.version}`)} ${_isinstalledglobally2.default ? _kolorist.yellow.call(void 0, "(global)") : ""}`);
400
+ console.log(`${_kolorist.bold.call(void 0, " Slidev")} ${_kolorist.blue.call(void 0, `v${_chunkIM22HCOOjs.version}`)} ${_isinstalledglobally2.default ? _kolorist.yellow.call(void 0, "(global)") : ""}`);
402
401
  console.log();
403
402
  console.log(_kolorist.dim.call(void 0, " theme ") + (options.theme ? _kolorist.green.call(void 0, options.theme) : _kolorist.gray.call(void 0, "none")));
404
403
  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));
@@ -428,24 +427,8 @@ function printInfo(options, port, remote) {
428
427
  _parser.verifyConfig.call(void 0, options.data.config, options.data.themeMeta, (v) => console.warn(_kolorist.yellow.call(void 0, ` ! ${v}`)));
429
428
  console.log();
430
429
  }
431
- function isPortFree(port) {
432
- return new Promise((resolve) => {
433
- const server = _net2.default.createServer((socket) => {
434
- socket.write("Echo server\r\n");
435
- socket.pipe(socket);
436
- });
437
- server.listen(port, "127.0.0.1");
438
- server.on("error", () => {
439
- resolve(false);
440
- });
441
- server.on("listening", () => {
442
- server.close();
443
- resolve(true);
444
- });
445
- });
446
- }
447
430
  async function findFreePort(start) {
448
- if (await isPortFree(start))
431
+ if (await _getportplease.checkPort.call(void 0, start) !== false)
449
432
  return start;
450
433
  return findFreePort(start + 1);
451
434
  }
package/dist/cli.mjs CHANGED
@@ -9,23 +9,18 @@ import {
9
9
  resolveOptions,
10
10
  resolveThemeName,
11
11
  version
12
- } from "./chunk-5HOW7RNS.mjs";
12
+ } from "./chunk-CRCTWL4B.mjs";
13
13
  import {
14
14
  loadSetups,
15
15
  require_fast_deep_equal
16
- } from "./chunk-NOJBQ6MT.mjs";
16
+ } from "./chunk-36C7XM4S.mjs";
17
17
  import {
18
- __dirname,
19
- __require,
20
- __toESM,
21
- init_esm_shims
22
- } from "./chunk-T5WFA52O.mjs";
18
+ __toESM
19
+ } from "./chunk-VLEV37KF.mjs";
23
20
 
24
21
  // node/cli.ts
25
- init_esm_shims();
26
22
  var import_fast_deep_equal = __toESM(require_fast_deep_equal());
27
23
  import path from "path";
28
- import net from "net";
29
24
  import os from "os";
30
25
  import { exec } from "child_process";
31
26
  import * as readline from "readline";
@@ -37,6 +32,7 @@ import { blue, bold, cyan, dim, gray, green, underline, yellow } from "kolorist"
37
32
  import isInstalledGlobally from "is-installed-globally";
38
33
  import { verifyConfig } from "@slidev/parser";
39
34
  import { injectPreparserExtensionLoader } from "@slidev/parser/fs";
35
+ import { checkPort } from "get-port-please";
40
36
  var CONFIG_RESTART_FIELDS = [
41
37
  "highlighter",
42
38
  "monaco",
@@ -45,8 +41,7 @@ var CONFIG_RESTART_FIELDS = [
45
41
  "css"
46
42
  ];
47
43
  injectPreparserExtensionLoader(async (headmatter, filepath) => {
48
- var _a;
49
- const addons = (_a = headmatter == null ? void 0 : headmatter.addons) != null ? _a : [];
44
+ const addons = (headmatter == null ? void 0 : headmatter.addons) ?? [];
50
45
  const roots = [
51
46
  getUserRoot({}).userRoot,
52
47
  ...getAddonRoots(addons, ""),
@@ -209,7 +204,7 @@ cli.command(
209
204
  }).strict().help(),
210
205
  async (args) => {
211
206
  const { entry, theme, watch, base, download, out, inspect } = args;
212
- const { build } = await Promise.resolve().then(() => __toESM(__require("./build-2WSKFKOA.mjs")));
207
+ const { build } = await import("./build-LQUKCJTB.mjs");
213
208
  const options = await resolveOptions({ entry, theme, inspect }, "build");
214
209
  if (download && !options.data.config.download)
215
210
  options.data.config.download = download;
@@ -284,7 +279,7 @@ cli.command(
284
279
  async (args) => {
285
280
  const { entry, theme } = args;
286
281
  process.env.NODE_ENV = "production";
287
- const { exportSlides, getExportOptions } = await Promise.resolve().then(() => __toESM(__require("./export-LL3DLTJH.mjs")));
282
+ const { exportSlides, getExportOptions } = await import("./export-BAZ4BSV6.mjs");
288
283
  const port = await findFreePort(12445);
289
284
  const options = await resolveOptions({ entry, theme }, "export");
290
285
  const server = await createServer(
@@ -328,7 +323,7 @@ cli.command(
328
323
  timeout
329
324
  }) => {
330
325
  process.env.NODE_ENV = "production";
331
- const { exportNotes } = await Promise.resolve().then(() => __toESM(__require("./export-LL3DLTJH.mjs")));
326
+ const { exportNotes } = await import("./export-BAZ4BSV6.mjs");
332
327
  const port = await findFreePort(12445);
333
328
  const options = await resolveOptions({ entry }, "export");
334
329
  if (!output)
@@ -393,6 +388,9 @@ function exportOptions(args) {
393
388
  }).option("with-toc", {
394
389
  type: "boolean",
395
390
  describe: "export pages with outline"
391
+ }).option("per-slide", {
392
+ type: "boolean",
393
+ describe: "slide slides slide by slide. Works better with global components, but will break cross slide links and TOC in PDF"
396
394
  });
397
395
  }
398
396
  function printInfo(options, port, remote) {
@@ -429,24 +427,8 @@ function printInfo(options, port, remote) {
429
427
  verifyConfig(options.data.config, options.data.themeMeta, (v) => console.warn(yellow(` ! ${v}`)));
430
428
  console.log();
431
429
  }
432
- function isPortFree(port) {
433
- return new Promise((resolve) => {
434
- const server = net.createServer((socket) => {
435
- socket.write("Echo server\r\n");
436
- socket.pipe(socket);
437
- });
438
- server.listen(port, "127.0.0.1");
439
- server.on("error", () => {
440
- resolve(false);
441
- });
442
- server.on("listening", () => {
443
- server.close();
444
- resolve(true);
445
- });
446
- });
447
- }
448
430
  async function findFreePort(start) {
449
- if (await isPortFree(start))
431
+ if (await checkPort(start) !== false)
450
432
  return start;
451
433
  return findFreePort(start + 1);
452
434
  }
@@ -1,12 +1,8 @@
1
1
  import {
2
- __require,
3
- __toESM,
4
- init_esm_shims,
5
2
  packageExists
6
- } from "./chunk-T5WFA52O.mjs";
3
+ } from "./chunk-VLEV37KF.mjs";
7
4
 
8
5
  // node/export.ts
9
- init_esm_shims();
10
6
  import path from "path";
11
7
  import fs from "fs-extra";
12
8
  import { blue, cyan, dim, green, yellow } from "kolorist";
@@ -81,7 +77,7 @@ async function exportNotes({
81
77
  }) {
82
78
  if (!packageExists("playwright-chromium"))
83
79
  throw new Error("The exporting for Slidev is powered by Playwright, please installed it via `npm i -D playwright-chromium`");
84
- const { chromium } = await Promise.resolve().then(() => __toESM(__require("playwright-chromium")));
80
+ const { chromium } = await import("playwright-chromium");
85
81
  const browser = await chromium.launch();
86
82
  const context = await browser.newContext();
87
83
  const page = await context.newPage();
@@ -122,24 +118,25 @@ async function exportSlides({
122
118
  height = 1080,
123
119
  withClicks = false,
124
120
  executablePath = void 0,
125
- withToc = false
121
+ withToc = false,
122
+ perSlide = false
126
123
  }) {
127
124
  if (!packageExists("playwright-chromium"))
128
125
  throw new Error("The exporting for Slidev is powered by Playwright, please installed it via `npm i -D playwright-chromium`");
129
126
  const pages = parseRangeString(total, range);
130
- const { chromium } = await Promise.resolve().then(() => __toESM(__require("playwright-chromium")));
127
+ const { chromium } = await import("playwright-chromium");
131
128
  const browser = await chromium.launch({
132
129
  executablePath
133
130
  });
134
131
  const context = await browser.newContext({
135
132
  viewport: {
136
133
  width,
137
- height: height * pages.length
134
+ height: perSlide ? height : height * pages.length
138
135
  },
139
136
  deviceScaleFactor: 1
140
137
  });
141
138
  const page = await context.newPage();
142
- const progress = createSlidevProgress(true);
139
+ const progress = createSlidevProgress(!perSlide);
143
140
  async function go(no, clicks) {
144
141
  const path2 = `${no}?print${withClicks ? "=clicks" : ""}${clicks ? `&clicks=${clicks}` : ""}${range ? `&range=${range}` : ""}`;
145
142
  const url = routerMode === "hash" ? `http://localhost:${port}${base}#${path2}` : `http://localhost:${port}${base}${path2}`;
@@ -149,20 +146,20 @@ async function exportSlides({
149
146
  });
150
147
  await page.waitForLoadState("networkidle");
151
148
  await page.emulateMedia({ colorScheme: dark ? "dark" : "light", media: "screen" });
152
- const elements = await page.locator("[data-waitfor]");
149
+ const elements = page.locator("[data-waitfor]");
153
150
  const count = await elements.count();
154
151
  for (let index = 0; index < count; index++) {
155
- const element = await elements.nth(index);
152
+ const element = elements.nth(index);
156
153
  const attribute = await element.getAttribute("data-waitfor");
157
154
  if (attribute)
158
155
  await element.locator(attribute).waitFor();
159
156
  }
160
- const frames = await page.frames();
157
+ const frames = page.frames();
161
158
  await Promise.all(frames.map((frame) => frame.waitForLoadState()));
162
159
  }
163
160
  async function getSlidesIndex() {
164
161
  const clicksBySlide = {};
165
- const slides2 = await page.locator(".slide-container");
162
+ const slides2 = page.locator(".print-slide-container");
166
163
  const count = await slides2.count();
167
164
  for (let i = 0; i < count; i++) {
168
165
  const id = await slides2.nth(i).getAttribute("id") || "";
@@ -170,16 +167,62 @@ async function exportSlides({
170
167
  clicksBySlide[path2] = (clicksBySlide[path2] || 0) + 1;
171
168
  }
172
169
  const slideIndexes = Object.fromEntries(Object.entries(clicksBySlide).reduce((acc, [path2, clicks], i) => {
173
- var _a, _b;
174
- acc.push([path2, clicks + ((_b = (_a = acc[i - 1]) == null ? void 0 : _a[1]) != null ? _b : 0)]);
170
+ var _a;
171
+ acc.push([path2, clicks + (((_a = acc[i - 1]) == null ? void 0 : _a[1]) ?? 0)]);
175
172
  return acc;
176
173
  }, []));
177
174
  return slideIndexes;
178
175
  }
179
- async function genPagePdf() {
176
+ function getClicksFromUrl(url) {
177
+ var _a;
178
+ return (_a = url.match(/clicks=([1-9][0-9]*)/)) == null ? void 0 : _a[1];
179
+ }
180
+ async function genPageWithClicks(fn, i, clicks) {
181
+ await fn(i, clicks);
182
+ if (withClicks) {
183
+ await page.keyboard.press("ArrowRight", { delay: 100 });
184
+ const _clicks = getClicksFromUrl(page.url());
185
+ if (_clicks && clicks !== _clicks)
186
+ await genPageWithClicks(fn, i, _clicks);
187
+ }
188
+ }
189
+ async function genPagePdfPerSlide() {
190
+ const buffers = [];
191
+ const genPdfBuffer = async (i, clicks) => {
192
+ await go(i, clicks);
193
+ const pdf = await page.pdf({
194
+ width,
195
+ height,
196
+ margin: {
197
+ left: 0,
198
+ top: 0,
199
+ right: 0,
200
+ bottom: 0
201
+ },
202
+ pageRanges: "1",
203
+ printBackground: true,
204
+ preferCSSPageSize: true
205
+ });
206
+ buffers.push(pdf);
207
+ };
208
+ let idx = 0;
209
+ for (const i of pages) {
210
+ await genPageWithClicks(genPdfBuffer, i);
211
+ progress.update(++idx);
212
+ }
213
+ const mergedPdf = await PDFDocument.create({});
214
+ for (const pdfBytes of buffers) {
215
+ const pdf = await PDFDocument.load(pdfBytes);
216
+ const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices());
217
+ copiedPages.forEach((page2) => {
218
+ mergedPdf.addPage(page2);
219
+ });
220
+ }
221
+ const buffer = await mergedPdf.save();
222
+ await fs.writeFile(output, buffer);
223
+ }
224
+ async function genPagePdfOnePiece() {
180
225
  var _a;
181
- if (!output.endsWith(".pdf"))
182
- output = `${output}.pdf`;
183
226
  await go("print");
184
227
  const slideIndexes = await getSlidesIndex();
185
228
  await page.pdf({
@@ -214,10 +257,10 @@ async function exportSlides({
214
257
  pdfData = Buffer.from(await pdf.save());
215
258
  await fs.writeFile(output, pdfData);
216
259
  }
217
- async function genPagePng() {
260
+ async function genPagePngOnePiece() {
218
261
  await go("print");
219
262
  await fs.emptyDir(output);
220
- const slides2 = await page.locator(".slide-container");
263
+ const slides2 = await page.locator(".print-slide-container");
221
264
  const count = await slides2.count();
222
265
  for (let i = 0; i < count; i++) {
223
266
  progress.update(i + 1);
@@ -227,6 +270,28 @@ async function exportSlides({
227
270
  await fs.writeFile(path.join(output, `${id}.png`), buffer);
228
271
  }
229
272
  }
273
+ async function genPagePngPerSlide() {
274
+ const genScreenshot = async (i, clicks) => {
275
+ await go(i, clicks);
276
+ await page.screenshot({
277
+ omitBackground: false,
278
+ path: path.join(
279
+ output,
280
+ `${i.toString().padStart(2, "0")}${clicks ? `-${clicks}` : ""}.png`
281
+ )
282
+ });
283
+ };
284
+ for (const i of pages)
285
+ await genPageWithClicks(genScreenshot, i);
286
+ }
287
+ function genPagePdf() {
288
+ if (!output.endsWith(".pdf"))
289
+ output = `${output}.pdf`;
290
+ return perSlide ? genPagePdfPerSlide() : genPagePdfOnePiece();
291
+ }
292
+ function genPagePng() {
293
+ return perSlide ? genPagePngPerSlide() : genPagePngOnePiece();
294
+ }
230
295
  async function genPageMd(slides2) {
231
296
  const files = await fs.readdir(output);
232
297
  const mds = files.map((file, i, files2) => {
@@ -270,7 +335,8 @@ function getExportOptions(args, options, outDir, outFilename) {
270
335
  ...args,
271
336
  withClicks: args["with-clicks"],
272
337
  executablePath: args["executable-path"],
273
- withToc: args["with-toc"]
338
+ withToc: args["with-toc"],
339
+ perSlide: args["per-slide"]
274
340
  };
275
341
  const {
276
342
  entry,
@@ -281,7 +347,8 @@ function getExportOptions(args, options, outDir, outFilename) {
281
347
  dark,
282
348
  withClicks,
283
349
  executablePath,
284
- withToc
350
+ withToc,
351
+ perSlide
285
352
  } = config;
286
353
  outFilename = output || options.data.config.exportFilename || outFilename || `${path.basename(entry, ".md")}-export`;
287
354
  if (outDir)
@@ -292,14 +359,15 @@ function getExportOptions(args, options, outDir, outFilename) {
292
359
  total: options.data.slides.length,
293
360
  range,
294
361
  format: format || "pdf",
295
- timeout: timeout || 3e4,
362
+ timeout: timeout ?? 3e4,
296
363
  dark: dark || options.data.config.colorSchema === "dark",
297
364
  routerMode: options.data.config.routerMode,
298
365
  width: options.data.config.canvasWidth,
299
366
  height: Math.round(options.data.config.canvasWidth / options.data.config.aspectRatio),
300
367
  withClicks: withClicks || false,
301
368
  executablePath,
302
- withToc: withToc || false
369
+ withToc: withToc || false,
370
+ perSlide: perSlide || false
303
371
  };
304
372
  }
305
373
  export {