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.
Files changed (101) hide show
  1. package/README.md +2 -2
  2. package/dist/core/count/index.d.ts +3 -2
  3. package/dist/core/count/index.d.ts.map +1 -1
  4. package/dist/core/textToParticle/index.d.ts +3 -3
  5. package/dist/core/textToParticle/index.d.ts.map +1 -1
  6. package/dist/core/typing/index.d.ts +8 -6
  7. package/dist/core/typing/index.d.ts.map +1 -1
  8. package/dist/core/utils/visibilityManager.d.ts +35 -0
  9. package/dist/core/utils/visibilityManager.d.ts.map +1 -0
  10. package/dist/count/core/count/index.d.ts +3 -2
  11. package/dist/count/core/count/index.d.ts.map +1 -1
  12. package/dist/count/core/textToParticle/index.d.ts +3 -3
  13. package/dist/count/core/textToParticle/index.d.ts.map +1 -1
  14. package/dist/count/core/typing/index.d.ts +8 -6
  15. package/dist/count/core/typing/index.d.ts.map +1 -1
  16. package/dist/count/core/utils/visibilityManager.d.ts +35 -0
  17. package/dist/count/core/utils/visibilityManager.d.ts.map +1 -0
  18. package/dist/count/index.cjs +1 -1
  19. package/dist/count/index.mjs +1 -1
  20. package/dist/index.cjs +1 -1
  21. package/dist/index.mjs +1 -1
  22. package/dist/index.umd.min.js +1 -1
  23. package/dist/react/core/count/index.d.ts +3 -2
  24. package/dist/react/core/textToParticle/index.d.ts +3 -3
  25. package/dist/react/core/typing/index.d.ts +8 -6
  26. package/dist/react/core/utils/visibilityManager.d.ts +34 -0
  27. package/dist/react/count/core/count/index.d.ts +3 -2
  28. package/dist/react/count/core/count/index.d.ts.map +1 -1
  29. package/dist/react/count/core/textToParticle/index.d.ts +3 -3
  30. package/dist/react/count/core/textToParticle/index.d.ts.map +1 -1
  31. package/dist/react/count/core/typing/index.d.ts +8 -6
  32. package/dist/react/count/core/typing/index.d.ts.map +1 -1
  33. package/dist/react/count/core/utils/visibilityManager.d.ts +35 -0
  34. package/dist/react/count/core/utils/visibilityManager.d.ts.map +1 -0
  35. package/dist/react/count/index.cjs +1 -1
  36. package/dist/react/count/index.mjs +1 -1
  37. package/dist/react/textToParticle/core/count/index.d.ts +3 -2
  38. package/dist/react/textToParticle/core/count/index.d.ts.map +1 -1
  39. package/dist/react/textToParticle/core/textToParticle/index.d.ts +3 -3
  40. package/dist/react/textToParticle/core/textToParticle/index.d.ts.map +1 -1
  41. package/dist/react/textToParticle/core/typing/index.d.ts +8 -6
  42. package/dist/react/textToParticle/core/typing/index.d.ts.map +1 -1
  43. package/dist/react/textToParticle/core/utils/visibilityManager.d.ts +35 -0
  44. package/dist/react/textToParticle/core/utils/visibilityManager.d.ts.map +1 -0
  45. package/dist/react/textToParticle/index.cjs +1 -1
  46. package/dist/react/textToParticle/index.mjs +1 -1
  47. package/dist/react/typing/core/count/index.d.ts +3 -2
  48. package/dist/react/typing/core/count/index.d.ts.map +1 -1
  49. package/dist/react/typing/core/textToParticle/index.d.ts +3 -3
  50. package/dist/react/typing/core/textToParticle/index.d.ts.map +1 -1
  51. package/dist/react/typing/core/typing/index.d.ts +8 -6
  52. package/dist/react/typing/core/typing/index.d.ts.map +1 -1
  53. package/dist/react/typing/core/utils/visibilityManager.d.ts +35 -0
  54. package/dist/react/typing/core/utils/visibilityManager.d.ts.map +1 -0
  55. package/dist/react/typing/index.cjs +1 -1
  56. package/dist/react/typing/index.mjs +1 -1
  57. package/dist/svelte/count/index.cjs +1 -1
  58. package/dist/svelte/count/index.d.ts +46 -32
  59. package/dist/svelte/count/index.mjs +120 -42
  60. package/dist/svelte/index.cjs +1 -1
  61. package/dist/svelte/index.d.ts +46 -32
  62. package/dist/svelte/index.mjs +211 -160
  63. package/dist/svelte/textToParticle/index.cjs +1 -1
  64. package/dist/svelte/textToParticle/index.d.ts +46 -32
  65. package/dist/svelte/textToParticle/index.mjs +119 -33
  66. package/dist/svelte/typing/index.cjs +1 -1
  67. package/dist/svelte/typing/index.d.ts +46 -32
  68. package/dist/svelte/typing/index.mjs +174 -85
  69. package/dist/textToParticle/core/count/index.d.ts +3 -2
  70. package/dist/textToParticle/core/count/index.d.ts.map +1 -1
  71. package/dist/textToParticle/core/textToParticle/index.d.ts +3 -3
  72. package/dist/textToParticle/core/textToParticle/index.d.ts.map +1 -1
  73. package/dist/textToParticle/core/typing/index.d.ts +8 -6
  74. package/dist/textToParticle/core/typing/index.d.ts.map +1 -1
  75. package/dist/textToParticle/core/utils/visibilityManager.d.ts +35 -0
  76. package/dist/textToParticle/core/utils/visibilityManager.d.ts.map +1 -0
  77. package/dist/textToParticle/index.cjs +1 -1
  78. package/dist/textToParticle/index.mjs +1 -1
  79. package/dist/typing/core/count/index.d.ts +3 -2
  80. package/dist/typing/core/count/index.d.ts.map +1 -1
  81. package/dist/typing/core/textToParticle/index.d.ts +3 -3
  82. package/dist/typing/core/textToParticle/index.d.ts.map +1 -1
  83. package/dist/typing/core/typing/index.d.ts +8 -6
  84. package/dist/typing/core/typing/index.d.ts.map +1 -1
  85. package/dist/typing/core/utils/visibilityManager.d.ts +35 -0
  86. package/dist/typing/core/utils/visibilityManager.d.ts.map +1 -0
  87. package/dist/typing/index.cjs +1 -1
  88. package/dist/typing/index.mjs +1 -1
  89. package/dist/vue/count/index.cjs +1 -1
  90. package/dist/vue/count/index.d.ts +46 -32
  91. package/dist/vue/count/index.mjs +119 -41
  92. package/dist/vue/index.cjs +1 -1
  93. package/dist/vue/index.d.ts +46 -32
  94. package/dist/vue/index.mjs +209 -158
  95. package/dist/vue/textToParticle/index.cjs +1 -1
  96. package/dist/vue/textToParticle/index.d.ts +46 -32
  97. package/dist/vue/textToParticle/index.mjs +119 -33
  98. package/dist/vue/typing/index.cjs +1 -1
  99. package/dist/vue/typing/index.d.ts +46 -32
  100. package/dist/vue/typing/index.mjs +173 -84
  101. package/package.json +1 -1
