@thinkpixellab-public/px-vue 3.0.58 → 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.
@@ -38,11 +38,31 @@ export default {
38
38
  },
39
39
  },
40
40
  methods: {
41
- // true if the given variant is present
42
- isVariant(variantName) {
43
- return this.variants?.includes(variantName);
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
- // find the first matching variant key in a map and return the correspond value
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)) {
@@ -114,6 +114,9 @@ You can define a template using space notation like this:
114
114
  :class="bem('card')"
115
115
  :ref="cardRefFromItem(item)"
116
116
  >
117
+ <div v-if="item.id" :id="item.id" :class="bem('scroll-id')">
118
+ {{ item.id }}
119
+ </div>
117
120
  <slot
118
121
  name="default"
119
122
  :index="items.indexOf(item)"
@@ -512,5 +515,15 @@ export default {
512
515
  }
513
516
  }
514
517
  }
518
+
519
+ // element with id set to the section id, placed just outside the top of the section to help
520
+ // with scroll position
521
+ &__scroll-id {
522
+ position: absolute;
523
+ width: 1px;
524
+ height: 1px;
525
+ top: -80px;
526
+ opacity: 0;
527
+ }
515
528
  }
516
529
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "3.0.58",
3
+ "version": "3.0.60",
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
@@ -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 property syntax (the number version)
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
- this.cssAspect('3:2:1') => null
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 -1;
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;