@formulaxjs/tiptap 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +39 -33
  2. package/README.zh-CN.md +39 -33
  3. package/dist/base.css +47 -0
  4. package/dist/canvg-runtime-UR3JNX5Q.js +2759 -0
  5. package/dist/canvg-runtime-UR3JNX5Q.js.map +1 -0
  6. package/dist/chunk-OCSSWPUX.js +3407 -0
  7. package/dist/chunk-OCSSWPUX.js.map +1 -0
  8. package/dist/images/scrollbar/custom/bar-bg.png +0 -0
  9. package/dist/images/scrollbar/custom/bar.png +0 -0
  10. package/dist/images/scrollbar/custom/bg.png +0 -0
  11. package/dist/images/scrollbar/custom/bottom.png +0 -0
  12. package/dist/images/scrollbar/custom/btn.png +0 -0
  13. package/dist/images/scrollbar/custom/down.png +0 -0
  14. package/dist/images/scrollbar/custom/top.png +0 -0
  15. package/dist/images/scrollbar/custom/up.png +0 -0
  16. package/dist/images/scrollbar/edit/bar-bg.png +0 -0
  17. package/dist/images/scrollbar/edit/bar-left.png +0 -0
  18. package/dist/images/scrollbar/edit/bar-right.png +0 -0
  19. package/dist/images/scrollbar/edit/thumb-bg.png +0 -0
  20. package/dist/images/scrollbar/edit/thumb-left.png +0 -0
  21. package/dist/images/scrollbar/edit/thumb-right.png +0 -0
  22. package/dist/images/toolbar/btn.png +0 -0
  23. package/dist/index.cjs +24075 -65
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.global.js +865 -859
  26. package/dist/index.global.js.map +1 -1
  27. package/dist/index.js +3768 -21
  28. package/dist/index.js.map +1 -1
  29. package/dist/install-XGCSWTLU.js +5464 -0
  30. package/dist/install-XGCSWTLU.js.map +1 -0
  31. package/dist/install-XVTKACEN.js +1349 -0
  32. package/dist/install-XVTKACEN.js.map +1 -0
  33. package/dist/other.png +0 -0
  34. package/dist/scrollbar.css +78 -0
  35. package/dist/start-MBLTNR2Q.js +4926 -0
  36. package/dist/start-MBLTNR2Q.js.map +1 -0
  37. package/dist/ui.css +625 -0
  38. package/package.json +9 -4
  39. /package/dist/{KF_AMS_BB-5QF7FUSO.woff → KF_AMS_BB.woff} +0 -0
  40. /package/dist/{KF_AMS_CAL-NXRNLAZN.woff → KF_AMS_CAL.woff} +0 -0
  41. /package/dist/{KF_AMS_FRAK-CO33WWN4.woff → KF_AMS_FRAK.woff} +0 -0
  42. /package/dist/{KF_AMS_MAIN-25QJVAWY.woff → KF_AMS_MAIN.woff} +0 -0
  43. /package/dist/{KF_AMS_ROMAN-243BR7HH.woff → KF_AMS_ROMAN.woff} +0 -0
  44. /package/dist/{btn-5DANP6JY.png → btn.png} +0 -0
  45. /package/dist/{editor-JT5KLVXX.css → editor.css} +0 -0
  46. /package/dist/{other-OMWJFGL5.png → images/toolbar/other.png} +0 -0
