masoneffect 1.0.29 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/README.md +320 -231
  2. package/dist/core/count/index.d.ts +52 -0
  3. package/dist/core/count/index.d.ts.map +1 -0
  4. package/dist/core/index.d.ts +15 -97
  5. package/dist/core/index.d.ts.map +1 -1
  6. package/dist/core/textToParticle/index.d.ts +103 -0
  7. package/dist/core/textToParticle/index.d.ts.map +1 -0
  8. package/dist/count/core/count/index.d.ts +52 -0
  9. package/dist/count/core/count/index.d.ts.map +1 -0
  10. package/dist/count/core/index.d.ts +18 -0
  11. package/dist/count/core/index.d.ts.map +1 -0
  12. package/dist/count/core/textToParticle/index.d.ts +103 -0
  13. package/dist/count/core/textToParticle/index.d.ts.map +1 -0
  14. package/dist/count/index.cjs +1 -0
  15. package/dist/count/index.d.ts +16 -0
  16. package/dist/count/index.d.ts.map +1 -0
  17. package/dist/count/index.mjs +1 -0
  18. package/dist/count/index.umd.d.ts +7 -0
  19. package/dist/count/index.umd.d.ts.map +1 -0
  20. package/dist/count/react/MasonEffect.d.ts +32 -0
  21. package/dist/count/react/MasonEffect.d.ts.map +1 -0
  22. package/dist/count/react/count/Count.d.ts +19 -0
  23. package/dist/count/react/count/Count.d.ts.map +1 -0
  24. package/dist/count/react/count/index.d.ts +5 -0
  25. package/dist/count/react/count/index.d.ts.map +1 -0
  26. package/dist/count/react/index.d.ts +12 -0
  27. package/dist/count/react/index.d.ts.map +1 -0
  28. package/dist/count/react/textToParticle/TextToParticle.d.ts +15 -0
  29. package/dist/count/react/textToParticle/TextToParticle.d.ts.map +1 -0
  30. package/dist/count/react/textToParticle/index.d.ts +4 -0
  31. package/dist/count/react/textToParticle/index.d.ts.map +1 -0
  32. package/dist/count/svelte/count/index.d.ts +2 -0
  33. package/dist/count/svelte/count/index.d.ts.map +1 -0
  34. package/dist/count/svelte/index.d.ts +8 -0
  35. package/dist/count/svelte/index.d.ts.map +1 -0
  36. package/dist/count/svelte/textToParticle/index.d.ts +2 -0
  37. package/dist/count/svelte/textToParticle/index.d.ts.map +1 -0
  38. package/dist/count/vue/count/index.d.ts +2 -0
  39. package/dist/count/vue/count/index.d.ts.map +1 -0
  40. package/dist/count/vue/index.d.ts +8 -0
  41. package/dist/count/vue/index.d.ts.map +1 -0
  42. package/dist/count/vue/textToParticle/index.d.ts +2 -0
  43. package/dist/count/vue/textToParticle/index.d.ts.map +1 -0
  44. package/dist/index.cjs +1 -1
  45. package/dist/index.d.ts +12 -4
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.mjs +1 -1
  48. package/dist/index.umd.min.js +1 -1
  49. package/dist/react/MasonEffect.cjs +1 -1
  50. package/dist/react/MasonEffect.mjs +1 -1
  51. package/dist/react/core/count/index.d.ts +51 -0
  52. package/dist/react/core/index.d.ts +15 -97
  53. package/dist/react/core/textToParticle/index.d.ts +102 -0
  54. package/dist/react/count/Count.d.ts +19 -0
  55. package/dist/react/count/Count.d.ts.map +1 -0
  56. package/dist/react/count/core/count/index.d.ts +52 -0
  57. package/dist/react/count/core/count/index.d.ts.map +1 -0
  58. package/dist/react/count/core/index.d.ts +18 -0
  59. package/dist/react/count/core/index.d.ts.map +1 -0
  60. package/dist/react/count/core/textToParticle/index.d.ts +103 -0
  61. package/dist/react/count/core/textToParticle/index.d.ts.map +1 -0
  62. package/dist/react/count/index.cjs +1 -0
  63. package/dist/react/count/index.d.ts +16 -0
  64. package/dist/react/count/index.d.ts.map +1 -0
  65. package/dist/react/count/index.mjs +1 -0
  66. package/dist/react/count/index.umd.d.ts +7 -0
  67. package/dist/react/count/index.umd.d.ts.map +1 -0
  68. package/dist/react/count/react/MasonEffect.d.ts +32 -0
  69. package/dist/react/count/react/MasonEffect.d.ts.map +1 -0
  70. package/dist/react/count/react/count/Count.d.ts +19 -0
  71. package/dist/react/count/react/count/Count.d.ts.map +1 -0
  72. package/dist/react/count/react/count/index.d.ts +5 -0
  73. package/dist/react/count/react/count/index.d.ts.map +1 -0
  74. package/dist/react/count/react/index.d.ts +12 -0
  75. package/dist/react/count/react/index.d.ts.map +1 -0
  76. package/dist/react/count/react/textToParticle/TextToParticle.d.ts +15 -0
  77. package/dist/react/count/react/textToParticle/TextToParticle.d.ts.map +1 -0
  78. package/dist/react/count/react/textToParticle/index.d.ts +4 -0
  79. package/dist/react/count/react/textToParticle/index.d.ts.map +1 -0
  80. package/dist/react/count/svelte/count/index.d.ts +2 -0
  81. package/dist/react/count/svelte/count/index.d.ts.map +1 -0
  82. package/dist/react/count/svelte/index.d.ts +8 -0
  83. package/dist/react/count/svelte/index.d.ts.map +1 -0
  84. package/dist/react/count/svelte/textToParticle/index.d.ts +2 -0
  85. package/dist/react/count/svelte/textToParticle/index.d.ts.map +1 -0
  86. package/dist/react/count/vue/count/index.d.ts +2 -0
  87. package/dist/react/count/vue/count/index.d.ts.map +1 -0
  88. package/dist/react/count/vue/index.d.ts +8 -0
  89. package/dist/react/count/vue/index.d.ts.map +1 -0
  90. package/dist/react/count/vue/textToParticle/index.d.ts +2 -0
  91. package/dist/react/count/vue/textToParticle/index.d.ts.map +1 -0
  92. package/dist/react/index.cjs +12 -2
  93. package/dist/react/index.d.ts.map +1 -1
  94. package/dist/react/index.mjs +2 -1
  95. package/dist/react/react/count/Count.d.ts +18 -0
  96. package/dist/react/react/count/index.d.ts +4 -0
  97. package/dist/react/react/index.d.ts +11 -2
  98. package/dist/react/react/textToParticle/TextToParticle.d.ts +14 -0
  99. package/dist/react/react/textToParticle/index.d.ts +3 -0
  100. package/dist/react/svelte/count/index.d.ts +1 -0
  101. package/dist/react/svelte/index.d.ts +5 -3
  102. package/dist/react/svelte/textToParticle/index.d.ts +1 -0
  103. package/dist/react/textToParticle/TextToParticle.d.ts +15 -0
  104. package/dist/react/textToParticle/TextToParticle.d.ts.map +1 -0
  105. package/dist/react/textToParticle/core/count/index.d.ts +52 -0
  106. package/dist/react/textToParticle/core/count/index.d.ts.map +1 -0
  107. package/dist/react/textToParticle/core/index.d.ts +18 -0
  108. package/dist/react/textToParticle/core/index.d.ts.map +1 -0
  109. package/dist/react/textToParticle/core/textToParticle/index.d.ts +103 -0
  110. package/dist/react/textToParticle/core/textToParticle/index.d.ts.map +1 -0
  111. package/dist/react/textToParticle/index.cjs +1 -0
  112. package/dist/react/textToParticle/index.d.ts +16 -0
  113. package/dist/react/textToParticle/index.d.ts.map +1 -0
  114. package/dist/react/textToParticle/index.mjs +1 -0
  115. package/dist/react/textToParticle/index.umd.d.ts +7 -0
  116. package/dist/react/textToParticle/index.umd.d.ts.map +1 -0
  117. package/dist/react/textToParticle/react/MasonEffect.d.ts +32 -0
  118. package/dist/react/textToParticle/react/MasonEffect.d.ts.map +1 -0
  119. package/dist/react/textToParticle/react/count/Count.d.ts +19 -0
  120. package/dist/react/textToParticle/react/count/Count.d.ts.map +1 -0
  121. package/dist/react/textToParticle/react/count/index.d.ts +5 -0
  122. package/dist/react/textToParticle/react/count/index.d.ts.map +1 -0
  123. package/dist/react/textToParticle/react/index.d.ts +12 -0
  124. package/dist/react/textToParticle/react/index.d.ts.map +1 -0
  125. package/dist/react/textToParticle/react/textToParticle/TextToParticle.d.ts +15 -0
  126. package/dist/react/textToParticle/react/textToParticle/TextToParticle.d.ts.map +1 -0
  127. package/dist/react/textToParticle/react/textToParticle/index.d.ts +4 -0
  128. package/dist/react/textToParticle/react/textToParticle/index.d.ts.map +1 -0
  129. package/dist/react/textToParticle/svelte/count/index.d.ts +2 -0
  130. package/dist/react/textToParticle/svelte/count/index.d.ts.map +1 -0
  131. package/dist/react/textToParticle/svelte/index.d.ts +8 -0
  132. package/dist/react/textToParticle/svelte/index.d.ts.map +1 -0
  133. package/dist/react/textToParticle/svelte/textToParticle/index.d.ts +2 -0
  134. package/dist/react/textToParticle/svelte/textToParticle/index.d.ts.map +1 -0
  135. package/dist/react/textToParticle/vue/count/index.d.ts +2 -0
  136. package/dist/react/textToParticle/vue/count/index.d.ts.map +1 -0
  137. package/dist/react/textToParticle/vue/index.d.ts +8 -0
  138. package/dist/react/textToParticle/vue/index.d.ts.map +1 -0
  139. package/dist/react/textToParticle/vue/textToParticle/index.d.ts +2 -0
  140. package/dist/react/textToParticle/vue/textToParticle/index.d.ts.map +1 -0
  141. package/dist/react/vue/count/index.d.ts +1 -0
  142. package/dist/react/vue/index.d.ts +5 -3
  143. package/dist/react/vue/textToParticle/index.d.ts +1 -0
  144. package/dist/svelte/count/index.cjs +1 -0
  145. package/dist/svelte/count/index.d.ts +163 -0
  146. package/dist/svelte/count/index.mjs +659 -0
  147. package/dist/svelte/index.cjs +1 -1
  148. package/dist/svelte/index.d.ts +88 -29
  149. package/dist/svelte/index.mjs +404 -10
  150. package/dist/svelte/textToParticle/index.cjs +1 -0
  151. package/dist/svelte/textToParticle/index.d.ts +163 -0
  152. package/dist/svelte/textToParticle/index.mjs +924 -0
  153. package/dist/textToParticle/core/count/index.d.ts +52 -0
  154. package/dist/textToParticle/core/count/index.d.ts.map +1 -0
  155. package/dist/textToParticle/core/index.d.ts +18 -0
  156. package/dist/textToParticle/core/index.d.ts.map +1 -0
  157. package/dist/textToParticle/core/textToParticle/index.d.ts +103 -0
  158. package/dist/textToParticle/core/textToParticle/index.d.ts.map +1 -0
  159. package/dist/textToParticle/index.cjs +1 -0
  160. package/dist/textToParticle/index.d.ts +16 -0
  161. package/dist/textToParticle/index.d.ts.map +1 -0
  162. package/dist/textToParticle/index.mjs +1 -0
  163. package/dist/textToParticle/index.umd.d.ts +7 -0
  164. package/dist/textToParticle/index.umd.d.ts.map +1 -0
  165. package/dist/textToParticle/react/MasonEffect.d.ts +32 -0
  166. package/dist/textToParticle/react/MasonEffect.d.ts.map +1 -0
  167. package/dist/textToParticle/react/count/Count.d.ts +19 -0
  168. package/dist/textToParticle/react/count/Count.d.ts.map +1 -0
  169. package/dist/textToParticle/react/count/index.d.ts +5 -0
  170. package/dist/textToParticle/react/count/index.d.ts.map +1 -0
  171. package/dist/textToParticle/react/index.d.ts +12 -0
  172. package/dist/textToParticle/react/index.d.ts.map +1 -0
  173. package/dist/textToParticle/react/textToParticle/TextToParticle.d.ts +15 -0
  174. package/dist/textToParticle/react/textToParticle/TextToParticle.d.ts.map +1 -0
  175. package/dist/textToParticle/react/textToParticle/index.d.ts +4 -0
  176. package/dist/textToParticle/react/textToParticle/index.d.ts.map +1 -0
  177. package/dist/textToParticle/svelte/count/index.d.ts +2 -0
  178. package/dist/textToParticle/svelte/count/index.d.ts.map +1 -0
  179. package/dist/textToParticle/svelte/index.d.ts +8 -0
  180. package/dist/textToParticle/svelte/index.d.ts.map +1 -0
  181. package/dist/textToParticle/svelte/textToParticle/index.d.ts +2 -0
  182. package/dist/textToParticle/svelte/textToParticle/index.d.ts.map +1 -0
  183. package/dist/textToParticle/vue/count/index.d.ts +2 -0
  184. package/dist/textToParticle/vue/count/index.d.ts.map +1 -0
  185. package/dist/textToParticle/vue/index.d.ts +8 -0
  186. package/dist/textToParticle/vue/index.d.ts.map +1 -0
  187. package/dist/textToParticle/vue/textToParticle/index.d.ts +2 -0
  188. package/dist/textToParticle/vue/textToParticle/index.d.ts.map +1 -0
  189. package/dist/vue/count/index.cjs +1 -0
  190. package/dist/vue/count/index.d.ts +163 -0
  191. package/dist/vue/count/index.mjs +286 -0
  192. package/dist/vue/index.cjs +1 -1
  193. package/dist/vue/index.d.ts +88 -29
  194. package/dist/vue/index.mjs +293 -8
  195. package/dist/vue/textToParticle/index.cjs +1 -0
  196. package/dist/vue/textToParticle/index.d.ts +163 -0
  197. package/dist/vue/textToParticle/index.mjs +554 -0
  198. package/package.json +54 -5
