@thinkpixellab-public/px-vue 3.0.55 → 3.0.56
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/package.json +1 -1
- package/plugins/common.js +2 -0
- package/utils/cssStr.js +76 -1
package/package.json
CHANGED
package/plugins/common.js
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
cssPcnt,
|
|
12
12
|
cssUrl,
|
|
13
13
|
cssVar,
|
|
14
|
+
cssAspect,
|
|
14
15
|
cssUnitFallback,
|
|
15
16
|
cssEmFallback,
|
|
16
17
|
} from '../utils/cssStr.js';
|
|
@@ -30,6 +31,7 @@ export default {
|
|
|
30
31
|
Vue.prototype.cssPcnt = cssPcnt;
|
|
31
32
|
Vue.prototype.cssUrl = cssUrl;
|
|
32
33
|
Vue.prototype.cssVar = cssVar;
|
|
34
|
+
Vue.prototype.cssAspect = cssAspect;
|
|
33
35
|
Vue.prototype.cssUnitFallback = cssUnitFallback;
|
|
34
36
|
Vue.prototype.cssEmFallback = cssEmFallback;
|
|
35
37
|
|
package/utils/cssStr.js
CHANGED
|
@@ -93,6 +93,70 @@ function cssNum(val, nanValue = 0) {
|
|
|
93
93
|
return isNaN(num) ? nanValue : num;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
/*
|
|
97
|
+
Attempts to convert multiple input styles into valid aspect-ratio property syntax (the number version)
|
|
98
|
+
|
|
99
|
+
cssAspect(1.5) => 1.5
|
|
100
|
+
cssAspect('1.5') => 1.5
|
|
101
|
+
cssAspect('3 / 2') => 1.5
|
|
102
|
+
cssAspect('3:2') => 1.5
|
|
103
|
+
cssAspect('3 : 2') => 1.5
|
|
104
|
+
this.cssAspect('3:2:1') => null
|
|
105
|
+
cssAspect('auto') => auto
|
|
106
|
+
cssAspect('blah') => null
|
|
107
|
+
cssAspect('auto', 1.5) => auto
|
|
108
|
+
cssAspect('blah', 1.5) => 1.5
|
|
109
|
+
cssAspect(null, 1.5) => 1.5
|
|
110
|
+
|
|
111
|
+
*/
|
|
112
|
+
function cssAspect(val, fallback = null) {
|
|
113
|
+
// number
|
|
114
|
+
if (typeof val == 'number') {
|
|
115
|
+
return val;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// null or empty (return fallback)
|
|
119
|
+
if (!val) {
|
|
120
|
+
return fallback;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// string
|
|
124
|
+
if (typeof val == 'string') {
|
|
125
|
+
val = val.trim();
|
|
126
|
+
|
|
127
|
+
// special case 'auto' since it's valid
|
|
128
|
+
if (val == 'auto') {
|
|
129
|
+
return val;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// look for a delimiter first
|
|
133
|
+
|
|
134
|
+
let delimiter = null;
|
|
135
|
+
|
|
136
|
+
if (val && val.indexOf(':') > -1) {
|
|
137
|
+
delimiter = ':';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (val && val.indexOf('/') > -1) {
|
|
141
|
+
delimiter = '/';
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (delimiter) {
|
|
145
|
+
let parts = val.split(delimiter).map(s => cssNum(s.trim()));
|
|
146
|
+
if (parts && parts.length == 2) {
|
|
147
|
+
return parts[0] / parts[1];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// try to just parse the string
|
|
152
|
+
else {
|
|
153
|
+
return cssNum(val, fallback);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return fallback;
|
|
158
|
+
}
|
|
159
|
+
|
|
96
160
|
/*
|
|
97
161
|
Add the specified unit if no other unit is specified.
|
|
98
162
|
|
|
@@ -133,4 +197,15 @@ function cssEmFallback(val, allowNumberless = false) {
|
|
|
133
197
|
return cssUnitFallback(val, 'em', allowNumberless);
|
|
134
198
|
}
|
|
135
199
|
|
|
136
|
-
export {
|
|
200
|
+
export {
|
|
201
|
+
cssPx,
|
|
202
|
+
cssEm,
|
|
203
|
+
cssPcnt,
|
|
204
|
+
cssUrl,
|
|
205
|
+
cssVar,
|
|
206
|
+
cssAspect,
|
|
207
|
+
cssNum,
|
|
208
|
+
cssUnit,
|
|
209
|
+
cssUnitFallback,
|
|
210
|
+
cssEmFallback,
|
|
211
|
+
};
|