all files / diagram/load-utility/visio-import-export/ visio-nodes.js

95.58% Statements 540/565
87.22% Branches 471/540
97.01% Functions 65/67
95.79% Lines 523/546
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                     65× 190× 125× 65× 65×   65×     1590× 1590× 1590× 1590× 8184×                       1590× 1585×             1585×                   1585×   1590× 1590×                                                                           1590×   1590× 1590×   1663× 1229×   434×   431×   428×   1590× 1590×   1586×     1586×   1590×   1585×   361×   352×   350×   347×   1590× 1590×   1590×   1590×   1590×   1590×                       1589×   1590× 3180× 2581×   599× 178× 178×   421×   1590×         1590× 1590× 1590× 38×   1590× 65× 65×   1525×           1518×               1590× 1590× 1590× 10×   1590×   1590×   1590×   1590×   1590×   1590×   1590×   1590×   1590× 13×   1590× 16×   1590×   1590×   1590×   1590× 13×           13×   1577×   1590×   1589×   1587×   1584×   1590×         1590×           1590×       1590×     1590×     1590×                     1590×               1590× 1590× 1590× 1590×   1590× 1590×     1590× 1590× 1590×     1590×       1589× 1335×   254× 42×   212× 16× 16× 16×   196× 65× 65×   131×   127×   121×     116× 116× 116× 74× 74×   116× 116×         11×     11×     11× 11×     11× 173× 173×   11×     11×           65× 131× 65× 65× 14×   51×   43×   40×   38×   36× 29×                                                                                               22×                                                 229×     229× 229× 229×   74× 74× 63× 63× 229× 229× 229× 206×         74×   14× 14× 14×         14×     14× 28× 14×   14× 14×   14× 14× 11×   14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 14× 12×   14×     14× 14× 14× 14× 14×   14×     14× 14×         14×                                           16× 14×                                                                                       18×                   29× 29× 29×   29× 29×       29× 11×     18×     18×           18×           18× 18× 18× 18× 18× 18× 18×                 11×       11×       11× 11× 11× 11× 11× 11× 11× 11× 11× 11×                                     51×                         11×         28×                         28×      
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 = getPivotFromVisioFormulas(node.pivotX, node.pivotY);
        pivot.y = (pivot.y === 1) ? 0 : ((pivot.y === 0) ? 1 : pivot.y);
        var textBinding = null;
        var isGroup = Array.isArray(node.children) && node.children.length > 1;
        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
            }
        }); });
        if (node.annotation && node.annotation.txtPinX !== undefined) {
            var shapeTransform = {
                pinX: node.offsetX,
                pinY: node.pinY / 96,
                width: node.width,
                height: node.height,
                verticalAlignment: setVerticalAlignment(node)
            };
            var textTransform = {
                txtWidth: node.annotation.txtWidth,
                txtHeight: node.annotation.txtHeight,
                txtPinX: node.annotation.txtPinX,
                txtPinY: node.annotation.txtPinY,
                txtLocPinX: node.annotation.txtLocPinX,
                txtLocPinY: node.annotation.txtLocPinY,
                txtAngle: (node.annotation.rotateAngle || 0) * (Math.PI / 180),
                txtMargin: node.annotation.margin
            };
            textBinding = visio_annotations_1.VisioToSyncfusionTextBinder.bindVisioTextToSyncfusion(shapeTransform, textTransform);
        }
        var nodeStyle = visio_theme_1.setAnnotationStyle(node, context);
        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),
            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: [
                {
                    content: node.annotation.content,
                    width: visio_core_1.inchToPx(node.annotation.txtWidth ?
                        node.annotation.txtWidth : node.width),
                    height: visio_core_1.inchToPx(node.annotation.txtHeight ?
                        node.annotation.txtHeight : node.height),
                    visibility: node.annotation.visible,
                    hyperlink: setHyperLink(node, nodeStyle),
                    rotateAngle: setRotateAngle(node),
                    constraints: setAnnotationConstraints(node.annotation),
                    horizontalAlignment: setHorizontalAlignment(node),
                    offset: (textBinding && textBinding.offset) || { x: 0.5, y: 0.5 },
                    style: nodeStyle
                }
            ]
        };
    }
    exports.convertVisioShapeToNode = convertVisioShapeToNode;
    function setVisibility(node) {
        return 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 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 getPivotFromVisioFormulas(locPinX, locPinY) {
        var parse = function (pin) {
            if (typeof pin === 'number') {
                return pin;
            }
            if (typeof pin === 'string' && pin.includes('*')) {
                var valStr = pin.substring(pin.indexOf('*') + 1);
                return isNaN(parseFloat(valStr)) ? 0.5 : parseFloat(valStr);
            }
            return 0.5;
        };
        return {
            x: Math.min(Math.max(parse(locPinX), 0), 1),
            y: Math.min(Math.max(parse(locPinY), 0), 1)
        };
    }
    function setNodeShape(shape, context) {
        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.shadowPattern) {
            constraints |= enum_1.NodeConstraints.Shadow;
        }
        if (shape.comment) {
            constraints |= enum_1.NodeConstraints.Tooltip;
        }
        if (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 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'
        ]);
        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');
                if (hasUml && !hasFlow) {
                    Eif (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 if (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;
            }
            else if (finalShape === 'LineCallout') {
                return { type: 'Basic', shape: 'Rectangle' };
            }
            else {
                var geometrySection = defaultData;
                var formattedPath = undefined;
                if (geometrySection && geometrySection.N === 'Geometry' && geometrySection.Row) {
                    var pathData = visio_core_1.createCombinedPathFromGeometries(geometrySection, name);
                    formattedPath = visio_core_1.formatPathData(pathData);
                }
                context.addWarning("[WARNING] :: The " + name + " shape is not predefined, So it is rendered as Path shape");
                return { type: 'Path', data: formattedPath };
            }
        }
        return { type: 'Basic', shape: 'Rectangle' };
    }
    exports.determineShapeType = determineShapeType;
    function getShapeKeywordsFromMaster(shape, context) {
        var masterId = (shape && shape.$ && shape.$.Master != null)
            ? shape.$.Master
            : undefined;
        Iif (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) {
                            if (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: '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) {
                            Eif (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('');
    }
});