masoneffect 2.0.3 → 2.0.5

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.
Files changed (101) hide show
  1. package/README.md +2 -2
  2. package/dist/core/count/index.d.ts +3 -2
  3. package/dist/core/count/index.d.ts.map +1 -1
  4. package/dist/core/textToParticle/index.d.ts +3 -3
  5. package/dist/core/textToParticle/index.d.ts.map +1 -1
  6. package/dist/core/typing/index.d.ts +8 -6
  7. package/dist/core/typing/index.d.ts.map +1 -1
  8. package/dist/core/utils/visibilityManager.d.ts +35 -0
  9. package/dist/core/utils/visibilityManager.d.ts.map +1 -0
  10. package/dist/count/core/count/index.d.ts +3 -2
  11. package/dist/count/core/count/index.d.ts.map +1 -1
  12. package/dist/count/core/textToParticle/index.d.ts +3 -3
  13. package/dist/count/core/textToParticle/index.d.ts.map +1 -1
  14. package/dist/count/core/typing/index.d.ts +8 -6
  15. package/dist/count/core/typing/index.d.ts.map +1 -1
  16. package/dist/count/core/utils/visibilityManager.d.ts +35 -0
  17. package/dist/count/core/utils/visibilityManager.d.ts.map +1 -0
  18. package/dist/count/index.cjs +1 -1
  19. package/dist/count/index.mjs +1 -1
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.mjs +1 -1
  22. package/dist/index.umd.min.js +1 -1
  23. package/dist/react/core/count/index.d.ts +3 -2
  24. package/dist/react/core/textToParticle/index.d.ts +3 -3
  25. package/dist/react/core/typing/index.d.ts +8 -6
  26. package/dist/react/core/utils/visibilityManager.d.ts +34 -0
  27. package/dist/react/count/core/count/index.d.ts +3 -2
  28. package/dist/react/count/core/count/index.d.ts.map +1 -1
  29. package/dist/react/count/core/textToParticle/index.d.ts +3 -3
  30. package/dist/react/count/core/textToParticle/index.d.ts.map +1 -1
  31. package/dist/react/count/core/typing/index.d.ts +8 -6
  32. package/dist/react/count/core/typing/index.d.ts.map +1 -1
  33. package/dist/react/count/core/utils/visibilityManager.d.ts +35 -0
  34. package/dist/react/count/core/utils/visibilityManager.d.ts.map +1 -0
  35. package/dist/react/count/index.cjs +1 -1
  36. package/dist/react/count/index.mjs +1 -1
  37. package/dist/react/textToParticle/core/count/index.d.ts +3 -2
  38. package/dist/react/textToParticle/core/count/index.d.ts.map +1 -1
  39. package/dist/react/textToParticle/core/textToParticle/index.d.ts +3 -3
  40. package/dist/react/textToParticle/core/textToParticle/index.d.ts.map +1 -1
  41. package/dist/react/textToParticle/core/typing/index.d.ts +8 -6
  42. package/dist/react/textToParticle/core/typing/index.d.ts.map +1 -1
  43. package/dist/react/textToParticle/core/utils/visibilityManager.d.ts +35 -0
  44. package/dist/react/textToParticle/core/utils/visibilityManager.d.ts.map +1 -0
  45. package/dist/react/textToParticle/index.cjs +1 -1
  46. package/dist/react/textToParticle/index.mjs +1 -1
  47. package/dist/react/typing/core/count/index.d.ts +3 -2
  48. package/dist/react/typing/core/count/index.d.ts.map +1 -1
  49. package/dist/react/typing/core/textToParticle/index.d.ts +3 -3
  50. package/dist/react/typing/core/textToParticle/index.d.ts.map +1 -1
  51. package/dist/react/typing/core/typing/index.d.ts +8 -6
  52. package/dist/react/typing/core/typing/index.d.ts.map +1 -1
  53. package/dist/react/typing/core/utils/visibilityManager.d.ts +35 -0
  54. package/dist/react/typing/core/utils/visibilityManager.d.ts.map +1 -0
  55. package/dist/react/typing/index.cjs +1 -1
  56. package/dist/react/typing/index.mjs +1 -1
  57. package/dist/svelte/count/index.cjs +1 -1
  58. package/dist/svelte/count/index.d.ts +46 -32
  59. package/dist/svelte/count/index.mjs +120 -42
  60. package/dist/svelte/index.cjs +1 -1
  61. package/dist/svelte/index.d.ts +46 -32
  62. package/dist/svelte/index.mjs +211 -160
  63. package/dist/svelte/textToParticle/index.cjs +1 -1
  64. package/dist/svelte/textToParticle/index.d.ts +46 -32
  65. package/dist/svelte/textToParticle/index.mjs +119 -33
  66. package/dist/svelte/typing/index.cjs +1 -1
  67. package/dist/svelte/typing/index.d.ts +46 -32
  68. package/dist/svelte/typing/index.mjs +174 -85
  69. package/dist/textToParticle/core/count/index.d.ts +3 -2
  70. package/dist/textToParticle/core/count/index.d.ts.map +1 -1
  71. package/dist/textToParticle/core/textToParticle/index.d.ts +3 -3
  72. package/dist/textToParticle/core/textToParticle/index.d.ts.map +1 -1
  73. package/dist/textToParticle/core/typing/index.d.ts +8 -6
  74. package/dist/textToParticle/core/typing/index.d.ts.map +1 -1
  75. package/dist/textToParticle/core/utils/visibilityManager.d.ts +35 -0
  76. package/dist/textToParticle/core/utils/visibilityManager.d.ts.map +1 -0
  77. package/dist/textToParticle/index.cjs +1 -1
  78. package/dist/textToParticle/index.mjs +1 -1
  79. package/dist/typing/core/count/index.d.ts +3 -2
  80. package/dist/typing/core/count/index.d.ts.map +1 -1
  81. package/dist/typing/core/textToParticle/index.d.ts +3 -3
  82. package/dist/typing/core/textToParticle/index.d.ts.map +1 -1
  83. package/dist/typing/core/typing/index.d.ts +8 -6
  84. package/dist/typing/core/typing/index.d.ts.map +1 -1
  85. package/dist/typing/core/utils/visibilityManager.d.ts +35 -0
  86. package/dist/typing/core/utils/visibilityManager.d.ts.map +1 -0
  87. package/dist/typing/index.cjs +1 -1
  88. package/dist/typing/index.mjs +1 -1
  89. package/dist/vue/count/index.cjs +1 -1
  90. package/dist/vue/count/index.d.ts +46 -32
  91. package/dist/vue/count/index.mjs +119 -41
  92. package/dist/vue/index.cjs +1 -1
  93. package/dist/vue/index.d.ts +46 -32
  94. package/dist/vue/index.mjs +209 -158
  95. package/dist/vue/textToParticle/index.cjs +1 -1
  96. package/dist/vue/textToParticle/index.d.ts +46 -32
  97. package/dist/vue/textToParticle/index.mjs +119 -33
  98. package/dist/vue/typing/index.cjs +1 -1
  99. package/dist/vue/typing/index.d.ts +46 -32
  100. package/dist/vue/typing/index.mjs +173 -84
  101. package/package.json +1 -1
