@thinkpixellab-public/px-vue 3.0.16 → 3.0.17

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.
@@ -0,0 +1,26 @@
1
+ <!--
2
+ Extends PxBaseVariants with the ability to specify default and base variants
3
+ (see descriptions of props below).
4
+ -->
5
+
6
+ <script>
7
+ import PxBaseVariants from './PxBaseVariants.vue';
8
+ export default {
9
+ mixins: [PxBaseVariants],
10
+ props: {
11
+ // variant that is always applied in addition to option specified by the variant prop
12
+ variantBase: { type: String, default: '' },
13
+
14
+ // variant that is applied only if no other variant is specified
15
+ variantDefault: { type: String, default: '' },
16
+ },
17
+ computed: {
18
+ variantValue() {
19
+ return (
20
+ (this.variantBase ? `${this.variantBase} ` : '') +
21
+ (this.variant || this.variantDefault)
22
+ );
23
+ },
24
+ },
25
+ };
26
+ </script>
@@ -146,6 +146,9 @@ export default {
146
146
  aspectNumber() {
147
147
  this.resize();
148
148
  },
149
+ contain(nv) {
150
+ this.$emit('update', nv);
151
+ },
149
152
  },
150
153
  methods: {
151
154
  // Use a source for the outer container size other than this.$el. The container argument can
@@ -169,6 +172,7 @@ export default {
169
172
  left: null,
170
173
  scale: 1,
171
174
  };
175
+
172
176
  return;
173
177
  }
174
178
  let p = this.toBoxModelObject(this.padding);
@@ -226,8 +230,6 @@ export default {
226
230
  scale: this.naturalWidth || this.naturalHeight ? r.scale : 1,
227
231
  };
228
232
 
229
- this.$emit('update', c);
230
-
231
233
  c.width = this.prepValue(c.width);
232
234
  c.height = this.prepValue(c.height);
233
235
  c.left = this.prepValue(c.left);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "3.0.16",
3
+ "version": "3.0.17",
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,7 @@
5
5
 
6
6
  import bem from '../utils/bem';
7
7
  import isServer from '../utils/isServer.js';
8
- import { cssPx, cssEm, cssPcnt, cssUrl } from '../utils/cssStr.js';
8
+ import { cssPx, cssEm, cssPcnt, cssUrl, cssVar } from '../utils/cssStr.js';
9
9
  import aspect from './filters/aspect.js';
10
10
  import kebab from './filters/kebab.js';
11
11
  import slug from './filters/slug.js';
@@ -21,6 +21,7 @@ export default {
21
21
  Vue.prototype.cssEm = cssEm;
22
22
  Vue.prototype.cssPcnt = cssPcnt;
23
23
  Vue.prototype.cssUrl = cssUrl;
24
+ Vue.prototype.cssVar = cssVar;
24
25
 
25
26
  // filters
26
27
  // note: filters can be called as methods with something like
package/utils/cssStr.js CHANGED
@@ -24,9 +24,14 @@ function cssEm(val, fallback) {
24
24
  Converts a number to a percentage string
25
25
  percent(0.45) => '45%'
26
26
  */
27
- function cssPcnt(val) {
27
+ function cssPcnt(val, roundDec = 0) {
28
28
  if (!isNaN(val)) {
29
- return val * 100 + '%';
29
+ val *= 100;
30
+
31
+ if (roundDec) {
32
+ val = Math.round(val * Math.pow(10, roundDec)) / Math.pow(10, roundDec);
33
+ }
34
+ return val + '%';
30
35
  }
31
36
  return null;
32
37
  }
@@ -42,4 +47,15 @@ function cssUrl(val) {
42
47
  return null;
43
48
  }
44
49
 
45
- export { cssPx, cssEm, cssPcnt, cssUrl };
50
+ /*
51
+ Wrap a string in css variable syntax
52
+ cssVar('theme-blue') => 'var(--theme-blue)'
53
+ */
54
+ function cssVar(val) {
55
+ if (val) {
56
+ return `var(--${val})`;
57
+ }
58
+ return null;
59
+ }
60
+
61
+ export { cssPx, cssEm, cssPcnt, cssUrl, cssVar };
package/utils/utils.js CHANGED
@@ -165,4 +165,36 @@ export default {
165
165
  height: clientRect.height,
166
166
  };
167
167
  },
168
+
169
+ /**
170
+ * Returns a simple seeded random number function. This turns out to be really useful when trying
171
+ * to keep state in sync between nuxt and client. If seed is null, returns an instance that has
172
+ * been seeded with the current minute value (e.g. will change once per minute).
173
+ *
174
+ * Seed can be any string or number.
175
+ *
176
+ * This is based on the mulberry32 function found here:
177
+ * https://www.delftstack.com/howto/javascript/javascript-random-seed-to-generate-random/
178
+ *
179
+ * Usage:
180
+ * const myRandomFn = utils.seededRandom(1234);
181
+ * myRandomFn() // 0.432887248
182
+ * myRandomFn() // 0.028234674
183
+ *
184
+ */
185
+
186
+ seededRandomFn(seed) {
187
+ seed = seed || parseInt(Date().slice(19, 21));
188
+
189
+ return () => {
190
+ let for_bit32_mul = (seed += 0x6d2b79f5);
191
+ let cast32_one = for_bit32_mul ^ (for_bit32_mul >>> 15);
192
+ let cast32_two = for_bit32_mul | 1;
193
+ for_bit32_mul = Math.imul(cast32_one, cast32_two);
194
+ for_bit32_mul ^=
195
+ for_bit32_mul +
196
+ Math.imul(for_bit32_mul ^ (for_bit32_mul >>> 7), for_bit32_mul | 61);
197
+ return ((for_bit32_mul ^ (for_bit32_mul >>> 14)) >>> 0) / 4294967296;
198
+ };
199
+ },
168
200
  };