siegel
Version:
Web application development ecosystem
1 lines • 1.19 kB
JavaScript
import e,{useLayoutEffect as t}from"react";import n from"../_internals/resolve_tag_attributes.js";import o from"../_internals/component.js";import r from"../../utils/is_touchscreen/index.js";import s from"../_internals/ref_apply.js";let i="-ui-swipe",m=r(),a={passive:!0};function u(e,t){let{touches:n,x:o,y:r}=e;return m?t?n[0].screenX:n[0].screenY:t?o:r}let v=o(i,{deltaPos:60},o=>{let r,{className:i,children:v,xAxis:p,deltaPos:c,rootTagAttributes:d,onSwipe:l,onTouchStart:f,onMouseDown:E}=o,L={className:i,children:v};function h(e){if(m?f?.(e):E?.(e),!e.defaultPrevented){e.stopPropagation();let o=u(e.nativeEvent,p),s=!0,i=!1;function t(e){e.stopPropagation(),s=!1,i=!1,r()}function n(e){if(o&&s&&!i){let t=u(e,p)-o;Math.abs(t)>c&&(l(t<0,e),i=!0)}}m?(addEventListener("touchend",t,a),addEventListener("touchmove",n,a)):(addEventListener("mouseup",t,a),addEventListener("mousemove",n,a)),r=()=>{m?(removeEventListener("touchend",t),removeEventListener("touchmove",n)):(removeEventListener("mouseup",t),removeEventListener("mousemove",n))}}}return m?L.onTouchStart=h:L.onMouseDown=h,s(L,o),L=n(L,d),t(()=>{r?.()},[]),e.createElement("div",{...L})});export default v;export{i as componentID};