@deck.gl/aggregation-layers 9.0.0-beta.1 → 9.0.0-beta.2

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.
Files changed (41) hide show
  1. package/dist/dist.dev.js +3287 -310
  2. package/dist/es5/heatmap-layer/heatmap-layer-utils.js +0 -15
  3. package/dist/es5/heatmap-layer/heatmap-layer-utils.js.map +1 -1
  4. package/dist/es5/heatmap-layer/heatmap-layer.js +103 -97
  5. package/dist/es5/heatmap-layer/heatmap-layer.js.map +1 -1
  6. package/dist/es5/heatmap-layer/max-vs.glsl.js +1 -1
  7. package/dist/es5/heatmap-layer/triangle-layer-fragment.glsl.js +1 -1
  8. package/dist/es5/heatmap-layer/triangle-layer.js +26 -27
  9. package/dist/es5/heatmap-layer/triangle-layer.js.map +1 -1
  10. package/dist/es5/heatmap-layer/weights-vs.glsl.js +1 -1
  11. package/dist/esm/heatmap-layer/heatmap-layer-utils.js +0 -13
  12. package/dist/esm/heatmap-layer/heatmap-layer-utils.js.map +1 -1
  13. package/dist/esm/heatmap-layer/heatmap-layer.js +99 -87
  14. package/dist/esm/heatmap-layer/heatmap-layer.js.map +1 -1
  15. package/dist/esm/heatmap-layer/max-vs.glsl.js +11 -5
  16. package/dist/esm/heatmap-layer/max-vs.glsl.js.map +1 -1
  17. package/dist/esm/heatmap-layer/triangle-layer-fragment.glsl.js +2 -2
  18. package/dist/esm/heatmap-layer/triangle-layer-fragment.glsl.js.map +1 -1
  19. package/dist/esm/heatmap-layer/triangle-layer.js +21 -23
  20. package/dist/esm/heatmap-layer/triangle-layer.js.map +1 -1
  21. package/dist/esm/heatmap-layer/weights-vs.glsl.js +4 -2
  22. package/dist/esm/heatmap-layer/weights-vs.glsl.js.map +1 -1
  23. package/dist.min.js +85 -75
  24. package/package.json +7 -7
  25. package/src/heatmap-layer/heatmap-layer-utils.ts +0 -23
  26. package/src/heatmap-layer/heatmap-layer.ts +87 -105
  27. package/src/heatmap-layer/max-vs.glsl.ts +11 -5
  28. package/src/heatmap-layer/triangle-layer-fragment.glsl.ts +2 -2
  29. package/src/heatmap-layer/triangle-layer.ts +17 -23
  30. package/src/heatmap-layer/weights-vs.glsl.ts +4 -2
  31. package/typed/heatmap-layer/heatmap-layer-utils.d.ts +0 -9
  32. package/typed/heatmap-layer/heatmap-layer-utils.d.ts.map +1 -1
  33. package/typed/heatmap-layer/heatmap-layer.d.ts +4 -4
  34. package/typed/heatmap-layer/heatmap-layer.d.ts.map +1 -1
  35. package/typed/heatmap-layer/max-vs.glsl.d.ts +1 -1
  36. package/typed/heatmap-layer/max-vs.glsl.d.ts.map +1 -1
  37. package/typed/heatmap-layer/triangle-layer-fragment.glsl.d.ts +1 -1
  38. package/typed/heatmap-layer/triangle-layer.d.ts +10 -2
  39. package/typed/heatmap-layer/triangle-layer.d.ts.map +1 -1
  40. package/typed/heatmap-layer/weights-vs.glsl.d.ts +1 -1
  41. package/typed/heatmap-layer/weights-vs.glsl.d.ts.map +1 -1
package/dist/dist.dev.js CHANGED
@@ -1377,7 +1377,7 @@ ${moduleSource}
1377
1377
  }
1378
1378
  function getShaderName(shader) {
1379
1379
  let defaultName = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "unnamed";
1380
- const SHADER_NAME_REGEXP = /#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/;
1380
+ const SHADER_NAME_REGEXP = /#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/;
1381
1381
  const match = SHADER_NAME_REGEXP.exec(shader);
1382
1382
  return match ? match[1] : defaultName;
1383
1383
  }
@@ -1831,6 +1831,2779 @@ void main() {
1831
1831
  }
1832
1832
  }
1833
1833
 
