typegpu
Version:
A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.
19 lines • 120 kB
JavaScript
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7; var _class8; var _class9; var _class10; var _class11; var _class12; var _class13; var _class14; var _class15; var _class16; var _class17; var _class18; var _class19; var _class20; var _class21; var _class22; var _class23; var _class24; var _class25; var _class26; var _class27; var _class28; var _class29;var _chunkBZVU4Q6Acjs = require('./chunk-BZVU4Q6A.cjs');var _chunkCDUKTYEScjs = require('./chunk-CDUKTYES.cjs');var _chunkBJSN5UVVcjs = require('./chunk-BJSN5UVV.cjs');function gn(e){if(typeof _optionalChain([e, 'optionalAccess', _2 => _2[_chunkBJSN5UVVcjs.c]])=="function")return e[_chunkBJSN5UVVcjs.c].bind(e)}function dt(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}var ba={f:{1:_chunkBJSN5UVVcjs.ma,2:_chunkBJSN5UVVcjs.oa,3:_chunkBJSN5UVVcjs.ta,4:_chunkBJSN5UVVcjs.ya},h:{1:_chunkBJSN5UVVcjs.na,2:_chunkBJSN5UVVcjs.pa,3:_chunkBJSN5UVVcjs.ua,4:_chunkBJSN5UVVcjs.za},i:{1:_chunkBJSN5UVVcjs.la,2:_chunkBJSN5UVVcjs.qa,3:_chunkBJSN5UVVcjs.va,4:_chunkBJSN5UVVcjs.Aa},u:{1:_chunkBJSN5UVVcjs.ka,2:_chunkBJSN5UVVcjs.ra,3:_chunkBJSN5UVVcjs.wa,4:_chunkBJSN5UVVcjs.Ba},b:{1:_chunkBJSN5UVVcjs.ja,2:_chunkBJSN5UVVcjs.sa,3:_chunkBJSN5UVVcjs.xa,4:_chunkBJSN5UVVcjs.Ca}},Sa={vec2f:_chunkBJSN5UVVcjs.oa,vec2h:_chunkBJSN5UVVcjs.pa,vec2i:_chunkBJSN5UVVcjs.qa,vec2u:_chunkBJSN5UVVcjs.ra,"vec2<bool>":_chunkBJSN5UVVcjs.sa,vec3f:_chunkBJSN5UVVcjs.ta,vec3h:_chunkBJSN5UVVcjs.ua,vec3i:_chunkBJSN5UVVcjs.va,vec3u:_chunkBJSN5UVVcjs.wa,"vec3<bool>":_chunkBJSN5UVVcjs.xa,vec4f:_chunkBJSN5UVVcjs.ya,vec4h:_chunkBJSN5UVVcjs.za,vec4i:_chunkBJSN5UVVcjs.Aa,vec4u:_chunkBJSN5UVVcjs.Ba,"vec4<bool>":_chunkBJSN5UVVcjs.Ca,mat2x2f:_chunkBJSN5UVVcjs.Ma,mat3x3f:_chunkBJSN5UVVcjs.Na,mat4x4f:_chunkBJSN5UVVcjs.Oa},yn={vec2f:_chunkBJSN5UVVcjs.ma,vec2h:_chunkBJSN5UVVcjs.na,vec2i:_chunkBJSN5UVVcjs.la,vec2u:_chunkBJSN5UVVcjs.ka,"vec2<bool>":_chunkBJSN5UVVcjs.ja,vec3f:_chunkBJSN5UVVcjs.ma,vec3h:_chunkBJSN5UVVcjs.na,vec3i:_chunkBJSN5UVVcjs.la,vec3u:_chunkBJSN5UVVcjs.ka,"vec3<bool>":_chunkBJSN5UVVcjs.ja,vec4f:_chunkBJSN5UVVcjs.ma,vec4h:_chunkBJSN5UVVcjs.na,vec4i:_chunkBJSN5UVVcjs.la,vec4u:_chunkBJSN5UVVcjs.ka,"vec4<bool>":_chunkBJSN5UVVcjs.ja,mat2x2f:_chunkBJSN5UVVcjs.oa,mat3x3f:_chunkBJSN5UVVcjs.ta,mat4x4f:_chunkBJSN5UVVcjs.ya};function Ne(e,t){if(_chunkBJSN5UVVcjs.M.call(void 0, e)||_chunkBJSN5UVVcjs.Y.call(void 0, e))return _nullishCoalesce(e.propTypes[t], () => (_chunkBJSN5UVVcjs.ca));if(e===_chunkBJSN5UVVcjs.ja||_chunkCDUKTYEScjs.c.call(void 0, e))return _chunkBJSN5UVVcjs.ca;let r=t.length;if(_chunkBJSN5UVVcjs.E.call(void 0, e)&&r>=1&&r<=4){let n=e.type.includes("bool")?"b":e.type[4],a=ba[n][r];if(a)return a}return _chunkBJSN5UVVcjs.ca}function rr(e){return _chunkBJSN5UVVcjs.L.call(void 0, e)||_chunkBJSN5UVVcjs.X.call(void 0, e)?e.elementType:e.type in yn?yn[e.type]:_chunkBJSN5UVVcjs.ca}function nr(e){if(/^0x[0-9a-f]+$/i.test(e))return _chunkBJSN5UVVcjs.da.call(void 0, e,_chunkBJSN5UVVcjs.ha);if(/^0b[01]+$/i.test(e))return _chunkBJSN5UVVcjs.da.call(void 0, `${Number.parseInt(e.slice(2),2)}`,_chunkBJSN5UVVcjs.ha);if(/^-?(?:\d+\.\d*|\d*\.\d+)$/i.test(e))return _chunkBJSN5UVVcjs.da.call(void 0, e,_chunkBJSN5UVVcjs.ia);if(/^-?\d+(?:\.\d+)?e-?\d+$/i.test(e))return _chunkBJSN5UVVcjs.da.call(void 0, e,_chunkBJSN5UVVcjs.ia);if(/^-?\d+$/i.test(e))return _chunkBJSN5UVVcjs.da.call(void 0, e,_chunkBJSN5UVVcjs.ha)}var ar={rank:Number.POSITIVE_INFINITY,action:"none"};function Ae(e){return e.type==="decorated"?e.inner:e}function Tn(e){return _chunkBJSN5UVVcjs.E.call(void 0, e)?_chunkBJSN5UVVcjs.Da[e.type]:void 0}function ft(e,t){let r=Ae(e),n=Ae(t);if(r.type===n.type)return{rank:0,action:"none"};if(r.type==="abstractFloat"){if(n.type==="f32")return{rank:1,action:"none"};if(n.type==="f16")return{rank:2,action:"none"}}if(r.type==="abstractInt"){if(n.type==="i32")return{rank:3,action:"none"};if(n.type==="u32")return{rank:4,action:"none"};if(n.type==="abstractFloat")return{rank:5,action:"none"};if(n.type==="f32")return{rank:6,action:"none"};if(n.type==="f16")return{rank:7,action:"none"}}if(_chunkBJSN5UVVcjs.E.call(void 0, r)&&_chunkBJSN5UVVcjs.E.call(void 0, n)){let a=Tn(r),o=Tn(n);if(a&&o)return ft(a,o)}return _chunkBJSN5UVVcjs.I.call(void 0, r)&&_chunkBJSN5UVVcjs.I.call(void 0, n)?{rank:0,action:"none"}:ar}function va(e,t){let r=Ae(e),n=Ae(t);if(r.type==="ptr"&&ft(r.inner,n).rank<Number.POSITIVE_INFINITY)return{rank:0,action:"deref"};if(n.type==="ptr"&&ft(r,n.inner).rank<Number.POSITIVE_INFINITY)return{rank:1,action:"ref"};let a={f32:0,f16:1,i32:2,u32:3,bool:4};if(r.type in a&&n.type in a){let o=r.type,i=n.type;if(o!==i){let s=a[o];return{rank:a[i]<s?10:20,action:"cast",targetType:n}}}return ar}function Da(e,t,r){let n=ft(e,t);return n.rank<Number.POSITIVE_INFINITY?n:r?va(e,t):ar}function xn(e,t,r){let n,a=Number.POSITIVE_INFINITY,o=new Map;for(let u of t){let c=0,m=[],g=!0;for(let T of e){let x=Da(T,u,r);if(x.rank===Number.POSITIVE_INFINITY){g=!1;break}c+=x.rank,m.push(x)}g&&c<a&&(a=c,n=u,o.set(n,m))}if(!n)return;let s=o.get(n).map((u,c)=>({sourceIndex:c,action:u.action,...u.action==="cast"&&{targetType:u.targetType}})),l=s.some(u=>u.action==="cast");return{targetType:n,actions:s,hasImplicitConversions:l}}function or(e){return e.type==="abstractFloat"?_chunkBJSN5UVVcjs.ma:e.type==="abstractInt"?_chunkBJSN5UVVcjs.la:e}function hn(e,t){if(e.length===0)return;let r=[...new Set(e.map(Ae))],n=t?[...new Set(t.map(Ae))]:r,a=xn(e,n,!1);if(a)return a;let o=xn(e,n,!0);if(o)return o.hasImplicitConversions=o.actions.some(i=>i.action==="cast"),o}function Fa(e,t,r,n){if(r.action==="none")return _chunkBJSN5UVVcjs.da.call(void 0, t.value,n);let a=e.resolve(t.value);switch(r.action){case"ref":return _chunkBJSN5UVVcjs.da.call(void 0, `&${a}`,n);case"deref":return _chunkBJSN5UVVcjs.da.call(void 0, `*${a}`,n);case"cast":return _chunkBJSN5UVVcjs.da.call(void 0, `${e.resolve(n)}(${a})`,n);default:dt(r.action,"applyActionToSnippet")}}function M(e,t,r){let n=t.map(o=>o.dataType);if(n.some(o=>o===_chunkBJSN5UVVcjs.ca))return;let a=hn(n,r);if(a)return a.hasImplicitConversions&&console.warn(`Implicit conversions from [
${t.map(o=>` ${o.value}: ${o.dataType.type}`).join(`,
`)}
] to ${a.targetType.type} are supported, but not recommended.
Consider using explicit conversions instead.`),t.map((o,i)=>{let s=a.actions[i];return _chunkBJSN5UVVcjs.j.call(void 0, s,"Action should not be undefined"),Fa(e,o,s,a.targetType)})}function ir(e,t,r){return Object.keys(t.propTypes).map(a=>{let o=r[a];if(!o)throw new Error(`Missing property ${a}`);let i=t.propTypes[a];return _nullishCoalesce(_optionalChain([M, 'call', _3 => _3(e,[o],[i]), 'optionalAccess', _4 => _4[0]]), () => (o))})}function ge(e){if(_chunkBJSN5UVVcjs.ea.call(void 0, e))return e;if(_chunkBJSN5UVVcjs.z.call(void 0, e))return _chunkBJSN5UVVcjs.da.call(void 0, e,e[_chunkBJSN5UVVcjs.b]);if(_chunkBJSN5UVVcjs.B.call(void 0, e)||_chunkBJSN5UVVcjs.F.call(void 0, e))return _chunkBJSN5UVVcjs.da.call(void 0, e,Sa[e.kind]);if(Array.isArray(e)){let t=e.map(ge).filter(Boolean),r=_chunkBJSN5UVVcjs.s.call(void 0, );if(!r)throw new Error("Tried to coerce array without a context");let n=M(r,t),a=_optionalChain([hn, 'call', _5 => _5(t.map(o=>o.dataType)), 'optionalAccess', _6 => _6.targetType]);return!n||!a?_chunkBJSN5UVVcjs.da.call(void 0, e,_chunkBJSN5UVVcjs.ca):_chunkBJSN5UVVcjs.da.call(void 0, n.map(o=>o.value).join(", "),_chunkBZVU4Q6Acjs.X.call(void 0, or(a),e.length))}return typeof e=="string"||typeof e=="function"||typeof e=="object"||typeof e=="symbol"||typeof e>"u"||e===null?_chunkBJSN5UVVcjs.da.call(void 0, e,_chunkBJSN5UVVcjs.ca):typeof e=="number"||typeof e=="bigint"?_chunkBJSN5UVVcjs.da.call(void 0, e,_nullishCoalesce(_optionalChain([nr, 'call', _7 => _7(String(e)), 'optionalAccess', _8 => _8.dataType]), () => (_chunkBJSN5UVVcjs.ca))):typeof e=="boolean"?_chunkBJSN5UVVcjs.da.call(void 0, e,_chunkBJSN5UVVcjs.ja):_chunkBJSN5UVVcjs.da.call(void 0, e,_chunkBJSN5UVVcjs.ca)}var K={get(e,t){if(t in e)return Reflect.get(e,t);if(t!=="~providing")return t==="toString"||t===Symbol.toStringTag||t===Symbol.toPrimitive?()=>e.toString():new Proxy({"~resolve":r=>`${r.resolve(e)}.${String(t)}`,toString:()=>`.value(...).${String(t)}:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, e), () => ("<unnamed>"))}`,[_chunkBJSN5UVVcjs.b]:Ne(e[_chunkBJSN5UVVcjs.b],String(t))},K)}};function je(e,t){let r=t,n;for(;n=gn(r);)r=n(e);return r}function wn(e,t){return new sr(e,t)}var sr=class{constructor(t,r){this.dataType=t;this._value=r;this[_chunkBJSN5UVVcjs.a]={dataType:t}}$name(t){return _chunkBJSN5UVVcjs.f.call(void 0, this,t),this}"~resolve"(t){let r=t.names.makeUnique(_chunkBJSN5UVVcjs.e.call(void 0, this)),n=t.resolveValue(this._value,this.dataType);return t.addDeclaration(`const ${r} = ${n};`),r}toString(){return`const:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, this), () => ("<unnamed>"))}`}[_chunkBJSN5UVVcjs.c](){return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, this), () => ("<unnamed>"))}`,[_chunkBJSN5UVVcjs.b]:this.dataType},K)}get value(){return _chunkBJSN5UVVcjs.v.call(void 0, )?this[_chunkBJSN5UVVcjs.c]():this._value}};function Pe(e){return _optionalChain([e, 'optionalAccess', _9 => _9.resourceType])==="slot"}function Be(e){return _optionalChain([e, 'optionalAccess', _10 => _10.resourceType])==="derived"}function ze(e){return _optionalChain([e, 'optionalAccess', _11 => _11["~providing"]])!==void 0}function qe(e){return _optionalChain([e, 'optionalAccess', _12 => _12.resourceType])==="accessor"}function ur(e){return typeof _optionalChain([e, 'optionalAccess', _13 => _13["~resolve"]])=="function"}function ct(e){return typeof e=="number"||typeof e=="boolean"||typeof e=="string"||ur(e)||_chunkBJSN5UVVcjs.K.call(void 0, e)||Pe(e)||Be(e)||ze(e)}function bn(e){return!!e&&typeof e=="object"&&"getMappedRange"in e&&"mapAsync"in e}function Sn(e){return _optionalChain([e, 'optionalAccess', _14 => _14.resourceType])==="buffer-usage"}function pr(e){return!!_optionalChain([e, 'optionalAccess', _15 => _15[_chunkBJSN5UVVcjs.a]])}function ye(e,t){for(let[r,n]of Object.entries(t))e[r]=n,_chunkBJSN5UVVcjs.g.call(void 0, n)&&_chunkBJSN5UVVcjs.e.call(void 0, n)===void 0&&n.$name(r)}function vn(e,t,r){let n=[...e.matchAll(/:\s*(?<arg>.*?)\s*[,)]/g)].map(a=>a?a[1]:void 0);r(Object.fromEntries(t.flatMap((a,o)=>{let i=n?n[o]:void 0;return _chunkBJSN5UVVcjs.M.call(void 0, a)&&i!==void 0?[[i,a]]:[]})))}function Re(e,t,r){let n=e.match(/->\s(?<output>[\w\d_]+)\s{/),a=n?_optionalChain([n, 'access', _16 => _16[1], 'optionalAccess', _17 => _17.trim, 'call', _18 => _18()]):void 0;_chunkBJSN5UVVcjs.M.call(void 0, t)&&a&&!/\s/g.test(a)&&r({[a]:t})}function Ia(e){return new RegExp(`(?<![\\w\\$_.])${e.replaceAll(".","\\.").replaceAll("$","\\$")}(?![\\w\\$_])`,"g")}function Te(e,t,r){return Object.entries(t).reduce((n,[a,o])=>ct(o)||_chunkBJSN5UVVcjs.W.call(void 0, o)?n.replaceAll(Ia(a),e.resolve(o)):o!==null&&typeof o=="object"?(_nullishCoalesce([...r.matchAll(new RegExp(`${a.replaceAll(".","\\.").replaceAll("$","\\$")}\\.(?<prop>.*?)(?![\\w\\$_])`,"g"))].map(s=>s[1]), () => ([]))).reduce((s,l)=>l&&l in o?Te(e,{[`${a}.${l}`]:o[l]},s):s,n):n,r)}function Dn(e){return new lr(e)}var lr= (_class =class{constructor(t){;_class.prototype.__init.call(this);this.declaration=t}__init() {this.externalsToApply=[]}$uses(t){return this.externalsToApply.push(t),this}"~resolve"(t){let r={};for(let a of this.externalsToApply)ye(r,a);let n=Te(t,r,this.declaration);return t.addDeclaration(n),""}toString(){return`declare: ${this.declaration}`}}, _class);function Fn(e,t,r){return _chunkBJSN5UVVcjs.i.call(void 0, e,{ast:t,externals:r}),e}function In(e){return()=>{throw new Error(`The function "${_nullishCoalesce(e, () => ("<unnamed>"))}" is invokable only on the GPU. If you want to use it on the CPU, mark it with the "kernel & js" directive.`)}}var _tinyest = require('tinyest'); var ro = _interopRequireWildcard(_tinyest);function Pn(e){let{strippedCode:t,argRange:r}=Ua(e),n=new gt(t);n.consume("(");let a=[];for(;!n.isAt(")");){let i=[];for(;n.isAt("@");)n.parseUntil(Un,An),n.consume(")"),i.push(n.lastParsed);n.parseUntil(Pa);let s=n.lastParsed,l;n.isAt(":")&&(n.consume(":"),n.parseUntil(Ba,Ca),l=n.lastParsed),a.push({identifier:s,attributes:i,type:l}),n.isAt(",")&&n.consume(",")}n.consume(")");let o;if(n.isAt("->")){n.consume("->");let i=[];for(;n.isAt("@");)n.parseUntil(Un,An),n.consume(")"),i.push(n.lastParsed);o={type:n.str.slice(n.pos),attributes:i}}return{args:a,ret:o,range:{begin:r[0],end:r[1]}}}function Ua(e){let t=new gt(e),r="",n;for(;!t.isFinished();){if(t.isAt(Aa)){t.advanceBy(1);continue}if(t.isAt("//")){t.consume("//"),t.parseUntil(Bn),t.advanceBy(1);continue}if(t.isAt("/*")){t.parseUntil(Ra,Va),t.consume("*/");continue}if(t.isAt("{"))return{strippedCode:r,argRange:[n,t.pos]};t.isAt("(")&&n===void 0&&(n=t.pos),n!==void 0&&(r+=t.str[t.pos]),t.advanceBy(1)}throw new Error("Invalid wgsl code!")}var gt=class{constructor(t){this.str=t;this.#e=0}#t;#e;get pos(){return this.#e}get lastParsed(){if(this.#t===void 0)throw new Error("Parse was not called yet!");return this.str.slice(this.#t,this.pos)}isFinished(){return this.#e>=this.str.length}isAt(t){if(typeof t=="string"){for(let r=0;r<t.length;r++)if(this.str[this.#e+r]!==t[r])return!1;return!0}for(let r of t)if(this.isAt(r))return!0;return!1}parseUntil(t,r){this.#t=this.#e;let n=0;for(;this.#e<this.str.length;){if(r&&this.isAt(r[0])&&(n+=1),r&&this.isAt(r[1])&&(n-=1),n===0&&this.isAt(t))return this.#e;this.#e+=1}throw new Error("Reached the end of the string without finding a match!")}advanceBy(t){this.#e+=t}consume(t){if(!this.isAt(t))throw new Error(`Expected '${t}' at position ${this.#e}, but found '${this.str.slice(this.#e,this.#e+t.length)}'`);this.advanceBy(t.length)}},Bn=new Set([`
`,"\v","\f","\r","\x85","\u2028","\u2029"]),Aa=new Set([...Bn," "," ","\u200E","\u200F"]),Un=new Set([")"]),Pa=new Set([":",",",")"]),Ba=new Set([",",")"]),Ra=new Set(["*/"]),An=["(",")"],Ca=["<",">"],Va=["/*","*/"];function ne(e,t){let r=[];typeof t=="string"&&(e.isEntry?(_chunkBJSN5UVVcjs.M.call(void 0, e.argTypes[0])&&r.push({In:e.argTypes[0]}),_chunkBJSN5UVVcjs.M.call(void 0, e.returnType)&&r.push({Out:e.returnType})):(vn(t,e.argTypes,o=>r.push(o)),Re(t,e.returnType,o=>r.push(o))));let n={applyExternals(o){r.push(o)},resolve(o,i=""){let s={};for(let u of r)ye(s,u);let l=o.names.makeUnique(_chunkBJSN5UVVcjs.e.call(void 0, this));if(typeof t=="string"){let u=Te(o,s,t),c="",m="";if(e.isEntry){let g=_chunkBJSN5UVVcjs.M.call(void 0, e.argTypes[0])?`(in: ${o.resolve(e.argTypes[0])})`:"()",T=_chunkBJSN5UVVcjs.K.call(void 0, e.returnType)?_chunkBZVU4Q6Acjs.ba.call(void 0, e.returnType):"",x=e.returnType!==_chunkBJSN5UVVcjs.A?_chunkBJSN5UVVcjs.M.call(void 0, e.returnType)?`-> ${o.resolve(e.returnType)}`:`-> ${T!==""?T:"@location(0)"} ${o.resolve(e.returnType)}`:"";c=`${g} ${x} `,m=u}else{let g=Pn(u);if(g.args.length!==e.argTypes.length)throw new Error(`WGSL implementation has ${g.args.length} arguments, while the shell has ${e.argTypes.length} arguments.`);let T=g.args.map((y,F)=>`${y.identifier}: ${Cn(o,`parameter ${y.identifier}`,y.type,e.argTypes[F])}`).join(", "),x=e.returnType===_chunkBJSN5UVVcjs.A?"":`-> ${Cn(o,"return type",_optionalChain([g, 'access', _19 => _19.ret, 'optionalAccess', _20 => _20.type]),e.returnType)}`;c=`(${T}) ${x}`,m=u.slice(g.range.end)}o.addDeclaration(`${i}fn ${l}${c}${m}`)}else{let u=_chunkBJSN5UVVcjs.h.call(void 0, t);if(_optionalChain([u, 'optionalAccess', _21 => _21.externals])){let x=Object.fromEntries(Object.entries(u.externals).filter(([y])=>!(y in s)));ye(s,x)}let c=_nullishCoalesce(_optionalChain([u, 'optionalAccess', _22 => _22.ast]), () => (o.transpileFn(String(t)))),m=c.externalNames.filter(x=>!(x in s));if(m.length>0)throw new (0, _chunkBJSN5UVVcjs.n)(_chunkBJSN5UVVcjs.e.call(void 0, this),m);let{head:g,body:T}=o.fnToWgsl({args:e.argTypes.map((x,y)=>_chunkBJSN5UVVcjs.da.call(void 0, _optionalChain([c, 'access', _23 => _23.params, 'access', _24 => _24[y], 'optionalAccess', _25 => _25.type])===_tinyest.FuncParameterType.identifier?c.params[y].name:`_arg_${y}`,x)),argAliases:Object.fromEntries(c.params.flatMap((x,y)=>x.type===_tinyest.FuncParameterType.destructuredObject?x.props.map(({name:F,alias:U})=>[U,_chunkBJSN5UVVcjs.da.call(void 0, `_arg_${y}.${F}`,e.argTypes[y].propTypes[F])]):[])),returnType:e.returnType,body:c.body,externalMap:s});o.addDeclaration(`${i}fn ${l}${o.resolve(g)}${o.resolve(T)}`)}return l}},a=_chunkBJSN5UVVcjs.e.call(void 0, t);return a!==void 0&&_chunkBJSN5UVVcjs.f.call(void 0, n,a),n}function Cn(e,t,r,n){let a=e.resolve(n).replace(/\s/g,"");if(!r)return a;let o=r.replace(/\s/g,"");if(o!==a)throw new Error(`Type mismatch between TGPU shell and WGSL code string: ${t}, JS type "${a}", WGSL type "${o}".`);return r}function _a(e){let t=0;return Object.fromEntries(Object.entries(e).map(([r,n])=>{if(_chunkBZVU4Q6Acjs.aa.call(void 0, n))return[r,n];let a=_chunkBJSN5UVVcjs.aa.call(void 0, n);return a!==void 0?(t=a+1,[r,n]):[r,_chunkBZVU4Q6Acjs._.call(void 0, t++,n)]}))}function ae(e){return _chunkBJSN5UVVcjs.ba.call(void 0, e)?_chunkBJSN5UVVcjs.V.call(void 0, e)||_chunkBJSN5UVVcjs.aa.call(void 0, e)!==void 0?e:_chunkBZVU4Q6Acjs._.call(void 0, 0,e):_chunkBZVU4Q6Acjs.ca.call(void 0, _a(e))}function oe(e,...t){return $a(e)?Ea(e,...t):e}function $a(e){return Array.isArray(e)&&"raw"in e&&Array.isArray(e.raw)&&e.raw.every(t=>typeof t=="string")}function Ea(e,...t){return e.slice(1).reduce((r,n,a)=>`${r}${t[a]}${n}`,e[0])}function Vn(e){let t={argTypes:e.in&&Object.keys(e.in).length!==0?[ae(e.in)]:[],returnType:_chunkBJSN5UVVcjs.A,workgroupSize:[_nullishCoalesce(e.workgroupSize[0], () => (1)),_nullishCoalesce(e.workgroupSize[1], () => (1)),_nullishCoalesce(e.workgroupSize[2], () => (1))],isEntry:!0},r=(n,...a)=>Ga(t,e.workgroupSize,oe(n,...a));return Object.assign(Object.assign(r,t),{does:r})}function Ga(e,t,r){let n=ne(e,r),a=e.argTypes[0];return{shell:e,$uses(i){return n.applyExternals(i),this},[_chunkBJSN5UVVcjs.d]:n,$name(i){return _chunkBJSN5UVVcjs.f.call(void 0, n,i),_chunkBJSN5UVVcjs.g.call(void 0, a)&&a.$name(`${i}_Input`),this},"~resolve"(i){return n.resolve(i,`@compute @workgroup_size(${t.join(", ")}) `)},toString(){return`computeFn:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, n), () => ("<unnamed>"))}`}}}function _n(e,t){let r={[_chunkBJSN5UVVcjs.a]:!0,argTypes:e,returnType:_nullishCoalesce(t, () => (_chunkBJSN5UVVcjs.A)),isEntry:!1},n=(a,...o)=>La(r,oe(a,...o));return Object.assign(Object.assign(n,r),{does:n})}function mr(e){return!!_optionalChain([e, 'optionalAccess', _26 => _26[_chunkBJSN5UVVcjs.a]])&&_optionalChain([e, 'optionalAccess', _27 => _27.resourceType])==="function"}function ka([e,t]){return`${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, e), () => ("<unnamed>"))}=${t}`}function La(e,t){let r=ne(e,t),n={[_chunkBJSN5UVVcjs.a]:{implementation:t,argTypes:e.argTypes},shell:e,resourceType:"function",$uses(i){return r.applyExternals(i),this},[_chunkBJSN5UVVcjs.d]:r,$name(i){return _chunkBJSN5UVVcjs.f.call(void 0, r,i),this},with(i,s){return $n(o,[[qe(i)?i.slot:i,s]])},"~resolve"(i){if(typeof t=="string")return r.resolve(i);let s=i;if(s.callStack===void 0)throw new Error("Cannot resolve a TGSL function outside of a generation context");try{return s.callStack.push(e.returnType),r.resolve(i)}finally{s.callStack.pop()}}},a=_chunkBJSN5UVVcjs.ga.call(void 0, (...i)=>{if(typeof t=="string")throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");return t(...i)},(...i)=>_chunkBJSN5UVVcjs.da.call(void 0, new yt(o,i.map(s=>s.value)),_nullishCoalesce(e.returnType, () => (_chunkBJSN5UVVcjs.ca))),"tgpuFnCall",e.argTypes);a[_chunkBJSN5UVVcjs.a].implementation=t;let o=Object.assign(a,n);return Object.defineProperty(o,"toString",{value(){return`fn:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, r), () => ("<unnamed>"))}`}}),o}function $n(e,t){let r={[_chunkBJSN5UVVcjs.a]:{implementation:e[_chunkBJSN5UVVcjs.a].implementation,argTypes:e[_chunkBJSN5UVVcjs.a].argTypes},resourceType:"function",shell:e.shell,"~providing":{inner:e,pairs:t},$uses(o){return e.$uses(o),this},[_chunkBJSN5UVVcjs.d]:e,$name(o){return e.$name(o),this},with(o,i){return $n(a,[...t,[qe(o)?o.slot:o,i]])}},n=_chunkBJSN5UVVcjs.ga.call(void 0, (...o)=>e(...o),(...o)=>_chunkBJSN5UVVcjs.da.call(void 0, new yt(a,o.map(i=>i.value)),_nullishCoalesce(e.shell.returnType, () => (_chunkBJSN5UVVcjs.ca))),"tgpuFnCall",e.shell.argTypes),a=Object.assign(n,r);return Object.defineProperty(a,"toString",{value(){return`fn:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, e), () => ("<unnamed>"))}[${t.map(ka).join(", ")}]`}}),a[_chunkBJSN5UVVcjs.a].implementation=e[_chunkBJSN5UVVcjs.a].implementation,a}var yt=class{constructor(t,r){this._fn=t;this._params=r;this[_chunkBJSN5UVVcjs.d]=t}"~resolve"(t){return t.resolve(`${t.resolve(this._fn)}(${this._params.map(r=>t.resolve(r)).join(", ")})`)}toString(){return`call:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, this), () => ("<unnamed>"))}`}};function En(e){let t={argTypes:e.in&&Object.keys(e.in).length!==0?[ae(e.in)]:[],targets:e.out,returnType:ae(e.out),isEntry:!0},r=(n,...a)=>Oa(t,oe(n,...a));return Object.assign(Object.assign(r,t),{does:r})}function Oa(e,t){let r=ne(e,t),n=e.returnType,a=e.argTypes[0];return typeof t=="string"&&Re(t,n,i=>r.applyExternals(i)),{shell:e,outputType:n,$uses(i){return r.applyExternals(i),this},[_chunkBJSN5UVVcjs.d]:r,$name(i){return _chunkBJSN5UVVcjs.f.call(void 0, r,i),_chunkBJSN5UVVcjs.g.call(void 0, n)&&n.$name(`${i}_Output`),_chunkBJSN5UVVcjs.g.call(void 0, a)&&a.$name(`${i}_Input`),this},"~resolve"(i){if(typeof t=="string")return r.resolve(i,"@fragment ");let s=i;if(s.callStack===void 0)throw new Error("Cannot resolve a TGSL function outside of a generation context");try{return s.callStack.push(n),r.resolve(i,"@fragment ")}finally{s.callStack.pop()}},toString(){return`fragmentFn:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, r), () => ("<unnamed>"))}`}}}function Gn(e){if(Object.keys(e.out).length===0)throw new Error("A vertexFn output cannot be empty since it must include the 'position' builtin.");let t={attributes:[_nullishCoalesce(e.in, () => ({}))],returnType:ae(e.out),argTypes:e.in&&Object.keys(e.in).length!==0?[ae(e.in)]:[],isEntry:!0},r=(n,...a)=>Wa(t,oe(n,...a));return Object.assign(Object.assign(r,t),{does:r})}function Wa(e,t){let r=ne(e,t),n=e.returnType,a=e.argTypes[0];return typeof t=="string"&&Re(t,n,i=>r.applyExternals(i)),{shell:e,outputType:n,inputType:a,$uses(i){return r.applyExternals(i),this},[_chunkBJSN5UVVcjs.d]:r,$name(i){return _chunkBJSN5UVVcjs.f.call(void 0, r,i),_chunkBJSN5UVVcjs.g.call(void 0, n)&&n.$name(`${i}_Output`),_chunkBJSN5UVVcjs.g.call(void 0, a)&&a.$name(`${i}_Input`),this},"~resolve"(i){if(typeof t=="string")return r.resolve(i,"@vertex ");let s=i;if(s.callStack===void 0)throw new Error("Cannot resolve a TGSL function outside of a generation context");try{return s.callStack.push(n),r.resolve(i,"@vertex ")}finally{s.callStack.pop()}},toString(){return`vertexFn:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, r), () => ("<unnamed>"))}`}}}var ie= (_class2 =class{constructor() { _class2.prototype.__init2.call(this); }__init2() {this.lastUniqueId=0}makeUnique(t){let r;return t?(r=t.replaceAll(/\s/g,"_"),r=r.replaceAll(/[^\w\d]/g,"")):r="item",`${r}_${this.lastUniqueId++}`}}, _class2),se= exports.StrictNameRegistry = (_class3 =class{constructor() { _class3.prototype.__init3.call(this); }__init3() {this._usedNames=new Set}makeUnique(t){if(t===void 0)throw new Error("Unnamed item found when using a strict name registry");let r=0,n=t;for(;this._usedNames.has(n);)r++,n=`${t}_${r}`;return this._usedNames.add(n),n}}, _class3);function Qe(e){return typeof _optionalChain([e, 'optionalAccess', _28 => _28.format])=="string"}function kn(e,t){let r=[];if(_chunkBJSN5UVVcjs.ba.call(void 0, e)){if(!Qe(t))throw new Error("Shader expected a single attribute, not a record of attributes to be passed in.");return r.push(t._layout),{usedVertexLayouts:r,bufferDefinitions:[{arrayStride:t._layout.stride,stepMode:t._layout.stepMode,attributes:[{format:t.format,offset:t.offset,shaderLocation:_nullishCoalesce(_chunkBJSN5UVVcjs.aa.call(void 0, e), () => (0))}]}]}}let n=[],a=new WeakMap,o=0;for(let[i,s]of Object.entries(e)){if(_chunkBZVU4Q6Acjs.aa.call(void 0, s))continue;let l=t[i];if(!l)throw new Error(`An attribute by the name of '${i}' was not provided to the shader.`);let u=l._layout,c=a.get(u);c||(r.push(u),c=[],n.push({arrayStride:u.stride,stepMode:u.stepMode,attributes:c}),a.set(u,c)),o=_nullishCoalesce(_chunkBJSN5UVVcjs.aa.call(void 0, s), () => (o)),c.push({format:l.format,offset:l.offset,shaderLocation:o++})}return{usedVertexLayouts:r,bufferDefinitions:n}}var Ma=["bool","f32","f16","i32","u32","vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","vec2<bool>","vec3<bool>","vec4<bool>","mat2x2f","mat3x3f","mat4x4f"];function Na(e){return Ma.includes(e.type)}function dr(e,[t,r]){return` ${_chunkBZVU4Q6Acjs.ba.call(void 0, r)}${t}: ${e.resolve(r)},
`}function ja(e,t){let r=e.names.makeUnique(_chunkBJSN5UVVcjs.e.call(void 0, t));return e.addDeclaration(`
struct ${r} {
${Object.entries(t.propTypes).map(n=>dr(e,n)).join("")}}
`),r}function za(e,t){let r=e.names.makeUnique(_chunkBJSN5UVVcjs.e.call(void 0, t));return e.addDeclaration(`
struct ${r} {
${Object.entries(t.propTypes).map(n=>Qe(n[1])?dr(e,[n[0],_chunkBZVU4Q6Acjs.b[n[1].format]]):dr(e,n)).join("")}
}
`),r}function qa(e,t){let r=e.resolve(t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function Qa(e,t){let r=e.resolve(Qe(t.elementType)?_chunkBZVU4Q6Acjs.b[t.elementType.format]:t.elementType);return t.elementCount===0?`array<${r}>`:`array<${r}, ${t.elementCount}>`}function fr(e,t){if(_chunkBJSN5UVVcjs.W.call(void 0, t))return t.type==="unstruct"?za(e,t):t.type==="disarray"?Qa(e,t):t.type==="loose-decorated"?e.resolve(Qe(t.inner)?_chunkBZVU4Q6Acjs.b[t.inner.format]:t.inner):e.resolve(_chunkBZVU4Q6Acjs.b[t.type]);if(Na(t))return t.type;if(t.type==="struct")return ja(e,t);if(t.type==="array")return qa(e,t);if(t.type==="atomic")return`atomic<${fr(e,t.inner)}>`;if(t.type==="decorated")return e.resolve(t.inner);if(t.type==="ptr")return t.addressSpace==="storage"?`ptr<storage, ${e.resolve(t.inner)}, ${t.access==="read-write"?"read_write":t.access}>`:`ptr<${t.addressSpace}, ${e.resolve(t.inner)}>`;if(t.type==="abstractInt"||t.type==="abstractFloat")throw new Error("Abstract types have no concrete representation in WGSL");if(t.type==="void")throw new Error("Void has no representation in WGSL");dt(t,"resolveData")}var _typedbinary = require('typed-binary');function Ka(e,t){let r="size"in e?e.size:e.currentByteOffset,n=t-1,a=r&n;"skipBytes"in e?e.skipBytes(t-a&n):e.add(t-a&n)}var B=Ka;var Ln=new WeakMap;function Tt(e){let t=Ln.get(e);if(t)return t;let r=new _typedbinary.Measurer,n={},a;for(let o in e.propTypes){let i=e.propTypes[o];if(i===void 0)throw new Error(`Property ${o} is undefined in struct`);let s=r.size;B(r,_chunkBJSN5UVVcjs.Y.call(void 0, e)?_chunkBZVU4Q6Acjs.T.call(void 0, i):_chunkBZVU4Q6Acjs.S.call(void 0, i)),a&&(a.padding=r.size-s);let l=_chunkBZVU4Q6Acjs.V.call(void 0, i);n[o]={offset:r.size,size:l},a=n[o],r.add(l)}return a&&(a.padding=_chunkBZVU4Q6Acjs.a.call(void 0, _chunkBZVU4Q6Acjs.V.call(void 0, e),_chunkBZVU4Q6Acjs.S.call(void 0, e))-r.size),Ln.set(e,n),n}var ht=(()=>{try{return new Function("return true"),!0}catch (e2){return!1}})(),cr=new WeakMap,gr={u32:"u32",vec2u:"u32",vec3u:"u32",vec4u:"u32",i32:"i32",vec2i:"i32",vec3i:"i32",vec4i:"i32",f32:"f32",vec2f:"f32",vec3f:"f32",vec4f:"f32",vec2h:"f32",vec3h:"f32",vec4h:"f32",mat2x2f:"f32",mat3x3f:"f32",mat4x4f:"f32"},yr={u32:"setUint32",i32:"setInt32",f32:"setFloat32"};function xt(e,t,r){if(_chunkBJSN5UVVcjs.O.call(void 0, e)||_chunkBJSN5UVVcjs.U.call(void 0, e))return xt(e.inner,t,r);if(_chunkBJSN5UVVcjs.M.call(void 0, e)||_chunkBJSN5UVVcjs.Y.call(void 0, e)){let a=Tt(e),o=Object.entries(a).sort((s,l)=>s[1].offset-l[1].offset),i="";for(let[s,l]of o){let u=e.propTypes[s];u&&(i+=xt(u,`(${t} + ${l.offset})`,`${r}.${s}`))}return i}if(_chunkBJSN5UVVcjs.L.call(void 0, e)||_chunkBJSN5UVVcjs.X.call(void 0, e)){let a=e,o=_chunkBZVU4Q6Acjs.a.call(void 0, _chunkBZVU4Q6Acjs.V.call(void 0, a.elementType),_chunkBZVU4Q6Acjs.S.call(void 0, a.elementType)),i="";return i+=`for (let i = 0; i < ${a.elementCount}; i++) {
`,i+=xt(a.elementType,`(${t} + i * ${o})`,`${r}[i]`),i+=`}
`,i}if(_chunkBJSN5UVVcjs.E.call(void 0, e)){let a=gr[e.type],o="",i=yr[a],s=["x","y","z","w"],l=_chunkBJSN5UVVcjs.C.call(void 0, e)?2:_chunkBJSN5UVVcjs.D.call(void 0, e)?3:4;for(let u=0;u<l;u++)o+=`output.${i}((${t} + ${u*4}), ${r}.${s[u]}, littleEndian);
`;return o}if(_chunkBJSN5UVVcjs.I.call(void 0, e)){let a=gr[e.type],o=yr[a],i=_chunkBJSN5UVVcjs.G.call(void 0, e)?2:_chunkBJSN5UVVcjs.H.call(void 0, e)?3:4,s=i*i,l=_chunkBZVU4Q6Acjs.a.call(void 0, i*4,8),u="";for(let c=0;c<s;c++){let m=Math.floor(c/i),g=c%i,T=m*l+g*4;u+=`output.${o}((${t} + ${T}), ${r}.columns[${m}].${["x","y","z","w"][g]}, littleEndian);
`}return u}let n=gr[e.type];return`output.${yr[n]}(${t}, ${r}, littleEndian);
`}function wt(e){if(cr.has(e))return cr.get(e);let t=xt(e,"offset","value"),r=new Function("output","offset","value","littleEndian=true",t);return cr.set(e,r),r}var Ce={bool(){throw new Error("Booleans are not host-shareable")},f32(e,t,r){e.writeFloat32(r)},f16(e,t,r){e.writeFloat16(r)},i32(e,t,r){e.writeInt32(r)},u32(e,t,r){e.writeUint32(r)},vec2f(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y)},vec2h(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y)},vec2i(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y)},vec2u(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y)},"vec2<bool>"(){throw new Error("Booleans are not host-shareable")},vec3f(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z)},vec3h(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z)},vec3i(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z)},vec3u(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z)},"vec3<bool>"(){throw new Error("Booleans are not host-shareable")},vec4f(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z),e.writeFloat32(r.w)},vec4h(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z),e.writeFloat16(r.w)},vec4i(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z),e.writeInt32(r.w)},vec4u(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z),e.writeUint32(r.w)},"vec4<bool>"(){throw new Error("Booleans are not host-shareable")},mat2x2f(e,t,r){for(let n=0;n<r.length;++n)e.writeFloat32(r[n])},mat3x3f(e,t,r){for(let n=0;n<r.length;++n)e.writeFloat32(r[n])},mat4x4f(e,t,r){for(let n=0;n<r.length;++n)e.writeFloat32(r[n])},struct(e,t,r){let n=_chunkBZVU4Q6Acjs.S.call(void 0, t);B(e,n);for(let[a,o]of Object.entries(t.propTypes))B(e,_chunkBZVU4Q6Acjs.S.call(void 0, o)),ue(e,o,r[a]);B(e,n)},array(e,t,r){if(t.elementCount===0)throw new Error("Cannot write using a runtime-sized schema.");let n=_chunkBZVU4Q6Acjs.S.call(void 0, t);B(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)B(e,n),ue(e,t.elementType,r[o]);e.seekTo(a+_chunkBZVU4Q6Acjs.V.call(void 0, t))},ptr(){throw new Error("Pointers are not host-shareable")},atomic(e,t,r){_optionalChain([Ce, 'access', _29 => _29[t.inner.type], 'optionalCall', _30 => _30(e,t,r)])},decorated(e,t,r){let n=_chunkBZVU4Q6Acjs.T.call(void 0, t);B(e,n);let a=e.currentByteOffset;_optionalChain([Ce, 'access', _31 => _31[_optionalChain([t, 'access', _32 => _32.inner, 'optionalAccess', _33 => _33.type])], 'optionalCall', _34 => _34(e,t.inner,r)]),e.seekTo(a+_chunkBZVU4Q6Acjs.V.call(void 0, t))},uint8(e,t,r){e.writeUint8(r)},uint8x2(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y)},uint8x4(e,t,r){e.writeUint8(r.x),e.writeUint8(r.y),e.writeUint8(r.z),e.writeUint8(r.w)},sint8(e,t,r){e.writeInt8(r)},sint8x2(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y)},sint8x4(e,t,r){e.writeInt8(r.x),e.writeInt8(r.y),e.writeInt8(r.z),e.writeInt8(r.w)},unorm8(e,t,r){e.writeUint8(r*255)},unorm8x2(e,t,r){e.writeUint8(r.x*255),e.writeUint8(r.y*255)},unorm8x4(e,t,r){e.writeUint8(r.x*255),e.writeUint8(r.y*255),e.writeUint8(r.z*255),e.writeUint8(r.w*255)},snorm8(e,t,r){e.writeUint8(r*127+128)},snorm8x2(e,t,r){e.writeUint8(r.x*127+128),e.writeUint8(r.y*127+128)},snorm8x4(e,t,r){e.writeUint8(r.x*127+128),e.writeUint8(r.y*127+128),e.writeUint8(r.z*127+128),e.writeUint8(r.w*127+128)},uint16(e,t,r){e.writeUint16(r)},uint16x2(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y)},uint16x4(e,t,r){e.writeUint16(r.x),e.writeUint16(r.y),e.writeUint16(r.z),e.writeUint16(r.w)},sint16(e,t,r){e.writeInt16(r)},sint16x2(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y)},sint16x4(e,t,r){e.writeInt16(r.x),e.writeInt16(r.y),e.writeInt16(r.z),e.writeInt16(r.w)},unorm16(e,t,r){e.writeUint16(r*65535)},unorm16x2(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535)},unorm16x4(e,t,r){e.writeUint16(r.x*65535),e.writeUint16(r.y*65535),e.writeUint16(r.z*65535),e.writeUint16(r.w*65535)},snorm16(e,t,r){e.writeUint16(r*32767+32768)},snorm16x2(e,t,r){e.writeUint16(r.x*32767+32768),e.writeUint16(r.y*32767+32768)},snorm16x4(e,t,r){e.writeUint16(r.x*32767+32768),e.writeUint16(r.y*32767+32768),e.writeUint16(r.z*32767+32768),e.writeUint16(r.w*32767+32768)},float16(e,t,r){e.writeFloat16(r)},float16x2(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y)},float16x4(e,t,r){e.writeFloat16(r.x),e.writeFloat16(r.y),e.writeFloat16(r.z),e.writeFloat16(r.w)},float32(e,t,r){e.writeFloat32(r)},float32x2(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y)},float32x3(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z)},float32x4(e,t,r){e.writeFloat32(r.x),e.writeFloat32(r.y),e.writeFloat32(r.z),e.writeFloat32(r.w)},uint32(e,t,r){e.writeUint32(r)},uint32x2(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y)},uint32x3(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z)},uint32x4(e,t,r){e.writeUint32(r.x),e.writeUint32(r.y),e.writeUint32(r.z),e.writeUint32(r.w)},sint32(e,t,r){e.writeInt32(r)},sint32x2(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y)},sint32x3(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z)},sint32x4(e,t,r){e.writeInt32(r.x),e.writeInt32(r.y),e.writeInt32(r.z),e.writeInt32(r.w)},"unorm10-10-10-2"(e,t,r){let n=0;n|=(r.x*1023&1023)<<22,n|=(r.x*1023&1023)<<12,n|=(r.y*1023&1023)<<2,n|=r.z*3&3,e.writeUint32(n)},"unorm8x4-bgra"(e,t,r){e.writeUint8(r.z*255),e.writeUint8(r.y*255),e.writeUint8(r.x*255),e.writeUint8(r.w*255)},disarray(e,t,r){let n=_chunkBZVU4Q6Acjs.S.call(void 0, t);B(e,n);let a=e.currentByteOffset;for(let o=0;o<Math.min(t.elementCount,r.length);o++)B(e,n),_optionalChain([Ce, 'access', _35 => _35[_optionalChain([t, 'access', _36 => _36.elementType, 'optionalAccess', _37 => _37.type])], 'optionalCall', _38 => _38(e,t.elementType,r[o])]);e.seekTo(a+_chunkBZVU4Q6Acjs.V.call(void 0, t))},unstruct(e,t,r){for(let[n,a]of Object.entries(t.propTypes))_optionalChain([Ce, 'access', _39 => _39[a.type], 'optionalCall', _40 => _40(e,a,r[n])])},"loose-decorated"(e,t,r){let n=_chunkBZVU4Q6Acjs.T.call(void 0, t);B(e,n);let a=e.currentByteOffset,o=Ce[_optionalChain([t, 'access', _41 => _41.inner, 'optionalAccess', _42 => _42.type])];return _optionalChain([o, 'optionalCall', _43 => _43(e,t.inner,r)]),e.seekTo(a+_chunkBZVU4Q6Acjs.V.call(void 0, t)),r}};function ue(e,t,r){let n=Ce[t.type];if(!n)throw new Error(`Cannot write data of type '${t.type}'.`);n(e,t,r)}var xe={bool(){throw new Error("Booleans are not host-shareable")},f32(e){return e.readFloat32()},f16(e){return e.readFloat16()},i32(e){return e.readInt32()},u32(e){return e.readUint32()},vec2f(e){return _chunkBJSN5UVVcjs.oa.call(void 0, e.readFloat32(),e.readFloat32())},vec3f(e){return _chunkBJSN5UVVcjs.ta.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32())},vec4f(e){return _chunkBJSN5UVVcjs.ya.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},vec2h(e){return _chunkBJSN5UVVcjs.pa.call(void 0, e.readFloat16(),e.readFloat16())},vec3h(e){return _chunkBJSN5UVVcjs.ua.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16())},vec4h(e){return _chunkBJSN5UVVcjs.za.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16())},vec2i(e){return _chunkBJSN5UVVcjs.qa.call(void 0, e.readInt32(),e.readInt32())},vec3i(e){return _chunkBJSN5UVVcjs.va.call(void 0, e.readInt32(),e.readInt32(),e.readInt32())},vec4i(e){return _chunkBJSN5UVVcjs.Aa.call(void 0, e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32())},vec2u(e){return _chunkBJSN5UVVcjs.ra.call(void 0, e.readUint32(),e.readUint32())},vec3u(e){return _chunkBJSN5UVVcjs.wa.call(void 0, e.readUint32(),e.readUint32(),e.readUint32())},vec4u(e){return _chunkBJSN5UVVcjs.Ba.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32())},"vec2<bool>"(){throw new Error("Booleans are not host-shareable")},"vec3<bool>"(){throw new Error("Booleans are not host-shareable")},"vec4<bool>"(){throw new Error("Booleans are not host-shareable")},mat2x2f(e){return _chunkBJSN5UVVcjs.Ma.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},mat3x3f(e){let t=()=>{let r=e.readFloat32();return e.readFloat32(),r};return _chunkBJSN5UVVcjs.Na.call(void 0, e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t(),e.readFloat32(),e.readFloat32(),t())},mat4x4f(e){return _chunkBJSN5UVVcjs.Oa.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32())},struct(e,t){let r=_chunkBZVU4Q6Acjs.S.call(void 0, t);B(e,r);let n={};for(let[a,o]of Object.entries(t.propTypes))B(e,_chunkBZVU4Q6Acjs.S.call(void 0, o)),n[a]=N(e,o);return B(e,r),n},array(e,t){if(t.elementCount===0)throw new Error("Cannot read using a runtime-sized schema.");let r=_chunkBZVU4Q6Acjs.S.call(void 0, t),n=[];for(let a=0;a<t.elementCount;a++){B(e,r);let o=t.elementType,i=N(e,o);n.push(i)}return B(e,r),n},ptr(){throw new Error("Pointers are not host-shareable")},atomic(e,t){return N(e,t.inner)},decorated(e,t){let r=_chunkBZVU4Q6Acjs.T.call(void 0, t);B(e,r);let n=e.currentByteOffset,a=N(e,t.inner);return e.seekTo(n+_chunkBZVU4Q6Acjs.V.call(void 0, t)),a},uint8:e=>e.readUint8(),uint8x2:e=>_chunkBJSN5UVVcjs.ra.call(void 0, e.readUint8(),e.readUint8()),uint8x4:e=>_chunkBJSN5UVVcjs.Ba.call(void 0, e.readUint8(),e.readUint8(),e.readUint8(),e.readUint8()),sint8:e=>e.readInt8(),sint8x2:e=>_chunkBJSN5UVVcjs.qa.call(void 0, e.readInt8(),e.readInt8()),sint8x4:e=>_chunkBJSN5UVVcjs.Aa.call(void 0, e.readInt8(),e.readInt8(),e.readInt8(),e.readInt8()),unorm8:e=>e.readUint8()/255,unorm8x2:e=>_chunkBJSN5UVVcjs.oa.call(void 0, e.readUint8()/255,e.readUint8()/255),unorm8x4:e=>_chunkBJSN5UVVcjs.ya.call(void 0, e.readUint8()/255,e.readUint8()/255,e.readUint8()/255,e.readUint8()/255),snorm8:e=>(e.readUint8()-128)/127,snorm8x2:e=>_chunkBJSN5UVVcjs.oa.call(void 0, (e.readUint8()-128)/127,(e.readUint8()-128)/127),snorm8x4:e=>_chunkBJSN5UVVcjs.ya.call(void 0, (e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127,(e.readUint8()-128)/127),uint16:e=>e.readUint16(),uint16x2:e=>_chunkBJSN5UVVcjs.ra.call(void 0, e.readUint16(),e.readUint16()),uint16x4:e=>_chunkBJSN5UVVcjs.Ba.call(void 0, e.readUint16(),e.readUint16(),e.readUint16(),e.readUint16()),sint16:e=>e.readInt16(),sint16x2:e=>_chunkBJSN5UVVcjs.qa.call(void 0, e.readInt16(),e.readInt16()),sint16x4:e=>_chunkBJSN5UVVcjs.Aa.call(void 0, e.readInt16(),e.readInt16(),e.readInt16(),e.readInt16()),unorm16:e=>e.readUint16()/65535,unorm16x2:e=>_chunkBJSN5UVVcjs.oa.call(void 0, e.readUint16()/65535,e.readUint16()/65535),unorm16x4:e=>_chunkBJSN5UVVcjs.ya.call(void 0, e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535,e.readUint16()/65535),snorm16:e=>(e.readUint16()-32768)/32767,snorm16x2:e=>_chunkBJSN5UVVcjs.oa.call(void 0, xe.snorm16(e),xe.snorm16(e)),snorm16x4:e=>_chunkBJSN5UVVcjs.ya.call(void 0, xe.snorm16(e),xe.snorm16(e),xe.snorm16(e),xe.snorm16(e)),float16(e){return e.readFloat16()},float16x2:e=>_chunkBJSN5UVVcjs.oa.call(void 0, e.readFloat16(),e.readFloat16()),float16x4:e=>_chunkBJSN5UVVcjs.ya.call(void 0, e.readFloat16(),e.readFloat16(),e.readFloat16(),e.readFloat16()),float32:e=>e.readFloat32(),float32x2:e=>_chunkBJSN5UVVcjs.oa.call(void 0, e.readFloat32(),e.readFloat32()),float32x3:e=>_chunkBJSN5UVVcjs.ta.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32()),float32x4:e=>_chunkBJSN5UVVcjs.ya.call(void 0, e.readFloat32(),e.readFloat32(),e.readFloat32(),e.readFloat32()),uint32:e=>e.readUint32(),uint32x2:e=>_chunkBJSN5UVVcjs.ra.call(void 0, e.readUint32(),e.readUint32()),uint32x3:e=>_chunkBJSN5UVVcjs.wa.call(void 0, e.readUint32(),e.readUint32(),e.readUint32()),uint32x4:e=>_chunkBJSN5UVVcjs.Ba.call(void 0, e.readUint32(),e.readUint32(),e.readUint32(),e.readUint32()),sint32:e=>e.readInt32(),sint32x2:e=>_chunkBJSN5UVVcjs.qa.call(void 0, e.readInt32(),e.readInt32()),sint32x3:e=>_chunkBJSN5UVVcjs.va.call(void 0, e.readInt32(),e.readInt32(),e.readInt32()),sint32x4:e=>_chunkBJSN5UVVcjs.Aa.call(void 0, e.readInt32(),e.readInt32(),e.readInt32(),e.readInt32()),"unorm10-10-10-2"(e){let t=e.readUint32(),r=(t>>22)/1023,n=(t>>12&1023)/1023,a=(t>>2&1023)/1023,o=(t&3)/3;return _chunkBJSN5UVVcjs.ya.call(void 0, r,n,a,o)},"unorm8x4-bgra"(e){let t=e.readByte()/255,r=e.readByte()/255,n=e.readByte()/255,a=e.readByte()/255;return _chunkBJSN5UVVcjs.ya.call(void 0, n,r,t,a)},unstruct(e,t){let r={};for(let[n,a]of Object.entries(t.propTypes))r[n]=N(e,a);return r},disarray(e,t){let r=_chunkBZVU4Q6Acjs.S.call(void 0, t),n=[];for(let a=0;a<t.elementCount;a++)B(e,r),n.push(N(e,t.elementType));return B(e,r),n},"loose-decorated"(e,t){B(e,_chunkBZVU4Q6Acjs.T.call(void 0, t));let r=e.currentByteOffset,n=N(e,t.inner);return e.seekTo(r+_chunkBZVU4Q6Acjs.V.call(void 0, t)),n}};function N(e,t){let r=xe[t.type];if(!r)throw new Error(`Cannot read data of type '${t.type}'.`);return r(e,t)}function On(e,t){let r=_chunkBZVU4Q6Acjs.V.call(void 0, e);if(r===0||t===void 0||t===null)return[];let n=new ArrayBuffer(r),a=new (0, _typedbinary.BufferWriter)(n),o=[];function i(u,c,m,g){if(c!=null){if(_chunkBJSN5UVVcjs.M.call(void 0, u)||_chunkBJSN5UVVcjs.Y.call(void 0, u)){let T=Tt(u);for(let[x,y]of Object.entries(T)){let F=u.propTypes[x];if(!F)continue;let U=c[x];U!==void 0&&i(F,U,m+y.offset,_nullishCoalesce(y.padding, () => (g)))}return}if(_chunkBJSN5UVVcjs.L.call(void 0, u)||_chunkBJSN5UVVcjs.X.call(void 0, u)){let T=u,x=_chunkBZVU4Q6Acjs.a.call(void 0, _chunkBZVU4Q6Acjs.V.call(void 0, T.elementType),_chunkBZVU4Q6Acjs.S.call(void 0, T.elementType));if(!Array.isArray(c))throw new Error("Partial value for array must be an array");let y=_nullishCoalesce(c, () => ([]));y.sort((F,U)=>F.idx-U.idx);for(let{idx:F,value:U}of y)i(T.elementType,U,m+F*x,x-_chunkBZVU4Q6Acjs.V.call(void 0, T.elementType))}else{let T=_chunkBZVU4Q6Acjs.V.call(void 0, u);a.seekTo(m),ue(a,u,c),o.push({start:m,end:m+T,padding:g})}}}if(i(e,t,0),o.length===0)return[];let s=[],l=o[0];for(let u=1;u<o.length;u++){let c=o[u];if(!c||!l)throw new Error("Internal error: missing segment");c.start===l.end+(_nullishCoalesce(l.padding, () => (0)))?(l.end=c.end,l.padding=c.padding):(s.push({data:new Uint8Array(n,l.start,l.end-l.start)}),l=c)}if(!l)throw new Error("Internal error: missing segment");return s.push({data:new Uint8Array(n,l.start,l.end-l.start)}),s}function he(e){return!!_optionalChain([e, 'optionalAccess', _44 => _44.usableAsStorage])}var Ke=class e extends Error{constructor(t){super(`Resource '${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, t), () => ("<unnamed>"))}' cannot be bound as 'storage'. Use .$usage('storage') to allow it.`),Object.setPrototypeOf(this,e.prototype)}};function bt(e){return!!e.usableAsUniform}var jn={uniform:"uniform",mutable:"storage, read_write",readonly:"storage, read"},He= (_class4 =class{constructor(t,r){;_class4.prototype.__init4.call(this);this.usage=t;this.buffer=r;this[_chunkBJSN5UVVcjs.a]={dataType:r.dataType},this[_chunkBJSN5UVVcjs.d]=r}__init4() {this.resourceType="buffer-usage"}$name(t){return this.buffer.$name(t),this}"~resolve"(t){let r=t.names.makeUnique(_chunkBJSN5UVVcjs.e.call(void 0, this)),{group:n,binding:a}=t.allocateFixedEntry(this.usage==="uniform"?{uniform:this.buffer.dataType}:{storage:this.buffer.dataType,access:this.usage},this.buffer),o=jn[this.usage];return t.addDeclaration(`@group(${n}) @binding(${a}) var<${o}> ${r}: ${t.resolve(this.buffer.dataType)};`),r}write(t){this.buffer.write(t)}toString(){return`${this.usage}:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, this), () => ("<unnamed>"))}`}[_chunkBJSN5UVVcjs.c](){return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, this), () => ("<unnamed>"))}`,[_chunkBJSN5UVVcjs.b]:this.buffer.dataType},K)}get value(){if(!_chunkBJSN5UVVcjs.v.call(void 0, ))throw new Error("Cannot access buffer's value directly in JS.");return this[_chunkBJSN5UVVcjs.c]()}}, _class4),Je= (_class5 =class{constructor(t,r,n){;_class5.prototype.__init5.call(this);this.usage=t;this.dataType=r;this._membership=n;this[_chunkBJSN5UVVcjs.a]={dataType:r},_chunkBJSN5UVVcjs.f.call(void 0, this,n.key)}__init5() {this.resourceType="buffer-usage"}"~resolve"(t){let r=t.names.makeUnique(_chunkBJSN5UVVcjs.e.call(void 0, this)),n=t.allocateLayoutEntry(this._membership.layout),a=jn[this.usage];return t.addDeclaration(`@group(${n}) @binding(${this._membership.idx}) var<${a}> ${r}: ${t.resolve(this.dataType)};`),r}toString(){return`${this.usage}:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, this), () => ("<unnamed>"))}`}[_chunkBJSN5UVVcjs.c](){return new Proxy({"~resolve":t=>t.resolve(this),toString:()=>`.value:${_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, this), () => ("<unnamed>"))}`,[_chunkBJSN5UVVcjs.b]:this.dataType},K)}get value(){if(!_chunkBJSN5UVVcjs.v.call(void 0, ))throw new Error("Cannot access buffer's value directly in JS.");return this[_chunkBJSN5UVVcjs.c]()}}, _class5),Wn=new WeakMap;function Tr(e){if(!he(e))throw new Error(`Cannot pass ${e} to asMutable, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);let t=Wn.get(e);return t||(t=new He("mutable",e),Wn.set(e,t)),t}var Mn=new WeakMap;function xr(e){if(!he(e))throw new Error(`Cannot pass ${e} to asReadonly, as it is not allowed to be used as storage. To allow it, call .$usage('storage') when creating the buffer.`);let t=Mn.get(e);return t||(t=new He("readonly",e),Mn.set(e,t)),t}var Nn=new WeakMap;function hr(e){if(!bt(e))throw new Error(`Cannot pass ${e} to asUniform, as it is not allowed to be used as a uniform. To allow it, call .$usage('uniform') when creating the buffer.`);let t=Nn.get(e);return t||(t=new He("uniform",e),Nn.set(e,t)),t}var Za={uniform:hr,mutable:Tr,readonly:xr};function qn(e,t,r){return _chunkBJSN5UVVcjs.K.call(void 0, t)?new St(e,t,r):new St(e,t,r,["storage","uniform"])}function pe(e){return e.resourceType==="buffer"}function eo(e){return!!e.usableAsVertex}var zn=_typedbinary.getSystemEndianness.call(void 0, ),St= (_class6 =class{constructor(t,r,n,a){;_class6.prototype.__init6.call(this);_class6.prototype.__init7.call(this);_class6.prototype.__init8.call(this);_class6.prototype.__init9.call(this);_class6.prototype.__init10.call(this);_class6.prototype.__init11.call(this);_class6.prototype.__init12.call(this);this._group=t;this.dataType=r;this.initialOrBuffer=n;this._disallowedUsages=a;bn(n)?(this._ownBuffer=!1,this._buffer=n):(this._ownBuffer=!0,this.initial=n)}__init6() {this.resourceType="buffer"}__init7() {this.flags=GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC}__init8() {this._buffer=null}__init9() {this._destroyed=!1}__init10() {this.usableAsUniform=!1}__init11() {this.usableAsStorage=!1}__init12() {this.usableAsVertex=!1}get buffer(){let t=this._group.device;if(this._destroyed)throw new Error("This buffer has been destroyed");if(!this._buffer&&(this._buffer=t.createBuffer({size:_chunkBZVU4Q6Acjs.V.call(void 0, this.dataType),usage:this.flags,mappedAtCreation:!!this.initial,label:_nullishCoalesce(_chunkBJSN5UVVcjs.e.call(void 0, this), () => ("<unnamed>"))}),this.initial)){let r=new (0, _typedbinary.BufferWriter)(this._buffer.getMappedRange());ue(r,this.dataType,this.initial),this._buffer.unmap()}return this._buffer}get destroyed(){return this._destroyed}$name(t){return _chunkBJSN5UVVcjs.f.call(void 0, this,t),this._buffer&&(this._buffer.label=t),this}$usage(...t){for(let r of t){if(_optionalChain([this, 'access', _45 => _45._disallowedUsages, 'optionalAccess', _46 => _46.includes, 'call', _47 => _47(r)]))throw new Error(`Buffer of type ${this.dataType.type} cannot be used as ${r}`);this.flags|=r==="uniform"?GPUBuff