@v1hz/md2docx 2.6.0 → 2.7.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/index.js CHANGED
@@ -579,42 +579,113 @@ var require_browser = __commonJS((exports, module) => {
579
579
  };
580
580
  });
581
581
 
582
+ // node_modules/has-flag/index.js
583
+ var require_has_flag = __commonJS((exports, module) => {
584
+ module.exports = (flag, argv = process.argv) => {
585
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
586
+ const position2 = argv.indexOf(prefix + flag);
587
+ const terminatorPosition = argv.indexOf("--");
588
+ return position2 !== -1 && (terminatorPosition === -1 || position2 < terminatorPosition);
589
+ };
590
+ });
591
+
582
592
  // node_modules/supports-color/index.js
583
593
  var require_supports_color = __commonJS((exports, module) => {
584
- var argv = process.argv;
585
- var terminator = argv.indexOf("--");
586
- var hasFlag = function(flag) {
587
- flag = "--" + flag;
588
- var pos = argv.indexOf(flag);
589
- return pos !== -1 && (terminator !== -1 ? pos < terminator : true);
590
- };
591
- module.exports = function() {
592
- if ("FORCE_COLOR" in process.env) {
593
- return true;
594
+ var os = __require("os");
595
+ var tty = __require("tty");
596
+ var hasFlag = require_has_flag();
597
+ var { env } = process;
598
+ var forceColor;
599
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
600
+ forceColor = 0;
601
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
602
+ forceColor = 1;
603
+ }
604
+ if ("FORCE_COLOR" in env) {
605
+ if (env.FORCE_COLOR === "true") {
606
+ forceColor = 1;
607
+ } else if (env.FORCE_COLOR === "false") {
608
+ forceColor = 0;
609
+ } else {
610
+ forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
594
611
  }
595
- if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false")) {
612
+ }
613
+ function translateLevel(level) {
614
+ if (level === 0) {
596
615
  return false;
597
616
  }
598
- if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
599
- return true;
617
+ return {
618
+ level,
619
+ hasBasic: true,
620
+ has256: level >= 2,
621
+ has16m: level >= 3
622
+ };
623
+ }
624
+ function supportsColor(haveStream, streamIsTTY) {
625
+ if (forceColor === 0) {
626
+ return 0;
600
627
  }
601
- if (process.stdout && !process.stdout.isTTY) {
602
- return false;
628
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
629
+ return 3;
630
+ }
631
+ if (hasFlag("color=256")) {
632
+ return 2;
633
+ }
634
+ if (haveStream && !streamIsTTY && forceColor === undefined) {
635
+ return 0;
636
+ }
637
+ const min = forceColor || 0;
638
+ if (env.TERM === "dumb") {
639
+ return min;
603
640
  }
604
641
  if (process.platform === "win32") {
605
- return true;
642
+ const osRelease = os.release().split(".");
643
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
644
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
645
+ }
646
+ return 1;
606
647
  }
607
- if ("COLORTERM" in process.env) {
608
- return true;
648
+ if ("CI" in env) {
649
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
650
+ return 1;
651
+ }
652
+ return min;
609
653
  }
610
- if (process.env.TERM === "dumb") {
611
- return false;
654
+ if ("TEAMCITY_VERSION" in env) {
655
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
612
656
  }
613
- if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) {
614
- return true;
657
+ if (env.COLORTERM === "truecolor") {
658
+ return 3;
615
659
  }
616
- return false;
617
- }();
660
+ if ("TERM_PROGRAM" in env) {
661
+ const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
662
+ switch (env.TERM_PROGRAM) {
663
+ case "iTerm.app":
664
+ return version >= 3 ? 3 : 2;
665
+ case "Apple_Terminal":
666
+ return 2;
667
+ }
668
+ }
669
+ if (/-256(color)?$/i.test(env.TERM)) {
670
+ return 2;
671
+ }
672
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
673
+ return 1;
674
+ }
675
+ if ("COLORTERM" in env) {
676
+ return 1;
677
+ }
678
+ return min;
679
+ }
680
+ function getSupportLevel(stream) {
681
+ const level = supportsColor(stream, stream && stream.isTTY);
682
+ return translateLevel(level);
683
+ }
684
+ module.exports = {
685
+ supportsColor: getSupportLevel,
686
+ stdout: translateLevel(supportsColor(true, tty.isatty(1))),
687
+ stderr: translateLevel(supportsColor(true, tty.isatty(2)))
688
+ };
618
689
  });
619
690
 
620
691
  // node_modules/debug/src/node.js
