@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.
package/dist/index.cjs CHANGED
@@ -20,6 +20,105 @@ var __copyProps = (to, from, except, desc) => {
20
20
  };
21
21
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
22
 
23
+ // public/assets/images/toolbar/btn.png
24
+ var btn_default;
25
+ var init_btn = __esm({
26
+ "public/assets/images/toolbar/btn.png"() {
27
+ btn_default = "./btn-5DANP6JY.png";
28
+ }
29
+ });
30
+
31
+ // public/assets/images/toolbar/other.png
32
+ var other_default;
33
+ var init_other = __esm({
34
+ "public/assets/images/toolbar/other.png"() {
35
+ other_default = "./other-OMWJFGL5.png";
36
+ }
37
+ });
38
+
39
+ // public/assets/styles/editor.css?url
40
+ var editor_default;
41
+ var init_editor = __esm({
42
+ "public/assets/styles/editor.css?url"() {
43
+ editor_default = "./editor-JT5KLVXX.css?url";
44
+ }
45
+ });
46
+
47
+ // public/resource/KF_AMS_BB.woff
48
+ var KF_AMS_BB_default;
49
+ var init_KF_AMS_BB = __esm({
50
+ "public/resource/KF_AMS_BB.woff"() {
51
+ KF_AMS_BB_default = "./KF_AMS_BB-5QF7FUSO.woff";
52
+ }
53
+ });
54
+
55
+ // public/resource/KF_AMS_CAL.woff
56
+ var KF_AMS_CAL_default;
57
+ var init_KF_AMS_CAL = __esm({
58
+ "public/resource/KF_AMS_CAL.woff"() {
59
+ KF_AMS_CAL_default = "./KF_AMS_CAL-NXRNLAZN.woff";
60
+ }
61
+ });
62
+
63
+ // public/resource/KF_AMS_FRAK.woff
64
+ var KF_AMS_FRAK_default;
65
+ var init_KF_AMS_FRAK = __esm({
66
+ "public/resource/KF_AMS_FRAK.woff"() {
67
+ KF_AMS_FRAK_default = "./KF_AMS_FRAK-CO33WWN4.woff";
68
+ }
69
+ });
70
+
71
+ // public/resource/KF_AMS_MAIN.woff
72
+ var KF_AMS_MAIN_default;
73
+ var init_KF_AMS_MAIN = __esm({
74
+ "public/resource/KF_AMS_MAIN.woff"() {
75
+ KF_AMS_MAIN_default = "./KF_AMS_MAIN-25QJVAWY.woff";
76
+ }
77
+ });
78
+
79
+ // public/resource/KF_AMS_ROMAN.woff
80
+ var KF_AMS_ROMAN_default;
81
+ var init_KF_AMS_ROMAN = __esm({
82
+ "public/resource/KF_AMS_ROMAN.woff"() {
83
+ KF_AMS_ROMAN_default = "./KF_AMS_ROMAN-243BR7HH.woff";
84
+ }
85
+ });
86
+
87
+ // src/asset-manifest.ts
88
+ var kityFontAssets, kityToolbarAssets, kityStyleAssets, kityAssetManifest;
89
+ var init_asset_manifest = __esm({
90
+ "src/asset-manifest.ts"() {
91
+ "use strict";
92
+ init_btn();
93
+ init_other();
94
+ init_editor();
95
+ init_KF_AMS_BB();
96
+ init_KF_AMS_CAL();
97
+ init_KF_AMS_FRAK();
98
+ init_KF_AMS_MAIN();
99
+ init_KF_AMS_ROMAN();
100
+ kityFontAssets = {
101
+ KF_AMS_BB: KF_AMS_BB_default,
102
+ KF_AMS_CAL: KF_AMS_CAL_default,
103
+ KF_AMS_FRAK: KF_AMS_FRAK_default,
104
+ KF_AMS_MAIN: KF_AMS_MAIN_default,
105
+ KF_AMS_ROMAN: KF_AMS_ROMAN_default
106
+ };
107
+ kityToolbarAssets = {
108
+ btn: btn_default,
109
+ other: other_default
110
+ };
111
+ kityStyleAssets = {
112
+ editor: editor_default
113
+ };
114
+ kityAssetManifest = {
115
+ fonts: kityFontAssets,
116
+ toolbar: kityToolbarAssets,
117
+ styles: kityStyleAssets
118
+ };
119
+ }
120
+ });
121
+
23
122
  // src/vendor/legacy-box-type.ts
24
123
  var legacyBoxType;
