zois-core 1.0.14 → 1.0.15
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/messaging.js +1 -1
- package/dist/popups.js +1 -1
- package/package.json +1 -1
package/dist/messaging.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getPlayer as g,MOD_DATA as i}from"./index";import{hookFunction as y,HookPriority as m}from"./modsApi";import{setFontFamily as C}from"./ui";const d=new Map,l=new Map;function q(o,t){const e=d.get(o);e&&e.resolve({data:t})}function P(o,t,e,n){const
|
|
1
|
+
import{getPlayer as g,MOD_DATA as i}from"./index";import{hookFunction as y,HookPriority as m}from"./modsApi";import{setFontFamily as C}from"./ui";const d=new Map,l=new Map;function q(o,t){const e=d.get(o);e&&e.resolve({data:t})}function P(o,t,e,n){const s=l.get(t);if(!s)return;const a=s(e,n);a!==void 0&&u.sendPacket("requestResponse",{requestId:o,message:t,data:a},n.MemberNumber)}function k(o,t){const e=d.get(o);e&&e.resolve({data:t})}function M(o,t,e,n,s){const a=l.get(t);if(!a)return;const r=a(e,n,s);r!==void 0&&u.sendBeep({type:`${i.key}_requestResponse`,requestId:o,message:t,data:r},n)}class R{sendBeep(t,e){const n={IsSecret:!0,BeepType:"Leash",MemberNumber:e,Message:JSON.stringify({...t})};ServerSend("AccountBeep",n)}sendPacket(t,e,n){const s={Content:i.key,Dictionary:{msg:t},Type:"Hidden"};e&&(s.Dictionary.data=e),n&&(s.Target=n),ServerSend("ChatRoomChat",s)}sendAction(t,e=void 0,n=[]){if(!t||!ServerPlayerIsInChatRoom())return;const s=CharacterPronounDescription(Player)==="She/Her",a=s?"Her":"His",r=s?"Her":"Him",c=s?"Herself":"Himself",p=s?"She":"He";t=t.replaceAll("<Possessive>",a).replaceAll("<possessive>",a.toLocaleLowerCase()).replaceAll("<Intensive>",r).replaceAll("<intensive>",r.toLocaleLowerCase()).replaceAll("<SelfIntensive>",c).replaceAll("<selfIntensive>",c.toLocaleLowerCase()).replaceAll("<Pronoun>",p).replaceAll("<pronoun>",p.toLocaleLowerCase()),ServerSend("ChatRoomChat",{Content:"ZC_CUSTOM_ACTION",Type:"Action",Target:e??void 0,Dictionary:[{Tag:'MISSING TEXT IN "Interface.csv": ZC_CUSTOM_ACTION',Text:t},...n]})}sendRequest({message:t,data:e={},target:n,type:s="packet"}){const a=crypto.randomUUID();return new Promise((r,c)=>{d.set(a,{message:t,data:e,target:n,resolve:r,reject:c}),s==="packet"?u.sendPacket("request",{requestId:a,message:t,data:e},n):u.sendBeep({type:`${i.key}_request`,requestId:a,message:t,data:e},n),setTimeout(()=>{d.delete(a),r({isError:!0})},6e3)})}sendLocal(t){if(!ServerPlayerIsInChatRoom())return;const e=document.createElement("div");e.setAttribute("class","ChatMessage ChatMessageLocalMessage"),e.setAttribute("data-time",ChatRoomCurrentTime()),e.setAttribute("data-sender",`${Player.MemberNumber}`),C(e,i.fontFamily),e.style.background=i.chatMessageBackground??"#55edc095",e.style.color=i.chatMessageColor??"black",e.style.margin="0.15em 0",typeof t=="string"?e.innerHTML=t:e.appendChild(t),document.querySelector("#TextAreaChatLog").appendChild(e),ElementScrollToEnd("TextAreaChatLog")}sendChat(t){ServerSend("ChatRoomChat",{Type:"Chat",Content:t})}onRequest(t,e){l.set(t,e)}onPacket(t,e){y("ChatRoomMessage",m.ADD_BEHAVIOR,(n,s)=>{const a=n[0],r=g(a.Sender);return r&&a.Content===i.key&&a.Dictionary.msg===t&&!r.IsPlayer()&&e(a.Dictionary.data,r),s(n)})}}const u=new R;export{M as handleBeepRequest,k as handleBeepRequestResponse,P as handlePacketRequest,q as handlePacketRequestResponse,u as messagesManager};
|
package/dist/popups.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getRelativeWidth as
|
|
1
|
+
import{getRelativeWidth as h,getRelativeX as y,getRelativeY as D}from"./ui";import{useState as m,useEffect as u}from"react";import b from"react-dom/client";import{create as v}from"zustand";import x from"./assets/warningIcon.svg";import O from"./assets/errorIcon.svg";import z from"./assets/infoIcon.svg";import C from"./assets/successIcon.svg";import{Fragment as w,jsx as a,jsxs as d}from"react/jsx-runtime";function E({children:o}){const[e,t]=m({}),i=window.ZOISCORE.useToastsStore(s=>s.clearToasts);return u(()=>{const s=()=>{t({fontFamily:"ui-sans-serif",bottom:D(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(i,300)},children:o})}function P({title:o,message:e,type:t,duration:i,id:s}){const[c,n]=m({}),[r,l]=m(!1);return u(()=>{const p=()=>{const T=MainCanvas.canvas.clientWidth,S=MainCanvas.canvas.clientHeight,g=Math.min(T,S)/100;n({position:"relative",width:"100%",borderRadius:"0.1em",fontSize:3*g+"px",padding:1.5*g+"px"})};window.addEventListener("resize",p),p();const f=setTimeout(()=>l(!0),i);return()=>{clearTimeout(f),window.removeEventListener("resize",p)}},[]),d("div",{className:`zcToast ${r&&"exiting"}`,"data-zc-toast-type":t,style:c,children:[d("div",{style:{display:"flex",alignItems:"center",gap:"1vw",position:"relative",zIndex:5},children:[t==="spinner"?a("div",{className:"zcSpinner",style:{width:"2vw",height:"2vw"}}):a("img",{src:t==="info"?z:t==="success"?C:t==="warning"?x:O,style:{width:"2vw"}}),d("div",{children:[o&&e&&d(w,{children:[a("p",{children:o}),a("p",{style:{color:t==="info"?"#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})]})]}),a("div",{className:"zcToast-ProgressBar",style:{animation:`zcToast-progress ${i}ms linear 0s 1 alternate none`,position:"absolute",top:0,left:0,height:"100%"}})]})}function I({dialog:o}){const e=window.ZOISCORE.useDialogStore(n=>n.clearDialog),[t,i]=m({}),[s,c]=m([]);return u(()=>{const n=()=>{const r=MainCanvas.canvas.clientWidth,l=MainCanvas.canvas.clientHeight,p=Math.min(r,l)/100;i({width:h(o.width),position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",background:"rgba(36, 36, 36, 0.96)",zIndex:20,fontFamily:"ui-sans-serif",border:"none",padding:2*p})};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,r)=>a("button",{className:"zcDialogBtn","data-zc-picked":s.includes(r),style:{width:"100%",position:"relative"},onClick:()=>{o.type==="choice_one"?(e(),o.promise.resolve(n.value)):s.includes(r)?c(s.filter(l=>l!==r)):c([...s,r])},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,r)=>s.includes(r)).map(n=>n.value))},children:"Confirm"})]})}class R{generateToastId(){const{toasts:e}=window.ZOISCORE.useToastsStore.getState();return`${Date.now()}:${e.length+1}`}process({title:e,message:t,duration:i,type:s,id:c}){const{addToast:n,removeToast:r}=window.ZOISCORE.useToastsStore.getState();n({id:c,title:e,message:t,duration:i,type:s}),setTimeout(()=>r(c),i+300)}info({title:e,message:t,duration:i}){const s=this.generateToastId();this.process({title:e,message:t,duration:i,type:"info",id:s})}success({title:e,message:t,duration:i}){const s=this.generateToastId();this.process({title:e,message:t,duration:i,type:"success",id:s})}warn({title:e,message:t,duration:i}){const s=this.generateToastId();this.process({title:e,message:t,duration:i,type:"warning",id:s})}error({title:e,message:t,duration:i}){const s=this.generateToastId();this.process({title:e,message:t,duration:i,type:"error",id:s})}spinner({title:e,message:t}){const i=this.generateToastId();return this.process({title:e,message:t,duration:1e6,type:"spinner",id:i}),i}removeSpinner(e){const{removeToast:t}=window.ZOISCORE.useToastsStore.getState();t(e)}}class M{showDialog({type:e,title:t,body:i,buttons:s,width:c}){const{setDialog:n}=window.ZOISCORE.useDialogStore.getState();return new Promise((r,l)=>{n({width:c,type:e,title:t,body:i,buttons:s,promise:{resolve:r,reject:l}})})}}function k(){const o=window.ZOISCORE.useToastsStore(t=>t.toasts),e=window.ZOISCORE.useDialogStore(t=>t.dialog);return d(w,{children:[a(E,{children:o.map(({title:t,message:i,type:s,duration:c,id:n})=>a(P,{id:n,title:t,message:i,type:s,duration:c},n))}),e&&a(I,{dialog:e})]})}class L extends HTMLElement{disconnectedCallback(){ServerShowBeep("VirtualDOM was removed, chaos is coming...",5e3,{})}}const j=v(o=>({toasts:[],addToast:e=>o(t=>({toasts:[...t.toasts,e]})),removeToast:e=>o(t=>({toasts:t.toasts.filter(i=>i.id!==e)})),clearToasts:()=>o({toasts:[]})})),q=v(o=>({dialog:null,setDialog:e=>o({dialog:e}),clearDialog:()=>o({dialog:null})}));function Y(){customElements.define("zc-virtual-dom",L);const o=document.createElement("zc-virtual-dom");document.body.append(o),b.createRoot(document.getElementsByTagName("zc-virtual-dom")[0]).render(a(k,{}))}const G=new R,K=new M;export{K as dialogsManager,Y as initVirtualDOM,G as toastsManager,q as useDialogStore,j as useToastsStore};
|