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
@@ -12,7 +12,7 @@ function debounce(func, wait) {
12
12
  timeout = setTimeout(later, wait);
13
13
  };
14
14
  }
15
- class MasonEffect {
15
+ class TextToParticle {
16
16
  constructor(container, options = {}) {
17
17
  this.container = typeof container === "string" ? document.querySelector(container) : container;
18
18
  if (!this.container) {
@@ -36,7 +36,7 @@ class MasonEffect {
36
36
  onUpdate: options.onUpdate || null
37
37
  };
38
38
  this.canvas = document.createElement("canvas");
39
- const ctx = this.canvas.getContext("2d");
39
+ const ctx = this.canvas.getContext("2d", { willReadFrequently: true });
40
40
  if (!ctx) {
41
41
  throw new Error("Canvas context not available");
42
42
  }
@@ -44,7 +44,7 @@ class MasonEffect {
44
44
  this.container.appendChild(this.canvas);
45
45
  this.canvas.style.display = "block";
46
46
  this.offCanvas = document.createElement("canvas");
47
- const offCtx = this.offCanvas.getContext("2d");
47
+ const offCtx = this.offCanvas.getContext("2d", { willReadFrequently: true });
48
48
  if (!offCtx) {
49
49
  throw new Error("Offscreen canvas context not available");
50
50
  }
@@ -218,7 +218,7 @@ class MasonEffect {
218
218
  continue;
219
219
  }
220
220
  const chars = line.split("");
221
- const totalWidth = this.offCtx.measureText(line).width + spacing * (chars.length - 1);
221
+ const totalWidth = this.offCtx.measureText(line).width + spacing * (chars.length > 0 ? chars.length - 1 : 0);
222
222
  let x = this.W / 2 - totalWidth / 2;
223
223
  for (const ch of chars) {
224
224
  this.offCtx.fillText(ch, x + this.offCtx.measureText(ch).width / 2, startY);
@@ -422,8 +422,169 @@ class MasonEffect {
422
422
  }
423
423
  }
424
424
  }
425
- const _sfc_main = /* @__PURE__ */ defineComponent({
426
- __name: "MasonEffect",
425
+ const easingFunctions = {
426
+ linear: (t) => t
427
+ };
428
+ class Count {
429
+ constructor(container, options) {
430
+ this.container = typeof container === "string" ? document.querySelector(container) : container;
431
+ if (!this.container) {
432
+ throw new Error("Container element not found");
433
+ }
434
+ this.config = {
435
+ targetValue: options.targetValue,
436
+ duration: options.duration ?? 2e3,
437
+ startValue: options.startValue ?? 0,
438
+ enabled: options.enabled ?? true,
439
+ easing: options.easing ?? easingFunctions.linear,
440
+ threshold: options.threshold ?? 0.2,
441
+ rootMargin: options.rootMargin ?? "0px 0px -100px 0px",
442
+ triggerOnce: options.triggerOnce ?? false,
443
+ onUpdate: options.onUpdate || null,
444
+ onComplete: options.onComplete || null
445
+ };
446
+ this.currentValue = this.config.startValue;
447
+ this.startTime = null;
448
+ this.animationFrameId = null;
449
+ this.intersectionObserver = null;
450
+ this.isRunning = false;
451
+ this.hasTriggered = false;
452
+ this.init();
453
+ }
454
+ init() {
455
+ this.updateDisplay(this.config.startValue);
456
+ this.setupIntersectionObserver();
457
+ }
458
+ setupIntersectionObserver() {
459
+ if (typeof window === "undefined" || typeof window.IntersectionObserver === "undefined") {
460
+ if (this.config.enabled) {
461
+ this.start();
462
+ }
463
+ return;
464
+ }
465
+ this.intersectionObserver = new IntersectionObserver(
466
+ (entries) => {
467
+ var _a;
468
+ for (const entry of entries) {
469
+ if (entry.target !== this.container) continue;
470
+ if (entry.isIntersecting) {
471
+ if (!this.hasTriggered && this.config.enabled) {
472
+ this.hasTriggered = true;
473
+ this.start();
474
+ }
475
+ if (this.config.triggerOnce) {
476
+ (_a = this.intersectionObserver) == null ? void 0 : _a.unobserve(this.container);
477
+ }
478
+ } else {
479
+ if (!this.config.triggerOnce) {
480
+ const rect = entry.boundingClientRect;
481
+ const viewportHeight = window.innerHeight;
482
+ const viewportWidth = window.innerWidth;
483
+ const isCompletelyOutOfViewport = rect.bottom <= 0 || rect.top >= viewportHeight || rect.right <= 0 || rect.left >= viewportWidth;
484
+ if (isCompletelyOutOfViewport && this.isRunning) {
485
+ this.reset();
486
+ }
487
+ }
488
+ }
489
+ }
490
+ },
491
+ {
492
+ threshold: this.config.threshold,
493
+ rootMargin: this.config.rootMargin
494
+ }
495
+ );
496
+ this.intersectionObserver.observe(this.container);
497
+ }
498
+ start() {
499
+ if (this.isRunning) return;
500
+ if (!this.config.enabled) return;
501
+ this.isRunning = true;
502
+ this.startTime = null;
503
+ this.currentValue = this.config.startValue;
504
+ this.updateDisplay(this.currentValue);
505
+ const animate = (currentTime) => {
506
+ if (this.startTime === null) {
507
+ this.startTime = currentTime;
508
+ }
509
+ const elapsed = currentTime - this.startTime;
510
+ const progress = Math.min(elapsed / this.config.duration, 1);
511
+ const easedProgress = this.config.easing(progress);
512
+ this.currentValue = Math.floor(
513
+ this.config.startValue + (this.config.targetValue - this.config.startValue) * easedProgress
514
+ );
515
+ this.updateDisplay(this.currentValue);
516
+ if (this.config.onUpdate) {
517
+ this.config.onUpdate(this.currentValue);
518
+ }
519
+ if (progress < 1) {
520
+ this.animationFrameId = requestAnimationFrame(animate);
521
+ } else {
522
+ this.currentValue = this.config.targetValue;
523
+ this.updateDisplay(this.currentValue);
524
+ this.isRunning = false;
525
+ if (this.config.onComplete) {
526
+ this.config.onComplete();
527
+ }
528
+ }
529
+ };
530
+ this.animationFrameId = requestAnimationFrame(animate);
531
+ }
532
+ stop() {
533
+ this.isRunning = false;
534
+ if (this.animationFrameId !== null) {
535
+ cancelAnimationFrame(this.animationFrameId);
536
+ this.animationFrameId = null;
537
+ }
538
+ }
539
+ reset() {
540
+ this.stop();
541
+ this.currentValue = this.config.startValue;
542
+ this.updateDisplay(this.currentValue);
543
+ this.hasTriggered = false;
544
+ this.startTime = null;
545
+ }
546
+ updateDisplay(value) {
547
+ this.container.textContent = this.formatNumber(value);
548
+ }
549
+ formatNumber(value) {
550
+ return Math.floor(value).toLocaleString();
551
+ }
552
+ // 설정 업데이트
553
+ updateConfig(newConfig) {
554
+ const wasRunning = this.isRunning;
555
+ this.stop();
556
+ this.config = {
557
+ ...this.config,
558
+ ...newConfig,
559
+ onUpdate: newConfig.onUpdate !== void 0 ? newConfig.onUpdate : this.config.onUpdate,
560
+ onComplete: newConfig.onComplete !== void 0 ? newConfig.onComplete : this.config.onComplete
561
+ };
562
+ if (newConfig.targetValue !== void 0) {
563
+ this.reset();
564
+ if (wasRunning && this.config.enabled) {
565
+ this.start();
566
+ }
567
+ } else {
568
+ if (wasRunning && this.config.enabled) {
569
+ this.start();
570
+ }
571
+ }
572
+ }
573
+ // 현재 값 가져오기
574
+ getValue() {
575
+ return this.currentValue;
576
+ }
577
+ // 파괴 및 정리
578
+ destroy() {
579
+ this.stop();
580
+ if (this.intersectionObserver) {
581
+ this.intersectionObserver.disconnect();
582
+ this.intersectionObserver = null;
583
+ }
584
+ }
585
+ }
586
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
587
+ __name: "TextToParticle",
427
588
  props: {
428
589
  className: { default: "" },
429
590
  style: { default: () => ({}) },
@@ -475,7 +636,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
475
636
  emit("update", inst);
476
637
  }
477
638
  };
478
- instance = new MasonEffect(container.value, options);
639
+ instance = new TextToParticle(container.value, options);
479
640
  };
480
641
  watch(
481
642
  () => [
@@ -549,6 +710,130 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
549
710
  };
550
711
  }
551
712
  });
713
+ const _sfc_main = /* @__PURE__ */ defineComponent({
714
+ __name: "Count",
715
+ props: {
716
+ className: { default: "" },
717
+ style: { default: () => ({}) },
718
+ targetValue: { default: 0 },
719
+ duration: { default: 2e3 },
720
+ startValue: { default: 0 },
721
+ enabled: { type: Boolean, default: true },
722
+ easing: { type: Function, default: () => (t) => t },
723
+ threshold: { default: 0.2 },
724
+ rootMargin: { default: "0px 0px -100px 0px" },
725
+ triggerOnce: { type: Boolean, default: false },
726
+ onUpdate: { type: Function, default: null },
727
+ onComplete: { type: Function, default: null }
728
+ },
729
+ emits: ["update", "complete"],
730
+ setup(__props, { expose: __expose, emit: __emit }) {
731
+ const props = __props;
732
+ const emit = __emit;
733
+ const container = ref(null);
734
+ let instance = null;
735
+ const init = () => {
736
+ if (!container.value) return;
737
+ const options = {
738
+ targetValue: props.targetValue,
739
+ duration: props.duration,
740
+ startValue: props.startValue,
741
+ enabled: props.enabled,
742
+ easing: props.easing,
743
+ threshold: props.threshold,
744
+ rootMargin: props.rootMargin,
745
+ triggerOnce: props.triggerOnce,
746
+ onUpdate: (value) => {
747
+ if (props.onUpdate) props.onUpdate(value);
748
+ emit("update", value);
749
+ },
750
+ onComplete: () => {
751
+ if (props.onComplete) props.onComplete();
752
+ emit("complete");
753
+ }
754
+ };
755
+ instance = new Count(container.value, options);
756
+ };
757
+ watch(
758
+ () => [
759
+ props.targetValue,
760
+ props.duration,
761
+ props.startValue,
762
+ props.enabled,
763
+ props.easing,
764
+ props.threshold,
765
+ props.rootMargin,
766
+ props.triggerOnce
767
+ ],
768
+ () => {
769
+ if (instance) {
770
+ instance.updateConfig({
771
+ targetValue: props.targetValue,
772
+ duration: props.duration,
773
+ startValue: props.startValue,
774
+ enabled: props.enabled,
775
+ easing: props.easing,
776
+ threshold: props.threshold,
777
+ rootMargin: props.rootMargin,
778
+ triggerOnce: props.triggerOnce,
779
+ onUpdate: (value) => {
780
+ if (props.onUpdate) props.onUpdate(value);
781
+ emit("update", value);
782
+ },
783
+ onComplete: () => {
784
+ if (props.onComplete) props.onComplete();
785
+ emit("complete");
786
+ }
787
+ });
788
+ }
789
+ }
790
+ );
791
+ onMounted(() => {
792
+ init();
793
+ });
794
+ onBeforeUnmount(() => {
795
+ if (instance) {
796
+ instance.destroy();
797
+ instance = null;
798
+ }
799
+ });
800
+ __expose({
801
+ start: () => {
802
+ if (instance) instance.start();
803
+ },
804
+ stop: () => {
805
+ if (instance) instance.stop();
806
+ },
807
+ reset: () => {
808
+ if (instance) instance.reset();
809
+ },
810
+ getValue: () => {
811
+ if (instance) return instance.getValue();
812
+ return 0;
813
+ },
814
+ updateConfig: (config) => {
815
+ if (instance) instance.updateConfig(config);
816
+ },
817
+ destroy: () => {
818
+ if (instance) {
819
+ instance.destroy();
820
+ instance = null;
821
+ }
822
+ }
823
+ });
824
+ return (_ctx, _cache) => {
825
+ return openBlock(), createElementBlock("div", {
826
+ ref_key: "container",
827
+ ref: container,
828
+ class: normalizeClass(__props.className),
829
+ style: normalizeStyle(__props.style)
830
+ }, null, 6);
831
+ };
832
+ }
833
+ });
552
834
  export {
553
- _sfc_main as default
835
+ _sfc_main as Count,
836
+ _sfc_main$1 as MasonEffect,
837
+ _sfc_main$1 as TextToParticle,
838
+ _sfc_main$1 as default
554
839
  };
@@ -0,0 +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",{willReadFrequently:!0});if(!s)throw new Error("Canvas context not available");this.ctx=s,this.container.appendChild(this.canvas),this.canvas.style.display="block",this.offCanvas=document.createElement("canvas");const n=this.offCanvas.getContext("2d",{willReadFrequently:!0});if(!n)throw new Error("Offscreen canvas context not available");this.offCtx=n,this.W=0,this.H=0,this.DPR=this.config.devicePixelRatio||Math.min(window.devicePixelRatio||1,1.8),this.particles=[],this.mouse={x:0,y:0,down:!1},this.animationId=null,this.isRunning=!1,this.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>0?t.length-1:0);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:"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: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;
@@ -0,0 +1,163 @@
1
+ export declare class Count {
2
+ container: HTMLElement;
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'];
71
+ };
72
+ canvas: HTMLCanvasElement;
73
+ ctx: CanvasRenderingContext2D;
74
+ offCanvas: HTMLCanvasElement;
75
+ offCtx: CanvasRenderingContext2D;
76
+ W: number;
77
+ H: number;
78
+ DPR: number;
79
+ particles: Particle[];
80
+ mouse: {
81
+ x: number;
82
+ y: number;
83
+ down: boolean;
84
+ };
85
+ animationId: number | null;
86
+ isRunning: boolean;
87
+ isVisible: boolean;
88
+ intersectionObserver: IntersectionObserver | null;
89
+ debounceDelay: number;
90
+ _debouncedMorph: (textOrOptions?: string | Partial<TextToParticleOptions> | null) => void;
91
+ _debouncedUpdateConfig: (newConfig: Partial<TextToParticleOptions>) => void;
92
+ constructor(container: HTMLElement | string, options?: TextToParticleOptions);
93
+ init(): void;
94
+ setupIntersectionObserver(): void;
95
+ resize(): void;
96
+ /**
97
+ * 텍스트가 영역 안에 들어가는지 확인하는 헬퍼 함수 (줄바꿈 지원)
98
+ * @param fontSize 확인할 폰트 크기
99
+ * @param text 텍스트 (\n으로 줄바꿈 구분)
100
+ * @param maxWidth 최대 너비
101
+ * @param maxHeight 최대 높이
102
+ * @returns { width: number, height: number, fits: boolean }
103
+ */
104
+ private measureTextFit;
105
+ /**
106
+ * 이진 검색을 사용하여 적절한 폰트 크기를 찾는 최적화된 함수
107
+ * 반복 횟수를 O(log n)으로 줄여 성능 개선 (최대 15회 반복, 기존 최대 100회에서 대폭 감소)
108
+ */
109
+ private findOptimalFontSize;
110
+ buildTargets(): void;
111
+ makeParticle(): Particle;
112
+ initParticles(): void;
113
+ scatter(): void;
114
+ morph(textOrOptions?: string | Partial<TextToParticleOptions> | null): void;
115
+ _morphInternal(textOrOptions?: string | Partial<TextToParticleOptions> | null): void;
116
+ update(): void;
117
+ animate(): void;
118
+ start(): void;
119
+ stop(): void;
120
+ setupEventListeners(): void;
121
+ removeEventListeners(): void;
122
+ handleResize(): void;
123
+ handleMouseMove(e: MouseEvent): void;
124
+ handleMouseLeave(): void;
125
+ handleMouseDown(): void;
126
+ handleMouseUp(): void;
127
+ updateConfig(newConfig: Partial<TextToParticleOptions>): void;
128
+ _updateConfigInternal(newConfig: Partial<TextToParticleOptions>): void;
129
+ destroy(): void;
130
+ }
131
+ export { TextToParticle as MasonEffect }
132
+ export { TextToParticle }
133
+ export default TextToParticle;
134
+
135
+ /**
136
+ * TextToParticle - 텍스트를 파티클로 변환하는 효과
137
+ * 바닐라 JS 코어 클래스
138
+ *
139
+ * 사용법:
140
+ * import { TextToParticle } from 'masoneffect/textToParticle';
141
+ */
142
+ declare interface TextToParticleOptions {
143
+ text?: string;
144
+ densityStep?: number;
145
+ maxParticles?: number;
146
+ pointSize?: number;
147
+ ease?: number;
148
+ repelRadius?: number;
149
+ repelStrength?: number;
150
+ particleColor?: string;
151
+ fontFamily?: string;
152
+ fontSize?: number | null;
153
+ width?: number | null;
154
+ height?: number | null;
155
+ devicePixelRatio?: number | null;
156
+ debounceDelay?: number;
157
+ onReady?: (instance: TextToParticle) => void;
158
+ onUpdate?: (instance: TextToParticle) => void;
159
+ }
160
+ export { TextToParticleOptions as MasonEffectOptions }
161
+ export { TextToParticleOptions }
162
+
163
+ export { }