25
124
  var init_legacy_box_type = __esm({
@@ -927,28 +1026,30 @@ var init_dom_utils = __esm({
927
1026
 
928
1027
  // src/vendor/legacy-ui-utils.ts
929
1028
  function createLegacyUiUtils() {
930
- return {
931
- ele: createElement,
932
- getRectBox,
933
- on(target, type, fn) {
934
- addEvent(target, type, fn);
935
- return this;
936
- },
937
- delegate(target, selector, type, fn) {
938
- delegateEvent(target, selector, type, fn);
939
- return this;
940
- },
941
- publish(topic, ...args) {
942
- publish(topic, ...args);
943
- },
944
- subscribe,
945
- getClassList
946
- };
1029
+ return legacyUiUtils;
947
1030
  }
1031
+ var legacyUiUtils;
948
1032
  var init_legacy_ui_utils = __esm({
949
1033
  "src/vendor/legacy-ui-utils.ts"() {
950
1034
  "use strict";
951
1035
  init_dom_utils();
1036
+ legacyUiUtils = {
1037
+ ele: createElement,
1038
+ getRectBox,
1039
+ on(target, type, fn) {
1040
+ addEvent(target, type, fn);
1041
+ return this;
1042
+ },
1043
+ delegate(target, selector, type, fn) {
1044
+ delegateEvent(target, selector, type, fn);
1045
+ return this;
1046
+ },
1047
+ publish(topic, ...args) {
1048
+ publish(topic, ...args);
1049
+ },
1050
+ subscribe,
1051
+ getClassList
1052
+ };
952
1053
  }
953
1054
  });
954
1055
 
@@ -971,7 +1072,27 @@ var toolbarAssetFileMap;
971
1072
  var init_toolbar_assets = __esm({
972
1073
  "src/toolbar-assets.ts"() {
973
1074
  "use strict";
974
- toolbarAssetFileMap = {};
1075
+ init_asset_manifest();
1076
+ toolbarAssetFileMap = {
1077
+ "btn.png": kityToolbarAssets.btn,
1078
+ "other.png": kityToolbarAssets.other
1079
+ };
1080
+ }
1081
+ });
1082
+
1083
+ // src/i18n.ts
1084
+ function normalizeFormulaXLocale(locale) {
1085
+ if (locale === "zh_CN") {
1086
+ return "zh_CN";
1087
+ }
1088
+ return DEFAULT_FORMULAX_LOCALE;
1089
+ }
1090
+ var FORMULAX_LOCALES, DEFAULT_FORMULAX_LOCALE;
1091
+ var init_i18n = __esm({
1092
+ "src/i18n.ts"() {
1093
+ "use strict";
1094
+ FORMULAX_LOCALES = ["en_US", "zh_CN"];
1095
+ DEFAULT_FORMULAX_LOCALE = "en_US";
975
1096
  }
976
1097
  });
977
1098
 
@@ -1860,14 +1981,11 @@ var init_font_installer = __esm({
1860
1981
  count += 1;
1861
1982
  fontInfo.meta.src = resolveFontSource(this.fonts, this.resource, fontInfo.meta.src);
1862
1983
  this.createFontStyle(fontInfo);
1863
- preloadFont(this.doc, fontInfo).then(() => {
1864
- applyFonts(this.doc, fontInfo);
1865
- }).catch(() => void 0).finally(() => {
1866
- count -= 1;
1867
- if (count === 0) {
1868
- complete(this.doc, callback);
1869
- }
1870
- });
1984
+ applyFonts(this.doc, fontInfo);
1985
+ count -= 1;
1986
+ if (count === 0) {
1987
+ complete(this.doc, callback);
1988
+ }
1871
1989
  });
1872
1990
  },
1873
1991
  createFontStyle: function(fontInfo) {
@@ -1878,13 +1996,6 @@ var init_font_installer = __esm({
1878
1996
  this.doc.head.appendChild(stylesheet);
1879
1997
  }
1880
1998
  });
1881
- function preloadFont(doc, fontInfo) {
1882
- const view = doc.defaultView ?? window;
1883
- if (view.fetch) {
1884
- return view.fetch(fontInfo.meta.src, { method: "GET" }).then(() => void 0);
1885
- }
1886
- return Promise.resolve();
1887
- }
1888
1999
  function resolveFontSource(fonts, resourceBase, originalSrc) {
1889
2000
  const directMatch = fonts[originalSrc];
1890
2001
  if (directMatch) {
@@ -2042,11 +2153,11 @@ var init_formula = __esm({
2042
2153
  bg;
2043
2154
  exp;
2044
2155
  config;
2045
- constructor(kity26, exp, config2) {
2156
+ constructor(kity26, exp, config) {
2046
2157
  this.wrap = new kity26.Group();
2047
2158
  this.bg = new kity26.Rect(0, 0, 0, 0).fill("transparent");
2048
2159
  this.exp = exp;
2049
- this.config = config2;
2160
+ this.config = config;
2050
2161
  this.wrap.setAttr("data-type", "kf-exp-wrap");
2051
2162
  this.bg.setAttr("data-type", "kf-exp-wrap-bg");
2052
2163
  this.wrap.addShape(this.bg);
@@ -2075,14 +2186,14 @@ var init_formula = __esm({
2075
2186
  static create(kity26, GTYPE2, FontManager, FontInstaller, FPaper, Output) {
2076
2187
  const Formula = kity26.createClass("Formula", {
2077
2188
  base: FPaper,
2078
- constructor: function(container, config2) {
2189
+ constructor: function(container, config) {
2079
2190
  if (this.__FORMULAX_PRESERVE_CALL_BASE__) {
2080
2191
  this.callBase(container);
2081
2192
  }
2082
2193
  FPaper.call(this, container);
2083
2194
  this.expressions = [];
2084
2195
  this.fontInstaller = new FontInstaller(this);
2085
- this.config = kity26.Utils.extend({}, DEFAULT_OPTIONS, config2);
2196
+ this.config = kity26.Utils.extend({}, DEFAULT_OPTIONS, config);
2086
2197
  this.initEnvironment();
2087
2198
  this.initInnerFont();
2088
2199
  },
@@ -9547,7 +9658,7 @@ function registerAssemblyModule(context) {
9547
9658
  value: function() {
9548
9659
  const kf7 = window2.kf;
9549
9660
  const CONSTRUCT_MAPPING = {};
9550
- const CURSOR_CHAR3 = "\uF155";
9661
+ const CURSOR_CHAR4 = "\uF155";
9551
9662
  class Assembly {
9552
9663
  formula;
9553
9664
  constructor(formula) {
@@ -9584,7 +9695,7 @@ function registerAssemblyModule(context) {
9584
9695
  if (tree.name.indexOf("text") === -1) {
9585
9696
  for (let i2 = 0, len = operand.length; i2 < len; i2 += 1) {
9586
9697
  currentOperand = operand[i2];
9587
- if (currentOperand === CURSOR_CHAR3) {
9698
+ if (currentOperand === CURSOR_CHAR4) {
9588
9699
  cursorLocation.push(i2);
9589
9700
  if (!Object.prototype.hasOwnProperty.call(selectInfo, "startOffset")) {
9590
9701
  selectInfo.startOffset = i2;
@@ -10879,7 +10990,7 @@ function getService(serviceName) {
10879
10990
  return serviceObject;
10880
10991
  }
10881
10992
  var defaultOptions, components, kity2, kf, KFEditor, editor_default2;
10882
- var init_editor = __esm({
10993
+ var init_editor2 = __esm({
10883
10994
  "src/legacy/editor.ts"() {
10884
10995
  "use strict";
10885
10996
  init_legacy_utils();
@@ -10999,7 +11110,7 @@ var EditorWrapper, factory, factory_default;
10999
11110
  var init_factory = __esm({
11000
11111
  "src/legacy/factory.ts"() {
11001
11112
  "use strict";
11002
- init_editor();
11113
+ init_editor2();
11003
11114
  init_runtime_interop();
11004
11115
  EditorWrapper = class {
11005
11116
  callbacks = [];
@@ -12756,6 +12867,35 @@ function each(list, callback) {
12756
12867
  }
12757
12868
  Object.keys(list).forEach((key) => callback(list[key], key));
12758
12869
  }
12870
+ function translateToolbarText(value, locale) {
12871
+ if (locale === "zh_CN") {
12872
+ return value;
12873
+ }
12874
+ const normalizedValue = value.replace(/<br\s*\/?>/gi, "").trim();
12875
+ const translatedValue = zhCnToEnUsText.get(normalizedValue);
12876
+ if (!translatedValue) {
12877
+ return value;
12878
+ }
12879
+ const lineBreakMatch = value.match(/<br\s*\/?>/i);
12880
+ return lineBreakMatch ? `${translatedValue}${lineBreakMatch[0]}` : translatedValue;
12881
+ }
12882
+ function localizeToolbarConfig(value, locale) {
12883
+ if (Array.isArray(value)) {
12884
+ return value.map((item) => localizeToolbarConfig(item, locale));
12885
+ }
12886
+ if (!value || typeof value !== "object") {
12887
+ return value;
12888
+ }
12889
+ const result = {};
12890
+ for (const [key, currentValue] of Object.entries(value)) {
12891
+ if ((key === "label" || key === "title") && typeof currentValue === "string") {
12892
+ result[key] = translateToolbarText(currentValue, locale);
12893
+ continue;
12894
+ }
12895
+ result[key] = localizeToolbarConfig(currentValue, locale);
12896
+ }
12897
+ return result;
12898
+ }
12759
12899
  function getUnicodeContents(keySet) {
12760
12900
  let result = [];
12761
12901
  each(keySet, function(key) {
@@ -12775,7 +12915,13 @@ function getUnicodeContents(keySet) {
12775
12915
  });
12776
12916
  return result;
12777
12917
  }
12778
- var UI_ELE_TYPE, BOX_TYPE2, OTHER_POSITION, config, toolbar_config_default;
12918
+ function createToolbarConfig(locale = DEFAULT_FORMULAX_LOCALE) {
12919
+ return localizeToolbarConfig(
12920
+ baseToolbarConfig,
12921
+ normalizeFormulaXLocale(locale)
12922
+ );
12923
+ }
12924
+ var UI_ELE_TYPE, BOX_TYPE2, OTHER_POSITION, zhCnToEnUsText, baseToolbarConfig, toolbar_config_default;
12779
12925
  var init_toolbar_config = __esm({
12780
12926
  "src/legacy/toolbar-config.ts"() {
12781
12927
  "use strict";
@@ -12784,10 +12930,45 @@ var init_toolbar_config = __esm({
12784
12930
  init_other_position();
12785
12931
  init_toolbar_assets();
12786
12932
  init_formula_symbols();
12933
+ init_i18n();
12787
12934
  UI_ELE_TYPE = legacyEleType;
12788
12935
  BOX_TYPE2 = legacyBoxType;
12789
12936
  OTHER_POSITION = legacyOtherPosition;
12790
- config = [{
12937
+ zhCnToEnUsText = /* @__PURE__ */ new Map([
12938
+ ["\u9884\u8BBE", "Presets"],
12939
+ ["\u9884\u8BBE\u516C\u5F0F", "Preset formulas"],
12940
+ ["\u4E8C\u6B21\u516C\u5F0F", "Quadratic formula"],
12941
+ ["\u4E8C\u9879\u5F0F\u5B9A\u7406", "Binomial theorem"],
12942
+ ["\u52FE\u80A1\u5B9A\u7406", "Pythagorean theorem"],
12943
+ ["\u57FA\u7840\u6570\u5B66", "Basic math"],
12944
+ ["\u5E0C\u814A\u5B57\u6BCD", "Greek letters"],
12945
+ ["\u6C42\u53CD\u5173\u7CFB\u8FD0\u7B97\u7B26", "Negated operators"],
12946
+ ["\u5B57\u6BCD\u7C7B\u7B26\u53F7", "Letter-like symbols"],
12947
+ ["\u7BAD\u5934", "Arrows"],
12948
+ ["\u624B\u5199\u4F53", "Script"],
12949
+ ["\u5206\u6570", "Fraction"],
12950
+ ["\u5E38\u7528\u5206\u6570", "Common fractions"],
12951
+ ["\u4E0A\u4E0B\u6807", "Scripts"],
12952
+ ["\u4E0A\u6807\u548C\u4E0B\u6807", "Superscripts and subscripts"],
12953
+ ["\u5E38\u7528\u7684\u4E0A\u6807\u548C\u4E0B\u6807", "Common superscripts and subscripts"],
12954
+ ["\u6839\u5F0F", "Radicals"],
12955
+ ["\u5E38\u7528\u6839\u5F0F", "Common radicals"],
12956
+ ["\u79EF\u5206", "Integrals"],
12957
+ ["\u5927\u578B\u8FD0\u7B97\u7B26", "Large operators"],
12958
+ ["\u6C42\u548C", "Summations"],
12959
+ ["\u62EC\u53F7", "Brackets"],
12960
+ ["\u65B9\u62EC\u53F7", "Brackets"],
12961
+ ["\u51FD\u6570", "Functions"],
12962
+ ["\u4E09\u89D2\u51FD\u6570", "Trigonometric functions"],
12963
+ ["\u5E38\u7528\u51FD\u6570", "Common functions"],
12964
+ ["\u5C0F\u5199", "Lowercase"],
12965
+ ["\u5927\u5199", "Uppercase"],
12966
+ ["\u53D8\u4F53", "Variants"],
12967
+ ["\u82B1\u4F53", "Fraktur"],
12968
+ ["\u53CC\u7EBF", "Double-struck"],
12969
+ ["\u7F57\u9A6C", "Roman"]
12970
+ ]);
12971
+ baseToolbarConfig = [{
12791
12972
  type: UI_ELE_TYPE.DRAPDOWN_BOX,
12792
12973
  options: {
12793
12974
  button: {
@@ -13193,7 +13374,7 @@ var init_toolbar_config = __esm({
13193
13374
  }];
13194
13375
  (function() {
13195
13376
  let tmp = [], otherImageSrc = resolveToolbarAssetPath("other.png"), currentConf = [];
13196
- each(config, function(conf) {
13377
+ each(baseToolbarConfig, function(conf) {
13197
13378
  if (conf.type === UI_ELE_TYPE.DELIMITER) {
13198
13379
  return;
13199
13380
  }
@@ -13265,7 +13446,7 @@ var init_toolbar_config = __esm({
13265
13446
  "aleph",
13266
13447
  "beth",
13267
13448
  "blacksquare"
13268
- ], configList = config[2].options.box.group[0].items;
13449
+ ], configList = baseToolbarConfig[2].options.box.group[0].items;
13269
13450
  configList.push({
13270
13451
  title: "\u57FA\u7840\u6570\u5B66",
13271
13452
  content: getUnicodeContents(list)
@@ -13281,7 +13462,7 @@ var init_toolbar_config = __esm({
13281
13462
  }, {
13282
13463
  title: "\u53D8\u4F53",
13283
13464
  values: ["digamma", "varepsilon", "varkappa", "varphi", "varpi", "varrho", "varsigma", "vartheta"]
13284
- }], greekConfigList = config[2].options.box.group[1].items;
13465
+ }], greekConfigList = baseToolbarConfig[2].options.box.group[1].items;
13285
13466
  greekConfigList.push({
13286
13467
  title: greekList[0].title,
13287
13468
  content: getUnicodeContents(greekList[0].values)
@@ -13330,7 +13511,7 @@ var init_toolbar_config = __esm({
13330
13511
  "nVDash",
13331
13512
  "nexists"
13332
13513
  ]
13333
- }], greekConfigList = config[2].options.box.group[2].items;
13514
+ }], greekConfigList = baseToolbarConfig[2].options.box.group[2].items;
13334
13515
  greekConfigList.push({
13335
13516
  title: greekList[0].title,
13336
13517
  content: getUnicodeContents(greekList[0].values)
@@ -13356,7 +13537,7 @@ var init_toolbar_config = __esm({
13356
13537
  "Game",
13357
13538
  "Im",
13358
13539
  "Re"
13359
- ], configList = config[2].options.box.group[3].items;
13540
+ ], configList = baseToolbarConfig[2].options.box.group[3].items;
13360
13541
  configList.push({
13361
13542
  title: "\u5B57\u6BCD\u7C7B\u7B26\u53F7",
13362
13543
  content: getUnicodeContents(list)
@@ -13424,7 +13605,7 @@ var init_toolbar_config = __esm({
13424
13605
  "twoheadleftarrow",
13425
13606
  "twoheadrightarrow",
13426
13607
  "rightsquigarrow"
13427
- ], configList = config[2].options.box.group[4].items;
13608
+ ], configList = baseToolbarConfig[2].options.box.group[4].items;
13428
13609
  configList.push({
13429
13610
  title: "\u7BAD\u5934",
13430
13611
  content: getUnicodeContents(list)
@@ -13603,7 +13784,7 @@ var init_toolbar_config = __esm({
13603
13784
  "y",
13604
13785
  "z"
13605
13786
  ]
13606
- }], configList = config[2].options.box.group[5].items;
13787
+ }], configList = baseToolbarConfig[2].options.box.group[5].items;
13607
13788
  each(list[0].values, function(item, index) {
13608
13789
  list[0].values[index] = "mathcal{" + item + "}";
13609
13790
  });
@@ -13633,7 +13814,7 @@ var init_toolbar_config = __esm({
13633
13814
  content: getUnicodeContents(list[3].values)
13634
13815
  });
13635
13816
  })();
13636
- toolbar_config_default = config;
13817
+ toolbar_config_default = createToolbarConfig;
13637
13818
  }
13638
13819
  });
13639
13820
 
@@ -13676,6 +13857,7 @@ var init_ui = __esm({
13676
13857
  init_toolbar();
13677
13858
  init_scrollbar();
13678
13859
  init_toolbar_config();
13860
+ init_i18n();
13679
13861
  $$8 = createLegacyUiUtils();
13680
13862
  VIEW_STATE = legacyUiDef.VIEW_STATE;
13681
13863
  DEFAULT_EDIT_AREA_HEIGHT = 100;
@@ -13706,7 +13888,8 @@ var init_ui = __esm({
13706
13888
  this.initScrollEvent();
13707
13889
  },
13708
13890
  initComponents() {
13709
- this.components.toolbar = new toolbar_default(this, this.kfEditor, toolbar_config_default);
13891
+ const toolbarConfig = toolbar_config_default(normalizeFormulaXLocale(this.options.locale));
13892
+ this.components.toolbar = new toolbar_default(this, this.kfEditor, toolbarConfig);
13710
13893
  this.components.scrollbar = new scrollbar_default(this, this.kfEditor);
13711
13894
  },
13712
13895
  updateContainerSize(container, toolbar, editArea) {
@@ -14973,6 +15156,21 @@ var init_syntax_move = __esm({
14973
15156
  });
14974
15157
 
14975
15158
  // src/legacy/syntax.ts
15159
+ function clampOffset(offset, maxOffset) {
15160
+ return Math.max(0, Math.min(offset, maxOffset));
15161
+ }
15162
+ function normalizeCursorRecord(objTree, cursor) {
15163
+ const fallbackGroupId = objTree.mapping.root.strGroup.attr.id;
15164
+ const targetGroupId = cursor.groupId && objTree.mapping[cursor.groupId] ? cursor.groupId : fallbackGroupId;
15165
+ const operandCount = objTree.mapping[targetGroupId].strGroup.operand.length;
15166
+ const startOffset = clampOffset(cursor.startOffset, operandCount);
15167
+ const endOffset = clampOffset(cursor.endOffset, operandCount);
15168
+ return {
15169
+ groupId: targetGroupId,
15170
+ startOffset: Math.min(startOffset, endOffset),
15171
+ endOffset: Math.max(startOffset, endOffset)
15172
+ };
15173
+ }
14976
15174
  var CURSOR_CHAR2, kity19, SyntaxComponent, syntax_default;
14977
15175
  var init_syntax = __esm({
14978
15176
  "src/legacy/syntax.ts"() {
@@ -15033,10 +15231,14 @@ var init_syntax = __esm({
15033
15231
  },
15034
15232
  updateObjTree(objTree) {
15035
15233
  const selectInfo = objTree.select;
15234
+ this.objTree = objTree;
15036
15235
  if (selectInfo?.groupId) {
15037
15236
  this.updateCursor(selectInfo.groupId, selectInfo.startOffset, selectInfo.endOffset);
15237
+ return;
15238
+ }
15239
+ if (this.record.cursor.groupId !== null) {
15240
+ this.record.cursor = normalizeCursorRecord(objTree, this.record.cursor);
15038
15241
  }
15039
- this.objTree = objTree;
15040
15242
  },
15041
15243
  hasCursorInfo() {
15042
15244
  return this.record.cursor.groupId !== null;
@@ -15082,7 +15284,8 @@ var init_syntax = __esm({
15082
15284
  return this.objTree;
15083
15285
  },
15084
15286
  getGroupObject(id) {
15085
- return this.objTree.mapping[id].objGroup || null;
15287
+ const groupInfo = this.objTree.mapping[id];
15288
+ return groupInfo ? groupInfo.objGroup : null;
15086
15289
  },
15087
15290
  getCursorRecord() {
15088
15291
  return kity19.Utils.extend({}, this.record.cursor);
@@ -15158,7 +15361,7 @@ var init_syntax = __esm({
15158
15361
  return this.hasRootplaceholder();
15159
15362
  },
15160
15363
  serialization() {
15161
- const cursor = this.record.cursor;
15364
+ const cursor = normalizeCursorRecord(this.objTree, this.record.cursor);
15162
15365
  const objGroup = this.objTree.mapping[cursor.groupId];
15163
15366
  const curStrGroup = objGroup.strGroup;
15164
15367
  let strStartIndex = Math.min(cursor.endOffset, cursor.startOffset);
@@ -15194,11 +15397,12 @@ var init_syntax = __esm({
15194
15397
  endOffset = startOffset;
15195
15398
  startOffset = tmp;
15196
15399
  }
15197
- this.record.cursor = {
15400
+ const nextCursor = {
15198
15401
  groupId,
15199
15402
  startOffset,
15200
15403
  endOffset
15201
15404
  };
15405
+ this.record.cursor = this.objTree ? normalizeCursorRecord(this.objTree, nextCursor) : nextCursor;
15202
15406
  },
15203
15407
  leftMove() {
15204
15408
  this.components.move.leftMove();
@@ -15239,12 +15443,20 @@ var init_syntax = __esm({
15239
15443
  });
15240
15444
 
15241
15445
  // src/legacy/input.ts
15242
- var KEY_CODE, kity20, InputComponent, input_default;
15446
+ function insertCursorMarkers(value, selectionStart, selectionEnd) {
15447
+ const normalizedStart = Math.max(0, Math.min(selectionStart ?? value.length, value.length));
15448
+ const normalizedEnd = Math.max(0, Math.min(selectionEnd ?? normalizedStart, value.length));
15449
+ const rangeStart = Math.min(normalizedStart, normalizedEnd);
15450
+ const rangeEnd = Math.max(normalizedStart, normalizedEnd);
15451
+ return value.slice(0, rangeStart) + CURSOR_CHAR3 + value.slice(rangeStart, rangeEnd) + CURSOR_CHAR3 + value.slice(rangeEnd);
15452
+ }
15453
+ var KEY_CODE, CURSOR_CHAR3, kity20, InputComponent, input_default;
15243
15454
  var init_input = __esm({
15244
15455
  "src/legacy/input.ts"() {
15245
15456
  "use strict";
15246
15457
  init_legacy_utils();
15247
15458
  init_legacy_input_filter();
15459
+ init_legacy_sysconf();
15248
15460
  init_runtime_interop();
15249
15461
  KEY_CODE = {
15250
15462
  LEFT: 37,
@@ -15252,6 +15464,7 @@ var init_input = __esm({
15252
15464
  DELETE: 8,
15253
15465
  INPUT: 229
15254
15466
  };
15467
+ CURSOR_CHAR3 = legacySysconf.cursorCharacter;
15255
15468
  kity20 = getLegacyKity();
15256
15469
  InputComponent = kity20.createClass("InputComponent", {
15257
15470
  constructor(parentComponent, kfEditor) {
@@ -15424,7 +15637,12 @@ var init_input = __esm({
15424
15637
  return `${e.shiftKey ? "s+" : ""}${e.keyCode}`;
15425
15638
  },
15426
15639
  processingInput() {
15427
- this.restruct(this.inputBox.value);
15640
+ const latexWithCursor = insertCursorMarkers(
15641
+ this.inputBox.value,
15642
+ this.inputBox.selectionStart,
15643
+ this.inputBox.selectionEnd
15644
+ );
15645
+ this.restruct(latexWithCursor);
15428
15646
  this.kfEditor.requestService("ui.update.canvas.view");
15429
15647
  },
15430
15648
  restruct(latexStr) {
@@ -15957,7 +16175,7 @@ var installed3, start_default;
15957
16175
  var init_start = __esm({
15958
16176
  "src/boot/start.ts"() {
15959
16177
  "use strict";
15960
- init_editor();
16178
+ init_editor2();
15961
16179
  init_factory();
15962
16180
  init_ui();
15963
16181
  init_parser();
@@ -15974,6 +16192,8 @@ var init_start = __esm({
15974
16192
  // src/index.ts
15975
16193
  var index_exports = {};
15976
16194
  __export(index_exports, {
16195
+ DEFAULT_FORMULAX_LOCALE: () => DEFAULT_FORMULAX_LOCALE,
16196
+ FORMULAX_LOCALES: () => FORMULAX_LOCALES,
15977
16197
  FormulaXEditor: () => FormulaXEditor,
15978
16198
  addEvent: () => addEvent,
15979
16199
  createElement: () => createElement,
@@ -16001,59 +16221,18 @@ __export(index_exports, {
16001
16221
  legacyKfExtDef: () => legacyKfExtDef,
16002
16222
  legacySysconf: () => legacySysconf,
16003
16223
  legacyUiDef: () => legacyUiDef,
16224
+ legacyUiUtils: () => legacyUiUtils,
16004
16225
  mountKityEditor: () => mountKityEditor,
16226
+ normalizeFormulaXLocale: () => normalizeFormulaXLocale,
16005
16227
  normalizeMouseEvent: () => normalizeMouseEvent,
16006
16228
  publish: () => publish,
16007
16229
  subscribe: () => subscribe
16008
16230
  });
16009
16231
  module.exports = __toCommonJS(index_exports);
16010
-
16011
- // public/assets/images/toolbar/btn.png
16012
- var btn_default = "./btn-5DANP6JY.png";
16013
-
16014
- // public/assets/images/toolbar/other.png
16015
- var other_default = "./other-OMWJFGL5.png";
16016
-
16017
- // public/assets/styles/editor.css?url
16018
- var editor_default = "./editor-JT5KLVXX.css?url";
16019
-
16020
- // public/resource/KF_AMS_BB.woff
16021
- var KF_AMS_BB_default = "./KF_AMS_BB-5QF7FUSO.woff";
16022
-
16023
- // public/resource/KF_AMS_CAL.woff
16024
- var KF_AMS_CAL_default = "./KF_AMS_CAL-NXRNLAZN.woff";
16025
-
16026
- // public/resource/KF_AMS_FRAK.woff
16027
- var KF_AMS_FRAK_default = "./KF_AMS_FRAK-CO33WWN4.woff";
16028
-
16029
- // public/resource/KF_AMS_MAIN.woff
16030
- var KF_AMS_MAIN_default = "./KF_AMS_MAIN-25QJVAWY.woff";
16031
-
16032
- // public/resource/KF_AMS_ROMAN.woff
16033
- var KF_AMS_ROMAN_default = "./KF_AMS_ROMAN-243BR7HH.woff";
16034
-
16035
- // src/asset-manifest.ts
16036
- var kityFontAssets = {
16037
- KF_AMS_BB: KF_AMS_BB_default,
16038
- KF_AMS_CAL: KF_AMS_CAL_default,
16039
- KF_AMS_FRAK: KF_AMS_FRAK_default,
16040
- KF_AMS_MAIN: KF_AMS_MAIN_default,
16041
- KF_AMS_ROMAN: KF_AMS_ROMAN_default
16042
- };
16043
- var kityToolbarAssets = {
16044
- btn: btn_default,
16045
- other: other_default
16046
- };
16047
- var kityStyleAssets = {
16048
- editor: editor_default
16049
- };
16050
- var kityAssetManifest = {
16051
- fonts: kityFontAssets,
16052
- toolbar: kityToolbarAssets,
16053
- styles: kityStyleAssets
16054
- };
16232
+ init_asset_manifest();
16055
16233
 
16056
16234
  // src/create-editor.ts
16235
+ init_asset_manifest();
16057
16236
  init_legacy_box_type();
16058
16237
 
16059
16238
  // src/vendor/char-position.ts
@@ -19456,8 +19635,83 @@ function installKityRuntime(targetWindow = window) {
19456
19635
  targetWindow.kity = kity;
19457
19636
  }
19458
19637
 
19638
+ // src/perf.ts
19639
+ function getPerfHost() {
19640
+ return globalThis;
19641
+ }
19642
+ function getPerfState() {
19643
+ const host = getPerfHost();
19644
+ host.__FORMULAX_PERF_STATE__ ??= {
19645
+ reportedMeasureCount: 0,
19646
+ reportScheduled: false
19647
+ };
19648
+ return host.__FORMULAX_PERF_STATE__;
19649
+ }
19650
+ function hasPerfSupport() {
19651
+ return typeof performance !== "undefined" && typeof performance.mark === "function" && typeof performance.measure === "function" && typeof performance.getEntriesByType === "function";
19652
+ }
19653
+ function isPerfDebugEnabled() {
19654
+ return getPerfHost().__FORMULAX_PERF__ === true;
19655
+ }
19656
+ function schedulePerfReport() {
19657
+ if (!hasPerfSupport() || !isPerfDebugEnabled()) {
19658
+ return;
19659
+ }
19660
+ const state = getPerfState();
19661
+ if (state.reportScheduled) {
19662
+ return;
19663
+ }
19664
+ state.reportScheduled = true;
19665
+ queueMicrotask(() => {
19666
+ state.reportScheduled = false;
19667
+ const entries = performance.getEntriesByType("measure").filter((entry) => entry.name.startsWith("fx:")).sort((left, right) => left.startTime - right.startTime);
19668
+ const nextEntries = entries.slice(state.reportedMeasureCount);
19669
+ state.reportedMeasureCount = entries.length;
19670
+ if (!nextEntries.length) {
19671
+ return;
19672
+ }
19673
+ console.table(nextEntries.map((entry) => ({
19674
+ name: entry.name,
19675
+ duration: Number(entry.duration.toFixed(2)),
19676
+ startTime: Number(entry.startTime.toFixed(2))
19677
+ })));
19678
+ });
19679
+ }
19680
+ function markFormulaXPerf(name) {
19681
+ if (!hasPerfSupport()) {
19682
+ return null;
19683
+ }
19684
+ const markName = `${name}::${Date.now()}::${Math.random().toString(36).slice(2, 8)}`;
19685
+ performance.mark(markName);
19686
+ return markName;
19687
+ }
19688
+ function measureFormulaXPerf(name, startMark, endMark) {
19689
+ if (!hasPerfSupport() || !startMark) {
19690
+ return null;
19691
+ }
19692
+ const resolvedEndMark = endMark ?? markFormulaXPerf(`${name}:end`);
19693
+ if (!resolvedEndMark) {
19694
+ return null;
19695
+ }
19696
+ performance.measure(name, startMark, resolvedEndMark);
19697
+ schedulePerfReport();
19698
+ return resolvedEndMark;
19699
+ }
19700
+ function clearFormulaXPerfMarks(...marks) {
19701
+ if (!hasPerfSupport()) {
19702
+ return;
19703
+ }
19704
+ for (const mark of marks) {
19705
+ if (!mark) {
19706
+ continue;
19707
+ }
19708
+ performance.clearMarks(mark);
19709
+ }
19710
+ }
19711
+
19459
19712
  // src/create-editor.ts
19460
19713
  init_toolbar_assets();
19714
+ init_i18n();
19461
19715
  var DEFAULT_LATEX = "x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}";
19462
19716
  var DEFAULT_EDITOR_HEIGHT = "auto";
19463
19717
  var KITY_STYLE_ID = "formulax-kity-editor-styles";
@@ -19496,13 +19750,14 @@ function resolveEditorAssets(assets) {
19496
19750
  }
19497
19751
  function ensureKityStylesheet(doc, href) {
19498
19752
  if (doc.getElementById(KITY_STYLE_ID)) {
19499
- return;
19753
+ return false;
19500
19754
  }
19501
19755
  const link = doc.createElement("link");
19502
19756
  link.id = KITY_STYLE_ID;
19503
19757
  link.rel = "stylesheet";
19504
19758
  link.href = href;
19505
19759
  doc.head.appendChild(link);
19760
+ return true;
19506
19761
  }
19507
19762
  function hydrateLegacyKf(runtimeWindow) {
19508
19763
  const requireFormula = runtimeWindow.__kityFormulaRequire__;
@@ -19550,7 +19805,7 @@ function installLegacyRuntime(runtimeWindow) {
19550
19805
  kity: runtimeWindow.kity,
19551
19806
  otherPosition: legacyOtherPosition,
19552
19807
  uiDef: legacyUiDef,
19553
- uiUtils: createLegacyUiUtils()
19808
+ uiUtils: legacyUiUtils
19554
19809
  };
19555
19810
  }
19556
19811
  async function ensureKityRuntime() {
@@ -19558,64 +19813,118 @@ async function ensureKityRuntime() {
19558
19813
  return runtimePromise;
19559
19814
  }
19560
19815
  runtimePromise = (async () => {
19816
+ const runtimeTotalStart = markFormulaXPerf("fx:kity-runtime:total");
19561
19817
  const runtimeWindow = window;
19562
19818
  runtimeWindow.kf = runtimeWindow.kf ?? {};
19563
19819
  installKityRuntime(runtimeWindow);
19564
- const { installLegacyKityFormulaRuntime: installLegacyKityFormulaRuntime2 } = await Promise.resolve().then(() => (init_install(), install_exports));
19565
- installLegacyKityFormulaRuntime2(runtimeWindow);
19566
- hydrateLegacyKf(runtimeWindow);
19567
- const { installLegacyParserRuntime: installLegacyParserRuntime2 } = await Promise.resolve().then(() => (init_install2(), install_exports2));
19568
- installLegacyParserRuntime2(runtimeWindow);
19569
- installLegacyRuntime(runtimeWindow);
19570
- const { installKityEditorStart: installKityEditorStart2 } = await Promise.resolve().then(() => (init_start(), start_exports));
19571
- installKityEditorStart2(runtimeWindow);
19820
+ try {
19821
+ const formulaImportStart = markFormulaXPerf("fx:kity-runtime:formula-import");
19822
+ const { installLegacyKityFormulaRuntime: installLegacyKityFormulaRuntime2 } = await Promise.resolve().then(() => (init_install(), install_exports));
19823
+ const formulaImportEnd = markFormulaXPerf("fx:kity-runtime:formula-import:end");
19824
+ measureFormulaXPerf("fx:kity-runtime:formula-import", formulaImportStart, formulaImportEnd);
19825
+ clearFormulaXPerfMarks(formulaImportStart, formulaImportEnd);
19826
+ const formulaInstallStart = markFormulaXPerf("fx:kity-runtime:formula-install");
19827
+ installLegacyKityFormulaRuntime2(runtimeWindow);
19828
+ hydrateLegacyKf(runtimeWindow);
19829
+ const formulaInstallEnd = markFormulaXPerf("fx:kity-runtime:formula-install:end");
19830
+ measureFormulaXPerf("fx:kity-runtime:formula-install", formulaInstallStart, formulaInstallEnd);
19831
+ clearFormulaXPerfMarks(formulaInstallStart, formulaInstallEnd);
19832
+ const parserImportStart = markFormulaXPerf("fx:kity-runtime:parser-import");
19833
+ const { installLegacyParserRuntime: installLegacyParserRuntime2 } = await Promise.resolve().then(() => (init_install2(), install_exports2));
19834
+ const parserImportEnd = markFormulaXPerf("fx:kity-runtime:parser-import:end");
19835
+ measureFormulaXPerf("fx:kity-runtime:parser-import", parserImportStart, parserImportEnd);
19836
+ clearFormulaXPerfMarks(parserImportStart, parserImportEnd);
19837
+ const parserInstallStart = markFormulaXPerf("fx:kity-runtime:parser-install");
19838
+ installLegacyParserRuntime2(runtimeWindow);
19839
+ const parserInstallEnd = markFormulaXPerf("fx:kity-runtime:parser-install:end");
19840
+ measureFormulaXPerf("fx:kity-runtime:parser-install", parserInstallStart, parserInstallEnd);
19841
+ clearFormulaXPerfMarks(parserInstallStart, parserInstallEnd);
19842
+ installLegacyRuntime(runtimeWindow);
19843
+ const bootImportStart = markFormulaXPerf("fx:kity-runtime:boot-import");
19844
+ const { installKityEditorStart: installKityEditorStart2 } = await Promise.resolve().then(() => (init_start(), start_exports));
19845
+ const bootImportEnd = markFormulaXPerf("fx:kity-runtime:boot-import:end");
19846
+ measureFormulaXPerf("fx:kity-runtime:boot-import", bootImportStart, bootImportEnd);
19847
+ clearFormulaXPerfMarks(bootImportStart, bootImportEnd);
19848
+ const bootInstallStart = markFormulaXPerf("fx:kity-runtime:boot-install");
19849
+ installKityEditorStart2(runtimeWindow);
19850
+ const bootInstallEnd = markFormulaXPerf("fx:kity-runtime:boot-install:end");
19851
+ measureFormulaXPerf("fx:kity-runtime:boot-install", bootInstallStart, bootInstallEnd);
19852
+ clearFormulaXPerfMarks(bootInstallStart, bootInstallEnd);
19853
+ } finally {
19854
+ const runtimeTotalEnd = markFormulaXPerf("fx:kity-runtime:total:end");
19855
+ measureFormulaXPerf("fx:kity-runtime:total", runtimeTotalStart, runtimeTotalEnd);
19856
+ clearFormulaXPerfMarks(runtimeTotalStart, runtimeTotalEnd);
19857
+ }
19572
19858
  })();
19573
19859
  return runtimePromise;
19574
19860
  }
19575
19861
  async function createKityEditor(container, options = {}) {
19862
+ const createEditorStart = markFormulaXPerf("fx:create-kity-editor:total");
19576
19863
  const fontsize = options.render?.fontsize ?? 40;
19577
19864
  const editorHeight = normalizeCssSize(options.height, DEFAULT_EDITOR_HEIGHT);
19865
+ const locale = normalizeFormulaXLocale(options.locale ?? DEFAULT_FORMULAX_LOCALE);
19578
19866
  const assets = resolveEditorAssets(options.assets);
19579
- ensureKityStylesheet(document, assets.styles.editor);
19580
- setToolbarAssetUrls(assets.toolbar);
19581
- await ensureKityRuntime();
19582
- const runtimeWindow = window;
19583
- if (!runtimeWindow.kf?.EditorFactory) {
19584
- throw new Error("Kity editor runtime did not initialize");
19585
- }
19586
- container.innerHTML = "";
19587
- const host = document.createElement("div");
19588
- host.className = "kf-editor";
19589
- host.style.width = "100%";
19590
- host.style.height = editorHeight;
19591
- container.appendChild(host);
19592
- const factory2 = runtimeWindow.kf.EditorFactory.create(host, {
19593
- render: {
19594
- fontsize
19595
- },
19596
- resource: {
19597
- path: "",
19598
- fonts: assets.fonts
19867
+ try {
19868
+ const stylesheetInserted = ensureKityStylesheet(document, assets.styles.editor);
19869
+ if (stylesheetInserted) {
19870
+ const stylesheetInsertedMark = markFormulaXPerf("fx:kity-css:link-inserted");
19871
+ measureFormulaXPerf("fx:kity-css:link-inserted", createEditorStart, stylesheetInsertedMark);
19872
+ clearFormulaXPerfMarks(stylesheetInsertedMark);
19599
19873
  }
19600
- });
19601
- return {
19602
- ready: factory2.ready.bind(factory2),
19603
- execCommand(name, value) {
19604
- factory2.ready(function execWhenReady() {
19605
- this.execCommand(name, value);
19606
- });
19607
- },
19608
- focus() {
19609
- factory2.ready(function focusWhenReady() {
19610
- this.execCommand("focus");
19611
- });
19612
- },
19613
- destroy() {
19614
- container.innerHTML = "";
19615
- },
19616
- host,
19617
- raw: factory2
19618
- };
19874
+ setToolbarAssetUrls(assets.toolbar);
19875
+ await ensureKityRuntime();
19876
+ const runtimeReadyMark = markFormulaXPerf("fx:kity-runtime:ready-for-editor");
19877
+ measureFormulaXPerf("fx:kity-runtime:ready-for-editor", createEditorStart, runtimeReadyMark);
19878
+ clearFormulaXPerfMarks(runtimeReadyMark);
19879
+ const runtimeWindow = window;
19880
+ if (!runtimeWindow.kf?.EditorFactory) {
19881
+ throw new Error("Kity editor runtime did not initialize");
19882
+ }
19883
+ container.innerHTML = "";
19884
+ const host = document.createElement("div");
19885
+ host.className = "kf-editor";
19886
+ host.style.width = "100%";
19887
+ host.style.height = editorHeight;
19888
+ container.appendChild(host);
19889
+ const factoryCreateStart = markFormulaXPerf("fx:kity-editor-factory:create");
19890
+ const factory2 = runtimeWindow.kf.EditorFactory.create(host, {
19891
+ render: {
19892
+ fontsize
19893
+ },
19894
+ ui: {
19895
+ locale
19896
+ },
19897
+ resource: {
19898
+ path: "",
19899
+ fonts: assets.fonts
19900
+ }
19901
+ });
19902
+ const factoryCreateEnd = markFormulaXPerf("fx:kity-editor-factory:create:end");
19903
+ measureFormulaXPerf("fx:kity-editor-factory:create", factoryCreateStart, factoryCreateEnd);
19904
+ clearFormulaXPerfMarks(factoryCreateStart, factoryCreateEnd);
19905
+ return {
19906
+ ready: factory2.ready.bind(factory2),
19907
+ execCommand(name, value) {
19908
+ factory2.ready(function execWhenReady() {
19909
+ this.execCommand(name, value);
19910
+ });
19911
+ },
19912
+ focus() {
19913
+ factory2.ready(function focusWhenReady() {
19914
+ this.execCommand("focus");
19915
+ });
19916
+ },
19917
+ destroy() {
19918
+ container.innerHTML = "";
19919
+ },
19920
+ host,
19921
+ raw: factory2
19922
+ };
19923
+ } finally {
19924
+ const createEditorEnd = markFormulaXPerf("fx:create-kity-editor:total:end");
19925
+ measureFormulaXPerf("fx:create-kity-editor:total", createEditorStart, createEditorEnd);
19926
+ clearFormulaXPerfMarks(createEditorStart, createEditorEnd);
19927
+ }
19619
19928
  }
19620
19929
  async function mountKityEditor(container, options = {}) {
19621
19930
  const editor = await createKityEditor(container, options);
@@ -19667,6 +19976,7 @@ if (typeof window !== "undefined") {
19667
19976
 
19668
19977
  // src/index.ts
19669
19978
  init_dom_utils();
19979
+ init_i18n();
19670
19980
  init_legacy_box_type();
19671
19981
  init_legacy_component();
19672
19982
  init_legacy_ele_type();
@@ -19693,6 +20003,8 @@ init_legacy_ui_utils();
19693
20003
  init_legacy_utils();
19694
20004
  // Annotate the CommonJS export names for ESM import in node:
19695
20005
  0 && (module.exports = {
20006
+ DEFAULT_FORMULAX_LOCALE,
20007
+ FORMULAX_LOCALES,
19696
20008
  FormulaXEditor,
19697
20009
  addEvent,
19698
20010
  createElement,
@@ -19720,7 +20032,9 @@ init_legacy_utils();
19720
20032
  legacyKfExtDef,
19721
20033
  legacySysconf,
19722
20034
  legacyUiDef,
20035
+ legacyUiUtils,
19723
20036
  mountKityEditor,
20037
+ normalizeFormulaXLocale,
19724
20038
  normalizeMouseEvent,
19725
20039
  publish,
19726
20040
  subscribe