@@ -0,0 +1,286 @@
1
+ import { defineComponent, ref, watch, onMounted, onBeforeUnmount, createElementBlock, openBlock, normalizeStyle, normalizeClass } from "vue";
2
+ const easingFunctions = {
3
+ linear: (t) => t
4
+ };
5
+ class Count {
6
+ constructor(container, options) {
7
+ this.container = typeof container === "string" ? document.querySelector(container) : container;
8
+ if (!this.container) {
9
+ throw new Error("Container element not found");
10
+ }
11
+ this.config = {
12
+ targetValue: options.targetValue,
13
+ duration: options.duration ?? 2e3,
14
+ startValue: options.startValue ?? 0,
15
+ enabled: options.enabled ?? true,
16
+ easing: options.easing ?? easingFunctions.linear,
17
+ threshold: options.threshold ?? 0.2,
18
+ rootMargin: options.rootMargin ?? "0px 0px -100px 0px",
19
+ triggerOnce: options.triggerOnce ?? false,
20
+ onUpdate: options.onUpdate || null,
21
+ onComplete: options.onComplete || null
22
+ };
23
+ this.currentValue = this.config.startValue;
24
+ this.startTime = null;
25
+ this.animationFrameId = null;
26
+ this.intersectionObserver = null;
27
+ this.isRunning = false;
28
+ this.hasTriggered = false;
29
+ this.init();
30
+ }
31
+ init() {
32
+ this.updateDisplay(this.config.startValue);
33
+ this.setupIntersectionObserver();
34
+ }
35
+ setupIntersectionObserver() {
36
+ if (typeof window === "undefined" || typeof window.IntersectionObserver === "undefined") {
37
+ if (this.config.enabled) {
38
+ this.start();
39
+ }
40
+ return;
41
+ }
42
+ this.intersectionObserver = new IntersectionObserver(
43
+ (entries) => {
44
+ var _a;
45
+ for (const entry of entries) {
46
+ if (entry.target !== this.container) continue;
47
+ if (entry.isIntersecting) {
48
+ if (!this.hasTriggered && this.config.enabled) {
49
+ this.hasTriggered = true;
50
+ this.start();
51
+ }
52
+ if (this.config.triggerOnce) {
53
+ (_a = this.intersectionObserver) == null ? void 0 : _a.unobserve(this.container);
54
+ }
55
+ } else {
56
+ if (!this.config.triggerOnce) {
57
+ const rect = entry.boundingClientRect;
58
+ const viewportHeight = window.innerHeight;
59
+ const viewportWidth = window.innerWidth;
60
+ const isCompletelyOutOfViewport = rect.bottom <= 0 || rect.top >= viewportHeight || rect.right <= 0 || rect.left >= viewportWidth;
61
+ if (isCompletelyOutOfViewport && this.isRunning) {
62
+ this.reset();
63
+ }
64
+ }
65
+ }
66
+ }
67
+ },
68
+ {
69
+ threshold: this.config.threshold,
70
+ rootMargin: this.config.rootMargin
71
+ }
72
+ );
73
+ this.intersectionObserver.observe(this.container);
74
+ }
75
+ start() {
76
+ if (this.isRunning) return;
77
+ if (!this.config.enabled) return;
78
+ this.isRunning = true;
79
+ this.startTime = null;
80
+ this.currentValue = this.config.startValue;
81
+ this.updateDisplay(this.currentValue);
82
+ const animate = (currentTime) => {
83
+ if (this.startTime === null) {
84
+ this.startTime = currentTime;
85
+ }
86
+ const elapsed = currentTime - this.startTime;
87
+ const progress = Math.min(elapsed / this.config.duration, 1);
88
+ const easedProgress = this.config.easing(progress);
89
+ this.currentValue = Math.floor(
90
+ this.config.startValue + (this.config.targetValue - this.config.startValue) * easedProgress
91
+ );
92
+ this.updateDisplay(this.currentValue);
93
+ if (this.config.onUpdate) {
94
+ this.config.onUpdate(this.currentValue);
95
+ }
96
+ if (progress < 1) {
97
+ this.animationFrameId = requestAnimationFrame(animate);
98
+ } else {
99
+ this.currentValue = this.config.targetValue;
100
+ this.updateDisplay(this.currentValue);
101
+ this.isRunning = false;
102
+ if (this.config.onComplete) {
103
+ this.config.onComplete();
104
+ }
105
+ }
106
+ };
107
+ this.animationFrameId = requestAnimationFrame(animate);
108
+ }
109
+ stop() {
110
+ this.isRunning = false;
111
+ if (this.animationFrameId !== null) {
112
+ cancelAnimationFrame(this.animationFrameId);
113
+ this.animationFrameId = null;
114
+ }
115
+ }
116
+ reset() {
117
+ this.stop();
118
+ this.currentValue = this.config.startValue;
119
+ this.updateDisplay(this.currentValue);
120
+ this.hasTriggered = false;
121
+ this.startTime = null;
122
+ }
123
+ updateDisplay(value) {
124
+ this.container.textContent = this.formatNumber(value);
125
+ }
126
+ formatNumber(value) {
127
+ return Math.floor(value).toLocaleString();
128
+ }
129
+ // 설정 업데이트
130
+ updateConfig(newConfig) {
131
+ const wasRunning = this.isRunning;
132
+ this.stop();
133
+ this.config = {
134
+ ...this.config,
135
+ ...newConfig,
136
+ onUpdate: newConfig.onUpdate !== void 0 ? newConfig.onUpdate : this.config.onUpdate,
137
+ onComplete: newConfig.onComplete !== void 0 ? newConfig.onComplete : this.config.onComplete
138
+ };
139
+ if (newConfig.targetValue !== void 0) {
140
+ this.reset();
141
+ if (wasRunning && this.config.enabled) {
142
+ this.start();
143
+ }
144
+ } else {
145
+ if (wasRunning && this.config.enabled) {
146
+ this.start();
147
+ }
148
+ }
149
+ }
150
+ // 현재 값 가져오기
151
+ getValue() {
152
+ return this.currentValue;
153
+ }
154
+ // 파괴 및 정리
155
+ destroy() {
156
+ this.stop();
157
+ if (this.intersectionObserver) {
158
+ this.intersectionObserver.disconnect();
159
+ this.intersectionObserver = null;
160
+ }
161
+ }
162
+ }
163
+ const _sfc_main = /* @__PURE__ */ defineComponent({
164
+ __name: "Count",
165
+ props: {
166
+ className: { default: "" },
167
+ style: { default: () => ({}) },
168
+ targetValue: { default: 0 },
169
+ duration: { default: 2e3 },
170
+ startValue: { default: 0 },
171
+ enabled: { type: Boolean, default: true },
172
+ easing: { type: Function, default: () => (t) => t },
173
+ threshold: { default: 0.2 },
174
+ rootMargin: { default: "0px 0px -100px 0px" },
175
+ triggerOnce: { type: Boolean, default: false },
176
+ onUpdate: { type: Function, default: null },
177
+ onComplete: { type: Function, default: null }
178
+ },
179
+ emits: ["update", "complete"],
180
+ setup(__props, { expose: __expose, emit: __emit }) {
181
+ const props = __props;
182
+ const emit = __emit;
183
+ const container = ref(null);
184
+ let instance = null;
185
+ const init = () => {
186
+ if (!container.value) return;
187
+ const options = {
188
+ targetValue: props.targetValue,
189
+ duration: props.duration,
190
+ startValue: props.startValue,
191
+ enabled: props.enabled,
192
+ easing: props.easing,
193
+ threshold: props.threshold,
194
+ rootMargin: props.rootMargin,
195
+ triggerOnce: props.triggerOnce,
196
+ onUpdate: (value) => {
197
+ if (props.onUpdate) props.onUpdate(value);
198
+ emit("update", value);
199
+ },
200
+ onComplete: () => {
201
+ if (props.onComplete) props.onComplete();
202
+ emit("complete");
203
+ }
204
+ };
205
+ instance = new Count(container.value, options);
206
+ };
207
+ watch(
208
+ () => [
209
+ props.targetValue,
210
+ props.duration,
211
+ props.startValue,
212
+ props.enabled,
213
+ props.easing,
214
+ props.threshold,
215
+ props.rootMargin,
216
+ props.triggerOnce
217
+ ],
218
+ () => {
219
+ if (instance) {
220
+ instance.updateConfig({
221
+ targetValue: props.targetValue,
222
+ duration: props.duration,
223
+ startValue: props.startValue,
224
+ enabled: props.enabled,
225
+ easing: props.easing,
226
+ threshold: props.threshold,
227
+ rootMargin: props.rootMargin,
228
+ triggerOnce: props.triggerOnce,
229
+ onUpdate: (value) => {
230
+ if (props.onUpdate) props.onUpdate(value);
231
+ emit("update", value);
232
+ },
233
+ onComplete: () => {
234
+ if (props.onComplete) props.onComplete();
235
+ emit("complete");
236
+ }
237
+ });
238
+ }
239
+ }
240
+ );
241
+ onMounted(() => {
242
+ init();
243
+ });
244
+ onBeforeUnmount(() => {
245
+ if (instance) {
246
+ instance.destroy();
247
+ instance = null;
248
+ }
249
+ });
250
+ __expose({
251
+ start: () => {
252
+ if (instance) instance.start();
253
+ },
254
+ stop: () => {
255
+ if (instance) instance.stop();
256
+ },
257
+ reset: () => {
258
+ if (instance) instance.reset();
259
+ },
260
+ getValue: () => {
261
+ if (instance) return instance.getValue();
262
+ return 0;
263
+ },
264
+ updateConfig: (config) => {
265
+ if (instance) instance.updateConfig(config);
266
+ },
267
+ destroy: () => {
268
+ if (instance) {
269
+ instance.destroy();
270
+ instance = null;
271
+ }
272
+ }
273
+ });
274
+ return (_ctx, _cache) => {
275
+ return openBlock(), createElementBlock("div", {
276
+ ref_key: "container",
277
+ ref: container,
278
+ class: normalizeClass(__props.className),
279
+ style: normalizeStyle(__props.style)
280
+ }, null, 6);
281
+ };
282
+ }
283
+ });
284
+ export {
285
+ _sfc_main as default
286
+ };
@@ -1 +1 @@
1
- "use strict";const t=require("vue");function e(t,e){let i=null;return function(...s){null!==i&&clearTimeout(i),i=setTimeout(()=>{i=null,t.apply(this,s)},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 s=this.canvas.getContext("2d");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");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.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,s){this.offCtx.font=`400 ${t}px ${this.config.fontFamily}`;const n=e.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<=i&&r<=s}}findOptimalFontSize(t,e,i,s){if(this.measureTextFit(s,t,e,i).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,e,i).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 e=Math.min(this.W,this.H),i=this.config.fontSize||Math.max(80,Math.floor(.18*e)),s=this.W-80,n=this.H-80,o=this.findOptimalFontSize(t,s,n,i);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 m of h){if(0===m.length){c+=a+l;continue}const t=m.split(""),e=this.offCtx.measureText(m).width+r*(t.length-1);let i=this.W/2-e/2;for(const s of t)this.offCtx.fillText(s,i+this.offCtx.measureText(s).width/2,c),i+=this.offCtx.measureText(s).width+r;c+=a+l}const f=Math.max(2,this.config.densityStep),u=this.offCtx.getImageData(0,0,this.W,this.H).data,p=[];for(let m=0;m<this.H;m+=f)for(let t=0;t<this.W;t+=f){const e=4*(m*this.W+t);u[e]+u[e+1]+u[e+2]>600&&p.push({x:t,y:m})}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 m=0;m<this.particles.length;m++){const t=this.particles[m],e=p[m];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 s=e.x-this.mouse.x,n=e.y-this.mouse.y,o=s*s+n*n,h=this.config.repelRadius*this.DPR;if(o<h*h){const e=Math.sqrt(o)+1e-4,a=(this.mouse.down?-1:1)*this.config.repelStrength*(1-e/h);t+=s/e*a*6,i+=n/e*a*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 s=t.defineComponent({__name:"MasonEffect",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:s,emit:n}){const o=e,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 i(a.value,t)})()}),t.onBeforeUnmount(()=>{l&&(l.destroy(),l=null)}),s({morph:t=>{l&&l.morph(t)},scatter:()=>{l&&l.scatter()},updateConfig:t=>{l&&l.updateConfig(t)},destroy:()=>{l&&(l.destroy(),l=null)}}),(i,s)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"container",ref:a,class:t.normalizeClass(e.className),style:t.normalizeStyle(e.style)},null,6))}});module.exports=s;
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,8 +1,73 @@
1
- declare class MasonEffect {
1
+ export declare class Count {
2
2
  container: HTMLElement;
3
- config: Required<Omit<MasonEffectOptions, 'onReady' | 'onUpdate' | 'debounceDelay'>> & {
4
- onReady: MasonEffectOptions['onReady'];
5
- onUpdate: MasonEffectOptions['onUpdate'];
3
+ config: Required<Omit<CountOptions, 'onUpdate' | 'onComplete'>> & {
4
+ onUpdate: CountOptions['onUpdate'];
5
+ onComplete: CountOptions['onComplete'];
6
+ };
7
+ currentValue: number;
8
+ startTime: number | null;
9
+ animationFrameId: number | null;
10
+ intersectionObserver: IntersectionObserver | null;
11
+ isRunning: boolean;
12
+ hasTriggered: boolean;
13
+ constructor(container: HTMLElement | string, options: CountOptions);
14
+ init(): void;
15
+ setupIntersectionObserver(): void;
16
+ start(): void;
17
+ stop(): void;
18
+ reset(): void;
19
+ updateDisplay(value: number): void;
20
+ formatNumber(value: number): string;
21
+ updateConfig(newConfig: Partial<CountOptions>): void;
22
+ getValue(): number;
23
+ destroy(): void;
24
+ }
25
+
26
+ /**
27
+ * Count - 숫자 카운팅 애니메이션 효과
28
+ * 바닐라 JS 코어 클래스
29
+ *
30
+ * 사용법:
31
+ * import { Count } from 'masoneffect/count';
32
+ */
33
+ export declare interface CountOptions {
34
+ targetValue: number;
35
+ duration?: number;
36
+ startValue?: number;
37
+ enabled?: boolean;
38
+ easing?: (t: number) => number;
39
+ threshold?: number;
40
+ rootMargin?: string;
41
+ triggerOnce?: boolean;
42
+ onUpdate?: (value: number) => void;
43
+ onComplete?: () => void;
44
+ }
45
+
46
+ export declare const easingFunctions: {
47
+ linear: (t: number) => number;
48
+ easeInQuad: (t: number) => number;
49
+ easeOutQuad: (t: number) => number;
50
+ easeInOutQuad: (t: number) => number;
51
+ easeOutCubic: (t: number) => number;
52
+ };
53
+
54
+ export declare interface Particle {
55
+ x: number;
56
+ y: number;
57
+ vx: number;
58
+ vy: number;
59
+ tx: number;
60
+ ty: number;
61
+ initialX?: number;
62
+ initialY?: number;
63
+ j: number;
64
+ }
65
+
66
+ declare class TextToParticle {
67
+ container: HTMLElement;
68
+ config: Required<Omit<TextToParticleOptions, 'onReady' | 'onUpdate' | 'debounceDelay'>> & {
69
+ onReady: TextToParticleOptions['onReady'];
70
+ onUpdate: TextToParticleOptions['onUpdate'];
6
71
  };
7
72
  canvas: HTMLCanvasElement;
8
73
  ctx: CanvasRenderingContext2D;
@@ -22,9 +87,9 @@ declare class MasonEffect {
22
87
  isVisible: boolean;
23
88
  intersectionObserver: IntersectionObserver | null;
24
89
  debounceDelay: number;
25
- _debouncedMorph: (textOrOptions?: string | Partial<MasonEffectOptions> | null) => void;
26
- _debouncedUpdateConfig: (newConfig: Partial<MasonEffectOptions>) => void;
27
- constructor(container: HTMLElement | string, options?: MasonEffectOptions);
90
+ _debouncedMorph: (textOrOptions?: string | Partial<TextToParticleOptions> | null) => void;
91
+ _debouncedUpdateConfig: (newConfig: Partial<TextToParticleOptions>) => void;
92
+ constructor(container: HTMLElement | string, options?: TextToParticleOptions);
28
93
  init(): void;
29
94
  setupIntersectionObserver(): void;
30
95
  resize(): void;
@@ -46,8 +111,8 @@ declare class MasonEffect {
46
111
  makeParticle(): Particle;
47
112
  initParticles(): void;
48
113
  scatter(): void;
49
- morph(textOrOptions?: string | Partial<MasonEffectOptions> | null): void;
50
- _morphInternal(textOrOptions?: string | Partial<MasonEffectOptions> | null): void;
114
+ morph(textOrOptions?: string | Partial<TextToParticleOptions> | null): void;
115
+ _morphInternal(textOrOptions?: string | Partial<TextToParticleOptions> | null): void;
51
116
  update(): void;
52
117
  animate(): void;
53
118
  start(): void;
@@ -59,18 +124,22 @@ declare class MasonEffect {
59
124
  handleMouseLeave(): void;
60
125
  handleMouseDown(): void;
61
126
  handleMouseUp(): void;
62
- updateConfig(newConfig: Partial<MasonEffectOptions>): void;
63
- _updateConfigInternal(newConfig: Partial<MasonEffectOptions>): void;
127
+ updateConfig(newConfig: Partial<TextToParticleOptions>): void;
128
+ _updateConfigInternal(newConfig: Partial<TextToParticleOptions>): void;
64
129
  destroy(): void;
65
130
  }
66
- export { MasonEffect }
67
- export default MasonEffect;
131
+ export { TextToParticle as MasonEffect }
132
+ export { TextToParticle }
133
+ export default TextToParticle;
68
134
 
69
135
  /**
70
- * MasonEffect - 파티클 모핑 효과 라이브러리
136
+ * TextToParticle - 텍스트를 파티클로 변환하는 효과
71
137
  * 바닐라 JS 코어 클래스
138
+ *
139
+ * 사용법:
140
+ * import { TextToParticle } from 'masoneffect/textToParticle';
72
141
  */
73
- export declare interface MasonEffectOptions {
142
+ declare interface TextToParticleOptions {
74
143
  text?: string;
75
144
  densityStep?: number;
76
145
  maxParticles?: number;
@@ -85,20 +154,10 @@ declare class MasonEffect {
85
154
  height?: number | null;
86
155
  devicePixelRatio?: number | null;
87
156
  debounceDelay?: number;
88
- onReady?: (instance: MasonEffect) => void;
89
- onUpdate?: (instance: MasonEffect) => void;
90
- }
91
-
92
- export declare interface Particle {
93
- x: number;
94
- y: number;
95
- vx: number;
96
- vy: number;
97
- tx: number;
98
- ty: number;
99
- initialX?: number;
100
- initialY?: number;
101
- j: number;
157
+ onReady?: (instance: TextToParticle) => void;
158
+ onUpdate?: (instance: TextToParticle) => void;
102
159
  }
160
+ export { TextToParticleOptions as MasonEffectOptions }
161
+ export { TextToParticleOptions }
103
162
 
104
163
  export { }