masoneffect 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/core/count/index.d.ts +3 -2
- package/dist/core/count/index.d.ts.map +1 -1
- package/dist/core/textToParticle/index.d.ts +3 -3
- package/dist/core/textToParticle/index.d.ts.map +1 -1
- package/dist/core/typing/index.d.ts +8 -6
- package/dist/core/typing/index.d.ts.map +1 -1
- package/dist/core/utils/visibilityManager.d.ts +35 -0
- package/dist/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/count/core/count/index.d.ts +3 -2
- package/dist/count/core/count/index.d.ts.map +1 -1
- package/dist/count/core/textToParticle/index.d.ts +3 -3
- package/dist/count/core/textToParticle/index.d.ts.map +1 -1
- package/dist/count/core/typing/index.d.ts +8 -6
- package/dist/count/core/typing/index.d.ts.map +1 -1
- package/dist/count/core/utils/visibilityManager.d.ts +35 -0
- package/dist/count/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/count/index.cjs +1 -1
- package/dist/count/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/react/core/count/index.d.ts +3 -2
- package/dist/react/core/textToParticle/index.d.ts +3 -3
- package/dist/react/core/typing/index.d.ts +8 -6
- package/dist/react/core/utils/visibilityManager.d.ts +34 -0
- package/dist/react/count/core/count/index.d.ts +3 -2
- package/dist/react/count/core/count/index.d.ts.map +1 -1
- package/dist/react/count/core/textToParticle/index.d.ts +3 -3
- package/dist/react/count/core/textToParticle/index.d.ts.map +1 -1
- package/dist/react/count/core/typing/index.d.ts +8 -6
- package/dist/react/count/core/typing/index.d.ts.map +1 -1
- package/dist/react/count/core/utils/visibilityManager.d.ts +35 -0
- package/dist/react/count/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/react/count/index.cjs +1 -1
- package/dist/react/count/index.mjs +1 -1
- package/dist/react/textToParticle/core/count/index.d.ts +3 -2
- package/dist/react/textToParticle/core/count/index.d.ts.map +1 -1
- package/dist/react/textToParticle/core/textToParticle/index.d.ts +3 -3
- package/dist/react/textToParticle/core/textToParticle/index.d.ts.map +1 -1
- package/dist/react/textToParticle/core/typing/index.d.ts +8 -6
- package/dist/react/textToParticle/core/typing/index.d.ts.map +1 -1
- package/dist/react/textToParticle/core/utils/visibilityManager.d.ts +35 -0
- package/dist/react/textToParticle/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/react/textToParticle/index.cjs +1 -1
- package/dist/react/textToParticle/index.mjs +1 -1
- package/dist/react/typing/core/count/index.d.ts +3 -2
- package/dist/react/typing/core/count/index.d.ts.map +1 -1
- package/dist/react/typing/core/textToParticle/index.d.ts +3 -3
- package/dist/react/typing/core/textToParticle/index.d.ts.map +1 -1
- package/dist/react/typing/core/typing/index.d.ts +8 -6
- package/dist/react/typing/core/typing/index.d.ts.map +1 -1
- package/dist/react/typing/core/utils/visibilityManager.d.ts +35 -0
- package/dist/react/typing/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/react/typing/index.cjs +1 -1
- package/dist/react/typing/index.mjs +1 -1
- package/dist/svelte/count/index.cjs +1 -1
- package/dist/svelte/count/index.d.ts +46 -32
- package/dist/svelte/count/index.mjs +120 -42
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.d.ts +46 -32
- package/dist/svelte/index.mjs +211 -160
- package/dist/svelte/textToParticle/index.cjs +1 -1
- package/dist/svelte/textToParticle/index.d.ts +46 -32
- package/dist/svelte/textToParticle/index.mjs +119 -33
- package/dist/svelte/typing/index.cjs +1 -1
- package/dist/svelte/typing/index.d.ts +46 -32
- package/dist/svelte/typing/index.mjs +174 -85
- package/dist/textToParticle/core/count/index.d.ts +3 -2
- package/dist/textToParticle/core/count/index.d.ts.map +1 -1
- package/dist/textToParticle/core/textToParticle/index.d.ts +3 -3
- package/dist/textToParticle/core/textToParticle/index.d.ts.map +1 -1
- package/dist/textToParticle/core/typing/index.d.ts +8 -6
- package/dist/textToParticle/core/typing/index.d.ts.map +1 -1
- package/dist/textToParticle/core/utils/visibilityManager.d.ts +35 -0
- package/dist/textToParticle/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/textToParticle/index.cjs +1 -1
- package/dist/textToParticle/index.mjs +1 -1
- package/dist/typing/core/count/index.d.ts +3 -2
- package/dist/typing/core/count/index.d.ts.map +1 -1
- package/dist/typing/core/textToParticle/index.d.ts +3 -3
- package/dist/typing/core/textToParticle/index.d.ts.map +1 -1
- package/dist/typing/core/typing/index.d.ts +8 -6
- package/dist/typing/core/typing/index.d.ts.map +1 -1
- package/dist/typing/core/utils/visibilityManager.d.ts +35 -0
- package/dist/typing/core/utils/visibilityManager.d.ts.map +1 -0
- package/dist/typing/index.cjs +1 -1
- package/dist/typing/index.mjs +1 -1
- package/dist/vue/count/index.cjs +1 -1
- package/dist/vue/count/index.d.ts +46 -32
- package/dist/vue/count/index.mjs +119 -41
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.d.ts +46 -32
- package/dist/vue/index.mjs +209 -158
- package/dist/vue/textToParticle/index.cjs +1 -1
- package/dist/vue/textToParticle/index.d.ts +46 -32
- package/dist/vue/textToParticle/index.mjs +119 -33
- package/dist/vue/typing/index.cjs +1 -1
- package/dist/vue/typing/index.d.ts +46 -32
- package/dist/vue/typing/index.mjs +173 -84
- package/package.json +1 -1
|
@@ -1,4 +1,105 @@
|
|
|
1
1
|
import { defineComponent, ref, onMounted, onUnmounted, watch, createElementBlock, openBlock, normalizeStyle, normalizeClass } from "vue";
|
|
2
|
+
class VisibilityManager {
|
|
3
|
+
constructor(container, options = {}) {
|
|
4
|
+
this.container = container;
|
|
5
|
+
this.options = {
|
|
6
|
+
threshold: options.threshold ?? 0.1,
|
|
7
|
+
rootMargin: options.rootMargin ?? "0px",
|
|
8
|
+
onVisible: options.onVisible,
|
|
9
|
+
onHidden: options.onHidden
|
|
10
|
+
};
|
|
11
|
+
this.intersectionObserver = null;
|
|
12
|
+
this.visibilityChangeHandler = null;
|
|
13
|
+
this.isVisible = false;
|
|
14
|
+
this.isPageVisible = typeof document !== "undefined" ? !document.hidden : true;
|
|
15
|
+
this.setupIntersectionObserver();
|
|
16
|
+
this.setupPageVisibility();
|
|
17
|
+
}
|
|
18
|
+
setupIntersectionObserver() {
|
|
19
|
+
if (typeof window === "undefined" || typeof window.IntersectionObserver === "undefined") {
|
|
20
|
+
this.isVisible = true;
|
|
21
|
+
if (this.isPageVisible && this.options.onVisible) {
|
|
22
|
+
this.options.onVisible();
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this.intersectionObserver = new IntersectionObserver(
|
|
27
|
+
(entries) => {
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
if (entry.target !== this.container) continue;
|
|
30
|
+
if (entry.isIntersecting) {
|
|
31
|
+
this.isVisible = true;
|
|
32
|
+
if (this.isPageVisible && this.options.onVisible) {
|
|
33
|
+
this.options.onVisible();
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
this.isVisible = false;
|
|
37
|
+
if (this.options.onHidden) {
|
|
38
|
+
this.options.onHidden();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
threshold: this.options.threshold,
|
|
45
|
+
rootMargin: this.options.rootMargin
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
this.intersectionObserver.observe(this.container);
|
|
49
|
+
}
|
|
50
|
+
setupPageVisibility() {
|
|
51
|
+
if (typeof document === "undefined") return;
|
|
52
|
+
this.visibilityChangeHandler = () => {
|
|
53
|
+
const wasVisible = this.isPageVisible;
|
|
54
|
+
this.isPageVisible = !document.hidden;
|
|
55
|
+
if (document.hidden) {
|
|
56
|
+
if (this.options.onHidden) {
|
|
57
|
+
this.options.onHidden();
|
|
58
|
+
}
|
|
59
|
+
} else if (wasVisible !== this.isPageVisible) {
|
|
60
|
+
if (this.isVisible && this.options.onVisible) {
|
|
61
|
+
this.options.onVisible();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
document.addEventListener("visibilitychange", this.visibilityChangeHandler);
|
|
66
|
+
if (document.hidden && this.isVisible) {
|
|
67
|
+
if (this.options.onHidden) {
|
|
68
|
+
this.options.onHidden();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 현재 요소가 화면에 보이는지 확인
|
|
74
|
+
*/
|
|
75
|
+
getIsVisible() {
|
|
76
|
+
return this.isVisible && this.isPageVisible;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 옵션 업데이트
|
|
80
|
+
*/
|
|
81
|
+
updateOptions(newOptions) {
|
|
82
|
+
this.options = { ...this.options, ...newOptions };
|
|
83
|
+
if (this.intersectionObserver) {
|
|
84
|
+
this.intersectionObserver.disconnect();
|
|
85
|
+
this.intersectionObserver = null;
|
|
86
|
+
}
|
|
87
|
+
this.setupIntersectionObserver();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 리소스 정리
|
|
91
|
+
*/
|
|
92
|
+
destroy() {
|
|
93
|
+
if (this.intersectionObserver) {
|
|
94
|
+
this.intersectionObserver.disconnect();
|
|
95
|
+
this.intersectionObserver = null;
|
|
96
|
+
}
|
|
97
|
+
if (this.visibilityChangeHandler && typeof document !== "undefined") {
|
|
98
|
+
document.removeEventListener("visibilitychange", this.visibilityChangeHandler);
|
|
99
|
+
this.visibilityChangeHandler = null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
2
103
|
function decomposeHangul(char) {
|
|
3
104
|
const code = char.charCodeAt(0);
|
|
4
105
|
if (code < 44032 || code > 55203) {
|
|
@@ -19,25 +120,48 @@ function decomposeHangul(char) {
|
|
|
19
120
|
}
|
|
20
121
|
return result;
|
|
21
122
|
}
|
|
123
|
+
function composeHangul(initial, medial, final) {
|
|
124
|
+
const initialChars = ["ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
|
|
125
|
+
const medialChars = ["ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ"];
|
|
126
|
+
const finalChars = ["", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
|
|
127
|
+
const initialIndex = initialChars.indexOf(initial);
|
|
128
|
+
const medialIndex = medialChars.indexOf(medial);
|
|
129
|
+
const finalIndex = final ? finalChars.indexOf(final) : 0;
|
|
130
|
+
if (initialIndex === -1 || medialIndex === -1) {
|
|
131
|
+
return initial + (medial || "") + (final || "");
|
|
132
|
+
}
|
|
133
|
+
const code = 44032 + initialIndex * 21 * 28 + medialIndex * 28 + finalIndex;
|
|
134
|
+
return String.fromCharCode(code);
|
|
135
|
+
}
|
|
22
136
|
function decomposeText(text) {
|
|
23
137
|
const units = [];
|
|
138
|
+
const charUnitRanges = [];
|
|
24
139
|
for (let i = 0; i < text.length; i++) {
|
|
25
140
|
const char = text[i];
|
|
26
141
|
const code = char.charCodeAt(0);
|
|
142
|
+
const startIndex = units.length;
|
|
27
143
|
if (code >= 44032 && code <= 55203) {
|
|
28
144
|
const decomposed = decomposeHangul(char);
|
|
29
145
|
units.push(...decomposed);
|
|
146
|
+
charUnitRanges.push({
|
|
147
|
+
start: startIndex,
|
|
148
|
+
end: units.length,
|
|
149
|
+
isHangul: true
|
|
150
|
+
});
|
|
30
151
|
} else {
|
|
31
152
|
units.push(char);
|
|
153
|
+
charUnitRanges.push({
|
|
154
|
+
start: startIndex,
|
|
155
|
+
end: units.length,
|
|
156
|
+
isHangul: false
|
|
157
|
+
});
|
|
32
158
|
}
|
|
33
159
|
}
|
|
34
|
-
return units;
|
|
160
|
+
return { units, charUnitRanges };
|
|
35
161
|
}
|
|
36
162
|
class Typing {
|
|
37
163
|
// 원본 텍스트
|
|
38
164
|
constructor(container, options) {
|
|
39
|
-
this.originalChars = [];
|
|
40
|
-
this.charUnitMap = [];
|
|
41
165
|
this.container = typeof container === "string" ? document.querySelector(container) : container;
|
|
42
166
|
if (!this.container) {
|
|
43
167
|
throw new Error("Container element not found");
|
|
@@ -56,100 +180,65 @@ class Typing {
|
|
|
56
180
|
onUpdate: options.onUpdate || null,
|
|
57
181
|
onComplete: options.onComplete || null
|
|
58
182
|
};
|
|
59
|
-
|
|
60
|
-
this.
|
|
61
|
-
this.
|
|
62
|
-
this.initializeTextStructure();
|
|
183
|
+
const decomposed = decomposeText(this.config.text);
|
|
184
|
+
this.textUnits = decomposed.units;
|
|
185
|
+
this.charUnitRanges = decomposed.charUnitRanges;
|
|
63
186
|
this.currentIndex = 0;
|
|
64
187
|
this.displayedText = "";
|
|
65
188
|
this.timeoutId = null;
|
|
66
|
-
this.
|
|
189
|
+
this.visibilityManager = null;
|
|
67
190
|
this.isRunning = false;
|
|
68
191
|
this.hasTriggered = false;
|
|
69
192
|
this.init();
|
|
70
193
|
}
|
|
71
194
|
init() {
|
|
72
195
|
this.updateDisplay("");
|
|
73
|
-
this.
|
|
196
|
+
this.setupVisibilityManager();
|
|
74
197
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
(entries) => {
|
|
84
|
-
var _a;
|
|
85
|
-
for (const entry of entries) {
|
|
86
|
-
if (entry.target !== this.container) continue;
|
|
87
|
-
if (entry.isIntersecting && !this.hasTriggered) {
|
|
88
|
-
if (this.config.enabled) {
|
|
89
|
-
setTimeout(() => this.start(), this.config.delay);
|
|
90
|
-
}
|
|
91
|
-
this.hasTriggered = true;
|
|
92
|
-
if (this.config.triggerOnce) {
|
|
93
|
-
(_a = this.intersectionObserver) == null ? void 0 : _a.disconnect();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
198
|
+
setupVisibilityManager() {
|
|
199
|
+
this.visibilityManager = new VisibilityManager(this.container, {
|
|
200
|
+
threshold: this.config.threshold,
|
|
201
|
+
rootMargin: this.config.rootMargin,
|
|
202
|
+
onVisible: () => {
|
|
203
|
+
if (!this.hasTriggered && this.config.enabled) {
|
|
204
|
+
this.hasTriggered = true;
|
|
205
|
+
setTimeout(() => this.start(), this.config.delay);
|
|
96
206
|
}
|
|
97
207
|
},
|
|
98
|
-
{
|
|
99
|
-
threshold: this.config.threshold,
|
|
100
|
-
rootMargin: this.config.rootMargin
|
|
208
|
+
onHidden: () => {
|
|
101
209
|
}
|
|
102
|
-
);
|
|
103
|
-
this.intersectionObserver.observe(this.container);
|
|
210
|
+
});
|
|
104
211
|
}
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const decomposed = decomposeHangul(char);
|
|
115
|
-
this.charUnitMap.push(decomposed.length);
|
|
116
|
-
} else {
|
|
117
|
-
this.charUnitMap.push(1);
|
|
212
|
+
// 단위들을 다시 합쳐서 실제 표시할 텍스트 생성
|
|
213
|
+
// 한글의 경우 자음/모음이 하나씩 보이도록 합성
|
|
214
|
+
buildTextFromUnits(unitCount) {
|
|
215
|
+
if (unitCount === 0) return "";
|
|
216
|
+
let result = "";
|
|
217
|
+
for (let charIndex = 0; charIndex < this.charUnitRanges.length; charIndex++) {
|
|
218
|
+
const range = this.charUnitRanges[charIndex];
|
|
219
|
+
if (range.start >= unitCount) {
|
|
220
|
+
break;
|
|
118
221
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
charIndex = i + 1;
|
|
222
|
+
const unitsEntered = Math.min(unitCount - range.start, range.end - range.start);
|
|
223
|
+
if (unitsEntered <= 0) {
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
if (range.isHangul) {
|
|
227
|
+
const charUnits = this.textUnits.slice(range.start, range.start + unitsEntered);
|
|
228
|
+
if (charUnits.length === 1) {
|
|
229
|
+
result += charUnits[0];
|
|
230
|
+
} else if (charUnits.length === 2) {
|
|
231
|
+
result += composeHangul(charUnits[0], charUnits[1]);
|
|
232
|
+
} else if (charUnits.length >= 3) {
|
|
233
|
+
result += composeHangul(charUnits[0], charUnits[1], charUnits[2]);
|
|
234
|
+
}
|
|
133
235
|
} else {
|
|
134
|
-
const unitsEntered = unitIndex - (currentUnits - unitsForChar);
|
|
135
236
|
if (unitsEntered > 0) {
|
|
136
|
-
|
|
137
|
-
if (isHangul && unitsEntered >= 2) {
|
|
138
|
-
charIndex = i + 1;
|
|
139
|
-
} else if (!isHangul && unitsEntered >= 1) {
|
|
140
|
-
charIndex = i + 1;
|
|
141
|
-
}
|
|
237
|
+
result += this.textUnits[range.start];
|
|
142
238
|
}
|
|
143
|
-
break;
|
|
144
239
|
}
|
|
145
240
|
}
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
// 단위들을 다시 합쳐서 실제 표시할 텍스트 생성
|
|
149
|
-
buildTextFromUnits(units) {
|
|
150
|
-
if (units.length === 0) return "";
|
|
151
|
-
const charIndex = this.getCharIndexFromUnitIndex(units.length);
|
|
152
|
-
return this.originalText.substring(0, charIndex);
|
|
241
|
+
return result;
|
|
153
242
|
}
|
|
154
243
|
start() {
|
|
155
244
|
if (this.isRunning) return;
|
|
@@ -169,8 +258,7 @@ class Typing {
|
|
|
169
258
|
}
|
|
170
259
|
return;
|
|
171
260
|
}
|
|
172
|
-
|
|
173
|
-
this.displayedText = this.buildTextFromUnits(unitsToShow);
|
|
261
|
+
this.displayedText = this.buildTextFromUnits(this.currentIndex + 1);
|
|
174
262
|
let displayText = this.displayedText;
|
|
175
263
|
if (this.config.showCursor) {
|
|
176
264
|
displayText += this.config.cursorChar;
|
|
@@ -205,8 +293,9 @@ class Typing {
|
|
|
205
293
|
setText(newText) {
|
|
206
294
|
this.originalText = newText;
|
|
207
295
|
this.config.text = newText;
|
|
208
|
-
|
|
209
|
-
this.
|
|
296
|
+
const decomposed = decomposeText(newText);
|
|
297
|
+
this.textUnits = decomposed.units;
|
|
298
|
+
this.charUnitRanges = decomposed.charUnitRanges;
|
|
210
299
|
this.reset();
|
|
211
300
|
if (this.config.enabled) {
|
|
212
301
|
setTimeout(() => this.start(), this.config.delay);
|
|
@@ -214,9 +303,9 @@ class Typing {
|
|
|
214
303
|
}
|
|
215
304
|
destroy() {
|
|
216
305
|
this.stop();
|
|
217
|
-
if (this.
|
|
218
|
-
this.
|
|
219
|
-
this.
|
|
306
|
+
if (this.visibilityManager) {
|
|
307
|
+
this.visibilityManager.destroy();
|
|
308
|
+
this.visibilityManager = null;
|
|
220
309
|
}
|
|
221
310
|
}
|
|
222
311
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "masoneffect",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "A collection of animation effects library. Supports React, Vue, Svelte, and vanilla JavaScript with Tree-shaking support.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|