{"version":3,"file":"ScrollToPlugin.min.js","sources":["../src/ScrollToPlugin.js"],"sourcesContent":["/*!\n * ScrollToPlugin 3.12.2\n * https://greensock.com\n *\n * @license Copyright 2008-2023, GreenSock. All rights reserved.\n * Subject to the terms at https://greensock.com/standard-license or for\n * Club GreenSock members, the agreement issued with that membership.\n * @author: Jack Doyle, jack@greensock.com\n*/\n/* eslint-disable */\n\nlet gsap, _coreInitted, _window, _docEl, _body, _toArray, _config, ScrollTrigger,\n\t_windowExists = () => typeof(window) !== \"undefined\",\n\t_getGSAP = () => gsap || (_windowExists() && (gsap = window.gsap) && gsap.registerPlugin && gsap),\n\t_isString = value => typeof(value) === \"string\",\n\t_isFunction = value => typeof(value) === \"function\",\n\t_max = (element, axis) => {\n\t\tlet dim = (axis === \"x\") ? \"Width\" : \"Height\",\n\t\t\tscroll = \"scroll\" + dim,\n\t\t\tclient = \"client\" + dim;\n\t\treturn (element === _window || element === _docEl || element === _body) ? Math.max(_docEl[scroll], _body[scroll]) - (_window[\"inner\" + dim] || _docEl[client] || _body[client]) : element[scroll] - element[\"offset\" + dim];\n\t},\n\t_buildGetter = (e, axis) => { //pass in an element and an axis (\"x\" or \"y\") and it'll return a getter function for the scroll position of that element (like scrollTop or scrollLeft, although if the element is the window, it'll use the pageXOffset/pageYOffset or the documentElement's scrollTop/scrollLeft or document.body's. Basically this streamlines things and makes a very fast getter across browsers.\n\t\tlet p = \"scroll\" + ((axis === \"x\") ? \"Left\" : \"Top\");\n\t\tif (e === _window) {\n\t\t\tif (e.pageXOffset != null) {\n\t\t\t\tp = \"page\" + axis.toUpperCase() + \"Offset\";\n\t\t\t} else {\n\t\t\t\te = _docEl[p] != null ? _docEl : _body;\n\t\t\t}\n\t\t}\n\t\treturn () => e[p];\n\t},\n\t_clean = (value, index, target, targets) => {\n\t\t_isFunction(value) && (value = value(index, target, targets));\n\t\tif (typeof(value) !== \"object\") {\n\t\t\treturn _isString(value) && value !== \"max\" && value.charAt(1) !== \"=\" ? {x: value, y: value} : {y: value}; //if we don't receive an object as the parameter, assume the user intends \"y\".\n\t\t} else if (value.nodeType) {\n\t\t\treturn {y: value, x: value};\n\t\t} else {\n\t\t\tlet result = {}, p;\n\t\t\tfor (p in value) {\n\t\t\t\tresult[p] = p !== \"onAutoKill\" && _isFunction(value[p]) ? value[p](index, target, targets) : value[p];\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t},\n\t_getOffset = (element, container) => {\n\t\telement = _toArray(element)[0];\n\t\tif (!element || !element.getBoundingClientRect) {\n\t\t\treturn console.warn(\"scrollTo target doesn't exist. Using 0\") || {x:0, y:0};\n\t\t}\n\t\tlet rect = element.getBoundingClientRect(),\n\t\t\tisRoot = (!container || container === _window || container === _body),\n\t\t\tcRect = isRoot ? {top:_docEl.clientTop - (_window.pageYOffset || _docEl.scrollTop || _body.scrollTop || 0), left:_docEl.clientLeft - (_window.pageXOffset || _docEl.scrollLeft || _body.scrollLeft || 0)} : container.getBoundingClientRect(),\n\t\t\toffsets = {x: rect.left - cRect.left, y: rect.top - cRect.top};\n\t\tif (!isRoot && container) { //only add the current scroll position if it's not the window/body.\n\t\t\toffsets.x += _buildGetter(container, \"x\")();\n\t\t\toffsets.y += _buildGetter(container, \"y\")();\n\t\t}\n\t\treturn offsets;\n\t},\n\t_parseVal = (value, target, axis, currentVal, offset) => !isNaN(value) && typeof(value) !== \"object\" ? parseFloat(value) - offset : (_isString(value) && value.charAt(1) === \"=\") ? parseFloat(value.substr(2)) * (value.charAt(0) === \"-\" ? -1 : 1) + currentVal - offset : (value === \"max\") ? _max(target, axis) - offset : Math.min(_max(target, axis), _getOffset(value, target)[axis] - offset),\n\t_initCore = () => {\n\t\tgsap = _getGSAP();\n\t\tif (_windowExists() && gsap && typeof(document) !== \"undefined\" && document.body) {\n\t\t\t_window = window;\n\t\t\t_body = document.body;\n\t\t\t_docEl = document.documentElement;\n\t\t\t_toArray = gsap.utils.toArray;\n\t\t\tgsap.config({autoKillThreshold:7});\n\t\t\t_config = gsap.config();\n\t\t\t_coreInitted = 1;\n\t\t}\n\t};\n\n\nexport const ScrollToPlugin = {\n\tversion: \"3.12.2\",\n\tname: \"scrollTo\",\n\trawVars: 1,\n\tregister(core) {\n\t\tgsap = core;\n\t\t_initCore();\n\t},\n\tinit(target, value, tween, index, targets) {\n\t\t_coreInitted || _initCore();\n\t\tlet data = this,\n\t\t\tsnapType = gsap.getProperty(target, \"scrollSnapType\");\n\t\tdata.isWin = (target === _window);\n\t\tdata.target = target;\n\t\tdata.tween = tween;\n\t\tvalue = _clean(value, index, target, targets);\n\t\tdata.vars = value;\n\t\tdata.autoKill = !!value.autoKill;\n\t\tdata.getX = _buildGetter(target, \"x\");\n\t\tdata.getY = _buildGetter(target, \"y\");\n\t\tdata.x = data.xPrev = data.getX();\n\t\tdata.y = data.yPrev = data.getY();\n\t\tScrollTrigger || (ScrollTrigger = gsap.core.globals().ScrollTrigger);\n\t\tgsap.getProperty(target, \"scrollBehavior\") === \"smooth\" && gsap.set(target, {scrollBehavior: \"auto\"});\n\t\tif (snapType && snapType !== \"none\") { // disable scroll snapping to avoid strange behavior\n\t\t\tdata.snap = 1;\n\t\t\tdata.snapInline = target.style.scrollSnapType;\n\t\t\ttarget.style.scrollSnapType = \"none\";\n\t\t}\n\t\tif (value.x != null) {\n\t\t\tdata.add(data, \"x\", data.x, _parseVal(value.x, target, \"x\", data.x, value.offsetX || 0), index, targets);\n\t\t\tdata._props.push(\"scrollTo_x\");\n\t\t} else {\n\t\t\tdata.skipX = 1;\n\t\t}\n\t\tif (value.y != null) {\n\t\t\tdata.add(data, \"y\", data.y, _parseVal(value.y, target, \"y\", data.y, value.offsetY || 0), index, targets);\n\t\t\tdata._props.push(\"scrollTo_y\");\n\t\t} else {\n\t\t\tdata.skipY = 1;\n\t\t}\n\t},\n\trender(ratio, data) {\n\t\tlet pt = data._pt,\n\t\t\t{ target, tween, autoKill, xPrev, yPrev, isWin, snap, snapInline } = data,\n\t\t\tx, y, yDif, xDif, threshold;\n\t\twhile (pt) {\n\t\t\tpt.r(ratio, pt.d);\n\t\t\tpt = pt._next;\n\t\t}\n\t\tx = (isWin || !data.skipX) ? data.getX() : xPrev;\n\t\ty = (isWin || !data.skipY) ? data.getY() : yPrev;\n\t\tyDif = y - yPrev;\n\t\txDif = x - xPrev;\n\t\tthreshold = _config.autoKillThreshold;\n\t\tif (data.x < 0) { //can't scroll to a position less than 0! Might happen if someone uses a Back.easeOut or Elastic.easeOut when scrolling back to the top of the page (for example)\n\t\t\tdata.x = 0;\n\t\t}\n\t\tif (data.y < 0) {\n\t\t\tdata.y = 0;\n\t\t}\n\t\tif (autoKill) {\n\t\t\t//note: iOS has a bug that throws off the scroll by several pixels, so we need to check if it's within 7 pixels of the previous one that we set instead of just looking for an exact match.\n\t\t\tif (!data.skipX && (xDif > threshold || xDif < -threshold) && x < _max(target, \"x\")) {\n\t\t\t\tdata.skipX = 1; //if the user scrolls separately, we should stop tweening!\n\t\t\t}\n\t\t\tif (!data.skipY && (yDif > threshold || yDif < -threshold) && y < _max(target, \"y\")) {\n\t\t\t\tdata.skipY = 1; //if the user scrolls separately, we should stop tweening!\n\t\t\t}\n\t\t\tif (data.skipX && data.skipY) {\n\t\t\t\ttween.kill();\n\t\t\t\tdata.vars.onAutoKill && data.vars.onAutoKill.apply(tween, data.vars.onAutoKillParams || []);\n\t\t\t}\n\t\t}\n\t\tif (isWin) {\n\t\t\t_window.scrollTo((!data.skipX) ? data.x : x, (!data.skipY) ? data.y : y);\n\t\t} else {\n\t\t\tdata.skipY || (target.scrollTop = data.y);\n\t\t\tdata.skipX || (target.scrollLeft = data.x);\n\t\t}\n\t\tif (snap && (ratio === 1 || ratio === 0)) {\n\t\t\ty = target.scrollTop;\n\t\t\tx = target.scrollLeft;\n\t\t\tsnapInline ? (target.style.scrollSnapType = snapInline) : target.style.removeProperty(\"scroll-snap-type\");\n\t\t\ttarget.scrollTop = y + 1; // bug in Safari causes the element to totally reset its scroll position when scroll-snap-type changes, so we need to set it to a slightly different value and then back again to work around this bug.\n\t\t\ttarget.scrollLeft = x + 1;\n\t\t\ttarget.scrollTop = y;\n\t\t\ttarget.scrollLeft = x;\n\t\t}\n\t\tdata.xPrev = data.x;\n\t\tdata.yPrev = data.y;\n\t\tScrollTrigger && ScrollTrigger.update();\n\t},\n\tkill(property) {\n\t\tlet both = (property === \"scrollTo\");\n\t\tif (both || property === \"scrollTo_x\") {\n\t\t\tthis.skipX = 1;\n\t\t}\n\t\tif (both || property === \"scrollTo_y\") {\n\t\t\tthis.skipY = 1;\n\t\t}\n\t}\n};\n\nScrollToPlugin.max = _max;\nScrollToPlugin.getOffset = _getOffset;\nScrollToPlugin.buildGetter = _buildGetter;\n\n_getGSAP() && gsap.registerPlugin(ScrollToPlugin);\n\nexport { ScrollToPlugin as default };"],"names":["_windowExists","window","_getGSAP","gsap","registerPlugin","_isString","value","_isFunction","_max","element","axis","dim","scroll","client","_window","_docEl","_body","Math","max","_buildGetter","e","p","pageXOffset","toUpperCase","_getOffset","container","_toArray","getBoundingClientRect","console","warn","x","y","rect","isRoot","cRect","top","clientTop","pageYOffset","scrollTop","left","clientLeft","scrollLeft","offsets","_parseVal","target","currentVal","offset","isNaN","charAt","parseFloat","substr","min","_initCore","document","body","documentElement","utils","toArray","config","autoKillThreshold","_config","_coreInitted","ScrollTrigger","ScrollToPlugin","version","name","rawVars","register","core","init","tween","index","targets","data","this","snapType","getProperty","isWin","_clean","nodeType","result","vars","autoKill","getX","getY","xPrev","yPrev","globals","set","scrollBehavior","snap","snapInline","style","scrollSnapType","add","offsetX","_props","push","skipX","offsetY","skipY","render","ratio","yDif","xDif","threshold","pt","_pt","r","d","_next","kill","onAutoKill","apply","onAutoKillParams","scrollTo","removeProperty","update","property","both","getOffset","buildGetter"],"mappings":";;;;;;;;;6MAYiB,SAAhBA,UAAyC,oBAAZC,OAClB,SAAXC,WAAiBC,GAASH,MAAoBG,EAAOF,OAAOE,OAASA,EAAKC,gBAAkBD,EAChF,SAAZE,EAAYC,SAA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