vis-util 5.0.3 → 5.0.4

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.4
8
+ * @date 2023-09-13T20:29:32.256Z
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
  */
@@ -246,7 +241,7 @@
246
241
 
247
242
  const Hammer$1 =
248
243
  typeof window !== "undefined"
249
- ? window.Hammer || RealHammer__default["default"]
244
+ ? window.Hammer || RealHammer
250
245
  : function () {
251
246
  // hammer.js is only available in a browser, not in node.js. Replacing it with a mock object.
252
247
  return hammerMock();
@@ -331,7 +326,7 @@
331
326
  }
332
327
 
333
328
  // turn into an event emitter
334
- Emitter__default["default"](Activator$1.prototype);
329
+ Emitter(Activator$1.prototype);
335
330
 
336
331
  // The currently active activator
337
332
  Activator$1.current = null;
@@ -1334,29 +1329,21 @@
1334
1329
  const value = maxRGB;
1335
1330
  return { h: hue, s: saturation, v: value };
1336
1331
  }
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
- };
1332
+ /**
1333
+ * Split a string with css styles into an object with key/values.
1334
+ *
1335
+ * @param cssText - CSS source code to split into key/value object.
1336
+ * @returns Key/value object corresponding to {@link cssText}.
1337
+ */
1338
+ function splitCSSText(cssText) {
1339
+ const tmpEllement = document.createElement("div");
1340
+ const styles = {};
1341
+ tmpEllement.style.cssText = cssText;
1342
+ for (let i = 0; i < tmpEllement.style.length; ++i) {
1343
+ styles[tmpEllement.style[i]] = tmpEllement.style.getPropertyValue(tmpEllement.style[i]);
1344
+ }
1345
+ return styles;
1346
+ }
1360
1347
  /**
1361
1348
  * Append a string with css styles to an element.
1362
1349
  *
@@ -1364,13 +1351,10 @@
1364
1351
  * @param cssText - The styles to be appended.
1365
1352
  */
1366
1353
  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);
1354
+ const cssStyle = splitCSSText(cssText);
1355
+ for (const [key, value] of Object.entries(cssStyle)) {
1356
+ element.style.setProperty(key, value);
1357
+ }
1374
1358
  }
1375
1359
  /**
1376
1360
  * Remove a string with css styles from an element.
@@ -1379,14 +1363,10 @@
1379
1363
  * @param cssText - The styles to be removed.
1380
1364
  */
1381
1365
  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
- }
1366
+ const cssStyle = splitCSSText(cssText);
1367
+ for (const key of Object.keys(cssStyle)) {
1368
+ element.style.removeProperty(key);
1388
1369
  }
1389
- element.style.cssText = cssUtil.join(styles);
1390
1370
  }
1391
1371
  /**
1392
1372
  * Convert HSV \<0, 1\> into RGB color object.
@@ -2107,7 +2087,7 @@
2107
2087
  /**
2108
2088
  * @param {number} [pixelRatio=1]
2109
2089
  */
2110
- class ColorPicker$1 {
2090
+ let ColorPicker$1 = class ColorPicker {
2111
2091
  /**
2112
2092
  * @param {number} [pixelRatio=1]
2113
2093
  */
@@ -2752,7 +2732,7 @@
2752
2732
  this.color.a +
2753
2733
  ")";
2754
2734
  }
2755
- }
2735
+ };
2756
2736
 
2757
2737
  /**
2758
2738
  * Wrap given text (last argument) in HTML elements (all preceding arguments).
@@ -2781,7 +2761,7 @@
2781
2761
  *
2782
2762
  * The options are matched with their counterparts in each of the modules and the values used in the configuration are
2783
2763
  */
