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 | 1×
1×
1×
9×
9×
9×
9×
63×
1×
1×
1123×
1123×
1123×
1123×
1123×
1123×
1123×
1123×
1123×
1123×
1123×
1123×
1123×
29044×
29044×
1123×
1123×
1×
1×
91026×
91026×
91026×
91026×
91026×
1×
1×
36434×
36434×
36434×
36434×
917252×
917252×
917252×
917252×
917252×
917252×
917252×
2799×
2799×
1330×
1330×
840×
840×
912283×
912283×
917252×
917252×
917252×
9351×
9351×
917252×
9351×
917252×
36434×
1×
1×
74410×
41156×
41156×
41156×
41156×
41156×
41156×
41156×
41156×
41156×
33254×
1×
1×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
1×
16987×
16987×
16987×
16987×
16987×
16987×
16976×
622×
622×
622×
10074×
10074×
2×
2×
10072×
10072×
2×
2×
10072×
10072×
134×
134×
10072×
618×
618×
16354×
11×
16987×
1×
16354×
16354×
16354×
16354×
16354×
16354×
16354×
16354×
16354×
16354×
16354×
16354×
16354×
17435×
17435×
17435×
27342×
27342×
9636×
17706×
27342×
27342×
3107×
3107×
24235×
16150×
16150×
27342×
27342×
16354×
1×
16987×
16987×
16987×
16987×
16987×
20024×
20024×
20024×
318×
19706×
19687×
33×
19654×
19×
19×
20024×
20024×
20024×
20024×
16987×
1×
57×
57×
57×
6×
57×
2×
57×
57×
57×
57×
57×
57×
57×
57×
57×
57×
57×
57×
57×
57×
57×
57×
1×
1×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
16987×
24×
16987×
16987×
1×
1×
19×
19×
19×
19×
19×
19×
19×
19×
19×
19×
19×
19×
19×
19×
16×
16×
19×
1×
1×
96×
96×
96×
96×
96×
96×
96×
96×
96×
96×
96×
96×
1×
1×
23×
23×
23×
23×
23×
23×
23×
23×
1×
1×
1242×
1242×
1242×
1242×
1242×
1242×
1242×
1242×
1242×
1053×
1053×
1242×
1230×
1230×
1230×
1242×
1242×
1242×
1242×
1242×
1×
1×
9208×
9208×
9208×
9208×
1×
1×
142158×
142158×
142158×
6434×
142158×
142158×
142158×
1×
1×
7171×
7171×
7171×
7171×
2×
2×
7169×
5×
5×
7164×
7164×
7171×
7171×
187197×
187197×
5873×
5873×
7171×
1×
1×
51044×
51044×
51044×
51044×
51044×
1×
1×
17340×
17340×
17340×
17340×
1×
1×
5474×
5474×
5474×
5474×
1×
1×
16887×
16887×
16887×
16887×
16887×
1×
1×
7164×
7164×
7164×
1×
1×
2153×
2153×
2153×
2153×
2153×
1×
1×
2197×
2197×
2197×
2197×
2197×
1×
1×
9886×
9886×
9886×
9886×
9886×
1×
1×
2303×
2303×
2303×
2303×
1×
1×
4×
4×
4×
4×
4×
1×
1×
14250×
14250×
14250×
14250×
14250×
1×
1×
4825×
4825×
4825×
1305×
1305×
1305×
3520×
4825×
1×
1×
44×
44×
44×
44×
1×
1×
27588×
27588×
27588×
1328×
1328×
1328×
1328×
26260×
27588×
1×
1×
18166×
18166×
18166×
1×
1×
116988×
116988×
116988×
1×
1×
171×
171×
371×
124×
247×
171×
1×
1×
1070×
1070×
1×
1×
1302×
1302×
1302×
1302×
1302×
1302×
1302×
1302×
1302×
1×
1×
3×
3×
6×
3×
1×
1×
24540×
24540×
185×
1×
1×
237×
237×
137×
137×
100×
237×
237×
237×
237×
237×
237×
191×
191×
70×
70×
70×
70×
70×
70×
70×
70×
70×
191×
46×
46×
237×
237×
237×
237×
237×
229×
229×
229×
229×
229×
232×
232×
8×
7×
7×
7×
7×
7×
7×
7×
1×
1×
237×
1×
1×
544969×
544969×
3024220×
3012803×
11417×
1×
1×
79084×
79084×
282902×
282902×
257629×
1×
1×
20848×
20848×
40766×
23812×
16954×
1×
1×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1355×
1057×
298×
1×
1×
11102×
47×
47×
11055×
1×
1×
17×
2×
2×
15×
17×
1×
1×
1302×
1302×
1302×
1302×
1302×
1302×
1302×
1302×
1302×
2×
2×
5×
5×
5×
5×
5×
5×
5×
5×
1×
| define(["require", "exports", "../primitives/rect", "../primitives/size", "./path-util", "./base-util", "../primitives/matrix", "@syncfusion/ej2-base", "../objects/node", "./diagram-util", "../utility/base-util"], function (require, exports, rect_1, size_1, path_util_1, base_util_1, matrix_1, ej2_base_1, node_1, diagram_util_1, base_util_2) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function removeElementsByClass(className, id) {
var elements;
Iif (id && document.getElementById(id).classList.contains(className)) {
elements = document.getElementById(id).getElementsByClassName(className);
}
else {
elements = document.getElementsByClassName(className);
}
while (elements.length > 0) {
elements[0].parentNode.removeChild(elements[0]);
}
}
exports.removeElementsByClass = removeElementsByClass;
function findSegmentPoints(element) {
var pts = [];
var sample;
var sampleLength;
var measureWindowElement = 'measureElement';
window["" + measureWindowElement].style.visibility = 'visible';
var svg = window["" + measureWindowElement].children[2];
var pathNode = getChildNode(svg)[0];
pathNode.setAttributeNS(null, 'd', element.data);
var pathBounds = element.absoluteBounds;
var pathData = updatePath(element, pathBounds, element);
pathNode.setAttributeNS(null, 'd', pathData);
var pathLength = pathNode.getTotalLength();
for (sampleLength = 0; sampleLength <= pathLength; sampleLength += 10) {
sample = pathNode.getPointAtLength(sampleLength);
pts.push({ x: sample.x, y: sample.y });
}
window["" + measureWindowElement].style.visibility = 'hidden';
return pts;
}
exports.findSegmentPoints = findSegmentPoints;
function getChildNode(node) {
var child;
var collection = [];
Iif (ej2_base_1.Browser.info.name === 'msie' || ej2_base_1.Browser.info.name === 'edge') {
for (var i = 0; i < node.childNodes.length; i++) {
child = node.childNodes[parseInt(i.toString(), 10)];
if (child.nodeType === 1) {
collection.push(child);
}
}
}
else {
collection = node.children;
}
return collection;
}
exports.getChildNode = getChildNode;
function translatePoints(element, points) {
var translatedPts = [];
var left = element.offsetX - element.actualSize.width * element.pivot.x;
var top = element.offsetY - element.actualSize.height * element.pivot.y;
for (var _i = 0, points_1 = points; _i < points_1.length; _i++) {
var point = points_1[_i];
var pt1 = void 0;
var baseX = left + point.x;
var baseY = top + point.y;
var flipX = left + element.actualSize.width - point.x;
var flipY = top + element.actualSize.height - point.y;
switch (element.flip) {
case 'Both':
pt1 = { x: flipX, y: flipY };
break;
case 'Horizontal':
pt1 = { x: flipX, y: baseY };
break;
case 'Vertical':
pt1 = { x: baseX, y: flipY };
break;
default:
pt1 = { x: baseX, y: baseY };
break;
}
var matrix = void 0;
var angle = element.rotateAngle + element.parentTransform;
if (angle) {
matrix = matrix_1.identityMatrix();
matrix_1.rotateMatrix(matrix, angle, element.offsetX, element.offsetY);
}
if (matrix) {
pt1 = matrix_1.transformPointByMatrix(matrix, pt1);
}
translatedPts.push(pt1);
}
return translatedPts;
}
exports.translatePoints = translatePoints;
function measurePath(data) {
if (data) {
var measureWindowElement = 'measureElement';
window["" + measureWindowElement].style.visibility = 'visible';
var svg = window["" + measureWindowElement].children[2];
var element = getChildNode(svg)[0];
element.setAttribute('d', data);
var bounds = element.getBBox();
var svgBounds = new rect_1.Rect(bounds.x, bounds.y, bounds.width, bounds.height);
window["" + measureWindowElement].style.visibility = 'hidden';
return svgBounds;
}
return new rect_1.Rect(0, 0, 0, 0);
}
exports.measurePath = measurePath;
function getTextOptions(element, maxWidth) {
var options = {
fill: element.style.fill, stroke: element.style.strokeColor, angle: element.rotateAngle + element.parentTransform,
pivotX: element.pivot.x, pivotY: element.pivot.y, strokeWidth: element.style.strokeWidth,
dashArray: element.style.strokeDashArray, opacity: element.style.opacity, shadow: element.shadow,
gradient: element.style.gradient, visible: element.visible, id: element.id, description: element.description,
width: maxWidth || element.actualSize.width, height: element.actualSize.height,
x: element.offsetX - element.actualSize.width * element.pivot.x + 0.5,
y: element.offsetY - element.actualSize.height * element.pivot.y + 0.5
};
options.fontSize = element.style.fontSize;
options.fontFamily = element.style.fontFamily;
options.textOverflow = element.style.textOverflow;
options.textDecoration = element.style.textDecoration;
options.doWrap = element.doWrap;
options.whiteSpace = base_util_1.whiteSpaceToString(element.style.whiteSpace, element.style.textWrapping);
options.content = element.content;
options.textWrapping = element.style.textWrapping;
options.breakWord = base_util_1.wordBreakToString(element.style.textWrapping);
options.textAlign = base_util_1.textAlignToString(element.style.textAlign);
options.color = element.style.color;
options.italic = element.style.italic;
options.bold = element.style.bold;
options.dashArray = '';
options.strokeWidth = 0;
options.fill = '';
return options;
}
function wrapSvgText(text, textValue, laneWidth) {
var childNodes = [];
var k = 0;
var txtValue;
var bounds1;
var content = textValue || text.content;
if (text.whiteSpace !== 'nowrap' && text.whiteSpace !== 'pre') {
if (text.breakWord === 'breakall') {
txtValue = '';
txtValue += content[0];
for (k = 0; k < content.length; k++) {
bounds1 = base_util_1.bBoxText(txtValue, text);
if (bounds1 >= text.width && txtValue.length > 0) {
childNodes[childNodes.length] = { text: txtValue, x: 0, dy: 0, width: bounds1 };
txtValue = '';
}
else {
txtValue = txtValue + (content[k + 1] || '');
if (txtValue.indexOf('\n') > -1) {
childNodes[childNodes.length] = { text: txtValue, x: 0, dy: 0, width: base_util_1.bBoxText(txtValue, text) };
txtValue = '';
}
var width = base_util_1.bBoxText(txtValue, text);
if (Math.ceil(width) + 2 >= text.width && txtValue.length > 0) {
childNodes[childNodes.length] = { text: txtValue, x: 0, dy: 0, width: width };
txtValue = '';
}
if (k === content.length - 1 && txtValue.length > 0) {
childNodes[childNodes.length] = { text: txtValue, x: 0, dy: 0, width: width };
txtValue = '';
}
}
}
}
else {
childNodes = wordWrapping(text, textValue, laneWidth);
}
}
else {
childNodes[childNodes.length] = { text: content, x: 0, dy: 0, width: base_util_1.bBoxText(content, text) };
}
return childNodes;
}
function wordWrapping(text, textValue, laneWidth) {
var childNodes = [];
var txtValue = '';
var j = 0;
var i = 0;
var wrap = text.whiteSpace !== 'nowrap' ? true : false;
var content = textValue || text.content;
var eachLine = content.split('\n');
var txt;
var words;
var newText;
var existingWidth;
var existingText;
for (j = 0; j < eachLine.length; j++) {
txt = '';
words = text.textWrapping !== 'NoWrap' ? eachLine[parseInt(j.toString(), 10)].split(' ') : (text.textWrapping === 'NoWrap') ? [eachLine[parseInt(j.toString(), 10)]] : eachLine;
for (i = 0; i < words.length; i++) {
txtValue += (((i !== 0 || words.length === 1) && wrap && txtValue.length > 0) ? ' ' : '') + words[parseInt(i.toString(), 10)];
if (words[i + 1]) {
newText = txtValue + ' ' + (words[i + 1]);
}
else {
newText = txtValue;
}
var width = base_util_1.bBoxText(newText, text);
if (Math.floor(width) > (laneWidth || text.width) - 2 && txtValue.length > 0) {
childNodes[childNodes.length] = {
text: txtValue, x: 0, dy: 0,
width: newText === txtValue ? width : (txtValue === existingText) ? existingWidth : base_util_1.bBoxText(txtValue, text)
};
txtValue = '';
}
else {
if (i === words.length - 1) {
childNodes[childNodes.length] = { text: txtValue, x: 0, dy: 0, width: width };
txtValue = '';
}
}
existingText = newText;
existingWidth = width;
}
}
return childNodes;
}
function wrapSvgTextAlign(text, childNodes) {
var wrapBounds = { x: 0, width: 0 };
var k = 0;
var txtWidth;
var width;
for (k = 0; k < childNodes.length; k++) {
txtWidth = childNodes[parseInt(k.toString(), 10)].width;
width = txtWidth;
if (text.textAlign === 'left' || text.textAlign === 'justify') {
txtWidth = 0;
}
else if (text.textAlign === 'center') {
if (txtWidth > text.width && (text.textOverflow === 'Ellipsis' || text.textOverflow === 'Clip')) {
txtWidth = 0;
}
else {
txtWidth = -txtWidth / 2;
}
}
else Eif (text.textAlign === 'right') {
txtWidth = -txtWidth;
}
else {
txtWidth = childNodes.length > 1 ? 0 : -txtWidth / 2;
}
childNodes[parseInt(k.toString(), 10)].dy = text.fontSize * 1.2;
childNodes[parseInt(k.toString(), 10)].x = txtWidth;
wrapBounds.x = Math.min(wrapBounds.x, txtWidth);
wrapBounds.width = Math.max(wrapBounds.width, width);
}
return wrapBounds;
}
function measureHtmlText(style, content, width, height, maxWidth) {
var bounds = new size_1.Size();
var text = createHtmlElement('span', { 'style': 'display:inline-block; line-height: normal' });
if (style.bold) {
text.style.fontWeight = 'bold';
}
if (style.italic) {
text.style.fontStyle = 'italic';
}
Iif (width !== undefined) {
text.style.width = width.toString() + 'px';
}
Iif (height !== undefined) {
text.style.height = height.toString() + 'px';
}
Eif (maxWidth !== undefined) {
text.style.maxWidth = maxWidth.toString() + 'px';
}
text.style.fontFamily = style.fontFamily;
text.style.fontSize = style.fontSize + 'px';
text.style.color = style.color;
text.textContent = content;
text.style.whiteSpace = base_util_1.whiteSpaceToString(style.whiteSpace, style.textWrapping);
Eif (maxWidth !== undefined) {
text.style.wordBreak = 'break-word';
}
else {
text.style.wordBreak = base_util_1.wordBreakToString(style.textWrapping);
}
document.body.appendChild(text);
bounds.width = text.offsetWidth;
bounds.height = text.offsetHeight;
document.body.removeChild(text);
return bounds;
}
exports.measureHtmlText = measureHtmlText;
function measureText(text, style, content, maxWidth, textValue) {
var bounds = new size_1.Size(0, 0);
var childNodes;
var wrapBounds;
var options = getTextOptions(text, maxWidth);
text.childNodes = childNodes = wrapSvgText(options, textValue, text.isLaneOrientation ? maxWidth : undefined);
text.wrapBounds = wrapBounds = wrapSvgTextAlign(options, childNodes);
bounds.width = wrapBounds.width;
if (text.wrapBounds.width >= maxWidth && options.textOverflow !== 'Wrap') {
bounds.width = maxWidth;
}
bounds.height = childNodes.length * text.style.fontSize * 1.2;
return bounds;
}
exports.measureText = measureText;
function measureImage(source, contentSize, id, callback) {
var measureWindowElement = 'measureElement';
window["" + measureWindowElement].style.visibility = 'visible';
var imageElement = window["" + measureWindowElement].children[1];
imageElement.setAttribute('src', source);
var bounds = imageElement.getBoundingClientRect();
var width = bounds.width;
var height = bounds.height;
contentSize = new size_1.Size(width, height);
window["" + measureWindowElement].style.visibility = 'hidden';
var element = document.createElement('img');
element.setAttribute('src', source);
setAttributeHtml(element, { id: id + 'sf-imageNode', style: 'display: none;' });
document.body.appendChild(element);
element.onload = function (event) {
var loadedImage = event.currentTarget;
Iif (callback) {
callback(id, { width: loadedImage.width, height: loadedImage.height });
}
};
return contentSize;
}
exports.measureImage = measureImage;
function measureNativeContent(nativeContent) {
var measureWindowElement = 'measureElement';
window[measureWindowElement].style.visibility = 'visible';
var nativeSVG = window[measureWindowElement].children[2];
nativeSVG.appendChild(nativeContent);
var bounds = nativeContent.getBoundingClientRect();
var svgBounds = nativeSVG.getBoundingClientRect();
var rect = bounds;
rect.x = bounds.left - svgBounds.left;
rect.y = bounds.top - svgBounds.top;
nativeSVG.removeChild(nativeContent);
window[measureWindowElement].style.visibility = 'hidden';
return rect;
}
exports.measureNativeContent = measureNativeContent;
function measureNativeSvg(nativeContent) {
var measureWindowElement = 'measureElement';
window[measureWindowElement].style.visibility = 'visible';
var nativeSVG = window[measureWindowElement].children[2];
nativeSVG.appendChild(nativeContent);
var svgBounds = nativeSVG.getBoundingClientRect();
nativeSVG.removeChild(nativeContent);
window[measureWindowElement].style.visibility = 'hidden';
return svgBounds;
}
exports.measureNativeSvg = measureNativeSvg;
function updatePath(element, bounds, child, options) {
var initX = 0;
var initY = 0;
var scaleX = 0;
var scaleY = 0;
var isScale = false;
var newPathString = '';
var arrayCollection = [];
var bBox = bounds;
if (initX !== bBox.x || initY !== bBox.y) {
scaleX = initX - Number(bBox.x);
scaleY = initY - Number(bBox.y);
}
if (element.actualSize.width !== bBox.width || element.actualSize.height !== bBox.height || options) {
scaleX = (options && options.width || element.actualSize.width) / Number(bBox.width ? bBox.width : 1);
scaleY = (options && options.height || element.actualSize.height) / Number(bBox.height ? bBox.height : 1);
isScale = true;
}
arrayCollection = path_util_1.processPathData(element.data);
arrayCollection = path_util_1.splitArrayCollection(arrayCollection);
newPathString = path_util_1.transformPath(arrayCollection, scaleX, scaleY, isScale, bBox.x, bBox.y, initX, initY);
isScale = false;
return newPathString;
}
exports.updatePath = updatePath;
function getDiagramLayerSvg(diagramId) {
var diagramElement = getDiagramElement(diagramId);
var elementcoll = diagramElement.getElementsByClassName('e-diagram-layer');
var diagramLayerSvg = elementcoll[0];
return diagramLayerSvg;
}
exports.getDiagramLayerSvg = getDiagramLayerSvg;
function getDiagramElement(elementId, contentId) {
var diagramElement;
var element;
if (contentId) {
element = document.getElementById(contentId);
}
Iif (ej2_base_1.Browser.info.name === 'msie' || ej2_base_1.Browser.info.name === 'edge') {
diagramElement = (element) ? element.querySelector('#' + elementId) : document.getElementById(elementId);
}
else {
diagramElement = (element) ? element.querySelector('#' + CSS.escape(elementId)) : document.getElementById(elementId);
}
return diagramElement;
}
exports.getDiagramElement = getDiagramElement;
function getDomIndex(viewId, elementId, layer) {
var index = undefined;
var parentElement;
var postId = '';
if (layer === 'native') {
parentElement = getNativeLayer(viewId);
postId = '_content_groupElement';
}
else if (layer === 'html') {
parentElement = getHTMLLayer(viewId).childNodes[0];
postId = '_html_element';
}
else {
parentElement = getDiagramLayer(viewId);
postId = '_groupElement';
}
var childElement;
for (var i = 0; parentElement.childNodes && i < parentElement.childNodes.length; i++) {
childElement = parentElement.childNodes[i];
if (childElement && childElement.id === elementId + postId) {
index = i;
break;
}
}
return index;
}
exports.getDomIndex = getDomIndex;
function getAdornerLayerSvg(diagramId) {
var adornerLayerSvg = null;
var diagramElement = getDiagramElement(diagramId);
var elementcoll = diagramElement.getElementsByClassName('e-adorner-layer');
adornerLayerSvg = elementcoll[0];
return adornerLayerSvg;
}
exports.getAdornerLayerSvg = getAdornerLayerSvg;
function getSelectorElement(diagramId) {
var adornerLayer = null;
var adornerSvg = getAdornerLayerSvg(diagramId);
adornerLayer = adornerSvg.getElementById(diagramId + '_SelectorElement');
return adornerLayer;
}
exports.getSelectorElement = getSelectorElement;
function getAdornerLayer(diagramId) {
var adornerLayer = null;
var diagramAdornerSvg = getAdornerLayerSvg(diagramId);
adornerLayer = diagramAdornerSvg.getElementById(diagramId + '_diagramAdorner');
return adornerLayer;
}
exports.getAdornerLayer = getAdornerLayer;
function getUserHandleLayer(diagramId) {
var adornerLayer = null;
var diagramUserHandleLayer = getDiagramElement(diagramId);
var elementcoll = diagramUserHandleLayer.getElementsByClassName('e-userHandle-layer');
adornerLayer = elementcoll[0];
return adornerLayer;
}
exports.getUserHandleLayer = getUserHandleLayer;
function getDiagramLayer(diagramId) {
var diagramLayerSvg = getDiagramLayerSvg(diagramId);
var diagramLayer = diagramLayerSvg.getElementById(diagramId + '_diagramLayer');
return diagramLayer;
}
exports.getDiagramLayer = getDiagramLayer;
function getPortLayerSvg(diagramId) {
var adornerLayerSvg = null;
var diagramElement = getDiagramElement(diagramId);
var elementcoll = diagramElement.getElementsByClassName('e-ports-expand-layer');
adornerLayerSvg = elementcoll[0];
return adornerLayerSvg;
}
exports.getPortLayerSvg = getPortLayerSvg;
function getNativeLayerSvg(diagramId) {
var nativeLayerSvg;
var diagramElement = getDiagramElement(diagramId);
var elementcoll = diagramElement.getElementsByClassName('e-native-layer');
nativeLayerSvg = elementcoll[0];
return nativeLayerSvg;
}
exports.getNativeLayerSvg = getNativeLayerSvg;
function getGridLayerSvg(diagramId) {
var gridLayerSvg = null;
var diagramElement = getDiagramElement(diagramId);
var elementcoll = diagramElement.getElementsByClassName('e-grid-layer');
gridLayerSvg = elementcoll[0];
return gridLayerSvg;
}
exports.getGridLayerSvg = getGridLayerSvg;
function getBackgroundLayerSvg(diagramId) {
var gridLayerSvg = null;
var diagramElement = getDiagramElement(diagramId);
var elementcoll = diagramElement.getElementsByClassName('e-background-layer');
return elementcoll[0].parentNode;
}
exports.getBackgroundLayerSvg = getBackgroundLayerSvg;
function getBackgroundImageLayer(diagramId) {
var imageLayer = null;
var diagramElement = getDiagramElement(diagramId);
var elementcoll = diagramElement.getElementsByClassName('e-background-image-layer');
imageLayer = elementcoll[0];
return imageLayer;
}
exports.getBackgroundImageLayer = getBackgroundImageLayer;
function getBackgroundLayer(diagramId) {
var imageLayer = null;
var diagramElement = getDiagramElement(diagramId);
var elementcoll = diagramElement.getElementsByClassName('e-background-layer');
imageLayer = elementcoll[0];
return imageLayer;
}
exports.getBackgroundLayer = getBackgroundLayer;
function getGridLayer(diagramId) {
var domTable = 'domTable';
var expandCollapse = null;
if (!window[domTable][diagramId + '_gridline']) {
var diagramGridSvg = getGridLayerSvg(diagramId);
expandCollapse = diagramGridSvg.getElementById(diagramId + '_gridline');
window[domTable][diagramId + '_gridline'] = expandCollapse;
}
else {
expandCollapse = window[domTable][diagramId + '_gridline'];
}
return expandCollapse;
}
exports.getGridLayer = getGridLayer;
function getNativeLayer(diagramId) {
var nativeLayer = null;
var nativeLayerSvg = getNativeLayerSvg(diagramId);
nativeLayer = nativeLayerSvg.getElementById(diagramId + '_nativeLayer');
return nativeLayer;
}
exports.getNativeLayer = getNativeLayer;
function getHTMLLayer(diagramId) {
var htmlLayer = null;
var domTable = 'domTable';
if (!window[domTable][diagramId + 'html_layer']) {
var element = getDiagramElement(diagramId);
var elementcoll = element.getElementsByClassName('e-html-layer');
htmlLayer = elementcoll[0];
window[domTable][diagramId + 'html_layer'] = htmlLayer;
}
else {
htmlLayer = window[domTable][diagramId + 'html_layer'];
}
return htmlLayer;
}
exports.getHTMLLayer = getHTMLLayer;
function createHtmlElement(elementType, attribute) {
var element = ej2_base_1.createElement(elementType);
setAttributeHtml(element, attribute);
return element;
}
exports.createHtmlElement = createHtmlElement;
function createSvgElement(elementType, attribute) {
var element = document.createElementNS('http://www.w3.org/2000/svg', elementType);
setAttributeSvg(element, attribute);
return element;
}
exports.createSvgElement = createSvgElement;
function parentsUntil(elem, selector, isID) {
var parent = elem;
while (parent) {
if (isID ? parent.id === selector : hasClass(parent, selector)) {
break;
}
parent = parent.parentNode;
}
return parent;
}
exports.parentsUntil = parentsUntil;
function hasClass(element, className) {
var eClassName = (typeof element.className === 'object') ? element.className.animVal : element.className;
return ((' ' + eClassName + ' ').indexOf(' ' + className + ' ') > -1) ? true : false;
}
exports.hasClass = hasClass;
function getScrollerWidth() {
var outer = createHtmlElement('div', { 'style': 'visibility:hidden; width: 100px' });
document.body.appendChild(outer);
var widthNoScroll = outer.getBoundingClientRect().width;
outer.style.overflow = 'scroll';
var inner = createHtmlElement('div', { 'style': 'width:100%' });
outer.appendChild(inner);
var widthWithScroll = inner.getBoundingClientRect().width;
outer.parentNode.removeChild(outer);
return widthNoScroll - widthWithScroll;
}
exports.getScrollerWidth = getScrollerWidth;
function addTouchPointer(touchList, e, touches) {
touchList = [];
for (var i = 0, length_1 = touches.length; i < length_1; i++) {
touchList.push({
pageX: touches[parseInt(i.toString(), 10)].clientX, pageY: touches[parseInt(i.toString(), 10)].clientY,
pointerId: null
});
}
return touchList;
}
exports.addTouchPointer = addTouchPointer;
function removeElement(elementId, contentId) {
var div = getDiagramElement(elementId, contentId);
if (div) {
div.parentNode.removeChild(div);
}
}
exports.removeElement = removeElement;
function getContent(element, isHtml, nodeObject) {
var div;
if (isHtml) {
var attr = { 'style': 'height: 100%; width: 100%' };
div = createHtmlElement('div', attr);
}
else {
div = document.createElementNS('http://www.w3.org/2000/svg', 'g');
}
var node = diagram_util_1.getElement(element);
var content = '';
var sentNode = {};
var isSvg = false;
var propertyName;
if (node instanceof node_1.Node) {
sentNode = node;
if (node.shape.type === 'Native') {
isSvg = true;
var svgContent = void 0;
var div_1 = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
document.body.appendChild(div_1);
div_1.innerHTML = (node.shape.content);
svgContent = (div_1.getElementsByTagName('svg').length > 0)
? div_1.getElementsByTagName('svg')[0].outerHTML :
div_1.getElementsByTagName('g').length > 0 ? div_1.getElementsByTagName('g')[0].outerHTML : "";
node.shape.content = svgContent;
element.content = svgContent;
div_1.parentElement.removeChild(div_1);
}
propertyName = "nodeTemplate";
}
else {
sentNode = node;
propertyName = "annotationTemplate";
}
var item;
var diagramElement = document.getElementById(element.diagramId);
var instance = 'ej2_instances';
var diagram = diagramElement[instance][0];
if ((typeof element.content === 'string' || typeof element.content === 'function') && (!element.isTemplate)) {
var template = document.getElementById(element.content);
Iif (template) {
div.appendChild(template);
}
else {
var compiledString = void 0;
compiledString = ej2_base_1.compile(element.content);
for (var _i = 0, _a = compiledString(sentNode, diagram, propertyName, content); _i < _a.length; _i++) {
item = _a[_i];
div.appendChild(item);
}
}
}
else if (element.isTemplate) {
var compiledString = void 0;
Iif (diagram.isReact) {
compiledString = element.getNodeTemplate()(base_util_1.cloneObject(nodeObject), diagram, propertyName + "_" + ((propertyName === "nodeTemplate") ? nodeObject.id : element.nodeId + nodeObject.id), undefined, undefined, false, div);
}
else Iif (diagram.isVue || diagram.isVue3) {
var templateFn = element.getNodeTemplate();
if (templateFn) {
compiledString = element.getNodeTemplate()(base_util_1.cloneObject(nodeObject), diagram, propertyName + "_" + ((propertyName === "nodeTemplate") ? nodeObject.id : element.nodeId + nodeObject.id), undefined, undefined, false, div);
}
else {
if (propertyName === 'nodeTemplate') {
compiledString = ej2_base_1.compile(diagram.nodeTemplate);
}
else {
compiledString = ej2_base_1.compile(diagram.annotationTemplate);
}
compiledString = compiledString(base_util_1.cloneObject(nodeObject), diagram, propertyName + "_" + ((propertyName === "nodeTemplate") ? nodeObject.id : element.nodeId + nodeObject.id), undefined, undefined, false, div);
}
}
else {
compiledString = element.getNodeTemplate()(base_util_1.cloneObject(nodeObject), diagram, propertyName + "_" + ((propertyName === "nodeTemplate") ? nodeObject.id : element.nodeId + nodeObject.id), undefined, undefined, false);
}
Eif (compiledString) {
for (var i = 0; i < compiledString.length; i++) {
div.appendChild(compiledString[parseInt(i.toString(), 10)]);
}
}
}
else {
Eif (element.content && element.content.outerHTML) {
div.appendChild(element.content);
}
}
return element.isTemplate ?
div : (isHtml ? div.cloneNode(true) : div.cloneNode(true));
}
exports.getContent = getContent;
function setAttributeSvg(svg, attributes) {
var keys = Object.keys(attributes);
for (var i = 0; i < keys.length; i++) {
if (svg && keys[parseInt(i.toString(), 10)] !== 'style') {
svg.setAttribute(keys[parseInt(i.toString(), 10)], attributes[keys[parseInt(i.toString(), 10)]]);
}
else {
applyStyleAgainstCsp(svg, attributes[keys[parseInt(i.toString(), 10)]]);
}
}
}
exports.setAttributeSvg = setAttributeSvg;
function applyStyleAgainstCsp(svg, attributes) {
var keys = attributes.split(';');
for (var i = 0; i < keys.length; i++) {
var attribute = keys[parseInt(i.toString(), 10)].split(':');
if (attribute.length === 2) {
svg.style[attribute[0].trim()] = attribute[1].trim();
}
}
}
exports.applyStyleAgainstCsp = applyStyleAgainstCsp;
function setAttributeHtml(element, attributes) {
var keys = Object.keys(attributes);
for (var i = 0; i < keys.length; i++) {
if (keys[parseInt(i.toString(), 10)] !== 'style') {
element.setAttribute(keys[parseInt(i.toString(), 10)], attributes[keys[parseInt(i.toString(), 10)]]);
}
else {
applyStyleAgainstCsp(element, attributes[keys[parseInt(i.toString(), 10)]]);
}
}
}
exports.setAttributeHtml = setAttributeHtml;
function createMeasureElements() {
var measureWindowElement = 'measureElement';
Eif (!window["" + measureWindowElement]) {
var divElement = createHtmlElement('div', {
id: 'measureElement',
style: 'visibility:hidden ; height: 0px ; width: 0px; overflow: hidden;'
});
var text = createHtmlElement('span', { 'style': 'display:inline-block ; line-height: normal' });
divElement.appendChild(text);
var imageElement = createHtmlElement('img', { 'alt': 'measureElementImage', 'src': 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' });
divElement.appendChild(imageElement);
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
divElement.appendChild(svg);
var element = document.createElementNS('http://www.w3.org/2000/svg', 'path');
element.setAttribute('d', '');
svg.appendChild(element);
var data = document.createTextNode('');
var tSpan = document.createElementNS('http://www.w3.org/2000/svg', 'text');
tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
svg.appendChild(tSpan);
window["" + measureWindowElement] = divElement;
window["" + measureWindowElement].usageCount = 1;
document.body.appendChild(divElement);
var measureElementCount = 'measureElementCount';
if (!window["" + measureElementCount]) {
window["" + measureElementCount] = 1;
}
else {
window["" + measureElementCount]++;
}
}
else {
window["" + measureWindowElement].usageCount += 1;
}
}
exports.createMeasureElements = createMeasureElements;
function setChildPosition(temp, childNodes, i, options) {
if (childNodes.length >= 1 && temp.x === 0 &&
(options.textOverflow === 'Clip' || options.textOverflow === 'Ellipsis') &&
(options.textWrapping === 'Wrap' || options.textWrapping === 'WrapWithOverflow')) {
temp.x = childNodes[i - 1] ? childNodes[i - 1].x : -(temp.width / 2);
return temp.x;
}
return temp.x;
}
exports.setChildPosition = setChildPosition;
function getTemplateContent(annotationcontent, annotation, annotationTemplate, diagram) {
if ((annotationTemplate && !annotation.template) ||
(annotation.template && typeof annotation.template === 'function' && diagram.isReact)) {
annotationcontent.isTemplate = true;
annotationcontent.template = annotationcontent.content = getContent(annotationcontent, true, annotation);
}
else {
annotationcontent.content = annotation.template;
}
return annotationcontent;
}
exports.getTemplateContent = getTemplateContent;
function createUserHandleTemplates(userHandleTemplate, template, selectedItems, diagramID) {
var userHandleFn;
var handle;
var compiledString;
var i;
var div;
var diagramElement = document.getElementById(diagramID);
var instance = 'ej2_instances';
var diagram = diagramElement[instance][0];
if (userHandleTemplate && template) {
userHandleFn = base_util_2.templateCompiler(userHandleTemplate);
for (var _i = 0, _a = selectedItems.userHandles; _i < _a.length; _i++) {
handle = _a[_i];
Eif (userHandleFn) {
compiledString = userHandleFn(base_util_1.cloneObject(handle), diagram, 'userHandleTemplate' + '_' + handle.name, undefined, undefined, false);
for (i = 0; i < compiledString.length; i++) {
var attr = {
'style': 'height: 100%; width: 100%; pointer-events: all',
'id': handle.name + '_template_hiddenUserHandle'
};
div = createHtmlElement('div', attr);
div.appendChild(compiledString[i]);
}
template[0].appendChild(div);
}
}
}
}
exports.createUserHandleTemplates = createUserHandleTemplates;
});
|