@wonderyard/vivarium 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/README.md.local +93 -0
- package/dist/automaton/types.d.ts +56 -0
- package/dist/automaton/types.js +1 -0
- package/dist/blueprint/base-blueprint.d.ts +10 -0
- package/dist/blueprint/base-blueprint.js +29 -0
- package/dist/blueprint/helpers.d.ts +9 -0
- package/dist/blueprint/helpers.js +32 -0
- package/dist/blueprint/ref-blueprint.d.ts +24 -0
- package/dist/blueprint/ref-blueprint.js +42 -0
- package/dist/blueprint/rule-blueprint.d.ts +18 -0
- package/dist/blueprint/rule-blueprint.js +7 -0
- package/dist/blueprint/types.d.ts +8 -0
- package/dist/blueprint/types.js +1 -0
- package/dist/blueprint/utils.d.ts +4 -0
- package/dist/blueprint/utils.js +5 -0
- package/dist/blueprint/vivarium-blueprint.d.ts +18 -0
- package/dist/blueprint/vivarium-blueprint.js +47 -0
- package/dist/common/constants.d.ts +64 -0
- package/dist/common/constants.js +14 -0
- package/dist/common/utils.d.ts +1 -0
- package/dist/common/utils.js +53 -0
- package/dist/compiler-CEYR17Vv.js +527 -0
- package/dist/constants-Ry69vZz5.js +2565 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +6 -0
- package/dist/rule-blueprint-Df5BKApy.js +50 -0
- package/dist/vivarium/vivarium.d.ts +3 -0
- package/dist/vivarium/vivarium.js +7 -0
- package/dist/vivarium/vivarium.test.d.ts +1 -0
- package/dist/webgpu/compiler.d.ts +27 -0
- package/dist/webgpu/compiler.js +6 -0
- package/dist/webgpu/setup.d.ts +11 -0
- package/dist/webgpu/setup.js +4348 -0
- package/package.json +40 -0
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import { V as x, p as M, T as j, m as we, a as q, i as d, J as ge, t as R, h as ke, y as D, f as ee, u as G, w as te, z as Ne, b as L, c as Ce, l as je, d as Pe, e as Ae, g as $e, K as xe, $ as C, o as y, j as be, k as Te, q as Ee, r as Ie, _ as J, s as re, v as ae, Y as V, x as oe, W as ie, B as Se, D as Me, E as Ue, L as se, F as Ge, P as ue, G as Le, H as _, I as ze, M as We, N as Fe, O as Be, Q as Re, R as F, U as De, X as Ke, Z as K, a0 as ne, a1 as le, a2 as ce, a3 as N, a4 as H, a5 as pe, a6 as k } from "./constants-Ry69vZz5.js";
|
|
2
|
+
import { colorToABGR as Ye } from "./common/utils.js";
|
|
3
|
+
var Je = { block: 0, binaryExpr: 1, assignmentExpr: 2, logicalExpr: 3, unaryExpr: 4, numericLiteral: 5, call: 6, memberAccess: 7, indexAccess: 8, return: 10, if: 11, let: 12, const: 13, for: 14, while: 15, continue: 16, break: 17, arrayExpr: 100, preUpdate: 101, postUpdate: 102, stringLiteral: 103, objectExpr: 104 }, Ve = { identifier: "i", destructuredObject: "d" }, He = 1;
|
|
4
|
+
const Ze = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5
|
+
__proto__: null,
|
|
6
|
+
FORMAT_VERSION: He,
|
|
7
|
+
FuncParameterType: Ve,
|
|
8
|
+
NodeTypeCatalog: Je
|
|
9
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
10
|
+
var W = (e, t) => {
|
|
11
|
+
let a = t - 1, n = ~a;
|
|
12
|
+
return (e & a) === 0 ? e : (e & n) + t;
|
|
13
|
+
}, Qe = { f32: 4, f16: 2, i32: 4, u32: 4, u16: 2, vec2f: 8, vec2h: 4, vec2i: 8, vec2u: 8, vec3f: 16, vec3h: 8, vec3i: 16, vec3u: 16, vec4f: 16, vec4h: 8, vec4i: 16, vec4u: 16, mat2x2f: 8, mat3x3f: 16, mat4x4f: 16, atomic: 4 };
|
|
14
|
+
function Xe(e) {
|
|
15
|
+
let t = e?.type, a = Qe[t];
|
|
16
|
+
if (a !== void 0) return a;
|
|
17
|
+
if (D(e)) return Object.values(e.propTypes).map(b).reduce((n, o) => n > o ? n : o);
|
|
18
|
+
if (G(e)) return b(e.elementType);
|
|
19
|
+
if (ee(e)) {
|
|
20
|
+
let n = Object.values(e.propTypes)[0];
|
|
21
|
+
return n ? L(n) ?? 1 : 1;
|
|
22
|
+
}
|
|
23
|
+
if (te(e)) return L(e.elementType) ?? 1;
|
|
24
|
+
if (M(e) || j(e)) return L(e) ?? b(e.inner);
|
|
25
|
+
if (Ce.has(t)) return 1;
|
|
26
|
+
throw new Error(`Cannot determine alignment of data: ${JSON.stringify(e)}`);
|
|
27
|
+
}
|
|
28
|
+
function qe(e) {
|
|
29
|
+
if (ee(e)) {
|
|
30
|
+
let t = Object.values(e.propTypes)[0];
|
|
31
|
+
return t ? z(t) : 1;
|
|
32
|
+
}
|
|
33
|
+
return te(e) ? z(e.elementType) : j(e) ? L(e) ?? z(e.inner) : L(e) ?? 1;
|
|
34
|
+
}
|
|
35
|
+
var fe = /* @__PURE__ */ new WeakMap(), de = /* @__PURE__ */ new WeakMap();
|
|
36
|
+
function b(e) {
|
|
37
|
+
let t = fe.get(e);
|
|
38
|
+
return t === void 0 && (t = Xe(e), fe.set(e, t)), t;
|
|
39
|
+
}
|
|
40
|
+
function z(e) {
|
|
41
|
+
let t = de.get(e);
|
|
42
|
+
return t === void 0 && (t = qe(e), de.set(e, t)), t;
|
|
43
|
+
}
|
|
44
|
+
function bt(e) {
|
|
45
|
+
return b(e);
|
|
46
|
+
}
|
|
47
|
+
var et = { f32: 4, f16: 2, i32: 4, u32: 4, u16: 2, vec2f: 8, vec2h: 4, vec2i: 8, vec2u: 8, vec3f: 12, vec3h: 6, vec3i: 12, vec3u: 12, vec4f: 16, vec4h: 8, vec4i: 16, vec4u: 16, mat2x2f: 16, mat3x3f: 48, mat4x4f: 64, uint8: 1, uint8x2: 2, uint8x4: 4, sint8: 1, sint8x2: 2, sint8x4: 4, unorm8: 1, unorm8x2: 2, unorm8x4: 4, snorm8: 1, snorm8x2: 2, snorm8x4: 4, uint16: 2, uint16x2: 4, uint16x4: 8, sint16: 2, sint16x2: 4, sint16x4: 8, unorm16: 2, unorm16x2: 4, unorm16x4: 8, snorm16: 2, snorm16x2: 4, snorm16x4: 8, float16: 2, float16x2: 4, float16x4: 8, float32: 4, float32x2: 8, float32x3: 12, float32x4: 16, uint32: 4, uint32x2: 8, uint32x3: 12, uint32x4: 16, sint32: 4, sint32x2: 8, sint32x3: 12, sint32x4: 16, "unorm10-10-10-2": 4, "unorm8x4-bgra": 4, atomic: 4 };
|
|
48
|
+
function tt(e) {
|
|
49
|
+
let t = 0, a = e.propTypes;
|
|
50
|
+
for (let n of Object.values(a)) {
|
|
51
|
+
if (Number.isNaN(t)) throw new Error("Only the last property of a struct can be unbounded");
|
|
52
|
+
if (t = W(t, b(n)), t += T(n), Number.isNaN(t) && n.type !== "array") throw new Error("Cannot nest unbounded struct within another struct");
|
|
53
|
+
}
|
|
54
|
+
return W(t, b(e));
|
|
55
|
+
}
|
|
56
|
+
function nt(e) {
|
|
57
|
+
let t = 0, a = e.propTypes;
|
|
58
|
+
for (let n of Object.values(a)) {
|
|
59
|
+
let o = z(n);
|
|
60
|
+
t = W(t, o), t += T(n);
|
|
61
|
+
}
|
|
62
|
+
return t;
|
|
63
|
+
}
|
|
64
|
+
function rt(e) {
|
|
65
|
+
let t = et[e?.type];
|
|
66
|
+
if (t !== void 0) return t;
|
|
67
|
+
if (D(e)) return tt(e);
|
|
68
|
+
if (ee(e)) return nt(e);
|
|
69
|
+
if (G(e)) {
|
|
70
|
+
if (e.elementCount === 0) return Number.NaN;
|
|
71
|
+
let a = b(e.elementType);
|
|
72
|
+
return W(T(e.elementType), a) * e.elementCount;
|
|
73
|
+
}
|
|
74
|
+
if (te(e)) {
|
|
75
|
+
let a = z(e.elementType);
|
|
76
|
+
return W(T(e.elementType), a) * e.elementCount;
|
|
77
|
+
}
|
|
78
|
+
if (M(e) || j(e)) return Ne(e) ?? T(e.inner);
|
|
79
|
+
throw new Error(`Cannot determine size of data: ${e}`);
|
|
80
|
+
}
|
|
81
|
+
var me = /* @__PURE__ */ new WeakMap();
|
|
82
|
+
function T(e) {
|
|
83
|
+
let t = me.get(e);
|
|
84
|
+
return t === void 0 && (t = rt(e), me.set(e, t)), t;
|
|
85
|
+
}
|
|
86
|
+
function Tt(e) {
|
|
87
|
+
return T(e);
|
|
88
|
+
}
|
|
89
|
+
function S(e, t) {
|
|
90
|
+
if (t === void 0) return (n) => S(e, n);
|
|
91
|
+
let a = (n) => {
|
|
92
|
+
if (n && n.length !== t) throw new Error(`Array schema of ${t} elements of type ${e.type} called with ${n.length} argument(s).`);
|
|
93
|
+
return Array.from({ length: t }, (o, r) => q(e, n?.[r]));
|
|
94
|
+
};
|
|
95
|
+
if (Object.setPrototypeOf(a, at), Number.isNaN(T(e))) throw new Error("Cannot nest runtime sized arrays.");
|
|
96
|
+
if (a.elementType = e, !Number.isInteger(t) || t < 0) throw new Error(`Cannot create array schema with invalid element count: ${t}.`);
|
|
97
|
+
return a.elementCount = t, a;
|
|
98
|
+
}
|
|
99
|
+
var at = { [d]: !0, type: "array", toString() {
|
|
100
|
+
return `arrayOf(${this.elementType}, ${this.elementCount})`;
|
|
101
|
+
} }, { NodeTypeCatalog: p } = Ze, ot = ["==", "!=", "<", "<=", ">", ">=", "<<", ">>", "+", "-", "*", "/", "%", "|", "^", "&", "&&", "||"], it = ["&&", "||", "==", "!=", "<", "<=", ">", ">="], st = ["vec2f", "vec3f", "vec4f", "vec2h", "vec3h", "vec4h", "vec2i", "vec3i", "vec4i", "vec2u", "vec3u", "vec4u", "mat2x2f", "mat3x3f", "mat4x4f"], Z = { add: Ie, sub: Ee, mul: Te, div: be };
|
|
102
|
+
function he(e, t, a) {
|
|
103
|
+
return a ? it.includes(t) ? C : t === "=" ? a : e : t === "!" || t === "~" ? C : e;
|
|
104
|
+
}
|
|
105
|
+
function ut(e) {
|
|
106
|
+
throw new Error(`'${JSON.stringify(e)}' was not handled by the WGSL generator.`);
|
|
107
|
+
}
|
|
108
|
+
function A(e, [t, a]) {
|
|
109
|
+
e.pushBlockScope();
|
|
110
|
+
try {
|
|
111
|
+
e.indent();
|
|
112
|
+
let n = a.map((o) => X(e, o)).join(`
|
|
113
|
+
`);
|
|
114
|
+
return e.dedent(), `{
|
|
115
|
+
${n}
|
|
116
|
+
${e.pre}}`;
|
|
117
|
+
} finally {
|
|
118
|
+
e.popBlockScope();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function lt(e, t, a) {
|
|
122
|
+
return e.defineVariable(t, a);
|
|
123
|
+
}
|
|
124
|
+
function Q(e, t) {
|
|
125
|
+
let a = e.getById(t);
|
|
126
|
+
if (!a) throw new Error(`Identifier ${t} not found`);
|
|
127
|
+
return a;
|
|
128
|
+
}
|
|
129
|
+
function O(e, t, a) {
|
|
130
|
+
let n = e.expectedType;
|
|
131
|
+
e.expectedType = a;
|
|
132
|
+
try {
|
|
133
|
+
let o = g(e, t);
|
|
134
|
+
return xe(e, o, a);
|
|
135
|
+
} finally {
|
|
136
|
+
e.expectedType = n;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
var ct = { "+": Ie[d].gpuImpl, "-": Ee[d].gpuImpl, "*": Te[d].gpuImpl, "/": be[d].gpuImpl };
|
|
140
|
+
function g(e, t) {
|
|
141
|
+
if (typeof t == "string") return Q(e, t);
|
|
142
|
+
if (typeof t == "boolean") return y(t ? "true" : "false", C);
|
|
143
|
+
if (t[0] === p.logicalExpr || t[0] === p.binaryExpr || t[0] === p.assignmentExpr) {
|
|
144
|
+
let [a, n, o, r] = t, s = g(e, n), i = g(e, r), l = ct[o];
|
|
145
|
+
if (l) return l(s, i);
|
|
146
|
+
let f = t[0] === p.assignmentExpr ? s.dataType.type === "ptr" ? [s.dataType.inner] : [s.dataType] : void 0, m = J({ ctx: e, values: [s, i], restrictTo: f }), [h, E] = m || [s, i], u = e.resolve(h.value), c = e.resolve(E.value), $ = he(h.dataType, o, E.dataType);
|
|
147
|
+
return y(ot.includes(o) ? `(${u} ${o} ${c})` : `${u} ${o} ${c}`, $);
|
|
148
|
+
}
|
|
149
|
+
if (t[0] === p.postUpdate) {
|
|
150
|
+
let [a, n, o] = t, r = g(e, o), s = e.resolve(r.value);
|
|
151
|
+
return y(`${s}${n}`, r.dataType);
|
|
152
|
+
}
|
|
153
|
+
if (t[0] === p.unaryExpr) {
|
|
154
|
+
let [a, n, o] = t, r = g(e, o), s = e.resolve(r.value), i = he(r.dataType, n);
|
|
155
|
+
return y(`${n}${s}`, i);
|
|
156
|
+
}
|
|
157
|
+
if (t[0] === p.memberAccess) {
|
|
158
|
+
let [a, n, o] = t, r = g(e, n);
|
|
159
|
+
if (st.includes(r.dataType.type) && o in Z) return { value: new ae(o, r, Z[o][d].gpuImpl), dataType: re };
|
|
160
|
+
if (r.dataType.type === "unknown") {
|
|
161
|
+
let s = r.value[o];
|
|
162
|
+
return V(s);
|
|
163
|
+
}
|
|
164
|
+
return oe(r.dataType) ? y(`(*${e.resolve(r.value)}).${o}`, ie(r.dataType.inner, o)) : G(r.dataType) && o === "length" ? r.dataType.elementCount === 0 ? y(`arrayLength(&${e.resolve(r.value)})`, x) : y(String(r.dataType.elementCount), Re) : Se(r.dataType) && o === "columns" ? y(r.value, r.dataType) : Me(r.dataType) && Ue(r.value) ? V(r.value[o]) : y(`${e.resolve(r.value)}.${o}`, ie(r.dataType, o));
|
|
165
|
+
}
|
|
166
|
+
if (t[0] === p.indexAccess) {
|
|
167
|
+
let [a, n, o] = t, r = g(e, n), s = g(e, o), i = e.resolve(r.value), l = e.resolve(s.value);
|
|
168
|
+
if (r.dataType.type === "unknown") {
|
|
169
|
+
if (Array.isArray(o) && o[0] === p.numericLiteral) return V(r.value[o[1]]);
|
|
170
|
+
throw new Error(`Cannot index value ${i} of unknown type with index ${l}`);
|
|
171
|
+
}
|
|
172
|
+
return oe(r.dataType) ? y(`(*${i})[${l}]`, se(r.dataType.inner)) : y(`${i}[${l}]`, Ge(r.dataType) ? se(r.dataType) : re);
|
|
173
|
+
}
|
|
174
|
+
if (t[0] === p.numericLiteral) {
|
|
175
|
+
let a = typeof t[1] == "string" ? ue(Le(t[1])) : ue(t[1]);
|
|
176
|
+
if (!a) throw new Error(`Invalid numeric literal ${t[1]}`);
|
|
177
|
+
return a;
|
|
178
|
+
}
|
|
179
|
+
if (t[0] === p.call) {
|
|
180
|
+
let [a, n, o] = t, r = g(e, n);
|
|
181
|
+
if (D(r.value) || G(r.value)) {
|
|
182
|
+
if (o.length > 1) throw new _("Array and struct schemas should always be called with at most 1 argument");
|
|
183
|
+
if (!o[0]) return y(`${e.resolve(r.value)}()`, r.value);
|
|
184
|
+
let i = O(e, o[0], r.value);
|
|
185
|
+
return y(e.resolve(i.value, r.value), r.value);
|
|
186
|
+
}
|
|
187
|
+
if (r.value instanceof ae) {
|
|
188
|
+
if (!o[0]) throw new _(`An infix operator '${r.value.name}' was called without any arguments`);
|
|
189
|
+
let i = g(e, o[0]);
|
|
190
|
+
return r.value.operator(r.value.lhs, i);
|
|
191
|
+
}
|
|
192
|
+
if (!ze(r.value)) throw new Error(`Function ${String(r.value)} ${R(r.value)} has not been created using TypeGPU APIs. Did you mean to wrap the function with tgpu.fn(args, return)(...) ?`);
|
|
193
|
+
let s = r.value[d]?.argConversionHint ?? "keep";
|
|
194
|
+
try {
|
|
195
|
+
let i;
|
|
196
|
+
if (Array.isArray(s)) i = o.map((f, m) => {
|
|
197
|
+
let h = s[m];
|
|
198
|
+
if (!h) throw new _(`Function '${R(r.value)}' was called with too many arguments`);
|
|
199
|
+
return O(e, f, h);
|
|
200
|
+
});
|
|
201
|
+
else {
|
|
202
|
+
let f = o.map((m) => g(e, m));
|
|
203
|
+
s === "keep" ? i = f : s === "unify" ? i = J({ ctx: e, values: f }) ?? f : i = s(...f).map((m, h) => [m, f[h]]).map(([m, h]) => xe(e, h, m));
|
|
204
|
+
}
|
|
205
|
+
let l = r.value(...i);
|
|
206
|
+
if (!We(l)) throw new Error("Functions running in codegen mode must return snippets");
|
|
207
|
+
return l;
|
|
208
|
+
} catch (i) {
|
|
209
|
+
throw new Fe(i, [{ toString: () => R(r.value) }]);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (t[0] === p.objectExpr) {
|
|
213
|
+
let a = t[1], n = e.expectedType;
|
|
214
|
+
if (!n || !D(n)) throw new _(`No target type could be inferred for object with keys [${Object.keys(a).join(", ")}], please wrap the object in the corresponding schema.`);
|
|
215
|
+
let o = Object.fromEntries(Object.entries(n.propTypes).map(([s, i]) => {
|
|
216
|
+
let l = a[s];
|
|
217
|
+
if (l === void 0) throw new _(`Missing property ${s} in object literal for struct ${n}`);
|
|
218
|
+
let f = O(e, l, i);
|
|
219
|
+
return [s, f];
|
|
220
|
+
})), r = Be(e, n, o);
|
|
221
|
+
return y(`${e.resolve(n)}(${r.map((s) => e.resolve(s.value)).join(", ")})`, n);
|
|
222
|
+
}
|
|
223
|
+
if (t[0] === p.arrayExpr) {
|
|
224
|
+
let [a, n] = t, o = e.expectedType, r, s;
|
|
225
|
+
if (G(o)) {
|
|
226
|
+
if (r = o.elementType, s = n.map((f) => O(e, f, r)), s.length !== o.elementCount) throw new _(`Cannot create value of type '${o}' from an array of length: ${s.length}`);
|
|
227
|
+
} else {
|
|
228
|
+
let f = n.map((h) => g(e, h));
|
|
229
|
+
if (f.length === 0) throw new _("Cannot infer the type of an empty array literal.");
|
|
230
|
+
let m = J({ ctx: e, values: f });
|
|
231
|
+
if (!m) throw new _("The given values cannot be automatically converted to a common type. Consider wrapping the array in an appropriate schema");
|
|
232
|
+
s = m, r = $e(s[0]?.dataType);
|
|
233
|
+
}
|
|
234
|
+
let i = `array<${e.resolve(r)}, ${s.length}>`, l = s.map((f) => e.resolve(f.value));
|
|
235
|
+
return y(`${i}(${l.join(", ")})`, S(r, s.length));
|
|
236
|
+
}
|
|
237
|
+
if (t[0] === p.stringLiteral) throw new Error("Cannot use string literals in TGSL.");
|
|
238
|
+
if (t[0] === p.preUpdate) throw new Error("Cannot use pre-updates in TGSL.");
|
|
239
|
+
ut(t);
|
|
240
|
+
}
|
|
241
|
+
function B(e) {
|
|
242
|
+
return typeof e != "object" || e[0] !== p.block ? [p.block, [e]] : e;
|
|
243
|
+
}
|
|
244
|
+
function X(e, t) {
|
|
245
|
+
if (typeof t == "string") return `${e.pre}${e.resolve(Q(e, t).value)};`;
|
|
246
|
+
if (typeof t == "boolean") return `${e.pre}${t ? "true" : "false"};`;
|
|
247
|
+
if (t[0] === p.return) {
|
|
248
|
+
let a = t[1], n = a !== void 0 ? e.resolve(O(e, a, e.topFunctionReturnType).value) : void 0;
|
|
249
|
+
return n ? `${e.pre}return ${n};` : `${e.pre}return;`;
|
|
250
|
+
}
|
|
251
|
+
if (t[0] === p.if) {
|
|
252
|
+
let [a, n, o, r] = t, s = e.resolve(O(e, n, C).value), i = A(e, B(o)), l = r ? A(e, B(r)) : void 0;
|
|
253
|
+
return l ? `${e.pre}if (${s}) ${i}
|
|
254
|
+
${e.pre}else ${l}` : `${e.pre}if (${s}) ${i}`;
|
|
255
|
+
}
|
|
256
|
+
if (t[0] === p.let || t[0] === p.const) {
|
|
257
|
+
let [a, n, o] = t, r = o !== void 0 ? g(e, o) : void 0;
|
|
258
|
+
if (!r) throw new Error(`Cannot create variable '${n}' without an initial value.`);
|
|
259
|
+
if (ge(r.dataType)) throw new Error(`Cannot create variable '${n}' with loose data type.`);
|
|
260
|
+
lt(e, n, $e(r.dataType));
|
|
261
|
+
let s = e.resolve(Q(e, n).value);
|
|
262
|
+
return `${e.pre}var ${s} = ${e.resolve(r.value)};`;
|
|
263
|
+
}
|
|
264
|
+
if (t[0] === p.block) return A(e, t);
|
|
265
|
+
if (t[0] === p.for) {
|
|
266
|
+
let [a, n, o, r, s] = t, [i, l, f] = e.withResetIndentLevel(() => [n ? X(e, n) : void 0, o ? g(e, o) : void 0, r ? X(e, r) : void 0]), m = i ? i.slice(0, -1) : "", h = o ? O(e, o, C) : void 0, E = h ? e.resolve(h.value) : "", u = f ? f.slice(0, -1) : "", c = A(e, B(s));
|
|
267
|
+
return `${e.pre}for (${m}; ${E}; ${u}) ${c}`;
|
|
268
|
+
}
|
|
269
|
+
if (t[0] === p.while) {
|
|
270
|
+
let [a, n, o] = t, r = O(e, n, C), s = e.resolve(r.value), i = A(e, B(o));
|
|
271
|
+
return `${e.pre}while (${s}) ${i}`;
|
|
272
|
+
}
|
|
273
|
+
return t[0] === p.continue ? `${e.pre}continue;` : t[0] === p.break ? `${e.pre}break;` : `${e.pre}${e.resolve(g(e, t).value)};`;
|
|
274
|
+
}
|
|
275
|
+
function Et(e, t) {
|
|
276
|
+
return A(e, t);
|
|
277
|
+
}
|
|
278
|
+
function pt(e, t) {
|
|
279
|
+
if (t === void 0) return (n) => pt(e, n);
|
|
280
|
+
let a = (n) => {
|
|
281
|
+
if (n && n.length !== t) throw new Error(`Disarray schema of ${t} elements of type ${e.type} called with ${n.length} argument(s).`);
|
|
282
|
+
return Array.from({ length: t }, (o, r) => q(e, n?.[r]));
|
|
283
|
+
};
|
|
284
|
+
if (Object.setPrototypeOf(a, ft), a.elementType = e, !Number.isInteger(t) || t < 0) throw new Error(`Cannot create disarray schema with invalid element count: ${t}.`);
|
|
285
|
+
return a.elementCount = t, a;
|
|
286
|
+
}
|
|
287
|
+
var ft = { [d]: !0, type: "disarray", toString() {
|
|
288
|
+
return `disarrayOf(${this.elementType}, ${this.elementCount})`;
|
|
289
|
+
} };
|
|
290
|
+
function It(e) {
|
|
291
|
+
let t = (a) => Object.fromEntries(Object.entries(e).map(([n, o]) => [n, q(o, a?.[n])]));
|
|
292
|
+
return Object.setPrototypeOf(t, dt), t.propTypes = e, t;
|
|
293
|
+
}
|
|
294
|
+
var dt = { [d]: !0, type: "unstruct", $name(e) {
|
|
295
|
+
return ke(this, e), this;
|
|
296
|
+
}, toString() {
|
|
297
|
+
return `unstruct:${R(this) ?? "<unnamed>"}`;
|
|
298
|
+
} };
|
|
299
|
+
function _t(e) {
|
|
300
|
+
return new mt(e);
|
|
301
|
+
}
|
|
302
|
+
var mt = class {
|
|
303
|
+
constructor(e) {
|
|
304
|
+
this.inner = e;
|
|
305
|
+
}
|
|
306
|
+
[d] = !0;
|
|
307
|
+
type = "atomic";
|
|
308
|
+
};
|
|
309
|
+
function U(e, t) {
|
|
310
|
+
return M(e) ? new ve(e.inner, [t, ...e.attribs]) : j(e) ? new ye(e.inner, [t, ...e.attribs]) : ge(e) ? new ye(e, [t]) : new ve(e, [t]);
|
|
311
|
+
}
|
|
312
|
+
function Ot(e, t) {
|
|
313
|
+
return U(t, { [d]: !0, type: "@align", params: [e] });
|
|
314
|
+
}
|
|
315
|
+
function kt(e, t) {
|
|
316
|
+
return U(t, { [d]: !0, type: "@size", params: [e] });
|
|
317
|
+
}
|
|
318
|
+
function Nt(e, t) {
|
|
319
|
+
return U(t, { [d]: !0, type: "@location", params: [e] });
|
|
320
|
+
}
|
|
321
|
+
function Ct(e, t) {
|
|
322
|
+
return U(t, { [d]: !0, type: "@interpolate", params: [e] });
|
|
323
|
+
}
|
|
324
|
+
function jt(e) {
|
|
325
|
+
if (!ht(e)) throw new Error("The @invariant attribute must only be applied to the position built-in value.");
|
|
326
|
+
let t = M(e) || j(e) ? e.attribs.find(we) : void 0;
|
|
327
|
+
if (!t || t.params[0] !== "position") throw new Error("The @invariant attribute must only be applied to the position built-in value.");
|
|
328
|
+
return U(e, { [d]: !0, type: "@invariant", params: [] });
|
|
329
|
+
}
|
|
330
|
+
function ht(e) {
|
|
331
|
+
return (M(e) || j(e)) && e.attribs.find(we) !== void 0;
|
|
332
|
+
}
|
|
333
|
+
function Pt(e) {
|
|
334
|
+
return !M(e) && !j(e) ? "" : e.attribs.map((t) => t.params.length === 0 ? `${t.type} ` : `${t.type}(${t.params.join(", ")}) `).join("");
|
|
335
|
+
}
|
|
336
|
+
var _e = class {
|
|
337
|
+
constructor(e, t) {
|
|
338
|
+
this.inner = e, this.attribs = t;
|
|
339
|
+
let a = t.find(je)?.params[0], n = t.find(Pe)?.params[0];
|
|
340
|
+
if (a !== void 0) {
|
|
341
|
+
if (a <= 0) throw new Error(`Custom data alignment must be a positive number, got: ${a}.`);
|
|
342
|
+
if (Math.log2(a) % 1 !== 0) throw new Error(`Alignment has to be a power of 2, got: ${a}.`);
|
|
343
|
+
if (Ae(this.inner) && a % b(this.inner) !== 0) throw new Error(`Custom alignment has to be a multiple of the standard data alignment. Got: ${a}, expected multiple of: ${b(this.inner)}.`);
|
|
344
|
+
}
|
|
345
|
+
if (n !== void 0) {
|
|
346
|
+
if (n < T(this.inner)) throw new Error(`Custom data size cannot be smaller then the standard data size. Got: ${n}, expected at least: ${T(this.inner)}.`);
|
|
347
|
+
if (n <= 0) throw new Error(`Custom data size must be a positive number. Got: ${n}.`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
[d] = !0;
|
|
351
|
+
}, ve = class extends _e {
|
|
352
|
+
[d] = !0;
|
|
353
|
+
type = "decorated";
|
|
354
|
+
}, ye = class extends _e {
|
|
355
|
+
[d] = !0;
|
|
356
|
+
type = "loose-decorated";
|
|
357
|
+
};
|
|
358
|
+
function w(e, t) {
|
|
359
|
+
return U(e, { [d]: !0, type: "@builtin", params: [t] });
|
|
360
|
+
}
|
|
361
|
+
var At = { vertexIndex: w(x, "vertex_index"), instanceIndex: w(x, "instance_index"), position: w(Ke, "position"), clipDistances: w(S(x, 8), "clip_distances"), frontFacing: w(C, "front_facing"), fragDepth: w(De, "frag_depth"), sampleIndex: w(x, "sample_index"), sampleMask: w(x, "sample_mask"), localInvocationId: w(F, "local_invocation_id"), localInvocationIndex: w(x, "local_invocation_index"), globalInvocationId: w(F, "global_invocation_id"), workgroupId: w(F, "workgroup_id"), numWorkgroups: w(F, "num_workgroups"), subgroupInvocationId: w(x, "subgroup_invocation_id"), subgroupSize: w(x, "subgroup_size") };
|
|
362
|
+
function P(e, t) {
|
|
363
|
+
let a = e.prototype, n = Z[t][d].jsImpl;
|
|
364
|
+
a[t] = function(o) {
|
|
365
|
+
return n(this, o);
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
P(K, "add");
|
|
369
|
+
P(K, "sub");
|
|
370
|
+
P(K, "mul");
|
|
371
|
+
P(K, "div");
|
|
372
|
+
P(ne, "add");
|
|
373
|
+
P(ne, "sub");
|
|
374
|
+
P(ne, "mul");
|
|
375
|
+
const Oe = (e) => {
|
|
376
|
+
if (e.some((t) => t > 31))
|
|
377
|
+
throw console.warn(
|
|
378
|
+
`Elements with an index greater than 31 and extending one or more kinds are not allowed when they are involved in conditions referencing kinds.
|
|
379
|
+
To assign a lower index, move the elements with extensions higher in the definition list or reduce the overall number of elements and kinds.`
|
|
380
|
+
), new Error(
|
|
381
|
+
"Element in condition involving kinds has an index greater than 31"
|
|
382
|
+
);
|
|
383
|
+
}, vt = (e, t, a) => {
|
|
384
|
+
const { elements: n } = a, o = n.findIndex((r) => r.id === e);
|
|
385
|
+
if (o !== -1)
|
|
386
|
+
t.opcode = k.COUNT_ELEMENT, t.checkId = o;
|
|
387
|
+
else {
|
|
388
|
+
const r = n.map((i, l) => ({ ...i, index: l })).filter(
|
|
389
|
+
(i) => i.extensions.some((l) => l === e)
|
|
390
|
+
).map((i) => i.index);
|
|
391
|
+
Oe(r);
|
|
392
|
+
const s = r.reduce((i, l) => (i |= 1 << l, i), 0);
|
|
393
|
+
t.checkId = s, t.opcode = k.COUNT_KIND;
|
|
394
|
+
}
|
|
395
|
+
}, yt = (e, t) => {
|
|
396
|
+
t.opcode = k.COUNT_POINT, t.checkPointOrComparePoint = N(e.x, e.y);
|
|
397
|
+
}, wt = (e, t, a) => {
|
|
398
|
+
const { check: n, count: o } = e;
|
|
399
|
+
if (typeof n > "u")
|
|
400
|
+
throw new Error("condition.check is undefined");
|
|
401
|
+
typeof n == "string" ? vt(n, t, a) : yt(n, t), t.countOrWithId = o.reduce(
|
|
402
|
+
// Packing numbers as positional bits.
|
|
403
|
+
// Example: [2, 3] -> 0b000001100
|
|
404
|
+
(r, s) => (r |= 1 << s, r),
|
|
405
|
+
0
|
|
406
|
+
);
|
|
407
|
+
}, gt = (e, t, a) => {
|
|
408
|
+
const n = e.compare;
|
|
409
|
+
if (typeof n > "u")
|
|
410
|
+
throw new Error("condition.compare is undefined");
|
|
411
|
+
if (typeof e.with > "u")
|
|
412
|
+
throw new Error("condition.with is undefined");
|
|
413
|
+
if (t.checkPointOrComparePoint = N(
|
|
414
|
+
n.x,
|
|
415
|
+
n.y
|
|
416
|
+
), typeof e.with == "string") {
|
|
417
|
+
const o = e.with;
|
|
418
|
+
if (a.elements.some((r) => r.id === o)) {
|
|
419
|
+
t.opcode = k.IS_ELEMENT;
|
|
420
|
+
const r = a.elements.findIndex(
|
|
421
|
+
(s) => s.id === o
|
|
422
|
+
);
|
|
423
|
+
t.countOrWithId = r;
|
|
424
|
+
} else {
|
|
425
|
+
const r = a.elements.map((i, l) => ({ ...i, index: l })).filter(
|
|
426
|
+
(i) => i.extensions.some((l) => l === o)
|
|
427
|
+
).map((i) => i.index);
|
|
428
|
+
Oe(r);
|
|
429
|
+
const s = r.reduce((i, l) => (i |= 1 << l, i), 0);
|
|
430
|
+
t.countOrWithId = s, t.opcode = k.IS_KIND;
|
|
431
|
+
}
|
|
432
|
+
} else
|
|
433
|
+
t.opcode = k.IS_POINT, t.withPoint = N(e.with.x, e.with.y);
|
|
434
|
+
}, St = (e, t) => {
|
|
435
|
+
const { elements: a, rules: n } = t, o = n.filter((u) => u.fromType === "element").reduce(
|
|
436
|
+
(u, c) => {
|
|
437
|
+
const $ = a.findIndex(
|
|
438
|
+
(v) => v.id === c.fromId
|
|
439
|
+
);
|
|
440
|
+
return u[$].push(c), u;
|
|
441
|
+
},
|
|
442
|
+
a.map(() => [])
|
|
443
|
+
), r = n.filter((u) => u.fromType === "kind").reduce((u, c) => (a.forEach(($, v) => {
|
|
444
|
+
$.extensions.includes(c.fromId) && u[v].push(c);
|
|
445
|
+
}), u), o), s = [];
|
|
446
|
+
let i = [];
|
|
447
|
+
const l = /* @__PURE__ */ new Map();
|
|
448
|
+
r.forEach((u) => {
|
|
449
|
+
u.forEach((c, $) => {
|
|
450
|
+
let v, I;
|
|
451
|
+
const Y = `${c.fromId}:${$.toString()}`;
|
|
452
|
+
c.fromType === "kind" && l.has(Y) ? [v, I] = l.get(Y) : (v = i.length, Array.isArray(c.when) ? i = i.concat(c.when) : i = i.concat([c.when]), I = i.length, l.set(Y, [v, I])), s.push({
|
|
453
|
+
...c,
|
|
454
|
+
conditionsStart: v,
|
|
455
|
+
conditionsEnd: I
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
const f = [], m = [], h = [];
|
|
460
|
+
let E = 0;
|
|
461
|
+
return a.forEach((u, c) => {
|
|
462
|
+
const $ = E, v = E + r[c].length;
|
|
463
|
+
E = v;
|
|
464
|
+
const I = le({
|
|
465
|
+
color: Ye(u.color),
|
|
466
|
+
ruleStart: $,
|
|
467
|
+
ruleEnd: v
|
|
468
|
+
});
|
|
469
|
+
f.push(I);
|
|
470
|
+
}), s.forEach((u) => {
|
|
471
|
+
const { conditionsStart: c, conditionsEnd: $ } = u, v = ce({
|
|
472
|
+
toType: H.ELEMENT_ID,
|
|
473
|
+
toId: 0,
|
|
474
|
+
toNeighbor: N(),
|
|
475
|
+
conditionsStart: c,
|
|
476
|
+
conditionsEnd: $,
|
|
477
|
+
accept: u.accept
|
|
478
|
+
});
|
|
479
|
+
if (m.push(v), typeof u.to > "u")
|
|
480
|
+
throw new Error("rule.to is undefined");
|
|
481
|
+
typeof u.to == "string" ? (v.toType = H.ELEMENT_ID, v.toId = a.findIndex((I) => I.id === u.to)) : (v.toType = H.POINT, v.toNeighbor = N(u.to.x, u.to.y));
|
|
482
|
+
}), i.forEach((u) => {
|
|
483
|
+
const c = pe({
|
|
484
|
+
opcode: k.NOOP,
|
|
485
|
+
checkId: 0,
|
|
486
|
+
countOrWithId: 0,
|
|
487
|
+
checkPointOrComparePoint: N(),
|
|
488
|
+
withPoint: N(),
|
|
489
|
+
chance: 0
|
|
490
|
+
});
|
|
491
|
+
h.push(c), u.type === "count" ? wt(u, c, t) : u.type === "is" ? gt(u, c, t) : (c.opcode = k.CHANCE, c.chance = u.ratio.part / u.ratio.whole);
|
|
492
|
+
}), {
|
|
493
|
+
neighborhood: (globalThis.__TYPEGPU_AUTONAME__ ?? ((u) => u))(e.createBuffer(x, t.neighborhood === "cross" ? 4 : 8).$usage("uniform"), "neighborhood"),
|
|
494
|
+
elements: (globalThis.__TYPEGPU_AUTONAME__ ?? ((u) => u))(e.createBuffer(
|
|
495
|
+
S(le, Math.max(a.length, 1)),
|
|
496
|
+
f
|
|
497
|
+
).$usage("storage"), "elements"),
|
|
498
|
+
rules: (globalThis.__TYPEGPU_AUTONAME__ ?? ((u) => u))(e.createBuffer(S(ce, Math.max(s.length, 1)), m).$usage("storage"), "rules"),
|
|
499
|
+
conditions: (globalThis.__TYPEGPU_AUTONAME__ ?? ((u) => u))(e.createBuffer(
|
|
500
|
+
S(pe, Math.max(i.length, 1)),
|
|
501
|
+
h
|
|
502
|
+
).$usage("storage"), "conditions")
|
|
503
|
+
};
|
|
504
|
+
};
|
|
505
|
+
export {
|
|
506
|
+
pt as C,
|
|
507
|
+
Tt as K,
|
|
508
|
+
S as U,
|
|
509
|
+
W as V,
|
|
510
|
+
Pt as Z,
|
|
511
|
+
Ot as a,
|
|
512
|
+
ht as b,
|
|
513
|
+
At as c,
|
|
514
|
+
Et as d,
|
|
515
|
+
b as e,
|
|
516
|
+
z as f,
|
|
517
|
+
St as g,
|
|
518
|
+
T as h,
|
|
519
|
+
bt as j,
|
|
520
|
+
Nt as l,
|
|
521
|
+
_t as o,
|
|
522
|
+
jt as p,
|
|
523
|
+
It as r,
|
|
524
|
+
kt as s,
|
|
525
|
+
Ve as t,
|
|
526
|
+
Ct as u
|
|
527
|
+
};
|