@localnerve/jump-scroll 0.3.5 → 0.3.7
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/README.md +8 -1
- package/dist/jump-scroll.css +1 -1
- package/dist/jump-scroll.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
## Summary
|
|
10
10
|
|
|
11
|
-
Provides a small scrolling control that allows the user to go to the top or bottom, or jump to the next (or previous) section of a page.
|
|
11
|
+
Provides a small scrolling control that allows the user to go to the top or bottom, or jump to the next (or previous) section of a page. Non-browser version of the module exports build helpers (for building CSP rules, etc).
|
|
12
12
|
|
|
13
13
|
## Attributes
|
|
14
14
|
|
|
@@ -23,11 +23,18 @@ Provides a small scrolling control that allows the user to go to the top or bott
|
|
|
23
23
|
* `--js-bg-color` - The color of the control arrows. Defaults to black.
|
|
24
24
|
* `--js-opacity-full` - The opacity of the control arrows at attention. Defaults to 0.7.
|
|
25
25
|
* `--js-opacity-rest` - The opacity of the control arrows at rest. Defaults to 0.3.
|
|
26
|
+
* `--js-attach-right` - The distance from the fixed, right-edge attachment. Defaults to 0.5rem;
|
|
27
|
+
* `--js-attach-bottom` - The distance form the fixed, bottom-edge attachment. Defaults to 0.7rem;
|
|
26
28
|
|
|
27
29
|
## Usage Example
|
|
28
30
|
```html
|
|
29
31
|
<jump-scroll target="article" display="best"></jump-scroll>
|
|
30
32
|
```
|
|
33
|
+
## Non-browser Exports
|
|
34
|
+
The non-browser version of the module exports methods to help with builds.
|
|
35
|
+
|
|
36
|
+
### {Promise} getJumpScrollCssText()
|
|
37
|
+
A function to asynchronously get the raw shadow css text. This is useful for computing the hash for a CSP style rule. Returns a Promise that resolves to the full utf8 string of css text.
|
|
31
38
|
|
|
32
39
|
## License
|
|
33
40
|
LocalNerve [BSD-3-Clause](LICENSE.md) Licensed
|
package/dist/jump-scroll.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
:host{--js-width:2em;--js-height:8em;--js-bg-color:black;--js-color:white;--js-opacity-full:0.7;--js-opacity-rest:0.3;position:fixed;bottom:
|
|
1
|
+
:host{--js-width:2em;--js-height:8em;--js-bg-color:black;--js-color:white;--js-opacity-full:0.7;--js-opacity-rest:0.3;--js-attach-right:0.5rem;--js-attach-bottom:0.7rem;position:fixed;bottom:var(--js-attach-bottom);right:var(--js-attach-right);width:var(--js-width);height:var(--js-height);color:var(--js-color)}.container{display:block;transition:opacity 1s;opacity:var(--js-opacity-full)}.container.none{display:none}.container.rest{opacity:var(--js-opacity-rest)}.container.mid{transform:none}.container.best.mid.down .top,.container.start .top{pointer-events:none;opacity:0}.container.best.mid.up .bot,.container.end .bot{pointer-events:none;opacity:0;transform:translateY(102%)}.container.best.mid.down .top,.container.best.mid.up .top,.container.end .top{transform:translateY(102%)}.bot,.top{position:absolute;width:100%;height:calc(var(--js-height)/ 2);transition:opacity 1s,transform 1s;pointer-events:auto}.top{top:0}.bot{bottom:0}.bot .end,.bot .next,.top .prev,.top .start{content:'';position:absolute;left:50%;width:100%;background:var(--js-bg-color)}.bot .end,.top .start{height:calc(var(--js-height)/ 6);clip-path:polygon(15% 5%,85% 5%,85% 30%,60% 30%,85% 95%,15% 95%,40% 30%,15% 30%)}.bot .next,.top .prev{height:calc(var(--js-height)/ 4);clip-path:polygon(50% 5%,85% 60%,60% 60%,85% 95%,15% 95%,40% 60%,15% 60%)}.top .prev,.top .start{transform:translateX(-50%)}.bot .end,.bot .next{transform:translateX(-50%) rotateX(180deg)}.top .start{top:0}.top .prev{top:calc((var(--js-height)/ 6) + 10%)}.bot .next{bottom:calc((var(--js-height)/ 6) + 10%)}.bot .end{bottom:0}
|
package/dist/jump-scroll.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! jump-scroll, Copyright (c) 2023 Alex Grant (@localnerve), LocalNerve LLC, BSD-3-Clause */
|
|
2
|
-
class t extends HTMLElement{#t=null;#e=null;#s=null;#
|
|
2
|
+
class t extends HTMLElement{#t=null;#e=null;#s=null;#r=null;#i=null;#o=null;#n=null;#a=null;#c=!0;#l=!1;static#h=["target"];static#p={target:"section",display:"both"};static get observedAttributes(){return[...t.#h,"display","colormap"]}constructor(){super(),this.attachShadow({mode:"open"}),this.targetIntersection=this.targetIntersection.bind(this),this.controlIntersection=this.controlIntersection.bind(this),this.setup=this.setup.bind(this),this.clickTop=this.clickTop.bind(this),this.clickBottom=this.clickBottom.bind(this),this.clickNext=this.clickNext.bind(this),this.clickPrev=this.clickPrev.bind(this),this.createTargetProperties()}createTargetProperties(){t.#h.forEach((e=>{Object.defineProperty(this,e,{get(){return this.hasAttribute(e)?this.getAttribute(e):t.#p[e]},set(t){t?this.setAttribute(e,t):this.removeAttribute(e),this.updateTargetMap(t)}})}))}get display(){const e="display";return this.hasAttribute(e)?this.getAttribute(e):t.#p[e]}set display(t){const e="display",s=["both","best"];this.#a&&this.#a.classList.remove(...s.concat("up","down")),s.includes(t)?(this.setAttribute(e,t),this.#a&&this.#a.classList.add(t)):this.removeAttribute(e)}get colormap(){let t="";const e="colormap";return this.hasAttribute(e)&&(t=this.getAttribute(e)),t}set colormap(t){if(null===this.#a)return;const e="colormap",s=t&&t.split(";");if(s&&s.length>0&&s[0].includes(":")){this.setAttribute(e,t),this.#n=new Map;for(const t of s){let[e,s]=t.replace(/\s/,"").split(":");s.startsWith("--")&&(s=`var(${s})`),this.#n.set(parseInt(e,10),s)}}else this.removeAttribute(e),this.#n=null}update(t){const e=[t],s=["mid","start","end","rest","up","down"];null!==this.#s&&s.push("none"),"best"===this.display&&"mid"===t&&(this.#c?e.push("down"):e.push("up")),this.#a.classList.remove(...s),this.#a.classList.add(...e),setTimeout((()=>{this.#a.classList.add("rest")}),500)}clickTop(){this.#i=this.#s,this.#s.scrollIntoView({block:"nearest",inline:"start",behavior:"smooth"}),this.update("start")}clickBottom(){this.#i=this.#r,this.#r.scrollIntoView({block:"nearest",inline:"start",behavior:"smooth"}),this.update("end")}clickNext(){const t=this.#o.get(this.#i);t&&t.next&&(this.#i=t.next,t.next.scrollIntoView({block:"nearest",inline:"start",behavior:"smooth"}))}clickPrev(){const t=this.#o.get(this.#i);t&&t.prev&&(this.#i=t.prev,t.prev.scrollIntoView({block:"nearest",inline:"start",behavior:"smooth"}))}updateTargetMap(e,s){if(!t.#h.includes(e)||!this.#l)return;let r,i;this.#s=null,this.#r=null,this.#i=null,this.#o=new WeakMap;const o=[];if(document.querySelectorAll(this[e]).forEach((t=>{for(r=t.getBoundingClientRect(),i=0;i<o.length&&!(r.top<o[i].top);i++);o.splice(i,0,{top:r.top,el:t}),"function"==typeof s&&s(t)})),o.length>0){this.#s=o[0].el,this.#r=o[o.length-1].el;let t=0;for(i=0;i<o.length;i++)0>o[i].top&&(t=i+1),this.#o.set(o[i].el,{index:i,prev:i>0?o[i-1].el:null,next:i<o.length-1?o[i+1].el:null});this.#i=o[t].el,0===t?this.update("start"):t===o.length-1?this.update("end"):this.update("mid")}}targetIntersection(t){const e=t[0];if(e.isIntersecting){const t=e.target;let s="mid";this.#c=e.boundingClientRect.top>=0,t===this.#s?s="start":t===this.#r&&(s="end"),this.#i=t,this.update(s)}}controlIntersection(t){const e=t.filter((t=>t.isIntersecting));if(e&&e.length>0&&this.#n){const t=e[0],s=this.#o.get(t.target);if(s){const t=s&&this.#n.get(s.index);t?this.#a.style.setProperty("--js-bg-color",t):this.#a.style.removeProperty("--js-bg-color")}}}setup(){this.#l=!0,this.#t=new IntersectionObserver(this.targetIntersection,{threshold:.5}),this.#e=new IntersectionObserver(this.controlIntersection,{threshold:.05,rootMargin:"-90% 0px 0px 0px"}),t.#h.forEach((t=>{this.updateTargetMap(t,(t=>{this.#t.observe(t),this.#e.observe(t)}))}))}teardown(){this.#t&&this.#t.disconnect(),this.#e&&this.#e.disconnect(),this.#t=null,this.#e=null,this.#s=null,this.#r=null,this.#i=null,this.#a=null,this.#o=null,this.#n=null,this.#l=!1}connectedCallback(){"complete"!==document.readyState?window.addEventListener("load",(()=>{this.setup()}),{once:!0}):this.setup();const{shadowRoot:t}=this;t.innerHTML='<style>:host{--js-width:2em;--js-height:8em;--js-bg-color:black;--js-color:white;--js-opacity-full:0.7;--js-opacity-rest:0.3;--js-attach-right:0.5rem;--js-attach-bottom:0.7rem;position:fixed;bottom:var(--js-attach-bottom);right:var(--js-attach-right);width:var(--js-width);height:var(--js-height);color:var(--js-color)}.container{display:block;transition:opacity 1s;opacity:var(--js-opacity-full)}.container.none{display:none}.container.rest{opacity:var(--js-opacity-rest)}.container.mid{transform:none}.container.best.mid.down .top,.container.start .top{pointer-events:none;opacity:0}.container.best.mid.up .bot,.container.end .bot{pointer-events:none;opacity:0;transform:translateY(102%)}.container.best.mid.down .top,.container.best.mid.up .top,.container.end .top{transform:translateY(102%)}.bot,.top{position:absolute;width:100%;height:calc(var(--js-height)/ 2);transition:opacity 1s,transform 1s;pointer-events:auto}.top{top:0}.bot{bottom:0}.bot .end,.bot .next,.top .prev,.top .start{content:\'\';position:absolute;left:50%;width:100%;background:var(--js-bg-color)}.bot .end,.top .start{height:calc(var(--js-height)/ 6);clip-path:polygon(15% 5%,85% 5%,85% 30%,60% 30%,85% 95%,15% 95%,40% 30%,15% 30%)}.bot .next,.top .prev{height:calc(var(--js-height)/ 4);clip-path:polygon(50% 5%,85% 60%,60% 60%,85% 95%,15% 95%,40% 60%,15% 60%)}.top .prev,.top .start{transform:translateX(-50%)}.bot .end,.bot .next{transform:translateX(-50%) rotateX(180deg)}.top .start{top:0}.top .prev{top:calc((var(--js-height)/ 6) + 10%)}.bot .next{bottom:calc((var(--js-height)/ 6) + 10%)}.bot .end{bottom:0}</style><div class="container none"><div class="top"><div class="start"></div><div class="prev"></div></div><div class="bot"><div class="next"></div><div class="end"></div></div></div>',this.#a=t.querySelector(".container"),this.display=this.display,this.colormap=this.colormap,t.querySelector(".top .start").addEventListener("click",this.clickTop),t.querySelector(".bot .end").addEventListener("click",this.clickBottom),t.querySelector(".top .prev").addEventListener("click",this.clickPrev),t.querySelector(".bot .next").addEventListener("click",this.clickNext)}disconnectedCallback(){this.#a=null,this.shadowRoot.querySelector(".top .start").removeEventListener("click",this.clickTop),this.shadowRoot.querySelector(".bot .end").removeEventListener("click",this.clickBottom),this.shadowRoot.querySelector(".top. .prev").removeEventListener("click",this.clickPrev),this.shadowRoot.querySelector(".bot .next").removeEventListener("click",this.clickNext),this.teardown()}attributeChangedCallback(t,e,s){s!==e&&(this[t]=this.getAttribute(t))}}customElements.define("jump-scroll",t);
|