zois-core 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/popups.js +1 -1
- package/package.json +1 -1
package/dist/popups.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getRelativeWidth as C,getRelativeX as y,getRelativeY as
|
|
1
|
+
import{getRelativeWidth as C,getRelativeX as y,getRelativeY as x}from"./ui";import{MOD_DATA as p}from"./index";import{useState as g,useEffect as f}from"react";import D from"react-dom/client";import{create as T}from"zustand";import{CircleAlert as k,CircleCheck as z,CircleX as O,Info as E}from"lucide-react";import{Fragment as w,jsx as a,jsxs as d}from"react/jsx-runtime";function I({children:o}){const[e,t]=g({}),r=window.ZOISCORE.useToastsStore(s=>s.clearToasts);return f(()=>{const s=()=>{t({fontFamily:CommonGetFontName(),bottom:x(5)+"px",left:y(5)+"px"})};return window.addEventListener("resize",s),s(),()=>{window.removeEventListener("resize",s)}},[]),a("div",{className:"zcToastsContainer",style:e,onClick:()=>{document.querySelectorAll(".zcToast").forEach(s=>{s.classList.add("exiting")}),setTimeout(r,300)},children:o})}const P=({type:o,theme:e})=>{switch(o){case"info":return a(E,{style:{flexShrink:0,width:"1.65em",height:"1.65em",fill:e?e.iconFillColor:"#addbff",stroke:e?e.iconStrokeColor:"#385073"}});case"success":return a(z,{style:{flexShrink:0,width:"1.65em",height:"1.65em",fill:e?e.iconFillColor:"#c3ffc3",stroke:e?e.iconStrokeColor:"#028f74"}});case"warning":return a(k,{style:{flexShrink:0,width:"1.65em",height:"1.65em",fill:e?e.iconFillColor:"#ffdfaf",stroke:e?e.iconStrokeColor:"#9c7633"}});case"error":return a(O,{style:{flexShrink:0,width:"1.65em",height:"1.65em",fill:e?e.iconFillColor:"#ffb2b2",stroke:e?e.iconStrokeColor:"#7f2828"}});case"spinner":return a("div",{style:{flexShrink:0,width:"1.65em",height:"1.65em",boxSizing:"border-box",border:"2px solid",borderRadius:"100%",borderColor:`transparent ${e?e.iconFillColor:"rgb(154 154 255)"}`,animation:"zcSpin 0.65s linear infinite"}})}};function R({title:o,message:e,type:t,duration:r,id:s,theme:i}){const[n,c]=g({}),[l,m]=g(!1);return f(()=>{const u=()=>{const h=MainCanvas.canvas.clientWidth,b=MainCanvas.canvas.clientHeight,v=Math.min(h,b)/100;c({position:"relative",width:"100%",borderRadius:"0.1em",fontSize:3*v+"px",padding:1.5*v+"px",background:i?i.backgroundColor:t==="success"?"#3ece7e":t==="warning"?"#debf72":t==="error"?"rgb(212, 46, 107)":"rgb(80, 80, 223)"})};window.addEventListener("resize",u),u();const S=setTimeout(()=>m(!0),r);return()=>{clearTimeout(S),window.removeEventListener("resize",u)}},[]),d("div",{className:`zcToast ${l&&"exiting"}`,"data-zc-toast-type":t,style:n,children:[d("div",{style:{display:"flex",alignItems:"center",gap:"1vw",position:"relative",zIndex:5},children:[a(P,{type:t,theme:i}),d("div",{children:[o&&e&&d(w,{children:[a("p",{style:{color:i?i.titleColor:"white"},children:o}),a("p",{style:{color:i?i.messageColor:t==="info"||t==="spinner"?"#b8b8ff":t==="success"?"#c7f9c7":t==="error"?"#f8bcbc":"#ffeec5",fontSize:"70%",overflowWrap:"anywhere",marginTop:"0.25em"},children:e})]}),(!o&&e||o&&!e)&&a("p",{style:{position:"relative",zIndex:5},children:o||e})]})]}),t!=="spinner"&&a("div",{className:"zcToast-ProgressBar",style:{animation:`zcToast-progress ${r}ms linear 0s 1 alternate none`,position:"absolute",top:0,left:0,height:"100%",background:i?i.progressBarColor:t==="info"?"rgb(103, 103, 234)":t==="success"?"#34bc71":t==="warning"?"#d0af5e":"rgb(183, 40, 92)"}})]})}function M({dialog:o}){const e=window.ZOISCORE.useDialogStore(n=>n.clearDialog),[t,r]=g({}),[s,i]=g([]);return f(()=>{const n=()=>{const c=MainCanvas.canvas.clientWidth,l=MainCanvas.canvas.clientHeight,m=Math.min(c,l)/100;r({width:C(o.width),position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",background:"rgba(36, 36, 36, 0.96)",zIndex:20,fontFamily:CommonGetFontName(),border:"none",padding:2*m})};return window.addEventListener("resize",n),n(),()=>{window.removeEventListener("resize",n)}},[]),d("dialog",{open:Object.keys(t).length>0,"data-zc-dialog-type":o.type,style:t,children:[o.title&&a("p",{style:{position:"absolute",top:0,left:0,fontWeight:"bold",color:"white",fontSize:"clamp(6px, 2vw, 24px)",padding:"0.25em",background:"#2d2d2d",width:"100%"},children:o.title}),a("p",{style:{padding:"1em",marginTop:"2vw",fontSize:"clamp(6px, 2vw, 24px)",color:"white"},children:o.body}),a("div",{style:{display:"flex",flexDirection:o.buttons.direction,justifyContent:"center",gap:"0.5vw"},children:o.buttons?.list?.map((n,c)=>a("button",{className:"zcDialogBtn","data-zc-picked":s.includes(c),style:{width:"100%",position:"relative"},onClick:()=>{o.type==="choice_one"?(e(),o.promise.resolve(n.value)):s.includes(c)?i(s.filter(l=>l!==c)):i([...s,c])},children:n.text}))}),o.type==="choice_multiple"&&a("button",{style:{cursor:"pointer",color:"white",background:"#4d4d4d",border:"none",marginTop:"1vw",fontSize:"clamp(8px,2.5vw,28px)",padding:"0.2em",borderRadius:"4px"},onClick:()=>{e(),o.promise.resolve(o.buttons.list.filter((n,c)=>s.includes(c)).map(n=>n.value))},children:"Confirm"})]})}class F{generateToastId(){return crypto.randomUUID()}process({title:e,message:t,duration:r,type:s,id:i,theme:n}){const{addToast:c,removeToast:l}=window.ZOISCORE.useToastsStore.getState();c({id:i,title:e,message:t,duration:r,type:s,theme:n}),setTimeout(()=>l(i),r+300)}info({title:e,message:t,duration:r}){const s=this.generateToastId(),i=p.singleToastsTheme;this.process({title:e,message:t,duration:r,type:"info",id:s,theme:i})}success({title:e,message:t,duration:r}){const s=this.generateToastId(),i=p.singleToastsTheme;this.process({title:e,message:t,duration:r,type:"success",id:s,theme:i})}warn({title:e,message:t,duration:r}){const s=this.generateToastId(),i=p.singleToastsTheme;this.process({title:e,message:t,duration:r,type:"warning",id:s,theme:i})}error({title:e,message:t,duration:r}){const s=this.generateToastId(),i=p.singleToastsTheme;this.process({title:e,message:t,duration:r,type:"error",id:s,theme:i})}spinner({title:e,message:t}){const r=this.generateToastId(),s=p.singleToastsTheme;return this.process({title:e,message:t,duration:1e6,type:"spinner",id:r,theme:s}),r}removeSpinner(e){const{removeToast:t}=window.ZOISCORE.useToastsStore.getState();t(e)}}class N{showDialog({type:e,title:t,body:r,buttons:s,width:i}){const{setDialog:n}=window.ZOISCORE.useDialogStore.getState();return new Promise((c,l)=>{n({width:i,type:e,title:t,body:r,buttons:s,promise:{resolve:c,reject:l}})})}}function L(){const o=window.ZOISCORE.useToastsStore(t=>t.toasts),e=window.ZOISCORE.useDialogStore(t=>t.dialog);return d(w,{children:[a(I,{children:o.map(({title:t,message:r,type:s,duration:i,id:n,theme:c})=>a(R,{id:n,title:t,message:r,type:s,duration:i,theme:c},n))}),e&&a(M,{dialog:e})]})}class W extends HTMLElement{disconnectedCallback(){ServerShowBeep("VirtualDOM was removed, chaos is coming...",5e3,{})}}const q=T(o=>({toasts:[],addToast:e=>o(t=>({toasts:[...t.toasts,e]})),removeToast:e=>o(t=>({toasts:t.toasts.filter(r=>r.id!==e)})),clearToasts:()=>o({toasts:[]})})),Y=T(o=>({dialog:null,setDialog:e=>o({dialog:e}),clearDialog:()=>o({dialog:null})}));function K(){customElements.define("zc-virtual-dom",W);const o=document.createElement("zc-virtual-dom");document.body.append(o),D.createRoot(document.getElementsByTagName("zc-virtual-dom")[0]).render(a(L,{}))}const Q=new F,ee=new N;export{ee as dialogsManager,K as initVirtualDOM,Q as toastsManager,Y as useDialogStore,q as useToastsStore};
|