@formulaxjs/kity-runtime 0.2.0 → 0.4.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.
@@ -21,6 +21,105 @@ var FormulaX = (() => {
21
21
  };
22
22
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
23
 
24
+ // public/assets/images/toolbar/btn.png
25
+ var btn_default;
26
+ var init_btn = __esm({
27
+ "public/assets/images/toolbar/btn.png"() {
28
+ btn_default = "./btn-5DANP6JY.png";
29
+ }
30
+ });
31
+
32
+ // public/assets/images/toolbar/other.png
33
+ var other_default;
34
+ var init_other = __esm({
35
+ "public/assets/images/toolbar/other.png"() {
36
+ other_default = "./other-OMWJFGL5.png";
37
+ }
38
+ });
39
+
40
+ // public/assets/styles/editor.css?url
41
+ var editor_default;
42
+ var init_editor = __esm({
43
+ "public/assets/styles/editor.css?url"() {
44
+ editor_default = "./editor-JT5KLVXX.css?url";
45
+ }
46
+ });
47
+
48
+ // public/resource/KF_AMS_BB.woff
49
+ var KF_AMS_BB_default;
50
+ var init_KF_AMS_BB = __esm({
51
+ "public/resource/KF_AMS_BB.woff"() {
52
+ KF_AMS_BB_default = "./KF_AMS_BB-5QF7FUSO.woff";
53
+ }
54
+ });
55
+
56
+ // public/resource/KF_AMS_CAL.woff
57
+ var KF_AMS_CAL_default;
58
+ var init_KF_AMS_CAL = __esm({
59
+ "public/resource/KF_AMS_CAL.woff"() {
60
+ KF_AMS_CAL_default = "./KF_AMS_CAL-NXRNLAZN.woff";
61
+ }
62
+ });
63
+
64
+ // public/resource/KF_AMS_FRAK.woff
65
+ var KF_AMS_FRAK_default;
66
+ var init_KF_AMS_FRAK = __esm({
67
+ "public/resource/KF_AMS_FRAK.woff"() {
68
+ KF_AMS_FRAK_default = "./KF_AMS_FRAK-CO33WWN4.woff";
69
+ }
70
+ });
71
+
72
+ // public/resource/KF_AMS_MAIN.woff
73
+ var KF_AMS_MAIN_default;
74
+ var init_KF_AMS_MAIN = __esm({
75
+ "public/resource/KF_AMS_MAIN.woff"() {
76
+ KF_AMS_MAIN_default = "./KF_AMS_MAIN-25QJVAWY.woff";
77
+ }
78
+ });
79
+
80
+ // public/resource/KF_AMS_ROMAN.woff
81
+ var KF_AMS_ROMAN_default;
82
+ var init_KF_AMS_ROMAN = __esm({
83
+ "public/resource/KF_AMS_ROMAN.woff"() {
84
+ KF_AMS_ROMAN_default = "./KF_AMS_ROMAN-243BR7HH.woff";
85
+ }
86
+ });
87
+
88
+ // src/asset-manifest.ts
89
+ var kityFontAssets, kityToolbarAssets, kityStyleAssets, kityAssetManifest;
90
+ var init_asset_manifest = __esm({
91
+ "src/asset-manifest.ts"() {
92
+ "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();
101
+ 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
107
+ };
108
+ kityToolbarAssets = {
109
+ btn: btn_default,
110
+ other: other_default
111
+ };
112
+ kityStyleAssets = {
113
+ editor: editor_default
114
+ };
115
+ kityAssetManifest = {
116
+ fonts: kityFontAssets,
117
+ toolbar: kityToolbarAssets,
118
+ styles: kityStyleAssets
119
+ };
120
+ }
121
+ });
122
+
24
123
  // src/vendor/legacy-box-type.ts
25
124
  var legacyBoxType;
