@thinkpixellab-public/px-vue 3.0.33 → 3.0.35

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "3.0.33",
3
+ "version": "3.0.35",
4
4
  "description": "General purpose Vue components and helpers that can be used across projects.",
5
5
  "author": "Pixel Lab",
6
6
  "license": "MIT",
package/plugins/common.js CHANGED
@@ -5,7 +5,15 @@
5
5
 
6
6
  import bem from '../utils/bem';
7
7
  import isServer from '../utils/isServer.js';
8
- import { cssPx, cssEm, cssPcnt, cssUrl, cssVar } from '../utils/cssStr.js';
8
+ import {
9
+ cssPx,
10
+ cssEm,
11
+ cssPcnt,
12
+ cssUrl,
13
+ cssVar,
14
+ cssUnitFallback,
15
+ cssEmFallback,
16
+ } from '../utils/cssStr.js';
9
17
  import aspect from './filters/aspect.js';
10
18
  import kebab from './filters/kebab.js';
11
19
  import slug from './filters/slug.js';
@@ -22,6 +30,8 @@ export default {
22
30
  Vue.prototype.cssPcnt = cssPcnt;
23
31
  Vue.prototype.cssUrl = cssUrl;
24
32
  Vue.prototype.cssVar = cssVar;
33
+ Vue.prototype.cssUnitFallback = cssUnitFallback;
34
+ Vue.prototype.cssEmFallback = cssEmFallback;
25
35
 
26
36
  // filters
27
37
  // note: filters can be called as methods with something like
package/utils/cssStr.js CHANGED
@@ -58,4 +58,44 @@ function cssVar(val) {
58
58
  return null;
59
59
  }
60
60
 
61
- export { cssPx, cssEm, cssPcnt, cssUrl, cssVar };
61
+ /*
62
+ Add the specified unit if no other unit is specified.
63
+
64
+ cssUnitFallback('10px', 'em) => '10px'
65
+ cssUnitFallback('10', 'em') => '10em'
66
+ cssUnitFallback(10, 'em') => '10em'
67
+ */
68
+ function cssUnitFallback(val, fallback, allowNumberless = false) {
69
+ if (!val) {
70
+ return val;
71
+ }
72
+
73
+ let num = typeof val == 'number' ? val : parseFloat(val.toString());
74
+
75
+ val = val.toString().trim();
76
+
77
+ if (isNaN(num)) {
78
+ if (allowNumberless) {
79
+ num = '';
80
+ } else {
81
+ return null;
82
+ }
83
+ }
84
+
85
+ const unit =
86
+ val
87
+ .replace(num, '')
88
+ .replace(/[0-9]|-|\./g, '')
89
+ .trim() || fallback;
90
+
91
+ return `${num}${unit}`;
92
+ }
93
+
94
+ /*
95
+ Ems version of cssUnitFallback
96
+ */
97
+ function cssEmFallback(val, allowNumberless = false) {
98
+ return cssUnitFallback(val, 'em', allowNumberless);
99
+ }
100
+
101
+ export { cssPx, cssEm, cssPcnt, cssUrl, cssVar, cssUnitFallback, cssEmFallback };