|
| 1 | +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ELK = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ |
| 2 | +"use strict"; |
| 3 | + |
| 4 | +Object.defineProperty(exports, "__esModule", { |
| 5 | + value: true |
| 6 | +}); |
| 7 | +exports["default"] = void 0; |
| 8 | +function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } |
| 9 | +function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } |
| 10 | +function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } |
| 11 | +function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } |
| 12 | +function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } |
| 13 | +function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } |
| 14 | +/******************************************************************************* |
| 15 | + * Copyright (c) 2017 Kiel University and others. |
| 16 | + * |
| 17 | + * This program and the accompanying materials are made |
| 18 | + * available under the terms of the Eclipse Public License 2.0 |
| 19 | + * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| 20 | + * |
| 21 | + * SPDX-License-Identifier: EPL-2.0 |
| 22 | + *******************************************************************************/ |
| 23 | +var ELK = exports["default"] = /*#__PURE__*/function () { |
| 24 | + function ELK() { |
| 25 | + var _this = this; |
| 26 | + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, |
| 27 | + _ref$defaultLayoutOpt = _ref.defaultLayoutOptions, |
| 28 | + defaultLayoutOptions = _ref$defaultLayoutOpt === void 0 ? {} : _ref$defaultLayoutOpt, |
| 29 | + _ref$algorithms = _ref.algorithms, |
| 30 | + algorithms = _ref$algorithms === void 0 ? ['layered', 'stress', 'mrtree', 'radial', 'force', 'disco', 'sporeOverlap', 'sporeCompaction', 'rectpacking'] : _ref$algorithms, |
| 31 | + workerFactory = _ref.workerFactory, |
| 32 | + workerUrl = _ref.workerUrl; |
| 33 | + _classCallCheck(this, ELK); |
| 34 | + this.defaultLayoutOptions = defaultLayoutOptions; |
| 35 | + this.initialized = false; |
| 36 | + |
| 37 | + // check valid worker construction possible |
| 38 | + if (typeof workerUrl === 'undefined' && typeof workerFactory === 'undefined') { |
| 39 | + throw new Error("Cannot construct an ELK without both 'workerUrl' and 'workerFactory'."); |
| 40 | + } |
| 41 | + var factory = workerFactory; |
| 42 | + if (typeof workerUrl !== 'undefined' && typeof workerFactory === 'undefined') { |
| 43 | + // use default Web Worker |
| 44 | + factory = function factory(url) { |
| 45 | + return new Worker(url); |
| 46 | + }; |
| 47 | + } |
| 48 | + |
| 49 | + // create the worker |
| 50 | + var worker = factory(workerUrl); |
| 51 | + if (typeof worker.postMessage !== 'function') { |
| 52 | + throw new TypeError("Created worker does not provide" + " the required 'postMessage' function."); |
| 53 | + } |
| 54 | + |
| 55 | + // wrap the worker to return promises |
| 56 | + this.worker = new PromisedWorker(worker); |
| 57 | + |
| 58 | + // initially register algorithms |
| 59 | + this.worker.postMessage({ |
| 60 | + cmd: 'register', |
| 61 | + algorithms: algorithms |
| 62 | + }).then(function (r) { |
| 63 | + return _this.initialized = true; |
| 64 | + })["catch"](console.err); |
| 65 | + } |
| 66 | + return _createClass(ELK, [{ |
| 67 | + key: "layout", |
| 68 | + value: function layout(graph) { |
| 69 | + var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, |
| 70 | + _ref2$layoutOptions = _ref2.layoutOptions, |
| 71 | + layoutOptions = _ref2$layoutOptions === void 0 ? this.defaultLayoutOptions : _ref2$layoutOptions, |
| 72 | + _ref2$logging = _ref2.logging, |
| 73 | + logging = _ref2$logging === void 0 ? false : _ref2$logging, |
| 74 | + _ref2$measureExecutio = _ref2.measureExecutionTime, |
| 75 | + measureExecutionTime = _ref2$measureExecutio === void 0 ? false : _ref2$measureExecutio; |
| 76 | + if (!graph) { |
| 77 | + return Promise.reject(new Error("Missing mandatory parameter 'graph'.")); |
| 78 | + } |
| 79 | + return this.worker.postMessage({ |
| 80 | + cmd: 'layout', |
| 81 | + graph: graph, |
| 82 | + layoutOptions: layoutOptions, |
| 83 | + options: { |
| 84 | + logging: logging, |
| 85 | + measureExecutionTime: measureExecutionTime |
| 86 | + } |
| 87 | + }); |
| 88 | + } |
| 89 | + }, { |
| 90 | + key: "knownLayoutAlgorithms", |
| 91 | + value: function knownLayoutAlgorithms() { |
| 92 | + return this.worker.postMessage({ |
| 93 | + cmd: 'algorithms' |
| 94 | + }); |
| 95 | + } |
| 96 | + }, { |
| 97 | + key: "knownLayoutOptions", |
| 98 | + value: function knownLayoutOptions() { |
| 99 | + return this.worker.postMessage({ |
| 100 | + cmd: 'options' |
| 101 | + }); |
| 102 | + } |
| 103 | + }, { |
| 104 | + key: "knownLayoutCategories", |
| 105 | + value: function knownLayoutCategories() { |
| 106 | + return this.worker.postMessage({ |
| 107 | + cmd: 'categories' |
| 108 | + }); |
| 109 | + } |
| 110 | + }, { |
| 111 | + key: "terminateWorker", |
| 112 | + value: function terminateWorker() { |
| 113 | + if (this.worker) this.worker.terminate(); |
| 114 | + } |
| 115 | + }]); |
| 116 | +}(); |
| 117 | +var PromisedWorker = /*#__PURE__*/function () { |
| 118 | + function PromisedWorker(worker) { |
| 119 | + var _this2 = this; |
| 120 | + _classCallCheck(this, PromisedWorker); |
| 121 | + if (worker === undefined) { |
| 122 | + throw new Error("Missing mandatory parameter 'worker'."); |
| 123 | + } |
| 124 | + this.resolvers = {}; |
| 125 | + this.worker = worker; |
| 126 | + this.worker.onmessage = function (answer) { |
| 127 | + // why is this necessary? |
| 128 | + setTimeout(function () { |
| 129 | + _this2.receive(_this2, answer); |
| 130 | + }, 0); |
| 131 | + }; |
| 132 | + } |
| 133 | + return _createClass(PromisedWorker, [{ |
| 134 | + key: "postMessage", |
| 135 | + value: function postMessage(msg) { |
| 136 | + var id = this.id || 0; |
| 137 | + this.id = id + 1; |
| 138 | + msg.id = id; |
| 139 | + var self = this; |
| 140 | + return new Promise(function (resolve, reject) { |
| 141 | + // prepare the resolver |
| 142 | + self.resolvers[id] = function (err, res) { |
| 143 | + if (err) { |
| 144 | + self.convertGwtStyleError(err); |
| 145 | + reject(err); |
| 146 | + } else { |
| 147 | + resolve(res); |
| 148 | + } |
| 149 | + }; |
| 150 | + // post the message |
| 151 | + self.worker.postMessage(msg); |
| 152 | + }); |
| 153 | + } |
| 154 | + }, { |
| 155 | + key: "receive", |
| 156 | + value: function receive(self, answer) { |
| 157 | + var json = answer.data; |
| 158 | + var resolver = self.resolvers[json.id]; |
| 159 | + if (resolver) { |
| 160 | + delete self.resolvers[json.id]; |
| 161 | + if (json.error) { |
| 162 | + resolver(json.error); |
| 163 | + } else { |
| 164 | + resolver(null, json.data); |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | + }, { |
| 169 | + key: "terminate", |
| 170 | + value: function terminate() { |
| 171 | + if (this.worker) { |
| 172 | + this.worker.terminate(); |
| 173 | + } |
| 174 | + } |
| 175 | + }, { |
| 176 | + key: "convertGwtStyleError", |
| 177 | + value: function convertGwtStyleError(err) { |
| 178 | + if (!err) { |
| 179 | + return; |
| 180 | + } |
| 181 | + // Somewhat flatten the way GWT stores nested exception(s) |
| 182 | + var javaException = err['__java$exception']; |
| 183 | + if (javaException) { |
| 184 | + // Note that the property name of the nested exception is different |
| 185 | + // in the non-minified ('cause') and the minified (not deterministic) version. |
| 186 | + // Hence, the version below only works for the non-minified version. |
| 187 | + // However, as the minified stack trace is not of much use anyway, one |
| 188 | + // should switch the used version for debugging in such a case. |
| 189 | + if (javaException.cause && javaException.cause.backingJsObject) { |
| 190 | + err.cause = javaException.cause.backingJsObject; |
| 191 | + this.convertGwtStyleError(err.cause); |
| 192 | + } |
| 193 | + delete err['__java$exception']; |
| 194 | + } |
| 195 | + } |
| 196 | + }]); |
| 197 | +}(); |
| 198 | +},{}],2:[function(require,module,exports){ |
| 199 | +"use strict"; |
| 200 | + |
| 201 | +/******************************************************************************* |
| 202 | + * Copyright (c) 2021 Kiel University and others. |
| 203 | + * This program and the accompanying materials are made available under the |
| 204 | + * terms of the Eclipse Public License 2.0 which is available at |
| 205 | + * http://www.eclipse.org/legal/epl-2.0. |
| 206 | + * |
| 207 | + * SPDX-License-Identifier: EPL-2.0 |
| 208 | + *******************************************************************************/ |
| 209 | +var ELK = require('./elk-api.js')["default"]; |
| 210 | +Object.defineProperty(module.exports, "__esModule", { |
| 211 | + value: true |
| 212 | +}); |
| 213 | +module.exports = ELK; |
| 214 | +ELK["default"] = ELK; |
| 215 | +},{"./elk-api.js":1}]},{},[2])(2) |
| 216 | +}); |
0 commit comments