@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.
package/dist/index.js ADDED
@@ -0,0 +1,3652 @@
1
+ import {
2
+ addEvent,
3
+ createElement,
4
+ createLegacyBaseComponent,
5
+ createLegacyUiUtils,
6
+ delegateEvent,
7
+ getClassList,
8
+ getRectBox,
9
+ legacyBaseUtils,
10
+ legacyBoxType,
11
+ legacyEleType,
12
+ legacyEventListener,
13
+ legacyGroupType,
14
+ legacyInputFilter,
15
+ legacyItemType,
16
+ legacyKfEvent,
17
+ legacyKfExtDef,
18
+ legacyOtherPosition,
19
+ legacySysconf,
20
+ legacyUiDef,
21
+ normalizeMouseEvent,
22
+ publish,
23
+ setToolbarAssetUrls,
24
+ subscribe,
25
+ utils_default
26
+ } from "./chunk-EKIJQ64F.js";
27
+
28
+ // src/create-editor.ts
29
+ import { kityAssetManifest } from "@formulaxjs/kity-assets";
30
+
31
+ // src/vendor/char-position.ts
32
+ var legacyCharPosition = {
33
+ "\\pm": {
34
+ "x": 5,
35
+ "y": 0
36
+ },
37
+ "\\infty": {
38
+ "x": 42,
39
+ "y": 0
40
+ },
41
+ "=": {
42
+ "x": 79,
43
+ "y": 0
44
+ },
45
+ "\\sim": {
46
+ "x": 116,
47
+ "y": 0
48
+ },
49
+ "\\times": {
50
+ "x": 153,
51
+ "y": 0
52
+ },
53
+ "\\div": {
54
+ "x": 190,
55
+ "y": 0
56
+ },
57
+ "!": {
58
+ "x": 227,
59
+ "y": 0
60
+ },
61
+ "<": {
62
+ "x": 264,
63
+ "y": 0
64
+ },
65
+ "\\ll": {
66
+ "x": 301,
67
+ "y": 0
68
+ },
69
+ ">": {
70
+ "x": 338,
71
+ "y": 0
72
+ },
73
+ "\\gg": {
74
+ "x": 375,
75
+ "y": 0
76
+ },
77
+ "\\leq": {
78
+ "x": 412,
79
+ "y": 0
80
+ },
81
+ "\\geq": {
82
+ "x": 449,
83
+ "y": 0
84
+ },
85
+ "\\mp": {
86
+ "x": 486,
87
+ "y": 0
88
+ },
89
+ "\\cong": {
90
+ "x": 523,
91
+ "y": 0
92
+ },
93
+ "\\equiv": {
94
+ "x": 560,
95
+ "y": 0
96
+ },
97
+ "\\propto": {
98
+ "x": 597,
99
+ "y": 0
100
+ },
101
+ "\\approx": {
102
+ "x": 634,
103
+ "y": 0
104
+ },
105
+ "\\forall": {
106
+ "x": 671,
107
+ "y": 0
108
+ },
109
+ "\\partial": {
110
+ "x": 708,
111
+ "y": 0
112
+ },
113
+ "\\surd": {
114
+ "x": 745,
115
+ "y": 0
116
+ },
117
+ "\\cup": {
118
+ "x": 782,
119
+ "y": 0
120
+ },
121
+ "\\cap": {
122
+ "x": 819,
123
+ "y": 0
124
+ },
125
+ "\\varnothing": {
126
+ "x": 856,
127
+ "y": 0
128
+ },
129
+ "%": {
130
+ "x": 893,
131
+ "y": 0
132
+ },
133
+ "\\circ": {
134
+ "x": 930,
135
+ "y": 0
136
+ },
137
+ "\\exists": {
138
+ "x": 967,
139
+ "y": 0
140
+ },
141
+ "\\nexists": {
142
+ "x": 1004,
143
+ "y": 0
144
+ },
145
+ "\\in": {
146
+ "x": 1041,
147
+ "y": 0
148
+ },
149
+ "\\ni": {
150
+ "x": 1078,
151
+ "y": 0
152
+ },
153
+ "\\gets": {
154
+ "x": 5,
155
+ "y": 37
156
+ },
157
+ "\\uparrow": {
158
+ "x": 42,
159
+ "y": 37
160
+ },
161
+ "\\to": {
162
+ "x": 79,
163
+ "y": 37
164
+ },
165
+ "\\downarrow": {
166
+ "x": 116,
167
+ "y": 37
168
+ },
169
+ "\\leftrightarrow": {
170
+ "x": 153,
171
+ "y": 37
172
+ },
173
+ "\\therefore": {
174
+ "x": 190,
175
+ "y": 37
176
+ },
177
+ "\\because": {
178
+ "x": 227,
179
+ "y": 37
180
+ },
181
+ "+": {
182
+ "x": 264,
183
+ "y": 37
184
+ },
185
+ "-": {
186
+ "x": 301,
187
+ "y": 37
188
+ },
189
+ "\\neg": {
190
+ "x": 338,
191
+ "y": 37
192
+ },
193
+ "\\ast": {
194
+ "x": 375,
195
+ "y": 37
196
+ },
197
+ "\\cdot": {
198
+ "x": 412,
199
+ "y": 37
200
+ },
201
+ "\\vdots": {
202
+ "x": 449,
203
+ "y": 37
204
+ },
205
+ "\\ddots": {
206
+ "x": 486,
207
+ "y": 37
208
+ },
209
+ "\\aleph": {
210
+ "x": 523,
211
+ "y": 37
212
+ },
213
+ "\\beth": {
214
+ "x": 560,
215
+ "y": 37
216
+ },
217
+ "\\blacksquare": {
218
+ "x": 597,
219
+ "y": 37
220
+ },
221
+ "\\alpha": {
222
+ "x": 634,
223
+ "y": 37
224
+ },
225
+ "\\beta": {
226
+ "x": 671,
227
+ "y": 37
228
+ },
229
+ "\\gamma": {
230
+ "x": 708,
231
+ "y": 37
232
+ },
233
+ "\\delta": {
234
+ "x": 745,
235
+ "y": 37
236
+ },
237
+ "\\epsilon": {
238
+ "x": 782,
239
+ "y": 37
240
+ },
241
+ "\\zeta": {
242
+ "x": 819,
243
+ "y": 37
244
+ },
245
+ "\\eta": {
246
+ "x": 856,
247
+ "y": 37
248
+ },
249
+ "\\theta": {
250
+ "x": 893,
251
+ "y": 37
252
+ },
253
+ "\\iota": {
254
+ "x": 930,
255
+ "y": 37
256
+ },
257
+ "\\kappa": {
258
+ "x": 967,
259
+ "y": 37
260
+ },
261
+ "\\lambda": {
262
+ "x": 1004,
263
+ "y": 37
264
+ },
265
+ "\\mu": {
266
+ "x": 1041,
267
+ "y": 37
268
+ },
269
+ "\\nu": {
270
+ "x": 1078,
271
+ "y": 37
272
+ },
273
+ "\\xi": {
274
+ "x": 5,
275
+ "y": 74
276
+ },
277
+ "\\omicron": {
278
+ "x": 42,
279
+ "y": 74
280
+ },
281
+ "\\pi": {
282
+ "x": 79,
283
+ "y": 74
284
+ },
285
+ "\\rho": {
286
+ "x": 116,
287
+ "y": 74
288
+ },
289
+ "\\sigma": {
290
+ "x": 153,
291
+ "y": 74
292
+ },
293
+ "\\tau": {
294
+ "x": 190,
295
+ "y": 74
296
+ },
297
+ "\\upsilon": {
298
+ "x": 227,
299
+ "y": 74
300
+ },
301
+ "\\phi": {
302
+ "x": 264,
303
+ "y": 74
304
+ },
305
+ "\\chi": {
306
+ "x": 301,
307
+ "y": 74
308
+ },
309
+ "\\psi": {
310
+ "x": 338,
311
+ "y": 74
312
+ },
313
+ "\\omega": {
314
+ "x": 375,
315
+ "y": 74
316
+ },
317
+ "\\Alpha": {
318
+ "x": 412,
319
+ "y": 74
320
+ },
321
+ "\\Beta": {
322
+ "x": 449,
323
+ "y": 74
324
+ },
325
+ "\\Gamma": {
326
+ "x": 486,
327
+ "y": 74
328
+ },
329
+ "\\Delta": {
330
+ "x": 523,
331
+ "y": 74
332
+ },
333
+ "\\Epsilon": {
334
+ "x": 560,
335
+ "y": 74
336
+ },
337
+ "\\Zeta": {
338
+ "x": 597,
339
+ "y": 74
340
+ },
341
+ "\\Eta": {
342
+ "x": 634,
343
+ "y": 74
344
+ },
345
+ "\\Theta": {
346
+ "x": 671,
347
+ "y": 74
348
+ },
349
+ "\\Iota": {
350
+ "x": 708,
351
+ "y": 74
352
+ },
353
+ "\\Kappa": {
354
+ "x": 745,
355
+ "y": 74
356
+ },
357
+ "\\Lambda": {
358
+ "x": 782,
359
+ "y": 74
360
+ },
361
+ "\\Mu": {
362
+ "x": 819,
363
+ "y": 74
364
+ },
365
+ "\\Nu": {
366
+ "x": 856,
367
+ "y": 74
368
+ },
369
+ "\\Xi": {
370
+ "x": 893,
371
+ "y": 74
372
+ },
373
+ "\\Omicron": {
374
+ "x": 930,
375
+ "y": 74
376
+ },
377
+ "\\Pi": {
378
+ "x": 967,
379
+ "y": 74
380
+ },
381
+ "\\Rho": {
382
+ "x": 1004,
383
+ "y": 74
384
+ },
385
+ "\\Sigma": {
386
+ "x": 1041,
387
+ "y": 74
388
+ },
389
+ "\\Tau": {
390
+ "x": 1078,
391
+ "y": 74
392
+ },
393
+ "\\Upsilon": {
394
+ "x": 5,
395
+ "y": 111
396
+ },
397
+ "\\Phi": {
398
+ "x": 42,
399
+ "y": 111
400
+ },
401
+ "\\Chi": {
402
+ "x": 79,
403
+ "y": 111
404
+ },
405
+ "\\Psi": {
406
+ "x": 116,
407
+ "y": 111
408
+ },
409
+ "\\Omega": {
410
+ "x": 153,
411
+ "y": 111
412
+ },
413
+ "\\digamma": {
414
+ "x": 190,
415
+ "y": 111
416
+ },
417
+ "\\varepsilon": {
418
+ "x": 227,
419
+ "y": 111
420
+ },
421
+ "\\varkappa": {
422
+ "x": 264,
423
+ "y": 111
424
+ },
425
+ "\\varphi": {
426
+ "x": 301,
427
+ "y": 111
428
+ },
429
+ "\\varpi": {
430
+ "x": 338,
431
+ "y": 111
432
+ },
433
+ "\\varrho": {
434
+ "x": 375,
435
+ "y": 111
436
+ },
437
+ "\\varsigma": {
438
+ "x": 412,
439
+ "y": 111
440
+ },
441
+ "\\vartheta": {
442
+ "x": 449,
443
+ "y": 111
444
+ },
445
+ "\\neq": {
446
+ "x": 486,
447
+ "y": 111
448
+ },
449
+ "\\nless": {
450
+ "x": 523,
451
+ "y": 111
452
+ },
453
+ "\\ngtr": {
454
+ "x": 560,
455
+ "y": 111
456
+ },
457
+ "\\nleq": {
458
+ "x": 597,
459
+ "y": 111
460
+ },
461
+ "\\ngeq": {
462
+ "x": 634,
463
+ "y": 111
464
+ },
465
+ "\\nsim": {
466
+ "x": 671,
467
+ "y": 111
468
+ },
469
+ "\\lneqq": {
470
+ "x": 708,
471
+ "y": 111
472
+ },
473
+ "\\gneqq": {
474
+ "x": 745,
475
+ "y": 111
476
+ },
477
+ "\\nprec": {
478
+ "x": 782,
479
+ "y": 111
480
+ },
481
+ "\\nsucc": {
482
+ "x": 819,
483
+ "y": 111
484
+ },
485
+ "\\notin": {
486
+ "x": 856,
487
+ "y": 111
488
+ },
489
+ "\\nsubseteq": {
490
+ "x": 893,
491
+ "y": 111
492
+ },
493
+ "\\nsupseteq": {
494
+ "x": 930,
495
+ "y": 111
496
+ },
497
+ "\\subsetneq": {
498
+ "x": 967,
499
+ "y": 111
500
+ },
501
+ "\\supsetneq": {
502
+ "x": 1004,
503
+ "y": 111
504
+ },
505
+ "\\lnsim": {
506
+ "x": 1041,
507
+ "y": 111
508
+ },
509
+ "\\gnsim": {
510
+ "x": 1078,
511
+ "y": 111
512
+ },
513
+ "\\precnsim": {
514
+ "x": 5,
515
+ "y": 148
516
+ },
517
+ "\\succnsim": {
518
+ "x": 42,
519
+ "y": 148
520
+ },
521
+ "\\ntriangleleft": {
522
+ "x": 79,
523
+ "y": 148
524
+ },
525
+ "\\ntriangleright": {
526
+ "x": 116,
527
+ "y": 148
528
+ },
529
+ "\\ntrianglelefteq": {
530
+ "x": 153,
531
+ "y": 148
532
+ },
533
+ "\\ntrianglerighteq": {
534
+ "x": 190,
535
+ "y": 148
536
+ },
537
+ "\\nmid": {
538
+ "x": 227,
539
+ "y": 148
540
+ },
541
+ "\\nparallel": {
542
+ "x": 264,
543
+ "y": 148
544
+ },
545
+ "\\nvdash": {
546
+ "x": 301,
547
+ "y": 148
548
+ },
549
+ "\\nVdash": {
550
+ "x": 338,
551
+ "y": 148
552
+ },
553
+ "\\nvDash": {
554
+ "x": 375,
555
+ "y": 148
556
+ },
557
+ "\\nVDash": {
558
+ "x": 412,
559
+ "y": 148
560
+ },
561
+ "\\daleth": {
562
+ "x": 449,
563
+ "y": 148
564
+ },
565
+ "\\gimel": {
566
+ "x": 486,
567
+ "y": 148
568
+ },
569
+ "\\complement": {
570
+ "x": 523,
571
+ "y": 148
572
+ },
573
+ "\\ell": {
574
+ "x": 560,
575
+ "y": 148
576
+ },
577
+ "\\eth": {
578
+ "x": 597,
579
+ "y": 148
580
+ },
581
+ "\\hbar": {
582
+ "x": 634,
583
+ "y": 148
584
+ },
585
+ "\\hslash": {
586
+ "x": 671,
587
+ "y": 148
588
+ },
589
+ "\\mho": {
590
+ "x": 708,
591
+ "y": 148
592
+ },
593
+ "\\wp": {
594
+ "x": 745,
595
+ "y": 148
596
+ },
597
+ "\\circledS": {
598
+ "x": 782,
599
+ "y": 148
600
+ },
601
+ "\\Bbbk": {
602
+ "x": 819,
603
+ "y": 148
604
+ },
605
+ "\\Finv": {
606
+ "x": 856,
607
+ "y": 148
608
+ },
609
+ "\\Game": {
610
+ "x": 893,
611
+ "y": 148
612
+ },
613
+ "\\Im": {
614
+ "x": 930,
615
+ "y": 148
616
+ },
617
+ "\\Re": {
618
+ "x": 967,
619
+ "y": 148
620
+ },
621
+ "\\updownarrow": {
622
+ "x": 1004,
623
+ "y": 148
624
+ },
625
+ "\\Leftarrow": {
626
+ "x": 1041,
627
+ "y": 148
628
+ },
629
+ "\\Rightarrow": {
630
+ "x": 1078,
631
+ "y": 148
632
+ },
633
+ "\\Uparrow": {
634
+ "x": 5,
635
+ "y": 185
636
+ },
637
+ "\\Downarrow": {
638
+ "x": 42,
639
+ "y": 185
640
+ },
641
+ "\\Leftrightarrow": {
642
+ "x": 79,
643
+ "y": 185
644
+ },
645
+ "\\Updownarrow": {
646
+ "x": 116,
647
+ "y": 185
648
+ },
649
+ "\\longleftarrow": {
650
+ "x": 153,
651
+ "y": 185
652
+ },
653
+ "\\longrightarrow": {
654
+ "x": 190,
655
+ "y": 185
656
+ },
657
+ "\\longleftrightarrow": {
658
+ "x": 227,
659
+ "y": 185
660
+ },
661
+ "\\Longleftarrow": {
662
+ "x": 264,
663
+ "y": 185
664
+ },
665
+ "\\Longrightarrow": {
666
+ "x": 301,
667
+ "y": 185
668
+ },
669
+ "\\Longleftrightarrow": {
670
+ "x": 338,
671
+ "y": 185
672
+ },
673
+ "\\nearrow": {
674
+ "x": 375,
675
+ "y": 185
676
+ },
677
+ "\\nwarrow": {
678
+ "x": 412,
679
+ "y": 185
680
+ },
681
+ "\\searrow": {
682
+ "x": 449,
683
+ "y": 185
684
+ },
685
+ "\\swarrow": {
686
+ "x": 486,
687
+ "y": 185
688
+ },
689
+ "\\nleftarrow": {
690
+ "x": 523,
691
+ "y": 185
692
+ },
693
+ "\\nrightarrow": {
694
+ "x": 560,
695
+ "y": 185
696
+ },
697
+ "\\nLeftarrow": {
698
+ "x": 597,
699
+ "y": 185
700
+ },
701
+ "\\nRightarrow": {
702
+ "x": 634,
703
+ "y": 185
704
+ },
705
+ "\\nLeftrightarrow": {
706
+ "x": 671,
707
+ "y": 185
708
+ },
709
+ "\\leftharpoonup": {
710
+ "x": 708,
711
+ "y": 185
712
+ },
713
+ "\\leftharpoondown": {
714
+ "x": 745,
715
+ "y": 185
716
+ },
717
+ "\\rightharpoonup": {
718
+ "x": 782,
719
+ "y": 185
720
+ },
721
+ "\\rightharpoondown": {
722
+ "x": 819,
723
+ "y": 185
724
+ },
725
+ "\\upharpoonleft": {
726
+ "x": 856,
727
+ "y": 185
728
+ },
729
+ "\\upharpoonright": {
730
+ "x": 893,
731
+ "y": 185
732
+ },
733
+ "\\downharpoonleft": {
734
+ "x": 930,
735
+ "y": 185
736
+ },
737
+ "\\downharpoonright": {
738
+ "x": 967,
739
+ "y": 185
740
+ },
741
+ "\\leftrightharpoons": {
742
+ "x": 1004,
743
+ "y": 185
744
+ },
745
+ "\\rightleftharpoons": {
746
+ "x": 1041,
747
+ "y": 185
748
+ },
749
+ "\\leftleftarrows": {
750
+ "x": 1078,
751
+ "y": 185
752
+ },
753
+ "\\rightrightarrows": {
754
+ "x": 5,
755
+ "y": 222
756
+ },
757
+ "\\upuparrows": {
758
+ "x": 42,
759
+ "y": 222
760
+ },
761
+ "\\downdownarrows": {
762
+ "x": 79,
763
+ "y": 222
764
+ },
765
+ "\\leftrightarrows": {
766
+ "x": 116,
767
+ "y": 222
768
+ },
769
+ "\\rightleftarrows": {
770
+ "x": 153,
771
+ "y": 222
772
+ },
773
+ "\\looparrowleft": {
774
+ "x": 190,
775
+ "y": 222
776
+ },
777
+ "\\looparrowright": {
778
+ "x": 227,
779
+ "y": 222
780
+ },
781
+ "\\leftarrowtail": {
782
+ "x": 264,
783
+ "y": 222
784
+ },
785
+ "\\rightarrowtail": {
786
+ "x": 301,
787
+ "y": 222
788
+ },
789
+ "\\Lsh": {
790
+ "x": 338,
791
+ "y": 222
792
+ },
793
+ "\\Rsh": {
794
+ "x": 375,
795
+ "y": 222
796
+ },
797
+ "\\Lleftarrow": {
798
+ "x": 412,
799
+ "y": 222
800
+ },
801
+ "\\Rrightarrow": {
802
+ "x": 449,
803
+ "y": 222
804
+ },
805
+ "\\curvearrowleft": {
806
+ "x": 486,
807
+ "y": 222
808
+ },
809
+ "\\curvearrowright": {
810
+ "x": 523,
811
+ "y": 222
812
+ },
813
+ "\\circlearrowleft": {
814
+ "x": 560,
815
+ "y": 222
816
+ },
817
+ "\\circlearrowright": {
818
+ "x": 597,
819
+ "y": 222
820
+ },
821
+ "\\multimap": {
822
+ "x": 634,
823
+ "y": 222
824
+ },
825
+ "\\leftrightsquigarrow": {
826
+ "x": 671,
827
+ "y": 222
828
+ },
829
+ "\\twoheadleftarrow": {
830
+ "x": 708,
831
+ "y": 222
832
+ },
833
+ "\\twoheadrightarrow": {
834
+ "x": 745,
835
+ "y": 222
836
+ },
837
+ "\\rightsquigarrow": {
838
+ "x": 782,
839
+ "y": 222
840
+ },
841
+ "\\mathcal{A}": {
842
+ "x": 819,
843
+ "y": 222
844
+ },
845
+ "\\mathcal{B}": {
846
+ "x": 856,
847
+ "y": 222
848
+ },
849
+ "\\mathcal{C}": {
850
+ "x": 893,
851
+ "y": 222
852
+ },
853
+ "\\mathcal{D}": {
854
+ "x": 930,
855
+ "y": 222
856
+ },
857
+ "\\mathcal{E}": {
858
+ "x": 967,
859
+ "y": 222
860
+ },
861
+ "\\mathcal{F}": {
862
+ "x": 1004,
863
+ "y": 222
864
+ },
865
+ "\\mathcal{G}": {
866
+ "x": 1041,
867
+ "y": 222
868
+ },
869
+ "\\mathcal{H}": {
870
+ "x": 1078,
871
+ "y": 222
872
+ },
873
+ "\\mathcal{I}": {
874
+ "x": 5,
875
+ "y": 259
876
+ },
877
+ "\\mathcal{J}": {
878
+ "x": 42,
879
+ "y": 259
880
+ },
881
+ "\\mathcal{K}": {
882
+ "x": 79,
883
+ "y": 259
884
+ },
885
+ "\\mathcal{L}": {
886
+ "x": 116,
887
+ "y": 259
888
+ },
889
+ "\\mathcal{M}": {
890
+ "x": 153,
891
+ "y": 259
892
+ },
893
+ "\\mathcal{N}": {
894
+ "x": 190,
895
+ "y": 259
896
+ },
897
+ "\\mathcal{O}": {
898
+ "x": 227,
899
+ "y": 259
900
+ },
901
+ "\\mathcal{P}": {
902
+ "x": 264,
903
+ "y": 259
904
+ },
905
+ "\\mathcal{Q}": {
906
+ "x": 301,
907
+ "y": 259
908
+ },
909
+ "\\mathcal{R}": {
910
+ "x": 338,
911
+ "y": 259
912
+ },
913
+ "\\mathcal{S}": {
914
+ "x": 375,
915
+ "y": 259
916
+ },
917
+ "\\mathcal{T}": {
918
+ "x": 412,
919
+ "y": 259
920
+ },
921
+ "\\mathcal{U}": {
922
+ "x": 449,
923
+ "y": 259
924
+ },
925
+ "\\mathcal{V}": {
926
+ "x": 486,
927
+ "y": 259
928
+ },
929
+ "\\mathcal{W}": {
930
+ "x": 523,
931
+ "y": 259
932
+ },
933
+ "\\mathcal{X}": {
934
+ "x": 560,
935
+ "y": 259
936
+ },
937
+ "\\mathcal{Y}": {
938
+ "x": 597,
939
+ "y": 259
940
+ },
941
+ "\\mathcal{Z}": {
942
+ "x": 634,
943
+ "y": 259
944
+ },
945
+ "\\mathfrak{A}": {
946
+ "x": 671,
947
+ "y": 259
948
+ },
949
+ "\\mathfrak{B}": {
950
+ "x": 708,
951
+ "y": 259
952
+ },
953
+ "\\mathfrak{C}": {
954
+ "x": 745,
955
+ "y": 259
956
+ },
957
+ "\\mathfrak{D}": {
958
+ "x": 782,
959
+ "y": 259
960
+ },
961
+ "\\mathfrak{E}": {
962
+ "x": 819,
963
+ "y": 259
964
+ },
965
+ "\\mathfrak{F}": {
966
+ "x": 856,
967
+ "y": 259
968
+ },
969
+ "\\mathfrak{G}": {
970
+ "x": 893,
971
+ "y": 259
972
+ },
973
+ "\\mathfrak{H}": {
974
+ "x": 930,
975
+ "y": 259
976
+ },
977
+ "\\mathfrak{I}": {
978
+ "x": 967,
979
+ "y": 259
980
+ },
981
+ "\\mathfrak{J}": {
982
+ "x": 1004,
983
+ "y": 259
984
+ },
985
+ "\\mathfrak{K}": {
986
+ "x": 1041,
987
+ "y": 259
988
+ },
989
+ "\\mathfrak{L}": {
990
+ "x": 1078,
991
+ "y": 259
992
+ },
993
+ "\\mathfrak{M}": {
994
+ "x": 5,
995
+ "y": 296
996
+ },
997
+ "\\mathfrak{N}": {
998
+ "x": 42,
999
+ "y": 296
1000
+ },
1001
+ "\\mathfrak{O}": {
1002
+ "x": 79,
1003
+ "y": 296
1004
+ },
1005
+ "\\mathfrak{P}": {
1006
+ "x": 116,
1007
+ "y": 296
1008
+ },
1009
+ "\\mathfrak{Q}": {
1010
+ "x": 153,
1011
+ "y": 296
1012
+ },
1013
+ "\\mathfrak{R}": {
1014
+ "x": 190,
1015
+ "y": 296
1016
+ },
1017
+ "\\mathfrak{S}": {
1018
+ "x": 227,
1019
+ "y": 296
1020
+ },
1021
+ "\\mathfrak{T}": {
1022
+ "x": 264,
1023
+ "y": 296
1024
+ },
1025
+ "\\mathfrak{U}": {
1026
+ "x": 301,
1027
+ "y": 296
1028
+ },
1029
+ "\\mathfrak{V}": {
1030
+ "x": 338,
1031
+ "y": 296
1032
+ },
1033
+ "\\mathfrak{W}": {
1034
+ "x": 375,
1035
+ "y": 296
1036
+ },
1037
+ "\\mathfrak{X}": {
1038
+ "x": 412,
1039
+ "y": 296
1040
+ },
1041
+ "\\mathfrak{Y}": {
1042
+ "x": 449,
1043
+ "y": 296
1044
+ },
1045
+ "\\mathfrak{Z}": {
1046
+ "x": 486,
1047
+ "y": 296
1048
+ },
1049
+ "\\mathfrak{a}": {
1050
+ "x": 523,
1051
+ "y": 296
1052
+ },
1053
+ "\\mathfrak{b}": {
1054
+ "x": 560,
1055
+ "y": 296
1056
+ },
1057
+ "\\mathfrak{c}": {
1058
+ "x": 597,
1059
+ "y": 296
1060
+ },
1061
+ "\\mathfrak{d}": {
1062
+ "x": 634,
1063
+ "y": 296
1064
+ },
1065
+ "\\mathfrak{e}": {
1066
+ "x": 671,
1067
+ "y": 296
1068
+ },
1069
+ "\\mathfrak{f}": {
1070
+ "x": 708,
1071
+ "y": 296
1072
+ },
1073
+ "\\mathfrak{g}": {
1074
+ "x": 745,
1075
+ "y": 296
1076
+ },
1077
+ "\\mathfrak{h}": {
1078
+ "x": 782,
1079
+ "y": 296
1080
+ },
1081
+ "\\mathfrak{i}": {
1082
+ "x": 819,
1083
+ "y": 296
1084
+ },
1085
+ "\\mathfrak{j}": {
1086
+ "x": 856,
1087
+ "y": 296
1088
+ },
1089
+ "\\mathfrak{k}": {
1090
+ "x": 893,
1091
+ "y": 296
1092
+ },
1093
+ "\\mathfrak{l}": {
1094
+ "x": 930,
1095
+ "y": 296
1096
+ },
1097
+ "\\mathfrak{m}": {
1098
+ "x": 967,
1099
+ "y": 296
1100
+ },
1101
+ "\\mathfrak{n}": {
1102
+ "x": 1004,
1103
+ "y": 296
1104
+ },
1105
+ "\\mathfrak{o}": {
1106
+ "x": 1041,
1107
+ "y": 296
1108
+ },
1109
+ "\\mathfrak{p}": {
1110
+ "x": 1078,
1111
+ "y": 296
1112
+ },
1113
+ "\\mathfrak{q}": {
1114
+ "x": 5,
1115
+ "y": 333
1116
+ },
1117
+ "\\mathfrak{r}": {
1118
+ "x": 42,
1119
+ "y": 333
1120
+ },
1121
+ "\\mathfrak{s}": {
1122
+ "x": 79,
1123
+ "y": 333
1124
+ },
1125
+ "\\mathfrak{t}": {
1126
+ "x": 116,
1127
+ "y": 333
1128
+ },
1129
+ "\\mathfrak{u}": {
1130
+ "x": 153,
1131
+ "y": 333
1132
+ },
1133
+ "\\mathfrak{v}": {
1134
+ "x": 190,
1135
+ "y": 333
1136
+ },
1137
+ "\\mathfrak{w}": {
1138
+ "x": 227,
1139
+ "y": 333
1140
+ },
1141
+ "\\mathfrak{x}": {
1142
+ "x": 264,
1143
+ "y": 333
1144
+ },
1145
+ "\\mathfrak{y}": {
1146
+ "x": 301,
1147
+ "y": 333
1148
+ },
1149
+ "\\mathfrak{z}": {
1150
+ "x": 338,
1151
+ "y": 333
1152
+ },
1153
+ "\\mathbb{A}": {
1154
+ "x": 375,
1155
+ "y": 333
1156
+ },
1157
+ "\\mathbb{B}": {
1158
+ "x": 412,
1159
+ "y": 333
1160
+ },
1161
+ "\\mathbb{C}": {
1162
+ "x": 449,
1163
+ "y": 333
1164
+ },
1165
+ "\\mathbb{D}": {
1166
+ "x": 486,
1167
+ "y": 333
1168
+ },
1169
+ "\\mathbb{E}": {
1170
+ "x": 523,
1171
+ "y": 333
1172
+ },
1173
+ "\\mathbb{F}": {
1174
+ "x": 560,
1175
+ "y": 333
1176
+ },
1177
+ "\\mathbb{G}": {
1178
+ "x": 597,
1179
+ "y": 333
1180
+ },
1181
+ "\\mathbb{H}": {
1182
+ "x": 634,
1183
+ "y": 333
1184
+ },
1185
+ "\\mathbb{I}": {
1186
+ "x": 671,
1187
+ "y": 333
1188
+ },
1189
+ "\\mathbb{J}": {
1190
+ "x": 708,
1191
+ "y": 333
1192
+ },
1193
+ "\\mathbb{K}": {
1194
+ "x": 745,
1195
+ "y": 333
1196
+ },
1197
+ "\\mathbb{L}": {
1198
+ "x": 782,
1199
+ "y": 333
1200
+ },
1201
+ "\\mathbb{M}": {
1202
+ "x": 819,
1203
+ "y": 333
1204
+ },
1205
+ "\\mathbb{N}": {
1206
+ "x": 856,
1207
+ "y": 333
1208
+ },
1209
+ "\\mathbb{O}": {
1210
+ "x": 893,
1211
+ "y": 333
1212
+ },
1213
+ "\\mathbb{P}": {
1214
+ "x": 930,
1215
+ "y": 333
1216
+ },
1217
+ "\\mathbb{Q}": {
1218
+ "x": 967,
1219
+ "y": 333
1220
+ },
1221
+ "\\mathbb{R}": {
1222
+ "x": 1004,
1223
+ "y": 333
1224
+ },
1225
+ "\\mathbb{S}": {
1226
+ "x": 1041,
1227
+ "y": 333
1228
+ },
1229
+ "\\mathbb{T}": {
1230
+ "x": 1078,
1231
+ "y": 333
1232
+ },
1233
+ "\\mathbb{U}": {
1234
+ "x": 5,
1235
+ "y": 370
1236
+ },
1237
+ "\\mathbb{V}": {
1238
+ "x": 42,
1239
+ "y": 370
1240
+ },
1241
+ "\\mathbb{W}": {
1242
+ "x": 79,
1243
+ "y": 370
1244
+ },
1245
+ "\\mathbb{X}": {
1246
+ "x": 116,
1247
+ "y": 370
1248
+ },
1249
+ "\\mathbb{Y}": {
1250
+ "x": 153,
1251
+ "y": 370
1252
+ },
1253
+ "\\mathbb{Z}": {
1254
+ "x": 190,
1255
+ "y": 370
1256
+ },
1257
+ "\\mathrm{A}": {
1258
+ "x": 227,
1259
+ "y": 370
1260
+ },
1261
+ "\\mathrm{B}": {
1262
+ "x": 264,
1263
+ "y": 370
1264
+ },
1265
+ "\\mathrm{C}": {
1266
+ "x": 301,
1267
+ "y": 370
1268
+ },
1269
+ "\\mathrm{D}": {
1270
+ "x": 338,
1271
+ "y": 370
1272
+ },
1273
+ "\\mathrm{E}": {
1274
+ "x": 375,
1275
+ "y": 370
1276
+ },
1277
+ "\\mathrm{F}": {
1278
+ "x": 412,
1279
+ "y": 370
1280
+ },
1281
+ "\\mathrm{G}": {
1282
+ "x": 449,
1283
+ "y": 370
1284
+ },
1285
+ "\\mathrm{H}": {
1286
+ "x": 486,
1287
+ "y": 370
1288
+ },
1289
+ "\\mathrm{I}": {
1290
+ "x": 523,
1291
+ "y": 370
1292
+ },
1293
+ "\\mathrm{J}": {
1294
+ "x": 560,
1295
+ "y": 370
1296
+ },
1297
+ "\\mathrm{K}": {
1298
+ "x": 597,
1299
+ "y": 370
1300
+ },
1301
+ "\\mathrm{L}": {
1302
+ "x": 634,
1303
+ "y": 370
1304
+ },
1305
+ "\\mathrm{M}": {
1306
+ "x": 671,
1307
+ "y": 370
1308
+ },
1309
+ "\\mathrm{N}": {
1310
+ "x": 708,
1311
+ "y": 370
1312
+ },
1313
+ "\\mathrm{O}": {
1314
+ "x": 745,
1315
+ "y": 370
1316
+ },
1317
+ "\\mathrm{P}": {
1318
+ "x": 782,
1319
+ "y": 370
1320
+ },
1321
+ "\\mathrm{Q}": {
1322
+ "x": 819,
1323
+ "y": 370
1324
+ },
1325
+ "\\mathrm{R}": {
1326
+ "x": 856,
1327
+ "y": 370
1328
+ },
1329
+ "\\mathrm{S}": {
1330
+ "x": 893,
1331
+ "y": 370
1332
+ },
1333
+ "\\mathrm{T}": {
1334
+ "x": 930,
1335
+ "y": 370
1336
+ },
1337
+ "\\mathrm{U}": {
1338
+ "x": 967,
1339
+ "y": 370
1340
+ },
1341
+ "\\mathrm{V}": {
1342
+ "x": 1004,
1343
+ "y": 370
1344
+ },
1345
+ "\\mathrm{W}": {
1346
+ "x": 1041,
1347
+ "y": 370
1348
+ },
1349
+ "\\mathrm{X}": {
1350
+ "x": 1078,
1351
+ "y": 370
1352
+ },
1353
+ "\\mathrm{Y}": {
1354
+ "x": 5,
1355
+ "y": 407
1356
+ },
1357
+ "\\mathrm{Z}": {
1358
+ "x": 42,
1359
+ "y": 407
1360
+ },
1361
+ "\\mathrm{a}": {
1362
+ "x": 79,
1363
+ "y": 407
1364
+ },
1365
+ "\\mathrm{b}": {
1366
+ "x": 116,
1367
+ "y": 407
1368
+ },
1369
+ "\\mathrm{c}": {
1370
+ "x": 153,
1371
+ "y": 407
1372
+ },
1373
+ "\\mathrm{d}": {
1374
+ "x": 190,
1375
+ "y": 407
1376
+ },
1377
+ "\\mathrm{e}": {
1378
+ "x": 227,
1379
+ "y": 407
1380
+ },
1381
+ "\\mathrm{f}": {
1382
+ "x": 264,
1383
+ "y": 407
1384
+ },
1385
+ "\\mathrm{g}": {
1386
+ "x": 301,
1387
+ "y": 407
1388
+ },
1389
+ "\\mathrm{h}": {
1390
+ "x": 338,
1391
+ "y": 407
1392
+ },
1393
+ "\\mathrm{i}": {
1394
+ "x": 375,
1395
+ "y": 407
1396
+ },
1397
+ "\\mathrm{j}": {
1398
+ "x": 412,
1399
+ "y": 407
1400
+ },
1401
+ "\\mathrm{k}": {
1402
+ "x": 449,
1403
+ "y": 407
1404
+ },
1405
+ "\\mathrm{l}": {
1406
+ "x": 486,
1407
+ "y": 407
1408
+ },
1409
+ "\\mathrm{m}": {
1410
+ "x": 523,
1411
+ "y": 407
1412
+ },
1413
+ "\\mathrm{n}": {
1414
+ "x": 560,
1415
+ "y": 407
1416
+ },
1417
+ "\\mathrm{o}": {
1418
+ "x": 597,
1419
+ "y": 407
1420
+ },
1421
+ "\\mathrm{p}": {
1422
+ "x": 634,
1423
+ "y": 407
1424
+ },
1425
+ "\\mathrm{q}": {
1426
+ "x": 671,
1427
+ "y": 407
1428
+ },
1429
+ "\\mathrm{r}": {
1430
+ "x": 708,
1431
+ "y": 407
1432
+ },
1433
+ "\\mathrm{s}": {
1434
+ "x": 745,
1435
+ "y": 407
1436
+ },
1437
+ "\\mathrm{t}": {
1438
+ "x": 782,
1439
+ "y": 407
1440
+ },
1441
+ "\\mathrm{u}": {
1442
+ "x": 819,
1443
+ "y": 407
1444
+ },
1445
+ "\\mathrm{v}": {
1446
+ "x": 856,
1447
+ "y": 407
1448
+ },
1449
+ "\\mathrm{w}": {
1450
+ "x": 893,
1451
+ "y": 407
1452
+ },
1453
+ "\\mathrm{x}": {
1454
+ "x": 930,
1455
+ "y": 407
1456
+ },
1457
+ "\\mathrm{y}": {
1458
+ "x": 967,
1459
+ "y": 407
1460
+ },
1461
+ "\\mathrm{z}": {
1462
+ "x": 1004,
1463
+ "y": 407
1464
+ }
1465
+ };
1466
+
1467
+ // src/vendor/legacy-common.ts
1468
+ var legacyCommonUtils = {
1469
+ contains: legacyBaseUtils.contains,
1470
+ getRect: legacyBaseUtils.getRect
1471
+ };
1472
+
1473
+ // src/kity/class-system.ts
1474
+ function Class() {
1475
+ }
1476
+ var ClassProto = Class.prototype;
1477
+ ClassProto.base = function(name) {
1478
+ const stack = this.__kityCallStack__;
1479
+ const info = stack[stack.length - 1];
1480
+ const method = info.cls.__KityBaseClass.prototype[name];
1481
+ return method.apply(this, Array.prototype.slice.call(arguments, 1));
1482
+ };
1483
+ ClassProto.callBase = function() {
1484
+ const stack = this.__kityCallStack__;
1485
+ const info = stack[stack.length - 1];
1486
+ const method = info.cls.__KityBaseClass.prototype[info.methodName];
1487
+ return method.apply(this, arguments);
1488
+ };
1489
+ ClassProto.mixin = function(name) {
1490
+ const stack = this.__kityCallStack__;
1491
+ const info = stack[stack.length - 1];
1492
+ const mixins = info.cls.__KityMixins;
1493
+ if (!mixins) return this;
1494
+ return mixins[name].apply(this, Array.prototype.slice.call(arguments, 1));
1495
+ };
1496
+ ClassProto.callMixin = function() {
1497
+ const stack = this.__kityCallStack__;
1498
+ const info = stack[stack.length - 1];
1499
+ const methodName = info.methodName;
1500
+ const mixins = info.cls.__KityMixins;
1501
+ if (!mixins) return this;
1502
+ const method = mixins[methodName];
1503
+ if (methodName === "constructor") {
1504
+ for (let i = 0; i < method.length; i++) method[i].call(this);
1505
+ return this;
1506
+ }
1507
+ return method.apply(this, arguments);
1508
+ };
1509
+ ClassProto.pipe = function(fn) {
1510
+ if (typeof fn === "function") fn.call(this, this);
1511
+ return this;
1512
+ };
1513
+ ClassProto.getType = function() {
1514
+ return this.__KityClassName;
1515
+ };
1516
+ ClassProto.getClass = function() {
1517
+ return this.constructor;
1518
+ };
1519
+ function wrapMethod(cls, methodName, originalMethod) {
1520
+ const wrapped = function() {
1521
+ this.__kityCallStack__ = this.__kityCallStack__ || [];
1522
+ this.__kityCallStack__.push({ cls, methodName });
1523
+ try {
1524
+ return originalMethod.apply(this, arguments);
1525
+ } finally {
1526
+ this.__kityCallStack__.pop();
1527
+ }
1528
+ };
1529
+ wrapped.__KityMethodClass = cls;
1530
+ wrapped.__KityMethodName = methodName;
1531
+ return wrapped;
1532
+ }
1533
+ function inherit(constructor, BaseClass) {
1534
+ const KityClass = function() {
1535
+ const meta2 = KityClass;
1536
+ meta2.__KityConstructor.apply(this, arguments);
1537
+ };
1538
+ const meta = KityClass;
1539
+ meta.__KityConstructor = constructor;
1540
+ KityClass.prototype = Object.create(BaseClass.prototype);
1541
+ for (const methodName in BaseClass.prototype) {
1542
+ if (Object.prototype.hasOwnProperty.call(BaseClass.prototype, methodName) && methodName.indexOf("__Kity") !== 0) {
1543
+ KityClass.prototype[methodName] = BaseClass.prototype[methodName];
1544
+ }
1545
+ }
1546
+ KityClass.prototype.constructor = KityClass;
1547
+ return KityClass;
1548
+ }
1549
+ function legacyMixin(NewClass, mixins) {
1550
+ if (!(mixins instanceof Array)) return NewClass;
1551
+ const meta = NewClass;
1552
+ meta.__KityMixins = { constructor: [] };
1553
+ for (let i = 0; i < mixins.length; i++) {
1554
+ const proto = mixins[i].prototype;
1555
+ for (const method in proto) {
1556
+ if (!Object.prototype.hasOwnProperty.call(proto, method)) continue;
1557
+ if (method === "constructor") {
1558
+ meta.__KityMixins["constructor"].push(proto[method]);
1559
+ } else {
1560
+ NewClass.prototype[method] = meta.__KityMixins[method] = proto[method];
1561
+ }
1562
+ }
1563
+ }
1564
+ return NewClass;
1565
+ }
1566
+ function extend(BaseClass, extension) {
1567
+ for (const methodName in extension) {
1568
+ if (Object.prototype.hasOwnProperty.call(extension, methodName) && methodName !== "constructor" && methodName.indexOf("__Kity") !== 0) {
1569
+ BaseClass.prototype[methodName] = wrapMethod(
1570
+ BaseClass,
1571
+ methodName,
1572
+ extension[methodName]
1573
+ );
1574
+ }
1575
+ }
1576
+ return BaseClass;
1577
+ }
1578
+ function checkBaseConstructorCall(targetClass, classname) {
1579
+ if (!/this\.callBase/.test(targetClass.toString())) {
1580
+ throw new Error(
1581
+ `${classname}: the constructor must call the base constructor for compatibility with the legacy kity class system.`
1582
+ );
1583
+ }
1584
+ }
1585
+ function createClass(classname, defines) {
1586
+ let constructor;
1587
+ let NewClass;
1588
+ let BaseClass;
1589
+ if (arguments.length === 1) {
1590
+ defines = arguments[0];
1591
+ classname = "AnonymousClass";
1592
+ }
1593
+ defines = defines || {};
1594
+ BaseClass = defines.base || Class;
1595
+ if (Object.prototype.hasOwnProperty.call(defines, "constructor")) {
1596
+ constructor = defines.constructor;
1597
+ if (BaseClass !== Class) {
1598
+ checkBaseConstructorCall(constructor, classname);
1599
+ }
1600
+ } else {
1601
+ constructor = function() {
1602
+ this.callBase.apply(this, arguments);
1603
+ this.callMixin.apply(this, arguments);
1604
+ };
1605
+ }
1606
+ const originalConstructor = constructor;
1607
+ constructor = function() {
1608
+ this.__kityCallStack__ = this.__kityCallStack__ || [];
1609
+ this.__kityCallStack__.push({
1610
+ cls: NewClass,
1611
+ methodName: "constructor"
1612
+ });
1613
+ try {
1614
+ return originalConstructor.apply(this, arguments);
1615
+ } finally {
1616
+ this.__kityCallStack__.pop();
1617
+ }
1618
+ };
1619
+ NewClass = inherit(constructor, BaseClass);
1620
+ NewClass = legacyMixin(NewClass, defines.mixins || []);
1621
+ const meta = NewClass;
1622
+ meta.__KityClassName = constructor.__KityClassName = classname;
1623
+ meta.__KityBaseClass = constructor.__KityBaseClass = BaseClass;
1624
+ constructor.__KityMethodName = "constructor";
1625
+ constructor.__KityMethodClass = NewClass;
1626
+ delete defines.mixins;
1627
+ delete defines.constructor;
1628
+ delete defines.base;
1629
+ NewClass = extend(NewClass, defines);
1630
+ return NewClass;
1631
+ }
1632
+ function extendClass(clazz, extension) {
1633
+ return extend(clazz, extension);
1634
+ }
1635
+
1636
+ // src/kity/geometry.ts
1637
+ var Box = createClass("Box", {
1638
+ constructor(x, y, width, height) {
1639
+ const box = arguments[0];
1640
+ if (box && typeof box === "object" && ("x" in box || "left" in box)) {
1641
+ x = box.x ?? box.left;
1642
+ y = box.y ?? box.top;
1643
+ width = box.width;
1644
+ height = box.height;
1645
+ }
1646
+ const w = width ?? 0;
1647
+ const h = height ?? 0;
1648
+ if (w < 0) {
1649
+ x = x - (width = -w);
1650
+ }
1651
+ if (h < 0) {
1652
+ y = y - (height = -h);
1653
+ }
1654
+ this.x = x || 0;
1655
+ this.y = y || 0;
1656
+ this.width = width || 0;
1657
+ this.height = height || 0;
1658
+ this.left = this.x;
1659
+ this.right = this.x + this.width;
1660
+ this.top = this.y;
1661
+ this.bottom = this.y + this.height;
1662
+ this.cx = this.x + this.width / 2;
1663
+ this.cy = this.y + this.height / 2;
1664
+ },
1665
+ getRangeX() {
1666
+ return [this.left, this.right];
1667
+ },
1668
+ getRangeY() {
1669
+ return [this.top, this.bottom];
1670
+ },
1671
+ merge(another) {
1672
+ if (this.isEmpty()) return new Box(another.x, another.y, another.width, another.height);
1673
+ const left = Math.min(this.left, another.left);
1674
+ const right = Math.max(this.right, another.right);
1675
+ const top = Math.min(this.top, another.top);
1676
+ const bottom = Math.max(this.bottom, another.bottom);
1677
+ return new Box(left, top, right - left, bottom - top);
1678
+ },
1679
+ intersect(another) {
1680
+ if (!(another instanceof Box) || this.isEmpty() || another.isEmpty()) return new Box();
1681
+ if (this.right <= another.left || another.right <= this.left || this.bottom <= another.top || another.bottom <= this.top)
1682
+ return new Box();
1683
+ const x = Math.max(this.left, another.left), y = Math.max(this.top, another.top);
1684
+ return new Box(
1685
+ x,
1686
+ y,
1687
+ Math.min(this.right, another.right) - x,
1688
+ Math.min(this.bottom, another.bottom) - y
1689
+ );
1690
+ },
1691
+ expand(top, right, bottom, left) {
1692
+ if (arguments.length < 4) {
1693
+ right = top;
1694
+ bottom = top;
1695
+ left = top;
1696
+ }
1697
+ return new Box(
1698
+ this.x - left,
1699
+ this.y - top,
1700
+ this.width + right + left,
1701
+ this.height + top + bottom
1702
+ );
1703
+ },
1704
+ valueOf() {
1705
+ return [this.x, this.y, this.width, this.height];
1706
+ },
1707
+ toString() {
1708
+ return this.valueOf().join(" ");
1709
+ },
1710
+ isEmpty() {
1711
+ return !this.width || !this.height;
1712
+ }
1713
+ });
1714
+ Box.parse = function(unknown) {
1715
+ if (!unknown) return new Box();
1716
+ if (unknown instanceof Box) return unknown;
1717
+ if (typeof unknown === "string") return Box.parse(unknown.split(/\s*[\s,]\s*/));
1718
+ if ("0" in unknown && "1" in unknown && "2" in unknown && "3" in unknown)
1719
+ return new Box(unknown[0], unknown[1], unknown[2], unknown[3]);
1720
+ return new Box();
1721
+ };
1722
+ var Point = createClass("Point", {
1723
+ constructor(x, y) {
1724
+ this.x = x || 0;
1725
+ this.y = y || 0;
1726
+ },
1727
+ offset(dx, dy) {
1728
+ if (arguments.length === 1) {
1729
+ dy = dx.y;
1730
+ dx = dx.x;
1731
+ }
1732
+ return new Point(this.x + dx, this.y + dy);
1733
+ },
1734
+ valueOf() {
1735
+ return [this.x, this.y];
1736
+ },
1737
+ toString() {
1738
+ return this.valueOf().join(" ");
1739
+ },
1740
+ spof() {
1741
+ return new Point((this.x | 0) + 0.5, (this.y | 0) + 0.5);
1742
+ },
1743
+ round() {
1744
+ return new Point(this.x | 0, this.y | 0);
1745
+ },
1746
+ isOrigin() {
1747
+ return this.x === 0 && this.y === 0;
1748
+ }
1749
+ });
1750
+ Point.fromPolar = function(radius, angle, unit) {
1751
+ if (unit !== "rad") angle = angle / 180 * Math.PI;
1752
+ return new Point(radius * Math.cos(angle), radius * Math.sin(angle));
1753
+ };
1754
+ Point.parse = function(unknown) {
1755
+ if (!unknown) return new Point();
1756
+ if (unknown instanceof Point) return unknown;
1757
+ if (typeof unknown === "string") return Point.parse(unknown.split(/\s*[\s,]\s*/));
1758
+ if ("0" in unknown && "1" in unknown) return new Point(unknown[0], unknown[1]);
1759
+ return new Point();
1760
+ };
1761
+ var g = {};
1762
+ g.pathToString = function(pathSegment) {
1763
+ pathSegment = pathSegment || this;
1764
+ if (typeof pathSegment === "string") return pathSegment;
1765
+ if (pathSegment instanceof Array)
1766
+ return utils_default.flatten(pathSegment).join(",").replace(/,?([achlmqrstvxz]),?/gi, "$1");
1767
+ return "";
1768
+ };
1769
+ function d2r(deg) {
1770
+ return deg * Math.PI / 180;
1771
+ }
1772
+ function mergeMatrixData(m2, m1) {
1773
+ return {
1774
+ a: m1.a * m2.a + m1.c * m2.b,
1775
+ b: m1.b * m2.a + m1.d * m2.b,
1776
+ c: m1.a * m2.c + m1.c * m2.d,
1777
+ d: m1.b * m2.c + m1.d * m2.d,
1778
+ e: m1.a * m2.e + m1.c * m2.f + m1.e,
1779
+ f: m1.b * m2.e + m1.d * m2.f + m1.f
1780
+ };
1781
+ }
1782
+ var mPattern = /matrix\s*\((.+)\)/i;
1783
+ var Matrix = createClass("Matrix", {
1784
+ constructor(..._args) {
1785
+ if (arguments.length) {
1786
+ this.setMatrix.apply(this, arguments);
1787
+ } else {
1788
+ this.setMatrix(1, 0, 0, 1, 0, 0);
1789
+ }
1790
+ },
1791
+ translate(x, y) {
1792
+ this.m = mergeMatrixData(this.m, {
1793
+ a: 1,
1794
+ c: 0,
1795
+ e: x,
1796
+ b: 0,
1797
+ d: 1,
1798
+ f: y
1799
+ });
1800
+ return this;
1801
+ },
1802
+ rotate(deg) {
1803
+ const r = d2r(deg), s = Math.sin(r), c = Math.cos(r);
1804
+ this.m = mergeMatrixData(this.m, {
1805
+ a: c,
1806
+ c: -s,
1807
+ e: 0,
1808
+ b: s,
1809
+ d: c,
1810
+ f: 0
1811
+ });
1812
+ return this;
1813
+ },
1814
+ scale(sx, sy) {
1815
+ if (sy === void 0) sy = sx;
1816
+ this.m = mergeMatrixData(this.m, {
1817
+ a: sx,
1818
+ c: 0,
1819
+ e: 0,
1820
+ b: 0,
1821
+ d: sy,
1822
+ f: 0
1823
+ });
1824
+ return this;
1825
+ },
1826
+ skew(degX, degY) {
1827
+ if (degY === void 0) degY = degX;
1828
+ this.m = mergeMatrixData(this.m, {
1829
+ a: 1,
1830
+ c: Math.tan(d2r(degX)),
1831
+ e: 0,
1832
+ b: Math.tan(d2r(degY)),
1833
+ d: 1,
1834
+ f: 0
1835
+ });
1836
+ return this;
1837
+ },
1838
+ inverse() {
1839
+ const m = this.m, k = m.a * m.d - m.b * m.c;
1840
+ return new Matrix(
1841
+ m.d / k,
1842
+ -m.b / k,
1843
+ -m.c / k,
1844
+ m.a / k,
1845
+ (m.c * m.f - m.e * m.d) / k,
1846
+ (m.b * m.e - m.a * m.f) / k
1847
+ );
1848
+ },
1849
+ setMatrix(a, b, c, d, e, f) {
1850
+ if (arguments.length === 1) {
1851
+ this.m = utils_default.clone(arguments[0]);
1852
+ } else {
1853
+ this.m = {
1854
+ a,
1855
+ b,
1856
+ c,
1857
+ d,
1858
+ e,
1859
+ f
1860
+ };
1861
+ }
1862
+ return this;
1863
+ },
1864
+ getMatrix() {
1865
+ return utils_default.clone(this.m);
1866
+ },
1867
+ getTranslate() {
1868
+ const m = this.m;
1869
+ return { x: m.e / m.a, y: m.f / m.d };
1870
+ },
1871
+ mergeMatrix(matrix) {
1872
+ return new Matrix(mergeMatrixData(this.m, matrix.m));
1873
+ },
1874
+ merge(matrix) {
1875
+ return this.mergeMatrix(matrix);
1876
+ },
1877
+ toString() {
1878
+ return this.valueOf().join(" ");
1879
+ },
1880
+ valueOf() {
1881
+ const m = this.m;
1882
+ return [m.a, m.b, m.c, m.d, m.e, m.f];
1883
+ },
1884
+ equals(matrix) {
1885
+ const m1 = this.m, m2 = matrix.m;
1886
+ return m1.a === m2.a && m1.b === m2.b && m1.c === m2.c && m1.d === m2.d && m1.e === m2.e && m1.f === m2.f;
1887
+ },
1888
+ transformPoint() {
1889
+ return Matrix.transformPoint.apply(
1890
+ null,
1891
+ [].slice.call(arguments).concat([this.m])
1892
+ );
1893
+ },
1894
+ transformBox(box) {
1895
+ return Matrix.transformBox(box, this.m);
1896
+ },
1897
+ clone() {
1898
+ return new Matrix(this.m);
1899
+ },
1900
+ reverse() {
1901
+ return this.inverse();
1902
+ }
1903
+ });
1904
+ Matrix.parse = function(str) {
1905
+ const f = parseFloat;
1906
+ if (str instanceof Array)
1907
+ return new Matrix({
1908
+ a: f(str[0]),
1909
+ b: f(str[1]),
1910
+ c: f(str[2]),
1911
+ d: f(str[3]),
1912
+ e: f(str[4]),
1913
+ f: f(str[5])
1914
+ });
1915
+ const match = mPattern.exec(str);
1916
+ if (match) {
1917
+ let values = match[1].split(",");
1918
+ if (values.length !== 6) values = match[1].split(" ");
1919
+ return new Matrix({
1920
+ a: f(values[0]),
1921
+ b: f(values[1]),
1922
+ c: f(values[2]),
1923
+ d: f(values[3]),
1924
+ e: f(values[4]),
1925
+ f: f(values[5])
1926
+ });
1927
+ }
1928
+ return new Matrix();
1929
+ };
1930
+ Matrix.transformPoint = function(x, y, m) {
1931
+ if (arguments.length === 2) {
1932
+ m = y;
1933
+ y = x.y;
1934
+ x = x.x;
1935
+ }
1936
+ return new Point(
1937
+ m.a * x + m.c * y + m.e,
1938
+ m.b * x + m.d * y + m.f
1939
+ );
1940
+ };
1941
+ Matrix.transformBox = function(box, matrix) {
1942
+ let xMin = Number.MAX_VALUE, xMax = -Number.MAX_VALUE, yMin = Number.MAX_VALUE, yMax = -Number.MAX_VALUE;
1943
+ const bps = [
1944
+ [box.x, box.y],
1945
+ [box.x + box.width, box.y],
1946
+ [box.x, box.y + box.height],
1947
+ [box.x + box.width, box.y + box.height]
1948
+ ];
1949
+ const rps = [];
1950
+ let bp;
1951
+ while (bp = bps.pop()) {
1952
+ const rp = Matrix.transformPoint(bp[0], bp[1], matrix);
1953
+ rps.push(rp);
1954
+ xMin = Math.min(xMin, rp.x);
1955
+ xMax = Math.max(xMax, rp.x);
1956
+ yMin = Math.min(yMin, rp.y);
1957
+ yMax = Math.max(yMax, rp.y);
1958
+ }
1959
+ const result = new Box({
1960
+ x: xMin,
1961
+ y: yMin,
1962
+ width: xMax - xMin,
1963
+ height: yMax - yMin
1964
+ });
1965
+ utils_default.extend(result, { closurePoints: rps });
1966
+ return result;
1967
+ };
1968
+ function getTransformToElement(target, source) {
1969
+ try {
1970
+ return source.getScreenCTM().inverse().multiply(target.getScreenCTM());
1971
+ } catch {
1972
+ throw new Error("Unable to invert the source element's transformation matrix.");
1973
+ }
1974
+ }
1975
+ Matrix.getCTM = function(target, refer) {
1976
+ let ctm = {
1977
+ a: 1,
1978
+ b: 0,
1979
+ c: 0,
1980
+ d: 1,
1981
+ e: 0,
1982
+ f: 0
1983
+ };
1984
+ const node = target.shapeNode || target.node;
1985
+ refer = refer || "parent";
1986
+ switch (refer) {
1987
+ case "screen":
1988
+ ctm = node.getScreenCTM();
1989
+ break;
1990
+ case "doc":
1991
+ case "paper":
1992
+ ctm = node.getCTM();
1993
+ break;
1994
+ case "view":
1995
+ case "top":
1996
+ if (target.getPaper()) {
1997
+ ctm = getTransformToElement(node, target.getPaper().shapeNode);
1998
+ }
1999
+ break;
2000
+ case "parent":
2001
+ if (target.node.parentNode) {
2002
+ ctm = getTransformToElement(node, target.node.parentNode);
2003
+ }
2004
+ break;
2005
+ default:
2006
+ if (refer && refer.node) {
2007
+ ctm = getTransformToElement(node, refer.shapeNode || refer.node);
2008
+ }
2009
+ }
2010
+ return new Matrix(ctm.a, ctm.b, ctm.c, ctm.d, ctm.e, ctm.f);
2011
+ };
2012
+
2013
+ // src/kity/graphics.ts
2014
+ var pc = Point;
2015
+ var mc = Matrix;
2016
+ var _svgId = { id: 0 };
2017
+ var svg = {
2018
+ ns: "http://www.w3.org/2000/svg",
2019
+ xlink: "http://www.w3.org/1999/xlink",
2020
+ defaults: {
2021
+ stroke: "none",
2022
+ fill: "none"
2023
+ },
2024
+ createNode(name) {
2025
+ const node = document.createElementNS(svg.ns, name);
2026
+ node.id = "kity_" + name + "_" + _svgId.id++;
2027
+ return node;
2028
+ }
2029
+ };
2030
+ var INNER_HANDLER_CACHE = {};
2031
+ var USER_HANDLER_CACHE = {};
2032
+ var _guid = 0;
2033
+ function getEventUid(target) {
2034
+ const eventUid = target._EVENT_UID ?? target._EVNET_UID;
2035
+ if (eventUid === void 0) {
2036
+ throw new Error("Event handler instance is missing an event uid.");
2037
+ }
2038
+ return eventUid;
2039
+ }
2040
+ function setLegacyEventUid(target, eventUid) {
2041
+ target._EVENT_UID = eventUid;
2042
+ if (Object.prototype.hasOwnProperty.call(target, "_EVNET_UID")) {
2043
+ target._EVNET_UID = eventUid;
2044
+ return;
2045
+ }
2046
+ Object.defineProperty(target, "_EVNET_UID", {
2047
+ configurable: true,
2048
+ enumerable: true,
2049
+ get() {
2050
+ return target._EVENT_UID;
2051
+ },
2052
+ set(value) {
2053
+ target._EVENT_UID = value;
2054
+ }
2055
+ });
2056
+ }
2057
+ function bindDomEvent(node, type, handler) {
2058
+ node.addEventListener(type, handler, false);
2059
+ }
2060
+ function deleteDomEvent(node, type, handler) {
2061
+ node.removeEventListener(type, handler, false);
2062
+ }
2063
+ function sendMessage(messageObj, type, msg) {
2064
+ const handlers = INNER_HANDLER_CACHE[getEventUid(messageObj)];
2065
+ if (!handlers) {
2066
+ return;
2067
+ }
2068
+ const handler = handlers[type];
2069
+ if (!handler) {
2070
+ return;
2071
+ }
2072
+ const event = utils_default.extend({ type, target: messageObj }, msg || {});
2073
+ handler.call(messageObj, event);
2074
+ }
2075
+ function listen(node, type, handler, isOnce, targetObject) {
2076
+ const eid = getEventUid(targetObject);
2077
+ if (!INNER_HANDLER_CACHE[eid]) {
2078
+ INNER_HANDLER_CACHE[eid] = {};
2079
+ }
2080
+ if (!INNER_HANDLER_CACHE[eid][type]) {
2081
+ INNER_HANDLER_CACHE[eid][type] = function kityEventHandler(e) {
2082
+ e = new ShapeEvent(e || window.event);
2083
+ const list = USER_HANDLER_CACHE[eid][type];
2084
+ if (!list) {
2085
+ return;
2086
+ }
2087
+ for (let i = 0; i < list.length; i++) {
2088
+ const fn = list[i];
2089
+ if (fn) {
2090
+ const result = fn.call(targetObject, e);
2091
+ if (isOnce) {
2092
+ targetObject.off(type, fn);
2093
+ }
2094
+ if (result === false) {
2095
+ return false;
2096
+ }
2097
+ }
2098
+ }
2099
+ return;
2100
+ };
2101
+ }
2102
+ if (!USER_HANDLER_CACHE[eid]) {
2103
+ USER_HANDLER_CACHE[eid] = {};
2104
+ }
2105
+ if (!USER_HANDLER_CACHE[eid][type]) {
2106
+ USER_HANDLER_CACHE[eid][type] = [handler];
2107
+ if (!!node && "on" + type in node) {
2108
+ bindDomEvent(node, type, INNER_HANDLER_CACHE[eid][type]);
2109
+ }
2110
+ } else {
2111
+ USER_HANDLER_CACHE[eid][type].push(handler);
2112
+ }
2113
+ }
2114
+ function _addEvent(type, handler, isOnce) {
2115
+ isOnce = !!isOnce;
2116
+ if (utils_default.isString(type)) {
2117
+ type = type.match(/\S+/g) || [];
2118
+ }
2119
+ utils_default.each(type, (currentType) => {
2120
+ listen(this.node, currentType, handler, isOnce, this);
2121
+ });
2122
+ return this;
2123
+ }
2124
+ function _removeEvent(type, handler) {
2125
+ const eventId = String(getEventUid(this));
2126
+ const userHandlerList = USER_HANDLER_CACHE[eventId][type];
2127
+ let isRemoveAll = handler === void 0;
2128
+ if (!isRemoveAll && userHandlerList) {
2129
+ isRemoveAll = true;
2130
+ utils_default.each(userHandlerList, (fn, index) => {
2131
+ if (fn === handler) {
2132
+ delete userHandlerList[index];
2133
+ } else {
2134
+ isRemoveAll = false;
2135
+ }
2136
+ });
2137
+ }
2138
+ if (isRemoveAll) {
2139
+ deleteDomEvent(this.node, type, INNER_HANDLER_CACHE[eventId][type]);
2140
+ delete USER_HANDLER_CACHE[eventId][type];
2141
+ delete INNER_HANDLER_CACHE[eventId][type];
2142
+ }
2143
+ return this;
2144
+ }
2145
+ var EventHandler = createClass("EventHandler", {
2146
+ constructor() {
2147
+ setLegacyEventUid(this, ++_guid);
2148
+ },
2149
+ addEventListener(type, handler) {
2150
+ return _addEvent.call(this, type, handler, false);
2151
+ },
2152
+ addOnceEventListener(type, handler) {
2153
+ return _addEvent.call(this, type, handler, true);
2154
+ },
2155
+ removeEventListener(type, handler) {
2156
+ return _removeEvent.call(this, type, handler);
2157
+ },
2158
+ on(type, handler) {
2159
+ return this.addEventListener(type, handler);
2160
+ },
2161
+ once(type, handler) {
2162
+ return this.addOnceEventListener(type, handler);
2163
+ },
2164
+ off(type, handler) {
2165
+ return this.removeEventListener(type, handler);
2166
+ },
2167
+ fire(type, params) {
2168
+ return this.trigger(type, params);
2169
+ },
2170
+ trigger(type, params) {
2171
+ sendMessage(this, type, params);
2172
+ return this;
2173
+ }
2174
+ });
2175
+ var ShapeEvent = createClass("ShapeEvent", {
2176
+ constructor(event) {
2177
+ let target = null;
2178
+ if (!utils_default.isObject(event.target)) {
2179
+ this.type = event.type;
2180
+ target = event.target;
2181
+ if (target.correspondingUseElement) {
2182
+ target = target.correspondingUseElement;
2183
+ }
2184
+ this.originEvent = event;
2185
+ this.targetShape = target.shape || target.paper || event.currentTarget && (event.currentTarget.shape || event.currentTarget.paper);
2186
+ if (event._kityParam) {
2187
+ utils_default.extend(this, event._kityParam);
2188
+ }
2189
+ } else {
2190
+ utils_default.extend(this, event);
2191
+ }
2192
+ },
2193
+ preventDefault() {
2194
+ const evt = this.originEvent;
2195
+ if (!evt) {
2196
+ return true;
2197
+ }
2198
+ evt.preventDefault();
2199
+ return evt.cancelable;
2200
+ },
2201
+ getPosition(refer, touchIndex) {
2202
+ if (!this.originEvent) {
2203
+ return null;
2204
+ }
2205
+ const eventClient = this.originEvent.touches ? this.originEvent.touches[touchIndex || 0] : this.originEvent;
2206
+ const target = this.targetShape;
2207
+ const targetNode = target.shapeNode || target.node;
2208
+ const pScreen = new pc(
2209
+ eventClient && eventClient.clientX || 0,
2210
+ eventClient && eventClient.clientY || 0
2211
+ );
2212
+ const pTarget = mc.transformPoint(pScreen, targetNode.getScreenCTM().inverse());
2213
+ const pRefer = mc.getCTM(target, refer || "view").transformPoint(pTarget);
2214
+ return pRefer;
2215
+ },
2216
+ stopPropagation() {
2217
+ const evt = this.originEvent;
2218
+ if (!evt) {
2219
+ return true;
2220
+ }
2221
+ evt.stopPropagation();
2222
+ }
2223
+ });
2224
+ var _ClassListProto = {
2225
+ constructor(node) {
2226
+ this._node = node;
2227
+ this._list = node.className.toString().split(" ");
2228
+ },
2229
+ _update() {
2230
+ this._node.className = this._list.join(" ");
2231
+ },
2232
+ add(name) {
2233
+ this._list.push(name);
2234
+ this._update();
2235
+ },
2236
+ remove(name) {
2237
+ const index = this._list.indexOf(name);
2238
+ if (~index) {
2239
+ this._list.splice(index, 1);
2240
+ }
2241
+ this._update();
2242
+ },
2243
+ contains(name) {
2244
+ return !!~this._list.indexOf(name);
2245
+ }
2246
+ };
2247
+ function _getClassList(node) {
2248
+ if (!node.classList) {
2249
+ node.classList = new (createClass("ClassList", _ClassListProto))(node);
2250
+ }
2251
+ return node.classList;
2252
+ }
2253
+ var Styled = createClass("Styled", {
2254
+ addClass(name) {
2255
+ _getClassList(this.node).add(name);
2256
+ return this;
2257
+ },
2258
+ removeClass(name) {
2259
+ _getClassList(this.node).remove(name);
2260
+ return this;
2261
+ },
2262
+ hasClass(name) {
2263
+ return _getClassList(this.node).contains(name);
2264
+ },
2265
+ setStyle(styleOrName, value) {
2266
+ if (arguments.length === 2 && typeof styleOrName === "string") {
2267
+ this.node.style[styleOrName] = value;
2268
+ return this;
2269
+ }
2270
+ if (typeof styleOrName === "object") {
2271
+ for (const name in styleOrName) {
2272
+ if (Object.prototype.hasOwnProperty.call(styleOrName, name)) {
2273
+ this.node.style[name] = styleOrName[name];
2274
+ }
2275
+ }
2276
+ }
2277
+ return this;
2278
+ }
2279
+ });
2280
+ var Data = createClass("Data", {
2281
+ constructor() {
2282
+ this._data = {};
2283
+ },
2284
+ setData(name, value) {
2285
+ this._data[name] = value;
2286
+ return this;
2287
+ },
2288
+ getData(name) {
2289
+ return this._data[name];
2290
+ },
2291
+ removeData(name) {
2292
+ delete this._data[name];
2293
+ return this;
2294
+ }
2295
+ });
2296
+ function itemRemove() {
2297
+ this.container.removeItem(this);
2298
+ return this;
2299
+ }
2300
+ var Container = createClass("Container", {
2301
+ getItems() {
2302
+ return this.items || (this.items = []);
2303
+ },
2304
+ getItem(index) {
2305
+ return this.getItems()[index];
2306
+ },
2307
+ getFirstItem() {
2308
+ return this.getItem(0);
2309
+ },
2310
+ getLastItem() {
2311
+ return this.getItem(this.getItems().length - 1);
2312
+ },
2313
+ indexOf(item) {
2314
+ return this.getItems().indexOf(item);
2315
+ },
2316
+ eachItem(fn) {
2317
+ const items = this.getItems();
2318
+ for (let i = 0; i < items.length; i++) {
2319
+ fn.call(this, i, items[i]);
2320
+ }
2321
+ return this;
2322
+ },
2323
+ addItem(item, pos, noEvent) {
2324
+ const items = this.getItems();
2325
+ const length = items.length;
2326
+ if (~items.indexOf(item)) {
2327
+ return this;
2328
+ }
2329
+ if (!(pos >= 0 && pos < length)) {
2330
+ pos = length;
2331
+ }
2332
+ items.splice(pos, 0, item);
2333
+ if (typeof item === "object") {
2334
+ item.container = this;
2335
+ item.remove = itemRemove;
2336
+ }
2337
+ this.handleAdd(item, pos);
2338
+ if (!noEvent) {
2339
+ this.onContainerChanged("add", [item]);
2340
+ }
2341
+ return this;
2342
+ },
2343
+ addItems(items) {
2344
+ for (let i = 0, l = items.length; i < l; i++) {
2345
+ this.addItem(items[i], -1, true);
2346
+ }
2347
+ this.onContainerChanged("add", items);
2348
+ return this;
2349
+ },
2350
+ setItems(items) {
2351
+ return this.clear().addItems(items);
2352
+ },
2353
+ appendItem(item) {
2354
+ return this.addItem(item);
2355
+ },
2356
+ prependItem(item) {
2357
+ return this.addItem(item, 0);
2358
+ },
2359
+ removeItem(pos, noEvent) {
2360
+ if (typeof pos !== "number") {
2361
+ return this.removeItem(this.indexOf(pos));
2362
+ }
2363
+ const items = this.getItems();
2364
+ const item = items[pos];
2365
+ if (item === void 0) {
2366
+ return this;
2367
+ }
2368
+ items.splice(pos, 1);
2369
+ if (item.container) {
2370
+ delete item.container;
2371
+ }
2372
+ if (item.remove) {
2373
+ delete item.remove;
2374
+ }
2375
+ this.handleRemove(item, pos);
2376
+ if (!noEvent) {
2377
+ this.onContainerChanged("remove", [item]);
2378
+ }
2379
+ return this;
2380
+ },
2381
+ clear() {
2382
+ const removed = [];
2383
+ let item;
2384
+ while ((item = this.getFirstItem()) !== void 0) {
2385
+ removed.push(item);
2386
+ this.removeItem(0, true);
2387
+ }
2388
+ this.onContainerChanged("remove", removed);
2389
+ return this;
2390
+ },
2391
+ onContainerChanged(_type, _items) {
2392
+ },
2393
+ handleAdd(_item, _index) {
2394
+ },
2395
+ handleRemove(_item, _index) {
2396
+ }
2397
+ });
2398
+ var Shape = createClass("Shape", {
2399
+ mixins: [EventHandler, Styled, Data],
2400
+ constructor(tagName) {
2401
+ this.node = svg.createNode(tagName);
2402
+ this.node.shape = this;
2403
+ this.transform = {
2404
+ translate: null,
2405
+ rotate: null,
2406
+ scale: null,
2407
+ matrix: null
2408
+ };
2409
+ this.callMixin();
2410
+ },
2411
+ getId() {
2412
+ return this.node.id;
2413
+ },
2414
+ setId(id) {
2415
+ this.node.id = id;
2416
+ return this;
2417
+ },
2418
+ getNode() {
2419
+ return this.node;
2420
+ },
2421
+ getBoundaryBox() {
2422
+ let box;
2423
+ try {
2424
+ box = this.node.getBBox();
2425
+ } catch {
2426
+ box = {
2427
+ x: this.node.clientLeft,
2428
+ y: this.node.clientTop,
2429
+ width: this.node.clientWidth,
2430
+ height: this.node.clientHeight
2431
+ };
2432
+ }
2433
+ return new Box(box);
2434
+ },
2435
+ getRenderBox(refer) {
2436
+ const box = this.getBoundaryBox();
2437
+ const matrix = this.getTransform(refer);
2438
+ return matrix.transformBox(box);
2439
+ },
2440
+ getWidth() {
2441
+ return this.getRenderBox().width;
2442
+ },
2443
+ getHeight() {
2444
+ return this.getRenderBox().height;
2445
+ },
2446
+ getSize() {
2447
+ const box = this.getRenderBox();
2448
+ delete box.x;
2449
+ delete box.y;
2450
+ return box;
2451
+ },
2452
+ setOpacity(value) {
2453
+ this.node.setAttribute("opacity", String(value));
2454
+ return this;
2455
+ },
2456
+ getOpacity() {
2457
+ const opacity = this.node.getAttribute("opacity");
2458
+ return opacity ? +opacity : 1;
2459
+ },
2460
+ setVisible(value) {
2461
+ if (value) {
2462
+ this.node.removeAttribute("display");
2463
+ } else {
2464
+ this.node.setAttribute("display", "none");
2465
+ }
2466
+ return this;
2467
+ },
2468
+ getVisible() {
2469
+ this.node.getAttribute("display");
2470
+ },
2471
+ hasAncestor(node) {
2472
+ let parent = this.container;
2473
+ while (parent) {
2474
+ if (parent === node) {
2475
+ return true;
2476
+ }
2477
+ parent = parent.container;
2478
+ }
2479
+ return false;
2480
+ },
2481
+ getTransform(refer) {
2482
+ return mc.getCTM(this, refer);
2483
+ },
2484
+ clearTransform() {
2485
+ this.node.removeAttribute("transform");
2486
+ this.transform = {
2487
+ translate: null,
2488
+ rotate: null,
2489
+ scale: null,
2490
+ matrix: null
2491
+ };
2492
+ this.trigger("shapeupdate", {
2493
+ type: "transform"
2494
+ });
2495
+ return this;
2496
+ },
2497
+ _applyTransform() {
2498
+ const t = this.transform;
2499
+ const result = [];
2500
+ if (t.translate) {
2501
+ result.push(["translate(", t.translate, ")"]);
2502
+ }
2503
+ if (t.rotate) {
2504
+ result.push(["rotate(", t.rotate, ")"]);
2505
+ }
2506
+ if (t.scale) {
2507
+ result.push(["scale(", t.scale, ")"]);
2508
+ }
2509
+ if (t.matrix) {
2510
+ result.push(["matrix(", t.matrix, ")"]);
2511
+ }
2512
+ this.node.setAttribute("transform", utils_default.flatten(result).join(" "));
2513
+ return this;
2514
+ },
2515
+ setMatrix(m) {
2516
+ this.transform.matrix = m;
2517
+ return this._applyTransform();
2518
+ },
2519
+ setTranslate(t) {
2520
+ this.transform.translate = t !== null && [].slice.call(arguments) || null;
2521
+ return this._applyTransform();
2522
+ },
2523
+ setRotate(r) {
2524
+ this.transform.rotate = r !== null && [].slice.call(arguments) || null;
2525
+ return this._applyTransform();
2526
+ },
2527
+ setScale(s) {
2528
+ this.transform.scale = s !== null && [].slice.call(arguments) || null;
2529
+ return this._applyTransform();
2530
+ },
2531
+ translate(dx, dy) {
2532
+ let m = this.transform.matrix || new mc();
2533
+ if (dy === void 0) {
2534
+ dy = 0;
2535
+ }
2536
+ this.transform.matrix = m.translate(dx, dy);
2537
+ return this._applyTransform();
2538
+ },
2539
+ rotate(deg) {
2540
+ let m = this.transform.matrix || new mc();
2541
+ this.transform.matrix = m.rotate(deg);
2542
+ return this._applyTransform();
2543
+ },
2544
+ scale(sx, sy) {
2545
+ let m = this.transform.matrix || new mc();
2546
+ if (sy === void 0) {
2547
+ sy = sx;
2548
+ }
2549
+ this.transform.matrix = m.scale(sx, sy);
2550
+ return this._applyTransform();
2551
+ },
2552
+ skew(sx, sy) {
2553
+ let m = this.transform.matrix || new mc();
2554
+ if (sy === void 0) {
2555
+ sy = sx;
2556
+ }
2557
+ this.transform.matrix = m.skew(sx, sy);
2558
+ return this._applyTransform();
2559
+ },
2560
+ stroke(pen, width) {
2561
+ if (pen && pen.stroke) {
2562
+ pen.stroke(this);
2563
+ } else if (pen) {
2564
+ this.node.setAttribute("stroke", pen.toString());
2565
+ if (width) {
2566
+ this.node.setAttribute("stroke-width", String(width));
2567
+ }
2568
+ } else if (pen === null) {
2569
+ this.node.removeAttribute("stroke");
2570
+ }
2571
+ return this;
2572
+ },
2573
+ fill(brush) {
2574
+ if (brush) {
2575
+ this.node.setAttribute("fill", brush.toString());
2576
+ }
2577
+ if (brush === null) {
2578
+ this.node.removeAttribute("fill");
2579
+ }
2580
+ return this;
2581
+ },
2582
+ setAttr(a, v) {
2583
+ if (utils_default.isObject(a)) {
2584
+ utils_default.each(a, (val, key) => {
2585
+ this.setAttr(key, val);
2586
+ });
2587
+ return this;
2588
+ }
2589
+ if (v === void 0 || v === null || v === "") {
2590
+ this.node.removeAttribute(a);
2591
+ } else {
2592
+ this.node.setAttribute(a, v);
2593
+ }
2594
+ return this;
2595
+ },
2596
+ getAttr(a) {
2597
+ return this.node.getAttribute(a);
2598
+ }
2599
+ });
2600
+ var ShapeContainer = createClass("ShapeContainer", {
2601
+ base: Container,
2602
+ isShapeContainer: true,
2603
+ handleAdd(shape, index) {
2604
+ const parent = this.getShapeNode();
2605
+ parent.insertBefore(shape.node, parent.childNodes[index] || null);
2606
+ shape.trigger("add", { container: this });
2607
+ if (shape.notifyTreeModification) {
2608
+ shape.notifyTreeModification("treeadd", this);
2609
+ }
2610
+ },
2611
+ handleRemove(shape, _index) {
2612
+ const parent = this.getShapeNode();
2613
+ parent.removeChild(shape.node);
2614
+ shape.trigger("remove", {
2615
+ container: this
2616
+ });
2617
+ if (shape.notifyTreeModification) {
2618
+ shape.notifyTreeModification("treeremove", this);
2619
+ }
2620
+ },
2621
+ notifyTreeModification(type, container) {
2622
+ this.eachItem((_index, shape) => {
2623
+ if (shape.notifyTreeModification) {
2624
+ shape.notifyTreeModification(type, container);
2625
+ }
2626
+ shape.trigger(type, { container });
2627
+ });
2628
+ },
2629
+ getShape(index) {
2630
+ return this.getItem(index);
2631
+ },
2632
+ addShape(shape, index) {
2633
+ return this.addItem(shape, index);
2634
+ },
2635
+ put(shape) {
2636
+ this.addShape(shape);
2637
+ return shape;
2638
+ },
2639
+ appendShape(shape) {
2640
+ return this.addShape(shape);
2641
+ },
2642
+ prependShape(shape) {
2643
+ return this.addShape(shape, 0);
2644
+ },
2645
+ replaceShape(replacer, origin) {
2646
+ const index = this.indexOf(origin);
2647
+ if (index === -1) {
2648
+ return;
2649
+ }
2650
+ this.removeShape(index);
2651
+ this.addShape(replacer, index);
2652
+ return this;
2653
+ },
2654
+ addShapeBefore(shape, refer) {
2655
+ const index = this.indexOf(refer);
2656
+ return this.addShape(shape, index);
2657
+ },
2658
+ addShapeAfter(shape, refer) {
2659
+ const index = this.indexOf(refer);
2660
+ return this.addShape(shape, index === -1 ? void 0 : index + 1);
2661
+ },
2662
+ addShapes(shapes) {
2663
+ return this.addItems(shapes);
2664
+ },
2665
+ removeShape(index) {
2666
+ return this.removeItem(index);
2667
+ },
2668
+ getShapes() {
2669
+ return this.getItems();
2670
+ },
2671
+ getShapesByType(name) {
2672
+ const shapes = [];
2673
+ const getShapes = (shape) => {
2674
+ if (name.toLowerCase() === shape.getType().toLowerCase()) {
2675
+ shapes.push(shape);
2676
+ }
2677
+ if (shape.isShapeContainer) {
2678
+ utils_default.each(shape.getShapes(), (n) => {
2679
+ getShapes(n);
2680
+ });
2681
+ }
2682
+ };
2683
+ getShapes(this);
2684
+ return shapes;
2685
+ },
2686
+ getShapeById(id) {
2687
+ return this.getShapeNode().getElementById(id).shape;
2688
+ },
2689
+ arrangeShape(shape, index) {
2690
+ return this.removeShape(shape).addShape(shape, index);
2691
+ },
2692
+ getShapeNode() {
2693
+ return this.shapeNode || this.node;
2694
+ }
2695
+ });
2696
+ extendClass(Shape, {
2697
+ bringTo(index) {
2698
+ this.container.arrangeShape(this, index);
2699
+ return this;
2700
+ },
2701
+ bringFront() {
2702
+ return this.bringTo(this.container.indexOf(this) + 1);
2703
+ },
2704
+ bringBack() {
2705
+ return this.bringTo(this.container.indexOf(this) - 1);
2706
+ },
2707
+ bringTop() {
2708
+ this.container.removeShape(this).addShape(this);
2709
+ return this;
2710
+ },
2711
+ bringRear() {
2712
+ return this.bringTo(0);
2713
+ },
2714
+ bringRefer(referShape, offset) {
2715
+ if (referShape.container) {
2716
+ if (this.remove) {
2717
+ this.remove();
2718
+ }
2719
+ referShape.container.addShape(this, referShape.container.indexOf(referShape) + (offset || 0));
2720
+ }
2721
+ return this;
2722
+ },
2723
+ bringAbove(referShape) {
2724
+ return this.bringRefer(referShape);
2725
+ },
2726
+ bringBelow(referShape) {
2727
+ return this.bringRefer(referShape, 1);
2728
+ },
2729
+ replaceBy(newShape) {
2730
+ if (this.container) {
2731
+ newShape.bringAbove(this);
2732
+ this.remove();
2733
+ }
2734
+ return this;
2735
+ }
2736
+ });
2737
+ var ViewBox = createClass("ViewBox", {
2738
+ getViewBox() {
2739
+ const attr = this.node.getAttribute("viewBox");
2740
+ if (attr === null) {
2741
+ return {
2742
+ x: 0,
2743
+ y: 0,
2744
+ width: this.node.clientWidth || this.node.parentNode?.clientWidth || 0,
2745
+ height: this.node.clientHeight || this.node.parentNode?.clientHeight || 0
2746
+ };
2747
+ } else {
2748
+ const parts = attr.split(" ");
2749
+ return {
2750
+ x: +parts[0],
2751
+ y: +parts[1],
2752
+ width: +parts[2],
2753
+ height: +parts[3]
2754
+ };
2755
+ }
2756
+ },
2757
+ setViewBox(x, y, width, height) {
2758
+ this.node.setAttribute("viewBox", [x, y, width, height].join(" "));
2759
+ return this;
2760
+ }
2761
+ });
2762
+ var TextContent = createClass("TextContent", {
2763
+ base: Shape,
2764
+ constructor(nodeType) {
2765
+ this.callBase(nodeType);
2766
+ this.shapeNode = this.shapeNode || this.node;
2767
+ this.shapeNode.setAttribute("text-rendering", "geometricPrecision");
2768
+ },
2769
+ clearContent() {
2770
+ while (this.shapeNode.firstChild) {
2771
+ this.shapeNode.removeChild(this.shapeNode.firstChild);
2772
+ }
2773
+ return this;
2774
+ },
2775
+ setContent(content) {
2776
+ this.shapeNode.textContent = content;
2777
+ return this;
2778
+ },
2779
+ getContent() {
2780
+ return this.shapeNode.textContent;
2781
+ },
2782
+ appendContent(content) {
2783
+ this.shapeNode.textContent += content;
2784
+ return this;
2785
+ },
2786
+ setSize(value) {
2787
+ return this.setFontSize(value);
2788
+ },
2789
+ setFontSize(value) {
2790
+ return this.setFont({
2791
+ size: value
2792
+ });
2793
+ },
2794
+ setFontFamily(value) {
2795
+ return this.setFont({
2796
+ family: value
2797
+ });
2798
+ },
2799
+ setFontBold(bold) {
2800
+ return this.setFont({
2801
+ weight: bold ? "bold" : "normal"
2802
+ });
2803
+ },
2804
+ setFontItalic(italic) {
2805
+ return this.setFont({
2806
+ style: italic ? "italic" : "normal"
2807
+ });
2808
+ },
2809
+ setFont(font) {
2810
+ const node = this.node;
2811
+ ["family", "size", "weight", "style"].forEach((section) => {
2812
+ if (font[section] === null) {
2813
+ node.removeAttribute("font-" + section);
2814
+ } else if (font[section]) {
2815
+ node.setAttribute("font-" + section, font[section]);
2816
+ }
2817
+ });
2818
+ return this;
2819
+ },
2820
+ getExtentOfChar(index) {
2821
+ return this.node.getExtentOfChar(index);
2822
+ },
2823
+ getRotationOfChar(index) {
2824
+ return this.node.getRotationOfChar(index);
2825
+ },
2826
+ getCharNumAtPosition(x, y) {
2827
+ return this.node.getCharNumAtPosition({ x, y });
2828
+ }
2829
+ });
2830
+ var _offsetHash = {};
2831
+ function _getTextBoundOffset(text) {
2832
+ const font = text._cachedFontHash;
2833
+ if (_offsetHash[font]) {
2834
+ return _offsetHash[font];
2835
+ }
2836
+ const textContent = text.getContent();
2837
+ text.setContent("\u767E\u5EA6Fex");
2838
+ const bbox = text.getBoundaryBox();
2839
+ const y = text.getY();
2840
+ if (!bbox.height) {
2841
+ return { top: 0, bottom: 0, middle: 0 };
2842
+ }
2843
+ const topOffset = y - bbox.y + +text.node.getAttribute("dy");
2844
+ const bottomOffset = topOffset - bbox.height;
2845
+ text.setContent(textContent);
2846
+ _offsetHash[font] = {
2847
+ top: topOffset,
2848
+ bottom: bottomOffset,
2849
+ middle: (topOffset + bottomOffset) / 2
2850
+ };
2851
+ return _offsetHash[font];
2852
+ }
2853
+ var Text = createClass("Text", {
2854
+ base: TextContent,
2855
+ mixins: [ShapeContainer],
2856
+ constructor(content) {
2857
+ this.callBase("text");
2858
+ if (content !== void 0) {
2859
+ this.setContent(content);
2860
+ }
2861
+ this._buildFontHash();
2862
+ },
2863
+ fixPosition() {
2864
+ if (!this.__fixedPosition) {
2865
+ this.setVerticalAlign(this.getVerticalAlign());
2866
+ }
2867
+ },
2868
+ _buildFontHash() {
2869
+ const style = window.getComputedStyle(this.node);
2870
+ this._cachedFontHash = [
2871
+ style.fontFamily,
2872
+ style.fontSize,
2873
+ style.fontStretch,
2874
+ style.fontStyle,
2875
+ style.fontVariant,
2876
+ style.fontWeight
2877
+ ].join("-");
2878
+ },
2879
+ _fontChanged(font) {
2880
+ const last = this._lastFont;
2881
+ const current = utils_default.extend({}, last, font);
2882
+ if (!last) {
2883
+ this._lastFont = font;
2884
+ return true;
2885
+ }
2886
+ const changed = last.family !== current.family || last.size !== current.size || last.style !== current.style || last.weight !== current.weight;
2887
+ this._lastFont = current;
2888
+ return changed;
2889
+ },
2890
+ setX(x) {
2891
+ this.node.setAttribute("x", String(x));
2892
+ return this;
2893
+ },
2894
+ setPosition(x, y) {
2895
+ return this.setX(x).setY(y);
2896
+ },
2897
+ setY(y) {
2898
+ this.node.setAttribute("y", String(y));
2899
+ return this;
2900
+ },
2901
+ getX() {
2902
+ return +(this.node.getAttribute("x") || "0");
2903
+ },
2904
+ getY() {
2905
+ return +(this.node.getAttribute("y") || "0");
2906
+ },
2907
+ setFont(font) {
2908
+ this.callBase(font);
2909
+ if (this._fontChanged(font)) {
2910
+ this._buildFontHash();
2911
+ this.setVerticalAlign(this.getVerticalAlign());
2912
+ }
2913
+ return this;
2914
+ },
2915
+ setTextAnchor(anchor) {
2916
+ this.node.setAttribute("text-anchor", anchor);
2917
+ return this;
2918
+ },
2919
+ getTextAnchor() {
2920
+ return this.node.getAttribute("text-anchor") || "start";
2921
+ },
2922
+ setVerticalAlign(align) {
2923
+ this.whenPaperReady(() => {
2924
+ let dy;
2925
+ switch (align) {
2926
+ case "top":
2927
+ dy = _getTextBoundOffset(this).top;
2928
+ break;
2929
+ case "bottom":
2930
+ dy = _getTextBoundOffset(this).bottom;
2931
+ break;
2932
+ case "middle":
2933
+ dy = _getTextBoundOffset(this).middle;
2934
+ break;
2935
+ default:
2936
+ dy = 0;
2937
+ }
2938
+ if (dy) {
2939
+ this.__fixedPosition = true;
2940
+ }
2941
+ this.node.setAttribute("dy", dy);
2942
+ });
2943
+ this.verticalAlign = align;
2944
+ return this;
2945
+ },
2946
+ getVerticalAlign() {
2947
+ return this.verticalAlign || "baseline";
2948
+ },
2949
+ setStartOffset(offset) {
2950
+ if (this.shapeNode !== this.node) {
2951
+ this.shapeNode.setAttribute("startOffset", offset * 100 + "%");
2952
+ }
2953
+ },
2954
+ addSpan(span) {
2955
+ this.addShape(span);
2956
+ return this;
2957
+ },
2958
+ setPath(path) {
2959
+ let textpath = this.shapeNode;
2960
+ if (this.shapeNode === this.node) {
2961
+ textpath = this.shapeNode = svg.createNode("textPath");
2962
+ while (this.node.firstChild) {
2963
+ this.shapeNode.appendChild(this.node.firstChild);
2964
+ }
2965
+ this.node.appendChild(textpath);
2966
+ }
2967
+ textpath.setAttributeNS(svg.xlink, "xlink:href", "#" + path.node.id);
2968
+ this.setTextAnchor(this.getTextAnchor());
2969
+ return this;
2970
+ }
2971
+ });
2972
+ var PathDrawer = createClass("PathDrawer", {
2973
+ constructor(path) {
2974
+ this.segment = [];
2975
+ this.path = path;
2976
+ this.__clear = false;
2977
+ },
2978
+ getPath() {
2979
+ return this.path;
2980
+ },
2981
+ redraw() {
2982
+ this._transation = this._transation || [];
2983
+ return this.clear();
2984
+ },
2985
+ done() {
2986
+ const transation = this._transation;
2987
+ this._transation = null;
2988
+ this.push(transation);
2989
+ return this;
2990
+ },
2991
+ clear() {
2992
+ if (this._transation) {
2993
+ this._transation = [];
2994
+ } else {
2995
+ this.path.setPathData("M 0 0");
2996
+ }
2997
+ this._clear = true;
2998
+ return this;
2999
+ },
3000
+ push() {
3001
+ const segment = [].slice.call(arguments);
3002
+ let originData;
3003
+ if (this._transation) {
3004
+ this._transation.push(segment);
3005
+ return this;
3006
+ }
3007
+ if (this._clear) {
3008
+ originData = "";
3009
+ this._clear = false;
3010
+ } else {
3011
+ originData = this.path.getPathData();
3012
+ }
3013
+ originData = originData || "";
3014
+ this.path.setPathData(originData + g.pathToString(segment));
3015
+ return this;
3016
+ },
3017
+ moveTo(_x, _y) {
3018
+ return this.push("M", [].slice.call(arguments));
3019
+ },
3020
+ moveBy(_dx, _dy) {
3021
+ return this.push("m", [].slice.call(arguments));
3022
+ },
3023
+ lineTo(_x, _y) {
3024
+ return this.push("L", [].slice.call(arguments));
3025
+ },
3026
+ lineBy(_dx, _dy) {
3027
+ return this.push("l", [].slice.call(arguments));
3028
+ },
3029
+ arcTo(_rx, _ry, _xr, _laf, _sf, _x, _y) {
3030
+ return this.push("A", [].slice.call(arguments));
3031
+ },
3032
+ arcBy(_rx, _ry, _xr, _laf, _sf, _dx, _dy) {
3033
+ return this.push("a", arguments);
3034
+ },
3035
+ carcTo(r, _laf, _sf, _x, _y) {
3036
+ return this.push("A", [r, r, 0].concat([].slice.call(arguments, 1)));
3037
+ },
3038
+ carcBy(r, _laf, _sf, _dx, _dy) {
3039
+ return this.push("a", [r, r, 0].concat([].slice.call(arguments, 1)));
3040
+ },
3041
+ bezierTo(_x1, _y1, _x2, _y2, _x, _y) {
3042
+ return this.push("C", [].slice.call(arguments));
3043
+ },
3044
+ bezierBy(_dx1, _dy1, _dx2, _dy2, _dx, _dy) {
3045
+ return this.push("c", [].slice.call(arguments));
3046
+ },
3047
+ close() {
3048
+ return this.push("z");
3049
+ }
3050
+ });
3051
+ var Path = createClass("Path", {
3052
+ base: Shape,
3053
+ constructor(data) {
3054
+ this.callBase("path");
3055
+ if (data) {
3056
+ this.setPathData(data);
3057
+ }
3058
+ this.node.setAttribute("fill", svg.defaults.fill);
3059
+ this.node.setAttribute("stroke", svg.defaults.stroke);
3060
+ },
3061
+ setPathData(data) {
3062
+ data = data || "M0,0";
3063
+ this.pathdata = g.pathToString(data);
3064
+ this.node.setAttribute("d", this.pathdata);
3065
+ this.trigger("shapeupdate", {
3066
+ type: "pathdata"
3067
+ });
3068
+ return this;
3069
+ },
3070
+ getPathData() {
3071
+ return this.pathdata || "";
3072
+ },
3073
+ getDrawer() {
3074
+ return new PathDrawer(this);
3075
+ },
3076
+ isClosed() {
3077
+ const data = this.getPathData();
3078
+ return !!~data.indexOf("z") || !!~data.indexOf("Z");
3079
+ }
3080
+ });
3081
+ var RectUtils = {
3082
+ formatRadius(width, height, radius) {
3083
+ const minValue = Math.floor(Math.min(width / 2, height / 2));
3084
+ return Math.min(minValue, radius);
3085
+ }
3086
+ };
3087
+ var Rect = createClass("Rect", {
3088
+ base: Path,
3089
+ constructor(width, height, x, y, radius) {
3090
+ this.callBase();
3091
+ this.x = x || 0;
3092
+ this.y = y || 0;
3093
+ this.width = width || 0;
3094
+ this.height = height || 0;
3095
+ this.radius = RectUtils.formatRadius(this.width, this.height, radius || 0);
3096
+ this.update();
3097
+ },
3098
+ update() {
3099
+ const x = this.x, y = this.y, w = this.width, h = this.height, r = this.radius;
3100
+ const drawer = this.getDrawer().redraw();
3101
+ if (!r) {
3102
+ drawer.push("M", x, y);
3103
+ drawer.push("h", w);
3104
+ drawer.push("v", h);
3105
+ drawer.push("h", -w);
3106
+ drawer.push("z");
3107
+ } else {
3108
+ const w2 = w - 2 * r;
3109
+ const h2 = h - 2 * r;
3110
+ drawer.push("M", x + r, y);
3111
+ drawer.push("h", w2);
3112
+ drawer.push("a", r, r, 0, 0, 1, r, r);
3113
+ drawer.push("v", h2);
3114
+ drawer.push("a", r, r, 0, 0, 1, -r, r);
3115
+ drawer.push("h", -w2);
3116
+ drawer.push("a", r, r, 0, 0, 1, -r, -r);
3117
+ drawer.push("v", -h2);
3118
+ drawer.push("a", r, r, 0, 0, 1, r, -r);
3119
+ drawer.push("z");
3120
+ }
3121
+ drawer.done();
3122
+ return this;
3123
+ },
3124
+ setWidth(width) {
3125
+ this.width = width;
3126
+ return this.update();
3127
+ },
3128
+ setHeight(height) {
3129
+ this.height = height;
3130
+ return this.update();
3131
+ },
3132
+ setSize(width, height) {
3133
+ this.width = width;
3134
+ this.height = height;
3135
+ return this.update();
3136
+ },
3137
+ setBox(box) {
3138
+ this.x = box.x;
3139
+ this.y = box.y;
3140
+ this.width = box.width;
3141
+ this.height = box.height;
3142
+ return this.update();
3143
+ },
3144
+ getBox() {
3145
+ return new Box(this.x, this.y, this.width, this.height);
3146
+ },
3147
+ getRadius() {
3148
+ return this.radius;
3149
+ },
3150
+ setRadius(radius) {
3151
+ this.radius = RectUtils.formatRadius(this.width, this.height, radius || 0);
3152
+ return this.update();
3153
+ },
3154
+ getPosition() {
3155
+ return new pc(this.x, this.y);
3156
+ },
3157
+ setPosition(xOrP, y) {
3158
+ if (arguments.length === 1) {
3159
+ const p = pc.parse(arguments[0]);
3160
+ y = p.y;
3161
+ xOrP = p.x;
3162
+ }
3163
+ this.x = xOrP;
3164
+ this.y = y;
3165
+ return this.update();
3166
+ },
3167
+ getWidth() {
3168
+ return this.width;
3169
+ },
3170
+ getHeight() {
3171
+ return this.height;
3172
+ },
3173
+ getPositionX() {
3174
+ return this.x;
3175
+ },
3176
+ getPositionY() {
3177
+ return this.y;
3178
+ },
3179
+ setPositionX(x) {
3180
+ this.x = x;
3181
+ return this.update();
3182
+ },
3183
+ setPositionY(y) {
3184
+ this.y = y;
3185
+ return this.update();
3186
+ }
3187
+ });
3188
+ var Group = createClass("Group", {
3189
+ mixins: [ShapeContainer],
3190
+ base: Shape,
3191
+ constructor() {
3192
+ this.callBase("g");
3193
+ }
3194
+ });
3195
+ var Use = createClass("Use", {
3196
+ base: Shape,
3197
+ constructor(shape) {
3198
+ this.callBase("use");
3199
+ this.ref(shape);
3200
+ },
3201
+ ref(shape) {
3202
+ if (!shape) {
3203
+ this.node.removeAttributeNS(svg.xlink, "xlink:href");
3204
+ return this;
3205
+ }
3206
+ const shapeId = shape.getId();
3207
+ if (shapeId) {
3208
+ this.node.setAttributeNS(svg.xlink, "xlink:href", "#" + shapeId);
3209
+ }
3210
+ if (shape.node.getAttribute("fill") === "none") {
3211
+ shape.node.removeAttribute("fill");
3212
+ }
3213
+ if (shape.node.getAttribute("stroke") === "none") {
3214
+ shape.node.removeAttribute("stroke");
3215
+ }
3216
+ return this;
3217
+ }
3218
+ });
3219
+ extendClass(Shape, {
3220
+ use() {
3221
+ return new Use(this);
3222
+ }
3223
+ });
3224
+ var Paper = createClass("Paper", {
3225
+ mixins: [ShapeContainer, EventHandler, Styled, ViewBox],
3226
+ constructor(container) {
3227
+ this.callBase();
3228
+ this.node = this.createSVGNode();
3229
+ this.node.paper = this;
3230
+ this.node.appendChild(this.resourceNode = svg.createNode("defs"));
3231
+ this.node.appendChild(this.shapeNode = svg.createNode("g"));
3232
+ this.resources = new Container();
3233
+ this.setWidth("100%").setHeight("100%");
3234
+ if (container) {
3235
+ this.renderTo(container);
3236
+ }
3237
+ this.callMixin();
3238
+ },
3239
+ renderTo(container) {
3240
+ if (utils_default.isString(container)) {
3241
+ container = document.getElementById(container);
3242
+ }
3243
+ this.container = container;
3244
+ container.appendChild(this.node);
3245
+ },
3246
+ createSVGNode() {
3247
+ const node = svg.createNode("svg");
3248
+ node.setAttribute("xmlns", "http://www.w3.org/2000/svg");
3249
+ node.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
3250
+ node.setAttribute("version", "1.1");
3251
+ return node;
3252
+ },
3253
+ getNode() {
3254
+ return this.node;
3255
+ },
3256
+ getContainer() {
3257
+ return this.container;
3258
+ },
3259
+ getWidth() {
3260
+ return this.node.clientWidth;
3261
+ },
3262
+ setWidth(width) {
3263
+ this.node.setAttribute("width", String(width));
3264
+ return this;
3265
+ },
3266
+ getHeight() {
3267
+ return this.node.clientHeight;
3268
+ },
3269
+ setHeight(height) {
3270
+ this.node.setAttribute("height", String(height));
3271
+ return this;
3272
+ },
3273
+ setViewPort(cx, cy, zoom) {
3274
+ let viewport, box;
3275
+ if (arguments.length === 1) {
3276
+ viewport = arguments[0];
3277
+ cx = viewport.center.x;
3278
+ cy = viewport.center.y;
3279
+ zoom = viewport.zoom;
3280
+ }
3281
+ zoom = zoom || 1;
3282
+ box = this.getViewBox();
3283
+ const matrix = new mc();
3284
+ const dx = box.x + box.width / 2 - cx;
3285
+ const dy = box.y + box.height / 2 - cy;
3286
+ matrix.translate(-cx, -cy);
3287
+ matrix.scale(zoom);
3288
+ matrix.translate(cx, cy);
3289
+ matrix.translate(dx, dy);
3290
+ this.shapeNode.setAttribute("transform", "matrix(" + matrix + ")");
3291
+ this.viewport = {
3292
+ center: { x: cx, y: cy },
3293
+ offset: { x: dx, y: dy },
3294
+ zoom
3295
+ };
3296
+ return this;
3297
+ },
3298
+ getViewPort() {
3299
+ if (!this.viewport) {
3300
+ const box = this.getViewBox();
3301
+ return {
3302
+ zoom: 1,
3303
+ center: {
3304
+ x: box.x + box.width / 2,
3305
+ y: box.y + box.height / 2
3306
+ },
3307
+ offset: { x: 0, y: 0 }
3308
+ };
3309
+ }
3310
+ return this.viewport;
3311
+ },
3312
+ getViewPortMatrix() {
3313
+ return mc.parse(this.shapeNode.getAttribute("transform"));
3314
+ },
3315
+ getViewPortTransform() {
3316
+ const m = this.shapeNode.getCTM();
3317
+ return new mc(m.a, m.b, m.c, m.d, m.e, m.f);
3318
+ },
3319
+ getTransform() {
3320
+ return this.getViewPortTransform().reverse();
3321
+ },
3322
+ addResource(resource) {
3323
+ this.resources.appendItem(resource);
3324
+ if (resource.node) {
3325
+ this.resourceNode.appendChild(resource.node);
3326
+ }
3327
+ return this;
3328
+ },
3329
+ removeResource(resource) {
3330
+ if (resource.remove) {
3331
+ resource.remove();
3332
+ }
3333
+ if (resource.node) {
3334
+ this.resourceNode.removeChild(resource.node);
3335
+ }
3336
+ return this;
3337
+ },
3338
+ getPaper() {
3339
+ return this;
3340
+ }
3341
+ });
3342
+ extendClass(Shape, {
3343
+ getPaper() {
3344
+ let parent = this.container;
3345
+ while (parent && parent instanceof Paper === false) {
3346
+ parent = parent.container;
3347
+ }
3348
+ return parent;
3349
+ },
3350
+ isAttached() {
3351
+ return !!this.getPaper();
3352
+ },
3353
+ whenPaperReady(fn) {
3354
+ const me = this;
3355
+ function check() {
3356
+ const paper = me.getPaper();
3357
+ if (paper && fn) {
3358
+ fn.call(me, paper);
3359
+ }
3360
+ return paper;
3361
+ }
3362
+ if (!check()) {
3363
+ this.on("add treeadd", function listen2() {
3364
+ if (check()) {
3365
+ me.off("add", listen2);
3366
+ me.off("treeadd", listen2);
3367
+ }
3368
+ });
3369
+ }
3370
+ return this;
3371
+ }
3372
+ });
3373
+
3374
+ // src/kity/index.ts
3375
+ var kity = {
3376
+ version: "2.0.5",
3377
+ createClass,
3378
+ extendClass,
3379
+ Utils: utils_default,
3380
+ Class,
3381
+ Box,
3382
+ Point,
3383
+ Matrix,
3384
+ g,
3385
+ Container,
3386
+ Shape,
3387
+ ShapeContainer,
3388
+ Group,
3389
+ Rect,
3390
+ Path,
3391
+ Text,
3392
+ Paper,
3393
+ Use,
3394
+ ViewBox,
3395
+ EventHandler,
3396
+ Styled,
3397
+ Data,
3398
+ PathDrawer,
3399
+ svg
3400
+ };
3401
+ function installKityRuntime(targetWindow = window) {
3402
+ if (targetWindow.kity) {
3403
+ return;
3404
+ }
3405
+ targetWindow.kity = kity;
3406
+ }
3407
+
3408
+ // src/create-editor.ts
3409
+ var DEFAULT_LATEX = "x=\\frac{-b\\pm\\sqrt{b^2-4ac}}{2a}";
3410
+ var DEFAULT_EDITOR_HEIGHT = "auto";
3411
+ var KITY_STYLE_ID = "formulax-kity-editor-styles";
3412
+ var runtimePromise = null;
3413
+ function resolveContainer(el) {
3414
+ if (typeof el === "string") {
3415
+ const element = document.querySelector(el);
3416
+ if (!(element instanceof HTMLElement)) {
3417
+ throw new Error(`Kity editor mount target not found: ${el}`);
3418
+ }
3419
+ return element;
3420
+ }
3421
+ return el;
3422
+ }
3423
+ function normalizeCssSize(value, fallback) {
3424
+ if (typeof value === "number") {
3425
+ return `${value}px`;
3426
+ }
3427
+ return value ?? fallback;
3428
+ }
3429
+ function resolveEditorAssets(assets) {
3430
+ return {
3431
+ fonts: {
3432
+ ...kityAssetManifest.fonts,
3433
+ ...assets?.fonts
3434
+ },
3435
+ toolbar: {
3436
+ ...kityAssetManifest.toolbar,
3437
+ ...assets?.toolbar
3438
+ },
3439
+ styles: {
3440
+ ...kityAssetManifest.styles,
3441
+ ...assets?.styles
3442
+ }
3443
+ };
3444
+ }
3445
+ function ensureKityStylesheet(doc, href) {
3446
+ if (doc.getElementById(KITY_STYLE_ID)) {
3447
+ return;
3448
+ }
3449
+ const link = doc.createElement("link");
3450
+ link.id = KITY_STYLE_ID;
3451
+ link.rel = "stylesheet";
3452
+ link.href = href;
3453
+ doc.head.appendChild(link);
3454
+ }
3455
+ function hydrateLegacyKf(runtimeWindow) {
3456
+ const requireFormula = runtimeWindow.__kityFormulaRequire__;
3457
+ if (!requireFormula) {
3458
+ return;
3459
+ }
3460
+ runtimeWindow.kf = {
3461
+ ...runtimeWindow.kf ?? {},
3462
+ ResourceManager: requireFormula("resource-manager"),
3463
+ Operator: requireFormula("operator/operator"),
3464
+ Expression: requireFormula("expression/expression"),
3465
+ CompoundExpression: requireFormula("expression/compound"),
3466
+ TextExpression: requireFormula("expression/text"),
3467
+ EmptyExpression: requireFormula("expression/empty"),
3468
+ CombinationExpression: requireFormula("expression/compound-exp/combination"),
3469
+ FunctionExpression: requireFormula("expression/compound-exp/func"),
3470
+ FractionExpression: requireFormula("expression/compound-exp/fraction"),
3471
+ IntegrationExpression: requireFormula("expression/compound-exp/integration"),
3472
+ RadicalExpression: requireFormula("expression/compound-exp/radical"),
3473
+ ScriptExpression: requireFormula("expression/compound-exp/script"),
3474
+ SuperscriptExpression: requireFormula("expression/compound-exp/binary-exp/superscript"),
3475
+ SubscriptExpression: requireFormula("expression/compound-exp/binary-exp/subscript"),
3476
+ SummationExpression: requireFormula("expression/compound-exp/summation"),
3477
+ BracketsExpression: requireFormula("expression/compound-exp/brackets")
3478
+ };
3479
+ }
3480
+ function installLegacyRuntime(runtimeWindow) {
3481
+ runtimeWindow.__FORMULAX_KITY_RUNTIME__ = {
3482
+ baseComponent: runtimeWindow.kity ? createLegacyBaseComponent(
3483
+ runtimeWindow.kity
3484
+ ) : void 0,
3485
+ baseUtils: legacyBaseUtils,
3486
+ boxType: legacyBoxType,
3487
+ sysconf: legacySysconf,
3488
+ charPosition: legacyCharPosition,
3489
+ commonUtils: legacyCommonUtils,
3490
+ eleType: legacyEleType,
3491
+ eventListener: legacyEventListener,
3492
+ groupType: legacyGroupType,
3493
+ inputFilter: legacyInputFilter,
3494
+ itemType: legacyItemType,
3495
+ kf: runtimeWindow.kf,
3496
+ kfExtDef: legacyKfExtDef,
3497
+ kfEvent: legacyKfEvent,
3498
+ kity: runtimeWindow.kity,
3499
+ otherPosition: legacyOtherPosition,
3500
+ uiDef: legacyUiDef,
3501
+ uiUtils: createLegacyUiUtils()
3502
+ };
3503
+ }
3504
+ async function ensureKityRuntime() {
3505
+ if (runtimePromise) {
3506
+ return runtimePromise;
3507
+ }
3508
+ runtimePromise = (async () => {
3509
+ const runtimeWindow = window;
3510
+ runtimeWindow.kf = runtimeWindow.kf ?? {};
3511
+ installKityRuntime(runtimeWindow);
3512
+ const { installLegacyKityFormulaRuntime } = await import("./install-ARHGHFNJ.js");
3513
+ installLegacyKityFormulaRuntime(runtimeWindow);
3514
+ hydrateLegacyKf(runtimeWindow);
3515
+ const { installLegacyParserRuntime } = await import("./install-HKCG5NWK.js");
3516
+ installLegacyParserRuntime(runtimeWindow);
3517
+ installLegacyRuntime(runtimeWindow);
3518
+ const { installKityEditorStart } = await import("./start-GQH6XUBI.js");
3519
+ installKityEditorStart(runtimeWindow);
3520
+ })();
3521
+ return runtimePromise;
3522
+ }
3523
+ async function createKityEditor(container, options = {}) {
3524
+ const fontsize = options.render?.fontsize ?? 40;
3525
+ const editorHeight = normalizeCssSize(options.height, DEFAULT_EDITOR_HEIGHT);
3526
+ const assets = resolveEditorAssets(options.assets);
3527
+ ensureKityStylesheet(document, assets.styles.editor);
3528
+ setToolbarAssetUrls(assets.toolbar);
3529
+ await ensureKityRuntime();
3530
+ const runtimeWindow = window;
3531
+ if (!runtimeWindow.kf?.EditorFactory) {
3532
+ throw new Error("Kity editor runtime did not initialize");
3533
+ }
3534
+ container.innerHTML = "";
3535
+ const host = document.createElement("div");
3536
+ host.className = "kf-editor";
3537
+ host.style.width = "100%";
3538
+ host.style.height = editorHeight;
3539
+ container.appendChild(host);
3540
+ const factory = runtimeWindow.kf.EditorFactory.create(host, {
3541
+ render: {
3542
+ fontsize
3543
+ },
3544
+ resource: {
3545
+ path: "",
3546
+ fonts: assets.fonts
3547
+ }
3548
+ });
3549
+ return {
3550
+ ready: factory.ready.bind(factory),
3551
+ execCommand(name, value) {
3552
+ factory.ready(function execWhenReady() {
3553
+ this.execCommand(name, value);
3554
+ });
3555
+ },
3556
+ focus() {
3557
+ factory.ready(function focusWhenReady() {
3558
+ this.execCommand("focus");
3559
+ });
3560
+ },
3561
+ destroy() {
3562
+ container.innerHTML = "";
3563
+ },
3564
+ host,
3565
+ raw: factory
3566
+ };
3567
+ }
3568
+ async function mountKityEditor(container, options = {}) {
3569
+ const editor = await createKityEditor(container, options);
3570
+ const initialLatex = options.initialLatex ?? DEFAULT_LATEX;
3571
+ const shouldFocus = options.autofocus ?? true;
3572
+ editor.ready(function ready() {
3573
+ this.execCommand("render", initialLatex);
3574
+ if (shouldFocus) {
3575
+ this.execCommand("focus");
3576
+ }
3577
+ });
3578
+ return editor;
3579
+ }
3580
+ var FormulaXEditor = class {
3581
+ container;
3582
+ options;
3583
+ handlePromise;
3584
+ constructor(options) {
3585
+ const { el, ...editorOptions } = options;
3586
+ this.container = resolveContainer(el);
3587
+ this.options = editorOptions;
3588
+ this.handlePromise = mountKityEditor(this.container, this.options);
3589
+ }
3590
+ ready(callback) {
3591
+ void this.handlePromise.then((handle) => handle.ready(callback));
3592
+ return this;
3593
+ }
3594
+ async execCommand(name, value) {
3595
+ const handle = await this.handlePromise;
3596
+ handle.execCommand(name, value);
3597
+ return this;
3598
+ }
3599
+ async focus() {
3600
+ const handle = await this.handlePromise;
3601
+ handle.focus();
3602
+ return this;
3603
+ }
3604
+ async destroy() {
3605
+ const handle = await this.handlePromise;
3606
+ handle.destroy();
3607
+ }
3608
+ async getHandle() {
3609
+ return this.handlePromise;
3610
+ }
3611
+ };
3612
+ if (typeof window !== "undefined") {
3613
+ window.FormulaXEditor = FormulaXEditor;
3614
+ }
3615
+
3616
+ // src/vendor/install-legacy-data.ts
3617
+ function installLegacyKityData(target = window) {
3618
+ target.__FORMULAX_KITY_DATA__ = {
3619
+ charPosition: legacyCharPosition,
3620
+ otherPosition: legacyOtherPosition
3621
+ };
3622
+ }
3623
+ export {
3624
+ FormulaXEditor,
3625
+ addEvent,
3626
+ createElement,
3627
+ createKityEditor,
3628
+ createLegacyBaseComponent,
3629
+ createLegacyUiUtils,
3630
+ delegateEvent,
3631
+ ensureKityRuntime,
3632
+ getClassList,
3633
+ getRectBox,
3634
+ installLegacyKityData,
3635
+ legacyBaseUtils,
3636
+ legacyBoxType,
3637
+ legacyCommonUtils,
3638
+ legacyEleType,
3639
+ legacyEventListener,
3640
+ legacyGroupType,
3641
+ legacyInputFilter,
3642
+ legacyItemType,
3643
+ legacyKfEvent,
3644
+ legacyKfExtDef,
3645
+ legacySysconf,
3646
+ legacyUiDef,
3647
+ mountKityEditor,
3648
+ normalizeMouseEvent,
3649
+ publish,
3650
+ subscribe
3651
+ };
3652
+ //# sourceMappingURL=index.js.map