ray-template/assets/utils-bL-oQI6P.js

2 lines
8.1 KiB
JavaScript

import{A as y,u as A,a as x,b as v}from"./hooks-v5yhfgkQ.js";import{c as l}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 _}from"./lodash-es@4.17.21-xgd1l9mE.js";var m=(e=>(e.Windows="Windows",e.MacOS="MacOS",e.Linux="Linux",e.Android="Android",e.IOS="IOS",e.Unknown="Unknown",e))(m||{}),I={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 K=()=>I,P=(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)},h=(e,t)=>Object.prototype.toString.call(e).includes(t),M=(e=16,t=62)=>{const r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),o=[],s=window.crypto||window.msCrypto;let n=0;for(n=0;n<e;n++){const i=new Uint32Array(1);s.getRandomValues(i);const a=i[0]%t;o.push(r[a])}return o.join("")},X=(e,t)=>new Promise((r,o)=>{let s;try{if(typeof e=="string")return P(e,t),r();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 o(new Error("downloadAnyFile: Unsupported data type."));const n=URL.createObjectURL(s),i=document.createElement("a");i.href=n,i.download=t,i.style.display="none";const a=()=>{URL.revokeObjectURL(n),document.body.removeChild(i)};i.addEventListener("load",()=>(a(),r())),i.addEventListener("error",c=>(a(),o(c))),document.body.appendChild(i),i.click()}catch(n){return o(n)}});function k(e,t){if(!e)return console.warn(`[omit]: The targetObject is expected to be an object, but got ${e}.`),{};const r=Array.isArray(t)?t:[t];return r.length&&r.forEach(o=>{delete e[o]}),e}function J(e,t){if(!e)return console.warn(`[pick]: The targetObject is expected to be an object, but got ${e}.`),{};const r=Array.isArray(t)?t:[t];return r.length?r.reduce((s,n)=>(Reflect.has(e,n)&&(s[n]=e[n]),s),{}):e}const Y=()=>{const e=navigator.userAgent;return/windows/i.test(e)?m.Windows:/macintosh|mac os x/i.test(e)?m.MacOS:/linux/i.test(e)?m.Linux:/android/i.test(e)?m.Android:/iphone|ipad|ipod/i.test(e)?m.IOS:m.Unknown},G=(e,t)=>{const r=e.endsWith("/"),o=t.endsWith("/");return r&&o?e.slice(0,-1)===t.slice(0,-1):!r&&!o?e===t:e===t||e.slice(0,-1)===t||e===t.slice(0,-1)};function H(e,t="sessionStorage",r){const{prefix:o,prefixKey:s}=r??{},n=o?s||y:"",i=t==="localStorage"?window.localStorage:window.sessionStorage;return!!Object.keys(i).find(a=>a===n+e)}function Q(e,t,r="sessionStorage",o){if(!e){console.error(`[setStorage]: Failed to set stored data: key ${e} is empty`);return}const{prefix:s,prefixKey:n}=o??{},i=s?n||y:"";try{const a=JSON.stringify(t);r==="localStorage"?window.localStorage.setItem(i+e,a):window.sessionStorage.setItem(i+e,a)}catch(a){console.error(`[setStorage]: Failed to set stored data for key '${e}'`,a)}}function Z(e,t="sessionStorage",r){const{prefix:o,prefixKey:s,defaultValue:n}=r??{},i=o?s||y:"";try{const a=t==="localStorage"?window.localStorage.getItem(i+e):window.sessionStorage.getItem(i+e);return a===null?n??null:JSON.parse(a)}catch(a){return console.error(`[getStorage]: Failed to get stored data for key '${e}'`,a),n??null}}const z=(e,t,r)=>{if(!e){console.error(`[removeStorage]: Failed to remove stored data: key ${e} is empty or undefined`);return}const{prefix:o,prefixKey:s}=r??{},n=o?s||y:"",i=Object.keys(window.localStorage),a=Object.keys(window.sessionStorage),c=(g,p)=>{(g?[...a,...i]:p==="localStorage"?i:a).forEach(d=>{e==="__all__"?(window.sessionStorage.removeItem(n+d),window.localStorage.removeItem(n+d)):p==="localStorage"?window.localStorage.removeItem(n+d):window.sessionStorage.removeItem(n+d)})};switch(e){case"__all__":c(!0);break;case"__all_sessionStorage__":c(!1,"sessionStorage");break;case"__all_localStorage__":c(!1,"localStorage");break;default:t==="localStorage"?window.localStorage.removeItem(n+e):window.sessionStorage.removeItem(n+e);break}},N=(e,t)=>{var n;const{domToImageOptions:r,printOptions:o}=t??{},{create:s}=x(e,r);window==null||window.$loadingBar.start(),(n=s("jpeg"))==null||n.then(i=>{const{print:a}=A(i,{type:"image",base64:!0,targetStyles:["*"],...k(o,["type","base64"])});a()}).catch(()=>{window==null||window.$loadingBar.error()}).finally(()=>{window==null||window.$loadingBar.finish()})},ee=(e,t)=>{const r=()=>{const s=f(e);s&&(typeof t=="string"?t.trim().split(" "):t).forEach(i=>{i&&s.classList.add(i)})},o=Vue.watch(()=>f(e),r,{immediate:!0});w(o)},te=(e,t)=>{const r=()=>{const s=f(e);if(s)if(t==="removeAllClass"){const n=s.classList;n.forEach(i=>n.remove(i))}else(typeof t=="string"?t.trim().split(" "):t).forEach(i=>{i&&s.classList.remove(i)})},o=Vue.watch(()=>f(e),r,{immediate:!0});w(o)},re=(e,t)=>{const r=Vue.ref(!1),o=()=>{const n=f(e);if(!n)r.value=!1;else{const i=n.className,a=typeof t=="string"?t.trim().split(" ").filter(c=>c!==""):t;r.value=a.some(c=>i.includes(c))}},s=Vue.watch(()=>f(e),o,{immediate:!0});return w(s),r},C=e=>{const t=["webkit","moz","ms","o"],r={};return t.forEach(o=>{r[`${o}${e.charAt(0).toUpperCase()}${e.slice(1)}`]=e}),r},ne=(e,t)=>{const r=(n,i)=>{n.split(";").forEach(a=>{const[c,g]=a.split(":");if(c&&g){const p=c.trim(),b=g.trim();if(c.startsWith("--"))i.style.setProperty(p,b);else{const d=C(p);Object.keys(d).forEach(E=>{i.style[E]=d[E]}),i.style[p]=b}}})},o=()=>{const n=f(e);n&&(h(t,"String")?r(t,n):h(t,"Array")?t.forEach(i=>{r(i,n)}):Object.keys(t).forEach(a=>{r(`${a}: ${t[a]}`,n)}))},s=Vue.watch(()=>f(e),o,{immediate:!0});w(s)},oe=(e,t=1)=>{const r=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i,o=/^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 n;if(r.test(e)){const i=e.substring(1);n="rgb("+[parseInt(i.substring(0,2),16),parseInt(i.substring(2,4),16),parseInt(i.substring(4,6),16)].join(", ")+")"}else return o.test(e)||s.test(e),e;return n&&!n.startsWith("rgba")&&(n=n.replace("rgb","rgba").replace(")",`, ${t})`)),n},se=(e,t)=>{const{defaultElement:r}=t||{};if(!e)return r?[r]:null;const o=e.startsWith("attr:")?`[${e.replace("attr:","")}]`:e;try{return Array.from(document.querySelectorAll(o))}catch(s){return console.error(`[queryElements]: Failed to get elements for selector '${e}'`,s),r?[r]:null}},ie=(e,t="px")=>typeof e=="number"?e.toString()+t:h(e,"String")&&v.cssUnit.test(e)?e:e+t,u={precision:8,decimal:"."},S=(e,t,r)=>e!=null&&e.length?e.length===1?l(e[0],u):e.reduce((s,n,i,a)=>(s=r==null?void 0:r(s,n,i,a),s),t):0,R=(e,t,r="number")=>{const o=Object.assign({},u,t),s=l(e,o);return r==="number"?s.value:s.toString()},ae=(...e)=>e.length===1?l(e[0],u).add(0):S(e,0,(t,r)=>l(t,u).add(r)),ce=(...e)=>{if(e.length===1)return l(e[0],u).subtract(0);if(e.length===2){const[o,s]=e;return l(o,u).subtract(s)}const t=_(e),r=t.shift();return t.length?S(t,r,(o,s)=>l(o,u).subtract(s)):r},le=(...e)=>e.length===1?l(e[0],u).multiply(1):S(e,1,(t,r)=>l(t,u).multiply(r)),ue=(...e)=>{if(e.length===1)return l(e[0],u).divide(1);if(e.length===2){const[o,s]=e;return l(o,u).divide(s)}const t=_(e),r=t.shift();return S(t,r,(o,s)=>l(o,u).divide(s))},fe=(e,t)=>t<=1?[e||0]:e?l(e,u).distribute(t).map(o=>R(o)):new Array(t).fill(0);function $(e,...t){if(Array.isArray(e))e.forEach(r=>$(r,...t));else return e(...t)}function f(e,t){var o;if(!e)return t;let r;return typeof e=="function"?r=e():Vue.isRef(e)?r=((o=e.value)==null?void 0:o.$el)??e.value:r=e,r}function de(e,t){if(!e){const{defaultElement:r=null}=t??{};return typeof r=="function"?r:()=>r}if(typeof e=="string"||h(e,"Object"))return()=>e;if(typeof e=="function")return e}function w(e){return Vue.getCurrentScope()?(Vue.onScopeDispose(e),!0):!1}function me(e,t){const r=Vue.watchEffect(e,t);w(r)}export{fe as A,ae as B,ce as C,le as D,ue as E,ie as a,$ as b,oe as c,P as d,X as e,J as f,Z as g,G as h,h as i,z as j,K as k,te as l,ee as m,Y as n,re as o,N as p,se as q,de as r,Q as s,w as t,M as u,f as v,me as w,ne as x,H as y,R as z};