| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717 | 1×
1×
65×
190×
125×
65×
65×
65×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1832×
1832×
1832×
1832×
1832×
1832×
1832×
1832×
8400×
1832×
1832×
1832×
1832×
1805×
1805×
1805×
1832×
1832×
1832×
83×
1749×
1×
1×
1749×
1×
1749×
1749×
1×
2155×
1375×
780×
3×
777×
4×
773×
1×
1×
1832×
1832×
4×
4×
1828×
1828×
1×
1832×
1×
3637×
1×
1832×
1832×
1832×
1832×
1832×
1832×
1832×
1832×
1832×
1832×
1832×
1832×
1805×
1832×
1832×
1832×
1832×
1832×
2×
2×
1830×
167×
167×
167×
167×
1832×
1×
1832×
1832×
1832×
1805×
1832×
1832×
1832×
1×
1832×
1832×
1832×
1805×
1805×
1×
3664×
3664×
21×
3643×
1832×
167×
1665×
1665×
1665×
2×
2×
2×
1×
2×
2×
2×
1663×
1663×
9×
1654×
2×
1663×
1663×
6×
1657×
1×
1665×
1665×
1665×
1×
1832×
1832×
2×
1830×
1830×
1830×
1830×
1830×
1×
1830×
1830×
1830×
1830×
1830×
1×
167×
167×
167×
167×
167×
167×
167×
167×
167×
167×
167×
167×
167×
167×
167×
167×
167×
167×
167×
16×
151×
151×
151×
151×
21×
151×
151×
151×
151×
4×
147×
35×
112×
1×
459×
9×
450×
2×
448×
3×
445×
1×
1×
1832×
1832×
2×
1832×
2×
1832×
2×
1832×
1×
1832×
1×
1×
1×
1×
1831×
1×
1832×
83×
1749×
1749×
1749×
38×
1749×
65×
65×
1684×
6×
1678×
1×
1832×
1832×
1832×
6×
1832×
7×
1832×
5×
1832×
10×
10×
1832×
5×
1832×
2×
1832×
2×
1832×
95×
1832×
4×
1832×
24×
1832×
34×
1832×
1832×
5×
1832×
1×
1×
3664×
3664×
1×
3663×
1832×
1832×
1832×
1832×
1832×
1832×
1832×
1×
1749×
16×
16×
1733×
1×
1749×
1×
1748×
2×
1746×
6×
1740×
1×
1815×
1815×
1815×
1815×
1815×
1815×
1815×
1815×
1815×
1815×
1815×
1815×
1815×
9×
1815×
1815×
1815×
1815×
8×
8×
8×
8×
8×
1815×
1338×
477×
50×
427×
427×
65×
65×
362×
7×
355×
6×
6×
349×
1×
1×
12×
12×
8×
4×
4×
4×
40×
40×
4×
4×
1×
1×
6×
1×
65×
139×
65×
65×
14×
51×
8×
43×
3×
40×
2×
38×
2×
36×
29×
7×
5×
2×
1×
1×
1×
1×
7×
7×
7×
7×
7×
7×
7×
7×
3×
4×
3×
1×
1×
1×
1×
3×
3×
3×
3×
2×
2×
3×
1×
3×
3×
3×
3×
2×
2×
3×
1×
1×
1×
8×
8×
8×
8×
8×
22×
8×
4×
4×
5×
5×
5×
5×
5×
5×
4×
4×
2×
4×
2×
2×
8×
1×
8×
1×
1×
8×
8×
4×
4×
1×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
1×
258×
258×
258×
258×
1×
74×
74×
67×
67×
258×
258×
258×
235×
74×
1×
14×
14×
14×
14×
14×
28×
14×
14×
14×
6×
14×
14×
11×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
14×
1×
8×
8×
8×
8×
5×
3×
3×
1×
16×
8×
7×
14×
7×
1×
1×
1×
8×
8×
8×
1×
3×
1×
1×
1×
2×
2×
2×
1×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
1×
2×
2×
2×
2×
2×
2×
2×
2×
1×
2×
18×
2×
1×
2×
1×
29×
29×
29×
29×
29×
2×
1×
1×
1×
29×
11×
18×
1×
18×
18×
18×
18×
18×
18×
18×
18×
18×
1×
11×
11×
11×
11×
11×
11×
11×
11×
11×
11×
11×
11×
1×
5×
5×
5×
5×
5×
5×
5×
5×
5×
5×
51×
5×
3×
3×
2×
5×
5×
5×
5×
1×
5×
1×
1×
51×
1×
1×
3×
28×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
2×
2×
2×
2×
4×
4×
4×
3×
1×
1×
1×
1×
1×
1×
28×
1×
58884×
58884×
1×
58579×
58579×
58579×
58579×
58579×
13×
58566×
58566×
164×
58402×
41438×
16964×
13820×
13820×
13820×
250633×
13820×
58566×
13984×
13984×
13984×
13984×
13984×
44582×
41438×
41438×
41438×
41438×
41438×
41438×
3144×
1×
1×
3636×
3636×
3636×
14×
3622×
3622×
2881×
741×
741×
16×
725×
725×
725×
696×
696×
696×
20×
676×
676×
705×
325×
380×
380×
75×
305×
305×
305×
305×
305×
305×
305×
1×
1×
287×
287×
80×
207×
207×
207×
191×
191×
191×
191×
189×
207×
287×
1×
1692×
1692×
1692×
1692×
1692×
1405×
287×
1×
1×
143×
143×
143×
20×
123×
123×
123×
123×
62×
61×
61×
60×
1×
1×
1×
4054×
4054×
4054×
4054×
4054×
9470×
9470×
6471×
2999×
2999×
2999×
2999×
2999×
2999×
4054×
1×
2027×
2027×
2027×
2027×
1501×
1947×
1501×
526×
8×
8×
8×
518×
518×
522×
522×
522×
522×
518×
522×
518×
1×
522×
522×
522×
522×
522×
522×
522×
522×
522×
2483×
2483×
2483×
2483×
2483×
2483×
2483×
2483×
2483×
522×
522×
522×
522×
2238×
2238×
2238×
2238×
2238×
2238×
2238×
2238×
2238×
2238×
2091×
2091×
147×
147×
2238×
2238×
2238×
522×
2483×
392×
522×
522×
522×
522×
522×
522×
522×
1×
2238×
2238×
2238×
2238×
2238×
1×
2238×
2238×
2238×
2238×
2238×
2238×
2238×
1×
392×
392×
392×
392×
848×
848×
392×
392×
392×
1×
5520×
5520×
11516×
11516×
11516×
5520×
1×
3994×
3994×
3994×
3994×
3994×
3994×
3994×
1×
8300×
8300×
8300×
8300×
8300×
8300×
8300×
8300×
8300×
8300×
8300×
8300×
8300×
8300×
1×
2760×
2760×
2760×
2760×
7452×
7452×
3994×
3994×
3458×
2760×
1×
1×
1678×
1678×
16×
1662×
1731×
1731×
1731×
1731×
1707×
1707×
1707×
1731×
1659×
3×
1×
1×
1678×
1678×
16×
1662×
1794×
1794×
1794×
1794×
1770×
1770×
1770×
1794×
1639×
23×
1×
1×
2237×
2237×
2213×
2213×
2213×
2213×
11×
2226×
1×
1×
1974×
1974×
1974×
1974×
1974×
1974×
1×
1×
1678×
1678×
16×
1662×
1662×
1662×
1661×
1×
1×
| var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
Eif (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
define(["require", "exports", "../../enum/enum", "./visio-annotations", "./visio-core", "./visio-theme"], function (require, exports, enum_1, visio_annotations_1, visio_core_1, visio_theme_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.shapeIndex = { value: 0 };
var PROPERTY_SECTION = 'Property';
var USER_SECTION = 'User';
var RELATIONSHIPS_CELL = 'Relationships';
var VALUE_CELL = 'Value';
var ACTIONS_SECTION = 'Actions';
function convertVisioShapeToNode(node, context, shapeGroup) {
var pivot = { x: 0.5, y: 0.5 };
var hasSize = node && node.width != null && node.height != null;
var hasPivot = node && node.pivotX != null && node.pivotY != null;
Eif (hasSize && hasPivot) {
var widthInches = Number(node.width);
var heightInches = Number(node.height);
Eif (widthInches > 0 && heightInches > 0) {
pivot = normalizePivotForEJ2(Number(node.pivotX), Number(node.pivotY), widthInches, heightInches);
}
}
var diagramPorts = (node.ports || []).map(function (port) { return ({
id: port.id,
offset: { x: port.x, y: port.y },
shape: 'Circle',
style: { strokeColor: '#757575', strokeWidth: 1 }
}); });
var annotation = node.annotation;
var annotationStyle = visio_theme_1.setAnnotationStyle(node, context);
var textBinding = null;
if (annotation && annotation.txtPinX !== undefined) {
var shapeTransform = {
pinX: node.offsetX,
pinY: node.pinY / 96,
width: node.width,
height: node.height,
verticalAlignment: setVerticalAlignment(node)
};
var textTransform = {
txtWidth: annotation.txtWidth,
txtHeight: annotation.txtHeight,
txtPinX: annotation.txtPinX,
txtPinY: annotation.txtPinY,
txtLocPinX: annotation.txtLocPinX,
txtLocPinY: annotation.txtLocPinY,
txtAngle: (annotation.rotateAngle || 0) * (Math.PI / 180),
txtMargin: annotation.margin
};
textBinding = visio_annotations_1.VisioToSyncfusionTextBinder.bindVisioTextToSyncfusion(shapeTransform, textTransform);
}
var alignmentConfig = resolveAnnotationAlignmentAndOffset(node, textBinding);
var isGroup = Array.isArray(node.children) && node.children.length > 0;
if (isGroup) {
return {
id: node.id,
addInfo: node.addInfo,
shape: setNodeShape(node, context, isGroup),
style: visio_theme_1.getNodeStyle(node, context, isGroup),
children: node.children,
parentId: node.parentId,
pivot: pivot,
constraints: setConstraints(node, context),
shadow: undefined,
rotateAngle: (360 - visio_core_1.radiansToDegrees(node.rotateAngle)) % 360 || 0,
annotations: createAnnotationArray(node, alignmentConfig, annotationStyle)
};
}
return {
id: node.id,
width: visio_core_1.inchToPx(node.width),
height: visio_core_1.inchToPx(node.height),
offsetX: visio_core_1.inchToPx(node.offsetX),
offsetY: node.offsetY,
shape: setNodeShape(node, context, isGroup),
addInfo: node.addInfo,
style: visio_theme_1.getNodeStyle(node, context, isGroup),
constraints: setConstraints(node, context),
shadow: setShadow(node),
flip: setFlip(node),
visible: setVisibility(node),
tooltip: { content: node.tooltip || '' },
pivot: pivot,
rotateAngle: (360 - visio_core_1.radiansToDegrees(node.rotateAngle)) % 360 || 0,
children: node.children,
parentId: node.parentId,
padding: setPadding(isGroup),
ports: diagramPorts,
margin: node.calculatedMargin ? node.calculatedMargin : undefined,
annotations: createAnnotationArray(node, alignmentConfig, annotationStyle)
};
}
exports.convertVisioShapeToNode = convertVisioShapeToNode;
function setVisibility(node) {
return node.shape && node.shape.shape === 'TextAnnotation' ? true : node.visibility !== undefined ? !node.visibility : true;
}
function setPadding(isGroup) {
var value = isGroup ? 12 : 0;
return { left: value, right: value, top: value, bottom: value };
}
function getTextDecoration(textDecoration) {
if (!textDecoration) {
return 'None';
}
if (textDecoration.underline) {
return 'Underline';
}
if (textDecoration.strikethrough) {
return 'LineThrough';
}
return 'None';
}
exports.getTextDecoration = getTextDecoration;
function setRotateAngle(node) {
var rotateAngle = 0;
if (node.annotation && node.annotation.rotateAngle) {
rotateAngle = (360 - (node.annotation.rotateAngle)) % 360;
return rotateAngle;
}
else Iif (node.annotation && node.annotation.segmentAngle) {
rotateAngle += 90;
}
return rotateAngle;
}
function setHorizontalAlignment(node) {
return node.annotation && node.annotation.horizontalAlignment;
}
function setVerticalAlignment(node) {
return node.annotation && node.annotation.verticalAlignment;
}
function resolveAnnotationAlignmentAndOffset(node, textBinding) {
var baseVerticalAlign = setVerticalAlignment(node);
var baseHorizontalAlign = setHorizontalAlignment(node);
var isVerticalText = isVerticalTextAnnotation(node);
var annotation = node.annotation;
var hasExplicitTextPosition = false;
Eif (annotation) {
var hasExplicitFlag = annotation.hasExplicitTextPosition === true;
hasExplicitTextPosition = hasExplicitFlag;
}
var nodeWidthPx = visio_core_1.inchToPx(node.width);
var nodeHeightPx = visio_core_1.inchToPx(node.height);
var annotationWidthInches = node.width;
if (annotation && annotation.txtWidth) {
annotationWidthInches = annotation.txtWidth;
}
var annotationWidthPx = visio_core_1.inchToPx(annotationWidthInches);
var annotationOffset = calculateAnnotationOffset(textBinding, baseVerticalAlign, baseHorizontalAlign, nodeHeightPx, nodeHeightPx, annotationWidthPx, nodeWidthPx, isVerticalText, hasExplicitTextPosition);
var effectiveVerticalAlign = baseVerticalAlign;
var effectiveHorizontalAlign = baseHorizontalAlign;
if (isVerticalText) {
effectiveVerticalAlign = 'Center';
effectiveHorizontalAlign = 'Center';
}
else {
if (hasExplicitTextPosition) {
effectiveHorizontalAlign = 'Center';
var nodeHeightInches = typeof node.height === 'number' ? node.height : 0;
var derived = deriveVerticalAlignForExplicitPins(annotation, nodeHeightInches);
effectiveVerticalAlign = derived;
}
}
return {
verticalAlign: effectiveVerticalAlign,
horizontalAlign: effectiveHorizontalAlign,
annotationOffset: annotationOffset
};
}
function createAnnotationArray(node, alignmentConfig, annotationStyle) {
var annotationInputWidthInches = node.width;
var nodeAnnotation = node.annotation;
if (nodeAnnotation.txtWidth) {
annotationInputWidthInches = nodeAnnotation.txtWidth;
}
var annotationWidthPx = visio_core_1.inchToPx(annotationInputWidthInches);
var annotation = {
content: node.annotation.content,
width: annotationWidthPx,
visibility: node.annotation.visible,
hyperlink: setHyperLink(node, annotationStyle),
rotateAngle: setRotateAngle(node),
constraints: setAnnotationConstraints(node.annotation),
verticalAlignment: alignmentConfig.verticalAlign,
horizontalAlignment: alignmentConfig.horizontalAlign,
offset: alignmentConfig.annotationOffset,
style: annotationStyle
};
return [annotation];
}
function calculateAnnotationOffset(textBinding, verticalAlignment, horizontalAlignment, annotationHeight, nodeHeight, annotationWidth, nodeWidth, isVerticalText, preserveExplicit) {
var baseOffsetX = 0.5;
var baseOffsetY = 0.5;
if (textBinding !== null && textBinding.offset) {
baseOffsetX = textBinding.offset.x;
baseOffsetY = textBinding.offset.y;
}
function clamp01(value) {
Iif (value < 0) {
return 0;
}
if (value > 1) {
return 1;
}
return value;
}
if (preserveExplicit) {
return { x: clamp01(baseOffsetX), y: clamp01(baseOffsetY) };
}
var finalX = baseOffsetX;
var finalY = baseOffsetY;
if (isVerticalText) {
Eif (typeof verticalAlignment === 'string') {
Iif (verticalAlignment === 'Top') {
finalX = 1;
}
else if (verticalAlignment === 'Bottom') {
finalX = 0;
}
else {
}
}
Eif (typeof horizontalAlignment === 'string') {
Iif (horizontalAlignment === 'Left') {
finalY = 0;
}
else Iif (horizontalAlignment === 'Right') {
finalY = 1;
}
else {
}
}
}
else {
Eif (typeof horizontalAlignment === 'string') {
if (horizontalAlignment === 'Left') {
finalX = 0;
}
else if (horizontalAlignment === 'Right') {
finalX = 1;
}
else {
}
}
Eif (typeof verticalAlignment === 'string') {
if (verticalAlignment === 'Top') {
finalY = 0;
}
else if (verticalAlignment === 'Bottom') {
finalY = 1;
}
else {
}
}
}
finalX = clamp01(finalX);
finalY = clamp01(finalY);
return { x: finalX, y: finalY };
}
function isVerticalTextAnnotation(node) {
Iif (!node || !node.annotation) {
return false;
}
if (node.annotation.segmentAngle === true) {
return true;
}
var rawAngle = 0;
Eif (typeof node.annotation.rotateAngle === 'number') {
rawAngle = node.annotation.rotateAngle;
}
var normalized = rawAngle % 360;
if (normalized < 0) {
normalized = normalized + 360;
}
var tolerance = 0.5;
var nearNinety = Math.abs(normalized - 90) <= tolerance;
var nearTwoSeventy = Math.abs(normalized - 270) <= tolerance;
Iif (nearNinety || nearTwoSeventy) {
return true;
}
return false;
}
function deriveVerticalAlignForExplicitPins(annotation, nodeHeightInches) {
var hasTxtPinY = false;
var txtPinYInches = 0;
Eif (annotation &&
typeof annotation.txtPinY === 'number' &&
isFinite(annotation.txtPinY)) {
txtPinYInches = annotation.txtPinY;
hasTxtPinY = true;
}
var hasTxtHeight = false;
var txtHeightInches = 0;
Eif (annotation &&
typeof annotation.txtHeight === 'number' &&
isFinite(annotation.txtHeight)) {
txtHeightInches = annotation.txtHeight;
hasTxtHeight = true;
}
var hasTxtLocPinY = false;
var txtLocPinYInches = 0;
Eif (annotation &&
typeof annotation.txtLocPinY === 'number' &&
isFinite(annotation.txtLocPinY)) {
txtLocPinYInches = annotation.txtLocPinY;
hasTxtLocPinY = true;
}
var hasNodeHeight = typeof nodeHeightInches === 'number' &&
isFinite(nodeHeightInches) && nodeHeightInches > 0;
var isFullHeightBlock = hasTxtHeight &&
hasNodeHeight &&
Math.abs(txtHeightInches - nodeHeightInches) < 1e-6;
var pinsAtOrigin = hasTxtPinY &&
hasTxtLocPinY &&
txtPinYInches === 0 &&
txtLocPinYInches === 0;
if (isFullHeightBlock && pinsAtOrigin) {
return 'Center';
}
var normalizedFromBottom = 0.5;
Eif (hasTxtPinY && nodeHeightInches > 0 && isFinite(nodeHeightInches)) {
normalizedFromBottom = txtPinYInches / nodeHeightInches;
if (normalizedFromBottom < 0) {
normalizedFromBottom = 0;
}
Iif (normalizedFromBottom > 1) {
normalizedFromBottom = 1;
}
}
else {
if (annotation &&
annotation.offset &&
typeof annotation.offset.y === 'number') {
var topOriginOffsetY = annotation
.offset.y;
var flipped = 1 - topOriginOffsetY;
if (flipped < 0) {
flipped = 0;
}
if (flipped > 1) {
flipped = 1;
}
normalizedFromBottom = flipped;
}
}
var nearTopThreshold = 0.67;
var nearBottomThreshold = 0.33;
if (normalizedFromBottom >= nearTopThreshold) {
return 'Bottom';
}
if (normalizedFromBottom <= nearBottomThreshold) {
return 'Top';
}
return 'Center';
}
function getTextAlign(alignment) {
if (alignment.left) {
return 'Left';
}
if (alignment.right) {
return 'Right';
}
if (alignment.justify) {
return 'Justify';
}
return 'Center';
}
exports.getTextAlign = getTextAlign;
function setAnnotationConstraints(shape) {
var constraints = shape.constraints;
if (shape.lockTextEdit) {
constraints = enum_1.AnnotationConstraints.InheritReadOnly;
}
if (shape.lockRotate) {
constraints &= ~enum_1.AnnotationConstraints.Rotate;
}
if (shape.lockSelect) {
constraints &= ~enum_1.AnnotationConstraints.Select;
}
return constraints;
}
function setHyperLink(NodeData, nodeStyle) {
if (NodeData.annotation && NodeData.annotation.hyperlink && NodeData.annotation.hyperlink.link) {
var textDecoration = 'None';
Iif (NodeData.annotation.style.textDecoration.underline) {
textDecoration = 'Underline';
}
else Iif (NodeData.annotation.style.textDecoration.strikethrough) {
textDecoration = 'LineThrough';
}
return {
link: NodeData.annotation.hyperlink.link,
content: NodeData.annotation.content || '',
hyperlinkOpenState: NodeData.annotation.hyperlink.newWindow ? 'NewWindow' : 'NewTab',
color: nodeStyle.color || 'black',
textDecoration: nodeStyle.textDecoration || 'None'
};
}
return undefined;
}
function setNodeShape(shape, context, isGroup) {
if (!shape || !shape.shape || isGroup) {
return {
type: 'Basic',
shape: 'Rectangle',
cornerRadius: 0
};
}
var type = shape.shape.type;
var mainShapeObject = shape && shape.shape;
if (shape.cornerRadius) {
context.addWarning('[WARNING] :: In EJ2, cap type and rounding can only be adjusted for rectangles; there is no support for adjusting these properties for all shapes.');
}
if (type === 'Bpmn') {
var bpmnType = mainShapeObject.type, bpmnProperties = __rest(mainShapeObject, ["type"]);
return __assign({ type: 'Bpmn' }, bpmnProperties, { cornerRadius: shape.cornerRadius ? visio_core_1.inchToPoint(shape.cornerRadius) : 0 });
}
if (type === 'UmlActivity') {
return {
type: 'UmlActivity',
shape: mainShapeObject.shape,
cornerRadius: shape.cornerRadius ? visio_core_1.inchToPoint(shape.cornerRadius) : 0
};
}
return __assign({ type: type }, (type === 'Basic' || type === 'Flow'
? { shape: shape.shape.shape }
: type === 'Path'
? { data: shape.shape.data }
: type === 'Image'
? { source: shape.shape.source }
: {}), { cornerRadius: shape.cornerRadius ? visio_core_1.inchToPoint(shape.cornerRadius) : 0 });
}
function setConstraints(shape, context) {
var constraints = shape.constraints;
constraints = enum_1.NodeConstraints.Default;
if (shape.lockHeight) {
constraints &= ~(enum_1.NodeConstraints.ResizeNorth | enum_1.NodeConstraints.ResizeSouth);
}
if (shape.lockWidth) {
constraints &= ~(enum_1.NodeConstraints.ResizeWest | enum_1.NodeConstraints.ResizeEast);
}
if (shape.lockHeight && shape.lockWidth) {
constraints &= ~enum_1.NodeConstraints.Resize;
}
if (shape.lockMoveX || shape.lockMoveY) {
context.addWarning('[WARNING] :: In EJ2, individual disabling of drag constraints for X and Y positions is not supported. Therefore, if enabled, a node cannot be dragged.');
constraints &= ~enum_1.NodeConstraints.Drag;
}
if (shape.lockRotate) {
constraints &= ~enum_1.NodeConstraints.Rotate;
}
if (shape.lockDelete) {
constraints &= ~enum_1.NodeConstraints.Delete;
}
if (shape.lockSelect) {
constraints &= ~enum_1.NodeConstraints.Select;
}
if (shape.lockAspect) {
constraints |= enum_1.NodeConstraints.AspectRatio;
}
if (shape.lockTextEdit) {
constraints |= enum_1.NodeConstraints.ReadOnly;
}
if (shape.shadow && shape.shadow.shadowPattern) {
constraints |= enum_1.NodeConstraints.Shadow;
}
if (shape.comment) {
constraints |= enum_1.NodeConstraints.Tooltip;
}
Iif (shape.glueType && shape.glueValue === '8') {
constraints &= ~(enum_1.NodeConstraints.InConnect | enum_1.NodeConstraints.OutConnect);
}
if (shape.AllowDrop) {
constraints |= enum_1.NodeConstraints.AllowDrop;
}
return constraints;
}
function normalizePivotForEJ2(pivotXInches, pivotYInches, widthInches, heightInches) {
function clamp01(v) {
Iif (v < 0) {
return 0;
}
if (v > 1) {
return 1;
}
return v;
}
var xNormalized = 0.5;
Eif (typeof widthInches === 'number' && isFinite(widthInches) && widthInches !== 0) {
xNormalized = clamp01(pivotXInches / widthInches);
}
var yNormalized = 0.5;
Eif (typeof heightInches === 'number' && isFinite(heightInches) && heightInches !== 0) {
yNormalized = clamp01(1 - (pivotYInches / heightInches));
}
return { x: xNormalized, y: yNormalized };
}
function setShadow(node) {
if (node.shadow.shadowPattern && node.shadow.shapeShadowShow) {
var shadow = {
color: node.shadow.shadowcolor,
opacity: node.shadow.shadowOpacity,
angle: node.shadow.shadow.angle,
distance: (node.shadow.shadow.distance) * 100
};
return shadow;
}
return undefined;
}
function setFlip(shape) {
if (shape.flipX && shape.flipY) {
return enum_1.FlipDirection.Both;
}
if (shape.flipX) {
return enum_1.FlipDirection.Horizontal;
}
if (shape.flipY) {
return enum_1.FlipDirection.Vertical;
}
return enum_1.FlipDirection.None;
}
function determineShapeType(attributes, defaultData, shapes, Node, context) {
var basicShapes = new Set([
'Rectangle', 'Ellipse', 'Triangle', 'Pentagon', 'Heptagon', 'Octagon', 'Trapezoid',
'Decagon', 'RightTriangle', 'Parallelogram', 'Hexagon', 'Cylinder', 'Diamond',
'Polygon', 'Star', 'Plus'
]);
var flowShapes = new Set([
'Terminator', 'Process', 'Decision', 'Document', 'Data', 'Or', 'Collate', 'Merge',
'Extract', 'Sort', 'SummingJunction', 'MultiDocument', 'OffPageReference',
'PreDefinedProcess', 'DirectData', 'SequentialData', 'PaperTap', 'Card',
'ManualOperation', 'StoredData', 'Preparation', 'Display', 'Delay', 'InternalStorage'
]);
var bpmnShapes = new Set([
'StartEvent', 'EndEvent', 'IntermediateEvent', 'Gateway', 'DataStore', 'DataObject',
'TextAnnotation', 'Task', 'CollapsedSubProcess', 'ExpandedSubProcess', 'Group', 'Message'
]);
var umlActivityShapes = new Set([
'Action', 'Decision', 'MergeNode', 'InitialNode', 'FinalNode', 'ForkNode', 'JoinNode', 'Note'
]);
var umlClassShapes = new Set([
'Class', 'Member', 'Separator', 'Interface', 'Enumeration'
]);
var shapeTransformations = new Map([
['Subprocess', 'PreDefinedProcess'],
['MagneticTape', 'SequentialData'],
['Database', 'DirectData'],
['Microform', 'PaperTap'],
['custom3', 'Card'],
['custom2', 'ManualOperation'],
['Start/End', 'Terminator'],
['ExternalData', 'StoredData'],
['Custom4', 'Preparation']
]);
var basicTrans = new Map([
['Cross', 'Plus'],
['5PointStar', 'Star'],
['Circle', 'Ellipse'],
['Can', 'Cylinder'],
['Square', 'Rectangle'],
['OnPageReference', 'Ellipse']
]);
var name = attributes.Name;
var finalShape;
Eif (name !== undefined) {
var trimmedName = name.replace(/[-\s](.)/g, function (match, letter) { return letter.toUpperCase(); })
.replace(/[-\s]/g, '');
trimmedName = trimmedName.replace(/\.\d+$/, '').trim();
if (name === 'Parallelogram' || name === 'Trapezoid' || name === 'Hexagon' ||
name === 'Data' || name === 'Off-page reference' || name === 'Preparation' || name === 'Multi document') {
context.addWarning("[WARNING] :: In the Visio to EJ2 Basic import, the " + name + " exist in the EJ2 diagram but their appearance differs.");
}
var fromBasic = basicTrans.get(trimmedName);
var fromTransform = shapeTransformations.get(trimmedName);
finalShape = fromBasic !== undefined
? fromBasic
: (fromTransform !== undefined ? fromTransform : trimmedName);
if (finalShape === 'Decision') {
var keywordsRaw = getShapeKeywordsFromMaster(shapes, context);
var kw = (keywordsRaw || '').toLowerCase();
var hasUml = kw.includes('uml');
var hasFlow = kw.includes('flow') || kw.includes('flowchart');
Iif (hasUml && !hasFlow) {
if (finalShape === 'Decision') {
var shape = getUMLActivityShapes(shapes, finalShape);
return shape;
}
}
}
if (basicShapes.has(finalShape) || basicTrans.has(finalShape)) {
return { type: 'Basic', shape: finalShape };
}
else if ((flowShapes.has(finalShape)) || shapeTransformations.has(finalShape)) {
return { type: 'Flow', shape: finalShape };
}
else Iif (finalShape === 'Path') {
var drawpathData = visio_core_1.createPathFromGeometry(attributes, undefined, undefined, { useLocalScaling: true });
var drawformattedPath = visio_core_1.formatPathData(drawpathData);
return { type: 'Path', data: drawformattedPath };
}
else if (bpmnShapes.has(finalShape)) {
var shape = getBPMNShapes(shapes, finalShape, Node, context);
return shape;
}
else if (finalShape === 'Image') {
return { type: 'Image', source: '' };
}
else if (umlActivityShapes.has(finalShape)) {
var shape = getUMLActivityShapes(shapes, finalShape);
return shape;
}
}
return undefined;
}
exports.determineShapeType = determineShapeType;
function getShapeKeywordsFromMaster(shape, context) {
var masterId = (shape && shape.$ && shape.$.Master != null)
? shape.$.Master
: undefined;
if (masterId == null) {
return '';
}
var masters = (context.data.masters) || [];
Iif (!Array.isArray(masters)) {
return '';
}
var master = masters.find(function (m) {
var mid = (m && m.id != null) ? m.id : undefined;
return String(mid) === String(masterId);
});
Iif (!master || !master.shapeKeywords) {
return '';
}
return String(master.shapeKeywords);
}
exports.getShapeKeywordsFromMaster = getShapeKeywordsFromMaster;
function getUMLActivityShapes(shapes, shapeName) {
return {
type: 'UmlActivity',
shape: shapeName
};
}
function getBPMNShapes(shapes, shapeName, Node, context) {
var sections = visio_core_1.ensureArray(shapes.Section);
var propertySection = sections.find(function (sec) { return sec.$ && sec.$.N === PROPERTY_SECTION; });
var propertyMap = createPropertyMap(propertySection);
if (shapeName.toLowerCase().includes('event')) {
return getEventShape(shapes, propertyMap, Node);
}
else if (shapeName.toLowerCase().includes('gateway')) {
return getGatewayShape(shapes, propertyMap, sections);
}
else if (shapeName.toLowerCase().includes('datastore')) {
return getDataSourceShape();
}
else if (shapeName.toLowerCase().includes('dataobject')) {
return getDataObjectShape(shapes, propertyMap, Node);
}
else if (shapeName.toLowerCase().includes('textannotation')) {
return getTextAnnotationShape(shapes);
}
else if (shapeName.toLowerCase().includes('task') || shapeName.toLowerCase().includes('collapsedsubprocess')) {
return getActivityShape(shapes, propertyMap);
}
else if (shapeName.toLowerCase().includes('expandedsubprocess')) {
return getExpandedSubProcessShape(shapes, propertyMap, Node, context);
}
else if (shapeName.toLowerCase().includes('group')) {
return getGroupShape(shapes);
}
else Eif (shapeName.toLowerCase().includes('message')) {
return getMessageShape();
}
return getEventShape(shapes, propertyMap, Node);
}
function getBPMNFlowShapes(shapes, shapeName, Node) {
var name = shapeName;
var sections = visio_core_1.ensureArray(shapes.Section);
var propertySection = sections.find(function (sec) { return sec.$ && sec.$.N === PROPERTY_SECTION; });
var propertyMap = createPropertyMap(propertySection);
var bpmnConnectingObjectType = propertyMap.get('BpmnConnectingObjectType');
Iif (bpmnConnectingObjectType) {
name = bpmnConnectingObjectType;
}
var cleanedBpmnType = name.replace(/\s+/g, '').toLowerCase();
if (cleanedBpmnType.includes('association')) {
return getBPMNAssociationFlow(propertyMap);
}
else if (cleanedBpmnType.includes('sequenceflow')) {
return getBPMNSequenceFlow(propertyMap);
}
else Eif (cleanedBpmnType.includes('messageflow')) {
return getBPMNMessageFlow();
}
return undefined;
}
exports.getBPMNFlowShapes = getBPMNFlowShapes;
function getBPMNAssociationFlow(propertyMap) {
var direction = 'Default';
var associationDirectionMap = {
'none': 'Default',
'both': 'BiDirectional',
'one': 'Directional'
};
var bpmnAssociationDirection = propertyMap.get('BpmnDirection');
if (bpmnAssociationDirection) {
var lookupKey = bpmnAssociationDirection.replace(/\s+/g, '').toLowerCase();
direction = associationDirectionMap["" + lookupKey] || 'Default';
}
return {
type: 'Bpmn',
flow: 'Association',
association: direction
};
}
function getBPMNSequenceFlow(propertyMap) {
var sequence = 'Normal';
var associationDirectionMap = {
'default': 'Default',
'none': 'Normal',
'conditional': 'Conditional'
};
var bpmnAssociationDirection = propertyMap.get('BpmnConditionType');
if (bpmnAssociationDirection) {
var lookupKey = bpmnAssociationDirection.replace(/\s+/g, '').toLowerCase();
sequence = associationDirectionMap["" + lookupKey] || 'Normal';
}
return {
type: 'Bpmn',
flow: 'Sequence',
sequence: sequence
};
}
function getBPMNMessageFlow() {
return {
type: 'Bpmn',
flow: 'Message',
message: 'Default'
};
}
function getUMLConnectors(shapes, shapeName, Node) {
var multiplicity;
var typeMapping = {
'Row_3': 'Aggregation',
'Row_4': 'Association',
'Row_5': 'Composition',
'Row_6': 'Dependency',
'Row_7': 'DirectedAssociation',
'Row_8': 'Inheritance',
'Row_9': 'Realization'
};
var sections = visio_core_1.ensureArray(shapes.Section);
Eif (shapeName.includes('Inheritance') || shapeName.includes('Association') || shapeName.includes('Dependency')
|| shapeName.includes('Composition') || shapeName.includes('Aggregation') || shapeName.includes('InterfaceRealization') || shapeName.includes('DirectedAssociation')) {
var shapeType = shapeName;
var actionsSection = sections.find(function (sec) { return sec.$ && sec.$.N === ACTIONS_SECTION; });
if (actionsSection && actionsSection.Row) {
var rows = visio_core_1.ensureArray(actionsSection.Row);
for (var _i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
var row = rows_1[_i];
Eif (row && row.$ && row.Cell) {
var cells = visio_core_1.ensureArray(row.Cell);
var checkedCell = cells.find(function (cell) {
return cell.$ && cell.$.N === 'Checked' && cell.$.V === '1';
});
if (checkedCell) {
var rowName = row.$.N;
if (rowName === 'Row_1') {
multiplicity = buildMultiplicity(shapes);
}
if (rowName in typeMapping) {
shapeType = typeMapping["" + rowName];
break;
}
}
}
}
}
if (shapeType === 'InterfaceRealization') {
shapeType = 'Realization';
}
return {
type: 'UmlClassifier',
relationship: shapeType,
multiplicity: multiplicity
};
}
return undefined;
}
exports.getUMLConnectors = getUMLConnectors;
function getShapeText(shape) {
Iif (!shape) {
return '';
}
if (shape.Text && typeof shape.Text.value === 'string') {
return shape.Text.value;
}
return '';
}
function buildMultiplicity(groupShape) {
var children = visio_core_1.ensureArray(groupShape && groupShape.Shapes && groupShape.Shapes.Shape);
var t0 = getShapeText(children[0]) || 'M1';
var t1 = getShapeText(children[1]) || 'M2';
var t2 = getShapeText(children[2]) || 'M3';
var t3 = getShapeText(children[3]) || 'M4';
var sourceLower = t0;
var sourceUpper = t1;
var targetLower = t2;
var targetUpper = t3;
var sourceOptional = true;
var targetOptional = true;
var type = 'ManyToMany';
return {
type: type,
source: { optional: sourceOptional, lowerBounds: sourceLower, upperBounds: sourceUpper },
target: { optional: targetOptional, lowerBounds: targetLower, upperBounds: targetUpper }
};
}
function getPropertyValue(row, propertyName) {
Iif (!row || !row.$ || row.$.N !== propertyName || !row.Cell) {
return undefined;
}
var cells = visio_core_1.ensureArray(row.Cell);
var valueCell = cells.find(function (c) { return c && c.$ && c.$.N === VALUE_CELL; });
return valueCell && valueCell.$ && valueCell.$.V != null ? String(valueCell.$.V).replace(/\s+/g, '') : undefined;
}
function createPropertyMap(section) {
var propertyMap = new Map();
if (section && section.Row) {
var propertyRows = visio_core_1.ensureArray(section.Row);
propertyRows.forEach(function (row) {
Eif (row && row.$ && row.$.N) {
var value = getPropertyValue(row, row.$.N);
if (value !== undefined) {
propertyMap.set(row.$.N, value);
}
}
});
}
return propertyMap;
}
function getEventShape(shapes, propertyMap, node) {
var eventName = 'Start';
var trigger = 'None';
var eventNameMap = {
'start(non-interrupting)': 'NonInterruptingStart',
'intermediate(non-interrupting)': 'NonInterruptingIntermediate',
'intermediate(throwing)': 'ThrowingIntermediate'
};
var triggerMap = {
'parallelmultiple': 'Parallel'
};
Eif (shapes.$.Name) {
var nameParts = shapes.$.Name.split(' ').map(function (p) { return p.trim().toLowerCase(); });
eventName = nameParts[0];
}
var bpmnEventType = propertyMap.get('BpmnEventType');
if (bpmnEventType) {
eventName = bpmnEventType;
}
var bpmnTriggerOrResult = propertyMap.get('BpmnTriggerOrResult');
if (bpmnTriggerOrResult) {
trigger = bpmnTriggerOrResult;
}
eventName = toCapitalizedWords(eventName);
trigger = toCapitalizedWords(trigger);
eventName = eventNameMap[eventName.toLowerCase()] || eventName;
trigger = triggerMap[trigger.toLowerCase()] || trigger;
var childShapes = shapes.Shapes && shapes.Shapes.Shape && visio_core_1.ensureArray(shapes.Shapes.Shape);
Eif (childShapes && childShapes.length > 0) {
var fillColorFound = false;
var strokeColorFound = false;
for (var _i = 0, childShapes_1 = childShapes; _i < childShapes_1.length; _i++) {
var childShape = childShapes_1[_i];
Eif (childShape && childShape.Cell) {
var childCell = visio_core_1.mapCellValues(childShape.Cell);
Eif (!fillColorFound) {
var fillColor = visio_core_1.getCellMapStringValue(childCell, 'FillForegnd');
Eif (fillColor !== undefined) {
Iif (node.style && node.style.fillColor === undefined) {
node.style.fillColor = fillColor;
}
fillColorFound = true;
}
}
Eif (!strokeColorFound) {
var strokeColor = visio_core_1.getCellMapStringValue(childCell, 'LineColor');
Eif (strokeColor !== undefined) {
Iif (node.style && node.style.strokeColor === undefined) {
node.style.strokeColor = strokeColor;
}
strokeColorFound = true;
}
}
Eif (fillColorFound && strokeColorFound) {
break;
}
}
}
}
return {
type: 'Bpmn',
shape: 'Event',
event: {
event: eventName,
trigger: trigger
}
};
}
function getGatewayShape(shapes, propertyMap, sections) {
var gatewayType = 'None';
var gatewayMap = {
'exclusive': 'None',
'inclusive': 'Inclusive',
'parallel': 'Parallel',
'complex': 'Complex',
'event': 'EventBased',
'eventbased': 'Exclusive',
'exclusiveevent(instantiate)': 'ExclusiveEventBased',
'parallelevent(instantiate)': 'ParallelEventBased'
};
var bpmnGatewayType = propertyMap.get('BpmnGatewayType');
if (bpmnGatewayType) {
gatewayType = bpmnGatewayType;
}
else {
var bpmnExclusiveType = propertyMap.get('BpmnExclusiveType');
if (bpmnExclusiveType) {
gatewayType = bpmnExclusiveType;
}
}
var actionsSection = sections.find(function (sec) { return sec.$ && sec.$.N === ACTIONS_SECTION; });
if (actionsSection && actionsSection.Row) {
var actionRows = visio_core_1.ensureArray(actionsSection.Row);
var exclusiveDataWithMarkerRow = actionRows.find(function (row) { return row && row.$ && row.$.N === 'ExclusiveDataWithMarker'; });
if (exclusiveDataWithMarkerRow && exclusiveDataWithMarkerRow.Cell) {
var checkedCell = visio_core_1.ensureArray(exclusiveDataWithMarkerRow.Cell).find(function (cell) { return cell && cell.$ && cell.$.N === 'Checked'; });
Eif (checkedCell && checkedCell.$.V === '1') {
gatewayType = 'eventbased';
}
}
}
var lookupKey = gatewayType.toLowerCase().replace(/\s/g, '');
var GatewayType = gatewayMap["" + lookupKey] || 'None';
return {
type: 'Bpmn',
shape: 'Gateway',
gateway: {
type: GatewayType
}
};
}
function getDataSourceShape() {
return {
type: 'Bpmn',
shape: 'DataSource'
};
}
function getMessageShape() {
return {
type: 'Bpmn',
shape: 'Message'
};
}
function getDataObjectShape(shapes, propertyMap, node) {
var isCollection = false;
var bpmnCollection = propertyMap.get('BpmnCollection');
if (bpmnCollection === '1') {
isCollection = true;
}
var childShapes = shapes.Shapes && shapes.Shapes.Shape && visio_core_1.ensureArray(shapes.Shapes.Shape);
Eif (childShapes && childShapes.length > 0) {
var fillColorFound = false;
var strokeColorFound = false;
for (var _i = 0, childShapes_2 = childShapes; _i < childShapes_2.length; _i++) {
var childShape = childShapes_2[_i];
Eif (childShape && childShape.Cell) {
var childCell = visio_core_1.mapCellValues(childShape.Cell);
Eif (!fillColorFound) {
var fillColor = visio_core_1.getCellMapStringValue(childCell, 'FillForegnd');
Eif (fillColor !== undefined) {
Iif (node.style && node.style.fillColor === undefined) {
node.style.fillColor = fillColor;
}
fillColorFound = true;
}
}
Eif (!strokeColorFound) {
var strokeColor = visio_core_1.getCellMapStringValue(childCell, 'LineColor');
Eif (strokeColor !== undefined) {
Eif (node.style && node.style.strokeColor === undefined) {
node.style.strokeColor = strokeColor;
}
strokeColorFound = true;
}
}
Eif (fillColorFound && strokeColorFound) {
break;
}
}
}
}
return {
type: 'Bpmn',
shape: 'DataObject',
dataObject: {
collection: isCollection,
type: 'None'
}
};
}
function getTextAnnotationShape(shapes) {
var direction = 'Left';
var targetId = '';
var orientationMap = {
'1': 'Right',
'2': 'Top',
'3': 'Left',
'4': 'Bottom'
};
var sections = visio_core_1.ensureArray(shapes.Section);
var userSection = sections.find(function (sec) { return sec.$ && sec.$.N === USER_SECTION; });
var propertyMap = createPropertyMap(userSection);
var orientation = propertyMap.get('Orientation');
if (orientation && orientationMap["" + orientation]) {
direction = orientationMap["" + orientation];
}
var shapeCells = visio_core_1.ensureArray(shapes.Cell);
var relationshipCell = shapeCells.find(function (cell) { return cell && cell.$ && cell.$.N === RELATIONSHIPS_CELL; });
if (relationshipCell && relationshipCell.$.F) {
targetId = getTextAnnotationTargetID(relationshipCell.$.F) || '';
}
return {
type: 'Bpmn',
shape: 'TextAnnotation',
textAnnotation: {
textAnnotationDirection: direction,
textAnnotationTarget: targetId || ''
}
};
}
function getActivityShape(shapes, propertyMap) {
var activityType = 'Task';
Eif (shapes.$.Name) {
activityType = shapes.$.Name.replace(/[^a-zA-Z]/g, '');
}
var bpmnActivityType = propertyMap.get('BpmnActivityType');
if (bpmnActivityType) {
if (bpmnActivityType === 'Sub-Process') {
activityType = 'SubProcess';
}
else Eif (bpmnActivityType === 'Task') {
activityType = 'Task';
}
}
if (activityType === 'SubProcess' || activityType === 'CollapsedSubProcess') {
return getSubProcessShape(shapes, propertyMap);
}
else {
return getTaskShape(shapes, propertyMap);
}
}
function getTaskShape(shapes, propertyMap) {
var task = {
type: 'None',
loop: 'None',
compensation: false,
call: false
};
var loopTypeMap = {
'none': 'None',
'standard': 'Standard',
'parallelmultiinstance': 'ParallelMultiInstance',
'sequentialmultiinstance': 'SequenceMultiInstance'
};
task.type = propertyMap.get('BpmnTaskType') || 'None';
task.compensation = propertyMap.get('BpmnIsForCompensation') === '1';
task.call = propertyMap.get('BpmnBoundaryType') === 'Call';
var visioLoopValue = propertyMap.get('BpmnLoopType') || 'none';
var visioLoopKey = visioLoopValue.toLowerCase();
task.loop = loopTypeMap["" + visioLoopKey] || visioLoopValue;
return {
type: 'Bpmn',
shape: 'Activity',
activity: {
activity: 'Task',
task: task
}
};
}
function getSubProcessShape(shapes, propertyMap) {
var subProcess = {
type: 'None', loop: 'None', compensation: false, adhoc: false,
collapsed: true, boundary: 'Default'
};
var loopTypeMap = {
'none': 'None', 'standard': 'Standard', 'parallelmultiinstance': 'ParallelMultiInstance',
'sequentialmultiinstance': 'SequenceMultiInstance'
};
subProcess.type = 'None';
subProcess.compensation = propertyMap.get('BpmnIsForCompensation') === '1';
subProcess.adhoc = propertyMap.get('BpmnAdHoc') === '1';
var isCollapsedValue = propertyMap.get('BpmnIsCollapsed');
subProcess.collapsed = isCollapsedValue !== '0';
var visioLoopValue = propertyMap.get('BpmnLoopType') || 'none';
var visioLoopKey = visioLoopValue.toLowerCase();
subProcess.loop = loopTypeMap["" + visioLoopKey] || visioLoopValue;
subProcess.boundary = propertyMap.get('BpmnBoundaryType') || 'Default';
return {
type: 'Bpmn',
shape: 'Activity',
activity: {
activity: 'SubProcess',
subProcess: subProcess
}
};
}
function getExpandedSubProcessShape(shapes, propertyMap, Node, context) {
var subProcess = {
loop: 'None',
compensation: false,
adhoc: false,
collapsed: false,
boundary: 'Default',
processes: []
};
var loopTypeMap = {
'none': 'None', 'standard': 'Standard', 'parallelmultiinstance': 'ParallelMultiInstance',
'sequentialmultiinstance': 'SequenceMultiInstance'
};
subProcess.compensation = propertyMap.get('BpmnIsForCompensation') === '1';
subProcess.adhoc = propertyMap.get('BpmnAdHoc') === '1';
subProcess.boundary = propertyMap.get('BpmnBoundaryType') || 'Default';
var visioLoopValue = propertyMap.get('BpmnLoopType') || 'none';
var visioLoopKey = visioLoopValue.toLowerCase();
subProcess.loop = loopTypeMap["" + visioLoopKey] || visioLoopValue;
Node.AllowDrop = true;
var shapeCells = visio_core_1.ensureArray(shapes.Cell);
var relationshipCell = shapeCells.find(function (cell) { return cell && cell.$ && cell.$.N === RELATIONSHIPS_CELL; });
if (relationshipCell && relationshipCell.$.F) {
var processIDs = getProcessIDs(shapes);
if (processIDs.length > 0) {
subProcess.processes = processIDs;
}
}
var shapeID = getShapeId(shapes);
Eif (shapeID) {
context.data.expandedSubprocessCollection.push(shapeID);
}
return {
type: 'Bpmn',
shape: 'Activity',
activity: {
activity: 'SubProcess',
subProcess: subProcess
}
};
}
function getShapeId(shapes) {
return shapes && shapes.$ && shapes.$.ID != null ? String(shapes.$.ID) : '';
}
function getGroupShape(shapes) {
var shapeCells = visio_core_1.ensureArray(shapes.Cell);
var relationshipCell = shapeCells.find(function (cell) { return cell && cell.$ && cell.$.N === RELATIONSHIPS_CELL; });
return {
type: 'Bpmn',
shape: 'Group'
};
}
function getProcessIDs(shape) {
var processIDs = [];
var relationsCell = visio_core_1.ensureArray(shape.Cell).find(function (c) { return c.$.N === RELATIONSHIPS_CELL; });
Eif (relationsCell && relationsCell.$.F) {
var formula = relationsCell.$.F;
var sumArgsRegex = /SUM\((.*)\)/;
var sumMatch = formula.match(sumArgsRegex);
Eif (sumMatch && sumMatch[1]) {
var argsString = sumMatch[1];
var dependsonCallSplitter = /,(?=\s*DEPENDSON\()/g;
var individualDependsonCalls = argsString.split(dependsonCallSplitter);
for (var _i = 0, individualDependsonCalls_1 = individualDependsonCalls; _i < individualDependsonCalls_1.length; _i++) {
var call = individualDependsonCalls_1[_i];
if (call.startsWith('DEPENDSON(1,')) {
var sheetIdExtractorRegex = /Sheet\.(\d+)!SheetRef\(\)/g;
var sheetIdExtractMatch = void 0;
sheetIdExtractMatch = sheetIdExtractorRegex.exec(call);
while (sheetIdExtractMatch !== null) {
Eif (sheetIdExtractMatch[1]) {
processIDs.push(sheetIdExtractMatch[1]);
}
sheetIdExtractMatch = sheetIdExtractorRegex.exec(call);
}
}
}
}
}
return processIDs;
}
function getTextAnnotationTargetID(formula) {
Iif (!formula) {
return null;
}
var match = formula.match(/Sheet\.(\d+)!/);
Eif (match && match.length > 1) {
return match[1];
}
return null;
}
function toCapitalizedWords(str) {
return str.split(' ').map(function (word) { return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); }).join('');
}
function getIndex(context) {
var entries = context.entries;
return entries && entries.__Index ? entries.__Index : null;
}
function resolveMasterSourceForNode(pageNode, context, parentMasterId) {
var attributes = (pageNode && pageNode.$) ? pageNode.$ : {};
var masterShapeId = (attributes && attributes.MasterShape != null) ? String(attributes.MasterShape) : '';
var masterId = (attributes && attributes.Master != null) ? String(attributes.Master) : '';
var idx = getIndex(context);
if (!idx) {
return null;
}
var owningMaster = '';
if (masterShapeId && parentMasterId && parentMasterId.length > 0) {
owningMaster = parentMasterId;
}
else if (masterId) {
owningMaster = masterId;
}
else if (masterShapeId) {
var masterChildIndex = idx.masterChildByMasterId;
Eif (masterChildIndex && typeof masterChildIndex.forEach === 'function') {
masterChildIndex.forEach(function (childMap, masterKey) {
if (!owningMaster && childMap && typeof childMap.has === 'function' && childMap.has(String(masterShapeId))) {
owningMaster = String(masterKey);
}
});
}
}
if (masterShapeId && owningMaster) {
var childMap = idx.masterChildByMasterId && idx.masterChildByMasterId.get
? idx.masterChildByMasterId.get(String(owningMaster)) : null;
Eif (childMap && childMap.get) {
var node = childMap.get(String(masterShapeId));
Eif (node) {
return node;
}
}
}
if (masterId) {
var roots = idx.masterRootIdsByMasterId && idx.masterRootIdsByMasterId.get
? idx.masterRootIdsByMasterId.get(String(masterId)) : [];
var childMap2 = idx.masterChildByMasterId && idx.masterChildByMasterId.get
? idx.masterChildByMasterId.get(String(masterId)) : null;
Eif (childMap2 && roots && roots.length > 0) {
var rootNode = childMap2.get(String(roots[0]));
Eif (rootNode) {
return rootNode;
}
}
}
return null;
}
exports.resolveMasterSourceForNode = resolveMasterSourceForNode;
function resolveShapeNameForMapping(pageNode, masterSource, context, parentMasterId) {
var attributes = pageNode && pageNode.$ ? pageNode.$ : {};
var typeStr = visio_core_1.getAttrString(attributes, 'Type');
if (typeStr && typeStr.toLowerCase() === 'foreign') {
return 'Image';
}
var instNameU = visio_core_1.getTrimmedOrEmpty(visio_core_1.getAttrString(attributes, 'NameU'));
if (instNameU) {
return instNameU;
}
var instName = visio_core_1.getTrimmedOrEmpty(visio_core_1.getAttrString(attributes, 'Name'));
if (instName) {
return instName;
}
var hasMasterShape = visio_core_1.getTrimmedOrEmpty(visio_core_1.getAttrString(attributes, 'MasterShape')).length > 0;
var hasMaster = visio_core_1.getTrimmedOrEmpty(visio_core_1.getAttrString(attributes, 'Master')).length > 0;
if (masterSource && masterSource.$) {
var msAttrs = masterSource.$;
var msNameU = visio_core_1.getTrimmedOrEmpty(visio_core_1.getAttrString(msAttrs, 'NameU'));
if (msNameU) {
return msNameU;
}
var msName = visio_core_1.getTrimmedOrEmpty(visio_core_1.getAttrString(msAttrs, 'Name'));
Iif (msName) {
return msName;
}
}
if (hasMasterShape && !hasMaster) {
return '';
}
var masterId = hasMaster ? visio_core_1.getTrimmedOrEmpty(visio_core_1.getAttrString(attributes, 'Master'))
: (parentMasterId ? visio_core_1.getTrimmedOrEmpty(String(parentMasterId)) : '');
if (!masterId) {
return '';
}
var idx = getIndex(context);
Iif (!idx || !idx.mastersById || !idx.mastersById.get) {
return '';
}
var masterInfo = idx.mastersById.get(String(masterId));
Iif (!masterInfo) {
return '';
}
var nameU = visio_core_1.getTrimmedOrEmpty(masterInfo.nameU ? String(masterInfo.nameU) : '');
Eif (nameU) {
return nameU;
}
return '';
}
exports.resolveShapeNameForMapping = resolveShapeNameForMapping;
function buildPathShapeFromGeometrySections(geomSections, node) {
var finalPath = '';
if (geomSections && geomSections.length > 1) {
finalPath = visio_core_1.formatPathData(visio_core_1.createPathFromGeometrySections(geomSections, { pinX: 0, pinY: 0, Width: node.width, Height: node.height }, { useLocalScaling: true }));
}
else {
var pathData = '';
var sectionsArr = visio_core_1.ensureArray(geomSections);
for (var _i = 0, sectionsArr_1 = sectionsArr; _i < sectionsArr_1.length; _i++) {
var section = sectionsArr_1[_i];
Iif (!section || !section.Row) {
continue;
}
var part = visio_core_1.createPathFromGeometry({ Row: visio_core_1.ensureArray(section.Row), width: node.width, height: node.height }, { pinX: 0, pinY: 0, Width: node.width, Height: node.height }, undefined, { useLocalScaling: true });
if (part && part.length > 0) {
pathData += part.trim() + ' ';
}
}
finalPath = visio_core_1.formatPathData(pathData.trim());
}
return { type: 'Path', data: finalPath };
}
function determineDefaultNodeShape(pageNode, masterSource, geomSections, node, context, parentMasterId) {
var resolvedName = resolveShapeNameForMapping(pageNode, masterSource, context, parentMasterId);
var attributes = pageNode && pageNode.$ ? pageNode.$ : {};
var mappingAttrs = {
Name: (resolvedName !== undefined && resolvedName !== null) ? String(resolvedName) : '',
Type: visio_core_1.getAttrString(attributes, 'Type')
};
var mapped = determineShapeType(mappingAttrs, undefined, masterSource ? masterSource : pageNode, node, context);
if (mapped && mapped.type && mapped.type !== 'Path') {
return mapped;
}
return buildPathShapeFromGeometrySections(geomSections, node);
}
exports.determineDefaultNodeShape = determineDefaultNodeShape;
function tryDetermineSemanticGroupShape(groupNode, groupMasterNode, groupShape, context, parentMasterId) {
var attrs = groupNode && groupNode.$ ? groupNode.$ : {};
var masterId = visio_core_1.getTrimmedOrEmpty(visio_core_1.getAttrString(attrs, 'Master'));
if (!masterId) {
return null;
}
var resolvedName = resolveShapeNameForMapping(groupNode, groupMasterNode, context, parentMasterId);
Iif (!resolvedName) {
return null;
}
var mapped = determineShapeType({ Name: String(resolvedName), Type: 'Group' }, undefined, groupNode, groupShape, context);
if (!mapped || !mapped.type) {
return null;
}
var t = String(mapped.type);
if (t === 'Bpmn' || t === 'UmlClassifier' || t === 'UmlActivity' || t === 'Image') {
return mapped;
}
return null;
}
exports.tryDetermineSemanticGroupShape = tryDetermineSemanticGroupShape;
function getGeometrySectionsByIX(node) {
var geometrySectionsByIX = new Map();
Iif (!node) {
return geometrySectionsByIX;
}
var sections = visio_core_1.ensureArray(node.Section);
var syntheticKeyCounter = 0;
for (var sectionIndex = 0; sectionIndex < sections.length; sectionIndex += 1) {
var section = sections[parseInt(sectionIndex.toString(), 10)];
if (!section || !section.$ || section.$.N !== 'Geometry') {
continue;
}
var sectionKey = '';
var sectionAttributes = section.$;
var ixValue = sectionAttributes.IX;
Eif (ixValue !== null && ixValue !== undefined) {
sectionKey = String(ixValue);
}
else {
sectionKey = 'g' + String(syntheticKeyCounter);
syntheticKeyCounter += 1;
}
geometrySectionsByIX.set(sectionKey, section);
}
return geometrySectionsByIX;
}
function mergeGeometrySectionsByIndex(masterNode, instNode) {
var masterSectionMap = getGeometrySectionsByIX(masterNode);
var instanceSectionMap = getGeometrySectionsByIX(instNode);
var resultSections = [];
if (!instanceSectionMap || instanceSectionMap.size === 0) {
masterSectionMap.forEach(function (section) {
resultSections.push(section);
});
return resultSections;
}
if (!masterSectionMap || masterSectionMap.size === 0) {
instanceSectionMap.forEach(function (section) {
resultSections.push(section);
});
return resultSections;
}
var processedSectionKeys = new Set();
instanceSectionMap.forEach(function (instanceSection, sectionKey) {
var masterSection = masterSectionMap.get(sectionKey);
Eif (masterSection) {
resultSections.push(mergeOneSectionDeep(masterSection, instanceSection));
}
else {
resultSections.push(instanceSection);
}
processedSectionKeys.add(sectionKey);
});
masterSectionMap.forEach(function (masterSection, sectionKey) {
Iif (!processedSectionKeys.has(sectionKey)) {
resultSections.push(masterSection);
}
});
return resultSections;
function mergeOneSectionDeep(masterSection, instanceSection) {
var masterSectionCells = masterSection && masterSection.Cell ? visio_core_1.ensureArray(masterSection.Cell) : [];
var instanceSectionCells = instanceSection && instanceSection.Cell ? visio_core_1.ensureArray(instanceSection.Cell) : [];
var mergedSectionCells = mergeCellsNumericOnly(masterSectionCells, instanceSectionCells);
var masterRowArray = masterSection && masterSection.Row ? visio_core_1.ensureArray(masterSection.Row) : [];
var instanceRowArray = instanceSection && instanceSection.Row ? visio_core_1.ensureArray(instanceSection.Row) : [];
var instanceRowsByIX = new Map();
var instanceRowsByPosition = new Map();
var instancePositionCounter = 0;
for (var instanceRowIndex = 0; instanceRowIndex < instanceRowArray.length; instanceRowIndex += 1) {
var instanceRow = instanceRowArray[parseInt(instanceRowIndex.toString(), 10)];
var rowIndexString = '';
Eif (instanceRow && instanceRow.$) {
var rowAttributes = instanceRow.$;
var ixAttribute = rowAttributes.IX;
Eif (ixAttribute !== undefined && ixAttribute !== null) {
rowIndexString = String(ixAttribute);
}
}
Eif (rowIndexString.length > 0) {
instanceRowsByIX.set(rowIndexString, instanceRow);
}
else {
var positionKey = 'pos_' + String(instancePositionCounter);
instanceRowsByPosition.set(positionKey, instanceRow);
instancePositionCounter += 1;
}
}
var mergedRowArray = [];
var masterKeySet = new Set();
var masterPositionCounter = 0;
for (var masterRowIndex = 0; masterRowIndex < masterRowArray.length; masterRowIndex += 1) {
var masterRow = masterRowArray[parseInt(masterRowIndex.toString(), 10)];
var masterRowIndexString = '';
Eif (masterRow && masterRow.$) {
var masterRowAttributes = masterRow.$;
var masterIxAttribute = masterRowAttributes.IX;
Eif (masterIxAttribute !== undefined && masterIxAttribute !== null) {
masterRowIndexString = String(masterIxAttribute);
}
}
var masterPositionKey = resolveRowPositionKey(masterRow, masterPositionCounter);
var mergedRow = void 0;
if (masterRowIndexString.length > 0 && instanceRowsByIX.has(masterRowIndexString)) {
var matchingInstanceRow = instanceRowsByIX.get(masterRowIndexString);
mergedRow = mergeRowCellsNumericOnly(masterRow, matchingInstanceRow);
}
else {
var fallbackInstanceRow = instanceRowsByPosition.get(masterPositionKey);
mergedRow = mergeRowCellsNumericOnly(masterRow, fallbackInstanceRow);
}
mergedRowArray.push(mergedRow);
masterKeySet.add(masterRowIndexString.length > 0 ? masterRowIndexString : masterPositionKey);
masterPositionCounter += 1;
}
instanceRowsByIX.forEach(function (instanceRow, instanceRowIX) {
if (!masterKeySet.has(instanceRowIX)) {
mergedRowArray.push(sanitizeRowShallow(instanceRow));
}
});
instanceRowsByPosition.forEach(function (instanceRow, positionKey) {
if (!masterKeySet.has(positionKey)) {
mergedRowArray.push(sanitizeRowShallow(instanceRow));
}
});
var mergedSection = { $: masterSection.$ };
Eif (mergedSectionCells.length > 0) {
mergedSection.Cell = mergedSectionCells;
}
Eif (mergedRowArray.length > 0) {
mergedSection.Row = mergedRowArray;
}
return mergedSection;
function resolveRowPositionKey(row, position) {
Eif (row && row.$) {
var rowAttributes = row.$;
var ixAttribute = rowAttributes.IX;
Eif (ixAttribute !== undefined && ixAttribute !== null) {
return String(ixAttribute);
}
}
return 'pos_' + String(position);
}
function mergeRowCellsNumericOnly(masterRow, instanceRow) {
var masterRowCells = masterRow && masterRow.Cell ? visio_core_1.ensureArray(masterRow.Cell) : [];
var instanceRowCells = instanceRow && instanceRow.Cell ? visio_core_1.ensureArray(instanceRow.Cell) : [];
var mergedCells = mergeCellsNumericOnly(masterRowCells, instanceRowCells);
var resultRow = { $: masterRow.$ };
Eif (mergedCells.length > 0) {
resultRow.Cell = mergedCells;
}
return resultRow;
}
function sanitizeRowShallow(sourceRow) {
var sanitizedRow = { $: sourceRow.$ };
var sourceRowCells = sourceRow && sourceRow.Cell ? visio_core_1.ensureArray(sourceRow.Cell) : [];
var sanitizedCells = [];
for (var cellIndex = 0; cellIndex < sourceRowCells.length; cellIndex += 1) {
var currentCell = sourceRowCells[parseInt(cellIndex.toString(), 10)];
sanitizedCells.push(cloneNameV(currentCell));
}
Eif (sanitizedCells.length > 0) {
sanitizedRow.Cell = sanitizedCells;
}
return sanitizedRow;
}
}
function mapCellsByName(cells) {
var cellsByName = new Map();
for (var cellIndex = 0; cellIndex < cells.length; cellIndex += 1) {
var cell = cells[parseInt(cellIndex.toString(), 10)];
Eif (cell && cell.$ && cell.$.N) {
cellsByName.set(String(cell.$.N), cell);
}
}
return cellsByName;
}
function hasNumericV(cell) {
Iif (!cell || !cell.$) {
return false;
}
var cellAttributes = cell.$;
var vAttribute = cellAttributes.V;
Iif (vAttribute === undefined || vAttribute === null) {
return false;
}
var numericValue = parseFloat(String(vAttribute));
Iif (!isFinite(numericValue)) {
return false;
}
return true;
}
function cloneNameV(sourceCell) {
var cellName = '';
Eif (sourceCell && sourceCell.$ && sourceCell.$.N) {
cellName = String(sourceCell.$.N);
}
var cellValue;
Eif (sourceCell && sourceCell.$) {
var sourceAttributes = sourceCell.$;
var vAttribute = sourceAttributes.V;
Eif (vAttribute !== undefined && vAttribute !== null) {
Iif (typeof vAttribute === 'number') {
cellValue = vAttribute;
}
else {
cellValue = String(vAttribute);
}
}
}
var clonedCell = { $: { N: cellName } };
Eif (cellValue !== undefined && cellValue !== null) {
clonedCell.$.V = cellValue;
}
return clonedCell;
}
function mergeCellsNumericOnly(masterCells, instanceCells) {
var masterCellsByName = mapCellsByName(masterCells);
var instanceCellsByName = mapCellsByName(instanceCells);
var mergedCells = [];
masterCellsByName.forEach(function (masterCell, cellName) {
var instanceCell = instanceCellsByName.get(cellName);
if (instanceCell) {
Eif (hasNumericV(instanceCell)) {
mergedCells.push(cloneNameV(instanceCell));
}
else {
mergedCells.push(cloneNameV(masterCell));
}
}
else {
mergedCells.push(cloneNameV(masterCell));
}
});
return mergedCells;
}
}
exports.mergeGeometrySectionsByIndex = mergeGeometrySectionsByIndex;
function allGeometrySectionsNoFill(sections) {
var geometrySections = visio_core_1.ensureArray(sections);
if (!geometrySections || geometrySections.length === 0) {
return false;
}
for (var sectionIndex = 0; sectionIndex < geometrySections.length; sectionIndex++) {
var geometrySection = geometrySections[parseInt(sectionIndex.toString(), 10)];
Iif (!geometrySection) {
return false;
}
var noFillValue = 0;
if (geometrySection.Cell) {
var cellMap = visio_core_1.createCellMap(visio_core_1.ensureArray(geometrySection.Cell));
var noFillCell = cellMap.get('NoFill');
noFillValue = visio_core_1.safeNumber(noFillCell);
}
if (noFillValue !== 1) {
return false;
}
}
return true;
}
exports.allGeometrySectionsNoFill = allGeometrySectionsNoFill;
function allGeometrySectionsNoLine(sections) {
var geometrySections = visio_core_1.ensureArray(sections);
if (!geometrySections || geometrySections.length === 0) {
return false;
}
for (var sectionIndex = 0; sectionIndex < geometrySections.length; sectionIndex++) {
var geometrySection = geometrySections[parseInt(sectionIndex.toString(), 10)];
Iif (!geometrySection) {
return false;
}
var noLineValue = 0;
if (geometrySection.Cell) {
var cellMap = visio_core_1.createCellMap(visio_core_1.ensureArray(geometrySection.Cell));
var noLineCell = cellMap.get('NoLine');
noLineValue = visio_core_1.safeNumber(noLineCell);
}
if (noLineValue !== 1) {
return false;
}
}
return true;
}
exports.allGeometrySectionsNoLine = allGeometrySectionsNoLine;
function isGeometrySectionHidden(section) {
Iif (!section) {
return false;
}
if (section.Cell) {
var cellMap = visio_core_1.createCellMap(visio_core_1.ensureArray(section.Cell));
var noShowValue = cellMap.get('NoShow');
var hidden = visio_core_1.safeNumber(noShowValue) === 1;
if (hidden) {
return true;
}
}
return false;
}
exports.isGeometrySectionHidden = isGeometrySectionHidden;
function isGeometryRowHidden(row) {
Iif (!row) {
return false;
}
Eif (row.Cell) {
var cellMap = visio_core_1.createCellMap(visio_core_1.ensureArray(row.Cell));
var noShowValue = cellMap.get('NoShow');
Iif (visio_core_1.safeNumber(noShowValue) === 1) {
return true;
}
}
return false;
}
exports.isGeometryRowHidden = isGeometryRowHidden;
function areAllGeometrySectionsHidden(sections) {
var allSections = visio_core_1.ensureArray(sections);
if (!allSections || allSections.length === 0) {
return false;
}
for (var i = 0; i < allSections.length; i++) {
var section = allSections[parseInt(i.toString(), 10)];
if (!isGeometrySectionHidden(section)) {
return false;
}
}
return true;
}
exports.areAllGeometrySectionsHidden = areAllGeometrySectionsHidden;
});
|