@formulaxjs/tiptap 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +39 -33
  2. package/README.zh-CN.md +39 -33
  3. package/dist/base.css +47 -0
  4. package/dist/canvg-runtime-UR3JNX5Q.js +2759 -0
  5. package/dist/canvg-runtime-UR3JNX5Q.js.map +1 -0
  6. package/dist/chunk-OCSSWPUX.js +3407 -0
  7. package/dist/chunk-OCSSWPUX.js.map +1 -0
  8. package/dist/images/scrollbar/custom/bar-bg.png +0 -0
  9. package/dist/images/scrollbar/custom/bar.png +0 -0
  10. package/dist/images/scrollbar/custom/bg.png +0 -0
  11. package/dist/images/scrollbar/custom/bottom.png +0 -0
  12. package/dist/images/scrollbar/custom/btn.png +0 -0
  13. package/dist/images/scrollbar/custom/down.png +0 -0
  14. package/dist/images/scrollbar/custom/top.png +0 -0
  15. package/dist/images/scrollbar/custom/up.png +0 -0
  16. package/dist/images/scrollbar/edit/bar-bg.png +0 -0
  17. package/dist/images/scrollbar/edit/bar-left.png +0 -0
  18. package/dist/images/scrollbar/edit/bar-right.png +0 -0
  19. package/dist/images/scrollbar/edit/thumb-bg.png +0 -0
  20. package/dist/images/scrollbar/edit/thumb-left.png +0 -0
  21. package/dist/images/scrollbar/edit/thumb-right.png +0 -0
  22. package/dist/images/toolbar/btn.png +0 -0
  23. package/dist/index.cjs +24075 -65
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +79 -0
  26. package/dist/index.d.ts +79 -0
  27. package/dist/index.global.js +865 -859
  28. package/dist/index.global.js.map +1 -1
  29. package/dist/index.js +3768 -21
  30. package/dist/index.js.map +1 -1
  31. package/dist/install-XGCSWTLU.js +5464 -0
  32. package/dist/install-XGCSWTLU.js.map +1 -0
  33. package/dist/install-XVTKACEN.js +1349 -0
  34. package/dist/install-XVTKACEN.js.map +1 -0
  35. package/dist/other.png +0 -0
  36. package/dist/scrollbar.css +78 -0
  37. package/dist/start-MBLTNR2Q.js +4926 -0
  38. package/dist/start-MBLTNR2Q.js.map +1 -0
  39. package/dist/ui.css +625 -0
  40. package/package.json +12 -7
  41. /package/dist/{KF_AMS_BB-5QF7FUSO.woff → KF_AMS_BB.woff} +0 -0
  42. /package/dist/{KF_AMS_CAL-NXRNLAZN.woff → KF_AMS_CAL.woff} +0 -0
  43. /package/dist/{KF_AMS_FRAK-CO33WWN4.woff → KF_AMS_FRAK.woff} +0 -0
  44. /package/dist/{KF_AMS_MAIN-25QJVAWY.woff → KF_AMS_MAIN.woff} +0 -0
  45. /package/dist/{KF_AMS_ROMAN-243BR7HH.woff → KF_AMS_ROMAN.woff} +0 -0
  46. /package/dist/{btn-5DANP6JY.png → btn.png} +0 -0
  47. /package/dist/{editor-JT5KLVXX.css → editor.css} +0 -0
  48. /package/dist/{other-OMWJFGL5.png → images/toolbar/other.png} +0 -0
@@ -1,9 +1,17 @@
1
1
  "use strict";
2
2
  var FormulaX = (() => {
3
+ var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
6
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
+ }) : x)(function(x) {
12
+ if (typeof require !== "undefined") return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
7
15
  var __esm = (fn, res) => function __init() {
8
16
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
17
  };
@@ -19,98 +27,42 @@ var FormulaX = (() => {
19
27
  }
20
28
  return to;
21
29
  };
30
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
+ // If the importer is in node compatibility mode or this is not an ESM
32
+ // file that has been converted to a CommonJS file using a Babel-
33
+ // compatible transform (i.e. "__esModule" has not been set), then set
34
+ // "default" to the CommonJS "module.exports" for node compatibility.
35
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
36
+ mod
37
+ ));
22
38
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
39
 
24
- // ../kity-runtime/public/assets/images/toolbar/btn.png
25
- var btn_default;
26
- var init_btn = __esm({
27
- "../kity-runtime/public/assets/images/toolbar/btn.png"() {
28
- btn_default = "./btn-5DANP6JY.png";
29
- }
30
- });
31
-
32
- // ../kity-runtime/public/assets/images/toolbar/other.png
33
- var other_default;
34
- var init_other = __esm({
35
- "../kity-runtime/public/assets/images/toolbar/other.png"() {
36
- other_default = "./other-OMWJFGL5.png";
37
- }
38
- });
39
-
40
- // ../kity-runtime/public/assets/styles/editor.css?url
41
- var editor_default;
42
- var init_editor = __esm({
43
- "../kity-runtime/public/assets/styles/editor.css?url"() {
44
- editor_default = "./editor-JT5KLVXX.css?url";
45
- }
46
- });
47
-
48
- // ../kity-runtime/public/resource/KF_AMS_BB.woff
49
- var KF_AMS_BB_default;
50
- var init_KF_AMS_BB = __esm({
51
- "../kity-runtime/public/resource/KF_AMS_BB.woff"() {
52
- KF_AMS_BB_default = "./KF_AMS_BB-5QF7FUSO.woff";
53
- }
54
- });
55
-
56
- // ../kity-runtime/public/resource/KF_AMS_CAL.woff
57
- var KF_AMS_CAL_default;
58
- var init_KF_AMS_CAL = __esm({
59
- "../kity-runtime/public/resource/KF_AMS_CAL.woff"() {
60
- KF_AMS_CAL_default = "./KF_AMS_CAL-NXRNLAZN.woff";
61
- }
62
- });
63
-
64
- // ../kity-runtime/public/resource/KF_AMS_FRAK.woff
65
- var KF_AMS_FRAK_default;
66
- var init_KF_AMS_FRAK = __esm({
67
- "../kity-runtime/public/resource/KF_AMS_FRAK.woff"() {
68
- KF_AMS_FRAK_default = "./KF_AMS_FRAK-CO33WWN4.woff";
69
- }
70
- });
71
-
72
- // ../kity-runtime/public/resource/KF_AMS_MAIN.woff
73
- var KF_AMS_MAIN_default;
74
- var init_KF_AMS_MAIN = __esm({
75
- "../kity-runtime/public/resource/KF_AMS_MAIN.woff"() {
76
- KF_AMS_MAIN_default = "./KF_AMS_MAIN-25QJVAWY.woff";
77
- }
78
- });
79
-
80
- // ../kity-runtime/public/resource/KF_AMS_ROMAN.woff
81
- var KF_AMS_ROMAN_default;
82
- var init_KF_AMS_ROMAN = __esm({
83
- "../kity-runtime/public/resource/KF_AMS_ROMAN.woff"() {
84
- KF_AMS_ROMAN_default = "./KF_AMS_ROMAN-243BR7HH.woff";
85
- }
86
- });
87
-
88
40
  // ../kity-runtime/src/asset-manifest.ts
