zois-core 1.1.9 → 2.0.0

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.
Files changed (116) hide show
  1. package/README.md +23 -2
  2. package/dist/changelogs.js +167 -0
  3. package/dist/core-subscreen/coreSubscreen.js +81 -0
  4. package/dist/core-subscreen/developmentSubscreen.js +22 -0
  5. package/dist/core-subscreen/generalSubscreen.js +23 -0
  6. package/dist/core-subscreen/mainSubscreen.js +58 -0
  7. package/dist/core-subscreen/shards/coreButtonShard.js +30 -0
  8. package/dist/core-subscreen/shards/coreCheckboxShard.js +33 -0
  9. package/dist/core-subscreen/shards/coreInputListShard.js +38 -0
  10. package/dist/core-subscreen/shards/coreSelectShard.js +17 -0
  11. package/dist/core-subscreen/shards/coreTextShard.js +9 -0
  12. package/dist/core-subscreen/shards/index.js +5 -0
  13. package/dist/core-subscreen/toastsSubscreen.js +112 -0
  14. package/dist/core.js +178 -0
  15. package/dist/dialogs.js +110 -0
  16. package/dist/index.js +202 -1
  17. package/dist/localization.js +71 -0
  18. package/dist/logging.js +31 -0
  19. package/dist/messaging.js +234 -1
  20. package/dist/modSdk.js +63 -0
  21. package/dist/shard-modules/attributesModule.js +16 -0
  22. package/dist/shard-modules/centerModule.js +12 -0
  23. package/dist/shard-modules/clickModule.js +14 -0
  24. package/dist/shard-modules/counterUpModule.js +37 -0
  25. package/dist/shard-modules/dynamicClassModule.js +15 -0
  26. package/dist/shard-modules/index.js +9 -0
  27. package/dist/shard-modules/multiClickModule.js +41 -0
  28. package/dist/shard-modules/shardModule.js +12 -0
  29. package/dist/shard-modules/styleModule.js +20 -0
  30. package/dist/shard-modules/typeModule.js +37 -0
  31. package/dist/shards/backNextButtonShard.js +99 -0
  32. package/dist/shards/buttonShard.js +118 -0
  33. package/dist/shards/cardShard.js +35 -0
  34. package/dist/shards/checkboxShard.js +139 -0
  35. package/dist/shards/containerShard.js +16 -0
  36. package/dist/shards/imageShard.js +98 -0
  37. package/dist/shards/index.js +13 -0
  38. package/dist/shards/inputListShard.js +162 -0
  39. package/dist/shards/inputShard.js +33 -0
  40. package/dist/shards/selectShard.js +126 -0
  41. package/dist/shards/shard.js +79 -0
  42. package/dist/shards/svgShard.js +47 -0
  43. package/dist/shards/tabsShard.js +59 -0
  44. package/dist/shards/textShard.js +27 -0
  45. package/dist/styles.css +209 -1
  46. package/dist/toasts.js +188 -0
  47. package/dist/types/changelogs.d.ts +1 -0
  48. package/dist/types/core-subscreen/coreSubscreen.d.ts +15 -0
  49. package/dist/types/core-subscreen/developmentSubscreen.d.ts +5 -0
  50. package/dist/types/core-subscreen/generalSubscreen.d.ts +5 -0
  51. package/dist/types/core-subscreen/mainSubscreen.d.ts +6 -0
  52. package/dist/types/core-subscreen/shards/coreButtonShard.d.ts +5 -0
  53. package/dist/types/core-subscreen/shards/coreCheckboxShard.d.ts +6 -0
  54. package/dist/types/core-subscreen/shards/coreInputListShard.d.ts +6 -0
  55. package/dist/types/core-subscreen/shards/coreSelectShard.d.ts +5 -0
  56. package/dist/types/core-subscreen/shards/coreTextShard.d.ts +4 -0
  57. package/dist/types/core-subscreen/shards/index.d.ts +5 -0
  58. package/dist/types/core-subscreen/toastsSubscreen.d.ts +5 -0
  59. package/dist/types/core.d.ts +18 -0
  60. package/dist/types/dialogs.d.ts +29 -0
  61. package/dist/types/index.d.ts +55 -3
  62. package/dist/types/localization.d.ts +4 -0
  63. package/dist/types/logging.d.ts +16 -0
  64. package/dist/types/messaging.d.ts +5 -3
  65. package/dist/types/{modsApi.d.ts → modSdk.d.ts} +2 -2
  66. package/dist/types/shard-modules/attributesModule.d.ts +7 -0
  67. package/dist/types/shard-modules/centerModule.d.ts +5 -0
  68. package/dist/types/shard-modules/clickModule.d.ts +7 -0
  69. package/dist/types/shard-modules/counterUpModule.d.ts +13 -0
  70. package/dist/types/shard-modules/dynamicClassModule.d.ts +8 -0
  71. package/dist/types/{ui-modules → shard-modules}/index.d.ts +2 -0
  72. package/dist/types/shard-modules/multiClickModule.d.ts +12 -0
  73. package/dist/types/shard-modules/shardModule.d.ts +7 -0
  74. package/dist/types/shard-modules/styleModule.d.ts +8 -0
  75. package/dist/types/shard-modules/typeModule.d.ts +11 -0
  76. package/dist/types/shards/backNextButtonShard.d.ts +14 -0
  77. package/dist/types/shards/buttonShard.d.ts +20 -0
  78. package/dist/types/shards/cardShard.d.ts +10 -0
  79. package/dist/types/shards/checkboxShard.d.ts +19 -0
  80. package/dist/types/shards/containerShard.d.ts +7 -0
  81. package/dist/types/shards/imageShard.d.ts +11 -0
  82. package/dist/types/shards/index.d.ts +13 -0
  83. package/dist/types/shards/inputListShard.d.ts +16 -0
  84. package/dist/types/shards/inputShard.d.ts +14 -0
  85. package/dist/types/shards/selectShard.d.ts +17 -0
  86. package/dist/types/shards/shard.d.ts +21 -0
  87. package/dist/types/shards/svgShard.d.ts +12 -0
  88. package/dist/types/shards/tabsShard.d.ts +17 -0
  89. package/dist/types/shards/textShard.d.ts +13 -0
  90. package/dist/types/toasts.d.ts +21 -0
  91. package/dist/types/ui.d.ts +30 -147
  92. package/dist/ui.js +351 -11
  93. package/dist/validation.js +31 -1
  94. package/dist/wardrobe.js +167 -1
  95. package/package.json +44 -26
  96. package/scripts/generateChangelog.mjs +80 -0
  97. package/dist/modsApi.js +0 -1
  98. package/dist/modules.js +0 -1
  99. package/dist/popups.js +0 -1
  100. package/dist/types/modules.d.ts +0 -18
  101. package/dist/types/popups.d.ts +0 -48
  102. package/dist/types/ui-modules/attributesModule.d.ts +0 -6
  103. package/dist/types/ui-modules/centerModule.d.ts +0 -4
  104. package/dist/types/ui-modules/clickModule.d.ts +0 -6
  105. package/dist/types/ui-modules/counterUpModule.d.ts +0 -12
  106. package/dist/types/ui-modules/dynamicClassModule.d.ts +0 -7
  107. package/dist/types/ui-modules/styleModule.d.ts +0 -7
  108. package/dist/types/ui-modules/typeModule.d.ts +0 -10
  109. package/dist/ui-modules/attributesModule.js +0 -1
  110. package/dist/ui-modules/centerModule.js +0 -1
  111. package/dist/ui-modules/clickModule.js +0 -1
  112. package/dist/ui-modules/counterUpModule.js +0 -1
  113. package/dist/ui-modules/dynamicClassModule.js +0 -1
  114. package/dist/ui-modules/index.js +0 -1
  115. package/dist/ui-modules/styleModule.js +0 -1
  116. package/dist/ui-modules/typeModule.js +0 -1
