@formulaxjs/tinymce 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -78
- package/README.zh-CN.md +60 -61
- package/dist/index.global.js +178 -40
- package/dist/index.global.js.map +1 -1
- package/package.json +3 -3
package/dist/index.global.js
CHANGED
|
@@ -5072,6 +5072,21 @@ var FormulaX = (() => {
|
|
|
5072
5072
|
}
|
|
5073
5073
|
});
|
|
5074
5074
|
|
|
5075
|
+
// ../kity-runtime/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 DEFAULT_FORMULAX_LOCALE;
|
|
5083
|
+
var init_i18n = __esm({
|
|
5084
|
+
"../kity-runtime/src/i18n.ts"() {
|
|
5085
|
+
"use strict";
|
|
5086
|
+
DEFAULT_FORMULAX_LOCALE = "en_US";
|
|
5087
|
+
}
|
|
5088
|
+
});
|
|
5089
|
+
|
|
5075
5090
|
// ../kity-runtime/src/vendor/kity-formula/binary-expression.ts
|
|
5076
5091
|
var BinaryExpressionModule, createBinaryExpressionClass;
|
|
5077
5092
|
var init_binary_expression = __esm({
|
|
@@ -5957,14 +5972,11 @@ var FormulaX = (() => {
|
|
|
5957
5972
|
count += 1;
|
|
5958
5973
|
fontInfo.meta.src = resolveFontSource(this.fonts, this.resource, fontInfo.meta.src);
|
|
5959
5974
|
this.createFontStyle(fontInfo);
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
complete(this.doc, callback);
|
|
5966
|
-
}
|
|
5967
|
-
});
|
|
5975
|
+
applyFonts(this.doc, fontInfo);
|
|
5976
|
+
count -= 1;
|
|
5977
|
+
if (count === 0) {
|
|
5978
|
+
complete(this.doc, callback);
|
|
5979
|
+
}
|
|
5968
5980
|
});
|
|
5969
5981
|
},
|
|
5970
5982
|
createFontStyle: function(fontInfo) {
|
|
@@ -5975,13 +5987,6 @@ var FormulaX = (() => {
|
|
|
5975
5987
|
this.doc.head.appendChild(stylesheet);
|
|
5976
5988
|
}
|
|
5977
5989
|
});
|
|
5978
|
-
function preloadFont(doc2, fontInfo) {
|
|
5979
|
-
const view = doc2.defaultView ?? window;
|
|
5980
|
-
if (view.fetch) {
|
|
5981
|
-
return view.fetch(fontInfo.meta.src, { method: "GET" }).then(() => void 0);
|
|
5982
|
-
}
|
|
5983
|
-
return Promise.resolve();
|
|
5984
|
-
}
|
|
5985
5990
|
function resolveFontSource(fonts, resourceBase, originalSrc) {
|
|
5986
5991
|
const directMatch = fonts[originalSrc];
|
|
5987
5992
|
if (directMatch) {
|
|
@@ -6139,11 +6144,11 @@ var FormulaX = (() => {
|
|
|
6139
6144
|
bg;
|
|
6140
6145
|
exp;
|
|
6141
6146
|
config;
|
|
6142
|
-
constructor(kity26, exp,
|
|
6147
|
+
constructor(kity26, exp, config) {
|
|
6143
6148
|
this.wrap = new kity26.Group();
|
|
6144
6149
|
this.bg = new kity26.Rect(0, 0, 0, 0).fill("transparent");
|
|
6145
6150
|
this.exp = exp;
|
|
6146
|
-
this.config =
|
|
6151
|
+
this.config = config;
|
|
6147
6152
|
this.wrap.setAttr("data-type", "kf-exp-wrap");
|
|
6148
6153
|
this.bg.setAttr("data-type", "kf-exp-wrap-bg");
|
|
6149
6154
|
this.wrap.addShape(this.bg);
|
|
@@ -6172,14 +6177,14 @@ var FormulaX = (() => {
|
|
|
6172
6177
|
static create(kity26, GTYPE2, FontManager, FontInstaller, FPaper, Output) {
|
|
6173
6178
|
const Formula = kity26.createClass("Formula", {
|
|
6174
6179
|
base: FPaper,
|
|
6175
|
-
constructor: function(container,
|
|
6180
|
+
constructor: function(container, config) {
|
|
6176
6181
|
if (this.__FORMULAX_PRESERVE_CALL_BASE__) {
|
|
6177
6182
|
this.callBase(container);
|
|
6178
6183
|
}
|
|
6179
6184
|
FPaper.call(this, container);
|
|
6180
6185
|
this.expressions = [];
|
|
6181
6186
|
this.fontInstaller = new FontInstaller(this);
|
|
6182
|
-
this.config = kity26.Utils.extend({}, DEFAULT_OPTIONS,
|
|
6187
|
+
this.config = kity26.Utils.extend({}, DEFAULT_OPTIONS, config);
|
|
6183
6188
|
this.initEnvironment();
|
|
6184
6189
|
this.initInnerFont();
|
|
6185
6190
|
},
|
|
@@ -13644,7 +13649,7 @@ var FormulaX = (() => {
|
|
|
13644
13649
|
value: function() {
|
|
13645
13650
|
const kf7 = window2.kf;
|
|
13646
13651
|
const CONSTRUCT_MAPPING = {};
|
|
13647
|
-
const
|
|
13652
|
+
const CURSOR_CHAR4 = "\uF155";
|
|
13648
13653
|
class Assembly {
|
|
13649
13654
|
formula;
|
|
13650
13655
|
constructor(formula) {
|
|
@@ -13681,7 +13686,7 @@ var FormulaX = (() => {
|
|
|
13681
13686
|
if (tree.name.indexOf("text") === -1) {
|
|
13682
13687
|
for (let i2 = 0, len = operand.length; i2 < len; i2 += 1) {
|
|
13683
13688
|
currentOperand = operand[i2];
|
|
13684
|
-
if (currentOperand ===
|
|
13689
|
+
if (currentOperand === CURSOR_CHAR4) {
|
|
13685
13690
|
cursorLocation.push(i2);
|
|
13686
13691
|
if (!Object.prototype.hasOwnProperty.call(selectInfo, "startOffset")) {
|
|
13687
13692
|
selectInfo.startOffset = i2;
|
|
@@ -16853,6 +16858,35 @@ var FormulaX = (() => {
|
|
|
16853
16858
|
}
|
|
16854
16859
|
Object.keys(list).forEach((key) => callback(list[key], key));
|
|
16855
16860
|
}
|
|
16861
|
+
function translateToolbarText(value, locale) {
|
|
16862
|
+
if (locale === "zh_CN") {
|
|
16863
|
+
return value;
|
|
16864
|
+
}
|
|
16865
|
+
const normalizedValue = value.replace(/<br\s*\/?>/gi, "").trim();
|
|
16866
|
+
const translatedValue = zhCnToEnUsText.get(normalizedValue);
|
|
16867
|
+
if (!translatedValue) {
|
|
16868
|
+
return value;
|
|
16869
|
+
}
|
|
16870
|
+
const lineBreakMatch = value.match(/<br\s*\/?>/i);
|
|
16871
|
+
return lineBreakMatch ? `${translatedValue}${lineBreakMatch[0]}` : translatedValue;
|
|
16872
|
+
}
|
|
16873
|
+
function localizeToolbarConfig(value, locale) {
|
|
16874
|
+
if (Array.isArray(value)) {
|
|
16875
|
+
return value.map((item) => localizeToolbarConfig(item, locale));
|
|
16876
|
+
}
|
|
16877
|
+
if (!value || typeof value !== "object") {
|
|
16878
|
+
return value;
|
|
16879
|
+
}
|
|
16880
|
+
const result = {};
|
|
16881
|
+
for (const [key, currentValue] of Object.entries(value)) {
|
|
16882
|
+
if ((key === "label" || key === "title") && typeof currentValue === "string") {
|
|
16883
|
+
result[key] = translateToolbarText(currentValue, locale);
|
|
16884
|
+
continue;
|
|
16885
|
+
}
|
|
16886
|
+
result[key] = localizeToolbarConfig(currentValue, locale);
|
|
16887
|
+
}
|
|
16888
|
+
return result;
|
|
16889
|
+
}
|
|
16856
16890
|
function getUnicodeContents(keySet) {
|
|
16857
16891
|
let result = [];
|
|
16858
16892
|
each(keySet, function(key) {
|
|
@@ -16872,7 +16906,13 @@ var FormulaX = (() => {
|
|
|
16872
16906
|
});
|
|
16873
16907
|
return result;
|
|
16874
16908
|
}
|
|
16875
|
-
|
|
16909
|
+
function createToolbarConfig(locale = DEFAULT_FORMULAX_LOCALE) {
|
|
16910
|
+
return localizeToolbarConfig(
|
|
16911
|
+
baseToolbarConfig,
|
|
16912
|
+
normalizeFormulaXLocale(locale)
|
|
16913
|
+
);
|
|
16914
|
+
}
|
|
16915
|
+
var UI_ELE_TYPE, BOX_TYPE2, OTHER_POSITION, zhCnToEnUsText, baseToolbarConfig, toolbar_config_default;
|
|
16876
16916
|
var init_toolbar_config = __esm({
|
|
16877
16917
|
"../kity-runtime/src/legacy/toolbar-config.ts"() {
|
|
16878
16918
|
"use strict";
|
|
@@ -16881,10 +16921,45 @@ var FormulaX = (() => {
|
|
|
16881
16921
|
init_other_position();
|
|
16882
16922
|
init_toolbar_assets();
|
|
16883
16923
|
init_formula_symbols();
|
|
16924
|
+
init_i18n();
|
|
16884
16925
|
UI_ELE_TYPE = legacyEleType;
|
|
16885
16926
|
BOX_TYPE2 = legacyBoxType;
|
|
16886
16927
|
OTHER_POSITION = legacyOtherPosition;
|
|
16887
|
-
|
|
16928
|
+
zhCnToEnUsText = /* @__PURE__ */ new Map([
|
|
16929
|
+
["\u9884\u8BBE", "Presets"],
|
|
16930
|
+
["\u9884\u8BBE\u516C\u5F0F", "Preset formulas"],
|
|
16931
|
+
["\u4E8C\u6B21\u516C\u5F0F", "Quadratic formula"],
|
|
16932
|
+
["\u4E8C\u9879\u5F0F\u5B9A\u7406", "Binomial theorem"],
|
|
16933
|
+
["\u52FE\u80A1\u5B9A\u7406", "Pythagorean theorem"],
|
|
16934
|
+
["\u57FA\u7840\u6570\u5B66", "Basic math"],
|
|
16935
|
+
["\u5E0C\u814A\u5B57\u6BCD", "Greek letters"],
|
|
16936
|
+
["\u6C42\u53CD\u5173\u7CFB\u8FD0\u7B97\u7B26", "Negated operators"],
|
|
16937
|
+
["\u5B57\u6BCD\u7C7B\u7B26\u53F7", "Letter-like symbols"],
|
|
16938
|
+
["\u7BAD\u5934", "Arrows"],
|
|
16939
|
+
["\u624B\u5199\u4F53", "Script"],
|
|
16940
|
+
["\u5206\u6570", "Fraction"],
|
|
16941
|
+
["\u5E38\u7528\u5206\u6570", "Common fractions"],
|
|
16942
|
+
["\u4E0A\u4E0B\u6807", "Scripts"],
|
|
16943
|
+
["\u4E0A\u6807\u548C\u4E0B\u6807", "Superscripts and subscripts"],
|
|
16944
|
+
["\u5E38\u7528\u7684\u4E0A\u6807\u548C\u4E0B\u6807", "Common superscripts and subscripts"],
|
|
16945
|
+
["\u6839\u5F0F", "Radicals"],
|
|
16946
|
+
["\u5E38\u7528\u6839\u5F0F", "Common radicals"],
|
|
16947
|
+
["\u79EF\u5206", "Integrals"],
|
|
16948
|
+
["\u5927\u578B\u8FD0\u7B97\u7B26", "Large operators"],
|
|
16949
|
+
["\u6C42\u548C", "Summations"],
|
|
16950
|
+
["\u62EC\u53F7", "Brackets"],
|
|
16951
|
+
["\u65B9\u62EC\u53F7", "Brackets"],
|
|
16952
|
+
["\u51FD\u6570", "Functions"],
|
|
16953
|
+
["\u4E09\u89D2\u51FD\u6570", "Trigonometric functions"],
|
|
16954
|
+
["\u5E38\u7528\u51FD\u6570", "Common functions"],
|
|
16955
|
+
["\u5C0F\u5199", "Lowercase"],
|
|
16956
|
+
["\u5927\u5199", "Uppercase"],
|
|
16957
|
+
["\u53D8\u4F53", "Variants"],
|
|
16958
|
+
["\u82B1\u4F53", "Fraktur"],
|
|
16959
|
+
["\u53CC\u7EBF", "Double-struck"],
|
|
16960
|
+
["\u7F57\u9A6C", "Roman"]
|
|
16961
|
+
]);
|
|
16962
|
+
baseToolbarConfig = [{
|
|
16888
16963
|
type: UI_ELE_TYPE.DRAPDOWN_BOX,
|
|
16889
16964
|
options: {
|
|
16890
16965
|
button: {
|
|
@@ -17290,7 +17365,7 @@ var FormulaX = (() => {
|
|
|
17290
17365
|
}];
|
|
17291
17366
|
(function() {
|
|
17292
17367
|
let tmp = [], otherImageSrc = resolveToolbarAssetPath("other.png"), currentConf = [];
|
|
17293
|
-
each(
|
|
17368
|
+
each(baseToolbarConfig, function(conf) {
|
|
17294
17369
|
if (conf.type === UI_ELE_TYPE.DELIMITER) {
|
|
17295
17370
|
return;
|
|
17296
17371
|
}
|
|
@@ -17362,7 +17437,7 @@ var FormulaX = (() => {
|
|
|
17362
17437
|
"aleph",
|
|
17363
17438
|
"beth",
|
|
17364
17439
|
"blacksquare"
|
|
17365
|
-
], configList =
|
|
17440
|
+
], configList = baseToolbarConfig[2].options.box.group[0].items;
|
|
17366
17441
|
configList.push({
|
|
17367
17442
|
title: "\u57FA\u7840\u6570\u5B66",
|
|
17368
17443
|
content: getUnicodeContents(list)
|
|
@@ -17378,7 +17453,7 @@ var FormulaX = (() => {
|
|
|
17378
17453
|
}, {
|
|
17379
17454
|
title: "\u53D8\u4F53",
|
|
17380
17455
|
values: ["digamma", "varepsilon", "varkappa", "varphi", "varpi", "varrho", "varsigma", "vartheta"]
|
|
17381
|
-
}], greekConfigList =
|
|
17456
|
+
}], greekConfigList = baseToolbarConfig[2].options.box.group[1].items;
|
|
17382
17457
|
greekConfigList.push({
|
|
17383
17458
|
title: greekList[0].title,
|
|
17384
17459
|
content: getUnicodeContents(greekList[0].values)
|
|
@@ -17427,7 +17502,7 @@ var FormulaX = (() => {
|
|
|
17427
17502
|
"nVDash",
|
|
17428
17503
|
"nexists"
|
|
17429
17504
|
]
|
|
17430
|
-
}], greekConfigList =
|
|
17505
|
+
}], greekConfigList = baseToolbarConfig[2].options.box.group[2].items;
|
|
17431
17506
|
greekConfigList.push({
|
|
17432
17507
|
title: greekList[0].title,
|
|
17433
17508
|
content: getUnicodeContents(greekList[0].values)
|
|
@@ -17453,7 +17528,7 @@ var FormulaX = (() => {
|
|
|
17453
17528
|
"Game",
|
|
17454
17529
|
"Im",
|
|
17455
17530
|
"Re"
|
|
17456
|
-
], configList =
|
|
17531
|
+
], configList = baseToolbarConfig[2].options.box.group[3].items;
|
|
17457
17532
|
configList.push({
|
|
17458
17533
|
title: "\u5B57\u6BCD\u7C7B\u7B26\u53F7",
|
|
17459
17534
|
content: getUnicodeContents(list)
|
|
@@ -17521,7 +17596,7 @@ var FormulaX = (() => {
|
|
|
17521
17596
|
"twoheadleftarrow",
|
|
17522
17597
|
"twoheadrightarrow",
|
|
17523
17598
|
"rightsquigarrow"
|
|
17524
|
-
], configList =
|
|
17599
|
+
], configList = baseToolbarConfig[2].options.box.group[4].items;
|
|
17525
17600
|
configList.push({
|
|
17526
17601
|
title: "\u7BAD\u5934",
|
|
17527
17602
|
content: getUnicodeContents(list)
|
|
@@ -17700,7 +17775,7 @@ var FormulaX = (() => {
|
|
|
17700
17775
|
"y",
|
|
17701
17776
|
"z"
|
|
17702
17777
|
]
|
|
17703
|
-
}], configList =
|
|
17778
|
+
}], configList = baseToolbarConfig[2].options.box.group[5].items;
|
|
17704
17779
|
each(list[0].values, function(item, index) {
|
|
17705
17780
|
list[0].values[index] = "mathcal{" + item + "}";
|
|
17706
17781
|
});
|
|
@@ -17730,7 +17805,7 @@ var FormulaX = (() => {
|
|
|
17730
17805
|
content: getUnicodeContents(list[3].values)
|
|
17731
17806
|
});
|
|
17732
17807
|
})();
|
|
17733
|
-
toolbar_config_default =
|
|
17808
|
+
toolbar_config_default = createToolbarConfig;
|
|
17734
17809
|
}
|
|
17735
17810
|
});
|
|
17736
17811
|
|
|
@@ -17773,6 +17848,7 @@ var FormulaX = (() => {
|
|
|
17773
17848
|
init_toolbar();
|
|
17774
17849
|
init_scrollbar();
|
|
17775
17850
|
init_toolbar_config();
|
|
17851
|
+
init_i18n();
|
|
17776
17852
|
$$8 = createLegacyUiUtils();
|
|
17777
17853
|
VIEW_STATE = legacyUiDef.VIEW_STATE;
|
|
17778
17854
|
DEFAULT_EDIT_AREA_HEIGHT = 100;
|
|
@@ -17803,7 +17879,8 @@ var FormulaX = (() => {
|
|
|
17803
17879
|
this.initScrollEvent();
|
|
17804
17880
|
},
|
|
17805
17881
|
initComponents() {
|
|
17806
|
-
|
|
17882
|
+
const toolbarConfig = toolbar_config_default(normalizeFormulaXLocale(this.options.locale));
|
|
17883
|
+
this.components.toolbar = new toolbar_default(this, this.kfEditor, toolbarConfig);
|
|
17807
17884
|
this.components.scrollbar = new scrollbar_default(this, this.kfEditor);
|
|
17808
17885
|
},
|
|
17809
17886
|
updateContainerSize(container, toolbar, editArea) {
|
|
@@ -19070,6 +19147,21 @@ var FormulaX = (() => {
|
|
|
19070
19147
|
});
|
|
19071
19148
|
|
|
19072
19149
|
// ../kity-runtime/src/legacy/syntax.ts
|
|
19150
|
+
function clampOffset(offset, maxOffset) {
|
|
19151
|
+
return Math.max(0, Math.min(offset, maxOffset));
|
|
19152
|
+
}
|
|
19153
|
+
function normalizeCursorRecord(objTree, cursor) {
|
|
19154
|
+
const fallbackGroupId = objTree.mapping.root.strGroup.attr.id;
|
|
19155
|
+
const targetGroupId = cursor.groupId && objTree.mapping[cursor.groupId] ? cursor.groupId : fallbackGroupId;
|
|
19156
|
+
const operandCount = objTree.mapping[targetGroupId].strGroup.operand.length;
|
|
19157
|
+
const startOffset = clampOffset(cursor.startOffset, operandCount);
|
|
19158
|
+
const endOffset = clampOffset(cursor.endOffset, operandCount);
|
|
19159
|
+
return {
|
|
19160
|
+
groupId: targetGroupId,
|
|
19161
|
+
startOffset: Math.min(startOffset, endOffset),
|
|
19162
|
+
endOffset: Math.max(startOffset, endOffset)
|
|
19163
|
+
};
|
|
19164
|
+
}
|
|
19073
19165
|
var CURSOR_CHAR2, kity19, SyntaxComponent, syntax_default;
|
|
19074
19166
|
var init_syntax = __esm({
|
|
19075
19167
|
"../kity-runtime/src/legacy/syntax.ts"() {
|
|
@@ -19130,10 +19222,14 @@ var FormulaX = (() => {
|
|
|
19130
19222
|
},
|
|
19131
19223
|
updateObjTree(objTree) {
|
|
19132
19224
|
const selectInfo = objTree.select;
|
|
19225
|
+
this.objTree = objTree;
|
|
19133
19226
|
if (selectInfo?.groupId) {
|
|
19134
19227
|
this.updateCursor(selectInfo.groupId, selectInfo.startOffset, selectInfo.endOffset);
|
|
19228
|
+
return;
|
|
19229
|
+
}
|
|
19230
|
+
if (this.record.cursor.groupId !== null) {
|
|
19231
|
+
this.record.cursor = normalizeCursorRecord(objTree, this.record.cursor);
|
|
19135
19232
|
}
|
|
19136
|
-
this.objTree = objTree;
|
|
19137
19233
|
},
|
|
19138
19234
|
hasCursorInfo() {
|
|
19139
19235
|
return this.record.cursor.groupId !== null;
|
|
@@ -19179,7 +19275,8 @@ var FormulaX = (() => {
|
|
|
19179
19275
|
return this.objTree;
|
|
19180
19276
|
},
|
|
19181
19277
|
getGroupObject(id) {
|
|
19182
|
-
|
|
19278
|
+
const groupInfo = this.objTree.mapping[id];
|
|
19279
|
+
return groupInfo ? groupInfo.objGroup : null;
|
|
19183
19280
|
},
|
|
19184
19281
|
getCursorRecord() {
|
|
19185
19282
|
return kity19.Utils.extend({}, this.record.cursor);
|
|
@@ -19255,7 +19352,7 @@ var FormulaX = (() => {
|
|
|
19255
19352
|
return this.hasRootplaceholder();
|
|
19256
19353
|
},
|
|
19257
19354
|
serialization() {
|
|
19258
|
-
const cursor = this.record.cursor;
|
|
19355
|
+
const cursor = normalizeCursorRecord(this.objTree, this.record.cursor);
|
|
19259
19356
|
const objGroup = this.objTree.mapping[cursor.groupId];
|
|
19260
19357
|
const curStrGroup = objGroup.strGroup;
|
|
19261
19358
|
let strStartIndex = Math.min(cursor.endOffset, cursor.startOffset);
|
|
@@ -19291,11 +19388,12 @@ var FormulaX = (() => {
|
|
|
19291
19388
|
endOffset = startOffset;
|
|
19292
19389
|
startOffset = tmp;
|
|
19293
19390
|
}
|
|
19294
|
-
|
|
19391
|
+
const nextCursor = {
|
|
19295
19392
|
groupId,
|
|
19296
19393
|
startOffset,
|
|
19297
19394
|
endOffset
|
|
19298
19395
|
};
|
|
19396
|
+
this.record.cursor = this.objTree ? normalizeCursorRecord(this.objTree, nextCursor) : nextCursor;
|
|
19299
19397
|
},
|
|
19300
19398
|
leftMove() {
|
|
19301
19399
|
this.components.move.leftMove();
|
|
@@ -19336,12 +19434,20 @@ var FormulaX = (() => {
|
|
|
19336
19434
|
});
|
|
19337
19435
|
|
|
19338
19436
|
// ../kity-runtime/src/legacy/input.ts
|
|
19339
|
-
|
|
19437
|
+
function insertCursorMarkers(value, selectionStart, selectionEnd) {
|
|
19438
|
+
const normalizedStart = Math.max(0, Math.min(selectionStart ?? value.length, value.length));
|
|
19439
|
+
const normalizedEnd = Math.max(0, Math.min(selectionEnd ?? normalizedStart, value.length));
|
|
19440
|
+
const rangeStart = Math.min(normalizedStart, normalizedEnd);
|
|
19441
|
+
const rangeEnd = Math.max(normalizedStart, normalizedEnd);
|
|
19442
|
+
return value.slice(0, rangeStart) + CURSOR_CHAR3 + value.slice(rangeStart, rangeEnd) + CURSOR_CHAR3 + value.slice(rangeEnd);
|
|
19443
|
+
}
|
|
19444
|
+
var KEY_CODE, CURSOR_CHAR3, kity20, InputComponent, input_default;
|
|
19340
19445
|
var init_input = __esm({
|
|
19341
19446
|
"../kity-runtime/src/legacy/input.ts"() {
|
|
19342
19447
|
"use strict";
|
|
19343
19448
|
init_legacy_utils();
|
|
19344
19449
|
init_legacy_input_filter();
|
|
19450
|
+
init_legacy_sysconf();
|
|
19345
19451
|
init_runtime_interop();
|
|
19346
19452
|
KEY_CODE = {
|
|
19347
19453
|
LEFT: 37,
|
|
@@ -19349,6 +19455,7 @@ var FormulaX = (() => {
|
|
|
19349
19455
|
DELETE: 8,
|
|
19350
19456
|
INPUT: 229
|
|
19351
19457
|
};
|
|
19458
|
+
CURSOR_CHAR3 = legacySysconf.cursorCharacter;
|
|
19352
19459
|
kity20 = getLegacyKity();
|
|
19353
19460
|
InputComponent = kity20.createClass("InputComponent", {
|
|
19354
19461
|
constructor(parentComponent, kfEditor) {
|
|
@@ -19521,7 +19628,12 @@ var FormulaX = (() => {
|
|
|
19521
19628
|
return `${e.shiftKey ? "s+" : ""}${e.keyCode}`;
|
|
19522
19629
|
},
|
|
19523
19630
|
processingInput() {
|
|
19524
|
-
|
|
19631
|
+
const latexWithCursor = insertCursorMarkers(
|
|
19632
|
+
this.inputBox.value,
|
|
19633
|
+
this.inputBox.selectionStart,
|
|
19634
|
+
this.inputBox.selectionEnd
|
|
19635
|
+
);
|
|
19636
|
+
this.restruct(latexWithCursor);
|
|
19525
19637
|
this.kfEditor.requestService("ui.update.canvas.view");
|
|
19526
19638
|
},
|
|
19527
19639
|
restruct(latexStr) {
|
|
@@ -20542,6 +20654,11 @@ var FormulaX = (() => {
|
|
|
20542
20654
|
}
|
|
20543
20655
|
|
|
20544
20656
|
// ../renderer/src/svg.ts
|
|
20657
|
+
var SIMPLE_INLINE_HEIGHT_EM = 1.25;
|
|
20658
|
+
var BASE_FORMULA_HEIGHT = 40.5;
|
|
20659
|
+
var SIMPLE_FORMULA_HEIGHT_RATIO = 1.05;
|
|
20660
|
+
var MAX_INLINE_HEIGHT_EM = 1.65;
|
|
20661
|
+
var COMPLEX_FORMULA_SCALE = 0.825;
|
|
20545
20662
|
function readRenderedFormulaSvgBox(svg2) {
|
|
20546
20663
|
return getInlineSvgContent(svg2)?.box ?? readSvgBox(svg2);
|
|
20547
20664
|
}
|
|
@@ -20716,6 +20833,7 @@ var FormulaX = (() => {
|
|
|
20716
20833
|
"width",
|
|
20717
20834
|
"height",
|
|
20718
20835
|
"viewBox",
|
|
20836
|
+
"font-size",
|
|
20719
20837
|
"class",
|
|
20720
20838
|
"focusable",
|
|
20721
20839
|
"aria-hidden",
|
|
@@ -20727,13 +20845,24 @@ var FormulaX = (() => {
|
|
|
20727
20845
|
target.setAttribute(attribute.name, attribute.value);
|
|
20728
20846
|
});
|
|
20729
20847
|
}
|
|
20848
|
+
function calculateInlineHeightEm(height2) {
|
|
20849
|
+
const heightRatio = height2 / BASE_FORMULA_HEIGHT;
|
|
20850
|
+
if (!Number.isFinite(heightRatio) || heightRatio <= SIMPLE_FORMULA_HEIGHT_RATIO) {
|
|
20851
|
+
return SIMPLE_INLINE_HEIGHT_EM;
|
|
20852
|
+
}
|
|
20853
|
+
return Math.min(
|
|
20854
|
+
MAX_INLINE_HEIGHT_EM,
|
|
20855
|
+
SIMPLE_INLINE_HEIGHT_EM * Math.pow(heightRatio, COMPLEX_FORMULA_SCALE)
|
|
20856
|
+
);
|
|
20857
|
+
}
|
|
20730
20858
|
function sizeSvgForInlineDisplay(clone, source, viewport) {
|
|
20859
|
+
clone.removeAttribute("font-size");
|
|
20731
20860
|
const viewBox = clone.viewBox?.baseVal;
|
|
20732
20861
|
const rect = source.getBoundingClientRect();
|
|
20733
20862
|
const width2 = viewport?.width || viewBox?.width || rect.width || Number(clone.getAttribute("width")) || 1;
|
|
20734
20863
|
const height2 = viewport?.height || viewBox?.height || rect.height || Number(clone.getAttribute("height")) || 1;
|
|
20735
20864
|
const ratio = Math.max(0.1, width2 / Math.max(1, height2));
|
|
20736
|
-
const inlineHeightEm =
|
|
20865
|
+
const inlineHeightEm = calculateInlineHeightEm(height2);
|
|
20737
20866
|
const inlineWidthEm = Math.min(40, Math.max(0.75, ratio * inlineHeightEm));
|
|
20738
20867
|
clone.setAttribute("width", roundLength(width2));
|
|
20739
20868
|
clone.setAttribute("height", roundLength(height2));
|
|
@@ -20741,8 +20870,9 @@ var FormulaX = (() => {
|
|
|
20741
20870
|
"style",
|
|
20742
20871
|
mergeInlineStyles2(
|
|
20743
20872
|
clone.getAttribute("style"),
|
|
20873
|
+
"font-size:inherit",
|
|
20744
20874
|
`width:${roundLength(inlineWidthEm)}em`,
|
|
20745
|
-
`height:${inlineHeightEm}em`
|
|
20875
|
+
`height:${roundLength(inlineHeightEm)}em`
|
|
20746
20876
|
)
|
|
20747
20877
|
);
|
|
20748
20878
|
}
|
|
@@ -24343,6 +24473,7 @@ var FormulaX = (() => {
|
|
|
24343
24473
|
|
|
24344
24474
|
// ../kity-runtime/src/create-editor.ts
|
|
24345
24475
|
init_toolbar_assets();
|
|
24476
|
+
init_i18n();
|
|
24346
24477
|
var DEFAULT_LATEX = "x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}";
|
|
24347
24478
|
var DEFAULT_EDITOR_HEIGHT = "auto";
|
|
24348
24479
|
var KITY_STYLE_ID = "formulax-kity-editor-styles";
|
|
@@ -24493,6 +24624,7 @@ var FormulaX = (() => {
|
|
|
24493
24624
|
const createEditorStart = markFormulaXPerf("fx:create-kity-editor:total");
|
|
24494
24625
|
const fontsize = options.render?.fontsize ?? 40;
|
|
24495
24626
|
const editorHeight = normalizeCssSize(options.height, DEFAULT_EDITOR_HEIGHT);
|
|
24627
|
+
const locale = normalizeFormulaXLocale(options.locale ?? DEFAULT_FORMULAX_LOCALE);
|
|
24496
24628
|
const assets = resolveEditorAssets(options.assets);
|
|
24497
24629
|
try {
|
|
24498
24630
|
const stylesheetInserted = ensureKityStylesheet(document, assets.styles.editor);
|
|
@@ -24521,6 +24653,9 @@ var FormulaX = (() => {
|
|
|
24521
24653
|
render: {
|
|
24522
24654
|
fontsize
|
|
24523
24655
|
},
|
|
24656
|
+
ui: {
|
|
24657
|
+
locale
|
|
24658
|
+
},
|
|
24524
24659
|
resource: {
|
|
24525
24660
|
path: "",
|
|
24526
24661
|
fonts: assets.fonts
|
|
@@ -24603,6 +24738,7 @@ var FormulaX = (() => {
|
|
|
24603
24738
|
|
|
24604
24739
|
// ../kity-runtime/src/index.ts
|
|
24605
24740
|
init_dom_utils();
|
|
24741
|
+
init_i18n();
|
|
24606
24742
|
init_legacy_box_type();
|
|
24607
24743
|
init_legacy_component();
|
|
24608
24744
|
init_legacy_ele_type();
|
|
@@ -25026,6 +25162,8 @@ var FormulaX = (() => {
|
|
|
25026
25162
|
}
|
|
25027
25163
|
|
|
25028
25164
|
.fx-formula-kity-host .kf-editor {
|
|
25165
|
+
box-sizing: border-box;
|
|
25166
|
+
width: 100%;
|
|
25029
25167
|
height: var(--fx-formula-editor-body-height) !important;
|
|
25030
25168
|
overflow: visible !important;
|
|
25031
25169
|
}
|