handy-scroll 2.0.4 → 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,121 +1,6 @@
1
1
  /*!
2
- handy-scroll v2.0.4
2
+ handy-scroll v2.0.5
3
3
  https://amphiluke.github.io/handy-scroll/
4
- (c) 2025 Amphiluke
4
+ (c) 2026 Amphiluke
5
5
  */
6
- const o = ':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}', h = new CSSStyleSheet();
7
- h.replaceSync(o);
8
- let n = (s) => `Attribute ‘${s}’ must reference a valid container ‘id’`;
9
- class r extends HTMLElement {
10
- static get observedAttributes() {
11
- return ["owner", "viewport", "hidden"];
12
- }
13
- #o = null;
14
- #t = null;
15
- #e = null;
16
- #s = null;
17
- #i = null;
18
- #n = null;
19
- #r = !0;
20
- #l = !0;
21
- get owner() {
22
- return this.getAttribute("owner");
23
- }
24
- set owner(t) {
25
- this.setAttribute("owner", t);
26
- }
27
- get viewport() {
28
- return this.getAttribute("viewport");
29
- }
30
- set viewport(t) {
31
- this.setAttribute("viewport", t);
32
- }
33
- get #h() {
34
- return this.#o.states.has("latent");
35
- }
36
- set #h(t) {
37
- this.#o.states[t ? "add" : "delete"]("latent");
38
- }
39
- constructor() {
40
- super();
41
- let t = this.attachShadow({ mode: "open" });
42
- t.adoptedStyleSheets = [h], this.#s = document.createElement("div"), this.#s.classList.add("strut"), t.appendChild(this.#s), this.#o = this.attachInternals();
43
- }
44
- connectedCallback() {
45
- this.#a(), this.#c(), this.#u(), this.#p(), this.update();
46
- }
47
- disconnectedCallback() {
48
- this.#w(), this.#f(), this.#e = this.#t = null;
49
- }
50
- attributeChangedCallback(t) {
51
- if (this.#i) {
52
- if (t === "hidden") {
53
- this.hasAttribute("hidden") || this.update();
54
- return;
55
- }
56
- t === "owner" ? this.#a() : t === "viewport" && this.#c(), this.#w(), this.#f(), this.#u(), this.#p(), this.update();
57
- }
58
- }
59
- #a() {
60
- let t = this.getAttribute("owner");
61
- if (this.#e = document.getElementById(t), !this.#e)
62
- throw new DOMException(n("owner"));
63
- }
64
- #c() {
65
- if (!this.hasAttribute("viewport")) {
66
- this.#t = window;
67
- return;
68
- }
69
- let t = this.getAttribute("viewport");
70
- if (this.#t = document.getElementById(t), !this.#t)
71
- throw new DOMException(n("viewport"));
72
- }
73
- #u() {
74
- this.#i = new AbortController();
75
- let t = { signal: this.#i.signal };
76
- this.#t.addEventListener("scroll", () => this.#v(), t), this.#t === window && this.#t.addEventListener("resize", () => this.update(), t), this.addEventListener("scroll", () => {
77
- this.#r && !this.#h && this.#b(), this.#r = !0;
78
- }, t), this.#e.addEventListener("scroll", () => {
79
- this.#l && this.#d(), this.#l = !0;
80
- }, t), this.#e.addEventListener("focusin", () => {
81
- setTimeout(() => {
82
- this.isConnected && this.#d();
83
- }, 0);
84
- }, t);
85
- }
86
- #w() {
87
- this.#i?.abort(), this.#i = null;
88
- }
89
- #p() {
90
- this.#t !== window && (this.#n = new ResizeObserver(([t]) => {
91
- t.contentBoxSize?.[0]?.inlineSize && this.update();
92
- }), this.#n.observe(this.#t));
93
- }
94
- #f() {
95
- this.#n?.disconnect(), this.#n = null;
96
- }
97
- #b() {
98
- let { scrollLeft: t } = this;
99
- this.#e.scrollLeft !== t && (this.#l = !1, this.#e.scrollLeft = t);
100
- }
101
- #d() {
102
- let { scrollLeft: t } = this.#e;
103
- this.scrollLeft !== t && (this.#r = !1, this.scrollLeft = t);
104
- }
105
- #v() {
106
- let t = this.scrollWidth <= this.offsetWidth;
107
- if (!t) {
108
- let i = this.#e.getBoundingClientRect(), e = this.#t === window ? window.innerHeight || document.documentElement.clientHeight : this.#t.getBoundingClientRect().bottom;
109
- t = i.bottom <= e || i.top > e;
110
- }
111
- this.#h !== t && (this.#h = t);
112
- }
113
- update() {
114
- let { clientWidth: t, scrollWidth: i } = this.#e, { style: e } = this;
115
- e.width = `${t}px`, this.#t === window && (e.left = `${this.#e.getBoundingClientRect().left}px`), this.#s.style.width = `${i}px`, i > t && (e.height = `${this.offsetHeight - this.clientHeight + 1}px`), this.#d(), this.#v();
116
- }
117
- }
118
- customElements.define("handy-scroll", r);
119
- export {
120
- r as default
121
- };
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.4",
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.24.0",
40
- "@stylistic/eslint-plugin-js": "^4.2.0",
41
- "eslint": "^9.24.0",
42
- "globals": "^16.0.0",
43
- "vite": "^6.2.5"
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
- }