masoneffect 2.0.2 → 2.0.4
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 +4 -4
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/typing/index.d.ts +53 -0
- package/dist/core/typing/index.d.ts.map +1 -0
- package/dist/count/core/index.d.ts +2 -0
- package/dist/count/core/index.d.ts.map +1 -1
- package/dist/count/core/typing/index.d.ts +53 -0
- package/dist/count/core/typing/index.d.ts.map +1 -0
- package/dist/count/index.d.ts +2 -0
- package/dist/count/index.d.ts.map +1 -1
- package/dist/count/react/index.d.ts +2 -0
- package/dist/count/react/index.d.ts.map +1 -1
- package/dist/count/react/typing/Typing.d.ts +18 -0
- package/dist/count/react/typing/Typing.d.ts.map +1 -0
- package/dist/count/react/typing/index.d.ts +4 -0
- package/dist/count/react/typing/index.d.ts.map +1 -0
- package/dist/count/svelte/index.d.ts +1 -0
- package/dist/count/svelte/index.d.ts.map +1 -1
- package/dist/count/svelte/typing/index.d.ts +3 -0
- package/dist/count/svelte/typing/index.d.ts.map +1 -0
- package/dist/count/vue/index.d.ts +1 -0
- package/dist/count/vue/index.d.ts.map +1 -1
- package/dist/count/vue/typing/index.d.ts +4 -0
- package/dist/count/vue/typing/index.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/react/core/index.d.ts +2 -0
- package/dist/react/core/typing/index.d.ts +52 -0
- package/dist/react/count/core/index.d.ts +2 -0
- package/dist/react/count/core/index.d.ts.map +1 -1
- package/dist/react/count/core/typing/index.d.ts +53 -0
- package/dist/react/count/core/typing/index.d.ts.map +1 -0
- package/dist/react/count/index.d.ts +2 -0
- package/dist/react/count/index.d.ts.map +1 -1
- package/dist/react/count/react/index.d.ts +2 -0
- package/dist/react/count/react/index.d.ts.map +1 -1
- package/dist/react/count/react/typing/Typing.d.ts +18 -0
- package/dist/react/count/react/typing/Typing.d.ts.map +1 -0
- package/dist/react/count/react/typing/index.d.ts +4 -0
- package/dist/react/count/react/typing/index.d.ts.map +1 -0
- package/dist/react/count/svelte/index.d.ts +1 -0
- package/dist/react/count/svelte/index.d.ts.map +1 -1
- package/dist/react/count/svelte/typing/index.d.ts +3 -0
- package/dist/react/count/svelte/typing/index.d.ts.map +1 -0
- package/dist/react/count/vue/index.d.ts +1 -0
- package/dist/react/count/vue/index.d.ts.map +1 -1
- package/dist/react/count/vue/typing/index.d.ts +4 -0
- package/dist/react/count/vue/typing/index.d.ts.map +1 -0
- package/dist/react/index.cjs +2 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.mjs +1 -0
- package/dist/react/react/index.d.ts +2 -0
- package/dist/react/react/typing/Typing.d.ts +17 -0
- package/dist/react/react/typing/index.d.ts +3 -0
- package/dist/react/svelte/index.d.ts +1 -0
- package/dist/react/svelte/typing/index.d.ts +2 -0
- package/dist/react/textToParticle/core/index.d.ts +2 -0
- package/dist/react/textToParticle/core/index.d.ts.map +1 -1
- package/dist/react/textToParticle/core/typing/index.d.ts +53 -0
- package/dist/react/textToParticle/core/typing/index.d.ts.map +1 -0
- package/dist/react/textToParticle/index.d.ts +2 -0
- package/dist/react/textToParticle/index.d.ts.map +1 -1
- package/dist/react/textToParticle/react/index.d.ts +2 -0
- package/dist/react/textToParticle/react/index.d.ts.map +1 -1
- package/dist/react/textToParticle/react/typing/Typing.d.ts +18 -0
- package/dist/react/textToParticle/react/typing/Typing.d.ts.map +1 -0
- package/dist/react/textToParticle/react/typing/index.d.ts +4 -0
- package/dist/react/textToParticle/react/typing/index.d.ts.map +1 -0
- package/dist/react/textToParticle/svelte/index.d.ts +1 -0
- package/dist/react/textToParticle/svelte/index.d.ts.map +1 -1
- package/dist/react/textToParticle/svelte/typing/index.d.ts +3 -0
- package/dist/react/textToParticle/svelte/typing/index.d.ts.map +1 -0
- package/dist/react/textToParticle/vue/index.d.ts +1 -0
- package/dist/react/textToParticle/vue/index.d.ts.map +1 -1
- package/dist/react/textToParticle/vue/typing/index.d.ts +4 -0
- package/dist/react/textToParticle/vue/typing/index.d.ts.map +1 -0
- package/dist/react/typing/Typing.d.ts +18 -0
- package/dist/react/typing/Typing.d.ts.map +1 -0
- package/dist/react/typing/core/count/index.d.ts +52 -0
- package/dist/react/typing/core/count/index.d.ts.map +1 -0
- package/dist/react/typing/core/index.d.ts +20 -0
- package/dist/react/typing/core/index.d.ts.map +1 -0
- package/dist/react/typing/core/textToParticle/index.d.ts +103 -0
- package/dist/react/typing/core/textToParticle/index.d.ts.map +1 -0
- package/dist/react/typing/core/typing/index.d.ts +53 -0
- package/dist/react/typing/core/typing/index.d.ts.map +1 -0
- package/dist/react/typing/index.cjs +1 -0
- package/dist/react/typing/index.d.ts +18 -0
- package/dist/react/typing/index.d.ts.map +1 -0
- package/dist/react/typing/index.mjs +1 -0
- package/dist/react/typing/index.umd.d.ts +7 -0
- package/dist/react/typing/index.umd.d.ts.map +1 -0
- package/dist/react/typing/react/MasonEffect.d.ts +32 -0
- package/dist/react/typing/react/MasonEffect.d.ts.map +1 -0
- package/dist/react/typing/react/count/Count.d.ts +19 -0
- package/dist/react/typing/react/count/Count.d.ts.map +1 -0
- package/dist/react/typing/react/count/index.d.ts +5 -0
- package/dist/react/typing/react/count/index.d.ts.map +1 -0
- package/dist/react/typing/react/index.d.ts +14 -0
- package/dist/react/typing/react/index.d.ts.map +1 -0
- package/dist/react/typing/react/textToParticle/TextToParticle.d.ts +15 -0
- package/dist/react/typing/react/textToParticle/TextToParticle.d.ts.map +1 -0
- package/dist/react/typing/react/textToParticle/index.d.ts +4 -0
- package/dist/react/typing/react/textToParticle/index.d.ts.map +1 -0
- package/dist/react/typing/react/typing/Typing.d.ts +18 -0
- package/dist/react/typing/react/typing/Typing.d.ts.map +1 -0
- package/dist/react/typing/react/typing/index.d.ts +4 -0
- package/dist/react/typing/react/typing/index.d.ts.map +1 -0
- package/dist/react/typing/svelte/count/index.d.ts +2 -0
- package/dist/react/typing/svelte/count/index.d.ts.map +1 -0
- package/dist/react/typing/svelte/index.d.ts +9 -0
- package/dist/react/typing/svelte/index.d.ts.map +1 -0
- package/dist/react/typing/svelte/textToParticle/index.d.ts +2 -0
- package/dist/react/typing/svelte/textToParticle/index.d.ts.map +1 -0
- package/dist/react/typing/svelte/typing/index.d.ts +3 -0
- package/dist/react/typing/svelte/typing/index.d.ts.map +1 -0
- package/dist/react/typing/vue/count/index.d.ts +2 -0
- package/dist/react/typing/vue/count/index.d.ts.map +1 -0
- package/dist/react/typing/vue/index.d.ts +9 -0
- package/dist/react/typing/vue/index.d.ts.map +1 -0
- package/dist/react/typing/vue/textToParticle/index.d.ts +2 -0
- package/dist/react/typing/vue/textToParticle/index.d.ts.map +1 -0
- package/dist/react/typing/vue/typing/index.d.ts +4 -0
- package/dist/react/typing/vue/typing/index.d.ts.map +1 -0
- package/dist/react/vue/index.d.ts +1 -0
- package/dist/react/vue/typing/index.d.ts +3 -0
- package/dist/svelte/count/index.d.ts +53 -0
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.d.ts +53 -0
- package/dist/svelte/index.mjs +419 -48
- package/dist/svelte/textToParticle/index.d.ts +53 -0
- package/dist/svelte/typing/index.cjs +1 -0
- package/dist/svelte/typing/index.d.ts +216 -0
- package/dist/svelte/typing/index.mjs +638 -0
- package/dist/textToParticle/core/index.d.ts +2 -0
- package/dist/textToParticle/core/index.d.ts.map +1 -1
- package/dist/textToParticle/core/typing/index.d.ts +53 -0
- package/dist/textToParticle/core/typing/index.d.ts.map +1 -0
- package/dist/textToParticle/index.d.ts +2 -0
- package/dist/textToParticle/index.d.ts.map +1 -1
- package/dist/textToParticle/react/index.d.ts +2 -0
- package/dist/textToParticle/react/index.d.ts.map +1 -1
- package/dist/textToParticle/react/typing/Typing.d.ts +18 -0
- package/dist/textToParticle/react/typing/Typing.d.ts.map +1 -0
- package/dist/textToParticle/react/typing/index.d.ts +4 -0
- package/dist/textToParticle/react/typing/index.d.ts.map +1 -0
- package/dist/textToParticle/svelte/index.d.ts +1 -0
- package/dist/textToParticle/svelte/index.d.ts.map +1 -1
- package/dist/textToParticle/svelte/typing/index.d.ts +3 -0
- package/dist/textToParticle/svelte/typing/index.d.ts.map +1 -0
- package/dist/textToParticle/vue/index.d.ts +1 -0
- package/dist/textToParticle/vue/index.d.ts.map +1 -1
- package/dist/textToParticle/vue/typing/index.d.ts +4 -0
- package/dist/textToParticle/vue/typing/index.d.ts.map +1 -0
- package/dist/typing/core/count/index.d.ts +52 -0
- package/dist/typing/core/count/index.d.ts.map +1 -0
- package/dist/typing/core/index.d.ts +20 -0
- package/dist/typing/core/index.d.ts.map +1 -0
- package/dist/typing/core/textToParticle/index.d.ts +103 -0
- package/dist/typing/core/textToParticle/index.d.ts.map +1 -0
- package/dist/typing/core/typing/index.d.ts +53 -0
- package/dist/typing/core/typing/index.d.ts.map +1 -0
- package/dist/typing/index.cjs +1 -0
- package/dist/typing/index.d.ts +18 -0
- package/dist/typing/index.d.ts.map +1 -0
- package/dist/typing/index.mjs +1 -0
- package/dist/typing/index.umd.d.ts +7 -0
- package/dist/typing/index.umd.d.ts.map +1 -0
- package/dist/typing/react/MasonEffect.d.ts +32 -0
- package/dist/typing/react/MasonEffect.d.ts.map +1 -0
- package/dist/typing/react/count/Count.d.ts +19 -0
- package/dist/typing/react/count/Count.d.ts.map +1 -0
- package/dist/typing/react/count/index.d.ts +5 -0
- package/dist/typing/react/count/index.d.ts.map +1 -0
- package/dist/typing/react/index.d.ts +14 -0
- package/dist/typing/react/index.d.ts.map +1 -0
- package/dist/typing/react/textToParticle/TextToParticle.d.ts +15 -0
- package/dist/typing/react/textToParticle/TextToParticle.d.ts.map +1 -0
- package/dist/typing/react/textToParticle/index.d.ts +4 -0
- package/dist/typing/react/textToParticle/index.d.ts.map +1 -0
- package/dist/typing/react/typing/Typing.d.ts +18 -0
- package/dist/typing/react/typing/Typing.d.ts.map +1 -0
- package/dist/typing/react/typing/index.d.ts +4 -0
- package/dist/typing/react/typing/index.d.ts.map +1 -0
- package/dist/typing/svelte/count/index.d.ts +2 -0
- package/dist/typing/svelte/count/index.d.ts.map +1 -0
- package/dist/typing/svelte/index.d.ts +9 -0
- package/dist/typing/svelte/index.d.ts.map +1 -0
- package/dist/typing/svelte/textToParticle/index.d.ts +2 -0
- package/dist/typing/svelte/textToParticle/index.d.ts.map +1 -0
- package/dist/typing/svelte/typing/index.d.ts +3 -0
- package/dist/typing/svelte/typing/index.d.ts.map +1 -0
- package/dist/typing/vue/count/index.d.ts +2 -0
- package/dist/typing/vue/count/index.d.ts.map +1 -0
- package/dist/typing/vue/index.d.ts +9 -0
- package/dist/typing/vue/index.d.ts.map +1 -0
- package/dist/typing/vue/textToParticle/index.d.ts +2 -0
- package/dist/typing/vue/textToParticle/index.d.ts.map +1 -0
- package/dist/typing/vue/typing/index.d.ts +4 -0
- package/dist/typing/vue/typing/index.d.ts.map +1 -0
- package/dist/vue/count/index.d.ts +53 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.d.ts +53 -0
- package/dist/vue/index.mjs +316 -7
- package/dist/vue/textToParticle/index.d.ts +53 -0
- package/dist/vue/typing/index.cjs +1 -0
- package/dist/vue/typing/index.d.ts +216 -0
- package/dist/vue/typing/index.mjs +312 -0
- package/package.json +25 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/svelte/textToParticle/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/svelte/typing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,YAAY,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/vue/count/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MasonEffect Vue - 모든 Vue 컴포넌트를 export하는 메인 파일
|
|
3
|
+
*/
|
|
4
|
+
export { default as TextToParticle } from './textToParticle/index.js';
|
|
5
|
+
export { default as Count } from './count/index.js';
|
|
6
|
+
export { default as Typing } from './typing/index.js';
|
|
7
|
+
export { default as MasonEffect } from './textToParticle/index.js';
|
|
8
|
+
export { default } from './textToParticle/index.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vue/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGtE,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGnE,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/vue/textToParticle/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/vue/typing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,YAAY,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -160,4 +160,57 @@ declare class TextToParticle {
|
|
|
160
160
|
export { TextToParticleOptions as MasonEffectOptions }
|
|
161
161
|
export { TextToParticleOptions }
|
|
162
162
|
|
|
163
|
+
export declare class Typing {
|
|
164
|
+
container: HTMLElement;
|
|
165
|
+
config: Required<Omit<TypingOptions, 'onUpdate' | 'onComplete'>> & {
|
|
166
|
+
onUpdate: TypingOptions['onUpdate'];
|
|
167
|
+
onComplete: TypingOptions['onComplete'];
|
|
168
|
+
};
|
|
169
|
+
textUnits: string[];
|
|
170
|
+
charUnitRanges: Array<{
|
|
171
|
+
start: number;
|
|
172
|
+
end: number;
|
|
173
|
+
isHangul: boolean;
|
|
174
|
+
}>;
|
|
175
|
+
currentIndex: number;
|
|
176
|
+
displayedText: string;
|
|
177
|
+
timeoutId: ReturnType<typeof setTimeout> | null;
|
|
178
|
+
intersectionObserver: IntersectionObserver | null;
|
|
179
|
+
isRunning: boolean;
|
|
180
|
+
hasTriggered: boolean;
|
|
181
|
+
originalText: string;
|
|
182
|
+
constructor(container: HTMLElement | string, options: TypingOptions);
|
|
183
|
+
init(): void;
|
|
184
|
+
setupIntersectionObserver(): void;
|
|
185
|
+
private buildTextFromUnits;
|
|
186
|
+
start(): void;
|
|
187
|
+
typeNext(): void;
|
|
188
|
+
stop(): void;
|
|
189
|
+
reset(): void;
|
|
190
|
+
updateDisplay(text: string): void;
|
|
191
|
+
setText(newText: string): void;
|
|
192
|
+
destroy(): void;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Typing - 타이핑 애니메이션 효과
|
|
197
|
+
* 바닐라 JS 코어 클래스
|
|
198
|
+
*
|
|
199
|
+
* 사용법:
|
|
200
|
+
* import { Typing } from 'masoneffect/typing';
|
|
201
|
+
*/
|
|
202
|
+
export declare interface TypingOptions {
|
|
203
|
+
text: string;
|
|
204
|
+
speed?: number;
|
|
205
|
+
delay?: number;
|
|
206
|
+
enabled?: boolean;
|
|
207
|
+
threshold?: number;
|
|
208
|
+
rootMargin?: string;
|
|
209
|
+
triggerOnce?: boolean;
|
|
210
|
+
showCursor?: boolean;
|
|
211
|
+
cursorChar?: string;
|
|
212
|
+
onUpdate?: (text: string) => void;
|
|
213
|
+
onComplete?: () => void;
|
|
214
|
+
}
|
|
215
|
+
|
|
163
216
|
export { }
|
package/dist/vue/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue");function e(t,e){let i=null;return function(...n){null!==i&&clearTimeout(i),i=setTimeout(()=>{i=null,t.apply(this,n)},e)}}class i{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 n=this.canvas.getContext("2d",{willReadFrequently:!0});if(!n)throw new Error("Canvas context not available");this.ctx=n,this.container.appendChild(this.canvas),this.canvas.style.display="block",this.offCanvas=document.createElement("canvas");const s=this.offCanvas.getContext("2d",{willReadFrequently:!0});if(!s)throw new Error("Offscreen canvas context not available");this.offCtx=s,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.isVisible=!1,this.intersectionObserver=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.setupIntersectionObserver(),this.config.onReady&&this.config.onReady(this)}setupIntersectionObserver(){if("undefined"==typeof window||void 0===window.IntersectionObserver)return this.isVisible=!0,void this.start();this.intersectionObserver||(this.intersectionObserver=new IntersectionObserver(t=>{for(const e of t)e.target===this.container&&(e.isIntersecting?(this.isVisible=!0,this.start()):(this.isVisible=!1,this.stop()))},{threshold:.1}),this.intersectionObserver.observe(this.container))}resize(){const t=this.config.width||this.container.clientWidth||window.innerWidth,e=this.config.height||this.container.clientHeight||.7*window.innerHeight;if(t<=0||e<=0)return;this.W=Math.floor(t*this.DPR),this.H=Math.floor(e*this.DPR);const i=4096;if(this.W>i||this.H>i){const t=Math.min(i/this.W,i/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=t+"px",this.canvas.style.height=e+"px",this.W>0&&this.H>0&&(this.buildTargets(),this.particles.length||this.initParticles())}measureTextFit(t,e,i,n){this.offCtx.font=`400 ${t}px ${this.config.fontFamily}`;const s=e.split("\n"),o=t,a=.1*t,r=.05*t;let h=0;for(const d of s){if(0===d.length)continue;const t=this.offCtx.measureText(d).width+r*(d.length>0?d.length-1:0);h=Math.max(h,t)}const l=s.length>0?o*s.length+a*(s.length-1):o;return{width:h,height:l,fits:h<=i&&l<=n}}findOptimalFontSize(t,e,i,n){if(this.measureTextFit(n,t,e,i).fits)return n;if(n<=12)return 12;let s=12,o=n,a=12;for(;s<=o;){const n=Math.floor((s+o)/2);this.measureTextFit(n,t,e,i).fits?(a=n,s=n+1):o=n-1}return a}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 e=Math.min(this.W,this.H),i=this.config.fontSize||Math.max(80,Math.floor(.18*e)),n=this.W-80,s=this.H-80,o=this.findOptimalFontSize(t,n,s,i);this.offCtx.fillStyle="#ffffff",this.offCtx.textAlign="center",this.offCtx.textBaseline="middle",this.offCtx.font=`400 ${o}px ${this.config.fontFamily}`;const a=t.split("\n"),r=o,h=.1*o,l=.05*o,d=a.length>0?r*a.length+h*(a.length-1):r;let c=this.H/2-d/2+r/2;for(const g of a){if(0===g.length){c+=r+h;continue}const t=g.split(""),e=this.offCtx.measureText(g).width+l*(t.length>0?t.length-1:0);let i=this.W/2-e/2;for(const n of t)this.offCtx.fillText(n,i+this.offCtx.measureText(n).width/2,c),i+=this.offCtx.measureText(n).width+l;c+=r+h}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 e=4*(g*this.W+t);f[e]+f[e+1]+f[e+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 e=0;e<t;e++)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],e=p[g];t.tx=e.x,t.ty=e.y}}makeParticle(){const t=Math.random()*this.W,e=Math.random()*this.H;return{x:t,y:e,vx:0,vy:0,tx:t,ty:e,initialX:t,initialY:e,j:Math.random()*Math.PI*2}}initParticles(){for(const t of this.particles){const e=Math.random()*this.W,i=Math.random()*this.H;t.x=e,t.y=i,t.vx=t.vy=0,t.initialX=e,t.initialY=i}}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 e=void 0!==t.text;this.config={...this.config,...t},e&&this.buildTargets()}else this.buildTargets()}update(){this.ctx.clearRect(0,0,this.W,this.H);for(const e of this.particles){let t=(e.tx-e.x)*this.config.ease,i=(e.ty-e.y)*this.config.ease;if(this.mouse.x||this.mouse.y){const n=e.x-this.mouse.x,s=e.y-this.mouse.y,o=n*n+s*s,a=this.config.repelRadius*this.DPR;if(o<a*a){const e=Math.sqrt(o)+1e-4,r=(this.mouse.down?-1:1)*this.config.repelStrength*(1-e/a);t+=n/e*r*6,i+=s/e*r*6}}e.j+=2,t+=.05*Math.cos(e.j),i+=.05*Math.sin(1.3*e.j),e.vx=(e.vx+t)*Math.random(),e.vy=(e.vy+i)*Math.random(),e.x+=e.vx,e.y+=e.vy}this.ctx.fillStyle=this.config.particleColor;const t=this.config.pointSize*this.DPR;for(const e of this.particles)this.ctx.beginPath(),this.ctx.arc(e.x,e.y,t,0,2*Math.PI),this.ctx.fill();this.config.onUpdate&&this.config.onUpdate(this)}animate(){this.isRunning&&(this.update(),this.animationId=requestAnimationFrame(()=>this.animate()))}start(){this.isRunning||(this.isRunning=!0,this.animate())}stop(){this.isRunning=!1,this.animationId&&(cancelAnimationFrame(this.animationId),this.animationId=null)}setupEventListeners(){window.addEventListener("resize",this.handleResize),this.canvas.addEventListener("mousemove",this.handleMouseMove),this.canvas.addEventListener("mouseleave",this.handleMouseLeave),this.canvas.addEventListener("mousedown",this.handleMouseDown),window.addEventListener("mouseup",this.handleMouseUp)}removeEventListeners(){window.removeEventListener("resize",this.handleResize),this.canvas.removeEventListener("mousemove",this.handleMouseMove),this.canvas.removeEventListener("mouseleave",this.handleMouseLeave),this.canvas.removeEventListener("mousedown",this.handleMouseDown),window.removeEventListener("mouseup",this.handleMouseUp)}handleResize(){this.resize()}handleMouseMove(t){const e=this.canvas.getBoundingClientRect();this.mouse.x=(t.clientX-e.left)*this.DPR,this.mouse.y=(t.clientY-e.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.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null),this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas)}}const n={linear:t=>t};class s{constructor(t,e){if(this.container="string"==typeof t?document.querySelector(t):t,!this.container)throw new Error("Container element not found");this.config={targetValue:e.targetValue,duration:e.duration??2e3,startValue:e.startValue??0,enabled:e.enabled??!0,easing:e.easing??n.linear,threshold:e.threshold??.2,rootMargin:e.rootMargin??"0px 0px -100px 0px",triggerOnce:e.triggerOnce??!1,onUpdate:e.onUpdate||null,onComplete:e.onComplete||null},this.currentValue=this.config.startValue,this.startTime=null,this.animationFrameId=null,this.intersectionObserver=null,this.isRunning=!1,this.hasTriggered=!1,this.init()}init(){this.updateDisplay(this.config.startValue),this.setupIntersectionObserver()}setupIntersectionObserver(){"undefined"!=typeof window&&void 0!==window.IntersectionObserver?(this.intersectionObserver=new IntersectionObserver(t=>{var e;for(const i of t)if(i.target===this.container)if(i.isIntersecting)!this.hasTriggered&&this.config.enabled&&(this.hasTriggered=!0,this.start()),this.config.triggerOnce&&(null==(e=this.intersectionObserver)||e.unobserve(this.container));else if(!this.config.triggerOnce){const t=i.boundingClientRect,e=window.innerHeight,n=window.innerWidth;(t.bottom<=0||t.top>=e||t.right<=0||t.left>=n)&&this.isRunning&&this.reset()}},{threshold:this.config.threshold,rootMargin:this.config.rootMargin}),this.intersectionObserver.observe(this.container)):this.config.enabled&&this.start()}start(){if(this.isRunning)return;if(!this.config.enabled)return;this.isRunning=!0,this.startTime=null,this.currentValue=this.config.startValue,this.updateDisplay(this.currentValue);const t=e=>{null===this.startTime&&(this.startTime=e);const i=e-this.startTime,n=Math.min(i/this.config.duration,1),s=this.config.easing(n);this.currentValue=Math.floor(this.config.startValue+(this.config.targetValue-this.config.startValue)*s),this.updateDisplay(this.currentValue),this.config.onUpdate&&this.config.onUpdate(this.currentValue),n<1?this.animationFrameId=requestAnimationFrame(t):(this.currentValue=this.config.targetValue,this.updateDisplay(this.currentValue),this.isRunning=!1,this.config.onComplete&&this.config.onComplete())};this.animationFrameId=requestAnimationFrame(t)}stop(){this.isRunning=!1,null!==this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}reset(){this.stop(),this.currentValue=this.config.startValue,this.updateDisplay(this.currentValue),this.hasTriggered=!1,this.startTime=null}updateDisplay(t){this.container.textContent=this.formatNumber(t)}formatNumber(t){return Math.floor(t).toLocaleString()}updateConfig(t){const e=this.isRunning;this.stop(),this.config={...this.config,...t,onUpdate:void 0!==t.onUpdate?t.onUpdate:this.config.onUpdate,onComplete:void 0!==t.onComplete?t.onComplete:this.config.onComplete},void 0!==t.targetValue?(this.reset(),e&&this.config.enabled&&this.start()):e&&this.config.enabled&&this.start()}getValue(){return this.currentValue}destroy(){this.stop(),this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null)}}const o=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(e,{expose:n,emit:s}){const o=e,a=s,r=t.ref(null);let h=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],()=>{h&&h.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(!r.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),a("ready",t)},onUpdate:t=>{o.onUpdate&&o.onUpdate(t),a("update",t)}};h=new i(r.value,t)})()}),t.onBeforeUnmount(()=>{h&&(h.destroy(),h=null)}),n({morph:t=>{h&&h.morph(t)},scatter:()=>{h&&h.scatter()},updateConfig:t=>{h&&h.updateConfig(t)},destroy:()=>{h&&(h.destroy(),h=null)}}),(i,n)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"container",ref:r,class:t.normalizeClass(e.className),style:t.normalizeStyle(e.style)},null,6))}}),a=t.defineComponent({__name:"Count",props:{className:{default:""},style:{default:()=>({})},targetValue:{default:0},duration:{default:2e3},startValue:{default:0},enabled:{type:Boolean,default:!0},easing:{type:Function,default:()=>t=>t},threshold:{default:.2},rootMargin:{default:"0px 0px -100px 0px"},triggerOnce:{type:Boolean,default:!1},onUpdate:{type:Function,default:null},onComplete:{type:Function,default:null}},emits:["update","complete"],setup(e,{expose:i,emit:n}){const o=e,a=n,r=t.ref(null);let h=null;return t.watch(()=>[o.targetValue,o.duration,o.startValue,o.enabled,o.easing,o.threshold,o.rootMargin,o.triggerOnce],()=>{h&&h.updateConfig({targetValue:o.targetValue,duration:o.duration,startValue:o.startValue,enabled:o.enabled,easing:o.easing,threshold:o.threshold,rootMargin:o.rootMargin,triggerOnce:o.triggerOnce,onUpdate:t=>{o.onUpdate&&o.onUpdate(t),a("update",t)},onComplete:()=>{o.onComplete&&o.onComplete(),a("complete")}})}),t.onMounted(()=>{(()=>{if(!r.value)return;const t={targetValue:o.targetValue,duration:o.duration,startValue:o.startValue,enabled:o.enabled,easing:o.easing,threshold:o.threshold,rootMargin:o.rootMargin,triggerOnce:o.triggerOnce,onUpdate:t=>{o.onUpdate&&o.onUpdate(t),a("update",t)},onComplete:()=>{o.onComplete&&o.onComplete(),a("complete")}};h=new s(r.value,t)})()}),t.onBeforeUnmount(()=>{h&&(h.destroy(),h=null)}),i({start:()=>{h&&h.start()},stop:()=>{h&&h.stop()},reset:()=>{h&&h.reset()},getValue:()=>h?h.getValue():0,updateConfig:t=>{h&&h.updateConfig(t)},destroy:()=>{h&&(h.destroy(),h=null)}}),(i,n)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"container",ref:r,class:t.normalizeClass(e.className),style:t.normalizeStyle(e.style)},null,6))}});exports.Count=a,exports.MasonEffect=o,exports.TextToParticle=o,exports.default=o;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue");function e(t,e){let i=null;return function(...n){null!==i&&clearTimeout(i),i=setTimeout(()=>{i=null,t.apply(this,n)},e)}}class i{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 n=this.canvas.getContext("2d",{willReadFrequently:!0});if(!n)throw new Error("Canvas context not available");this.ctx=n,this.container.appendChild(this.canvas),this.canvas.style.display="block",this.offCanvas=document.createElement("canvas");const s=this.offCanvas.getContext("2d",{willReadFrequently:!0});if(!s)throw new Error("Offscreen canvas context not available");this.offCtx=s,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.isVisible=!1,this.intersectionObserver=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.setupIntersectionObserver(),this.config.onReady&&this.config.onReady(this)}setupIntersectionObserver(){if("undefined"==typeof window||void 0===window.IntersectionObserver)return this.isVisible=!0,void this.start();this.intersectionObserver||(this.intersectionObserver=new IntersectionObserver(t=>{for(const e of t)e.target===this.container&&(e.isIntersecting?(this.isVisible=!0,this.start()):(this.isVisible=!1,this.stop()))},{threshold:.1}),this.intersectionObserver.observe(this.container))}resize(){const t=this.config.width||this.container.clientWidth||window.innerWidth,e=this.config.height||this.container.clientHeight||.7*window.innerHeight;if(t<=0||e<=0)return;this.W=Math.floor(t*this.DPR),this.H=Math.floor(e*this.DPR);const i=4096;if(this.W>i||this.H>i){const t=Math.min(i/this.W,i/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=t+"px",this.canvas.style.height=e+"px",this.W>0&&this.H>0&&(this.buildTargets(),this.particles.length||this.initParticles())}measureTextFit(t,e,i,n){this.offCtx.font=`400 ${t}px ${this.config.fontFamily}`;const s=e.split("\n"),o=t,a=.1*t,r=.05*t;let h=0;for(const u of s){if(0===u.length)continue;const t=this.offCtx.measureText(u).width+r*(u.length>0?u.length-1:0);h=Math.max(h,t)}const l=s.length>0?o*s.length+a*(s.length-1):o;return{width:h,height:l,fits:h<=i&&l<=n}}findOptimalFontSize(t,e,i,n){if(this.measureTextFit(n,t,e,i).fits)return n;if(n<=12)return 12;let s=12,o=n,a=12;for(;s<=o;){const n=Math.floor((s+o)/2);this.measureTextFit(n,t,e,i).fits?(a=n,s=n+1):o=n-1}return a}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 e=Math.min(this.W,this.H),i=this.config.fontSize||Math.max(80,Math.floor(.18*e)),n=this.W-80,s=this.H-80,o=this.findOptimalFontSize(t,n,s,i);this.offCtx.fillStyle="#ffffff",this.offCtx.textAlign="center",this.offCtx.textBaseline="middle",this.offCtx.font=`400 ${o}px ${this.config.fontFamily}`;const a=t.split("\n"),r=o,h=.1*o,l=.05*o,u=a.length>0?r*a.length+h*(a.length-1):r;let d=this.H/2-u/2+r/2;for(const p of a){if(0===p.length){d+=r+h;continue}const t=p.split(""),e=this.offCtx.measureText(p).width+l*(t.length>0?t.length-1:0);let i=this.W/2-e/2;for(const n of t)this.offCtx.fillText(n,i+this.offCtx.measureText(n).width/2,d),i+=this.offCtx.measureText(n).width+l;d+=r+h}const c=Math.max(2,this.config.densityStep),f=this.offCtx.getImageData(0,0,this.W,this.H).data,g=[];for(let p=0;p<this.H;p+=c)for(let t=0;t<this.W;t+=c){const e=4*(p*this.W+t);f[e]+f[e+1]+f[e+2]>600&&g.push({x:t,y:p})}for(;g.length>this.config.maxParticles;)g.splice(Math.floor(Math.random()*g.length),1);if(this.particles.length<g.length){const t=g.length-this.particles.length;for(let e=0;e<t;e++)this.particles.push(this.makeParticle())}else this.particles.length>g.length&&(this.particles.length=g.length);for(let p=0;p<this.particles.length;p++){const t=this.particles[p],e=g[p];t.tx=e.x,t.ty=e.y}}makeParticle(){const t=Math.random()*this.W,e=Math.random()*this.H;return{x:t,y:e,vx:0,vy:0,tx:t,ty:e,initialX:t,initialY:e,j:Math.random()*Math.PI*2}}initParticles(){for(const t of this.particles){const e=Math.random()*this.W,i=Math.random()*this.H;t.x=e,t.y=i,t.vx=t.vy=0,t.initialX=e,t.initialY=i}}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 e=void 0!==t.text;this.config={...this.config,...t},e&&this.buildTargets()}else this.buildTargets()}update(){this.ctx.clearRect(0,0,this.W,this.H);for(const e of this.particles){let t=(e.tx-e.x)*this.config.ease,i=(e.ty-e.y)*this.config.ease;if(this.mouse.x||this.mouse.y){const n=e.x-this.mouse.x,s=e.y-this.mouse.y,o=n*n+s*s,a=this.config.repelRadius*this.DPR;if(o<a*a){const e=Math.sqrt(o)+1e-4,r=(this.mouse.down?-1:1)*this.config.repelStrength*(1-e/a);t+=n/e*r*6,i+=s/e*r*6}}e.j+=2,t+=.05*Math.cos(e.j),i+=.05*Math.sin(1.3*e.j),e.vx=(e.vx+t)*Math.random(),e.vy=(e.vy+i)*Math.random(),e.x+=e.vx,e.y+=e.vy}this.ctx.fillStyle=this.config.particleColor;const t=this.config.pointSize*this.DPR;for(const e of this.particles)this.ctx.beginPath(),this.ctx.arc(e.x,e.y,t,0,2*Math.PI),this.ctx.fill();this.config.onUpdate&&this.config.onUpdate(this)}animate(){this.isRunning&&(this.update(),this.animationId=requestAnimationFrame(()=>this.animate()))}start(){this.isRunning||(this.isRunning=!0,this.animate())}stop(){this.isRunning=!1,this.animationId&&(cancelAnimationFrame(this.animationId),this.animationId=null)}setupEventListeners(){window.addEventListener("resize",this.handleResize),this.canvas.addEventListener("mousemove",this.handleMouseMove),this.canvas.addEventListener("mouseleave",this.handleMouseLeave),this.canvas.addEventListener("mousedown",this.handleMouseDown),window.addEventListener("mouseup",this.handleMouseUp)}removeEventListeners(){window.removeEventListener("resize",this.handleResize),this.canvas.removeEventListener("mousemove",this.handleMouseMove),this.canvas.removeEventListener("mouseleave",this.handleMouseLeave),this.canvas.removeEventListener("mousedown",this.handleMouseDown),window.removeEventListener("mouseup",this.handleMouseUp)}handleResize(){this.resize()}handleMouseMove(t){const e=this.canvas.getBoundingClientRect();this.mouse.x=(t.clientX-e.left)*this.DPR,this.mouse.y=(t.clientY-e.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.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null),this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas)}}const n={linear:t=>t};class s{constructor(t,e){if(this.container="string"==typeof t?document.querySelector(t):t,!this.container)throw new Error("Container element not found");this.config={targetValue:e.targetValue,duration:e.duration??2e3,startValue:e.startValue??0,enabled:e.enabled??!0,easing:e.easing??n.linear,threshold:e.threshold??.2,rootMargin:e.rootMargin??"0px 0px -100px 0px",triggerOnce:e.triggerOnce??!1,onUpdate:e.onUpdate||null,onComplete:e.onComplete||null},this.currentValue=this.config.startValue,this.startTime=null,this.animationFrameId=null,this.intersectionObserver=null,this.isRunning=!1,this.hasTriggered=!1,this.init()}init(){this.updateDisplay(this.config.startValue),this.setupIntersectionObserver()}setupIntersectionObserver(){"undefined"!=typeof window&&void 0!==window.IntersectionObserver?(this.intersectionObserver=new IntersectionObserver(t=>{var e;for(const i of t)if(i.target===this.container)if(i.isIntersecting)!this.hasTriggered&&this.config.enabled&&(this.hasTriggered=!0,this.start()),this.config.triggerOnce&&(null==(e=this.intersectionObserver)||e.unobserve(this.container));else if(!this.config.triggerOnce){const t=i.boundingClientRect,e=window.innerHeight,n=window.innerWidth;(t.bottom<=0||t.top>=e||t.right<=0||t.left>=n)&&this.isRunning&&this.reset()}},{threshold:this.config.threshold,rootMargin:this.config.rootMargin}),this.intersectionObserver.observe(this.container)):this.config.enabled&&this.start()}start(){if(this.isRunning)return;if(!this.config.enabled)return;this.isRunning=!0,this.startTime=null,this.currentValue=this.config.startValue,this.updateDisplay(this.currentValue);const t=e=>{null===this.startTime&&(this.startTime=e);const i=e-this.startTime,n=Math.min(i/this.config.duration,1),s=this.config.easing(n);this.currentValue=Math.floor(this.config.startValue+(this.config.targetValue-this.config.startValue)*s),this.updateDisplay(this.currentValue),this.config.onUpdate&&this.config.onUpdate(this.currentValue),n<1?this.animationFrameId=requestAnimationFrame(t):(this.currentValue=this.config.targetValue,this.updateDisplay(this.currentValue),this.isRunning=!1,this.config.onComplete&&this.config.onComplete())};this.animationFrameId=requestAnimationFrame(t)}stop(){this.isRunning=!1,null!==this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}reset(){this.stop(),this.currentValue=this.config.startValue,this.updateDisplay(this.currentValue),this.hasTriggered=!1,this.startTime=null}updateDisplay(t){this.container.textContent=this.formatNumber(t)}formatNumber(t){return Math.floor(t).toLocaleString()}updateConfig(t){const e=this.isRunning;this.stop(),this.config={...this.config,...t,onUpdate:void 0!==t.onUpdate?t.onUpdate:this.config.onUpdate,onComplete:void 0!==t.onComplete?t.onComplete:this.config.onComplete},void 0!==t.targetValue?(this.reset(),e&&this.config.enabled&&this.start()):e&&this.config.enabled&&this.start()}getValue(){return this.currentValue}destroy(){this.stop(),this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null)}}function o(t){const e=t.charCodeAt(0);if(e<44032||e>55203)return[t];const i=e-44032,n=Math.floor(i/588),s=Math.floor(i%588/28),o=i%28,a=["","ㄱ","ㄲ","ㄳ","ㄴ","ㄵ","ㄶ","ㄷ","ㄹ","ㄺ","ㄻ","ㄼ","ㄽ","ㄾ","ㄿ","ㅀ","ㅁ","ㅂ","ㅄ","ㅅ","ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"],r=[];return r.push(["ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"][n]),r.push(["ㅏ","ㅐ","ㅑ","ㅒ","ㅓ","ㅔ","ㅕ","ㅖ","ㅗ","ㅘ","ㅙ","ㅚ","ㅛ","ㅜ","ㅝ","ㅞ","ㅟ","ㅠ","ㅡ","ㅢ","ㅣ"][s]),o>0&&r.push(a[o]),r}function a(t,e,i){const n=["ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ","ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"].indexOf(t),s=["ㅏ","ㅐ","ㅑ","ㅒ","ㅓ","ㅔ","ㅕ","ㅖ","ㅗ","ㅘ","ㅙ","ㅚ","ㅛ","ㅜ","ㅝ","ㅞ","ㅟ","ㅠ","ㅡ","ㅢ","ㅣ"].indexOf(e),o=i?["","ㄱ","ㄲ","ㄳ","ㄴ","ㄵ","ㄶ","ㄷ","ㄹ","ㄺ","ㄻ","ㄼ","ㄽ","ㄾ","ㄿ","ㅀ","ㅁ","ㅂ","ㅄ","ㅅ","ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"].indexOf(i):0;if(-1===n||-1===s)return t+(e||"")+(i||"");const a=44032+21*n*28+28*s+o;return String.fromCharCode(a)}function r(t){const e=[],i=[];for(let n=0;n<t.length;n++){const s=t[n],a=s.charCodeAt(0),r=e.length;if(a>=44032&&a<=55203){const t=o(s);e.push(...t),i.push({start:r,end:e.length,isHangul:!0})}else e.push(s),i.push({start:r,end:e.length,isHangul:!1})}return{units:e,charUnitRanges:i}}class h{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=r(this.config.text);this.textUnits=i.units,this.charUnitRanges=i.charUnitRanges,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)}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 s=Math.min(t-n.start,n.end-n.start);if(s<=0)break;if(n.isHangul){const t=this.textUnits.slice(n.start,n.start+s);1===t.length?e+=t[0]:2===t.length?e+=a(t[0],t[1]):t.length>=3&&(e+=a(t[0],t[1],t[2]))}else s>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=r(t);this.textUnits=e.units,this.charUnitRanges=e.charUnitRanges,this.reset(),this.config.enabled&&setTimeout(()=>this.start(),this.config.delay)}destroy(){this.stop(),this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null)}}const l=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(e,{expose:n,emit:s}){const o=e,a=s,r=t.ref(null);let h=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],()=>{h&&h.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(!r.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),a("ready",t)},onUpdate:t=>{o.onUpdate&&o.onUpdate(t),a("update",t)}};h=new i(r.value,t)})()}),t.onBeforeUnmount(()=>{h&&(h.destroy(),h=null)}),n({morph:t=>{h&&h.morph(t)},scatter:()=>{h&&h.scatter()},updateConfig:t=>{h&&h.updateConfig(t)},destroy:()=>{h&&(h.destroy(),h=null)}}),(i,n)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"container",ref:r,class:t.normalizeClass(e.className),style:t.normalizeStyle(e.style)},null,6))}}),u=t.defineComponent({__name:"Count",props:{className:{default:""},style:{default:()=>({})},targetValue:{default:0},duration:{default:2e3},startValue:{default:0},enabled:{type:Boolean,default:!0},easing:{type:Function,default:()=>t=>t},threshold:{default:.2},rootMargin:{default:"0px 0px -100px 0px"},triggerOnce:{type:Boolean,default:!1},onUpdate:{type:Function,default:null},onComplete:{type:Function,default:null}},emits:["update","complete"],setup(e,{expose:i,emit:n}){const o=e,a=n,r=t.ref(null);let h=null;return t.watch(()=>[o.targetValue,o.duration,o.startValue,o.enabled,o.easing,o.threshold,o.rootMargin,o.triggerOnce],()=>{h&&h.updateConfig({targetValue:o.targetValue,duration:o.duration,startValue:o.startValue,enabled:o.enabled,easing:o.easing,threshold:o.threshold,rootMargin:o.rootMargin,triggerOnce:o.triggerOnce,onUpdate:t=>{o.onUpdate&&o.onUpdate(t),a("update",t)},onComplete:()=>{o.onComplete&&o.onComplete(),a("complete")}})}),t.onMounted(()=>{(()=>{if(!r.value)return;const t={targetValue:o.targetValue,duration:o.duration,startValue:o.startValue,enabled:o.enabled,easing:o.easing,threshold:o.threshold,rootMargin:o.rootMargin,triggerOnce:o.triggerOnce,onUpdate:t=>{o.onUpdate&&o.onUpdate(t),a("update",t)},onComplete:()=>{o.onComplete&&o.onComplete(),a("complete")}};h=new s(r.value,t)})()}),t.onBeforeUnmount(()=>{h&&(h.destroy(),h=null)}),i({start:()=>{h&&h.start()},stop:()=>{h&&h.stop()},reset:()=>{h&&h.reset()},getValue:()=>h?h.getValue():0,updateConfig:t=>{h&&h.updateConfig(t)},destroy:()=>{h&&(h.destroy(),h=null)}}),(i,n)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"container",ref:r,class:t.normalizeClass(e.className),style:t.normalizeStyle(e.style)},null,6))}}),d=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,s=t.ref(null),o=t.ref(null);return t.onMounted(()=>{if(!s.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 h(s.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,n)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"containerRef",ref:s,class:t.normalizeClass(e.className),style:t.normalizeStyle(e.style)},null,6))}});exports.Count=u,exports.MasonEffect=l,exports.TextToParticle=l,exports.Typing=d,exports.default=l;
|
package/dist/vue/index.d.ts
CHANGED
|
@@ -160,4 +160,57 @@ declare class TextToParticle {
|
|
|
160
160
|
export { TextToParticleOptions as MasonEffectOptions }
|
|
161
161
|
export { TextToParticleOptions }
|
|
162
162
|
|
|
163
|
+
export declare class Typing {
|
|
164
|
+
container: HTMLElement;
|
|
165
|
+
config: Required<Omit<TypingOptions, 'onUpdate' | 'onComplete'>> & {
|
|
166
|
+
onUpdate: TypingOptions['onUpdate'];
|
|
167
|
+
onComplete: TypingOptions['onComplete'];
|
|
168
|
+
};
|
|
169
|
+
textUnits: string[];
|
|
170
|
+
charUnitRanges: Array<{
|
|
171
|
+
start: number;
|
|
172
|
+
end: number;
|
|
173
|
+
isHangul: boolean;
|
|
174
|
+
}>;
|
|
175
|
+
currentIndex: number;
|
|
176
|
+
displayedText: string;
|
|
177
|
+
timeoutId: ReturnType<typeof setTimeout> | null;
|
|
178
|
+
intersectionObserver: IntersectionObserver | null;
|
|
179
|
+
isRunning: boolean;
|
|
180
|
+
hasTriggered: boolean;
|
|
181
|
+
originalText: string;
|
|
182
|
+
constructor(container: HTMLElement | string, options: TypingOptions);
|
|
183
|
+
init(): void;
|
|
184
|
+
setupIntersectionObserver(): void;
|
|
185
|
+
private buildTextFromUnits;
|
|
186
|
+
start(): void;
|
|
187
|
+
typeNext(): void;
|
|
188
|
+
stop(): void;
|
|
189
|
+
reset(): void;
|
|
190
|
+
updateDisplay(text: string): void;
|
|
191
|
+
setText(newText: string): void;
|
|
192
|
+
destroy(): void;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Typing - 타이핑 애니메이션 효과
|
|
197
|
+
* 바닐라 JS 코어 클래스
|
|
198
|
+
*
|
|
199
|
+
* 사용법:
|
|
200
|
+
* import { Typing } from 'masoneffect/typing';
|
|
201
|
+
*/
|
|
202
|
+
export declare interface TypingOptions {
|
|
203
|
+
text: string;
|
|
204
|
+
speed?: number;
|
|
205
|
+
delay?: number;
|
|
206
|
+
enabled?: boolean;
|
|
207
|
+
threshold?: number;
|
|
208
|
+
rootMargin?: string;
|
|
209
|
+
triggerOnce?: boolean;
|
|
210
|
+
showCursor?: boolean;
|
|
211
|
+
cursorChar?: string;
|
|
212
|
+
onUpdate?: (text: string) => void;
|
|
213
|
+
onComplete?: () => void;
|
|
214
|
+
}
|
|
215
|
+
|
|
163
216
|
export { }
|
package/dist/vue/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, ref, watch, onMounted, onBeforeUnmount, createElementBlock, openBlock, normalizeStyle, normalizeClass } from "vue";
|
|
1
|
+
import { defineComponent, ref, watch, onMounted, onBeforeUnmount, createElementBlock, openBlock, normalizeStyle, normalizeClass, onUnmounted } from "vue";
|
|
2
2
|
function debounce(func, wait) {
|
|
3
3
|
let timeout = null;
|
|
4
4
|
return function executedFunction(...args) {
|
|
@@ -583,7 +583,232 @@ class Count {
|
|
|
583
583
|
}
|
|
584
584
|
}
|
|
585
585
|
}
|
|
586
|
-
|
|
586
|
+
function decomposeHangul(char) {
|
|
587
|
+
const code = char.charCodeAt(0);
|
|
588
|
+
if (code < 44032 || code > 55203) {
|
|
589
|
+
return [char];
|
|
590
|
+
}
|
|
591
|
+
const base = code - 44032;
|
|
592
|
+
const initial = Math.floor(base / (21 * 28));
|
|
593
|
+
const medial = Math.floor(base % (21 * 28) / 28);
|
|
594
|
+
const final = base % 28;
|
|
595
|
+
const initialChars = ["ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
|
|
596
|
+
const medialChars = ["ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ"];
|
|
597
|
+
const finalChars = ["", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
|
|
598
|
+
const result = [];
|
|
599
|
+
result.push(initialChars[initial]);
|
|
600
|
+
result.push(medialChars[medial]);
|
|
601
|
+
if (final > 0) {
|
|
602
|
+
result.push(finalChars[final]);
|
|
603
|
+
}
|
|
604
|
+
return result;
|
|
605
|
+
}
|
|
606
|
+
function composeHangul(initial, medial, final) {
|
|
607
|
+
const initialChars = ["ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
|
|
608
|
+
const medialChars = ["ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ"];
|
|
609
|
+
const finalChars = ["", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
|
|
610
|
+
const initialIndex = initialChars.indexOf(initial);
|
|
611
|
+
const medialIndex = medialChars.indexOf(medial);
|
|
612
|
+
const finalIndex = final ? finalChars.indexOf(final) : 0;
|
|
613
|
+
if (initialIndex === -1 || medialIndex === -1) {
|
|
614
|
+
return initial + (medial || "") + (final || "");
|
|
615
|
+
}
|
|
616
|
+
const code = 44032 + initialIndex * 21 * 28 + medialIndex * 28 + finalIndex;
|
|
617
|
+
return String.fromCharCode(code);
|
|
618
|
+
}
|
|
619
|
+
function decomposeText(text) {
|
|
620
|
+
const units = [];
|
|
621
|
+
const charUnitRanges = [];
|
|
622
|
+
for (let i = 0; i < text.length; i++) {
|
|
623
|
+
const char = text[i];
|
|
624
|
+
const code = char.charCodeAt(0);
|
|
625
|
+
const startIndex = units.length;
|
|
626
|
+
if (code >= 44032 && code <= 55203) {
|
|
627
|
+
const decomposed = decomposeHangul(char);
|
|
628
|
+
units.push(...decomposed);
|
|
629
|
+
charUnitRanges.push({
|
|
630
|
+
start: startIndex,
|
|
631
|
+
end: units.length,
|
|
632
|
+
isHangul: true
|
|
633
|
+
});
|
|
634
|
+
} else {
|
|
635
|
+
units.push(char);
|
|
636
|
+
charUnitRanges.push({
|
|
637
|
+
start: startIndex,
|
|
638
|
+
end: units.length,
|
|
639
|
+
isHangul: false
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return { units, charUnitRanges };
|
|
644
|
+
}
|
|
645
|
+
class Typing {
|
|
646
|
+
// 원본 텍스트
|
|
647
|
+
constructor(container, options) {
|
|
648
|
+
this.container = typeof container === "string" ? document.querySelector(container) : container;
|
|
649
|
+
if (!this.container) {
|
|
650
|
+
throw new Error("Container element not found");
|
|
651
|
+
}
|
|
652
|
+
this.originalText = options.text;
|
|
653
|
+
this.config = {
|
|
654
|
+
text: options.text,
|
|
655
|
+
speed: options.speed ?? 50,
|
|
656
|
+
delay: options.delay ?? 0,
|
|
657
|
+
enabled: options.enabled ?? true,
|
|
658
|
+
threshold: options.threshold ?? 0.2,
|
|
659
|
+
rootMargin: options.rootMargin ?? "0px 0px -100px 0px",
|
|
660
|
+
triggerOnce: options.triggerOnce ?? false,
|
|
661
|
+
showCursor: options.showCursor ?? true,
|
|
662
|
+
cursorChar: options.cursorChar ?? "|",
|
|
663
|
+
onUpdate: options.onUpdate || null,
|
|
664
|
+
onComplete: options.onComplete || null
|
|
665
|
+
};
|
|
666
|
+
const decomposed = decomposeText(this.config.text);
|
|
667
|
+
this.textUnits = decomposed.units;
|
|
668
|
+
this.charUnitRanges = decomposed.charUnitRanges;
|
|
669
|
+
this.currentIndex = 0;
|
|
670
|
+
this.displayedText = "";
|
|
671
|
+
this.timeoutId = null;
|
|
672
|
+
this.intersectionObserver = null;
|
|
673
|
+
this.isRunning = false;
|
|
674
|
+
this.hasTriggered = false;
|
|
675
|
+
this.init();
|
|
676
|
+
}
|
|
677
|
+
init() {
|
|
678
|
+
this.updateDisplay("");
|
|
679
|
+
this.setupIntersectionObserver();
|
|
680
|
+
}
|
|
681
|
+
setupIntersectionObserver() {
|
|
682
|
+
if (typeof window === "undefined" || typeof window.IntersectionObserver === "undefined") {
|
|
683
|
+
if (this.config.enabled) {
|
|
684
|
+
setTimeout(() => this.start(), this.config.delay);
|
|
685
|
+
}
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
this.intersectionObserver = new IntersectionObserver(
|
|
689
|
+
(entries) => {
|
|
690
|
+
var _a;
|
|
691
|
+
for (const entry of entries) {
|
|
692
|
+
if (entry.target !== this.container) continue;
|
|
693
|
+
if (entry.isIntersecting && !this.hasTriggered) {
|
|
694
|
+
if (this.config.enabled) {
|
|
695
|
+
setTimeout(() => this.start(), this.config.delay);
|
|
696
|
+
}
|
|
697
|
+
this.hasTriggered = true;
|
|
698
|
+
if (this.config.triggerOnce) {
|
|
699
|
+
(_a = this.intersectionObserver) == null ? void 0 : _a.disconnect();
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
},
|
|
704
|
+
{
|
|
705
|
+
threshold: this.config.threshold,
|
|
706
|
+
rootMargin: this.config.rootMargin
|
|
707
|
+
}
|
|
708
|
+
);
|
|
709
|
+
this.intersectionObserver.observe(this.container);
|
|
710
|
+
}
|
|
711
|
+
// 단위들을 다시 합쳐서 실제 표시할 텍스트 생성
|
|
712
|
+
// 한글의 경우 자음/모음이 하나씩 보이도록 합성
|
|
713
|
+
buildTextFromUnits(unitCount) {
|
|
714
|
+
if (unitCount === 0) return "";
|
|
715
|
+
let result = "";
|
|
716
|
+
for (let charIndex = 0; charIndex < this.charUnitRanges.length; charIndex++) {
|
|
717
|
+
const range = this.charUnitRanges[charIndex];
|
|
718
|
+
if (range.start >= unitCount) {
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
const unitsEntered = Math.min(unitCount - range.start, range.end - range.start);
|
|
722
|
+
if (unitsEntered <= 0) {
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
if (range.isHangul) {
|
|
726
|
+
const charUnits = this.textUnits.slice(range.start, range.start + unitsEntered);
|
|
727
|
+
if (charUnits.length === 1) {
|
|
728
|
+
result += charUnits[0];
|
|
729
|
+
} else if (charUnits.length === 2) {
|
|
730
|
+
result += composeHangul(charUnits[0], charUnits[1]);
|
|
731
|
+
} else if (charUnits.length >= 3) {
|
|
732
|
+
result += composeHangul(charUnits[0], charUnits[1], charUnits[2]);
|
|
733
|
+
}
|
|
734
|
+
} else {
|
|
735
|
+
if (unitsEntered > 0) {
|
|
736
|
+
result += this.textUnits[range.start];
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return result;
|
|
741
|
+
}
|
|
742
|
+
start() {
|
|
743
|
+
if (this.isRunning) return;
|
|
744
|
+
this.isRunning = true;
|
|
745
|
+
this.currentIndex = 0;
|
|
746
|
+
this.displayedText = "";
|
|
747
|
+
this.typeNext();
|
|
748
|
+
}
|
|
749
|
+
typeNext() {
|
|
750
|
+
if (this.currentIndex >= this.textUnits.length) {
|
|
751
|
+
this.isRunning = false;
|
|
752
|
+
if (this.config.showCursor) {
|
|
753
|
+
this.updateDisplay(this.originalText);
|
|
754
|
+
}
|
|
755
|
+
if (this.config.onComplete) {
|
|
756
|
+
this.config.onComplete();
|
|
757
|
+
}
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
this.displayedText = this.buildTextFromUnits(this.currentIndex + 1);
|
|
761
|
+
let displayText = this.displayedText;
|
|
762
|
+
if (this.config.showCursor) {
|
|
763
|
+
displayText += this.config.cursorChar;
|
|
764
|
+
}
|
|
765
|
+
this.updateDisplay(displayText);
|
|
766
|
+
if (this.config.onUpdate) {
|
|
767
|
+
this.config.onUpdate(this.displayedText);
|
|
768
|
+
}
|
|
769
|
+
this.currentIndex++;
|
|
770
|
+
this.timeoutId = setTimeout(() => {
|
|
771
|
+
this.typeNext();
|
|
772
|
+
}, this.config.speed);
|
|
773
|
+
}
|
|
774
|
+
stop() {
|
|
775
|
+
this.isRunning = false;
|
|
776
|
+
if (this.timeoutId) {
|
|
777
|
+
clearTimeout(this.timeoutId);
|
|
778
|
+
this.timeoutId = null;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
reset() {
|
|
782
|
+
this.stop();
|
|
783
|
+
this.currentIndex = 0;
|
|
784
|
+
this.displayedText = "";
|
|
785
|
+
this.hasTriggered = false;
|
|
786
|
+
this.updateDisplay("");
|
|
787
|
+
}
|
|
788
|
+
updateDisplay(text) {
|
|
789
|
+
this.container.textContent = text;
|
|
790
|
+
}
|
|
791
|
+
// 텍스트 변경
|
|
792
|
+
setText(newText) {
|
|
793
|
+
this.originalText = newText;
|
|
794
|
+
this.config.text = newText;
|
|
795
|
+
const decomposed = decomposeText(newText);
|
|
796
|
+
this.textUnits = decomposed.units;
|
|
797
|
+
this.charUnitRanges = decomposed.charUnitRanges;
|
|
798
|
+
this.reset();
|
|
799
|
+
if (this.config.enabled) {
|
|
800
|
+
setTimeout(() => this.start(), this.config.delay);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
destroy() {
|
|
804
|
+
this.stop();
|
|
805
|
+
if (this.intersectionObserver) {
|
|
806
|
+
this.intersectionObserver.disconnect();
|
|
807
|
+
this.intersectionObserver = null;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
587
812
|
__name: "TextToParticle",
|
|
588
813
|
props: {
|
|
589
814
|
className: { default: "" },
|
|
@@ -710,7 +935,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
710
935
|
};
|
|
711
936
|
}
|
|
712
937
|
});
|
|
713
|
-
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
938
|
+
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
714
939
|
__name: "Count",
|
|
715
940
|
props: {
|
|
716
941
|
className: { default: "" },
|
|
@@ -831,9 +1056,93 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
831
1056
|
};
|
|
832
1057
|
}
|
|
833
1058
|
});
|
|
1059
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
1060
|
+
__name: "Typing",
|
|
1061
|
+
props: {
|
|
1062
|
+
className: {},
|
|
1063
|
+
style: {},
|
|
1064
|
+
onUpdate: {},
|
|
1065
|
+
onComplete: {},
|
|
1066
|
+
text: {},
|
|
1067
|
+
speed: { default: 50 },
|
|
1068
|
+
delay: { default: 0 },
|
|
1069
|
+
enabled: { type: Boolean, default: true },
|
|
1070
|
+
threshold: { default: 0.2 },
|
|
1071
|
+
rootMargin: { default: "0px 0px -100px 0px" },
|
|
1072
|
+
triggerOnce: { type: Boolean, default: false },
|
|
1073
|
+
showCursor: { type: Boolean, default: true },
|
|
1074
|
+
cursorChar: { default: "|" }
|
|
1075
|
+
},
|
|
1076
|
+
setup(__props, { expose: __expose }) {
|
|
1077
|
+
const props = __props;
|
|
1078
|
+
const containerRef = ref(null);
|
|
1079
|
+
const instanceRef = ref(null);
|
|
1080
|
+
onMounted(() => {
|
|
1081
|
+
if (!containerRef.value) return;
|
|
1082
|
+
const options = {
|
|
1083
|
+
text: props.text,
|
|
1084
|
+
speed: props.speed,
|
|
1085
|
+
delay: props.delay,
|
|
1086
|
+
enabled: props.enabled,
|
|
1087
|
+
threshold: props.threshold,
|
|
1088
|
+
rootMargin: props.rootMargin,
|
|
1089
|
+
triggerOnce: props.triggerOnce,
|
|
1090
|
+
showCursor: props.showCursor,
|
|
1091
|
+
cursorChar: props.cursorChar,
|
|
1092
|
+
onUpdate: props.onUpdate,
|
|
1093
|
+
onComplete: props.onComplete
|
|
1094
|
+
};
|
|
1095
|
+
instanceRef.value = new Typing(containerRef.value, options);
|
|
1096
|
+
});
|
|
1097
|
+
onUnmounted(() => {
|
|
1098
|
+
if (instanceRef.value) {
|
|
1099
|
+
instanceRef.value.destroy();
|
|
1100
|
+
instanceRef.value = null;
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
watch(() => props.text, (newText) => {
|
|
1104
|
+
if (instanceRef.value && newText !== instanceRef.value["originalText"]) {
|
|
1105
|
+
instanceRef.value.setText(newText);
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
__expose({
|
|
1109
|
+
start: () => {
|
|
1110
|
+
var _a;
|
|
1111
|
+
return (_a = instanceRef.value) == null ? void 0 : _a.start();
|
|
1112
|
+
},
|
|
1113
|
+
stop: () => {
|
|
1114
|
+
var _a;
|
|
1115
|
+
return (_a = instanceRef.value) == null ? void 0 : _a.stop();
|
|
1116
|
+
},
|
|
1117
|
+
reset: () => {
|
|
1118
|
+
var _a;
|
|
1119
|
+
return (_a = instanceRef.value) == null ? void 0 : _a.reset();
|
|
1120
|
+
},
|
|
1121
|
+
setText: (text) => {
|
|
1122
|
+
var _a;
|
|
1123
|
+
return (_a = instanceRef.value) == null ? void 0 : _a.setText(text);
|
|
1124
|
+
},
|
|
1125
|
+
destroy: () => {
|
|
1126
|
+
if (instanceRef.value) {
|
|
1127
|
+
instanceRef.value.destroy();
|
|
1128
|
+
instanceRef.value = null;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
});
|
|
1132
|
+
return (_ctx, _cache) => {
|
|
1133
|
+
return openBlock(), createElementBlock("div", {
|
|
1134
|
+
ref_key: "containerRef",
|
|
1135
|
+
ref: containerRef,
|
|
1136
|
+
class: normalizeClass(__props.className),
|
|
1137
|
+
style: normalizeStyle(__props.style)
|
|
1138
|
+
}, null, 6);
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
834
1142
|
export {
|
|
835
|
-
_sfc_main as Count,
|
|
836
|
-
_sfc_main$
|
|
837
|
-
_sfc_main$
|
|
838
|
-
_sfc_main
|
|
1143
|
+
_sfc_main$1 as Count,
|
|
1144
|
+
_sfc_main$2 as MasonEffect,
|
|
1145
|
+
_sfc_main$2 as TextToParticle,
|
|
1146
|
+
_sfc_main as Typing,
|
|
1147
|
+
_sfc_main$2 as default
|
|
839
1148
|
};
|
|
@@ -160,4 +160,57 @@ declare class TextToParticle {
|
|
|
160
160
|
export { TextToParticleOptions as MasonEffectOptions }
|
|
161
161
|
export { TextToParticleOptions }
|
|
162
162
|
|
|
163
|
+
export declare class Typing {
|
|
164
|
+
container: HTMLElement;
|
|
165
|
+
config: Required<Omit<TypingOptions, 'onUpdate' | 'onComplete'>> & {
|
|
166
|
+
onUpdate: TypingOptions['onUpdate'];
|
|
167
|
+
onComplete: TypingOptions['onComplete'];
|
|
168
|
+
};
|
|
169
|
+
textUnits: string[];
|
|
170
|
+
charUnitRanges: Array<{
|
|
171
|
+
start: number;
|
|
172
|
+
end: number;
|
|
173
|
+
isHangul: boolean;
|
|
174
|
+
}>;
|
|
175
|
+
currentIndex: number;
|
|
176
|
+
displayedText: string;
|
|
177
|
+
timeoutId: ReturnType<typeof setTimeout> | null;
|
|
178
|
+
intersectionObserver: IntersectionObserver | null;
|
|
179
|
+
isRunning: boolean;
|
|
180
|
+
hasTriggered: boolean;
|
|
181
|
+
originalText: string;
|
|
182
|
+
constructor(container: HTMLElement | string, options: TypingOptions);
|
|
183
|
+
init(): void;
|
|
184
|
+
setupIntersectionObserver(): void;
|
|
185
|
+
private buildTextFromUnits;
|
|
186
|
+
start(): void;
|
|
187
|
+
typeNext(): void;
|
|
188
|
+
stop(): void;
|
|
189
|
+
reset(): void;
|
|
190
|
+
updateDisplay(text: string): void;
|
|
191
|
+
setText(newText: string): void;
|
|
192
|
+
destroy(): void;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Typing - 타이핑 애니메이션 효과
|
|
197
|
+
* 바닐라 JS 코어 클래스
|
|
198
|
+
*
|
|
199
|
+
* 사용법:
|
|
200
|
+
* import { Typing } from 'masoneffect/typing';
|
|
201
|
+
*/
|
|
202
|
+
export declare interface TypingOptions {
|
|
203
|
+
text: string;
|
|
204
|
+
speed?: number;
|
|
205
|
+
delay?: number;
|
|
206
|
+
enabled?: boolean;
|
|
207
|
+
threshold?: number;
|
|
208
|
+
rootMargin?: string;
|
|
209
|
+
triggerOnce?: boolean;
|
|
210
|
+
showCursor?: boolean;
|
|
211
|
+
cursorChar?: string;
|
|
212
|
+
onUpdate?: (text: string) => void;
|
|
213
|
+
onComplete?: () => void;
|
|
214
|
+
}
|
|
215
|
+
|
|
163
216
|
export { }
|