@formulaxjs/kity-runtime 0.3.0 → 0.5.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.
Files changed (46) hide show
  1. package/README.md +33 -30
  2. package/README.zh-CN.md +44 -0
  3. package/dist/base.css +47 -0
  4. package/dist/{chunk-AOMNUFFB.js → chunk-EQCAHDH7.js} +98 -34
  5. package/dist/chunk-EQCAHDH7.js.map +1 -0
  6. package/dist/images/scrollbar/custom/bar-bg.png +0 -0
  7. package/dist/images/scrollbar/custom/bar.png +0 -0
  8. package/dist/images/scrollbar/custom/bg.png +0 -0
  9. package/dist/images/scrollbar/custom/bottom.png +0 -0
  10. package/dist/images/scrollbar/custom/btn.png +0 -0
  11. package/dist/images/scrollbar/custom/down.png +0 -0
  12. package/dist/images/scrollbar/custom/top.png +0 -0
  13. package/dist/images/scrollbar/custom/up.png +0 -0
  14. package/dist/images/scrollbar/edit/bar-bg.png +0 -0
  15. package/dist/images/scrollbar/edit/bar-left.png +0 -0
  16. package/dist/images/scrollbar/edit/bar-right.png +0 -0
  17. package/dist/images/scrollbar/edit/thumb-bg.png +0 -0
  18. package/dist/images/scrollbar/edit/thumb-left.png +0 -0
  19. package/dist/images/scrollbar/edit/thumb-right.png +0 -0
  20. package/dist/images/toolbar/btn.png +0 -0
  21. package/dist/index.cjs +270 -186
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.global.js +270 -185
  24. package/dist/index.global.js.map +1 -1
  25. package/dist/index.js +19 -4
  26. package/dist/index.js.map +1 -1
  27. package/dist/{install-TIZBWEFU.js → install-WDCVVIMM.js} +34 -61
  28. package/dist/install-WDCVVIMM.js.map +1 -0
  29. package/dist/other.png +0 -0
  30. package/dist/scrollbar.css +78 -0
  31. package/dist/{start-LTYA5XON.js → start-N66J24A5.js} +88 -21
  32. package/dist/start-N66J24A5.js.map +1 -0
  33. package/dist/ui.css +625 -0
  34. package/package.json +7 -2
  35. package/public/assets/styles/ui.css +58 -26
  36. package/dist/chunk-AOMNUFFB.js.map +0 -1
  37. package/dist/install-TIZBWEFU.js.map +0 -1
  38. package/dist/start-LTYA5XON.js.map +0 -1
  39. /package/dist/{KF_AMS_BB-5QF7FUSO.woff → KF_AMS_BB.woff} +0 -0
  40. /package/dist/{KF_AMS_CAL-NXRNLAZN.woff → KF_AMS_CAL.woff} +0 -0
  41. /package/dist/{KF_AMS_FRAK-CO33WWN4.woff → KF_AMS_FRAK.woff} +0 -0
  42. /package/dist/{KF_AMS_MAIN-25QJVAWY.woff → KF_AMS_MAIN.woff} +0 -0
  43. /package/dist/{KF_AMS_ROMAN-243BR7HH.woff → KF_AMS_ROMAN.woff} +0 -0
  44. /package/dist/{btn-5DANP6JY.png → btn.png} +0 -0
  45. /package/dist/{editor-JT5KLVXX.css → editor.css} +0 -0
  46. /package/dist/{other-OMWJFGL5.png → images/toolbar/other.png} +0 -0
