masoneffect 2.0.8 → 2.0.11
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 +23 -25
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/scrollFadeIn/index.d.ts +4 -11
- package/dist/core/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/core/typing/index.d.ts +2 -0
- package/dist/core/typing/index.d.ts.map +1 -1
- package/dist/core/utils/visibilityManager.d.ts +1 -0
- package/dist/core/utils/visibilityManager.d.ts.map +1 -1
- package/dist/count/core/index.d.ts +0 -1
- package/dist/count/core/index.d.ts.map +1 -1
- package/dist/count/core/scrollFadeIn/index.d.ts +4 -11
- package/dist/count/core/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/count/core/typing/index.d.ts +2 -0
- package/dist/count/core/typing/index.d.ts.map +1 -1
- package/dist/count/core/utils/visibilityManager.d.ts +1 -0
- package/dist/count/core/utils/visibilityManager.d.ts.map +1 -1
- package/dist/count/index.cjs +1 -1
- package/dist/count/index.d.ts +0 -1
- package/dist/count/index.d.ts.map +1 -1
- package/dist/count/index.mjs +1 -1
- package/dist/count/react/index.d.ts +0 -1
- package/dist/count/react/index.d.ts.map +1 -1
- package/dist/count/react/scrollFadeIn/index.d.ts +0 -1
- package/dist/count/react/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/react/core/index.d.ts +0 -1
- package/dist/react/core/scrollFadeIn/index.d.ts +4 -11
- package/dist/react/core/typing/index.d.ts +2 -0
- package/dist/react/core/utils/visibilityManager.d.ts +1 -0
- package/dist/react/count/core/index.d.ts +0 -1
- package/dist/react/count/core/index.d.ts.map +1 -1
- package/dist/react/count/core/scrollFadeIn/index.d.ts +4 -11
- package/dist/react/count/core/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/react/count/core/typing/index.d.ts +2 -0
- package/dist/react/count/core/typing/index.d.ts.map +1 -1
- package/dist/react/count/core/utils/visibilityManager.d.ts +1 -0
- package/dist/react/count/core/utils/visibilityManager.d.ts.map +1 -1
- package/dist/react/count/index.cjs +1 -1
- package/dist/react/count/index.d.ts +0 -1
- package/dist/react/count/index.d.ts.map +1 -1
- package/dist/react/count/index.mjs +1 -1
- package/dist/react/count/react/index.d.ts +0 -1
- package/dist/react/count/react/index.d.ts.map +1 -1
- package/dist/react/count/react/scrollFadeIn/index.d.ts +0 -1
- package/dist/react/count/react/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/react/index.cjs +0 -4
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.mjs +1 -1
- package/dist/react/react/index.d.ts +0 -1
- package/dist/react/react/scrollFadeIn/index.d.ts +0 -1
- package/dist/react/scrollFadeIn/core/index.d.ts +0 -1
- package/dist/react/scrollFadeIn/core/index.d.ts.map +1 -1
- package/dist/react/scrollFadeIn/core/scrollFadeIn/index.d.ts +4 -11
- package/dist/react/scrollFadeIn/core/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/react/scrollFadeIn/core/typing/index.d.ts +2 -0
- package/dist/react/scrollFadeIn/core/typing/index.d.ts.map +1 -1
- package/dist/react/scrollFadeIn/core/utils/visibilityManager.d.ts +1 -0
- package/dist/react/scrollFadeIn/core/utils/visibilityManager.d.ts.map +1 -1
- package/dist/react/scrollFadeIn/index.cjs +1 -1
- package/dist/react/scrollFadeIn/index.d.ts +0 -1
- package/dist/react/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/react/scrollFadeIn/index.mjs +1 -1
- package/dist/react/scrollFadeIn/react/index.d.ts +0 -1
- package/dist/react/scrollFadeIn/react/index.d.ts.map +1 -1
- package/dist/react/scrollFadeIn/react/scrollFadeIn/index.d.ts +0 -1
- package/dist/react/scrollFadeIn/react/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/react/textToParticle/core/index.d.ts +0 -1
- package/dist/react/textToParticle/core/index.d.ts.map +1 -1
- package/dist/react/textToParticle/core/scrollFadeIn/index.d.ts +4 -11
- package/dist/react/textToParticle/core/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/react/textToParticle/core/typing/index.d.ts +2 -0
- package/dist/react/textToParticle/core/typing/index.d.ts.map +1 -1
- package/dist/react/textToParticle/core/utils/visibilityManager.d.ts +1 -0
- package/dist/react/textToParticle/core/utils/visibilityManager.d.ts.map +1 -1
- package/dist/react/textToParticle/index.cjs +1 -1
- package/dist/react/textToParticle/index.d.ts +0 -1
- package/dist/react/textToParticle/index.d.ts.map +1 -1
- package/dist/react/textToParticle/index.mjs +1 -1
- package/dist/react/textToParticle/react/index.d.ts +0 -1
- package/dist/react/textToParticle/react/index.d.ts.map +1 -1
- package/dist/react/textToParticle/react/scrollFadeIn/index.d.ts +0 -1
- package/dist/react/textToParticle/react/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/react/typing/core/index.d.ts +0 -1
- package/dist/react/typing/core/index.d.ts.map +1 -1
- package/dist/react/typing/core/scrollFadeIn/index.d.ts +4 -11
- package/dist/react/typing/core/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/react/typing/core/typing/index.d.ts +2 -0
- package/dist/react/typing/core/typing/index.d.ts.map +1 -1
- package/dist/react/typing/core/utils/visibilityManager.d.ts +1 -0
- package/dist/react/typing/core/utils/visibilityManager.d.ts.map +1 -1
- package/dist/react/typing/index.cjs +1 -1
- package/dist/react/typing/index.d.ts +0 -1
- package/dist/react/typing/index.d.ts.map +1 -1
- package/dist/react/typing/index.mjs +1 -1
- package/dist/react/typing/react/index.d.ts +0 -1
- package/dist/react/typing/react/index.d.ts.map +1 -1
- package/dist/react/typing/react/scrollFadeIn/index.d.ts +0 -1
- package/dist/react/typing/react/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/scrollFadeIn/core/index.d.ts +0 -1
- package/dist/scrollFadeIn/core/index.d.ts.map +1 -1
- package/dist/scrollFadeIn/core/scrollFadeIn/index.d.ts +4 -11
- package/dist/scrollFadeIn/core/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/scrollFadeIn/core/typing/index.d.ts +2 -0
- package/dist/scrollFadeIn/core/typing/index.d.ts.map +1 -1
- package/dist/scrollFadeIn/core/utils/visibilityManager.d.ts +1 -0
- package/dist/scrollFadeIn/core/utils/visibilityManager.d.ts.map +1 -1
- package/dist/scrollFadeIn/index.cjs +1 -1
- package/dist/scrollFadeIn/index.d.ts +0 -1
- package/dist/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/scrollFadeIn/index.mjs +1 -1
- package/dist/scrollFadeIn/react/index.d.ts +0 -1
- package/dist/scrollFadeIn/react/index.d.ts.map +1 -1
- package/dist/scrollFadeIn/react/scrollFadeIn/index.d.ts +0 -1
- package/dist/scrollFadeIn/react/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/svelte/count/index.cjs +1 -1
- package/dist/svelte/count/index.d.ts +8 -6
- package/dist/svelte/count/index.mjs +5 -1
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.d.ts +8 -6
- package/dist/svelte/index.mjs +88 -27
- package/dist/svelte/scrollFadeIn/index.cjs +1 -1
- package/dist/svelte/scrollFadeIn/index.d.ts +8 -6
- package/dist/svelte/scrollFadeIn/index.mjs +35 -24
- package/dist/svelte/textToParticle/index.cjs +1 -1
- package/dist/svelte/textToParticle/index.d.ts +8 -6
- package/dist/svelte/textToParticle/index.mjs +5 -1
- package/dist/svelte/typing/index.cjs +1 -1
- package/dist/svelte/typing/index.d.ts +8 -6
- package/dist/svelte/typing/index.mjs +56 -2
- package/dist/textToParticle/core/index.d.ts +0 -1
- package/dist/textToParticle/core/index.d.ts.map +1 -1
- package/dist/textToParticle/core/scrollFadeIn/index.d.ts +4 -11
- package/dist/textToParticle/core/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/textToParticle/core/typing/index.d.ts +2 -0
- package/dist/textToParticle/core/typing/index.d.ts.map +1 -1
- package/dist/textToParticle/core/utils/visibilityManager.d.ts +1 -0
- package/dist/textToParticle/core/utils/visibilityManager.d.ts.map +1 -1
- package/dist/textToParticle/index.cjs +1 -1
- package/dist/textToParticle/index.d.ts +0 -1
- package/dist/textToParticle/index.d.ts.map +1 -1
- package/dist/textToParticle/index.mjs +1 -1
- package/dist/textToParticle/react/index.d.ts +0 -1
- package/dist/textToParticle/react/index.d.ts.map +1 -1
- package/dist/textToParticle/react/scrollFadeIn/index.d.ts +0 -1
- package/dist/textToParticle/react/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/typing/core/index.d.ts +0 -1
- package/dist/typing/core/index.d.ts.map +1 -1
- package/dist/typing/core/scrollFadeIn/index.d.ts +4 -11
- package/dist/typing/core/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/typing/core/typing/index.d.ts +2 -0
- package/dist/typing/core/typing/index.d.ts.map +1 -1
- package/dist/typing/core/utils/visibilityManager.d.ts +1 -0
- package/dist/typing/core/utils/visibilityManager.d.ts.map +1 -1
- package/dist/typing/index.cjs +1 -1
- package/dist/typing/index.d.ts +0 -1
- package/dist/typing/index.d.ts.map +1 -1
- package/dist/typing/index.mjs +1 -1
- package/dist/typing/react/index.d.ts +0 -1
- package/dist/typing/react/index.d.ts.map +1 -1
- package/dist/typing/react/scrollFadeIn/index.d.ts +0 -1
- package/dist/typing/react/scrollFadeIn/index.d.ts.map +1 -1
- package/dist/vue/count/index.cjs +1 -1
- package/dist/vue/count/index.d.ts +8 -6
- package/dist/vue/count/index.mjs +5 -1
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.d.ts +8 -6
- package/dist/vue/index.mjs +81 -20
- package/dist/vue/scrollFadeIn/index.cjs +1 -1
- package/dist/vue/scrollFadeIn/index.d.ts +8 -6
- package/dist/vue/scrollFadeIn/index.mjs +28 -17
- package/dist/vue/textToParticle/index.cjs +1 -1
- package/dist/vue/textToParticle/index.d.ts +8 -6
- package/dist/vue/textToParticle/index.mjs +5 -1
- package/dist/vue/typing/index.cjs +1 -1
- package/dist/vue/typing/index.d.ts +8 -6
- package/dist/vue/typing/index.mjs +56 -2
- package/package.json +1 -1
|
@@ -5,6 +5,8 @@ class VisibilityManager {
|
|
|
5
5
|
this.options = {
|
|
6
6
|
threshold: options.threshold ?? 0.1,
|
|
7
7
|
rootMargin: options.rootMargin ?? "0px",
|
|
8
|
+
root: options.root ?? null,
|
|
9
|
+
// 기본값은 null (viewport 기준)
|
|
8
10
|
onVisible: options.onVisible,
|
|
9
11
|
onHidden: options.onHidden
|
|
10
12
|
};
|
|
@@ -42,7 +44,9 @@ class VisibilityManager {
|
|
|
42
44
|
},
|
|
43
45
|
{
|
|
44
46
|
threshold: this.options.threshold,
|
|
45
|
-
rootMargin: this.options.rootMargin
|
|
47
|
+
rootMargin: this.options.rootMargin,
|
|
48
|
+
root: this.options.root || null
|
|
49
|
+
// null이면 viewport 기준, HTMLElement면 해당 요소 기준
|
|
46
50
|
}
|
|
47
51
|
);
|
|
48
52
|
this.intersectionObserver.observe(this.container);
|
|
@@ -100,9 +104,7 @@ class VisibilityManager {
|
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
|
-
const
|
|
104
|
-
easeOutCubic: (t) => --t * t * t + 1
|
|
105
|
-
};
|
|
107
|
+
const defaultEasing = (t) => --t * t * t + 1;
|
|
106
108
|
class ScrollFadeIn {
|
|
107
109
|
// 계산된 거리 (px)
|
|
108
110
|
constructor(container, options = {}) {
|
|
@@ -114,14 +116,16 @@ class ScrollFadeIn {
|
|
|
114
116
|
direction: options.direction ?? "bottom",
|
|
115
117
|
distance: options.distance ?? "50px",
|
|
116
118
|
duration: options.duration ?? 800,
|
|
117
|
-
easing: options.easing ?? easingFunctions.easeOutCubic,
|
|
118
119
|
threshold: options.threshold ?? 0.1,
|
|
119
120
|
rootMargin: options.rootMargin ?? "0px",
|
|
121
|
+
root: options.root ?? null,
|
|
122
|
+
// 기본값은 null (viewport 기준)
|
|
120
123
|
triggerOnce: options.triggerOnce ?? false,
|
|
121
124
|
enabled: options.enabled ?? true,
|
|
122
125
|
onStart: options.onStart || null,
|
|
123
126
|
onComplete: options.onComplete || null
|
|
124
127
|
};
|
|
128
|
+
this.easing = defaultEasing;
|
|
125
129
|
this.visibilityManager = null;
|
|
126
130
|
this.animationFrameId = null;
|
|
127
131
|
this.startTime = null;
|
|
@@ -197,15 +201,23 @@ class ScrollFadeIn {
|
|
|
197
201
|
this.visibilityManager = new VisibilityManager(this.container, {
|
|
198
202
|
threshold: this.config.threshold,
|
|
199
203
|
rootMargin: this.config.rootMargin,
|
|
204
|
+
root: this.config.root,
|
|
205
|
+
// 내부 스크롤 컨테이너 지원
|
|
200
206
|
onVisible: () => {
|
|
201
|
-
if (
|
|
202
|
-
this.hasTriggered
|
|
203
|
-
|
|
207
|
+
if (this.config.enabled) {
|
|
208
|
+
if (!this.config.triggerOnce || !this.hasTriggered) {
|
|
209
|
+
this.hasTriggered = true;
|
|
210
|
+
this.start();
|
|
211
|
+
}
|
|
204
212
|
}
|
|
205
213
|
},
|
|
206
214
|
onHidden: () => {
|
|
207
|
-
if (
|
|
208
|
-
this.
|
|
215
|
+
if (this.config.enabled) {
|
|
216
|
+
this.stop();
|
|
217
|
+
if (!this.config.triggerOnce) {
|
|
218
|
+
this.hasTriggered = false;
|
|
219
|
+
}
|
|
220
|
+
this.setInitialPosition();
|
|
209
221
|
}
|
|
210
222
|
}
|
|
211
223
|
});
|
|
@@ -225,7 +237,7 @@ class ScrollFadeIn {
|
|
|
225
237
|
const currentTime = performance.now();
|
|
226
238
|
const elapsed = currentTime - (this.startTime || 0);
|
|
227
239
|
const progress = Math.min(elapsed / this.config.duration, 1);
|
|
228
|
-
const easedProgress = this.
|
|
240
|
+
const easedProgress = this.easing(progress);
|
|
229
241
|
const direction = this.config.direction;
|
|
230
242
|
let translateX = 0;
|
|
231
243
|
let translateY = 0;
|
|
@@ -292,7 +304,6 @@ class ScrollFadeIn {
|
|
|
292
304
|
this.config = {
|
|
293
305
|
...this.config,
|
|
294
306
|
...newConfig,
|
|
295
|
-
easing: newConfig.easing ?? this.config.easing,
|
|
296
307
|
onStart: newConfig.onStart ?? this.config.onStart,
|
|
297
308
|
onComplete: newConfig.onComplete ?? this.config.onComplete
|
|
298
309
|
};
|
|
@@ -300,7 +311,7 @@ class ScrollFadeIn {
|
|
|
300
311
|
this.targetDistance = this.parseDistance(this.config.distance);
|
|
301
312
|
}
|
|
302
313
|
this.setInitialPosition();
|
|
303
|
-
if (newConfig.threshold !== void 0 || newConfig.rootMargin !== void 0) {
|
|
314
|
+
if (newConfig.threshold !== void 0 || newConfig.rootMargin !== void 0 || newConfig.root !== void 0) {
|
|
304
315
|
if (this.visibilityManager) {
|
|
305
316
|
this.visibilityManager.destroy();
|
|
306
317
|
this.visibilityManager = null;
|
|
@@ -331,9 +342,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
331
342
|
direction: { default: "bottom" },
|
|
332
343
|
distance: { default: "50px" },
|
|
333
344
|
duration: { default: 800 },
|
|
334
|
-
easing: { type: Function, default: () => (t) => t },
|
|
335
345
|
threshold: { default: 0.1 },
|
|
336
346
|
rootMargin: { default: "0px" },
|
|
347
|
+
root: { default: null },
|
|
337
348
|
triggerOnce: { type: Boolean, default: false },
|
|
338
349
|
enabled: { type: Boolean, default: true },
|
|
339
350
|
onStart: { type: Function, default: null },
|
|
@@ -351,9 +362,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
351
362
|
direction: props.direction,
|
|
352
363
|
distance: props.distance,
|
|
353
364
|
duration: props.duration,
|
|
354
|
-
easing: props.easing,
|
|
355
365
|
threshold: props.threshold,
|
|
356
366
|
rootMargin: props.rootMargin,
|
|
367
|
+
root: props.root,
|
|
357
368
|
triggerOnce: props.triggerOnce,
|
|
358
369
|
enabled: props.enabled,
|
|
359
370
|
onStart: () => {
|
|
@@ -372,9 +383,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
372
383
|
props.direction,
|
|
373
384
|
props.distance,
|
|
374
385
|
props.duration,
|
|
375
|
-
props.easing,
|
|
376
386
|
props.threshold,
|
|
377
387
|
props.rootMargin,
|
|
388
|
+
props.root,
|
|
378
389
|
props.triggerOnce,
|
|
379
390
|
props.enabled
|
|
380
391
|
],
|
|
@@ -384,9 +395,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
384
395
|
direction: props.direction,
|
|
385
396
|
distance: props.distance,
|
|
386
397
|
duration: props.duration,
|
|
387
|
-
easing: props.easing,
|
|
388
398
|
threshold: props.threshold,
|
|
389
399
|
rootMargin: props.rootMargin,
|
|
400
|
+
root: props.root,
|
|
390
401
|
triggerOnce: props.triggerOnce,
|
|
391
402
|
enabled: props.enabled,
|
|
392
403
|
onStart: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const t=require("vue");class i{constructor(t,i={}){this.container=t,this.options={threshold:i.threshold??.1,rootMargin:i.rootMargin??"0px",onVisible:i.onVisible,onHidden:i.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 i of t)i.target===this.container&&(i.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 e(t,i){let e=null;return function(...s){null!==e&&clearTimeout(e),e=setTimeout(()=>{e=null,t.apply(this,s)},i)}}class s{constructor(t,i={}){if(this.container="string"==typeof t?document.querySelector(t):t,!this.container)throw new Error("Container element not found");this.config={text:i.text||"mason effect",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");const s=this.canvas.getContext("2d",{willReadFrequently:!0});if(!s)throw new Error("Canvas context not available");this.ctx=s,this.container.appendChild(this.canvas),this.canvas.style.display="block",this.offCanvas=document.createElement("canvas");const n=this.offCanvas.getContext("2d",{willReadFrequently:!0});if(!n)throw new Error("Offscreen canvas context not available");this.offCtx=n,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.visibilityManager=null,this.debounceDelay=i.debounceDelay??150;const o=this.handleResize.bind(this);this.handleResize=e(o,this.debounceDelay),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._debouncedMorph=e(this._morphInternal.bind(this),this.debounceDelay),this._debouncedUpdateConfig=e(this._updateConfigInternal.bind(this),this.debounceDelay),this.init()}init(){this.resize(),this.setupEventListeners(),this.setupVisibilityManager(),this.config.onReady&&this.config.onReady(this)}setupVisibilityManager(){this.visibilityManager=new i(this.container,{threshold:.1,onVisible:()=>{this.start()},onHidden:()=>{this.stop()}})}resize(){const t=this.container.getBoundingClientRect(),i=this.config.width||t.width||this.container.clientWidth||window.innerWidth,e=this.config.height||t.height||this.container.clientHeight||.7*window.innerHeight;if(i<=0||e<=0)return;this.W=Math.floor(i*this.DPR),this.H=Math.floor(e*this.DPR);const s=4096;if(this.W>s||this.H>s){const t=Math.min(s/this.W,s/this.H);this.W=Math.floor(this.W*t),this.H=Math.floor(this.H*t),this.DPR=this.DPR*t}this.canvas.width=this.W,this.canvas.height=this.H,this.canvas.style.width=i+"px",this.canvas.style.height=e+"px",this.W>0&&this.H>0&&(this.buildTargets(),this.particles.length||this.initParticles())}measureTextFit(t,i,e,s){this.offCtx.font=`400 ${t}px ${this.config.fontFamily}`;const n=i.split("\n"),o=t,h=.1*t,a=.05*t;let l=0;for(const d of n){if(0===d.length)continue;const t=this.offCtx.measureText(d).width+a*(d.length>0?d.length-1:0);l=Math.max(l,t)}const r=n.length>0?o*n.length+h*(n.length-1):o;return{width:l,height:r,fits:l<=e&&r<=s}}findOptimalFontSize(t,i,e,s){if(this.measureTextFit(s,t,i,e).fits)return s;if(s<=12)return 12;let n=12,o=s,h=12;for(;n<=o;){const s=Math.floor((n+o)/2);this.measureTextFit(s,t,i,e).fits?(h=s,n=s+1):o=s-1}return h}buildTargets(){if(this.W<=0||this.H<=0)return;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),e=this.config.fontSize||Math.max(80,Math.floor(.18*i)),s=this.W-80,n=this.H-80,o=this.findOptimalFontSize(t,s,n,e);this.offCtx.fillStyle="#ffffff",this.offCtx.textAlign="center",this.offCtx.textBaseline="middle",this.offCtx.font=`400 ${o}px ${this.config.fontFamily}`;const h=t.split("\n"),a=o,l=.1*o,r=.05*o,d=h.length>0?a*h.length+l*(h.length-1):a;let c=this.H/2-d/2+a/2;for(const g of h){if(0===g.length){c+=a+l;continue}const t=g.split(""),i=this.offCtx.measureText(g).width+r*(t.length>0?t.length-1:0);let e=this.W/2-i/2;for(const s of t)this.offCtx.fillText(s,e+this.offCtx.measureText(s).width/2,c),e+=this.offCtx.measureText(s).width+r;c+=a+l}const u=Math.max(2,this.config.densityStep),f=this.offCtx.getImageData(0,0,this.W,this.H).data,p=[];for(let g=0;g<this.H;g+=u)for(let t=0;t<this.W;t+=u){const i=4*(g*this.W+t);f[i]+f[i+1]+f[i+2]>600&&p.push({x:t,y:g})}for(;p.length>this.config.maxParticles;)p.splice(Math.floor(Math.random()*p.length),1);if(this.particles.length<p.length){const t=p.length-this.particles.length;for(let i=0;i<t;i++)this.particles.push(this.makeParticle())}else this.particles.length>p.length&&(this.particles.length=p.length);for(let g=0;g<this.particles.length;g++){const t=this.particles[g],i=p[g];t.tx=i.x,t.ty=i.y}}makeParticle(){const t=Math.random()*this.W,i=Math.random()*this.H;return{x:t,y:i,vx:0,vy:0,tx:t,ty:i,initialX:t,initialY:i,j:Math.random()*Math.PI*2}}initParticles(){for(const t of this.particles){const i=Math.random()*this.W,e=Math.random()*this.H;t.x=i,t.y=e,t.vx=t.vy=0,t.initialX=i,t.initialY=e}}scatter(){for(const t of this.particles)void 0!==t.initialX&&void 0!==t.initialY?(t.tx=t.initialX,t.ty=t.initialY):(t.initialX=t.x,t.initialY=t.y,t.tx=t.initialX,t.ty=t.initialY)}morph(t){this._debouncedMorph(t)}_morphInternal(t){if(0!==this.W&&0!==this.H||this.resize(),"string"==typeof t)this.config.text=t,this.buildTargets();else if(t&&"object"==typeof t){const i=void 0!==t.text;this.config={...this.config,...t},i&&this.buildTargets()}else this.buildTargets()}update(){this.ctx.clearRect(0,0,this.W,this.H);for(const s of this.particles){let t=(s.tx-s.x)*this.config.ease,i=(s.ty-s.y)*this.config.ease;if(this.mouse.x||this.mouse.y){const e=s.x-this.mouse.x,n=s.y-this.mouse.y,o=e*e+n*n,h=this.config.repelRadius*this.DPR;if(o<h*h){const s=Math.sqrt(o)+1e-4,a=(this.mouse.down?-1:1)*this.config.repelStrength*(1-s/h);t+=e/s*a*6,i+=n/s*a*6}}s.j+=2,t+=.05*Math.cos(s.j),i+=.05*Math.sin(1.3*s.j),s.vx=(s.vx+t)*Math.random(),s.vy=(s.vy+i)*Math.random(),s.x+=s.vx,s.y+=s.vy}this.ctx.fillStyle=this.config.particleColor;const t=Math.min(this.W,this.H)/this.DPR,i=Math.max(.5,Math.min(2,t/1920)),e=this.config.pointSize*this.DPR*i;for(const s of this.particles)this.ctx.beginPath(),this.ctx.arc(s.x,s.y,e,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._debouncedUpdateConfig(t)}_updateConfigInternal(t){this.config={...this.config,...t},t.text&&this.buildTargets()}destroy(){this.stop(),this.removeEventListeners(),this.visibilityManager&&(this.visibilityManager.destroy(),this.visibilityManager=null),this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas)}}const n=t.defineComponent({__name:"TextToParticle",props:{className:{default:""},style:{default:()=>({})},text:{default:"mason effect"},densityStep:{default:2},maxParticles:{default:3200},pointSize:{default:.5},ease:{default:.05},repelRadius:{default:150},repelStrength:{default:1},particleColor:{default:"#fff"},fontFamily:{default:"Inter, system-ui, Arial"},fontSize:{default:null},width:{default:null},height:{default:null},devicePixelRatio:{default:null},debounceDelay:{},onReady:{type:Function,default:null},onUpdate:{type:Function,default:null}},emits:["ready","update"],setup(i,{expose:e,emit:n}){const o=i,h=n,a=t.ref(null);let l=null;return t.watch(()=>[o.text,o.densityStep,o.maxParticles,o.pointSize,o.ease,o.repelRadius,o.repelStrength,o.particleColor,o.fontFamily,o.fontSize,o.width,o.height,o.devicePixelRatio],()=>{l&&l.updateConfig({text:o.text,densityStep:o.densityStep,maxParticles:o.maxParticles,pointSize:o.pointSize,ease:o.ease,repelRadius:o.repelRadius,repelStrength:o.repelStrength,particleColor:o.particleColor,fontFamily:o.fontFamily,fontSize:o.fontSize,width:o.width,height:o.height,devicePixelRatio:o.devicePixelRatio})}),t.onMounted(()=>{(()=>{if(!a.value)return;const t={text:o.text,densityStep:o.densityStep,maxParticles:o.maxParticles,pointSize:o.pointSize,ease:o.ease,repelRadius:o.repelRadius,repelStrength:o.repelStrength,particleColor:o.particleColor,fontFamily:o.fontFamily,fontSize:o.fontSize,width:o.width,height:o.height,devicePixelRatio:o.devicePixelRatio,onReady:t=>{o.onReady&&o.onReady(t),h("ready",t)},onUpdate:t=>{o.onUpdate&&o.onUpdate(t),h("update",t)}};l=new s(a.value,t)})()}),t.onBeforeUnmount(()=>{l&&(l.destroy(),l=null)}),e({morph:t=>{l&&l.morph(t)},scatter:()=>{l&&l.scatter()},updateConfig:t=>{l&&l.updateConfig(t)},destroy:()=>{l&&(l.destroy(),l=null)}}),(e,s)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"container",ref:a,class:t.normalizeClass(i.className),style:t.normalizeStyle(i.style)},null,6))}});module.exports=n;
|
|
1
|
+
"use strict";const t=require("vue");class i{constructor(t,i={}){this.container=t,this.options={threshold:i.threshold??.1,rootMargin:i.rootMargin??"0px",root:i.root??null,onVisible:i.onVisible,onHidden:i.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 i of t)i.target===this.container&&(i.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,root:this.options.root||null}),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 e(t,i){let e=null;return function(...s){null!==e&&clearTimeout(e),e=setTimeout(()=>{e=null,t.apply(this,s)},i)}}class s{constructor(t,i={}){if(this.container="string"==typeof t?document.querySelector(t):t,!this.container)throw new Error("Container element not found");this.config={text:i.text||"mason effect",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");const s=this.canvas.getContext("2d",{willReadFrequently:!0});if(!s)throw new Error("Canvas context not available");this.ctx=s,this.container.appendChild(this.canvas),this.canvas.style.display="block",this.offCanvas=document.createElement("canvas");const n=this.offCanvas.getContext("2d",{willReadFrequently:!0});if(!n)throw new Error("Offscreen canvas context not available");this.offCtx=n,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.visibilityManager=null,this.debounceDelay=i.debounceDelay??150;const o=this.handleResize.bind(this);this.handleResize=e(o,this.debounceDelay),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._debouncedMorph=e(this._morphInternal.bind(this),this.debounceDelay),this._debouncedUpdateConfig=e(this._updateConfigInternal.bind(this),this.debounceDelay),this.init()}init(){this.resize(),this.setupEventListeners(),this.setupVisibilityManager(),this.config.onReady&&this.config.onReady(this)}setupVisibilityManager(){this.visibilityManager=new i(this.container,{threshold:.1,onVisible:()=>{this.start()},onHidden:()=>{this.stop()}})}resize(){const t=this.container.getBoundingClientRect(),i=this.config.width||t.width||this.container.clientWidth||window.innerWidth,e=this.config.height||t.height||this.container.clientHeight||.7*window.innerHeight;if(i<=0||e<=0)return;this.W=Math.floor(i*this.DPR),this.H=Math.floor(e*this.DPR);const s=4096;if(this.W>s||this.H>s){const t=Math.min(s/this.W,s/this.H);this.W=Math.floor(this.W*t),this.H=Math.floor(this.H*t),this.DPR=this.DPR*t}this.canvas.width=this.W,this.canvas.height=this.H,this.canvas.style.width=i+"px",this.canvas.style.height=e+"px",this.W>0&&this.H>0&&(this.buildTargets(),this.particles.length||this.initParticles())}measureTextFit(t,i,e,s){this.offCtx.font=`400 ${t}px ${this.config.fontFamily}`;const n=i.split("\n"),o=t,h=.1*t,a=.05*t;let l=0;for(const d of n){if(0===d.length)continue;const t=this.offCtx.measureText(d).width+a*(d.length>0?d.length-1:0);l=Math.max(l,t)}const r=n.length>0?o*n.length+h*(n.length-1):o;return{width:l,height:r,fits:l<=e&&r<=s}}findOptimalFontSize(t,i,e,s){if(this.measureTextFit(s,t,i,e).fits)return s;if(s<=12)return 12;let n=12,o=s,h=12;for(;n<=o;){const s=Math.floor((n+o)/2);this.measureTextFit(s,t,i,e).fits?(h=s,n=s+1):o=s-1}return h}buildTargets(){if(this.W<=0||this.H<=0)return;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),e=this.config.fontSize||Math.max(80,Math.floor(.18*i)),s=this.W-80,n=this.H-80,o=this.findOptimalFontSize(t,s,n,e);this.offCtx.fillStyle="#ffffff",this.offCtx.textAlign="center",this.offCtx.textBaseline="middle",this.offCtx.font=`400 ${o}px ${this.config.fontFamily}`;const h=t.split("\n"),a=o,l=.1*o,r=.05*o,d=h.length>0?a*h.length+l*(h.length-1):a;let c=this.H/2-d/2+a/2;for(const g of h){if(0===g.length){c+=a+l;continue}const t=g.split(""),i=this.offCtx.measureText(g).width+r*(t.length>0?t.length-1:0);let e=this.W/2-i/2;for(const s of t)this.offCtx.fillText(s,e+this.offCtx.measureText(s).width/2,c),e+=this.offCtx.measureText(s).width+r;c+=a+l}const u=Math.max(2,this.config.densityStep),f=this.offCtx.getImageData(0,0,this.W,this.H).data,p=[];for(let g=0;g<this.H;g+=u)for(let t=0;t<this.W;t+=u){const i=4*(g*this.W+t);f[i]+f[i+1]+f[i+2]>600&&p.push({x:t,y:g})}for(;p.length>this.config.maxParticles;)p.splice(Math.floor(Math.random()*p.length),1);if(this.particles.length<p.length){const t=p.length-this.particles.length;for(let i=0;i<t;i++)this.particles.push(this.makeParticle())}else this.particles.length>p.length&&(this.particles.length=p.length);for(let g=0;g<this.particles.length;g++){const t=this.particles[g],i=p[g];t.tx=i.x,t.ty=i.y}}makeParticle(){const t=Math.random()*this.W,i=Math.random()*this.H;return{x:t,y:i,vx:0,vy:0,tx:t,ty:i,initialX:t,initialY:i,j:Math.random()*Math.PI*2}}initParticles(){for(const t of this.particles){const i=Math.random()*this.W,e=Math.random()*this.H;t.x=i,t.y=e,t.vx=t.vy=0,t.initialX=i,t.initialY=e}}scatter(){for(const t of this.particles)void 0!==t.initialX&&void 0!==t.initialY?(t.tx=t.initialX,t.ty=t.initialY):(t.initialX=t.x,t.initialY=t.y,t.tx=t.initialX,t.ty=t.initialY)}morph(t){this._debouncedMorph(t)}_morphInternal(t){if(0!==this.W&&0!==this.H||this.resize(),"string"==typeof t)this.config.text=t,this.buildTargets();else if(t&&"object"==typeof t){const i=void 0!==t.text;this.config={...this.config,...t},i&&this.buildTargets()}else this.buildTargets()}update(){this.ctx.clearRect(0,0,this.W,this.H);for(const s of this.particles){let t=(s.tx-s.x)*this.config.ease,i=(s.ty-s.y)*this.config.ease;if(this.mouse.x||this.mouse.y){const e=s.x-this.mouse.x,n=s.y-this.mouse.y,o=e*e+n*n,h=this.config.repelRadius*this.DPR;if(o<h*h){const s=Math.sqrt(o)+1e-4,a=(this.mouse.down?-1:1)*this.config.repelStrength*(1-s/h);t+=e/s*a*6,i+=n/s*a*6}}s.j+=2,t+=.05*Math.cos(s.j),i+=.05*Math.sin(1.3*s.j),s.vx=(s.vx+t)*Math.random(),s.vy=(s.vy+i)*Math.random(),s.x+=s.vx,s.y+=s.vy}this.ctx.fillStyle=this.config.particleColor;const t=Math.min(this.W,this.H)/this.DPR,i=Math.max(.5,Math.min(2,t/1920)),e=this.config.pointSize*this.DPR*i;for(const s of this.particles)this.ctx.beginPath(),this.ctx.arc(s.x,s.y,e,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._debouncedUpdateConfig(t)}_updateConfigInternal(t){this.config={...this.config,...t},t.text&&this.buildTargets()}destroy(){this.stop(),this.removeEventListeners(),this.visibilityManager&&(this.visibilityManager.destroy(),this.visibilityManager=null),this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas)}}const n=t.defineComponent({__name:"TextToParticle",props:{className:{default:""},style:{default:()=>({})},text:{default:"mason effect"},densityStep:{default:2},maxParticles:{default:3200},pointSize:{default:.5},ease:{default:.05},repelRadius:{default:150},repelStrength:{default:1},particleColor:{default:"#fff"},fontFamily:{default:"Inter, system-ui, Arial"},fontSize:{default:null},width:{default:null},height:{default:null},devicePixelRatio:{default:null},debounceDelay:{},onReady:{type:Function,default:null},onUpdate:{type:Function,default:null}},emits:["ready","update"],setup(i,{expose:e,emit:n}){const o=i,h=n,a=t.ref(null);let l=null;return t.watch(()=>[o.text,o.densityStep,o.maxParticles,o.pointSize,o.ease,o.repelRadius,o.repelStrength,o.particleColor,o.fontFamily,o.fontSize,o.width,o.height,o.devicePixelRatio],()=>{l&&l.updateConfig({text:o.text,densityStep:o.densityStep,maxParticles:o.maxParticles,pointSize:o.pointSize,ease:o.ease,repelRadius:o.repelRadius,repelStrength:o.repelStrength,particleColor:o.particleColor,fontFamily:o.fontFamily,fontSize:o.fontSize,width:o.width,height:o.height,devicePixelRatio:o.devicePixelRatio})}),t.onMounted(()=>{(()=>{if(!a.value)return;const t={text:o.text,densityStep:o.densityStep,maxParticles:o.maxParticles,pointSize:o.pointSize,ease:o.ease,repelRadius:o.repelRadius,repelStrength:o.repelStrength,particleColor:o.particleColor,fontFamily:o.fontFamily,fontSize:o.fontSize,width:o.width,height:o.height,devicePixelRatio:o.devicePixelRatio,onReady:t=>{o.onReady&&o.onReady(t),h("ready",t)},onUpdate:t=>{o.onUpdate&&o.onUpdate(t),h("update",t)}};l=new s(a.value,t)})()}),t.onBeforeUnmount(()=>{l&&(l.destroy(),l=null)}),e({morph:t=>{l&&l.morph(t)},scatter:()=>{l&&l.scatter()},updateConfig:t=>{l&&l.updateConfig(t)},destroy:()=>{l&&(l.destroy(),l=null)}}),(e,s)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"container",ref:a,class:t.normalizeClass(i.className),style:t.normalizeStyle(i.style)},null,6))}});module.exports=n;
|
|
@@ -36,15 +36,13 @@ export declare interface CountOptions {
|
|
|
36
36
|
onComplete?: () => void;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
declare const easingFunctions: {
|
|
39
|
+
export declare const easingFunctions: {
|
|
40
40
|
linear: (t: number) => number;
|
|
41
41
|
easeInQuad: (t: number) => number;
|
|
42
42
|
easeOutQuad: (t: number) => number;
|
|
43
43
|
easeInOutQuad: (t: number) => number;
|
|
44
44
|
easeOutCubic: (t: number) => number;
|
|
45
45
|
};
|
|
46
|
-
export { easingFunctions }
|
|
47
|
-
export { easingFunctions as scrollFadeInEasingFunctions }
|
|
48
46
|
|
|
49
47
|
export declare interface Particle {
|
|
50
48
|
x: number;
|
|
@@ -60,11 +58,12 @@ export declare interface Particle {
|
|
|
60
58
|
|
|
61
59
|
export declare class ScrollFadeIn {
|
|
62
60
|
container: HTMLElement;
|
|
63
|
-
config: Required<Omit<ScrollFadeInOptions, 'onStart' | 'onComplete' | '
|
|
64
|
-
|
|
61
|
+
config: Required<Omit<ScrollFadeInOptions, 'onStart' | 'onComplete' | 'root'>> & {
|
|
62
|
+
root: HTMLElement | null;
|
|
65
63
|
onStart: ScrollFadeInOptions['onStart'];
|
|
66
64
|
onComplete: ScrollFadeInOptions['onComplete'];
|
|
67
65
|
};
|
|
66
|
+
private easing;
|
|
68
67
|
visibilityManager: VisibilityManager | null;
|
|
69
68
|
animationFrameId: number | null;
|
|
70
69
|
startTime: number | null;
|
|
@@ -90,9 +89,9 @@ export declare interface ScrollFadeInOptions {
|
|
|
90
89
|
direction?: 'top' | 'right' | 'bottom' | 'left';
|
|
91
90
|
distance?: string;
|
|
92
91
|
duration?: number;
|
|
93
|
-
easing?: (t: number) => number;
|
|
94
92
|
threshold?: number;
|
|
95
93
|
rootMargin?: string;
|
|
94
|
+
root?: HTMLElement | null;
|
|
96
95
|
triggerOnce?: boolean;
|
|
97
96
|
enabled?: boolean;
|
|
98
97
|
onStart?: () => void;
|
|
@@ -209,6 +208,7 @@ declare class TextToParticle {
|
|
|
209
208
|
originalText: string;
|
|
210
209
|
constructor(container: HTMLElement | string, options: TypingOptions);
|
|
211
210
|
init(): void;
|
|
211
|
+
private injectStyles;
|
|
212
212
|
setupVisibilityManager(): void;
|
|
213
213
|
private buildTextFromUnits;
|
|
214
214
|
start(): void;
|
|
@@ -216,6 +216,7 @@ declare class TextToParticle {
|
|
|
216
216
|
stop(): void;
|
|
217
217
|
reset(): void;
|
|
218
218
|
updateDisplay(text: string): void;
|
|
219
|
+
private escapeHtml;
|
|
219
220
|
setText(newText: string): void;
|
|
220
221
|
destroy(): void;
|
|
221
222
|
}
|
|
@@ -265,6 +266,7 @@ declare class TextToParticle {
|
|
|
265
266
|
declare interface VisibilityManagerOptions {
|
|
266
267
|
threshold?: number;
|
|
267
268
|
rootMargin?: string;
|
|
269
|
+
root?: HTMLElement | null;
|
|
268
270
|
onVisible?: () => void;
|
|
269
271
|
onHidden?: () => void;
|
|
270
272
|
}
|
|
@@ -5,6 +5,8 @@ class VisibilityManager {
|
|
|
5
5
|
this.options = {
|
|
6
6
|
threshold: options.threshold ?? 0.1,
|
|
7
7
|
rootMargin: options.rootMargin ?? "0px",
|
|
8
|
+
root: options.root ?? null,
|
|
9
|
+
// 기본값은 null (viewport 기준)
|
|
8
10
|
onVisible: options.onVisible,
|
|
9
11
|
onHidden: options.onHidden
|
|
10
12
|
};
|
|
@@ -42,7 +44,9 @@ class VisibilityManager {
|
|
|
42
44
|
},
|
|
43
45
|
{
|
|
44
46
|
threshold: this.options.threshold,
|
|
45
|
-
rootMargin: this.options.rootMargin
|
|
47
|
+
rootMargin: this.options.rootMargin,
|
|
48
|
+
root: this.options.root || null
|
|
49
|
+
// null이면 viewport 기준, HTMLElement면 해당 요소 기준
|
|
46
50
|
}
|
|
47
51
|
);
|
|
48
52
|
this.intersectionObserver.observe(this.container);
|
|
@@ -1 +1 @@
|
|
|
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=["","ㄱ","ㄲ","ㄳ","ㄴ","ㄵ","ㄶ","ㄷ","ㄹ","ㄺ","ㄻ","ㄼ","ㄽ","ㄾ","ㄿ","ㅀ","ㅁ","ㅂ","ㅄ","ㅅ","ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"],
|
|
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",root:e.root??null,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,root:this.options.root||null}),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=["","ㄱ","ㄲ","ㄳ","ㄴ","ㄵ","ㄶ","ㄷ","ㄹ","ㄺ","ㄻ","ㄼ","ㄽ","ㄾ","ㄿ","ㅀ","ㅁ","ㅂ","ㅄ","ㅅ","ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"],l=[];return l.push(["ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"][s]),l.push(["ㅏ","ㅐ","ㅑ","ㅒ","ㅓ","ㅔ","ㅕ","ㅖ","ㅗ","ㅘ","ㅙ","ㅚ","ㅛ","ㅜ","ㅝ","ㅞ","ㅟ","ㅠ","ㅡ","ㅢ","ㅣ"][n]),o>0&&l.push(r[o]),l}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),l=e.length;if(r>=44032&&r<=55203){const t=i(o);e.push(...t),s.push({start:l,end:e.length,isHangul:!0})}else e.push(o),s.push({start:l,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.injectStyles(),this.setupVisibilityManager()}injectStyles(){if(document.getElementById("masoneffect-typing-styles"))return;const t=document.createElement("style");t.id="masoneffect-typing-styles",t.textContent="\n .typing-char {\n transition: opacity 0.2s ease-in;\n display: inline-block;\n }\n .typing-cursor {\n display: inline-block;\n }\n ",document.head.appendChild(t)}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){const e=t.replace(new RegExp(this.escapeHtml(this.config.cursorChar)+"$"),""),i=t.endsWith(this.config.cursorChar),s=(this.container.textContent||"").replace(new RegExp(this.config.cursorChar+"$"),"");let n="";for(let r=0;r<e.length;r++){const t=e[r];n+=r>=s.length?`<span class="typing-char typing-fade-in" style="opacity: 0;">${this.escapeHtml(t)}</span>`:`<span class="typing-char" style="opacity: 1;">${this.escapeHtml(t)}</span>`}i&&(n+=`<span class="typing-cursor">${this.escapeHtml(this.config.cursorChar)}</span>`),this.container.innerHTML=n;const o=this.container.querySelectorAll(".typing-fade-in");o.length>0&&requestAnimationFrame(()=>{o.forEach(t=>{t.style.opacity="1",t.classList.remove("typing-fade-in")})})}escapeHtml(t){const e=document.createElement("div");return e.textContent=t,e.innerHTML}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;
|
|
@@ -36,15 +36,13 @@ export declare interface CountOptions {
|
|
|
36
36
|
onComplete?: () => void;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
declare const easingFunctions: {
|
|
39
|
+
export declare const easingFunctions: {
|
|
40
40
|
linear: (t: number) => number;
|
|
41
41
|
easeInQuad: (t: number) => number;
|
|
42
42
|
easeOutQuad: (t: number) => number;
|
|
43
43
|
easeInOutQuad: (t: number) => number;
|
|
44
44
|
easeOutCubic: (t: number) => number;
|
|
45
45
|
};
|
|
46
|
-
export { easingFunctions }
|
|
47
|
-
export { easingFunctions as scrollFadeInEasingFunctions }
|
|
48
46
|
|
|
49
47
|
export declare interface Particle {
|
|
50
48
|
x: number;
|
|
@@ -60,11 +58,12 @@ export declare interface Particle {
|
|
|
60
58
|
|
|
61
59
|
export declare class ScrollFadeIn {
|
|
62
60
|
container: HTMLElement;
|
|
63
|
-
config: Required<Omit<ScrollFadeInOptions, 'onStart' | 'onComplete' | '
|
|
64
|
-
|
|
61
|
+
config: Required<Omit<ScrollFadeInOptions, 'onStart' | 'onComplete' | 'root'>> & {
|
|
62
|
+
root: HTMLElement | null;
|
|
65
63
|
onStart: ScrollFadeInOptions['onStart'];
|
|
66
64
|
onComplete: ScrollFadeInOptions['onComplete'];
|
|
67
65
|
};
|
|
66
|
+
private easing;
|
|
68
67
|
visibilityManager: VisibilityManager | null;
|
|
69
68
|
animationFrameId: number | null;
|
|
70
69
|
startTime: number | null;
|
|
@@ -90,9 +89,9 @@ export declare interface ScrollFadeInOptions {
|
|
|
90
89
|
direction?: 'top' | 'right' | 'bottom' | 'left';
|
|
91
90
|
distance?: string;
|
|
92
91
|
duration?: number;
|
|
93
|
-
easing?: (t: number) => number;
|
|
94
92
|
threshold?: number;
|
|
95
93
|
rootMargin?: string;
|
|
94
|
+
root?: HTMLElement | null;
|
|
96
95
|
triggerOnce?: boolean;
|
|
97
96
|
enabled?: boolean;
|
|
98
97
|
onStart?: () => void;
|
|
@@ -209,6 +208,7 @@ declare class TextToParticle {
|
|
|
209
208
|
originalText: string;
|
|
210
209
|
constructor(container: HTMLElement | string, options: TypingOptions);
|
|
211
210
|
init(): void;
|
|
211
|
+
private injectStyles;
|
|
212
212
|
setupVisibilityManager(): void;
|
|
213
213
|
private buildTextFromUnits;
|
|
214
214
|
start(): void;
|
|
@@ -216,6 +216,7 @@ declare class TextToParticle {
|
|
|
216
216
|
stop(): void;
|
|
217
217
|
reset(): void;
|
|
218
218
|
updateDisplay(text: string): void;
|
|
219
|
+
private escapeHtml;
|
|
219
220
|
setText(newText: string): void;
|
|
220
221
|
destroy(): void;
|
|
221
222
|
}
|
|
@@ -265,6 +266,7 @@ declare class TextToParticle {
|
|
|
265
266
|
declare interface VisibilityManagerOptions {
|
|
266
267
|
threshold?: number;
|
|
267
268
|
rootMargin?: string;
|
|
269
|
+
root?: HTMLElement | null;
|
|
268
270
|
onVisible?: () => void;
|
|
269
271
|
onHidden?: () => void;
|
|
270
272
|
}
|
|
@@ -5,6 +5,8 @@ class VisibilityManager {
|
|
|
5
5
|
this.options = {
|
|
6
6
|
threshold: options.threshold ?? 0.1,
|
|
7
7
|
rootMargin: options.rootMargin ?? "0px",
|
|
8
|
+
root: options.root ?? null,
|
|
9
|
+
// 기본값은 null (viewport 기준)
|
|
8
10
|
onVisible: options.onVisible,
|
|
9
11
|
onHidden: options.onHidden
|
|
10
12
|
};
|
|
@@ -42,7 +44,9 @@ class VisibilityManager {
|
|
|
42
44
|
},
|
|
43
45
|
{
|
|
44
46
|
threshold: this.options.threshold,
|
|
45
|
-
rootMargin: this.options.rootMargin
|
|
47
|
+
rootMargin: this.options.rootMargin,
|
|
48
|
+
root: this.options.root || null
|
|
49
|
+
// null이면 viewport 기준, HTMLElement면 해당 요소 기준
|
|
46
50
|
}
|
|
47
51
|
);
|
|
48
52
|
this.intersectionObserver.observe(this.container);
|
|
@@ -193,8 +197,26 @@ class Typing {
|
|
|
193
197
|
}
|
|
194
198
|
init() {
|
|
195
199
|
this.updateDisplay("");
|
|
200
|
+
this.injectStyles();
|
|
196
201
|
this.setupVisibilityManager();
|
|
197
202
|
}
|
|
203
|
+
injectStyles() {
|
|
204
|
+
if (document.getElementById("masoneffect-typing-styles")) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const style = document.createElement("style");
|
|
208
|
+
style.id = "masoneffect-typing-styles";
|
|
209
|
+
style.textContent = `
|
|
210
|
+
.typing-char {
|
|
211
|
+
transition: opacity 0.2s ease-in;
|
|
212
|
+
display: inline-block;
|
|
213
|
+
}
|
|
214
|
+
.typing-cursor {
|
|
215
|
+
display: inline-block;
|
|
216
|
+
}
|
|
217
|
+
`;
|
|
218
|
+
document.head.appendChild(style);
|
|
219
|
+
}
|
|
198
220
|
setupVisibilityManager() {
|
|
199
221
|
this.visibilityManager = new VisibilityManager(this.container, {
|
|
200
222
|
threshold: this.config.threshold,
|
|
@@ -287,7 +309,39 @@ class Typing {
|
|
|
287
309
|
this.updateDisplay("");
|
|
288
310
|
}
|
|
289
311
|
updateDisplay(text) {
|
|
290
|
-
this.
|
|
312
|
+
const textWithoutCursor = text.replace(new RegExp(this.escapeHtml(this.config.cursorChar) + "$"), "");
|
|
313
|
+
const hasCursor = text.endsWith(this.config.cursorChar);
|
|
314
|
+
const previousTextContent = this.container.textContent || "";
|
|
315
|
+
const previousTextWithoutCursor = previousTextContent.replace(new RegExp(this.config.cursorChar + "$"), "");
|
|
316
|
+
let html = "";
|
|
317
|
+
for (let i = 0; i < textWithoutCursor.length; i++) {
|
|
318
|
+
const char = textWithoutCursor[i];
|
|
319
|
+
const isNewChar = i >= previousTextWithoutCursor.length;
|
|
320
|
+
if (isNewChar) {
|
|
321
|
+
html += `<span class="typing-char typing-fade-in" style="opacity: 0;">${this.escapeHtml(char)}</span>`;
|
|
322
|
+
} else {
|
|
323
|
+
html += `<span class="typing-char" style="opacity: 1;">${this.escapeHtml(char)}</span>`;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (hasCursor) {
|
|
327
|
+
html += `<span class="typing-cursor">${this.escapeHtml(this.config.cursorChar)}</span>`;
|
|
328
|
+
}
|
|
329
|
+
this.container.innerHTML = html;
|
|
330
|
+
const newChars = this.container.querySelectorAll(".typing-fade-in");
|
|
331
|
+
if (newChars.length > 0) {
|
|
332
|
+
requestAnimationFrame(() => {
|
|
333
|
+
newChars.forEach((char) => {
|
|
334
|
+
char.style.opacity = "1";
|
|
335
|
+
char.classList.remove("typing-fade-in");
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
// HTML 이스케이프 유틸리티
|
|
341
|
+
escapeHtml(text) {
|
|
342
|
+
const div = document.createElement("div");
|
|
343
|
+
div.textContent = text;
|
|
344
|
+
return div.innerHTML;
|
|
291
345
|
}
|
|
292
346
|
// 텍스트 변경
|
|
293
347
|
setText(newText) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masoneffect",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
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",
|