Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@better-scroll/nested-scroll

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@better-scroll/nested-scroll - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1

22

dist/nested-scroll.esm.js

@@ -297,2 +297,21 @@ /*!

};
var isResettingPosition = function (scroll) {
var hasHorizontalScroll = scroll.hasHorizontalScroll, hasVerticalScroll = scroll.hasVerticalScroll, x = scroll.x, y = scroll.y, minScrollX = scroll.minScrollX, maxScrollX = scroll.maxScrollX, minScrollY = scroll.minScrollY, maxScrollY = scroll.maxScrollY;
var ret = false;
var outOfLeftBoundary = x > minScrollX;
var outOfRightBoundary = x < maxScrollX;
var outOfTopBoundary = y > minScrollY;
var outOfBottomBoundary = y < maxScrollY;
if (hasVerticalScroll) {
ret = outOfTopBoundary || outOfBottomBoundary;
}
else if (hasHorizontalScroll) {
ret = outOfLeftBoundary || outOfRightBoundary;
}
return ret;
};
var resetPositionHandler = function (scroll) {
scroll.scroller.reflow();
scroll.resetPosition(0 /* Immediately */);
};
var calculateDistance = function (childNode, parentNode) {

@@ -428,2 +447,5 @@ var distance = 0;

forceScrollStopHandler(__spreadArrays(ancestorScrolls, descendantScrolls));
if (isResettingPosition(currentScroll)) {
resetPositionHandler(currentScroll);
}
syncTouchstartData(ancestorScrolls);

@@ -430,0 +452,0 @@ disableScrollHander(ancestorScrolls);

@@ -303,2 +303,21 @@ /*!

};
var isResettingPosition = function (scroll) {
var hasHorizontalScroll = scroll.hasHorizontalScroll, hasVerticalScroll = scroll.hasVerticalScroll, x = scroll.x, y = scroll.y, minScrollX = scroll.minScrollX, maxScrollX = scroll.maxScrollX, minScrollY = scroll.minScrollY, maxScrollY = scroll.maxScrollY;
var ret = false;
var outOfLeftBoundary = x > minScrollX;
var outOfRightBoundary = x < maxScrollX;
var outOfTopBoundary = y > minScrollY;
var outOfBottomBoundary = y < maxScrollY;
if (hasVerticalScroll) {
ret = outOfTopBoundary || outOfBottomBoundary;
}
else if (hasHorizontalScroll) {
ret = outOfLeftBoundary || outOfRightBoundary;
}
return ret;
};
var resetPositionHandler = function (scroll) {
scroll.scroller.reflow();
scroll.resetPosition(0 /* Immediately */);
};
var calculateDistance = function (childNode, parentNode) {

@@ -434,2 +453,5 @@ var distance = 0;

forceScrollStopHandler(__spreadArrays(ancestorScrolls, descendantScrolls));
if (isResettingPosition(currentScroll)) {
resetPositionHandler(currentScroll);
}
syncTouchstartData(ancestorScrolls);

@@ -436,0 +458,0 @@ disableScrollHander(ancestorScrolls);

2

dist/nested-scroll.min.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).NestedScroll={})}(this,function(t){"use strict";function r(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;for(var r=Array(t),o=0,e=0;e<n;e++)for(var s=arguments[e],i=0,a=s.length;i<a;i++,o++)r[o]=s[i];return r}var o="undefined"!=typeof window,n=o&&navigator.userAgent.toLowerCase();n&&/wechatdevtools/.test(n),n&&n.indexOf("android"),function(){if("string"!=typeof n)return;var t=/os (\d\d?_\d(_\d)?)/.exec(n);if(!t)return;var e=t[1].split("_").map(function(t){return parseInt(t,10)});13===e[0]&&e[1]}();function l(t,o){if(t.findIndex)return t.findIndex(o);var s=-1;return t.some(function(t,e,n){var r=o(t,e,n);if(r)return s=e,r}),s}var s=o&&document.createElement("div").style,e=function(){if(!o)return!1;for(var t=0,e=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];t<e.length;t++){var n=e[t];if(void 0!==s[n.value])return n.key}return!1}();function i(t){return!1===e?t:"standard"===e?"transitionEnd"===t?"transitionend":t:e+t.charAt(0).toUpperCase()+t.substr(1)}e&&"standard"!==e&&e.toLowerCase();var a=i("transform"),c=i("transition"),u=(o&&i("perspective")in s,i("transitionTimingFunction"),i("transitionDuration"),i("transitionDelay"),i("transformOrigin"),i("transitionEnd"),i("transitionProperty"),f.create=function(t){return new f(t)},f.prototype.hasAncestors=function(e){return-1<l(this.ancestors,function(t){return t[0]===e})},f.prototype.hasDescendants=function(e){return-1<l(this.descendants,function(t){return t[0]===e})},f.prototype.addAncestor=function(t,e){var n=this.ancestors;n.push([t,e]),n.sort(function(t,e){return t[1]-e[1]})},f.prototype.addDescendant=function(t,e){var n=this.descendants;n.push([t,e]),n.sort(function(t,e){return t[1]-e[1]})},f.prototype.removeAncestor=function(e){var t=this.ancestors;if(t.length){var n=l(this.ancestors,function(t){return t[0]===e});if(-1<n)return t.splice(n,1)}},f.prototype.removeDescendant=function(e){var t=this.descendants;if(t.length){var n=l(this.descendants,function(t){return t[0]===e});if(-1<n)return t.splice(n,1)}},f.prototype.registerHooks=function(t,e,n){t.on(e,n),this.hooksManager.push([t,e,n])},f.prototype.setAnalyzed=function(t){void 0===t&&(t=!1),this.analyzed=t},f.prototype.purge=function(){var e=this;this.ancestors.forEach(function(t){t[0].removeDescendant(e)}),this.descendants.forEach(function(t){t[0].removeAncestor(e)}),this.hooksManager.forEach(function(t){var e=t[0],n=t[1],r=t[2];e.off(n,r)}),this.hooksManager=[]},f);function f(t){this.ancestors=[],this.descendants=[],this.hooksManager=[],this.analyzed=!1,this.selfScroll=t}function m(t){t.forEach(function(t){t.enable()})}function k(t){t.forEach(function(t){t.disable()})}var d=[{key:"purgeNestedScroll",name:"purgeNestedScroll"}].map(function(t){return{key:t.key,sourceKey:"plugins.nestedScroll."+t.name}}),p="INTERNAL_NESTED_SCROLL",h=(v.getAllNestedScrolls=function(){var e=v.instancesMap;return Object.keys(e).map(function(t){return e[t]})},v.purgeAllNestedScrolls=function(){v.getAllNestedScrolls().forEach(function(t){return t.purgeNestedScroll()})},v.prototype.handleOptions=function(t){var e=!0===t.options.nestedScroll?{}:t.options.nestedScroll,n={groupId:p};this.options=function(t,e){for(var n in e)t[n]=e[n];return t}(n,e);var r=typeof this.options.groupId;return"string"!=r&&"number"!=r&&console.error("[BScroll warn]: groupId must be string or number for NestedScroll plugin"),this.options.groupId},v.prototype.init=function(t){t.proxy(d),this.addBScroll(t),this.buildBScrollGraph(),this.analyzeBScrollGraph(),this.ensureEventInvokeSequence(),this.handleHooks(t)},v.prototype.handleHooks=function(t){var e=this;this.registerHooks(t.hooks,t.hooks.eventTypes.destroy,function(){e.deleteScroll(t)})},v.prototype.deleteScroll=function(e){e.wrapper.isBScrollContainer=void 0;var t=this.store,n=this.hooksFn,r=l(t,function(t){return t.selfScroll===e});-1<r&&(t[r].purge(),t.splice(r,1));var o,s,i,a,c=l(n,function(t){return t[0]===e.hooks});-1<c&&(s=(o=n[c])[0],i=o[1],a=o[2],s.off(i,a),n.splice(c,1))},v.prototype.addBScroll=function(t){this.store.push(u.create(t))},v.prototype.buildBScrollGraph=function(){for(var t,e,n,r=this.store,o=this.store.length,s=0;s<o;s++){n=(t=r[s]).selfScroll.wrapper;for(var i=0;i<o;i++){var a,c=(e=r[i]).selfScroll.wrapper;t!==e&&n.contains(c)&&(a=function(t,e){for(var n=0,r=t.parentNode;r&&r!==e;)n++,r=r.parentNode;return n}(c,n),t.hasDescendants(e)||t.addDescendant(e,a),e.hasAncestors(t)||e.addAncestor(t,a))}}},v.prototype.analyzeBScrollGraph=function(){this.store.forEach(function(t){var g,n,S,e;t.analyzed||(g=t.ancestors,n=t.descendants,S=t.selfScroll,t.registerHooks(S,S.eventTypes.beforeScrollStart,function(){var t=g.map(function(t){return t[0].selfScroll}),e=n.map(function(t){return t[0].selfScroll});r(t,e).forEach(function(t){t.pending&&(t.stop(),t.resetPosition())}),t.forEach(function(t){var e=t.scroller,n=e.actions,r=e.scrollBehaviorX,o=e.scrollBehaviorY;n.fingerMoved=!0,n.contentMoved=!1,n.directionLockAction.reset(),r.start(),o.start(),r.resetStartPos(),o.resetStartPos(),n.startTime=+new Date}),k(t)}),t.registerHooks(S,S.eventTypes.touchEnd,function(){var t=g.map(function(t){return t[0].selfScroll}),e=n.map(function(t){return t[0].selfScroll});m(r(t,e))}),e=S.scroller.actions.hooks,t.registerHooks(e,e.eventTypes.detectMovingDirection,function(){var t,e,n,r,o,s,i,a,c,l,u,f,d=g.map(function(t){return t[0].selfScroll}),p=d[0],h=d.slice(1),v=S.scroller.actions.contentMoved,y=0===d.length;if(v)k(d);else if(!y&&(e=(t=S).hasHorizontalScroll,n=t.hasVerticalScroll,r=t.x,o=t.y,s=t.minScrollX,i=t.maxScrollX,a=t.minScrollY,c=t.maxScrollY,l=t.movingDirectionX,u=t.movingDirectionY,f=!1,n?f=a<=o&&-1===u||o<=c&&1===u:e&&(f=s<=r&&-1===l||r<=i&&1===l),f))return k([S]),p&&m([p]),k(h),!0}),t.setAnalyzed(!0))})},v.prototype.ensureEventInvokeSequence=function(){this.store.slice().sort(function(t,e){return t.descendants.length-e.descendants.length}).forEach(function(t){t.selfScroll.scroller.actionsHandler.rebindDOMEvents()})},v.prototype.registerHooks=function(t,e,n){t.on(e,n,this),this.hooksFn.push([t,e,n])},v.prototype.purgeNestedScroll=function(){var t=this.options.groupId;this.store.forEach(function(t){t.purge()}),this.store=[],this.hooksFn.forEach(function(t){var e=t[0],n=t[1],r=t[2];e.off(n,r)}),this.hooksFn=[],delete v.instancesMap[t]},v.pluginName="nestedScroll",v.instancesMap={},v);function v(t){var e=this.handleOptions(t),n=v.instancesMap[e];return n||((n=v.instancesMap[e]=this).store=[],n.hooksFn=[]),n.init(t),n}t.DEFAUL_GROUP_ID=p,t.default=h,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).NestedScroll={})}(this,function(t){"use strict";function h(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;for(var r=Array(t),o=0,e=0;e<n;e++)for(var s=arguments[e],i=0,a=s.length;i<a;i++,o++)r[o]=s[i];return r}var r="undefined"!=typeof window,n=r&&navigator.userAgent.toLowerCase();n&&/wechatdevtools/.test(n),n&&n.indexOf("android"),function(){if("string"!=typeof n)return;var t=/os (\d\d?_\d(_\d)?)/.exec(n);if(!t)return;var e=t[1].split("_").map(function(t){return parseInt(t,10)});13===e[0]&&e[1]}();function l(t,o){if(t.findIndex)return t.findIndex(o);var s=-1;return t.some(function(t,e,n){var r=o(t,e,n);if(r)return s=e,r}),s}var o=r&&document.createElement("div").style,e=function(){if(!r)return!1;for(var t=0,e=[{key:"standard",value:"transform"},{key:"webkit",value:"webkitTransform"},{key:"Moz",value:"MozTransform"},{key:"O",value:"OTransform"},{key:"ms",value:"msTransform"}];t<e.length;t++){var n=e[t];if(void 0!==o[n.value])return n.key}return!1}();function s(t){return!1===e?t:"standard"===e?"transitionEnd"===t?"transitionend":t:e+t.charAt(0).toUpperCase()+t.substr(1)}e&&"standard"!==e&&e.toLowerCase();var i=s("transform"),a=s("transition"),c=(r&&s("perspective")in o,s("transitionTimingFunction"),s("transitionDuration"),s("transitionDelay"),s("transformOrigin"),s("transitionEnd"),s("transitionProperty"),u.create=function(t){return new u(t)},u.prototype.hasAncestors=function(e){return-1<l(this.ancestors,function(t){return t[0]===e})},u.prototype.hasDescendants=function(e){return-1<l(this.descendants,function(t){return t[0]===e})},u.prototype.addAncestor=function(t,e){var n=this.ancestors;n.push([t,e]),n.sort(function(t,e){return t[1]-e[1]})},u.prototype.addDescendant=function(t,e){var n=this.descendants;n.push([t,e]),n.sort(function(t,e){return t[1]-e[1]})},u.prototype.removeAncestor=function(e){var t=this.ancestors;if(t.length){var n=l(this.ancestors,function(t){return t[0]===e});if(-1<n)return t.splice(n,1)}},u.prototype.removeDescendant=function(e){var t=this.descendants;if(t.length){var n=l(this.descendants,function(t){return t[0]===e});if(-1<n)return t.splice(n,1)}},u.prototype.registerHooks=function(t,e,n){t.on(e,n),this.hooksManager.push([t,e,n])},u.prototype.setAnalyzed=function(t){void 0===t&&(t=!1),this.analyzed=t},u.prototype.purge=function(){var e=this;this.ancestors.forEach(function(t){t[0].removeDescendant(e)}),this.descendants.forEach(function(t){t[0].removeAncestor(e)}),this.hooksManager.forEach(function(t){var e=t[0],n=t[1],r=t[2];e.off(n,r)}),this.hooksManager=[]},u);function u(t){this.ancestors=[],this.descendants=[],this.hooksManager=[],this.analyzed=!1,this.selfScroll=t}function m(t){t.forEach(function(t){t.enable()})}function k(t){t.forEach(function(t){t.disable()})}var f=[{key:"purgeNestedScroll",name:"purgeNestedScroll"}].map(function(t){return{key:t.key,sourceKey:"plugins.nestedScroll."+t.name}}),d="INTERNAL_NESTED_SCROLL",p=(v.getAllNestedScrolls=function(){var e=v.instancesMap;return Object.keys(e).map(function(t){return e[t]})},v.purgeAllNestedScrolls=function(){v.getAllNestedScrolls().forEach(function(t){return t.purgeNestedScroll()})},v.prototype.handleOptions=function(t){var e=!0===t.options.nestedScroll?{}:t.options.nestedScroll,n={groupId:d};this.options=function(t,e){for(var n in e)t[n]=e[n];return t}(n,e);var r=typeof this.options.groupId;return"string"!=r&&"number"!=r&&console.error("[BScroll warn]: groupId must be string or number for NestedScroll plugin"),this.options.groupId},v.prototype.init=function(t){t.proxy(f),this.addBScroll(t),this.buildBScrollGraph(),this.analyzeBScrollGraph(),this.ensureEventInvokeSequence(),this.handleHooks(t)},v.prototype.handleHooks=function(t){var e=this;this.registerHooks(t.hooks,t.hooks.eventTypes.destroy,function(){e.deleteScroll(t)})},v.prototype.deleteScroll=function(e){e.wrapper.isBScrollContainer=void 0;var t=this.store,n=this.hooksFn,r=l(t,function(t){return t.selfScroll===e});-1<r&&(t[r].purge(),t.splice(r,1));var o,s,i,a,c=l(n,function(t){return t[0]===e.hooks});-1<c&&(s=(o=n[c])[0],i=o[1],a=o[2],s.off(i,a),n.splice(c,1))},v.prototype.addBScroll=function(t){this.store.push(c.create(t))},v.prototype.buildBScrollGraph=function(){for(var t,e,n,r=this.store,o=this.store.length,s=0;s<o;s++){n=(t=r[s]).selfScroll.wrapper;for(var i=0;i<o;i++){var a,c=(e=r[i]).selfScroll.wrapper;t!==e&&n.contains(c)&&(a=function(t,e){for(var n=0,r=t.parentNode;r&&r!==e;)n++,r=r.parentNode;return n}(c,n),t.hasDescendants(e)||t.addDescendant(e,a),e.hasAncestors(t)||e.addAncestor(t,a))}}},v.prototype.analyzeBScrollGraph=function(){this.store.forEach(function(t){var S,p,g,e;t.analyzed||(S=t.ancestors,p=t.descendants,g=t.selfScroll,t.registerHooks(g,g.eventTypes.beforeScrollStart,function(){var t,e,n,r,o,s,i,a,c,l,u,f=S.map(function(t){return t[0].selfScroll}),d=p.map(function(t){return t[0].selfScroll});h(f,d).forEach(function(t){t.pending&&(t.stop(),t.resetPosition())}),n=(e=g).hasHorizontalScroll,r=e.hasVerticalScroll,o=e.x,s=e.y,i=e.minScrollX,a=e.maxScrollX,c=e.minScrollY,l=e.maxScrollY,u=!1,r?u=c<s||s<l:n&&(u=i<o||o<a),u&&((t=g).scroller.reflow(),t.resetPosition(0)),f.forEach(function(t){var e=t.scroller,n=e.actions,r=e.scrollBehaviorX,o=e.scrollBehaviorY;n.fingerMoved=!0,n.contentMoved=!1,n.directionLockAction.reset(),r.start(),o.start(),r.resetStartPos(),o.resetStartPos(),n.startTime=+new Date}),k(f)}),t.registerHooks(g,g.eventTypes.touchEnd,function(){var t=S.map(function(t){return t[0].selfScroll}),e=p.map(function(t){return t[0].selfScroll});m(h(t,e))}),e=g.scroller.actions.hooks,t.registerHooks(e,e.eventTypes.detectMovingDirection,function(){var t,e,n,r,o,s,i,a,c,l,u,f,d=S.map(function(t){return t[0].selfScroll}),p=d[0],h=d.slice(1),v=g.scroller.actions.contentMoved,y=0===d.length;if(v)k(d);else if(!y&&(e=(t=g).hasHorizontalScroll,n=t.hasVerticalScroll,r=t.x,o=t.y,s=t.minScrollX,i=t.maxScrollX,a=t.minScrollY,c=t.maxScrollY,l=t.movingDirectionX,u=t.movingDirectionY,f=!1,n?f=a<=o&&-1===u||o<=c&&1===u:e&&(f=s<=r&&-1===l||r<=i&&1===l),f))return k([g]),p&&m([p]),k(h),!0}),t.setAnalyzed(!0))})},v.prototype.ensureEventInvokeSequence=function(){this.store.slice().sort(function(t,e){return t.descendants.length-e.descendants.length}).forEach(function(t){t.selfScroll.scroller.actionsHandler.rebindDOMEvents()})},v.prototype.registerHooks=function(t,e,n){t.on(e,n,this),this.hooksFn.push([t,e,n])},v.prototype.purgeNestedScroll=function(){var t=this.options.groupId;this.store.forEach(function(t){t.purge()}),this.store=[],this.hooksFn.forEach(function(t){var e=t[0],n=t[1],r=t[2];e.off(n,r)}),this.hooksFn=[],delete v.instancesMap[t]},v.pluginName="nestedScroll",v.instancesMap={},v);function v(t){var e=this.handleOptions(t),n=v.instancesMap[e];return n||((n=v.instancesMap[e]=this).store=[],n.hooksFn=[]),n.init(t),n}t.DEFAUL_GROUP_ID=d,t.default=p,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "@better-scroll/nested-scroll",
"version": "2.1.0",
"version": "2.1.1",
"description": "make your nested scrolls reconciliation",

@@ -34,5 +34,5 @@ "author": {

"dependencies": {
"@better-scroll/core": "^2.1.0"
"@better-scroll/core": "^2.1.1"
},
"gitHead": "29312b14a1762be5656419c9d7e9b498ec8cb34d"
"gitHead": "b84059e9326b45f78a88d770f09a998ee5e7812e"
}

@@ -5,3 +5,2 @@ import BScroll from '@better-scroll/core'

import NestedScroll, { DEFAUL_GROUP_ID } from '../index'
import BScrollFamily from '../BScrollFamily'

@@ -290,2 +289,32 @@ const addProperties = <T extends Object, K extends Object>(

it('should force self resetting potisition', () => {
const parentScroll = new BScroll(parentWrapper, {
nestedScroll: {
groupId: 'force-stop',
},
})
const childScroll = new BScroll(childWrapper, {
nestedScroll: {
groupId: 'force-stop',
},
})
addProperties(parentScroll, {
hasVerticalScroll: false,
hasHorizontalScroll: true,
})
addProperties(childScroll, {
hasVerticalScroll: false,
hasHorizontalScroll: true,
x: 1,
})
new NestedScroll(parentScroll)
new NestedScroll(childScroll)
childScroll.trigger(childScroll.eventTypes.beforeScrollStart)
expect(childScroll.scroller.reflow).toBeCalled()
expect(childScroll.resetPosition).toBeCalled()
})
it('detectMovingDirection hook', () => {

@@ -292,0 +321,0 @@ const parentScroll = new BScroll(parentWrapper, {

@@ -114,2 +114,34 @@ import BScroll, { MountedBScrollHTMLElement } from '@better-scroll/core'

const isResettingPosition = (scroll: BScroll): boolean => {
const {
hasHorizontalScroll,
hasVerticalScroll,
x,
y,
minScrollX,
maxScrollX,
minScrollY,
maxScrollY,
} = scroll
let ret = false
const outOfLeftBoundary = x > minScrollX
const outOfRightBoundary = x < maxScrollX
const outOfTopBoundary = y > minScrollY
const outOfBottomBoundary = y < maxScrollY
if (hasVerticalScroll) {
ret = outOfTopBoundary || outOfBottomBoundary
} else if (hasHorizontalScroll) {
ret = outOfLeftBoundary || outOfRightBoundary
}
return ret
}
const resetPositionHandler = (scroll: BScroll) => {
scroll.scroller.reflow()
scroll.resetPosition(0 /* Immediately */)
}
const calculateDistance = (

@@ -273,2 +305,6 @@ childNode: HTMLElement,

forceScrollStopHandler([...ancestorScrolls, ...descendantScrolls])
if (isResettingPosition(currentScroll)) {
resetPositionHandler(currentScroll)
}
syncTouchstartData(ancestorScrolls)

@@ -275,0 +311,0 @@ disableScrollHander(ancestorScrolls)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc