@any-scroll/core
Advanced tools
+1
-1
@@ -21,3 +21,3 @@ import _wrap, { Options as _Options } from './wrap'; | ||
| */ | ||
| use(plugin: Plugin, options: PluginOptions): void; | ||
| use(plugin: Plugin, options?: PluginOptions): void; | ||
| } |
+2
-2
@@ -47,3 +47,3 @@ import AnyTouch from '@any-touch/core'; | ||
| } | ||
| else if (MutationObserver) { | ||
| if (MutationObserver) { | ||
| this.update(); | ||
@@ -349,3 +349,3 @@ const observer = new MutationObserver(() => { | ||
| } | ||
| use(plugin, options) { | ||
| use(plugin, options = {}) { | ||
| plugin(this, options); | ||
@@ -352,0 +352,0 @@ } |
+1
-1
@@ -1,2 +0,2 @@ | ||
| "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),e=require("@any-touch/core"),n=require("@any-touch/pan"),o=require("@any-touch/swipe"),i=require("any-event"),r=require("raf"),s=require("lodash/clamp"),a=require("lodash/inRange"),l=require("@any-scroll/shared");function u(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var c=u(e),f=u(n),p=u(o),d=u(i),h=u(r),_=u(s),v=u(a),y=window.ResizeObserver,m=window.MutationObserver,x=function(e){function n(t,n){var o=e.call(this)||this;o.xy=[0,0],o.minXY=[0,0],o.maxXY=[0,0],o.wrapSize=[0,0],o.contentSize=[0,0],o.targets=[],o.isScrolling=!1,o.__scrollEndTimeId=-1,o.__dampScrollRafId=-1,o.__stopScroll=function(){},o.el=t,o.wrapRef=n;var i=n.options;if(o.__options=i,n.on("beforeUpdate",(function(){o.update()})),y){var r=new y((function(){o.update()}));r.observe(t),o.on("beforeDestroy",(function(){r.disconnect()}))}else if(m){o.update();var s=new m((function(){o.update()}));s.observe(t,{childList:!0,subtree:!0}),o.on("beforeDestroy",(function(){s.disconnect()}))}return o}return t.__extends(n,e),n.prototype.set=function(e){this.__options=t.__assign(t.__assign({},this.__options),e),this.update()},n.prototype.update=function(){var t=this.el,e=t.offsetWidth,n=t.offsetHeight,o=t.clientWidth,i=t.clientHeight,r=t.scrollWidth,s=t.scrollHeight;this.wrapSize=[this.wrapRef.size[0],this.wrapRef.size[1]],this.contentSize=[e-o+r,n-i+s],this.maxXY=this.__options.maxXY?this.__options.maxXY(this):[Math.max(0,this.contentSize[0]-this.wrapSize[0]),Math.max(0,this.contentSize[1]-this.wrapSize[1])],this.minXY=this.__options.minXY?this.__options.minXY(this):[0,0],this.emit("updated",this)},n.prototype.stop=function(){var t=this;this.isScrolling&&this.xy.every((function(e,n){return v.default(e,t.minXY[n],t.maxXY[n])}))&&this.emit("scrollEnd",this.xy),this.isScrolling=!1,h.default.cancel(this.__dampScrollRafId),this.__stopScroll()},n.prototype.snap=function(){var t=this,e=l.runTwice((function(e){return _.default(t.xy[e],t.minXY[e],t.maxXY[e])}));this.dampScroll(e)},n.prototype.moveTo=function(e){var n=this,o=this.__options,i=o.allow,r=o.overflowDistance;if(!i.includes(!0))return this.xy;clearTimeout(this.__scrollEndTimeId);var s=l.xY2Tuple(e,this.xy),a=l.runTwice((function(t){return i[t]&&void 0!==s[t]?_.default(s[t],n.minXY[t]-r,n.maxXY[t]+r):n.xy[t]}));if(!this.xy.some((function(t,e){return t!==a[e]})))return this.xy;l.runTwice((function(t){return n.xy[t]=a[t]}));var u=t.__read(this.xy,2),c=u[0],f=u[1],p=this.targets,d=p[0];return this.emit("scroll",{targets:p,target:d,x:c,y:f}),this.__options.render(this.el,[-this.xy[0],-this.xy[1]]),this.xy},n.prototype.scrollTo=function(e,n,o){var i=this;void 0===n&&(n=1e3);var r=l.xY2Tuple(e,this.xy),s=this.__options.overflowDistance;this.stop(),this.isScrolling=!0;var a=l.runTwice((function(t){return _.default(r[t],i.minXY[t]-s,i.maxXY[t]+s)})),u=t.__read(l.tween(this.xy,a,n,o),3),c=u[0],f=u[1],p=u[2];c(this.moveTo.bind(this)),this.__stopScroll=f,p((function(){i.snap(),i.isScrolling=!1}))},n.prototype.scrollToElement=function(t,e,n,o){var i=this;if(void 0===e&&(e=[0,0]),void 0===n&&(n=1e3),void 0===o&&(o=l.easing),this.el.contains(t)){var r=l.xY2Tuple(e,[0,0]),s=this.wrapRef.el.getBoundingClientRect(),a=t.getBoundingClientRect(),u=a.x,c=a.y,f=l.runTwice((function(t){return i.xy[t]+[u,c][t]-[s.x,s.y][t]+r[t]}));this.scrollTo(f,n,o)}},n.prototype.dampScroll=function(e,n){var o=this,i=l.xY2Tuple(e,this.xy),r=this.__options,s=r.overflowDistance,a=r.allow;if(!l.runTwice((function(t){return!a[t]||i[t]===o.xy[t]})).every((function(t){return t}))){h.default.cancel(this.__dampScrollRafId);var u=t.__spreadArray([],t.__read(i),!1);!function t(e){e.isScrolling=!0;var o=e.xy,i=e.minXY,r=e.maxXY,c=l.runTwice((function(t){if(!a[t])return o[t];var c=l.damp(e.xy[t],u[t],n);if(c>=r[t]+s)u[t]=r[t];else{if(!(c<=i[t]-s))return c===u[t]&&(o[t]>r[t]?u[t]=r[t]:o[t]<i[t]&&(u[t]=i[t])),c;u[t]=i[t]}return l.damp(e.xy[t],u[t],n)}));e.moveTo(c),l.runTwice((function(t){return a[t]&&u[t]!==c[t]})).some((function(t){return t}))?e.__dampScrollRafId=h.default((function(){t(e)})):(e.isScrolling=!1,e.emit("scroll-end",e.xy))}(this)}},n.prototype.destroy=function(){e.prototype.destroy.call(this)},n}(d.default),w=window.setTimeout,g=window.ResizeObserver,R={overflowDistance:100,damping:.1,allow:[!0,!0],render:l.render},T=function(e){function n(n,o){var i=e.call(this)||this;if(i.size=[0,0],i.targets=[],i.__contentRefList=[],i.el=n,i.options=t.__assign(t.__assign({},R),o),l.setStyle(n,{position:"relative",overflow:"hidden"}),Array.from(n.children).forEach((function(t){if(!t.hasAttribute("no-scroll")){var e=new x(t,i);e.on("scroll",(function(t){i.emit("scroll",t)})),e.on("scrollEnd",(function(t){i.emit("scrollEnd",t)})),e.on("updated",(function(t){i.emit("updated",t)})),i.on("beforeDestroy",(function(){e.destroy()})),i.__contentRefList.push(e)}})),i.__currentContentRef=i.getContentRef(),g){var r=new g(i.update.bind(i));r.observe(n),i.on("beforeDestroy",(function(){r.disconnect()}))}else i.update();var s=new c.default(n);s.use(f.default),s.use(p.default),i.at=s,s.on(["panstart","panmove"],(function(t){var e=i.__currentContentRef;if(null!==e){i.targets=t.targets;var n=t.deltaX,o=t.deltaY,r=e.xy;e.moveTo([r[0]-n,r[1]-o])}})),s.on("panend",(function(t){null!==i.__currentContentRef&&(i.__currentContentRef.__scrollEndTimeId=w((function(){null!==i.__currentContentRef&&(i.targets=t.targets,i.emit("scrollEnd",i.__currentContentRef.xy))}),16))})),s.on("at:start",(function(t){var e;i.emit("at:start");var n=t.target;i.__currentContentRef=i.getContentRef(n),null===(e=i.__currentContentRef)||void 0===e||e.stop()})),s.on("at:end",(function(){var t;i.emit("at:end"),null===(t=i.__currentContentRef)||void 0===t||t.snap()}));var a=s.get("swipe");return a&&(a.velocity=1),s.on("swipe",(function(t){var e=i.__currentContentRef;if(null!==e){i.targets=t.targets;var n=200*t.speedX,o=200*t.speedY;e.dampScroll([e.xy[0]-n,e.xy[1]-o])}})),s.on("at:after",(function(t){i.emit(t.name,t)})),i}return t.__extends(n,e),n.prototype.update=function(){var t=this.el,e=t.clientWidth,n=t.clientHeight;this.size=[e,n],this.emit("beforeUpdate",this.size)},n.prototype.getContentRef=function(e){var n,o,i=this.__contentRefList;if(void 0===e)return this.__currentContentRef||i[i.length-1];if("number"==typeof e)return i[Number(e)]||null;try{for(var r=t.__values(i),s=r.next();!s.done;s=r.next()){var a=s.value;if(a.el.contains(e))return a}}catch(t){n={error:t}}finally{try{s&&!s.done&&(o=r.return)&&o.call(r)}finally{if(n)throw n.error}}return this.__currentContentRef},n.prototype.active=function(t){this.__currentContentRef=t},n.prototype.moveTo=function(t){var e;return null===(e=this.__currentContentRef)||void 0===e?void 0:e.moveTo(t)},n.prototype.scrollTo=function(t,e,n){var o;void 0===e&&(e=1e3),null===(o=this.__currentContentRef)||void 0===o||o.scrollTo(t,e,n)},n.prototype.scrollToElement=function(t,e,n,o){var i;null===(i=this.__currentContentRef)||void 0===i||i.scrollToElement(t,e,n,o)},n.prototype.dampScroll=function(t,e){var n;void 0===e&&(e=this.options.damping),null===(n=this.__currentContentRef)||void 0===n||n.dampScroll(t,e)},n.prototype.stop=function(){var t;null===(t=this.__currentContentRef)||void 0===t||t.stop()},n.prototype.destroy=function(){this.emit("beforeDestroy"),this.at.destroy(),e.prototype.destroy.call(this)},n}(d.default),S=T,C=x,Y=function(e){function n(t,n){return e.call(this,t,n)||this}return t.__extends(n,e),n.prototype.use=function(t,e){t(this,e)},n}(S);exports.Content=C,exports.Wrap=S,exports.default=Y; | ||
| "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),e=require("@any-touch/core"),n=require("@any-touch/pan"),o=require("@any-touch/swipe"),i=require("any-event"),r=require("raf"),s=require("lodash/clamp"),a=require("lodash/inRange"),l=require("@any-scroll/shared");function u(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var c=u(e),f=u(n),d=u(o),p=u(i),h=u(r),_=u(s),v=u(a),y=window.ResizeObserver,m=window.MutationObserver,x=function(e){function n(t,n){var o=e.call(this)||this;o.xy=[0,0],o.minXY=[0,0],o.maxXY=[0,0],o.wrapSize=[0,0],o.contentSize=[0,0],o.targets=[],o.isScrolling=!1,o.__scrollEndTimeId=-1,o.__dampScrollRafId=-1,o.__stopScroll=function(){},o.el=t,o.wrapRef=n;var i=n.options;if(o.__options=i,n.on("beforeUpdate",(function(){o.update()})),y){var r=new y((function(){o.update()}));r.observe(t),o.on("beforeDestroy",(function(){r.disconnect()}))}if(m){o.update();var s=new m((function(){o.update()}));s.observe(t,{childList:!0,subtree:!0}),o.on("beforeDestroy",(function(){s.disconnect()}))}return o}return t.__extends(n,e),n.prototype.set=function(e){this.__options=t.__assign(t.__assign({},this.__options),e),this.update()},n.prototype.update=function(){var t=this.el,e=t.offsetWidth,n=t.offsetHeight,o=t.clientWidth,i=t.clientHeight,r=t.scrollWidth,s=t.scrollHeight;this.wrapSize=[this.wrapRef.size[0],this.wrapRef.size[1]],this.contentSize=[e-o+r,n-i+s],this.maxXY=this.__options.maxXY?this.__options.maxXY(this):[Math.max(0,this.contentSize[0]-this.wrapSize[0]),Math.max(0,this.contentSize[1]-this.wrapSize[1])],this.minXY=this.__options.minXY?this.__options.minXY(this):[0,0],this.emit("updated",this)},n.prototype.stop=function(){var t=this;this.isScrolling&&this.xy.every((function(e,n){return v.default(e,t.minXY[n],t.maxXY[n])}))&&this.emit("scrollEnd",this.xy),this.isScrolling=!1,h.default.cancel(this.__dampScrollRafId),this.__stopScroll()},n.prototype.snap=function(){var t=this,e=l.runTwice((function(e){return _.default(t.xy[e],t.minXY[e],t.maxXY[e])}));this.dampScroll(e)},n.prototype.moveTo=function(e){var n=this,o=this.__options,i=o.allow,r=o.overflowDistance;if(!i.includes(!0))return this.xy;clearTimeout(this.__scrollEndTimeId);var s=l.xY2Tuple(e,this.xy),a=l.runTwice((function(t){return i[t]&&void 0!==s[t]?_.default(s[t],n.minXY[t]-r,n.maxXY[t]+r):n.xy[t]}));if(!this.xy.some((function(t,e){return t!==a[e]})))return this.xy;l.runTwice((function(t){return n.xy[t]=a[t]}));var u=t.__read(this.xy,2),c=u[0],f=u[1],d=this.targets,p=d[0];return this.emit("scroll",{targets:d,target:p,x:c,y:f}),this.__options.render(this.el,[-this.xy[0],-this.xy[1]]),this.xy},n.prototype.scrollTo=function(e,n,o){var i=this;void 0===n&&(n=1e3);var r=l.xY2Tuple(e,this.xy),s=this.__options.overflowDistance;this.stop(),this.isScrolling=!0;var a=l.runTwice((function(t){return _.default(r[t],i.minXY[t]-s,i.maxXY[t]+s)})),u=t.__read(l.tween(this.xy,a,n,o),3),c=u[0],f=u[1],d=u[2];c(this.moveTo.bind(this)),this.__stopScroll=f,d((function(){i.snap(),i.isScrolling=!1}))},n.prototype.scrollToElement=function(t,e,n,o){var i=this;if(void 0===e&&(e=[0,0]),void 0===n&&(n=1e3),void 0===o&&(o=l.easing),this.el.contains(t)){var r=l.xY2Tuple(e,[0,0]),s=this.wrapRef.el.getBoundingClientRect(),a=t.getBoundingClientRect(),u=a.x,c=a.y,f=l.runTwice((function(t){return i.xy[t]+[u,c][t]-[s.x,s.y][t]+r[t]}));this.scrollTo(f,n,o)}},n.prototype.dampScroll=function(e,n){var o=this,i=l.xY2Tuple(e,this.xy),r=this.__options,s=r.overflowDistance,a=r.allow;if(!l.runTwice((function(t){return!a[t]||i[t]===o.xy[t]})).every((function(t){return t}))){h.default.cancel(this.__dampScrollRafId);var u=t.__spreadArray([],t.__read(i),!1);!function t(e){e.isScrolling=!0;var o=e.xy,i=e.minXY,r=e.maxXY,c=l.runTwice((function(t){if(!a[t])return o[t];var c=l.damp(e.xy[t],u[t],n);if(c>=r[t]+s)u[t]=r[t];else{if(!(c<=i[t]-s))return c===u[t]&&(o[t]>r[t]?u[t]=r[t]:o[t]<i[t]&&(u[t]=i[t])),c;u[t]=i[t]}return l.damp(e.xy[t],u[t],n)}));e.moveTo(c),l.runTwice((function(t){return a[t]&&u[t]!==c[t]})).some((function(t){return t}))?e.__dampScrollRafId=h.default((function(){t(e)})):(e.isScrolling=!1,e.emit("scroll-end",e.xy))}(this)}},n.prototype.destroy=function(){e.prototype.destroy.call(this)},n}(p.default),w=window.setTimeout,g=window.ResizeObserver,R={overflowDistance:100,damping:.1,allow:[!0,!0],render:l.render},T=function(e){function n(n,o){var i=e.call(this)||this;if(i.size=[0,0],i.targets=[],i.__contentRefList=[],i.el=n,i.options=t.__assign(t.__assign({},R),o),l.setStyle(n,{position:"relative",overflow:"hidden"}),Array.from(n.children).forEach((function(t){if(!t.hasAttribute("no-scroll")){var e=new x(t,i);e.on("scroll",(function(t){i.emit("scroll",t)})),e.on("scrollEnd",(function(t){i.emit("scrollEnd",t)})),e.on("updated",(function(t){i.emit("updated",t)})),i.on("beforeDestroy",(function(){e.destroy()})),i.__contentRefList.push(e)}})),i.__currentContentRef=i.getContentRef(),g){var r=new g(i.update.bind(i));r.observe(n),i.on("beforeDestroy",(function(){r.disconnect()}))}else i.update();var s=new c.default(n);s.use(f.default),s.use(d.default),i.at=s,s.on(["panstart","panmove"],(function(t){var e=i.__currentContentRef;if(null!==e){i.targets=t.targets;var n=t.deltaX,o=t.deltaY,r=e.xy;e.moveTo([r[0]-n,r[1]-o])}})),s.on("panend",(function(t){null!==i.__currentContentRef&&(i.__currentContentRef.__scrollEndTimeId=w((function(){null!==i.__currentContentRef&&(i.targets=t.targets,i.emit("scrollEnd",i.__currentContentRef.xy))}),16))})),s.on("at:start",(function(t){var e;i.emit("at:start");var n=t.target;i.__currentContentRef=i.getContentRef(n),null===(e=i.__currentContentRef)||void 0===e||e.stop()})),s.on("at:end",(function(){var t;i.emit("at:end"),null===(t=i.__currentContentRef)||void 0===t||t.snap()}));var a=s.get("swipe");return a&&(a.velocity=1),s.on("swipe",(function(t){var e=i.__currentContentRef;if(null!==e){i.targets=t.targets;var n=200*t.speedX,o=200*t.speedY;e.dampScroll([e.xy[0]-n,e.xy[1]-o])}})),s.on("at:after",(function(t){i.emit(t.name,t)})),i}return t.__extends(n,e),n.prototype.update=function(){var t=this.el,e=t.clientWidth,n=t.clientHeight;this.size=[e,n],this.emit("beforeUpdate",this.size)},n.prototype.getContentRef=function(e){var n,o,i=this.__contentRefList;if(void 0===e)return this.__currentContentRef||i[i.length-1];if("number"==typeof e)return i[Number(e)]||null;try{for(var r=t.__values(i),s=r.next();!s.done;s=r.next()){var a=s.value;if(a.el.contains(e))return a}}catch(t){n={error:t}}finally{try{s&&!s.done&&(o=r.return)&&o.call(r)}finally{if(n)throw n.error}}return this.__currentContentRef},n.prototype.active=function(t){this.__currentContentRef=t},n.prototype.moveTo=function(t){var e;return null===(e=this.__currentContentRef)||void 0===e?void 0:e.moveTo(t)},n.prototype.scrollTo=function(t,e,n){var o;void 0===e&&(e=1e3),null===(o=this.__currentContentRef)||void 0===o||o.scrollTo(t,e,n)},n.prototype.scrollToElement=function(t,e,n,o){var i;null===(i=this.__currentContentRef)||void 0===i||i.scrollToElement(t,e,n,o)},n.prototype.dampScroll=function(t,e){var n;void 0===e&&(e=this.options.damping),null===(n=this.__currentContentRef)||void 0===n||n.dampScroll(t,e)},n.prototype.stop=function(){var t;null===(t=this.__currentContentRef)||void 0===t||t.stop()},n.prototype.destroy=function(){this.emit("beforeDestroy"),this.at.destroy(),e.prototype.destroy.call(this)},n}(p.default),S=T,C=x,Y=function(e){function n(t,n){return e.call(this,t,n)||this}return t.__extends(n,e),n.prototype.use=function(t,e){void 0===e&&(e={}),t(this,e)},n}(S);exports.Content=C,exports.Wrap=S,exports.default=Y; | ||
| //# sourceMappingURL=index.js.map |
+2
-2
| { | ||
| "name": "@any-scroll/core", | ||
| "version": "0.6.2", | ||
| "version": "0.6.3", | ||
| "description": "虚拟滚动", | ||
@@ -49,3 +49,3 @@ "unpkg": "dist/any-scroll.js", | ||
| "sideEffects": false, | ||
| "gitHead": "b972397294cbe4e1edb694c63bac4a74f5e3aaf3" | ||
| "gitHead": "c33efe097c6060100d367fdc9f9c4a76db622d3e" | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
52120
0.05%