26
125
  var init_legacy_box_type = __esm({
@@ -4919,28 +5018,30 @@ var FormulaX = (() => {
4919
5018
 
4920
5019
  // src/vendor/legacy-ui-utils.ts
4921
5020
  function createLegacyUiUtils() {
4922
- return {
4923
- ele: createElement,
4924
- getRectBox,
4925
- on(target, type, fn) {
4926
- addEvent(target, type, fn);
4927
- return this;
4928
- },
4929
- delegate(target, selector, type, fn) {
4930
- delegateEvent(target, selector, type, fn);
4931
- return this;
4932
- },
4933
- publish(topic, ...args) {
4934
- publish(topic, ...args);
4935
- },
4936
- subscribe,
4937
- getClassList
4938
- };
5021
+ return legacyUiUtils;
4939
5022
  }
5023
+ var legacyUiUtils;
4940
5024
  var init_legacy_ui_utils = __esm({
4941
5025
  "src/vendor/legacy-ui-utils.ts"() {
4942
5026
  "use strict";
4943
5027
  init_dom_utils();
5028
+ legacyUiUtils = {
5029
+ ele: createElement,
5030
+ getRectBox,
5031
+ on(target, type, fn) {
5032
+ addEvent(target, type, fn);
5033
+ return this;
5034
+ },
5035
+ delegate(target, selector, type, fn) {
5036
+ delegateEvent(target, selector, type, fn);
5037
+ return this;
5038
+ },
5039
+ publish(topic, ...args) {
5040
+ publish(topic, ...args);
5041
+ },
5042
+ subscribe,
5043
+ getClassList
5044
+ };
4944
5045
  }
4945
5046
  });
4946
5047
 
@@ -4963,7 +5064,27 @@ var FormulaX = (() => {
4963
5064
  var init_toolbar_assets = __esm({
4964
5065
  "src/toolbar-assets.ts"() {
4965
5066
  "use strict";
4966
- toolbarAssetFileMap = {};
5067
+ init_asset_manifest();
5068
+ toolbarAssetFileMap = {
5069
+ "btn.png": kityToolbarAssets.btn,
5070
+ "other.png": kityToolbarAssets.other
5071
+ };
5072
+ }
5073
+ });
5074
+
5075
+ // src/i18n.ts
5076
+ function normalizeFormulaXLocale(locale) {
5077
+ if (locale === "zh_CN") {
5078
+ return "zh_CN";
5079
+ }
5080
+ return DEFAULT_FORMULAX_LOCALE;
5081
+ }
5082
+ var FORMULAX_LOCALES, DEFAULT_FORMULAX_LOCALE;
5083
+ var init_i18n = __esm({
5084
+ "src/i18n.ts"() {
5085
+ "use strict";
5086
+ FORMULAX_LOCALES = ["en_US", "zh_CN"];
5087
+ DEFAULT_FORMULAX_LOCALE = "en_US";
4967
5088
  }
4968
5089
  });
4969
5090
 
@@ -5852,14 +5973,11 @@ var FormulaX = (() => {
5852
5973
  count += 1;
5853
5974
  fontInfo.meta.src = resolveFontSource(this.fonts, this.resource, fontInfo.meta.src);
5854
5975
  this.createFontStyle(fontInfo);
5855
- preloadFont(this.doc, fontInfo).then(() => {
5856
- applyFonts(this.doc, fontInfo);
5857
- }).catch(() => void 0).finally(() => {
5858
- count -= 1;
5859
- if (count === 0) {
5860
- complete(this.doc, callback);
5861
- }
5862
- });
5976
+ applyFonts(this.doc, fontInfo);
5977
+ count -= 1;
5978
+ if (count === 0) {
5979
+ complete(this.doc, callback);
5980
+ }
5863
5981
  });
5864
5982
  },
5865
5983
  createFontStyle: function(fontInfo) {
@@ -5870,13 +5988,6 @@ var FormulaX = (() => {
5870
5988
  this.doc.head.appendChild(stylesheet);
5871
5989
  }
5872
5990
  });
5873
- function preloadFont(doc, fontInfo) {
5874
- const view = doc.defaultView ?? window;
5875
- if (view.fetch) {
5876
- return view.fetch(fontInfo.meta.src, { method: "GET" }).then(() => void 0);
5877
- }
5878
- return Promise.resolve();
5879
- }
5880
5991
  function resolveFontSource(fonts, resourceBase, originalSrc) {
5881
5992
  const directMatch = fonts[originalSrc];
5882
5993
  if (directMatch) {
@@ -6034,11 +6145,11 @@ var FormulaX = (() => {
6034
6145
  bg;
6035
6146
  exp;
6036
6147
  config;
6037
- constructor(kity26, exp, config2) {
6148
+ constructor(kity26, exp, config) {
6038
6149
  this.wrap = new kity26.Group();
6039
6150
  this.bg = new kity26.Rect(0, 0, 0, 0).fill("transparent");
6040
6151
  this.exp = exp;
6041
- this.config = config2;
6152
+ this.config = config;
6042
6153
  this.wrap.setAttr("data-type", "kf-exp-wrap");
6043
6154
  this.bg.setAttr("data-type", "kf-exp-wrap-bg");
6044
6155
  this.wrap.addShape(this.bg);
@@ -6067,14 +6178,14 @@ var FormulaX = (() => {
6067
6178
  static create(kity26, GTYPE2, FontManager, FontInstaller, FPaper, Output) {
6068
6179
  const Formula = kity26.createClass("Formula", {
6069
6180
  base: FPaper,
6070
- constructor: function(container, config2) {
6181
+ constructor: function(container, config) {
6071
6182
  if (this.__FORMULAX_PRESERVE_CALL_BASE__) {
6072
6183
  this.callBase(container);
6073
6184
  }
6074
6185
  FPaper.call(this, container);
6075
6186
  this.expressions = [];
6076
6187
  this.fontInstaller = new FontInstaller(this);
6077
- this.config = kity26.Utils.extend({}, DEFAULT_OPTIONS, config2);
6188
+ this.config = kity26.Utils.extend({}, DEFAULT_OPTIONS, config);
6078
6189
  this.initEnvironment();
6079
6190
  this.initInnerFont();
6080
6191
  },
@@ -13539,7 +13650,7 @@ var FormulaX = (() => {
13539
13650
  value: function() {
13540
13651
  const kf7 = window2.kf;
13541
13652
  const CONSTRUCT_MAPPING = {};
13542
- const CURSOR_CHAR3 = "\uF155";
13653
+ const CURSOR_CHAR4 = "\uF155";
13543
13654
  class Assembly {
13544
13655
  formula;
13545
13656
  constructor(formula) {
@@ -13576,7 +13687,7 @@ var FormulaX = (() => {
13576
13687
  if (tree.name.indexOf("text") === -1) {
13577
13688
  for (let i2 = 0, len = operand.length; i2 < len; i2 += 1) {
13578
13689
  currentOperand = operand[i2];
13579
- if (currentOperand === CURSOR_CHAR3) {
13690
+ if (currentOperand === CURSOR_CHAR4) {
13580
13691
  cursorLocation.push(i2);
13581
13692
  if (!Object.prototype.hasOwnProperty.call(selectInfo, "startOffset")) {
13582
13693
  selectInfo.startOffset = i2;
@@ -14871,7 +14982,7 @@ var FormulaX = (() => {
14871
14982
  return serviceObject;
14872
14983
  }
14873
14984
  var defaultOptions, components, kity2, kf, KFEditor, editor_default2;
14874
- var init_editor = __esm({
14985
+ var init_editor2 = __esm({
14875
14986
  "src/legacy/editor.ts"() {
14876
14987
  "use strict";
14877
14988
  init_legacy_utils();
@@ -14991,7 +15102,7 @@ var FormulaX = (() => {
14991
15102
  var init_factory = __esm({
14992
15103
  "src/legacy/factory.ts"() {
14993
15104
  "use strict";
14994
- init_editor();
15105
+ init_editor2();
14995
15106
  init_runtime_interop();
14996
15107
  EditorWrapper = class {
14997
15108
  callbacks = [];
@@ -16748,6 +16859,35 @@ var FormulaX = (() => {
16748
16859
  }
16749
16860
  Object.keys(list).forEach((key) => callback(list[key], key));
16750
16861
  }
16862
+ function translateToolbarText(value, locale) {
16863
+ if (locale === "zh_CN") {
16864
+ return value;
16865
+ }
16866
+ const normalizedValue = value.replace(/<br\s*\/?>/gi, "").trim();
16867
+ const translatedValue = zhCnToEnUsText.get(normalizedValue);
16868
+ if (!translatedValue) {
16869
+ return value;
16870
+ }
16871
+ const lineBreakMatch = value.match(/<br\s*\/?>/i);
16872
+ return lineBreakMatch ? `${translatedValue}${lineBreakMatch[0]}` : translatedValue;
16873
+ }
16874
+ function localizeToolbarConfig(value, locale) {
16875
+ if (Array.isArray(value)) {
16876
+ return value.map((item) => localizeToolbarConfig(item, locale));
16877
+ }
16878
+ if (!value || typeof value !== "object") {
16879
+ return value;
16880
+ }
16881
+ const result = {};
16882
+ for (const [key, currentValue] of Object.entries(value)) {
16883
+ if ((key === "label" || key === "title") && typeof currentValue === "string") {
16884
+ result[key] = translateToolbarText(currentValue, locale);
16885
+ continue;
16886
+ }
16887
+ result[key] = localizeToolbarConfig(currentValue, locale);
16888
+ }
16889
+ return result;
16890
+ }
16751
16891
  function getUnicodeContents(keySet) {
16752
16892
  let result = [];
16753
16893
  each(keySet, function(key) {
@@ -16767,7 +16907,13 @@ var FormulaX = (() => {
16767
16907
  });
16768
16908
  return result;
16769
16909
  }
16770
- var UI_ELE_TYPE, BOX_TYPE2, OTHER_POSITION, config, toolbar_config_default;
16910
+ function createToolbarConfig(locale = DEFAULT_FORMULAX_LOCALE) {
16911
+ return localizeToolbarConfig(
16912
+ baseToolbarConfig,
16913
+ normalizeFormulaXLocale(locale)
16914
+ );
16915
+ }
16916
+ var UI_ELE_TYPE, BOX_TYPE2, OTHER_POSITION, zhCnToEnUsText, baseToolbarConfig, toolbar_config_default;
16771
16917
  var init_toolbar_config = __esm({
16772
16918
  "src/legacy/toolbar-config.ts"() {
16773
16919
  "use strict";
@@ -16776,10 +16922,45 @@ var FormulaX = (() => {
16776
16922
  init_other_position();
16777
16923
  init_toolbar_assets();
16778
16924
  init_formula_symbols();
16925
+ init_i18n();
16779
16926
  UI_ELE_TYPE = legacyEleType;
16780
16927
  BOX_TYPE2 = legacyBoxType;
16781
16928
  OTHER_POSITION = legacyOtherPosition;
16782
- config = [{
16929
+ zhCnToEnUsText = /* @__PURE__ */ new Map([
16930
+ ["\u9884\u8BBE", "Presets"],
16931
+ ["\u9884\u8BBE\u516C\u5F0F", "Preset formulas"],
16932
+ ["\u4E8C\u6B21\u516C\u5F0F", "Quadratic formula"],
16933
+ ["\u4E8C\u9879\u5F0F\u5B9A\u7406", "Binomial theorem"],
16934
+ ["\u52FE\u80A1\u5B9A\u7406", "Pythagorean theorem"],
16935
+ ["\u57FA\u7840\u6570\u5B66", "Basic math"],
16936
+ ["\u5E0C\u814A\u5B57\u6BCD", "Greek letters"],
16937
+ ["\u6C42\u53CD\u5173\u7CFB\u8FD0\u7B97\u7B26", "Negated operators"],
16938
+ ["\u5B57\u6BCD\u7C7B\u7B26\u53F7", "Letter-like symbols"],
16939
+ ["\u7BAD\u5934", "Arrows"],
16940
+ ["\u624B\u5199\u4F53", "Script"],
16941
+ ["\u5206\u6570", "Fraction"],
16942
+ ["\u5E38\u7528\u5206\u6570", "Common fractions"],
16943
+ ["\u4E0A\u4E0B\u6807", "Scripts"],
16944
+ ["\u4E0A\u6807\u548C\u4E0B\u6807", "Superscripts and subscripts"],
16945
+ ["\u5E38\u7528\u7684\u4E0A\u6807\u548C\u4E0B\u6807", "Common superscripts and subscripts"],
16946
+ ["\u6839\u5F0F", "Radicals"],
16947
+ ["\u5E38\u7528\u6839\u5F0F", "Common radicals"],
16948
+ ["\u79EF\u5206", "Integrals"],
16949
+ ["\u5927\u578B\u8FD0\u7B97\u7B26", "Large operators"],
16950
+ ["\u6C42\u548C", "Summations"],
16951
+ ["\u62EC\u53F7", "Brackets"],
16952
+ ["\u65B9\u62EC\u53F7", "Brackets"],
16953
+ ["\u51FD\u6570", "Functions"],
16954
+ ["\u4E09\u89D2\u51FD\u6570", "Trigonometric functions"],
16955
+ ["\u5E38\u7528\u51FD\u6570", "Common functions"],
16956
+ ["\u5C0F\u5199", "Lowercase"],
16957
+ ["\u5927\u5199", "Uppercase"],
16958
+ ["\u53D8\u4F53", "Variants"],
16959
+ ["\u82B1\u4F53", "Fraktur"],
16960
+ ["\u53CC\u7EBF", "Double-struck"],
16961
+ ["\u7F57\u9A6C", "Roman"]
16962
+ ]);
16963
+ baseToolbarConfig = [{
16783
16964
  type: UI_ELE_TYPE.DRAPDOWN_BOX,
16784
16965
  options: {
16785
16966
  button: {
@@ -17185,7 +17366,7 @@ var FormulaX = (() => {
17185
17366
  }];
17186
17367
  (function() {
17187
17368
  let tmp = [], otherImageSrc = resolveToolbarAssetPath("other.png"), currentConf = [];
17188
- each(config, function(conf) {
17369
+ each(baseToolbarConfig, function(conf) {
17189
17370
  if (conf.type === UI_ELE_TYPE.DELIMITER) {
17190
17371
  return;
17191
17372
  }
@@ -17257,7 +17438,7 @@ var FormulaX = (() => {
17257
17438
  "aleph",
17258
17439
  "beth",
17259
17440
  "blacksquare"
17260
- ], configList = config[2].options.box.group[0].items;
17441
+ ], configList = baseToolbarConfig[2].options.box.group[0].items;
17261
17442
  configList.push({
17262
17443
  title: "\u57FA\u7840\u6570\u5B66",
17263
17444
  content: getUnicodeContents(list)
@@ -17273,7 +17454,7 @@ var FormulaX = (() => {
17273
17454
  }, {
17274
17455
  title: "\u53D8\u4F53",
17275
17456
  values: ["digamma", "varepsilon", "varkappa", "varphi", "varpi", "varrho", "varsigma", "vartheta"]
17276
- }], greekConfigList = config[2].options.box.group[1].items;
17457
+ }], greekConfigList = baseToolbarConfig[2].options.box.group[1].items;
17277
17458
  greekConfigList.push({
17278
17459
  title: greekList[0].title,
17279
17460
  content: getUnicodeContents(greekList[0].values)
@@ -17322,7 +17503,7 @@ var FormulaX = (() => {
17322
17503
  "nVDash",
17323
17504
  "nexists"
17324
17505
  ]
17325
- }], greekConfigList = config[2].options.box.group[2].items;
17506
+ }], greekConfigList = baseToolbarConfig[2].options.box.group[2].items;
17326
17507
  greekConfigList.push({
17327
17508
  title: greekList[0].title,
17328
17509
  content: getUnicodeContents(greekList[0].values)
@@ -17348,7 +17529,7 @@ var FormulaX = (() => {
17348
17529
  "Game",
17349
17530
  "Im",
17350
17531
  "Re"
17351
- ], configList = config[2].options.box.group[3].items;
17532
+ ], configList = baseToolbarConfig[2].options.box.group[3].items;
17352
17533
  configList.push({
17353
17534
  title: "\u5B57\u6BCD\u7C7B\u7B26\u53F7",
17354
17535
  content: getUnicodeContents(list)
@@ -17416,7 +17597,7 @@ var FormulaX = (() => {
17416
17597
  "twoheadleftarrow",
17417
17598
  "twoheadrightarrow",
17418
17599
  "rightsquigarrow"
17419
- ], configList = config[2].options.box.group[4].items;
17600
+ ], configList = baseToolbarConfig[2].options.box.group[4].items;
17420
17601
  configList.push({
17421
17602
  title: "\u7BAD\u5934",
17422
17603
  content: getUnicodeContents(list)
@@ -17595,7 +17776,7 @@ var FormulaX = (() => {
17595
17776
  "y",
17596
17777
  "z"
17597
17778
  ]
17598
- }], configList = config[2].options.box.group[5].items;
17779
+ }], configList = baseToolbarConfig[2].options.box.group[5].items;
17599
17780
  each(list[0].values, function(item, index) {
17600
17781
  list[0].values[index] = "mathcal{" + item + "}";
17601
17782
  });
@@ -17625,7 +17806,7 @@ var FormulaX = (() => {
17625
17806
  content: getUnicodeContents(list[3].values)
17626
17807
  });
17627
17808
  })();
17628
- toolbar_config_default = config;
17809
+ toolbar_config_default = createToolbarConfig;
17629
17810
  }
17630
17811
  });
17631
17812
 
@@ -17668,6 +17849,7 @@ var FormulaX = (() => {
17668
17849
  init_toolbar();
17669
17850
  init_scrollbar();
17670
17851
  init_toolbar_config();
17852
+ init_i18n();
17671
17853
  $$8 = createLegacyUiUtils();
17672
17854
  VIEW_STATE = legacyUiDef.VIEW_STATE;
17673
17855
  DEFAULT_EDIT_AREA_HEIGHT = 100;
@@ -17698,7 +17880,8 @@ var FormulaX = (() => {
17698
17880
  this.initScrollEvent();
17699
17881
  },
17700
17882
  initComponents() {
17701
- this.components.toolbar = new toolbar_default(this, this.kfEditor, toolbar_config_default);
17883
+ const toolbarConfig = toolbar_config_default(normalizeFormulaXLocale(this.options.locale));
17884
+ this.components.toolbar = new toolbar_default(this, this.kfEditor, toolbarConfig);
17702
17885
  this.components.scrollbar = new scrollbar_default(this, this.kfEditor);
17703
17886
  },
17704
17887
  updateContainerSize(container, toolbar, editArea) {
@@ -18965,6 +19148,21 @@ var FormulaX = (() => {
18965
19148
  });
18966
19149
 
18967
19150
  // src/legacy/syntax.ts
19151
+ function clampOffset(offset, maxOffset) {
19152
+ return Math.max(0, Math.min(offset, maxOffset));
19153
+ }
19154
+ function normalizeCursorRecord(objTree, cursor) {
19155
+ const fallbackGroupId = objTree.mapping.root.strGroup.attr.id;
19156
+ const targetGroupId = cursor.groupId && objTree.mapping[cursor.groupId] ? cursor.groupId : fallbackGroupId;
19157
+ const operandCount = objTree.mapping[targetGroupId].strGroup.operand.length;
19158
+ const startOffset = clampOffset(cursor.startOffset, operandCount);
19159
+ const endOffset = clampOffset(cursor.endOffset, operandCount);
19160
+ return {
19161
+ groupId: targetGroupId,
19162
+ startOffset: Math.min(startOffset, endOffset),
19163
+ endOffset: Math.max(startOffset, endOffset)
19164
+ };
19165
+ }
18968
19166
  var CURSOR_CHAR2, kity19, SyntaxComponent, syntax_default;
18969
19167
  var init_syntax = __esm({
18970
19168
  "src/legacy/syntax.ts"() {
@@ -19025,10 +19223,14 @@ var FormulaX = (() => {
19025
19223
  },
19026
19224
  updateObjTree(objTree) {
19027
19225
  const selectInfo = objTree.select;
19226
+ this.objTree = objTree;
19028
19227
  if (selectInfo?.groupId) {
19029
19228
  this.updateCursor(selectInfo.groupId, selectInfo.startOffset, selectInfo.endOffset);
19229
+ return;
19230
+ }
19231
+ if (this.record.cursor.groupId !== null) {
19232
+ this.record.cursor = normalizeCursorRecord(objTree, this.record.cursor);
19030
19233
  }
19031
- this.objTree = objTree;
19032
19234
  },
19033
19235
  hasCursorInfo() {
19034
19236
  return this.record.cursor.groupId !== null;
@@ -19074,7 +19276,8 @@ var FormulaX = (() => {
19074
19276
  return this.objTree;
19075
19277
  },
19076
19278
  getGroupObject(id) {
19077
- return this.objTree.mapping[id].objGroup || null;
19279
+ const groupInfo = this.objTree.mapping[id];
19280
+ return groupInfo ? groupInfo.objGroup : null;
19078
19281
  },
19079
19282
  getCursorRecord() {
19080
19283
  return kity19.Utils.extend({}, this.record.cursor);
@@ -19150,7 +19353,7 @@ var FormulaX = (() => {
19150
19353
  return this.hasRootplaceholder();
19151
19354
  },
19152
19355
  serialization() {
19153
- const cursor = this.record.cursor;
19356
+ const cursor = normalizeCursorRecord(this.objTree, this.record.cursor);
19154
19357
  const objGroup = this.objTree.mapping[cursor.groupId];
19155
19358
  const curStrGroup = objGroup.strGroup;
19156
19359
  let strStartIndex = Math.min(cursor.endOffset, cursor.startOffset);
@@ -19186,11 +19389,12 @@ var FormulaX = (() => {
19186
19389
  endOffset = startOffset;
19187
19390
  startOffset = tmp;
19188
19391
  }
19189
- this.record.cursor = {
19392
+ const nextCursor = {
19190
19393
  groupId,
19191
19394
  startOffset,
19192
19395
  endOffset
19193
19396
  };
19397
+ this.record.cursor = this.objTree ? normalizeCursorRecord(this.objTree, nextCursor) : nextCursor;
19194
19398
  },
19195
19399
  leftMove() {
19196
19400
  this.components.move.leftMove();
@@ -19231,12 +19435,20 @@ var FormulaX = (() => {
19231
19435
  });
19232
19436
 
19233
19437
  // src/legacy/input.ts
19234
- var KEY_CODE, kity20, InputComponent, input_default;
19438
+ function insertCursorMarkers(value, selectionStart, selectionEnd) {
19439
+ const normalizedStart = Math.max(0, Math.min(selectionStart ?? value.length, value.length));
19440
+ const normalizedEnd = Math.max(0, Math.min(selectionEnd ?? normalizedStart, value.length));
19441
+ const rangeStart = Math.min(normalizedStart, normalizedEnd);
19442
+ const rangeEnd = Math.max(normalizedStart, normalizedEnd);
19443
+ return value.slice(0, rangeStart) + CURSOR_CHAR3 + value.slice(rangeStart, rangeEnd) + CURSOR_CHAR3 + value.slice(rangeEnd);
19444
+ }
19445
+ var KEY_CODE, CURSOR_CHAR3, kity20, InputComponent, input_default;
19235
19446
  var init_input = __esm({
19236
19447
  "src/legacy/input.ts"() {
19237
19448
  "use strict";
19238
19449
  init_legacy_utils();
19239
19450
  init_legacy_input_filter();
19451
+ init_legacy_sysconf();
19240
19452
  init_runtime_interop();
19241
19453
  KEY_CODE = {
19242
19454
  LEFT: 37,
@@ -19244,6 +19456,7 @@ var FormulaX = (() => {
19244
19456
  DELETE: 8,
19245
19457
  INPUT: 229
19246
19458
  };
19459
+ CURSOR_CHAR3 = legacySysconf.cursorCharacter;
19247
19460
  kity20 = getLegacyKity();
19248
19461
  InputComponent = kity20.createClass("InputComponent", {
19249
19462
  constructor(parentComponent, kfEditor) {
@@ -19416,7 +19629,12 @@ var FormulaX = (() => {
19416
19629
  return `${e.shiftKey ? "s+" : ""}${e.keyCode}`;
19417
19630
  },
19418
19631
  processingInput() {
19419
- this.restruct(this.inputBox.value);
19632
+ const latexWithCursor = insertCursorMarkers(
19633
+ this.inputBox.value,
19634
+ this.inputBox.selectionStart,
19635
+ this.inputBox.selectionEnd
19636
+ );
19637
+ this.restruct(latexWithCursor);
19420
19638
  this.kfEditor.requestService("ui.update.canvas.view");
19421
19639
  },
19422
19640
  restruct(latexStr) {
@@ -19949,7 +20167,7 @@ var FormulaX = (() => {
19949
20167
  var init_start = __esm({
19950
20168
  "src/boot/start.ts"() {
19951
20169
  "use strict";
19952
- init_editor();
20170
+ init_editor2();
19953
20171
  init_factory();
19954
20172
  init_ui();
19955
20173
  init_parser();
@@ -19966,6 +20184,8 @@ var FormulaX = (() => {
19966
20184
  // src/index.ts
19967
20185
  var index_exports = {};
19968
20186
  __export(index_exports, {
20187
+ DEFAULT_FORMULAX_LOCALE: () => DEFAULT_FORMULAX_LOCALE,
20188
+ FORMULAX_LOCALES: () => FORMULAX_LOCALES,
19969
20189
  FormulaXEditor: () => FormulaXEditor,
19970
20190
  addEvent: () => addEvent,
19971
20191
  createElement: () => createElement,
@@ -19993,58 +20213,17 @@ var FormulaX = (() => {
19993
20213
  legacyKfExtDef: () => legacyKfExtDef,
19994
20214
  legacySysconf: () => legacySysconf,
19995
20215
  legacyUiDef: () => legacyUiDef,
20216
+ legacyUiUtils: () => legacyUiUtils,
19996
20217
  mountKityEditor: () => mountKityEditor,
20218
+ normalizeFormulaXLocale: () => normalizeFormulaXLocale,
19997
20219
  normalizeMouseEvent: () => normalizeMouseEvent,
19998
20220
  publish: () => publish,
19999
20221
  subscribe: () => subscribe
20000
20222
  });
20001
-
20002
- // public/assets/images/toolbar/btn.png
20003
- var btn_default = "./btn-5DANP6JY.png";
20004
-
20005
- // public/assets/images/toolbar/other.png
20006
- var other_default = "./other-OMWJFGL5.png";
20007
-
20008
- // public/assets/styles/editor.css?url
20009
- var editor_default = "./editor-JT5KLVXX.css?url";
20010
-
20011
- // public/resource/KF_AMS_BB.woff
20012
- var KF_AMS_BB_default = "./KF_AMS_BB-5QF7FUSO.woff";
20013
-
20014
- // public/resource/KF_AMS_CAL.woff
20015
- var KF_AMS_CAL_default = "./KF_AMS_CAL-NXRNLAZN.woff";
20016
-
20017
- // public/resource/KF_AMS_FRAK.woff
20018
- var KF_AMS_FRAK_default = "./KF_AMS_FRAK-CO33WWN4.woff";
20019
-
20020
- // public/resource/KF_AMS_MAIN.woff
20021
- var KF_AMS_MAIN_default = "./KF_AMS_MAIN-25QJVAWY.woff";
20022
-
20023
- // public/resource/KF_AMS_ROMAN.woff
20024
- var KF_AMS_ROMAN_default = "./KF_AMS_ROMAN-243BR7HH.woff";
20025
-
20026
- // src/asset-manifest.ts
20027
- var kityFontAssets = {
20028
- KF_AMS_BB: KF_AMS_BB_default,
20029
- KF_AMS_CAL: KF_AMS_CAL_default,
20030
- KF_AMS_FRAK: KF_AMS_FRAK_default,
20031
- KF_AMS_MAIN: KF_AMS_MAIN_default,
20032
- KF_AMS_ROMAN: KF_AMS_ROMAN_default
20033
- };
20034
- var kityToolbarAssets = {
20035
- btn: btn_default,
20036
- other: other_default
20037
- };
20038
- var kityStyleAssets = {
20039
- editor: editor_default
20040
- };
20041
- var kityAssetManifest = {
20042
- fonts: kityFontAssets,
20043
- toolbar: kityToolbarAssets,
20044
- styles: kityStyleAssets
20045
- };
20223
+ init_asset_manifest();
20046
20224
 
20047
20225
  // src/create-editor.ts
20226
+ init_asset_manifest();
20048
20227
  init_legacy_box_type();
20049
20228
 
20050
20229
  // src/vendor/char-position.ts
@@ -23447,8 +23626,83 @@ var FormulaX = (() => {
23447
23626
  targetWindow.kity = kity;
23448
23627
  }
23449
23628
 
23629
+ // src/perf.ts
23630
+ function getPerfHost() {
23631
+ return globalThis;
23632
+ }
23633
+ function getPerfState() {
23634
+ const host = getPerfHost();
23635
+ host.__FORMULAX_PERF_STATE__ ??= {
23636
+ reportedMeasureCount: 0,
23637
+ reportScheduled: false
23638
+ };
23639
+ return host.__FORMULAX_PERF_STATE__;
23640
+ }
23641
+ function hasPerfSupport() {
23642
+ return typeof performance !== "undefined" && typeof performance.mark === "function" && typeof performance.measure === "function" && typeof performance.getEntriesByType === "function";
23643
+ }
23644
+ function isPerfDebugEnabled() {
23645
+ return getPerfHost().__FORMULAX_PERF__ === true;
23646
+ }
23647
+ function schedulePerfReport() {
23648
+ if (!hasPerfSupport() || !isPerfDebugEnabled()) {
23649
+ return;
23650
+ }
23651
+ const state = getPerfState();
23652
+ if (state.reportScheduled) {
23653
+ return;
23654
+ }
23655
+ state.reportScheduled = true;
23656
+ queueMicrotask(() => {
23657
+ state.reportScheduled = false;
23658
+ const entries = performance.getEntriesByType("measure").filter((entry) => entry.name.startsWith("fx:")).sort((left, right) => left.startTime - right.startTime);
23659
+ const nextEntries = entries.slice(state.reportedMeasureCount);
23660
+ state.reportedMeasureCount = entries.length;
23661
+ if (!nextEntries.length) {
23662
+ return;
23663
+ }
23664
+ console.table(nextEntries.map((entry) => ({
23665
+ name: entry.name,
23666
+ duration: Number(entry.duration.toFixed(2)),
23667
+ startTime: Number(entry.startTime.toFixed(2))
23668
+ })));
23669
+ });
23670
+ }
23671
+ function markFormulaXPerf(name) {
23672
+ if (!hasPerfSupport()) {
23673
+ return null;
23674
+ }
23675
+ const markName = `${name}::${Date.now()}::${Math.random().toString(36).slice(2, 8)}`;
23676
+ performance.mark(markName);
23677
+ return markName;
23678
+ }
23679
+ function measureFormulaXPerf(name, startMark, endMark) {
23680
+ if (!hasPerfSupport() || !startMark) {
23681
+ return null;
23682
+ }
23683
+ const resolvedEndMark = endMark ?? markFormulaXPerf(`${name}:end`);
23684
+ if (!resolvedEndMark) {
23685
+ return null;
23686
+ }
23687
+ performance.measure(name, startMark, resolvedEndMark);
23688
+ schedulePerfReport();
23689
+ return resolvedEndMark;
23690
+ }
23691
+ function clearFormulaXPerfMarks(...marks) {
23692
+ if (!hasPerfSupport()) {
23693
+ return;
23694
+ }
23695
+ for (const mark of marks) {
23696
+ if (!mark) {
23697
+ continue;
23698
+ }
23699
+ performance.clearMarks(mark);
23700
+ }
23701
+ }
23702
+
23450
23703
  // src/create-editor.ts
23451
23704
  init_toolbar_assets();
23705
+ init_i18n();
23452
23706
  var DEFAULT_LATEX = "x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}";
23453
23707
  var DEFAULT_EDITOR_HEIGHT = "auto";
23454
23708
  var KITY_STYLE_ID = "formulax-kity-editor-styles";
@@ -23487,13 +23741,14 @@ var FormulaX = (() => {
23487
23741
  }
23488
23742
  function ensureKityStylesheet(doc, href) {
23489
23743
  if (doc.getElementById(KITY_STYLE_ID)) {
23490
- return;
23744
+ return false;
23491
23745
  }
23492
23746
  const link = doc.createElement("link");
23493
23747
  link.id = KITY_STYLE_ID;
23494
23748
  link.rel = "stylesheet";
23495
23749
  link.href = href;
23496
23750
  doc.head.appendChild(link);
23751
+ return true;
23497
23752
  }
23498
23753
  function hydrateLegacyKf(runtimeWindow) {
23499
23754
  const requireFormula = runtimeWindow.__kityFormulaRequire__;
@@ -23541,7 +23796,7 @@ var FormulaX = (() => {
23541
23796
  kity: runtimeWindow.kity,
23542
23797
  otherPosition: legacyOtherPosition,
23543
23798
  uiDef: legacyUiDef,
23544
- uiUtils: createLegacyUiUtils()
23799
+ uiUtils: legacyUiUtils
23545
23800
  };
23546
23801
  }
23547
23802
  async function ensureKityRuntime() {
@@ -23549,64 +23804,118 @@ var FormulaX = (() => {
23549
23804
  return runtimePromise;
23550
23805
  }
23551
23806
  runtimePromise = (async () => {
23807
+ const runtimeTotalStart = markFormulaXPerf("fx:kity-runtime:total");
23552
23808
  const runtimeWindow = window;
23553
23809
  runtimeWindow.kf = runtimeWindow.kf ?? {};
23554
23810
  installKityRuntime(runtimeWindow);
23555
- const { installLegacyKityFormulaRuntime: installLegacyKityFormulaRuntime2 } = await Promise.resolve().then(() => (init_install(), install_exports));
23556
- installLegacyKityFormulaRuntime2(runtimeWindow);
23557
- hydrateLegacyKf(runtimeWindow);
23558
- const { installLegacyParserRuntime: installLegacyParserRuntime2 } = await Promise.resolve().then(() => (init_install2(), install_exports2));
23559
- installLegacyParserRuntime2(runtimeWindow);
23560
- installLegacyRuntime(runtimeWindow);
23561
- const { installKityEditorStart: installKityEditorStart2 } = await Promise.resolve().then(() => (init_start(), start_exports));
23562
- installKityEditorStart2(runtimeWindow);
23811
+ try {
23812
+ const formulaImportStart = markFormulaXPerf("fx:kity-runtime:formula-import");
23813
+ const { installLegacyKityFormulaRuntime: installLegacyKityFormulaRuntime2 } = await Promise.resolve().then(() => (init_install(), install_exports));
23814
+ const formulaImportEnd = markFormulaXPerf("fx:kity-runtime:formula-import:end");
23815
+ measureFormulaXPerf("fx:kity-runtime:formula-import", formulaImportStart, formulaImportEnd);
23816
+ clearFormulaXPerfMarks(formulaImportStart, formulaImportEnd);
23817
+ const formulaInstallStart = markFormulaXPerf("fx:kity-runtime:formula-install");
23818
+ installLegacyKityFormulaRuntime2(runtimeWindow);
23819
+ hydrateLegacyKf(runtimeWindow);
23820
+ const formulaInstallEnd = markFormulaXPerf("fx:kity-runtime:formula-install:end");
23821
+ measureFormulaXPerf("fx:kity-runtime:formula-install", formulaInstallStart, formulaInstallEnd);
23822
+ clearFormulaXPerfMarks(formulaInstallStart, formulaInstallEnd);
23823
+ const parserImportStart = markFormulaXPerf("fx:kity-runtime:parser-import");
23824
+ const { installLegacyParserRuntime: installLegacyParserRuntime2 } = await Promise.resolve().then(() => (init_install2(), install_exports2));
23825
+ const parserImportEnd = markFormulaXPerf("fx:kity-runtime:parser-import:end");
23826
+ measureFormulaXPerf("fx:kity-runtime:parser-import", parserImportStart, parserImportEnd);
23827
+ clearFormulaXPerfMarks(parserImportStart, parserImportEnd);
23828
+ const parserInstallStart = markFormulaXPerf("fx:kity-runtime:parser-install");
23829
+ installLegacyParserRuntime2(runtimeWindow);
23830
+ const parserInstallEnd = markFormulaXPerf("fx:kity-runtime:parser-install:end");
23831
+ measureFormulaXPerf("fx:kity-runtime:parser-install", parserInstallStart, parserInstallEnd);
23832
+ clearFormulaXPerfMarks(parserInstallStart, parserInstallEnd);
23833
+ installLegacyRuntime(runtimeWindow);
23834
+ const bootImportStart = markFormulaXPerf("fx:kity-runtime:boot-import");
23835
+ const { installKityEditorStart: installKityEditorStart2 } = await Promise.resolve().then(() => (init_start(), start_exports));
23836
+ const bootImportEnd = markFormulaXPerf("fx:kity-runtime:boot-import:end");
23837
+ measureFormulaXPerf("fx:kity-runtime:boot-import", bootImportStart, bootImportEnd);
23838
+ clearFormulaXPerfMarks(bootImportStart, bootImportEnd);
23839
+ const bootInstallStart = markFormulaXPerf("fx:kity-runtime:boot-install");
23840
+ installKityEditorStart2(runtimeWindow);
23841
+ const bootInstallEnd = markFormulaXPerf("fx:kity-runtime:boot-install:end");
23842
+ measureFormulaXPerf("fx:kity-runtime:boot-install", bootInstallStart, bootInstallEnd);
23843
+ clearFormulaXPerfMarks(bootInstallStart, bootInstallEnd);
23844
+ } finally {
23845
+ const runtimeTotalEnd = markFormulaXPerf("fx:kity-runtime:total:end");
23846
+ measureFormulaXPerf("fx:kity-runtime:total", runtimeTotalStart, runtimeTotalEnd);
23847
+ clearFormulaXPerfMarks(runtimeTotalStart, runtimeTotalEnd);
23848
+ }
23563
23849
  })();
23564
23850
  return runtimePromise;
23565
23851
  }
23566
23852
  async function createKityEditor(container, options = {}) {
23853
+ const createEditorStart = markFormulaXPerf("fx:create-kity-editor:total");
23567
23854
  const fontsize = options.render?.fontsize ?? 40;
23568
23855
  const editorHeight = normalizeCssSize(options.height, DEFAULT_EDITOR_HEIGHT);
23856
+ const locale = normalizeFormulaXLocale(options.locale ?? DEFAULT_FORMULAX_LOCALE);
23569
23857
  const assets = resolveEditorAssets(options.assets);
23570
- ensureKityStylesheet(document, assets.styles.editor);
23571
- setToolbarAssetUrls(assets.toolbar);
23572
- await ensureKityRuntime();
23573
- const runtimeWindow = window;
23574
- if (!runtimeWindow.kf?.EditorFactory) {
23575
- throw new Error("Kity editor runtime did not initialize");
23576
- }
23577
- container.innerHTML = "";
23578
- const host = document.createElement("div");
23579
- host.className = "kf-editor";
23580
- host.style.width = "100%";
23581
- host.style.height = editorHeight;
23582
- container.appendChild(host);
23583
- const factory2 = runtimeWindow.kf.EditorFactory.create(host, {
23584
- render: {
23585
- fontsize
23586
- },
23587
- resource: {
23588
- path: "",
23589
- fonts: assets.fonts
23858
+ try {
23859
+ const stylesheetInserted = ensureKityStylesheet(document, assets.styles.editor);
23860
+ if (stylesheetInserted) {
23861
+ const stylesheetInsertedMark = markFormulaXPerf("fx:kity-css:link-inserted");
23862
+ measureFormulaXPerf("fx:kity-css:link-inserted", createEditorStart, stylesheetInsertedMark);
23863
+ clearFormulaXPerfMarks(stylesheetInsertedMark);
23590
23864
  }
23591
- });
23592
- return {
23593
- ready: factory2.ready.bind(factory2),
23594
- execCommand(name, value) {
23595
- factory2.ready(function execWhenReady() {
23596
- this.execCommand(name, value);
23597
- });
23598
- },
23599
- focus() {
23600
- factory2.ready(function focusWhenReady() {
23601
- this.execCommand("focus");
23602
- });
23603
- },
23604
- destroy() {
23605
- container.innerHTML = "";
23606
- },
23607
- host,
23608
- raw: factory2
23609
- };
23865
+ setToolbarAssetUrls(assets.toolbar);
23866
+ await ensureKityRuntime();
23867
+ const runtimeReadyMark = markFormulaXPerf("fx:kity-runtime:ready-for-editor");
23868
+ measureFormulaXPerf("fx:kity-runtime:ready-for-editor", createEditorStart, runtimeReadyMark);
23869
+ clearFormulaXPerfMarks(runtimeReadyMark);
23870
+ const runtimeWindow = window;
23871
+ if (!runtimeWindow.kf?.EditorFactory) {
23872
+ throw new Error("Kity editor runtime did not initialize");
23873
+ }
23874
+ container.innerHTML = "";
23875
+ const host = document.createElement("div");
23876
+ host.className = "kf-editor";
23877
+ host.style.width = "100%";
23878
+ host.style.height = editorHeight;
23879
+ container.appendChild(host);
23880
+ const factoryCreateStart = markFormulaXPerf("fx:kity-editor-factory:create");
23881
+ const factory2 = runtimeWindow.kf.EditorFactory.create(host, {
23882
+ render: {
23883
+ fontsize
23884
+ },
23885
+ ui: {
23886
+ locale
23887
+ },
23888
+ resource: {
23889
+ path: "",
23890
+ fonts: assets.fonts
23891
+ }
23892
+ });
23893
+ const factoryCreateEnd = markFormulaXPerf("fx:kity-editor-factory:create:end");
23894
+ measureFormulaXPerf("fx:kity-editor-factory:create", factoryCreateStart, factoryCreateEnd);
23895
+ clearFormulaXPerfMarks(factoryCreateStart, factoryCreateEnd);
23896
+ return {
23897
+ ready: factory2.ready.bind(factory2),
23898
+ execCommand(name, value) {
23899
+ factory2.ready(function execWhenReady() {
23900
+ this.execCommand(name, value);
23901
+ });
23902
+ },
23903
+ focus() {
23904
+ factory2.ready(function focusWhenReady() {
23905
+ this.execCommand("focus");
23906
+ });
23907
+ },
23908
+ destroy() {
23909
+ container.innerHTML = "";
23910
+ },
23911
+ host,
23912
+ raw: factory2
23913
+ };
23914
+ } finally {
23915
+ const createEditorEnd = markFormulaXPerf("fx:create-kity-editor:total:end");
23916
+ measureFormulaXPerf("fx:create-kity-editor:total", createEditorStart, createEditorEnd);
23917
+ clearFormulaXPerfMarks(createEditorStart, createEditorEnd);
23918
+ }
23610
23919
  }
23611
23920
  async function mountKityEditor(container, options = {}) {
23612
23921
  const editor = await createKityEditor(container, options);
@@ -23658,6 +23967,7 @@ var FormulaX = (() => {
23658
23967
 
23659
23968
  // src/index.ts
23660
23969
  init_dom_utils();
23970
+ init_i18n();
23661
23971
  init_legacy_box_type();
23662
23972
  init_legacy_component();
23663
23973
  init_legacy_ele_type();