89
- var kityFontAssets, kityToolbarAssets, kityStyleAssets, kityAssetManifest;
41
+ var import_btn, import_other, import_editor, import_KF_AMS_BB, import_KF_AMS_CAL, import_KF_AMS_FRAK, import_KF_AMS_MAIN, import_KF_AMS_ROMAN, kityFontAssets, kityToolbarAssets, kityStyleAssets, kityAssetManifest;
90
42
  var init_asset_manifest = __esm({
91
43
  "../kity-runtime/src/asset-manifest.ts"() {
92
44
  "use strict";
93
- init_btn();
94
- init_other();
95
- init_editor();
96
- init_KF_AMS_BB();
97
- init_KF_AMS_CAL();
98
- init_KF_AMS_FRAK();
99
- init_KF_AMS_MAIN();
100
- init_KF_AMS_ROMAN();
45
+ import_btn = __toESM(__require("./btn.png"), 1);
46
+ import_other = __toESM(__require("./other.png"), 1);
47
+ import_editor = __toESM(__require("./editor.css?url"), 1);
48
+ import_KF_AMS_BB = __toESM(__require("./KF_AMS_BB.woff"), 1);
49
+ import_KF_AMS_CAL = __toESM(__require("./KF_AMS_CAL.woff"), 1);
50
+ import_KF_AMS_FRAK = __toESM(__require("./KF_AMS_FRAK.woff"), 1);
51
+ import_KF_AMS_MAIN = __toESM(__require("./KF_AMS_MAIN.woff"), 1);
52
+ import_KF_AMS_ROMAN = __toESM(__require("./KF_AMS_ROMAN.woff"), 1);
101
53
  kityFontAssets = {
102
- KF_AMS_BB: KF_AMS_BB_default,
103
- KF_AMS_CAL: KF_AMS_CAL_default,
104
- KF_AMS_FRAK: KF_AMS_FRAK_default,
105
- KF_AMS_MAIN: KF_AMS_MAIN_default,
106
- KF_AMS_ROMAN: KF_AMS_ROMAN_default
54
+ KF_AMS_BB: import_KF_AMS_BB.default,
55
+ KF_AMS_CAL: import_KF_AMS_CAL.default,
56
+ KF_AMS_FRAK: import_KF_AMS_FRAK.default,
57
+ KF_AMS_MAIN: import_KF_AMS_MAIN.default,
58
+ KF_AMS_ROMAN: import_KF_AMS_ROMAN.default
107
59
  };
108
60
  kityToolbarAssets = {
109
- btn: btn_default,
110
- other: other_default
61
+ btn: import_btn.default,
62
+ other: import_other.default
111
63
  };
112
64
  kityStyleAssets = {
113
- editor: editor_default
65
+ editor: import_editor.default
114
66
  };
115
67
  kityAssetManifest = {
116
68
  fonts: kityFontAssets,
@@ -5079,11 +5031,76 @@ var FormulaX = (() => {
5079
5031
  }
5080
5032
  return DEFAULT_FORMULAX_LOCALE;
5081
5033
  }
5082
- var DEFAULT_FORMULAX_LOCALE;
5034
+ function translateFormulaXText(namespace, value, locale) {
5035
+ if (locale === "zh_CN") {
5036
+ return value;
5037
+ }
5038
+ const normalizedValue = value.replace(/<br\s*\/?>/gi, "").trim();
5039
+ const translatedValue = FORMULAX_TRANSLATIONS[locale]?.[namespace]?.[normalizedValue];
5040
+ if (!translatedValue) {
5041
+ return value;
5042
+ }
5043
+ const lineBreakMatch = value.match(/<br\s*\/?>/i);
5044
+ if (/<br\s*\/?>/i.test(translatedValue)) {
5045
+ return translatedValue;
5046
+ }
5047
+ return lineBreakMatch ? `${translatedValue}${lineBreakMatch[0]}` : translatedValue;
5048
+ }
5049
+ function getFormulaXRuntimeMessage(key, locale = DEFAULT_FORMULAX_LOCALE) {
5050
+ const normalizedLocale = normalizeFormulaXLocale(locale);
5051
+ return FORMULAX_RUNTIME_MESSAGES[normalizedLocale][key] ?? FORMULAX_RUNTIME_MESSAGES[DEFAULT_FORMULAX_LOCALE][key];
5052
+ }
5053
+ var DEFAULT_FORMULAX_LOCALE, FORMULAX_TRANSLATIONS, FORMULAX_RUNTIME_MESSAGES;
5083
5054
  var init_i18n = __esm({
5084
5055
  "../kity-runtime/src/i18n.ts"() {
5085
5056
  "use strict";
5086
5057
  DEFAULT_FORMULAX_LOCALE = "en_US";
5058
+ FORMULAX_TRANSLATIONS = {
5059
+ en_US: {
5060
+ toolbar: {
5061
+ \u9884\u8BBE: "Presets",
5062
+ \u9884\u8BBE\u516C\u5F0F: "Presets",
5063
+ \u4E8C\u6B21\u516C\u5F0F: "Quadratic",
5064
+ \u4E8C\u9879\u5F0F\u5B9A\u7406: "Binomial",
5065
+ \u52FE\u80A1\u5B9A\u7406: "Pythagorean",
5066
+ \u57FA\u7840\u6570\u5B66: "Basic math",
5067
+ \u5E0C\u814A\u5B57\u6BCD: "Greek",
5068
+ \u6C42\u53CD\u5173\u7CFB\u8FD0\u7B97\u7B26: "Negated operators",
5069
+ \u5B57\u6BCD\u7C7B\u7B26\u53F7: "Letter symbols",
5070
+ \u7BAD\u5934: "Arrows",
5071
+ \u624B\u5199\u4F53: "Script",
5072
+ \u5206\u6570: "Fraction",
5073
+ \u5E38\u7528\u5206\u6570: "Common fractions",
5074
+ \u4E0A\u4E0B\u6807: "Scripts",
5075
+ \u4E0A\u6807\u548C\u4E0B\u6807: "Super/subscripts",
5076
+ \u5E38\u7528\u7684\u4E0A\u6807\u548C\u4E0B\u6807: "Common super/subscripts",
5077
+ \u6839\u5F0F: "Radicals",
5078
+ \u5E38\u7528\u6839\u5F0F: "Common radicals",
5079
+ \u79EF\u5206: "Integrals",
5080
+ \u5927\u578B\u8FD0\u7B97\u7B26: "Large<br/>ops",
5081
+ \u6C42\u548C: "Summations",
5082
+ \u62EC\u53F7: "Brackets",
5083
+ \u65B9\u62EC\u53F7: "Brackets",
5084
+ \u51FD\u6570: "Functions",
5085
+ \u4E09\u89D2\u51FD\u6570: "Trig functions",
5086
+ \u5E38\u7528\u51FD\u6570: "Common functions",
5087
+ \u5C0F\u5199: "Lowercase",
5088
+ \u5927\u5199: "Uppercase",
5089
+ \u53D8\u4F53: "Variants",
5090
+ \u82B1\u4F53: "Fraktur",
5091
+ \u53CC\u7EBF: "Double-struck",
5092
+ \u7F57\u9A6C: "Roman"
5093
+ }
5094
+ }
5095
+ };
5096
+ FORMULAX_RUNTIME_MESSAGES = {
5097
+ en_US: {
5098
+ "editor.placeholder.root": "Type formula here"
5099
+ },
5100
+ zh_CN: {
5101
+ "editor.placeholder.root": "\u8BF7\u8F93\u5165\u516C\u5F0F"
5102
+ }
5103
+ };
5087
5104
  }
5088
5105
  });
5089
5106
 
@@ -14980,8 +14997,8 @@ var FormulaX = (() => {
14980
14997
  }
14981
14998
  return serviceObject;
14982
14999
  }
14983
- var defaultOptions, components, kity2, kf, KFEditor, editor_default2;
14984
- var init_editor2 = __esm({
15000
+ var defaultOptions, components, kity2, kf, KFEditor, editor_default;
15001
+ var init_editor = __esm({
14985
15002
  "../kity-runtime/src/legacy/editor.ts"() {
14986
15003
  "use strict";
14987
15004
  init_legacy_utils();
@@ -15092,7 +15109,7 @@ var FormulaX = (() => {
15092
15109
  components[name] = component;
15093
15110
  }
15094
15111
  });
15095
- editor_default2 = KFEditor;
15112
+ editor_default = KFEditor;
15096
15113
  }
15097
15114
  });
15098
15115
 
@@ -15101,13 +15118,13 @@ var FormulaX = (() => {
15101
15118
  var init_factory = __esm({
15102
15119
  "../kity-runtime/src/legacy/factory.ts"() {
15103
15120
  "use strict";
15104
- init_editor2();
15121
+ init_editor();
15105
15122
  init_runtime_interop();
15106
15123
  EditorWrapper = class {
15107
15124
  callbacks = [];
15108
15125
  editor;
15109
15126
  constructor(container, options) {
15110
- this.editor = new editor_default2(container, options);
15127
+ this.editor = new editor_default(container, options);
15111
15128
  this.editor.ready(() => {
15112
15129
  this.trigger();
15113
15130
  });
@@ -16675,6 +16692,7 @@ var FormulaX = (() => {
16675
16692
  to: "\u2192",
16676
16693
  downarrow: "\u2193",
16677
16694
  leftrightarrow: "\u2194",
16695
+ updownarrow: "\u2195",
16678
16696
  therefore: "\u2234",
16679
16697
  because: "\u2235",
16680
16698
  "+": "+",
@@ -16791,7 +16809,7 @@ var FormulaX = (() => {
16791
16809
  Uparrow: "\u21D1",
16792
16810
  Downarrow: "\u21D3",
16793
16811
  Leftrightarrow: "\u21D4",
16794
- Updownarrow: "\u21F3",
16812
+ Updownarrow: "\u21D5",
16795
16813
  longleftarrow: "\u27F5",
16796
16814
  longrightarrow: "\u27F6",
16797
16815
  longleftrightarrow: "\u27F7",
@@ -16859,16 +16877,7 @@ var FormulaX = (() => {
16859
16877
  Object.keys(list).forEach((key) => callback(list[key], key));
16860
16878
  }
16861
16879
  function translateToolbarText(value, locale) {
16862
- if (locale === "zh_CN") {
16863
- return value;
16864
- }
16865
- const normalizedValue = value.replace(/<br\s*\/?>/gi, "").trim();
16866
- const translatedValue = zhCnToEnUsText.get(normalizedValue);
16867
- if (!translatedValue) {
16868
- return value;
16869
- }
16870
- const lineBreakMatch = value.match(/<br\s*\/?>/i);
16871
- return lineBreakMatch ? `${translatedValue}${lineBreakMatch[0]}` : translatedValue;
16880
+ return translateFormulaXText("toolbar", value, locale);
16872
16881
  }
16873
16882
  function localizeToolbarConfig(value, locale) {
16874
16883
  if (Array.isArray(value)) {
@@ -16912,7 +16921,7 @@ var FormulaX = (() => {
16912
16921
  normalizeFormulaXLocale(locale)
16913
16922
  );
16914
16923
  }
16915
- var UI_ELE_TYPE, BOX_TYPE2, OTHER_POSITION, zhCnToEnUsText, baseToolbarConfig, toolbar_config_default;
16924
+ var UI_ELE_TYPE, BOX_TYPE2, OTHER_POSITION, baseToolbarConfig, toolbar_config_default;
16916
16925
  var init_toolbar_config = __esm({
16917
16926
  "../kity-runtime/src/legacy/toolbar-config.ts"() {
16918
16927
  "use strict";
@@ -16925,40 +16934,6 @@ var FormulaX = (() => {
16925
16934
  UI_ELE_TYPE = legacyEleType;
16926
16935
  BOX_TYPE2 = legacyBoxType;
16927
16936
  OTHER_POSITION = legacyOtherPosition;
16928
- zhCnToEnUsText = /* @__PURE__ */ new Map([
16929
- ["\u9884\u8BBE", "Presets"],
16930
- ["\u9884\u8BBE\u516C\u5F0F", "Preset formulas"],
16931
- ["\u4E8C\u6B21\u516C\u5F0F", "Quadratic formula"],
16932
- ["\u4E8C\u9879\u5F0F\u5B9A\u7406", "Binomial theorem"],
16933
- ["\u52FE\u80A1\u5B9A\u7406", "Pythagorean theorem"],
16934
- ["\u57FA\u7840\u6570\u5B66", "Basic math"],
16935
- ["\u5E0C\u814A\u5B57\u6BCD", "Greek letters"],
16936
- ["\u6C42\u53CD\u5173\u7CFB\u8FD0\u7B97\u7B26", "Negated operators"],
16937
- ["\u5B57\u6BCD\u7C7B\u7B26\u53F7", "Letter-like symbols"],
16938
- ["\u7BAD\u5934", "Arrows"],
16939
- ["\u624B\u5199\u4F53", "Script"],
16940
- ["\u5206\u6570", "Fraction"],
16941
- ["\u5E38\u7528\u5206\u6570", "Common fractions"],
16942
- ["\u4E0A\u4E0B\u6807", "Scripts"],
16943
- ["\u4E0A\u6807\u548C\u4E0B\u6807", "Superscripts and subscripts"],
16944
- ["\u5E38\u7528\u7684\u4E0A\u6807\u548C\u4E0B\u6807", "Common superscripts and subscripts"],
16945
- ["\u6839\u5F0F", "Radicals"],
16946
- ["\u5E38\u7528\u6839\u5F0F", "Common radicals"],
16947
- ["\u79EF\u5206", "Integrals"],
16948
- ["\u5927\u578B\u8FD0\u7B97\u7B26", "Large operators"],
16949
- ["\u6C42\u548C", "Summations"],
16950
- ["\u62EC\u53F7", "Brackets"],
16951
- ["\u65B9\u62EC\u53F7", "Brackets"],
16952
- ["\u51FD\u6570", "Functions"],
16953
- ["\u4E09\u89D2\u51FD\u6570", "Trigonometric functions"],
16954
- ["\u5E38\u7528\u51FD\u6570", "Common functions"],
16955
- ["\u5C0F\u5199", "Lowercase"],
16956
- ["\u5927\u5199", "Uppercase"],
16957
- ["\u53D8\u4F53", "Variants"],
16958
- ["\u82B1\u4F53", "Fraktur"],
16959
- ["\u53CC\u7EBF", "Double-struck"],
16960
- ["\u7F57\u9A6C", "Roman"]
16961
- ]);
16962
16937
  baseToolbarConfig = [{
16963
16938
  type: UI_ELE_TYPE.DRAPDOWN_BOX,
16964
16939
  options: {
@@ -18189,6 +18164,9 @@ var FormulaX = (() => {
18189
18164
  operand: []
18190
18165
  };
18191
18166
  }
18167
+ function getRootPlaceholderText() {
18168
+ return legacySysconf.rootPlaceholder.content;
18169
+ }
18192
18170
  function processRootGroup(parser, tree) {
18193
18171
  if (!parser.isResetId) {
18194
18172
  tree.attr["data-type"] = legacyGroupType.VIRTUAL;
@@ -18236,7 +18214,7 @@ var FormulaX = (() => {
18236
18214
  if (isRoot) {
18237
18215
  processRootGroup(parser, tree);
18238
18216
  } else if (parentTree?.attr?.["data-root"] && tree.name === "placeholder" && onlyPlaceholder(parentTree.operand)) {
18239
- tree.attr.label = ROOT_P_TEXT;
18217
+ tree.attr.label = getRootPlaceholderText();
18240
18218
  }
18241
18219
  for (let i2 = 0; i2 < tree.operand.length; i2 += 1) {
18242
18220
  const currentOperand = tree.operand[i2];
@@ -18248,7 +18226,7 @@ var FormulaX = (() => {
18248
18226
  }
18249
18227
  return tree;
18250
18228
  }
18251
- var CURSOR_CHAR, ROOT_P_TEXT, COMBINATION_NAME, PID_PREFIX, pidSeed, kity14, kf5, BaseComponent, Parser, parser_default;
18229
+ var CURSOR_CHAR, COMBINATION_NAME, PID_PREFIX, pidSeed, kity14, kf5, BaseComponent, Parser, parser_default;
18252
18230
  var init_parser = __esm({
18253
18231
  "../kity-runtime/src/legacy/parser.ts"() {
18254
18232
  "use strict";
@@ -18259,7 +18237,6 @@ var FormulaX = (() => {
18259
18237
  init_kf_ext_extension();
18260
18238
  init_vgroup_def();
18261
18239
  CURSOR_CHAR = legacySysconf.cursorCharacter;
18262
- ROOT_P_TEXT = legacySysconf.rootPlaceholder.content;
18263
18240
  COMBINATION_NAME = "combination";
18264
18241
  PID_PREFIX = "_kf_editor_";
18265
18242
  pidSeed = 0;
@@ -20139,26 +20116,26 @@ var FormulaX = (() => {
20139
20116
  var start_exports = {};
20140
20117
  __export(start_exports, {
20141
20118
  Factory: () => factory_default,
20142
- KFEditor: () => editor_default2,
20119
+ KFEditor: () => editor_default,
20143
20120
  default: () => start_default,
20144
20121
  installKityEditorStart: () => installKityEditorStart
20145
20122
  });
20146
20123
  function installKityEditorStart(target = window) {
20147
20124
  const runtimeTarget = target;
20148
20125
  if (!installed3) {
20149
- editor_default2.registerComponents("ui", ui_default);
20150
- editor_default2.registerComponents("parser", parser_default);
20151
- editor_default2.registerComponents("render", render_default);
20152
- editor_default2.registerComponents("position", position_default);
20153
- editor_default2.registerComponents("syntax", syntax_default);
20154
- editor_default2.registerComponents("control", controller_default);
20155
- editor_default2.registerComponents("print", printer_default);
20126
+ editor_default.registerComponents("ui", ui_default);
20127
+ editor_default.registerComponents("parser", parser_default);
20128
+ editor_default.registerComponents("render", render_default);
20129
+ editor_default.registerComponents("position", position_default);
20130
+ editor_default.registerComponents("syntax", syntax_default);
20131
+ editor_default.registerComponents("control", controller_default);
20132
+ editor_default.registerComponents("print", printer_default);
20156
20133
  installed3 = true;
20157
20134
  }
20158
20135
  runtimeTarget.kf = runtimeTarget.kf ?? {};
20159
20136
  runtimeTarget.kf.EditorFactory = factory_default;
20160
20137
  return {
20161
- KFEditor: editor_default2,
20138
+ KFEditor: editor_default,
20162
20139
  Factory: factory_default
20163
20140
  };
20164
20141
  }
@@ -20166,7 +20143,7 @@ var FormulaX = (() => {
20166
20143
  var init_start = __esm({
20167
20144
  "../kity-runtime/src/boot/start.ts"() {
20168
20145
  "use strict";
20169
- init_editor2();
20146
+ init_editor();
20170
20147
  init_factory();
20171
20148
  init_ui();
20172
20149
  init_parser();
@@ -25542,7 +25519,7 @@ var FormulaX = (() => {
25542
25519
  };
25543
25520
  }
25544
25521
 
25545
- // ../../node_modules/.pnpm/@tiptap+core@2.27.2_@tiptap+pm@2.27.2/node_modules/@tiptap/core/dist/index.js
25522
+ // ../../node_modules/.pnpm/@tiptap+core@2.27.2_@tiptap+pm@3.23.4/node_modules/@tiptap/core/dist/index.js
25546
25523
  function createChainableState(config) {
25547
25524
  const { state, transaction } = config;
25548
25525
  let { selection } = transaction;
@@ -27633,710 +27610,12 @@ var FormulaX = (() => {
27633
27610
  }
27634
27611
  };
27635
27612
 
27636
- // ../core/src/ast.ts
27637
- var text = (value) => ({ type: "text", value });
27638
- var group = (body = []) => ({ type: "group", body });
27639
- var doc = (body = []) => ({ type: "doc", body });
27640
- var frac = (numerator = [], denominator = []) => ({
27641
- type: "frac",
27642
- numerator,
27643
- denominator
27644
- });
27645
- var supsub = (base, sup, sub) => ({
27646
- type: "supsub",
27647
- base,
27648
- sup,
27649
- sub
27650
- });
27651
- var sqrt = (value = []) => ({ type: "sqrt", value });
27652
- var fenced = (left, right, body = []) => ({
27653
- type: "fenced",
27654
- left,
27655
- right,
27656
- body
27657
- });
27658
-
27659
- // ../core/src/commands.ts
27660
- var createEmptyState = () => ({
27661
- doc: { type: "doc", body: [] },
27662
- selection: { anchor: [0], focus: [0] }
27663
- });
27664
-
27665
- // ../core/src/latex.ts
27666
- var isAlpha = (char) => /[a-zA-Z]/.test(char);
27667
- var GREEK_LETTERS = {
27668
- alpha: "\u03B1",
27669
- beta: "\u03B2",
27670
- gamma: "\u03B3",
27671
- delta: "\u03B4",
27672
- epsilon: "\u03B5",
27673
- zeta: "\u03B6",
27674
- eta: "\u03B7",
27675
- theta: "\u03B8",
27676
- iota: "\u03B9",
27677
- kappa: "\u03BA",
27678
- lambda: "\u03BB",
27679
- mu: "\u03BC",
27680
- nu: "\u03BD",
27681
- xi: "\u03BE",
27682
- omicron: "\u03BF",
27683
- pi: "\u03C0",
27684
- rho: "\u03C1",
27685
- sigma: "\u03C3",
27686
- tau: "\u03C4",
27687
- upsilon: "\u03C5",
27688
- phi: "\u03C6",
27689
- chi: "\u03C7",
27690
- psi: "\u03C8",
27691
- omega: "\u03C9",
27692
- Gamma: "\u0393",
27693
- Delta: "\u0394",
27694
- Theta: "\u0398",
27695
- Lambda: "\u039B",
27696
- Xi: "\u039E",
27697
- Pi: "\u03A0",
27698
- Sigma: "\u03A3",
27699
- Phi: "\u03A6",
27700
- Psi: "\u03A8",
27701
- Omega: "\u03A9"
27702
- };
27703
- var BINARY_OPERATORS = {
27704
- cdot: "\xB7",
27705
- times: "\xD7",
27706
- div: "\xF7",
27707
- pm: "\xB1",
27708
- mp: "\u2213",
27709
- ast: "\u2217",
27710
- star: "\u22C6",
27711
- circ: "\u2218",
27712
- bullet: "\u2022",
27713
- cup: "\u222A",
27714
- cap: "\u2229",
27715
- vee: "\u2228",
27716
- wedge: "\u2227",
27717
- setminus: "\u2216"
27718
- };
27719
- var MATH_FUNCTIONS = {
27720
- sin: "sin",
27721
- cos: "cos",
27722
- tan: "tan",
27723
- cot: "cot",
27724
- sec: "sec",
27725
- csc: "csc",
27726
- arcsin: "arcsin",
27727
- arccos: "arccos",
27728
- arctan: "arctan",
27729
- sinh: "sinh",
27730
- cosh: "cosh",
27731
- tanh: "tanh",
27732
- log: "log",
27733
- ln: "ln",
27734
- exp: "exp",
27735
- lim: "lim",
27736
- det: "det",
27737
- dim: "dim",
27738
- deg: "deg",
27739
- max: "max",
27740
- min: "min"
27741
- };
27742
- var RELATIONS = {
27743
- leq: "\u2264",
27744
- le: "\u2264",
27745
- ge: "\u2265",
27746
- geq: "\u2265",
27747
- ne: "\u2260",
27748
- neq: "\u2260",
27749
- approx: "\u2248",
27750
- equiv: "\u2261",
27751
- sim: "\u223C",
27752
- simeq: "\u2243",
27753
- cong: "\u2245",
27754
- perp: "\u22A5",
27755
- parallel: "\u2225",
27756
- propto: "\u221D",
27757
- leqslant: "\u2A7D",
27758
- geqslant: "\u2A7E"
27759
- };
27760
- var ARROWS = {
27761
- to: "\u2192",
27762
- gets: "\u2190",
27763
- leftrightarrow: "\u2194",
27764
- rightarrow: "\u2192",
27765
- leftarrow: "\u2190",
27766
- Rightarrow: "\u21D2",
27767
- Leftarrow: "\u21D0",
27768
- Leftrightarrow: "\u21D4",
27769
- mapsto: "\u21A6",
27770
- longmapsto: "\u27FC",
27771
- nearrow: "\u2197",
27772
- searrow: "\u2198",
27773
- swarrow: "\u2199",
27774
- nwarrow: "\u2196"
27775
- };
27776
- var MISC_SYMBOLS = {
27777
- infty: "\u221E",
27778
- infinity: "\u221E",
27779
- aleph: "\u2135",
27780
- wp: "\u2118",
27781
- Re: "\u211C",
27782
- Im: "\u2111",
27783
- partial: "\u2202",
27784
- nabla: "\u2207",
27785
- forall: "\u2200",
27786
- exists: "\u2203",
27787
- neg: "\xAC",
27788
- prime: "\u2032",
27789
- dprime: "\u2033",
27790
- triangle: "\u25B3",
27791
- square: "\u25A1",
27792
- flat: "\u266D",
27793
- natural: "\u266E",
27794
- sharp: "\u266F",
27795
- dag: "\u2020",
27796
- ddag: "\u2021"
27797
- };
27798
- var LATEX_SYMBOLS = {
27799
- ...GREEK_LETTERS,
27800
- ...BINARY_OPERATORS,
27801
- ...MATH_FUNCTIONS,
27802
- ...RELATIONS,
27803
- ...ARROWS,
27804
- ...MISC_SYMBOLS
27805
- };
27806
- var SYMBOL_TO_LATEX = Object.entries(LATEX_SYMBOLS).reduce((acc, [command2, symbol]) => {
27807
- if (!(symbol in acc)) {
27808
- acc[symbol] = command2;
27809
- }
27810
- return acc;
27811
- }, {});
27812
- var symbolToLatexCommand = (symbol) => SYMBOL_TO_LATEX[symbol] ?? null;
27813
- var serializeTextValue = (value) => {
27814
- const command2 = symbolToLatexCommand(value);
27815
- return command2 ? `\\${command2} ` : value;
27816
- };
27817
- var LatexParser = class {
27818
- constructor(input) {
27819
- this.input = input;
27820
- }
27821
- input;
27822
- index = 0;
27823
- parse() {
27824
- return doc(this.parseSequence());
27825
- }
27826
- parseSequence(stopChar) {
27827
- const nodes = [];
27828
- while (this.index < this.input.length) {
27829
- const current = this.input[this.index];
27830
- if (stopChar && current === stopChar) {
27831
- this.index += 1;
27832
- break;
27833
- }
27834
- if (current === "{") {
27835
- this.index += 1;
27836
- nodes.push(group(this.parseSequence("}")));
27837
- continue;
27838
- }
27839
- if (current === "^" || current === "_") {
27840
- const modifier = current;
27841
- this.index += 1;
27842
- const last = nodes.pop() ?? text("");
27843
- const target = this.parseAtomAsList();
27844
- const base = last.type === "group" ? last.body : [last];
27845
- if (modifier === "^") {
27846
- nodes.push(supsub(base, target));
27847
- } else {
27848
- nodes.push(supsub(base, void 0, target));
27849
- }
27850
- continue;
27851
- }
27852
- if (current === "\\") {
27853
- nodes.push(this.parseCommand());
27854
- continue;
27855
- }
27856
- if (["(", "["].includes(current)) {
27857
- this.index += 1;
27858
- const right = current === "(" ? ")" : "]";
27859
- nodes.push(fenced(current, right, this.parseSequence(right)));
27860
- continue;
27861
- }
27862
- nodes.push(text(current));
27863
- this.index += 1;
27864
- }
27865
- return nodes;
27866
- }
27867
- parseCommand() {
27868
- this.index += 1;
27869
- let command2 = "";
27870
- while (this.index < this.input.length && isAlpha(this.input[this.index])) {
27871
- command2 += this.input[this.index];
27872
- this.index += 1;
27873
- }
27874
- if (command2 === "frac") {
27875
- const numerator = this.parseAtomAsList();
27876
- const denominator = this.parseAtomAsList();
27877
- return frac(numerator, denominator);
27878
- }
27879
- if (command2 === "sqrt") {
27880
- return sqrt(this.parseAtomAsList());
27881
- }
27882
- if (LATEX_SYMBOLS[command2]) {
27883
- return text(LATEX_SYMBOLS[command2]);
27884
- }
27885
- if (command2 === "left") {
27886
- const left = this.input[this.index] ?? "(";
27887
- this.index += 1;
27888
- const body = [];
27889
- while (!this.input.startsWith("\\right", this.index) && this.index < this.input.length) {
27890
- body.push(...this.parseSequenceChunk());
27891
- }
27892
- this.index += "\\right".length;
27893
- const right = this.input[this.index] ?? ")";
27894
- this.index += 1;
27895
- return fenced(left, right, body);
27896
- }
27897
- return text(`\\${command2}`);
27898
- }
27899
- parseSequenceChunk() {
27900
- const char = this.input[this.index];
27901
- if (char === "{") {
27902
- this.index += 1;
27903
- return [group(this.parseSequence("}"))];
27904
- }
27905
- if (char === "\\") {
27906
- return [this.parseCommand()];
27907
- }
27908
- if (char === "(" || char === "[") {
27909
- this.index += 1;
27910
- const right = char === "(" ? ")" : "]";
27911
- return [fenced(char, right, this.parseSequence(right))];
27912
- }
27913
- this.index += 1;
27914
- return [text(char)];
27915
- }
27916
- parseAtomAsList() {
27917
- if (this.input[this.index] === "{") {
27918
- this.index += 1;
27919
- return this.parseSequence("}");
27920
- }
27921
- return this.parseSequenceChunk();
27922
- }
27923
- };
27924
- var serializeList = (nodes) => nodes.map(serializeNode).join("");
27925
- var serializeNode = (node) => {
27926
- switch (node.type) {
27927
- case "doc":
27928
- return serializeList(node.body);
27929
- case "group":
27930
- return `{${serializeList(node.body)}}`;
27931
- case "text":
27932
- return serializeTextValue(node.value);
27933
- case "frac":
27934
- return `\\frac{${serializeList(node.numerator)}}{${serializeList(node.denominator)}}`;
27935
- case "supsub": {
27936
- const base = serializeList(node.base);
27937
- const sup = node.sup ? `^{${serializeList(node.sup)}}` : "";
27938
- const sub = node.sub ? `_{${serializeList(node.sub)}}` : "";
27939
- return `${base}${sup}${sub}`;
27940
- }
27941
- case "sqrt":
27942
- return `\\sqrt{${serializeList(node.value)}}`;
27943
- case "fenced":
27944
- return `\\left${node.left}${serializeList(node.body)}\\right${node.right}`;
27945
- }
27946
- };
27947
- var parseLatex = (input) => new LatexParser(input).parse();
27948
- var serializeLatex = (document2) => serializeNode(document2);
27949
-
27950
- // ../renderer/src/markup.ts
27951
- var DEFAULT_FORMULA_ATTRIBUTE = "data-formulax-latex";
27952
- var FORMULA_FLAG_ATTRIBUTE = "data-formulax";
27953
- var DEFAULT_FORMULA_CLASS = "formulax-math";
27954
- function escapeAttribute(value) {
27955
- return value.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
27956
- }
27957
- function escapeHtml(value) {
27958
- return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
27959
- }
27960
- function createFormulaMarkup(latex, options = {}) {
27961
- const attributeName = options.attributeName ?? DEFAULT_FORMULA_ATTRIBUTE;
27962
- const className = options.className ?? DEFAULT_FORMULA_CLASS;
27963
- const displayClass = options.displayMode ? `${className} ${className}--block` : className;
27964
- const safeLatex = escapeAttribute(latex);
27965
- const cursorStyle = options.cursorStyle?.trim() || "pointer";
27966
- const extraAttributes = {
27967
- ...options.extraAttributes ?? {},
27968
- style: mergeInlineStyles(
27969
- typeof options.extraAttributes?.style === "string" ? options.extraAttributes.style : "",
27970
- cursorStyle ? `cursor: ${cursorStyle}` : ""
27971
- )
27972
- };
27973
- const serializedAttributes = Object.entries(extraAttributes).filter(([, value]) => value !== null && value !== void 0 && value !== false).map(([key, value]) => value === true ? key : `${key}="${escapeAttribute(String(value))}"`);
27974
- return [
27975
- "<span",
27976
- ` class="${escapeAttribute(displayClass)}"`,
27977
- ` ${FORMULA_FLAG_ATTRIBUTE}="true"`,
27978
- ` ${attributeName}="${safeLatex}"`,
27979
- ` data-latex="${safeLatex}"`,
27980
- ' contenteditable="false"',
27981
- ' role="button"',
27982
- ' tabindex="0"',
27983
- serializedAttributes.length ? ` ${serializedAttributes.join(" ")}` : "",
27984
- ">",
27985
- options.renderHtml ?? `<span class="${escapeAttribute(className)}__render">${escapeHtml(latex || "\\square")}</span>`,
27986
- "</span>"
27987
- ].join("");
27988
- }
27989
- function mergeInlineStyles(existingStyle, nextStyle) {
27990
- const existing = existingStyle.trim().replace(/;+\s*$/, "");
27991
- const next = nextStyle.trim().replace(/;+\s*$/, "");
27992
- if (!existing) return next;
27993
- if (!next) return existing;
27994
- return `${existing}; ${next}`;
27995
- }
27996
- function createFormulaElement(ownerDocument, latex, options = {}) {
27997
- const wrapper = ownerDocument.createElement("span");
27998
- wrapper.innerHTML = createFormulaMarkup(latex, options);
27999
- return wrapper.firstElementChild;
28000
- }
28001
- function getFormulaLatexFromElement(element, attributeName = DEFAULT_FORMULA_ATTRIBUTE) {
28002
- return element.getAttribute(attributeName) ?? element.getAttribute("data-latex") ?? "";
28003
- }
28004
-
28005
- // ../renderer/src/styles.ts
28006
- var FORMULAX_BASE_STYLE_ID = "fx-formulax-base-styles";
28007
- var formulaXBaseStyles = `
28008
- .formulax-math {
28009
- display: inline-flex;
28010
- align-items: center;
28011
- vertical-align: middle;
28012
- line-height: 1;
28013
- padding: 0 2px;
28014
- margin: 0 1px;
28015
- border-radius: 3px;
28016
- background: transparent;
28017
- cursor: pointer;
28018
- user-select: none;
28019
- }
28020
-
28021
- .formulax-math:hover {
28022
- outline: 1px solid rgba(37, 99, 235, 0.35);
28023
- background: rgba(37, 99, 235, 0.06);
28024
- }
28025
-
28026
- .formulax-math__render,
28027
- .formulax-math__svg,
28028
- .formulax-math__image {
28029
- display: inline-block;
28030
- max-width: 100%;
28031
- pointer-events: none;
28032
- }
28033
-
28034
- .formulax-math__render {
28035
- vertical-align: middle;
28036
- font-family: "KF AMS MAIN", "Cambria Math", "Latin Modern Math", "Times New Roman", serif;
28037
- }
28038
-
28039
- .formulax-math__svg {
28040
- flex: 0 0 auto;
28041
- vertical-align: -0.35em;
28042
- }
28043
-
28044
- .formulax-math__image {
28045
- height: auto;
28046
- vertical-align: middle;
28047
- }
28048
- `;
28049
- function ensureFormulaXBaseStyles(doc2 = document) {
28050
- if (doc2.getElementById(FORMULAX_BASE_STYLE_ID)) return;
28051
- const style = doc2.createElement("style");
28052
- style.id = FORMULAX_BASE_STYLE_ID;
28053
- style.textContent = formulaXBaseStyles;
28054
- doc2.head.appendChild(style);
28055
- }
27613
+ // ../kity-runtime/src/index.ts
27614
+ init_asset_manifest();
28056
27615
 
28057
- // ../renderer/src/cache.ts
28058
- function createFormulaRenderCacheKey(input) {
28059
- return JSON.stringify({
28060
- engine: input.engine,
28061
- latex: input.latex,
28062
- output: input.output,
28063
- fontSize: input.fontSize,
28064
- displayMode: input.displayMode,
28065
- className: input.className,
28066
- assetsVersion: input.assetsVersion
28067
- });
28068
- }
28069
-
28070
- // ../renderer/src/svg.ts
28071
- var SIMPLE_INLINE_HEIGHT_EM = 1.25;
28072
- var BASE_FORMULA_HEIGHT = 40.5;
28073
- var SIMPLE_FORMULA_HEIGHT_RATIO = 1.05;
28074
- var MAX_INLINE_HEIGHT_EM = 1.65;
28075
- var COMPLEX_FORMULA_SCALE = 0.825;
28076
- function readRenderedFormulaSvgBox(svg2) {
28077
- return getInlineSvgContent(svg2)?.box ?? readSvgBox(svg2);
28078
- }
28079
- function serializeSvgForInsertion(svg2) {
28080
- const content = getInlineSvgContent(svg2);
28081
- const inlineViewport = content ? createInlineSvgViewport(content.box) : null;
28082
- const clone = content && inlineViewport ? createInlineSvgClone(svg2, content, inlineViewport) : svg2.cloneNode(true);
28083
- uniquifySvgIds(clone);
28084
- sizeSvgForInlineDisplay(clone, svg2, inlineViewport);
28085
- clone.setAttribute("focusable", "false");
28086
- clone.setAttribute("aria-hidden", "true");
28087
- clone.setAttribute("class", mergeClassNames(clone.getAttribute("class"), "formulax-math__svg"));
28088
- return clone.outerHTML;
28089
- }
28090
- function getInlineSvgContent(svg2) {
28091
- const selectorCandidates = [
28092
- '[data-type="kf-editor-exp-content-box"]',
28093
- '[data-root="true"] [data-type="kf-editor-exp-content-box"]',
28094
- 'g[data-root="true"]'
28095
- ];
28096
- for (const selector of selectorCandidates) {
28097
- const element = svg2.querySelector(selector);
28098
- if (!element) continue;
28099
- const rootSpace = readSvgBoxInRootSpace(element);
28100
- if (!rootSpace) continue;
28101
- return {
28102
- box: rootSpace.box,
28103
- matrix: rootSpace.matrix,
28104
- root: element
28105
- };
28106
- }
28107
- return null;
28108
- }
28109
- function readSvgBoxInRootSpace(element) {
28110
- const box = readSvgBox(element);
28111
- const matrix = getSvgRootSpaceMatrix(element);
28112
- if (!box || !matrix) {
28113
- return null;
28114
- }
28115
- const points = [
28116
- { x: box.x, y: box.y },
28117
- { x: box.x + box.width, y: box.y },
28118
- { x: box.x, y: box.y + box.height },
28119
- { x: box.x + box.width, y: box.y + box.height }
28120
- ].map((point) => ({
28121
- x: matrix.a * point.x + matrix.c * point.y + matrix.e,
28122
- y: matrix.b * point.x + matrix.d * point.y + matrix.f
28123
- }));
28124
- const xs = points.map((point) => point.x);
28125
- const ys = points.map((point) => point.y);
28126
- const x = Math.min(...xs);
28127
- const y = Math.min(...ys);
28128
- const width2 = Math.max(...xs) - x;
28129
- const height2 = Math.max(...ys) - y;
28130
- if (!Number.isFinite(width2) || !Number.isFinite(height2) || width2 <= 0 || height2 <= 0) {
28131
- return null;
28132
- }
28133
- return {
28134
- box: { x, y, width: width2, height: height2 },
28135
- matrix
28136
- };
28137
- }
28138
- function getSvgRootSpaceMatrix(element) {
28139
- const elementMatrix = typeof element.getCTM === "function" ? element.getCTM() : null;
28140
- const rootMatrix = typeof element.ownerSVGElement?.getCTM === "function" ? element.ownerSVGElement.getCTM() : null;
28141
- if (!elementMatrix) {
28142
- return null;
28143
- }
28144
- return rootMatrix ? multiplySvgMatrices(invertSvgMatrix(rootMatrix), elementMatrix) : toSvgMatrixLike(elementMatrix);
28145
- }
28146
- function invertSvgMatrix(matrix) {
28147
- const determinant = matrix.a * matrix.d - matrix.b * matrix.c;
28148
- if (!Number.isFinite(determinant) || determinant === 0) {
28149
- return {
28150
- a: 1,
28151
- b: 0,
28152
- c: 0,
28153
- d: 1,
28154
- e: 0,
28155
- f: 0
28156
- };
28157
- }
28158
- return {
28159
- a: matrix.d / determinant,
28160
- b: -matrix.b / determinant,
28161
- c: -matrix.c / determinant,
28162
- d: matrix.a / determinant,
28163
- e: (matrix.c * matrix.f - matrix.d * matrix.e) / determinant,
28164
- f: (matrix.b * matrix.e - matrix.a * matrix.f) / determinant
28165
- };
28166
- }
28167
- function multiplySvgMatrices(left, right) {
28168
- return {
28169
- a: left.a * right.a + left.c * right.b,
28170
- b: left.b * right.a + left.d * right.b,
28171
- c: left.a * right.c + left.c * right.d,
28172
- d: left.b * right.c + left.d * right.d,
28173
- e: left.a * right.e + left.c * right.f + left.e,
28174
- f: left.b * right.e + left.d * right.f + left.f
28175
- };
28176
- }
28177
- function toSvgMatrixLike(matrix) {
28178
- return {
28179
- a: matrix.a,
28180
- b: matrix.b,
28181
- c: matrix.c,
28182
- d: matrix.d,
28183
- e: matrix.e,
28184
- f: matrix.f
28185
- };
28186
- }
28187
- function readSvgBox(element) {
28188
- if (typeof element.getBBox !== "function") {
28189
- return null;
28190
- }
28191
- try {
28192
- const box = element.getBBox();
28193
- if (!Number.isFinite(box.width) || !Number.isFinite(box.height) || box.width <= 0 || box.height <= 0) {
28194
- return null;
28195
- }
28196
- return {
28197
- x: box.x,
28198
- y: box.y,
28199
- width: box.width,
28200
- height: box.height
28201
- };
28202
- } catch {
28203
- return null;
28204
- }
28205
- }
28206
- function createInlineSvgViewport(contentBox) {
28207
- const edgePadding = Math.max(0.5, Math.min(contentBox.width, contentBox.height) * 6e-3);
28208
- const inset = edgePadding / 2;
28209
- return {
28210
- x: contentBox.x - inset,
28211
- y: contentBox.y - inset,
28212
- width: contentBox.width + edgePadding,
28213
- height: contentBox.height + edgePadding
28214
- };
28215
- }
28216
- function createInlineSvgClone(source, content, viewport) {
28217
- const clone = source.cloneNode(false);
28218
- const ownerDocument = source.ownerDocument;
28219
- copySvgRootAttributes(source, clone);
28220
- clone.setAttribute(
28221
- "viewBox",
28222
- `0 0 ${roundLength(viewport.width)} ${roundLength(viewport.height)}`
28223
- );
28224
- Array.from(source.children).forEach((child) => {
28225
- if (child.tagName.toLowerCase() === "defs") {
28226
- clone.appendChild(child.cloneNode(true));
28227
- }
28228
- });
28229
- const wrapper = ownerDocument.createElementNS("http://www.w3.org/2000/svg", "g");
28230
- wrapper.setAttribute(
28231
- "transform",
28232
- `translate(${roundLength(-viewport.x)} ${roundLength(-viewport.y)})`
28233
- );
28234
- const flattened = ownerDocument.createElementNS("http://www.w3.org/2000/svg", "g");
28235
- flattened.setAttribute(
28236
- "transform",
28237
- `matrix(${roundLength(content.matrix.a)} ${roundLength(content.matrix.b)} ${roundLength(content.matrix.c)} ${roundLength(content.matrix.d)} ${roundLength(content.matrix.e)} ${roundLength(content.matrix.f)})`
28238
- );
28239
- flattened.appendChild(content.root.cloneNode(true));
28240
- wrapper.appendChild(flattened);
28241
- clone.appendChild(wrapper);
28242
- return clone;
28243
- }
28244
- function copySvgRootAttributes(source, target) {
28245
- const excluded = /* @__PURE__ */ new Set([
28246
- "id",
28247
- "width",
28248
- "height",
28249
- "viewBox",
28250
- "font-size",
28251
- "class",
28252
- "focusable",
28253
- "aria-hidden",
28254
- "xmlns",
28255
- "xmlns:xlink"
28256
- ]);
28257
- Array.from(source.attributes).forEach((attribute) => {
28258
- if (excluded.has(attribute.name)) return;
28259
- target.setAttribute(attribute.name, attribute.value);
28260
- });
28261
- }
28262
- function calculateInlineHeightEm(height2) {
28263
- const heightRatio = height2 / BASE_FORMULA_HEIGHT;
28264
- if (!Number.isFinite(heightRatio) || heightRatio <= SIMPLE_FORMULA_HEIGHT_RATIO) {
28265
- return SIMPLE_INLINE_HEIGHT_EM;
28266
- }
28267
- return Math.min(
28268
- MAX_INLINE_HEIGHT_EM,
28269
- SIMPLE_INLINE_HEIGHT_EM * Math.pow(heightRatio, COMPLEX_FORMULA_SCALE)
28270
- );
28271
- }
28272
- function sizeSvgForInlineDisplay(clone, source, viewport) {
28273
- clone.removeAttribute("font-size");
28274
- const viewBox = clone.viewBox?.baseVal;
28275
- const rect = source.getBoundingClientRect();
28276
- const width2 = viewport?.width || viewBox?.width || rect.width || Number(clone.getAttribute("width")) || 1;
28277
- const height2 = viewport?.height || viewBox?.height || rect.height || Number(clone.getAttribute("height")) || 1;
28278
- const ratio = Math.max(0.1, width2 / Math.max(1, height2));
28279
- const inlineHeightEm = calculateInlineHeightEm(height2);
28280
- const inlineWidthEm = Math.min(40, Math.max(0.75, ratio * inlineHeightEm));
28281
- clone.setAttribute("width", roundLength(width2));
28282
- clone.setAttribute("height", roundLength(height2));
28283
- clone.setAttribute(
28284
- "style",
28285
- mergeInlineStyles2(
28286
- clone.getAttribute("style"),
28287
- "font-size:inherit",
28288
- `width:${roundLength(inlineWidthEm)}em`,
28289
- `height:${roundLength(inlineHeightEm)}em`
28290
- )
28291
- );
28292
- }
28293
- function roundLength(value) {
28294
- return String(Math.round(value * 1e3) / 1e3);
28295
- }
28296
- function uniquifySvgIds(svg2) {
28297
- const idMap = /* @__PURE__ */ new Map();
28298
- const prefix = `fx-${randomIdPrefix()}-`;
28299
- const elementsWithId = svg2.querySelectorAll("[id]");
28300
- elementsWithId.forEach((element) => {
28301
- const id = element.getAttribute("id");
28302
- if (!id) return;
28303
- const nextId = `${prefix}${id}`;
28304
- idMap.set(id, nextId);
28305
- element.setAttribute("id", nextId);
28306
- });
28307
- if (!idMap.size) return;
28308
- svg2.querySelectorAll("*").forEach((element) => {
28309
- Array.from(element.attributes).forEach((attribute) => {
28310
- const nextValue = rewriteSvgReferences(attribute.value, idMap);
28311
- if (nextValue !== attribute.value) {
28312
- element.setAttribute(attribute.name, nextValue);
28313
- }
28314
- });
28315
- });
28316
- }
28317
- function randomIdPrefix() {
28318
- return Math.random().toString(36).slice(2, 5).padEnd(3, "0");
28319
- }
28320
- function rewriteSvgReferences(value, idMap) {
28321
- let nextValue = value;
28322
- idMap.forEach((nextId, id) => {
28323
- nextValue = nextValue.replaceAll(`#${id}`, `#${nextId}`).replaceAll(`url(${id})`, `url(${nextId})`).replaceAll(`url(#${id})`, `url(#${nextId})`);
28324
- });
28325
- return nextValue;
28326
- }
28327
- function mergeClassNames(...values) {
28328
- return values.flatMap((value) => value?.split(/\s+/) ?? []).filter(Boolean).filter((value, index, list) => list.indexOf(value) === index).join(" ");
28329
- }
28330
- function mergeInlineStyles2(...values) {
28331
- return values.flatMap((value) => value?.split(";") ?? []).map((value) => value.trim()).filter(Boolean).join("; ");
28332
- }
28333
-
28334
- // ../kity-runtime/src/index.ts
28335
- init_asset_manifest();
28336
-
28337
- // ../kity-runtime/src/create-editor.ts
28338
- init_asset_manifest();
28339
- init_legacy_box_type();
27616
+ // ../kity-runtime/src/create-editor.ts
27617
+ init_asset_manifest();
27618
+ init_legacy_box_type();
28340
27619
 
28341
27620
  // ../kity-runtime/src/vendor/char-position.ts
28342
27621
  var legacyCharPosition = {
@@ -31968,6 +31247,7 @@ var FormulaX = (() => {
31968
31247
  const locale = normalizeFormulaXLocale(options.locale ?? DEFAULT_FORMULAX_LOCALE);
31969
31248
  const assets = resolveEditorAssets(options.assets);
31970
31249
  try {
31250
+ legacySysconf.rootPlaceholder.content = getFormulaXRuntimeMessage("editor.placeholder.root", locale);
31971
31251
  const stylesheetInserted = ensureKityStylesheet(document, assets.styles.editor);
31972
31252
  if (stylesheetInserted) {
31973
31253
  const stylesheetInsertedMark = markFormulaXPerf("fx:kity-css:link-inserted");
@@ -32099,6 +31379,704 @@ var FormulaX = (() => {
32099
31379
  init_legacy_ui_utils();
32100
31380
  init_legacy_utils();
32101
31381
 
31382
+ // ../core/src/ast.ts
31383
+ var text = (value) => ({ type: "text", value });
31384
+ var group = (body = []) => ({ type: "group", body });
31385
+ var doc = (body = []) => ({ type: "doc", body });
31386
+ var frac = (numerator = [], denominator = []) => ({
31387
+ type: "frac",
31388
+ numerator,
31389
+ denominator
31390
+ });
31391
+ var supsub = (base, sup, sub) => ({
31392
+ type: "supsub",
31393
+ base,
31394
+ sup,
31395
+ sub
31396
+ });
31397
+ var sqrt = (value = []) => ({ type: "sqrt", value });
31398
+ var fenced = (left, right, body = []) => ({
31399
+ type: "fenced",
31400
+ left,
31401
+ right,
31402
+ body
31403
+ });
31404
+
31405
+ // ../core/src/commands.ts
31406
+ var createEmptyState = () => ({
31407
+ doc: { type: "doc", body: [] },
31408
+ selection: { anchor: [0], focus: [0] }
31409
+ });
31410
+
31411
+ // ../core/src/latex.ts
31412
+ var isAlpha = (char) => /[a-zA-Z]/.test(char);
31413
+ var GREEK_LETTERS = {
31414
+ alpha: "\u03B1",
31415
+ beta: "\u03B2",
31416
+ gamma: "\u03B3",
31417
+ delta: "\u03B4",
31418
+ epsilon: "\u03B5",
31419
+ zeta: "\u03B6",
31420
+ eta: "\u03B7",
31421
+ theta: "\u03B8",
31422
+ iota: "\u03B9",
31423
+ kappa: "\u03BA",
31424
+ lambda: "\u03BB",
31425
+ mu: "\u03BC",
31426
+ nu: "\u03BD",
31427
+ xi: "\u03BE",
31428
+ omicron: "\u03BF",
31429
+ pi: "\u03C0",
31430
+ rho: "\u03C1",
31431
+ sigma: "\u03C3",
31432
+ tau: "\u03C4",
31433
+ upsilon: "\u03C5",
31434
+ phi: "\u03C6",
31435
+ chi: "\u03C7",
31436
+ psi: "\u03C8",
31437
+ omega: "\u03C9",
31438
+ Gamma: "\u0393",
31439
+ Delta: "\u0394",
31440
+ Theta: "\u0398",
31441
+ Lambda: "\u039B",
31442
+ Xi: "\u039E",
31443
+ Pi: "\u03A0",
31444
+ Sigma: "\u03A3",
31445
+ Phi: "\u03A6",
31446
+ Psi: "\u03A8",
31447
+ Omega: "\u03A9"
31448
+ };
31449
+ var BINARY_OPERATORS = {
31450
+ cdot: "\xB7",
31451
+ times: "\xD7",
31452
+ div: "\xF7",
31453
+ pm: "\xB1",
31454
+ mp: "\u2213",
31455
+ ast: "\u2217",
31456
+ star: "\u22C6",
31457
+ circ: "\u2218",
31458
+ bullet: "\u2022",
31459
+ cup: "\u222A",
31460
+ cap: "\u2229",
31461
+ vee: "\u2228",
31462
+ wedge: "\u2227",
31463
+ setminus: "\u2216"
31464
+ };
31465
+ var MATH_FUNCTIONS = {
31466
+ sin: "sin",
31467
+ cos: "cos",
31468
+ tan: "tan",
31469
+ cot: "cot",
31470
+ sec: "sec",
31471
+ csc: "csc",
31472
+ arcsin: "arcsin",
31473
+ arccos: "arccos",
31474
+ arctan: "arctan",
31475
+ sinh: "sinh",
31476
+ cosh: "cosh",
31477
+ tanh: "tanh",
31478
+ log: "log",
31479
+ ln: "ln",
31480
+ exp: "exp",
31481
+ lim: "lim",
31482
+ det: "det",
31483
+ dim: "dim",
31484
+ deg: "deg",
31485
+ max: "max",
31486
+ min: "min"
31487
+ };
31488
+ var RELATIONS = {
31489
+ leq: "\u2264",
31490
+ le: "\u2264",
31491
+ ge: "\u2265",
31492
+ geq: "\u2265",
31493
+ ne: "\u2260",
31494
+ neq: "\u2260",
31495
+ approx: "\u2248",
31496
+ equiv: "\u2261",
31497
+ sim: "\u223C",
31498
+ simeq: "\u2243",
31499
+ cong: "\u2245",
31500
+ perp: "\u22A5",
31501
+ parallel: "\u2225",
31502
+ propto: "\u221D",
31503
+ leqslant: "\u2A7D",
31504
+ geqslant: "\u2A7E"
31505
+ };
31506
+ var ARROWS = {
31507
+ to: "\u2192",
31508
+ gets: "\u2190",
31509
+ leftrightarrow: "\u2194",
31510
+ rightarrow: "\u2192",
31511
+ leftarrow: "\u2190",
31512
+ Rightarrow: "\u21D2",
31513
+ Leftarrow: "\u21D0",
31514
+ Leftrightarrow: "\u21D4",
31515
+ mapsto: "\u21A6",
31516
+ longmapsto: "\u27FC",
31517
+ nearrow: "\u2197",
31518
+ searrow: "\u2198",
31519
+ swarrow: "\u2199",
31520
+ nwarrow: "\u2196"
31521
+ };
31522
+ var MISC_SYMBOLS = {
31523
+ infty: "\u221E",
31524
+ infinity: "\u221E",
31525
+ aleph: "\u2135",
31526
+ wp: "\u2118",
31527
+ Re: "\u211C",
31528
+ Im: "\u2111",
31529
+ partial: "\u2202",
31530
+ nabla: "\u2207",
31531
+ forall: "\u2200",
31532
+ exists: "\u2203",
31533
+ neg: "\xAC",
31534
+ prime: "\u2032",
31535
+ dprime: "\u2033",
31536
+ triangle: "\u25B3",
31537
+ square: "\u25A1",
31538
+ flat: "\u266D",
31539
+ natural: "\u266E",
31540
+ sharp: "\u266F",
31541
+ dag: "\u2020",
31542
+ ddag: "\u2021"
31543
+ };
31544
+ var LATEX_SYMBOLS = {
31545
+ ...GREEK_LETTERS,
31546
+ ...BINARY_OPERATORS,
31547
+ ...MATH_FUNCTIONS,
31548
+ ...RELATIONS,
31549
+ ...ARROWS,
31550
+ ...MISC_SYMBOLS
31551
+ };
31552
+ var SYMBOL_TO_LATEX = Object.entries(LATEX_SYMBOLS).reduce((acc, [command2, symbol]) => {
31553
+ if (!(symbol in acc)) {
31554
+ acc[symbol] = command2;
31555
+ }
31556
+ return acc;
31557
+ }, {});
31558
+ var symbolToLatexCommand = (symbol) => SYMBOL_TO_LATEX[symbol] ?? null;
31559
+ var serializeTextValue = (value) => {
31560
+ const command2 = symbolToLatexCommand(value);
31561
+ return command2 ? `\\${command2} ` : value;
31562
+ };
31563
+ var LatexParser = class {
31564
+ constructor(input) {
31565
+ this.input = input;
31566
+ }
31567
+ input;
31568
+ index = 0;
31569
+ parse() {
31570
+ return doc(this.parseSequence());
31571
+ }
31572
+ parseSequence(stopChar) {
31573
+ const nodes = [];
31574
+ while (this.index < this.input.length) {
31575
+ const current = this.input[this.index];
31576
+ if (stopChar && current === stopChar) {
31577
+ this.index += 1;
31578
+ break;
31579
+ }
31580
+ if (current === "{") {
31581
+ this.index += 1;
31582
+ nodes.push(group(this.parseSequence("}")));
31583
+ continue;
31584
+ }
31585
+ if (current === "^" || current === "_") {
31586
+ const modifier = current;
31587
+ this.index += 1;
31588
+ const last = nodes.pop() ?? text("");
31589
+ const target = this.parseAtomAsList();
31590
+ const base = last.type === "group" ? last.body : [last];
31591
+ if (modifier === "^") {
31592
+ nodes.push(supsub(base, target));
31593
+ } else {
31594
+ nodes.push(supsub(base, void 0, target));
31595
+ }
31596
+ continue;
31597
+ }
31598
+ if (current === "\\") {
31599
+ nodes.push(this.parseCommand());
31600
+ continue;
31601
+ }
31602
+ if (["(", "["].includes(current)) {
31603
+ this.index += 1;
31604
+ const right = current === "(" ? ")" : "]";
31605
+ nodes.push(fenced(current, right, this.parseSequence(right)));
31606
+ continue;
31607
+ }
31608
+ nodes.push(text(current));
31609
+ this.index += 1;
31610
+ }
31611
+ return nodes;
31612
+ }
31613
+ parseCommand() {
31614
+ this.index += 1;
31615
+ let command2 = "";
31616
+ while (this.index < this.input.length && isAlpha(this.input[this.index])) {
31617
+ command2 += this.input[this.index];
31618
+ this.index += 1;
31619
+ }
31620
+ if (command2 === "frac") {
31621
+ const numerator = this.parseAtomAsList();
31622
+ const denominator = this.parseAtomAsList();
31623
+ return frac(numerator, denominator);
31624
+ }
31625
+ if (command2 === "sqrt") {
31626
+ return sqrt(this.parseAtomAsList());
31627
+ }
31628
+ if (LATEX_SYMBOLS[command2]) {
31629
+ return text(LATEX_SYMBOLS[command2]);
31630
+ }
31631
+ if (command2 === "left") {
31632
+ const left = this.input[this.index] ?? "(";
31633
+ this.index += 1;
31634
+ const body = [];
31635
+ while (!this.input.startsWith("\\right", this.index) && this.index < this.input.length) {
31636
+ body.push(...this.parseSequenceChunk());
31637
+ }
31638
+ this.index += "\\right".length;
31639
+ const right = this.input[this.index] ?? ")";
31640
+ this.index += 1;
31641
+ return fenced(left, right, body);
31642
+ }
31643
+ return text(`\\${command2}`);
31644
+ }
31645
+ parseSequenceChunk() {
31646
+ const char = this.input[this.index];
31647
+ if (char === "{") {
31648
+ this.index += 1;
31649
+ return [group(this.parseSequence("}"))];
31650
+ }
31651
+ if (char === "\\") {
31652
+ return [this.parseCommand()];
31653
+ }
31654
+ if (char === "(" || char === "[") {
31655
+ this.index += 1;
31656
+ const right = char === "(" ? ")" : "]";
31657
+ return [fenced(char, right, this.parseSequence(right))];
31658
+ }
31659
+ this.index += 1;
31660
+ return [text(char)];
31661
+ }
31662
+ parseAtomAsList() {
31663
+ if (this.input[this.index] === "{") {
31664
+ this.index += 1;
31665
+ return this.parseSequence("}");
31666
+ }
31667
+ return this.parseSequenceChunk();
31668
+ }
31669
+ };
31670
+ var serializeList = (nodes) => nodes.map(serializeNode).join("");
31671
+ var serializeNode = (node) => {
31672
+ switch (node.type) {
31673
+ case "doc":
31674
+ return serializeList(node.body);
31675
+ case "group":
31676
+ return `{${serializeList(node.body)}}`;
31677
+ case "text":
31678
+ return serializeTextValue(node.value);
31679
+ case "frac":
31680
+ return `\\frac{${serializeList(node.numerator)}}{${serializeList(node.denominator)}}`;
31681
+ case "supsub": {
31682
+ const base = serializeList(node.base);
31683
+ const sup = node.sup ? `^{${serializeList(node.sup)}}` : "";
31684
+ const sub = node.sub ? `_{${serializeList(node.sub)}}` : "";
31685
+ return `${base}${sup}${sub}`;
31686
+ }
31687
+ case "sqrt":
31688
+ return `\\sqrt{${serializeList(node.value)}}`;
31689
+ case "fenced":
31690
+ return `\\left${node.left}${serializeList(node.body)}\\right${node.right}`;
31691
+ }
31692
+ };
31693
+ var parseLatex = (input) => new LatexParser(input).parse();
31694
+ var serializeLatex = (document2) => serializeNode(document2);
31695
+
31696
+ // ../renderer/src/markup.ts
31697
+ var DEFAULT_FORMULA_ATTRIBUTE = "data-formulax-latex";
31698
+ var FORMULA_FLAG_ATTRIBUTE = "data-formulax";
31699
+ var DEFAULT_FORMULA_CLASS = "formulax-math";
31700
+ function escapeAttribute(value) {
31701
+ return value.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
31702
+ }
31703
+ function escapeHtml(value) {
31704
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
31705
+ }
31706
+ function createFormulaMarkup(latex, options = {}) {
31707
+ const attributeName = options.attributeName ?? DEFAULT_FORMULA_ATTRIBUTE;
31708
+ const className = options.className ?? DEFAULT_FORMULA_CLASS;
31709
+ const displayClass = options.displayMode ? `${className} ${className}--block` : className;
31710
+ const safeLatex = escapeAttribute(latex);
31711
+ const cursorStyle = options.cursorStyle?.trim() || "pointer";
31712
+ const extraAttributes = {
31713
+ ...options.extraAttributes ?? {},
31714
+ style: mergeInlineStyles(
31715
+ typeof options.extraAttributes?.style === "string" ? options.extraAttributes.style : "",
31716
+ cursorStyle ? `cursor: ${cursorStyle}` : ""
31717
+ )
31718
+ };
31719
+ const serializedAttributes = Object.entries(extraAttributes).filter(([, value]) => value !== null && value !== void 0 && value !== false).map(([key, value]) => value === true ? key : `${key}="${escapeAttribute(String(value))}"`);
31720
+ return [
31721
+ "<span",
31722
+ ` class="${escapeAttribute(displayClass)}"`,
31723
+ ` ${FORMULA_FLAG_ATTRIBUTE}="true"`,
31724
+ ` ${attributeName}="${safeLatex}"`,
31725
+ ` data-latex="${safeLatex}"`,
31726
+ ' contenteditable="false"',
31727
+ ' role="button"',
31728
+ ' tabindex="0"',
31729
+ serializedAttributes.length ? ` ${serializedAttributes.join(" ")}` : "",
31730
+ ">",
31731
+ options.renderHtml ?? `<span class="${escapeAttribute(className)}__render">${escapeHtml(latex || "\\square")}</span>`,
31732
+ "</span>"
31733
+ ].join("");
31734
+ }
31735
+ function mergeInlineStyles(existingStyle, nextStyle) {
31736
+ const existing = existingStyle.trim().replace(/;+\s*$/, "");
31737
+ const next = nextStyle.trim().replace(/;+\s*$/, "");
31738
+ if (!existing) return next;
31739
+ if (!next) return existing;
31740
+ return `${existing}; ${next}`;
31741
+ }
31742
+ function createFormulaElement(ownerDocument, latex, options = {}) {
31743
+ const wrapper = ownerDocument.createElement("span");
31744
+ wrapper.innerHTML = createFormulaMarkup(latex, options);
31745
+ return wrapper.firstElementChild;
31746
+ }
31747
+ function getFormulaLatexFromElement(element, attributeName = DEFAULT_FORMULA_ATTRIBUTE) {
31748
+ return element.getAttribute(attributeName) ?? element.getAttribute("data-latex") ?? "";
31749
+ }
31750
+
31751
+ // ../renderer/src/styles.ts
31752
+ var FORMULAX_BASE_STYLE_ID = "fx-formulax-base-styles";
31753
+ var formulaXBaseStyles = `
31754
+ .formulax-math {
31755
+ display: inline-flex;
31756
+ align-items: center;
31757
+ vertical-align: middle;
31758
+ line-height: 1;
31759
+ padding: 0 2px;
31760
+ margin: 0 1px;
31761
+ border-radius: 3px;
31762
+ background: transparent;
31763
+ cursor: pointer;
31764
+ user-select: none;
31765
+ }
31766
+
31767
+ .formulax-math:hover {
31768
+ outline: 1px solid rgba(37, 99, 235, 0.35);
31769
+ background: rgba(37, 99, 235, 0.06);
31770
+ }
31771
+
31772
+ .formulax-math__render,
31773
+ .formulax-math__svg,
31774
+ .formulax-math__image {
31775
+ display: inline-block;
31776
+ max-width: 100%;
31777
+ pointer-events: none;
31778
+ }
31779
+
31780
+ .formulax-math__render {
31781
+ vertical-align: middle;
31782
+ font-family: "KF AMS MAIN", "Cambria Math", "Latin Modern Math", "Times New Roman", serif;
31783
+ }
31784
+
31785
+ .formulax-math__svg {
31786
+ flex: 0 0 auto;
31787
+ vertical-align: -0.35em;
31788
+ }
31789
+
31790
+ .formulax-math__image {
31791
+ height: auto;
31792
+ vertical-align: middle;
31793
+ }
31794
+ `;
31795
+ function ensureFormulaXBaseStyles(doc2 = document) {
31796
+ if (doc2.getElementById(FORMULAX_BASE_STYLE_ID)) return;
31797
+ const style = doc2.createElement("style");
31798
+ style.id = FORMULAX_BASE_STYLE_ID;
31799
+ style.textContent = formulaXBaseStyles;
31800
+ doc2.head.appendChild(style);
31801
+ }
31802
+
31803
+ // ../renderer/src/cache.ts
31804
+ function createFormulaRenderCacheKey(input) {
31805
+ return JSON.stringify({
31806
+ engine: input.engine,
31807
+ latex: input.latex,
31808
+ output: input.output,
31809
+ fontSize: input.fontSize,
31810
+ displayMode: input.displayMode,
31811
+ className: input.className,
31812
+ assetCacheKey: input.assetCacheKey
31813
+ });
31814
+ }
31815
+
31816
+ // ../renderer/src/svg.ts
31817
+ var SIMPLE_INLINE_HEIGHT_EM = 1.25;
31818
+ var BASE_FORMULA_HEIGHT = 40.5;
31819
+ var SIMPLE_FORMULA_HEIGHT_RATIO = 1.05;
31820
+ var MAX_INLINE_HEIGHT_EM = 1.65;
31821
+ var COMPLEX_FORMULA_SCALE = 0.825;
31822
+ function readRenderedFormulaSvgBox(svg2) {
31823
+ return getInlineSvgContent(svg2)?.box ?? readSvgBox(svg2);
31824
+ }
31825
+ function serializeSvgForInsertion(svg2) {
31826
+ const content = getInlineSvgContent(svg2);
31827
+ const inlineViewport = content ? createInlineSvgViewport(content.box) : null;
31828
+ const clone = content && inlineViewport ? createInlineSvgClone(svg2, content, inlineViewport) : svg2.cloneNode(true);
31829
+ uniquifySvgIds(clone);
31830
+ sizeSvgForInlineDisplay(clone, svg2, inlineViewport);
31831
+ clone.setAttribute("focusable", "false");
31832
+ clone.setAttribute("aria-hidden", "true");
31833
+ clone.setAttribute("class", mergeClassNames(clone.getAttribute("class"), "formulax-math__svg"));
31834
+ return clone.outerHTML;
31835
+ }
31836
+ function getInlineSvgContent(svg2) {
31837
+ const selectorCandidates = [
31838
+ '[data-type="kf-editor-exp-content-box"]',
31839
+ '[data-root="true"] [data-type="kf-editor-exp-content-box"]',
31840
+ 'g[data-root="true"]'
31841
+ ];
31842
+ for (const selector of selectorCandidates) {
31843
+ const element = svg2.querySelector(selector);
31844
+ if (!element) continue;
31845
+ const rootSpace = readSvgBoxInRootSpace(element);
31846
+ if (!rootSpace) continue;
31847
+ return {
31848
+ box: rootSpace.box,
31849
+ matrix: rootSpace.matrix,
31850
+ root: element
31851
+ };
31852
+ }
31853
+ return null;
31854
+ }
31855
+ function readSvgBoxInRootSpace(element) {
31856
+ const box = readSvgBox(element);
31857
+ const matrix = getSvgRootSpaceMatrix(element);
31858
+ if (!box || !matrix) {
31859
+ return null;
31860
+ }
31861
+ const points = [
31862
+ { x: box.x, y: box.y },
31863
+ { x: box.x + box.width, y: box.y },
31864
+ { x: box.x, y: box.y + box.height },
31865
+ { x: box.x + box.width, y: box.y + box.height }
31866
+ ].map((point) => ({
31867
+ x: matrix.a * point.x + matrix.c * point.y + matrix.e,
31868
+ y: matrix.b * point.x + matrix.d * point.y + matrix.f
31869
+ }));
31870
+ const xs = points.map((point) => point.x);
31871
+ const ys = points.map((point) => point.y);
31872
+ const x = Math.min(...xs);
31873
+ const y = Math.min(...ys);
31874
+ const width2 = Math.max(...xs) - x;
31875
+ const height2 = Math.max(...ys) - y;
31876
+ if (!Number.isFinite(width2) || !Number.isFinite(height2) || width2 <= 0 || height2 <= 0) {
31877
+ return null;
31878
+ }
31879
+ return {
31880
+ box: { x, y, width: width2, height: height2 },
31881
+ matrix
31882
+ };
31883
+ }
31884
+ function getSvgRootSpaceMatrix(element) {
31885
+ const elementMatrix = typeof element.getCTM === "function" ? element.getCTM() : null;
31886
+ const rootMatrix = typeof element.ownerSVGElement?.getCTM === "function" ? element.ownerSVGElement.getCTM() : null;
31887
+ if (!elementMatrix) {
31888
+ return null;
31889
+ }
31890
+ return rootMatrix ? multiplySvgMatrices(invertSvgMatrix(rootMatrix), elementMatrix) : toSvgMatrixLike(elementMatrix);
31891
+ }
31892
+ function invertSvgMatrix(matrix) {
31893
+ const determinant = matrix.a * matrix.d - matrix.b * matrix.c;
31894
+ if (!Number.isFinite(determinant) || determinant === 0) {
31895
+ return {
31896
+ a: 1,
31897
+ b: 0,
31898
+ c: 0,
31899
+ d: 1,
31900
+ e: 0,
31901
+ f: 0
31902
+ };
31903
+ }
31904
+ return {
31905
+ a: matrix.d / determinant,
31906
+ b: -matrix.b / determinant,
31907
+ c: -matrix.c / determinant,
31908
+ d: matrix.a / determinant,
31909
+ e: (matrix.c * matrix.f - matrix.d * matrix.e) / determinant,
31910
+ f: (matrix.b * matrix.e - matrix.a * matrix.f) / determinant
31911
+ };
31912
+ }
31913
+ function multiplySvgMatrices(left, right) {
31914
+ return {
31915
+ a: left.a * right.a + left.c * right.b,
31916
+ b: left.b * right.a + left.d * right.b,
31917
+ c: left.a * right.c + left.c * right.d,
31918
+ d: left.b * right.c + left.d * right.d,
31919
+ e: left.a * right.e + left.c * right.f + left.e,
31920
+ f: left.b * right.e + left.d * right.f + left.f
31921
+ };
31922
+ }
31923
+ function toSvgMatrixLike(matrix) {
31924
+ return {
31925
+ a: matrix.a,
31926
+ b: matrix.b,
31927
+ c: matrix.c,
31928
+ d: matrix.d,
31929
+ e: matrix.e,
31930
+ f: matrix.f
31931
+ };
31932
+ }
31933
+ function readSvgBox(element) {
31934
+ if (typeof element.getBBox !== "function") {
31935
+ return null;
31936
+ }
31937
+ try {
31938
+ const box = element.getBBox();
31939
+ if (!Number.isFinite(box.width) || !Number.isFinite(box.height) || box.width <= 0 || box.height <= 0) {
31940
+ return null;
31941
+ }
31942
+ return {
31943
+ x: box.x,
31944
+ y: box.y,
31945
+ width: box.width,
31946
+ height: box.height
31947
+ };
31948
+ } catch {
31949
+ return null;
31950
+ }
31951
+ }
31952
+ function createInlineSvgViewport(contentBox) {
31953
+ const edgePadding = Math.max(0.5, Math.min(contentBox.width, contentBox.height) * 6e-3);
31954
+ const inset = edgePadding / 2;
31955
+ return {
31956
+ x: contentBox.x - inset,
31957
+ y: contentBox.y - inset,
31958
+ width: contentBox.width + edgePadding,
31959
+ height: contentBox.height + edgePadding
31960
+ };
31961
+ }
31962
+ function createInlineSvgClone(source, content, viewport) {
31963
+ const clone = source.cloneNode(false);
31964
+ const ownerDocument = source.ownerDocument;
31965
+ copySvgRootAttributes(source, clone);
31966
+ clone.setAttribute(
31967
+ "viewBox",
31968
+ `0 0 ${roundLength(viewport.width)} ${roundLength(viewport.height)}`
31969
+ );
31970
+ Array.from(source.children).forEach((child) => {
31971
+ if (child.tagName.toLowerCase() === "defs") {
31972
+ clone.appendChild(child.cloneNode(true));
31973
+ }
31974
+ });
31975
+ const wrapper = ownerDocument.createElementNS("http://www.w3.org/2000/svg", "g");
31976
+ wrapper.setAttribute(
31977
+ "transform",
31978
+ `translate(${roundLength(-viewport.x)} ${roundLength(-viewport.y)})`
31979
+ );
31980
+ const flattened = ownerDocument.createElementNS("http://www.w3.org/2000/svg", "g");
31981
+ flattened.setAttribute(
31982
+ "transform",
31983
+ `matrix(${roundLength(content.matrix.a)} ${roundLength(content.matrix.b)} ${roundLength(content.matrix.c)} ${roundLength(content.matrix.d)} ${roundLength(content.matrix.e)} ${roundLength(content.matrix.f)})`
31984
+ );
31985
+ flattened.appendChild(content.root.cloneNode(true));
31986
+ wrapper.appendChild(flattened);
31987
+ clone.appendChild(wrapper);
31988
+ return clone;
31989
+ }
31990
+ function copySvgRootAttributes(source, target) {
31991
+ const excluded = /* @__PURE__ */ new Set([
31992
+ "id",
31993
+ "width",
31994
+ "height",
31995
+ "viewBox",
31996
+ "font-size",
31997
+ "class",
31998
+ "focusable",
31999
+ "aria-hidden",
32000
+ "xmlns",
32001
+ "xmlns:xlink"
32002
+ ]);
32003
+ Array.from(source.attributes).forEach((attribute) => {
32004
+ if (excluded.has(attribute.name)) return;
32005
+ target.setAttribute(attribute.name, attribute.value);
32006
+ });
32007
+ }
32008
+ function calculateInlineHeightEm(height2) {
32009
+ const heightRatio = height2 / BASE_FORMULA_HEIGHT;
32010
+ if (!Number.isFinite(heightRatio) || heightRatio <= SIMPLE_FORMULA_HEIGHT_RATIO) {
32011
+ return SIMPLE_INLINE_HEIGHT_EM;
32012
+ }
32013
+ return Math.min(
32014
+ MAX_INLINE_HEIGHT_EM,
32015
+ SIMPLE_INLINE_HEIGHT_EM * Math.pow(heightRatio, COMPLEX_FORMULA_SCALE)
32016
+ );
32017
+ }
32018
+ function sizeSvgForInlineDisplay(clone, source, viewport) {
32019
+ clone.removeAttribute("font-size");
32020
+ const viewBox = clone.viewBox?.baseVal;
32021
+ const rect = source.getBoundingClientRect();
32022
+ const width2 = viewport?.width || viewBox?.width || rect.width || Number(clone.getAttribute("width")) || 1;
32023
+ const height2 = viewport?.height || viewBox?.height || rect.height || Number(clone.getAttribute("height")) || 1;
32024
+ const ratio = Math.max(0.1, width2 / Math.max(1, height2));
32025
+ const inlineHeightEm = calculateInlineHeightEm(height2);
32026
+ const inlineWidthEm = Math.min(40, Math.max(0.75, ratio * inlineHeightEm));
32027
+ clone.setAttribute("width", roundLength(width2));
32028
+ clone.setAttribute("height", roundLength(height2));
32029
+ clone.setAttribute(
32030
+ "style",
32031
+ mergeInlineStyles2(
32032
+ clone.getAttribute("style"),
32033
+ "font-size:inherit",
32034
+ `width:${roundLength(inlineWidthEm)}em`,
32035
+ `height:${roundLength(inlineHeightEm)}em`
32036
+ )
32037
+ );
32038
+ }
32039
+ function roundLength(value) {
32040
+ return String(Math.round(value * 1e3) / 1e3);
32041
+ }
32042
+ function uniquifySvgIds(svg2) {
32043
+ const idMap = /* @__PURE__ */ new Map();
32044
+ const prefix = `fx-${randomIdPrefix()}-`;
32045
+ const elementsWithId = svg2.querySelectorAll("[id]");
32046
+ elementsWithId.forEach((element) => {
32047
+ const id = element.getAttribute("id");
32048
+ if (!id) return;
32049
+ const nextId = `${prefix}${id}`;
32050
+ idMap.set(id, nextId);
32051
+ element.setAttribute("id", nextId);
32052
+ });
32053
+ if (!idMap.size) return;
32054
+ svg2.querySelectorAll("*").forEach((element) => {
32055
+ Array.from(element.attributes).forEach((attribute) => {
32056
+ const nextValue = rewriteSvgReferences(attribute.value, idMap);
32057
+ if (nextValue !== attribute.value) {
32058
+ element.setAttribute(attribute.name, nextValue);
32059
+ }
32060
+ });
32061
+ });
32062
+ }
32063
+ function randomIdPrefix() {
32064
+ return Math.random().toString(36).slice(2, 5).padEnd(3, "0");
32065
+ }
32066
+ function rewriteSvgReferences(value, idMap) {
32067
+ let nextValue = value;
32068
+ idMap.forEach((nextId, id) => {
32069
+ nextValue = nextValue.replaceAll(`#${id}`, `#${nextId}`).replaceAll(`url(${id})`, `url(${nextId})`).replaceAll(`url(#${id})`, `url(#${nextId})`);
32070
+ });
32071
+ return nextValue;
32072
+ }
32073
+ function mergeClassNames(...values) {
32074
+ return values.flatMap((value) => value?.split(/\s+/) ?? []).filter(Boolean).filter((value, index, list) => list.indexOf(value) === index).join(" ");
32075
+ }
32076
+ function mergeInlineStyles2(...values) {
32077
+ return values.flatMap((value) => value?.split(";") ?? []).map((value) => value.trim()).filter(Boolean).join("; ");
32078
+ }
32079
+
32102
32080
  // ../renderer-kity/src/dom.ts
32103
32081
  function createHiddenRenderHost(doc2 = document) {
32104
32082
  const host = doc2.createElement("div");
@@ -32181,7 +32159,7 @@ var FormulaX = (() => {
32181
32159
  }
32182
32160
  function renderLatexToSvgMarkup(latex, options = {}) {
32183
32161
  const normalizedLatex = latex.trim();
32184
- const shouldUseCache = options.cache !== false && !(hasCustomAssetOverrides(options.assets) && !options.assetsVersion);
32162
+ const shouldUseCache = options.cache !== false && !(hasCustomAssetOverrides(options.assets) && !options.assetCacheKey);
32185
32163
  if (!normalizedLatex) {
32186
32164
  return Promise.resolve({
32187
32165
  engine: "kity",
@@ -32197,7 +32175,7 @@ var FormulaX = (() => {
32197
32175
  fontSize: options.fontSize,
32198
32176
  displayMode: options.displayMode,
32199
32177
  className: options.className,
32200
- assetsVersion: options.assetsVersion
32178
+ assetCacheKey: options.assetCacheKey
32201
32179
  });
32202
32180
  if (shouldUseCache) {
32203
32181
  const cached = renderCache.get(cacheKey);
@@ -32410,8 +32388,11 @@ var FormulaX = (() => {
32410
32388
  inset: 0;
32411
32389
  z-index: 2147483000;
32412
32390
  display: flex;
32413
- align-items: center;
32391
+ align-items: flex-start;
32414
32392
  justify-content: center;
32393
+ padding: 16px;
32394
+ overflow-x: hidden;
32395
+ overflow-y: auto;
32415
32396
  }
32416
32397
 
32417
32398
  .fx-formula-modal-backdrop {
@@ -32424,9 +32405,10 @@ var FormulaX = (() => {
32424
32405
  --fx-formula-editor-body-height: 264px;
32425
32406
  --fx-formula-workspace-height: 168px;
32426
32407
  position: relative;
32427
- width: min(860px, calc(100vw - 32px));
32408
+ width: min(920px, calc(100vw - 32px));
32428
32409
  height: auto;
32429
- max-height: calc(100vh - 32px);
32410
+ max-height: none;
32411
+ margin: 0 auto;
32430
32412
  background: #fff;
32431
32413
  border-radius: 14px;
32432
32414
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
@@ -32644,6 +32626,7 @@ var FormulaX = (() => {
32644
32626
  initialLatex,
32645
32627
  height: options.height ?? "100%",
32646
32628
  autofocus: options.autofocus ?? true,
32629
+ locale: options.locale,
32647
32630
  assets: options.assets,
32648
32631
  render: {
32649
32632
  fontsize: options.render?.fontsize ?? 40
@@ -32748,6 +32731,26 @@ var FormulaX = (() => {
32748
32731
  return null;
32749
32732
  }
32750
32733
 
32734
+ // ../editor/src/i18n.ts
32735
+ var FORMULAX_EDITOR_MESSAGES = {
32736
+ en_US: {
32737
+ "modal.title": "FormulaX Editor",
32738
+ "modal.insert": "Insert",
32739
+ "modal.update": "Update",
32740
+ "modal.cancel": "Cancel"
32741
+ },
32742
+ zh_CN: {
32743
+ "modal.title": "FormulaX \u7F16\u8F91\u5668",
32744
+ "modal.insert": "\u63D2\u5165",
32745
+ "modal.update": "\u66F4\u65B0",
32746
+ "modal.cancel": "\u53D6\u6D88"
32747
+ }
32748
+ };
32749
+ function getFormulaXEditorMessage(key, locale = DEFAULT_FORMULAX_LOCALE) {
32750
+ const normalizedLocale = normalizeFormulaXLocale(locale);
32751
+ return FORMULAX_EDITOR_MESSAGES[normalizedLocale][key] ?? FORMULAX_EDITOR_MESSAGES[DEFAULT_FORMULAX_LOCALE][key];
32752
+ }
32753
+
32751
32754
  // src/modal.ts
32752
32755
  function openFormulaXTiptapModal(input) {
32753
32756
  recordFormulaXPerfPoint("fx:modal:open:start");
@@ -32799,6 +32802,7 @@ var FormulaX = (() => {
32799
32802
  initialLatex: input.initialLatex,
32800
32803
  height: input.options.editor.height,
32801
32804
  autofocus: input.options.editor.autofocus,
32805
+ locale: input.options.editor.locale,
32802
32806
  assets: input.options.editor.assets,
32803
32807
  render: {
32804
32808
  fontsize: input.options.editor.render.fontsize
@@ -32879,6 +32883,7 @@ var FormulaX = (() => {
32879
32883
  // src/index.ts
32880
32884
  var FORMULAX_NODE_NAME = "formulaX";
32881
32885
  function resolveOptions(options = {}) {
32886
+ const locale = options.editor?.locale ?? DEFAULT_FORMULAX_LOCALE;
32882
32887
  return {
32883
32888
  name: options.name ?? FORMULAX_NODE_NAME,
32884
32889
  formulaClassName: options.formulaClassName ?? DEFAULT_FORMULA_CLASS,
@@ -32892,15 +32897,16 @@ var FormulaX = (() => {
32892
32897
  }),
32893
32898
  preload: options.preload ?? "idle",
32894
32899
  modal: {
32895
- title: options.modal?.title ?? "FormulaX Editor",
32896
- insertText: options.modal?.insertText ?? "Insert",
32897
- updateText: options.modal?.updateText ?? "Update",
32898
- cancelText: options.modal?.cancelText ?? "Cancel",
32900
+ title: options.modal?.title ?? getFormulaXEditorMessage("modal.title", locale),
32901
+ insertText: options.modal?.insertText ?? getFormulaXEditorMessage("modal.insert", locale),
32902
+ updateText: options.modal?.updateText ?? getFormulaXEditorMessage("modal.update", locale),
32903
+ cancelText: options.modal?.cancelText ?? getFormulaXEditorMessage("modal.cancel", locale),
32899
32904
  closeOnBackdrop: options.modal?.closeOnBackdrop ?? true
32900
32905
  },
32901
32906
  editor: {
32902
32907
  height: options.editor?.height ?? "100%",
32903
32908
  autofocus: options.editor?.autofocus ?? true,
32909
+ locale,
32904
32910
  assets: options.editor?.assets ?? {},
32905
32911
  render: {
32906
32912
  fontsize: options.editor?.render?.fontsize ?? 40