masoneffect 0.1.13 → 0.1.14

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/dist/index.umd.js CHANGED
@@ -1,440 +1,398 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MasonEffect = {}));
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MasonEffect = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- /**
8
- * MasonEffect - 파티클 모핑 효과 라이브러리
9
- * 바닐라 JS 코어 클래스
10
- */
11
-
12
- // 디바운스 유틸리티 함수
13
- function debounce(func, wait) {
14
- let timeout;
15
- return function executedFunction(...args) {
16
- const later = () => {
17
- clearTimeout(timeout);
18
- func.apply(this, args);
19
- };
20
- clearTimeout(timeout);
21
- timeout = setTimeout(later, wait);
22
- };
23
- }
24
-
25
- class MasonEffect {
26
- constructor(container, options = {}) {
27
- // 컨테이너 요소
28
- this.container = typeof container === 'string'
29
- ? document.querySelector(container)
30
- : container;
31
-
32
- if (!this.container) {
33
- throw new Error('Container element not found');
34
- }
35
-
36
- // 설정값들
37
- this.config = {
38
- text: options.text || 'mason effect',
39
- densityStep: options.densityStep ?? 2,
40
- maxParticles: options.maxParticles ?? 3200,
41
- pointSize: options.pointSize ?? 0.5,
42
- ease: options.ease ?? 0.05,
43
- repelRadius: options.repelRadius ?? 150,
44
- repelStrength: options.repelStrength ?? 1,
45
- particleColor: options.particleColor || '#fff',
46
- fontFamily: options.fontFamily || 'Inter, system-ui, Arial',
47
- fontSize: options.fontSize || null, // null이면 자동 계산
48
- width: options.width || null, // null이면 컨테이너 크기
49
- height: options.height || null, // null이면 컨테이너 크기
50
- devicePixelRatio: options.devicePixelRatio ?? null, // null이면 자동
51
- onReady: options.onReady || null,
52
- onUpdate: options.onUpdate || null,
53
- };
54
-
55
- // 캔버스 생성
56
- this.canvas = document.createElement('canvas');
57
- this.ctx = this.canvas.getContext('2d');
58
- this.container.appendChild(this.canvas);
59
- this.canvas.style.display = 'block';
60
-
61
- // 오프스크린 캔버스 (텍스트 렌더링용)
62
- this.offCanvas = document.createElement('canvas');
63
- this.offCtx = this.offCanvas.getContext('2d');
64
-
65
- // 상태
66
- this.W = 0;
67
- this.H = 0;
68
- this.DPR = this.config.devicePixelRatio || Math.min(window.devicePixelRatio || 1, 1.8);
69
- this.particles = [];
70
- this.mouse = { x: 0, y: 0, down: false };
71
- this.animationId = null;
72
- this.isRunning = false;
73
- this.isVisible = false;
74
- this.intersectionObserver = null;
75
-
76
- // 디바운스 설정 (ms)
77
- this.debounceDelay = options.debounceDelay ?? 150; // 기본 150ms
78
-
79
- // 이벤트 핸들러 바인딩 (디바운스 적용 전에 바인딩)
80
- const boundHandleResize = this.handleResize.bind(this);
81
- this.handleResize = debounce(boundHandleResize, this.debounceDelay);
82
- this.handleMouseMove = this.handleMouseMove.bind(this);
83
- this.handleMouseLeave = this.handleMouseLeave.bind(this);
84
- this.handleMouseDown = this.handleMouseDown.bind(this);
85
- this.handleMouseUp = this.handleMouseUp.bind(this);
86
-
87
- // morph와 updateConfig를 위한 디바운스된 내부 메서드
88
- this._debouncedMorph = debounce(this._morphInternal.bind(this), this.debounceDelay);
89
- this._debouncedUpdateConfig = debounce(this._updateConfigInternal.bind(this), this.debounceDelay);
90
-
91
- // 초기화
92
- this.init();
93
- }
94
-
95
- init() {
96
- this.resize();
97
- this.setupEventListeners();
98
- this.setupIntersectionObserver();
99
-
100
- if (this.config.onReady) {
101
- this.config.onReady(this);
102
- }
7
+ /**
8
+ * MasonEffect - 파티클 모핑 효과 라이브러리
9
+ * 바닐라 JS 코어 클래스
10
+ */
11
+ // 디바운스 유틸리티 함수
12
+ function debounce(func, wait) {
13
+ let timeout = null;
14
+ return function executedFunction(...args) {
15
+ const later = () => {
16
+ timeout = null;
17
+ func.apply(this, args);
18
+ };
19
+ if (timeout !== null) {
20
+ clearTimeout(timeout);
21
+ }
22
+ timeout = setTimeout(later, wait);
23
+ };
103
24
  }
104
-
105
- setupIntersectionObserver() {
106
- // IntersectionObserver가 지원되지 않는 환경에서는 항상 재생
107
- if (typeof window === 'undefined' || typeof window.IntersectionObserver === 'undefined') {
108
- this.isVisible = true;
109
- this.start();
110
- return;
111
- }
112
-
113
- // 이미 설정되어 있다면 다시 만들지 않음
114
- if (this.intersectionObserver) {
115
- return;
116
- }
117
-
118
- this.intersectionObserver = new IntersectionObserver(
119
- (entries) => {
120
- for (const entry of entries) {
121
- if (entry.target !== this.container) continue;
122
-
123
- if (entry.isIntersecting) {
124
- this.isVisible = true;
125
- this.start();
126
- } else {
127
- this.isVisible = false;
128
- this.stop();
25
+ class MasonEffect {
26
+ constructor(container, options = {}) {
27
+ // 컨테이너 요소
28
+ this.container = typeof container === 'string'
29
+ ? document.querySelector(container)
30
+ : container;
31
+ if (!this.container) {
32
+ throw new Error('Container element not found');
33
+ }
34
+ // 설정값들
35
+ this.config = {
36
+ text: options.text || 'mason effect',
37
+ densityStep: options.densityStep ?? 2,
38
+ maxParticles: options.maxParticles ?? 3200,
39
+ pointSize: options.pointSize ?? 0.5,
40
+ ease: options.ease ?? 0.05,
41
+ repelRadius: options.repelRadius ?? 150,
42
+ repelStrength: options.repelStrength ?? 1,
43
+ particleColor: options.particleColor || '#fff',
44
+ fontFamily: options.fontFamily || 'Inter, system-ui, Arial',
45
+ fontSize: options.fontSize || null,
46
+ width: options.width || null,
47
+ height: options.height || null,
48
+ devicePixelRatio: options.devicePixelRatio ?? null,
49
+ onReady: options.onReady || null,
50
+ onUpdate: options.onUpdate || null,
51
+ };
52
+ // 캔버스 생성
53
+ this.canvas = document.createElement('canvas');
54
+ const ctx = this.canvas.getContext('2d');
55
+ if (!ctx) {
56
+ throw new Error('Canvas context not available');
129
57
  }
130
- }
131
- },
132
- {
133
- threshold: 0.1, // 10% 이상 보일 때 동작
58
+ this.ctx = ctx;
59
+ this.container.appendChild(this.canvas);
60
+ this.canvas.style.display = 'block';
61
+ // 오프스크린 캔버스 (텍스트 렌더링용)
62
+ this.offCanvas = document.createElement('canvas');
63
+ const offCtx = this.offCanvas.getContext('2d');
64
+ if (!offCtx) {
65
+ throw new Error('Offscreen canvas context not available');
66
+ }
67
+ this.offCtx = offCtx;
68
+ // 상태
69
+ this.W = 0;
70
+ this.H = 0;
71
+ this.DPR = this.config.devicePixelRatio || Math.min(window.devicePixelRatio || 1, 1.8);
72
+ this.particles = [];
73
+ this.mouse = { x: 0, y: 0, down: false };
74
+ this.animationId = null;
75
+ this.isRunning = false;
76
+ this.isVisible = false;
77
+ this.intersectionObserver = null;
78
+ // 디바운스 설정 (ms)
79
+ this.debounceDelay = options.debounceDelay ?? 150;
80
+ // 이벤트 핸들러 바인딩 (디바운스 적용 전에 바인딩)
81
+ const boundHandleResize = this.handleResize.bind(this);
82
+ this.handleResize = debounce(boundHandleResize, this.debounceDelay);
83
+ this.handleMouseMove = this.handleMouseMove.bind(this);
84
+ this.handleMouseLeave = this.handleMouseLeave.bind(this);
85
+ this.handleMouseDown = this.handleMouseDown.bind(this);
86
+ this.handleMouseUp = this.handleMouseUp.bind(this);
87
+ // morph와 updateConfig를 위한 디바운스된 내부 메서드
88
+ this._debouncedMorph = debounce(this._morphInternal.bind(this), this.debounceDelay);
89
+ this._debouncedUpdateConfig = debounce(this._updateConfigInternal.bind(this), this.debounceDelay);
90
+ // 초기화
91
+ this.init();
134
92
  }
135
- );
136
-
137
- this.intersectionObserver.observe(this.container);
138
- }
139
-
140
- resize() {
141
- const width = this.config.width || this.container.clientWidth || window.innerWidth;
142
- const height = this.config.height || this.container.clientHeight || window.innerHeight * 0.7;
143
-
144
- this.W = Math.floor(width * this.DPR);
145
- this.H = Math.floor(height * this.DPR);
146
-
147
- this.canvas.width = this.W;
148
- this.canvas.height = this.H;
149
- this.canvas.style.width = width + 'px';
150
- this.canvas.style.height = height + 'px';
151
-
152
- this.buildTargets();
153
- if (!this.particles.length) {
154
- this.initParticles();
155
- }
156
- }
157
-
158
- buildTargets() {
159
- const text = this.config.text;
160
- this.offCanvas.width = this.W;
161
- this.offCanvas.height = this.H;
162
- this.offCtx.clearRect(0, 0, this.offCanvas.width, this.offCanvas.height);
163
-
164
- const base = Math.min(this.W, this.H);
165
- const fontSize = this.config.fontSize || Math.max(80, Math.floor(base * 0.18));
166
- this.offCtx.fillStyle = '#ffffff';
167
- this.offCtx.textAlign = 'center';
168
- this.offCtx.textBaseline = 'middle';
169
- this.offCtx.font = `400 ${fontSize}px ${this.config.fontFamily}`;
170
-
171
- // 글자 간격 계산 및 그리기
172
- const chars = text.split('');
173
- const spacing = fontSize * 0.05;
174
- const totalWidth = this.offCtx.measureText(text).width + spacing * (chars.length - 1);
175
- let x = this.W / 2 - totalWidth / 2;
176
-
177
- for (const ch of chars) {
178
- this.offCtx.fillText(ch, x + this.offCtx.measureText(ch).width / 2, this.H / 2);
179
- x += this.offCtx.measureText(ch).width + spacing;
180
- }
181
-
182
- // 픽셀 샘플링
183
- const step = Math.max(2, this.config.densityStep);
184
- const img = this.offCtx.getImageData(0, 0, this.W, this.H).data;
185
- const targets = [];
186
-
187
- for (let y = 0; y < this.H; y += step) {
188
- for (let x = 0; x < this.W; x += step) {
189
- const i = (y * this.W + x) * 4;
190
- if (img[i] + img[i + 1] + img[i + 2] > 600) {
191
- targets.push({ x, y });
192
- }
93
+ init() {
94
+ this.resize();
95
+ this.setupEventListeners();
96
+ this.setupIntersectionObserver();
97
+ if (this.config.onReady) {
98
+ this.config.onReady(this);
99
+ }
193
100
  }
194
- }
195
-
196
- // 파티클 제한
197
- while (targets.length > this.config.maxParticles) {
198
- targets.splice(Math.floor(Math.random() * targets.length), 1);
199
- }
200
-
201
- // 파티클 조정
202
- if (this.particles.length < targets.length) {
203
- const need = targets.length - this.particles.length;
204
- for (let i = 0; i < need; i++) {
205
- this.particles.push(this.makeParticle());
101
+ setupIntersectionObserver() {
102
+ // IntersectionObserver가 지원되지 않는 환경에서는 항상 재생
103
+ if (typeof window === 'undefined' || typeof window.IntersectionObserver === 'undefined') {
104
+ this.isVisible = true;
105
+ this.start();
106
+ return;
107
+ }
108
+ // 이미 설정되어 있다면 다시 만들지 않음
109
+ if (this.intersectionObserver) {
110
+ return;
111
+ }
112
+ this.intersectionObserver = new IntersectionObserver((entries) => {
113
+ for (const entry of entries) {
114
+ if (entry.target !== this.container)
115
+ continue;
116
+ if (entry.isIntersecting) {
117
+ this.isVisible = true;
118
+ this.start();
119
+ }
120
+ else {
121
+ this.isVisible = false;
122
+ this.stop();
123
+ }
124
+ }
125
+ }, {
126
+ threshold: 0.1, // 10% 이상 보일 때 동작
127
+ });
128
+ this.intersectionObserver.observe(this.container);
206
129
  }
207
- } else if (this.particles.length > targets.length) {
208
- this.particles.length = targets.length;
209
- }
210
-
211
- // 목표 좌표 할당
212
- for (let i = 0; i < this.particles.length; i++) {
213
- const p = this.particles[i];
214
- const t = targets[i];
215
- p.tx = t.x;
216
- p.ty = t.y;
217
- }
218
- }
219
-
220
- makeParticle() {
221
- // 캔버스 전체에 골고루 분포 (여백 없이)
222
- const sx = Math.random() * this.W;
223
- const sy = Math.random() * this.H;
224
- return {
225
- x: sx,
226
- y: sy,
227
- vx: 0,
228
- vy: 0,
229
- tx: sx,
230
- ty: sy,
231
- initialX: sx, // 초기 위치 저장 (scatter 시 돌아갈 위치)
232
- initialY: sy,
233
- j: Math.random() * Math.PI * 2,
234
- };
235
- }
236
-
237
- initParticles() {
238
- // 캔버스 전체에 골고루 분포 (여백 없이)
239
- for (const p of this.particles) {
240
- const sx = Math.random() * this.W;
241
- const sy = Math.random() * this.H;
242
- p.x = sx;
243
- p.y = sy;
244
- p.vx = p.vy = 0;
245
- // 초기 위치 저장 (scatter 시 돌아갈 위치)
246
- p.initialX = sx;
247
- p.initialY = sy;
248
- }
249
- }
250
-
251
- scatter() {
252
- // 각 파티클을 초기 위치로 돌아가도록 설정
253
- for (const p of this.particles) {
254
- // 초기 위치가 저장되어 있으면 그 위치로, 없으면 현재 위치 유지
255
- if (p.initialX !== undefined && p.initialY !== undefined) {
256
- p.tx = p.initialX;
257
- p.ty = p.initialY;
258
- } else {
259
- // 초기 위치가 없으면 현재 위치를 초기 위치로 저장
260
- p.initialX = p.x;
261
- p.initialY = p.y;
262
- p.tx = p.initialX;
263
- p.ty = p.initialY;
130
+ resize() {
131
+ const width = this.config.width || this.container.clientWidth || window.innerWidth;
132
+ const height = this.config.height || this.container.clientHeight || window.innerHeight * 0.7;
133
+ this.W = Math.floor(width * this.DPR);
134
+ this.H = Math.floor(height * this.DPR);
135
+ this.canvas.width = this.W;
136
+ this.canvas.height = this.H;
137
+ this.canvas.style.width = width + 'px';
138
+ this.canvas.style.height = height + 'px';
139
+ this.buildTargets();
140
+ if (!this.particles.length) {
141
+ this.initParticles();
142
+ }
264
143
  }
265
- }
266
- }
267
-
268
- morph(textOrOptions = null) {
269
- // 즉시 실행이 필요한 경우 (예: 초기화 시)를 위해 내부 메서드 직접 호출
270
- // 일반적인 경우에는 디바운스 적용
271
- this._debouncedMorph(textOrOptions);
272
- }
273
-
274
- _morphInternal(textOrOptions = null) {
275
- // W와 H가 0이면 resize 먼저 실행
276
- if (this.W === 0 || this.H === 0) {
277
- this.resize();
278
- }
279
-
280
- if (typeof textOrOptions === 'string') {
281
- // 문자열인 경우: 기존 동작 유지
282
- this.config.text = textOrOptions;
283
- this.buildTargets();
284
- } else if (textOrOptions && typeof textOrOptions === 'object') {
285
- // 객체인 경우: 텍스트와 함께 다른 설정도 변경
286
- const needsRebuild = textOrOptions.text !== undefined;
287
- this.config = { ...this.config, ...textOrOptions };
288
- if (needsRebuild) {
289
- this.buildTargets();
144
+ buildTargets() {
145
+ const text = this.config.text;
146
+ this.offCanvas.width = this.W;
147
+ this.offCanvas.height = this.H;
148
+ this.offCtx.clearRect(0, 0, this.offCanvas.width, this.offCanvas.height);
149
+ const base = Math.min(this.W, this.H);
150
+ const fontSize = this.config.fontSize || Math.max(80, Math.floor(base * 0.18));
151
+ this.offCtx.fillStyle = '#ffffff';
152
+ this.offCtx.textAlign = 'center';
153
+ this.offCtx.textBaseline = 'middle';
154
+ this.offCtx.font = `400 ${fontSize}px ${this.config.fontFamily}`;
155
+ // 글자 간격 계산 그리기
156
+ const chars = text.split('');
157
+ const spacing = fontSize * 0.05;
158
+ const totalWidth = this.offCtx.measureText(text).width + spacing * (chars.length - 1);
159
+ let x = this.W / 2 - totalWidth / 2;
160
+ for (const ch of chars) {
161
+ this.offCtx.fillText(ch, x + this.offCtx.measureText(ch).width / 2, this.H / 2);
162
+ x += this.offCtx.measureText(ch).width + spacing;
163
+ }
164
+ // 픽셀 샘플링
165
+ const step = Math.max(2, this.config.densityStep);
166
+ const img = this.offCtx.getImageData(0, 0, this.W, this.H).data;
167
+ const targets = [];
168
+ for (let y = 0; y < this.H; y += step) {
169
+ for (let x = 0; x < this.W; x += step) {
170
+ const i = (y * this.W + x) * 4;
171
+ if (img[i] + img[i + 1] + img[i + 2] > 600) {
172
+ targets.push({ x, y });
173
+ }
174
+ }
175
+ }
176
+ // 파티클 수 제한
177
+ while (targets.length > this.config.maxParticles) {
178
+ targets.splice(Math.floor(Math.random() * targets.length), 1);
179
+ }
180
+ // 파티클 수 조정
181
+ if (this.particles.length < targets.length) {
182
+ const need = targets.length - this.particles.length;
183
+ for (let i = 0; i < need; i++) {
184
+ this.particles.push(this.makeParticle());
185
+ }
186
+ }
187
+ else if (this.particles.length > targets.length) {
188
+ this.particles.length = targets.length;
189
+ }
190
+ // 목표 좌표 할당
191
+ for (let i = 0; i < this.particles.length; i++) {
192
+ const p = this.particles[i];
193
+ const t = targets[i];
194
+ p.tx = t.x;
195
+ p.ty = t.y;
196
+ }
290
197
  }
291
- } else {
292
- // null이거나 undefined인 경우: 현재 텍스트로 재빌드
293
- this.buildTargets();
294
- }
295
- }
296
-
297
- update() {
298
- this.ctx.clearRect(0, 0, this.W, this.H);
299
-
300
- for (const p of this.particles) {
301
- // 목표 좌표로 당기는 힘
302
- let ax = (p.tx - p.x) * this.config.ease;
303
- let ay = (p.ty - p.y) * this.config.ease;
304
-
305
- // 마우스 반발/흡입
306
- if (this.mouse.x || this.mouse.y) {
307
- const dx = p.x - this.mouse.x;
308
- const dy = p.y - this.mouse.y;
309
- const d2 = dx * dx + dy * dy;
310
- const r = this.config.repelRadius * this.DPR;
311
- if (d2 < r * r) {
312
- const d = Math.sqrt(d2) + 0.0001;
313
- const f = (this.mouse.down ? -1 : 1) * this.config.repelStrength * (1 - d / r);
314
- ax += (dx / d) * f * 6.0;
315
- ay += (dy / d) * f * 6.0;
316
- }
198
+ makeParticle() {
199
+ // 캔버스 전체에 골고루 분포 (여백 없이)
200
+ const sx = Math.random() * this.W;
201
+ const sy = Math.random() * this.H;
202
+ return {
203
+ x: sx,
204
+ y: sy,
205
+ vx: 0,
206
+ vy: 0,
207
+ tx: sx,
208
+ ty: sy,
209
+ initialX: sx, // 초기 위치 저장 (scatter 돌아갈 위치)
210
+ initialY: sy,
211
+ j: Math.random() * Math.PI * 2,
212
+ };
213
+ }
214
+ initParticles() {
215
+ // 캔버스 전체에 골고루 분포 (여백 없이)
216
+ for (const p of this.particles) {
217
+ const sx = Math.random() * this.W;
218
+ const sy = Math.random() * this.H;
219
+ p.x = sx;
220
+ p.y = sy;
221
+ p.vx = p.vy = 0;
222
+ // 초기 위치 저장 (scatter 돌아갈 위치)
223
+ p.initialX = sx;
224
+ p.initialY = sy;
225
+ }
226
+ }
227
+ scatter() {
228
+ // 각 파티클을 초기 위치로 돌아가도록 설정
229
+ for (const p of this.particles) {
230
+ // 초기 위치가 저장되어 있으면 그 위치로, 없으면 현재 위치 유지
231
+ if (p.initialX !== undefined && p.initialY !== undefined) {
232
+ p.tx = p.initialX;
233
+ p.ty = p.initialY;
234
+ }
235
+ else {
236
+ // 초기 위치가 없으면 현재 위치를 초기 위치로 저장
237
+ p.initialX = p.x;
238
+ p.initialY = p.y;
239
+ p.tx = p.initialX;
240
+ p.ty = p.initialY;
241
+ }
242
+ }
243
+ }
244
+ morph(textOrOptions) {
245
+ // 즉시 실행이 필요한 경우 (예: 초기화 시)를 위해 내부 메서드 직접 호출
246
+ // 일반적인 경우에는 디바운스 적용
247
+ this._debouncedMorph(textOrOptions);
248
+ }
249
+ _morphInternal(textOrOptions) {
250
+ // W와 H가 0이면 resize 먼저 실행
251
+ if (this.W === 0 || this.H === 0) {
252
+ this.resize();
253
+ }
254
+ if (typeof textOrOptions === 'string') {
255
+ // 문자열인 경우: 기존 동작 유지
256
+ this.config.text = textOrOptions;
257
+ this.buildTargets();
258
+ }
259
+ else if (textOrOptions && typeof textOrOptions === 'object') {
260
+ // 객체인 경우: 텍스트와 함께 다른 설정도 변경
261
+ const needsRebuild = textOrOptions.text !== undefined;
262
+ this.config = { ...this.config, ...textOrOptions };
263
+ if (needsRebuild) {
264
+ this.buildTargets();
265
+ }
266
+ }
267
+ else {
268
+ // null이거나 undefined인 경우: 현재 텍스트로 재빌드
269
+ this.buildTargets();
270
+ }
271
+ }
272
+ update() {
273
+ this.ctx.clearRect(0, 0, this.W, this.H);
274
+ for (const p of this.particles) {
275
+ // 목표 좌표로 당기는 힘
276
+ let ax = (p.tx - p.x) * this.config.ease;
277
+ let ay = (p.ty - p.y) * this.config.ease;
278
+ // 마우스 반발/흡입
279
+ if (this.mouse.x || this.mouse.y) {
280
+ const dx = p.x - this.mouse.x;
281
+ const dy = p.y - this.mouse.y;
282
+ const d2 = dx * dx + dy * dy;
283
+ const r = this.config.repelRadius * this.DPR;
284
+ if (d2 < r * r) {
285
+ const d = Math.sqrt(d2) + 0.0001;
286
+ const f = (this.mouse.down ? -1 : 1) * this.config.repelStrength * (1 - d / r);
287
+ ax += (dx / d) * f * 6.0;
288
+ ay += (dy / d) * f * 6.0;
289
+ }
290
+ }
291
+ // 진동 효과
292
+ p.j += 2;
293
+ ax += Math.cos(p.j) * 0.05;
294
+ ay += Math.sin(p.j * 1.3) * 0.05;
295
+ // 속도와 위치 업데이트
296
+ p.vx = (p.vx + ax) * Math.random();
297
+ p.vy = (p.vy + ay) * Math.random();
298
+ p.x += p.vx;
299
+ p.y += p.vy;
300
+ }
301
+ // 파티클 그리기
302
+ this.ctx.fillStyle = this.config.particleColor;
303
+ const r = this.config.pointSize * this.DPR;
304
+ for (const p of this.particles) {
305
+ this.ctx.beginPath();
306
+ this.ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
307
+ this.ctx.fill();
308
+ }
309
+ if (this.config.onUpdate) {
310
+ this.config.onUpdate(this);
311
+ }
312
+ }
313
+ animate() {
314
+ if (!this.isRunning)
315
+ return;
316
+ this.update();
317
+ this.animationId = requestAnimationFrame(() => this.animate());
318
+ }
319
+ start() {
320
+ if (this.isRunning)
321
+ return;
322
+ this.isRunning = true;
323
+ this.animate();
324
+ }
325
+ stop() {
326
+ this.isRunning = false;
327
+ if (this.animationId) {
328
+ cancelAnimationFrame(this.animationId);
329
+ this.animationId = null;
330
+ }
331
+ }
332
+ setupEventListeners() {
333
+ window.addEventListener('resize', this.handleResize);
334
+ this.canvas.addEventListener('mousemove', this.handleMouseMove);
335
+ this.canvas.addEventListener('mouseleave', this.handleMouseLeave);
336
+ this.canvas.addEventListener('mousedown', this.handleMouseDown);
337
+ window.addEventListener('mouseup', this.handleMouseUp);
338
+ }
339
+ removeEventListeners() {
340
+ window.removeEventListener('resize', this.handleResize);
341
+ this.canvas.removeEventListener('mousemove', this.handleMouseMove);
342
+ this.canvas.removeEventListener('mouseleave', this.handleMouseLeave);
343
+ this.canvas.removeEventListener('mousedown', this.handleMouseDown);
344
+ window.removeEventListener('mouseup', this.handleMouseUp);
345
+ }
346
+ handleResize() {
347
+ this.resize();
348
+ }
349
+ handleMouseMove(e) {
350
+ const rect = this.canvas.getBoundingClientRect();
351
+ this.mouse.x = (e.clientX - rect.left) * this.DPR;
352
+ this.mouse.y = (e.clientY - rect.top) * this.DPR;
353
+ }
354
+ handleMouseLeave() {
355
+ this.mouse.x = this.mouse.y = 0;
356
+ }
357
+ handleMouseDown() {
358
+ this.mouse.down = true;
359
+ }
360
+ handleMouseUp() {
361
+ this.mouse.down = false;
362
+ }
363
+ // 설정 업데이트
364
+ updateConfig(newConfig) {
365
+ // 디바운스 적용
366
+ this._debouncedUpdateConfig(newConfig);
367
+ }
368
+ _updateConfigInternal(newConfig) {
369
+ this.config = { ...this.config, ...newConfig };
370
+ if (newConfig.text) {
371
+ this.buildTargets();
372
+ }
373
+ }
374
+ // 파괴 및 정리
375
+ destroy() {
376
+ this.stop();
377
+ this.removeEventListeners();
378
+ if (this.intersectionObserver) {
379
+ this.intersectionObserver.disconnect();
380
+ this.intersectionObserver = null;
381
+ }
382
+ if (this.canvas && this.canvas.parentNode) {
383
+ this.canvas.parentNode.removeChild(this.canvas);
384
+ }
317
385
  }
318
-
319
- // 진동 효과
320
- p.j += 2;
321
- ax += Math.cos(p.j) * 0.05;
322
- ay += Math.sin(p.j * 1.3) * 0.05;
323
-
324
- // 속도와 위치 업데이트
325
- p.vx = (p.vx + ax) * Math.random();
326
- p.vy = (p.vy + ay) * Math.random();
327
- p.x += p.vx;
328
- p.y += p.vy;
329
- }
330
-
331
- // 파티클 그리기
332
- this.ctx.fillStyle = this.config.particleColor;
333
- const r = this.config.pointSize * this.DPR;
334
- for (const p of this.particles) {
335
- this.ctx.beginPath();
336
- this.ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
337
- this.ctx.fill();
338
- }
339
-
340
- if (this.config.onUpdate) {
341
- this.config.onUpdate(this);
342
- }
343
- }
344
-
345
- animate() {
346
- if (!this.isRunning) return;
347
- this.update();
348
- this.animationId = requestAnimationFrame(() => this.animate());
349
- }
350
-
351
- start() {
352
- if (this.isRunning) return;
353
- this.isRunning = true;
354
- this.animate();
355
- }
356
-
357
- stop() {
358
- this.isRunning = false;
359
- if (this.animationId) {
360
- cancelAnimationFrame(this.animationId);
361
- this.animationId = null;
362
- }
363
- }
364
-
365
- setupEventListeners() {
366
- window.addEventListener('resize', this.handleResize);
367
- this.canvas.addEventListener('mousemove', this.handleMouseMove);
368
- this.canvas.addEventListener('mouseleave', this.handleMouseLeave);
369
- this.canvas.addEventListener('mousedown', this.handleMouseDown);
370
- window.addEventListener('mouseup', this.handleMouseUp);
371
- }
372
-
373
- removeEventListeners() {
374
- window.removeEventListener('resize', this.handleResize);
375
- this.canvas.removeEventListener('mousemove', this.handleMouseMove);
376
- this.canvas.removeEventListener('mouseleave', this.handleMouseLeave);
377
- this.canvas.removeEventListener('mousedown', this.handleMouseDown);
378
- window.removeEventListener('mouseup', this.handleMouseUp);
379
- }
380
-
381
- handleResize() {
382
- this.resize();
383
- }
384
-
385
- handleMouseMove(e) {
386
- const rect = this.canvas.getBoundingClientRect();
387
- this.mouse.x = (e.clientX - rect.left) * this.DPR;
388
- this.mouse.y = (e.clientY - rect.top) * this.DPR;
389
- }
390
-
391
- handleMouseLeave() {
392
- this.mouse.x = this.mouse.y = 0;
393
- }
394
-
395
- handleMouseDown() {
396
- this.mouse.down = true;
397
- }
398
-
399
- handleMouseUp() {
400
- this.mouse.down = false;
401
- }
402
-
403
- // 설정 업데이트
404
- updateConfig(newConfig) {
405
- // 디바운스 적용
406
- this._debouncedUpdateConfig(newConfig);
407
- }
408
-
409
- _updateConfigInternal(newConfig) {
410
- this.config = { ...this.config, ...newConfig };
411
- if (newConfig.text) {
412
- this.buildTargets();
413
- }
414
- }
415
-
416
- // 파괴 및 정리
417
- destroy() {
418
- this.stop();
419
- this.removeEventListeners();
420
- if (this.intersectionObserver) {
421
- this.intersectionObserver.disconnect();
422
- this.intersectionObserver = null;
423
- }
424
- if (this.canvas && this.canvas.parentNode) {
425
- this.canvas.parentNode.removeChild(this.canvas);
426
- }
427
386
  }
428
- }
429
387
 
430
- /**
431
- * MasonEffect - 메인 엔트리 포인트
432
- */
388
+ /**
389
+ * MasonEffect - 메인 엔트리 포인트
390
+ */
433
391
 
434
- exports.MasonEffect = MasonEffect;
435
- exports.default = MasonEffect;
392
+ exports.MasonEffect = MasonEffect;
393
+ exports.default = MasonEffect;
436
394
 
437
- Object.defineProperty(exports, '__esModule', { value: true });
395
+ Object.defineProperty(exports, '__esModule', { value: true });
438
396
 
439
397
  }));
440
398
  //# sourceMappingURL=index.umd.js.map