masoneffect 0.1.16 → 0.1.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "masoneffect",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "파티클 모핑 효과를 제공하는 라이브러리 - React, Vue, 바닐라 JS 지원",
5
5
  "main": "dist/index.min.js",
6
6
  "module": "dist/index.esm.min.js",
@@ -2,91 +2,94 @@
2
2
  <div ref="container" :class="className" :style="style"></div>
3
3
  </template>
4
4
 
5
- <script>
6
- import { defineComponent, ref, onMounted, onBeforeUnmount, watch } from 'vue';
7
- import { MasonEffect } from '../core/index.js';
5
+ <script setup lang="ts">
6
+ import { ref, onMounted, onBeforeUnmount, watch } from 'vue';
7
+ import { MasonEffect } from '../core/index';
8
+ import type { MasonEffectOptions } from '../core/index';
8
9
 
9
- export default defineComponent({
10
- name: 'MasonEffect',
11
- props: {
12
- text: {
13
- type: String,
14
- default: 'mason effect',
15
- },
16
- densityStep: {
17
- type: Number,
18
- default: 2,
19
- },
20
- maxParticles: {
21
- type: Number,
22
- default: 3200,
23
- },
24
- pointSize: {
25
- type: Number,
26
- default: 0.5,
27
- },
28
- ease: {
29
- type: Number,
30
- default: 0.05,
31
- },
32
- repelRadius: {
33
- type: Number,
34
- default: 150,
35
- },
36
- repelStrength: {
37
- type: Number,
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;
10
+ interface Props extends Partial<MasonEffectOptions> {
11
+ className?: string;
12
+ style?: Record<string, any>;
13
+ }
14
+
15
+ const props = withDefaults(defineProps<Props>(), {
16
+ text: 'mason effect',
17
+ densityStep: 2,
18
+ maxParticles: 3200,
19
+ pointSize: 0.5,
20
+ ease: 0.05,
21
+ repelRadius: 150,
22
+ repelStrength: 1,
23
+ particleColor: '#fff',
24
+ fontFamily: 'Inter, system-ui, Arial',
25
+ fontSize: null,
26
+ width: null,
27
+ height: null,
28
+ devicePixelRatio: null,
29
+ className: '',
30
+ style: () => ({}),
31
+ onReady: null,
32
+ onUpdate: null,
33
+ });
34
+
35
+ const emit = defineEmits<{
36
+ ready: [instance: MasonEffect];
37
+ update: [instance: MasonEffect];
38
+ }>();
85
39
 
86
- const init = () => {
87
- if (!container.value) return;
40
+ const container = ref<HTMLElement | null>(null);
41
+ let instance: MasonEffect | null = null;
88
42
 
89
- const options = {
43
+ const init = () => {
44
+ if (!container.value) return;
45
+
46
+ const options: MasonEffectOptions = {
47
+ text: props.text,
48
+ densityStep: props.densityStep,
49
+ maxParticles: props.maxParticles,
50
+ pointSize: props.pointSize,
51
+ ease: props.ease,
52
+ repelRadius: props.repelRadius,
53
+ repelStrength: props.repelStrength,
54
+ particleColor: props.particleColor,
55
+ fontFamily: props.fontFamily,
56
+ fontSize: props.fontSize,
57
+ width: props.width,
58
+ height: props.height,
59
+ devicePixelRatio: props.devicePixelRatio,
60
+ onReady: (inst) => {
61
+ if (props.onReady) props.onReady(inst);
62
+ emit('ready', inst);
63
+ },
64
+ onUpdate: (inst) => {
65
+ if (props.onUpdate) props.onUpdate(inst);
66
+ emit('update', inst);
67
+ },
68
+ };
69
+
70
+ instance = new MasonEffect(container.value, options);
71
+ };
72
+
73
+ // props 변경 감지
74
+ watch(
75
+ () => [
76
+ props.text,
77
+ props.densityStep,
78
+ props.maxParticles,
79
+ props.pointSize,
80
+ props.ease,
81
+ props.repelRadius,
82
+ props.repelStrength,
83
+ props.particleColor,
84
+ props.fontFamily,
85
+ props.fontSize,
86
+ props.width,
87
+ props.height,
88
+ props.devicePixelRatio,
89
+ ],
90
+ () => {
91
+ if (instance) {
92
+ instance.updateConfig({
90
93
  text: props.text,
91
94
  densityStep: props.densityStep,
92
95
  maxParticles: props.maxParticles,
@@ -100,91 +103,38 @@ export default defineComponent({
100
103
  width: props.width,
101
104
  height: props.height,
102
105
  devicePixelRatio: props.devicePixelRatio,
103
- onReady: (inst) => {
104
- if (props.onReady) props.onReady(inst);
105
- emit('ready', inst);
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
- };
106
+ });
107
+ }
108
+ }
109
+ );
115
110
 
116
- // props 변경 감지
117
- watch(
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
- });
111
+ onMounted(() => {
112
+ init();
113
+ });
164
114
 
165
- // 외부에서 사용할 수 있는 메서드 노출
166
- expose({
167
- morph: (text) => {
168
- if (instance) instance.morph(text);
169
- },
170
- scatter: () => {
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
- });
115
+ onBeforeUnmount(() => {
116
+ if (instance) {
117
+ instance.destroy();
118
+ instance = null;
119
+ }
120
+ });
183
121
 
184
- return {
185
- container,
186
- };
122
+ // 외부에서 사용할 수 있는 메서드 노출
123
+ defineExpose({
124
+ morph: (textOrOptions?: string | Partial<MasonEffectOptions>) => {
125
+ if (instance) instance.morph(textOrOptions);
126
+ },
127
+ scatter: () => {
128
+ if (instance) instance.scatter();
129
+ },
130
+ updateConfig: (config: Partial<MasonEffectOptions>) => {
131
+ if (instance) instance.updateConfig(config);
132
+ },
133
+ destroy: () => {
134
+ if (instance) {
135
+ instance.destroy();
136
+ instance = null;
137
+ }
187
138
  },
188
139
  });
189
140
  </script>
190
-