@nrk/core-scroll
Advanced tools
Comparing version 4.2.0 to 4.2.1
@@ -1,2 +0,2 @@ | ||
/*! @nrk/core-scroll v4.2.0 - Copyright (c) 2017-2021 NRK */ | ||
/*! @nrk/core-scroll v4.2.1 - Copyright (c) 2017-2021 NRK */ | ||
'use strict'; | ||
@@ -152,2 +152,4 @@ | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
@@ -415,7 +417,8 @@ | ||
} else { | ||
// We floor all values to handle potential decimal leftovers if browser is zoomed in or out | ||
var scroll = { | ||
left: this.scrollLeft, | ||
up: this.scrollTop, | ||
right: this.scrollRight, | ||
down: this.scrollBottom | ||
up: Math.floor(this.scrollTop), | ||
right: Math.floor(this.scrollRight), | ||
down: Math.floor(this.scrollBottom), | ||
left: Math.floor(this.scrollLeft) | ||
}; | ||
@@ -468,12 +471,14 @@ var cursor = scroll.left || scroll.right || scroll.up || scroll.down ? 'grab' : ''; | ||
this.setAttribute('items', val || ''); | ||
} | ||
} // ScrollLeft can return decimals when browser is zoomed, leading to unwanted negative values | ||
}, { | ||
key: "scrollRight", | ||
get: function get() { | ||
return this.scrollWidth - this.clientWidth - this.scrollLeft; | ||
} | ||
return Math.max(0, this.scrollWidth - this.clientWidth - this.scrollLeft); | ||
} // Safeguard for negative due to decimals for scrollTop similar to scrollLeft above | ||
}, { | ||
key: "scrollBottom", | ||
get: function get() { | ||
return this.scrollHeight - this.clientHeight - this.scrollTop; | ||
return Math.max(0, this.scrollHeight - this.clientHeight - this.scrollTop); | ||
} // Avoid friction 1 (infinite) | ||
@@ -480,0 +485,0 @@ |
@@ -64,5 +64,10 @@ import { IS_BROWSER, addStyle, closest, dispatchEvent, throttle, getUUID, queryAll } from '../utils' | ||
} else { | ||
const scroll = { left: this.scrollLeft, up: this.scrollTop, right: this.scrollRight, down: this.scrollBottom } | ||
// We floor all values to handle potential decimal leftovers if browser is zoomed in or out | ||
const scroll = { | ||
up: Math.floor(this.scrollTop), | ||
right: Math.floor(this.scrollRight), | ||
down: Math.floor(this.scrollBottom), | ||
left: Math.floor(this.scrollLeft) | ||
} | ||
const cursor = (scroll.left || scroll.right || scroll.up || scroll.down) ? 'grab' : '' | ||
queryAll(this.id && `[for="${this.id}"],[data-for="${this.id}"]`).forEach((el) => (el.disabled = !scroll[el.value])) | ||
@@ -100,5 +105,7 @@ dispatchEvent(this, 'scroll.change') | ||
get scrollRight () { return this.scrollWidth - this.clientWidth - this.scrollLeft } | ||
// ScrollLeft can return decimals when browser is zoomed, leading to unwanted negative values | ||
get scrollRight () { return Math.max(0, this.scrollWidth - this.clientWidth - this.scrollLeft) } | ||
get scrollBottom () { return this.scrollHeight - this.clientHeight - this.scrollTop } | ||
// Safeguard for negative due to decimals for scrollTop similar to scrollLeft above | ||
get scrollBottom () { return Math.max(0, this.scrollHeight - this.clientHeight - this.scrollTop) } | ||
@@ -105,0 +112,0 @@ // Avoid friction 1 (infinite) |
@@ -1,2 +0,2 @@ | ||
/*! @nrk/core-scroll v4.2.0 - Copyright (c) 2017-2021 NRK */ | ||
/*! @nrk/core-scroll v4.2.1 - Copyright (c) 2017-2021 NRK */ | ||
(function (global, factory) { | ||
@@ -6,3 +6,3 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.CoreScroll = factory(global.React)); | ||
}(this, (function (React) { 'use strict'; | ||
})(this, (function (React) { 'use strict'; | ||
@@ -161,2 +161,4 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
@@ -424,7 +426,8 @@ | ||
} else { | ||
// We floor all values to handle potential decimal leftovers if browser is zoomed in or out | ||
var scroll = { | ||
left: this.scrollLeft, | ||
up: this.scrollTop, | ||
right: this.scrollRight, | ||
down: this.scrollBottom | ||
up: Math.floor(this.scrollTop), | ||
right: Math.floor(this.scrollRight), | ||
down: Math.floor(this.scrollBottom), | ||
left: Math.floor(this.scrollLeft) | ||
}; | ||
@@ -477,12 +480,14 @@ var cursor = scroll.left || scroll.right || scroll.up || scroll.down ? 'grab' : ''; | ||
this.setAttribute('items', val || ''); | ||
} | ||
} // ScrollLeft can return decimals when browser is zoomed, leading to unwanted negative values | ||
}, { | ||
key: "scrollRight", | ||
get: function get() { | ||
return this.scrollWidth - this.clientWidth - this.scrollLeft; | ||
} | ||
return Math.max(0, this.scrollWidth - this.clientWidth - this.scrollLeft); | ||
} // Safeguard for negative due to decimals for scrollTop similar to scrollLeft above | ||
}, { | ||
key: "scrollBottom", | ||
get: function get() { | ||
return this.scrollHeight - this.clientHeight - this.scrollTop; | ||
return Math.max(0, this.scrollHeight - this.clientHeight - this.scrollTop); | ||
} // Avoid friction 1 (infinite) | ||
@@ -586,3 +591,3 @@ | ||
var version = "4.2.0"; | ||
var version = "4.2.1"; | ||
@@ -642,3 +647,3 @@ /** | ||
var tagName = (dashCase + "-" + (options.suffix || 'react')).replace(/\W+/g, '-').toLowerCase(); | ||
return function (superclass) { | ||
return /*@__PURE__*/function (superclass) { | ||
function anonymous(props) { | ||
@@ -714,3 +719,3 @@ var this$1$1 = this; | ||
return React__default['default'].createElement(tagName, Object.keys(this.props).reduce(function (thisProps, propName) { | ||
return React__default["default"].createElement(tagName, Object.keys(this.props).reduce(function (thisProps, propName) { | ||
if (skipProps.indexOf(propName) === -1) { | ||
@@ -737,3 +742,3 @@ // Do not render customEvents and custom props as attributes | ||
return anonymous; | ||
}(React__default['default'].Component); | ||
}(React__default["default"].Component); | ||
} | ||
@@ -748,3 +753,3 @@ | ||
}))); | ||
})); | ||
//# sourceMappingURL=core-scroll.jsx.js.map |
@@ -1,3 +0,3 @@ | ||
/*! @nrk/core-scroll v4.2.0 - Copyright (c) 2017-2021 NRK */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).coreScroll=e()}(this,(function(){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function s(t,e,n){return(s=r()?Reflect.construct:function(t,e,n){var o=[null];o.push.apply(o,e);var r=new(Function.bind.apply(t,o));return n&&i(r,n.prototype),r}).apply(null,arguments)}function c(t){var e="function"==typeof Map?new Map:void 0;return(c=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return s(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,t)})(t)}function l(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}var a="undefined"!=typeof window;a&&/(android)/i.test(navigator.userAgent),a&&/iPad|iPhone|iPod/.test(String(navigator.platform)),a||global.HTMLElement||(global.HTMLElement=function(){return function t(){e(this,t)}}());var u,f,d=(u="undefined"==typeof window?{}:window.Element.prototype,f=u.matches||u.msMatchesSelector||u.webkitMatchesSelector,u.closest?function(t,e){return t.closest(e)}:function(t,e){for(t.correspondingUseElement&&(t=t.correspondingUseElement);t;t=t.parentElement)if(f.call(t,e))return t;return null});function h(t,e){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i="prevent_recursive_dispatch_maximum_callstack".concat(e);if(t[i])return!0;t[i]=!0,"function"==typeof window.CustomEvent?n=new window.CustomEvent(e,{bubbles:!0,cancelable:!0,detail:o}):(n=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,o);var r=t.dispatchEvent(n);return t[i]=null,r}function p(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(t){if(t.nodeType)return[t];if("string"==typeof t)return[].slice.call(e.querySelectorAll(t));if(t.length)return[].slice.call(t)}return[]}var m={},v={up:{y:-1,prop:"top"},down:{y:1,prop:"bottom"},left:{x:-1},right:{x:1}},y=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{window.addEventListener("test",null,{get passive(){t={passive:!0}}})}catch(t){}return t}(),g=a&&window.matchMedia&&window.matchMedia("(prefers-reduced-motion)").matches,b=a&&(window.requestAnimationFrame||window.setTimeout);function w(t){d(t.target,'[contenteditable="true"],input,select,textarea')||0===t.button&&(t.preventDefault(),m.pageX=t.pageX,m.pageY=t.pageY,m.diffSumX=0,m.diffSumY=0,m.animate=m.diffX=m.diffY=0,m.scrollX=this.scrollLeft,m.scrollY=this.scrollTop,m.target=this,document.body.style.cursor=this.style.cursor="-webkit-grabbing",document.body.style.cursor=this.style.cursor="grabbing",document.addEventListener("mousemove",E),document.addEventListener("mouseup",L))}function E(t){m.diffX=m.pageX-(m.pageX=t.pageX),m.diffY=m.pageY-(m.pageY=t.pageY),m.diffSumX+=m.diffX,m.diffSumY+=m.diffY,m.target.scrollLeft=m.scrollX+=m.diffX,m.target.scrollTop=m.scrollY+=m.diffY,Math.max(Math.abs(m.diffSumX),Math.abs(m.diffSumY))>10&&(m.target.style.pointerEvents="none")}function L(t){var e=Math.abs(m.diffX||m.diffY)>10?20:0;document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",L),document.body.style.cursor="",e&&m.target.scroll({x:m.scrollX+m.diffX*e,y:m.scrollY+m.diffY*e}),m.target.style.pointerEvents="",m.target.style.cursor="-webkit-grab",m.target.style.cursor="grab",m.target=null}return function(s){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&i(t,e)}(x,s);var c,a,u,f,E,L=(c=x,a=r(),function(){var t,e=o(c);if(a){var n=o(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return l(this,t)});function x(){return e(this,x),L.apply(this,arguments)}return u=x,(f=[{key:"connectedCallback",value:function(){var t,e,n,o,i=this;t=this.nodeName,e="\n ".concat(this.nodeName,"{display:block}\n ").concat(this.nodeName,"::-webkit-scrollbar{display:none}\n "),n="style-".concat(t.toLowerCase()),o=e.replace(/\/\*[^!][^*]*\*\//g,"").replace(/\s*(^|[:;,{}]|$)\s*/g,"$1"),document.getElementById(n)||document.head.insertAdjacentHTML("afterbegin",'<style id="'.concat(n,'">').concat(o,"</style>")),this.style.overflow="scroll",this.style.webkitOverflowScrolling="touch";var r,s,c,l=this.offsetWidth-this.clientWidth,a=this.offsetHeight-this.clientHeight;this.style.marginRight="-".concat(l,"px"),this.style.marginBottom="-".concat(a,"px"),this.style.maxHeight="calc(100% + ".concat(a,"px)"),this._throttledEvent=(r=this.handleEvent.bind(this),s=500,function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];c||(c=setTimeout((function(){r.apply(this,e),c=null}),s))}),this.addEventListener("mousedown",this),this.addEventListener("wheel",this,y),this.addEventListener("scroll",this._throttledEvent,y),window.addEventListener("resize",this._throttledEvent,y),window.addEventListener("load",this),document.addEventListener("click",this),setTimeout((function(){return i.handleEvent()}))}},{key:"disconnectedCallback",value:function(){this._throttledEvent=null,this.removeEventListener("mousedown",this),this.removeEventListener("wheel",this,y),this.removeEventListener("scroll",this._throttledEvent,y),window.removeEventListener("resize",this._throttledEvent,y),window.removeEventListener("load",this),document.removeEventListener("click",this)}},{key:"handleEvent",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.parentNode&&!t.defaultPrevented)if("wheel"===t.type)m.animate=!1;else if("mousedown"===t.type)w.call(this,t);else if("click"===t.type){var e=this.id&&d(t.target,'[for="'.concat(this.id,'"],[data-for="').concat(this.id,'"]'));e&&h(this,"scroll.click",{move:e.value})&&this.scroll(e.value)}else{var n={left:this.scrollLeft,up:this.scrollTop,right:this.scrollRight,down:this.scrollBottom},o=n.left||n.right||n.up||n.down?"grab":"";p(this.id&&'[for="'.concat(this.id,'"],[data-for="').concat(this.id,'"]')).forEach((function(t){return t.disabled=!n[t.value]})),h(this,"scroll.change"),t.type||(this.style.cursor="-webkit-".concat(o),this.style.cursor=o)}}},{key:"scroll",value:function(e){var n=this,o=function(e,n){var o="object"===t(n)?n:{move:n};if("number"!=typeof o.x&&(o.x=e.scrollLeft),"number"!=typeof o.y&&(o.y=e.scrollTop),o.move=v[o.move]){var i=o.move.x?"x":"y",r=o.move.x?"left":"top",s=e.getBoundingClientRect(),c=s[r]-e[o.move.x?"scrollLeft":"scrollTop"],l=s[r]+s[o.move.x?"width":"height"]*o.move[i];e.items.every((function(t){var e=t.getBoundingClientRect(),s=t.ownerDocument.defaultView.getComputedStyle(t)["margin-".concat(r)];return o[i]=e[r]-parseInt(s,10)-c,e[o.move.prop||n]<l}))}return{x:Math.max(0,Math.min(o.x,e.scrollWidth-e.clientWidth)),y:Math.max(0,Math.min(o.y,e.scrollHeight-e.clientHeight))}}(this,e),i=o.x,r=o.y,s=m.animate=Date.now().toString(36)+Math.random().toString(36).slice(2,5),c=this.friction,l=g?1:i-this.scrollLeft,a=g?1:r-this.scrollTop;!function t(){m.animate===s&&(Math.round(l)||Math.round(a))&&(n.scrollLeft=i-Math.round(l*=c),n.scrollTop=r-Math.round(a*=c),b(t))}()}},{key:"items",get:function(){return p(this.getAttribute("items")||this.children,this)},set:function(t){this.setAttribute("items",t||"")}},{key:"scrollRight",get:function(){return this.scrollWidth-this.clientWidth-this.scrollLeft}},{key:"scrollBottom",get:function(){return this.scrollHeight-this.clientHeight-this.scrollTop}},{key:"friction",get:function(){return Math.min(.99,this.getAttribute("friction"))||.8},set:function(t){this.setAttribute("friction",t)}}])&&n(u.prototype,f),E&&n(u,E),x}(c(HTMLElement))})),window.customElements.define("core-scroll",coreScroll); | ||
/*! @nrk/core-scroll v4.2.1 - Copyright (c) 2017-2021 NRK */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).coreScroll=e()}(this,(function(){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function r(t,e){return(r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function l(t,e,n){return(l=i()?Reflect.construct:function(t,e,n){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return n&&r(i,n.prototype),i}).apply(null,arguments)}function c(t){var e="function"==typeof Map?new Map:void 0;return(c=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return l(t,arguments,o(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),r(i,t)})(t)}function s(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}var a="undefined"!=typeof window;a&&/(android)/i.test(navigator.userAgent),a&&/iPad|iPhone|iPod/.test(String(navigator.platform)),a||global.HTMLElement||(global.HTMLElement=function(){return function t(){e(this,t)}}());var u,f,d=(u="undefined"==typeof window?{}:window.Element.prototype,f=u.matches||u.msMatchesSelector||u.webkitMatchesSelector,u.closest?function(t,e){return t.closest(e)}:function(t,e){for(t.correspondingUseElement&&(t=t.correspondingUseElement);t;t=t.parentElement)if(f.call(t,e))return t;return null});function h(t,e){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r="prevent_recursive_dispatch_maximum_callstack".concat(e);if(t[r])return!0;t[r]=!0,"function"==typeof window.CustomEvent?n=new window.CustomEvent(e,{bubbles:!0,cancelable:!0,detail:o}):(n=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,o);var i=t.dispatchEvent(n);return t[r]=null,i}function p(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;if(t){if(t.nodeType)return[t];if("string"==typeof t)return[].slice.call(e.querySelectorAll(t));if(t.length)return[].slice.call(t)}return[]}var m={},v={up:{y:-1,prop:"top"},down:{y:1,prop:"bottom"},left:{x:-1},right:{x:1}},y=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{window.addEventListener("test",null,{get passive(){t={passive:!0}}})}catch(t){}return t}(),g=a&&window.matchMedia&&window.matchMedia("(prefers-reduced-motion)").matches,b=a&&(window.requestAnimationFrame||window.setTimeout);function w(t){d(t.target,'[contenteditable="true"],input,select,textarea')||0===t.button&&(t.preventDefault(),m.pageX=t.pageX,m.pageY=t.pageY,m.diffSumX=0,m.diffSumY=0,m.animate=m.diffX=m.diffY=0,m.scrollX=this.scrollLeft,m.scrollY=this.scrollTop,m.target=this,document.body.style.cursor=this.style.cursor="-webkit-grabbing",document.body.style.cursor=this.style.cursor="grabbing",document.addEventListener("mousemove",E),document.addEventListener("mouseup",x))}function E(t){m.diffX=m.pageX-(m.pageX=t.pageX),m.diffY=m.pageY-(m.pageY=t.pageY),m.diffSumX+=m.diffX,m.diffSumY+=m.diffY,m.target.scrollLeft=m.scrollX+=m.diffX,m.target.scrollTop=m.scrollY+=m.diffY,Math.max(Math.abs(m.diffSumX),Math.abs(m.diffSumY))>10&&(m.target.style.pointerEvents="none")}function x(t){var e=Math.abs(m.diffX||m.diffY)>10?20:0;document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",x),document.body.style.cursor="",e&&m.target.scroll({x:m.scrollX+m.diffX*e,y:m.scrollY+m.diffY*e}),m.target.style.pointerEvents="",m.target.style.cursor="-webkit-grab",m.target.style.cursor="grab",m.target=null}return function(l){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&r(t,e)}(L,l);var c,a,u,f,E,x=(c=L,a=i(),function(){var t,e=o(c);if(a){var n=o(this).constructor;t=Reflect.construct(e,arguments,n)}else t=e.apply(this,arguments);return s(this,t)});function L(){return e(this,L),x.apply(this,arguments)}return u=L,(f=[{key:"connectedCallback",value:function(){var t,e,n,o,r=this;t=this.nodeName,e="\n ".concat(this.nodeName,"{display:block}\n ").concat(this.nodeName,"::-webkit-scrollbar{display:none}\n "),n="style-".concat(t.toLowerCase()),o=e.replace(/\/\*[^!][^*]*\*\//g,"").replace(/\s*(^|[:;,{}]|$)\s*/g,"$1"),document.getElementById(n)||document.head.insertAdjacentHTML("afterbegin",'<style id="'.concat(n,'">').concat(o,"</style>")),this.style.overflow="scroll",this.style.webkitOverflowScrolling="touch";var i,l,c,s=this.offsetWidth-this.clientWidth,a=this.offsetHeight-this.clientHeight;this.style.marginRight="-".concat(s,"px"),this.style.marginBottom="-".concat(a,"px"),this.style.maxHeight="calc(100% + ".concat(a,"px)"),this._throttledEvent=(i=this.handleEvent.bind(this),l=500,function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];c||(c=setTimeout((function(){i.apply(this,e),c=null}),l))}),this.addEventListener("mousedown",this),this.addEventListener("wheel",this,y),this.addEventListener("scroll",this._throttledEvent,y),window.addEventListener("resize",this._throttledEvent,y),window.addEventListener("load",this),document.addEventListener("click",this),setTimeout((function(){return r.handleEvent()}))}},{key:"disconnectedCallback",value:function(){this._throttledEvent=null,this.removeEventListener("mousedown",this),this.removeEventListener("wheel",this,y),this.removeEventListener("scroll",this._throttledEvent,y),window.removeEventListener("resize",this._throttledEvent,y),window.removeEventListener("load",this),document.removeEventListener("click",this)}},{key:"handleEvent",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(this.parentNode&&!t.defaultPrevented)if("wheel"===t.type)m.animate=!1;else if("mousedown"===t.type)w.call(this,t);else if("click"===t.type){var e=this.id&&d(t.target,'[for="'.concat(this.id,'"],[data-for="').concat(this.id,'"]'));e&&h(this,"scroll.click",{move:e.value})&&this.scroll(e.value)}else{var n={up:Math.floor(this.scrollTop),right:Math.floor(this.scrollRight),down:Math.floor(this.scrollBottom),left:Math.floor(this.scrollLeft)},o=n.left||n.right||n.up||n.down?"grab":"";p(this.id&&'[for="'.concat(this.id,'"],[data-for="').concat(this.id,'"]')).forEach((function(t){return t.disabled=!n[t.value]})),h(this,"scroll.change"),t.type||(this.style.cursor="-webkit-".concat(o),this.style.cursor=o)}}},{key:"scroll",value:function(e){var n=this,o=function(e,n){var o="object"===t(n)?n:{move:n};if("number"!=typeof o.x&&(o.x=e.scrollLeft),"number"!=typeof o.y&&(o.y=e.scrollTop),o.move=v[o.move]){var r=o.move.x?"x":"y",i=o.move.x?"left":"top",l=e.getBoundingClientRect(),c=l[i]-e[o.move.x?"scrollLeft":"scrollTop"],s=l[i]+l[o.move.x?"width":"height"]*o.move[r];e.items.every((function(t){var e=t.getBoundingClientRect(),l=t.ownerDocument.defaultView.getComputedStyle(t)["margin-".concat(i)];return o[r]=e[i]-parseInt(l,10)-c,e[o.move.prop||n]<s}))}return{x:Math.max(0,Math.min(o.x,e.scrollWidth-e.clientWidth)),y:Math.max(0,Math.min(o.y,e.scrollHeight-e.clientHeight))}}(this,e),r=o.x,i=o.y,l=m.animate=Date.now().toString(36)+Math.random().toString(36).slice(2,5),c=this.friction,s=g?1:r-this.scrollLeft,a=g?1:i-this.scrollTop;!function t(){m.animate===l&&(Math.round(s)||Math.round(a))&&(n.scrollLeft=r-Math.round(s*=c),n.scrollTop=i-Math.round(a*=c),b(t))}()}},{key:"items",get:function(){return p(this.getAttribute("items")||this.children,this)},set:function(t){this.setAttribute("items",t||"")}},{key:"scrollRight",get:function(){return Math.max(0,this.scrollWidth-this.clientWidth-this.scrollLeft)}},{key:"scrollBottom",get:function(){return Math.max(0,this.scrollHeight-this.clientHeight-this.scrollTop)}},{key:"friction",get:function(){return Math.min(.99,this.getAttribute("friction"))||.8},set:function(t){this.setAttribute("friction",t)}}])&&n(u.prototype,f),E&&n(u,E),L}(c(HTMLElement))})),window.customElements.define("core-scroll",coreScroll); | ||
//# sourceMappingURL=core-scroll.min.js.map |
@@ -1,2 +0,2 @@ | ||
/*! @nrk/core-scroll v4.2.0 - Copyright (c) 2017-2021 NRK */ | ||
/*! @nrk/core-scroll v4.2.1 - Copyright (c) 2017-2021 NRK */ | ||
'use strict'; | ||
@@ -48,4 +48,4 @@ | ||
var coreScroll = fs__default['default'].readFileSync(path__default['default'].resolve(__dirname, 'core-scroll.min.js'), 'utf-8'); | ||
var customElements = fs__default['default'].readFileSync(require.resolve('@webcomponents/custom-elements'), 'utf-8'); | ||
var coreScroll = fs__default["default"].readFileSync(path__default["default"].resolve(__dirname, 'core-scroll.min.js'), 'utf-8'); | ||
var customElements = fs__default["default"].readFileSync(require.resolve('@webcomponents/custom-elements'), 'utf-8'); | ||
describe('core-scroll', function () { | ||
@@ -52,0 +52,0 @@ beforeEach( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { |
31
jsx.js
@@ -1,2 +0,2 @@ | ||
/*! @nrk/core-scroll v4.2.0 - Copyright (c) 2017-2021 NRK */ | ||
/*! @nrk/core-scroll v4.2.1 - Copyright (c) 2017-2021 NRK */ | ||
'use strict'; | ||
@@ -158,2 +158,4 @@ | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
@@ -421,7 +423,8 @@ | ||
} else { | ||
// We floor all values to handle potential decimal leftovers if browser is zoomed in or out | ||
var scroll = { | ||
left: this.scrollLeft, | ||
up: this.scrollTop, | ||
right: this.scrollRight, | ||
down: this.scrollBottom | ||
up: Math.floor(this.scrollTop), | ||
right: Math.floor(this.scrollRight), | ||
down: Math.floor(this.scrollBottom), | ||
left: Math.floor(this.scrollLeft) | ||
}; | ||
@@ -474,12 +477,14 @@ var cursor = scroll.left || scroll.right || scroll.up || scroll.down ? 'grab' : ''; | ||
this.setAttribute('items', val || ''); | ||
} | ||
} // ScrollLeft can return decimals when browser is zoomed, leading to unwanted negative values | ||
}, { | ||
key: "scrollRight", | ||
get: function get() { | ||
return this.scrollWidth - this.clientWidth - this.scrollLeft; | ||
} | ||
return Math.max(0, this.scrollWidth - this.clientWidth - this.scrollLeft); | ||
} // Safeguard for negative due to decimals for scrollTop similar to scrollLeft above | ||
}, { | ||
key: "scrollBottom", | ||
get: function get() { | ||
return this.scrollHeight - this.clientHeight - this.scrollTop; | ||
return Math.max(0, this.scrollHeight - this.clientHeight - this.scrollTop); | ||
} // Avoid friction 1 (infinite) | ||
@@ -583,3 +588,3 @@ | ||
var version = "4.2.0"; | ||
var version = "4.2.1"; | ||
@@ -639,3 +644,3 @@ /** | ||
var tagName = (dashCase + "-" + (options.suffix || 'react')).replace(/\W+/g, '-').toLowerCase(); | ||
return function (superclass) { | ||
return /*@__PURE__*/function (superclass) { | ||
function anonymous(props) { | ||
@@ -711,3 +716,3 @@ var this$1$1 = this; | ||
return React__default['default'].createElement(tagName, Object.keys(this.props).reduce(function (thisProps, propName) { | ||
return React__default["default"].createElement(tagName, Object.keys(this.props).reduce(function (thisProps, propName) { | ||
if (skipProps.indexOf(propName) === -1) { | ||
@@ -734,3 +739,3 @@ // Do not render customEvents and custom props as attributes | ||
return anonymous; | ||
}(React__default['default'].Component); | ||
}(React__default["default"].Component); | ||
} | ||
@@ -737,0 +742,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"author": "NRK <opensource@nrk.no> (https://www.nrk.no/)", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "core-scroll.cjs.js", |
@@ -152,3 +152,3 @@ # Core Scroll | ||
```html | ||
<script src="https://static.nrk.no/core-components/major/7/core-scroll/core-scroll.min.js"></script> <!-- Using static --> | ||
<script src="https://static.nrk.no/core-components/major/9/core-scroll/core-scroll.min.js"></script> <!-- Using static --> | ||
``` | ||
@@ -155,0 +155,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
163964
2024
0