@thinkpixellab-public/px-vue 3.0.59 → 3.0.60
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/components/PxBaseVariants.vue +24 -4
- package/package.json +1 -1
- package/utils/cssStr.js +2 -9
- package/utils/utils.js +4 -4
|
@@ -38,11 +38,31 @@ export default {
|
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
40
|
methods: {
|
|
41
|
-
// true if the given variant
|
|
42
|
-
isVariant(
|
|
43
|
-
|
|
41
|
+
// true if the given variant (string) or variants (array) are present
|
|
42
|
+
isVariant(val) {
|
|
43
|
+
// if (val.includes && val.includes('offset')) {
|
|
44
|
+
// debugger;
|
|
45
|
+
// }
|
|
46
|
+
|
|
47
|
+
if (this.variants && this.variants.length && val) {
|
|
48
|
+
if (typeof val == 'string') {
|
|
49
|
+
return this.variants?.includes(val);
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(val) && val.length) {
|
|
52
|
+
for (let i = 0; i < val.length; i++) {
|
|
53
|
+
if (this.variants?.includes(val[i])) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
44
60
|
},
|
|
45
|
-
|
|
61
|
+
|
|
62
|
+
// Find the first matching variant key in a map and return the correspond value
|
|
63
|
+
// Example:
|
|
64
|
+
// <MyComponent variant="red" />
|
|
65
|
+
// variantsToValue({'red': '#F00', 'blue': '#0F0'}) => '#F00'
|
|
46
66
|
variantsToValue(valueMap, fallback) {
|
|
47
67
|
for (let key in valueMap) {
|
|
48
68
|
if (this.isVariant(key)) {
|
package/package.json
CHANGED
package/utils/cssStr.js
CHANGED
|
@@ -94,17 +94,15 @@ function cssNum(val, nanValue = 0) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/*
|
|
97
|
-
Attempts to convert multiple input styles into valid aspect-ratio
|
|
97
|
+
Attempts to convert multiple input styles into valid aspect-ratio number that can be used in css or javascript
|
|
98
98
|
|
|
99
99
|
cssAspect(1.5) => 1.5
|
|
100
100
|
cssAspect('1.5') => 1.5
|
|
101
101
|
cssAspect('3 / 2') => 1.5
|
|
102
102
|
cssAspect('3:2') => 1.5
|
|
103
103
|
cssAspect('3 : 2') => 1.5
|
|
104
|
-
|
|
105
|
-
cssAspect('auto') => auto
|
|
104
|
+
cssAspect('3:2:1') => null
|
|
106
105
|
cssAspect('blah') => null
|
|
107
|
-
cssAspect('auto', 1.5) => auto
|
|
108
106
|
cssAspect('blah', 1.5) => 1.5
|
|
109
107
|
cssAspect(null, 1.5) => 1.5
|
|
110
108
|
|
|
@@ -124,11 +122,6 @@ function cssAspect(val, fallback = null) {
|
|
|
124
122
|
if (typeof val == 'string') {
|
|
125
123
|
val = val.trim();
|
|
126
124
|
|
|
127
|
-
// special case 'auto' since it's valid
|
|
128
|
-
if (val == 'auto') {
|
|
129
|
-
return val;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
125
|
// look for a delimiter first
|
|
133
126
|
|
|
134
127
|
let delimiter = null;
|
package/utils/utils.js
CHANGED
|
@@ -9,7 +9,7 @@ export default {
|
|
|
9
9
|
* @param {} min The minimum allowed value
|
|
10
10
|
* @param {} max The maximum allowed value
|
|
11
11
|
*/
|
|
12
|
-
clamp: function (value, min, max) {
|
|
12
|
+
clamp: function (value, min = 0, max = 1) {
|
|
13
13
|
return Math.min(Math.max(value, min), max);
|
|
14
14
|
},
|
|
15
15
|
|
|
@@ -38,9 +38,9 @@ export default {
|
|
|
38
38
|
* @param {*} wrap When true out-of-bounds indices will wrap, otherwise they will be clamped.
|
|
39
39
|
* @return {*} A safe index into the array.
|
|
40
40
|
*/
|
|
41
|
-
arraySafeIndex: function (arr, index, offset, wrap) {
|
|
42
|
-
if (!arr || !arr.length) {
|
|
43
|
-
return
|
|
41
|
+
arraySafeIndex: function (arr, index, offset = 0, wrap = false, fallback = -1) {
|
|
42
|
+
if (!arr || !arr.length || typeof index !== 'number') {
|
|
43
|
+
return fallback;
|
|
44
44
|
}
|
|
45
45
|
if (wrap) {
|
|
46
46
|
return (index + (offset % arr.length) + arr.length) % arr.length;
|