ray-template/assets/utils-9KNp0Hl_.js

2 lines
7.4 KiB
JavaScript

import{A as h,u as _,a as A,b as E}from"./hooks-caxx0fQA.js";import{c}from"./currency.js@2.0.4--or6eeOG.js";import"./dayjs@1.11.10-A-QuG2Ol.js";import"./awesome-qr@2.1.5-rc.0-UnPo3EFD.js";import"./vue-hooks-plus@1.8.5_vue@3.4.15-UGgZVZ2w.js";import"./lodash@4.17.21-yUHHMES2.js";import"./js-cookie@3.0.5-bc0KQLgp.js";import"./screenfull@5.2.0-q9gEF-YC.js";import"./qs@6.11.2-wwOruwhc.js";import"./print-js@1.6.0-gYKv6oGQ.js";import{c as b}from"./lodash-es@4.17.21-xgd1l9mE.js";var f=(e=>(e.Windows="Windows",e.MacOS="MacOS",e.Linux="Linux",e.Android="Android",e.IOS="IOS",e.Unknown="Unknown",e))(f||{}),v={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 W=()=>v,I=(e,r)=>{const t=document.createElement("a");t.href=e,t.download=r,t.style.display="none",document.body.appendChild(t),t.click(),document.body.removeChild(t)},y=(e,r)=>Object.prototype.toString.call(e).includes(r),q=(e=16,r=62)=>{const t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),n=[],s=window.crypto||window.msCrypto;let i=0;for(i=0;i<e;i++){const o=new Uint32Array(1);s.getRandomValues(o);const a=o[0]%r;n.push(t[a])}return n.join("")},M=(e,r)=>new Promise((t,n)=>{let s;try{if(typeof e=="string")return I(e,r),t();if(e instanceof ArrayBuffer)s=new Blob([new Uint8Array(e)],{type:"application/octet-stream"});else if(e instanceof File||e instanceof Blob)s=e;else return n(new Error("downloadAnyFile: Unsupported data type."));const i=URL.createObjectURL(s),o=document.createElement("a");o.href=i,o.download=r,o.style.display="none";const a=()=>{URL.revokeObjectURL(i),document.body.removeChild(o)};o.addEventListener("load",()=>(a(),t())),o.addEventListener("error",u=>(a(),n(u))),document.body.appendChild(o),o.click()}catch(i){return n(i)}}),x=(e,r)=>{if(!e)return{};const t=Array.isArray(r)?r:[r];return t.length&&t.forEach(n=>{delete e[n]}),e},K=(e,r)=>{if(!e)return{};const t=Array.isArray(r)?r:[r],n={};return t.length&&t.forEach(s=>{n[s]=e[s]}),n},N=()=>{const e=navigator.userAgent;return/windows/i.test(e)?f.Windows:/macintosh|mac os x/i.test(e)?f.MacOS:/linux/i.test(e)?f.Linux:/android/i.test(e)?f.Android:/iphone|ipad|ipod/i.test(e)?f.IOS:f.Unknown};function X(e,r="sessionStorage",t){const{prefix:n,prefixKey:s}=t??{},i=n?s||h:"",o=r==="localStorage"?window.localStorage:window.sessionStorage;return!!Object.keys(o).find(a=>a===i+e)}function J(e,r,t="sessionStorage",n){if(!e){console.error(`[setStorage]: Failed to set stored data: key ${e} is empty`);return}const{prefix:s,prefixKey:i}=n??{},o=s?i||h:"";try{const a=JSON.stringify(r);t==="localStorage"?window.localStorage.setItem(o+e,a):window.sessionStorage.setItem(o+e,a)}catch(a){console.error(`[setStorage]: Failed to set stored data for key '${e}'`,a)}}function Y(e,r="sessionStorage",t){const{prefix:n,prefixKey:s,defaultValue:i}=t??{},o=n?s||h:"";try{const a=r==="localStorage"?window.localStorage.getItem(o+e):window.sessionStorage.getItem(o+e);return a===null?i??null:JSON.parse(a)}catch(a){return console.error(`[getStorage]: Failed to get stored data for key '${e}'`,a),i??null}}const G=(e,r,t)=>{if(!e){console.error(`[removeStorage]: Failed to remove stored data: key ${e} is empty or undefined`);return}const{prefix:n,prefixKey:s}=t??{},i=n?s||h:"",o=Object.keys(window.localStorage),a=Object.keys(window.sessionStorage),u=(p,w)=>{(p?[...a,...o]:w==="localStorage"?o:a).forEach(g=>{e==="__all__"?(window.sessionStorage.removeItem(i+g),window.localStorage.removeItem(i+g)):w==="localStorage"?window.localStorage.removeItem(i+g):window.sessionStorage.removeItem(i+g)})};switch(e){case"__all__":u(!0);break;case"__all_sessionStorage__":u(!1,"sessionStorage");break;case"__all_localStorage__":u(!1,"localStorage");break;default:r==="localStorage"?window.localStorage.removeItem(i+e):window.sessionStorage.removeItem(i+e);break}},H=(e,r)=>{var i;const{domToImageOptions:t,printOptions:n}=r??{},{create:s}=A(e,t);window==null||window.$loadingBar.start(),(i=s("jpeg"))==null||i.then(o=>{const{print:a}=_(o,{type:"image",base64:!0,targetStyles:["*"],...x(n,["type","base64"])});a()}).catch(()=>{window==null||window.$loadingBar.error()}).finally(()=>{window==null||window.$loadingBar.finish()})},Q=(e,r)=>{const t=()=>{const s=d(e);s&&r.trim().split(" ").forEach(o=>{o&&s.classList.add(o)})},n=Vue.watch(()=>d(e),t,{immediate:!0});m(n)},Z=(e,r)=>{const t=()=>{const s=d(e);if(s)if(r==="removeAllClass"){const i=s.classList;i.forEach(o=>i.remove(o))}else r.trim().split(" ").forEach(o=>{o&&s.classList.remove(o)})},n=Vue.watch(()=>d(e),t,{immediate:!0});m(n)},z=(e,r)=>{const t=Vue.ref(!1),n=()=>{const i=d(e);if(!i)t.value=!1;else{const o=i.className,a=r.trim().split(" ").filter(u=>u!=="");t.value=o.includes(a.join(" "))}},s=Vue.watch(()=>d(e),n,{immediate:!0});return m(s),t},ee=(e,r)=>{let t;const n=()=>{const i=d(e);i&&(y(r,"String")?t=r.split(";").reduce((o,a)=>{const[u,p]=a.split(":").map(w=>w.trim());return u&&p&&(o[u]=p),o},{}):t=r,Object.keys(t).forEach(o=>{const a=t[o];o in i.style&&(i.style[o]=a)}))},s=Vue.watch(()=>d(e),n,{immediate:!0});m(s)},te=(e,r=1)=>{const t=/^#([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,s=/^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d*(?:\.\d+)?)\)$/i;let i;if(t.test(e)){const o=e.substring(1);i="rgb("+[parseInt(o.substring(0,2),16),parseInt(o.substring(2,4),16),parseInt(o.substring(4,6),16)].join(", ")+")"}else return n.test(e)||s.test(e),e;return i&&!i.startsWith("rgba")&&(i=i.replace("rgb","rgba").replace(")",`, ${r})`)),i},re=e=>{if(!e)return null;const r=e.startsWith("attr:")?`[${e.replace("attr:","")}]`:e;try{return Array.from(document.querySelectorAll(r))}catch(t){return console.error(`Failed to get elements for selector '${e}'`,t),null}},ne=(e,r="px")=>typeof e=="number"?e.toString()+r:y(e,"String")&&E.cssUnit.test(e)?e:e+r,l={precision:8,decimal:"."},S=(e,r,t)=>e!=null&&e.length?e.length===1?c(e[0],l):e.reduce((s,i,o,a)=>(s=t==null?void 0:t(s,i,o,a),s),r):0,C=(e,r,t="number")=>{const n=Object.assign({},l,r),s=c(e,n);return t==="number"?s.value:s.toString()},oe=(...e)=>e.length===1?c(e[0],l).add(0):S(e,0,(r,t)=>c(r,l).add(t)),se=(...e)=>{if(e.length===1)return c(e[0],l).subtract(0);if(e.length===2){const[n,s]=e;return c(n,l).subtract(s)}const r=b(e),t=r.shift();return r.length?S(r,t,(n,s)=>c(n,l).subtract(s)):t},ie=(...e)=>e.length===1?c(e[0],l).multiply(1):S(e,1,(r,t)=>c(r,l).multiply(t)),ae=(...e)=>{if(e.length===1)return c(e[0],l).divide(1);if(e.length===2){const[n,s]=e;return c(n,l).divide(s)}const r=b(e),t=r.shift();return S(r,t,(n,s)=>c(n,l).divide(s))},ce=(e,r)=>r<=1?[e||0]:e?c(e,l).distribute(r).map(n=>C(n)):new Array(r).fill(0);function P(e,...r){if(Array.isArray(e))e.forEach(t=>P(t,...r));else return e(...r)}function d(e,r){var n;if(!e)return r;let t;return typeof e=="function"?t=e():Vue.isRef(e)?t=((n=e.value)==null?void 0:n.$el)??e.value:t=e,t}function le(e,r){if(!e){const{defaultElement:t=null}=r??{};return typeof t=="function"?t:()=>t}if(typeof e=="string"||y(e,"Object"))return()=>e;if(typeof e=="function")return e}function m(e){return Vue.getCurrentScope()?(Vue.onScopeDispose(e),!0):!1}function ue(e,r){const t=Vue.watchEffect(e,r);m(t)}export{oe as A,se as B,ie as C,ae as D,ne as a,P as b,te as c,I as d,M as e,K as f,Y as g,G as h,y as i,W as j,Z as k,Q as l,N as m,z as n,m as o,H as p,re as q,le as r,J as s,d as t,q as u,ee as v,ue as w,X as x,C as y,ce as z};