@@ -7,12 +7,12 @@ export declare class Count {
7
7
  currentValue: number;
8
8
  startTime: number | null;
9
9
  animationFrameId: number | null;
10
- intersectionObserver: IntersectionObserver | null;
10
+ visibilityManager: VisibilityManager | null;
11
11
  isRunning: boolean;
12
12
  hasTriggered: boolean;
13
13
  constructor(container: HTMLElement | string, options: CountOptions);
14
14
  init(): void;
15
- setupIntersectionObserver(): void;
15
+ setupVisibilityManager(): void;
16
16
  start(): void;
17
17
  stop(): void;
18
18
  reset(): void;
@@ -23,13 +23,6 @@ export declare class Count {
23
23
  destroy(): void;
24
24
  }
25
25
 
26
- /**
27
- * Count - 숫자 카운팅 애니메이션 효과
28
- * 바닐라 JS 코어 클래스
29
- *
30
- * 사용법:
31
- * import { Count } from 'masoneffect/count';
32
- */
33
26
  export declare interface CountOptions {
34
27
  targetValue: number;
35
28
  duration?: number;
@@ -84,14 +77,13 @@ declare class TextToParticle {
84
77
  };
85
78
  animationId: number | null;
86
79
  isRunning: boolean;
87
- isVisible: boolean;
88
- intersectionObserver: IntersectionObserver | null;
80
+ visibilityManager: VisibilityManager | null;
89
81
  debounceDelay: number;
90
82
  _debouncedMorph: (textOrOptions?: string | Partial<TextToParticleOptions> | null) => void;
91
83
  _debouncedUpdateConfig: (newConfig: Partial<TextToParticleOptions>) => void;
92
84
  constructor(container: HTMLElement | string, options?: TextToParticleOptions);
93
85
  init(): void;
94
- setupIntersectionObserver(): void;
86
+ setupVisibilityManager(): void;
95
87
  resize(): void;
96
88
  /**
97
89
  * 텍스트가 영역 안에 들어가는지 확인하는 헬퍼 함수 (줄바꿈 지원)
@@ -132,13 +124,6 @@ declare class TextToParticle {
132
124
  export { TextToParticle }
133
125
  export default TextToParticle;
134
126
 
135
- /**
136
- * TextToParticle - 텍스트를 파티클로 변환하는 효과
137
- * 바닐라 JS 코어 클래스
138
- *
139
- * 사용법:
140
- * import { TextToParticle } from 'masoneffect/textToParticle';
141
- */
142
127
  declare interface TextToParticleOptions {
143
128
  text?: string;
144
129
  densityStep?: number;
@@ -167,20 +152,21 @@ declare class TextToParticle {
167
152
  onComplete: TypingOptions['onComplete'];
168
153
  };
169
154
  textUnits: string[];
155
+ charUnitRanges: Array<{
156
+ start: number;
157
+ end: number;
158
+ isHangul: boolean;
159
+ }>;
170
160
  currentIndex: number;
171
161
  displayedText: string;
172
162
  timeoutId: ReturnType<typeof setTimeout> | null;
173
- intersectionObserver: IntersectionObserver | null;
163
+ visibilityManager: VisibilityManager | null;
174
164
  isRunning: boolean;
175
165
  hasTriggered: boolean;
176
166
  originalText: string;
177
167
  constructor(container: HTMLElement | string, options: TypingOptions);
178
168
  init(): void;
179
- setupIntersectionObserver(): void;
180
- private originalChars;
181
- private charUnitMap;
182
- private initializeTextStructure;
183
- private getCharIndexFromUnitIndex;
169
+ setupVisibilityManager(): void;
184
170
  private buildTextFromUnits;
185
171
  start(): void;
186
172
  typeNext(): void;
@@ -191,13 +177,6 @@ declare class TextToParticle {
191
177
  destroy(): void;
192
178
  }
193
179
 
194
- /**
195
- * Typing - 타이핑 애니메이션 효과
196
- * 바닐라 JS 코어 클래스
197
- *
198
- * 사용법:
199
- * import { Typing } from 'masoneffect/typing';
200
- */
201
180
  export declare interface TypingOptions {
202
181
  text: string;
203
182
  speed?: number;
@@ -212,4 +191,39 @@ declare class TextToParticle {
212
191
  onComplete?: () => void;
213
192
  }
214
193
 
194
+ declare class VisibilityManager {
195
+ private container;
196
+ private options;
197
+ private intersectionObserver;
198
+ private visibilityChangeHandler;
199
+ private isVisible;
200
+ private isPageVisible;
201
+ constructor(container: HTMLElement, options?: VisibilityManagerOptions);
202
+ private setupIntersectionObserver;
203
+ private setupPageVisibility;
204
+ /**
205
+ * 현재 요소가 화면에 보이는지 확인
206
+ */
207
+ getIsVisible(): boolean;
208
+ /**
209
+ * 옵션 업데이트
210
+ */
211
+ updateOptions(newOptions: Partial<VisibilityManagerOptions>): void;
212
+ /**
213
+ * 리소스 정리
214
+ */
215
+ destroy(): void;
216
+ }
217
+
218
+ /**
219
+ * VisibilityManager - IntersectionObserver와 Page Visibility API를 통합 관리
220
+ * 모든 효과에서 공통으로 사용하는 가시성 관리 유틸리티
221
+ */
222
+ declare interface VisibilityManagerOptions {
223
+ threshold?: number;
224
+ rootMargin?: string;
225
+ onVisible?: () => void;
226
+ onHidden?: () => void;
227
+ }
228
+
215
229
  export { }
@@ -1,4 +1,105 @@
1
1
  import { defineComponent, ref, watch, onMounted, onBeforeUnmount, createElementBlock, openBlock, normalizeStyle, normalizeClass } from "vue";
2
+ class VisibilityManager {
3
+ constructor(container, options = {}) {
4
+ this.container = container;
5
+ this.options = {
6
+ threshold: options.threshold ?? 0.1,
7
+ rootMargin: options.rootMargin ?? "0px",
8
+ onVisible: options.onVisible,
9
+ onHidden: options.onHidden
10
+ };
11
+ this.intersectionObserver = null;
12
+ this.visibilityChangeHandler = null;
13
+ this.isVisible = false;
14
+ this.isPageVisible = typeof document !== "undefined" ? !document.hidden : true;
15
+ this.setupIntersectionObserver();
16
+ this.setupPageVisibility();
17
+ }
18
+ setupIntersectionObserver() {
19
+ if (typeof window === "undefined" || typeof window.IntersectionObserver === "undefined") {
20
+ this.isVisible = true;
21
+ if (this.isPageVisible && this.options.onVisible) {
22
+ this.options.onVisible();
23
+ }
24
+ return;
25
+ }
26
+ this.intersectionObserver = new IntersectionObserver(
27
+ (entries) => {
28
+ for (const entry of entries) {
29
+ if (entry.target !== this.container) continue;
30
+ if (entry.isIntersecting) {
31
+ this.isVisible = true;
32
+ if (this.isPageVisible && this.options.onVisible) {
33
+ this.options.onVisible();
34
+ }
35
+ } else {
36
+ this.isVisible = false;
37
+ if (this.options.onHidden) {
38
+ this.options.onHidden();
39
+ }
40
+ }
41
+ }
42
+ },
43
+ {
44
+ threshold: this.options.threshold,
45
+ rootMargin: this.options.rootMargin
46
+ }
47
+ );
48
+ this.intersectionObserver.observe(this.container);
49
+ }
50
+ setupPageVisibility() {
51
+ if (typeof document === "undefined") return;
52
+ this.visibilityChangeHandler = () => {
53
+ const wasVisible = this.isPageVisible;
54
+ this.isPageVisible = !document.hidden;
55
+ if (document.hidden) {
56
+ if (this.options.onHidden) {
57
+ this.options.onHidden();
58
+ }
59
+ } else if (wasVisible !== this.isPageVisible) {
60
+ if (this.isVisible && this.options.onVisible) {
61
+ this.options.onVisible();
62
+ }
63
+ }
64
+ };
65
+ document.addEventListener("visibilitychange", this.visibilityChangeHandler);
66
+ if (document.hidden && this.isVisible) {
67
+ if (this.options.onHidden) {
68
+ this.options.onHidden();
69
+ }
70
+ }
71
+ }
72
+ /**
73
+ * 현재 요소가 화면에 보이는지 확인
74
+ */
75
+ getIsVisible() {
76
+ return this.isVisible && this.isPageVisible;
77
+ }
78
+ /**
79
+ * 옵션 업데이트
80
+ */
81
+ updateOptions(newOptions) {
82
+ this.options = { ...this.options, ...newOptions };
83
+ if (this.intersectionObserver) {
84
+ this.intersectionObserver.disconnect();
85
+ this.intersectionObserver = null;
86
+ }
87
+ this.setupIntersectionObserver();
88
+ }
89
+ /**
90
+ * 리소스 정리
91
+ */
92
+ destroy() {
93
+ if (this.intersectionObserver) {
94
+ this.intersectionObserver.disconnect();
95
+ this.intersectionObserver = null;
96
+ }
97
+ if (this.visibilityChangeHandler && typeof document !== "undefined") {
98
+ document.removeEventListener("visibilitychange", this.visibilityChangeHandler);
99
+ this.visibilityChangeHandler = null;
100
+ }
101
+ }
102
+ }
2
103
  function debounce(func, wait) {
3
104
  let timeout = null;
4
105
  return function executedFunction(...args) {
@@ -56,8 +157,7 @@ class TextToParticle {
56
157
  this.mouse = { x: 0, y: 0, down: false };
57
158
  this.animationId = null;
58
159
  this.isRunning = false;
59
- this.isVisible = false;
60
- this.intersectionObserver = null;
160
+ this.visibilityManager = null;
61
161
  this.debounceDelay = options.debounceDelay ?? 150;
62
162
  const boundHandleResize = this.handleResize.bind(this);
63
163
  this.handleResize = debounce(boundHandleResize, this.debounceDelay);
@@ -72,39 +172,22 @@ class TextToParticle {
72
172
  init() {
73
173
  this.resize();
74
174
  this.setupEventListeners();
75
- this.setupIntersectionObserver();
175
+ this.setupVisibilityManager();
76
176
  if (this.config.onReady) {
77
177
  this.config.onReady(this);
78
178
  }
79
179
  }
80
- setupIntersectionObserver() {
81
- if (typeof window === "undefined" || typeof window.IntersectionObserver === "undefined") {
82
- this.isVisible = true;
83
- this.start();
84
- return;
85
- }
86
- if (this.intersectionObserver) {
87
- return;
88
- }
89
- this.intersectionObserver = new IntersectionObserver(
90
- (entries) => {
91
- for (const entry of entries) {
92
- if (entry.target !== this.container) continue;
93
- if (entry.isIntersecting) {
94
- this.isVisible = true;
95
- this.start();
96
- } else {
97
- this.isVisible = false;
98
- this.stop();
99
- }
100
- }
180
+ setupVisibilityManager() {
181
+ this.visibilityManager = new VisibilityManager(this.container, {
182
+ threshold: 0.1,
183
+ // 10% 이상 보일 때 동작
184
+ onVisible: () => {
185
+ this.start();
101
186
  },
102
- {
103
- threshold: 0.1
104
- // 10% 이상 보일 때 동작
187
+ onHidden: () => {
188
+ this.stop();
105
189
  }
106
- );
107
- this.intersectionObserver.observe(this.container);
190
+ });
108
191
  }
109
192
  resize() {
110
193
  const width = this.config.width || this.container.clientWidth || window.innerWidth;
@@ -341,7 +424,10 @@ class TextToParticle {
341
424
  p.y += p.vy;
342
425
  }
343
426
  this.ctx.fillStyle = this.config.particleColor;
344
- const r = this.config.pointSize * this.DPR;
427
+ const baseSize = 1920;
428
+ const currentSize = Math.min(this.W, this.H) / this.DPR;
429
+ const sizeRatio = Math.max(0.5, Math.min(2, currentSize / baseSize));
430
+ const r = this.config.pointSize * this.DPR * sizeRatio;
345
431
  for (const p of this.particles) {
346
432
  this.ctx.beginPath();
347
433
  this.ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
@@ -413,9 +499,9 @@ class TextToParticle {
413
499
  destroy() {
414
500
  this.stop();
415
501
  this.removeEventListeners();
416
- if (this.intersectionObserver) {
417
- this.intersectionObserver.disconnect();
418
- this.intersectionObserver = null;
502
+ if (this.visibilityManager) {
503
+ this.visibilityManager.destroy();
504
+ this.visibilityManager = null;
419
505
  }
420
506
  if (this.canvas && this.canvas.parentNode) {
421
507
  this.canvas.parentNode.removeChild(this.canvas);
@@ -1 +1 @@
1
- "use strict";const t=require("vue");function e(t){const e=t.charCodeAt(0);if(e<44032||e>55203)return[t];const i=e-44032,s=Math.floor(i/588),n=Math.floor(i%588/28),r=i%28,o=["","ㄱ","ㄲ","ㄳ","ㄴ","ㄵ","ㄶ","ㄷ","ㄹ","ㄺ","ㄻ","ㄼ","ㄽ","ㄾ","ㄿ","ㅀ","ㅁ","ㅂ","ㅄ","ㅅ","ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"],h=[];return h.push(["ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"][s]),h.push(["ㅏ","ㅐ","ㅑ","ㅒ","ㅓ","ㅔ","ㅕ","ㅖ","ㅗ","ㅘ","ㅙ","ㅚ","ㅛ","ㅜ","ㅝ","ㅞ","ㅟ","ㅠ","ㅡ","ㅢ","ㅣ"][n]),r>0&&h.push(o[r]),h}function i(t){const i=[];for(let s=0;s<t.length;s++){const n=t[s],r=n.charCodeAt(0);if(r>=44032&&r<=55203){const t=e(n);i.push(...t)}else i.push(n)}return i}class s{constructor(t,e){if(this.originalChars=[],this.charUnitMap=[],this.container="string"==typeof t?document.querySelector(t):t,!this.container)throw new Error("Container element not found");this.originalText=e.text,this.config={text:e.text,speed:e.speed??50,delay:e.delay??0,enabled:e.enabled??!0,threshold:e.threshold??.2,rootMargin:e.rootMargin??"0px 0px -100px 0px",triggerOnce:e.triggerOnce??!1,showCursor:e.showCursor??!0,cursorChar:e.cursorChar??"|",onUpdate:e.onUpdate||null,onComplete:e.onComplete||null},this.textUnits=i(this.config.text),this.originalChars=[],this.charUnitMap=[],this.initializeTextStructure(),this.currentIndex=0,this.displayedText="",this.timeoutId=null,this.intersectionObserver=null,this.isRunning=!1,this.hasTriggered=!1,this.init()}init(){this.updateDisplay(""),this.setupIntersectionObserver()}setupIntersectionObserver(){"undefined"!=typeof window&&void 0!==window.IntersectionObserver?(this.intersectionObserver=new IntersectionObserver(t=>{var e;for(const i of t)i.target===this.container&&i.isIntersecting&&!this.hasTriggered&&(this.config.enabled&&setTimeout(()=>this.start(),this.config.delay),this.hasTriggered=!0,this.config.triggerOnce&&(null==(e=this.intersectionObserver)||e.disconnect()))},{threshold:this.config.threshold,rootMargin:this.config.rootMargin}),this.intersectionObserver.observe(this.container)):this.config.enabled&&setTimeout(()=>this.start(),this.config.delay)}initializeTextStructure(){this.originalChars=[],this.charUnitMap=[];for(let t=0;t<this.originalText.length;t++){const i=this.originalText[t],s=i.charCodeAt(0);if(this.originalChars.push(i),s>=44032&&s<=55203){const t=e(i);this.charUnitMap.push(t.length)}else this.charUnitMap.push(1)}}getCharIndexFromUnitIndex(t){if(0===t)return 0;let e=0,i=0;for(let s=0;s<this.charUnitMap.length;s++){const n=this.charUnitMap[s];if(i+=n,!(t>=i)){const r=t-(i-n);if(r>0){const t=this.originalChars[s]&&this.originalChars[s].charCodeAt(0)>=44032&&this.originalChars[s].charCodeAt(0)<=55203;(t&&r>=2||!t&&r>=1)&&(e=s+1)}break}e=s+1}return e}buildTextFromUnits(t){if(0===t.length)return"";const e=this.getCharIndexFromUnitIndex(t.length);return this.originalText.substring(0,e)}start(){this.isRunning||(this.isRunning=!0,this.currentIndex=0,this.displayedText="",this.typeNext())}typeNext(){if(this.currentIndex>=this.textUnits.length)return this.isRunning=!1,this.config.showCursor&&this.updateDisplay(this.originalText),void(this.config.onComplete&&this.config.onComplete());const t=this.textUnits.slice(0,this.currentIndex+1);this.displayedText=this.buildTextFromUnits(t);let e=this.displayedText;this.config.showCursor&&(e+=this.config.cursorChar),this.updateDisplay(e),this.config.onUpdate&&this.config.onUpdate(this.displayedText),this.currentIndex++,this.timeoutId=setTimeout(()=>{this.typeNext()},this.config.speed)}stop(){this.isRunning=!1,this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=null)}reset(){this.stop(),this.currentIndex=0,this.displayedText="",this.hasTriggered=!1,this.updateDisplay("")}updateDisplay(t){this.container.textContent=t}setText(t){this.originalText=t,this.config.text=t,this.textUnits=i(t),this.initializeTextStructure(),this.reset(),this.config.enabled&&setTimeout(()=>this.start(),this.config.delay)}destroy(){this.stop(),this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null)}}const n=t.defineComponent({__name:"Typing",props:{className:{},style:{},onUpdate:{},onComplete:{},text:{},speed:{default:50},delay:{default:0},enabled:{type:Boolean,default:!0},threshold:{default:.2},rootMargin:{default:"0px 0px -100px 0px"},triggerOnce:{type:Boolean,default:!1},showCursor:{type:Boolean,default:!0},cursorChar:{default:"|"}},setup(e,{expose:i}){const n=e,r=t.ref(null),o=t.ref(null);return t.onMounted(()=>{if(!r.value)return;const t={text:n.text,speed:n.speed,delay:n.delay,enabled:n.enabled,threshold:n.threshold,rootMargin:n.rootMargin,triggerOnce:n.triggerOnce,showCursor:n.showCursor,cursorChar:n.cursorChar,onUpdate:n.onUpdate,onComplete:n.onComplete};o.value=new s(r.value,t)}),t.onUnmounted(()=>{o.value&&(o.value.destroy(),o.value=null)}),t.watch(()=>n.text,t=>{o.value&&t!==o.value.originalText&&o.value.setText(t)}),i({start:()=>{var t;return null==(t=o.value)?void 0:t.start()},stop:()=>{var t;return null==(t=o.value)?void 0:t.stop()},reset:()=>{var t;return null==(t=o.value)?void 0:t.reset()},setText:t=>{var e;return null==(e=o.value)?void 0:e.setText(t)},destroy:()=>{o.value&&(o.value.destroy(),o.value=null)}}),(i,s)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"containerRef",ref:r,class:t.normalizeClass(e.className),style:t.normalizeStyle(e.style)},null,6))}});module.exports=n;
1
+ "use strict";const t=require("vue");class e{constructor(t,e={}){this.container=t,this.options={threshold:e.threshold??.1,rootMargin:e.rootMargin??"0px",onVisible:e.onVisible,onHidden:e.onHidden},this.intersectionObserver=null,this.visibilityChangeHandler=null,this.isVisible=!1,this.isPageVisible="undefined"==typeof document||!document.hidden,this.setupIntersectionObserver(),this.setupPageVisibility()}setupIntersectionObserver(){if("undefined"==typeof window||void 0===window.IntersectionObserver)return this.isVisible=!0,void(this.isPageVisible&&this.options.onVisible&&this.options.onVisible());this.intersectionObserver=new IntersectionObserver(t=>{for(const e of t)e.target===this.container&&(e.isIntersecting?(this.isVisible=!0,this.isPageVisible&&this.options.onVisible&&this.options.onVisible()):(this.isVisible=!1,this.options.onHidden&&this.options.onHidden()))},{threshold:this.options.threshold,rootMargin:this.options.rootMargin}),this.intersectionObserver.observe(this.container)}setupPageVisibility(){"undefined"!=typeof document&&(this.visibilityChangeHandler=()=>{const t=this.isPageVisible;this.isPageVisible=!document.hidden,document.hidden?this.options.onHidden&&this.options.onHidden():t!==this.isPageVisible&&this.isVisible&&this.options.onVisible&&this.options.onVisible()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),document.hidden&&this.isVisible&&this.options.onHidden&&this.options.onHidden())}getIsVisible(){return this.isVisible&&this.isPageVisible}updateOptions(t){this.options={...this.options,...t},this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null),this.setupIntersectionObserver()}destroy(){this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null),this.visibilityChangeHandler&&"undefined"!=typeof document&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null)}}function i(t){const e=t.charCodeAt(0);if(e<44032||e>55203)return[t];const i=e-44032,s=Math.floor(i/588),n=Math.floor(i%588/28),o=i%28,r=["","ㄱ","ㄲ","ㄳ","ㄴ","ㄵ","ㄶ","ㄷ","ㄹ","ㄺ","ㄻ","ㄼ","ㄽ","ㄾ","ㄿ","ㅀ","ㅁ","ㅂ","ㅄ","ㅅ","ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"],h=[];return h.push(["ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"][s]),h.push(["ㅏ","ㅐ","ㅑ","ㅒ","ㅓ","ㅔ","ㅕ","ㅖ","ㅗ","ㅘ","ㅙ","ㅚ","ㅛ","ㅜ","ㅝ","ㅞ","ㅟ","ㅠ","ㅡ","ㅢ","ㅣ"][n]),o>0&&h.push(r[o]),h}function s(t,e,i){const s=["ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"].indexOf(t),n=["ㅏ","ㅐ","ㅑ","ㅒ","ㅓ","ㅔ","ㅕ","ㅖ","ㅗ","ㅘ","ㅙ","ㅚ","ㅛ","ㅜ","ㅝ","ㅞ","ㅟ","ㅠ","ㅡ","ㅢ","ㅣ"].indexOf(e),o=i?["","ㄱ","ㄲ","ㄳ","ㄴ","ㄵ","ㄶ","ㄷ","ㄹ","ㄺ","ㄻ","ㄼ","ㄽ","ㄾ","ㄿ","ㅀ","ㅁ","ㅂ","ㅄ","ㅅ","ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"].indexOf(i):0;if(-1===s||-1===n)return t+(e||"")+(i||"");const r=44032+21*s*28+28*n+o;return String.fromCharCode(r)}function n(t){const e=[],s=[];for(let n=0;n<t.length;n++){const o=t[n],r=o.charCodeAt(0),h=e.length;if(r>=44032&&r<=55203){const t=i(o);e.push(...t),s.push({start:h,end:e.length,isHangul:!0})}else e.push(o),s.push({start:h,end:e.length,isHangul:!1})}return{units:e,charUnitRanges:s}}class o{constructor(t,e){if(this.container="string"==typeof t?document.querySelector(t):t,!this.container)throw new Error("Container element not found");this.originalText=e.text,this.config={text:e.text,speed:e.speed??50,delay:e.delay??0,enabled:e.enabled??!0,threshold:e.threshold??.2,rootMargin:e.rootMargin??"0px 0px -100px 0px",triggerOnce:e.triggerOnce??!1,showCursor:e.showCursor??!0,cursorChar:e.cursorChar??"|",onUpdate:e.onUpdate||null,onComplete:e.onComplete||null};const i=n(this.config.text);this.textUnits=i.units,this.charUnitRanges=i.charUnitRanges,this.currentIndex=0,this.displayedText="",this.timeoutId=null,this.visibilityManager=null,this.isRunning=!1,this.hasTriggered=!1,this.init()}init(){this.updateDisplay(""),this.setupVisibilityManager()}setupVisibilityManager(){this.visibilityManager=new e(this.container,{threshold:this.config.threshold,rootMargin:this.config.rootMargin,onVisible:()=>{!this.hasTriggered&&this.config.enabled&&(this.hasTriggered=!0,setTimeout(()=>this.start(),this.config.delay))},onHidden:()=>{}})}buildTextFromUnits(t){if(0===t)return"";let e="";for(let i=0;i<this.charUnitRanges.length;i++){const n=this.charUnitRanges[i];if(n.start>=t)break;const o=Math.min(t-n.start,n.end-n.start);if(o<=0)break;if(n.isHangul){const t=this.textUnits.slice(n.start,n.start+o);1===t.length?e+=t[0]:2===t.length?e+=s(t[0],t[1]):t.length>=3&&(e+=s(t[0],t[1],t[2]))}else o>0&&(e+=this.textUnits[n.start])}return e}start(){this.isRunning||(this.isRunning=!0,this.currentIndex=0,this.displayedText="",this.typeNext())}typeNext(){if(this.currentIndex>=this.textUnits.length)return this.isRunning=!1,this.config.showCursor&&this.updateDisplay(this.originalText),void(this.config.onComplete&&this.config.onComplete());this.displayedText=this.buildTextFromUnits(this.currentIndex+1);let t=this.displayedText;this.config.showCursor&&(t+=this.config.cursorChar),this.updateDisplay(t),this.config.onUpdate&&this.config.onUpdate(this.displayedText),this.currentIndex++,this.timeoutId=setTimeout(()=>{this.typeNext()},this.config.speed)}stop(){this.isRunning=!1,this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=null)}reset(){this.stop(),this.currentIndex=0,this.displayedText="",this.hasTriggered=!1,this.updateDisplay("")}updateDisplay(t){this.container.textContent=t}setText(t){this.originalText=t,this.config.text=t;const e=n(t);this.textUnits=e.units,this.charUnitRanges=e.charUnitRanges,this.reset(),this.config.enabled&&setTimeout(()=>this.start(),this.config.delay)}destroy(){this.stop(),this.visibilityManager&&(this.visibilityManager.destroy(),this.visibilityManager=null)}}const r=t.defineComponent({__name:"Typing",props:{className:{},style:{},onUpdate:{},onComplete:{},text:{},speed:{default:50},delay:{default:0},enabled:{type:Boolean,default:!0},threshold:{default:.2},rootMargin:{default:"0px 0px -100px 0px"},triggerOnce:{type:Boolean,default:!1},showCursor:{type:Boolean,default:!0},cursorChar:{default:"|"}},setup(e,{expose:i}){const s=e,n=t.ref(null),r=t.ref(null);return t.onMounted(()=>{if(!n.value)return;const t={text:s.text,speed:s.speed,delay:s.delay,enabled:s.enabled,threshold:s.threshold,rootMargin:s.rootMargin,triggerOnce:s.triggerOnce,showCursor:s.showCursor,cursorChar:s.cursorChar,onUpdate:s.onUpdate,onComplete:s.onComplete};r.value=new o(n.value,t)}),t.onUnmounted(()=>{r.value&&(r.value.destroy(),r.value=null)}),t.watch(()=>s.text,t=>{r.value&&t!==r.value.originalText&&r.value.setText(t)}),i({start:()=>{var t;return null==(t=r.value)?void 0:t.start()},stop:()=>{var t;return null==(t=r.value)?void 0:t.stop()},reset:()=>{var t;return null==(t=r.value)?void 0:t.reset()},setText:t=>{var e;return null==(e=r.value)?void 0:e.setText(t)},destroy:()=>{r.value&&(r.value.destroy(),r.value=null)}}),(i,s)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"containerRef",ref:n,class:t.normalizeClass(e.className),style:t.normalizeStyle(e.style)},null,6))}});module.exports=r;
@@ -7,12 +7,12 @@ export declare class Count {
7
7
  currentValue: number;
8
8
  startTime: number | null;
9
9
  animationFrameId: number | null;
10
- intersectionObserver: IntersectionObserver | null;
10
+ visibilityManager: VisibilityManager | null;
11
11
  isRunning: boolean;
12
12
  hasTriggered: boolean;
13
13
  constructor(container: HTMLElement | string, options: CountOptions);
14
14
  init(): void;
15
- setupIntersectionObserver(): void;
15
+ setupVisibilityManager(): void;
16
16
  start(): void;
17
17
  stop(): void;
18
18
  reset(): void;
@@ -23,13 +23,6 @@ export declare class Count {
23
23
  destroy(): void;
24
24
  }
25
25
 
26
- /**
27
- * Count - 숫자 카운팅 애니메이션 효과
28
- * 바닐라 JS 코어 클래스
29
- *
30
- * 사용법:
31
- * import { Count } from 'masoneffect/count';
32
- */
33
26
  export declare interface CountOptions {
34
27
  targetValue: number;
35
28
  duration?: number;
@@ -84,14 +77,13 @@ declare class TextToParticle {
84
77
  };
85
78
  animationId: number | null;
86
79
  isRunning: boolean;
87
- isVisible: boolean;
88
- intersectionObserver: IntersectionObserver | null;
80
+ visibilityManager: VisibilityManager | null;
89
81
  debounceDelay: number;
90
82
  _debouncedMorph: (textOrOptions?: string | Partial<TextToParticleOptions> | null) => void;
91
83
  _debouncedUpdateConfig: (newConfig: Partial<TextToParticleOptions>) => void;
92
84
  constructor(container: HTMLElement | string, options?: TextToParticleOptions);
93
85
  init(): void;
94
- setupIntersectionObserver(): void;
86
+ setupVisibilityManager(): void;
95
87
  resize(): void;
96
88
  /**
97
89
  * 텍스트가 영역 안에 들어가는지 확인하는 헬퍼 함수 (줄바꿈 지원)
@@ -132,13 +124,6 @@ declare class TextToParticle {
132
124
  export { TextToParticle }
133
125
  export default TextToParticle;
134
126
 
135
- /**
136
- * TextToParticle - 텍스트를 파티클로 변환하는 효과
137
- * 바닐라 JS 코어 클래스
138
- *
139
- * 사용법:
140
- * import { TextToParticle } from 'masoneffect/textToParticle';
141
- */
142
127
  declare interface TextToParticleOptions {
143
128
  text?: string;
144
129
  densityStep?: number;
@@ -167,20 +152,21 @@ declare class TextToParticle {
167
152
  onComplete: TypingOptions['onComplete'];
168
153
  };
169
154
  textUnits: string[];
155
+ charUnitRanges: Array<{
156
+ start: number;
157
+ end: number;
158
+ isHangul: boolean;
159
+ }>;
170
160
  currentIndex: number;
171
161
  displayedText: string;
172
162
  timeoutId: ReturnType<typeof setTimeout> | null;
173
- intersectionObserver: IntersectionObserver | null;
163
+ visibilityManager: VisibilityManager | null;
174
164
  isRunning: boolean;
175
165
  hasTriggered: boolean;
176
166
  originalText: string;
177
167
  constructor(container: HTMLElement | string, options: TypingOptions);
178
168
  init(): void;
179
- setupIntersectionObserver(): void;
180
- private originalChars;
181
- private charUnitMap;
182
- private initializeTextStructure;
183
- private getCharIndexFromUnitIndex;
169
+ setupVisibilityManager(): void;
184
170
  private buildTextFromUnits;
185
171
  start(): void;
186
172
  typeNext(): void;
@@ -191,13 +177,6 @@ declare class TextToParticle {
191
177
  destroy(): void;
192
178
  }
193
179
 
194
- /**
195
- * Typing - 타이핑 애니메이션 효과
196
- * 바닐라 JS 코어 클래스
197
- *
198
- * 사용법:
199
- * import { Typing } from 'masoneffect/typing';
200
- */
201
180
  export declare interface TypingOptions {
202
181
  text: string;
203
182
  speed?: number;
@@ -212,4 +191,39 @@ declare class TextToParticle {
212
191
  onComplete?: () => void;
213
192
  }
214
193
 
194
+ declare class VisibilityManager {
195
+ private container;
196
+ private options;
197
+ private intersectionObserver;
198
+ private visibilityChangeHandler;
199
+ private isVisible;
200
+ private isPageVisible;
201
+ constructor(container: HTMLElement, options?: VisibilityManagerOptions);
202
+ private setupIntersectionObserver;
203
+ private setupPageVisibility;
204
+ /**
205
+ * 현재 요소가 화면에 보이는지 확인
206
+ */
207
+ getIsVisible(): boolean;
208
+ /**
209
+ * 옵션 업데이트
210
+ */
211
+ updateOptions(newOptions: Partial<VisibilityManagerOptions>): void;
212
+ /**
213
+ * 리소스 정리
214
+ */
215
+ destroy(): void;
216
+ }
217
+
218
+ /**
219
+ * VisibilityManager - IntersectionObserver와 Page Visibility API를 통합 관리
220
+ * 모든 효과에서 공통으로 사용하는 가시성 관리 유틸리티
221
+ */
222
+ declare interface VisibilityManagerOptions {
223
+ threshold?: number;
224
+ rootMargin?: string;
225
+ onVisible?: () => void;
226
+ onHidden?: () => void;
227
+ }
228
+
215
229
  export { }