vis-util 5.0.7 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/declarations/css-shim.d.ts +2 -0
  2. package/declarations/css-shim.d.ts.map +1 -0
  3. package/declarations/deep-object-assign.d.ts +0 -2
  4. package/declarations/deep-object-assign.d.ts.map +1 -1
  5. package/declarations/entry-esnext.d.ts +4 -4
  6. package/declarations/entry-esnext.d.ts.map +1 -1
  7. package/declarations/index.d.ts +2 -2
  8. package/declarations/index.d.ts.map +1 -1
  9. package/declarations/random/alea.d.ts +0 -2
  10. package/declarations/random/alea.d.ts.map +1 -1
  11. package/declarations/random/index.d.ts +1 -1
  12. package/declarations/random/index.d.ts.map +1 -1
  13. package/declarations/shared/configurator-types.d.ts +0 -1
  14. package/declarations/shared/configurator-types.d.ts.map +1 -1
  15. package/declarations/shared/index.d.ts +1 -2
  16. package/declarations/shared/index.d.ts.map +1 -1
  17. package/declarations/util.d.ts +5 -66
  18. package/declarations/util.d.ts.map +1 -1
  19. package/esnext/esm/vis-util.js +1634 -1761
  20. package/esnext/esm/vis-util.js.map +1 -1
  21. package/esnext/esm/vis-util.min.js +3 -3
  22. package/esnext/esm/vis-util.min.js.map +1 -1
  23. package/esnext/esm/vis-util.min.mjs +27 -0
  24. package/esnext/esm/vis-util.min.mjs.map +1 -0
  25. package/esnext/esm/vis-util.mjs +3925 -0
  26. package/esnext/esm/vis-util.mjs.map +1 -0
  27. package/esnext/umd/vis-util.cjs +3925 -0
  28. package/esnext/umd/vis-util.cjs.map +1 -0
  29. package/esnext/umd/vis-util.js +3611 -3802
  30. package/esnext/umd/vis-util.js.map +1 -1
  31. package/esnext/umd/vis-util.min.cjs +27 -0
  32. package/esnext/umd/vis-util.min.cjs.map +1 -0
  33. package/esnext/umd/vis-util.min.js +3 -3
  34. package/esnext/umd/vis-util.min.js.map +1 -1
  35. package/package.json +211 -79
  36. package/peer/esm/vis-util.js +8547 -6113
  37. package/peer/esm/vis-util.js.map +1 -1
  38. package/peer/esm/vis-util.min.js +4 -4
  39. package/peer/esm/vis-util.min.js.map +1 -1
  40. package/peer/esm/vis-util.min.mjs +34 -0
  41. package/peer/esm/vis-util.min.mjs.map +1 -0
  42. package/peer/esm/vis-util.mjs +13823 -0
  43. package/peer/esm/vis-util.mjs.map +1 -0
  44. package/peer/umd/vis-util.cjs +13890 -0
  45. package/peer/umd/vis-util.cjs.map +1 -0
  46. package/peer/umd/vis-util.js +8547 -6113
  47. package/peer/umd/vis-util.js.map +1 -1
  48. package/peer/umd/vis-util.min.cjs +34 -0
  49. package/peer/umd/vis-util.min.cjs.map +1 -0
  50. package/peer/umd/vis-util.min.js +4 -4
  51. package/peer/umd/vis-util.min.js.map +1 -1
  52. package/standalone/esm/vis-util.js +8547 -6113
  53. package/standalone/esm/vis-util.js.map +1 -1
  54. package/standalone/esm/vis-util.min.js +4 -4
  55. package/standalone/esm/vis-util.min.js.map +1 -1
  56. package/standalone/esm/vis-util.min.mjs +34 -0
  57. package/standalone/esm/vis-util.min.mjs.map +1 -0
  58. package/standalone/esm/vis-util.mjs +13823 -0
  59. package/standalone/esm/vis-util.mjs.map +1 -0
  60. package/standalone/umd/vis-util.cjs +13890 -0
  61. package/standalone/umd/vis-util.cjs.map +1 -0
  62. package/standalone/umd/vis-util.js +8547 -6113
  63. package/standalone/umd/vis-util.js.map +1 -1
  64. package/standalone/umd/vis-util.min.cjs +34 -0
  65. package/standalone/umd/vis-util.min.cjs.map +1 -0
  66. package/standalone/umd/vis-util.min.js +4 -4
  67. package/standalone/umd/vis-util.min.js.map +1 -1
