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
@@ -276,6 +276,107 @@ class SvelteComponent {
276
276
  const PUBLIC_VERSION = "4";
277
277
  if (typeof window !== "undefined")
278
278
  (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(PUBLIC_VERSION);
279
+ class VisibilityManager {
280
+ constructor(container, options = {}) {
281
+ this.container = container;
282
+ this.options = {
283
+ threshold: options.threshold ?? 0.1,
284
+ rootMargin: options.rootMargin ?? "0px",
285
+ onVisible: options.onVisible,
286
+ onHidden: options.onHidden
287
+ };
288
+ this.intersectionObserver = null;
289
+ this.visibilityChangeHandler = null;
290
+ this.isVisible = false;
291
+ this.isPageVisible = typeof document !== "undefined" ? !document.hidden : true;
292
+ this.setupIntersectionObserver();
293
+ this.setupPageVisibility();
294
+ }
295
+ setupIntersectionObserver() {
296
+ if (typeof window === "undefined" || typeof window.IntersectionObserver === "undefined") {
297
+ this.isVisible = true;
298
+ if (this.isPageVisible && this.options.onVisible) {
299
+ this.options.onVisible();
300
+ }
301
+ return;
302
+ }
303
+ this.intersectionObserver = new IntersectionObserver(
304
+ (entries) => {
305
+ for (const entry of entries) {
306
+ if (entry.target !== this.container) continue;
307
+ if (entry.isIntersecting) {
308
+ this.isVisible = true;
309
+ if (this.isPageVisible && this.options.onVisible) {
310
+ this.options.onVisible();
311
+ }
312
+ } else {
313
+ this.isVisible = false;
314
+ if (this.options.onHidden) {
315
+ this.options.onHidden();
316
+ }
317
+ }
318
+ }
319
+ },
320
+ {
321
+ threshold: this.options.threshold,
322
+ rootMargin: this.options.rootMargin
323
+ }
324
+ );
325
+ this.intersectionObserver.observe(this.container);
326
+ }
327
+ setupPageVisibility() {
328
+ if (typeof document === "undefined") return;
329
+ this.visibilityChangeHandler = () => {
330
+ const wasVisible = this.isPageVisible;
331
+ this.isPageVisible = !document.hidden;
332
+ if (document.hidden) {
333
+ if (this.options.onHidden) {
334
+ this.options.onHidden();
335
+ }
336
+ } else if (wasVisible !== this.isPageVisible) {
337
+ if (this.isVisible && this.options.onVisible) {
338
+ this.options.onVisible();
339
+ }
340
+ }
341
+ };
342
+ document.addEventListener("visibilitychange", this.visibilityChangeHandler);
343
+ if (document.hidden && this.isVisible) {
344
+ if (this.options.onHidden) {
345
+ this.options.onHidden();
346
+ }
347
+ }
348
+ }
349
+ /**
350
+ * 현재 요소가 화면에 보이는지 확인
351
+ */
352
+ getIsVisible() {
353
+ return this.isVisible && this.isPageVisible;
354
+ }
355
+ /**
356
+ * 옵션 업데이트
357
+ */
358
+ updateOptions(newOptions) {
359
+ this.options = { ...this.options, ...newOptions };
360
+ if (this.intersectionObserver) {
361
+ this.intersectionObserver.disconnect();
362
+ this.intersectionObserver = null;
363
+ }
364
+ this.setupIntersectionObserver();
365
+ }
366
+ /**
367
+ * 리소스 정리
368
+ */
369
+ destroy() {
370
+ if (this.intersectionObserver) {
371
+ this.intersectionObserver.disconnect();
372
+ this.intersectionObserver = null;
373
+ }
374
+ if (this.visibilityChangeHandler && typeof document !== "undefined") {
375
+ document.removeEventListener("visibilitychange", this.visibilityChangeHandler);
376
+ this.visibilityChangeHandler = null;
377
+ }
378
+ }
379
+ }
279
380
  function debounce(func, wait) {
280
381
  let timeout = null;
281
382
  return function executedFunction(...args) {
@@ -333,8 +434,7 @@ class TextToParticle {
333
434
  this.mouse = { x: 0, y: 0, down: false };
334
435
  this.animationId = null;
335
436
  this.isRunning = false;
336
- this.isVisible = false;
337
- this.intersectionObserver = null;
437
+ this.visibilityManager = null;
338
438
  this.debounceDelay = options.debounceDelay ?? 150;
339
439
  const boundHandleResize = this.handleResize.bind(this);
340
440
  this.handleResize = debounce(boundHandleResize, this.debounceDelay);
@@ -349,39 +449,22 @@ class TextToParticle {
349
449
  init() {
350
450
  this.resize();
351
451
  this.setupEventListeners();
352
- this.setupIntersectionObserver();
452
+ this.setupVisibilityManager();
353
453
  if (this.config.onReady) {
354
454
  this.config.onReady(this);
355
455
  }
356
456
  }
357
- setupIntersectionObserver() {
358
- if (typeof window === "undefined" || typeof window.IntersectionObserver === "undefined") {
359
- this.isVisible = true;
360
- this.start();
361
- return;
362
- }
363
- if (this.intersectionObserver) {
364
- return;
365
- }
366
- this.intersectionObserver = new IntersectionObserver(
367
- (entries) => {
368
- for (const entry of entries) {
369
- if (entry.target !== this.container) continue;
370
- if (entry.isIntersecting) {
371
- this.isVisible = true;
372
- this.start();
373
- } else {
374
- this.isVisible = false;
375
- this.stop();
376
- }
377
- }
457
+ setupVisibilityManager() {
458
+ this.visibilityManager = new VisibilityManager(this.container, {
459
+ threshold: 0.1,
460
+ // 10% 이상 보일 때 동작
461
+ onVisible: () => {
462
+ this.start();
378
463
  },
379
- {
380
- threshold: 0.1
381
- // 10% 이상 보일 때 동작
464
+ onHidden: () => {
465
+ this.stop();
382
466
  }
383
- );
384
- this.intersectionObserver.observe(this.container);
467
+ });
385
468
  }
386
469
  resize() {
387
470
  const width = this.config.width || this.container.clientWidth || window.innerWidth;
@@ -618,7 +701,10 @@ class TextToParticle {
618
701
  p.y += p.vy;
619
702
  }
620
703
  this.ctx.fillStyle = this.config.particleColor;
621
- const r = this.config.pointSize * this.DPR;
704
+ const baseSize = 1920;
705
+ const currentSize = Math.min(this.W, this.H) / this.DPR;
706
+ const sizeRatio = Math.max(0.5, Math.min(2, currentSize / baseSize));
707
+ const r = this.config.pointSize * this.DPR * sizeRatio;
622
708
  for (const p of this.particles) {
623
709
  this.ctx.beginPath();
624
710
  this.ctx.arc(p.x, p.y, r, 0, Math.PI * 2);
@@ -690,9 +776,9 @@ class TextToParticle {
690
776
  destroy() {
691
777
  this.stop();
692
778
  this.removeEventListeners();
693
- if (this.intersectionObserver) {
694
- this.intersectionObserver.disconnect();
695
- this.intersectionObserver = null;
779
+ if (this.visibilityManager) {
780
+ this.visibilityManager.destroy();
781
+ this.visibilityManager = null;
696
782
  }
697
783
  if (this.canvas && this.canvas.parentNode) {
698
784
  this.canvas.parentNode.removeChild(this.canvas);
@@ -723,54 +809,31 @@ class Count {
723
809
  this.currentValue = this.config.startValue;
724
810
  this.startTime = null;
725
811
  this.animationFrameId = null;
726
- this.intersectionObserver = null;
812
+ this.visibilityManager = null;
727
813
  this.isRunning = false;
728
814
  this.hasTriggered = false;
729
815
  this.init();
730
816
  }
731
817
  init() {
732
818
  this.updateDisplay(this.config.startValue);
733
- this.setupIntersectionObserver();
734
- }
735
- setupIntersectionObserver() {
736
- if (typeof window === "undefined" || typeof window.IntersectionObserver === "undefined") {
737
- if (this.config.enabled) {
738
- this.start();
739
- }
740
- return;
741
- }
742
- this.intersectionObserver = new IntersectionObserver(
743
- (entries) => {
744
- var _a;
745
- for (const entry of entries) {
746
- if (entry.target !== this.container) continue;
747
- if (entry.isIntersecting) {
748
- if (!this.hasTriggered && this.config.enabled) {
749
- this.hasTriggered = true;
750
- this.start();
751
- }
752
- if (this.config.triggerOnce) {
753
- (_a = this.intersectionObserver) == null ? void 0 : _a.unobserve(this.container);
754
- }
755
- } else {
756
- if (!this.config.triggerOnce) {
757
- const rect = entry.boundingClientRect;
758
- const viewportHeight = window.innerHeight;
759
- const viewportWidth = window.innerWidth;
760
- const isCompletelyOutOfViewport = rect.bottom <= 0 || rect.top >= viewportHeight || rect.right <= 0 || rect.left >= viewportWidth;
761
- if (isCompletelyOutOfViewport && this.isRunning) {
762
- this.reset();
763
- }
764
- }
765
- }
819
+ this.setupVisibilityManager();
820
+ }
821
+ setupVisibilityManager() {
822
+ this.visibilityManager = new VisibilityManager(this.container, {
823
+ threshold: this.config.threshold,
824
+ rootMargin: this.config.rootMargin,
825
+ onVisible: () => {
826
+ if (!this.hasTriggered && this.config.enabled) {
827
+ this.hasTriggered = true;
828
+ this.start();
766
829
  }
767
830
  },
768
- {
769
- threshold: this.config.threshold,
770
- rootMargin: this.config.rootMargin
831
+ onHidden: () => {
832
+ if (!this.config.triggerOnce && this.isRunning) {
833
+ this.reset();
834
+ }
771
835
  }
772
- );
773
- this.intersectionObserver.observe(this.container);
836
+ });
774
837
  }
775
838
  start() {
776
839
  if (this.isRunning) return;
@@ -854,9 +917,9 @@ class Count {
854
917
  // 파괴 및 정리
855
918
  destroy() {
856
919
  this.stop();
857
- if (this.intersectionObserver) {
858
- this.intersectionObserver.disconnect();
859
- this.intersectionObserver = null;
920
+ if (this.visibilityManager) {
921
+ this.visibilityManager.destroy();
922
+ this.visibilityManager = null;
860
923
  }
861
924
  }
862
925
  }
@@ -880,25 +943,48 @@ function decomposeHangul(char) {
880
943
  }
881
944
  return result;
882
945
  }
946
+ function composeHangul(initial, medial, final) {
947
+ const initialChars = ["ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
948
+ const medialChars = ["ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ"];
949
+ const finalChars = ["", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"];
950
+ const initialIndex = initialChars.indexOf(initial);
951
+ const medialIndex = medialChars.indexOf(medial);
952
+ const finalIndex = final ? finalChars.indexOf(final) : 0;
953
+ if (initialIndex === -1 || medialIndex === -1) {
954
+ return initial + (medial || "") + (final || "");
955
+ }
956
+ const code = 44032 + initialIndex * 21 * 28 + medialIndex * 28 + finalIndex;
957
+ return String.fromCharCode(code);
958
+ }
883
959
  function decomposeText(text) {
884
960
  const units = [];
961
+ const charUnitRanges = [];
885
962
  for (let i = 0; i < text.length; i++) {
886
963
  const char = text[i];
887
964
  const code = char.charCodeAt(0);
965
+ const startIndex = units.length;
888
966
  if (code >= 44032 && code <= 55203) {
889
967
  const decomposed = decomposeHangul(char);
890
968
  units.push(...decomposed);
969
+ charUnitRanges.push({
970
+ start: startIndex,
971
+ end: units.length,
972
+ isHangul: true
973
+ });
891
974
  } else {
892
975
  units.push(char);
976
+ charUnitRanges.push({
977
+ start: startIndex,
978
+ end: units.length,
979
+ isHangul: false
980
+ });
893
981
  }
894
982
  }
895
- return units;
983
+ return { units, charUnitRanges };
896
984
  }
897
985
  class Typing {
898
986
  // 원본 텍스트
899
987
  constructor(container, options) {
900
- this.originalChars = [];
901
- this.charUnitMap = [];
902
988
  this.container = typeof container === "string" ? document.querySelector(container) : container;
903
989
  if (!this.container) {
904
990
  throw new Error("Container element not found");
@@ -917,100 +1003,65 @@ class Typing {
917
1003
  onUpdate: options.onUpdate || null,
918
1004
  onComplete: options.onComplete || null
919
1005
  };
920
- this.textUnits = decomposeText(this.config.text);
921
- this.originalChars = [];
922
- this.charUnitMap = [];
923
- this.initializeTextStructure();
1006
+ const decomposed = decomposeText(this.config.text);
1007
+ this.textUnits = decomposed.units;
1008
+ this.charUnitRanges = decomposed.charUnitRanges;
924
1009
  this.currentIndex = 0;
925
1010
  this.displayedText = "";
926
1011
  this.timeoutId = null;
927
- this.intersectionObserver = null;
1012
+ this.visibilityManager = null;
928
1013
  this.isRunning = false;
929
1014
  this.hasTriggered = false;
930
1015
  this.init();
931
1016
  }
932
1017
  init() {
933
1018
  this.updateDisplay("");
934
- this.setupIntersectionObserver();
935
- }
936
- setupIntersectionObserver() {
937
- if (typeof window === "undefined" || typeof window.IntersectionObserver === "undefined") {
938
- if (this.config.enabled) {
939
- setTimeout(() => this.start(), this.config.delay);
940
- }
941
- return;
942
- }
943
- this.intersectionObserver = new IntersectionObserver(
944
- (entries) => {
945
- var _a;
946
- for (const entry of entries) {
947
- if (entry.target !== this.container) continue;
948
- if (entry.isIntersecting && !this.hasTriggered) {
949
- if (this.config.enabled) {
950
- setTimeout(() => this.start(), this.config.delay);
951
- }
952
- this.hasTriggered = true;
953
- if (this.config.triggerOnce) {
954
- (_a = this.intersectionObserver) == null ? void 0 : _a.disconnect();
955
- }
956
- }
1019
+ this.setupVisibilityManager();
1020
+ }
1021
+ setupVisibilityManager() {
1022
+ this.visibilityManager = new VisibilityManager(this.container, {
1023
+ threshold: this.config.threshold,
1024
+ rootMargin: this.config.rootMargin,
1025
+ onVisible: () => {
1026
+ if (!this.hasTriggered && this.config.enabled) {
1027
+ this.hasTriggered = true;
1028
+ setTimeout(() => this.start(), this.config.delay);
957
1029
  }
958
1030
  },
959
- {
960
- threshold: this.config.threshold,
961
- rootMargin: this.config.rootMargin
1031
+ onHidden: () => {
962
1032
  }
963
- );
964
- this.intersectionObserver.observe(this.container);
1033
+ });
965
1034
  }
966
- // 글자에 해당하는 단위 개수
967
- initializeTextStructure() {
968
- this.originalChars = [];
969
- this.charUnitMap = [];
970
- for (let i = 0; i < this.originalText.length; i++) {
971
- const char = this.originalText[i];
972
- const code = char.charCodeAt(0);
973
- this.originalChars.push(char);
974
- if (code >= 44032 && code <= 55203) {
975
- const decomposed = decomposeHangul(char);
976
- this.charUnitMap.push(decomposed.length);
977
- } else {
978
- this.charUnitMap.push(1);
1035
+ // 단위들을 다시 합쳐서 실제 표시할 텍스트 생성
1036
+ // 한글의 경우 자음/모음이 하나씩 보이도록 합성
1037
+ buildTextFromUnits(unitCount) {
1038
+ if (unitCount === 0) return "";
1039
+ let result = "";
1040
+ for (let charIndex = 0; charIndex < this.charUnitRanges.length; charIndex++) {
1041
+ const range = this.charUnitRanges[charIndex];
1042
+ if (range.start >= unitCount) {
1043
+ break;
979
1044
  }
980
- }
981
- }
982
- // 단위 인덱스를 원본 텍스트의 글자 인덱스로 변환
983
- // unitIndex: 현재까지 입력된 단위 개수 (0부터 시작)
984
- // 반환: 표시할 글자 개수 (0부터 시작, exclusive)
985
- getCharIndexFromUnitIndex(unitIndex) {
986
- if (unitIndex === 0) return 0;
987
- let charIndex = 0;
988
- let currentUnits = 0;
989
- for (let i = 0; i < this.charUnitMap.length; i++) {
990
- const unitsForChar = this.charUnitMap[i];
991
- currentUnits += unitsForChar;
992
- if (unitIndex >= currentUnits) {
993
- charIndex = i + 1;
1045
+ const unitsEntered = Math.min(unitCount - range.start, range.end - range.start);
1046
+ if (unitsEntered <= 0) {
1047
+ break;
1048
+ }
1049
+ if (range.isHangul) {
1050
+ const charUnits = this.textUnits.slice(range.start, range.start + unitsEntered);
1051
+ if (charUnits.length === 1) {
1052
+ result += charUnits[0];
1053
+ } else if (charUnits.length === 2) {
1054
+ result += composeHangul(charUnits[0], charUnits[1]);
1055
+ } else if (charUnits.length >= 3) {
1056
+ result += composeHangul(charUnits[0], charUnits[1], charUnits[2]);
1057
+ }
994
1058
  } else {
995
- const unitsEntered = unitIndex - (currentUnits - unitsForChar);
996
1059
  if (unitsEntered > 0) {
997
- const isHangul = this.originalChars[i] && this.originalChars[i].charCodeAt(0) >= 44032 && this.originalChars[i].charCodeAt(0) <= 55203;
998
- if (isHangul && unitsEntered >= 2) {
999
- charIndex = i + 1;
1000
- } else if (!isHangul && unitsEntered >= 1) {
1001
- charIndex = i + 1;
1002
- }
1060
+ result += this.textUnits[range.start];
1003
1061
  }
1004
- break;
1005
1062
  }
1006
1063
  }
1007
- return charIndex;
1008
- }
1009
- // 단위들을 다시 합쳐서 실제 표시할 텍스트 생성
1010
- buildTextFromUnits(units) {
1011
- if (units.length === 0) return "";
1012
- const charIndex = this.getCharIndexFromUnitIndex(units.length);
1013
- return this.originalText.substring(0, charIndex);
1064
+ return result;
1014
1065
  }
1015
1066
  start() {
1016
1067
  if (this.isRunning) return;
@@ -1030,8 +1081,7 @@ class Typing {
1030
1081
  }
1031
1082
  return;
1032
1083
  }
1033
- const unitsToShow = this.textUnits.slice(0, this.currentIndex + 1);
1034
- this.displayedText = this.buildTextFromUnits(unitsToShow);
1084
+ this.displayedText = this.buildTextFromUnits(this.currentIndex + 1);
1035
1085
  let displayText = this.displayedText;
1036
1086
  if (this.config.showCursor) {
1037
1087
  displayText += this.config.cursorChar;
@@ -1066,8 +1116,9 @@ class Typing {
1066
1116
  setText(newText) {
1067
1117
  this.originalText = newText;
1068
1118
  this.config.text = newText;
1069
- this.textUnits = decomposeText(newText);
1070
- this.initializeTextStructure();
1119
+ const decomposed = decomposeText(newText);
1120
+ this.textUnits = decomposed.units;
1121
+ this.charUnitRanges = decomposed.charUnitRanges;
1071
1122
  this.reset();
1072
1123
  if (this.config.enabled) {
1073
1124
  setTimeout(() => this.start(), this.config.delay);
@@ -1075,9 +1126,9 @@ class Typing {
1075
1126
  }
1076
1127
  destroy() {
1077
1128
  this.stop();
1078
- if (this.intersectionObserver) {
1079
- this.intersectionObserver.disconnect();
1080
- this.intersectionObserver = null;
1129
+ if (this.visibilityManager) {
1130
+ this.visibilityManager.destroy();
1131
+ this.visibilityManager = null;
1081
1132
  }
1082
1133
  }
1083
1134
  }
@@ -1 +1 @@
1
- "use strict";var t=Object.defineProperty,e=(e,i,n)=>((e,i,n)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n)(e,"symbol"!=typeof i?i+"":i,n);const i=require("svelte");function n(){}function s(t){return t()}function o(){return Object.create(null)}function h(t){t.forEach(s)}function a(t){return"function"==typeof t}function r(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function l(t){t.parentNode&&t.parentNode.removeChild(t)}function c(t,e,i){null==i?t.removeAttribute(e):t.getAttribute(e)!==i&&t.setAttribute(e,i)}let f;function d(t){f=t}const u=[],p=[];let g=[];const m=[],v=Promise.resolve();let x=!1;function y(t){g.push(t)}const w=new Set;let b=0;function $(){if(0!==b)return;const t=f;do{try{for(;b<u.length;){const t=u[b];b++,d(t),M(t.$$)}}catch(e){throw u.length=0,b=0,e}for(d(null),u.length=0,b=0;p.length;)p.pop()();for(let t=0;t<g.length;t+=1){const e=g[t];w.has(e)||(w.add(e),e())}g.length=0}while(u.length);for(;m.length;)m.pop()();x=!1,w.clear(),d(t)}function M(t){if(null!==t.fragment){t.update(),h(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(y)}}const R=new Set;function C(t,e){const i=t.$$;null!==i.fragment&&(!function(t){const e=[],i=[];g.forEach(n=>-1===t.indexOf(n)?e.push(n):i.push(n)),i.forEach(t=>t()),g=e}(i.after_update),h(i.on_destroy),i.fragment&&i.fragment.d(e),i.on_destroy=i.fragment=null,i.ctx=[])}function S(t,e){-1===t.$$.dirty[0]&&(u.push(t),x||(x=!0,v.then($)),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function P(t,e,i,r,c,u,p=null,g=[-1]){const m=f;d(t);const v=t.$$={fragment:null,ctx:[],props:u,update:n,not_equal:c,bound:o(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(m?m.$$.context:[])),callbacks:o(),dirty:g,skip_bound:!1,root:e.target||m.$$.root};p&&p(v.root);let x=!1;if(v.ctx=i?i(t,e.props||{},(e,i,...n)=>{const s=n.length?n[0]:i;return v.ctx&&c(v.ctx[e],v.ctx[e]=s)&&(!v.skip_bound&&v.bound[e]&&v.bound[e](s),x&&S(t,e)),i}):[],v.update(),x=!0,h(v.before_update),v.fragment=!!r&&r(v.ctx),e.target){if(e.hydrate){const t=(M=e.target,Array.from(M.childNodes));v.fragment&&v.fragment.l(t),t.forEach(l)}else v.fragment&&v.fragment.c();e.intro&&((w=t.$$.fragment)&&w.i&&(R.delete(w),w.i(b))),function(t,e,i){const{fragment:n,after_update:o}=t.$$;n&&n.m(e,i),y(()=>{const e=t.$$.on_mount.map(s).filter(a);t.$$.on_destroy?t.$$.on_destroy.push(...e):h(e),t.$$.on_mount=[]}),o.forEach(y)}(t,e.target,e.anchor),$()}var w,b,M;d(m)}class _{constructor(){e(this,"$$"),e(this,"$$set")}$destroy(){C(this,1),this.$destroy=n}$on(t,e){if(!a(e))return n;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const t=i.indexOf(e);-1!==t&&i.splice(t,1)}}$set(t){var e;this.$$set&&(e=t,0!==Object.keys(e).length)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}function z(t,e){let i=null;return function(...n){null!==i&&clearTimeout(i),i=setTimeout(()=>{i=null,t.apply(this,n)},e)}}"undefined"!=typeof window&&(window.__svelte||(window.__svelte={v:new Set})).v.add("4");class E{constructor(t,e={}){if(this.container="string"==typeof t?document.querySelector(t):t,!this.container)throw new Error("Container element not found");this.config={text:e.text||"mason effect",densityStep:e.densityStep??2,maxParticles:e.maxParticles??3200,pointSize:e.pointSize??.5,ease:e.ease??.05,repelRadius:e.repelRadius??150,repelStrength:e.repelStrength??1,particleColor:e.particleColor||"#fff",fontFamily:e.fontFamily||"Inter, system-ui, Arial",fontSize:e.fontSize||null,width:e.width||null,height:e.height||null,devicePixelRatio:e.devicePixelRatio??null,onReady:e.onReady||null,onUpdate:e.onUpdate||null},this.canvas=document.createElement("canvas");const i=this.canvas.getContext("2d",{willReadFrequently:!0});if(!i)throw new Error("Canvas context not available");this.ctx=i,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=e.debounceDelay??150;const s=this.handleResize.bind(this);this.handleResize=z(s,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=z(this._morphInternal.bind(this),this.debounceDelay),this._debouncedUpdateConfig=z(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,h=.1*t,a=.05*t;let r=0;for(const c of s){if(0===c.length)continue;const t=this.offCtx.measureText(c).width+a*(c.length>0?c.length-1:0);r=Math.max(r,t)}const l=s.length>0?o*s.length+h*(s.length-1):o;return{width:r,height:l,fits:r<=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,h=12;for(;s<=o;){const n=Math.floor((s+o)/2);this.measureTextFit(n,t,e,i).fits?(h=n,s=n+1):o=n-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)),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 h=t.split("\n"),a=o,r=.1*o,l=.05*o,c=h.length>0?a*h.length+r*(h.length-1):a;let f=this.H/2-c/2+a/2;for(const g of h){if(0===g.length){f+=a+r;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,f),i+=this.offCtx.measureText(n).width+l;f+=a+r}const d=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+=d)for(let t=0;t<this.W;t+=d){const e=4*(g*this.W+t);u[e]+u[e+1]+u[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,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+=n/e*a*6,i+=s/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)}}function D(t){let e;return{c(){var i;i="div",e=document.createElement(i),c(e,"class",t[0]),c(e,"style",t[1])},m(i,n){!function(t,e,i){t.insertBefore(e,i||null)}(i,e,n),t[21](e)},p(t,[i]){1&i&&c(e,"class",t[0]),2&i&&c(e,"style",t[1])},i:n,o:n,d(i){i&&l(e),t[21](null)}}}function W(t,e,n){let{text:s="mason effect"}=e,{densityStep:o=2}=e,{maxParticles:h=3200}=e,{pointSize:a=.5}=e,{ease:r=.05}=e,{repelRadius:l=150}=e,{repelStrength:c=1}=e,{particleColor:f="#fff"}=e,{fontFamily:d="Inter, system-ui, Arial"}=e,{fontSize:u=null}=e,{width:g=null}=e,{height:m=null}=e,{devicePixelRatio:v=null}=e,{className:x=""}=e,{style:y={}}=e;const w=i.createEventDispatcher();let b,$=null;return i.onMount(()=>{if(!b)return;n(20,$=new E(b,{text:s,densityStep:o,maxParticles:h,pointSize:a,ease:r,repelRadius:l,repelStrength:c,particleColor:f,fontFamily:d,fontSize:u,width:g,height:m,devicePixelRatio:v,onReady:t=>{w("ready",t)},onUpdate:t=>{w("update",t)}}))}),i.onDestroy(()=>{$&&($.destroy(),n(20,$=null))}),t.$$set=t=>{"text"in t&&n(3,s=t.text),"densityStep"in t&&n(4,o=t.densityStep),"maxParticles"in t&&n(5,h=t.maxParticles),"pointSize"in t&&n(6,a=t.pointSize),"ease"in t&&n(7,r=t.ease),"repelRadius"in t&&n(8,l=t.repelRadius),"repelStrength"in t&&n(9,c=t.repelStrength),"particleColor"in t&&n(10,f=t.particleColor),"fontFamily"in t&&n(11,d=t.fontFamily),"fontSize"in t&&n(12,u=t.fontSize),"width"in t&&n(13,g=t.width),"height"in t&&n(14,m=t.height),"devicePixelRatio"in t&&n(15,v=t.devicePixelRatio),"className"in t&&n(0,x=t.className),"style"in t&&n(1,y=t.style)},t.$$.update=()=>{1114104&t.$$.dirty&&$&&$.updateConfig({text:s,densityStep:o,maxParticles:h,pointSize:a,ease:r,repelRadius:l,repelStrength:c,particleColor:f,fontFamily:d,fontSize:u,width:g,height:m,devicePixelRatio:v})},[x,y,b,s,o,h,a,r,l,c,f,d,u,g,m,v,function(t){$&&$.morph(t)},function(){$&&$.scatter()},function(t){$&&$.updateConfig(t)},function(){$&&($.destroy(),n(20,$=null))},$,function(t){p[t?"unshift":"push"](()=>{b=t,n(2,b)})}]}module.exports=class extends _{constructor(t){super(),P(this,t,W,D,r,{text:3,densityStep:4,maxParticles:5,pointSize:6,ease:7,repelRadius:8,repelStrength:9,particleColor:10,fontFamily:11,fontSize:12,width:13,height:14,devicePixelRatio:15,className:0,style:1,morph:16,scatter:17,updateConfig:18,destroy:19})}get morph(){return this.$$.ctx[16]}get scatter(){return this.$$.ctx[17]}get updateConfig(){return this.$$.ctx[18]}get destroy(){return this.$$.ctx[19]}};
1
+ "use strict";var t=Object.defineProperty,e=(e,i,n)=>((e,i,n)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[i]=n)(e,"symbol"!=typeof i?i+"":i,n);const i=require("svelte");function n(){}function s(t){return t()}function o(){return Object.create(null)}function h(t){t.forEach(s)}function a(t){return"function"==typeof t}function r(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function l(t){t.parentNode&&t.parentNode.removeChild(t)}function c(t,e,i){null==i?t.removeAttribute(e):t.getAttribute(e)!==i&&t.setAttribute(e,i)}let d;function u(t){d=t}const f=[],p=[];let g=[];const m=[],v=Promise.resolve();let y=!1;function x(t){g.push(t)}const b=new Set;let w=0;function M(){if(0!==w)return;const t=d;do{try{for(;w<f.length;){const t=f[w];w++,u(t),$(t.$$)}}catch(e){throw f.length=0,w=0,e}for(u(null),f.length=0,w=0;p.length;)p.pop()();for(let t=0;t<g.length;t+=1){const e=g[t];b.has(e)||(b.add(e),e())}g.length=0}while(f.length);for(;m.length;)m.pop()();y=!1,b.clear(),u(t)}function $(t){if(null!==t.fragment){t.update(),h(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(x)}}const C=new Set;function R(t,e){const i=t.$$;null!==i.fragment&&(!function(t){const e=[],i=[];g.forEach(n=>-1===t.indexOf(n)?e.push(n):i.push(n)),i.forEach(t=>t()),g=e}(i.after_update),h(i.on_destroy),i.fragment&&i.fragment.d(e),i.on_destroy=i.fragment=null,i.ctx=[])}function P(t,e){-1===t.$$.dirty[0]&&(f.push(t),y||(y=!0,v.then(M)),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function S(t,e,i,r,c,f,p=null,g=[-1]){const m=d;u(t);const v=t.$$={fragment:null,ctx:[],props:f,update:n,not_equal:c,bound:o(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(m?m.$$.context:[])),callbacks:o(),dirty:g,skip_bound:!1,root:e.target||m.$$.root};p&&p(v.root);let y=!1;if(v.ctx=i?i(t,e.props||{},(e,i,...n)=>{const s=n.length?n[0]:i;return v.ctx&&c(v.ctx[e],v.ctx[e]=s)&&(!v.skip_bound&&v.bound[e]&&v.bound[e](s),y&&P(t,e)),i}):[],v.update(),y=!0,h(v.before_update),v.fragment=!!r&&r(v.ctx),e.target){if(e.hydrate){const t=($=e.target,Array.from($.childNodes));v.fragment&&v.fragment.l(t),t.forEach(l)}else v.fragment&&v.fragment.c();e.intro&&((b=t.$$.fragment)&&b.i&&(C.delete(b),b.i(w))),function(t,e,i){const{fragment:n,after_update:o}=t.$$;n&&n.m(e,i),x(()=>{const e=t.$$.on_mount.map(s).filter(a);t.$$.on_destroy?t.$$.on_destroy.push(...e):h(e),t.$$.on_mount=[]}),o.forEach(x)}(t,e.target,e.anchor),M()}var b,w,$;u(m)}class H{constructor(){e(this,"$$"),e(this,"$$set")}$destroy(){R(this,1),this.$destroy=n}$on(t,e){if(!a(e))return n;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const t=i.indexOf(e);-1!==t&&i.splice(t,1)}}$set(t){var e;this.$$set&&(e=t,0!==Object.keys(e).length)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}"undefined"!=typeof window&&(window.__svelte||(window.__svelte={v:new Set})).v.add("4");class _{constructor(t,e={}){this.container=t,this.options={threshold:e.threshold??.1,rootMargin:e.rootMargin??"0px",onVisible:e.onVisible,onHidden:e.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 e of t)e.target===this.container&&(e.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 z(t,e){let i=null;return function(...n){null!==i&&clearTimeout(i),i=setTimeout(()=>{i=null,t.apply(this,n)},e)}}class E{constructor(t,e={}){if(this.container="string"==typeof t?document.querySelector(t):t,!this.container)throw new Error("Container element not found");this.config={text:e.text||"mason effect",densityStep:e.densityStep??2,maxParticles:e.maxParticles??3200,pointSize:e.pointSize??.5,ease:e.ease??.05,repelRadius:e.repelRadius??150,repelStrength:e.repelStrength??1,particleColor:e.particleColor||"#fff",fontFamily:e.fontFamily||"Inter, system-ui, Arial",fontSize:e.fontSize||null,width:e.width||null,height:e.height||null,devicePixelRatio:e.devicePixelRatio??null,onReady:e.onReady||null,onUpdate:e.onUpdate||null},this.canvas=document.createElement("canvas");const i=this.canvas.getContext("2d",{willReadFrequently:!0});if(!i)throw new Error("Canvas context not available");this.ctx=i,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=e.debounceDelay??150;const s=this.handleResize.bind(this);this.handleResize=z(s,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=z(this._morphInternal.bind(this),this.debounceDelay),this._debouncedUpdateConfig=z(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 _(this.container,{threshold:.1,onVisible:()=>{this.start()},onHidden:()=>{this.stop()}})}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,h=.1*t,a=.05*t;let r=0;for(const c of s){if(0===c.length)continue;const t=this.offCtx.measureText(c).width+a*(c.length>0?c.length-1:0);r=Math.max(r,t)}const l=s.length>0?o*s.length+h*(s.length-1):o;return{width:r,height:l,fits:r<=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,h=12;for(;s<=o;){const n=Math.floor((s+o)/2);this.measureTextFit(n,t,e,i).fits?(h=n,s=n+1):o=n-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)),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 h=t.split("\n"),a=o,r=.1*o,l=.05*o,c=h.length>0?a*h.length+r*(h.length-1):a;let d=this.H/2-c/2+a/2;for(const g of h){if(0===g.length){d+=a+r;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,d),i+=this.offCtx.measureText(n).width+l;d+=a+r}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 n of this.particles){let t=(n.tx-n.x)*this.config.ease,e=(n.ty-n.y)*this.config.ease;if(this.mouse.x||this.mouse.y){const i=n.x-this.mouse.x,s=n.y-this.mouse.y,o=i*i+s*s,h=this.config.repelRadius*this.DPR;if(o<h*h){const n=Math.sqrt(o)+1e-4,a=(this.mouse.down?-1:1)*this.config.repelStrength*(1-n/h);t+=i/n*a*6,e+=s/n*a*6}}n.j+=2,t+=.05*Math.cos(n.j),e+=.05*Math.sin(1.3*n.j),n.vx=(n.vx+t)*Math.random(),n.vy=(n.vy+e)*Math.random(),n.x+=n.vx,n.y+=n.vy}this.ctx.fillStyle=this.config.particleColor;const t=Math.min(this.W,this.H)/this.DPR,e=Math.max(.5,Math.min(2,t/1920)),i=this.config.pointSize*this.DPR*e;for(const n of this.particles)this.ctx.beginPath(),this.ctx.arc(n.x,n.y,i,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.visibilityManager&&(this.visibilityManager.destroy(),this.visibilityManager=null),this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas)}}function V(t){let e;return{c(){var i;i="div",e=document.createElement(i),c(e,"class",t[0]),c(e,"style",t[1])},m(i,n){!function(t,e,i){t.insertBefore(e,i||null)}(i,e,n),t[21](e)},p(t,[i]){1&i&&c(e,"class",t[0]),2&i&&c(e,"style",t[1])},i:n,o:n,d(i){i&&l(e),t[21](null)}}}function D(t,e,n){let{text:s="mason effect"}=e,{densityStep:o=2}=e,{maxParticles:h=3200}=e,{pointSize:a=.5}=e,{ease:r=.05}=e,{repelRadius:l=150}=e,{repelStrength:c=1}=e,{particleColor:d="#fff"}=e,{fontFamily:u="Inter, system-ui, Arial"}=e,{fontSize:f=null}=e,{width:g=null}=e,{height:m=null}=e,{devicePixelRatio:v=null}=e,{className:y=""}=e,{style:x={}}=e;const b=i.createEventDispatcher();let w,M=null;return i.onMount(()=>{if(!w)return;n(20,M=new E(w,{text:s,densityStep:o,maxParticles:h,pointSize:a,ease:r,repelRadius:l,repelStrength:c,particleColor:d,fontFamily:u,fontSize:f,width:g,height:m,devicePixelRatio:v,onReady:t=>{b("ready",t)},onUpdate:t=>{b("update",t)}}))}),i.onDestroy(()=>{M&&(M.destroy(),n(20,M=null))}),t.$$set=t=>{"text"in t&&n(3,s=t.text),"densityStep"in t&&n(4,o=t.densityStep),"maxParticles"in t&&n(5,h=t.maxParticles),"pointSize"in t&&n(6,a=t.pointSize),"ease"in t&&n(7,r=t.ease),"repelRadius"in t&&n(8,l=t.repelRadius),"repelStrength"in t&&n(9,c=t.repelStrength),"particleColor"in t&&n(10,d=t.particleColor),"fontFamily"in t&&n(11,u=t.fontFamily),"fontSize"in t&&n(12,f=t.fontSize),"width"in t&&n(13,g=t.width),"height"in t&&n(14,m=t.height),"devicePixelRatio"in t&&n(15,v=t.devicePixelRatio),"className"in t&&n(0,y=t.className),"style"in t&&n(1,x=t.style)},t.$$.update=()=>{1114104&t.$$.dirty&&M&&M.updateConfig({text:s,densityStep:o,maxParticles:h,pointSize:a,ease:r,repelRadius:l,repelStrength:c,particleColor:d,fontFamily:u,fontSize:f,width:g,height:m,devicePixelRatio:v})},[y,x,w,s,o,h,a,r,l,c,d,u,f,g,m,v,function(t){M&&M.morph(t)},function(){M&&M.scatter()},function(t){M&&M.updateConfig(t)},function(){M&&(M.destroy(),n(20,M=null))},M,function(t){p[t?"unshift":"push"](()=>{w=t,n(2,w)})}]}module.exports=class extends H{constructor(t){super(),S(this,t,D,V,r,{text:3,densityStep:4,maxParticles:5,pointSize:6,ease:7,repelRadius:8,repelStrength:9,particleColor:10,fontFamily:11,fontSize:12,width:13,height:14,devicePixelRatio:15,className:0,style:1,morph:16,scatter:17,updateConfig:18,destroy:19})}get morph(){return this.$$.ctx[16]}get scatter(){return this.$$.ctx[17]}get updateConfig(){return this.$$.ctx[18]}get destroy(){return this.$$.ctx[19]}};