1 line
8.3 KiB
JavaScript
1 line
8.3 KiB
JavaScript
import{$ as e,H as t,O as n,U as r,V as i,_t as a,at as o,ct as s,ft as c,gt as l,it as u,lt as d,ot as f,st as p,ut as m,vt as h}from"./BasicIcon-CjTTsi6o.js";var g=typeof window<`u`,_,v=e=>_=e,y=Symbol();function b(e){return e&&typeof e==`object`&&Object.prototype.toString.call(e)===`[object Object]`&&typeof e.toJSON!=`function`}var x=typeof window==`object`&&window.window===window?window:typeof self==`object`&&self.self===self?self:typeof global==`object`&&global.global===global?global:typeof globalThis==`object`?globalThis:{HTMLElement:null};function S(e,{autoBom:t=!1}={}){return t&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob([``,e],{type:e.type}):e}function C(e,t,n){let r=new XMLHttpRequest;r.open(`GET`,e),r.responseType=`blob`,r.onload=function(){O(r.response,t,n)},r.onerror=function(){console.error(`could not download file`)},r.send()}function w(e){let t=new XMLHttpRequest;t.open(`HEAD`,e,!1);try{t.send()}catch{}return t.status>=200&&t.status<=299}function T(e){try{e.dispatchEvent(new MouseEvent(`click`))}catch{let t=new MouseEvent(`click`,{bubbles:!0,cancelable:!0,view:window,detail:0,screenX:80,screenY:20,clientX:80,clientY:20,ctrlKey:!1,altKey:!1,shiftKey:!1,metaKey:!1,button:0,relatedTarget:null});e.dispatchEvent(t)}}var E=typeof navigator==`object`?navigator:{userAgent:``},D=/Macintosh/.test(E.userAgent)&&/AppleWebKit/.test(E.userAgent)&&!/Safari/.test(E.userAgent),O=g?typeof HTMLAnchorElement<`u`&&`download`in HTMLAnchorElement.prototype&&!D?k:`msSaveOrOpenBlob`in E?A:j:()=>{};function k(e,t=`download`,n){let r=document.createElement(`a`);r.download=t,r.rel=`noopener`,typeof e==`string`?(r.href=e,r.origin===location.origin?T(r):w(r.href)?C(e,t,n):(r.target=`_blank`,T(r))):(r.href=URL.createObjectURL(e),setTimeout(function(){URL.revokeObjectURL(r.href)},4e4),setTimeout(function(){T(r)},0))}function A(e,t=`download`,n){if(typeof e==`string`)if(w(e))C(e,t,n);else{let t=document.createElement(`a`);t.href=e,t.target=`_blank`,setTimeout(function(){T(t)})}else navigator.msSaveOrOpenBlob(S(e,n),t)}function j(e,t,n,r){if(r||=open(``,`_blank`),r&&(r.document.title=r.document.body.innerText=`downloading...`),typeof e==`string`)return C(e,t,n);let i=e.type===`application/octet-stream`,a=/constructor/i.test(String(x.HTMLElement))||`safari`in x,o=/CriOS\/[\d]+/.test(navigator.userAgent);if((o||i&&a||D)&&typeof FileReader<`u`){let t=new FileReader;t.onloadend=function(){let e=t.result;if(typeof e!=`string`)throw r=null,Error(`Wrong reader.result type`);e=o?e:e.replace(/^data:[^;]*;/,`data:attachment/file;`),r?r.location.href=e:location.assign(e),r=null},t.readAsDataURL(e)}else{let t=URL.createObjectURL(e);r?r.location.assign(t):location.href=t,r=null,setTimeout(function(){URL.revokeObjectURL(t)},4e4)}}var{assign:ee}=Object;function M(){let e=u(!0),t=e.run(()=>c({})),n=[],r=[],i=s({install(e){v(i),i._a=e,e.provide(y,i),e.config.globalProperties.$pinia=i,r.forEach(e=>n.push(e)),r=[]},use(e){return this._a?n.push(e):r.push(e),this},_p:n,_a:null,_e:e,_s:new Map,state:t});return i}var N=()=>{};function P(e,t,n,r=N){e.add(t);let i=()=>{e.delete(t)&&r()};return!n&&o()&&d(i),i}function F(e,...t){e.forEach(e=>{e(...t)})}var I=e=>e(),L=Symbol(),R=Symbol();function z(e,t){e instanceof Map&&t instanceof Map?t.forEach((t,n)=>e.set(n,t)):e instanceof Set&&t instanceof Set&&t.forEach(e.add,e);for(let n in t){if(!Object.hasOwn(t,n))continue;let r=t[n],i=e[n];e[n]=b(i)&&b(r)&&Object.hasOwn(e,n)&&!p(r)&&!f(r)?z(i,r):r}return e}var B=Symbol();function V(e){return!e||typeof e!=`object`||!Object.hasOwn(e,B)}var{assign:H}=Object;function U(e){return!!(p(e)&&e.effect)}function W(e,t,r,i){let{state:a,actions:o,getters:c}=t,l=r.state.value[e],u;function d(){return l||(r.state.value[e]=a?a():{}),H(h(r.state.value[e]),o,Object.keys(c||{}).reduce((t,i)=>(t[i]=s(n(()=>{v(r);let t=r._s.get(e);return c[i].call(t,t)})),t),{}))}return u=G(e,d,t,r,i,!0),u}function G(t,n,i={},a,o,s){let c,d=H({actions:{}},i),h={deep:!0},g,_,y=new Set,b=new Set,x,S=a.state.value[t];!s&&!S&&(a.state.value[t]={});let C;function w(e){let n;g=_=!1,typeof e==`function`?(e(a.state.value[t]),n={type:`patch function`,storeId:t,events:x}):(z(a.state.value[t],e),n={type:`patch object`,payload:e,storeId:t,events:x});let i=C=Symbol();r().then(()=>{C===i&&(g=!0)}),_=!0,F(y,n,a.state.value[t])}let T=s?function(){let{state:e}=i,t=e?e():{};this.$patch(e=>{H(e,t)})}:N;function E(){c.stop(),y.clear(),b.clear(),a._s.delete(t)}let D=(e,n=``)=>{if(L in e)return e[R]=n,e;let r=function(){v(a);let n=Array.from(arguments),i=new Set,o=new Set;function s(e){i.add(e)}function c(e){o.add(e)}F(b,{args:n,name:r[R],store:k,after:s,onError:c});let l;try{l=e.apply(this&&this.$id===t?this:k,n)}catch(e){throw F(o,e),e}return l instanceof Promise?l.then(e=>(F(i,e),e)).catch(e=>(F(o,e),Promise.reject(e))):(F(i,l),l)};return r[L]=!0,r[R]=n,r},O={_p:a,$id:t,$onAction:P.bind(null,b),$patch:w,$reset:T,$subscribe(n,r={}){if(y.has(n))return N;let i=P(y,n,r.detached,()=>o()),o=c.run(()=>e(()=>a.state.value[t],e=>{(r.flush===`sync`?_:g)&&n({storeId:t,type:`direct`,events:x},e)},H({},h,r)));return i},$dispose:E},k=m(O);a._s.set(t,k);let A=(a._a&&a._a.runWithContext||I)(()=>a._e.run(()=>(c=u()).run(()=>n({action:D}))));for(let e in A){let n=A[e];p(n)&&!U(n)||f(n)?s||(S&&V(n)&&(p(n)?n.value=S[e]:z(n,S[e])),a.state.value[t][e]=n):typeof n==`function`&&(A[e]=D(n,e),d.actions[e]=n)}return H(k,A),H(l(k),A),Object.defineProperty(k,"$state",{get:()=>a.state.value[t],set:e=>{w(t=>{H(t,e)})}}),a._p.forEach(e=>{let t=c.run(()=>e({store:k,app:a._a,pinia:a,options:d}));H(k,t)}),S&&s&&i.hydrate&&i.hydrate(k.$state,S),g=!0,_=!0,k}function K(e,n,r){let a,o=typeof n==`function`;a=o?r:n;function s(r,s){let c=i();return r||=c?t(y,null):null,r&&v(r),r=_,r._s.has(e)||(o?G(e,n,a,r):W(e,a,r)),r._s.get(e)}return s.$id=e,s}function q(e){let t=l(e),r={};for(let i in t){let o=t[i];o?.effect?r[i]=n({get:()=>e[i],set(t){e[i]=t}}):(p(o)||f(o))&&(r[i]=a(e,i))}return r}var J=`ft_access_token`;function Y(){return`https://nademitex.montest.ir/server/api`.replace(/\/$/,``)||`https://nademitex.montest.ir/server/api`}function X(){return localStorage.getItem(J)}function Z(e){e?localStorage.setItem(J,e):localStorage.removeItem(J)}var Q=class extends Error{status;constructor(e,t){super(t),this.status=e}};function $(e,t){let n=Y(),r=e.startsWith(`http`)?e:`${n.replace(/\/$/,``)}/${e.replace(/^\//,``)}`,i=r.startsWith(`http`)?new URL(r):new URL(r,typeof window<`u`?window.location.origin:`http://127.0.0.1`);if(t)for(let[e,n]of Object.entries(t))n!=null&&n!==``&&i.searchParams.set(e,String(n));return i.toString()}function te(e,t){if(typeof e==`object`&&e){if(`message`in e){let t=e.message;if(Array.isArray(t))return t.join(`، `);if(t!=null&&String(t).trim())return String(t)}if(`error`in e){let n=e.error;if(typeof n==`string`&&n.trim())return`${n} (${t})`}}if(typeof e==`string`){if(/upstream error/i.test(e))return`سرور API در دسترس نیست. کمی بعد دوباره تلاش کنید.`;if(e.trim()&&!e.trimStart().startsWith(`<`))return e.trim().slice(0,200)}return t===400?`درخواست نامعتبر است. اطلاعات سفارش را بررسی کنید.`:t===401?`نشست شما منقضی شده است. دوباره وارد شوید.`:`خطای سرور (${t})`}async function ne(e,t={}){let n={Accept:`application/json`};if(t.body!==void 0&&(n[`Content-Type`]=`application/json`),t.auth!==!1){let e=X();e&&(n.Authorization=`Bearer ${e}`)}let r;try{r=await fetch($(e,t.query),{method:t.method??(t.body===void 0?`GET`:`POST`),headers:n,body:t.body===void 0?void 0:JSON.stringify(t.body),signal:AbortSignal.timeout(2e4)})}catch(e){throw new Q(0,e instanceof DOMException&&e.name===`TimeoutError`||e instanceof Error&&e.name===`TimeoutError`?`پاسخ سرور طول کشید. دوباره تلاش کنید.`:`اتصال به سرور برقرار نشد. اینترنت یا آدرس API را بررسی کنید.`)}let i=await r.text(),a=null;if(i)try{a=JSON.parse(i)}catch{a=i}if(!r.ok){if(r.status===401&&t.auth!==!1){Z(null);try{localStorage.removeItem(`ft_user`)}catch{}if(typeof window<`u`&&!window.location.pathname.startsWith(`/login`)){let e=encodeURIComponent(`${window.location.pathname}${window.location.search}`);window.location.assign(`/login?redirect=${e}`)}}throw new Q(r.status,te(a,r.status))}return a}export{M as a,Z as i,ne as n,K as o,X as r,q as s,Q as t}; |