@formulaxjs/ckeditor5 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 +283 -284
- package/README.zh-CN.md +50 -51
- package/dist/index.global.js +178 -40
- package/dist/index.global.js.map +1 -1
- package/package.json +4 -4
package/README.zh-CN.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
FormulaX 的 CKEditor 5 集成适配器。
|
|
6
6
|
|
|
7
|
-
`@formulaxjs/ckeditor5` 提供了一个 CKEditor 5 插件,会以弹窗形式打开 FormulaX 编辑器,用于在 CKEditor 5 内容中插入和更新行内公式。
|
|
7
|
+
`@formulaxjs/ckeditor5` 提供了一个 CKEditor 5 插件,会以弹窗形式打开 FormulaX 编辑器,用于在 CKEditor 5 内容中插入和更新行内公式。
|
|
8
8
|
|
|
9
9
|
> 状态:实验阶段。在首个稳定版本发布前,公共 API 仍可能调整。
|
|
10
10
|
|
|
@@ -14,13 +14,13 @@ FormulaX 的 CKEditor 5 集成适配器。
|
|
|
14
14
|
- 基于 CKEditor 5 `componentFactory` 注册工具栏按钮
|
|
15
15
|
- 通过 `editor.execute('formulaX')` 在代码中主动打开
|
|
16
16
|
- 将公式作为行内 widget object 插入和更新
|
|
17
|
-
- 支持双击编辑已有公式
|
|
18
|
-
- 在 CKEditor 5 model 中仅持久化 LaTeX 源内容
|
|
19
|
-
- 在 editing view 中运行时渲染 SVG
|
|
20
|
-
- 默认通过 `@formulaxjs/renderer-kity` 完成只读渲染
|
|
21
|
-
- 支持在首次打开弹窗前预加载 runtime
|
|
22
|
-
- 支持在编辑器数据中对公式 markup 进行 upcast 和 downcast
|
|
23
|
-
- 直接导出弹窗工具函数 `openFormulaXModal`
|
|
17
|
+
- 支持双击编辑已有公式
|
|
18
|
+
- 在 CKEditor 5 model 中仅持久化 LaTeX 源内容
|
|
19
|
+
- 在 editing view 中运行时渲染 SVG
|
|
20
|
+
- 默认通过 `@formulaxjs/renderer-kity` 完成只读渲染
|
|
21
|
+
- 支持在首次打开弹窗前预加载 runtime
|
|
22
|
+
- 支持在编辑器数据中对公式 markup 进行 upcast 和 downcast
|
|
23
|
+
- 直接导出弹窗工具函数 `openFormulaXModal`
|
|
24
24
|
|
|
25
25
|
## 兼容性
|
|
26
26
|
|
|
@@ -39,8 +39,7 @@ FormulaX 的 CKEditor 5 集成适配器。
|
|
|
39
39
|
包发布后可使用:
|
|
40
40
|
|
|
41
41
|
```bash
|
|
42
|
-
|
|
43
|
-
pnpm add ckeditor5
|
|
42
|
+
npm install @formulaxjs/ckeditor5 ckeditor5
|
|
44
43
|
```
|
|
45
44
|
|
|
46
45
|
在 FormulaX 工作空间内,直接使用 workspace 包:
|
|
@@ -60,10 +59,10 @@ import {
|
|
|
60
59
|
Essentials,
|
|
61
60
|
Paragraph,
|
|
62
61
|
} from 'ckeditor5';
|
|
63
|
-
import 'ckeditor5/ckeditor5.css';
|
|
64
|
-
|
|
65
|
-
import { FormulaX } from '@formulaxjs/ckeditor5';
|
|
66
|
-
import { createKityFormulaRenderer } from '@formulaxjs/renderer-kity';
|
|
62
|
+
import 'ckeditor5/ckeditor5.css';
|
|
63
|
+
|
|
64
|
+
import { FormulaX } from '@formulaxjs/ckeditor5';
|
|
65
|
+
import { createKityFormulaRenderer } from '@formulaxjs/renderer-kity';
|
|
67
66
|
|
|
68
67
|
await ClassicEditor.create(document.querySelector('#editor')!, {
|
|
69
68
|
licenseKey: 'GPL',
|
|
@@ -73,18 +72,18 @@ await ClassicEditor.create(document.querySelector('#editor')!, {
|
|
|
73
72
|
FormulaX,
|
|
74
73
|
],
|
|
75
74
|
toolbar: ['formulaX'],
|
|
76
|
-
formulaX: {
|
|
77
|
-
toolbarText: 'FormulaX',
|
|
78
|
-
tooltip: '插入或编辑公式',
|
|
79
|
-
modal: {
|
|
80
|
-
title: 'FormulaX 公式编辑器',
|
|
81
|
-
},
|
|
82
|
-
renderer: createKityFormulaRenderer({
|
|
83
|
-
fontSize: 40,
|
|
84
|
-
}),
|
|
85
|
-
editor: {
|
|
86
|
-
render: {
|
|
87
|
-
fontsize: 40,
|
|
75
|
+
formulaX: {
|
|
76
|
+
toolbarText: 'FormulaX',
|
|
77
|
+
tooltip: '插入或编辑公式',
|
|
78
|
+
modal: {
|
|
79
|
+
title: 'FormulaX 公式编辑器',
|
|
80
|
+
},
|
|
81
|
+
renderer: createKityFormulaRenderer({
|
|
82
|
+
fontSize: 40,
|
|
83
|
+
}),
|
|
84
|
+
editor: {
|
|
85
|
+
render: {
|
|
86
|
+
fontsize: 40,
|
|
88
87
|
},
|
|
89
88
|
},
|
|
90
89
|
},
|
|
@@ -165,28 +164,28 @@ CKEditor 5 的 model 层只保存公式的 LaTeX 源内容:
|
|
|
165
164
|
></span>
|
|
166
165
|
```
|
|
167
166
|
|
|
168
|
-
编辑态中的 SVG 由持久化的 LaTeX 在运行时生成。用于渲染公式的内部 HTML 结构属于实现细节,后续可能演进。业务侧应优先依赖插件能力和导出的配置项,而不是写死完整 markup 结构。
|
|
169
|
-
|
|
170
|
-
## 自定义 renderer
|
|
171
|
-
|
|
172
|
-
该适配器支持 `renderer` 配置项。默认值是来自 `@formulaxjs/renderer-kity` 的 `createKityFormulaRenderer()`。
|
|
167
|
+
编辑态中的 SVG 由持久化的 LaTeX 在运行时生成。用于渲染公式的内部 HTML 结构属于实现细节,后续可能演进。业务侧应优先依赖插件能力和导出的配置项,而不是写死完整 markup 结构。
|
|
168
|
+
|
|
169
|
+
## 自定义 renderer
|
|
170
|
+
|
|
171
|
+
该适配器支持 `renderer` 配置项。默认值是来自 `@formulaxjs/renderer-kity` 的 `createKityFormulaRenderer()`。
|
|
173
172
|
|
|
174
173
|
## 配置项
|
|
175
174
|
|
|
176
175
|
```ts
|
|
177
|
-
interface FormulaXCKEditor5Options {
|
|
178
|
-
name?: string;
|
|
179
|
-
buttonName?: string;
|
|
180
|
-
toolbarText?: string;
|
|
181
|
-
tooltip?: string;
|
|
182
|
-
cursorStyle?: string;
|
|
183
|
-
formulaClassName?: string;
|
|
184
|
-
formulaAttributeName?: string;
|
|
185
|
-
renderer?: FormulaRenderer;
|
|
186
|
-
preload?: FormulaXEditorPreloadMode;
|
|
187
|
-
modal?: {
|
|
188
|
-
title?: string;
|
|
189
|
-
insertText?: string;
|
|
176
|
+
interface FormulaXCKEditor5Options {
|
|
177
|
+
name?: string;
|
|
178
|
+
buttonName?: string;
|
|
179
|
+
toolbarText?: string;
|
|
180
|
+
tooltip?: string;
|
|
181
|
+
cursorStyle?: string;
|
|
182
|
+
formulaClassName?: string;
|
|
183
|
+
formulaAttributeName?: string;
|
|
184
|
+
renderer?: FormulaRenderer;
|
|
185
|
+
preload?: FormulaXEditorPreloadMode;
|
|
186
|
+
modal?: {
|
|
187
|
+
title?: string;
|
|
188
|
+
insertText?: string;
|
|
190
189
|
updateText?: string;
|
|
191
190
|
cancelText?: string;
|
|
192
191
|
closeOnBackdrop?: boolean;
|
|
@@ -208,13 +207,13 @@ interface FormulaXCKEditor5Options {
|
|
|
208
207
|
| `buttonName` | `formulaX` | CKEditor 5 的工具栏按钮名,同时也是命令名。 |
|
|
209
208
|
| `toolbarText` | `FormulaX` | 工具栏按钮显示文本。 |
|
|
210
209
|
| `tooltip` | `Insert or edit formula` | 工具栏按钮 tooltip。 |
|
|
211
|
-
| `cursorStyle` | `pointer` | 应用于生成公式节点的鼠标光标样式。 |
|
|
212
|
-
| `formulaClassName` | `formulax-math` | 生成的公式节点 CSS class。 |
|
|
213
|
-
| `formulaAttributeName` | `data-formulax-latex` | 用于保存 LaTeX 源内容的属性。 |
|
|
214
|
-
| `renderer` | `createKityFormulaRenderer()` | editing view 中运行时 SVG 输出使用的 renderer。 |
|
|
215
|
-
| `preload` | `idle` | 控制在浏览器空闲时、宿主 hover/focus 时,或完全不预加载 FormulaX runtime。 |
|
|
216
|
-
| `modal` | 见下方 | 弹窗文案和关闭行为。 |
|
|
217
|
-
| `editor` | 见下方 | 内嵌 FormulaX 编辑器配置。 |
|
|
210
|
+
| `cursorStyle` | `pointer` | 应用于生成公式节点的鼠标光标样式。 |
|
|
211
|
+
| `formulaClassName` | `formulax-math` | 生成的公式节点 CSS class。 |
|
|
212
|
+
| `formulaAttributeName` | `data-formulax-latex` | 用于保存 LaTeX 源内容的属性。 |
|
|
213
|
+
| `renderer` | `createKityFormulaRenderer()` | editing view 中运行时 SVG 输出使用的 renderer。 |
|
|
214
|
+
| `preload` | `idle` | 控制在浏览器空闲时、宿主 hover/focus 时,或完全不预加载 FormulaX runtime。 |
|
|
215
|
+
| `modal` | 见下方 | 弹窗文案和关闭行为。 |
|
|
216
|
+
| `editor` | 见下方 | 内嵌 FormulaX 编辑器配置。 |
|
|
218
217
|
|
|
219
218
|
### Modal 配置
|
|
220
219
|
|
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
|
count2 += 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
|
+
count2 -= 1;
|
|
5977
|
+
if (count2 === 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) {
|
|
@@ -20196,6 +20308,11 @@ var FormulaX = (() => {
|
|
|
20196
20308
|
}
|
|
20197
20309
|
|
|
20198
20310
|
// ../renderer/src/svg.ts
|
|
20311
|
+
var SIMPLE_INLINE_HEIGHT_EM = 1.25;
|
|
20312
|
+
var BASE_FORMULA_HEIGHT = 40.5;
|
|
20313
|
+
var SIMPLE_FORMULA_HEIGHT_RATIO = 1.05;
|
|
20314
|
+
var MAX_INLINE_HEIGHT_EM = 1.65;
|
|
20315
|
+
var COMPLEX_FORMULA_SCALE = 0.825;
|
|
20199
20316
|
function readRenderedFormulaSvgBox(svg2) {
|
|
20200
20317
|
return getInlineSvgContent(svg2)?.box ?? readSvgBox(svg2);
|
|
20201
20318
|
}
|
|
@@ -20370,6 +20487,7 @@ var FormulaX = (() => {
|
|
|
20370
20487
|
"width",
|
|
20371
20488
|
"height",
|
|
20372
20489
|
"viewBox",
|
|
20490
|
+
"font-size",
|
|
20373
20491
|
"class",
|
|
20374
20492
|
"focusable",
|
|
20375
20493
|
"aria-hidden",
|
|
@@ -20381,13 +20499,24 @@ var FormulaX = (() => {
|
|
|
20381
20499
|
target.setAttribute(attribute.name, attribute.value);
|
|
20382
20500
|
});
|
|
20383
20501
|
}
|
|
20502
|
+
function calculateInlineHeightEm(height2) {
|
|
20503
|
+
const heightRatio = height2 / BASE_FORMULA_HEIGHT;
|
|
20504
|
+
if (!Number.isFinite(heightRatio) || heightRatio <= SIMPLE_FORMULA_HEIGHT_RATIO) {
|
|
20505
|
+
return SIMPLE_INLINE_HEIGHT_EM;
|
|
20506
|
+
}
|
|
20507
|
+
return Math.min(
|
|
20508
|
+
MAX_INLINE_HEIGHT_EM,
|
|
20509
|
+
SIMPLE_INLINE_HEIGHT_EM * Math.pow(heightRatio, COMPLEX_FORMULA_SCALE)
|
|
20510
|
+
);
|
|
20511
|
+
}
|
|
20384
20512
|
function sizeSvgForInlineDisplay(clone4, source2, viewport) {
|
|
20513
|
+
clone4.removeAttribute("font-size");
|
|
20385
20514
|
const viewBox = clone4.viewBox?.baseVal;
|
|
20386
20515
|
const rect = source2.getBoundingClientRect();
|
|
20387
20516
|
const width2 = viewport?.width || viewBox?.width || rect.width || Number(clone4.getAttribute("width")) || 1;
|
|
20388
20517
|
const height2 = viewport?.height || viewBox?.height || rect.height || Number(clone4.getAttribute("height")) || 1;
|
|
20389
20518
|
const ratio = Math.max(0.1, width2 / Math.max(1, height2));
|
|
20390
|
-
const inlineHeightEm =
|
|
20519
|
+
const inlineHeightEm = calculateInlineHeightEm(height2);
|
|
20391
20520
|
const inlineWidthEm = Math.min(40, Math.max(0.75, ratio * inlineHeightEm));
|
|
20392
20521
|
clone4.setAttribute("width", roundLength(width2));
|
|
20393
20522
|
clone4.setAttribute("height", roundLength(height2));
|
|
@@ -20395,8 +20524,9 @@ var FormulaX = (() => {
|
|
|
20395
20524
|
"style",
|
|
20396
20525
|
mergeInlineStyles2(
|
|
20397
20526
|
clone4.getAttribute("style"),
|
|
20527
|
+
"font-size:inherit",
|
|
20398
20528
|
`width:${roundLength(inlineWidthEm)}em`,
|
|
20399
|
-
`height:${inlineHeightEm}em`
|
|
20529
|
+
`height:${roundLength(inlineHeightEm)}em`
|
|
20400
20530
|
)
|
|
20401
20531
|
);
|
|
20402
20532
|
}
|
|
@@ -61179,6 +61309,7 @@ Original error: ${originalError.name}: ${originalError.message}` : "";
|
|
|
61179
61309
|
|
|
61180
61310
|
// ../kity-runtime/src/create-editor.ts
|
|
61181
61311
|
init_toolbar_assets();
|
|
61312
|
+
init_i18n();
|
|
61182
61313
|
var DEFAULT_LATEX = "x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}";
|
|
61183
61314
|
var DEFAULT_EDITOR_HEIGHT = "auto";
|
|
61184
61315
|
var KITY_STYLE_ID = "formulax-kity-editor-styles";
|
|
@@ -61329,6 +61460,7 @@ Original error: ${originalError.name}: ${originalError.message}` : "";
|
|
|
61329
61460
|
const createEditorStart = markFormulaXPerf("fx:create-kity-editor:total");
|
|
61330
61461
|
const fontsize = options.render?.fontsize ?? 40;
|
|
61331
61462
|
const editorHeight = normalizeCssSize(options.height, DEFAULT_EDITOR_HEIGHT);
|
|
61463
|
+
const locale = normalizeFormulaXLocale(options.locale ?? DEFAULT_FORMULAX_LOCALE);
|
|
61332
61464
|
const assets = resolveEditorAssets(options.assets);
|
|
61333
61465
|
try {
|
|
61334
61466
|
const stylesheetInserted = ensureKityStylesheet(document, assets.styles.editor);
|
|
@@ -61357,6 +61489,9 @@ Original error: ${originalError.name}: ${originalError.message}` : "";
|
|
|
61357
61489
|
render: {
|
|
61358
61490
|
fontsize
|
|
61359
61491
|
},
|
|
61492
|
+
ui: {
|
|
61493
|
+
locale
|
|
61494
|
+
},
|
|
61360
61495
|
resource: {
|
|
61361
61496
|
path: "",
|
|
61362
61497
|
fonts: assets.fonts
|
|
@@ -61439,6 +61574,7 @@ Original error: ${originalError.name}: ${originalError.message}` : "";
|
|
|
61439
61574
|
|
|
61440
61575
|
// ../kity-runtime/src/index.ts
|
|
61441
61576
|
init_dom_utils();
|
|
61577
|
+
init_i18n();
|
|
61442
61578
|
init_legacy_box_type();
|
|
61443
61579
|
init_legacy_component();
|
|
61444
61580
|
init_legacy_ele_type();
|
|
@@ -62147,6 +62283,8 @@ Original error: ${originalError.name}: ${originalError.message}` : "";
|
|
|
62147
62283
|
}
|
|
62148
62284
|
|
|
62149
62285
|
.fx-formula-kity-host .kf-editor {
|
|
62286
|
+
box-sizing: border-box;
|
|
62287
|
+
width: 100%;
|
|
62150
62288
|
height: var(--fx-formula-editor-body-height) !important;
|
|
62151
62289
|
overflow: visible !important;
|
|
62152
62290
|
}
|