@teipublisher/pb-components 1.42.7 → 1.43.0

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.
package/src/utils.js CHANGED
@@ -1,52 +1,51 @@
1
-
2
- export function resolveURL(relPath) {
3
- const src = document.querySelector('script[src*=pb-components]');
4
- if (src) {
5
- return new URL(relPath, src.src).href;
6
- }
7
- return new URL(relPath, window.location.href).href;
8
- }
9
-
10
- export function cmpVersion(a, b) {
11
- var i, cmp, len;
12
- a = (a + '').split('.');
13
- b = (b + '').split('.');
14
- len = Math.max(a.length, b.length);
15
- for (i = 0; i < len; i++) {
16
- if (a[i] === undefined) {
17
- a[i] = '0';
18
- }
19
- if (b[i] === undefined) {
20
- b[i] = '0';
21
- }
22
- cmp = parseInt(a[i], 10) - parseInt(b[i], 10);
23
- if (cmp !== 0) {
24
- return (cmp < 0 ? -1 : 1);
25
- }
26
- }
27
- return 0;
28
- }
29
-
30
- export function minVersion(given, required) {
31
- return cmpVersion(given, required) >= 0;
32
- }
33
-
34
- /**
35
- * Retrieve value of a CSS property.
36
- *
37
- * @param {Element} elem the component
38
- * @param {string} name name of the property
39
- * @param {any} defaultValue default value
40
- * @returns the value or defaultValue if it does not exist
41
- */
42
- export function getCSSProperty(elem, name, defaultValue) {
43
- const property = getComputedStyle(elem).getPropertyValue(name);
44
- if (property) {
45
- try {
46
- return JSON.parse(property);
47
- } catch (e) {
48
- return defaultValue;
49
- }
50
- }
51
- return defaultValue;
1
+ export function resolveURL(relPath) {
2
+ const src = document.querySelector('script[src*=pb-components]');
3
+ if (src) {
4
+ return new URL(relPath, src.src).href;
5
+ }
6
+ return new URL(relPath, window.location.href).href;
7
+ }
8
+
9
+ export function cmpVersion(a, b) {
10
+ var i, cmp, len;
11
+ a = (a + '').split('.');
12
+ b = (b + '').split('.');
13
+ len = Math.max(a.length, b.length);
14
+ for (i = 0; i < len; i++) {
15
+ if (a[i] === undefined) {
16
+ a[i] = '0';
17
+ }
18
+ if (b[i] === undefined) {
19
+ b[i] = '0';
20
+ }
21
+ cmp = parseInt(a[i], 10) - parseInt(b[i], 10);
22
+ if (cmp !== 0) {
23
+ return (cmp < 0 ? -1 : 1);
24
+ }
25
+ }
26
+ return 0;
27
+ }
28
+
29
+ export function minVersion(given, required) {
30
+ return cmpVersion(given, required) >= 0;
31
+ }
32
+
33
+ /**
34
+ * Retrieve value of a CSS property.
35
+ *
36
+ * @param {Element} elem the component
37
+ * @param {string} name name of the property
38
+ * @param {any} defaultValue default value
39
+ * @returns the value or defaultValue if it does not exist
40
+ */
41
+ export function getCSSProperty(elem, name, defaultValue) {
42
+ const property = getComputedStyle(elem).getPropertyValue(name);
43
+ if (property) {
44
+ try {
45
+ return JSON.parse(property);
46
+ } catch (e) {
47
+ return defaultValue;
48
+ }
49
+ }
50
+ return defaultValue;
52
51
  }