masoneffect 2.0.4 → 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.
- package/README.md +2 -2
- package/dist/core/count/index.d.ts +3 -2
- package/dist/core/count/index.d.ts.map +1 -1
- package/dist/core/textToParticle/index.d.ts +3 -3
- package/dist/core/textToParticle/index.d.ts.map +1 -1
- package/dist/core/typing/index.d.ts +3 -2
- package/dist/core/typing/index.d.ts.map +1 -1
- package/dist/core/utils/visibilityManager.d.ts +35 -0
- package/dist/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/count/core/count/index.d.ts +3 -2
- package/dist/count/core/count/index.d.ts.map +1 -1
- package/dist/count/core/textToParticle/index.d.ts +3 -3
- package/dist/count/core/textToParticle/index.d.ts.map +1 -1
- package/dist/count/core/typing/index.d.ts +3 -2
- package/dist/count/core/typing/index.d.ts.map +1 -1
- package/dist/count/core/utils/visibilityManager.d.ts +35 -0
- package/dist/count/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/count/index.cjs +1 -1
- package/dist/count/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/react/core/count/index.d.ts +3 -2
- package/dist/react/core/textToParticle/index.d.ts +3 -3
- package/dist/react/core/typing/index.d.ts +3 -2
- package/dist/react/core/utils/visibilityManager.d.ts +34 -0
- package/dist/react/count/core/count/index.d.ts +3 -2
- package/dist/react/count/core/count/index.d.ts.map +1 -1
- package/dist/react/count/core/textToParticle/index.d.ts +3 -3
- package/dist/react/count/core/textToParticle/index.d.ts.map +1 -1
- package/dist/react/count/core/typing/index.d.ts +3 -2
- package/dist/react/count/core/typing/index.d.ts.map +1 -1
- package/dist/react/count/core/utils/visibilityManager.d.ts +35 -0
- package/dist/react/count/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/react/count/index.cjs +1 -1
- package/dist/react/count/index.mjs +1 -1
- package/dist/react/textToParticle/core/count/index.d.ts +3 -2
- package/dist/react/textToParticle/core/count/index.d.ts.map +1 -1
- package/dist/react/textToParticle/core/textToParticle/index.d.ts +3 -3
- package/dist/react/textToParticle/core/textToParticle/index.d.ts.map +1 -1
- package/dist/react/textToParticle/core/typing/index.d.ts +3 -2
- package/dist/react/textToParticle/core/typing/index.d.ts.map +1 -1
- package/dist/react/textToParticle/core/utils/visibilityManager.d.ts +35 -0
- package/dist/react/textToParticle/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/react/textToParticle/index.cjs +1 -1
- package/dist/react/textToParticle/index.mjs +1 -1
- package/dist/react/typing/core/count/index.d.ts +3 -2
- package/dist/react/typing/core/count/index.d.ts.map +1 -1
- package/dist/react/typing/core/textToParticle/index.d.ts +3 -3
- package/dist/react/typing/core/textToParticle/index.d.ts.map +1 -1
- package/dist/react/typing/core/typing/index.d.ts +3 -2
- package/dist/react/typing/core/typing/index.d.ts.map +1 -1
- package/dist/react/typing/core/utils/visibilityManager.d.ts +35 -0
- package/dist/react/typing/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/react/typing/index.cjs +1 -1
- package/dist/react/typing/index.mjs +1 -1
- package/dist/svelte/count/index.cjs +1 -1
- package/dist/svelte/count/index.d.ts +41 -28
- package/dist/svelte/count/index.mjs +120 -42
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.d.ts +41 -28
- package/dist/svelte/index.mjs +154 -107
- package/dist/svelte/textToParticle/index.cjs +1 -1
- package/dist/svelte/textToParticle/index.d.ts +41 -28
- package/dist/svelte/textToParticle/index.mjs +119 -33
- package/dist/svelte/typing/index.cjs +1 -1
- package/dist/svelte/typing/index.d.ts +41 -28
- package/dist/svelte/typing/index.mjs +117 -32
- package/dist/textToParticle/core/count/index.d.ts +3 -2
- package/dist/textToParticle/core/count/index.d.ts.map +1 -1
- package/dist/textToParticle/core/textToParticle/index.d.ts +3 -3
- package/dist/textToParticle/core/textToParticle/index.d.ts.map +1 -1
- package/dist/textToParticle/core/typing/index.d.ts +3 -2
- package/dist/textToParticle/core/typing/index.d.ts.map +1 -1
- package/dist/textToParticle/core/utils/visibilityManager.d.ts +35 -0
- package/dist/textToParticle/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/textToParticle/index.cjs +1 -1
- package/dist/textToParticle/index.mjs +1 -1
- package/dist/typing/core/count/index.d.ts +3 -2
- package/dist/typing/core/count/index.d.ts.map +1 -1
- package/dist/typing/core/textToParticle/index.d.ts +3 -3
- package/dist/typing/core/textToParticle/index.d.ts.map +1 -1
- package/dist/typing/core/typing/index.d.ts +3 -2
- package/dist/typing/core/typing/index.d.ts.map +1 -1
- package/dist/typing/core/utils/visibilityManager.d.ts +35 -0
- package/dist/typing/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/typing/index.cjs +1 -1
- package/dist/typing/index.mjs +1 -1
- package/dist/vue/count/index.cjs +1 -1
- package/dist/vue/count/index.d.ts +41 -28
- package/dist/vue/count/index.mjs +119 -41
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.d.ts +41 -28
- package/dist/vue/index.mjs +152 -105
- package/dist/vue/textToParticle/index.cjs +1 -1
- package/dist/vue/textToParticle/index.d.ts +41 -28
- package/dist/vue/textToParticle/index.mjs +119 -33
- package/dist/vue/typing/index.cjs +1 -1
- package/dist/vue/typing/index.d.ts +41 -28
- package/dist/vue/typing/index.mjs +116 -31
- package/package.json +1 -1
|
@@ -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.
|
|
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.
|
|
175
|
+
this.setupVisibilityManager();
|
|
76
176
|
if (this.config.onReady) {
|
|
77
177
|
this.config.onReady(this);
|
|
78
178
|
}
|
|
79
179
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
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
|
|
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.
|
|
417
|
-
this.
|
|
418
|
-
this.
|
|
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");
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -175,13 +160,13 @@ declare class TextToParticle {
|
|
|
175
160
|
currentIndex: number;
|
|
176
161
|
displayedText: string;
|
|
177
162
|
timeoutId: ReturnType<typeof setTimeout> | null;
|
|
178
|
-
|
|
163
|
+
visibilityManager: VisibilityManager | null;
|
|
179
164
|
isRunning: boolean;
|
|
180
165
|
hasTriggered: boolean;
|
|
181
166
|
originalText: string;
|
|
182
167
|
constructor(container: HTMLElement | string, options: TypingOptions);
|
|
183
168
|
init(): void;
|
|
184
|
-
|
|
169
|
+
setupVisibilityManager(): void;
|
|
185
170
|
private buildTextFromUnits;
|
|
186
171
|
start(): void;
|
|
187
172
|
typeNext(): void;
|
|
@@ -192,13 +177,6 @@ declare class TextToParticle {
|
|
|
192
177
|
destroy(): void;
|
|
193
178
|
}
|
|
194
179
|
|
|
195
|
-
/**
|
|
196
|
-
* Typing - 타이핑 애니메이션 효과
|
|
197
|
-
* 바닐라 JS 코어 클래스
|
|
198
|
-
*
|
|
199
|
-
* 사용법:
|
|
200
|
-
* import { Typing } from 'masoneffect/typing';
|
|
201
|
-
*/
|
|
202
180
|
export declare interface TypingOptions {
|
|
203
181
|
text: string;
|
|
204
182
|
speed?: number;
|
|
@@ -213,4 +191,39 @@ declare class TextToParticle {
|
|
|
213
191
|
onComplete?: () => void;
|
|
214
192
|
}
|
|
215
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
|
+
|
|
216
229
|
export { }
|
|
@@ -1,4 +1,105 @@
|
|
|
1
1
|
import { defineComponent, ref, onMounted, onUnmounted, watch, 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 decomposeHangul(char) {
|
|
3
104
|
const code = char.charCodeAt(0);
|
|
4
105
|
if (code < 44032 || code > 55203) {
|
|
@@ -85,44 +186,28 @@ class Typing {
|
|
|
85
186
|
this.currentIndex = 0;
|
|
86
187
|
this.displayedText = "";
|
|
87
188
|
this.timeoutId = null;
|
|
88
|
-
this.
|
|
189
|
+
this.visibilityManager = null;
|
|
89
190
|
this.isRunning = false;
|
|
90
191
|
this.hasTriggered = false;
|
|
91
192
|
this.init();
|
|
92
193
|
}
|
|
93
194
|
init() {
|
|
94
195
|
this.updateDisplay("");
|
|
95
|
-
this.
|
|
196
|
+
this.setupVisibilityManager();
|
|
96
197
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
(entries) => {
|
|
106
|
-
var _a;
|
|
107
|
-
for (const entry of entries) {
|
|
108
|
-
if (entry.target !== this.container) continue;
|
|
109
|
-
if (entry.isIntersecting && !this.hasTriggered) {
|
|
110
|
-
if (this.config.enabled) {
|
|
111
|
-
setTimeout(() => this.start(), this.config.delay);
|
|
112
|
-
}
|
|
113
|
-
this.hasTriggered = true;
|
|
114
|
-
if (this.config.triggerOnce) {
|
|
115
|
-
(_a = this.intersectionObserver) == null ? void 0 : _a.disconnect();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
198
|
+
setupVisibilityManager() {
|
|
199
|
+
this.visibilityManager = new VisibilityManager(this.container, {
|
|
200
|
+
threshold: this.config.threshold,
|
|
201
|
+
rootMargin: this.config.rootMargin,
|
|
202
|
+
onVisible: () => {
|
|
203
|
+
if (!this.hasTriggered && this.config.enabled) {
|
|
204
|
+
this.hasTriggered = true;
|
|
205
|
+
setTimeout(() => this.start(), this.config.delay);
|
|
118
206
|
}
|
|
119
207
|
},
|
|
120
|
-
{
|
|
121
|
-
threshold: this.config.threshold,
|
|
122
|
-
rootMargin: this.config.rootMargin
|
|
208
|
+
onHidden: () => {
|
|
123
209
|
}
|
|
124
|
-
);
|
|
125
|
-
this.intersectionObserver.observe(this.container);
|
|
210
|
+
});
|
|
126
211
|
}
|
|
127
212
|
// 단위들을 다시 합쳐서 실제 표시할 텍스트 생성
|
|
128
213
|
// 한글의 경우 자음/모음이 하나씩 보이도록 합성
|
|
@@ -218,9 +303,9 @@ class Typing {
|
|
|
218
303
|
}
|
|
219
304
|
destroy() {
|
|
220
305
|
this.stop();
|
|
221
|
-
if (this.
|
|
222
|
-
this.
|
|
223
|
-
this.
|
|
306
|
+
if (this.visibilityManager) {
|
|
307
|
+
this.visibilityManager.destroy();
|
|
308
|
+
this.visibilityManager = null;
|
|
224
309
|
}
|
|
225
310
|
}
|
|
226
311
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masoneffect",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "A collection of animation effects library. Supports React, Vue, Svelte, and vanilla JavaScript with Tree-shaking support.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|