@ekg_gg/devkit 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @ekg_gg/devkit
|
|
2
|
+
|
|
3
|
+
The official development toolkit for building [EKG.gg](https://ekg.gg) streaming widgets. Provides a local dev server with live preview, hot reloading, test events, and a build pipeline for publishing widgets to the EKG.gg marketplace.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm create ekg@latest my-widget
|
|
9
|
+
cd my-widget
|
|
10
|
+
npm run dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
This scaffolds a new widget project and starts the dev server at `http://localhost:5173`.
|
|
14
|
+
|
|
15
|
+
For a full guide on building widgets, see the [Getting Started](https://github.com/ekggg/getting-started) documentation.
|
|
16
|
+
|
|
17
|
+
## CLI Commands
|
|
18
|
+
|
|
19
|
+
### `ekg dev [dir]`
|
|
20
|
+
|
|
21
|
+
Starts the local development server with:
|
|
22
|
+
|
|
23
|
+
- Live widget preview at configurable dimensions
|
|
24
|
+
- Hot reloading on file changes
|
|
25
|
+
- Settings panel for testing widget configuration
|
|
26
|
+
- Test event buttons for every supported event type
|
|
27
|
+
- Auto-generated TypeScript types from your manifest
|
|
28
|
+
|
|
29
|
+
### `ekg build [dir]`
|
|
30
|
+
|
|
31
|
+
Validates your manifest, compiles TypeScript, and outputs a `dist/` folder ready to upload to the [EKG.gg artist portal](https://ekg.gg/app/artist/widgets).
|
|
32
|
+
|
|
33
|
+
### `ekg sync [dir]`
|
|
34
|
+
|
|
35
|
+
Re-downloads the EKG runtime files and regenerates TypeScript types without starting the dev server. Use `--force` to bypass the cache.
|
|
36
|
+
|
|
37
|
+
## Type Safety
|
|
38
|
+
|
|
39
|
+
The devkit auto-generates an `ekg.d.ts` file from your `manifest.json`, providing full TypeScript autocomplete for `ctx.settings` and `ctx.assets` specific to your widget. Types update automatically as you edit the manifest.
|
|
40
|
+
|
|
41
|
+
## How It Works
|
|
42
|
+
|
|
43
|
+
The dev server downloads the EKG widget runtime (QuickJS WASM, event schemas, and type definitions) from the EKG.gg servers and caches them locally. Your widget script is compiled with [tsdown](https://tsdown.dev/) and runs inside the same sandboxed environment used in production — so what you see locally is what streamers will see in OBS.
|
|
@@ -35,11 +35,11 @@ Error generating stack: `+e.message+`
|
|
|
35
35
|
newResult[${r}] = ${n}.value;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=$_,s=!z_.jitless,c=s&&ev.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?vb([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function xb(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!hv(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>vv(e,r,B_())))}),t)}const Sb=Q(`$ZodUnion`,(e,t)=>{Fy.init(e,t),J_(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),J_(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),J_(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),J_(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>G_(e.source)).join(`|`)})$`)}});let n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,a)=>{if(n)return r(i,a);let o=!1,s=[];for(let e of t.options){let t=e._zod.run({value:i.value,issues:[]},a);if(t instanceof Promise)s.push(t),o=!0;else{if(t.issues.length===0)return t;s.push(t)}}return o?Promise.all(s).then(t=>xb(t,i,e,a)):xb(s,i,e,a)}}),Cb=Q(`$ZodIntersection`,(e,t)=>{Fy.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>Tb(e,t,n)):Tb(e,i,a)}});function wb(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(tv(e)&&tv(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=wb(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=wb(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Tb(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),hv(e))return e;let r=wb(t.value,n.value);if(!r.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const Eb=Q(`$ZodRecord`,(e,t)=>{Fy.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!tv(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[];if(t.keyType._zod.values){let o=t.keyType._zod.values;n.value={};for(let e of o)if(typeof e==`string`||typeof e==`number`||typeof e==`symbol`){let o=t.valueType._zod.run({value:i[e],issues:[]},r);o instanceof Promise?a.push(o.then(t=>{t.issues.length&&n.issues.push(...gv(e,t.issues)),n.value[e]=t.value})):(o.issues.length&&n.issues.push(...gv(e,o.issues)),n.value[e]=o.value)}let s;for(let e in i)o.has(e)||(s??=[],s.push(e));s&&s.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:s})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`)continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>vv(e,r,B_())),input:o,path:[o],inst:e}),n.value[s.value]=s.value;continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...gv(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...gv(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),Db=Q(`$ZodEnum`,(e,t)=>{Fy.init(e,t);let n=V_(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>rv.has(typeof e)).map(e=>typeof e==`string`?iv(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Ob=Q(`$ZodLiteral`,(e,t)=>{if(Fy.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);e._zod.values=new Set(t.values),e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?iv(e):e?iv(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(n,r)=>{let i=n.value;return e._zod.values.has(i)||n.issues.push({code:`invalid_value`,values:t.values,input:i,inst:e}),n}}),kb=Q(`$ZodTransform`,(e,t)=>{Fy.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new R_(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new L_;return n.value=i,n}});function Ab(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const jb=Q(`$ZodOptional`,(e,t)=>{Fy.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,J_(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),J_(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${G_(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>Ab(t,e.value)):Ab(r,e.value)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),Mb=Q(`$ZodNullable`,(e,t)=>{Fy.init(e,t),J_(e._zod,`optin`,()=>t.innerType._zod.optin),J_(e._zod,`optout`,()=>t.innerType._zod.optout),J_(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${G_(e.source)}|null)$`):void 0}),J_(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Nb=Q(`$ZodDefault`,(e,t)=>{Fy.init(e,t),e._zod.optin=`optional`,J_(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Pb(e,t)):Pb(r,t)}});function Pb(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Fb=Q(`$ZodPrefault`,(e,t)=>{Fy.init(e,t),e._zod.optin=`optional`,J_(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Ib=Q(`$ZodNonOptional`,(e,t)=>{Fy.init(e,t),J_(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Lb(t,e)):Lb(i,e)}});function Lb(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const Rb=Q(`$ZodCatch`,(e,t)=>{Fy.init(e,t),J_(e._zod,`optin`,()=>t.innerType._zod.optin),J_(e._zod,`optout`,()=>t.innerType._zod.optout),J_(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>vv(e,n,B_()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>vv(e,n,B_()))},input:e.value}),e.issues=[]),e)}}),zb=Q(`$ZodPipe`,(e,t)=>{Fy.init(e,t),J_(e._zod,`values`,()=>t.in._zod.values),J_(e._zod,`optin`,()=>t.in._zod.optin),J_(e._zod,`optout`,()=>t.out._zod.optout),J_(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Bb(e,t.in,n)):Bb(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Bb(e,t.out,n)):Bb(r,t.out,n)}});function Bb(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Vb=Q(`$ZodReadonly`,(e,t)=>{Fy.init(e,t),J_(e._zod,`propValues`,()=>t.innerType._zod.propValues),J_(e._zod,`values`,()=>t.innerType._zod.values),J_(e._zod,`optin`,()=>t.innerType._zod.optin),J_(e._zod,`optout`,()=>t.innerType._zod.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Hb):Hb(r)}});function Hb(e){return e.value=Object.freeze(e.value),e}const Ub=Q(`$ZodCustom`,(e,t)=>{gy.init(e,t),Fy.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Wb(t,n,r,e));Wb(i,n,r,e)}});function Wb(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(bv(e))}}var Gb=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];if(this._map.set(e,n),n&&typeof n==`object`&&`id`in n){if(this._idmap.has(n.id))throw Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function Kb(){return new Gb}const qb=Kb();function Jb(e,t){return new e({type:`string`,...$(t)})}function Yb(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...$(t)})}function Xb(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...$(t)})}function Zb(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...$(t)})}function Qb(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...$(t)})}function $b(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...$(t)})}function ex(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...$(t)})}function tx(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...$(t)})}function nx(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...$(t)})}function rx(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...$(t)})}function ix(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...$(t)})}function ax(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...$(t)})}function ox(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...$(t)})}function sx(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...$(t)})}function cx(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...$(t)})}function lx(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...$(t)})}function ux(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...$(t)})}function dx(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...$(t)})}function fx(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...$(t)})}function px(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...$(t)})}function mx(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...$(t)})}function hx(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...$(t)})}function gx(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...$(t)})}function _x(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...$(t)})}function vx(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...$(t)})}function yx(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...$(t)})}function bx(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...$(t)})}function xx(e,t){return new e({type:`number`,checks:[],...$(t)})}function Sx(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...$(t)})}function Cx(e){return new e({type:`unknown`})}function wx(e,t){return new e({type:`never`,...$(t)})}function Tx(e,t){return new vy({check:`less_than`,...$(t),value:e,inclusive:!1})}function Ex(e,t){return new vy({check:`less_than`,...$(t),value:e,inclusive:!0})}function Dx(e,t){return new yy({check:`greater_than`,...$(t),value:e,inclusive:!1})}function Ox(e,t){return new yy({check:`greater_than`,...$(t),value:e,inclusive:!0})}function kx(e,t){return new by({check:`multiple_of`,...$(t),value:e})}function Ax(e,t){return new Sy({check:`max_length`,...$(t),maximum:e})}function jx(e,t){return new Cy({check:`min_length`,...$(t),minimum:e})}function Mx(e,t){return new wy({check:`length_equals`,...$(t),length:e})}function Nx(e,t){return new Ey({check:`string_format`,format:`regex`,...$(t),pattern:e})}function Px(e){return new Dy({check:`string_format`,format:`lowercase`,...$(e)})}function Fx(e){return new Oy({check:`string_format`,format:`uppercase`,...$(e)})}function Ix(e,t){return new ky({check:`string_format`,format:`includes`,...$(t),includes:e})}function Lx(e,t){return new Ay({check:`string_format`,format:`starts_with`,...$(t),prefix:e})}function Rx(e,t){return new jy({check:`string_format`,format:`ends_with`,...$(t),suffix:e})}function zx(e){return new My({check:`overwrite`,tx:e})}function Bx(e){return zx(t=>t.normalize(e))}function Vx(){return zx(e=>e.trim())}function Hx(){return zx(e=>e.toLowerCase())}function Ux(){return zx(e=>e.toUpperCase())}function Wx(e,t,n){return new e({type:`array`,element:t,...$(n)})}function Gx(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...$(n)})}function Kx(e){let t=qx(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(bv(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(bv(r))}},e(n.value,n)));return t}function qx(e,t){let n=new gy({check:`custom`,...$(t)});return n._zod.check=e,n}const Jx=Q(`ZodISODateTime`,(e,t)=>{Yy.init(e,t),bS.init(e,t)});function Yx(e){return _x(Jx,e)}const Xx=Q(`ZodISODate`,(e,t)=>{Xy.init(e,t),bS.init(e,t)});function Zx(e){return vx(Xx,e)}const Qx=Q(`ZodISOTime`,(e,t)=>{Zy.init(e,t),bS.init(e,t)});function $x(e){return yx(Qx,e)}const eS=Q(`ZodISODuration`,(e,t)=>{Qy.init(e,t),bS.init(e,t)});function tS(e){return bx(eS,e)}var nS=(e,t)=>{Sv.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>Tv(e,t)},flatten:{value:t=>wv(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,H_,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,H_,2)}},isEmpty:{get(){return e.issues.length===0}}})};Q(`ZodError`,nS);const rS=Q(`ZodError`,nS,{Parent:Error}),iS=Ev(rS),aS=Dv(rS),oS=Ov(rS),sS=Av(rS),cS=Mv(rS),lS=Nv(rS),uS=Pv(rS),dS=Fv(rS),fS=Iv(rS),pS=Lv(rS),mS=Rv(rS),hS=zv(rS),gS=Q(`ZodType`,(e,t)=>(Fy.init(e,t),e.def=t,e.type=t.type,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone(X_(t,{checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]})),e.clone=(t,n)=>av(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>iS(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>oS(e,t,n),e.parseAsync=async(t,n)=>aS(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>sS(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>cS(e,t,n),e.decode=(t,n)=>lS(e,t,n),e.encodeAsync=async(t,n)=>uS(e,t,n),e.decodeAsync=async(t,n)=>dS(e,t,n),e.safeEncode=(t,n)=>fS(e,t,n),e.safeDecode=(t,n)=>pS(e,t,n),e.safeEncodeAsync=async(t,n)=>mS(e,t,n),e.safeDecodeAsync=async(t,n)=>hS(e,t,n),e.refine=(t,n)=>e.check(OC(t,n)),e.superRefine=t=>e.check(kC(t)),e.overwrite=t=>e.check(zx(t)),e.optional=()=>fC(e),e.nullable=()=>mC(e),e.nullish=()=>fC(mC(e)),e.nonoptional=t=>bC(e,t),e.array=()=>YS(e),e.or=t=>eC([e,t]),e.and=t=>nC(e,t),e.transform=t=>wC(e,uC(t)),e.default=t=>gC(e,t),e.prefault=t=>vC(e,t),e.catch=t=>SC(e,t),e.pipe=t=>wC(e,t),e.readonly=()=>EC(e),e.describe=t=>{let n=e.clone();return qb.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return qb.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return qb.get(e);let n=e.clone();return qb.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),_S=Q(`_ZodString`,(e,t)=>{Iy.init(e,t),gS.init(e,t);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Nx(...t)),e.includes=(...t)=>e.check(Ix(...t)),e.startsWith=(...t)=>e.check(Lx(...t)),e.endsWith=(...t)=>e.check(Rx(...t)),e.min=(...t)=>e.check(jx(...t)),e.max=(...t)=>e.check(Ax(...t)),e.length=(...t)=>e.check(Mx(...t)),e.nonempty=(...t)=>e.check(jx(1,...t)),e.lowercase=t=>e.check(Px(t)),e.uppercase=t=>e.check(Fx(t)),e.trim=()=>e.check(Vx()),e.normalize=(...t)=>e.check(Bx(...t)),e.toLowerCase=()=>e.check(Hx()),e.toUpperCase=()=>e.check(Ux())}),vS=Q(`ZodString`,(e,t)=>{Iy.init(e,t),_S.init(e,t),e.email=t=>e.check(Yb(xS,t)),e.url=t=>e.check(tx(wS,t)),e.jwt=t=>e.check(gx(zS,t)),e.emoji=t=>e.check(nx(TS,t)),e.guid=t=>e.check(Xb(SS,t)),e.uuid=t=>e.check(Zb(CS,t)),e.uuidv4=t=>e.check(Qb(CS,t)),e.uuidv6=t=>e.check($b(CS,t)),e.uuidv7=t=>e.check(ex(CS,t)),e.nanoid=t=>e.check(rx(ES,t)),e.guid=t=>e.check(Xb(SS,t)),e.cuid=t=>e.check(ix(DS,t)),e.cuid2=t=>e.check(ax(OS,t)),e.ulid=t=>e.check(ox(kS,t)),e.base64=t=>e.check(px(IS,t)),e.base64url=t=>e.check(mx(LS,t)),e.xid=t=>e.check(sx(AS,t)),e.ksuid=t=>e.check(cx(jS,t)),e.ipv4=t=>e.check(lx(MS,t)),e.ipv6=t=>e.check(ux(NS,t)),e.cidrv4=t=>e.check(dx(PS,t)),e.cidrv6=t=>e.check(fx(FS,t)),e.e164=t=>e.check(hx(RS,t)),e.datetime=t=>e.check(Yx(t)),e.date=t=>e.check(Zx(t)),e.time=t=>e.check($x(t)),e.duration=t=>e.check(tS(t))});function yS(e){return Jb(vS,e)}const bS=Q(`ZodStringFormat`,(e,t)=>{Ly.init(e,t),_S.init(e,t)}),xS=Q(`ZodEmail`,(e,t)=>{By.init(e,t),bS.init(e,t)}),SS=Q(`ZodGUID`,(e,t)=>{Ry.init(e,t),bS.init(e,t)}),CS=Q(`ZodUUID`,(e,t)=>{zy.init(e,t),bS.init(e,t)}),wS=Q(`ZodURL`,(e,t)=>{Vy.init(e,t),bS.init(e,t)}),TS=Q(`ZodEmoji`,(e,t)=>{Hy.init(e,t),bS.init(e,t)}),ES=Q(`ZodNanoID`,(e,t)=>{Uy.init(e,t),bS.init(e,t)}),DS=Q(`ZodCUID`,(e,t)=>{Wy.init(e,t),bS.init(e,t)}),OS=Q(`ZodCUID2`,(e,t)=>{Gy.init(e,t),bS.init(e,t)}),kS=Q(`ZodULID`,(e,t)=>{Ky.init(e,t),bS.init(e,t)}),AS=Q(`ZodXID`,(e,t)=>{qy.init(e,t),bS.init(e,t)}),jS=Q(`ZodKSUID`,(e,t)=>{Jy.init(e,t),bS.init(e,t)}),MS=Q(`ZodIPv4`,(e,t)=>{$y.init(e,t),bS.init(e,t)}),NS=Q(`ZodIPv6`,(e,t)=>{eb.init(e,t),bS.init(e,t)}),PS=Q(`ZodCIDRv4`,(e,t)=>{tb.init(e,t),bS.init(e,t)}),FS=Q(`ZodCIDRv6`,(e,t)=>{nb.init(e,t),bS.init(e,t)}),IS=Q(`ZodBase64`,(e,t)=>{ib.init(e,t),bS.init(e,t)}),LS=Q(`ZodBase64URL`,(e,t)=>{ob.init(e,t),bS.init(e,t)}),RS=Q(`ZodE164`,(e,t)=>{sb.init(e,t),bS.init(e,t)}),zS=Q(`ZodJWT`,(e,t)=>{lb.init(e,t),bS.init(e,t)}),BS=Q(`ZodNumber`,(e,t)=>{ub.init(e,t),gS.init(e,t),e.gt=(t,n)=>e.check(Dx(t,n)),e.gte=(t,n)=>e.check(Ox(t,n)),e.min=(t,n)=>e.check(Ox(t,n)),e.lt=(t,n)=>e.check(Tx(t,n)),e.lte=(t,n)=>e.check(Ex(t,n)),e.max=(t,n)=>e.check(Ex(t,n)),e.int=t=>e.check(US(t)),e.safe=t=>e.check(US(t)),e.positive=t=>e.check(Dx(0,t)),e.nonnegative=t=>e.check(Ox(0,t)),e.negative=t=>e.check(Tx(0,t)),e.nonpositive=t=>e.check(Ex(0,t)),e.multipleOf=(t,n)=>e.check(kx(t,n)),e.step=(t,n)=>e.check(kx(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function VS(e){return xx(BS,e)}const HS=Q(`ZodNumberFormat`,(e,t)=>{db.init(e,t),BS.init(e,t)});function US(e){return Sx(HS,e)}const WS=Q(`ZodUnknown`,(e,t)=>{fb.init(e,t),gS.init(e,t)});function GS(){return Cx(WS)}const KS=Q(`ZodNever`,(e,t)=>{pb.init(e,t),gS.init(e,t)});function qS(e){return wx(KS,e)}const JS=Q(`ZodArray`,(e,t)=>{hb.init(e,t),gS.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(jx(t,n)),e.nonempty=t=>e.check(jx(1,t)),e.max=(t,n)=>e.check(Ax(t,n)),e.length=(t,n)=>e.check(Mx(t,n)),e.unwrap=()=>e.element});function YS(e,t){return Wx(JS,e,t)}const XS=Q(`ZodObject`,(e,t)=>{bb.init(e,t),gS.init(e,t),J_(e,`shape`,()=>t.shape),e.keyof=()=>oC(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:GS()}),e.loose=()=>e.clone({...e._zod.def,catchall:GS()}),e.strict=()=>e.clone({...e._zod.def,catchall:qS()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>uv(e,t),e.safeExtend=t=>dv(e,t),e.merge=t=>fv(e,t),e.pick=t=>cv(e,t),e.omit=t=>lv(e,t),e.partial=(...t)=>pv(dC,e,t[0]),e.required=(...t)=>mv(yC,e,t[0])});function ZS(e,t){let n={type:`object`,shape:e??{},...$(t)};return new XS(n)}function QS(e,t){return new XS({type:`object`,shape:e,catchall:GS(),...$(t)})}const $S=Q(`ZodUnion`,(e,t)=>{Sb.init(e,t),gS.init(e,t),e.options=t.options});function eC(e,t){return new $S({type:`union`,options:e,...$(t)})}const tC=Q(`ZodIntersection`,(e,t)=>{Cb.init(e,t),gS.init(e,t)});function nC(e,t){return new tC({type:`intersection`,left:e,right:t})}const rC=Q(`ZodRecord`,(e,t)=>{Eb.init(e,t),gS.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function iC(e,t,n){return new rC({type:`record`,keyType:e,valueType:t,...$(n)})}const aC=Q(`ZodEnum`,(e,t)=>{Db.init(e,t),gS.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new aC({...t,checks:[],...$(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new aC({...t,checks:[],...$(r),entries:i})}});function oC(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new aC({type:`enum`,entries:n,...$(t)})}const sC=Q(`ZodLiteral`,(e,t)=>{Ob.init(e,t),gS.init(e,t),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function cC(e,t){return new sC({type:`literal`,values:Array.isArray(e)?e:[e],...$(t)})}const lC=Q(`ZodTransform`,(e,t)=>{kb.init(e,t),gS.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new R_(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(bv(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(bv(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function uC(e){return new lC({type:`transform`,transform:e})}const dC=Q(`ZodOptional`,(e,t)=>{jb.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType});function fC(e){return new dC({type:`optional`,innerType:e})}const pC=Q(`ZodNullable`,(e,t)=>{Mb.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType});function mC(e){return new pC({type:`nullable`,innerType:e})}const hC=Q(`ZodDefault`,(e,t)=>{Nb.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function gC(e,t){return new hC({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():nv(t)}})}const _C=Q(`ZodPrefault`,(e,t)=>{Fb.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType});function vC(e,t){return new _C({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():nv(t)}})}const yC=Q(`ZodNonOptional`,(e,t)=>{Ib.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType});function bC(e,t){return new yC({type:`nonoptional`,innerType:e,...$(t)})}const xC=Q(`ZodCatch`,(e,t)=>{Rb.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function SC(e,t){return new xC({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const CC=Q(`ZodPipe`,(e,t)=>{zb.init(e,t),gS.init(e,t),e.in=t.in,e.out=t.out});function wC(e,t){return new CC({type:`pipe`,in:e,out:t})}const TC=Q(`ZodReadonly`,(e,t)=>{Vb.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType});function EC(e){return new TC({type:`readonly`,innerType:e})}const DC=Q(`ZodCustom`,(e,t)=>{Ub.init(e,t),gS.init(e,t)});function OC(e,t={}){return Gx(DC,e,t)}function kC(e){return Kx(e)}const AC=ZS({width:VS().min(0).default(1e3),height:VS().min(0).default(1e3),settings:iC(yS(),GS()).default({}),events:iC(yS(),GS()).default({}),persistedState:GS().optional()}),jC=ZS({$schema:cC(`https://ekg.gg/schemas/manifest.json`).default(`https://ekg.gg/schemas/manifest.json`),name:yS().optional(),version:yS().optional(),description:yS().optional(),template:yS().default(``),css:yS().default(``),js:yS().default(``),assets:iC(yS(),ZS({type:yS().default(``),file:yS().default(``)})).optional(),settings:iC(yS(),QS({type:yS().default(``),name:yS().default(``),description:yS().optional()})).optional()});var MC=[`audio`,`image`];function NC(e){let t=AC.parse(JSON.parse(e.state)),r=jC.parse(JSON.parse(e.widget[`manifest.json`])),a=e=>import.meta.hot?.send(`ekg:state`,{...t,...e}),o=e=>import.meta.hot?.send(`ekg:manifest`,{...r,...e}),s=e=>a({width:e}),c=e=>a({height:e}),l=e=>o({name:e}),u=e=>o({version:e}),d=e=>o({description:e}),f=Object.entries(r.settings??{}).map(([n,r])=>({setting:{...r,key:n},value:t.settings[n]??RC(e.widget,r),update:e=>a({settings:{...t.settings,[n]:e}})})),p=(0,T.useRef)(null),[m,h]=(0,T.useState)({width:1,height:1});(0,T.useEffect)(()=>{let e=p.current;if(!e)return;let t=()=>{let{width:t,height:n}=e.getBoundingClientRect();h({width:t,height:n})},n=new ResizeObserver(t);return n.observe(e),t(),()=>n.disconnect()},[p.current]);let g=Math.min(m.width/t.width,m.height/t.height),[_,v]=(0,T.useState)(n.oneOf.map(e=>{let r=e.$ref.split(`/`).at(-1),i=n.$defs[r].properties.type.const,a={$schema:`https://json-schema.org/draft/2020-12/schema`,$defs:n.$defs,...n.$defs[r].properties.data},o=PC(a.properties,t.events[i]);return{name:r,type:i,schema:a,data:o}}));(0,T.useEffect)(()=>{a({events:Object.fromEntries(_.map(e=>[e.type,e.data]))})},[_]);let y=e=>{let t=_.find(t=>t.name===e);i.fireEvent({id:FC(60),timestamp:Date.now(),type:t.type,data:t.data})};return(0,Z.jsxs)(`div`,{className:`flex h-screen dark:text-slate-100 dark:bg-slate-900`,children:[(0,Z.jsx)(`div`,{className:`bg-black/10 border-r border-white/10 w-72 contain-strict overflow-auto`,children:(0,Z.jsxs)(`div`,{className:`px-6 flex flex-col gap-4 pb-8`,children:[(0,Z.jsx)(`h1`,{className:`text-xl font-bold py-4`,children:`Widget Dev Kit`}),(0,Z.jsxs)(`div`,{className:`flex gap-4`,children:[(0,Z.jsx)(w_,{label:`Width:`,name:`width`,value:t.width,update:s}),(0,Z.jsx)(w_,{label:`Height:`,name:`height`,value:t.height,update:c})]}),(0,Z.jsx)(S_,{type:`text`,label:`Name:`,name:`name`,value:r.name??``,update:l}),(0,Z.jsx)(S_,{type:`text`,label:`Version:`,name:`version`,value:r.version??``,update:u}),(0,Z.jsx)(S_,{type:`textarea`,label:`Description:`,name:`description`,value:r.description??``,update:d}),(0,Z.jsx)(`h1`,{className:`text-lg font-bold pt-4`,children:`Settings`}),f.map(e=>(0,Z.jsx)(BC,{...e},e.setting.key))]})}),(0,Z.jsx)(`div`,{className:`p-4 sm:p-16 flex-1 contain-strict`,children:(0,Z.jsx)(`div`,{className:`@container-[size] h-full grid auto-cols-fr place-items-center`,children:(0,Z.jsx)(`div`,{ref:p,className:`max-w-full`,style:{aspectRatio:`${t.width}/${t.height}`,width:`${100*t.width/t.height}cqh`},children:(0,Z.jsx)(`div`,{className:`relative origin-top-left bg-white dark:bg-black`,style:{width:`${t.width}px`,height:`${t.height}px`,transform:`scale(${g})`},children:(0,Z.jsx)(LC,{state:t,manifest:r,widget:e.widget,updateState:a})})})})}),(0,Z.jsx)(`div`,{className:`bg-black/10 border-l border-white/10 w-72 contain-strict overflow-auto`,children:(0,Z.jsxs)(`div`,{className:`px-6 flex flex-col gap-4 pb-8`,children:[(0,Z.jsx)(`h1`,{className:`text-xl font-bold py-4`,children:`Test Events`}),_.map(e=>(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(b_,{variant:`secondary`,size:`md`,className:`grow`,onClick:()=>y(e.name),children:e.name}),(0,Z.jsx)(b_,{variant:`secondary`,size:`md`,commandfor:`${e.name}-modal`,command:`show-modal`,children:`S`}),(0,Z.jsx)(A_,{id:`${e.name}-modal`,name:e.name,schema:e.schema,data:e.data,setData:t=>v(n=>n.map(n=>n.name===e.name?{...n,data:t}:n))})]},e.name))]})})]})}function PC(e,t){let n=(e,n)=>t?.[e]&&(n===`array`?Array.isArray(t[e]):typeof t[e]===n)?t[e]:null;return Object.fromEntries(Object.entries(e).map(([e,r])=>e===`raw`?[e,n(e,`object`)??{}]:e===`currency`?[e,n(e,`string`)??`USD`]:typeof r!=`object`||!r?[e,null]:`const`in r?[e,r.const]:`enum`in r&&Array.isArray(r.enum)?[e,r.enum.includes(t?.[e])?t[e]:r.enum[0]]:`type`in r?e.endsWith(`At`)&&r.type===`integer`?[e,n(e,`number`)??Date.now()]:e.endsWith(`Cents`)&&r.type===`integer`?[e,n(e,`number`)??500]:r.type===`string`?[e,n(e,`string`)??FC(12)]:r.type===`boolean`?[e,n(e,`boolean`)??!1]:r.type===`integer`?[e,n(e,`number`)??2]:r.type===`array`&&`items`in r&&typeof r.items==`object`&&r.items&&`$ref`in r.items&&r.items.$ref===`#/$defs/ChatNode`?[e,n(e,`array`)??[{type:`text`,text:FC(40)}]]:r.type===`array`?[e,n(e,`array`)??[]]:[e,null]:[e,null]))}function FC(e){let t=new Uint8Array(e);return crypto.getRandomValues(t),Array.from(t,e=>e.toString(36).slice(-1)).join(``)}var IC=(()=>{setInterval(()=>{i.fireEvent({type:`TICK`})},100);let e=BigInt(Math.floor(16777215*Math.random())),t=null,n=null,r=new Map;return{subscribe(t){let n=(e++).toString();return r.set(n,t),()=>{r.delete(n)}},getSnapshot(){return n},register(e){e!==t&&(n&&n.stop(),t=e,n=t?i.createManagedWidget(t):null,r.forEach(e=>e()))}}})();function LC({state:e,manifest:t,widget:n,updateState:r}){let i=n[t.template],a=n[t.css],o=n[t.js],s=Object.fromEntries(Object.entries(t.assets??{}).map(([e,{file:t,type:r}])=>{let i=n[t];return r===`font`&&(i=VC(i)),[e,i]})),c=Object.fromEntries(Object.entries(t.settings??{}).map(([t,r])=>{let i=e.settings[t]??RC(n,r);if(r.type===`font`){let[e,t]=zC(n,i);i=e}return[t,i]})),l=Object.values(t.assets??{}).map(({file:e,type:t})=>{if(t!==`font`)return``;let[r,i]=zC(n,e);return i}).join(``)+Object.entries(t.settings??{}).map(([t,r])=>{if(r.type!==`font`)return``;let i=e.settings[t]??RC(n,r),[a,o]=zC(n,i);return o}).join(``),u=(0,T.useSyncExternalStore)(IC.subscribe,IC.getSnapshot),d=(0,T.useRef)(e.persistedState);d.current=e.persistedState;let f=(0,T.useRef)(r);return f.current=r,(0,T.useEffect)(()=>{if(!u||!i||!o||!a)return;u.init({template:i,js:o,css:a,cdnDomain:`https://cdn.ekg.gg`,fonts:l,assets:s,settings:c,persistedState:d.current});let e=async()=>{let e=await u.persist();JSON.stringify(e)!==JSON.stringify(d.current)&&f.current({persistedState:e})},t=setInterval(e,1e3);return()=>{e(),clearInterval(t)}},[u,i,a,o,l,JSON.stringify(s),JSON.stringify(c)]),(0,Z.jsx)(`div`,{ref:IC.register,className:`size-full`})}function RC(e,t){if(t.type===`font`){if(!t.default)return null;let e=r.find(e=>e.name===t.default)?.value||Object.entries(t.custom||{}).find(e=>e[1]===t.default)?.[0];if(e)return e;throw Error(`Invalid default value for setting "${t.name}". Expected a font name, either built-in or from the custom array.`)}return t.type===`reward_ids`?[]:MC.includes(t.type)?e[t.default]:t.default}function zC(e,t){let n=r.find(e=>e.value===t);if(n)return[n.value,n.font_face];let i=e[t];if(!i)throw Error(`Missing font file: ${t}`);return[VC(i),`
|
|
38
|
+
`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=$_,s=!z_.jitless,c=s&&ev.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?vb([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}});function xb(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!hv(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>vv(e,r,B_())))}),t)}const Sb=Q(`$ZodUnion`,(e,t)=>{Fy.init(e,t),J_(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),J_(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),J_(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),J_(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>G_(e.source)).join(`|`)})$`)}});let n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,a)=>{if(n)return r(i,a);let o=!1,s=[];for(let e of t.options){let t=e._zod.run({value:i.value,issues:[]},a);if(t instanceof Promise)s.push(t),o=!0;else{if(t.issues.length===0)return t;s.push(t)}}return o?Promise.all(s).then(t=>xb(t,i,e,a)):xb(s,i,e,a)}}),Cb=Q(`$ZodIntersection`,(e,t)=>{Fy.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>Tb(e,t,n)):Tb(e,i,a)}});function wb(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(tv(e)&&tv(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=wb(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=wb(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Tb(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),hv(e))return e;let r=wb(t.value,n.value);if(!r.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const Eb=Q(`$ZodRecord`,(e,t)=>{Fy.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!tv(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[];if(t.keyType._zod.values){let o=t.keyType._zod.values;n.value={};for(let e of o)if(typeof e==`string`||typeof e==`number`||typeof e==`symbol`){let o=t.valueType._zod.run({value:i[e],issues:[]},r);o instanceof Promise?a.push(o.then(t=>{t.issues.length&&n.issues.push(...gv(e,t.issues)),n.value[e]=t.value})):(o.issues.length&&n.issues.push(...gv(e,o.issues)),n.value[e]=o.value)}let s;for(let e in i)o.has(e)||(s??=[],s.push(e));s&&s.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:s})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`)continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>vv(e,r,B_())),input:o,path:[o],inst:e}),n.value[s.value]=s.value;continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...gv(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...gv(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),Db=Q(`$ZodEnum`,(e,t)=>{Fy.init(e,t);let n=V_(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>rv.has(typeof e)).map(e=>typeof e==`string`?iv(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Ob=Q(`$ZodLiteral`,(e,t)=>{if(Fy.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);e._zod.values=new Set(t.values),e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?iv(e):e?iv(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(n,r)=>{let i=n.value;return e._zod.values.has(i)||n.issues.push({code:`invalid_value`,values:t.values,input:i,inst:e}),n}}),kb=Q(`$ZodTransform`,(e,t)=>{Fy.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new R_(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new L_;return n.value=i,n}});function Ab(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const jb=Q(`$ZodOptional`,(e,t)=>{Fy.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,J_(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),J_(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${G_(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>Ab(t,e.value)):Ab(r,e.value)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),Mb=Q(`$ZodNullable`,(e,t)=>{Fy.init(e,t),J_(e._zod,`optin`,()=>t.innerType._zod.optin),J_(e._zod,`optout`,()=>t.innerType._zod.optout),J_(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${G_(e.source)}|null)$`):void 0}),J_(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Nb=Q(`$ZodDefault`,(e,t)=>{Fy.init(e,t),e._zod.optin=`optional`,J_(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Pb(e,t)):Pb(r,t)}});function Pb(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Fb=Q(`$ZodPrefault`,(e,t)=>{Fy.init(e,t),e._zod.optin=`optional`,J_(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Ib=Q(`$ZodNonOptional`,(e,t)=>{Fy.init(e,t),J_(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Lb(t,e)):Lb(i,e)}});function Lb(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}const Rb=Q(`$ZodCatch`,(e,t)=>{Fy.init(e,t),J_(e._zod,`optin`,()=>t.innerType._zod.optin),J_(e._zod,`optout`,()=>t.innerType._zod.optout),J_(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>vv(e,n,B_()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>vv(e,n,B_()))},input:e.value}),e.issues=[]),e)}}),zb=Q(`$ZodPipe`,(e,t)=>{Fy.init(e,t),J_(e._zod,`values`,()=>t.in._zod.values),J_(e._zod,`optin`,()=>t.in._zod.optin),J_(e._zod,`optout`,()=>t.out._zod.optout),J_(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Bb(e,t.in,n)):Bb(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Bb(e,t.out,n)):Bb(r,t.out,n)}});function Bb(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Vb=Q(`$ZodReadonly`,(e,t)=>{Fy.init(e,t),J_(e._zod,`propValues`,()=>t.innerType._zod.propValues),J_(e._zod,`values`,()=>t.innerType._zod.values),J_(e._zod,`optin`,()=>t.innerType._zod.optin),J_(e._zod,`optout`,()=>t.innerType._zod.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Hb):Hb(r)}});function Hb(e){return e.value=Object.freeze(e.value),e}const Ub=Q(`$ZodCustom`,(e,t)=>{gy.init(e,t),Fy.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Wb(t,n,r,e));Wb(i,n,r,e)}});function Wb(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(bv(e))}}var Gb=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];if(this._map.set(e,n),n&&typeof n==`object`&&`id`in n){if(this._idmap.has(n.id))throw Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function Kb(){return new Gb}const qb=Kb();function Jb(e,t){return new e({type:`string`,...$(t)})}function Yb(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...$(t)})}function Xb(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...$(t)})}function Zb(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...$(t)})}function Qb(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...$(t)})}function $b(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...$(t)})}function ex(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...$(t)})}function tx(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...$(t)})}function nx(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...$(t)})}function rx(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...$(t)})}function ix(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...$(t)})}function ax(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...$(t)})}function ox(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...$(t)})}function sx(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...$(t)})}function cx(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...$(t)})}function lx(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...$(t)})}function ux(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...$(t)})}function dx(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...$(t)})}function fx(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...$(t)})}function px(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...$(t)})}function mx(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...$(t)})}function hx(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...$(t)})}function gx(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...$(t)})}function _x(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...$(t)})}function vx(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...$(t)})}function yx(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...$(t)})}function bx(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...$(t)})}function xx(e,t){return new e({type:`number`,checks:[],...$(t)})}function Sx(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...$(t)})}function Cx(e){return new e({type:`unknown`})}function wx(e,t){return new e({type:`never`,...$(t)})}function Tx(e,t){return new vy({check:`less_than`,...$(t),value:e,inclusive:!1})}function Ex(e,t){return new vy({check:`less_than`,...$(t),value:e,inclusive:!0})}function Dx(e,t){return new yy({check:`greater_than`,...$(t),value:e,inclusive:!1})}function Ox(e,t){return new yy({check:`greater_than`,...$(t),value:e,inclusive:!0})}function kx(e,t){return new by({check:`multiple_of`,...$(t),value:e})}function Ax(e,t){return new Sy({check:`max_length`,...$(t),maximum:e})}function jx(e,t){return new Cy({check:`min_length`,...$(t),minimum:e})}function Mx(e,t){return new wy({check:`length_equals`,...$(t),length:e})}function Nx(e,t){return new Ey({check:`string_format`,format:`regex`,...$(t),pattern:e})}function Px(e){return new Dy({check:`string_format`,format:`lowercase`,...$(e)})}function Fx(e){return new Oy({check:`string_format`,format:`uppercase`,...$(e)})}function Ix(e,t){return new ky({check:`string_format`,format:`includes`,...$(t),includes:e})}function Lx(e,t){return new Ay({check:`string_format`,format:`starts_with`,...$(t),prefix:e})}function Rx(e,t){return new jy({check:`string_format`,format:`ends_with`,...$(t),suffix:e})}function zx(e){return new My({check:`overwrite`,tx:e})}function Bx(e){return zx(t=>t.normalize(e))}function Vx(){return zx(e=>e.trim())}function Hx(){return zx(e=>e.toLowerCase())}function Ux(){return zx(e=>e.toUpperCase())}function Wx(e,t,n){return new e({type:`array`,element:t,...$(n)})}function Gx(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...$(n)})}function Kx(e){let t=qx(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(bv(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(bv(r))}},e(n.value,n)));return t}function qx(e,t){let n=new gy({check:`custom`,...$(t)});return n._zod.check=e,n}const Jx=Q(`ZodISODateTime`,(e,t)=>{Yy.init(e,t),bS.init(e,t)});function Yx(e){return _x(Jx,e)}const Xx=Q(`ZodISODate`,(e,t)=>{Xy.init(e,t),bS.init(e,t)});function Zx(e){return vx(Xx,e)}const Qx=Q(`ZodISOTime`,(e,t)=>{Zy.init(e,t),bS.init(e,t)});function $x(e){return yx(Qx,e)}const eS=Q(`ZodISODuration`,(e,t)=>{Qy.init(e,t),bS.init(e,t)});function tS(e){return bx(eS,e)}var nS=(e,t)=>{Sv.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>Tv(e,t)},flatten:{value:t=>wv(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,H_,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,H_,2)}},isEmpty:{get(){return e.issues.length===0}}})};Q(`ZodError`,nS);const rS=Q(`ZodError`,nS,{Parent:Error}),iS=Ev(rS),aS=Dv(rS),oS=Ov(rS),sS=Av(rS),cS=Mv(rS),lS=Nv(rS),uS=Pv(rS),dS=Fv(rS),fS=Iv(rS),pS=Lv(rS),mS=Rv(rS),hS=zv(rS),gS=Q(`ZodType`,(e,t)=>(Fy.init(e,t),e.def=t,e.type=t.type,Object.defineProperty(e,`_def`,{value:t}),e.check=(...n)=>e.clone(X_(t,{checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]})),e.clone=(t,n)=>av(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>iS(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>oS(e,t,n),e.parseAsync=async(t,n)=>aS(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>sS(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>cS(e,t,n),e.decode=(t,n)=>lS(e,t,n),e.encodeAsync=async(t,n)=>uS(e,t,n),e.decodeAsync=async(t,n)=>dS(e,t,n),e.safeEncode=(t,n)=>fS(e,t,n),e.safeDecode=(t,n)=>pS(e,t,n),e.safeEncodeAsync=async(t,n)=>mS(e,t,n),e.safeDecodeAsync=async(t,n)=>hS(e,t,n),e.refine=(t,n)=>e.check(OC(t,n)),e.superRefine=t=>e.check(kC(t)),e.overwrite=t=>e.check(zx(t)),e.optional=()=>fC(e),e.nullable=()=>mC(e),e.nullish=()=>fC(mC(e)),e.nonoptional=t=>bC(e,t),e.array=()=>YS(e),e.or=t=>eC([e,t]),e.and=t=>nC(e,t),e.transform=t=>wC(e,uC(t)),e.default=t=>gC(e,t),e.prefault=t=>vC(e,t),e.catch=t=>SC(e,t),e.pipe=t=>wC(e,t),e.readonly=()=>EC(e),e.describe=t=>{let n=e.clone();return qb.add(n,{description:t}),n},Object.defineProperty(e,`description`,{get(){return qb.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return qb.get(e);let n=e.clone();return qb.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),_S=Q(`_ZodString`,(e,t)=>{Iy.init(e,t),gS.init(e,t);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(Nx(...t)),e.includes=(...t)=>e.check(Ix(...t)),e.startsWith=(...t)=>e.check(Lx(...t)),e.endsWith=(...t)=>e.check(Rx(...t)),e.min=(...t)=>e.check(jx(...t)),e.max=(...t)=>e.check(Ax(...t)),e.length=(...t)=>e.check(Mx(...t)),e.nonempty=(...t)=>e.check(jx(1,...t)),e.lowercase=t=>e.check(Px(t)),e.uppercase=t=>e.check(Fx(t)),e.trim=()=>e.check(Vx()),e.normalize=(...t)=>e.check(Bx(...t)),e.toLowerCase=()=>e.check(Hx()),e.toUpperCase=()=>e.check(Ux())}),vS=Q(`ZodString`,(e,t)=>{Iy.init(e,t),_S.init(e,t),e.email=t=>e.check(Yb(xS,t)),e.url=t=>e.check(tx(wS,t)),e.jwt=t=>e.check(gx(zS,t)),e.emoji=t=>e.check(nx(TS,t)),e.guid=t=>e.check(Xb(SS,t)),e.uuid=t=>e.check(Zb(CS,t)),e.uuidv4=t=>e.check(Qb(CS,t)),e.uuidv6=t=>e.check($b(CS,t)),e.uuidv7=t=>e.check(ex(CS,t)),e.nanoid=t=>e.check(rx(ES,t)),e.guid=t=>e.check(Xb(SS,t)),e.cuid=t=>e.check(ix(DS,t)),e.cuid2=t=>e.check(ax(OS,t)),e.ulid=t=>e.check(ox(kS,t)),e.base64=t=>e.check(px(IS,t)),e.base64url=t=>e.check(mx(LS,t)),e.xid=t=>e.check(sx(AS,t)),e.ksuid=t=>e.check(cx(jS,t)),e.ipv4=t=>e.check(lx(MS,t)),e.ipv6=t=>e.check(ux(NS,t)),e.cidrv4=t=>e.check(dx(PS,t)),e.cidrv6=t=>e.check(fx(FS,t)),e.e164=t=>e.check(hx(RS,t)),e.datetime=t=>e.check(Yx(t)),e.date=t=>e.check(Zx(t)),e.time=t=>e.check($x(t)),e.duration=t=>e.check(tS(t))});function yS(e){return Jb(vS,e)}const bS=Q(`ZodStringFormat`,(e,t)=>{Ly.init(e,t),_S.init(e,t)}),xS=Q(`ZodEmail`,(e,t)=>{By.init(e,t),bS.init(e,t)}),SS=Q(`ZodGUID`,(e,t)=>{Ry.init(e,t),bS.init(e,t)}),CS=Q(`ZodUUID`,(e,t)=>{zy.init(e,t),bS.init(e,t)}),wS=Q(`ZodURL`,(e,t)=>{Vy.init(e,t),bS.init(e,t)}),TS=Q(`ZodEmoji`,(e,t)=>{Hy.init(e,t),bS.init(e,t)}),ES=Q(`ZodNanoID`,(e,t)=>{Uy.init(e,t),bS.init(e,t)}),DS=Q(`ZodCUID`,(e,t)=>{Wy.init(e,t),bS.init(e,t)}),OS=Q(`ZodCUID2`,(e,t)=>{Gy.init(e,t),bS.init(e,t)}),kS=Q(`ZodULID`,(e,t)=>{Ky.init(e,t),bS.init(e,t)}),AS=Q(`ZodXID`,(e,t)=>{qy.init(e,t),bS.init(e,t)}),jS=Q(`ZodKSUID`,(e,t)=>{Jy.init(e,t),bS.init(e,t)}),MS=Q(`ZodIPv4`,(e,t)=>{$y.init(e,t),bS.init(e,t)}),NS=Q(`ZodIPv6`,(e,t)=>{eb.init(e,t),bS.init(e,t)}),PS=Q(`ZodCIDRv4`,(e,t)=>{tb.init(e,t),bS.init(e,t)}),FS=Q(`ZodCIDRv6`,(e,t)=>{nb.init(e,t),bS.init(e,t)}),IS=Q(`ZodBase64`,(e,t)=>{ib.init(e,t),bS.init(e,t)}),LS=Q(`ZodBase64URL`,(e,t)=>{ob.init(e,t),bS.init(e,t)}),RS=Q(`ZodE164`,(e,t)=>{sb.init(e,t),bS.init(e,t)}),zS=Q(`ZodJWT`,(e,t)=>{lb.init(e,t),bS.init(e,t)}),BS=Q(`ZodNumber`,(e,t)=>{ub.init(e,t),gS.init(e,t),e.gt=(t,n)=>e.check(Dx(t,n)),e.gte=(t,n)=>e.check(Ox(t,n)),e.min=(t,n)=>e.check(Ox(t,n)),e.lt=(t,n)=>e.check(Tx(t,n)),e.lte=(t,n)=>e.check(Ex(t,n)),e.max=(t,n)=>e.check(Ex(t,n)),e.int=t=>e.check(US(t)),e.safe=t=>e.check(US(t)),e.positive=t=>e.check(Dx(0,t)),e.nonnegative=t=>e.check(Ox(0,t)),e.negative=t=>e.check(Tx(0,t)),e.nonpositive=t=>e.check(Ex(0,t)),e.multipleOf=(t,n)=>e.check(kx(t,n)),e.step=(t,n)=>e.check(kx(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function VS(e){return xx(BS,e)}const HS=Q(`ZodNumberFormat`,(e,t)=>{db.init(e,t),BS.init(e,t)});function US(e){return Sx(HS,e)}const WS=Q(`ZodUnknown`,(e,t)=>{fb.init(e,t),gS.init(e,t)});function GS(){return Cx(WS)}const KS=Q(`ZodNever`,(e,t)=>{pb.init(e,t),gS.init(e,t)});function qS(e){return wx(KS,e)}const JS=Q(`ZodArray`,(e,t)=>{hb.init(e,t),gS.init(e,t),e.element=t.element,e.min=(t,n)=>e.check(jx(t,n)),e.nonempty=t=>e.check(jx(1,t)),e.max=(t,n)=>e.check(Ax(t,n)),e.length=(t,n)=>e.check(Mx(t,n)),e.unwrap=()=>e.element});function YS(e,t){return Wx(JS,e,t)}const XS=Q(`ZodObject`,(e,t)=>{bb.init(e,t),gS.init(e,t),J_(e,`shape`,()=>t.shape),e.keyof=()=>oC(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:GS()}),e.loose=()=>e.clone({...e._zod.def,catchall:GS()}),e.strict=()=>e.clone({...e._zod.def,catchall:qS()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>uv(e,t),e.safeExtend=t=>dv(e,t),e.merge=t=>fv(e,t),e.pick=t=>cv(e,t),e.omit=t=>lv(e,t),e.partial=(...t)=>pv(dC,e,t[0]),e.required=(...t)=>mv(yC,e,t[0])});function ZS(e,t){let n={type:`object`,shape:e??{},...$(t)};return new XS(n)}function QS(e,t){return new XS({type:`object`,shape:e,catchall:GS(),...$(t)})}const $S=Q(`ZodUnion`,(e,t)=>{Sb.init(e,t),gS.init(e,t),e.options=t.options});function eC(e,t){return new $S({type:`union`,options:e,...$(t)})}const tC=Q(`ZodIntersection`,(e,t)=>{Cb.init(e,t),gS.init(e,t)});function nC(e,t){return new tC({type:`intersection`,left:e,right:t})}const rC=Q(`ZodRecord`,(e,t)=>{Eb.init(e,t),gS.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function iC(e,t,n){return new rC({type:`record`,keyType:e,valueType:t,...$(n)})}const aC=Q(`ZodEnum`,(e,t)=>{Db.init(e,t),gS.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new aC({...t,checks:[],...$(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new aC({...t,checks:[],...$(r),entries:i})}});function oC(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new aC({type:`enum`,entries:n,...$(t)})}const sC=Q(`ZodLiteral`,(e,t)=>{Ob.init(e,t),gS.init(e,t),e.values=new Set(t.values),Object.defineProperty(e,`value`,{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function cC(e,t){return new sC({type:`literal`,values:Array.isArray(e)?e:[e],...$(t)})}const lC=Q(`ZodTransform`,(e,t)=>{kb.init(e,t),gS.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new R_(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(bv(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(bv(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function uC(e){return new lC({type:`transform`,transform:e})}const dC=Q(`ZodOptional`,(e,t)=>{jb.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType});function fC(e){return new dC({type:`optional`,innerType:e})}const pC=Q(`ZodNullable`,(e,t)=>{Mb.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType});function mC(e){return new pC({type:`nullable`,innerType:e})}const hC=Q(`ZodDefault`,(e,t)=>{Nb.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function gC(e,t){return new hC({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():nv(t)}})}const _C=Q(`ZodPrefault`,(e,t)=>{Fb.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType});function vC(e,t){return new _C({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():nv(t)}})}const yC=Q(`ZodNonOptional`,(e,t)=>{Ib.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType});function bC(e,t){return new yC({type:`nonoptional`,innerType:e,...$(t)})}const xC=Q(`ZodCatch`,(e,t)=>{Rb.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function SC(e,t){return new xC({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}const CC=Q(`ZodPipe`,(e,t)=>{zb.init(e,t),gS.init(e,t),e.in=t.in,e.out=t.out});function wC(e,t){return new CC({type:`pipe`,in:e,out:t})}const TC=Q(`ZodReadonly`,(e,t)=>{Vb.init(e,t),gS.init(e,t),e.unwrap=()=>e._zod.def.innerType});function EC(e){return new TC({type:`readonly`,innerType:e})}const DC=Q(`ZodCustom`,(e,t)=>{Ub.init(e,t),gS.init(e,t)});function OC(e,t={}){return Gx(DC,e,t)}function kC(e){return Kx(e)}const AC=ZS({width:VS().min(0).catch(1e3),height:VS().min(0).catch(1e3),settings:iC(yS(),GS()).catch({}),events:iC(yS(),GS()).catch({}),persistedState:GS().optional()});function jC(e){try{return AC.parse(JSON.parse(e))}catch{return AC.parse({})}}const MC=ZS({$schema:cC(`https://ekg.gg/schemas/manifest.json`).default(`https://ekg.gg/schemas/manifest.json`),name:yS().optional(),version:yS().optional(),description:yS().optional(),template:yS().default(``),css:yS().default(``),js:yS().default(``),assets:iC(yS(),ZS({type:yS().default(``),file:yS().default(``)})).optional(),settings:iC(yS(),QS({type:yS().default(``),name:yS().default(``),description:yS().optional()})).optional()});var NC=[`audio`,`image`];function PC(e){let t=jC(e.state),r=MC.parse(JSON.parse(e.widget[`manifest.json`])),a=e=>import.meta.hot?.send(`ekg:state`,{...t,...e}),o=e=>import.meta.hot?.send(`ekg:manifest`,{...r,...e}),s=e=>a({width:e}),c=e=>a({height:e}),l=e=>o({name:e}),u=e=>o({version:e}),d=e=>o({description:e}),f=Object.entries(r.settings??{}).map(([n,r])=>({setting:{...r,key:n},value:t.settings[n]??zC(e.widget,r),update:e=>a({settings:{...t.settings,[n]:e}})})),p=(0,T.useRef)(null),[m,h]=(0,T.useState)({width:1,height:1});(0,T.useEffect)(()=>{let e=p.current;if(!e)return;let t=()=>{let{width:t,height:n}=e.getBoundingClientRect();h({width:t,height:n})},n=new ResizeObserver(t);return n.observe(e),t(),()=>n.disconnect()},[p.current]);let g=Math.min(m.width/t.width,m.height/t.height),[_,v]=(0,T.useState)(n.oneOf.map(e=>{let r=e.$ref.split(`/`).at(-1),i=n.$defs[r].properties.type.const,a={$schema:`https://json-schema.org/draft/2020-12/schema`,$defs:n.$defs,...n.$defs[r].properties.data},o=FC(a.properties,t.events[i]);return{name:r,type:i,schema:a,data:o}}));(0,T.useEffect)(()=>{a({events:Object.fromEntries(_.map(e=>[e.type,e.data]))})},[_]);let y=e=>{let t=_.find(t=>t.name===e);i.fireEvent({id:IC(60),timestamp:Date.now(),type:t.type,data:t.data})};return(0,Z.jsxs)(`div`,{className:`flex h-screen dark:text-slate-100 dark:bg-slate-900`,children:[(0,Z.jsx)(`div`,{className:`bg-black/10 border-r border-white/10 w-72 contain-strict overflow-auto`,children:(0,Z.jsxs)(`div`,{className:`px-6 flex flex-col gap-4 pb-8`,children:[(0,Z.jsx)(`h1`,{className:`text-xl font-bold py-4`,children:`Widget Dev Kit`}),(0,Z.jsxs)(`div`,{className:`flex gap-4`,children:[(0,Z.jsx)(w_,{label:`Width:`,name:`width`,value:t.width,update:s}),(0,Z.jsx)(w_,{label:`Height:`,name:`height`,value:t.height,update:c})]}),(0,Z.jsx)(S_,{type:`text`,label:`Name:`,name:`name`,value:r.name??``,update:l}),(0,Z.jsx)(S_,{type:`text`,label:`Version:`,name:`version`,value:r.version??``,update:u}),(0,Z.jsx)(S_,{type:`textarea`,label:`Description:`,name:`description`,value:r.description??``,update:d}),(0,Z.jsx)(`h1`,{className:`text-lg font-bold pt-4`,children:`Settings`}),f.map(e=>(0,Z.jsx)(VC,{...e},e.setting.key))]})}),(0,Z.jsx)(`div`,{className:`p-4 sm:p-16 flex-1 contain-strict`,children:(0,Z.jsx)(`div`,{className:`@container-[size] h-full grid auto-cols-fr place-items-center`,children:(0,Z.jsx)(`div`,{ref:p,className:`max-w-full`,style:{aspectRatio:`${t.width}/${t.height}`,width:`${100*t.width/t.height}cqh`},children:(0,Z.jsx)(`div`,{className:`relative origin-top-left bg-white dark:bg-black`,style:{width:`${t.width}px`,height:`${t.height}px`,transform:`scale(${g})`},children:(0,Z.jsx)(RC,{state:t,manifest:r,widget:e.widget,updateState:a})})})})}),(0,Z.jsx)(`div`,{className:`bg-black/10 border-l border-white/10 w-72 contain-strict overflow-auto`,children:(0,Z.jsxs)(`div`,{className:`px-6 flex flex-col gap-4 pb-8`,children:[(0,Z.jsx)(`h1`,{className:`text-xl font-bold py-4`,children:`Test Events`}),_.map(e=>(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(b_,{variant:`secondary`,size:`md`,className:`grow`,onClick:()=>y(e.name),children:e.name}),(0,Z.jsx)(b_,{variant:`secondary`,size:`md`,commandfor:`${e.name}-modal`,command:`show-modal`,children:`S`}),(0,Z.jsx)(A_,{id:`${e.name}-modal`,name:e.name,schema:e.schema,data:e.data,setData:t=>v(n=>n.map(n=>n.name===e.name?{...n,data:t}:n))})]},e.name))]})})]})}function FC(e,t){let n=(e,n)=>t?.[e]&&(n===`array`?Array.isArray(t[e]):typeof t[e]===n)?t[e]:null;return Object.fromEntries(Object.entries(e).map(([e,r])=>e===`raw`?[e,n(e,`object`)??{}]:e===`currency`?[e,n(e,`string`)??`USD`]:typeof r!=`object`||!r?[e,null]:`const`in r?[e,r.const]:`enum`in r&&Array.isArray(r.enum)?[e,r.enum.includes(t?.[e])?t[e]:r.enum[0]]:`type`in r?e.endsWith(`At`)&&r.type===`integer`?[e,n(e,`number`)??Date.now()]:e.endsWith(`Cents`)&&r.type===`integer`?[e,n(e,`number`)??500]:r.type===`string`?[e,n(e,`string`)??IC(12)]:r.type===`boolean`?[e,n(e,`boolean`)??!1]:r.type===`integer`?[e,n(e,`number`)??2]:r.type===`array`&&`items`in r&&typeof r.items==`object`&&r.items&&`$ref`in r.items&&r.items.$ref===`#/$defs/ChatNode`?[e,n(e,`array`)??[{type:`text`,text:IC(40)}]]:r.type===`array`?[e,n(e,`array`)??[]]:[e,null]:[e,null]))}function IC(e){let t=new Uint8Array(e);return crypto.getRandomValues(t),Array.from(t,e=>e.toString(36).slice(-1)).join(``)}var LC=(()=>{setInterval(()=>{i.fireEvent({type:`TICK`})},100);let e=BigInt(Math.floor(16777215*Math.random())),t=null,n=null,r=new Map;return{subscribe(t){let n=(e++).toString();return r.set(n,t),()=>{r.delete(n)}},getSnapshot(){return n},register(e){e!==t&&(n&&n.stop(),t=e,n=t?i.createManagedWidget(t):null,r.forEach(e=>e()))}}})();function RC({state:e,manifest:t,widget:n,updateState:r}){let i=n[t.template],a=n[t.css],o=n[t.js],s=Object.fromEntries(Object.entries(t.assets??{}).map(([e,{file:t,type:r}])=>{let i=n[t];return r===`font`&&(i=HC(i)),[e,i]})),c=Object.fromEntries(Object.entries(t.settings??{}).map(([t,r])=>{let i=e.settings[t]??zC(n,r);if(r.type===`font`){let[e,t]=BC(n,i);i=e}return[t,i]})),l=Object.values(t.assets??{}).map(({file:e,type:t})=>{if(t!==`font`)return``;let[r,i]=BC(n,e);return i}).join(``)+Object.entries(t.settings??{}).map(([t,r])=>{if(r.type!==`font`)return``;let i=e.settings[t]??zC(n,r),[a,o]=BC(n,i);return o}).join(``),u=(0,T.useSyncExternalStore)(LC.subscribe,LC.getSnapshot),d=(0,T.useRef)(e.persistedState);d.current=e.persistedState;let f=(0,T.useRef)(r);return f.current=r,(0,T.useEffect)(()=>{if(!u||!i||!o||!a)return;u.init({template:i,js:o,css:a,cdnDomain:`https://cdn.ekg.gg`,fonts:l,assets:s,settings:c,persistedState:d.current});let e=async()=>{let e=await u.persist();JSON.stringify(e)!==JSON.stringify(d.current)&&f.current({persistedState:e})},t=setInterval(e,1e3);return()=>{e(),clearInterval(t)}},[u,i,a,o,l,JSON.stringify(s),JSON.stringify(c)]),(0,Z.jsx)(`div`,{ref:LC.register,className:`size-full`})}function zC(e,t){if(t.type===`font`){if(!t.default)return null;let e=r.find(e=>e.name===t.default)?.value||Object.entries(t.custom||{}).find(e=>e[1]===t.default)?.[0];if(e)return e;throw Error(`Invalid default value for setting "${t.name}". Expected a font name, either built-in or from the custom array.`)}return t.type===`reward_ids`?[]:NC.includes(t.type)?e[t.default]:t.default}function BC(e,t){let n=r.find(e=>e.value===t);if(n)return[n.value,n.font_face];let i=e[t];if(!i)throw Error(`Missing font file: ${t}`);return[HC(i),`
|
|
39
39
|
@font-face {
|
|
40
|
-
font-family: "${
|
|
40
|
+
font-family: "${HC(i)}";
|
|
41
41
|
font-style: normal;
|
|
42
42
|
font-display: swap;
|
|
43
43
|
src: url("${i}");
|
|
44
44
|
}
|
|
45
|
-
`]}function
|
|
45
|
+
`]}function VC({setting:e,value:t,update:n}){if(e.choices){let r=Object.entries(e.choices).map(([e,t])=>({label:t,value:e})),i=[`decimal`,`integer`].includes(e.type)?e=>n(parseFloat(e)):n;return(0,Z.jsx)(D_,{label:e.name,description:e.description,name:e.key,value:t.toString(),update:i,options:r})}let i={label:e.name,description:e.description,name:e.key,value:t,update:n};switch(e.type){case`audio`:return(0,Z.jsx)(j_,{kind:`audio`,...i});case`boolean`:return(0,Z.jsx)(x_,{...i});case`color`:return(0,Z.jsx)(C_,{...i});case`color_array`:return(0,Z.jsx)(I_,{...i,render:e=>(0,Z.jsx)(C_,{...e})});case`decimal`:return(0,Z.jsx)(T_,{...i});case`decimal_array`:return(0,Z.jsx)(I_,{...i,render:e=>(0,Z.jsx)(T_,{...e})});case`font`:let t=[{label:`Built-in Fonts`,options:r.map(({name:e,value:t})=>({name:e,value:t}))}];return e.custom&&t.unshift({label:`Artist's Fonts`,options:Object.entries(e.custom).map(([e,t])=>({name:t,value:e}))}),(0,Z.jsx)(F_,{options:t,...i});case`image`:return(0,Z.jsx)(j_,{kind:`image`,...i});case`integer`:return(0,Z.jsx)(w_,{...i});case`integer_array`:return(0,Z.jsx)(I_,{...i,render:e=>(0,Z.jsx)(w_,{...e})});case`string`:return(0,Z.jsx)(S_,{type:`text`,...i});case`string_array`:case`reward_ids`:return(0,Z.jsx)(I_,{...i,render:e=>(0,Z.jsx)(S_,{type:`text`,...e})})}return null}function HC(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)-t+r}return`h`+(t>>>0).toString(36).padStart(7,`0`)}import.meta.hot?(UC(import.meta.hot.data.root??=(0,w.createRoot)(document.body),t,e),import.meta.hot.accept(`ekg:widget`,e=>{UC(import.meta.hot.data.root,e.widget,e.state)})):UC((0,w.createRoot)(document.body),t,e);function UC(e,t,n){let r=Object.fromEntries(Object.entries(t).map(([e,t])=>[e.slice(2),t]));e.render((0,Z.jsx)(T.StrictMode,{children:(0,Z.jsx)(O,{fallbackRender:WC,children:(0,Z.jsx)(PC,{widget:r,state:n})})}))}function WC({error:e}){return(0,Z.jsx)(`div`,{className:`text-2xl text-red-500`,children:e.message})}
|
package/dist/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>EKG.gg Widget Dev Kit</title>
|
|
7
|
-
<script async type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script async type="module" crossorigin src="/assets/index-PTJ0-hJh.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/assets/index-D7-5KvI9.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body class="dark"></body>
|
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import e from"yargs";import{hideBin as t}from"yargs/helpers";import n from"ajv/dist/2020.js";import r from"chalk";import i from"node:fs/promises";import a from"node:path";import{build as o}from"tsdown";import{fileURLToPath as s}from"node:url";import{
|
|
2
|
+
import e from"yargs";import{hideBin as t}from"yargs/helpers";import n from"ajv/dist/2020.js";import r from"chalk";import i from"node:fs/promises";import a from"node:path";import{build as o}from"tsdown";import{fileURLToPath as s,pathToFileURL as c}from"node:url";import{createServer as l,normalizePath as u}from"vite";import{z as d}from"zod/v4";d.object({width:d.number().min(0).catch(1e3),height:d.number().min(0).catch(1e3),settings:d.record(d.string(),d.unknown()).catch({}),events:d.record(d.string(),d.unknown()).catch({}),persistedState:d.unknown().optional()});const f=d.object({$schema:d.literal(`https://ekg.gg/schemas/manifest.json`).default(`https://ekg.gg/schemas/manifest.json`),name:d.string().optional(),version:d.string().optional(),description:d.string().optional(),template:d.string().default(``),css:d.string().default(``),js:d.string().default(``),assets:d.record(d.string(),d.object({type:d.string().default(``),file:d.string().default(``)})).optional(),settings:d.record(d.string(),d.looseObject({type:d.string().default(``),name:d.string().default(``),description:d.string().optional()})).optional()});async function p(e,t){let n=a.resolve(e),r=await m(n),i=a.join(r,`manifest.json`),o=s(new URL(`..`,import.meta.url)),c=t?o:a.join(o,`..`,`..`),l=a.join(o,t?`client`:`dist`),d=e=>u(a.relative(l,e)),f=a.join(o,`.runtime`),p=a.join(f,`state.json`);return{root:u(n),ekg:u(f),state:u(p),widget:u(r),manifest:u(i),node_modules:u(c),server:u(l),relative:d}}async function m(e){for await(let t of i.glob(`**/manifest.json`,{cwd:e}))if(!t.includes(`.runtime`)&&!t.includes(`dist`))return a.dirname(a.join(e,t));throw`No manifest.json found in ${e}`}async function h(e,t){let n=[`assets/js/devkit.d.ts`,`assets/js/devkit.js`,`assets/js/widget-worker.js`,`assets/js/emscripten-module.wasm`,`schemas/events.json`,`schemas/manifest.json`,`schemas/fonts.json`];await i.mkdir(e,{recursive:!0});try{await i.writeFile(a.join(e,`state.json`),`{}`,{flag:`wx`})}catch{}let r=await Promise.allSettled(n.map(t=>i.stat(a.join(e,a.basename(t))))),o=r.every(e=>e.status===`fulfilled`&&e.value.isFile());if(!(r.every(e=>e.status===`fulfilled`&&e.value.isFile()&&e.value.mtimeMs>Date.now()-6048e5)&&!t))try{await Promise.all(n.map(t=>g(e,t)))}catch(e){if(o&&!t)console.log(`Failed to update EKG types and devkit binary. Continuing with existing files.`);else throw`Failed to download devkit: ${e}`}}async function g(e,t){let n=await(await fetch(`https://ekg.gg/${t}?t=${Date.now()}`)).bytes();await i.writeFile(a.join(e,a.basename(t)),n)}async function _(e,t){let n=(e,t)=>`/// <reference types="@ekg_gg/devkit" />
|
|
3
3
|
|
|
4
4
|
declare namespace EKG {
|
|
5
5
|
interface WidgetAssets ${e}
|
|
6
6
|
interface WidgetSettings ${t}
|
|
7
7
|
}
|
|
8
|
-
`,r=(e,t)=>{let n=Object.entries(e).map(([e,n])=>` ${e}: ${t(n)}\n`).join(``);return n?`{\n${n} }`:`{}`},o=e=>{if(e.choices)return Object.keys(e.choices).map(e=>JSON.stringify(e)).join(` | `);switch(e.type){case`string`:case`color`:case`image`:case`audio`:case`font`:return`string`;case`string_array`:case`color_array`:case`reward_ids`:return`string[]`;case`decimal`:case`integer`:return`number`;case`decimal_array`:case`integer_array`:return`number[]`;case`boolean`:return`boolean`;default:return`any`}};try{let s=await i.readFile(t),c=
|
|
9
|
-
export { manager } from '
|
|
10
|
-
export { default as EventSchema } from '
|
|
11
|
-
export { default as Fonts } from '
|
|
8
|
+
`,r=(e,t)=>{let n=Object.entries(e).map(([e,n])=>` ${e}: ${t(n)}\n`).join(``);return n?`{\n${n} }`:`{}`},o=e=>{if(e.choices)return Object.keys(e.choices).map(e=>JSON.stringify(e)).join(` | `);switch(e.type){case`string`:case`color`:case`image`:case`audio`:case`font`:return`string`;case`string_array`:case`color_array`:case`reward_ids`:return`string[]`;case`decimal`:case`integer`:return`number`;case`decimal_array`:case`integer_array`:return`number[]`;case`boolean`:return`boolean`;default:return`any`}};try{let s=await i.readFile(t),c=f.parse(JSON.parse(s.toString(`utf8`))),l=r(c.assets??{},()=>`string`),u=r(c.settings??{},o);await i.writeFile(a.join(e,`ekg.d.ts`),n(l,u))}catch{try{await i.writeFile(a.join(e,`ekg.d.ts`),n(`{}`,`{}`),{flag:`wx`})}catch{}}}async function v(e,t){let s=await p(e,t);await h(s.ekg);let c=new n({allErrors:!0,discriminator:!0}),l=JSON.parse(await i.readFile(a.join(s.ekg,`manifest.json`),{encoding:`utf8`}));l.properties.settings.additionalProperties.unevaluatedProperties=!0;let u=c.compile(l),d=await y(s.manifest);if(!u(d)&&u.errors){console.log(r.red(`Invalid manifest.json`));for(let e of u.errors)console.log(r.red(`${r.bold(e.instancePath.slice(1))}: ${e.message}`));process.exit(1)}let f=new Set([`manifest.json`,d.css,d.template]);for(let e of Object.values(d.assets??{}))f.add(e.file);for(let e of Object.values(d.settings??{}))if([`image`,`audio`].includes(e.type)&&e.default&&f.add(e.default),e.type===`font`&&e.custom)for(let t of Object.keys(e.custom))f.add(t);let m=(await Promise.all(f.values().map(async e=>{try{if((await i.stat(a.join(s.widget,e))).isFile())return null}catch{}return e}))).filter(e=>e!==null);if(m.length){for(let e of m)console.log(r.red(`Missing file: ${r.bold(e)}`));process.exit(1)}let g=a.extname(d.js);try{await o({config:!1,tsconfig:!1,logLevel:`error`,outDir:a.join(s.root,`dist`),copy:f.values().map(e=>({from:a.join(s.widget,e),to:a.join(s.root,`dist`,e)})).toArray(),entry:a.join(s.widget,d.js),loader:{[g]:`ts`},outExtensions:()=>({js:g}),format:`esm`,platform:`neutral`,target:`es2023`,dts:!1})}catch(e){if(typeof e==`object`&&e&&`errors`in e&&Array.isArray(e.errors))for(let t of e.errors)t instanceof Error?console.log(t.message):console.error(t);else console.error(e);process.exit(1)}console.log(r.green(`${r.bold(`Success!`)} Widget files were written to ${a.join(s.root,`dist`)}`))}async function y(e){try{return JSON.parse(await i.readFile(e,{encoding:`utf8`}))}catch(e){console.log(r.red(`Failed to read widget's manifest.json`)),console.error(e),process.exit(1)}}async function b(e,t){let n=await p(e,t),r=(...e)=>`/@fs${c(a.join(...e)).pathname}`;await h(n.ekg);let o=await l({configFile:t?`vite.config.ts`:!1,root:n.server,define:{"import.meta.hot":!1},server:{fs:{allow:[n.node_modules,n.widget]},watch:{ignored:[`!${n.ekg}/**`]}},plugins:[{name:`EKG Dev Kit`,configureServer(e){e.ws.on(`ekg:state`,e=>{i.writeFile(n.state,JSON.stringify(e,null,2)).catch(e=>console.error(`Failed to write state file.`,e))}),e.ws.on(`ekg:manifest`,e=>{i.writeFile(n.manifest,JSON.stringify(e,null,2)).catch(e=>console.error(`Failed to write manifest file.`,e))})},resolveId(e){if(e.startsWith(`ekg:`))return`\0${e}`},load(e){let t=[`json`,`css`,`hbs`].join(`|`);switch(e){case`\0ekg:devkit`:return`
|
|
9
|
+
export { manager } from '${r(n.ekg,`devkit.js`)}'
|
|
10
|
+
export { default as EventSchema } from '${r(n.ekg,`events.json`)}'
|
|
11
|
+
export { default as Fonts } from '${r(n.ekg,`fonts.json`)}'
|
|
12
12
|
`;case`\0ekg:widget`:return`
|
|
13
|
-
export { default as state } from '
|
|
13
|
+
export { default as state } from '${r(n.state)}?raw'
|
|
14
14
|
|
|
15
|
-
const inline = import.meta.glob(['./**', '
|
|
15
|
+
const inline = import.meta.glob(['./**', '!./**/*.(${t})'], {
|
|
16
16
|
base: '${n.relative(n.widget)}',
|
|
17
17
|
query: '?inline',
|
|
18
18
|
import: 'default',
|
|
@@ -29,4 +29,4 @@ declare namespace EKG {
|
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
export const widget = { ...inline, ...raw }
|
|
32
|
-
`}},transform(e,t){if(t.startsWith(n.widget)&&!t.startsWith(n.ekg)&&!e.startsWith(`export default `))return{code:`export default ${JSON.stringify(e)}`}}}]});
|
|
32
|
+
`}},transform(e,t){if(t.startsWith(n.widget)&&!t.startsWith(n.ekg)&&!e.startsWith(`export default `))return{code:`export default ${JSON.stringify(e)}`}}}]});o.watcher.add(n.manifest),o.watcher.on(`change`,e=>{u(e)===n.manifest&&_(n.root,n.manifest)}),await _(n.root,n.manifest),await o.listen(),o.printUrls(),o.bindCLIShortcuts({print:!0})}async function x(e,t){let n=await p(e,!1);await h(n.ekg,t),await _(n.root,n.manifest)}e(t(process.argv)).command(`dev [dir]`,`Runs the EKG devkit, watching for changes`,e=>e.positional(`dir`,{type:`string`,describe:`Folder to watch`,default:`.`}).option(`dev`,{alias:`d`,type:`boolean`,description:`Internal option when developing the EKG CLI`,hidden:!0}),e=>b(e.dir,e.dev??!1)).command(`build [dir]`,`Builds the widget into a directory ready for uploading to EKG`,e=>e.positional(`dir`,{type:`string`,describe:`Folder to watch`,default:`.`}).option(`dev`,{alias:`d`,type:`boolean`,description:`Internal option when developing the EKG CLI`,hidden:!0}),e=>v(e.dir,e.dev??!1)).command(`sync [dir]`,`Regenerates the EKG types`,e=>e.positional(`dir`,{type:`string`,describe:`Folder to watch`,default:`.`}).option(`force`,{alias:`f`,type:`boolean`,description:`Force downloading types and devkit binary from EKG servers`}),({dir:e,force:t})=>x(e,t)).demandCommand().help().parse();export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekg_gg/devkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
|
+
"description": "Development toolkit for building EKG.gg streaming widgets — local dev server, live preview, and build pipeline.",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"repository": "github:ekggg/devkit",
|
|
6
7
|
"bugs": "https://github.com/ekggg/devkit/issues",
|
package/.vscode/settings.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|