package/dist/ui.js CHANGED
@@ -1,11 +1,351 @@
1
- import{Check as N,ChevronDown as I,CircleX as F,createElement as T,Trash2 as W}from"lucide";import{getThemedColorsModule as z,MOD_DATA as C}from"./index";import{StyleModule as H}from"./ui-modules";function q(g,e){return g.replace(/fill="[^"]*"/g,`fill="${e}"`).replace(/stroke="[^"]*"/g,`stroke="${e}"`)}function D(g){return g*(MainCanvas.canvas.clientHeight/1e3)}function P(g){return g*(MainCanvas.canvas.clientWidth/2e3)}function V(g,e="top"){const o=MainCanvas.canvas.clientHeight/1e3;return e==="top"?MainCanvas.canvas.offsetTop+g*o:window.innerHeight-(MainCanvas.canvas.offsetTop+MainCanvas.canvas.clientHeight)+g*o}function R(g,e="left"){const o=MainCanvas.canvas.clientWidth/2e3;return e==="left"?MainCanvas.canvas.offsetLeft+g*o:window.innerWidth-(MainCanvas.canvas.offsetLeft+MainCanvas.canvas.clientWidth)+g*o}function O(g,e,o,l="top-left"){const i=l==="top-left"||l==="top-right"?"top":"bottom",n=l==="top-left"||l==="bottom-left"?"left":"right",t=V(o,i),f=R(e,n);Object.assign(g.style,{position:"fixed",[n]:f+"px",[i]:t+"px"})}function J(g,e,o){Object.assign(g.style,{width:P(e)+"px",height:D(o)+"px"})}function j(g,e){const o=MainCanvas.canvas.clientWidth,l=MainCanvas.canvas.clientHeight,i=Math.min(o,l)/100,n=e*i;Object.assign(g.style,{fontSize:n+"px"})}function L(g,e){g.style.fontFamily=e??"sans-serif"}function G(g,e){const o=MainCanvas.canvas.clientWidth,l=MainCanvas.canvas.clientHeight,i=Math.min(o,l)/100,n=e*i;Object.assign(g.style,{padding:n+"px"})}function X(g){const e=MainCanvas.canvas.clientWidth<=MainCanvas.canvas.clientHeight*2?MainCanvas.canvas.clientWidth/50:MainCanvas.canvas.clientHeight/25;Object.assign(g.style,{fontSize:e+"px"})}const B=[];function _(g){const e=o=>o?JSON.stringify(Object.keys(o).sort().reduce((l,i)=>(l[i]=o[i],l),{})):"null";return`base:${e(g.base)}|hover:${e(g.hover)}|active:${e(g.active)}|before:${e(g.before)}|after:${e(g.after)}`}function Q(g,e){const o=_(e),l=B.find(p=>p.key===o);if(l)return g.classList.add(l.className);let i;do i="dynamic-"+Math.random().toString(36).substring(2,10);while(B.find(p=>p.className===i));B.push({key:o,className:i});const n=(p,m)=>{let d=`${p} {`;for(const[r,c]of Object.entries(m))d+=`${r.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase()}: ${c};`;return d+="}",d};let t="";e.base&&(t+=n(`.${i}`,e.base)),e.hover&&(t+=n(`.${i}:hover`,e.hover)),e.active&&(t+=n(`.${i}:active`,e.active)),e.focus&&(t+=n(`.${i}:focus`,e.focus)),e.disabled&&(t+=n(`.${i}:disabled`,e.disabled)),e.before&&(t+=n(`.${i}:before`,e.before)),e.after&&(t+=n(`.${i}:after`,e.after));let f=document.getElementById(`${C.key??""}-dynamic-classes`);f?f.textContent+=t:(f=document.createElement("style"),f.id=`${C.key??""}-dynamic-classes`,f.textContent=t,document.head.appendChild(f)),g.classList.add(i)}function U(){$(w)}function $(g){w=k,k=g,k&&k.load(),w&&w.unload()}function ee(){return k}let k,w=null;class te{htmlElements=[];resizeEventListeners=[];tabHandlers={};addElement(e,{x:o,y:l,width:i,height:n,padding:t,fontSize:f="auto",anchor:p,place:m,modules:d={},modulesMap:r}){L(e,C.fontFamily);const c={anchor:p,x:o,y:l,width:i,height:n,padding:t,fontSize:f,place:m,element:e};Object.keys(d)?.forEach(s=>{d[s].forEach(b=>{const u=b.overrideProperties(c,r[s]);p=u.anchor,o=u.x,l=u.y,i=u.width,n=u.height,t=u.padding,f=u.fontSize,m=u.place,e=u.element})});const a=()=>{typeof o=="number"&&typeof l=="number"&&O(e,o,l,p),f==="auto"?X(e):j(e,f),t&&G(e,t),i&&(e.style.width=P(i)+"px"),n&&(e.style.height=D(n)+"px")};a(),window.addEventListener("resize",a),Object.keys(d)?.forEach(s=>{d[s].forEach(b=>{b.layoutEffect(c,r[s])})}),m&&document.body.append(e),this.resizeEventListeners.push(a),this.htmlElements.push(e),Object.keys(d)?.forEach(s=>{d[s].forEach(b=>{b.effect(c,r[s])})})}get currentSubscreen(){return k}get previousSubscreen(){return w}get name(){return""}run(){this.tabHandlers.run?.()}load(){this.createButton({x:1815,y:75,width:90,height:90,icon:"Icons/Exit.png",modules:{base:[new H({zIndex:"10"})]}}).addEventListener("click",()=>this.exit()),this.name&&(this.createText({text:this.name,x:100,y:60,fontSize:8}).style.cssText+="max-width: 85%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0.1em;"),M[this.constructor.name]&&M[this.name].forEach(e=>e(this))}unload(){this.tabHandlers.unload?.(),this.htmlElements.forEach(e=>{e.remove()}),this.resizeEventListeners.forEach(e=>{removeEventListener("resize",e)})}click(){}exit(){this.tabHandlers.exit?.(),this.setSubscreen(this.previousSubscreen)}update(){}setPreviousSubscreen(){U()}setSubscreen(e){$(e)}createButton({text:e,x:o,y:l,width:i,height:n,fontSize:t="auto",anchor:f="top-left",padding:p,style:m="default",place:d=!0,icon:r,iconAbsolutePosition:c=!0,tooltip:a,onClick:s,isDisabled:b,modules:u}){let h,v;const y=document.createElement("button");if(y.classList.add("zcButton"),y.setAttribute("data-zc-style",m),y.style.display="flex",y.style.alignItems="center",y.style.justifyContent="center",y.style.columnGap="1.25vw",L(y,C.fontFamily),r&&(typeof r=="string"?(h=document.createElement("img"),h.src=r):h=r,h.style.height="80%",h.style.width="auto",e&&c&&(h.style.position="absolute",h.style.left="1vw"),e&&!c&&(y.style.justifyContent=""),y.append(h)),e&&(v=document.createElement("span"),v.textContent=e,y.append(v)),a){const S=document.createElement("span");S.classList.add("tooltip"),S.setAttribute("position",a.position),S.textContent=a.text,y.append(S)}return typeof b=="function"&&b()&&y.classList.add("zcDisabled"),y.addEventListener("click",()=>{if(typeof b=="function"&&b())return y.classList.add("zcDisabled");typeof s=="function"&&s()}),this.addElement(y,{x:o,y:l,width:i,height:n,anchor:f,place:d,fontSize:t,padding:p,modules:u,modulesMap:{base:y,text:v,icon:h}}),y}createText({text:e,color:o,x:l,y:i,width:n,height:t,withBackground:f=!1,withBorder:p=!1,fontSize:m="auto",anchor:d="top-left",padding:r,place:c=!0,modules:a}){const s=document.createElement("p");return s.innerHTML=e,s.style.color=o??"var(--tmd-text, black)",f&&(s.style.background="var(--tmd-element,rgb(239, 239, 239))"),p&&(s.style.border="2px solid var(--tmd-accent, rgb(236, 236, 236))"),L(s,C.fontFamily),this.addElement(s,{x:l,y:i,width:n,height:t,anchor:d,place:c,fontSize:m,padding:r,modules:a,modulesMap:{base:s}}),s}createInput({value:e,placeholder:o,x:l,y:i,width:n,height:t,textArea:f=!1,fontSize:p="auto",anchor:m="top-left",padding:d,place:r=!0,onChange:c,onInput:a,isDisabled:s,modules:b}){const u=document.createElement(f?"textarea":"input");return u.classList.add("zcInput"),o&&(u.placeholder=o),e&&(u.value=e),L(u,C.fontFamily),typeof s=="function"&&s()&&u.classList.add("zcDisabled"),u.addEventListener("change",()=>{if(typeof s=="function"&&s())return u.classList.add("zcDisabled");typeof c=="function"&&c()}),u.addEventListener("input",()=>{if(typeof s=="function"&&s())return u.classList.add("zcDisabled");typeof a=="function"&&a()}),this.addElement(u,{x:l,y:i,width:n,height:t,anchor:m,place:r,fontSize:p,padding:d,modules:b,modulesMap:{base:u}}),u}createCheckbox({text:e,x:o,y:l,isChecked:i,width:n,modules:t,anchor:f="top-left",place:p=!0,isDisabled:m,onChange:d}){const r=document.createElement("div");r.style.display="flex",r.style.alignItems="center",r.style.columnGap="1vw";const c=document.createElement("input");c.type="checkbox",c.checked=i,c.style.borderRadius="min(0.8dvh, 0.3dvw)",c.style.aspectRatio="1/1",c.classList.add("zcCheckbox","checkbox");const a=document.createElement("p");return a.textContent=e,a.style.color="var(--tmd-text, black)",L(a,C.fontFamily),typeof m=="function"&&m()&&r.classList.add("zcDisabled"),r.addEventListener("change",()=>{if(typeof m=="function"&&m())return r.classList.add("zcDisabled");typeof d=="function"&&d()}),r.append(c,a),this.addElement(r,{x:o,y:l,width:n,anchor:f,place:p,modules:t,modulesMap:{base:r,checkbox:c,label:a}}),r}createScrollView({scroll:e,x:o,y:l,width:i,height:n,anchor:t="top-left",modules:f,place:p=!0}){const m=document.createElement("div");return e==="all"&&(m.style.overflow="scroll"),e==="x"&&(m.style.overflowX="scroll"),e==="y"&&(m.style.overflowY="scroll"),this.addElement(m,{x:o,y:l,width:i,height:n,anchor:t,place:p,modules:f,modulesMap:{base:m}}),m}createInputList({x:e,y:o,width:l,height:i,title:n,value:t,modules:f,anchor:p="top-left",place:m=!0,numbersOnly:d=!1,isDisabled:r,onChange:c}){const a=[],s=document.createElement("div");s.style.cssText=`
2
- display: flex; flex-direction: column; gap: 1vw; border: 2px solid var(--tmd-accent, black);
3
- border-radius: 4px; padding: 0.75vw; background: var(--tmd-element, none);
4
- `,L(s,C.fontFamily);const b=document.createElement("div");b.style.cssText="display: flex; justify-content: center; column-gap: 1vw; width: 100%;";const u=document.createElement("b");u.textContent=n+":",u.style.cssText="width: 100%; font-size: clamp(10px, 2.4vw, 24px); color: var(--tmd-text, black);";const h=document.createElement("div");h.style.cssText=`display: flex; gap: 1vw; flex-wrap: wrap; align-content: flex-start;
5
- overflow-y: scroll;`;const v=document.createElement("input");v.style.cssText="border: none; outline: none; background: none; height: fit-content; flex-grow: 1; padding: 0.8vw; width: 6vw; font-size: clamp(8px, 2vw, 20px);";const y=(x,E)=>{const A=this.createButton({icon:x,place:!1,onClick:E,style:"default",modules:{icon:[new H({width:"70%",height:"70%"})]}});A.style.width="2em",A.style.aspectRatio="1/1",b.append(A)},S=x=>{const E=document.createElement("div");E.style.cssText="cursor: pointer; background: var(--tmd-element-hover, rgb(206, 206, 206)); color: var(--tmd-text, black); height: fit-content; padding: 0.8vw; border-radius: 0.8vw; font-size: clamp(8px, 2vw, 20px);",E.textContent=x,h.insertBefore(E,v),E.addEventListener("click",A=>{E.style.border===""?E.style.border="2px solid red":E.style.border="",A.stopPropagation()}),a.push(x)};return y(T(F),()=>{if(typeof r=="function"&&r())return s.classList.add("zcDisabled");h.innerHTML="",a.splice(0,a.length),h.append(v),t.forEach(x=>S(String(x))),typeof c=="function"&&c(d?a.map(x=>parseInt(x)):a)}),y(T(W),()=>{if(typeof r=="function"&&r())return s.classList.add("zcDisabled");for(const x of[...h.children])x.getAttribute("style").includes("border: 2px solid red;")&&(a.splice(a.indexOf(x.textContent),1),x.remove());typeof c=="function"&&c(d?a.map(x=>parseInt(x)):a)}),typeof r=="function"&&r()&&s.classList.add("zcDisabled"),v.addEventListener("keypress",x=>{if(document.activeElement===v)switch(x.key){case"Enter":if(d&&Number.isNaN(parseInt(v.value))||v.value.trim()==="")return;if(typeof r=="function"&&r())return s.classList.add("zcDisabled");S(v.value),v.value="",typeof c=="function"&&c(d?a.map(E=>parseInt(E)):a);break}}),s.addEventListener("click",x=>{x.currentTarget==s&&v.focus()}),h.append(v),s.append(b,u,h),this.addElement(s,{x:e,y:o,width:l,height:i,anchor:p,place:m,modules:f,modulesMap:{base:s,input:v}}),t.forEach(x=>S(String(x))),s}createImage({x:e,y:o,width:l,src:i,place:n=!0,anchor:t="top-left",modules:f}){const p=document.createElement("img");return p.style.height="auto",p.src=i,this.addElement(p,{x:e,y:o,width:l,height:0,anchor:t,place:n,modules:f,modulesMap:{base:p}}),p}createSvg({x:e,y:o,size:l,dataurl:i,place:n=!0,anchor:t="top-left",fill:f="var(--tmd-accent, black)",stroke:p="var(--tmd-accent-hover, black)",strokeWidth:m="2px",modules:d}){function r(s){const b=s.replace("data:image/svg+xml,",""),u=decodeURIComponent(b),h=document.createElement("div");return h.innerHTML=u,h.firstElementChild}function c(s,{fill:b,stroke:u}){return s.querySelectorAll("*").forEach(v=>{v.getAttribute("fill")!=="none"&&v.setAttribute("fill",b),v.getAttribute("stroke")!=="none"&&v.setAttribute("stroke",u)}),s.getAttribute("fill")!=="none"&&s.setAttribute("fill",b),s.getAttribute("stroke")!=="none"&&s.setAttribute("stroke",u),s}const a=r(i);return c(a,{fill:f,stroke:p}),a.setAttribute("stroke-width",m),this.addElement(a,{x:e,y:o,width:l,height:l,anchor:t,place:n,modules:d,modulesMap:{base:a}}),a}createBackNextButton({x:e,y:o,width:l,height:i,items:n,currentIndex:t,modules:f,isBold:p=!1,anchor:m="top-left",place:d=!0,onChange:r,isDisabled:c}){const a=document.createElement("div");a.classList.add("zcBackNextButton"),L(a,C.fontFamily);const s=()=>{t===0||typeof c=="function"&&c(n[t-1][1])?b.classList.add("zcBackNextButton-btnDisabled"):b.classList.remove("zcBackNextButton-btnDisabled"),t===n.length-1||typeof c=="function"&&c(n[t+1][1])?u.classList.add("zcBackNextButton-btnDisabled"):u.classList.remove("zcBackNextButton-btnDisabled")},b=document.createElement("button");b.style.cssText=`
6
- position: absolute; left: 1vw; font-size: 3.5vw; aspect-ratio: 1/1;
7
- height: 140%; background-image: url("Icons/Prev.png"); background-size: 100%;
8
- `,b.classList.add("zcButton"),b.addEventListener("click",()=>{if(t===0||typeof c=="function"&&c(n[t-1][1]))return b.classList.add("zcDisabled");t--,h.textContent=n[t][0],typeof r=="function"&&r(n[t][1]),s()});const u=document.createElement("button");u.style.cssText=`
9
- position: absolute; right: 1vw; font-size: 3.5vw; aspect-ratio: 1/1;
10
- height: 140%; background-image: url("Icons/Next.png"); background-size: 100%;
11
- `,u.classList.add("zcButton"),u.addEventListener("click",()=>{if(t===n.length-1||typeof c=="function"&&c(n[t+1][1]))return u.classList.add("zcDisabled");t++,h.textContent=n[t][0],typeof r=="function"&&r(n[t][1]),s()}),s();const h=document.createElement("p");return p&&(h.style.fontWeight="bold"),h.textContent=n[t][0],a.append(b,h,u),this.addElement(a,{x:e,y:o,width:l,height:i,anchor:m,place:d,modules:f,modulesMap:{base:a,backButton:b,nextButton:u,text:h}}),a}createTabs({x:e,y:o,width:l,tabs:i,anchor:n="top-left",place:t=!0,currentTabName:f,modules:p}){let m=[];const d=document.createElement("div");return d.classList.add("zcTabs"),L(d,C.fontFamily),i.forEach(r=>{const c=()=>{for(const b of d.children)b.removeAttribute("data-opened");for(const b of m)b instanceof Node&&document.body.removeChild(b);m=[],a.setAttribute("data-opened","true");const s=document.body.append.bind(document.body);document.body.append=(...b)=>{m.push(...b),s(...b)},this.tabHandlers.unload?.(),this.tabHandlers.exit?.(),r.load(),this.tabHandlers={run:r.run,load:r.load,unload:r.unload,exit:r.exit},document.body.append=s},a=document.createElement("button");a.textContent=r.name,r.name===f&&c(),a.addEventListener("click",c),d.append(a)}),this.addElement(d,{x:e,y:o,width:l,anchor:n,place:t,modules:p,modulesMap:{base:d}}),d}drawPolylineArrow({points:e,strokeColor:o=z()?.base?.text??"black",lineWidth:l=2,circleRadius:i=5,circleColor:n=z()?.base?.text??"black"}){if(e.length<2)return;const t=MainCanvas.canvas.getContext("2d");t.save(),t.strokeStyle=o,t.lineWidth=l,t.fillStyle=n,t.beginPath(),t.moveTo(e[0].x,e[0].y);for(let f=1;f<e.length;f++)t.lineTo(e[f].x,e[f].y);t.stroke(),t.beginPath(),t.arc(e[0].x,e[0].y,i,0,Math.PI*2),t.fill(),t.beginPath(),t.arc(e[e.length-1].x,e[e.length-1].y,i,0,Math.PI*2),t.fill(),t.restore()}createCard({x:e,y:o,name:l,value:i,icon:n,anchor:t="top-left",place:f=!0,modules:p}){const m=document.createElement("div");m.classList.add("zcCard");const d=document.createElement("p");d.classList.add("zcCard_name"),d.textContent=l;const r=document.createElement("p");return r.classList.add("zcCard_value"),r.textContent=`${i}`,n&&(n.style.cssText+="position: absolute; top: 0.4em; right: 0.4em; width: 1.2em; height: 1.2em;",m.append(n)),m.append(d,r),this.addElement(m,{x:e,y:o,anchor:t,place:f,modules:p,modulesMap:{name:d,value:r,base:m,icon:null}}),m}createSelect({x:e,y:o,width:l,options:i,currentOption:n,anchor:t="top-left",place:f=!0,modules:p,onChange:m,isDisabled:d}){let r=!1,c;const a=document.createElement("div");a.classList.add("zcSelect"),a.setAttribute("opened",!1),a.addEventListener("click",()=>{if(d&&d())return a.classList.add("zcDisabled");r?(r=!1,c.remove()):(r=!0,c=document.createElement("div"),c.setAttribute("data-zc-position",typeof o=="number"&&o>500-a.offsetHeight/2?"top":"bottom"),i.forEach(h=>{const v=document.createElement("div");v.style.cssText="display: flex; align-items: center; column-gap: 0.5em;",h.icon&&(h.icon.style.cssText="color: #bcbcbc;",v.append(h.icon)),v.append(h.text),h.name===n&&v.append(u),v.addEventListener("click",()=>{n=h.name,s.textContent=h.text,c.remove(),m&&m(h.name)}),c.append(v)}),a.append(c))});const s=document.createElement("p");s.textContent=i.find(h=>h.name===n).text;const b=T(I),u=T(N);return u.style.cssText="position: absolute; right: 0.25em;",a.append(s,b),d&&d()&&a.classList.add("zcDisabled"),this.addElement(a,{x:e,y:o,width:l,anchor:t,place:f,modules:p,modulesMap:{base:a}}),a}createContainer({x:e,y:o,width:l,height:i,anchor:n="top-left",place:t=!0,modules:f}){const p=document.createElement("div");return this.addElement(p,{x:e,y:o,width:l,height:i,anchor:n,place:t,modules:f,modulesMap:{base:p}}),p}}const M={};function ne(g,e){M[g]||(M[g]=[]),M[g].push(e)}export{te as BaseSubscreen,Q as addDynamicClass,X as autosetFontSize,q as dataUrlSvgWithColor,ee as getCurrentSubscreen,D as getRelativeHeight,P as getRelativeWidth,R as getRelativeX,V as getRelativeY,ne as hookSubscreen,L as setFontFamily,j as setFontSize,G as setPadding,O as setPosition,U as setPreviousSubscreen,J as setSize,$ as setSubscreen};
1
+ import { getThemedColorsModule, SubscreenLoadedEvent, SubscreenUnloadedEvent } from "./index";
2
+ import { StyleModule } from "./shard-modules";
3
+ import { MOD_DATA } from "./index";
4
+ import { ButtonShard, TextShard, InputShard, CheckboxShard, InputListShard, ImageShard, SvgShard, BackNextButtonShard, TabsShard, CardShard, SelectShard, ContainerShard } from "./shards";
5
+ import { logger } from "./logging";
6
+ function hexToRgb(hex) {
7
+ hex = hex.replace("#", "");
8
+ const r = parseInt(hex.substring(0, 2), 16);
9
+ const g = parseInt(hex.substring(2, 4), 16);
10
+ const b = parseInt(hex.substring(4, 6), 16);
11
+ return `rgb(${r}, ${g}, ${b})`;
12
+ }
13
+ function dataUrlSvgWithColor(dataUrl, newColor) {
14
+ return dataUrl.replace(/fill="[^"]*"/g, `fill="${newColor}"`).replace(/stroke="[^"]*"/g, `stroke="${newColor}"`);
15
+ }
16
+ function dataUrlSvgReplaceVars(dataUrl, vars) {
17
+ for (let [name, value] of Object.entries(vars)) {
18
+ if (value.startsWith("#")) {
19
+ value = hexToRgb(value);
20
+ }
21
+ dataUrl = dataUrl.replaceAll(`$${name}`, value);
22
+ }
23
+ return dataUrl;
24
+ }
25
+ function cssVar(name, fallback) {
26
+ const value = getComputedStyle(document.documentElement).getPropertyValue(name).trim();
27
+ return value || fallback;
28
+ }
29
+ function getRelativeHeight(height) {
30
+ return height * (MainCanvas.canvas.clientHeight / 1e3);
31
+ }
32
+ function getRelativeWidth(width) {
33
+ return width * (MainCanvas.canvas.clientWidth / 2e3);
34
+ }
35
+ function getRelativeY(yPos, anchorPosition = "top") {
36
+ const scaleY = MainCanvas.canvas.clientHeight / 1e3;
37
+ return anchorPosition === "top" ? MainCanvas.canvas.offsetTop + yPos * scaleY : window.innerHeight - (MainCanvas.canvas.offsetTop + MainCanvas.canvas.clientHeight) + yPos * scaleY;
38
+ }
39
+ function getRelativeX(xPos, anchorPosition = "left") {
40
+ const scaleX = MainCanvas.canvas.clientWidth / 2e3;
41
+ return anchorPosition === "left" ? MainCanvas.canvas.offsetLeft + xPos * scaleX : window.innerWidth - (MainCanvas.canvas.offsetLeft + MainCanvas.canvas.clientWidth) + xPos * scaleX;
42
+ }
43
+ function setPosition(element, xPos, yPos, anchor = "top-left") {
44
+ const yAnchor = anchor === "top-left" || anchor === "top-right" ? "top" : "bottom";
45
+ const xAnchor = anchor === "top-left" || anchor === "bottom-left" ? "left" : "right";
46
+ const y = getRelativeY(yPos, yAnchor);
47
+ const x = getRelativeX(xPos, xAnchor);
48
+ Object.assign(element.style, {
49
+ position: "fixed",
50
+ [xAnchor]: x + "px",
51
+ [yAnchor]: y + "px"
52
+ });
53
+ }
54
+ function setSize(element, width, height) {
55
+ Object.assign(element.style, {
56
+ width: getRelativeWidth(width) + "px",
57
+ height: getRelativeHeight(height) + "px"
58
+ });
59
+ }
60
+ function setFontSize(element, targetFontSize) {
61
+ const canvasWidth = MainCanvas.canvas.clientWidth;
62
+ const canvasHeight = MainCanvas.canvas.clientHeight;
63
+ const scaleFactor = Math.min(canvasWidth, canvasHeight) / 100;
64
+ const fontSize = targetFontSize * scaleFactor;
65
+ Object.assign(element.style, {
66
+ fontSize: fontSize + "px"
67
+ });
68
+ }
69
+ function setFontFamily(element, fontFamily) {
70
+ element.style.fontFamily = fontFamily ?? "sans-serif";
71
+ }
72
+ function setPadding(element, targetPadding) {
73
+ const canvasWidth = MainCanvas.canvas.clientWidth;
74
+ const canvasHeight = MainCanvas.canvas.clientHeight;
75
+ const scaleFactor = Math.min(canvasWidth, canvasHeight) / 100;
76
+ const paddingValue = targetPadding * scaleFactor;
77
+ Object.assign(element.style, {
78
+ padding: paddingValue + "px"
79
+ });
80
+ }
81
+ function autosetFontSize(element) {
82
+ const Font = MainCanvas.canvas.clientWidth <= MainCanvas.canvas.clientHeight * 2 ? MainCanvas.canvas.clientWidth / 50 : MainCanvas.canvas.clientHeight / 25;
83
+ Object.assign(element.style, {
84
+ fontSize: Font + "px"
85
+ });
86
+ }
87
+ const createdDynamicClasses = [];
88
+ function generateDynamicClassCacheKey(styles) {
89
+ const sortedStringify = (obj) => {
90
+ if (!obj) return "null";
91
+ return JSON.stringify(
92
+ Object.keys(obj).sort().reduce((acc, key) => {
93
+ acc[key] = obj[key];
94
+ return acc;
95
+ }, {})
96
+ );
97
+ };
98
+ let cacheKey = "";
99
+ for (const [key, value] of Object.entries(styles)) {
100
+ if (value === void 0) continue;
101
+ cacheKey += `${key}:=${sortedStringify(value)}|`;
102
+ }
103
+ return cacheKey;
104
+ }
105
+ function addDynamicClass(targetElement, styles) {
106
+ const cacheKey = generateDynamicClassCacheKey(styles);
107
+ const _class = createdDynamicClasses.find((g) => g.key === cacheKey);
108
+ if (_class) return targetElement.classList.add(_class.className);
109
+ let className;
110
+ do {
111
+ className = "dynamic-" + Math.random().toString(36).substring(2, 10);
112
+ } while (createdDynamicClasses.find((g) => g.className === className));
113
+ createdDynamicClasses.push({
114
+ key: cacheKey,
115
+ className
116
+ });
117
+ const buildCssBlock = (selector, styleRules) => {
118
+ let css = `${selector} {`;
119
+ for (const [property, value] of Object.entries(styleRules)) {
120
+ css += `${property.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase()}: ${value};`;
121
+ }
122
+ css += "}";
123
+ return css;
124
+ };
125
+ let cssRules = "";
126
+ for (const [key, value] of Object.entries(styles)) {
127
+ if (value === void 0) continue;
128
+ if (key === "base") {
129
+ cssRules += buildCssBlock(`.${className}`, value);
130
+ } else if (["hover", "active", "focus", "disabled", "before", "after"].includes(key)) {
131
+ cssRules += buildCssBlock(`.${className}:${key}`, value);
132
+ } else {
133
+ cssRules += buildCssBlock(`.${className}${key}`, value);
134
+ }
135
+ }
136
+ let styleElement = document.getElementById(`${MOD_DATA.key ?? ""}-dynamic-classes`);
137
+ if (styleElement) {
138
+ styleElement.textContent += cssRules;
139
+ } else {
140
+ styleElement = document.createElement("style");
141
+ styleElement.id = `${MOD_DATA.key ?? ""}-dynamic-classes`;
142
+ styleElement.textContent = cssRules;
143
+ document.head.appendChild(styleElement);
144
+ }
145
+ targetElement.classList.add(className);
146
+ }
147
+ function setPreviousSubscreen() {
148
+ setSubscreen(previousSubscreen);
149
+ }
150
+ let previousSubscreen = null;
151
+ let currentSubscreen = null;
152
+ function setSubscreen(subscreen) {
153
+ previousSubscreen = currentSubscreen;
154
+ currentSubscreen = subscreen;
155
+ if (previousSubscreen) {
156
+ try {
157
+ previousSubscreen.unload();
158
+ } catch (e) {
159
+ logger.error("Failed to unload subscreen", previousSubscreen);
160
+ }
161
+ window.dispatchEvent(new SubscreenUnloadedEvent({ subscreen: previousSubscreen }));
162
+ }
163
+ if (subscreen) {
164
+ try {
165
+ subscreen.load();
166
+ } catch (e) {
167
+ logger.error("Failed to load subscreen", subscreen);
168
+ }
169
+ window.dispatchEvent(new SubscreenLoadedEvent({ subscreen }));
170
+ }
171
+ }
172
+ function getCurrentSubscreen() {
173
+ return currentSubscreen;
174
+ }
175
+ function getPreviousSubscreen() {
176
+ return previousSubscreen;
177
+ }
178
+ class BaseSubscreen {
179
+ setSubscreen = setSubscreen;
180
+ get currentSubscreen() {
181
+ return getCurrentSubscreen();
182
+ }
183
+ get previousSubscreen() {
184
+ return getPreviousSubscreen();
185
+ }
186
+ run() {
187
+ }
188
+ load() {
189
+ this.createButton({
190
+ x: 1815,
191
+ y: 75,
192
+ width: 90,
193
+ height: 90,
194
+ icon: "Icons/Exit.png",
195
+ tooltip: {
196
+ position: "left",
197
+ text: "Back"
198
+ },
199
+ modules: {
200
+ base: [
201
+ new StyleModule({
202
+ zIndex: "10"
203
+ })
204
+ ]
205
+ }
206
+ }).addEventListener("click", () => this.exit());
207
+ if (this.name) {
208
+ this.createText({
209
+ text: this.name,
210
+ x: 100,
211
+ y: 60,
212
+ fontSize: 8
213
+ }).style.cssText += "max-width: 85%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0.1em;";
214
+ }
215
+ if (subscreenHooks[this.constructor.name]) {
216
+ subscreenHooks[this.name].forEach((hook) => hook(this));
217
+ }
218
+ }
219
+ unload() {
220
+ }
221
+ click() {
222
+ }
223
+ exit() {
224
+ setPreviousSubscreen();
225
+ }
226
+ update() {
227
+ }
228
+ setPreviousSubscreen() {
229
+ setPreviousSubscreen();
230
+ }
231
+ create(shard) {
232
+ const htmlElement = shard.mount();
233
+ return htmlElement;
234
+ }
235
+ createButton(ctx) {
236
+ const shard = new ButtonShard(ctx);
237
+ const htmlElement = shard.mount();
238
+ return htmlElement;
239
+ }
240
+ createText(ctx) {
241
+ const shard = new TextShard(ctx);
242
+ const htmlElement = shard.mount();
243
+ return htmlElement;
244
+ }
245
+ createInput(ctx) {
246
+ const shard = new InputShard(ctx);
247
+ const htmlElement = shard.mount();
248
+ return htmlElement;
249
+ }
250
+ createCheckbox(ctx) {
251
+ const shard = new CheckboxShard(ctx);
252
+ const htmlElement = shard.mount();
253
+ return htmlElement;
254
+ }
255
+ createInputList(ctx) {
256
+ const shard = new InputListShard(ctx);
257
+ const htmlElement = shard.mount();
258
+ return htmlElement;
259
+ }
260
+ createImage(ctx) {
261
+ const shard = new ImageShard(ctx);
262
+ const htmlElement = shard.mount();
263
+ return htmlElement;
264
+ }
265
+ createSvg(ctx) {
266
+ const shard = new SvgShard(ctx);
267
+ const htmlElement = shard.mount();
268
+ return htmlElement;
269
+ }
270
+ createBackNextButton(ctx) {
271
+ const shard = new BackNextButtonShard(ctx);
272
+ const htmlElement = shard.mount();
273
+ return htmlElement;
274
+ }
275
+ createTabs(ctx) {
276
+ const shard = new TabsShard(ctx);
277
+ const htmlElement = shard.mount();
278
+ return htmlElement;
279
+ }
280
+ drawPolylineArrow({
281
+ points,
282
+ strokeColor = getThemedColorsModule()?.base?.text ?? "black",
283
+ lineWidth = 2,
284
+ circleRadius = 5,
285
+ circleColor = getThemedColorsModule()?.base?.text ?? "black"
286
+ }) {
287
+ if (points.length < 2) return;
288
+ const ctx = MainCanvas.canvas.getContext("2d");
289
+ if (!ctx) return;
290
+ ctx.save();
291
+ ctx.strokeStyle = strokeColor;
292
+ ctx.lineWidth = lineWidth;
293
+ ctx.fillStyle = circleColor;
294
+ ctx.beginPath();
295
+ ctx.moveTo(points[0].x, points[0].y);
296
+ for (let i = 1; i < points.length; i++) {
297
+ ctx.lineTo(points[i].x, points[i].y);
298
+ }
299
+ ctx.stroke();
300
+ ctx.beginPath();
301
+ ctx.arc(points[0].x, points[0].y, circleRadius, 0, Math.PI * 2);
302
+ ctx.fill();
303
+ ctx.beginPath();
304
+ ctx.arc(points[points.length - 1].x, points[points.length - 1].y, circleRadius, 0, Math.PI * 2);
305
+ ctx.fill();
306
+ ctx.restore();
307
+ }
308
+ createCard(ctx) {
309
+ const shard = new CardShard(ctx);
310
+ const htmlElement = shard.mount();
311
+ return htmlElement;
312
+ }
313
+ createSelect(ctx) {
314
+ const shard = new SelectShard(ctx);
315
+ const htmlElement = shard.mount();
316
+ return htmlElement;
317
+ }
318
+ createContainer(ctx) {
319
+ const shard = new ContainerShard(ctx);
320
+ const htmlElement = shard.mount();
321
+ return htmlElement;
322
+ }
323
+ }
324
+ const subscreenHooks = {};
325
+ function hookSubscreen(subscreenName, hook) {
326
+ if (!subscreenHooks[subscreenName]) subscreenHooks[subscreenName] = [];
327
+ subscreenHooks[subscreenName].push(hook);
328
+ }
329
+ export {
330
+ BaseSubscreen,
331
+ addDynamicClass,
332
+ autosetFontSize,
333
+ cssVar,
334
+ dataUrlSvgReplaceVars,
335
+ dataUrlSvgWithColor,
336
+ getCurrentSubscreen,
337
+ getPreviousSubscreen,
338
+ getRelativeHeight,
339
+ getRelativeWidth,
340
+ getRelativeX,
341
+ getRelativeY,
342
+ hexToRgb,
343
+ hookSubscreen,
344
+ setFontFamily,
345
+ setFontSize,
346
+ setPadding,
347
+ setPosition,
348
+ setPreviousSubscreen,
349
+ setSize,
350
+ setSubscreen
351
+ };
@@ -1 +1,31 @@
1
- import{plainToInstance as o}from"class-transformer";import{validate as i}from"class-validator";export*from"class-validator";export*from"class-transformer";async function c(e,t){try{const r=o(t,e),a=await i(r);return a.length>0?{isValid:!1,errors:a.flatMap(s=>Object.values(s.constraints||{}))}:{isValid:!0,validatedData:r}}catch(r){return{isValid:!1,errors:["Validation error: "+r.message]}}}export{c as validateData};
1
+ import { plainToInstance } from "class-transformer";
2
+ import { validate } from "class-validator";
3
+ export * from "class-validator";
4
+ export * from "class-transformer";
5
+ async function validateData(data, dtoClass) {
6
+ try {
7
+ const dtoInstance = plainToInstance(dtoClass, data);
8
+ const errors = await validate(dtoInstance);
9
+ if (errors.length > 0) {
10
+ const errorMessages = errors.flatMap(
11
+ (error) => Object.values(error.constraints || {})
12
+ );
13
+ return {
14
+ isValid: false,
15
+ errors: errorMessages
16
+ };
17
+ }
18
+ return {
19
+ isValid: true,
20
+ validatedData: dtoInstance
21
+ };
22
+ } catch (error) {
23
+ return {
24
+ isValid: false,
25
+ errors: ["Validation error: " + error.message]
26
+ };
27
+ }
28
+ }
29
+ export {
30
+ validateData
31
+ };
package/dist/wardrobe.js CHANGED
@@ -1 +1,167 @@
1
- import{normalizeObject as l}from"./index";class m{seedsCache=new Map;getSeed(e){const r=l(ServerAppearanceBundle(e)),o=JSON.stringify(r);return this.seedsCache.has(o)||this.seedsCache.set(o,this.generateSeed(o)),this.seedsCache.get(o)}generateSeed(e){let r=0;for(let o=0;o<e.length;o++){const a=e.charCodeAt(o);r=(r<<5)-r+a,r=r&r}return r}compare(e,r){return this.getSeed(e)===this.getSeed(r)}getDifference(e,r){const o={added:[],modified:[],removed:[]};if(this.compare(e,r))return o;const a=ServerBuildAppearanceDiff("Female3DCG",e,ServerAppearanceBundle(r));for(const[i,s]of Object.entries(a)){if(s[0]===null&&s[1]!==null){o.added.push(s[1].Asset.Description);continue}if(s[0]!==null&&s[1]===null){o.removed.push(s[0].Asset.Description);continue}if(s[0].Asset.Name!==s[1].Asset.Name){o.removed.push(s[0].Asset.Description),o.added.push(s[1].Asset.Description);continue}this.compare([s[0]],[s[1]])||o.modified.push(s[0].Asset.Description)}return o}}const I=new m;function G(t){const e=Asset.includes(t)?t:t.Asset;if(!Asset.includes(e))throw new Error("Failed to convert item to asset");return e}function p(t){const e=AssetGroup.includes(t)?t:Asset.includes(t)?t.Group:t.Asset.Group;if(!AssetGroup.includes(e))throw new Error("Failed to convert item to group");return e}function y(t){return t?.Craft?.Name?t.Craft.Name:t?.Asset?.Description}function N(t){return AssetGroup.some(e=>e.Name===t)}function g(t,e=!1){const r=p(t);return r.Category==="Appearance"&&r.AllowNone&&r.Clothing&&(e||!r.BodyCosplay)}function f(t){const e=p(t);return e.Category==="Appearance"&&e.AllowNone&&e.Clothing&&e.BodyCosplay}function u(t){const e=p(t);return e.Category==="Appearance"&&!e.Clothing}function A(t,e=["ItemNeck","ItemNeckAccessories","ItemNeckRestraints"]){const r=p(t);return r.Category!=="Item"||r.BodyCosplay?!1:!e.includes(r.Name)}function h(t,e,r=["Cosplay","Binds","Collar","Locks"],o=t,a=!1){e=e.filter(s=>!!s&&!u(s)),r.includes("Cosplay")||(e=e.filter(s=>!f(s))),r.includes("Binds")||(e=e.filter(s=>!A(s))),r.includes("Collar")||(e=e.filter(s=>s.Asset.Group.Name!=="ItemNeck")),r.includes("Locks")||(e=e.map(s=>(s.Property?.LockedBy&&delete s.Property.LockedBy,s)));const i=[];if(a)t.Appearance=t.Appearance.filter(s=>u(s));else{const s=ValidationCreateDiffParams(o,Player.MemberNumber);t.Appearance=t.Appearance.filter(n=>u(n)||!ValidationCanRemoveItem(n,s,!!e.find(c=>c?.Asset?.Group?.Name===n?.Asset?.Group?.Name))||n.Property?.LockedBy&&!DialogCanUnlock(o,n)||n.Asset.Name==="SlaveCollar"&&o.IsPlayer()?(i.push(n.Asset.Group.Name),!0):!1)}for(const s of e){if(!a&&(!d(o,s.Asset.Group.Name,s.Asset)||i.includes(s.Asset.Group.Name)))continue;CharacterAppearanceSetItem(t,s.Asset.Group.Name,s.Asset,s.Color);const n=InventoryGet(t,s.Asset.Group.Name);s.Craft&&CraftingValidate(s.Craft,s.Asset)!==CraftingStatusType.CRITICAL_ERROR&&(n.Craft=s.Craft),s.Property&&(ValidationSanitizeProperties(t,s),n.Property=s.Property)}CharacterRefresh(t),t.IsNpc()||ChatRoomCharacterUpdate(t)}function d(t,e,r){return!ValidationIsItemBlockedOrLimited(t,Player.MemberNumber,e,r.Name)&&ServerChatRoomGetAllowItem(Player,t)}function v(t,e){return e.map(r=>ServerBundledItemToAppearanceItem(t,r))}function B(t){AssetGroup.forEach(e=>{if(e.Category!=="Appearance"||e.AllowNone||t.find(o=>o.Asset.Group.Name===e.Name))return;const r=AssetGet("Female3DCG",e.Name,e.Asset[0]?.Name);r&&t.push({Asset:r,Color:e.DefaultColor})})}export{B as addRequiredAppearanceItems,I as appearanceComparer,h as importAppearance,N as isAssetGroupName,A as isBind,u as isBody,g as isCloth,f as isCosplay,v as serverAppearanceBundleToAppearance,G as smartGetAsset,p as smartGetAssetGroup,y as smartGetItemName,d as validationCanAccessCheck};
1
+ import { normalizeObject } from "./index";
2
+ class AppearanceComparer {
3
+ seedsCache = /* @__PURE__ */ new Map();
4
+ getSeed(arr) {
5
+ const normalized = normalizeObject(ServerAppearanceBundle(arr));
6
+ const key = JSON.stringify(normalized);
7
+ if (!this.seedsCache.has(key)) {
8
+ this.seedsCache.set(key, this.generateSeed(key));
9
+ }
10
+ return this.seedsCache.get(key);
11
+ }
12
+ generateSeed(str) {
13
+ let seed = 0;
14
+ for (let i = 0; i < str.length; i++) {
15
+ const char = str.charCodeAt(i);
16
+ seed = (seed << 5) - seed + char;
17
+ seed = seed & seed;
18
+ }
19
+ return seed;
20
+ }
21
+ compare(arr1, arr2) {
22
+ return this.getSeed(arr1) === this.getSeed(arr2);
23
+ }
24
+ getDifference(arr1, arr2) {
25
+ const diff = {
26
+ added: [],
27
+ modified: [],
28
+ removed: []
29
+ };
30
+ if (this.compare(arr1, arr2)) return diff;
31
+ const diffMap = ServerBuildAppearanceDiff("Female3DCG", arr1, ServerAppearanceBundle(arr2));
32
+ for (const [group, diffResult] of Object.entries(diffMap)) {
33
+ if (diffResult[0] === null && diffResult[1] !== null) {
34
+ diff.added.push(diffResult[1].Asset.Description);
35
+ continue;
36
+ }
37
+ if (diffResult[0] !== null && diffResult[1] === null) {
38
+ diff.removed.push(diffResult[0].Asset.Description);
39
+ continue;
40
+ }
41
+ if (diffResult[0].Asset.Name !== diffResult[1].Asset.Name) {
42
+ diff.removed.push(diffResult[0].Asset.Description);
43
+ diff.added.push(diffResult[1].Asset.Description);
44
+ continue;
45
+ }
46
+ if (!this.compare([diffResult[0]], [diffResult[1]])) diff.modified.push(diffResult[0].Asset.Description);
47
+ }
48
+ return diff;
49
+ }
50
+ }
51
+ const appearanceComparer = new AppearanceComparer();
52
+ function smartGetAsset(item) {
53
+ const asset = Asset.includes(item) ? item : item.Asset;
54
+ if (!Asset.includes(asset)) {
55
+ throw new Error("Failed to convert item to asset");
56
+ }
57
+ return asset;
58
+ }
59
+ function smartGetAssetGroup(item) {
60
+ const group = AssetGroup.includes(item) ? item : Asset.includes(item) ? item.Group : item.Asset.Group;
61
+ if (!AssetGroup.includes(group)) {
62
+ throw new Error("Failed to convert item to group");
63
+ }
64
+ return group;
65
+ }
66
+ function smartGetItemName(item) {
67
+ if (item?.Craft?.Name) return item.Craft.Name;
68
+ return item?.Asset?.Description;
69
+ }
70
+ function isAssetGroupName(name) {
71
+ return AssetGroup.some((group) => group.Name === name);
72
+ }
73
+ function isCloth(item, allowCosplay = false) {
74
+ const group = smartGetAssetGroup(item);
75
+ return group.Category === "Appearance" && group.AllowNone && group.Clothing && (allowCosplay || !group.BodyCosplay);
76
+ }
77
+ function isCosplay(item) {
78
+ const group = smartGetAssetGroup(item);
79
+ return group.Category === "Appearance" && group.AllowNone && group.Clothing && group.BodyCosplay;
80
+ }
81
+ function isBody(item) {
82
+ const group = smartGetAssetGroup(item);
83
+ return group.Category === "Appearance" && !group.Clothing;
84
+ }
85
+ function isBind(item, excludeSlots = ["ItemNeck", "ItemNeckAccessories", "ItemNeckRestraints"]) {
86
+ const group = smartGetAssetGroup(item);
87
+ if (group.Category !== "Item" || group.BodyCosplay) return false;
88
+ return !excludeSlots.includes(group.Name);
89
+ }
90
+ function importAppearance(C, bundleToAttach, include = ["Cosplay", "Binds", "Collar", "Locks"], characterValidate = C, ignoreAccessValidation = false) {
91
+ bundleToAttach = bundleToAttach.filter((i) => !!i && !isBody(i));
92
+ if (!include.includes("Cosplay")) bundleToAttach = bundleToAttach.filter((i) => !isCosplay(i));
93
+ if (!include.includes("Binds")) bundleToAttach = bundleToAttach.filter((i) => !isBind(i));
94
+ if (!include.includes("Collar")) bundleToAttach = bundleToAttach.filter((i) => i.Asset.Group.Name !== "ItemNeck");
95
+ if (!include.includes("Locks")) bundleToAttach = bundleToAttach.map((i) => {
96
+ if (i.Property?.LockedBy) delete i.Property.LockedBy;
97
+ return i;
98
+ });
99
+ const blockedGroups = [];
100
+ if (ignoreAccessValidation) {
101
+ C.Appearance = C.Appearance.filter((a) => isBody(a));
102
+ } else {
103
+ const validationParams = ValidationCreateDiffParams(characterValidate, Player.MemberNumber);
104
+ C.Appearance = C.Appearance.filter((a) => {
105
+ if (isBody(a)) {
106
+ blockedGroups.push(a.Asset.Group.Name);
107
+ return true;
108
+ }
109
+ if (!ValidationCanRemoveItem(
110
+ a,
111
+ validationParams,
112
+ !!bundleToAttach.find((b) => b?.Asset?.Group?.Name === a?.Asset?.Group?.Name)
113
+ ) || a.Property?.LockedBy && !DialogCanUnlock(characterValidate, a) || a.Asset.Name === "SlaveCollar" && characterValidate.IsPlayer()) {
114
+ blockedGroups.push(a.Asset.Group.Name);
115
+ return true;
116
+ }
117
+ return false;
118
+ });
119
+ }
120
+ for (const item of bundleToAttach) {
121
+ if (!ignoreAccessValidation) {
122
+ if (!validationCanAccessCheck(characterValidate, item.Asset.Group.Name, item.Asset)) continue;
123
+ if (blockedGroups.includes(item.Asset.Group.Name)) continue;
124
+ }
125
+ const _item = CharacterAppearanceSetItem(C, item.Asset.Group.Name, item.Asset, item.Color);
126
+ if (!_item) continue;
127
+ if (item.Craft && CraftingValidate(item.Craft, item.Asset) !== CraftingStatusType.CRITICAL_ERROR) _item.Craft = item.Craft;
128
+ if (item.Property) {
129
+ ValidationSanitizeProperties(C, item);
130
+ _item.Property = item.Property;
131
+ }
132
+ }
133
+ CharacterRefresh(C);
134
+ if (!C.IsNpc()) ChatRoomCharacterUpdate(C);
135
+ }
136
+ function validationCanAccessCheck(C, group, asset) {
137
+ return !ValidationIsItemBlockedOrLimited(C, Player.MemberNumber, group, asset.Name) && ServerChatRoomGetAllowItem(Player, C);
138
+ }
139
+ function serverAppearanceBundleToAppearance(assetFamily, serverAppearanceBundle) {
140
+ return serverAppearanceBundle.map((t) => {
141
+ return ServerBundledItemToAppearanceItem(assetFamily, t);
142
+ }).filter((i) => !!i);
143
+ }
144
+ function addRequiredAppearanceItems(appearanceBundle) {
145
+ AssetGroup.forEach((group) => {
146
+ if (group.Category !== "Appearance" || group.AllowNone) return;
147
+ if (appearanceBundle.find((i) => i.Asset.Group.Name === group.Name)) return;
148
+ const asset = AssetGet("Female3DCG", group.Name, group.Asset[0]?.Name);
149
+ if (!asset) return;
150
+ appearanceBundle.push({ Asset: asset, Color: group.DefaultColor });
151
+ });
152
+ }
153
+ export {
154
+ addRequiredAppearanceItems,
155
+ appearanceComparer,
156
+ importAppearance,
157
+ isAssetGroupName,
158
+ isBind,
159
+ isBody,
160
+ isCloth,
161
+ isCosplay,
162
+ serverAppearanceBundleToAppearance,
163
+ smartGetAsset,
164
+ smartGetAssetGroup,
165
+ smartGetItemName,
166
+ validationCanAccessCheck
167
+ };