@formulaxjs/renderer-kity 0.2.0 → 0.3.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.
@@ -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,
@@ -5072,6 +5024,86 @@ var FormulaX = (() => {
5072
5024
  }
5073
5025
  });
5074
5026
 
5027
+ // ../kity-runtime/src/i18n.ts
5028
+ function normalizeFormulaXLocale(locale) {
5029
+ if (locale === "zh_CN") {
5030
+ return "zh_CN";
5031
+ }
5032
+ return DEFAULT_FORMULAX_LOCALE;
5033
+ }
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;
5054
+ var init_i18n = __esm({
5055
+ "../kity-runtime/src/i18n.ts"() {
5056
+ "use strict";
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
+ };
5104
+ }
5105
+ });
5106
+
5075
5107
  // ../kity-runtime/src/vendor/kity-formula/binary-expression.ts
5076
5108
  var BinaryExpressionModule, createBinaryExpressionClass;
5077
5109
  var init_binary_expression = __esm({
@@ -5957,14 +5989,11 @@ var FormulaX = (() => {
5957
5989
  count += 1;
5958
5990
  fontInfo.meta.src = resolveFontSource(this.fonts, this.resource, fontInfo.meta.src);
5959
5991
  this.createFontStyle(fontInfo);
5960
- preloadFont(this.doc, fontInfo).then(() => {
5961
- applyFonts(this.doc, fontInfo);
5962
- }).catch(() => void 0).finally(() => {
5963
- count -= 1;
5964
- if (count === 0) {
5965
- complete(this.doc, callback);
5966
- }
5967
- });
5992
+ applyFonts(this.doc, fontInfo);
5993
+ count -= 1;
5994
+ if (count === 0) {
5995
+ complete(this.doc, callback);
5996
+ }
5968
5997
  });
5969
5998
  },
5970
5999
  createFontStyle: function(fontInfo) {
@@ -5975,13 +6004,6 @@ var FormulaX = (() => {
5975
6004
  this.doc.head.appendChild(stylesheet);
5976
6005
  }
5977
6006
  });
5978
- function preloadFont(doc, fontInfo) {
5979
- const view = doc.defaultView ?? window;
5980
- if (view.fetch) {
5981
- return view.fetch(fontInfo.meta.src, { method: "GET" }).then(() => void 0);
5982
- }
5983
- return Promise.resolve();
5984
- }
5985
6007
  function resolveFontSource(fonts, resourceBase, originalSrc) {
5986
6008
  const directMatch = fonts[originalSrc];
5987
6009
  if (directMatch) {
@@ -6139,11 +6161,11 @@ var FormulaX = (() => {
6139
6161
  bg;
6140
6162
  exp;
6141
6163
  config;
6142
- constructor(kity26, exp, config2) {
6164
+ constructor(kity26, exp, config) {
6143
6165
  this.wrap = new kity26.Group();
6144
6166
  this.bg = new kity26.Rect(0, 0, 0, 0).fill("transparent");
6145
6167
  this.exp = exp;
6146
- this.config = config2;
6168
+ this.config = config;
6147
6169
  this.wrap.setAttr("data-type", "kf-exp-wrap");
6148
6170
  this.bg.setAttr("data-type", "kf-exp-wrap-bg");
6149
6171
  this.wrap.addShape(this.bg);
@@ -6172,14 +6194,14 @@ var FormulaX = (() => {
6172
6194
  static create(kity26, GTYPE2, FontManager, FontInstaller, FPaper, Output) {
6173
6195
  const Formula = kity26.createClass("Formula", {
6174
6196
  base: FPaper,
6175
- constructor: function(container, config2) {
6197
+ constructor: function(container, config) {
6176
6198
  if (this.__FORMULAX_PRESERVE_CALL_BASE__) {
6177
6199
  this.callBase(container);
6178
6200
  }
6179
6201
  FPaper.call(this, container);
6180
6202
  this.expressions = [];
6181
6203
  this.fontInstaller = new FontInstaller(this);
6182
- this.config = kity26.Utils.extend({}, DEFAULT_OPTIONS, config2);
6204
+ this.config = kity26.Utils.extend({}, DEFAULT_OPTIONS, config);
6183
6205
  this.initEnvironment();
6184
6206
  this.initInnerFont();
6185
6207
  },
@@ -13644,7 +13666,7 @@ var FormulaX = (() => {
13644
13666
  value: function() {
13645
13667
  const kf7 = window2.kf;
13646
13668
  const CONSTRUCT_MAPPING = {};
13647
- const CURSOR_CHAR3 = "\uF155";
13669
+ const CURSOR_CHAR4 = "\uF155";
13648
13670
  class Assembly {
13649
13671
  formula;
13650
13672
  constructor(formula) {
@@ -13681,7 +13703,7 @@ var FormulaX = (() => {
13681
13703
  if (tree.name.indexOf("text") === -1) {
13682
13704
  for (let i2 = 0, len = operand.length; i2 < len; i2 += 1) {
13683
13705
  currentOperand = operand[i2];
13684
- if (currentOperand === CURSOR_CHAR3) {
13706
+ if (currentOperand === CURSOR_CHAR4) {
13685
13707
  cursorLocation.push(i2);
13686
13708
  if (!Object.prototype.hasOwnProperty.call(selectInfo, "startOffset")) {
13687
13709
  selectInfo.startOffset = i2;
@@ -14975,8 +14997,8 @@ var FormulaX = (() => {
14975
14997
  }
14976
14998
  return serviceObject;
14977
14999
  }
14978
- var defaultOptions, components, kity2, kf, KFEditor, editor_default2;
14979
- var init_editor2 = __esm({
15000
+ var defaultOptions, components, kity2, kf, KFEditor, editor_default;
15001
+ var init_editor = __esm({
14980
15002
  "../kity-runtime/src/legacy/editor.ts"() {
14981
15003
  "use strict";
14982
15004
  init_legacy_utils();
@@ -15087,7 +15109,7 @@ var FormulaX = (() => {
15087
15109
  components[name] = component;
15088
15110
  }
15089
15111
  });
15090
- editor_default2 = KFEditor;
15112
+ editor_default = KFEditor;
15091
15113
  }
15092
15114
  });
15093
15115
 
@@ -15096,13 +15118,13 @@ var FormulaX = (() => {
15096
15118
  var init_factory = __esm({
15097
15119
  "../kity-runtime/src/legacy/factory.ts"() {
15098
15120
  "use strict";
15099
- init_editor2();
15121
+ init_editor();
15100
15122
  init_runtime_interop();
15101
15123
  EditorWrapper = class {
15102
15124
  callbacks = [];
15103
15125
  editor;
15104
15126
  constructor(container, options) {
15105
- this.editor = new editor_default2(container, options);
15127
+ this.editor = new editor_default(container, options);
15106
15128
  this.editor.ready(() => {
15107
15129
  this.trigger();
15108
15130
  });
@@ -16670,6 +16692,7 @@ var FormulaX = (() => {
16670
16692
  to: "\u2192",
16671
16693
  downarrow: "\u2193",
16672
16694
  leftrightarrow: "\u2194",
16695
+ updownarrow: "\u2195",
16673
16696
  therefore: "\u2234",
16674
16697
  because: "\u2235",
16675
16698
  "+": "+",
@@ -16786,7 +16809,7 @@ var FormulaX = (() => {
16786
16809
  Uparrow: "\u21D1",
16787
16810
  Downarrow: "\u21D3",
16788
16811
  Leftrightarrow: "\u21D4",
16789
- Updownarrow: "\u21F3",
16812
+ Updownarrow: "\u21D5",
16790
16813
  longleftarrow: "\u27F5",
16791
16814
  longrightarrow: "\u27F6",
16792
16815
  longleftrightarrow: "\u27F7",
@@ -16853,6 +16876,26 @@ var FormulaX = (() => {
16853
16876
  }
16854
16877
  Object.keys(list).forEach((key) => callback(list[key], key));
16855
16878
  }
16879
+ function translateToolbarText(value, locale) {
16880
+ return translateFormulaXText("toolbar", value, locale);
16881
+ }
16882
+ function localizeToolbarConfig(value, locale) {
16883
+ if (Array.isArray(value)) {
16884
+ return value.map((item) => localizeToolbarConfig(item, locale));
16885
+ }
16886
+ if (!value || typeof value !== "object") {
16887
+ return value;
16888
+ }
16889
+ const result = {};
16890
+ for (const [key, currentValue] of Object.entries(value)) {
16891
+ if ((key === "label" || key === "title") && typeof currentValue === "string") {
16892
+ result[key] = translateToolbarText(currentValue, locale);
16893
+ continue;
16894
+ }
16895
+ result[key] = localizeToolbarConfig(currentValue, locale);
16896
+ }
16897
+ return result;
16898
+ }
16856
16899
  function getUnicodeContents(keySet) {
16857
16900
  let result = [];
16858
16901
  each(keySet, function(key) {
@@ -16872,7 +16915,13 @@ var FormulaX = (() => {
16872
16915
  });
16873
16916
  return result;
16874
16917
  }
16875
- var UI_ELE_TYPE, BOX_TYPE2, OTHER_POSITION, config, toolbar_config_default;
16918
+ function createToolbarConfig(locale = DEFAULT_FORMULAX_LOCALE) {
16919
+ return localizeToolbarConfig(
16920
+ baseToolbarConfig,
16921
+ normalizeFormulaXLocale(locale)
16922
+ );
16923
+ }
16924
+ var UI_ELE_TYPE, BOX_TYPE2, OTHER_POSITION, baseToolbarConfig, toolbar_config_default;
16876
16925
  var init_toolbar_config = __esm({
16877
16926
  "../kity-runtime/src/legacy/toolbar-config.ts"() {
16878
16927
  "use strict";
@@ -16881,10 +16930,11 @@ var FormulaX = (() => {
16881
16930
  init_other_position();
16882
16931
  init_toolbar_assets();
16883
16932
  init_formula_symbols();
16933
+ init_i18n();
16884
16934
  UI_ELE_TYPE = legacyEleType;
16885
16935
  BOX_TYPE2 = legacyBoxType;
16886
16936
  OTHER_POSITION = legacyOtherPosition;
16887
- config = [{
16937
+ baseToolbarConfig = [{
16888
16938
  type: UI_ELE_TYPE.DRAPDOWN_BOX,
16889
16939
  options: {
16890
16940
  button: {
@@ -17290,7 +17340,7 @@ var FormulaX = (() => {
17290
17340
  }];
17291
17341
  (function() {
17292
17342
  let tmp = [], otherImageSrc = resolveToolbarAssetPath("other.png"), currentConf = [];
17293
- each(config, function(conf) {
17343
+ each(baseToolbarConfig, function(conf) {
17294
17344
  if (conf.type === UI_ELE_TYPE.DELIMITER) {
17295
17345
  return;
17296
17346
  }
@@ -17362,7 +17412,7 @@ var FormulaX = (() => {
17362
17412
  "aleph",
17363
17413
  "beth",
17364
17414
  "blacksquare"
17365
- ], configList = config[2].options.box.group[0].items;
17415
+ ], configList = baseToolbarConfig[2].options.box.group[0].items;
17366
17416
  configList.push({
17367
17417
  title: "\u57FA\u7840\u6570\u5B66",
17368
17418
  content: getUnicodeContents(list)
@@ -17378,7 +17428,7 @@ var FormulaX = (() => {
17378
17428
  }, {
17379
17429
  title: "\u53D8\u4F53",
17380
17430
  values: ["digamma", "varepsilon", "varkappa", "varphi", "varpi", "varrho", "varsigma", "vartheta"]
17381
- }], greekConfigList = config[2].options.box.group[1].items;
17431
+ }], greekConfigList = baseToolbarConfig[2].options.box.group[1].items;
17382
17432
  greekConfigList.push({
17383
17433
  title: greekList[0].title,
17384
17434
  content: getUnicodeContents(greekList[0].values)
@@ -17427,7 +17477,7 @@ var FormulaX = (() => {
17427
17477
  "nVDash",
17428
17478
  "nexists"
17429
17479
  ]
17430
- }], greekConfigList = config[2].options.box.group[2].items;
17480
+ }], greekConfigList = baseToolbarConfig[2].options.box.group[2].items;
17431
17481
  greekConfigList.push({
17432
17482
  title: greekList[0].title,
17433
17483
  content: getUnicodeContents(greekList[0].values)
@@ -17453,7 +17503,7 @@ var FormulaX = (() => {
17453
17503
  "Game",
17454
17504
  "Im",
17455
17505
  "Re"
17456
- ], configList = config[2].options.box.group[3].items;
17506
+ ], configList = baseToolbarConfig[2].options.box.group[3].items;
17457
17507
  configList.push({
17458
17508
  title: "\u5B57\u6BCD\u7C7B\u7B26\u53F7",
17459
17509
  content: getUnicodeContents(list)
@@ -17521,7 +17571,7 @@ var FormulaX = (() => {
17521
17571
  "twoheadleftarrow",
17522
17572
  "twoheadrightarrow",
17523
17573
  "rightsquigarrow"
17524
- ], configList = config[2].options.box.group[4].items;
17574
+ ], configList = baseToolbarConfig[2].options.box.group[4].items;
17525
17575
  configList.push({
17526
17576
  title: "\u7BAD\u5934",
17527
17577
  content: getUnicodeContents(list)
@@ -17700,7 +17750,7 @@ var FormulaX = (() => {
17700
17750
  "y",
17701
17751
  "z"
17702
17752
  ]
17703
- }], configList = config[2].options.box.group[5].items;
17753
+ }], configList = baseToolbarConfig[2].options.box.group[5].items;
17704
17754
  each(list[0].values, function(item, index) {
17705
17755
  list[0].values[index] = "mathcal{" + item + "}";
17706
17756
  });
@@ -17730,7 +17780,7 @@ var FormulaX = (() => {
17730
17780
  content: getUnicodeContents(list[3].values)
17731
17781
  });
17732
17782
  })();
17733
- toolbar_config_default = config;
17783
+ toolbar_config_default = createToolbarConfig;
17734
17784
  }
17735
17785
  });
17736
17786
 
@@ -17773,6 +17823,7 @@ var FormulaX = (() => {
17773
17823
  init_toolbar();
17774
17824
  init_scrollbar();
17775
17825
  init_toolbar_config();
17826
+ init_i18n();
17776
17827
  $$8 = createLegacyUiUtils();
17777
17828
  VIEW_STATE = legacyUiDef.VIEW_STATE;
17778
17829
  DEFAULT_EDIT_AREA_HEIGHT = 100;
@@ -17803,7 +17854,8 @@ var FormulaX = (() => {
17803
17854
  this.initScrollEvent();
17804
17855
  },
17805
17856
  initComponents() {
17806
- this.components.toolbar = new toolbar_default(this, this.kfEditor, toolbar_config_default);
17857
+ const toolbarConfig = toolbar_config_default(normalizeFormulaXLocale(this.options.locale));
17858
+ this.components.toolbar = new toolbar_default(this, this.kfEditor, toolbarConfig);
17807
17859
  this.components.scrollbar = new scrollbar_default(this, this.kfEditor);
17808
17860
  },
17809
17861
  updateContainerSize(container, toolbar, editArea) {
@@ -18112,6 +18164,9 @@ var FormulaX = (() => {
18112
18164
  operand: []
18113
18165
  };
18114
18166
  }
18167
+ function getRootPlaceholderText() {
18168
+ return legacySysconf.rootPlaceholder.content;
18169
+ }
18115
18170
  function processRootGroup(parser, tree) {
18116
18171
  if (!parser.isResetId) {
18117
18172
  tree.attr["data-type"] = legacyGroupType.VIRTUAL;
@@ -18159,7 +18214,7 @@ var FormulaX = (() => {
18159
18214
  if (isRoot) {
18160
18215
  processRootGroup(parser, tree);
18161
18216
  } else if (parentTree?.attr?.["data-root"] && tree.name === "placeholder" && onlyPlaceholder(parentTree.operand)) {
18162
- tree.attr.label = ROOT_P_TEXT;
18217
+ tree.attr.label = getRootPlaceholderText();
18163
18218
  }
18164
18219
  for (let i2 = 0; i2 < tree.operand.length; i2 += 1) {
18165
18220
  const currentOperand = tree.operand[i2];
@@ -18171,7 +18226,7 @@ var FormulaX = (() => {
18171
18226
  }
18172
18227
  return tree;
18173
18228
  }
18174
- 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;
18175
18230
  var init_parser = __esm({
18176
18231
  "../kity-runtime/src/legacy/parser.ts"() {
18177
18232
  "use strict";
@@ -18182,7 +18237,6 @@ var FormulaX = (() => {
18182
18237
  init_kf_ext_extension();
18183
18238
  init_vgroup_def();
18184
18239
  CURSOR_CHAR = legacySysconf.cursorCharacter;
18185
- ROOT_P_TEXT = legacySysconf.rootPlaceholder.content;
18186
18240
  COMBINATION_NAME = "combination";
18187
18241
  PID_PREFIX = "_kf_editor_";
18188
18242
  pidSeed = 0;
@@ -19070,6 +19124,21 @@ var FormulaX = (() => {
19070
19124
  });
19071
19125
 
19072
19126
  // ../kity-runtime/src/legacy/syntax.ts
19127
+ function clampOffset(offset, maxOffset) {
19128
+ return Math.max(0, Math.min(offset, maxOffset));
19129
+ }
19130
+ function normalizeCursorRecord(objTree, cursor) {
19131
+ const fallbackGroupId = objTree.mapping.root.strGroup.attr.id;
19132
+ const targetGroupId = cursor.groupId && objTree.mapping[cursor.groupId] ? cursor.groupId : fallbackGroupId;
19133
+ const operandCount = objTree.mapping[targetGroupId].strGroup.operand.length;
19134
+ const startOffset = clampOffset(cursor.startOffset, operandCount);
19135
+ const endOffset = clampOffset(cursor.endOffset, operandCount);
19136
+ return {
19137
+ groupId: targetGroupId,
19138
+ startOffset: Math.min(startOffset, endOffset),
19139
+ endOffset: Math.max(startOffset, endOffset)
19140
+ };
19141
+ }
19073
19142
  var CURSOR_CHAR2, kity19, SyntaxComponent, syntax_default;
19074
19143
  var init_syntax = __esm({
19075
19144
  "../kity-runtime/src/legacy/syntax.ts"() {
@@ -19130,10 +19199,14 @@ var FormulaX = (() => {
19130
19199
  },
19131
19200
  updateObjTree(objTree) {
19132
19201
  const selectInfo = objTree.select;
19202
+ this.objTree = objTree;
19133
19203
  if (selectInfo?.groupId) {
19134
19204
  this.updateCursor(selectInfo.groupId, selectInfo.startOffset, selectInfo.endOffset);
19205
+ return;
19206
+ }
19207
+ if (this.record.cursor.groupId !== null) {
19208
+ this.record.cursor = normalizeCursorRecord(objTree, this.record.cursor);
19135
19209
  }
19136
- this.objTree = objTree;
19137
19210
  },
19138
19211
  hasCursorInfo() {
19139
19212
  return this.record.cursor.groupId !== null;
@@ -19179,7 +19252,8 @@ var FormulaX = (() => {
19179
19252
  return this.objTree;
19180
19253
  },
19181
19254
  getGroupObject(id) {
19182
- return this.objTree.mapping[id].objGroup || null;
19255
+ const groupInfo = this.objTree.mapping[id];
19256
+ return groupInfo ? groupInfo.objGroup : null;
19183
19257
  },
19184
19258
  getCursorRecord() {
19185
19259
  return kity19.Utils.extend({}, this.record.cursor);
@@ -19255,7 +19329,7 @@ var FormulaX = (() => {
19255
19329
  return this.hasRootplaceholder();
19256
19330
  },
19257
19331
  serialization() {
19258
- const cursor = this.record.cursor;
19332
+ const cursor = normalizeCursorRecord(this.objTree, this.record.cursor);
19259
19333
  const objGroup = this.objTree.mapping[cursor.groupId];
19260
19334
  const curStrGroup = objGroup.strGroup;
19261
19335
  let strStartIndex = Math.min(cursor.endOffset, cursor.startOffset);
@@ -19291,11 +19365,12 @@ var FormulaX = (() => {
19291
19365
  endOffset = startOffset;
19292
19366
  startOffset = tmp;
19293
19367
  }
19294
- this.record.cursor = {
19368
+ const nextCursor = {
19295
19369
  groupId,
19296
19370
  startOffset,
19297
19371
  endOffset
19298
19372
  };
19373
+ this.record.cursor = this.objTree ? normalizeCursorRecord(this.objTree, nextCursor) : nextCursor;
19299
19374
  },
19300
19375
  leftMove() {
19301
19376
  this.components.move.leftMove();
@@ -19336,12 +19411,20 @@ var FormulaX = (() => {
19336
19411
  });
19337
19412
 
19338
19413
  // ../kity-runtime/src/legacy/input.ts
19339
- var KEY_CODE, kity20, InputComponent, input_default;
19414
+ function insertCursorMarkers(value, selectionStart, selectionEnd) {
19415
+ const normalizedStart = Math.max(0, Math.min(selectionStart ?? value.length, value.length));
19416
+ const normalizedEnd = Math.max(0, Math.min(selectionEnd ?? normalizedStart, value.length));
19417
+ const rangeStart = Math.min(normalizedStart, normalizedEnd);
19418
+ const rangeEnd = Math.max(normalizedStart, normalizedEnd);
19419
+ return value.slice(0, rangeStart) + CURSOR_CHAR3 + value.slice(rangeStart, rangeEnd) + CURSOR_CHAR3 + value.slice(rangeEnd);
19420
+ }
19421
+ var KEY_CODE, CURSOR_CHAR3, kity20, InputComponent, input_default;
19340
19422
  var init_input = __esm({
19341
19423
  "../kity-runtime/src/legacy/input.ts"() {
19342
19424
  "use strict";
19343
19425
  init_legacy_utils();
19344
19426
  init_legacy_input_filter();
19427
+ init_legacy_sysconf();
19345
19428
  init_runtime_interop();
19346
19429
  KEY_CODE = {
19347
19430
  LEFT: 37,
@@ -19349,6 +19432,7 @@ var FormulaX = (() => {
19349
19432
  DELETE: 8,
19350
19433
  INPUT: 229
19351
19434
  };
19435
+ CURSOR_CHAR3 = legacySysconf.cursorCharacter;
19352
19436
  kity20 = getLegacyKity();
19353
19437
  InputComponent = kity20.createClass("InputComponent", {
19354
19438
  constructor(parentComponent, kfEditor) {
@@ -19521,7 +19605,12 @@ var FormulaX = (() => {
19521
19605
  return `${e.shiftKey ? "s+" : ""}${e.keyCode}`;
19522
19606
  },
19523
19607
  processingInput() {
19524
- this.restruct(this.inputBox.value);
19608
+ const latexWithCursor = insertCursorMarkers(
19609
+ this.inputBox.value,
19610
+ this.inputBox.selectionStart,
19611
+ this.inputBox.selectionEnd
19612
+ );
19613
+ this.restruct(latexWithCursor);
19525
19614
  this.kfEditor.requestService("ui.update.canvas.view");
19526
19615
  },
19527
19616
  restruct(latexStr) {
@@ -20027,26 +20116,26 @@ var FormulaX = (() => {
20027
20116
  var start_exports = {};
20028
20117
  __export(start_exports, {
20029
20118
  Factory: () => factory_default,
20030
- KFEditor: () => editor_default2,
20119
+ KFEditor: () => editor_default,
20031
20120
  default: () => start_default,
20032
20121
  installKityEditorStart: () => installKityEditorStart
20033
20122
  });
20034
20123
  function installKityEditorStart(target = window) {
20035
20124
  const runtimeTarget = target;
20036
20125
  if (!installed3) {
20037
- editor_default2.registerComponents("ui", ui_default);
20038
- editor_default2.registerComponents("parser", parser_default);
20039
- editor_default2.registerComponents("render", render_default);
20040
- editor_default2.registerComponents("position", position_default);
20041
- editor_default2.registerComponents("syntax", syntax_default);
20042
- editor_default2.registerComponents("control", controller_default);
20043
- 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);
20044
20133
  installed3 = true;
20045
20134
  }
20046
20135
  runtimeTarget.kf = runtimeTarget.kf ?? {};
20047
20136
  runtimeTarget.kf.EditorFactory = factory_default;
20048
20137
  return {
20049
- KFEditor: editor_default2,
20138
+ KFEditor: editor_default,
20050
20139
  Factory: factory_default
20051
20140
  };
20052
20141
  }
@@ -20054,7 +20143,7 @@ var FormulaX = (() => {
20054
20143
  var init_start = __esm({
20055
20144
  "../kity-runtime/src/boot/start.ts"() {
20056
20145
  "use strict";
20057
- init_editor2();
20146
+ init_editor();
20058
20147
  init_factory();
20059
20148
  init_ui();
20060
20149
  init_parser();
@@ -20087,11 +20176,16 @@ var FormulaX = (() => {
20087
20176
  fontSize: input.fontSize,
20088
20177
  displayMode: input.displayMode,
20089
20178
  className: input.className,
20090
- assetsVersion: input.assetsVersion
20179
+ assetCacheKey: input.assetCacheKey
20091
20180
  });
20092
20181
  }
20093
20182
 
20094
20183
  // ../renderer/src/svg.ts
20184
+ var SIMPLE_INLINE_HEIGHT_EM = 1.25;
20185
+ var BASE_FORMULA_HEIGHT = 40.5;
20186
+ var SIMPLE_FORMULA_HEIGHT_RATIO = 1.05;
20187
+ var MAX_INLINE_HEIGHT_EM = 1.65;
20188
+ var COMPLEX_FORMULA_SCALE = 0.825;
20095
20189
  function readRenderedFormulaSvgBox(svg2) {
20096
20190
  return getInlineSvgContent(svg2)?.box ?? readSvgBox(svg2);
20097
20191
  }
@@ -20266,6 +20360,7 @@ var FormulaX = (() => {
20266
20360
  "width",
20267
20361
  "height",
20268
20362
  "viewBox",
20363
+ "font-size",
20269
20364
  "class",
20270
20365
  "focusable",
20271
20366
  "aria-hidden",
@@ -20277,13 +20372,24 @@ var FormulaX = (() => {
20277
20372
  target.setAttribute(attribute.name, attribute.value);
20278
20373
  });
20279
20374
  }
20375
+ function calculateInlineHeightEm(height2) {
20376
+ const heightRatio = height2 / BASE_FORMULA_HEIGHT;
20377
+ if (!Number.isFinite(heightRatio) || heightRatio <= SIMPLE_FORMULA_HEIGHT_RATIO) {
20378
+ return SIMPLE_INLINE_HEIGHT_EM;
20379
+ }
20380
+ return Math.min(
20381
+ MAX_INLINE_HEIGHT_EM,
20382
+ SIMPLE_INLINE_HEIGHT_EM * Math.pow(heightRatio, COMPLEX_FORMULA_SCALE)
20383
+ );
20384
+ }
20280
20385
  function sizeSvgForInlineDisplay(clone, source, viewport) {
20386
+ clone.removeAttribute("font-size");
20281
20387
  const viewBox = clone.viewBox?.baseVal;
20282
20388
  const rect = source.getBoundingClientRect();
20283
20389
  const width2 = viewport?.width || viewBox?.width || rect.width || Number(clone.getAttribute("width")) || 1;
20284
20390
  const height2 = viewport?.height || viewBox?.height || rect.height || Number(clone.getAttribute("height")) || 1;
20285
20391
  const ratio = Math.max(0.1, width2 / Math.max(1, height2));
20286
- const inlineHeightEm = 0.875;
20392
+ const inlineHeightEm = calculateInlineHeightEm(height2);
20287
20393
  const inlineWidthEm = Math.min(40, Math.max(0.75, ratio * inlineHeightEm));
20288
20394
  clone.setAttribute("width", roundLength(width2));
20289
20395
  clone.setAttribute("height", roundLength(height2));
@@ -20291,8 +20397,9 @@ var FormulaX = (() => {
20291
20397
  "style",
20292
20398
  mergeInlineStyles(
20293
20399
  clone.getAttribute("style"),
20400
+ "font-size:inherit",
20294
20401
  `width:${roundLength(inlineWidthEm)}em`,
20295
- `height:${inlineHeightEm}em`
20402
+ `height:${roundLength(inlineHeightEm)}em`
20296
20403
  )
20297
20404
  );
20298
20405
  }
@@ -23820,6 +23927,7 @@ var FormulaX = (() => {
23820
23927
 
23821
23928
  // ../kity-runtime/src/create-editor.ts
23822
23929
  init_toolbar_assets();
23930
+ init_i18n();
23823
23931
  var DEFAULT_LATEX = "x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}";
23824
23932
  var DEFAULT_EDITOR_HEIGHT = "auto";
23825
23933
  var KITY_STYLE_ID = "formulax-kity-editor-styles";
@@ -23970,8 +24078,10 @@ var FormulaX = (() => {
23970
24078
  const createEditorStart = markFormulaXPerf("fx:create-kity-editor:total");
23971
24079
  const fontsize = options.render?.fontsize ?? 40;
23972
24080
  const editorHeight = normalizeCssSize(options.height, DEFAULT_EDITOR_HEIGHT);
24081
+ const locale = normalizeFormulaXLocale(options.locale ?? DEFAULT_FORMULAX_LOCALE);
23973
24082
  const assets = resolveEditorAssets(options.assets);
23974
24083
  try {
24084
+ legacySysconf.rootPlaceholder.content = getFormulaXRuntimeMessage("editor.placeholder.root", locale);
23975
24085
  const stylesheetInserted = ensureKityStylesheet(document, assets.styles.editor);
23976
24086
  if (stylesheetInserted) {
23977
24087
  const stylesheetInsertedMark = markFormulaXPerf("fx:kity-css:link-inserted");
@@ -23998,6 +24108,9 @@ var FormulaX = (() => {
23998
24108
  render: {
23999
24109
  fontsize
24000
24110
  },
24111
+ ui: {
24112
+ locale
24113
+ },
24001
24114
  resource: {
24002
24115
  path: "",
24003
24116
  fonts: assets.fonts
@@ -24080,6 +24193,7 @@ var FormulaX = (() => {
24080
24193
 
24081
24194
  // ../kity-runtime/src/index.ts
24082
24195
  init_dom_utils();
24196
+ init_i18n();
24083
24197
  init_legacy_box_type();
24084
24198
  init_legacy_component();
24085
24199
  init_legacy_ele_type();
@@ -24181,7 +24295,7 @@ var FormulaX = (() => {
24181
24295
  }
24182
24296
  function renderLatexToSvgMarkup(latex, options = {}) {
24183
24297
  const normalizedLatex = latex.trim();
24184
- const shouldUseCache = options.cache !== false && !(hasCustomAssetOverrides(options.assets) && !options.assetsVersion);
24298
+ const shouldUseCache = options.cache !== false && !(hasCustomAssetOverrides(options.assets) && !options.assetCacheKey);
24185
24299
  if (!normalizedLatex) {
24186
24300
  return Promise.resolve({
24187
24301
  engine: "kity",
@@ -24197,7 +24311,7 @@ var FormulaX = (() => {
24197
24311
  fontSize: options.fontSize,
24198
24312
  displayMode: options.displayMode,
24199
24313
  className: options.className,
24200
- assetsVersion: options.assetsVersion
24314
+ assetCacheKey: options.assetCacheKey
24201
24315
  });
24202
24316
  if (shouldUseCache) {
24203
24317
  const cached = renderCache.get(cacheKey);