masoneffect 0.1.15 → 0.1.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.
- package/README.md +6 -2
- package/package.json +1 -1
- package/src/vue/MasonEffect.vue +113 -164
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ effect.scatter();
|
|
|
41
41
|
#### Using CDN (UMD)
|
|
42
42
|
|
|
43
43
|
```html
|
|
44
|
-
<script src="https://cdn.jsdelivr.net/npm/masoneffect@0.1.
|
|
44
|
+
<script src="https://cdn.jsdelivr.net/npm/masoneffect@0.1.15/dist/index.umd.min.js"></script>
|
|
45
45
|
<script>
|
|
46
46
|
const container = document.getElementById('my-container');
|
|
47
47
|
const effect = new MasonEffect(container, {
|
|
@@ -50,7 +50,11 @@ effect.scatter();
|
|
|
50
50
|
maxParticles: 2000,
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
// Change text
|
|
54
|
+
effect.morph({ text: 'New Text' });
|
|
55
|
+
|
|
56
|
+
// Return particles to initial position
|
|
57
|
+
effect.scatter();
|
|
54
58
|
</script>
|
|
55
59
|
```
|
|
56
60
|
|
package/package.json
CHANGED
package/src/vue/MasonEffect.vue
CHANGED
|
@@ -2,91 +2,93 @@
|
|
|
2
2
|
<div ref="container" :class="className" :style="style"></div>
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
|
-
<script>
|
|
6
|
-
import {
|
|
7
|
-
import { MasonEffect } from '../core/index
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import { ref, onMounted, onBeforeUnmount, watch } from 'vue';
|
|
7
|
+
import { MasonEffect, type MasonEffectOptions } from '../core/index';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
default: 1,
|
|
39
|
-
},
|
|
40
|
-
particleColor: {
|
|
41
|
-
type: String,
|
|
42
|
-
default: '#fff',
|
|
43
|
-
},
|
|
44
|
-
fontFamily: {
|
|
45
|
-
type: String,
|
|
46
|
-
default: 'Inter, system-ui, Arial',
|
|
47
|
-
},
|
|
48
|
-
fontSize: {
|
|
49
|
-
type: Number,
|
|
50
|
-
default: null,
|
|
51
|
-
},
|
|
52
|
-
width: {
|
|
53
|
-
type: Number,
|
|
54
|
-
default: null,
|
|
55
|
-
},
|
|
56
|
-
height: {
|
|
57
|
-
type: Number,
|
|
58
|
-
default: null,
|
|
59
|
-
},
|
|
60
|
-
devicePixelRatio: {
|
|
61
|
-
type: Number,
|
|
62
|
-
default: null,
|
|
63
|
-
},
|
|
64
|
-
className: {
|
|
65
|
-
type: String,
|
|
66
|
-
default: '',
|
|
67
|
-
},
|
|
68
|
-
style: {
|
|
69
|
-
type: Object,
|
|
70
|
-
default: () => ({}),
|
|
71
|
-
},
|
|
72
|
-
onReady: {
|
|
73
|
-
type: Function,
|
|
74
|
-
default: null,
|
|
75
|
-
},
|
|
76
|
-
onUpdate: {
|
|
77
|
-
type: Function,
|
|
78
|
-
default: null,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
emits: ['ready', 'update'],
|
|
82
|
-
setup(props, { expose, emit }) {
|
|
83
|
-
const container = ref(null);
|
|
84
|
-
let instance = null;
|
|
9
|
+
interface Props extends Partial<MasonEffectOptions> {
|
|
10
|
+
className?: string;
|
|
11
|
+
style?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
15
|
+
text: 'mason effect',
|
|
16
|
+
densityStep: 2,
|
|
17
|
+
maxParticles: 3200,
|
|
18
|
+
pointSize: 0.5,
|
|
19
|
+
ease: 0.05,
|
|
20
|
+
repelRadius: 150,
|
|
21
|
+
repelStrength: 1,
|
|
22
|
+
particleColor: '#fff',
|
|
23
|
+
fontFamily: 'Inter, system-ui, Arial',
|
|
24
|
+
fontSize: null,
|
|
25
|
+
width: null,
|
|
26
|
+
height: null,
|
|
27
|
+
devicePixelRatio: null,
|
|
28
|
+
className: '',
|
|
29
|
+
style: () => ({}),
|
|
30
|
+
onReady: null,
|
|
31
|
+
onUpdate: null,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const emit = defineEmits<{
|
|
35
|
+
ready: [instance: MasonEffect];
|
|
36
|
+
update: [instance: MasonEffect];
|
|
37
|
+
}>();
|
|
85
38
|
|
|
86
|
-
|
|
87
|
-
|
|
39
|
+
const container = ref<HTMLElement | null>(null);
|
|
40
|
+
let instance: MasonEffect | null = null;
|
|
88
41
|
|
|
89
|
-
|
|
42
|
+
const init = () => {
|
|
43
|
+
if (!container.value) return;
|
|
44
|
+
|
|
45
|
+
const options: MasonEffectOptions = {
|
|
46
|
+
text: props.text,
|
|
47
|
+
densityStep: props.densityStep,
|
|
48
|
+
maxParticles: props.maxParticles,
|
|
49
|
+
pointSize: props.pointSize,
|
|
50
|
+
ease: props.ease,
|
|
51
|
+
repelRadius: props.repelRadius,
|
|
52
|
+
repelStrength: props.repelStrength,
|
|
53
|
+
particleColor: props.particleColor,
|
|
54
|
+
fontFamily: props.fontFamily,
|
|
55
|
+
fontSize: props.fontSize,
|
|
56
|
+
width: props.width,
|
|
57
|
+
height: props.height,
|
|
58
|
+
devicePixelRatio: props.devicePixelRatio,
|
|
59
|
+
onReady: (inst) => {
|
|
60
|
+
if (props.onReady) props.onReady(inst);
|
|
61
|
+
emit('ready', inst);
|
|
62
|
+
},
|
|
63
|
+
onUpdate: (inst) => {
|
|
64
|
+
if (props.onUpdate) props.onUpdate(inst);
|
|
65
|
+
emit('update', inst);
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
instance = new MasonEffect(container.value, options);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// props 변경 감지
|
|
73
|
+
watch(
|
|
74
|
+
() => [
|
|
75
|
+
props.text,
|
|
76
|
+
props.densityStep,
|
|
77
|
+
props.maxParticles,
|
|
78
|
+
props.pointSize,
|
|
79
|
+
props.ease,
|
|
80
|
+
props.repelRadius,
|
|
81
|
+
props.repelStrength,
|
|
82
|
+
props.particleColor,
|
|
83
|
+
props.fontFamily,
|
|
84
|
+
props.fontSize,
|
|
85
|
+
props.width,
|
|
86
|
+
props.height,
|
|
87
|
+
props.devicePixelRatio,
|
|
88
|
+
],
|
|
89
|
+
() => {
|
|
90
|
+
if (instance) {
|
|
91
|
+
instance.updateConfig({
|
|
90
92
|
text: props.text,
|
|
91
93
|
densityStep: props.densityStep,
|
|
92
94
|
maxParticles: props.maxParticles,
|
|
@@ -100,91 +102,38 @@ export default defineComponent({
|
|
|
100
102
|
width: props.width,
|
|
101
103
|
height: props.height,
|
|
102
104
|
devicePixelRatio: props.devicePixelRatio,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
onUpdate: (inst) => {
|
|
108
|
-
if (props.onUpdate) props.onUpdate(inst);
|
|
109
|
-
emit('update', inst);
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
instance = new MasonEffect(container.value, options);
|
|
114
|
-
};
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
);
|
|
115
109
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
props.text,
|
|
120
|
-
props.densityStep,
|
|
121
|
-
props.maxParticles,
|
|
122
|
-
props.pointSize,
|
|
123
|
-
props.ease,
|
|
124
|
-
props.repelRadius,
|
|
125
|
-
props.repelStrength,
|
|
126
|
-
props.particleColor,
|
|
127
|
-
props.fontFamily,
|
|
128
|
-
props.fontSize,
|
|
129
|
-
props.width,
|
|
130
|
-
props.height,
|
|
131
|
-
props.devicePixelRatio,
|
|
132
|
-
],
|
|
133
|
-
() => {
|
|
134
|
-
if (instance) {
|
|
135
|
-
instance.updateConfig({
|
|
136
|
-
text: props.text,
|
|
137
|
-
densityStep: props.densityStep,
|
|
138
|
-
maxParticles: props.maxParticles,
|
|
139
|
-
pointSize: props.pointSize,
|
|
140
|
-
ease: props.ease,
|
|
141
|
-
repelRadius: props.repelRadius,
|
|
142
|
-
repelStrength: props.repelStrength,
|
|
143
|
-
particleColor: props.particleColor,
|
|
144
|
-
fontFamily: props.fontFamily,
|
|
145
|
-
fontSize: props.fontSize,
|
|
146
|
-
width: props.width,
|
|
147
|
-
height: props.height,
|
|
148
|
-
devicePixelRatio: props.devicePixelRatio,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
onMounted(() => {
|
|
155
|
-
init();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
onBeforeUnmount(() => {
|
|
159
|
-
if (instance) {
|
|
160
|
-
instance.destroy();
|
|
161
|
-
instance = null;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
110
|
+
onMounted(() => {
|
|
111
|
+
init();
|
|
112
|
+
});
|
|
164
113
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (instance) instance.scatter();
|
|
172
|
-
},
|
|
173
|
-
updateConfig: (config) => {
|
|
174
|
-
if (instance) instance.updateConfig(config);
|
|
175
|
-
},
|
|
176
|
-
destroy: () => {
|
|
177
|
-
if (instance) {
|
|
178
|
-
instance.destroy();
|
|
179
|
-
instance = null;
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
});
|
|
114
|
+
onBeforeUnmount(() => {
|
|
115
|
+
if (instance) {
|
|
116
|
+
instance.destroy();
|
|
117
|
+
instance = null;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
183
120
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
121
|
+
// 외부에서 사용할 수 있는 메서드 노출
|
|
122
|
+
defineExpose({
|
|
123
|
+
morph: (textOrOptions?: string | Partial<MasonEffectOptions>) => {
|
|
124
|
+
if (instance) instance.morph(textOrOptions);
|
|
125
|
+
},
|
|
126
|
+
scatter: () => {
|
|
127
|
+
if (instance) instance.scatter();
|
|
128
|
+
},
|
|
129
|
+
updateConfig: (config: Partial<MasonEffectOptions>) => {
|
|
130
|
+
if (instance) instance.updateConfig(config);
|
|
131
|
+
},
|
|
132
|
+
destroy: () => {
|
|
133
|
+
if (instance) {
|
|
134
|
+
instance.destroy();
|
|
135
|
+
instance = null;
|
|
136
|
+
}
|
|
187
137
|
},
|
|
188
138
|
});
|
|
189
139
|
</script>
|
|
190
|
-
|