@thinkpixellab-public/px-vue 3.0.69 → 3.0.71
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/PxBalancedText.vue +8 -0
- package/components/PxBaseActiveTab.vue +50 -0
- package/components/PxFlip.vue +95 -0
- package/components/PxGsapScrubber.vue +7 -4
- package/dev/demos/Demo-PxFlip.vue +108 -0
- package/dev/dev.vue +3 -1
- package/package.json +1 -1
- package/utils/balanceText.js +2 -2
|
@@ -111,10 +111,16 @@ export default {
|
|
|
111
111
|
this.resize();
|
|
112
112
|
});
|
|
113
113
|
},
|
|
114
|
+
html() {
|
|
115
|
+
this.balance();
|
|
116
|
+
},
|
|
114
117
|
},
|
|
115
118
|
|
|
116
119
|
methods: {
|
|
117
120
|
resize() {
|
|
121
|
+
this.balance();
|
|
122
|
+
},
|
|
123
|
+
balance() {
|
|
118
124
|
if (isServer()) {
|
|
119
125
|
return;
|
|
120
126
|
}
|
|
@@ -126,11 +132,13 @@ export default {
|
|
|
126
132
|
|
|
127
133
|
if (this.enabled) {
|
|
128
134
|
try {
|
|
135
|
+
this.$emit('start');
|
|
129
136
|
this.balanceFailed = false;
|
|
130
137
|
if (this.$refs.text && this.$refs.text.offsetWidth > 0) {
|
|
131
138
|
balanceText(this.$refs.text);
|
|
132
139
|
}
|
|
133
140
|
this.balanced = true;
|
|
141
|
+
this.$emit('complete');
|
|
134
142
|
} catch (error) {
|
|
135
143
|
console.error('balanceText failed');
|
|
136
144
|
console.error(error);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
|
|
5
|
+
To perform an action the first time the browser tab becomes active, override the browserTabFirstActive() method.
|
|
6
|
+
|
|
7
|
+
To watch for changes to the browser tab's active state, watch the isBrowserTabActive property.
|
|
8
|
+
|
|
9
|
+
-->
|
|
10
|
+
<script>
|
|
11
|
+
export default {
|
|
12
|
+
data() {
|
|
13
|
+
return { isBrowserTabActive: false, browserTabActivationCount: 0 };
|
|
14
|
+
},
|
|
15
|
+
mounted() {
|
|
16
|
+
if (typeof document == undefined) {
|
|
17
|
+
console.warn('Unable to create visibility change listener. No document object.');
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
document.addEventListener('visibilitychange', this.onTabVisibilityChange);
|
|
22
|
+
this.onTabVisibilityChange();
|
|
23
|
+
},
|
|
24
|
+
beforeDestroy() {
|
|
25
|
+
document.removeEventListener('visibilitychange', this.onTabVisibilityChange);
|
|
26
|
+
},
|
|
27
|
+
methods: {
|
|
28
|
+
onTabVisibilityChange() {
|
|
29
|
+
if (document.visibilityState === 'visible') {
|
|
30
|
+
this.isBrowserTabActive = true;
|
|
31
|
+
this.browserTabActivationCount++;
|
|
32
|
+
|
|
33
|
+
if (this.browserTabActivationCount == 1) {
|
|
34
|
+
if (this.browserTabFirstActive) {
|
|
35
|
+
this.browserTabFirstActive();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
this.isBrowserTabActive = false;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
// OVERRIDE this method to perform an action the first time the browser tab becomes active
|
|
44
|
+
//
|
|
45
|
+
// browserTabFirstActive() {
|
|
46
|
+
// console.log('browser tab first active');}
|
|
47
|
+
// }
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
</script>
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Usage:
|
|
3
|
+
|
|
4
|
+
<px-flip :states="['select', 'interact']" :current="'select'">
|
|
5
|
+
<template :state="state">
|
|
6
|
+
<div :class="bem('container', { state })">
|
|
7
|
+
<div data-pxflip>...</div>
|
|
8
|
+
<div data-pxflip>...</div>
|
|
9
|
+
</div>
|
|
10
|
+
</template>
|
|
11
|
+
</px-flip>
|
|
12
|
+
-->
|
|
13
|
+
|
|
14
|
+
<template>
|
|
15
|
+
<div :class="bem()">
|
|
16
|
+
<!-- in the component -->
|
|
17
|
+
<slot name="default" :state="currentValue">
|
|
18
|
+
<!-- fallback -->
|
|
19
|
+
</slot>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script>
|
|
24
|
+
import { gsap } from 'gsap';
|
|
25
|
+
import { Flip } from 'gsap/Flip';
|
|
26
|
+
|
|
27
|
+
export default {
|
|
28
|
+
name: 'px-flip',
|
|
29
|
+
props: {
|
|
30
|
+
states: { type: Array, default: null },
|
|
31
|
+
current: { type: String, default: null },
|
|
32
|
+
autoSelectFirstState: { type: Boolean, default: true },
|
|
33
|
+
otherProps: { type: String, default: 'opacity,color,backgroundColor' },
|
|
34
|
+
selector: { type: String, default: '[data-flip]' },
|
|
35
|
+
targets: { default: null },
|
|
36
|
+
duration: { type: Number, default: 0.5 },
|
|
37
|
+
ease: { type: String, default: 'circ.out' },
|
|
38
|
+
absolute: { type: Boolean, default: false },
|
|
39
|
+
},
|
|
40
|
+
data() {
|
|
41
|
+
return { currentValue: this.current };
|
|
42
|
+
},
|
|
43
|
+
watch: {
|
|
44
|
+
currentValue(nv) {
|
|
45
|
+
this.$emit('update:current', nv);
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
async current(nv) {
|
|
49
|
+
const targetElements = this.targets || this.$el.querySelectorAll(this.selector);
|
|
50
|
+
|
|
51
|
+
// save initial state
|
|
52
|
+
const state = Flip.getState(targetElements, { props: this.otherProps, absolute: true });
|
|
53
|
+
|
|
54
|
+
// make state changes
|
|
55
|
+
this.currentValue = nv;
|
|
56
|
+
|
|
57
|
+
await this.$nextTick();
|
|
58
|
+
// animate from the old state to the new one
|
|
59
|
+
// animate from the previous state to the current one:
|
|
60
|
+
|
|
61
|
+
Flip.from(state, {
|
|
62
|
+
duration: this.duration,
|
|
63
|
+
ease: this.ease,
|
|
64
|
+
absolute: this.absolute,
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
mounted() {
|
|
69
|
+
gsap.registerPlugin(Flip);
|
|
70
|
+
|
|
71
|
+
if (!this.currentValue && this.autoSelectFirstState && this.states.length) {
|
|
72
|
+
this.currentValue = this.states[0];
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
methods: {
|
|
76
|
+
nextState() {
|
|
77
|
+
if (this.states) {
|
|
78
|
+
const index = this.states.indexOf(this.currentValue);
|
|
79
|
+
if (index >= 0) {
|
|
80
|
+
this.currentValue = this.states[(index + 1) % this.states.length];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
toggle() {
|
|
85
|
+
this.nextState();
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
</script>
|
|
90
|
+
|
|
91
|
+
<style lang="scss">
|
|
92
|
+
.px-flip {
|
|
93
|
+
// add styles here
|
|
94
|
+
}
|
|
95
|
+
</style>
|
|
@@ -81,13 +81,16 @@ export default {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
this.timeline = t;
|
|
84
|
-
this.progress = this.timeline.progress();
|
|
85
|
-
this.isPlaying = !this.timeline.paused();
|
|
86
84
|
|
|
87
|
-
this.timeline
|
|
85
|
+
if (this.timeline) {
|
|
88
86
|
this.progress = this.timeline.progress();
|
|
89
87
|
this.isPlaying = !this.timeline.paused();
|
|
90
|
-
|
|
88
|
+
|
|
89
|
+
this.timeline.eventCallback('onUpdate', () => {
|
|
90
|
+
this.progress = this.timeline.progress();
|
|
91
|
+
this.isPlaying = !this.timeline.paused();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
91
94
|
},
|
|
92
95
|
pause() {
|
|
93
96
|
if (this.timeline) {
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'one | two | 50%'
|
|
2
|
+
<!--
|
|
3
|
+
Describe this component...
|
|
4
|
+
-->
|
|
5
|
+
<template>
|
|
6
|
+
<div :class="bem()">
|
|
7
|
+
<PxFlip ref="flip" :states="['one', 'two']" :current="currentState">
|
|
8
|
+
<template #default="{ state }">
|
|
9
|
+
{{ state }}
|
|
10
|
+
<br />
|
|
11
|
+
<br />
|
|
12
|
+
<div :class="bem('container', { state })">
|
|
13
|
+
<div :class="bem('red')" data-flip />
|
|
14
|
+
<div :class="bem('gold')" data-flip />
|
|
15
|
+
<div :class="bem('blue')" data-flip />
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
</PxFlip>
|
|
19
|
+
<button @click="toggleState">Toggle</button>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script>
|
|
24
|
+
// import { mapState } from 'vuex';
|
|
25
|
+
// import Component from '~/components/Component.vue';
|
|
26
|
+
// import Mixin from '~/components/Mixin.vue';
|
|
27
|
+
|
|
28
|
+
import PxFlip from '../../components/PxFlip.vue';
|
|
29
|
+
|
|
30
|
+
export default {
|
|
31
|
+
name: 'demo-px-flip',
|
|
32
|
+
components: { PxFlip },
|
|
33
|
+
|
|
34
|
+
// mixins: [ Mixin ],
|
|
35
|
+
// props: { a: { type: Boolean, default: false } },
|
|
36
|
+
data() {
|
|
37
|
+
return {
|
|
38
|
+
currentState: 'one',
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
// computed: {},
|
|
42
|
+
// watch: {},
|
|
43
|
+
// mounted() {},
|
|
44
|
+
methods: {
|
|
45
|
+
toggleState() {
|
|
46
|
+
if (this.currentState == 'one') {
|
|
47
|
+
this.currentState = 'two';
|
|
48
|
+
} else {
|
|
49
|
+
this.currentState = 'one';
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<style lang="scss">
|
|
57
|
+
@use '../../styles/px.scss' as *;
|
|
58
|
+
.demo-px-flip {
|
|
59
|
+
padding: 5em;
|
|
60
|
+
&__container {
|
|
61
|
+
width: 200px;
|
|
62
|
+
height: 200px;
|
|
63
|
+
border: 1px solid black;
|
|
64
|
+
|
|
65
|
+
// prettier-ignore
|
|
66
|
+
@include grid-art(
|
|
67
|
+
(
|
|
68
|
+
'50% | 50% | ',
|
|
69
|
+
'red | gold | 50%',
|
|
70
|
+
'blue | blue | 50%'
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
span {
|
|
75
|
+
width: 100%;
|
|
76
|
+
height: 0.5em;
|
|
77
|
+
background-color: currentColor;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
&--state-one {
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
&--state-two {
|
|
84
|
+
// prettier-ignore
|
|
85
|
+
@include grid-art(
|
|
86
|
+
(
|
|
87
|
+
'33% | 67% | ',
|
|
88
|
+
'blue | red | 50%',
|
|
89
|
+
'gold | gold | 50%'
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&__red {
|
|
96
|
+
background-color: tomato;
|
|
97
|
+
grid-area: red;
|
|
98
|
+
}
|
|
99
|
+
&__gold {
|
|
100
|
+
background-color: gold;
|
|
101
|
+
grid-area: gold;
|
|
102
|
+
}
|
|
103
|
+
&__blue {
|
|
104
|
+
background-color: lightblue;
|
|
105
|
+
grid-area: blue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
</style>
|
package/dev/dev.vue
CHANGED
|
@@ -19,6 +19,7 @@ import DemoPxPivot from './demos/Demo-PxPivot.vue';
|
|
|
19
19
|
import DemoPxFloat from './demos/Demo-PxFloat.vue';
|
|
20
20
|
import DemoPxContain from './demos/Demo-PxContain.vue';
|
|
21
21
|
import DemoPxMenu from './demos/Demo-PxMenu.vue';
|
|
22
|
+
import DemoPxFlip from './demos/Demo-PxFlip.vue';
|
|
22
23
|
|
|
23
24
|
export default Vue.extend({
|
|
24
25
|
components: {
|
|
@@ -34,6 +35,7 @@ export default Vue.extend({
|
|
|
34
35
|
DemoPxFloat,
|
|
35
36
|
DemoPxContain,
|
|
36
37
|
DemoPxMenu,
|
|
38
|
+
DemoPxFlip,
|
|
37
39
|
},
|
|
38
40
|
name: 'ServeDev',
|
|
39
41
|
data() {
|
|
@@ -46,7 +48,7 @@ export default Vue.extend({
|
|
|
46
48
|
const params = new Proxy(new URLSearchParams(window.location.search), {
|
|
47
49
|
get: (searchParams, prop) => searchParams.get(prop),
|
|
48
50
|
});
|
|
49
|
-
this.componentToRender = params.component || '
|
|
51
|
+
this.componentToRender = params.component || 'DemoPxFlip';
|
|
50
52
|
console.log(`this.componentToRender: ${this.componentToRender}`);
|
|
51
53
|
},
|
|
52
54
|
});
|
package/package.json
CHANGED
package/utils/balanceText.js
CHANGED
|
@@ -110,8 +110,8 @@ function textElementIsMultipleLines(element) {
|
|
|
110
110
|
// Update the first word variable in the dom
|
|
111
111
|
firstWord = document.getElementById('element-first-word');
|
|
112
112
|
|
|
113
|
-
firstWordHeight = firstWord
|
|
114
|
-
elementHeight = element
|
|
113
|
+
firstWordHeight = firstWord?.offsetHeight;
|
|
114
|
+
elementHeight = element?.offsetHeight;
|
|
115
115
|
|
|
116
116
|
// Restore the original element text
|
|
117
117
|
element.innerHTML = ORIGINAL_ELEMENT_TEXT;
|