package/dist/other.png ADDED
Binary file
@@ -0,0 +1,78 @@
1
+ /*!
2
+ * Scrollbar
3
+ **/
4
+
5
+ .kf-editor-edit-scrollbar {
6
+ width: 100%;
7
+ height: 16px;
8
+ position: absolute;
9
+ bottom: 0;
10
+ left: 0;
11
+ z-index: 994;
12
+ border-top: 1px solid #ddd;
13
+ }
14
+
15
+ .kf-editor-ui-left-button {
16
+ position: absolute;
17
+ top: 0;
18
+ left: 0;
19
+ width: 5px;
20
+ height: 100%;
21
+ background: white;
22
+ }
23
+
24
+ .kf-editor-ui-right-button {
25
+ position: absolute;
26
+ top: 0;
27
+ right: 0;
28
+ width: 5px;
29
+ height: 100%;
30
+ background: white;
31
+ }
32
+
33
+ .kf-editor-ui-track {
34
+ position: absolute;
35
+ top: 0;
36
+ left: 5px;
37
+ width: 0;
38
+ height: 100%;
39
+ background-image: url(./images/scrollbar/edit/bar-left.png), url(./images/scrollbar/edit/bar-right.png), url(./images/scrollbar/edit/bar-bg.png);
40
+ background-repeat: no-repeat, no-repeat, repeat-x;
41
+ background-position: 0 0, right 0, 0 0;
42
+ }
43
+
44
+ .kf-editor-ui-thumb {
45
+ position: absolute;
46
+ top: 0;
47
+ left: 0;
48
+ width: 0;
49
+ height: 100%;
50
+ }
51
+
52
+ .kf-editor-ui-thumb-left {
53
+ width: 5px;
54
+ height: 100%;
55
+ position: absolute;
56
+ top: 0;
57
+ left: 0;
58
+ background: url(./images/scrollbar/edit/thumb-left.png) no-repeat 0 0;
59
+ z-index: 1;
60
+ }
61
+
62
+ .kf-editor-ui-thumb-right {
63
+ width: 5px;
64
+ height: 100%;
65
+ position: absolute;
66
+ top: 0;
67
+ right: 0;
68
+ background: url(./images/scrollbar/edit/thumb-right.png) no-repeat 0 0;
69
+ }
70
+
71
+ .kf-editor-ui-thumb-body {
72
+ position: absolute;
73
+ top: 0;
74
+ left: 5px;
75
+ width: 0;
76
+ height: 100%;
77
+ background: url(./images/scrollbar/edit/thumb-bg.png) repeat-x 0 0;
78
+ }
@@ -1,4 +1,5 @@
1
1
  import {
2
+ DEFAULT_FORMULAX_LOCALE,
2
3
  createLegacyBaseComponent,
3
4
  createLegacyUiUtils,
4
5
  legacyBaseUtils,
@@ -11,8 +12,10 @@ import {
11
12
  legacyOtherPosition,
12
13
  legacySysconf,
13
14
  legacyUiDef,
14
- resolveToolbarAssetPath
15
- } from "./chunk-AOMNUFFB.js";
15
+ normalizeFormulaXLocale,
16
+ resolveToolbarAssetPath,
17
+ translateFormulaXText
18
+ } from "./chunk-EQCAHDH7.js";
16
19
 
17
20
  // src/vendor/runtime-interop.ts
