@livx.cc/bare-v3 0.1.0-alpha.154 → 0.1.0-alpha.155
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/components/swipe.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
var
|
|
1
|
+
var C=typeof HTMLElement==="function"?HTMLElement:class{};function L(e,t){if(typeof customElements>"u"||customElements.get?.(e))return;try{customElements.define(e,t)}catch(s){console.warn(`bare-v3: ${e} was not registered`,s)}}var O=Symbol.for("bare-v3.styles");function T(e,t,s){if(!e?.head||e.getElementById(t))return;let o=e[O]??=new Set;if(o.has(t))return;let l=e.defaultView;if(l&&"adoptedStyleSheets"in e&&"replaceSync"in l.CSSStyleSheet.prototype){let b=new l.CSSStyleSheet;b.replaceSync(s),e.adoptedStyleSheets=[...e.adoptedStyleSheets,b],o.add(t);return}let d=e.createElement("style");d.id=t,d.textContent=s,e.head.append(d)}var X=10,P=24,N=0.6,B=48,Y=400,M="[data-b3-swipe],[data-b3-swipe-left],[data-b3-swipe-right]",W="b3-swipe-style",_=`
|
|
2
2
|
b3-swipe{display:block;}
|
|
3
|
-
b3-swipe :is(${
|
|
4
|
-
b3-swipe [data-b3-swiping]{position:relative;z-index:1;
|
|
3
|
+
b3-swipe :is(${M}){touch-action:pan-y;}
|
|
4
|
+
b3-swipe [data-b3-swiping]{position:relative;z-index:1;transition:none!important;}
|
|
5
5
|
b3-swipe [data-b3-swipe-back]{transition:transform .18s ease-out;}
|
|
6
6
|
.b3-swipe-action{position:absolute;display:flex;align-items:center;padding-inline:20px;box-sizing:border-box;
|
|
7
|
-
font-weight:600;color:#fff;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.b3-swipe-action[data-
|
|
11
|
-
|
|
7
|
+
overflow:hidden;white-space:nowrap;font-weight:600;color:#fff;pointer-events:none;
|
|
8
|
+
--b3-swipe-color:var(--b3-swipe-left-color,var(--b3-color-danger,#c0392b));
|
|
9
|
+
background:color-mix(in srgb,var(--b3-swipe-color) 55%,var(--b3-color-muted,#888));}
|
|
10
|
+
.b3-swipe-action[data-side=right]{justify-content:flex-end;--b3-swipe-color:var(--b3-swipe-right-color,var(--b3-color-accent,#276bdd));}
|
|
11
|
+
.b3-swipe-action[data-go]{background:var(--b3-swipe-color);}
|
|
12
|
+
`;class k extends C{static observedAttributes=["disabled"];#e=null;#t=null;get edge(){return Number(this.getAttribute("edge"))||0}get threshold(){return Number(this.getAttribute("threshold"))||0}get hold(){let e=this.getAttribute("hold");return e===null?500:Number(e)||0}connectedCallback(){T(this.ownerDocument,W,_),this.#e=new AbortController;let e=this.#e.signal;this.addEventListener("pointerdown",(t)=>this.#n(t),{signal:e}),this.addEventListener("touchmove",(t)=>{if(this.hasAttribute("data-b3-dragging")&&t.cancelable)t.preventDefault()},{signal:e,passive:!1})}disconnectedCallback(){this.#t?.(),this.#e?.abort(),this.#e=null}attributeChangedCallback(){if(this.hasAttribute("disabled"))this.#t?.()}cancel(){this.#t?.()}#n(e){if(e.pointerType==="mouse"||!e.isPrimary||this.hasAttribute("disabled")||this.#t)return;let t=e.target.closest?.(M);if(!t||!this.contains(t))return;let s=this.ownerDocument.defaultView;if(this.edge&&(e.clientX<this.edge||e.clientX>s.innerWidth-this.edge))return;let{pointerId:o,clientX:l,clientY:d}=e,b=t.offsetWidth,f=this.threshold,y=f?f<=1?f*b:f:Math.max(110,b*0.4),h=null,r=0,g=!1,a=null,p=[[e.timeStamp,l]],v=new AbortController,w={signal:v.signal},S=()=>{let n=(i)=>{i.stopPropagation(),i.preventDefault()};s.addEventListener("click",n,{capture:!0,once:!0}),s.setTimeout(()=>s.removeEventListener("click",n,!0),Y)},u=(n)=>{if(v.abort(),s.clearTimeout(E),this.#t=null,this.removeAttribute("data-b3-dragging"),h!=="x")return;S();try{t.releasePointerCapture(o)}catch{}t.removeAttribute("data-b3-swiping"),t.style.background="",t.setAttribute("data-b3-swipe-back",""),t.style.transform="",s.setTimeout(()=>t.removeAttribute("data-b3-swipe-back"),200),a?.remove();let i=r<0?"left":"right";if(n&&t.hasAttribute(`data-b3-swipe-${i}`))t.dispatchEvent(new CustomEvent("b3-swipe",{bubbles:!0,detail:{side:i,item:t}}))};this.#t=()=>u(!1);let E=this.hold?s.setTimeout(()=>{if(h)return;u(!1),S(),t.dispatchEvent(new CustomEvent("b3-swipe-hold",{bubbles:!0,detail:{item:t,x:l,y:d}}))},this.hold):0,I=()=>{let n=r<0?"left":"right",i=t.getAttribute(`data-b3-swipe-${n}`),c=Math.abs(r);if(g=!!i&&(g?c>=y-P:c>=y),t.style.transform=`translateX(${i?r:r/4}px)`,!a)a=this.ownerDocument.createElement("div"),a.className="b3-swipe-action",a.style.cssText=`top:${t.offsetTop}px;height:${t.offsetHeight}px`,t.before(a);let m=Math.abs(i?r:r/4);a.style.left=`${t.offsetLeft+(r<0?b-m:0)}px`,a.style.width=`${m}px`,a.dataset.side=n,a.textContent=i||"",a.toggleAttribute("data-go",g)};s.addEventListener("pointermove",(n)=>{if(n.pointerId!==o)return;r=n.clientX-l;let i=n.clientY-d;p.push([n.timeStamp,n.clientX]);while(p.length>2&&n.timeStamp-p[0][0]>100)p.shift();if(!h){if(Math.hypot(r,i)<X)return;if(s.clearTimeout(E),Math.abs(i)>=Math.abs(r))return h="y",u(!1);if(!t.hasAttribute("data-b3-swipe-left")&&!t.hasAttribute("data-b3-swipe-right"))return u(!1);h="x",this.setAttribute("data-b3-dragging",""),t.setAttribute("data-b3-swiping","");let c=s.getComputedStyle(t).backgroundColor;t.style.background=`linear-gradient(${c},${c}),var(--b3-swipe-surface,var(--b3-color-canvas,#fff))`;try{t.setPointerCapture(o)}catch{}}I()},w),s.addEventListener("pointerup",(n)=>{if(n.pointerId!==o)return;let i=p.filter(([H])=>n.timeStamp-H<=100),[c,m]=i[0]??[n.timeStamp,n.clientX],x=n.timeStamp-c,A=x>0?(n.clientX-m)/x:0,D=Math.abs(r)>=B&&Math.abs(A)>=N&&Math.sign(A)===Math.sign(r);u(g||D)},w),s.addEventListener("pointercancel",(n)=>{if(n.pointerId===o)u(!1)},w)}}L("b3-swipe",k);export{k as B3Swipe};
|
package/dist/manifest.json
CHANGED
package/dist/references/swipe.md
CHANGED
|
@@ -23,7 +23,7 @@ Touch and pen only; a mouse never swipes, so always offer the same actions as bu
|
|
|
23
23
|
| `hold` | Still-press ms that fires `b3-swipe-hold`; `0` disables. Default 500. |
|
|
24
24
|
| `disabled` | No swipes (e.g. while the list is in select mode). |
|
|
25
25
|
|
|
26
|
-
Colours: `--b3-swipe-left-color`, `--b3-swipe-right-color` (
|
|
26
|
+
Colours: `--b3-swipe-left-color`, `--b3-swipe-right-color` (strong once the pull will commit, muted before). The dragged row is painted opaque (its own background over `--b3-swipe-surface`, default the canvas), so a translucent selection tint never shows the action through it.
|
|
27
27
|
The action panel is positioned by the row's `offsetTop`, so give the rows' container `position: relative`.
|
|
28
28
|
|
|
29
29
|
Events (bubble from the row): `b3-swipe` `{ side: 'left'|'right', item }` when a pull commits;
|