You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
7.6 KiB

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).SharedUtils={})}(this,function(e){"use strict";function n(e){console.error("[BScroll warn]: "+e)}var u=function(){return(u=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};var r="undefined"!=typeof window,i=r&&navigator.userAgent.toLowerCase(),t=!(!i||!/wechatdevtools/.test(i)),o=i&&0<i.indexOf("android"),s=function(){if("string"!=typeof i)return!1;var e=/os (\d\d?_\d(_\d)?)/.exec(i);if(!e)return!1;var t=e[1].split("_").map(function(e){return parseInt(e,10)});return!!(13<=t[0]&&4<=t[1])}();var c=function(e,t){for(var n in t)e[n]=t[n];return e};var a=r&&document.createElement("div").style,f=function(){if(!r)return!1;for(var e=0,t=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];e<t.length;e++){var n=t[e];if(void 0!==a[n.value])return n.key}return!1}();function p(e){return!1===f?e:"standard"===f?"transitionEnd"===e?"transitionend":e:f+e.charAt(0).toUpperCase()+e.substr(1)}function v(e,t,n,r){e.addEventListener(t,n,{passive:!1,capture:!!r})}function h(e,t,n,r){e.removeEventListener(t,n,{capture:!!r})}var l=f&&"standard"!==f?"-"+f.toLowerCase()+"-":"",d=p("transform"),m=p("transition"),y=r&&p("perspective")in a,g=r&&("ontouchstart"in window||t),w=r&&m in a,E={transform:d,transition:m,transitionTimingFunction:p("transitionTimingFunction"),transitionDuration:p("transitionDuration"),transitionDelay:p("transitionDelay"),transformOrigin:p("transformOrigin"),transitionEnd:p("transitionEnd"),transitionProperty:p("transitionProperty")};function b(e,t){for(var n in t)if(t[n].test(e[n]))return!0;return!1}var T=b;function O(e,t){var n;void 0===t&&(t="click"),"mouseup"===e.type?n=e:"touchend"!==e.type&&"touchcancel"!==e.type||(n=e.changedTouches[0]);var r,i={};n&&(i.screenX=n.screenX||0,i.screenY=n.screenY||0,i.clientX=n.clientX||0,i.clientY=n.clientY||0);var o=!0,s=!0,a={ctrlKey:e.ctrlKey,shiftKey:e.shiftKey,altKey:e.altKey,metaKey:e.metaKey};if("undefined"!=typeof MouseEvent)try{r=new MouseEvent(t,c(u({bubbles:o,cancelable:s},a),i))}catch(e){f()}else f();function f(){(r=document.createEvent("Event")).initEvent(t,o,s),c(r,i)}r.forwardedTouchEvent=!0,r._constructed=!0,e.target.dispatchEvent(r)}function k(e,t){t.parentNode.insertBefore(e,t)}function C(e,t){return new RegExp("(^|\\s)"+t+"(\\s|$)").test(e.className)}var D=r&&window;function A(){}function F(e){}var M=r?D.requestAnimationFrame||D.webkitRequestAnimationFrame||D.mozRequestAnimationFrame||D.oRequestAnimationFrame||function(e){return window.setTimeout(e,(e.interval||1e3/60)/2)}:A,x=r?D.cancelAnimationFrame||D.webkitCancelAnimationFrame||D.mozCancelAnimationFrame||D.oCancelAnimationFrame||function(e){window.clearTimeout(e)}:A,B={enumerable:!0,configurable:!0,get:F,set:F};var R=(j.prototype.on=function(e,t,n){return void 0===n&&(n=this),this.hasType(e),this.events[e]||(this.events[e]=[]),this.events[e].push([t,n]),this},j.prototype.once=function(n,r,i){var o=this;void 0===i&&(i=this),this.hasType(n);var s=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o.off(n,s),r.apply(i,e)};return s.fn=r,this.on(n,s),this},j.prototype.off=function(e,t){if(!e&&!t)return this.events={},this;if(e){if(this.hasType(e),!t)return this.events[e]=[],this;var n=this.events[e];if(!n)return this;for(var r=n.length;r--;)(n[r][0]===t||n[r][0]&&n[r][0].fn===t)&&n.splice(r,1);return this}},j.prototype.trigger=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];this.hasType(e);var r=this.events[e];if(r)for(var i,o=r.length,s=function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),i=0,t=0;t<n;t++)for(var o=arguments[t],s=0,a=o.length;s<a;s++,i++)r[i]=o[s];return r}(r),a=0;a<o;a++){var f=s[a],u=f[0],c=f[1];if(u&&!0===(i=u.apply(c,t)))return i}},j.prototype.registerType=function(e){var t=this;e.forEach(function(e){t.eventTypes[e]=e})},j.prototype.destroy=function(){this.events={},this.eventTypes={}},j.prototype.hasType=function(e){var t=this.eventTypes;t[e]===e||n('EventEmitter has used unknown event type: "'+e+'", should be oneof ['+Object.keys(t).map(function(e){return JSON.stringify(e)})+"]")},j);function j(e){this.events={},this.eventTypes={},this.registerType(e)}var K=(N.prototype.destroy=function(){this.removeDOMEvents(),this.events=[]},N.prototype.addDOMEvents=function(){this.handleDOMEvents(v)},N.prototype.removeDOMEvents=function(){this.handleDOMEvents(h)},N.prototype.handleDOMEvents=function(t){var n=this,r=this.wrapper;this.events.forEach(function(e){t(r,e.name,n,!!e.capture)})},N.prototype.handleEvent=function(t){var n=t.type;this.events.some(function(e){return e.name===n&&(e.handler(t),!0)})},N);function N(e,t){this.wrapper=e,this.events=t,this.addDOMEvents()}e.EventEmitter=R,e.EventRegister=K,e.addClass=function(e,t){var n;C(e,t)||((n=e.className.split(" ")).push(t),e.className=n.join(" "))},e.addEvent=v,e.assert=function(e,t){if(!e)throw new Error("[BScroll] "+t)},e.before=k,e.between=function(e,t,n){return e<t?t:n<e?n:e},e.cancelAnimationFrame=x,e.click=O,e.cssVendor=l,e.dblclick=function(e){O(e,"dblclick")},e.ease={swipe:{style:"cubic-bezier(0.23, 1, 0.32, 1)",fn:function(e){return 1+--e*e*e*e*e}},swipeBounce:{style:"cubic-bezier(0.25, 0.46, 0.45, 0.94)",fn:function(e){return e*(2-e)}},bounce:{style:"cubic-bezier(0.165, 0.84, 0.44, 1)",fn:function(e){return 1- --e*e*e*e}}},e.eventTypeMap={touchstart:1,touchmove:1,touchend:1,mousedown:2,mousemove:2,mouseup:2},e.extend=c,e.getDistance=function(e,t){return Math.sqrt(e*e+t*t)},e.getElement=function(e){return"string"==typeof e?document.querySelector(e):e},e.getNow=function(){return window.performance&&window.performance.now&&window.performance.timing?window.performance.now()+window.performance.timing.navigationStart:+new Date},e.getRect=function(e){if(e instanceof window.SVGElement){var t=e.getBoundingClientRect();return{top:t.top,left:t.left,width:t.width,height:t.height}}return{top:e.offsetTop,left:e.offsetLeft,width:e.offsetWidth,height:e.offsetHeight}},e.hasClass=C,e.hasPerspective=y,e.hasTouch=g,e.hasTransition=w,e.inBrowser=r,e.isAndroid=o,e.isIOSBadVersion=s,e.isUndef=function(e){return null==e},e.isWeChatDevTools=t,e.offset=function(e){for(var t=0,n=0;e;)t-=e.offsetLeft,n-=e.offsetTop,e=e.offsetParent;return{left:t,top:n}},e.offsetToBody=function(e){var t=e.getBoundingClientRect();return{left:-(t.left+window.pageXOffset),top:-(t.top+window.pageYOffset)}},e.prepend=function(e,t){var n=t.firstChild;n?k(e,n):t.appendChild(e)},e.preventDefaultExceptionFn=b,e.propertiesProxy=function(e,t,n){B.get=function(){return function(e,t){for(var n=t.split("."),r=0;r<n.length-1;r++)if("object"!=typeof(e=e[n[r]])||!e)return;var i=n.pop();return"function"==typeof e[i]?function(){return e[i].apply(e,arguments)}:e[i]}(this,t)},B.set=function(e){!function(e,t,n){for(var r,i=t.split("."),o=0;o<i.length-1;o++)e[r=i[o]]||(e[r]={}),e=e[r];e[i.pop()]=n}(this,t,e)},Object.defineProperty(e,n,B)},e.removeChild=function(e,t){e.removeChild(t)},e.removeClass=function(e,t){var n;C(e,t)&&(n=new RegExp("(^|\\s)"+t+"(\\s|$)","g"),e.className=e.className.replace(n," "))},e.removeEvent=h,e.requestAnimationFrame=M,e.style=E,e.tagExceptionFn=T,e.tap=function(e,t){var n=document.createEvent("Event");n.initEvent(t,!0,!0),n.pageX=e.pageX,n.pageY=e.pageY,e.target.dispatchEvent(n)},e.ua=i,e.warn=n,Object.defineProperty(e,"__esModule",{value:!0})});