@@ -0,0 +1,4926 @@
1
+ import {
2
+ DEFAULT_FORMULAX_LOCALE,
3
+ createLegacyBaseComponent,
4
+ createLegacyUiUtils,
5
+ legacyBaseUtils,
6
+ legacyBoxType,
7
+ legacyEleType,
8
+ legacyGroupType,
9
+ legacyInputFilter,
10
+ legacyItemType,
11
+ legacyKfExtDef,
12
+ legacyOtherPosition,
13
+ legacySysconf,
14
+ legacyUiDef,
15
+ normalizeFormulaXLocale,
16
+ resolveToolbarAssetPath,
17
+ translateFormulaXText
18
+ } from "./chunk-OCSSWPUX.js";
19
+
20
+ // ../kity-runtime/src/vendor/runtime-interop.ts
21
+ function getLegacyRuntime() {
22
+ const runtime = window.__FORMULAX_KITY_RUNTIME__;
23
+ if (!runtime) {
24
+ throw new Error("Missing FormulaX legacy runtime");
25
+ }
26
+ return runtime;
27
+ }
28
+ function getLegacyKity() {
29
+ const runtime = getLegacyRuntime();
30
+ if (!runtime.kity) {
31
+ throw new Error("Missing FormulaX legacy kity runtime");
32
+ }
33
+ return runtime.kity;
34
+ }
35
+ function getLegacyKf() {
36
+ const runtime = getLegacyRuntime();
37
+ if (!runtime.kf) {
38
+ throw new Error("Missing FormulaX legacy kf runtime");
39
+ }
40
+ return runtime.kf;
41
+ }
42
+
43
+ // ../kity-runtime/src/legacy/editor.ts
44
+ var defaultOptions = {
45
+ formula: {
46
+ fontsize: 50,
47
+ autoresize: false
48
+ },
49
+ ui: {
50
+ zoom: true,
51
+ maxzoom: 2,
52
+ minzoom: 1
53
+ }
54
+ };
55
+ var components = {};
56
+ function getService(serviceName) {
57
+ const serviceObject = this.services[serviceName];
58
+ if (!serviceObject) {
59
+ throw new Error(`KFEditor: not found service, ${serviceName}`);
60
+ }
61
+ return serviceObject;
62
+ }
63
+ var kity = getLegacyKity();
64
+ var kf = getLegacyKf();
65
+ var KFEditor = kity.createClass("KFEditor", {
66
+ constructor(container, options) {
67
+ this.options = legacyBaseUtils.extend(true, {}, defaultOptions, options);
68
+ this.FormulaClass = null;
69
+ this._readyState = false;
70
+ this._callbacks = [];
71
+ this.container = container;
72
+ this.services = {};
73
+ this.commands = {};
74
+ this.initResource();
75
+ },
76
+ isReady() {
77
+ return !!this._readyState;
78
+ },
79
+ triggerReady() {
80
+ let callback;
81
+ while (callback = this._callbacks.shift()) {
82
+ callback.call(this, this);
83
+ }
84
+ },
85
+ ready(callback) {
86
+ if (this._readyState) {
87
+ callback.call(this, this);
88
+ return;
89
+ }
90
+ this._callbacks.push(callback);
91
+ },
92
+ getContainer() {
93
+ return this.container;
94
+ },
95
+ getDocument() {
96
+ return this.container.ownerDocument;
97
+ },
98
+ getFormulaClass() {
99
+ return this.FormulaClass;
100
+ },
101
+ getOptions() {
102
+ return this.options;
103
+ },
104
+ initResource() {
105
+ kf.ResourceManager.ready((formula) => {
106
+ this.FormulaClass = formula;
107
+ this.initComponents();
108
+ this._readyState = true;
109
+ this.triggerReady();
110
+ }, this.options.resource);
111
+ },
112
+ initComponents() {
113
+ legacyBaseUtils.each(components, (Component, name) => {
114
+ new Component(this, this.options[name]);
115
+ });
116
+ },
117
+ requestService(serviceName, ...args) {
118
+ const serviceObject = getService.call(this, serviceName);
119
+ return serviceObject.service[serviceObject.key].apply(serviceObject.provider, args);
120
+ },
121
+ request(serviceName) {
122
+ return getService.call(this, serviceName).service;
123
+ },
124
+ registerService(serviceName, provider, serviceObject) {
125
+ let key = "";
126
+ for (const currentKey in serviceObject) {
127
+ if (Object.prototype.hasOwnProperty.call(serviceObject, currentKey) && serviceObject[currentKey]) {
128
+ serviceObject[currentKey] = legacyBaseUtils.proxy(serviceObject[currentKey], provider);
129
+ key = currentKey;
130
+ }
131
+ }
132
+ this.services[serviceName] = {
133
+ provider,
134
+ key,
135
+ service: serviceObject
136
+ };
137
+ },
138
+ registerCommand(commandName, executor, execFn) {
139
+ this.commands[commandName] = {
140
+ executor,
141
+ execFn
142
+ };
143
+ },
144
+ execCommand(commandName, ...args) {
145
+ const commandObject = this.commands[commandName];
146
+ if (!commandObject) {
147
+ throw new Error(`KFEditor: not found command, ${commandName}`);
148
+ }
149
+ return commandObject.execFn.apply(commandObject.executor, args);
150
+ }
151
+ });
152
+ legacyBaseUtils.extend(KFEditor, {
153
+ registerComponents(name, component) {
154
+ components[name] = component;
155
+ }
156
+ });
157
+ var editor_default = KFEditor;
158
+
159
+ // ../kity-runtime/src/legacy/factory.ts
160
+ var EditorWrapper = class {
161
+ callbacks = [];
162
+ editor;
163
+ constructor(container, options) {
164
+ this.editor = new editor_default(container, options);
165
+ this.editor.ready(() => {
166
+ this.trigger();
167
+ });
168
+ }
169
+ trigger() {
170
+ const editor = this.editor;
171
+ getLegacyKity().Utils.each(this.callbacks, (callback) => {
172
+ callback.call(editor, editor);
173
+ });
174
+ }
175
+ ready(callback) {
176
+ if (this.editor.isReady()) {
177
+ callback.call(this.editor, this.editor);
178
+ return;
179
+ }
180
+ this.callbacks.push(callback);
181
+ }
182
+ };
183
+ var factory = {
184
+ create(container, options) {
185
+ return new EditorWrapper(container, options);
186
+ }
187
+ };
188
+ var factory_default = factory;
189
+
190
+ // ../kity-runtime/src/legacy/button.ts
191
+ var PREFIX = "kf-editor-ui-";
192
+ var LIST_OFFSET = 7;
193
+ var DEFAULT_OPTIONS = {
194
+ iconSize: {
195
+ w: 32,
196
+ h: 32
197
+ }
198
+ };
199
+ var $$ = createLegacyUiUtils();
200
+ var kity2 = getLegacyKity();
201
+ function getBackgroundStyle(data) {
202
+ let style = `url( ${data.src} ) no-repeat `;
203
+ style += `${-data.x}px `;
204
+ style += `${-data.y}px`;
205
+ return style;
206
+ }
207
+ var Button = kity2.createClass("Button", {
208
+ constructor(doc, options) {
209
+ this.options = kity2.Utils.extend({}, DEFAULT_OPTIONS, options);
210
+ this.eventState = false;
211
+ this.toolbar = null;
212
+ this.displayState = false;
213
+ this.fixOffset = !!options.fixOffset;
214
+ this.doc = doc;
215
+ this.element = this.createButton();
216
+ this.disabled = true;
217
+ this.mountElement = null;
218
+ this.icon = this.createIcon();
219
+ this.label = this.createLabel();
220
+ this.sign = this.createSign();
221
+ this.mountPoint = this.createMountPoint();
222
+ this.mergeElement();
223
+ },
224
+ initEvent() {
225
+ if (this.eventState) {
226
+ return;
227
+ }
228
+ this.eventState = true;
229
+ $$.on(this.element, "mousedown", (e) => {
230
+ e.preventDefault();
231
+ e.stopPropagation();
232
+ if ((e.which ?? 1) !== 1 || this.disabled) {
233
+ return;
234
+ }
235
+ this.toggleSelect();
236
+ this.toggleMountElement();
237
+ });
238
+ },
239
+ setToolbar(toolbar) {
240
+ this.toolbar = toolbar;
241
+ },
242
+ toggleMountElement() {
243
+ if (this.displayState) {
244
+ this.hideMount();
245
+ } else {
246
+ this.showMount();
247
+ }
248
+ },
249
+ setLabel(labelText) {
250
+ let signText = "";
251
+ if (this.sign) {
252
+ signText = `<div class="${PREFIX}button-sign"></div>`;
253
+ }
254
+ this.label.innerHTML = `${labelText}${signText}`;
255
+ },
256
+ toggleSelect() {
257
+ $$.getClassList(this.element).toggle(`${PREFIX}button-in`);
258
+ },
259
+ unselect() {
260
+ $$.getClassList(this.element).remove(`${PREFIX}button-in`);
261
+ },
262
+ select() {
263
+ $$.getClassList(this.element).add(`${PREFIX}button-in`);
264
+ },
265
+ show() {
266
+ this.select();
267
+ this.showMount();
268
+ },
269
+ hide() {
270
+ this.unselect();
271
+ this.hideMount();
272
+ },
273
+ showMount() {
274
+ this.displayState = true;
275
+ this.mountPoint.style.display = "block";
276
+ if (this.fixOffset && this.mountElement?.setOffset) {
277
+ const elementRect = this.element.getBoundingClientRect();
278
+ this.mountElement.setOffset(elementRect.left + LIST_OFFSET, elementRect.bottom);
279
+ }
280
+ const editorContainer = this.toolbar?.getContainer();
281
+ if (!editorContainer || !this.mountElement) {
282
+ return;
283
+ }
284
+ const containerBox = $$.getRectBox(editorContainer);
285
+ const mountEleBox = this.mountElement.getPositionInfo();
286
+ if (mountEleBox.right > containerBox.right) {
287
+ const currentBox = $$.getRectBox(this.element);
288
+ this.mountPoint.style.left = `${currentBox.right - mountEleBox.right - 1}px`;
289
+ }
290
+ this.mountElement.updateSize?.();
291
+ },
292
+ hideMount() {
293
+ this.displayState = false;
294
+ this.mountPoint.style.display = "none";
295
+ },
296
+ getNode() {
297
+ return this.element;
298
+ },
299
+ mount(element) {
300
+ this.mountElement = element;
301
+ element.mountTo(this.mountPoint);
302
+ },
303
+ createButton() {
304
+ const buttonNode = $$.ele(this.doc, "div", {
305
+ className: `${PREFIX}button`
306
+ });
307
+ if (this.options.className) {
308
+ buttonNode.className += ` ${PREFIX}${this.options.className}`;
309
+ }
310
+ return buttonNode;
311
+ },
312
+ createIcon() {
313
+ if (!this.options.icon) {
314
+ return null;
315
+ }
316
+ const iconNode = $$.ele(this.doc, "div", {
317
+ className: `${PREFIX}button-icon`
318
+ });
319
+ if (typeof this.options.icon === "string") {
320
+ iconNode.style.backgroundImage = `url(${this.options.icon}) no-repeat`;
321
+ } else {
322
+ iconNode.style.background = getBackgroundStyle(this.options.icon);
323
+ }
324
+ if (this.options.iconSize.w) {
325
+ iconNode.style.width = `${this.options.iconSize.w}px`;
326
+ }
327
+ if (this.options.iconSize.h) {
328
+ iconNode.style.height = `${this.options.iconSize.h}px`;
329
+ }
330
+ return iconNode;
331
+ },
332
+ createLabel() {
333
+ return $$.ele(this.doc, "div", {
334
+ className: `${PREFIX}button-label`,
335
+ content: this.options.label
336
+ });
337
+ },
338
+ createSign() {
339
+ if (this.options.sign === false) {
340
+ return null;
341
+ }
342
+ return $$.ele(this.doc, "div", {
343
+ className: `${PREFIX}button-sign`
344
+ });
345
+ },
346
+ createMountPoint() {
347
+ return $$.ele(this.doc, "div", {
348
+ className: `${PREFIX}button-mount-point`
349
+ });
350
+ },
351
+ disable() {
352
+ this.disabled = true;
353
+ $$.getClassList(this.element).remove(`${PREFIX}enabled`);
354
+ },
355
+ enable() {
356
+ this.disabled = false;
357
+ $$.getClassList(this.element).add(`${PREFIX}enabled`);
358
+ },
359
+ mergeElement() {
360
+ if (this.icon) {
361
+ this.element.appendChild(this.icon);
362
+ }
363
+ this.element.appendChild(this.label);
364
+ if (this.sign) {
365
+ this.label.appendChild(this.sign);
366
+ }
367
+ this.element.appendChild(this.mountPoint);
368
+ }
369
+ });
370
+ var button_default = Button;
371
+
372
+ // ../kity-runtime/src/legacy/list.ts
373
+ var PREFIX2 = "kf-editor-ui-";
374
+ var $$2 = createLegacyUiUtils();
375
+ var kity3 = getLegacyKity();
376
+ var List = kity3.createClass("List", {
377
+ constructor(doc, options) {
378
+ this.options = options;
379
+ this.doc = doc;
380
+ this.onselectHandler = function() {
381
+ };
382
+ this.currentSelect = -1;
383
+ this.element = this.createBox();
384
+ this.itemGroups = this.createItems();
385
+ this.mergeElement();
386
+ },
387
+ setSelectHandler(selectHandler) {
388
+ this.onselectHandler = selectHandler;
389
+ },
390
+ createBox() {
391
+ const boxNode = $$2.ele(this.doc, "div", {
392
+ className: `${PREFIX2}list`
393
+ });
394
+ const bgNode = $$2.ele(this.doc, "div", {
395
+ className: `${PREFIX2}list-bg`
396
+ });
397
+ if ("width" in this.options && this.options.width !== void 0) {
398
+ boxNode.style.width = `${this.options.width}px`;
399
+ }
400
+ boxNode.appendChild(bgNode);
401
+ return boxNode;
402
+ },
403
+ select(index) {
404
+ let oldSelect = this.currentSelect;
405
+ if (oldSelect === -1) {
406
+ oldSelect = index;
407
+ }
408
+ this.unselect(oldSelect);
409
+ this.currentSelect = index;
410
+ $$2.getClassList(this.itemGroups.items[index]).add(`${PREFIX2}list-item-select`);
411
+ this.onselectHandler(index, oldSelect);
412
+ },
413
+ unselect(index) {
414
+ if (!this.itemGroups.items[index]) {
415
+ return;
416
+ }
417
+ $$2.getClassList(this.itemGroups.items[index]).remove(`${PREFIX2}list-item-select`);
418
+ },
419
+ setOffset(x, y) {
420
+ this.element.style.left = `${x}px`;
421
+ this.element.style.top = `${y}px`;
422
+ },
423
+ initEvent() {
424
+ const className = `.${PREFIX2}list-item`;
425
+ const self = this;
426
+ $$2.delegate(this.itemGroups.container, className, "mousedown", function(e) {
427
+ e.preventDefault();
428
+ if ((e.which ?? 1) !== 1) {
429
+ return;
430
+ }
431
+ const index = Number(this.getAttribute("data-index"));
432
+ if (!Number.isNaN(index)) {
433
+ self.select(index);
434
+ }
435
+ });
436
+ $$2.on(this.element, "mousedown", (e) => {
437
+ e.stopPropagation();
438
+ e.preventDefault();
439
+ });
440
+ },
441
+ getPositionInfo() {
442
+ return $$2.getRectBox(this.element);
443
+ },
444
+ createItems() {
445
+ const doc = this.doc;
446
+ const groupNode = $$2.ele(this.doc, "div", {
447
+ className: `${PREFIX2}list-item`
448
+ });
449
+ const itemContainer = groupNode.cloneNode(false);
450
+ const items = [];
451
+ itemContainer.className = `${PREFIX2}list-item-container`;
452
+ kity3.Utils.each(this.options.items, (itemText, i) => {
453
+ const itemNode = groupNode.cloneNode(false);
454
+ const iconNode = groupNode.cloneNode(false);
455
+ iconNode.className = `${PREFIX2}list-item-icon`;
456
+ itemNode.appendChild(iconNode);
457
+ itemNode.appendChild($$2.ele(doc, "text", itemText));
458
+ itemNode.setAttribute("data-index", String(i));
459
+ items.push(itemNode);
460
+ itemContainer.appendChild(itemNode);
461
+ });
462
+ return {
463
+ container: itemContainer,
464
+ items
465
+ };
466
+ },
467
+ mergeElement() {
468
+ this.element.appendChild(this.itemGroups.container);
469
+ },
470
+ mountTo(container) {
471
+ container.appendChild(this.element);
472
+ }
473
+ });
474
+ var list_default = List;
475
+
476
+ // ../kity-runtime/src/legacy/box.ts
477
+ var kity4 = getLegacyKity();
478
+ var $$3 = createLegacyUiUtils();
479
+ var PREFIX3 = "kf-editor-ui-";
480
+ var BOX_TYPE = legacyBoxType;
481
+ var ITEM_TYPE = legacyItemType;
482
+ var SCROLL_STEP = 20;
483
+ function getViewportBox(doc) {
484
+ const view = doc.documentElement;
485
+ return {
486
+ top: 0,
487
+ left: 0,
488
+ right: view.clientWidth,
489
+ bottom: view.clientHeight,
490
+ width: view.clientWidth,
491
+ height: view.clientHeight
492
+ };
493
+ }
494
+ function getStyleByData(data) {
495
+ let style = `background: url( ${data.img} ) no-repeat `;
496
+ style += `${-data.pos.x}px `;
497
+ style += `${-data.pos.y}px;`;
498
+ style += ` width: ${data.size.width}px;`;
499
+ style += ` height: ${data.size.height}px;`;
500
+ return style;
501
+ }
502
+ function createItems(doc, group, type) {
503
+ const items = [];
504
+ kity4.Utils.each(group, (itemVal) => {
505
+ items.push(new BoxItem(type, doc, itemVal));
506
+ });
507
+ return items;
508
+ }
509
+ function createOverlapContainer(doc) {
510
+ return $$3.ele(doc, "div", {
511
+ className: `${PREFIX3}overlap-container`
512
+ });
513
+ }
514
+ function createOverlapButton(doc, options) {
515
+ return new button_default(doc, {
516
+ className: "overlap-button",
517
+ label: "",
518
+ fixOffset: options.fixOffset
519
+ });
520
+ }
521
+ function createOverlapList(doc, list) {
522
+ return new list_default(doc, list);
523
+ }
524
+ var BoxItem = kity4.createClass("BoxItem", {
525
+ constructor(type, doc, options) {
526
+ this.type = type;
527
+ this.doc = doc;
528
+ this.options = options;
529
+ this.element = this.createItem();
530
+ this.labelNode = this.createLabel();
531
+ this.contentNode = this.createContent();
532
+ this.mergeElement();
533
+ },
534
+ getNode() {
535
+ return this.element;
536
+ },
537
+ createItem() {
538
+ return $$3.ele(this.doc, "div", {
539
+ className: `${PREFIX3}box-item`
540
+ });
541
+ },
542
+ createLabel() {
543
+ if (!("label" in this.options)) {
544
+ return void 0;
545
+ }
546
+ return $$3.ele(this.doc, "div", {
547
+ className: `${PREFIX3}box-item-label`,
548
+ content: this.options.label
549
+ });
550
+ },
551
+ getContent() {
552
+ },
553
+ createContent() {
554
+ switch (this.type) {
555
+ case ITEM_TYPE.BIG:
556
+ return this.createBigContent();
557
+ case ITEM_TYPE.SMALL:
558
+ return this.createSmallContent();
559
+ default:
560
+ return this.createSmallContent();
561
+ }
562
+ },
563
+ createBigContent() {
564
+ const contentNode = $$3.ele(this.doc, "div", {
565
+ className: `${PREFIX3}box-item-content`
566
+ });
567
+ const cls = `${PREFIX3}box-item-val`;
568
+ const tmpContent = this.options.item;
569
+ const tmpNode = $$3.ele(this.doc, "div", {
570
+ className: cls
571
+ });
572
+ const styleStr = getStyleByData(tmpContent);
573
+ tmpNode.innerHTML = `<div class="${PREFIX3}item-image" style="${styleStr}"></div>`;
574
+ this.element.setAttribute("data-value", tmpContent.val);
575
+ contentNode.appendChild(tmpNode);
576
+ return contentNode;
577
+ },
578
+ createSmallContent() {
579
+ const contentNode = $$3.ele(this.doc, "div", {
580
+ className: `${PREFIX3}box-item-content`
581
+ });
582
+ const cls = `${PREFIX3}box-item-val`;
583
+ const tmpContent = this.options;
584
+ if (tmpContent.unicode) {
585
+ const tmpNode2 = $$3.ele(this.doc, "span", {
586
+ className: `${PREFIX3}box-item-text`,
587
+ content: tmpContent.unicode
588
+ });
589
+ if (tmpContent.unicodeFont) {
590
+ tmpNode2.style.fontFamily = tmpContent.unicodeFont;
591
+ }
592
+ if (tmpContent.key) {
593
+ this.element.setAttribute("data-value", tmpContent.key);
594
+ }
595
+ contentNode.appendChild(tmpNode2);
596
+ return contentNode;
597
+ }
598
+ const tmpNode = $$3.ele(this.doc, "div", {
599
+ className: cls
600
+ });
601
+ tmpNode.style.background = `url( ${tmpContent.img} )`;
602
+ tmpNode.style.backgroundPosition = `${-tmpContent.pos.x}px ${-tmpContent.pos.y}px`;
603
+ if (tmpContent.key) {
604
+ this.element.setAttribute("data-value", tmpContent.key);
605
+ }
606
+ contentNode.appendChild(tmpNode);
607
+ return contentNode;
608
+ },
609
+ mergeElement() {
610
+ if (this.labelNode) {
611
+ this.element.appendChild(this.labelNode);
612
+ }
613
+ this.element.appendChild(this.contentNode);
614
+ },
615
+ appendTo(container) {
616
+ container.appendChild(this.element);
617
+ }
618
+ });
619
+ var Box = kity4.createClass("Box", {
620
+ constructor(doc, options) {
621
+ this.options = options;
622
+ this.toolbar = null;
623
+ this.options.type = this.options.type || BOX_TYPE.DETACHED;
624
+ this.doc = doc;
625
+ this.itemPanels = null;
626
+ this.overlapButtonObject = null;
627
+ this.overlapIndex = -1;
628
+ this.onchangeHandler = function() {
629
+ };
630
+ this.element = this.createBox();
631
+ this.groupContainer = this.createGroupContainer();
632
+ this.itemGroups = this.createItemGroup();
633
+ this.mergeElement();
634
+ },
635
+ createBox() {
636
+ const boxNode = $$3.ele(this.doc, "div", {
637
+ className: `${PREFIX3}box`
638
+ });
639
+ if ("width" in this.options && this.options.width !== void 0) {
640
+ boxNode.style.width = `${this.options.width}px`;
641
+ }
642
+ return boxNode;
643
+ },
644
+ setToolbar(toolbar) {
645
+ this.toolbar = toolbar;
646
+ if (this.overlapButtonObject) {
647
+ this.overlapButtonObject.setToolbar(toolbar);
648
+ }
649
+ },
650
+ updateSize() {
651
+ const containerBox = getViewportBox(this.doc);
652
+ const diff = 30;
653
+ const curBox = $$3.getRectBox(this.element);
654
+ if (this.options.type === BOX_TYPE.DETACHED) {
655
+ if (curBox.bottom <= containerBox.bottom) {
656
+ this.element.scrollTop = 0;
657
+ return;
658
+ }
659
+ this.element.style.height = `${curBox.height - (curBox.bottom - containerBox.bottom + diff)}px`;
660
+ return;
661
+ }
662
+ const panel = this.getCurrentItemPanel();
663
+ panel.scrollTop = 0;
664
+ if (curBox.bottom <= containerBox.bottom) {
665
+ return;
666
+ }
667
+ const panelRect = $$3.getRectBox(panel);
668
+ panel.style.height = `${containerBox.bottom - panelRect.top - diff}px`;
669
+ },
670
+ initEvent() {
671
+ const className = `.${PREFIX3}box-item`;
672
+ const self = this;
673
+ $$3.delegate(this.groupContainer, className, "mousedown", function(e) {
674
+ e.preventDefault();
675
+ if ((e.which ?? 1) !== 1) {
676
+ return;
677
+ }
678
+ self.onselectHandler?.(this.getAttribute("data-value"));
679
+ });
680
+ $$3.on(this.element, "mousedown", (e) => {
681
+ e.stopPropagation();
682
+ e.preventDefault();
683
+ });
684
+ $$3.on(this.element, "mousewheel", (e) => {
685
+ e.preventDefault();
686
+ e.stopPropagation();
687
+ this.scroll(e.wheelDelta ?? 0);
688
+ });
689
+ },
690
+ getNode() {
691
+ return this.element;
692
+ },
693
+ setSelectHandler(onselectHandler) {
694
+ this.onselectHandler = onselectHandler;
695
+ },
696
+ scroll(delta) {
697
+ if (delta < 0) {
698
+ this.scrollDown();
699
+ return;
700
+ }
701
+ if (delta > 0) {
702
+ this.scrollUp();
703
+ }
704
+ },
705
+ scrollDown() {
706
+ if (this.options.type === BOX_TYPE.DETACHED) {
707
+ this.element.scrollTop += SCROLL_STEP;
708
+ } else {
709
+ this.getCurrentItemPanel().scrollTop += SCROLL_STEP;
710
+ }
711
+ },
712
+ scrollUp() {
713
+ if (this.options.type === BOX_TYPE.DETACHED) {
714
+ this.element.scrollTop -= SCROLL_STEP;
715
+ } else {
716
+ this.getCurrentItemPanel().scrollTop -= SCROLL_STEP;
717
+ }
718
+ },
719
+ setChangeHandler(changeHandler) {
720
+ this.onchangeHandler = changeHandler;
721
+ },
722
+ createGroupContainer() {
723
+ return $$3.ele(this.doc, "div", {
724
+ className: `${PREFIX3}box-container`
725
+ });
726
+ },
727
+ getPositionInfo() {
728
+ return $$3.getRectBox(this.element);
729
+ },
730
+ createItemGroup() {
731
+ const itemGroup = this.createGroup();
732
+ switch (this.options.type) {
733
+ case BOX_TYPE.DETACHED:
734
+ return itemGroup.items[0];
735
+ case BOX_TYPE.OVERLAP:
736
+ return this.createOverlapGroup(itemGroup);
737
+ default:
738
+ return null;
739
+ }
740
+ },
741
+ enable() {
742
+ this.overlapButtonObject?.enable();
743
+ },
744
+ disable() {
745
+ this.overlapButtonObject?.disable();
746
+ },
747
+ hide() {
748
+ this.overlapButtonObject?.hideMount();
749
+ },
750
+ getOverlapContent() {
751
+ if (this.options.type !== BOX_TYPE.OVERLAP || this.overlapIndex < 0) {
752
+ return null;
753
+ }
754
+ return this.options.group[this.overlapIndex].items;
755
+ },
756
+ createOverlapGroup(itemGroup) {
757
+ const classifyList = itemGroup.title;
758
+ const overlapContainer = createOverlapContainer(this.doc);
759
+ const overlapButtonObject = createOverlapButton(this.doc, {
760
+ fixOffset: this.options.fixOffset
761
+ });
762
+ const overlapListObject = createOverlapList(this.doc, {
763
+ width: 150,
764
+ items: classifyList
765
+ });
766
+ const wrapNode = $$3.ele(this.doc, "div", {
767
+ className: `${PREFIX3}wrap-group`
768
+ });
769
+ this.overlapButtonObject = overlapButtonObject;
770
+ overlapButtonObject.mount(overlapListObject);
771
+ overlapButtonObject.initEvent();
772
+ overlapListObject.initEvent();
773
+ kity4.Utils.each(itemGroup.items, (itemArr, index) => {
774
+ const itemWrapNode = wrapNode.cloneNode(false);
775
+ kity4.Utils.each(itemArr, (item) => {
776
+ itemWrapNode.appendChild(item);
777
+ });
778
+ itemGroup.items[index] = itemWrapNode;
779
+ });
780
+ this.itemPanels = itemGroup.items;
781
+ overlapListObject.setSelectHandler((index, oldIndex) => {
782
+ this.overlapIndex = index;
783
+ overlapButtonObject.setLabel(classifyList[index]);
784
+ overlapButtonObject.hideMount();
785
+ itemGroup.items[oldIndex].style.display = "none";
786
+ itemGroup.items[index].style.display = "block";
787
+ if (index !== oldIndex) {
788
+ this.updateSize();
789
+ }
790
+ this.onchangeHandler(index);
791
+ });
792
+ overlapContainer.appendChild(overlapButtonObject.getNode());
793
+ kity4.Utils.each(itemGroup.items, (group, index) => {
794
+ const groupNode = group;
795
+ if (index > 0) {
796
+ groupNode.style.display = "none";
797
+ }
798
+ overlapContainer.appendChild(groupNode);
799
+ });
800
+ overlapListObject.select(0);
801
+ return [overlapContainer];
802
+ },
803
+ getCurrentItemPanel() {
804
+ return this.itemPanels[this.overlapIndex];
805
+ },
806
+ getGroupList() {
807
+ const lists = [];
808
+ kity4.Utils.each(this.options.group, (group) => {
809
+ lists.push(group.title || "");
810
+ });
811
+ return {
812
+ width: 150,
813
+ items: lists
814
+ };
815
+ },
816
+ createGroup() {
817
+ const doc = this.doc;
818
+ const result = {
819
+ title: [],
820
+ items: []
821
+ };
822
+ const baseGroupNode = $$3.ele(this.doc, "div", {
823
+ className: `${PREFIX3}box-group`
824
+ });
825
+ const baseItemContainer = baseGroupNode.cloneNode(false);
826
+ baseItemContainer.className = `${PREFIX3}box-group-item-container`;
827
+ const itemType = BOX_TYPE.DETACHED === this.options.type ? ITEM_TYPE.BIG : ITEM_TYPE.SMALL;
828
+ kity4.Utils.each(this.options.group, (group) => {
829
+ result.title.push(group.title || "");
830
+ const itemGroup = [];
831
+ kity4.Utils.each(group.items, (item) => {
832
+ const groupNode = baseGroupNode.cloneNode(false);
833
+ const itemContainer = baseItemContainer.cloneNode(false);
834
+ const groupTitle = $$3.ele(doc, "div", {
835
+ className: `${PREFIX3}box-group-title`,
836
+ content: item.title
837
+ });
838
+ groupNode.appendChild(groupTitle);
839
+ groupNode.appendChild(itemContainer);
840
+ kity4.Utils.each(createItems(doc, item.content, itemType), (boxItem) => {
841
+ boxItem.appendTo(itemContainer);
842
+ });
843
+ itemGroup.push(groupNode);
844
+ });
845
+ result.items.push(itemGroup);
846
+ });
847
+ return result;
848
+ },
849
+ mergeElement() {
850
+ const groupContainer = this.groupContainer;
851
+ this.element.appendChild(groupContainer);
852
+ kity4.Utils.each(this.itemGroups, (group) => {
853
+ groupContainer.appendChild(group);
854
+ });
855
+ },
856
+ mountTo(container) {
857
+ container.appendChild(this.element);
858
+ },
859
+ appendTo(container) {
860
+ container.appendChild(this.element);
861
+ }
862
+ });
863
+ var box_default = Box;
864
+
865
+ // ../kity-runtime/src/legacy/area.ts
866
+ var PREFIX4 = "kf-editor-ui-";
867
+ var PANEL_HEIGHT = 66;
868
+ var $$4 = createLegacyUiUtils();
869
+ var kity5 = getLegacyKity();
870
+ var Area = kity5.createClass("Area", {
871
+ constructor(doc, options) {
872
+ this.options = options;
873
+ this.doc = doc;
874
+ this.toolbar = null;
875
+ this.disabled = true;
876
+ this.panelIndex = 0;
877
+ this.maxPanelIndex = 0;
878
+ this.currentItemCount = 0;
879
+ this.lineMaxCount = 9;
880
+ this.element = this.createArea();
881
+ this.container = this.createContainer();
882
+ this.panel = this.createPanel();
883
+ this.buttonContainer = this.createButtonContainer();
884
+ this.button = this.createButton();
885
+ this.mountPoint = this.createMountPoint();
886
+ this.moveDownButton = this.createMoveDownButton();
887
+ this.moveUpButton = this.createMoveUpButton();
888
+ this.boxObject = this.createBox();
889
+ this.mergeElement();
890
+ this.mount();
891
+ this.setListener();
892
+ this.initEvent();
893
+ },
894
+ initEvent() {
895
+ const self = this;
896
+ $$4.on(this.button, "mousedown", (e) => {
897
+ e.preventDefault();
898
+ e.stopPropagation();
899
+ if ((e.which ?? 1) !== 1 || this.disabled) {
900
+ return;
901
+ }
902
+ this.showMount();
903
+ this.toolbar?.notify("closeOther", this);
904
+ });
905
+ $$4.on(this.moveDownButton, "mousedown", (e) => {
906
+ e.preventDefault();
907
+ e.stopPropagation();
908
+ if ((e.which ?? 1) !== 1 || this.disabled) {
909
+ return;
910
+ }
911
+ this.nextPanel();
912
+ this.toolbar?.notify("closeOther", this);
913
+ });
914
+ $$4.on(this.moveUpButton, "mousedown", (e) => {
915
+ e.preventDefault();
916
+ e.stopPropagation();
917
+ if ((e.which ?? 1) !== 1 || this.disabled) {
918
+ return;
919
+ }
920
+ this.prevPanel();
921
+ this.toolbar?.notify("closeOther", this);
922
+ });
923
+ $$4.delegate(this.container, ".kf-editor-ui-area-item", "mousedown", function(e) {
924
+ e.preventDefault();
925
+ if ((e.which ?? 1) !== 1 || self.disabled) {
926
+ return;
927
+ }
928
+ $$4.publish("data.select", this.getAttribute("data-value"));
929
+ });
930
+ this.boxObject.initEvent();
931
+ },
932
+ disable() {
933
+ this.disabled = true;
934
+ this.boxObject.disable();
935
+ $$4.getClassList(this.element).remove(`${PREFIX4}enabled`);
936
+ },
937
+ enable() {
938
+ this.disabled = false;
939
+ this.boxObject.enable();
940
+ $$4.getClassList(this.element).add(`${PREFIX4}enabled`);
941
+ },
942
+ setListener() {
943
+ this.boxObject.setSelectHandler((val) => {
944
+ $$4.publish("data.select", val);
945
+ this.hide();
946
+ });
947
+ this.boxObject.setChangeHandler(() => {
948
+ this.updateContent();
949
+ });
950
+ },
951
+ createArea() {
952
+ const areaNode = $$4.ele(this.doc, "div", {
953
+ className: `${PREFIX4}area`
954
+ });
955
+ if ("width" in this.options && this.options.width !== void 0) {
956
+ areaNode.style.width = `${this.options.width}px`;
957
+ }
958
+ return areaNode;
959
+ },
960
+ checkMaxPanelIndex() {
961
+ this.maxPanelIndex = Math.ceil(this.currentItemCount / this.lineMaxCount / 2);
962
+ },
963
+ updateContent() {
964
+ const items = this.boxObject.getOverlapContent();
965
+ let count = 0;
966
+ let lineno = 0;
967
+ let colno = 0;
968
+ const lineMaxCount = this.lineMaxCount;
969
+ const newContent = [];
970
+ this.panel.innerHTML = "";
971
+ kity5.Utils.each(items, (item) => {
972
+ const contents = item.content;
973
+ kity5.Utils.each(contents, (currentContent) => {
974
+ lineno = Math.floor(count / lineMaxCount);
975
+ colno = count % lineMaxCount;
976
+ count += 1;
977
+ const style = `top: ${lineno * 33 + 5}px; left: ${colno * 32 + 5}px;`;
978
+ if (currentContent.unicode !== void 0) {
979
+ const fontStyle = currentContent.unicodeFont ? `font-family: ${currentContent.unicodeFont};` : "";
980
+ newContent.push(
981
+ `<div class="${PREFIX4}area-item ${PREFIX4}area-item-unicode" data-value="${currentContent.key}" style="${style}"><div class="${PREFIX4}area-item-inner"><span class="${PREFIX4}area-item-text" style="${fontStyle}">${currentContent.unicode}</span></div></div>`
982
+ );
983
+ } else {
984
+ newContent.push(
985
+ `<div class="${PREFIX4}area-item" data-value="${currentContent.key}" style="${style}"><div class="${PREFIX4}area-item-inner"><div class="${PREFIX4}area-item-img" style="background: url(${currentContent.img}) no-repeat ${-(currentContent.pos?.x ?? 0)}px ${-(currentContent.pos?.y ?? 0)}px;"></div></div></div>`
986
+ );
987
+ }
988
+ });
989
+ });
990
+ this.currentItemCount = count;
991
+ this.panelIndex = 0;
992
+ this.panel.style.top = "0";
993
+ this.panel.innerHTML = newContent.join("");
994
+ this.checkMaxPanelIndex();
995
+ this.updatePanelButtonState();
996
+ },
997
+ mount() {
998
+ this.boxObject.mountTo(this.mountPoint);
999
+ },
1000
+ showMount() {
1001
+ this.mountPoint.style.display = "block";
1002
+ this.boxObject.updateSize();
1003
+ },
1004
+ hideMount() {
1005
+ this.mountPoint.style.display = "none";
1006
+ },
1007
+ hide() {
1008
+ this.hideMount();
1009
+ this.boxObject.hide();
1010
+ },
1011
+ createButton() {
1012
+ return $$4.ele(this.doc, "div", {
1013
+ className: `${PREFIX4}area-button`
1014
+ });
1015
+ },
1016
+ createMoveDownButton() {
1017
+ return $$4.ele(this.doc, "div", {
1018
+ className: `${PREFIX4}movedown-button`,
1019
+ content: ""
1020
+ });
1021
+ },
1022
+ createMoveUpButton() {
1023
+ return $$4.ele(this.doc, "div", {
1024
+ className: `${PREFIX4}moveup-button`,
1025
+ content: ""
1026
+ });
1027
+ },
1028
+ createMountPoint() {
1029
+ return $$4.ele(this.doc, "div", {
1030
+ className: `${PREFIX4}area-mount`
1031
+ });
1032
+ },
1033
+ createBox() {
1034
+ return new box_default(this.doc, this.options.box);
1035
+ },
1036
+ createContainer() {
1037
+ return $$4.ele(this.doc, "div", {
1038
+ className: `${PREFIX4}area-container`
1039
+ });
1040
+ },
1041
+ createPanel() {
1042
+ return $$4.ele(this.doc, "div", {
1043
+ className: `${PREFIX4}area-panel`
1044
+ });
1045
+ },
1046
+ createButtonContainer() {
1047
+ return $$4.ele(this.doc, "div", {
1048
+ className: `${PREFIX4}area-button-container`
1049
+ });
1050
+ },
1051
+ mergeElement() {
1052
+ this.buttonContainer.appendChild(this.moveUpButton);
1053
+ this.buttonContainer.appendChild(this.moveDownButton);
1054
+ this.buttonContainer.appendChild(this.button);
1055
+ this.container.appendChild(this.panel);
1056
+ this.element.appendChild(this.container);
1057
+ this.element.appendChild(this.buttonContainer);
1058
+ this.element.appendChild(this.mountPoint);
1059
+ },
1060
+ disablePanelUp() {
1061
+ this.disabledUp = true;
1062
+ $$4.getClassList(this.moveUpButton).add("kf-editor-ui-disabled");
1063
+ },
1064
+ enablePanelUp() {
1065
+ this.disabledUp = false;
1066
+ $$4.getClassList(this.moveUpButton).remove("kf-editor-ui-disabled");
1067
+ },
1068
+ disablePanelDown() {
1069
+ this.disabledDown = true;
1070
+ $$4.getClassList(this.moveDownButton).add("kf-editor-ui-disabled");
1071
+ },
1072
+ enablePanelDown() {
1073
+ this.disabledDown = false;
1074
+ $$4.getClassList(this.moveDownButton).remove("kf-editor-ui-disabled");
1075
+ },
1076
+ updatePanelButtonState() {
1077
+ if (this.panelIndex === 0) {
1078
+ this.disablePanelUp();
1079
+ } else {
1080
+ this.enablePanelUp();
1081
+ }
1082
+ if (this.panelIndex + 1 >= this.maxPanelIndex) {
1083
+ this.disablePanelDown();
1084
+ } else {
1085
+ this.enablePanelDown();
1086
+ }
1087
+ },
1088
+ nextPanel() {
1089
+ if (this.disabledDown || this.panelIndex + 1 >= this.maxPanelIndex) {
1090
+ return;
1091
+ }
1092
+ this.panelIndex += 1;
1093
+ this.panel.style.top = `${-this.panelIndex * PANEL_HEIGHT}px`;
1094
+ this.updatePanelButtonState();
1095
+ },
1096
+ prevPanel() {
1097
+ if (this.disabledUp || this.panelIndex === 0) {
1098
+ return;
1099
+ }
1100
+ this.panelIndex -= 1;
1101
+ this.panel.style.top = `${-this.panelIndex * PANEL_HEIGHT}px`;
1102
+ this.updatePanelButtonState();
1103
+ },
1104
+ setToolbar(toolbar) {
1105
+ this.toolbar = toolbar;
1106
+ this.boxObject.setToolbar(toolbar);
1107
+ },
1108
+ attachTo(container) {
1109
+ container.appendChild(this.element);
1110
+ this.updateContent();
1111
+ this.updatePanelButtonState();
1112
+ }
1113
+ });
1114
+ var area_default = Area;
1115
+
1116
+ // ../kity-runtime/src/legacy/delimiter.ts
1117
+ var PREFIX5 = "kf-editor-ui-";
1118
+ var $$5 = createLegacyUiUtils();
1119
+ var kity6 = getLegacyKity();
1120
+ var Delimiter = kity6.createClass("Delimiter", {
1121
+ constructor(doc) {
1122
+ this.doc = doc;
1123
+ this.element = this.createDilimiter();
1124
+ },
1125
+ setToolbar(_toolbar) {
1126
+ },
1127
+ createDilimiter() {
1128
+ const dilimiterNode = $$5.ele(this.doc, "div", {
1129
+ className: `${PREFIX5}delimiter`
1130
+ });
1131
+ dilimiterNode.appendChild(
1132
+ $$5.ele(this.doc, "div", {
1133
+ className: `${PREFIX5}delimiter-line`
1134
+ })
1135
+ );
1136
+ return dilimiterNode;
1137
+ },
1138
+ attachTo(container) {
1139
+ container.appendChild(this.element);
1140
+ }
1141
+ });
1142
+ var delimiter_default = Delimiter;
1143
+
1144
+ // ../kity-runtime/src/legacy/dropdown-box.ts
1145
+ var $$6 = createLegacyUiUtils();
1146
+ var kity7 = getLegacyKity();
1147
+ var DrapdownBox = kity7.createClass("DrapdownBox", {
1148
+ constructor(doc, options) {
1149
+ this.options = options;
1150
+ this.toolbar = null;
1151
+ this.doc = doc;
1152
+ this.buttonElement = this.createButton();
1153
+ this.element = this.buttonElement.getNode();
1154
+ this.boxElement = this.createBox();
1155
+ this.buttonElement.mount(this.boxElement);
1156
+ this.initEvent();
1157
+ },
1158
+ initEvent() {
1159
+ $$6.on(this.element, "mousedown", (e) => {
1160
+ e.preventDefault();
1161
+ e.stopPropagation();
1162
+ this.toolbar?.notify("closeOther", this);
1163
+ });
1164
+ this.buttonElement.initEvent();
1165
+ this.boxElement.initEvent();
1166
+ this.boxElement.setSelectHandler((val) => {
1167
+ $$6.publish("data.select", val);
1168
+ this.buttonElement.hide();
1169
+ });
1170
+ },
1171
+ disable() {
1172
+ this.buttonElement.disable();
1173
+ },
1174
+ enable() {
1175
+ this.buttonElement.enable();
1176
+ },
1177
+ setToolbar(toolbar) {
1178
+ this.toolbar = toolbar;
1179
+ this.buttonElement.setToolbar(toolbar);
1180
+ this.boxElement.setToolbar(toolbar);
1181
+ },
1182
+ createButton() {
1183
+ return new button_default(this.doc, this.options.button);
1184
+ },
1185
+ show() {
1186
+ this.buttonElement.show();
1187
+ },
1188
+ hide() {
1189
+ this.buttonElement.hide();
1190
+ },
1191
+ createBox() {
1192
+ return new box_default(this.doc, this.options.box);
1193
+ },
1194
+ attachTo(container) {
1195
+ container.appendChild(this.element);
1196
+ }
1197
+ });
1198
+ var dropdown_box_default = DrapdownBox;
1199
+
1200
+ // ../kity-runtime/src/legacy/ui-impl.ts
1201
+ var UiImpl = {
1202
+ DrapdownBox: dropdown_box_default,
1203
+ Delimiter: delimiter_default,
1204
+ Area: area_default
1205
+ };
1206
+ var ui_impl_default = UiImpl;
1207
+
1208
+ // ../kity-runtime/src/legacy/toolbar.ts
1209
+ var $$7 = createLegacyUiUtils();
1210
+ var kity8 = getLegacyKity();
1211
+ var Toolbar = kity8.createClass("Tollbar", {
1212
+ constructor(uiComponent, kfEditor, elementList) {
1213
+ this.kfEditor = kfEditor;
1214
+ this.uiComponent = uiComponent;
1215
+ this.elementList = elementList;
1216
+ this.elements = [];
1217
+ this.initToolbarElements();
1218
+ this.initServices();
1219
+ this.initEvent();
1220
+ },
1221
+ initServices() {
1222
+ this.kfEditor.registerService("ui.toolbar.disable", this, {
1223
+ disableToolbar: this.disableToolbar
1224
+ });
1225
+ this.kfEditor.registerService("ui.toolbar.enable", this, {
1226
+ enableToolbar: this.enableToolbar
1227
+ });
1228
+ this.kfEditor.registerService("ui.toolbar.close", this, {
1229
+ closeToolbar: this.closeToolbar
1230
+ });
1231
+ },
1232
+ initEvent() {
1233
+ $$7.on(this.uiComponent.toolbarContainer, "mousedown", (e) => {
1234
+ e.preventDefault();
1235
+ });
1236
+ $$7.on(this.uiComponent.toolbarContainer, "mousewheel", (e) => {
1237
+ e.preventDefault();
1238
+ });
1239
+ $$7.on(this.kfEditor.getContainer(), "mousedown", () => {
1240
+ this.notify("closeAll");
1241
+ });
1242
+ $$7.subscribe("data.select", (...args) => {
1243
+ this.insertSource(String(args[0] ?? ""));
1244
+ });
1245
+ },
1246
+ insertSource(value) {
1247
+ this.kfEditor.requestService("control.insert.string", value);
1248
+ },
1249
+ disableToolbar() {
1250
+ kity8.Utils.each(this.elements, (ele) => {
1251
+ ele.disable?.();
1252
+ });
1253
+ },
1254
+ enableToolbar() {
1255
+ kity8.Utils.each(this.elements, (ele) => {
1256
+ ele.enable?.();
1257
+ });
1258
+ },
1259
+ getContainer() {
1260
+ return this.kfEditor.requestService("ui.get.canvas.container");
1261
+ },
1262
+ closeToolbar() {
1263
+ this.closeElement();
1264
+ },
1265
+ notify(type, exception) {
1266
+ switch (type) {
1267
+ case "closeAll":
1268
+ case "closeOther":
1269
+ this.closeElement(exception);
1270
+ return;
1271
+ default:
1272
+ return;
1273
+ }
1274
+ },
1275
+ closeElement(exception) {
1276
+ kity8.Utils.each(this.elements, (ele) => {
1277
+ if (ele !== exception) {
1278
+ ele.hide?.();
1279
+ }
1280
+ });
1281
+ },
1282
+ initToolbarElements() {
1283
+ const doc = this.uiComponent.toolbarContainer.ownerDocument;
1284
+ kity8.Utils.each(this.elementList, (eleInfo) => {
1285
+ const ele = createElement(eleInfo.type, doc, eleInfo.options);
1286
+ this.elements.push(ele);
1287
+ this.appendElement(ele);
1288
+ });
1289
+ },
1290
+ appendElement(uiElement) {
1291
+ uiElement.setToolbar(this);
1292
+ uiElement.attachTo(this.uiComponent.toolbarContainer);
1293
+ }
1294
+ });
1295
+ function createElement(type, doc, options) {
1296
+ switch (type) {
1297
+ case legacyEleType.DRAPDOWN_BOX:
1298
+ return createDrapdownBox(doc, options);
1299
+ case legacyEleType.DELIMITER:
1300
+ return createDelimiter(doc);
1301
+ case legacyEleType.AREA:
1302
+ return createArea(doc, options);
1303
+ default:
1304
+ throw new Error(`Unknown toolbar element type: ${String(type)}`);
1305
+ }
1306
+ }
1307
+ function createDrapdownBox(doc, options) {
1308
+ return new ui_impl_default.DrapdownBox(doc, options);
1309
+ }
1310
+ function createDelimiter(doc) {
1311
+ return new ui_impl_default.Delimiter(doc);
1312
+ }
1313
+ function createArea(doc, options) {
1314
+ return new ui_impl_default.Area(doc, options);
1315
+ }
1316
+ var toolbar_default = Toolbar;
1317
+
1318
+ // ../kity-runtime/src/legacy/scrollbar.ts
1319
+ var SCROLLBAR_DEF = legacyUiDef.scrollbar;
1320
+ var SCROLLBAR_CONF = legacySysconf.scrollbar;
1321
+ var CLASS_PREFIX = "kf-editor-ui-";
1322
+ var kity9 = getLegacyKity();
1323
+ function createElement2(doc, eleName, className) {
1324
+ const node = doc.createElement(eleName);
1325
+ const str = '<div class="$1"></div><div class="$2"></div>';
1326
+ node.className = CLASS_PREFIX + className;
1327
+ if (className === "thumb") {
1328
+ const thumbClassName = CLASS_PREFIX + className;
1329
+ node.innerHTML = str.replace("$1", `${thumbClassName}-left`).replace("$2", `${thumbClassName}-right`);
1330
+ }
1331
+ return node;
1332
+ }
1333
+ function preventDefault(comp) {
1334
+ legacyBaseUtils.addEvent(comp.container, "mousedown", (e) => {
1335
+ e.preventDefault();
1336
+ });
1337
+ }
1338
+ function trackClick(comp) {
1339
+ legacyBaseUtils.addEvent(comp.widgets.track, "mousedown", function(e) {
1340
+ trackClickHandler(this, comp, e);
1341
+ });
1342
+ }
1343
+ function btnClick(comp) {
1344
+ legacyBaseUtils.addEvent(comp.widgets.leftButton, "mousedown", () => {
1345
+ setThumbOffsetByStep(comp, -SCROLLBAR_CONF.step);
1346
+ });
1347
+ legacyBaseUtils.addEvent(comp.widgets.rightButton, "mousedown", () => {
1348
+ setThumbOffsetByStep(comp, SCROLLBAR_CONF.step);
1349
+ });
1350
+ }
1351
+ function thumbHandler(comp) {
1352
+ let isMoving = false;
1353
+ let startPoint = 0;
1354
+ let startOffset = 0;
1355
+ const trackWidth = comp.values.trackWidth;
1356
+ legacyBaseUtils.addEvent(comp.widgets.thumb, "mousedown", (e) => {
1357
+ e.preventDefault();
1358
+ e.stopPropagation();
1359
+ isMoving = true;
1360
+ startPoint = e.clientX;
1361
+ startOffset = comp.thumbLocationX;
1362
+ });
1363
+ legacyBaseUtils.addEvent(comp.container.ownerDocument, "mouseup", () => {
1364
+ isMoving = false;
1365
+ startPoint = 0;
1366
+ startOffset = 0;
1367
+ });
1368
+ legacyBaseUtils.addEvent(comp.container.ownerDocument, "mousemove", (e) => {
1369
+ if (!isMoving) {
1370
+ return;
1371
+ }
1372
+ const distance = e.clientX - startPoint;
1373
+ let offset = startOffset + distance;
1374
+ const thumbWidth = comp.values.thumbWidth;
1375
+ if (offset < 0) {
1376
+ offset = 0;
1377
+ } else if (offset + thumbWidth > trackWidth) {
1378
+ offset = trackWidth - thumbWidth;
1379
+ }
1380
+ setThumbLocation(comp, offset);
1381
+ });
1382
+ }
1383
+ function trackClickHandler(track, comp, evt) {
1384
+ const trackRect = legacyBaseUtils.getRect(track);
1385
+ const values = comp.values;
1386
+ const unitOffset = values.viewWidth / (values.contentWidth - values.viewWidth) * values.trackWidth;
1387
+ const clickOffset = evt.clientX - trackRect.left;
1388
+ if (clickOffset > values.offset) {
1389
+ if (values.offset + unitOffset > values.trackWidth) {
1390
+ setThumbOffset(comp, values.trackWidth);
1391
+ } else {
1392
+ setThumbOffset(comp, values.offset + unitOffset);
1393
+ }
1394
+ return;
1395
+ }
1396
+ if (values.offset - unitOffset < 0) {
1397
+ setThumbOffset(comp, 0);
1398
+ } else {
1399
+ setThumbOffset(comp, values.offset - unitOffset);
1400
+ }
1401
+ }
1402
+ function setThumbLocation(comp, locationX) {
1403
+ const values = comp.values;
1404
+ const trackPieceWidth = values.trackWidth - values.thumbWidth;
1405
+ const offset = Math.floor(locationX / trackPieceWidth * values.trackWidth);
1406
+ comp.updateOffset(offset);
1407
+ comp.thumbLocationX = locationX;
1408
+ comp.widgets.thumb.style.left = `${locationX}px`;
1409
+ }
1410
+ function setThumbOffsetByStep(comp, step) {
1411
+ let leftOverflow = comp.leftOverflow + step;
1412
+ if (leftOverflow < 0) {
1413
+ leftOverflow = 0;
1414
+ } else if (leftOverflow > comp.values.scrollWidth) {
1415
+ leftOverflow = comp.values.scrollWidth;
1416
+ }
1417
+ setThumbByLeftOverflow(comp, leftOverflow);
1418
+ }
1419
+ function setThumbOffset(comp, offset) {
1420
+ const values = comp.values;
1421
+ const offsetProportion = offset / values.trackWidth;
1422
+ const trackPieceWidth = values.trackWidth - values.thumbWidth;
1423
+ let thumbLocationX = Math.floor(offsetProportion * trackPieceWidth);
1424
+ if (offset < 0) {
1425
+ offset = 0;
1426
+ thumbLocationX = 0;
1427
+ }
1428
+ comp.updateOffset(offset);
1429
+ comp.widgets.thumb.style.left = `${thumbLocationX}px`;
1430
+ comp.thumbLocationX = thumbLocationX;
1431
+ }
1432
+ function setThumbOffsetByViewOffset(comp, viewOffset) {
1433
+ const values = comp.values;
1434
+ const offsetProportion = viewOffset / (values.contentWidth - values.viewWidth);
1435
+ const offset = Math.floor(offsetProportion * values.trackWidth);
1436
+ setThumbOffset(comp, offset);
1437
+ }
1438
+ function setThumbByLeftOverflow(comp, leftViewOverflow) {
1439
+ const values = comp.values;
1440
+ const overflowProportion = leftViewOverflow / (values.contentWidth - values.viewWidth);
1441
+ setThumbOffset(comp, overflowProportion * values.trackWidth);
1442
+ }
1443
+ var Scrollbar = kity9.createClass("Scrollbar", {
1444
+ constructor(uiComponent, kfEditor) {
1445
+ this.uiComponent = uiComponent;
1446
+ this.kfEditor = kfEditor;
1447
+ this.widgets = null;
1448
+ this.container = this.uiComponent.scrollbarContainer;
1449
+ this.state = false;
1450
+ this.values = {
1451
+ offset: 0,
1452
+ left: 0,
1453
+ viewWidth: 0,
1454
+ contentWidth: 0,
1455
+ trackWidth: 0,
1456
+ thumbWidth: 0,
1457
+ scrollWidth: 0
1458
+ };
1459
+ this.thumbLocationX = 0;
1460
+ this.leftOverflow = 0;
1461
+ this.rightOverflow = 0;
1462
+ this.isExpand = true;
1463
+ this.initWidget();
1464
+ this.mountWidget();
1465
+ this.initSize();
1466
+ this.hide();
1467
+ this.initServices();
1468
+ this.initEvent();
1469
+ this.updateHandler = function() {
1470
+ };
1471
+ },
1472
+ initWidget() {
1473
+ const doc = this.container.ownerDocument;
1474
+ this.widgets = {
1475
+ leftButton: createElement2(doc, "div", "left-button"),
1476
+ rightButton: createElement2(doc, "div", "right-button"),
1477
+ track: createElement2(doc, "div", "track"),
1478
+ thumb: createElement2(doc, "div", "thumb"),
1479
+ thumbBody: createElement2(doc, "div", "thumb-body")
1480
+ };
1481
+ },
1482
+ initSize() {
1483
+ const leftBtnWidth = legacyBaseUtils.getRect(this.widgets.leftButton).width;
1484
+ const rightBtnWidth = legacyBaseUtils.getRect(this.widgets.rightButton).width;
1485
+ this.values.viewWidth = legacyBaseUtils.getRect(this.container).width;
1486
+ this.values.trackWidth = this.values.viewWidth - leftBtnWidth - rightBtnWidth;
1487
+ this.widgets.track.style.width = `${this.values.trackWidth}px`;
1488
+ },
1489
+ initServices() {
1490
+ this.kfEditor.registerService("ui.show.scrollbar", this, {
1491
+ showScrollbar: this.show
1492
+ });
1493
+ this.kfEditor.registerService("ui.hide.scrollbar", this, {
1494
+ hideScrollbar: this.hide
1495
+ });
1496
+ this.kfEditor.registerService("ui.update.scrollbar", this, {
1497
+ updateScrollbar: this.update
1498
+ });
1499
+ this.kfEditor.registerService("ui.set.scrollbar.update.handler", this, {
1500
+ setUpdateHandler: this.setUpdateHandler
1501
+ });
1502
+ this.kfEditor.registerService("ui.relocation.scrollbar", this, {
1503
+ relocation: this.relocation
1504
+ });
1505
+ },
1506
+ initEvent() {
1507
+ preventDefault(this);
1508
+ trackClick(this);
1509
+ thumbHandler(this);
1510
+ btnClick(this);
1511
+ },
1512
+ mountWidget() {
1513
+ const widgets = this.widgets;
1514
+ const container = this.container;
1515
+ for (const wgtName in widgets) {
1516
+ if (Object.prototype.hasOwnProperty.call(widgets, wgtName)) {
1517
+ container.appendChild(widgets[wgtName]);
1518
+ }
1519
+ }
1520
+ widgets.thumb.appendChild(widgets.thumbBody);
1521
+ widgets.track.appendChild(widgets.thumb);
1522
+ },
1523
+ show() {
1524
+ this.state = true;
1525
+ this.container.style.display = "block";
1526
+ },
1527
+ hide() {
1528
+ this.state = false;
1529
+ this.container.style.display = "none";
1530
+ },
1531
+ update(contentWidth) {
1532
+ const trackWidth = this.values.trackWidth;
1533
+ this.isExpand = contentWidth > this.values.contentWidth;
1534
+ this.values.contentWidth = contentWidth;
1535
+ this.values.scrollWidth = contentWidth - this.values.viewWidth;
1536
+ if (trackWidth >= contentWidth) {
1537
+ this.hide();
1538
+ return;
1539
+ }
1540
+ const thumbWidth = Math.max(Math.ceil(trackWidth * trackWidth / contentWidth), SCROLLBAR_DEF.thumbMinSize);
1541
+ this.values.thumbWidth = thumbWidth;
1542
+ this.widgets.thumb.style.width = `${thumbWidth}px`;
1543
+ this.widgets.thumbBody.style.width = `${thumbWidth - 10}px`;
1544
+ },
1545
+ setUpdateHandler(updateHandler) {
1546
+ this.updateHandler = updateHandler;
1547
+ },
1548
+ updateOffset(offset) {
1549
+ const values = this.values;
1550
+ values.offset = offset;
1551
+ values.left = offset / values.trackWidth;
1552
+ this.leftOverflow = values.left * (values.contentWidth - values.viewWidth);
1553
+ this.rightOverflow = values.contentWidth - values.viewWidth - this.leftOverflow;
1554
+ this.updateHandler(values.left, values.offset, values);
1555
+ },
1556
+ relocation() {
1557
+ const cursorLocation = this.kfEditor.requestService("control.get.cursor.location");
1558
+ const padding = SCROLLBAR_CONF.padding;
1559
+ const contentWidth = this.values.contentWidth;
1560
+ const viewWidth = this.values.viewWidth;
1561
+ const viewLeftOverflow = this.values.left * (contentWidth - viewWidth);
1562
+ if (cursorLocation.x < viewLeftOverflow) {
1563
+ if (cursorLocation.x < 0) {
1564
+ cursorLocation.x = 0;
1565
+ }
1566
+ setThumbOffsetByViewOffset(this, cursorLocation.x);
1567
+ return;
1568
+ }
1569
+ if (cursorLocation.x + padding > viewLeftOverflow + viewWidth) {
1570
+ cursorLocation.x += padding;
1571
+ if (cursorLocation.x > contentWidth) {
1572
+ cursorLocation.x = contentWidth;
1573
+ }
1574
+ const diff = cursorLocation.x - viewWidth;
1575
+ setThumbOffsetByViewOffset(this, diff);
1576
+ return;
1577
+ }
1578
+ if (this.isExpand) {
1579
+ setThumbByLeftOverflow(this, this.leftOverflow);
1580
+ } else {
1581
+ setThumbByLeftOverflow(this, contentWidth - viewWidth - this.rightOverflow);
1582
+ }
1583
+ }
1584
+ });
1585
+ var scrollbar_default = Scrollbar;
1586
+
1587
+ // ../kity-runtime/src/formula-symbols.ts
1588
+ var UNICODE_SYMBOLS = {
1589
+ pm: "\xB1",
1590
+ infty: "\u221E",
1591
+ "=": "=",
1592
+ sim: "\u223C",
1593
+ times: "\xD7",
1594
+ div: "\xF7",
1595
+ "!": "!",
1596
+ "<": "<",
1597
+ ll: "\u226A",
1598
+ ">": ">",
1599
+ gg: "\u226B",
1600
+ leq: "\u2264",
1601
+ geq: "\u2265",
1602
+ mp: "\u2213",
1603
+ cong: "\u2245",
1604
+ equiv: "\u2261",
1605
+ propto: "\u221D",
1606
+ approx: "\u2248",
1607
+ forall: "\u2200",
1608
+ partial: "\u2202",
1609
+ surd: "\u221A",
1610
+ cup: "\u222A",
1611
+ cap: "\u2229",
1612
+ varnothing: "\u2205",
1613
+ "%": "%",
1614
+ circ: "\u2218",
1615
+ exists: "\u2203",
1616
+ nexists: "\u2204",
1617
+ in: "\u2208",
1618
+ ni: "\u220B",
1619
+ gets: "\u2190",
1620
+ uparrow: "\u2191",
1621
+ to: "\u2192",
1622
+ downarrow: "\u2193",
1623
+ leftrightarrow: "\u2194",
1624
+ updownarrow: "\u2195",
1625
+ therefore: "\u2234",
1626
+ because: "\u2235",
1627
+ "+": "+",
1628
+ "-": "\u2212",
1629
+ neg: "\xAC",
1630
+ ast: "\u2217",
1631
+ cdot: "\u22C5",
1632
+ vdots: "\u22EE",
1633
+ aleph: "\u2135",
1634
+ beth: "\u2136",
1635
+ blacksquare: "\u25A0",
1636
+ alpha: "\u03B1",
1637
+ beta: "\u03B2",
1638
+ gamma: "\u03B3",
1639
+ delta: "\u03B4",
1640
+ epsilon: "\u03B5",
1641
+ zeta: "\u03B6",
1642
+ eta: "\u03B7",
1643
+ theta: "\u03B8",
1644
+ iota: "\u03B9",
1645
+ kappa: "\u03BA",
1646
+ lambda: "\u03BB",
1647
+ mu: "\u03BC",
1648
+ nu: "\u03BD",
1649
+ xi: "\u03BE",
1650
+ omicron: "\u03BF",
1651
+ pi: "\u03C0",
1652
+ rho: "\u03C1",
1653
+ sigma: "\u03C3",
1654
+ tau: "\u03C4",
1655
+ upsilon: "\u03C5",
1656
+ phi: "\u03C6",
1657
+ chi: "\u03C7",
1658
+ psi: "\u03C8",
1659
+ omega: "\u03C9",
1660
+ Alpha: "\u0391",
1661
+ Beta: "\u0392",
1662
+ Gamma: "\u0393",
1663
+ Delta: "\u0394",
1664
+ Epsilon: "\u0395",
1665
+ Zeta: "\u0396",
1666
+ Eta: "\u0397",
1667
+ Theta: "\u0398",
1668
+ Iota: "\u0399",
1669
+ Kappa: "\u039A",
1670
+ Lambda: "\u039B",
1671
+ Mu: "\u039C",
1672
+ Nu: "\u039D",
1673
+ Xi: "\u039E",
1674
+ Omicron: "\u039F",
1675
+ Pi: "\u03A0",
1676
+ Rho: "\u03A1",
1677
+ Sigma: "\u03A3",
1678
+ Tau: "\u03A4",
1679
+ Upsilon: "\u03A5",
1680
+ Phi: "\u03A6",
1681
+ Chi: "\u03A7",
1682
+ Psi: "\u03A8",
1683
+ Omega: "\u03A9",
1684
+ digamma: "\u03DD",
1685
+ varepsilon: "\u03F5",
1686
+ varkappa: "\u03F0",
1687
+ varphi: "\u03C6",
1688
+ varpi: "\u03D6",
1689
+ varrho: "\u03F1",
1690
+ varsigma: "\u03C2",
1691
+ vartheta: "\u03D1",
1692
+ neq: "\u2260",
1693
+ nless: "\u226E",
1694
+ ngtr: "\u226F",
1695
+ nleq: "\u2270",
1696
+ ngeq: "\u2271",
1697
+ nsim: "\u2241",
1698
+ lneqq: "\u2268",
1699
+ gneqq: "\u2269",
1700
+ nprec: "\u2280",
1701
+ nsucc: "\u2281",
1702
+ notin: "\u2209",
1703
+ nsubseteq: "\u2288",
1704
+ nsupseteq: "\u2289",
1705
+ subsetneq: "\u228A",
1706
+ supsetneq: "\u228B",
1707
+ lnsim: "\u22E6",
1708
+ gnsim: "\u22E7",
1709
+ precnsim: "\u22E8",
1710
+ succnsim: "\u22E9",
1711
+ ntriangleleft: "\u22EA",
1712
+ ntriangleright: "\u22EB",
1713
+ ntrianglelefteq: "\u22EC",
1714
+ ntrianglerighteq: "\u22ED",
1715
+ nmid: "\u2224",
1716
+ nparallel: "\u2226",
1717
+ nvdash: "\u22AC",
1718
+ nVdash: "\u22AE",
1719
+ nvDash: "\u22AD",
1720
+ nVDash: "\u22AF",
1721
+ daleth: "\u2138",
1722
+ gimel: "\u2137",
1723
+ complement: "\u2201",
1724
+ ell: "\u2113",
1725
+ eth: "\xF0",
1726
+ hbar: "\u210F",
1727
+ hslash: "\u210F",
1728
+ mho: "\u2127",
1729
+ wp: "\u2118",
1730
+ circledS: "\u24C8",
1731
+ Bbbk: "\u212C",
1732
+ Finv: "\u2132",
1733
+ Game: "\u2141",
1734
+ Im: "\u2111",
1735
+ Re: "\u211C",
1736
+ Leftarrow: "\u21D0",
1737
+ Rightarrow: "\u21D2",
1738
+ Uparrow: "\u21D1",
1739
+ Downarrow: "\u21D3",
1740
+ Leftrightarrow: "\u21D4",
1741
+ Updownarrow: "\u21D5",
1742
+ longleftarrow: "\u27F5",
1743
+ longrightarrow: "\u27F6",
1744
+ longleftrightarrow: "\u27F7",
1745
+ Longleftarrow: "\u27F8",
1746
+ Longrightarrow: "\u27F9",
1747
+ Longleftrightarrow: "\u27FA",
1748
+ nearrow: "\u2197",
1749
+ nwarrow: "\u2196",
1750
+ searrow: "\u2198",
1751
+ swarrow: "\u2199",
1752
+ nleftarrow: "\u219A",
1753
+ nrightarrow: "\u219B",
1754
+ nLeftarrow: "\u21CD",
1755
+ nRightarrow: "\u21CF",
1756
+ nLeftrightarrow: "\u21CE",
1757
+ leftharpoonup: "\u21BC",
1758
+ leftharpoondown: "\u21BD",
1759
+ rightharpoonup: "\u21C0",
1760
+ rightharpoondown: "\u21C1",
1761
+ upharpoonleft: "\u21BF",
1762
+ upharpoonright: "\u21BE",
1763
+ downharpoonleft: "\u21C3",
1764
+ downharpoonright: "\u21C2",
1765
+ leftrightharpoons: "\u21CB",
1766
+ rightleftharpoons: "\u21CC",
1767
+ leftleftarrows: "\u21C7",
1768
+ rightrightarrows: "\u21C9",
1769
+ upuparrows: "\u21C8",
1770
+ downdownarrows: "\u21CA",
1771
+ leftrightarrows: "\u21C6",
1772
+ rightleftarrows: "\u21C4",
1773
+ looparrowleft: "\u21AB",
1774
+ looparrowright: "\u21AC",
1775
+ leftarrowtail: "\u21A2",
1776
+ rightarrowtail: "\u21A3",
1777
+ Lsh: "\u21B0",
1778
+ Rsh: "\u21B1",
1779
+ Lleftarrow: "\u21DA",
1780
+ Rrightarrow: "\u21DB",
1781
+ curvearrowleft: "\u21B6",
1782
+ curvearrowright: "\u21B7",
1783
+ circlearrowleft: "\u21BA",
1784
+ circlearrowright: "\u21BB",
1785
+ multimap: "\u22B8",
1786
+ leftrightsquigarrow: "\u21AD",
1787
+ twoheadleftarrow: "\u219E",
1788
+ twoheadrightarrow: "\u21A0",
1789
+ rightsquigarrow: "\u21DD"
1790
+ };
1791
+ var STYLE_FONT_MAP = {
1792
+ mathcal: "KF AMS CAL, serif",
1793
+ mathfrak: "KF AMS FRAK, serif",
1794
+ mathbb: "KF AMS BB, serif",
1795
+ mathrm: "KF AMS ROMAN, serif"
1796
+ };
1797
+ function resolveUnicode(key) {
1798
+ const clean = key.replace(/^\\/, "");
1799
+ for (const style of ["mathcal", "mathfrak", "mathbb", "mathrm"]) {
1800
+ const prefix = `${style}{`;
1801
+ if (clean.startsWith(prefix) && clean.endsWith("}")) {
1802
+ const letter = clean.slice(prefix.length, -1);
1803
+ return {
1804
+ char: letter,
1805
+ fontFamily: STYLE_FONT_MAP[style]
1806
+ };
1807
+ }
1808
+ }
1809
+ const code = UNICODE_SYMBOLS[clean];
1810
+ if (code !== void 0) {
1811
+ return { char: code };
1812
+ }
1813
+ return null;
1814
+ }
1815
+
1816
+ // ../kity-runtime/src/legacy/toolbar-config.ts
1817
+ var UI_ELE_TYPE = legacyEleType;
1818
+ var BOX_TYPE2 = legacyBoxType;
1819
+ var OTHER_POSITION = legacyOtherPosition;
1820
+ function each(list, callback) {
1821
+ if (Array.isArray(list)) {
1822
+ list.forEach((item, index) => callback(item, index));
1823
+ return;
1824
+ }
1825
+ Object.keys(list).forEach((key) => callback(list[key], key));
1826
+ }
1827
+ function translateToolbarText(value, locale) {
1828
+ return translateFormulaXText("toolbar", value, locale);
1829
+ }
1830
+ function localizeToolbarConfig(value, locale) {
1831
+ if (Array.isArray(value)) {
1832
+ return value.map((item) => localizeToolbarConfig(item, locale));
1833
+ }
1834
+ if (!value || typeof value !== "object") {
1835
+ return value;
1836
+ }
1837
+ const result = {};
1838
+ for (const [key, currentValue] of Object.entries(value)) {
1839
+ if ((key === "label" || key === "title") && typeof currentValue === "string") {
1840
+ result[key] = translateToolbarText(currentValue, locale);
1841
+ continue;
1842
+ }
1843
+ result[key] = localizeToolbarConfig(currentValue, locale);
1844
+ }
1845
+ return result;
1846
+ }
1847
+ var baseToolbarConfig = [{
1848
+ type: UI_ELE_TYPE.DRAPDOWN_BOX,
1849
+ options: {
1850
+ button: {
1851
+ label: "\u9884\u8BBE<br/>",
1852
+ className: "yushe-btn",
1853
+ icon: {
1854
+ src: resolveToolbarAssetPath("btn.png"),
1855
+ x: 0,
1856
+ y: 0
1857
+ },
1858
+ iconSize: {
1859
+ w: 40
1860
+ }
1861
+ },
1862
+ box: {
1863
+ width: 367,
1864
+ group: [{
1865
+ title: "\u9884\u8BBE\u516C\u5F0F",
1866
+ items: [{
1867
+ title: "\u9884\u8BBE\u516C\u5F0F",
1868
+ content: [{
1869
+ label: "\u4E8C\u6B21\u516C\u5F0F",
1870
+ item: {
1871
+ val: "x=\\frac {-b\\pm\\sqrt {b^2-4ac}}{2a}"
1872
+ }
1873
+ }, {
1874
+ label: "\u4E8C\u9879\u5F0F\u5B9A\u7406",
1875
+ item: {
1876
+ val: "{\\left(x+a\\right)}^2=\\sum^n_{k=0}{\\left(^n_k\\right)x^ka^{n-k}}"
1877
+ }
1878
+ }, {
1879
+ label: "\u52FE\u80A1\u5B9A\u7406",
1880
+ item: {
1881
+ val: "a^2+b^2=c^2"
1882
+ }
1883
+ }]
1884
+ }]
1885
+ }]
1886
+ }
1887
+ }
1888
+ }, {
1889
+ type: UI_ELE_TYPE.DELIMITER
1890
+ }, {
1891
+ type: UI_ELE_TYPE.AREA,
1892
+ options: {
1893
+ box: {
1894
+ fixOffset: true,
1895
+ width: 527,
1896
+ type: BOX_TYPE2.OVERLAP,
1897
+ group: [{
1898
+ title: "\u57FA\u7840\u6570\u5B66",
1899
+ items: []
1900
+ }, {
1901
+ title: "\u5E0C\u814A\u5B57\u6BCD",
1902
+ items: []
1903
+ }, {
1904
+ title: "\u6C42\u53CD\u5173\u7CFB\u8FD0\u7B97\u7B26",
1905
+ items: []
1906
+ }, {
1907
+ title: "\u5B57\u6BCD\u7C7B\u7B26\u53F7",
1908
+ items: []
1909
+ }, {
1910
+ title: "\u7BAD\u5934",
1911
+ items: []
1912
+ }, {
1913
+ title: "\u624B\u5199\u4F53",
1914
+ items: []
1915
+ }]
1916
+ }
1917
+ }
1918
+ }, {
1919
+ type: UI_ELE_TYPE.DELIMITER
1920
+ }, {
1921
+ type: UI_ELE_TYPE.DRAPDOWN_BOX,
1922
+ options: {
1923
+ button: {
1924
+ label: "\u5206\u6570<br/>",
1925
+ icon: {
1926
+ src: resolveToolbarAssetPath("btn.png"),
1927
+ x: 45,
1928
+ y: 0
1929
+ }
1930
+ },
1931
+ box: {
1932
+ width: 332,
1933
+ group: [{
1934
+ title: "\u5206\u6570",
1935
+ items: [{
1936
+ title: "\u5206\u6570",
1937
+ content: [{
1938
+ item: {
1939
+ val: "\\frac \\placeholder\\placeholder"
1940
+ }
1941
+ }, {
1942
+ item: {
1943
+ val: "{\\placeholder/\\placeholder}"
1944
+ }
1945
+ }]
1946
+ }, {
1947
+ title: "\u5E38\u7528\u5206\u6570",
1948
+ content: [{
1949
+ item: {
1950
+ val: "\\frac {dy}{dx}"
1951
+ }
1952
+ }, {
1953
+ item: {
1954
+ val: "\\frac {\\Delta y}{\\Delta x}"
1955
+ }
1956
+ }, {
1957
+ item: {
1958
+ val: "\\frac {\\delta y}{\\delta x}"
1959
+ }
1960
+ }, {
1961
+ item: {
1962
+ val: "\\frac \\pi 2"
1963
+ }
1964
+ }]
1965
+ }]
1966
+ }]
1967
+ }
1968
+ }
1969
+ }, {
1970
+ type: UI_ELE_TYPE.DRAPDOWN_BOX,
1971
+ options: {
1972
+ button: {
1973
+ label: "\u4E0A\u4E0B\u6807<br/>",
1974
+ icon: {
1975
+ src: resolveToolbarAssetPath("btn.png"),
1976
+ x: 82,
1977
+ y: 0
1978
+ }
1979
+ },
1980
+ box: {
1981
+ width: 332,
1982
+ group: [{
1983
+ title: "\u4E0A\u6807\u548C\u4E0B\u6807",
1984
+ items: [{
1985
+ title: "\u4E0A\u6807\u548C\u4E0B\u6807",
1986
+ content: [{
1987
+ item: {
1988
+ val: "\\placeholder^\\placeholder"
1989
+ }
1990
+ }, {
1991
+ item: {
1992
+ val: "\\placeholder_\\placeholder"
1993
+ }
1994
+ }, {
1995
+ item: {
1996
+ val: "\\placeholder^\\placeholder_\\placeholder"
1997
+ }
1998
+ }, {
1999
+ item: {
2000
+ val: "{^\\placeholder_\\placeholder\\placeholder}"
2001
+ }
2002
+ }]
2003
+ }, {
2004
+ title: "\u5E38\u7528\u7684\u4E0A\u6807\u548C\u4E0B\u6807",
2005
+ content: [{
2006
+ item: {
2007
+ val: "e^{-i\\omega t}"
2008
+ }
2009
+ }, {
2010
+ item: {
2011
+ val: "x^2"
2012
+ }
2013
+ }, {
2014
+ item: {
2015
+ val: "{}^n_1Y"
2016
+ }
2017
+ }]
2018
+ }]
2019
+ }]
2020
+ }
2021
+ }
2022
+ }, {
2023
+ type: UI_ELE_TYPE.DRAPDOWN_BOX,
2024
+ options: {
2025
+ button: {
2026
+ label: "\u6839\u5F0F<br/>",
2027
+ icon: {
2028
+ src: resolveToolbarAssetPath("btn.png"),
2029
+ x: 119,
2030
+ y: 0
2031
+ }
2032
+ },
2033
+ box: {
2034
+ width: 342,
2035
+ group: [{
2036
+ title: "\u6839\u5F0F",
2037
+ items: [{
2038
+ title: "\u6839\u5F0F",
2039
+ content: [{
2040
+ item: {
2041
+ val: "\\sqrt \\placeholder"
2042
+ }
2043
+ }, {
2044
+ item: {
2045
+ val: "\\sqrt [\\placeholder] \\placeholder"
2046
+ }
2047
+ }, {
2048
+ item: {
2049
+ val: "\\sqrt [2] \\placeholder"
2050
+ }
2051
+ }, {
2052
+ item: {
2053
+ val: "\\sqrt [3] \\placeholder"
2054
+ }
2055
+ }]
2056
+ }, {
2057
+ title: "\u5E38\u7528\u6839\u5F0F",
2058
+ content: [{
2059
+ item: {
2060
+ val: "\\frac {-b\\pm\\sqrt{b^2-4ac}}{2a}"
2061
+ }
2062
+ }, {
2063
+ item: {
2064
+ val: "\\sqrt {a^2+b^2}"
2065
+ }
2066
+ }]
2067
+ }]
2068
+ }]
2069
+ }
2070
+ }
2071
+ }, {
2072
+ type: UI_ELE_TYPE.DRAPDOWN_BOX,
2073
+ options: {
2074
+ button: {
2075
+ label: "\u79EF\u5206<br/>",
2076
+ icon: {
2077
+ src: resolveToolbarAssetPath("btn.png"),
2078
+ x: 156,
2079
+ y: 0
2080
+ }
2081
+ },
2082
+ box: {
2083
+ width: 332,
2084
+ group: [{
2085
+ title: "\u79EF\u5206",
2086
+ items: [{
2087
+ title: "\u79EF\u5206",
2088
+ content: [{
2089
+ item: {
2090
+ val: "\\int \\placeholder"
2091
+ }
2092
+ }, {
2093
+ item: {
2094
+ val: "\\int^\\placeholder_\\placeholder\\placeholder"
2095
+ }
2096
+ }, {
2097
+ item: {
2098
+ val: "\\iint\\placeholder"
2099
+ }
2100
+ }, {
2101
+ item: {
2102
+ val: "\\iint^\\placeholder_\\placeholder\\placeholder"
2103
+ }
2104
+ }, {
2105
+ item: {
2106
+ val: "\\iiint\\placeholder"
2107
+ }
2108
+ }, {
2109
+ item: {
2110
+ val: "\\iiint^\\placeholder_\\placeholder\\placeholder"
2111
+ }
2112
+ }]
2113
+ }]
2114
+ }]
2115
+ }
2116
+ }
2117
+ }, {
2118
+ type: UI_ELE_TYPE.DRAPDOWN_BOX,
2119
+ options: {
2120
+ button: {
2121
+ label: "\u5927\u578B<br/>\u8FD0\u7B97\u7B26",
2122
+ icon: {
2123
+ src: resolveToolbarAssetPath("btn.png"),
2124
+ x: 193,
2125
+ y: 0
2126
+ }
2127
+ },
2128
+ box: {
2129
+ width: 332,
2130
+ group: [{
2131
+ title: "\u6C42\u548C",
2132
+ items: [{
2133
+ title: "\u6C42\u548C",
2134
+ content: [{
2135
+ item: {
2136
+ val: "\\sum\\placeholder"
2137
+ }
2138
+ }, {
2139
+ item: {
2140
+ val: "\\sum^\\placeholder_\\placeholder\\placeholder"
2141
+ }
2142
+ }, {
2143
+ item: {
2144
+ val: "\\sum_\\placeholder\\placeholder"
2145
+ }
2146
+ }]
2147
+ }]
2148
+ }]
2149
+ }
2150
+ }
2151
+ }, {
2152
+ type: UI_ELE_TYPE.DRAPDOWN_BOX,
2153
+ options: {
2154
+ button: {
2155
+ label: "\u62EC\u53F7<br/>",
2156
+ icon: {
2157
+ src: resolveToolbarAssetPath("btn.png"),
2158
+ x: 230,
2159
+ y: 0
2160
+ }
2161
+ },
2162
+ box: {
2163
+ width: 332,
2164
+ group: [{
2165
+ title: "\u65B9\u62EC\u53F7",
2166
+ items: [{
2167
+ title: "\u65B9\u62EC\u53F7",
2168
+ content: [{
2169
+ item: {
2170
+ val: "\\left(\\placeholder\\right)"
2171
+ }
2172
+ }, {
2173
+ item: {
2174
+ val: "\\left[\\placeholder\\right]"
2175
+ }
2176
+ }, {
2177
+ item: {
2178
+ val: "\\left\\{\\placeholder\\right\\}"
2179
+ }
2180
+ }, {
2181
+ item: {
2182
+ val: "\\left|\\placeholder\\right|"
2183
+ }
2184
+ }]
2185
+ }]
2186
+ }]
2187
+ }
2188
+ }
2189
+ }, {
2190
+ type: UI_ELE_TYPE.DRAPDOWN_BOX,
2191
+ options: {
2192
+ button: {
2193
+ label: "\u51FD\u6570<br/>",
2194
+ icon: {
2195
+ src: resolveToolbarAssetPath("btn.png"),
2196
+ x: 267,
2197
+ y: 0
2198
+ }
2199
+ },
2200
+ box: {
2201
+ width: 340,
2202
+ group: [{
2203
+ title: "\u51FD\u6570",
2204
+ items: [{
2205
+ title: "\u4E09\u89D2\u51FD\u6570",
2206
+ content: [{
2207
+ item: {
2208
+ val: "\\sin\\placeholder"
2209
+ }
2210
+ }, {
2211
+ item: {
2212
+ val: "\\cos\\placeholder"
2213
+ }
2214
+ }, {
2215
+ item: {
2216
+ val: "\\tan\\placeholder"
2217
+ }
2218
+ }, {
2219
+ item: {
2220
+ val: "\\csc\\placeholder"
2221
+ }
2222
+ }, {
2223
+ item: {
2224
+ val: "\\sec\\placeholder"
2225
+ }
2226
+ }, {
2227
+ item: {
2228
+ val: "\\cot\\placeholder"
2229
+ }
2230
+ }]
2231
+ }, {
2232
+ title: "\u5E38\u7528\u51FD\u6570",
2233
+ content: [{
2234
+ item: {
2235
+ val: "\\sin\\theta"
2236
+ }
2237
+ }, {
2238
+ item: {
2239
+ val: "\\cos{2x}"
2240
+ }
2241
+ }, {
2242
+ item: {
2243
+ val: "\\tan\\theta=\\frac {\\sin\\theta}{\\cos\\theta}"
2244
+ }
2245
+ }]
2246
+ }]
2247
+ }]
2248
+ }
2249
+ }
2250
+ }];
2251
+ (function() {
2252
+ let tmp = [], otherImageSrc = resolveToolbarAssetPath("other.png"), currentConf = [];
2253
+ each(baseToolbarConfig, function(conf) {
2254
+ if (conf.type === UI_ELE_TYPE.DELIMITER) {
2255
+ return;
2256
+ }
2257
+ conf = conf.options.box.group;
2258
+ tmp = tmp.concat(conf);
2259
+ });
2260
+ each(tmp, function(conf) {
2261
+ conf = conf.items;
2262
+ for (let i = 0, len = conf.length; i < len; i++) {
2263
+ currentConf = currentConf.concat(conf[i].content);
2264
+ }
2265
+ });
2266
+ each(currentConf, function(conf) {
2267
+ let data = OTHER_POSITION[conf.item.val];
2268
+ if (!data) {
2269
+ return;
2270
+ }
2271
+ conf.item.img = otherImageSrc;
2272
+ conf.item.pos = data.pos;
2273
+ conf.item.size = data.size;
2274
+ });
2275
+ })();
2276
+ (function() {
2277
+ let list = [
2278
+ "pm",
2279
+ "infty",
2280
+ "=",
2281
+ "sim",
2282
+ "times",
2283
+ "div",
2284
+ "!",
2285
+ "<",
2286
+ "ll",
2287
+ ">",
2288
+ "gg",
2289
+ "leq",
2290
+ "geq",
2291
+ "mp",
2292
+ "cong",
2293
+ "equiv",
2294
+ "propto",
2295
+ "approx",
2296
+ "forall",
2297
+ "partial",
2298
+ "surd",
2299
+ "cup",
2300
+ "cap",
2301
+ "varnothing",
2302
+ "%",
2303
+ "circ",
2304
+ "exists",
2305
+ "nexists",
2306
+ "in",
2307
+ "ni",
2308
+ "gets",
2309
+ "uparrow",
2310
+ "to",
2311
+ "downarrow",
2312
+ "leftrightarrow",
2313
+ "therefore",
2314
+ "because",
2315
+ "+",
2316
+ "-",
2317
+ "neg",
2318
+ "ast",
2319
+ "cdot",
2320
+ "vdots",
2321
+ /* "ddots",*/
2322
+ "aleph",
2323
+ "beth",
2324
+ "blacksquare"
2325
+ ], configList = baseToolbarConfig[2].options.box.group[0].items;
2326
+ configList.push({
2327
+ title: "\u57FA\u7840\u6570\u5B66",
2328
+ content: getUnicodeContents(list)
2329
+ });
2330
+ })();
2331
+ (function() {
2332
+ let greekList = [{
2333
+ title: "\u5C0F\u5199",
2334
+ values: ["alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota", "kappa", "lambda", "mu", "nu", "xi", "omicron", "pi", "rho", "sigma", "tau", "upsilon", "phi", "chi", "psi", "omega"]
2335
+ }, {
2336
+ title: "\u5927\u5199",
2337
+ values: ["Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta", "Iota", "Kappa", "Lambda", "Mu", "Nu", "Xi", "Omicron", "Pi", "Rho", "Sigma", "Tau", "Upsilon", "Phi", "Chi", "Psi", "Omega"]
2338
+ }, {
2339
+ title: "\u53D8\u4F53",
2340
+ values: ["digamma", "varepsilon", "varkappa", "varphi", "varpi", "varrho", "varsigma", "vartheta"]
2341
+ }], greekConfigList = baseToolbarConfig[2].options.box.group[1].items;
2342
+ greekConfigList.push({
2343
+ title: greekList[0].title,
2344
+ content: getUnicodeContents(greekList[0].values)
2345
+ });
2346
+ greekConfigList.push({
2347
+ title: greekList[1].title,
2348
+ content: getUnicodeContents(greekList[1].values)
2349
+ });
2350
+ greekConfigList.push({
2351
+ title: greekList[2].title,
2352
+ content: getUnicodeContents(greekList[2].values)
2353
+ });
2354
+ })();
2355
+ (function() {
2356
+ let greekList = [{
2357
+ title: "\u6C42\u53CD\u5173\u7CFB\u8FD0\u7B97\u7B26",
2358
+ values: [
2359
+ "neq",
2360
+ "nless",
2361
+ "ngtr",
2362
+ "nleq",
2363
+ "ngeq",
2364
+ "nsim",
2365
+ "lneqq",
2366
+ "gneqq",
2367
+ "nprec",
2368
+ "nsucc",
2369
+ "notin",
2370
+ "nsubseteq",
2371
+ "nsupseteq",
2372
+ "subsetneq",
2373
+ "supsetneq",
2374
+ "lnsim",
2375
+ "gnsim",
2376
+ "precnsim",
2377
+ "succnsim",
2378
+ "ntriangleleft",
2379
+ "ntriangleright",
2380
+ "ntrianglelefteq",
2381
+ "ntrianglerighteq",
2382
+ "nmid",
2383
+ "nparallel",
2384
+ "nvdash",
2385
+ "nVdash",
2386
+ "nvDash",
2387
+ "nVDash",
2388
+ "nexists"
2389
+ ]
2390
+ }], greekConfigList = baseToolbarConfig[2].options.box.group[2].items;
2391
+ greekConfigList.push({
2392
+ title: greekList[0].title,
2393
+ content: getUnicodeContents(greekList[0].values)
2394
+ });
2395
+ })();
2396
+ (function() {
2397
+ let list = [
2398
+ "aleph",
2399
+ "beth",
2400
+ "daleth",
2401
+ "gimel",
2402
+ "complement",
2403
+ "ell",
2404
+ "eth",
2405
+ "hbar",
2406
+ "hslash",
2407
+ "mho",
2408
+ "partial",
2409
+ "wp",
2410
+ "circledS",
2411
+ "Bbbk",
2412
+ "Finv",
2413
+ "Game",
2414
+ "Im",
2415
+ "Re"
2416
+ ], configList = baseToolbarConfig[2].options.box.group[3].items;
2417
+ configList.push({
2418
+ title: "\u5B57\u6BCD\u7C7B\u7B26\u53F7",
2419
+ content: getUnicodeContents(list)
2420
+ });
2421
+ })();
2422
+ (function() {
2423
+ let list = [
2424
+ "gets",
2425
+ "to",
2426
+ "uparrow",
2427
+ "downarrow",
2428
+ "leftrightarrow",
2429
+ "updownarrow",
2430
+ "Leftarrow",
2431
+ "Rightarrow",
2432
+ "Uparrow",
2433
+ "Downarrow",
2434
+ "Leftrightarrow",
2435
+ "Updownarrow",
2436
+ "longleftarrow",
2437
+ "longrightarrow",
2438
+ "longleftrightarrow",
2439
+ "Longleftarrow",
2440
+ "Longrightarrow",
2441
+ "Longleftrightarrow",
2442
+ "nearrow",
2443
+ "nwarrow",
2444
+ "searrow",
2445
+ "swarrow",
2446
+ "nleftarrow",
2447
+ "nrightarrow",
2448
+ "nLeftarrow",
2449
+ "nRightarrow",
2450
+ "nLeftrightarrow",
2451
+ "leftharpoonup",
2452
+ "leftharpoondown",
2453
+ "rightharpoonup",
2454
+ "rightharpoondown",
2455
+ "upharpoonleft",
2456
+ "upharpoonright",
2457
+ "downharpoonleft",
2458
+ "downharpoonright",
2459
+ "leftrightharpoons",
2460
+ "rightleftharpoons",
2461
+ "leftleftarrows",
2462
+ "rightrightarrows",
2463
+ "upuparrows",
2464
+ "downdownarrows",
2465
+ "leftrightarrows",
2466
+ "rightleftarrows",
2467
+ "looparrowleft",
2468
+ "looparrowright",
2469
+ "leftarrowtail",
2470
+ "rightarrowtail",
2471
+ "Lsh",
2472
+ "Rsh",
2473
+ "Lleftarrow",
2474
+ "Rrightarrow",
2475
+ "curvearrowleft",
2476
+ "curvearrowright",
2477
+ "circlearrowleft",
2478
+ "circlearrowright",
2479
+ "multimap",
2480
+ "leftrightsquigarrow",
2481
+ "twoheadleftarrow",
2482
+ "twoheadrightarrow",
2483
+ "rightsquigarrow"
2484
+ ], configList = baseToolbarConfig[2].options.box.group[4].items;
2485
+ configList.push({
2486
+ title: "\u7BAD\u5934",
2487
+ content: getUnicodeContents(list)
2488
+ });
2489
+ })();
2490
+ (function() {
2491
+ let list = [{
2492
+ title: "\u624B\u5199\u4F53",
2493
+ values: [
2494
+ "A",
2495
+ "B",
2496
+ "C",
2497
+ "D",
2498
+ "E",
2499
+ "F",
2500
+ "G",
2501
+ "H",
2502
+ "I",
2503
+ "J",
2504
+ "K",
2505
+ "L",
2506
+ "M",
2507
+ "N",
2508
+ "O",
2509
+ "P",
2510
+ "Q",
2511
+ "R",
2512
+ "S",
2513
+ "T",
2514
+ "U",
2515
+ "V",
2516
+ "W",
2517
+ "X",
2518
+ "Y",
2519
+ "Z"
2520
+ ]
2521
+ }, {
2522
+ title: "\u82B1\u4F53",
2523
+ values: [
2524
+ "A",
2525
+ "B",
2526
+ "C",
2527
+ "D",
2528
+ "E",
2529
+ "F",
2530
+ "G",
2531
+ "H",
2532
+ "I",
2533
+ "J",
2534
+ "K",
2535
+ "L",
2536
+ "M",
2537
+ "N",
2538
+ "O",
2539
+ "P",
2540
+ "Q",
2541
+ "R",
2542
+ "S",
2543
+ "T",
2544
+ "U",
2545
+ "V",
2546
+ "W",
2547
+ "X",
2548
+ "Y",
2549
+ "Z",
2550
+ "a",
2551
+ "b",
2552
+ "c",
2553
+ "d",
2554
+ "e",
2555
+ "f",
2556
+ "g",
2557
+ "h",
2558
+ "i",
2559
+ "j",
2560
+ "k",
2561
+ "l",
2562
+ "m",
2563
+ "n",
2564
+ "o",
2565
+ "p",
2566
+ "q",
2567
+ "r",
2568
+ "s",
2569
+ "t",
2570
+ "u",
2571
+ "v",
2572
+ "w",
2573
+ "x",
2574
+ "y",
2575
+ "z"
2576
+ ]
2577
+ }, {
2578
+ title: "\u53CC\u7EBF",
2579
+ values: [
2580
+ "A",
2581
+ "B",
2582
+ "C",
2583
+ "D",
2584
+ "E",
2585
+ "F",
2586
+ "G",
2587
+ "H",
2588
+ "I",
2589
+ "J",
2590
+ "K",
2591
+ "L",
2592
+ "M",
2593
+ "N",
2594
+ "O",
2595
+ "P",
2596
+ "Q",
2597
+ "R",
2598
+ "S",
2599
+ "T",
2600
+ "U",
2601
+ "V",
2602
+ "W",
2603
+ "X",
2604
+ "Y",
2605
+ "Z"
2606
+ ]
2607
+ }, {
2608
+ title: "\u7F57\u9A6C",
2609
+ values: [
2610
+ "A",
2611
+ "B",
2612
+ "C",
2613
+ "D",
2614
+ "E",
2615
+ "F",
2616
+ "G",
2617
+ "H",
2618
+ "I",
2619
+ "J",
2620
+ "K",
2621
+ "L",
2622
+ "M",
2623
+ "N",
2624
+ "O",
2625
+ "P",
2626
+ "Q",
2627
+ "R",
2628
+ "S",
2629
+ "T",
2630
+ "U",
2631
+ "V",
2632
+ "W",
2633
+ "X",
2634
+ "Y",
2635
+ "Z",
2636
+ "a",
2637
+ "b",
2638
+ "c",
2639
+ "d",
2640
+ "e",
2641
+ "f",
2642
+ "g",
2643
+ "h",
2644
+ "i",
2645
+ "j",
2646
+ "k",
2647
+ "l",
2648
+ "m",
2649
+ "n",
2650
+ "o",
2651
+ "p",
2652
+ "q",
2653
+ "r",
2654
+ "s",
2655
+ "t",
2656
+ "u",
2657
+ "v",
2658
+ "w",
2659
+ "x",
2660
+ "y",
2661
+ "z"
2662
+ ]
2663
+ }], configList = baseToolbarConfig[2].options.box.group[5].items;
2664
+ each(list[0].values, function(item, index) {
2665
+ list[0].values[index] = "mathcal{" + item + "}";
2666
+ });
2667
+ each(list[1].values, function(item, index) {
2668
+ list[1].values[index] = "mathfrak{" + item + "}";
2669
+ });
2670
+ each(list[2].values, function(item, index) {
2671
+ list[2].values[index] = "mathbb{" + item + "}";
2672
+ });
2673
+ each(list[3].values, function(item, index) {
2674
+ list[3].values[index] = "mathrm{" + item + "}";
2675
+ });
2676
+ configList.push({
2677
+ title: list[0].title,
2678
+ content: getUnicodeContents(list[0].values)
2679
+ });
2680
+ configList.push({
2681
+ title: list[1].title,
2682
+ content: getUnicodeContents(list[1].values)
2683
+ });
2684
+ configList.push({
2685
+ title: list[2].title,
2686
+ content: getUnicodeContents(list[2].values)
2687
+ });
2688
+ configList.push({
2689
+ title: list[3].title,
2690
+ content: getUnicodeContents(list[3].values)
2691
+ });
2692
+ })();
2693
+ function getUnicodeContents(keySet) {
2694
+ let result = [];
2695
+ each(keySet, function(key) {
2696
+ let displayKey = key;
2697
+ if (key.length > 1) {
2698
+ displayKey = "\\" + key;
2699
+ }
2700
+ const resolved = resolveUnicode(displayKey);
2701
+ const item = {
2702
+ key: displayKey,
2703
+ unicode: resolved ? resolved.char : displayKey
2704
+ };
2705
+ if (resolved?.fontFamily) {
2706
+ item.unicodeFont = resolved.fontFamily;
2707
+ }
2708
+ result.push(item);
2709
+ });
2710
+ return result;
2711
+ }
2712
+ function createToolbarConfig(locale = DEFAULT_FORMULAX_LOCALE) {
2713
+ return localizeToolbarConfig(
2714
+ baseToolbarConfig,
2715
+ normalizeFormulaXLocale(locale)
2716
+ );
2717
+ }
2718
+ var toolbar_config_default = createToolbarConfig;
2719
+
2720
+ // ../kity-runtime/src/legacy/ui.ts
2721
+ var $$8 = createLegacyUiUtils();
2722
+ var VIEW_STATE = legacyUiDef.VIEW_STATE;
2723
+ var DEFAULT_EDIT_AREA_HEIGHT = 100;
2724
+ var kity10 = getLegacyKity();
2725
+ var UIComponent = kity10.createClass("UIComponent", {
2726
+ constructor(kfEditor, options) {
2727
+ const currentDocument = kfEditor.getContainer().ownerDocument;
2728
+ this.options = options ?? {};
2729
+ this.container = kfEditor.getContainer();
2730
+ this.components = {};
2731
+ this.canvasRect = null;
2732
+ this.viewState = VIEW_STATE.NO_OVERFLOW;
2733
+ this.kfEditor = kfEditor;
2734
+ this.toolbarWrap = createToolbarWrap(currentDocument);
2735
+ this.toolbarContainer = createToolbarContainer(currentDocument);
2736
+ this.editArea = createEditArea(currentDocument);
2737
+ this.canvasContainer = createCanvasContainer(currentDocument);
2738
+ this.scrollbarContainer = createScrollbarContainer(currentDocument);
2739
+ this.toolbarWrap.appendChild(this.toolbarContainer);
2740
+ this.container.appendChild(this.toolbarWrap);
2741
+ this.editArea.appendChild(this.canvasContainer);
2742
+ this.container.appendChild(this.editArea);
2743
+ this.container.appendChild(this.scrollbarContainer);
2744
+ this.initComponents();
2745
+ this.initServices();
2746
+ this.initEvent();
2747
+ this.updateContainerSize(this.container, this.toolbarWrap, this.editArea);
2748
+ this.initScrollEvent();
2749
+ },
2750
+ initComponents() {
2751
+ const toolbarConfig = toolbar_config_default(normalizeFormulaXLocale(this.options.locale));
2752
+ this.components.toolbar = new toolbar_default(this, this.kfEditor, toolbarConfig);
2753
+ this.components.scrollbar = new scrollbar_default(this, this.kfEditor);
2754
+ },
2755
+ updateContainerSize(container, toolbar, editArea) {
2756
+ const containerBox = container.getBoundingClientRect();
2757
+ const toolbarBox = toolbar.getBoundingClientRect();
2758
+ const declaredHeight = container.style.height;
2759
+ const containerHeight = containerBox.height;
2760
+ let editAreaHeight = DEFAULT_EDIT_AREA_HEIGHT;
2761
+ if (declaredHeight && declaredHeight !== "auto") {
2762
+ editAreaHeight = Math.max(containerHeight - toolbarBox.height, DEFAULT_EDIT_AREA_HEIGHT);
2763
+ }
2764
+ editArea.style.width = "100%";
2765
+ editArea.style.height = `${editAreaHeight}px`;
2766
+ },
2767
+ initServices() {
2768
+ this.kfEditor.registerService("ui.get.canvas.container", this, {
2769
+ getCanvasContainer: this.getCanvasContainer
2770
+ });
2771
+ this.kfEditor.registerService("ui.update.canvas.view", this, {
2772
+ updateCanvasView: this.updateCanvasView
2773
+ });
2774
+ this.kfEditor.registerService("ui.canvas.container.event", this, {
2775
+ on: this.addEvent,
2776
+ off: this.removeEvent,
2777
+ trigger: this.trigger,
2778
+ fire: this.trigger
2779
+ });
2780
+ },
2781
+ initEvent() {
2782
+ },
2783
+ initScrollEvent() {
2784
+ this.kfEditor.requestService(
2785
+ "ui.set.scrollbar.update.handler",
2786
+ (proportion, _offset, values) => {
2787
+ const offset = Math.floor(proportion * (values.contentWidth - values.viewWidth));
2788
+ this.kfEditor.requestService("render.set.canvas.offset", offset);
2789
+ }
2790
+ );
2791
+ },
2792
+ getCanvasContainer() {
2793
+ return this.canvasContainer;
2794
+ },
2795
+ addEvent(type, handler) {
2796
+ legacyBaseUtils.addEvent(this.canvasContainer, type, handler);
2797
+ },
2798
+ removeEvent() {
2799
+ },
2800
+ trigger(type) {
2801
+ legacyBaseUtils.trigger(this.canvasContainer, type);
2802
+ },
2803
+ updateCanvasView() {
2804
+ const canvas = this.kfEditor.requestService("render.get.canvas");
2805
+ const contentContainer = canvas.getContentContainer();
2806
+ this.canvasRect = this.canvasContainer.getBoundingClientRect();
2807
+ const contentRect = contentContainer.getRenderBox("paper");
2808
+ if (contentRect.width > this.canvasRect.width) {
2809
+ if (this.viewState === VIEW_STATE.NO_OVERFLOW) {
2810
+ this.toggleViewState();
2811
+ this.kfEditor.requestService("ui.show.scrollbar");
2812
+ this.kfEditor.requestService("render.disable.relocation");
2813
+ }
2814
+ this.kfEditor.requestService("render.relocation");
2815
+ this.kfEditor.requestService("ui.update.scrollbar", contentRect.width);
2816
+ this.kfEditor.requestService("ui.relocation.scrollbar");
2817
+ return;
2818
+ }
2819
+ if (this.viewState === VIEW_STATE.OVERFLOW) {
2820
+ this.toggleViewState();
2821
+ this.kfEditor.requestService("ui.hide.scrollbar");
2822
+ this.kfEditor.requestService("render.enable.relocation");
2823
+ }
2824
+ this.kfEditor.requestService("render.relocation");
2825
+ },
2826
+ toggleViewState() {
2827
+ this.viewState = this.viewState === VIEW_STATE.NO_OVERFLOW ? VIEW_STATE.OVERFLOW : VIEW_STATE.NO_OVERFLOW;
2828
+ }
2829
+ });
2830
+ function createToolbarWrap(doc) {
2831
+ return $$8.ele(doc, "div", {
2832
+ className: "kf-editor-toolbar"
2833
+ });
2834
+ }
2835
+ function createToolbarContainer(doc) {
2836
+ return $$8.ele(doc, "div", {
2837
+ className: "kf-editor-inner-toolbar"
2838
+ });
2839
+ }
2840
+ function createEditArea(doc) {
2841
+ const container = doc.createElement("div");
2842
+ container.className = "kf-editor-edit-area";
2843
+ container.style.width = "100%";
2844
+ container.style.height = `${DEFAULT_EDIT_AREA_HEIGHT}px`;
2845
+ return container;
2846
+ }
2847
+ function createCanvasContainer(doc) {
2848
+ const container = doc.createElement("div");
2849
+ container.className = "kf-editor-canvas-container";
2850
+ return container;
2851
+ }
2852
+ function createScrollbarContainer(doc) {
2853
+ const container = doc.createElement("div");
2854
+ container.className = "kf-editor-edit-scrollbar";
2855
+ return container;
2856
+ }
2857
+ var ui_default = UIComponent;
2858
+
2859
+ // ../kity-runtime/src/legacy/kf-ext-placeholder-operator.ts
2860
+ var kity11 = getLegacyKity();
2861
+ var kf2 = getLegacyKf();
2862
+ function createCommonShape(operator) {
2863
+ const shape = new kity11.Rect(35, 50, 0, 0).stroke("black").fill("transparent");
2864
+ shape.setAttr("stroke-dasharray", "5, 5");
2865
+ operator.addOperatorShape(shape);
2866
+ return shape;
2867
+ }
2868
+ function createRootPlaceholder(operator, label) {
2869
+ const textShape = new kity11.Text(label).fill(legacySysconf.rootPlaceholder.color);
2870
+ const shapeGroup = new kity11.Group();
2871
+ const padding = 20;
2872
+ const radius = 7;
2873
+ const borderBoxShape = new kity11.Rect(0, 0, 0, 0, radius).stroke(legacySysconf.rootPlaceholder.color).fill("transparent");
2874
+ textShape.setFontSize(40);
2875
+ shapeGroup.addShape(borderBoxShape);
2876
+ shapeGroup.addShape(textShape);
2877
+ operator.addOperatorShape(shapeGroup);
2878
+ const textBox = textShape.getFixRenderBox();
2879
+ borderBoxShape.stroke(legacySysconf.rootPlaceholder.color).fill("transparent");
2880
+ borderBoxShape.setSize(textBox.width + padding * 2, textBox.height + padding * 2);
2881
+ borderBoxShape.setRadius(radius);
2882
+ borderBoxShape.setAttr("stroke-dasharray", "5, 5");
2883
+ textShape.setAttr({
2884
+ dx: -textBox.x,
2885
+ dy: -textBox.y
2886
+ });
2887
+ textShape.translate(padding, padding);
2888
+ return borderBoxShape;
2889
+ }
2890
+ function generateOpShape(operator, label) {
2891
+ if (label !== null) {
2892
+ return createRootPlaceholder(operator, label);
2893
+ }
2894
+ return createCommonShape(operator);
2895
+ }
2896
+ var PlaceholderOperator = kity11.createClass("PlaceholderOperator", {
2897
+ base: kf2.Operator,
2898
+ constructor() {
2899
+ this.opShape = null;
2900
+ if (this.__formulaxNeverCallBase__) {
2901
+ this.callBase("Placeholder");
2902
+ }
2903
+ kf2.Operator.call(this, "Placeholder");
2904
+ },
2905
+ applyOperand() {
2906
+ this.opShape = generateOpShape(this, this.parentExpression.getLabel());
2907
+ this.parentExpression.expand(20, 20);
2908
+ this.parentExpression.translateElement(10, 10);
2909
+ },
2910
+ select() {
2911
+ this.opShape?.fill(legacyKfExtDef.selectColor);
2912
+ },
2913
+ selectAll() {
2914
+ this.opShape?.fill(legacyKfExtDef.allSelectColor);
2915
+ },
2916
+ unselect() {
2917
+ this.opShape?.fill("transparent");
2918
+ }
2919
+ });
2920
+ var kf_ext_placeholder_operator_default = PlaceholderOperator;
2921
+
2922
+ // ../kity-runtime/src/legacy/kf-ext-placeholder-expression.ts
2923
+ var kity12 = getLegacyKity();
2924
+ var kf3 = getLegacyKf();
2925
+ var BaseCompoundExpression = kf3.CompoundExpression;
2926
+ var PlaceholderExpression = kity12.createClass("PlaceholderExpression", {
2927
+ base: kf3.CompoundExpression,
2928
+ constructor() {
2929
+ if (this.__formulaxNeverCallBase__) {
2930
+ this.callBase();
2931
+ }
2932
+ BaseCompoundExpression.call(this);
2933
+ this.setFlag("Placeholder");
2934
+ this.label = null;
2935
+ this.box.setAttr("data-type", null);
2936
+ this.setOperator(new kf_ext_placeholder_operator_default());
2937
+ },
2938
+ setLabel(label) {
2939
+ this.label = label;
2940
+ },
2941
+ getLabel() {
2942
+ return this.label;
2943
+ },
2944
+ setAttr(key, val) {
2945
+ if (key === "label") {
2946
+ this.setLabel(val);
2947
+ return;
2948
+ }
2949
+ if (typeof key === "object" && key.label) {
2950
+ this.setLabel(key.label);
2951
+ delete key.label;
2952
+ }
2953
+ BaseCompoundExpression.prototype.setAttr.call(this, key, val);
2954
+ },
2955
+ select() {
2956
+ this.getOperator().select();
2957
+ },
2958
+ selectAll() {
2959
+ this.getOperator().selectAll();
2960
+ },
2961
+ unselect() {
2962
+ this.getOperator().unselect();
2963
+ }
2964
+ });
2965
+ var kf_ext_placeholder_expression_default = PlaceholderExpression;
2966
+
2967
+ // ../kity-runtime/src/legacy/kf-ext-extension.ts
2968
+ var kf4 = getLegacyKf();
2969
+ function installLegacyKfExtension(parser) {
2970
+ kf4.PlaceholderExpression = kf_ext_placeholder_expression_default;
2971
+ kf4.Expression.prototype.select = function select() {
2972
+ this.box.fill(legacyKfExtDef.selectColor);
2973
+ };
2974
+ kf4.Expression.prototype.selectAll = function selectAll() {
2975
+ this.box.fill(legacyKfExtDef.allSelectColor);
2976
+ };
2977
+ kf4.Expression.prototype.unselect = function unselect() {
2978
+ this.box.fill("transparent");
2979
+ };
2980
+ parser.getKFParser().expand({
2981
+ parse: {
2982
+ placeholder: {
2983
+ name: "placeholder",
2984
+ handler(info) {
2985
+ delete info.handler;
2986
+ info.operand = [];
2987
+ return info;
2988
+ },
2989
+ sign: false
2990
+ }
2991
+ },
2992
+ reverse: {
2993
+ placeholder() {
2994
+ return "\\placeholder ";
2995
+ }
2996
+ }
2997
+ });
2998
+ }
2999
+ var kf_ext_extension_default = {
3000
+ ext: installLegacyKfExtension
3001
+ };
3002
+
3003
+ // ../kity-runtime/src/legacy/vgroup-def.ts
3004
+ var legacyVirtualGroupMap = {
3005
+ radical: true,
3006
+ fraction: true,
3007
+ summation: true,
3008
+ integration: true,
3009
+ placeholder: true,
3010
+ script: true,
3011
+ superscript: true,
3012
+ subscript: true,
3013
+ brackets: true,
3014
+ function: true
3015
+ };
3016
+ var vgroup_def_default = legacyVirtualGroupMap;
3017
+
3018
+ // ../kity-runtime/src/legacy/parser.ts
3019
+ var CURSOR_CHAR = legacySysconf.cursorCharacter;
3020
+ var COMBINATION_NAME = "combination";
3021
+ var PID_PREFIX = "_kf_editor_";
3022
+ var pidSeed = 0;
3023
+ var kity13 = getLegacyKity();
3024
+ var kf5 = getLegacyKf();
3025
+ var BaseComponent = createLegacyBaseComponent(kity13);
3026
+ function generateId() {
3027
+ pidSeed += 1;
3028
+ return `${PID_PREFIX}${pidSeed}`;
3029
+ }
3030
+ function isVirtualGroup(tree) {
3031
+ return !!vgroup_def_default[tree.name];
3032
+ }
3033
+ function isPlaceholder(tree) {
3034
+ return tree.name === "placeholder";
3035
+ }
3036
+ function onlyPlaceholder(operands) {
3037
+ let result = 1;
3038
+ if (operands.length > 3) {
3039
+ return false;
3040
+ }
3041
+ for (const operand of operands) {
3042
+ if (operand === CURSOR_CHAR) {
3043
+ continue;
3044
+ }
3045
+ if (operand && typeof operand !== "string" && operand.name === "placeholder") {
3046
+ result -= 1;
3047
+ }
3048
+ }
3049
+ return !result;
3050
+ }
3051
+ function createGroup(parser) {
3052
+ return {
3053
+ name: COMBINATION_NAME,
3054
+ attr: {
3055
+ "data-type": legacyGroupType.GROUP,
3056
+ id: parser.getGroupId()
3057
+ },
3058
+ operand: []
3059
+ };
3060
+ }
3061
+ function getRootPlaceholderText() {
3062
+ return legacySysconf.rootPlaceholder.content;
3063
+ }
3064
+ function processRootGroup(parser, tree) {
3065
+ if (!parser.isResetId) {
3066
+ tree.attr["data-type"] = legacyGroupType.VIRTUAL;
3067
+ } else {
3068
+ tree.attr["data-root"] = "true";
3069
+ }
3070
+ }
3071
+ function processVirtualGroup(parser, index, tree, subtree) {
3072
+ if (tree.name === "brackets" && index < 2 || tree.name === "function" && index === 0) {
3073
+ return;
3074
+ }
3075
+ tree.attr["data-type"] = legacyGroupType.VIRTUAL;
3076
+ if (!subtree) {
3077
+ tree.operand[index] = subtree;
3078
+ return;
3079
+ }
3080
+ if (typeof subtree === "string") {
3081
+ tree.operand[index] = createGroup(parser);
3082
+ tree.operand[index].operand[0] = subtree;
3083
+ return;
3084
+ }
3085
+ if (isPlaceholder(subtree)) {
3086
+ tree.operand[index] = createGroup(parser);
3087
+ tree.operand[index].operand[0] = supplementTree(parser, subtree, tree.operand[index]);
3088
+ return;
3089
+ }
3090
+ tree.operand[index] = supplementTree(parser, subtree, tree);
3091
+ }
3092
+ function processGroup(parser, index, tree, subtree) {
3093
+ tree.attr["data-type"] = legacyGroupType.GROUP;
3094
+ if (!subtree || typeof subtree === "string") {
3095
+ tree.operand[index] = subtree;
3096
+ return;
3097
+ }
3098
+ if (subtree.name === "text") {
3099
+ tree.operand[index] = subtree;
3100
+ return;
3101
+ }
3102
+ tree.operand[index] = supplementTree(parser, subtree, tree);
3103
+ }
3104
+ function supplementTree(parser, tree, parentTree) {
3105
+ const isRoot = !parentTree;
3106
+ tree.attr = tree.attr || {};
3107
+ tree.attr.id = parser.getGroupId();
3108
+ if (isRoot) {
3109
+ processRootGroup(parser, tree);
3110
+ } else if (parentTree?.attr?.["data-root"] && tree.name === "placeholder" && onlyPlaceholder(parentTree.operand)) {
3111
+ tree.attr.label = getRootPlaceholderText();
3112
+ }
3113
+ for (let i = 0; i < tree.operand.length; i += 1) {
3114
+ const currentOperand = tree.operand[i];
3115
+ if (isVirtualGroup(tree)) {
3116
+ processVirtualGroup(parser, i, tree, currentOperand);
3117
+ } else {
3118
+ processGroup(parser, i, tree, currentOperand);
3119
+ }
3120
+ }
3121
+ return tree;
3122
+ }
3123
+ var Parser = kity13.createClass("Parser", {
3124
+ base: BaseComponent,
3125
+ constructor(kfEditor) {
3126
+ this.kfEditor = kfEditor;
3127
+ if (this.__formulaxNeverCallBase__) {
3128
+ this.callBase();
3129
+ }
3130
+ BaseComponent.call(this);
3131
+ this.kfParser = kf5.Parser.use("latex");
3132
+ this.initKFormulExtension();
3133
+ this.pid = generateId();
3134
+ this.groupRecord = 0;
3135
+ this.tree = null;
3136
+ this.isResetId = true;
3137
+ this.initServices();
3138
+ },
3139
+ parse(str, isResetId) {
3140
+ this.isResetId = !!isResetId;
3141
+ if (this.isResetId) {
3142
+ this.resetGroupId();
3143
+ }
3144
+ const parsedResult = this.kfParser.parse(str);
3145
+ supplementTree(this, parsedResult.tree);
3146
+ return parsedResult;
3147
+ },
3148
+ serialization(tree) {
3149
+ return this.kfParser.serialization(tree);
3150
+ },
3151
+ initServices() {
3152
+ this.kfEditor.registerService("parser.parse", this, {
3153
+ parse: this.parse
3154
+ });
3155
+ this.kfEditor.registerService("parser.latex.serialization", this, {
3156
+ serialization: this.serialization
3157
+ });
3158
+ },
3159
+ getKFParser() {
3160
+ return this.kfParser;
3161
+ },
3162
+ initKFormulExtension() {
3163
+ kf_ext_extension_default.ext(this);
3164
+ },
3165
+ resetGroupId() {
3166
+ this.groupRecord = 0;
3167
+ },
3168
+ getGroupId() {
3169
+ this.groupRecord += 1;
3170
+ return `${this.pid}_${this.groupRecord}`;
3171
+ }
3172
+ });
3173
+ var parser_default = Parser;
3174
+
3175
+ // ../kity-runtime/src/legacy/render.ts
3176
+ var DEFAULT_OPTIONS2 = {
3177
+ autoresize: false,
3178
+ fontsize: 50,
3179
+ padding: [20, 50]
3180
+ };
3181
+ var kity14 = getLegacyKity();
3182
+ var kf6 = getLegacyKf();
3183
+ var BaseComponent2 = createLegacyBaseComponent(kity14);
3184
+ var RenderComponent = kity14.createClass("RenderComponent", {
3185
+ base: BaseComponent2,
3186
+ constructor(kfEditor, options) {
3187
+ if (this.__formulaxNeverCallBase__) {
3188
+ this.callBase();
3189
+ }
3190
+ BaseComponent2.call(this);
3191
+ this.options = kity14.Utils.extend({}, DEFAULT_OPTIONS2, options);
3192
+ this.kfEditor = kfEditor;
3193
+ this.assembly = null;
3194
+ this.formula = null;
3195
+ this.relDisabled = false;
3196
+ this.canvasZoom = 1;
3197
+ this.record = {
3198
+ select: {},
3199
+ cursor: {},
3200
+ canvas: {}
3201
+ };
3202
+ this.initCanvas();
3203
+ this.initServices();
3204
+ this.initCommands();
3205
+ },
3206
+ initCanvas() {
3207
+ const canvasContainer = this.kfEditor.requestService("ui.get.canvas.container");
3208
+ const Formula = this.kfEditor.getFormulaClass();
3209
+ this.assembly = new kf6.Assembly(new Formula(canvasContainer, this.options));
3210
+ this.formula = this.assembly.formula;
3211
+ this.setCanvasToCenter();
3212
+ },
3213
+ setCanvasOffset(offsetX, offsetY) {
3214
+ const viewBox = this.formula.getViewBox();
3215
+ const nextOffsetY = offsetY !== void 0 ? offsetY : -viewBox.height / 2;
3216
+ this.formula.setViewBox(offsetX, nextOffsetY, viewBox.width, viewBox.height);
3217
+ },
3218
+ setCanvasToCenter() {
3219
+ const viewBox = this.formula.getViewBox();
3220
+ this.formula.setViewBox(-viewBox.width / 2, -viewBox.height / 2, viewBox.width, viewBox.height);
3221
+ },
3222
+ initServices() {
3223
+ this.kfEditor.registerService("render.get.canvas", this, {
3224
+ getCanvas: this.getCanvas
3225
+ });
3226
+ this.kfEditor.registerService("render.get.content.size", this, {
3227
+ getContentSize: this.getContentSize
3228
+ });
3229
+ this.kfEditor.registerService("render.clear.canvas.transform", this, {
3230
+ clearCanvasOffset: this.clearCanvasTransform
3231
+ });
3232
+ this.kfEditor.registerService("render.set.canvas.offset", this, {
3233
+ setCanvasOffset: this.setCanvasOffset
3234
+ });
3235
+ this.kfEditor.registerService("render.set.canvas.to.center", this, {
3236
+ setCanvasToCenter: this.setCanvasToCenter
3237
+ });
3238
+ this.kfEditor.registerService("render.revert.canvas.transform", this, {
3239
+ revertCanvasTransform: this.revertCanvasTransform
3240
+ });
3241
+ this.kfEditor.registerService("render.relocation", this, {
3242
+ relocation: this.relocation
3243
+ });
3244
+ this.kfEditor.registerService("render.disable.relocation", this, {
3245
+ disableRelocation: this.disableRelocation
3246
+ });
3247
+ this.kfEditor.registerService("render.enable.relocation", this, {
3248
+ enableRelocation: this.enableRelocation
3249
+ });
3250
+ this.kfEditor.registerService("render.select.group.content", this, {
3251
+ selectGroupContent: this.selectGroupContent
3252
+ });
3253
+ this.kfEditor.registerService("render.select.group", this, {
3254
+ selectGroup: this.selectGroup
3255
+ });
3256
+ this.kfEditor.registerService("render.select.group.all", this, {
3257
+ selectAllGroup: this.selectAllGroup
3258
+ });
3259
+ this.kfEditor.registerService("render.tint.current.cursor", this, {
3260
+ tintCurrentGroup: this.tintCurrentGroup
3261
+ });
3262
+ this.kfEditor.registerService("render.select.current.cursor", this, {
3263
+ selectCurrentCursor: this.selectCurrentCursor
3264
+ });
3265
+ this.kfEditor.registerService("render.reselect", this, {
3266
+ reselect: this.reselect
3267
+ });
3268
+ this.kfEditor.registerService("render.clear.select", this, {
3269
+ clearSelect: this.clearSelect
3270
+ });
3271
+ this.kfEditor.registerService("render.set.canvas.zoom", this, {
3272
+ setCanvasZoom: this.setCanvasZoom
3273
+ });
3274
+ this.kfEditor.registerService("render.get.canvas.zoom", this, {
3275
+ getCanvasZoom: this.getCanvasZoom
3276
+ });
3277
+ this.kfEditor.registerService("render.get.paper.offset", this, {
3278
+ getPaperOffset: this.getPaperOffset
3279
+ });
3280
+ this.kfEditor.registerService("render.draw", this, {
3281
+ render: this.render
3282
+ });
3283
+ this.kfEditor.registerService("render.insert.string", this, {
3284
+ insertString: this.insertString
3285
+ });
3286
+ this.kfEditor.registerService("render.insert.group", this, {
3287
+ insertGroup: this.insertGroup
3288
+ });
3289
+ this.kfEditor.registerService("render.get.paper", this, {
3290
+ getPaper: this.getPaper
3291
+ });
3292
+ },
3293
+ initCommands() {
3294
+ this.kfEditor.registerCommand("render", this, function(str) {
3295
+ this.render(str);
3296
+ this.kfEditor.requestService("ui.update.canvas.view");
3297
+ requestAnimationFrame(() => {
3298
+ requestAnimationFrame(() => {
3299
+ this.kfEditor.requestService("ui.update.canvas.view");
3300
+ });
3301
+ });
3302
+ });
3303
+ this.kfEditor.registerCommand("getPaper", this, this.getPaper);
3304
+ },
3305
+ relocation() {
3306
+ if (!this.relDisabled) {
3307
+ this.relocationToCenter();
3308
+ return;
3309
+ }
3310
+ this.relocationToLeft();
3311
+ },
3312
+ relocationToCenter() {
3313
+ const formulaSpace = this.formula.container.getRenderBox();
3314
+ this.formula.container.setTranslate(-formulaSpace.width / 2, -formulaSpace.height / 2);
3315
+ this.setCanvasToCenter();
3316
+ },
3317
+ relocationToLeft() {
3318
+ const formulaSpace = this.formula.container.getRenderBox();
3319
+ this.formula.container.setTranslate(0, -formulaSpace.height / 2);
3320
+ this.setCanvasOffset(0);
3321
+ },
3322
+ selectGroup(groupId) {
3323
+ const groupObject = this.kfEditor.requestService("syntax.get.group.object", groupId);
3324
+ this.clearSelect();
3325
+ if (groupObject.node.getAttribute("data-root")) {
3326
+ return;
3327
+ }
3328
+ this.record.select.lastSelect = groupObject;
3329
+ groupObject.select();
3330
+ },
3331
+ selectGroupContent(group) {
3332
+ let nextGroup = group;
3333
+ if (group.groupObj.getAttribute("data-placeholder") !== null) {
3334
+ nextGroup = {
3335
+ id: group.content[0].id,
3336
+ groupObj: group.groupObj,
3337
+ content: group.content
3338
+ };
3339
+ }
3340
+ const groupObject = this.kfEditor.requestService("syntax.get.group.object", nextGroup.id);
3341
+ this.clearSelect();
3342
+ this.record.select.lastSelect = groupObject;
3343
+ if (groupObject.node.getAttribute("data-root")) {
3344
+ return;
3345
+ }
3346
+ groupObject.select();
3347
+ },
3348
+ selectAllGroup(group) {
3349
+ let nextGroup = group;
3350
+ if (group.groupObj.getAttribute("data-placeholder") !== null) {
3351
+ nextGroup = {
3352
+ id: group.content[0].id,
3353
+ groupObj: group.groupObj,
3354
+ content: group.content
3355
+ };
3356
+ }
3357
+ const groupObject = this.kfEditor.requestService("syntax.get.group.object", nextGroup.id);
3358
+ this.clearSelect();
3359
+ this.record.select.lastSelect = groupObject;
3360
+ groupObject.selectAll();
3361
+ },
3362
+ selectCurrentCursor() {
3363
+ const cursorInfo = this.kfEditor.requestService("syntax.get.record.cursor");
3364
+ const group = this.kfEditor.requestService("syntax.get.group.object", cursorInfo.groupId);
3365
+ let offset = -1;
3366
+ let width = 0;
3367
+ const startIndex = Math.min(cursorInfo.startOffset, cursorInfo.endOffset);
3368
+ const endIndex = Math.max(cursorInfo.startOffset, cursorInfo.endOffset);
3369
+ this.clearSelect();
3370
+ this.record.select.lastSelect = group;
3371
+ for (let i = startIndex; i < endIndex; i += 1) {
3372
+ const box = group.getOperand(i).getRenderBox(group);
3373
+ if (offset === -1) {
3374
+ offset = box.x;
3375
+ }
3376
+ width += box.width;
3377
+ }
3378
+ group.setBoxWidth(width);
3379
+ group.selectAll();
3380
+ group.getBox().setTranslate(offset, 0);
3381
+ },
3382
+ tintCurrentGroup() {
3383
+ const groupId = this.kfEditor.requestService("syntax.get.record.cursor").groupId;
3384
+ let groupObject = this.kfEditor.requestService("syntax.get.group.object", groupId);
3385
+ const isPlaceholder2 = this.kfEditor.requestService("syntax.is.placeholder.node", groupId);
3386
+ this.clearSelect();
3387
+ if (groupObject.node.getAttribute("data-root")) {
3388
+ return;
3389
+ }
3390
+ if (isPlaceholder2) {
3391
+ groupObject = this.kfEditor.requestService(
3392
+ "syntax.get.group.object",
3393
+ groupObject.operands[0].node.id
3394
+ );
3395
+ }
3396
+ this.record.select.lastSelect = groupObject;
3397
+ groupObject.select();
3398
+ },
3399
+ reselect() {
3400
+ const cursorInfo = this.kfEditor.requestService("syntax.get.record.cursor");
3401
+ const groupObject = this.kfEditor.requestService("syntax.get.group.object", cursorInfo.groupId);
3402
+ this.clearSelect();
3403
+ this.record.select.lastSelect = groupObject;
3404
+ if (groupObject.node.getAttribute("data-root")) {
3405
+ return;
3406
+ }
3407
+ groupObject.select();
3408
+ },
3409
+ clearSelect() {
3410
+ const currentSelect = this.record.select.lastSelect;
3411
+ if (!currentSelect || !currentSelect.node.ownerSVGElement) {
3412
+ return;
3413
+ }
3414
+ currentSelect.unselect();
3415
+ const box = currentSelect.getRenderBox(currentSelect);
3416
+ currentSelect.setBoxWidth(box.width);
3417
+ currentSelect.getBox().setTranslate(0, 0);
3418
+ },
3419
+ getPaper() {
3420
+ return this.formula;
3421
+ },
3422
+ getPaperOffset() {
3423
+ return this.formula.container.getTranslate();
3424
+ },
3425
+ render(latexStr) {
3426
+ const parsedTree = this.kfEditor.requestService("parser.parse", latexStr, true);
3427
+ const objTree = this.assembly.regenerateBy(parsedTree);
3428
+ this.kfEditor.requestService("syntax.update.objtree", objTree);
3429
+ },
3430
+ enableRelocation() {
3431
+ this.relDisabled = false;
3432
+ },
3433
+ disableRelocation() {
3434
+ this.relDisabled = true;
3435
+ },
3436
+ setCanvasZoom(zoom) {
3437
+ const viewPort = this.formula.getViewPort();
3438
+ this.canvasZoom = zoom;
3439
+ viewPort.zoom = zoom;
3440
+ this.formula.setViewPort(viewPort);
3441
+ },
3442
+ getCanvas() {
3443
+ return this.formula;
3444
+ },
3445
+ getContentSize() {
3446
+ return this.formula.container.getRenderBox();
3447
+ },
3448
+ clearCanvasTransform() {
3449
+ const canvasInfo = this.record.canvas;
3450
+ canvasInfo.viewBox = this.formula.getViewBox();
3451
+ canvasInfo.contentOffset = this.formula.container.getTranslate();
3452
+ this.setCanvasToCenter();
3453
+ this.formula.node.removeAttribute("viewBox");
3454
+ this.formula.container.setTranslate(0, 0);
3455
+ },
3456
+ revertCanvasTransform() {
3457
+ const canvasInfo = this.record.canvas;
3458
+ const viewBox = canvasInfo.viewBox;
3459
+ if (!viewBox) {
3460
+ return false;
3461
+ }
3462
+ this.formula.setViewBox(viewBox.x, viewBox.y, viewBox.width, viewBox.height);
3463
+ this.formula.container.setTranslate(canvasInfo.contentOffset);
3464
+ canvasInfo.viewBox = null;
3465
+ canvasInfo.contentOffset = null;
3466
+ return true;
3467
+ },
3468
+ getCanvasZoom() {
3469
+ return this.canvasZoom;
3470
+ },
3471
+ insertString(value) {
3472
+ return value;
3473
+ },
3474
+ insertGroup(value) {
3475
+ return value;
3476
+ }
3477
+ });
3478
+ var render_default = RenderComponent;
3479
+
3480
+ // ../kity-runtime/src/legacy/position.ts
3481
+ var kity15 = getLegacyKity();
3482
+ function getGroup(node, isAllowVirtual, isAllowWrap) {
3483
+ const target = node;
3484
+ if (!target || !target.ownerSVGElement) {
3485
+ return null;
3486
+ }
3487
+ const parentNode = target.parentNode;
3488
+ if (!parentNode) {
3489
+ return null;
3490
+ }
3491
+ const tagName = parentNode.tagName.toLowerCase();
3492
+ if (tagName === "body" || tagName === "svg") {
3493
+ return null;
3494
+ }
3495
+ if (parentNode.getAttribute("data-type") === "kf-editor-group") {
3496
+ return parentNode;
3497
+ }
3498
+ if (isAllowVirtual && parentNode.getAttribute("data-type") === "kf-editor-virtual-group") {
3499
+ return parentNode;
3500
+ }
3501
+ if (isAllowWrap && parentNode.getAttribute("data-flag") !== null) {
3502
+ return parentNode;
3503
+ }
3504
+ return getGroup(parentNode, isAllowVirtual, isAllowWrap);
3505
+ }
3506
+ var PositionComponent = kity15.createClass("PositionComponenet", {
3507
+ constructor(kfEditor) {
3508
+ this.kfEditor = kfEditor;
3509
+ this.initServices();
3510
+ },
3511
+ initServices() {
3512
+ this.kfEditor.registerService("position.get.group", this, {
3513
+ getGroupByTarget: this.getGroupByTarget
3514
+ });
3515
+ this.kfEditor.registerService("position.get.index", this, {
3516
+ getIndexByTargetInGroup: this.getIndexByTargetInGroup
3517
+ });
3518
+ this.kfEditor.registerService("position.get.location.info", this, {
3519
+ getLocationInfo: this.getLocationInfo
3520
+ });
3521
+ this.kfEditor.registerService("position.get.parent.group", this, {
3522
+ getParentGroupByTarget: this.getParentGroupByTarget
3523
+ });
3524
+ this.kfEditor.registerService("position.get.wrap", this, {
3525
+ getWrap: this.getWrap
3526
+ });
3527
+ this.kfEditor.registerService("position.get.area", this, {
3528
+ getAreaByCursorInGroup: this.getAreaByCursorInGroup
3529
+ });
3530
+ this.kfEditor.registerService("position.get.group.info", this, {
3531
+ getGroupInfoByNode: this.getGroupInfoByNode
3532
+ });
3533
+ this.kfEditor.registerService("position.get.parent.info", this, {
3534
+ getParentInfoByNode: this.getParentInfoByNode
3535
+ });
3536
+ },
3537
+ getGroupByTarget(target) {
3538
+ const groupDom = getGroup(target, false, false);
3539
+ if (!groupDom) {
3540
+ return null;
3541
+ }
3542
+ return this.kfEditor.requestService("syntax.get.group.content", groupDom.id);
3543
+ },
3544
+ getIndexByTargetInGroup(groupNode, targetNode) {
3545
+ const groupInfo = this.kfEditor.requestService("syntax.get.group.content", groupNode.id);
3546
+ let index = -1;
3547
+ kity15.Utils.each(groupInfo.content, (child, i) => {
3548
+ index = i;
3549
+ if (legacyBaseUtils.contains(child, targetNode)) {
3550
+ return false;
3551
+ }
3552
+ return void 0;
3553
+ });
3554
+ return index;
3555
+ },
3556
+ getAreaByCursorInGroup(groupNode, offset) {
3557
+ const groupRect = legacyBaseUtils.getRect(groupNode);
3558
+ return groupRect.left + groupRect.width / 2 < offset;
3559
+ },
3560
+ getLocationInfo(distance, groupInfo) {
3561
+ let index = -1;
3562
+ for (let i = groupInfo.content.length - 1; i >= 0; i -= 1) {
3563
+ index = i;
3564
+ const child = groupInfo.content[i];
3565
+ const boundingRect = legacyBaseUtils.getRect(child);
3566
+ if (boundingRect.left < distance) {
3567
+ if (boundingRect.left + boundingRect.width / 2 < distance) {
3568
+ index += 1;
3569
+ }
3570
+ break;
3571
+ }
3572
+ }
3573
+ return index;
3574
+ },
3575
+ getParentGroupByTarget(target) {
3576
+ const groupDom = getGroup(target, true, false);
3577
+ if (!groupDom) {
3578
+ return null;
3579
+ }
3580
+ return this.kfEditor.requestService("syntax.get.group.content", groupDom.id);
3581
+ },
3582
+ getWrap(node) {
3583
+ return getGroup(node, true, true);
3584
+ },
3585
+ getGroupInfoByNode(target) {
3586
+ const containerNode = getGroup(target, false, false);
3587
+ if (!containerNode) {
3588
+ return null;
3589
+ }
3590
+ const containerInfo = this.kfEditor.requestService("syntax.get.group.content", containerNode.id);
3591
+ let index = 0;
3592
+ for (let i = 0, len = containerInfo.content.length; i < len; i += 1) {
3593
+ index = i;
3594
+ if (legacyBaseUtils.contains(containerInfo.content[i], target)) {
3595
+ break;
3596
+ }
3597
+ }
3598
+ return {
3599
+ group: containerInfo,
3600
+ index
3601
+ };
3602
+ },
3603
+ getParentInfoByNode(target) {
3604
+ const groupNode = getGroup(target, true, false);
3605
+ if (!groupNode) {
3606
+ throw new Error("PositionComponent: failed to resolve parent group");
3607
+ }
3608
+ const group = this.kfEditor.requestService("syntax.get.group.content", groupNode.id);
3609
+ return {
3610
+ group,
3611
+ index: group.content.indexOf(target)
3612
+ };
3613
+ }
3614
+ });
3615
+ var position_default = PositionComponent;
3616
+
3617
+ // ../kity-runtime/src/legacy/syntax-delete.ts
3618
+ var kity16 = getLegacyKity();
3619
+ var DeleteComponent = kity16.createClass("DeleteComponent", {
3620
+ constructor(parentComponent, kfEditor) {
3621
+ this.parentComponent = parentComponent;
3622
+ this.kfEditor = kfEditor;
3623
+ },
3624
+ deleteGroup() {
3625
+ let cursorInfo = this.parentComponent.getCursorRecord();
3626
+ const cursorGroupId = cursorInfo.groupId;
3627
+ const objTree = this.parentComponent.getObjectTree();
3628
+ const currentTree = objTree.mapping[cursorGroupId].strGroup;
3629
+ if (cursorInfo.startOffset === cursorInfo.endOffset) {
3630
+ if (cursorInfo.startOffset === 0) {
3631
+ if (this.parentComponent.isRootTree(currentTree)) {
3632
+ return false;
3633
+ }
3634
+ cursorInfo = this.selectParentContainer(cursorGroupId);
3635
+ this.parentComponent.updateCursor(cursorInfo);
3636
+ return false;
3637
+ }
3638
+ if (currentTree.operand.length > 1) {
3639
+ cursorInfo = this.deletePrevGroup(currentTree, cursorInfo);
3640
+ } else {
3641
+ cursorInfo.startOffset = 0;
3642
+ cursorInfo.endOffset = 1;
3643
+ const operand0 = currentTree.operand[0];
3644
+ if (operand0.attr && this.parentComponent.isGroupNode(operand0.attr.id)) {
3645
+ this.parentComponent.updateCursor(cursorInfo);
3646
+ return false;
3647
+ }
3648
+ currentTree.operand[0] = {
3649
+ name: "placeholder",
3650
+ operand: []
3651
+ };
3652
+ this.parentComponent.updateCursor(cursorInfo);
3653
+ return true;
3654
+ }
3655
+ } else if (this.parentComponent.isSelectPlaceholder()) {
3656
+ if (this.parentComponent.isRootTree(currentTree)) {
3657
+ return false;
3658
+ }
3659
+ cursorInfo = this.selectParentContainer(cursorGroupId);
3660
+ this.parentComponent.updateCursor(cursorInfo);
3661
+ return false;
3662
+ } else {
3663
+ return this.deleteSelection(currentTree, cursorInfo);
3664
+ }
3665
+ this.parentComponent.updateCursor(cursorInfo);
3666
+ return cursorInfo.startOffset === cursorInfo.endOffset;
3667
+ },
3668
+ deletePrevGroup(tree, cursorInfo) {
3669
+ const index = cursorInfo.startOffset - 1;
3670
+ const group = tree.operand[index];
3671
+ if (this.parentComponent.isLeafTree(group)) {
3672
+ tree.operand.splice(index, 1);
3673
+ cursorInfo.startOffset -= 1;
3674
+ cursorInfo.endOffset -= 1;
3675
+ } else {
3676
+ cursorInfo.startOffset -= 1;
3677
+ }
3678
+ return cursorInfo;
3679
+ },
3680
+ deleteSelection(tree, cursorInfo) {
3681
+ if (cursorInfo.startOffset === 0 && cursorInfo.endOffset === tree.operand.length) {
3682
+ tree.operand.length = 1;
3683
+ tree.operand[0] = {
3684
+ name: "placeholder",
3685
+ operand: []
3686
+ };
3687
+ cursorInfo.endOffset = 1;
3688
+ } else {
3689
+ tree.operand.splice(cursorInfo.startOffset, cursorInfo.endOffset - cursorInfo.startOffset);
3690
+ cursorInfo.endOffset = cursorInfo.startOffset;
3691
+ }
3692
+ this.parentComponent.updateCursor(cursorInfo);
3693
+ return true;
3694
+ },
3695
+ selectParentContainer(groupId) {
3696
+ const currentGroup = this.parentComponent.getGroupObject(groupId);
3697
+ if (!currentGroup) {
3698
+ throw new Error(`DeleteComponent: missing group object for ${groupId}`);
3699
+ }
3700
+ const currentGroupNode = currentGroup.node;
3701
+ const parentContainerInfo = this.kfEditor.requestService("position.get.group", currentGroupNode);
3702
+ const index = this.kfEditor.requestService("position.get.index", parentContainerInfo.groupObj, currentGroupNode);
3703
+ return {
3704
+ groupId: parentContainerInfo.id,
3705
+ startOffset: index,
3706
+ endOffset: index + 1
3707
+ };
3708
+ }
3709
+ });
3710
+ var syntax_delete_default = DeleteComponent;
3711
+
3712
+ // ../kity-runtime/src/legacy/syntax-move.ts
3713
+ var kity17 = getLegacyKity();
3714
+ function isRootNode(node) {
3715
+ return !!node.getAttribute("data-root");
3716
+ }
3717
+ function isContainerNode(node) {
3718
+ return node.getAttribute("data-type") === "kf-editor-group";
3719
+ }
3720
+ function isGroupNode(node) {
3721
+ const dataType = node.getAttribute("data-type");
3722
+ return dataType === "kf-editor-group" || dataType === "kf-editor-virtual-group";
3723
+ }
3724
+ function isPlaceholderNode(node) {
3725
+ return node.getAttribute("data-flag") === "Placeholder";
3726
+ }
3727
+ function isEmptyNode(node) {
3728
+ return node.getAttribute("data-flag") === "Empty";
3729
+ }
3730
+ function locateLeftIndex(moveComponent, groupNode) {
3731
+ const syntaxComponent = moveComponent.parentComponent;
3732
+ if (isPlaceholderNode(groupNode) || isEmptyNode(groupNode)) {
3733
+ return locateOuterLeftIndex(moveComponent, groupNode);
3734
+ }
3735
+ if (!isGroupNode(groupNode)) {
3736
+ return null;
3737
+ }
3738
+ let groupInfo = syntaxComponent.getGroupContent(groupNode.id);
3739
+ let groupElement = groupInfo.content[groupInfo.content.length - 1];
3740
+ if (isEmptyNode(groupElement)) {
3741
+ return locateOuterLeftIndex(moveComponent, groupElement);
3742
+ }
3743
+ if (isContainerNode(groupNode)) {
3744
+ if (isPlaceholderNode(groupElement)) {
3745
+ return {
3746
+ groupId: groupNode.id,
3747
+ startOffset: groupInfo.content.length - 1,
3748
+ endOffset: groupInfo.content.length
3749
+ };
3750
+ }
3751
+ if (isContainerNode(groupElement) && groupInfo.content.length === 1) {
3752
+ return locateLeftIndex(moveComponent, groupElement);
3753
+ }
3754
+ return {
3755
+ groupId: groupNode.id,
3756
+ startOffset: groupInfo.content.length,
3757
+ endOffset: groupInfo.content.length
3758
+ };
3759
+ }
3760
+ while (!isContainerNode(groupElement) && !isEmptyNode(groupElement) && !isPlaceholderNode(groupElement)) {
3761
+ groupInfo = syntaxComponent.getGroupContent(groupElement.id);
3762
+ groupElement = groupInfo.content[groupInfo.content.length - 1];
3763
+ }
3764
+ if (isEmptyNode(groupElement)) {
3765
+ return locateOuterLeftIndex(moveComponent, groupElement);
3766
+ }
3767
+ if (isPlaceholderNode(groupElement)) {
3768
+ return {
3769
+ groupId: groupElement.id,
3770
+ startOffset: groupInfo.content.length,
3771
+ endOffset: groupInfo.content.length
3772
+ };
3773
+ }
3774
+ return locateLeftIndex(moveComponent, groupElement);
3775
+ }
3776
+ function locateOuterLeftIndex(moveComponent, groupNode) {
3777
+ const kfEditor = moveComponent.kfEditor;
3778
+ let outerGroupInfo = kfEditor.requestService("position.get.parent.info", groupNode);
3779
+ if (isRootNode(groupNode)) {
3780
+ return null;
3781
+ }
3782
+ while (outerGroupInfo.index === 0) {
3783
+ if (isRootNode(outerGroupInfo.group.groupObj)) {
3784
+ return {
3785
+ groupId: outerGroupInfo.group.id,
3786
+ startOffset: 0,
3787
+ endOffset: 0
3788
+ };
3789
+ }
3790
+ if (isContainerNode(outerGroupInfo.group.groupObj) && outerGroupInfo.group.content.length > 1) {
3791
+ return {
3792
+ groupId: outerGroupInfo.group.id,
3793
+ startOffset: 0,
3794
+ endOffset: 0
3795
+ };
3796
+ }
3797
+ outerGroupInfo = kfEditor.requestService("position.get.parent.info", outerGroupInfo.group.groupObj);
3798
+ }
3799
+ groupNode = outerGroupInfo.group.content[outerGroupInfo.index - 1];
3800
+ if (isGroupNode(groupNode)) {
3801
+ return locateLeftIndex(moveComponent, groupNode);
3802
+ }
3803
+ if (isEmptyNode(groupNode)) {
3804
+ return locateOuterLeftIndex(moveComponent, groupNode);
3805
+ }
3806
+ return {
3807
+ groupId: outerGroupInfo.group.id,
3808
+ startOffset: outerGroupInfo.index,
3809
+ endOffset: outerGroupInfo.index
3810
+ };
3811
+ }
3812
+ function locateRightIndex(moveComponent, groupNode) {
3813
+ const syntaxComponent = moveComponent.parentComponent;
3814
+ if (!isGroupNode(groupNode)) {
3815
+ return null;
3816
+ }
3817
+ let groupInfo = syntaxComponent.getGroupContent(groupNode.id);
3818
+ let groupElement = groupInfo.content[0];
3819
+ if (isContainerNode(groupNode)) {
3820
+ if (isContainerNode(groupElement)) {
3821
+ return locateRightIndex(moveComponent, groupElement);
3822
+ }
3823
+ if (isPlaceholderNode(groupElement)) {
3824
+ return {
3825
+ groupId: groupNode.id,
3826
+ startOffset: 0,
3827
+ endOffset: 1
3828
+ };
3829
+ }
3830
+ return {
3831
+ groupId: groupNode.id,
3832
+ startOffset: 0,
3833
+ endOffset: 0
3834
+ };
3835
+ }
3836
+ while (!isContainerNode(groupElement) && !isPlaceholderNode(groupElement) && !isEmptyNode(groupElement)) {
3837
+ groupInfo = syntaxComponent.getGroupContent(groupElement.id);
3838
+ groupElement = groupInfo.content[0];
3839
+ }
3840
+ if (isPlaceholderNode(groupElement)) {
3841
+ return {
3842
+ groupId: groupElement.id,
3843
+ startOffset: 0,
3844
+ endOffset: 0
3845
+ };
3846
+ }
3847
+ if (isEmptyNode(groupElement)) {
3848
+ return locateOuterRightIndex(moveComponent, groupElement);
3849
+ }
3850
+ return locateRightIndex(moveComponent, groupElement);
3851
+ }
3852
+ function locateOuterRightIndex(moveComponent, groupNode) {
3853
+ const kfEditor = moveComponent.kfEditor;
3854
+ const syntaxComponent = moveComponent.parentComponent;
3855
+ if (isRootNode(groupNode)) {
3856
+ return null;
3857
+ }
3858
+ let outerGroupInfo = kfEditor.requestService("position.get.parent.info", groupNode);
3859
+ while (outerGroupInfo.index === outerGroupInfo.group.content.length - 1) {
3860
+ if (isRootNode(outerGroupInfo.group.groupObj)) {
3861
+ return {
3862
+ groupId: outerGroupInfo.group.id,
3863
+ startOffset: outerGroupInfo.group.content.length,
3864
+ endOffset: outerGroupInfo.group.content.length
3865
+ };
3866
+ }
3867
+ if (isContainerNode(outerGroupInfo.group.groupObj) && outerGroupInfo.group.content.length > 1) {
3868
+ return {
3869
+ groupId: outerGroupInfo.group.id,
3870
+ startOffset: outerGroupInfo.group.content.length,
3871
+ endOffset: outerGroupInfo.group.content.length
3872
+ };
3873
+ }
3874
+ outerGroupInfo = kfEditor.requestService("position.get.parent.info", outerGroupInfo.group.groupObj);
3875
+ }
3876
+ groupNode = outerGroupInfo.group.content[outerGroupInfo.index + 1];
3877
+ if (isEmptyNode(groupNode)) {
3878
+ return locateOuterRightIndex(moveComponent, groupNode);
3879
+ }
3880
+ if (isContainerNode(groupNode)) {
3881
+ const groupInfo = syntaxComponent.getGroupContent(groupNode.id);
3882
+ if (syntaxComponent.isPlaceholder(groupInfo.content[0].id)) {
3883
+ return {
3884
+ groupId: groupNode.id,
3885
+ startOffset: 0,
3886
+ endOffset: 1
3887
+ };
3888
+ }
3889
+ return {
3890
+ groupId: groupNode.id,
3891
+ startOffset: 0,
3892
+ endOffset: 0
3893
+ };
3894
+ }
3895
+ return {
3896
+ groupId: outerGroupInfo.group.id,
3897
+ startOffset: outerGroupInfo.index + 1,
3898
+ endOffset: outerGroupInfo.index + 1
3899
+ };
3900
+ }
3901
+ function updateCursorGoLeft(moveComponent, cursorInfo) {
3902
+ const syntaxComponent = moveComponent.parentComponent;
3903
+ const containerInfo = syntaxComponent.getGroupContent(cursorInfo.groupId);
3904
+ if (syntaxComponent.isSelectPlaceholder()) {
3905
+ return locateOuterLeftIndex(moveComponent, containerInfo.content[cursorInfo.startOffset]);
3906
+ }
3907
+ if (cursorInfo.startOffset === cursorInfo.endOffset) {
3908
+ if (cursorInfo.startOffset > 0) {
3909
+ const prevGroupNode = containerInfo.content[cursorInfo.startOffset - 1];
3910
+ if (isGroupNode(prevGroupNode)) {
3911
+ return locateLeftIndex(moveComponent, prevGroupNode);
3912
+ }
3913
+ cursorInfo.startOffset -= 1;
3914
+ if (!isPlaceholderNode(prevGroupNode)) {
3915
+ cursorInfo.endOffset = cursorInfo.startOffset;
3916
+ }
3917
+ return cursorInfo;
3918
+ }
3919
+ return locateOuterLeftIndex(moveComponent, containerInfo.groupObj);
3920
+ }
3921
+ cursorInfo.startOffset = Math.min(cursorInfo.startOffset, cursorInfo.endOffset);
3922
+ cursorInfo.endOffset = cursorInfo.startOffset;
3923
+ return cursorInfo;
3924
+ }
3925
+ function updateCursorGoRight(moveComponent, cursorInfo) {
3926
+ const syntaxComponent = moveComponent.parentComponent;
3927
+ const containerInfo = syntaxComponent.getGroupContent(cursorInfo.groupId);
3928
+ if (syntaxComponent.isSelectPlaceholder()) {
3929
+ return locateOuterRightIndex(moveComponent, containerInfo.content[cursorInfo.startOffset]);
3930
+ }
3931
+ if (cursorInfo.startOffset === cursorInfo.endOffset) {
3932
+ if (cursorInfo.startOffset < containerInfo.content.length) {
3933
+ const nextGroupNode = containerInfo.content[cursorInfo.startOffset];
3934
+ if (isGroupNode(nextGroupNode)) {
3935
+ return locateRightIndex(moveComponent, nextGroupNode);
3936
+ }
3937
+ cursorInfo.startOffset += 1;
3938
+ if (!isPlaceholderNode(nextGroupNode)) {
3939
+ cursorInfo.endOffset = cursorInfo.startOffset;
3940
+ }
3941
+ return cursorInfo;
3942
+ }
3943
+ return locateOuterRightIndex(moveComponent, containerInfo.groupObj);
3944
+ }
3945
+ cursorInfo.endOffset = Math.max(cursorInfo.startOffset, cursorInfo.endOffset);
3946
+ cursorInfo.startOffset = cursorInfo.endOffset;
3947
+ return cursorInfo;
3948
+ }
3949
+ var MoveComponent = kity17.createClass("MoveComponent", {
3950
+ constructor(parentComponent, kfEditor) {
3951
+ this.parentComponent = parentComponent;
3952
+ this.kfEditor = kfEditor;
3953
+ },
3954
+ leftMove() {
3955
+ let cursorInfo = this.parentComponent.getCursorRecord();
3956
+ cursorInfo = updateCursorGoLeft(this, cursorInfo);
3957
+ if (cursorInfo) {
3958
+ this.parentComponent.updateCursor(cursorInfo);
3959
+ }
3960
+ },
3961
+ rightMove() {
3962
+ let cursorInfo = this.parentComponent.getCursorRecord();
3963
+ cursorInfo = updateCursorGoRight(this, cursorInfo);
3964
+ if (cursorInfo) {
3965
+ this.parentComponent.updateCursor(cursorInfo);
3966
+ }
3967
+ }
3968
+ });
3969
+ var syntax_move_default = MoveComponent;
3970
+
3971
+ // ../kity-runtime/src/legacy/syntax.ts
3972
+ var CURSOR_CHAR2 = legacySysconf.cursorCharacter;
3973
+ var kity18 = getLegacyKity();
3974
+ function clampOffset(offset, maxOffset) {
3975
+ return Math.max(0, Math.min(offset, maxOffset));
3976
+ }
3977
+ function normalizeCursorRecord(objTree, cursor) {
3978
+ const fallbackGroupId = objTree.mapping.root.strGroup.attr.id;
3979
+ const targetGroupId = cursor.groupId && objTree.mapping[cursor.groupId] ? cursor.groupId : fallbackGroupId;
3980
+ const operandCount = objTree.mapping[targetGroupId].strGroup.operand.length;
3981
+ const startOffset = clampOffset(cursor.startOffset, operandCount);
3982
+ const endOffset = clampOffset(cursor.endOffset, operandCount);
3983
+ return {
3984
+ groupId: targetGroupId,
3985
+ startOffset: Math.min(startOffset, endOffset),
3986
+ endOffset: Math.max(startOffset, endOffset)
3987
+ };
3988
+ }
3989
+ var SyntaxComponent = kity18.createClass("SyntaxComponenet", {
3990
+ constructor(kfEditor) {
3991
+ this.kfEditor = kfEditor;
3992
+ this.record = {
3993
+ cursor: {
3994
+ groupId: null,
3995
+ startOffset: -1,
3996
+ endOffset: -1
3997
+ }
3998
+ };
3999
+ this.components = {};
4000
+ this.objTree = null;
4001
+ this.initComponents();
4002
+ this.initServices();
4003
+ this.initCommands();
4004
+ },
4005
+ initComponents() {
4006
+ this.components.move = new syntax_move_default(this, this.kfEditor);
4007
+ this.components.delete = new syntax_delete_default(this, this.kfEditor);
4008
+ },
4009
+ initServices() {
4010
+ this.kfEditor.registerService("syntax.update.objtree", this, { updateObjTree: this.updateObjTree });
4011
+ this.kfEditor.registerService("syntax.get.objtree", this, { getObjectTree: this.getObjectTree });
4012
+ this.kfEditor.registerService("syntax.get.group.object", this, { getGroupObject: this.getGroupObject });
4013
+ this.kfEditor.registerService("syntax.is.root.node", this, { isRootNode: this.isRootNode });
4014
+ this.kfEditor.registerService("syntax.is.group.node", this, { isGroupNode: this.isGroupNode });
4015
+ this.kfEditor.registerService("syntax.is.virtual.node", this, { isVirtualNode: this.isVirtualNode });
4016
+ this.kfEditor.registerService("syntax.is.placeholder.node", this, { isPlaceholder: this.isPlaceholder });
4017
+ this.kfEditor.registerService("syntax.is.select.placeholder", this, { isSelectPlaceholder: this.isSelectPlaceholder });
4018
+ this.kfEditor.registerService("syntax.has.root.placeholder", this, { hasRootplaceholder: this.hasRootplaceholder });
4019
+ this.kfEditor.registerService("syntax.valid.brackets", this, { isBrackets: this.isBrackets });
4020
+ this.kfEditor.registerService("syntax.get.group.content", this, { getGroupContent: this.getGroupContent });
4021
+ this.kfEditor.registerService("syntax.get.root.group.info", this, { getRootGroupInfo: this.getRootGroupInfo });
4022
+ this.kfEditor.registerService("syntax.get.root", this, { getRootObject: this.getRootObject });
4023
+ this.kfEditor.registerService("syntax.update.record.cursor", this, { updateCursor: this.updateCursor });
4024
+ this.kfEditor.registerService("syntax.update.selection", this, { updateSelection: this.updateSelection });
4025
+ this.kfEditor.registerService("syntax.get.record.cursor", this, { getCursorRecord: this.getCursorRecord });
4026
+ this.kfEditor.registerService("syntax.has.cursor.info", this, { hasCursorInfo: this.hasCursorInfo });
4027
+ this.kfEditor.registerService("syntax.serialization", this, { serialization: this.serialization });
4028
+ this.kfEditor.registerService("syntax.cursor.move.left", this, { leftMove: this.leftMove });
4029
+ this.kfEditor.registerService("syntax.cursor.move.right", this, { rightMove: this.rightMove });
4030
+ this.kfEditor.registerService("syntax.delete.group", this, { deleteGroup: this.deleteGroup });
4031
+ },
4032
+ initCommands() {
4033
+ this.kfEditor.registerCommand("get.source", this, this.getSource);
4034
+ this.kfEditor.registerCommand("content.is.empty", this, this.isEmpty);
4035
+ },
4036
+ updateObjTree(objTree) {
4037
+ const selectInfo = objTree.select;
4038
+ this.objTree = objTree;
4039
+ if (selectInfo?.groupId) {
4040
+ this.updateCursor(selectInfo.groupId, selectInfo.startOffset, selectInfo.endOffset);
4041
+ return;
4042
+ }
4043
+ if (this.record.cursor.groupId !== null) {
4044
+ this.record.cursor = normalizeCursorRecord(objTree, this.record.cursor);
4045
+ }
4046
+ },
4047
+ hasCursorInfo() {
4048
+ return this.record.cursor.groupId !== null;
4049
+ },
4050
+ isRootNode(groupId) {
4051
+ return this.objTree.mapping.root.strGroup.attr.id === groupId;
4052
+ },
4053
+ isGroupNode(groupId) {
4054
+ const type = this.objTree.mapping[groupId].strGroup.attr["data-type"];
4055
+ return type === legacyGroupType.GROUP || type === legacyGroupType.VIRTUAL;
4056
+ },
4057
+ isVirtualNode(groupId) {
4058
+ return this.objTree.mapping[groupId].strGroup.attr["data-type"] === legacyGroupType.VIRTUAL;
4059
+ },
4060
+ isPlaceholder(groupId) {
4061
+ const currentNode = this.objTree.mapping[groupId];
4062
+ if (!currentNode) {
4063
+ return false;
4064
+ }
4065
+ return currentNode.objGroup.node.getAttribute("data-flag") === "Placeholder";
4066
+ },
4067
+ isBrackets(groupId) {
4068
+ return !!this.objTree.mapping[groupId].objGroup.node.getAttribute("data-brackets");
4069
+ },
4070
+ hasRootplaceholder() {
4071
+ return this.objTree.mapping.root.strGroup.operand[0].name === "placeholder";
4072
+ },
4073
+ isSelectPlaceholder() {
4074
+ const cursorInfo = this.record.cursor;
4075
+ if (cursorInfo.endOffset - cursorInfo.startOffset !== 1 || !cursorInfo.groupId) {
4076
+ return false;
4077
+ }
4078
+ const groupInfo = this.getGroupContent(cursorInfo.groupId);
4079
+ return this.isPlaceholder(groupInfo.content[cursorInfo.startOffset].id);
4080
+ },
4081
+ isLeafTree(tree) {
4082
+ return typeof tree === "string";
4083
+ },
4084
+ isRootTree(tree) {
4085
+ return !!tree.attr?.["data-root"];
4086
+ },
4087
+ getObjectTree() {
4088
+ return this.objTree;
4089
+ },
4090
+ getGroupObject(id) {
4091
+ const groupInfo = this.objTree.mapping[id];
4092
+ return groupInfo ? groupInfo.objGroup : null;
4093
+ },
4094
+ getCursorRecord() {
4095
+ return kity18.Utils.extend({}, this.record.cursor);
4096
+ },
4097
+ getGroupContent(groupId) {
4098
+ const groupInfo = this.objTree.mapping[groupId];
4099
+ const operands = groupInfo.objGroup.operands;
4100
+ const offset = operands.length - 1;
4101
+ const isLtr = groupInfo.strGroup.traversal !== "rtl";
4102
+ const content = [];
4103
+ kity18.Utils.each(operands, (operand, i) => {
4104
+ if (isLtr) {
4105
+ content.push(operand.node);
4106
+ } else {
4107
+ content[offset - i] = operand.node;
4108
+ }
4109
+ });
4110
+ return {
4111
+ id: groupId,
4112
+ traversal: groupInfo.strGroup.traversal || "ltr",
4113
+ groupObj: groupInfo.objGroup.node,
4114
+ content
4115
+ };
4116
+ },
4117
+ getRootObject() {
4118
+ return this.objTree.mapping.root.objGroup;
4119
+ },
4120
+ getRootGroupInfo() {
4121
+ const rootGroupId = this.objTree.mapping.root.strGroup.attr.id;
4122
+ return this.getGroupContent(rootGroupId);
4123
+ },
4124
+ updateSelection(group) {
4125
+ let groupObj = this.objTree.mapping[group.id];
4126
+ let curStrGroup = groupObj.strGroup;
4127
+ let parentGroup = group;
4128
+ let parentGroupObj = groupObj;
4129
+ if (curStrGroup.name === "combination") {
4130
+ this.record.cursor = {
4131
+ groupId: parentGroup.id,
4132
+ startOffset: 0,
4133
+ endOffset: curStrGroup.operand.length
4134
+ };
4135
+ curStrGroup.operand.unshift(CURSOR_CHAR2);
4136
+ curStrGroup.operand.push(CURSOR_CHAR2);
4137
+ } else {
4138
+ while (parentGroupObj.strGroup.name !== "combination" || parentGroup.content === 1) {
4139
+ group = parentGroup;
4140
+ groupObj = parentGroupObj;
4141
+ parentGroup = this.kfEditor.requestService("position.get.parent.group", groupObj.objGroup.node);
4142
+ parentGroupObj = this.objTree.mapping[parentGroup.id];
4143
+ }
4144
+ const parentIndex = parentGroup.content.indexOf(group.groupObj);
4145
+ this.record.cursor = {
4146
+ groupId: parentGroup.id,
4147
+ startOffset: parentIndex,
4148
+ endOffset: parentIndex + 1
4149
+ };
4150
+ parentGroupObj.strGroup.operand.splice(parentIndex + 1, 0, CURSOR_CHAR2);
4151
+ parentGroupObj.strGroup.operand.splice(parentIndex, 0, CURSOR_CHAR2);
4152
+ }
4153
+ let resultStr = this.kfEditor.requestService("parser.latex.serialization", this.objTree.parsedTree);
4154
+ const startOffset = resultStr.indexOf(CURSOR_CHAR2);
4155
+ resultStr = resultStr.replace(CURSOR_CHAR2, "");
4156
+ const endOffset = resultStr.indexOf(CURSOR_CHAR2);
4157
+ parentGroupObj.strGroup.operand.splice(this.record.cursor.startOffset, 1);
4158
+ parentGroupObj.strGroup.operand.splice(this.record.cursor.endOffset, 1);
4159
+ return { str: resultStr, startOffset, endOffset };
4160
+ },
4161
+ getSource() {
4162
+ return this.serialization().str.replace(CURSOR_CHAR2, "").replace(CURSOR_CHAR2, "");
4163
+ },
4164
+ isEmpty() {
4165
+ return this.hasRootplaceholder();
4166
+ },
4167
+ serialization() {
4168
+ const cursor = normalizeCursorRecord(this.objTree, this.record.cursor);
4169
+ const objGroup = this.objTree.mapping[cursor.groupId];
4170
+ const curStrGroup = objGroup.strGroup;
4171
+ let strStartIndex = Math.min(cursor.endOffset, cursor.startOffset);
4172
+ let strEndIndex = Math.max(cursor.endOffset, cursor.startOffset);
4173
+ curStrGroup.operand.splice(strEndIndex, 0, CURSOR_CHAR2);
4174
+ curStrGroup.operand.splice(strStartIndex, 0, CURSOR_CHAR2);
4175
+ strEndIndex += 1;
4176
+ let resultStr = this.kfEditor.requestService("parser.latex.serialization", this.objTree.parsedTree);
4177
+ curStrGroup.operand.splice(strEndIndex, 1);
4178
+ curStrGroup.operand.splice(strStartIndex, 1);
4179
+ strStartIndex = resultStr.indexOf(CURSOR_CHAR2);
4180
+ if (cursor.startOffset === cursor.endOffset) {
4181
+ resultStr = resultStr.replace(CURSOR_CHAR2, "");
4182
+ }
4183
+ strEndIndex = resultStr.lastIndexOf(CURSOR_CHAR2);
4184
+ return {
4185
+ str: resultStr,
4186
+ startOffset: strStartIndex,
4187
+ endOffset: strEndIndex
4188
+ };
4189
+ },
4190
+ updateCursor(groupId, startOffset, endOffset) {
4191
+ if (arguments.length === 1) {
4192
+ endOffset = groupId.endOffset;
4193
+ startOffset = groupId.startOffset;
4194
+ groupId = groupId.groupId;
4195
+ }
4196
+ if (endOffset === void 0) {
4197
+ endOffset = startOffset;
4198
+ }
4199
+ if (startOffset > endOffset) {
4200
+ const tmp = endOffset;
4201
+ endOffset = startOffset;
4202
+ startOffset = tmp;
4203
+ }
4204
+ const nextCursor = {
4205
+ groupId,
4206
+ startOffset,
4207
+ endOffset
4208
+ };
4209
+ this.record.cursor = this.objTree ? normalizeCursorRecord(this.objTree, nextCursor) : nextCursor;
4210
+ },
4211
+ leftMove() {
4212
+ this.components.move.leftMove();
4213
+ },
4214
+ rightMove() {
4215
+ this.components.move.rightMove();
4216
+ },
4217
+ deleteGroup() {
4218
+ return this.components.delete.deleteGroup();
4219
+ },
4220
+ insertSubtree(subtree) {
4221
+ const cursorInfo = this.record.cursor;
4222
+ if (this.isPlaceholder(cursorInfo.groupId)) {
4223
+ this.replaceTree(subtree);
4224
+ return;
4225
+ }
4226
+ const startOffset = Math.min(cursorInfo.startOffset, cursorInfo.endOffset);
4227
+ const endOffset = Math.max(cursorInfo.startOffset, cursorInfo.endOffset);
4228
+ const diff = endOffset - startOffset;
4229
+ const currentTree = this.objTree.mapping[cursorInfo.groupId].strGroup;
4230
+ currentTree.operand.splice(startOffset, diff, subtree);
4231
+ cursorInfo.startOffset += 1;
4232
+ cursorInfo.endOffset = cursorInfo.startOffset;
4233
+ },
4234
+ replaceTree(subtree) {
4235
+ const cursorInfo = this.record.cursor;
4236
+ const groupNode = this.objTree.mapping[cursorInfo.groupId].objGroup.node;
4237
+ const parentInfo = this.kfEditor.requestService("position.get.parent.info", groupNode);
4238
+ const currentTree = this.objTree.mapping[parentInfo.group.id].strGroup;
4239
+ currentTree.operand[parentInfo.index] = subtree;
4240
+ cursorInfo.groupId = parentInfo.group.id;
4241
+ cursorInfo.startOffset = parentInfo.index + 1;
4242
+ cursorInfo.endOffset = parentInfo.index + 1;
4243
+ }
4244
+ });
4245
+ var syntax_default = SyntaxComponent;
4246
+
4247
+ // ../kity-runtime/src/legacy/input.ts
4248
+ var KEY_CODE = {
4249
+ LEFT: 37,
4250
+ RIGHT: 39,
4251
+ DELETE: 8,
4252
+ INPUT: 229
4253
+ };
4254
+ var CURSOR_CHAR3 = legacySysconf.cursorCharacter;
4255
+ var kity19 = getLegacyKity();
4256
+ function insertCursorMarkers(value, selectionStart, selectionEnd) {
4257
+ const normalizedStart = Math.max(0, Math.min(selectionStart ?? value.length, value.length));
4258
+ const normalizedEnd = Math.max(0, Math.min(selectionEnd ?? normalizedStart, value.length));
4259
+ const rangeStart = Math.min(normalizedStart, normalizedEnd);
4260
+ const rangeEnd = Math.max(normalizedStart, normalizedEnd);
4261
+ return value.slice(0, rangeStart) + CURSOR_CHAR3 + value.slice(rangeStart, rangeEnd) + CURSOR_CHAR3 + value.slice(rangeEnd);
4262
+ }
4263
+ var InputComponent = kity19.createClass("InputComponent", {
4264
+ constructor(parentComponent, kfEditor) {
4265
+ this.parentComponent = parentComponent;
4266
+ this.kfEditor = kfEditor;
4267
+ this.inputBox = this.createInputBox();
4268
+ this.initServices();
4269
+ this.initCommands();
4270
+ this.initEvent();
4271
+ },
4272
+ initServices() {
4273
+ this.kfEditor.registerService("control.update.input", this, {
4274
+ updateInput: this.updateInput
4275
+ });
4276
+ this.kfEditor.registerService("control.insert.string", this, {
4277
+ insertStr: this.insertStr
4278
+ });
4279
+ },
4280
+ initCommands() {
4281
+ this.kfEditor.registerCommand("focus", this, this.focus);
4282
+ },
4283
+ createInputBox() {
4284
+ const editorContainer = this.kfEditor.getContainer();
4285
+ const box = this.kfEditor.getDocument().createElement("input");
4286
+ box.className = "kf-editor-input-box";
4287
+ box.type = "text";
4288
+ box.isTrusted = false;
4289
+ editorContainer.appendChild(box);
4290
+ return box;
4291
+ },
4292
+ focus() {
4293
+ this.inputBox.focus();
4294
+ if (!this.kfEditor.requestService("syntax.has.cursor.info")) {
4295
+ const rootInfo = this.kfEditor.requestService("syntax.get.root.group.info");
4296
+ this.kfEditor.requestService("syntax.update.record.cursor", {
4297
+ groupId: rootInfo.id,
4298
+ startOffset: 0,
4299
+ endOffset: rootInfo.content.length
4300
+ });
4301
+ this.kfEditor.requestService("control.update.input");
4302
+ }
4303
+ this.kfEditor.requestService("control.reselect");
4304
+ },
4305
+ setUntrusted() {
4306
+ this.inputBox.isTrusted = false;
4307
+ },
4308
+ setTrusted() {
4309
+ this.inputBox.isTrusted = true;
4310
+ },
4311
+ updateInput() {
4312
+ const latexInfo = this.kfEditor.requestService("syntax.serialization");
4313
+ this.setUntrusted();
4314
+ this.inputBox.value = latexInfo.str;
4315
+ this.inputBox.selectionStart = latexInfo.startOffset;
4316
+ this.inputBox.selectionEnd = latexInfo.endOffset;
4317
+ this.inputBox.focus();
4318
+ this.setTrusted();
4319
+ },
4320
+ insertStr(str) {
4321
+ const latexInfo = this.kfEditor.requestService("syntax.serialization");
4322
+ let originString = latexInfo.str;
4323
+ originString = originString.substring(0, latexInfo.startOffset) + ` ${str} ` + originString.substring(latexInfo.endOffset);
4324
+ this.restruct(originString);
4325
+ this.updateInput();
4326
+ this.kfEditor.requestService("ui.update.canvas.view");
4327
+ },
4328
+ initEvent() {
4329
+ legacyBaseUtils.addEvent(this.inputBox, "keydown", (e) => {
4330
+ let isControl = false;
4331
+ if (e.ctrlKey) {
4332
+ this.processUserCtrl(e);
4333
+ return;
4334
+ }
4335
+ switch (e.keyCode) {
4336
+ case KEY_CODE.INPUT:
4337
+ return;
4338
+ case KEY_CODE.LEFT:
4339
+ e.preventDefault();
4340
+ this.leftMove();
4341
+ isControl = true;
4342
+ break;
4343
+ case KEY_CODE.RIGHT:
4344
+ e.preventDefault();
4345
+ this.rightMove();
4346
+ isControl = true;
4347
+ break;
4348
+ case KEY_CODE.DELETE:
4349
+ e.preventDefault();
4350
+ this.delete();
4351
+ isControl = true;
4352
+ break;
4353
+ }
4354
+ if (isControl) {
4355
+ this.kfEditor.requestService("ui.update.canvas.view");
4356
+ }
4357
+ if (!this.pretreatmentInput(e)) {
4358
+ e.preventDefault();
4359
+ }
4360
+ });
4361
+ legacyBaseUtils.addEvent(this.inputBox, "input", () => {
4362
+ this.processingInput();
4363
+ });
4364
+ legacyBaseUtils.addEvent(this.inputBox, "blur", () => {
4365
+ this.kfEditor.requestService("ui.toolbar.disable");
4366
+ this.kfEditor.requestService("ui.toolbar.close");
4367
+ this.kfEditor.requestService("control.cursor.hide");
4368
+ this.kfEditor.requestService("render.clear.select");
4369
+ });
4370
+ legacyBaseUtils.addEvent(this.inputBox, "focus", () => {
4371
+ this.kfEditor.requestService("ui.toolbar.enable");
4372
+ if (this.inputBox.isTrusted) {
4373
+ this.kfEditor.requestService("control.reselect");
4374
+ }
4375
+ });
4376
+ legacyBaseUtils.addEvent(this.inputBox, "paste", (e) => {
4377
+ e.preventDefault();
4378
+ });
4379
+ },
4380
+ hasRootplaceholder() {
4381
+ return this.kfEditor.requestService("syntax.has.root.placeholder");
4382
+ },
4383
+ leftMove() {
4384
+ if (this.hasRootplaceholder()) {
4385
+ return;
4386
+ }
4387
+ this.kfEditor.requestService("syntax.cursor.move.left");
4388
+ this.update();
4389
+ },
4390
+ rightMove() {
4391
+ if (this.hasRootplaceholder()) {
4392
+ return;
4393
+ }
4394
+ this.kfEditor.requestService("syntax.cursor.move.right");
4395
+ this.update();
4396
+ },
4397
+ delete() {
4398
+ if (this.hasRootplaceholder()) {
4399
+ return;
4400
+ }
4401
+ const isNeedRedraw = this.kfEditor.requestService("syntax.delete.group");
4402
+ if (isNeedRedraw) {
4403
+ this.updateInput();
4404
+ this.processingInput();
4405
+ return;
4406
+ }
4407
+ this.updateInput();
4408
+ this.kfEditor.requestService("control.reselect");
4409
+ },
4410
+ processUserCtrl(e) {
4411
+ e.preventDefault();
4412
+ switch (e.keyCode) {
4413
+ case 65:
4414
+ this.kfEditor.requestService("control.select.all");
4415
+ break;
4416
+ case 83:
4417
+ this.kfEditor.requestService("print.image");
4418
+ break;
4419
+ }
4420
+ },
4421
+ pretreatmentInput(evt) {
4422
+ const keyCode = this.getKeyCode(evt);
4423
+ const replaceStr = legacyInputFilter.getReplaceString(keyCode);
4424
+ if (replaceStr === null) {
4425
+ return true;
4426
+ }
4427
+ this.insertStr(replaceStr);
4428
+ return false;
4429
+ },
4430
+ getKeyCode(e) {
4431
+ return `${e.shiftKey ? "s+" : ""}${e.keyCode}`;
4432
+ },
4433
+ processingInput() {
4434
+ const latexWithCursor = insertCursorMarkers(
4435
+ this.inputBox.value,
4436
+ this.inputBox.selectionStart,
4437
+ this.inputBox.selectionEnd
4438
+ );
4439
+ this.restruct(latexWithCursor);
4440
+ this.kfEditor.requestService("ui.update.canvas.view");
4441
+ },
4442
+ restruct(latexStr) {
4443
+ this.kfEditor.requestService("render.draw", latexStr);
4444
+ this.kfEditor.requestService("control.reselect");
4445
+ },
4446
+ update() {
4447
+ this.updateInput();
4448
+ this.kfEditor.requestService("control.reselect");
4449
+ }
4450
+ });
4451
+ var input_default = InputComponent;
4452
+
4453
+ // ../kity-runtime/src/legacy/location.ts
4454
+ var kity20 = getLegacyKity();
4455
+ var LocationComponent = kity20.createClass("LocationComponent", {
4456
+ constructor(parentComponent, kfEditor) {
4457
+ this.parentComponent = parentComponent;
4458
+ this.kfEditor = kfEditor;
4459
+ this.paper = this.getPaper();
4460
+ this.cursorShape = this.createCursor();
4461
+ this.initServices();
4462
+ this.initEvent();
4463
+ },
4464
+ getPaper() {
4465
+ return this.kfEditor.requestService("render.get.paper");
4466
+ },
4467
+ initServices() {
4468
+ this.kfEditor.registerService("control.cursor.relocation", this, {
4469
+ relocationCursor: this.updateCursor
4470
+ });
4471
+ this.kfEditor.registerService("control.cursor.hide", this, {
4472
+ hideCursor: this.hideCursor
4473
+ });
4474
+ this.kfEditor.registerService("control.reselect", this, {
4475
+ reselect: this.reselect
4476
+ });
4477
+ this.kfEditor.registerService("control.get.cursor.location", this, {
4478
+ getCursorLocation: this.getCursorLocation
4479
+ });
4480
+ },
4481
+ createCursor() {
4482
+ const cursorShape = new kity20.Rect(1, 0, 0, 0).fill("black");
4483
+ cursorShape.setAttr("style", "display: none");
4484
+ this.paper.addShape(cursorShape);
4485
+ return cursorShape;
4486
+ },
4487
+ initEvent() {
4488
+ const eventServiceObject = this.kfEditor.request("ui.canvas.container.event");
4489
+ eventServiceObject.on("mousedown", (e) => {
4490
+ e.preventDefault();
4491
+ this.updateCursorInfo(e);
4492
+ this.kfEditor.requestService("control.update.input");
4493
+ this.reselect();
4494
+ });
4495
+ },
4496
+ updateCursorInfo(evt) {
4497
+ if (this.kfEditor.requestService("syntax.has.root.placeholder")) {
4498
+ this.kfEditor.requestService("syntax.update.record.cursor", {
4499
+ groupId: this.kfEditor.requestService("syntax.get.root.group.info").id,
4500
+ startOffset: 0,
4501
+ endOffset: 1
4502
+ });
4503
+ return false;
4504
+ }
4505
+ const wrapNode = this.kfEditor.requestService("position.get.wrap", evt.target);
4506
+ if (wrapNode && this.kfEditor.requestService("syntax.is.placeholder.node", wrapNode.id)) {
4507
+ const groupInfo2 = this.kfEditor.requestService("position.get.group.info", wrapNode);
4508
+ this.kfEditor.requestService("syntax.update.record.cursor", groupInfo2.group.id, groupInfo2.index, groupInfo2.index + 1);
4509
+ return;
4510
+ }
4511
+ let groupInfo = this.kfEditor.requestService("position.get.group", evt.target);
4512
+ if (groupInfo === null) {
4513
+ groupInfo = this.kfEditor.requestService("syntax.get.root.group.info");
4514
+ }
4515
+ const index = this.getIndex(evt.clientX, groupInfo);
4516
+ this.kfEditor.requestService("syntax.update.record.cursor", groupInfo.id, index);
4517
+ },
4518
+ hideCursor() {
4519
+ this.cursorShape.setAttr("style", "display: none");
4520
+ },
4521
+ reselect() {
4522
+ const cursorInfo = this.kfEditor.requestService("syntax.get.record.cursor");
4523
+ this.hideCursor();
4524
+ if (this.kfEditor.requestService("syntax.is.select.placeholder")) {
4525
+ const groupInfo = this.kfEditor.requestService("syntax.get.group.content", cursorInfo.groupId);
4526
+ this.kfEditor.requestService("render.select.group", groupInfo.content[cursorInfo.startOffset].id);
4527
+ return;
4528
+ }
4529
+ if (cursorInfo.startOffset === cursorInfo.endOffset) {
4530
+ this.updateCursor();
4531
+ this.kfEditor.requestService("render.tint.current.cursor");
4532
+ return;
4533
+ }
4534
+ this.kfEditor.requestService("render.select.current.cursor");
4535
+ },
4536
+ updateCursor() {
4537
+ const cursorInfo = this.kfEditor.requestService("syntax.get.record.cursor");
4538
+ if (cursorInfo.startOffset !== cursorInfo.endOffset) {
4539
+ this.hideCursor();
4540
+ return;
4541
+ }
4542
+ const groupInfo = this.kfEditor.requestService("syntax.get.group.content", cursorInfo.groupId);
4543
+ const isBefore = cursorInfo.endOffset === 0;
4544
+ const index = isBefore ? 0 : cursorInfo.endOffset - 1;
4545
+ const focusChild = groupInfo.content[index];
4546
+ const paperContainerRect = legacyBaseUtils.getRect(this.paper.container.node);
4547
+ const focusChildRect = legacyBaseUtils.getRect(focusChild);
4548
+ const cursorTransform = this.cursorShape.getTransform(this.cursorShape);
4549
+ const canvasZoom = this.kfEditor.requestService("render.get.canvas.zoom");
4550
+ const formulaZoom = this.paper.getZoom();
4551
+ this.cursorShape.setHeight(focusChildRect.height / canvasZoom / formulaZoom);
4552
+ let cursorOffset = isBefore ? focusChildRect.left - 2 : focusChildRect.left + focusChildRect.width - 2;
4553
+ cursorOffset -= paperContainerRect.left;
4554
+ cursorTransform.m.e = Math.floor(cursorOffset / canvasZoom / formulaZoom) + 0.5;
4555
+ cursorTransform.m.f = (focusChildRect.top - paperContainerRect.top) / canvasZoom / formulaZoom;
4556
+ this.cursorShape.setMatrix(cursorTransform);
4557
+ this.cursorShape.setAttr("style", "display: block");
4558
+ },
4559
+ getCursorLocation() {
4560
+ const rect = this.cursorShape.getRenderBox("paper");
4561
+ return {
4562
+ x: rect.x,
4563
+ y: rect.y
4564
+ };
4565
+ },
4566
+ getIndex(distance, groupInfo) {
4567
+ let index = -1;
4568
+ for (let i = groupInfo.content.length - 1; i >= 0; i -= 1) {
4569
+ index = i;
4570
+ const child = groupInfo.content[i];
4571
+ const boundingRect = legacyBaseUtils.getRect(child);
4572
+ if (boundingRect.left < distance) {
4573
+ if (boundingRect.left + boundingRect.width / 2 < distance) {
4574
+ index += 1;
4575
+ }
4576
+ break;
4577
+ }
4578
+ }
4579
+ return index;
4580
+ }
4581
+ });
4582
+ var location_default = LocationComponent;
4583
+
4584
+ // ../kity-runtime/src/legacy/selection.ts
4585
+ var MAX_DISTANCE = 10;
4586
+ var kity21 = getLegacyKity();
4587
+ var SelectionComponent = kity21.createClass("SelectionComponent", {
4588
+ constructor(parentComponent, kfEditor) {
4589
+ this.parentComponent = parentComponent;
4590
+ this.kfEditor = kfEditor;
4591
+ this.isDrag = false;
4592
+ this.isMousedown = false;
4593
+ this.startPoint = { x: -1, y: -1 };
4594
+ this.startGroupIsPlaceholder = false;
4595
+ this.startGroup = {};
4596
+ this.initServices();
4597
+ this.initEvent();
4598
+ },
4599
+ initServices() {
4600
+ this.kfEditor.registerService("control.select.all", this, {
4601
+ selectAll: this.selectAll
4602
+ });
4603
+ },
4604
+ initEvent() {
4605
+ const eventServiceObject = this.kfEditor.request("ui.canvas.container.event");
4606
+ eventServiceObject.on("mousedown", (e) => {
4607
+ e.preventDefault();
4608
+ if (this.kfEditor.requestService("syntax.has.root.placeholder")) {
4609
+ return false;
4610
+ }
4611
+ this.isMousedown = true;
4612
+ this.updateStartPoint(e.clientX, e.clientY);
4613
+ this.updateStartGroup();
4614
+ });
4615
+ eventServiceObject.on("mouseup", (e) => {
4616
+ e.preventDefault();
4617
+ this.stopUpdateSelection();
4618
+ });
4619
+ eventServiceObject.on("mousemove", (e) => {
4620
+ e.preventDefault();
4621
+ if (!this.isDrag) {
4622
+ if (this.isMousedown && MAX_DISTANCE < this.getDistance(e.clientX, e.clientY)) {
4623
+ this.kfEditor.requestService("control.cursor.hide");
4624
+ this.startUpdateSelection();
4625
+ }
4626
+ return;
4627
+ }
4628
+ if (e.which !== 1) {
4629
+ this.stopUpdateSelection();
4630
+ return;
4631
+ }
4632
+ this.updateSelection(e.target, e.clientX, e.clientY);
4633
+ });
4634
+ eventServiceObject.on("dblclick", (e) => {
4635
+ this.updateSelectionByTarget(e.target);
4636
+ });
4637
+ },
4638
+ getDistance(x, y) {
4639
+ const distanceX = Math.abs(x - this.startPoint.x);
4640
+ const distanceY = Math.abs(y - this.startPoint.y);
4641
+ return Math.max(distanceX, distanceY);
4642
+ },
4643
+ updateStartPoint(x, y) {
4644
+ this.startPoint.x = x;
4645
+ this.startPoint.y = y;
4646
+ },
4647
+ updateStartGroup() {
4648
+ const cursorInfo = this.kfEditor.requestService("syntax.get.record.cursor");
4649
+ this.startGroupIsPlaceholder = this.kfEditor.requestService("syntax.is.select.placeholder");
4650
+ this.startGroup = {
4651
+ groupInfo: this.kfEditor.requestService("syntax.get.group.content", cursorInfo.groupId),
4652
+ offset: cursorInfo.startOffset
4653
+ };
4654
+ },
4655
+ startUpdateSelection() {
4656
+ this.isDrag = true;
4657
+ this.isMousedown = false;
4658
+ this.clearSelection();
4659
+ },
4660
+ stopUpdateSelection() {
4661
+ this.isDrag = false;
4662
+ this.isMousedown = false;
4663
+ this.kfEditor.requestService("control.update.input");
4664
+ },
4665
+ clearSelection() {
4666
+ this.kfEditor.requestService("render.clear.select");
4667
+ },
4668
+ updateSelection(target, x) {
4669
+ const dir = x > this.startPoint.x;
4670
+ const startGroupInfo = this.startGroup;
4671
+ const currentGroupInfo = this.getGroupInof(x, target);
4672
+ let cursorInfo;
4673
+ if (currentGroupInfo.groupInfo.id === startGroupInfo.groupInfo.id) {
4674
+ cursorInfo = {
4675
+ groupId: currentGroupInfo.groupInfo.id,
4676
+ startOffset: startGroupInfo.offset,
4677
+ endOffset: currentGroupInfo.offset
4678
+ };
4679
+ if (this.startGroupIsPlaceholder) {
4680
+ if (!dir) {
4681
+ cursorInfo.startOffset += 1;
4682
+ } else if (cursorInfo.startOffset === cursorInfo.endOffset) {
4683
+ cursorInfo.endOffset += 1;
4684
+ }
4685
+ }
4686
+ } else if (legacyBaseUtils.contains(startGroupInfo.groupInfo.groupObj, currentGroupInfo.groupInfo.groupObj)) {
4687
+ cursorInfo = {
4688
+ groupId: startGroupInfo.groupInfo.id,
4689
+ startOffset: startGroupInfo.offset,
4690
+ endOffset: this.getIndex(startGroupInfo.groupInfo.groupObj, target, x)
4691
+ };
4692
+ } else if (legacyBaseUtils.contains(currentGroupInfo.groupInfo.groupObj, startGroupInfo.groupInfo.groupObj)) {
4693
+ cursorInfo = {
4694
+ groupId: currentGroupInfo.groupInfo.id,
4695
+ startOffset: this.kfEditor.requestService(
4696
+ "position.get.index",
4697
+ currentGroupInfo.groupInfo.groupObj,
4698
+ startGroupInfo.groupInfo.groupObj
4699
+ ),
4700
+ endOffset: currentGroupInfo.offset
4701
+ };
4702
+ if (!dir) {
4703
+ cursorInfo.startOffset += 1;
4704
+ }
4705
+ } else {
4706
+ const communityGroupInfo = this.getCommunityGroup(startGroupInfo.groupInfo, currentGroupInfo.groupInfo);
4707
+ if (communityGroupInfo.startOffset === communityGroupInfo.endOffset) {
4708
+ communityGroupInfo.endOffset += 1;
4709
+ } else {
4710
+ const currentGroupNode = communityGroupInfo.group.content[communityGroupInfo.endOffset];
4711
+ const inRightArea = this.kfEditor.requestService("position.get.area", currentGroupNode, x);
4712
+ if (inRightArea) {
4713
+ communityGroupInfo.endOffset += 1;
4714
+ }
4715
+ if (!dir) {
4716
+ communityGroupInfo.startOffset += 1;
4717
+ }
4718
+ }
4719
+ cursorInfo = {
4720
+ groupId: communityGroupInfo.group.id,
4721
+ startOffset: communityGroupInfo.startOffset,
4722
+ endOffset: communityGroupInfo.endOffset
4723
+ };
4724
+ }
4725
+ this.kfEditor.requestService("syntax.update.record.cursor", cursorInfo.groupId, cursorInfo.startOffset, cursorInfo.endOffset);
4726
+ this.kfEditor.requestService("control.reselect");
4727
+ },
4728
+ updateSelectionByTarget(target) {
4729
+ const parentGroupInfo = this.kfEditor.requestService("position.get.parent.group", target);
4730
+ if (parentGroupInfo === null) {
4731
+ return;
4732
+ }
4733
+ if (this.kfEditor.requestService("syntax.is.root.node", parentGroupInfo.id)) {
4734
+ this.selectAll();
4735
+ return;
4736
+ }
4737
+ let cursorInfo;
4738
+ if (!this.kfEditor.requestService("syntax.is.virtual.node", parentGroupInfo.id)) {
4739
+ cursorInfo = {
4740
+ groupId: parentGroupInfo.id,
4741
+ startOffset: 0,
4742
+ endOffset: parentGroupInfo.content.length
4743
+ };
4744
+ } else {
4745
+ const containerInfo = this.kfEditor.requestService("position.get.group.info", parentGroupInfo.groupObj);
4746
+ cursorInfo = {
4747
+ groupId: containerInfo.group.id,
4748
+ startOffset: containerInfo.index,
4749
+ endOffset: containerInfo.index + 1
4750
+ };
4751
+ }
4752
+ this.kfEditor.requestService("syntax.update.record.cursor", cursorInfo);
4753
+ this.kfEditor.requestService("control.reselect");
4754
+ this.kfEditor.requestService("control.update.input");
4755
+ },
4756
+ selectAll() {
4757
+ const rootGroupInfo = this.kfEditor.requestService("syntax.get.root.group.info");
4758
+ const cursorInfo = {
4759
+ groupId: rootGroupInfo.id,
4760
+ startOffset: 0,
4761
+ endOffset: rootGroupInfo.content.length
4762
+ };
4763
+ this.kfEditor.requestService("syntax.update.record.cursor", cursorInfo);
4764
+ this.kfEditor.requestService("control.reselect");
4765
+ this.kfEditor.requestService("control.update.input");
4766
+ },
4767
+ getGroupInof(offset, target) {
4768
+ let groupInfo = this.kfEditor.requestService("position.get.group", target);
4769
+ if (groupInfo === null) {
4770
+ groupInfo = this.kfEditor.requestService("syntax.get.root.group.info");
4771
+ }
4772
+ const index = this.kfEditor.requestService("position.get.location.info", offset, groupInfo);
4773
+ return {
4774
+ groupInfo,
4775
+ offset: index
4776
+ };
4777
+ },
4778
+ getIndex(groupNode, targetNode, offset) {
4779
+ let index = this.kfEditor.requestService("position.get.index", groupNode, targetNode);
4780
+ const groupInfo = this.kfEditor.requestService("syntax.get.group.content", groupNode.id);
4781
+ const targetWrapNode = groupInfo.content[index];
4782
+ const targetRect = legacyBaseUtils.getRect(targetWrapNode);
4783
+ if (targetRect.left + targetRect.width / 2 < offset) {
4784
+ index += 1;
4785
+ }
4786
+ return index;
4787
+ },
4788
+ getCommunityGroup(startGroupInfo, endGroupInfo) {
4789
+ let targetGroup = startGroupInfo.groupObj;
4790
+ let bigBoundingGroup = null;
4791
+ while (bigBoundingGroup = this.kfEditor.requestService("position.get.group.info", targetGroup)) {
4792
+ targetGroup = bigBoundingGroup.group.groupObj;
4793
+ if (legacyBaseUtils.contains(bigBoundingGroup.group.groupObj, endGroupInfo.groupObj)) {
4794
+ break;
4795
+ }
4796
+ }
4797
+ if (!bigBoundingGroup) {
4798
+ throw new Error("SelectionComponent: failed to find community group");
4799
+ }
4800
+ const groupNode = bigBoundingGroup.group.groupObj;
4801
+ return {
4802
+ group: bigBoundingGroup.group,
4803
+ startOffset: bigBoundingGroup.index,
4804
+ endOffset: this.kfEditor.requestService("position.get.index", groupNode, endGroupInfo.groupObj)
4805
+ };
4806
+ }
4807
+ });
4808
+ var selection_default = SelectionComponent;
4809
+
4810
+ // ../kity-runtime/src/legacy/listener.ts
4811
+ var kity22 = getLegacyKity();
4812
+ var ListenerComponent = kity22.createClass("MoveComponent", {
4813
+ constructor(parentComponent, kfEditor) {
4814
+ this.parentComponent = parentComponent;
4815
+ this.kfEditor = kfEditor;
4816
+ this.components = {};
4817
+ this.initComponents();
4818
+ },
4819
+ initComponents() {
4820
+ this.components.location = new location_default(this, this.kfEditor);
4821
+ this.components.selection = new selection_default(this, this.kfEditor);
4822
+ this.components.input = new input_default(this, this.kfEditor);
4823
+ }
4824
+ });
4825
+ var listener_default = ListenerComponent;
4826
+
4827
+ // ../kity-runtime/src/legacy/controller.ts
4828
+ var kity23 = getLegacyKity();
4829
+ var ControllerComponent = kity23.createClass("ControllerComponent", {
4830
+ constructor(kfEditor) {
4831
+ this.kfEditor = kfEditor;
4832
+ this.components = {};
4833
+ this.initComponents();
4834
+ },
4835
+ initComponents() {
4836
+ this.components.listener = new listener_default(this, this.kfEditor);
4837
+ }
4838
+ });
4839
+ var controller_default = ControllerComponent;
4840
+
4841
+ // ../kity-runtime/src/legacy/printer.ts
4842
+ var kity24 = getLegacyKity();
4843
+ var Printer = kity24.createClass("Printer", {
4844
+ constructor(kfEditor) {
4845
+ this.kfEditor = kfEditor;
4846
+ this.initServices();
4847
+ this.initCommands();
4848
+ },
4849
+ initServices() {
4850
+ this.kfEditor.registerService("print.image", this, {
4851
+ printImage: this.printImage
4852
+ });
4853
+ },
4854
+ initCommands() {
4855
+ this.kfEditor.registerCommand("get.image.data", this, this.getImageData);
4856
+ },
4857
+ printImage() {
4858
+ const formula = this.kfEditor.requestService("render.get.paper");
4859
+ this._formatCanvas();
4860
+ formula.toPNG((dataUrl) => {
4861
+ document.body.innerHTML = `<img style="background: red;" src="${dataUrl}">`;
4862
+ });
4863
+ this._restoreCanvas();
4864
+ },
4865
+ getImageData(cb) {
4866
+ const canvas = this.kfEditor.requestService("render.get.canvas");
4867
+ const formula = this.kfEditor.requestService("render.get.paper");
4868
+ this._formatCanvas();
4869
+ formula.toPNG((dataUrl) => {
4870
+ cb({
4871
+ width: canvas.width,
4872
+ height: canvas.height,
4873
+ img: dataUrl
4874
+ });
4875
+ });
4876
+ this._restoreCanvas();
4877
+ },
4878
+ _formatCanvas() {
4879
+ const canvas = this.kfEditor.requestService("render.get.canvas");
4880
+ const rect = canvas.container.getRenderBox();
4881
+ canvas.node.setAttribute("width", rect.width);
4882
+ canvas.node.setAttribute("height", rect.height);
4883
+ this.kfEditor.requestService("render.clear.canvas.transform");
4884
+ this.kfEditor.requestService("control.cursor.hide");
4885
+ this.kfEditor.requestService("render.clear.select");
4886
+ },
4887
+ _restoreCanvas() {
4888
+ const canvas = this.kfEditor.requestService("render.get.canvas");
4889
+ canvas.node.setAttribute("width", "100%");
4890
+ canvas.node.setAttribute("height", "100%");
4891
+ this.kfEditor.requestService("render.revert.canvas.transform");
4892
+ this.kfEditor.requestService("control.cursor.relocation");
4893
+ this.kfEditor.requestService("render.reselect");
4894
+ }
4895
+ });
4896
+ var printer_default = Printer;
4897
+
4898
+ // ../kity-runtime/src/boot/start.ts
4899
+ var installed = false;
4900
+ function installKityEditorStart(target = window) {
4901
+ const runtimeTarget = target;
4902
+ if (!installed) {
4903
+ editor_default.registerComponents("ui", ui_default);
4904
+ editor_default.registerComponents("parser", parser_default);
4905
+ editor_default.registerComponents("render", render_default);
4906
+ editor_default.registerComponents("position", position_default);
4907
+ editor_default.registerComponents("syntax", syntax_default);
4908
+ editor_default.registerComponents("control", controller_default);
4909
+ editor_default.registerComponents("print", printer_default);
4910
+ installed = true;
4911
+ }
4912
+ runtimeTarget.kf = runtimeTarget.kf ?? {};
4913
+ runtimeTarget.kf.EditorFactory = factory_default;
4914
+ return {
4915
+ KFEditor: editor_default,
4916
+ Factory: factory_default
4917
+ };
4918
+ }
4919
+ var start_default = installKityEditorStart;
4920
+ export {
4921
+ factory_default as Factory,
4922
+ editor_default as KFEditor,
4923
+ start_default as default,
4924
+ installKityEditorStart
4925
+ };
4926
+ //# sourceMappingURL=start-MBLTNR2Q.js.map