@formulaxjs/tiptap 0.3.0 → 0.3.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 +235 -236
- package/README.zh-CN.md +42 -43
- package/dist/index.global.js +196 -58
- 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) {
|
|
@@ -24690,24 +24802,24 @@ var FormulaX = (() => {
|
|
|
24690
24802
|
};
|
|
24691
24803
|
var baseFields = [
|
|
24692
24804
|
new FieldDesc("doc", {
|
|
24693
|
-
init(
|
|
24694
|
-
return
|
|
24805
|
+
init(config) {
|
|
24806
|
+
return config.doc || config.schema.topNodeType.createAndFill();
|
|
24695
24807
|
},
|
|
24696
24808
|
apply(tr) {
|
|
24697
24809
|
return tr.doc;
|
|
24698
24810
|
}
|
|
24699
24811
|
}),
|
|
24700
24812
|
new FieldDesc("selection", {
|
|
24701
|
-
init(
|
|
24702
|
-
return
|
|
24813
|
+
init(config, instance) {
|
|
24814
|
+
return config.selection || Selection.atStart(instance.doc);
|
|
24703
24815
|
},
|
|
24704
24816
|
apply(tr) {
|
|
24705
24817
|
return tr.selection;
|
|
24706
24818
|
}
|
|
24707
24819
|
}),
|
|
24708
24820
|
new FieldDesc("storedMarks", {
|
|
24709
|
-
init(
|
|
24710
|
-
return
|
|
24821
|
+
init(config) {
|
|
24822
|
+
return config.storedMarks || null;
|
|
24711
24823
|
},
|
|
24712
24824
|
apply(tr, _marks, _old, state) {
|
|
24713
24825
|
return state.selection.$cursor ? tr.storedMarks : null;
|
|
@@ -25431,8 +25543,8 @@ var FormulaX = (() => {
|
|
|
25431
25543
|
}
|
|
25432
25544
|
|
|
25433
25545
|
// ../../node_modules/.pnpm/@tiptap+core@2.27.2_@tiptap+pm@2.27.2/node_modules/@tiptap/core/dist/index.js
|
|
25434
|
-
function createChainableState(
|
|
25435
|
-
const { state, transaction } =
|
|
25546
|
+
function createChainableState(config) {
|
|
25547
|
+
const { state, transaction } = config;
|
|
25436
25548
|
let { selection } = transaction;
|
|
25437
25549
|
let { doc: doc2 } = transaction;
|
|
25438
25550
|
let { storedMarks } = transaction;
|
|
@@ -25627,7 +25739,7 @@ var FormulaX = (() => {
|
|
|
25627
25739
|
return output;
|
|
25628
25740
|
}
|
|
25629
25741
|
var Extension = class _Extension {
|
|
25630
|
-
constructor(
|
|
25742
|
+
constructor(config = {}) {
|
|
25631
25743
|
this.type = "extension";
|
|
25632
25744
|
this.name = "extension";
|
|
25633
25745
|
this.parent = null;
|
|
@@ -25638,10 +25750,10 @@ var FormulaX = (() => {
|
|
|
25638
25750
|
};
|
|
25639
25751
|
this.config = {
|
|
25640
25752
|
...this.config,
|
|
25641
|
-
...
|
|
25753
|
+
...config
|
|
25642
25754
|
};
|
|
25643
25755
|
this.name = this.config.name;
|
|
25644
|
-
if (
|
|
25756
|
+
if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
|
|
25645
25757
|
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`);
|
|
25646
25758
|
}
|
|
25647
25759
|
this.options = this.config.defaultOptions;
|
|
@@ -25655,8 +25767,8 @@ var FormulaX = (() => {
|
|
|
25655
25767
|
options: this.options
|
|
25656
25768
|
})) || {};
|
|
25657
25769
|
}
|
|
25658
|
-
static create(
|
|
25659
|
-
return new _Extension(
|
|
25770
|
+
static create(config = {}) {
|
|
25771
|
+
return new _Extension(config);
|
|
25660
25772
|
}
|
|
25661
25773
|
configure(options = {}) {
|
|
25662
25774
|
const extension = this.extend({
|
|
@@ -27460,7 +27572,7 @@ var FormulaX = (() => {
|
|
|
27460
27572
|
}
|
|
27461
27573
|
});
|
|
27462
27574
|
var Node2 = class _Node {
|
|
27463
|
-
constructor(
|
|
27575
|
+
constructor(config = {}) {
|
|
27464
27576
|
this.type = "node";
|
|
27465
27577
|
this.name = "node";
|
|
27466
27578
|
this.parent = null;
|
|
@@ -27471,10 +27583,10 @@ var FormulaX = (() => {
|
|
|
27471
27583
|
};
|
|
27472
27584
|
this.config = {
|
|
27473
27585
|
...this.config,
|
|
27474
|
-
...
|
|
27586
|
+
...config
|
|
27475
27587
|
};
|
|
27476
27588
|
this.name = this.config.name;
|
|
27477
|
-
if (
|
|
27589
|
+
if (config.defaultOptions && Object.keys(config.defaultOptions).length > 0) {
|
|
27478
27590
|
console.warn(`[tiptap warn]: BREAKING CHANGE: "defaultOptions" is deprecated. Please use "addOptions" instead. Found in extension: "${this.name}".`);
|
|
27479
27591
|
}
|
|
27480
27592
|
this.options = this.config.defaultOptions;
|
|
@@ -27488,8 +27600,8 @@ var FormulaX = (() => {
|
|
|
27488
27600
|
options: this.options
|
|
27489
27601
|
})) || {};
|
|
27490
27602
|
}
|
|
27491
|
-
static create(
|
|
27492
|
-
return new _Node(
|
|
27603
|
+
static create(config = {}) {
|
|
27604
|
+
return new _Node(config);
|
|
27493
27605
|
}
|
|
27494
27606
|
configure(options = {}) {
|
|
27495
27607
|
const extension = this.extend({
|
|
@@ -27956,6 +28068,11 @@ var FormulaX = (() => {
|
|
|
27956
28068
|
}
|
|
27957
28069
|
|
|
27958
28070
|
// ../renderer/src/svg.ts
|
|
28071
|
+
var SIMPLE_INLINE_HEIGHT_EM = 1.25;
|
|
28072
|
+
var BASE_FORMULA_HEIGHT = 40.5;
|
|
28073
|
+
var SIMPLE_FORMULA_HEIGHT_RATIO = 1.05;
|
|
28074
|
+
var MAX_INLINE_HEIGHT_EM = 1.65;
|
|
28075
|
+
var COMPLEX_FORMULA_SCALE = 0.825;
|
|
27959
28076
|
function readRenderedFormulaSvgBox(svg2) {
|
|
27960
28077
|
return getInlineSvgContent(svg2)?.box ?? readSvgBox(svg2);
|
|
27961
28078
|
}
|
|
@@ -28130,6 +28247,7 @@ var FormulaX = (() => {
|
|
|
28130
28247
|
"width",
|
|
28131
28248
|
"height",
|
|
28132
28249
|
"viewBox",
|
|
28250
|
+
"font-size",
|
|
28133
28251
|
"class",
|
|
28134
28252
|
"focusable",
|
|
28135
28253
|
"aria-hidden",
|
|
@@ -28141,13 +28259,24 @@ var FormulaX = (() => {
|
|
|
28141
28259
|
target.setAttribute(attribute.name, attribute.value);
|
|
28142
28260
|
});
|
|
28143
28261
|
}
|
|
28262
|
+
function calculateInlineHeightEm(height2) {
|
|
28263
|
+
const heightRatio = height2 / BASE_FORMULA_HEIGHT;
|
|
28264
|
+
if (!Number.isFinite(heightRatio) || heightRatio <= SIMPLE_FORMULA_HEIGHT_RATIO) {
|
|
28265
|
+
return SIMPLE_INLINE_HEIGHT_EM;
|
|
28266
|
+
}
|
|
28267
|
+
return Math.min(
|
|
28268
|
+
MAX_INLINE_HEIGHT_EM,
|
|
28269
|
+
SIMPLE_INLINE_HEIGHT_EM * Math.pow(heightRatio, COMPLEX_FORMULA_SCALE)
|
|
28270
|
+
);
|
|
28271
|
+
}
|
|
28144
28272
|
function sizeSvgForInlineDisplay(clone, source, viewport) {
|
|
28273
|
+
clone.removeAttribute("font-size");
|
|
28145
28274
|
const viewBox = clone.viewBox?.baseVal;
|
|
28146
28275
|
const rect = source.getBoundingClientRect();
|
|
28147
28276
|
const width2 = viewport?.width || viewBox?.width || rect.width || Number(clone.getAttribute("width")) || 1;
|
|
28148
28277
|
const height2 = viewport?.height || viewBox?.height || rect.height || Number(clone.getAttribute("height")) || 1;
|
|
28149
28278
|
const ratio = Math.max(0.1, width2 / Math.max(1, height2));
|
|
28150
|
-
const inlineHeightEm =
|
|
28279
|
+
const inlineHeightEm = calculateInlineHeightEm(height2);
|
|
28151
28280
|
const inlineWidthEm = Math.min(40, Math.max(0.75, ratio * inlineHeightEm));
|
|
28152
28281
|
clone.setAttribute("width", roundLength(width2));
|
|
28153
28282
|
clone.setAttribute("height", roundLength(height2));
|
|
@@ -28155,8 +28284,9 @@ var FormulaX = (() => {
|
|
|
28155
28284
|
"style",
|
|
28156
28285
|
mergeInlineStyles2(
|
|
28157
28286
|
clone.getAttribute("style"),
|
|
28287
|
+
"font-size:inherit",
|
|
28158
28288
|
`width:${roundLength(inlineWidthEm)}em`,
|
|
28159
|
-
`height:${inlineHeightEm}em`
|
|
28289
|
+
`height:${roundLength(inlineHeightEm)}em`
|
|
28160
28290
|
)
|
|
28161
28291
|
);
|
|
28162
28292
|
}
|
|
@@ -31684,6 +31814,7 @@ var FormulaX = (() => {
|
|
|
31684
31814
|
|
|
31685
31815
|
// ../kity-runtime/src/create-editor.ts
|
|
31686
31816
|
init_toolbar_assets();
|
|
31817
|
+
init_i18n();
|
|
31687
31818
|
var DEFAULT_LATEX = "x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}";
|
|
31688
31819
|
var DEFAULT_EDITOR_HEIGHT = "auto";
|
|
31689
31820
|
var KITY_STYLE_ID = "formulax-kity-editor-styles";
|
|
@@ -31834,6 +31965,7 @@ var FormulaX = (() => {
|
|
|
31834
31965
|
const createEditorStart = markFormulaXPerf("fx:create-kity-editor:total");
|
|
31835
31966
|
const fontsize = options.render?.fontsize ?? 40;
|
|
31836
31967
|
const editorHeight = normalizeCssSize(options.height, DEFAULT_EDITOR_HEIGHT);
|
|
31968
|
+
const locale = normalizeFormulaXLocale(options.locale ?? DEFAULT_FORMULAX_LOCALE);
|
|
31837
31969
|
const assets = resolveEditorAssets(options.assets);
|
|
31838
31970
|
try {
|
|
31839
31971
|
const stylesheetInserted = ensureKityStylesheet(document, assets.styles.editor);
|
|
@@ -31862,6 +31994,9 @@ var FormulaX = (() => {
|
|
|
31862
31994
|
render: {
|
|
31863
31995
|
fontsize
|
|
31864
31996
|
},
|
|
31997
|
+
ui: {
|
|
31998
|
+
locale
|
|
31999
|
+
},
|
|
31865
32000
|
resource: {
|
|
31866
32001
|
path: "",
|
|
31867
32002
|
fonts: assets.fonts
|
|
@@ -31944,6 +32079,7 @@ var FormulaX = (() => {
|
|
|
31944
32079
|
|
|
31945
32080
|
// ../kity-runtime/src/index.ts
|
|
31946
32081
|
init_dom_utils();
|
|
32082
|
+
init_i18n();
|
|
31947
32083
|
init_legacy_box_type();
|
|
31948
32084
|
init_legacy_component();
|
|
31949
32085
|
init_legacy_ele_type();
|
|
@@ -32367,6 +32503,8 @@ var FormulaX = (() => {
|
|
|
32367
32503
|
}
|
|
32368
32504
|
|
|
32369
32505
|
.fx-formula-kity-host .kf-editor {
|
|
32506
|
+
box-sizing: border-box;
|
|
32507
|
+
width: 100%;
|
|
32370
32508
|
height: var(--fx-formula-editor-body-height) !important;
|
|
32371
32509
|
overflow: visible !important;
|
|
32372
32510
|
}
|