@@ -1,4 +1,105 @@
1
1
  import { defineComponent, ref, watch, onMounted, onBeforeUnmount, createElementBlock, openBlock, normalizeStyle, normalizeClass, onUnmounted } 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 debounce(func, wait) {
3
104
  let timeout = null;
4
105
  return function executedFunction(...args) {
@@ -56,8 +157,7 @@ class TextToParticle {
56
157
  this.mouse = { x: 0, y: 0, down: false };
57
158
  this.animationId = null;
58
159
  this.isRunning = false;
59
- this.isVisible = false;
60
- this.intersectionObserver = null;
160
+ this.visibilityManager = null;
61
161
  this.debounceDelay = options.debounceDelay ?? 150;
62
162
  const boundHandleResize = this.handleResize.bind(this);
63
163
  this.handleResize = debounce(boundHandleResize, this.debounceDelay);
@@ -72,39 +172,22 @@ class TextToParticle {
72
172
  init() {
73
173
  this.resize();
74
174
  this.setupEventListeners();
75
- this.setupIntersectionObserver();
175
+ this.setupVisibilityManager();
76
176
  if (this.config.onReady) {
77
177
  this.config.onReady(this);
78
178
  }
79
179
  }
80
- setupIntersectionObserver() {
81
- if (typeof window === "undefined" || typeof window.IntersectionObserver === "undefined") {
82
- this.isVisible = true;
83
- this.start();
84
- return;
85
- }
86
- if (this.intersectionObserver) {
87
- return;
88
- }
89
- this.intersectionObserver = new IntersectionObserver(
90
- (entries) => {
91
- for (const entry of entries) {
92
- if (entry.target !== this.container) continue;
93
- if (entry.isIntersecting) {
94
- this.isVisible = true;
95
- this.start();
96
- } else {
97
- this.isVisible = false;
98
- this.stop();
99
- }
100
- }
180
+ setupVisibilityManager() {
181
+ this.visibilityManager = new VisibilityManager(this.container, {
182
+ threshold: 0.1,
183
+ // 10% 이상 보일 때 동작
184
+ onVisible: () => {
185
+ this.start();
101
186
  },
102
- {
103
- threshold: 0.1
104
- // 10% 이상 보일 때 동작
187
+ onHidden: () => {
188
+ this.stop();
105
189
  }
106
- );
107
- this.intersectionObserver.observe(this.container);
190
+ });
108
191
  }
109
192
  resize() {
110
193
  const width = this.config.width || this.container.clientWidth || window.innerWidth;
@@ -341,7 +424,10 @@ class TextToParticle {
341
424
  p.y += p.vy;
342
425
  }
343
426
  this.ctx.fillStyle = this.config.particleColor;
344
- const r = this.config.pointSize * this.DPR;
427
+ const baseSize = 1920;
428
+ const currentSize = Math.min(this.W, this.H) / this.DPR;
429
+ const sizeRatio = Math.max(0.5, Math.min(2, currentSize / baseSize));
430
+ const r = this.config.pointSize * this.DPR * sizeRatio;
345
431
  for (const p of this.particles) {
346
432
  this.ctx.beginPath();
347
433
  this.ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
@@ -413,9 +499,9 @@ class TextToParticle {
413
499
  destroy() {
414
500
  this.stop();
415
501
  this.removeEventListeners();
416
- if (this.intersectionObserver) {
417
- this.intersectionObserver.disconnect();
418
- this.intersectionObserver = null;
502
+ if (this.visibilityManager) {
503
+ this.visibilityManager.destroy();
504
+ this.visibilityManager = null;
419
505
  }
420
506
  if (this.canvas && this.canvas.parentNode) {
421
507
  this.canvas.parentNode.removeChild(this.canvas);
@@ -446,54 +532,31 @@ class Count {
446
532
  this.currentValue = this.config.startValue;
447
533
  this.startTime = null;
448
534
  this.animationFrameId = null;
449
- this.intersectionObserver = null;
535
+ this.visibilityManager = null;
450
536
  this.isRunning = false;
451
537
  this.hasTriggered = false;
452
538
  this.init();
453
539
  }
454
540
  init() {
455
541
  this.updateDisplay(this.config.startValue);
456
- this.setupIntersectionObserver();
542
+ this.setupVisibilityManager();
457
543
  }
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
- }
544
+ setupVisibilityManager() {
545
+ this.visibilityManager = new VisibilityManager(this.container, {
546
+ threshold: this.config.threshold,
547
+ rootMargin: this.config.rootMargin,
548
+ onVisible: () => {
549
+ if (!this.hasTriggered && this.config.enabled) {
550
+ this.hasTriggered = true;
551
+ this.start();
489
552
  }
490
553
  },
491
- {
492
- threshold: this.config.threshold,
493
- rootMargin: this.config.rootMargin
554
+ onHidden: () => {
555
+ if (!this.config.triggerOnce && this.isRunning) {
556
+ this.reset();
557
+ }
494
558
  }
495
- );
496
- this.intersectionObserver.observe(this.container);
559
+ });
497
560
  }
498
561
  start() {
499
562
  if (this.isRunning) return;
@@ -577,9 +640,9 @@ class Count {
577
640
  // 파괴 및 정리
578
641
  destroy() {
579
642
  this.stop();
580
- if (this.intersectionObserver) {
581
- this.intersectionObserver.disconnect();
582
- this.intersectionObserver = null;
643
+ if (this.visibilityManager) {
644
+ this.visibilityManager.destroy();
645
+ this.visibilityManager = null;
583
646
  }
584
647
  }
585
648
  }
@@ -603,25 +666,48 @@ function decomposeHangul(char) {
603
666
  }
604
667
  return result;
605
668
  }
669
+ function composeHangul(initial, medial, final) {
670
+ const initialChars = ["ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
671
+ const medialChars = ["ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ"];
672
+ const finalChars = ["", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
673
+ const initialIndex = initialChars.indexOf(initial);
674
+ const medialIndex = medialChars.indexOf(medial);
675
+ const finalIndex = final ? finalChars.indexOf(final) : 0;
676
+ if (initialIndex === -1 || medialIndex === -1) {
677
+ return initial + (medial || "") + (final || "");
678
+ }
679
+ const code = 44032 + initialIndex * 21 * 28 + medialIndex * 28 + finalIndex;
680
+ return String.fromCharCode(code);
681
+ }
606
682
  function decomposeText(text) {
607
683
  const units = [];
684
+ const charUnitRanges = [];
608
685
  for (let i = 0; i < text.length; i++) {
609
686
  const char = text[i];
610
687
  const code = char.charCodeAt(0);
688
+ const startIndex = units.length;
611
689
  if (code >= 44032 && code <= 55203) {
612
690
  const decomposed = decomposeHangul(char);
613
691
  units.push(...decomposed);
692
+ charUnitRanges.push({
693
+ start: startIndex,
694
+ end: units.length,
695
+ isHangul: true
696
+ });
614
697
  } else {
615
698
  units.push(char);
699
+ charUnitRanges.push({
700
+ start: startIndex,
701
+ end: units.length,
702
+ isHangul: false
703
+ });
616
704
  }
617
705
  }
618
- return units;
706
+ return { units, charUnitRanges };
619
707
  }
620
708
  class Typing {
621
709
  // 원본 텍스트
622
710
  constructor(container, options) {
623
- this.originalChars = [];
624
- this.charUnitMap = [];
625
711
  this.container = typeof container === "string" ? document.querySelector(container) : container;
626
712
  if (!this.container) {
627
713
  throw new Error("Container element not found");
@@ -640,100 +726,65 @@ class Typing {
640
726
  onUpdate: options.onUpdate || null,
641
727
  onComplete: options.onComplete || null
642
728
  };
643
- this.textUnits = decomposeText(this.config.text);
644
- this.originalChars = [];
645
- this.charUnitMap = [];
646
- this.initializeTextStructure();
729
+ const decomposed = decomposeText(this.config.text);
730
+ this.textUnits = decomposed.units;
731
+ this.charUnitRanges = decomposed.charUnitRanges;
647
732
  this.currentIndex = 0;
648
733
  this.displayedText = "";
649
734
  this.timeoutId = null;
650
- this.intersectionObserver = null;
735
+ this.visibilityManager = null;
651
736
  this.isRunning = false;
652
737
  this.hasTriggered = false;
653
738
  this.init();
654
739
  }
655
740
  init() {
656
741
  this.updateDisplay("");
657
- this.setupIntersectionObserver();
742
+ this.setupVisibilityManager();
658
743
  }
659
- setupIntersectionObserver() {
660
- if (typeof window === "undefined" || typeof window.IntersectionObserver === "undefined") {
661
- if (this.config.enabled) {
662
- setTimeout(() => this.start(), this.config.delay);
663
- }
664
- return;
665
- }
666
- this.intersectionObserver = new IntersectionObserver(
667
- (entries) => {
668
- var _a;
669
- for (const entry of entries) {
670
- if (entry.target !== this.container) continue;
671
- if (entry.isIntersecting && !this.hasTriggered) {
672
- if (this.config.enabled) {
673
- setTimeout(() => this.start(), this.config.delay);
674
- }
675
- this.hasTriggered = true;
676
- if (this.config.triggerOnce) {
677
- (_a = this.intersectionObserver) == null ? void 0 : _a.disconnect();
678
- }
679
- }
744
+ setupVisibilityManager() {
745
+ this.visibilityManager = new VisibilityManager(this.container, {
746
+ threshold: this.config.threshold,
747
+ rootMargin: this.config.rootMargin,
748
+ onVisible: () => {
749
+ if (!this.hasTriggered && this.config.enabled) {
750
+ this.hasTriggered = true;
751
+ setTimeout(() => this.start(), this.config.delay);
680
752
  }
681
753
  },
682
- {
683
- threshold: this.config.threshold,
684
- rootMargin: this.config.rootMargin
754
+ onHidden: () => {
685
755
  }
686
- );
687
- this.intersectionObserver.observe(this.container);
756
+ });
688
757
  }
689
- // 글자에 해당하는 단위 개수
690
- initializeTextStructure() {
691
- this.originalChars = [];
692
- this.charUnitMap = [];
693
- for (let i = 0; i < this.originalText.length; i++) {
694
- const char = this.originalText[i];
695
- const code = char.charCodeAt(0);
696
- this.originalChars.push(char);
697
- if (code >= 44032 && code <= 55203) {
698
- const decomposed = decomposeHangul(char);
699
- this.charUnitMap.push(decomposed.length);
700
- } else {
701
- this.charUnitMap.push(1);
758
+ // 단위들을 다시 합쳐서 실제 표시할 텍스트 생성
759
+ // 한글의 경우 자음/모음이 하나씩 보이도록 합성
760
+ buildTextFromUnits(unitCount) {
761
+ if (unitCount === 0) return "";
762
+ let result = "";
763
+ for (let charIndex = 0; charIndex < this.charUnitRanges.length; charIndex++) {
764
+ const range = this.charUnitRanges[charIndex];
765
+ if (range.start >= unitCount) {
766
+ break;
702
767
  }
703
- }
704
- }
705
- // 단위 인덱스를 원본 텍스트의 글자 인덱스로 변환
706
- // unitIndex: 현재까지 입력된 단위 개수 (0부터 시작)
707
- // 반환: 표시할 글자 개수 (0부터 시작, exclusive)
708
- getCharIndexFromUnitIndex(unitIndex) {
709
- if (unitIndex === 0) return 0;
710
- let charIndex = 0;
711
- let currentUnits = 0;
712
- for (let i = 0; i < this.charUnitMap.length; i++) {
713
- const unitsForChar = this.charUnitMap[i];
714
- currentUnits += unitsForChar;
715
- if (unitIndex >= currentUnits) {
716
- charIndex = i + 1;
768
+ const unitsEntered = Math.min(unitCount - range.start, range.end - range.start);
769
+ if (unitsEntered <= 0) {
770
+ break;
771
+ }
772
+ if (range.isHangul) {
773
+ const charUnits = this.textUnits.slice(range.start, range.start + unitsEntered);
774
+ if (charUnits.length === 1) {
775
+ result += charUnits[0];
776
+ } else if (charUnits.length === 2) {
777
+ result += composeHangul(charUnits[0], charUnits[1]);
778
+ } else if (charUnits.length >= 3) {
779
+ result += composeHangul(charUnits[0], charUnits[1], charUnits[2]);
780
+ }
717
781
  } else {
718
- const unitsEntered = unitIndex - (currentUnits - unitsForChar);
719
782
  if (unitsEntered > 0) {
720
- const isHangul = this.originalChars[i] && this.originalChars[i].charCodeAt(0) >= 44032 && this.originalChars[i].charCodeAt(0) <= 55203;
721
- if (isHangul && unitsEntered >= 2) {
722
- charIndex = i + 1;
723
- } else if (!isHangul && unitsEntered >= 1) {
724
- charIndex = i + 1;
725
- }
783
+ result += this.textUnits[range.start];
726
784
  }
727
- break;
728
785
  }
729
786
  }
730
- return charIndex;
731
- }
732
- // 단위들을 다시 합쳐서 실제 표시할 텍스트 생성
733
- buildTextFromUnits(units) {
734
- if (units.length === 0) return "";
735
- const charIndex = this.getCharIndexFromUnitIndex(units.length);
736
- return this.originalText.substring(0, charIndex);
787
+ return result;
737
788
  }
738
789
  start() {
739
790
  if (this.isRunning) return;
@@ -753,8 +804,7 @@ class Typing {
753
804
  }
754
805
  return;
755
806
  }
756
- const unitsToShow = this.textUnits.slice(0, this.currentIndex + 1);
757
- this.displayedText = this.buildTextFromUnits(unitsToShow);
807
+ this.displayedText = this.buildTextFromUnits(this.currentIndex + 1);
758
808
  let displayText = this.displayedText;
759
809
  if (this.config.showCursor) {
760
810
  displayText += this.config.cursorChar;
@@ -789,8 +839,9 @@ class Typing {
789
839
  setText(newText) {
790
840
  this.originalText = newText;
791
841
  this.config.text = newText;
792
- this.textUnits = decomposeText(newText);
793
- this.initializeTextStructure();
842
+ const decomposed = decomposeText(newText);
843
+ this.textUnits = decomposed.units;
844
+ this.charUnitRanges = decomposed.charUnitRanges;
794
845
  this.reset();
795
846
  if (this.config.enabled) {
796
847
  setTimeout(() => this.start(), this.config.delay);
@@ -798,9 +849,9 @@ class Typing {
798
849
  }
799
850
  destroy() {
800
851
  this.stop();
801
- if (this.intersectionObserver) {
802
- this.intersectionObserver.disconnect();
803
- this.intersectionObserver = null;
852
+ if (this.visibilityManager) {
853
+ this.visibilityManager.destroy();
854
+ this.visibilityManager = null;
804
855
  }
805
856
  }
806
857
  }
@@ -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",{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;
1
+ "use strict";const t=require("vue");class i{constructor(t,i={}){this.container=t,this.options={threshold:i.threshold??.1,rootMargin:i.rootMargin??"0px",onVisible:i.onVisible,onHidden:i.onHidden},this.intersectionObserver=null,this.visibilityChangeHandler=null,this.isVisible=!1,this.isPageVisible="undefined"==typeof document||!document.hidden,this.setupIntersectionObserver(),this.setupPageVisibility()}setupIntersectionObserver(){if("undefined"==typeof window||void 0===window.IntersectionObserver)return this.isVisible=!0,void(this.isPageVisible&&this.options.onVisible&&this.options.onVisible());this.intersectionObserver=new IntersectionObserver(t=>{for(const i of t)i.target===this.container&&(i.isIntersecting?(this.isVisible=!0,this.isPageVisible&&this.options.onVisible&&this.options.onVisible()):(this.isVisible=!1,this.options.onHidden&&this.options.onHidden()))},{threshold:this.options.threshold,rootMargin:this.options.rootMargin}),this.intersectionObserver.observe(this.container)}setupPageVisibility(){"undefined"!=typeof document&&(this.visibilityChangeHandler=()=>{const t=this.isPageVisible;this.isPageVisible=!document.hidden,document.hidden?this.options.onHidden&&this.options.onHidden():t!==this.isPageVisible&&this.isVisible&&this.options.onVisible&&this.options.onVisible()},document.addEventListener("visibilitychange",this.visibilityChangeHandler),document.hidden&&this.isVisible&&this.options.onHidden&&this.options.onHidden())}getIsVisible(){return this.isVisible&&this.isPageVisible}updateOptions(t){this.options={...this.options,...t},this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null),this.setupIntersectionObserver()}destroy(){this.intersectionObserver&&(this.intersectionObserver.disconnect(),this.intersectionObserver=null),this.visibilityChangeHandler&&"undefined"!=typeof document&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null)}}function e(t,i){let e=null;return function(...s){null!==e&&clearTimeout(e),e=setTimeout(()=>{e=null,t.apply(this,s)},i)}}class s{constructor(t,i={}){if(this.container="string"==typeof t?document.querySelector(t):t,!this.container)throw new Error("Container element not found");this.config={text:i.text||"mason effect",densityStep:i.densityStep??2,maxParticles:i.maxParticles??3200,pointSize:i.pointSize??.5,ease:i.ease??.05,repelRadius:i.repelRadius??150,repelStrength:i.repelStrength??1,particleColor:i.particleColor||"#fff",fontFamily:i.fontFamily||"Inter, system-ui, Arial",fontSize:i.fontSize||null,width:i.width||null,height:i.height||null,devicePixelRatio:i.devicePixelRatio??null,onReady:i.onReady||null,onUpdate:i.onUpdate||null},this.canvas=document.createElement("canvas");const s=this.canvas.getContext("2d",{willReadFrequently:!0});if(!s)throw new Error("Canvas context not available");this.ctx=s,this.container.appendChild(this.canvas),this.canvas.style.display="block",this.offCanvas=document.createElement("canvas");const n=this.offCanvas.getContext("2d",{willReadFrequently:!0});if(!n)throw new Error("Offscreen canvas context not available");this.offCtx=n,this.W=0,this.H=0,this.DPR=this.config.devicePixelRatio||Math.min(window.devicePixelRatio||1,1.8),this.particles=[],this.mouse={x:0,y:0,down:!1},this.animationId=null,this.isRunning=!1,this.visibilityManager=null,this.debounceDelay=i.debounceDelay??150;const o=this.handleResize.bind(this);this.handleResize=e(o,this.debounceDelay),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseLeave=this.handleMouseLeave.bind(this),this.handleMouseDown=this.handleMouseDown.bind(this),this.handleMouseUp=this.handleMouseUp.bind(this),this._debouncedMorph=e(this._morphInternal.bind(this),this.debounceDelay),this._debouncedUpdateConfig=e(this._updateConfigInternal.bind(this),this.debounceDelay),this.init()}init(){this.resize(),this.setupEventListeners(),this.setupVisibilityManager(),this.config.onReady&&this.config.onReady(this)}setupVisibilityManager(){this.visibilityManager=new i(this.container,{threshold:.1,onVisible:()=>{this.start()},onHidden:()=>{this.stop()}})}resize(){const t=this.config.width||this.container.clientWidth||window.innerWidth,i=this.config.height||this.container.clientHeight||.7*window.innerHeight;if(t<=0||i<=0)return;this.W=Math.floor(t*this.DPR),this.H=Math.floor(i*this.DPR);const e=4096;if(this.W>e||this.H>e){const t=Math.min(e/this.W,e/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=i+"px",this.W>0&&this.H>0&&(this.buildTargets(),this.particles.length||this.initParticles())}measureTextFit(t,i,e,s){this.offCtx.font=`400 ${t}px ${this.config.fontFamily}`;const n=i.split("\n"),o=t,h=.1*t,a=.05*t;let l=0;for(const d of n){if(0===d.length)continue;const t=this.offCtx.measureText(d).width+a*(d.length>0?d.length-1:0);l=Math.max(l,t)}const r=n.length>0?o*n.length+h*(n.length-1):o;return{width:l,height:r,fits:l<=e&&r<=s}}findOptimalFontSize(t,i,e,s){if(this.measureTextFit(s,t,i,e).fits)return s;if(s<=12)return 12;let n=12,o=s,h=12;for(;n<=o;){const s=Math.floor((n+o)/2);this.measureTextFit(s,t,i,e).fits?(h=s,n=s+1):o=s-1}return h}buildTargets(){if(this.W<=0||this.H<=0)return;const t=this.config.text;this.offCanvas.width=this.W,this.offCanvas.height=this.H,this.offCtx.clearRect(0,0,this.offCanvas.width,this.offCanvas.height);const i=Math.min(this.W,this.H),e=this.config.fontSize||Math.max(80,Math.floor(.18*i)),s=this.W-80,n=this.H-80,o=this.findOptimalFontSize(t,s,n,e);this.offCtx.fillStyle="#ffffff",this.offCtx.textAlign="center",this.offCtx.textBaseline="middle",this.offCtx.font=`400 ${o}px ${this.config.fontFamily}`;const h=t.split("\n"),a=o,l=.1*o,r=.05*o,d=h.length>0?a*h.length+l*(h.length-1):a;let c=this.H/2-d/2+a/2;for(const g of h){if(0===g.length){c+=a+l;continue}const t=g.split(""),i=this.offCtx.measureText(g).width+r*(t.length>0?t.length-1:0);let e=this.W/2-i/2;for(const s of t)this.offCtx.fillText(s,e+this.offCtx.measureText(s).width/2,c),e+=this.offCtx.measureText(s).width+r;c+=a+l}const f=Math.max(2,this.config.densityStep),u=this.offCtx.getImageData(0,0,this.W,this.H).data,p=[];for(let g=0;g<this.H;g+=f)for(let t=0;t<this.W;t+=f){const i=4*(g*this.W+t);u[i]+u[i+1]+u[i+2]>600&&p.push({x:t,y:g})}for(;p.length>this.config.maxParticles;)p.splice(Math.floor(Math.random()*p.length),1);if(this.particles.length<p.length){const t=p.length-this.particles.length;for(let i=0;i<t;i++)this.particles.push(this.makeParticle())}else this.particles.length>p.length&&(this.particles.length=p.length);for(let g=0;g<this.particles.length;g++){const t=this.particles[g],i=p[g];t.tx=i.x,t.ty=i.y}}makeParticle(){const t=Math.random()*this.W,i=Math.random()*this.H;return{x:t,y:i,vx:0,vy:0,tx:t,ty:i,initialX:t,initialY:i,j:Math.random()*Math.PI*2}}initParticles(){for(const t of this.particles){const i=Math.random()*this.W,e=Math.random()*this.H;t.x=i,t.y=e,t.vx=t.vy=0,t.initialX=i,t.initialY=e}}scatter(){for(const t of this.particles)void 0!==t.initialX&&void 0!==t.initialY?(t.tx=t.initialX,t.ty=t.initialY):(t.initialX=t.x,t.initialY=t.y,t.tx=t.initialX,t.ty=t.initialY)}morph(t){this._debouncedMorph(t)}_morphInternal(t){if(0!==this.W&&0!==this.H||this.resize(),"string"==typeof t)this.config.text=t,this.buildTargets();else if(t&&"object"==typeof t){const i=void 0!==t.text;this.config={...this.config,...t},i&&this.buildTargets()}else this.buildTargets()}update(){this.ctx.clearRect(0,0,this.W,this.H);for(const s of this.particles){let t=(s.tx-s.x)*this.config.ease,i=(s.ty-s.y)*this.config.ease;if(this.mouse.x||this.mouse.y){const e=s.x-this.mouse.x,n=s.y-this.mouse.y,o=e*e+n*n,h=this.config.repelRadius*this.DPR;if(o<h*h){const s=Math.sqrt(o)+1e-4,a=(this.mouse.down?-1:1)*this.config.repelStrength*(1-s/h);t+=e/s*a*6,i+=n/s*a*6}}s.j+=2,t+=.05*Math.cos(s.j),i+=.05*Math.sin(1.3*s.j),s.vx=(s.vx+t)*Math.random(),s.vy=(s.vy+i)*Math.random(),s.x+=s.vx,s.y+=s.vy}this.ctx.fillStyle=this.config.particleColor;const t=Math.min(this.W,this.H)/this.DPR,i=Math.max(.5,Math.min(2,t/1920)),e=this.config.pointSize*this.DPR*i;for(const s of this.particles)this.ctx.beginPath(),this.ctx.arc(s.x,s.y,e,0,2*Math.PI),this.ctx.fill();this.config.onUpdate&&this.config.onUpdate(this)}animate(){this.isRunning&&(this.update(),this.animationId=requestAnimationFrame(()=>this.animate()))}start(){this.isRunning||(this.isRunning=!0,this.animate())}stop(){this.isRunning=!1,this.animationId&&(cancelAnimationFrame(this.animationId),this.animationId=null)}setupEventListeners(){window.addEventListener("resize",this.handleResize),this.canvas.addEventListener("mousemove",this.handleMouseMove),this.canvas.addEventListener("mouseleave",this.handleMouseLeave),this.canvas.addEventListener("mousedown",this.handleMouseDown),window.addEventListener("mouseup",this.handleMouseUp)}removeEventListeners(){window.removeEventListener("resize",this.handleResize),this.canvas.removeEventListener("mousemove",this.handleMouseMove),this.canvas.removeEventListener("mouseleave",this.handleMouseLeave),this.canvas.removeEventListener("mousedown",this.handleMouseDown),window.removeEventListener("mouseup",this.handleMouseUp)}handleResize(){this.resize()}handleMouseMove(t){const i=this.canvas.getBoundingClientRect();this.mouse.x=(t.clientX-i.left)*this.DPR,this.mouse.y=(t.clientY-i.top)*this.DPR}handleMouseLeave(){this.mouse.x=this.mouse.y=0}handleMouseDown(){this.mouse.down=!0}handleMouseUp(){this.mouse.down=!1}updateConfig(t){this._debouncedUpdateConfig(t)}_updateConfigInternal(t){this.config={...this.config,...t},t.text&&this.buildTargets()}destroy(){this.stop(),this.removeEventListeners(),this.visibilityManager&&(this.visibilityManager.destroy(),this.visibilityManager=null),this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas)}}const n=t.defineComponent({__name:"TextToParticle",props:{className:{default:""},style:{default:()=>({})},text:{default:"mason effect"},densityStep:{default:2},maxParticles:{default:3200},pointSize:{default:.5},ease:{default:.05},repelRadius:{default:150},repelStrength:{default:1},particleColor:{default:"#fff"},fontFamily:{default:"Inter, system-ui, Arial"},fontSize:{default:null},width:{default:null},height:{default:null},devicePixelRatio:{default:null},debounceDelay:{},onReady:{type:Function,default:null},onUpdate:{type:Function,default:null}},emits:["ready","update"],setup(i,{expose:e,emit:n}){const o=i,h=n,a=t.ref(null);let l=null;return t.watch(()=>[o.text,o.densityStep,o.maxParticles,o.pointSize,o.ease,o.repelRadius,o.repelStrength,o.particleColor,o.fontFamily,o.fontSize,o.width,o.height,o.devicePixelRatio],()=>{l&&l.updateConfig({text:o.text,densityStep:o.densityStep,maxParticles:o.maxParticles,pointSize:o.pointSize,ease:o.ease,repelRadius:o.repelRadius,repelStrength:o.repelStrength,particleColor:o.particleColor,fontFamily:o.fontFamily,fontSize:o.fontSize,width:o.width,height:o.height,devicePixelRatio:o.devicePixelRatio})}),t.onMounted(()=>{(()=>{if(!a.value)return;const t={text:o.text,densityStep:o.densityStep,maxParticles:o.maxParticles,pointSize:o.pointSize,ease:o.ease,repelRadius:o.repelRadius,repelStrength:o.repelStrength,particleColor:o.particleColor,fontFamily:o.fontFamily,fontSize:o.fontSize,width:o.width,height:o.height,devicePixelRatio:o.devicePixelRatio,onReady:t=>{o.onReady&&o.onReady(t),h("ready",t)},onUpdate:t=>{o.onUpdate&&o.onUpdate(t),h("update",t)}};l=new s(a.value,t)})()}),t.onBeforeUnmount(()=>{l&&(l.destroy(),l=null)}),e({morph:t=>{l&&l.morph(t)},scatter:()=>{l&&l.scatter()},updateConfig:t=>{l&&l.updateConfig(t)},destroy:()=>{l&&(l.destroy(),l=null)}}),(e,s)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"container",ref:a,class:t.normalizeClass(i.className),style:t.normalizeStyle(i.style)},null,6))}});module.exports=n;