UNPKG

@hopeio/utils

Version:
2 lines (1 loc) 5.01 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./message-Bj8PdpuH.js"),f=require("@vueuse/core"),a=require("@pureadmin/utils"),T={mounted(e,t){const{value:n}=t;if(n){e.copyValue=n;const o=t.arg??"dblclick";f.useEventListener(e,o,()=>{a.copyTextToClipboard(e.copyValue)?h.message("复制成功",{type:"success"}):h.message("复制失败",{type:"error"})})}else throw new Error('[Directive: copy]: need value! Like v-copy="modelValue"')},updated(e,t){e.copyValue=t.value}},N={mounted(e,t){var o;const n=t.value;if(n&&a.isFunction(n)){let s=null,i=null,r=500,c=null;const u=((o=t==null?void 0:t.arg)==null?void 0:o.includes(":"))??!1;u?(r=Number(a.subBefore(t.arg,":")),c=Number(a.subAfter(t.arg,":"))):t.arg&&(r=Number(t.arg));const l=()=>{s&&(clearTimeout(s),s=null),i&&(clearInterval(i),i=null)},m=p=>{p.preventDefault(),i===null&&(i=setInterval(()=>n(),c))},d=p=>{l(),p.preventDefault(),s===null&&(s=setTimeout(u?()=>{n(),m(p)}:()=>n(),r))};f.useEventListener(e,"pointerdown",d),f.useEventListener(e,"pointerup",l),f.useEventListener(e,"pointerleave",l)}else throw new Error('[Directive: longpress]: need callback and callback must be a function! Like v-longpress="callback"')}},$={mounted(e,t){const{value:n}=t,o=t.arg??"debounce",s=["debounce","throttle"].find(i=>i===o);if(s)if(n&&n.event&&a.isFunction(n.fn)){let i=n==null?void 0:n.params;if(i)if(a.isArray(i)||a.isObject(i))i=a.isObject(i)?Array.of(i):i;else throw new Error("[Directive: optimize]: `params` must be an array or object");f.useEventListener(e,n.event,s==="debounce"?a.debounce(i?()=>n.fn(...i):n.fn,(n==null?void 0:n.timeout)??200,(n==null?void 0:n.immediate)??!1):a.throttle(i?()=>n.fn(...i):n.fn,(n==null?void 0:n.timeout)??1e3))}else throw new Error("[Directive: optimize]: `event` and `fn` are required, and `fn` must be a function");else throw new Error("[Directive: optimize]: only `debounce` and `throttle` are supported")}};function y(e,t){e.style.transform=t,e.style.webkitTransform=t}const x=(e,t,n={})=>{var p;const o=t.getBoundingClientRect();let s=e.clientX-o.left,i=e.clientY-o.top,r=0,c=.3;(p=t._ripple)!=null&&p.circle?(c=.15,r=t.clientWidth/2,r=n.center?r:r+Math.sqrt((s-r)**2+(i-r)**2)/4):r=Math.sqrt(t.clientWidth**2+t.clientHeight**2)/2;const u=`${(t.clientWidth-r*2)/2}px`,l=`${(t.clientHeight-r*2)/2}px`,m=n.center?u:`${s-r}px`,d=n.center?l:`${i-r}px`;return{radius:r,scale:c,x:m,y:d,centerX:u,centerY:l}},v={show(e,t,n={}){var _;if(!((_=t==null?void 0:t._ripple)!=null&&_.enabled))return;const o=document.createElement("span"),s=document.createElement("span");o.appendChild(s),o.className="v-ripple__container",n.class&&(o.className+=` ${n.class}`);const{radius:i,scale:r,x:c,y:u,centerX:l,centerY:m}=x(e,t,n),d=`${i*2}px`;s.className="v-ripple__animation",s.style.width=d,s.style.height=d,t.appendChild(o);const p=window.getComputedStyle(t);p&&p.position==="static"&&(t.style.position="relative",t.dataset.previousPosition="static"),s.classList.add("v-ripple__animation--enter"),s.classList.add("v-ripple__animation--visible"),y(s,`translate(${c}, ${u}) scale3d(${r},${r},${r})`),s.dataset.activated=String(performance.now()),setTimeout(()=>{s.classList.remove("v-ripple__animation--enter"),s.classList.add("v-ripple__animation--in"),y(s,`translate(${l}, ${m}) scale3d(1,1,1)`)},0)},hide(e){var i;if(!((i=e==null?void 0:e._ripple)!=null&&i.enabled))return;const t=e.getElementsByClassName("v-ripple__animation");if(t.length===0)return;const n=t[t.length-1];if(n.dataset.isHiding)return;n.dataset.isHiding="true";const o=performance.now()-Number(n.dataset.activated),s=Math.max(250-o,0);setTimeout(()=>{n.classList.remove("v-ripple__animation--in"),n.classList.add("v-ripple__animation--out"),setTimeout(()=>{var c;e.getElementsByClassName("v-ripple__animation").length===1&&e.dataset.previousPosition&&(e.style.position=e.dataset.previousPosition,delete e.dataset.previousPosition),((c=n.parentNode)==null?void 0:c.parentNode)===e&&e.removeChild(n.parentNode)},300)},s)}};function w(e){return typeof e>"u"||!!e}function b(e){const t={},n=e.currentTarget;!(n!=null&&n._ripple)||n._ripple.touched||(t.center=n._ripple.centered,n._ripple.class&&(t.class=n._ripple.class),v.show(e,n,t))}function g(e){const t=e.currentTarget;t!=null&&t._ripple&&(window.setTimeout(()=>{t._ripple&&(t._ripple.touched=!1)}),v.hide(t))}function E(e,t,n){const{value:o,modifiers:s}=t,i=w(o);i||v.hide(e),e._ripple=e._ripple??{},e._ripple.enabled=i,e._ripple.centered=s.center,e._ripple.circle=s.circle,a.isObject(o)&&o.class&&(e._ripple.class=o.class),i&&!n?(e.addEventListener("pointerdown",b),e.addEventListener("pointerup",g)):!i&&n&&L(e)}function L(e){e.removeEventListener("pointerdown",b),e.removeEventListener("pointerup",g)}function D(e,t){E(e,t,!1)}function C(e){delete e._ripple,L(e)}function k(e,t){if(t.value===t.oldValue)return;const n=w(t.oldValue);E(e,t,n)}const z={mounted:D,unmounted:C,updated:k};exports.Ripple=z;exports.copy=T;exports.longpress=N;exports.optimize=$;