{ "version": 3, "sources": ["../../../Vettvangur.Heilsuvera/src/scripts/components/Sykurmagn/sugarCubes.ts"], "sourcesContent": ["import { gsap, ScrollTrigger } from \"gsap/all\";\nimport { throttle } from \"throttle-debounce-ts\";\n\nconst sugarCubes = {\n\telContainer: document.querySelector(\".background__cubes\"),\n\telItems: document.querySelectorAll(\".background__cubesImage svg g\"),\n\n\tinit: (): void => {\n\t\tif (!sugarCubes.elContainer) return;\n\n\t\tconst throttledMouseMove = throttle(123, sugarCubes.moveItems);\n\n\t\tgsap.registerPlugin(ScrollTrigger);\n\n\t\tsugarCubes.resetItems();\n\t\twindow.addEventListener(\"mousemove\", throttledMouseMove);\n\t},\n\n\tmoveItems: (event: MouseEvent): void => {\n\t\tconst globalX = event.clientX; // event ? event.touches ? event.touches[0].clientX : event.clientX : 0;\n\t\tconst globalY = event.clientY; // event ? event.touches ? event.touches[0].clientY : event.clientY : 0;\n\n\t\tsugarCubes.elItems.forEach((item) => {\n\t\t\tif (!item) return;\n\n\t\t\tconst localX =\n\t\t\t\titem.getBoundingClientRect().left +\n\t\t\t\titem.getBoundingClientRect().width / 2;\n\t\t\tconst localY =\n\t\t\t\titem.getBoundingClientRect().top +\n\t\t\t\titem.getBoundingClientRect().height / 2;\n\n\t\t\tconst distance = Math.hypot(localX - globalX, localY - globalY);\n\t\t\tconst distanceMax = 212;\n\t\t\tconst distanceMod = 21;\n\t\t\tconst distanceX = Math.hypot(localX - globalX);\n\t\t\tconst distanceY = Math.hypot(localY - globalY);\n\t\t\tconst rotationMod = 12;\n\t\t\tlet x;\n\t\t\tlet y;\n\n\t\t\tif (distance < distanceMax) {\n\t\t\t\tif (globalX < localX) {\n\t\t\t\t\tx =\n\t\t\t\t\t\tdistanceX < distanceMax / 2\n\t\t\t\t\t\t\t? localX - globalX\n\t\t\t\t\t\t\t: distanceMax - (localX - globalX);\n\t\t\t\t} else {\n\t\t\t\t\tx =\n\t\t\t\t\t\tdistanceX < distanceMax / 2\n\t\t\t\t\t\t\t? localX - globalX\n\t\t\t\t\t\t\t: globalX - localX - distanceMax;\n\t\t\t\t}\n\n\t\t\t\tif (globalY < localY) {\n\t\t\t\t\ty =\n\t\t\t\t\t\tdistanceY < distanceMax / 2\n\t\t\t\t\t\t\t? localY - globalY\n\t\t\t\t\t\t\t: distanceMax - (localY - globalY);\n\t\t\t\t} else {\n\t\t\t\t\ty =\n\t\t\t\t\t\tdistanceY < distanceMax / 2\n\t\t\t\t\t\t\t? localY - globalY\n\t\t\t\t\t\t\t: globalY - localY - distanceMax;\n\t\t\t\t}\n\n\t\t\t\tgsap.to(item, {\n\t\t\t\t\tduration: 1.23,\n\t\t\t\t\tease: \"power3.out\",\n\t\t\t\t\trotation: -x / rotationMod,\n\t\t\t\t\t// x: (localX - globalX) / distanceMod,\n\t\t\t\t\t// y: (localY - globalY) / distanceMod,\n\t\t\t\t\t// x: localX - globalX,\n\t\t\t\t\t// y: localY - globalY,\n\t\t\t\t\tx: x / distanceMod,\n\t\t\t\t\ty: y / distanceMod,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tgsap.to(item, {\n\t\t\t\t\tduration: 2.34,\n\t\t\t\t\tease: \"power4.out\",\n\t\t\t\t\trotation: 0,\n\t\t\t\t\tx: 0,\n\t\t\t\t\ty: 0,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t},\n\n\tresetItems: (): void => {\n\t\tsugarCubes.elItems.forEach((item) => {\n\t\t\tgsap.set(item, {\n\t\t\t\ttransformOrigin: \"50% 50%\",\n\t\t\t});\n\t\t});\n\t},\n};\n\nexport default sugarCubes;\n"], "mappings": "+JAGA,IAAMA,EAAa,CAClB,YAAa,SAAS,cAAc,oBAAoB,EACxD,QAAS,SAAS,iBAAiB,+BAA+B,EAElE,KAAM,IAAY,CACjB,GAAI,CAACA,EAAW,YAAa,OAE7B,IAAMC,EAAqBC,EAAS,IAAKF,EAAW,SAAS,EAE7DG,EAAK,eAAeC,CAAa,EAEjCJ,EAAW,WAAW,EACtB,OAAO,iBAAiB,YAAaC,CAAkB,CACxD,EAEA,UAAYI,GAA4B,CACvC,IAAMC,EAAUD,EAAM,QAChBE,EAAUF,EAAM,QAEtBL,EAAW,QAAQ,QAASQ,GAAS,CACpC,GAAI,CAACA,EAAM,OAEX,IAAMC,EACLD,EAAK,sBAAsB,EAAE,KAC7BA,EAAK,sBAAsB,EAAE,MAAQ,EAChCE,EACLF,EAAK,sBAAsB,EAAE,IAC7BA,EAAK,sBAAsB,EAAE,OAAS,EAEjCG,EAAW,KAAK,MAAMF,EAASH,EAASI,EAASH,CAAO,EACxDK,EAAc,IACdC,EAAc,GACdC,EAAY,KAAK,MAAML,EAASH,CAAO,EACvCS,EAAY,KAAK,MAAML,EAASH,CAAO,EACvCS,EAAc,GAChBC,EACAC,EAEAP,EAAWC,GACVN,EAAUG,EACbQ,EACCH,EAAYF,EAAc,EACvBH,EAASH,EACTM,GAAeH,EAASH,GAE5BW,EACCH,EAAYF,EAAc,EACvBH,EAASH,EACTA,EAAUG,EAASG,EAGpBL,EAAUG,EACbQ,EACCH,EAAYH,EAAc,EACvBF,EAASH,EACTK,GAAeF,EAASH,GAE5BW,EACCH,EAAYH,EAAc,EACvBF,EAASH,EACTA,EAAUG,EAASE,EAGxBT,EAAK,GAAGK,EAAM,CACb,SAAU,KACV,KAAM,aACN,SAAU,CAACS,EAAID,EAKf,EAAGC,EAAIJ,EACP,EAAGK,EAAIL,CACR,CAAC,GAEDV,EAAK,GAAGK,EAAM,CACb,SAAU,KACV,KAAM,aACN,SAAU,EACV,EAAG,EACH,EAAG,CACJ,CAAC,CAEH,CAAC,CACF,EAEA,WAAY,IAAY,CACvBR,EAAW,QAAQ,QAASQ,GAAS,CACpCL,EAAK,IAAIK,EAAM,CACd,gBAAiB,SAClB,CAAC,CACF,CAAC,CACF,CACD,EAEOW,EAAQnB", "names": ["sugarCubes", "throttledMouseMove", "n", "gsapWithCSS", "ScrollTrigger", "event", "globalX", "globalY", "item", "localX", "localY", "distance", "distanceMax", "distanceMod", "distanceX", "distanceY", "rotationMod", "x", "y", "sugarCubes_default"] }