-
Notifications
You must be signed in to change notification settings - Fork 23
/
cytoscape-popper.js
381 lines (300 loc) · 9.99 KB
/
cytoscape-popper.js
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
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["cytoscapePopper"] = factory();
else
root["cytoscapePopper"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 7);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _require = __webpack_require__(5),
getBoundingBox = _require.getBoundingBox;
// Create a popper virtual element (aka popper v1 reference object)
// https://popper.js.org/docs/v2/virtual-elements/
function getRef(target, opts) {
//Define popper reference object and cy reference object
var refObject = {
getBoundingClientRect: function getBoundingClientRect() {
return getBoundingBox(target, opts);
}
};
return refObject;
}
module.exports = { getRef: getRef };
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
// Simple, internal Object.assign() polyfill for options objects etc.
module.exports = Object.assign != null ? Object.assign.bind(Object) : function (tgt) {
for (var _len = arguments.length, srcs = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
srcs[_key - 1] = arguments[_key];
}
srcs.forEach(function (src) {
if (src !== null && src !== undefined) {
Object.keys(src).forEach(function (k) {
return tgt[k] = src[k];
});
}
});
return tgt;
};
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _require = __webpack_require__(0),
getRef = _require.getRef;
var _require2 = __webpack_require__(6),
getContent = _require2.getContent;
// Create a new popper object for a core or element target
function getPopper(target, opts) {
var refObject = getRef(target, opts);
var content = getContent(target, opts.content);
return target.popperFactory(refObject, content, opts.popper);
}
module.exports = { getPopper: getPopper };
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var assign = __webpack_require__(1);
var _require = __webpack_require__(2),
getPopper = _require.getPopper;
var _require2 = __webpack_require__(0),
getRef = _require2.getRef;
function popper(opts) {
checkForWarning(this);
return getPopper(this[0], createOptionsObject(this[0], opts));
}
function popperRef(opts) {
checkForWarning(this);
return getRef(this[0], createOptionsObject(this[0], opts));
}
function createOptionsObject(target, opts) {
var renderedDimensions = function renderedDimensions(el) {
return el.isNode() ? { w: el.renderedWidth(), h: el.renderedHeight() } : { w: 3, h: 3 };
};
var renderedPosition = function renderedPosition(el) {
return el.isNode() ? getRenderedCenter(el, renderedDimensions) : getRenderedMidpoint(el);
};
var popper = {};
var cy = target.cy();
var defaults = { renderedDimensions: renderedDimensions, renderedPosition: renderedPosition, popper: popper, cy: cy };
return assign({}, defaults, opts);
}
//Get the rendered center
function getRenderedCenter(target, renderedDimensions) {
var pos = target.renderedPosition();
var dimensions = renderedDimensions(target);
var offsetX = dimensions.w / 2;
var offsetY = dimensions.h / 2;
return {
x: pos.x - offsetX,
y: pos.y - offsetY
};
}
//Get the rendered position of the midpoint
function getRenderedMidpoint(target) {
var p = target.midpoint();
var pan = target.cy().pan();
var zoom = target.cy().zoom();
return {
x: p.x * zoom + pan.x,
y: p.y * zoom + pan.y
};
}
//Warn user about misuse of the plugin
function checkForWarning(elements) {
/* eslint-disable no-console */
//Popper.js Should only be used on 1 element
if (elements.length > 1) {
console.warn("Popper.js Extension should only be used on one element.");
console.warn("Ignoring all subsequent elements");
}
/* eslint-enable */
}
module.exports = { popper: popper, popperRef: popperRef };
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var assign = __webpack_require__(1);
var _require = __webpack_require__(2),
getPopper = _require.getPopper;
var _require2 = __webpack_require__(0),
getRef = _require2.getRef;
function popper(opts) {
return getPopper(this, createOptionsObject(this, opts));
}
function popperRef(opts) {
return getRef(this, createOptionsObject(this, opts));
}
//Create a options object with required default values
function createOptionsObject(target, opts) {
var defaults = {
boundingBox: {
top: 0,
left: 0,
right: 0,
bottom: 0,
w: 3,
h: 3
},
renderedDimensions: function renderedDimensions() {
return { w: 3, h: 3 };
},
renderedPosition: function renderedPosition() {
return { x: 0, y: 0 };
},
popper: {},
cy: target
};
return assign({}, defaults, opts);
}
module.exports = { popper: popper, popperRef: popperRef };
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
function getBoundingBox(target, opts) {
var renderedPosition = opts.renderedPosition,
cy = opts.cy,
renderedDimensions = opts.renderedDimensions;
var offset = cy.container().getBoundingClientRect();
var dims = renderedDimensions(target);
var pos = renderedPosition(target);
return {
top: pos.y + offset.top,
left: pos.x + offset.left,
right: pos.x + dims.w + offset.left,
bottom: pos.y + dims.h + offset.top,
width: dims.w,
height: dims.h
};
}
module.exports = { getBoundingBox: getBoundingBox };
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
function getContent(target, content) {
var contentObject = null;
if (typeof content === "function") {
//Execute function if user opted for a dyanamic target
contentObject = content(target);
} else if (content instanceof HTMLElement) {
//Target option is an HTML element
return content;
} else {
throw new Error("Can not create popper from 'target' with unknown type");
}
// Check validity of parsed target
if (contentObject === null) {
throw new Error("No 'target' specified to create popper");
} else {
return contentObject;
}
}
module.exports = { getContent: getContent };
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var coreImpl = __webpack_require__(4);
var collectionImpl = __webpack_require__(3);
// registers the extension on a cytoscape lib ref
var registerFactory = function registerFactory(popperFactory) {
if (typeof popperFactory !== "function") {
throw new Error('Provide \'popperFactory\' before registering the module');
}
return function register(cytoscape) {
if (!cytoscape) {
return;
} // can't register if cytoscape unspecified
// register with cytoscape.js
cytoscape('core', 'popperFactory', popperFactory); // Cytoscape Core factory
cytoscape('collection', 'popperFactory', popperFactory); //Cytoscape Collections factory
cytoscape('core', 'popper', coreImpl.popper); //Cytoscape Core
cytoscape('collection', 'popper', collectionImpl.popper); //Cytoscape Collections
cytoscape('core', 'popperRef', coreImpl.popperRef); //Cytoscape Core for References
cytoscape('collection', 'popperRef', collectionImpl.popperRef); //Cytoscape Collections for References
};
};
module.exports = registerFactory;
/***/ })
/******/ ]);
});