@@ -0,0 +1,3925 @@
1
+ /**
2
+ * vis-util
3
+ * https://github.com/visjs/vis-util
4
+ *
5
+ * utilitie collection for visjs
6
+ *
7
+ * @version 6.0.1
8
+ * @date 2026-08-03T17:52:53.613Z
9
+ *
10
+ * @copyright (c) 2011-2017 Almende B.V, http://almende.com
11
+ * @copyright (c) 2017-2019 visjs contributors, https://github.com/visjs
12
+ *
13
+ * @license
14
+ * vis.js is dual licensed under both
15
+ *
16
+ * 1. The Apache 2.0 License
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * and
20
+ *
21
+ * 2. The MIT License
22
+ * http://opensource.org/licenses/MIT
23
+ *
24
+ * vis.js may be distributed under either license.
25
+ */
26
+
27
+ import Emitter from 'component-emitter';
28
+ import RealHammer from '@egjs/hammerjs';
29
+
30
+ /**
31
+ * Use this symbol to delete properies in deepObjectAssign.
32
+ */
33
+ const DELETE = Symbol("DELETE");
34
+ /**
35
+ * Pure version of deepObjectAssign, it doesn't modify any of it's arguments.
36
+ * @param base - The base object that fullfils the whole interface T.
37
+ * @param updates - Updates that may change or delete props.
38
+ * @returns A brand new instance with all the supplied objects deeply merged.
39
+ */
40
+ function pureDeepObjectAssign(base, ...updates) {
41
+ return deepObjectAssign({}, base, ...updates);
42
+ }
43
+ /**
44
+ * Deep version of object assign with additional deleting by the DELETE symbol.
45
+ * @param values - Objects to be deeply merged.
46
+ * @returns The first object from values.
47
+ */
48
+ function deepObjectAssign(...values) {
49
+ const merged = deepObjectAssignNonentry(...values);
50
+ stripDelete(merged);
51
+ return merged;
52
+ }
53
+ /**
54
+ * Deep version of object assign with additional deleting by the DELETE symbol.
55
+ * @remarks
56
+ * This doesn't strip the DELETE symbols so they may end up in the final object.
57
+ * @param values - Objects to be deeply merged.
58
+ * @returns The first object from values.
59
+ */
60
+ function deepObjectAssignNonentry(...values) {
61
+ if (values.length < 2) {
62
+ return values[0];
63
+ }
64
+ else if (values.length > 2) {
65
+ return deepObjectAssignNonentry(deepObjectAssign(values[0], values[1]), ...values.slice(2));
66
+ }
67
+ const a = values[0];
68
+ const b = values[1];
69
+ if (a instanceof Date && b instanceof Date) {
70
+ a.setTime(b.getTime());
71
+ return a;
72
+ }
73
+ for (const prop of Reflect.ownKeys(b)) {
74
+ if (!Object.prototype.propertyIsEnumerable.call(b, prop)) ;
75
+ else if (b[prop] === DELETE) {
76
+ delete a[prop];
77
+ }
78
+ else if (a[prop] !== null &&
79
+ b[prop] !== null &&
80
+ typeof a[prop] === "object" &&
81
+ typeof b[prop] === "object" &&
82
+ !Array.isArray(a[prop]) &&
83
+ !Array.isArray(b[prop])) {
84
+ a[prop] = deepObjectAssignNonentry(a[prop], b[prop]);
85
+ }
86
+ else {
87
+ a[prop] = clone(b[prop]);
88
+ }
89
+ }
90
+ return a;
91
+ }
92
+ /**
93
+ * Deep clone given object or array. In case of primitive simply return.
94
+ * @param a - Anything.
95
+ * @returns Deep cloned object/array or unchanged a.
96
+ */
97
+ function clone(a) {
98
+ if (Array.isArray(a)) {
99
+ return a.map((value) => clone(value));
100
+ }
101
+ else if (typeof a === "object" && a !== null) {
102
+ if (a instanceof Date) {
103
+ return new Date(a.getTime());
104
+ }
105
+ return deepObjectAssignNonentry({}, a);
106
+ }
107
+ else {
108
+ return a;
109
+ }
110
+ }
111
+ /**
112
+ * Strip DELETE from given object.
113
+ * @param a - Object which may contain DELETE but won't after this is executed.
114
+ */
115
+ function stripDelete(a) {
116
+ for (const prop of Object.keys(a)) {
117
+ if (a[prop] === DELETE) {
118
+ delete a[prop];
119
+ }
120
+ else if (typeof a[prop] === "object" && a[prop] !== null) {
121
+ stripDelete(a[prop]);
122
+ }
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Seedable, fast and reasonably good (not crypto but more than okay for our
128
+ * needs) random number generator.
129
+ * @remarks
130
+ * Adapted from {@link https://web.archive.org/web/20110429100736/http://baagoe.com:80/en/RandomMusings/javascript}.
131
+ * Original algorithm created by Johannes Baagøe \<baagoe\@baagoe.com\> in 2010.
132
+ */
133
+ /**
134
+ * Create a seeded pseudo random generator based on Alea by Johannes Baagøe.
135
+ * @param seed - All supplied arguments will be used as a seed. In case nothing
136
+ * is supplied the current time will be used to seed the generator.
137
+ * @returns A ready to use seeded generator.
138
+ */
139
+ function Alea(...seed) {
140
+ return AleaImplementation(seed.length ? seed : [Date.now()]);
141
+ }
142
+ /**
143
+ * An implementation of [[Alea]] without user input validation.
144
+ * @param seed - The data that will be used to seed the generator.
145
+ * @returns A ready to use seeded generator.
146
+ */
147
+ function AleaImplementation(seed) {
148
+ let [s0, s1, s2] = mashSeed(seed);
149
+ let c = 1;
150
+ const random = () => {
151
+ const t = 2091639 * s0 + c * 2.3283064365386963e-10; // 2^-32
152
+ s0 = s1;
153
+ s1 = s2;
154
+ return (s2 = t - (c = t | 0));
155
+ };
156
+ random.uint32 = () => random() * 0x100000000; // 2^32
157
+ random.fract53 = () => random() + ((random() * 0x200000) | 0) * 1.1102230246251565e-16; // 2^-53
158
+ random.algorithm = "Alea";
159
+ random.seed = seed;
160
+ random.version = "0.9";
161
+ return random;
162
+ }
163
+ /**
164
+ * Turn arbitrary data into values [[AleaImplementation]] can use to generate
165
+ * random numbers.
166
+ * @param seed - Arbitrary data that will be used as the seed.
167
+ * @returns Three numbers to use as initial values for [[AleaImplementation]].
168
+ */
169
+ function mashSeed(...seed) {
170
+ const mash = Mash();
171
+ let s0 = mash(" ");
172
+ let s1 = mash(" ");
173
+ let s2 = mash(" ");
174
+ for (let i = 0; i < seed.length; i++) {
175
+ s0 -= mash(seed[i]);
176
+ if (s0 < 0) {
177
+ s0 += 1;
178
+ }
179
+ s1 -= mash(seed[i]);
180
+ if (s1 < 0) {
181
+ s1 += 1;
182
+ }
183
+ s2 -= mash(seed[i]);
184
+ if (s2 < 0) {
185
+ s2 += 1;
186
+ }
187
+ }
188
+ return [s0, s1, s2];
189
+ }
190
+ /**
191
+ * Create a new mash function.
192
+ * @returns A nonpure function that takes arbitrary [[Mashable]] data and turns
193
+ * them into numbers.
194
+ */
195
+ function Mash() {
196
+ let n = 0xefc8249d;
197
+ return function (data) {
198
+ const string = data.toString();
199
+ for (let i = 0; i < string.length; i++) {
200
+ n += string.charCodeAt(i);
201
+ let h = 0.02519603282416938 * n;
202
+ n = h >>> 0;
203
+ h -= n;
204
+ h *= n;
205
+ n = h >>> 0;
206
+ h -= n;
207
+ n += h * 0x100000000; // 2^32
208
+ }
209
+ return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
210
+ };
211
+ }
212
+
213
+ /**
214
+ * Setup a mock hammer.js object, for unit testing.
215
+ *
216
+ * Inspiration: https://github.com/uber/deck.gl/pull/658
217
+ * @returns {{on: noop, off: noop, destroy: noop, emit: noop, get: get}}
218
+ */
219
+ function hammerMock() {
220
+ const noop = () => {};
221
+
222
+ return {
223
+ on: noop,
224
+ off: noop,
225
+ destroy: noop,
226
+ emit: noop,
227
+
228
+ get() {
229
+ return {
230
+ set: noop,
231
+ };
232
+ },
233
+ };
234
+ }
235
+
236
+ const Hammer$1 =
237
+ typeof window !== "undefined"
238
+ ? window.Hammer || RealHammer
239
+ : function () {
240
+ // hammer.js is only available in a browser, not in node.js. Replacing it with a mock object.
241
+ return hammerMock();
242
+ };
243
+
244
+ /**
245
+ * Turn an element into an clickToUse element.
246
+ * When not active, the element has a transparent overlay. When the overlay is
247
+ * clicked, the mode is changed to active.
248
+ * When active, the element is displayed with a blue border around it, and
249
+ * the interactive contents of the element can be used. When clicked outside
250
+ * the element, the elements mode is changed to inactive.
251
+ * @param {Element} container
252
+ * @class Activator
253
+ */
254
+ function Activator$1(container) {
255
+ this._cleanupQueue = [];
256
+
257
+ this.active = false;
258
+
259
+ this._dom = {
260
+ container,
261
+ overlay: document.createElement("div"),
262
+ };
263
+
264
+ this._dom.overlay.classList.add("vis-overlay");
265
+
266
+ this._dom.container.appendChild(this._dom.overlay);
267
+ this._cleanupQueue.push(() => {
268
+ this._dom.overlay.parentNode.removeChild(this._dom.overlay);
269
+ });
270
+
271
+ const hammer = Hammer$1(this._dom.overlay);
272
+ hammer.on("tap", this._onTapOverlay.bind(this));
273
+ this._cleanupQueue.push(() => {
274
+ hammer.destroy();
275
+ // FIXME: cleaning up hammer instances doesn't work (Timeline not removed
276
+ // from memory)
277
+ });
278
+
279
+ // block all touch events (except tap)
280
+ const events = [
281
+ "tap",
282
+ "doubletap",
283
+ "press",
284
+ "pinch",
285
+ "pan",
286
+ "panstart",
287
+ "panmove",
288
+ "panend",
289
+ ];
290
+ events.forEach((event) => {
291
+ hammer.on(event, (event) => {
292
+ event.srcEvent.stopPropagation();
293
+ });
294
+ });
295
+
296
+ // attach a click event to the window, in order to deactivate when clicking outside the timeline
297
+ if (document && document.body) {
298
+ this._onClick = (event) => {
299
+ if (!_hasParent(event.target, container)) {
300
+ this.deactivate();
301
+ }
302
+ };
303
+ document.body.addEventListener("click", this._onClick);
304
+ this._cleanupQueue.push(() => {
305
+ document.body.removeEventListener("click", this._onClick);
306
+ });
307
+ }
308
+
309
+ // prepare escape key listener for deactivating when active
310
+ this._escListener = (event) => {
311
+ if (
312
+ "key" in event
313
+ ? event.key === "Escape"
314
+ : event.keyCode === 27 /* the keyCode is for IE11 */
315
+ ) {
316
+ this.deactivate();
317
+ }
318
+ };
319
+ }
320
+
321
+ // turn into an event emitter
322
+ Emitter(Activator$1.prototype);
323
+
324
+ // The currently active activator
325
+ Activator$1.current = null;
326
+
327
+ /**
328
+ * Destroy the activator. Cleans up all created DOM and event listeners
329
+ */
330
+ Activator$1.prototype.destroy = function () {
331
+ this.deactivate();
332
+
333
+ for (const callback of this._cleanupQueue.splice(0).toReversed()) {
334
+ callback();
335
+ }
336
+ };
337
+
338
+ /**
339
+ * Activate the element
340
+ * Overlay is hidden, element is decorated with a blue shadow border
341
+ */
342
+ Activator$1.prototype.activate = function () {
343
+ // we allow only one active activator at a time
344
+ if (Activator$1.current) {
345
+ Activator$1.current.deactivate();
346
+ }
347
+ Activator$1.current = this;
348
+
349
+ this.active = true;
350
+ this._dom.overlay.style.display = "none";
351
+ this._dom.container.classList.add("vis-active");
352
+
353
+ this.emit("change");
354
+ this.emit("activate");
355
+
356
+ // ugly hack: bind ESC after emitting the events, as the Network rebinds all
357
+ // keyboard events on a 'change' event
358
+ document.body.addEventListener("keydown", this._escListener);
359
+ };
360
+
361
+ /**
362
+ * Deactivate the element
363
+ * Overlay is displayed on top of the element
364
+ */
365
+ Activator$1.prototype.deactivate = function () {
366
+ this.active = false;
367
+ this._dom.overlay.style.display = "block";
368
+ this._dom.container.classList.remove("vis-active");
369
+ document.body.removeEventListener("keydown", this._escListener);
370
+
371
+ this.emit("change");
372
+ this.emit("deactivate");
373
+ };
374
+
375
+ /**
376
+ * Handle a tap event: activate the container
377
+ * @param {Event} event The event
378
+ * @private
379
+ */
380
+ Activator$1.prototype._onTapOverlay = function (event) {
381
+ // activate the container
382
+ this.activate();
383
+ event.srcEvent.stopPropagation();
384
+ };
385
+
386
+ /**
387
+ * Test whether the element has the requested parent element somewhere in
388
+ * its chain of parent nodes.
389
+ * @param {HTMLElement} element
390
+ * @param {HTMLElement} parent
391
+ * @returns {boolean} Returns true when the parent is found somewhere in the
392
+ * chain of parent nodes.
393
+ * @private
394
+ */
395
+ function _hasParent(element, parent) {
396
+ while (element) {
397
+ if (element === parent) {
398
+ return true;
399
+ }
400
+ element = element.parentNode;
401
+ }
402
+ return false;
403
+ }
404
+
405
+ // utility functions
406
+ // parse ASP.Net Date pattern,
407
+ // for example '/Date(1198908717056)/' or '/Date(1198908717056-0700)/'
408
+ // code from http://momentjs.com/
409
+ const ASPDateRegex = /^\/?Date\((-?\d+)/i;
410
+ // Color REs
411
+ const fullHexRE = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
412
+ const shortHexRE = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
413
+ const rgbRE = /^rgb\( *(1?\d{1,2}|2[0-4]\d|25[0-5]) *, *(1?\d{1,2}|2[0-4]\d|25[0-5]) *, *(1?\d{1,2}|2[0-4]\d|25[0-5]) *\)$/i;
414
+ const rgbaRE = /^rgba\( *(1?\d{1,2}|2[0-4]\d|25[0-5]) *, *(1?\d{1,2}|2[0-4]\d|25[0-5]) *, *(1?\d{1,2}|2[0-4]\d|25[0-5]) *, *([01]|0?\.\d+) *\)$/i;
415
+ /**
416
+ * Test whether given object is a number.
417
+ * @param value - Input value of unknown type.
418
+ * @returns True if number, false otherwise.
419
+ */
420
+ function isNumber(value) {
421
+ return value instanceof Number || typeof value === "number";
422
+ }
423
+ /**
424
+ * Remove everything in the DOM object.
425
+ * @param DOMobject - Node whose child nodes will be recursively deleted.
426
+ */
427
+ function recursiveDOMDelete(DOMobject) {
428
+ if (DOMobject) {
429
+ while (DOMobject.hasChildNodes() === true) {
430
+ const child = DOMobject.firstChild;
431
+ if (child) {
432
+ recursiveDOMDelete(child);
433
+ DOMobject.removeChild(child);
434
+ }
435
+ }
436
+ }
437
+ }
438
+ /**
439
+ * Test whether given object is a string.
440
+ * @param value - Input value of unknown type.
441
+ * @returns True if string, false otherwise.
442
+ */
443
+ function isString(value) {
444
+ return value instanceof String || typeof value === "string";
445
+ }
446
+ /**
447
+ * Test whether given object is a object (not primitive or null).
448
+ * @param value - Input value of unknown type.
449
+ * @returns True if not null object, false otherwise.
450
+ */
451
+ function isObject(value) {
452
+ return typeof value === "object" && value !== null;
453
+ }
454
+ /**
455
+ * Test whether given object is a Date, or a String containing a Date.
456
+ * @param value - Input value of unknown type.
457
+ * @returns True if Date instance or string date representation, false otherwise.
458
+ */
459
+ function isDate(value) {
460
+ if (value instanceof Date) {
461
+ return true;
462
+ }
463
+ else if (isString(value)) {
464
+ // test whether this string contains a date
465
+ const match = ASPDateRegex.exec(value);
466
+ if (match) {
467
+ return true;
468
+ }
469
+ else if (!isNaN(Date.parse(value))) {
470
+ return true;
471
+ }
472
+ }
473
+ return false;
474
+ }
475
+ /**
476
+ * Copy property from b to a if property present in a.
477
+ * If property in b explicitly set to null, delete it if `allowDeletion` set.
478
+ *
479
+ * Internal helper routine, should not be exported. Not added to `exports` for that reason.
480
+ * @param a - Target object.
481
+ * @param b - Source object.
482
+ * @param prop - Name of property to copy from b to a.
483
+ * @param allowDeletion - If true, delete property in a if explicitly set to null in b.
484
+ */
485
+ function copyOrDelete(a, b, prop, allowDeletion) {
486
+ let doDeletion = false;
487
+ if (allowDeletion === true) {
488
+ doDeletion = b[prop] === null && a[prop] !== undefined;
489
+ }
490
+ if (doDeletion) {
491
+ delete a[prop];
492
+ }
493
+ else {
494
+ a[prop] = b[prop]; // Remember, this is a reference copy!
495
+ }
496
+ }
497
+ /**
498
+ * Fill an object with a possibly partially defined other object.
499
+ *
500
+ * Only copies values for the properties already present in a.
501
+ * That means an object is not created on a property if only the b object has it.
502
+ * @param a - The object that will have it's properties updated.
503
+ * @param b - The object with property updates.
504
+ * @param allowDeletion - If true, delete properties in a that are explicitly set to null in b.
505
+ */
506
+ function fillIfDefined(a, b, allowDeletion = false) {
507
+ // NOTE: iteration of properties of a
508
+ // NOTE: prototype properties iterated over as well
509
+ for (const prop in a) {
510
+ if (b[prop] !== undefined) {
511
+ if (b[prop] === null || typeof b[prop] !== "object") {
512
+ // Note: typeof null === 'object'
513
+ copyOrDelete(a, b, prop, allowDeletion);
514
+ }
515
+ else {
516
+ const aProp = a[prop];
517
+ const bProp = b[prop];
518
+ if (isObject(aProp) && isObject(bProp)) {
519
+ fillIfDefined(aProp, bProp, allowDeletion);
520
+ }
521
+ }
522
+ }
523
+ }
524
+ }
525
+ /**
526
+ * Copy the values of all of the enumerable own properties from one or more source objects to a
527
+ * target object. Returns the target object.
528
+ * @param target - The target object to copy to.
529
+ * @param source - The source object from which to copy properties.
530
+ * @returns The target object.
531
+ */
532
+ const extend = Object.assign;
533
+ /**
534
+ * Extend object a with selected properties of object b or a series of objects.
535
+ * @remarks
536
+ * Only properties with defined values are copied.
537
+ * @param props - Properties to be copied to a.
538
+ * @param a - The target.
539
+ * @param others - The sources.
540
+ * @returns Argument a.
541
+ */
542
+ function selectiveExtend(props, a, ...others) {
543
+ if (!Array.isArray(props)) {
544
+ throw new Error("Array with property names expected as first argument");
545
+ }
546
+ for (const other of others) {
547
+ for (let p = 0; p < props.length; p++) {
548
+ const prop = props[p];
549
+ if (other && Object.prototype.hasOwnProperty.call(other, prop)) {
550
+ a[prop] = other[prop];
551
+ }
552
+ }
553
+ }
554
+ return a;
555
+ }
556
+ /**
557
+ * Extend object a with selected properties of object b.
558
+ * Only properties with defined values are copied.
559
+ * @remarks
560
+ * Previous version of this routine implied that multiple source objects could
561
+ * be used; however, the implementation was **wrong**. Since multiple (\>1)
562
+ * sources weren't used anywhere in the `vis.js` code, this has been removed
563
+ * @param props - Names of first-level properties to copy over.
564
+ * @param a - Target object.
565
+ * @param b - Source object.
566
+ * @param allowDeletion - If true, delete property in a if explicitly set to null in b.
567
+ * @returns Argument a.
568
+ */
569
+ function selectiveDeepExtend(props, a, b, allowDeletion = false) {
570
+ // TODO: add support for Arrays to deepExtend
571
+ if (Array.isArray(b)) {
572
+ throw new TypeError("Arrays are not supported by deepExtend");
573
+ }
574
+ for (let p = 0; p < props.length; p++) {
575
+ const prop = props[p];
576
+ if (Object.prototype.hasOwnProperty.call(b, prop)) {
577
+ if (b[prop] && b[prop].constructor === Object) {
578
+ if (a[prop] === undefined) {
579
+ a[prop] = {};
580
+ }
581
+ if (a[prop].constructor === Object) {
582
+ deepExtend(a[prop], b[prop], false, allowDeletion);
583
+ }
584
+ else {
585
+ copyOrDelete(a, b, prop, allowDeletion);
586
+ }
587
+ }
588
+ else if (Array.isArray(b[prop])) {
589
+ throw new TypeError("Arrays are not supported by deepExtend");
590
+ }
591
+ else {
592
+ copyOrDelete(a, b, prop, allowDeletion);
593
+ }
594
+ }
595
+ }
596
+ return a;
597
+ }
598
+ /**
599
+ * Extend object `a` with properties of object `b`, ignoring properties which
600
+ * are explicitly specified to be excluded.
601
+ * @remarks
602
+ * The properties of `b` are considered for copying. Properties which are
603
+ * themselves objects are are also extended. Only properties with defined
604
+ * values are copied.
605
+ * @param propsToExclude - Names of properties which should *not* be copied.
606
+ * @param a - Object to extend.
607
+ * @param b - Object to take properties from for extension.
608
+ * @param allowDeletion - If true, delete properties in a that are explicitly
609
+ * set to null in b.
610
+ * @returns Argument a.
611
+ */
612
+ function selectiveNotDeepExtend(propsToExclude, a, b, allowDeletion = false) {
613
+ // TODO: add support for Arrays to deepExtend
614
+ // NOTE: array properties have an else-below; apparently, there is a problem here.
615
+ if (Array.isArray(b)) {
616
+ throw new TypeError("Arrays are not supported by deepExtend");
617
+ }
618
+ for (const prop in b) {
619
+ if (!Object.prototype.hasOwnProperty.call(b, prop)) {
620
+ continue;
621
+ } // Handle local properties only
622
+ if (propsToExclude.includes(prop)) {
623
+ continue;
624
+ } // In exclusion list, skip
625
+ if (b[prop] && b[prop].constructor === Object) {
626
+ if (a[prop] === undefined) {
627
+ a[prop] = {};
628
+ }
629
+ if (a[prop].constructor === Object) {
630
+ deepExtend(a[prop], b[prop]); // NOTE: allowDeletion not propagated!
631
+ }
632
+ else {
633
+ copyOrDelete(a, b, prop, allowDeletion);
634
+ }
635
+ }
636
+ else if (Array.isArray(b[prop])) {
637
+ a[prop] = [];
638
+ for (let i = 0; i < b[prop].length; i++) {
639
+ a[prop].push(b[prop][i]);
640
+ }
641
+ }
642
+ else {
643
+ copyOrDelete(a, b, prop, allowDeletion);
644
+ }
645
+ }
646
+ return a;
647
+ }
648
+ /**
649
+ * Deep extend an object a with the properties of object b.
650
+ * @param a - Target object.
651
+ * @param b - Source object.
652
+ * @param protoExtend - If true, the prototype values will also be extended.
653
+ * (That is the options objects that inherit from others will also get the
654
+ * inherited options).
655
+ * @param allowDeletion - If true, the values of fields that are null will be deleted.
656
+ * @returns Argument a.
657
+ */
658
+ function deepExtend(a, b, protoExtend = false, allowDeletion = false) {
659
+ for (const prop in b) {
660
+ if (Object.prototype.hasOwnProperty.call(b, prop) || protoExtend === true) {
661
+ if (typeof b[prop] === "object" &&
662
+ b[prop] !== null &&
663
+ Object.getPrototypeOf(b[prop]) === Object.prototype) {
664
+ if (a[prop] === undefined) {
665
+ a[prop] = deepExtend({}, b[prop], protoExtend); // NOTE: allowDeletion not propagated!
666
+ }
667
+ else if (typeof a[prop] === "object" &&
668
+ a[prop] !== null &&
669
+ Object.getPrototypeOf(a[prop]) === Object.prototype) {
670
+ deepExtend(a[prop], b[prop], protoExtend); // NOTE: allowDeletion not propagated!
671
+ }
672
+ else {
673
+ copyOrDelete(a, b, prop, allowDeletion);
674
+ }
675
+ }
676
+ else if (Array.isArray(b[prop])) {
677
+ a[prop] = b[prop].slice();
678
+ }
679
+ else {
680
+ copyOrDelete(a, b, prop, allowDeletion);
681
+ }
682
+ }
683
+ }
684
+ return a;
685
+ }
686
+ /**
687
+ * Test whether all elements in two arrays are equal.
688
+ * @param a - First array.
689
+ * @param b - Second array.
690
+ * @returns True if both arrays have the same length and same elements (1 = '1').
691
+ */
692
+ function equalArray(a, b) {
693
+ if (a.length !== b.length) {
694
+ return false;
695
+ }
696
+ for (let i = 0, len = a.length; i < len; i++) {
697
+ if (a[i] != b[i]) {
698
+ return false;
699
+ }
700
+ }
701
+ return true;
702
+ }
703
+ /**
704
+ * Get the type of an object, for example exports.getType([]) returns 'Array'.
705
+ * @param object - Input value of unknown type.
706
+ * @returns Detected type.
707
+ */
708
+ function getType(object) {
709
+ const type = typeof object;
710
+ if (type === "object") {
711
+ if (object === null) {
712
+ return "null";
713
+ }
714
+ if (object instanceof Boolean) {
715
+ return "Boolean";
716
+ }
717
+ if (object instanceof Number) {
718
+ return "Number";
719
+ }
720
+ if (object instanceof String) {
721
+ return "String";
722
+ }
723
+ if (Array.isArray(object)) {
724
+ return "Array";
725
+ }
726
+ if (object instanceof Date) {
727
+ return "Date";
728
+ }
729
+ return "Object";
730
+ }
731
+ if (type === "number") {
732
+ return "Number";
733
+ }
734
+ if (type === "boolean") {
735
+ return "Boolean";
736
+ }
737
+ if (type === "string") {
738
+ return "String";
739
+ }
740
+ if (type === undefined) {
741
+ return "undefined";
742
+ }
743
+ return type;
744
+ }
745
+ /**
746
+ * Used to extend an array and copy it. This is used to propagate paths recursively.
747
+ * @param arr - First part.
748
+ * @param newValue - The value to be aadded into the array.
749
+ * @returns A new array with all items from arr and newValue (which is last).
750
+ */
751
+ function copyAndExtendArray(arr, newValue) {
752
+ return [...arr, newValue];
753
+ }
754
+ /**
755
+ * Used to extend an array and copy it. This is used to propagate paths recursively.
756
+ * @param arr - The array to be copied.
757
+ * @returns Shallow copy of arr.
758
+ */
759
+ function copyArray(arr) {
760
+ return arr.slice();
761
+ }
762
+ /**
763
+ * Retrieve the absolute left value of a DOM element.
764
+ * @param elem - A dom element, for example a div.
765
+ * @returns The absolute left position of this element in the browser page.
766
+ */
767
+ function getAbsoluteLeft(elem) {
768
+ return elem.getBoundingClientRect().left;
769
+ }
770
+ /**
771
+ * Retrieve the absolute right value of a DOM element.
772
+ * @param elem - A dom element, for example a div.
773
+ * @returns The absolute right position of this element in the browser page.
774
+ */
775
+ function getAbsoluteRight(elem) {
776
+ return elem.getBoundingClientRect().right;
777
+ }
778
+ /**
779
+ * Retrieve the absolute top value of a DOM element.
780
+ * @param elem - A dom element, for example a div.
781
+ * @returns The absolute top position of this element in the browser page.
782
+ */
783
+ function getAbsoluteTop(elem) {
784
+ return elem.getBoundingClientRect().top;
785
+ }
786
+ /**
787
+ * Add a className to the given elements style.
788
+ * @param elem - The element to which the classes will be added.
789
+ * @param classNames - Space separated list of classes.
790
+ */
791
+ function addClassName(elem, classNames) {
792
+ let classes = elem.className.split(" ");
793
+ const newClasses = classNames.split(" ");
794
+ classes = classes.concat(newClasses.filter(function (className) {
795
+ return !classes.includes(className);
796
+ }));
797
+ elem.className = classes.join(" ");
798
+ }
799
+ /**
800
+ * Remove a className from the given elements style.
801
+ * @param elem - The element from which the classes will be removed.
802
+ * @param classNames - Space separated list of classes.
803
+ */
804
+ function removeClassName(elem, classNames) {
805
+ let classes = elem.className.split(" ");
806
+ const oldClasses = classNames.split(" ");
807
+ classes = classes.filter(function (className) {
808
+ return !oldClasses.includes(className);
809
+ });
810
+ elem.className = classes.join(" ");
811
+ }
812
+ /**
813
+ * For each method for both arrays and objects.
814
+ * In case of an array, the built-in Array.forEach() is applied (**No, it's not!**).
815
+ * In case of an Object, the method loops over all properties of the object.
816
+ * @param object - An Object or Array to be iterated over.
817
+ * @param callback - Array.forEach-like callback.
818
+ */
819
+ function forEach(object, callback) {
820
+ if (Array.isArray(object)) {
821
+ // array
822
+ const len = object.length;
823
+ for (let i = 0; i < len; i++) {
824
+ callback(object[i], i, object);
825
+ }
826
+ }
827
+ else {
828
+ // object
829
+ for (const key in object) {
830
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
831
+ callback(object[key], key, object);
832
+ }
833
+ }
834
+ }
835
+ }
836
+ /**
837
+ * Convert an object into an array: all objects properties are put into the array. The resulting array is unordered.
838
+ * @param o - Object that contains the properties and methods.
839
+ * @returns An array of unordered values.
840
+ */
841
+ const toArray = Object.values;
842
+ /**
843
+ * Update a property in an object.
844
+ * @param object - The object whose property will be updated.
845
+ * @param key - Name of the property to be updated.
846
+ * @param value - The new value to be assigned.
847
+ * @returns Whether the value was updated (true) or already strictly the same in the original object (false).
848
+ */
849
+ function updateProperty(object, key, value) {
850
+ if (object[key] !== value) {
851
+ object[key] = value;
852
+ return true;
853
+ }
854
+ else {
855
+ return false;
856
+ }
857
+ }
858
+ /**
859
+ * Throttle the given function to be only executed once per animation frame.
860
+ * @param fn - The original function.
861
+ * @returns The throttled function.
862
+ */
863
+ function throttle(fn) {
864
+ let scheduled = false;
865
+ return () => {
866
+ if (!scheduled) {
867
+ scheduled = true;
868
+ requestAnimationFrame(() => {
869
+ scheduled = false;
870
+ fn();
871
+ });
872
+ }
873
+ };
874
+ }
875
+ /**
876
+ * Cancels the event's default action if it is cancelable, without stopping further propagation of the event.
877
+ * @param event - The event whose default action should be prevented.
878
+ */
879
+ function preventDefault(event) {
880
+ if (!event) {
881
+ event = window.event;
882
+ }
883
+ if (!event) ;
884
+ else if (event.preventDefault) {
885
+ event.preventDefault(); // non-IE browsers
886
+ }
887
+ else {
888
+ // @TODO: IE types? Does anyone care?
889
+ event.returnValue = false; // IE browsers
890
+ }
891
+ }
892
+ /**
893
+ * Get HTML element which is the target of the event.
894
+ * @param event - The event.
895
+ * @returns The element or null if not obtainable.
896
+ */
897
+ function getTarget(event = window.event) {
898
+ // code from http://www.quirksmode.org/js/events_properties.html
899
+ // @TODO: EventTarget can be almost anything, is it okay to return only Elements?
900
+ let target = null;
901
+ if (!event) ;
902
+ else if (event.target) {
903
+ target = event.target;
904
+ }
905
+ else if (event.srcElement) {
906
+ target = event.srcElement;
907
+ }
908
+ if (!(target instanceof Element)) {
909
+ return null;
910
+ }
911
+ if (target.nodeType != null && target.nodeType == 3) {
912
+ // defeat Safari bug
913
+ target = target.parentNode;
914
+ if (!(target instanceof Element)) {
915
+ return null;
916
+ }
917
+ }
918
+ return target;
919
+ }
920
+ /**
921
+ * Check if given element contains given parent somewhere in the DOM tree.
922
+ * @param element - The element to be tested.
923
+ * @param parent - The ancestor (not necessarily parent) of the element.
924
+ * @returns True if parent is an ancestor of the element, false otherwise.
925
+ */
926
+ function hasParent(element, parent) {
927
+ let elem = element;
928
+ while (elem) {
929
+ if (elem === parent) {
930
+ return true;
931
+ }
932
+ else if (elem.parentNode) {
933
+ elem = elem.parentNode;
934
+ }
935
+ else {
936
+ return false;
937
+ }
938
+ }
939
+ return false;
940
+ }
941
+ const option = {
942
+ /**
943
+ * Convert a value into a boolean.
944
+ * @param value - Value to be converted intoboolean, a function will be executed as `(() => unknown)`.
945
+ * @param defaultValue - If the value or the return value of the function == null then this will be returned.
946
+ * @returns Corresponding boolean value, if none then the default value, if none then null.
947
+ */
948
+ asBoolean(value, defaultValue) {
949
+ if (typeof value == "function") {
950
+ value = value();
951
+ }
952
+ if (value != null) {
953
+ return value != false;
954
+ }
955
+ return defaultValue || null;
956
+ },
957
+ /**
958
+ * Convert a value into a number.
959
+ * @param value - Value to be converted intonumber, a function will be executed as `(() => unknown)`.
960
+ * @param defaultValue - If the value or the return value of the function == null then this will be returned.
961
+ * @returns Corresponding **boxed** number value, if none then the default value, if none then null.
962
+ */
963
+ asNumber(value, defaultValue) {
964
+ if (typeof value == "function") {
965
+ value = value();
966
+ }
967
+ if (value != null) {
968
+ return Number(value) || defaultValue || null;
969
+ }
970
+ return defaultValue || null;
971
+ },
972
+ /**
973
+ * Convert a value into a string.
974
+ * @param value - Value to be converted intostring, a function will be executed as `(() => unknown)`.
975
+ * @param defaultValue - If the value or the return value of the function == null then this will be returned.
976
+ * @returns Corresponding **boxed** string value, if none then the default value, if none then null.
977
+ */
978
+ asString(value, defaultValue) {
979
+ if (typeof value == "function") {
980
+ value = value();
981
+ }
982
+ if (value != null) {
983
+ return String(value);
984
+ }
985
+ return defaultValue || null;
986
+ },
987
+ /**
988
+ * Convert a value into a size.
989
+ * @param value - Value to be converted intosize, a function will be executed as `(() => unknown)`.
990
+ * @param defaultValue - If the value or the return value of the function == null then this will be returned.
991
+ * @returns Corresponding string value (number + 'px'), if none then the default value, if none then null.
992
+ */
993
+ asSize(value, defaultValue) {
994
+ if (typeof value == "function") {
995
+ value = value();
996
+ }
997
+ if (isString(value)) {
998
+ return value;
999
+ }
1000
+ else if (isNumber(value)) {
1001
+ return value + "px";
1002
+ }
1003
+ else {
1004
+ return defaultValue || null;
1005
+ }
1006
+ },
1007
+ /**
1008
+ * Convert a value into a DOM Element.
1009
+ * @param value - Value to be converted into DOM Element, a function will be executed as `(() => unknown)`.
1010
+ * @param defaultValue - If the value or the return value of the function == null then this will be returned.
1011
+ * @returns The DOM Element, if none then the default value, if none then null.
1012
+ */
1013
+ asElement(value, defaultValue) {
1014
+ if (typeof value == "function") {
1015
+ value = value();
1016
+ }
1017
+ return value || defaultValue || null;
1018
+ },
1019
+ };
1020
+ /**
1021
+ * Convert hex color string into RGB color object.
1022
+ * @remarks
1023
+ * {@link http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb}
1024
+ * @param hex - Hex color string (3 or 6 digits, with or without #).
1025
+ * @returns RGB color object.
1026
+ */
1027
+ function hexToRGB(hex) {
1028
+ let result;
1029
+ switch (hex.length) {
1030
+ case 3:
1031
+ case 4:
1032
+ result = shortHexRE.exec(hex);
1033
+ return result
1034
+ ? {
1035
+ r: parseInt(result[1] + result[1], 16),
1036
+ g: parseInt(result[2] + result[2], 16),
1037
+ b: parseInt(result[3] + result[3], 16),
1038
+ }
1039
+ : null;
1040
+ case 6:
1041
+ case 7:
1042
+ result = fullHexRE.exec(hex);
1043
+ return result
1044
+ ? {
1045
+ r: parseInt(result[1], 16),
1046
+ g: parseInt(result[2], 16),
1047
+ b: parseInt(result[3], 16),
1048
+ }
1049
+ : null;
1050
+ default:
1051
+ return null;
1052
+ }
1053
+ }
1054
+ /**
1055
+ * This function takes string color in hex or RGB format and adds the opacity, RGBA is passed through unchanged.
1056
+ * @param color - The color string (hex, RGB, RGBA).
1057
+ * @param opacity - The new opacity.
1058
+ * @returns RGBA string, for example 'rgba(255, 0, 127, 0.3)'.
1059
+ */
1060
+ function overrideOpacity(color, opacity) {
1061
+ if (color.includes("rgba")) {
1062
+ return color;
1063
+ }
1064
+ else if (color.includes("rgb")) {
1065
+ const rgb = color
1066
+ .substr(color.indexOf("(") + 1)
1067
+ .replace(")", "")
1068
+ .split(",");
1069
+ return "rgba(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "," + opacity + ")";
1070
+ }
1071
+ else {
1072
+ const rgb = hexToRGB(color);
1073
+ if (rgb == null) {
1074
+ return color;
1075
+ }
1076
+ else {
1077
+ return "rgba(" + rgb.r + "," + rgb.g + "," + rgb.b + "," + opacity + ")";
1078
+ }
1079
+ }
1080
+ }
1081
+ /**
1082
+ * Convert RGB \<0, 255\> into hex color string.
1083
+ * @param red - Red channel.
1084
+ * @param green - Green channel.
1085
+ * @param blue - Blue channel.
1086
+ * @returns Hex color string (for example: '#0acdc0').
1087
+ */
1088
+ function RGBToHex(red, green, blue) {
1089
+ return ("#" + ((1 << 24) + (red << 16) + (green << 8) + blue).toString(16).slice(1));
1090
+ }
1091
+ /**
1092
+ * Parse a color property into an object with border, background, and highlight colors.
1093
+ * @param inputColor - Shorthand color string or input color object.
1094
+ * @param defaultColor - Full color object to fill in missing values in inputColor.
1095
+ * @returns Color object.
1096
+ */
1097
+ function parseColor(inputColor, defaultColor) {
1098
+ if (isString(inputColor)) {
1099
+ let colorStr = inputColor;
1100
+ if (isValidRGB(colorStr)) {
1101
+ const rgb = colorStr
1102
+ .substr(4)
1103
+ .substr(0, colorStr.length - 5)
1104
+ .split(",")
1105
+ .map(function (value) {
1106
+ return parseInt(value);
1107
+ });
1108
+ colorStr = RGBToHex(rgb[0], rgb[1], rgb[2]);
1109
+ }
1110
+ if (isValidHex(colorStr) === true) {
1111
+ const hsv = hexToHSV(colorStr);
1112
+ const lighterColorHSV = {
1113
+ h: hsv.h,
1114
+ s: hsv.s * 0.8,
1115
+ v: Math.min(1, hsv.v * 1.02),
1116
+ };
1117
+ const darkerColorHSV = {
1118
+ h: hsv.h,
1119
+ s: Math.min(1, hsv.s * 1.25),
1120
+ v: hsv.v * 0.8,
1121
+ };
1122
+ const darkerColorHex = HSVToHex(darkerColorHSV.h, darkerColorHSV.s, darkerColorHSV.v);
1123
+ const lighterColorHex = HSVToHex(lighterColorHSV.h, lighterColorHSV.s, lighterColorHSV.v);
1124
+ return {
1125
+ background: colorStr,
1126
+ border: darkerColorHex,
1127
+ highlight: {
1128
+ background: lighterColorHex,
1129
+ border: darkerColorHex,
1130
+ },
1131
+ hover: {
1132
+ background: lighterColorHex,
1133
+ border: darkerColorHex,
1134
+ },
1135
+ };
1136
+ }
1137
+ else {
1138
+ return {
1139
+ background: colorStr,
1140
+ border: colorStr,
1141
+ highlight: {
1142
+ background: colorStr,
1143
+ border: colorStr,
1144
+ },
1145
+ hover: {
1146
+ background: colorStr,
1147
+ border: colorStr,
1148
+ },
1149
+ };
1150
+ }
1151
+ }
1152
+ else {
1153
+ if (defaultColor) {
1154
+ const color = {
1155
+ background: inputColor.background || defaultColor.background,
1156
+ border: inputColor.border || defaultColor.border,
1157
+ highlight: isString(inputColor.highlight)
1158
+ ? {
1159
+ border: inputColor.highlight,
1160
+ background: inputColor.highlight,
1161
+ }
1162
+ : {
1163
+ background: (inputColor.highlight && inputColor.highlight.background) ||
1164
+ defaultColor.highlight.background,
1165
+ border: (inputColor.highlight && inputColor.highlight.border) ||
1166
+ defaultColor.highlight.border,
1167
+ },
1168
+ hover: isString(inputColor.hover)
1169
+ ? {
1170
+ border: inputColor.hover,
1171
+ background: inputColor.hover,
1172
+ }
1173
+ : {
1174
+ border: (inputColor.hover && inputColor.hover.border) ||
1175
+ defaultColor.hover.border,
1176
+ background: (inputColor.hover && inputColor.hover.background) ||
1177
+ defaultColor.hover.background,
1178
+ },
1179
+ };
1180
+ return color;
1181
+ }
1182
+ else {
1183
+ const color = {
1184
+ background: inputColor.background || undefined,
1185
+ border: inputColor.border || undefined,
1186
+ highlight: isString(inputColor.highlight)
1187
+ ? {
1188
+ border: inputColor.highlight,
1189
+ background: inputColor.highlight,
1190
+ }
1191
+ : {
1192
+ background: (inputColor.highlight && inputColor.highlight.background) ||
1193
+ undefined,
1194
+ border: (inputColor.highlight && inputColor.highlight.border) ||
1195
+ undefined,
1196
+ },
1197
+ hover: isString(inputColor.hover)
1198
+ ? {
1199
+ border: inputColor.hover,
1200
+ background: inputColor.hover,
1201
+ }
1202
+ : {
1203
+ border: (inputColor.hover && inputColor.hover.border) || undefined,
1204
+ background: (inputColor.hover && inputColor.hover.background) || undefined,
1205
+ },
1206
+ };
1207
+ return color;
1208
+ }
1209
+ }
1210
+ }
1211
+ /**
1212
+ * Convert RGB \<0, 255\> into HSV object.
1213
+ * @remarks
1214
+ * {@link http://www.javascripter.net/faq/rgb2hsv.htm}
1215
+ * @param red - Red channel.
1216
+ * @param green - Green channel.
1217
+ * @param blue - Blue channel.
1218
+ * @returns HSV color object.
1219
+ */
1220
+ function RGBToHSV(red, green, blue) {
1221
+ red = red / 255;
1222
+ green = green / 255;
1223
+ blue = blue / 255;
1224
+ const minRGB = Math.min(red, Math.min(green, blue));
1225
+ const maxRGB = Math.max(red, Math.max(green, blue));
1226
+ // Black-gray-white
1227
+ if (minRGB === maxRGB) {
1228
+ return { h: 0, s: 0, v: minRGB };
1229
+ }
1230
+ // Colors other than black-gray-white:
1231
+ const d = red === minRGB ? green - blue : blue === minRGB ? red - green : blue - red;
1232
+ const h = red === minRGB ? 3 : blue === minRGB ? 1 : 5;
1233
+ const hue = (60 * (h - d / (maxRGB - minRGB))) / 360;
1234
+ const saturation = (maxRGB - minRGB) / maxRGB;
1235
+ const value = maxRGB;
1236
+ return { h: hue, s: saturation, v: value };
1237
+ }
1238
+ /**
1239
+ * Split a string with css styles into an object with key/values.
1240
+ * @param cssText - CSS source code to split into key/value object.
1241
+ * @returns Key/value object corresponding to {@link cssText}.
1242
+ */
1243
+ function splitCSSText(cssText) {
1244
+ const tmpEllement = document.createElement("div");
1245
+ const styles = {};
1246
+ tmpEllement.style.cssText = cssText;
1247
+ for (let i = 0; i < tmpEllement.style.length; ++i) {
1248
+ styles[tmpEllement.style[i]] = tmpEllement.style.getPropertyValue(tmpEllement.style[i]);
1249
+ }
1250
+ return styles;
1251
+ }
1252
+ /**
1253
+ * Append a string with css styles to an element.
1254
+ * @param element - The element that will receive new styles.
1255
+ * @param cssText - The styles to be appended.
1256
+ */
1257
+ function addCssText(element, cssText) {
1258
+ const cssStyle = splitCSSText(cssText);
1259
+ for (const [key, value] of Object.entries(cssStyle)) {
1260
+ element.style.setProperty(key, value);
1261
+ }
1262
+ }
1263
+ /**
1264
+ * Remove a string with css styles from an element.
1265
+ * @param element - The element from which styles should be removed.
1266
+ * @param cssText - The styles to be removed.
1267
+ */
1268
+ function removeCssText(element, cssText) {
1269
+ const cssStyle = splitCSSText(cssText);
1270
+ for (const key of Object.keys(cssStyle)) {
1271
+ element.style.removeProperty(key);
1272
+ }
1273
+ }
1274
+ /**
1275
+ * Convert HSV \<0, 1\> into RGB color object.
1276
+ * @remarks
1277
+ * {@link https://gist.github.com/mjijackson/5311256}
1278
+ * @param h - Hue.
1279
+ * @param s - Saturation.
1280
+ * @param v - Value.
1281
+ * @returns RGB color object.
1282
+ */
1283
+ function HSVToRGB(h, s, v) {
1284
+ let r;
1285
+ let g;
1286
+ let b;
1287
+ const i = Math.floor(h * 6);
1288
+ const f = h * 6 - i;
1289
+ const p = v * (1 - s);
1290
+ const q = v * (1 - f * s);
1291
+ const t = v * (1 - (1 - f) * s);
1292
+ switch (i % 6) {
1293
+ case 0:
1294
+ ((r = v), (g = t), (b = p));
1295
+ break;
1296
+ case 1:
1297
+ ((r = q), (g = v), (b = p));
1298
+ break;
1299
+ case 2:
1300
+ ((r = p), (g = v), (b = t));
1301
+ break;
1302
+ case 3:
1303
+ ((r = p), (g = q), (b = v));
1304
+ break;
1305
+ case 4:
1306
+ ((r = t), (g = p), (b = v));
1307
+ break;
1308
+ case 5:
1309
+ ((r = v), (g = p), (b = q));
1310
+ break;
1311
+ }
1312
+ return {
1313
+ r: Math.floor(r * 255),
1314
+ g: Math.floor(g * 255),
1315
+ b: Math.floor(b * 255),
1316
+ };
1317
+ }
1318
+ /**
1319
+ * Convert HSV \<0, 1\> into hex color string.
1320
+ * @param h - Hue.
1321
+ * @param s - Saturation.
1322
+ * @param v - Value.
1323
+ * @returns Hex color string.
1324
+ */
1325
+ function HSVToHex(h, s, v) {
1326
+ const rgb = HSVToRGB(h, s, v);
1327
+ return RGBToHex(rgb.r, rgb.g, rgb.b);
1328
+ }
1329
+ /**
1330
+ * Convert hex color string into HSV \<0, 1\>.
1331
+ * @param hex - Hex color string.
1332
+ * @returns HSV color object.
1333
+ */
1334
+ function hexToHSV(hex) {
1335
+ const rgb = hexToRGB(hex);
1336
+ if (!rgb) {
1337
+ throw new TypeError(`'${hex}' is not a valid color.`);
1338
+ }
1339
+ return RGBToHSV(rgb.r, rgb.g, rgb.b);
1340
+ }
1341
+ /**
1342
+ * Validate hex color string.
1343
+ * @param hex - Unknown string that may contain a color.
1344
+ * @returns True if the string is valid, false otherwise.
1345
+ */
1346
+ function isValidHex(hex) {
1347
+ const isOk = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(hex);
1348
+ return isOk;
1349
+ }
1350
+ /**
1351
+ * Validate RGB color string.
1352
+ * @param rgb - Unknown string that may contain a color.
1353
+ * @returns True if the string is valid, false otherwise.
1354
+ */
1355
+ function isValidRGB(rgb) {
1356
+ return rgbRE.test(rgb);
1357
+ }
1358
+ /**
1359
+ * Validate RGBA color string.
1360
+ * @param rgba - Unknown string that may contain a color.
1361
+ * @returns True if the string is valid, false otherwise.
1362
+ */
1363
+ function isValidRGBA(rgba) {
1364
+ return rgbaRE.test(rgba);
1365
+ }
1366
+ /**
1367
+ * This recursively redirects the prototype of JSON objects to the referenceObject.
1368
+ * This is used for default options.
1369
+ * @param fields - Names of properties to be bridged.
1370
+ * @param referenceObject - The original object.
1371
+ * @returns A new object inheriting from the referenceObject.
1372
+ */
1373
+ function selectiveBridgeObject(fields, referenceObject) {
1374
+ if (referenceObject !== null && typeof referenceObject === "object") {
1375
+ // !!! typeof null === 'object'
1376
+ const objectTo = Object.create(referenceObject);
1377
+ for (let i = 0; i < fields.length; i++) {
1378
+ if (Object.prototype.hasOwnProperty.call(referenceObject, fields[i])) {
1379
+ if (typeof referenceObject[fields[i]] == "object") {
1380
+ objectTo[fields[i]] = bridgeObject(referenceObject[fields[i]]);
1381
+ }
1382
+ }
1383
+ }
1384
+ return objectTo;
1385
+ }
1386
+ else {
1387
+ return null;
1388
+ }
1389
+ }
1390
+ /**
1391
+ * This recursively redirects the prototype of JSON objects to the referenceObject.
1392
+ * This is used for default options.
1393
+ * @param referenceObject - The original object.
1394
+ * @returns The Element if the referenceObject is an Element, or a new object inheriting from the referenceObject.
1395
+ */
1396
+ function bridgeObject(referenceObject) {
1397
+ if (referenceObject === null || typeof referenceObject !== "object") {
1398
+ return null;
1399
+ }
1400
+ if (referenceObject instanceof Element) {
1401
+ // Avoid bridging DOM objects
1402
+ return referenceObject;
1403
+ }
1404
+ const objectTo = Object.create(referenceObject);
1405
+ for (const i in referenceObject) {
1406
+ if (Object.prototype.hasOwnProperty.call(referenceObject, i)) {
1407
+ if (typeof referenceObject[i] == "object") {
1408
+ objectTo[i] = bridgeObject(referenceObject[i]);
1409
+ }
1410
+ }
1411
+ }
1412
+ return objectTo;
1413
+ }
1414
+ /**
1415
+ * This method provides a stable sort implementation, very fast for presorted data.
1416
+ * @param a - The array to be sorted (in-place).
1417
+ * @param compare - An order comparator.
1418
+ * @returns The argument a.
1419
+ */
1420
+ function insertSort(a, compare) {
1421
+ for (let i = 0; i < a.length; i++) {
1422
+ const k = a[i];
1423
+ let j;
1424
+ for (j = i; j > 0 && compare(k, a[j - 1]) < 0; j--) {
1425
+ a[j] = a[j - 1];
1426
+ }
1427
+ a[j] = k;
1428
+ }
1429
+ return a;
1430
+ }
1431
+ /**
1432
+ * This is used to set the options of subobjects in the options object.
1433
+ *
1434
+ * A requirement of these subobjects is that they have an 'enabled' element
1435
+ * which is optional for the user but mandatory for the program.
1436
+ *
1437
+ * The added value here of the merge is that option 'enabled' is set as required.
1438
+ * @param mergeTarget - Either this.options or the options used for the groups.
1439
+ * @param options - Options.
1440
+ * @param option - Option key in the options argument.
1441
+ * @param globalOptions - Global options, passed in to determine value of option 'enabled'.
1442
+ */
1443
+ function mergeOptions(mergeTarget, options, option, globalOptions = {}) {
1444
+ // Local helpers
1445
+ const isPresent = function (obj) {
1446
+ return obj !== null && obj !== undefined;
1447
+ };
1448
+ const isObject = function (obj) {
1449
+ return obj !== null && typeof obj === "object";
1450
+ };
1451
+ // https://stackoverflow.com/a/34491287/1223531
1452
+ const isEmpty = function (obj) {
1453
+ for (const x in obj) {
1454
+ if (Object.prototype.hasOwnProperty.call(obj, x)) {
1455
+ return false;
1456
+ }
1457
+ }
1458
+ return true;
1459
+ };
1460
+ // Guards
1461
+ if (!isObject(mergeTarget)) {
1462
+ throw new Error("Parameter mergeTarget must be an object");
1463
+ }
1464
+ if (!isObject(options)) {
1465
+ throw new Error("Parameter options must be an object");
1466
+ }
1467
+ if (!isPresent(option)) {
1468
+ throw new Error("Parameter option must have a value");
1469
+ }
1470
+ if (!isObject(globalOptions)) {
1471
+ throw new Error("Parameter globalOptions must be an object");
1472
+ }
1473
+ //
1474
+ // Actual merge routine, separated from main logic
1475
+ // Only a single level of options is merged. Deeper levels are ref'd. This may actually be an issue.
1476
+ //
1477
+ const doMerge = function (target, options, option) {
1478
+ if (!isObject(target[option])) {
1479
+ target[option] = {};
1480
+ }
1481
+ const src = options[option];
1482
+ const dst = target[option];
1483
+ for (const prop in src) {
1484
+ if (Object.prototype.hasOwnProperty.call(src, prop)) {
1485
+ dst[prop] = src[prop];
1486
+ }
1487
+ }
1488
+ };
1489
+ // Local initialization
1490
+ const srcOption = options[option];
1491
+ const globalPassed = isObject(globalOptions) && !isEmpty(globalOptions);
1492
+ const globalOption = globalPassed ? globalOptions[option] : undefined;
1493
+ const globalEnabled = globalOption ? globalOption.enabled : undefined;
1494
+ /////////////////////////////////////////
1495
+ // Main routine
1496
+ /////////////////////////////////////////
1497
+ if (srcOption === undefined) {
1498
+ return; // Nothing to do
1499
+ }
1500
+ if (typeof srcOption === "boolean") {
1501
+ if (!isObject(mergeTarget[option])) {
1502
+ mergeTarget[option] = {};
1503
+ }
1504
+ mergeTarget[option].enabled = srcOption;
1505
+ return;
1506
+ }
1507
+ if (srcOption === null && !isObject(mergeTarget[option])) {
1508
+ // If possible, explicit copy from globals
1509
+ if (isPresent(globalOption)) {
1510
+ mergeTarget[option] = Object.create(globalOption);
1511
+ }
1512
+ else {
1513
+ return; // Nothing to do
1514
+ }
1515
+ }
1516
+ if (!isObject(srcOption)) {
1517
+ return;
1518
+ }
1519
+ //
1520
+ // Ensure that 'enabled' is properly set. It is required internally
1521
+ // Note that the value from options will always overwrite the existing value
1522
+ //
1523
+ let enabled = true; // default value
1524
+ if (srcOption.enabled !== undefined) {
1525
+ enabled = srcOption.enabled;
1526
+ }
1527
+ else {
1528
+ // Take from globals, if present
1529
+ if (globalEnabled !== undefined) {
1530
+ enabled = globalOption.enabled;
1531
+ }
1532
+ }
1533
+ doMerge(mergeTarget, options, option);
1534
+ mergeTarget[option].enabled = enabled;
1535
+ }
1536
+ /**
1537
+ * This function does a binary search for a visible item in a sorted list. If we find a visible item, the code that uses
1538
+ * this function will then iterate in both directions over this sorted list to find all visible items.
1539
+ * @param orderedItems - Items ordered by start.
1540
+ * @param comparator - -1 is lower, 0 is equal, 1 is higher.
1541
+ * @param field - Property name on an item (That is item[field]).
1542
+ * @param field2 - Second property name on an item (That is item[field][field2]).
1543
+ * @returns Index of the found item or -1 if nothing was found.
1544
+ */
1545
+ function binarySearchCustom(orderedItems, comparator, field, field2) {
1546
+ const maxIterations = 10000;
1547
+ let iteration = 0;
1548
+ let low = 0;
1549
+ let high = orderedItems.length - 1;
1550
+ while (low <= high && iteration < maxIterations) {
1551
+ const middle = Math.floor((low + high) / 2);
1552
+ const item = orderedItems[middle];
1553
+ const value = field2 === undefined ? item[field] : item[field][field2];
1554
+ const searchResult = comparator(value);
1555
+ if (searchResult == 0) {
1556
+ // jihaa, found a visible item!
1557
+ return middle;
1558
+ }
1559
+ else if (searchResult == -1) {
1560
+ // it is too small --> increase low
1561
+ low = middle + 1;
1562
+ }
1563
+ else {
1564
+ // it is too big --> decrease high
1565
+ high = middle - 1;
1566
+ }
1567
+ iteration++;
1568
+ }
1569
+ return -1;
1570
+ }
1571
+ /**
1572
+ * This function does a binary search for a specific value in a sorted array.
1573
+ * If it does not exist but is in between of two values, we return either the
1574
+ * one before or the one after, depending on user input If it is found, we
1575
+ * return the index, else -1.
1576
+ * @param orderedItems - Sorted array.
1577
+ * @param target - The searched value.
1578
+ * @param field - Name of the property in items to be searched.
1579
+ * @param sidePreference - If the target is between two values, should the index of the before or the after be returned?
1580
+ * @param comparator - An optional comparator, returning -1, 0, 1 for \<, ===, \>.
1581
+ * @returns The index of found value or -1 if nothing was found.
1582
+ */
1583
+ function binarySearchValue(orderedItems, target, field, sidePreference, comparator) {
1584
+ const maxIterations = 10000;
1585
+ let iteration = 0;
1586
+ let low = 0;
1587
+ let high = orderedItems.length - 1;
1588
+ let prevValue;
1589
+ let value;
1590
+ let nextValue;
1591
+ let middle;
1592
+ comparator =
1593
+ comparator != undefined
1594
+ ? comparator
1595
+ : function (a, b) {
1596
+ return a == b ? 0 : a < b ? -1 : 1;
1597
+ };
1598
+ while (low <= high && iteration < maxIterations) {
1599
+ // get a new guess
1600
+ middle = Math.floor(0.5 * (high + low));
1601
+ prevValue = orderedItems[Math.max(0, middle - 1)][field];
1602
+ value = orderedItems[middle][field];
1603
+ nextValue =
1604
+ orderedItems[Math.min(orderedItems.length - 1, middle + 1)][field];
1605
+ if (comparator(value, target) == 0) {
1606
+ // we found the target
1607
+ return middle;
1608
+ }
1609
+ else if (comparator(prevValue, target) < 0 &&
1610
+ comparator(value, target) > 0) {
1611
+ // target is in between of the previous and the current
1612
+ return sidePreference == "before" ? Math.max(0, middle - 1) : middle;
1613
+ }
1614
+ else if (comparator(value, target) < 0 &&
1615
+ comparator(nextValue, target) > 0) {
1616
+ // target is in between of the current and the next
1617
+ return sidePreference == "before"
1618
+ ? middle
1619
+ : Math.min(orderedItems.length - 1, middle + 1);
1620
+ }
1621
+ else {
1622
+ // didnt find the target, we need to change our boundaries.
1623
+ if (comparator(value, target) < 0) {
1624
+ // it is too small --> increase low
1625
+ low = middle + 1;
1626
+ }
1627
+ else {
1628
+ // it is too big --> decrease high
1629
+ high = middle - 1;
1630
+ }
1631
+ }
1632
+ iteration++;
1633
+ }
1634
+ // didnt find anything. Return -1.
1635
+ return -1;
1636
+ }
1637
+ /*
1638
+ * Easing Functions.
1639
+ * Only considering the t value for the range [0, 1] => [0, 1].
1640
+ *
1641
+ * Inspiration: from http://gizma.com/easing/
1642
+ * https://gist.github.com/gre/1650294
1643
+ */
1644
+ const easingFunctions = {
1645
+ /**
1646
+ * Provides no easing and no acceleration.
1647
+ * @param t - Time.
1648
+ * @returns Value at time t.
1649
+ */
1650
+ linear(t) {
1651
+ return t;
1652
+ },
1653
+ /**
1654
+ * Accelerate from zero velocity.
1655
+ * @param t - Time.
1656
+ * @returns Value at time t.
1657
+ */
1658
+ easeInQuad(t) {
1659
+ return t * t;
1660
+ },
1661
+ /**
1662
+ * Decelerate to zero velocity.
1663
+ * @param t - Time.
1664
+ * @returns Value at time t.
1665
+ */
1666
+ easeOutQuad(t) {
1667
+ return t * (2 - t);
1668
+ },
1669
+ /**
1670
+ * Accelerate until halfway, then decelerate.
1671
+ * @param t - Time.
1672
+ * @returns Value at time t.
1673
+ */
1674
+ easeInOutQuad(t) {
1675
+ return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
1676
+ },
1677
+ /**
1678
+ * Accelerate from zero velocity.
1679
+ * @param t - Time.
1680
+ * @returns Value at time t.
1681
+ */
1682
+ easeInCubic(t) {
1683
+ return t * t * t;
1684
+ },
1685
+ /**
1686
+ * Decelerate to zero velocity.
1687
+ * @param t - Time.
1688
+ * @returns Value at time t.
1689
+ */
1690
+ easeOutCubic(t) {
1691
+ return --t * t * t + 1;
1692
+ },
1693
+ /**
1694
+ * Accelerate until halfway, then decelerate.
1695
+ * @param t - Time.
1696
+ * @returns Value at time t.
1697
+ */
1698
+ easeInOutCubic(t) {
1699
+ return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
1700
+ },
1701
+ /**
1702
+ * Accelerate from zero velocity.
1703
+ * @param t - Time.
1704
+ * @returns Value at time t.
1705
+ */
1706
+ easeInQuart(t) {
1707
+ return t * t * t * t;
1708
+ },
1709
+ /**
1710
+ * Decelerate to zero velocity.
1711
+ * @param t - Time.
1712
+ * @returns Value at time t.
1713
+ */
1714
+ easeOutQuart(t) {
1715
+ return 1 - --t * t * t * t;
1716
+ },
1717
+ /**
1718
+ * Accelerate until halfway, then decelerate.
1719
+ * @param t - Time.
1720
+ * @returns Value at time t.
1721
+ */
1722
+ easeInOutQuart(t) {
1723
+ return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
1724
+ },
1725
+ /**
1726
+ * Accelerate from zero velocity.
1727
+ * @param t - Time.
1728
+ * @returns Value at time t.
1729
+ */
1730
+ easeInQuint(t) {
1731
+ return t * t * t * t * t;
1732
+ },
1733
+ /**
1734
+ * Decelerate to zero velocity.
1735
+ * @param t - Time.
1736
+ * @returns Value at time t.
1737
+ */
1738
+ easeOutQuint(t) {
1739
+ return 1 + --t * t * t * t * t;
1740
+ },
1741
+ /**
1742
+ * Accelerate until halfway, then decelerate.
1743
+ * @param t - Time.
1744
+ * @returns Value at time t.
1745
+ */
1746
+ easeInOutQuint(t) {
1747
+ return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
1748
+ },
1749
+ };
1750
+ /**
1751
+ * Experimentaly compute the width of the scrollbar for this browser.
1752
+ * @returns The width in pixels.
1753
+ */
1754
+ function getScrollBarWidth() {
1755
+ const inner = document.createElement("p");
1756
+ inner.style.width = "100%";
1757
+ inner.style.height = "200px";
1758
+ const outer = document.createElement("div");
1759
+ outer.style.position = "absolute";
1760
+ outer.style.top = "0px";
1761
+ outer.style.left = "0px";
1762
+ outer.style.visibility = "hidden";
1763
+ outer.style.width = "200px";
1764
+ outer.style.height = "150px";
1765
+ outer.style.overflow = "hidden";
1766
+ outer.appendChild(inner);
1767
+ document.body.appendChild(outer);
1768
+ const w1 = inner.offsetWidth;
1769
+ outer.style.overflow = "scroll";
1770
+ let w2 = inner.offsetWidth;
1771
+ if (w1 == w2) {
1772
+ w2 = outer.clientWidth;
1773
+ }
1774
+ document.body.removeChild(outer);
1775
+ return w1 - w2;
1776
+ }
1777
+ // @TODO: This doesn't work properly.
1778
+ // It works only for single property objects,
1779
+ // otherwise it combines all of the types in a union.
1780
+ // export function topMost<K1 extends string, V1> (
1781
+ // pile: Record<K1, undefined | V1>[],
1782
+ // accessors: K1 | [K1]
1783
+ // ): undefined | V1
1784
+ // export function topMost<K1 extends string, K2 extends string, V1, V2> (
1785
+ // pile: Record<K1, undefined | V1 | Record<K2, undefined | V2>>[],
1786
+ // accessors: [K1, K2]
1787
+ // ): undefined | V1 | V2
1788
+ // export function topMost<K1 extends string, K2 extends string, K3 extends string, V1, V2, V3> (
1789
+ // pile: Record<K1, undefined | V1 | Record<K2, undefined | V2 | Record<K3, undefined | V3>>>[],
1790
+ // accessors: [K1, K2, K3]
1791
+ // ): undefined | V1 | V2 | V3
1792
+ /**
1793
+ * Get the top most property value from a pile of objects.
1794
+ * @param pile - Array of objects, no required format.
1795
+ * @param accessors - Array of property names.
1796
+ * For example `object['foo']['bar']` → `['foo', 'bar']`.
1797
+ * @returns Value of the property with given accessors path from the first pile item where it's not undefined.
1798
+ */
1799
+ function topMost(pile, accessors) {
1800
+ let candidate;
1801
+ if (!Array.isArray(accessors)) {
1802
+ accessors = [accessors];
1803
+ }
1804
+ for (const member of pile) {
1805
+ if (member) {
1806
+ candidate = member[accessors[0]];
1807
+ for (let i = 1; i < accessors.length; i++) {
1808
+ if (candidate) {
1809
+ candidate = candidate[accessors[i]];
1810
+ }
1811
+ }
1812
+ if (typeof candidate !== "undefined") {
1813
+ break;
1814
+ }
1815
+ }
1816
+ }
1817
+ return candidate;
1818
+ }
1819
+
1820
+ const htmlColors = {
1821
+ black: "#000000",
1822
+ navy: "#000080",
1823
+ darkblue: "#00008B",
1824
+ mediumblue: "#0000CD",
1825
+ blue: "#0000FF",
1826
+ darkgreen: "#006400",
1827
+ green: "#008000",
1828
+ teal: "#008080",
1829
+ darkcyan: "#008B8B",
1830
+ deepskyblue: "#00BFFF",
1831
+ darkturquoise: "#00CED1",
1832
+ mediumspringgreen: "#00FA9A",
1833
+ lime: "#00FF00",
1834
+ springgreen: "#00FF7F",
1835
+ aqua: "#00FFFF",
1836
+ cyan: "#00FFFF",
1837
+ midnightblue: "#191970",
1838
+ dodgerblue: "#1E90FF",
1839
+ lightseagreen: "#20B2AA",
1840
+ forestgreen: "#228B22",
1841
+ seagreen: "#2E8B57",
1842
+ darkslategray: "#2F4F4F",
1843
+ limegreen: "#32CD32",
1844
+ mediumseagreen: "#3CB371",
1845
+ turquoise: "#40E0D0",
1846
+ royalblue: "#4169E1",
1847
+ steelblue: "#4682B4",
1848
+ darkslateblue: "#483D8B",
1849
+ mediumturquoise: "#48D1CC",
1850
+ indigo: "#4B0082",
1851
+ darkolivegreen: "#556B2F",
1852
+ cadetblue: "#5F9EA0",
1853
+ cornflowerblue: "#6495ED",
1854
+ mediumaquamarine: "#66CDAA",
1855
+ dimgray: "#696969",
1856
+ slateblue: "#6A5ACD",
1857
+ olivedrab: "#6B8E23",
1858
+ slategray: "#708090",
1859
+ lightslategray: "#778899",
1860
+ mediumslateblue: "#7B68EE",
1861
+ lawngreen: "#7CFC00",
1862
+ chartreuse: "#7FFF00",
1863
+ aquamarine: "#7FFFD4",
1864
+ maroon: "#800000",
1865
+ purple: "#800080",
1866
+ olive: "#808000",
1867
+ gray: "#808080",
1868
+ skyblue: "#87CEEB",
1869
+ lightskyblue: "#87CEFA",
1870
+ blueviolet: "#8A2BE2",
1871
+ darkred: "#8B0000",
1872
+ darkmagenta: "#8B008B",
1873
+ saddlebrown: "#8B4513",
1874
+ darkseagreen: "#8FBC8F",
1875
+ lightgreen: "#90EE90",
1876
+ mediumpurple: "#9370D8",
1877
+ darkviolet: "#9400D3",
1878
+ palegreen: "#98FB98",
1879
+ darkorchid: "#9932CC",
1880
+ yellowgreen: "#9ACD32",
1881
+ sienna: "#A0522D",
1882
+ brown: "#A52A2A",
1883
+ darkgray: "#A9A9A9",
1884
+ lightblue: "#ADD8E6",
1885
+ greenyellow: "#ADFF2F",
1886
+ paleturquoise: "#AFEEEE",
1887
+ lightsteelblue: "#B0C4DE",
1888
+ powderblue: "#B0E0E6",
1889
+ firebrick: "#B22222",
1890
+ darkgoldenrod: "#B8860B",
1891
+ mediumorchid: "#BA55D3",
1892
+ rosybrown: "#BC8F8F",
1893
+ darkkhaki: "#BDB76B",
1894
+ silver: "#C0C0C0",
1895
+ mediumvioletred: "#C71585",
1896
+ indianred: "#CD5C5C",
1897
+ peru: "#CD853F",
1898
+ chocolate: "#D2691E",
1899
+ tan: "#D2B48C",
1900
+ lightgrey: "#D3D3D3",
1901
+ palevioletred: "#D87093",
1902
+ thistle: "#D8BFD8",
1903
+ orchid: "#DA70D6",
1904
+ goldenrod: "#DAA520",
1905
+ crimson: "#DC143C",
1906
+ gainsboro: "#DCDCDC",
1907
+ plum: "#DDA0DD",
1908
+ burlywood: "#DEB887",
1909
+ lightcyan: "#E0FFFF",
1910
+ lavender: "#E6E6FA",
1911
+ darksalmon: "#E9967A",
1912
+ violet: "#EE82EE",
1913
+ palegoldenrod: "#EEE8AA",
1914
+ lightcoral: "#F08080",
1915
+ khaki: "#F0E68C",
1916
+ aliceblue: "#F0F8FF",
1917
+ honeydew: "#F0FFF0",
1918
+ azure: "#F0FFFF",
1919
+ sandybrown: "#F4A460",
1920
+ wheat: "#F5DEB3",
1921
+ beige: "#F5F5DC",
1922
+ whitesmoke: "#F5F5F5",
1923
+ mintcream: "#F5FFFA",
1924
+ ghostwhite: "#F8F8FF",
1925
+ salmon: "#FA8072",
1926
+ antiquewhite: "#FAEBD7",
1927
+ linen: "#FAF0E6",
1928
+ lightgoldenrodyellow: "#FAFAD2",
1929
+ oldlace: "#FDF5E6",
1930
+ red: "#FF0000",
1931
+ fuchsia: "#FF00FF",
1932
+ magenta: "#FF00FF",
1933
+ deeppink: "#FF1493",
1934
+ orangered: "#FF4500",
1935
+ tomato: "#FF6347",
1936
+ hotpink: "#FF69B4",
1937
+ coral: "#FF7F50",
1938
+ darkorange: "#FF8C00",
1939
+ lightsalmon: "#FFA07A",
1940
+ orange: "#FFA500",
1941
+ lightpink: "#FFB6C1",
1942
+ pink: "#FFC0CB",
1943
+ gold: "#FFD700",
1944
+ peachpuff: "#FFDAB9",
1945
+ navajowhite: "#FFDEAD",
1946
+ moccasin: "#FFE4B5",
1947
+ bisque: "#FFE4C4",
1948
+ mistyrose: "#FFE4E1",
1949
+ blanchedalmond: "#FFEBCD",
1950
+ papayawhip: "#FFEFD5",
1951
+ lavenderblush: "#FFF0F5",
1952
+ seashell: "#FFF5EE",
1953
+ cornsilk: "#FFF8DC",
1954
+ lemonchiffon: "#FFFACD",
1955
+ floralwhite: "#FFFAF0",
1956
+ snow: "#FFFAFA",
1957
+ yellow: "#FFFF00",
1958
+ lightyellow: "#FFFFE0",
1959
+ ivory: "#FFFFF0",
1960
+ white: "#FFFFFF",
1961
+ };
1962
+
1963
+ /**
1964
+ * @param {number} [pixelRatio=1]
1965
+ */
1966
+ let ColorPicker$1 = class ColorPicker {
1967
+ /**
1968
+ * @param {number} [pixelRatio]
1969
+ */
1970
+ constructor(pixelRatio = 1) {
1971
+ this.pixelRatio = pixelRatio;
1972
+ this.generated = false;
1973
+ this.centerCoordinates = { x: 289 / 2, y: 289 / 2 };
1974
+ this.r = 289 * 0.49;
1975
+ this.color = { r: 255, g: 255, b: 255, a: 1.0 };
1976
+ this.hueCircle = undefined;
1977
+ this.initialColor = { r: 255, g: 255, b: 255, a: 1.0 };
1978
+ this.previousColor = undefined;
1979
+ this.applied = false;
1980
+
1981
+ // bound by
1982
+ this.updateCallback = () => {};
1983
+ this.closeCallback = () => {};
1984
+
1985
+ // create all DOM elements
1986
+ this._create();
1987
+ }
1988
+
1989
+ /**
1990
+ * this inserts the colorPicker into a div from the DOM
1991
+ * @param {Element} container
1992
+ */
1993
+ insertTo(container) {
1994
+ if (this.hammer !== undefined) {
1995
+ this.hammer.destroy();
1996
+ this.hammer = undefined;
1997
+ }
1998
+ this.container = container;
1999
+ this.container.appendChild(this.frame);
2000
+ this._bindHammer();
2001
+
2002
+ this._setSize();
2003
+ }
2004
+
2005
+ /**
2006
+ * the callback is executed on apply and save. Bind it to the application
2007
+ * @param {Function} callback
2008
+ */
2009
+ setUpdateCallback(callback) {
2010
+ if (typeof callback === "function") {
2011
+ this.updateCallback = callback;
2012
+ } else {
2013
+ throw new Error(
2014
+ "Function attempted to set as colorPicker update callback is not a function.",
2015
+ );
2016
+ }
2017
+ }
2018
+
2019
+ /**
2020
+ * the callback is executed on apply and save. Bind it to the application
2021
+ * @param {Function} callback
2022
+ */
2023
+ setCloseCallback(callback) {
2024
+ if (typeof callback === "function") {
2025
+ this.closeCallback = callback;
2026
+ } else {
2027
+ throw new Error(
2028
+ "Function attempted to set as colorPicker closing callback is not a function.",
2029
+ );
2030
+ }
2031
+ }
2032
+
2033
+ /**
2034
+ *
2035
+ * @param {string} color
2036
+ * @returns {string}
2037
+ * @private
2038
+ */
2039
+ _isColorString(color) {
2040
+ if (typeof color === "string") {
2041
+ return htmlColors[color];
2042
+ }
2043
+ }
2044
+
2045
+ /**
2046
+ * Set the color of the colorPicker
2047
+ * Supported formats:
2048
+ * 'red' --> HTML color string
2049
+ * '#ffffff' --> hex string
2050
+ * 'rgb(255,255,255)' --> rgb string
2051
+ * 'rgba(255,255,255,1.0)' --> rgba string
2052
+ * {r:255,g:255,b:255} --> rgb object
2053
+ * {r:255,g:255,b:255,a:1.0} --> rgba object
2054
+ * @param {string | object} color
2055
+ * @param {boolean} [setInitial]
2056
+ */
2057
+ setColor(color, setInitial = true) {
2058
+ if (color === "none") {
2059
+ return;
2060
+ }
2061
+
2062
+ let rgba;
2063
+
2064
+ // if a html color shorthand is used, convert to hex
2065
+ const htmlColor = this._isColorString(color);
2066
+ if (htmlColor !== undefined) {
2067
+ color = htmlColor;
2068
+ }
2069
+
2070
+ // check format
2071
+ if (isString(color) === true) {
2072
+ if (isValidRGB(color) === true) {
2073
+ const rgbaArray = color
2074
+ .substr(4)
2075
+ .substr(0, color.length - 5)
2076
+ .split(",");
2077
+ rgba = { r: rgbaArray[0], g: rgbaArray[1], b: rgbaArray[2], a: 1.0 };
2078
+ } else if (isValidRGBA(color) === true) {
2079
+ const rgbaArray = color
2080
+ .substr(5)
2081
+ .substr(0, color.length - 6)
2082
+ .split(",");
2083
+ rgba = {
2084
+ r: rgbaArray[0],
2085
+ g: rgbaArray[1],
2086
+ b: rgbaArray[2],
2087
+ a: rgbaArray[3],
2088
+ };
2089
+ } else if (isValidHex(color) === true) {
2090
+ const rgbObj = hexToRGB(color);
2091
+ rgba = { r: rgbObj.r, g: rgbObj.g, b: rgbObj.b, a: 1.0 };
2092
+ }
2093
+ } else {
2094
+ if (color instanceof Object) {
2095
+ if (
2096
+ color.r !== undefined &&
2097
+ color.g !== undefined &&
2098
+ color.b !== undefined
2099
+ ) {
2100
+ const alpha = color.a !== undefined ? color.a : "1.0";
2101
+ rgba = { r: color.r, g: color.g, b: color.b, a: alpha };
2102
+ }
2103
+ }
2104
+ }
2105
+
2106
+ // set color
2107
+ if (rgba === undefined) {
2108
+ throw new Error(
2109
+ "Unknown color passed to the colorPicker. Supported are strings: rgb, hex, rgba. Object: rgb ({r:r,g:g,b:b,[a:a]}). Supplied: " +
2110
+ JSON.stringify(color),
2111
+ );
2112
+ } else {
2113
+ this._setColor(rgba, setInitial);
2114
+ }
2115
+ }
2116
+
2117
+ /**
2118
+ * this shows the color picker.
2119
+ * The hue circle is constructed once and stored.
2120
+ */
2121
+ show() {
2122
+ if (this.closeCallback !== undefined) {
2123
+ this.closeCallback();
2124
+ this.closeCallback = undefined;
2125
+ }
2126
+
2127
+ this.applied = false;
2128
+ this.frame.style.display = "block";
2129
+ this._generateHueCircle();
2130
+ }
2131
+
2132
+ // ------------------------------------------ PRIVATE ----------------------------- //
2133
+
2134
+ /**
2135
+ * Hide the picker. Is called by the cancel button.
2136
+ * Optional boolean to store the previous color for easy access later on.
2137
+ * @param {boolean} [storePrevious]
2138
+ * @private
2139
+ */
2140
+ _hide(storePrevious = true) {
2141
+ // store the previous color for next time;
2142
+ if (storePrevious === true) {
2143
+ this.previousColor = Object.assign({}, this.color);
2144
+ }
2145
+
2146
+ if (this.applied === true) {
2147
+ this.updateCallback(this.initialColor);
2148
+ }
2149
+
2150
+ this.frame.style.display = "none";
2151
+
2152
+ // call the closing callback, restoring the onclick method.
2153
+ // this is in a setTimeout because it will trigger the show again before the click is done.
2154
+ setTimeout(() => {
2155
+ if (this.closeCallback !== undefined) {
2156
+ this.closeCallback();
2157
+ this.closeCallback = undefined;
2158
+ }
2159
+ }, 0);
2160
+ }
2161
+
2162
+ /**
2163
+ * bound to the save button. Saves and hides.
2164
+ * @private
2165
+ */
2166
+ _save() {
2167
+ this.updateCallback(this.color);
2168
+ this.applied = false;
2169
+ this._hide();
2170
+ }
2171
+
2172
+ /**
2173
+ * Bound to apply button. Saves but does not close. Is undone by the cancel button.
2174
+ * @private
2175
+ */
2176
+ _apply() {
2177
+ this.applied = true;
2178
+ this.updateCallback(this.color);
2179
+ this._updatePicker(this.color);
2180
+ }
2181
+
2182
+ /**
2183
+ * load the color from the previous session.
2184
+ * @private
2185
+ */
2186
+ _loadLast() {
2187
+ if (this.previousColor !== undefined) {
2188
+ this.setColor(this.previousColor, false);
2189
+ } else {
2190
+ alert("There is no last color to load...");
2191
+ }
2192
+ }
2193
+
2194
+ /**
2195
+ * set the color, place the picker
2196
+ * @param {object} rgba
2197
+ * @param {boolean} [setInitial]
2198
+ * @private
2199
+ */
2200
+ _setColor(rgba, setInitial = true) {
2201
+ // store the initial color
2202
+ if (setInitial === true) {
2203
+ this.initialColor = Object.assign({}, rgba);
2204
+ }
2205
+
2206
+ this.color = rgba;
2207
+ const hsv = RGBToHSV(rgba.r, rgba.g, rgba.b);
2208
+
2209
+ const angleConvert = 2 * Math.PI;
2210
+ const radius = this.r * hsv.s;
2211
+ const x =
2212
+ this.centerCoordinates.x + radius * Math.sin(angleConvert * hsv.h);
2213
+ const y =
2214
+ this.centerCoordinates.y + radius * Math.cos(angleConvert * hsv.h);
2215
+
2216
+ this.colorPickerSelector.style.left =
2217
+ x - 0.5 * this.colorPickerSelector.clientWidth + "px";
2218
+ this.colorPickerSelector.style.top =
2219
+ y - 0.5 * this.colorPickerSelector.clientHeight + "px";
2220
+
2221
+ this._updatePicker(rgba);
2222
+ }
2223
+
2224
+ /**
2225
+ * bound to opacity control
2226
+ * @param {number} value
2227
+ * @private
2228
+ */
2229
+ _setOpacity(value) {
2230
+ this.color.a = value / 100;
2231
+ this._updatePicker(this.color);
2232
+ }
2233
+
2234
+ /**
2235
+ * bound to brightness control
2236
+ * @param {number} value
2237
+ * @private
2238
+ */
2239
+ _setBrightness(value) {
2240
+ const hsv = RGBToHSV(this.color.r, this.color.g, this.color.b);
2241
+ hsv.v = value / 100;
2242
+ const rgba = HSVToRGB(hsv.h, hsv.s, hsv.v);
2243
+ rgba["a"] = this.color.a;
2244
+ this.color = rgba;
2245
+ this._updatePicker();
2246
+ }
2247
+
2248
+ /**
2249
+ * update the color picker. A black circle overlays the hue circle to mimic the brightness decreasing.
2250
+ * @param {object} rgba
2251
+ * @private
2252
+ */
2253
+ _updatePicker(rgba = this.color) {
2254
+ const hsv = RGBToHSV(rgba.r, rgba.g, rgba.b);
2255
+ const ctx = this.colorPickerCanvas.getContext("2d");
2256
+ if (this.pixelRation === undefined) {
2257
+ this.pixelRatio =
2258
+ (window.devicePixelRatio || 1) /
2259
+ (ctx.webkitBackingStorePixelRatio ||
2260
+ ctx.mozBackingStorePixelRatio ||
2261
+ ctx.msBackingStorePixelRatio ||
2262
+ ctx.oBackingStorePixelRatio ||
2263
+ ctx.backingStorePixelRatio ||
2264
+ 1);
2265
+ }
2266
+ ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0);
2267
+
2268
+ // clear the canvas
2269
+ const w = this.colorPickerCanvas.clientWidth;
2270
+ const h = this.colorPickerCanvas.clientHeight;
2271
+ ctx.clearRect(0, 0, w, h);
2272
+
2273
+ ctx.putImageData(this.hueCircle, 0, 0);
2274
+ ctx.fillStyle = "rgba(0,0,0," + (1 - hsv.v) + ")";
2275
+ ctx.circle(this.centerCoordinates.x, this.centerCoordinates.y, this.r);
2276
+ ctx.fill();
2277
+
2278
+ this.brightnessRange.value = 100 * hsv.v;
2279
+ this.opacityRange.value = 100 * rgba.a;
2280
+
2281
+ this.initialColorDiv.style.backgroundColor =
2282
+ "rgba(" +
2283
+ this.initialColor.r +
2284
+ "," +
2285
+ this.initialColor.g +
2286
+ "," +
2287
+ this.initialColor.b +
2288
+ "," +
2289
+ this.initialColor.a +
2290
+ ")";
2291
+ this.newColorDiv.style.backgroundColor =
2292
+ "rgba(" +
2293
+ this.color.r +
2294
+ "," +
2295
+ this.color.g +
2296
+ "," +
2297
+ this.color.b +
2298
+ "," +
2299
+ this.color.a +
2300
+ ")";
2301
+ }
2302
+
2303
+ /**
2304
+ * used by create to set the size of the canvas.
2305
+ * @private
2306
+ */
2307
+ _setSize() {
2308
+ this.colorPickerCanvas.style.width = "100%";
2309
+ this.colorPickerCanvas.style.height = "100%";
2310
+
2311
+ this.colorPickerCanvas.width = 289 * this.pixelRatio;
2312
+ this.colorPickerCanvas.height = 289 * this.pixelRatio;
2313
+ }
2314
+
2315
+ /**
2316
+ * create all dom elements
2317
+ * TODO: cleanup, lots of similar dom elements
2318
+ * @private
2319
+ */
2320
+ _create() {
2321
+ this.frame = document.createElement("div");
2322
+ this.frame.className = "vis-color-picker";
2323
+
2324
+ this.colorPickerDiv = document.createElement("div");
2325
+ this.colorPickerSelector = document.createElement("div");
2326
+ this.colorPickerSelector.className = "vis-selector";
2327
+ this.colorPickerDiv.appendChild(this.colorPickerSelector);
2328
+
2329
+ this.colorPickerCanvas = document.createElement("canvas");
2330
+ this.colorPickerDiv.appendChild(this.colorPickerCanvas);
2331
+
2332
+ if (!this.colorPickerCanvas.getContext) {
2333
+ const noCanvas = document.createElement("DIV");
2334
+ noCanvas.style.color = "red";
2335
+ noCanvas.style.fontWeight = "bold";
2336
+ noCanvas.style.padding = "10px";
2337
+ noCanvas.innerText = "Error: your browser does not support HTML canvas";
2338
+ this.colorPickerCanvas.appendChild(noCanvas);
2339
+ } else {
2340
+ const ctx = this.colorPickerCanvas.getContext("2d");
2341
+ this.pixelRatio =
2342
+ (window.devicePixelRatio || 1) /
2343
+ (ctx.webkitBackingStorePixelRatio ||
2344
+ ctx.mozBackingStorePixelRatio ||
2345
+ ctx.msBackingStorePixelRatio ||
2346
+ ctx.oBackingStorePixelRatio ||
2347
+ ctx.backingStorePixelRatio ||
2348
+ 1);
2349
+ this.colorPickerCanvas
2350
+ .getContext("2d")
2351
+ .setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0);
2352
+ }
2353
+
2354
+ this.colorPickerDiv.className = "vis-color";
2355
+
2356
+ this.opacityDiv = document.createElement("div");
2357
+ this.opacityDiv.className = "vis-opacity";
2358
+
2359
+ this.brightnessDiv = document.createElement("div");
2360
+ this.brightnessDiv.className = "vis-brightness";
2361
+
2362
+ this.arrowDiv = document.createElement("div");
2363
+ this.arrowDiv.className = "vis-arrow";
2364
+
2365
+ this.opacityRange = document.createElement("input");
2366
+ try {
2367
+ this.opacityRange.type = "range"; // Not supported on IE9
2368
+ this.opacityRange.min = "0";
2369
+ this.opacityRange.max = "100";
2370
+ } catch {
2371
+ // TODO: Add some error handling.
2372
+ }
2373
+ this.opacityRange.value = "100";
2374
+ this.opacityRange.className = "vis-range";
2375
+
2376
+ this.brightnessRange = document.createElement("input");
2377
+ try {
2378
+ this.brightnessRange.type = "range"; // Not supported on IE9
2379
+ this.brightnessRange.min = "0";
2380
+ this.brightnessRange.max = "100";
2381
+ } catch {
2382
+ // TODO: Add some error handling.
2383
+ }
2384
+ this.brightnessRange.value = "100";
2385
+ this.brightnessRange.className = "vis-range";
2386
+
2387
+ this.opacityDiv.appendChild(this.opacityRange);
2388
+ this.brightnessDiv.appendChild(this.brightnessRange);
2389
+
2390
+ const me = this;
2391
+ this.opacityRange.onchange = function () {
2392
+ me._setOpacity(this.value);
2393
+ };
2394
+ this.opacityRange.oninput = function () {
2395
+ me._setOpacity(this.value);
2396
+ };
2397
+ this.brightnessRange.onchange = function () {
2398
+ me._setBrightness(this.value);
2399
+ };
2400
+ this.brightnessRange.oninput = function () {
2401
+ me._setBrightness(this.value);
2402
+ };
2403
+
2404
+ this.brightnessLabel = document.createElement("div");
2405
+ this.brightnessLabel.className = "vis-label vis-brightness";
2406
+ this.brightnessLabel.innerText = "brightness:";
2407
+
2408
+ this.opacityLabel = document.createElement("div");
2409
+ this.opacityLabel.className = "vis-label vis-opacity";
2410
+ this.opacityLabel.innerText = "opacity:";
2411
+
2412
+ this.newColorDiv = document.createElement("div");
2413
+ this.newColorDiv.className = "vis-new-color";
2414
+ this.newColorDiv.innerText = "new";
2415
+
2416
+ this.initialColorDiv = document.createElement("div");
2417
+ this.initialColorDiv.className = "vis-initial-color";
2418
+ this.initialColorDiv.innerText = "initial";
2419
+
2420
+ this.cancelButton = document.createElement("div");
2421
+ this.cancelButton.className = "vis-button vis-cancel";
2422
+ this.cancelButton.innerText = "cancel";
2423
+ this.cancelButton.onclick = this._hide.bind(this, false);
2424
+
2425
+ this.applyButton = document.createElement("div");
2426
+ this.applyButton.className = "vis-button vis-apply";
2427
+ this.applyButton.innerText = "apply";
2428
+ this.applyButton.onclick = this._apply.bind(this);
2429
+
2430
+ this.saveButton = document.createElement("div");
2431
+ this.saveButton.className = "vis-button vis-save";
2432
+ this.saveButton.innerText = "save";
2433
+ this.saveButton.onclick = this._save.bind(this);
2434
+
2435
+ this.loadButton = document.createElement("div");
2436
+ this.loadButton.className = "vis-button vis-load";
2437
+ this.loadButton.innerText = "load last";
2438
+ this.loadButton.onclick = this._loadLast.bind(this);
2439
+
2440
+ this.frame.appendChild(this.colorPickerDiv);
2441
+ this.frame.appendChild(this.arrowDiv);
2442
+ this.frame.appendChild(this.brightnessLabel);
2443
+ this.frame.appendChild(this.brightnessDiv);
2444
+ this.frame.appendChild(this.opacityLabel);
2445
+ this.frame.appendChild(this.opacityDiv);
2446
+ this.frame.appendChild(this.newColorDiv);
2447
+ this.frame.appendChild(this.initialColorDiv);
2448
+
2449
+ this.frame.appendChild(this.cancelButton);
2450
+ this.frame.appendChild(this.applyButton);
2451
+ this.frame.appendChild(this.saveButton);
2452
+ this.frame.appendChild(this.loadButton);
2453
+ }
2454
+
2455
+ /**
2456
+ * bind hammer to the color picker
2457
+ * @private
2458
+ */
2459
+ _bindHammer() {
2460
+ this.drag = {};
2461
+ this.pinch = {};
2462
+ this.hammer = new Hammer$1(this.colorPickerCanvas);
2463
+ this.hammer.get("pinch").set({ enable: true });
2464
+
2465
+ this.hammer.on("hammer.input", (event) => {
2466
+ if (event.isFirst) {
2467
+ this._moveSelector(event);
2468
+ }
2469
+ });
2470
+ this.hammer.on("tap", (event) => {
2471
+ this._moveSelector(event);
2472
+ });
2473
+ this.hammer.on("panstart", (event) => {
2474
+ this._moveSelector(event);
2475
+ });
2476
+ this.hammer.on("panmove", (event) => {
2477
+ this._moveSelector(event);
2478
+ });
2479
+ this.hammer.on("panend", (event) => {
2480
+ this._moveSelector(event);
2481
+ });
2482
+ }
2483
+
2484
+ /**
2485
+ * generate the hue circle. This is relatively heavy (200ms) and is done only once on the first time it is shown.
2486
+ * @private
2487
+ */
2488
+ _generateHueCircle() {
2489
+ if (this.generated === false) {
2490
+ const ctx = this.colorPickerCanvas.getContext("2d");
2491
+ if (this.pixelRation === undefined) {
2492
+ this.pixelRatio =
2493
+ (window.devicePixelRatio || 1) /
2494
+ (ctx.webkitBackingStorePixelRatio ||
2495
+ ctx.mozBackingStorePixelRatio ||
2496
+ ctx.msBackingStorePixelRatio ||
2497
+ ctx.oBackingStorePixelRatio ||
2498
+ ctx.backingStorePixelRatio ||
2499
+ 1);
2500
+ }
2501
+ ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0);
2502
+
2503
+ // clear the canvas
2504
+ const w = this.colorPickerCanvas.clientWidth;
2505
+ const h = this.colorPickerCanvas.clientHeight;
2506
+ ctx.clearRect(0, 0, w, h);
2507
+
2508
+ // draw hue circle
2509
+ let x, y, hue, sat;
2510
+ this.centerCoordinates = { x: w * 0.5, y: h * 0.5 };
2511
+ this.r = 0.49 * w;
2512
+ const angleConvert = (2 * Math.PI) / 360;
2513
+ const hfac = 1 / 360;
2514
+ const sfac = 1 / this.r;
2515
+ let rgb;
2516
+ for (hue = 0; hue < 360; hue++) {
2517
+ for (sat = 0; sat < this.r; sat++) {
2518
+ x = this.centerCoordinates.x + sat * Math.sin(angleConvert * hue);
2519
+ y = this.centerCoordinates.y + sat * Math.cos(angleConvert * hue);
2520
+ rgb = HSVToRGB(hue * hfac, sat * sfac, 1);
2521
+ ctx.fillStyle = "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")";
2522
+ ctx.fillRect(x - 0.5, y - 0.5, 2, 2);
2523
+ }
2524
+ }
2525
+ ctx.strokeStyle = "rgba(0,0,0,1)";
2526
+ ctx.circle(this.centerCoordinates.x, this.centerCoordinates.y, this.r);
2527
+ ctx.stroke();
2528
+
2529
+ this.hueCircle = ctx.getImageData(0, 0, w, h);
2530
+ }
2531
+ this.generated = true;
2532
+ }
2533
+
2534
+ /**
2535
+ * move the selector. This is called by hammer functions.
2536
+ * @param {Event} event The event
2537
+ * @private
2538
+ */
2539
+ _moveSelector(event) {
2540
+ const rect = this.colorPickerDiv.getBoundingClientRect();
2541
+ const left = event.center.x - rect.left;
2542
+ const top = event.center.y - rect.top;
2543
+
2544
+ const centerY = 0.5 * this.colorPickerDiv.clientHeight;
2545
+ const centerX = 0.5 * this.colorPickerDiv.clientWidth;
2546
+
2547
+ const x = left - centerX;
2548
+ const y = top - centerY;
2549
+
2550
+ const angle = Math.atan2(x, y);
2551
+ const radius = 0.98 * Math.min(Math.sqrt(x * x + y * y), centerX);
2552
+
2553
+ const newTop = Math.cos(angle) * radius + centerY;
2554
+ const newLeft = Math.sin(angle) * radius + centerX;
2555
+
2556
+ this.colorPickerSelector.style.top =
2557
+ newTop - 0.5 * this.colorPickerSelector.clientHeight + "px";
2558
+ this.colorPickerSelector.style.left =
2559
+ newLeft - 0.5 * this.colorPickerSelector.clientWidth + "px";
2560
+
2561
+ // set color
2562
+ let h = angle / (2 * Math.PI);
2563
+ h = h < 0 ? h + 1 : h;
2564
+ const s = radius / this.r;
2565
+ const hsv = RGBToHSV(this.color.r, this.color.g, this.color.b);
2566
+ hsv.h = h;
2567
+ hsv.s = s;
2568
+ const rgba = HSVToRGB(hsv.h, hsv.s, hsv.v);
2569
+ rgba["a"] = this.color.a;
2570
+ this.color = rgba;
2571
+
2572
+ // update previews
2573
+ this.initialColorDiv.style.backgroundColor =
2574
+ "rgba(" +
2575
+ this.initialColor.r +
2576
+ "," +
2577
+ this.initialColor.g +
2578
+ "," +
2579
+ this.initialColor.b +
2580
+ "," +
2581
+ this.initialColor.a +
2582
+ ")";
2583
+ this.newColorDiv.style.backgroundColor =
2584
+ "rgba(" +
2585
+ this.color.r +
2586
+ "," +
2587
+ this.color.g +
2588
+ "," +
2589
+ this.color.b +
2590
+ "," +
2591
+ this.color.a +
2592
+ ")";
2593
+ }
2594
+ };
2595
+
2596
+ /**
2597
+ * Wrap given text (last argument) in HTML elements (all preceding arguments).
2598
+ * @param {...any} rest - List of tag names followed by inner text.
2599
+ * @returns An element or a text node.
2600
+ */
2601
+ function wrapInTag(...rest) {
2602
+ if (rest.length < 1) {
2603
+ throw new TypeError("Invalid arguments.");
2604
+ } else if (rest.length === 1) {
2605
+ return document.createTextNode(rest[0]);
2606
+ } else {
2607
+ const element = document.createElement(rest[0]);
2608
+ element.appendChild(wrapInTag(...rest.slice(1)));
2609
+ return element;
2610
+ }
2611
+ }
2612
+
2613
+ /**
2614
+ * The way this works is for all properties of this.possible options, you can supply the property name in any form to list the options.
2615
+ * Boolean options are recognised as Boolean
2616
+ * Number options should be written as array: [default value, min value, max value, stepsize]
2617
+ * Colors should be written as array: ['color', '#ffffff']
2618
+ * Strings with should be written as array: [option1, option2, option3, ..]
2619
+ *
2620
+ * The options are matched with their counterparts in each of the modules and the values used in the configuration are
2621
+ */
2622
+ let Configurator$1 = class Configurator {
2623
+ /**
2624
+ * @param {object} parentModule | the location where parentModule.setOptions() can be called
2625
+ * @param {object} defaultContainer | the default container of the module
2626
+ * @param {object} configureOptions | the fully configured and predefined options set found in allOptions.js
2627
+ * @param {number} pixelRatio | canvas pixel ratio
2628
+ * @param {Function} hideOption | custom logic to dynamically hide options
2629
+ */
2630
+ constructor(
2631
+ parentModule,
2632
+ defaultContainer,
2633
+ configureOptions,
2634
+ pixelRatio = 1,
2635
+ hideOption = () => false,
2636
+ ) {
2637
+ this.parent = parentModule;
2638
+ this.changedOptions = [];
2639
+ this.container = defaultContainer;
2640
+ this.allowCreation = false;
2641
+ this.hideOption = hideOption;
2642
+
2643
+ this.options = {};
2644
+ this.initialized = false;
2645
+ this.popupCounter = 0;
2646
+ this.defaultOptions = {
2647
+ enabled: false,
2648
+ filter: true,
2649
+ container: undefined,
2650
+ showButton: true,
2651
+ };
2652
+ Object.assign(this.options, this.defaultOptions);
2653
+
2654
+ this.configureOptions = configureOptions;
2655
+ this.moduleOptions = {};
2656
+ this.domElements = [];
2657
+ this.popupDiv = {};
2658
+ this.popupLimit = 5;
2659
+ this.popupHistory = {};
2660
+ this.colorPicker = new ColorPicker$1(pixelRatio);
2661
+ this.wrapper = undefined;
2662
+ }
2663
+
2664
+ /**
2665
+ * refresh all options.
2666
+ * Because all modules parse their options by themselves, we just use their options. We copy them here.
2667
+ * @param {object} options
2668
+ */
2669
+ setOptions(options) {
2670
+ if (options !== undefined) {
2671
+ // reset the popup history because the indices may have been changed.
2672
+ this.popupHistory = {};
2673
+ this._removePopup();
2674
+
2675
+ let enabled = true;
2676
+ if (typeof options === "string") {
2677
+ this.options.filter = options;
2678
+ } else if (Array.isArray(options)) {
2679
+ this.options.filter = options.join();
2680
+ } else if (typeof options === "object") {
2681
+ if (options == null) {
2682
+ throw new TypeError("options cannot be null");
2683
+ }
2684
+ if (options.container !== undefined) {
2685
+ this.options.container = options.container;
2686
+ }
2687
+ if (options.filter !== undefined) {
2688
+ this.options.filter = options.filter;
2689
+ }
2690
+ if (options.showButton !== undefined) {
2691
+ this.options.showButton = options.showButton;
2692
+ }
2693
+ if (options.enabled !== undefined) {
2694
+ enabled = options.enabled;
2695
+ }
2696
+ } else if (typeof options === "boolean") {
2697
+ this.options.filter = true;
2698
+ enabled = options;
2699
+ } else if (typeof options === "function") {
2700
+ this.options.filter = options;
2701
+ enabled = true;
2702
+ }
2703
+ if (this.options.filter === false) {
2704
+ enabled = false;
2705
+ }
2706
+
2707
+ this.options.enabled = enabled;
2708
+ }
2709
+ this._clean();
2710
+ }
2711
+
2712
+ /**
2713
+ *
2714
+ * @param {object} moduleOptions
2715
+ */
2716
+ setModuleOptions(moduleOptions) {
2717
+ this.moduleOptions = moduleOptions;
2718
+ if (this.options.enabled === true) {
2719
+ this._clean();
2720
+ if (this.options.container !== undefined) {
2721
+ this.container = this.options.container;
2722
+ }
2723
+ this._create();
2724
+ }
2725
+ }
2726
+
2727
+ /**
2728
+ * Create all DOM elements
2729
+ * @private
2730
+ */
2731
+ _create() {
2732
+ this._clean();
2733
+ this.changedOptions = [];
2734
+
2735
+ const filter = this.options.filter;
2736
+ let counter = 0;
2737
+ let show = false;
2738
+ for (const option in this.configureOptions) {
2739
+ if (Object.prototype.hasOwnProperty.call(this.configureOptions, option)) {
2740
+ this.allowCreation = false;
2741
+ show = false;
2742
+ if (typeof filter === "function") {
2743
+ show = filter(option, []);
2744
+ show =
2745
+ show ||
2746
+ this._handleObject(this.configureOptions[option], [option], true);
2747
+ } else if (filter === true || filter.indexOf(option) !== -1) {
2748
+ show = true;
2749
+ }
2750
+
2751
+ if (show !== false) {
2752
+ this.allowCreation = true;
2753
+
2754
+ // linebreak between categories
2755
+ if (counter > 0) {
2756
+ this._makeItem([]);
2757
+ }
2758
+ // a header for the category
2759
+ this._makeHeader(option);
2760
+
2761
+ // get the sub options
2762
+ this._handleObject(this.configureOptions[option], [option]);
2763
+ }
2764
+ counter++;
2765
+ }
2766
+ }
2767
+ this._makeButton();
2768
+ this._push();
2769
+ //~ this.colorPicker.insertTo(this.container);
2770
+ }
2771
+
2772
+ /**
2773
+ * draw all DOM elements on the screen
2774
+ * @private
2775
+ */
2776
+ _push() {
2777
+ this.wrapper = document.createElement("div");
2778
+ this.wrapper.className = "vis-configuration-wrapper";
2779
+ this.container.appendChild(this.wrapper);
2780
+ for (let i = 0; i < this.domElements.length; i++) {
2781
+ this.wrapper.appendChild(this.domElements[i]);
2782
+ }
2783
+
2784
+ this._showPopupIfNeeded();
2785
+ }
2786
+
2787
+ /**
2788
+ * delete all DOM elements
2789
+ * @private
2790
+ */
2791
+ _clean() {
2792
+ for (let i = 0; i < this.domElements.length; i++) {
2793
+ this.wrapper.removeChild(this.domElements[i]);
2794
+ }
2795
+
2796
+ if (this.wrapper !== undefined) {
2797
+ this.container.removeChild(this.wrapper);
2798
+ this.wrapper = undefined;
2799
+ }
2800
+ this.domElements = [];
2801
+
2802
+ this._removePopup();
2803
+ }
2804
+
2805
+ /**
2806
+ * get the value from the actualOptions if it exists
2807
+ * @param {Array} path | where to look for the actual option
2808
+ * @returns {*}
2809
+ * @private
2810
+ */
2811
+ _getValue(path) {
2812
+ let base = this.moduleOptions;
2813
+ for (let i = 0; i < path.length; i++) {
2814
+ if (base[path[i]] !== undefined) {
2815
+ base = base[path[i]];
2816
+ } else {
2817
+ base = undefined;
2818
+ break;
2819
+ }
2820
+ }
2821
+ return base;
2822
+ }
2823
+
2824
+ /**
2825
+ * all option elements are wrapped in an item
2826
+ * @param {Array} path | where to look for the actual option
2827
+ * @param {Array.<Element>} domElements
2828
+ * @returns {number}
2829
+ * @private
2830
+ */
2831
+ _makeItem(path, ...domElements) {
2832
+ if (this.allowCreation === true) {
2833
+ const item = document.createElement("div");
2834
+ item.className =
2835
+ "vis-configuration vis-config-item vis-config-s" + path.length;
2836
+ domElements.forEach((element) => {
2837
+ item.appendChild(element);
2838
+ });
2839
+ this.domElements.push(item);
2840
+ return this.domElements.length;
2841
+ }
2842
+ return 0;
2843
+ }
2844
+
2845
+ /**
2846
+ * header for major subjects
2847
+ * @param {string} name
2848
+ * @private
2849
+ */
2850
+ _makeHeader(name) {
2851
+ const div = document.createElement("div");
2852
+ div.className = "vis-configuration vis-config-header";
2853
+ div.innerText = name;
2854
+ this._makeItem([], div);
2855
+ }
2856
+
2857
+ /**
2858
+ * make a label, if it is an object label, it gets different styling.
2859
+ * @param {string} name
2860
+ * @param {Array} path | where to look for the actual option
2861
+ * @param {string} objectLabel
2862
+ * @returns {HTMLElement}
2863
+ * @private
2864
+ */
2865
+ _makeLabel(name, path, objectLabel = false) {
2866
+ const div = document.createElement("div");
2867
+ div.className =
2868
+ "vis-configuration vis-config-label vis-config-s" + path.length;
2869
+ if (objectLabel === true) {
2870
+ while (div.firstChild) {
2871
+ div.removeChild(div.firstChild);
2872
+ }
2873
+ div.appendChild(wrapInTag("i", "b", name));
2874
+ } else {
2875
+ div.innerText = name + ":";
2876
+ }
2877
+ return div;
2878
+ }
2879
+
2880
+ /**
2881
+ * make a dropdown list for multiple possible string optoins
2882
+ * @param {Array.<number>} arr
2883
+ * @param {number} value
2884
+ * @param {Array} path | where to look for the actual option
2885
+ * @private
2886
+ */
2887
+ _makeDropdown(arr, value, path) {
2888
+ const select = document.createElement("select");
2889
+ select.className = "vis-configuration vis-config-select";
2890
+ let selectedValue = 0;
2891
+ if (value !== undefined) {
2892
+ if (arr.indexOf(value) !== -1) {
2893
+ selectedValue = arr.indexOf(value);
2894
+ }
2895
+ }
2896
+
2897
+ for (let i = 0; i < arr.length; i++) {
2898
+ const option = document.createElement("option");
2899
+ option.value = arr[i];
2900
+ if (i === selectedValue) {
2901
+ option.selected = "selected";
2902
+ }
2903
+ option.innerText = arr[i];
2904
+ select.appendChild(option);
2905
+ }
2906
+
2907
+ const me = this;
2908
+ select.onchange = function () {
2909
+ me._update(this.value, path);
2910
+ };
2911
+
2912
+ const label = this._makeLabel(path[path.length - 1], path);
2913
+ this._makeItem(path, label, select);
2914
+ }
2915
+
2916
+ /**
2917
+ * make a range object for numeric options
2918
+ * @param {Array.<number>} arr
2919
+ * @param {number} value
2920
+ * @param {Array} path | where to look for the actual option
2921
+ * @private
2922
+ */
2923
+ _makeRange(arr, value, path) {
2924
+ const defaultValue = arr[0];
2925
+ const min = arr[1];
2926
+ const max = arr[2];
2927
+ const step = arr[3];
2928
+ const range = document.createElement("input");
2929
+ range.className = "vis-configuration vis-config-range";
2930
+ try {
2931
+ range.type = "range"; // not supported on IE9
2932
+ range.min = min;
2933
+ range.max = max;
2934
+ } catch {
2935
+ // TODO: Add some error handling.
2936
+ }
2937
+ range.step = step;
2938
+
2939
+ // set up the popup settings in case they are needed.
2940
+ let popupString = "";
2941
+ let popupValue = 0;
2942
+
2943
+ if (value !== undefined) {
2944
+ const factor = 1.2;
2945
+ if (value < 0 && value * factor < min) {
2946
+ range.min = Math.ceil(value * factor);
2947
+ popupValue = range.min;
2948
+ popupString = "range increased";
2949
+ } else if (value / factor < min) {
2950
+ range.min = Math.ceil(value / factor);
2951
+ popupValue = range.min;
2952
+ popupString = "range increased";
2953
+ }
2954
+ if (value * factor > max && max !== 1) {
2955
+ range.max = Math.ceil(value * factor);
2956
+ popupValue = range.max;
2957
+ popupString = "range increased";
2958
+ }
2959
+ range.value = value;
2960
+ } else {
2961
+ range.value = defaultValue;
2962
+ }
2963
+
2964
+ const input = document.createElement("input");
2965
+ input.className = "vis-configuration vis-config-rangeinput";
2966
+ input.value = range.value;
2967
+
2968
+ const me = this;
2969
+ range.onchange = function () {
2970
+ input.value = this.value;
2971
+ me._update(Number(this.value), path);
2972
+ };
2973
+ range.oninput = function () {
2974
+ input.value = this.value;
2975
+ };
2976
+
2977
+ const label = this._makeLabel(path[path.length - 1], path);
2978
+ const itemIndex = this._makeItem(path, label, range, input);
2979
+
2980
+ // if a popup is needed AND it has not been shown for this value, show it.
2981
+ if (popupString !== "" && this.popupHistory[itemIndex] !== popupValue) {
2982
+ this.popupHistory[itemIndex] = popupValue;
2983
+ this._setupPopup(popupString, itemIndex);
2984
+ }
2985
+ }
2986
+
2987
+ /**
2988
+ * make a button object
2989
+ * @private
2990
+ */
2991
+ _makeButton() {
2992
+ if (this.options.showButton === true) {
2993
+ const generateButton = document.createElement("div");
2994
+ generateButton.className = "vis-configuration vis-config-button";
2995
+ generateButton.innerText = "generate options";
2996
+ generateButton.onclick = () => {
2997
+ this._printOptions();
2998
+ };
2999
+ generateButton.onmouseover = () => {
3000
+ generateButton.className = "vis-configuration vis-config-button hover";
3001
+ };
3002
+ generateButton.onmouseout = () => {
3003
+ generateButton.className = "vis-configuration vis-config-button";
3004
+ };
3005
+
3006
+ this.optionsContainer = document.createElement("div");
3007
+ this.optionsContainer.className =
3008
+ "vis-configuration vis-config-option-container";
3009
+
3010
+ this.domElements.push(this.optionsContainer);
3011
+ this.domElements.push(generateButton);
3012
+ }
3013
+ }
3014
+
3015
+ /**
3016
+ * prepare the popup
3017
+ * @param {string} string
3018
+ * @param {number} index
3019
+ * @private
3020
+ */
3021
+ _setupPopup(string, index) {
3022
+ if (
3023
+ this.initialized === true &&
3024
+ this.allowCreation === true &&
3025
+ this.popupCounter < this.popupLimit
3026
+ ) {
3027
+ const div = document.createElement("div");
3028
+ div.id = "vis-configuration-popup";
3029
+ div.className = "vis-configuration-popup";
3030
+ div.innerText = string;
3031
+ div.onclick = () => {
3032
+ this._removePopup();
3033
+ };
3034
+ this.popupCounter += 1;
3035
+ this.popupDiv = { html: div, index: index };
3036
+ }
3037
+ }
3038
+
3039
+ /**
3040
+ * remove the popup from the dom
3041
+ * @private
3042
+ */
3043
+ _removePopup() {
3044
+ if (this.popupDiv.html !== undefined) {
3045
+ this.popupDiv.html.parentNode.removeChild(this.popupDiv.html);
3046
+ clearTimeout(this.popupDiv.hideTimeout);
3047
+ clearTimeout(this.popupDiv.deleteTimeout);
3048
+ this.popupDiv = {};
3049
+ }
3050
+ }
3051
+
3052
+ /**
3053
+ * Show the popup if it is needed.
3054
+ * @private
3055
+ */
3056
+ _showPopupIfNeeded() {
3057
+ if (this.popupDiv.html !== undefined) {
3058
+ const correspondingElement = this.domElements[this.popupDiv.index];
3059
+ const rect = correspondingElement.getBoundingClientRect();
3060
+ this.popupDiv.html.style.left = rect.left + "px";
3061
+ this.popupDiv.html.style.top = rect.top - 30 + "px"; // 30 is the height;
3062
+ document.body.appendChild(this.popupDiv.html);
3063
+ this.popupDiv.hideTimeout = setTimeout(() => {
3064
+ this.popupDiv.html.style.opacity = 0;
3065
+ }, 1500);
3066
+ this.popupDiv.deleteTimeout = setTimeout(() => {
3067
+ this._removePopup();
3068
+ }, 1800);
3069
+ }
3070
+ }
3071
+
3072
+ /**
3073
+ * make a checkbox for boolean options.
3074
+ * @param {number} defaultValue
3075
+ * @param {number} value
3076
+ * @param {Array} path | where to look for the actual option
3077
+ * @private
3078
+ */
3079
+ _makeCheckbox(defaultValue, value, path) {
3080
+ const checkbox = document.createElement("input");
3081
+ checkbox.type = "checkbox";
3082
+ checkbox.className = "vis-configuration vis-config-checkbox";
3083
+ checkbox.checked = defaultValue;
3084
+ if (value !== undefined) {
3085
+ checkbox.checked = value;
3086
+ if (value !== defaultValue) {
3087
+ if (typeof defaultValue === "object") {
3088
+ if (value !== defaultValue.enabled) {
3089
+ this.changedOptions.push({ path: path, value: value });
3090
+ }
3091
+ } else {
3092
+ this.changedOptions.push({ path: path, value: value });
3093
+ }
3094
+ }
3095
+ }
3096
+
3097
+ const me = this;
3098
+ checkbox.onchange = function () {
3099
+ me._update(this.checked, path);
3100
+ };
3101
+
3102
+ const label = this._makeLabel(path[path.length - 1], path);
3103
+ this._makeItem(path, label, checkbox);
3104
+ }
3105
+
3106
+ /**
3107
+ * make a text input field for string options.
3108
+ * @param {number} defaultValue
3109
+ * @param {number} value
3110
+ * @param {Array} path | where to look for the actual option
3111
+ * @private
3112
+ */
3113
+ _makeTextInput(defaultValue, value, path) {
3114
+ const checkbox = document.createElement("input");
3115
+ checkbox.type = "text";
3116
+ checkbox.className = "vis-configuration vis-config-text";
3117
+ checkbox.value = value;
3118
+ if (value !== defaultValue) {
3119
+ this.changedOptions.push({ path: path, value: value });
3120
+ }
3121
+
3122
+ const me = this;
3123
+ checkbox.onchange = function () {
3124
+ me._update(this.value, path);
3125
+ };
3126
+
3127
+ const label = this._makeLabel(path[path.length - 1], path);
3128
+ this._makeItem(path, label, checkbox);
3129
+ }
3130
+
3131
+ /**
3132
+ * make a color field with a color picker for color fields
3133
+ * @param {Array.<number>} arr
3134
+ * @param {number} value
3135
+ * @param {Array} path | where to look for the actual option
3136
+ * @private
3137
+ */
3138
+ _makeColorField(arr, value, path) {
3139
+ const defaultColor = arr[1];
3140
+ const div = document.createElement("div");
3141
+ value = value === undefined ? defaultColor : value;
3142
+
3143
+ if (value !== "none") {
3144
+ div.className = "vis-configuration vis-config-colorBlock";
3145
+ div.style.backgroundColor = value;
3146
+ } else {
3147
+ div.className = "vis-configuration vis-config-colorBlock none";
3148
+ }
3149
+
3150
+ value = value === undefined ? defaultColor : value;
3151
+ div.onclick = () => {
3152
+ this._showColorPicker(value, div, path);
3153
+ };
3154
+
3155
+ const label = this._makeLabel(path[path.length - 1], path);
3156
+ this._makeItem(path, label, div);
3157
+ }
3158
+
3159
+ /**
3160
+ * used by the color buttons to call the color picker.
3161
+ * @param {number} value
3162
+ * @param {HTMLElement} div
3163
+ * @param {Array} path | where to look for the actual option
3164
+ * @private
3165
+ */
3166
+ _showColorPicker(value, div, path) {
3167
+ // clear the callback from this div
3168
+ div.onclick = function () {};
3169
+
3170
+ this.colorPicker.insertTo(div);
3171
+ this.colorPicker.show();
3172
+
3173
+ this.colorPicker.setColor(value);
3174
+ this.colorPicker.setUpdateCallback((color) => {
3175
+ const colorString =
3176
+ "rgba(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")";
3177
+ div.style.backgroundColor = colorString;
3178
+ this._update(colorString, path);
3179
+ });
3180
+
3181
+ // on close of the colorpicker, restore the callback.
3182
+ this.colorPicker.setCloseCallback(() => {
3183
+ div.onclick = () => {
3184
+ this._showColorPicker(value, div, path);
3185
+ };
3186
+ });
3187
+ }
3188
+
3189
+ /**
3190
+ * parse an object and draw the correct items
3191
+ * @param {object} obj
3192
+ * @param {Array} [path] | where to look for the actual option
3193
+ * @param {boolean} [checkOnly]
3194
+ * @returns {boolean}
3195
+ * @private
3196
+ */
3197
+ _handleObject(obj, path = [], checkOnly = false) {
3198
+ let show = false;
3199
+ const filter = this.options.filter;
3200
+ let visibleInSet = false;
3201
+ for (const subObj in obj) {
3202
+ if (Object.prototype.hasOwnProperty.call(obj, subObj)) {
3203
+ show = true;
3204
+ const item = obj[subObj];
3205
+ const newPath = copyAndExtendArray(path, subObj);
3206
+ if (typeof filter === "function") {
3207
+ show = filter(subObj, path);
3208
+
3209
+ // if needed we must go deeper into the object.
3210
+ if (show === false) {
3211
+ if (
3212
+ !Array.isArray(item) &&
3213
+ typeof item !== "string" &&
3214
+ typeof item !== "boolean" &&
3215
+ item instanceof Object
3216
+ ) {
3217
+ this.allowCreation = false;
3218
+ show = this._handleObject(item, newPath, true);
3219
+ this.allowCreation = checkOnly === false;
3220
+ }
3221
+ }
3222
+ }
3223
+
3224
+ if (show !== false) {
3225
+ visibleInSet = true;
3226
+ const value = this._getValue(newPath);
3227
+
3228
+ if (Array.isArray(item)) {
3229
+ this._handleArray(item, value, newPath);
3230
+ } else if (typeof item === "string") {
3231
+ this._makeTextInput(item, value, newPath);
3232
+ } else if (typeof item === "boolean") {
3233
+ this._makeCheckbox(item, value, newPath);
3234
+ } else if (item instanceof Object) {
3235
+ // skip the options that are not enabled
3236
+ if (!this.hideOption(path, subObj, this.moduleOptions)) {
3237
+ // initially collapse options with an disabled enabled option.
3238
+ if (item.enabled !== undefined) {
3239
+ const enabledPath = copyAndExtendArray(newPath, "enabled");
3240
+ const enabledValue = this._getValue(enabledPath);
3241
+ if (enabledValue === true) {
3242
+ const label = this._makeLabel(subObj, newPath, true);
3243
+ this._makeItem(newPath, label);
3244
+ visibleInSet =
3245
+ this._handleObject(item, newPath) || visibleInSet;
3246
+ } else {
3247
+ this._makeCheckbox(item, enabledValue, newPath);
3248
+ }
3249
+ } else {
3250
+ const label = this._makeLabel(subObj, newPath, true);
3251
+ this._makeItem(newPath, label);
3252
+ visibleInSet =
3253
+ this._handleObject(item, newPath) || visibleInSet;
3254
+ }
3255
+ }
3256
+ } else {
3257
+ console.error("dont know how to handle", item, subObj, newPath);
3258
+ }
3259
+ }
3260
+ }
3261
+ }
3262
+ return visibleInSet;
3263
+ }
3264
+
3265
+ /**
3266
+ * handle the array type of option
3267
+ * @param {Array.<number>} arr
3268
+ * @param {number} value
3269
+ * @param {Array} path | where to look for the actual option
3270
+ * @private
3271
+ */
3272
+ _handleArray(arr, value, path) {
3273
+ if (typeof arr[0] === "string" && arr[0] === "color") {
3274
+ this._makeColorField(arr, value, path);
3275
+ if (arr[1] !== value) {
3276
+ this.changedOptions.push({ path: path, value: value });
3277
+ }
3278
+ } else if (typeof arr[0] === "string") {
3279
+ this._makeDropdown(arr, value, path);
3280
+ if (arr[0] !== value) {
3281
+ this.changedOptions.push({ path: path, value: value });
3282
+ }
3283
+ } else if (typeof arr[0] === "number") {
3284
+ this._makeRange(arr, value, path);
3285
+ if (arr[0] !== value) {
3286
+ this.changedOptions.push({ path: path, value: Number(value) });
3287
+ }
3288
+ }
3289
+ }
3290
+
3291
+ /**
3292
+ * called to update the network with the new settings.
3293
+ * @param {number} value
3294
+ * @param {Array} path | where to look for the actual option
3295
+ * @private
3296
+ */
3297
+ _update(value, path) {
3298
+ const options = this._constructOptions(value, path);
3299
+
3300
+ if (
3301
+ this.parent.body &&
3302
+ this.parent.body.emitter &&
3303
+ this.parent.body.emitter.emit
3304
+ ) {
3305
+ this.parent.body.emitter.emit("configChange", options);
3306
+ }
3307
+ this.initialized = true;
3308
+ this.parent.setOptions(options);
3309
+ }
3310
+
3311
+ /**
3312
+ *
3313
+ * @param {string | boolean} value
3314
+ * @param {Array.<string>} path
3315
+ * @param {{}} optionsObj
3316
+ * @returns {{}}
3317
+ * @private
3318
+ */
3319
+ _constructOptions(value, path, optionsObj = {}) {
3320
+ let pointer = optionsObj;
3321
+
3322
+ // when dropdown boxes can be string or boolean, we typecast it into correct types
3323
+ value = value === "true" ? true : value;
3324
+ value = value === "false" ? false : value;
3325
+
3326
+ for (let i = 0; i < path.length; i++) {
3327
+ if (path[i] !== "global") {
3328
+ if (pointer[path[i]] === undefined) {
3329
+ pointer[path[i]] = {};
3330
+ }
3331
+ if (i !== path.length - 1) {
3332
+ pointer = pointer[path[i]];
3333
+ } else {
3334
+ pointer[path[i]] = value;
3335
+ }
3336
+ }
3337
+ }
3338
+ return optionsObj;
3339
+ }
3340
+
3341
+ /**
3342
+ * @private
3343
+ */
3344
+ _printOptions() {
3345
+ const options = this.getOptions();
3346
+
3347
+ while (this.optionsContainer.firstChild) {
3348
+ this.optionsContainer.removeChild(this.optionsContainer.firstChild);
3349
+ }
3350
+ this.optionsContainer.appendChild(
3351
+ wrapInTag("pre", "const options = " + JSON.stringify(options, null, 2)),
3352
+ );
3353
+ }
3354
+
3355
+ /**
3356
+ *
3357
+ * @returns {{}} options
3358
+ */
3359
+ getOptions() {
3360
+ const options = {};
3361
+ for (let i = 0; i < this.changedOptions.length; i++) {
3362
+ this._constructOptions(
3363
+ this.changedOptions[i].value,
3364
+ this.changedOptions[i].path,
3365
+ options,
3366
+ );
3367
+ }
3368
+ return options;
3369
+ }
3370
+ };
3371
+
3372
+ /**
3373
+ * Popup is a class to create a popup window with some text
3374
+ */
3375
+ let Popup$1 = class Popup {
3376
+ /**
3377
+ * @param {Element} container The container object.
3378
+ * @param {string} overflowMethod How the popup should act to overflowing ('flip' or 'cap')
3379
+ */
3380
+ constructor(container, overflowMethod) {
3381
+ this.container = container;
3382
+ this.overflowMethod = overflowMethod || "cap";
3383
+
3384
+ this.x = 0;
3385
+ this.y = 0;
3386
+ this.padding = 5;
3387
+ this.hidden = false;
3388
+
3389
+ // create the frame
3390
+ this.frame = document.createElement("div");
3391
+ this.frame.className = "vis-tooltip";
3392
+ this.container.appendChild(this.frame);
3393
+ }
3394
+
3395
+ /**
3396
+ * @param {number} x Horizontal position of the popup window
3397
+ * @param {number} y Vertical position of the popup window
3398
+ */
3399
+ setPosition(x, y) {
3400
+ this.x = parseInt(x);
3401
+ this.y = parseInt(y);
3402
+ }
3403
+
3404
+ /**
3405
+ * Set the content for the popup window. This can be HTML code or text.
3406
+ * @param {string | Element} content
3407
+ */
3408
+ setText(content) {
3409
+ if (content instanceof Element) {
3410
+ while (this.frame.firstChild) {
3411
+ this.frame.removeChild(this.frame.firstChild);
3412
+ }
3413
+ this.frame.appendChild(content);
3414
+ } else {
3415
+ // String containing literal text, element has to be used for HTML due to
3416
+ // XSS risks associated with innerHTML (i.e. prevent XSS by accident).
3417
+ this.frame.innerText = content;
3418
+ }
3419
+ }
3420
+
3421
+ /**
3422
+ * Show the popup window
3423
+ * @param {boolean} [doShow] Show or hide the window
3424
+ */
3425
+ show(doShow) {
3426
+ if (doShow === undefined) {
3427
+ doShow = true;
3428
+ }
3429
+
3430
+ if (doShow === true) {
3431
+ const height = this.frame.clientHeight;
3432
+ const width = this.frame.clientWidth;
3433
+ const maxHeight = this.frame.parentNode.clientHeight;
3434
+ const maxWidth = this.frame.parentNode.clientWidth;
3435
+
3436
+ let left = 0,
3437
+ top = 0;
3438
+
3439
+ if (this.overflowMethod == "flip") {
3440
+ let isLeft = false,
3441
+ isTop = true; // Where around the position it's located
3442
+
3443
+ if (this.y - height < this.padding) {
3444
+ isTop = false;
3445
+ }
3446
+
3447
+ if (this.x + width > maxWidth - this.padding) {
3448
+ isLeft = true;
3449
+ }
3450
+
3451
+ if (isLeft) {
3452
+ left = this.x - width;
3453
+ } else {
3454
+ left = this.x;
3455
+ }
3456
+
3457
+ if (isTop) {
3458
+ top = this.y - height;
3459
+ } else {
3460
+ top = this.y;
3461
+ }
3462
+ } else {
3463
+ top = this.y - height;
3464
+ if (top + height + this.padding > maxHeight) {
3465
+ top = maxHeight - height - this.padding;
3466
+ }
3467
+ if (top < this.padding) {
3468
+ top = this.padding;
3469
+ }
3470
+
3471
+ left = this.x;
3472
+ if (left + width + this.padding > maxWidth) {
3473
+ left = maxWidth - width - this.padding;
3474
+ }
3475
+ if (left < this.padding) {
3476
+ left = this.padding;
3477
+ }
3478
+ }
3479
+
3480
+ this.frame.style.left = left + "px";
3481
+ this.frame.style.top = top + "px";
3482
+ this.frame.style.visibility = "visible";
3483
+ this.hidden = false;
3484
+ } else {
3485
+ this.hide();
3486
+ }
3487
+ }
3488
+
3489
+ /**
3490
+ * Hide the popup window
3491
+ */
3492
+ hide() {
3493
+ this.hidden = true;
3494
+ this.frame.style.left = "0";
3495
+ this.frame.style.top = "0";
3496
+ this.frame.style.visibility = "hidden";
3497
+ }
3498
+
3499
+ /**
3500
+ * Remove the popup window
3501
+ */
3502
+ destroy() {
3503
+ this.frame.parentNode.removeChild(this.frame); // Remove element from DOM
3504
+ }
3505
+ };
3506
+
3507
+ let errorFound = false;
3508
+ let allOptions;
3509
+
3510
+ const VALIDATOR_PRINT_STYLE$1 = "background: #FFeeee; color: #dd0000";
3511
+
3512
+ /**
3513
+ * Used to validate options.
3514
+ */
3515
+ let Validator$1 = class Validator {
3516
+ /**
3517
+ * Main function to be called
3518
+ * @param {object} options
3519
+ * @param {object} referenceOptions
3520
+ * @param {object} subObject
3521
+ * @returns {boolean}
3522
+ * @static
3523
+ */
3524
+ static validate(options, referenceOptions, subObject) {
3525
+ errorFound = false;
3526
+ allOptions = referenceOptions;
3527
+ let usedOptions = referenceOptions;
3528
+ if (subObject !== undefined) {
3529
+ usedOptions = referenceOptions[subObject];
3530
+ }
3531
+ Validator.parse(options, usedOptions, []);
3532
+ return errorFound;
3533
+ }
3534
+
3535
+ /**
3536
+ * Will traverse an object recursively and check every value
3537
+ * @param {object} options
3538
+ * @param {object} referenceOptions
3539
+ * @param {Array} path | where to look for the actual option
3540
+ * @static
3541
+ */
3542
+ static parse(options, referenceOptions, path) {
3543
+ for (const option in options) {
3544
+ if (Object.prototype.hasOwnProperty.call(options, option)) {
3545
+ Validator.check(option, options, referenceOptions, path);
3546
+ }
3547
+ }
3548
+ }
3549
+
3550
+ /**
3551
+ * Check every value. If the value is an object, call the parse function on that object.
3552
+ * @param {string} option
3553
+ * @param {object} options
3554
+ * @param {object} referenceOptions
3555
+ * @param {Array} path | where to look for the actual option
3556
+ * @static
3557
+ */
3558
+ static check(option, options, referenceOptions, path) {
3559
+ if (
3560
+ referenceOptions[option] === undefined &&
3561
+ referenceOptions.__any__ === undefined
3562
+ ) {
3563
+ Validator.getSuggestion(option, referenceOptions, path);
3564
+ return;
3565
+ }
3566
+
3567
+ let referenceOption = option;
3568
+ let is_object = true;
3569
+
3570
+ if (
3571
+ referenceOptions[option] === undefined &&
3572
+ referenceOptions.__any__ !== undefined
3573
+ ) {
3574
+ // NOTE: This only triggers if the __any__ is in the top level of the options object.
3575
+ // THAT'S A REALLY BAD PLACE TO ALLOW IT!!!!
3576
+ // TODO: Examine if needed, remove if possible
3577
+
3578
+ // __any__ is a wildcard. Any value is accepted and will be further analysed by reference.
3579
+ referenceOption = "__any__";
3580
+
3581
+ // if the any-subgroup is not a predefined object in the configurator,
3582
+ // we do not look deeper into the object.
3583
+ is_object = Validator.getType(options[option]) === "object";
3584
+ }
3585
+
3586
+ let refOptionObj = referenceOptions[referenceOption];
3587
+ if (is_object && refOptionObj.__type__ !== undefined) {
3588
+ refOptionObj = refOptionObj.__type__;
3589
+ }
3590
+
3591
+ Validator.checkFields(
3592
+ option,
3593
+ options,
3594
+ referenceOptions,
3595
+ referenceOption,
3596
+ refOptionObj,
3597
+ path,
3598
+ );
3599
+ }
3600
+
3601
+ /**
3602
+ *
3603
+ * @param {string} option | the option property
3604
+ * @param {object} options | The supplied options object
3605
+ * @param {object} referenceOptions | The reference options containing all options and their allowed formats
3606
+ * @param {string} referenceOption | Usually this is the same as option, except when handling an __any__ tag.
3607
+ * @param {string} refOptionObj | This is the type object from the reference options
3608
+ * @param {Array} path | where in the object is the option
3609
+ * @static
3610
+ */
3611
+ static checkFields(
3612
+ option,
3613
+ options,
3614
+ referenceOptions,
3615
+ referenceOption,
3616
+ refOptionObj,
3617
+ path,
3618
+ ) {
3619
+ const log = function (message) {
3620
+ console.error(
3621
+ "%c" + message + Validator.printLocation(path, option),
3622
+ VALIDATOR_PRINT_STYLE$1,
3623
+ );
3624
+ };
3625
+
3626
+ const optionType = Validator.getType(options[option]);
3627
+ const refOptionType = refOptionObj[optionType];
3628
+
3629
+ if (refOptionType !== undefined) {
3630
+ // if the type is correct, we check if it is supposed to be one of a few select values
3631
+ if (
3632
+ Validator.getType(refOptionType) === "array" &&
3633
+ refOptionType.indexOf(options[option]) === -1
3634
+ ) {
3635
+ log(
3636
+ 'Invalid option detected in "' +
3637
+ option +
3638
+ '".' +
3639
+ " Allowed values are:" +
3640
+ Validator.print(refOptionType) +
3641
+ ' not "' +
3642
+ options[option] +
3643
+ '". ',
3644
+ );
3645
+ errorFound = true;
3646
+ } else if (optionType === "object" && referenceOption !== "__any__") {
3647
+ path = copyAndExtendArray(path, option);
3648
+ Validator.parse(
3649
+ options[option],
3650
+ referenceOptions[referenceOption],
3651
+ path,
3652
+ );
3653
+ }
3654
+ } else if (refOptionObj["any"] === undefined) {
3655
+ // type of the field is incorrect and the field cannot be any
3656
+ log(
3657
+ 'Invalid type received for "' +
3658
+ option +
3659
+ '". Expected: ' +
3660
+ Validator.print(Object.keys(refOptionObj)) +
3661
+ ". Received [" +
3662
+ optionType +
3663
+ '] "' +
3664
+ options[option] +
3665
+ '"',
3666
+ );
3667
+ errorFound = true;
3668
+ }
3669
+ }
3670
+
3671
+ /**
3672
+ *
3673
+ * @param {object | boolean | number | string | Array.<number> | Date | Node | Moment | undefined | null} object
3674
+ * @returns {string}
3675
+ * @static
3676
+ */
3677
+ static getType(object) {
3678
+ const type = typeof object;
3679
+
3680
+ if (type === "object") {
3681
+ if (object === null) {
3682
+ return "null";
3683
+ }
3684
+ if (object instanceof Boolean) {
3685
+ return "boolean";
3686
+ }
3687
+ if (object instanceof Number) {
3688
+ return "number";
3689
+ }
3690
+ if (object instanceof String) {
3691
+ return "string";
3692
+ }
3693
+ if (Array.isArray(object)) {
3694
+ return "array";
3695
+ }
3696
+ if (object instanceof Date) {
3697
+ return "date";
3698
+ }
3699
+ if (object.nodeType !== undefined) {
3700
+ return "dom";
3701
+ }
3702
+ if (object._isAMomentObject === true) {
3703
+ return "moment";
3704
+ }
3705
+ return "object";
3706
+ } else if (type === "number") {
3707
+ return "number";
3708
+ } else if (type === "boolean") {
3709
+ return "boolean";
3710
+ } else if (type === "string") {
3711
+ return "string";
3712
+ } else if (type === undefined) {
3713
+ return "undefined";
3714
+ }
3715
+ return type;
3716
+ }
3717
+
3718
+ /**
3719
+ * @param {string} option
3720
+ * @param {object} options
3721
+ * @param {Array.<string>} path
3722
+ * @static
3723
+ */
3724
+ static getSuggestion(option, options, path) {
3725
+ const localSearch = Validator.findInOptions(option, options, path, false);
3726
+ const globalSearch = Validator.findInOptions(option, allOptions, [], true);
3727
+
3728
+ const localSearchThreshold = 8;
3729
+ const globalSearchThreshold = 4;
3730
+
3731
+ let msg;
3732
+ if (localSearch.indexMatch !== undefined) {
3733
+ msg =
3734
+ " in " +
3735
+ Validator.printLocation(localSearch.path, option, "") +
3736
+ 'Perhaps it was incomplete? Did you mean: "' +
3737
+ localSearch.indexMatch +
3738
+ '"?\n\n';
3739
+ } else if (
3740
+ globalSearch.distance <= globalSearchThreshold &&
3741
+ localSearch.distance > globalSearch.distance
3742
+ ) {
3743
+ msg =
3744
+ " in " +
3745
+ Validator.printLocation(localSearch.path, option, "") +
3746
+ "Perhaps it was misplaced? Matching option found at: " +
3747
+ Validator.printLocation(
3748
+ globalSearch.path,
3749
+ globalSearch.closestMatch,
3750
+ "",
3751
+ );
3752
+ } else if (localSearch.distance <= localSearchThreshold) {
3753
+ msg =
3754
+ '. Did you mean "' +
3755
+ localSearch.closestMatch +
3756
+ '"?' +
3757
+ Validator.printLocation(localSearch.path, option);
3758
+ } else {
3759
+ msg =
3760
+ ". Did you mean one of these: " +
3761
+ Validator.print(Object.keys(options)) +
3762
+ Validator.printLocation(path, option);
3763
+ }
3764
+
3765
+ console.error(
3766
+ '%cUnknown option detected: "' + option + '"' + msg,
3767
+ VALIDATOR_PRINT_STYLE$1,
3768
+ );
3769
+ errorFound = true;
3770
+ }
3771
+
3772
+ /**
3773
+ * traverse the options in search for a match.
3774
+ * @param {string} option
3775
+ * @param {object} options
3776
+ * @param {Array} path | where to look for the actual option
3777
+ * @param {boolean} [recursive]
3778
+ * @returns {{closestMatch: string, path: Array, distance: number}}
3779
+ * @static
3780
+ */
3781
+ static findInOptions(option, options, path, recursive = false) {
3782
+ let min = 1e9;
3783
+ let closestMatch = "";
3784
+ let closestMatchPath = [];
3785
+ const lowerCaseOption = option.toLowerCase();
3786
+ let indexMatch = undefined;
3787
+ // oxlint-disable-next-line guard-for-in -- Options use prototype inheritance to override defaults, parent options, etc.
3788
+ for (const op in options) {
3789
+ let distance;
3790
+ if (options[op].__type__ !== undefined && recursive === true) {
3791
+ const result = Validator.findInOptions(
3792
+ option,
3793
+ options[op],
3794
+ copyAndExtendArray(path, op),
3795
+ );
3796
+ if (min > result.distance) {
3797
+ closestMatch = result.closestMatch;
3798
+ closestMatchPath = result.path;
3799
+ min = result.distance;
3800
+ indexMatch = result.indexMatch;
3801
+ }
3802
+ } else {
3803
+ if (op.toLowerCase().indexOf(lowerCaseOption) !== -1) {
3804
+ indexMatch = op;
3805
+ }
3806
+ distance = Validator.levenshteinDistance(option, op);
3807
+ if (min > distance) {
3808
+ closestMatch = op;
3809
+ closestMatchPath = copyArray(path);
3810
+ min = distance;
3811
+ }
3812
+ }
3813
+ }
3814
+ return {
3815
+ closestMatch: closestMatch,
3816
+ path: closestMatchPath,
3817
+ distance: min,
3818
+ indexMatch: indexMatch,
3819
+ };
3820
+ }
3821
+
3822
+ /**
3823
+ * @param {Array.<string>} path
3824
+ * @param {object} option
3825
+ * @param {string} prefix
3826
+ * @returns {string}
3827
+ * @static
3828
+ */
3829
+ static printLocation(path, option, prefix = "Problem value found at: \n") {
3830
+ let str = "\n\n" + prefix + "options = {\n";
3831
+ for (let i = 0; i < path.length; i++) {
3832
+ for (let j = 0; j < i + 1; j++) {
3833
+ str += " ";
3834
+ }
3835
+ str += path[i] + ": {\n";
3836
+ }
3837
+ for (let j = 0; j < path.length + 1; j++) {
3838
+ str += " ";
3839
+ }
3840
+ str += option + "\n";
3841
+ for (let i = 0; i < path.length + 1; i++) {
3842
+ for (let j = 0; j < path.length - i; j++) {
3843
+ str += " ";
3844
+ }
3845
+ str += "}\n";
3846
+ }
3847
+ return str + "\n\n";
3848
+ }
3849
+
3850
+ /**
3851
+ * @param {object} options
3852
+ * @returns {string}
3853
+ * @static
3854
+ */
3855
+ static print(options) {
3856
+ return JSON.stringify(options)
3857
+ .replace(/(")|(\[)|(\])|(,"__type__")/g, "")
3858
+ .replace(/(,)/g, ", ");
3859
+ }
3860
+
3861
+ /**
3862
+ * Compute the edit distance between the two given strings
3863
+ * http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#JavaScript
3864
+ *
3865
+ * Copyright (c) 2011 Andrei Mackenzie
3866
+ *
3867
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3868
+ *
3869
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
3870
+ *
3871
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3872
+ * @param {string} a
3873
+ * @param {string} b
3874
+ * @returns {Array.<Array.<number>>}}
3875
+ * @static
3876
+ */
3877
+ static levenshteinDistance(a, b) {
3878
+ if (a.length === 0) return b.length;
3879
+ if (b.length === 0) return a.length;
3880
+
3881
+ const matrix = [];
3882
+
3883
+ // increment along the first column of each row
3884
+ let i;
3885
+ for (i = 0; i <= b.length; i++) {
3886
+ matrix[i] = [i];
3887
+ }
3888
+
3889
+ // increment each column in the first row
3890
+ let j;
3891
+ for (j = 0; j <= a.length; j++) {
3892
+ matrix[0][j] = j;
3893
+ }
3894
+
3895
+ // Fill in the rest of the matrix
3896
+ for (i = 1; i <= b.length; i++) {
3897
+ for (j = 1; j <= a.length; j++) {
3898
+ if (b.charAt(i - 1) == a.charAt(j - 1)) {
3899
+ matrix[i][j] = matrix[i - 1][j - 1];
3900
+ } else {
3901
+ matrix[i][j] = Math.min(
3902
+ matrix[i - 1][j - 1] + 1, // substitution
3903
+ Math.min(
3904
+ matrix[i][j - 1] + 1, // insertion
3905
+ matrix[i - 1][j] + 1,
3906
+ ),
3907
+ ); // deletion
3908
+ }
3909
+ }
3910
+ }
3911
+
3912
+ return matrix[b.length][a.length];
3913
+ }
3914
+ };
3915
+
3916
+ const Activator = Activator$1;
3917
+ const ColorPicker = ColorPicker$1;
3918
+ const Configurator = Configurator$1;
3919
+ const Hammer = Hammer$1;
3920
+ const Popup = Popup$1;
3921
+ const VALIDATOR_PRINT_STYLE = VALIDATOR_PRINT_STYLE$1;
3922
+ const Validator = Validator$1;
3923
+
3924
+ export { Activator, Alea, ColorPicker, Configurator, DELETE, HSVToHex, HSVToRGB, Hammer, Popup, RGBToHSV, RGBToHex, VALIDATOR_PRINT_STYLE, Validator, addClassName, addCssText, binarySearchCustom, binarySearchValue, bridgeObject, copyAndExtendArray, copyArray, deepExtend, deepObjectAssign, easingFunctions, equalArray, extend, fillIfDefined, forEach, getAbsoluteLeft, getAbsoluteRight, getAbsoluteTop, getScrollBarWidth, getTarget, getType, hasParent, hexToHSV, hexToRGB, insertSort, isDate, isNumber, isObject, isString, isValidHex, isValidRGB, isValidRGBA, mergeOptions, option, overrideOpacity, parseColor, preventDefault, pureDeepObjectAssign, recursiveDOMDelete, removeClassName, removeCssText, selectiveBridgeObject, selectiveDeepExtend, selectiveExtend, selectiveNotDeepExtend, throttle, toArray, topMost, updateProperty };
3925
+ //# sourceMappingURL=vis-util.mjs.map