typegpu 0.0.0-alpha.3 → 0.0.0-alpha.4

Sign up to get free protection for your applications and to get access to all the features.
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 };