masoneffect 1.0.30 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/README.md +320 -231
  2. package/dist/core/count/index.d.ts +52 -0
  3. package/dist/core/count/index.d.ts.map +1 -0
  4. package/dist/core/index.d.ts +15 -97
  5. package/dist/core/index.d.ts.map +1 -1
  6. package/dist/core/textToParticle/index.d.ts +103 -0
  7. package/dist/core/textToParticle/index.d.ts.map +1 -0
  8. package/dist/count/core/count/index.d.ts +52 -0
  9. package/dist/count/core/count/index.d.ts.map +1 -0
  10. package/dist/count/core/index.d.ts +18 -0
  11. package/dist/count/core/index.d.ts.map +1 -0
  12. package/dist/count/core/textToParticle/index.d.ts +103 -0
  13. package/dist/count/core/textToParticle/index.d.ts.map +1 -0
  14. package/dist/count/index.cjs +1 -0
  15. package/dist/count/index.d.ts +16 -0
  16. package/dist/count/index.d.ts.map +1 -0
  17. package/dist/count/index.mjs +1 -0
  18. package/dist/count/index.umd.d.ts +7 -0
  19. package/dist/count/index.umd.d.ts.map +1 -0
  20. package/dist/count/react/MasonEffect.d.ts +32 -0
  21. package/dist/count/react/MasonEffect.d.ts.map +1 -0
  22. package/dist/count/react/count/Count.d.ts +19 -0
  23. package/dist/count/react/count/Count.d.ts.map +1 -0
  24. package/dist/count/react/count/index.d.ts +5 -0
  25. package/dist/count/react/count/index.d.ts.map +1 -0
  26. package/dist/count/react/index.d.ts +12 -0
  27. package/dist/count/react/index.d.ts.map +1 -0
  28. package/dist/count/react/textToParticle/TextToParticle.d.ts +15 -0
  29. package/dist/count/react/textToParticle/TextToParticle.d.ts.map +1 -0
  30. package/dist/count/react/textToParticle/index.d.ts +4 -0
  31. package/dist/count/react/textToParticle/index.d.ts.map +1 -0
  32. package/dist/count/svelte/count/index.d.ts +2 -0
  33. package/dist/count/svelte/count/index.d.ts.map +1 -0
  34. package/dist/count/svelte/index.d.ts +8 -0
  35. package/dist/count/svelte/index.d.ts.map +1 -0
  36. package/dist/count/svelte/textToParticle/index.d.ts +2 -0
  37. package/dist/count/svelte/textToParticle/index.d.ts.map +1 -0
  38. package/dist/count/vue/count/index.d.ts +2 -0
  39. package/dist/count/vue/count/index.d.ts.map +1 -0
  40. package/dist/count/vue/index.d.ts +8 -0
  41. package/dist/count/vue/index.d.ts.map +1 -0
  42. package/dist/count/vue/textToParticle/index.d.ts +2 -0
  43. package/dist/count/vue/textToParticle/index.d.ts.map +1 -0
  44. package/dist/index.cjs +1 -1
  45. package/dist/index.d.ts +12 -4
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.mjs +1 -1
  48. package/dist/index.umd.min.js +1 -1
  49. package/dist/react/core/count/index.d.ts +51 -0
  50. package/dist/react/core/index.d.ts +15 -97
  51. package/dist/react/core/textToParticle/index.d.ts +102 -0
  52. package/dist/react/count/Count.d.ts +19 -0
  53. package/dist/react/count/Count.d.ts.map +1 -0
  54. package/dist/react/count/core/count/index.d.ts +52 -0
  55. package/dist/react/count/core/count/index.d.ts.map +1 -0
  56. package/dist/react/count/core/index.d.ts +18 -0
  57. package/dist/react/count/core/index.d.ts.map +1 -0
  58. package/dist/react/count/core/textToParticle/index.d.ts +103 -0
  59. package/dist/react/count/core/textToParticle/index.d.ts.map +1 -0
  60. package/dist/react/count/index.cjs +1 -0
  61. package/dist/react/count/index.d.ts +16 -0
  62. package/dist/react/count/index.d.ts.map +1 -0
  63. package/dist/react/count/index.mjs +1 -0
  64. package/dist/react/count/index.umd.d.ts +7 -0
  65. package/dist/react/count/index.umd.d.ts.map +1 -0
  66. package/dist/react/count/react/MasonEffect.d.ts +32 -0
  67. package/dist/react/count/react/MasonEffect.d.ts.map +1 -0
  68. package/dist/react/count/react/count/Count.d.ts +19 -0
  69. package/dist/react/count/react/count/Count.d.ts.map +1 -0
  70. package/dist/react/count/react/count/index.d.ts +5 -0
  71. package/dist/react/count/react/count/index.d.ts.map +1 -0
  72. package/dist/react/count/react/index.d.ts +12 -0
  73. package/dist/react/count/react/index.d.ts.map +1 -0
  74. package/dist/react/count/react/textToParticle/TextToParticle.d.ts +15 -0
  75. package/dist/react/count/react/textToParticle/TextToParticle.d.ts.map +1 -0
  76. package/dist/react/count/react/textToParticle/index.d.ts +4 -0
  77. package/dist/react/count/react/textToParticle/index.d.ts.map +1 -0
  78. package/dist/react/count/svelte/count/index.d.ts +2 -0
  79. package/dist/react/count/svelte/count/index.d.ts.map +1 -0
  80. package/dist/react/count/svelte/index.d.ts +8 -0
  81. package/dist/react/count/svelte/index.d.ts.map +1 -0
  82. package/dist/react/count/svelte/textToParticle/index.d.ts +2 -0
  83. package/dist/react/count/svelte/textToParticle/index.d.ts.map +1 -0
  84. package/dist/react/count/vue/count/index.d.ts +2 -0
  85. package/dist/react/count/vue/count/index.d.ts.map +1 -0
  86. package/dist/react/count/vue/index.d.ts +8 -0
  87. package/dist/react/count/vue/index.d.ts.map +1 -0
  88. package/dist/react/count/vue/textToParticle/index.d.ts +2 -0
  89. package/dist/react/count/vue/textToParticle/index.d.ts.map +1 -0
  90. package/dist/react/index.cjs +12 -2
  91. package/dist/react/index.d.ts.map +1 -1
  92. package/dist/react/index.mjs +2 -1
  93. package/dist/react/react/count/Count.d.ts +18 -0
  94. package/dist/react/react/count/index.d.ts +4 -0
  95. package/dist/react/react/index.d.ts +11 -2
  96. package/dist/react/react/textToParticle/TextToParticle.d.ts +14 -0
  97. package/dist/react/react/textToParticle/index.d.ts +3 -0
  98. package/dist/react/svelte/count/index.d.ts +1 -0
  99. package/dist/react/svelte/index.d.ts +5 -3
  100. package/dist/react/svelte/textToParticle/index.d.ts +1 -0
  101. package/dist/react/textToParticle/TextToParticle.d.ts +15 -0
  102. package/dist/react/textToParticle/TextToParticle.d.ts.map +1 -0
  103. package/dist/react/textToParticle/core/count/index.d.ts +52 -0
  104. package/dist/react/textToParticle/core/count/index.d.ts.map +1 -0
  105. package/dist/react/textToParticle/core/index.d.ts +18 -0
  106. package/dist/react/textToParticle/core/index.d.ts.map +1 -0
  107. package/dist/react/textToParticle/core/textToParticle/index.d.ts +103 -0
  108. package/dist/react/textToParticle/core/textToParticle/index.d.ts.map +1 -0
  109. package/dist/react/textToParticle/index.cjs +1 -0
  110. package/dist/react/textToParticle/index.d.ts +16 -0
  111. package/dist/react/textToParticle/index.d.ts.map +1 -0
  112. package/dist/react/textToParticle/index.mjs +1 -0
  113. package/dist/react/textToParticle/index.umd.d.ts +7 -0
  114. package/dist/react/textToParticle/index.umd.d.ts.map +1 -0
  115. package/dist/react/textToParticle/react/MasonEffect.d.ts +32 -0
  116. package/dist/react/textToParticle/react/MasonEffect.d.ts.map +1 -0
  117. package/dist/react/textToParticle/react/count/Count.d.ts +19 -0
  118. package/dist/react/textToParticle/react/count/Count.d.ts.map +1 -0
  119. package/dist/react/textToParticle/react/count/index.d.ts +5 -0
  120. package/dist/react/textToParticle/react/count/index.d.ts.map +1 -0
  121. package/dist/react/textToParticle/react/index.d.ts +12 -0
  122. package/dist/react/textToParticle/react/index.d.ts.map +1 -0
  123. package/dist/react/textToParticle/react/textToParticle/TextToParticle.d.ts +15 -0
  124. package/dist/react/textToParticle/react/textToParticle/TextToParticle.d.ts.map +1 -0
  125. package/dist/react/textToParticle/react/textToParticle/index.d.ts +4 -0
  126. package/dist/react/textToParticle/react/textToParticle/index.d.ts.map +1 -0
  127. package/dist/react/textToParticle/svelte/count/index.d.ts +2 -0
  128. package/dist/react/textToParticle/svelte/count/index.d.ts.map +1 -0
  129. package/dist/react/textToParticle/svelte/index.d.ts +8 -0
  130. package/dist/react/textToParticle/svelte/index.d.ts.map +1 -0
  131. package/dist/react/textToParticle/svelte/textToParticle/index.d.ts +2 -0
  132. package/dist/react/textToParticle/svelte/textToParticle/index.d.ts.map +1 -0
  133. package/dist/react/textToParticle/vue/count/index.d.ts +2 -0
  134. package/dist/react/textToParticle/vue/count/index.d.ts.map +1 -0
  135. package/dist/react/textToParticle/vue/index.d.ts +8 -0
  136. package/dist/react/textToParticle/vue/index.d.ts.map +1 -0
  137. package/dist/react/textToParticle/vue/textToParticle/index.d.ts +2 -0
  138. package/dist/react/textToParticle/vue/textToParticle/index.d.ts.map +1 -0
  139. package/dist/react/vue/count/index.d.ts +1 -0
  140. package/dist/react/vue/index.d.ts +5 -3
  141. package/dist/react/vue/textToParticle/index.d.ts +1 -0
  142. package/dist/svelte/count/index.cjs +1 -0
  143. package/dist/svelte/count/index.d.ts +163 -0
  144. package/dist/svelte/count/index.mjs +659 -0
  145. package/dist/svelte/index.cjs +1 -1
  146. package/dist/svelte/index.d.ts +88 -29
  147. package/dist/svelte/index.mjs +402 -8
  148. package/dist/svelte/textToParticle/index.cjs +1 -0
  149. package/dist/svelte/textToParticle/index.d.ts +163 -0
  150. package/dist/svelte/textToParticle/index.mjs +924 -0
  151. package/dist/textToParticle/core/count/index.d.ts +52 -0
  152. package/dist/textToParticle/core/count/index.d.ts.map +1 -0
  153. package/dist/textToParticle/core/index.d.ts +18 -0
  154. package/dist/textToParticle/core/index.d.ts.map +1 -0
  155. package/dist/textToParticle/core/textToParticle/index.d.ts +103 -0
  156. package/dist/textToParticle/core/textToParticle/index.d.ts.map +1 -0
  157. package/dist/textToParticle/index.cjs +1 -0
  158. package/dist/textToParticle/index.d.ts +16 -0
  159. package/dist/textToParticle/index.d.ts.map +1 -0
  160. package/dist/textToParticle/index.mjs +1 -0
  161. package/dist/textToParticle/index.umd.d.ts +7 -0
  162. package/dist/textToParticle/index.umd.d.ts.map +1 -0
  163. package/dist/textToParticle/react/MasonEffect.d.ts +32 -0
  164. package/dist/textToParticle/react/MasonEffect.d.ts.map +1 -0
  165. package/dist/textToParticle/react/count/Count.d.ts +19 -0
  166. package/dist/textToParticle/react/count/Count.d.ts.map +1 -0
  167. package/dist/textToParticle/react/count/index.d.ts +5 -0
  168. package/dist/textToParticle/react/count/index.d.ts.map +1 -0
  169. package/dist/textToParticle/react/index.d.ts +12 -0
  170. package/dist/textToParticle/react/index.d.ts.map +1 -0
  171. package/dist/textToParticle/react/textToParticle/TextToParticle.d.ts +15 -0
  172. package/dist/textToParticle/react/textToParticle/TextToParticle.d.ts.map +1 -0
  173. package/dist/textToParticle/react/textToParticle/index.d.ts +4 -0
  174. package/dist/textToParticle/react/textToParticle/index.d.ts.map +1 -0
  175. package/dist/textToParticle/svelte/count/index.d.ts +2 -0
  176. package/dist/textToParticle/svelte/count/index.d.ts.map +1 -0
  177. package/dist/textToParticle/svelte/index.d.ts +8 -0
  178. package/dist/textToParticle/svelte/index.d.ts.map +1 -0
  179. package/dist/textToParticle/svelte/textToParticle/index.d.ts +2 -0
  180. package/dist/textToParticle/svelte/textToParticle/index.d.ts.map +1 -0
  181. package/dist/textToParticle/vue/count/index.d.ts +2 -0
  182. package/dist/textToParticle/vue/count/index.d.ts.map +1 -0
  183. package/dist/textToParticle/vue/index.d.ts +8 -0
  184. package/dist/textToParticle/vue/index.d.ts.map +1 -0
  185. package/dist/textToParticle/vue/textToParticle/index.d.ts +2 -0
  186. package/dist/textToParticle/vue/textToParticle/index.d.ts.map +1 -0
  187. package/dist/vue/count/index.cjs +1 -0
  188. package/dist/vue/count/index.d.ts +163 -0
  189. package/dist/vue/count/index.mjs +286 -0
  190. package/dist/vue/index.cjs +1 -1
  191. package/dist/vue/index.d.ts +88 -29
  192. package/dist/vue/index.mjs +291 -6
  193. package/dist/vue/textToParticle/index.cjs +1 -0
  194. package/dist/vue/textToParticle/index.d.ts +163 -0
  195. package/dist/vue/textToParticle/index.mjs +554 -0
  196. package/package.json +54 -5