18
21
  function getLegacyRuntime() {
@@ -1618,6 +1621,7 @@ var UNICODE_SYMBOLS = {
1618
1621
  to: "\u2192",
1619
1622
  downarrow: "\u2193",
1620
1623
  leftrightarrow: "\u2194",
1624
+ updownarrow: "\u2195",
1621
1625
  therefore: "\u2234",
1622
1626
  because: "\u2235",
1623
1627
  "+": "+",
@@ -1734,7 +1738,7 @@ var UNICODE_SYMBOLS = {
1734
1738
  Uparrow: "\u21D1",
1735
1739
  Downarrow: "\u21D3",
1736
1740
  Leftrightarrow: "\u21D4",
1737
- Updownarrow: "\u21F3",
1741
+ Updownarrow: "\u21D5",
1738
1742
  longleftarrow: "\u27F5",
1739
1743
  longrightarrow: "\u27F6",
1740
1744
  longleftrightarrow: "\u27F7",
@@ -1820,7 +1824,27 @@ function each(list, callback) {
1820
1824
  }
1821
1825
  Object.keys(list).forEach((key) => callback(list[key], key));
1822
1826
  }
1823
- var config = [{
1827
+ function translateToolbarText(value, locale) {
1828
+ return translateFormulaXText("toolbar", value, locale);
1829
+ }
1830
+ function localizeToolbarConfig(value, locale) {
1831
+ if (Array.isArray(value)) {
1832
+ return value.map((item) => localizeToolbarConfig(item, locale));
1833
+ }
1834
+ if (!value || typeof value !== "object") {
1835
+ return value;
1836
+ }
1837
+ const result = {};
1838
+ for (const [key, currentValue] of Object.entries(value)) {
1839
+ if ((key === "label" || key === "title") && typeof currentValue === "string") {
1840
+ result[key] = translateToolbarText(currentValue, locale);
1841
+ continue;
1842
+ }
1843
+ result[key] = localizeToolbarConfig(currentValue, locale);
1844
+ }
1845
+ return result;
1846
+ }
1847
+ var baseToolbarConfig = [{
1824
1848
  type: UI_ELE_TYPE.DRAPDOWN_BOX,
1825
1849
  options: {
1826
1850
  button: {
@@ -2226,7 +2250,7 @@ var config = [{
2226
2250
  }];
2227
2251
  (function() {
2228
2252
  let tmp = [], otherImageSrc = resolveToolbarAssetPath("other.png"), currentConf = [];
2229
- each(config, function(conf) {
2253
+ each(baseToolbarConfig, function(conf) {
2230
2254
  if (conf.type === UI_ELE_TYPE.DELIMITER) {
2231
2255
  return;
2232
2256
  }
@@ -2298,7 +2322,7 @@ var config = [{
2298
2322
  "aleph",
2299
2323
  "beth",
2300
2324
  "blacksquare"
2301
- ], configList = config[2].options.box.group[0].items;
2325
+ ], configList = baseToolbarConfig[2].options.box.group[0].items;
2302
2326
  configList.push({
2303
2327
  title: "\u57FA\u7840\u6570\u5B66",
2304
2328
  content: getUnicodeContents(list)
@@ -2314,7 +2338,7 @@ var config = [{
2314
2338
  }, {
2315
2339
  title: "\u53D8\u4F53",
2316
2340
  values: ["digamma", "varepsilon", "varkappa", "varphi", "varpi", "varrho", "varsigma", "vartheta"]
2317
- }], greekConfigList = config[2].options.box.group[1].items;
2341
+ }], greekConfigList = baseToolbarConfig[2].options.box.group[1].items;
2318
2342
  greekConfigList.push({
2319
2343
  title: greekList[0].title,
2320
2344
  content: getUnicodeContents(greekList[0].values)
@@ -2363,7 +2387,7 @@ var config = [{
2363
2387
  "nVDash",
2364
2388
  "nexists"
2365
2389
  ]
2366
- }], greekConfigList = config[2].options.box.group[2].items;
2390
+ }], greekConfigList = baseToolbarConfig[2].options.box.group[2].items;
2367
2391
  greekConfigList.push({
2368
2392
  title: greekList[0].title,
2369
2393
  content: getUnicodeContents(greekList[0].values)
@@ -2389,7 +2413,7 @@ var config = [{
2389
2413
  "Game",
2390
2414
  "Im",
2391
2415
  "Re"
2392
- ], configList = config[2].options.box.group[3].items;
2416
+ ], configList = baseToolbarConfig[2].options.box.group[3].items;
2393
2417
  configList.push({
2394
2418
  title: "\u5B57\u6BCD\u7C7B\u7B26\u53F7",
2395
2419
  content: getUnicodeContents(list)
@@ -2457,7 +2481,7 @@ var config = [{
2457
2481
  "twoheadleftarrow",
2458
2482
  "twoheadrightarrow",
2459
2483
  "rightsquigarrow"
2460
- ], configList = config[2].options.box.group[4].items;
2484
+ ], configList = baseToolbarConfig[2].options.box.group[4].items;
2461
2485
  configList.push({
2462
2486
  title: "\u7BAD\u5934",
2463
2487
  content: getUnicodeContents(list)
@@ -2636,7 +2660,7 @@ var config = [{
2636
2660
  "y",
2637
2661
  "z"
2638
2662
  ]
2639
- }], configList = config[2].options.box.group[5].items;
2663
+ }], configList = baseToolbarConfig[2].options.box.group[5].items;
2640
2664
  each(list[0].values, function(item, index) {
2641
2665
  list[0].values[index] = "mathcal{" + item + "}";
2642
2666
  });
@@ -2685,7 +2709,13 @@ function getUnicodeContents(keySet) {
2685
2709
  });
2686
2710
  return result;
2687
2711
  }
2688
- var toolbar_config_default = config;
2712
+ function createToolbarConfig(locale = DEFAULT_FORMULAX_LOCALE) {
2713
+ return localizeToolbarConfig(
2714
+ baseToolbarConfig,
2715
+ normalizeFormulaXLocale(locale)
2716
+ );
2717
+ }
2718
+ var toolbar_config_default = createToolbarConfig;
2689
2719
 
2690
2720
  // src/legacy/ui.ts
2691
2721
  var $$8 = createLegacyUiUtils();
@@ -2718,7 +2748,8 @@ var UIComponent = kity10.createClass("UIComponent", {
2718
2748
  this.initScrollEvent();
2719
2749
  },
2720
2750
  initComponents() {
2721
- this.components.toolbar = new toolbar_default(this, this.kfEditor, toolbar_config_default);
2751
+ const toolbarConfig = toolbar_config_default(normalizeFormulaXLocale(this.options.locale));
2752
+ this.components.toolbar = new toolbar_default(this, this.kfEditor, toolbarConfig);
2722
2753
  this.components.scrollbar = new scrollbar_default(this, this.kfEditor);
2723
2754
  },
2724
2755
  updateContainerSize(container, toolbar, editArea) {
@@ -2986,7 +3017,6 @@ var vgroup_def_default = legacyVirtualGroupMap;
2986
3017
 
2987
3018
  // src/legacy/parser.ts
2988
3019
  var CURSOR_CHAR = legacySysconf.cursorCharacter;
2989
- var ROOT_P_TEXT = legacySysconf.rootPlaceholder.content;
2990
3020
  var COMBINATION_NAME = "combination";
2991
3021
  var PID_PREFIX = "_kf_editor_";
2992
3022
  var pidSeed = 0;
@@ -3028,6 +3058,9 @@ function createGroup(parser) {
3028
3058
  operand: []
3029
3059
  };
3030
3060
  }
3061
+ function getRootPlaceholderText() {
3062
+ return legacySysconf.rootPlaceholder.content;
3063
+ }
3031
3064
  function processRootGroup(parser, tree) {
3032
3065
  if (!parser.isResetId) {
3033
3066
  tree.attr["data-type"] = legacyGroupType.VIRTUAL;
@@ -3075,7 +3108,7 @@ function supplementTree(parser, tree, parentTree) {
3075
3108
  if (isRoot) {
3076
3109
  processRootGroup(parser, tree);
3077
3110
  } else if (parentTree?.attr?.["data-root"] && tree.name === "placeholder" && onlyPlaceholder(parentTree.operand)) {
3078
- tree.attr.label = ROOT_P_TEXT;
3111
+ tree.attr.label = getRootPlaceholderText();
3079
3112
  }
3080
3113
  for (let i = 0; i < tree.operand.length; i += 1) {
3081
3114
  const currentOperand = tree.operand[i];
@@ -3938,6 +3971,21 @@ var syntax_move_default = MoveComponent;
3938
3971
  // src/legacy/syntax.ts
3939
3972
  var CURSOR_CHAR2 = legacySysconf.cursorCharacter;
3940
3973
  var kity18 = getLegacyKity();
3974
+ function clampOffset(offset, maxOffset) {
3975
+ return Math.max(0, Math.min(offset, maxOffset));
3976
+ }
3977
+ function normalizeCursorRecord(objTree, cursor) {
3978
+ const fallbackGroupId = objTree.mapping.root.strGroup.attr.id;
3979
+ const targetGroupId = cursor.groupId && objTree.mapping[cursor.groupId] ? cursor.groupId : fallbackGroupId;
3980
+ const operandCount = objTree.mapping[targetGroupId].strGroup.operand.length;
3981
+ const startOffset = clampOffset(cursor.startOffset, operandCount);
3982
+ const endOffset = clampOffset(cursor.endOffset, operandCount);
3983
+ return {
3984
+ groupId: targetGroupId,
3985
+ startOffset: Math.min(startOffset, endOffset),
3986
+ endOffset: Math.max(startOffset, endOffset)
3987
+ };
3988
+ }
3941
3989
  var SyntaxComponent = kity18.createClass("SyntaxComponenet", {
3942
3990
  constructor(kfEditor) {
3943
3991
  this.kfEditor = kfEditor;
@@ -3987,10 +4035,14 @@ var SyntaxComponent = kity18.createClass("SyntaxComponenet", {
3987
4035
  },
3988
4036
  updateObjTree(objTree) {
3989
4037
  const selectInfo = objTree.select;
4038
+ this.objTree = objTree;
3990
4039
  if (selectInfo?.groupId) {
3991
4040
  this.updateCursor(selectInfo.groupId, selectInfo.startOffset, selectInfo.endOffset);
4041
+ return;
4042
+ }
4043
+ if (this.record.cursor.groupId !== null) {
4044
+ this.record.cursor = normalizeCursorRecord(objTree, this.record.cursor);
3992
4045
  }
3993
- this.objTree = objTree;
3994
4046
  },
3995
4047
  hasCursorInfo() {
3996
4048
  return this.record.cursor.groupId !== null;
@@ -4036,7 +4088,8 @@ var SyntaxComponent = kity18.createClass("SyntaxComponenet", {
4036
4088
  return this.objTree;
4037
4089
  },
4038
4090
  getGroupObject(id) {
4039
- return this.objTree.mapping[id].objGroup || null;
4091
+ const groupInfo = this.objTree.mapping[id];
4092
+ return groupInfo ? groupInfo.objGroup : null;
4040
4093
  },
4041
4094
  getCursorRecord() {
4042
4095
  return kity18.Utils.extend({}, this.record.cursor);
@@ -4112,7 +4165,7 @@ var SyntaxComponent = kity18.createClass("SyntaxComponenet", {
4112
4165
  return this.hasRootplaceholder();
4113
4166
  },
4114
4167
  serialization() {
4115
- const cursor = this.record.cursor;
4168
+ const cursor = normalizeCursorRecord(this.objTree, this.record.cursor);
4116
4169
  const objGroup = this.objTree.mapping[cursor.groupId];
4117
4170
  const curStrGroup = objGroup.strGroup;
4118
4171
  let strStartIndex = Math.min(cursor.endOffset, cursor.startOffset);
@@ -4148,11 +4201,12 @@ var SyntaxComponent = kity18.createClass("SyntaxComponenet", {
4148
4201
  endOffset = startOffset;
4149
4202
  startOffset = tmp;
4150
4203
  }
4151
- this.record.cursor = {
4204
+ const nextCursor = {
4152
4205
  groupId,
4153
4206
  startOffset,
4154
4207
  endOffset
4155
4208
  };
4209
+ this.record.cursor = this.objTree ? normalizeCursorRecord(this.objTree, nextCursor) : nextCursor;
4156
4210
  },
4157
4211
  leftMove() {
4158
4212
  this.components.move.leftMove();
@@ -4197,7 +4251,15 @@ var KEY_CODE = {
4197
4251
  DELETE: 8,
4198
4252
  INPUT: 229
4199
4253
  };
4254
+ var CURSOR_CHAR3 = legacySysconf.cursorCharacter;
4200
4255
  var kity19 = getLegacyKity();
4256
+ function insertCursorMarkers(value, selectionStart, selectionEnd) {
4257
+ const normalizedStart = Math.max(0, Math.min(selectionStart ?? value.length, value.length));
4258
+ const normalizedEnd = Math.max(0, Math.min(selectionEnd ?? normalizedStart, value.length));
4259
+ const rangeStart = Math.min(normalizedStart, normalizedEnd);
4260
+ const rangeEnd = Math.max(normalizedStart, normalizedEnd);
4261
+ return value.slice(0, rangeStart) + CURSOR_CHAR3 + value.slice(rangeStart, rangeEnd) + CURSOR_CHAR3 + value.slice(rangeEnd);
4262
+ }
4201
4263
  var InputComponent = kity19.createClass("InputComponent", {
4202
4264
  constructor(parentComponent, kfEditor) {
4203
4265
  this.parentComponent = parentComponent;
@@ -4369,7 +4431,12 @@ var InputComponent = kity19.createClass("InputComponent", {
4369
4431
  return `${e.shiftKey ? "s+" : ""}${e.keyCode}`;
4370
4432
  },
4371
4433
  processingInput() {
4372
- this.restruct(this.inputBox.value);
4434
+ const latexWithCursor = insertCursorMarkers(
4435
+ this.inputBox.value,
4436
+ this.inputBox.selectionStart,
4437
+ this.inputBox.selectionEnd
4438
+ );
4439
+ this.restruct(latexWithCursor);
4373
4440
  this.kfEditor.requestService("ui.update.canvas.view");
4374
4441
  },
4375
4442
  restruct(latexStr) {
@@ -4856,4 +4923,4 @@ export {
4856
4923
  start_default as default,
4857
4924
  installKityEditorStart
4858
4925
  };
4859
- //# sourceMappingURL=start-LTYA5XON.js.map
4926
+ //# sourceMappingURL=start-N66J24A5.js.map