handy-scroll 1.1.3 → 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.
- package/dist/handy-scroll.es6.js +11 -17
- package/dist/handy-scroll.es6.min.js +2 -2
- package/dist/handy-scroll.js +11 -16
- package/dist/handy-scroll.min.js +2 -2
- package/package.json +6 -6
- package/src/dom.js +6 -12
- package/src/handy-scroll-proto.js +3 -3
- package/src/handy-scroll.js +1 -1
package/dist/handy-scroll.es6.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
handy-scroll v1.1.
|
|
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
|
-
|
|
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 (
|
|
26
|
-
|
|
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
|
|
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(
|
|
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 =
|
|
66
|
+
let widget = instance.widget = document.createElement("div");
|
|
73
67
|
widget.classList.add("handy-scroll");
|
|
74
|
-
let strut =
|
|
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 ||
|
|
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 (!
|
|
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
|
+
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,
|
|
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}));
|
package/dist/handy-scroll.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
handy-scroll v1.1.
|
|
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
|
-
|
|
18
|
-
|
|
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 (
|
|
23
|
-
|
|
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
|
|
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(
|
|
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 =
|
|
70
|
+
var widget = instance.widget = document.createElement("div");
|
|
76
71
|
widget.classList.add("handy-scroll");
|
|
77
|
-
var strut =
|
|
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 ||
|
|
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 (!
|
|
266
|
+
if (!document.body.contains(instance.container)) {
|
|
272
267
|
instance.destroy();
|
|
273
268
|
return false;
|
|
274
269
|
}
|
package/dist/handy-scroll.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
handy-scroll v1.1.
|
|
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=
|
|
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.
|
|
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.
|
|
45
|
-
"@babel/preset-env": "^7.22.
|
|
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.
|
|
49
|
+
"eslint": "^8.50.0",
|
|
50
50
|
"husky": "8.0.3",
|
|
51
|
-
"less": "^4.
|
|
52
|
-
"rollup": "^3.
|
|
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
|
-
|
|
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 (
|
|
15
|
-
|
|
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
|
|
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(
|
|
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 =
|
|
22
|
+
let widget = instance.widget = document.createElement("div");
|
|
23
23
|
widget.classList.add("handy-scroll");
|
|
24
|
-
let strut =
|
|
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 ||
|
|
92
|
+
window.innerHeight || document.documentElement.clientHeight;
|
|
93
93
|
mustHide = ((containerRect.bottom <= maxVisibleY) || (containerRect.top > maxVisibleY));
|
|
94
94
|
}
|
|
95
95
|
if (instance.visible === mustHide) {
|
package/src/handy-scroll.js
CHANGED