@thinkpixellab-public/px-vue 3.0.5 → 3.0.6

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.
@@ -1,7 +1,7 @@
1
1
  <!--
2
2
  Keeps a child element contained within boundaries.
3
3
 
4
- <px-contain #default="{width, height, left: }" :aspect="16/9" :round="true" :px="true">
4
+ <px-contain #default="{width, height, left: }" :aspect="16/9" :round="true" :to-px="true">
5
5
  <div :style="{position: 'absolute', left: left top: top width: width height: height}" />
6
6
  </px-contain>
7
7
 
@@ -18,9 +18,7 @@
18
18
  :width="contain.width"
19
19
  :height="contain.height"
20
20
  :scale="contain.scale"
21
- >
22
- <!-- fallback -->
23
- </slot>
21
+ ></slot>
24
22
  </div>
25
23
  </template>
26
24
 
@@ -46,6 +44,15 @@ export default {
46
44
  naturalWidth: { type: Number, default: null },
47
45
  naturalHeight: { type: Number, default: null },
48
46
 
47
+ // these are adjustments to the available area inside of the container rectangle; the
48
+ // difference between padding and border is that padding values will also affect the final
49
+ // top/left values but border does not (to visualize this, imagine that you use border if
50
+ // the content has a visible border around and the final values reflect that where padding
51
+ // is empty space so palcement gets shfited); specify as either a number or an arry of up to
52
+ // 4 numbers that follow the css box-model pattern
53
+ padding: { default: null },
54
+ border: { default: null },
55
+
49
56
  // the horizontal positioning when there is leftover space
50
57
  alignX: { default: 0.5 }, // number | 'start' | 'center' | 'end'
51
58
 
@@ -53,7 +60,7 @@ export default {
53
60
  alignY: { default: 0.5 }, // number | 'start' | 'center' | 'end'
54
61
 
55
62
  // whether slot values should be returned as strings with 'px'
56
- px: { type: Boolean, default: true },
63
+ toPx: { type: Boolean, default: true },
57
64
 
58
65
  // whether slot values should be rounded to screen pixels
59
66
  round: { type: Boolean, default: true },
@@ -125,38 +132,104 @@ export default {
125
132
  },
126
133
  methods: {
127
134
  resize() {
135
+ let p = this.toBoxModelObject(this.padding);
136
+
137
+ let b = this.toBoxModelObject(this.border);
128
138
  let outer = this.$el.getBoundingClientRect();
129
139
  let inner = this.aspectRect || outer;
130
140
 
131
- const c = contain(
132
- inner,
133
- outer,
134
- this.alignToDecimal(this.alignX),
135
- this.alignToDecimal(this.alignY)
136
- );
141
+ outer = {
142
+ width: outer.width - (b.w + p.w),
143
+ height: outer.height - (b.h + p.h),
144
+ };
145
+
146
+ let r;
147
+
148
+ if (this.aspect) {
149
+ r = contain(
150
+ inner,
151
+ outer,
152
+ this.alignToDecimal(this.alignX),
153
+ this.alignToDecimal(this.alignY)
154
+ );
155
+ } else {
156
+ r = {
157
+ x: 0,
158
+ y: 0,
159
+ width: outer.width,
160
+ height: outer.height,
161
+ };
162
+ }
137
163
 
138
- this.contain = {
164
+ let c = {
139
165
  current: true,
140
- width: this.prepValue(c.width),
141
- height: this.prepValue(c.height),
142
- top: this.prepValue(c.y),
143
- right: this.prepValue(c.width - c.x),
144
- bottom: this.prepValue((c.height = c.y)),
145
- left: this.prepValue(c.x),
146
- scale: this.naturalWidth || this.naturalHeight ? c.scale : 1,
166
+ width: r.width + b.w,
167
+ height: r.height + b.h,
168
+ top: r.y + p.top,
169
+ left: r.x + p.left,
170
+ right: r.width - (r.x + b.w),
171
+ bottom: r.height - (r.y + b.h),
172
+ scale: this.naturalWidth || this.naturalHeight ? r.scale : 1,
147
173
  };
174
+
175
+ this.$emit('update', c);
176
+
177
+ c.width = this.prepValue(c.width);
178
+ c.height = this.prepValue(c.height);
179
+ c.left = this.prepValue(c.left);
180
+ c.top = this.prepValue(c.top);
181
+ c.right = this.prepValue(c.right);
182
+ c.bottom = this.prepValue(c.bottom);
183
+
184
+ this.contain = c;
148
185
  },
149
186
 
150
187
  prepValue(n) {
151
188
  if (this.round && typeof window != 'undefined') {
152
189
  n = Math.round(n * window.devicePixelRatio) / window.devicePixelRatio;
153
190
  }
154
- if (this.px) {
191
+ if (this.toPx) {
155
192
  n = this.cssPx(n);
156
193
  }
157
194
  return n;
158
195
  },
159
196
 
197
+ toBoxModelObject(val) {
198
+ const arr = this.toBoxModelArray(val);
199
+ return {
200
+ top: arr[0],
201
+ right: arr[1],
202
+ bottom: arr[2],
203
+ left: arr[3],
204
+ w: arr[1] + arr[3],
205
+ h: arr[0] + arr[2],
206
+ };
207
+ },
208
+
209
+ toBoxModelArray(val) {
210
+ if (!val) {
211
+ return [0, 0, 0, 0];
212
+ }
213
+
214
+ if (Array.isArray(val)) {
215
+ if (val.length == 0) {
216
+ return [0, 0, 0, 0];
217
+ }
218
+ if (val.length == 1) {
219
+ return [val[0], val[0], val[0], val[0]];
220
+ }
221
+ if (val.length == 2) {
222
+ return [val[0], val[1], val[0], val[1]];
223
+ }
224
+ if (val.length == 3) {
225
+ return [val[0], val[1], val[2], val[1]];
226
+ }
227
+ return [val[0], val[1], val[2], val[3]];
228
+ }
229
+
230
+ return [val, val, val, val];
231
+ },
232
+
160
233
  alignToDecimal(align) {
161
234
  if (typeof align == 'number') {
162
235
  return align;
@@ -22,10 +22,10 @@
22
22
  :name="calcTransitionName"
23
23
  @before-enter="transitionVisible = true"
24
24
  @after-leave="transitionVisible = false"
25
- :style="{ zIndex: zStart + currentLayerIndex }"
26
25
  >
27
26
  <div
28
27
  :class="bem({ ...variantsMap, absolute: strategy == 'absolute' })"
28
+ :style="{ zIndex: zStart + currentLayerIndex }"
29
29
  v-show="visibleValueNext"
30
30
  >
31
31
  <!-- overlay element -->
@@ -273,7 +273,6 @@ export default {
273
273
  }
274
274
  } else {
275
275
  if (this.cleanup) {
276
- console.log('cleanup');
277
276
  this.cleanup();
278
277
  this.cleanup = null;
279
278
  }
@@ -22,7 +22,7 @@
22
22
  </px-test>
23
23
 
24
24
  <px-test name="Width / Height" testId="pxcontain-wh" :size="{ h: 600 }">
25
- <px-contain :naturalWidth="1600" :naturalHeight="900" :px="true">
25
+ <px-contain :naturalWidth="1600" :naturalHeight="900">
26
26
  <template #default="{ top, left, width, height }">
27
27
  <div
28
28
  :style="{
@@ -39,7 +39,7 @@
39
39
  </px-test>
40
40
 
41
41
  <px-test name="Scale" testId="pxcontain-scale" :size="{ h: 600 }">
42
- <px-contain :naturalWidth="1600" :naturalHeight="900" :px="true">
42
+ <px-contain :naturalWidth="1600" :naturalHeight="900">
43
43
  <template #default="{ top, left, scale }">
44
44
  <div
45
45
  :style="{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkpixellab-public/px-vue",
3
- "version": "3.0.5",
3
+ "version": "3.0.6",
4
4
  "description": "General purpose Vue components and helpers that can be used across projects.",
5
5
  "author": "Pixel Lab",
6
6
  "license": "MIT",