ray-template/assets/utils-HNbFOS7v.js
XiaoDaiGua-Ray 7073b242a1 v4.4.0
2023-11-25 11:43:33 +08:00

2 lines
6.0 KiB
JavaScript

import{p as y}from"./print-js@1.6.0-gYKv6oGQ.js";import{c as g}from"./lodash-es@4.17.21-B0eCOOcg.js";import{c as i}from"./currency.js@2.0.4--or6eeOG.js";function L(e,t,r="sessionStorage"){if(!e){console.error("Failed to set stored data: key is empty or undefined");return}try{const n=JSON.stringify(t);r==="localStorage"?window.localStorage.setItem(e,n):window.sessionStorage.setItem(e,n)}catch(n){console.error(`Failed to set stored data for key '${e}'`,n)}}function I(e,t="sessionStorage",r){try{const n=t==="localStorage"?window.localStorage.getItem(e):window.sessionStorage.getItem(e);return n===null?r??null:JSON.parse(n)}catch(n){return console.error(`Failed to get stored data for key '${e}'`,n),r??null}}function _(e,t="sessionStorage"){switch(e){case"all":window.window.localStorage.clear(),window.sessionStorage.clear();break;case"all-sessionStorage":window.sessionStorage.clear();break;case"all-localStorage":window.localStorage.clear();break;default:if(!e){console.error("Failed to remove stored data: key is empty or undefined");return}t==="localStorage"?window.localStorage.removeItem(e):window.sessionStorage.removeItem(e)}}function b(e,...t){if(Array.isArray(e))e.forEach(r=>b(r,...t));else return e(...t)}function l(e,t){var n;if(!e)return t;let r;return typeof e=="function"?r=e():Vue.isRef(e)?r=((n=e.value)==null?void 0:n.$el)??e.value:r=e,r}function F(e,t){if(!e){const{defaultElement:r=null}=t??{};return typeof r=="function"?r:()=>r}if(typeof e=="string"||p(e,"Object"))return()=>e;if(typeof e=="function")return e}function S(e){return Vue.getCurrentScope()?(Vue.onScopeDispose(e),!0):!1}function u(e,t){const r=Vue.watchEffect(e,t);S(r)}var E={VITE_APP_URL:"/",VITE_APP_OFFICE_PROXY_URL:"https://office.yka.one/",VITE_APP_OFFICE_SCRIPT_URL:"https://office.yka.one/web-apps/apps/api/documents/api.js",BASE_URL:"/ray-template/",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const U=()=>E,V=(e,t)=>{const r=document.createElement("a");r.href=e,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)},p=(e,t)=>Object.prototype.toString.call(e).includes(t),j=(e=16,t=62)=>{const r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),n=[],c=window.crypto||window.msCrypto;let s=0;for(s=0;s<e;s++){const o=new Uint32Array(1);c.getRandomValues(o);const a=o[0]%t;n.push(r[a])}return n.join("")},x=(e,t)=>new Promise((r,n)=>{let c;try{if(typeof e=="string"){V(e,t),r();return}if(e instanceof ArrayBuffer)c=new Blob([new Uint8Array(e)],{type:"application/octet-stream"});else if(e instanceof File||e instanceof Blob)c=e;else{n(new Error("downloadAnyFile: Unsupported data type."));return}const s=URL.createObjectURL(c),o=document.createElement("a");o.href=s,o.download=t,o.style.display="none";const a=()=>{URL.revokeObjectURL(s),document.body.removeChild(o)};o.addEventListener("load",()=>{a(),r()}),o.addEventListener("error",d=>{a(),n(d)}),document.body.appendChild(o),o.click()}catch(s){n(s)}});function $(e,t){const r=Vue.computed(()=>l(e)),{printable:n,...c}=t??{},s=a=>{y({...c,printable:a})},o=Vue.watch(r,a=>s(a),{immediate:!0});u(o)}const v={validCSSUnit:/^\d+(\.\d+)?(px|em|rem|%|vw|vh|vmin|vmax|cm|mm|in|pt|pc|ch|ex|q|s|ms|deg|rad|turn|grad|hz|khz|dpi|dpcm|dppx|fr|auto)$/},D=(e,t,r,n=!1)=>{const c=Vue.computed(()=>l(e,window)),s=a=>{a&&t&&r&&a.addEventListener(t,r,n)},o=Vue.watch(c,a=>s(a),{immediate:!0});u(o)},k=(e,t,r,n=!1)=>{const c=Vue.computed(()=>l(e,window)),s=a=>{a&&t&&r&&a.removeEventListener(t,r,n)},o=Vue.watch(c,a=>s(a),{immediate:!0});u(o)},O=(e,t)=>{const r=Vue.computed(()=>l(e)),n=s=>{s&&t.trim().split(" ").forEach(a=>{a&&s.classList.add(a)})},c=Vue.watch(r,s=>n(s),{immediate:!0});u(c)},T=(e,t)=>{const r=Vue.computed(()=>l(e)),n=s=>{if(s)if(t==="removeAllClass"){const o=s.classList;o.forEach(a=>o.remove(a))}else t.trim().split(" ").forEach(a=>{a&&s.classList.remove(a)})},c=Vue.watch(r,s=>n(s),{immediate:!0});u(c)},B=(e,t)=>{const r=Vue.computed(()=>l(e)),n=Vue.ref(!1),c=o=>{if(!o)n.value=!1;else{const a=o.className,d=t.trim().split(" ").filter(f=>f!=="");n.value=a.includes(d.join(" "))}},s=Vue.watch(r,o=>c(o),{immediate:!0});return u(s),n},q=(e,t)=>{const r=Vue.computed(()=>l(e));let n;const c=o=>{o&&(p(t,"String")?n=t.split(";").reduce((a,d)=>{const[f,w]=d.split(":").map(h=>h.trim());return f&&w&&(a[f]=w),a},{}):n=t,Object.keys(n).forEach(a=>{const d=n[a];a in o.style&&(o.style[a]=d)}))},s=Vue.watch(r,o=>c(o),{immediate:!0});u(s)},J=(e,t)=>{const r=Vue.computed(()=>l(e)),n=s=>{s&&t.forEach(o=>{s.style.removeProperty(o)})},c=Vue.watch(r,s=>n(s),{immediate:!0});u(c)},N=(e,t=1)=>{const r=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i,n=/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/i,c=/^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d*(?:\.\d+)?)\)$/i;let s;if(r.test(e)){const o=e.substring(1);s="rgb("+[parseInt(o.substring(0,2),16),parseInt(o.substring(2,4),16),parseInt(o.substring(4,6),16)].join(", ")+")"}else n.test(e)||c.test(e),s=e;return s&&!s.startsWith("rgba")&&(s=s.replace("rgb","rgba").replace(")",`, ${t})`)),s},W=e=>{if(!e)return null;const t=e.startsWith("attr:")?`[${e.replace("attr:","")}]`:e;try{return Array.from(document.querySelectorAll(t))}catch(r){return console.error(`Failed to get elements for selector '${e}'`,r),null}},X=(e,t="px")=>typeof e=="number"?e.toString()+t:p(e,"String")&&v.validCSSUnit.test(e)?e:e+t,m=(e,t,r)=>e!=null&&e.length?e.length===1?i(e[0]):e.reduce((c,s,o,a)=>(c=r==null?void 0:r(c,s,o,a),c),t):0,A=(e,t,r="number")=>r==="number"?i(e,t).value:i(e,t).toString(),G=(...e)=>m(e,0,(t,r)=>i(t).add(r)),M=(...e)=>{if(e.length===2){const[n,c]=e;return i(n).subtract(c)}const t=g(e),r=t.shift();return t.length?m(t,r,(n,c)=>i(n).subtract(c)):r},Y=(...e)=>m(e,1,(t,r)=>i(t).multiply(r)),H=(...e)=>{if(e.length===2){const[n,c]=e;return i(n).divide(c)}const t=g(e),r=t.shift();return t.length?m(t,r,(n,c)=>i(n).divide(c)):r},K=(e,t,r)=>t<=1?[e||0]:e?i(e,r).distribute(t).map(c=>A(c,r)):new Array(t).fill(0);export{M as A,Y as B,H as C,q as a,U as b,X as c,F as d,b as e,V as f,I as g,k as h,p as i,j,x as k,T as l,O as m,B as n,D as o,$ as p,W as q,J as r,L as s,N as t,l as u,_ as v,u as w,A as x,K as y,G as z};