Skip to content

Commit 73ae718

Browse files
committed
add lib files for 0.12.1 release
1 parent 95f18bf commit 73ae718

10 files changed

Lines changed: 120764 additions & 0 deletions

‎lib/elk-api.d.ts‎

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2019 TypeFox and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* https://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the Eclipse
10+
* Public License v. 2.0 are satisfied: GPL-3.0 which is available at
11+
* https://www.gnu.org/licenses/gpl-3.0-standalone.html.
12+
*
13+
* SPDX-License-Identifier: EPL-2.0 OR GPL-3.0-or-later
14+
*******************************************************************************/
15+
16+
export interface LayoutOptions {
17+
[key: string]: string
18+
}
19+
20+
export interface ElkPoint {
21+
x: number
22+
y: number
23+
}
24+
25+
export interface ElkGraphElement {
26+
id?: string
27+
labels?: ElkLabel[]
28+
layoutOptions?: LayoutOptions
29+
}
30+
31+
export interface ElkShape extends ElkGraphElement {
32+
x?: number
33+
y?: number
34+
width?: number
35+
height?: number
36+
}
37+
38+
export interface ElkNode extends ElkShape {
39+
id: string
40+
children?: ElkNode[]
41+
ports?: ElkPort[]
42+
edges?: ElkExtendedEdge[]
43+
}
44+
45+
export interface ElkPort extends ElkShape {
46+
id: string
47+
}
48+
49+
export interface ElkLabel extends ElkShape {
50+
text?: string
51+
}
52+
53+
/**
54+
* @deprecated use ElkExtendedEdge directly
55+
*/
56+
export interface ElkEdge extends ElkGraphElement {
57+
id: string
58+
container?: string
59+
junctionPoints?: ElkPoint[]
60+
}
61+
62+
/**
63+
* @deprecated use ElkExtendedEdge instead
64+
*/
65+
export interface ElkPrimitiveEdge extends ElkEdge {
66+
source: string
67+
sourcePort?: string
68+
target: string
69+
targetPort?: string
70+
sourcePoint?: ElkPoint
71+
targetPoint?: ElkPoint
72+
bendPoints?: ElkPoint[]
73+
}
74+
75+
export interface ElkExtendedEdge extends ElkEdge {
76+
sources: string[]
77+
targets: string[]
78+
sections?: ElkEdgeSection[]
79+
}
80+
81+
export interface ElkEdgeSection extends ElkGraphElement {
82+
id: string
83+
startPoint: ElkPoint
84+
endPoint: ElkPoint
85+
bendPoints?: ElkPoint[]
86+
incomingShape?: string
87+
outgoingShape?: string
88+
incomingSections?: string[]
89+
outgoingSections?: string[]
90+
}
91+
92+
export interface ElkLayoutArguments {
93+
layoutOptions?: LayoutOptions
94+
logging?: boolean
95+
measureExecutionTime?: boolean
96+
}
97+
98+
export interface ElkCommonDescription {
99+
id?: string
100+
name?: string
101+
description?: string
102+
}
103+
104+
export interface ElkLayoutAlgorithmDescription extends ElkCommonDescription {
105+
category?: string
106+
knownOptions?: string[]
107+
supportedFeatures?: string[]
108+
}
109+
110+
export interface ElkLayoutOptionDescription extends ElkCommonDescription {
111+
group?: string
112+
type?: string
113+
targets?: string[]
114+
}
115+
116+
export interface ElkLayoutCategoryDescription extends ElkCommonDescription {
117+
knownLayouters?: string[]
118+
}
119+
120+
export interface ELK {
121+
layout<T extends ElkNode>(
122+
graph: T,
123+
args?: ElkLayoutArguments
124+
): Promise<Omit<T, 'children'> & { children?: (T['children'][number] & ElkNode)[] }>;
125+
knownLayoutAlgorithms(): Promise<ElkLayoutAlgorithmDescription[]>
126+
knownLayoutOptions(): Promise<ElkLayoutOptionDescription[]>
127+
knownLayoutCategories(): Promise<ElkLayoutCategoryDescription[]>
128+
terminateWorker(): void;
129+
}
130+
131+
export interface ELKConstructorArguments {
132+
defaultLayoutOptions?: LayoutOptions
133+
algorithms?: string[]
134+
workerUrl?: string
135+
workerFactory?: (url?: string) => Worker
136+
}
137+
138+
declare const ElkConstructor: {
139+
new(args?: ELKConstructorArguments): ELK;
140+
};
141+
export default ElkConstructor;

‎lib/elk-api.js‎

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

‎lib/elk-worker.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type Worker = Worker

0 commit comments

Comments
 (0)