ziex 0.0.1-dev.4 → 0.0.1-dev.5

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/package.json CHANGED
@@ -3,7 +3,6 @@
3
3
  "description": "ZX is a framework for building web applications with Zig.",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
- "version": "0.0.1-dev.4",
7
6
  "exports": {
8
7
  ".": "./index.js",
9
8
  "./react": "./react/index.js",
@@ -29,5 +28,6 @@
29
28
  "author": "Nurul Huda (Apon) <me@nurulhudaapon.com>",
30
29
  "license": "MIT",
31
30
  "module": "index.js",
32
- "types": "index.d.ts"
33
- }
31
+ "types": "index.d.ts",
32
+ "version": "0.0.1-dev.5"
33
+ }
package/wasm/index.d.ts CHANGED
@@ -1,3 +1,19 @@
1
- import type { InitOptions } from "./types";
2
- export type { InitOptions } from "./types";
1
+ declare class ZXInstance {
2
+ exports: Record<string, (...args: any[]) => void>;
3
+ events: Event[];
4
+ constructor({ exports, events }: ZXInstanceOptions);
5
+ }
3
6
  export declare function init(options?: InitOptions): Promise<void>;
7
+ export type InitOptions = {
8
+ url?: string;
9
+ };
10
+ type ZXInstanceOptions = {
11
+ exports: Record<string, (...args: any[]) => void>;
12
+ events?: Event[];
13
+ };
14
+ declare global {
15
+ interface Window {
16
+ _zx: ZXInstance;
17
+ }
18
+ }
19
+ export {};
package/wasm/index.js CHANGED
@@ -1 +1 @@
1
- var U={nan:0,null:1,true:2,false:3,undefined:4,globalThis:5,runtime:6};var _=new TextEncoder,D=new TextDecoder("utf-8");class W{memory;values=[NaN,null,!0,!1,void 0,globalThis,this];idPool=[];importObject(){return{"zig-js":{valueGet:this.valueGet.bind(this),valueSet:this.valueSet.bind(this),valueDeinit:this.valueDeinit.bind(this),valueObjectCreate:this.valueObjectCreate.bind(this),valueStringCreate:this.valueStringCreate.bind(this),valueStringLen:this.valueStringLen.bind(this),valueStringCopy:this.valueStringCopy.bind(this),valueNew:this.valueNew.bind(this),funcApply:this.funcApply.bind(this)}}}valueGet(m,n,c,s){let x=this.loadValue(n),O=this.loadString(c,s),y=Reflect.get(x,O);this.storeValue(m,y)}valueSet(m,n,c,s){let x=this.loadValue(m),O=this.loadString(n,c),y=this.loadRef(s);Reflect.set(x,O,y)}valueDeinit(m){if(m>6)this.values[m]=null,this.idPool.push(m)}valueObjectCreate(m){this.storeValue(m,{})}valueStringCreate(m,n,c){let s=this.loadString(n,c);this.storeValue(m,s)}valueStringLen(m){let n=this.loadValue(m);return _.encode(n).byteLength}valueStringCopy(m,n,c){if(this.memory==null)return;let s=this.loadValue(m),x=_.encode(s);if(x.byteLength>c)return;new Uint8Array(this.memory.buffer,n,x.length).set(x)}valueNew(m,n,c,s){let x=this.loadValue(n),O=[];for(let j=0;j<s;j++)O.push(this.loadRef(c+j*8));let y=Reflect.construct(x,O);this.storeValue(m,y)}funcApply(m,n,c,s,x){let O=this.loadValue(n),y=this.loadRef(c),j=[];for(let z=0;z<x;z++)j.push(this.loadRef(s+z*8));let B=Reflect.apply(O,y,j);this.storeValue(m,B)}loadValue(m){return this.values[m]}deleteValue(m){let n=this.values[m];return this.valueDeinit(m),n}loadRef(m){if(this.memory==null)return;let c=new DataView(this.memory.buffer).getFloat64(m,!0);if(!isNaN(c))return c;let s=this.loadRefId(m);return this.values[s]}loadRefId(m){if(this.memory==null)return 0;return new DataView(this.memory.buffer).getUint32(m,!0)}storeValue(m,n){if(this.memory==null)return;let c=new DataView(this.memory.buffer);if(typeof n==="number"){if(isNaN(n))c.setUint32(m,U.nan,!0),c.setUint32(m+4,2146959360,!0);else c.setFloat64(m,n,!0);return}if(n===null){c.setUint32(m,U.null,!0),c.setUint32(m+4,2146959360,!0);return}if(n===void 0){c.setUint32(m,U.undefined,!0),c.setUint32(m+4,2146959360,!0);return}let s=this.idPool.pop();if(s===void 0)s=this.values.length;this.values[s]=n;let x=0;switch(typeof n){case"object":x=1;break;case"string":x=2;break;case"symbol":x=3;break;case"function":x=4;break}c.setUint32(m,Number(s),!0),c.setUint32(m+4,2146959360|x,!0)}loadString(m,n){if(this.memory==null)return"";let s=new Uint8ClampedArray(this.memory.buffer,m,Number(n)).slice();return D.decode(s)}}var E="/assets/main.wasm",b=new W,F={module:{},env:{},...b.importObject()};async function Z(m={}){let n=await(await fetch(m?.url??E)).arrayBuffer(),{instance:c}=await WebAssembly.instantiate(n,F);b.memory=c.exports.memory,window._zx=c.exports;let s=c.exports.main;s()}export{Z as init};
1
+ var z={nan:0,null:1,true:2,false:3,undefined:4,globalThis:5,runtime:6};var W=new TextEncoder,j=new TextDecoder("utf-8");class E{memory;values=[NaN,null,!0,!1,void 0,globalThis,this];idPool=[];importObject(){return{"zig-js":{valueGet:this.valueGet.bind(this),valueSet:this.valueSet.bind(this),valueDeinit:this.valueDeinit.bind(this),valueObjectCreate:this.valueObjectCreate.bind(this),valueStringCreate:this.valueStringCreate.bind(this),valueStringLen:this.valueStringLen.bind(this),valueStringCopy:this.valueStringCopy.bind(this),valueNew:this.valueNew.bind(this),funcApply:this.funcApply.bind(this)}}}valueGet(n,s,c,m){let x=this.loadValue(s),o=this.loadString(c,m),O=Reflect.get(x,o);this.storeValue(n,O)}valueSet(n,s,c,m){let x=this.loadValue(n),o=this.loadString(s,c),O=this.loadRef(m);Reflect.set(x,o,O)}valueDeinit(n){if(n>6)this.values[n]=null,this.idPool.push(n)}valueObjectCreate(n){this.storeValue(n,{})}valueStringCreate(n,s,c){let m=this.loadString(s,c);this.storeValue(n,m)}valueStringLen(n){let s=this.loadValue(n);return W.encode(s).byteLength}valueStringCopy(n,s,c){if(this.memory==null)return;let m=this.loadValue(n),x=W.encode(m);if(x.byteLength>c)return;new Uint8Array(this.memory.buffer,s,x.length).set(x)}valueNew(n,s,c,m){let x=this.loadValue(s),o=[];for(let Z=0;Z<m;Z++)o.push(this.loadRef(c+Z*8));let O=Reflect.construct(x,o);this.storeValue(n,O)}funcApply(n,s,c,m,x){let o=this.loadValue(s),O=this.loadRef(c),Z=[];for(let y=0;y<x;y++)Z.push(this.loadRef(m+y*8));let b=Reflect.apply(o,O,Z);this.storeValue(n,b)}loadValue(n){return this.values[n]}deleteValue(n){let s=this.values[n];return this.valueDeinit(n),s}loadRef(n){if(this.memory==null)return;let c=new DataView(this.memory.buffer).getFloat64(n,!0);if(!isNaN(c))return c;let m=this.loadRefId(n);return this.values[m]}loadRefId(n){if(this.memory==null)return 0;return new DataView(this.memory.buffer).getUint32(n,!0)}storeValue(n,s){if(this.memory==null)return;let c=new DataView(this.memory.buffer);if(typeof s==="number"){if(isNaN(s))c.setUint32(n,z.nan,!0),c.setUint32(n+4,2146959360,!0);else c.setFloat64(n,s,!0);return}if(s===null){c.setUint32(n,z.null,!0),c.setUint32(n+4,2146959360,!0);return}if(s===void 0){c.setUint32(n,z.undefined,!0),c.setUint32(n+4,2146959360,!0);return}let m=this.idPool.pop();if(m===void 0)m=this.values.length;this.values[m]=s;let x=0;switch(typeof s){case"object":x=1;break;case"string":x=2;break;case"symbol":x=3;break;case"function":x=4;break}c.setUint32(n,Number(m),!0),c.setUint32(n+4,2146959360|x,!0)}loadString(n,s){if(this.memory==null)return"";let m=new Uint8ClampedArray(this.memory.buffer,n,Number(s)).slice();return j.decode(m)}}var R="/assets/main.wasm",X=new E,U={module:{},env:{},...X.importObject()};class _{exports;events;constructor({exports:n,events:s}){this.exports=n,this.events=s??[]}}async function J(n={}){let s=await(await fetch(n?.url??R)).arrayBuffer(),{instance:c}=await WebAssembly.instantiate(s,U);X.memory=c.exports.memory,window._zx=new _({exports:c.exports});let m=c.exports.main;m()}export{J as init};
package/wasm/types.d.ts CHANGED
@@ -1,9 +1 @@
1
1
  export type ComponentMetadata = {};
2
- export type InitOptions = {
3
- url?: string;
4
- };
5
- declare global {
6
- interface Window {
7
- _zx: Record<string, (...args: any[]) => void>;
8
- }
9
- }