@@ -1079,13 +1150,13 @@ var require_elk_bundled = __commonJS((exports, module) => {
1079
1150
  this.id = id + 1;
1080
1151
  msg.id = id;
1081
1152
  var self2 = this;
1082
- return new Promise(function(resolve4, reject) {
1153
+ return new Promise(function(resolve5, reject) {
1083
1154
  self2.resolvers[id] = function(err, res) {
1084
1155
  if (err) {
1085
1156
  self2.convertGwtStyleError(err);
1086
1157
  reject(err);
1087
1158
  } else {
1088
- resolve4(res);
1159
+ resolve5(res);
1089
1160
  }
1090
1161
  };
1091
1162
  self2.worker.postMessage(msg);
@@ -96120,7 +96191,7 @@ var init_dist = __esm(() => {
96120
96191
  return ret;
96121
96192
  }
96122
96193
  function once(emitter, name2) {
96123
- return new Promise(function(resolve5, reject) {
96194
+ return new Promise(function(resolve6, reject) {
96124
96195
  function errorListener(err) {
96125
96196
  emitter.removeListener(name2, resolver2);
96126
96197
  reject(err);
@@ -96128,7 +96199,7 @@ var init_dist = __esm(() => {
96128
96199
  function resolver2() {
96129
96200
  if (typeof emitter.removeListener === "function")
96130
96201
  emitter.removeListener("error", errorListener);
96131
- resolve5([].slice.call(arguments));
96202
+ resolve6([].slice.call(arguments));
96132
96203
  }
96133
96204
  eventTargetAgnosticAddListener(emitter, name2, resolver2, { once: true });
96134
96205
  if (name2 !== "error")
@@ -99412,8 +99483,8 @@ var init_dist = __esm(() => {
99412
99483
  }
99413
99484
  function fn2() {
99414
99485
  var promiseResolve, promiseReject;
99415
- var promise = new Promise(function(resolve5, reject) {
99416
- promiseResolve = resolve5;
99486
+ var promise = new Promise(function(resolve6, reject) {
99487
+ promiseResolve = resolve6;
99417
99488
  promiseReject = reject;
99418
99489
  });
99419
99490
  var args = [];
@@ -100948,14 +101019,14 @@ var init_dist = __esm(() => {
100948
101019
  };
100949
101020
  }
100950
101021
  function readAndResolve(iter) {
100951
- var resolve5 = iter[kLastResolve];
100952
- if (resolve5 !== null) {
101022
+ var resolve6 = iter[kLastResolve];
101023
+ if (resolve6 !== null) {
100953
101024
  var data = iter[kStream].read();
100954
101025
  if (data !== null) {
100955
101026
  iter[kLastPromise] = null;
100956
101027
  iter[kLastResolve] = null;
100957
101028
  iter[kLastReject] = null;
100958
- resolve5(createIterResult(data, false));
101029
+ resolve6(createIterResult(data, false));
100959
101030
  }
100960
101031
  }
100961
101032
  }
@@ -100963,13 +101034,13 @@ var init_dist = __esm(() => {
100963
101034
  process$1.nextTick(readAndResolve, iter);
100964
101035
  }
100965
101036
  function wrapForNext(lastPromise, iter) {
100966
- return function(resolve5, reject) {
101037
+ return function(resolve6, reject) {
100967
101038
  lastPromise.then(function() {
100968
101039
  if (iter[kEnded]) {
100969
- resolve5(createIterResult(undefined, true));
101040
+ resolve6(createIterResult(undefined, true));
100970
101041
  return;
100971
101042
  }
100972
- iter[kHandlePromise](resolve5, reject);
101043
+ iter[kHandlePromise](resolve6, reject);
100973
101044
  }, reject);
100974
101045
  };
100975
101046
  }
@@ -100986,12 +101057,12 @@ var init_dist = __esm(() => {
100986
101057
  if (this[kEnded])
100987
101058
  return Promise.resolve(createIterResult(undefined, true));
100988
101059
  if (this[kStream].destroyed)
100989
- return new Promise(function(resolve5, reject) {
101060
+ return new Promise(function(resolve6, reject) {
100990
101061
  process$1.nextTick(function() {
100991
101062
  if (_this[kError])
100992
101063
  reject(_this[kError]);
100993
101064
  else
100994
- resolve5(createIterResult(undefined, true));
101065
+ resolve6(createIterResult(undefined, true));
100995
101066
  });
100996
101067
  });
100997
101068
  var lastPromise = this[kLastPromise];
@@ -101011,13 +101082,13 @@ var init_dist = __esm(() => {
101011
101082
  return this;
101012
101083
  }), _defineProperty2(_Object$setPrototypeO, "return", function _return() {
101013
101084
  var _this2 = this;
101014
- return new Promise(function(resolve5, reject) {
101085
+ return new Promise(function(resolve6, reject) {
101015
101086
  _this2[kStream].destroy(null, function(err) {
101016
101087
  if (err) {
101017
101088
  reject(err);
101018
101089
  return;
101019
101090
  }
101020
- resolve5(createIterResult(undefined, true));
101091
+ resolve6(createIterResult(undefined, true));
101021
101092
  });
101022
101093
  });
101023
101094
  }), _Object$setPrototypeO), AsyncIteratorPrototype);
@@ -101039,15 +101110,15 @@ var init_dist = __esm(() => {
101039
101110
  value: stream._readableState.endEmitted,
101040
101111
  writable: true
101041
101112
  }), _defineProperty2(_Object$create, kHandlePromise, {
101042
- value: function value2(resolve5, reject) {
101113
+ value: function value2(resolve6, reject) {
101043
101114
  var data = iterator[kStream].read();
101044
101115
  if (data) {
101045
101116
  iterator[kLastPromise] = null;
101046
101117
  iterator[kLastResolve] = null;
101047
101118
  iterator[kLastReject] = null;
101048
- resolve5(createIterResult(data, false));
101119
+ resolve6(createIterResult(data, false));
101049
101120
  } else {
101050
- iterator[kLastResolve] = resolve5;
101121
+ iterator[kLastResolve] = resolve6;
101051
101122
  iterator[kLastReject] = reject;
101052
101123
  }
101053
101124
  },
@@ -101066,12 +101137,12 @@ var init_dist = __esm(() => {
101066
101137
  iterator[kError] = err;
101067
101138
  return;
101068
101139
  }
101069
- var resolve5 = iterator[kLastResolve];
101070
- if (resolve5 !== null) {
101140
+ var resolve6 = iterator[kLastResolve];
101141
+ if (resolve6 !== null) {
101071
101142
  iterator[kLastPromise] = null;
101072
101143
  iterator[kLastResolve] = null;
101073
101144
  iterator[kLastReject] = null;
101074
- resolve5(createIterResult(undefined, true));
101145
+ resolve6(createIterResult(undefined, true));
101075
101146
  }
101076
101147
  iterator[kEnded] = true;
101077
101148
  });
@@ -113877,7 +113948,7 @@ Actual: ` + parser.attribValue);
113877
113948
  }
113878
113949
  }
113879
113950
  function add(value2, last) {
113880
- format(append, resolve5(value2, indent2, indent2 ? 1 : 0), last);
113951
+ format(append, resolve6(value2, indent2, indent2 ? 1 : 0), last);
113881
113952
  }
113882
113953
  function end() {
113883
113954
  if (stream) {
@@ -113921,13 +113992,13 @@ Actual: ` + parser.attribValue);
113921
113992
  return output;
113922
113993
  }
113923
113994
  function element() {
113924
- var self2 = { _elem: resolve5(Array.prototype.slice.call(arguments)) };
113995
+ var self2 = { _elem: resolve6(Array.prototype.slice.call(arguments)) };
113925
113996
  self2.push = function(input) {
113926
113997
  if (!this.append)
113927
113998
  throw new Error("not assigned to a parent!");
113928
113999
  var that = this;
113929
114000
  var indent2 = this._elem.indent;
113930
- format(this.append, resolve5(input, indent2, this._elem.icount + (indent2 ? 1 : 0)), function() {
114001
+ format(this.append, resolve6(input, indent2, this._elem.icount + (indent2 ? 1 : 0)), function() {
113931
114002
  that.append(true);
113932
114003
  });
113933
114004
  };
@@ -113942,7 +114013,7 @@ Actual: ` + parser.attribValue);
113942
114013
  function create_indent(character, count) {
113943
114014
  return new Array(count || 0).join(character || "");
113944
114015
  }
113945
- function resolve5(data, indent2, indent_count) {
114016
+ function resolve6(data, indent2, indent_count) {
113946
114017
  indent_count = indent_count || 0;
113947
114018
  var indent_spaces = create_indent(indent2, indent_count);
113948
114019
  var name2;
@@ -113983,7 +114054,7 @@ Actual: ` + parser.attribValue);
113983
114054
  if (Object.keys(value2)[0] == "_attr")
113984
114055
  get_attributes(value2._attr);
113985
114056
  else
113986
- content3.push(resolve5(value2, indent2, indent_count + 1));
114057
+ content3.push(resolve6(value2, indent2, indent_count + 1));
113987
114058
  else {
113988
114059
  content3.pop();
113989
114060
  isStringContent = true;
@@ -128401,7 +128472,7 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
128401
128472
  // package.json
128402
128473
  var package_default = {
128403
128474
  name: "@v1hz/md2docx",
128404
- version: "2.6.0",
128475
+ version: "2.7.0",
128405
128476
  description: "基于 pandoc 的 Markdown 转 Word 工具,自动格式化 Markdown,支持自定义样式,AI 友好,用户友好。",
128406
128477
  keywords: [
128407
128478
  "converter",
@@ -128431,6 +128502,7 @@ var package_default = {
128431
128502
  "LICENSE"
128432
128503
  ],
128433
128504
  type: "module",
128505
+ main: "dist-electron/main.js",
128434
128506
  module: "dist/index.js",
128435
128507
  scripts: {
128436
128508
  cli: "bun run src/index.ts",
@@ -128439,7 +128511,16 @@ var package_default = {
128439
128511
  "build:exe": "bun run clean:dist && bun build src/index.ts --compile --outfile dist/md2docx.exe",
128440
128512
  prepack: "bun run build",
128441
128513
  test: "bun test",
128442
- check: "bun tsc --noEmit && bun run oxlint && bun run oxfmt"
128514
+ check: "bun tsc --noEmit && bun run oxlint && bun run oxfmt",
128515
+ "build:electron": "bun build --target=node --format=esm --outdir=dist-electron --asset-naming=[name].[ext] -e electron ./electron/main.ts && bun build --target=node --format=cjs --outfile=dist-electron/preload.cjs -e electron ./electron/preload.ts",
128516
+ "build:frontend": "bun run scripts/generate-icon.ts && vite build --config frontend/vite.config.ts",
128517
+ electron: "bun run build:electron && bun run build:frontend && electron .",
128518
+ "dev:frontend": "vite --config frontend/vite.config.ts",
128519
+ "dev:electron": "bun run build:electron && electron .",
128520
+ dev: "bun run scripts/dev.ts",
128521
+ pack: "bun run build:electron && bun run build:frontend && electron-builder --win nsis",
128522
+ "pack:setup": "bun run pack",
128523
+ "pack:portable": "bun run build:electron && bun run build:frontend && electron-builder --win portable"
128443
128524
  },
128444
128525
  dependencies: {
128445
128526
  "@resvg/resvg-wasm": "2.6.2",
@@ -128447,21 +128528,32 @@ var package_default = {
128447
128528
  "beautiful-mermaid": "^1.1.3",
128448
128529
  commander: "^15.0.0",
128449
128530
  docx: "^9.7.1",
128531
+ "electron-updater": "^6.8.9",
128532
+ "lucide-vue-next": "^1.0.0",
128450
128533
  pizzip: "^3.2.0",
128451
128534
  "remark-frontmatter": "^5.0.0",
128452
128535
  "remark-gfm": "^4.0.1",
128453
128536
  "remark-parse": "^11.0.0",
128454
128537
  "remark-stringify": "^11.0.0",
128455
128538
  unified: "^11.0.5",
128539
+ vue: "^3.5.40",
128456
128540
  xpath: "^0.0.34"
128457
128541
  },
128458
128542
  devDependencies: {
128543
+ "@tailwindcss/vite": "^4.3.3",
128459
128544
  "@types/bun": "^1.3.14",
128460
128545
  "@types/node": "^24.0.0",
128546
+ "@vitejs/plugin-vue": "^6.0.8",
128547
+ "@vue/test-utils": "^2.4.11",
128548
+ electron: "^43.2.0",
128549
+ "electron-builder": "^26.15.3",
128550
+ "happy-dom": "^20.11.1",
128461
128551
  oxfmt: "^0.58.0",
128462
128552
  oxlint: "^1.73.0",
128463
128553
  sharp: "^0.35.3",
128464
- typescript: "^7.0.2"
128554
+ tailwindcss: "^4.3.3",
128555
+ typescript: "^7.0.2",
128556
+ vite: "^8.1.5"
128465
128557
  },
128466
128558
  engines: {
128467
128559
  node: ">=22.12.0"
@@ -128576,7 +128668,7 @@ function cleanIntermediateFiles(paths = { targetDir: TMP_DIR, homeDir: homedir2(
128576
128668
  // src/commands/convert.ts
128577
128669
  import { existsSync as existsSync7, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
128578
128670
  import { spawn } from "node:child_process";
128579
- import { dirname as dirname7, parse as parse4, resolve as resolve5 } from "node:path";
128671
+ import { dirname as dirname7, parse as parse4, resolve as resolve6 } from "node:path";
128580
128672
 
128581
128673
  // src/config.ts
128582
128674
  import { access, readFile } from "node:fs/promises";
@@ -128594,16 +128686,26 @@ async function loadConfig(path2) {
128594
128686
  throw new Error(`配置文件不是有效的 JSON:${path2}
128595
128687
  ${message}`);
128596
128688
  }
128597
- validateConfig(raw, path2);
128598
- delete raw.$schema;
128599
- return raw;
128689
+ return validateConfigValue(raw, path2);
128600
128690
  }
128601
- function validateConfig(value, path2) {
128691
+ function validateConfigValue(value, path2) {
128602
128692
  const root = expectRecord(value, path2, "配置");
128693
+ rejectUnknown(root, [
128694
+ "$schema",
128695
+ "figureCaption",
128696
+ "tableCaption",
128697
+ "normalizeHeadings",
128698
+ "numberHeadings",
128699
+ "renderMermaid",
128700
+ "imageSize",
128701
+ "detectTitle",
128702
+ "removeThematicBreaks"
128703
+ ], path2, "配置");
128603
128704
  validateCaption(root.figureCaption, path2, "figureCaption");
128604
128705
  validateCaption(root.tableCaption, path2, "tableCaption");
128605
128706
  validateEnabled(root.normalizeHeadings, path2, "normalizeHeadings");
128606
128707
  const numbering = expectRecord(root.numberHeadings, path2, "numberHeadings");
128708
+ rejectUnknown(numbering, ["enabled", "detectExisting", "existingPattern", "useBuiltinRules"], path2, "numberHeadings");
128607
128709
  expectBoolean(numbering.enabled, path2, "numberHeadings.enabled");
128608
128710
  expectBoolean(numbering.detectExisting, path2, "numberHeadings.detectExisting");
128609
128711
  if (numbering.existingPattern !== undefined) {
@@ -128613,31 +128715,39 @@ function validateConfig(value, path2) {
128613
128715
  expectBoolean(numbering.useBuiltinRules, path2, "numberHeadings.useBuiltinRules");
128614
128716
  }
128615
128717
  const mermaid = expectRecord(root.renderMermaid, path2, "renderMermaid");
128718
+ rejectUnknown(mermaid, ["enabled", "theme", "density"], path2, "renderMermaid");
128616
128719
  expectBoolean(mermaid.enabled, path2, "renderMermaid.enabled");
128617
128720
  expectString(mermaid.theme, path2, "renderMermaid.theme");
128618
128721
  if (!Number.isInteger(mermaid.density) || mermaid.density < 72) {
128619
128722
  invalidConfig(path2, "renderMermaid.density", "必须是不小于 72 的整数");
128620
128723
  }
128621
128724
  const imageSize = expectRecord(root.imageSize, path2, "imageSize");
128725
+ rejectUnknown(imageSize, ["enabled", "maxWidthCm", "maxHeightCm"], path2, "imageSize");
128622
128726
  expectBoolean(imageSize.enabled, path2, "imageSize.enabled");
128623
128727
  expectPositiveNumber(imageSize.maxWidthCm, path2, "imageSize.maxWidthCm");
128624
128728
  expectPositiveNumber(imageSize.maxHeightCm, path2, "imageSize.maxHeightCm");
128625
128729
  validateEnabled(root.removeThematicBreaks, path2, "removeThematicBreaks");
128626
128730
  const title = expectRecord(root.detectTitle, path2, "detectTitle");
128731
+ rejectUnknown(title, ["enabled", "strategy"], path2, "detectTitle");
128627
128732
  expectBoolean(title.enabled, path2, "detectTitle.enabled");
128628
128733
  const strategy = expectString(title.strategy, path2, "detectTitle.strategy");
128629
128734
  if (!["first-h1", "single-h1", "filename", "none"].includes(strategy)) {
128630
128735
  invalidConfig(path2, "detectTitle.strategy", "不是支持的标题提取策略");
128631
128736
  }
128737
+ const result = structuredClone(root);
128738
+ delete result.$schema;
128739
+ return result;
128632
128740
  }
128633
128741
  function validateCaption(value, path2, field) {
128634
128742
  const caption = expectRecord(value, path2, field);
128743
+ rejectUnknown(caption, ["enabled", "format", "separator"], path2, field);
128635
128744
  expectBoolean(caption.enabled, path2, `${field}.enabled`);
128636
128745
  expectString(caption.format, path2, `${field}.format`);
128637
128746
  expectString(caption.separator, path2, `${field}.separator`);
128638
128747
  }
128639
128748
  function validateEnabled(value, path2, field) {
128640
128749
  const config = expectRecord(value, path2, field);
128750
+ rejectUnknown(config, ["enabled"], path2, field);
128641
128751
  expectBoolean(config.enabled, path2, `${field}.enabled`);
128642
128752
  }
128643
128753
  function expectRecord(value, path2, field) {
@@ -128662,6 +128772,11 @@ function expectPositiveNumber(value, path2, field) {
128662
128772
  }
128663
128773
  return value;
128664
128774
  }
128775
+ function rejectUnknown(value, allowed, path2, field) {
128776
+ const unknown = Object.keys(value).find((key) => !allowed.includes(key));
128777
+ if (unknown !== undefined)
128778
+ invalidConfig(path2, `${field}.${unknown}`, "不是支持的配置项");
128779
+ }
128665
128780
  function invalidConfig(path2, field, reason) {
128666
128781
  throw new Error(`配置文件无效:${path2}
128667
128782
  位置:${field}
@@ -128672,6 +128787,7 @@ function invalidConfig(path2, field, reason) {
128672
128787
  import {
128673
128788
  copyFileSync,
128674
128789
  existsSync as existsSync4,
128790
+ lstatSync as lstatSync2,
128675
128791
  mkdirSync as mkdirSync3,
128676
128792
  mkdtempSync,
128677
128793
  readdirSync,
@@ -128682,7 +128798,7 @@ import {
128682
128798
  writeFileSync as writeFileSync2
128683
128799
  } from "node:fs";
128684
128800
  import { randomUUID } from "node:crypto";
128685
- import { dirname as dirname4, join as join3 } from "node:path";
128801
+ import { basename, dirname as dirname4, join as join3, resolve as resolve4 } from "node:path";
128686
128802
 
128687
128803
  // src/output.ts
128688
128804
  import { existsSync as existsSync2, mkdirSync, statSync } from "node:fs";
@@ -129897,7 +130013,7 @@ import { readFileSync as readFileSync2 } from "node:fs";
129897
130013
  // src/style/config.ts
129898
130014
  function validateStyleConfig(value, path2) {
129899
130015
  const root = expectRecord2(value, path2, "样式配置");
129900
- rejectUnknown(root, ["$schema", "schemaVersion", "options"], path2, "样式配置");
130016
+ rejectUnknown2(root, ["$schema", "schemaVersion", "options"], path2, "样式配置");
129901
130017
  if (root.$schema !== undefined)
129902
130018
  expectString2(root.$schema, path2, "$schema");
129903
130019
  if (root.schemaVersion !== 1)
@@ -129908,10 +130024,10 @@ function validateStyleConfig(value, path2) {
129908
130024
  }
129909
130025
  function validateOptions(value, path2) {
129910
130026
  const options = expectRecord2(value, path2, "options");
129911
- rejectUnknown(options, ["body", "headings", "inlineCode", "codeBlock"], path2, "options");
130027
+ rejectUnknown2(options, ["body", "headings", "inlineCode", "codeBlock"], path2, "options");
129912
130028
  if (options.body !== undefined) {
129913
130029
  const body = expectRecord2(options.body, path2, "options.body");
129914
- rejectUnknown(body, ["firstLineIndent", "lineSpacing"], path2, "options.body");
130030
+ rejectUnknown2(body, ["firstLineIndent", "lineSpacing"], path2, "options.body");
129915
130031
  if (body.firstLineIndent !== undefined) {
129916
130032
  expectBoolean2(body.firstLineIndent, path2, "options.body.firstLineIndent");
129917
130033
  }
@@ -129923,7 +130039,7 @@ function validateOptions(value, path2) {
129923
130039
  }
129924
130040
  if (options.headings !== undefined) {
129925
130041
  const headings = expectRecord2(options.headings, path2, "options.headings");
129926
- rejectUnknown(headings, ["1", "2", "3", "4", "5", "6"], path2, "options.headings");
130042
+ rejectUnknown2(headings, ["1", "2", "3", "4", "5", "6"], path2, "options.headings");
129927
130043
  validateHeading(headings, "1", ["startOnNewPage", "alignment", "bold"], path2);
129928
130044
  validateHeading(headings, "2", ["bold"], path2);
129929
130045
  validateHeading(headings, "3", ["bold"], path2);
@@ -129933,14 +130049,14 @@ function validateOptions(value, path2) {
129933
130049
  }
129934
130050
  if (options.inlineCode !== undefined) {
129935
130051
  const inlineCode = expectRecord2(options.inlineCode, path2, "options.inlineCode");
129936
- rejectUnknown(inlineCode, ["background"], path2, "options.inlineCode");
130052
+ rejectUnknown2(inlineCode, ["background"], path2, "options.inlineCode");
129937
130053
  if (inlineCode.background !== undefined) {
129938
130054
  expectBoolean2(inlineCode.background, path2, "options.inlineCode.background");
129939
130055
  }
129940
130056
  }
129941
130057
  if (options.codeBlock !== undefined) {
129942
130058
  const codeBlock = expectRecord2(options.codeBlock, path2, "options.codeBlock");
129943
- rejectUnknown(codeBlock, ["border"], path2, "options.codeBlock");
130059
+ rejectUnknown2(codeBlock, ["border"], path2, "options.codeBlock");
129944
130060
  if (codeBlock.border !== undefined) {
129945
130061
  expectBoolean2(codeBlock.border, path2, "options.codeBlock.border");
129946
130062
  }
@@ -129951,7 +130067,7 @@ function validateHeading(headings, level, allowed, path2) {
129951
130067
  return;
129952
130068
  const field = `options.headings["${level}"]`;
129953
130069
  const heading = expectRecord2(headings[level], path2, field);
129954
- rejectUnknown(heading, allowed, path2, field);
130070
+ rejectUnknown2(heading, allowed, path2, field);
129955
130071
  if (heading.startOnNewPage !== undefined) {
129956
130072
  expectBoolean2(heading.startOnNewPage, path2, `${field}.startOnNewPage`);
129957
130073
  }
@@ -129963,7 +130079,7 @@ function validateHeading(headings, level, allowed, path2) {
129963
130079
  if (heading.italic !== undefined)
129964
130080
  expectBoolean2(heading.italic, path2, `${field}.italic`);
129965
130081
  }
129966
- function rejectUnknown(value, allowed, path2, field) {
130082
+ function rejectUnknown2(value, allowed, path2, field) {
129967
130083
  const unknown = Object.keys(value).find((key) => !allowed.includes(key));
129968
130084
  if (unknown !== undefined)
129969
130085
  invalidStyleConfig(path2, `${field}.${unknown}`, "不是支持的配置项");
@@ -130000,6 +130116,9 @@ var HEADING_LEVELS = ["1", "2", "3", "4", "5", "6"];
130000
130116
  function resolveEffectiveStyles(sources, defaults) {
130001
130117
  const rawPath = sources.styleRawPath ?? defaults?.styleRawPath ?? materializeDefaultStyleRaw();
130002
130118
  const rawStyle = loadStyleRaw(rawPath);
130119
+ if (sources.styleConfig) {
130120
+ return compileStyleConfig(rawStyle, sources.styleConfig);
130121
+ }
130003
130122
  if (sources.styleConfigPath) {
130004
130123
  return compileStyleConfig(rawStyle, loadStyleConfig(sources.styleConfigPath));
130005
130124
  }
@@ -130190,10 +130309,12 @@ function readCurrentPresetName(paths = DEFAULT_STORAGE_PATHS) {
130190
130309
  throw new Error(`预设设置不是有效的 JSON:${paths.settingsPath}
130191
130310
  ${message}`);
130192
130311
  }
130312
+ if (isLegacyDesktopSettings(value))
130313
+ return DEFAULT_PRESET_NAME;
130193
130314
  if (!isRecord3(value) || value.schemaVersion !== 1 || typeof value.preset !== "string") {
130194
130315
  throw new Error(`预设设置无效:${paths.settingsPath}`);
130195
130316
  }
130196
- const unknownKeys = Object.keys(value).filter((key) => key !== "schemaVersion" && key !== "preset");
130317
+ const unknownKeys = Object.keys(value).filter((key) => key !== "schemaVersion" && key !== "preset" && key !== "desktop");
130197
130318
  if (unknownKeys.length > 0) {
130198
130319
  throw new Error(`预设设置无效:${paths.settingsPath}
130199
130320
  未知字段:${unknownKeys.join(", ")}`);
@@ -130277,7 +130398,12 @@ async function usePreset(name2, paths = DEFAULT_STORAGE_PATHS) {
130277
130398
  await resolvePresetByName(name2, paths);
130278
130399
  mkdirSync3(dirname4(paths.settingsPath), { recursive: true });
130279
130400
  const temporary = `${paths.settingsPath}.${process.pid}.${randomUUID()}.tmp`;
130280
- writeFileSync2(temporary, `${JSON.stringify({ schemaVersion: 1, preset: name2 }, null, 2)}
130401
+ const desktop = readExistingDesktopSettings(paths.settingsPath);
130402
+ writeFileSync2(temporary, `${JSON.stringify({
130403
+ schemaVersion: 1,
130404
+ preset: name2,
130405
+ ...desktop ? { desktop } : {}
130406
+ }, null, 2)}
130281
130407
  `, "utf-8");
130282
130408
  try {
130283
130409
  renameSync(temporary, paths.settingsPath);
@@ -130286,6 +130412,18 @@ async function usePreset(name2, paths = DEFAULT_STORAGE_PATHS) {
130286
130412
  throw error;
130287
130413
  }
130288
130414
  }
130415
+ function readExistingDesktopSettings(settingsPath) {
130416
+ if (!existsSync4(settingsPath))
130417
+ return;
130418
+ try {
130419
+ const value = JSON.parse(readFileSync3(settingsPath, "utf-8"));
130420
+ if (isLegacyDesktopSettings(value))
130421
+ return value;
130422
+ return isRecord3(value) && isRecord3(value.desktop) ? value.desktop : undefined;
130423
+ } catch {
130424
+ return;
130425
+ }
130426
+ }
130289
130427
  async function savePreset(input, paths = DEFAULT_STORAGE_PATHS) {
130290
130428
  assertPresetName(input.name);
130291
130429
  if (input.name === DEFAULT_PRESET_NAME)
@@ -130372,6 +130510,12 @@ function assertPresetName(name2) {
130372
130510
  function isRecord3(value) {
130373
130511
  return typeof value === "object" && value !== null && !Array.isArray(value);
130374
130512
  }
130513
+ function isLegacyDesktopSettings(value) {
130514
+ if (!isRecord3(value))
130515
+ return false;
130516
+ const keys = Object.keys(value);
130517
+ return keys.length === 3 && keys.every((key) => ["outputMode", "outputFolder", "conflictAction"].includes(key)) && ["source", "folder", "ask"].includes(String(value.outputMode)) && typeof value.outputFolder === "string" && ["overwrite", "rename", "ask"].includes(String(value.conflictAction));
130518
+ }
130375
130519
 
130376
130520
  // src/preprocess/index.ts
130377
130521
  import { readFile as readFile3 } from "node:fs/promises";
@@ -130664,10 +130808,10 @@ class VFile {
130664
130808
  get basename() {
130665
130809
  return typeof this.path === "string" ? default2.basename(this.path) : undefined;
130666
130810
  }
130667
- set basename(basename) {
130668
- assertNonEmpty(basename, "basename");
130669
- assertPart(basename, "basename");
130670
- this.path = default2.join(this.dirname || "", basename);
130811
+ set basename(basename2) {
130812
+ assertNonEmpty(basename2, "basename");
130813
+ assertPart(basename2, "basename");
130814
+ this.path = default2.join(this.dirname || "", basename2);
130671
130815
  }
130672
130816
  get dirname() {
130673
130817
  return typeof this.path === "string" ? default2.dirname(this.path) : undefined;
@@ -130851,7 +130995,7 @@ class Processor extends CallableInstance {
130851
130995
  assertParser("process", this.parser || this.Parser);
130852
130996
  assertCompiler("process", this.compiler || this.Compiler);
130853
130997
  return done ? executor(undefined, done) : new Promise(executor);
130854
- function executor(resolve4, reject) {
130998
+ function executor(resolve5, reject) {
130855
130999
  const realFile = vfile(file);
130856
131000
  const parseTree = self2.parse(realFile);
130857
131001
  self2.run(parseTree, realFile, function(error, tree, file2) {
@@ -130870,8 +131014,8 @@ class Processor extends CallableInstance {
130870
131014
  function realDone(error, file2) {
130871
131015
  if (error || !file2) {
130872
131016
  reject(error);
130873
- } else if (resolve4) {
130874
- resolve4(file2);
131017
+ } else if (resolve5) {
131018
+ resolve5(file2);
130875
131019
  } else {
130876
131020
  ok(done, "`done` is defined if `resolve` is not");
130877
131021
  done(undefined, file2);
@@ -130904,7 +131048,7 @@ class Processor extends CallableInstance {
130904
131048
  file = undefined;
130905
131049
  }
130906
131050
  return done ? executor(undefined, done) : new Promise(executor);
130907
- function executor(resolve4, reject) {
131051
+ function executor(resolve5, reject) {
130908
131052
  ok(typeof file !== "function", "`file` can’t be a `done` anymore, we checked");
130909
131053
  const realFile = vfile(file);
130910
131054
  transformers.run(tree, realFile, realDone);
@@ -130912,8 +131056,8 @@ class Processor extends CallableInstance {
130912
131056
  const resultingTree = outputTree || tree;
130913
131057
  if (error) {
130914
131058
  reject(error);
130915
- } else if (resolve4) {
130916
- resolve4(resultingTree);
131059
+ } else if (resolve5) {
131060
+ resolve5(resultingTree);
130917
131061
  } else {
130918
131062
  ok(done, "`done` is defined if `resolve` is not");
130919
131063
  done(undefined, resultingTree, file2);
@@ -133993,10 +134137,10 @@ function resolveAll(constructs2, events, context) {
133993
134137
  const called = [];
133994
134138
  let index2 = -1;
133995
134139
  while (++index2 < constructs2.length) {
133996
- const resolve4 = constructs2[index2].resolveAll;
133997
- if (resolve4 && !called.includes(resolve4)) {
133998
- events = resolve4(events, context);
133999
- called.push(resolve4);
134140
+ const resolve5 = constructs2[index2].resolveAll;
134141
+ if (resolve5 && !called.includes(resolve5)) {
134142
+ events = resolve5(events, context);
134143
+ called.push(resolve5);
134000
134144
  }
134001
134145
  }
134002
134146
  return events;
@@ -142096,7 +142240,7 @@ function stripPictureNum(text5, format) {
142096
142240
  import { existsSync as existsSync5, mkdirSync as mkdirSync4, writeFileSync as writeFileSync3 } from "node:fs";
142097
142241
  import { readFile as readFile2 } from "node:fs/promises";
142098
142242
  import { homedir as homedir3 } from "node:os";
142099
- import { dirname as dirname5, isAbsolute, join as join5, resolve as resolve4 } from "node:path";
142243
+ import { dirname as dirname5, isAbsolute, join as join5, resolve as resolve5 } from "node:path";
142100
142244
  import { fileURLToPath as fileURLToPath2 } from "node:url";
142101
142245
 
142102
142246
  // node_modules/@resvg/resvg-wasm/index.mjs
@@ -147497,7 +147641,7 @@ function renderMermaidSVG(text5, options = {}) {
147497
147641
  // src/preprocess/mermaid.ts
147498
147642
  var wasmInitialization;
147499
147643
  var fontLoading;
147500
- var RESVG_WASM_PATH = isAbsolute(index_bg_default) ? index_bg_default : resolve4(dirname5(fileURLToPath2(import.meta.url)), index_bg_default);
147644
+ var RESVG_WASM_PATH = isAbsolute(index_bg_default) ? index_bg_default : resolve5(dirname5(fileURLToPath2(import.meta.url)), index_bg_default);
147501
147645
  function initializeResvg() {
147502
147646
  const wasm2 = typeof Bun === "undefined" ? readFile2(RESVG_WASM_PATH) : Bun.file(RESVG_WASM_PATH).arrayBuffer();
147503
147647
  wasmInitialization ??= initWasm(wasm2);
@@ -147508,7 +147652,7 @@ function loadSystemFonts() {
147508
147652
  return fontLoading;
147509
147653
  }
147510
147654
  async function loadSystemFontsUncached() {
147511
- const fontPaths = process.platform === "win32" ? ["msyh.ttc", "msyhbd.ttc", "arial.ttf", "consola.ttf"].map((name2) => resolve4(process.env.WINDIR ?? "C:/Windows", "Fonts", name2)) : process.platform === "darwin" ? [
147655
+ const fontPaths = process.platform === "win32" ? ["msyh.ttc", "msyhbd.ttc", "arial.ttf", "consola.ttf"].map((name2) => resolve5(process.env.WINDIR ?? "C:/Windows", "Fonts", name2)) : process.platform === "darwin" ? [
147512
147656
  "/System/Library/Fonts/PingFang.ttc",
147513
147657
  "/System/Library/Fonts/Helvetica.ttc",
147514
147658
  "/System/Library/Fonts/Menlo.ttc"
@@ -147837,7 +147981,7 @@ async function ensureTemplateDocx(rawStyle) {
147837
147981
  }
147838
147982
 
147839
147983
  // src/commands/convert.ts
147840
- async function convertMarkdown(options) {
147984
+ async function convertMarkdown(options, overrides = {}) {
147841
147985
  if (!options.file)
147842
147986
  throw new Error("缺少必填参数:--file");
147843
147987
  const input = resolveInputPath(options.file, [".md", ".markdown"], "Markdown 文件");
@@ -147848,13 +147992,19 @@ async function convertMarkdown(options) {
147848
147992
  const baseName = parse4(input).name;
147849
147993
  const output = resolveOutputPath(options.output, `${baseName}.docx`, [".docx"], "DOCX 输出文件");
147850
147994
  prepareOutput(output);
147851
- const config = await loadConfig(configPath);
147995
+ const config = overrides.config ? validateConfigValue(structuredClone(overrides.config), "桌面转换设置") : await loadConfig(configPath);
147852
147996
  const outDir = preprocessDir(input);
147853
147997
  mkdirSync6(outDir, { recursive: true });
147854
147998
  const formatted = await preprocess2(input, config, outDir);
147855
147999
  const markdownOutput = formattedMdPath(input);
147856
148000
  writeFileSync4(markdownOutput, formatted, "utf-8");
147857
- const effectiveStyles = resolveEffectiveStyles({ styleRawPath, styleConfigPath }, { styleRawPath: preset.styleRawPath, styleConfigPath: preset.styleConfigPath });
148001
+ const effectiveStyles = resolveEffectiveStyles({
148002
+ styleRawPath,
148003
+ styleConfigPath,
148004
+ ...overrides.styleConfig ? {
148005
+ styleConfig: validateStyleConfig(structuredClone(overrides.styleConfig), "桌面转换样式")
148006
+ } : {}
148007
+ }, { styleRawPath: preset.styleRawPath, styleConfigPath: preset.styleConfigPath });
147858
148008
  const templatePath = await ensureTemplateDocx(effectiveStyles);
147859
148009
  const inlineCodeFilter = materializeInlineCodeFilter();
147860
148010
  const imageSizeArgs = config.imageSize.enabled ? buildImageSizePandocArgs(config.imageSize, materializeImageSizeFilter()) : [];
@@ -147883,13 +148033,13 @@ function buildImageSizePandocArgs(config, filterPath) {
147883
148033
  ];
147884
148034
  }
147885
148035
  function buildPandocResourcePathArgs(inputPath, workingDirectory = process.cwd()) {
147886
- const workingDir = resolve5(workingDirectory);
147887
- const sourceDir = dirname7(resolve5(inputPath));
148036
+ const workingDir = resolve6(workingDirectory);
148037
+ const sourceDir = dirname7(resolve6(inputPath));
147888
148038
  const searchDirs = workingDir === sourceDir ? [sourceDir] : [workingDir, sourceDir];
147889
148039
  return searchDirs.map((directory) => `--resource-path=${directory}`);
147890
148040
  }
147891
148041
  function runProcess(command, args) {
147892
- return new Promise((resolve6, reject) => {
148042
+ return new Promise((resolve7, reject) => {
147893
148043
  const child = spawn(command, args, { stdio: ["ignore", "ignore", "pipe"], windowsHide: true });
147894
148044
  let stderr = "";
147895
148045
  child.stderr.setEncoding("utf-8");
@@ -147897,7 +148047,7 @@ function runProcess(command, args) {
147897
148047
  stderr += chunk;
147898
148048
  });
147899
148049
  child.once("error", reject);
147900
- child.once("close", (exitCode) => resolve6({ exitCode: exitCode ?? 1, stderr }));
148050
+ child.once("close", (exitCode) => resolve7({ exitCode: exitCode ?? 1, stderr }));
147901
148051
  });
147902
148052
  }
147903
148053
 
@@ -148555,7 +148705,7 @@ async function exportStyleConfig(options) {
148555
148705
 
148556
148706
  // src/commands/format.ts
148557
148707
  import { existsSync as existsSync8, rmSync as rmSync3, writeFileSync as writeFileSync6 } from "node:fs";
148558
- import { basename, dirname as dirname8, parse as parse6, resolve as resolve6 } from "node:path";
148708
+ import { basename as basename2, dirname as dirname8, parse as parse6, resolve as resolve7 } from "node:path";
148559
148709
  async function formatMarkdown(options) {
148560
148710
  const input = resolveInputPath(options.file, [".md", ".markdown"], "Markdown 文件");
148561
148711
  const preset = await resolvePresetConfig(options.preset);
@@ -148566,14 +148716,14 @@ async function formatMarkdown(options) {
148566
148716
  const config = await loadConfig(configPath);
148567
148717
  const outputName = parse6(output).name;
148568
148718
  const assetsName = `${outputName}_assets`;
148569
- const assetsDir = resolve6(dirname8(output), assetsName);
148719
+ const assetsDir = resolve7(dirname8(output), assetsName);
148570
148720
  if (config.renderMermaid.enabled && existsSync8(assetsDir)) {
148571
- const parent = resolve6(dirname8(output));
148721
+ const parent = resolve7(dirname8(output));
148572
148722
  if (dirname8(assetsDir) !== parent)
148573
148723
  throw new Error(`拒绝清理非输出目录:${assetsDir}`);
148574
148724
  rmSync3(assetsDir, { recursive: true, force: true });
148575
148725
  }
148576
- const formatted = await preprocess2(input, config, assetsDir, basename(assetsDir));
148726
+ const formatted = await preprocess2(input, config, assetsDir, basename2(assetsDir));
148577
148727
  writeFileSync6(output, formatted, "utf-8");
148578
148728
  console.log(`已格式化:${output}`);
148579
148729
  }