1834
+ // ../../node_modules/@luma.gl/shadertools/dist/libs/wgsl-reflect/wgsl_reflect.module.js
1835
+ var ParseContext = class {
1836
+ constructor() {
1837
+ this.constants = /* @__PURE__ */ new Map();
1838
+ this.aliases = /* @__PURE__ */ new Map();
1839
+ this.structs = /* @__PURE__ */ new Map();
1840
+ }
1841
+ };
1842
+ var Node = class {
1843
+ constructor() {
1844
+ }
1845
+ get isAstNode() {
1846
+ return true;
1847
+ }
1848
+ get astNodeType() {
1849
+ return "";
1850
+ }
1851
+ evaluate(context) {
1852
+ throw new Error("Cannot evaluate node");
1853
+ }
1854
+ evaluateString(context) {
1855
+ return this.evaluate(context).toString();
1856
+ }
1857
+ };
1858
+ var Statement = class extends Node {
1859
+ constructor() {
1860
+ super();
1861
+ }
1862
+ };
1863
+ var Function = class extends Statement {
1864
+ constructor(name, args, returnType, body) {
1865
+ super();
1866
+ this.name = name;
1867
+ this.args = args;
1868
+ this.returnType = returnType;
1869
+ this.body = body;
1870
+ }
1871
+ get astNodeType() {
1872
+ return "function";
1873
+ }
1874
+ };
1875
+ var StaticAssert = class extends Statement {
1876
+ constructor(expression) {
1877
+ super();
1878
+ this.expression = expression;
1879
+ }
1880
+ get astNodeType() {
1881
+ return "staticAssert";
1882
+ }
1883
+ };
1884
+ var While = class extends Statement {
1885
+ constructor(condition, body) {
1886
+ super();
1887
+ this.condition = condition;
1888
+ this.body = body;
1889
+ }
1890
+ get astNodeType() {
1891
+ return "while";
1892
+ }
1893
+ };
1894
+ var Continuing = class extends Statement {
1895
+ constructor(body) {
1896
+ super();
1897
+ this.body = body;
1898
+ }
1899
+ get astNodeType() {
1900
+ return "continuing";
1901
+ }
1902
+ };
1903
+ var For = class extends Statement {
1904
+ constructor(init, condition, increment, body) {
1905
+ super();
1906
+ this.init = init;
1907
+ this.condition = condition;
1908
+ this.increment = increment;
1909
+ this.body = body;
1910
+ }
1911
+ get astNodeType() {
1912
+ return "for";
1913
+ }
1914
+ };
1915
+ var Var = class extends Statement {
1916
+ constructor(name, type, storage, access, value) {
1917
+ super();
1918
+ this.name = name;
1919
+ this.type = type;
1920
+ this.storage = storage;
1921
+ this.access = access;
1922
+ this.value = value;
1923
+ }
1924
+ get astNodeType() {
1925
+ return "var";
1926
+ }
1927
+ };
1928
+ var Override = class extends Statement {
1929
+ constructor(name, type, value) {
1930
+ super();
1931
+ this.name = name;
1932
+ this.type = type;
1933
+ this.value = value;
1934
+ }
1935
+ get astNodeType() {
1936
+ return "override";
1937
+ }
1938
+ };
1939
+ var Let = class extends Statement {
1940
+ constructor(name, type, storage, access, value) {
1941
+ super();
1942
+ this.name = name;
1943
+ this.type = type;
1944
+ this.storage = storage;
1945
+ this.access = access;
1946
+ this.value = value;
1947
+ }
1948
+ get astNodeType() {
1949
+ return "let";
1950
+ }
1951
+ };
1952
+ var Const = class extends Statement {
1953
+ constructor(name, type, storage, access, value) {
1954
+ super();
1955
+ this.name = name;
1956
+ this.type = type;
1957
+ this.storage = storage;
1958
+ this.access = access;
1959
+ this.value = value;
1960
+ }
1961
+ get astNodeType() {
1962
+ return "const";
1963
+ }
1964
+ evaluate(context) {
1965
+ return this.value.evaluate(context);
1966
+ }
1967
+ };
1968
+ var IncrementOperator;
1969
+ (function(IncrementOperator2) {
1970
+ IncrementOperator2["increment"] = "++";
1971
+ IncrementOperator2["decrement"] = "--";
1972
+ })(IncrementOperator || (IncrementOperator = {}));
1973
+ (function(IncrementOperator2) {
1974
+ function parse(val) {
1975
+ const key = val;
1976
+ if (key == "parse")
1977
+ throw new Error("Invalid value for IncrementOperator");
1978
+ return IncrementOperator2[key];
1979
+ }
1980
+ IncrementOperator2.parse = parse;
1981
+ })(IncrementOperator || (IncrementOperator = {}));
1982
+ var Increment = class extends Statement {
1983
+ constructor(operator, variable) {
1984
+ super();
1985
+ this.operator = operator;
1986
+ this.variable = variable;
1987
+ }
1988
+ get astNodeType() {
1989
+ return "increment";
1990
+ }
1991
+ };
1992
+ var AssignOperator;
1993
+ (function(AssignOperator2) {
1994
+ AssignOperator2["assign"] = "=";
1995
+ AssignOperator2["addAssign"] = "+=";
1996
+ AssignOperator2["subtractAssin"] = "-=";
1997
+ AssignOperator2["multiplyAssign"] = "*=";
1998
+ AssignOperator2["divideAssign"] = "/=";
1999
+ AssignOperator2["moduloAssign"] = "%=";
2000
+ AssignOperator2["andAssign"] = "&=";
2001
+ AssignOperator2["orAssign"] = "|=";
2002
+ AssignOperator2["xorAssign"] = "^=";
2003
+ AssignOperator2["shiftLeftAssign"] = "<<=";
2004
+ AssignOperator2["shiftRightAssign"] = ">>=";
2005
+ })(AssignOperator || (AssignOperator = {}));
2006
+ (function(AssignOperator2) {
2007
+ function parse(val) {
2008
+ const key = val;
2009
+ if (key == "parse")
2010
+ throw new Error("Invalid value for AssignOperator");
2011
+ return AssignOperator2[key];
2012
+ }
2013
+ AssignOperator2.parse = parse;
2014
+ })(AssignOperator || (AssignOperator = {}));
2015
+ var Assign = class extends Statement {
2016
+ constructor(operator, variable, value) {
2017
+ super();
2018
+ this.operator = operator;
2019
+ this.variable = variable;
2020
+ this.value = value;
2021
+ }
2022
+ get astNodeType() {
2023
+ return "assign";
2024
+ }
2025
+ };
2026
+ var Call = class extends Statement {
2027
+ constructor(name, args) {
2028
+ super();
2029
+ this.name = name;
2030
+ this.args = args;
2031
+ }
2032
+ get astNodeType() {
2033
+ return "call";
2034
+ }
2035
+ };
2036
+ var Loop = class extends Statement {
2037
+ constructor(body, continuing) {
2038
+ super();
2039
+ this.body = body;
2040
+ this.continuing = continuing;
2041
+ }
2042
+ get astNodeType() {
2043
+ return "loop";
2044
+ }
2045
+ };
2046
+ var Switch = class extends Statement {
2047
+ constructor(condition, body) {
2048
+ super();
2049
+ this.condition = condition;
2050
+ this.body = body;
2051
+ }
2052
+ get astNodeType() {
2053
+ return "body";
2054
+ }
2055
+ };
2056
+ var If = class extends Statement {
2057
+ constructor(condition, body, elseif, _else) {
2058
+ super();
2059
+ this.condition = condition;
2060
+ this.body = body;
2061
+ this.elseif = elseif;
2062
+ this.else = _else;
2063
+ }
2064
+ get astNodeType() {
2065
+ return "if";
2066
+ }
2067
+ };
2068
+ var Return = class extends Statement {
2069
+ constructor(value) {
2070
+ super();
2071
+ this.value = value;
2072
+ }
2073
+ get astNodeType() {
2074
+ return "return";
2075
+ }
2076
+ };
2077
+ var Enable = class extends Statement {
2078
+ constructor(name) {
2079
+ super();
2080
+ this.name = name;
2081
+ }
2082
+ get astNodeType() {
2083
+ return "enable";
2084
+ }
2085
+ };
2086
+ var Alias = class extends Statement {
2087
+ constructor(name, type) {
2088
+ super();
2089
+ this.name = name;
2090
+ this.type = type;
2091
+ }
2092
+ get astNodeType() {
2093
+ return "alias";
2094
+ }
2095
+ };
2096
+ var Discard = class extends Statement {
2097
+ constructor() {
2098
+ super();
2099
+ }
2100
+ get astNodeType() {
2101
+ return "discard";
2102
+ }
2103
+ };
2104
+ var Break = class extends Statement {
2105
+ constructor() {
2106
+ super();
2107
+ }
2108
+ get astNodeType() {
2109
+ return "break";
2110
+ }
2111
+ };
2112
+ var Continue = class extends Statement {
2113
+ constructor() {
2114
+ super();
2115
+ }
2116
+ get astNodeType() {
2117
+ return "continue";
2118
+ }
2119
+ };
2120
+ var Type = class extends Statement {
2121
+ constructor(name) {
2122
+ super();
2123
+ this.name = name;
2124
+ }
2125
+ get astNodeType() {
2126
+ return "type";
2127
+ }
2128
+ get isStruct() {
2129
+ return false;
2130
+ }
2131
+ get isArray() {
2132
+ return false;
2133
+ }
2134
+ };
2135
+ var Struct = class extends Type {
2136
+ constructor(name, members) {
2137
+ super(name);
2138
+ this.members = members;
2139
+ }
2140
+ get astNodeType() {
2141
+ return "struct";
2142
+ }
2143
+ get isStruct() {
2144
+ return true;
2145
+ }
2146
+ getMemberIndex(name) {
2147
+ for (let i = 0; i < this.members.length; i++) {
2148
+ if (this.members[i].name == name)
2149
+ return i;
2150
+ }
2151
+ return -1;
2152
+ }
2153
+ };
2154
+ var TemplateType = class extends Type {
2155
+ constructor(name, format, access) {
2156
+ super(name);
2157
+ this.format = format;
2158
+ this.access = access;
2159
+ }
2160
+ get astNodeType() {
2161
+ return "template";
2162
+ }
2163
+ };
2164
+ var PointerType = class extends Type {
2165
+ constructor(name, storage, type, access) {
2166
+ super(name);
2167
+ this.storage = storage;
2168
+ this.type = type;
2169
+ this.access = access;
2170
+ }
2171
+ get astNodeType() {
2172
+ return "pointer";
2173
+ }
2174
+ };
2175
+ var ArrayType = class extends Type {
2176
+ constructor(name, attributes, format, count) {
2177
+ super(name);
2178
+ this.attributes = attributes;
2179
+ this.format = format;
2180
+ this.count = count;
2181
+ }
2182
+ get astNodeType() {
2183
+ return "array";
2184
+ }
2185
+ get isArray() {
2186
+ return true;
2187
+ }
2188
+ };
2189
+ var SamplerType = class extends Type {
2190
+ constructor(name, format, access) {
2191
+ super(name);
2192
+ this.format = format;
2193
+ this.access = access;
2194
+ }
2195
+ get astNodeType() {
2196
+ return "sampler";
2197
+ }
2198
+ };
2199
+ var Expression = class extends Node {
2200
+ constructor() {
2201
+ super();
2202
+ }
2203
+ };
2204
+ var StringExpr = class extends Expression {
2205
+ constructor(value) {
2206
+ super();
2207
+ this.value = value;
2208
+ }
2209
+ get astNodeType() {
2210
+ return "stringExpr";
2211
+ }
2212
+ toString() {
2213
+ return this.value;
2214
+ }
2215
+ evaluateString() {
2216
+ return this.value;
2217
+ }
2218
+ };
2219
+ var CreateExpr = class extends Expression {
2220
+ constructor(type, args) {
2221
+ super();
2222
+ this.type = type;
2223
+ this.args = args;
2224
+ }
2225
+ get astNodeType() {
2226
+ return "createExpr";
2227
+ }
2228
+ };
2229
+ var CallExpr = class extends Expression {
2230
+ constructor(name, args) {
2231
+ super();
2232
+ this.name = name;
2233
+ this.args = args;
2234
+ }
2235
+ get astNodeType() {
2236
+ return "callExpr";
2237
+ }
2238
+ evaluate(context) {
2239
+ switch (this.name) {
2240
+ case "abs":
2241
+ return Math.abs(this.args[0].evaluate(context));
2242
+ case "acos":
2243
+ return Math.acos(this.args[0].evaluate(context));
2244
+ case "acosh":
2245
+ return Math.acosh(this.args[0].evaluate(context));
2246
+ case "asin":
2247
+ return Math.asin(this.args[0].evaluate(context));
2248
+ case "asinh":
2249
+ return Math.asinh(this.args[0].evaluate(context));
2250
+ case "atan":
2251
+ return Math.atan(this.args[0].evaluate(context));
2252
+ case "atan2":
2253
+ return Math.atan2(this.args[0].evaluate(context), this.args[1].evaluate(context));
2254
+ case "atanh":
2255
+ return Math.atanh(this.args[0].evaluate(context));
2256
+ case "ceil":
2257
+ return Math.ceil(this.args[0].evaluate(context));
2258
+ case "clamp":
2259
+ return Math.min(Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context)), this.args[2].evaluate(context));
2260
+ case "cos":
2261
+ return Math.cos(this.args[0].evaluate(context));
2262
+ case "degrees":
2263
+ return this.args[0].evaluate(context) * 180 / Math.PI;
2264
+ case "distance":
2265
+ return Math.sqrt(Math.pow(this.args[0].evaluate(context) - this.args[1].evaluate(context), 2));
2266
+ case "dot":
2267
+ case "exp":
2268
+ return Math.exp(this.args[0].evaluate(context));
2269
+ case "exp2":
2270
+ return Math.pow(2, this.args[0].evaluate(context));
2271
+ case "floor":
2272
+ return Math.floor(this.args[0].evaluate(context));
2273
+ case "fma":
2274
+ return this.args[0].evaluate(context) * this.args[1].evaluate(context) + this.args[2].evaluate(context);
2275
+ case "fract":
2276
+ return this.args[0].evaluate(context) - Math.floor(this.args[0].evaluate(context));
2277
+ case "inverseSqrt":
2278
+ return 1 / Math.sqrt(this.args[0].evaluate(context));
2279
+ case "log":
2280
+ return Math.log(this.args[0].evaluate(context));
2281
+ case "log2":
2282
+ return Math.log2(this.args[0].evaluate(context));
2283
+ case "max":
2284
+ return Math.max(this.args[0].evaluate(context), this.args[1].evaluate(context));
2285
+ case "min":
2286
+ return Math.min(this.args[0].evaluate(context), this.args[1].evaluate(context));
2287
+ case "mix":
2288
+ return this.args[0].evaluate(context) * (1 - this.args[2].evaluate(context)) + this.args[1].evaluate(context) * this.args[2].evaluate(context);
2289
+ case "modf":
2290
+ return this.args[0].evaluate(context) - Math.floor(this.args[0].evaluate(context));
2291
+ case "pow":
2292
+ return Math.pow(this.args[0].evaluate(context), this.args[1].evaluate(context));
2293
+ case "radians":
2294
+ return this.args[0].evaluate(context) * Math.PI / 180;
2295
+ case "round":
2296
+ return Math.round(this.args[0].evaluate(context));
2297
+ case "sign":
2298
+ return Math.sign(this.args[0].evaluate(context));
2299
+ case "sin":
2300
+ return Math.sin(this.args[0].evaluate(context));
2301
+ case "sinh":
2302
+ return Math.sinh(this.args[0].evaluate(context));
2303
+ case "saturate":
2304
+ return Math.min(Math.max(this.args[0].evaluate(context), 0), 1);
2305
+ case "smoothstep":
2306
+ return this.args[0].evaluate(context) * this.args[0].evaluate(context) * (3 - 2 * this.args[0].evaluate(context));
2307
+ case "sqrt":
2308
+ return Math.sqrt(this.args[0].evaluate(context));
2309
+ case "step":
2310
+ return this.args[0].evaluate(context) < this.args[1].evaluate(context) ? 0 : 1;
2311
+ case "tan":
2312
+ return Math.tan(this.args[0].evaluate(context));
2313
+ case "tanh":
2314
+ return Math.tanh(this.args[0].evaluate(context));
2315
+ case "trunc":
2316
+ return Math.trunc(this.args[0].evaluate(context));
2317
+ default:
2318
+ throw new Error("Non const function: " + this.name);
2319
+ }
2320
+ }
2321
+ };
2322
+ var VariableExpr = class extends Expression {
2323
+ constructor(name) {
2324
+ super();
2325
+ this.name = name;
2326
+ }
2327
+ get astNodeType() {
2328
+ return "varExpr";
2329
+ }
2330
+ };
2331
+ var ConstExpr = class extends Expression {
2332
+ constructor(name, initializer) {
2333
+ super();
2334
+ this.name = name;
2335
+ this.initializer = initializer;
2336
+ }
2337
+ get astNodeType() {
2338
+ return "constExpr";
2339
+ }
2340
+ evaluate(context) {
2341
+ var _a2, _b;
2342
+ if (this.initializer instanceof CreateExpr) {
2343
+ const property = (_a2 = this.postfix) === null || _a2 === void 0 ? void 0 : _a2.evaluateString(context);
2344
+ const type = (_b = this.initializer.type) === null || _b === void 0 ? void 0 : _b.name;
2345
+ const struct = context.structs.get(type);
2346
+ const memberIndex = struct === null || struct === void 0 ? void 0 : struct.getMemberIndex(property);
2347
+ if (memberIndex != -1) {
2348
+ const value = this.initializer.args[memberIndex].evaluate(context);
2349
+ return value;
2350
+ }
2351
+ console.log(memberIndex);
2352
+ }
2353
+ return this.initializer.evaluate(context);
2354
+ }
2355
+ };
2356
+ var LiteralExpr = class extends Expression {
2357
+ constructor(value) {
2358
+ super();
2359
+ this.value = value;
2360
+ }
2361
+ get astNodeType() {
2362
+ return "literalExpr";
2363
+ }
2364
+ evaluate() {
2365
+ return this.value;
2366
+ }
2367
+ };
2368
+ var BitcastExpr = class extends Expression {
2369
+ constructor(type, value) {
2370
+ super();
2371
+ this.type = type;
2372
+ this.value = value;
2373
+ }
2374
+ get astNodeType() {
2375
+ return "bitcastExpr";
2376
+ }
2377
+ };
2378
+ var TypecastExpr = class extends Expression {
2379
+ constructor(type, args) {
2380
+ super();
2381
+ this.type = type;
2382
+ this.args = args;
2383
+ }
2384
+ get astNodeType() {
2385
+ return "typecastExpr";
2386
+ }
2387
+ evaluate(context) {
2388
+ return this.args[0].evaluate(context);
2389
+ }
2390
+ };
2391
+ var GroupingExpr = class extends Expression {
2392
+ constructor(contents) {
2393
+ super();
2394
+ this.contents = contents;
2395
+ }
2396
+ get astNodeType() {
2397
+ return "groupExpr";
2398
+ }
2399
+ evaluate(context) {
2400
+ return this.contents[0].evaluate(context);
2401
+ }
2402
+ };
2403
+ var Operator = class extends Expression {
2404
+ constructor() {
2405
+ super();
2406
+ }
2407
+ };
2408
+ var UnaryOperator = class extends Operator {
2409
+ constructor(operator, right) {
2410
+ super();
2411
+ this.operator = operator;
2412
+ this.right = right;
2413
+ }
2414
+ get astNodeType() {
2415
+ return "unaryOp";
2416
+ }
2417
+ evaluate(context) {
2418
+ switch (this.operator) {
2419
+ case "+":
2420
+ return this.right.evaluate(context);
2421
+ case "-":
2422
+ return -this.right.evaluate(context);
2423
+ case "!":
2424
+ return this.right.evaluate(context) ? 0 : 1;
2425
+ case "~":
2426
+ return ~this.right.evaluate(context);
2427
+ default:
2428
+ throw new Error("Unknown unary operator: " + this.operator);
2429
+ }
2430
+ }
2431
+ };
2432
+ var BinaryOperator = class extends Operator {
2433
+ constructor(operator, left, right) {
2434
+ super();
2435
+ this.operator = operator;
2436
+ this.left = left;
2437
+ this.right = right;
2438
+ }
2439
+ get astNodeType() {
2440
+ return "binaryOp";
2441
+ }
2442
+ evaluate(context) {
2443
+ switch (this.operator) {
2444
+ case "+":
2445
+ return this.left.evaluate(context) + this.right.evaluate(context);
2446
+ case "-":
2447
+ return this.left.evaluate(context) - this.right.evaluate(context);
2448
+ case "*":
2449
+ return this.left.evaluate(context) * this.right.evaluate(context);
2450
+ case "/":
2451
+ return this.left.evaluate(context) / this.right.evaluate(context);
2452
+ case "%":
2453
+ return this.left.evaluate(context) % this.right.evaluate(context);
2454
+ case "==":
2455
+ return this.left.evaluate(context) == this.right.evaluate(context) ? 1 : 0;
2456
+ case "!=":
2457
+ return this.left.evaluate(context) != this.right.evaluate(context) ? 1 : 0;
2458
+ case "<":
2459
+ return this.left.evaluate(context) < this.right.evaluate(context) ? 1 : 0;
2460
+ case ">":
2461
+ return this.left.evaluate(context) > this.right.evaluate(context) ? 1 : 0;
2462
+ case "<=":
2463
+ return this.left.evaluate(context) <= this.right.evaluate(context) ? 1 : 0;
2464
+ case ">=":
2465
+ return this.left.evaluate(context) >= this.right.evaluate(context) ? 1 : 0;
2466
+ case "&&":
2467
+ return this.left.evaluate(context) && this.right.evaluate(context) ? 1 : 0;
2468
+ case "||":
2469
+ return this.left.evaluate(context) || this.right.evaluate(context) ? 1 : 0;
2470
+ default:
2471
+ throw new Error(`Unknown operator ${this.operator}`);
2472
+ }
2473
+ }
2474
+ };
2475
+ var SwitchCase = class extends Node {
2476
+ constructor() {
2477
+ super();
2478
+ }
2479
+ };
2480
+ var Case = class extends SwitchCase {
2481
+ constructor(selector, body) {
2482
+ super();
2483
+ this.selector = selector;
2484
+ this.body = body;
2485
+ }
2486
+ get astNodeType() {
2487
+ return "case";
2488
+ }
2489
+ };
2490
+ var Default = class extends SwitchCase {
2491
+ constructor(body) {
2492
+ super();
2493
+ this.body = body;
2494
+ }
2495
+ get astNodeType() {
2496
+ return "default";
2497
+ }
2498
+ };
2499
+ var Argument = class extends Node {
2500
+ constructor(name, type, attributes) {
2501
+ super();
2502
+ this.name = name;
2503
+ this.type = type;
2504
+ this.attributes = attributes;
2505
+ }
2506
+ get astNodeType() {
2507
+ return "argument";
2508
+ }
2509
+ };
2510
+ var ElseIf = class extends Node {
2511
+ constructor(condition, body) {
2512
+ super();
2513
+ this.condition = condition;
2514
+ this.body = body;
2515
+ }
2516
+ get astNodeType() {
2517
+ return "elseif";
2518
+ }
2519
+ };
2520
+ var Member = class extends Node {
2521
+ constructor(name, type, attributes) {
2522
+ super();
2523
+ this.name = name;
2524
+ this.type = type;
2525
+ this.attributes = attributes;
2526
+ }
2527
+ get astNodeType() {
2528
+ return "member";
2529
+ }
2530
+ };
2531
+ var Attribute = class extends Node {
2532
+ constructor(name, value) {
2533
+ super();
2534
+ this.name = name;
2535
+ this.value = value;
2536
+ }
2537
+ get astNodeType() {
2538
+ return "attribute";
2539
+ }
2540
+ };
2541
+ var _a;
2542
+ var TokenClass;
2543
+ (function(TokenClass2) {
2544
+ TokenClass2[TokenClass2["token"] = 0] = "token";
2545
+ TokenClass2[TokenClass2["keyword"] = 1] = "keyword";
2546
+ TokenClass2[TokenClass2["reserved"] = 2] = "reserved";
2547
+ })(TokenClass || (TokenClass = {}));
2548
+ var TokenType = class {
2549
+ constructor(name, type, rule) {
2550
+ this.name = name;
2551
+ this.type = type;
2552
+ this.rule = rule;
2553
+ }
2554
+ toString() {
2555
+ return this.name;
2556
+ }
2557
+ };
2558
+ var TokenTypes = class {
2559
+ };
2560
+ _a = TokenTypes;
2561
+ TokenTypes.none = new TokenType("", TokenClass.reserved, "");
2562
+ TokenTypes.eof = new TokenType("EOF", TokenClass.token, "");
2563
+ TokenTypes.reserved = {
2564
+ asm: new TokenType("asm", TokenClass.reserved, "asm"),
2565
+ bf16: new TokenType("bf16", TokenClass.reserved, "bf16"),
2566
+ do: new TokenType("do", TokenClass.reserved, "do"),
2567
+ enum: new TokenType("enum", TokenClass.reserved, "enum"),
2568
+ f16: new TokenType("f16", TokenClass.reserved, "f16"),
2569
+ f64: new TokenType("f64", TokenClass.reserved, "f64"),
2570
+ handle: new TokenType("handle", TokenClass.reserved, "handle"),
2571
+ i8: new TokenType("i8", TokenClass.reserved, "i8"),
2572
+ i16: new TokenType("i16", TokenClass.reserved, "i16"),
2573
+ i64: new TokenType("i64", TokenClass.reserved, "i64"),
2574
+ mat: new TokenType("mat", TokenClass.reserved, "mat"),
2575
+ premerge: new TokenType("premerge", TokenClass.reserved, "premerge"),
2576
+ regardless: new TokenType("regardless", TokenClass.reserved, "regardless"),
2577
+ typedef: new TokenType("typedef", TokenClass.reserved, "typedef"),
2578
+ u8: new TokenType("u8", TokenClass.reserved, "u8"),
2579
+ u16: new TokenType("u16", TokenClass.reserved, "u16"),
2580
+ u64: new TokenType("u64", TokenClass.reserved, "u64"),
2581
+ unless: new TokenType("unless", TokenClass.reserved, "unless"),
2582
+ using: new TokenType("using", TokenClass.reserved, "using"),
2583
+ vec: new TokenType("vec", TokenClass.reserved, "vec"),
2584
+ void: new TokenType("void", TokenClass.reserved, "void")
2585
+ };
2586
+ TokenTypes.keywords = {
2587
+ array: new TokenType("array", TokenClass.keyword, "array"),
2588
+ atomic: new TokenType("atomic", TokenClass.keyword, "atomic"),
2589
+ bool: new TokenType("bool", TokenClass.keyword, "bool"),
2590
+ f32: new TokenType("f32", TokenClass.keyword, "f32"),
2591
+ i32: new TokenType("i32", TokenClass.keyword, "i32"),
2592
+ mat2x2: new TokenType("mat2x2", TokenClass.keyword, "mat2x2"),
2593
+ mat2x3: new TokenType("mat2x3", TokenClass.keyword, "mat2x3"),
2594
+ mat2x4: new TokenType("mat2x4", TokenClass.keyword, "mat2x4"),
2595
+ mat3x2: new TokenType("mat3x2", TokenClass.keyword, "mat3x2"),
2596
+ mat3x3: new TokenType("mat3x3", TokenClass.keyword, "mat3x3"),
2597
+ mat3x4: new TokenType("mat3x4", TokenClass.keyword, "mat3x4"),
2598
+ mat4x2: new TokenType("mat4x2", TokenClass.keyword, "mat4x2"),
2599
+ mat4x3: new TokenType("mat4x3", TokenClass.keyword, "mat4x3"),
2600
+ mat4x4: new TokenType("mat4x4", TokenClass.keyword, "mat4x4"),
2601
+ ptr: new TokenType("ptr", TokenClass.keyword, "ptr"),
2602
+ sampler: new TokenType("sampler", TokenClass.keyword, "sampler"),
2603
+ sampler_comparison: new TokenType("sampler_comparison", TokenClass.keyword, "sampler_comparison"),
2604
+ struct: new TokenType("struct", TokenClass.keyword, "struct"),
2605
+ texture_1d: new TokenType("texture_1d", TokenClass.keyword, "texture_1d"),
2606
+ texture_2d: new TokenType("texture_2d", TokenClass.keyword, "texture_2d"),
2607
+ texture_2d_array: new TokenType("texture_2d_array", TokenClass.keyword, "texture_2d_array"),
2608
+ texture_3d: new TokenType("texture_3d", TokenClass.keyword, "texture_3d"),
2609
+ texture_cube: new TokenType("texture_cube", TokenClass.keyword, "texture_cube"),
2610
+ texture_cube_array: new TokenType("texture_cube_array", TokenClass.keyword, "texture_cube_array"),
2611
+ texture_multisampled_2d: new TokenType("texture_multisampled_2d", TokenClass.keyword, "texture_multisampled_2d"),
2612
+ texture_storage_1d: new TokenType("texture_storage_1d", TokenClass.keyword, "texture_storage_1d"),
2613
+ texture_storage_2d: new TokenType("texture_storage_2d", TokenClass.keyword, "texture_storage_2d"),
2614
+ texture_storage_2d_array: new TokenType("texture_storage_2d_array", TokenClass.keyword, "texture_storage_2d_array"),
2615
+ texture_storage_3d: new TokenType("texture_storage_3d", TokenClass.keyword, "texture_storage_3d"),
2616
+ texture_depth_2d: new TokenType("texture_depth_2d", TokenClass.keyword, "texture_depth_2d"),
2617
+ texture_depth_2d_array: new TokenType("texture_depth_2d_array", TokenClass.keyword, "texture_depth_2d_array"),
2618
+ texture_depth_cube: new TokenType("texture_depth_cube", TokenClass.keyword, "texture_depth_cube"),
2619
+ texture_depth_cube_array: new TokenType("texture_depth_cube_array", TokenClass.keyword, "texture_depth_cube_array"),
2620
+ texture_depth_multisampled_2d: new TokenType("texture_depth_multisampled_2d", TokenClass.keyword, "texture_depth_multisampled_2d"),
2621
+ texture_external: new TokenType("texture_external", TokenClass.keyword, "texture_external"),
2622
+ u32: new TokenType("u32", TokenClass.keyword, "u32"),
2623
+ vec2: new TokenType("vec2", TokenClass.keyword, "vec2"),
2624
+ vec3: new TokenType("vec3", TokenClass.keyword, "vec3"),
2625
+ vec4: new TokenType("vec4", TokenClass.keyword, "vec4"),
2626
+ bitcast: new TokenType("bitcast", TokenClass.keyword, "bitcast"),
2627
+ block: new TokenType("block", TokenClass.keyword, "block"),
2628
+ break: new TokenType("break", TokenClass.keyword, "break"),
2629
+ case: new TokenType("case", TokenClass.keyword, "case"),
2630
+ continue: new TokenType("continue", TokenClass.keyword, "continue"),
2631
+ continuing: new TokenType("continuing", TokenClass.keyword, "continuing"),
2632
+ default: new TokenType("default", TokenClass.keyword, "default"),
2633
+ discard: new TokenType("discard", TokenClass.keyword, "discard"),
2634
+ else: new TokenType("else", TokenClass.keyword, "else"),
2635
+ enable: new TokenType("enable", TokenClass.keyword, "enable"),
2636
+ fallthrough: new TokenType("fallthrough", TokenClass.keyword, "fallthrough"),
2637
+ false: new TokenType("false", TokenClass.keyword, "false"),
2638
+ fn: new TokenType("fn", TokenClass.keyword, "fn"),
2639
+ for: new TokenType("for", TokenClass.keyword, "for"),
2640
+ function: new TokenType("function", TokenClass.keyword, "function"),
2641
+ if: new TokenType("if", TokenClass.keyword, "if"),
2642
+ let: new TokenType("let", TokenClass.keyword, "let"),
2643
+ const: new TokenType("const", TokenClass.keyword, "const"),
2644
+ loop: new TokenType("loop", TokenClass.keyword, "loop"),
2645
+ while: new TokenType("while", TokenClass.keyword, "while"),
2646
+ private: new TokenType("private", TokenClass.keyword, "private"),
2647
+ read: new TokenType("read", TokenClass.keyword, "read"),
2648
+ read_write: new TokenType("read_write", TokenClass.keyword, "read_write"),
2649
+ return: new TokenType("return", TokenClass.keyword, "return"),
2650
+ storage: new TokenType("storage", TokenClass.keyword, "storage"),
2651
+ switch: new TokenType("switch", TokenClass.keyword, "switch"),
2652
+ true: new TokenType("true", TokenClass.keyword, "true"),
2653
+ alias: new TokenType("alias", TokenClass.keyword, "alias"),
2654
+ type: new TokenType("type", TokenClass.keyword, "type"),
2655
+ uniform: new TokenType("uniform", TokenClass.keyword, "uniform"),
2656
+ var: new TokenType("var", TokenClass.keyword, "var"),
2657
+ override: new TokenType("override", TokenClass.keyword, "override"),
2658
+ workgroup: new TokenType("workgroup", TokenClass.keyword, "workgroup"),
2659
+ write: new TokenType("write", TokenClass.keyword, "write"),
2660
+ r8unorm: new TokenType("r8unorm", TokenClass.keyword, "r8unorm"),
2661
+ r8snorm: new TokenType("r8snorm", TokenClass.keyword, "r8snorm"),
2662
+ r8uint: new TokenType("r8uint", TokenClass.keyword, "r8uint"),
2663
+ r8sint: new TokenType("r8sint", TokenClass.keyword, "r8sint"),
2664
+ r16uint: new TokenType("r16uint", TokenClass.keyword, "r16uint"),
2665
+ r16sint: new TokenType("r16sint", TokenClass.keyword, "r16sint"),
2666
+ r16float: new TokenType("r16float", TokenClass.keyword, "r16float"),
2667
+ rg8unorm: new TokenType("rg8unorm", TokenClass.keyword, "rg8unorm"),
2668
+ rg8snorm: new TokenType("rg8snorm", TokenClass.keyword, "rg8snorm"),
2669
+ rg8uint: new TokenType("rg8uint", TokenClass.keyword, "rg8uint"),
2670
+ rg8sint: new TokenType("rg8sint", TokenClass.keyword, "rg8sint"),
2671
+ r32uint: new TokenType("r32uint", TokenClass.keyword, "r32uint"),
2672
+ r32sint: new TokenType("r32sint", TokenClass.keyword, "r32sint"),
2673
+ r32float: new TokenType("r32float", TokenClass.keyword, "r32float"),
2674
+ rg16uint: new TokenType("rg16uint", TokenClass.keyword, "rg16uint"),
2675
+ rg16sint: new TokenType("rg16sint", TokenClass.keyword, "rg16sint"),
2676
+ rg16float: new TokenType("rg16float", TokenClass.keyword, "rg16float"),
2677
+ rgba8unorm: new TokenType("rgba8unorm", TokenClass.keyword, "rgba8unorm"),
2678
+ rgba8unorm_srgb: new TokenType("rgba8unorm_srgb", TokenClass.keyword, "rgba8unorm_srgb"),
2679
+ rgba8snorm: new TokenType("rgba8snorm", TokenClass.keyword, "rgba8snorm"),
2680
+ rgba8uint: new TokenType("rgba8uint", TokenClass.keyword, "rgba8uint"),
2681
+ rgba8sint: new TokenType("rgba8sint", TokenClass.keyword, "rgba8sint"),
2682
+ bgra8unorm: new TokenType("bgra8unorm", TokenClass.keyword, "bgra8unorm"),
2683
+ bgra8unorm_srgb: new TokenType("bgra8unorm_srgb", TokenClass.keyword, "bgra8unorm_srgb"),
2684
+ rgb10a2unorm: new TokenType("rgb10a2unorm", TokenClass.keyword, "rgb10a2unorm"),
2685
+ rg11b10float: new TokenType("rg11b10float", TokenClass.keyword, "rg11b10float"),
2686
+ rg32uint: new TokenType("rg32uint", TokenClass.keyword, "rg32uint"),
2687
+ rg32sint: new TokenType("rg32sint", TokenClass.keyword, "rg32sint"),
2688
+ rg32float: new TokenType("rg32float", TokenClass.keyword, "rg32float"),
2689
+ rgba16uint: new TokenType("rgba16uint", TokenClass.keyword, "rgba16uint"),
2690
+ rgba16sint: new TokenType("rgba16sint", TokenClass.keyword, "rgba16sint"),
2691
+ rgba16float: new TokenType("rgba16float", TokenClass.keyword, "rgba16float"),
2692
+ rgba32uint: new TokenType("rgba32uint", TokenClass.keyword, "rgba32uint"),
2693
+ rgba32sint: new TokenType("rgba32sint", TokenClass.keyword, "rgba32sint"),
2694
+ rgba32float: new TokenType("rgba32float", TokenClass.keyword, "rgba32float"),
2695
+ static_assert: new TokenType("static_assert", TokenClass.keyword, "static_assert")
2696
+ };
2697
+ TokenTypes.tokens = {
2698
+ decimal_float_literal: new TokenType("decimal_float_literal", TokenClass.token, /((-?[0-9]*\.[0-9]+|-?[0-9]+\.[0-9]*)((e|E)(\+|-)?[0-9]+)?f?)|(-?[0-9]+(e|E)(\+|-)?[0-9]+f?)|([0-9]+f)/),
2699
+ hex_float_literal: new TokenType("hex_float_literal", TokenClass.token, /-?0x((([0-9a-fA-F]*\.[0-9a-fA-F]+|[0-9a-fA-F]+\.[0-9a-fA-F]*)((p|P)(\+|-)?[0-9]+f?)?)|([0-9a-fA-F]+(p|P)(\+|-)?[0-9]+f?))/),
2700
+ int_literal: new TokenType("int_literal", TokenClass.token, /-?0x[0-9a-fA-F]+|0i?|-?[1-9][0-9]*i?/),
2701
+ uint_literal: new TokenType("uint_literal", TokenClass.token, /0x[0-9a-fA-F]+u|0u|[1-9][0-9]*u/),
2702
+ ident: new TokenType("ident", TokenClass.token, /[a-zA-Z][0-9a-zA-Z_]*/),
2703
+ and: new TokenType("and", TokenClass.token, "&"),
2704
+ and_and: new TokenType("and_and", TokenClass.token, "&&"),
2705
+ arrow: new TokenType("arrow ", TokenClass.token, "->"),
2706
+ attr: new TokenType("attr", TokenClass.token, "@"),
2707
+ attr_left: new TokenType("attr_left", TokenClass.token, "[["),
2708
+ attr_right: new TokenType("attr_right", TokenClass.token, "]]"),
2709
+ forward_slash: new TokenType("forward_slash", TokenClass.token, "/"),
2710
+ bang: new TokenType("bang", TokenClass.token, "!"),
2711
+ bracket_left: new TokenType("bracket_left", TokenClass.token, "["),
2712
+ bracket_right: new TokenType("bracket_right", TokenClass.token, "]"),
2713
+ brace_left: new TokenType("brace_left", TokenClass.token, "{"),
2714
+ brace_right: new TokenType("brace_right", TokenClass.token, "}"),
2715
+ colon: new TokenType("colon", TokenClass.token, ":"),
2716
+ comma: new TokenType("comma", TokenClass.token, ","),
2717
+ equal: new TokenType("equal", TokenClass.token, "="),
2718
+ equal_equal: new TokenType("equal_equal", TokenClass.token, "=="),
2719
+ not_equal: new TokenType("not_equal", TokenClass.token, "!="),
2720
+ greater_than: new TokenType("greater_than", TokenClass.token, ">"),
2721
+ greater_than_equal: new TokenType("greater_than_equal", TokenClass.token, ">="),
2722
+ shift_right: new TokenType("shift_right", TokenClass.token, ">>"),
2723
+ less_than: new TokenType("less_than", TokenClass.token, "<"),
2724
+ less_than_equal: new TokenType("less_than_equal", TokenClass.token, "<="),
2725
+ shift_left: new TokenType("shift_left", TokenClass.token, "<<"),
2726
+ modulo: new TokenType("modulo", TokenClass.token, "%"),
2727
+ minus: new TokenType("minus", TokenClass.token, "-"),
2728
+ minus_minus: new TokenType("minus_minus", TokenClass.token, "--"),
2729
+ period: new TokenType("period", TokenClass.token, "."),
2730
+ plus: new TokenType("plus", TokenClass.token, "+"),
2731
+ plus_plus: new TokenType("plus_plus", TokenClass.token, "++"),
2732
+ or: new TokenType("or", TokenClass.token, "|"),
2733
+ or_or: new TokenType("or_or", TokenClass.token, "||"),
2734
+ paren_left: new TokenType("paren_left", TokenClass.token, "("),
2735
+ paren_right: new TokenType("paren_right", TokenClass.token, ")"),
2736
+ semicolon: new TokenType("semicolon", TokenClass.token, ";"),
2737
+ star: new TokenType("star", TokenClass.token, "*"),
2738
+ tilde: new TokenType("tilde", TokenClass.token, "~"),
2739
+ underscore: new TokenType("underscore", TokenClass.token, "_"),
2740
+ xor: new TokenType("xor", TokenClass.token, "^"),
2741
+ plus_equal: new TokenType("plus_equal", TokenClass.token, "+="),
2742
+ minus_equal: new TokenType("minus_equal", TokenClass.token, "-="),
2743
+ times_equal: new TokenType("times_equal", TokenClass.token, "*="),
2744
+ division_equal: new TokenType("division_equal", TokenClass.token, "/="),
2745
+ modulo_equal: new TokenType("modulo_equal", TokenClass.token, "%="),
2746
+ and_equal: new TokenType("and_equal", TokenClass.token, "&="),
2747
+ or_equal: new TokenType("or_equal", TokenClass.token, "|="),
2748
+ xor_equal: new TokenType("xor_equal", TokenClass.token, "^="),
2749
+ shift_right_equal: new TokenType("shift_right_equal", TokenClass.token, ">>="),
2750
+ shift_left_equal: new TokenType("shift_left_equal", TokenClass.token, "<<=")
2751
+ };
2752
+ TokenTypes.storage_class = [_a.keywords.function, _a.keywords.private, _a.keywords.workgroup, _a.keywords.uniform, _a.keywords.storage];
2753
+ TokenTypes.access_mode = [_a.keywords.read, _a.keywords.write, _a.keywords.read_write];
2754
+ TokenTypes.sampler_type = [_a.keywords.sampler, _a.keywords.sampler_comparison];
2755
+ TokenTypes.sampled_texture_type = [_a.keywords.texture_1d, _a.keywords.texture_2d, _a.keywords.texture_2d_array, _a.keywords.texture_3d, _a.keywords.texture_cube, _a.keywords.texture_cube_array];
2756
+ TokenTypes.multisampled_texture_type = [_a.keywords.texture_multisampled_2d];
2757
+ TokenTypes.storage_texture_type = [_a.keywords.texture_storage_1d, _a.keywords.texture_storage_2d, _a.keywords.texture_storage_2d_array, _a.keywords.texture_storage_3d];
2758
+ TokenTypes.depth_texture_type = [_a.keywords.texture_depth_2d, _a.keywords.texture_depth_2d_array, _a.keywords.texture_depth_cube, _a.keywords.texture_depth_cube_array, _a.keywords.texture_depth_multisampled_2d];
2759
+ TokenTypes.texture_external_type = [_a.keywords.texture_external];
2760
+ TokenTypes.any_texture_type = [..._a.sampled_texture_type, ..._a.multisampled_texture_type, ..._a.storage_texture_type, ..._a.depth_texture_type, ..._a.texture_external_type];
2761
+ TokenTypes.texel_format = [_a.keywords.r8unorm, _a.keywords.r8snorm, _a.keywords.r8uint, _a.keywords.r8sint, _a.keywords.r16uint, _a.keywords.r16sint, _a.keywords.r16float, _a.keywords.rg8unorm, _a.keywords.rg8snorm, _a.keywords.rg8uint, _a.keywords.rg8sint, _a.keywords.r32uint, _a.keywords.r32sint, _a.keywords.r32float, _a.keywords.rg16uint, _a.keywords.rg16sint, _a.keywords.rg16float, _a.keywords.rgba8unorm, _a.keywords.rgba8unorm_srgb, _a.keywords.rgba8snorm, _a.keywords.rgba8uint, _a.keywords.rgba8sint, _a.keywords.bgra8unorm, _a.keywords.bgra8unorm_srgb, _a.keywords.rgb10a2unorm, _a.keywords.rg11b10float, _a.keywords.rg32uint, _a.keywords.rg32sint, _a.keywords.rg32float, _a.keywords.rgba16uint, _a.keywords.rgba16sint, _a.keywords.rgba16float, _a.keywords.rgba32uint, _a.keywords.rgba32sint, _a.keywords.rgba32float];
2762
+ TokenTypes.const_literal = [_a.tokens.int_literal, _a.tokens.uint_literal, _a.tokens.decimal_float_literal, _a.tokens.hex_float_literal, _a.keywords.true, _a.keywords.false];
2763
+ TokenTypes.literal_or_ident = [_a.tokens.ident, _a.tokens.int_literal, _a.tokens.uint_literal, _a.tokens.decimal_float_literal, _a.tokens.hex_float_literal];
2764
+ TokenTypes.element_count_expression = [_a.tokens.int_literal, _a.tokens.uint_literal, _a.tokens.ident];
2765
+ TokenTypes.template_types = [_a.keywords.vec2, _a.keywords.vec3, _a.keywords.vec4, _a.keywords.mat2x2, _a.keywords.mat2x3, _a.keywords.mat2x4, _a.keywords.mat3x2, _a.keywords.mat3x3, _a.keywords.mat3x4, _a.keywords.mat4x2, _a.keywords.mat4x3, _a.keywords.mat4x4, _a.keywords.atomic, _a.keywords.bitcast, ..._a.any_texture_type];
2766
+ TokenTypes.attribute_name = [_a.tokens.ident, _a.keywords.block];
2767
+ TokenTypes.assignment_operators = [_a.tokens.equal, _a.tokens.plus_equal, _a.tokens.minus_equal, _a.tokens.times_equal, _a.tokens.division_equal, _a.tokens.modulo_equal, _a.tokens.and_equal, _a.tokens.or_equal, _a.tokens.xor_equal, _a.tokens.shift_right_equal, _a.tokens.shift_left_equal];
2768
+ TokenTypes.increment_operators = [_a.tokens.plus_plus, _a.tokens.minus_minus];
2769
+ var Token = class {
2770
+ constructor(type, lexeme, line) {
2771
+ this.type = type;
2772
+ this.lexeme = lexeme;
2773
+ this.line = line;
2774
+ }
2775
+ toString() {
2776
+ return this.lexeme;
2777
+ }
2778
+ isTemplateType() {
2779
+ return TokenTypes.template_types.indexOf(this.type) != -1;
2780
+ }
2781
+ isArrayType() {
2782
+ return this.type == TokenTypes.keywords.array;
2783
+ }
2784
+ isArrayOrTemplateType() {
2785
+ return this.isArrayType() || this.isTemplateType();
2786
+ }
2787
+ };
2788
+ var WgslScanner = class {
2789
+ constructor(source) {
2790
+ this._tokens = [];
2791
+ this._start = 0;
2792
+ this._current = 0;
2793
+ this._line = 1;
2794
+ this._source = source !== null && source !== void 0 ? source : "";
2795
+ }
2796
+ scanTokens() {
2797
+ while (!this._isAtEnd()) {
2798
+ this._start = this._current;
2799
+ if (!this.scanToken())
2800
+ throw `Invalid syntax at line ${this._line}`;
2801
+ }
2802
+ this._tokens.push(new Token(TokenTypes.eof, "", this._line));
2803
+ return this._tokens;
2804
+ }
2805
+ scanToken() {
2806
+ let lexeme = this._advance();
2807
+ if (lexeme == "\n") {
2808
+ this._line++;
2809
+ return true;
2810
+ }
2811
+ if (this._isWhitespace(lexeme)) {
2812
+ return true;
2813
+ }
2814
+ if (lexeme == "/") {
2815
+ if (this._peekAhead() == "/") {
2816
+ while (lexeme != "\n") {
2817
+ if (this._isAtEnd())
2818
+ return true;
2819
+ lexeme = this._advance();
2820
+ }
2821
+ this._line++;
2822
+ return true;
2823
+ } else if (this._peekAhead() == "*") {
2824
+ this._advance();
2825
+ let commentLevel = 1;
2826
+ while (commentLevel > 0) {
2827
+ if (this._isAtEnd())
2828
+ return true;
2829
+ lexeme = this._advance();
2830
+ if (lexeme == "\n") {
2831
+ this._line++;
2832
+ } else if (lexeme == "*") {
2833
+ if (this._peekAhead() == "/") {
2834
+ this._advance();
2835
+ commentLevel--;
2836
+ if (commentLevel == 0) {
2837
+ return true;
2838
+ }
2839
+ }
2840
+ } else if (lexeme == "/") {
2841
+ if (this._peekAhead() == "*") {
2842
+ this._advance();
2843
+ commentLevel++;
2844
+ }
2845
+ }
2846
+ }
2847
+ return true;
2848
+ }
2849
+ }
2850
+ let matchType = TokenTypes.none;
2851
+ for (; ; ) {
2852
+ let matchedType = this._findType(lexeme);
2853
+ const nextLexeme = this._peekAhead();
2854
+ if (lexeme == ">" && (nextLexeme == ">" || nextLexeme == "=")) {
2855
+ let foundLessThan = false;
2856
+ let ti = this._tokens.length - 1;
2857
+ for (let count = 0; count < 5 && ti >= 0; ++count, --ti) {
2858
+ if (this._tokens[ti].type === TokenTypes.tokens.less_than) {
2859
+ if (ti > 0 && this._tokens[ti - 1].isArrayOrTemplateType()) {
2860
+ foundLessThan = true;
2861
+ }
2862
+ break;
2863
+ }
2864
+ }
2865
+ if (foundLessThan) {
2866
+ this._addToken(matchedType);
2867
+ return true;
2868
+ }
2869
+ }
2870
+ if (matchedType === TokenTypes.none) {
2871
+ let lookAheadLexeme = lexeme;
2872
+ let lookAhead = 0;
2873
+ const maxLookAhead = 2;
2874
+ for (let li = 0; li < maxLookAhead; ++li) {
2875
+ lookAheadLexeme += this._peekAhead(li);
2876
+ matchedType = this._findType(lookAheadLexeme);
2877
+ if (matchedType !== TokenTypes.none) {
2878
+ lookAhead = li;
2879
+ break;
2880
+ }
2881
+ }
2882
+ if (matchedType === TokenTypes.none) {
2883
+ if (matchType === TokenTypes.none)
2884
+ return false;
2885
+ this._current--;
2886
+ this._addToken(matchType);
2887
+ return true;
2888
+ }
2889
+ lexeme = lookAheadLexeme;
2890
+ this._current += lookAhead + 1;
2891
+ }
2892
+ matchType = matchedType;
2893
+ if (this._isAtEnd())
2894
+ break;
2895
+ lexeme += this._advance();
2896
+ }
2897
+ if (matchType === TokenTypes.none)
2898
+ return false;
2899
+ this._addToken(matchType);
2900
+ return true;
2901
+ }
2902
+ _findType(lexeme) {
2903
+ for (const name in TokenTypes.keywords) {
2904
+ const type = TokenTypes.keywords[name];
2905
+ if (this._match(lexeme, type.rule)) {
2906
+ return type;
2907
+ }
2908
+ }
2909
+ for (const name in TokenTypes.tokens) {
2910
+ const type = TokenTypes.tokens[name];
2911
+ if (this._match(lexeme, type.rule)) {
2912
+ return type;
2913
+ }
2914
+ }
2915
+ return TokenTypes.none;
2916
+ }
2917
+ _match(lexeme, rule) {
2918
+ if (typeof rule === "string") {
2919
+ if (rule == lexeme) {
2920
+ return true;
2921
+ }
2922
+ } else {
2923
+ const match = rule.exec(lexeme);
2924
+ if (match && match.index == 0 && match[0] == lexeme)
2925
+ return true;
2926
+ }
2927
+ return false;
2928
+ }
2929
+ _isAtEnd() {
2930
+ return this._current >= this._source.length;
2931
+ }
2932
+ _isWhitespace(c) {
2933
+ return c == " " || c == " " || c == "\r";
2934
+ }
2935
+ _advance() {
2936
+ let amount = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
2937
+ let c = this._source[this._current];
2938
+ amount = amount || 0;
2939
+ amount++;
2940
+ this._current += amount;
2941
+ return c;
2942
+ }
2943
+ _peekAhead() {
2944
+ let offset = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
2945
+ offset = offset || 0;
2946
+ if (this._current + offset >= this._source.length)
2947
+ return "\0";
2948
+ return this._source[this._current + offset];
2949
+ }
2950
+ _addToken(type) {
2951
+ const text = this._source.substring(this._start, this._current);
2952
+ this._tokens.push(new Token(type, text, this._line));
2953
+ }
2954
+ };
2955
+ var WgslParser = class {
2956
+ constructor() {
2957
+ this._tokens = [];
2958
+ this._current = 0;
2959
+ this._context = new ParseContext();
2960
+ }
2961
+ parse(tokensOrCode) {
2962
+ this._initialize(tokensOrCode);
2963
+ let statements = [];
2964
+ while (!this._isAtEnd()) {
2965
+ const statement = this._global_decl_or_directive();
2966
+ if (!statement)
2967
+ break;
2968
+ statements.push(statement);
2969
+ }
2970
+ return statements;
2971
+ }
2972
+ _initialize(tokensOrCode) {
2973
+ if (tokensOrCode) {
2974
+ if (typeof tokensOrCode == "string") {
2975
+ const scanner = new WgslScanner(tokensOrCode);
2976
+ this._tokens = scanner.scanTokens();
2977
+ } else {
2978
+ this._tokens = tokensOrCode;
2979
+ }
2980
+ } else {
2981
+ this._tokens = [];
2982
+ }
2983
+ this._current = 0;
2984
+ }
2985
+ _error(token, message2) {
2986
+ console.error(token, message2);
2987
+ return {
2988
+ token,
2989
+ message: message2,
2990
+ toString: function() {
2991
+ return `${message2}`;
2992
+ }
2993
+ };
2994
+ }
2995
+ _isAtEnd() {
2996
+ return this._current >= this._tokens.length || this._peek().type == TokenTypes.eof;
2997
+ }
2998
+ _match(types) {
2999
+ if (types instanceof TokenType) {
3000
+ if (this._check(types)) {
3001
+ this._advance();
3002
+ return true;
3003
+ }
3004
+ return false;
3005
+ }
3006
+ for (let i = 0, l = types.length; i < l; ++i) {
3007
+ const type = types[i];
3008
+ if (this._check(type)) {
3009
+ this._advance();
3010
+ return true;
3011
+ }
3012
+ }
3013
+ return false;
3014
+ }
3015
+ _consume(types, message2) {
3016
+ if (this._check(types))
3017
+ return this._advance();
3018
+ throw this._error(this._peek(), message2);
3019
+ }
3020
+ _check(types) {
3021
+ if (this._isAtEnd())
3022
+ return false;
3023
+ const tk = this._peek();
3024
+ if (types instanceof Array) {
3025
+ let t = tk.type;
3026
+ let index2 = types.indexOf(t);
3027
+ return index2 != -1;
3028
+ }
3029
+ return tk.type == types;
3030
+ }
3031
+ _advance() {
3032
+ if (!this._isAtEnd())
3033
+ this._current++;
3034
+ return this._previous();
3035
+ }
3036
+ _peek() {
3037
+ return this._tokens[this._current];
3038
+ }
3039
+ _previous() {
3040
+ return this._tokens[this._current - 1];
3041
+ }
3042
+ _global_decl_or_directive() {
3043
+ while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
3044
+ ;
3045
+ if (this._match(TokenTypes.keywords.alias)) {
3046
+ const type = this._type_alias();
3047
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
3048
+ return type;
3049
+ }
3050
+ if (this._match(TokenTypes.keywords.enable)) {
3051
+ const enable2 = this._enable_directive();
3052
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
3053
+ return enable2;
3054
+ }
3055
+ const attrs = this._attribute();
3056
+ if (this._check(TokenTypes.keywords.var)) {
3057
+ const _var = this._global_variable_decl();
3058
+ if (_var != null)
3059
+ _var.attributes = attrs;
3060
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
3061
+ return _var;
3062
+ }
3063
+ if (this._check(TokenTypes.keywords.override)) {
3064
+ const _override = this._override_variable_decl();
3065
+ if (_override != null)
3066
+ _override.attributes = attrs;
3067
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
3068
+ return _override;
3069
+ }
3070
+ if (this._check(TokenTypes.keywords.let)) {
3071
+ const _let = this._global_let_decl();
3072
+ if (_let != null)
3073
+ _let.attributes = attrs;
3074
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
3075
+ return _let;
3076
+ }
3077
+ if (this._check(TokenTypes.keywords.const)) {
3078
+ const _const = this._global_const_decl();
3079
+ if (_const != null)
3080
+ _const.attributes = attrs;
3081
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
3082
+ return _const;
3083
+ }
3084
+ if (this._check(TokenTypes.keywords.struct)) {
3085
+ const _struct = this._struct_decl();
3086
+ if (_struct != null)
3087
+ _struct.attributes = attrs;
3088
+ return _struct;
3089
+ }
3090
+ if (this._check(TokenTypes.keywords.fn)) {
3091
+ const _fn = this._function_decl();
3092
+ if (_fn != null)
3093
+ _fn.attributes = attrs;
3094
+ return _fn;
3095
+ }
3096
+ return null;
3097
+ }
3098
+ _function_decl() {
3099
+ if (!this._match(TokenTypes.keywords.fn))
3100
+ return null;
3101
+ const name = this._consume(TokenTypes.tokens.ident, "Expected function name.").toString();
3102
+ this._consume(TokenTypes.tokens.paren_left, "Expected '(' for function arguments.");
3103
+ const args = [];
3104
+ if (!this._check(TokenTypes.tokens.paren_right)) {
3105
+ do {
3106
+ if (this._check(TokenTypes.tokens.paren_right))
3107
+ break;
3108
+ const argAttrs = this._attribute();
3109
+ const name2 = this._consume(TokenTypes.tokens.ident, "Expected argument name.").toString();
3110
+ this._consume(TokenTypes.tokens.colon, "Expected ':' for argument type.");
3111
+ const typeAttrs = this._attribute();
3112
+ const type = this._type_decl();
3113
+ if (type != null) {
3114
+ type.attributes = typeAttrs;
3115
+ args.push(new Argument(name2, type, argAttrs));
3116
+ }
3117
+ } while (this._match(TokenTypes.tokens.comma));
3118
+ }
3119
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')' after function arguments.");
3120
+ let _return = null;
3121
+ if (this._match(TokenTypes.tokens.arrow)) {
3122
+ const attrs = this._attribute();
3123
+ _return = this._type_decl();
3124
+ if (_return != null)
3125
+ _return.attributes = attrs;
3126
+ }
3127
+ const body = this._compound_statement();
3128
+ return new Function(name, args, _return, body);
3129
+ }
3130
+ _compound_statement() {
3131
+ const statements = [];
3132
+ this._consume(TokenTypes.tokens.brace_left, "Expected '{' for block.");
3133
+ while (!this._check(TokenTypes.tokens.brace_right)) {
3134
+ const statement = this._statement();
3135
+ if (statement !== null)
3136
+ statements.push(statement);
3137
+ }
3138
+ this._consume(TokenTypes.tokens.brace_right, "Expected '}' for block.");
3139
+ return statements;
3140
+ }
3141
+ _statement() {
3142
+ while (this._match(TokenTypes.tokens.semicolon) && !this._isAtEnd())
3143
+ ;
3144
+ if (this._check(TokenTypes.keywords.if))
3145
+ return this._if_statement();
3146
+ if (this._check(TokenTypes.keywords.switch))
3147
+ return this._switch_statement();
3148
+ if (this._check(TokenTypes.keywords.loop))
3149
+ return this._loop_statement();
3150
+ if (this._check(TokenTypes.keywords.for))
3151
+ return this._for_statement();
3152
+ if (this._check(TokenTypes.keywords.while))
3153
+ return this._while_statement();
3154
+ if (this._check(TokenTypes.keywords.continuing))
3155
+ return this._continuing_statement();
3156
+ if (this._check(TokenTypes.keywords.static_assert))
3157
+ return this._static_assert_statement();
3158
+ if (this._check(TokenTypes.tokens.brace_left))
3159
+ return this._compound_statement();
3160
+ let result = null;
3161
+ if (this._check(TokenTypes.keywords.return))
3162
+ result = this._return_statement();
3163
+ else if (this._check([TokenTypes.keywords.var, TokenTypes.keywords.let, TokenTypes.keywords.const]))
3164
+ result = this._variable_statement();
3165
+ else if (this._match(TokenTypes.keywords.discard))
3166
+ result = new Discard();
3167
+ else if (this._match(TokenTypes.keywords.break))
3168
+ result = new Break();
3169
+ else if (this._match(TokenTypes.keywords.continue))
3170
+ result = new Continue();
3171
+ else
3172
+ result = this._increment_decrement_statement() || this._func_call_statement() || this._assignment_statement();
3173
+ if (result != null)
3174
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';' after statement.");
3175
+ return result;
3176
+ }
3177
+ _static_assert_statement() {
3178
+ if (!this._match(TokenTypes.keywords.static_assert))
3179
+ return null;
3180
+ let expression = this._optional_paren_expression();
3181
+ return new StaticAssert(expression);
3182
+ }
3183
+ _while_statement() {
3184
+ if (!this._match(TokenTypes.keywords.while))
3185
+ return null;
3186
+ let condition = this._optional_paren_expression();
3187
+ const block = this._compound_statement();
3188
+ return new While(condition, block);
3189
+ }
3190
+ _continuing_statement() {
3191
+ if (!this._match(TokenTypes.keywords.continuing))
3192
+ return null;
3193
+ const block = this._compound_statement();
3194
+ return new Continuing(block);
3195
+ }
3196
+ _for_statement() {
3197
+ if (!this._match(TokenTypes.keywords.for))
3198
+ return null;
3199
+ this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
3200
+ const init = !this._check(TokenTypes.tokens.semicolon) ? this._for_init() : null;
3201
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
3202
+ const condition = !this._check(TokenTypes.tokens.semicolon) ? this._short_circuit_or_expression() : null;
3203
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'.");
3204
+ const increment = !this._check(TokenTypes.tokens.paren_right) ? this._for_increment() : null;
3205
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
3206
+ const body = this._compound_statement();
3207
+ return new For(init, condition, increment, body);
3208
+ }
3209
+ _for_init() {
3210
+ return this._variable_statement() || this._func_call_statement() || this._assignment_statement();
3211
+ }
3212
+ _for_increment() {
3213
+ return this._func_call_statement() || this._increment_decrement_statement() || this._assignment_statement();
3214
+ }
3215
+ _variable_statement() {
3216
+ if (this._check(TokenTypes.keywords.var)) {
3217
+ const _var = this._variable_decl();
3218
+ if (_var === null)
3219
+ throw this._error(this._peek(), "Variable declaration expected.");
3220
+ let value = null;
3221
+ if (this._match(TokenTypes.tokens.equal))
3222
+ value = this._short_circuit_or_expression();
3223
+ return new Var(_var.name, _var.type, _var.storage, _var.access, value);
3224
+ }
3225
+ if (this._match(TokenTypes.keywords.let)) {
3226
+ const name = this._consume(TokenTypes.tokens.ident, "Expected name for let.").toString();
3227
+ let type = null;
3228
+ if (this._match(TokenTypes.tokens.colon)) {
3229
+ const typeAttrs = this._attribute();
3230
+ type = this._type_decl();
3231
+ if (type != null)
3232
+ type.attributes = typeAttrs;
3233
+ }
3234
+ this._consume(TokenTypes.tokens.equal, "Expected '=' for let.");
3235
+ const value = this._short_circuit_or_expression();
3236
+ return new Let(name, type, null, null, value);
3237
+ }
3238
+ if (this._match(TokenTypes.keywords.const)) {
3239
+ const name = this._consume(TokenTypes.tokens.ident, "Expected name for const.").toString();
3240
+ let type = null;
3241
+ if (this._match(TokenTypes.tokens.colon)) {
3242
+ const typeAttrs = this._attribute();
3243
+ type = this._type_decl();
3244
+ if (type != null)
3245
+ type.attributes = typeAttrs;
3246
+ }
3247
+ this._consume(TokenTypes.tokens.equal, "Expected '=' for const.");
3248
+ const value = this._short_circuit_or_expression();
3249
+ return new Const(name, type, null, null, value);
3250
+ }
3251
+ return null;
3252
+ }
3253
+ _increment_decrement_statement() {
3254
+ const savedPos = this._current;
3255
+ const _var = this._unary_expression();
3256
+ if (_var == null)
3257
+ return null;
3258
+ if (!this._check(TokenTypes.increment_operators)) {
3259
+ this._current = savedPos;
3260
+ return null;
3261
+ }
3262
+ const token = this._consume(TokenTypes.increment_operators, "Expected increment operator");
3263
+ return new Increment(token.type === TokenTypes.tokens.plus_plus ? IncrementOperator.increment : IncrementOperator.decrement, _var);
3264
+ }
3265
+ _assignment_statement() {
3266
+ let _var = null;
3267
+ if (this._check(TokenTypes.tokens.brace_right))
3268
+ return null;
3269
+ let isUnderscore = this._match(TokenTypes.tokens.underscore);
3270
+ if (!isUnderscore)
3271
+ _var = this._unary_expression();
3272
+ if (!isUnderscore && _var == null)
3273
+ return null;
3274
+ const type = this._consume(TokenTypes.assignment_operators, "Expected assignment operator.");
3275
+ const value = this._short_circuit_or_expression();
3276
+ return new Assign(AssignOperator.parse(type.lexeme), _var, value);
3277
+ }
3278
+ _func_call_statement() {
3279
+ if (!this._check(TokenTypes.tokens.ident))
3280
+ return null;
3281
+ const savedPos = this._current;
3282
+ const name = this._consume(TokenTypes.tokens.ident, "Expected function name.");
3283
+ const args = this._argument_expression_list();
3284
+ if (args === null) {
3285
+ this._current = savedPos;
3286
+ return null;
3287
+ }
3288
+ return new Call(name.lexeme, args);
3289
+ }
3290
+ _loop_statement() {
3291
+ if (!this._match(TokenTypes.keywords.loop))
3292
+ return null;
3293
+ this._consume(TokenTypes.tokens.brace_left, "Expected '{' for loop.");
3294
+ const statements = [];
3295
+ let statement = this._statement();
3296
+ while (statement !== null) {
3297
+ if (Array.isArray(statement)) {
3298
+ for (let s of statement) {
3299
+ statements.push(s);
3300
+ }
3301
+ } else {
3302
+ statements.push(statement);
3303
+ }
3304
+ statement = this._statement();
3305
+ }
3306
+ let continuing = null;
3307
+ if (this._match(TokenTypes.keywords.continuing))
3308
+ continuing = this._compound_statement();
3309
+ this._consume(TokenTypes.tokens.brace_right, "Expected '}' for loop.");
3310
+ return new Loop(statements, continuing);
3311
+ }
3312
+ _switch_statement() {
3313
+ if (!this._match(TokenTypes.keywords.switch))
3314
+ return null;
3315
+ const condition = this._optional_paren_expression();
3316
+ this._consume(TokenTypes.tokens.brace_left, "Expected '{' for switch.");
3317
+ const body = this._switch_body();
3318
+ if (body == null || body.length == 0)
3319
+ throw this._error(this._previous(), "Expected 'case' or 'default'.");
3320
+ this._consume(TokenTypes.tokens.brace_right, "Expected '}' for switch.");
3321
+ return new Switch(condition, body);
3322
+ }
3323
+ _switch_body() {
3324
+ const cases = [];
3325
+ if (this._match(TokenTypes.keywords.case)) {
3326
+ const selector = this._case_selectors();
3327
+ this._match(TokenTypes.tokens.colon);
3328
+ this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch case.");
3329
+ const body = this._case_body();
3330
+ this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch case.");
3331
+ cases.push(new Case(selector, body));
3332
+ }
3333
+ if (this._match(TokenTypes.keywords.default)) {
3334
+ this._match(TokenTypes.tokens.colon);
3335
+ this._consume(TokenTypes.tokens.brace_left, "Exected '{' for switch default.");
3336
+ const body = this._case_body();
3337
+ this._consume(TokenTypes.tokens.brace_right, "Exected '}' for switch default.");
3338
+ cases.push(new Default(body));
3339
+ }
3340
+ if (this._check([TokenTypes.keywords.default, TokenTypes.keywords.case])) {
3341
+ const _cases = this._switch_body();
3342
+ cases.push(_cases[0]);
3343
+ }
3344
+ return cases;
3345
+ }
3346
+ _case_selectors() {
3347
+ var _a2, _b, _c, _d;
3348
+ const selectors = [(_b = (_a2 = this._shift_expression()) === null || _a2 === void 0 ? void 0 : _a2.evaluate(this._context).toString()) !== null && _b !== void 0 ? _b : ""];
3349
+ while (this._match(TokenTypes.tokens.comma)) {
3350
+ selectors.push((_d = (_c = this._shift_expression()) === null || _c === void 0 ? void 0 : _c.evaluate(this._context).toString()) !== null && _d !== void 0 ? _d : "");
3351
+ }
3352
+ return selectors;
3353
+ }
3354
+ _case_body() {
3355
+ if (this._match(TokenTypes.keywords.fallthrough)) {
3356
+ this._consume(TokenTypes.tokens.semicolon, "Expected ';'");
3357
+ return [];
3358
+ }
3359
+ let statement = this._statement();
3360
+ if (statement == null)
3361
+ return [];
3362
+ if (!(statement instanceof Array)) {
3363
+ statement = [statement];
3364
+ }
3365
+ const nextStatement = this._case_body();
3366
+ if (nextStatement.length == 0)
3367
+ return statement;
3368
+ return [...statement, nextStatement[0]];
3369
+ }
3370
+ _if_statement() {
3371
+ if (!this._match(TokenTypes.keywords.if))
3372
+ return null;
3373
+ const condition = this._optional_paren_expression();
3374
+ const block = this._compound_statement();
3375
+ let elseif = [];
3376
+ if (this._match_elseif()) {
3377
+ elseif = this._elseif_statement(elseif);
3378
+ }
3379
+ let _else = null;
3380
+ if (this._match(TokenTypes.keywords.else))
3381
+ _else = this._compound_statement();
3382
+ return new If(condition, block, elseif, _else);
3383
+ }
3384
+ _match_elseif() {
3385
+ if (this._tokens[this._current].type === TokenTypes.keywords.else && this._tokens[this._current + 1].type === TokenTypes.keywords.if) {
3386
+ this._advance();
3387
+ this._advance();
3388
+ return true;
3389
+ }
3390
+ return false;
3391
+ }
3392
+ _elseif_statement() {
3393
+ let elseif = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
3394
+ const condition = this._optional_paren_expression();
3395
+ const block = this._compound_statement();
3396
+ elseif.push(new ElseIf(condition, block));
3397
+ if (this._match_elseif()) {
3398
+ this._elseif_statement(elseif);
3399
+ }
3400
+ return elseif;
3401
+ }
3402
+ _return_statement() {
3403
+ if (!this._match(TokenTypes.keywords.return))
3404
+ return null;
3405
+ const value = this._short_circuit_or_expression();
3406
+ return new Return(value);
3407
+ }
3408
+ _short_circuit_or_expression() {
3409
+ let expr = this._short_circuit_and_expr();
3410
+ while (this._match(TokenTypes.tokens.or_or)) {
3411
+ expr = new BinaryOperator(this._previous().toString(), expr, this._short_circuit_and_expr());
3412
+ }
3413
+ return expr;
3414
+ }
3415
+ _short_circuit_and_expr() {
3416
+ let expr = this._inclusive_or_expression();
3417
+ while (this._match(TokenTypes.tokens.and_and)) {
3418
+ expr = new BinaryOperator(this._previous().toString(), expr, this._inclusive_or_expression());
3419
+ }
3420
+ return expr;
3421
+ }
3422
+ _inclusive_or_expression() {
3423
+ let expr = this._exclusive_or_expression();
3424
+ while (this._match(TokenTypes.tokens.or)) {
3425
+ expr = new BinaryOperator(this._previous().toString(), expr, this._exclusive_or_expression());
3426
+ }
3427
+ return expr;
3428
+ }
3429
+ _exclusive_or_expression() {
3430
+ let expr = this._and_expression();
3431
+ while (this._match(TokenTypes.tokens.xor)) {
3432
+ expr = new BinaryOperator(this._previous().toString(), expr, this._and_expression());
3433
+ }
3434
+ return expr;
3435
+ }
3436
+ _and_expression() {
3437
+ let expr = this._equality_expression();
3438
+ while (this._match(TokenTypes.tokens.and)) {
3439
+ expr = new BinaryOperator(this._previous().toString(), expr, this._equality_expression());
3440
+ }
3441
+ return expr;
3442
+ }
3443
+ _equality_expression() {
3444
+ const expr = this._relational_expression();
3445
+ if (this._match([TokenTypes.tokens.equal_equal, TokenTypes.tokens.not_equal])) {
3446
+ return new BinaryOperator(this._previous().toString(), expr, this._relational_expression());
3447
+ }
3448
+ return expr;
3449
+ }
3450
+ _relational_expression() {
3451
+ let expr = this._shift_expression();
3452
+ while (this._match([TokenTypes.tokens.less_than, TokenTypes.tokens.greater_than, TokenTypes.tokens.less_than_equal, TokenTypes.tokens.greater_than_equal])) {
3453
+ expr = new BinaryOperator(this._previous().toString(), expr, this._shift_expression());
3454
+ }
3455
+ return expr;
3456
+ }
3457
+ _shift_expression() {
3458
+ let expr = this._additive_expression();
3459
+ while (this._match([TokenTypes.tokens.shift_left, TokenTypes.tokens.shift_right])) {
3460
+ expr = new BinaryOperator(this._previous().toString(), expr, this._additive_expression());
3461
+ }
3462
+ return expr;
3463
+ }
3464
+ _additive_expression() {
3465
+ let expr = this._multiplicative_expression();
3466
+ while (this._match([TokenTypes.tokens.plus, TokenTypes.tokens.minus])) {
3467
+ expr = new BinaryOperator(this._previous().toString(), expr, this._multiplicative_expression());
3468
+ }
3469
+ return expr;
3470
+ }
3471
+ _multiplicative_expression() {
3472
+ let expr = this._unary_expression();
3473
+ while (this._match([TokenTypes.tokens.star, TokenTypes.tokens.forward_slash, TokenTypes.tokens.modulo])) {
3474
+ expr = new BinaryOperator(this._previous().toString(), expr, this._unary_expression());
3475
+ }
3476
+ return expr;
3477
+ }
3478
+ _unary_expression() {
3479
+ if (this._match([TokenTypes.tokens.minus, TokenTypes.tokens.bang, TokenTypes.tokens.tilde, TokenTypes.tokens.star, TokenTypes.tokens.and])) {
3480
+ return new UnaryOperator(this._previous().toString(), this._unary_expression());
3481
+ }
3482
+ return this._singular_expression();
3483
+ }
3484
+ _singular_expression() {
3485
+ const expr = this._primary_expression();
3486
+ const p = this._postfix_expression();
3487
+ if (p)
3488
+ expr.postfix = p;
3489
+ return expr;
3490
+ }
3491
+ _postfix_expression() {
3492
+ if (this._match(TokenTypes.tokens.bracket_left)) {
3493
+ const expr = this._short_circuit_or_expression();
3494
+ this._consume(TokenTypes.tokens.bracket_right, "Expected ']'.");
3495
+ const p = this._postfix_expression();
3496
+ if (p)
3497
+ expr.postfix = p;
3498
+ return expr;
3499
+ }
3500
+ if (this._match(TokenTypes.tokens.period)) {
3501
+ const name = this._consume(TokenTypes.tokens.ident, "Expected member name.");
3502
+ const p = this._postfix_expression();
3503
+ const expr = new StringExpr(name.lexeme);
3504
+ if (p)
3505
+ expr.postfix = p;
3506
+ return expr;
3507
+ }
3508
+ return null;
3509
+ }
3510
+ _getStruct(name) {
3511
+ if (this._context.aliases.has(name)) {
3512
+ const alias = this._context.aliases.get(name).type;
3513
+ return alias;
3514
+ }
3515
+ if (this._context.structs.has(name)) {
3516
+ const struct = this._context.structs.get(name);
3517
+ return struct;
3518
+ }
3519
+ return null;
3520
+ }
3521
+ _primary_expression() {
3522
+ if (this._match(TokenTypes.tokens.ident)) {
3523
+ const name = this._previous().toString();
3524
+ if (this._check(TokenTypes.tokens.paren_left)) {
3525
+ const args2 = this._argument_expression_list();
3526
+ const struct = this._getStruct(name);
3527
+ if (struct != null) {
3528
+ return new CreateExpr(struct, args2);
3529
+ }
3530
+ return new CallExpr(name, args2);
3531
+ }
3532
+ if (this._context.constants.has(name)) {
3533
+ const c = this._context.constants.get(name);
3534
+ return new ConstExpr(name, c.value);
3535
+ }
3536
+ return new VariableExpr(name);
3537
+ }
3538
+ if (this._match(TokenTypes.const_literal)) {
3539
+ return new LiteralExpr(parseFloat(this._previous().toString()));
3540
+ }
3541
+ if (this._check(TokenTypes.tokens.paren_left)) {
3542
+ return this._paren_expression();
3543
+ }
3544
+ if (this._match(TokenTypes.keywords.bitcast)) {
3545
+ this._consume(TokenTypes.tokens.less_than, "Expected '<'.");
3546
+ const type2 = this._type_decl();
3547
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
3548
+ const value = this._paren_expression();
3549
+ return new BitcastExpr(type2, value);
3550
+ }
3551
+ const type = this._type_decl();
3552
+ const args = this._argument_expression_list();
3553
+ return new TypecastExpr(type, args);
3554
+ }
3555
+ _argument_expression_list() {
3556
+ if (!this._match(TokenTypes.tokens.paren_left))
3557
+ return null;
3558
+ const args = [];
3559
+ do {
3560
+ if (this._check(TokenTypes.tokens.paren_right))
3561
+ break;
3562
+ const arg = this._short_circuit_or_expression();
3563
+ args.push(arg);
3564
+ } while (this._match(TokenTypes.tokens.comma));
3565
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')' for agument list");
3566
+ return args;
3567
+ }
3568
+ _optional_paren_expression() {
3569
+ this._match(TokenTypes.tokens.paren_left);
3570
+ const expr = this._short_circuit_or_expression();
3571
+ this._match(TokenTypes.tokens.paren_right);
3572
+ return new GroupingExpr([expr]);
3573
+ }
3574
+ _paren_expression() {
3575
+ this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
3576
+ const expr = this._short_circuit_or_expression();
3577
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
3578
+ return new GroupingExpr([expr]);
3579
+ }
3580
+ _struct_decl() {
3581
+ if (!this._match(TokenTypes.keywords.struct))
3582
+ return null;
3583
+ const name = this._consume(TokenTypes.tokens.ident, "Expected name for struct.").toString();
3584
+ this._consume(TokenTypes.tokens.brace_left, "Expected '{' for struct body.");
3585
+ const members = [];
3586
+ while (!this._check(TokenTypes.tokens.brace_right)) {
3587
+ const memberAttrs = this._attribute();
3588
+ const memberName = this._consume(TokenTypes.tokens.ident, "Expected variable name.").toString();
3589
+ this._consume(TokenTypes.tokens.colon, "Expected ':' for struct member type.");
3590
+ const typeAttrs = this._attribute();
3591
+ const memberType = this._type_decl();
3592
+ if (memberType != null)
3593
+ memberType.attributes = typeAttrs;
3594
+ if (!this._check(TokenTypes.tokens.brace_right))
3595
+ this._consume(TokenTypes.tokens.comma, "Expected ',' for struct member.");
3596
+ else
3597
+ this._match(TokenTypes.tokens.comma);
3598
+ members.push(new Member(memberName, memberType, memberAttrs));
3599
+ }
3600
+ this._consume(TokenTypes.tokens.brace_right, "Expected '}' after struct body.");
3601
+ const structNode = new Struct(name, members);
3602
+ this._context.structs.set(name, structNode);
3603
+ return structNode;
3604
+ }
3605
+ _global_variable_decl() {
3606
+ const _var = this._variable_decl();
3607
+ if (_var && this._match(TokenTypes.tokens.equal))
3608
+ _var.value = this._const_expression();
3609
+ return _var;
3610
+ }
3611
+ _override_variable_decl() {
3612
+ const _override = this._override_decl();
3613
+ if (_override && this._match(TokenTypes.tokens.equal))
3614
+ _override.value = this._const_expression();
3615
+ return _override;
3616
+ }
3617
+ _global_const_decl() {
3618
+ if (!this._match(TokenTypes.keywords.const))
3619
+ return null;
3620
+ const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
3621
+ let type = null;
3622
+ if (this._match(TokenTypes.tokens.colon)) {
3623
+ const attrs = this._attribute();
3624
+ type = this._type_decl();
3625
+ if (type != null)
3626
+ type.attributes = attrs;
3627
+ }
3628
+ let value = null;
3629
+ if (this._match(TokenTypes.tokens.equal)) {
3630
+ const valueExpr = this._short_circuit_or_expression();
3631
+ if (valueExpr instanceof CreateExpr) {
3632
+ value = valueExpr;
3633
+ } else if (valueExpr instanceof ConstExpr && valueExpr.initializer instanceof CreateExpr) {
3634
+ value = valueExpr.initializer;
3635
+ } else {
3636
+ try {
3637
+ const constValue = valueExpr.evaluate(this._context);
3638
+ value = new LiteralExpr(constValue);
3639
+ } catch (_a2) {
3640
+ value = valueExpr;
3641
+ }
3642
+ }
3643
+ }
3644
+ const c = new Const(name.toString(), type, "", "", value);
3645
+ this._context.constants.set(c.name, c);
3646
+ return c;
3647
+ }
3648
+ _global_let_decl() {
3649
+ if (!this._match(TokenTypes.keywords.let))
3650
+ return null;
3651
+ const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
3652
+ let type = null;
3653
+ if (this._match(TokenTypes.tokens.colon)) {
3654
+ const attrs = this._attribute();
3655
+ type = this._type_decl();
3656
+ if (type != null)
3657
+ type.attributes = attrs;
3658
+ }
3659
+ let value = null;
3660
+ if (this._match(TokenTypes.tokens.equal)) {
3661
+ value = this._const_expression();
3662
+ }
3663
+ return new Let(name.toString(), type, "", "", value);
3664
+ }
3665
+ _const_expression() {
3666
+ if (this._match(TokenTypes.const_literal))
3667
+ return new StringExpr(this._previous().toString());
3668
+ const type = this._type_decl();
3669
+ this._consume(TokenTypes.tokens.paren_left, "Expected '('.");
3670
+ let args = [];
3671
+ while (!this._check(TokenTypes.tokens.paren_right)) {
3672
+ args.push(this._const_expression());
3673
+ if (!this._check(TokenTypes.tokens.comma))
3674
+ break;
3675
+ this._advance();
3676
+ }
3677
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')'.");
3678
+ return new CreateExpr(type, args);
3679
+ }
3680
+ _variable_decl() {
3681
+ if (!this._match(TokenTypes.keywords.var))
3682
+ return null;
3683
+ let storage = "";
3684
+ let access = "";
3685
+ if (this._match(TokenTypes.tokens.less_than)) {
3686
+ storage = this._consume(TokenTypes.storage_class, "Expected storage_class.").toString();
3687
+ if (this._match(TokenTypes.tokens.comma))
3688
+ access = this._consume(TokenTypes.access_mode, "Expected access_mode.").toString();
3689
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>'.");
3690
+ }
3691
+ const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
3692
+ let type = null;
3693
+ if (this._match(TokenTypes.tokens.colon)) {
3694
+ const attrs = this._attribute();
3695
+ type = this._type_decl();
3696
+ if (type != null)
3697
+ type.attributes = attrs;
3698
+ }
3699
+ return new Var(name.toString(), type, storage, access, null);
3700
+ }
3701
+ _override_decl() {
3702
+ if (!this._match(TokenTypes.keywords.override))
3703
+ return null;
3704
+ const name = this._consume(TokenTypes.tokens.ident, "Expected variable name");
3705
+ let type = null;
3706
+ if (this._match(TokenTypes.tokens.colon)) {
3707
+ const attrs = this._attribute();
3708
+ type = this._type_decl();
3709
+ if (type != null)
3710
+ type.attributes = attrs;
3711
+ }
3712
+ return new Override(name.toString(), type, null);
3713
+ }
3714
+ _enable_directive() {
3715
+ const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
3716
+ return new Enable(name.toString());
3717
+ }
3718
+ _type_alias() {
3719
+ const name = this._consume(TokenTypes.tokens.ident, "identity expected.");
3720
+ this._consume(TokenTypes.tokens.equal, "Expected '=' for type alias.");
3721
+ let aliasType = this._type_decl();
3722
+ if (aliasType === null) {
3723
+ throw this._error(this._peek(), "Expected Type for Alias.");
3724
+ }
3725
+ if (this._context.aliases.has(aliasType.name)) {
3726
+ aliasType = this._context.aliases.get(aliasType.name).type;
3727
+ }
3728
+ const aliasNode = new Alias(name.toString(), aliasType);
3729
+ this._context.aliases.set(aliasNode.name, aliasNode);
3730
+ return aliasNode;
3731
+ }
3732
+ _type_decl() {
3733
+ if (this._check([TokenTypes.tokens.ident, ...TokenTypes.texel_format, TokenTypes.keywords.bool, TokenTypes.keywords.f32, TokenTypes.keywords.i32, TokenTypes.keywords.u32])) {
3734
+ const type2 = this._advance();
3735
+ const typeName = type2.toString();
3736
+ if (this._context.structs.has(typeName)) {
3737
+ return this._context.structs.get(typeName);
3738
+ }
3739
+ if (this._context.aliases.has(typeName)) {
3740
+ return this._context.aliases.get(typeName).type;
3741
+ }
3742
+ return new Type(type2.toString());
3743
+ }
3744
+ let type = this._texture_sampler_types();
3745
+ if (type)
3746
+ return type;
3747
+ if (this._check(TokenTypes.template_types)) {
3748
+ let type2 = this._advance().toString();
3749
+ let format = null;
3750
+ let access = null;
3751
+ if (this._match(TokenTypes.tokens.less_than)) {
3752
+ format = this._type_decl();
3753
+ access = null;
3754
+ if (this._match(TokenTypes.tokens.comma))
3755
+ access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
3756
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>' for type.");
3757
+ }
3758
+ return new TemplateType(type2, format, access);
3759
+ }
3760
+ if (this._match(TokenTypes.keywords.ptr)) {
3761
+ let pointer = this._previous().toString();
3762
+ this._consume(TokenTypes.tokens.less_than, "Expected '<' for pointer.");
3763
+ const storage = this._consume(TokenTypes.storage_class, "Expected storage_class for pointer");
3764
+ this._consume(TokenTypes.tokens.comma, "Expected ',' for pointer.");
3765
+ const decl = this._type_decl();
3766
+ let access = null;
3767
+ if (this._match(TokenTypes.tokens.comma))
3768
+ access = this._consume(TokenTypes.access_mode, "Expected access_mode for pointer").toString();
3769
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>' for pointer.");
3770
+ return new PointerType(pointer, storage.toString(), decl, access);
3771
+ }
3772
+ const attrs = this._attribute();
3773
+ if (this._match(TokenTypes.keywords.array)) {
3774
+ let format = null;
3775
+ let countInt = -1;
3776
+ const array = this._previous();
3777
+ if (this._match(TokenTypes.tokens.less_than)) {
3778
+ format = this._type_decl();
3779
+ if (this._context.aliases.has(format.name)) {
3780
+ format = this._context.aliases.get(format.name).type;
3781
+ }
3782
+ let count = "";
3783
+ if (this._match(TokenTypes.tokens.comma)) {
3784
+ let c = this._shift_expression();
3785
+ count = c.evaluate(this._context).toString();
3786
+ }
3787
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>' for array.");
3788
+ countInt = count ? parseInt(count) : 0;
3789
+ }
3790
+ return new ArrayType(array.toString(), attrs, format, countInt);
3791
+ }
3792
+ return null;
3793
+ }
3794
+ _texture_sampler_types() {
3795
+ if (this._match(TokenTypes.sampler_type))
3796
+ return new SamplerType(this._previous().toString(), null, null);
3797
+ if (this._match(TokenTypes.depth_texture_type))
3798
+ return new SamplerType(this._previous().toString(), null, null);
3799
+ if (this._match(TokenTypes.sampled_texture_type) || this._match(TokenTypes.multisampled_texture_type)) {
3800
+ const sampler = this._previous();
3801
+ this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
3802
+ const format = this._type_decl();
3803
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
3804
+ return new SamplerType(sampler.toString(), format, null);
3805
+ }
3806
+ if (this._match(TokenTypes.storage_texture_type)) {
3807
+ const sampler = this._previous();
3808
+ this._consume(TokenTypes.tokens.less_than, "Expected '<' for sampler type.");
3809
+ const format = this._consume(TokenTypes.texel_format, "Invalid texel format.").toString();
3810
+ this._consume(TokenTypes.tokens.comma, "Expected ',' after texel format.");
3811
+ const access = this._consume(TokenTypes.access_mode, "Expected access mode for storage texture type.").toString();
3812
+ this._consume(TokenTypes.tokens.greater_than, "Expected '>' for sampler type.");
3813
+ return new SamplerType(sampler.toString(), format, access);
3814
+ }
3815
+ return null;
3816
+ }
3817
+ _attribute() {
3818
+ let attributes = [];
3819
+ while (this._match(TokenTypes.tokens.attr)) {
3820
+ const name = this._consume(TokenTypes.attribute_name, "Expected attribute name");
3821
+ const attr = new Attribute(name.toString(), null);
3822
+ if (this._match(TokenTypes.tokens.paren_left)) {
3823
+ attr.value = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
3824
+ if (this._check(TokenTypes.tokens.comma)) {
3825
+ this._advance();
3826
+ do {
3827
+ const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
3828
+ if (!(attr.value instanceof Array)) {
3829
+ attr.value = [attr.value];
3830
+ }
3831
+ attr.value.push(v);
3832
+ } while (this._match(TokenTypes.tokens.comma));
3833
+ }
3834
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
3835
+ }
3836
+ attributes.push(attr);
3837
+ }
3838
+ while (this._match(TokenTypes.tokens.attr_left)) {
3839
+ if (!this._check(TokenTypes.tokens.attr_right)) {
3840
+ do {
3841
+ const name = this._consume(TokenTypes.attribute_name, "Expected attribute name");
3842
+ const attr = new Attribute(name.toString(), null);
3843
+ if (this._match(TokenTypes.tokens.paren_left)) {
3844
+ attr.value = [this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString()];
3845
+ if (this._check(TokenTypes.tokens.comma)) {
3846
+ this._advance();
3847
+ do {
3848
+ const v = this._consume(TokenTypes.literal_or_ident, "Expected attribute value").toString();
3849
+ attr.value.push(v);
3850
+ } while (this._match(TokenTypes.tokens.comma));
3851
+ }
3852
+ this._consume(TokenTypes.tokens.paren_right, "Expected ')'");
3853
+ }
3854
+ attributes.push(attr);
3855
+ } while (this._match(TokenTypes.tokens.comma));
3856
+ }
3857
+ this._consume(TokenTypes.tokens.attr_right, "Expected ']]' after attribute declarations");
3858
+ }
3859
+ if (attributes.length == 0)
3860
+ return null;
3861
+ return attributes;
3862
+ }
3863
+ };
3864
+ var TypeInfo = class {
3865
+ constructor(name, attributes) {
3866
+ this.name = name;
3867
+ this.attributes = attributes;
3868
+ this.size = 0;
3869
+ }
3870
+ get isArray() {
3871
+ return false;
3872
+ }
3873
+ get isStruct() {
3874
+ return false;
3875
+ }
3876
+ get isTemplate() {
3877
+ return false;
3878
+ }
3879
+ };
3880
+ var MemberInfo = class {
3881
+ constructor(name, type, attributes) {
3882
+ this.name = name;
3883
+ this.type = type;
3884
+ this.attributes = attributes;
3885
+ this.offset = 0;
3886
+ this.size = 0;
3887
+ }
3888
+ get isArray() {
3889
+ return this.type.isArray;
3890
+ }
3891
+ get isStruct() {
3892
+ return this.type.isStruct;
3893
+ }
3894
+ get isTemplate() {
3895
+ return this.type.isTemplate;
3896
+ }
3897
+ get align() {
3898
+ return this.type.isStruct ? this.type.align : 0;
3899
+ }
3900
+ get members() {
3901
+ return this.type.isStruct ? this.type.members : null;
3902
+ }
3903
+ get format() {
3904
+ return this.type.isArray ? this.type.format : this.type.isTemplate ? this.type.format : null;
3905
+ }
3906
+ get count() {
3907
+ return this.type.isArray ? this.type.count : 0;
3908
+ }
3909
+ get stride() {
3910
+ return this.type.isArray ? this.type.stride : this.size;
3911
+ }
3912
+ };
3913
+ var StructInfo = class extends TypeInfo {
3914
+ constructor(name, attributes) {
3915
+ super(name, attributes);
3916
+ this.members = [];
3917
+ this.align = 0;
3918
+ }
3919
+ get isStruct() {
3920
+ return true;
3921
+ }
3922
+ };
3923
+ var ArrayInfo = class extends TypeInfo {
3924
+ constructor(name, attributes) {
3925
+ super(name, attributes);
3926
+ this.count = 0;
3927
+ this.stride = 0;
3928
+ }
3929
+ get isArray() {
3930
+ return true;
3931
+ }
3932
+ };
3933
+ var TemplateInfo = class extends TypeInfo {
3934
+ constructor(name, format, attributes, access) {
3935
+ super(name, attributes);
3936
+ this.format = format;
3937
+ this.access = access;
3938
+ }
3939
+ get isTemplate() {
3940
+ return true;
3941
+ }
3942
+ };
3943
+ var ResourceType;
3944
+ (function(ResourceType2) {
3945
+ ResourceType2[ResourceType2["Uniform"] = 0] = "Uniform";
3946
+ ResourceType2[ResourceType2["Storage"] = 1] = "Storage";
3947
+ ResourceType2[ResourceType2["Texture"] = 2] = "Texture";
3948
+ ResourceType2[ResourceType2["Sampler"] = 3] = "Sampler";
3949
+ ResourceType2[ResourceType2["StorageTexture"] = 4] = "StorageTexture";
3950
+ })(ResourceType || (ResourceType = {}));
3951
+ var VariableInfo = class {
3952
+ constructor(name, type, group, binding, attributes, resourceType, access) {
3953
+ this.name = name;
3954
+ this.type = type;
3955
+ this.group = group;
3956
+ this.binding = binding;
3957
+ this.attributes = attributes;
3958
+ this.resourceType = resourceType;
3959
+ this.access = access;
3960
+ }
3961
+ get isArray() {
3962
+ return this.type.isArray;
3963
+ }
3964
+ get isStruct() {
3965
+ return this.type.isStruct;
3966
+ }
3967
+ get isTemplate() {
3968
+ return this.type.isTemplate;
3969
+ }
3970
+ get size() {
3971
+ return this.type.size;
3972
+ }
3973
+ get align() {
3974
+ return this.type.isStruct ? this.type.align : 0;
3975
+ }
3976
+ get members() {
3977
+ return this.type.isStruct ? this.type.members : null;
3978
+ }
3979
+ get format() {
3980
+ return this.type.isArray ? this.type.format : this.type.isTemplate ? this.type.format : null;
3981
+ }
3982
+ get count() {
3983
+ return this.type.isArray ? this.type.count : 0;
3984
+ }
3985
+ get stride() {
3986
+ return this.type.isArray ? this.type.stride : this.size;
3987
+ }
3988
+ };
3989
+ var AliasInfo = class {
3990
+ constructor(name, type) {
3991
+ this.name = name;
3992
+ this.type = type;
3993
+ }
3994
+ };
3995
+ var _TypeSize = class {
3996
+ constructor(align, size) {
3997
+ this.align = align;
3998
+ this.size = size;
3999
+ }
4000
+ };
4001
+ var InputInfo = class {
4002
+ constructor(name, type, locationType, location) {
4003
+ this.name = name;
4004
+ this.type = type;
4005
+ this.locationType = locationType;
4006
+ this.location = location;
4007
+ this.interpolation = null;
4008
+ }
4009
+ };
4010
+ var OutputInfo = class {
4011
+ constructor(name, type, locationType, location) {
4012
+ this.name = name;
4013
+ this.type = type;
4014
+ this.locationType = locationType;
4015
+ this.location = location;
4016
+ }
4017
+ };
4018
+ var FunctionInfo = class {
4019
+ constructor(name) {
4020
+ let stage = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
4021
+ this.stage = null;
4022
+ this.inputs = [];
4023
+ this.outputs = [];
4024
+ this.name = name;
4025
+ this.stage = stage;
4026
+ }
4027
+ };
4028
+ var EntryFunctions = class {
4029
+ constructor() {
4030
+ this.vertex = [];
4031
+ this.fragment = [];
4032
+ this.compute = [];
4033
+ }
4034
+ };
4035
+ var OverrideInfo = class {
4036
+ constructor(name, type, attributes, id) {
4037
+ this.name = name;
4038
+ this.type = type;
4039
+ this.attributes = attributes;
4040
+ this.id = id;
4041
+ }
4042
+ };
4043
+ var WgslReflect = class {
4044
+ constructor(code) {
4045
+ this.uniforms = [];
4046
+ this.storage = [];
4047
+ this.textures = [];
4048
+ this.samplers = [];
4049
+ this.aliases = [];
4050
+ this.overrides = [];
4051
+ this.structs = [];
4052
+ this.entry = new EntryFunctions();
4053
+ this._types = /* @__PURE__ */ new Map();
4054
+ if (code) {
4055
+ this.update(code);
4056
+ }
4057
+ }
4058
+ _isStorageTexture(type) {
4059
+ return type.name == "texture_storage_1d" || type.name == "texture_storage_2d" || type.name == "texture_storage_2d_array" || type.name == "texture_storage_3d";
4060
+ }
4061
+ update(code) {
4062
+ const parser = new WgslParser();
4063
+ const ast = parser.parse(code);
4064
+ for (const node of ast) {
4065
+ if (node instanceof Struct) {
4066
+ const info = this._getTypeInfo(node, null);
4067
+ if (info instanceof StructInfo) {
4068
+ this.structs.push(info);
4069
+ }
4070
+ continue;
4071
+ }
4072
+ if (node instanceof Alias) {
4073
+ this.aliases.push(this._getAliasInfo(node));
4074
+ continue;
4075
+ }
4076
+ if (node instanceof Override) {
4077
+ const v = node;
4078
+ const id = this._getAttributeNum(v.attributes, "id", 0);
4079
+ const type = v.type != null ? this._getTypeInfo(v.type, v.attributes) : null;
4080
+ this.overrides.push(new OverrideInfo(v.name, type, v.attributes, id));
4081
+ continue;
4082
+ }
4083
+ if (this._isUniformVar(node)) {
4084
+ const v = node;
4085
+ const g = this._getAttributeNum(v.attributes, "group", 0);
4086
+ const b = this._getAttributeNum(v.attributes, "binding", 0);
4087
+ const type = this._getTypeInfo(v.type, v.attributes);
4088
+ const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Uniform, v.access);
4089
+ this.uniforms.push(varInfo);
4090
+ continue;
4091
+ }
4092
+ if (this._isStorageVar(node)) {
4093
+ const v = node;
4094
+ const g = this._getAttributeNum(v.attributes, "group", 0);
4095
+ const b = this._getAttributeNum(v.attributes, "binding", 0);
4096
+ const type = this._getTypeInfo(v.type, v.attributes);
4097
+ const isStorageTexture = this._isStorageTexture(type);
4098
+ const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Storage, v.access);
4099
+ this.storage.push(varInfo);
4100
+ continue;
4101
+ }
4102
+ if (this._isTextureVar(node)) {
4103
+ const v = node;
4104
+ const g = this._getAttributeNum(v.attributes, "group", 0);
4105
+ const b = this._getAttributeNum(v.attributes, "binding", 0);
4106
+ const type = this._getTypeInfo(v.type, v.attributes);
4107
+ const isStorageTexture = this._isStorageTexture(type);
4108
+ const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, isStorageTexture ? ResourceType.StorageTexture : ResourceType.Texture, v.access);
4109
+ if (isStorageTexture) {
4110
+ this.storage.push(varInfo);
4111
+ } else {
4112
+ this.textures.push(varInfo);
4113
+ }
4114
+ continue;
4115
+ }
4116
+ if (this._isSamplerVar(node)) {
4117
+ const v = node;
4118
+ const g = this._getAttributeNum(v.attributes, "group", 0);
4119
+ const b = this._getAttributeNum(v.attributes, "binding", 0);
4120
+ const type = this._getTypeInfo(v.type, v.attributes);
4121
+ const varInfo = new VariableInfo(v.name, type, g, b, v.attributes, ResourceType.Sampler, v.access);
4122
+ this.samplers.push(varInfo);
4123
+ continue;
4124
+ }
4125
+ if (node instanceof Function) {
4126
+ const vertexStage = this._getAttribute(node, "vertex");
4127
+ const fragmentStage = this._getAttribute(node, "fragment");
4128
+ const computeStage = this._getAttribute(node, "compute");
4129
+ const stage = vertexStage || fragmentStage || computeStage;
4130
+ if (stage) {
4131
+ const fn = new FunctionInfo(node.name, stage.name);
4132
+ fn.inputs = this._getInputs(node.args);
4133
+ fn.outputs = this._getOutputs(node.returnType);
4134
+ this.entry[stage.name].push(fn);
4135
+ }
4136
+ continue;
4137
+ }
4138
+ }
4139
+ }
4140
+ getBindGroups() {
4141
+ const groups = [];
4142
+ function _makeRoom(group, binding) {
4143
+ if (group >= groups.length)
4144
+ groups.length = group + 1;
4145
+ if (groups[group] === void 0)
4146
+ groups[group] = [];
4147
+ if (binding >= groups[group].length)
4148
+ groups[group].length = binding + 1;
4149
+ }
4150
+ for (const u of this.uniforms) {
4151
+ _makeRoom(u.group, u.binding);
4152
+ const group = groups[u.group];
4153
+ group[u.binding] = u;
4154
+ }
4155
+ for (const u of this.storage) {
4156
+ _makeRoom(u.group, u.binding);
4157
+ const group = groups[u.group];
4158
+ group[u.binding] = u;
4159
+ }
4160
+ for (const t of this.textures) {
4161
+ _makeRoom(t.group, t.binding);
4162
+ const group = groups[t.group];
4163
+ group[t.binding] = t;
4164
+ }
4165
+ for (const t of this.samplers) {
4166
+ _makeRoom(t.group, t.binding);
4167
+ const group = groups[t.group];
4168
+ group[t.binding] = t;
4169
+ }
4170
+ return groups;
4171
+ }
4172
+ _getOutputs(type) {
4173
+ let outputs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : void 0;
4174
+ if (outputs === void 0)
4175
+ outputs = [];
4176
+ if (type instanceof Struct) {
4177
+ this._getStructOutputs(type, outputs);
4178
+ } else {
4179
+ const output = this._getOutputInfo(type);
4180
+ if (output !== null)
4181
+ outputs.push(output);
4182
+ }
4183
+ return outputs;
4184
+ }
4185
+ _getStructOutputs(struct, outputs) {
4186
+ for (const m of struct.members) {
4187
+ if (m.type instanceof Struct) {
4188
+ this._getStructOutputs(m.type, outputs);
4189
+ } else {
4190
+ const location = this._getAttribute(m, "location") || this._getAttribute(m, "builtin");
4191
+ if (location !== null) {
4192
+ const typeInfo = this._getTypeInfo(m.type, m.type.attributes);
4193
+ const locationValue = this._parseInt(location.value);
4194
+ const info = new OutputInfo(m.name, typeInfo, location.name, locationValue);
4195
+ outputs.push(info);
4196
+ }
4197
+ }
4198
+ }
4199
+ }
4200
+ _getOutputInfo(type) {
4201
+ const location = this._getAttribute(type, "location") || this._getAttribute(type, "builtin");
4202
+ if (location !== null) {
4203
+ const typeInfo = this._getTypeInfo(type, type.attributes);
4204
+ const locationValue = this._parseInt(location.value);
4205
+ const info = new OutputInfo("", typeInfo, location.name, locationValue);
4206
+ return info;
4207
+ }
4208
+ return null;
4209
+ }
4210
+ _getInputs(args) {
4211
+ let inputs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : void 0;
4212
+ if (inputs === void 0)
4213
+ inputs = [];
4214
+ for (const arg of args) {
4215
+ if (arg.type instanceof Struct) {
4216
+ this._getStructInputs(arg.type, inputs);
4217
+ } else {
4218
+ const input = this._getInputInfo(arg);
4219
+ if (input !== null)
4220
+ inputs.push(input);
4221
+ }
4222
+ }
4223
+ return inputs;
4224
+ }
4225
+ _getStructInputs(struct, inputs) {
4226
+ for (const m of struct.members) {
4227
+ if (m.type instanceof Struct) {
4228
+ this._getStructInputs(m.type, inputs);
4229
+ } else {
4230
+ const input = this._getInputInfo(m);
4231
+ if (input !== null)
4232
+ inputs.push(input);
4233
+ }
4234
+ }
4235
+ }
4236
+ _getInputInfo(node) {
4237
+ const location = this._getAttribute(node, "location") || this._getAttribute(node, "builtin");
4238
+ if (location !== null) {
4239
+ const interpolation = this._getAttribute(node, "interpolation");
4240
+ const type = this._getTypeInfo(node.type, node.attributes);
4241
+ const locationValue = this._parseInt(location.value);
4242
+ const info = new InputInfo(node.name, type, location.name, locationValue);
4243
+ if (interpolation !== null) {
4244
+ info.interpolation = this._parseString(interpolation.value);
4245
+ }
4246
+ return info;
4247
+ }
4248
+ return null;
4249
+ }
4250
+ _parseString(s) {
4251
+ if (s instanceof Array) {
4252
+ s = s[0];
4253
+ }
4254
+ return s;
4255
+ }
4256
+ _parseInt(s) {
4257
+ if (s instanceof Array) {
4258
+ s = s[0];
4259
+ }
4260
+ const n = parseInt(s);
4261
+ return isNaN(n) ? s : n;
4262
+ }
4263
+ _getAlias(name) {
4264
+ for (const a of this.aliases) {
4265
+ if (a.name == name)
4266
+ return a.type;
4267
+ }
4268
+ return null;
4269
+ }
4270
+ _getAliasInfo(node) {
4271
+ return new AliasInfo(node.name, this._getTypeInfo(node.type, null));
4272
+ }
4273
+ _getTypeInfo(type, attributes) {
4274
+ if (this._types.has(type)) {
4275
+ return this._types.get(type);
4276
+ }
4277
+ if (type instanceof ArrayType) {
4278
+ const a = type;
4279
+ const t = this._getTypeInfo(a.format, a.attributes);
4280
+ const info2 = new ArrayInfo(a.name, attributes);
4281
+ info2.format = t;
4282
+ info2.count = a.count;
4283
+ this._types.set(type, info2);
4284
+ this._updateTypeInfo(info2);
4285
+ return info2;
4286
+ }
4287
+ if (type instanceof Struct) {
4288
+ const s = type;
4289
+ const info2 = new StructInfo(s.name, attributes);
4290
+ for (const m of s.members) {
4291
+ const t = this._getTypeInfo(m.type, m.attributes);
4292
+ info2.members.push(new MemberInfo(m.name, t, m.attributes));
4293
+ }
4294
+ this._types.set(type, info2);
4295
+ this._updateTypeInfo(info2);
4296
+ return info2;
4297
+ }
4298
+ if (type instanceof SamplerType) {
4299
+ const s = type;
4300
+ const formatIsType = s.format instanceof Type;
4301
+ const format = s.format ? formatIsType ? this._getTypeInfo(s.format, null) : new TypeInfo(s.format, null) : null;
4302
+ const info2 = new TemplateInfo(s.name, format, attributes, s.access);
4303
+ this._types.set(type, info2);
4304
+ this._updateTypeInfo(info2);
4305
+ return info2;
4306
+ }
4307
+ if (type instanceof TemplateType) {
4308
+ const t = type;
4309
+ const format = t.format ? this._getTypeInfo(t.format, null) : null;
4310
+ const info2 = new TemplateInfo(t.name, format, attributes, t.access);
4311
+ this._types.set(type, info2);
4312
+ this._updateTypeInfo(info2);
4313
+ return info2;
4314
+ }
4315
+ const info = new TypeInfo(type.name, attributes);
4316
+ this._types.set(type, info);
4317
+ this._updateTypeInfo(info);
4318
+ return info;
4319
+ }
4320
+ _updateTypeInfo(type) {
4321
+ var _a2, _b;
4322
+ const typeSize = this._getTypeSize(type);
4323
+ type.size = (_a2 = typeSize === null || typeSize === void 0 ? void 0 : typeSize.size) !== null && _a2 !== void 0 ? _a2 : 0;
4324
+ if (type instanceof ArrayInfo) {
4325
+ const formatInfo = this._getTypeSize(type["format"]);
4326
+ type.stride = (_b = formatInfo === null || formatInfo === void 0 ? void 0 : formatInfo.size) !== null && _b !== void 0 ? _b : 0;
4327
+ this._updateTypeInfo(type["format"]);
4328
+ }
4329
+ if (type instanceof StructInfo) {
4330
+ this._updateStructInfo(type);
4331
+ }
4332
+ }
4333
+ _updateStructInfo(struct) {
4334
+ var _a2;
4335
+ let offset = 0;
4336
+ let lastSize = 0;
4337
+ let lastOffset = 0;
4338
+ let structAlign = 0;
4339
+ for (let mi = 0, ml = struct.members.length; mi < ml; ++mi) {
4340
+ const member = struct.members[mi];
4341
+ const sizeInfo = this._getTypeSize(member);
4342
+ if (!sizeInfo)
4343
+ continue;
4344
+ (_a2 = this._getAlias(member.type.name)) !== null && _a2 !== void 0 ? _a2 : member.type;
4345
+ const align = sizeInfo.align;
4346
+ const size = sizeInfo.size;
4347
+ offset = this._roundUp(align, offset + lastSize);
4348
+ lastSize = size;
4349
+ lastOffset = offset;
4350
+ structAlign = Math.max(structAlign, align);
4351
+ member.offset = offset;
4352
+ member.size = size;
4353
+ this._updateTypeInfo(member.type);
4354
+ }
4355
+ struct.size = this._roundUp(structAlign, lastOffset + lastSize);
4356
+ struct.align = structAlign;
4357
+ }
4358
+ _getTypeSize(type) {
4359
+ var _a2;
4360
+ if (type === null || type === void 0)
4361
+ return null;
4362
+ const explicitSize = this._getAttributeNum(type.attributes, "size", 0);
4363
+ const explicitAlign = this._getAttributeNum(type.attributes, "align", 0);
4364
+ if (type instanceof MemberInfo)
4365
+ type = type.type;
4366
+ if (type instanceof TypeInfo) {
4367
+ const alias = this._getAlias(type.name);
4368
+ if (alias !== null) {
4369
+ type = alias;
4370
+ }
4371
+ }
4372
+ {
4373
+ const info = WgslReflect._typeInfo[type.name];
4374
+ if (info !== void 0) {
4375
+ const divisor = type["format"] === "f16" ? 2 : 1;
4376
+ return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
4377
+ }
4378
+ }
4379
+ {
4380
+ const info = WgslReflect._typeInfo[type.name.substring(0, type.name.length - 1)];
4381
+ if (info) {
4382
+ const divisor = type.name[type.name.length - 1] === "h" ? 2 : 1;
4383
+ return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
4384
+ }
4385
+ }
4386
+ if (type instanceof ArrayInfo) {
4387
+ let arrayType = type;
4388
+ let align = 8;
4389
+ let size = 8;
4390
+ const E = this._getTypeSize(arrayType.format);
4391
+ if (E !== null) {
4392
+ size = E.size;
4393
+ align = E.align;
4394
+ }
4395
+ const N = arrayType.count;
4396
+ const stride = this._getAttributeNum((_a2 = type === null || type === void 0 ? void 0 : type.attributes) !== null && _a2 !== void 0 ? _a2 : null, "stride", this._roundUp(align, size));
4397
+ size = N * stride;
4398
+ if (explicitSize)
4399
+ size = explicitSize;
4400
+ return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
4401
+ }
4402
+ if (type instanceof StructInfo) {
4403
+ let align = 0;
4404
+ let size = 0;
4405
+ let offset = 0;
4406
+ let lastSize = 0;
4407
+ let lastOffset = 0;
4408
+ for (const m of type.members) {
4409
+ const mi = this._getTypeSize(m.type);
4410
+ if (mi !== null) {
4411
+ align = Math.max(mi.align, align);
4412
+ offset = this._roundUp(mi.align, offset + lastSize);
4413
+ lastSize = mi.size;
4414
+ lastOffset = offset;
4415
+ }
4416
+ }
4417
+ size = this._roundUp(align, lastOffset + lastSize);
4418
+ return new _TypeSize(Math.max(explicitAlign, align), Math.max(explicitSize, size));
4419
+ }
4420
+ return null;
4421
+ }
4422
+ _isUniformVar(node) {
4423
+ return node instanceof Var && node.storage == "uniform";
4424
+ }
4425
+ _isStorageVar(node) {
4426
+ return node instanceof Var && node.storage == "storage";
4427
+ }
4428
+ _isTextureVar(node) {
4429
+ return node instanceof Var && node.type !== null && WgslReflect._textureTypes.indexOf(node.type.name) != -1;
4430
+ }
4431
+ _isSamplerVar(node) {
4432
+ return node instanceof Var && node.type !== null && WgslReflect._samplerTypes.indexOf(node.type.name) != -1;
4433
+ }
4434
+ _getAttribute(node, name) {
4435
+ const obj = node;
4436
+ if (!obj || !obj["attributes"])
4437
+ return null;
4438
+ const attrs = obj["attributes"];
4439
+ for (let a of attrs) {
4440
+ if (a.name == name)
4441
+ return a;
4442
+ }
4443
+ return null;
4444
+ }
4445
+ _getAttributeNum(attributes, name, defaultValue) {
4446
+ if (attributes === null)
4447
+ return defaultValue;
4448
+ for (let a of attributes) {
4449
+ if (a.name == name) {
4450
+ let v = a !== null && a.value !== null ? a.value : defaultValue;
4451
+ if (v instanceof Array) {
4452
+ v = v[0];
4453
+ }
4454
+ if (typeof v === "number") {
4455
+ return v;
4456
+ }
4457
+ if (typeof v === "string") {
4458
+ return parseInt(v);
4459
+ }
4460
+ return defaultValue;
4461
+ }
4462
+ }
4463
+ return defaultValue;
4464
+ }
4465
+ _roundUp(k, n) {
4466
+ return Math.ceil(n / k) * k;
4467
+ }
4468
+ };
4469
+ WgslReflect._typeInfo = {
4470
+ f16: {
4471
+ align: 2,
4472
+ size: 2
4473
+ },
4474
+ i32: {
4475
+ align: 4,
4476
+ size: 4
4477
+ },
4478
+ u32: {
4479
+ align: 4,
4480
+ size: 4
4481
+ },
4482
+ f32: {
4483
+ align: 4,
4484
+ size: 4
4485
+ },
4486
+ atomic: {
4487
+ align: 4,
4488
+ size: 4
4489
+ },
4490
+ vec2: {
4491
+ align: 8,
4492
+ size: 8
4493
+ },
4494
+ vec3: {
4495
+ align: 16,
4496
+ size: 12
4497
+ },
4498
+ vec4: {
4499
+ align: 16,
4500
+ size: 16
4501
+ },
4502
+ mat2x2: {
4503
+ align: 8,
4504
+ size: 16
4505
+ },
4506
+ mat3x2: {
4507
+ align: 8,
4508
+ size: 24
4509
+ },
4510
+ mat4x2: {
4511
+ align: 8,
4512
+ size: 32
4513
+ },
4514
+ mat2x3: {
4515
+ align: 16,
4516
+ size: 32
4517
+ },
4518
+ mat3x3: {
4519
+ align: 16,
4520
+ size: 48
4521
+ },
4522
+ mat4x3: {
4523
+ align: 16,
4524
+ size: 64
4525
+ },
4526
+ mat2x4: {
4527
+ align: 16,
4528
+ size: 32
4529
+ },
4530
+ mat3x4: {
4531
+ align: 16,
4532
+ size: 48
4533
+ },
4534
+ mat4x4: {
4535
+ align: 16,
4536
+ size: 64
4537
+ }
4538
+ };
4539
+ WgslReflect._textureTypes = TokenTypes.any_texture_type.map((t) => {
4540
+ return t.name;
4541
+ });
4542
+ WgslReflect._samplerTypes = TokenTypes.sampler_type.map((t) => {
4543
+ return t.name;
4544
+ });
4545
+
4546
+ // ../../node_modules/@luma.gl/shadertools/dist/lib/wgsl/get-shader-layout-wgsl.js
4547
+ function getShaderLayoutFromWGSL(source) {
4548
+ const shaderLayout = {
4549
+ attributes: [],
4550
+ bindings: []
4551
+ };
4552
+ const parsedWGSL = parseWGSL(source);
4553
+ for (const uniform of parsedWGSL.uniforms) {
4554
+ const members = [];
4555
+ for (const member of uniform.type.members) {
4556
+ members.push({
4557
+ name: member.name,
4558
+ type: getType(member.type)
4559
+ });
4560
+ }
4561
+ shaderLayout.bindings.push({
4562
+ type: "uniform",
4563
+ name: uniform.name,
4564
+ location: uniform.binding,
4565
+ group: uniform.group,
4566
+ members
4567
+ });
4568
+ }
4569
+ const vertex = parsedWGSL.entry.vertex[0];
4570
+ const attributeCount = vertex.inputs.length;
4571
+ for (let i = 0; i < attributeCount; i++) {
4572
+ const wgslAttribute = vertex.inputs[i];
4573
+ if (wgslAttribute.locationType === "location") {
4574
+ const type = getType(wgslAttribute.type);
4575
+ shaderLayout.attributes.push({
4576
+ name: wgslAttribute.name,
4577
+ location: wgslAttribute.location,
4578
+ type
4579
+ });
4580
+ }
4581
+ }
4582
+ return shaderLayout;
4583
+ }
4584
+ function getType(type) {
4585
+ return type.format ? `${type.name}<${type.format.name}>` : type.name;
4586
+ }
4587
+ function parseWGSL(source) {
4588
+ try {
4589
+ return new WgslReflect(source);
4590
+ } catch (error2) {
4591
+ if (error2 instanceof Error) {
4592
+ throw error2;
4593
+ }
4594
+ let message2 = "WGSL parse error";
4595
+ if (typeof error2 === "object" && error2 !== null && error2 !== void 0 && error2.message) {
4596
+ message2 += `: ${error2.message} `;
4597
+ }
4598
+ if (typeof error2 === "object" && error2 !== null && error2 !== void 0 && error2.token) {
4599
+ message2 += error2.token.line || "";
4600
+ }
4601
+ throw new Error(message2, {
4602
+ cause: error2
4603
+ });
4604
+ }
4605
+ }
4606
+
1834
4607
  // ../../node_modules/@luma.gl/shadertools/dist/modules-webgl1/math/fp64/fp64-utils.js
