@thinkpixellab-public/px-vue 3.0.84 → 3.0.86

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.
@@ -6,7 +6,7 @@
6
6
  export default {
7
7
  inject: {
8
8
  mediaQuery: {
9
- default: { isMobile: null, currentBreakpoint: null },
9
+ default: { isMobile: null, currentBreakpoint: null, breakpoints: {} },
10
10
  },
11
11
  },
12
12
  computed: {
@@ -17,5 +17,26 @@ export default {
17
17
  return this.mediaQuery.currentBreakpoint;
18
18
  },
19
19
  },
20
+ mounted() {
21
+ // setTimeout(() => {
22
+ // console.log(this.mediaQuery.breakpoints);
23
+ // }, 100);
24
+ },
25
+ methods: {
26
+ isBreakpointOrSmaller(breakpoint) {
27
+ if (this.currentBreakpoint === null) {
28
+ return false;
29
+ }
30
+
31
+ if (this.currentBreakpoint === breakpoint) {
32
+ return true;
33
+ }
34
+
35
+ return (
36
+ this.mediaQuery.breakpoints[breakpoint] >=
37
+ this.mediaQuery.breakpoints[this.currentBreakpoint]
38
+ );
39
+ },
40
+ },
20
41
  };
21
42
  </script>
@@ -21,9 +21,38 @@ export default {
21
21
  },
22
22
  mixins: [PxBaseResize],
23
23
  data() {
24
- return { mediaQuery: { isMobile: null, currentBreakpoint: null } };
24
+ return { mediaQuery: { isMobile: null, currentBreakpoint: null, breakpoints: {} } };
25
25
  },
26
+ mounted() {
27
+ const breakpointNames = getComputedStyle(document.documentElement)
28
+ .getPropertyValue('--breakpoint-names')
29
+ .trim()
30
+ .split(' ');
26
31
 
32
+ const breakpointSizes = getComputedStyle(document.documentElement)
33
+ .getPropertyValue('--breakpoint-sizes')
34
+ .trim()
35
+ .split(' ');
36
+
37
+ if (breakpointNames.length !== breakpointSizes.length) {
38
+ console.warn('Breakpoint names and sizes do not match');
39
+ return;
40
+ }
41
+
42
+ try {
43
+ this.mediaQuery.breakpoints = Object.fromEntries(
44
+ breakpointNames
45
+ .map((name, index) => {
46
+ return [name, parseInt(breakpointSizes[index])];
47
+ })
48
+ .sort((a, b) => a[1] - b[1])
49
+ );
50
+ } catch {
51
+ console.warn(
52
+ 'Could not parse breakpoint sizes. Check the format of the breakpoint-sizes variable in the theme file.'
53
+ );
54
+ }
55
+ },
27
56
  methods: {
28
57
  updateMediaQuery() {
29
58
  this.mediaQuery.isMobile =
@@ -40,10 +40,6 @@ export default {
40
40
  methods: {
41
41
  // true if the given variant (string) or variants (array) are present
42
42
  isVariant(val) {
43
- // if (val.includes && val.includes('offset')) {
44
- // debugger;
45
- // }
46
-
47
43
  if (this.variants && this.variants.length && val) {
48
44
  if (typeof val == 'string') {
49
45
  return this.variants?.includes(val);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "3.0.84",
3
+ "version": "3.0.86",
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/utils/cssStr.js CHANGED
@@ -99,10 +99,15 @@ function cssUnit(val) {
99
99
  * @example
100
100
  * cssUnitScale('10px', 2) => '20px'
101
101
  */
102
- function cssUnitScale(val, scaler) {
103
- const unit = cssUnit(val);
104
- const num = cssNum(val);
105
- return `${num * scaler}${unit}`;
102
+ function cssUnitScale(val, scaler, min = null, max = null) {
103
+ let unit = cssUnit(val);
104
+ let num = cssNum(val);
105
+
106
+ num = num * scaler;
107
+ num = min !== null && num < min ? min : num;
108
+ num = max !== null && num > max ? max : num;
109
+
110
+ return `${num}${unit}`;
106
111
  }
107
112
 
108
113
  /*