handy-scroll 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- handy-scroll v1.1.2
2
+ handy-scroll v1.1.4
3
3
  https://amphiluke.github.io/handy-scroll/
4
4
  (c) 2023 Amphiluke
5
5
  */
@@ -11,19 +11,13 @@ https://amphiluke.github.io/handy-scroll/
11
11
 
12
12
  let slice = Array.prototype.slice;
13
13
 
14
- // Precaution to avoid reference errors when imported for SSR (issue #13)
15
- let isDOMAvailable = typeof document === "object" && !!document.documentElement;
16
-
17
14
  let dom = {
18
- isDOMAvailable,
19
-
20
- doc: isDOMAvailable ? document : null,
21
- html: isDOMAvailable ? document.documentElement : null,
22
- body: isDOMAvailable ? document.body : null,
15
+ // Precaution to avoid reference errors when imported for SSR (issue #13)
16
+ isDOMAvailable: typeof document === "object" && !!document.documentElement,
23
17
 
24
18
  ready(handler) {
25
- if (dom.doc.readyState === "loading") {
26
- dom.doc.addEventListener("DOMContentLoaded", () => void handler(), {once: true});
19
+ if (document.readyState === "loading") {
20
+ document.addEventListener("DOMContentLoaded", () => void handler(), {once: true});
27
21
  } else {
28
22
  handler();
29
23
  }
@@ -31,7 +25,7 @@ https://amphiluke.github.io/handy-scroll/
31
25
 
32
26
  $(ref) {
33
27
  if (typeof ref === "string") { // ref is a selector
34
- return dom.body.querySelector(ref);
28
+ return document.body.querySelector(ref);
35
29
  }
36
30
  return ref; // ref is already an element
37
31
  },
@@ -44,7 +38,7 @@ https://amphiluke.github.io/handy-scroll/
44
38
  return [ref];
45
39
  }
46
40
  if (typeof ref === "string") { // ref is a selector
47
- return slice.call(dom.body.querySelectorAll(ref));
41
+ return slice.call(document.body.querySelectorAll(ref));
48
42
  }
49
43
  return slice.call(ref); // ref is an array-like object (NodeList or HTMLCollection)
50
44
  }
@@ -69,9 +63,9 @@ https://amphiluke.github.io/handy-scroll/
69
63
 
70
64
  initWidget() {
71
65
  let instance = this;
72
- let widget = instance.widget = dom.doc.createElement("div");
66
+ let widget = instance.widget = document.createElement("div");
73
67
  widget.classList.add("handy-scroll");
74
- let strut = dom.doc.createElement("div");
68
+ let strut = document.createElement("div");
75
69
  strut.style.width = `${instance.container.scrollWidth}px`;
76
70
  widget.appendChild(strut);
77
71
  instance.container.appendChild(widget);
@@ -139,7 +133,7 @@ https://amphiluke.github.io/handy-scroll/
139
133
  let containerRect = container.getBoundingClientRect();
140
134
  let maxVisibleY = scrollBody ?
141
135
  scrollBody.getBoundingClientRect().bottom :
142
- window.innerHeight || dom.html.clientHeight;
136
+ window.innerHeight || document.documentElement.clientHeight;
143
137
  mustHide = ((containerRect.bottom <= maxVisibleY) || (containerRect.top > maxVisibleY));
144
138
  }
145
139
  if (instance.visible === mustHide) {
@@ -265,7 +259,7 @@ https://amphiluke.github.io/handy-scroll/
265
259
  */
266
260
  destroyDetached() {
267
261
  instances = instances.filter(instance => {
268
- if (!dom.body.contains(instance.container)) {
262
+ if (!document.body.contains(instance.container)) {
269
263
  instance.destroy();
270
264
  return false;
271
265
  }
@@ -1,6 +1,6 @@
1
1
  /*!
2
- handy-scroll v1.1.2
2
+ handy-scroll v1.1.4
3
3
  https://amphiluke.github.io/handy-scroll/
4
4
  (c) 2023 Amphiluke
5
5
  */
6
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).handyScroll=t()}(this,(function(){"use strict";let e=Array.prototype.slice,t="object"==typeof document&&!!document.documentElement,i={isDOMAvailable:t,doc:t?document:null,html:t?document.documentElement:null,body:t?document.body:null,ready(e){"loading"===i.doc.readyState?i.doc.addEventListener("DOMContentLoaded",(()=>{e()}),{once:!0}):e()},$:e=>"string"==typeof e?i.body.querySelector(e):e,$$:t=>Array.isArray(t)?t:t.nodeType===Node.ELEMENT_NODE?[t]:"string"==typeof t?e.call(i.body.querySelectorAll(t)):e.call(t)},n={init(e){let t=this,n=i.$$(".handy-scroll-body").filter((t=>t.contains(e)));n.length&&(t.scrollBody=n[0]),t.container=e,t.visible=!0,t.initWidget(),t.update(),t.addEventHandlers(),t.skipSyncContainer=t.skipSyncWidget=!1},initWidget(){let e=this,t=e.widget=i.doc.createElement("div");t.classList.add("handy-scroll");let n=i.doc.createElement("div");n.style.width=`${e.container.scrollWidth}px`,t.appendChild(n),e.container.appendChild(t)},addEventHandlers(){let e=this;(e.eventHandlers=[{el:e.scrollBody||window,handlers:{scroll(){e.checkVisibility()},resize(){e.update()}}},{el:e.widget,handlers:{scroll(){e.visible&&!e.skipSyncContainer&&e.syncContainer(),e.skipSyncContainer=!1}}},{el:e.container,handlers:{scroll(){e.skipSyncWidget||e.syncWidget(),e.skipSyncWidget=!1},focusin(){setTimeout((()=>{e.widget&&e.syncWidget()}),0)}}}]).forEach((({el:e,handlers:t})=>{Object.keys(t).forEach((i=>e.addEventListener(i,t[i],!1)))}))},checkVisibility(){let e=this,{widget:t,container:n,scrollBody:l}=e,o=t.scrollWidth<=t.offsetWidth;if(!o){let e=n.getBoundingClientRect(),t=l?l.getBoundingClientRect().bottom:window.innerHeight||i.html.clientHeight;o=e.bottom<=t||e.top>t}e.visible===o&&(e.visible=!o,t.classList.toggle("handy-scroll-hidden"))},syncContainer(){let e=this,{scrollLeft:t}=e.widget;e.container.scrollLeft!==t&&(e.skipSyncWidget=!0,e.container.scrollLeft=t)},syncWidget(){let e=this,{scrollLeft:t}=e.container;e.widget.scrollLeft!==t&&(e.skipSyncContainer=!0,e.widget.scrollLeft=t)},update(){let e=this,{widget:t,container:i,scrollBody:n}=e,{clientWidth:l,scrollWidth:o}=i;t.style.width=`${l}px`,n||(t.style.left=`${i.getBoundingClientRect().left}px`),t.firstElementChild.style.width=`${o}px`,o>l&&(t.style.height=t.offsetHeight-t.clientHeight+1+"px"),e.syncWidget(),e.checkVisibility()},destroy(){let e=this;e.eventHandlers.forEach((({el:e,handlers:t})=>{Object.keys(t).forEach((i=>e.removeEventListener(i,t[i],!1)))})),e.widget.parentNode.removeChild(e.widget),e.eventHandlers=e.widget=e.container=e.scrollBody=null}},l=[],o={mount(e){i.$$(e).forEach((e=>{if(o.mounted(e))return;let t=Object.create(n);l.push(t),t.init(e)}))},mounted(e){let t=i.$(e);return l.some((e=>e.container===t))},update(e){i.$$(e).forEach((e=>{l.some((t=>t.container===e&&(t.update(),!0)))}))},destroy(e){i.$$(e).forEach((e=>{l.some(((t,i)=>t.container===e&&(l.splice(i,1)[0].destroy(),!0)))}))},destroyDetached(){l=l.filter((e=>!!i.body.contains(e.container)||(e.destroy(),!1)))}};return i.isDOMAvailable&&i.ready((()=>{o.mount("[data-handy-scroll]")})),o}));
6
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).handyScroll=t()}(this,(function(){"use strict";let e=Array.prototype.slice,t={isDOMAvailable:"object"==typeof document&&!!document.documentElement,ready(e){"loading"===document.readyState?document.addEventListener("DOMContentLoaded",(()=>{e()}),{once:!0}):e()},$:e=>"string"==typeof e?document.body.querySelector(e):e,$$:t=>Array.isArray(t)?t:t.nodeType===Node.ELEMENT_NODE?[t]:"string"==typeof t?e.call(document.body.querySelectorAll(t)):e.call(t)},n={init(e){let n=this,i=t.$$(".handy-scroll-body").filter((t=>t.contains(e)));i.length&&(n.scrollBody=i[0]),n.container=e,n.visible=!0,n.initWidget(),n.update(),n.addEventHandlers(),n.skipSyncContainer=n.skipSyncWidget=!1},initWidget(){let e=this,t=e.widget=document.createElement("div");t.classList.add("handy-scroll");let n=document.createElement("div");n.style.width=`${e.container.scrollWidth}px`,t.appendChild(n),e.container.appendChild(t)},addEventHandlers(){let e=this;(e.eventHandlers=[{el:e.scrollBody||window,handlers:{scroll(){e.checkVisibility()},resize(){e.update()}}},{el:e.widget,handlers:{scroll(){e.visible&&!e.skipSyncContainer&&e.syncContainer(),e.skipSyncContainer=!1}}},{el:e.container,handlers:{scroll(){e.skipSyncWidget||e.syncWidget(),e.skipSyncWidget=!1},focusin(){setTimeout((()=>{e.widget&&e.syncWidget()}),0)}}}]).forEach((({el:e,handlers:t})=>{Object.keys(t).forEach((n=>e.addEventListener(n,t[n],!1)))}))},checkVisibility(){let e=this,{widget:t,container:n,scrollBody:i}=e,l=t.scrollWidth<=t.offsetWidth;if(!l){let e=n.getBoundingClientRect(),t=i?i.getBoundingClientRect().bottom:window.innerHeight||document.documentElement.clientHeight;l=e.bottom<=t||e.top>t}e.visible===l&&(e.visible=!l,t.classList.toggle("handy-scroll-hidden"))},syncContainer(){let e=this,{scrollLeft:t}=e.widget;e.container.scrollLeft!==t&&(e.skipSyncWidget=!0,e.container.scrollLeft=t)},syncWidget(){let e=this,{scrollLeft:t}=e.container;e.widget.scrollLeft!==t&&(e.skipSyncContainer=!0,e.widget.scrollLeft=t)},update(){let e=this,{widget:t,container:n,scrollBody:i}=e,{clientWidth:l,scrollWidth:o}=n;t.style.width=`${l}px`,i||(t.style.left=`${n.getBoundingClientRect().left}px`),t.firstElementChild.style.width=`${o}px`,o>l&&(t.style.height=t.offsetHeight-t.clientHeight+1+"px"),e.syncWidget(),e.checkVisibility()},destroy(){let e=this;e.eventHandlers.forEach((({el:e,handlers:t})=>{Object.keys(t).forEach((n=>e.removeEventListener(n,t[n],!1)))})),e.widget.parentNode.removeChild(e.widget),e.eventHandlers=e.widget=e.container=e.scrollBody=null}},i=[],l={mount(e){t.$$(e).forEach((e=>{if(l.mounted(e))return;let t=Object.create(n);i.push(t),t.init(e)}))},mounted(e){let n=t.$(e);return i.some((e=>e.container===n))},update(e){t.$$(e).forEach((e=>{i.some((t=>t.container===e&&(t.update(),!0)))}))},destroy(e){t.$$(e).forEach((e=>{i.some(((t,n)=>t.container===e&&(i.splice(n,1)[0].destroy(),!0)))}))},destroyDetached(){i=i.filter((e=>!!document.body.contains(e.container)||(e.destroy(),!1)))}};return t.isDOMAvailable&&t.ready((()=>{l.mount("[data-handy-scroll]")})),l}));
@@ -1,5 +1,5 @@
1
1
  /*!
2
- handy-scroll v1.1.2
2
+ handy-scroll v1.1.4
3
3
  https://amphiluke.github.io/handy-scroll/
4
4
  (c) 2023 Amphiluke
5
5
  */
@@ -10,17 +10,12 @@ https://amphiluke.github.io/handy-scroll/
10
10
  })(this, (function () { 'use strict';
11
11
 
12
12
  var slice = Array.prototype.slice;
13
-
14
- // Precaution to avoid reference errors when imported for SSR (issue #13)
15
- var isDOMAvailable = typeof document === "object" && !!document.documentElement;
16
13
  var dom = {
17
- isDOMAvailable: isDOMAvailable,
18
- doc: isDOMAvailable ? document : null,
19
- html: isDOMAvailable ? document.documentElement : null,
20
- body: isDOMAvailable ? document.body : null,
14
+ // Precaution to avoid reference errors when imported for SSR (issue #13)
15
+ isDOMAvailable: typeof document === "object" && !!document.documentElement,
21
16
  ready: function ready(handler) {
22
- if (dom.doc.readyState === "loading") {
23
- dom.doc.addEventListener("DOMContentLoaded", function () {
17
+ if (document.readyState === "loading") {
18
+ document.addEventListener("DOMContentLoaded", function () {
24
19
  return void handler();
25
20
  }, {
26
21
  once: true
@@ -32,7 +27,7 @@ https://amphiluke.github.io/handy-scroll/
32
27
  $: function $(ref) {
33
28
  if (typeof ref === "string") {
34
29
  // ref is a selector
35
- return dom.body.querySelector(ref);
30
+ return document.body.querySelector(ref);
36
31
  }
37
32
  return ref; // ref is already an element
38
33
  },
@@ -47,7 +42,7 @@ https://amphiluke.github.io/handy-scroll/
47
42
  }
48
43
  if (typeof ref === "string") {
49
44
  // ref is a selector
50
- return slice.call(dom.body.querySelectorAll(ref));
45
+ return slice.call(document.body.querySelectorAll(ref));
51
46
  }
52
47
  return slice.call(ref); // ref is an array-like object (NodeList or HTMLCollection)
53
48
  }
@@ -72,9 +67,9 @@ https://amphiluke.github.io/handy-scroll/
72
67
  },
73
68
  initWidget: function initWidget() {
74
69
  var instance = this;
75
- var widget = instance.widget = dom.doc.createElement("div");
70
+ var widget = instance.widget = document.createElement("div");
76
71
  widget.classList.add("handy-scroll");
77
- var strut = dom.doc.createElement("div");
72
+ var strut = document.createElement("div");
78
73
  strut.style.width = instance.container.scrollWidth + "px";
79
74
  widget.appendChild(strut);
80
75
  instance.container.appendChild(widget);
@@ -140,7 +135,7 @@ https://amphiluke.github.io/handy-scroll/
140
135
  var mustHide = widget.scrollWidth <= widget.offsetWidth;
141
136
  if (!mustHide) {
142
137
  var containerRect = container.getBoundingClientRect();
143
- var maxVisibleY = scrollBody ? scrollBody.getBoundingClientRect().bottom : window.innerHeight || dom.html.clientHeight;
138
+ var maxVisibleY = scrollBody ? scrollBody.getBoundingClientRect().bottom : window.innerHeight || document.documentElement.clientHeight;
144
139
  mustHide = containerRect.bottom <= maxVisibleY || containerRect.top > maxVisibleY;
145
140
  }
146
141
  if (instance.visible === mustHide) {
@@ -268,7 +263,7 @@ https://amphiluke.github.io/handy-scroll/
268
263
  */
269
264
  destroyDetached: function destroyDetached() {
270
265
  instances = instances.filter(function (instance) {
271
- if (!dom.body.contains(instance.container)) {
266
+ if (!document.body.contains(instance.container)) {
272
267
  instance.destroy();
273
268
  return false;
274
269
  }
@@ -1,6 +1,6 @@
1
1
  /*!
2
- handy-scroll v1.1.2
2
+ handy-scroll v1.1.4
3
3
  https://amphiluke.github.io/handy-scroll/
4
4
  (c) 2023 Amphiluke
5
5
  */
6
- !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).handyScroll=n()}(this,(function(){"use strict";var t=Array.prototype.slice,n="object"==typeof document&&!!document.documentElement,e={isDOMAvailable:n,doc:n?document:null,html:n?document.documentElement:null,body:n?document.body:null,ready:function(t){"loading"===e.doc.readyState?e.doc.addEventListener("DOMContentLoaded",(function(){t()}),{once:!0}):t()},$:function(t){return"string"==typeof t?e.body.querySelector(t):t},$$:function(n){return Array.isArray(n)?n:n.nodeType===Node.ELEMENT_NODE?[n]:"string"==typeof n?t.call(e.body.querySelectorAll(n)):t.call(n)}},i={init:function(t){var n=this,i=e.$$(".handy-scroll-body").filter((function(n){return n.contains(t)}));i.length&&(n.scrollBody=i[0]),n.container=t,n.visible=!0,n.initWidget(),n.update(),n.addEventHandlers(),n.skipSyncContainer=n.skipSyncWidget=!1},initWidget:function(){var t=this,n=t.widget=e.doc.createElement("div");n.classList.add("handy-scroll");var i=e.doc.createElement("div");i.style.width=t.container.scrollWidth+"px",n.appendChild(i),t.container.appendChild(n)},addEventHandlers:function(){var t=this;(t.eventHandlers=[{el:t.scrollBody||window,handlers:{scroll:function(){t.checkVisibility()},resize:function(){t.update()}}},{el:t.widget,handlers:{scroll:function(){t.visible&&!t.skipSyncContainer&&t.syncContainer(),t.skipSyncContainer=!1}}},{el:t.container,handlers:{scroll:function(){t.skipSyncWidget||t.syncWidget(),t.skipSyncWidget=!1},focusin:function(){setTimeout((function(){t.widget&&t.syncWidget()}),0)}}}]).forEach((function(t){var n=t.el,e=t.handlers;Object.keys(e).forEach((function(t){return n.addEventListener(t,e[t],!1)}))}))},checkVisibility:function(){var t=this,n=t.widget,i=t.container,o=t.scrollBody,c=n.scrollWidth<=n.offsetWidth;if(!c){var r=i.getBoundingClientRect(),l=o?o.getBoundingClientRect().bottom:window.innerHeight||e.html.clientHeight;c=r.bottom<=l||r.top>l}t.visible===c&&(t.visible=!c,n.classList.toggle("handy-scroll-hidden"))},syncContainer:function(){var t=this,n=t.widget.scrollLeft;t.container.scrollLeft!==n&&(t.skipSyncWidget=!0,t.container.scrollLeft=n)},syncWidget:function(){var t=this,n=t.container.scrollLeft;t.widget.scrollLeft!==n&&(t.skipSyncContainer=!0,t.widget.scrollLeft=n)},update:function(){var t=this,n=t.widget,e=t.container,i=t.scrollBody,o=e.clientWidth,c=e.scrollWidth;n.style.width=o+"px",i||(n.style.left=e.getBoundingClientRect().left+"px"),n.firstElementChild.style.width=c+"px",c>o&&(n.style.height=n.offsetHeight-n.clientHeight+1+"px"),t.syncWidget(),t.checkVisibility()},destroy:function(){var t=this;t.eventHandlers.forEach((function(t){var n=t.el,e=t.handlers;Object.keys(e).forEach((function(t){return n.removeEventListener(t,e[t],!1)}))})),t.widget.parentNode.removeChild(t.widget),t.eventHandlers=t.widget=t.container=t.scrollBody=null}},o=[],c={mount:function(t){e.$$(t).forEach((function(t){if(!c.mounted(t)){var n=Object.create(i);o.push(n),n.init(t)}}))},mounted:function(t){var n=e.$(t);return o.some((function(t){return t.container===n}))},update:function(t){e.$$(t).forEach((function(t){o.some((function(n){return n.container===t&&(n.update(),!0)}))}))},destroy:function(t){e.$$(t).forEach((function(t){o.some((function(n,e){return n.container===t&&(o.splice(e,1)[0].destroy(),!0)}))}))},destroyDetached:function(){o=o.filter((function(t){return!!e.body.contains(t.container)||(t.destroy(),!1)}))}};return e.isDOMAvailable&&e.ready((function(){c.mount("[data-handy-scroll]")})),c}));
6
+ !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).handyScroll=n()}(this,(function(){"use strict";var t=Array.prototype.slice,n="object"==typeof document&&!!document.documentElement,e=function(t){return"string"==typeof t?document.body.querySelector(t):t},i=function(n){return Array.isArray(n)?n:n.nodeType===Node.ELEMENT_NODE?[n]:"string"==typeof n?t.call(document.body.querySelectorAll(n)):t.call(n)},o={init:function(t){var n=this,e=i(".handy-scroll-body").filter((function(n){return n.contains(t)}));e.length&&(n.scrollBody=e[0]),n.container=t,n.visible=!0,n.initWidget(),n.update(),n.addEventHandlers(),n.skipSyncContainer=n.skipSyncWidget=!1},initWidget:function(){var t=this,n=t.widget=document.createElement("div");n.classList.add("handy-scroll");var e=document.createElement("div");e.style.width=t.container.scrollWidth+"px",n.appendChild(e),t.container.appendChild(n)},addEventHandlers:function(){var t=this;(t.eventHandlers=[{el:t.scrollBody||window,handlers:{scroll:function(){t.checkVisibility()},resize:function(){t.update()}}},{el:t.widget,handlers:{scroll:function(){t.visible&&!t.skipSyncContainer&&t.syncContainer(),t.skipSyncContainer=!1}}},{el:t.container,handlers:{scroll:function(){t.skipSyncWidget||t.syncWidget(),t.skipSyncWidget=!1},focusin:function(){setTimeout((function(){t.widget&&t.syncWidget()}),0)}}}]).forEach((function(t){var n=t.el,e=t.handlers;Object.keys(e).forEach((function(t){return n.addEventListener(t,e[t],!1)}))}))},checkVisibility:function(){var t=this,n=t.widget,e=t.container,i=t.scrollBody,o=n.scrollWidth<=n.offsetWidth;if(!o){var c=e.getBoundingClientRect(),r=i?i.getBoundingClientRect().bottom:window.innerHeight||document.documentElement.clientHeight;o=c.bottom<=r||c.top>r}t.visible===o&&(t.visible=!o,n.classList.toggle("handy-scroll-hidden"))},syncContainer:function(){var t=this,n=t.widget.scrollLeft;t.container.scrollLeft!==n&&(t.skipSyncWidget=!0,t.container.scrollLeft=n)},syncWidget:function(){var t=this,n=t.container.scrollLeft;t.widget.scrollLeft!==n&&(t.skipSyncContainer=!0,t.widget.scrollLeft=n)},update:function(){var t=this,n=t.widget,e=t.container,i=t.scrollBody,o=e.clientWidth,c=e.scrollWidth;n.style.width=o+"px",i||(n.style.left=e.getBoundingClientRect().left+"px"),n.firstElementChild.style.width=c+"px",c>o&&(n.style.height=n.offsetHeight-n.clientHeight+1+"px"),t.syncWidget(),t.checkVisibility()},destroy:function(){var t=this;t.eventHandlers.forEach((function(t){var n=t.el,e=t.handlers;Object.keys(e).forEach((function(t){return n.removeEventListener(t,e[t],!1)}))})),t.widget.parentNode.removeChild(t.widget),t.eventHandlers=t.widget=t.container=t.scrollBody=null}},c=[],r={mount:function(t){i(t).forEach((function(t){if(!r.mounted(t)){var n=Object.create(o);c.push(n),n.init(t)}}))},mounted:function(t){var n=e(t);return c.some((function(t){return t.container===n}))},update:function(t){i(t).forEach((function(t){c.some((function(n){return n.container===t&&(n.update(),!0)}))}))},destroy:function(t){i(t).forEach((function(t){c.some((function(n,e){return n.container===t&&(c.splice(e,1)[0].destroy(),!0)}))}))},destroyDetached:function(){c=c.filter((function(t){return!!document.body.contains(t.container)||(t.destroy(),!1)}))}};return n&&function(t){"loading"===document.readyState?document.addEventListener("DOMContentLoaded",(function(){t()}),{once:!0}):t()}((function(){r.mount("[data-handy-scroll]")})),r}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "handy-scroll",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Handy dependency-free floating scrollbar widget",
5
5
  "main": "./dist/handy-scroll.min.js",
6
6
  "module": "./src/handy-scroll.js",
@@ -41,14 +41,14 @@
41
41
  },
42
42
  "homepage": "https://amphiluke.github.io/handy-scroll/",
43
43
  "devDependencies": {
44
- "@babel/core": "^7.22.5",
45
- "@babel/preset-env": "^7.22.5",
44
+ "@babel/core": "^7.23.0",
45
+ "@babel/preset-env": "^7.22.20",
46
46
  "@rollup/plugin-babel": "^6.0.3",
47
47
  "@rollup/plugin-terser": "^0.4.3",
48
48
  "clean-css-cli": "^5.6.2",
49
- "eslint": "^8.43.0",
49
+ "eslint": "^8.50.0",
50
50
  "husky": "8.0.3",
51
- "less": "^4.1.3",
52
- "rollup": "^3.25.2"
51
+ "less": "^4.2.0",
52
+ "rollup": "^3.29.4"
53
53
  }
54
54
  }
package/src/dom.js CHANGED
@@ -1,18 +1,12 @@
1
1
  let slice = Array.prototype.slice;
2
2
 
3
- // Precaution to avoid reference errors when imported for SSR (issue #13)
4
- let isDOMAvailable = typeof document === "object" && !!document.documentElement;
5
-
6
3
  let dom = {
7
- isDOMAvailable,
8
-
9
- doc: isDOMAvailable ? document : null,
10
- html: isDOMAvailable ? document.documentElement : null,
11
- body: isDOMAvailable ? document.body : null,
4
+ // Precaution to avoid reference errors when imported for SSR (issue #13)
5
+ isDOMAvailable: typeof document === "object" && !!document.documentElement,
12
6
 
13
7
  ready(handler) {
14
- if (dom.doc.readyState === "loading") {
15
- dom.doc.addEventListener("DOMContentLoaded", () => void handler(), {once: true});
8
+ if (document.readyState === "loading") {
9
+ document.addEventListener("DOMContentLoaded", () => void handler(), {once: true});
16
10
  } else {
17
11
  handler();
18
12
  }
@@ -20,7 +14,7 @@ let dom = {
20
14
 
21
15
  $(ref) {
22
16
  if (typeof ref === "string") { // ref is a selector
23
- return dom.body.querySelector(ref);
17
+ return document.body.querySelector(ref);
24
18
  }
25
19
  return ref; // ref is already an element
26
20
  },
@@ -33,7 +27,7 @@ let dom = {
33
27
  return [ref];
34
28
  }
35
29
  if (typeof ref === "string") { // ref is a selector
36
- return slice.call(dom.body.querySelectorAll(ref));
30
+ return slice.call(document.body.querySelectorAll(ref));
37
31
  }
38
32
  return slice.call(ref); // ref is an array-like object (NodeList or HTMLCollection)
39
33
  }
@@ -19,9 +19,9 @@ let handyScrollProto = {
19
19
 
20
20
  initWidget() {
21
21
  let instance = this;
22
- let widget = instance.widget = dom.doc.createElement("div");
22
+ let widget = instance.widget = document.createElement("div");
23
23
  widget.classList.add("handy-scroll");
24
- let strut = dom.doc.createElement("div");
24
+ let strut = document.createElement("div");
25
25
  strut.style.width = `${instance.container.scrollWidth}px`;
26
26
  widget.appendChild(strut);
27
27
  instance.container.appendChild(widget);
@@ -89,7 +89,7 @@ let handyScrollProto = {
89
89
  let containerRect = container.getBoundingClientRect();
90
90
  let maxVisibleY = scrollBody ?
91
91
  scrollBody.getBoundingClientRect().bottom :
92
- window.innerHeight || dom.html.clientHeight;
92
+ window.innerHeight || document.documentElement.clientHeight;
93
93
  mustHide = ((containerRect.bottom <= maxVisibleY) || (containerRect.top > maxVisibleY));
94
94
  }
95
95
  if (instance.visible === mustHide) {
@@ -1,5 +1,5 @@
1
1
  import dom from "./dom.js";
2
- import handyScrollProto from "./handy-scroll-proto";
2
+ import handyScrollProto from "./handy-scroll-proto.js";
3
3
 
4
4
  let instances = []; // if it were not for IE, it would be better to use Map (container -> instance)
5
5
 
@@ -66,7 +66,7 @@ let handyScroll = {
66
66
  */
67
67
  destroyDetached() {
68
68
  instances = instances.filter(instance => {
69
- if (!dom.body.contains(instance.container)) {
69
+ if (!document.body.contains(instance.container)) {
70
70
  instance.destroy();
71
71
  return false;
72
72
  }