2784
- class Configurator$1 {
2764
+ let Configurator$1 = class Configurator {
2785
2765
  /**
2786
2766
  * @param {object} parentModule | the location where parentModule.setOptions() can be called
2787
2767
  * @param {object} defaultContainer | the default container of the module
@@ -3550,12 +3530,12 @@
3550
3530
  }
3551
3531
  return options;
3552
3532
  }
3553
- }
3533
+ };
3554
3534
 
3555
3535
  /**
3556
3536
  * Popup is a class to create a popup window with some text
3557
3537
  */
3558
- class Popup$1 {
3538
+ let Popup$1 = class Popup {
3559
3539
  /**
3560
3540
  * @param {Element} container The container object.
3561
3541
  * @param {string} overflowMethod How the popup should act to overflowing ('flip' or 'cap')
@@ -3687,7 +3667,7 @@
3687
3667
  destroy() {
3688
3668
  this.frame.parentNode.removeChild(this.frame); // Remove element from DOM
3689
3669
  }
3690
- }
3670
+ };
3691
3671
 
3692
3672
  let errorFound = false;
3693
3673
  let allOptions;
@@ -3697,7 +3677,7 @@
3697
3677
  /**
3698
3678
  * Used to validate options.
3699
3679
  */
3700
- class Validator$1 {
3680
+ let Validator$1 = class Validator {
3701
3681
  /**
3702
3682
  * Main function to be called
3703
3683
  *
@@ -3714,7 +3694,7 @@
3714
3694
  if (subObject !== undefined) {
3715
3695
  usedOptions = referenceOptions[subObject];
3716
3696
  }
3717
- Validator$1.parse(options, usedOptions, []);
3697
+ Validator.parse(options, usedOptions, []);
3718
3698
  return errorFound;
3719
3699
  }
3720
3700
 
@@ -3729,7 +3709,7 @@
3729
3709
  static parse(options, referenceOptions, path) {
3730
3710
  for (const option in options) {
3731
3711
  if (Object.prototype.hasOwnProperty.call(options, option)) {
3732
- Validator$1.check(option, options, referenceOptions, path);
3712
+ Validator.check(option, options, referenceOptions, path);
3733
3713
  }
3734
3714
  }
3735
3715
  }
@@ -3748,7 +3728,7 @@
3748
3728
  referenceOptions[option] === undefined &&
3749
3729
  referenceOptions.__any__ === undefined
3750
3730
  ) {
3751
- Validator$1.getSuggestion(option, referenceOptions, path);
3731
+ Validator.getSuggestion(option, referenceOptions, path);
3752
3732
  return;
3753
3733
  }
3754
3734
 
@@ -3768,7 +3748,7 @@
3768
3748
 
3769
3749
  // if the any-subgroup is not a predefined object in the configurator,
3770
3750
  // we do not look deeper into the object.
3771
- is_object = Validator$1.getType(options[option]) === "object";
3751
+ is_object = Validator.getType(options[option]) === "object";
3772
3752
  }
3773
3753
 
3774
3754
  let refOptionObj = referenceOptions[referenceOption];
@@ -3776,7 +3756,7 @@
3776
3756
  refOptionObj = refOptionObj.__type__;
3777
3757
  }
3778
3758
 
3779
- Validator$1.checkFields(
3759
+ Validator.checkFields(
3780
3760
  option,
3781
3761
  options,
3782
3762
  referenceOptions,
@@ -3806,18 +3786,18 @@
3806
3786
  ) {
3807
3787
  const log = function (message) {
3808
3788
  console.error(
3809
- "%c" + message + Validator$1.printLocation(path, option),
3789
+ "%c" + message + Validator.printLocation(path, option),
3810
3790
  VALIDATOR_PRINT_STYLE$1
3811
3791
  );
3812
3792
  };
3813
3793
 
3814
- const optionType = Validator$1.getType(options[option]);
3794
+ const optionType = Validator.getType(options[option]);
3815
3795
  const refOptionType = refOptionObj[optionType];
3816
3796
 
3817
3797
  if (refOptionType !== undefined) {
3818
3798
  // if the type is correct, we check if it is supposed to be one of a few select values
3819
3799
  if (
3820
- Validator$1.getType(refOptionType) === "array" &&
3800
+ Validator.getType(refOptionType) === "array" &&
3821
3801
  refOptionType.indexOf(options[option]) === -1
3822
3802
  ) {
3823
3803
  log(
@@ -3825,7 +3805,7 @@
3825
3805
  option +
3826
3806
  '".' +
3827
3807
  " Allowed values are:" +
3828
- Validator$1.print(refOptionType) +
3808
+ Validator.print(refOptionType) +
3829
3809
  ' not "' +
3830
3810
  options[option] +
3831
3811
  '". '
@@ -3833,7 +3813,7 @@
3833
3813
  errorFound = true;
3834
3814
  } else if (optionType === "object" && referenceOption !== "__any__") {
3835
3815
  path = copyAndExtendArray(path, option);
3836
- Validator$1.parse(
3816
+ Validator.parse(
3837
3817
  options[option],
3838
3818
  referenceOptions[referenceOption],
3839
3819
  path
@@ -3845,7 +3825,7 @@
3845
3825
  'Invalid type received for "' +
3846
3826
  option +
3847
3827
  '". Expected: ' +
3848
- Validator$1.print(Object.keys(refOptionObj)) +
3828
+ Validator.print(Object.keys(refOptionObj)) +
3849
3829
  ". Received [" +
3850
3830
  optionType +
3851
3831
  '] "' +
@@ -3910,8 +3890,8 @@
3910
3890
  * @static
3911
3891
  */
3912
3892
  static getSuggestion(option, options, path) {
3913
- const localSearch = Validator$1.findInOptions(option, options, path, false);
3914
- const globalSearch = Validator$1.findInOptions(option, allOptions, [], true);
3893
+ const localSearch = Validator.findInOptions(option, options, path, false);
3894
+ const globalSearch = Validator.findInOptions(option, allOptions, [], true);
3915
3895
 
3916
3896
  const localSearchThreshold = 8;
3917
3897
  const globalSearchThreshold = 4;
@@ -3920,7 +3900,7 @@
3920
3900
  if (localSearch.indexMatch !== undefined) {
3921
3901
  msg =
3922
3902
  " in " +
3923
- Validator$1.printLocation(localSearch.path, option, "") +
3903
+ Validator.printLocation(localSearch.path, option, "") +
3924
3904
  'Perhaps it was incomplete? Did you mean: "' +
3925
3905
  localSearch.indexMatch +
3926
3906
  '"?\n\n';
@@ -3930,9 +3910,9 @@
3930
3910
  ) {
3931
3911
  msg =
3932
3912
  " in " +
3933
- Validator$1.printLocation(localSearch.path, option, "") +
3913
+ Validator.printLocation(localSearch.path, option, "") +
3934
3914
  "Perhaps it was misplaced? Matching option found at: " +
3935
- Validator$1.printLocation(
3915
+ Validator.printLocation(
3936
3916
  globalSearch.path,
3937
3917
  globalSearch.closestMatch,
3938
3918
  ""
@@ -3942,12 +3922,12 @@
3942
3922
  '. Did you mean "' +
3943
3923
  localSearch.closestMatch +
3944
3924
  '"?' +
3945
- Validator$1.printLocation(localSearch.path, option);
3925
+ Validator.printLocation(localSearch.path, option);
3946
3926
  } else {
3947
3927
  msg =
3948
3928
  ". Did you mean one of these: " +
3949
- Validator$1.print(Object.keys(options)) +
3950
- Validator$1.printLocation(path, option);
3929
+ Validator.print(Object.keys(options)) +
3930
+ Validator.printLocation(path, option);
3951
3931
  }
3952
3932
 
3953
3933
  console.error(
@@ -3976,7 +3956,7 @@
3976
3956
  for (const op in options) {
3977
3957
  let distance;
3978
3958
  if (options[op].__type__ !== undefined && recursive === true) {
3979
- const result = Validator$1.findInOptions(
3959
+ const result = Validator.findInOptions(
3980
3960
  option,
3981
3961
  options[op],
3982
3962
  copyAndExtendArray(path, op)
@@ -3991,7 +3971,7 @@
3991
3971
  if (op.toLowerCase().indexOf(lowerCaseOption) !== -1) {
3992
3972
  indexMatch = op;
3993
3973
  }
3994
- distance = Validator$1.levenshteinDistance(option, op);
3974
+ distance = Validator.levenshteinDistance(option, op);
3995
3975
  if (min > distance) {
3996
3976
  closestMatch = op;
3997
3977
  closestMatchPath = copyArray(path);
@@ -4100,7 +4080,7 @@
4100
4080
 
4101
4081
  return matrix[b.length][a.length];
4102
4082
  }
4103
- }
4083
+ };
4104
4084
 
4105
4085
  const Activator = Activator$1;
4106
4086
  const ColorPicker = ColorPicker$1;
@@ -4174,7 +4154,5 @@
4174
4154
  exports.topMost = topMost;
4175
4155
  exports.updateProperty = updateProperty;
4176
4156
 
4177
- Object.defineProperty(exports, '__esModule', { value: true });
4178
-
4179
4157
  }));
4180
4158
  //# sourceMappingURL=vis-util.js.map