vis-util 5.0.3 → 5.0.5

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.
@@ -4,8 +4,8 @@
4
4
  *
5
5
  * utilitie collection for visjs
6
6
  *
7
- * @version 5.0.3
8
- * @date 2022-03-04T18:53:16.725Z
7
+ * @version 5.0.5
8
+ * @date 2023-10-03T18:47:58.061Z
9
9
  *
10
10
  * @copyright (c) 2011-2017 Almende B.V, http://almende.com
11
11
  * @copyright (c) 2017-2019 visjs contributors, https://github.com/visjs
@@ -29,11 +29,6 @@
29
29
  typeof define === 'function' && define.amd ? define(['exports', 'component-emitter', '@egjs/hammerjs'], factory) :
30
30
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vis = global.vis || {}, global.Emitter, global.Hammer));
31
31
  })(this, (function (exports, Emitter, RealHammer) {
32
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
33
-
34
- var Emitter__default = /*#__PURE__*/_interopDefaultLegacy(Emitter);
35
- var RealHammer__default = /*#__PURE__*/_interopDefaultLegacy(RealHammer);
36
-
37
32
  /**
38
33
  * Use this symbol to delete properies in deepObjectAssign.
39
34
  */
@@ -76,6 +71,10 @@
76
71
  }
77
72
  const a = values[0];
78
73
  const b = values[1];
74
+ if (a instanceof Date && b instanceof Date) {
75
+ a.setTime(b.getTime());
76
+ return a;
77
+ }
79
78
  for (const prop of Reflect.ownKeys(b)) {
80
79
  if (!Object.prototype.propertyIsEnumerable.call(b, prop)) ;
81
80
  else if (b[prop] === DELETE) {
@@ -106,6 +105,9 @@
106
105
  return a.map((value) => clone(value));
107
106
  }
108
107
  else if (typeof a === "object" && a !== null) {
108
+ if (a instanceof Date) {
109
+ return new Date(a.getTime());
110
+ }
109
111
  return deepObjectAssignNonentry({}, a);
110
112
  }
111
113
  else {
@@ -246,7 +248,7 @@
246
248
 
247
249
  const Hammer$1 =
248
250
  typeof window !== "undefined"
249
- ? window.Hammer || RealHammer__default["default"]
251
+ ? window.Hammer || RealHammer
250
252
  : function () {
251
253
  // hammer.js is only available in a browser, not in node.js. Replacing it with a mock object.
252
254
  return hammerMock();
@@ -331,7 +333,7 @@
331
333
  }
332
334
 
333
335
  // turn into an event emitter
334
- Emitter__default["default"](Activator$1.prototype);
336
+ Emitter(Activator$1.prototype);
335
337
 
336
338
  // The currently active activator
337
339
  Activator$1.current = null;
@@ -1334,29 +1336,21 @@
1334
1336
  const value = maxRGB;
1335
1337
  return { h: hue, s: saturation, v: value };
1336
1338
  }
1337
- const cssUtil = {
1338
- // split a string with css styles into an object with key/values
1339
- split(cssText) {
1340
- const styles = {};
1341
- cssText.split(";").forEach((style) => {
1342
- if (style.trim() != "") {
1343
- const parts = style.split(":");
1344
- const key = parts[0].trim();
1345
- const value = parts[1].trim();
1346
- styles[key] = value;
1347
- }
1348
- });
1349
- return styles;
1350
- },
1351
- // build a css text string from an object with key/values
1352
- join(styles) {
1353
- return Object.keys(styles)
1354
- .map(function (key) {
1355
- return key + ": " + styles[key];
1356
- })
1357
- .join("; ");
1358
- },
1359
- };
1339
+ /**
1340
+ * Split a string with css styles into an object with key/values.
1341
+ *
1342
+ * @param cssText - CSS source code to split into key/value object.
1343
+ * @returns Key/value object corresponding to {@link cssText}.
1344
+ */
1345
+ function splitCSSText(cssText) {
1346
+ const tmpEllement = document.createElement("div");
1347
+ const styles = {};
1348
+ tmpEllement.style.cssText = cssText;
1349
+ for (let i = 0; i < tmpEllement.style.length; ++i) {
1350
+ styles[tmpEllement.style[i]] = tmpEllement.style.getPropertyValue(tmpEllement.style[i]);
1351
+ }
1352
+ return styles;
1353
+ }
1360
1354
  /**
1361
1355
  * Append a string with css styles to an element.
1362
1356
  *
@@ -1364,13 +1358,10 @@
1364
1358
  * @param cssText - The styles to be appended.
1365
1359
  */
1366
1360
  function addCssText(element, cssText) {
1367
- const currentStyles = cssUtil.split(element.style.cssText);
1368
- const newStyles = cssUtil.split(cssText);
1369
- const styles = {
1370
- ...currentStyles,
1371
- ...newStyles,
1372
- };
1373
- element.style.cssText = cssUtil.join(styles);
1361
+ const cssStyle = splitCSSText(cssText);
1362
+ for (const [key, value] of Object.entries(cssStyle)) {
1363
+ element.style.setProperty(key, value);
1364
+ }
1374
1365
  }
1375
1366
  /**
1376
1367
  * Remove a string with css styles from an element.
@@ -1379,14 +1370,10 @@
1379
1370
  * @param cssText - The styles to be removed.
1380
1371
  */
1381
1372
  function removeCssText(element, cssText) {
1382
- const styles = cssUtil.split(element.style.cssText);
1383
- const removeStyles = cssUtil.split(cssText);
1384
- for (const key in removeStyles) {
1385
- if (Object.prototype.hasOwnProperty.call(removeStyles, key)) {
1386
- delete styles[key];
1387
- }
1373
+ const cssStyle = splitCSSText(cssText);
1374
+ for (const key of Object.keys(cssStyle)) {
1375
+ element.style.removeProperty(key);
1388
1376
  }
1389
- element.style.cssText = cssUtil.join(styles);
1390
1377
  }
1391
1378
  /**
1392
1379
  * Convert HSV \<0, 1\> into RGB color object.
@@ -2107,7 +2094,7 @@
2107
2094
  /**
2108
2095
  * @param {number} [pixelRatio=1]
2109
2096
  */
2110
- class ColorPicker$1 {
2097
+ let ColorPicker$1 = class ColorPicker {
2111
2098
  /**
2112
2099
  * @param {number} [pixelRatio=1]
2113
2100
  */
@@ -2752,7 +2739,7 @@
2752
2739
  this.color.a +
2753
2740
  ")";
2754
2741
  }
2755
- }
2742
+ };
2756
2743
 
2757
2744
  /**
2758
2745
  * Wrap given text (last argument) in HTML elements (all preceding arguments).
@@ -2781,7 +2768,7 @@
2781
2768
  *
2782
2769
  * The options are matched with their counterparts in each of the modules and the values used in the configuration are
2783
2770
  */
2784
- class Configurator$1 {
2771
+ let Configurator$1 = class Configurator {
2785
2772
  /**
2786
2773
  * @param {object} parentModule | the location where parentModule.setOptions() can be called
2787
2774
  * @param {object} defaultContainer | the default container of the module
@@ -3550,12 +3537,12 @@
3550
3537
  }
3551
3538
  return options;
3552
3539
  }
3553
- }
3540
+ };
3554
3541
 
3555
3542
  /**
3556
3543
  * Popup is a class to create a popup window with some text
3557
3544
  */
3558
- class Popup$1 {
3545
+ let Popup$1 = class Popup {
3559
3546
  /**
3560
3547
  * @param {Element} container The container object.
3561
3548
  * @param {string} overflowMethod How the popup should act to overflowing ('flip' or 'cap')
@@ -3687,7 +3674,7 @@
3687
3674
  destroy() {
3688
3675
  this.frame.parentNode.removeChild(this.frame); // Remove element from DOM
3689
3676
  }
3690
- }
3677
+ };
3691
3678
 
3692
3679
  let errorFound = false;
3693
3680
  let allOptions;
@@ -3697,7 +3684,7 @@
3697
3684
  /**
3698
3685
  * Used to validate options.
3699
3686
  */
3700
- class Validator$1 {
3687
+ let Validator$1 = class Validator {
3701
3688
  /**
3702
3689
  * Main function to be called
3703
3690
  *
@@ -3714,7 +3701,7 @@
3714
3701
  if (subObject !== undefined) {
3715
3702
  usedOptions = referenceOptions[subObject];
3716
3703
  }
3717
- Validator$1.parse(options, usedOptions, []);
3704
+ Validator.parse(options, usedOptions, []);
3718
3705
  return errorFound;
3719
3706
  }
3720
3707
 
@@ -3729,7 +3716,7 @@
3729
3716
  static parse(options, referenceOptions, path) {
3730
3717
  for (const option in options) {
3731
3718
  if (Object.prototype.hasOwnProperty.call(options, option)) {
3732
- Validator$1.check(option, options, referenceOptions, path);
3719
+ Validator.check(option, options, referenceOptions, path);
3733
3720
  }
3734
3721
  }
3735
3722
  }
@@ -3748,7 +3735,7 @@
3748
3735
  referenceOptions[option] === undefined &&
3749
3736
  referenceOptions.__any__ === undefined
3750
3737
  ) {
3751
- Validator$1.getSuggestion(option, referenceOptions, path);
3738
+ Validator.getSuggestion(option, referenceOptions, path);
3752
3739
  return;
3753
3740
  }
3754
3741
 
@@ -3768,7 +3755,7 @@
3768
3755
 
3769
3756
  // if the any-subgroup is not a predefined object in the configurator,
3770
3757
  // we do not look deeper into the object.
3771
- is_object = Validator$1.getType(options[option]) === "object";
3758
+ is_object = Validator.getType(options[option]) === "object";
3772
3759
  }
3773
3760
 
3774
3761
  let refOptionObj = referenceOptions[referenceOption];
@@ -3776,7 +3763,7 @@
3776
3763
  refOptionObj = refOptionObj.__type__;
3777
3764
  }
3778
3765
 
3779
- Validator$1.checkFields(
3766
+ Validator.checkFields(
3780
3767
  option,
3781
3768
  options,
3782
3769
  referenceOptions,
@@ -3806,18 +3793,18 @@
3806
3793
  ) {
3807
3794
  const log = function (message) {
3808
3795
  console.error(
3809
- "%c" + message + Validator$1.printLocation(path, option),
3796
+ "%c" + message + Validator.printLocation(path, option),
3810
3797
  VALIDATOR_PRINT_STYLE$1
3811
3798
  );
3812
3799
  };
3813
3800
 
3814
- const optionType = Validator$1.getType(options[option]);
3801
+ const optionType = Validator.getType(options[option]);
3815
3802
  const refOptionType = refOptionObj[optionType];
3816
3803
 
3817
3804
  if (refOptionType !== undefined) {
3818
3805
  // if the type is correct, we check if it is supposed to be one of a few select values
3819
3806
  if (
3820
- Validator$1.getType(refOptionType) === "array" &&
3807
+ Validator.getType(refOptionType) === "array" &&
3821
3808
  refOptionType.indexOf(options[option]) === -1
3822
3809
  ) {
3823
3810
  log(
@@ -3825,7 +3812,7 @@
3825
3812
  option +
3826
3813
  '".' +
3827
3814
  " Allowed values are:" +
3828
- Validator$1.print(refOptionType) +
3815
+ Validator.print(refOptionType) +
3829
3816
  ' not "' +
3830
3817
  options[option] +
3831
3818
  '". '
@@ -3833,7 +3820,7 @@
3833
3820
  errorFound = true;
3834
3821
  } else if (optionType === "object" && referenceOption !== "__any__") {
3835
3822
  path = copyAndExtendArray(path, option);
3836
- Validator$1.parse(
3823
+ Validator.parse(
3837
3824
  options[option],
3838
3825
  referenceOptions[referenceOption],
3839
3826
  path
@@ -3845,7 +3832,7 @@
3845
3832
  'Invalid type received for "' +
3846
3833
  option +
3847
3834
  '". Expected: ' +
3848
- Validator$1.print(Object.keys(refOptionObj)) +
3835
+ Validator.print(Object.keys(refOptionObj)) +
3849
3836
  ". Received [" +
3850
3837
  optionType +
3851
3838
  '] "' +
@@ -3910,8 +3897,8 @@
3910
3897
  * @static
3911
3898
  */
3912
3899
  static getSuggestion(option, options, path) {
3913
- const localSearch = Validator$1.findInOptions(option, options, path, false);
3914
- const globalSearch = Validator$1.findInOptions(option, allOptions, [], true);
3900
+ const localSearch = Validator.findInOptions(option, options, path, false);
3901
+ const globalSearch = Validator.findInOptions(option, allOptions, [], true);
3915
3902
 
3916
3903
  const localSearchThreshold = 8;
3917
3904
  const globalSearchThreshold = 4;
@@ -3920,7 +3907,7 @@
3920
3907
  if (localSearch.indexMatch !== undefined) {
3921
3908
  msg =
3922
3909
  " in " +
3923
- Validator$1.printLocation(localSearch.path, option, "") +
3910
+ Validator.printLocation(localSearch.path, option, "") +
3924
3911
  'Perhaps it was incomplete? Did you mean: "' +
3925
3912
  localSearch.indexMatch +
3926
3913
  '"?\n\n';
@@ -3930,9 +3917,9 @@
3930
3917
  ) {
3931
3918
  msg =
3932
3919
  " in " +
3933
- Validator$1.printLocation(localSearch.path, option, "") +
3920
+ Validator.printLocation(localSearch.path, option, "") +
3934
3921
  "Perhaps it was misplaced? Matching option found at: " +
3935
- Validator$1.printLocation(
3922
+ Validator.printLocation(
3936
3923
  globalSearch.path,
3937
3924
  globalSearch.closestMatch,
3938
3925
  ""
@@ -3942,12 +3929,12 @@
3942
3929
  '. Did you mean "' +
3943
3930
  localSearch.closestMatch +
3944
3931
  '"?' +
3945
- Validator$1.printLocation(localSearch.path, option);
3932
+ Validator.printLocation(localSearch.path, option);
3946
3933
  } else {
3947
3934
  msg =
3948
3935
  ". Did you mean one of these: " +
3949
- Validator$1.print(Object.keys(options)) +
3950
- Validator$1.printLocation(path, option);
3936
+ Validator.print(Object.keys(options)) +
3937
+ Validator.printLocation(path, option);
3951
3938
  }
3952
3939
 
3953
3940
  console.error(
@@ -3976,7 +3963,7 @@
3976
3963
  for (const op in options) {
3977
3964
  let distance;
3978
3965
  if (options[op].__type__ !== undefined && recursive === true) {
3979
- const result = Validator$1.findInOptions(
3966
+ const result = Validator.findInOptions(
3980
3967
  option,
3981
3968
  options[op],
3982
3969
  copyAndExtendArray(path, op)
@@ -3991,7 +3978,7 @@
3991
3978
  if (op.toLowerCase().indexOf(lowerCaseOption) !== -1) {
3992
3979
  indexMatch = op;
3993
3980
  }
3994
- distance = Validator$1.levenshteinDistance(option, op);
3981
+ distance = Validator.levenshteinDistance(option, op);
3995
3982
  if (min > distance) {
3996
3983
  closestMatch = op;
3997
3984
  closestMatchPath = copyArray(path);
@@ -4100,7 +4087,7 @@
4100
4087
 
4101
4088
  return matrix[b.length][a.length];
4102
4089
  }
4103
- }
4090
+ };
4104
4091
 
4105
4092
  const Activator = Activator$1;
4106
4093
  const ColorPicker = ColorPicker$1;
@@ -4174,7 +4161,5 @@
4174
4161
  exports.topMost = topMost;
4175
4162
  exports.updateProperty = updateProperty;
4176
4163
 
4177
- Object.defineProperty(exports, '__esModule', { value: true });
4178
-
4179
4164
  }));
4180
4165
  //# sourceMappingURL=vis-util.js.map