typegpu 0.0.0-alpha.3 → 0.0.0-alpha.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,207 @@
1
+ import { ISchema, Parsed } from 'typed-binary';
2
+
3
+ interface Swizzle2<T2> {
4
+ readonly xx: T2;
5
+ readonly xy: T2;
6
+ readonly yx: T2;
7
+ readonly yy: T2;
8
+ }
9
+ interface Swizzle3<T2, T3> extends Swizzle2<T2> {
10
+ }
11
+ interface Swizzle4<T2, T3, T4> extends Swizzle3<T2, T3> {
12
+ }
13
+ interface vec2 {
14
+ x: number;
15
+ y: number;
16
+ length: 2;
17
+ at(idx: 0 | 1): number;
18
+ }
19
+ interface vec3 {
20
+ x: number;
21
+ y: number;
22
+ z: number;
23
+ length: 3;
24
+ at(idx: 0 | 1 | 2): number;
25
+ }
26
+ interface vec4 {
27
+ x: number;
28
+ y: number;
29
+ z: number;
30
+ w: number;
31
+ length: 4;
32
+ at(idx: 0 | 1 | 2 | 3): number;
33
+ }
34
+ type VecKind = 'vec2f' | 'vec2i' | 'vec2u' | 'vec3f' | 'vec3i' | 'vec3u' | 'vec4f' | 'vec4i' | 'vec4u';
35
+ interface vecBase {
36
+ kind: VecKind;
37
+ length: number;
38
+ at(idx: number): number;
39
+ }
40
+ type Vec2f = TgpuData<vec2f> & ((x: number, y: number) => vec2f) & ((xy: number) => vec2f) & (() => vec2f);
41
+ interface vec2f extends vec2, Swizzle2<vec2f> {
42
+ /** use to distinguish between vectors of the same size on the type level */
43
+ kind: 'vec2f';
44
+ }
45
+ declare const vec2f: Vec2f;
46
+ type Vec2i = TgpuData<vec2i> & ((x: number, y: number) => vec2i) & ((xy: number) => vec2i) & (() => vec2i);
47
+ interface vec2i extends vec2, Swizzle2<vec2i> {
48
+ /** use to distinguish between vectors of the same size on the type level */
49
+ kind: 'vec2i';
50
+ }
51
+ declare const vec2i: Vec2i;
52
+ type Vec2u = TgpuData<vec2u> & ((x: number, y: number) => vec2u) & ((xy: number) => vec2u) & (() => vec2u);
53
+ interface vec2u extends vec2, Swizzle2<vec2u> {
54
+ /** use to distinguish between vectors of the same size on the type level */
55
+ kind: 'vec2u';
56
+ }
57
+ declare const vec2u: Vec2u;
58
+ type Vec3f = TgpuData<vec3f> & ((x: number, y: number, z: number) => vec3f) & ((xyz: number) => vec3f) & (() => vec3f);
59
+ interface vec3f extends vec3, Swizzle3<vec2f, vec3f> {
60
+ /** use to distinguish between vectors of the same size on the type level */
61
+ kind: 'vec3f';
62
+ }
63
+ declare const vec3f: Vec3f;
64
+ type Vec3i = TgpuData<vec3i> & ((x: number, y: number, z: number) => vec3i) & ((xyz: number) => vec3i) & (() => vec3i);
65
+ interface vec3i extends vec3, Swizzle3<vec2i, vec3i> {
66
+ /** use to distinguish between vectors of the same size on the type level */
67
+ kind: 'vec3i';
68
+ }
69
+ declare const vec3i: Vec3i;
70
+ type Vec3u = TgpuData<vec3u> & ((x: number, y: number, z: number) => vec3u) & ((xyz: number) => vec3u) & (() => vec3u);
71
+ interface vec3u extends vec3, Swizzle3<vec2u, vec3u> {
72
+ /** use to distinguish between vectors of the same size on the type level */
73
+ kind: 'vec3u';
74
+ }
75
+ declare const vec3u: Vec3u;
76
+ type Vec4f = TgpuData<vec4f> & ((x: number, y: number, z: number, w: number) => vec4f) & ((xyzw: number) => vec4f) & (() => vec4f);
77
+ interface vec4f extends vec4, Swizzle4<vec2f, vec3f, vec4f> {
78
+ /** use to distinguish between vectors of the same size on the type level */
79
+ kind: 'vec4f';
80
+ }
81
+ declare const vec4f: Vec4f;
82
+ type Vec4i = TgpuData<vec4i> & ((x: number, y: number, z: number, w: number) => vec4i) & ((xyzw: number) => vec4i) & (() => vec4i);
83
+ interface vec4i extends vec4, Swizzle4<vec2i, vec3i, vec4i> {
84
+ /** use to distinguish between vectors of the same size on the type level */
85
+ kind: 'vec4i';
86
+ }
87
+ declare const vec4i: Vec4i;
88
+ type Vec4u = TgpuData<vec4u> & ((x: number, y: number, z: number, w: number) => vec4u) & ((xyzw: number) => vec4u) & (() => vec4u);
89
+ interface vec4u extends vec4, Swizzle4<vec2u, vec3u, vec4u> {
90
+ /** use to distinguish between vectors of the same size on the type level */
91
+ kind: 'vec4u';
92
+ }
93
+ declare const vec4u: Vec4u;
94
+
95
+ /**
96
+ * Helpful when creating new Resolvable types. For internal use.
97
+ */
98
+ declare class TgpuIdentifier implements TgpuResolvable, TgpuNamable {
99
+ label?: string | undefined;
100
+ $name(label: string | undefined): this;
101
+ resolve(ctx: ResolutionCtx): string;
102
+ toString(): string;
103
+ }
104
+
105
+ interface Builtin {
106
+ symbol: symbol;
107
+ name: string;
108
+ stage: 'vertex' | 'fragment' | 'compute';
109
+ direction: 'input' | 'output';
110
+ identifier: TgpuIdentifier;
111
+ }
112
+
113
+ type Getter = <T>(plum: TgpuPlum<T>) => T;
114
+ interface TgpuPlum<TValue = unknown> extends TgpuNamable {
115
+ readonly __brand: 'TgpuPlum';
116
+ /**
117
+ * Computes the value of this plum. Circumvents the store
118
+ * memoization, so use with care.
119
+ */
120
+ compute(get: Getter): TValue;
121
+ }
122
+
123
+ type Wgsl = string | number | TgpuResolvable | symbol | boolean;
124
+ /**
125
+ * Passed into each resolvable item. All sibling items share a resolution ctx,
126
+ * and a new resolution ctx is made when going down each level in the tree.
127
+ */
128
+ interface ResolutionCtx {
129
+ /**
130
+ * Slots that were used by items resolved by this context.
131
+ */
132
+ readonly usedSlots: Iterable<TgpuSlot<unknown>>;
133
+ addDeclaration(item: TgpuResolvable): void;
134
+ addBinding(bindable: TgpuBindable, identifier: TgpuIdentifier): void;
135
+ addRenderResource(resource: TgpuRenderResource, identifier: TgpuIdentifier): void;
136
+ addBuiltin(builtin: Builtin): void;
137
+ nameFor(token: TgpuResolvable): string;
138
+ /**
139
+ * Unwraps all layers of slot indirection and returns the concrete value if available.
140
+ * @throws {MissingSlotValueError}
141
+ */
142
+ unwrap<T>(eventual: Eventual<T>): T;
143
+ resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
144
+ }
145
+ interface TgpuResolvable {
146
+ readonly label?: string | undefined;
147
+ resolve(ctx: ResolutionCtx): string;
148
+ }
149
+ /**
150
+ * Can be assigned a name. Not to be confused with
151
+ * being able to HAVE a name.
152
+ */
153
+ interface TgpuNamable {
154
+ $name(label?: string | undefined): this;
155
+ }
156
+ interface TgpuSlot<T> extends TgpuNamable {
157
+ readonly __brand: 'TgpuSlot';
158
+ readonly defaultValue: T | undefined;
159
+ readonly label?: string | undefined;
160
+ /**
161
+ * Used to determine if code generated using either value `a` or `b` in place
162
+ * of the slot will be equivalent. Defaults to `Object.is`.
163
+ */
164
+ areEqual(a: T, b: T): boolean;
165
+ }
166
+ /**
167
+ * Represents a value that is available at resolution time.
168
+ */
169
+ type Eventual<T> = T | TgpuSlot<T>;
170
+ type SlotValuePair<T> = [TgpuSlot<T>, T];
171
+ interface TgpuAllocatable<TData extends AnyTgpuData = AnyTgpuData> {
172
+ /**
173
+ * The data type this allocatable was constructed with.
174
+ * It informs the size and format of data in both JS and
175
+ * binary.
176
+ */
177
+ readonly dataType: TData;
178
+ vertexLayout: Omit<GPUVertexBufferLayout, 'attributes'> | null;
179
+ readonly initial?: Parsed<TData> | TgpuPlum<Parsed<TData>> | undefined;
180
+ readonly flags: GPUBufferUsageFlags;
181
+ }
182
+ interface TgpuBindable<TData extends AnyTgpuData = AnyTgpuData, TUsage extends BufferUsage = BufferUsage> extends TgpuResolvable {
183
+ readonly allocatable: TgpuAllocatable<TData>;
184
+ readonly usage: TUsage;
185
+ }
186
+ type TgpuSamplerType = 'sampler' | 'sampler_comparison';
187
+ type TgpuTypedTextureType = 'texture_1d' | 'texture_2d' | 'texture_2d_array' | 'texture_3d' | 'texture_cube' | 'texture_cube_array' | 'texture_multisampled_2d';
188
+ type TgpuDepthTextureType = 'texture_depth_2d' | 'texture_depth_2d_array' | 'texture_depth_cube' | 'texture_depth_cube_array' | 'texture_depth_multisampled_2d';
189
+ type TgpuStorageTextureType = 'texture_storage_1d' | 'texture_storage_2d' | 'texture_storage_2d_array' | 'texture_storage_3d';
190
+ type TgpuExternalTextureType = 'texture_external';
191
+ type TgpuRenderResourceType = TgpuSamplerType | TgpuTypedTextureType | TgpuDepthTextureType | TgpuStorageTextureType | TgpuExternalTextureType;
192
+ interface TgpuRenderResource extends TgpuResolvable {
193
+ readonly type: TgpuRenderResourceType;
194
+ }
195
+ type BufferUsage = 'uniform' | 'readonly' | 'mutable' | 'vertex';
196
+ interface TgpuData<TInner> extends ISchema<TInner>, TgpuResolvable {
197
+ readonly byteAlignment: number;
198
+ readonly size: number;
199
+ }
200
+ type AnyTgpuData = TgpuData<unknown>;
201
+ type TexelFormat = Vec4u | Vec4i | Vec4f;
202
+ interface TgpuPointer<TScope extends 'function', TInner extends AnyTgpuData> {
203
+ readonly scope: TScope;
204
+ readonly pointsTo: TInner;
205
+ }
206
+
207
+ export { type AnyTgpuData as A, type BufferUsage as B, type Eventual as E, type ResolutionCtx as R, type TgpuBindable as T, type VecKind as V, type Wgsl as W, type TgpuAllocatable as a, type TgpuNamable as b, type TgpuPlum as c, vec3f as d, vec3i as e, vec3u as f, type TgpuData as g, type TexelFormat as h, type TgpuPointer as i, vec2f as j, vec2i as k, vec2u as l, vec4f as m, vec4i as n, vec4u as o, type Vec2f as p, type Vec2i as q, type Vec2u as r, type Vec3f as s, type Vec3i as t, type Vec3u as u, type vecBase as v, type Vec4f as w, type Vec4i as x, type Vec4u as y };
package/.DS_Store DELETED
Binary file
@@ -1,4 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var r=class e extends Error{constructor(o,s){let t=s.map(c=>`- ${c}`);t.length>20&&(t=[...t.slice(0,11),"...",...t.slice(-10)]);super(`Resolution of the following tree failed:
2
- ${t.join(`
3
- `)}`);this.cause=o;this.trace=s;Object.setPrototypeOf(this,e.prototype)}appendToTrace(o){let s=[o,...this.trace];return new e(this.cause,s)}},l= exports.b =class e extends Error{constructor(o){super(`Missing value for '${o}'`);this.slot=o;Object.setPrototypeOf(this,e.prototype)}},n= exports.c =class e extends Error{constructor(){super("Recursive types are not supported in WGSL"),Object.setPrototypeOf(this,e.prototype)}};exports.a = r; exports.b = l; exports.c = n;
4
- //# sourceMappingURL=chunk-G3WAZR24.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors.ts"],"names":["ResolutionError","_ResolutionError","cause","trace","entries","ancestor","newTrace","MissingSlotValueError","_MissingSlotValueError","slot","RecursiveDataTypeError","_RecursiveDataTypeError"],"mappings":"AASO,IAAMA,EAAN,MAAMC,UAAwB,KAAM,CACzC,YACkBC,EACAC,EAChB,CACA,IAAIC,EAAUD,EAAM,IAAKE,GAAa,KAAKA,CAAQ,EAAE,EAGjDD,EAAQ,OAAS,KACnBA,EAAU,CAAC,GAAGA,EAAQ,MAAM,EAAG,EAAE,EAAG,MAAO,GAAGA,EAAQ,MAAM,GAAG,CAAC,GAGlE,MAAM;AAAA,EAA8CA,EAAQ,KAAK;AAAA,CAAI,CAAC,EAAE,EAVxD,WAAAF,EACA,WAAAC,EAYhB,OAAO,eAAe,KAAMF,EAAgB,SAAS,CACvD,CAEA,cAAcI,EAA2C,CACvD,IAAMC,EAAW,CAACD,EAAU,GAAG,KAAK,KAAK,EAEzC,OAAO,IAAIJ,EAAgB,KAAK,MAAOK,CAAQ,CACjD,CACF,EAKaC,EAAN,MAAMC,UAA8B,KAAM,CAC/C,YAA4BC,EAAyB,CACnD,MAAM,sBAAsBA,CAAI,GAAG,EADT,UAAAA,EAI1B,OAAO,eAAe,KAAMD,EAAsB,SAAS,CAC7D,CACF,EAKaE,EAAN,MAAMC,UAA+B,KAAM,CAChD,aAAc,CACZ,MAAM,2CAA2C,EAGjD,OAAO,eAAe,KAAMA,EAAuB,SAAS,CAC9D,CACF","sourcesContent":["import type { WgslResolvable, WgslSlot } from './types';\n\n/**\n * An error that happens during resolution of WGSL code.\n * Contains a trace of all ancestor resolvables in\n * which this error originated.\n *\n * @category Errors\n */\nexport class ResolutionError extends Error {\n constructor(\n public readonly cause: unknown,\n public readonly trace: WgslResolvable[],\n ) {\n let entries = trace.map((ancestor) => `- ${ancestor}`);\n\n // Showing only the root and leaf nodes.\n if (entries.length > 20) {\n entries = [...entries.slice(0, 11), '...', ...entries.slice(-10)];\n }\n\n super(`Resolution of the following tree failed: \\n${entries.join('\\n')}`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, ResolutionError.prototype);\n }\n\n appendToTrace(ancestor: WgslResolvable): ResolutionError {\n const newTrace = [ancestor, ...this.trace];\n\n return new ResolutionError(this.cause, newTrace);\n }\n}\n\n/**\n * @category Errors\n */\nexport class MissingSlotValueError extends Error {\n constructor(public readonly slot: WgslSlot<unknown>) {\n super(`Missing value for '${slot}'`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, MissingSlotValueError.prototype);\n }\n}\n\n/**\n * @category Errors\n */\nexport class RecursiveDataTypeError extends Error {\n constructor() {\n super('Recursive types are not supported in WGSL');\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, RecursiveDataTypeError.prototype);\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var f=Object.defineProperty,T=Object.defineProperties;var b=Object.getOwnPropertyDescriptors;var a=Object.getOwnPropertySymbols;var p=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var i=(t,e,l)=>e in t?f(t,e,{enumerable:!0,configurable:!0,writable:!0,value:l}):t[e]=l,m= exports.a =(t,e)=>{for(var l in e||(e={}))p.call(e,l)&&i(t,l,e[l]);if(a)for(var l of a(e))W.call(e,l)&&i(t,l,e[l]);return t},v= exports.b =(t,e)=>T(t,b(e));var c=(t,e)=>{var l={};for(var n in t)p.call(t,n)&&e.indexOf(n)<0&&(l[n]=t[n]);if(t!=null&&a)for(var n of a(t))e.indexOf(n)<0&&W.call(t,n)&&(l[n]=t[n]);return l};var r=(t,e,l)=>(i(t,typeof e!="symbol"?e+"":e,l),l);function g(t){return!!t&&(typeof t=="object"||typeof t=="function")&&"resolve"in t}function S(t){return typeof t=="number"||typeof t=="boolean"||typeof t=="string"||g(t)}function R(t){return t.__brand==="WgslSlot"}function h(t){return"pointsTo"in t}function D(t,...e){let l=t.flatMap((n,s)=>{let o=e[s];return o===void 0?[n]:Array.isArray(o)?[n,...o]:[n,o]});return new u(l)}var u=class{constructor(e){this.segments=e;r(this,"_label")}get label(){return this._label}$name(e){return this._label=e,this}resolve(e){let l="";for(let n of this.segments)if(typeof n=="function"){let s=n(o=>e.unwrap(o));l+=e.resolve(s)}else g(n)?l+=e.resolve(n):l+=String(n);return l}with(e,l){return new d(this,[e,l])}toString(){var e;return`code:${(e=this._label)!=null?e:"<unnamed>"}`}},d=class t{constructor(e,l){this._innerFn=e;this._slotValuePair=l}get label(){return this._innerFn.label}with(e,l){return new t(this,[e,l])}resolve(e){return e.resolve(this._innerFn,[this._slotValuePair])}toString(){var n,s;let[e,l]=this._slotValuePair;return`code:${(n=this.label)!=null?n:"<unnamed>"}[${(s=e.label)!=null?s:"<unnamed>"}=${l}]`}};var y=class{constructor(){r(this,"label")}$name(e){return this.label=e,this}resolve(e){return e.nameFor(this)}toString(){var e;return`id:${(e=this.label)!=null?e:"<unnamed>"}`}};exports.a = m; exports.b = v; exports.c = c; exports.d = r; exports.e = g; exports.f = S; exports.g = R; exports.h = h; exports.i = D; exports.j = y;
2
- //# sourceMappingURL=chunk-JYXJ5NFX.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types.ts","../src/wgslCode.ts","../src/wgslIdentifier.ts"],"names":["isResolvable","value","isWgsl","isSlot","isPointer","code","strings","params","segments","string","idx","param","WgslCodeImpl","__publicField","label","ctx","s","result","eventual","slot","BoundWgslCodeImpl","_a","_BoundWgslCodeImpl","_innerFn","_slotValuePair","_b","WgslIdentifier"],"mappings":"moBAiCO,SAASA,EAAaC,EAAyC,CACpE,MACE,CAAC,CAACA,IACD,OAAOA,GAAU,UAAY,OAAOA,GAAU,aAC/C,YAAaA,CAEjB,CAEO,SAASC,EAAOD,EAA+B,CACpD,OACE,OAAOA,GAAU,UACjB,OAAOA,GAAU,WACjB,OAAOA,GAAU,UACjBD,EAAaC,CAAK,CAEtB,CAkBO,SAASE,EAAUF,EAAoD,CAC5E,OAAQA,EAAsB,UAAY,UAC5C,CAkEO,SAASG,EACdH,EACyB,CACzB,MAAO,aAAcA,CACvB,CCnHO,SAASI,EACdC,KACGC,EACO,CACV,IAAMC,EAAqCF,EAAQ,QAAQ,CAACG,EAAQC,IAAQ,CAC1E,IAAMC,EAAQJ,EAAOG,CAAG,EACxB,OAAIC,IAAU,OACL,CAACF,CAAM,EAGT,MAAM,QAAQE,CAAK,EAAI,CAACF,EAAQ,GAAGE,CAAK,EAAI,CAACF,EAAQE,CAAK,CACnE,CAAC,EAED,OAAO,IAAIC,EAAaJ,CAAQ,CAClC,CAMA,IAAMI,EAAN,KAAuC,CAGrC,YAA4BJ,EAAoC,CAApC,cAAAA,EAF5BK,EAAA,KAAQ,SAEyD,CAEjE,IAAI,OAAQ,CACV,OAAO,KAAK,MACd,CAEA,MAAMC,EAA4B,CAChC,YAAK,OAASA,EACP,IACT,CAEA,QAAQC,EAAoB,CAC1B,IAAIV,EAAO,GAEX,QAAWW,KAAK,KAAK,SACnB,GAAI,OAAOA,GAAM,WAAY,CAC3B,IAAMC,EAASD,EAAGE,GAAaH,EAAI,OAAOG,CAAQ,CAAC,EACnDb,GAAQU,EAAI,QAAQE,CAAM,CAC5B,MAAWjB,EAAagB,CAAC,EACvBX,GAAQU,EAAI,QAAQC,CAAC,EAErBX,GAAQ,OAAOW,CAAC,EAIpB,OAAOX,CACT,CAEA,KAAac,EAAwBlB,EAAwC,CAC3E,OAAO,IAAImB,EAAkB,KAAM,CAACD,EAAMlB,CAAK,CAAC,CAClD,CAEA,UAAmB,CA9ErB,IAAAoB,EA+EI,MAAO,SAAQA,EAAA,KAAK,SAAL,KAAAA,EAAe,WAAW,EAC3C,CACF,EAEMD,EAAN,MAAME,CAA8C,CAClD,YACmBC,EACAC,EACjB,CAFiB,cAAAD,EACA,oBAAAC,CAChB,CAEH,IAAI,OAAQ,CACV,OAAO,KAAK,SAAS,KACvB,CAEA,KAAaL,EAAwBlB,EAAwC,CAC3E,OAAO,IAAIqB,EAAkB,KAAM,CAACH,EAAMlB,CAAK,CAAC,CAClD,CAEA,QAAQc,EAA4B,CAClC,OAAOA,EAAI,QAAQ,KAAK,SAAU,CAAC,KAAK,cAAc,CAAC,CACzD,CAEA,UAAmB,CArGrB,IAAAM,EAAAI,EAsGI,GAAM,CAACN,EAAMlB,CAAK,EAAI,KAAK,eAC3B,MAAO,SAAQoB,EAAA,KAAK,QAAL,KAAAA,EAAc,WAAW,KAAII,EAAAN,EAAK,QAAL,KAAAM,EAAc,WAAW,IAAIxB,CAAK,GAChF,CACF,ECpGO,IAAMyB,EAAN,KAA+C,CAA/C,cACLb,EAAA,cAEA,MAAMC,EAA2B,CAC/B,YAAK,MAAQA,EACN,IACT,CAEA,QAAQC,EAA4B,CAClC,OAAOA,EAAI,QAAQ,IAAI,CACzB,CAEA,UAAmB,CAjBrB,IAAAM,EAkBI,MAAO,OAAMA,EAAA,KAAK,QAAL,KAAAA,EAAc,WAAW,EACxC,CACF","sourcesContent":["import type { ISchema, Parsed } from 'typed-binary';\nimport type { WgslIdentifier } from './wgslIdentifier';\nimport type { WgslPlum } from './wgslPlum';\n\nexport type Wgsl = string | boolean | number | WgslResolvable;\n\n/**\n * Passed into each resolvable item. All sibling items share a resolution ctx,\n * and a new resolution ctx is made when going down each level in the tree.\n */\nexport interface ResolutionCtx {\n /**\n * Slots that were used by items resolved by this context.\n */\n readonly usedSlots: Iterable<WgslSlot<unknown>>;\n\n addDeclaration(item: WgslResolvable): void;\n addBinding(bindable: WgslBindable, identifier: WgslIdentifier): void;\n nameFor(token: WgslResolvable): string;\n /**\n * Unwraps all layers of slot indirection and returns the concrete value if available.\n * @throws {MissingSlotValueError}\n */\n unwrap<T>(eventual: Eventual<T>): T;\n resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;\n}\n\nexport interface WgslResolvable {\n readonly label?: string | undefined;\n\n resolve(ctx: ResolutionCtx): string;\n}\n\nexport function isResolvable(value: unknown): value is WgslResolvable {\n return (\n !!value &&\n (typeof value === 'object' || typeof value === 'function') &&\n 'resolve' in value\n );\n}\n\nexport function isWgsl(value: unknown): value is Wgsl {\n return (\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n typeof value === 'string' ||\n isResolvable(value)\n );\n}\n\nexport interface WgslSlot<T> {\n readonly __brand: 'WgslSlot';\n\n readonly defaultValue: T | undefined;\n\n readonly label?: string | undefined;\n\n $name(label: string): WgslSlot<T>;\n\n /**\n * Used to determine if code generated using either value `a` or `b` in place\n * of the slot will be equivalent. Defaults to `Object.is`.\n */\n areEqual(a: T, b: T): boolean;\n}\n\nexport function isSlot<T>(value: unknown | WgslSlot<T>): value is WgslSlot<T> {\n return (value as WgslSlot<T>).__brand === 'WgslSlot';\n}\n\n/**\n * Represents a value that is available at resolution time.\n */\nexport type Eventual<T> = T | WgslSlot<T>;\n\nexport type EventualGetter = <T>(value: Eventual<T>) => T;\n\nexport type InlineResolve = (get: EventualGetter) => Wgsl;\n\nexport interface WgslResolvableSlot<T extends Wgsl>\n extends WgslResolvable,\n WgslSlot<T> {\n $name(label: string): WgslResolvableSlot<T>;\n}\n\nexport type SlotValuePair<T> = [WgslSlot<T>, T];\n\nexport interface WgslAllocatable<TData extends AnyWgslData = AnyWgslData> {\n /**\n * The data type this allocatable was constructed with.\n * It informs the size and format of data in both JS and\n * binary.\n */\n readonly dataType: TData;\n readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;\n readonly flags: GPUBufferUsageFlags;\n}\n\nexport interface WgslBindable<\n TData extends AnyWgslData = AnyWgslData,\n TUsage extends BufferUsage = BufferUsage,\n> extends WgslResolvable {\n readonly allocatable: WgslAllocatable<TData>;\n readonly usage: TUsage;\n}\n\nexport type BufferUsage = 'uniform' | 'readonly_storage' | 'mutable_storage';\n\nexport interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {\n readonly byteAlignment: number;\n readonly size: number;\n}\n\nexport type AnyWgslData = WgslData<unknown>;\n\nexport interface WgslPointer<\n TScope extends 'function',\n TInner extends AnyWgslData,\n> {\n readonly scope: TScope;\n readonly pointsTo: TInner;\n}\n\n/**\n * A virtual representation of a WGSL value.\n */\nexport type WgslValue<TDataType> = {\n readonly __dataType: TDataType;\n};\n\nexport type AnyWgslPointer = WgslPointer<'function', AnyWgslData>;\n\nexport type WgslFnArgument = AnyWgslPointer | AnyWgslData;\n\nexport function isPointer(\n value: AnyWgslPointer | AnyWgslData,\n): value is AnyWgslPointer {\n return 'pointsTo' in value;\n}\n","import {\n type Eventual,\n type InlineResolve,\n type ResolutionCtx,\n type SlotValuePair,\n type Wgsl,\n type WgslResolvable,\n type WgslSlot,\n isResolvable,\n} from './types';\n\n// ----------\n// Public API\n// ----------\n\nexport interface WgslCode extends WgslResolvable {\n $name(label?: string | undefined): WgslCode;\n\n with<T>(slot: WgslSlot<T>, value: Eventual<T>): BoundWgslCode;\n}\n\nexport type BoundWgslCode = Omit<WgslCode, '$name'>;\n\nexport function code(\n strings: TemplateStringsArray,\n ...params: (Wgsl | Wgsl[] | InlineResolve)[]\n): WgslCode {\n const segments: (Wgsl | InlineResolve)[] = strings.flatMap((string, idx) => {\n const param = params[idx];\n if (param === undefined) {\n return [string];\n }\n\n return Array.isArray(param) ? [string, ...param] : [string, param];\n });\n\n return new WgslCodeImpl(segments);\n}\n\n// --------------\n// Implementation\n// --------------\n\nclass WgslCodeImpl implements WgslCode {\n private _label: string | undefined;\n\n constructor(public readonly segments: (Wgsl | InlineResolve)[]) {}\n\n get label() {\n return this._label;\n }\n\n $name(label?: string | undefined) {\n this._label = label;\n return this;\n }\n\n resolve(ctx: ResolutionCtx) {\n let code = '';\n\n for (const s of this.segments) {\n if (typeof s === 'function') {\n const result = s((eventual) => ctx.unwrap(eventual));\n code += ctx.resolve(result);\n } else if (isResolvable(s)) {\n code += ctx.resolve(s);\n } else {\n code += String(s);\n }\n }\n\n return code;\n }\n\n with<TValue>(slot: WgslSlot<TValue>, value: Eventual<TValue>): BoundWgslCode {\n return new BoundWgslCodeImpl(this, [slot, value]);\n }\n\n toString(): string {\n return `code:${this._label ?? '<unnamed>'}`;\n }\n}\n\nclass BoundWgslCodeImpl<T> implements BoundWgslCode {\n constructor(\n private readonly _innerFn: BoundWgslCode,\n private readonly _slotValuePair: SlotValuePair<T>,\n ) {}\n\n get label() {\n return this._innerFn.label;\n }\n\n with<TValue>(slot: WgslSlot<TValue>, value: Eventual<TValue>): BoundWgslCode {\n return new BoundWgslCodeImpl(this, [slot, value]);\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.resolve(this._innerFn, [this._slotValuePair]);\n }\n\n toString(): string {\n const [slot, value] = this._slotValuePair;\n return `code:${this.label ?? '<unnamed>'}[${slot.label ?? '<unnamed>'}=${value}]`;\n }\n}\n","import type { ResolutionCtx, WgslResolvable } from './types';\n\n/**\n * Helpful when creating new Resolvable types. For internal use.\n */\nexport class WgslIdentifier implements WgslResolvable {\n label?: string | undefined;\n\n $name(label: string | undefined) {\n this.label = label;\n return this;\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.nameFor(this);\n }\n\n toString(): string {\n return `id:${this.label ?? '<unnamed>'}`;\n }\n}\n"]}
package/chunk-K6N2A55L.js DELETED
@@ -1,4 +0,0 @@
1
- var r=class e extends Error{constructor(o,s){let t=s.map(c=>`- ${c}`);t.length>20&&(t=[...t.slice(0,11),"...",...t.slice(-10)]);super(`Resolution of the following tree failed:
2
- ${t.join(`
3
- `)}`);this.cause=o;this.trace=s;Object.setPrototypeOf(this,e.prototype)}appendToTrace(o){let s=[o,...this.trace];return new e(this.cause,s)}},l=class e extends Error{constructor(o){super(`Missing value for '${o}'`);this.slot=o;Object.setPrototypeOf(this,e.prototype)}},n=class e extends Error{constructor(){super("Recursive types are not supported in WGSL"),Object.setPrototypeOf(this,e.prototype)}};export{r as a,l as b,n as c};
4
- //# sourceMappingURL=chunk-K6N2A55L.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors.ts"],"sourcesContent":["import type { WgslResolvable, WgslSlot } from './types';\n\n/**\n * An error that happens during resolution of WGSL code.\n * Contains a trace of all ancestor resolvables in\n * which this error originated.\n *\n * @category Errors\n */\nexport class ResolutionError extends Error {\n constructor(\n public readonly cause: unknown,\n public readonly trace: WgslResolvable[],\n ) {\n let entries = trace.map((ancestor) => `- ${ancestor}`);\n\n // Showing only the root and leaf nodes.\n if (entries.length > 20) {\n entries = [...entries.slice(0, 11), '...', ...entries.slice(-10)];\n }\n\n super(`Resolution of the following tree failed: \\n${entries.join('\\n')}`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, ResolutionError.prototype);\n }\n\n appendToTrace(ancestor: WgslResolvable): ResolutionError {\n const newTrace = [ancestor, ...this.trace];\n\n return new ResolutionError(this.cause, newTrace);\n }\n}\n\n/**\n * @category Errors\n */\nexport class MissingSlotValueError extends Error {\n constructor(public readonly slot: WgslSlot<unknown>) {\n super(`Missing value for '${slot}'`);\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, MissingSlotValueError.prototype);\n }\n}\n\n/**\n * @category Errors\n */\nexport class RecursiveDataTypeError extends Error {\n constructor() {\n super('Recursive types are not supported in WGSL');\n\n // Set the prototype explicitly.\n Object.setPrototypeOf(this, RecursiveDataTypeError.prototype);\n }\n}\n"],"mappings":"AASO,IAAMA,EAAN,MAAMC,UAAwB,KAAM,CACzC,YACkBC,EACAC,EAChB,CACA,IAAIC,EAAUD,EAAM,IAAKE,GAAa,KAAKA,CAAQ,EAAE,EAGjDD,EAAQ,OAAS,KACnBA,EAAU,CAAC,GAAGA,EAAQ,MAAM,EAAG,EAAE,EAAG,MAAO,GAAGA,EAAQ,MAAM,GAAG,CAAC,GAGlE,MAAM;AAAA,EAA8CA,EAAQ,KAAK;AAAA,CAAI,CAAC,EAAE,EAVxD,WAAAF,EACA,WAAAC,EAYhB,OAAO,eAAe,KAAMF,EAAgB,SAAS,CACvD,CAEA,cAAcI,EAA2C,CACvD,IAAMC,EAAW,CAACD,EAAU,GAAG,KAAK,KAAK,EAEzC,OAAO,IAAIJ,EAAgB,KAAK,MAAOK,CAAQ,CACjD,CACF,EAKaC,EAAN,MAAMC,UAA8B,KAAM,CAC/C,YAA4BC,EAAyB,CACnD,MAAM,sBAAsBA,CAAI,GAAG,EADT,UAAAA,EAI1B,OAAO,eAAe,KAAMD,EAAsB,SAAS,CAC7D,CACF,EAKaE,EAAN,MAAMC,UAA+B,KAAM,CAChD,aAAc,CACZ,MAAM,2CAA2C,EAGjD,OAAO,eAAe,KAAMA,EAAuB,SAAS,CAC9D,CACF","names":["ResolutionError","_ResolutionError","cause","trace","entries","ancestor","newTrace","MissingSlotValueError","_MissingSlotValueError","slot","RecursiveDataTypeError","_RecursiveDataTypeError"]}
package/chunk-NTGWE7PR.js DELETED
@@ -1,2 +0,0 @@
1
- var f=Object.defineProperty,T=Object.defineProperties;var b=Object.getOwnPropertyDescriptors;var a=Object.getOwnPropertySymbols;var p=Object.prototype.hasOwnProperty,W=Object.prototype.propertyIsEnumerable;var i=(t,e,l)=>e in t?f(t,e,{enumerable:!0,configurable:!0,writable:!0,value:l}):t[e]=l,m=(t,e)=>{for(var l in e||(e={}))p.call(e,l)&&i(t,l,e[l]);if(a)for(var l of a(e))W.call(e,l)&&i(t,l,e[l]);return t},v=(t,e)=>T(t,b(e));var c=(t,e)=>{var l={};for(var n in t)p.call(t,n)&&e.indexOf(n)<0&&(l[n]=t[n]);if(t!=null&&a)for(var n of a(t))e.indexOf(n)<0&&W.call(t,n)&&(l[n]=t[n]);return l};var r=(t,e,l)=>(i(t,typeof e!="symbol"?e+"":e,l),l);function g(t){return!!t&&(typeof t=="object"||typeof t=="function")&&"resolve"in t}function S(t){return typeof t=="number"||typeof t=="boolean"||typeof t=="string"||g(t)}function R(t){return t.__brand==="WgslSlot"}function h(t){return"pointsTo"in t}function D(t,...e){let l=t.flatMap((n,s)=>{let o=e[s];return o===void 0?[n]:Array.isArray(o)?[n,...o]:[n,o]});return new u(l)}var u=class{constructor(e){this.segments=e;r(this,"_label")}get label(){return this._label}$name(e){return this._label=e,this}resolve(e){let l="";for(let n of this.segments)if(typeof n=="function"){let s=n(o=>e.unwrap(o));l+=e.resolve(s)}else g(n)?l+=e.resolve(n):l+=String(n);return l}with(e,l){return new d(this,[e,l])}toString(){var e;return`code:${(e=this._label)!=null?e:"<unnamed>"}`}},d=class t{constructor(e,l){this._innerFn=e;this._slotValuePair=l}get label(){return this._innerFn.label}with(e,l){return new t(this,[e,l])}resolve(e){return e.resolve(this._innerFn,[this._slotValuePair])}toString(){var n,s;let[e,l]=this._slotValuePair;return`code:${(n=this.label)!=null?n:"<unnamed>"}[${(s=e.label)!=null?s:"<unnamed>"}=${l}]`}};var y=class{constructor(){r(this,"label")}$name(e){return this.label=e,this}resolve(e){return e.nameFor(this)}toString(){var e;return`id:${(e=this.label)!=null?e:"<unnamed>"}`}};export{m as a,v as b,c,r as d,g as e,S as f,R as g,h,D as i,y as j};
2
- //# sourceMappingURL=chunk-NTGWE7PR.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types.ts","../src/wgslCode.ts","../src/wgslIdentifier.ts"],"sourcesContent":["import type { ISchema, Parsed } from 'typed-binary';\nimport type { WgslIdentifier } from './wgslIdentifier';\nimport type { WgslPlum } from './wgslPlum';\n\nexport type Wgsl = string | boolean | number | WgslResolvable;\n\n/**\n * Passed into each resolvable item. All sibling items share a resolution ctx,\n * and a new resolution ctx is made when going down each level in the tree.\n */\nexport interface ResolutionCtx {\n /**\n * Slots that were used by items resolved by this context.\n */\n readonly usedSlots: Iterable<WgslSlot<unknown>>;\n\n addDeclaration(item: WgslResolvable): void;\n addBinding(bindable: WgslBindable, identifier: WgslIdentifier): void;\n nameFor(token: WgslResolvable): string;\n /**\n * Unwraps all layers of slot indirection and returns the concrete value if available.\n * @throws {MissingSlotValueError}\n */\n unwrap<T>(eventual: Eventual<T>): T;\n resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;\n}\n\nexport interface WgslResolvable {\n readonly label?: string | undefined;\n\n resolve(ctx: ResolutionCtx): string;\n}\n\nexport function isResolvable(value: unknown): value is WgslResolvable {\n return (\n !!value &&\n (typeof value === 'object' || typeof value === 'function') &&\n 'resolve' in value\n );\n}\n\nexport function isWgsl(value: unknown): value is Wgsl {\n return (\n typeof value === 'number' ||\n typeof value === 'boolean' ||\n typeof value === 'string' ||\n isResolvable(value)\n );\n}\n\nexport interface WgslSlot<T> {\n readonly __brand: 'WgslSlot';\n\n readonly defaultValue: T | undefined;\n\n readonly label?: string | undefined;\n\n $name(label: string): WgslSlot<T>;\n\n /**\n * Used to determine if code generated using either value `a` or `b` in place\n * of the slot will be equivalent. Defaults to `Object.is`.\n */\n areEqual(a: T, b: T): boolean;\n}\n\nexport function isSlot<T>(value: unknown | WgslSlot<T>): value is WgslSlot<T> {\n return (value as WgslSlot<T>).__brand === 'WgslSlot';\n}\n\n/**\n * Represents a value that is available at resolution time.\n */\nexport type Eventual<T> = T | WgslSlot<T>;\n\nexport type EventualGetter = <T>(value: Eventual<T>) => T;\n\nexport type InlineResolve = (get: EventualGetter) => Wgsl;\n\nexport interface WgslResolvableSlot<T extends Wgsl>\n extends WgslResolvable,\n WgslSlot<T> {\n $name(label: string): WgslResolvableSlot<T>;\n}\n\nexport type SlotValuePair<T> = [WgslSlot<T>, T];\n\nexport interface WgslAllocatable<TData extends AnyWgslData = AnyWgslData> {\n /**\n * The data type this allocatable was constructed with.\n * It informs the size and format of data in both JS and\n * binary.\n */\n readonly dataType: TData;\n readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;\n readonly flags: GPUBufferUsageFlags;\n}\n\nexport interface WgslBindable<\n TData extends AnyWgslData = AnyWgslData,\n TUsage extends BufferUsage = BufferUsage,\n> extends WgslResolvable {\n readonly allocatable: WgslAllocatable<TData>;\n readonly usage: TUsage;\n}\n\nexport type BufferUsage = 'uniform' | 'readonly_storage' | 'mutable_storage';\n\nexport interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {\n readonly byteAlignment: number;\n readonly size: number;\n}\n\nexport type AnyWgslData = WgslData<unknown>;\n\nexport interface WgslPointer<\n TScope extends 'function',\n TInner extends AnyWgslData,\n> {\n readonly scope: TScope;\n readonly pointsTo: TInner;\n}\n\n/**\n * A virtual representation of a WGSL value.\n */\nexport type WgslValue<TDataType> = {\n readonly __dataType: TDataType;\n};\n\nexport type AnyWgslPointer = WgslPointer<'function', AnyWgslData>;\n\nexport type WgslFnArgument = AnyWgslPointer | AnyWgslData;\n\nexport function isPointer(\n value: AnyWgslPointer | AnyWgslData,\n): value is AnyWgslPointer {\n return 'pointsTo' in value;\n}\n","import {\n type Eventual,\n type InlineResolve,\n type ResolutionCtx,\n type SlotValuePair,\n type Wgsl,\n type WgslResolvable,\n type WgslSlot,\n isResolvable,\n} from './types';\n\n// ----------\n// Public API\n// ----------\n\nexport interface WgslCode extends WgslResolvable {\n $name(label?: string | undefined): WgslCode;\n\n with<T>(slot: WgslSlot<T>, value: Eventual<T>): BoundWgslCode;\n}\n\nexport type BoundWgslCode = Omit<WgslCode, '$name'>;\n\nexport function code(\n strings: TemplateStringsArray,\n ...params: (Wgsl | Wgsl[] | InlineResolve)[]\n): WgslCode {\n const segments: (Wgsl | InlineResolve)[] = strings.flatMap((string, idx) => {\n const param = params[idx];\n if (param === undefined) {\n return [string];\n }\n\n return Array.isArray(param) ? [string, ...param] : [string, param];\n });\n\n return new WgslCodeImpl(segments);\n}\n\n// --------------\n// Implementation\n// --------------\n\nclass WgslCodeImpl implements WgslCode {\n private _label: string | undefined;\n\n constructor(public readonly segments: (Wgsl | InlineResolve)[]) {}\n\n get label() {\n return this._label;\n }\n\n $name(label?: string | undefined) {\n this._label = label;\n return this;\n }\n\n resolve(ctx: ResolutionCtx) {\n let code = '';\n\n for (const s of this.segments) {\n if (typeof s === 'function') {\n const result = s((eventual) => ctx.unwrap(eventual));\n code += ctx.resolve(result);\n } else if (isResolvable(s)) {\n code += ctx.resolve(s);\n } else {\n code += String(s);\n }\n }\n\n return code;\n }\n\n with<TValue>(slot: WgslSlot<TValue>, value: Eventual<TValue>): BoundWgslCode {\n return new BoundWgslCodeImpl(this, [slot, value]);\n }\n\n toString(): string {\n return `code:${this._label ?? '<unnamed>'}`;\n }\n}\n\nclass BoundWgslCodeImpl<T> implements BoundWgslCode {\n constructor(\n private readonly _innerFn: BoundWgslCode,\n private readonly _slotValuePair: SlotValuePair<T>,\n ) {}\n\n get label() {\n return this._innerFn.label;\n }\n\n with<TValue>(slot: WgslSlot<TValue>, value: Eventual<TValue>): BoundWgslCode {\n return new BoundWgslCodeImpl(this, [slot, value]);\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.resolve(this._innerFn, [this._slotValuePair]);\n }\n\n toString(): string {\n const [slot, value] = this._slotValuePair;\n return `code:${this.label ?? '<unnamed>'}[${slot.label ?? '<unnamed>'}=${value}]`;\n }\n}\n","import type { ResolutionCtx, WgslResolvable } from './types';\n\n/**\n * Helpful when creating new Resolvable types. For internal use.\n */\nexport class WgslIdentifier implements WgslResolvable {\n label?: string | undefined;\n\n $name(label: string | undefined) {\n this.label = label;\n return this;\n }\n\n resolve(ctx: ResolutionCtx): string {\n return ctx.nameFor(this);\n }\n\n toString(): string {\n return `id:${this.label ?? '<unnamed>'}`;\n }\n}\n"],"mappings":"moBAiCO,SAASA,EAAaC,EAAyC,CACpE,MACE,CAAC,CAACA,IACD,OAAOA,GAAU,UAAY,OAAOA,GAAU,aAC/C,YAAaA,CAEjB,CAEO,SAASC,EAAOD,EAA+B,CACpD,OACE,OAAOA,GAAU,UACjB,OAAOA,GAAU,WACjB,OAAOA,GAAU,UACjBD,EAAaC,CAAK,CAEtB,CAkBO,SAASE,EAAUF,EAAoD,CAC5E,OAAQA,EAAsB,UAAY,UAC5C,CAkEO,SAASG,EACdH,EACyB,CACzB,MAAO,aAAcA,CACvB,CCnHO,SAASI,EACdC,KACGC,EACO,CACV,IAAMC,EAAqCF,EAAQ,QAAQ,CAACG,EAAQC,IAAQ,CAC1E,IAAMC,EAAQJ,EAAOG,CAAG,EACxB,OAAIC,IAAU,OACL,CAACF,CAAM,EAGT,MAAM,QAAQE,CAAK,EAAI,CAACF,EAAQ,GAAGE,CAAK,EAAI,CAACF,EAAQE,CAAK,CACnE,CAAC,EAED,OAAO,IAAIC,EAAaJ,CAAQ,CAClC,CAMA,IAAMI,EAAN,KAAuC,CAGrC,YAA4BJ,EAAoC,CAApC,cAAAA,EAF5BK,EAAA,KAAQ,SAEyD,CAEjE,IAAI,OAAQ,CACV,OAAO,KAAK,MACd,CAEA,MAAMC,EAA4B,CAChC,YAAK,OAASA,EACP,IACT,CAEA,QAAQC,EAAoB,CAC1B,IAAIV,EAAO,GAEX,QAAWW,KAAK,KAAK,SACnB,GAAI,OAAOA,GAAM,WAAY,CAC3B,IAAMC,EAASD,EAAGE,GAAaH,EAAI,OAAOG,CAAQ,CAAC,EACnDb,GAAQU,EAAI,QAAQE,CAAM,CAC5B,MAAWE,EAAaH,CAAC,EACvBX,GAAQU,EAAI,QAAQC,CAAC,EAErBX,GAAQ,OAAOW,CAAC,EAIpB,OAAOX,CACT,CAEA,KAAae,EAAwBC,EAAwC,CAC3E,OAAO,IAAIC,EAAkB,KAAM,CAACF,EAAMC,CAAK,CAAC,CAClD,CAEA,UAAmB,CA9ErB,IAAAE,EA+EI,MAAO,SAAQA,EAAA,KAAK,SAAL,KAAAA,EAAe,WAAW,EAC3C,CACF,EAEMD,EAAN,MAAME,CAA8C,CAClD,YACmBC,EACAC,EACjB,CAFiB,cAAAD,EACA,oBAAAC,CAChB,CAEH,IAAI,OAAQ,CACV,OAAO,KAAK,SAAS,KACvB,CAEA,KAAaN,EAAwBC,EAAwC,CAC3E,OAAO,IAAIG,EAAkB,KAAM,CAACJ,EAAMC,CAAK,CAAC,CAClD,CAEA,QAAQN,EAA4B,CAClC,OAAOA,EAAI,QAAQ,KAAK,SAAU,CAAC,KAAK,cAAc,CAAC,CACzD,CAEA,UAAmB,CArGrB,IAAAQ,EAAAI,EAsGI,GAAM,CAACP,EAAMC,CAAK,EAAI,KAAK,eAC3B,MAAO,SAAQE,EAAA,KAAK,QAAL,KAAAA,EAAc,WAAW,KAAII,EAAAP,EAAK,QAAL,KAAAO,EAAc,WAAW,IAAIN,CAAK,GAChF,CACF,ECpGO,IAAMO,EAAN,KAA+C,CAA/C,cACLC,EAAA,cAEA,MAAMC,EAA2B,CAC/B,YAAK,MAAQA,EACN,IACT,CAEA,QAAQC,EAA4B,CAClC,OAAOA,EAAI,QAAQ,IAAI,CACzB,CAEA,UAAmB,CAjBrB,IAAAC,EAkBI,MAAO,OAAMA,EAAA,KAAK,QAAL,KAAAA,EAAc,WAAW,EACxC,CACF","names":["isResolvable","value","isWgsl","isSlot","isPointer","code","strings","params","segments","string","idx","param","WgslCodeImpl","__publicField","label","ctx","s","result","eventual","isResolvable","slot","value","BoundWgslCodeImpl","_a","_BoundWgslCodeImpl","_innerFn","_slotValuePair","_b","WgslIdentifier","__publicField","label","ctx","_a"]}
@@ -1,9 +0,0 @@
1
- import { ISchema, UnwrapRecord } from 'typed-binary';
2
- import { A as AnyWgslData, r as WgslData } from './types-DeF6xFAt.cjs';
3
-
4
- interface WgslStruct<TProps extends Record<string, AnyWgslData>> extends ISchema<UnwrapRecord<TProps>>, WgslData<UnwrapRecord<TProps>> {
5
- $name(label: string): this;
6
- }
7
- declare const struct: <TProps extends Record<string, AnyWgslData>>(properties: TProps) => WgslStruct<TProps>;
8
-
9
- export { type WgslStruct as W, struct as s };
@@ -1,9 +0,0 @@
1
- import { ISchema, UnwrapRecord } from 'typed-binary';
2
- import { A as AnyWgslData, r as WgslData } from './types-DeF6xFAt.js';
3
-
4
- interface WgslStruct<TProps extends Record<string, AnyWgslData>> extends ISchema<UnwrapRecord<TProps>>, WgslData<UnwrapRecord<TProps>> {
5
- $name(label: string): this;
6
- }
7
- declare const struct: <TProps extends Record<string, AnyWgslData>>(properties: TProps) => WgslStruct<TProps>;
8
-
9
- export { type WgslStruct as W, struct as s };
@@ -1,148 +0,0 @@
1
- import { Parsed, ISchema } from 'typed-binary';
2
-
3
- /**
4
- * Helpful when creating new Resolvable types. For internal use.
5
- */
6
- declare class WgslIdentifier implements WgslResolvable {
7
- label?: string | undefined;
8
- $name(label: string | undefined): this;
9
- resolve(ctx: ResolutionCtx): string;
10
- toString(): string;
11
- }
12
-
13
- declare const WgslSettableTrait: unique symbol;
14
- interface WgslSettable {
15
- readonly [WgslSettableTrait]: true;
16
- }
17
-
18
- type Getter = <T>(plum: WgslPlum<T>) => T;
19
- type Unsubscribe = () => unknown;
20
- type ExtractPlumValue<T> = T extends WgslPlum<infer TValue> ? TValue : never;
21
- interface WgslPlum<TValue = unknown> {
22
- readonly __brand: 'WgslPlum';
23
- $name(label: string): this;
24
- /**
25
- * Computes the value of this plum. Circumvents the store
26
- * memoization, so use with care.
27
- */
28
- compute(get: Getter): TValue;
29
- }
30
- declare const WgslExternalPlumTrait: unique symbol;
31
- interface WgslExternalPlum {
32
- readonly [WgslExternalPlumTrait]: true;
33
- readonly version: number;
34
- subscribe(listener: () => unknown): Unsubscribe;
35
- }
36
- /**
37
- * Creates a computed plum. Its value depends on the plums read using `get`
38
- * inside the `compute` function, so cannot be set imperatively.
39
- *
40
- * @param compute A pure function that describes this plum's value.
41
- */
42
- declare function plum<T extends Wgsl>(compute: (get: Getter) => T): WgslPlum<T> & WgslResolvable;
43
- /**
44
- * Creates a computed plum. Its value depends on the plums read using `get`
45
- * inside the `compute` function, so cannot be set imperatively.
46
- *
47
- * @param compute A pure function that describes this plum's value.
48
- */
49
- declare function plum<T>(compute: (get: Getter) => T): WgslPlum<T>;
50
- /**
51
- * Creates a plum with an initial value of `initial`.
52
- * Its value can be updated by calling `runtime.setPlum(thePlum, newValue)`.
53
- *
54
- * @param initial The initial value of this plum.
55
- */
56
- declare function plum<T extends Wgsl>(initial: T): WgslPlum<T> & WgslSettable & WgslResolvable;
57
- /**
58
- * Creates a plum with an initial value of `initial`.
59
- * Its value can be updated by calling `runtime.setPlum(thePlum, newValue)`.
60
- *
61
- * @param initial The initial value of this plum.
62
- */
63
- declare function plum<T>(initial: T): WgslPlum<T> & WgslSettable;
64
- declare function plumFromEvent<T>(subscribe: (listener: () => unknown) => Unsubscribe, getLatest: () => T): WgslPlum<T> & WgslExternalPlum;
65
-
66
- type Wgsl = string | boolean | number | WgslResolvable;
67
- /**
68
- * Passed into each resolvable item. All sibling items share a resolution ctx,
69
- * and a new resolution ctx is made when going down each level in the tree.
70
- */
71
- interface ResolutionCtx {
72
- /**
73
- * Slots that were used by items resolved by this context.
74
- */
75
- readonly usedSlots: Iterable<WgslSlot<unknown>>;
76
- addDeclaration(item: WgslResolvable): void;
77
- addBinding(bindable: WgslBindable, identifier: WgslIdentifier): void;
78
- nameFor(token: WgslResolvable): string;
79
- /**
80
- * Unwraps all layers of slot indirection and returns the concrete value if available.
81
- * @throws {MissingSlotValueError}
82
- */
83
- unwrap<T>(eventual: Eventual<T>): T;
84
- resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
85
- }
86
- interface WgslResolvable {
87
- readonly label?: string | undefined;
88
- resolve(ctx: ResolutionCtx): string;
89
- }
90
- declare function isResolvable(value: unknown): value is WgslResolvable;
91
- declare function isWgsl(value: unknown): value is Wgsl;
92
- interface WgslSlot<T> {
93
- readonly __brand: 'WgslSlot';
94
- readonly defaultValue: T | undefined;
95
- readonly label?: string | undefined;
96
- $name(label: string): WgslSlot<T>;
97
- /**
98
- * Used to determine if code generated using either value `a` or `b` in place
99
- * of the slot will be equivalent. Defaults to `Object.is`.
100
- */
101
- areEqual(a: T, b: T): boolean;
102
- }
103
- declare function isSlot<T>(value: unknown | WgslSlot<T>): value is WgslSlot<T>;
104
- /**
105
- * Represents a value that is available at resolution time.
106
- */
107
- type Eventual<T> = T | WgslSlot<T>;
108
- type EventualGetter = <T>(value: Eventual<T>) => T;
109
- type InlineResolve = (get: EventualGetter) => Wgsl;
110
- interface WgslResolvableSlot<T extends Wgsl> extends WgslResolvable, WgslSlot<T> {
111
- $name(label: string): WgslResolvableSlot<T>;
112
- }
113
- type SlotValuePair<T> = [WgslSlot<T>, T];
114
- interface WgslAllocatable<TData extends AnyWgslData = AnyWgslData> {
115
- /**
116
- * The data type this allocatable was constructed with.
117
- * It informs the size and format of data in both JS and
118
- * binary.
119
- */
120
- readonly dataType: TData;
121
- readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;
122
- readonly flags: GPUBufferUsageFlags;
123
- }
124
- interface WgslBindable<TData extends AnyWgslData = AnyWgslData, TUsage extends BufferUsage = BufferUsage> extends WgslResolvable {
125
- readonly allocatable: WgslAllocatable<TData>;
126
- readonly usage: TUsage;
127
- }
128
- type BufferUsage = 'uniform' | 'readonly_storage' | 'mutable_storage';
129
- interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {
130
- readonly byteAlignment: number;
131
- readonly size: number;
132
- }
133
- type AnyWgslData = WgslData<unknown>;
134
- interface WgslPointer<TScope extends 'function', TInner extends AnyWgslData> {
135
- readonly scope: TScope;
136
- readonly pointsTo: TInner;
137
- }
138
- /**
139
- * A virtual representation of a WGSL value.
140
- */
141
- type WgslValue<TDataType> = {
142
- readonly __dataType: TDataType;
143
- };
144
- type AnyWgslPointer = WgslPointer<'function', AnyWgslData>;
145
- type WgslFnArgument = AnyWgslPointer | AnyWgslData;
146
- declare function isPointer(value: AnyWgslPointer | AnyWgslData): value is AnyWgslPointer;
147
-
148
- export { type AnyWgslData as A, type BufferUsage as B, type ExtractPlumValue as E, type InlineResolve as I, type ResolutionCtx as R, type SlotValuePair as S, type Unsubscribe as U, type WgslResolvable as W, type WgslSlot as a, type WgslPlum as b, type WgslSettable as c, type WgslAllocatable as d, type Wgsl as e, type WgslBindable as f, type Eventual as g, type WgslFnArgument as h, type WgslValue as i, WgslIdentifier as j, type WgslResolvableSlot as k, plumFromEvent as l, isResolvable as m, isWgsl as n, isSlot as o, plum as p, type EventualGetter as q, type WgslData as r, type WgslPointer as s, type AnyWgslPointer as t, isPointer as u };
@@ -1,148 +0,0 @@
1
- import { Parsed, ISchema } from 'typed-binary';
2
-
3
- /**
4
- * Helpful when creating new Resolvable types. For internal use.
5
- */
6
- declare class WgslIdentifier implements WgslResolvable {
7
- label?: string | undefined;
8
- $name(label: string | undefined): this;
9
- resolve(ctx: ResolutionCtx): string;
10
- toString(): string;
11
- }
12
-
13
- declare const WgslSettableTrait: unique symbol;
14
- interface WgslSettable {
15
- readonly [WgslSettableTrait]: true;
16
- }
17
-
18
- type Getter = <T>(plum: WgslPlum<T>) => T;
19
- type Unsubscribe = () => unknown;
20
- type ExtractPlumValue<T> = T extends WgslPlum<infer TValue> ? TValue : never;
21
- interface WgslPlum<TValue = unknown> {
22
- readonly __brand: 'WgslPlum';
23
- $name(label: string): this;
24
- /**
25
- * Computes the value of this plum. Circumvents the store
26
- * memoization, so use with care.
27
- */
28
- compute(get: Getter): TValue;
29
- }
30
- declare const WgslExternalPlumTrait: unique symbol;
31
- interface WgslExternalPlum {
32
- readonly [WgslExternalPlumTrait]: true;
33
- readonly version: number;
34
- subscribe(listener: () => unknown): Unsubscribe;
35
- }
36
- /**
37
- * Creates a computed plum. Its value depends on the plums read using `get`
38
- * inside the `compute` function, so cannot be set imperatively.
39
- *
40
- * @param compute A pure function that describes this plum's value.
41
- */
42
- declare function plum<T extends Wgsl>(compute: (get: Getter) => T): WgslPlum<T> & WgslResolvable;
43
- /**
44
- * Creates a computed plum. Its value depends on the plums read using `get`
45
- * inside the `compute` function, so cannot be set imperatively.
46
- *
47
- * @param compute A pure function that describes this plum's value.
48
- */
49
- declare function plum<T>(compute: (get: Getter) => T): WgslPlum<T>;
50
- /**
51
- * Creates a plum with an initial value of `initial`.
52
- * Its value can be updated by calling `runtime.setPlum(thePlum, newValue)`.
53
- *
54
- * @param initial The initial value of this plum.
55
- */
56
- declare function plum<T extends Wgsl>(initial: T): WgslPlum<T> & WgslSettable & WgslResolvable;
57
- /**
58
- * Creates a plum with an initial value of `initial`.
59
- * Its value can be updated by calling `runtime.setPlum(thePlum, newValue)`.
60
- *
61
- * @param initial The initial value of this plum.
62
- */
63
- declare function plum<T>(initial: T): WgslPlum<T> & WgslSettable;
64
- declare function plumFromEvent<T>(subscribe: (listener: () => unknown) => Unsubscribe, getLatest: () => T): WgslPlum<T> & WgslExternalPlum;
65
-
66
- type Wgsl = string | boolean | number | WgslResolvable;
67
- /**
68
- * Passed into each resolvable item. All sibling items share a resolution ctx,
69
- * and a new resolution ctx is made when going down each level in the tree.
70
- */
71
- interface ResolutionCtx {
72
- /**
73
- * Slots that were used by items resolved by this context.
74
- */
75
- readonly usedSlots: Iterable<WgslSlot<unknown>>;
76
- addDeclaration(item: WgslResolvable): void;
77
- addBinding(bindable: WgslBindable, identifier: WgslIdentifier): void;
78
- nameFor(token: WgslResolvable): string;
79
- /**
80
- * Unwraps all layers of slot indirection and returns the concrete value if available.
81
- * @throws {MissingSlotValueError}
82
- */
83
- unwrap<T>(eventual: Eventual<T>): T;
84
- resolve(item: Wgsl, slotValueOverrides?: SlotValuePair<unknown>[]): string;
85
- }
86
- interface WgslResolvable {
87
- readonly label?: string | undefined;
88
- resolve(ctx: ResolutionCtx): string;
89
- }
90
- declare function isResolvable(value: unknown): value is WgslResolvable;
91
- declare function isWgsl(value: unknown): value is Wgsl;
92
- interface WgslSlot<T> {
93
- readonly __brand: 'WgslSlot';
94
- readonly defaultValue: T | undefined;
95
- readonly label?: string | undefined;
96
- $name(label: string): WgslSlot<T>;
97
- /**
98
- * Used to determine if code generated using either value `a` or `b` in place
99
- * of the slot will be equivalent. Defaults to `Object.is`.
100
- */
101
- areEqual(a: T, b: T): boolean;
102
- }
103
- declare function isSlot<T>(value: unknown | WgslSlot<T>): value is WgslSlot<T>;
104
- /**
105
- * Represents a value that is available at resolution time.
106
- */
107
- type Eventual<T> = T | WgslSlot<T>;
108
- type EventualGetter = <T>(value: Eventual<T>) => T;
109
- type InlineResolve = (get: EventualGetter) => Wgsl;
110
- interface WgslResolvableSlot<T extends Wgsl> extends WgslResolvable, WgslSlot<T> {
111
- $name(label: string): WgslResolvableSlot<T>;
112
- }
113
- type SlotValuePair<T> = [WgslSlot<T>, T];
114
- interface WgslAllocatable<TData extends AnyWgslData = AnyWgslData> {
115
- /**
116
- * The data type this allocatable was constructed with.
117
- * It informs the size and format of data in both JS and
118
- * binary.
119
- */
120
- readonly dataType: TData;
121
- readonly initial?: Parsed<TData> | WgslPlum<Parsed<TData>> | undefined;
122
- readonly flags: GPUBufferUsageFlags;
123
- }
124
- interface WgslBindable<TData extends AnyWgslData = AnyWgslData, TUsage extends BufferUsage = BufferUsage> extends WgslResolvable {
125
- readonly allocatable: WgslAllocatable<TData>;
126
- readonly usage: TUsage;
127
- }
128
- type BufferUsage = 'uniform' | 'readonly_storage' | 'mutable_storage';
129
- interface WgslData<TInner> extends ISchema<TInner>, WgslResolvable {
130
- readonly byteAlignment: number;
131
- readonly size: number;
132
- }
133
- type AnyWgslData = WgslData<unknown>;
134
- interface WgslPointer<TScope extends 'function', TInner extends AnyWgslData> {
135
- readonly scope: TScope;
136
- readonly pointsTo: TInner;
137
- }
138
- /**
139
- * A virtual representation of a WGSL value.
140
- */
141
- type WgslValue<TDataType> = {
142
- readonly __dataType: TDataType;
143
- };
144
- type AnyWgslPointer = WgslPointer<'function', AnyWgslData>;
145
- type WgslFnArgument = AnyWgslPointer | AnyWgslData;
146
- declare function isPointer(value: AnyWgslPointer | AnyWgslData): value is AnyWgslPointer;
147
-
148
- export { type AnyWgslData as A, type BufferUsage as B, type ExtractPlumValue as E, type InlineResolve as I, type ResolutionCtx as R, type SlotValuePair as S, type Unsubscribe as U, type WgslResolvable as W, type WgslSlot as a, type WgslPlum as b, type WgslSettable as c, type WgslAllocatable as d, type Wgsl as e, type WgslBindable as f, type Eventual as g, type WgslFnArgument as h, type WgslValue as i, WgslIdentifier as j, type WgslResolvableSlot as k, plumFromEvent as l, isResolvable as m, isWgsl as n, isSlot as o, plum as p, type EventualGetter as q, type WgslData as r, type WgslPointer as s, type AnyWgslPointer as t, isPointer as u };