UNPKG

51 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3 typeof define === 'function' && define.amd ? define(['exports'], factory) :
4 (global = global || self, factory(global.window = global.window || {}));
5}(this, (function (exports) { 'use strict';
6
7 /*!
8 * ScrollTrigger 3.5.1
9 * https://greensock.com
10 *
11 * @license Copyright 2008-2020, GreenSock. All rights reserved.
12 * Subject to the terms at https://greensock.com/standard-license or for
13 * Club GreenSock members, the agreement issued with that membership.
14 * @author: Jack Doyle, jack@greensock.com
15 */
16 var gsap,
17 _coreInitted,
18 _win,
19 _doc,
20 _docEl,
21 _body,
22 _root,
23 _resizeDelay,
24 _raf,
25 _request,
26 _toArray,
27 _clamp,
28 _time2,
29 _syncInterval,
30 _refreshing,
31 _pointerIsDown,
32 _transformProp,
33 _i,
34 _prevWidth,
35 _prevHeight,
36 _autoRefresh,
37 _sort,
38 _limitCallbacks,
39 _startup = 1,
40 _proxies = [],
41 _scrollers = [],
42 _getTime = Date.now,
43 _time1 = _getTime(),
44 _lastScrollTime = 0,
45 _enabled = 1,
46 _passThrough = function _passThrough(v) {
47 return v;
48 },
49 _windowExists = function _windowExists() {
50 return typeof window !== "undefined";
51 },
52 _getGSAP = function _getGSAP() {
53 return gsap || _windowExists() && (gsap = window.gsap) && gsap.registerPlugin && gsap;
54 },
55 _isViewport = function _isViewport(e) {
56 return !!~_root.indexOf(e);
57 },
58 _getProxyProp = function _getProxyProp(element, property) {
59 return ~_proxies.indexOf(element) && _proxies[_proxies.indexOf(element) + 1][property];
60 },
61 _getScrollFunc = function _getScrollFunc(element, _ref) {
62 var s = _ref.s,
63 sc = _ref.sc;
64
65 var i = _scrollers.indexOf(element),
66 offset = sc === _vertical.sc ? 1 : 2;
67
68 !~i && (i = _scrollers.push(element) - 1);
69 return _scrollers[i + offset] || (_scrollers[i + offset] = _getProxyProp(element, s) || (_isViewport(element) ? sc : function (value) {
70 return arguments.length ? element[s] = value : element[s];
71 }));
72 },
73 _getBoundsFunc = function _getBoundsFunc(element) {
74 return _getProxyProp(element, "getBoundingClientRect") || (_isViewport(element) ? function () {
75 _winOffsets.width = _win.innerWidth;
76 _winOffsets.height = _win.innerHeight;
77 return _winOffsets;
78 } : function () {
79 return _getBounds(element);
80 });
81 },
82 _getSizeFunc = function _getSizeFunc(scroller, isViewport, _ref2) {
83 var d = _ref2.d,
84 d2 = _ref2.d2,
85 a = _ref2.a;
86 return (a = _getProxyProp(scroller, "getBoundingClientRect")) ? function () {
87 return a()[d];
88 } : function () {
89 return (isViewport ? _win["inner" + d2] : scroller["client" + d2]) || 0;
90 };
91 },
92 _getOffsetsFunc = function _getOffsetsFunc(element, isViewport) {
93 return !isViewport || ~_proxies.indexOf(element) ? _getBoundsFunc(element) : function () {
94 return _winOffsets;
95 };
96 },
97 _maxScroll = function _maxScroll(element, _ref3) {
98 var s = _ref3.s,
99 d2 = _ref3.d2,
100 d = _ref3.d,
101 a = _ref3.a;
102 return (s = "scroll" + d2) && (a = _getProxyProp(element, s)) ? a() - _getBoundsFunc(element)()[d] : _isViewport(element) ? Math.max(_docEl[s], _body[s]) - (_win["inner" + d2] || _docEl["client" + d2] || _body["client" + d2]) : element[s] - element["offset" + d2];
103 },
104 _iterateAutoRefresh = function _iterateAutoRefresh(func, events) {
105 for (var i = 0; i < _autoRefresh.length; i += 3) {
106 (!events || ~events.indexOf(_autoRefresh[i + 1])) && func(_autoRefresh[i], _autoRefresh[i + 1], _autoRefresh[i + 2]);
107 }
108 },
109 _isString = function _isString(value) {
110 return typeof value === "string";
111 },
112 _isFunction = function _isFunction(value) {
113 return typeof value === "function";
114 },
115 _isNumber = function _isNumber(value) {
116 return typeof value === "number";
117 },
118 _isObject = function _isObject(value) {
119 return typeof value === "object";
120 },
121 _callIfFunc = function _callIfFunc(value) {
122 return _isFunction(value) && value();
123 },
124 _combineFunc = function _combineFunc(f1, f2) {
125 return function () {
126 var result1 = _callIfFunc(f1),
127 result2 = _callIfFunc(f2);
128
129 return function () {
130 _callIfFunc(result1);
131
132 _callIfFunc(result2);
133 };
134 };
135 },
136 _abs = Math.abs,
137 _scrollLeft = "scrollLeft",
138 _scrollTop = "scrollTop",
139 _left = "left",
140 _top = "top",
141 _right = "right",
142 _bottom = "bottom",
143 _width = "width",
144 _height = "height",
145 _Right = "Right",
146 _Left = "Left",
147 _Top = "Top",
148 _Bottom = "Bottom",
149 _padding = "padding",
150 _margin = "margin",
151 _Width = "Width",
152 _Height = "Height",
153 _px = "px",
154 _horizontal = {
155 s: _scrollLeft,
156 p: _left,
157 p2: _Left,
158 os: _right,
159 os2: _Right,
160 d: _width,
161 d2: _Width,
162 a: "x",
163 sc: function sc(value) {
164 return arguments.length ? _win.scrollTo(value, _vertical.sc()) : _win.pageXOffset || _doc[_scrollLeft] || _docEl[_scrollLeft] || _body[_scrollLeft] || 0;
165 }
166 },
167 _vertical = {
168 s: _scrollTop,
169 p: _top,
170 p2: _Top,
171 os: _bottom,
172 os2: _Bottom,
173 d: _height,
174 d2: _Height,
175 a: "y",
176 op: _horizontal,
177 sc: function sc(value) {
178 return arguments.length ? _win.scrollTo(_horizontal.sc(), value) : _win.pageYOffset || _doc[_scrollTop] || _docEl[_scrollTop] || _body[_scrollTop] || 0;
179 }
180 },
181 _getComputedStyle = function _getComputedStyle(element) {
182 return _win.getComputedStyle(element);
183 },
184 _makePositionable = function _makePositionable(element) {
185 return element.style.position = _getComputedStyle(element).position === "absolute" ? "absolute" : "relative";
186 },
187 _setDefaults = function _setDefaults(obj, defaults) {
188 for (var p in defaults) {
189 p in obj || (obj[p] = defaults[p]);
190 }
191
192 return obj;
193 },
194 _getBounds = function _getBounds(element, withoutTransforms) {
195 var tween = withoutTransforms && _getComputedStyle(element)[_transformProp] !== "matrix(1, 0, 0, 1, 0, 0)" && gsap.to(element, {
196 x: 0,
197 y: 0,
198 xPercent: 0,
199 yPercent: 0,
200 rotation: 0,
201 rotationX: 0,
202 rotationY: 0,
203 scale: 1,
204 skewX: 0,
205 skewY: 0
206 }).progress(1),
207 bounds = element.getBoundingClientRect();
208 tween && tween.progress(0).kill();
209 return bounds;
210 },
211 _getSize = function _getSize(element, _ref4) {
212 var d2 = _ref4.d2;
213 return element["offset" + d2] || element["client" + d2] || 0;
214 },
215 _getLabels = function _getLabels(animation) {
216 return function (value) {
217 var a = [],
218 labels = animation.labels,
219 duration = animation.duration(),
220 p;
221
222 for (p in labels) {
223 a.push(labels[p] / duration);
224 }
225
226 return gsap.utils.snap(a, value);
227 };
228 },
229 _multiListener = function _multiListener(func, element, types, callback) {
230 return types.split(",").forEach(function (type) {
231 return func(element, type, callback);
232 });
233 },
234 _addListener = function _addListener(element, type, func) {
235 return element.addEventListener(type, func, {
236 passive: true
237 });
238 },
239 _removeListener = function _removeListener(element, type, func) {
240 return element.removeEventListener(type, func);
241 },
242 _markerDefaults = {
243 startColor: "green",
244 endColor: "red",
245 indent: 0,
246 fontSize: "16px",
247 fontWeight: "normal"
248 },
249 _defaults = {
250 toggleActions: "play",
251 anticipatePin: 0
252 },
253 _keywords = {
254 top: 0,
255 left: 0,
256 center: 0.5,
257 bottom: 1,
258 right: 1
259 },
260 _offsetToPx = function _offsetToPx(value, size) {
261 if (_isString(value)) {
262 var eqIndex = value.indexOf("="),
263 relative = ~eqIndex ? +(value.charAt(eqIndex - 1) + 1) * parseFloat(value.substr(eqIndex + 1)) : 0;
264
265 if (relative) {
266 value.indexOf("%") > eqIndex && (relative *= size / 100);
267 value = value.substr(0, eqIndex - 1);
268 }
269
270 value = relative + (value in _keywords ? _keywords[value] * size : ~value.indexOf("%") ? parseFloat(value) * size / 100 : parseFloat(value) || 0);
271 }
272
273 return value;
274 },
275 _createMarker = function _createMarker(type, name, container, direction, _ref5, offset, matchWidthEl) {
276 var startColor = _ref5.startColor,
277 endColor = _ref5.endColor,
278 fontSize = _ref5.fontSize,
279 indent = _ref5.indent,
280 fontWeight = _ref5.fontWeight;
281
282 var e = _doc.createElement("div"),
283 useFixedPosition = _isViewport(container) || _getProxyProp(container, "pinType") === "fixed",
284 isScroller = type.indexOf("scroller") !== -1,
285 parent = useFixedPosition ? _body : container,
286 isStart = type.indexOf("start") !== -1,
287 color = isStart ? startColor : endColor,
288 css = "border-color:" + color + ";font-size:" + fontSize + ";color:" + color + ";font-weight:" + fontWeight + ";pointer-events:none;white-space:nowrap;font-family:sans-serif,Arial;z-index:1000;padding:4px 8px;border-width:0;border-style:solid;";
289
290 css += "position:" + (isScroller && useFixedPosition ? "fixed;" : "absolute;");
291 (isScroller || !useFixedPosition) && (css += (direction === _vertical ? _right : _bottom) + ":" + (offset + parseFloat(indent)) + "px;");
292 matchWidthEl && (css += "box-sizing:border-box;text-align:left;width:" + matchWidthEl.offsetWidth + "px;");
293 e._isStart = isStart;
294 e.setAttribute("class", "gsap-marker-" + type);
295 e.style.cssText = css;
296 e.innerText = name || name === 0 ? type + "-" + name : type;
297 parent.insertBefore(e, parent.children[0]);
298 e._offset = e["offset" + direction.op.d2];
299
300 _positionMarker(e, 0, direction, isStart);
301
302 return e;
303 },
304 _positionMarker = function _positionMarker(marker, start, direction, flipped) {
305 var vars = {
306 display: "block"
307 },
308 side = direction[flipped ? "os2" : "p2"],
309 oppositeSide = direction[flipped ? "p2" : "os2"];
310 marker._isFlipped = flipped;
311 vars[direction.a + "Percent"] = flipped ? -100 : 0;
312 vars[direction.a] = flipped ? 1 : 0;
313 vars["border" + side + _Width] = 1;
314 vars["border" + oppositeSide + _Width] = 0;
315 vars[direction.p] = start;
316 gsap.set(marker, vars);
317 },
318 _triggers = [],
319 _ids = {},
320 _sync = function _sync() {
321 return _request || (_request = _raf(_updateAll));
322 },
323 _onScroll = function _onScroll() {
324 if (!_request) {
325 _request = _raf(_updateAll);
326 _lastScrollTime || _dispatch("scrollStart");
327 _lastScrollTime = _getTime();
328 }
329 },
330 _onResize = function _onResize() {
331 return !_refreshing && _resizeDelay.restart(true);
332 },
333 _listeners = {},
334 _emptyArray = [],
335 _media = [],
336 _creatingMedia,
337 _lastMediaTick,
338 _onMediaChange = function _onMediaChange(e) {
339 var tick = gsap.ticker.frame,
340 matches = [],
341 i = 0,
342 index;
343
344 if (_lastMediaTick !== tick || _startup) {
345 _revertAll();
346
347 for (; i < _media.length; i += 4) {
348 index = _win.matchMedia(_media[i]).matches;
349
350 if (index !== _media[i + 3]) {
351 _media[i + 3] = index;
352 index ? matches.push(i) : _revertAll(1, _media[i]) || _isFunction(_media[i + 2]) && _media[i + 2]();
353 }
354 }
355
356 _revertRecorded();
357
358 for (i = 0; i < matches.length; i++) {
359 index = matches[i];
360 _creatingMedia = _media[index];
361 _media[index + 2] = _media[index + 1](e);
362 }
363
364 _creatingMedia = 0;
365
366 _refreshAll(0, 1);
367
368 _lastMediaTick = tick;
369
370 _dispatch("matchMedia");
371 }
372 },
373 _softRefresh = function _softRefresh() {
374 return _removeListener(ScrollTrigger, "scrollEnd", _softRefresh) || _refreshAll(true);
375 },
376 _dispatch = function _dispatch(type) {
377 return _listeners[type] && _listeners[type].map(function (f) {
378 return f();
379 }) || _emptyArray;
380 },
381 _savedStyles = [],
382 _revertRecorded = function _revertRecorded(media) {
383 for (var i = 0; i < _savedStyles.length; i += 4) {
384 if (!media || _savedStyles[i + 3] === media) {
385 _savedStyles[i].style.cssText = _savedStyles[i + 1];
386 _savedStyles[i + 2].uncache = 1;
387 }
388 }
389 },
390 _revertAll = function _revertAll(kill, media) {
391 var trigger;
392
393 for (_i = 0; _i < _triggers.length; _i++) {
394 trigger = _triggers[_i];
395
396 if (!media || trigger.media === media) {
397 if (kill) {
398 trigger.kill(1);
399 } else {
400 trigger.scroll.rec || (trigger.scroll.rec = trigger.scroll());
401 trigger.revert();
402 }
403 }
404 }
405
406 _revertRecorded(media);
407
408 media || _dispatch("revert");
409 },
410 _refreshAll = function _refreshAll(force, skipRevert) {
411 if (_lastScrollTime && !force) {
412 _addListener(ScrollTrigger, "scrollEnd", _softRefresh);
413
414 return;
415 }
416
417 var refreshInits = _dispatch("refreshInit");
418
419 _sort && ScrollTrigger.sort();
420 skipRevert || _revertAll();
421
422 for (_i = 0; _i < _triggers.length; _i++) {
423 _triggers[_i].refresh();
424 }
425
426 refreshInits.forEach(function (result) {
427 return result && result.render && result.render(-1);
428 });
429 _i = _triggers.length;
430
431 while (_i--) {
432 _triggers[_i].scroll.rec = 0;
433 }
434
435 _resizeDelay.pause();
436
437 _dispatch("refresh");
438 },
439 _lastScroll = 0,
440 _direction = 1,
441 _updateAll = function _updateAll() {
442 var l = _triggers.length,
443 time = _getTime(),
444 recordVelocity = time - _time1 >= 50,
445 scroll = l && _triggers[0].scroll();
446
447 _direction = _lastScroll > scroll ? -1 : 1;
448 _lastScroll = scroll;
449
450 if (recordVelocity) {
451 if (_lastScrollTime && !_pointerIsDown && time - _lastScrollTime > 200) {
452 _lastScrollTime = 0;
453
454 _dispatch("scrollEnd");
455 }
456
457 _time2 = _time1;
458 _time1 = time;
459 }
460
461 if (_direction < 0) {
462 _i = l;
463
464 while (_i--) {
465 _triggers[_i] && _triggers[_i].update(0, recordVelocity);
466 }
467
468 _direction = 1;
469 } else {
470 for (_i = 0; _i < l; _i++) {
471 _triggers[_i] && _triggers[_i].update(0, recordVelocity);
472 }
473 }
474
475 _request = 0;
476 },
477 _propNamesToCopy = [_left, _top, _bottom, _right, _margin + _Bottom, _margin + _Right, _margin + _Top, _margin + _Left, "display", "flexShrink", "float"],
478 _stateProps = _propNamesToCopy.concat([_width, _height, "boxSizing", "max" + _Width, "max" + _Height, "position", _margin, _padding, _padding + _Top, _padding + _Right, _padding + _Bottom, _padding + _Left]),
479 _swapPinOut = function _swapPinOut(pin, spacer, state) {
480 _setState(state);
481
482 if (pin.parentNode === spacer) {
483 var parent = spacer.parentNode;
484
485 if (parent) {
486 parent.insertBefore(pin, spacer);
487 parent.removeChild(spacer);
488 }
489 }
490 },
491 _swapPinIn = function _swapPinIn(pin, spacer, cs, spacerState) {
492 if (pin.parentNode !== spacer) {
493 var i = _propNamesToCopy.length,
494 spacerStyle = spacer.style,
495 pinStyle = pin.style,
496 p;
497
498 while (i--) {
499 p = _propNamesToCopy[i];
500 spacerStyle[p] = cs[p];
501 }
502
503 spacerStyle.position = cs.position === "absolute" ? "absolute" : "relative";
504 cs.display === "inline" && (spacerStyle.display = "inline-block");
505 pinStyle[_bottom] = pinStyle[_right] = "auto";
506 spacerStyle.overflow = "visible";
507 spacerStyle.boxSizing = "border-box";
508 spacerStyle[_width] = _getSize(pin, _horizontal) + _px;
509 spacerStyle[_height] = _getSize(pin, _vertical) + _px;
510 spacerStyle[_padding] = pinStyle[_margin] = pinStyle[_top] = pinStyle[_left] = "0";
511
512 _setState(spacerState);
513
514 pinStyle[_width] = pinStyle["max" + _Width] = cs[_width];
515 pinStyle[_height] = pinStyle["max" + _Height] = cs[_height];
516 pinStyle[_padding] = cs[_padding];
517 pin.parentNode.insertBefore(spacer, pin);
518 spacer.appendChild(pin);
519 }
520 },
521 _capsExp = /([A-Z])/g,
522 _setState = function _setState(state) {
523 if (state) {
524 var style = state.t.style,
525 l = state.length,
526 i = 0,
527 p,
528 value;
529
530 for (; i < l; i += 2) {
531 value = state[i + 1];
532 p = state[i];
533
534 if (value) {
535 style[p] = value;
536 } else if (style[p]) {
537 style.removeProperty(p.replace(_capsExp, "-$1").toLowerCase());
538 }
539 }
540 }
541 },
542 _getState = function _getState(element) {
543 var l = _stateProps.length,
544 style = element.style,
545 state = [],
546 i = 0;
547
548 for (; i < l; i++) {
549 state.push(_stateProps[i], style[_stateProps[i]]);
550 }
551
552 state.t = element;
553 return state;
554 },
555 _copyState = function _copyState(state, override, omitOffsets) {
556 var result = [],
557 l = state.length,
558 i = omitOffsets ? 8 : 0,
559 p;
560
561 for (; i < l; i += 2) {
562 p = state[i];
563 result.push(p, p in override ? override[p] : state[i + 1]);
564 }
565
566 result.t = state.t;
567 return result;
568 },
569 _winOffsets = {
570 left: 0,
571 top: 0
572 },
573 _parsePosition = function _parsePosition(value, trigger, scrollerSize, direction, scroll, marker, markerScroller, self, scrollerBounds, borderWidth, useFixedPosition, scrollerMax) {
574 _isFunction(value) && (value = value(self));
575
576 if (_isString(value) && value.substr(0, 3) === "max") {
577 value = scrollerMax + (value.charAt(4) === "=" ? _offsetToPx("0" + value.substr(3), scrollerSize) : 0);
578 }
579
580 if (!_isNumber(value)) {
581 _isFunction(trigger) && (trigger = trigger(self));
582
583 var element = _toArray(trigger)[0] || _body,
584 bounds = _getBounds(element) || {},
585 offsets = value.split(" "),
586 localOffset,
587 globalOffset,
588 display;
589
590 if ((!bounds || !bounds.left && !bounds.top) && _getComputedStyle(element).display === "none") {
591 display = element.style.display;
592 element.style.display = "block";
593 bounds = _getBounds(element);
594 display ? element.style.display = display : element.style.removeProperty("display");
595 }
596
597 localOffset = _offsetToPx(offsets[0], bounds[direction.d]);
598 globalOffset = _offsetToPx(offsets[1] || "0", scrollerSize);
599 value = bounds[direction.p] - scrollerBounds[direction.p] - borderWidth + localOffset + scroll - globalOffset;
600 markerScroller && _positionMarker(markerScroller, globalOffset, direction, scrollerSize - globalOffset < 20 || markerScroller._isStart && globalOffset > 20);
601 scrollerSize -= scrollerSize - globalOffset;
602 } else if (markerScroller) {
603 _positionMarker(markerScroller, scrollerSize, direction, true);
604 }
605
606 if (marker) {
607 var position = value + scrollerSize,
608 isStart = marker._isStart;
609 scrollerMax = "scroll" + direction.d2;
610
611 _positionMarker(marker, position, direction, isStart && position > 20 || !isStart && (useFixedPosition ? Math.max(_body[scrollerMax], _docEl[scrollerMax]) : marker.parentNode[scrollerMax]) <= position + 1);
612
613 if (useFixedPosition) {
614 scrollerBounds = _getBounds(markerScroller);
615 useFixedPosition && (marker.style[direction.op.p] = scrollerBounds[direction.op.p] - direction.op.m - marker._offset + _px);
616 }
617 }
618
619 return Math.round(value);
620 },
621 _prefixExp = /(?:webkit|moz|length|cssText)/i,
622 _reparent = function _reparent(element, parent, top, left) {
623 if (element.parentNode !== parent) {
624 var style = element.style,
625 p,
626 cs;
627
628 if (parent === _body) {
629 element._stOrig = style.cssText;
630 cs = _getComputedStyle(element);
631
632 for (p in cs) {
633 if (!+p && !_prefixExp.test(p) && cs[p] && typeof style[p] === "string" && p !== "0") {
634 style[p] = cs[p];
635 }
636 }
637
638 style.top = top;
639 style.left = left;
640 } else {
641 style.cssText = element._stOrig;
642 }
643
644 gsap.core.getCache(element).uncache = 1;
645 parent.appendChild(element);
646 }
647 },
648 _getTweenCreator = function _getTweenCreator(scroller, direction) {
649 var getScroll = _getScrollFunc(scroller, direction),
650 prop = "_scroll" + direction.p2,
651 lastScroll1,
652 lastScroll2,
653 getTween = function getTween(scrollTo, vars, initialValue, change1, change2) {
654 var tween = getTween.tween,
655 onComplete = vars.onComplete,
656 modifiers = {};
657 tween && tween.kill();
658 lastScroll1 = Math.round(initialValue);
659 vars[prop] = scrollTo;
660 vars.modifiers = modifiers;
661
662 modifiers[prop] = function (value) {
663 value = Math.round(getScroll());
664
665 if (value !== lastScroll1 && value !== lastScroll2) {
666 tween.kill();
667 getTween.tween = 0;
668 } else {
669 value = initialValue + change1 * tween.ratio + change2 * tween.ratio * tween.ratio;
670 }
671
672 lastScroll2 = lastScroll1;
673 return lastScroll1 = Math.round(value);
674 };
675
676 vars.onComplete = function () {
677 getTween.tween = 0;
678 onComplete && onComplete.call(tween);
679 };
680
681 tween = getTween.tween = gsap.to(scroller, vars);
682 return tween;
683 };
684
685 scroller[prop] = getScroll;
686 return getTween;
687 };
688
689 _horizontal.op = _vertical;
690 var ScrollTrigger = function () {
691 function ScrollTrigger(vars, animation) {
692 _coreInitted || ScrollTrigger.register(gsap) || console.warn("Please gsap.registerPlugin(ScrollTrigger)");
693 this.init(vars, animation);
694 }
695
696 var _proto = ScrollTrigger.prototype;
697
698 _proto.init = function init(vars, animation) {
699 this.progress = 0;
700 this.vars && this.kill(1);
701
702 if (!_enabled) {
703 this.update = this.refresh = this.kill = _passThrough;
704 return;
705 }
706
707 vars = _setDefaults(_isString(vars) || _isNumber(vars) || vars.nodeType ? {
708 trigger: vars
709 } : vars, _defaults);
710
711 var direction = vars.horizontal ? _horizontal : _vertical,
712 _vars = vars,
713 onUpdate = _vars.onUpdate,
714 toggleClass = _vars.toggleClass,
715 id = _vars.id,
716 onToggle = _vars.onToggle,
717 onRefresh = _vars.onRefresh,
718 scrub = _vars.scrub,
719 trigger = _vars.trigger,
720 pin = _vars.pin,
721 pinSpacing = _vars.pinSpacing,
722 invalidateOnRefresh = _vars.invalidateOnRefresh,
723 anticipatePin = _vars.anticipatePin,
724 onScrubComplete = _vars.onScrubComplete,
725 onSnapComplete = _vars.onSnapComplete,
726 once = _vars.once,
727 snap = _vars.snap,
728 pinReparent = _vars.pinReparent,
729 isToggle = !scrub && scrub !== 0,
730 scroller = _toArray(vars.scroller || _win)[0],
731 scrollerCache = gsap.core.getCache(scroller),
732 isViewport = _isViewport(scroller),
733 useFixedPosition = "pinType" in vars ? vars.pinType === "fixed" : isViewport || _getProxyProp(scroller, "pinType") === "fixed",
734 callbacks = [vars.onEnter, vars.onLeave, vars.onEnterBack, vars.onLeaveBack],
735 toggleActions = isToggle && vars.toggleActions.split(" "),
736 markers = "markers" in vars ? vars.markers : _defaults.markers,
737 borderWidth = isViewport ? 0 : parseFloat(_getComputedStyle(scroller)["border" + direction.p2 + _Width]) || 0,
738 self = this,
739 onRefreshInit = vars.onRefreshInit && function () {
740 return vars.onRefreshInit(self);
741 },
742 getScrollerSize = _getSizeFunc(scroller, isViewport, direction),
743 getScrollerOffsets = _getOffsetsFunc(scroller, isViewport),
744 tweenTo,
745 pinCache,
746 snapFunc,
747 isReverted,
748 scroll1,
749 scroll2,
750 start,
751 end,
752 markerStart,
753 markerEnd,
754 markerStartTrigger,
755 markerEndTrigger,
756 markerVars,
757 change,
758 pinOriginalState,
759 pinActiveState,
760 pinState,
761 spacer,
762 offset,
763 pinGetter,
764 pinSetter,
765 pinStart,
766 pinChange,
767 spacingStart,
768 spacerState,
769 markerStartSetter,
770 markerEndSetter,
771 cs,
772 snap1,
773 snap2,
774 scrubTween,
775 scrubSmooth,
776 snapDurClamp,
777 snapDelayedCall,
778 prevProgress,
779 prevScroll,
780 prevAnimProgress;
781
782 self.media = _creatingMedia;
783 anticipatePin *= 45;
784
785 _triggers.push(self);
786
787 self.scroller = scroller;
788 self.scroll = _getScrollFunc(scroller, direction);
789 scroll1 = self.scroll();
790 self.vars = vars;
791 animation = animation || vars.animation;
792 "refreshPriority" in vars && (_sort = 1);
793 scrollerCache.tweenScroll = scrollerCache.tweenScroll || {
794 top: _getTweenCreator(scroller, _vertical),
795 left: _getTweenCreator(scroller, _horizontal)
796 };
797 self.tweenTo = tweenTo = scrollerCache.tweenScroll[direction.p];
798
799 if (animation) {
800 animation.vars.lazy = false;
801 animation._initted || animation.vars.immediateRender !== false && vars.immediateRender !== false && animation.render(0, true, true);
802 self.animation = animation.pause();
803 animation.scrollTrigger = self;
804 scrubSmooth = _isNumber(scrub) && scrub;
805 scrubSmooth && (scrubTween = gsap.to(animation, {
806 ease: "power3",
807 duration: scrubSmooth,
808 onComplete: function onComplete() {
809 return onScrubComplete && onScrubComplete(self);
810 }
811 }));
812 snap1 = 0;
813 id || (id = animation.vars.id);
814 }
815
816 if (snap) {
817 _isObject(snap) || (snap = {
818 snapTo: snap
819 });
820 gsap.set(isViewport ? [_body, _docEl] : scroller, {
821 scrollBehavior: "auto"
822 });
823 snapFunc = _isFunction(snap.snapTo) ? snap.snapTo : snap.snapTo === "labels" ? _getLabels(animation) : gsap.utils.snap(snap.snapTo);
824 snapDurClamp = snap.duration || {
825 min: 0.1,
826 max: 2
827 };
828 snapDurClamp = _isObject(snapDurClamp) ? _clamp(snapDurClamp.min, snapDurClamp.max) : _clamp(snapDurClamp, snapDurClamp);
829 snapDelayedCall = gsap.delayedCall(snap.delay || scrubSmooth / 2 || 0.1, function () {
830 if (Math.abs(self.getVelocity()) < 10 && !_pointerIsDown) {
831 var totalProgress = animation && !isToggle ? animation.totalProgress() : self.progress,
832 velocity = (totalProgress - snap2) / (_getTime() - _time2) * 1000 || 0,
833 change1 = _abs(velocity / 2) * velocity / 0.185,
834 naturalEnd = totalProgress + change1,
835 endValue = _clamp(0, 1, snapFunc(naturalEnd, self)),
836 scroll = self.scroll(),
837 endScroll = Math.round(start + endValue * change),
838 tween = tweenTo.tween;
839
840 if (scroll <= end && scroll >= start && endScroll !== scroll) {
841 if (tween && !tween._initted && tween.data <= Math.abs(endScroll - scroll)) {
842 return;
843 }
844
845 tweenTo(endScroll, {
846 duration: snapDurClamp(_abs(Math.max(_abs(naturalEnd - totalProgress), _abs(endValue - totalProgress)) * 0.185 / velocity / 0.05 || 0)),
847 ease: snap.ease || "power3",
848 data: Math.abs(endScroll - scroll),
849 onComplete: function onComplete() {
850 snap1 = snap2 = animation && !isToggle ? animation.totalProgress() : self.progress;
851 onSnapComplete && onSnapComplete(self);
852 }
853 }, scroll, change1 * change, endScroll - scroll - change1 * change);
854 }
855 } else if (self.isActive) {
856 snapDelayedCall.restart(true);
857 }
858 }).pause();
859 }
860
861 id && (_ids[id] = self);
862 trigger = self.trigger = _toArray(trigger || pin)[0];
863 pin = pin === true ? trigger : _toArray(pin)[0];
864 _isString(toggleClass) && (toggleClass = {
865 targets: trigger,
866 className: toggleClass
867 });
868
869 if (pin) {
870 pinSpacing === false || pinSpacing === _margin || (pinSpacing = !pinSpacing && _getComputedStyle(pin.parentNode).display === "flex" ? false : _padding);
871 self.pin = pin;
872 vars.force3D !== false && gsap.set(pin, {
873 force3D: true
874 });
875 pinCache = gsap.core.getCache(pin);
876
877 if (!pinCache.spacer) {
878 pinCache.spacer = spacer = _doc.createElement("div");
879 spacer.setAttribute("class", "pin-spacer" + (id ? " pin-spacer-" + id : ""));
880 pinCache.pinState = pinOriginalState = _getState(pin);
881 } else {
882 pinOriginalState = pinCache.pinState;
883 }
884
885 self.spacer = spacer = pinCache.spacer;
886 cs = _getComputedStyle(pin);
887 spacingStart = cs[pinSpacing + direction.os2];
888 pinGetter = gsap.getProperty(pin);
889 pinSetter = gsap.quickSetter(pin, direction.a, _px);
890
891 _swapPinIn(pin, spacer, cs);
892
893 pinState = _getState(pin);
894 }
895
896 if (markers) {
897 markerVars = _isObject(markers) ? _setDefaults(markers, _markerDefaults) : _markerDefaults;
898 markerStartTrigger = _createMarker("scroller-start", id, scroller, direction, markerVars, 0);
899 markerEndTrigger = _createMarker("scroller-end", id, scroller, direction, markerVars, 0, markerStartTrigger);
900 offset = markerStartTrigger["offset" + direction.op.d2];
901 markerStart = _createMarker("start", id, scroller, direction, markerVars, offset);
902 markerEnd = _createMarker("end", id, scroller, direction, markerVars, offset);
903
904 if (!useFixedPosition) {
905 _makePositionable(scroller);
906
907 gsap.set([markerStartTrigger, markerEndTrigger], {
908 force3D: true
909 });
910 markerStartSetter = gsap.quickSetter(markerStartTrigger, direction.a, _px);
911 markerEndSetter = gsap.quickSetter(markerEndTrigger, direction.a, _px);
912 }
913 }
914
915 self.revert = function (revert) {
916 var r = revert !== false || !self.enabled,
917 prevRefreshing = _refreshing;
918
919 if (r !== isReverted) {
920 if (r) {
921 prevScroll = Math.max(self.scroll(), self.scroll.rec || 0);
922 prevProgress = self.progress;
923 prevAnimProgress = animation && animation.progress();
924 }
925
926 markerStart && [markerStart, markerEnd, markerStartTrigger, markerEndTrigger].forEach(function (m) {
927 return m.style.display = r ? "none" : "block";
928 });
929 r && (_refreshing = 1);
930 self.update(r);
931 _refreshing = prevRefreshing;
932 pin && (r ? _swapPinOut(pin, spacer, pinOriginalState) : (!pinReparent || !self.isActive) && _swapPinIn(pin, spacer, _getComputedStyle(pin), spacerState));
933 isReverted = r;
934 }
935 };
936
937 self.refresh = function (soft) {
938 if (_refreshing || !self.enabled) {
939 return;
940 }
941
942 if (pin && soft && _lastScrollTime) {
943 _addListener(ScrollTrigger, "scrollEnd", _softRefresh);
944
945 return;
946 }
947
948 _refreshing = 1;
949 scrubTween && scrubTween.kill();
950 invalidateOnRefresh && animation && animation.progress(0).invalidate();
951 isReverted || self.revert();
952
953 var size = getScrollerSize(),
954 scrollerBounds = getScrollerOffsets(),
955 max = _maxScroll(scroller, direction),
956 offset = 0,
957 otherPinOffset = 0,
958 parsedEnd = vars.end,
959 parsedEndTrigger = vars.endTrigger || trigger,
960 parsedStart = vars.start || (vars.start === 0 ? 0 : pin || !trigger ? "0 0" : "0 100%"),
961 triggerIndex = trigger && Math.max(0, _triggers.indexOf(self)) || 0,
962 i = triggerIndex,
963 cs,
964 bounds,
965 scroll,
966 isVertical,
967 override,
968 curTrigger,
969 curPin,
970 oppositeScroll;
971
972 while (i--) {
973 curPin = _triggers[i].pin;
974 curPin && (curPin === trigger || curPin === pin) && _triggers[i].revert();
975 }
976
977 start = _parsePosition(parsedStart, trigger, size, direction, self.scroll(), markerStart, markerStartTrigger, self, scrollerBounds, borderWidth, useFixedPosition, max) || (pin ? -0.001 : 0);
978 _isFunction(parsedEnd) && (parsedEnd = parsedEnd(self));
979
980 if (_isString(parsedEnd) && !parsedEnd.indexOf("+=")) {
981 if (~parsedEnd.indexOf(" ")) {
982 parsedEnd = (_isString(parsedStart) ? parsedStart.split(" ")[0] : "") + parsedEnd;
983 } else {
984 offset = _offsetToPx(parsedEnd.substr(2), size);
985 parsedEnd = _isString(parsedStart) ? parsedStart : start + offset;
986 parsedEndTrigger = trigger;
987 }
988 }
989
990 end = Math.max(start, _parsePosition(parsedEnd || (parsedEndTrigger ? "100% 0" : max), parsedEndTrigger, size, direction, self.scroll() + offset, markerEnd, markerEndTrigger, self, scrollerBounds, borderWidth, useFixedPosition, max)) || -0.001;
991 change = end - start || (start -= 0.01) && 0.001;
992 offset = 0;
993 i = triggerIndex;
994
995 while (i--) {
996 curTrigger = _triggers[i];
997 curPin = curTrigger.pin;
998
999 if (curPin && curTrigger.start - curTrigger._pinPush < start) {
1000 cs = curTrigger.end - curTrigger.start;
1001 curPin === trigger && (offset += cs);
1002 curPin === pin && (otherPinOffset += cs);
1003 }
1004 }
1005
1006 start += offset;
1007 end += offset;
1008 self._pinPush = otherPinOffset;
1009
1010 if (markerStart && offset) {
1011 cs = {};
1012 cs[direction.a] = "+=" + offset;
1013 gsap.set([markerStart, markerEnd], cs);
1014 }
1015
1016 if (pin) {
1017 cs = _getComputedStyle(pin);
1018 isVertical = direction === _vertical;
1019 scroll = self.scroll();
1020 pinStart = parseFloat(pinGetter(direction.a)) + otherPinOffset;
1021 !max && end > 1 && ((isViewport ? _body : scroller).style["overflow-" + direction.a] = "scroll");
1022
1023 _swapPinIn(pin, spacer, cs);
1024
1025 pinState = _getState(pin);
1026 bounds = _getBounds(pin, true);
1027 oppositeScroll = useFixedPosition && _getScrollFunc(scroller, isVertical ? _horizontal : _vertical)();
1028
1029 if (pinSpacing) {
1030 spacerState = [pinSpacing + direction.os2, change + otherPinOffset + _px];
1031 spacerState.t = spacer;
1032 i = pinSpacing === _padding ? _getSize(pin, direction) + change + otherPinOffset : 0;
1033 i && spacerState.push(direction.d, i + _px);
1034
1035 _setState(spacerState);
1036
1037 useFixedPosition && self.scroll(prevScroll);
1038 }
1039
1040 if (useFixedPosition) {
1041 override = {
1042 top: bounds.top + (isVertical ? scroll - start : oppositeScroll) + _px,
1043 left: bounds.left + (isVertical ? oppositeScroll : scroll - start) + _px,
1044 boxSizing: "border-box",
1045 position: "fixed"
1046 };
1047 override[_width] = override["max" + _Width] = Math.ceil(bounds.width) + _px;
1048 override[_height] = override["max" + _Height] = Math.ceil(bounds.height) + _px;
1049 override[_margin] = override[_margin + _Top] = override[_margin + _Right] = override[_margin + _Bottom] = override[_margin + _Left] = "0";
1050 override[_padding] = cs[_padding];
1051 override[_padding + _Top] = cs[_padding + _Top];
1052 override[_padding + _Right] = cs[_padding + _Right];
1053 override[_padding + _Bottom] = cs[_padding + _Bottom];
1054 override[_padding + _Left] = cs[_padding + _Left];
1055 pinActiveState = _copyState(pinOriginalState, override, pinReparent);
1056 }
1057
1058 if (animation) {
1059 animation.progress(1, true);
1060 pinChange = pinGetter(direction.a) - pinStart + change + otherPinOffset;
1061 change !== pinChange && pinActiveState.splice(pinActiveState.length - 2, 2);
1062 animation.progress(0, true);
1063 } else {
1064 pinChange = change;
1065 }
1066 } else if (trigger && self.scroll()) {
1067 bounds = trigger.parentNode;
1068
1069 while (bounds && bounds !== _body) {
1070 if (bounds._pinOffset) {
1071 start -= bounds._pinOffset;
1072 end -= bounds._pinOffset;
1073 }
1074
1075 bounds = bounds.parentNode;
1076 }
1077 }
1078
1079 for (i = 0; i < triggerIndex; i++) {
1080 curTrigger = _triggers[i].pin;
1081 curTrigger && (curTrigger === trigger || curTrigger === pin) && _triggers[i].revert(false);
1082 }
1083
1084 self.start = start;
1085 self.end = end;
1086 scroll1 = scroll2 = self.scroll();
1087 scroll1 < prevScroll && self.scroll(prevScroll);
1088 self.revert(false);
1089 _refreshing = 0;
1090 prevAnimProgress && isToggle && animation.progress(prevAnimProgress, true);
1091
1092 if (prevProgress !== self.progress) {
1093 scrubTween && animation.totalProgress(prevProgress, true);
1094 self.progress = prevProgress;
1095 self.update();
1096 }
1097
1098 pin && pinSpacing && (spacer._pinOffset = Math.round(self.progress * pinChange));
1099 onRefresh && onRefresh(self);
1100 };
1101
1102 self.getVelocity = function () {
1103 return (self.scroll() - scroll2) / (_getTime() - _time2) * 1000 || 0;
1104 };
1105
1106 self.update = function (reset, recordVelocity) {
1107 var scroll = self.scroll(),
1108 p = reset ? 0 : (scroll - start) / change,
1109 clipped = p < 0 ? 0 : p > 1 ? 1 : p || 0,
1110 prevProgress = self.progress,
1111 isActive,
1112 wasActive,
1113 toggleState,
1114 action,
1115 stateChanged,
1116 toggled;
1117
1118 if (recordVelocity) {
1119 scroll2 = scroll1;
1120 scroll1 = scroll;
1121
1122 if (snap) {
1123 snap2 = snap1;
1124 snap1 = animation && !isToggle ? animation.totalProgress() : clipped;
1125 }
1126 }
1127
1128 anticipatePin && !clipped && pin && !_refreshing && !_startup && _lastScrollTime && start < scroll + (scroll - scroll2) / (_getTime() - _time2) * anticipatePin && (clipped = 0.0001);
1129
1130 if (clipped !== prevProgress && self.enabled) {
1131 isActive = self.isActive = !!clipped && clipped < 1;
1132 wasActive = !!prevProgress && prevProgress < 1;
1133 toggled = isActive !== wasActive;
1134 stateChanged = toggled || !!clipped !== !!prevProgress;
1135 self.direction = clipped > prevProgress ? 1 : -1;
1136 self.progress = clipped;
1137
1138 if (!isToggle) {
1139 if (scrubTween && !_refreshing && !_startup) {
1140 scrubTween.vars.totalProgress = clipped;
1141 scrubTween.invalidate().restart();
1142 } else if (animation) {
1143 animation.totalProgress(clipped, !!_refreshing);
1144 }
1145 }
1146
1147 if (pin) {
1148 reset && pinSpacing && (spacer.style[pinSpacing + direction.os2] = spacingStart);
1149
1150 if (!useFixedPosition) {
1151 pinSetter(pinStart + pinChange * clipped);
1152 } else if (stateChanged) {
1153 action = !reset && clipped > prevProgress && end + 1 > scroll && scroll + 1 >= _maxScroll(scroller, direction);
1154
1155 if (pinReparent) {
1156 if (!reset && (isActive || action)) {
1157 var bounds = _getBounds(pin, true),
1158 _offset = scroll - start;
1159
1160 _reparent(pin, _body, bounds.top + (direction === _vertical ? _offset : 0) + _px, bounds.left + (direction === _vertical ? 0 : _offset) + _px);
1161 } else {
1162 _reparent(pin, spacer);
1163 }
1164 }
1165
1166 _setState(isActive || action ? pinActiveState : pinState);
1167
1168 pinChange !== change && clipped < 1 && isActive || pinSetter(pinStart + (clipped === 1 && !action ? pinChange : 0));
1169 }
1170 }
1171
1172 snap && !tweenTo.tween && !_refreshing && !_startup && snapDelayedCall.restart(true);
1173 toggleClass && (toggled || once && clipped && (clipped < 1 || !_limitCallbacks)) && _toArray(toggleClass.targets).forEach(function (el) {
1174 return el.classList[isActive || once ? "add" : "remove"](toggleClass.className);
1175 });
1176 onUpdate && !isToggle && !reset && onUpdate(self);
1177
1178 if (stateChanged && !_refreshing) {
1179 toggleState = clipped && !prevProgress ? 0 : clipped === 1 ? 1 : prevProgress === 1 ? 2 : 3;
1180
1181 if (isToggle) {
1182 action = !toggled && toggleActions[toggleState + 1] !== "none" && toggleActions[toggleState + 1] || toggleActions[toggleState];
1183
1184 if (animation && (action === "complete" || action === "reset" || action in animation)) {
1185 if (action === "complete") {
1186 animation.pause().totalProgress(1);
1187 } else if (action === "reset") {
1188 animation.restart(true).pause();
1189 } else {
1190 animation[action]();
1191 }
1192 }
1193
1194 onUpdate && onUpdate(self);
1195 }
1196
1197 if (toggled || !_limitCallbacks) {
1198 onToggle && toggled && onToggle(self);
1199 callbacks[toggleState] && callbacks[toggleState](self);
1200 once && (clipped === 1 ? self.kill(false, 1) : callbacks[toggleState] = 0);
1201
1202 if (!toggled) {
1203 toggleState = clipped === 1 ? 1 : 3;
1204 callbacks[toggleState] && callbacks[toggleState](self);
1205 }
1206 }
1207 } else if (isToggle && onUpdate && !_refreshing) {
1208 onUpdate(self);
1209 }
1210 }
1211
1212 if (markerEndSetter) {
1213 markerStartSetter(scroll + (markerStartTrigger._isFlipped ? 1 : 0));
1214 markerEndSetter(scroll);
1215 }
1216 };
1217
1218 self.enable = function () {
1219 if (!self.enabled) {
1220 self.enabled = true;
1221
1222 _addListener(scroller, "resize", _onResize);
1223
1224 _addListener(scroller, "scroll", _onScroll);
1225
1226 onRefreshInit && _addListener(ScrollTrigger, "refreshInit", onRefreshInit);
1227 !animation || !animation.add ? self.refresh() : gsap.delayedCall(0.01, function () {
1228 return start || end || self.refresh();
1229 }) && (change = 0.01) && (start = end = 0);
1230 }
1231 };
1232
1233 self.disable = function (reset, allowAnimation) {
1234 if (self.enabled) {
1235 reset !== false && self.revert();
1236 self.enabled = self.isActive = false;
1237 allowAnimation || scrubTween && scrubTween.pause();
1238 prevScroll = 0;
1239 pinCache && (pinCache.uncache = 1);
1240 onRefreshInit && _removeListener(ScrollTrigger, "refreshInit", onRefreshInit);
1241
1242 if (snapDelayedCall) {
1243 snapDelayedCall.pause();
1244 tweenTo.tween && tweenTo.tween.kill() && (tweenTo.tween = 0);
1245 }
1246
1247 if (!isViewport) {
1248 var i = _triggers.length;
1249
1250 while (i--) {
1251 if (_triggers[i].scroller === scroller && _triggers[i] !== self) {
1252 return;
1253 }
1254 }
1255
1256 _removeListener(scroller, "resize", _onResize);
1257
1258 _removeListener(scroller, "scroll", _onScroll);
1259 }
1260 }
1261 };
1262
1263 self.kill = function (revert, allowAnimation) {
1264 self.disable(revert, allowAnimation);
1265 id && delete _ids[id];
1266
1267 var i = _triggers.indexOf(self);
1268
1269 _triggers.splice(i, 1);
1270
1271 i === _i && _direction > 0 && _i--;
1272
1273 if (animation) {
1274 animation.scrollTrigger = null;
1275 revert && animation.render(-1);
1276 allowAnimation || animation.kill();
1277 }
1278
1279 markerStart && [markerStart, markerEnd, markerStartTrigger, markerEndTrigger].forEach(function (m) {
1280 return m.parentNode.removeChild(m);
1281 });
1282 pinCache && (pinCache.uncache = 1);
1283 };
1284
1285 self.enable();
1286 };
1287
1288 ScrollTrigger.register = function register(core) {
1289 if (!_coreInitted) {
1290 gsap = core || _getGSAP();
1291
1292 if (_windowExists() && window.document) {
1293 _win = window;
1294 _doc = document;
1295 _docEl = _doc.documentElement;
1296 _body = _doc.body;
1297 }
1298
1299 if (gsap) {
1300 _toArray = gsap.utils.toArray;
1301 _clamp = gsap.utils.clamp;
1302 gsap.core.globals("ScrollTrigger", ScrollTrigger);
1303
1304 if (_body) {
1305 _raf = _win.requestAnimationFrame || function (f) {
1306 return setTimeout(f, 16);
1307 };
1308
1309 _addListener(_win, "mousewheel", _onScroll);
1310
1311 _root = [_win, _doc, _docEl, _body];
1312
1313 _addListener(_doc, "scroll", _onScroll);
1314
1315 var bodyStyle = _body.style,
1316 border = bodyStyle.borderTop,
1317 bounds;
1318 bodyStyle.borderTop = "1px solid #000";
1319 bounds = _getBounds(_body);
1320 _vertical.m = Math.round(bounds.top + _vertical.sc()) || 0;
1321 _horizontal.m = Math.round(bounds.left + _horizontal.sc()) || 0;
1322 border ? bodyStyle.borderTop = border : bodyStyle.removeProperty("border-top");
1323 _syncInterval = setInterval(_sync, 200);
1324 gsap.delayedCall(0.5, function () {
1325 return _startup = 0;
1326 });
1327
1328 _addListener(_doc, "touchcancel", _passThrough);
1329
1330 _addListener(_body, "touchstart", _passThrough);
1331
1332 _multiListener(_addListener, _doc, "pointerdown,touchstart,mousedown", function () {
1333 return _pointerIsDown = 1;
1334 });
1335
1336 _multiListener(_addListener, _doc, "pointerup,touchend,mouseup", function () {
1337 return _pointerIsDown = 0;
1338 });
1339
1340 _transformProp = gsap.utils.checkPrefix("transform");
1341
1342 _stateProps.push(_transformProp);
1343
1344 _coreInitted = _getTime();
1345 _resizeDelay = gsap.delayedCall(0.2, _refreshAll).pause();
1346 _autoRefresh = [_doc, "visibilitychange", function () {
1347 var w = _win.innerWidth,
1348 h = _win.innerHeight;
1349
1350 if (_doc.hidden) {
1351 _prevWidth = w;
1352 _prevHeight = h;
1353 } else if (_prevWidth !== w || _prevHeight !== h) {
1354 _onResize();
1355 }
1356 }, _doc, "DOMContentLoaded", _refreshAll, _win, "load", function () {
1357 return _lastScrollTime || _refreshAll();
1358 }, _win, "resize", _onResize];
1359
1360 _iterateAutoRefresh(_addListener);
1361 }
1362 }
1363 }
1364
1365 return _coreInitted;
1366 };
1367
1368 ScrollTrigger.defaults = function defaults(config) {
1369 for (var p in config) {
1370 _defaults[p] = config[p];
1371 }
1372 };
1373
1374 ScrollTrigger.kill = function kill() {
1375 _enabled = 0;
1376
1377 _triggers.slice(0).forEach(function (trigger) {
1378 return trigger.kill(1);
1379 });
1380 };
1381
1382 ScrollTrigger.config = function config(vars) {
1383 "limitCallbacks" in vars && (_limitCallbacks = !!vars.limitCallbacks);
1384 var ms = vars.syncInterval;
1385 ms && clearInterval(_syncInterval) || (_syncInterval = ms) && setInterval(_sync, ms);
1386 "autoRefreshEvents" in vars && (_iterateAutoRefresh(_removeListener) || _iterateAutoRefresh(_addListener, vars.autoRefreshEvents || "none"));
1387 };
1388
1389 ScrollTrigger.scrollerProxy = function scrollerProxy(target, vars) {
1390 var t = _toArray(target)[0];
1391
1392 _isViewport(t) ? _proxies.unshift(_win, vars, _body, vars, _docEl, vars) : _proxies.unshift(t, vars);
1393 };
1394
1395 ScrollTrigger.matchMedia = function matchMedia(vars) {
1396 var mq, p, i, func, result;
1397
1398 for (p in vars) {
1399 i = _media.indexOf(p);
1400 func = vars[p];
1401 _creatingMedia = p;
1402
1403 if (p === "all") {
1404 func();
1405 } else {
1406 mq = _win.matchMedia(p);
1407
1408 if (mq) {
1409 mq.matches && (result = func());
1410
1411 if (~i) {
1412 _media[i + 1] = _combineFunc(_media[i + 1], func);
1413 _media[i + 2] = _combineFunc(_media[i + 2], result);
1414 } else {
1415 i = _media.length;
1416
1417 _media.push(p, func, result);
1418
1419 mq.addListener ? mq.addListener(_onMediaChange) : mq.addEventListener("change", _onMediaChange);
1420 }
1421
1422 _media[i + 3] = mq.matches;
1423 }
1424 }
1425
1426 _creatingMedia = 0;
1427 }
1428
1429 return _media;
1430 };
1431
1432 ScrollTrigger.clearMatchMedia = function clearMatchMedia(query) {
1433 query || (_media.length = 0);
1434 query = _media.indexOf(query);
1435 query >= 0 && _media.splice(query, 4);
1436 };
1437
1438 return ScrollTrigger;
1439 }();
1440 ScrollTrigger.version = "3.5.1";
1441
1442 ScrollTrigger.saveStyles = function (targets) {
1443 return targets ? _toArray(targets).forEach(function (target) {
1444 var i = _savedStyles.indexOf(target);
1445
1446 i >= 0 && _savedStyles.splice(i, 4);
1447
1448 _savedStyles.push(target, target.style.cssText, gsap.core.getCache(target), _creatingMedia);
1449 }) : _savedStyles;
1450 };
1451
1452 ScrollTrigger.revert = function (soft, media) {
1453 return _revertAll(!soft, media);
1454 };
1455
1456 ScrollTrigger.create = function (vars, animation) {
1457 return new ScrollTrigger(vars, animation);
1458 };
1459
1460 ScrollTrigger.refresh = function (safe) {
1461 return safe ? _onResize() : _refreshAll(true);
1462 };
1463
1464 ScrollTrigger.update = _updateAll;
1465
1466 ScrollTrigger.maxScroll = function (element, horizontal) {
1467 return _maxScroll(element, horizontal ? _horizontal : _vertical);
1468 };
1469
1470 ScrollTrigger.getScrollFunc = function (element, horizontal) {
1471 return _getScrollFunc(_toArray(element)[0], horizontal ? _horizontal : _vertical);
1472 };
1473
1474 ScrollTrigger.getById = function (id) {
1475 return _ids[id];
1476 };
1477
1478 ScrollTrigger.getAll = function () {
1479 return _triggers.slice(0);
1480 };
1481
1482 ScrollTrigger.isScrolling = function () {
1483 return !!_lastScrollTime;
1484 };
1485
1486 ScrollTrigger.addEventListener = function (type, callback) {
1487 var a = _listeners[type] || (_listeners[type] = []);
1488 ~a.indexOf(callback) || a.push(callback);
1489 };
1490
1491 ScrollTrigger.removeEventListener = function (type, callback) {
1492 var a = _listeners[type],
1493 i = a && a.indexOf(callback);
1494 i >= 0 && a.splice(i, 1);
1495 };
1496
1497 ScrollTrigger.batch = function (targets, vars) {
1498 var result = [],
1499 varsCopy = {},
1500 interval = vars.interval || 0.016,
1501 batchMax = vars.batchMax || 1e9,
1502 proxyCallback = function proxyCallback(type, callback) {
1503 var elements = [],
1504 triggers = [],
1505 delay = gsap.delayedCall(interval, function () {
1506 callback(elements, triggers);
1507 elements = [];
1508 triggers = [];
1509 }).pause();
1510 return function (self) {
1511 elements.length || delay.restart(true);
1512 elements.push(self.trigger);
1513 triggers.push(self);
1514 batchMax <= elements.length && delay.progress(1);
1515 };
1516 },
1517 p;
1518
1519 for (p in vars) {
1520 varsCopy[p] = p.substr(0, 2) === "on" && _isFunction(vars[p]) && p !== "onRefreshInit" ? proxyCallback(p, vars[p]) : vars[p];
1521 }
1522
1523 if (_isFunction(batchMax)) {
1524 batchMax = batchMax();
1525
1526 _addListener(ScrollTrigger, "refresh", function () {
1527 return batchMax = vars.batchMax();
1528 });
1529 }
1530
1531 _toArray(targets).forEach(function (target) {
1532 var config = {};
1533
1534 for (p in varsCopy) {
1535 config[p] = varsCopy[p];
1536 }
1537
1538 config.trigger = target;
1539 result.push(ScrollTrigger.create(config));
1540 });
1541
1542 return result;
1543 };
1544
1545 ScrollTrigger.sort = function (func) {
1546 return _triggers.sort(func || function (a, b) {
1547 return (a.vars.refreshPriority || 0) * -1e6 + a.start - (b.start + (b.vars.refreshPriority || 0) * -1e6);
1548 });
1549 };
1550
1551 _getGSAP() && gsap.registerPlugin(ScrollTrigger);
1552
1553 exports.ScrollTrigger = ScrollTrigger;
1554 exports.default = ScrollTrigger;
1555
1556 Object.defineProperty(exports, '__esModule', { value: true });
1557
1558})));