UNPKG

drawio-offline

Version:
991 lines (918 loc) 749 kB
var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; /* Generated from Java with JSweet 2.0.0-rc1 - http://www.jsweet.org */ var com; (function (com) { var mxgraph; (function (mxgraph) { var io; (function (io) { /** * Parses a .vsdx XML diagram file and imports it in the given graph.<br/> * @class */ var mxVsdxCodec = (function () { function mxVsdxCodec(editorUi) { this.RESPONSE_END = "</mxfile>"; this.RESPONSE_DIAGRAM_START = ""; this.RESPONSE_DIAGRAM_END = "</diagram>"; this.RESPONSE_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><mxfile>"; /** * Stores the vertexes imported. */ this.vertexMap = ({}); /** * Stores the shapes that represent Edges. */ this.edgeShapeMap = ({}); /** * Stores the shapes that represent Vertexes. */ this.vertexShapeMap = ({}); /** * Stores the parents of the shapes imported. */ this.parentsMap = ({}); this.layersMap = ({}); /** * Set to true if you want to display spline debug data */ this.debugPaths = false; this.vsdxModel = null; this.editorUi = editorUi; } mxVsdxCodec.vsdxPlaceholder_$LI$ = function () { if (mxVsdxCodec.vsdxPlaceholder == null) { var tmp = "dmlzaW8="; mxVsdxCodec.vsdxPlaceholder = (window.atob) ? atob(tmp) : Base64.decode(tmp, true); } return mxVsdxCodec.vsdxPlaceholder; }; mxVsdxCodec.parsererrorNS_$LI$ = function () { if (mxVsdxCodec.parsererrorNS == null) { mxVsdxCodec.parsererrorNS = ""; if (window.DOMParser) { var parser = new DOMParser(); try { mxVsdxCodec.parsererrorNS = parser.parseFromString('<', 'text/xml').getElementsByTagName("parsererror")[0].namespaceURI; } catch(e) { //ignore! IE11 throw an exception on XML syntax error } } } return mxVsdxCodec.parsererrorNS; }; mxVsdxCodec.parseXml = function (xml) { try { var doc = mxUtils.parseXml(xml); if (doc.getElementsByTagNameNS(mxVsdxCodec.parsererrorNS, 'parsererror').length > 0) { return null; } else { return doc; } } catch (e) { //IE11 throw an exception on XML syntax error return null; } }; //TODO Optimize this function mxVsdxCodec.decodeUTF16LE = function ( binaryStr ) { var cp = ""; for( var i = 0; i < binaryStr.length; i+=2) { cp += String.fromCharCode( binaryStr.charCodeAt(i) | ( binaryStr.charCodeAt(i+1) << 8 ) ); } return cp ; } mxVsdxCodec.prototype.scaleGraph = function(graph, scale) { if (scale !== 1) { var model = graph.getModel(); { for (var id in model.cells) { var c = model.cells[id]; { var geo = model.getGeometry(c); if (geo != null) { this.scaleRect(geo, scale); this.scaleRect(geo.alternateBounds, scale); if (model.isEdge(c)) { this.scalePoint(geo.sourcePoint, scale); this.scalePoint(geo.targetPoint, scale); this.scalePoint(geo.offset, scale); var points = geo.points; if (points != null) { for (var index125 = 0; index125 < points.length; index125++) { var p = points[index125]; { this.scalePoint(p, scale); } } } } } } } } } }; mxVsdxCodec.incorrectXMLReqExp = [ { regExp: /\&(?!amp;|lt;|gt;|quot;|#)/g, repl: '&amp;' } ]; /** * Parses the input VSDX format and uses the information to populate * the specified graph. * @param docs All XML documents contained in the VSDX source file * @throws IOException * @throws ParserConfigurationException * @throws SAXException * @throws TransformerException * @param {Array} data * @param {string} charset * @return {string} */ //FIXME TODO add charset support mxVsdxCodec.prototype.decodeVsdx = function (file, callback, charset, onerror) { var _this = this; var docData = ({}); var mediaData = ({}); var allDone = function () { var path = mxVsdxCodec.vsdxPlaceholder + "/document.xml"; var rootDoc = (function (m, k) { return m[k] ? m[k] : null; })(docData, path); var rootChild = rootDoc.firstChild; while (rootChild != null && !(rootChild.nodeType == 1)) { rootChild = rootChild.nextSibling; } ; if (rootChild != null && (rootChild.nodeType == 1)) { _this.importNodes(rootDoc, rootChild, path, docData); } else { return null; } _this.vsdxModel = new com.mxgraph.io.vsdx.mxVsdxModel(rootDoc, docData, mediaData); var pages = _this.vsdxModel.getPages(); var xmlBuilder = { str: _this.RESPONSE_HEADER, toString: function () { return this.str; } }; { var array122 = (function (m) { if (m.entries == null) m.entries = []; return m.entries; })(pages); var _loop_1 = function (index121, remaining) { var entry = array122[index121]; { var page_1 = entry.getValue(); //As per many requests, include all pages in the output //if (!page_1.isBackground()) { var graph_1 = this_1.createMxGraph(); graph_1.getModel().beginUpdate(); this_1.importPage(page_1, graph_1, graph_1.getDefaultParent(), true); this_1.scaleGraph(graph_1, page_1.getPageScale() / page_1.getDrawingScale()); graph_1.getModel().endUpdate(); this_1.postImportPage(page_1, graph_1, function() { this_1.sanitiseGraph(graph_1); /* append */ (function (sb) { return sb.str = sb.str.concat(_this.RESPONSE_DIAGRAM_START); })(xmlBuilder); /* append */ (function (sb) { return sb.str = sb.str.concat(_this.processPage(graph_1, page_1)); })(xmlBuilder); /* append */ (function (sb) { return sb.str = sb.str.concat(_this.RESPONSE_DIAGRAM_END); })(xmlBuilder); if (index121 < array122.length - 1) { _loop_1(index121 + 1, remaining); } else { remaining(); } }); } } }; var this_1 = _this; if (array122.length > 0) { _loop_1(0, remaining); } else { remaining(); } } function remaining() { /* append */ (function (sb) { return sb.str = sb.str.concat(_this.RESPONSE_END); })(xmlBuilder); var dateAfter = new Date(); //console.log("File processed in " + (dateAfter - dateBefore) + "ms"); //console.log(xmlBuilder.str); if (callback) { callback(xmlBuilder.str); } } }; var dateBefore = new Date(); var filesCount = 0; var processedFiles = 0; var doneCheck = function() { if (processedFiles == filesCount) { var dateAfter = new Date(); //console.log(processedFiles + " File extracted in " + (dateAfter - dateBefore) + "ms"); try { allDone(); } catch(e) { console.log(e); if (onerror != null) { onerror(); } else { callback(""); } } } }; JSZip.loadAsync(file) .then(function(zip) { if (Object.keys(zip.files).length == 0) { if (onerror != null) { onerror(); } } else { var dateAfter = new Date(); //console.log(" (loaded in " + (dateAfter - dateBefore) + "ms)"); zip.forEach(function (relativePath, zipEntry) { var filename = zipEntry.name; var name = filename.toLowerCase(); var nameLen = name.length; if (name.indexOf('.xml') == nameLen - 4 || name.indexOf('.rels') == nameLen - 5) //xml files { filesCount++; zipEntry.async("string").then(function (str) { if (!(str.length === 0)) { //UTF-8 BOM causes exception while parsing, so remove it //TODO is the text encoding will be correct or string must be re-read as UTF-8? if (str.charCodeAt(0) == 65279) { str = str.substring(1); } var doc = mxVsdxCodec.parseXml(str); if (doc == null) { if (str.charCodeAt(1) === 0 && str.charCodeAt(3) === 0 && str.charCodeAt(5) === 0) { doc = mxVsdxCodec.parseXml(mxVsdxCodec.decodeUTF16LE(str)); } else { for (var r = 0; r < mxVsdxCodec.incorrectXMLReqExp.length; r++) { if (mxVsdxCodec.incorrectXMLReqExp[r].regExp.test(str)) { str = str.replace(mxVsdxCodec.incorrectXMLReqExp[r].regExp, mxVsdxCodec.incorrectXMLReqExp[r].repl); } } doc = mxVsdxCodec.parseXml(str); } //TODO add any other non-standard encoding that may be needed } if (doc != null) { doc.vsdxFileName = filename; /* put */ (docData[filename] = doc); } } processedFiles++; doneCheck(); }); } else if (name.indexOf(mxVsdxCodec.vsdxPlaceholder + "/media") === 0)//binary files { filesCount++; if ((function (str, searchString) { var pos = str.length - searchString.length; var lastIndex = str.indexOf(searchString, pos); return lastIndex !== -1 && lastIndex === pos; })(name, ".emf")) { var emfDone = function() { processedFiles++; doneCheck(); } if (JSZip.support.blob && window.EMF_CONVERT_URL) { zipEntry.async("blob").then(function (emfBlob) { //send to emf conversion service var formData = new FormData(); formData.append('img', emfBlob, name); formData.append('inputformat', 'emf'); formData.append('outputformat', 'png'); var xhr = new XMLHttpRequest(); xhr.open('POST', EMF_CONVERT_URL); xhr.responseType = 'blob'; _this.editorUi.addRemoteServiceSecurityCheck(xhr); xhr.onreadystatechange = mxUtils.bind(this, function() { if (xhr.readyState == 4) { if (xhr.status >= 200 && xhr.status <= 299) { try { var reader = new FileReader(); reader.readAsDataURL(xhr.response); reader.onloadend = function() { var dataPos = reader.result.indexOf(',') + 1; mediaData[filename] = reader.result.substr(dataPos); emfDone(); } } catch (e) { console.log(e); emfDone(); } } else { emfDone(); } } }); xhr.send(formData); }); } else { emfDone(); } } else if ((function (str, searchString) { var pos = str.length - searchString.length; var lastIndex = str.indexOf(searchString, pos); return lastIndex !== -1 && lastIndex === pos; })(name, ".bmp")) { if (JSZip.support.uint8array) { zipEntry.async("uint8array").then(function (bmpData) { var bitmap = new BmpDecoder(bmpData); var c = document.createElement("canvas"); c.width = bitmap.width; c.height = bitmap.height; var ctx = c.getContext("2d"); ctx.putImageData(bitmap.imageData, 0, 0); var jpgData = c.toDataURL("image/jpeg"); /* put */ (mediaData[filename] = jpgData.substr(23)); //23 is the length of "data:image/jpeg;base64," processedFiles++; doneCheck(); }); } } else { zipEntry.async("base64").then(function (base64Str) { // if ((function (str, searchString) { var pos = str.length - searchString.length; var lastIndex = str.indexOf(searchString, pos); return lastIndex !== -1 && lastIndex === pos; })(name, ".bmp")) { // try // { // //convert BMP files to PNG // var bmpImg = new Image(); // // bmpImg.onload = function() { // var c = document.createElement("canvas"); // c.width = bmpImg.width; // c.height = bmpImg.height; // var ctx = c.getContext("2d"); // ctx.drawImage(bmpImg, 0, 0); // var jpgData = c.toDataURL("image/jpeg"); // // /* put */ (mediaData[filename] = jpgData.substr(23)); //23 is the length of "data:image/jpeg;base64," // // processedFiles++; // doneCheck(); // }; // // bmpImg.src = "data:image/bmp;base64," + base64Str; // } // catch (e) {} //conversion failed. Nothing can be done! // } // else // { /* put */ (mediaData[filename] = base64Str); processedFiles++; doneCheck(); // } }); } } }); } }, function (e) { //console.log("Error!" + e.message); if (onerror != null) { onerror(e); } }); }; mxVsdxCodec.prototype.createMxGraph = function () { var graph = new Graph(); graph.setExtendParents(false); graph.setExtendParentsOnAdd(false); graph.setConstrainChildren(false); graph.setHtmlLabels(true); graph.getModel().maintainEdgeParent = false; return graph; }; mxVsdxCodec.prototype.processPage = function (graph, page) { var codec = new mxCodec(); var node = codec.encode(graph.getModel()); node.setAttribute("style", "default-style2"); var modelString = mxUtils.getXml(node); var output = ""; if (page != null) { //var pageName_1 = org.apache.commons.lang3.StringEscapeUtils.escapeXml11(page.getPageName()); //TODO FIXME htmlEntities is not exactly as escapeXml11 but close var pageName_1 = mxUtils.htmlEntities(page.getPageName()) + (page.isBackground()? ' (Background)' : ''); output += '<diagram name="' + pageName_1 + '" id="' + pageName_1.replace(/\s/g, '_') + '">'; } output += Graph.compress(modelString); return output; }; /** * Scale a point in place * * @param {mxPoint} p point to scale in place * @param {number} scale scale * @return {mxPoint} scaled point * @private */ /*private*/ mxVsdxCodec.prototype.scalePoint = function (p, scale) { if (p != null) { p.x = (p.x * scale); p.y = (p.y * scale); } return p; }; /** * Scale a rectangle in place * * @param {mxRectangle} rect rectangle to scale in place * @param {number} scale scale * @return {mxRectangle} scaled rectangle * @private */ /*private*/ mxVsdxCodec.prototype.scaleRect = function (rect, scale) { if (rect != null) { rect.x = (rect.x * scale); rect.y = (rect.y * scale); rect.height = (rect.height * scale); rect.width = (rect.width * scale); } return rect; }; /** * * @param {*} rootDoc * @param {*} currentNode * @param {string} path * @param {*} docData * @private */ /*private*/ mxVsdxCodec.prototype.importNodes = function (rootDoc, currentNode, path, docData) { var lastSlash = path.lastIndexOf("/"); var dir = path; var fileName = path; if (lastSlash !== -1) { dir = path.substring(0, lastSlash); fileName = path.substring(lastSlash + 1, path.length); } else { return; } var relsPath = dir + "/_rels/" + fileName + ".rels"; var relsDoc = (function (m, k) { return m[k] ? m[k] : null; })(docData, relsPath); if (relsDoc == null) { return; } var rels = relsDoc.getElementsByTagName("Relationship"); var relMap = ({}); for (var i = 0; i < rels.length; i++) { var currElem = rels.item(i); var id = currElem.getAttribute("Id"); var target = currElem.getAttribute("Target"); /* put */ (relMap[id] = target); } ; var relList = currentNode.getElementsByTagName("Rel"); for (var i = 0; i < relList.length; i++) { var rel = relList.item(i); var pathSuffix = (function (m, k) { return m[k] ? m[k] : null; })(relMap, rel.getAttribute("r:id")); var target = dir + "/" + pathSuffix; if (target != null) { var childDoc = (function (m, k) { return m[k] ? m[k] : null; })(docData, target); if (childDoc != null) { var parent_1 = rel.parentNode; var rootChild = childDoc.firstChild; while (rootChild != null && !(rootChild.nodeType == 1)) { rootChild = rootChild.nextSibling; } ; if (rootChild != null && (rootChild.nodeType == 1)) { var importNode = rootChild.firstChild; while ((importNode != null)) { if (importNode != null && importNode.nodeType == 1) { var newNode = parent_1.appendChild(rootDoc.importNode(importNode, true)); var pathTmp = target; this.importNodes(rootDoc, newNode, pathTmp, docData); } importNode = importNode.nextSibling; } ; } } } } ; }; /** * Imports a page of the document with the actual pageHeight.<br/> * In .vdx, the Y-coordinate grows upward from the bottom of the page.<br/> * The page height is used for calculating the correct position in mxGraph using * this formula: mxGraph_Y_Coord = PageHeight - VSDX_Y_Coord. * @param {com.mxgraph.io.vsdx.mxVsdxPage} page Actual page Element to be imported * @param {mxGraph} graph Graph where the parsed graph is included. * @param {*} parent The parent of the elements to be imported. * @return {number} */ mxVsdxCodec.prototype.importPage = function (page, graph, parent, noSanitize) { //BackPages can include another backPage, so it is recursive var backPage = page.getBackPage(); if (backPage != null) { graph.getModel().setValue(graph.getDefaultParent(), page.getPageName()); var backCell = new mxCell(backPage.getPageName()); graph.addCell(backCell, graph.getModel().getRoot(), 0, null, null); this.importPage(backPage, graph, graph.getDefaultParent()); } //TODO KNOWN ISSUE: VSDX layers are virtual grouping where parts of a group can be members of a layers while the remaining group members belong to another layer // This cannot be done in draw.io currently // Also, layers should NOT affect cells order. So, as a best effort solution, layers should be orders such that the cells order is maintained //add page layers var layers = page.getLayers(); this.layersMap[0] = graph.getDefaultParent(); var layersOrder = {}, lastOrder = 0, lastLayer = null; var shapes = page.getShapes(); try { //Trying to determine layers order for (var k = 0; shapes.entries != null && k < shapes.entries.length; k++) { var layer = shapes.entries[k].getValue().layerMember; if (layer != null) { if (lastLayer == null) { layersOrder[layer] = lastOrder; lastLayer = layer; } else if (lastLayer != layer && layersOrder[layer] == null) { lastOrder++; layersOrder[layer] = lastOrder; lastLayer = layer; } } } } catch(e) { console.log('VSDX Import: Failed to detect layers order'); } for (var k = 0; k < layers.length; k++) { var layer = layers[k]; var layerIndex = layersOrder[k] != null? layersOrder[k] : k; if (layerIndex == 0) { var layerCell = graph.getDefaultParent(); } else { var layerCell = new mxCell(); graph.addCell(layerCell, graph.model.root, layerIndex); } layerCell.setVisible(layer.Visible == 1); if (layer.Lock == 1) { layerCell.setStyle("locked=1;"); } //TODO handlle color and other properties layerCell.setValue(layer.Name); this.layersMap[k] = layerCell; } //add shapes var entries = (function (a) { var i = 0; return { next: function () { return i < a.length ? a[i++] : null; }, hasNext: function () { return i < a.length; } }; })(/* entrySet */ (function (m) { if (m.entries == null) m.entries = []; return m.entries; })(shapes)); var pageHeight = page.getPageDimensions().y; var pageId = page.getId(); while ((entries.hasNext())) { var entry = entries.next(); var shape = entry.getValue(); var p = this.layersMap[shape.layerMember]; this.addShape(graph, shape, p? p : parent, pageId, pageHeight); } ; var connects = page.getConnects(); var entries2 = (function (a) { var i = 0; return { next: function () { return i < a.length ? a[i++] : null; }, hasNext: function () { return i < a.length; } }; })(/* entrySet */ (function (m) { if (m.entries == null) m.entries = []; return m.entries; })(connects)); while ((entries2.hasNext())) { var entry = entries2.next(); var edgeId = this.addConnectedEdge(graph, entry.getValue(), pageId, pageHeight); if (edgeId != null) { /* remove */ (function (m, k) { if (m.entries == null) m.entries = []; for (var i = 0; i < m.entries.length; i++) if (m.entries[i].key.equals != null && m.entries[i].key.equals(k) || m.entries[i].key === k) { return m.entries.splice(i, 1)[0]; } })(this.edgeShapeMap, edgeId); } } ; var it = (function (a) { var i = 0; return { next: function () { return i < a.length ? a[i++] : null; }, hasNext: function () { return i < a.length; } }; })(/* entrySet */ (function (m) { if (m.entries == null) m.entries = []; return m.entries; })(this.edgeShapeMap)); while ((it.hasNext())) { var edgeShapeEntry = it.next(); if (edgeShapeEntry.getKey().getPageNumber() === pageId) { this.addUnconnectedEdge(graph, /* get */ (function (m, k) { if (m.entries == null) m.entries = []; for (var i = 0; i < m.entries.length; i++) if (m.entries[i].key.equals != null && m.entries[i].key.equals(k) || m.entries[i].key === k) { return m.entries[i].value; } return null; })(this.parentsMap, edgeShapeEntry.getKey()), edgeShapeEntry.getValue(), pageHeight); } } ; if (!noSanitize) { this.sanitiseGraph(graph); } return pageHeight; }; /** * This function is for doing any async processing needed after importing a page */ mxVsdxCodec.prototype.postImportPage = function(page, graph, callback) { try { var me = this; var toCropImgs = []; var shapes = page.getShapes().entries || []; for (var i = 0; i < shapes.length; i++) { var shape = shapes[i].value || {}; if (shape.toBeCroppedImg) { toCropImgs.push(shape); } } if (toCropImgs.length > 0) { function cropImage(index, callback) { function next() { if (index < toCropImgs.length - 1) { cropImage(index + 1, callback); } else { callback(); } }; var shape = toCropImgs[index]; var imgInfo = shape.toBeCroppedImg; var cell = (function (m, k) { if (m.entries == null) m.entries = []; for (var i = 0; i < m.entries.length; i++) if (m.entries[i].key.equals != null && m.entries[i].key.equals(k) || m.entries[i].key === k) { return m.entries[i].value; } return null; })(me.vertexMap, new com.mxgraph.io.vsdx.ShapePageId(page.Id, shape.Id)); var img = new Image(); img.onload = function() { var data = imgInfo.iData; var type = imgInfo.iType; try { //TODO There is still some minor inaccuracy in width/height var scaleX = img.width / imgInfo.imgWidth; var scaleY = img.height / imgInfo.imgHeight; var offsetX = (-imgInfo.imgOffsetX) * scaleX; var offsetY = (imgInfo.imgHeight - imgInfo.height + imgInfo.imgOffsetY) * scaleY; var c = document.createElement("canvas"); c.width = imgInfo.width * scaleX; c.height = imgInfo.height * scaleY; var ctx = c.getContext("2d"); ctx.fillStyle = "#FFFFFF"; ctx.fillRect(0, 0, c.width, c.height); ctx.drawImage(img, offsetX, offsetY, c.width, c.height, 0, 0, c.width, c.height); var jpgData = c.toDataURL("image/jpeg"); data = jpgData.substr(23); //23 is the length of "data:image/jpeg;base64," type = 'jpg'; } catch(e) { console.log(e); } cell.style += ';image=data:image/' + type + ',' + data; next(); }; img.src = 'data:image/' + imgInfo.iType + ';base64,' + imgInfo.iData; img.onerror = function() { cell.style += ';image=data:image/' + imgInfo.iType + ',' + imgInfo.iData; next(); } }; cropImage(0, callback); } else { callback(); } } catch(e) { console.log(e); callback(); } }; /** * Adds a vertex to the graph if 'shape' is a vertex or add the shape to edgeShapeMap if it is an edge. * This method doesn't import sub-shapes of 'shape'. * @param {mxGraph} graph Graph where the parsed graph is included. * @param shp Shape to be imported. * @param {number} parentHeight Height of the parent cell. * @return {mxCell} the new vertex added. null if 'shape' is not a vertex. * @param {com.mxgraph.io.vsdx.VsdxShape} shape * @param {*} parent * @param {number} pageId */ mxVsdxCodec.prototype.addShape = function (graph, shape, parent, pageId, parentHeight) { shape.parentHeight = parentHeight; var type = com.mxgraph.io.vsdx.VsdxShape.getType(shape.getShape()); if (type != null && ((function (o1, o2) { if (o1 && o1.equals) { return o1.equals(o2); } else { return o1 === o2; } })(type, com.mxgraph.io.vsdx.mxVsdxConstants.TYPE_SHAPE) || (function (o1, o2) { if (o1 && o1.equals) { return o1.equals(o2); } else { return o1 === o2; } })(type, com.mxgraph.io.vsdx.mxVsdxConstants.TYPE_GROUP) || (function (o1, o2) { if (o1 && o1.equals) { return o1.equals(o2); } else { return o1 === o2; } })(type, com.mxgraph.io.vsdx.mxVsdxConstants.FOREIGN))) { var id = shape.getId(); if (shape.isVertex()) { var v1 = null; if (shape.isGroup()) { v1 = this.addGroup(graph, shape, parent, pageId, parentHeight); } else { v1 = this.addVertex(graph, shape, parent, pageId, parentHeight); } /* put */ (function (m, k, v) { if (m.entries == null) m.entries = []; for (var i = 0; i < m.entries.length; i++) if (m.entries[i].key.equals != null && m.entries[i].key.equals(k) || m.entries[i].key === k) { m.entries[i].value = v; return; } m.entries.push({ key: k, value: v, getKey: function () { return this.key; }, getValue: function () { return this.value; } }); })(this.vertexShapeMap, new com.mxgraph.io.vsdx.ShapePageId(pageId, id), shape); var lnkObj = shape.getHyperlink(); if (lnkObj.extLink) { graph.setLinkForCell(v1, lnkObj.extLink); } else if (lnkObj.pageLink) { graph.setLinkForCell(v1, 'data:page/id,' + lnkObj.pageLink); } // Add Shape properties var props = shape.getProperties(); for (var i = 0; i < props.length; i++) { graph.setAttributeForCell(v1, props[i].key, props[i].val); } return v1; } else { shape.setShapeIndex(graph.getModel().getChildCount(parent)); /* put */ (function (m, k, v) { if (m.entries == null) m.entries = []; for (var i = 0; i < m.entries.length; i++) if (m.entries[i].key.equals != null && m.entries[i].key.equals(k) || m.entries[i].key === k) { m.entries[i].value = v; return; } m.entries.push({ key: k, value: v, getKey: function () { return this.key; }, getValue: function () { return this.value; } }); })(this.edgeShapeMap, new com.mxgraph.io.vsdx.ShapePageId(pageId, id), shape); /* put */ (function (m, k, v) { if (m.entries == null) m.entries = []; for (var i = 0; i < m.entries.length; i++) if (m.entries[i].key.equals != null && m.entries[i].key.equals(k) || m.entries[i].key === k) { m.entries[i].value = v; return; } m.entries.push({ key: k, value: v, getKey: function () { return this.key; }, getValue: function () { return this.value; } }); })(this.parentsMap, new com.mxgraph.io.vsdx.ShapePageId(pageId, id), parent); } } return null; }; /** * Adds a group to the graph. * The sub-shapes of a complex shape are processed like part of the shape. * @param {mxGraph} graph Graph where the parsed graph is included. * @param {*} parent Parent cell of the shape. * @param {number} parentHeight Height of the parent cell of the shape. * @return {mxCell} Cell added to the graph. * @param {com.mxgraph.io.vsdx.VsdxShape} shape * @param {number} pageId */ mxVsdxCodec.prototype.addGroup = function (graph, shape, parent, pageId, parentHeight) { var d = shape.getDimensions(); var master = shape.getMaster(); var styleMap = shape.getStyleFromShape(); var geomList = shape.getGeomList(); if (geomList.isNoFill()) { /* put */ (styleMap[mxConstants.STYLE_FILLCOLOR] = "none"); /* put */ (styleMap[mxConstants.STYLE_GRADIENTCOLOR] = "none"); } if (geomList.isNoLine()) { /* put */ (styleMap[mxConstants.STYLE_STROKECOLOR] = "none"); } /* put */ (styleMap["html"] = "1"); /* put */ (styleMap[mxConstants.STYLE_WHITE_SPACE] = "wrap"); var style = com.mxgraph.io.vsdx.mxVsdxUtils.getStyleString(styleMap, "="); var group = null; var children = shape.getChildShapes(); var hasChildren = children != null && (function (m) { if (m.entries == null) m.entries = []; return m.entries.length; })(children) > 0; var subLabel = shape.isDisplacedLabel() || shape.isRotatedLabel() || hasChildren; var o = shape.getOriginPoint(parentHeight, true); if (subLabel) { group = graph.insertVertex(parent, null, null, Math.floor(Math.round(o.x * 100) / 100), Math.floor(Math.round(o.y * 100) / 100), Math.floor(Math.round(d.x * 100) / 100), Math.floor(Math.round(d.y * 100) / 100), style); } else { var textLabel = shape.getTextLabel(); group = graph.insertVertex(parent, null, textLabel, Math.floor(Math.round(o.x * 100) / 100), Math.floor(Math.round(o.y * 100) / 100), Math.floor(Math.round(d.x * 100) / 100), Math.floor(Math.round(d.y * 100) / 100), style); } var entries = (function (a) { var i = 0; return { next: function () { return i < a.length ? a[i++] : null; }, hasNext: function () { return i < a.length; } }; })(/* entrySet */ (function (m) { if (m.entries == null) m.entries = []; return m.entries; })(children)); while ((entries.hasNext())) { var entry = entries.next(); var subShape = entry.getValue(); var Id = subShape.getId(); if (subShape.isVertex()) { var type = com.mxgraph.io.vsdx.VsdxShape.getType(subShape.getShape()); if (type != null && ((function (o1, o2) { if (o1 && o1.equals) { return o1.equals(o2); } else { return o1 === o2; } })(type, com.mxgraph.io.vsdx.mxVsdxConstants.TYPE_SHAPE) || (function (o1, o2) { if (o1 && o1.equals) { return o1.equals(o2); } else { return o1 === o2;