UNPKG

gsap

Version:

GSAP is a framework-agnostic JavaScript animation library that turns developers into animation superheroes. Build high-performance animations that work in **every** major browser. Animate CSS, SVG, canvas, React, Vue, WebGL, colors, strings, motion paths,

1,680 lines (1,442 loc) 92.4 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = global || self, factory(global.window = global.window || {})); }(this, (function (exports) { 'use strict'; function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } var _doc, _win, _docElement, _body, _divContainer, _svgContainer, _identityMatrix, _gEl, _transformProp = "transform", _transformOriginProp = _transformProp + "Origin", _hasOffsetBug, _setDoc = function _setDoc(element) { var doc = element.ownerDocument || element; if (!(_transformProp in element.style) && "msTransform" in element.style) { _transformProp = "msTransform"; _transformOriginProp = _transformProp + "Origin"; } while (doc.parentNode && (doc = doc.parentNode)) {} _win = window; _identityMatrix = new Matrix2D(); if (doc) { _doc = doc; _docElement = doc.documentElement; _body = doc.body; _gEl = _doc.createElementNS("http://www.w3.org/2000/svg", "g"); _gEl.style.transform = "none"; var d1 = doc.createElement("div"), d2 = doc.createElement("div"), root = doc && (doc.body || doc.firstElementChild); if (root && root.appendChild) { root.appendChild(d1); d1.appendChild(d2); d1.setAttribute("style", "position:static;transform:translate3d(0,0,1px)"); _hasOffsetBug = d2.offsetParent !== d1; root.removeChild(d1); } } return doc; }, _forceNonZeroScale = function _forceNonZeroScale(e) { var a, cache; while (e && e !== _body) { cache = e._gsap; cache && cache.uncache && cache.get(e, "x"); if (cache && !cache.scaleX && !cache.scaleY && cache.renderTransform) { cache.scaleX = cache.scaleY = 1e-4; cache.renderTransform(1, cache); a ? a.push(cache) : a = [cache]; } e = e.parentNode; } return a; }, _svgTemps = [], _divTemps = [], _getDocScrollTop = function _getDocScrollTop() { return _win.pageYOffset || _doc.scrollTop || _docElement.scrollTop || _body.scrollTop || 0; }, _getDocScrollLeft = function _getDocScrollLeft() { return _win.pageXOffset || _doc.scrollLeft || _docElement.scrollLeft || _body.scrollLeft || 0; }, _svgOwner = function _svgOwner(element) { return element.ownerSVGElement || ((element.tagName + "").toLowerCase() === "svg" ? element : null); }, _isFixed = function _isFixed(element) { if (_win.getComputedStyle(element).position === "fixed") { return true; } element = element.parentNode; if (element && element.nodeType === 1) { return _isFixed(element); } }, _createSibling = function _createSibling(element, i) { if (element.parentNode && (_doc || _setDoc(element))) { var svg = _svgOwner(element), ns = svg ? svg.getAttribute("xmlns") || "http://www.w3.org/2000/svg" : "http://www.w3.org/1999/xhtml", type = svg ? i ? "rect" : "g" : "div", x = i !== 2 ? 0 : 100, y = i === 3 ? 100 : 0, css = "position:absolute;display:block;pointer-events:none;margin:0;padding:0;", e = _doc.createElementNS ? _doc.createElementNS(ns.replace(/^https/, "http"), type) : _doc.createElement(type); if (i) { if (!svg) { if (!_divContainer) { _divContainer = _createSibling(element); _divContainer.style.cssText = css; } e.style.cssText = css + "width:0.1px;height:0.1px;top:" + y + "px;left:" + x + "px"; _divContainer.appendChild(e); } else { _svgContainer || (_svgContainer = _createSibling(element)); e.setAttribute("width", 0.01); e.setAttribute("height", 0.01); e.setAttribute("transform", "translate(" + x + "," + y + ")"); _svgContainer.appendChild(e); } } return e; } throw "Need document and parent."; }, _consolidate = function _consolidate(m) { var c = new Matrix2D(), i = 0; for (; i < m.numberOfItems; i++) { c.multiply(m.getItem(i).matrix); } return c; }, _getCTM = function _getCTM(svg) { var m = svg.getCTM(), transform; if (!m) { transform = svg.style[_transformProp]; svg.style[_transformProp] = "none"; svg.appendChild(_gEl); m = _gEl.getCTM(); svg.removeChild(_gEl); transform ? svg.style[_transformProp] = transform : svg.style.removeProperty(_transformProp.replace(/([A-Z])/g, "-$1").toLowerCase()); } return m || _identityMatrix.clone(); }, _placeSiblings = function _placeSiblings(element, adjustGOffset) { var svg = _svgOwner(element), isRootSVG = element === svg, siblings = svg ? _svgTemps : _divTemps, parent = element.parentNode, appendToEl = parent && !svg && parent.shadowRoot && parent.shadowRoot.appendChild ? parent.shadowRoot : parent, container, m, b, x, y, cs; if (element === _win) { return element; } siblings.length || siblings.push(_createSibling(element, 1), _createSibling(element, 2), _createSibling(element, 3)); container = svg ? _svgContainer : _divContainer; if (svg) { if (isRootSVG) { b = _getCTM(element); x = -b.e / b.a; y = -b.f / b.d; m = _identityMatrix; } else if (element.getBBox) { b = element.getBBox(); m = element.transform ? element.transform.baseVal : {}; m = !m.numberOfItems ? _identityMatrix : m.numberOfItems > 1 ? _consolidate(m) : m.getItem(0).matrix; x = m.a * b.x + m.c * b.y; y = m.b * b.x + m.d * b.y; } else { m = new Matrix2D(); x = y = 0; } if (adjustGOffset && element.tagName.toLowerCase() === "g") { x = y = 0; } (isRootSVG ? svg : parent).appendChild(container); container.setAttribute("transform", "matrix(" + m.a + "," + m.b + "," + m.c + "," + m.d + "," + (m.e + x) + "," + (m.f + y) + ")"); } else { x = y = 0; if (_hasOffsetBug) { m = element.offsetParent; b = element; while (b && (b = b.parentNode) && b !== m && b.parentNode) { if ((_win.getComputedStyle(b)[_transformProp] + "").length > 4) { x = b.offsetLeft; y = b.offsetTop; b = 0; } } } cs = _win.getComputedStyle(element); if (cs.position !== "absolute" && cs.position !== "fixed") { m = element.offsetParent; while (parent && parent !== m) { x += parent.scrollLeft || 0; y += parent.scrollTop || 0; parent = parent.parentNode; } } b = container.style; b.top = element.offsetTop - y + "px"; b.left = element.offsetLeft - x + "px"; b[_transformProp] = cs[_transformProp]; b[_transformOriginProp] = cs[_transformOriginProp]; b.position = cs.position === "fixed" ? "fixed" : "absolute"; appendToEl.appendChild(container); } return container; }, _setMatrix = function _setMatrix(m, a, b, c, d, e, f) { m.a = a; m.b = b; m.c = c; m.d = d; m.e = e; m.f = f; return m; }; var Matrix2D = function () { function Matrix2D(a, b, c, d, e, f) { if (a === void 0) { a = 1; } if (b === void 0) { b = 0; } if (c === void 0) { c = 0; } if (d === void 0) { d = 1; } if (e === void 0) { e = 0; } if (f === void 0) { f = 0; } _setMatrix(this, a, b, c, d, e, f); } var _proto = Matrix2D.prototype; _proto.inverse = function inverse() { var a = this.a, b = this.b, c = this.c, d = this.d, e = this.e, f = this.f, determinant = a * d - b * c || 1e-10; return _setMatrix(this, d / determinant, -b / determinant, -c / determinant, a / determinant, (c * f - d * e) / determinant, -(a * f - b * e) / determinant); }; _proto.multiply = function multiply(matrix) { var a = this.a, b = this.b, c = this.c, d = this.d, e = this.e, f = this.f, a2 = matrix.a, b2 = matrix.c, c2 = matrix.b, d2 = matrix.d, e2 = matrix.e, f2 = matrix.f; return _setMatrix(this, a2 * a + c2 * c, a2 * b + c2 * d, b2 * a + d2 * c, b2 * b + d2 * d, e + e2 * a + f2 * c, f + e2 * b + f2 * d); }; _proto.clone = function clone() { return new Matrix2D(this.a, this.b, this.c, this.d, this.e, this.f); }; _proto.equals = function equals(matrix) { var a = this.a, b = this.b, c = this.c, d = this.d, e = this.e, f = this.f; return a === matrix.a && b === matrix.b && c === matrix.c && d === matrix.d && e === matrix.e && f === matrix.f; }; _proto.apply = function apply(point, decoratee) { if (decoratee === void 0) { decoratee = {}; } var x = point.x, y = point.y, a = this.a, b = this.b, c = this.c, d = this.d, e = this.e, f = this.f; decoratee.x = x * a + y * c + e || 0; decoratee.y = x * b + y * d + f || 0; return decoratee; }; return Matrix2D; }(); function getGlobalMatrix(element, inverse, adjustGOffset, includeScrollInFixed) { if (!element || !element.parentNode || (_doc || _setDoc(element)).documentElement === element) { return new Matrix2D(); } var zeroScales = _forceNonZeroScale(element), svg = _svgOwner(element), temps = svg ? _svgTemps : _divTemps, container = _placeSiblings(element, adjustGOffset), b1 = temps[0].getBoundingClientRect(), b2 = temps[1].getBoundingClientRect(), b3 = temps[2].getBoundingClientRect(), parent = container.parentNode, isFixed = !includeScrollInFixed && _isFixed(element), m = new Matrix2D((b2.left - b1.left) / 100, (b2.top - b1.top) / 100, (b3.left - b1.left) / 100, (b3.top - b1.top) / 100, b1.left + (isFixed ? 0 : _getDocScrollLeft()), b1.top + (isFixed ? 0 : _getDocScrollTop())); parent.removeChild(container); if (zeroScales) { b1 = zeroScales.length; while (b1--) { b2 = zeroScales[b1]; b2.scaleX = b2.scaleY = 0; b2.renderTransform(1, b2); } } return inverse ? m.inverse() : m; } var gsap, _win$1, _doc$1, _docElement$1, _body$1, _tempDiv, _placeholderDiv, _coreInitted, _checkPrefix, _toArray, _supportsPassive, _isTouchDevice, _touchEventLookup, _isMultiTouching, _isAndroid, InertiaPlugin, _defaultCursor, _supportsPointer, _context, _getStyleSaver, _dragCount = 0, _windowExists = function _windowExists() { return typeof window !== "undefined"; }, _getGSAP = function _getGSAP() { return gsap || _windowExists() && (gsap = window.gsap) && gsap.registerPlugin && gsap; }, _isFunction = function _isFunction(value) { return typeof value === "function"; }, _isObject = function _isObject(value) { return typeof value === "object"; }, _isUndefined = function _isUndefined(value) { return typeof value === "undefined"; }, _emptyFunc = function _emptyFunc() { return false; }, _transformProp$1 = "transform", _transformOriginProp$1 = "transformOrigin", _round = function _round(value) { return Math.round(value * 10000) / 10000; }, _isArray = Array.isArray, _createElement = function _createElement(type, ns) { var e = _doc$1.createElementNS ? _doc$1.createElementNS((ns || "http://www.w3.org/1999/xhtml").replace(/^https/, "http"), type) : _doc$1.createElement(type); return e.style ? e : _doc$1.createElement(type); }, _RAD2DEG = 180 / Math.PI, _bigNum = 1e20, _identityMatrix$1 = new Matrix2D(), _getTime = Date.now || function () { return new Date().getTime(); }, _renderQueue = [], _lookup = {}, _lookupCount = 0, _clickableTagExp = /^(?:a|input|textarea|button|select)$/i, _lastDragTime = 0, _temp1 = {}, _windowProxy = {}, _copy = function _copy(obj, factor) { var copy = {}, p; for (p in obj) { copy[p] = factor ? obj[p] * factor : obj[p]; } return copy; }, _extend = function _extend(obj, defaults) { for (var p in defaults) { if (!(p in obj)) { obj[p] = defaults[p]; } } return obj; }, _setTouchActionForAllDescendants = function _setTouchActionForAllDescendants(elements, value) { var i = elements.length, children; while (i--) { value ? elements[i].style.touchAction = value : elements[i].style.removeProperty("touch-action"); children = elements[i].children; children && children.length && _setTouchActionForAllDescendants(children, value); } }, _renderQueueTick = function _renderQueueTick() { return _renderQueue.forEach(function (func) { return func(); }); }, _addToRenderQueue = function _addToRenderQueue(func) { _renderQueue.push(func); if (_renderQueue.length === 1) { gsap.ticker.add(_renderQueueTick); } }, _renderQueueTimeout = function _renderQueueTimeout() { return !_renderQueue.length && gsap.ticker.remove(_renderQueueTick); }, _removeFromRenderQueue = function _removeFromRenderQueue(func) { var i = _renderQueue.length; while (i--) { if (_renderQueue[i] === func) { _renderQueue.splice(i, 1); } } gsap.to(_renderQueueTimeout, { overwrite: true, delay: 15, duration: 0, onComplete: _renderQueueTimeout, data: "_draggable" }); }, _setDefaults = function _setDefaults(obj, defaults) { for (var p in defaults) { if (!(p in obj)) { obj[p] = defaults[p]; } } return obj; }, _addListener = function _addListener(element, type, func, capture) { if (element.addEventListener) { var touchType = _touchEventLookup[type]; capture = capture || (_supportsPassive ? { passive: false } : null); element.addEventListener(touchType || type, func, capture); touchType && type !== touchType && element.addEventListener(type, func, capture); } }, _removeListener = function _removeListener(element, type, func, capture) { if (element.removeEventListener) { var touchType = _touchEventLookup[type]; element.removeEventListener(touchType || type, func, capture); touchType && type !== touchType && element.removeEventListener(type, func, capture); } }, _preventDefault = function _preventDefault(event) { event.preventDefault && event.preventDefault(); event.preventManipulation && event.preventManipulation(); }, _hasTouchID = function _hasTouchID(list, ID) { var i = list.length; while (i--) { if (list[i].identifier === ID) { return true; } } }, _onMultiTouchDocumentEnd = function _onMultiTouchDocumentEnd(event) { _isMultiTouching = event.touches && _dragCount < event.touches.length; _removeListener(event.target, "touchend", _onMultiTouchDocumentEnd); }, _onMultiTouchDocument = function _onMultiTouchDocument(event) { _isMultiTouching = event.touches && _dragCount < event.touches.length; _addListener(event.target, "touchend", _onMultiTouchDocumentEnd); }, _getDocScrollTop$1 = function _getDocScrollTop(doc) { return _win$1.pageYOffset || doc.scrollTop || doc.documentElement.scrollTop || doc.body.scrollTop || 0; }, _getDocScrollLeft$1 = function _getDocScrollLeft(doc) { return _win$1.pageXOffset || doc.scrollLeft || doc.documentElement.scrollLeft || doc.body.scrollLeft || 0; }, _addScrollListener = function _addScrollListener(e, callback) { _addListener(e, "scroll", callback); if (!_isRoot(e.parentNode)) { _addScrollListener(e.parentNode, callback); } }, _removeScrollListener = function _removeScrollListener(e, callback) { _removeListener(e, "scroll", callback); if (!_isRoot(e.parentNode)) { _removeScrollListener(e.parentNode, callback); } }, _isRoot = function _isRoot(e) { return !!(!e || e === _docElement$1 || e.nodeType === 9 || e === _doc$1.body || e === _win$1 || !e.nodeType || !e.parentNode); }, _getMaxScroll = function _getMaxScroll(element, axis) { var dim = axis === "x" ? "Width" : "Height", scroll = "scroll" + dim, client = "client" + dim; return Math.max(0, _isRoot(element) ? Math.max(_docElement$1[scroll], _body$1[scroll]) - (_win$1["inner" + dim] || _docElement$1[client] || _body$1[client]) : element[scroll] - element[client]); }, _recordMaxScrolls = function _recordMaxScrolls(e, skipCurrent) { var x = _getMaxScroll(e, "x"), y = _getMaxScroll(e, "y"); if (_isRoot(e)) { e = _windowProxy; } else { _recordMaxScrolls(e.parentNode, skipCurrent); } e._gsMaxScrollX = x; e._gsMaxScrollY = y; if (!skipCurrent) { e._gsScrollX = e.scrollLeft || 0; e._gsScrollY = e.scrollTop || 0; } }, _setStyle = function _setStyle(element, property, value) { var style = element.style; if (!style) { return; } if (_isUndefined(style[property])) { property = _checkPrefix(property, element) || property; } if (value == null) { style.removeProperty && style.removeProperty(property.replace(/([A-Z])/g, "-$1").toLowerCase()); } else { style[property] = value; } }, _getComputedStyle = function _getComputedStyle(element) { return _win$1.getComputedStyle(element instanceof Element ? element : element.host || (element.parentNode || {}).host || element); }, _tempRect = {}, _parseRect = function _parseRect(e) { if (e === _win$1) { _tempRect.left = _tempRect.top = 0; _tempRect.width = _tempRect.right = _docElement$1.clientWidth || e.innerWidth || _body$1.clientWidth || 0; _tempRect.height = _tempRect.bottom = (e.innerHeight || 0) - 20 < _docElement$1.clientHeight ? _docElement$1.clientHeight : e.innerHeight || _body$1.clientHeight || 0; return _tempRect; } var doc = e.ownerDocument || _doc$1, r = !_isUndefined(e.pageX) ? { left: e.pageX - _getDocScrollLeft$1(doc), top: e.pageY - _getDocScrollTop$1(doc), right: e.pageX - _getDocScrollLeft$1(doc) + 1, bottom: e.pageY - _getDocScrollTop$1(doc) + 1 } : !e.nodeType && !_isUndefined(e.left) && !_isUndefined(e.top) ? e : _toArray(e)[0].getBoundingClientRect(); if (_isUndefined(r.right) && !_isUndefined(r.width)) { r.right = r.left + r.width; r.bottom = r.top + r.height; } else if (_isUndefined(r.width)) { r = { width: r.right - r.left, height: r.bottom - r.top, right: r.right, left: r.left, bottom: r.bottom, top: r.top }; } return r; }, _dispatchEvent = function _dispatchEvent(target, type, callbackName) { var vars = target.vars, callback = vars[callbackName], listeners = target._listeners[type], result; if (_isFunction(callback)) { result = callback.apply(vars.callbackScope || target, vars[callbackName + "Params"] || [target.pointerEvent]); } if (listeners && target.dispatchEvent(type) === false) { result = false; } return result; }, _getBounds = function _getBounds(target, context) { var e = _toArray(target)[0], top, left, offset; if (!e.nodeType && e !== _win$1) { if (!_isUndefined(target.left)) { offset = { x: 0, y: 0 }; return { left: target.left - offset.x, top: target.top - offset.y, width: target.width, height: target.height }; } left = target.min || target.minX || target.minRotation || 0; top = target.min || target.minY || 0; return { left: left, top: top, width: (target.max || target.maxX || target.maxRotation || 0) - left, height: (target.max || target.maxY || 0) - top }; } return _getElementBounds(e, context); }, _point1 = {}, _getElementBounds = function _getElementBounds(element, context) { context = _toArray(context)[0]; var isSVG = element.getBBox && element.ownerSVGElement, doc = element.ownerDocument || _doc$1, left, right, top, bottom, matrix, p1, p2, p3, p4, bbox, width, height, cs; if (element === _win$1) { top = _getDocScrollTop$1(doc); left = _getDocScrollLeft$1(doc); right = left + (doc.documentElement.clientWidth || element.innerWidth || doc.body.clientWidth || 0); bottom = top + ((element.innerHeight || 0) - 20 < doc.documentElement.clientHeight ? doc.documentElement.clientHeight : element.innerHeight || doc.body.clientHeight || 0); } else if (context === _win$1 || _isUndefined(context)) { return element.getBoundingClientRect(); } else { left = top = 0; if (isSVG) { bbox = element.getBBox(); width = bbox.width; height = bbox.height; } else { if (element.viewBox && (bbox = element.viewBox.baseVal)) { left = bbox.x || 0; top = bbox.y || 0; width = bbox.width; height = bbox.height; } if (!width) { cs = _getComputedStyle(element); bbox = cs.boxSizing === "border-box"; width = (parseFloat(cs.width) || element.clientWidth || 0) + (bbox ? 0 : parseFloat(cs.borderLeftWidth) + parseFloat(cs.borderRightWidth)); height = (parseFloat(cs.height) || element.clientHeight || 0) + (bbox ? 0 : parseFloat(cs.borderTopWidth) + parseFloat(cs.borderBottomWidth)); } } right = width; bottom = height; } if (element === context) { return { left: left, top: top, width: right - left, height: bottom - top }; } matrix = getGlobalMatrix(context, true).multiply(getGlobalMatrix(element)); p1 = matrix.apply({ x: left, y: top }); p2 = matrix.apply({ x: right, y: top }); p3 = matrix.apply({ x: right, y: bottom }); p4 = matrix.apply({ x: left, y: bottom }); left = Math.min(p1.x, p2.x, p3.x, p4.x); top = Math.min(p1.y, p2.y, p3.y, p4.y); return { left: left, top: top, width: Math.max(p1.x, p2.x, p3.x, p4.x) - left, height: Math.max(p1.y, p2.y, p3.y, p4.y) - top }; }, _parseInertia = function _parseInertia(draggable, snap, max, min, factor, forceZeroVelocity) { var vars = {}, a, i, l; if (snap) { if (factor !== 1 && snap instanceof Array) { vars.end = a = []; l = snap.length; if (_isObject(snap[0])) { for (i = 0; i < l; i++) { a[i] = _copy(snap[i], factor); } } else { for (i = 0; i < l; i++) { a[i] = snap[i] * factor; } } max += 1.1; min -= 1.1; } else if (_isFunction(snap)) { vars.end = function (value) { var result = snap.call(draggable, value), copy, p; if (factor !== 1) { if (_isObject(result)) { copy = {}; for (p in result) { copy[p] = result[p] * factor; } result = copy; } else { result *= factor; } } return result; }; } else { vars.end = snap; } } if (max || max === 0) { vars.max = max; } if (min || min === 0) { vars.min = min; } if (forceZeroVelocity) { vars.velocity = 0; } return vars; }, _isClickable = function _isClickable(element) { var data; return !element || !element.getAttribute || element === _body$1 ? false : (data = element.getAttribute("data-clickable")) === "true" || data !== "false" && (_clickableTagExp.test(element.nodeName + "") || element.getAttribute("contentEditable") === "true") ? true : _isClickable(element.parentNode); }, _setSelectable = function _setSelectable(elements, selectable) { var i = elements.length, e; while (i--) { e = elements[i]; e.ondragstart = e.onselectstart = selectable ? null : _emptyFunc; gsap.set(e, { lazy: true, userSelect: selectable ? "text" : "none" }); } }, _isFixed$1 = function _isFixed(element) { if (_getComputedStyle(element).position === "fixed") { return true; } element = element.parentNode; if (element && element.nodeType === 1) { return _isFixed(element); } }, _supports3D, _addPaddingBR, ScrollProxy = function ScrollProxy(element, vars) { element = gsap.utils.toArray(element)[0]; vars = vars || {}; var content = document.createElement("div"), style = content.style, node = element.firstChild, offsetTop = 0, offsetLeft = 0, prevTop = element.scrollTop, prevLeft = element.scrollLeft, scrollWidth = element.scrollWidth, scrollHeight = element.scrollHeight, extraPadRight = 0, maxLeft = 0, maxTop = 0, elementWidth, elementHeight, contentHeight, nextNode, transformStart, transformEnd; if (_supports3D && vars.force3D !== false) { transformStart = "translate3d("; transformEnd = "px,0px)"; } else if (_transformProp$1) { transformStart = "translate("; transformEnd = "px)"; } this.scrollTop = function (value, force) { if (!arguments.length) { return -this.top(); } this.top(-value, force); }; this.scrollLeft = function (value, force) { if (!arguments.length) { return -this.left(); } this.left(-value, force); }; this.left = function (value, force) { if (!arguments.length) { return -(element.scrollLeft + offsetLeft); } var dif = element.scrollLeft - prevLeft, oldOffset = offsetLeft; if ((dif > 2 || dif < -2) && !force) { prevLeft = element.scrollLeft; gsap.killTweensOf(this, { left: 1, scrollLeft: 1 }); this.left(-prevLeft); if (vars.onKill) { vars.onKill(); } return; } value = -value; if (value < 0) { offsetLeft = value - 0.5 | 0; value = 0; } else if (value > maxLeft) { offsetLeft = value - maxLeft | 0; value = maxLeft; } else { offsetLeft = 0; } if (offsetLeft || oldOffset) { if (!this._skip) { style[_transformProp$1] = transformStart + -offsetLeft + "px," + -offsetTop + transformEnd; } if (offsetLeft + extraPadRight >= 0) { style.paddingRight = offsetLeft + extraPadRight + "px"; } } element.scrollLeft = value | 0; prevLeft = element.scrollLeft; }; this.top = function (value, force) { if (!arguments.length) { return -(element.scrollTop + offsetTop); } var dif = element.scrollTop - prevTop, oldOffset = offsetTop; if ((dif > 2 || dif < -2) && !force) { prevTop = element.scrollTop; gsap.killTweensOf(this, { top: 1, scrollTop: 1 }); this.top(-prevTop); if (vars.onKill) { vars.onKill(); } return; } value = -value; if (value < 0) { offsetTop = value - 0.5 | 0; value = 0; } else if (value > maxTop) { offsetTop = value - maxTop | 0; value = maxTop; } else { offsetTop = 0; } if (offsetTop || oldOffset) { if (!this._skip) { style[_transformProp$1] = transformStart + -offsetLeft + "px," + -offsetTop + transformEnd; } } element.scrollTop = value | 0; prevTop = element.scrollTop; }; this.maxScrollTop = function () { return maxTop; }; this.maxScrollLeft = function () { return maxLeft; }; this.disable = function () { node = content.firstChild; while (node) { nextNode = node.nextSibling; element.appendChild(node); node = nextNode; } if (element === content.parentNode) { element.removeChild(content); } }; this.enable = function () { node = element.firstChild; if (node === content) { return; } while (node) { nextNode = node.nextSibling; content.appendChild(node); node = nextNode; } element.appendChild(content); this.calibrate(); }; this.calibrate = function (force) { var widthMatches = element.clientWidth === elementWidth, cs, x, y; prevTop = element.scrollTop; prevLeft = element.scrollLeft; if (widthMatches && element.clientHeight === elementHeight && content.offsetHeight === contentHeight && scrollWidth === element.scrollWidth && scrollHeight === element.scrollHeight && !force) { return; } if (offsetTop || offsetLeft) { x = this.left(); y = this.top(); this.left(-element.scrollLeft); this.top(-element.scrollTop); } cs = _getComputedStyle(element); if (!widthMatches || force) { style.display = "block"; style.width = "auto"; style.paddingRight = "0px"; extraPadRight = Math.max(0, element.scrollWidth - element.clientWidth); if (extraPadRight) { extraPadRight += parseFloat(cs.paddingLeft) + (_addPaddingBR ? parseFloat(cs.paddingRight) : 0); } } style.display = "inline-block"; style.position = "relative"; style.overflow = "visible"; style.verticalAlign = "top"; style.boxSizing = "content-box"; style.width = "100%"; style.paddingRight = extraPadRight + "px"; if (_addPaddingBR) { style.paddingBottom = cs.paddingBottom; } elementWidth = element.clientWidth; elementHeight = element.clientHeight; scrollWidth = element.scrollWidth; scrollHeight = element.scrollHeight; maxLeft = element.scrollWidth - elementWidth; maxTop = element.scrollHeight - elementHeight; contentHeight = content.offsetHeight; style.display = "block"; if (x || y) { this.left(x); this.top(y); } }; this.content = content; this.element = element; this._skip = false; this.enable(); }, _initCore = function _initCore(required) { if (_windowExists() && document.body) { var nav = window && window.navigator; _win$1 = window; _doc$1 = document; _docElement$1 = _doc$1.documentElement; _body$1 = _doc$1.body; _tempDiv = _createElement("div"); _supportsPointer = !!window.PointerEvent; _placeholderDiv = _createElement("div"); _placeholderDiv.style.cssText = "visibility:hidden;height:1px;top:-1px;pointer-events:none;position:relative;clear:both;cursor:grab"; _defaultCursor = _placeholderDiv.style.cursor === "grab" ? "grab" : "move"; _isAndroid = nav && nav.userAgent.toLowerCase().indexOf("android") !== -1; _isTouchDevice = "ontouchstart" in _docElement$1 && "orientation" in _win$1 || nav && (nav.MaxTouchPoints > 0 || nav.msMaxTouchPoints > 0); _addPaddingBR = function () { var div = _createElement("div"), child = _createElement("div"), childStyle = child.style, parent = _body$1, val; childStyle.display = "inline-block"; childStyle.position = "relative"; div.style.cssText = "width:90px;height:40px;padding:10px;overflow:auto;visibility:hidden"; div.appendChild(child); parent.appendChild(div); val = child.offsetHeight + 18 > div.scrollHeight; parent.removeChild(div); return val; }(); _touchEventLookup = function (types) { var standard = types.split(","), converted = ("onpointerdown" in _tempDiv ? "pointerdown,pointermove,pointerup,pointercancel" : "onmspointerdown" in _tempDiv ? "MSPointerDown,MSPointerMove,MSPointerUp,MSPointerCancel" : types).split(","), obj = {}, i = 4; while (--i > -1) { obj[standard[i]] = converted[i]; obj[converted[i]] = standard[i]; } try { _docElement$1.addEventListener("test", null, Object.defineProperty({}, "passive", { get: function get() { _supportsPassive = 1; } })); } catch (e) {} return obj; }("touchstart,touchmove,touchend,touchcancel"); _addListener(_doc$1, "touchcancel", _emptyFunc); _addListener(_win$1, "touchmove", _emptyFunc); _body$1 && _body$1.addEventListener("touchstart", _emptyFunc); _addListener(_doc$1, "contextmenu", function () { for (var p in _lookup) { if (_lookup[p].isPressed) { _lookup[p].endDrag(); } } }); gsap = _coreInitted = _getGSAP(); } if (gsap) { InertiaPlugin = gsap.plugins.inertia; _context = gsap.core.context || function () {}; _checkPrefix = gsap.utils.checkPrefix; _transformProp$1 = _checkPrefix(_transformProp$1); _transformOriginProp$1 = _checkPrefix(_transformOriginProp$1); _toArray = gsap.utils.toArray; _getStyleSaver = gsap.core.getStyleSaver; _supports3D = !!_checkPrefix("perspective"); } else if (required) { console.warn("Please gsap.registerPlugin(Draggable)"); } }; var EventDispatcher = function () { function EventDispatcher(target) { this._listeners = {}; this.target = target || this; } var _proto = EventDispatcher.prototype; _proto.addEventListener = function addEventListener(type, callback) { var list = this._listeners[type] || (this._listeners[type] = []); if (!~list.indexOf(callback)) { list.push(callback); } }; _proto.removeEventListener = function removeEventListener(type, callback) { var list = this._listeners[type], i = list && list.indexOf(callback); i >= 0 && list.splice(i, 1); }; _proto.dispatchEvent = function dispatchEvent(type) { var _this = this; var result; (this._listeners[type] || []).forEach(function (callback) { return callback.call(_this, { type: type, target: _this.target }) === false && (result = false); }); return result; }; return EventDispatcher; }(); var Draggable = function (_EventDispatcher) { _inheritsLoose(Draggable, _EventDispatcher); function Draggable(target, vars) { var _this2; _this2 = _EventDispatcher.call(this) || this; _coreInitted || _initCore(1); target = _toArray(target)[0]; _this2.styles = _getStyleSaver && _getStyleSaver(target, "transform,left,top"); if (!InertiaPlugin) { InertiaPlugin = gsap.plugins.inertia; } _this2.vars = vars = _copy(vars || {}); _this2.target = target; _this2.x = _this2.y = _this2.rotation = 0; _this2.dragResistance = parseFloat(vars.dragResistance) || 0; _this2.edgeResistance = isNaN(vars.edgeResistance) ? 1 : parseFloat(vars.edgeResistance) || 0; _this2.lockAxis = vars.lockAxis; _this2.autoScroll = vars.autoScroll || 0; _this2.lockedAxis = null; _this2.allowEventDefault = !!vars.allowEventDefault; gsap.getProperty(target, "x"); var type = (vars.type || "x,y").toLowerCase(), xyMode = ~type.indexOf("x") || ~type.indexOf("y"), rotationMode = type.indexOf("rotation") !== -1, xProp = rotationMode ? "rotation" : xyMode ? "x" : "left", yProp = xyMode ? "y" : "top", allowX = !!(~type.indexOf("x") || ~type.indexOf("left") || type === "scroll"), allowY = !!(~type.indexOf("y") || ~type.indexOf("top") || type === "scroll"), minimumMovement = vars.minimumMovement || 2, self = _assertThisInitialized(_this2), triggers = _toArray(vars.trigger || vars.handle || target), killProps = {}, dragEndTime = 0, checkAutoScrollBounds = false, autoScrollMarginTop = vars.autoScrollMarginTop || 40, autoScrollMarginRight = vars.autoScrollMarginRight || 40, autoScrollMarginBottom = vars.autoScrollMarginBottom || 40, autoScrollMarginLeft = vars.autoScrollMarginLeft || 40, isClickable = vars.clickableTest || _isClickable, clickTime = 0, gsCache = target._gsap || gsap.core.getCache(target), isFixed = _isFixed$1(target), getPropAsNum = function getPropAsNum(property, unit) { return parseFloat(gsCache.get(target, property, unit)); }, ownerDoc = target.ownerDocument || _doc$1, enabled, scrollProxy, startPointerX, startPointerY, startElementX, startElementY, hasBounds, hasDragCallback, hasMoveCallback, maxX, minX, maxY, minY, touch, touchID, rotationOrigin, dirty, old, snapX, snapY, snapXY, isClicking, touchEventTarget, matrix, interrupted, allowNativeTouchScrolling, touchDragAxis, isDispatching, clickDispatch, trustedClickDispatch, isPreventingDefault, innerMatrix, dragged, onContextMenu = function onContextMenu(e) { _preventDefault(e); e.stopImmediatePropagation && e.stopImmediatePropagation(); return false; }, render = function render(suppressEvents) { if (self.autoScroll && self.isDragging && (checkAutoScrollBounds || dirty)) { var e = target, autoScrollFactor = self.autoScroll * 15, parent, isRoot, rect, pointerX, pointerY, changeX, changeY, gap; checkAutoScrollBounds = false; _windowProxy.scrollTop = _win$1.pageYOffset != null ? _win$1.pageYOffset : ownerDoc.documentElement.scrollTop != null ? ownerDoc.documentElement.scrollTop : ownerDoc.body.scrollTop; _windowProxy.scrollLeft = _win$1.pageXOffset != null ? _win$1.pageXOffset : ownerDoc.documentElement.scrollLeft != null ? ownerDoc.documentElement.scrollLeft : ownerDoc.body.scrollLeft; pointerX = self.pointerX - _windowProxy.scrollLeft; pointerY = self.pointerY - _windowProxy.scrollTop; while (e && !isRoot) { isRoot = _isRoot(e.parentNode); parent = isRoot ? _windowProxy : e.parentNode; rect = isRoot ? { bottom: Math.max(_docElement$1.clientHeight, _win$1.innerHeight || 0), right: Math.max(_docElement$1.clientWidth, _win$1.innerWidth || 0), left: 0, top: 0 } : parent.getBoundingClientRect(); changeX = changeY = 0; if (allowY) { gap = parent._gsMaxScrollY - parent.scrollTop; if (gap < 0) { changeY = gap; } else if (pointerY > rect.bottom - autoScrollMarginBottom && gap) { checkAutoScrollBounds = true; changeY = Math.min(gap, autoScrollFactor * (1 - Math.max(0, rect.bottom - pointerY) / autoScrollMarginBottom) | 0); } else if (pointerY < rect.top + autoScrollMarginTop && parent.scrollTop) { checkAutoScrollBounds = true; changeY = -Math.min(parent.scrollTop, autoScrollFactor * (1 - Math.max(0, pointerY - rect.top) / autoScrollMarginTop) | 0); } if (changeY) { parent.scrollTop += changeY; } } if (allowX) { gap = parent._gsMaxScrollX - parent.scrollLeft; if (gap < 0) { changeX = gap; } else if (pointerX > rect.right - autoScrollMarginRight && gap) { checkAutoScrollBounds = true; changeX = Math.min(gap, autoScrollFactor * (1 - Math.max(0, rect.right - pointerX) / autoScrollMarginRight) | 0); } else if (pointerX < rect.left + autoScrollMarginLeft && parent.scrollLeft) { checkAutoScrollBounds = true; changeX = -Math.min(parent.scrollLeft, autoScrollFactor * (1 - Math.max(0, pointerX - rect.left) / autoScrollMarginLeft) | 0); } if (changeX) { parent.scrollLeft += changeX; } } if (isRoot && (changeX || changeY)) { _win$1.scrollTo(parent.scrollLeft, parent.scrollTop); setPointerPosition(self.pointerX + changeX, self.pointerY + changeY); } e = parent; } } if (dirty) { var x = self.x, y = self.y; if (rotationMode) { self.deltaX = x - parseFloat(gsCache.rotation); self.rotation = x; gsCache.rotation = x + "deg"; gsCache.renderTransform(1, gsCache); } else { if (scrollProxy) { if (allowY) { self.deltaY = y - scrollProxy.top(); scrollProxy.top(y); } if (allowX) { self.deltaX = x - scrollProxy.left(); scrollProxy.left(x); } } else if (xyMode) { if (allowY) { self.deltaY = y - parseFloat(gsCache.y); gsCache.y = y + "px"; } if (allowX) { self.deltaX = x - parseFloat(gsCache.x); gsCache.x = x + "px"; } gsCache.renderTransform(1, gsCache); } else { if (allowY) { self.deltaY = y - parseFloat(target.style.top || 0); target.style.top = y + "px"; } if (allowX) { self.deltaX = x - parseFloat(target.style.left || 0); target.style.left = x + "px"; } } } if (hasDragCallback && !suppressEvents && !isDispatching) { isDispatching = true; if (_dispatchEvent(self, "drag", "onDrag") === false) { if (allowX) { self.x -= self.deltaX; } if (allowY) { self.y -= self.deltaY; } render(true); } isDispatching = false; } } dirty = false; }, syncXY = function syncXY(skipOnUpdate, skipSnap) { var x = self.x, y = self.y, snappedValue, cs; if (!target._gsap) { gsCache = gsap.core.getCache(target); } gsCache.uncache && gsap.getProperty(target, "x"); if (xyMode) { self.x = parseFloat(gsCache.x); self.y = parseFloat(gsCache.y); } else if (rotationMode) { self.x = self.rotation = parseFloat(gsCache.rotation); } else if (scrollProxy) { self.y = scrollProxy.top(); self.x = scrollProxy.left(); } else { self.y = parseFloat(target.style.top || (cs = _getComputedStyle(target)) && cs.top) || 0; self.x = parseFloat(target.style.left || (cs || {}).left) || 0; } if ((snapX || snapY || snapXY) && !skipSnap && (self.isDragging || self.isThrowing)) { if (snapXY) { _temp1.x = self.x; _temp1.y = self.y; snappedValue = snapXY(_temp1); if (snappedValue.x !== self.x) { self.x = snappedValue.x; dirty = true; } if (snappedValue.y !== self.y) { self.y = snappedValue.y; dirty = true; } } if (snapX) { snappedValue = snapX(self.x); if (snappedValue !== self.x) { self.x = snappedValue; if (rotationMode) { self.rotation = snappedValue; } dirty = true; } } if (snapY) { snappedValue = snapY(self.y); if (snappedValue !== self.y) { self.y = snappedValue; } dirty = true; } } dirty && render(true); if (!skipOnUpdate) { self.deltaX = self.x - x; self.deltaY = self.y - y; _dispatchEvent(self, "throwupdate", "onThrowUpdate"); } }, buildSnapFunc = function buildSnapFunc(snap, min, max, factor) { if (min == null) { min = -_bigNum; } if (max == null) { max = _bigNum; } if (_isFunction(snap)) { return function (n) { var edgeTolerance = !self.isPressed ? 1 : 1 - self.edgeResistance; return snap.call(self, (n > max ? max + (n - max) * edgeTolerance : n < min ? min + (n - min) * edgeTolerance : n) * factor) * factor; }; } if (_isArray(snap)) { return function (n) { var i = snap.length, closest = 0, absDif = _bigNum, val, dif; while (--i > -1) { val = snap[i]; dif = val - n; if (dif < 0) { dif = -dif; } if (dif < absDif && val >= min && val <= max) { closest = i; absDif = dif; } } return snap[closest]; }; } return isNaN(snap) ? function (n) { return n; } : function () { return snap * factor; }; }, buildPointSnapFunc = function buildPointSnapFunc(snap, minX, maxX, minY, maxY, radius, factor) { radius = radius && radius < _bigNum ? radius * radius : _bigNum; if (_isFunction(snap)) { return function (point) { var edgeTolerance = !self.isPressed ? 1 : 1 - self.edgeResistance, x = point.x, y = point.y, result, dx, dy; point.x = x = x > maxX ? maxX + (x - maxX) * edgeTolerance : x < minX ? minX + (x - minX) * edgeTolerance : x; point.y = y = y > maxY ? maxY + (y - maxY) * edgeTolerance : y < minY ? minY + (y - minY) * edgeTolerance : y; result = snap.call(self, point); if (result !== point) { point.x = result.x; point.y = result.y; } if (factor !== 1) { point.x *= factor; point.y *= factor; } if (radius < _bigNum) { dx = point.x - x; dy = point.y - y; if (dx * dx + dy * dy > radius) { point.x = x; point.y = y; } } return point; }; } if (_isArray(snap)) { return function (p) { var i = snap.length, closest = 0, minDist = _bigNum, x, y, point, dist; while (--i > -1) { point = snap[i]; x = point.x - p.x; y = point.y - p.y; dist = x * x + y * y; if (dist < minDist) { closest = i; minDist = dist; } } return minDist <= radius ? snap[closest] : p; }; } return function (n) { return n; }; }, calculateBounds = function calculateBounds() { var bounds, targetBounds, snap, snapIsRaw; hasBounds = false; if (scrollProxy) { scrol