masoneffect 0.1.0
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/LICENSE +22 -0
- package/README.md +160 -0
- package/dist/index.esm.js +318 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.esm.min.js +1 -0
- package/dist/index.js +323 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +1 -0
- package/dist/index.umd.js +329 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/index.umd.min.js +1 -0
- package/dist/react/MasonEffect.cjs +408 -0
- package/dist/react/MasonEffect.cjs.map +1 -0
- package/dist/react/MasonEffect.d.ts +32 -0
- package/dist/react/MasonEffect.d.ts.map +1 -0
- package/dist/react/MasonEffect.js +406 -0
- package/dist/react/MasonEffect.js.map +1 -0
- package/dist/react/MasonEffect.min.cjs +1 -0
- package/dist/react/MasonEffect.min.js +1 -0
- package/dist/react/react/MasonEffect.d.ts +32 -0
- package/dist/react/react/MasonEffect.d.ts.map +1 -0
- package/package.json +79 -0
- package/src/core/index.d.ts +59 -0
- package/src/core/index.js +319 -0
- package/src/index.js +7 -0
- package/src/react/MasonEffect.tsx +170 -0
- package/src/react/index.js +2 -0
- package/src/vue/MasonEffect.vue +190 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import React, { forwardRef, useRef, useEffect, useImperativeHandle } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MasonEffect - 파티클 모핑 효과 라이브러리
|
|
5
|
+
* 바닐라 JS 코어 클래스
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
class MasonEffect {
|
|
9
|
+
constructor(container, options = {}) {
|
|
10
|
+
// 컨테이너 요소
|
|
11
|
+
this.container = typeof container === 'string'
|
|
12
|
+
? document.querySelector(container)
|
|
13
|
+
: container;
|
|
14
|
+
|
|
15
|
+
if (!this.container) {
|
|
16
|
+
throw new Error('Container element not found');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 설정값들
|
|
20
|
+
this.config = {
|
|
21
|
+
text: options.text || 'mason crawler',
|
|
22
|
+
densityStep: options.densityStep ?? 2,
|
|
23
|
+
maxParticles: options.maxParticles ?? 3200,
|
|
24
|
+
pointSize: options.pointSize ?? 0.5,
|
|
25
|
+
ease: options.ease ?? 0.05,
|
|
26
|
+
repelRadius: options.repelRadius ?? 150,
|
|
27
|
+
repelStrength: options.repelStrength ?? 1,
|
|
28
|
+
particleColor: options.particleColor || '#fff',
|
|
29
|
+
fontFamily: options.fontFamily || 'Inter, system-ui, Arial',
|
|
30
|
+
fontSize: options.fontSize || null, // null이면 자동 계산
|
|
31
|
+
width: options.width || null, // null이면 컨테이너 크기
|
|
32
|
+
height: options.height || null, // null이면 컨테이너 크기
|
|
33
|
+
devicePixelRatio: options.devicePixelRatio ?? null, // null이면 자동
|
|
34
|
+
onReady: options.onReady || null,
|
|
35
|
+
onUpdate: options.onUpdate || null,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// 캔버스 생성
|
|
39
|
+
this.canvas = document.createElement('canvas');
|
|
40
|
+
this.ctx = this.canvas.getContext('2d');
|
|
41
|
+
this.container.appendChild(this.canvas);
|
|
42
|
+
this.canvas.style.display = 'block';
|
|
43
|
+
|
|
44
|
+
// 오프스크린 캔버스 (텍스트 렌더링용)
|
|
45
|
+
this.offCanvas = document.createElement('canvas');
|
|
46
|
+
this.offCtx = this.offCanvas.getContext('2d');
|
|
47
|
+
|
|
48
|
+
// 상태
|
|
49
|
+
this.W = 0;
|
|
50
|
+
this.H = 0;
|
|
51
|
+
this.DPR = this.config.devicePixelRatio || Math.min(window.devicePixelRatio || 1, 1.8);
|
|
52
|
+
this.particles = [];
|
|
53
|
+
this.mouse = { x: 0, y: 0, down: false };
|
|
54
|
+
this.animationId = null;
|
|
55
|
+
this.isRunning = false;
|
|
56
|
+
|
|
57
|
+
// 이벤트 핸들러 바인딩
|
|
58
|
+
this.handleResize = this.handleResize.bind(this);
|
|
59
|
+
this.handleMouseMove = this.handleMouseMove.bind(this);
|
|
60
|
+
this.handleMouseLeave = this.handleMouseLeave.bind(this);
|
|
61
|
+
this.handleMouseDown = this.handleMouseDown.bind(this);
|
|
62
|
+
this.handleMouseUp = this.handleMouseUp.bind(this);
|
|
63
|
+
|
|
64
|
+
// 초기화
|
|
65
|
+
this.init();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
init() {
|
|
69
|
+
this.resize();
|
|
70
|
+
this.setupEventListeners();
|
|
71
|
+
this.start();
|
|
72
|
+
|
|
73
|
+
if (this.config.onReady) {
|
|
74
|
+
this.config.onReady(this);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
resize() {
|
|
79
|
+
const width = this.config.width || this.container.clientWidth || window.innerWidth;
|
|
80
|
+
const height = this.config.height || this.container.clientHeight || window.innerHeight * 0.7;
|
|
81
|
+
|
|
82
|
+
this.W = Math.floor(width * this.DPR);
|
|
83
|
+
this.H = Math.floor(height * this.DPR);
|
|
84
|
+
|
|
85
|
+
this.canvas.width = this.W;
|
|
86
|
+
this.canvas.height = this.H;
|
|
87
|
+
this.canvas.style.width = width + 'px';
|
|
88
|
+
this.canvas.style.height = height + 'px';
|
|
89
|
+
|
|
90
|
+
this.buildTargets();
|
|
91
|
+
if (!this.particles.length) {
|
|
92
|
+
this.initParticles();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
buildTargets() {
|
|
97
|
+
const text = this.config.text;
|
|
98
|
+
this.offCanvas.width = this.W;
|
|
99
|
+
this.offCanvas.height = this.H;
|
|
100
|
+
this.offCtx.clearRect(0, 0, this.offCanvas.width, this.offCanvas.height);
|
|
101
|
+
|
|
102
|
+
const base = Math.min(this.W, this.H);
|
|
103
|
+
const fontSize = this.config.fontSize || Math.max(80, Math.floor(base * 0.18));
|
|
104
|
+
this.offCtx.fillStyle = '#ffffff';
|
|
105
|
+
this.offCtx.textAlign = 'center';
|
|
106
|
+
this.offCtx.textBaseline = 'middle';
|
|
107
|
+
this.offCtx.font = `400 ${fontSize}px ${this.config.fontFamily}`;
|
|
108
|
+
|
|
109
|
+
// 글자 간격 계산 및 그리기
|
|
110
|
+
const chars = text.split('');
|
|
111
|
+
const spacing = fontSize * 0.05;
|
|
112
|
+
const totalWidth = this.offCtx.measureText(text).width + spacing * (chars.length - 1);
|
|
113
|
+
let x = this.W / 2 - totalWidth / 2;
|
|
114
|
+
|
|
115
|
+
for (const ch of chars) {
|
|
116
|
+
this.offCtx.fillText(ch, x + this.offCtx.measureText(ch).width / 2, this.H / 2);
|
|
117
|
+
x += this.offCtx.measureText(ch).width + spacing;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 픽셀 샘플링
|
|
121
|
+
const step = Math.max(2, this.config.densityStep);
|
|
122
|
+
const img = this.offCtx.getImageData(0, 0, this.W, this.H).data;
|
|
123
|
+
const targets = [];
|
|
124
|
+
|
|
125
|
+
for (let y = 0; y < this.H; y += step) {
|
|
126
|
+
for (let x = 0; x < this.W; x += step) {
|
|
127
|
+
const i = (y * this.W + x) * 4;
|
|
128
|
+
if (img[i] + img[i + 1] + img[i + 2] > 600) {
|
|
129
|
+
targets.push({ x, y });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 파티클 수 제한
|
|
135
|
+
while (targets.length > this.config.maxParticles) {
|
|
136
|
+
targets.splice(Math.floor(Math.random() * targets.length), 1);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 파티클 수 조정
|
|
140
|
+
if (this.particles.length < targets.length) {
|
|
141
|
+
const need = targets.length - this.particles.length;
|
|
142
|
+
for (let i = 0; i < need; i++) {
|
|
143
|
+
this.particles.push(this.makeParticle());
|
|
144
|
+
}
|
|
145
|
+
} else if (this.particles.length > targets.length) {
|
|
146
|
+
this.particles.length = targets.length;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 목표 좌표 할당
|
|
150
|
+
for (let i = 0; i < this.particles.length; i++) {
|
|
151
|
+
const p = this.particles[i];
|
|
152
|
+
const t = targets[i];
|
|
153
|
+
p.tx = t.x;
|
|
154
|
+
p.ty = t.y;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
makeParticle() {
|
|
159
|
+
const m = 0.12;
|
|
160
|
+
const sx = (m + Math.random() * (1 - 2 * m)) * this.W;
|
|
161
|
+
const sy = (m + Math.random() * (1 - 2 * m)) * this.H;
|
|
162
|
+
return {
|
|
163
|
+
x: sx,
|
|
164
|
+
y: sy,
|
|
165
|
+
vx: 0,
|
|
166
|
+
vy: 0,
|
|
167
|
+
tx: sx,
|
|
168
|
+
ty: sy,
|
|
169
|
+
j: Math.random() * Math.PI * 2,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
initParticles() {
|
|
174
|
+
for (const p of this.particles) {
|
|
175
|
+
p.x = (0.12 + Math.random() * 1.76) * this.W;
|
|
176
|
+
p.y = (0.12 + Math.random() * 1.76) * this.H;
|
|
177
|
+
p.vx = p.vy = 0;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
scatter() {
|
|
182
|
+
for (const p of this.particles) {
|
|
183
|
+
p.tx = (0.12 + Math.random() * 1.76) * this.W;
|
|
184
|
+
p.ty = (0.12 + Math.random() * 1.76) * this.H;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
morph(text = null) {
|
|
189
|
+
if (text) {
|
|
190
|
+
this.config.text = text;
|
|
191
|
+
}
|
|
192
|
+
this.buildTargets();
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
update() {
|
|
196
|
+
this.ctx.clearRect(0, 0, this.W, this.H);
|
|
197
|
+
|
|
198
|
+
for (const p of this.particles) {
|
|
199
|
+
// 목표 좌표로 당기는 힘
|
|
200
|
+
let ax = (p.tx - p.x) * this.config.ease;
|
|
201
|
+
let ay = (p.ty - p.y) * this.config.ease;
|
|
202
|
+
|
|
203
|
+
// 마우스 반발/흡입
|
|
204
|
+
if (this.mouse.x || this.mouse.y) {
|
|
205
|
+
const dx = p.x - this.mouse.x;
|
|
206
|
+
const dy = p.y - this.mouse.y;
|
|
207
|
+
const d2 = dx * dx + dy * dy;
|
|
208
|
+
const r = this.config.repelRadius * this.DPR;
|
|
209
|
+
if (d2 < r * r) {
|
|
210
|
+
const d = Math.sqrt(d2) + 0.0001;
|
|
211
|
+
const f = (this.mouse.down ? -1 : 1) * this.config.repelStrength * (1 - d / r);
|
|
212
|
+
ax += (dx / d) * f * 6.0;
|
|
213
|
+
ay += (dy / d) * f * 6.0;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// 진동 효과
|
|
218
|
+
p.j += 2;
|
|
219
|
+
ax += Math.cos(p.j) * 0.05;
|
|
220
|
+
ay += Math.sin(p.j * 1.3) * 0.05;
|
|
221
|
+
|
|
222
|
+
// 속도와 위치 업데이트
|
|
223
|
+
p.vx = (p.vx + ax) * Math.random();
|
|
224
|
+
p.vy = (p.vy + ay) * Math.random();
|
|
225
|
+
p.x += p.vx;
|
|
226
|
+
p.y += p.vy;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// 파티클 그리기
|
|
230
|
+
this.ctx.fillStyle = this.config.particleColor;
|
|
231
|
+
const r = this.config.pointSize * this.DPR;
|
|
232
|
+
for (const p of this.particles) {
|
|
233
|
+
this.ctx.beginPath();
|
|
234
|
+
this.ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
|
|
235
|
+
this.ctx.fill();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (this.config.onUpdate) {
|
|
239
|
+
this.config.onUpdate(this);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
animate() {
|
|
244
|
+
if (!this.isRunning) return;
|
|
245
|
+
this.update();
|
|
246
|
+
this.animationId = requestAnimationFrame(() => this.animate());
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
start() {
|
|
250
|
+
if (this.isRunning) return;
|
|
251
|
+
this.isRunning = true;
|
|
252
|
+
this.animate();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
stop() {
|
|
256
|
+
this.isRunning = false;
|
|
257
|
+
if (this.animationId) {
|
|
258
|
+
cancelAnimationFrame(this.animationId);
|
|
259
|
+
this.animationId = null;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
setupEventListeners() {
|
|
264
|
+
window.addEventListener('resize', this.handleResize);
|
|
265
|
+
this.canvas.addEventListener('mousemove', this.handleMouseMove);
|
|
266
|
+
this.canvas.addEventListener('mouseleave', this.handleMouseLeave);
|
|
267
|
+
this.canvas.addEventListener('mousedown', this.handleMouseDown);
|
|
268
|
+
window.addEventListener('mouseup', this.handleMouseUp);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
removeEventListeners() {
|
|
272
|
+
window.removeEventListener('resize', this.handleResize);
|
|
273
|
+
this.canvas.removeEventListener('mousemove', this.handleMouseMove);
|
|
274
|
+
this.canvas.removeEventListener('mouseleave', this.handleMouseLeave);
|
|
275
|
+
this.canvas.removeEventListener('mousedown', this.handleMouseDown);
|
|
276
|
+
window.removeEventListener('mouseup', this.handleMouseUp);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
handleResize() {
|
|
280
|
+
this.resize();
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
handleMouseMove(e) {
|
|
284
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
285
|
+
this.mouse.x = (e.clientX - rect.left) * this.DPR;
|
|
286
|
+
this.mouse.y = (e.clientY - rect.top) * this.DPR;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
handleMouseLeave() {
|
|
290
|
+
this.mouse.x = this.mouse.y = 0;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
handleMouseDown() {
|
|
294
|
+
this.mouse.down = true;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
handleMouseUp() {
|
|
298
|
+
this.mouse.down = false;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// 설정 업데이트
|
|
302
|
+
updateConfig(newConfig) {
|
|
303
|
+
this.config = { ...this.config, ...newConfig };
|
|
304
|
+
if (newConfig.text) {
|
|
305
|
+
this.buildTargets();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// 파괴 및 정리
|
|
310
|
+
destroy() {
|
|
311
|
+
this.stop();
|
|
312
|
+
this.removeEventListeners();
|
|
313
|
+
if (this.canvas && this.canvas.parentNode) {
|
|
314
|
+
this.canvas.parentNode.removeChild(this.canvas);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const MasonEffectComponent = forwardRef((props, ref) => {
|
|
320
|
+
const containerRef = useRef(null);
|
|
321
|
+
const instanceRef = useRef(null);
|
|
322
|
+
useEffect(() => {
|
|
323
|
+
if (!containerRef.current)
|
|
324
|
+
return;
|
|
325
|
+
const { className, style, text, densityStep, maxParticles, pointSize, ease, repelRadius, repelStrength, particleColor, fontFamily, fontSize, width, height, devicePixelRatio, onReady, onUpdate, } = props;
|
|
326
|
+
const options = {
|
|
327
|
+
text,
|
|
328
|
+
densityStep,
|
|
329
|
+
maxParticles,
|
|
330
|
+
pointSize,
|
|
331
|
+
ease,
|
|
332
|
+
repelRadius,
|
|
333
|
+
repelStrength,
|
|
334
|
+
particleColor,
|
|
335
|
+
fontFamily,
|
|
336
|
+
fontSize,
|
|
337
|
+
width,
|
|
338
|
+
height,
|
|
339
|
+
devicePixelRatio,
|
|
340
|
+
onReady,
|
|
341
|
+
onUpdate,
|
|
342
|
+
};
|
|
343
|
+
instanceRef.current = new MasonEffect(containerRef.current, options);
|
|
344
|
+
return () => {
|
|
345
|
+
if (instanceRef.current) {
|
|
346
|
+
instanceRef.current.destroy();
|
|
347
|
+
instanceRef.current = null;
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
}, []);
|
|
351
|
+
// props 변경 시 설정 업데이트
|
|
352
|
+
useEffect(() => {
|
|
353
|
+
if (!instanceRef.current)
|
|
354
|
+
return;
|
|
355
|
+
const { text, densityStep, maxParticles, pointSize, ease, repelRadius, repelStrength, particleColor, fontFamily, fontSize, width, height, devicePixelRatio, } = props;
|
|
356
|
+
instanceRef.current.updateConfig({
|
|
357
|
+
text,
|
|
358
|
+
densityStep,
|
|
359
|
+
maxParticles,
|
|
360
|
+
pointSize,
|
|
361
|
+
ease,
|
|
362
|
+
repelRadius,
|
|
363
|
+
repelStrength,
|
|
364
|
+
particleColor,
|
|
365
|
+
fontFamily,
|
|
366
|
+
fontSize,
|
|
367
|
+
width,
|
|
368
|
+
height,
|
|
369
|
+
devicePixelRatio,
|
|
370
|
+
});
|
|
371
|
+
}, [
|
|
372
|
+
props.text,
|
|
373
|
+
props.densityStep,
|
|
374
|
+
props.maxParticles,
|
|
375
|
+
props.pointSize,
|
|
376
|
+
props.ease,
|
|
377
|
+
props.repelRadius,
|
|
378
|
+
props.repelStrength,
|
|
379
|
+
props.particleColor,
|
|
380
|
+
props.fontFamily,
|
|
381
|
+
props.fontSize,
|
|
382
|
+
props.width,
|
|
383
|
+
props.height,
|
|
384
|
+
props.devicePixelRatio,
|
|
385
|
+
]);
|
|
386
|
+
useImperativeHandle(ref, () => ({
|
|
387
|
+
morph: (text) => {
|
|
388
|
+
instanceRef.current?.morph(text);
|
|
389
|
+
},
|
|
390
|
+
scatter: () => {
|
|
391
|
+
instanceRef.current?.scatter();
|
|
392
|
+
},
|
|
393
|
+
updateConfig: (config) => {
|
|
394
|
+
instanceRef.current?.updateConfig(config);
|
|
395
|
+
},
|
|
396
|
+
destroy: () => {
|
|
397
|
+
instanceRef.current?.destroy();
|
|
398
|
+
instanceRef.current = null;
|
|
399
|
+
},
|
|
400
|
+
}));
|
|
401
|
+
return (React.createElement("div", { ref: containerRef, className: props.className, style: props.style }));
|
|
402
|
+
});
|
|
403
|
+
MasonEffectComponent.displayName = 'MasonEffect';
|
|
404
|
+
|
|
405
|
+
export { MasonEffectComponent as default };
|
|
406
|
+
//# sourceMappingURL=MasonEffect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MasonEffect.js","sources":["../../src/core/index.js","../../src/react/MasonEffect.tsx"],"sourcesContent":["/**\n * MasonEffect - 파티클 모핑 효과 라이브러리\n * 바닐라 JS 코어 클래스\n */\n\nexport class MasonEffect {\n constructor(container, options = {}) {\n // 컨테이너 요소\n this.container = typeof container === 'string' \n ? document.querySelector(container) \n : container;\n \n if (!this.container) {\n throw new Error('Container element not found');\n }\n\n // 설정값들\n this.config = {\n text: options.text || 'mason crawler',\n densityStep: options.densityStep ?? 2,\n maxParticles: options.maxParticles ?? 3200,\n pointSize: options.pointSize ?? 0.5,\n ease: options.ease ?? 0.05,\n repelRadius: options.repelRadius ?? 150,\n repelStrength: options.repelStrength ?? 1,\n particleColor: options.particleColor || '#fff',\n fontFamily: options.fontFamily || 'Inter, system-ui, Arial',\n fontSize: options.fontSize || null, // null이면 자동 계산\n width: options.width || null, // null이면 컨테이너 크기\n height: options.height || null, // null이면 컨테이너 크기\n devicePixelRatio: options.devicePixelRatio ?? null, // null이면 자동\n onReady: options.onReady || null,\n onUpdate: options.onUpdate || null,\n };\n\n // 캔버스 생성\n this.canvas = document.createElement('canvas');\n this.ctx = this.canvas.getContext('2d');\n this.container.appendChild(this.canvas);\n this.canvas.style.display = 'block';\n\n // 오프스크린 캔버스 (텍스트 렌더링용)\n this.offCanvas = document.createElement('canvas');\n this.offCtx = this.offCanvas.getContext('2d');\n\n // 상태\n this.W = 0;\n this.H = 0;\n this.DPR = this.config.devicePixelRatio || Math.min(window.devicePixelRatio || 1, 1.8);\n this.particles = [];\n this.mouse = { x: 0, y: 0, down: false };\n this.animationId = null;\n this.isRunning = false;\n\n // 이벤트 핸들러 바인딩\n this.handleResize = this.handleResize.bind(this);\n this.handleMouseMove = this.handleMouseMove.bind(this);\n this.handleMouseLeave = this.handleMouseLeave.bind(this);\n this.handleMouseDown = this.handleMouseDown.bind(this);\n this.handleMouseUp = this.handleMouseUp.bind(this);\n\n // 초기화\n this.init();\n }\n\n init() {\n this.resize();\n this.setupEventListeners();\n this.start();\n \n if (this.config.onReady) {\n this.config.onReady(this);\n }\n }\n\n resize() {\n const width = this.config.width || this.container.clientWidth || window.innerWidth;\n const height = this.config.height || this.container.clientHeight || window.innerHeight * 0.7;\n \n this.W = Math.floor(width * this.DPR);\n this.H = Math.floor(height * this.DPR);\n \n this.canvas.width = this.W;\n this.canvas.height = this.H;\n this.canvas.style.width = width + 'px';\n this.canvas.style.height = height + 'px';\n\n this.buildTargets();\n if (!this.particles.length) {\n this.initParticles();\n }\n }\n\n buildTargets() {\n const text = this.config.text;\n this.offCanvas.width = this.W;\n this.offCanvas.height = this.H;\n this.offCtx.clearRect(0, 0, this.offCanvas.width, this.offCanvas.height);\n\n const base = Math.min(this.W, this.H);\n const fontSize = this.config.fontSize || Math.max(80, Math.floor(base * 0.18));\n this.offCtx.fillStyle = '#ffffff';\n this.offCtx.textAlign = 'center';\n this.offCtx.textBaseline = 'middle';\n this.offCtx.font = `400 ${fontSize}px ${this.config.fontFamily}`;\n\n // 글자 간격 계산 및 그리기\n const chars = text.split('');\n const spacing = fontSize * 0.05;\n const totalWidth = this.offCtx.measureText(text).width + spacing * (chars.length - 1);\n let x = this.W / 2 - totalWidth / 2;\n \n for (const ch of chars) {\n this.offCtx.fillText(ch, x + this.offCtx.measureText(ch).width / 2, this.H / 2);\n x += this.offCtx.measureText(ch).width + spacing;\n }\n\n // 픽셀 샘플링\n const step = Math.max(2, this.config.densityStep);\n const img = this.offCtx.getImageData(0, 0, this.W, this.H).data;\n const targets = [];\n \n for (let y = 0; y < this.H; y += step) {\n for (let x = 0; x < this.W; x += step) {\n const i = (y * this.W + x) * 4;\n if (img[i] + img[i + 1] + img[i + 2] > 600) {\n targets.push({ x, y });\n }\n }\n }\n\n // 파티클 수 제한\n while (targets.length > this.config.maxParticles) {\n targets.splice(Math.floor(Math.random() * targets.length), 1);\n }\n\n // 파티클 수 조정\n if (this.particles.length < targets.length) {\n const need = targets.length - this.particles.length;\n for (let i = 0; i < need; i++) {\n this.particles.push(this.makeParticle());\n }\n } else if (this.particles.length > targets.length) {\n this.particles.length = targets.length;\n }\n\n // 목표 좌표 할당\n for (let i = 0; i < this.particles.length; i++) {\n const p = this.particles[i];\n const t = targets[i];\n p.tx = t.x;\n p.ty = t.y;\n }\n }\n\n makeParticle() {\n const m = 0.12;\n const sx = (m + Math.random() * (1 - 2 * m)) * this.W;\n const sy = (m + Math.random() * (1 - 2 * m)) * this.H;\n return {\n x: sx,\n y: sy,\n vx: 0,\n vy: 0,\n tx: sx,\n ty: sy,\n j: Math.random() * Math.PI * 2,\n };\n }\n\n initParticles() {\n for (const p of this.particles) {\n p.x = (0.12 + Math.random() * 1.76) * this.W;\n p.y = (0.12 + Math.random() * 1.76) * this.H;\n p.vx = p.vy = 0;\n }\n }\n\n scatter() {\n for (const p of this.particles) {\n p.tx = (0.12 + Math.random() * 1.76) * this.W;\n p.ty = (0.12 + Math.random() * 1.76) * this.H;\n }\n }\n\n morph(text = null) {\n if (text) {\n this.config.text = text;\n }\n this.buildTargets();\n }\n\n update() {\n this.ctx.clearRect(0, 0, this.W, this.H);\n\n for (const p of this.particles) {\n // 목표 좌표로 당기는 힘\n let ax = (p.tx - p.x) * this.config.ease;\n let ay = (p.ty - p.y) * this.config.ease;\n\n // 마우스 반발/흡입\n if (this.mouse.x || this.mouse.y) {\n const dx = p.x - this.mouse.x;\n const dy = p.y - this.mouse.y;\n const d2 = dx * dx + dy * dy;\n const r = this.config.repelRadius * this.DPR;\n if (d2 < r * r) {\n const d = Math.sqrt(d2) + 0.0001;\n const f = (this.mouse.down ? -1 : 1) * this.config.repelStrength * (1 - d / r);\n ax += (dx / d) * f * 6.0;\n ay += (dy / d) * f * 6.0;\n }\n }\n\n // 진동 효과\n p.j += 2;\n ax += Math.cos(p.j) * 0.05;\n ay += Math.sin(p.j * 1.3) * 0.05;\n\n // 속도와 위치 업데이트\n p.vx = (p.vx + ax) * Math.random();\n p.vy = (p.vy + ay) * Math.random();\n p.x += p.vx;\n p.y += p.vy;\n }\n\n // 파티클 그리기\n this.ctx.fillStyle = this.config.particleColor;\n const r = this.config.pointSize * this.DPR;\n for (const p of this.particles) {\n this.ctx.beginPath();\n this.ctx.arc(p.x, p.y, r, 0, Math.PI * 2);\n this.ctx.fill();\n }\n\n if (this.config.onUpdate) {\n this.config.onUpdate(this);\n }\n }\n\n animate() {\n if (!this.isRunning) return;\n this.update();\n this.animationId = requestAnimationFrame(() => this.animate());\n }\n\n start() {\n if (this.isRunning) return;\n this.isRunning = true;\n this.animate();\n }\n\n stop() {\n this.isRunning = false;\n if (this.animationId) {\n cancelAnimationFrame(this.animationId);\n this.animationId = null;\n }\n }\n\n setupEventListeners() {\n window.addEventListener('resize', this.handleResize);\n this.canvas.addEventListener('mousemove', this.handleMouseMove);\n this.canvas.addEventListener('mouseleave', this.handleMouseLeave);\n this.canvas.addEventListener('mousedown', this.handleMouseDown);\n window.addEventListener('mouseup', this.handleMouseUp);\n }\n\n removeEventListeners() {\n window.removeEventListener('resize', this.handleResize);\n this.canvas.removeEventListener('mousemove', this.handleMouseMove);\n this.canvas.removeEventListener('mouseleave', this.handleMouseLeave);\n this.canvas.removeEventListener('mousedown', this.handleMouseDown);\n window.removeEventListener('mouseup', this.handleMouseUp);\n }\n\n handleResize() {\n this.resize();\n }\n\n handleMouseMove(e) {\n const rect = this.canvas.getBoundingClientRect();\n this.mouse.x = (e.clientX - rect.left) * this.DPR;\n this.mouse.y = (e.clientY - rect.top) * this.DPR;\n }\n\n handleMouseLeave() {\n this.mouse.x = this.mouse.y = 0;\n }\n\n handleMouseDown() {\n this.mouse.down = true;\n }\n\n handleMouseUp() {\n this.mouse.down = false;\n }\n\n // 설정 업데이트\n updateConfig(newConfig) {\n this.config = { ...this.config, ...newConfig };\n if (newConfig.text) {\n this.buildTargets();\n }\n }\n\n // 파괴 및 정리\n destroy() {\n this.stop();\n this.removeEventListeners();\n if (this.canvas && this.canvas.parentNode) {\n this.canvas.parentNode.removeChild(this.canvas);\n }\n }\n}\n\n// 기본 export\nexport default MasonEffect;\n\n",null],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;;AAEO,MAAM,WAAW,CAAC;AACzB,EAAE,WAAW,CAAC,SAAS,EAAE,OAAO,GAAG,EAAE,EAAE;AACvC;AACA,IAAI,IAAI,CAAC,SAAS,GAAG,OAAO,SAAS,KAAK,QAAQ;AAClD,QAAQ,QAAQ,CAAC,aAAa,CAAC,SAAS,CAAC;AACzC,QAAQ,SAAS;AACjB;AACA,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;AACzB,MAAM,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC;AACpD,IAAI;;AAEJ;AACA,IAAI,IAAI,CAAC,MAAM,GAAG;AAClB,MAAM,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,eAAe;AAC3C,MAAM,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,CAAC;AAC3C,MAAM,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,IAAI;AAChD,MAAM,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,GAAG;AACzC,MAAM,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI;AAChC,MAAM,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,GAAG;AAC7C,MAAM,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,CAAC;AAC/C,MAAM,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,MAAM;AACpD,MAAM,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,yBAAyB;AACjE,MAAM,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;AACxC,MAAM,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,IAAI;AAClC,MAAM,MAAM,EAAE,OAA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
|
|
1
|
+
var t=require("react");class i{constructor(t,i={}){if(this.container="string"==typeof t?document.querySelector(t):t,!this.container)throw Error("Container element not found");this.config={text:i.text||"mason crawler",densityStep:i.densityStep??2,maxParticles:i.maxParticles??3200,pointSize:i.pointSize??.5,ease:i.ease??.05,repelRadius:i.repelRadius??150,repelStrength:i.repelStrength??1,particleColor:i.particleColor||"#fff",fontFamily:i.fontFamily||"Inter, system-ui, Arial",fontSize:i.fontSize||null,width:i.width||null,height:i.height||null,devicePixelRatio:i.devicePixelRatio??null,onReady:i.onReady||null,onUpdate:i.onUpdate||null},this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.container.appendChild(this.canvas),this.canvas.style.display="block",this.offCanvas=document.createElement("canvas"),this.offCtx=this.offCanvas.getContext("2d"),this.W=0,this.H=0,this.DPR=this.config.devicePixelRatio||Math.min(window.devicePixelRatio||1,1.8),this.particles=[],this.mouse={x:0,y:0,down:!1},this.animationId=null,this.isRunning=!1,this.handleResize=this.handleResize.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseLeave=this.handleMouseLeave.bind(this),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this),this.init()}init(){this.resize(),this.setupEventListeners(),this.start(),this.config.onReady&&this.config.onReady(this)}resize(){const t=this.config.width||this.container.clientWidth||window.innerWidth,i=this.config.height||this.container.clientHeight||.7*window.innerHeight;this.W=Math.floor(t*this.DPR),this.H=Math.floor(i*this.DPR),this.canvas.width=this.W,this.canvas.height=this.H,this.canvas.style.width=t+"px",this.canvas.style.height=i+"px",this.buildTargets(),this.particles.length||this.initParticles()}buildTargets(){const t=this.config.text;this.offCanvas.width=this.W,this.offCanvas.height=this.H,this.offCtx.clearRect(0,0,this.offCanvas.width,this.offCanvas.height);const i=Math.min(this.W,this.H),s=this.config.fontSize||Math.max(80,Math.floor(.18*i));this.offCtx.fillStyle="#ffffff",this.offCtx.textAlign="center",this.offCtx.textBaseline="middle",this.offCtx.font=`400 ${s}px ${this.config.fontFamily}`;const h=t.split(""),e=.05*s,o=this.offCtx.measureText(t).width+e*(h.length-1);let n=this.W/2-o/2;for(const t of h)this.offCtx.fillText(t,n+this.offCtx.measureText(t).width/2,this.H/2),n+=this.offCtx.measureText(t).width+e;const a=Math.max(2,this.config.densityStep),l=this.offCtx.getImageData(0,0,this.W,this.H).data,r=[];for(let t=0;t<this.H;t+=a)for(let i=0;i<this.W;i+=a){const s=4*(t*this.W+i);l[s]+l[s+1]+l[s+2]>600&&r.push({x:i,y:t})}for(;r.length>this.config.maxParticles;)r.splice(Math.floor(Math.random()*r.length),1);if(this.particles.length<r.length){const t=r.length-this.particles.length;for(let i=0;t>i;i++)this.particles.push(this.makeParticle())}else this.particles.length>r.length&&(this.particles.length=r.length);for(let t=0;t<this.particles.length;t++){const i=this.particles[t],s=r[t];i.tx=s.x,i.ty=s.y}}makeParticle(){const t=(.12+.76*Math.random())*this.W,i=(.12+.76*Math.random())*this.H;return{x:t,y:i,vx:0,vy:0,tx:t,ty:i,j:Math.random()*Math.PI*2}}initParticles(){for(const t of this.particles)t.x=(.12+1.76*Math.random())*this.W,t.y=(.12+1.76*Math.random())*this.H,t.vx=t.vy=0}scatter(){for(const t of this.particles)t.tx=(.12+1.76*Math.random())*this.W,t.ty=(.12+1.76*Math.random())*this.H}morph(t=null){t&&(this.config.text=t),this.buildTargets()}update(){this.ctx.clearRect(0,0,this.W,this.H);for(const t of this.particles){let i=(t.tx-t.x)*this.config.ease,s=(t.ty-t.y)*this.config.ease;if(this.mouse.x||this.mouse.y){const h=t.x-this.mouse.x,e=t.y-this.mouse.y,o=h*h+e*e,n=this.config.repelRadius*this.DPR;if(n*n>o){const t=Math.sqrt(o)+1e-4,a=(this.mouse.down?-1:1)*this.config.repelStrength*(1-t/n);i+=h/t*a*6,s+=e/t*a*6}}t.j+=2,i+=.05*Math.cos(t.j),s+=.05*Math.sin(1.3*t.j),t.vx=(t.vx+i)*Math.random(),t.vy=(t.vy+s)*Math.random(),t.x+=t.vx,t.y+=t.vy}this.ctx.fillStyle=this.config.particleColor;const t=this.config.pointSize*this.DPR;for(const i of this.particles)this.ctx.beginPath(),this.ctx.arc(i.x,i.y,t,0,2*Math.PI),this.ctx.fill();this.config.onUpdate&&this.config.onUpdate(this)}animate(){this.isRunning&&(this.update(),this.animationId=requestAnimationFrame(()=>this.animate()))}start(){this.isRunning||(this.isRunning=!0,this.animate())}stop(){this.isRunning=!1,this.animationId&&(cancelAnimationFrame(this.animationId),this.animationId=null)}setupEventListeners(){window.addEventListener("resize",this.handleResize),this.canvas.addEventListener("mousemove",this.handleMouseMove),this.canvas.addEventListener("mouseleave",this.handleMouseLeave),this.canvas.addEventListener("mousedown",this.handleMouseDown),window.addEventListener("mouseup",this.handleMouseUp)}removeEventListeners(){window.removeEventListener("resize",this.handleResize),this.canvas.removeEventListener("mousemove",this.handleMouseMove),this.canvas.removeEventListener("mouseleave",this.handleMouseLeave),this.canvas.removeEventListener("mousedown",this.handleMouseDown),window.removeEventListener("mouseup",this.handleMouseUp)}handleResize(){this.resize()}handleMouseMove(t){const i=this.canvas.getBoundingClientRect();this.mouse.x=(t.clientX-i.left)*this.DPR,this.mouse.y=(t.clientY-i.top)*this.DPR}handleMouseLeave(){this.mouse.x=this.mouse.y=0}handleMouseDown(){this.mouse.down=!0}handleMouseUp(){this.mouse.down=!1}updateConfig(t){this.config={...this.config,...t},t.text&&this.buildTargets()}destroy(){this.stop(),this.removeEventListeners(),this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas)}}const s=t.forwardRef((s,h)=>{const e=t.useRef(null),o=t.useRef(null);return t.useEffect(()=>{if(!e.current)return;const{className:t,style:h,text:n,densityStep:a,maxParticles:l,pointSize:r,ease:c,repelRadius:d,repelStrength:u,particleColor:f,fontFamily:p,fontSize:m,width:M,height:w,devicePixelRatio:y,onReady:x,onUpdate:v}=s,S={text:n,densityStep:a,maxParticles:l,pointSize:r,ease:c,repelRadius:d,repelStrength:u,particleColor:f,fontFamily:p,fontSize:m,width:M,height:w,devicePixelRatio:y,onReady:x,onUpdate:v};return o.current=new i(e.current,S),()=>{o.current&&(o.current.destroy(),o.current=null)}},[]),t.useEffect(()=>{if(!o.current)return;const{text:t,densityStep:i,maxParticles:h,pointSize:e,ease:n,repelRadius:a,repelStrength:l,particleColor:r,fontFamily:c,fontSize:d,width:u,height:f,devicePixelRatio:p}=s;o.current.updateConfig({text:t,densityStep:i,maxParticles:h,pointSize:e,ease:n,repelRadius:a,repelStrength:l,particleColor:r,fontFamily:c,fontSize:d,width:u,height:f,devicePixelRatio:p})},[s.text,s.densityStep,s.maxParticles,s.pointSize,s.ease,s.repelRadius,s.repelStrength,s.particleColor,s.fontFamily,s.fontSize,s.width,s.height,s.devicePixelRatio]),t.useImperativeHandle(h,()=>({morph(t){o.current?.morph(t)},scatter(){o.current?.scatter()},updateConfig(t){o.current?.updateConfig(t)},destroy(){o.current?.destroy(),o.current=null}})),t.createElement("div",{ref:e,className:s.className,style:s.style})});s.displayName="MasonEffect",module.exports=s;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t,{forwardRef as i,useRef as s,useEffect as h,useImperativeHandle as e}from"react";class o{constructor(t,i={}){if(this.container="string"==typeof t?document.querySelector(t):t,!this.container)throw Error("Container element not found");this.config={text:i.text||"mason crawler",densityStep:i.densityStep??2,maxParticles:i.maxParticles??3200,pointSize:i.pointSize??.5,ease:i.ease??.05,repelRadius:i.repelRadius??150,repelStrength:i.repelStrength??1,particleColor:i.particleColor||"#fff",fontFamily:i.fontFamily||"Inter, system-ui, Arial",fontSize:i.fontSize||null,width:i.width||null,height:i.height||null,devicePixelRatio:i.devicePixelRatio??null,onReady:i.onReady||null,onUpdate:i.onUpdate||null},this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.container.appendChild(this.canvas),this.canvas.style.display="block",this.offCanvas=document.createElement("canvas"),this.offCtx=this.offCanvas.getContext("2d"),this.W=0,this.H=0,this.DPR=this.config.devicePixelRatio||Math.min(window.devicePixelRatio||1,1.8),this.particles=[],this.mouse={x:0,y:0,down:!1},this.animationId=null,this.isRunning=!1,this.handleResize=this.handleResize.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseLeave=this.handleMouseLeave.bind(this),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this),this.init()}init(){this.resize(),this.setupEventListeners(),this.start(),this.config.onReady&&this.config.onReady(this)}resize(){const t=this.config.width||this.container.clientWidth||window.innerWidth,i=this.config.height||this.container.clientHeight||.7*window.innerHeight;this.W=Math.floor(t*this.DPR),this.H=Math.floor(i*this.DPR),this.canvas.width=this.W,this.canvas.height=this.H,this.canvas.style.width=t+"px",this.canvas.style.height=i+"px",this.buildTargets(),this.particles.length||this.initParticles()}buildTargets(){const t=this.config.text;this.offCanvas.width=this.W,this.offCanvas.height=this.H,this.offCtx.clearRect(0,0,this.offCanvas.width,this.offCanvas.height);const i=Math.min(this.W,this.H),s=this.config.fontSize||Math.max(80,Math.floor(.18*i));this.offCtx.fillStyle="#ffffff",this.offCtx.textAlign="center",this.offCtx.textBaseline="middle",this.offCtx.font=`400 ${s}px ${this.config.fontFamily}`;const h=t.split(""),e=.05*s,o=this.offCtx.measureText(t).width+e*(h.length-1);let n=this.W/2-o/2;for(const t of h)this.offCtx.fillText(t,n+this.offCtx.measureText(t).width/2,this.H/2),n+=this.offCtx.measureText(t).width+e;const a=Math.max(2,this.config.densityStep),l=this.offCtx.getImageData(0,0,this.W,this.H).data,r=[];for(let t=0;t<this.H;t+=a)for(let i=0;i<this.W;i+=a){const s=4*(t*this.W+i);l[s]+l[s+1]+l[s+2]>600&&r.push({x:i,y:t})}for(;r.length>this.config.maxParticles;)r.splice(Math.floor(Math.random()*r.length),1);if(this.particles.length<r.length){const t=r.length-this.particles.length;for(let i=0;t>i;i++)this.particles.push(this.makeParticle())}else this.particles.length>r.length&&(this.particles.length=r.length);for(let t=0;t<this.particles.length;t++){const i=this.particles[t],s=r[t];i.tx=s.x,i.ty=s.y}}makeParticle(){const t=(.12+.76*Math.random())*this.W,i=(.12+.76*Math.random())*this.H;return{x:t,y:i,vx:0,vy:0,tx:t,ty:i,j:Math.random()*Math.PI*2}}initParticles(){for(const t of this.particles)t.x=(.12+1.76*Math.random())*this.W,t.y=(.12+1.76*Math.random())*this.H,t.vx=t.vy=0}scatter(){for(const t of this.particles)t.tx=(.12+1.76*Math.random())*this.W,t.ty=(.12+1.76*Math.random())*this.H}morph(t=null){t&&(this.config.text=t),this.buildTargets()}update(){this.ctx.clearRect(0,0,this.W,this.H);for(const t of this.particles){let i=(t.tx-t.x)*this.config.ease,s=(t.ty-t.y)*this.config.ease;if(this.mouse.x||this.mouse.y){const h=t.x-this.mouse.x,e=t.y-this.mouse.y,o=h*h+e*e,n=this.config.repelRadius*this.DPR;if(n*n>o){const t=Math.sqrt(o)+1e-4,a=(this.mouse.down?-1:1)*this.config.repelStrength*(1-t/n);i+=h/t*a*6,s+=e/t*a*6}}t.j+=2,i+=.05*Math.cos(t.j),s+=.05*Math.sin(1.3*t.j),t.vx=(t.vx+i)*Math.random(),t.vy=(t.vy+s)*Math.random(),t.x+=t.vx,t.y+=t.vy}this.ctx.fillStyle=this.config.particleColor;const t=this.config.pointSize*this.DPR;for(const i of this.particles)this.ctx.beginPath(),this.ctx.arc(i.x,i.y,t,0,2*Math.PI),this.ctx.fill();this.config.onUpdate&&this.config.onUpdate(this)}animate(){this.isRunning&&(this.update(),this.animationId=requestAnimationFrame(()=>this.animate()))}start(){this.isRunning||(this.isRunning=!0,this.animate())}stop(){this.isRunning=!1,this.animationId&&(cancelAnimationFrame(this.animationId),this.animationId=null)}setupEventListeners(){window.addEventListener("resize",this.handleResize),this.canvas.addEventListener("mousemove",this.handleMouseMove),this.canvas.addEventListener("mouseleave",this.handleMouseLeave),this.canvas.addEventListener("mousedown",this.handleMouseDown),window.addEventListener("mouseup",this.handleMouseUp)}removeEventListeners(){window.removeEventListener("resize",this.handleResize),this.canvas.removeEventListener("mousemove",this.handleMouseMove),this.canvas.removeEventListener("mouseleave",this.handleMouseLeave),this.canvas.removeEventListener("mousedown",this.handleMouseDown),window.removeEventListener("mouseup",this.handleMouseUp)}handleResize(){this.resize()}handleMouseMove(t){const i=this.canvas.getBoundingClientRect();this.mouse.x=(t.clientX-i.left)*this.DPR,this.mouse.y=(t.clientY-i.top)*this.DPR}handleMouseLeave(){this.mouse.x=this.mouse.y=0}handleMouseDown(){this.mouse.down=!0}handleMouseUp(){this.mouse.down=!1}updateConfig(t){this.config={...this.config,...t},t.text&&this.buildTargets()}destroy(){this.stop(),this.removeEventListeners(),this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas)}}const n=i((i,n)=>{const a=s(null),l=s(null);return h(()=>{if(!a.current)return;const{className:t,style:s,text:h,densityStep:e,maxParticles:n,pointSize:r,ease:c,repelRadius:d,repelStrength:u,particleColor:f,fontFamily:p,fontSize:m,width:M,height:w,devicePixelRatio:x,onReady:y,onUpdate:S}=i,v={text:h,densityStep:e,maxParticles:n,pointSize:r,ease:c,repelRadius:d,repelStrength:u,particleColor:f,fontFamily:p,fontSize:m,width:M,height:w,devicePixelRatio:x,onReady:y,onUpdate:S};return l.current=new o(a.current,v),()=>{l.current&&(l.current.destroy(),l.current=null)}},[]),h(()=>{if(!l.current)return;const{text:t,densityStep:s,maxParticles:h,pointSize:e,ease:o,repelRadius:n,repelStrength:a,particleColor:r,fontFamily:c,fontSize:d,width:u,height:f,devicePixelRatio:p}=i;l.current.updateConfig({text:t,densityStep:s,maxParticles:h,pointSize:e,ease:o,repelRadius:n,repelStrength:a,particleColor:r,fontFamily:c,fontSize:d,width:u,height:f,devicePixelRatio:p})},[i.text,i.densityStep,i.maxParticles,i.pointSize,i.ease,i.repelRadius,i.repelStrength,i.particleColor,i.fontFamily,i.fontSize,i.width,i.height,i.devicePixelRatio]),e(n,()=>({morph(t){l.current?.morph(t)},scatter(){l.current?.scatter()},updateConfig(t){l.current?.updateConfig(t)},destroy(){l.current?.destroy(),l.current=null}})),t.createElement("div",{ref:a,className:i.className,style:i.style})});n.displayName="MasonEffect";export{n as default};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MasonEffect } from '../core/index.js';
|
|
3
|
+
export interface MasonEffectOptions {
|
|
4
|
+
text?: string;
|
|
5
|
+
densityStep?: number;
|
|
6
|
+
maxParticles?: number;
|
|
7
|
+
pointSize?: number;
|
|
8
|
+
ease?: number;
|
|
9
|
+
repelRadius?: number;
|
|
10
|
+
repelStrength?: number;
|
|
11
|
+
particleColor?: string;
|
|
12
|
+
fontFamily?: string;
|
|
13
|
+
fontSize?: number | null;
|
|
14
|
+
width?: number | null;
|
|
15
|
+
height?: number | null;
|
|
16
|
+
devicePixelRatio?: number | null;
|
|
17
|
+
onReady?: (instance: MasonEffect) => void;
|
|
18
|
+
onUpdate?: (instance: MasonEffect) => void;
|
|
19
|
+
}
|
|
20
|
+
export interface MasonEffectRef {
|
|
21
|
+
morph: (text?: string) => void;
|
|
22
|
+
scatter: () => void;
|
|
23
|
+
updateConfig: (config: Partial<MasonEffectOptions>) => void;
|
|
24
|
+
destroy: () => void;
|
|
25
|
+
}
|
|
26
|
+
interface MasonEffectProps extends MasonEffectOptions {
|
|
27
|
+
className?: string;
|
|
28
|
+
style?: React.CSSProperties;
|
|
29
|
+
}
|
|
30
|
+
declare const MasonEffectComponent: React.ForwardRefExoticComponent<MasonEffectProps & React.RefAttributes<MasonEffectRef>>;
|
|
31
|
+
export default MasonEffectComponent;
|
|
32
|
+
//# sourceMappingURL=MasonEffect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MasonEffect.d.ts","sourceRoot":"","sources":["../../../src/react/MasonEffect.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6D,MAAM,OAAO,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CA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
"version": "0.1.0",
|
|
4
|
+
"description": "파티클 모핑 효과를 제공하는 라이브러리 - React, Vue, 바닐라 JS 지원",
|
|
5
|
+
"main": "dist/index.min.js",
|
|
6
|
+
"module": "dist/index.esm.min.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.esm.min.js",
|
|
11
|
+
"require": "./dist/index.min.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./react": {
|
|
15
|
+
"import": "./dist/react/MasonEffect.min.js",
|
|
16
|
+
"require": "./dist/react/MasonEffect.min.cjs",
|
|
17
|
+
"types": "./dist/react/MasonEffect.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./vue": {
|
|
20
|
+
"import": "./src/vue/MasonEffect.vue"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"src"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "rollup -c rollup.config.mjs",
|
|
29
|
+
"dev": "rollup -c rollup.config.mjs -w",
|
|
30
|
+
"serve": "npx http-server . -p 8080 -o --cors",
|
|
31
|
+
"dev:example": "npm run serve",
|
|
32
|
+
"precheck": "node scripts/check-before-publish.js",
|
|
33
|
+
"prepublishOnly": "npm run build && npm run precheck"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"particles",
|
|
37
|
+
"morphing",
|
|
38
|
+
"canvas",
|
|
39
|
+
"animation",
|
|
40
|
+
"react",
|
|
41
|
+
"vue",
|
|
42
|
+
"vanilla-js"
|
|
43
|
+
],
|
|
44
|
+
"author": "mason.dev fe.hyunsu@gmail.com",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/fe-hyunsu/masoneffect.git"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/fe-hyunsu/masoneffect#readme",
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/fe-hyunsu/masoneffect/issues"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
56
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
57
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
58
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
59
|
+
"@types/react": "^19.2.3",
|
|
60
|
+
"@types/react-dom": "^19.2.3",
|
|
61
|
+
"react": "^19.2.0",
|
|
62
|
+
"react-dom": "^19.2.0",
|
|
63
|
+
"rollup": "^4.9.0",
|
|
64
|
+
"tslib": "^2.8.1",
|
|
65
|
+
"typescript": "^5.3.3"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"react": ">=16.8.0",
|
|
69
|
+
"vue": ">=3.0.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependenciesMeta": {
|
|
72
|
+
"react": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
75
|
+
"vue": {
|
|
76
|
+
"optional": true
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MasonEffect 타입 정의
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface MasonEffectOptions {
|
|
6
|
+
text?: string;
|
|
7
|
+
densityStep?: number;
|
|
8
|
+
maxParticles?: number;
|
|
9
|
+
pointSize?: number;
|
|
10
|
+
ease?: number;
|
|
11
|
+
repelRadius?: number;
|
|
12
|
+
repelStrength?: number;
|
|
13
|
+
particleColor?: string;
|
|
14
|
+
fontFamily?: string;
|
|
15
|
+
fontSize?: number | null;
|
|
16
|
+
width?: number | null;
|
|
17
|
+
height?: number | null;
|
|
18
|
+
devicePixelRatio?: number | null;
|
|
19
|
+
onReady?: (instance: MasonEffect) => void;
|
|
20
|
+
onUpdate?: (instance: MasonEffect) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface Particle {
|
|
24
|
+
x: number;
|
|
25
|
+
y: number;
|
|
26
|
+
vx: number;
|
|
27
|
+
vy: number;
|
|
28
|
+
tx: number;
|
|
29
|
+
ty: number;
|
|
30
|
+
j: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class MasonEffect {
|
|
34
|
+
constructor(container: HTMLElement | string, options?: MasonEffectOptions);
|
|
35
|
+
|
|
36
|
+
config: MasonEffectOptions;
|
|
37
|
+
canvas: HTMLCanvasElement;
|
|
38
|
+
ctx: CanvasRenderingContext2D;
|
|
39
|
+
particles: Particle[];
|
|
40
|
+
mouse: { x: number; y: number; down: boolean };
|
|
41
|
+
isRunning: boolean;
|
|
42
|
+
|
|
43
|
+
init(): void;
|
|
44
|
+
resize(): void;
|
|
45
|
+
buildTargets(): void;
|
|
46
|
+
makeParticle(): Particle;
|
|
47
|
+
initParticles(): void;
|
|
48
|
+
scatter(): void;
|
|
49
|
+
morph(text?: string): void;
|
|
50
|
+
update(): void;
|
|
51
|
+
animate(): void;
|
|
52
|
+
start(): void;
|
|
53
|
+
stop(): void;
|
|
54
|
+
updateConfig(newConfig: Partial<MasonEffectOptions>): void;
|
|
55
|
+
destroy(): void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default MasonEffect;
|
|
59
|
+
|