1835
4608
  function fp64ify(a) {
1836
4609
  let out = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
@@ -2313,10 +5086,17 @@ vec2 sqrt_fp64(vec2 a) {
2313
5086
  };
2314
5087
 
2315
5088
  // ../../node_modules/@luma.gl/engine/dist/debug/debug-shader-layout.js
2316
- function getDebugTableForShaderLayout(layout) {
2317
- let name = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
5089
+ function getDebugTableForShaderLayout(layout, name) {
5090
+ var _layout$varyings;
2318
5091
  const table = {};
2319
- const header = `Shader Layout for ${name}`;
5092
+ const header = "Values";
5093
+ if (layout.attributes.length === 0 && !((_layout$varyings = layout.varyings) !== null && _layout$varyings !== void 0 && _layout$varyings.length)) {
5094
+ return {
5095
+ "No attributes or varyings": {
5096
+ [header]: "N/A"
5097
+ }
5098
+ };
5099
+ }
2320
5100
  for (const attributeDeclaration of layout.attributes) {
2321
5101
  if (attributeDeclaration) {
2322
5102
  const glslDeclaration = `${attributeDeclaration.location} ${attributeDeclaration.name}: ${attributeDeclaration.type}`;
@@ -2334,6 +5114,49 @@ vec2 sqrt_fp64(vec2 a) {
2334
5114
  return table;
2335
5115
  }
2336
5116
 
5117
+ // ../../node_modules/@luma.gl/engine/dist/debug/debug-framebuffer.js
5118
+ var canvas = null;
5119
+ var ctx = null;
5120
+ function debugFramebuffer(fbo, _ref) {
5121
+ let {
5122
+ id,
5123
+ minimap,
5124
+ opaque,
5125
+ top = "0",
5126
+ left = "0",
5127
+ rgbaScale = 1
5128
+ } = _ref;
5129
+ if (!canvas) {
5130
+ canvas = document.createElement("canvas");
5131
+ canvas.id = id;
5132
+ canvas.title = id;
5133
+ canvas.style.zIndex = "100";
5134
+ canvas.style.position = "absolute";
5135
+ canvas.style.top = top;
5136
+ canvas.style.left = left;
5137
+ canvas.style.border = "blue 1px solid";
5138
+ canvas.style.transform = "scaleY(-1)";
5139
+ document.body.appendChild(canvas);
5140
+ ctx = canvas.getContext("2d");
5141
+ }
5142
+ if (canvas.width !== fbo.width || canvas.height !== fbo.height) {
5143
+ canvas.width = fbo.width / 2;
5144
+ canvas.height = fbo.height / 2;
5145
+ canvas.style.width = "400px";
5146
+ canvas.style.height = "400px";
5147
+ }
5148
+ const color = fbo.device.readPixelsToArrayWebGL(fbo);
5149
+ const imageData = ctx.createImageData(fbo.width, fbo.height);
5150
+ const offset = 0;
5151
+ for (let i = 0; i < color.length; i += 4) {
5152
+ imageData.data[offset + i + 0] = color[i + 0] * rgbaScale;
5153
+ imageData.data[offset + i + 1] = color[i + 1] * rgbaScale;
5154
+ imageData.data[offset + i + 2] = color[i + 2] * rgbaScale;
5155
+ imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale;
5156
+ }
5157
+ ctx.putImageData(imageData, 0, 0);
5158
+ }
5159
+
2337
5160
  // ../../node_modules/@luma.gl/engine/dist/model/model.js
2338
5161
  var LOG_DRAW_PRIORITY = 2;
2339
5162
  var LOG_DRAW_TIMEOUT = 1e4;
@@ -2368,6 +5191,7 @@ vec2 sqrt_fp64(vec2 a) {
2368
5191
  this.props = void 0;
2369
5192
  this._lastLogTime = 0;
2370
5193
  this._logOpen = false;
5194
+ this._drawCount = 0;
2371
5195
  this.props = {
2372
5196
  ...Model.defaultProps,
2373
5197
  ...props
@@ -2378,6 +5202,19 @@ vec2 sqrt_fp64(vec2 a) {
2378
5202
  Object.assign(this.userData, props.userData);
2379
5203
  const moduleMap = Object.fromEntries(((_this$props$modules = this.props.modules) === null || _this$props$modules === void 0 ? void 0 : _this$props$modules.map((module) => [module.name, module])) || []);
2380
5204
  this.setShaderInputs(props.shaderInputs || new ShaderInputs(moduleMap));
5205
+ const isWebGPU = this.device.info.type === "webgpu";
5206
+ if (this.props.source) {
5207
+ if (isWebGPU) {
5208
+ var _this$props;
5209
+ (_this$props = this.props).shaderLayout || (_this$props.shaderLayout = getShaderLayoutFromWGSL(this.props.source));
5210
+ }
5211
+ this.props.fs = this.props.source;
5212
+ this.props.vs = this.props.source;
5213
+ }
5214
+ if (isWebGPU && typeof this.props.vs !== "string") {
5215
+ var _this$props2;
5216
+ (_this$props2 = this.props).shaderLayout || (_this$props2.shaderLayout = getShaderLayoutFromWGSL(this.props.vs.wgsl));
5217
+ }
2381
5218
  const platformInfo = getPlatformInfo(device);
2382
5219
  const modules = (((_this$props$modules2 = this.props.modules) === null || _this$props$modules2 === void 0 ? void 0 : _this$props$modules2.length) > 0 ? this.props.modules : (_this$shaderInputs = this.shaderInputs) === null || _this$shaderInputs === void 0 ? void 0 : _this$shaderInputs.getModules()) || [];
2383
5220
  const {
@@ -2465,6 +5302,7 @@ vec2 sqrt_fp64(vec2 a) {
2465
5302
  } finally {
2466
5303
  this._logDrawCallEnd();
2467
5304
  }
5305
+ this._logFramebuffer(renderPass);
2468
5306
  }
2469
5307
  setGeometry(geometry) {
2470
5308
  const gpuGeometry = geometry && makeGPUGeometry(this.device, geometry);
@@ -2476,9 +5314,18 @@ vec2 sqrt_fp64(vec2 a) {
2476
5314
  return gpuGeometry;
2477
5315
  }
2478
5316
  _setGeometryAttributes(gpuGeometry) {
5317
+ const attributes = {
5318
+ ...gpuGeometry.attributes
5319
+ };
5320
+ for (const [attributeName] of Object.entries(attributes)) {
5321
+ if (!this.pipeline.shaderLayout.attributes.find((layout) => layout.name === attributeName) && attributeName !== "positions") {
5322
+ delete attributes[attributeName];
5323
+ }
5324
+ }
2479
5325
  this.vertexCount = gpuGeometry.vertexCount;
2480
- this.setAttributes(gpuGeometry.attributes, "ignore-unknown");
2481
5326
  this.setIndexBuffer(gpuGeometry.indices);
5327
+ this.setAttributes(gpuGeometry.attributes, "ignore-unknown");
5328
+ this.setAttributes(attributes);
2482
5329
  }
2483
5330
  setTopology(topology) {
2484
5331
  if (topology !== this.topology) {
@@ -2517,6 +5364,18 @@ vec2 sqrt_fp64(vec2 a) {
2517
5364
  this.bindings[`${moduleName}Uniforms`] = uniformBuffer;
2518
5365
  }
2519
5366
  }
5367
+ setShaderModuleProps(props) {
5368
+ const uniforms = this._getModuleUniforms(props);
5369
+ const keys = Object.keys(uniforms).filter((k) => {
5370
+ const uniform = uniforms[k];
5371
+ return !(0, import_core5.isNumberArray)(uniform) && typeof uniform !== "number" && typeof uniform !== "boolean";
5372
+ });
5373
+ const bindings = {};
5374
+ for (const k of keys) {
5375
+ bindings[k] = uniforms[k];
5376
+ delete uniforms[k];
5377
+ }
5378
+ }
2520
5379
  updateShaderInputs() {
2521
5380
  this._uniformStore.setUniforms(this.shaderInputs.getUniformValues());
2522
5381
  }
@@ -2585,21 +5444,23 @@ vec2 sqrt_fp64(vec2 a) {
2585
5444
  import_core5.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
2586
5445
  }
2587
5446
  this._pipelineNeedsUpdate = false;
5447
+ const vs = this.device.createShader({
5448
+ id: `${this.id}-vertex`,
5449
+ stage: "vertex",
5450
+ source: this.vs
5451
+ });
5452
+ const fs = this.fs ? this.device.createShader({
5453
+ id: `${this.id}-fragment`,
5454
+ stage: "fragment",
5455
+ source: this.fs
5456
+ }) : null;
2588
5457
  this.pipeline = this.device.createRenderPipeline({
2589
5458
  ...this.props,
2590
5459
  bufferLayout: this.bufferLayout,
2591
5460
  topology: this.topology,
2592
5461
  parameters: this.parameters,
2593
- vs: this.device.createShader({
2594
- id: "{$this.id}-vertex",
2595
- stage: "vertex",
2596
- source: this.vs
2597
- }),
2598
- fs: this.fs ? this.device.createShader({
2599
- id: "{$this.id}-fragment",
2600
- stage: "fragment",
2601
- source: this.fs
2602
- }) : null
5462
+ vs,
5463
+ fs
2603
5464
  });
2604
5465
  this._attributeInfos = (0, import_core6.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout, this.bufferLayout);
2605
5466
  }
@@ -2607,8 +5468,8 @@ vec2 sqrt_fp64(vec2 a) {
2607
5468
  }
2608
5469
  _logDrawCallStart() {
2609
5470
  const logDrawTimeout = import_core5.log.level > 3 ? 0 : LOG_DRAW_TIMEOUT;
2610
- if (Date.now() - this._lastLogTime < logDrawTimeout) {
2611
- return void 0;
5471
+ if (import_core5.log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
5472
+ return;
2612
5473
  }
2613
5474
  this._lastLogTime = Date.now();
2614
5475
  this._logOpen = true;
@@ -2618,7 +5479,7 @@ vec2 sqrt_fp64(vec2 a) {
2618
5479
  }
2619
5480
  _logDrawCallEnd() {
2620
5481
  if (this._logOpen) {
2621
- const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout);
5482
+ const shaderLayoutTable = getDebugTableForShaderLayout(this.pipeline.shaderLayout, this.id);
2622
5483
  import_core5.log.table(LOG_DRAW_PRIORITY, shaderLayoutTable)();
2623
5484
  const uniformTable = this.shaderInputs.getDebugTable();
2624
5485
  for (const [name, value] of Object.entries(this.uniforms)) {
@@ -2634,6 +5495,20 @@ vec2 sqrt_fp64(vec2 a) {
2634
5495
  this._logOpen = false;
2635
5496
  }
2636
5497
  }
5498
+ _logFramebuffer(renderPass) {
5499
+ const debugFramebuffers = import_core5.log.get("framebuffer");
5500
+ this._drawCount++;
5501
+ if (!debugFramebuffers || this._drawCount++ > 3 && this._drawCount % 60) {
5502
+ return;
5503
+ }
5504
+ const framebuffer = renderPass.props.framebuffer;
5505
+ if (framebuffer) {
5506
+ debugFramebuffer(framebuffer, {
5507
+ id: framebuffer.id,
5508
+ minimap: true
5509
+ });
5510
+ }
5511
+ }
2637
5512
  _getAttributeDebugTable() {
2638
5513
  const table = {};
2639
5514
  for (const [name, attributeInfo] of Object.entries(this._attributeInfos)) {
@@ -2664,6 +5539,7 @@ vec2 sqrt_fp64(vec2 a) {
2664
5539
  };
2665
5540
  Model.defaultProps = {
2666
5541
  ...import_core4.RenderPipeline.defaultProps,
5542
+ source: null,
2667
5543
  vs: null,
2668
5544
  fs: null,
2669
5545
  id: "unnamed",
@@ -2947,7 +5823,7 @@ vec2 sqrt_fp64(vec2 a) {
2947
5823
  var CUBE_POSITIONS = new Float32Array([-1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1]);
2948
5824
  var CUBE_NORMALS = new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0]);
2949
5825
  var CUBE_TEX_COORDS = new Float32Array([0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1]);
2950
- var CUBE_NON_INDEXED_POSITIONS = new Float32Array([1, -1, 1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, 1, -1, 1, -1, -1, -1, 1, -1, -1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, -1, 1, -1, 1, -1, 1]);
5826
+ var CUBE_NON_INDEXED_POSITIONS = new Float32Array([1, -1, 1, -1, -1, 1, -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1]);
2951
5827
  var CUBE_NON_INDEXED_TEX_COORDS = new Float32Array([1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0]);
2952
5828
  var CUBE_NON_INDEXED_COLORS = new Float32Array([1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1]);
2953
5829
  var ATTRIBUTES = {
@@ -2966,7 +5842,7 @@ vec2 sqrt_fp64(vec2 a) {
2966
5842
  };
2967
5843
  var NON_INDEXED_ATTRIBUTES = {
2968
5844
  POSITION: {
2969
- size: 4,
5845
+ size: 3,
2970
5846
  value: CUBE_NON_INDEXED_POSITIONS
2971
5847
  },
2972
5848
  TEXCOORD_0: {
@@ -3017,7 +5893,7 @@ vec2 sqrt_fp64(vec2 a) {
3017
5893
  }
3018
5894
 
3019
5895
  // ../../node_modules/@luma.gl/webgl/dist/adapter/webgl-device.js
3020
- var import_core34 = __toESM(require_core2(), 1);
5896
+ var import_core36 = __toESM(require_core2(), 1);
3021
5897
 
3022
5898
  // ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
3023
5899
  function isElectron(mockUserAgent) {
@@ -4354,14 +7230,14 @@ vec2 sqrt_fp64(vec2 a) {
4354
7230
  onContextLost: () => console.error("WebGL context lost"),
4355
7231
  onContextRestored: () => console.info("WebGL context restored")
4356
7232
  };
4357
- function createBrowserContext(canvas, props) {
7233
+ function createBrowserContext(canvas2, props) {
4358
7234
  props = {
4359
7235
  ...DEFAULT_CONTEXT_PROPS,
4360
7236
  ...props
4361
7237
  };
4362
7238
  let errorMessage = null;
4363
7239
  const onCreateError = (error2) => errorMessage = error2.statusMessage || errorMessage;
4364
- canvas.addEventListener("webglcontextcreationerror", onCreateError, false);
7240
+ canvas2.addEventListener("webglcontextcreationerror", onCreateError, false);
4365
7241
  let gl = null;
4366
7242
  if (props.type === "webgl2") {
4367
7243
  props = {
@@ -4376,12 +7252,12 @@ vec2 sqrt_fp64(vec2 a) {
4376
7252
  };
4377
7253
  }
4378
7254
  if (!gl && props.webgl2) {
4379
- gl = canvas.getContext("webgl2", props);
7255
+ gl = canvas2.getContext("webgl2", props);
4380
7256
  }
4381
7257
  if (!gl && props.webgl1) {
4382
- gl = canvas.getContext("webgl", props);
7258
+ gl = canvas2.getContext("webgl", props);
4383
7259
  }
4384
- canvas.removeEventListener("webglcontextcreationerror", onCreateError, false);
7260
+ canvas2.removeEventListener("webglcontextcreationerror", onCreateError, false);
4385
7261
  if (!gl) {
4386
7262
  throw new Error(`Failed to create ${props.webgl2 && !props.webgl1 ? "WebGL2" : "WebGL"} context: ${errorMessage || "Unknown error"}`);
4387
7263
  }
@@ -4389,13 +7265,13 @@ vec2 sqrt_fp64(vec2 a) {
4389
7265
  const {
4390
7266
  onContextLost
4391
7267
  } = props;
4392
- canvas.addEventListener("webglcontextlost", (event) => onContextLost(event), false);
7268
+ canvas2.addEventListener("webglcontextlost", (event) => onContextLost(event), false);
4393
7269
  }
4394
7270
  if (props.onContextRestored) {
4395
7271
  const {
4396
7272
  onContextRestored
4397
7273
  } = props;
4398
- canvas.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
7274
+ canvas2.addEventListener("webglcontextrestored", (event) => onContextRestored(event), false);
4399
7275
  }
4400
7276
  return gl;
4401
7277
  }
@@ -7172,9 +10048,12 @@ void main(void) {}`;
7172
10048
  const sizeChanged = size[0] !== this.presentationSize[0] || size[1] !== this.presentationSize[1];
7173
10049
  if (sizeChanged) {
7174
10050
  this.presentationSize = size;
10051
+ this.resize();
7175
10052
  }
7176
10053
  }
7177
10054
  resize(options) {
10055
+ if (!this.device.gl)
10056
+ return;
7178
10057
  if (this.canvas) {
7179
10058
  const devicePixelRatio = this.getDevicePixelRatio(options === null || options === void 0 ? void 0 : options.useDevicePixels);
7180
10059
  this.setDevicePixelRatio(devicePixelRatio, options);
@@ -7564,6 +10443,30 @@ ${source2}`;
7564
10443
  var import_core27 = __toESM(require_core2(), 1);
7565
10444
 
7566
10445
  // ../../node_modules/@luma.gl/webgl/dist/classic/typed-array-utils.js
10446
+ var ERR_TYPE_DEDUCTION = "Failed to deduce GL constant from typed array";
10447
+ function getGLTypeFromTypedArray(arrayOrType) {
10448
+ const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
10449
+ switch (type) {
10450
+ case Float32Array:
10451
+ return 5126;
10452
+ case Uint16Array:
10453
+ return 5123;
10454
+ case Uint32Array:
10455
+ return 5125;
10456
+ case Uint8Array:
10457
+ return 5121;
10458
+ case Uint8ClampedArray:
10459
+ return 5121;
10460
+ case Int8Array:
10461
+ return 5120;
10462
+ case Int16Array:
10463
+ return 5122;
10464
+ case Int32Array:
10465
+ return 5124;
10466
+ default:
10467
+ throw new Error(ERR_TYPE_DEDUCTION);
10468
+ }
10469
+ }
7567
10470
  function getTypedArrayFromGLType(glType, options) {
7568
10471
  const {
7569
10472
  clamped = true
@@ -7609,13 +10512,13 @@ ${source2}`;
7609
10512
  };
7610
10513
  var Accessor = class {
7611
10514
  static getBytesPerElement(accessor) {
7612
- const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
7613
- return ArrayType.BYTES_PER_ELEMENT;
10515
+ const ArrayType2 = getTypedArrayFromGLType(accessor.type || 5126);
10516
+ return ArrayType2.BYTES_PER_ELEMENT;
7614
10517
  }
7615
10518
  static getBytesPerVertex(accessor) {
7616
10519
  (0, import_core27.assert)(accessor.size);
7617
- const ArrayType = getTypedArrayFromGLType(accessor.type || 5126);
7618
- return ArrayType.BYTES_PER_ELEMENT * accessor.size;
10520
+ const ArrayType2 = getTypedArrayFromGLType(accessor.type || 5126);
10521
+ return ArrayType2.BYTES_PER_ELEMENT * accessor.size;
7619
10522
  }
7620
10523
  static resolve() {
7621
10524
  for (var _len = arguments.length, accessors = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -8184,6 +11087,13 @@ ${source2}`;
8184
11087
  this._compileAndLink();
8185
11088
  this.introspectedLayout = getShaderLayout(this.device.gl, this.handle);
8186
11089
  this.shaderLayout = (0, import_core29.mergeShaderLayout)(this.introspectedLayout, props.shaderLayout);
11090
+ switch (this.props.topology) {
11091
+ case "triangle-fan-webgl":
11092
+ case "line-loop-webgl":
11093
+ import_core28.log.warn(`Primitive topology ${this.props.topology} is deprecated and will be removed in v9.1`);
11094
+ break;
11095
+ default:
11096
+ }
8187
11097
  }
8188
11098
  destroy() {
8189
11099
  if (this.handle) {
@@ -8899,27 +11809,192 @@ ${source2}`;
8899
11809
  this.gl2.bindBufferBase(35982, Number(bufferIndex), null);
8900
11810
  }
8901
11811
  }
8902
- _bindBuffer(index2, buffer) {
8903
- let byteOffset = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0;
8904
- let byteLength = arguments.length > 3 ? arguments[3] : void 0;
8905
- const handle = buffer && buffer.handle;
8906
- if (!handle || byteLength === void 0) {
8907
- this.gl2.bindBufferBase(35982, index2, handle);
8908
- } else {
8909
- this.gl2.bindBufferRange(35982, index2, handle, byteOffset, byteLength);
8910
- }
11812
+ _bindBuffer(index2, buffer) {
11813
+ let byteOffset = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0;
11814
+ let byteLength = arguments.length > 3 ? arguments[3] : void 0;
11815
+ const handle = buffer && buffer.handle;
11816
+ if (!handle || byteLength === void 0) {
11817
+ this.gl2.bindBufferBase(35982, index2, handle);
11818
+ } else {
11819
+ this.gl2.bindBufferRange(35982, index2, handle, byteOffset, byteLength);
11820
+ }
11821
+ }
11822
+ };
11823
+ function isIndex(value) {
11824
+ if (typeof value === "number") {
11825
+ return Number.isInteger(value);
11826
+ }
11827
+ return /^\d+$/.test(value);
11828
+ }
11829
+
11830
+ // ../../node_modules/@luma.gl/webgl/dist/classic/copy-and-blit.js
11831
+ var import_core35 = __toESM(require_core2(), 1);
11832
+
11833
+ // ../../node_modules/@luma.gl/webgl/dist/classic/format-utils.js
11834
+ var import_core34 = __toESM(require_core2(), 1);
11835
+ function glFormatToComponents(format) {
11836
+ switch (format) {
11837
+ case 6406:
11838
+ case 33326:
11839
+ case 6403:
11840
+ return 1;
11841
+ case 33328:
11842
+ case 33319:
11843
+ return 2;
11844
+ case 6407:
11845
+ case 34837:
11846
+ return 3;
11847
+ case 6408:
11848
+ case 34836:
11849
+ return 4;
11850
+ default:
11851
+ (0, import_core34.assert)(false);
11852
+ return 0;
11853
+ }
11854
+ }
11855
+ function glTypeToBytes(type) {
11856
+ switch (type) {
11857
+ case 5121:
11858
+ return 1;
11859
+ case 33635:
11860
+ case 32819:
11861
+ case 32820:
11862
+ return 2;
11863
+ case 5126:
11864
+ return 4;
11865
+ default:
11866
+ (0, import_core34.assert)(false);
11867
+ return 0;
11868
+ }
11869
+ }
11870
+
11871
+ // ../../node_modules/@luma.gl/webgl/dist/classic/copy-and-blit.js
11872
+ function readPixelsToArray(source, options) {
11873
+ var _framebuffer$colorAtt;
11874
+ const {
11875
+ sourceX = 0,
11876
+ sourceY = 0,
11877
+ sourceFormat = 6408,
11878
+ sourceAttachment = 36064
11879
+ } = options || {};
11880
+ let {
11881
+ target = null,
11882
+ sourceWidth,
11883
+ sourceHeight,
11884
+ sourceType
11885
+ } = options || {};
11886
+ const {
11887
+ framebuffer,
11888
+ deleteFramebuffer
11889
+ } = getFramebuffer2(source);
11890
+ (0, import_core35.assert)(framebuffer);
11891
+ const {
11892
+ gl,
11893
+ handle
11894
+ } = framebuffer;
11895
+ sourceWidth = sourceWidth || framebuffer.width;
11896
+ sourceHeight = sourceHeight || framebuffer.height;
11897
+ const attachment = sourceAttachment - 36064;
11898
+ sourceType = sourceType || ((_framebuffer$colorAtt = framebuffer.colorAttachments[attachment]) === null || _framebuffer$colorAtt === void 0 ? void 0 : _framebuffer$colorAtt.type) || 5121;
11899
+ target = getPixelArray(target, sourceType, sourceFormat, sourceWidth, sourceHeight);
11900
+ sourceType = sourceType || getGLTypeFromTypedArray(target);
11901
+ const prevHandle = gl.bindFramebuffer(36160, handle);
11902
+ gl.readPixels(sourceX, sourceY, sourceWidth, sourceHeight, sourceFormat, sourceType, target);
11903
+ gl.bindFramebuffer(36160, prevHandle || null);
11904
+ if (deleteFramebuffer) {
11905
+ framebuffer.destroy();
11906
+ }
11907
+ return target;
11908
+ }
11909
+ function readPixelsToBuffer(source, options) {
11910
+ const {
11911
+ target,
11912
+ sourceX = 0,
11913
+ sourceY = 0,
11914
+ sourceFormat = 6408,
11915
+ targetByteOffset = 0
11916
+ } = options || {};
11917
+ let {
11918
+ sourceWidth,
11919
+ sourceHeight,
11920
+ sourceType
11921
+ } = options || {};
11922
+ const {
11923
+ framebuffer,
11924
+ deleteFramebuffer
11925
+ } = getFramebuffer2(source);
11926
+ (0, import_core35.assert)(framebuffer);
11927
+ sourceWidth = sourceWidth || framebuffer.width;
11928
+ sourceHeight = sourceHeight || framebuffer.height;
11929
+ const webglFramebuffer = framebuffer;
11930
+ sourceType = sourceType || 5121;
11931
+ let webglBufferTarget = target;
11932
+ if (!webglBufferTarget) {
11933
+ const components = glFormatToComponents(sourceFormat);
11934
+ const byteCount = glTypeToBytes(sourceType);
11935
+ const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
11936
+ webglBufferTarget = webglFramebuffer.device.createBuffer({
11937
+ byteLength
11938
+ });
11939
+ }
11940
+ const commandEncoder = source.device.createCommandEncoder();
11941
+ commandEncoder.copyTextureToBuffer({
11942
+ source,
11943
+ width: sourceWidth,
11944
+ height: sourceHeight,
11945
+ origin: [sourceX, sourceY],
11946
+ destination: webglBufferTarget,
11947
+ byteOffset: targetByteOffset
11948
+ });
11949
+ commandEncoder.destroy();
11950
+ if (deleteFramebuffer) {
11951
+ framebuffer.destroy();
11952
+ }
11953
+ return webglBufferTarget;
11954
+ }
11955
+ function getFramebuffer2(source) {
11956
+ if (!(source instanceof import_core35.Framebuffer)) {
11957
+ return {
11958
+ framebuffer: toFramebuffer(source),
11959
+ deleteFramebuffer: true
11960
+ };
8911
11961
  }
8912
- };
8913
- function isIndex(value) {
8914
- if (typeof value === "number") {
8915
- return Number.isInteger(value);
11962
+ return {
11963
+ framebuffer: source,
11964
+ deleteFramebuffer: false
11965
+ };
11966
+ }
11967
+ function toFramebuffer(texture, props) {
11968
+ const {
11969
+ device,
11970
+ width,
11971
+ height,
11972
+ id
11973
+ } = texture;
11974
+ const framebuffer = device.createFramebuffer({
11975
+ ...props,
11976
+ id: `framebuffer-for-${id}`,
11977
+ width,
11978
+ height,
11979
+ colorAttachments: [texture]
11980
+ });
11981
+ return framebuffer;
11982
+ }
11983
+ function getPixelArray(pixelArray, type, format, width, height) {
11984
+ if (pixelArray) {
11985
+ return pixelArray;
8916
11986
  }
8917
- return /^\d+$/.test(value);
11987
+ type = type || 5121;
11988
+ const ArrayType2 = getTypedArrayFromGLType(type, {
11989
+ clamped: false
11990
+ });
11991
+ const components = glFormatToComponents(format);
11992
+ return new ArrayType2(width * height * components);
8918
11993
  }
8919
11994
 
8920
11995
  // ../../node_modules/@luma.gl/webgl/dist/adapter/webgl-device.js
8921
11996
  var LOG_LEVEL2 = 1;
8922
- var WebGLDevice = class extends import_core34.Device {
11997
+ var WebGLDevice = class extends import_core36.Device {
8923
11998
  static isSupported() {
8924
11999
  return typeof WebGLRenderingContext !== "undefined" || isHeadlessGLRegistered();
8925
12000
  }
@@ -8935,7 +12010,7 @@ ${source2}`;
8935
12010
  if (gl instanceof WebGLDevice) {
8936
12011
  return gl;
8937
12012
  }
8938
- if ((gl === null || gl === void 0 ? void 0 : gl.device) instanceof import_core34.Device) {
12013
+ if ((gl === null || gl === void 0 ? void 0 : gl.device) instanceof import_core36.Device) {
8939
12014
  return gl.device;
8940
12015
  }
8941
12016
  if (!isWebGL3(gl)) {
@@ -8947,35 +12022,35 @@ ${source2}`;
8947
12022
  }
8948
12023
  static async create() {
8949
12024
  let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
8950
- import_core34.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
12025
+ import_core36.log.groupCollapsed(LOG_LEVEL2, "WebGLDevice created")();
8951
12026
  if (typeof props.canvas === "string") {
8952
- await import_core34.CanvasContext.pageLoaded;
12027
+ await import_core36.CanvasContext.pageLoaded;
8953
12028
  }
8954
- if (import_core34.log.get("debug") || props.debug) {
12029
+ if (import_core36.log.get("debug") || props.debug) {
8955
12030
  await loadWebGLDeveloperTools();
8956
12031
  }
8957
12032
  const {
8958
12033
  spector: spector2
8959
12034
  } = props;
8960
- if (import_core34.log.get("spector") || spector2) {
12035
+ if (import_core36.log.get("spector") || spector2) {
8961
12036
  await loadSpectorJS();
8962
12037
  }
8963
- import_core34.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
12038
+ import_core36.log.probe(LOG_LEVEL2 + 1, "DOM is loaded")();
8964
12039
  if (props.gl && props.gl.device) {
8965
12040
  return WebGLDevice.attach(props.gl);
8966
12041
  }
8967
12042
  const device = new WebGLDevice(props);
8968
12043
  const message2 = `Created ${device.info.type}${device.debug ? " debug" : ""} context: ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContext.id}`;
8969
- import_core34.log.probe(LOG_LEVEL2, message2)();
8970
- import_core34.log.table(LOG_LEVEL2, device.info)();
8971
- import_core34.log.groupEnd(LOG_LEVEL2)();
12044
+ import_core36.log.probe(LOG_LEVEL2, message2)();
12045
+ import_core36.log.table(LOG_LEVEL2, device.info)();
12046
+ import_core36.log.groupEnd(LOG_LEVEL2)();
8972
12047
  return device;
8973
12048
  }
8974
12049
  constructor(props) {
8975
- var _props$gl;
12050
+ var _props$gl, _props$gl2;
8976
12051
  super({
8977
12052
  ...props,
8978
- id: props.id || (0, import_core34.uid)("webgl-device")
12053
+ id: props.id || (0, import_core36.uid)("webgl-device")
8979
12054
  });
8980
12055
  this.info = void 0;
8981
12056
  this.canvasContext = void 0;
@@ -9004,7 +12079,11 @@ ${source2}`;
9004
12079
  if (device) {
9005
12080
  throw new Error(`WebGL context already attached to device ${device.id}`);
9006
12081
  }
9007
- this.canvasContext = new WebGLCanvasContext(this, props);
12082
+ const canvas2 = props.canvas || ((_props$gl2 = props.gl) === null || _props$gl2 === void 0 ? void 0 : _props$gl2.canvas);
12083
+ this.canvasContext = new WebGLCanvasContext(this, {
12084
+ ...props,
12085
+ canvas: canvas2
12086
+ });
9008
12087
  this.lost = new Promise((resolve) => {
9009
12088
  this._resolveContextLost = resolve;
9010
12089
  });
@@ -9032,6 +12111,7 @@ ${source2}`;
9032
12111
  this.gl2 = this.gl;
9033
12112
  this.isWebGL2 = isWebGL22(this.gl);
9034
12113
  this.isWebGL1 = !this.isWebGL2;
12114
+ this.canvasContext.resize();
9035
12115
  this.info = getDeviceInfo(this.gl);
9036
12116
  this.gl.device = this;
9037
12117
  this.gl._version = this.isWebGL2 ? 2 : 1;
@@ -9047,7 +12127,7 @@ ${source2}`;
9047
12127
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
9048
12128
  args[_key] = arguments[_key];
9049
12129
  }
9050
- return import_core34.log.log(1, ...args)();
12130
+ return import_core36.log.log(1, ...args)();
9051
12131
  }
9052
12132
  });
9053
12133
  if (isBrowser() && props.debug) {
@@ -9058,14 +12138,14 @@ ${source2}`;
9058
12138
  });
9059
12139
  this.gl2 = this.gl;
9060
12140
  this.debug = true;
9061
- import_core34.log.level = Math.max(import_core34.log.level, 1);
9062
- import_core34.log.warn("WebGL debug mode activated. Performance reduced.")();
12141
+ import_core36.log.level = Math.max(import_core36.log.level, 1);
12142
+ import_core36.log.warn("WebGL debug mode activated. Performance reduced.")();
9063
12143
  }
9064
12144
  if (isBrowser() && props.spector) {
9065
- const canvas = this.handle.canvas || props.canvas;
12145
+ const canvas3 = this.handle.canvas || props.canvas;
9066
12146
  this.spector = initializeSpectorJS({
9067
12147
  ...this.props,
9068
- canvas
12148
+ canvas: canvas3
9069
12149
  });
9070
12150
  }
9071
12151
  }
@@ -9150,6 +12230,12 @@ ${source2}`;
9150
12230
  (_this$renderPass = this.renderPass) === null || _this$renderPass === void 0 ? void 0 : _this$renderPass.end();
9151
12231
  this.renderPass = null;
9152
12232
  }
12233
+ readPixelsToArrayWebGL(source, options) {
12234
+ return readPixelsToArray(source, options);
12235
+ }
12236
+ readPixelsToBufferWebGL2(source, options) {
12237
+ return readPixelsToBuffer(source, options);
12238
+ }
9153
12239
  get webglLimits() {
9154
12240
  this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);
9155
12241
  return this._webglLimits;
@@ -9191,7 +12277,7 @@ ${source2}`;
9191
12277
  this._constants = this._constants || new Array(this.limits.maxVertexAttributes).fill(null);
9192
12278
  const currentConstant = this._constants[location];
9193
12279
  if (currentConstant && compareConstantArrayValues2(currentConstant, constant)) {
9194
- import_core34.log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();
12280
+ import_core36.log.info(1, `setConstantAttribute(${location}) could have been skipped, value unchanged`)();
9195
12281
  }
9196
12282
  this._constants[location] = constant;
9197
12283
  switch (constant.constructor) {
@@ -9205,7 +12291,7 @@ ${source2}`;
9205
12291
  setConstantUintArray(this, location, constant);
9206
12292
  break;
9207
12293
  default:
9208
- (0, import_core34.assert)(false);
12294
+ (0, import_core36.assert)(false);
9209
12295
  }
9210
12296
  }
9211
12297
  };
@@ -9240,7 +12326,7 @@ ${source2}`;
9240
12326
  device.gl.vertexAttrib4fv(location, array);
9241
12327
  break;
9242
12328
  default:
9243
- (0, import_core34.assert)(false);
12329
+ (0, import_core36.assert)(false);
9244
12330
  }
9245
12331
  }
9246
12332
  function setConstantIntArray(device, location, array) {
@@ -9266,7 +12352,7 @@ ${source2}`;
9266
12352
  }
9267
12353
 
9268
12354
  // ../../node_modules/@luma.gl/webgl/dist/classic/clear.js
9269
- var import_core35 = __toESM(require_core2(), 1);
12355
+ var import_core37 = __toESM(require_core2(), 1);
9270
12356
  var GL_DEPTH_BUFFER_BIT2 = 256;
9271
12357
  var GL_STENCIL_BUFFER_BIT2 = 1024;
9272
12358
  var GL_COLOR_BUFFER_BIT2 = 16384;
@@ -9302,128 +12388,12 @@ ${source2}`;
9302
12388
  parameters.clearStencil = depth;
9303
12389
  }
9304
12390
  }
9305
- (0, import_core35.assert)(clearFlags !== 0, ERR_ARGUMENTS);
12391
+ (0, import_core37.assert)(clearFlags !== 0, ERR_ARGUMENTS);
9306
12392
  withGLParameters(device.gl, parameters, () => {
9307
12393
  device.gl.clear(clearFlags);
9308
12394
  });
9309
12395
  }
9310
12396
 
9311
- // ../../node_modules/@luma.gl/webgl/dist/classic/copy-and-blit.js
9312
- var import_core37 = __toESM(require_core2(), 1);
9313
-
9314
- // ../../node_modules/@luma.gl/webgl/dist/classic/format-utils.js
9315
- var import_core36 = __toESM(require_core2(), 1);
9316
- function glFormatToComponents(format) {
9317
- switch (format) {
9318
- case 6406:
9319
- case 33326:
9320
- case 6403:
9321
- return 1;
9322
- case 33328:
9323
- case 33319:
9324
- return 2;
9325
- case 6407:
9326
- case 34837:
9327
- return 3;
9328
- case 6408:
9329
- case 34836:
9330
- return 4;
9331
- default:
9332
- (0, import_core36.assert)(false);
9333
- return 0;
9334
- }
9335
- }
9336
- function glTypeToBytes(type) {
9337
- switch (type) {
9338
- case 5121:
9339
- return 1;
9340
- case 33635:
9341
- case 32819:
9342
- case 32820:
9343
- return 2;
9344
- case 5126:
9345
- return 4;
9346
- default:
9347
- (0, import_core36.assert)(false);
9348
- return 0;
9349
- }
9350
- }
9351
-
9352
- // ../../node_modules/@luma.gl/webgl/dist/classic/copy-and-blit.js
9353
- function readPixelsToBuffer(source, options) {
9354
- const {
9355
- sourceX = 0,
9356
- sourceY = 0,
9357
- sourceFormat = 6408,
9358
- targetByteOffset = 0
9359
- } = options || {};
9360
- let {
9361
- target,
9362
- sourceWidth,
9363
- sourceHeight,
9364
- sourceType
9365
- } = options || {};
9366
- const {
9367
- framebuffer,
9368
- deleteFramebuffer
9369
- } = getFramebuffer2(source);
9370
- (0, import_core37.assert)(framebuffer);
9371
- sourceWidth = sourceWidth || framebuffer.width;
9372
- sourceHeight = sourceHeight || framebuffer.height;
9373
- const webglFramebuffer = framebuffer;
9374
- sourceType = sourceType || 5121;
9375
- if (!target) {
9376
- const components = glFormatToComponents(sourceFormat);
9377
- const byteCount = glTypeToBytes(sourceType);
9378
- const byteLength = targetByteOffset + sourceWidth * sourceHeight * components * byteCount;
9379
- target = webglFramebuffer.device.createBuffer({
9380
- byteLength
9381
- });
9382
- }
9383
- const commandEncoder = source.device.createCommandEncoder();
9384
- commandEncoder.copyTextureToBuffer({
9385
- source,
9386
- width: sourceWidth,
9387
- height: sourceHeight,
9388
- origin: [sourceX, sourceY],
9389
- destination: target,
9390
- byteOffset: targetByteOffset
9391
- });
9392
- commandEncoder.destroy();
9393
- if (deleteFramebuffer) {
9394
- framebuffer.destroy();
9395
- }
9396
- return target;
9397
- }
9398
- function getFramebuffer2(source) {
9399
- if (!(source instanceof import_core37.Framebuffer)) {
9400
- return {
9401
- framebuffer: toFramebuffer(source),
9402
- deleteFramebuffer: true
9403
- };
9404
- }
9405
- return {
9406
- framebuffer: source,
9407
- deleteFramebuffer: false
9408
- };
9409
- }
9410
- function toFramebuffer(texture, props) {
9411
- const {
9412
- device,
9413
- width,
9414
- height,
9415
- id
9416
- } = texture;
9417
- const framebuffer = device.createFramebuffer({
9418
- ...props,
9419
- id: `framebuffer-for-${id}`,
9420
- width,
9421
- height,
9422
- colorAttachments: [texture]
9423
- });
9424
- return framebuffer;
9425
- }
9426
-
9427
12397
  // src/utils/gpu-grid-aggregation/gpu-grid-aggregator.ts
9428
12398
  var import_core38 = __toESM(require_core());
9429
12399
 
@@ -10351,12 +13321,12 @@ void main()
10351
13321
 
10352
13322
  // src/utils/color-utils.ts
10353
13323
  var defaultColorRange = [[255, 255, 178], [254, 217, 118], [254, 178, 76], [253, 141, 60], [240, 59, 32], [189, 0, 38]];
10354
- function colorRangeToFlatArray(colorRange, normalize = false, ArrayType = Float32Array) {
13324
+ function colorRangeToFlatArray(colorRange, normalize = false, ArrayType2 = Float32Array) {
10355
13325
  let flatArray;
10356
13326
  if (Number.isFinite(colorRange[0])) {
10357
- flatArray = new ArrayType(colorRange);
13327
+ flatArray = new ArrayType2(colorRange);
10358
13328
  } else {
10359
- flatArray = new ArrayType(colorRange.length * 4);
13329
+ flatArray = new ArrayType2(colorRange.length * 4);
10360
13330
  let index2 = 0;
10361
13331
  for (let i = 0; i < colorRange.length; i++) {
10362
13332
  const color = colorRange[i];
@@ -14194,18 +17164,6 @@ void main(void) {
14194
17164
  const [xMin, yMin, xMax, yMax] = bounds;
14195
17165
  return [(point[0] - xMin) / (xMax - xMin), (point[1] - yMin) / (yMax - yMin)];
14196
17166
  }
14197
- function getTextureParams({
14198
- device,
14199
- floatTargetSupport
14200
- }) {
14201
- return floatTargetSupport ? {
14202
- format: device.info.type === "webgl2" ? 34836 : 6408,
14203
- type: 5126
14204
- } : {
14205
- format: 6408,
14206
- type: 5121
14207
- };
14208
- }
14209
17167
 
14210
17168
  // src/heatmap-layer/heatmap-layer.ts
14211
17169
  var import_core54 = __toESM(require_core());
@@ -14253,7 +17211,7 @@ void main(void) {
14253
17211
  precision highp float;
14254
17212
 
14255
17213
  uniform float opacity;
14256
- uniform sampler2D texture;
17214
+ uniform sampler2D weightsTexture;
14257
17215
  uniform sampler2D colorTexture;
14258
17216
  uniform float aggregationMode;
14259
17217
 
@@ -14271,7 +17229,7 @@ vec4 getLinearColor(float value) {
14271
17229
  }
14272
17230
 
14273
17231
  void main(void) {
14274
- vec4 weights = texture(texture, vTexCoords);
17232
+ vec4 weights = texture(weightsTexture, vTexCoords);
14275
17233
  float weight = weights.r;
14276
17234
 
14277
17235
  if (aggregationMode > 0.5) {
@@ -14301,32 +17259,36 @@ void main(void) {
14301
17259
  initializeState({
14302
17260
  device
14303
17261
  }) {
14304
- const attributeManager = this.getAttributeManager();
14305
- attributeManager.add({
14306
- positions: {
14307
- size: 3,
14308
- noAlloc: true
14309
- },
14310
- texCoords: {
14311
- size: 2,
14312
- noAlloc: true
14313
- }
14314
- });
14315
17262
  this.setState({
14316
17263
  model: this._getModel(device)
14317
17264
  });
14318
17265
  }
14319
17266
  _getModel(device) {
14320
17267
  const {
14321
- vertexCount
17268
+ vertexCount,
17269
+ data,
17270
+ weightsTexture,
17271
+ maxTexture,
17272
+ colorTexture
14322
17273
  } = this.props;
14323
17274
  return new Model(device, {
14324
17275
  ...this.getShaders(),
14325
17276
  id: this.props.id,
14326
- geometry: new Geometry({
14327
- topology: "triangle-fan-webgl",
14328
- vertexCount
14329
- })
17277
+ bindings: {
17278
+ weightsTexture,
17279
+ maxTexture,
17280
+ colorTexture
17281
+ },
17282
+ attributes: data.attributes,
17283
+ bufferLayout: [{
17284
+ name: "positions",
17285
+ format: "float32x3"
17286
+ }, {
17287
+ name: "texCoords",
17288
+ format: "float32x2"
17289
+ }],
17290
+ topology: "triangle-fan-webgl",
17291
+ vertexCount
14330
17292
  });
14331
17293
  }
14332
17294
  draw({
@@ -14336,9 +17298,6 @@ void main(void) {
14336
17298
  model
14337
17299
  } = this.state;
14338
17300
  const {
14339
- texture,
14340
- maxTexture,
14341
- colorTexture,
14342
17301
  intensity,
14343
17302
  threshold: threshold2,
14344
17303
  aggregationMode,
@@ -14346,9 +17305,6 @@ void main(void) {
14346
17305
  } = this.props;
14347
17306
  model.setUniforms({
14348
17307
  ...uniforms,
14349
- texture,
14350
- maxTexture,
14351
- colorTexture,
14352
17308
  intensity,
14353
17309
  threshold: threshold2,
14354
17310
  aggregationMode,
@@ -14369,18 +17325,20 @@ uniform float radiusPixels;
14369
17325
  uniform float textureWidth;
14370
17326
  uniform vec4 commonBounds;
14371
17327
  uniform float weightsScale;
17328
+
14372
17329
  void main()
14373
17330
  {
14374
17331
  weightsTexture = vec4(weights * weightsScale, 0., 0., 1.);
14375
17332
 
14376
- float radiusTexels = project_pixel_size(radiusPixels) * textureWidth / (commonBounds.z - commonBounds.x);
17333
+ float radiusTexels = project_pixel_size(radiusPixels) * textureWidth / (commonBounds.z - commonBounds.x);
14377
17334
  gl_PointSize = radiusTexels * 2.;
14378
17335
 
14379
17336
  vec3 commonPosition = project_position(positions, positions64Low);
14380
17337
 
14381
- // map xy from commonBounds to [-1, 1]
17338
+ // // map xy from commonBounds to [-1, 1]
14382
17339
  gl_Position.xy = (commonPosition.xy - commonBounds.xy) / (commonBounds.zw - commonBounds.xy) ;
14383
17340
  gl_Position.xy = (gl_Position.xy * 2.) - (1.);
17341
+ gl_Position.w = 1.0;
14384
17342
  }
14385
17343
  `;
14386
17344
 
@@ -14408,15 +17366,21 @@ void main()
14408
17366
 
14409
17367
  // src/heatmap-layer/max-vs.glsl.ts
14410
17368
  var max_vs_glsl_default = `#version 300 es
14411
- in vec4 inTexture;
17369
+ uniform sampler2D inTexture;
17370
+ uniform float textureSize;
14412
17371
  out vec4 outTexture;
14413
17372
 
14414
17373
  void main()
14415
17374
  {
14416
- outTexture = inTexture;
14417
- gl_Position = vec4(0, 0, 0, 1.);
14418
- // Enforce default value for ANGLE issue (https://bugs.chromium.org/p/angleproject/issues/detail?id=3941)
14419
- gl_PointSize = 1.0;
17375
+ // Sample every pixel in texture
17376
+ int yIndex = gl_VertexID / int(textureSize);
17377
+ int xIndex = gl_VertexID - (yIndex * int(textureSize));
17378
+ vec2 uv = (0.5 + vec2(float(xIndex), float(yIndex))) / textureSize;
17379
+ outTexture = texture(inTexture, uv);
17380
+
17381
+ gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
17382
+ // Enforce default value for ANGLE issue (https://bugs.chromium.org/p/angleproject/issues/detail?id=3941)
17383
+ gl_PointSize = 1.0;
14420
17384
  }
14421
17385
  `;
14422
17386
 
@@ -14436,8 +17400,8 @@ void main() {
14436
17400
  format: "rgba8unorm",
14437
17401
  mipmaps: false,
14438
17402
  sampler: {
14439
- minFilter: "nearest",
14440
- magFilter: "nearest",
17403
+ minFilter: "linear",
17404
+ magFilter: "linear",
14441
17405
  addressModeU: "clamp-to-edge",
14442
17406
  addressModeV: "clamp-to-edge"
14443
17407
  }
@@ -14592,7 +17556,7 @@ void main() {
14592
17556
  maxTexture: maxWeightsTexture,
14593
17557
  colorTexture,
14594
17558
  aggregationMode: AGGREGATION_MODE[aggregation] || 0,
14595
- texture: weightsTexture,
17559
+ weightsTexture,
14596
17560
  intensity,
14597
17561
  threshold: threshold2,
14598
17562
  colorDomain
@@ -14648,21 +17612,20 @@ void main() {
14648
17612
  _createTextures() {
14649
17613
  const {
14650
17614
  textureSize,
14651
- format,
14652
- type
17615
+ format
14653
17616
  } = this.state;
14654
17617
  this.setState({
14655
17618
  weightsTexture: this.context.device.createTexture({
17619
+ ...TEXTURE_PROPS,
14656
17620
  width: textureSize,
14657
17621
  height: textureSize,
14658
- format,
14659
- type,
14660
- ...TEXTURE_PROPS
17622
+ format
14661
17623
  }),
14662
17624
  maxWeightsTexture: this.context.device.createTexture({
14663
- format,
14664
- type,
14665
- ...TEXTURE_PROPS
17625
+ ...TEXTURE_PROPS,
17626
+ width: 1,
17627
+ height: 1,
17628
+ format
14666
17629
  })
14667
17630
  });
14668
17631
  }
@@ -14692,43 +17655,40 @@ void main() {
14692
17655
  } = this.props;
14693
17656
  const textureSize = Math.min(weightsTextureSize, device.limits.maxTextureDimension2D);
14694
17657
  const floatTargetSupport = FLOAT_TARGET_FEATURES.every((feature) => device.features.has(feature));
14695
- const {
14696
- format,
14697
- type
14698
- } = getTextureParams({
14699
- device,
14700
- floatTargetSupport
14701
- });
17658
+ const format = floatTargetSupport ? "rgba32float" : "rgba8unorm";
14702
17659
  const weightsScale = floatTargetSupport ? 1 : 1 / 255;
14703
17660
  this.setState({
14704
17661
  textureSize,
14705
17662
  format,
14706
- type,
14707
17663
  weightsScale
14708
17664
  });
14709
17665
  if (!floatTargetSupport) {
14710
- import_core54.log.warn(`HeatmapLayer: ${this.id} rendering to float texture not supported, fallingback to low precession format`)();
17666
+ import_core54.log.warn(`HeatmapLayer: ${this.id} rendering to float texture not supported, falling back to low precision format`)();
14711
17667
  }
14712
17668
  }
14713
- getShaders(type) {
14714
- return super.getShaders(type === "max-weights-transform" ? {
14715
- vs: max_vs_glsl_default,
14716
- _fs: max_fs_glsl_default
14717
- } : {
14718
- vs: weights_vs_glsl_default,
14719
- _fs: weights_fs_glsl_default
14720
- });
14721
- }
14722
- _createWeightsTransform(shaders = {}) {
17669
+ _createWeightsTransform(shaders) {
14723
17670
  let {
14724
17671
  weightsTransform
14725
17672
  } = this.state;
14726
- weightsTransform?.delete();
17673
+ const {
17674
+ weightsTexture
17675
+ } = this.state;
17676
+ const attributeManager = this.getAttributeManager();
17677
+ weightsTransform?.destroy();
14727
17678
  weightsTransform = new TextureTransform(this.context.device, {
14728
17679
  id: `${this.id}-weights-transform`,
17680
+ bufferLayout: attributeManager.getBufferLayouts(),
14729
17681
  vertexCount: 1,
14730
- targetTexture: this.state.weightsTexture,
14731
- targetTextureVarying: "weightsTexture",
17682
+ targetTexture: weightsTexture,
17683
+ parameters: {
17684
+ depthWriteEnabled: false,
17685
+ blendColorOperation: "add",
17686
+ blendColorSrcFactor: "one",
17687
+ blendColorDstFactor: "one",
17688
+ blendAlphaSrcFactor: "one",
17689
+ blendAlphaDstFactor: "one"
17690
+ },
17691
+ topology: "point-list",
14732
17692
  ...shaders
14733
17693
  });
14734
17694
  this.setState({
@@ -14737,57 +17697,75 @@ void main() {
14737
17697
  }
14738
17698
  _setupResources() {
14739
17699
  this._createTextures();
17700
+ const {
17701
+ device
17702
+ } = this.context;
14740
17703
  const {
14741
17704
  textureSize,
14742
17705
  weightsTexture,
14743
17706
  maxWeightsTexture
14744
17707
  } = this.state;
14745
- const weightsTransformShaders = this.getShaders("weights-transform");
17708
+ const weightsTransformShaders = this.getShaders({
17709
+ vs: weights_vs_glsl_default,
17710
+ fs: weights_fs_glsl_default
17711
+ });
14746
17712
  this._createWeightsTransform(weightsTransformShaders);
14747
- const maxWeightsTransformShaders = this.getShaders("max-weights-transform");
14748
- const maxWeightTransform = new TextureTransform(this.context.device, {
17713
+ const maxWeightsTransformShaders = this.getShaders({
17714
+ vs: max_vs_glsl_default,
17715
+ fs: max_fs_glsl_default
17716
+ });
17717
+ const maxWeightTransform = new TextureTransform(device, {
14749
17718
  id: `${this.id}-max-weights-transform`,
14750
- _sourceTextures: {
17719
+ bindings: {
14751
17720
  inTexture: weightsTexture
14752
17721
  },
14753
- _targetTexture: maxWeightsTexture,
14754
- _targetTextureVarying: "outTexture",
17722
+ uniforms: {
17723
+ textureSize
17724
+ },
17725
+ targetTexture: maxWeightsTexture,
14755
17726
  ...maxWeightsTransformShaders,
14756
- elementCount: textureSize * textureSize
17727
+ vertexCount: textureSize * textureSize,
17728
+ topology: "point-list",
17729
+ parameters: {
17730
+ depthWriteEnabled: false,
17731
+ blendColorOperation: "max",
17732
+ blendAlphaOperation: "max",
17733
+ blendColorSrcFactor: "one",
17734
+ blendColorDstFactor: "one",
17735
+ blendAlphaSrcFactor: "one",
17736
+ blendAlphaDstFactor: "one"
17737
+ }
14757
17738
  });
14758
17739
  this.setState({
14759
17740
  weightsTexture,
14760
17741
  maxWeightsTexture,
14761
17742
  maxWeightTransform,
14762
17743
  zoom: null,
14763
- triPositionBuffer: this.context.device.createBuffer({
14764
- byteLength: 48,
14765
- accessor: {
14766
- size: 3
14767
- }
17744
+ triPositionBuffer: device.createBuffer({
17745
+ byteLength: 48
14768
17746
  }),
14769
- triTexCoordBuffer: this.context.device.createBuffer({
14770
- byteLength: 48,
14771
- accessor: {
14772
- size: 2
14773
- }
17747
+ triTexCoordBuffer: device.createBuffer({
17748
+ byteLength: 48
14774
17749
  })
14775
17750
  });
14776
17751
  }
14777
17752
  updateShaders(shaderOptions) {
14778
- this._createWeightsTransform(shaderOptions);
17753
+ this._createWeightsTransform({
17754
+ vs: weights_vs_glsl_default,
17755
+ fs: weights_fs_glsl_default,
17756
+ ...shaderOptions
17757
+ });
14779
17758
  }
14780
17759
  _updateMaxWeightValue() {
14781
17760
  const {
14782
- maxWeightTransform
17761
+ maxWeightTransform,
17762
+ textureSize
14783
17763
  } = this.state;
14784
17764
  maxWeightTransform.run({
14785
17765
  parameters: {
14786
- blend: true,
14787
- depthTest: false,
14788
- blendFunc: [1, 1],
14789
- blendEquation: 32776
14790
- }
17766
+ viewport: [0, 0, 1, 1]
17767
+ },
17768
+ clearColor: [0, 0, 0, 0]
14791
17769
  });
14792
17770
  }
14793
17771
  _updateBounds(forceUpdate = false) {
@@ -14840,17 +17818,17 @@ void main() {
14840
17818
  colorTexture
14841
17819
  } = this.state;
14842
17820
  const colors = colorRangeToFlatArray(colorRange, false, Uint8Array);
14843
- if (colorTexture) {
14844
- colorTexture.setImageData({
14845
- data: colors,
14846
- width: colorRange.length
17821
+ if (colorTexture && colorTexture?.width === colorRange.length) {
17822
+ colorTexture.setSubImageData({
17823
+ data: colors
14847
17824
  });
14848
17825
  } else {
17826
+ colorTexture?.destroy();
14849
17827
  colorTexture = this.context.device.createTexture({
17828
+ ...TEXTURE_PROPS,
14850
17829
  data: colors,
14851
17830
  width: colorRange.length,
14852
- height: 1,
14853
- ...TEXTURE_PROPS
17831
+ height: 1
14854
17832
  });
14855
17833
  }
14856
17834
  this.setState({
@@ -14882,30 +17860,29 @@ void main() {
14882
17860
  } else {
14883
17861
  this.state.colorDomain = colorDomain || DEFAULT_COLOR_DOMAIN;
14884
17862
  }
17863
+ const attributeManager = this.getAttributeManager();
17864
+ const attributes = attributeManager.getAttributes();
17865
+ const moduleSettings = this.getModuleSettings();
17866
+ const positions = attributes.positions.buffer;
14885
17867
  const uniforms = {
14886
17868
  radiusPixels,
14887
17869
  commonBounds,
14888
17870
  textureWidth: textureSize,
14889
17871
  weightsScale
14890
17872
  };
14891
- weightsTransform.update({
14892
- elementCount: this.getNumInstances()
17873
+ const weights = attributes.weights.buffer;
17874
+ weightsTransform.model.setAttributes({
17875
+ positions,
17876
+ weights
14893
17877
  });
14894
- withGLParameters(this.context.gl, {
17878
+ weightsTransform.model.setVertexCount(this.getNumInstances());
17879
+ weightsTransform.model.setUniforms(uniforms);
17880
+ weightsTransform.model.updateModuleSettings(moduleSettings);
17881
+ weightsTransform.run({
17882
+ parameters: {
17883
+ viewport: [0, 0, textureSize, textureSize]
17884
+ },
14895
17885
  clearColor: [0, 0, 0, 0]
14896
- }, () => {
14897
- weightsTransform.run({
14898
- uniforms,
14899
- parameters: {
14900
- blend: true,
14901
- depthTest: false,
14902
- blendFunc: [1, 1],
14903
- blendEquation: 32774
14904
- },
14905
- clearRenderTarget: true,
14906
- attributes: this.getAttributes(),
14907
- moduleSettings: this.getModuleSettings()
14908
- });
14909
17886
  });
14910
17887
  this._updateMaxWeightValue();
14911
17888
  }