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