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

77.92% Statements 314/403
66.02% Branches 274/415
58.82% Functions 20/34
86.8% Lines 309/356
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                                                                               434× 434× 434× 434× 434× 372× 372×     370× 370×     370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370× 370×                                                               370× 370× 370× 370× 370×   370× 370×     434×                 434× 1914× 1914× 1914× 1914× 1894× 1894× 1894×     1894×     1894× 1894× 1894× 1894× 1894× 73×     1821× 1821× 1524× 1524× 1524× 1524× 1524× 1524×     1522× 1522×                   1522×   1524×       20× 20× 20× 20×     20×     20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 20× 29× 20× 20×             20× 20× 20×   20× 20× 20×   20× 20× 20× 20× 20× 20× 20× 20×     20× 20×   1914×       434×   1570× 1570× 1570×           1570× 1570× 1570× 1570×     1570× 1570×         1570×         1570× 1570× 1570× 1570× 1570× 1570× 1570× 1570× 1570×   1570×   1570×   1570×   1570×   1570×   1570× 1570× 1570× 1570× 1570× 1570× 1570× 1570× 1570× 1570×           1570× 1570× 1570× 1570×             1570× 1528× 1528× 6112× 6112× 6112×     1528×   42×     42×   370×     370×     370×     370× 370× 1480× 1480× 1480×   370× 370× 370× 370× 370× 370× 370× 370× 370×   1590× 8158× 1767× 1590×   73×     73× 73× 73×     73× 73×     73×     204× 73× 73×     73× 73× 73× 99× 99× 99× 62×   37× 37× 37× 37×     11× 11× 11× 11× 11× 11× 11× 11× 11× 11× 11×                   11× 11× 11×   37×     37× 37×     37×     37×     37× 37× 37× 37× 37× 37× 37× 37× 37× 37×       37× 37×                   37×   37× 37×   1942× 2203× 2203× 52× 52×     1890×   1590× 1590×     1590× 1590× 1590× 1590× 1590× 1521×     1590×                           1590× 19080× 19080× 19080×     25×     25× 25×     25×     20× 20×     25×      
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
define(["require", "exports", "./visio-annotations", "./visio-connectors", "./visio-core", "./visio-model-parsers", "./visio-models", "./visio-nodes"], function (require, exports, visio_annotations_1, visio_connectors_1, visio_core_1, visio_model_parsers_1, visio_models_1, visio_nodes_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function parserVisioShape(obj, context) {
        var _this = this;
        var shapeElements = obj.Shape;
        var rawShape = shapeElements && !Array.isArray(shapeElements) && typeof shapeElements === 'object';
        var resultShapes = [];
        if (rawShape && !Array.isArray(shapeElements)) {
            var singleShape = shapeElements;
            if (singleShape.$ &&
                (singleShape.$.NameU || singleShape.$.Type) &&
                !singleShape.$.Master) {
                var shapeData = singleShape;
                var cells = Array.isArray(shapeData.Cell)
                    ? shapeData.Cell
                    : [shapeData.Cell];
                var cellMap = visio_core_1.mapCellValues(cells);
                var defaultWidth = Number(cellMap.get('Width'));
                var defaultHeight = Number(cellMap.get('Height'));
                var defaultLocX = cellMap.get('LocPinX');
                var defaultLocY = cellMap.get('LocPinY');
                var defaultBeginX = cellMap.get('BeginX');
                var defaultBeginY = cellMap.get('BeginY');
                var defaultEndX = cellMap.get('EndX');
                var defaultEndY = cellMap.get('EndY');
                var bgColor = cellMap.get('FillForegnd');
                var txtWidth = Number(cellMap.get('TxtWidth'));
                var txtHeight = Number(cellMap.get('TxtHeight'));
                var txtPinX = Number(cellMap.get('TxtPinX'));
                var txtPinY = Number(cellMap.get('TxtPinY'));
                var txtLocalPinX = Number(cellMap.get('TxtLocPinX'));
                var txtLocalPinY = Number(cellMap.get('TxtLocPinY'));
                var QuickStyleLineColor = cellMap.get('QuickStyleLineColor');
                var QuickStyleFillColor = cellMap.get('QuickStyleFillColor');
                var QuickStyleShadowColor = cellMap.get('QuickStyleShadowColor');
                var QuickStyleFontColor = cellMap.get('QuickStyleFontColor');
                var QuickStyleLineMatrix = cellMap.get('QuickStyleLineMatrix');
                var QuickStyleFillMatrix = cellMap.get('QuickStyleFillMatrix');
                var QuickStyleEffectsMatrix = cellMap.get('QuickStyleEffectsMatrix');
                var QuickStyleFontMatrix = cellMap.get('QuickStyleFontMatrix');
                var master = context.data.masters[visio_nodes_1.shapeIndex.value];
                var connections = visio_model_parsers_1.getVisioPorts(shapeData, undefined, defaultWidth, defaultHeight);
                var Geometry = {
                    N: 'Geometry',
                    Row: undefined,
                    Width: defaultWidth,
                    Height: defaultHeight,
                    LocPinX: defaultLocX,
                    LocPinY: defaultLocY,
                    beginX: defaultBeginX,
                    beginY: defaultBeginY,
                    endX: defaultEndX,
                    endY: defaultEndY,
                    masterID: master ? master.id : undefined,
                    shapeName: master ? master.name : undefined,
                    shapeType: master ? master.shapeType : undefined,
                    ports: connections,
                    fillColor: bgColor,
                    shapeStyle: undefined,
                    txtWidth: txtWidth,
                    txtHeight: txtHeight,
                    txtPinX: txtPinX,
                    txtPinY: txtPinY,
                    txtLocalPinX: txtLocalPinX,
                    txtLocalPinY: txtLocalPinY,
                    QuickStyleLineColor: QuickStyleLineColor,
                    QuickStyleFillColor: QuickStyleFillColor,
                    QuickStyleShadowColor: QuickStyleShadowColor,
                    QuickStyleFontColor: QuickStyleFontColor,
                    QuickStyleLineMatrix: QuickStyleLineMatrix,
                    QuickStyleFillMatrix: QuickStyleFillMatrix,
                    QuickStyleEffectsMatrix: QuickStyleEffectsMatrix,
                    QuickStyleFontMatrix: QuickStyleFontMatrix
                };
                var geometry = visio_core_1.findAllGeometries(shapeData);
                Geometry.Row = geometry;
                var defaultStyle = findAllDefaultStyles(shapeData);
                Eif (defaultStyle) {
                    Geometry.shapeStyle = defaultStyle;
                }
                context.data.shapes.push(Geometry);
                visio_nodes_1.shapeIndex.value++;
            }
        }
        var rawShapes = Array.isArray(shapeElements)
            ? shapeElements
            : (shapeElements &&
                typeof shapeElements === 'object' &&
                shapeElements.$ &&
                (shapeElements.$.Master || visio_core_1.isGroupShape(shapeElements) || shapeElements.$.Type === 'Foreign')) ||
                context.data.masters.length === 0
                ? [shapeElements]
                : [];
        Eif (rawShapes) {
            rawShapes.forEach(function (shapeObj) { return __awaiter(_this, void 0, void 0, function () {
                var shapeData, attributes, cells, section, pageHeight, cellMap, pinYExists, getcell, masterId, shape, defaultData, drawshapeData, attributes, cells, section, pageHeight, cellMap, drawshape, drawpinY, pinYValue, attributeName, shapePorts, geometrySection, defaultData, merged, ForeignData, geometryCellMap, media;
                return __generator(this, function (_a) {
                    if (shapeObj.$.Master || visio_core_1.isGroupShape(shapeObj)) {
                        shapeData = shapeObj;
                        attributes = shapeData.$;
                        cells = Array.isArray(shapeData.Cell)
                            ? shapeData.Cell
                            : [shapeData.Cell];
                        section = shapeData.Section
                            ? (Array.isArray(shapeData.Section) ? shapeData.Section : [shapeData.Section])
                            : [];
                        pageHeight = visio_core_1.inchToPx(context.data.currentPage.pageHeight);
                        cellMap = visio_core_1.mapCellValues(cells);
                        pinYExists = cellMap.has('PinY');
                        getcell = getGeometryCells(section, visio_core_1.mapCellValues);
                        if (visio_core_1.isGroupShape(shapeObj) && !(shapeObj.$.Master != null)) {
                            processImmediateSubShapes(shapeObj, context, resultShapes);
                        }
                        else {
                            masterId = visio_core_1.getMasterId(shapeObj);
                            if (!visio_connectors_1.isConnectorShape(shapeObj, context)) {
                                shape = new visio_models_1.VisioShape();
                                shape.id = attributes.ID;
                                shape.masterId = attributes.Master;
                                shape.name = attributes.NameU;
                                shape.type = attributes.Type != null ? attributes.Type : 'Shape';
                                if (shape.name === 'Solid') {
                                    shape.fillColor = String(cellMap.get('FillForegnd') || 'transParent');
                                }
                                else {
                                    defaultData = visio_model_parsers_1.setDefaultData(context.data.shapes, attributes);
                                    applyCommonNodeProperties(shape, {
                                        cellMap: cellMap,
                                        attributes: attributes,
                                        defaultData: defaultData,
                                        pageHeight: pageHeight,
                                        pinYExists: pinYExists,
                                        context: context,
                                        getcell: getcell,
                                        shapeData: shapeData
                                    });
                                    assignShapeLayer(shape, cellMap, context);
                                }
                                resultShapes.push(shape);
                            }
                        }
                    }
                    else Eif (shapeObj.$ && (shapeObj.$.Type !== 'Guide' || shapeObj.$.Type === 'Foreign')) {
                        drawshapeData = shapeObj;
                        attributes = drawshapeData.$ || {};
                        cells = Array.isArray(drawshapeData.Cell)
                            ? drawshapeData.Cell
                            : [drawshapeData.Cell];
                        section = drawshapeData.Section
                            ? (Array.isArray(drawshapeData.Section) ? drawshapeData.Section : [drawshapeData.Section])
                            : [];
                        pageHeight = visio_core_1.inchToPx(context.data.currentPage.pageHeight);
                        cellMap = visio_core_1.mapCellValues(cells);
                        drawshape = new visio_models_1.VisioShape();
                        drawpinY = cellMap.get('PinY') != null ? Number(cellMap.get('PinY')) : 0;
                        pinYValue = visio_core_1.inchToPx(drawpinY);
                        drawshape.offsetY = drawpinY ? pageHeight - pinYValue : 0;
                        drawshape.id = attributes.ID;
                        drawshape.offsetX = cellMap.get('PinX') != null ? Number(cellMap.get('PinX')) : 0;
                        drawshape.width = cellMap.get('Width') != null ? Number(cellMap.get('Width')) : 1;
                        drawshape.height = cellMap.get('Height') != null ? Number(cellMap.get('Height')) : 1;
                        drawshape.pivotX = cellMap.get('LocPinX') != null ? cellMap.get('LocPinX') : 0.5;
                        drawshape.pivotY = cellMap.get('LocPinY') != null ? cellMap.get('LocPinY') : 0.5;
                        drawshape.flipX = cellMap.get('FlipX') != null ? Number(cellMap.get('FlipX')) : 0;
                        drawshape.flipY = cellMap.get('FlipY') != null ? Number(cellMap.get('FlipY')) : 0;
                        drawshape.rotateAngle = cellMap.get('Angle') != null ? cellMap.get('Angle') : 0;
                        drawshape.cornerRadius = cellMap.get('Rounding') != null ? cellMap.get('Rounding') : 0;
                        attributes.Name = attributes.Type === 'Foreign' ? 'Image' : 'Path';
                        attributeName = attributes.Name;
                        shapePorts = visio_model_parsers_1.getVisioPorts(drawshape, undefined, drawshape.width, drawshape.height);
                        geometrySection = section.filter(function (sec) { return sec && sec.$ && sec.$.N === 'Geometry'; });
                        attributes.Row = geometrySection ? geometrySection[0].Row : undefined;
                        defaultData = {
                            Width: drawshape.width,
                            Height: drawshape.height,
                            Name: attributeName,
                            pinY: drawpinY,
                            pinX: drawshape.offsetX
                        };
                        defaultData.Ports = mergePorts(undefined, shapePorts);
                        merged = __assign({}, defaultData, attributes);
                        if (attributeName === 'Image') {
                            ForeignData = drawshapeData.ForeignData;
                            drawshape.type = ForeignData.$.CompressionType;
                            drawshape.foreignType = ForeignData.$.ForeignType;
                            drawshape.imageId = ForeignData.Rel.$['r:id'];
                        }
                        Eif (geometrySection && geometrySection[0].Cell) {
                            geometryCellMap = visio_core_1.mapCellValues(geometrySection[0].Cell);
                            drawshape.visibility = geometryCellMap.get('NoShow') ? geometryCellMap.get('NoShow') === '1' : false;
                        }
                        drawshape.pinY = drawpinY;
                        drawshape.shape = visio_nodes_1.determineShapeType(merged, undefined, undefined, undefined, context);
                        drawshape.style = visio_model_parsers_1.parseVisioNodeStyle(drawshapeData, context, undefined, attributeName);
                        drawshape.annotation = visio_annotations_1.VisioNodeAnnotation.fromJs(drawshapeData, defaultData);
                        drawshape.constraints = applyConstraints(drawshape, cellMap);
                        drawshape.shadow = visio_model_parsers_1.parseVisioNodeShadow(cellMap, context);
                        drawshape.ports = defaultData.Ports || [];
                        if (drawshape.shape && drawshape.shape.type === 'Image' && drawshape.imageId) {
                            media = context.data.medias[drawshape.imageId];
                            Eif (media && media.dataUrl) {
                                drawshape.shape.source = media.dataUrl;
                            }
                        }
                        assignShapeLayer(drawshape, cellMap, context);
                        resultShapes.push(drawshape);
                    }
                    return [2];
                });
            }); });
        }
        return resultShapes;
    }
    exports.parserVisioShape = parserVisioShape;
    function applyCommonNodeProperties(shape, args) {
        var cellMap = args.cellMap, attributes = args.attributes, defaultData = args.defaultData, pageHeight = args.pageHeight, pinYExists = args.pinYExists, context = args.context, getcell = args.getcell, shapeData = args.shapeData;
        attributes.Name = (attributes.Type === 'Foreign') ? 'Image' : attributes.Name ? attributes.Name : defaultData.Name ? defaultData.Name : 'Shape';
        Iif (attributes.Name === 'Image') {
            var ForeignData = args.shapeData.ForeignData;
            shape.type = ForeignData.$.CompressionType;
            shape.foreignType = ForeignData.$.ForeignType;
            shape.imageId = ForeignData.Rel.$['r:id'];
        }
        var defaultShapeStyle = shapeStyleToObject(defaultData.shapeStyle);
        var shapeHeight = cellMap.get('Height') ? Number(cellMap.get('Height')) : defaultData.Height;
        shape.offsetX = cellMap.get('PinX') != null ? Number(cellMap.get('PinX')) : 0;
        var pinYValue = pinYExists
            ? visio_core_1.inchToPx(Number(cellMap.get('PinY')))
            : Number(cellMap.get('PinY'));
        shape.offsetY = pinYExists ? pageHeight - pinYValue : 0;
        shape.width = cellMap.get('Width') != null
            ? Number(cellMap.get('Width'))
            : (defaultData && defaultData.Width) !== undefined
                ? defaultData.Width
                : 1;
        shape.height = cellMap.get('Height') != null
            ? Number(cellMap.get('Height'))
            : (defaultData && defaultData.Height) !== undefined
                ? defaultData.Height
                : 1;
        var shapePorts = visio_model_parsers_1.getVisioPorts(args.shapeData, args.defaultData, shape.width, shape.height);
        defaultData.Ports = mergePorts(defaultData.Ports, shapePorts);
        shape.pivotX = cellMap.get('LocPinX') != null ? cellMap.get('LocPinX') : 0.5;
        shape.pivotY = cellMap.get('LocPinY') != null ? cellMap.get('LocPinY') : 0.5;
        shape.rotateAngle = cellMap.get('Angle') != null ? cellMap.get('Angle') : 0;
        shape.cornerRadius = cellMap.get('Rounding') != null ? cellMap.get('Rounding') : defaultShapeStyle.cornerRadius;
        shape.pinY = pinYValue;
        shape.annotation = visio_annotations_1.VisioNodeAnnotation.fromJs(shapeData, defaultData);
        shape.QuickLineColor = cellMap.get('QuickStyleLineColor') != null ? Number(cellMap.get('QuickStyleLineColor')) :
            (defaultData && defaultData.QuickStyleLineColor) !== undefined ? Number(defaultData.QuickStyleLineColor) : undefined;
        shape.QuickFillColor = cellMap.get('QuickStyleFillColor') != null ? Number(cellMap.get('QuickStyleFillColor')) :
            (defaultData && defaultData.QuickStyleFillColor) !== undefined ? Number(defaultData.QuickStyleFillColor) : undefined;
        shape.QuickShadowColor = cellMap.get('QuickStyleShadowColor') != null ? Number(cellMap.get('QuickStyleShadowColor')) :
            (defaultData && defaultData.QuickStyleShadowColor) !== undefined ? Number(defaultData.QuickStyleShadowColor) : undefined;
        shape.QuickLineMatrix = cellMap.get('QuickStyleLineMatrix') != null ? Number(cellMap.get('QuickStyleLineMatrix')) :
            (defaultData && defaultData.QuickStyleLineMatrix) !== undefined ? Number(defaultData.QuickStyleLineMatrix) : undefined;
        shape.QuickFillMatrix = cellMap.get('QuickStyleFillMatrix') != null ? Number(cellMap.get('QuickStyleFillMatrix')) :
            (defaultData && defaultData.QuickStyleFillMatrix) !== undefined ? Number(defaultData.QuickStyleFillMatrix) : undefined;
        shape.QuickShadowMatrix = cellMap.get('QuickStyleEffectsMatrix') != null ? Number(cellMap.get('QuickStyleEffectsMatrix')) :
            (defaultData && defaultData.QuickStyleEffectsMatrix) !== undefined ? Number(defaultData.QuickStyleEffectsMatrix) : undefined;
        shape.ThemeIndex = cellMap.get('ThemeIndex') != null ? Number(cellMap.get('ThemeIndex')) : undefined;
        shape.ColorSchemeIndex = cellMap.get('ColorSchemeIndex') != null ? Number(cellMap.get('ColorSchemeIndex')) : undefined;
        shape.flipX = cellMap.get('FlipX') != null ? Number(cellMap.get('FlipX')) : 0;
        shape.flipY = cellMap.get('FlipY') != null ? Number(cellMap.get('FlipY')) : 0;
        shape.visibility = getcell.has('NoShow') ? getcell.get('NoShow') === '1' : false;
        shape.tooltip = cellMap.get('Comment') != null ? cellMap.get('Comment') : '';
        shape.glueValue = cellMap.get('GlueType') != null ? cellMap.get('GlueType') : undefined;
        shape.style = visio_model_parsers_1.parseVisioNodeStyle(shapeData, context, defaultShapeStyle, undefined);
        shape.shape = visio_nodes_1.determineShapeType(attributes, defaultData, shapeData, shape, context);
        Iif (shape.shape && shape.shape.type === 'Image' && shape.imageId) {
            var media = context.data.medias[shape.imageId];
            if (media && media.dataUrl) {
                shape.shape.source = media.dataUrl;
            }
        }
        shape.constraints = applyConstraints(shape, cellMap);
        shape.shadow = visio_model_parsers_1.parseVisioNodeShadow(cellMap, context);
        shape.ports = defaultData.Ports;
        if (shape.shape && attributes && attributes.Name === 'Line Callout') {
            Eif (shape.annotation.content === '') {
                var deepTexts = collectDeepAnnotationText(shapeData);
                Eif (deepTexts.length > 0) {
                    var merged = deepTexts.join('\n');
                    shape.annotation = {
                        content: merged
                    };
                }
            }
            shape.flipX = 0;
            shape.flipY = 0;
            shape.rotateAngle = 0;
        }
    }
    exports.applyCommonNodeProperties = applyCommonNodeProperties;
    function shapeStyleToObject(style) {
        if (Array.isArray(style)) {
            var out = {};
            for (var _i = 0, _a = style; _i < _a.length; _i++) {
                var item = _a[_i];
                Eif (item && typeof item.key === 'string') {
                    out[item.key] = item.value;
                }
            }
            return out;
        }
        Iif (style && typeof style === 'object') {
            return __assign({}, style);
        }
        return {};
    }
    function findAllDefaultStyles(shapeData) {
        Iif (!shapeData) {
            return [];
        }
        var cells = Array.isArray(shapeData.Cell)
            ? shapeData.Cell
            : [shapeData.Cell];
        Iif (!cells || cells.length === 0) {
            return [];
        }
        var entries = [];
        var defaultStyles = function (key, value, defaultValue) {
            var invalidNumber = typeof value === 'number' && Number.isNaN(value);
            var isMissing = value === undefined || value === null || value === '' || invalidNumber;
            entries.push({ key: key, value: isMissing ? defaultValue : value });
        };
        var rounding = visio_connectors_1.getCellValue(cells, 'Rounding');
        defaultStyles('cornerRadius', Number(rounding), 0);
        var lineWidth = visio_connectors_1.getCellValue(cells, 'LineWeight');
        defaultStyles('strokeWidth', Number(lineWidth), 0);
        var fillPattern = visio_connectors_1.getCellValue(cells, 'FillPattern');
        defaultStyles('FillPattern', fillPattern, undefined);
        var FillForegndTrans = visio_connectors_1.getCellValue(cells, 'FillForegndTrans');
        defaultStyles('FillForegndTrans', Number(FillForegndTrans), 0);
        return entries;
    }
    function mergePorts(basePorts, updatePorts) {
        var portMap = new Map();
        (basePorts ? basePorts : []).forEach(function (port) { return portMap.set(port.id, port); });
        (updatePorts ? updatePorts : []).forEach(function (port) { return portMap.set(port.id, port); });
        return Array.from(portMap.values());
    }
    function processImmediateSubShapes(shape, context, resultShapes) {
        Iif (!shape || !shape.$) {
            return;
        }
        var groupId = shape.$.ID;
        var children = shape.Shapes.Shape;
        Iif (!children) {
            return;
        }
        var attributes = shape.$;
        var cells = Array.isArray(shape.Cell)
            ? shape.Cell
            : shape.Cell ? [shape.Cell] : [];
        var section = shape.Section
            ? (Array.isArray(shape.Section) ? shape.Section : [shape.Section])
            : [];
        var userSection = section.find(function (s) { return s && s.$ && s.$.N === 'User'; });
        var excludeFromProcessing = false;
        Iif (userSection && !Array.isArray(userSection.Row) && userSection.Row.$.N === 'visNavOrder') {
            excludeFromProcessing = true;
        }
        var subShapes = Array.isArray(children) ? children : [children];
        var childIds = [];
        for (var _i = 0, subShapes_1 = subShapes; _i < subShapes_1.length; _i++) {
            var sub = subShapes_1[_i];
            var masterId = visio_core_1.getMasterId(sub);
            if (!visio_core_1.isValidMasterId(masterId) && !(sub.Text && sub.Text.value) && !excludeFromProcessing) {
                return null;
            }
            var child = createNodeForShape(sub, context, resultShapes);
            Eif (child && child.id) {
                child.parentId = groupId;
                childIds.push(child.id);
            }
        }
        var pageHeight = visio_core_1.inchToPx(context.data.currentPage.pageHeight);
        var cellMap = visio_core_1.mapCellValues(cells);
        var pinYExists = cellMap.has('PinY');
        var getcell = getGeometryCells(section, visio_core_1.mapCellValues);
        var defaultData = visio_model_parsers_1.setDefaultData(context.data.shapes, attributes);
        var groupNode = new visio_models_1.VisioShape();
        groupNode.id = groupId;
        groupNode.masterId = attributes.Master;
        groupNode.name = attributes.NameU;
        groupNode.type = attributes.Type != null ? attributes.Type : 'Shape';
        applyCommonNodeProperties(groupNode, {
            cellMap: cellMap,
            attributes: attributes,
            defaultData: defaultData,
            pageHeight: pageHeight,
            pinYExists: pinYExists,
            context: context,
            getcell: getcell,
            shapeData: shape
        });
        groupNode.children = childIds;
        assignShapeLayer(groupNode, cellMap, context);
        resultShapes.push(groupNode);
    }
    function createNodeForShape(shapeObj, context, resultShapes) {
        Iif (!shapeObj || !shapeObj.$) {
            return null;
        }
        var attributes = shapeObj.$;
        var cells = Array.isArray(shapeObj.Cell)
            ? shapeObj.Cell
            : shapeObj.Cell ? [shapeObj.Cell] : [];
        var section = shapeObj.Section
            ? (Array.isArray(shapeObj.Section) ? shapeObj.Section : [shapeObj.Section])
            : [];
        Iif (visio_connectors_1.isConnectorShape(shapeObj, context)) {
            return null;
        }
        var pageHeight = visio_core_1.inchToPx(context.data.currentPage.pageHeight);
        var cellMap = visio_core_1.mapCellValues(cells);
        var pinYExists = cellMap.has('PinY');
        var getcell = getGeometryCells(section, visio_core_1.mapCellValues);
        var shape = new visio_models_1.VisioShape();
        shape.id = attributes.ID;
        shape.masterId = attributes.Master;
        shape.name = attributes.NameU;
        shape.type = attributes.Type != null ? attributes.Type : 'Shape';
        Iif (shape.name === 'Solid') {
            shape.fillColor = cellMap.get('FillForegnd') || 'transParent';
        }
        else {
            var defaultData = visio_model_parsers_1.setDefaultData(context.data.shapes, attributes);
            applyCommonNodeProperties(shape, {
                cellMap: cellMap,
                attributes: attributes,
                defaultData: defaultData,
                pageHeight: pageHeight,
                pinYExists: pinYExists,
                context: context,
                getcell: getcell,
                shapeData: shapeObj
            });
            assignShapeLayer(shape, cellMap, context);
        }
        resultShapes.push(shape);
        return shape;
    }
    function getGeometryCells(section, cellMapper) {
        for (var _i = 0, _a = section || []; _i < _a.length; _i++) {
            var sec = _a[_i];
            if (sec.$.N === 'Geometry' && sec.Cell) {
                var geometryCells = Array.isArray(sec.Cell) ? sec.Cell : [sec.Cell];
                return cellMapper(geometryCells);
            }
        }
        return new Map();
    }
    function assignShapeLayer(shape, cellMap, context) {
        var shapeId = shape.id;
        Iif (!shapeId) {
            return;
        }
        var layerValue = cellMap.get('LayerMember');
        var layerIndex = layerValue != null ? parseInt(layerValue.toString(), 10) : 0;
        shape.layerMember = layerIndex;
        var layers = context.data.currentPage.layers;
        if (Array.isArray(layers) && layers.length > 0 && layerIndex >= 0 && layers[parseInt(layerIndex.toString(), 10)]) {
            layers[parseInt(layerIndex.toString(), 10)].objects.push(shape.id);
        }
    }
    function applyConstraints(shape, cellMap) {
        var lockKeys = [
            'LockWidth',
            'LockHeight',
            'LockAspect',
            'LockMoveY',
            'LockMoveX',
            'LockRotate',
            'LockDelete',
            'LockSelect',
            'LockTextEdit',
            'Comment',
            'GlueType',
            'AllowDrop'
        ];
        for (var _i = 0, lockKeys_1 = lockKeys; _i < lockKeys_1.length; _i++) {
            var key = lockKeys_1[_i];
            var value = cellMap.get(key);
            shape[visio_core_1.toCamelCase(key)] = value != null && value !== '0';
        }
    }
    function collectDeepAnnotationText(shapeNode) {
        Iif (!shapeNode) {
            return [];
        }
        var results = [];
        if (shapeNode.Text && typeof shapeNode.Text.value === 'string') {
            var text = shapeNode.Text.value.trim();
            Eif (text.length > 0) {
                results.push(text);
            }
        }
        if (shapeNode.Shapes && shapeNode.Shapes.Shape) {
            var children = Array.isArray(shapeNode.Shapes.Shape)
                ? shapeNode.Shapes.Shape
                : [shapeNode.Shapes.Shape];
            for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
                var c = children_1[_i];
                results.push.apply(results, collectDeepAnnotationText(c));
            }
        }
        return results;
    }
});