handy-scroll 2.0.3 → 2.0.5

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,120 +1,6 @@
1
1
  /*!
2
- handy-scroll v2.0.3
2
+ handy-scroll v2.0.5
3
3
  https://amphiluke.github.io/handy-scroll/
4
- (c) 2024 Amphiluke
4
+ (c) 2026 Amphiluke
5
5
  */
6
- const h = ':host{bottom:0;min-height:17px;overflow:auto;position:fixed}.strut{height:1px;overflow:hidden;pointer-events:none;&:before{content:" "}}:host,.strut{font-size:1px;line-height:0;margin:0;padding:0}:host(:state(latent)){bottom:110vh;.strut:before{content:"  "}}:host([viewport]:not([hidden])){display:block}:host([viewport]){position:sticky}:host([viewport]:state(latent)){position:fixed}';
7
- let n = (s) => `Attribute ‘${s}’ must reference a valid container ‘id’`;
8
- class o extends HTMLElement {
9
- static get observedAttributes() {
10
- return ["owner", "viewport", "hidden"];
11
- }
12
- #o = null;
13
- #t = null;
14
- #e = null;
15
- #s = null;
16
- #i = null;
17
- #n = null;
18
- #r = !0;
19
- #l = !0;
20
- get owner() {
21
- return this.getAttribute("owner");
22
- }
23
- set owner(t) {
24
- this.setAttribute("owner", t);
25
- }
26
- get viewport() {
27
- return this.getAttribute("viewport");
28
- }
29
- set viewport(t) {
30
- this.setAttribute("viewport", t);
31
- }
32
- get #h() {
33
- return this.#o.states.has("latent");
34
- }
35
- set #h(t) {
36
- this.#o.states[t ? "add" : "delete"]("latent");
37
- }
38
- constructor() {
39
- super();
40
- let t = this.attachShadow({ mode: "open" }), e = document.createElement("style");
41
- e.textContent = h, t.appendChild(e), this.#s = document.createElement("div"), this.#s.classList.add("strut"), t.appendChild(this.#s), this.#o = this.attachInternals();
42
- }
43
- connectedCallback() {
44
- this.#a(), this.#c(), this.#u(), this.#p(), this.update();
45
- }
46
- disconnectedCallback() {
47
- this.#w(), this.#f(), this.#e = this.#t = null;
48
- }
49
- attributeChangedCallback(t) {
50
- if (this.#i) {
51
- if (t === "hidden") {
52
- this.hasAttribute("hidden") || this.update();
53
- return;
54
- }
55
- t === "owner" ? this.#a() : t === "viewport" && this.#c(), this.#w(), this.#f(), this.#u(), this.#p(), this.update();
56
- }
57
- }
58
- #a() {
59
- let t = this.getAttribute("owner");
60
- if (this.#e = document.getElementById(t), !this.#e)
61
- throw new DOMException(n("owner"));
62
- }
63
- #c() {
64
- if (!this.hasAttribute("viewport")) {
65
- this.#t = window;
66
- return;
67
- }
68
- let t = this.getAttribute("viewport");
69
- if (this.#t = document.getElementById(t), !this.#t)
70
- throw new DOMException(n("viewport"));
71
- }
72
- #u() {
73
- this.#i = new AbortController();
74
- let t = { signal: this.#i.signal };
75
- this.#t.addEventListener("scroll", () => this.#v(), t), this.#t === window && this.#t.addEventListener("resize", () => this.update(), t), this.addEventListener("scroll", () => {
76
- this.#r && !this.#h && this.#b(), this.#r = !0;
77
- }, t), this.#e.addEventListener("scroll", () => {
78
- this.#l && this.#d(), this.#l = !0;
79
- }, t), this.#e.addEventListener("focusin", () => {
80
- setTimeout(() => {
81
- this.isConnected && this.#d();
82
- }, 0);
83
- }, t);
84
- }
85
- #w() {
86
- this.#i?.abort(), this.#i = null;
87
- }
88
- #p() {
89
- this.#t !== window && (this.#n = new ResizeObserver(([t]) => {
90
- t.contentBoxSize?.[0]?.inlineSize && this.update();
91
- }), this.#n.observe(this.#t));
92
- }
93
- #f() {
94
- this.#n?.disconnect(), this.#n = null;
95
- }
96
- #b() {
97
- let { scrollLeft: t } = this;
98
- this.#e.scrollLeft !== t && (this.#l = !1, this.#e.scrollLeft = t);
99
- }
100
- #d() {
101
- let { scrollLeft: t } = this.#e;
102
- this.scrollLeft !== t && (this.#r = !1, this.scrollLeft = t);
103
- }
104
- #v() {
105
- let t = this.scrollWidth <= this.offsetWidth;
106
- if (!t) {
107
- let e = this.#e.getBoundingClientRect(), i = this.#t === window ? window.innerHeight || document.documentElement.clientHeight : this.#t.getBoundingClientRect().bottom;
108
- t = e.bottom <= i || e.top > i;
109
- }
110
- this.#h !== t && (this.#h = t);
111
- }
112
- update() {
113
- let { clientWidth: t, scrollWidth: e } = this.#e, { style: i } = this;
114
- i.width = `${t}px`, this.#t === window && (i.left = `${this.#e.getBoundingClientRect().left}px`), this.#s.style.width = `${e}px`, e > t && (i.height = `${this.offsetHeight - this.clientHeight + 1}px`), this.#d(), this.#v();
115
- }
116
- }
117
- customElements.define("handy-scroll", o);
118
- export {
119
- o as default
120
- };
6
+ const t=new CSSStyleSheet;t.replaceSync(':host{bottom:0;min-height:17px;overflow:auto;position:fixed}.strut{height:1px;overflow:hidden;pointer-events:none;&:before{content:" "}}:host,.strut{font-size:1px;line-height:0;margin:0;padding:0}:host(:state(latent)){clip-path:inset(100%);.strut:before{content:"  "}}:host([viewport]:not([hidden])){display:block}:host([viewport]){position:sticky}');let e=t=>`Attribute ‘${t}’ must reference a valid container ‘id’`;class i extends HTMLElement{static get observedAttributes(){return["owner","viewport","hidden"]}#t=null;#e=null;#i=null;#s=null;#h=null;#n=null;#o=!0;#l=!0;get owner(){return this.getAttribute("owner")}set owner(t){this.setAttribute("owner",t)}get viewport(){return this.getAttribute("viewport")}set viewport(t){this.setAttribute("viewport",t)}get#r(){return this.#t.states.has("latent")}set#r(t){this.#t.states[t?"add":"delete"]("latent")}constructor(){super();let e=this.attachShadow({mode:"open"});e.adoptedStyleSheets=[t],this.#s=document.createElement("div"),this.#s.classList.add("strut"),e.appendChild(this.#s),this.#t=this.attachInternals()}connectedCallback(){this.#d(),this.#a(),this.#c(),this.#u(),this.update()}disconnectedCallback(){this.#w(),this.#p(),this.#i=this.#e=null}attributeChangedCallback(t){if(this.#h){if("hidden"===t)return void(this.hasAttribute("hidden")||this.update());"owner"===t?this.#d():"viewport"===t&&this.#a(),this.#w(),this.#p(),this.#c(),this.#u(),this.update()}}#d(){let t=this.getAttribute("owner");if(this.#i=document.getElementById(t),!this.#i)throw new DOMException(e("owner"))}#a(){if(!this.hasAttribute("viewport"))return void(this.#e=window);let t=this.getAttribute("viewport");if(this.#e=document.getElementById(t),!this.#e)throw new DOMException(e("viewport"))}#c(){this.#h=new AbortController;let t={signal:this.#h.signal};this.#e.addEventListener("scroll",()=>this.#f(),t),this.#e===window&&this.#e.addEventListener("resize",()=>this.update(),t),this.addEventListener("scroll",()=>{this.#o&&!this.#r&&this.#g(),this.#o=!0},t),this.#i.addEventListener("scroll",()=>{this.#l&&this.#v(),this.#l=!0},t),this.#i.addEventListener("focusin",()=>{setTimeout(()=>{this.isConnected&&this.#v()},0)},t)}#w(){this.#h?.abort(),this.#h=null}#u(){this.#e!==window&&(this.#n=new ResizeObserver(([t])=>{t.contentBoxSize?.[0]?.inlineSize&&this.update()}),this.#n.observe(this.#e))}#p(){this.#n?.disconnect(),this.#n=null}#g(){let{scrollLeft:t}=this;this.#i.scrollLeft!==t&&(this.#l=!1,this.#i.scrollLeft=t)}#v(){let{scrollLeft:t}=this.#i;this.scrollLeft!==t&&(this.#o=!1,this.scrollLeft=t)}#f(){let t=this.scrollWidth<=this.offsetWidth;if(!t){let e=this.#i.getBoundingClientRect(),i=this.#e===window?window.innerHeight||document.documentElement.clientHeight:this.#e.getBoundingClientRect().bottom;t=e.bottom<=i||e.top>i}this.#r!==t&&(this.#r=t)}update(){let{clientWidth:t,scrollWidth:e}=this.#i,{style:i}=this;i.width=`${t}px`,this.#e===window&&(i.left=`${this.#i.getBoundingClientRect().left}px`),this.#s.style.width=`${e}px`,e>t&&(i.height=this.offsetHeight-this.clientHeight+1+"px"),this.#v(),this.#f()}}customElements.define("handy-scroll",i);export{i as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "handy-scroll",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "Handy dependency-free floating scrollbar web component",
5
5
  "exports": {
6
6
  ".": {
@@ -17,7 +17,7 @@
17
17
  "scripts": {
18
18
  "lint": "eslint",
19
19
  "dev": "vite",
20
- "build": "vite build",
20
+ "build": "vite build && terser dist/handy-scroll.mjs -c -m --module -o dist/handy-scroll.mjs",
21
21
  "preview": "vite preview"
22
22
  },
23
23
  "repository": {
@@ -36,10 +36,11 @@
36
36
  },
37
37
  "homepage": "https://amphiluke.github.io/handy-scroll/",
38
38
  "devDependencies": {
39
- "@eslint/js": "^9.12.0",
40
- "@stylistic/eslint-plugin-js": "^2.9.0",
41
- "eslint": "^9.12.0",
42
- "globals": "^15.10.0",
43
- "vite": "^5.4.8"
39
+ "@eslint/js": "^9.39.2",
40
+ "@stylistic/eslint-plugin": "^5.7.0",
41
+ "eslint": "^9.39.2",
42
+ "globals": "^17.0.0",
43
+ "terser": "^5.44.1",
44
+ "vite": "^7.3.1"
44
45
  }
45
46
  }
@@ -24,7 +24,7 @@
24
24
  }
25
25
 
26
26
  :host(:state(latent)) {
27
- bottom: 110vh;
27
+ clip-path: inset(100%);
28
28
 
29
29
  .strut::before {
30
30
  content: "\A0\A0"; /* changing content fixes eventual bug with widget re-rendering in Chrome */
@@ -38,7 +38,3 @@
38
38
  :host([viewport]) {
39
39
  position: sticky;
40
40
  }
41
-
42
- :host([viewport]:state(latent)) {
43
- position: fixed;
44
- }
@@ -1,5 +1,8 @@
1
1
  import css from "./handy-scroll.css?inline";
2
2
 
3
+ const stylesheet = new CSSStyleSheet();
4
+ stylesheet.replaceSync(css);
5
+
3
6
  let getAttributeErrorMessage = (attribute) => `Attribute ‘${attribute}’ must reference a valid container ‘id’`;
4
7
 
5
8
  class HandyScroll extends HTMLElement {
@@ -44,9 +47,7 @@ class HandyScroll extends HTMLElement {
44
47
  super();
45
48
  let shadowRoot = this.attachShadow({mode: "open"});
46
49
 
47
- let style = document.createElement("style");
48
- style.textContent = css;
49
- shadowRoot.appendChild(style);
50
+ shadowRoot.adoptedStyleSheets = [stylesheet];
50
51
 
51
52
  this.#strut = document.createElement("div");
52
53
  this.#strut.classList.add("strut");