@thinkpixellab-public/px-vue 4.0.0 → 4.0.2
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/components/PxCalendar.vue +1 -1
- package/components/PxClock.vue +18 -18
- package/components/PxRadioButton.vue +2 -2
- package/components/PxResizer.vue +1 -1
- package/components/PxSlides.vue +102 -5
- package/components/PxSpinner.vue +6 -6
- package/package.json +2 -2
- package/utils/lethargy.js +111 -0
package/components/PxClock.vue
CHANGED
|
@@ -217,19 +217,19 @@ export default {
|
|
|
217
217
|
&__hand-min,
|
|
218
218
|
&__hand-min-hover {
|
|
219
219
|
@include abs;
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
&::before,
|
|
221
|
+
&::after {
|
|
222
222
|
content: '';
|
|
223
223
|
display: block;
|
|
224
224
|
position: absolute;
|
|
225
225
|
}
|
|
226
|
-
|
|
226
|
+
&::before {
|
|
227
227
|
border-radius: 50%;
|
|
228
228
|
top: 50%;
|
|
229
229
|
left: 50%;
|
|
230
230
|
transform: translate(-50%, -50%);
|
|
231
231
|
}
|
|
232
|
-
|
|
232
|
+
&::after {
|
|
233
233
|
bottom: 50%;
|
|
234
234
|
left: 50%;
|
|
235
235
|
transform: translateX(-50%);
|
|
@@ -239,12 +239,12 @@ export default {
|
|
|
239
239
|
&__hand-hour-shadow,
|
|
240
240
|
&__hand-hour-hover,
|
|
241
241
|
&__hand-hour {
|
|
242
|
-
|
|
242
|
+
&::before {
|
|
243
243
|
width: $hour-width + 4px;
|
|
244
244
|
height: $hour-width + 4px;
|
|
245
245
|
background-color: $hour-color;
|
|
246
246
|
}
|
|
247
|
-
|
|
247
|
+
&::after {
|
|
248
248
|
height: $hour-height;
|
|
249
249
|
width: $hour-width;
|
|
250
250
|
background-color: $hour-color;
|
|
@@ -253,20 +253,20 @@ export default {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
&__hand-hour-hover {
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
&::before,
|
|
257
|
+
&::after {
|
|
258
258
|
background-color: $hour-hover;
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
&__hand-hour-shadow {
|
|
263
263
|
margin-top: 3px;
|
|
264
|
-
|
|
264
|
+
&::before {
|
|
265
265
|
background-color: rgba(black, 0.5);
|
|
266
266
|
box-shadow: 0px 0px 4px black;
|
|
267
267
|
opacity: 0.25;
|
|
268
268
|
}
|
|
269
|
-
|
|
269
|
+
&::after {
|
|
270
270
|
background-color: rgba(black, 0.5);
|
|
271
271
|
box-shadow: 0px 0px 4px black;
|
|
272
272
|
opacity: 0.25;
|
|
@@ -275,12 +275,12 @@ export default {
|
|
|
275
275
|
|
|
276
276
|
&__hand-min,
|
|
277
277
|
&__hand-min-hover {
|
|
278
|
-
|
|
278
|
+
&::before {
|
|
279
279
|
width: $min-width + 2px;
|
|
280
280
|
height: $min-width + 2px;
|
|
281
281
|
background-color: $min-color;
|
|
282
282
|
}
|
|
283
|
-
|
|
283
|
+
&::after {
|
|
284
284
|
height: $min-height;
|
|
285
285
|
width: $min-width;
|
|
286
286
|
background-color: $min-color;
|
|
@@ -289,8 +289,8 @@ export default {
|
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
&__hand-min-hover {
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
&::before,
|
|
293
|
+
&::after {
|
|
294
294
|
background-color: $min-hover;
|
|
295
295
|
}
|
|
296
296
|
}
|
|
@@ -426,7 +426,7 @@ export default {
|
|
|
426
426
|
|
|
427
427
|
&__hour {
|
|
428
428
|
text-align: right;
|
|
429
|
-
|
|
429
|
+
&::before {
|
|
430
430
|
// derive a fixed size from this
|
|
431
431
|
content: '10';
|
|
432
432
|
color: transparent;
|
|
@@ -439,7 +439,7 @@ export default {
|
|
|
439
439
|
|
|
440
440
|
&__min {
|
|
441
441
|
text-align: center;
|
|
442
|
-
|
|
442
|
+
&::before {
|
|
443
443
|
// derive a fixed size from this
|
|
444
444
|
content: '00';
|
|
445
445
|
color: transparent;
|
|
@@ -450,11 +450,11 @@ export default {
|
|
|
450
450
|
}
|
|
451
451
|
}
|
|
452
452
|
|
|
453
|
-
&__hour
|
|
453
|
+
&__hour::after {
|
|
454
454
|
background-color: $hour-color;
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
-
&__min
|
|
457
|
+
&__min::after {
|
|
458
458
|
background-color: $min-color;
|
|
459
459
|
}
|
|
460
460
|
|
package/components/PxResizer.vue
CHANGED
package/components/PxSlides.vue
CHANGED
|
@@ -26,24 +26,43 @@
|
|
|
26
26
|
</div>
|
|
27
27
|
</px-slide-transition>
|
|
28
28
|
</div>
|
|
29
|
+
|
|
30
|
+
<slot name="scrollpreview" :direction="scrollPreview">
|
|
31
|
+
<div :class="bem('scroll-preview', { prev: true, visible: scrollPreview == -1 })">
|
|
32
|
+
<px-icon :src="require('../assets/feather/arrow-left.svg')" :size="2" />
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<div :class="bem('scroll-preview', { next: true, visible: scrollPreview == 1 })">
|
|
36
|
+
<px-icon :src="require('../assets/feather/arrow-right.svg')" :size="2" />
|
|
37
|
+
</div>
|
|
38
|
+
</slot>
|
|
29
39
|
</div>
|
|
30
40
|
</template>
|
|
31
41
|
|
|
32
42
|
<script>
|
|
33
43
|
import PxBaseItemsSelect from './PxBaseItemsSelect.vue';
|
|
34
44
|
import PxSlideTransition from './PxSlideTransition.vue';
|
|
45
|
+
import PxIcon from './PxIcon.vue';
|
|
46
|
+
|
|
35
47
|
import gsap from 'gsap';
|
|
36
48
|
import Drag from '../utils/drag.js';
|
|
49
|
+
import Lethargy from '../utils/lethargy.js';
|
|
37
50
|
|
|
38
51
|
export default {
|
|
39
52
|
name: 'px-slides',
|
|
40
53
|
mixins: [PxBaseItemsSelect],
|
|
41
|
-
components: { PxSlideTransition },
|
|
54
|
+
components: { PxSlideTransition, PxIcon },
|
|
42
55
|
|
|
43
56
|
props: {
|
|
44
57
|
// whether drag interaction is enabled
|
|
45
58
|
dragEnabled: { type: Boolean, default: true },
|
|
46
59
|
|
|
60
|
+
// whether scroll interaction is enabled
|
|
61
|
+
scrollEnabled: { type: Boolean, default: false },
|
|
62
|
+
|
|
63
|
+
// whether to show an icon or other indicator that scrolling has started
|
|
64
|
+
scrollPreviewEnabled: { type: Boolean, default: false },
|
|
65
|
+
|
|
47
66
|
// if true, slides loop to the first slide once last slide is reached
|
|
48
67
|
loop: { type: Boolean, default: true },
|
|
49
68
|
|
|
@@ -61,6 +80,7 @@ export default {
|
|
|
61
80
|
return {
|
|
62
81
|
direction: 1,
|
|
63
82
|
activeTransitions: 0,
|
|
83
|
+
scrollPreview: 0,
|
|
64
84
|
};
|
|
65
85
|
},
|
|
66
86
|
computed: {},
|
|
@@ -101,11 +121,17 @@ export default {
|
|
|
101
121
|
excludeSelector: this.dragExcludeSelector,
|
|
102
122
|
disabled: !this.dragEnabled,
|
|
103
123
|
});
|
|
124
|
+
|
|
125
|
+
if (this.scrollEnabled) {
|
|
126
|
+
this.$el.addEventListener('wheel', this.onWheel);
|
|
127
|
+
}
|
|
104
128
|
},
|
|
105
129
|
beforeDestroy() {
|
|
106
130
|
if (this.drag) {
|
|
107
131
|
this.drag.destroy();
|
|
108
132
|
}
|
|
133
|
+
|
|
134
|
+
this.$el.removeEventListener('wheel', this.onWheel);
|
|
109
135
|
},
|
|
110
136
|
methods: {
|
|
111
137
|
transitionStart() {
|
|
@@ -154,12 +180,48 @@ export default {
|
|
|
154
180
|
}
|
|
155
181
|
},
|
|
156
182
|
|
|
157
|
-
|
|
158
|
-
|
|
183
|
+
onWheel(e) {
|
|
184
|
+
if (typeof this.lethargy == 'undefined') {
|
|
185
|
+
this.lethargy = new Lethargy();
|
|
186
|
+
this.lethargyPrevCheck = false;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (this.scrollPreviewEnabled) {
|
|
190
|
+
const delta = (e.deltaY + e.deltaX) / 2;
|
|
191
|
+
if (Math.abs(delta) > 5) {
|
|
192
|
+
this.scrollPreview = Math.max(Math.min(delta, 1), -1);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
clearTimeout(this.scrollPreviewTimeout);
|
|
196
|
+
this.scrollPreviewTimeout = setTimeout(() => {
|
|
197
|
+
this.scrollPreview = 0;
|
|
198
|
+
}, 200);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const check = this.lethargy.check(e);
|
|
202
|
+
|
|
203
|
+
if (check !== this.lethargyPrevCheck) {
|
|
204
|
+
if (check) {
|
|
205
|
+
if (check > 0) {
|
|
206
|
+
this.previous(false);
|
|
207
|
+
} else {
|
|
208
|
+
this.next(false);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
this.lethargyPrevCheck = check;
|
|
214
|
+
|
|
215
|
+
e.stopPropagation();
|
|
216
|
+
e.preventDefault();
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
next(loopOverride = null) {
|
|
220
|
+
this.selectOffsetSafe(1, loopOverride === null ? this.loop : loopOverride);
|
|
159
221
|
},
|
|
160
222
|
|
|
161
|
-
previous() {
|
|
162
|
-
this.selectOffsetSafe(-1, this.loop);
|
|
223
|
+
previous(loopOverride = null) {
|
|
224
|
+
this.selectOffsetSafe(-1, loopOverride === null ? this.loop : loopOverride);
|
|
163
225
|
},
|
|
164
226
|
|
|
165
227
|
// returns the index of the item relative to the selected item, if looped
|
|
@@ -214,5 +276,40 @@ export default {
|
|
|
214
276
|
width: 100%;
|
|
215
277
|
height: 100%;
|
|
216
278
|
}
|
|
279
|
+
|
|
280
|
+
&__scroll-preview {
|
|
281
|
+
position: absolute;
|
|
282
|
+
top: 50%;
|
|
283
|
+
width: 5em;
|
|
284
|
+
height: 5em;
|
|
285
|
+
border-radius: 50%;
|
|
286
|
+
background-color: rgba(black, 0.07);
|
|
287
|
+
background-color: #f2f2f2;
|
|
288
|
+
backdrop-filter: blur(6px);
|
|
289
|
+
z-index: 100;
|
|
290
|
+
pointer-events: none;
|
|
291
|
+
opacity: 0;
|
|
292
|
+
transform: translate(0, -50%);
|
|
293
|
+
|
|
294
|
+
@include transition(opacity transform, $dur: 500ms);
|
|
295
|
+
@include depth-shadow(55, 0.05);
|
|
296
|
+
|
|
297
|
+
svg {
|
|
298
|
+
@include center();
|
|
299
|
+
color: currentColor;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
&--prev {
|
|
303
|
+
left: 2.5em;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
&--next {
|
|
307
|
+
right: 2.5em;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
&--visible {
|
|
311
|
+
opacity: 1;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
217
314
|
}
|
|
218
315
|
</style>
|
package/components/PxSpinner.vue
CHANGED
|
@@ -85,8 +85,8 @@ export default {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
&__spinner,
|
|
88
|
-
&__spinner
|
|
89
|
-
&__spinner
|
|
88
|
+
&__spinner::before,
|
|
89
|
+
&__spinner::after {
|
|
90
90
|
position: absolute;
|
|
91
91
|
top: -2.5em;
|
|
92
92
|
width: 2.5em;
|
|
@@ -103,17 +103,17 @@ export default {
|
|
|
103
103
|
transform: translateZ(0);
|
|
104
104
|
animation-delay: ($dur * -0.088888888);
|
|
105
105
|
}
|
|
106
|
-
&__spinner
|
|
107
|
-
&__spinner
|
|
106
|
+
&__spinner::before,
|
|
107
|
+
&__spinner::after {
|
|
108
108
|
content: '';
|
|
109
109
|
position: absolute;
|
|
110
110
|
top: 0;
|
|
111
111
|
}
|
|
112
|
-
&__spinner
|
|
112
|
+
&__spinner::before {
|
|
113
113
|
left: -5em;
|
|
114
114
|
animation-delay: ($dur * -0.088888888 * 2);
|
|
115
115
|
}
|
|
116
|
-
&__spinner
|
|
116
|
+
&__spinner::after {
|
|
117
117
|
left: 5em;
|
|
118
118
|
}
|
|
119
119
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thinkpixellab-public/px-vue",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "General purpose Vue components and helpers that can be used across projects.",
|
|
5
5
|
"author": "Pixel Lab",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@floating-ui/dom": "^1.1.1",
|
|
19
|
-
"@thinkpixellab-public/px-styles": "^3.7.
|
|
19
|
+
"@thinkpixellab-public/px-styles": "^3.7.9",
|
|
20
20
|
"@thinkpixellab-public/vue-resize-directive": "^1.2.2",
|
|
21
21
|
"body-scroll-lock": "^4.0.0-beta.0",
|
|
22
22
|
"mitt": "^3.0.0",
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Adapted from here: https://github.com/d4nyll/lethargy
|
|
2
|
+
// MIT License
|
|
3
|
+
|
|
4
|
+
function Lethargy(stability, sensitivity, tolerance, delay) {
|
|
5
|
+
this.stability = stability != null ? Math.abs(stability) : 8;
|
|
6
|
+
this.sensitivity = sensitivity != null ? 1 + Math.abs(sensitivity) : 100;
|
|
7
|
+
this.tolerance = tolerance != null ? 1 + Math.abs(tolerance) : 1.1;
|
|
8
|
+
this.delay = delay != null ? delay : 150;
|
|
9
|
+
this.lastUpDeltas = function () {
|
|
10
|
+
var i, ref, results;
|
|
11
|
+
results = [];
|
|
12
|
+
for (
|
|
13
|
+
i = 1, ref = this.stability * 2;
|
|
14
|
+
1 <= ref ? i <= ref : i >= ref;
|
|
15
|
+
1 <= ref ? i++ : i--
|
|
16
|
+
) {
|
|
17
|
+
results.push(null);
|
|
18
|
+
}
|
|
19
|
+
return results;
|
|
20
|
+
}.call(this);
|
|
21
|
+
this.lastDownDeltas = function () {
|
|
22
|
+
var i, ref, results;
|
|
23
|
+
results = [];
|
|
24
|
+
for (
|
|
25
|
+
i = 1, ref = this.stability * 2;
|
|
26
|
+
1 <= ref ? i <= ref : i >= ref;
|
|
27
|
+
1 <= ref ? i++ : i--
|
|
28
|
+
) {
|
|
29
|
+
results.push(null);
|
|
30
|
+
}
|
|
31
|
+
return results;
|
|
32
|
+
}.call(this);
|
|
33
|
+
this.deltasTimestamp = function () {
|
|
34
|
+
var i, ref, results;
|
|
35
|
+
results = [];
|
|
36
|
+
for (
|
|
37
|
+
i = 1, ref = this.stability * 2;
|
|
38
|
+
1 <= ref ? i <= ref : i >= ref;
|
|
39
|
+
1 <= ref ? i++ : i--
|
|
40
|
+
) {
|
|
41
|
+
results.push(null);
|
|
42
|
+
}
|
|
43
|
+
return results;
|
|
44
|
+
}.call(this);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Lethargy.prototype.check = function (e) {
|
|
48
|
+
var lastDelta;
|
|
49
|
+
e = e.originalEvent || e;
|
|
50
|
+
if (e.wheelDelta != null) {
|
|
51
|
+
lastDelta = e.wheelDelta;
|
|
52
|
+
} else if (e.deltaY != null) {
|
|
53
|
+
lastDelta = e.deltaY * -40;
|
|
54
|
+
} else if (e.detail != null || e.detail === 0) {
|
|
55
|
+
lastDelta = e.detail * -40;
|
|
56
|
+
}
|
|
57
|
+
this.deltasTimestamp.push(Date.now());
|
|
58
|
+
this.deltasTimestamp.shift();
|
|
59
|
+
if (lastDelta > 0) {
|
|
60
|
+
this.lastUpDeltas.push(lastDelta);
|
|
61
|
+
this.lastUpDeltas.shift();
|
|
62
|
+
return this.isInertia(1);
|
|
63
|
+
} else {
|
|
64
|
+
this.lastDownDeltas.push(lastDelta);
|
|
65
|
+
this.lastDownDeltas.shift();
|
|
66
|
+
return this.isInertia(-1);
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
Lethargy.prototype.isInertia = function (direction) {
|
|
72
|
+
var lastDeltas, lastDeltasNew, lastDeltasOld, newAverage, newSum, oldAverage, oldSum;
|
|
73
|
+
lastDeltas = direction === -1 ? this.lastDownDeltas : this.lastUpDeltas;
|
|
74
|
+
if (lastDeltas[0] === null) {
|
|
75
|
+
return direction;
|
|
76
|
+
}
|
|
77
|
+
if (
|
|
78
|
+
this.deltasTimestamp[this.stability * 2 - 2] + this.delay > Date.now() &&
|
|
79
|
+
lastDeltas[0] === lastDeltas[this.stability * 2 - 1]
|
|
80
|
+
) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
lastDeltasOld = lastDeltas.slice(0, this.stability);
|
|
84
|
+
lastDeltasNew = lastDeltas.slice(this.stability, this.stability * 2);
|
|
85
|
+
oldSum = lastDeltasOld.reduce(function (t, s) {
|
|
86
|
+
return t + s;
|
|
87
|
+
});
|
|
88
|
+
newSum = lastDeltasNew.reduce(function (t, s) {
|
|
89
|
+
return t + s;
|
|
90
|
+
});
|
|
91
|
+
oldAverage = oldSum / lastDeltasOld.length;
|
|
92
|
+
newAverage = newSum / lastDeltasNew.length;
|
|
93
|
+
if (
|
|
94
|
+
Math.abs(oldAverage) < Math.abs(newAverage * this.tolerance) &&
|
|
95
|
+
this.sensitivity < Math.abs(newAverage)
|
|
96
|
+
) {
|
|
97
|
+
return direction;
|
|
98
|
+
} else {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
Lethargy.prototype.showLastUpDeltas = function () {
|
|
104
|
+
return this.lastUpDeltas;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
Lethargy.prototype.showLastDownDeltas = function () {
|
|
108
|
+
return this.lastDownDeltas;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export default Lethargy;
|