zois-core 1.2.1 → 2.0.1

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