@@ -0,0 +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]}};
@@ -0,0 +1,163 @@
1
+ export declare class Count {
2
+ container: HTMLElement;
3
+ config: Required<Omit<CountOptions, 'onUpdate' | 'onComplete'>> & {
4
+ onUpdate: CountOptions['onUpdate'];
5
+ onComplete: CountOptions['onComplete'];
6
+ };
7
+ currentValue: number;
8
+ startTime: number | null;
9
+ animationFrameId: number | null;
10
+ intersectionObserver: IntersectionObserver | null;
11
+ isRunning: boolean;
12
+ hasTriggered: boolean;
13
+ constructor(container: HTMLElement | string, options: CountOptions);
14
+ init(): void;
15
+ setupIntersectionObserver(): void;
16
+ start(): void;
17
+ stop(): void;
18
+ reset(): void;
19
+ updateDisplay(value: number): void;
20
+ formatNumber(value: number): string;
21
+ updateConfig(newConfig: Partial<CountOptions>): void;
22
+ getValue(): number;
23
+ destroy(): void;
24
+ }
25
+
26
+ /**
27
+ * Count - 숫자 카운팅 애니메이션 효과
28
+ * 바닐라 JS 코어 클래스
29
+ *
30
+ * 사용법:
31
+ * import { Count } from 'masoneffect/count';
32
+ */
33
+ export declare interface CountOptions {
34
+ targetValue: number;
35
+ duration?: number;
36
+ startValue?: number;
37
+ enabled?: boolean;
38
+ easing?: (t: number) => number;
39
+ threshold?: number;
40
+ rootMargin?: string;
41
+ triggerOnce?: boolean;
42
+ onUpdate?: (value: number) => void;
43
+ onComplete?: () => void;
44
+ }
45
+
46
+ export declare const easingFunctions: {
47
+ linear: (t: number) => number;
48
+ easeInQuad: (t: number) => number;
49
+ easeOutQuad: (t: number) => number;
50
+ easeInOutQuad: (t: number) => number;
51
+ easeOutCubic: (t: number) => number;
52
+ };
53
+
54
+ export declare interface Particle {
55
+ x: number;
56
+ y: number;
57
+ vx: number;
58
+ vy: number;
59
+ tx: number;
60
+ ty: number;
61
+ initialX?: number;
62
+ initialY?: number;
63
+ j: number;
64
+ }
65
+
66
+ declare class TextToParticle {
67
+ container: HTMLElement;
68
+ config: Required<Omit<TextToParticleOptions, 'onReady' | 'onUpdate' | 'debounceDelay'>> & {
69
+ onReady: TextToParticleOptions['onReady'];
70
+ onUpdate: TextToParticleOptions['onUpdate'];
71
+ };
72
+ canvas: HTMLCanvasElement;
73
+ ctx: CanvasRenderingContext2D;
74
+ offCanvas: HTMLCanvasElement;
75
+ offCtx: CanvasRenderingContext2D;
76
+ W: number;
77
+ H: number;
78
+ DPR: number;
79
+ particles: Particle[];
80
+ mouse: {
81
+ x: number;
82
+ y: number;
83
+ down: boolean;
84
+ };
85
+ animationId: number | null;
86
+ isRunning: boolean;
87
+ isVisible: boolean;
88
+ intersectionObserver: IntersectionObserver | null;
89
+ debounceDelay: number;
90
+ _debouncedMorph: (textOrOptions?: string | Partial<TextToParticleOptions> | null) => void;
91
+ _debouncedUpdateConfig: (newConfig: Partial<TextToParticleOptions>) => void;
92
+ constructor(container: HTMLElement | string, options?: TextToParticleOptions);
93
+ init(): void;
94
+ setupIntersectionObserver(): void;
95
+ resize(): void;
96
+ /**
97
+ * 텍스트가 영역 안에 들어가는지 확인하는 헬퍼 함수 (줄바꿈 지원)
98
+ * @param fontSize 확인할 폰트 크기
99
+ * @param text 텍스트 (\n으로 줄바꿈 구분)
100
+ * @param maxWidth 최대 너비
101
+ * @param maxHeight 최대 높이
102
+ * @returns { width: number, height: number, fits: boolean }
103
+ */
104
+ private measureTextFit;
105
+ /**
106
+ * 이진 검색을 사용하여 적절한 폰트 크기를 찾는 최적화된 함수
107
+ * 반복 횟수를 O(log n)으로 줄여 성능 개선 (최대 15회 반복, 기존 최대 100회에서 대폭 감소)
108
+ */
109
+ private findOptimalFontSize;
110
+ buildTargets(): void;
111
+ makeParticle(): Particle;
112
+ initParticles(): void;
113
+ scatter(): void;
114
+ morph(textOrOptions?: string | Partial<TextToParticleOptions> | null): void;
115
+ _morphInternal(textOrOptions?: string | Partial<TextToParticleOptions> | null): void;
116
+ update(): void;
117
+ animate(): void;
118
+ start(): void;
119
+ stop(): void;
120
+ setupEventListeners(): void;
121
+ removeEventListeners(): void;
122
+ handleResize(): void;
123
+ handleMouseMove(e: MouseEvent): void;
124
+ handleMouseLeave(): void;
125
+ handleMouseDown(): void;
126
+ handleMouseUp(): void;
127
+ updateConfig(newConfig: Partial<TextToParticleOptions>): void;
128
+ _updateConfigInternal(newConfig: Partial<TextToParticleOptions>): void;
129
+ destroy(): void;
130
+ }
131
+ export { TextToParticle as MasonEffect }
132
+ export { TextToParticle }
133
+ export default TextToParticle;
134
+
135
+ /**
136
+ * TextToParticle - 텍스트를 파티클로 변환하는 효과
137
+ * 바닐라 JS 코어 클래스
138
+ *
139
+ * 사용법:
140
+ * import { TextToParticle } from 'masoneffect/textToParticle';
141
+ */
142
+ declare interface TextToParticleOptions {
143
+ text?: string;
144
+ densityStep?: number;
145
+ maxParticles?: number;
146
+ pointSize?: number;
147
+ ease?: number;
148
+ repelRadius?: number;
149
+ repelStrength?: number;
150
+ particleColor?: string;
151
+ fontFamily?: string;
152
+ fontSize?: number | null;
153
+ width?: number | null;
154
+ height?: number | null;
155
+ devicePixelRatio?: number | null;
156
+ debounceDelay?: number;
157
+ onReady?: (instance: TextToParticle) => void;
158
+ onUpdate?: (instance: TextToParticle) => void;
159
+ }
160
+ export { TextToParticleOptions as MasonEffectOptions }
161
+ export { TextToParticleOptions }
162
+
163
+ export { }