@formulaxjs/editor 0.1.1 → 0.3.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.
@@ -21,6 +21,105 @@ var FormulaX = (() => {
21
21
  };
22
22
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
23
 
24
+ // ../kity-runtime/public/assets/images/toolbar/btn.png
25
+ var btn_default;
26
+ var init_btn = __esm({
27
+ "../kity-runtime/public/assets/images/toolbar/btn.png"() {
28
+ btn_default = "./btn-5DANP6JY.png";
29
+ }
30
+ });
31
+
32
+ // ../kity-runtime/public/assets/images/toolbar/other.png
33
+ var other_default;
34
+ var init_other = __esm({
35
+ "../kity-runtime/public/assets/images/toolbar/other.png"() {
36
+ other_default = "./other-OMWJFGL5.png";
37
+ }
38
+ });
39
+
40
+ // ../kity-runtime/public/assets/styles/editor.css?url
41
+ var editor_default;
42
+ var init_editor = __esm({
43
+ "../kity-runtime/public/assets/styles/editor.css?url"() {
44
+ editor_default = "./editor-JT5KLVXX.css?url";
45
+ }
46
+ });
47
+
48
+ // ../kity-runtime/public/resource/KF_AMS_BB.woff
49
+ var KF_AMS_BB_default;
50
+ var init_KF_AMS_BB = __esm({
51
+ "../kity-runtime/public/resource/KF_AMS_BB.woff"() {
52
+ KF_AMS_BB_default = "./KF_AMS_BB-5QF7FUSO.woff";
53
+ }
54
+ });
55
+
56
+ // ../kity-runtime/public/resource/KF_AMS_CAL.woff
57
+ var KF_AMS_CAL_default;
58
+ var init_KF_AMS_CAL = __esm({
59
+ "../kity-runtime/public/resource/KF_AMS_CAL.woff"() {
60
+ KF_AMS_CAL_default = "./KF_AMS_CAL-NXRNLAZN.woff";
61
+ }
62
+ });
63
+
64
+ // ../kity-runtime/public/resource/KF_AMS_FRAK.woff
65
+ var KF_AMS_FRAK_default;
66
+ var init_KF_AMS_FRAK = __esm({
67
+ "../kity-runtime/public/resource/KF_AMS_FRAK.woff"() {
68
+ KF_AMS_FRAK_default = "./KF_AMS_FRAK-CO33WWN4.woff";
69
+ }
70
+ });
71
+
72
+ // ../kity-runtime/public/resource/KF_AMS_MAIN.woff
73
+ var KF_AMS_MAIN_default;
74
+ var init_KF_AMS_MAIN = __esm({
75
+ "../kity-runtime/public/resource/KF_AMS_MAIN.woff"() {
76
+ KF_AMS_MAIN_default = "./KF_AMS_MAIN-25QJVAWY.woff";
77
+ }
78
+ });
79
+
80
+ // ../kity-runtime/public/resource/KF_AMS_ROMAN.woff
81
+ var KF_AMS_ROMAN_default;
82
+ var init_KF_AMS_ROMAN = __esm({
83
+ "../kity-runtime/public/resource/KF_AMS_ROMAN.woff"() {
84
+ KF_AMS_ROMAN_default = "./KF_AMS_ROMAN-243BR7HH.woff";
85
+ }
86
+ });
87
+
88
+ // ../kity-runtime/src/asset-manifest.ts
89
+ var kityFontAssets, kityToolbarAssets, kityStyleAssets, kityAssetManifest;
90
+ var init_asset_manifest = __esm({
91
+ "../kity-runtime/src/asset-manifest.ts"() {
92
+ "use strict";
93
+ init_btn();
94
+ init_other();
95
+ init_editor();
96
+ init_KF_AMS_BB();
97
+ init_KF_AMS_CAL();
98
+ init_KF_AMS_FRAK();
99
+ init_KF_AMS_MAIN();
100
+ init_KF_AMS_ROMAN();
101
+ kityFontAssets = {
102
+ KF_AMS_BB: KF_AMS_BB_default,
103
+ KF_AMS_CAL: KF_AMS_CAL_default,
104
+ KF_AMS_FRAK: KF_AMS_FRAK_default,
105
+ KF_AMS_MAIN: KF_AMS_MAIN_default,
106
+ KF_AMS_ROMAN: KF_AMS_ROMAN_default
107
+ };
108
+ kityToolbarAssets = {
109
+ btn: btn_default,
110
+ other: other_default
111
+ };
112
+ kityStyleAssets = {
113
+ editor: editor_default
114
+ };
115
+ kityAssetManifest = {
116
+ fonts: kityFontAssets,
117
+ toolbar: kityToolbarAssets,
118
+ styles: kityStyleAssets
119
+ };
120
+ }
121
+ });
122
+
24
123
  // ../kity-runtime/src/vendor/legacy-box-type.ts
25
124
  var legacyBoxType;
26
125
  var init_legacy_box_type = __esm({
@@ -4919,28 +5018,30 @@ var FormulaX = (() => {
4919
5018
 
4920
5019
  // ../kity-runtime/src/vendor/legacy-ui-utils.ts
4921
5020
  function createLegacyUiUtils() {
4922
- return {
4923
- ele: createElement,
4924
- getRectBox,
4925
- on(target, type, fn) {
4926
- addEvent(target, type, fn);
4927
- return this;
4928
- },
4929
- delegate(target, selector, type, fn) {
4930
- delegateEvent(target, selector, type, fn);
4931
- return this;
4932
- },
4933
- publish(topic, ...args) {
4934
- publish(topic, ...args);
4935
- },
4936
- subscribe,
4937
- getClassList
4938
- };
5021
+ return legacyUiUtils;
4939
5022
  }
5023
+ var legacyUiUtils;
4940
5024
  var init_legacy_ui_utils = __esm({
4941
5025
  "../kity-runtime/src/vendor/legacy-ui-utils.ts"() {
4942
5026
  "use strict";
4943
5027
  init_dom_utils();
5028
+ legacyUiUtils = {
5029
+ ele: createElement,
5030
+ getRectBox,
5031
+ on(target, type, fn) {
5032
+ addEvent(target, type, fn);
5033
+ return this;
5034
+ },
5035
+ delegate(target, selector, type, fn) {
5036
+ delegateEvent(target, selector, type, fn);
5037
+ return this;
5038
+ },
5039
+ publish(topic, ...args) {
5040
+ publish(topic, ...args);
5041
+ },
5042
+ subscribe,
5043
+ getClassList
5044
+ };
4944
5045
  }
4945
5046
  });
4946
5047
 
@@ -4963,7 +5064,11 @@ var FormulaX = (() => {
4963
5064
  var init_toolbar_assets = __esm({
4964
5065
  "../kity-runtime/src/toolbar-assets.ts"() {
4965
5066
  "use strict";
4966
- toolbarAssetFileMap = {};
5067
+ init_asset_manifest();
5068
+ toolbarAssetFileMap = {
5069
+ "btn.png": kityToolbarAssets.btn,
5070
+ "other.png": kityToolbarAssets.other
5071
+ };
4967
5072
  }
4968
5073
  });
4969
5074
 
@@ -7357,18 +7462,18 @@ var FormulaX = (() => {
7357
7462
  this.addPoint(p0[0], p0[1]);
7358
7463
  this.addPoint(p3[0], p3[1]);
7359
7464
  for (i = 0; i <= 1; i++) {
7360
- let f = function(t3) {
7361
- return Math.pow(1 - t3, 3) * p0[i] + 3 * Math.pow(1 - t3, 2) * t3 * p1[i] + 3 * (1 - t3) * Math.pow(t3, 2) * p2[i] + Math.pow(t3, 3) * p3[i];
7465
+ let f = function(t) {
7466
+ return Math.pow(1 - t, 3) * p0[i] + 3 * Math.pow(1 - t, 2) * t * p1[i] + 3 * (1 - t) * Math.pow(t, 2) * p2[i] + Math.pow(t, 3) * p3[i];
7362
7467
  };
7363
7468
  let b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i];
7364
7469
  let a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i];
7365
7470
  let c = 3 * p1[i] - 3 * p0[i];
7366
7471
  if (a == 0) {
7367
7472
  if (b == 0) continue;
7368
- let t3 = -c / b;
7369
- if (0 < t3 && t3 < 1) {
7370
- if (i == 0) this.addX(f(t3));
7371
- if (i == 1) this.addY(f(t3));
7473
+ let t = -c / b;
7474
+ if (0 < t && t < 1) {
7475
+ if (i == 0) this.addX(f(t));
7476
+ if (i == 1) this.addY(f(t));
7372
7477
  }
7373
7478
  continue;
7374
7479
  }
@@ -14197,16 +14302,16 @@ var FormulaX = (() => {
14197
14302
  };
14198
14303
  _p[5] = {
14199
14304
  value: function() {
14200
- let t2 = true;
14305
+ let t = true;
14201
14306
  return {
14202
- ".": t2,
14203
- "{": t2,
14204
- "}": t2,
14205
- "[": t2,
14206
- "]": t2,
14207
- "(": t2,
14208
- ")": t2,
14209
- "|": t2
14307
+ ".": t,
14308
+ "{": t,
14309
+ "}": t,
14310
+ "[": t,
14311
+ "]": t,
14312
+ "(": t,
14313
+ ")": t,
14314
+ "|": t
14210
14315
  };
14211
14316
  }
14212
14317
  };
@@ -14871,7 +14976,7 @@ var FormulaX = (() => {
14871
14976
  return serviceObject;
14872
14977
  }
14873
14978
  var defaultOptions, components, kity2, kf, KFEditor, editor_default2;
14874
- var init_editor = __esm({
14979
+ var init_editor2 = __esm({
14875
14980
  "../kity-runtime/src/legacy/editor.ts"() {
14876
14981
  "use strict";
14877
14982
  init_legacy_utils();
@@ -14991,7 +15096,7 @@ var FormulaX = (() => {
14991
15096
  var init_factory = __esm({
14992
15097
  "../kity-runtime/src/legacy/factory.ts"() {
14993
15098
  "use strict";
14994
- init_editor();
15099
+ init_editor2();
14995
15100
  init_runtime_interop();
14996
15101
  EditorWrapper = class {
14997
15102
  callbacks = [];
@@ -19949,7 +20054,7 @@ var FormulaX = (() => {
19949
20054
  var init_start = __esm({
19950
20055
  "../kity-runtime/src/boot/start.ts"() {
19951
20056
  "use strict";
19952
- init_editor();
20057
+ init_editor2();
19953
20058
  init_factory();
19954
20059
  init_ui();
19955
20060
  init_parser();
@@ -19966,87 +20071,18 @@ var FormulaX = (() => {
19966
20071
  // src/index.ts
19967
20072
  var index_exports = {};
19968
20073
  __export(index_exports, {
19969
- DEFAULT_FORMULA_ATTRIBUTE: () => DEFAULT_FORMULA_ATTRIBUTE,
19970
- DEFAULT_FORMULA_CLASS: () => DEFAULT_FORMULA_CLASS,
19971
- FORMULA_FLAG_ATTRIBUTE: () => FORMULA_FLAG_ATTRIBUTE,
19972
- FormulaEditor: () => FormulaEditor,
19973
- createFormulaElement: () => createFormulaElement,
19974
- createFormulaMarkup: () => createFormulaMarkup,
19975
- editorStyles: () => editorStyles,
20074
+ clearFormulaXPerfMarks: () => clearFormulaXPerfMarks2,
19976
20075
  ensureFormulaXModalStyles: () => ensureFormulaXModalStyles,
19977
- escapeAttribute: () => escapeAttribute,
19978
- escapeHtml: () => escapeHtml,
19979
- findFormulaElement: () => findFormulaElement,
19980
20076
  formulaXModalStyles: () => formulaXModalStyles,
19981
- getFormulaLatexFromElement: () => getFormulaLatexFromElement,
19982
- isFormulaElement: () => isFormulaElement,
19983
- mountFormulaXKityEditor: () => mountFormulaXKityEditor,
19984
- renderInteractiveHtml: () => renderInteractiveHtml,
19985
- replaceFormulaElement: () => replaceFormulaElement,
19986
- serializeSvgForInsertion: () => serializeSvgForInsertion,
19987
- t: () => t,
19988
- translations: () => translations
19989
- });
19990
-
19991
- // src/dom-renderer.ts
19992
- var joinPath = (path) => path.join(".");
19993
- var renderInteractiveHtml = (doc2, activePath) => `
19994
- <div class="fx-editor-surface" data-role="surface">
19995
- ${renderChildren(doc2.body, [], activePath)}
19996
- </div>
19997
- `;
19998
- var renderChildren = (nodes, basePath, activePath) => {
19999
- const html = [];
20000
- for (let index = 0; index <= nodes.length; index += 1) {
20001
- const path = joinPath([...basePath, index]);
20002
- const isActive = path === joinPath(activePath);
20003
- html.push(
20004
- `<button class="fx-slot${isActive ? " is-active" : ""}" data-path="${path}" type="button" title="${path}"></button>`
20005
- );
20006
- if (index < nodes.length) {
20007
- html.push(renderNode(nodes[index], [...basePath, index], activePath));
20008
- }
20009
- }
20010
- return html.join("");
20011
- };
20012
- var renderNode = (node, path, activePath) => {
20013
- const pathValue = joinPath(path);
20014
- const isActive = (p) => joinPath(p) === joinPath(activePath);
20015
- switch (node.type) {
20016
- case "text":
20017
- return `<span class="fx-node fx-text" data-node-path="${pathValue}">${node.value}</span>`;
20018
- case "group":
20019
- return `<span class="fx-node fx-group" data-node-path="${pathValue}">${renderChildren(node.body, [...path, 0], activePath)}</span>`;
20020
- case "frac":
20021
- return `<span class="fx-node fx-frac" data-node-path="${pathValue}">
20022
- <span class="fx-frac-num${isActive([...path, 0]) ? " is-active" : ""}" data-path="${joinPath([...path, 0])}">${renderChildren(node.numerator, [...path, 0], activePath)}</span>
20023
- <span class="fx-frac-line"></span>
20024
- <span class="fx-frac-den${isActive([...path, 1]) ? " is-active" : ""}" data-path="${joinPath([...path, 1])}">${renderChildren(node.denominator, [...path, 1], activePath)}</span>
20025
- </span>`;
20026
- case "supsub":
20027
- return `<span class="fx-node fx-supsub" data-node-path="${pathValue}">
20028
- <span class="fx-supsub-base">${renderChildren(node.base, [...path, 0], activePath)}</span>
20029
- <span class="fx-supsub-stack">
20030
- <span class="fx-sup${isActive([...path, 1]) ? " is-active" : ""}" data-path="${joinPath([...path, 1])}">${renderChildren(node.sup ?? [], [...path, 1], activePath)}</span>
20031
- <span class="fx-sub${isActive([...path, 2]) ? " is-active" : ""}" data-path="${joinPath([...path, 2])}">${renderChildren(node.sub ?? [], [...path, 2], activePath)}</span>
20032
- </span>
20033
- </span>`;
20034
- case "sqrt":
20035
- return `<span class="fx-node fx-sqrt" data-node-path="${pathValue}">
20036
- <span class="fx-sqrt-symbol">\u221A</span>
20037
- <span class="fx-sqrt-body${isActive([...path, 0]) ? " is-active" : ""}" data-path="${joinPath([...path, 0])}">${renderChildren(node.value, [...path, 0], activePath)}</span>
20038
- </span>`;
20039
- case "fenced":
20040
- return `<span class="fx-node fx-fenced" data-node-path="${pathValue}">
20041
- <span class="fx-fence">${node.left}</span>
20042
- <span class="fx-fenced-body${isActive([...path, 0]) ? " is-active" : ""}" data-path="${joinPath([...path, 0])}">${renderChildren(node.body, [...path, 0], activePath)}</span>
20043
- <span class="fx-fence">${node.right}</span>
20044
- </span>`;
20045
- case "doc":
20046
- return renderChildren(node.body, [0], activePath);
20047
- }
20048
- throw new Error(`Unsupported node type: ${String(node.type)}`);
20049
- };
20077
+ markFormulaXPerf: () => markFormulaXPerf2,
20078
+ measureFormulaXPerf: () => measureFormulaXPerf2,
20079
+ mountFormulaXEditor: () => mountFormulaXEditor,
20080
+ preloadFormulaXEditor: () => preloadFormulaXEditor,
20081
+ recordFormulaXPerfPoint: () => recordFormulaXPerfPoint,
20082
+ renderFormulaXEditorLoadingState: () => renderFormulaXEditorLoadingState,
20083
+ scheduleFormulaXEditorPreload: () => scheduleFormulaXEditorPreload,
20084
+ waitForFormulaXAnimationFrame: () => waitForFormulaXAnimationFrame
20085
+ });
20050
20086
 
20051
20087
  // ../core/src/ast.ts
20052
20088
  var text = (value) => ({ type: "text", value });
@@ -20071,125 +20107,11 @@ var FormulaX = (() => {
20071
20107
  body
20072
20108
  });
20073
20109
 
20074
- // ../core/src/traversal.ts
20075
- var resolveContainer = (node, branch) => {
20076
- switch (node.type) {
20077
- case "doc":
20078
- case "group":
20079
- if (branch !== 0) throw new Error("Invalid branch");
20080
- return node.body;
20081
- case "frac":
20082
- if (branch === 0) return node.numerator;
20083
- if (branch === 1) return node.denominator;
20084
- break;
20085
- case "supsub":
20086
- if (branch === 0) return node.base;
20087
- if (branch === 1) return node.sup ?? (node.sup = []);
20088
- if (branch === 2) return node.sub ?? (node.sub = []);
20089
- break;
20090
- case "sqrt":
20091
- if (branch !== 0) throw new Error("Invalid branch");
20092
- return node.value;
20093
- case "fenced":
20094
- if (branch !== 0) throw new Error("Invalid branch");
20095
- return node.body;
20096
- default:
20097
- break;
20098
- }
20099
- throw new Error("Invalid branch");
20100
- };
20101
- var cloneDoc = (node) => structuredClone(node);
20102
- var resolveParent = (root2, path) => {
20103
- if (path.length === 0) {
20104
- return { container: root2.body, index: root2.body.length };
20105
- }
20106
- if (path.length === 1) {
20107
- return { container: root2.body, index: path[0] };
20108
- }
20109
- let current = root2.body[path[0]];
20110
- if (!current) {
20111
- return { container: root2.body, index: path[0] };
20112
- }
20113
- let container = root2.body;
20114
- for (let i2 = 1; i2 < path.length - 2; i2 += 2) {
20115
- const branch = path[i2];
20116
- const index = path[i2 + 1];
20117
- container = resolveContainer(current, branch);
20118
- current = container[index];
20119
- }
20120
- container = resolveContainer(current, path[path.length - 2]);
20121
- return {
20122
- container,
20123
- index: path[path.length - 1] ?? container.length
20124
- };
20125
- };
20126
- var insertAtPath = (root2, path, node) => {
20127
- const next = cloneDoc(root2);
20128
- const { container, index } = resolveParent(next, path);
20129
- container.splice(index, 0, node);
20130
- return next;
20131
- };
20132
- var removeAtPath = (root2, path) => {
20133
- const next = cloneDoc(root2);
20134
- const { container, index } = resolveParent(next, path);
20135
- if (index > 0) {
20136
- container.splice(index - 1, 1);
20137
- }
20138
- return next;
20139
- };
20140
-
20141
- // ../core/src/transaction.ts
20142
- var FormulaTransaction = class {
20143
- doc;
20144
- selection;
20145
- constructor(state) {
20146
- this.doc = structuredClone(state.doc);
20147
- this.selection = structuredClone(state.selection);
20148
- }
20149
- insert(node) {
20150
- this.doc = insertAtPath(this.doc, this.selection.focus, node);
20151
- this.selection = {
20152
- anchor: [...this.selection.focus],
20153
- focus: [...this.selection.focus.slice(0, -1), (this.selection.focus.at(-1) ?? 0) + 1]
20154
- };
20155
- return this;
20156
- }
20157
- deleteBackward() {
20158
- this.doc = removeAtPath(this.doc, this.selection.focus);
20159
- this.selection = {
20160
- anchor: [...this.selection.focus.slice(0, -1), Math.max((this.selection.focus.at(-1) ?? 0) - 1, 0)],
20161
- focus: [...this.selection.focus.slice(0, -1), Math.max((this.selection.focus.at(-1) ?? 0) - 1, 0)]
20162
- };
20163
- return this;
20164
- }
20165
- moveFocus(nextFocus) {
20166
- this.selection = {
20167
- anchor: [...nextFocus],
20168
- focus: [...nextFocus]
20169
- };
20170
- return this;
20171
- }
20172
- apply() {
20173
- return {
20174
- doc: this.doc,
20175
- selection: this.selection
20176
- };
20177
- }
20178
- };
20179
-
20180
20110
  // ../core/src/commands.ts
20181
- var insertText = (value) => (state) => new FormulaTransaction(state).insert(text(value)).apply();
20182
- var insertFraction = () => (state) => new FormulaTransaction(state).insert(frac([], [])).apply();
20183
- var insertSuperscript = () => (state) => new FormulaTransaction(state).insert(supsub([text("x")], [text("2")])).apply();
20184
- var insertSubscript = () => (state) => new FormulaTransaction(state).insert(supsub([text("x")], void 0, [text("i")])).apply();
20185
- var insertSqrt = () => (state) => new FormulaTransaction(state).insert(sqrt([])).apply();
20186
- var insertFenced = (left = "(", right = ")") => (state) => new FormulaTransaction(state).insert(fenced(left, right, [])).apply();
20187
- var backspace = () => (state) => new FormulaTransaction(state).deleteBackward().apply();
20188
20111
  var createEmptyState = () => ({
20189
20112
  doc: { type: "doc", body: [] },
20190
20113
  selection: { anchor: [0], focus: [0] }
20191
20114
  });
20192
- var applyCommand = (state, command) => command(state);
20193
20115
 
20194
20116
  // ../core/src/latex.ts
20195
20117
  var isAlpha = (char) => /[a-zA-Z]/.test(char);
@@ -20447,337 +20369,11 @@ var FormulaX = (() => {
20447
20369
  };
20448
20370
  var parseLatex = (input) => new LatexParser(input).parse();
20449
20371
 
20450
- // src/styles.ts
20451
- var editorStyles = `
20452
- @keyframes fx-blink {
20453
- 0%, 50% { opacity: 1; }
20454
- 51%, 100% { opacity: 0; }
20455
- }
20456
- .fx-editor {
20457
- border: 1px solid #d8d4c7;
20458
- border-radius: 2px;
20459
- background: #fffefb;
20460
- box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
20461
- padding: 24px 28px;
20462
- font-family: Cambria, 'Times New Roman', serif;
20463
- font-size: 25px;
20464
- line-height: 1.7;
20465
- min-height: 120px;
20466
- position: relative;
20467
- }
20468
- .fx-editor:focus-within {
20469
- border-color: #7bbb59;
20470
- box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7), 0 0 0 3px rgba(123, 187, 89, 0.18);
20471
- }
20472
- .fx-editor-surface {
20473
- display: flex;
20474
- flex-wrap: wrap;
20475
- align-items: baseline;
20476
- gap: 3px;
20477
- cursor: text;
20478
- }
20479
- .fx-node {
20480
- position: relative;
20481
- display: inline-flex;
20482
- align-items: center;
20483
- padding: 2px 3px;
20484
- border-radius: 2px;
20485
- transition: background 0.12s ease;
20486
- }
20487
- .fx-node:hover {
20488
- background: rgba(122, 186, 89, 0.12);
20489
- }
20490
- .fx-text {
20491
- color: #2b2925;
20492
- }
20493
- .fx-group {
20494
- background: rgba(243, 241, 230, 0.82);
20495
- border: 1px dashed #c8c0a8;
20496
- }
20497
- .fx-frac {
20498
- display: inline-flex;
20499
- flex-direction: column;
20500
- align-items: center;
20501
- vertical-align: middle;
20502
- padding: 0 5px;
20503
- }
20504
- .fx-frac-num, .fx-frac-den {
20505
- display: flex;
20506
- flex-wrap: wrap;
20507
- align-items: center;
20508
- justify-content: center;
20509
- padding: 3px 8px;
20510
- min-width: 24px;
20511
- min-height: 28px;
20512
- border-radius: 2px;
20513
- transition: all 0.15s ease;
20514
- }
20515
- .fx-frac-num {
20516
- border-bottom: 2px solid #2e2c29;
20517
- padding-bottom: 6px;
20518
- }
20519
- .fx-frac-den {
20520
- border-top: 2px solid #2e2c29;
20521
- padding-top: 6px;
20522
- }
20523
- .fx-frac-num:hover, .fx-frac-den:hover {
20524
- background: rgba(122, 186, 89, 0.1);
20525
- }
20526
- .fx-frac-num.is-active, .fx-frac-den.is-active {
20527
- background: rgba(122, 186, 89, 0.16);
20528
- box-shadow: inset 0 0 0 1px rgba(83, 184, 86, 0.5);
20529
- }
20530
- .fx-supsub {
20531
- display: inline-flex;
20532
- align-items: baseline;
20533
- gap: 0;
20534
- }
20535
- .fx-supsub-base {
20536
- display: inline-flex;
20537
- align-items: center;
20538
- padding: 0 2px;
20539
- }
20540
- .fx-supsub-stack {
20541
- display: inline-flex;
20542
- flex-direction: column;
20543
- align-items: flex-start;
20544
- font-size: 0.65em;
20545
- margin-left: 2px;
20546
- }
20547
- .fx-sup, .fx-sub {
20548
- display: flex;
20549
- align-items: center;
20550
- min-width: 16px;
20551
- min-height: 20px;
20552
- padding: 0 4px;
20553
- border-radius: 2px;
20554
- transition: all 0.15s ease;
20555
- }
20556
- .fx-sup {
20557
- vertical-align: super;
20558
- }
20559
- .fx-sub {
20560
- vertical-align: sub;
20561
- }
20562
- .fx-sup:hover, .fx-sub:hover {
20563
- background: rgba(122, 186, 89, 0.1);
20564
- }
20565
- .fx-sup.is-active, .fx-sub.is-active {
20566
- background: rgba(122, 186, 89, 0.16);
20567
- box-shadow: inset 0 0 0 1px rgba(83, 184, 86, 0.5);
20568
- }
20569
- .fx-sqrt {
20570
- display: inline-flex;
20571
- align-items: baseline;
20572
- }
20573
- .fx-sqrt-symbol {
20574
- font-size: 1.1em;
20575
- color: #2e2c29;
20576
- margin-right: 2px;
20577
- }
20578
- .fx-sqrt-body {
20579
- display: inline-flex;
20580
- align-items: center;
20581
- border-top: 2px solid #2e2c29;
20582
- padding: 4px 6px 0;
20583
- margin-left: 2px;
20584
- }
20585
- .fx-sqrt-body:hover {
20586
- background: rgba(122, 186, 89, 0.1);
20587
- }
20588
- .fx-sqrt-body.is-active {
20589
- background: rgba(122, 186, 89, 0.16);
20590
- }
20591
- .fx-fenced {
20592
- display: inline-flex;
20593
- align-items: center;
20594
- background: rgba(243, 241, 230, 0.78);
20595
- border-radius: 3px;
20596
- padding: 0 4px;
20597
- }
20598
- .fx-fence {
20599
- color: #59554d;
20600
- font-size: 1.2em;
20601
- padding: 0 2px;
20602
- }
20603
- .fx-fenced-body {
20604
- display: inline-flex;
20605
- align-items: center;
20606
- padding: 0 6px;
20607
- }
20608
- .fx-fenced-body:hover {
20609
- background: rgba(122, 186, 89, 0.1);
20610
- border-radius: 2px;
20611
- }
20612
- .fx-fenced-body.is-active {
20613
- background: rgba(122, 186, 89, 0.16);
20614
- border-radius: 2px;
20615
- }
20616
- .fx-slot {
20617
- width: 3px;
20618
- height: 1.2em;
20619
- border: none;
20620
- background: #53b856;
20621
- padding: 0;
20622
- margin: 0 1px;
20623
- cursor: text;
20624
- border-radius: 1px;
20625
- vertical-align: middle;
20626
- }
20627
- .fx-slot.is-active {
20628
- animation: fx-blink 1s infinite;
20629
- }
20630
- .fx-slot:hover {
20631
- background: #77c75b;
20632
- }
20633
- `;
20634
-
20635
- // src/editor.ts
20636
- var FormulaEditor = class {
20637
- state;
20638
- root;
20639
- onChange;
20640
- locale;
20641
- constructor(options) {
20642
- this.root = options.root;
20643
- this.state = options.initialState ?? createEmptyState();
20644
- this.onChange = options.onChange;
20645
- this.locale = options.locale ?? "en";
20646
- this.root.classList.add("fx-editor");
20647
- this.root.tabIndex = 0;
20648
- this.ensureStyles();
20649
- this.bindEvents();
20650
- this.render();
20651
- }
20652
- getState() {
20653
- return structuredClone(this.state);
20654
- }
20655
- getLocale() {
20656
- return this.locale;
20657
- }
20658
- setState(state) {
20659
- this.state = structuredClone(state);
20660
- this.render();
20661
- }
20662
- dispatch(command) {
20663
- this.state = applyCommand(this.state, command);
20664
- this.render();
20665
- this.onChange?.(this.getState());
20666
- }
20667
- ensureStyles() {
20668
- if (document.getElementById("fx-editor-styles")) return;
20669
- const style = document.createElement("style");
20670
- style.id = "fx-editor-styles";
20671
- style.textContent = editorStyles;
20672
- document.head.appendChild(style);
20673
- }
20674
- bindEvents() {
20675
- this.root.addEventListener("click", (event2) => {
20676
- const target = event2.target;
20677
- const pathValue = target.dataset.path;
20678
- if (pathValue === void 0) return;
20679
- const path = pathValue === "" ? [] : pathValue.split(".").map(Number);
20680
- this.moveSelection(path);
20681
- });
20682
- this.root.addEventListener("keydown", (event2) => {
20683
- if (event2.key === "Backspace") {
20684
- event2.preventDefault();
20685
- this.dispatch(backspace());
20686
- return;
20687
- }
20688
- if (event2.key === "/") {
20689
- event2.preventDefault();
20690
- this.dispatch(insertFraction());
20691
- return;
20692
- }
20693
- if (event2.key === "^") {
20694
- event2.preventDefault();
20695
- this.dispatch(insertSuperscript());
20696
- return;
20697
- }
20698
- if (event2.key === "_") {
20699
- event2.preventDefault();
20700
- this.dispatch(insertSubscript());
20701
- return;
20702
- }
20703
- if (event2.key === "r" && event2.ctrlKey) {
20704
- event2.preventDefault();
20705
- this.dispatch(insertSqrt());
20706
- return;
20707
- }
20708
- if (event2.key === "(") {
20709
- event2.preventDefault();
20710
- this.dispatch(insertFenced("(", ")"));
20711
- return;
20712
- }
20713
- if (event2.key.length === 1 && !event2.ctrlKey && !event2.metaKey) {
20714
- event2.preventDefault();
20715
- this.dispatch(insertText(event2.key));
20716
- }
20717
- });
20718
- }
20719
- moveSelection(path) {
20720
- this.state = {
20721
- ...this.state,
20722
- selection: {
20723
- anchor: [...path],
20724
- focus: [...path]
20725
- }
20726
- };
20727
- this.render();
20728
- this.onChange?.(this.getState());
20729
- }
20730
- render() {
20731
- this.root.innerHTML = renderInteractiveHtml(this.state.doc, this.state.selection.focus);
20732
- }
20733
- };
20734
-
20735
- // ../kity-runtime/public/assets/images/toolbar/btn.png
20736
- var btn_default = "./btn-5DANP6JY.png";
20737
-
20738
- // ../kity-runtime/public/assets/images/toolbar/other.png
20739
- var other_default = "./other-OMWJFGL5.png";
20740
-
20741
- // ../kity-runtime/public/assets/styles/editor.css?url
20742
- var editor_default = "./editor-JT5KLVXX.css?url";
20743
-
20744
- // ../kity-runtime/public/resource/KF_AMS_BB.woff
20745
- var KF_AMS_BB_default = "./KF_AMS_BB-5QF7FUSO.woff";
20746
-
20747
- // ../kity-runtime/public/resource/KF_AMS_CAL.woff
20748
- var KF_AMS_CAL_default = "./KF_AMS_CAL-NXRNLAZN.woff";
20749
-
20750
- // ../kity-runtime/public/resource/KF_AMS_FRAK.woff
20751
- var KF_AMS_FRAK_default = "./KF_AMS_FRAK-CO33WWN4.woff";
20752
-
20753
- // ../kity-runtime/public/resource/KF_AMS_MAIN.woff
20754
- var KF_AMS_MAIN_default = "./KF_AMS_MAIN-25QJVAWY.woff";
20755
-
20756
- // ../kity-runtime/public/resource/KF_AMS_ROMAN.woff
20757
- var KF_AMS_ROMAN_default = "./KF_AMS_ROMAN-243BR7HH.woff";
20758
-
20759
- // ../kity-runtime/src/asset-manifest.ts
20760
- var kityFontAssets = {
20761
- KF_AMS_BB: KF_AMS_BB_default,
20762
- KF_AMS_CAL: KF_AMS_CAL_default,
20763
- KF_AMS_FRAK: KF_AMS_FRAK_default,
20764
- KF_AMS_MAIN: KF_AMS_MAIN_default,
20765
- KF_AMS_ROMAN: KF_AMS_ROMAN_default
20766
- };
20767
- var kityToolbarAssets = {
20768
- btn: btn_default,
20769
- other: other_default
20770
- };
20771
- var kityStyleAssets = {
20772
- editor: editor_default
20773
- };
20774
- var kityAssetManifest = {
20775
- fonts: kityFontAssets,
20776
- toolbar: kityToolbarAssets,
20777
- styles: kityStyleAssets
20778
- };
20372
+ // ../kity-runtime/src/index.ts
20373
+ init_asset_manifest();
20779
20374
 
20780
20375
  // ../kity-runtime/src/create-editor.ts
20376
+ init_asset_manifest();
20781
20377
  init_legacy_box_type();
20782
20378
 
20783
20379
  // ../kity-runtime/src/vendor/char-position.ts
@@ -23270,19 +22866,19 @@ var FormulaX = (() => {
23270
22866
  return this;
23271
22867
  },
23272
22868
  _applyTransform() {
23273
- const t2 = this.transform;
22869
+ const t = this.transform;
23274
22870
  const result = [];
23275
- if (t2.translate) {
23276
- result.push(["translate(", t2.translate, ")"]);
22871
+ if (t.translate) {
22872
+ result.push(["translate(", t.translate, ")"]);
23277
22873
  }
23278
- if (t2.rotate) {
23279
- result.push(["rotate(", t2.rotate, ")"]);
22874
+ if (t.rotate) {
22875
+ result.push(["rotate(", t.rotate, ")"]);
23280
22876
  }
23281
- if (t2.scale) {
23282
- result.push(["scale(", t2.scale, ")"]);
22877
+ if (t.scale) {
22878
+ result.push(["scale(", t.scale, ")"]);
23283
22879
  }
23284
- if (t2.matrix) {
23285
- result.push(["matrix(", t2.matrix, ")"]);
22880
+ if (t.matrix) {
22881
+ result.push(["matrix(", t.matrix, ")"]);
23286
22882
  }
23287
22883
  this.node.setAttribute("transform", utils_default.flatten(result).join(" "));
23288
22884
  return this;
@@ -23291,8 +22887,8 @@ var FormulaX = (() => {
23291
22887
  this.transform.matrix = m;
23292
22888
  return this._applyTransform();
23293
22889
  },
23294
- setTranslate(t2) {
23295
- this.transform.translate = t2 !== null && [].slice.call(arguments) || null;
22890
+ setTranslate(t) {
22891
+ this.transform.translate = t !== null && [].slice.call(arguments) || null;
23296
22892
  return this._applyTransform();
23297
22893
  },
23298
22894
  setRotate(r) {
@@ -24180,13 +23776,87 @@ var FormulaX = (() => {
24180
23776
  targetWindow.kity = kity;
24181
23777
  }
24182
23778
 
23779
+ // ../kity-runtime/src/perf.ts
23780
+ function getPerfHost() {
23781
+ return globalThis;
23782
+ }
23783
+ function getPerfState() {
23784
+ const host = getPerfHost();
23785
+ host.__FORMULAX_PERF_STATE__ ??= {
23786
+ reportedMeasureCount: 0,
23787
+ reportScheduled: false
23788
+ };
23789
+ return host.__FORMULAX_PERF_STATE__;
23790
+ }
23791
+ function hasPerfSupport() {
23792
+ return typeof performance !== "undefined" && typeof performance.mark === "function" && typeof performance.measure === "function" && typeof performance.getEntriesByType === "function";
23793
+ }
23794
+ function isPerfDebugEnabled() {
23795
+ return getPerfHost().__FORMULAX_PERF__ === true;
23796
+ }
23797
+ function schedulePerfReport() {
23798
+ if (!hasPerfSupport() || !isPerfDebugEnabled()) {
23799
+ return;
23800
+ }
23801
+ const state = getPerfState();
23802
+ if (state.reportScheduled) {
23803
+ return;
23804
+ }
23805
+ state.reportScheduled = true;
23806
+ queueMicrotask(() => {
23807
+ state.reportScheduled = false;
23808
+ const entries = performance.getEntriesByType("measure").filter((entry) => entry.name.startsWith("fx:")).sort((left, right) => left.startTime - right.startTime);
23809
+ const nextEntries = entries.slice(state.reportedMeasureCount);
23810
+ state.reportedMeasureCount = entries.length;
23811
+ if (!nextEntries.length) {
23812
+ return;
23813
+ }
23814
+ console.table(nextEntries.map((entry) => ({
23815
+ name: entry.name,
23816
+ duration: Number(entry.duration.toFixed(2)),
23817
+ startTime: Number(entry.startTime.toFixed(2))
23818
+ })));
23819
+ });
23820
+ }
23821
+ function markFormulaXPerf(name) {
23822
+ if (!hasPerfSupport()) {
23823
+ return null;
23824
+ }
23825
+ const markName = `${name}::${Date.now()}::${Math.random().toString(36).slice(2, 8)}`;
23826
+ performance.mark(markName);
23827
+ return markName;
23828
+ }
23829
+ function measureFormulaXPerf(name, startMark, endMark) {
23830
+ if (!hasPerfSupport() || !startMark) {
23831
+ return null;
23832
+ }
23833
+ const resolvedEndMark = endMark ?? markFormulaXPerf(`${name}:end`);
23834
+ if (!resolvedEndMark) {
23835
+ return null;
23836
+ }
23837
+ performance.measure(name, startMark, resolvedEndMark);
23838
+ schedulePerfReport();
23839
+ return resolvedEndMark;
23840
+ }
23841
+ function clearFormulaXPerfMarks(...marks) {
23842
+ if (!hasPerfSupport()) {
23843
+ return;
23844
+ }
23845
+ for (const mark of marks) {
23846
+ if (!mark) {
23847
+ continue;
23848
+ }
23849
+ performance.clearMarks(mark);
23850
+ }
23851
+ }
23852
+
24183
23853
  // ../kity-runtime/src/create-editor.ts
24184
23854
  init_toolbar_assets();
24185
23855
  var DEFAULT_LATEX = "x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}";
24186
23856
  var DEFAULT_EDITOR_HEIGHT = "auto";
24187
23857
  var KITY_STYLE_ID = "formulax-kity-editor-styles";
24188
23858
  var runtimePromise = null;
24189
- function resolveContainer2(el) {
23859
+ function resolveContainer(el) {
24190
23860
  if (typeof el === "string") {
24191
23861
  const element = document.querySelector(el);
24192
23862
  if (!(element instanceof HTMLElement)) {
@@ -24220,13 +23890,14 @@ var FormulaX = (() => {
24220
23890
  }
24221
23891
  function ensureKityStylesheet(doc2, href) {
24222
23892
  if (doc2.getElementById(KITY_STYLE_ID)) {
24223
- return;
23893
+ return false;
24224
23894
  }
24225
23895
  const link = doc2.createElement("link");
24226
23896
  link.id = KITY_STYLE_ID;
24227
23897
  link.rel = "stylesheet";
24228
23898
  link.href = href;
24229
23899
  doc2.head.appendChild(link);
23900
+ return true;
24230
23901
  }
24231
23902
  function hydrateLegacyKf(runtimeWindow) {
24232
23903
  const requireFormula = runtimeWindow.__kityFormulaRequire__;
@@ -24274,7 +23945,7 @@ var FormulaX = (() => {
24274
23945
  kity: runtimeWindow.kity,
24275
23946
  otherPosition: legacyOtherPosition,
24276
23947
  uiDef: legacyUiDef,
24277
- uiUtils: createLegacyUiUtils()
23948
+ uiUtils: legacyUiUtils
24278
23949
  };
24279
23950
  }
24280
23951
  async function ensureKityRuntime() {
@@ -24282,65 +23953,115 @@ var FormulaX = (() => {
24282
23953
  return runtimePromise;
24283
23954
  }
24284
23955
  runtimePromise = (async () => {
23956
+ const runtimeTotalStart = markFormulaXPerf("fx:kity-runtime:total");
24285
23957
  const runtimeWindow = window;
24286
23958
  runtimeWindow.kf = runtimeWindow.kf ?? {};
24287
23959
  installKityRuntime(runtimeWindow);
24288
- const { installLegacyKityFormulaRuntime: installLegacyKityFormulaRuntime2 } = await Promise.resolve().then(() => (init_install(), install_exports));
24289
- installLegacyKityFormulaRuntime2(runtimeWindow);
24290
- hydrateLegacyKf(runtimeWindow);
24291
- const { installLegacyParserRuntime: installLegacyParserRuntime2 } = await Promise.resolve().then(() => (init_install2(), install_exports2));
24292
- installLegacyParserRuntime2(runtimeWindow);
24293
- installLegacyRuntime(runtimeWindow);
24294
- const { installKityEditorStart: installKityEditorStart2 } = await Promise.resolve().then(() => (init_start(), start_exports));
24295
- installKityEditorStart2(runtimeWindow);
23960
+ try {
23961
+ const formulaImportStart = markFormulaXPerf("fx:kity-runtime:formula-import");
23962
+ const { installLegacyKityFormulaRuntime: installLegacyKityFormulaRuntime2 } = await Promise.resolve().then(() => (init_install(), install_exports));
23963
+ const formulaImportEnd = markFormulaXPerf("fx:kity-runtime:formula-import:end");
23964
+ measureFormulaXPerf("fx:kity-runtime:formula-import", formulaImportStart, formulaImportEnd);
23965
+ clearFormulaXPerfMarks(formulaImportStart, formulaImportEnd);
23966
+ const formulaInstallStart = markFormulaXPerf("fx:kity-runtime:formula-install");
23967
+ installLegacyKityFormulaRuntime2(runtimeWindow);
23968
+ hydrateLegacyKf(runtimeWindow);
23969
+ const formulaInstallEnd = markFormulaXPerf("fx:kity-runtime:formula-install:end");
23970
+ measureFormulaXPerf("fx:kity-runtime:formula-install", formulaInstallStart, formulaInstallEnd);
23971
+ clearFormulaXPerfMarks(formulaInstallStart, formulaInstallEnd);
23972
+ const parserImportStart = markFormulaXPerf("fx:kity-runtime:parser-import");
23973
+ const { installLegacyParserRuntime: installLegacyParserRuntime2 } = await Promise.resolve().then(() => (init_install2(), install_exports2));
23974
+ const parserImportEnd = markFormulaXPerf("fx:kity-runtime:parser-import:end");
23975
+ measureFormulaXPerf("fx:kity-runtime:parser-import", parserImportStart, parserImportEnd);
23976
+ clearFormulaXPerfMarks(parserImportStart, parserImportEnd);
23977
+ const parserInstallStart = markFormulaXPerf("fx:kity-runtime:parser-install");
23978
+ installLegacyParserRuntime2(runtimeWindow);
23979
+ const parserInstallEnd = markFormulaXPerf("fx:kity-runtime:parser-install:end");
23980
+ measureFormulaXPerf("fx:kity-runtime:parser-install", parserInstallStart, parserInstallEnd);
23981
+ clearFormulaXPerfMarks(parserInstallStart, parserInstallEnd);
23982
+ installLegacyRuntime(runtimeWindow);
23983
+ const bootImportStart = markFormulaXPerf("fx:kity-runtime:boot-import");
23984
+ const { installKityEditorStart: installKityEditorStart2 } = await Promise.resolve().then(() => (init_start(), start_exports));
23985
+ const bootImportEnd = markFormulaXPerf("fx:kity-runtime:boot-import:end");
23986
+ measureFormulaXPerf("fx:kity-runtime:boot-import", bootImportStart, bootImportEnd);
23987
+ clearFormulaXPerfMarks(bootImportStart, bootImportEnd);
23988
+ const bootInstallStart = markFormulaXPerf("fx:kity-runtime:boot-install");
23989
+ installKityEditorStart2(runtimeWindow);
23990
+ const bootInstallEnd = markFormulaXPerf("fx:kity-runtime:boot-install:end");
23991
+ measureFormulaXPerf("fx:kity-runtime:boot-install", bootInstallStart, bootInstallEnd);
23992
+ clearFormulaXPerfMarks(bootInstallStart, bootInstallEnd);
23993
+ } finally {
23994
+ const runtimeTotalEnd = markFormulaXPerf("fx:kity-runtime:total:end");
23995
+ measureFormulaXPerf("fx:kity-runtime:total", runtimeTotalStart, runtimeTotalEnd);
23996
+ clearFormulaXPerfMarks(runtimeTotalStart, runtimeTotalEnd);
23997
+ }
24296
23998
  })();
24297
23999
  return runtimePromise;
24298
24000
  }
24299
24001
  async function createKityEditor(container, options = {}) {
24002
+ const createEditorStart = markFormulaXPerf("fx:create-kity-editor:total");
24300
24003
  const fontsize = options.render?.fontsize ?? 40;
24301
24004
  const editorHeight = normalizeCssSize(options.height, DEFAULT_EDITOR_HEIGHT);
24302
24005
  const assets = resolveEditorAssets(options.assets);
24303
- ensureKityStylesheet(document, assets.styles.editor);
24304
- setToolbarAssetUrls(assets.toolbar);
24305
- await ensureKityRuntime();
24306
- const runtimeWindow = window;
24307
- if (!runtimeWindow.kf?.EditorFactory) {
24308
- throw new Error("Kity editor runtime did not initialize");
24309
- }
24310
- container.innerHTML = "";
24311
- const host = document.createElement("div");
24312
- host.className = "kf-editor";
24313
- host.style.width = "100%";
24314
- host.style.height = editorHeight;
24315
- container.appendChild(host);
24316
- const factory2 = runtimeWindow.kf.EditorFactory.create(host, {
24317
- render: {
24318
- fontsize
24319
- },
24320
- resource: {
24321
- path: "",
24322
- fonts: assets.fonts
24006
+ try {
24007
+ const stylesheetInserted = ensureKityStylesheet(document, assets.styles.editor);
24008
+ if (stylesheetInserted) {
24009
+ const stylesheetInsertedMark = markFormulaXPerf("fx:kity-css:link-inserted");
24010
+ measureFormulaXPerf("fx:kity-css:link-inserted", createEditorStart, stylesheetInsertedMark);
24011
+ clearFormulaXPerfMarks(stylesheetInsertedMark);
24323
24012
  }
24324
- });
24325
- return {
24326
- ready: factory2.ready.bind(factory2),
24327
- execCommand(name, value) {
24328
- factory2.ready(function execWhenReady() {
24329
- this.execCommand(name, value);
24330
- });
24331
- },
24332
- focus() {
24333
- factory2.ready(function focusWhenReady() {
24334
- this.execCommand("focus");
24335
- });
24336
- },
24337
- destroy() {
24338
- container.innerHTML = "";
24339
- },
24340
- host,
24341
- raw: factory2
24342
- };
24343
- }
24013
+ setToolbarAssetUrls(assets.toolbar);
24014
+ await ensureKityRuntime();
24015
+ const runtimeReadyMark = markFormulaXPerf("fx:kity-runtime:ready-for-editor");
24016
+ measureFormulaXPerf("fx:kity-runtime:ready-for-editor", createEditorStart, runtimeReadyMark);
24017
+ clearFormulaXPerfMarks(runtimeReadyMark);
24018
+ const runtimeWindow = window;
24019
+ if (!runtimeWindow.kf?.EditorFactory) {
24020
+ throw new Error("Kity editor runtime did not initialize");
24021
+ }
24022
+ container.innerHTML = "";
24023
+ const host = document.createElement("div");
24024
+ host.className = "kf-editor";
24025
+ host.style.width = "100%";
24026
+ host.style.height = editorHeight;
24027
+ container.appendChild(host);
24028
+ const factoryCreateStart = markFormulaXPerf("fx:kity-editor-factory:create");
24029
+ const factory2 = runtimeWindow.kf.EditorFactory.create(host, {
24030
+ render: {
24031
+ fontsize
24032
+ },
24033
+ resource: {
24034
+ path: "",
24035
+ fonts: assets.fonts
24036
+ }
24037
+ });
24038
+ const factoryCreateEnd = markFormulaXPerf("fx:kity-editor-factory:create:end");
24039
+ measureFormulaXPerf("fx:kity-editor-factory:create", factoryCreateStart, factoryCreateEnd);
24040
+ clearFormulaXPerfMarks(factoryCreateStart, factoryCreateEnd);
24041
+ return {
24042
+ ready: factory2.ready.bind(factory2),
24043
+ execCommand(name, value) {
24044
+ factory2.ready(function execWhenReady() {
24045
+ this.execCommand(name, value);
24046
+ });
24047
+ },
24048
+ focus() {
24049
+ factory2.ready(function focusWhenReady() {
24050
+ this.execCommand("focus");
24051
+ });
24052
+ },
24053
+ destroy() {
24054
+ container.innerHTML = "";
24055
+ },
24056
+ host,
24057
+ raw: factory2
24058
+ };
24059
+ } finally {
24060
+ const createEditorEnd = markFormulaXPerf("fx:create-kity-editor:total:end");
24061
+ measureFormulaXPerf("fx:create-kity-editor:total", createEditorStart, createEditorEnd);
24062
+ clearFormulaXPerfMarks(createEditorStart, createEditorEnd);
24063
+ }
24064
+ }
24344
24065
  async function mountKityEditor(container, options = {}) {
24345
24066
  const editor = await createKityEditor(container, options);
24346
24067
  const initialLatex = options.initialLatex ?? DEFAULT_LATEX;
@@ -24359,7 +24080,7 @@ var FormulaX = (() => {
24359
24080
  handlePromise;
24360
24081
  constructor(options) {
24361
24082
  const { el, ...editorOptions } = options;
24362
- this.container = resolveContainer2(el);
24083
+ this.container = resolveContainer(el);
24363
24084
  this.options = editorOptions;
24364
24085
  this.handlePromise = mountKityEditor(this.container, this.options);
24365
24086
  }
@@ -24410,292 +24131,14 @@ var FormulaX = (() => {
24410
24131
  init_legacy_ui_utils();
24411
24132
  init_legacy_utils();
24412
24133
 
24413
- // src/formula-node.ts
24414
- var DEFAULT_FORMULA_ATTRIBUTE = "data-formulax-latex";
24415
- var FORMULA_FLAG_ATTRIBUTE = "data-formulax";
24416
- var DEFAULT_FORMULA_CLASS = "formulax-math";
24417
- function escapeAttribute(value) {
24418
- return value.replaceAll("&", "&amp;").replaceAll('"', "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
24419
- }
24134
+ // ../renderer/src/markup.ts
24420
24135
  function escapeHtml(value) {
24421
24136
  return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
24422
24137
  }
24423
- function createFormulaMarkup(latex, options = {}) {
24424
- const attributeName = options.attributeName ?? DEFAULT_FORMULA_ATTRIBUTE;
24425
- const className = options.className ?? DEFAULT_FORMULA_CLASS;
24426
- const displayClass = options.displayMode ? `${className} ${className}--block` : className;
24427
- const safeLatex = escapeAttribute(latex);
24428
- const cursorStyle = options.cursorStyle?.trim() || "pointer";
24429
- const extraAttributes = {
24430
- ...options.extraAttributes ?? {},
24431
- style: mergeInlineStyles(
24432
- typeof options.extraAttributes?.style === "string" ? options.extraAttributes.style : "",
24433
- cursorStyle ? `cursor: ${cursorStyle}` : ""
24434
- )
24435
- };
24436
- const serializedAttributes = Object.entries(extraAttributes).filter(([, value]) => value !== null && value !== void 0 && value !== false).map(([key, value]) => value === true ? key : `${key}="${escapeAttribute(String(value))}"`);
24437
- return [
24438
- "<span",
24439
- ` class="${escapeAttribute(displayClass)}"`,
24440
- ` ${FORMULA_FLAG_ATTRIBUTE}="true"`,
24441
- ` ${attributeName}="${safeLatex}"`,
24442
- ` data-latex="${safeLatex}"`,
24443
- ' contenteditable="false"',
24444
- ' role="button"',
24445
- ' tabindex="0"',
24446
- serializedAttributes.length ? ` ${serializedAttributes.join(" ")}` : "",
24447
- ">",
24448
- options.renderHtml ?? `<span class="${escapeAttribute(className)}__render">${escapeHtml(latex || "\\square")}</span>`,
24449
- "</span>"
24450
- ].join("");
24451
- }
24452
- function mergeInlineStyles(existingStyle, nextStyle) {
24453
- const existing = existingStyle.trim().replace(/;+\s*$/, "");
24454
- const next = nextStyle.trim().replace(/;+\s*$/, "");
24455
- if (!existing) return next;
24456
- if (!next) return existing;
24457
- return `${existing}; ${next}`;
24458
- }
24459
- function createFormulaElement(ownerDocument, latex, options = {}) {
24460
- const wrapper = ownerDocument.createElement("span");
24461
- wrapper.innerHTML = createFormulaMarkup(latex, options);
24462
- return wrapper.firstElementChild;
24463
- }
24464
- function replaceFormulaElement(target, latex, options = {}) {
24465
- const next = createFormulaElement(target.ownerDocument ?? document, latex, options);
24466
- if (!next) return null;
24467
- target.replaceWith(next);
24468
- return next;
24469
- }
24470
- function getFormulaLatexFromElement(element, attributeName = DEFAULT_FORMULA_ATTRIBUTE) {
24471
- return element.getAttribute(attributeName) ?? element.getAttribute("data-latex") ?? "";
24472
- }
24473
- function isFormulaElement(node) {
24474
- if (!node || typeof node !== "object") return false;
24475
- const element = node;
24476
- return typeof element.getAttribute === "function" && element.getAttribute(FORMULA_FLAG_ATTRIBUTE) === "true";
24477
- }
24478
- function findFormulaElement(node) {
24479
- if (!node) return null;
24480
- const element = node.nodeType === 1 ? node : node.parentElement;
24481
- return element?.closest?.(`[${FORMULA_FLAG_ATTRIBUTE}="true"]`);
24482
- }
24483
-
24484
- // src/formula-modal.ts
24485
- var EMPTY_FORMULA_PLACEHOLDER = "\\placeholder ";
24486
- var STYLE_ID = "fx-formula-modal-styles";
24487
- var formulaXModalStyles = `
24488
- .fx-formula-modal-open {
24489
- overflow: hidden;
24490
- }
24491
-
24492
- .fx-formula-modal-root {
24493
- position: fixed;
24494
- inset: 0;
24495
- z-index: 2147483000;
24496
- display: flex;
24497
- align-items: center;
24498
- justify-content: center;
24499
- }
24500
-
24501
- .fx-formula-modal-backdrop {
24502
- position: absolute;
24503
- inset: 0;
24504
- background: rgba(15, 23, 42, 0.48);
24505
- }
24506
-
24507
- .fx-formula-modal {
24508
- --fx-formula-editor-body-height: 264px;
24509
- --fx-formula-workspace-height: 168px;
24510
- position: relative;
24511
- width: min(860px, calc(100vw - 32px));
24512
- height: auto;
24513
- max-height: calc(100vh - 32px);
24514
- background: #fff;
24515
- border-radius: 14px;
24516
- box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
24517
- display: flex;
24518
- flex-direction: column;
24519
- overflow: visible;
24520
- isolation: isolate;
24521
- }
24522
-
24523
- .fx-formula-modal__header,
24524
- .fx-formula-modal__footer,
24525
- .fx-formula-modal__title,
24526
- .fx-formula-modal__close,
24527
- .fx-formula-modal__button,
24528
- .fx-formula-editor-loading,
24529
- .fx-formula-editor-error {
24530
- font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
24531
- }
24532
-
24533
- .fx-formula-modal__header {
24534
- min-height: 56px;
24535
- padding: 0 20px;
24536
- border-bottom: 1px solid #e5e7eb;
24537
- display: flex;
24538
- align-items: center;
24539
- justify-content: space-between;
24540
- flex-shrink: 0;
24541
- position: relative;
24542
- z-index: 3;
24543
- background: #fff;
24544
- border-radius: 14px 14px 0 0;
24545
- }
24546
-
24547
- .fx-formula-modal__title {
24548
- font-size: 16px;
24549
- font-weight: 650;
24550
- margin: 0;
24551
- color: #111827;
24552
- }
24553
-
24554
- .fx-formula-modal__close {
24555
- border: 0;
24556
- background: transparent;
24557
- font-size: 24px;
24558
- line-height: 1;
24559
- cursor: pointer;
24560
- color: #6b7280;
24561
- }
24562
-
24563
- .fx-formula-modal__body {
24564
- flex: 0 0 auto;
24565
- height: var(--fx-formula-editor-body-height);
24566
- padding: 0;
24567
- overflow: visible;
24568
- min-height: var(--fx-formula-editor-body-height);
24569
- position: relative;
24570
- z-index: 2;
24571
- }
24572
-
24573
- .fx-formula-editor-host {
24574
- width: 100%;
24575
- height: var(--fx-formula-editor-body-height);
24576
- min-height: var(--fx-formula-editor-body-height);
24577
- overflow: visible;
24578
- position: relative;
24579
- }
24580
-
24581
- .fx-formula-kity-host {
24582
- width: 100%;
24583
- height: var(--fx-formula-editor-body-height);
24584
- min-height: var(--fx-formula-editor-body-height);
24585
- overflow: visible;
24586
- position: relative;
24587
- }
24588
-
24589
- .fx-formula-kity-host .kf-editor {
24590
- height: var(--fx-formula-editor-body-height) !important;
24591
- overflow: visible !important;
24592
- }
24593
-
24594
- .fx-formula-kity-host .kf-editor-toolbar {
24595
- overflow: visible;
24596
- position: relative;
24597
- z-index: 20;
24598
- }
24599
-
24600
- .fx-formula-kity-host .kf-editor-ui-button-mount-point,
24601
- .fx-formula-kity-host .kf-editor-ui-area-mount,
24602
- .fx-formula-kity-host .kf-editor-ui-box,
24603
- .fx-formula-kity-host .kf-editor-ui-list {
24604
- z-index: 1000;
24605
- }
24606
-
24607
- .fx-formula-kity-host .kf-editor-edit-area,
24608
- .fx-formula-kity-host .kf-editor-canvas-container {
24609
- min-height: var(--fx-formula-workspace-height);
24610
- height: var(--fx-formula-workspace-height);
24611
- }
24612
-
24613
- .fx-formula-kity-host .kf-editor-edit-area {
24614
- flex: 0 0 auto;
24615
- overflow: hidden;
24616
- }
24617
-
24618
- .fx-formula-kity-host .kf-editor,
24619
- .fx-formula-kity-host .kf-editor svg text,
24620
- .fx-formula-kity-host .kf-editor-ui-area-item-text,
24621
- .fx-formula-kity-host .kf-editor-ui-box-item-text,
24622
- .fx-formula-kity-host .kf-editor-ui-box-item-val,
24623
- .formulax-math__render {
24624
- font-family: "KF AMS MAIN", "Cambria Math", "Latin Modern Math", "Times New Roman", serif !important;
24625
- }
24626
-
24627
- .fx-formula-kity-host .kf-editor-ui-box-item-content,
24628
- .fx-formula-kity-host .kf-editor-ui-box-item-val {
24629
- min-width: 32px;
24630
- min-height: 32px;
24631
- }
24632
-
24633
- .fx-formula-kity-host .kf-editor-ui-box-item-val svg,
24634
- .fx-formula-kity-host .kf-editor-ui-box-item-val img,
24635
- .fx-formula-kity-host .kf-editor-ui-area-item-img,
24636
- .fx-formula-kity-host .kf-editor-ui-area-item-text {
24637
- display: block;
24638
- }
24639
-
24640
- .fx-formula-editor-loading {
24641
- height: var(--fx-formula-editor-body-height);
24642
- padding: 24px;
24643
- color: #4b5563;
24644
- text-align: center;
24645
- display: flex;
24646
- align-items: center;
24647
- justify-content: center;
24648
- }
24649
-
24650
- .fx-formula-editor-error {
24651
- padding: 24px;
24652
- color: #dc2626;
24653
- font-size: 14px;
24654
- }
24655
-
24656
- .fx-formula-editor-error pre {
24657
- white-space: pre-wrap;
24658
- word-break: break-all;
24659
- color: #991b1b;
24660
- background: #fef2f2;
24661
- border: 1px solid #fecaca;
24662
- border-radius: 8px;
24663
- padding: 12px;
24664
- margin-top: 8px;
24665
- }
24666
-
24667
- .fx-formula-modal__footer {
24668
- min-height: 64px;
24669
- padding: 12px 20px;
24670
- border-top: 1px solid #e5e7eb;
24671
- display: flex;
24672
- align-items: center;
24673
- justify-content: flex-end;
24674
- gap: 12px;
24675
- flex-shrink: 0;
24676
- position: relative;
24677
- z-index: 1;
24678
- background: #fff;
24679
- border-radius: 0 0 14px 14px;
24680
- }
24681
-
24682
- .fx-formula-modal__button {
24683
- appearance: none;
24684
- border: 1px solid #d1d5db;
24685
- background: #fff;
24686
- color: #111827;
24687
- border-radius: 8px;
24688
- padding: 8px 14px;
24689
- font-size: 14px;
24690
- cursor: pointer;
24691
- }
24692
-
24693
- .fx-formula-modal__button--primary {
24694
- border-color: #2563eb;
24695
- background: #2563eb;
24696
- color: #fff;
24697
- }
24698
24138
 
24139
+ // ../renderer/src/styles.ts
24140
+ var FORMULAX_BASE_STYLE_ID = "fx-formulax-base-styles";
24141
+ var formulaXBaseStyles = `
24699
24142
  .formulax-math {
24700
24143
  display: inline-flex;
24701
24144
  align-items: center;
@@ -24714,224 +24157,68 @@ var FormulaX = (() => {
24714
24157
  background: rgba(37, 99, 235, 0.06);
24715
24158
  }
24716
24159
 
24717
- .formulax-math__svg {
24160
+ .formulax-math__render,
24161
+ .formulax-math__svg,
24162
+ .formulax-math__image {
24718
24163
  display: inline-block;
24719
- flex: 0 0 auto;
24720
24164
  max-width: 100%;
24721
- vertical-align: -0.35em;
24722
24165
  pointer-events: none;
24723
24166
  }
24724
24167
 
24168
+ .formulax-math__render {
24169
+ vertical-align: middle;
24170
+ font-family: "KF AMS MAIN", "Cambria Math", "Latin Modern Math", "Times New Roman", serif;
24171
+ }
24172
+
24173
+ .formulax-math__svg {
24174
+ flex: 0 0 auto;
24175
+ vertical-align: -0.35em;
24176
+ }
24177
+
24725
24178
  .formulax-math__image {
24726
- display: inline-block;
24727
- max-width: 100%;
24728
24179
  height: auto;
24729
24180
  vertical-align: middle;
24730
- pointer-events: none;
24731
24181
  }
24732
24182
  `;
24733
- function ensureFormulaXModalStyles(doc2 = document) {
24734
- if (doc2.getElementById(STYLE_ID)) return;
24183
+ function ensureFormulaXBaseStyles(doc2 = document) {
24184
+ if (doc2.getElementById(FORMULAX_BASE_STYLE_ID)) return;
24735
24185
  const style = doc2.createElement("style");
24736
- style.id = STYLE_ID;
24737
- style.textContent = formulaXModalStyles;
24186
+ style.id = FORMULAX_BASE_STYLE_ID;
24187
+ style.textContent = formulaXBaseStyles;
24738
24188
  doc2.head.appendChild(style);
24739
24189
  }
24740
- function mountFormulaXKityEditor(root2, options = {}) {
24741
- let destroyed = false;
24742
- let latestLatex = options.initialLatex ?? "";
24743
- let handle = null;
24744
- const initialLatex = latestLatex.trim() ? latestLatex : EMPTY_FORMULA_PLACEHOLDER;
24745
- root2.classList.add("fx-formula-kity-host");
24746
- root2.innerHTML = `
24747
- <div class="fx-formula-editor-loading" role="status" aria-live="polite">
24748
- Loading FormulaX editor...
24749
- </div>
24750
- `;
24751
- const readyPromise = mountKityEditor(root2, {
24752
- initialLatex,
24753
- height: options.height ?? "100%",
24754
- autofocus: options.autofocus ?? true,
24755
- assets: options.assets,
24756
- render: {
24757
- fontsize: options.render?.fontsize ?? 40
24758
- }
24759
- }).then((nextHandle) => {
24760
- if (destroyed) {
24761
- nextHandle.destroy();
24762
- throw new Error("FormulaX editor mount cancelled");
24763
- }
24764
- handle = nextHandle;
24765
- return nextHandle;
24766
- }).catch((error) => {
24767
- console.error("[FormulaX] Failed to load FormulaX editor:", error);
24768
- if (!destroyed) {
24769
- root2.innerHTML = `
24770
- <div class="fx-formula-editor-error">
24771
- Failed to load FormulaX editor.
24772
- <pre>${escapeHtml(error instanceof Error ? error.message : String(error))}</pre>
24773
- </div>
24774
- `;
24775
- }
24776
- throw error;
24777
- });
24778
- const getCurrentLatex = async () => {
24779
- const readyHandle = handle ?? await readyPromise;
24780
- const latex = await tryReadLatexFromKityHandle(readyHandle);
24781
- if (latex !== null) {
24782
- latestLatex = latex;
24783
- }
24784
- return latestLatex;
24785
- };
24786
- return {
24787
- root: root2,
24788
- getLatex: getCurrentLatex,
24789
- async getState() {
24790
- const latex = await getCurrentLatex();
24791
- try {
24792
- return {
24793
- ...createEmptyState(),
24794
- doc: parseLatex(latex)
24795
- };
24796
- } catch {
24797
- return createEmptyState();
24798
- }
24799
- },
24800
- async getRenderHtml() {
24801
- await readyPromise;
24802
- await waitForFormulaSvgLayout(root2);
24803
- return renderCurrentFormulaAsSvgHtml(root2);
24804
- },
24805
- destroy() {
24806
- if (destroyed) return;
24807
- destroyed = true;
24808
- void readyPromise.then((readyHandle) => readyHandle.destroy()).catch(() => void 0);
24809
- root2.innerHTML = "";
24810
- }
24811
- };
24812
- }
24813
- async function tryReadLatexFromKityHandle(handle) {
24814
- try {
24815
- let isEmpty = false;
24816
- handle.ready(function ready() {
24817
- const result = this.execCommand("content.is.empty");
24818
- isEmpty = result === true;
24819
- });
24820
- if (isEmpty) {
24821
- return "";
24822
- }
24823
- } catch {
24824
- }
24825
- const candidates = [
24826
- "get.source",
24827
- "getSource",
24828
- "getLatex",
24829
- "get.latex",
24830
- "get.content",
24831
- "getContent"
24832
- ];
24833
- for (const command of candidates) {
24834
- try {
24835
- let value = null;
24836
- handle.ready(function ready() {
24837
- value = this.execCommand(command);
24838
- });
24839
- if (typeof value === "string" && value.trim()) {
24840
- return value;
24841
- }
24842
- if (value && typeof value === "object" && "latex" in value) {
24843
- const latex = value.latex;
24844
- if (typeof latex === "string" && latex.trim()) {
24845
- return latex;
24846
- }
24847
- }
24848
- } catch {
24849
- }
24850
- }
24851
- return null;
24852
- }
24853
- function renderCurrentFormulaAsSvgHtml(root2) {
24854
- const svg2 = findFormulaSvg(root2);
24855
- if (!svg2) {
24856
- return "";
24857
- }
24858
- return serializeSvgForInsertion(svg2);
24859
- }
24860
- async function waitForFormulaSvgLayout(root2) {
24861
- const doc2 = root2.ownerDocument ?? document;
24862
- const view = doc2.defaultView ?? window;
24863
- await waitForDocumentFonts(doc2);
24864
- let previous = readRenderedFormulaBox(root2);
24865
- for (let attempt = 0; attempt < 4; attempt += 1) {
24866
- await waitForAnimationFrame(view);
24867
- const current = readRenderedFormulaBox(root2);
24868
- if (previous && current && areSvgBoxesClose(previous, current)) {
24869
- return;
24870
- }
24871
- previous = current;
24872
- }
24873
- }
24874
- function findFormulaSvg(root2) {
24875
- return root2.querySelector(
24876
- ".kf-editor-edit-area svg, .kf-editor-canvas-container svg, svg"
24877
- );
24878
- }
24879
- function readRenderedFormulaBox(root2) {
24880
- const svg2 = findFormulaSvg(root2);
24881
- if (!svg2) {
24882
- return null;
24883
- }
24190
+
24191
+ // ../renderer/src/svg.ts
24192
+ function readRenderedFormulaSvgBox(svg2) {
24884
24193
  return getInlineSvgContent(svg2)?.box ?? readSvgBox(svg2);
24885
24194
  }
24886
- function areSvgBoxesClose(left, right) {
24887
- return Math.abs(left.x - right.x) < 0.01 && Math.abs(left.y - right.y) < 0.01 && Math.abs(left.width - right.width) < 0.01 && Math.abs(left.height - right.height) < 0.01;
24888
- }
24889
- async function waitForDocumentFonts(doc2) {
24890
- if (!doc2.fonts?.ready) {
24891
- return;
24892
- }
24893
- try {
24894
- await doc2.fonts.ready;
24895
- } catch {
24896
- }
24897
- }
24898
- function waitForAnimationFrame(view) {
24899
- return new Promise((resolve) => {
24900
- view.requestAnimationFrame(() => resolve());
24901
- });
24902
- }
24903
24195
  function serializeSvgForInsertion(svg2) {
24904
24196
  const content = getInlineSvgContent(svg2);
24905
24197
  const inlineViewport = content ? createInlineSvgViewport(content.box) : null;
24906
24198
  const clone = content && inlineViewport ? createInlineSvgClone(svg2, content, inlineViewport) : svg2.cloneNode(true);
24907
24199
  uniquifySvgIds(clone);
24908
24200
  sizeSvgForInlineDisplay(clone, svg2, inlineViewport);
24909
- clone.removeAttribute("id");
24910
- clone.removeAttribute("xmlns");
24911
- clone.removeAttribute("xmlns:xlink");
24912
- clone.setAttribute("class", mergeClassNames(clone.getAttribute("class"), "formulax-math__svg"));
24913
24201
  clone.setAttribute("focusable", "false");
24914
24202
  clone.setAttribute("aria-hidden", "true");
24915
- clone.setAttribute("preserveAspectRatio", clone.getAttribute("preserveAspectRatio") || "xMinYMin meet");
24916
- return new XMLSerializer().serializeToString(clone);
24203
+ clone.setAttribute("class", mergeClassNames(clone.getAttribute("class"), "formulax-math__svg"));
24204
+ return clone.outerHTML;
24917
24205
  }
24918
24206
  function getInlineSvgContent(svg2) {
24919
- const candidates = [
24920
- '[data-root="true"] > g[data-type="kf-editor-exp-content-box"]',
24921
- 'g[data-type="kf-editor-exp-content-box"]',
24922
- 'g[data-type="kf-container"]',
24923
- "svg > g, g"
24207
+ const selectorCandidates = [
24208
+ '[data-type="kf-editor-exp-content-box"]',
24209
+ '[data-root="true"] [data-type="kf-editor-exp-content-box"]',
24210
+ 'g[data-root="true"]'
24924
24211
  ];
24925
- for (const selector of candidates) {
24926
- const content = svg2.querySelector(selector);
24927
- const rootSpace = content ? readSvgBoxInRootSpace(content) : null;
24928
- if (content && rootSpace) {
24929
- return {
24930
- root: content,
24931
- box: rootSpace.box,
24932
- matrix: rootSpace.matrix
24933
- };
24934
- }
24212
+ for (const selector of selectorCandidates) {
24213
+ const element = svg2.querySelector(selector);
24214
+ if (!element) continue;
24215
+ const rootSpace = readSvgBoxInRootSpace(element);
24216
+ if (!rootSpace) continue;
24217
+ return {
24218
+ box: rootSpace.box,
24219
+ matrix: rootSpace.matrix,
24220
+ root: element
24221
+ };
24935
24222
  }
24936
24223
  return null;
24937
24224
  }
@@ -25099,7 +24386,7 @@ var FormulaX = (() => {
25099
24386
  clone.setAttribute("height", roundLength(height2));
25100
24387
  clone.setAttribute(
25101
24388
  "style",
25102
- mergeInlineStyles2(
24389
+ mergeInlineStyles(
25103
24390
  clone.getAttribute("style"),
25104
24391
  `width:${roundLength(inlineWidthEm)}em`,
25105
24392
  `height:${inlineHeightEm}em`
@@ -25143,85 +24430,562 @@ var FormulaX = (() => {
25143
24430
  function mergeClassNames(...values) {
25144
24431
  return values.flatMap((value) => value?.split(/\s+/) ?? []).filter(Boolean).filter((value, index, list) => list.indexOf(value) === index).join(" ");
25145
24432
  }
25146
- function mergeInlineStyles2(...values) {
24433
+ function mergeInlineStyles(...values) {
25147
24434
  return values.flatMap((value) => value?.split(";") ?? []).map((value) => value.trim()).filter(Boolean).join("; ");
25148
24435
  }
25149
24436
 
25150
- // src/i18n.ts
25151
- var translations = {
25152
- en: {
25153
- equation: "Equation",
25154
- structures: "Structures",
25155
- symbols: "Symbols",
25156
- matrices: "Matrices",
25157
- templates: "Templates",
25158
- insert: "Insert",
25159
- greek: "Greek",
25160
- operators: "Operators",
25161
- relations: "Relations",
25162
- fraction: "Fraction",
25163
- superscript: "Superscript",
25164
- subscript: "Subscript",
25165
- squareRoot: "Square Root",
25166
- parentheses: "Parentheses",
25167
- plusMinus: "Plus Minus",
25168
- multiply: "Multiply",
25169
- divide: "Divide",
25170
- dot: "Dot",
25171
- union: "Union",
25172
- intersect: "Intersection",
25173
- lessOrEqual: "Less or Equal",
25174
- greaterOrEqual: "Greater or Equal",
25175
- notEqual: "Not Equal",
25176
- approximate: "Approximate",
25177
- infinity: "Infinity",
25178
- arrow: "Arrow",
25179
- limit: "Limit",
25180
- sine: "Sine",
25181
- logarithm: "Logarithm",
25182
- matrix: "Matrix",
25183
- summation: "Summation",
25184
- integral: "Integral",
25185
- placeholder: "WPS-inspired ribbon layout. Some tiles are placeholders for future SDK features."
25186
- },
25187
- zh: {
25188
- equation: "\u516C\u5F0F",
25189
- structures: "\u7ED3\u6784",
25190
- symbols: "\u7B26\u53F7",
25191
- matrices: "\u77E9\u9635",
25192
- templates: "\u6A21\u677F",
25193
- insert: "\u63D2\u5165",
25194
- greek: "\u5E0C\u814A\u5B57\u6BCD",
25195
- operators: "\u8FD0\u7B97\u7B26",
25196
- relations: "\u5173\u7CFB",
25197
- fraction: "\u5206\u6570",
25198
- superscript: "\u4E0A\u6807",
25199
- subscript: "\u4E0B\u6807",
25200
- squareRoot: "\u5E73\u65B9\u6839",
25201
- parentheses: "\u62EC\u53F7",
25202
- plusMinus: "\u52A0\u51CF",
25203
- multiply: "\u4E58",
25204
- divide: "\u9664",
25205
- dot: "\u70B9\u4E58",
25206
- union: "\u5E76\u96C6",
25207
- intersect: "\u4EA4\u96C6",
25208
- lessOrEqual: "\u5C0F\u4E8E\u7B49\u4E8E",
25209
- greaterOrEqual: "\u5927\u4E8E\u7B49\u4E8E",
25210
- notEqual: "\u4E0D\u7B49\u4E8E",
25211
- approximate: "\u7EA6\u7B49\u4E8E",
25212
- infinity: "\u65E0\u7A77",
25213
- arrow: "\u7BAD\u5934",
25214
- limit: "\u6781\u9650",
25215
- sine: "\u6B63\u5F26",
25216
- logarithm: "\u5BF9\u6570",
25217
- matrix: "\u77E9\u9635",
25218
- summation: "\u6C42\u548C",
25219
- integral: "\u79EF\u5206",
25220
- placeholder: "WPS \u98CE\u683C\u7684\u5DE5\u5177\u680F\u5E03\u5C40\u3002\u90E8\u5206\u6309\u94AE\u4ECD\u662F\u672A\u6765 SDK \u529F\u80FD\u7684\u5360\u4F4D\u9879\u3002"
24437
+ // ../renderer-kity/src/dom.ts
24438
+ async function waitForDocumentFonts(doc2) {
24439
+ if (!doc2.fonts?.ready) return;
24440
+ try {
24441
+ await doc2.fonts.ready;
24442
+ } catch {
24443
+ }
24444
+ }
24445
+ function waitForAnimationFrame(view) {
24446
+ return new Promise((resolve) => {
24447
+ view.requestAnimationFrame(() => resolve());
24448
+ });
24449
+ }
24450
+
24451
+ // ../renderer-kity/src/serialize.ts
24452
+ function findKityFormulaSvg(root2) {
24453
+ return root2.querySelector(
24454
+ ".kf-editor-edit-area svg, .kf-editor-canvas-container svg, svg"
24455
+ );
24456
+ }
24457
+ function serializeKityFormulaFromRoot(root2) {
24458
+ const svg2 = findKityFormulaSvg(root2);
24459
+ if (!svg2) {
24460
+ return "";
25221
24461
  }
25222
- };
25223
- function t(locale, key) {
25224
- return translations[locale][key] ?? translations.en[key];
24462
+ return serializeSvgForInsertion(svg2);
24463
+ }
24464
+ async function waitForKityFormulaSvgLayout(root2) {
24465
+ const doc2 = root2.ownerDocument ?? document;
24466
+ const view = doc2.defaultView ?? window;
24467
+ await waitForDocumentFonts(doc2);
24468
+ let previous = readRenderedFormulaBox(root2);
24469
+ for (let attempt = 0; attempt < 4; attempt += 1) {
24470
+ await waitForAnimationFrame(view);
24471
+ const current = readRenderedFormulaBox(root2);
24472
+ if (previous && current && areSvgBoxesClose(previous, current)) {
24473
+ return;
24474
+ }
24475
+ previous = current;
24476
+ }
24477
+ }
24478
+ function readRenderedFormulaBox(root2) {
24479
+ const svg2 = findKityFormulaSvg(root2);
24480
+ if (!svg2) {
24481
+ return null;
24482
+ }
24483
+ return readRenderedFormulaSvgBox(svg2);
24484
+ }
24485
+ function areSvgBoxesClose(left, right) {
24486
+ return Math.abs(left.x - right.x) < 0.01 && Math.abs(left.y - right.y) < 0.01 && Math.abs(left.width - right.width) < 0.01 && Math.abs(left.height - right.height) < 0.01;
24487
+ }
24488
+
24489
+ // src/perf.ts
24490
+ function getPerfHost2() {
24491
+ return globalThis;
24492
+ }
24493
+ function getPerfState2() {
24494
+ const host = getPerfHost2();
24495
+ host.__FORMULAX_PERF_STATE__ ??= {
24496
+ reportedMeasureCount: 0,
24497
+ reportScheduled: false
24498
+ };
24499
+ return host.__FORMULAX_PERF_STATE__;
24500
+ }
24501
+ function hasPerfSupport2() {
24502
+ return typeof performance !== "undefined" && typeof performance.mark === "function" && typeof performance.measure === "function" && typeof performance.getEntriesByType === "function";
24503
+ }
24504
+ function isPerfDebugEnabled2() {
24505
+ return getPerfHost2().__FORMULAX_PERF__ === true;
24506
+ }
24507
+ function schedulePerfReport2() {
24508
+ if (!hasPerfSupport2() || !isPerfDebugEnabled2()) {
24509
+ return;
24510
+ }
24511
+ const state = getPerfState2();
24512
+ if (state.reportScheduled) {
24513
+ return;
24514
+ }
24515
+ state.reportScheduled = true;
24516
+ queueMicrotask(() => {
24517
+ state.reportScheduled = false;
24518
+ const entries = performance.getEntriesByType("measure").filter((entry) => entry.name.startsWith("fx:")).sort((left, right) => left.startTime - right.startTime);
24519
+ const nextEntries = entries.slice(state.reportedMeasureCount);
24520
+ state.reportedMeasureCount = entries.length;
24521
+ if (!nextEntries.length) {
24522
+ return;
24523
+ }
24524
+ console.table(nextEntries.map((entry) => ({
24525
+ name: entry.name,
24526
+ duration: Number(entry.duration.toFixed(2)),
24527
+ startTime: Number(entry.startTime.toFixed(2))
24528
+ })));
24529
+ });
24530
+ }
24531
+ function markFormulaXPerf2(name) {
24532
+ if (!hasPerfSupport2()) {
24533
+ return null;
24534
+ }
24535
+ const markName = `${name}::${Date.now()}::${Math.random().toString(36).slice(2, 8)}`;
24536
+ performance.mark(markName);
24537
+ return markName;
24538
+ }
24539
+ function measureFormulaXPerf2(name, startMark, endMark) {
24540
+ if (!hasPerfSupport2() || !startMark) {
24541
+ return null;
24542
+ }
24543
+ const resolvedEndMark = endMark ?? markFormulaXPerf2(`${name}:end`);
24544
+ if (!resolvedEndMark) {
24545
+ return null;
24546
+ }
24547
+ performance.measure(name, startMark, resolvedEndMark);
24548
+ schedulePerfReport2();
24549
+ return resolvedEndMark;
24550
+ }
24551
+ function recordFormulaXPerfPoint(name) {
24552
+ const markName = markFormulaXPerf2(name);
24553
+ if (!markName) {
24554
+ return;
24555
+ }
24556
+ measureFormulaXPerf2(name, markName, markName);
24557
+ clearFormulaXPerfMarks2(markName);
24558
+ }
24559
+ function clearFormulaXPerfMarks2(...marks) {
24560
+ if (!hasPerfSupport2()) {
24561
+ return;
24562
+ }
24563
+ for (const mark of marks) {
24564
+ if (!mark) {
24565
+ continue;
24566
+ }
24567
+ performance.clearMarks(mark);
24568
+ }
24569
+ }
24570
+ async function preloadFormulaXEditor() {
24571
+ await ensureKityRuntime();
24572
+ }
24573
+ function scheduleFormulaXEditorPreload(mode, target) {
24574
+ if (mode === false || typeof window === "undefined") {
24575
+ return () => void 0;
24576
+ }
24577
+ let disposed = false;
24578
+ let triggered = false;
24579
+ const cleanupCallbacks = [];
24580
+ const trigger = () => {
24581
+ if (disposed || triggered) {
24582
+ return;
24583
+ }
24584
+ triggered = true;
24585
+ while (cleanupCallbacks.length) {
24586
+ cleanupCallbacks.pop()?.();
24587
+ }
24588
+ void preloadFormulaXEditor();
24589
+ };
24590
+ if (mode === "idle") {
24591
+ const host = getPerfHost2();
24592
+ if (typeof host.requestIdleCallback === "function") {
24593
+ const handle = host.requestIdleCallback(() => {
24594
+ trigger();
24595
+ });
24596
+ cleanupCallbacks.push(() => {
24597
+ host.cancelIdleCallback?.(handle);
24598
+ });
24599
+ } else {
24600
+ const handle = window.setTimeout(() => {
24601
+ trigger();
24602
+ }, 1);
24603
+ cleanupCallbacks.push(() => {
24604
+ window.clearTimeout(handle);
24605
+ });
24606
+ }
24607
+ return () => {
24608
+ disposed = true;
24609
+ while (cleanupCallbacks.length) {
24610
+ cleanupCallbacks.pop()?.();
24611
+ }
24612
+ };
24613
+ }
24614
+ if (target && "addEventListener" in target && "removeEventListener" in target) {
24615
+ const eventTarget = target;
24616
+ const onActivate = () => {
24617
+ trigger();
24618
+ };
24619
+ eventTarget.addEventListener("pointerenter", onActivate, { once: true, passive: true });
24620
+ eventTarget.addEventListener("focusin", onActivate, { once: true });
24621
+ cleanupCallbacks.push(() => {
24622
+ eventTarget.removeEventListener("pointerenter", onActivate);
24623
+ eventTarget.removeEventListener("focusin", onActivate);
24624
+ });
24625
+ }
24626
+ return () => {
24627
+ disposed = true;
24628
+ while (cleanupCallbacks.length) {
24629
+ cleanupCallbacks.pop()?.();
24630
+ }
24631
+ };
24632
+ }
24633
+ function waitForFormulaXAnimationFrame() {
24634
+ if (typeof window === "undefined" || typeof window.requestAnimationFrame !== "function") {
24635
+ return Promise.resolve();
24636
+ }
24637
+ return new Promise((resolve) => {
24638
+ window.requestAnimationFrame(() => resolve());
24639
+ });
24640
+ }
24641
+
24642
+ // src/formula-modal.ts
24643
+ var EMPTY_FORMULA_PLACEHOLDER = "\\placeholder ";
24644
+ var STYLE_ID = "fx-formula-modal-styles";
24645
+ var formulaXModalStyles = `
24646
+ .fx-formula-modal-open {
24647
+ overflow: hidden;
24648
+ }
24649
+
24650
+ .fx-formula-modal-root {
24651
+ position: fixed;
24652
+ inset: 0;
24653
+ z-index: 2147483000;
24654
+ display: flex;
24655
+ align-items: center;
24656
+ justify-content: center;
24657
+ }
24658
+
24659
+ .fx-formula-modal-backdrop {
24660
+ position: absolute;
24661
+ inset: 0;
24662
+ background: rgba(15, 23, 42, 0.48);
24663
+ }
24664
+
24665
+ .fx-formula-modal {
24666
+ --fx-formula-editor-body-height: 264px;
24667
+ --fx-formula-workspace-height: 168px;
24668
+ position: relative;
24669
+ width: min(860px, calc(100vw - 32px));
24670
+ height: auto;
24671
+ max-height: calc(100vh - 32px);
24672
+ background: #fff;
24673
+ border-radius: 14px;
24674
+ box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
24675
+ display: flex;
24676
+ flex-direction: column;
24677
+ overflow: visible;
24678
+ isolation: isolate;
24679
+ }
24680
+
24681
+ .fx-formula-modal__header,
24682
+ .fx-formula-modal__footer,
24683
+ .fx-formula-modal__title,
24684
+ .fx-formula-modal__close,
24685
+ .fx-formula-modal__button,
24686
+ .fx-formula-editor-loading,
24687
+ .fx-formula-editor-error {
24688
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
24689
+ }
24690
+
24691
+ .fx-formula-modal__header {
24692
+ min-height: 56px;
24693
+ padding: 0 20px;
24694
+ border-bottom: 1px solid #e5e7eb;
24695
+ display: flex;
24696
+ align-items: center;
24697
+ justify-content: space-between;
24698
+ flex-shrink: 0;
24699
+ position: relative;
24700
+ z-index: 3;
24701
+ background: #fff;
24702
+ border-radius: 14px 14px 0 0;
24703
+ }
24704
+
24705
+ .fx-formula-modal__title {
24706
+ font-size: 16px;
24707
+ font-weight: 650;
24708
+ margin: 0;
24709
+ color: #111827;
24710
+ }
24711
+
24712
+ .fx-formula-modal__close {
24713
+ border: 0;
24714
+ background: transparent;
24715
+ font-size: 24px;
24716
+ line-height: 1;
24717
+ cursor: pointer;
24718
+ color: #6b7280;
24719
+ }
24720
+
24721
+ .fx-formula-modal__body {
24722
+ flex: 0 0 auto;
24723
+ height: var(--fx-formula-editor-body-height);
24724
+ padding: 0;
24725
+ overflow: visible;
24726
+ min-height: var(--fx-formula-editor-body-height);
24727
+ position: relative;
24728
+ z-index: 2;
24729
+ }
24730
+
24731
+ .fx-formula-editor-host {
24732
+ width: 100%;
24733
+ height: var(--fx-formula-editor-body-height);
24734
+ min-height: var(--fx-formula-editor-body-height);
24735
+ overflow: visible;
24736
+ position: relative;
24737
+ }
24738
+
24739
+ .fx-formula-kity-host {
24740
+ width: 100%;
24741
+ height: var(--fx-formula-editor-body-height);
24742
+ min-height: var(--fx-formula-editor-body-height);
24743
+ overflow: visible;
24744
+ position: relative;
24745
+ }
24746
+
24747
+ .fx-formula-kity-host .kf-editor {
24748
+ height: var(--fx-formula-editor-body-height) !important;
24749
+ overflow: visible !important;
24750
+ }
24751
+
24752
+ .fx-formula-kity-host .kf-editor-toolbar {
24753
+ overflow: visible;
24754
+ position: relative;
24755
+ z-index: 20;
24756
+ }
24757
+
24758
+ .fx-formula-kity-host .kf-editor-ui-button-mount-point,
24759
+ .fx-formula-kity-host .kf-editor-ui-area-mount,
24760
+ .fx-formula-kity-host .kf-editor-ui-box,
24761
+ .fx-formula-kity-host .kf-editor-ui-list {
24762
+ z-index: 1000;
24763
+ }
24764
+
24765
+ .fx-formula-kity-host .kf-editor-edit-area,
24766
+ .fx-formula-kity-host .kf-editor-canvas-container {
24767
+ min-height: var(--fx-formula-workspace-height);
24768
+ height: var(--fx-formula-workspace-height);
24769
+ }
24770
+
24771
+ .fx-formula-kity-host .kf-editor-edit-area {
24772
+ flex: 0 0 auto;
24773
+ overflow: hidden;
24774
+ }
24775
+
24776
+ .fx-formula-kity-host .kf-editor,
24777
+ .fx-formula-kity-host .kf-editor svg text,
24778
+ .fx-formula-kity-host .kf-editor-ui-area-item-text,
24779
+ .fx-formula-kity-host .kf-editor-ui-box-item-text,
24780
+ .fx-formula-kity-host .kf-editor-ui-box-item-val {
24781
+ font-family: "KF AMS MAIN", "Cambria Math", "Latin Modern Math", "Times New Roman", serif !important;
24782
+ }
24783
+
24784
+ .fx-formula-kity-host .kf-editor-ui-box-item-content,
24785
+ .fx-formula-kity-host .kf-editor-ui-box-item-val {
24786
+ min-width: 32px;
24787
+ min-height: 32px;
24788
+ }
24789
+
24790
+ .fx-formula-kity-host .kf-editor-ui-box-item-val svg,
24791
+ .fx-formula-kity-host .kf-editor-ui-box-item-val img,
24792
+ .fx-formula-kity-host .kf-editor-ui-area-item-img,
24793
+ .fx-formula-kity-host .kf-editor-ui-area-item-text {
24794
+ display: block;
24795
+ }
24796
+
24797
+ .fx-formula-editor-loading {
24798
+ height: var(--fx-formula-editor-body-height);
24799
+ padding: 24px;
24800
+ color: #4b5563;
24801
+ text-align: center;
24802
+ display: flex;
24803
+ align-items: center;
24804
+ justify-content: center;
24805
+ }
24806
+
24807
+ .fx-formula-editor-error {
24808
+ padding: 24px;
24809
+ color: #dc2626;
24810
+ font-size: 14px;
24811
+ }
24812
+
24813
+ .fx-formula-editor-error pre {
24814
+ white-space: pre-wrap;
24815
+ word-break: break-all;
24816
+ color: #991b1b;
24817
+ background: #fef2f2;
24818
+ border: 1px solid #fecaca;
24819
+ border-radius: 8px;
24820
+ padding: 12px;
24821
+ margin-top: 8px;
24822
+ }
24823
+
24824
+ .fx-formula-modal__footer {
24825
+ min-height: 64px;
24826
+ padding: 12px 20px;
24827
+ border-top: 1px solid #e5e7eb;
24828
+ display: flex;
24829
+ align-items: center;
24830
+ justify-content: flex-end;
24831
+ gap: 12px;
24832
+ flex-shrink: 0;
24833
+ position: relative;
24834
+ z-index: 1;
24835
+ background: #fff;
24836
+ border-radius: 0 0 14px 14px;
24837
+ }
24838
+
24839
+ .fx-formula-modal__button {
24840
+ appearance: none;
24841
+ border: 1px solid #d1d5db;
24842
+ background: #fff;
24843
+ color: #111827;
24844
+ border-radius: 8px;
24845
+ padding: 8px 14px;
24846
+ font-size: 14px;
24847
+ cursor: pointer;
24848
+ }
24849
+
24850
+ .fx-formula-modal__button--primary {
24851
+ border-color: #2563eb;
24852
+ background: #2563eb;
24853
+ color: #fff;
24854
+ }
24855
+ `;
24856
+ function ensureFormulaXModalStyles(doc2 = document) {
24857
+ ensureFormulaXBaseStyles(doc2);
24858
+ if (doc2.getElementById(STYLE_ID)) return;
24859
+ const style = doc2.createElement("style");
24860
+ style.id = STYLE_ID;
24861
+ style.textContent = formulaXModalStyles;
24862
+ doc2.head.appendChild(style);
24863
+ }
24864
+ function renderFormulaXEditorLoadingState(root2) {
24865
+ root2.classList.add("fx-formula-kity-host");
24866
+ root2.innerHTML = `
24867
+ <div class="fx-formula-editor-loading" role="status" aria-live="polite">
24868
+ Loading FormulaX editor...
24869
+ </div>
24870
+ `;
24871
+ }
24872
+ function mountFormulaXEditor(root2, options = {}) {
24873
+ recordFormulaXPerfPoint("fx:formula-editor:mount:start");
24874
+ const mountStart = markFormulaXPerf2("fx:formula-editor:mount:start:scope");
24875
+ let destroyed = false;
24876
+ let latestLatex = options.initialLatex ?? "";
24877
+ let handle = null;
24878
+ const initialLatex = latestLatex.trim() ? latestLatex : EMPTY_FORMULA_PLACEHOLDER;
24879
+ renderFormulaXEditorLoadingState(root2);
24880
+ const loadingVisibleMark = markFormulaXPerf2("fx:formula-editor:loading-visible");
24881
+ measureFormulaXPerf2("fx:formula-editor:loading-visible", mountStart, loadingVisibleMark);
24882
+ clearFormulaXPerfMarks2(loadingVisibleMark);
24883
+ const readyPromise = mountKityEditor(root2, {
24884
+ initialLatex,
24885
+ height: options.height ?? "100%",
24886
+ autofocus: options.autofocus ?? true,
24887
+ assets: options.assets,
24888
+ render: {
24889
+ fontsize: options.render?.fontsize ?? 40
24890
+ }
24891
+ }).then((nextHandle) => {
24892
+ if (destroyed) {
24893
+ nextHandle.destroy();
24894
+ throw new Error("FormulaX editor mount cancelled");
24895
+ }
24896
+ const readyMark = markFormulaXPerf2("fx:kity-editor:ready");
24897
+ measureFormulaXPerf2("fx:kity-editor:ready", mountStart, readyMark);
24898
+ clearFormulaXPerfMarks2(readyMark);
24899
+ handle = nextHandle;
24900
+ return nextHandle;
24901
+ }).catch((error) => {
24902
+ console.error("[FormulaX] Failed to load FormulaX editor:", error);
24903
+ if (!destroyed) {
24904
+ root2.innerHTML = `
24905
+ <div class="fx-formula-editor-error">
24906
+ Failed to load FormulaX editor.
24907
+ <pre>${escapeHtml(error instanceof Error ? error.message : String(error))}</pre>
24908
+ </div>
24909
+ `;
24910
+ }
24911
+ throw error;
24912
+ }).finally(() => {
24913
+ clearFormulaXPerfMarks2(mountStart);
24914
+ });
24915
+ const getCurrentLatex = async () => {
24916
+ const readyHandle = handle ?? await readyPromise;
24917
+ const latex = await tryReadLatexFromKityHandle(readyHandle);
24918
+ if (latex !== null) {
24919
+ latestLatex = latex;
24920
+ }
24921
+ return latestLatex;
24922
+ };
24923
+ return {
24924
+ root: root2,
24925
+ getLatex: getCurrentLatex,
24926
+ async getState() {
24927
+ const latex = await getCurrentLatex();
24928
+ try {
24929
+ return {
24930
+ ...createEmptyState(),
24931
+ doc: parseLatex(latex)
24932
+ };
24933
+ } catch {
24934
+ return createEmptyState();
24935
+ }
24936
+ },
24937
+ async getRenderHtml() {
24938
+ await readyPromise;
24939
+ await waitForKityFormulaSvgLayout(root2);
24940
+ return serializeKityFormulaFromRoot(root2);
24941
+ },
24942
+ destroy() {
24943
+ if (destroyed) return;
24944
+ destroyed = true;
24945
+ void readyPromise.then((readyHandle) => readyHandle.destroy()).catch(() => void 0);
24946
+ root2.innerHTML = "";
24947
+ }
24948
+ };
24949
+ }
24950
+ async function tryReadLatexFromKityHandle(handle) {
24951
+ try {
24952
+ let isEmpty = false;
24953
+ handle.ready(function ready() {
24954
+ const result = this.execCommand("content.is.empty");
24955
+ isEmpty = result === true;
24956
+ });
24957
+ if (isEmpty) {
24958
+ return "";
24959
+ }
24960
+ } catch {
24961
+ }
24962
+ const candidates = [
24963
+ "get.source",
24964
+ "getSource",
24965
+ "getLatex",
24966
+ "get.latex",
24967
+ "get.content",
24968
+ "getContent"
24969
+ ];
24970
+ for (const command of candidates) {
24971
+ try {
24972
+ let value = null;
24973
+ handle.ready(function ready() {
24974
+ value = this.execCommand(command);
24975
+ });
24976
+ if (typeof value === "string" && value.trim()) {
24977
+ return value;
24978
+ }
24979
+ if (value && typeof value === "object" && "latex" in value) {
24980
+ const latex = value.latex;
24981
+ if (typeof latex === "string" && latex.trim()) {
24982
+ return latex;
24983
+ }
24984
+ }
24985
+ } catch {
24986
+ }
24987
+ }
24988
+ return null;
25225
24989
  }
25226
24990
  return __toCommonJS(index_exports);
25227
24991
  })();