Heatmap using GPU.js
In this notebook, we use the Javascript framework GPU.js to compile custom WebGL shaders to render and animate the heatmap together with normal Wolfram Language graphics primitives.
All dependencies are kept within this notebook and do not require installation or compilation.
Building common module (optional)
We build a simple module, which will hook up a CommonJS module to a global variable so that we can continue experimenting with compute shader code without needing to rebuild the whole thing.
Download original notebook.esm window.gpuJS = require('./js/gpu.js');
var __getOwnPropNames = Object.getOwnPropertyNames; var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) { if (typeof require !== "undefined") return require.apply(this, arguments); throw Error('Dynamic require of "' + x + '" is not supported'); }); var __commonJS = (cb, mod) => function __require2() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; // js/gpu.js var require_gpu = __commonJS({ "js/gpu.js"(exports, module) { !function(e) { if ("object" == typeof exports && "undefined" != typeof module) module.exports = e(); else if ("function" == typeof define && define.amd) define([], e); else { ("undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this).GPU = e(); } }(function() { return function e(t, r, n) { function i(a2, o) { if (!r[a2]) { if (!t[a2]) { var u = "function" == typeof __require && __require; if (!o && u) return u(a2, true); if (s) return s(a2, true); var l = new Error("Cannot find module '" + a2 + "'"); throw l.code = "MODULE_NOT_FOUND", l; } var h = r[a2] = { exports: {} }; t[a2][0].call(h.exports, function(e2) { return i(t[a2][1][e2] || e2); }, h, h.exports, e, t, r, n); } return r[a2].exports; } for (var s = "function" == typeof __require && __require, a = 0; a < n.length; a++) i(n[a]); return i; }({ 1: [function(e, t, r) { !function(e2, n) { "object" == typeof r && void 0 !== t ? n(r) : n((e2 = "undefined" != typeof globalThis ? globalThis : e2 || self).acorn = {}); }(this, function(e2) { "use strict"; var t2 = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 80, 3, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 343, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 726, 6, 110, 6, 6, 9, 4759, 9, 787719, 239], r2 = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 2, 60, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 42, 9, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 496, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191], n = "\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1878\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C8A\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u31A0-\u31BF\u31F0-\u31FF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CD\uA7D0\uA7D1\uA7D3\uA7D5-\uA7DC\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC", i = { 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile", 5: "class enum extends super const export import", 6: "enum", strict: "implements interface let package private protected public static yield", strictBind: "eval arguments" }, s = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this", a = { 5: s, "5module": s + " export import", 6: s + " const class extends export import super" }, o = /^in(stanceof)?$/, u = new RegExp("[" + n + "]"), l = new RegExp("[" + n + "\u200C\u200D\xB7\u0300-\u036F\u0387\u0483-\u0487\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u0669\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u06F0-\u06F9\u0711\u0730-\u074A\u07A6-\u07B0\u07C0-\u07C9\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u0897-\u089F\u08CA-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0966-\u096F\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09E6-\u09EF\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A66-\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AE6-\u0AEF\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B55-\u0B57\u0B62\u0B63\u0B66-\u0B6F\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0BE6-\u0BEF\u0C00-\u0C04\u0C3C\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0CE6-\u0CEF\u0CF3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D66-\u0D6F\u0D81-\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0E50-\u0E59\u0EB1\u0EB4-\u0EBC\u0EC8-\u0ECE\u0ED0-\u0ED9\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1040-\u1049\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F-\u109D\u135D-\u135F\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u17E0-\u17E9\u180B-\u180D\u180F-\u1819\u18A9\u1920-\u192B\u1930-\u193B\u1946-\u194F\u19D0-\u19DA\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AB0-\u1ABD\u1ABF-\u1ACE\u1B00-\u1B04\u1B34-\u1B44\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BB0-\u1BB9\u1BE6-\u1BF3\u1C24-\u1C37\u1C40-\u1C49\u1C50-\u1C59\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DFF\u200C\u200D\u203F\u2040\u2054\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\u30FB\uA620-\uA629\uA66F\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA82C\uA880\uA881\uA8B4-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F1\uA8FF-\uA909\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9D0-\uA9D9\uA9E5\uA9F0-\uA9F9\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA50-\uAA59\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uABF0-\uABF9\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFF10-\uFF19\uFF3F\uFF65]"); function h(e3, t3) { for (var r3 = 65536, n2 = 0; n2 < t3.length; n2 += 2) { if ((r3 += t3[n2]) > e3) return false; if ((r3 += t3[n2 + 1]) >= e3) return true; } return false; } function c(e3, t3) { return e3 < 65 ? 36 === e3 : e3 < 91 || (e3 < 97 ? 95 === e3 : e3 < 123 || (e3 <= 65535 ? e3 >= 170 && u.test(String.fromCharCode(e3)) : false !== t3 && h(e3, r2))); } function p(e3, n2) { return e3 < 48 ? 36 === e3 : e3 < 58 || !(e3 < 65) && (e3 < 91 || (e3 < 97 ? 95 === e3 : e3 < 123 || (e3 <= 65535 ? e3 >= 170 && l.test(String.fromCharCode(e3)) : false !== n2 && (h(e3, r2) || h(e3, t2))))); } var d = function(e3, t3) { void 0 === t3 && (t3 = {}), this.label = e3, this.keyword = t3.keyword, this.beforeExpr = !!t3.beforeExpr, this.startsExpr = !!t3.startsExpr, this.isLoop = !!t3.isLoop, this.isAssign = !!t3.isAssign, this.prefix = !!t3.prefix, this.postfix = !!t3.postfix, this.binop = t3.binop || null, this.updateContext = null; }; function m(e3, t3) { return new d(e3, { beforeExpr: true, binop: t3 }); } var f = { beforeExpr: true }, g = { startsExpr: true }, x = {}; function y(e3, t3) { return void 0 === t3 && (t3 = {}), t3.keyword = e3, x[e3] = new d(e3, t3); } var b = { num: new d("num", g), regexp: new d("regexp", g), string: new d("string", g), name: new d("name", g), privateId: new d("privateId", g), eof: new d("eof"), bracketL: new d("[", { beforeExpr: true, startsExpr: true }), bracketR: new d("]"), braceL: new d("{", { beforeExpr: true, startsExpr: true }), braceR: new d("}"), parenL: new d("(", { beforeExpr: true, startsExpr: true }), parenR: new d(")"), comma: new d(",", f), semi: new d(";", f), colon: new d(":", f), dot: new d("."), question: new d("?", f), questionDot: new d("?."), arrow: new d("=>", f), template: new d("template"), invalidTemplate: new d("invalidTemplate"), ellipsis: new d("...", f), backQuote: new d("`", g), dollarBraceL: new d("${", { beforeExpr: true, startsExpr: true }), eq: new d("=", { beforeExpr: true, isAssign: true }), assign: new d("_=", { beforeExpr: true, isAssign: true }), incDec: new d("++/--", { prefix: true, postfix: true, startsExpr: true }), prefix: new d("!/~", { beforeExpr: true, prefix: true, startsExpr: true }), logicalOR: m("||", 1), logicalAND: m("&&", 2), bitwiseOR: m("|", 3), bitwiseXOR: m("^", 4), bitwiseAND: m("&", 5), equality: m("==/!=/===/!==", 6), relational: m("</>/<=/>=", 7), bitShift: m("<</>>/>>>", 8), plusMin: new d("+/-", { beforeExpr: true, binop: 9, prefix: true, startsExpr: true }), modulo: m("%", 10), star: m("*", 10), slash: m("/", 10), starstar: new d("**", { beforeExpr: true }), coalesce: m("??", 1), _break: y("break"), _case: y("case", f), _catch: y("catch"), _continue: y("continue"), _debugger: y("debugger"), _default: y("default", f), _do: y("do", { isLoop: true, beforeExpr: true }), _else: y("else", f), _finally: y("finally"), _for: y("for", { isLoop: true }), _function: y("function", g), _if: y("if"), _return: y("return", f), _switch: y("switch"), _throw: y("throw", f), _try: y("try"), _var: y("var"), _const: y("const"), _while: y("while", { isLoop: true }), _with: y("with"), _new: y("new", { beforeExpr: true, startsExpr: true }), _this: y("this", g), _super: y("super", g), _class: y("class", g), _extends: y("extends", f), _export: y("export"), _import: y("import", g), _null: y("null", g), _true: y("true", g), _false: y("false", g), _in: y("in", { beforeExpr: true, binop: 7 }), _instanceof: y("instanceof", { beforeExpr: true, binop: 7 }), _typeof: y("typeof", { beforeExpr: true, prefix: true, startsExpr: true }), _void: y("void", { beforeExpr: true, prefix: true, startsExpr: true }), _delete: y("delete", { beforeExpr: true, prefix: true, startsExpr: true }) }, T = /\r\n?|\n|\u2028|\u2029/, v = new RegExp(T.source, "g"); function S(e3) { return 10 === e3 || 13 === e3 || 8232 === e3 || 8233 === e3; } function A(e3, t3, r3) { void 0 === r3 && (r3 = e3.length); for (var n2 = t3; n2 < r3; n2++) { var i2 = e3.charCodeAt(n2); if (S(i2)) return n2 < r3 - 1 && 13 === i2 && 10 === e3.charCodeAt(n2 + 1) ? n2 + 2 : n2 + 1; } return -1; } var _ = /[\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]/, E = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g, w = Object.prototype, k = w.hasOwnProperty, I = w.toString, D = Object.hasOwn || function(e3, t3) { return k.call(e3, t3); }, C = Array.isArray || function(e3) { return "[object Array]" === I.call(e3); }, $ = /* @__PURE__ */ Object.create(null); function L(e3) { return $[e3] || ($[e3] = new RegExp("^(?:" + e3.replace(/ /g, "|") + ")$")); } function R(e3) { return e3 <= 65535 ? String.fromCharCode(e3) : (e3 -= 65536, String.fromCharCode(55296 + (e3 >> 10), 56320 + (1023 & e3))); } var F = /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/, N = function(e3, t3) { this.line = e3, this.column = t3; }; N.prototype.offset = function(e3) { return new N(this.line, this.column + e3); }; var V = function(e3, t3, r3) { this.start = t3, this.end = r3, null !== e3.sourceFile && (this.source = e3.sourceFile); }; function M(e3, t3) { for (var r3 = 1, n2 = 0; ; ) { var i2 = A(e3, n2, t3); if (i2 < 0) return new N(r3, t3 - n2); ++r3, n2 = i2; } } var O = { ecmaVersion: null, sourceType: "script", onInsertedSemicolon: null, onTrailingComma: null, allowReserved: null, allowReturnOutsideFunction: false, allowImportExportEverywhere: false, allowAwaitOutsideFunction: null, allowSuperOutsideMethod: null, allowHashBang: false, checkPrivateFields: true, locations: false, onToken: null, onComment: null, ranges: false, program: null, sourceFile: null, directSourceFile: null, preserveParens: false }, z = false; function P(e3) { var t3 = {}; for (var r3 in O) t3[r3] = e3 && D(e3, r3) ? e3[r3] : O[r3]; if ("latest" === t3.ecmaVersion ? t3.ecmaVersion = 1e8 : null == t3.ecmaVersion ? (!z && "object" == typeof console && console.warn && (z = true, console.warn("Since Acorn 8.0.0, options.ecmaVersion is required.\nDefaulting to 2020, but this will stop working in the future.")), t3.ecmaVersion = 11) : t3.ecmaVersion >= 2015 && (t3.ecmaVersion -= 2009), null == t3.allowReserved && (t3.allowReserved = t3.ecmaVersion < 5), e3 && null != e3.allowHashBang || (t3.allowHashBang = t3.ecmaVersion >= 14), C(t3.onToken)) { var n2 = t3.onToken; t3.onToken = function(e4) { return n2.push(e4); }; } return C(t3.onComment) && (t3.onComment = /* @__PURE__ */ function(e4, t4) { return function(r4, n3, i2, s2, a2, o2) { var u2 = { type: r4 ? "Block" : "Line", value: n3, start: i2, end: s2 }; e4.locations && (u2.loc = new V(this, a2, o2)), e4.ranges && (u2.range = [i2, s2]), t4.push(u2); }; }(t3, t3.onComment)), t3; } var K = 256; function G(e3, t3) { return 2 | (e3 ? 4 : 0) | (t3 ? 8 : 0); } var U = function(e3, t3, r3) { this.options = e3 = P(e3), this.sourceFile = e3.sourceFile, this.keywords = L(a[e3.ecmaVersion >= 6 ? 6 : "module" === e3.sourceType ? "5module" : 5]); var n2 = ""; true !== e3.allowReserved && (n2 = i[e3.ecmaVersion >= 6 ? 6 : 5 === e3.ecmaVersion ? 5 : 3], "module" === e3.sourceType && (n2 += " await")), this.reservedWords = L(n2); var s2 = (n2 ? n2 + " " : "") + i.strict; this.reservedWordsStrict = L(s2), this.reservedWordsStrictBind = L(s2 + " " + i.strictBind), this.input = String(t3), this.containsEsc = false, r3 ? (this.pos = r3, this.lineStart = this.input.lastIndexOf("\n", r3 - 1) + 1, this.curLine = this.input.slice(0, this.lineStart).split(T).length) : (this.pos = this.lineStart = 0, this.curLine = 1), this.type = b.eof, this.value = null, this.start = this.end = this.pos, this.startLoc = this.endLoc = this.curPosition(), this.lastTokEndLoc = this.lastTokStartLoc = null, this.lastTokStart = this.lastTokEnd = this.pos, this.context = this.initialContext(), this.exprAllowed = true, this.inModule = "module" === e3.sourceType, this.strict = this.inModule || this.strictDirective(this.pos), this.potentialArrowAt = -1, this.potentialArrowInForAwait = false, this.yieldPos = this.awaitPos = this.awaitIdentPos = 0, this.labels = [], this.undefinedExports = /* @__PURE__ */ Object.create(null), 0 === this.pos && e3.allowHashBang && "#!" === this.input.slice(0, 2) && this.skipLineComment(2), this.scopeStack = [], this.enterScope(1), this.regexpState = null, this.privateNameStack = []; }, B = { inFunction: { configurable: true }, inGenerator: { configurable: true }, inAsync: { configurable: true }, canAwait: { configurable: true }, allowSuper: { configurable: true }, allowDirectSuper: { configurable: true }, treatFunctionsAsVar: { configurable: true }, allowNewDotTarget: { configurable: true }, inClassStaticBlock: { configurable: true } }; U.prototype.parse = function() { var e3 = this.options.program || this.startNode(); return this.nextToken(), this.parseTopLevel(e3); }, B.inFunction.get = function() { return (2 & this.currentVarScope().flags) > 0; }, B.inGenerator.get = function() { return (8 & this.currentVarScope().flags) > 0 && !this.currentVarScope().inClassFieldInit; }, B.inAsync.get = function() { return (4 & this.currentVarScope().flags) > 0 && !this.currentVarScope().inClassFieldInit; }, B.canAwait.get = function() { for (var e3 = this.scopeStack.length - 1; e3 >= 0; e3--) { var t3 = this.scopeStack[e3]; if (t3.inClassFieldInit || t3.flags & K) return false; if (2 & t3.flags) return (4 & t3.flags) > 0; } return this.inModule && this.options.ecmaVersion >= 13 || this.options.allowAwaitOutsideFunction; }, B.allowSuper.get = function() { var e3 = this.currentThisScope(), t3 = e3.flags, r3 = e3.inClassFieldInit; return (64 & t3) > 0 || r3 || this.options.allowSuperOutsideMethod; }, B.allowDirectSuper.get = function() { return (128 & this.currentThisScope().flags) > 0; }, B.treatFunctionsAsVar.get = function() { return this.treatFunctionsAsVarInScope(this.currentScope()); }, B.allowNewDotTarget.get = function() { var e3 = this.currentThisScope(), t3 = e3.flags, r3 = e3.inClassFieldInit; return (258 & t3) > 0 || r3; }, B.inClassStaticBlock.get = function() { return (this.currentVarScope().flags & K) > 0; }, U.extend = function() { for (var e3 = [], t3 = arguments.length; t3--; ) e3[t3] = arguments[t3]; for (var r3 = this, n2 = 0; n2 < e3.length; n2++) r3 = e3[n2](r3); return r3; }, U.parse = function(e3, t3) { return new this(t3, e3).parse(); }, U.parseExpressionAt = function(e3, t3, r3) { var n2 = new this(r3, e3, t3); return n2.nextToken(), n2.parseExpression(); }, U.tokenizer = function(e3, t3) { return new this(t3, e3); }, Object.defineProperties(U.prototype, B); var W = U.prototype, j = /^(?:'((?:\\[^]|[^'\\])*?)'|"((?:\\[^]|[^"\\])*?)")/; W.strictDirective = function(e3) { if (this.options.ecmaVersion < 5) return false; for (; ; ) { E.lastIndex = e3, e3 += E.exec(this.input)[0].length; var t3 = j.exec(this.input.slice(e3)); if (!t3) return false; if ("use strict" === (t3[1] || t3[2])) { E.lastIndex = e3 + t3[0].length; var r3 = E.exec(this.input), n2 = r3.index + r3[0].length, i2 = this.input.charAt(n2); return ";" === i2 || "}" === i2 || T.test(r3[0]) && !(/[(`.[+\-/*%<>=,?^&]/.test(i2) || "!" === i2 && "=" === this.input.charAt(n2 + 1)); } e3 += t3[0].length, E.lastIndex = e3, e3 += E.exec(this.input)[0].length, ";" === this.input[e3] && e3++; } }, W.eat = function(e3) { return this.type === e3 && (this.next(), true); }, W.isContextual = function(e3) { return this.type === b.name && this.value === e3 && !this.containsEsc; }, W.eatContextual = function(e3) { return !!this.isContextual(e3) && (this.next(), true); }, W.expectContextual = function(e3) { this.eatContextual(e3) || this.unexpected(); }, W.canInsertSemicolon = function() { return this.type === b.eof || this.type === b.braceR || T.test(this.input.slice(this.lastTokEnd, this.start)); }, W.insertSemicolon = function() { if (this.canInsertSemicolon()) return this.options.onInsertedSemicolon && this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc), true; }, W.semicolon = function() { this.eat(b.semi) || this.insertSemicolon() || this.unexpected(); }, W.afterTrailingComma = function(e3, t3) { if (this.type === e3) return this.options.onTrailingComma && this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc), t3 || this.next(), true; }, W.expect = function(e3) { this.eat(e3) || this.unexpected(); }, W.unexpected = function(e3) { this.raise(null != e3 ? e3 : this.start, "Unexpected token"); }; var H = function() { this.shorthandAssign = this.trailingComma = this.parenthesizedAssign = this.parenthesizedBind = this.doubleProto = -1; }; W.checkPatternErrors = function(e3, t3) { if (e3) { e3.trailingComma > -1 && this.raiseRecoverable(e3.trailingComma, "Comma is not permitted after the rest element"); var r3 = t3 ? e3.parenthesizedAssign : e3.parenthesizedBind; r3 > -1 && this.raiseRecoverable(r3, t3 ? "Assigning to rvalue" : "Parenthesized pattern"); } }, W.checkExpressionErrors = function(e3, t3) { if (!e3) return false; var r3 = e3.shorthandAssign, n2 = e3.doubleProto; if (!t3) return r3 >= 0 || n2 >= 0; r3 >= 0 && this.raise(r3, "Shorthand property assignments are valid only in destructuring patterns"), n2 >= 0 && this.raiseRecoverable(n2, "Redefinition of __proto__ property"); }, W.checkYieldAwaitInDefaultParams = function() { this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos) && this.raise(this.yieldPos, "Yield expression cannot be a default value"), this.awaitPos && this.raise(this.awaitPos, "Await expression cannot be a default value"); }, W.isSimpleAssignTarget = function(e3) { return "ParenthesizedExpression" === e3.type ? this.isSimpleAssignTarget(e3.expression) : "Identifier" === e3.type || "MemberExpression" === e3.type; }; var X = U.prototype; X.parseTopLevel = function(e3) { var t3 = /* @__PURE__ */ Object.create(null); for (e3.body || (e3.body = []); this.type !== b.eof; ) { var r3 = this.parseStatement(null, true, t3); e3.body.push(r3); } if (this.inModule) for (var n2 = 0, i2 = Object.keys(this.undefinedExports); n2 < i2.length; n2 += 1) { var s2 = i2[n2]; this.raiseRecoverable(this.undefinedExports[s2].start, "Export '" + s2 + "' is not defined"); } return this.adaptDirectivePrologue(e3.body), this.next(), e3.sourceType = this.options.sourceType, this.finishNode(e3, "Program"); }; var q = { kind: "loop" }, Y = { kind: "switch" }; X.isLet = function(e3) { if (this.options.ecmaVersion < 6 || !this.isContextual("let")) return false; E.lastIndex = this.pos; var t3 = E.exec(this.input), r3 = this.pos + t3[0].length, n2 = this.input.charCodeAt(r3); if (91 === n2 || 92 === n2) return true; if (e3) return false; if (123 === n2 || n2 > 55295 && n2 < 56320) return true; if (c(n2, true)) { for (var i2 = r3 + 1; p(n2 = this.input.charCodeAt(i2), true); ) ++i2; if (92 === n2 || n2 > 55295 && n2 < 56320) return true; var s2 = this.input.slice(r3, i2); if (!o.test(s2)) return true; } return false; }, X.isAsyncFunction = function() { if (this.options.ecmaVersion < 8 || !this.isContextual("async")) return false; E.lastIndex = this.pos; var e3, t3 = E.exec(this.input), r3 = this.pos + t3[0].length; return !(T.test(this.input.slice(this.pos, r3)) || "function" !== this.input.slice(r3, r3 + 8) || r3 + 8 !== this.input.length && (p(e3 = this.input.charCodeAt(r3 + 8)) || e3 > 55295 && e3 < 56320)); }, X.parseStatement = function(e3, t3, r3) { var n2, i2 = this.type, s2 = this.startNode(); switch (this.isLet(e3) && (i2 = b._var, n2 = "let"), i2) { case b._break: case b._continue: return this.parseBreakContinueStatement(s2, i2.keyword); case b._debugger: return this.parseDebuggerStatement(s2); case b._do: return this.parseDoStatement(s2); case b._for: return this.parseForStatement(s2); case b._function: return e3 && (this.strict || "if" !== e3 && "label" !== e3) && this.options.ecmaVersion >= 6 && this.unexpected(), this.parseFunctionStatement(s2, false, !e3); case b._class: return e3 && this.unexpected(), this.parseClass(s2, true); case b._if: return this.parseIfStatement(s2); case b._return: return this.parseReturnStatement(s2); case b._switch: return this.parseSwitchStatement(s2); case b._throw: return this.parseThrowStatement(s2); case b._try: return this.parseTryStatement(s2); case b._const: case b._var: return n2 = n2 || this.value, e3 && "var" !== n2 && this.unexpected(), this.parseVarStatement(s2, n2); case b._while: return this.parseWhileStatement(s2); case b._with: return this.parseWithStatement(s2); case b.braceL: return this.parseBlock(true, s2); case b.semi: return this.parseEmptyStatement(s2); case b._export: case b._import: if (this.options.ecmaVersion > 10 && i2 === b._import) { E.lastIndex = this.pos; var a2 = E.exec(this.input), o2 = this.pos + a2[0].length, u2 = this.input.charCodeAt(o2); if (40 === u2 || 46 === u2) return this.parseExpressionStatement(s2, this.parseExpression()); } return this.options.allowImportExportEverywhere || (t3 || this.raise(this.start, "'import' and 'export' may only appear at the top level"), this.inModule || this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'")), i2 === b._import ? this.parseImport(s2) : this.parseExport(s2, r3); default: if (this.isAsyncFunction()) return e3 && this.unexpected(), this.next(), this.parseFunctionStatement(s2, true, !e3); var l2 = this.value, h2 = this.parseExpression(); return i2 === b.name && "Identifier" === h2.type && this.eat(b.colon) ? this.parseLabeledStatement(s2, l2, h2, e3) : this.parseExpressionStatement(s2, h2); } }, X.parseBreakContinueStatement = function(e3, t3) { var r3 = "break" === t3; this.next(), this.eat(b.semi) || this.insertSemicolon() ? e3.label = null : this.type !== b.name ? this.unexpected() : (e3.label = this.parseIdent(), this.semicolon()); for (var n2 = 0; n2 < this.labels.length; ++n2) { var i2 = this.labels[n2]; if (null == e3.label || i2.name === e3.label.name) { if (null != i2.kind && (r3 || "loop" === i2.kind)) break; if (e3.label && r3) break; } } return n2 === this.labels.length && this.raise(e3.start, "Unsyntactic " + t3), this.finishNode(e3, r3 ? "BreakStatement" : "ContinueStatement"); }, X.parseDebuggerStatement = function(e3) { return this.next(), this.semicolon(), this.finishNode(e3, "DebuggerStatement"); }, X.parseDoStatement = function(e3) { return this.next(), this.labels.push(q), e3.body = this.parseStatement("do"), this.labels.pop(), this.expect(b._while), e3.test = this.parseParenExpression(), this.options.ecmaVersion >= 6 ? this.eat(b.semi) : this.semicolon(), this.finishNode(e3, "DoWhileStatement"); }, X.parseForStatement = function(e3) { this.next(); var t3 = this.options.ecmaVersion >= 9 && this.canAwait && this.eatContextual("await") ? this.lastTokStart : -1; if (this.labels.push(q), this.enterScope(0), this.expect(b.parenL), this.type === b.semi) return t3 > -1 && this.unexpected(t3), this.parseFor(e3, null); var r3 = this.isLet(); if (this.type === b._var || this.type === b._const || r3) { var n2 = this.startNode(), i2 = r3 ? "let" : this.value; return this.next(), this.parseVar(n2, true, i2), this.finishNode(n2, "VariableDeclaration"), (this.type === b._in || this.options.ecmaVersion >= 6 && this.isContextual("of")) && 1 === n2.declarations.length ? (this.options.ecmaVersion >= 9 && (this.type === b._in ? t3 > -1 && this.unexpected(t3) : e3.await = t3 > -1), this.parseForIn(e3, n2)) : (t3 > -1 && this.unexpected(t3), this.parseFor(e3, n2)); } var s2 = this.isContextual("let"), a2 = false, o2 = this.containsEsc, u2 = new H(), l2 = this.start, h2 = t3 > -1 ? this.parseExprSubscripts(u2, "await") : this.parseExpression(true, u2); return this.type === b._in || (a2 = this.options.ecmaVersion >= 6 && this.isContextual("of")) ? (t3 > -1 ? (this.type === b._in && this.unexpected(t3), e3.await = true) : a2 && this.options.ecmaVersion >= 8 && (h2.start !== l2 || o2 || "Identifier" !== h2.type || "async" !== h2.name ? this.options.ecmaVersion >= 9 && (e3.await = false) : this.unexpected()), s2 && a2 && this.raise(h2.start, "The left-hand side of a for-of loop may not start with 'let'."), this.toAssignable(h2, false, u2), this.checkLValPattern(h2), this.parseForIn(e3, h2)) : (this.checkExpressionErrors(u2, true), t3 > -1 && this.unexpected(t3), this.parseFor(e3, h2)); }, X.parseFunctionStatement = function(e3, t3, r3) { return this.next(), this.parseFunction(e3, J | (r3 ? 0 : Q), false, t3); }, X.parseIfStatement = function(e3) { return this.next(), e3.test = this.parseParenExpression(), e3.consequent = this.parseStatement("if"), e3.alternate = this.eat(b._else) ? this.parseStatement("if") : null, this.finishNode(e3, "IfStatement"); }, X.parseReturnStatement = function(e3) { return this.inFunction || this.options.allowReturnOutsideFunction || this.raise(this.start, "'return' outside of function"), this.next(), this.eat(b.semi) || this.insertSemicolon() ? e3.argument = null : (e3.argument = this.parseExpression(), this.semicolon()), this.finishNode(e3, "ReturnStatement"); }, X.parseSwitchStatement = function(e3) { var t3; this.next(), e3.discriminant = this.parseParenExpression(), e3.cases = [], this.expect(b.braceL), this.labels.push(Y), this.enterScope(0); for (var r3 = false; this.type !== b.braceR; ) if (this.type === b._case || this.type === b._default) { var n2 = this.type === b._case; t3 && this.finishNode(t3, "SwitchCase"), e3.cases.push(t3 = this.startNode()), t3.consequent = [], this.next(), n2 ? t3.test = this.parseExpression() : (r3 && this.raiseRecoverable(this.lastTokStart, "Multiple default clauses"), r3 = true, t3.test = null), this.expect(b.colon); } else t3 || this.unexpected(), t3.consequent.push(this.parseStatement(null)); return this.exitScope(), t3 && this.finishNode(t3, "SwitchCase"), this.next(), this.labels.pop(), this.finishNode(e3, "SwitchStatement"); }, X.parseThrowStatement = function(e3) { return this.next(), T.test(this.input.slice(this.lastTokEnd, this.start)) && this.raise(this.lastTokEnd, "Illegal newline after throw"), e3.argument = this.parseExpression(), this.semicolon(), this.finishNode(e3, "ThrowStatement"); }; var Z = []; X.parseCatchClauseParam = function() { var e3 = this.parseBindingAtom(), t3 = "Identifier" === e3.type; return this.enterScope(t3 ? 32 : 0), this.checkLValPattern(e3, t3 ? 4 : 2), this.expect(b.parenR), e3; }, X.parseTryStatement = function(e3) { if (this.next(), e3.block = this.parseBlock(), e3.handler = null, this.type === b._catch) { var t3 = this.startNode(); this.next(), this.eat(b.parenL) ? t3.param = this.parseCatchClauseParam() : (this.options.ecmaVersion < 10 && this.unexpected(), t3.param = null, this.enterScope(0)), t3.body = this.parseBlock(false), this.exitScope(), e3.handler = this.finishNode(t3, "CatchClause"); } return e3.finalizer = this.eat(b._finally) ? this.parseBlock() : null, e3.handler || e3.finalizer || this.raise(e3.start, "Missing catch or finally clause"), this.finishNode(e3, "TryStatement"); }, X.parseVarStatement = function(e3, t3, r3) { return this.next(), this.parseVar(e3, false, t3, r3), this.semicolon(), this.finishNode(e3, "VariableDeclaration"); }, X.parseWhileStatement = function(e3) { return this.next(), e3.test = this.parseParenExpression(), this.labels.push(q), e3.body = this.parseStatement("while"), this.labels.pop(), this.finishNode(e3, "WhileStatement"); }, X.parseWithStatement = function(e3) { return this.strict && this.raise(this.start, "'with' in strict mode"), this.next(), e3.object = this.parseParenExpression(), e3.body = this.parseStatement("with"), this.finishNode(e3, "WithStatement"); }, X.parseEmptyStatement = function(e3) { return this.next(), this.finishNode(e3, "EmptyStatement"); }, X.parseLabeledStatement = function(e3, t3, r3, n2) { for (var i2 = 0, s2 = this.labels; i2 < s2.length; i2 += 1) { s2[i2].name === t3 && this.raise(r3.start, "Label '" + t3 + "' is already declared"); } for (var a2 = this.type.isLoop ? "loop" : this.type === b._switch ? "switch" : null, o2 = this.labels.length - 1; o2 >= 0; o2--) { var u2 = this.labels[o2]; if (u2.statementStart !== e3.start) break; u2.statementStart = this.start, u2.kind = a2; } return this.labels.push({ name: t3, kind: a2, statementStart: this.start }), e3.body = this.parseStatement(n2 ? -1 === n2.indexOf("label") ? n2 + "label" : n2 : "label"), this.labels.pop(), e3.label = r3, this.finishNode(e3, "LabeledStatement"); }, X.parseExpressionStatement = function(e3, t3) { return e3.expression = t3, this.semicolon(), this.finishNode(e3, "ExpressionStatement"); }, X.parseBlock = function(e3, t3, r3) { for (void 0 === e3 && (e3 = true), void 0 === t3 && (t3 = this.startNode()), t3.body = [], this.expect(b.braceL), e3 && this.enterScope(0); this.type !== b.braceR; ) { var n2 = this.parseStatement(null); t3.body.push(n2); } return r3 && (this.strict = false), this.next(), e3 && this.exitScope(), this.finishNode(t3, "BlockStatement"); }, X.parseFor = function(e3, t3) { return e3.init = t3, this.expect(b.semi), e3.test = this.type === b.semi ? null : this.parseExpression(), this.expect(b.semi), e3.update = this.type === b.parenR ? null : this.parseExpression(), this.expect(b.parenR), e3.body = this.parseStatement("for"), this.exitScope(), this.labels.pop(), this.finishNode(e3, "ForStatement"); }, X.parseForIn = function(e3, t3) { var r3 = this.type === b._in; return this.next(), "VariableDeclaration" === t3.type && null != t3.declarations[0].init && (!r3 || this.options.ecmaVersion < 8 || this.strict || "var" !== t3.kind || "Identifier" !== t3.declarations[0].id.type) && this.raise(t3.start, (r3 ? "for-in" : "for-of") + " loop variable declaration may not have an initializer"), e3.left = t3, e3.right = r3 ? this.parseExpression() : this.parseMaybeAssign(), this.expect(b.parenR), e3.body = this.parseStatement("for"), this.exitScope(), this.labels.pop(), this.finishNode(e3, r3 ? "ForInStatement" : "ForOfStatement"); }, X.parseVar = function(e3, t3, r3, n2) { for (e3.declarations = [], e3.kind = r3; ; ) { var i2 = this.startNode(); if (this.parseVarId(i2, r3), this.eat(b.eq) ? i2.init = this.parseMaybeAssign(t3) : n2 || "const" !== r3 || this.type === b._in || this.options.ecmaVersion >= 6 && this.isContextual("of") ? n2 || "Identifier" === i2.id.type || t3 && (this.type === b._in || this.isContextual("of")) ? i2.init = null : this.raise(this.lastTokEnd, "Complex binding patterns require an initialization value") : this.unexpected(), e3.declarations.push(this.finishNode(i2, "VariableDeclarator")), !this.eat(b.comma)) break; } return e3; }, X.parseVarId = function(e3, t3) { e3.id = this.parseBindingAtom(), this.checkLValPattern(e3.id, "var" === t3 ? 1 : 2, false); }; var J = 1, Q = 2; function ee(e3, t3) { var r3 = t3.key.name, n2 = e3[r3], i2 = "true"; return "MethodDefinition" !== t3.type || "get" !== t3.kind && "set" !== t3.kind || (i2 = (t3.static ? "s" : "i") + t3.kind), "iget" === n2 && "iset" === i2 || "iset" === n2 && "iget" === i2 || "sget" === n2 && "sset" === i2 || "sset" === n2 && "sget" === i2 ? (e3[r3] = "true", false) : !!n2 || (e3[r3] = i2, false); } function te(e3, t3) { var r3 = e3.computed, n2 = e3.key; return !r3 && ("Identifier" === n2.type && n2.name === t3 || "Literal" === n2.type && n2.value === t3); } X.parseFunction = function(e3, t3, r3, n2, i2) { this.initFunction(e3), (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !n2) && (this.type === b.star && t3 & Q && this.unexpected(), e3.generator = this.eat(b.star)), this.options.ecmaVersion >= 8 && (e3.async = !!n2), t3 & J && (e3.id = 4 & t3 && this.type !== b.name ? null : this.parseIdent(), !e3.id || t3 & Q || this.checkLValSimple(e3.id, this.strict || e3.generator || e3.async ? this.treatFunctionsAsVar ? 1 : 2 : 3)); var s2 = this.yieldPos, a2 = this.awaitPos, o2 = this.awaitIdentPos; return this.yieldPos = 0, this.awaitPos = 0, this.awaitIdentPos = 0, this.enterScope(G(e3.async, e3.generator)), t3 & J || (e3.id = this.type === b.name ? this.parseIdent() : null), this.parseFunctionParams(e3), this.parseFunctionBody(e3, r3, false, i2), this.yieldPos = s2, this.awaitPos = a2, this.awaitIdentPos = o2, this.finishNode(e3, t3 & J ? "FunctionDeclaration" : "FunctionExpression"); }, X.parseFunctionParams = function(e3) { this.expect(b.parenL), e3.params = this.parseBindingList(b.parenR, false, this.options.ecmaVersion >= 8), this.checkYieldAwaitInDefaultParams(); }, X.parseClass = function(e3, t3) { this.next(); var r3 = this.strict; this.strict = true, this.parseClassId(e3, t3), this.parseClassSuper(e3); var n2 = this.enterClassBody(), i2 = this.startNode(), s2 = false; for (i2.body = [], this.expect(b.braceL); this.type !== b.braceR; ) { var a2 = this.parseClassElement(null !== e3.superClass); a2 && (i2.body.push(a2), "MethodDefinition" === a2.type && "constructor" === a2.kind ? (s2 && this.raiseRecoverable(a2.start, "Duplicate constructor in the same class"), s2 = true) : a2.key && "PrivateIdentifier" === a2.key.type && ee(n2, a2) && this.raiseRecoverable(a2.key.start, "Identifier '#" + a2.key.name + "' has already been declared")); } return this.strict = r3, this.next(), e3.body = this.finishNode(i2, "ClassBody"), this.exitClassBody(), this.finishNode(e3, t3 ? "ClassDeclaration" : "ClassExpression"); }, X.parseClassElement = function(e3) { if (this.eat(b.semi)) return null; var t3 = this.options.ecmaVersion, r3 = this.startNode(), n2 = "", i2 = false, s2 = false, a2 = "method", o2 = false; if (this.eatContextual("static")) { if (t3 >= 13 && this.eat(b.braceL)) return this.parseClassStaticBlock(r3), r3; this.isClassElementNameStart() || this.type === b.star ? o2 = true : n2 = "static"; } if (r3.static = o2, !n2 && t3 >= 8 && this.eatContextual("async") && (!this.isClassElementNameStart() && this.type !== b.star || this.canInsertSemicolon() ? n2 = "async" : s2 = true), !n2 && (t3 >= 9 || !s2) && this.eat(b.star) && (i2 = true), !n2 && !s2 && !i2) { var u2 = this.value; (this.eatContextual("get") || this.eatContextual("set")) && (this.isClassElementNameStart() ? a2 = u2 : n2 = u2); } if (n2 ? (r3.computed = false, r3.key = this.startNodeAt(this.lastTokStart, this.lastTokStartLoc), r3.key.name = n2, this.finishNode(r3.key, "Identifier")) : this.parseClassElementName(r3), t3 < 13 || this.type === b.parenL || "method" !== a2 || i2 || s2) { var l2 = !r3.static && te(r3, "constructor"), h2 = l2 && e3; l2 && "method" !== a2 && this.raise(r3.key.start, "Constructor can't have get/set modifier"), r3.kind = l2 ? "constructor" : a2, this.parseClassMethod(r3, i2, s2, h2); } else this.parseClassField(r3); return r3; }, X.isClassElementNameStart = function() { return this.type === b.name || this.type === b.privateId || this.type === b.num || this.type === b.string || this.type === b.bracketL || this.type.keyword; }, X.parseClassElementName = function(e3) { this.type === b.privateId ? ("constructor" === this.value && this.raise(this.start, "Classes can't have an element named '#constructor'"), e3.computed = false, e3.key = this.parsePrivateIdent()) : this.parsePropertyName(e3); }, X.parseClassMethod = function(e3, t3, r3, n2) { var i2 = e3.key; "constructor" === e3.kind ? (t3 && this.raise(i2.start, "Constructor can't be a generator"), r3 && this.raise(i2.start, "Constructor can't be an async method")) : e3.static && te(e3, "prototype") && this.raise(i2.start, "Classes may not have a static property named prototype"); var s2 = e3.value = this.parseMethod(t3, r3, n2); return "get" === e3.kind && 0 !== s2.params.length && this.raiseRecoverable(s2.start, "getter should have no params"), "set" === e3.kind && 1 !== s2.params.length && this.raiseRecoverable(s2.start, "setter should have exactly one param"), "set" === e3.kind && "RestElement" === s2.params[0].type && this.raiseRecoverable(s2.params[0].start, "Setter cannot use rest params"), this.finishNode(e3, "MethodDefinition"); }, X.parseClassField = function(e3) { if (te(e3, "constructor") ? this.raise(e3.key.start, "Classes can't have a field named 'constructor'") : e3.static && te(e3, "prototype") && this.raise(e3.key.start, "Classes can't have a static field named 'prototype'"), this.eat(b.eq)) { var t3 = this.currentThisScope(), r3 = t3.inClassFieldInit; t3.inClassFieldInit = true, e3.value = this.parseMaybeAssign(), t3.inClassFieldInit = r3; } else e3.value = null; return this.semicolon(), this.finishNode(e3, "PropertyDefinition"); }, X.parseClassStaticBlock = function(e3) { e3.body = []; var t3 = this.labels; for (this.labels = [], this.enterScope(320); this.type !== b.braceR; ) { var r3 = this.parseStatement(null); e3.body.push(r3); } return this.next(), this.exitScope(), this.labels = t3, this.finishNode(e3, "StaticBlock"); }, X.parseClassId = function(e3, t3) { this.type === b.name ? (e3.id = this.parseIdent(), t3 && this.checkLValSimple(e3.id, 2, false)) : (true === t3 && this.unexpected(), e3.id = null); }, X.parseClassSuper = function(e3) { e3.superClass = this.eat(b._extends) ? this.parseExprSubscripts(null, false) : null; }, X.enterClassBody = function() { var e3 = { declared: /* @__PURE__ */ Object.create(null), used: [] }; return this.privateNameStack.push(e3), e3.declared; }, X.exitClassBody = function() { var e3 = this.privateNameStack.pop(), t3 = e3.declared, r3 = e3.used; if (this.options.checkPrivateFields) for (var n2 = this.privateNameStack.length, i2 = 0 === n2 ? null : this.privateNameStack[n2 - 1], s2 = 0; s2 < r3.length; ++s2) { var a2 = r3[s2]; D(t3, a2.name) || (i2 ? i2.used.push(a2) : this.raiseRecoverable(a2.start, "Private field '#" + a2.name + "' must be declared in an enclosing class")); } }, X.parseExportAllDeclaration = function(e3, t3) { return this.options.ecmaVersion >= 11 && (this.eatContextual("as") ? (e3.exported = this.parseModuleExportName(), this.checkExport(t3, e3.exported, this.lastTokStart)) : e3.exported = null), this.expectContextual("from"), this.type !== b.string && this.unexpected(), e3.source = this.parseExprAtom(), this.options.ecmaVersion >= 16 && (e3.attributes = this.parseWithClause()), this.semicolon(), this.finishNode(e3, "ExportAllDeclaration"); }, X.parseExport = function(e3, t3) { if (this.next(), this.eat(b.star)) return this.parseExportAllDeclaration(e3, t3); if (this.eat(b._default)) return this.checkExport(t3, "default", this.lastTokStart), e3.declaration = this.parseExportDefaultDeclaration(), this.finishNode(e3, "ExportDefaultDeclaration"); if (this.shouldParseExportStatement()) e3.declaration = this.parseExportDeclaration(e3), "VariableDeclaration" === e3.declaration.type ? this.checkVariableExport(t3, e3.declaration.declarations) : this.checkExport(t3, e3.declaration.id, e3.declaration.id.start), e3.specifiers = [], e3.source = null; else { if (e3.declaration = null, e3.specifiers = this.parseExportSpecifiers(t3), this.eatContextual("from")) this.type !== b.string && this.unexpected(), e3.source = this.parseExprAtom(), this.options.ecmaVersion >= 16 && (e3.attributes = this.parseWithClause()); else { for (var r3 = 0, n2 = e3.specifiers; r3 < n2.length; r3 += 1) { var i2 = n2[r3]; this.checkUnreserved(i2.local), this.checkLocalExport(i2.local), "Literal" === i2.local.type && this.raise(i2.local.start, "A string literal cannot be used as an exported binding without `from`."); } e3.source = null; } this.semicolon(); } return this.finishNode(e3, "ExportNamedDeclaration"); }, X.parseExportDeclaration = function(e3) { return this.parseStatement(null); }, X.parseExportDefaultDeclaration = function() { var e3; if (this.type === b._function || (e3 = this.isAsyncFunction())) { var t3 = this.startNode(); return this.next(), e3 && this.next(), this.parseFunction(t3, 4 | J, false, e3); } if (this.type === b._class) { var r3 = this.startNode(); return this.parseClass(r3, "nullableID"); } var n2 = this.parseMaybeAssign(); return this.semicolon(), n2; }, X.checkExport = function(e3, t3, r3) { e3 && ("string" != typeof t3 && (t3 = "Identifier" === t3.type ? t3.name : t3.value), D(e3, t3) && this.raiseRecoverable(r3, "Duplicate export '" + t3 + "'"), e3[t3] = true); }, X.checkPatternExport = function(e3, t3) { var r3 = t3.type; if ("Identifier" === r3) this.checkExport(e3, t3, t3.start); else if ("ObjectPattern" === r3) for (var n2 = 0, i2 = t3.properties; n2 < i2.length; n2 += 1) { var s2 = i2[n2]; this.checkPatternExport(e3, s2); } else if ("ArrayPattern" === r3) for (var a2 = 0, o2 = t3.elements; a2 < o2.length; a2 += 1) { var u2 = o2[a2]; u2 && this.checkPatternExport(e3, u2); } else "Property" === r3 ? this.checkPatternExport(e3, t3.value) : "AssignmentPattern" === r3 ? this.checkPatternExport(e3, t3.left) : "RestElement" === r3 && this.checkPatternExport(e3, t3.argument); }, X.checkVariableExport = function(e3, t3) { if (e3) for (var r3 = 0, n2 = t3; r3 < n2.length; r3 += 1) { var i2 = n2[r3]; this.checkPatternExport(e3, i2.id); } }, X.shouldParseExportStatement = function() { return "var" === this.type.keyword || "const" === this.type.keyword || "class" === this.type.keyword || "function" === this.type.keyword || this.isLet() || this.isAsyncFunction(); }, X.parseExportSpecifier = function(e3) { var t3 = this.startNode(); return t3.local = this.parseModuleExportName(), t3.exported = this.eatContextual("as") ? this.parseModuleExportName() : t3.local, this.checkExport(e3, t3.exported, t3.exported.start), this.finishNode(t3, "ExportSpecifier"); }, X.parseExportSpecifiers = function(e3) { var t3 = [], r3 = true; for (this.expect(b.braceL); !this.eat(b.braceR); ) { if (r3) r3 = false; else if (this.expect(b.comma), this.afterTrailingComma(b.braceR)) break; t3.push(this.parseExportSpecifier(e3)); } return t3; }, X.parseImport = function(e3) { return this.next(), this.type === b.string ? (e3.specifiers = Z, e3.source = this.parseExprAtom()) : (e3.specifiers = this.parseImportSpecifiers(), this.expectContextual("from"), e3.source = this.type === b.string ? this.parseExprAtom() : this.unexpected()), this.options.ecmaVersion >= 16 && (e3.attributes = this.parseWithClause()), this.semicolon(), this.finishNode(e3, "ImportDeclaration"); }, X.parseImportSpecifier = function() { var e3 = this.startNode(); return e3.imported = this.parseModuleExportName(), this.eatContextual("as") ? e3.local = this.parseIdent() : (this.checkUnreserved(e3.imported), e3.local = e3.imported), this.checkLValSimple(e3.local, 2), this.finishNode(e3, "ImportSpecifier"); }, X.parseImportDefaultSpecifier = function() { var e3 = this.startNode(); return e3.local = this.parseIdent(), this.checkLValSimple(e3.local, 2), this.finishNode(e3, "ImportDefaultSpecifier"); }, X.parseImportNamespaceSpecifier = function() { var e3 = this.startNode(); return this.next(), this.expectContextual("as"), e3.local = this.parseIdent(), this.checkLValSimple(e3.local, 2), this.finishNode(e3, "ImportNamespaceSpecifier"); }, X.parseImportSpecifiers = function() { var e3 = [], t3 = true; if (this.type === b.name && (e3.push(this.parseImportDefaultSpecifier()), !this.eat(b.comma))) return e3; if (this.type === b.star) return e3.push(this.parseImportNamespaceSpecifier()), e3; for (this.expect(b.braceL); !this.eat(b.braceR); ) { if (t3) t3 = false; else if (this.expect(b.comma), this.afterTrailingComma(b.braceR)) break; e3.push(this.parseImportSpecifier()); } return e3; }, X.parseWithClause = function() { var e3 = []; if (!this.eat(b._with)) return e3; this.expect(b.braceL); for (var t3 = {}, r3 = true; !this.eat(b.braceR); ) { if (r3) r3 = false; else if (this.expect(b.comma), this.afterTrailingComma(b.braceR)) break; var n2 = this.parseImportAttribute(), i2 = "Identifier" === n2.key.type ? n2.key.name : n2.key.value; D(t3, i2) && this.raiseRecoverable(n2.key.start, "Duplicate attribute key '" + i2 + "'"), t3[i2] = true, e3.push(n2); } return e3; }, X.parseImportAttribute = function() { var e3 = this.startNode(); return e3.key = this.type === b.string ? this.parseExprAtom() : this.parseIdent("never" !== this.options.allowReserved), this.expect(b.colon), this.type !== b.string && this.unexpected(), e3.value = this.parseExprAtom(), this.finishNode(e3, "ImportAttribute"); }, X.parseModuleExportName = function() { if (this.options.ecmaVersion >= 13 && this.type === b.string) { var e3 = this.parseLiteral(this.value); return F.test(e3.value) && this.raise(e3.start, "An export name cannot include a lone surrogate."), e3; } return this.parseIdent(true); }, X.adaptDirectivePrologue = function(e3) { for (var t3 = 0; t3 < e3.length && this.isDirectiveCandidate(e3[t3]); ++t3) e3[t3].directive = e3[t3].expression.raw.slice(1, -1); }, X.isDirectiveCandidate = function(e3) { return this.options.ecmaVersion >= 5 && "ExpressionStatement" === e3.type && "Literal" === e3.expression.type && "string" == typeof e3.expression.value && ('"' === this.input[e3.start] || "'" === this.input[e3.start]); }; var re = U.prototype; re.toAssignable = function(e3, t3, r3) { if (this.options.ecmaVersion >= 6 && e3) switch (e3.type) { case "Identifier": this.inAsync && "await" === e3.name && this.raise(e3.start, "Cannot use 'await' as identifier inside an async function"); break; case "ObjectPattern": case "ArrayPattern": case "AssignmentPattern": case "RestElement": break; case "ObjectExpression": e3.type = "ObjectPattern", r3 && this.checkPatternErrors(r3, true); for (var n2 = 0, i2 = e3.properties; n2 < i2.length; n2 += 1) { var s2 = i2[n2]; this.toAssignable(s2, t3), "RestElement" !== s2.type || "ArrayPattern" !== s2.argument.type && "ObjectPattern" !== s2.argument.type || this.raise(s2.argument.start, "Unexpected token"); } break; case "Property": "init" !== e3.kind && this.raise(e3.key.start, "Object pattern can't contain getter or setter"), this.toAssignable(e3.value, t3); break; case "ArrayExpression": e3.type = "ArrayPattern", r3 && this.checkPatternErrors(r3, true), this.toAssignableList(e3.elements, t3); break; case "SpreadElement": e3.type = "RestElement", this.toAssignable(e3.argument, t3), "AssignmentPattern" === e3.argument.type && this.raise(e3.argument.start, "Rest elements cannot have a default value"); break; case "AssignmentExpression": "=" !== e3.operator && this.raise(e3.left.end, "Only '=' operator can be used for specifying default value."), e3.type = "AssignmentPattern", delete e3.operator, this.toAssignable(e3.left, t3); break; case "ParenthesizedExpression": this.toAssignable(e3.expression, t3, r3); break; case "ChainExpression": this.raiseRecoverable(e3.start, "Optional chaining cannot appear in left-hand side"); break; case "MemberExpression": if (!t3) break; default: this.raise(e3.start, "Assigning to rvalue"); } else r3 && this.checkPatternErrors(r3, true); return e3; }, re.toAssignableList = function(e3, t3) { for (var r3 = e3.length, n2 = 0; n2 < r3; n2++) { var i2 = e3[n2]; i2 && this.toAssignable(i2, t3); } if (r3) { var s2 = e3[r3 - 1]; 6 === this.options.ecmaVersion && t3 && s2 && "RestElement" === s2.type && "Identifier" !== s2.argument.type && this.unexpected(s2.argument.start); } return e3; }, re.parseSpread = function(e3) { var t3 = this.startNode(); return this.next(), t3.argument = this.parseMaybeAssign(false, e3), this.finishNode(t3, "SpreadElement"); }, re.parseRestBinding = function() { var e3 = this.startNode(); return this.next(), 6 === this.options.ecmaVersion && this.type !== b.name && this.unexpected(), e3.argument = this.parseBindingAtom(), this.finishNode(e3, "RestElement"); }, re.parseBindingAtom = function() { if (this.options.ecmaVersion >= 6) switch (this.type) { case b.bracketL: var e3 = this.startNode(); return this.next(), e3.elements = this.parseBindingList(b.bracketR, true, true), this.finishNode(e3, "ArrayPattern"); case b.braceL: return this.parseObj(true); } return this.parseIdent(); }, re.parseBindingList = function(e3, t3, r3, n2) { for (var i2 = [], s2 = true; !this.eat(e3); ) if (s2 ? s2 = false : this.expect(b.comma), t3 && this.type === b.comma) i2.push(null); else { if (r3 && this.afterTrailingComma(e3)) break; if (this.type === b.ellipsis) { var a2 = this.parseRestBinding(); this.parseBindingListItem(a2), i2.push(a2), this.type === b.comma && this.raiseRecoverable(this.start, "Comma is not permitted after the rest element"), this.expect(e3); break; } i2.push(this.parseAssignableListItem(n2)); } return i2; }, re.parseAssignableListItem = function(e3) { var t3 = this.parseMaybeDefault(this.start, this.startLoc); return this.parseBindingListItem(t3), t3; }, re.parseBindingListItem = function(e3) { return e3; }, re.parseMaybeDefault = function(e3, t3, r3) { if (r3 = r3 || this.parseBindingAtom(), this.options.ecmaVersion < 6 || !this.eat(b.eq)) return r3; var n2 = this.startNodeAt(e3, t3); return n2.left = r3, n2.right = this.parseMaybeAssign(), this.finishNode(n2, "AssignmentPattern"); }, re.checkLValSimple = function(e3, t3, r3) { void 0 === t3 && (t3 = 0); var n2 = 0 !== t3; switch (e3.type) { case "Identifier": this.strict && this.reservedWordsStrictBind.test(e3.name) && this.raiseRecoverable(e3.start, (n2 ? "Binding " : "Assigning to ") + e3.name + " in strict mode"), n2 && (2 === t3 && "let" === e3.name && this.raiseRecoverable(e3.start, "let is disallowed as a lexically bound name"), r3 && (D(r3, e3.name) && this.raiseRecoverable(e3.start, "Argument name clash"), r3[e3.name] = true), 5 !== t3 && this.declareName(e3.name, t3, e3.start)); break; case "ChainExpression": this.raiseRecoverable(e3.start, "Optional chaining cannot appear in left-hand side"); break; case "MemberExpression": n2 && this.raiseRecoverable(e3.start, "Binding member expression"); break; case "ParenthesizedExpression": return n2 && this.raiseRecoverable(e3.start, "Binding parenthesized expression"), this.checkLValSimple(e3.expression, t3, r3); default: this.raise(e3.start, (n2 ? "Binding" : "Assigning to") + " rvalue"); } }, re.checkLValPattern = function(e3, t3, r3) { switch (void 0 === t3 && (t3 = 0), e3.type) { case "ObjectPattern": for (var n2 = 0, i2 = e3.properties; n2 < i2.length; n2 += 1) { var s2 = i2[n2]; this.checkLValInnerPattern(s2, t3, r3); } break; case "ArrayPattern": for (var a2 = 0, o2 = e3.elements; a2 < o2.length; a2 += 1) { var u2 = o2[a2]; u2 && this.checkLValInnerPattern(u2, t3, r3); } break; default: this.checkLValSimple(e3, t3, r3); } }, re.checkLValInnerPattern = function(e3, t3, r3) { switch (void 0 === t3 && (t3 = 0), e3.type) { case "Property": this.checkLValInnerPattern(e3.value, t3, r3); break; case "AssignmentPattern": this.checkLValPattern(e3.left, t3, r3); break; case "RestElement": this.checkLValPattern(e3.argument, t3, r3); break; default: this.checkLValPattern(e3, t3, r3); } }; var ne = function(e3, t3, r3, n2, i2) { this.token = e3, this.isExpr = !!t3, this.preserveSpace = !!r3, this.override = n2, this.generator = !!i2; }, ie = { b_stat: new ne("{", false), b_expr: new ne("{", true), b_tmpl: new ne("${", false), p_stat: new ne("(", false), p_expr: new ne("(", true), q_tmpl: new ne("`", true, true, function(e3) { return e3.tryReadTemplateToken(); }), f_stat: new ne("function", false), f_expr: new ne("function", true), f_expr_gen: new ne("function", true, false, null, true), f_gen: new ne("function", false, false, null, true) }, se = U.prototype; se.initialContext = function() { return [ie.b_stat]; }, se.curContext = function() { return this.context[this.context.length - 1]; }, se.braceIsBlock = function(e3) { var t3 = this.curContext(); return t3 === ie.f_expr || t3 === ie.f_stat || (e3 !== b.colon || t3 !== ie.b_stat && t3 !== ie.b_expr ? e3 === b._return || e3 === b.name && this.exprAllowed ? T.test(this.input.slice(this.lastTokEnd, this.start)) : e3 === b._else || e3 === b.semi || e3 === b.eof || e3 === b.parenR || e3 === b.arrow || (e3 === b.braceL ? t3 === ie.b_stat : e3 !== b._var && e3 !== b._const && e3 !== b.name && !this.exprAllowed) : !t3.isExpr); }, se.inGeneratorContext = function() { for (var e3 = this.context.length - 1; e3 >= 1; e3--) { var t3 = this.context[e3]; if ("function" === t3.token) return t3.generator; } return false; }, se.updateContext = function(e3) { var t3, r3 = this.type; r3.keyword && e3 === b.dot ? this.exprAllowed = false : (t3 = r3.updateContext) ? t3.call(this, e3) : this.exprAllowed = r3.beforeExpr; }, se.overrideContext = function(e3) { this.curContext() !== e3 && (this.context[this.context.length - 1] = e3); }, b.parenR.updateContext = b.braceR.updateContext = function() { if (1 !== this.context.length) { var e3 = this.context.pop(); e3 === ie.b_stat && "function" === this.curContext().token && (e3 = this.context.pop()), this.exprAllowed = !e3.isExpr; } else this.exprAllowed = true; }, b.braceL.updateContext = function(e3) { this.context.push(this.braceIsBlock(e3) ? ie.b_stat : ie.b_expr), this.exprAllowed = true; }, b.dollarBraceL.updateContext = function() { this.context.push(ie.b_tmpl), this.exprAllowed = true; }, b.parenL.updateContext = function(e3) { var t3 = e3 === b._if || e3 === b._for || e3 === b._with || e3 === b._while; this.context.push(t3 ? ie.p_stat : ie.p_expr), this.exprAllowed = true; }, b.incDec.updateContext = function() { }, b._function.updateContext = b._class.updateContext = function(e3) { !e3.beforeExpr || e3 === b._else || e3 === b.semi && this.curContext() !== ie.p_stat || e3 === b._return && T.test(this.input.slice(this.lastTokEnd, this.start)) || (e3 === b.colon || e3 === b.braceL) && this.curContext() === ie.b_stat ? this.context.push(ie.f_stat) : this.context.push(ie.f_expr), this.exprAllowed = false; }, b.colon.updateContext = function() { "function" === this.curContext().token && this.context.pop(), this.exprAllowed = true; }, b.backQuote.updateContext = function() { this.curContext() === ie.q_tmpl ? this.context.pop() : this.context.push(ie.q_tmpl), this.exprAllowed = false; }, b.star.updateContext = function(e3) { if (e3 === b._function) { var t3 = this.context.length - 1; this.context[t3] === ie.f_expr ? this.context[t3] = ie.f_expr_gen : this.context[t3] = ie.f_gen; } this.exprAllowed = true; }, b.name.updateContext = function(e3) { var t3 = false; this.options.ecmaVersion >= 6 && e3 !== b.dot && ("of" === this.value && !this.exprAllowed || "yield" === this.value && this.inGeneratorContext()) && (t3 = true), this.exprAllowed = t3; }; var ae = U.prototype; function oe(e3) { return "Identifier" === e3.type || "ParenthesizedExpression" === e3.type && oe(e3.expression); } function ue(e3) { return "MemberExpression" === e3.type && "PrivateIdentifier" === e3.property.type || "ChainExpression" === e3.type && ue(e3.expression) || "ParenthesizedExpression" === e3.type && ue(e3.expression); } ae.checkPropClash = function(e3, t3, r3) { if (!(this.options.ecmaVersion >= 9 && "SpreadElement" === e3.type || this.options.ecmaVersion >= 6 && (e3.computed || e3.method || e3.shorthand))) { var n2, i2 = e3.key; switch (i2.type) { case "Identifier": n2 = i2.name; break; case "Literal": n2 = String(i2.value); break; default: return; } var s2 = e3.kind; if (this.options.ecmaVersion >= 6) "__proto__" === n2 && "init" === s2 && (t3.proto && (r3 ? r3.doubleProto < 0 && (r3.doubleProto = i2.start) : this.raiseRecoverable(i2.start, "Redefinition of __proto__ property")), t3.proto = true); else { var a2 = t3[n2 = "$" + n2]; if (a2) ("init" === s2 ? this.strict && a2.init || a2.get || a2.set : a2.init || a2[s2]) && this.raiseRecoverable(i2.start, "Redefinition of property"); else a2 = t3[n2] = { init: false, get: false, set: false }; a2[s2] = true; } } }, ae.parseExpression = function(e3, t3) { var r3 = this.start, n2 = this.startLoc, i2 = this.parseMaybeAssign(e3, t3); if (this.type === b.comma) { var s2 = this.startNodeAt(r3, n2); for (s2.expressions = [i2]; this.eat(b.comma); ) s2.expressions.push(this.parseMaybeAssign(e3, t3)); return this.finishNode(s2, "SequenceExpression"); } return i2; }, ae.parseMaybeAssign = function(e3, t3, r3) { if (this.isContextual("yield")) { if (this.inGenerator) return this.parseYield(e3); this.exprAllowed = false; } var n2 = false, i2 = -1, s2 = -1, a2 = -1; t3 ? (i2 = t3.parenthesizedAssign, s2 = t3.trailingComma, a2 = t3.doubleProto, t3.parenthesizedAssign = t3.trailingComma = -1) : (t3 = new H(), n2 = true); var o2 = this.start, u2 = this.startLoc; this.type !== b.parenL && this.type !== b.name || (this.potentialArrowAt = this.start, this.potentialArrowInForAwait = "await" === e3); var l2 = this.parseMaybeConditional(e3, t3); if (r3 && (l2 = r3.call(this, l2, o2, u2)), this.type.isAssign) { var h2 = this.startNodeAt(o2, u2); return h2.operator = this.value, this.type === b.eq && (l2 = this.toAssignable(l2, false, t3)), n2 || (t3.parenthesizedAssign = t3.trailingComma = t3.doubleProto = -1), t3.shorthandAssign >= l2.start && (t3.shorthandAssign = -1), this.type === b.eq ? this.checkLValPattern(l2) : this.checkLValSimple(l2), h2.left = l2, this.next(), h2.right = this.parseMaybeAssign(e3), a2 > -1 && (t3.doubleProto = a2), this.finishNode(h2, "AssignmentExpression"); } return n2 && this.checkExpressionErrors(t3, true), i2 > -1 && (t3.parenthesizedAssign = i2), s2 > -1 && (t3.trailingComma = s2), l2; }, ae.parseMaybeConditional = function(e3, t3) { var r3 = this.start, n2 = this.startLoc, i2 = this.parseExprOps(e3, t3); if (this.checkExpressionErrors(t3)) return i2; if (this.eat(b.question)) { var s2 = this.startNodeAt(r3, n2); return s2.test = i2, s2.consequent = this.parseMaybeAssign(), this.expect(b.colon), s2.alternate = this.parseMaybeAssign(e3), this.finishNode(s2, "ConditionalExpression"); } return i2; }, ae.parseExprOps = function(e3, t3) { var r3 = this.start, n2 = this.startLoc, i2 = this.parseMaybeUnary(t3, false, false, e3); return this.checkExpressionErrors(t3) || i2.start === r3 && "ArrowFunctionExpression" === i2.type ? i2 : this.parseExprOp(i2, r3, n2, -1, e3); }, ae.parseExprOp = function(e3, t3, r3, n2, i2) { var s2 = this.type.binop; if (null != s2 && (!i2 || this.type !== b._in) && s2 > n2) { var a2 = this.type === b.logicalOR || this.type === b.logicalAND, o2 = this.type === b.coalesce; o2 && (s2 = b.logicalAND.binop); var u2 = this.value; this.next(); var l2 = this.start, h2 = this.startLoc, c2 = this.parseExprOp(this.parseMaybeUnary(null, false, false, i2), l2, h2, s2, i2), p2 = this.buildBinary(t3, r3, e3, c2, u2, a2 || o2); return (a2 && this.type === b.coalesce || o2 && (this.type === b.logicalOR || this.type === b.logicalAND)) && this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses"), this.parseExprOp(p2, t3, r3, n2, i2); } return e3; }, ae.buildBinary = function(e3, t3, r3, n2, i2, s2) { "PrivateIdentifier" === n2.type && this.raise(n2.start, "Private identifier can only be left side of binary expression"); var a2 = this.startNodeAt(e3, t3); return a2.left = r3, a2.operator = i2, a2.right = n2, this.finishNode(a2, s2 ? "LogicalExpression" : "BinaryExpression"); }, ae.parseMaybeUnary = function(e3, t3, r3, n2) { var i2, s2 = this.start, a2 = this.startLoc; if (this.isContextual("await") && this.canAwait) i2 = this.parseAwait(n2), t3 = true; else if (this.type.prefix) { var o2 = this.startNode(), u2 = this.type === b.incDec; o2.operator = this.value, o2.prefix = true, this.next(), o2.argument = this.parseMaybeUnary(null, true, u2, n2), this.checkExpressionErrors(e3, true), u2 ? this.checkLValSimple(o2.argument) : this.strict && "delete" === o2.operator && oe(o2.argument) ? this.raiseRecoverable(o2.start, "Deleting local variable in strict mode") : "delete" === o2.operator && ue(o2.argument) ? this.raiseRecoverable(o2.start, "Private fields can not be deleted") : t3 = true, i2 = this.finishNode(o2, u2 ? "UpdateExpression" : "UnaryExpression"); } else if (t3 || this.type !== b.privateId) { if (i2 = this.parseExprSubscripts(e3, n2), this.checkExpressionErrors(e3)) return i2; for (; this.type.postfix && !this.canInsertSemicolon(); ) { var l2 = this.startNodeAt(s2, a2); l2.operator = this.value, l2.prefix = false, l2.argument = i2, this.checkLValSimple(i2), this.next(), i2 = this.finishNode(l2, "UpdateExpression"); } } else (n2 || 0 === this.privateNameStack.length) && this.options.checkPrivateFields && this.unexpected(), i2 = this.parsePrivateIdent(), this.type !== b._in && this.unexpected(); return r3 || !this.eat(b.starstar) ? i2 : t3 ? void this.unexpected(this.lastTokStart) : this.buildBinary(s2, a2, i2, this.parseMaybeUnary(null, false, false, n2), "**", false); }, ae.parseExprSubscripts = function(e3, t3) { var r3 = this.start, n2 = this.startLoc, i2 = this.parseExprAtom(e3, t3); if ("ArrowFunctionExpression" === i2.type && ")" !== this.input.slice(this.lastTokStart, this.lastTokEnd)) return i2; var s2 = this.parseSubscripts(i2, r3, n2, false, t3); return e3 && "MemberExpression" === s2.type && (e3.parenthesizedAssign >= s2.start && (e3.parenthesizedAssign = -1), e3.parenthesizedBind >= s2.start && (e3.parenthesizedBind = -1), e3.trailingComma >= s2.start && (e3.trailingComma = -1)), s2; }, ae.parseSubscripts = function(e3, t3, r3, n2, i2) { for (var s2 = this.options.ecmaVersion >= 8 && "Identifier" === e3.type && "async" === e3.name && this.lastTokEnd === e3.end && !this.canInsertSemicolon() && e3.end - e3.start == 5 && this.potentialArrowAt === e3.start, a2 = false; ; ) { var o2 = this.parseSubscript(e3, t3, r3, n2, s2, a2, i2); if (o2.optional && (a2 = true), o2 === e3 || "ArrowFunctionExpression" === o2.type) { if (a2) { var u2 = this.startNodeAt(t3, r3); u2.expression = o2, o2 = this.finishNode(u2, "ChainExpression"); } return o2; } e3 = o2; } }, ae.shouldParseAsyncArrow = function() { return !this.canInsertSemicolon() && this.eat(b.arrow); }, ae.parseSubscriptAsyncArrow = function(e3, t3, r3, n2) { return this.parseArrowExpression(this.startNodeAt(e3, t3), r3, true, n2); }, ae.parseSubscript = function(e3, t3, r3, n2, i2, s2, a2) { var o2 = this.options.ecmaVersion >= 11, u2 = o2 && this.eat(b.questionDot); n2 && u2 && this.raise(this.lastTokStart, "Optional chaining cannot appear in the callee of new expressions"); var l2 = this.eat(b.bracketL); if (l2 || u2 && this.type !== b.parenL && this.type !== b.backQuote || this.eat(b.dot)) { var h2 = this.startNodeAt(t3, r3); h2.object = e3, l2 ? (h2.property = this.parseExpression(), this.expect(b.bracketR)) : this.type === b.privateId && "Super" !== e3.type ? h2.property = this.parsePrivateIdent() : h2.property = this.parseIdent("never" !== this.options.allowReserved), h2.computed = !!l2, o2 && (h2.optional = u2), e3 = this.finishNode(h2, "MemberExpression"); } else if (!n2 && this.eat(b.parenL)) { var c2 = new H(), p2 = this.yieldPos, d2 = this.awaitPos, m2 = this.awaitIdentPos; this.yieldPos = 0, this.awaitPos = 0, this.awaitIdentPos = 0; var f2 = this.parseExprList(b.parenR, this.options.ecmaVersion >= 8, false, c2); if (i2 && !u2 && this.shouldParseAsyncArrow()) return this.checkPatternErrors(c2, false), this.checkYieldAwaitInDefaultParams(), this.awaitIdentPos > 0 && this.raise(this.awaitIdentPos, "Cannot use 'await' as identifier inside an async function"), this.yieldPos = p2, this.awaitPos = d2, this.awaitIdentPos = m2, this.parseSubscriptAsyncArrow(t3, r3, f2, a2); this.checkExpressionErrors(c2, true), this.yieldPos = p2 || this.yieldPos, this.awaitPos = d2 || this.awaitPos, this.awaitIdentPos = m2 || this.awaitIdentPos; var g2 = this.startNodeAt(t3, r3); g2.callee = e3, g2.arguments = f2, o2 && (g2.optional = u2), e3 = this.finishNode(g2, "CallExpression"); } else if (this.type === b.backQuote) { (u2 || s2) && this.raise(this.start, "Optional chaining cannot appear in the tag of tagged template expressions"); var x2 = this.startNodeAt(t3, r3); x2.tag = e3, x2.quasi = this.parseTemplate({ isTagged: true }), e3 = this.finishNode(x2, "TaggedTemplateExpression"); } return e3; }, ae.parseExprAtom = function(e3, t3, r3) { this.type === b.slash && this.readRegexp(); var n2, i2 = this.potentialArrowAt === this.start; switch (this.type) { case b._super: return this.allowSuper || this.raise(this.start, "'super' keyword outside a method"), n2 = this.startNode(), this.next(), this.type !== b.parenL || this.allowDirectSuper || this.raise(n2.start, "super() call outside constructor of a subclass"), this.type !== b.dot && this.type !== b.bracketL && this.type !== b.parenL && this.unexpected(), this.finishNode(n2, "Super"); case b._this: return n2 = this.startNode(), this.next(), this.finishNode(n2, "ThisExpression"); case b.name: var s2 = this.start, a2 = this.startLoc, o2 = this.containsEsc, u2 = this.parseIdent(false); if (this.options.ecmaVersion >= 8 && !o2 && "async" === u2.name && !this.canInsertSemicolon() && this.eat(b._function)) return this.overrideContext(ie.f_expr), this.parseFunction(this.startNodeAt(s2, a2), 0, false, true, t3); if (i2 && !this.canInsertSemicolon()) { if (this.eat(b.arrow)) return this.parseArrowExpression(this.startNodeAt(s2, a2), [u2], false, t3); if (this.options.ecmaVersion >= 8 && "async" === u2.name && this.type === b.name && !o2 && (!this.potentialArrowInForAwait || "of" !== this.value || this.containsEsc)) return u2 = this.parseIdent(false), !this.canInsertSemicolon() && this.eat(b.arrow) || this.unexpected(), this.parseArrowExpression(this.startNodeAt(s2, a2), [u2], true, t3); } return u2; case b.regexp: var l2 = this.value; return (n2 = this.parseLiteral(l2.value)).regex = { pattern: l2.pattern, flags: l2.flags }, n2; case b.num: case b.string: return this.parseLiteral(this.value); case b._null: case b._true: case b._false: return (n2 = this.startNode()).value = this.type === b._null ? null : this.type === b._true, n2.raw = this.type.keyword, this.next(), this.finishNode(n2, "Literal"); case b.parenL: var h2 = this.start, c2 = this.parseParenAndDistinguishExpression(i2, t3); return e3 && (e3.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(c2) && (e3.parenthesizedAssign = h2), e3.parenthesizedBind < 0 && (e3.parenthesizedBind = h2)), c2; case b.bracketL: return n2 = this.startNode(), this.next(), n2.elements = this.parseExprList(b.bracketR, true, true, e3), this.finishNode(n2, "ArrayExpression"); case b.braceL: return this.overrideContext(ie.b_expr), this.parseObj(false, e3); case b._function: return n2 = this.startNode(), this.next(), this.parseFunction(n2, 0); case b._class: return this.parseClass(this.startNode(), false); case b._new: return this.parseNew(); case b.backQuote: return this.parseTemplate(); case b._import: return this.options.ecmaVersion >= 11 ? this.parseExprImport(r3) : this.unexpected(); default: return this.parseExprAtomDefault(); } }, ae.parseExprAtomDefault = function() { this.unexpected(); }, ae.parseExprImport = function(e3) { var t3 = this.startNode(); if (this.containsEsc && this.raiseRecoverable(this.start, "Escape sequence in keyword import"), this.next(), this.type === b.parenL && !e3) return this.parseDynamicImport(t3); if (this.type === b.dot) { var r3 = this.startNodeAt(t3.start, t3.loc && t3.loc.start); return r3.name = "import", t3.meta = this.finishNode(r3, "Identifier"), this.parseImportMeta(t3); } this.unexpected(); }, ae.parseDynamicImport = function(e3) { if (this.next(), e3.source = this.parseMaybeAssign(), this.options.ecmaVersion >= 16) this.eat(b.parenR) ? e3.options = null : (this.expect(b.comma), this.afterTrailingComma(b.parenR) ? e3.options = null : (e3.options = this.parseMaybeAssign(), this.eat(b.parenR) || (this.expect(b.comma), this.afterTrailingComma(b.parenR) || this.unexpected()))); else if (!this.eat(b.parenR)) { var t3 = this.start; this.eat(b.comma) && this.eat(b.parenR) ? this.raiseRecoverable(t3, "Trailing comma is not allowed in import()") : this.unexpected(t3); } return this.finishNode(e3, "ImportExpression"); }, ae.parseImportMeta = function(e3) { this.next(); var t3 = this.containsEsc; return e3.property = this.parseIdent(true), "meta" !== e3.property.name && this.raiseRecoverable(e3.property.start, "The only valid meta property for import is 'import.meta'"), t3 && this.raiseRecoverable(e3.start, "'import.meta' must not contain escaped characters"), "module" === this.options.sourceType || this.options.allowImportExportEverywhere || this.raiseRecoverable(e3.start, "Cannot use 'import.meta' outside a module"), this.finishNode(e3, "MetaProperty"); }, ae.parseLiteral = function(e3) { var t3 = this.startNode(); return t3.value = e3, t3.raw = this.input.slice(this.start, this.end), 110 === t3.raw.charCodeAt(t3.raw.length - 1) && (t3.bigint = t3.raw.slice(0, -1).replace(/_/g, "")), this.next(), this.finishNode(t3, "Literal"); }, ae.parseParenExpression = function() { this.expect(b.parenL); var e3 = this.parseExpression(); return this.expect(b.parenR), e3; }, ae.shouldParseArrow = function(e3) { return !this.canInsertSemicolon(); }, ae.parseParenAndDistinguishExpression = function(e3, t3) { var r3, n2 = this.start, i2 = this.startLoc, s2 = this.options.ecmaVersion >= 8; if (this.options.ecmaVersion >= 6) { this.next(); var a2, o2 = this.start, u2 = this.startLoc, l2 = [], h2 = true, c2 = false, p2 = new H(), d2 = this.yieldPos, m2 = this.awaitPos; for (this.yieldPos = 0, this.awaitPos = 0; this.type !== b.parenR; ) { if (h2 ? h2 = false : this.expect(b.comma), s2 && this.afterTrailingComma(b.parenR, true)) { c2 = true; break; } if (this.type === b.ellipsis) { a2 = this.start, l2.push(this.parseParenItem(this.parseRestBinding())), this.type === b.comma && this.raiseRecoverable(this.start, "Comma is not permitted after the rest element"); break; } l2.push(this.parseMaybeAssign(false, p2, this.parseParenItem)); } var f2 = this.lastTokEnd, g2 = this.lastTokEndLoc; if (this.expect(b.parenR), e3 && this.shouldParseArrow(l2) && this.eat(b.arrow)) return this.checkPatternErrors(p2, false), this.checkYieldAwaitInDefaultParams(), this.yieldPos = d2, this.awaitPos = m2, this.parseParenArrowList(n2, i2, l2, t3); l2.length && !c2 || this.unexpected(this.lastTokStart), a2 && this.unexpected(a2), this.checkExpressionErrors(p2, true), this.yieldPos = d2 || this.yieldPos, this.awaitPos = m2 || this.awaitPos, l2.length > 1 ? ((r3 = this.startNodeAt(o2, u2)).expressions = l2, this.finishNodeAt(r3, "SequenceExpression", f2, g2)) : r3 = l2[0]; } else r3 = this.parseParenExpression(); if (this.options.preserveParens) { var x2 = this.startNodeAt(n2, i2); return x2.expression = r3, this.finishNode(x2, "ParenthesizedExpression"); } return r3; }, ae.parseParenItem = function(e3) { return e3; }, ae.parseParenArrowList = function(e3, t3, r3, n2) { return this.parseArrowExpression(this.startNodeAt(e3, t3), r3, false, n2); }; var le = []; ae.parseNew = function() { this.containsEsc && this.raiseRecoverable(this.start, "Escape sequence in keyword new"); var e3 = this.startNode(); if (this.next(), this.options.ecmaVersion >= 6 && this.type === b.dot) { var t3 = this.startNodeAt(e3.start, e3.loc && e3.loc.start); t3.name = "new", e3.meta = this.finishNode(t3, "Identifier"), this.next(); var r3 = this.containsEsc; return e3.property = this.parseIdent(true), "target" !== e3.property.name && this.raiseRecoverable(e3.property.start, "The only valid meta property for new is 'new.target'"), r3 && this.raiseRecoverable(e3.start, "'new.target' must not contain escaped characters"), this.allowNewDotTarget || this.raiseRecoverable(e3.start, "'new.target' can only be used in functions and class static block"), this.finishNode(e3, "MetaProperty"); } var n2 = this.start, i2 = this.startLoc; return e3.callee = this.parseSubscripts(this.parseExprAtom(null, false, true), n2, i2, true, false), this.eat(b.parenL) ? e3.arguments = this.parseExprList(b.parenR, this.options.ecmaVersion >= 8, false) : e3.arguments = le, this.finishNode(e3, "NewExpression"); }, ae.parseTemplateElement = function(e3) { var t3 = e3.isTagged, r3 = this.startNode(); return this.type === b.invalidTemplate ? (t3 || this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal"), r3.value = { raw: this.value.replace(/\r\n?/g, "\n"), cooked: null }) : r3.value = { raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"), cooked: this.value }, this.next(), r3.tail = this.type === b.backQuote, this.finishNode(r3, "TemplateElement"); }, ae.parseTemplate = function(e3) { void 0 === e3 && (e3 = {}); var t3 = e3.isTagged; void 0 === t3 && (t3 = false); var r3 = this.startNode(); this.next(), r3.expressions = []; var n2 = this.parseTemplateElement({ isTagged: t3 }); for (r3.quasis = [n2]; !n2.tail; ) this.type === b.eof && this.raise(this.pos, "Unterminated template literal"), this.expect(b.dollarBraceL), r3.expressions.push(this.parseExpression()), this.expect(b.braceR), r3.quasis.push(n2 = this.parseTemplateElement({ isTagged: t3 })); return this.next(), this.finishNode(r3, "TemplateLiteral"); }, ae.isAsyncProp = function(e3) { return !e3.computed && "Identifier" === e3.key.type && "async" === e3.key.name && (this.type === b.name || this.type === b.num || this.type === b.string || this.type === b.bracketL || this.type.keyword || this.options.ecmaVersion >= 9 && this.type === b.star) && !T.test(this.input.slice(this.lastTokEnd, this.start)); }, ae.parseObj = function(e3, t3) { var r3 = this.startNode(), n2 = true, i2 = {}; for (r3.properties = [], this.next(); !this.eat(b.braceR); ) { if (n2) n2 = false; else if (this.expect(b.comma), this.options.ecmaVersion >= 5 && this.afterTrailingComma(b.braceR)) break; var s2 = this.parseProperty(e3, t3); e3 || this.checkPropClash(s2, i2, t3), r3.properties.push(s2); } return this.finishNode(r3, e3 ? "ObjectPattern" : "ObjectExpression"); }, ae.parseProperty = function(e3, t3) { var r3, n2, i2, s2, a2 = this.startNode(); if (this.options.ecmaVersion >= 9 && this.eat(b.ellipsis)) return e3 ? (a2.argument = this.parseIdent(false), this.type === b.comma && this.raiseRecoverable(this.start, "Comma is not permitted after the rest element"), this.finishNode(a2, "RestElement")) : (a2.argument = this.parseMaybeAssign(false, t3), this.type === b.comma && t3 && t3.trailingComma < 0 && (t3.trailingComma = this.start), this.finishNode(a2, "SpreadElement")); this.options.ecmaVersion >= 6 && (a2.method = false, a2.shorthand = false, (e3 || t3) && (i2 = this.start, s2 = this.startLoc), e3 || (r3 = this.eat(b.star))); var o2 = this.containsEsc; return this.parsePropertyName(a2), !e3 && !o2 && this.options.ecmaVersion >= 8 && !r3 && this.isAsyncProp(a2) ? (n2 = true, r3 = this.options.ecmaVersion >= 9 && this.eat(b.star), this.parsePropertyName(a2)) : n2 = false, this.parsePropertyValue(a2, e3, r3, n2, i2, s2, t3, o2), this.finishNode(a2, "Property"); }, ae.parseGetterSetter = function(e3) { e3.kind = e3.key.name, this.parsePropertyName(e3), e3.value = this.parseMethod(false); var t3 = "get" === e3.kind ? 0 : 1; if (e3.value.params.length !== t3) { var r3 = e3.value.start; "get" === e3.kind ? this.raiseRecoverable(r3, "getter should have no params") : this.raiseRecoverable(r3, "setter should have exactly one param"); } else "set" === e3.kind && "RestElement" === e3.value.params[0].type && this.raiseRecoverable(e3.value.params[0].start, "Setter cannot use rest params"); }, ae.parsePropertyValue = function(e3, t3, r3, n2, i2, s2, a2, o2) { (r3 || n2) && this.type === b.colon && this.unexpected(), this.eat(b.colon) ? (e3.value = t3 ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, a2), e3.kind = "init") : this.options.ecmaVersion >= 6 && this.type === b.parenL ? (t3 && this.unexpected(), e3.kind = "init", e3.method = true, e3.value = this.parseMethod(r3, n2)) : t3 || o2 || !(this.options.ecmaVersion >= 5) || e3.computed || "Identifier" !== e3.key.type || "get" !== e3.key.name && "set" !== e3.key.name || this.type === b.comma || this.type === b.braceR || this.type === b.eq ? this.options.ecmaVersion >= 6 && !e3.computed && "Identifier" === e3.key.type ? ((r3 || n2) && this.unexpected(), this.checkUnreserved(e3.key), "await" !== e3.key.name || this.awaitIdentPos || (this.awaitIdentPos = i2), e3.kind = "init", t3 ? e3.value = this.parseMaybeDefault(i2, s2, this.copyNode(e3.key)) : this.type === b.eq && a2 ? (a2.shorthandAssign < 0 && (a2.shorthandAssign = this.start), e3.value = this.parseMaybeDefault(i2, s2, this.copyNode(e3.key))) : e3.value = this.copyNode(e3.key), e3.shorthand = true) : this.unexpected() : ((r3 || n2) && this.unexpected(), this.parseGetterSetter(e3)); }, ae.parsePropertyName = function(e3) { if (this.options.ecmaVersion >= 6) { if (this.eat(b.bracketL)) return e3.computed = true, e3.key = this.parseMaybeAssign(), this.expect(b.bracketR), e3.key; e3.computed = false; } return e3.key = this.type === b.num || this.type === b.string ? this.parseExprAtom() : this.parseIdent("never" !== this.options.allowReserved); }, ae.initFunction = function(e3) { e3.id = null, this.options.ecmaVersion >= 6 && (e3.generator = e3.expression = false), this.options.ecmaVersion >= 8 && (e3.async = false); }, ae.parseMethod = function(e3, t3, r3) { var n2 = this.startNode(), i2 = this.yieldPos, s2 = this.awaitPos, a2 = this.awaitIdentPos; return this.initFunction(n2), this.options.ecmaVersion >= 6 && (n2.generator = e3), this.options.ecmaVersion >= 8 && (n2.async = !!t3), this.yieldPos = 0, this.awaitPos = 0, this.awaitIdentPos = 0, this.enterScope(64 | G(t3, n2.generator) | (r3 ? 128 : 0)), this.expect(b.parenL), n2.params = this.parseBindingList(b.parenR, false, this.options.ecmaVersion >= 8), this.checkYieldAwaitInDefaultParams(), this.parseFunctionBody(n2, false, true, false), this.yieldPos = i2, this.awaitPos = s2, this.awaitIdentPos = a2, this.finishNode(n2, "FunctionExpression"); }, ae.parseArrowExpression = function(e3, t3, r3, n2) { var i2 = this.yieldPos, s2 = this.awaitPos, a2 = this.awaitIdentPos; return this.enterScope(16 | G(r3, false)), this.initFunction(e3), this.options.ecmaVersion >= 8 && (e3.async = !!r3), this.yieldPos = 0, this.awaitPos = 0, this.awaitIdentPos = 0, e3.params = this.toAssignableList(t3, true), this.parseFunctionBody(e3, true, false, n2), this.yieldPos = i2, this.awaitPos = s2, this.awaitIdentPos = a2, this.finishNode(e3, "ArrowFunctionExpression"); }, ae.parseFunctionBody = function(e3, t3, r3, n2) { var i2 = t3 && this.type !== b.braceL, s2 = this.strict, a2 = false; if (i2) e3.body = this.parseMaybeAssign(n2), e3.expression = true, this.checkParams(e3, false); else { var o2 = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(e3.params); s2 && !o2 || (a2 = this.strictDirective(this.end)) && o2 && this.raiseRecoverable(e3.start, "Illegal 'use strict' directive in function with non-simple parameter list"); var u2 = this.labels; this.labels = [], a2 && (this.strict = true), this.checkParams(e3, !s2 && !a2 && !t3 && !r3 && this.isSimpleParamList(e3.params)), this.strict && e3.id && this.checkLValSimple(e3.id, 5), e3.body = this.parseBlock(false, void 0, a2 && !s2), e3.expression = false, this.adaptDirectivePrologue(e3.body.body), this.labels = u2; } this.exitScope(); }, ae.isSimpleParamList = function(e3) { for (var t3 = 0, r3 = e3; t3 < r3.length; t3 += 1) { if ("Identifier" !== r3[t3].type) return false; } return true; }, ae.checkParams = function(e3, t3) { for (var r3 = /* @__PURE__ */ Object.create(null), n2 = 0, i2 = e3.params; n2 < i2.length; n2 += 1) { var s2 = i2[n2]; this.checkLValInnerPattern(s2, 1, t3 ? null : r3); } }, ae.parseExprList = function(e3, t3, r3, n2) { for (var i2 = [], s2 = true; !this.eat(e3); ) { if (s2) s2 = false; else if (this.expect(b.comma), t3 && this.afterTrailingComma(e3)) break; var a2 = void 0; r3 && this.type === b.comma ? a2 = null : this.type === b.ellipsis ? (a2 = this.parseSpread(n2), n2 && this.type === b.comma && n2.trailingComma < 0 && (n2.trailingComma = this.start)) : a2 = this.parseMaybeAssign(false, n2), i2.push(a2); } return i2; }, ae.checkUnreserved = function(e3) { var t3 = e3.start, r3 = e3.end, n2 = e3.name; (this.inGenerator && "yield" === n2 && this.raiseRecoverable(t3, "Cannot use 'yield' as identifier inside a generator"), this.inAsync && "await" === n2 && this.raiseRecoverable(t3, "Cannot use 'await' as identifier inside an async function"), this.currentThisScope().inClassFieldInit && "arguments" === n2 && this.raiseRecoverable(t3, "Cannot use 'arguments' in class field initializer"), !this.inClassStaticBlock || "arguments" !== n2 && "await" !== n2 || this.raise(t3, "Cannot use " + n2 + " in class static initialization block"), this.keywords.test(n2) && this.raise(t3, "Unexpected keyword '" + n2 + "'"), this.options.ecmaVersion < 6 && -1 !== this.input.slice(t3, r3).indexOf("\\")) || (this.strict ? this.reservedWordsStrict : this.reservedWords).test(n2) && (this.inAsync || "await" !== n2 || this.raiseRecoverable(t3, "Cannot use keyword 'await' outside an async function"), this.raiseRecoverable(t3, "The keyword '" + n2 + "' is reserved")); }, ae.parseIdent = function(e3) { var t3 = this.parseIdentNode(); return this.next(!!e3), this.finishNode(t3, "Identifier"), e3 || (this.checkUnreserved(t3), "await" !== t3.name || this.awaitIdentPos || (this.awaitIdentPos = t3.start)), t3; }, ae.parseIdentNode = function() { var e3 = this.startNode(); return this.type === b.name ? e3.name = this.value : this.type.keyword ? (e3.name = this.type.keyword, "class" !== e3.name && "function" !== e3.name || this.lastTokEnd === this.lastTokStart + 1 && 46 === this.input.charCodeAt(this.lastTokStart) || this.context.pop(), this.type = b.name) : this.unexpected(), e3; }, ae.parsePrivateIdent = function() { var e3 = this.startNode(); return this.type === b.privateId ? e3.name = this.value : this.unexpected(), this.next(), this.finishNode(e3, "PrivateIdentifier"), this.options.checkPrivateFields && (0 === this.privateNameStack.length ? this.raise(e3.start, "Private field '#" + e3.name + "' must be declared in an enclosing class") : this.privateNameStack[this.privateNameStack.length - 1].used.push(e3)), e3; }, ae.parseYield = function(e3) { this.yieldPos || (this.yieldPos = this.start); var t3 = this.startNode(); return this.next(), this.type === b.semi || this.canInsertSemicolon() || this.type !== b.star && !this.type.startsExpr ? (t3.delegate = false, t3.argument = null) : (t3.delegate = this.eat(b.star), t3.argument = this.parseMaybeAssign(e3)), this.finishNode(t3, "YieldExpression"); }, ae.parseAwait = function(e3) { this.awaitPos || (this.awaitPos = this.start); var t3 = this.startNode(); return this.next(), t3.argument = this.parseMaybeUnary(null, true, false, e3), this.finishNode(t3, "AwaitExpression"); }; var he = U.prototype; he.raise = function(e3, t3) { var r3 = M(this.input, e3); t3 += " (" + r3.line + ":" + r3.column + ")"; var n2 = new SyntaxError(t3); throw n2.pos = e3, n2.loc = r3, n2.raisedAt = this.pos, n2; }, he.raiseRecoverable = he.raise, he.curPosition = function() { if (this.options.locations) return new N(this.curLine, this.pos - this.lineStart); }; var ce = U.prototype, pe = function(e3) { this.flags = e3, this.var = [], this.lexical = [], this.functions = [], this.inClassFieldInit = false; }; ce.enterScope = function(e3) { this.scopeStack.push(new pe(e3)); }, ce.exitScope = function() { this.scopeStack.pop(); }, ce.treatFunctionsAsVarInScope = function(e3) { return 2 & e3.flags || !this.inModule && 1 & e3.flags; }, ce.declareName = function(e3, t3, r3) { var n2 = false; if (2 === t3) { var i2 = this.currentScope(); n2 = i2.lexical.indexOf(e3) > -1 || i2.functions.indexOf(e3) > -1 || i2.var.indexOf(e3) > -1, i2.lexical.push(e3), this.inModule && 1 & i2.flags && delete this.undefinedExports[e3]; } else if (4 === t3) { this.currentScope().lexical.push(e3); } else if (3 === t3) { var s2 = this.currentScope(); n2 = this.treatFunctionsAsVar ? s2.lexical.indexOf(e3) > -1 : s2.lexical.indexOf(e3) > -1 || s2.var.indexOf(e3) > -1, s2.functions.push(e3); } else for (var a2 = this.scopeStack.length - 1; a2 >= 0; --a2) { var o2 = this.scopeStack[a2]; if (o2.lexical.indexOf(e3) > -1 && !(32 & o2.flags && o2.lexical[0] === e3) || !this.treatFunctionsAsVarInScope(o2) && o2.functions.indexOf(e3) > -1) { n2 = true; break; } if (o2.var.push(e3), this.inModule && 1 & o2.flags && delete this.undefinedExports[e3], 259 & o2.flags) break; } n2 && this.raiseRecoverable(r3, "Identifier '" + e3 + "' has already been declared"); }, ce.checkLocalExport = function(e3) { -1 === this.scopeStack[0].lexical.indexOf(e3.name) && -1 === this.scopeStack[0].var.indexOf(e3.name) && (this.undefinedExports[e3.name] = e3); }, ce.currentScope = function() { return this.scopeStack[this.scopeStack.length - 1]; }, ce.currentVarScope = function() { for (var e3 = this.scopeStack.length - 1; ; e3--) { var t3 = this.scopeStack[e3]; if (259 & t3.flags) return t3; } }, ce.currentThisScope = function() { for (var e3 = this.scopeStack.length - 1; ; e3--) { var t3 = this.scopeStack[e3]; if (259 & t3.flags && !(16 & t3.flags)) return t3; } }; var de = function(e3, t3, r3) { this.type = "", this.start = t3, this.end = 0, e3.options.locations && (this.loc = new V(e3, r3)), e3.options.directSourceFile && (this.sourceFile = e3.options.directSourceFile), e3.options.ranges && (this.range = [t3, 0]); }, me = U.prototype; function fe(e3, t3, r3, n2) { return e3.type = t3, e3.end = r3, this.options.locations && (e3.loc.end = n2), this.options.ranges && (e3.range[1] = r3), e3; } me.startNode = function() { return new de(this, this.start, this.startLoc); }, me.startNodeAt = function(e3, t3) { return new de(this, e3, t3); }, me.finishNode = function(e3, t3) { return fe.call(this, e3, t3, this.lastTokEnd, this.lastTokEndLoc); }, me.finishNodeAt = function(e3, t3, r3, n2) { return fe.call(this, e3, t3, r3, n2); }, me.copyNode = function(e3) { var t3 = new de(this, e3.start, this.startLoc); for (var r3 in e3) t3[r3] = e3[r3]; return t3; }; var ge = "ASCII ASCII_Hex_Digit AHex Alphabetic Alpha Any Assigned Bidi_Control Bidi_C Bidi_Mirrored Bidi_M Case_Ignorable CI Cased Changes_When_Casefolded CWCF Changes_When_Casemapped CWCM Changes_When_Lowercased CWL Changes_When_NFKC_Casefolded CWKCF Changes_When_Titlecased CWT Changes_When_Uppercased CWU Dash Default_Ignorable_Code_Point DI Deprecated Dep Diacritic Dia Emoji Emoji_Component Emoji_Modifier Emoji_Modifier_Base Emoji_Presentation Extender Ext Grapheme_Base Gr_Base Grapheme_Extend Gr_Ext Hex_Digit Hex IDS_Binary_Operator IDSB IDS_Trinary_Operator IDST ID_Continue IDC ID_Start IDS Ideographic Ideo Join_Control Join_C Logical_Order_Exception LOE Lowercase Lower Math Noncharacter_Code_Point NChar Pattern_Syntax Pat_Syn Pattern_White_Space Pat_WS Quotation_Mark QMark Radical Regional_Indicator RI Sentence_Terminal STerm Soft_Dotted SD Terminal_Punctuation Term Unified_Ideograph UIdeo Uppercase Upper Variation_Selector VS White_Space space XID_Continue XIDC XID_Start XIDS", xe = ge + " Extended_Pictographic", ye = xe + " EBase EComp EMod EPres ExtPict", be = { 9: ge, 10: xe, 11: xe, 12: ye, 13: ye, 14: ye }, Te = { 9: "", 10: "", 11: "", 12: "", 13: "", 14: "Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji" }, ve = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu", Se = "Adlam Adlm Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb", Ae = Se + " Dogra Dogr Gunjala_Gondi Gong Hanifi_Rohingya Rohg Makasar Maka Medefaidrin Medf Old_Sogdian Sogo Sogdian Sogd", _e = Ae + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho", Ee = _e + " Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi", we = Ee + " Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith", ke = { 9: Se, 10: Ae, 11: _e, 12: Ee, 13: we, 14: we + " Gara Garay Gukh Gurung_Khema Hrkt Katakana_Or_Hiragana Kawi Kirat_Rai Krai Nag_Mundari Nagm Ol_Onal Onao Sunu Sunuwar Todhri Todr Tulu_Tigalari Tutg Unknown Zzzz" }, Ie = {}; function De(e3) { var t3 = Ie[e3] = { binary: L(be[e3] + " " + ve), binaryOfStrings: L(Te[e3]), nonBinary: { General_Category: L(ve), Script: L(ke[e3]) } }; t3.nonBinary.Script_Extensions = t3.nonBinary.Script, t3.nonBinary.gc = t3.nonBinary.General_Category, t3.nonBinary.sc = t3.nonBinary.Script, t3.nonBinary.scx = t3.nonBinary.Script_Extensions; } for (var Ce = 0, $e = [9, 10, 11, 12, 13, 14]; Ce < $e.length; Ce += 1) { De($e[Ce]); } var Le = U.prototype, Re = function(e3, t3) { this.parent = e3, this.base = t3 || this; }; Re.prototype.separatedFrom = function(e3) { for (var t3 = this; t3; t3 = t3.parent) for (var r3 = e3; r3; r3 = r3.parent) if (t3.base === r3.base && t3 !== r3) return true; return false; }, Re.prototype.sibling = function() { return new Re(this.parent, this.base); }; var Fe = function(e3) { this.parser = e3, this.validFlags = "gim" + (e3.options.ecmaVersion >= 6 ? "uy" : "") + (e3.options.ecmaVersion >= 9 ? "s" : "") + (e3.options.ecmaVersion >= 13 ? "d" : "") + (e3.options.ecmaVersion >= 15 ? "v" : ""), this.unicodeProperties = Ie[e3.options.ecmaVersion >= 14 ? 14 : e3.options.ecmaVersion], this.source = "", this.flags = "", this.start = 0, this.switchU = false, this.switchV = false, this.switchN = false, this.pos = 0, this.lastIntValue = 0, this.lastStringValue = "", this.lastAssertionIsQuantifiable = false, this.numCapturingParens = 0, this.maxBackReference = 0, this.groupNames = /* @__PURE__ */ Object.create(null), this.backReferenceNames = [], this.branchID = null; }; function Ne(e3) { return 105 === e3 || 109 === e3 || 115 === e3; } function Ve(e3) { return 36 === e3 || e3 >= 40 && e3 <= 43 || 46 === e3 || 63 === e3 || e3 >= 91 && e3 <= 94 || e3 >= 123 && e3 <= 125; } function Me(e3) { return e3 >= 65 && e3 <= 90 || e3 >= 97 && e3 <= 122; } Fe.prototype.reset = function(e3, t3, r3) { var n2 = -1 !== r3.indexOf("v"), i2 = -1 !== r3.indexOf("u"); this.start = 0 | e3, this.source = t3 + "", this.flags = r3, n2 && this.parser.options.ecmaVersion >= 15 ? (this.switchU = true, this.switchV = true, this.switchN = true) : (this.switchU = i2 && this.parser.options.ecmaVersion >= 6, this.switchV = false, this.switchN = i2 && this.parser.options.ecmaVersion >= 9); }, Fe.prototype.raise = function(e3) { this.parser.raiseRecoverable(this.start, "Invalid regular expression: /" + this.source + "/: " + e3); }, Fe.prototype.at = function(e3, t3) { void 0 === t3 && (t3 = false); var r3 = this.source, n2 = r3.length; if (e3 >= n2) return -1; var i2 = r3.charCodeAt(e3); if (!t3 && !this.switchU || i2 <= 55295 || i2 >= 57344 || e3 + 1 >= n2) return i2; var s2 = r3.charCodeAt(e3 + 1); return s2 >= 56320 && s2 <= 57343 ? (i2 << 10) + s2 - 56613888 : i2; }, Fe.prototype.nextIndex = function(e3, t3) { void 0 === t3 && (t3 = false); var r3 = this.source, n2 = r3.length; if (e3 >= n2) return n2; var i2, s2 = r3.charCodeAt(e3); return !t3 && !this.switchU || s2 <= 55295 || s2 >= 57344 || e3 + 1 >= n2 || (i2 = r3.charCodeAt(e3 + 1)) < 56320 || i2 > 57343 ? e3 + 1 : e3 + 2; }, Fe.prototype.current = function(e3) { return void 0 === e3 && (e3 = false), this.at(this.pos, e3); }, Fe.prototype.lookahead = function(e3) { return void 0 === e3 && (e3 = false), this.at(this.nextIndex(this.pos, e3), e3); }, Fe.prototype.advance = function(e3) { void 0 === e3 && (e3 = false), this.pos = this.nextIndex(this.pos, e3); }, Fe.prototype.eat = function(e3, t3) { return void 0 === t3 && (t3 = false), this.current(t3) === e3 && (this.advance(t3), true); }, Fe.prototype.eatChars = function(e3, t3) { void 0 === t3 && (t3 = false); for (var r3 = this.pos, n2 = 0, i2 = e3; n2 < i2.length; n2 += 1) { var s2 = i2[n2], a2 = this.at(r3, t3); if (-1 === a2 || a2 !== s2) return false; r3 = this.nextIndex(r3, t3); } return this.pos = r3, true; }, Le.validateRegExpFlags = function(e3) { for (var t3 = e3.validFlags, r3 = e3.flags, n2 = false, i2 = false, s2 = 0; s2 < r3.length; s2++) { var a2 = r3.charAt(s2); -1 === t3.indexOf(a2) && this.raise(e3.start, "Invalid regular expression flag"), r3.indexOf(a2, s2 + 1) > -1 && this.raise(e3.start, "Duplicate regular expression flag"), "u" === a2 && (n2 = true), "v" === a2 && (i2 = true); } this.options.ecmaVersion >= 15 && n2 && i2 && this.raise(e3.start, "Invalid regular expression flag"); }, Le.validateRegExpPattern = function(e3) { this.regexp_pattern(e3), !e3.switchN && this.options.ecmaVersion >= 9 && function(e4) { for (var t3 in e4) return true; return false; }(e3.groupNames) && (e3.switchN = true, this.regexp_pattern(e3)); }, Le.regexp_pattern = function(e3) { e3.pos = 0, e3.lastIntValue = 0, e3.lastStringValue = "", e3.lastAssertionIsQuantifiable = false, e3.numCapturingParens = 0, e3.maxBackReference = 0, e3.groupNames = /* @__PURE__ */ Object.create(null), e3.backReferenceNames.length = 0, e3.branchID = null, this.regexp_disjunction(e3), e3.pos !== e3.source.length && (e3.eat(41) && e3.raise("Unmatched ')'"), (e3.eat(93) || e3.eat(125)) && e3.raise("Lone quantifier brackets")), e3.maxBackReference > e3.numCapturingParens && e3.raise("Invalid escape"); for (var t3 = 0, r3 = e3.backReferenceNames; t3 < r3.length; t3 += 1) { var n2 = r3[t3]; e3.groupNames[n2] || e3.raise("Invalid named capture referenced"); } }, Le.regexp_disjunction = function(e3) { var t3 = this.options.ecmaVersion >= 16; for (t3 && (e3.branchID = new Re(e3.branchID, null)), this.regexp_alternative(e3); e3.eat(124); ) t3 && (e3.branchID = e3.branchID.sibling()), this.regexp_alternative(e3); t3 && (e3.branchID = e3.branchID.parent), this.regexp_eatQuantifier(e3, true) && e3.raise("Nothing to repeat"), e3.eat(123) && e3.raise("Lone quantifier brackets"); }, Le.regexp_alternative = function(e3) { for (; e3.pos < e3.source.length && this.regexp_eatTerm(e3); ) ; }, Le.regexp_eatTerm = function(e3) { return this.regexp_eatAssertion(e3) ? (e3.lastAssertionIsQuantifiable && this.regexp_eatQuantifier(e3) && e3.switchU && e3.raise("Invalid quantifier"), true) : !!(e3.switchU ? this.regexp_eatAtom(e3) : this.regexp_eatExtendedAtom(e3)) && (this.regexp_eatQuantifier(e3), true); }, Le.regexp_eatAssertion = function(e3) { var t3 = e3.pos; if (e3.lastAssertionIsQuantifiable = false, e3.eat(94) || e3.eat(36)) return true; if (e3.eat(92)) { if (e3.eat(66) || e3.eat(98)) return true; e3.pos = t3; } if (e3.eat(40) && e3.eat(63)) { var r3 = false; if (this.options.ecmaVersion >= 9 && (r3 = e3.eat(60)), e3.eat(61) || e3.eat(33)) return this.regexp_disjunction(e3), e3.eat(41) || e3.raise("Unterminated group"), e3.lastAssertionIsQuantifiable = !r3, true; } return e3.pos = t3, false; }, Le.regexp_eatQuantifier = function(e3, t3) { return void 0 === t3 && (t3 = false), !!this.regexp_eatQuantifierPrefix(e3, t3) && (e3.eat(63), true); }, Le.regexp_eatQuantifierPrefix = function(e3, t3) { return e3.eat(42) || e3.eat(43) || e3.eat(63) || this.regexp_eatBracedQuantifier(e3, t3); }, Le.regexp_eatBracedQuantifier = function(e3, t3) { var r3 = e3.pos; if (e3.eat(123)) { var n2 = 0, i2 = -1; if (this.regexp_eatDecimalDigits(e3) && (n2 = e3.lastIntValue, e3.eat(44) && this.regexp_eatDecimalDigits(e3) && (i2 = e3.lastIntValue), e3.eat(125))) return -1 !== i2 && i2 < n2 && !t3 && e3.raise("numbers out of order in {} quantifier"), true; e3.switchU && !t3 && e3.raise("Incomplete quantifier"), e3.pos = r3; } return false; }, Le.regexp_eatAtom = function(e3) { return this.regexp_eatPatternCharacters(e3) || e3.eat(46) || this.regexp_eatReverseSolidusAtomEscape(e3) || this.regexp_eatCharacterClass(e3) || this.regexp_eatUncapturingGroup(e3) || this.regexp_eatCapturingGroup(e3); }, Le.regexp_eatReverseSolidusAtomEscape = function(e3) { var t3 = e3.pos; if (e3.eat(92)) { if (this.regexp_eatAtomEscape(e3)) return true; e3.pos = t3; } return false; }, Le.regexp_eatUncapturingGroup = function(e3) { var t3 = e3.pos; if (e3.eat(40)) { if (e3.eat(63)) { if (this.options.ecmaVersion >= 16) { var r3 = this.regexp_eatModifiers(e3), n2 = e3.eat(45); if (r3 || n2) { for (var i2 = 0; i2 < r3.length; i2++) { var s2 = r3.charAt(i2); r3.indexOf(s2, i2 + 1) > -1 && e3.raise("Duplicate regular expression modifiers"); } if (n2) { var a2 = this.regexp_eatModifiers(e3); r3 || a2 || 58 !== e3.current() || e3.raise("Invalid regular expression modifiers"); for (var o2 = 0; o2 < a2.length; o2++) { var u2 = a2.charAt(o2); (a2.indexOf(u2, o2 + 1) > -1 || r3.indexOf(u2) > -1) && e3.raise("Duplicate regular expression modifiers"); } } } } if (e3.eat(58)) { if (this.regexp_disjunction(e3), e3.eat(41)) return true; e3.raise("Unterminated group"); } } e3.pos = t3; } return false; }, Le.regexp_eatCapturingGroup = function(e3) { if (e3.eat(40)) { if (this.options.ecmaVersion >= 9 ? this.regexp_groupSpecifier(e3) : 63 === e3.current() && e3.raise("Invalid group"), this.regexp_disjunction(e3), e3.eat(41)) return e3.numCapturingParens += 1, true; e3.raise("Unterminated group"); } return false; }, Le.regexp_eatModifiers = function(e3) { for (var t3 = "", r3 = 0; -1 !== (r3 = e3.current()) && Ne(r3); ) t3 += R(r3), e3.advance(); return t3; }, Le.regexp_eatExtendedAtom = function(e3) { return e3.eat(46) || this.regexp_eatReverseSolidusAtomEscape(e3) || this.regexp_eatCharacterClass(e3) || this.regexp_eatUncapturingGroup(e3) || this.regexp_eatCapturingGroup(e3) || this.regexp_eatInvalidBracedQuantifier(e3) || this.regexp_eatExtendedPatternCharacter(e3); }, Le.regexp_eatInvalidBracedQuantifier = function(e3) { return this.regexp_eatBracedQuantifier(e3, true) && e3.raise("Nothing to repeat"), false; }, Le.regexp_eatSyntaxCharacter = function(e3) { var t3 = e3.current(); return !!Ve(t3) && (e3.lastIntValue = t3, e3.advance(), true); }, Le.regexp_eatPatternCharacters = function(e3) { for (var t3 = e3.pos, r3 = 0; -1 !== (r3 = e3.current()) && !Ve(r3); ) e3.advance(); return e3.pos !== t3; }, Le.regexp_eatExtendedPatternCharacter = function(e3) { var t3 = e3.current(); return !(-1 === t3 || 36 === t3 || t3 >= 40 && t3 <= 43 || 46 === t3 || 63 === t3 || 91 === t3 || 94 === t3 || 124 === t3) && (e3.advance(), true); }, Le.regexp_groupSpecifier = function(e3) { if (e3.eat(63)) { this.regexp_eatGroupName(e3) || e3.raise("Invalid group"); var t3 = this.options.ecmaVersion >= 16, r3 = e3.groupNames[e3.lastStringValue]; if (r3) if (t3) for (var n2 = 0, i2 = r3; n2 < i2.length; n2 += 1) { i2[n2].separatedFrom(e3.branchID) || e3.raise("Duplicate capture group name"); } else e3.raise("Duplicate capture group name"); t3 ? (r3 || (e3.groupNames[e3.lastStringValue] = [])).push(e3.branchID) : e3.groupNames[e3.lastStringValue] = true; } }, Le.regexp_eatGroupName = function(e3) { if (e3.lastStringValue = "", e3.eat(60)) { if (this.regexp_eatRegExpIdentifierName(e3) && e3.eat(62)) return true; e3.raise("Invalid capture group name"); } return false; }, Le.regexp_eatRegExpIdentifierName = function(e3) { if (e3.lastStringValue = "", this.regexp_eatRegExpIdentifierStart(e3)) { for (e3.lastStringValue += R(e3.lastIntValue); this.regexp_eatRegExpIdentifierPart(e3); ) e3.lastStringValue += R(e3.lastIntValue); return true; } return false; }, Le.regexp_eatRegExpIdentifierStart = function(e3) { var t3 = e3.pos, r3 = this.options.ecmaVersion >= 11, n2 = e3.current(r3); return e3.advance(r3), 92 === n2 && this.regexp_eatRegExpUnicodeEscapeSequence(e3, r3) && (n2 = e3.lastIntValue), function(e4) { return c(e4, true) || 36 === e4 || 95 === e4; }(n2) ? (e3.lastIntValue = n2, true) : (e3.pos = t3, false); }, Le.regexp_eatRegExpIdentifierPart = function(e3) { var t3 = e3.pos, r3 = this.options.ecmaVersion >= 11, n2 = e3.current(r3); return e3.advance(r3), 92 === n2 && this.regexp_eatRegExpUnicodeEscapeSequence(e3, r3) && (n2 = e3.lastIntValue), function(e4) { return p(e4, true) || 36 === e4 || 95 === e4 || 8204 === e4 || 8205 === e4; }(n2) ? (e3.lastIntValue = n2, true) : (e3.pos = t3, false); }, Le.regexp_eatAtomEscape = function(e3) { return !!(this.regexp_eatBackReference(e3) || this.regexp_eatCharacterClassEscape(e3) || this.regexp_eatCharacterEscape(e3) || e3.switchN && this.regexp_eatKGroupName(e3)) || (e3.switchU && (99 === e3.current() && e3.raise("Invalid unicode escape"), e3.raise("Invalid escape")), false); }, Le.regexp_eatBackReference = function(e3) { var t3 = e3.pos; if (this.regexp_eatDecimalEscape(e3)) { var r3 = e3.lastIntValue; if (e3.switchU) return r3 > e3.maxBackReference && (e3.maxBackReference = r3), true; if (r3 <= e3.numCapturingParens) return true; e3.pos = t3; } return false; }, Le.regexp_eatKGroupName = function(e3) { if (e3.eat(107)) { if (this.regexp_eatGroupName(e3)) return e3.backReferenceNames.push(e3.lastStringValue), true; e3.raise("Invalid named reference"); } return false; }, Le.regexp_eatCharacterEscape = function(e3) { return this.regexp_eatControlEscape(e3) || this.regexp_eatCControlLetter(e3) || this.regexp_eatZero(e3) || this.regexp_eatHexEscapeSequence(e3) || this.regexp_eatRegExpUnicodeEscapeSequence(e3, false) || !e3.switchU && this.regexp_eatLegacyOctalEscapeSequence(e3) || this.regexp_eatIdentityEscape(e3); }, Le.regexp_eatCControlLetter = function(e3) { var t3 = e3.pos; if (e3.eat(99)) { if (this.regexp_eatControlLetter(e3)) return true; e3.pos = t3; } return false; }, Le.regexp_eatZero = function(e3) { return 48 === e3.current() && !Pe(e3.lookahead()) && (e3.lastIntValue = 0, e3.advance(), true); }, Le.regexp_eatControlEscape = function(e3) { var t3 = e3.current(); return 116 === t3 ? (e3.lastIntValue = 9, e3.advance(), true) : 110 === t3 ? (e3.lastIntValue = 10, e3.advance(), true) : 118 === t3 ? (e3.lastIntValue = 11, e3.advance(), true) : 102 === t3 ? (e3.lastIntValue = 12, e3.advance(), true) : 114 === t3 && (e3.lastIntValue = 13, e3.advance(), true); }, Le.regexp_eatControlLetter = function(e3) { var t3 = e3.current(); return !!Me(t3) && (e3.lastIntValue = t3 % 32, e3.advance(), true); }, Le.regexp_eatRegExpUnicodeEscapeSequence = function(e3, t3) { void 0 === t3 && (t3 = false); var r3, n2 = e3.pos, i2 = t3 || e3.switchU; if (e3.eat(117)) { if (this.regexp_eatFixedHexDigits(e3, 4)) { var s2 = e3.lastIntValue; if (i2 && s2 >= 55296 && s2 <= 56319) { var a2 = e3.pos; if (e3.eat(92) && e3.eat(117) && this.regexp_eatFixedHexDigits(e3, 4)) { var o2 = e3.lastIntValue; if (o2 >= 56320 && o2 <= 57343) return e3.lastIntValue = 1024 * (s2 - 55296) + (o2 - 56320) + 65536, true; } e3.pos = a2, e3.lastIntValue = s2; } return true; } if (i2 && e3.eat(123) && this.regexp_eatHexDigits(e3) && e3.eat(125) && ((r3 = e3.lastIntValue) >= 0 && r3 <= 1114111)) return true; i2 && e3.raise("Invalid unicode escape"), e3.pos = n2; } return false; }, Le.regexp_eatIdentityEscape = function(e3) { if (e3.switchU) return !!this.regexp_eatSyntaxCharacter(e3) || !!e3.eat(47) && (e3.lastIntValue = 47, true); var t3 = e3.current(); return !(99 === t3 || e3.switchN && 107 === t3) && (e3.lastIntValue = t3, e3.advance(), true); }, Le.regexp_eatDecimalEscape = function(e3) { e3.lastIntValue = 0; var t3 = e3.current(); if (t3 >= 49 && t3 <= 57) { do { e3.lastIntValue = 10 * e3.lastIntValue + (t3 - 48), e3.advance(); } while ((t3 = e3.current()) >= 48 && t3 <= 57); return true; } return false; }; function Oe(e3) { return Me(e3) || 95 === e3; } function ze(e3) { return Oe(e3) || Pe(e3); } function Pe(e3) { return e3 >= 48 && e3 <= 57; } function Ke(e3) { return e3 >= 48 && e3 <= 57 || e3 >= 65 && e3 <= 70 || e3 >= 97 && e3 <= 102; } function Ge(e3) { return e3 >= 65 && e3 <= 70 ? e3 - 65 + 10 : e3 >= 97 && e3 <= 102 ? e3 - 97 + 10 : e3 - 48; } function Ue(e3) { return e3 >= 48 && e3 <= 55; } Le.regexp_eatCharacterClassEscape = function(e3) { var t3 = e3.current(); if (/* @__PURE__ */ function(e4) { return 100 === e4 || 68 === e4 || 115 === e4 || 83 === e4 || 119 === e4 || 87 === e4; }(t3)) return e3.lastIntValue = -1, e3.advance(), 1; var r3 = false; if (e3.switchU && this.options.ecmaVersion >= 9 && ((r3 = 80 === t3) || 112 === t3)) { var n2; if (e3.lastIntValue = -1, e3.advance(), e3.eat(123) && (n2 = this.regexp_eatUnicodePropertyValueExpression(e3)) && e3.eat(125)) return r3 && 2 === n2 && e3.raise("Invalid property name"), n2; e3.raise("Invalid property name"); } return 0; }, Le.regexp_eatUnicodePropertyValueExpression = function(e3) { var t3 = e3.pos; if (this.regexp_eatUnicodePropertyName(e3) && e3.eat(61)) { var r3 = e3.lastStringValue; if (this.regexp_eatUnicodePropertyValue(e3)) { var n2 = e3.lastStringValue; return this.regexp_validateUnicodePropertyNameAndValue(e3, r3, n2), 1; } } if (e3.pos = t3, this.regexp_eatLoneUnicodePropertyNameOrValue(e3)) { var i2 = e3.lastStringValue; return this.regexp_validateUnicodePropertyNameOrValue(e3, i2); } return 0; }, Le.regexp_validateUnicodePropertyNameAndValue = function(e3, t3, r3) { D(e3.unicodeProperties.nonBinary, t3) || e3.raise("Invalid property name"), e3.unicodeProperties.nonBinary[t3].test(r3) || e3.raise("Invalid property value"); }, Le.regexp_validateUnicodePropertyNameOrValue = function(e3, t3) { return e3.unicodeProperties.binary.test(t3) ? 1 : e3.switchV && e3.unicodeProperties.binaryOfStrings.test(t3) ? 2 : void e3.raise("Invalid property name"); }, Le.regexp_eatUnicodePropertyName = function(e3) { var t3 = 0; for (e3.lastStringValue = ""; Oe(t3 = e3.current()); ) e3.lastStringValue += R(t3), e3.advance(); return "" !== e3.lastStringValue; }, Le.regexp_eatUnicodePropertyValue = function(e3) { var t3 = 0; for (e3.lastStringValue = ""; ze(t3 = e3.current()); ) e3.lastStringValue += R(t3), e3.advance(); return "" !== e3.lastStringValue; }, Le.regexp_eatLoneUnicodePropertyNameOrValue = function(e3) { return this.regexp_eatUnicodePropertyValue(e3); }, Le.regexp_eatCharacterClass = function(e3) { if (e3.eat(91)) { var t3 = e3.eat(94), r3 = this.regexp_classContents(e3); return e3.eat(93) || e3.raise("Unterminated character class"), t3 && 2 === r3 && e3.raise("Negated character class may contain strings"), true; } return false; }, Le.regexp_classContents = function(e3) { return 93 === e3.current() ? 1 : e3.switchV ? this.regexp_classSetExpression(e3) : (this.regexp_nonEmptyClassRanges(e3), 1); }, Le.regexp_nonEmptyClassRanges = function(e3) { for (; this.regexp_eatClassAtom(e3); ) { var t3 = e3.lastIntValue; if (e3.eat(45) && this.regexp_eatClassAtom(e3)) { var r3 = e3.lastIntValue; !e3.switchU || -1 !== t3 && -1 !== r3 || e3.raise("Invalid character class"), -1 !== t3 && -1 !== r3 && t3 > r3 && e3.raise("Range out of order in character class"); } } }, Le.regexp_eatClassAtom = function(e3) { var t3 = e3.pos; if (e3.eat(92)) { if (this.regexp_eatClassEscape(e3)) return true; if (e3.switchU) { var r3 = e3.current(); (99 === r3 || Ue(r3)) && e3.raise("Invalid class escape"), e3.raise("Invalid escape"); } e3.pos = t3; } var n2 = e3.current(); return 93 !== n2 && (e3.lastIntValue = n2, e3.advance(), true); }, Le.regexp_eatClassEscape = function(e3) { var t3 = e3.pos; if (e3.eat(98)) return e3.lastIntValue = 8, true; if (e3.switchU && e3.eat(45)) return e3.lastIntValue = 45, true; if (!e3.switchU && e3.eat(99)) { if (this.regexp_eatClassControlLetter(e3)) return true; e3.pos = t3; } return this.regexp_eatCharacterClassEscape(e3) || this.regexp_eatCharacterEscape(e3); }, Le.regexp_classSetExpression = function(e3) { var t3, r3 = 1; if (this.regexp_eatClassSetRange(e3)) ; else if (t3 = this.regexp_eatClassSetOperand(e3)) { 2 === t3 && (r3 = 2); for (var n2 = e3.pos; e3.eatChars([38, 38]); ) 38 !== e3.current() && (t3 = this.regexp_eatClassSetOperand(e3)) ? 2 !== t3 && (r3 = 1) : e3.raise("Invalid character in character class"); if (n2 !== e3.pos) return r3; for (; e3.eatChars([45, 45]); ) this.regexp_eatClassSetOperand(e3) || e3.raise("Invalid character in character class"); if (n2 !== e3.pos) return r3; } else e3.raise("Invalid character in character class"); for (; ; ) if (!this.regexp_eatClassSetRange(e3)) { if (!(t3 = this.regexp_eatClassSetOperand(e3))) return r3; 2 === t3 && (r3 = 2); } }, Le.regexp_eatClassSetRange = function(e3) { var t3 = e3.pos; if (this.regexp_eatClassSetCharacter(e3)) { var r3 = e3.lastIntValue; if (e3.eat(45) && this.regexp_eatClassSetCharacter(e3)) { var n2 = e3.lastIntValue; return -1 !== r3 && -1 !== n2 && r3 > n2 && e3.raise("Range out of order in character class"), true; } e3.pos = t3; } return false; }, Le.regexp_eatClassSetOperand = function(e3) { return this.regexp_eatClassSetCharacter(e3) ? 1 : this.regexp_eatClassStringDisjunction(e3) || this.regexp_eatNestedClass(e3); }, Le.regexp_eatNestedClass = function(e3) { var t3 = e3.pos; if (e3.eat(91)) { var r3 = e3.eat(94), n2 = this.regexp_classContents(e3); if (e3.eat(93)) return r3 && 2 === n2 && e3.raise("Negated character class may contain strings"), n2; e3.pos = t3; } if (e3.eat(92)) { var i2 = this.regexp_eatCharacterClassEscape(e3); if (i2) return i2; e3.pos = t3; } return null; }, Le.regexp_eatClassStringDisjunction = function(e3) { var t3 = e3.pos; if (e3.eatChars([92, 113])) { if (e3.eat(123)) { var r3 = this.regexp_classStringDisjunctionContents(e3); if (e3.eat(125)) return r3; } else e3.raise("Invalid escape"); e3.pos = t3; } return null; }, Le.regexp_classStringDisjunctionContents = function(e3) { for (var t3 = this.regexp_classString(e3); e3.eat(124); ) 2 === this.regexp_classString(e3) && (t3 = 2); return t3; }, Le.regexp_classString = function(e3) { for (var t3 = 0; this.regexp_eatClassSetCharacter(e3); ) t3++; return 1 === t3 ? 1 : 2; }, Le.regexp_eatClassSetCharacter = function(e3) { var t3 = e3.pos; if (e3.eat(92)) return !(!this.regexp_eatCharacterEscape(e3) && !this.regexp_eatClassSetReservedPunctuator(e3)) || (e3.eat(98) ? (e3.lastIntValue = 8, true) : (e3.pos = t3, false)); var r3 = e3.current(); return !(r3 < 0 || r3 === e3.lookahead() && function(e4) { return 33 === e4 || e4 >= 35 && e4 <= 38 || e4 >= 42 && e4 <= 44 || 46 === e4 || e4 >= 58 && e4 <= 64 || 94 === e4 || 96 === e4 || 126 === e4; }(r3)) && (!function(e4) { return 40 === e4 || 41 === e4 || 45 === e4 || 47 === e4 || e4 >= 91 && e4 <= 93 || e4 >= 123 && e4 <= 125; }(r3) && (e3.advance(), e3.lastIntValue = r3, true)); }, Le.regexp_eatClassSetReservedPunctuator = function(e3) { var t3 = e3.current(); return !!function(e4) { return 33 === e4 || 35 === e4 || 37 === e4 || 38 === e4 || 44 === e4 || 45 === e4 || e4 >= 58 && e4 <= 62 || 64 === e4 || 96 === e4 || 126 === e4; }(t3) && (e3.lastIntValue = t3, e3.advance(), true); }, Le.regexp_eatClassControlLetter = function(e3) { var t3 = e3.current(); return !(!Pe(t3) && 95 !== t3) && (e3.lastIntValue = t3 % 32, e3.advance(), true); }, Le.regexp_eatHexEscapeSequence = function(e3) { var t3 = e3.pos; if (e3.eat(120)) { if (this.regexp_eatFixedHexDigits(e3, 2)) return true; e3.switchU && e3.raise("Invalid escape"), e3.pos = t3; } return false; }, Le.regexp_eatDecimalDigits = function(e3) { var t3 = e3.pos, r3 = 0; for (e3.lastIntValue = 0; Pe(r3 = e3.current()); ) e3.lastIntValue = 10 * e3.lastIntValue + (r3 - 48), e3.advance(); return e3.pos !== t3; }, Le.regexp_eatHexDigits = function(e3) { var t3 = e3.pos, r3 = 0; for (e3.lastIntValue = 0; Ke(r3 = e3.current()); ) e3.lastIntValue = 16 * e3.lastIntValue + Ge(r3), e3.advance(); return e3.pos !== t3; }, Le.regexp_eatLegacyOctalEscapeSequence = function(e3) { if (this.regexp_eatOctalDigit(e3)) { var t3 = e3.lastIntValue; if (this.regexp_eatOctalDigit(e3)) { var r3 = e3.lastIntValue; t3 <= 3 && this.regexp_eatOctalDigit(e3) ? e3.lastIntValue = 64 * t3 + 8 * r3 + e3.lastIntValue : e3.lastIntValue = 8 * t3 + r3; } else e3.lastIntValue = t3; return true; } return false; }, Le.regexp_eatOctalDigit = function(e3) { var t3 = e3.current(); return Ue(t3) ? (e3.lastIntValue = t3 - 48, e3.advance(), true) : (e3.lastIntValue = 0, false); }, Le.regexp_eatFixedHexDigits = function(e3, t3) { var r3 = e3.pos; e3.lastIntValue = 0; for (var n2 = 0; n2 < t3; ++n2) { var i2 = e3.current(); if (!Ke(i2)) return e3.pos = r3, false; e3.lastIntValue = 16 * e3.lastIntValue + Ge(i2), e3.advance(); } return true; }; var Be = function(e3) { this.type = e3.type, this.value = e3.value, this.start = e3.start, this.end = e3.end, e3.options.locations && (this.loc = new V(e3, e3.startLoc, e3.endLoc)), e3.options.ranges && (this.range = [e3.start, e3.end]); }, We = U.prototype; function je(e3) { return "function" != typeof BigInt ? null : BigInt(e3.replace(/_/g, "")); } We.next = function(e3) { !e3 && this.type.keyword && this.containsEsc && this.raiseRecoverable(this.start, "Escape sequence in keyword " + this.type.keyword), this.options.onToken && this.options.onToken(new Be(this)), this.lastTokEnd = this.end, this.lastTokStart = this.start, this.lastTokEndLoc = this.endLoc, this.lastTokStartLoc = this.startLoc, this.nextToken(); }, We.getToken = function() { return this.next(), new Be(this); }, "undefined" != typeof Symbol && (We[Symbol.iterator] = function() { var e3 = this; return { next: function() { var t3 = e3.getToken(); return { done: t3.type === b.eof, value: t3 }; } }; }), We.nextToken = function() { var e3 = this.curContext(); return e3 && e3.preserveSpace || this.skipSpace(), this.start = this.pos, this.options.locations && (this.startLoc = this.curPosition()), this.pos >= this.input.length ? this.finishToken(b.eof) : e3.override ? e3.override(this) : void this.readToken(this.fullCharCodeAtPos()); }, We.readToken = function(e3) { return c(e3, this.options.ecmaVersion >= 6) || 92 === e3 ? this.readWord() : this.getTokenFromCode(e3); }, We.fullCharCodeAtPos = function() { var e3 = this.input.charCodeAt(this.pos); if (e3 <= 55295 || e3 >= 56320) return e3; var t3 = this.input.charCodeAt(this.pos + 1); return t3 <= 56319 || t3 >= 57344 ? e3 : (e3 << 10) + t3 - 56613888; }, We.skipBlockComment = function() { var e3 = this.options.onComment && this.curPosition(), t3 = this.pos, r3 = this.input.indexOf("*/", this.pos += 2); if (-1 === r3 && this.raise(this.pos - 2, "Unterminated comment"), this.pos = r3 + 2, this.options.locations) for (var n2 = void 0, i2 = t3; (n2 = A(this.input, i2, this.pos)) > -1; ) ++this.curLine, i2 = this.lineStart = n2; this.options.onComment && this.options.onComment(true, this.input.slice(t3 + 2, r3), t3, this.pos, e3, this.curPosition()); }, We.skipLineComment = function(e3) { for (var t3 = this.pos, r3 = this.options.onComment && this.curPosition(), n2 = this.input.charCodeAt(this.pos += e3); this.pos < this.input.length && !S(n2); ) n2 = this.input.charCodeAt(++this.pos); this.options.onComment && this.options.onComment(false, this.input.slice(t3 + e3, this.pos), t3, this.pos, r3, this.curPosition()); }, We.skipSpace = function() { e: for (; this.pos < this.input.length; ) { var e3 = this.input.charCodeAt(this.pos); switch (e3) { case 32: case 160: ++this.pos; break; case 13: 10 === this.input.charCodeAt(this.pos + 1) && ++this.pos; case 10: case 8232: case 8233: ++this.pos, this.options.locations && (++this.curLine, this.lineStart = this.pos); break; case 47: switch (this.input.charCodeAt(this.pos + 1)) { case 42: this.skipBlockComment(); break; case 47: this.skipLineComment(2); break; default: break e; } break; default: if (!(e3 > 8 && e3 < 14 || e3 >= 5760 && _.test(String.fromCharCode(e3)))) break e; ++this.pos; } } }, We.finishToken = function(e3, t3) { this.end = this.pos, this.options.locations && (this.endLoc = this.curPosition()); var r3 = this.type; this.type = e3, this.value = t3, this.updateContext(r3); }, We.readToken_dot = function() { var e3 = this.input.charCodeAt(this.pos + 1); if (e3 >= 48 && e3 <= 57) return this.readNumber(true); var t3 = this.input.charCodeAt(this.pos + 2); return this.options.ecmaVersion >= 6 && 46 === e3 && 46 === t3 ? (this.pos += 3, this.finishToken(b.ellipsis)) : (++this.pos, this.finishToken(b.dot)); }, We.readToken_slash = function() { var e3 = this.input.charCodeAt(this.pos + 1); return this.exprAllowed ? (++this.pos, this.readRegexp()) : 61 === e3 ? this.finishOp(b.assign, 2) : this.finishOp(b.slash, 1); }, We.readToken_mult_modulo_exp = function(e3) { var t3 = this.input.charCodeAt(this.pos + 1), r3 = 1, n2 = 42 === e3 ? b.star : b.modulo; return this.options.ecmaVersion >= 7 && 42 === e3 && 42 === t3 && (++r3, n2 = b.starstar, t3 = this.input.charCodeAt(this.pos + 2)), 61 === t3 ? this.finishOp(b.assign, r3 + 1) : this.finishOp(n2, r3); }, We.readToken_pipe_amp = function(e3) { var t3 = this.input.charCodeAt(this.pos + 1); if (t3 === e3) { if (this.options.ecmaVersion >= 12) { if (61 === this.input.charCodeAt(this.pos + 2)) return this.finishOp(b.assign, 3); } return this.finishOp(124 === e3 ? b.logicalOR : b.logicalAND, 2); } return 61 === t3 ? this.finishOp(b.assign, 2) : this.finishOp(124 === e3 ? b.bitwiseOR : b.bitwiseAND, 1); }, We.readToken_caret = function() { return 61 === this.input.charCodeAt(this.pos + 1) ? this.finishOp(b.assign, 2) : this.finishOp(b.bitwiseXOR, 1); }, We.readToken_plus_min = function(e3) { var t3 = this.input.charCodeAt(this.pos + 1); return t3 === e3 ? 45 !== t3 || this.inModule || 62 !== this.input.charCodeAt(this.pos + 2) || 0 !== this.lastTokEnd && !T.test(this.input.slice(this.lastTokEnd, this.pos)) ? this.finishOp(b.incDec, 2) : (this.skipLineComment(3), this.skipSpace(), this.nextToken()) : 61 === t3 ? this.finishOp(b.assign, 2) : this.finishOp(b.plusMin, 1); }, We.readToken_lt_gt = function(e3) { var t3 = this.input.charCodeAt(this.pos + 1), r3 = 1; return t3 === e3 ? (r3 = 62 === e3 && 62 === this.input.charCodeAt(this.pos + 2) ? 3 : 2, 61 === this.input.charCodeAt(this.pos + r3) ? this.finishOp(b.assign, r3 + 1) : this.finishOp(b.bitShift, r3)) : 33 !== t3 || 60 !== e3 || this.inModule || 45 !== this.input.charCodeAt(this.pos + 2) || 45 !== this.input.charCodeAt(this.pos + 3) ? (61 === t3 && (r3 = 2), this.finishOp(b.relational, r3)) : (this.skipLineComment(4), this.skipSpace(), this.nextToken()); }, We.readToken_eq_excl = function(e3) { var t3 = this.input.charCodeAt(this.pos + 1); return 61 === t3 ? this.finishOp(b.equality, 61 === this.input.charCodeAt(this.pos + 2) ? 3 : 2) : 61 === e3 && 62 === t3 && this.options.ecmaVersion >= 6 ? (this.pos += 2, this.finishToken(b.arrow)) : this.finishOp(61 === e3 ? b.eq : b.prefix, 1); }, We.readToken_question = function() { var e3 = this.options.ecmaVersion; if (e3 >= 11) { var t3 = this.input.charCodeAt(this.pos + 1); if (46 === t3) { var r3 = this.input.charCodeAt(this.pos + 2); if (r3 < 48 || r3 > 57) return this.finishOp(b.questionDot, 2); } if (63 === t3) { if (e3 >= 12) { if (61 === this.input.charCodeAt(this.pos + 2)) return this.finishOp(b.assign, 3); } return this.finishOp(b.coalesce, 2); } } return this.finishOp(b.question, 1); }, We.readToken_numberSign = function() { var e3 = 35; if (this.options.ecmaVersion >= 13 && (++this.pos, c(e3 = this.fullCharCodeAtPos(), true) || 92 === e3)) return this.finishToken(b.privateId, this.readWord1()); this.raise(this.pos, "Unexpected character '" + R(e3) + "'"); }, We.getTokenFromCode = function(e3) { switch (e3) { case 46: return this.readToken_dot(); case 40: return ++this.pos, this.finishToken(b.parenL); case 41: return ++this.pos, this.finishToken(b.parenR); case 59: return ++this.pos, this.finishToken(b.semi); case 44: return ++this.pos, this.finishToken(b.comma); case 91: return ++this.pos, this.finishToken(b.bracketL); case 93: return ++this.pos, this.finishToken(b.bracketR); case 123: return ++this.pos, this.finishToken(b.braceL); case 125: return ++this.pos, this.finishToken(b.braceR); case 58: return ++this.pos, this.finishToken(b.colon); case 96: if (this.options.ecmaVersion < 6) break; return ++this.pos, this.finishToken(b.backQuote); case 48: var t3 = this.input.charCodeAt(this.pos + 1); if (120 === t3 || 88 === t3) return this.readRadixNumber(16); if (this.options.ecmaVersion >= 6) { if (111 === t3 || 79 === t3) return this.readRadixNumber(8); if (98 === t3 || 66 === t3) return this.readRadixNumber(2); } case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: return this.readNumber(false); case 34: case 39: return this.readString(e3); case 47: return this.readToken_slash(); case 37: case 42: return this.readToken_mult_modulo_exp(e3); case 124: case 38: return this.readToken_pipe_amp(e3); case 94: return this.readToken_caret(); case 43: case 45: return this.readToken_plus_min(e3); case 60: case 62: return this.readToken_lt_gt(e3); case 61: case 33: return this.readToken_eq_excl(e3); case 63: return this.readToken_question(); case 126: return this.finishOp(b.prefix, 1); case 35: return this.readToken_numberSign(); } this.raise(this.pos, "Unexpected character '" + R(e3) + "'"); }, We.finishOp = function(e3, t3) { var r3 = this.input.slice(this.pos, this.pos + t3); return this.pos += t3, this.finishToken(e3, r3); }, We.readRegexp = function() { for (var e3, t3, r3 = this.pos; ; ) { this.pos >= this.input.length && this.raise(r3, "Unterminated regular expression"); var n2 = this.input.charAt(this.pos); if (T.test(n2) && this.raise(r3, "Unterminated regular expression"), e3) e3 = false; else { if ("[" === n2) t3 = true; else if ("]" === n2 && t3) t3 = false; else if ("/" === n2 && !t3) break; e3 = "\\" === n2; } ++this.pos; } var i2 = this.input.slice(r3, this.pos); ++this.pos; var s2 = this.pos, a2 = this.readWord1(); this.containsEsc && this.unexpected(s2); var o2 = this.regexpState || (this.regexpState = new Fe(this)); o2.reset(r3, i2, a2), this.validateRegExpFlags(o2), this.validateRegExpPattern(o2); var u2 = null; try { u2 = new RegExp(i2, a2); } catch (e4) { } return this.finishToken(b.regexp, { pattern: i2, flags: a2, value: u2 }); }, We.readInt = function(e3, t3, r3) { for (var n2 = this.options.ecmaVersion >= 12 && void 0 === t3, i2 = r3 && 48 === this.input.charCodeAt(this.pos), s2 = this.pos, a2 = 0, o2 = 0, u2 = 0, l2 = null == t3 ? 1 / 0 : t3; u2 < l2; ++u2, ++this.pos) { var h2 = this.input.charCodeAt(this.pos), c2 = void 0; if (n2 && 95 === h2) i2 && this.raiseRecoverable(this.pos, "Numeric separator is not allowed in legacy octal numeric literals"), 95 === o2 && this.raiseRecoverable(this.pos, "Numeric separator must be exactly one underscore"), 0 === u2 && this.raiseRecoverable(this.pos, "Numeric separator is not allowed at the first of digits"), o2 = h2; else { if ((c2 = h2 >= 97 ? h2 - 97 + 10 : h2 >= 65 ? h2 - 65 + 10 : h2 >= 48 && h2 <= 57 ? h2 - 48 : 1 / 0) >= e3) break; o2 = h2, a2 = a2 * e3 + c2; } } return n2 && 95 === o2 && this.raiseRecoverable(this.pos - 1, "Numeric separator is not allowed at the last of digits"), this.pos === s2 || null != t3 && this.pos - s2 !== t3 ? null : a2; }, We.readRadixNumber = function(e3) { var t3 = this.pos; this.pos += 2; var r3 = this.readInt(e3); return null == r3 && this.raise(this.start + 2, "Expected number in radix " + e3), this.options.ecmaVersion >= 11 && 110 === this.input.charCodeAt(this.pos) ? (r3 = je(this.input.slice(t3, this.pos)), ++this.pos) : c(this.fullCharCodeAtPos()) && this.raise(this.pos, "Identifier directly after number"), this.finishToken(b.num, r3); }, We.readNumber = function(e3) { var t3 = this.pos; e3 || null !== this.readInt(10, void 0, true) || this.raise(t3, "Invalid number"); var r3 = this.pos - t3 >= 2 && 48 === this.input.charCodeAt(t3); r3 && this.strict && this.raise(t3, "Invalid number"); var n2 = this.input.charCodeAt(this.pos); if (!r3 && !e3 && this.options.ecmaVersion >= 11 && 110 === n2) { var i2 = je(this.input.slice(t3, this.pos)); return ++this.pos, c(this.fullCharCodeAtPos()) && this.raise(this.pos, "Identifier directly after number"), this.finishToken(b.num, i2); } r3 && /[89]/.test(this.input.slice(t3, this.pos)) && (r3 = false), 46 !== n2 || r3 || (++this.pos, this.readInt(10), n2 = this.input.charCodeAt(this.pos)), 69 !== n2 && 101 !== n2 || r3 || (43 !== (n2 = this.input.charCodeAt(++this.pos)) && 45 !== n2 || ++this.pos, null === this.readInt(10) && this.raise(t3, "Invalid number")), c(this.fullCharCodeAtPos()) && this.raise(this.pos, "Identifier directly after number"); var s2, a2 = (s2 = this.input.slice(t3, this.pos), r3 ? parseInt(s2, 8) : parseFloat(s2.replace(/_/g, ""))); return this.finishToken(b.num, a2); }, We.readCodePoint = function() { var e3; if (123 === this.input.charCodeAt(this.pos)) { this.options.ecmaVersion < 6 && this.unexpected(); var t3 = ++this.pos; e3 = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos), ++this.pos, e3 > 1114111 && this.invalidStringToken(t3, "Code point out of bounds"); } else e3 = this.readHexChar(4); return e3; }, We.readString = function(e3) { for (var t3 = "", r3 = ++this.pos; ; ) { this.pos >= this.input.length && this.raise(this.start, "Unterminated string constant"); var n2 = this.input.charCodeAt(this.pos); if (n2 === e3) break; 92 === n2 ? (t3 += this.input.slice(r3, this.pos), t3 += this.readEscapedChar(false), r3 = this.pos) : 8232 === n2 || 8233 === n2 ? (this.options.ecmaVersion < 10 && this.raise(this.start, "Unterminated string constant"), ++this.pos, this.options.locations && (this.curLine++, this.lineStart = this.pos)) : (S(n2) && this.raise(this.start, "Unterminated string constant"), ++this.pos); } return t3 += this.input.slice(r3, this.pos++), this.finishToken(b.string, t3); }; var He = {}; We.tryReadTemplateToken = function() { this.inTemplateElement = true; try { this.readTmplToken(); } catch (e3) { if (e3 !== He) throw e3; this.readInvalidTemplateToken(); } this.inTemplateElement = false; }, We.invalidStringToken = function(e3, t3) { if (this.inTemplateElement && this.options.ecmaVersion >= 9) throw He; this.raise(e3, t3); }, We.readTmplToken = function() { for (var e3 = "", t3 = this.pos; ; ) { this.pos >= this.input.length && this.raise(this.start, "Unterminated template"); var r3 = this.input.charCodeAt(this.pos); if (96 === r3 || 36 === r3 && 123 === this.input.charCodeAt(this.pos + 1)) return this.pos !== this.start || this.type !== b.template && this.type !== b.invalidTemplate ? (e3 += this.input.slice(t3, this.pos), this.finishToken(b.template, e3)) : 36 === r3 ? (this.pos += 2, this.finishToken(b.dollarBraceL)) : (++this.pos, this.finishToken(b.backQuote)); if (92 === r3) e3 += this.input.slice(t3, this.pos), e3 += this.readEscapedChar(true), t3 = this.pos; else if (S(r3)) { switch (e3 += this.input.slice(t3, this.pos), ++this.pos, r3) { case 13: 10 === this.input.charCodeAt(this.pos) && ++this.pos; case 10: e3 += "\n"; break; default: e3 += String.fromCharCode(r3); } this.options.locations && (++this.curLine, this.lineStart = this.pos), t3 = this.pos; } else ++this.pos; } }, We.readInvalidTemplateToken = function() { for (; this.pos < this.input.length; this.pos++) switch (this.input[this.pos]) { case "\\": ++this.pos; break; case "$": if ("{" !== this.input[this.pos + 1]) break; case "`": return this.finishToken(b.invalidTemplate, this.input.slice(this.start, this.pos)); case "\r": "\n" === this.input[this.pos + 1] && ++this.pos; case "\n": case "\u2028": case "\u2029": ++this.curLine, this.lineStart = this.pos + 1; } this.raise(this.start, "Unterminated template"); }, We.readEscapedChar = function(e3) { var t3 = this.input.charCodeAt(++this.pos); switch (++this.pos, t3) { case 110: return "\n"; case 114: return "\r"; case 120: return String.fromCharCode(this.readHexChar(2)); case 117: return R(this.readCodePoint()); case 116: return " "; case 98: return "\b"; case 118: return "\v"; case 102: return "\f"; case 13: 10 === this.input.charCodeAt(this.pos) && ++this.pos; case 10: return this.options.locations && (this.lineStart = this.pos, ++this.curLine), ""; case 56: case 57: if (this.strict && this.invalidStringToken(this.pos - 1, "Invalid escape sequence"), e3) { var r3 = this.pos - 1; this.invalidStringToken(r3, "Invalid escape sequence in template string"); } default: if (t3 >= 48 && t3 <= 55) { var n2 = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0], i2 = parseInt(n2, 8); return i2 > 255 && (n2 = n2.slice(0, -1), i2 = parseInt(n2, 8)), this.pos += n2.length - 1, t3 = this.input.charCodeAt(this.pos), "0" === n2 && 56 !== t3 && 57 !== t3 || !this.strict && !e3 || this.invalidStringToken(this.pos - 1 - n2.length, e3 ? "Octal literal in template string" : "Octal literal in strict mode"), String.fromCharCode(i2); } return S(t3) ? (this.options.locations && (this.lineStart = this.pos, ++this.curLine), "") : String.fromCharCode(t3); } }, We.readHexChar = function(e3) { var t3 = this.pos, r3 = this.readInt(16, e3); return null === r3 && this.invalidStringToken(t3, "Bad character escape sequence"), r3; }, We.readWord1 = function() { this.containsEsc = false; for (var e3 = "", t3 = true, r3 = this.pos, n2 = this.options.ecmaVersion >= 6; this.pos < this.input.length; ) { var i2 = this.fullCharCodeAtPos(); if (p(i2, n2)) this.pos += i2 <= 65535 ? 1 : 2; else { if (92 !== i2) break; this.containsEsc = true, e3 += this.input.slice(r3, this.pos); var s2 = this.pos; 117 !== this.input.charCodeAt(++this.pos) && this.invalidStringToken(this.pos, "Expecting Unicode escape sequence \\uXXXX"), ++this.pos; var a2 = this.readCodePoint(); (t3 ? c : p)(a2, n2) || this.invalidStringToken(s2, "Invalid Unicode escape"), e3 += R(a2), r3 = this.pos; } t3 = false; } return e3 + this.input.slice(r3, this.pos); }, We.readWord = function() { var e3 = this.readWord1(), t3 = b.name; return this.keywords.test(e3) && (t3 = x[e3]), this.finishToken(t3, e3); }; var Xe = "8.14.0"; U.acorn = { Parser: U, version: Xe, defaultOptions: O, Position: N, SourceLocation: V, getLineInfo: M, Node: de, TokenType: d, tokTypes: b, keywordTypes: x, TokContext: ne, tokContexts: ie, isIdentifierChar: p, isIdentifierStart: c, Token: Be, isNewLine: S, lineBreak: T, lineBreakG: v, nonASCIIwhitespace: _ }, e2.Node = de, e2.Parser = U, e2.Position = N, e2.SourceLocation = V, e2.TokContext = ne, e2.Token = Be, e2.TokenType = d, e2.defaultOptions = O, e2.getLineInfo = M, e2.isIdentifierChar = p, e2.isIdentifierStart = c, e2.isNewLine = S, e2.keywordTypes = x, e2.lineBreak = T, e2.lineBreakG = v, e2.nonASCIIwhitespace = _, e2.parse = function(e3, t3) { return U.parse(e3, t3); }, e2.parseExpressionAt = function(e3, t3, r3) { return U.parseExpressionAt(e3, t3, r3); }, e2.tokContexts = ie, e2.tokTypes = b, e2.tokenizer = function(e3, t3) { return U.tokenizer(e3, t3); }, e2.version = Xe; }); }, {}], 2: [function(e, t, r) { }, {}], 3: [function(e, t, r) { function n(e2, t2 = {}) { const { contextName: r2 = "gl", throwGetError: n2, useTrackablePrimitives: o, readPixelsFile: u, recording: l = [], variables: h = {}, onReadPixels: c, onUnrecognizedArgumentLookup: p } = t2, d = new Proxy(e2, { get: function(t3, d2) { switch (d2) { case "addComment": return E; case "checkThrowError": return w; case "getReadPixelsVariableName": return g; case "insertVariable": return v; case "reset": return T; case "setIndent": return A; case "toString": return b; case "getContextVariableName": return I; } if ("function" == typeof e2[d2]) return function() { switch (d2) { case "getError": return n2 ? l.push(`${y}if (${r2}.getError() !== ${r2}.NONE) throw new Error('error');`) : l.push(`${y}${r2}.getError();`), e2.getError(); case "getExtension": { const t6 = `${r2}Variables${m.length}`; l.push(`${y}const ${t6} = ${r2}.getExtension('${arguments[0]}');`); const n3 = e2.getExtension(arguments[0]); if (n3 && "object" == typeof n3) { const e3 = i(n3, { getEntity: S, useTrackablePrimitives: o, recording: l, contextName: t6, contextVariables: m, variables: h, indent: y, onUnrecognizedArgumentLookup: p }); return m.push(e3), e3; } return m.push(null), n3; } case "readPixels": const t5 = m.indexOf(arguments[6]); let a2; if (-1 === t5) { const e3 = function(e4) { if (h) { for (const t6 in h) if (h[t6] === e4) return t6; } return null; }(arguments[6]); e3 ? (a2 = e3, l.push(`${y}${e3}`)) : (a2 = `${r2}Variable${m.length}`, m.push(arguments[6]), l.push(`${y}const ${a2} = new ${arguments[6].constructor.name}(${arguments[6].length});`)); } else a2 = `${r2}Variable${t5}`; g = a2; const d3 = [arguments[0], arguments[1], arguments[2], arguments[3], S(arguments[4]), S(arguments[5]), a2]; return l.push(`${y}${r2}.readPixels(${d3.join(", ")});`), u && function(e3, t6) { const n3 = `${r2}Variable${m.length}`, i2 = `imageDatum${x}`; l.push(`${y}let ${i2} = ["P3\\n# ${u}.ppm\\n", ${e3}, ' ', ${t6}, "\\n255\\n"].join("");`), l.push(`${y}for (let i = 0; i < ${i2}.length; i += 4) {`), l.push(`${y} ${i2} += ${n3}[i] + ' ' + ${n3}[i + 1] + ' ' + ${n3}[i + 2] + ' ';`), l.push(`${y}}`), l.push(`${y}if (typeof require !== "undefined") {`), l.push(`${y} require('fs').writeFileSync('./${u}.ppm', ${i2});`), l.push(`${y}}`), x++; }(arguments[2], arguments[3]), c && c(a2, d3), e2.readPixels.apply(e2, arguments); case "drawBuffers": return l.push(`${y}${r2}.drawBuffers([${s(arguments[0], { contextName: r2, contextVariables: m, getEntity: S, addVariable: _, variables: h, onUnrecognizedArgumentLookup: p })}]);`), e2.drawBuffers(arguments[0]); } let t4 = e2[d2].apply(e2, arguments); switch (typeof t4) { case "undefined": return void l.push(`${y}${k(d2, arguments)};`); case "number": case "boolean": if (o && -1 === m.indexOf(a(t4))) { l.push(`${y}const ${r2}Variable${m.length} = ${k(d2, arguments)};`), m.push(t4 = a(t4)); break; } default: null === t4 ? l.push(`${k(d2, arguments)};`) : l.push(`${y}const ${r2}Variable${m.length} = ${k(d2, arguments)};`), m.push(t4); } return t4; }; return f[e2[d2]] = d2, e2[d2]; } }), m = [], f = {}; let g, x = 0, y = ""; return d; function b() { return l.join("\n"); } function T() { for (; l.length > 0; ) l.pop(); } function v(e3, t3) { h[e3] = t3; } function S(e3) { const t3 = f[e3]; return t3 ? r2 + "." + t3 : e3; } function A(e3) { y = " ".repeat(e3); } function _(e3, t3) { const n3 = `${r2}Variable${m.length}`; return l.push(`${y}const ${n3} = ${t3};`), m.push(e3), n3; } function E(e3) { l.push(`${y}// ${e3}`); } function w() { l.push(`${y}(() => { ${y}const error = ${r2}.getError(); ${y}if (error !== ${r2}.NONE) { ${y} const names = Object.getOwnPropertyNames(gl); ${y} for (let i = 0; i < names.length; i++) { ${y} const name = names[i]; ${y} if (${r2}[name] === error) { ${y} throw new Error('${r2} threw ' + name); ${y} } ${y} } ${y}} ${y}})();`); } function k(e3, t3) { return `${r2}.${e3}(${s(t3, { contextName: r2, contextVariables: m, getEntity: S, addVariable: _, variables: h, onUnrecognizedArgumentLookup: p })})`; } function I(e3) { const t3 = m.indexOf(e3); return -1 !== t3 ? `${r2}Variable${t3}` : null; } } function i(e2, t2) { const r2 = new Proxy(e2, { get: function(t3, r3) { if ("function" == typeof t3[r3]) return function() { if ("drawBuffersWEBGL" === r3) return h.push(`${p}${i2}.drawBuffersWEBGL([${s(arguments[0], { contextName: i2, contextVariables: o, getEntity: m, addVariable: g, variables: c, onUnrecognizedArgumentLookup: d })}]);`), e2.drawBuffersWEBGL(arguments[0]); let t4 = e2[r3].apply(e2, arguments); switch (typeof t4) { case "undefined": return void h.push(`${p}${f(r3, arguments)};`); case "number": case "boolean": l && -1 === o.indexOf(a(t4)) ? (h.push(`${p}const ${i2}Variable${o.length} = ${f(r3, arguments)};`), o.push(t4 = a(t4))) : (h.push(`${p}const ${i2}Variable${o.length} = ${f(r3, arguments)};`), o.push(t4)); break; default: null === t4 ? h.push(`${f(r3, arguments)};`) : h.push(`${p}const ${i2}Variable${o.length} = ${f(r3, arguments)};`), o.push(t4); } return t4; }; return n2[e2[r3]] = r3, e2[r3]; } }), n2 = {}, { contextName: i2, contextVariables: o, getEntity: u, useTrackablePrimitives: l, recording: h, variables: c, indent: p, onUnrecognizedArgumentLookup: d } = t2; return r2; function m(e3) { return n2.hasOwnProperty(e3) ? `${i2}.${n2[e3]}` : u(e3); } function f(e3, t3) { return `${i2}.${e3}(${s(t3, { contextName: i2, contextVariables: o, getEntity: m, addVariable: g, variables: c, onUnrecognizedArgumentLookup: d })})`; } function g(e3, t3) { const r3 = `${i2}Variable${o.length}`; return o.push(e3), h.push(`${p}const ${r3} = ${t3};`), r3; } } function s(e2, t2) { const { variables: r2, onUnrecognizedArgumentLookup: n2 } = t2; return Array.from(e2).map((e3) => { const i2 = function(e4) { if (r2) { for (const t3 in r2) if (r2.hasOwnProperty(t3) && r2[t3] === e4) return t3; } if (n2) return n2(e4); return null; }(e3); return i2 || function(e4, t3) { const { contextName: r3, contextVariables: n3, getEntity: i3, addVariable: s2, onUnrecognizedArgumentLookup: a2 } = t3; if (void 0 === e4) return "undefined"; if (null === e4) return "null"; const o = n3.indexOf(e4); if (o > -1) return `${r3}Variable${o}`; switch (e4.constructor.name) { case "String": const t4 = /\n/.test(e4), r4 = /'/.test(e4), n4 = /"/.test(e4); return t4 ? "`" + e4 + "`" : r4 && !n4 ? '"' + e4 + '"' : "'" + e4 + "'"; case "Number": case "Boolean": return i3(e4); case "Array": return s2(e4, `new ${e4.constructor.name}([${Array.from(e4).join(",")}])`); case "Float32Array": case "Uint8Array": case "Uint16Array": case "Int32Array": return s2(e4, `new ${e4.constructor.name}(${JSON.stringify(Array.from(e4))})`); default: if (a2) { const t5 = a2(e4); if (t5) return t5; } throw new Error(`unrecognized argument type ${e4.constructor.name}`); } }(e3, t2); }).join(", "); } function a(e2) { return new e2.constructor(e2); } void 0 !== t && (t.exports = { glWiretap: n, glExtensionWiretap: i }), "undefined" != typeof window && (n.glExtensionWiretap = i, window.glWiretap = n); }, {}], 4: [function(e, t, r) { function n(e2) { const t2 = new Array(e2.length); for (let r2 = 0; r2 < e2.length; r2++) { const n2 = e2[r2]; n2.toArray ? t2[r2] = n2.toArray() : t2[r2] = n2; } return t2; } function i() { const e2 = n(arguments), t2 = new Float32Array(this.output.x); for (let r2 = 0; r2 < this.output.x; r2++) this.thread.x = r2, this.thread.y = 0, this.thread.z = 0, t2[r2] = this._fn.apply(this, e2); return t2; } function s() { const e2 = n(arguments), t2 = new Array(this.output.y); for (let r2 = 0; r2 < this.output.y; r2++) { const n2 = new Float32Array(this.output.x); for (let t3 = 0; t3 < this.output.x; t3++) this.thread.x = t3, this.thread.y = r2, this.thread.z = 0, n2[t3] = this._fn.apply(this, e2); t2[r2] = n2; } return t2; } function a() { const e2 = n(arguments); for (let t2 = 0; t2 < this.output.y; t2++) for (let r2 = 0; r2 < this.output.x; r2++) this.thread.x = r2, this.thread.y = t2, this.thread.z = 0, this._fn.apply(this, e2); } function o() { const e2 = n(arguments), t2 = new Array(this.output.z); for (let r2 = 0; r2 < this.output.z; r2++) { const n2 = new Array(this.output.y); for (let t3 = 0; t3 < this.output.y; t3++) { const i2 = new Float32Array(this.output.x); for (let n3 = 0; n3 < this.output.x; n3++) this.thread.x = n3, this.thread.y = t3, this.thread.z = r2, i2[n3] = this._fn.apply(this, e2); n2[t3] = i2; } t2[r2] = n2; } return t2; } function u(e2) { e2.setOutput = (t3) => { e2.output = h(t3), e2.graphical && l(e2); }, e2.toJSON = () => { throw new Error("Not usable with gpuMock"); }, e2.setConstants = (t3) => (e2.constants = t3, e2), e2.setGraphical = (t3) => (e2.graphical = t3, e2), e2.setCanvas = (t3) => (e2.canvas = t3, e2), e2.setContext = (t3) => (e2.context = t3, e2), e2.destroy = () => { }, e2.validateSettings = () => { }, e2.graphical && e2.output && l(e2), e2.exec = function() { return new Promise((t3, r3) => { try { t3(e2.apply(e2, arguments)); } catch (e3) { r3(e3); } }); }, e2.getPixels = (t3) => { const { x: r3, y: n2 } = e2.output; return t3 ? function(e3, t4, r4) { const n3 = r4 / 2 | 0, i2 = 4 * t4, s2 = new Uint8ClampedArray(4 * t4), a2 = e3.slice(0); for (let e4 = 0; e4 < n3; ++e4) { const t5 = e4 * i2, n4 = (r4 - e4 - 1) * i2; s2.set(a2.subarray(t5, t5 + i2)), a2.copyWithin(t5, n4, n4 + i2), a2.set(s2, n4); } return a2; }(e2._imageData.data, r3, n2) : e2._imageData.data.slice(0); }, e2.color = function(t3, r3, n2, i2) { void 0 === i2 && (i2 = 1), t3 = Math.floor(255 * t3), r3 = Math.floor(255 * r3), n2 = Math.floor(255 * n2), i2 = Math.floor(255 * i2); const s2 = e2.output.x, a2 = e2.output.y, o2 = e2.thread.x + (a2 - e2.thread.y - 1) * s2; e2._colorData[4 * o2 + 0] = t3, e2._colorData[4 * o2 + 1] = r3, e2._colorData[4 * o2 + 2] = n2, e2._colorData[4 * o2 + 3] = i2; }; const t2 = () => e2, r2 = ["setWarnVarUsage", "setArgumentTypes", "setTactic", "setOptimizeFloatMemory", "setDebug", "setLoopMaxIterations", "setConstantTypes", "setFunctions", "setNativeFunctions", "setInjectedNative", "setPipeline", "setPrecision", "setOutputToTexture", "setImmutable", "setStrictIntegers", "setDynamicOutput", "setHardcodeConstants", "setDynamicArguments", "setUseLegacyEncoder", "setWarnVarUsage", "addSubKernel"]; for (let n2 = 0; n2 < r2.length; n2++) e2[r2[n2]] = t2; return e2; } function l(e2) { const { x: t2, y: r2 } = e2.output; if (e2.context && e2.context.createImageData) { const n2 = new Uint8ClampedArray(t2 * r2 * 4); e2._imageData = e2.context.createImageData(t2, r2), e2._colorData = n2; } else { const n2 = new Uint8ClampedArray(t2 * r2 * 4); e2._imageData = { data: n2 }, e2._colorData = n2; } } function h(e2) { let t2 = null; if (e2.length) if (3 === e2.length) { const [r2, n2, i2] = e2; t2 = { x: r2, y: n2, z: i2 }; } else if (2 === e2.length) { const [r2, n2] = e2; t2 = { x: r2, y: n2 }; } else { const [r2] = e2; t2 = { x: r2 }; } else t2 = e2; return t2; } t.exports = { gpuMock: function(e2, t2 = {}) { const r2 = t2.output ? h(t2.output) : null; function n2() { return n2.output.z ? o.apply(n2, arguments) : n2.output.y ? n2.graphical ? a.apply(n2, arguments) : s.apply(n2, arguments) : i.apply(n2, arguments); } return n2._fn = e2, n2.constants = t2.constants || null, n2.context = t2.context || null, n2.canvas = t2.canvas || null, n2.graphical = t2.graphical || false, n2._imageData = null, n2._colorData = null, n2.output = r2, n2.thread = { x: 0, y: 0, z: 0 }, u(n2); } }; }, {}], 5: [function(e, t, r) { const { utils: n } = e("./utils"); t.exports = { alias: function(e2, t2) { const r2 = t2.toString(); return new Function(`return function ${e2} (${n.getArgumentNamesFromString(r2).join(", ")}) { ${n.getFunctionBodyFromString(r2)} }`)(); } }; }, { "./utils": 114 }], 6: [function(e, t, r) { const { FunctionNode: n } = e("../function-node"); t.exports = { CPUFunctionNode: class extends n { astFunction(e2, t2) { if (!this.isRootKernel) { t2.push("function"), t2.push(" "), t2.push(this.name), t2.push("("); for (let e3 = 0; e3 < this.argumentNames.length; ++e3) { const r2 = this.argumentNames[e3]; e3 > 0 && t2.push(", "), t2.push("user_"), t2.push(r2); } t2.push(") {\n"); } for (let r2 = 0; r2 < e2.body.body.length; ++r2) this.astGeneric(e2.body.body[r2], t2), t2.push("\n"); return this.isRootKernel || t2.push("}\n"), t2; } astReturnStatement(e2, t2) { const r2 = this.returnType || this.getType(e2.argument); return this.returnType || (this.returnType = r2), this.isRootKernel ? (t2.push(this.leadingReturnStatement), this.astGeneric(e2.argument, t2), t2.push(";\n"), t2.push(this.followingReturnStatement), t2.push("continue;\n")) : this.isSubKernel ? (t2.push(`subKernelResult_${this.name} = `), this.astGeneric(e2.argument, t2), t2.push(";"), t2.push(`return subKernelResult_${this.name};`)) : (t2.push("return "), this.astGeneric(e2.argument, t2), t2.push(";")), t2; } astLiteral(e2, t2) { if (isNaN(e2.value)) throw this.astErrorOutput("Non-numeric literal not supported : " + e2.value, e2); return t2.push(e2.value), t2; } astBinaryExpression(e2, t2) { return t2.push("("), this.astGeneric(e2.left, t2), t2.push(e2.operator), this.astGeneric(e2.right, t2), t2.push(")"), t2; } astIdentifierExpression(e2, t2) { if ("Identifier" !== e2.type) throw this.astErrorOutput("IdentifierExpression - not an Identifier", e2); if ("Infinity" === e2.name) t2.push("Infinity"); else this.constants && this.constants.hasOwnProperty(e2.name) ? t2.push("constants_" + e2.name) : t2.push("user_" + e2.name); return t2; } astForStatement(e2, t2) { if ("ForStatement" !== e2.type) throw this.astErrorOutput("Invalid for statement", e2); const r2 = [], n2 = [], i = [], s = []; let a = null; if (e2.init) { this.pushState("in-for-loop-init"), this.astGeneric(e2.init, r2); for (let e3 = 0; e3 < r2.length; e3++) r2[e3].includes && r2[e3].includes(",") && (a = false); this.popState("in-for-loop-init"); } else a = false; if (e2.test ? this.astGeneric(e2.test, n2) : a = false, e2.update ? this.astGeneric(e2.update, i) : a = false, e2.body && (this.pushState("loop-body"), this.astGeneric(e2.body, s), this.popState("loop-body")), null === a && (a = this.isSafe(e2.init) && this.isSafe(e2.test)), a) t2.push(`for (${r2.join("")};${n2.join("")};${i.join("")}){ `), t2.push(s.join("")), t2.push("}\n"); else { const e3 = this.getInternalVariableName("safeI"); r2.length > 0 && t2.push(r2.join(""), ";\n"), t2.push(`for (let ${e3}=0;${e3}<LOOP_MAX;${e3}++){ `), n2.length > 0 && t2.push(`if (!${n2.join("")}) break; `), t2.push(s.join("")), t2.push(` ${i.join("")};`), t2.push("}\n"); } return t2; } astWhileStatement(e2, t2) { if ("WhileStatement" !== e2.type) throw this.astErrorOutput("Invalid while statement", e2); return t2.push("for (let i = 0; i < LOOP_MAX; i++) {"), t2.push("if ("), this.astGeneric(e2.test, t2), t2.push(") {\n"), this.astGeneric(e2.body, t2), t2.push("} else {\n"), t2.push("break;\n"), t2.push("}\n"), t2.push("}\n"), t2; } astDoWhileStatement(e2, t2) { if ("DoWhileStatement" !== e2.type) throw this.astErrorOutput("Invalid while statement", e2); return t2.push("for (let i = 0; i < LOOP_MAX; i++) {"), this.astGeneric(e2.body, t2), t2.push("if (!"), this.astGeneric(e2.test, t2), t2.push(") {\n"), t2.push("break;\n"), t2.push("}\n"), t2.push("}\n"), t2; } astAssignmentExpression(e2, t2) { const r2 = this.getDeclaration(e2.left); if (r2 && !r2.assignable) throw this.astErrorOutput(`Variable ${e2.left.name} is not assignable here`, e2); return this.astGeneric(e2.left, t2), t2.push(e2.operator), this.astGeneric(e2.right, t2), t2; } astBlockStatement(e2, t2) { if (this.isState("loop-body")) { this.pushState("block-body"); for (let r2 = 0; r2 < e2.body.length; r2++) this.astGeneric(e2.body[r2], t2); this.popState("block-body"); } else { t2.push("{\n"); for (let r2 = 0; r2 < e2.body.length; r2++) this.astGeneric(e2.body[r2], t2); t2.push("}\n"); } return t2; } astVariableDeclaration(e2, t2) { t2.push(`${e2.kind} `); const { declarations: r2 } = e2; for (let e3 = 0; e3 < r2.length; e3++) { e3 > 0 && t2.push(","); const n2 = r2[e3], i = this.getDeclaration(n2.id); i.valueType || (i.valueType = this.getType(n2.init)), this.astGeneric(n2, t2); } return this.isState("in-for-loop-init") || t2.push(";"), t2; } astIfStatement(e2, t2) { return t2.push("if ("), this.astGeneric(e2.test, t2), t2.push(")"), "BlockStatement" === e2.consequent.type ? this.astGeneric(e2.consequent, t2) : (t2.push(" {\n"), this.astGeneric(e2.consequent, t2), t2.push("\n}\n")), e2.alternate && (t2.push("else "), "BlockStatement" === e2.alternate.type || "IfStatement" === e2.alternate.type ? this.astGeneric(e2.alternate, t2) : (t2.push(" {\n"), this.astGeneric(e2.alternate, t2), t2.push("\n}\n"))), t2; } astSwitchStatement(e2, t2) { const { discriminant: r2, cases: n2 } = e2; t2.push("switch ("), this.astGeneric(r2, t2), t2.push(") {\n"); for (let e3 = 0; e3 < n2.length; e3++) null !== n2[e3].test ? (t2.push("case "), this.astGeneric(n2[e3].test, t2), t2.push(":\n"), n2[e3].consequent && n2[e3].consequent.length > 0 && (this.astGeneric(n2[e3].consequent, t2), t2.push("break;\n"))) : (t2.push("default:\n"), this.astGeneric(n2[e3].consequent, t2), n2[e3].consequent && n2[e3].consequent.length > 0 && t2.push("break;\n")); t2.push("\n}"); } astThisExpression(e2, t2) { return t2.push("_this"), t2; } astMemberExpression(e2, t2) { const { signature: r2, type: n2, property: i, xProperty: s, yProperty: a, zProperty: o, name: u, origin: l } = this.getMemberExpressionDetails(e2); switch (r2) { case "this.thread.value": return t2.push(`_this.thread.${u}`), t2; case "this.output.value": switch (u) { case "x": t2.push("outputX"); break; case "y": t2.push("outputY"); break; case "z": t2.push("outputZ"); break; default: throw this.astErrorOutput("Unexpected expression", e2); } return t2; case "value": default: throw this.astErrorOutput("Unexpected expression", e2); case "value[]": case "value[][]": case "value[][][]": case "value.value": if ("Math" === l) return t2.push(Math[u]), t2; switch (i) { case "r": return t2.push(`user_${u}[0]`), t2; case "g": return t2.push(`user_${u}[1]`), t2; case "b": return t2.push(`user_${u}[2]`), t2; case "a": return t2.push(`user_${u}[3]`), t2; } break; case "this.constants.value": case "this.constants.value[]": case "this.constants.value[][]": case "this.constants.value[][][]": break; case "fn()[]": return this.astGeneric(e2.object, t2), t2.push("["), this.astGeneric(e2.property, t2), t2.push("]"), t2; case "fn()[][]": return this.astGeneric(e2.object.object, t2), t2.push("["), this.astGeneric(e2.object.property, t2), t2.push("]"), t2.push("["), this.astGeneric(e2.property, t2), t2.push("]"), t2; } if (!e2.computed) switch (n2) { case "Number": case "Integer": case "Float": case "Boolean": return t2.push(`${l}_${u}`), t2; } const h = `${l}_${u}`; { let e3, r3; if ("constants" === l) { const t3 = this.constants[u]; r3 = "Input" === this.constantTypes[u], e3 = r3 ? t3.size : null; } else r3 = this.isInput(u), e3 = r3 ? this.argumentSizes[this.argumentNames.indexOf(u)] : null; t2.push(`${h}`), o && a ? r3 ? (t2.push("[("), this.astGeneric(o, t2), t2.push(`*${this.dynamicArguments ? "(outputY * outputX)" : e3[1] * e3[0]})+(`), this.astGeneric(a, t2), t2.push(`*${this.dynamicArguments ? "outputX" : e3[0]})+`), this.astGeneric(s, t2), t2.push("]")) : (t2.push("["), this.astGeneric(o, t2), t2.push("]"), t2.push("["), this.astGeneric(a, t2), t2.push("]"), t2.push("["), this.astGeneric(s, t2), t2.push("]")) : a ? r3 ? (t2.push("[("), this.astGeneric(a, t2), t2.push(`*${this.dynamicArguments ? "outputX" : e3[0]})+`), this.astGeneric(s, t2), t2.push("]")) : (t2.push("["), this.astGeneric(a, t2), t2.push("]"), t2.push("["), this.astGeneric(s, t2), t2.push("]")) : void 0 !== s && (t2.push("["), this.astGeneric(s, t2), t2.push("]")); } return t2; } astCallExpression(e2, t2) { if ("CallExpression" !== e2.type) throw this.astErrorOutput("Unknown CallExpression", e2); let r2 = this.astMemberExpressionUnroll(e2.callee); this.calledFunctions.indexOf(r2) < 0 && this.calledFunctions.push(r2); this.isAstMathFunction(e2); this.onFunctionCall && this.onFunctionCall(this.name, r2, e2.arguments), t2.push(r2), t2.push("("); const n2 = this.lookupFunctionArgumentTypes(r2) || []; for (let i = 0; i < e2.arguments.length; ++i) { const s = e2.arguments[i]; let a = this.getType(s); n2[i] || this.triggerImplyArgumentType(r2, i, a, this), i > 0 && t2.push(", "), this.astGeneric(s, t2); } return t2.push(")"), t2; } astArrayExpression(e2, t2) { const r2 = this.getType(e2), n2 = e2.elements.length, i = []; for (let t3 = 0; t3 < n2; ++t3) { const r3 = []; this.astGeneric(e2.elements[t3], r3), i.push(r3.join("")); } switch (r2) { case "Matrix(2)": case "Matrix(3)": case "Matrix(4)": t2.push(`[${i.join(", ")}]`); break; default: t2.push(`new Float32Array([${i.join(", ")}])`); } return t2; } astDebuggerStatement(e2, t2) { return t2.push("debugger;"), t2; } } }; }, { "../function-node": 10 }], 7: [function(e, t, r) { const { utils: n } = e("../../utils"); t.exports = { cpuKernelString: function(e2, t2) { const r2 = [], i = [], s = [], a = !/^function/.test(e2.color.toString()); if (r2.push(" const { context, canvas, constants: incomingConstants } = settings;", ` const output = new Int32Array(${JSON.stringify(Array.from(e2.output))});`, ` const _constantTypes = ${JSON.stringify(e2.constantTypes)};`, ` const _constants = ${function(e3, t3) { const r3 = []; for (const n2 in t3) { if (!t3.hasOwnProperty(n2)) continue; const i2 = t3[n2], s2 = e3[n2]; switch (i2) { case "Number": case "Integer": case "Float": case "Boolean": r3.push(`${n2}:${s2}`); break; case "Array(2)": case "Array(3)": case "Array(4)": case "Matrix(2)": case "Matrix(3)": case "Matrix(4)": r3.push(`${n2}:new ${s2.constructor.name}(${JSON.stringify(Array.from(s2))})`); } } return `{ ${r3.join()} }`; }(e2.constants, e2.constantTypes)};`), i.push(" constants: _constants,", " context,", " output,", " thread: {x: 0, y: 0, z: 0},"), e2.graphical) { r2.push(` const _imageData = context.createImageData(${e2.output[0]}, ${e2.output[1]});`), r2.push(` const _colorData = new Uint8ClampedArray(${e2.output[0]} * ${e2.output[1]} * 4);`); const t3 = n.flattenFunctionToString((a ? "function " : "") + e2.color.toString(), { thisLookup: (t4) => { switch (t4) { case "_colorData": return "_colorData"; case "_imageData": return "_imageData"; case "output": return "output"; case "thread": return "this.thread"; } return JSON.stringify(e2[t4]); }, findDependency: (e3, t4) => null }), o2 = n.flattenFunctionToString((a ? "function " : "") + e2.getPixels.toString(), { thisLookup: (t4) => { switch (t4) { case "_colorData": return "_colorData"; case "_imageData": return "_imageData"; case "output": return "output"; case "thread": return "this.thread"; } return JSON.stringify(e2[t4]); }, findDependency: () => null }); i.push(" _imageData,", " _colorData,", ` color: ${t3},`), s.push(` kernel.getPixels = ${o2};`); } const o = [], u = Object.keys(e2.constantTypes); for (let t3 = 0; t3 < u.length; t3++) o.push(e2.constantTypes[u]); if (-1 !== e2.argumentTypes.indexOf("HTMLImageArray") || -1 !== o.indexOf("HTMLImageArray")) { const t3 = n.flattenFunctionToString((a ? "function " : "") + e2._imageTo3DArray.toString(), { doNotDefine: ["canvas"], findDependency: (t4, r3) => "this" === t4 ? (a ? "function " : "") + e2[r3].toString() : null, thisLookup: (e3) => { switch (e3) { case "canvas": return; case "context": return "context"; } } }); s.push(t3), i.push(" _mediaTo2DArray,"), i.push(" _imageTo3DArray,"); } else if (-1 !== e2.argumentTypes.indexOf("HTMLImage") || -1 !== o.indexOf("HTMLImage")) { const t3 = n.flattenFunctionToString((a ? "function " : "") + e2._mediaTo2DArray.toString(), { findDependency: (e3, t4) => null, thisLookup: (e3) => { switch (e3) { case "canvas": return "settings.canvas"; case "context": return "settings.context"; } throw new Error("unhandled thisLookup"); } }); s.push(t3), i.push(" _mediaTo2DArray,"); } return `function(settings) { ${r2.join("\n")} for (const p in _constantTypes) { if (!_constantTypes.hasOwnProperty(p)) continue; const type = _constantTypes[p]; switch (type) { case 'Number': case 'Integer': case 'Float': case 'Boolean': case 'Array(2)': case 'Array(3)': case 'Array(4)': case 'Matrix(2)': case 'Matrix(3)': case 'Matrix(4)': if (incomingConstants.hasOwnProperty(p)) { console.warn('constant ' + p + ' of type ' + type + ' cannot be resigned'); } continue; } if (!incomingConstants.hasOwnProperty(p)) { throw new Error('constant ' + p + ' not found'); } _constants[p] = incomingConstants[p]; } const kernel = (function() { ${e2._kernelString} }) .apply({ ${i.join("\n")} }); ${s.join("\n")} return kernel; }`; } }; }, { "../../utils": 114 }], 8: [function(e, t, r) { const { Kernel: n } = e("../kernel"), { FunctionBuilder: i } = e("../function-builder"), { CPUFunctionNode: s } = e("./function-node"), { utils: a } = e("../../utils"), { cpuKernelString: o } = e("./kernel-string"); t.exports = { CPUKernel: class extends n { static getFeatures() { return this.features; } static get features() { return Object.freeze({ kernelMap: true, isIntegerDivisionAccurate: true }); } static get isSupported() { return true; } static isContextMatch(e2) { return false; } static get mode() { return "cpu"; } static nativeFunctionArguments() { return null; } static nativeFunctionReturnType() { throw new Error(`Looking up native function return type not supported on ${this.name}`); } static combineKernels(e2) { return e2; } static getSignature(e2, t2) { return "cpu" + (t2.length > 0 ? ":" + t2.join(",") : ""); } constructor(e2, t2) { super(e2, t2), this.mergeSettings(e2.settings || t2), this._imageData = null, this._colorData = null, this._kernelString = null, this._prependedString = [], this.thread = { x: 0, y: 0, z: 0 }, this.translatedSources = null; } initCanvas() { return "undefined" != typeof document ? document.createElement("canvas") : "undefined" != typeof OffscreenCanvas ? new OffscreenCanvas(0, 0) : void 0; } initContext() { return this.canvas ? this.canvas.getContext("2d") : null; } initPlugins(e2) { return []; } validateSettings(e2) { if (!this.output || 0 === this.output.length) { if (1 !== e2.length) throw new Error("Auto output only supported for kernels with only one input"); const t2 = a.getVariableType(e2[0], this.strictIntegers); if ("Array" === t2) this.output = a.getDimensions(t2); else { if ("NumberTexture" !== t2 && "ArrayTexture(4)" !== t2) throw new Error("Auto output not supported for input type: " + t2); this.output = e2[0].output; } } if (this.graphical && 2 !== this.output.length) throw new Error("Output must have 2 dimensions on graphical mode"); this.checkOutput(); } translateSource() { if (this.leadingReturnStatement = this.output.length > 1 ? "resultX[x] = " : "result[x] = ", this.subKernels) { const e3 = []; for (let t2 = 0; t2 < this.subKernels.length; t2++) { const { name: r2 } = this.subKernels[t2]; e3.push(this.output.length > 1 ? `resultX_${r2}[x] = subKernelResult_${r2}; ` : `result_${r2}[x] = subKernelResult_${r2}; `); } this.followingReturnStatement = e3.join(""); } const e2 = i.fromKernel(this, s); this.translatedSources = e2.getPrototypes("kernel"), this.graphical || this.returnType || (this.returnType = e2.getKernelResultType()); } build() { if (this.built) return; if (this.setupConstants(), this.setupArguments(arguments), this.validateSettings(arguments), this.translateSource(), this.graphical) { const { canvas: e3, output: t2 } = this; if (!e3) throw new Error("no canvas available for using graphical output"); const r2 = t2[0], n2 = t2[1] || 1; e3.width = r2, e3.height = n2, this._imageData = this.context.createImageData(r2, n2), this._colorData = new Uint8ClampedArray(r2 * n2 * 4); } const e2 = this.getKernelString(); this.kernelString = e2, this.debug && (console.log("Function output:"), console.log(e2)); try { this.run = new Function([], e2).bind(this)(); } catch (e3) { console.error("An error occurred compiling the javascript: ", e3); } this.buildSignature(arguments), this.built = true; } color(e2, t2, r2, n2) { void 0 === n2 && (n2 = 1), e2 = Math.floor(255 * e2), t2 = Math.floor(255 * t2), r2 = Math.floor(255 * r2), n2 = Math.floor(255 * n2); const i2 = this.output[0], s2 = this.output[1], a2 = this.thread.x + (s2 - this.thread.y - 1) * i2; this._colorData[4 * a2 + 0] = e2, this._colorData[4 * a2 + 1] = t2, this._colorData[4 * a2 + 2] = r2, this._colorData[4 * a2 + 3] = n2; } getKernelString() { if (null !== this._kernelString) return this._kernelString; let e2 = null, { translatedSources: t2 } = this; return t2.length > 1 ? t2 = t2.filter((t3) => /^function/.test(t3) ? t3 : (e2 = t3, false)) : e2 = t2.shift(), this._kernelString = ` const LOOP_MAX = ${this._getLoopMaxString()}; ${this.injectedNative || ""} const _this = this; ${this._resultKernelHeader()} ${this._processConstants()} return (${this.argumentNames.map((e3) => "user_" + e3).join(", ")}) => { ${this._prependedString.join("")} ${this._earlyThrows()} ${this._processArguments()} ${this.graphical ? this._graphicalKernelBody(e2) : this._resultKernelBody(e2)} ${t2.length > 0 ? t2.join("\n") : ""} };`; } toString() { return o(this); } _getLoopMaxString() { return this.loopMaxIterations ? ` ${parseInt(this.loopMaxIterations)};` : " 1000;"; } _processConstants() { if (!this.constants) return ""; const e2 = []; for (let t2 in this.constants) { switch (this.constantTypes[t2]) { case "HTMLCanvas": case "OffscreenCanvas": case "HTMLImage": case "ImageBitmap": case "ImageData": case "HTMLVideo": e2.push(` const constants_${t2} = this._mediaTo2DArray(this.constants.${t2}); `); break; case "HTMLImageArray": e2.push(` const constants_${t2} = this._imageTo3DArray(this.constants.${t2}); `); break; case "Input": e2.push(` const constants_${t2} = this.constants.${t2}.value; `); break; default: e2.push(` const constants_${t2} = this.constants.${t2}; `); } } return e2.join(""); } _earlyThrows() { if (this.graphical) return ""; if (this.immutable) return ""; if (!this.pipeline) return ""; const e2 = []; for (let t3 = 0; t3 < this.argumentTypes.length; t3++) "Array" === this.argumentTypes[t3] && e2.push(this.argumentNames[t3]); if (0 === e2.length) return ""; const t2 = []; for (let r2 = 0; r2 < e2.length; r2++) { const n2 = e2[r2], i2 = this._mapSubKernels((e3) => `user_${n2} === result_${e3.name}`).join(" || "); t2.push(`user_${n2} === result${i2 ? ` || ${i2}` : ""}`); } return `if (${t2.join(" || ")}) throw new Error('Source and destination arrays are the same. Use immutable = true');`; } _processArguments() { const e2 = []; for (let t2 = 0; t2 < this.argumentTypes.length; t2++) { const r2 = `user_${this.argumentNames[t2]}`; switch (this.argumentTypes[t2]) { case "HTMLCanvas": case "OffscreenCanvas": case "HTMLImage": case "ImageBitmap": case "ImageData": case "HTMLVideo": e2.push(` ${r2} = this._mediaTo2DArray(${r2}); `); break; case "HTMLImageArray": e2.push(` ${r2} = this._imageTo3DArray(${r2}); `); break; case "Input": e2.push(` ${r2} = ${r2}.value; `); break; case "ArrayTexture(1)": case "ArrayTexture(2)": case "ArrayTexture(3)": case "ArrayTexture(4)": case "NumberTexture": case "MemoryOptimizedNumberTexture": e2.push(` if (${r2}.toArray) { if (!_this.textureCache) { _this.textureCache = []; _this.arrayCache = []; } const textureIndex = _this.textureCache.indexOf(${r2}); if (textureIndex !== -1) { ${r2} = _this.arrayCache[textureIndex]; } else { _this.textureCache.push(${r2}); ${r2} = ${r2}.toArray(); _this.arrayCache.push(${r2}); } }`); } } return e2.join(""); } _mediaTo2DArray(e2) { const t2 = this.canvas, r2 = e2.width > 0 ? e2.width : e2.videoWidth, n2 = e2.height > 0 ? e2.height : e2.videoHeight; t2.width < r2 && (t2.width = r2), t2.height < n2 && (t2.height = n2); const i2 = this.context; let s2; e2.constructor === ImageData ? s2 = e2.data : (i2.drawImage(e2, 0, 0, r2, n2), s2 = i2.getImageData(0, 0, r2, n2).data); const a2 = new Array(n2); let o2 = 0; for (let e3 = n2 - 1; e3 >= 0; e3--) { const t3 = a2[e3] = new Array(r2); for (let e4 = 0; e4 < r2; e4++) { const r3 = new Float32Array(4); r3[0] = s2[o2++] / 255, r3[1] = s2[o2++] / 255, r3[2] = s2[o2++] / 255, r3[3] = s2[o2++] / 255, t3[e4] = r3; } } return a2; } getPixels(e2) { const [t2, r2] = this.output; return e2 ? a.flipPixels(this._imageData.data, t2, r2) : this._imageData.data.slice(0); } _imageTo3DArray(e2) { const t2 = new Array(e2.length); for (let r2 = 0; r2 < e2.length; r2++) t2[r2] = this._mediaTo2DArray(e2[r2]); return t2; } _resultKernelHeader() { if (this.graphical) return ""; if (this.immutable) return ""; if (!this.pipeline) return ""; switch (this.output.length) { case 1: return this._mutableKernel1DResults(); case 2: return this._mutableKernel2DResults(); case 3: return this._mutableKernel3DResults(); } } _resultKernelBody(e2) { switch (this.output.length) { case 1: return (!this.immutable && this.pipeline ? this._resultMutableKernel1DLoop(e2) : this._resultImmutableKernel1DLoop(e2)) + this._kernelOutput(); case 2: return (!this.immutable && this.pipeline ? this._resultMutableKernel2DLoop(e2) : this._resultImmutableKernel2DLoop(e2)) + this._kernelOutput(); case 3: return (!this.immutable && this.pipeline ? this._resultMutableKernel3DLoop(e2) : this._resultImmutableKernel3DLoop(e2)) + this._kernelOutput(); default: throw new Error("unsupported size kernel"); } } _graphicalKernelBody(e2) { if (2 === this.output.length) return this._graphicalKernel2DLoop(e2) + this._graphicalOutput(); throw new Error("unsupported size kernel"); } _graphicalOutput() { return "\n this._imageData.data.set(this._colorData);\n this.context.putImageData(this._imageData, 0, 0);\n return;"; } _getKernelResultTypeConstructorString() { switch (this.returnType) { case "LiteralInteger": case "Number": case "Integer": case "Float": return "Float32Array"; case "Array(2)": case "Array(3)": case "Array(4)": return "Array"; default: if (this.graphical) return "Float32Array"; throw new Error(`unhandled returnType ${this.returnType}`); } } _resultImmutableKernel1DLoop(e2) { const t2 = this._getKernelResultTypeConstructorString(); return ` const outputX = _this.output[0]; const result = new ${t2}(outputX); ${this._mapSubKernels((e3) => `const result_${e3.name} = new ${t2}(outputX); `).join(" ")} ${this._mapSubKernels((e3) => `let subKernelResult_${e3.name}; `).join(" ")} for (let x = 0; x < outputX; x++) { this.thread.x = x; this.thread.y = 0; this.thread.z = 0; ${e2} }`; } _mutableKernel1DResults() { const e2 = this._getKernelResultTypeConstructorString(); return ` const outputX = _this.output[0]; const result = new ${e2}(outputX); ${this._mapSubKernels((t2) => `const result_${t2.name} = new ${e2}(outputX); `).join(" ")} ${this._mapSubKernels((e3) => `let subKernelResult_${e3.name}; `).join(" ")}`; } _resultMutableKernel1DLoop(e2) { return ` const outputX = _this.output[0]; for (let x = 0; x < outputX; x++) { this.thread.x = x; this.thread.y = 0; this.thread.z = 0; ${e2} }`; } _resultImmutableKernel2DLoop(e2) { const t2 = this._getKernelResultTypeConstructorString(); return ` const outputX = _this.output[0]; const outputY = _this.output[1]; const result = new Array(outputY); ${this._mapSubKernels((e3) => `const result_${e3.name} = new Array(outputY); `).join(" ")} ${this._mapSubKernels((e3) => `let subKernelResult_${e3.name}; `).join(" ")} for (let y = 0; y < outputY; y++) { this.thread.z = 0; this.thread.y = y; const resultX = result[y] = new ${t2}(outputX); ${this._mapSubKernels((e3) => `const resultX_${e3.name} = result_${e3.name}[y] = new ${t2}(outputX); `).join("")} for (let x = 0; x < outputX; x++) { this.thread.x = x; ${e2} } }`; } _mutableKernel2DResults() { const e2 = this._getKernelResultTypeConstructorString(); return ` const outputX = _this.output[0]; const outputY = _this.output[1]; const result = new Array(outputY); ${this._mapSubKernels((e3) => `const result_${e3.name} = new Array(outputY); `).join(" ")} ${this._mapSubKernels((e3) => `let subKernelResult_${e3.name}; `).join(" ")} for (let y = 0; y < outputY; y++) { const resultX = result[y] = new ${e2}(outputX); ${this._mapSubKernels((t2) => `const resultX_${t2.name} = result_${t2.name}[y] = new ${e2}(outputX); `).join("")} }`; } _resultMutableKernel2DLoop(e2) { const t2 = this._getKernelResultTypeConstructorString(); return ` const outputX = _this.output[0]; const outputY = _this.output[1]; for (let y = 0; y < outputY; y++) { this.thread.z = 0; this.thread.y = y; const resultX = result[y]; ${this._mapSubKernels((e3) => `const resultX_${e3.name} = result_${e3.name}[y] = new ${t2}(outputX); `).join("")} for (let x = 0; x < outputX; x++) { this.thread.x = x; ${e2} } }`; } _graphicalKernel2DLoop(e2) { return ` const outputX = _this.output[0]; const outputY = _this.output[1]; for (let y = 0; y < outputY; y++) { this.thread.z = 0; this.thread.y = y; for (let x = 0; x < outputX; x++) { this.thread.x = x; ${e2} } }`; } _resultImmutableKernel3DLoop(e2) { const t2 = this._getKernelResultTypeConstructorString(); return ` const outputX = _this.output[0]; const outputY = _this.output[1]; const outputZ = _this.output[2]; const result = new Array(outputZ); ${this._mapSubKernels((e3) => `const result_${e3.name} = new Array(outputZ); `).join(" ")} ${this._mapSubKernels((e3) => `let subKernelResult_${e3.name}; `).join(" ")} for (let z = 0; z < outputZ; z++) { this.thread.z = z; const resultY = result[z] = new Array(outputY); ${this._mapSubKernels((e3) => `const resultY_${e3.name} = result_${e3.name}[z] = new Array(outputY); `).join(" ")} for (let y = 0; y < outputY; y++) { this.thread.y = y; const resultX = resultY[y] = new ${t2}(outputX); ${this._mapSubKernels((e3) => `const resultX_${e3.name} = resultY_${e3.name}[y] = new ${t2}(outputX); `).join(" ")} for (let x = 0; x < outputX; x++) { this.thread.x = x; ${e2} } } }`; } _mutableKernel3DResults() { const e2 = this._getKernelResultTypeConstructorString(); return ` const outputX = _this.output[0]; const outputY = _this.output[1]; const outputZ = _this.output[2]; const result = new Array(outputZ); ${this._mapSubKernels((e3) => `const result_${e3.name} = new Array(outputZ); `).join(" ")} ${this._mapSubKernels((e3) => `let subKernelResult_${e3.name}; `).join(" ")} for (let z = 0; z < outputZ; z++) { const resultY = result[z] = new Array(outputY); ${this._mapSubKernels((e3) => `const resultY_${e3.name} = result_${e3.name}[z] = new Array(outputY); `).join(" ")} for (let y = 0; y < outputY; y++) { const resultX = resultY[y] = new ${e2}(outputX); ${this._mapSubKernels((t2) => `const resultX_${t2.name} = resultY_${t2.name}[y] = new ${e2}(outputX); `).join(" ")} } }`; } _resultMutableKernel3DLoop(e2) { return ` const outputX = _this.output[0]; const outputY = _this.output[1]; const outputZ = _this.output[2]; for (let z = 0; z < outputZ; z++) { this.thread.z = z; const resultY = result[z]; for (let y = 0; y < outputY; y++) { this.thread.y = y; const resultX = resultY[y]; for (let x = 0; x < outputX; x++) { this.thread.x = x; ${e2} } } }`; } _kernelOutput() { return this.subKernels ? ` return { result: result, ${this.subKernels.map((e2) => `${e2.property}: result_${e2.name}`).join(",\n ")} };` : "\n return result;"; } _mapSubKernels(e2) { return null === this.subKernels ? [""] : this.subKernels.map(e2); } destroy(e2) { e2 && delete this.canvas; } static destroyContext(e2) { } toJSON() { const e2 = super.toJSON(); return e2.functionNodes = i.fromKernel(this, s).toJSON(), e2; } setOutput(e2) { super.setOutput(e2); const [t2, r2] = this.output; this.graphical && (this._imageData = this.context.createImageData(t2, r2), this._colorData = new Uint8ClampedArray(t2 * r2 * 4)); } prependString(e2) { if (this._kernelString) throw new Error("Kernel already built"); this._prependedString.push(e2); } hasPrependString(e2) { return this._prependedString.indexOf(e2) > -1; } } }; }, { "../../utils": 114, "../function-builder": 9, "../kernel": 36, "./function-node": 6, "./kernel-string": 7 }], 9: [function(e, t, r) { class n { static fromKernel(e2, t2, r2) { const { kernelArguments: i, kernelConstants: s, argumentNames: a, argumentSizes: o, argumentBitRatios: u, constants: l, constantBitRatios: h, debug: c, loopMaxIterations: p, nativeFunctions: d, output: m, optimizeFloatMemory: f, precision: g, plugins: x, source: y, subKernels: b, functions: T, leadingReturnStatement: v, followingReturnStatement: S, dynamicArguments: A, dynamicOutput: _ } = e2, E = new Array(i.length), w = {}; for (let e3 = 0; e3 < i.length; e3++) E[e3] = i[e3].type; for (let e3 = 0; e3 < s.length; e3++) { const t3 = s[e3]; w[t3.name] = t3.type; } const k = (e3, t3) => G.needsArgumentType(e3, t3), I = (e3, t3, r3) => { G.assignArgumentType(e3, t3, r3); }, D = (e3, t3, r3) => G.lookupReturnType(e3, t3, r3), C = (e3) => G.lookupFunctionArgumentTypes(e3), $ = (e3, t3) => G.lookupFunctionArgumentName(e3, t3), L = (e3, t3) => G.lookupFunctionArgumentBitRatio(e3, t3), R = (e3, t3, r3, n2) => { G.assignArgumentType(e3, t3, r3, n2); }, F = (e3, t3, r3, n2) => { G.assignArgumentBitRatio(e3, t3, r3, n2); }, N = (e3, t3, r3) => { G.trackFunctionCall(e3, t3, r3); }, V = (e3, r3) => { const n2 = []; for (let t3 = 0; t3 < e3.params.length; t3++) n2.push(e3.params[t3].name); const i2 = new t2(r3, Object.assign({}, M, { returnType: null, ast: e3, name: e3.id.name, argumentNames: n2, lookupReturnType: D, lookupFunctionArgumentTypes: C, lookupFunctionArgumentName: $, lookupFunctionArgumentBitRatio: L, needsArgumentType: k, assignArgumentType: I, triggerImplyArgumentType: R, triggerImplyArgumentBitRatio: F, onFunctionCall: N })); i2.traceFunctionAST(e3), G.addFunctionNode(i2); }, M = Object.assign({ isRootKernel: false, onNestedFunction: V, lookupReturnType: D, lookupFunctionArgumentTypes: C, lookupFunctionArgumentName: $, lookupFunctionArgumentBitRatio: L, needsArgumentType: k, assignArgumentType: I, triggerImplyArgumentType: R, triggerImplyArgumentBitRatio: F, onFunctionCall: N, optimizeFloatMemory: f, precision: g, constants: l, constantTypes: w, constantBitRatios: h, debug: c, loopMaxIterations: p, output: m, plugins: x, dynamicArguments: A, dynamicOutput: _ }, r2 || {}), O = Object.assign({}, M, { isRootKernel: true, name: "kernel", argumentNames: a, argumentTypes: E, argumentSizes: o, argumentBitRatios: u, leadingReturnStatement: v, followingReturnStatement: S }); if ("object" == typeof y && y.functionNodes) return new n().fromJSON(y.functionNodes, t2); const z = new t2(y, O); let P = null; T && (P = T.map((e3) => new t2(e3.source, { returnType: e3.returnType, argumentTypes: e3.argumentTypes, output: m, plugins: x, constants: l, constantTypes: w, constantBitRatios: h, optimizeFloatMemory: f, precision: g, lookupReturnType: D, lookupFunctionArgumentTypes: C, lookupFunctionArgumentName: $, lookupFunctionArgumentBitRatio: L, needsArgumentType: k, assignArgumentType: I, triggerImplyArgumentType: R, triggerImplyArgumentBitRatio: F, onFunctionCall: N, onNestedFunction: V }))); let K = null; b && (K = b.map((e3) => { const { name: r3, source: n2 } = e3; return new t2(n2, Object.assign({}, M, { name: r3, isSubKernel: true, isRootKernel: false })); })); const G = new n({ kernel: e2, rootNode: z, functionNodes: P, nativeFunctions: d, subKernelNodes: K }); return G; } constructor(e2) { if (e2 = e2 || {}, this.kernel = e2.kernel, this.rootNode = e2.rootNode, this.functionNodes = e2.functionNodes || [], this.subKernelNodes = e2.subKernelNodes || [], this.nativeFunctions = e2.nativeFunctions || [], this.functionMap = {}, this.nativeFunctionNames = [], this.lookupChain = [], this.functionNodeDependencies = {}, this.functionCalls = {}, this.rootNode && (this.functionMap.kernel = this.rootNode), this.functionNodes) for (let e3 = 0; e3 < this.functionNodes.length; e3++) this.functionMap[this.functionNodes[e3].name] = this.functionNodes[e3]; if (this.subKernelNodes) for (let e3 = 0; e3 < this.subKernelNodes.length; e3++) this.functionMap[this.subKernelNodes[e3].name] = this.subKernelNodes[e3]; if (this.nativeFunctions) for (let e3 = 0; e3 < this.nativeFunctions.length; e3++) { const t2 = this.nativeFunctions[e3]; this.nativeFunctionNames.push(t2.name); } } addFunctionNode(e2) { if (!e2.name) throw new Error("functionNode.name needs set"); this.functionMap[e2.name] = e2, e2.isRootKernel && (this.rootNode = e2); } traceFunctionCalls(e2, t2) { if (e2 = e2 || "kernel", t2 = t2 || [], this.nativeFunctionNames.indexOf(e2) > -1) { const r3 = t2.indexOf(e2); if (-1 === r3) t2.push(e2); else { const e3 = t2.splice(r3, 1)[0]; t2.push(e3); } return t2; } const r2 = this.functionMap[e2]; if (r2) { const n2 = t2.indexOf(e2); if (-1 === n2) { t2.push(e2), r2.toString(); for (let e3 = 0; e3 < r2.calledFunctions.length; ++e3) this.traceFunctionCalls(r2.calledFunctions[e3], t2); } else { const e3 = t2.splice(n2, 1)[0]; t2.push(e3); } } return t2; } getPrototypeString(e2) { return this.getPrototypes(e2).join("\n"); } getPrototypes(e2) { return this.rootNode && this.rootNode.toString(), e2 ? this.getPrototypesFromFunctionNames(this.traceFunctionCalls(e2, []).reverse()) : this.getPrototypesFromFunctionNames(Object.keys(this.functionMap)); } getStringFromFunctionNames(e2) { const t2 = []; for (let r2 = 0; r2 < e2.length; ++r2) { this.functionMap[e2[r2]] && t2.push(this.functionMap[e2[r2]].toString()); } return t2.join("\n"); } getPrototypesFromFunctionNames(e2) { const t2 = []; for (let r2 = 0; r2 < e2.length; ++r2) { const n2 = e2[r2], i = this.nativeFunctionNames.indexOf(n2); if (i > -1) { t2.push(this.nativeFunctions[i].source); continue; } const s = this.functionMap[n2]; s && t2.push(s.toString()); } return t2; } toJSON() { return this.traceFunctionCalls(this.rootNode.name).reverse().map((e2) => { const t2 = this.nativeFunctions.indexOf(e2); if (t2 > -1) return { name: e2, source: this.nativeFunctions[t2].source }; if (this.functionMap[e2]) return this.functionMap[e2].toJSON(); throw new Error(`function ${e2} not found`); }); } fromJSON(e2, t2) { this.functionMap = {}; for (let r2 = 0; r2 < e2.length; r2++) { const n2 = e2[r2]; this.functionMap[n2.settings.name] = new t2(n2.ast, n2.settings); } return this; } getString(e2) { return e2 ? this.getStringFromFunctionNames(this.traceFunctionCalls(e2).reverse()) : this.getStringFromFunctionNames(Object.keys(this.functionMap)); } lookupReturnType(e2, t2, r2) { if ("CallExpression" !== t2.type) throw new Error(`expected ast type of "CallExpression", but is ${t2.type}`); if (this._isNativeFunction(e2)) return this._lookupNativeFunctionReturnType(e2); if (this._isFunction(e2)) { const n2 = this._getFunction(e2); if (n2.returnType) return n2.returnType; { for (let e4 = 0; e4 < this.lookupChain.length; e4++) if (this.lookupChain[e4].ast === t2) { if (0 === n2.argumentTypes.length && t2.arguments.length > 0) { const i = t2.arguments; for (let t3 = 0; t3 < i.length; t3++) this.lookupChain.push({ name: r2.name, ast: i[e4], requestingNode: r2 }), n2.argumentTypes[t3] = r2.getType(i[t3]), this.lookupChain.pop(); return n2.returnType = n2.getType(n2.getJsAST()); } throw new Error("circlical logic detected!"); } this.lookupChain.push({ name: r2.name, ast: t2, requestingNode: r2 }); const e3 = n2.getType(n2.getJsAST()); return this.lookupChain.pop(), n2.returnType = e3; } } return null; } _getFunction(e2) { return this._isFunction(e2) || new Error(`Function ${e2} not found`), this.functionMap[e2]; } _isFunction(e2) { return Boolean(this.functionMap[e2]); } _getNativeFunction(e2) { for (let t2 = 0; t2 < this.nativeFunctions.length; t2++) if (this.nativeFunctions[t2].name === e2) return this.nativeFunctions[t2]; return null; } _isNativeFunction(e2) { return Boolean(this._getNativeFunction(e2)); } _lookupNativeFunctionReturnType(e2) { let t2 = this._getNativeFunction(e2); if (t2) return t2.returnType; throw new Error(`Native function ${e2} not found`); } lookupFunctionArgumentTypes(e2) { return this._isNativeFunction(e2) ? this._getNativeFunction(e2).argumentTypes : this._isFunction(e2) ? this._getFunction(e2).argumentTypes : null; } lookupFunctionArgumentName(e2, t2) { return this._getFunction(e2).argumentNames[t2]; } lookupFunctionArgumentBitRatio(e2, t2) { if (!this._isFunction(e2)) throw new Error("function not found"); if (this.rootNode.name === e2) { const e3 = this.rootNode.argumentNames.indexOf(t2); if (-1 !== e3) return this.rootNode.argumentBitRatios[e3]; } const r2 = this._getFunction(e2), n2 = r2.argumentNames.indexOf(t2); if (-1 === n2) throw new Error("argument not found"); const i = r2.argumentBitRatios[n2]; if ("number" != typeof i) throw new Error("argument bit ratio not found"); return i; } needsArgumentType(e2, t2) { if (!this._isFunction(e2)) return false; return !this._getFunction(e2).argumentTypes[t2]; } assignArgumentType(e2, t2, r2, n2) { if (!this._isFunction(e2)) return; const i = this._getFunction(e2); i.argumentTypes[t2] || (i.argumentTypes[t2] = r2); } assignArgumentBitRatio(e2, t2, r2, n2) { const i = this._getFunction(e2); if (this._isNativeFunction(r2)) return null; const s = this._getFunction(r2), a = i.argumentNames.indexOf(t2); if (-1 === a) throw new Error(`Argument ${t2} not found in arguments from function ${e2}`); const o = i.argumentBitRatios[a]; if ("number" != typeof o) throw new Error(`Bit ratio for argument ${t2} not found in function ${e2}`); s.argumentBitRatios || (s.argumentBitRatios = new Array(s.argumentNames.length)); const u = s.argumentBitRatios[a]; if ("number" == typeof u) { if (u !== o) throw new Error(`Incompatible bit ratio found at function ${e2} at argument ${t2}`); return u; } return s.argumentBitRatios[a] = o, o; } trackFunctionCall(e2, t2, r2) { this.functionNodeDependencies[e2] || (this.functionNodeDependencies[e2] = /* @__PURE__ */ new Set(), this.functionCalls[e2] = []), this.functionNodeDependencies[e2].add(t2), this.functionCalls[e2].push(r2); } getKernelResultType() { return this.rootNode.returnType || this.rootNode.getType(this.rootNode.ast); } getSubKernelResultType(e2) { const t2 = this.subKernelNodes[e2]; let r2 = false; for (let e3 = 0; e3 < this.rootNode.functionCalls.length; e3++) { this.rootNode.functionCalls[e3].ast.callee.name === t2.name && (r2 = true); } if (!r2) throw new Error(`SubKernel ${t2.name} never called by kernel`); return t2.returnType || t2.getType(t2.getJsAST()); } getReturnTypes() { const e2 = { [this.rootNode.name]: this.rootNode.getType(this.rootNode.ast) }, t2 = this.traceFunctionCalls(this.rootNode.name); for (let r2 = 0; r2 < t2.length; r2++) { const n2 = t2[r2], i = this.functionMap[n2]; e2[n2] = i.getType(i.ast); } return e2; } } t.exports = { FunctionBuilder: n }; }, {}], 10: [function(e, t, r) { const n = e("acorn"), { utils: i } = e("../utils"), { FunctionTracer: s } = e("./function-tracer"); const a = { Number: "Number", Float: "Float", Integer: "Integer", Array: "Number", "Array(2)": "Number", "Array(3)": "Number", "Array(4)": "Number", "Matrix(2)": "Number", "Matrix(3)": "Number", "Matrix(4)": "Number", Array2D: "Number", Array3D: "Number", Input: "Number", HTMLCanvas: "Array(4)", OffscreenCanvas: "Array(4)", HTMLImage: "Array(4)", ImageBitmap: "Array(4)", ImageData: "Array(4)", HTMLVideo: "Array(4)", HTMLImageArray: "Array(4)", NumberTexture: "Number", MemoryOptimizedNumberTexture: "Number", "Array1D(2)": "Array(2)", "Array1D(3)": "Array(3)", "Array1D(4)": "Array(4)", "Array2D(2)": "Array(2)", "Array2D(3)": "Array(3)", "Array2D(4)": "Array(4)", "Array3D(2)": "Array(2)", "Array3D(3)": "Array(3)", "Array3D(4)": "Array(4)", "ArrayTexture(1)": "Number", "ArrayTexture(2)": "Array(2)", "ArrayTexture(3)": "Array(3)", "ArrayTexture(4)": "Array(4)" }; t.exports = { FunctionNode: class { constructor(e2, t2) { if (!e2 && !t2.ast) throw new Error("source parameter is missing"); if (t2 = t2 || {}, this.source = e2, this.ast = null, this.name = "string" == typeof e2 ? t2.isRootKernel ? "kernel" : t2.name || i.getFunctionNameFromString(e2) : null, this.calledFunctions = [], this.constants = {}, this.constantTypes = {}, this.constantBitRatios = {}, this.isRootKernel = false, this.isSubKernel = false, this.debug = null, this.functions = null, this.identifiers = null, this.contexts = null, this.functionCalls = null, this.states = [], this.needsArgumentType = null, this.assignArgumentType = null, this.lookupReturnType = null, this.lookupFunctionArgumentTypes = null, this.lookupFunctionArgumentBitRatio = null, this.triggerImplyArgumentType = null, this.triggerImplyArgumentBitRatio = null, this.onNestedFunction = null, this.onFunctionCall = null, this.optimizeFloatMemory = null, this.precision = null, this.loopMaxIterations = null, this.argumentNames = "string" == typeof this.source ? i.getArgumentNamesFromString(this.source) : null, this.argumentTypes = [], this.argumentSizes = [], this.argumentBitRatios = null, this.returnType = null, this.output = [], this.plugins = null, this.leadingReturnStatement = null, this.followingReturnStatement = null, this.dynamicOutput = null, this.dynamicArguments = null, this.strictTypingChecking = false, this.fixIntegerDivisionAccuracy = null, t2) for (const e3 in t2) t2.hasOwnProperty(e3) && this.hasOwnProperty(e3) && (this[e3] = t2[e3]); this.literalTypes = {}, this.validate(), this._string = null, this._internalVariableNames = {}; } validate() { if ("string" != typeof this.source && !this.ast) throw new Error("this.source not a string"); if (!this.ast && !i.isFunctionString(this.source)) throw new Error("this.source not a function string"); if (!this.name) throw new Error("this.name could not be set"); if (this.argumentTypes.length > 0 && this.argumentTypes.length !== this.argumentNames.length) throw new Error(`argumentTypes count of ${this.argumentTypes.length} exceeds ${this.argumentNames.length}`); if (this.output.length < 1) throw new Error("this.output is not big enough"); } isIdentifierConstant(e2) { return !!this.constants && this.constants.hasOwnProperty(e2); } isInput(e2) { return "Input" === this.argumentTypes[this.argumentNames.indexOf(e2)]; } pushState(e2) { this.states.push(e2); } popState(e2) { if (this.state !== e2) throw new Error(`Cannot popState ${e2} when in ${this.state}`); this.states.pop(); } isState(e2) { return this.state === e2; } get state() { return this.states[this.states.length - 1]; } astMemberExpressionUnroll(e2) { if ("Identifier" === e2.type) return e2.name; if ("ThisExpression" === e2.type) return "this"; if ("MemberExpression" === e2.type && e2.object && e2.property) return e2.object.hasOwnProperty("name") && "Math" !== e2.object.name ? this.astMemberExpressionUnroll(e2.property) : this.astMemberExpressionUnroll(e2.object) + "." + this.astMemberExpressionUnroll(e2.property); if (e2.hasOwnProperty("expressions")) { const t2 = e2.expressions[0]; if ("Literal" === t2.type && 0 === t2.value && 2 === e2.expressions.length) return this.astMemberExpressionUnroll(e2.expressions[1]); } throw this.astErrorOutput("Unknown astMemberExpressionUnroll", e2); } getJsAST(e2) { if (this.ast) return this.ast; if ("object" == typeof this.source) return this.traceFunctionAST(this.source), this.ast = this.source; if (null === (e2 = e2 || n)) throw new Error("Missing JS to AST parser"); const t2 = Object.freeze(e2.parse(`const parser_${this.name} = ${this.source};`, { locations: true })), r2 = t2.body[0].declarations[0].init; if (this.traceFunctionAST(r2), !t2) throw new Error("Failed to parse JS code"); return this.ast = r2; } traceFunctionAST(e2) { const { contexts: t2, declarations: r2, functions: n2, identifiers: i2, functionCalls: a2 } = new s(e2); this.contexts = t2, this.identifiers = i2, this.functionCalls = a2, this.functions = n2; for (let e3 = 0; e3 < r2.length; e3++) { const t3 = r2[e3], { ast: n3, inForLoopInit: i3, inForLoopTest: s2 } = t3, { init: a3 } = n3, o = this.getDependencies(a3); let u = null; if (i3 && s2) u = "Integer"; else if (a3) { const e4 = this.getType(a3); switch (e4) { case "Integer": case "Float": case "Number": u = "MemberExpression" === a3.type ? e4 : "Number"; break; case "LiteralInteger": u = "Number"; break; default: u = e4; } } t3.valueType = u, t3.dependencies = o, t3.isSafe = this.isSafeDependencies(o); } for (let e3 = 0; e3 < n2.length; e3++) this.onNestedFunction(n2[e3], this.source); } getDeclaration(e2) { for (let t2 = 0; t2 < this.identifiers.length; t2++) { const r2 = this.identifiers[t2]; if (e2 === r2.ast) return r2.declaration; } return null; } getVariableType(e2) { if ("Identifier" !== e2.type) throw new Error(`ast of ${e2.type} not "Identifier"`); let t2 = null; const r2 = this.argumentNames.indexOf(e2.name); if (-1 === r2) { const t3 = this.getDeclaration(e2); if (t3) return t3.valueType; } else { const e3 = this.argumentTypes[r2]; e3 && (t2 = e3); } if (!t2 && this.strictTypingChecking) throw new Error(`Declaration of ${name} not found`); return t2; } getLookupType(e2) { if (!a.hasOwnProperty(e2)) throw new Error(`unknown typeLookupMap ${e2}`); return a[e2]; } getConstantType(e2) { if (this.constantTypes[e2]) { const t2 = this.constantTypes[e2]; return "Float" === t2 ? "Number" : t2; } throw new Error(`Type for constant "${e2}" not declared`); } toString() { return this._string ? this._string : this._string = this.astGeneric(this.getJsAST(), []).join("").trim(); } toJSON() { const e2 = { source: this.source, name: this.name, constants: this.constants, constantTypes: this.constantTypes, isRootKernel: this.isRootKernel, isSubKernel: this.isSubKernel, debug: this.debug, output: this.output, loopMaxIterations: this.loopMaxIterations, argumentNames: this.argumentNames, argumentTypes: this.argumentTypes, argumentSizes: this.argumentSizes, returnType: this.returnType, leadingReturnStatement: this.leadingReturnStatement, followingReturnStatement: this.followingReturnStatement }; return { ast: this.ast, settings: e2 }; } getType(e2) { if (Array.isArray(e2)) return this.getType(e2[e2.length - 1]); switch (e2.type) { case "BlockStatement": return this.getType(e2.body); case "ArrayExpression": switch (this.getType(e2.elements[0])) { case "Array(2)": case "Array(3)": case "Array(4)": return `Matrix(${e2.elements.length})`; } return `Array(${e2.elements.length})`; case "Literal": const t2 = this.astKey(e2); return this.literalTypes[t2] ? this.literalTypes[t2] : Number.isInteger(e2.value) ? "LiteralInteger" : true === e2.value || false === e2.value ? "Boolean" : "Number"; case "AssignmentExpression": return this.getType(e2.left); case "CallExpression": if (this.isAstMathFunction(e2)) return "Number"; if (!e2.callee || !e2.callee.name) { if ("SequenceExpression" === e2.callee.type && e2.callee.expressions[e2.callee.expressions.length - 1].property.name) { const t3 = e2.callee.expressions[e2.callee.expressions.length - 1].property.name; return this.inferArgumentTypesIfNeeded(t3, e2.arguments), this.lookupReturnType(t3, e2, this); } if ("this.color" === this.getVariableSignature(e2.callee, true)) return null; if ("MemberExpression" === e2.callee.type && e2.callee.object && e2.callee.property && e2.callee.property.name && e2.arguments) { const t3 = e2.callee.property.name; return this.inferArgumentTypesIfNeeded(t3, e2.arguments), this.lookupReturnType(t3, e2, this); } throw this.astErrorOutput("Unknown call expression", e2); } if (e2.callee && e2.callee.name) { const t3 = e2.callee.name; return this.inferArgumentTypesIfNeeded(t3, e2.arguments), this.lookupReturnType(t3, e2, this); } throw this.astErrorOutput(`Unhandled getType Type "${e2.type}"`, e2); case "LogicalExpression": return "Boolean"; case "BinaryExpression": switch (e2.operator) { case "%": case "/": if (this.fixIntegerDivisionAccuracy) return "Number"; break; case ">": case "<": return "Boolean"; case "&": case "|": case "^": case "<<": case ">>": case ">>>": return "Integer"; } const r2 = this.getType(e2.left); if (this.isState("skip-literal-correction")) return r2; if ("LiteralInteger" === r2) { const t3 = this.getType(e2.right); return "LiteralInteger" === t3 ? e2.left.value % 1 == 0 ? "Integer" : "Float" : t3; } return a[r2] || r2; case "UpdateExpression": case "ReturnStatement": return this.getType(e2.argument); case "UnaryExpression": return "~" === e2.operator ? "Integer" : this.getType(e2.argument); case "VariableDeclaration": { const t3 = e2.declarations; let r3; for (let e3 = 0; e3 < t3.length; e3++) { const n3 = t3[e3]; r3 = this.getType(n3); } if (!r3) throw this.astErrorOutput("Unable to find type for declaration", e2); return r3; } case "VariableDeclarator": const n2 = this.getDeclaration(e2.id); if (!n2) throw this.astErrorOutput("Unable to find declarator", e2); if (!n2.valueType) throw this.astErrorOutput("Unable to find declarator valueType", e2); return n2.valueType; case "Identifier": if ("Infinity" === e2.name) return "Number"; if (this.isAstVariable(e2)) { if ("value" === this.getVariableSignature(e2)) return this.getCheckVariableType(e2); } const i2 = this.findIdentifierOrigin(e2); return i2 && i2.init ? this.getType(i2.init) : null; case "MemberExpression": if (this.isAstMathFunction(e2)) { switch (e2.property.name) { case "ceil": case "floor": case "round": return "Integer"; } return "Number"; } if (this.isAstVariable(e2)) { switch (this.getVariableSignature(e2)) { case "value[]": return this.getLookupType(this.getCheckVariableType(e2.object)); case "value[][]": return this.getLookupType(this.getCheckVariableType(e2.object.object)); case "value[][][]": return this.getLookupType(this.getCheckVariableType(e2.object.object.object)); case "value[][][][]": return this.getLookupType(this.getCheckVariableType(e2.object.object.object.object)); case "value.thread.value": case "this.thread.value": return "Integer"; case "this.output.value": return this.dynamicOutput ? "Integer" : "LiteralInteger"; case "this.constants.value": return this.getConstantType(e2.property.name); case "this.constants.value[]": return this.getLookupType(this.getConstantType(e2.object.property.name)); case "this.constants.value[][]": return this.getLookupType(this.getConstantType(e2.object.object.property.name)); case "this.constants.value[][][]": return this.getLookupType(this.getConstantType(e2.object.object.object.property.name)); case "this.constants.value[][][][]": return this.getLookupType(this.getConstantType(e2.object.object.object.object.property.name)); case "fn()[]": case "fn()[][]": case "fn()[][][]": return this.getLookupType(this.getType(e2.object)); case "value.value": if (this.isAstMathVariable(e2)) return "Number"; switch (e2.property.name) { case "r": case "g": case "b": case "a": return this.getLookupType(this.getCheckVariableType(e2.object)); } case "[][]": return "Number"; } throw this.astErrorOutput("Unhandled getType MemberExpression", e2); } throw this.astErrorOutput("Unhandled getType MemberExpression", e2); case "ConditionalExpression": case "IfStatement": return this.getType(e2.consequent); case "FunctionDeclaration": case "FunctionExpression": const s2 = this.findLastReturn(e2.body); return s2 ? this.getType(s2) : null; case "SequenceExpression": return this.getType(e2.expressions[e2.expressions.length - 1]); default: throw this.astErrorOutput(`Unhandled getType Type "${e2.type}"`, e2); } } getCheckVariableType(e2) { const t2 = this.getVariableType(e2); if (!t2) throw this.astErrorOutput(`${e2.type} is not defined`, e2); return t2; } inferArgumentTypesIfNeeded(e2, t2) { for (let r2 = 0; r2 < t2.length; r2++) { if (!this.needsArgumentType(e2, r2)) continue; const n2 = this.getType(t2[r2]); if (!n2) throw this.astErrorOutput(`Unable to infer argument ${r2}`, t2[r2]); this.assignArgumentType(e2, r2, n2); } } isAstMathVariable(e2) { return "MemberExpression" === e2.type && e2.object && "Identifier" === e2.object.type && "Math" === e2.object.name && e2.property && "Identifier" === e2.property.type && ["E", "PI", "SQRT2", "SQRT1_2", "LN2", "LN10", "LOG2E", "LOG10E"].indexOf(e2.property.name) > -1; } isAstMathFunction(e2) { return "CallExpression" === e2.type && e2.callee && "MemberExpression" === e2.callee.type && e2.callee.object && "Identifier" === e2.callee.object.type && "Math" === e2.callee.object.name && e2.callee.property && "Identifier" === e2.callee.property.type && ["abs", "acos", "acosh", "asin", "asinh", "atan", "atan2", "atanh", "cbrt", "ceil", "clz32", "cos", "cosh", "expm1", "exp", "floor", "fround", "imul", "log", "log2", "log10", "log1p", "max", "min", "pow", "random", "round", "sign", "sin", "sinh", "sqrt", "tan", "tanh", "trunc"].indexOf(e2.callee.property.name) > -1; } isAstVariable(e2) { return "Identifier" === e2.type || "MemberExpression" === e2.type; } isSafe(e2) { return this.isSafeDependencies(this.getDependencies(e2)); } isSafeDependencies(e2) { return !e2 || !e2.every || e2.every((e3) => e3.isSafe); } getDependencies(e2, t2, r2) { if (t2 || (t2 = []), !e2) return null; if (Array.isArray(e2)) { for (let n2 = 0; n2 < e2.length; n2++) this.getDependencies(e2[n2], t2, r2); return t2; } switch (e2.type) { case "AssignmentExpression": return this.getDependencies(e2.left, t2, r2), this.getDependencies(e2.right, t2, r2), t2; case "ConditionalExpression": return this.getDependencies(e2.test, t2, r2), this.getDependencies(e2.alternate, t2, r2), this.getDependencies(e2.consequent, t2, r2), t2; case "Literal": t2.push({ origin: "literal", value: e2.value, isSafe: true !== r2 && (e2.value > -1 / 0 && e2.value < 1 / 0 && !isNaN(e2.value)) }); break; case "VariableDeclarator": return this.getDependencies(e2.init, t2, r2); case "Identifier": const n2 = this.getDeclaration(e2); if (n2) t2.push({ name: e2.name, origin: "declaration", isSafe: !r2 && this.isSafeDependencies(n2.dependencies) }); else if (this.argumentNames.indexOf(e2.name) > -1) t2.push({ name: e2.name, origin: "argument", isSafe: false }); else if (this.strictTypingChecking) throw new Error(`Cannot find identifier origin "${e2.name}"`); break; case "FunctionDeclaration": return this.getDependencies(e2.body.body[e2.body.body.length - 1], t2, r2); case "ReturnStatement": return this.getDependencies(e2.argument, t2); case "BinaryExpression": case "LogicalExpression": return r2 = "/" === e2.operator || "*" === e2.operator, this.getDependencies(e2.left, t2, r2), this.getDependencies(e2.right, t2, r2), t2; case "UnaryExpression": case "UpdateExpression": return this.getDependencies(e2.argument, t2, r2); case "VariableDeclaration": return this.getDependencies(e2.declarations, t2, r2); case "ArrayExpression": return t2.push({ origin: "declaration", isSafe: true }), t2; case "CallExpression": return t2.push({ origin: "function", isSafe: true }), t2; case "MemberExpression": const i2 = this.getMemberExpressionDetails(e2); switch (i2.signature) { case "value[]": this.getDependencies(e2.object, t2, r2); break; case "value[][]": this.getDependencies(e2.object.object, t2, r2); break; case "value[][][]": this.getDependencies(e2.object.object.object, t2, r2); break; case "this.output.value": this.dynamicOutput && t2.push({ name: i2.name, origin: "output", isSafe: false }); } if (i2) return i2.property && this.getDependencies(i2.property, t2, r2), i2.xProperty && this.getDependencies(i2.xProperty, t2, r2), i2.yProperty && this.getDependencies(i2.yProperty, t2, r2), i2.zProperty && this.getDependencies(i2.zProperty, t2, r2), t2; case "SequenceExpression": return this.getDependencies(e2.expressions, t2, r2); default: throw this.astErrorOutput(`Unhandled type ${e2.type} in getDependencies`, e2); } return t2; } getVariableSignature(e2, t2) { if (!this.isAstVariable(e2)) throw new Error(`ast of type "${e2.type}" is not a variable signature`); if ("Identifier" === e2.type) return "value"; const r2 = []; for (; e2; ) e2.computed ? r2.push("[]") : "ThisExpression" === e2.type ? r2.unshift("this") : e2.property && e2.property.name ? "x" === e2.property.name || "y" === e2.property.name || "z" === e2.property.name ? r2.unshift(t2 ? "." + e2.property.name : ".value") : "constants" === e2.property.name || "thread" === e2.property.name || "output" === e2.property.name ? r2.unshift("." + e2.property.name) : r2.unshift(t2 ? "." + e2.property.name : ".value") : e2.name ? r2.unshift(t2 ? e2.name : "value") : e2.callee && e2.callee.name ? r2.unshift(t2 ? e2.callee.name + "()" : "fn()") : e2.elements ? r2.unshift("[]") : r2.unshift("unknown"), e2 = e2.object; const n2 = r2.join(""); if (t2) return n2; return ["value", "value[]", "value[][]", "value[][][]", "value[][][][]", "value.value", "value.thread.value", "this.thread.value", "this.output.value", "this.constants.value", "this.constants.value[]", "this.constants.value[][]", "this.constants.value[][][]", "this.constants.value[][][][]", "fn()[]", "fn()[][]", "fn()[][][]", "[][]"].indexOf(n2) > -1 ? n2 : null; } build() { return this.toString().length > 0; } astGeneric(e2, t2) { if (null === e2) throw this.astErrorOutput("NULL ast", e2); if (Array.isArray(e2)) { for (let r2 = 0; r2 < e2.length; r2++) this.astGeneric(e2[r2], t2); return t2; } switch (e2.type) { case "FunctionDeclaration": return this.astFunctionDeclaration(e2, t2); case "FunctionExpression": return this.astFunctionExpression(e2, t2); case "ReturnStatement": return this.astReturnStatement(e2, t2); case "Literal": return this.astLiteral(e2, t2); case "BinaryExpression": return this.astBinaryExpression(e2, t2); case "Identifier": return this.astIdentifierExpression(e2, t2); case "AssignmentExpression": return this.astAssignmentExpression(e2, t2); case "ExpressionStatement": return this.astExpressionStatement(e2, t2); case "EmptyStatement": return this.astEmptyStatement(e2, t2); case "BlockStatement": return this.astBlockStatement(e2, t2); case "IfStatement": return this.astIfStatement(e2, t2); case "SwitchStatement": return this.astSwitchStatement(e2, t2); case "BreakStatement": return this.astBreakStatement(e2, t2); case "ContinueStatement": return this.astContinueStatement(e2, t2); case "ForStatement": return this.astForStatement(e2, t2); case "WhileStatement": return this.astWhileStatement(e2, t2); case "DoWhileStatement": return this.astDoWhileStatement(e2, t2); case "VariableDeclaration": return this.astVariableDeclaration(e2, t2); case "VariableDeclarator": return this.astVariableDeclarator(e2, t2); case "ThisExpression": return this.astThisExpression(e2, t2); case "SequenceExpression": return this.astSequenceExpression(e2, t2); case "UnaryExpression": return this.astUnaryExpression(e2, t2); case "UpdateExpression": return this.astUpdateExpression(e2, t2); case "LogicalExpression": return this.astLogicalExpression(e2, t2); case "MemberExpression": return this.astMemberExpression(e2, t2); case "CallExpression": return this.astCallExpression(e2, t2); case "ArrayExpression": return this.astArrayExpression(e2, t2); case "DebuggerStatement": return this.astDebuggerStatement(e2, t2); case "ConditionalExpression": return this.astConditionalExpression(e2, t2); } throw this.astErrorOutput("Unknown ast type : " + e2.type, e2); } astErrorOutput(e2, t2) { if ("string" != typeof this.source) return new Error(e2); const r2 = i.getAstString(this.source, t2), n2 = this.source.substr(t2.start).split(/\n/), s2 = n2.length > 0 ? n2[n2.length - 1] : 0; return new Error(`${e2} on line ${n2.length}, position ${s2.length}: ${r2}`); } astDebuggerStatement(e2, t2) { return t2; } astConditionalExpression(e2, t2) { if ("ConditionalExpression" !== e2.type) throw this.astErrorOutput("Not a conditional expression", e2); return t2.push("("), this.astGeneric(e2.test, t2), t2.push("?"), this.astGeneric(e2.consequent, t2), t2.push(":"), this.astGeneric(e2.alternate, t2), t2.push(")"), t2; } astFunction(e2, t2) { throw new Error(`"astFunction" not defined on ${this.constructor.name}`); } astFunctionDeclaration(e2, t2) { return this.isChildFunction(e2) ? t2 : this.astFunction(e2, t2); } astFunctionExpression(e2, t2) { return this.isChildFunction(e2) ? t2 : this.astFunction(e2, t2); } isChildFunction(e2) { for (let t2 = 0; t2 < this.functions.length; t2++) if (this.functions[t2] === e2) return true; return false; } astReturnStatement(e2, t2) { return t2; } astLiteral(e2, t2) { return this.literalTypes[this.astKey(e2)] = "Number", t2; } astBinaryExpression(e2, t2) { return t2; } astIdentifierExpression(e2, t2) { return t2; } astAssignmentExpression(e2, t2) { return t2; } astExpressionStatement(e2, t2) { return this.astGeneric(e2.expression, t2), t2.push(";"), t2; } astEmptyStatement(e2, t2) { return t2; } astBlockStatement(e2, t2) { return t2; } astIfStatement(e2, t2) { return t2; } astSwitchStatement(e2, t2) { return t2; } astBreakStatement(e2, t2) { return t2.push("break;"), t2; } astContinueStatement(e2, t2) { return t2.push("continue;\n"), t2; } astForStatement(e2, t2) { return t2; } astWhileStatement(e2, t2) { return t2; } astDoWhileStatement(e2, t2) { return t2; } astVariableDeclarator(e2, t2) { return this.astGeneric(e2.id, t2), null !== e2.init && (t2.push("="), this.astGeneric(e2.init, t2)), t2; } astThisExpression(e2, t2) { return t2; } astSequenceExpression(e2, t2) { const { expressions: r2 } = e2, n2 = []; for (let e3 = 0; e3 < r2.length; e3++) { const t3 = r2[e3], i2 = []; this.astGeneric(t3, i2), n2.push(i2.join("")); } return n2.length > 1 ? t2.push("(", n2.join(","), ")") : t2.push(n2[0]), t2; } astUnaryExpression(e2, t2) { return this.checkAndUpconvertBitwiseUnary(e2, t2) || (e2.prefix ? (t2.push(e2.operator), this.astGeneric(e2.argument, t2)) : (this.astGeneric(e2.argument, t2), t2.push(e2.operator))), t2; } checkAndUpconvertBitwiseUnary(e2, t2) { } astUpdateExpression(e2, t2) { return e2.prefix ? (t2.push(e2.operator), this.astGeneric(e2.argument, t2)) : (this.astGeneric(e2.argument, t2), t2.push(e2.operator)), t2; } astLogicalExpression(e2, t2) { return t2.push("("), this.astGeneric(e2.left, t2), t2.push(e2.operator), this.astGeneric(e2.right, t2), t2.push(")"), t2; } astMemberExpression(e2, t2) { return t2; } astCallExpression(e2, t2) { return t2; } astArrayExpression(e2, t2) { return t2; } getMemberExpressionDetails(e2) { if ("MemberExpression" !== e2.type) throw this.astErrorOutput(`Expression ${e2.type} not a MemberExpression`, e2); let t2 = null, r2 = null; const n2 = this.getVariableSignature(e2); switch (n2) { case "value": return null; case "value.thread.value": case "this.thread.value": case "this.output.value": return { signature: n2, type: "Integer", name: e2.property.name }; case "value[]": if ("string" != typeof e2.object.name) throw this.astErrorOutput("Unexpected expression", e2); return t2 = e2.object.name, { name: t2, origin: "user", signature: n2, type: this.getVariableType(e2.object), xProperty: e2.property }; case "value[][]": if ("string" != typeof e2.object.object.name) throw this.astErrorOutput("Unexpected expression", e2); return t2 = e2.object.object.name, { name: t2, origin: "user", signature: n2, type: this.getVariableType(e2.object.object), yProperty: e2.object.property, xProperty: e2.property }; case "value[][][]": if ("string" != typeof e2.object.object.object.name) throw this.astErrorOutput("Unexpected expression", e2); return t2 = e2.object.object.object.name, { name: t2, origin: "user", signature: n2, type: this.getVariableType(e2.object.object.object), zProperty: e2.object.object.property, yProperty: e2.object.property, xProperty: e2.property }; case "value[][][][]": if ("string" != typeof e2.object.object.object.object.name) throw this.astErrorOutput("Unexpected expression", e2); return t2 = e2.object.object.object.object.name, { name: t2, origin: "user", signature: n2, type: this.getVariableType(e2.object.object.object.object), zProperty: e2.object.object.property, yProperty: e2.object.property, xProperty: e2.property }; case "value.value": if ("string" != typeof e2.property.name) throw this.astErrorOutput("Unexpected expression", e2); if (this.isAstMathVariable(e2)) return t2 = e2.property.name, { name: t2, origin: "Math", type: "Number", signature: n2 }; switch (e2.property.name) { case "r": case "g": case "b": case "a": return t2 = e2.object.name, { name: t2, property: e2.property.name, origin: "user", signature: n2, type: "Number" }; default: throw this.astErrorOutput("Unexpected expression", e2); } case "this.constants.value": if ("string" != typeof e2.property.name) throw this.astErrorOutput("Unexpected expression", e2); if (t2 = e2.property.name, r2 = this.getConstantType(t2), !r2) throw this.astErrorOutput("Constant has no type", e2); return { name: t2, type: r2, origin: "constants", signature: n2 }; case "this.constants.value[]": if ("string" != typeof e2.object.property.name) throw this.astErrorOutput("Unexpected expression", e2); if (t2 = e2.object.property.name, r2 = this.getConstantType(t2), !r2) throw this.astErrorOutput("Constant has no type", e2); return { name: t2, type: r2, origin: "constants", signature: n2, xProperty: e2.property }; case "this.constants.value[][]": if ("string" != typeof e2.object.object.property.name) throw this.astErrorOutput("Unexpected expression", e2); if (t2 = e2.object.object.property.name, r2 = this.getConstantType(t2), !r2) throw this.astErrorOutput("Constant has no type", e2); return { name: t2, type: r2, origin: "constants", signature: n2, yProperty: e2.object.property, xProperty: e2.property }; case "this.constants.value[][][]": if ("string" != typeof e2.object.object.object.property.name) throw this.astErrorOutput("Unexpected expression", e2); if (t2 = e2.object.object.object.property.name, r2 = this.getConstantType(t2), !r2) throw this.astErrorOutput("Constant has no type", e2); return { name: t2, type: r2, origin: "constants", signature: n2, zProperty: e2.object.object.property, yProperty: e2.object.property, xProperty: e2.property }; case "fn()[]": case "fn()[][]": case "[][]": return { signature: n2, property: e2.property }; default: throw this.astErrorOutput("Unexpected expression", e2); } } findIdentifierOrigin(e2) { const t2 = [this.ast]; for (; t2.length > 0; ) { const r2 = t2[0]; if ("VariableDeclarator" === r2.type && r2.id && r2.id.name && r2.id.name === e2.name) return r2; if (t2.shift(), r2.argument) t2.push(r2.argument); else if (r2.body) t2.push(r2.body); else if (r2.declarations) t2.push(r2.declarations); else if (Array.isArray(r2)) for (let e3 = 0; e3 < r2.length; e3++) t2.push(r2[e3]); } return null; } findLastReturn(e2) { const t2 = [e2 || this.ast]; for (; t2.length > 0; ) { const e3 = t2.pop(); if ("ReturnStatement" === e3.type) return e3; if ("FunctionDeclaration" !== e3.type) if (e3.argument) t2.push(e3.argument); else if (e3.body) t2.push(e3.body); else if (e3.declarations) t2.push(e3.declarations); else if (Array.isArray(e3)) for (let r2 = 0; r2 < e3.length; r2++) t2.push(e3[r2]); else e3.consequent ? t2.push(e3.consequent) : e3.cases && t2.push(e3.cases); } return null; } getInternalVariableName(e2) { return this._internalVariableNames.hasOwnProperty(e2) || (this._internalVariableNames[e2] = 0), this._internalVariableNames[e2]++, 1 === this._internalVariableNames[e2] ? e2 : e2 + this._internalVariableNames[e2]; } astKey(e2, t2 = ",") { if (!e2.start || !e2.end) throw new Error("AST start and end needed"); return `${e2.start}${t2}${e2.end}`; } } }; }, { "../utils": 114, "./function-tracer": 11, acorn: 1 }], 11: [function(e, t, r) { const { utils: n } = e("../utils"); function i(e2) { return e2.length > 0 ? e2[e2.length - 1] : null; } const s = "trackIdentifiers", a = "memberExpression", o = "inForLoopInit"; t.exports = { FunctionTracer: class { constructor(e2) { this.runningContexts = [], this.functionContexts = [], this.contexts = [], this.functionCalls = [], this.declarations = [], this.identifiers = [], this.functions = [], this.returnStatements = [], this.trackedIdentifiers = null, this.states = [], this.newFunctionContext(), this.scan(e2); } isState(e2) { return this.states[this.states.length - 1] === e2; } hasState(e2) { return this.states.indexOf(e2) > -1; } pushState(e2) { this.states.push(e2); } popState(e2) { if (!this.isState(e2)) throw new Error(`Cannot pop the non-active state "${e2}"`); this.states.pop(); } get currentFunctionContext() { return i(this.functionContexts); } get currentContext() { return i(this.runningContexts); } newFunctionContext() { const e2 = { "@contextType": "function" }; this.contexts.push(e2), this.functionContexts.push(e2); } newContext(e2) { const t2 = Object.assign({ "@contextType": "const/let" }, this.currentContext); this.contexts.push(t2), this.runningContexts.push(t2), e2(); const { currentFunctionContext: r2 } = this; for (const e3 in r2) r2.hasOwnProperty(e3) && !t2.hasOwnProperty(e3) && (t2[e3] = r2[e3]); return this.runningContexts.pop(), t2; } useFunctionContext(e2) { const t2 = i(this.functionContexts); this.runningContexts.push(t2), e2(), this.runningContexts.pop(); } getIdentifiers(e2) { const t2 = this.trackedIdentifiers = []; return this.pushState(s), e2(), this.trackedIdentifiers = null, this.popState(s), t2; } getDeclaration(e2) { const { currentContext: t2, currentFunctionContext: r2, runningContexts: n2 } = this, i2 = t2[e2] || r2[e2] || null; if (!i2 && t2 === r2 && n2.length > 0) { const t3 = n2[n2.length - 2]; if (t3[e2]) return t3[e2]; } return i2; } scan(e2) { if (e2) if (Array.isArray(e2)) for (let t2 = 0; t2 < e2.length; t2++) this.scan(e2[t2]); else switch (e2.type) { case "Program": this.useFunctionContext(() => { this.scan(e2.body); }); break; case "BlockStatement": this.newContext(() => { this.scan(e2.body); }); break; case "AssignmentExpression": case "LogicalExpression": case "BinaryExpression": this.scan(e2.left), this.scan(e2.right); break; case "UpdateExpression": if ("++" === e2.operator) { const t2 = this.getDeclaration(e2.argument.name); t2 && (t2.suggestedType = "Integer"); } this.scan(e2.argument); break; case "UnaryExpression": this.scan(e2.argument); break; case "VariableDeclaration": "var" === e2.kind ? this.useFunctionContext(() => { e2.declarations = n.normalizeDeclarations(e2), this.scan(e2.declarations); }) : (e2.declarations = n.normalizeDeclarations(e2), this.scan(e2.declarations)); break; case "VariableDeclarator": { const { currentContext: t2 } = this, r2 = this.hasState(o), n2 = { ast: e2, context: t2, name: e2.id.name, origin: "declaration", inForLoopInit: r2, inForLoopTest: null, assignable: t2 === this.currentFunctionContext || !r2 && !t2.hasOwnProperty(e2.id.name), suggestedType: null, valueType: null, dependencies: null, isSafe: null }; t2[e2.id.name] || (t2[e2.id.name] = n2), this.declarations.push(n2), this.scan(e2.id), this.scan(e2.init); break; } case "FunctionExpression": case "FunctionDeclaration": 0 === this.runningContexts.length ? this.scan(e2.body) : this.functions.push(e2); break; case "IfStatement": this.scan(e2.test), this.scan(e2.consequent), e2.alternate && this.scan(e2.alternate); break; case "ForStatement": { let t2; const r2 = this.newContext(() => { this.pushState(o), this.scan(e2.init), this.popState(o), t2 = this.getIdentifiers(() => { this.scan(e2.test); }), this.scan(e2.update), this.newContext(() => { this.scan(e2.body); }); }); if (t2) for (const e3 in r2) "@contextType" !== e3 && t2.indexOf(e3) > -1 && (r2[e3].inForLoopTest = true); break; } case "DoWhileStatement": case "WhileStatement": this.newContext(() => { this.scan(e2.body), this.scan(e2.test); }); break; case "Identifier": this.isState(s) && this.trackedIdentifiers.push(e2.name), this.identifiers.push({ context: this.currentContext, declaration: this.getDeclaration(e2.name), ast: e2 }); break; case "ReturnStatement": this.returnStatements.push(e2), this.scan(e2.argument); break; case "MemberExpression": this.pushState(a), this.scan(e2.object), this.scan(e2.property), this.popState(a); break; case "ExpressionStatement": this.scan(e2.expression); break; case "SequenceExpression": this.scan(e2.expressions); break; case "CallExpression": this.functionCalls.push({ context: this.currentContext, ast: e2 }), this.scan(e2.arguments); break; case "ArrayExpression": this.scan(e2.elements); break; case "ConditionalExpression": this.scan(e2.test), this.scan(e2.alternate), this.scan(e2.consequent); break; case "SwitchStatement": this.scan(e2.discriminant), this.scan(e2.cases); break; case "SwitchCase": this.scan(e2.test), this.scan(e2.consequent); break; case "ThisExpression": case "Literal": case "DebuggerStatement": case "EmptyStatement": case "BreakStatement": case "ContinueStatement": break; default: throw new Error(`unhandled type "${e2.type}"`); } } } }; }, { "../utils": 114 }], 12: [function(e, t, r) { const { glWiretap: n } = e("gl-wiretap"), { utils: i } = e("../../utils"); function s(e2) { return e2.toString().replace("=>", "").replace(/^function /, "").replace(/utils[.]/g, "/*utils.*/"); } function a(e2, t2) { const r2 = "single" === t2.precision ? e2 : `new Float32Array(${e2}.buffer)`; return t2.output[2] ? `renderOutput(${r2}, ${t2.output[0]}, ${t2.output[1]}, ${t2.output[2]})` : t2.output[1] ? `renderOutput(${r2}, ${t2.output[0]}, ${t2.output[1]})` : `renderOutput(${r2}, ${t2.output[0]})`; } function o(e2, t2, r2) { const n2 = e2.toArray.toString(), s2 = !/^function/.test(n2); return `() => { function framebuffer() { return ${r2}; }; ${i.flattenFunctionToString(`${s2 ? "function " : ""}${n2}`, { findDependency: (t3, r3) => { if ("utils" === t3) return `const ${r3} = ${i[r3].toString()};`; if ("this" === t3) return "framebuffer" === r3 ? "" : `${s2 ? "function " : ""}${e2[r3].toString()}`; throw new Error("unhandled fromObject"); }, thisLookup: (r3, n3) => { if ("texture" === r3) return t2; if ("context" === r3) return n3 ? null : "gl"; if (e2.hasOwnProperty(r3)) return JSON.stringify(e2[r3]); throw new Error(`unhandled thisLookup ${r3}`); } })} return toArray(); }`; } function u(e2, t2, r2, n2, i2) { if (null === e2) return null; if (null === t2) return null; switch (typeof e2) { case "boolean": case "number": return null; } if ("undefined" != typeof HTMLImageElement && e2 instanceof HTMLImageElement) for (let i3 = 0; i3 < t2.length; i3++) { const s2 = t2[i3]; if ("HTMLImageArray" !== s2.type && s2) continue; if (s2.uploadValue !== e2) continue; const a2 = r2[i3].indexOf(e2); if (-1 === a2) continue; const o2 = `uploadValue_${s2.name}[${a2}]`; return n2.insertVariable(o2, e2), o2; } for (let r3 = 0; r3 < t2.length; r3++) { const i3 = t2[r3]; if (e2 !== i3.uploadValue) continue; const s2 = `uploadValue_${i3.name}`; return n2.insertVariable(s2, i3), s2; } return null; } t.exports = { glKernelString: function(e2, t2, r2, l, h) { r2.built || r2.build.apply(r2, t2), t2 = t2 ? Array.from(t2).map((e3) => { switch (typeof e3) { case "boolean": return new Boolean(e3); case "number": return new Number(e3); default: return e3; } }) : null; const c = [], p = [], d = n(r2.context, { useTrackablePrimitives: true, onReadPixels: (e3) => { if (N.subKernels) { if (m) { const t3 = N.subKernels[f++].property; p.push(` result${isNaN(t3) ? "." + t3 : `[${t3}]`} = ${a(e3, N)};`); } else p.push(` const result = { result: ${a(e3, N)} };`), m = true; f === N.subKernels.length && p.push(" return result;"); } else e3 ? p.push(` return ${a(e3, N)};`) : p.push(" return null;"); }, onUnrecognizedArgumentLookup: (e3) => { const t3 = u(e3, N.kernelArguments, [], d, c); if (t3) return t3; const r3 = u(e3, N.kernelConstants, S ? Object.keys(S).map((e4) => S[e4]) : [], d, c); return r3 || null; } }); let m = false, f = 0; const { source: g, canvas: x, output: y, pipeline: b, graphical: T, loopMaxIterations: v, constants: S, optimizeFloatMemory: A, precision: _, fixIntegerDivisionAccuracy: E, functions: w, nativeFunctions: k, subKernels: I, immutable: D, argumentTypes: C, constantTypes: $, kernelArguments: L, kernelConstants: R, tactic: F } = r2, N = new e2(g, { canvas: x, context: d, checkContext: false, output: y, pipeline: b, graphical: T, loopMaxIterations: v, constants: S, optimizeFloatMemory: A, precision: _, fixIntegerDivisionAccuracy: E, functions: w, nativeFunctions: k, subKernels: I, immutable: D, argumentTypes: C, constantTypes: $, tactic: F }); let V = []; if (d.setIndent(2), N.build.apply(N, t2), V.push(d.toString()), d.reset(), N.kernelArguments.forEach((e3, r3) => { switch (e3.type) { case "Integer": case "Boolean": case "Number": case "Float": case "Array": case "Array(2)": case "Array(3)": case "Array(4)": case "HTMLCanvas": case "HTMLImage": case "HTMLVideo": case "Input": d.insertVariable(`uploadValue_${e3.name}`, e3.uploadValue); break; case "HTMLImageArray": for (let n2 = 0; n2 < t2[r3].length; n2++) { const i2 = t2[r3]; d.insertVariable(`uploadValue_${e3.name}[${n2}]`, i2[n2]); } break; case "MemoryOptimizedNumberTexture": case "NumberTexture": case "Array1D(2)": case "Array1D(3)": case "Array1D(4)": case "Array2D(2)": case "Array2D(3)": case "Array2D(4)": case "Array3D(2)": case "Array3D(3)": case "Array3D(4)": case "ArrayTexture(1)": case "ArrayTexture(2)": case "ArrayTexture(3)": case "ArrayTexture(4)": d.insertVariable(`uploadValue_${e3.name}`, t2[r3].texture); break; default: throw new Error(`unhandled kernelArgumentType insertion for glWiretap of type ${e3.type}`); } }), V.push("/** start of injected functions **/"), V.push(`function ${s(i.flattenTo)}`), V.push(`function ${s(i.flatten2dArrayTo)}`), V.push(`function ${s(i.flatten3dArrayTo)}`), V.push(`function ${s(i.flatten4dArrayTo)}`), V.push(`function ${s(i.isArray)}`), N.renderOutput !== N.renderTexture && N.formatValues && V.push(` const renderOutput = function ${s(N.formatValues)};`), V.push("/** end of injected functions **/"), V.push(` const innerKernel = function (${N.kernelArguments.map((e3) => e3.varName).join(", ")}) {`), d.setIndent(4), N.run.apply(N, t2), N.renderKernels ? N.renderKernels() : N.renderOutput && N.renderOutput(), V.push(" /** start setup uploads for kernel values **/"), N.kernelArguments.forEach((e3) => { V.push(" " + e3.getStringValueHandler().split("\n").join("\n ")); }), V.push(" /** end setup uploads for kernel values **/"), V.push(d.toString()), N.renderOutput === N.renderTexture) { d.reset(); const e3 = d.getContextVariableName(N.framebuffer); if (N.renderKernels) { const t3 = N.renderKernels(), r3 = d.getContextVariableName(N.texture.texture); V.push(` return { result: { texture: ${r3}, type: '${t3.result.type}', toArray: ${o(t3.result, r3, e3)} },`); const { subKernels: n2, mappedTextures: i2 } = N; for (let r4 = 0; r4 < n2.length; r4++) { const s2 = i2[r4], a2 = n2[r4], u2 = t3[a2.property], l2 = d.getContextVariableName(s2.texture); V.push(` ${a2.property}: { texture: ${l2}, type: '${u2.type}', toArray: ${o(u2, l2, e3)} },`); } V.push(" };"); } else { const t3 = N.renderOutput(), r3 = d.getContextVariableName(N.texture.texture); V.push(` return { texture: ${r3}, type: '${t3.type}', toArray: ${o(t3, r3, e3)} };`); } } V.push(" " + (h ? "\n" + h + " " : "")), V.push(p.join("\n")), V.push(" };"), N.graphical && (V.push(function(e3) { const t3 = e3.getPixels.toString(), r3 = !/^function/.test(t3); return i.flattenFunctionToString(`${r3 ? "function " : ""}${t3}`, { findDependency: (e4, t4) => "utils" === e4 ? `const ${t4} = ${i[t4].toString()};` : null, thisLookup: (t4) => { if ("context" === t4) return null; if (e3.hasOwnProperty(t4)) return JSON.stringify(e3[t4]); throw new Error(`unhandled thisLookup ${t4}`); } }); }(N)), V.push(" innerKernel.getPixels = getPixels;")), V.push(" return innerKernel;"); let M = []; return R.forEach((e3) => { M.push(`${e3.getStringValueHandler()}`); }), `function kernel(settings) { const { context, constants } = settings; ${M.join("")} ${l || ""} ${V.join("\n")} }`; } }; }, { "../../utils": 114, "gl-wiretap": 3 }], 13: [function(e, t, r) { const { Kernel: n } = e("../kernel"), { utils: i } = e("../../utils"), { GLTextureArray2Float: s } = e("./texture/array-2-float"), { GLTextureArray2Float2D: a } = e("./texture/array-2-float-2d"), { GLTextureArray2Float3D: o } = e("./texture/array-2-float-3d"), { GLTextureArray3Float: u } = e("./texture/array-3-float"), { GLTextureArray3Float2D: l } = e("./texture/array-3-float-2d"), { GLTextureArray3Float3D: h } = e("./texture/array-3-float-3d"), { GLTextureArray4Float: c } = e("./texture/array-4-float"), { GLTextureArray4Float2D: p } = e("./texture/array-4-float-2d"), { GLTextureArray4Float3D: d } = e("./texture/array-4-float-3d"), { GLTextureFloat: m } = e("./texture/float"), { GLTextureFloat2D: f } = e("./texture/float-2d"), { GLTextureFloat3D: g } = e("./texture/float-3d"), { GLTextureMemoryOptimized: x } = e("./texture/memory-optimized"), { GLTextureMemoryOptimized2D: y } = e("./texture/memory-optimized-2d"), { GLTextureMemoryOptimized3D: b } = e("./texture/memory-optimized-3d"), { GLTextureUnsigned: T } = e("./texture/unsigned"), { GLTextureUnsigned2D: v } = e("./texture/unsigned-2d"), { GLTextureUnsigned3D: S } = e("./texture/unsigned-3d"), { GLTextureGraphical: A } = e("./texture/graphical"); const _ = { int: "Integer", float: "Number", vec2: "Array(2)", vec3: "Array(3)", vec4: "Array(4)" }; t.exports = { GLKernel: class extends n { static get mode() { return "gpu"; } static getIsFloatRead() { const e2 = new this("function kernelFunction() {\n return 1;\n }", { context: this.testContext, canvas: this.testCanvas, validate: false, output: [1], precision: "single", returnType: "Number", tactic: "speed" }); e2.build(), e2.run(); const t2 = e2.renderOutput(); return e2.destroy(true), 1 === t2[0]; } static getIsIntegerDivisionAccurate() { const e2 = new this(function(e3, t3) { return e3[this.thread.x] / t3[this.thread.x]; }.toString(), { context: this.testContext, canvas: this.testCanvas, validate: false, output: [2], returnType: "Number", precision: "unsigned", tactic: "speed" }), t2 = [[6, 6030401], [3, 3991]]; e2.build.apply(e2, t2), e2.run.apply(e2, t2); const r2 = e2.renderOutput(); return e2.destroy(true), 2 === r2[0] && 1511 === r2[1]; } static getIsSpeedTacticSupported() { const e2 = new this(function(e3) { return e3[this.thread.x]; }.toString(), { context: this.testContext, canvas: this.testCanvas, validate: false, output: [4], returnType: "Number", precision: "unsigned", tactic: "speed" }), t2 = [[0, 1, 2, 3]]; e2.build.apply(e2, t2), e2.run.apply(e2, t2); const r2 = e2.renderOutput(); return e2.destroy(true), 0 === Math.round(r2[0]) && 1 === Math.round(r2[1]) && 2 === Math.round(r2[2]) && 3 === Math.round(r2[3]); } static get testCanvas() { throw new Error(`"testCanvas" not defined on ${this.name}`); } static get testContext() { throw new Error(`"testContext" not defined on ${this.name}`); } static getFeatures() { const e2 = this.testContext, t2 = this.getIsDrawBuffers(); return Object.freeze({ isFloatRead: this.getIsFloatRead(), isIntegerDivisionAccurate: this.getIsIntegerDivisionAccurate(), isSpeedTacticSupported: this.getIsSpeedTacticSupported(), isTextureFloat: this.getIsTextureFloat(), isDrawBuffers: t2, kernelMap: t2, channelCount: this.getChannelCount(), maxTextureSize: this.getMaxTextureSize(), lowIntPrecision: e2.getShaderPrecisionFormat(e2.FRAGMENT_SHADER, e2.LOW_INT), lowFloatPrecision: e2.getShaderPrecisionFormat(e2.FRAGMENT_SHADER, e2.LOW_FLOAT), mediumIntPrecision: e2.getShaderPrecisionFormat(e2.FRAGMENT_SHADER, e2.MEDIUM_INT), mediumFloatPrecision: e2.getShaderPrecisionFormat(e2.FRAGMENT_SHADER, e2.MEDIUM_FLOAT), highIntPrecision: e2.getShaderPrecisionFormat(e2.FRAGMENT_SHADER, e2.HIGH_INT), highFloatPrecision: e2.getShaderPrecisionFormat(e2.FRAGMENT_SHADER, e2.HIGH_FLOAT) }); } static setupFeatureChecks() { throw new Error(`"setupFeatureChecks" not defined on ${this.name}`); } static getSignature(e2, t2) { return e2.getVariablePrecisionString() + (t2.length > 0 ? ":" + t2.join(",") : ""); } setFixIntegerDivisionAccuracy(e2) { return this.fixIntegerDivisionAccuracy = e2, this; } setPrecision(e2) { return this.precision = e2, this; } setFloatTextures(e2) { return i.warnDeprecated("method", "setFloatTextures", "setOptimizeFloatMemory"), this.floatTextures = e2, this; } static nativeFunctionArguments(e2) { const t2 = [], r2 = [], n2 = [], i2 = /^[a-zA-Z_]/, s2 = /[a-zA-Z_0-9]/; let a2 = 0, o2 = null, u2 = null; for (; a2 < e2.length; ) { const l2 = e2[a2], h2 = e2[a2 + 1], c2 = n2.length > 0 ? n2[n2.length - 1] : null; if ("FUNCTION_ARGUMENTS" !== c2 || "/" !== l2 || "*" !== h2) if ("MULTI_LINE_COMMENT" !== c2 || "*" !== l2 || "/" !== h2) if ("FUNCTION_ARGUMENTS" !== c2 || "/" !== l2 || "/" !== h2) if ("COMMENT" !== c2 || "\n" !== l2) if (null !== c2 || "(" !== l2) { if ("FUNCTION_ARGUMENTS" === c2) { if (")" === l2) { n2.pop(); break; } if ("f" === l2 && "l" === h2 && "o" === e2[a2 + 2] && "a" === e2[a2 + 3] && "t" === e2[a2 + 4] && " " === e2[a2 + 5]) { n2.push("DECLARE_VARIABLE"), u2 = "float", o2 = "", a2 += 6; continue; } if ("i" === l2 && "n" === h2 && "t" === e2[a2 + 2] && " " === e2[a2 + 3]) { n2.push("DECLARE_VARIABLE"), u2 = "int", o2 = "", a2 += 4; continue; } if ("v" === l2 && "e" === h2 && "c" === e2[a2 + 2] && "2" === e2[a2 + 3] && " " === e2[a2 + 4]) { n2.push("DECLARE_VARIABLE"), u2 = "vec2", o2 = "", a2 += 5; continue; } if ("v" === l2 && "e" === h2 && "c" === e2[a2 + 2] && "3" === e2[a2 + 3] && " " === e2[a2 + 4]) { n2.push("DECLARE_VARIABLE"), u2 = "vec3", o2 = "", a2 += 5; continue; } if ("v" === l2 && "e" === h2 && "c" === e2[a2 + 2] && "4" === e2[a2 + 3] && " " === e2[a2 + 4]) { n2.push("DECLARE_VARIABLE"), u2 = "vec4", o2 = "", a2 += 5; continue; } } else if ("DECLARE_VARIABLE" === c2) { if ("" === o2) { if (" " === l2) { a2++; continue; } if (!i2.test(l2)) throw new Error("variable name is not expected string"); } o2 += l2, s2.test(h2) || (n2.pop(), r2.push(o2), t2.push(_[u2])); } a2++; } else n2.push("FUNCTION_ARGUMENTS"), a2++; else n2.pop(), a2++; else n2.push("COMMENT"), a2 += 2; else n2.pop(), a2 += 2; else n2.push("MULTI_LINE_COMMENT"), a2 += 2; } if (n2.length > 0) throw new Error("GLSL function was not parsable"); return { argumentNames: r2, argumentTypes: t2 }; } static nativeFunctionReturnType(e2) { return _[e2.match(/int|float|vec[2-4]/)[0]]; } static combineKernels(e2, t2) { e2.apply(null, arguments); const { texSize: r2, context: n2, threadDim: s2 } = t2.texSize; let a2; if ("single" === t2.precision) { const e3 = r2[0], t3 = Math.ceil(r2[1] / 4); a2 = new Float32Array(e3 * t3 * 4 * 4), n2.readPixels(0, 0, e3, 4 * t3, n2.RGBA, n2.FLOAT, a2); } else { const e3 = new Uint8Array(r2[0] * r2[1] * 4); n2.readPixels(0, 0, r2[0], r2[1], n2.RGBA, n2.UNSIGNED_BYTE, e3), a2 = new Float32Array(e3.buffer); } if (a2 = a2.subarray(0, s2[0] * s2[1] * s2[2]), 1 === t2.output.length) return a2; if (2 === t2.output.length) return i.splitArray(a2, t2.output[0]); if (3 === t2.output.length) { return i.splitArray(a2, t2.output[0] * t2.output[1]).map(function(e3) { return i.splitArray(e3, t2.output[0]); }); } } constructor(e2, t2) { super(e2, t2), this.transferValues = null, this.formatValues = null, this.TextureConstructor = null, this.renderOutput = null, this.renderRawOutput = null, this.texSize = null, this.translatedSource = null, this.compiledFragmentShader = null, this.compiledVertexShader = null, this.switchingKernels = null, this._textureSwitched = null, this._mappedTextureSwitched = null; } checkTextureSize() { const { features: e2 } = this.constructor; if (this.texSize[0] > e2.maxTextureSize || this.texSize[1] > e2.maxTextureSize) throw new Error(`Texture size [${this.texSize[0]},${this.texSize[1]}] generated by kernel is larger than supported size [${e2.maxTextureSize},${e2.maxTextureSize}]`); } translateSource() { throw new Error(`"translateSource" not defined on ${this.constructor.name}`); } pickRenderStrategy(e2) { if (this.graphical) return this.renderRawOutput = this.readPackedPixelsToUint8Array, this.transferValues = (e3) => e3, this.TextureConstructor = A, null; if ("unsigned" === this.precision) if (this.renderRawOutput = this.readPackedPixelsToUint8Array, this.transferValues = this.readPackedPixelsToFloat32Array, this.pipeline) switch (this.renderOutput = this.renderTexture, null !== this.subKernels && (this.renderKernels = this.renderKernelsToTextures), this.returnType) { case "LiteralInteger": case "Float": case "Number": case "Integer": return this.output[2] > 0 ? (this.TextureConstructor = S, null) : this.output[1] > 0 ? (this.TextureConstructor = v, null) : (this.TextureConstructor = T, null); case "Array(2)": case "Array(3)": case "Array(4)": return this.requestFallback(e2); } else switch (null !== this.subKernels && (this.renderKernels = this.renderKernelsToArrays), this.returnType) { case "LiteralInteger": case "Float": case "Number": case "Integer": return this.renderOutput = this.renderValues, this.output[2] > 0 ? (this.TextureConstructor = S, this.formatValues = i.erect3DPackedFloat, null) : this.output[1] > 0 ? (this.TextureConstructor = v, this.formatValues = i.erect2DPackedFloat, null) : (this.TextureConstructor = T, this.formatValues = i.erectPackedFloat, null); case "Array(2)": case "Array(3)": case "Array(4)": return this.requestFallback(e2); } else { if ("single" !== this.precision) throw new Error(`unhandled precision of "${this.precision}"`); if (this.renderRawOutput = this.readFloatPixelsToFloat32Array, this.transferValues = this.readFloatPixelsToFloat32Array, this.pipeline) switch (this.renderOutput = this.renderTexture, null !== this.subKernels && (this.renderKernels = this.renderKernelsToTextures), this.returnType) { case "LiteralInteger": case "Float": case "Number": case "Integer": return this.optimizeFloatMemory ? this.output[2] > 0 ? (this.TextureConstructor = b, null) : this.output[1] > 0 ? (this.TextureConstructor = y, null) : (this.TextureConstructor = x, null) : this.output[2] > 0 ? (this.TextureConstructor = g, null) : this.output[1] > 0 ? (this.TextureConstructor = f, null) : (this.TextureConstructor = m, null); case "Array(2)": return this.output[2] > 0 ? (this.TextureConstructor = o, null) : this.output[1] > 0 ? (this.TextureConstructor = a, null) : (this.TextureConstructor = s, null); case "Array(3)": return this.output[2] > 0 ? (this.TextureConstructor = h, null) : this.output[1] > 0 ? (this.TextureConstructor = l, null) : (this.TextureConstructor = u, null); case "Array(4)": return this.output[2] > 0 ? (this.TextureConstructor = d, null) : this.output[1] > 0 ? (this.TextureConstructor = p, null) : (this.TextureConstructor = c, null); } if (this.renderOutput = this.renderValues, null !== this.subKernels && (this.renderKernels = this.renderKernelsToArrays), this.optimizeFloatMemory) switch (this.returnType) { case "LiteralInteger": case "Float": case "Number": case "Integer": return this.output[2] > 0 ? (this.TextureConstructor = b, this.formatValues = i.erectMemoryOptimized3DFloat, null) : this.output[1] > 0 ? (this.TextureConstructor = y, this.formatValues = i.erectMemoryOptimized2DFloat, null) : (this.TextureConstructor = x, this.formatValues = i.erectMemoryOptimizedFloat, null); case "Array(2)": return this.output[2] > 0 ? (this.TextureConstructor = o, this.formatValues = i.erect3DArray2, null) : this.output[1] > 0 ? (this.TextureConstructor = a, this.formatValues = i.erect2DArray2, null) : (this.TextureConstructor = s, this.formatValues = i.erectArray2, null); case "Array(3)": return this.output[2] > 0 ? (this.TextureConstructor = h, this.formatValues = i.erect3DArray3, null) : this.output[1] > 0 ? (this.TextureConstructor = l, this.formatValues = i.erect2DArray3, null) : (this.TextureConstructor = u, this.formatValues = i.erectArray3, null); case "Array(4)": return this.output[2] > 0 ? (this.TextureConstructor = d, this.formatValues = i.erect3DArray4, null) : this.output[1] > 0 ? (this.TextureConstructor = p, this.formatValues = i.erect2DArray4, null) : (this.TextureConstructor = c, this.formatValues = i.erectArray4, null); } else switch (this.returnType) { case "LiteralInteger": case "Float": case "Number": case "Integer": return this.output[2] > 0 ? (this.TextureConstructor = g, this.formatValues = i.erect3DFloat, null) : this.output[1] > 0 ? (this.TextureConstructor = f, this.formatValues = i.erect2DFloat, null) : (this.TextureConstructor = m, this.formatValues = i.erectFloat, null); case "Array(2)": return this.output[2] > 0 ? (this.TextureConstructor = o, this.formatValues = i.erect3DArray2, null) : this.output[1] > 0 ? (this.TextureConstructor = a, this.formatValues = i.erect2DArray2, null) : (this.TextureConstructor = s, this.formatValues = i.erectArray2, null); case "Array(3)": return this.output[2] > 0 ? (this.TextureConstructor = h, this.formatValues = i.erect3DArray3, null) : this.output[1] > 0 ? (this.TextureConstructor = l, this.formatValues = i.erect2DArray3, null) : (this.TextureConstructor = u, this.formatValues = i.erectArray3, null); case "Array(4)": return this.output[2] > 0 ? (this.TextureConstructor = d, this.formatValues = i.erect3DArray4, null) : this.output[1] > 0 ? (this.TextureConstructor = p, this.formatValues = i.erect2DArray4, null) : (this.TextureConstructor = c, this.formatValues = i.erectArray4, null); } } throw new Error(`unhandled return type "${this.returnType}"`); } getKernelString() { throw new Error("abstract method call"); } getMainResultTexture() { switch (this.returnType) { case "LiteralInteger": case "Float": case "Integer": case "Number": return this.getMainResultNumberTexture(); case "Array(2)": return this.getMainResultArray2Texture(); case "Array(3)": return this.getMainResultArray3Texture(); case "Array(4)": return this.getMainResultArray4Texture(); default: throw new Error(`unhandled returnType type ${this.returnType}`); } } getMainResultKernelNumberTexture() { throw new Error("abstract method call"); } getMainResultSubKernelNumberTexture() { throw new Error("abstract method call"); } getMainResultKernelArray2Texture() { throw new Error("abstract method call"); } getMainResultSubKernelArray2Texture() { throw new Error("abstract method call"); } getMainResultKernelArray3Texture() { throw new Error("abstract method call"); } getMainResultSubKernelArray3Texture() { throw new Error("abstract method call"); } getMainResultKernelArray4Texture() { throw new Error("abstract method call"); } getMainResultSubKernelArray4Texture() { throw new Error("abstract method call"); } getMainResultGraphical() { throw new Error("abstract method call"); } getMainResultMemoryOptimizedFloats() { throw new Error("abstract method call"); } getMainResultPackedPixels() { throw new Error("abstract method call"); } getMainResultString() { return this.graphical ? this.getMainResultGraphical() : "single" === this.precision ? this.optimizeFloatMemory ? this.getMainResultMemoryOptimizedFloats() : this.getMainResultTexture() : this.getMainResultPackedPixels(); } getMainResultNumberTexture() { return i.linesToString(this.getMainResultKernelNumberTexture()) + i.linesToString(this.getMainResultSubKernelNumberTexture()); } getMainResultArray2Texture() { return i.linesToString(this.getMainResultKernelArray2Texture()) + i.linesToString(this.getMainResultSubKernelArray2Texture()); } getMainResultArray3Texture() { return i.linesToString(this.getMainResultKernelArray3Texture()) + i.linesToString(this.getMainResultSubKernelArray3Texture()); } getMainResultArray4Texture() { return i.linesToString(this.getMainResultKernelArray4Texture()) + i.linesToString(this.getMainResultSubKernelArray4Texture()); } getFloatTacticDeclaration() { return `precision ${this.getVariablePrecisionString(this.texSize, this.tactic)} float; `; } getIntTacticDeclaration() { return `precision ${this.getVariablePrecisionString(this.texSize, this.tactic, true)} int; `; } getSampler2DTacticDeclaration() { return `precision ${this.getVariablePrecisionString(this.texSize, this.tactic)} sampler2D; `; } getSampler2DArrayTacticDeclaration() { return `precision ${this.getVariablePrecisionString(this.texSize, this.tactic)} sampler2DArray; `; } renderTexture() { return this.immutable ? this.texture.clone() : this.texture; } readPackedPixelsToUint8Array() { if ("unsigned" !== this.precision) throw new Error('Requires this.precision to be "unsigned"'); const { texSize: e2, context: t2 } = this, r2 = new Uint8Array(e2[0] * e2[1] * 4); return t2.readPixels(0, 0, e2[0], e2[1], t2.RGBA, t2.UNSIGNED_BYTE, r2), r2; } readPackedPixelsToFloat32Array() { return new Float32Array(this.readPackedPixelsToUint8Array().buffer); } readFloatPixelsToFloat32Array() { if ("single" !== this.precision) throw new Error('Requires this.precision to be "single"'); const { texSize: e2, context: t2 } = this, r2 = e2[0], n2 = e2[1], i2 = new Float32Array(r2 * n2 * 4); return t2.readPixels(0, 0, r2, n2, t2.RGBA, t2.FLOAT, i2), i2; } getPixels(e2) { const { context: t2, output: r2 } = this, [n2, s2] = r2, a2 = new Uint8Array(n2 * s2 * 4); return t2.readPixels(0, 0, n2, s2, t2.RGBA, t2.UNSIGNED_BYTE, a2), new Uint8ClampedArray((e2 ? a2 : i.flipPixels(a2, n2, s2)).buffer); } renderKernelsToArrays() { const e2 = { result: this.renderOutput() }; for (let t2 = 0; t2 < this.subKernels.length; t2++) e2[this.subKernels[t2].property] = this.mappedTextures[t2].toArray(); return e2; } renderKernelsToTextures() { const e2 = { result: this.renderOutput() }; if (this.immutable) for (let t2 = 0; t2 < this.subKernels.length; t2++) e2[this.subKernels[t2].property] = this.mappedTextures[t2].clone(); else for (let t2 = 0; t2 < this.subKernels.length; t2++) e2[this.subKernels[t2].property] = this.mappedTextures[t2]; return e2; } resetSwitchingKernels() { const e2 = this.switchingKernels; return this.switchingKernels = null, e2; } setOutput(e2) { const t2 = this.toKernelOutput(e2); if (this.program) { if (!this.dynamicOutput) throw new Error("Resizing a kernel with dynamicOutput: false is not possible"); const r2 = [t2[0], t2[1] || 1, t2[2] || 1], n2 = i.getKernelTextureSize({ optimizeFloatMemory: this.optimizeFloatMemory, precision: this.precision }, r2), s2 = this.texSize; if (s2) { const t3 = this.getVariablePrecisionString(s2, this.tactic), r3 = this.getVariablePrecisionString(n2, this.tactic); if (t3 !== r3) return this.debug && console.warn("Precision requirement changed, asking GPU instance to recompile"), void this.switchKernels({ type: "outputPrecisionMismatch", precision: r3, needed: e2 }); } this.output = t2, this.threadDim = r2, this.texSize = n2; const { context: a2 } = this; if (a2.bindFramebuffer(a2.FRAMEBUFFER, this.framebuffer), this.updateMaxTexSize(), this.framebuffer.width = this.texSize[0], this.framebuffer.height = this.texSize[1], a2.viewport(0, 0, this.maxTexSize[0], this.maxTexSize[1]), this.canvas.width = this.maxTexSize[0], this.canvas.height = this.maxTexSize[1], this.texture && this.texture.delete(), this.texture = null, this._setupOutputTexture(), this.mappedTextures && this.mappedTextures.length > 0) { for (let e3 = 0; e3 < this.mappedTextures.length; e3++) this.mappedTextures[e3].delete(); this.mappedTextures = null, this._setupSubOutputTextures(); } } else this.output = t2; return this; } renderValues() { return this.formatValues(this.transferValues(), this.output[0], this.output[1], this.output[2]); } switchKernels(e2) { this.switchingKernels ? this.switchingKernels.push(e2) : this.switchingKernels = [e2]; } getVariablePrecisionString(e2 = this.texSize, t2 = this.tactic, r2 = false) { if (!t2) { if (!this.constructor.features.isSpeedTacticSupported) return "highp"; const t3 = this.constructor.features[r2 ? "lowIntPrecision" : "lowFloatPrecision"], n2 = this.constructor.features[r2 ? "mediumIntPrecision" : "mediumFloatPrecision"], i2 = this.constructor.features[r2 ? "highIntPrecision" : "highFloatPrecision"], s2 = Math.log2(e2[0] * e2[1]); if (s2 <= t3.rangeMax) return "lowp"; if (s2 <= n2.rangeMax) return "mediump"; if (s2 <= i2.rangeMax) return "highp"; throw new Error("The required size exceeds that of the ability of your system"); } switch (t2) { case "speed": return "lowp"; case "balanced": return "mediump"; case "precision": return "highp"; default: throw new Error(`Unknown tactic "${t2}" use "speed", "balanced", "precision", or empty for auto`); } } updateTextureArgumentRefs(e2, t2) { if (this.immutable) { if (this.texture.texture === t2.texture) { const { prevArg: r2 } = e2; r2 && (1 === r2.texture._refs && (this.texture.delete(), this.texture = r2.clone(), this._textureSwitched = true), r2.delete()), e2.prevArg = t2.clone(); } else if (this.mappedTextures && this.mappedTextures.length > 0) { const { mappedTextures: r2 } = this; for (let n2 = 0; n2 < r2.length; n2++) { const i2 = r2[n2]; if (i2.texture === t2.texture) { const { prevArg: s2 } = e2; return s2 && (1 === s2.texture._refs && (i2.delete(), r2[n2] = s2.clone(), this._mappedTextureSwitched[n2] = true), s2.delete()), void (e2.prevArg = t2.clone()); } } } } } onActivate(e2) { if (this._textureSwitched = true, this.texture = e2.texture, this.mappedTextures) { for (let e3 = 0; e3 < this.mappedTextures.length; e3++) this._mappedTextureSwitched[e3] = true; this.mappedTextures = e2.mappedTextures; } } initCanvas() { } } }; }, { "../../utils": 114, "../kernel": 36, "./texture/array-2-float": 16, "./texture/array-2-float-2d": 14, "./texture/array-2-float-3d": 15, "./texture/array-3-float": 19, "./texture/array-3-float-2d": 17, "./texture/array-3-float-3d": 18, "./texture/array-4-float": 22, "./texture/array-4-float-2d": 20, "./texture/array-4-float-3d": 21, "./texture/float": 25, "./texture/float-2d": 23, "./texture/float-3d": 24, "./texture/graphical": 26, "./texture/memory-optimized": 30, "./texture/memory-optimized-2d": 28, "./texture/memory-optimized-3d": 29, "./texture/unsigned": 33, "./texture/unsigned-2d": 31, "./texture/unsigned-3d": 32 }], 14: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureArray2Float2D: class extends i { constructor(e2) { super(e2), this.type = "ArrayTexture(2)"; } toArray() { return n.erect2DArray2(this.renderValues(), this.output[0], this.output[1]); } } }; }, { "../../../utils": 114, "./float": 25 }], 15: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureArray2Float3D: class extends i { constructor(e2) { super(e2), this.type = "ArrayTexture(2)"; } toArray() { return n.erect3DArray2(this.renderValues(), this.output[0], this.output[1], this.output[2]); } } }; }, { "../../../utils": 114, "./float": 25 }], 16: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureArray2Float: class extends i { constructor(e2) { super(e2), this.type = "ArrayTexture(2)"; } toArray() { return n.erectArray2(this.renderValues(), this.output[0], this.output[1]); } } }; }, { "../../../utils": 114, "./float": 25 }], 17: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureArray3Float2D: class extends i { constructor(e2) { super(e2), this.type = "ArrayTexture(3)"; } toArray() { return n.erect2DArray3(this.renderValues(), this.output[0], this.output[1]); } } }; }, { "../../../utils": 114, "./float": 25 }], 18: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureArray3Float3D: class extends i { constructor(e2) { super(e2), this.type = "ArrayTexture(3)"; } toArray() { return n.erect3DArray3(this.renderValues(), this.output[0], this.output[1], this.output[2]); } } }; }, { "../../../utils": 114, "./float": 25 }], 19: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureArray3Float: class extends i { constructor(e2) { super(e2), this.type = "ArrayTexture(3)"; } toArray() { return n.erectArray3(this.renderValues(), this.output[0]); } } }; }, { "../../../utils": 114, "./float": 25 }], 20: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureArray4Float2D: class extends i { constructor(e2) { super(e2), this.type = "ArrayTexture(4)"; } toArray() { return n.erect2DArray4(this.renderValues(), this.output[0], this.output[1]); } } }; }, { "../../../utils": 114, "./float": 25 }], 21: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureArray4Float3D: class extends i { constructor(e2) { super(e2), this.type = "ArrayTexture(4)"; } toArray() { return n.erect3DArray4(this.renderValues(), this.output[0], this.output[1], this.output[2]); } } }; }, { "../../../utils": 114, "./float": 25 }], 22: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureArray4Float: class extends i { constructor(e2) { super(e2), this.type = "ArrayTexture(4)"; } toArray() { return n.erectArray4(this.renderValues(), this.output[0]); } } }; }, { "../../../utils": 114, "./float": 25 }], 23: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureFloat2D: class extends i { constructor(e2) { super(e2), this.type = "ArrayTexture(1)"; } toArray() { return n.erect2DFloat(this.renderValues(), this.output[0], this.output[1]); } } }; }, { "../../../utils": 114, "./float": 25 }], 24: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureFloat3D: class extends i { constructor(e2) { super(e2), this.type = "ArrayTexture(1)"; } toArray() { return n.erect3DFloat(this.renderValues(), this.output[0], this.output[1], this.output[2]); } } }; }, { "../../../utils": 114, "./float": 25 }], 25: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTexture: i } = e("./index"); t.exports = { GLTextureFloat: class extends i { get textureType() { return this.context.FLOAT; } constructor(e2) { super(e2), this.type = "ArrayTexture(1)"; } renderRawOutput() { const e2 = this.context, t2 = this.size; e2.bindFramebuffer(e2.FRAMEBUFFER, this.framebuffer()), e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0, e2.TEXTURE_2D, this.texture, 0); const r2 = new Float32Array(t2[0] * t2[1] * 4); return e2.readPixels(0, 0, t2[0], t2[1], e2.RGBA, e2.FLOAT, r2), r2; } renderValues() { return this._deleted ? null : this.renderRawOutput(); } toArray() { return n.erectFloat(this.renderValues(), this.output[0]); } } }; }, { "../../../utils": 114, "./index": 27 }], 26: [function(e, t, r) { const { GLTextureUnsigned: n } = e("./unsigned"); t.exports = { GLTextureGraphical: class extends n { constructor(e2) { super(e2), this.type = "ArrayTexture(4)"; } toArray() { return this.renderValues(); } } }; }, { "./unsigned": 33 }], 27: [function(e, t, r) { const { Texture: n } = e("../../../texture"); function i(e2, t2) { e2.activeTexture(e2.TEXTURE15), e2.bindTexture(e2.TEXTURE_2D, t2), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_WRAP_S, e2.CLAMP_TO_EDGE), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_WRAP_T, e2.CLAMP_TO_EDGE), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_MIN_FILTER, e2.NEAREST), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_MAG_FILTER, e2.NEAREST); } t.exports = { GLTexture: class extends n { get textureType() { throw new Error(`"textureType" not implemented on ${this.name}`); } clone() { return new this.constructor(this); } beforeMutate() { return this.texture._refs > 1 && (this.newTexture(), true); } cloneTexture() { this.texture._refs--; const { context: e2, size: t2, texture: r2, kernel: n2 } = this; n2.debug && console.warn("cloning internal texture"), e2.bindFramebuffer(e2.FRAMEBUFFER, this.framebuffer()), i(e2, r2), e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0, e2.TEXTURE_2D, r2, 0); const s = e2.createTexture(); i(e2, s), e2.texImage2D(e2.TEXTURE_2D, 0, this.internalFormat, t2[0], t2[1], 0, this.textureFormat, this.textureType, null), e2.copyTexSubImage2D(e2.TEXTURE_2D, 0, 0, 0, 0, 0, t2[0], t2[1]), s._refs = 1, this.texture = s; } newTexture() { this.texture._refs--; const e2 = this.context, t2 = this.size; this.kernel.debug && console.warn("new internal texture"); const r2 = e2.createTexture(); i(e2, r2), e2.texImage2D(e2.TEXTURE_2D, 0, this.internalFormat, t2[0], t2[1], 0, this.textureFormat, this.textureType, null), r2._refs = 1, this.texture = r2; } clear() { if (this.texture._refs) { this.texture._refs--; const e3 = this.context, t3 = this.texture = e3.createTexture(); i(e3, t3); const r2 = this.size; t3._refs = 1, e3.texImage2D(e3.TEXTURE_2D, 0, this.internalFormat, r2[0], r2[1], 0, this.textureFormat, this.textureType, null); } const { context: e2, texture: t2 } = this; e2.bindFramebuffer(e2.FRAMEBUFFER, this.framebuffer()), e2.bindTexture(e2.TEXTURE_2D, t2), i(e2, t2), e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0, e2.TEXTURE_2D, t2, 0), e2.clearColor(0, 0, 0, 0), e2.clear(e2.COLOR_BUFFER_BIT | e2.DEPTH_BUFFER_BIT); } delete() { this._deleted || (this._deleted = true, this.texture._refs && (this.texture._refs--, this.texture._refs) || this.context.deleteTexture(this.texture)); } framebuffer() { return this._framebuffer || (this._framebuffer = this.kernel.getRawValueFramebuffer(this.size[0], this.size[1])), this._framebuffer; } } }; }, { "../../../texture": 113 }], 28: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureMemoryOptimized2D: class extends i { constructor(e2) { super(e2), this.type = "MemoryOptimizedNumberTexture"; } toArray() { return n.erectMemoryOptimized2DFloat(this.renderValues(), this.output[0], this.output[1]); } } }; }, { "../../../utils": 114, "./float": 25 }], 29: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureMemoryOptimized3D: class extends i { constructor(e2) { super(e2), this.type = "MemoryOptimizedNumberTexture"; } toArray() { return n.erectMemoryOptimized3DFloat(this.renderValues(), this.output[0], this.output[1], this.output[2]); } } }; }, { "../../../utils": 114, "./float": 25 }], 30: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureFloat: i } = e("./float"); t.exports = { GLTextureMemoryOptimized: class extends i { constructor(e2) { super(e2), this.type = "MemoryOptimizedNumberTexture"; } toArray() { return n.erectMemoryOptimizedFloat(this.renderValues(), this.output[0]); } } }; }, { "../../../utils": 114, "./float": 25 }], 31: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureUnsigned: i } = e("./unsigned"); t.exports = { GLTextureUnsigned2D: class extends i { constructor(e2) { super(e2), this.type = "NumberTexture"; } toArray() { return n.erect2DPackedFloat(this.renderValues(), this.output[0], this.output[1]); } } }; }, { "../../../utils": 114, "./unsigned": 33 }], 32: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTextureUnsigned: i } = e("./unsigned"); t.exports = { GLTextureUnsigned3D: class extends i { constructor(e2) { super(e2), this.type = "NumberTexture"; } toArray() { return n.erect3DPackedFloat(this.renderValues(), this.output[0], this.output[1], this.output[2]); } } }; }, { "../../../utils": 114, "./unsigned": 33 }], 33: [function(e, t, r) { const { utils: n } = e("../../../utils"), { GLTexture: i } = e("./index"); t.exports = { GLTextureUnsigned: class extends i { get textureType() { return this.context.UNSIGNED_BYTE; } constructor(e2) { super(e2), this.type = "NumberTexture"; } renderRawOutput() { const { context: e2 } = this; e2.bindFramebuffer(e2.FRAMEBUFFER, this.framebuffer()), e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0, e2.TEXTURE_2D, this.texture, 0); const t2 = new Uint8Array(this.size[0] * this.size[1] * 4); return e2.readPixels(0, 0, this.size[0], this.size[1], e2.RGBA, e2.UNSIGNED_BYTE, t2), t2; } renderValues() { return this._deleted ? null : new Float32Array(this.renderRawOutput().buffer); } toArray() { return n.erectPackedFloat(this.renderValues(), this.output[0]); } } }; }, { "../../../utils": 114, "./index": 27 }], 34: [function(e, t, r) { const n = e("gl"), { WebGLKernel: i } = e("../web-gl/kernel"), { glKernelString: s } = e("../gl/kernel-string"); let a = null, o = null, u = null, l = null, h = null; t.exports = { HeadlessGLKernel: class extends i { static get isSupported() { return null !== a || (this.setupFeatureChecks(), a = null !== u), a; } static setupFeatureChecks() { if (o = null, l = null, "function" == typeof n) try { if (u = n(2, 2, { preserveDrawingBuffer: true }), !u || !u.getExtension) return; l = { STACKGL_resize_drawingbuffer: u.getExtension("STACKGL_resize_drawingbuffer"), STACKGL_destroy_context: u.getExtension("STACKGL_destroy_context"), OES_texture_float: u.getExtension("OES_texture_float"), OES_texture_float_linear: u.getExtension("OES_texture_float_linear"), OES_element_index_uint: u.getExtension("OES_element_index_uint"), WEBGL_draw_buffers: u.getExtension("WEBGL_draw_buffers"), WEBGL_color_buffer_float: u.getExtension("WEBGL_color_buffer_float") }, h = this.getFeatures(); } catch (e2) { console.warn(e2); } } static isContextMatch(e2) { try { return "ANGLE" === e2.getParameter(e2.RENDERER); } catch (e3) { return false; } } static getIsTextureFloat() { return Boolean(l.OES_texture_float); } static getIsDrawBuffers() { return Boolean(l.WEBGL_draw_buffers); } static getChannelCount() { return l.WEBGL_draw_buffers ? u.getParameter(l.WEBGL_draw_buffers.MAX_DRAW_BUFFERS_WEBGL) : 1; } static getMaxTextureSize() { return u.getParameter(u.MAX_TEXTURE_SIZE); } static get testCanvas() { return o; } static get testContext() { return u; } static get features() { return h; } initCanvas() { return {}; } initContext() { return n(2, 2, { preserveDrawingBuffer: true }); } initExtensions() { this.extensions = { STACKGL_resize_drawingbuffer: this.context.getExtension("STACKGL_resize_drawingbuffer"), STACKGL_destroy_context: this.context.getExtension("STACKGL_destroy_context"), OES_texture_float: this.context.getExtension("OES_texture_float"), OES_texture_float_linear: this.context.getExtension("OES_texture_float_linear"), OES_element_index_uint: this.context.getExtension("OES_element_index_uint"), WEBGL_draw_buffers: this.context.getExtension("WEBGL_draw_buffers") }; } build() { super.build.apply(this, arguments), this.fallbackRequested || this.extensions.STACKGL_resize_drawingbuffer.resize(this.maxTexSize[0], this.maxTexSize[1]); } destroyExtensions() { this.extensions.STACKGL_resize_drawingbuffer = null, this.extensions.STACKGL_destroy_context = null, this.extensions.OES_texture_float = null, this.extensions.OES_texture_float_linear = null, this.extensions.OES_element_index_uint = null, this.extensions.WEBGL_draw_buffers = null; } static destroyContext(e2) { const t2 = e2.getExtension("STACKGL_destroy_context"); t2 && t2.destroy && t2.destroy(); } toString() { return s(this.constructor, arguments, this, "const gl = context || require('gl')(1, 1);\n", " if (!context) { gl.getExtension('STACKGL_destroy_context').destroy(); }\n"); } setOutput(e2) { return super.setOutput(e2), this.graphical && this.extensions.STACKGL_resize_drawingbuffer && this.extensions.STACKGL_resize_drawingbuffer.resize(this.maxTexSize[0], this.maxTexSize[1]), this; } } }; }, { "../gl/kernel-string": 12, "../web-gl/kernel": 70, gl: 2 }], 35: [function(e, t, r) { t.exports = { KernelValue: class { constructor(e2, t2) { const { name: r2, kernel: n, context: i, checkContext: s, onRequestContextHandle: a, onUpdateValueMismatch: o, origin: u, strictIntegers: l, type: h, tactic: c } = t2; if (!r2) throw new Error("name not set"); if (!h) throw new Error("type not set"); if (!u) throw new Error("origin not set"); if ("user" !== u && "constants" !== u) throw new Error(`origin must be "user" or "constants" value is "${u}"`); if (!a) throw new Error("onRequestContextHandle is not set"); this.name = r2, this.origin = u, this.tactic = c, this.varName = "constants" === u ? `constants.${r2}` : r2, this.kernel = n, this.strictIntegers = l, this.type = e2.type || h, this.size = e2.size || null, this.index = null, this.context = i, this.checkContext = null == s || s, this.contextHandle = null, this.onRequestContextHandle = a, this.onUpdateValueMismatch = o, this.forceUploadEachRun = null; } get id() { return `${this.origin}_${name}`; } getSource() { throw new Error(`"getSource" not defined on ${this.constructor.name}`); } updateValue(e2) { throw new Error(`"updateValue" not defined on ${this.constructor.name}`); } } }; }, {}], 36: [function(e, t, r) { const { utils: n } = e("../utils"), { Input: i } = e("../input"); t.exports = { Kernel: class { static get isSupported() { throw new Error(`"isSupported" not implemented on ${this.name}`); } static isContextMatch(e2) { throw new Error(`"isContextMatch" not implemented on ${this.name}`); } static getFeatures() { throw new Error(`"getFeatures" not implemented on ${this.name}`); } static destroyContext(e2) { throw new Error(`"destroyContext" called on ${this.name}`); } static nativeFunctionArguments() { throw new Error(`"nativeFunctionArguments" called on ${this.name}`); } static nativeFunctionReturnType() { throw new Error(`"nativeFunctionReturnType" called on ${this.name}`); } static combineKernels() { throw new Error(`"combineKernels" called on ${this.name}`); } constructor(e2, t2) { if ("object" != typeof e2) { if ("string" != typeof e2) throw new Error("source not a string"); if (!n.isFunctionString(e2)) throw new Error("source not a function string"); } this.useLegacyEncoder = false, this.fallbackRequested = false, this.onRequestFallback = null, this.argumentNames = "string" == typeof e2 ? n.getArgumentNamesFromString(e2) : null, this.argumentTypes = null, this.argumentSizes = null, this.argumentBitRatios = null, this.kernelArguments = null, this.kernelConstants = null, this.forceUploadKernelConstants = null, this.source = e2, this.output = null, this.debug = false, this.graphical = false, this.loopMaxIterations = 0, this.constants = null, this.constantTypes = null, this.constantBitRatios = null, this.dynamicArguments = false, this.dynamicOutput = false, this.canvas = null, this.context = null, this.checkContext = null, this.gpu = null, this.functions = null, this.nativeFunctions = null, this.injectedNative = null, this.subKernels = null, this.validate = true, this.immutable = false, this.pipeline = false, this.precision = null, this.tactic = null, this.plugins = null, this.returnType = null, this.leadingReturnStatement = null, this.followingReturnStatement = null, this.optimizeFloatMemory = null, this.strictIntegers = false, this.fixIntegerDivisionAccuracy = null, this.built = false, this.signature = null; } mergeSettings(e2) { for (let t2 in e2) if (e2.hasOwnProperty(t2) && this.hasOwnProperty(t2)) { switch (t2) { case "output": if (!Array.isArray(e2.output)) { this.setOutput(e2.output); continue; } break; case "functions": this.functions = []; for (let t3 = 0; t3 < e2.functions.length; t3++) this.addFunction(e2.functions[t3]); continue; case "graphical": e2[t2] && !e2.hasOwnProperty("precision") && (this.precision = "unsigned"), this[t2] = e2[t2]; continue; case "nativeFunctions": if (!e2.nativeFunctions) continue; this.nativeFunctions = []; for (let t3 = 0; t3 < e2.nativeFunctions.length; t3++) { const r2 = e2.nativeFunctions[t3], { name: n2, source: i2 } = r2; this.addNativeFunction(n2, i2, r2); } continue; } this[t2] = e2[t2]; } this.canvas || (this.canvas = this.initCanvas()), this.context || (this.context = this.initContext()), this.plugins || (this.plugins = this.initPlugins(e2)); } build() { throw new Error(`"build" not defined on ${this.constructor.name}`); } run() { throw new Error(`"run" not defined on ${this.constructor.name}`); } initCanvas() { throw new Error(`"initCanvas" not defined on ${this.constructor.name}`); } initContext() { throw new Error(`"initContext" not defined on ${this.constructor.name}`); } initPlugins(e2) { throw new Error(`"initPlugins" not defined on ${this.constructor.name}`); } addFunction(e2, t2 = {}) { if (e2.name && e2.source && e2.argumentTypes && "returnType" in e2) this.functions.push(e2); else if ("settings" in e2 && "source" in e2) this.functions.push(this.functionToIGPUFunction(e2.source, e2.settings)); else { if ("string" != typeof e2 && "function" != typeof e2) throw new Error("function not properly defined"); this.functions.push(this.functionToIGPUFunction(e2, t2)); } return this; } addNativeFunction(e2, t2, r2 = {}) { const { argumentTypes: n2, argumentNames: i2 } = r2.argumentTypes ? function(e3) { const t3 = Object.keys(e3), r3 = []; for (let n3 = 0; n3 < t3.length; n3++) { const i3 = t3[n3]; r3.push(e3[i3]); } return { argumentTypes: r3, argumentNames: t3 }; }(r2.argumentTypes) : this.constructor.nativeFunctionArguments(t2) || {}; return this.nativeFunctions.push({ name: e2, source: t2, settings: r2, argumentTypes: n2, argumentNames: i2, returnType: r2.returnType || this.constructor.nativeFunctionReturnType(t2) }), this; } setupArguments(e2) { if (this.kernelArguments = [], this.argumentTypes) for (let e3 = 0; e3 < this.argumentTypes.length; e3++) this.kernelArguments.push({ type: this.argumentTypes[e3] }); else if (!this.argumentTypes) { this.argumentTypes = []; for (let t2 = 0; t2 < e2.length; t2++) { const r2 = n.getVariableType(e2[t2], this.strictIntegers), i2 = "Integer" === r2 ? "Number" : r2; this.argumentTypes.push(i2), this.kernelArguments.push({ type: i2 }); } } this.argumentSizes = new Array(e2.length), this.argumentBitRatios = new Int32Array(e2.length); for (let t2 = 0; t2 < e2.length; t2++) { const r2 = e2[t2]; this.argumentSizes[t2] = r2.constructor === i ? r2.size : null, this.argumentBitRatios[t2] = this.getBitRatio(r2); } if (this.argumentNames.length !== e2.length) throw new Error("arguments are miss-aligned"); } setupConstants() { this.kernelConstants = []; let e2 = null === this.constantTypes; if (e2 && (this.constantTypes = {}), this.constantBitRatios = {}, this.constants) for (let t2 in this.constants) { if (e2) { const e3 = n.getVariableType(this.constants[t2], this.strictIntegers); this.constantTypes[t2] = e3, this.kernelConstants.push({ name: t2, type: e3 }); } else this.kernelConstants.push({ name: t2, type: this.constantTypes[t2] }); this.constantBitRatios[t2] = this.getBitRatio(this.constants[t2]); } } setOptimizeFloatMemory(e2) { return this.optimizeFloatMemory = e2, this; } toKernelOutput(e2) { return e2.hasOwnProperty("x") ? e2.hasOwnProperty("y") ? e2.hasOwnProperty("z") ? [e2.x, e2.y, e2.z] : [e2.x, e2.y] : [e2.x] : e2; } setOutput(e2) { return this.output = this.toKernelOutput(e2), this; } setDebug(e2) { return this.debug = e2, this; } setGraphical(e2) { return this.graphical = e2, this.precision = "unsigned", this; } setLoopMaxIterations(e2) { return this.loopMaxIterations = e2, this; } setConstants(e2) { return this.constants = e2, this; } setConstantTypes(e2) { return this.constantTypes = e2, this; } setFunctions(e2) { for (let t2 = 0; t2 < e2.length; t2++) this.addFunction(e2[t2]); return this; } setNativeFunctions(e2) { for (let t2 = 0; t2 < e2.length; t2++) { const r2 = e2[t2], { name: n2, source: i2 } = r2; this.addNativeFunction(n2, i2, r2); } return this; } setInjectedNative(e2) { return this.injectedNative = e2, this; } setPipeline(e2) { return this.pipeline = e2, this; } setPrecision(e2) { return this.precision = e2, this; } setDimensions(e2) { return n.warnDeprecated("method", "setDimensions", "setOutput"), this.output = e2, this; } setOutputToTexture(e2) { return n.warnDeprecated("method", "setOutputToTexture", "setPipeline"), this.pipeline = e2, this; } setImmutable(e2) { return this.immutable = e2, this; } setCanvas(e2) { return this.canvas = e2, this; } setStrictIntegers(e2) { return this.strictIntegers = e2, this; } setDynamicOutput(e2) { return this.dynamicOutput = e2, this; } setHardcodeConstants(e2) { return n.warnDeprecated("method", "setHardcodeConstants"), this.setDynamicOutput(e2), this.setDynamicArguments(e2), this; } setDynamicArguments(e2) { return this.dynamicArguments = e2, this; } setUseLegacyEncoder(e2) { return this.useLegacyEncoder = e2, this; } setWarnVarUsage(e2) { return n.warnDeprecated("method", "setWarnVarUsage"), this; } getCanvas() { return n.warnDeprecated("method", "getCanvas"), this.canvas; } getWebGl() { return n.warnDeprecated("method", "getWebGl"), this.context; } setContext(e2) { return this.context = e2, this; } setArgumentTypes(e2) { if (Array.isArray(e2)) this.argumentTypes = e2; else { this.argumentTypes = []; for (const t2 in e2) { if (!e2.hasOwnProperty(t2)) continue; const r2 = this.argumentNames.indexOf(t2); if (-1 === r2) throw new Error(`unable to find argument ${t2}`); this.argumentTypes[r2] = e2[t2]; } } return this; } setTactic(e2) { return this.tactic = e2, this; } requestFallback(e2) { if (!this.onRequestFallback) throw new Error(`"onRequestFallback" not defined on ${this.constructor.name}`); return this.fallbackRequested = true, this.onRequestFallback(e2); } validateSettings() { throw new Error(`"validateSettings" not defined on ${this.constructor.name}`); } addSubKernel(e2) { if (null === this.subKernels && (this.subKernels = []), !e2.source) throw new Error('subKernel missing "source" property'); if (!e2.property && isNaN(e2.property)) throw new Error('subKernel missing "property" property'); if (!e2.name) throw new Error('subKernel missing "name" property'); return this.subKernels.push(e2), this; } destroy(e2) { throw new Error(`"destroy" called on ${this.constructor.name}`); } getBitRatio(e2) { if ("single" === this.precision) return 4; if (Array.isArray(e2[0])) return this.getBitRatio(e2[0]); if (e2.constructor === i) return this.getBitRatio(e2.value); switch (e2.constructor) { case Uint8ClampedArray: case Uint8Array: case Int8Array: return 1; case Uint16Array: case Int16Array: return 2; case Float32Array: case Int32Array: default: return 4; } } getPixels(e2) { throw new Error(`"getPixels" called on ${this.constructor.name}`); } checkOutput() { if (!this.output || !n.isArray(this.output)) throw new Error("kernel.output not an array"); if (this.output.length < 1) throw new Error("kernel.output is empty, needs at least 1 value"); for (let e2 = 0; e2 < this.output.length; e2++) if (isNaN(this.output[e2]) || this.output[e2] < 1) throw new Error(`${this.constructor.name}.output[${e2}] incorrectly defined as \`${this.output[e2]}\`, needs to be numeric, and greater than 0`); } prependString(e2) { throw new Error(`"prependString" called on ${this.constructor.name}`); } hasPrependString(e2) { throw new Error(`"hasPrependString" called on ${this.constructor.name}`); } toJSON() { return { settings: { output: this.output, pipeline: this.pipeline, argumentNames: this.argumentNames, argumentsTypes: this.argumentTypes, constants: this.constants, pluginNames: this.plugins ? this.plugins.map((e2) => e2.name) : null, returnType: this.returnType } }; } buildSignature(e2) { const t2 = this.constructor; this.signature = t2.getSignature(this, t2.getArgumentTypes(this, e2)); } static getArgumentTypes(e2, t2) { const r2 = new Array(t2.length); for (let i2 = 0; i2 < t2.length; i2++) { const s = t2[i2], a = e2.argumentTypes[i2]; if (s.type) r2[i2] = s.type; else switch (a) { case "Number": case "Integer": case "Float": case "ArrayTexture(1)": r2[i2] = n.getVariableType(s); break; default: r2[i2] = a; } } return r2; } static getSignature(e2, t2) { throw new Error(`"getSignature" not implemented on ${this.name}`); } functionToIGPUFunction(e2, t2 = {}) { if ("string" != typeof e2 && "function" != typeof e2) throw new Error("source not a string or function"); const r2 = "string" == typeof e2 ? e2 : e2.toString(); let i2 = []; return i2 = Array.isArray(t2.argumentTypes) ? t2.argumentTypes : "object" == typeof t2.argumentTypes ? n.getArgumentNamesFromString(r2).map((e3) => t2.argumentTypes[e3]) || [] : t2.argumentTypes || [], { name: n.getFunctionNameFromString(r2) || null, source: r2, argumentTypes: i2, returnType: t2.returnType || null }; } onActivate(e2) { } } }; }, { "../input": 110, "../utils": 114 }], 37: [function(e, t, r) { const n = `__HEADER__; __FLOAT_TACTIC_DECLARATION__; __INT_TACTIC_DECLARATION__; __SAMPLER_2D_TACTIC_DECLARATION__; const int LOOP_MAX = __LOOP_MAX__; __PLUGINS__; __CONSTANTS__; varying vec2 vTexCoord; float acosh(float x) { return log(x + sqrt(x * x - 1.0)); } float sinh(float x) { return (pow(${Math.E}, x) - pow(${Math.E}, -x)) / 2.0; } float asinh(float x) { return log(x + sqrt(x * x + 1.0)); } float atan2(float v1, float v2) { if (v1 == 0.0 || v2 == 0.0) return 0.0; return atan(v1 / v2); } float atanh(float x) { x = (x + 1.0) / (x - 1.0); if (x < 0.0) { return 0.5 * log(-x); } return 0.5 * log(x); } float cbrt(float x) { if (x >= 0.0) { return pow(x, 1.0 / 3.0); } else { return -pow(x, 1.0 / 3.0); } } float cosh(float x) { return (pow(${Math.E}, x) + pow(${Math.E}, -x)) / 2.0; } float expm1(float x) { return pow(${Math.E}, x) - 1.0; } float fround(highp float x) { return x; } float imul(float v1, float v2) { return float(int(v1) * int(v2)); } float log10(float x) { return log2(x) * (1.0 / log2(10.0)); } float log1p(float x) { return log(1.0 + x); } float _pow(float v1, float v2) { if (v2 == 0.0) return 1.0; return pow(v1, v2); } float tanh(float x) { float e = exp(2.0 * x); return (e - 1.0) / (e + 1.0); } float trunc(float x) { if (x >= 0.0) { return floor(x); } else { return ceil(x); } } vec4 _round(vec4 x) { return floor(x + 0.5); } float _round(float x) { return floor(x + 0.5); } const int BIT_COUNT = 32; int modi(int x, int y) { return x - y * (x / y); } int bitwiseOr(int a, int b) { int result = 0; int n = 1; for (int i = 0; i < BIT_COUNT; i++) { if ((modi(a, 2) == 1) || (modi(b, 2) == 1)) { result += n; } a = a / 2; b = b / 2; n = n * 2; if(!(a > 0 || b > 0)) { break; } } return result; } int bitwiseXOR(int a, int b) { int result = 0; int n = 1; for (int i = 0; i < BIT_COUNT; i++) { if ((modi(a, 2) == 1) != (modi(b, 2) == 1)) { result += n; } a = a / 2; b = b / 2; n = n * 2; if(!(a > 0 || b > 0)) { break; } } return result; } int bitwiseAnd(int a, int b) { int result = 0; int n = 1; for (int i = 0; i < BIT_COUNT; i++) { if ((modi(a, 2) == 1) && (modi(b, 2) == 1)) { result += n; } a = a / 2; b = b / 2; n = n * 2; if(!(a > 0 && b > 0)) { break; } } return result; } int bitwiseNot(int a) { int result = 0; int n = 1; for (int i = 0; i < BIT_COUNT; i++) { if (modi(a, 2) == 0) { result += n; } a = a / 2; n = n * 2; } return result; } int bitwiseZeroFillLeftShift(int n, int shift) { int maxBytes = BIT_COUNT; for (int i = 0; i < BIT_COUNT; i++) { if (maxBytes >= n) { break; } maxBytes *= 2; } for (int i = 0; i < BIT_COUNT; i++) { if (i >= shift) { break; } n *= 2; } int result = 0; int byteVal = 1; for (int i = 0; i < BIT_COUNT; i++) { if (i >= maxBytes) break; if (modi(n, 2) > 0) { result += byteVal; } n = int(n / 2); byteVal *= 2; } return result; } int bitwiseSignedRightShift(int num, int shifts) { return int(floor(float(num) / pow(2.0, float(shifts)))); } int bitwiseZeroFillRightShift(int n, int shift) { int maxBytes = BIT_COUNT; for (int i = 0; i < BIT_COUNT; i++) { if (maxBytes >= n) { break; } maxBytes *= 2; } for (int i = 0; i < BIT_COUNT; i++) { if (i >= shift) { break; } n /= 2; } int result = 0; int byteVal = 1; for (int i = 0; i < BIT_COUNT; i++) { if (i >= maxBytes) break; if (modi(n, 2) > 0) { result += byteVal; } n = int(n / 2); byteVal *= 2; } return result; } vec2 integerMod(vec2 x, float y) { vec2 res = floor(mod(x, y)); return res * step(1.0 - floor(y), -res); } vec3 integerMod(vec3 x, float y) { vec3 res = floor(mod(x, y)); return res * step(1.0 - floor(y), -res); } vec4 integerMod(vec4 x, vec4 y) { vec4 res = floor(mod(x, y)); return res * step(1.0 - floor(y), -res); } float integerMod(float x, float y) { float res = floor(mod(x, y)); return res * (res > floor(y) - 1.0 ? 0.0 : 1.0); } int integerMod(int x, int y) { return x - (y * int(x / y)); } __DIVIDE_WITH_INTEGER_CHECK__; // Here be dragons! // DO NOT OPTIMIZE THIS CODE // YOU WILL BREAK SOMETHING ON SOMEBODY'S MACHINE // LEAVE IT AS IT IS, LEST YOU WASTE YOUR OWN TIME const vec2 MAGIC_VEC = vec2(1.0, -256.0); const vec4 SCALE_FACTOR = vec4(1.0, 256.0, 65536.0, 0.0); const vec4 SCALE_FACTOR_INV = vec4(1.0, 0.00390625, 0.0000152587890625, 0.0); // 1, 1/256, 1/65536 float decode32(vec4 texel) { __DECODE32_ENDIANNESS__; texel *= 255.0; vec2 gte128; gte128.x = texel.b >= 128.0 ? 1.0 : 0.0; gte128.y = texel.a >= 128.0 ? 1.0 : 0.0; float exponent = 2.0 * texel.a - 127.0 + dot(gte128, MAGIC_VEC); float res = exp2(_round(exponent)); texel.b = texel.b - 128.0 * gte128.x; res = dot(texel, SCALE_FACTOR) * exp2(_round(exponent-23.0)) + res; res *= gte128.y * -2.0 + 1.0; return res; } float decode16(vec4 texel, int index) { int channel = integerMod(index, 2); if (channel == 0) return texel.r * 255.0 + texel.g * 65280.0; if (channel == 1) return texel.b * 255.0 + texel.a * 65280.0; return 0.0; } float decode8(vec4 texel, int index) { int channel = integerMod(index, 4); if (channel == 0) return texel.r * 255.0; if (channel == 1) return texel.g * 255.0; if (channel == 2) return texel.b * 255.0; if (channel == 3) return texel.a * 255.0; return 0.0; } vec4 legacyEncode32(float f) { float F = abs(f); float sign = f < 0.0 ? 1.0 : 0.0; float exponent = floor(log2(F)); float mantissa = (exp2(-exponent) * F); // exponent += floor(log2(mantissa)); vec4 texel = vec4(F * exp2(23.0-exponent)) * SCALE_FACTOR_INV; texel.rg = integerMod(texel.rg, 256.0); texel.b = integerMod(texel.b, 128.0); texel.a = exponent*0.5 + 63.5; texel.ba += vec2(integerMod(exponent+127.0, 2.0), sign) * 128.0; texel = floor(texel); texel *= 0.003921569; // 1/255 __ENCODE32_ENDIANNESS__; return texel; } // https://github.com/gpujs/gpu.js/wiki/Encoder-details vec4 encode32(float value) { if (value == 0.0) return vec4(0, 0, 0, 0); float exponent; float mantissa; vec4 result; float sgn; sgn = step(0.0, -value); value = abs(value); exponent = floor(log2(value)); mantissa = value*pow(2.0, -exponent)-1.0; exponent = exponent+127.0; result = vec4(0,0,0,0); result.a = floor(exponent/2.0); exponent = exponent - result.a*2.0; result.a = result.a + 128.0*sgn; result.b = floor(mantissa * 128.0); mantissa = mantissa - result.b / 128.0; result.b = result.b + exponent*128.0; result.g = floor(mantissa*32768.0); mantissa = mantissa - result.g/32768.0; result.r = floor(mantissa*8388608.0); return result/255.0; } // Dragons end here int index; ivec3 threadId; ivec3 indexTo3D(int idx, ivec3 texDim) { int z = int(idx / (texDim.x * texDim.y)); idx -= z * int(texDim.x * texDim.y); int y = int(idx / texDim.x); int x = int(integerMod(idx, texDim.x)); return ivec3(x, y, z); } float get32(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + texDim.x * (y + texDim.y * z); int w = texSize.x; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; vec4 texel = texture2D(tex, st / vec2(texSize)); return decode32(texel); } float get16(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + texDim.x * (y + texDim.y * z); int w = texSize.x * 2; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; vec4 texel = texture2D(tex, st / vec2(texSize.x * 2, texSize.y)); return decode16(texel, index); } float get8(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + texDim.x * (y + texDim.y * z); int w = texSize.x * 4; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; vec4 texel = texture2D(tex, st / vec2(texSize.x * 4, texSize.y)); return decode8(texel, index); } float getMemoryOptimized32(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + texDim.x * (y + texDim.y * z); int channel = integerMod(index, 4); index = index / 4; int w = texSize.x; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; vec4 texel = texture2D(tex, st / vec2(texSize)); if (channel == 0) return texel.r; if (channel == 1) return texel.g; if (channel == 2) return texel.b; if (channel == 3) return texel.a; return 0.0; } vec4 getImage2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + texDim.x * (y + texDim.y * z); int w = texSize.x; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; return texture2D(tex, st / vec2(texSize)); } float getFloatFromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { vec4 result = getImage2D(tex, texSize, texDim, z, y, x); return result[0]; } vec2 getVec2FromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { vec4 result = getImage2D(tex, texSize, texDim, z, y, x); return vec2(result[0], result[1]); } vec2 getMemoryOptimizedVec2(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + (texDim.x * (y + (texDim.y * z))); int channel = integerMod(index, 2); index = index / 2; int w = texSize.x; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; vec4 texel = texture2D(tex, st / vec2(texSize)); if (channel == 0) return vec2(texel.r, texel.g); if (channel == 1) return vec2(texel.b, texel.a); return vec2(0.0, 0.0); } vec3 getVec3FromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { vec4 result = getImage2D(tex, texSize, texDim, z, y, x); return vec3(result[0], result[1], result[2]); } vec3 getMemoryOptimizedVec3(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int fieldIndex = 3 * (x + texDim.x * (y + texDim.y * z)); int vectorIndex = fieldIndex / 4; int vectorOffset = fieldIndex - vectorIndex * 4; int readY = vectorIndex / texSize.x; int readX = vectorIndex - readY * texSize.x; vec4 tex1 = texture2D(tex, (vec2(readX, readY) + 0.5) / vec2(texSize)); if (vectorOffset == 0) { return tex1.xyz; } else if (vectorOffset == 1) { return tex1.yzw; } else { readX++; if (readX >= texSize.x) { readX = 0; readY++; } vec4 tex2 = texture2D(tex, vec2(readX, readY) / vec2(texSize)); if (vectorOffset == 2) { return vec3(tex1.z, tex1.w, tex2.x); } else { return vec3(tex1.w, tex2.x, tex2.y); } } } vec4 getVec4FromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { return getImage2D(tex, texSize, texDim, z, y, x); } vec4 getMemoryOptimizedVec4(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + texDim.x * (y + texDim.y * z); int channel = integerMod(index, 2); int w = texSize.x; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; vec4 texel = texture2D(tex, st / vec2(texSize)); return vec4(texel.r, texel.g, texel.b, texel.a); } vec4 actualColor; void color(float r, float g, float b, float a) { actualColor = vec4(r,g,b,a); } void color(float r, float g, float b) { color(r,g,b,1.0); } void color(sampler2D image) { actualColor = texture2D(image, vTexCoord); } float modulo(float number, float divisor) { if (number < 0.0) { number = abs(number); if (divisor < 0.0) { divisor = abs(divisor); } return -mod(number, divisor); } if (divisor < 0.0) { divisor = abs(divisor); } return mod(number, divisor); } __INJECTED_NATIVE__; __MAIN_CONSTANTS__; __MAIN_ARGUMENTS__; __KERNEL__; void main(void) { index = int(vTexCoord.s * float(uTexSize.x)) + int(vTexCoord.t * float(uTexSize.y)) * uTexSize.x; __MAIN_RESULT__; }`; t.exports = { fragmentShader: n }; }, {}], 38: [function(e, t, r) { const { utils: n } = e("../../utils"), { FunctionNode: i } = e("../function-node"); const s = { Array: "sampler2D", "Array(2)": "vec2", "Array(3)": "vec3", "Array(4)": "vec4", "Matrix(2)": "mat2", "Matrix(3)": "mat3", "Matrix(4)": "mat4", Array2D: "sampler2D", Array3D: "sampler2D", Boolean: "bool", Float: "float", Input: "sampler2D", Integer: "int", Number: "float", LiteralInteger: "float", NumberTexture: "sampler2D", MemoryOptimizedNumberTexture: "sampler2D", "ArrayTexture(1)": "sampler2D", "ArrayTexture(2)": "sampler2D", "ArrayTexture(3)": "sampler2D", "ArrayTexture(4)": "sampler2D", HTMLVideo: "sampler2D", HTMLCanvas: "sampler2D", OffscreenCanvas: "sampler2D", HTMLImage: "sampler2D", ImageBitmap: "sampler2D", ImageData: "sampler2D", HTMLImageArray: "sampler2DArray" }, a = { "===": "==", "!==": "!=" }; t.exports = { WebGLFunctionNode: class extends i { constructor(e2, t2) { super(e2, t2), t2 && t2.hasOwnProperty("fixIntegerDivisionAccuracy") && (this.fixIntegerDivisionAccuracy = t2.fixIntegerDivisionAccuracy); } astConditionalExpression(e2, t2) { if ("ConditionalExpression" !== e2.type) throw this.astErrorOutput("Not a conditional expression", e2); const r2 = this.getType(e2.consequent), n2 = this.getType(e2.alternate); return null === r2 && null === n2 ? (t2.push("if ("), this.astGeneric(e2.test, t2), t2.push(") {"), this.astGeneric(e2.consequent, t2), t2.push(";"), t2.push("} else {"), this.astGeneric(e2.alternate, t2), t2.push(";"), t2.push("}"), t2) : (t2.push("("), this.astGeneric(e2.test, t2), t2.push("?"), this.astGeneric(e2.consequent, t2), t2.push(":"), this.astGeneric(e2.alternate, t2), t2.push(")"), t2); } astFunction(e2, t2) { if (this.isRootKernel) t2.push("void"); else { if (!this.returnType) { this.findLastReturn() && (this.returnType = this.getType(e2.body), "LiteralInteger" === this.returnType && (this.returnType = "Number")); } const { returnType: r2 } = this; if (r2) { const e3 = s[r2]; if (!e3) throw new Error(`unknown type ${r2}`); t2.push(e3); } else t2.push("void"); } if (t2.push(" "), t2.push(this.name), t2.push("("), !this.isRootKernel) for (let r2 = 0; r2 < this.argumentNames.length; ++r2) { const i2 = this.argumentNames[r2]; r2 > 0 && t2.push(", "); let a2 = this.argumentTypes[this.argumentNames.indexOf(i2)]; if (!a2) throw this.astErrorOutput(`Unknown argument ${i2} type`, e2); "LiteralInteger" === a2 && (this.argumentTypes[r2] = a2 = "Number"); const o = s[a2]; if (!o) throw this.astErrorOutput("Unexpected expression", e2); const u = n.sanitizeName(i2); "sampler2D" === o || "sampler2DArray" === o ? t2.push(`${o} user_${u},ivec2 user_${u}Size,ivec3 user_${u}Dim`) : t2.push(`${o} user_${u}`); } t2.push(") {\n"); for (let r2 = 0; r2 < e2.body.body.length; ++r2) this.astGeneric(e2.body.body[r2], t2), t2.push("\n"); return t2.push("}\n"), t2; } astReturnStatement(e2, t2) { if (!e2.argument) throw this.astErrorOutput("Unexpected return statement", e2); this.pushState("skip-literal-correction"); const r2 = this.getType(e2.argument); this.popState("skip-literal-correction"); const n2 = []; switch (this.returnType || (this.returnType = "LiteralInteger" === r2 || "Integer" === r2 ? "Number" : r2), this.returnType) { case "LiteralInteger": case "Number": case "Float": switch (r2) { case "Integer": n2.push("float("), this.astGeneric(e2.argument, n2), n2.push(")"); break; case "LiteralInteger": this.castLiteralToFloat(e2.argument, n2), "Integer" === this.getType(e2) && (n2.unshift("float("), n2.push(")")); break; default: this.astGeneric(e2.argument, n2); } break; case "Integer": switch (r2) { case "Float": case "Number": this.castValueToInteger(e2.argument, n2); break; case "LiteralInteger": this.castLiteralToInteger(e2.argument, n2); break; default: this.astGeneric(e2.argument, n2); } break; case "Array(4)": case "Array(3)": case "Array(2)": case "Matrix(2)": case "Matrix(3)": case "Matrix(4)": case "Input": this.astGeneric(e2.argument, n2); break; default: throw this.astErrorOutput(`unhandled return type ${this.returnType}`, e2); } return this.isRootKernel ? (t2.push(`kernelResult = ${n2.join("")};`), t2.push("return;")) : this.isSubKernel ? (t2.push(`subKernelResult_${this.name} = ${n2.join("")};`), t2.push(`return subKernelResult_${this.name};`)) : t2.push(`return ${n2.join("")};`), t2; } astLiteral(e2, t2) { if (isNaN(e2.value)) throw this.astErrorOutput("Non-numeric literal not supported : " + e2.value, e2); const r2 = this.astKey(e2); return Number.isInteger(e2.value) ? this.isState("casting-to-integer") || this.isState("building-integer") ? (this.literalTypes[r2] = "Integer", t2.push(`${e2.value}`)) : (this.isState("casting-to-float") || this.isState("building-float"), this.literalTypes[r2] = "Number", t2.push(`${e2.value}.0`)) : this.isState("casting-to-integer") || this.isState("building-integer") ? (this.literalTypes[r2] = "Integer", t2.push(Math.round(e2.value))) : (this.literalTypes[r2] = "Number", t2.push(`${e2.value}`)), t2; } astBinaryExpression(e2, t2) { if (this.checkAndUpconvertOperator(e2, t2)) return t2; if (this.fixIntegerDivisionAccuracy && "/" === e2.operator) { switch (t2.push("divWithIntCheck("), this.pushState("building-float"), this.getType(e2.left)) { case "Integer": this.castValueToFloat(e2.left, t2); break; case "LiteralInteger": this.castLiteralToFloat(e2.left, t2); break; default: this.astGeneric(e2.left, t2); } switch (t2.push(", "), this.getType(e2.right)) { case "Integer": this.castValueToFloat(e2.right, t2); break; case "LiteralInteger": this.castLiteralToFloat(e2.right, t2); break; default: this.astGeneric(e2.right, t2); } return this.popState("building-float"), t2.push(")"), t2; } t2.push("("); const r2 = this.getType(e2.left) || "Number", n2 = this.getType(e2.right) || "Number"; if (!r2 || !n2) throw this.astErrorOutput("Unhandled binary expression", e2); const i2 = r2 + " & " + n2; switch (i2) { case "Integer & Integer": this.pushState("building-integer"), this.astGeneric(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.astGeneric(e2.right, t2), this.popState("building-integer"); break; case "Number & Float": case "Float & Number": case "Float & Float": case "Number & Number": this.pushState("building-float"), this.astGeneric(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.astGeneric(e2.right, t2), this.popState("building-float"); break; case "LiteralInteger & LiteralInteger": this.isState("casting-to-integer") || this.isState("building-integer") ? (this.pushState("building-integer"), this.astGeneric(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.astGeneric(e2.right, t2), this.popState("building-integer")) : (this.pushState("building-float"), this.castLiteralToFloat(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.castLiteralToFloat(e2.right, t2), this.popState("building-float")); break; case "Integer & Float": case "Integer & Number": if ((">" === e2.operator || "<" === e2.operator && "Literal" === e2.right.type) && !Number.isInteger(e2.right.value)) { this.pushState("building-float"), this.castValueToFloat(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.astGeneric(e2.right, t2), this.popState("building-float"); break; } if (this.pushState("building-integer"), this.astGeneric(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.pushState("casting-to-integer"), "Literal" === e2.right.type) { const r3 = []; this.astGeneric(e2.right, r3); if ("Integer" !== this.getType(e2.right)) throw this.astErrorOutput("Unhandled binary expression with literal", e2); t2.push(r3.join("")); } else t2.push("int("), this.astGeneric(e2.right, t2), t2.push(")"); this.popState("casting-to-integer"), this.popState("building-integer"); break; case "Integer & LiteralInteger": this.pushState("building-integer"), this.astGeneric(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.castLiteralToInteger(e2.right, t2), this.popState("building-integer"); break; case "Number & Integer": case "Float & Integer": this.pushState("building-float"), this.astGeneric(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.castValueToFloat(e2.right, t2), this.popState("building-float"); break; case "Float & LiteralInteger": case "Number & LiteralInteger": this.pushState("building-float"), this.astGeneric(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.castLiteralToFloat(e2.right, t2), this.popState("building-float"); break; case "LiteralInteger & Float": case "LiteralInteger & Number": this.isState("casting-to-integer") ? (this.pushState("building-integer"), this.castLiteralToInteger(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.castValueToInteger(e2.right, t2), this.popState("building-integer")) : (this.pushState("building-float"), this.astGeneric(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.pushState("casting-to-float"), this.astGeneric(e2.right, t2), this.popState("casting-to-float"), this.popState("building-float")); break; case "LiteralInteger & Integer": this.pushState("building-integer"), this.castLiteralToInteger(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.astGeneric(e2.right, t2), this.popState("building-integer"); break; case "Boolean & Boolean": this.pushState("building-boolean"), this.astGeneric(e2.left, t2), t2.push(a[e2.operator] || e2.operator), this.astGeneric(e2.right, t2), this.popState("building-boolean"); break; default: throw this.astErrorOutput(`Unhandled binary expression between ${i2}`, e2); } return t2.push(")"), t2; } checkAndUpconvertOperator(e2, t2) { const r2 = this.checkAndUpconvertBitwiseOperators(e2, t2); if (r2) return r2; const n2 = { "%": this.fixIntegerDivisionAccuracy ? "integerCorrectionModulo" : "modulo", "**": "pow" }[e2.operator]; if (!n2) return null; switch (t2.push(n2), t2.push("("), this.getType(e2.left)) { case "Integer": this.castValueToFloat(e2.left, t2); break; case "LiteralInteger": this.castLiteralToFloat(e2.left, t2); break; default: this.astGeneric(e2.left, t2); } switch (t2.push(","), this.getType(e2.right)) { case "Integer": this.castValueToFloat(e2.right, t2); break; case "LiteralInteger": this.castLiteralToFloat(e2.right, t2); break; default: this.astGeneric(e2.right, t2); } return t2.push(")"), t2; } checkAndUpconvertBitwiseOperators(e2, t2) { const r2 = { "&": "bitwiseAnd", "|": "bitwiseOr", "^": "bitwiseXOR", "<<": "bitwiseZeroFillLeftShift", ">>": "bitwiseSignedRightShift", ">>>": "bitwiseZeroFillRightShift" }[e2.operator]; if (!r2) return null; t2.push(r2), t2.push("("); switch (this.getType(e2.left)) { case "Number": case "Float": this.castValueToInteger(e2.left, t2); break; case "LiteralInteger": this.castLiteralToInteger(e2.left, t2); break; default: this.astGeneric(e2.left, t2); } t2.push(","); switch (this.getType(e2.right)) { case "Number": case "Float": this.castValueToInteger(e2.right, t2); break; case "LiteralInteger": this.castLiteralToInteger(e2.right, t2); break; default: this.astGeneric(e2.right, t2); } return t2.push(")"), t2; } checkAndUpconvertBitwiseUnary(e2, t2) { const r2 = { "~": "bitwiseNot" }[e2.operator]; if (!r2) return null; switch (t2.push(r2), t2.push("("), this.getType(e2.argument)) { case "Number": case "Float": this.castValueToInteger(e2.argument, t2); break; case "LiteralInteger": this.castLiteralToInteger(e2.argument, t2); break; default: this.astGeneric(e2.argument, t2); } return t2.push(")"), t2; } castLiteralToInteger(e2, t2) { return this.pushState("casting-to-integer"), this.astGeneric(e2, t2), this.popState("casting-to-integer"), t2; } castLiteralToFloat(e2, t2) { return this.pushState("casting-to-float"), this.astGeneric(e2, t2), this.popState("casting-to-float"), t2; } castValueToInteger(e2, t2) { return this.pushState("casting-to-integer"), t2.push("int("), this.astGeneric(e2, t2), t2.push(")"), this.popState("casting-to-integer"), t2; } castValueToFloat(e2, t2) { return this.pushState("casting-to-float"), t2.push("float("), this.astGeneric(e2, t2), t2.push(")"), this.popState("casting-to-float"), t2; } astIdentifierExpression(e2, t2) { if ("Identifier" !== e2.type) throw this.astErrorOutput("IdentifierExpression - not an Identifier", e2); const r2 = this.getType(e2), i2 = n.sanitizeName(e2.name); return "Infinity" === e2.name ? t2.push("3.402823466e+38") : "Boolean" === r2 && this.argumentNames.indexOf(i2) > -1 ? t2.push(`bool(user_${i2})`) : t2.push(`user_${i2}`), t2; } astForStatement(e2, t2) { if ("ForStatement" !== e2.type) throw this.astErrorOutput("Invalid for statement", e2); const r2 = [], n2 = [], i2 = [], s2 = []; let a2 = null; if (e2.init) { const { declarations: t3 } = e2.init; t3.length > 1 && (a2 = false), this.astGeneric(e2.init, r2); for (let e3 = 0; e3 < t3.length; e3++) t3[e3].init && "Literal" !== t3[e3].init.type && (a2 = false); } else a2 = false; if (e2.test ? this.astGeneric(e2.test, n2) : a2 = false, e2.update ? this.astGeneric(e2.update, i2) : a2 = false, e2.body && (this.pushState("loop-body"), this.astGeneric(e2.body, s2), this.popState("loop-body")), null === a2 && (a2 = this.isSafe(e2.init) && this.isSafe(e2.test)), a2) { const e3 = r2.join(""), a3 = ";" !== e3[e3.length - 1]; t2.push(`for (${e3}${a3 ? ";" : ""}${n2.join("")};${i2.join("")}){ `), t2.push(s2.join("")), t2.push("}\n"); } else { const e3 = this.getInternalVariableName("safeI"); r2.length > 0 && t2.push(r2.join(""), "\n"), t2.push(`for (int ${e3}=0;${e3}<LOOP_MAX;${e3}++){ `), n2.length > 0 && t2.push(`if (!${n2.join("")}) break; `), t2.push(s2.join("")), t2.push(` ${i2.join("")};`), t2.push("}\n"); } return t2; } astWhileStatement(e2, t2) { if ("WhileStatement" !== e2.type) throw this.astErrorOutput("Invalid while statement", e2); const r2 = this.getInternalVariableName("safeI"); return t2.push(`for (int ${r2}=0;${r2}<LOOP_MAX;${r2}++){ `), t2.push("if (!"), this.astGeneric(e2.test, t2), t2.push(") break;\n"), this.astGeneric(e2.body, t2), t2.push("}\n"), t2; } astDoWhileStatement(e2, t2) { if ("DoWhileStatement" !== e2.type) throw this.astErrorOutput("Invalid while statement", e2); const r2 = this.getInternalVariableName("safeI"); return t2.push(`for (int ${r2}=0;${r2}<LOOP_MAX;${r2}++){ `), this.astGeneric(e2.body, t2), t2.push("if (!"), this.astGeneric(e2.test, t2), t2.push(") break;\n"), t2.push("}\n"), t2; } astAssignmentExpression(e2, t2) { if ("%=" === e2.operator) this.astGeneric(e2.left, t2), t2.push("="), t2.push("mod("), this.astGeneric(e2.left, t2), t2.push(","), this.astGeneric(e2.right, t2), t2.push(")"); else { if ("**=" !== e2.operator) { const r2 = this.getType(e2.left), n2 = this.getType(e2.right); return this.astGeneric(e2.left, t2), t2.push(e2.operator), "Integer" !== r2 && "Integer" === n2 ? (t2.push("float("), this.astGeneric(e2.right, t2), t2.push(")")) : this.astGeneric(e2.right, t2), t2; } this.astGeneric(e2.left, t2), t2.push("="), t2.push("pow("), this.astGeneric(e2.left, t2), t2.push(","), this.astGeneric(e2.right, t2), t2.push(")"); } } astBlockStatement(e2, t2) { if (this.isState("loop-body")) { this.pushState("block-body"); for (let r2 = 0; r2 < e2.body.length; r2++) this.astGeneric(e2.body[r2], t2); this.popState("block-body"); } else { t2.push("{\n"); for (let r2 = 0; r2 < e2.body.length; r2++) this.astGeneric(e2.body[r2], t2); t2.push("}\n"); } return t2; } astVariableDeclaration(e2, t2) { const r2 = e2.declarations; if (!r2 || !r2[0] || !r2[0].init) throw this.astErrorOutput("Unexpected expression", e2); const i2 = []; let a2 = null; const o = []; let u = []; for (let t3 = 0; t3 < r2.length; t3++) { const i3 = r2[t3], l = i3.init, h = this.getDeclaration(i3.id), c = this.getType(i3.init); let p = c; "LiteralInteger" === p && (p = "Integer" === h.suggestedType ? "Integer" : "Number"); const d = s[p]; if (!d) throw this.astErrorOutput(`Markup type ${p} not handled`, e2); const m = []; if ("Integer" === c && "Integer" === p) { if (h.valueType = "Number", 0 === t3 || null === a2) m.push("float "); else if (p !== a2) throw new Error("Unhandled declaration"); a2 = p, m.push(`user_${n.sanitizeName(i3.id.name)}=`), m.push("float("), this.astGeneric(l, m), m.push(")"); } else h.valueType = p, 0 === t3 || null === a2 ? m.push(`${d} `) : p !== a2 && (o.push(u.join(",")), u = [], m.push(`${d} `)), a2 = p, m.push(`user_${n.sanitizeName(i3.id.name)}=`), "Number" === c && "Integer" === p ? l.left && "Literal" === l.left.type ? this.astGeneric(l, m) : (m.push("int("), this.astGeneric(l, m), m.push(")")) : "LiteralInteger" === c && "Integer" === p ? this.castLiteralToInteger(l, m) : this.astGeneric(l, m); u.push(m.join("")); } return u.length > 0 && o.push(u.join(",")), i2.push(o.join(";")), t2.push(i2.join("")), t2.push(";"), t2; } astIfStatement(e2, t2) { return t2.push("if ("), this.astGeneric(e2.test, t2), t2.push(")"), "BlockStatement" === e2.consequent.type ? this.astGeneric(e2.consequent, t2) : (t2.push(" {\n"), this.astGeneric(e2.consequent, t2), t2.push("\n}\n")), e2.alternate && (t2.push("else "), "BlockStatement" === e2.alternate.type || "IfStatement" === e2.alternate.type ? this.astGeneric(e2.alternate, t2) : (t2.push(" {\n"), this.astGeneric(e2.alternate, t2), t2.push("\n}\n"))), t2; } astSwitchStatement(e2, t2) { if ("SwitchStatement" !== e2.type) throw this.astErrorOutput("Invalid switch statement", e2); const { discriminant: r2, cases: n2 } = e2, i2 = this.getType(r2), s2 = `switchDiscriminant${this.astKey(e2, "_")}`; switch (i2) { case "Float": case "Number": t2.push(`float ${s2} = `), this.astGeneric(r2, t2), t2.push(";\n"); break; case "Integer": t2.push(`int ${s2} = `), this.astGeneric(r2, t2), t2.push(";\n"); } if (1 === n2.length && !n2[0].test) return this.astGeneric(n2[0].consequent, t2), t2; let a2 = false, o = [], u = false, l = false; for (let e3 = 0; e3 < n2.length; e3++) { if (n2[e3].test) { if (0 !== e3 && l ? a2 ? (t2.push(`${s2} == `), a2 = false) : t2.push(` else if (${s2} == `) : (l = true, t2.push(`if (${s2} == `)), "Integer" === i2) { switch (this.getType(n2[e3].test)) { case "Number": case "Float": this.castValueToInteger(n2[e3].test, t2); break; case "LiteralInteger": this.castLiteralToInteger(n2[e3].test, t2); } } else { if ("Float" !== i2) throw new Error("unhanlded"); switch (this.getType(n2[e3].test)) { case "LiteralInteger": this.castLiteralToFloat(n2[e3].test, t2); break; case "Integer": this.castValueToFloat(n2[e3].test, t2); } } if (!n2[e3].consequent || 0 === n2[e3].consequent.length) { a2 = true, t2.push(" || "); continue; } t2.push(") {\n"); } else { if (n2.length > e3 + 1) { u = true, this.astGeneric(n2[e3].consequent, o); continue; } t2.push(" else {\n"); } this.astGeneric(n2[e3].consequent, t2), t2.push("\n}"); } return u && (t2.push(" else {"), t2.push(o.join("")), t2.push("}")), t2; } astThisExpression(e2, t2) { return t2.push("this"), t2; } astMemberExpression(e2, t2) { const { property: r2, name: i2, signature: s2, origin: a2, type: o, xProperty: u, yProperty: l, zProperty: h } = this.getMemberExpressionDetails(e2); switch (s2) { case "value.thread.value": case "this.thread.value": if ("x" !== i2 && "y" !== i2 && "z" !== i2) throw this.astErrorOutput("Unexpected expression, expected `this.thread.x`, `this.thread.y`, or `this.thread.z`", e2); return t2.push(`threadId.${i2}`), t2; case "this.output.value": if (this.dynamicOutput) switch (i2) { case "x": this.isState("casting-to-float") ? t2.push("float(uOutputDim.x)") : t2.push("uOutputDim.x"); break; case "y": this.isState("casting-to-float") ? t2.push("float(uOutputDim.y)") : t2.push("uOutputDim.y"); break; case "z": this.isState("casting-to-float") ? t2.push("float(uOutputDim.z)") : t2.push("uOutputDim.z"); break; default: throw this.astErrorOutput("Unexpected expression", e2); } else switch (i2) { case "x": this.isState("casting-to-integer") ? t2.push(this.output[0]) : t2.push(this.output[0], ".0"); break; case "y": this.isState("casting-to-integer") ? t2.push(this.output[1]) : t2.push(this.output[1], ".0"); break; case "z": this.isState("casting-to-integer") ? t2.push(this.output[2]) : t2.push(this.output[2], ".0"); break; default: throw this.astErrorOutput("Unexpected expression", e2); } return t2; case "value": throw this.astErrorOutput("Unexpected expression", e2); case "value[]": case "value[][]": case "value[][][]": case "value[][][][]": case "value.value": if ("Math" === a2) return t2.push(Math[i2]), t2; const s3 = n.sanitizeName(i2); switch (r2) { case "r": return t2.push(`user_${s3}.r`), t2; case "g": return t2.push(`user_${s3}.g`), t2; case "b": return t2.push(`user_${s3}.b`), t2; case "a": return t2.push(`user_${s3}.a`), t2; } break; case "this.constants.value": if (void 0 === u) switch (o) { case "Array(2)": case "Array(3)": case "Array(4)": return t2.push(`constants_${n.sanitizeName(i2)}`), t2; } case "this.constants.value[]": case "this.constants.value[][]": case "this.constants.value[][][]": case "this.constants.value[][][][]": break; case "fn()[]": return this.astCallExpression(e2.object, t2), t2.push("["), t2.push(this.memberExpressionPropertyMarkup(r2)), t2.push("]"), t2; case "fn()[][]": return this.astCallExpression(e2.object.object, t2), t2.push("["), t2.push(this.memberExpressionPropertyMarkup(e2.object.property)), t2.push("]"), t2.push("["), t2.push(this.memberExpressionPropertyMarkup(e2.property)), t2.push("]"), t2; case "[][]": return this.astArrayExpression(e2.object, t2), t2.push("["), t2.push(this.memberExpressionPropertyMarkup(r2)), t2.push("]"), t2; default: throw this.astErrorOutput("Unexpected expression", e2); } if (false === e2.computed) switch (o) { case "Number": case "Integer": case "Float": case "Boolean": return t2.push(`${a2}_${n.sanitizeName(i2)}`), t2; } const c = `${a2}_${n.sanitizeName(i2)}`; switch (o) { case "Array(2)": case "Array(3)": case "Array(4)": this.astGeneric(e2.object, t2), t2.push("["), t2.push(this.memberExpressionPropertyMarkup(u)), t2.push("]"); break; case "HTMLImageArray": t2.push(`getImage3D(${c}, ${c}Size, ${c}Dim, `), this.memberExpressionXYZ(u, l, h, t2), t2.push(")"); break; case "ArrayTexture(1)": t2.push(`getFloatFromSampler2D(${c}, ${c}Size, ${c}Dim, `), this.memberExpressionXYZ(u, l, h, t2), t2.push(")"); break; case "Array1D(2)": case "Array2D(2)": case "Array3D(2)": t2.push(`getMemoryOptimizedVec2(${c}, ${c}Size, ${c}Dim, `), this.memberExpressionXYZ(u, l, h, t2), t2.push(")"); break; case "ArrayTexture(2)": t2.push(`getVec2FromSampler2D(${c}, ${c}Size, ${c}Dim, `), this.memberExpressionXYZ(u, l, h, t2), t2.push(")"); break; case "Array1D(3)": case "Array2D(3)": case "Array3D(3)": t2.push(`getMemoryOptimizedVec3(${c}, ${c}Size, ${c}Dim, `), this.memberExpressionXYZ(u, l, h, t2), t2.push(")"); break; case "ArrayTexture(3)": t2.push(`getVec3FromSampler2D(${c}, ${c}Size, ${c}Dim, `), this.memberExpressionXYZ(u, l, h, t2), t2.push(")"); break; case "Array1D(4)": case "Array2D(4)": case "Array3D(4)": t2.push(`getMemoryOptimizedVec4(${c}, ${c}Size, ${c}Dim, `), this.memberExpressionXYZ(u, l, h, t2), t2.push(")"); break; case "ArrayTexture(4)": case "HTMLCanvas": case "OffscreenCanvas": case "HTMLImage": case "ImageBitmap": case "ImageData": case "HTMLVideo": t2.push(`getVec4FromSampler2D(${c}, ${c}Size, ${c}Dim, `), this.memberExpressionXYZ(u, l, h, t2), t2.push(")"); break; case "NumberTexture": case "Array": case "Array2D": case "Array3D": case "Array4D": case "Input": case "Number": case "Float": case "Integer": if ("single" === this.precision) t2.push(`getMemoryOptimized32(${c}, ${c}Size, ${c}Dim, `), this.memberExpressionXYZ(u, l, h, t2), t2.push(")"); else { const e3 = "user" === a2 ? this.lookupFunctionArgumentBitRatio(this.name, i2) : this.constantBitRatios[i2]; switch (e3) { case 1: t2.push(`get8(${c}, ${c}Size, ${c}Dim, `); break; case 2: t2.push(`get16(${c}, ${c}Size, ${c}Dim, `); break; case 4: case 0: t2.push(`get32(${c}, ${c}Size, ${c}Dim, `); break; default: throw new Error(`unhandled bit ratio of ${e3}`); } this.memberExpressionXYZ(u, l, h, t2), t2.push(")"); } break; case "MemoryOptimizedNumberTexture": t2.push(`getMemoryOptimized32(${c}, ${c}Size, ${c}Dim, `), this.memberExpressionXYZ(u, l, h, t2), t2.push(")"); break; case "Matrix(2)": case "Matrix(3)": case "Matrix(4)": t2.push(`${c}[${this.memberExpressionPropertyMarkup(l)}]`), l && t2.push(`[${this.memberExpressionPropertyMarkup(u)}]`); break; default: throw new Error(`unhandled member expression "${o}"`); } return t2; } astCallExpression(e2, t2) { if (!e2.callee) throw this.astErrorOutput("Unknown CallExpression", e2); let r2 = null; const i2 = this.isAstMathFunction(e2); if (r2 = i2 || e2.callee.object && "ThisExpression" === e2.callee.object.type ? e2.callee.property.name : "SequenceExpression" !== e2.callee.type || "Literal" !== e2.callee.expressions[0].type || isNaN(e2.callee.expressions[0].raw) ? e2.callee.name : e2.callee.expressions[1].property.name, !r2) throw this.astErrorOutput("Unhandled function, couldn't find name", e2); switch (r2) { case "pow": r2 = "_pow"; break; case "round": r2 = "_round"; } if (this.calledFunctions.indexOf(r2) < 0 && this.calledFunctions.push(r2), "random" === r2 && this.plugins && this.plugins.length > 0) for (let e3 = 0; e3 < this.plugins.length; e3++) { const r3 = this.plugins[e3]; if ("Math.random()" === r3.functionMatch && r3.functionReplace) return t2.push(r3.functionReplace), t2; } if (this.onFunctionCall && this.onFunctionCall(this.name, r2, e2.arguments), t2.push(r2), t2.push("("), i2) for (let r3 = 0; r3 < e2.arguments.length; ++r3) { const n2 = e2.arguments[r3], i3 = this.getType(n2); if (r3 > 0 && t2.push(", "), "Integer" === i3) this.castValueToFloat(n2, t2); else this.astGeneric(n2, t2); } else { const i3 = this.lookupFunctionArgumentTypes(r2) || []; for (let s2 = 0; s2 < e2.arguments.length; ++s2) { const a2 = e2.arguments[s2]; let o = i3[s2]; s2 > 0 && t2.push(", "); const u = this.getType(a2); switch (o || (this.triggerImplyArgumentType(r2, s2, u, this), o = u), u) { case "Boolean": this.astGeneric(a2, t2); continue; case "Number": case "Float": if ("Integer" === o) { t2.push("int("), this.astGeneric(a2, t2), t2.push(")"); continue; } if ("Number" === o || "Float" === o) { this.astGeneric(a2, t2); continue; } if ("LiteralInteger" === o) { this.castLiteralToFloat(a2, t2); continue; } break; case "Integer": if ("Number" === o || "Float" === o) { t2.push("float("), this.astGeneric(a2, t2), t2.push(")"); continue; } if ("Integer" === o) { this.astGeneric(a2, t2); continue; } break; case "LiteralInteger": if ("Integer" === o) { this.castLiteralToInteger(a2, t2); continue; } if ("Number" === o || "Float" === o) { this.castLiteralToFloat(a2, t2); continue; } if ("LiteralInteger" === o) { this.astGeneric(a2, t2); continue; } break; case "Array(2)": case "Array(3)": case "Array(4)": if (o === u) { if ("Identifier" === a2.type) t2.push(`user_${n.sanitizeName(a2.name)}`); else { if ("ArrayExpression" !== a2.type && "MemberExpression" !== a2.type && "CallExpression" !== a2.type) throw this.astErrorOutput(`Unhandled argument type ${a2.type}`, e2); this.astGeneric(a2, t2); } continue; } break; case "HTMLCanvas": case "OffscreenCanvas": case "HTMLImage": case "ImageBitmap": case "ImageData": case "HTMLImageArray": case "HTMLVideo": case "ArrayTexture(1)": case "ArrayTexture(2)": case "ArrayTexture(3)": case "ArrayTexture(4)": case "Array": case "Input": if (o === u) { if ("Identifier" !== a2.type) throw this.astErrorOutput(`Unhandled argument type ${a2.type}`, e2); this.triggerImplyArgumentBitRatio(this.name, a2.name, r2, s2); const i4 = n.sanitizeName(a2.name); t2.push(`user_${i4},user_${i4}Size,user_${i4}Dim`); continue; } } throw this.astErrorOutput(`Unhandled argument combination of ${u} and ${o} for argument named "${a2.name}"`, e2); } } return t2.push(")"), t2; } astArrayExpression(e2, t2) { const r2 = this.getType(e2), n2 = e2.elements.length; switch (r2) { case "Matrix(2)": case "Matrix(3)": case "Matrix(4)": t2.push(`mat${n2}(`); break; default: t2.push(`vec${n2}(`); } for (let r3 = 0; r3 < n2; ++r3) { r3 > 0 && t2.push(", "); const n3 = e2.elements[r3]; this.astGeneric(n3, t2); } return t2.push(")"), t2; } memberExpressionXYZ(e2, t2, r2, n2) { return r2 ? n2.push(this.memberExpressionPropertyMarkup(r2), ", ") : n2.push("0, "), t2 ? n2.push(this.memberExpressionPropertyMarkup(t2), ", ") : n2.push("0, "), n2.push(this.memberExpressionPropertyMarkup(e2)), n2; } memberExpressionPropertyMarkup(e2) { if (!e2) throw new Error("Property not set"); const t2 = []; switch (this.getType(e2)) { case "Number": case "Float": this.castValueToInteger(e2, t2); break; case "LiteralInteger": this.castLiteralToInteger(e2, t2); break; default: this.astGeneric(e2, t2); } return t2.join(""); } } }; }, { "../../utils": 114, "../function-node": 10 }], 39: [function(e, t, r) { const { WebGLKernelValueBoolean: n } = e("./kernel-value/boolean"), { WebGLKernelValueFloat: i } = e("./kernel-value/float"), { WebGLKernelValueInteger: s } = e("./kernel-value/integer"), { WebGLKernelValueHTMLImage: a } = e("./kernel-value/html-image"), { WebGLKernelValueDynamicHTMLImage: o } = e("./kernel-value/dynamic-html-image"), { WebGLKernelValueHTMLVideo: u } = e("./kernel-value/html-video"), { WebGLKernelValueDynamicHTMLVideo: l } = e("./kernel-value/dynamic-html-video"), { WebGLKernelValueSingleInput: h } = e("./kernel-value/single-input"), { WebGLKernelValueDynamicSingleInput: c } = e("./kernel-value/dynamic-single-input"), { WebGLKernelValueUnsignedInput: p } = e("./kernel-value/unsigned-input"), { WebGLKernelValueDynamicUnsignedInput: d } = e("./kernel-value/dynamic-unsigned-input"), { WebGLKernelValueMemoryOptimizedNumberTexture: m } = e("./kernel-value/memory-optimized-number-texture"), { WebGLKernelValueDynamicMemoryOptimizedNumberTexture: f } = e("./kernel-value/dynamic-memory-optimized-number-texture"), { WebGLKernelValueNumberTexture: g } = e("./kernel-value/number-texture"), { WebGLKernelValueDynamicNumberTexture: x } = e("./kernel-value/dynamic-number-texture"), { WebGLKernelValueSingleArray: y } = e("./kernel-value/single-array"), { WebGLKernelValueDynamicSingleArray: b } = e("./kernel-value/dynamic-single-array"), { WebGLKernelValueSingleArray1DI: T } = e("./kernel-value/single-array1d-i"), { WebGLKernelValueDynamicSingleArray1DI: v } = e("./kernel-value/dynamic-single-array1d-i"), { WebGLKernelValueSingleArray2DI: S } = e("./kernel-value/single-array2d-i"), { WebGLKernelValueDynamicSingleArray2DI: A } = e("./kernel-value/dynamic-single-array2d-i"), { WebGLKernelValueSingleArray3DI: _ } = e("./kernel-value/single-array3d-i"), { WebGLKernelValueDynamicSingleArray3DI: E } = e("./kernel-value/dynamic-single-array3d-i"), { WebGLKernelValueArray2: w } = e("./kernel-value/array2"), { WebGLKernelValueArray3: k } = e("./kernel-value/array3"), { WebGLKernelValueArray4: I } = e("./kernel-value/array4"), { WebGLKernelValueUnsignedArray: D } = e("./kernel-value/unsigned-array"), { WebGLKernelValueDynamicUnsignedArray: C } = e("./kernel-value/dynamic-unsigned-array"), $ = { unsigned: { dynamic: { Boolean: n, Integer: s, Float: i, Array: C, "Array(2)": w, "Array(3)": k, "Array(4)": I, "Array1D(2)": false, "Array1D(3)": false, "Array1D(4)": false, "Array2D(2)": false, "Array2D(3)": false, "Array2D(4)": false, "Array3D(2)": false, "Array3D(3)": false, "Array3D(4)": false, Input: d, NumberTexture: x, "ArrayTexture(1)": x, "ArrayTexture(2)": x, "ArrayTexture(3)": x, "ArrayTexture(4)": x, MemoryOptimizedNumberTexture: f, HTMLCanvas: o, OffscreenCanvas: o, HTMLImage: o, ImageBitmap: o, ImageData: o, HTMLImageArray: false, HTMLVideo: l }, static: { Boolean: n, Float: i, Integer: s, Array: D, "Array(2)": w, "Array(3)": k, "Array(4)": I, "Array1D(2)": false, "Array1D(3)": false, "Array1D(4)": false, "Array2D(2)": false, "Array2D(3)": false, "Array2D(4)": false, "Array3D(2)": false, "Array3D(3)": false, "Array3D(4)": false, Input: p, NumberTexture: g, "ArrayTexture(1)": g, "ArrayTexture(2)": g, "ArrayTexture(3)": g, "ArrayTexture(4)": g, MemoryOptimizedNumberTexture: m, HTMLCanvas: a, OffscreenCanvas: a, HTMLImage: a, ImageBitmap: a, ImageData: a, HTMLImageArray: false, HTMLVideo: u } }, single: { dynamic: { Boolean: n, Integer: s, Float: i, Array: b, "Array(2)": w, "Array(3)": k, "Array(4)": I, "Array1D(2)": v, "Array1D(3)": v, "Array1D(4)": v, "Array2D(2)": A, "Array2D(3)": A, "Array2D(4)": A, "Array3D(2)": E, "Array3D(3)": E, "Array3D(4)": E, Input: c, NumberTexture: x, "ArrayTexture(1)": x, "ArrayTexture(2)": x, "ArrayTexture(3)": x, "ArrayTexture(4)": x, MemoryOptimizedNumberTexture: f, HTMLCanvas: o, OffscreenCanvas: o, HTMLImage: o, ImageBitmap: o, ImageData: o, HTMLImageArray: false, HTMLVideo: l }, static: { Boolean: n, Float: i, Integer: s, Array: y, "Array(2)": w, "Array(3)": k, "Array(4)": I, "Array1D(2)": T, "Array1D(3)": T, "Array1D(4)": T, "Array2D(2)": S, "Array2D(3)": S, "Array2D(4)": S, "Array3D(2)": _, "Array3D(3)": _, "Array3D(4)": _, Input: h, NumberTexture: g, "ArrayTexture(1)": g, "ArrayTexture(2)": g, "ArrayTexture(3)": g, "ArrayTexture(4)": g, MemoryOptimizedNumberTexture: m, HTMLCanvas: a, OffscreenCanvas: a, HTMLImage: a, ImageBitmap: a, ImageData: a, HTMLImageArray: false, HTMLVideo: u } } }; t.exports = { lookupKernelValueType: function(e2, t2, r2, n2) { if (!e2) throw new Error("type missing"); if (!t2) throw new Error("dynamic missing"); if (!r2) throw new Error("precision missing"); n2.type && (e2 = n2.type); const i2 = $[r2][t2]; if (false === i2[e2]) return null; if (void 0 === i2[e2]) throw new Error(`Could not find a KernelValue for ${e2}`); return i2[e2]; }, kernelValueMaps: $ }; }, { "./kernel-value/array2": 41, "./kernel-value/array3": 42, "./kernel-value/array4": 43, "./kernel-value/boolean": 44, "./kernel-value/dynamic-html-image": 45, "./kernel-value/dynamic-html-video": 46, "./kernel-value/dynamic-memory-optimized-number-texture": 47, "./kernel-value/dynamic-number-texture": 48, "./kernel-value/dynamic-single-array": 49, "./kernel-value/dynamic-single-array1d-i": 50, "./kernel-value/dynamic-single-array2d-i": 51, "./kernel-value/dynamic-single-array3d-i": 52, "./kernel-value/dynamic-single-input": 53, "./kernel-value/dynamic-unsigned-array": 54, "./kernel-value/dynamic-unsigned-input": 55, "./kernel-value/float": 56, "./kernel-value/html-image": 57, "./kernel-value/html-video": 58, "./kernel-value/integer": 60, "./kernel-value/memory-optimized-number-texture": 61, "./kernel-value/number-texture": 62, "./kernel-value/single-array": 63, "./kernel-value/single-array1d-i": 64, "./kernel-value/single-array2d-i": 65, "./kernel-value/single-array3d-i": 66, "./kernel-value/single-input": 67, "./kernel-value/unsigned-array": 68, "./kernel-value/unsigned-input": 69 }], 40: [function(e, t, r) { const { WebGLKernelValue: n } = e("./index"), { Input: i } = e("../../../input"); t.exports = { WebGLKernelArray: class extends n { checkSize(e2, t2) { if (!this.kernel.validate) return; const { maxTextureSize: r2 } = this.kernel.constructor.features; if (e2 > r2 || t2 > r2) throw e2 > t2 ? new Error(`Argument texture width of ${e2} larger than maximum size of ${r2} for your GPU`) : e2 < t2 ? new Error(`Argument texture height of ${t2} larger than maximum size of ${r2} for your GPU`) : new Error(`Argument texture height and width of ${t2} larger than maximum size of ${r2} for your GPU`); } setup() { this.requestTexture(), this.setupTexture(), this.defineTexture(); } requestTexture() { this.texture = this.onRequestTexture(); } defineTexture() { const { context: e2 } = this; e2.activeTexture(this.contextHandle), e2.bindTexture(e2.TEXTURE_2D, this.texture), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_WRAP_S, e2.CLAMP_TO_EDGE), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_WRAP_T, e2.CLAMP_TO_EDGE), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_MIN_FILTER, e2.NEAREST), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_MAG_FILTER, e2.NEAREST); } setupTexture() { this.contextHandle = this.onRequestContextHandle(), this.index = this.onRequestIndex(), this.dimensionsId = this.id + "Dim", this.sizeId = this.id + "Size"; } getBitRatio(e2) { if (Array.isArray(e2[0])) return this.getBitRatio(e2[0]); if (e2.constructor === i) return this.getBitRatio(e2.value); switch (e2.constructor) { case Uint8ClampedArray: case Uint8Array: case Int8Array: return 1; case Uint16Array: case Int16Array: return 2; case Float32Array: case Int32Array: default: return 4; } } destroy() { this.prevArg && this.prevArg.delete(), this.context.deleteTexture(this.texture); } } }; }, { "../../../input": 110, "./index": 59 }], 41: [function(e, t, r) { const { WebGLKernelValue: n } = e("./index"); t.exports = { WebGLKernelValueArray2: class extends n { constructor(e2, t2) { super(e2, t2), this.uploadValue = e2; } getSource(e2) { return "constants" === this.origin ? `const vec2 ${this.id} = vec2(${e2[0]},${e2[1]}); ` : `uniform vec2 ${this.id}; `; } getStringValueHandler() { return "constants" === this.origin ? "" : `const uploadValue_${this.name} = ${this.varName}; `; } updateValue(e2) { "constants" !== this.origin && this.kernel.setUniform2fv(this.id, this.uploadValue = e2); } } }; }, { "./index": 59 }], 42: [function(e, t, r) { const { WebGLKernelValue: n } = e("./index"); t.exports = { WebGLKernelValueArray3: class extends n { constructor(e2, t2) { super(e2, t2), this.uploadValue = e2; } getSource(e2) { return "constants" === this.origin ? `const vec3 ${this.id} = vec3(${e2[0]},${e2[1]},${e2[2]}); ` : `uniform vec3 ${this.id}; `; } getStringValueHandler() { return "constants" === this.origin ? "" : `const uploadValue_${this.name} = ${this.varName}; `; } updateValue(e2) { "constants" !== this.origin && this.kernel.setUniform3fv(this.id, this.uploadValue = e2); } } }; }, { "./index": 59 }], 43: [function(e, t, r) { const { WebGLKernelValue: n } = e("./index"); t.exports = { WebGLKernelValueArray4: class extends n { constructor(e2, t2) { super(e2, t2), this.uploadValue = e2; } getSource(e2) { return "constants" === this.origin ? `const vec4 ${this.id} = vec4(${e2[0]},${e2[1]},${e2[2]},${e2[3]}); ` : `uniform vec4 ${this.id}; `; } getStringValueHandler() { return "constants" === this.origin ? "" : `const uploadValue_${this.name} = ${this.varName}; `; } updateValue(e2) { "constants" !== this.origin && this.kernel.setUniform4fv(this.id, this.uploadValue = e2); } } }; }, { "./index": 59 }], 44: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValue: i } = e("./index"); t.exports = { WebGLKernelValueBoolean: class extends i { constructor(e2, t2) { super(e2, t2), this.uploadValue = e2; } getSource(e2) { return "constants" === this.origin ? `const bool ${this.id} = ${e2}; ` : `uniform bool ${this.id}; `; } getStringValueHandler() { return `const uploadValue_${this.name} = ${this.varName}; `; } updateValue(e2) { "constants" !== this.origin && this.kernel.setUniform1i(this.id, this.uploadValue = e2); } } }; }, { "../../../utils": 114, "./index": 59 }], 45: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueHTMLImage: i } = e("./html-image"); t.exports = { WebGLKernelValueDynamicHTMLImage: class extends i { getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `uniform ivec2 ${this.sizeId}`, `uniform ivec3 ${this.dimensionsId}`]); } updateValue(e2) { const { width: t2, height: r2 } = e2; this.checkSize(t2, r2), this.dimensions = [t2, r2, 1], this.textureSize = [t2, r2], this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "./html-image": 57 }], 46: [function(e, t, r) { const { WebGLKernelValueDynamicHTMLImage: n } = e("./dynamic-html-image"); t.exports = { WebGLKernelValueDynamicHTMLVideo: class extends n { } }; }, { "./dynamic-html-image": 45 }], 47: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueMemoryOptimizedNumberTexture: i } = e("./memory-optimized-number-texture"); t.exports = { WebGLKernelValueDynamicMemoryOptimizedNumberTexture: class extends i { getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `uniform ivec2 ${this.sizeId}`, `uniform ivec3 ${this.dimensionsId}`]); } updateValue(e2) { this.dimensions = e2.dimensions, this.checkSize(e2.size[0], e2.size[1]), this.textureSize = e2.size, this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "./memory-optimized-number-texture": 61 }], 48: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueNumberTexture: i } = e("./number-texture"); t.exports = { WebGLKernelValueDynamicNumberTexture: class extends i { getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `uniform ivec2 ${this.sizeId}`, `uniform ivec3 ${this.dimensionsId}`]); } updateValue(e2) { this.dimensions = e2.dimensions, this.checkSize(e2.size[0], e2.size[1]), this.textureSize = e2.size, this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "./number-texture": 62 }], 49: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueSingleArray: i } = e("./single-array"); t.exports = { WebGLKernelValueDynamicSingleArray: class extends i { getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `uniform ivec2 ${this.sizeId}`, `uniform ivec3 ${this.dimensionsId}`]); } updateValue(e2) { this.dimensions = n.getDimensions(e2, true), this.textureSize = n.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio, this.checkSize(this.textureSize[0], this.textureSize[1]), this.uploadValue = new Float32Array(this.uploadArrayLength), this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "./single-array": 63 }], 50: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueSingleArray1DI: i } = e("./single-array1d-i"); t.exports = { WebGLKernelValueDynamicSingleArray1DI: class extends i { getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `uniform ivec2 ${this.sizeId}`, `uniform ivec3 ${this.dimensionsId}`]); } updateValue(e2) { this.setShape(e2), this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "./single-array1d-i": 64 }], 51: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueSingleArray2DI: i } = e("./single-array2d-i"); t.exports = { WebGLKernelValueDynamicSingleArray2DI: class extends i { getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `uniform ivec2 ${this.sizeId}`, `uniform ivec3 ${this.dimensionsId}`]); } updateValue(e2) { this.setShape(e2), this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "./single-array2d-i": 65 }], 52: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueSingleArray3DI: i } = e("./single-array3d-i"); t.exports = { WebGLKernelValueDynamicSingleArray3DI: class extends i { getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `uniform ivec2 ${this.sizeId}`, `uniform ivec3 ${this.dimensionsId}`]); } updateValue(e2) { this.setShape(e2), this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "./single-array3d-i": 66 }], 53: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueSingleInput: i } = e("./single-input"); t.exports = { WebGLKernelValueDynamicSingleInput: class extends i { getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `uniform ivec2 ${this.sizeId}`, `uniform ivec3 ${this.dimensionsId}`]); } updateValue(e2) { let [t2, r2, i2] = e2.size; this.dimensions = new Int32Array([t2 || 1, r2 || 1, i2 || 1]), this.textureSize = n.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio, this.checkSize(this.textureSize[0], this.textureSize[1]), this.uploadValue = new Float32Array(this.uploadArrayLength), this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "./single-input": 67 }], 54: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueUnsignedArray: i } = e("./unsigned-array"); t.exports = { WebGLKernelValueDynamicUnsignedArray: class extends i { getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `uniform ivec2 ${this.sizeId}`, `uniform ivec3 ${this.dimensionsId}`]); } updateValue(e2) { this.dimensions = n.getDimensions(e2, true), this.textureSize = n.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio), this.checkSize(this.textureSize[0], this.textureSize[1]); const t2 = this.getTransferArrayType(e2); this.preUploadValue = new t2(this.uploadArrayLength), this.uploadValue = new Uint8Array(this.preUploadValue.buffer), this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "./unsigned-array": 68 }], 55: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueUnsignedInput: i } = e("./unsigned-input"); t.exports = { WebGLKernelValueDynamicUnsignedInput: class extends i { getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `uniform ivec2 ${this.sizeId}`, `uniform ivec3 ${this.dimensionsId}`]); } updateValue(e2) { let [t2, r2, i2] = e2.size; this.dimensions = new Int32Array([t2 || 1, r2 || 1, i2 || 1]), this.textureSize = n.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio), this.checkSize(this.textureSize[0], this.textureSize[1]); const s = this.getTransferArrayType(e2.value); this.preUploadValue = new s(this.uploadArrayLength), this.uploadValue = new Uint8Array(this.preUploadValue.buffer), this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "./unsigned-input": 69 }], 56: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValue: i } = e("./index"); t.exports = { WebGLKernelValueFloat: class extends i { constructor(e2, t2) { super(e2, t2), this.uploadValue = e2; } getStringValueHandler() { return `const uploadValue_${this.name} = ${this.varName}; `; } getSource(e2) { return "constants" === this.origin ? Number.isInteger(e2) ? `const float ${this.id} = ${e2}.0; ` : `const float ${this.id} = ${e2}; ` : `uniform float ${this.id}; `; } updateValue(e2) { "constants" !== this.origin && this.kernel.setUniform1f(this.id, this.uploadValue = e2); } } }; }, { "../../../utils": 114, "./index": 59 }], 57: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelArray: i } = e("./array"); t.exports = { WebGLKernelValueHTMLImage: class extends i { constructor(e2, t2) { super(e2, t2); const { width: r2, height: n2 } = e2; this.checkSize(r2, n2), this.dimensions = [r2, n2, 1], this.textureSize = [r2, n2], this.uploadValue = e2; } getStringValueHandler() { return `const uploadValue_${this.name} = ${this.varName}; `; } getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); const { context: t2 } = this; t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, true), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA, t2.RGBA, t2.UNSIGNED_BYTE, this.uploadValue = e2), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "./array": 40 }], 58: [function(e, t, r) { const { WebGLKernelValueHTMLImage: n } = e("./html-image"); t.exports = { WebGLKernelValueHTMLVideo: class extends n { } }; }, { "./html-image": 57 }], 59: [function(e, t, r) { const { utils: n } = e("../../../utils"), { KernelValue: i } = e("../../kernel-value"); t.exports = { WebGLKernelValue: class extends i { constructor(e2, t2) { super(e2, t2), this.dimensionsId = null, this.sizeId = null, this.initialValueConstructor = e2.constructor, this.onRequestTexture = t2.onRequestTexture, this.onRequestIndex = t2.onRequestIndex, this.uploadValue = null, this.textureSize = null, this.bitRatio = null, this.prevArg = null; } get id() { return `${this.origin}_${n.sanitizeName(this.name)}`; } setup() { } getTransferArrayType(e2) { if (Array.isArray(e2[0])) return this.getTransferArrayType(e2[0]); switch (e2.constructor) { case Array: case Int32Array: case Int16Array: case Int8Array: return Float32Array; case Uint8ClampedArray: case Uint8Array: case Uint16Array: case Uint32Array: case Float32Array: case Float64Array: return e2.constructor; } return console.warn("Unfamiliar constructor type. Will go ahead and use, but likley this may result in a transfer of zeros"), e2.constructor; } getStringValueHandler() { throw new Error(`"getStringValueHandler" not implemented on ${this.constructor.name}`); } getVariablePrecisionString() { return this.kernel.getVariablePrecisionString(this.textureSize || void 0, this.tactic || void 0); } destroy() { } } }; }, { "../../../utils": 114, "../../kernel-value": 35 }], 60: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValue: i } = e("./index"); t.exports = { WebGLKernelValueInteger: class extends i { constructor(e2, t2) { super(e2, t2), this.uploadValue = e2; } getStringValueHandler() { return `const uploadValue_${this.name} = ${this.varName}; `; } getSource(e2) { return "constants" === this.origin ? `const int ${this.id} = ${parseInt(e2)}; ` : `uniform int ${this.id}; `; } updateValue(e2) { "constants" !== this.origin && this.kernel.setUniform1i(this.id, this.uploadValue = e2); } } }; }, { "../../../utils": 114, "./index": 59 }], 61: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelArray: i } = e("./array"), s = "Source and destination textures are the same. Use immutable = true and manually cleanup kernel output texture memory with texture.delete()"; t.exports = { WebGLKernelValueMemoryOptimizedNumberTexture: class extends i { constructor(e2, t2) { super(e2, t2); const [r2, n2] = e2.size; this.checkSize(r2, n2), this.dimensions = e2.dimensions, this.textureSize = e2.size, this.uploadValue = e2.texture, this.forceUploadEachRun = true; } setup() { this.setupTexture(); } getStringValueHandler() { return `const uploadValue_${this.name} = ${this.varName}.texture; `; } getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); if (this.checkContext && e2.context !== this.context) throw new Error(`Value ${this.name} (${this.type}) must be from same context`); const { kernel: t2, context: r2 } = this; if (t2.pipeline) if (t2.immutable) t2.updateTextureArgumentRefs(this, e2); else { if (t2.texture && t2.texture.texture === e2.texture) throw new Error(s); if (t2.mappedTextures) { const { mappedTextures: r3 } = t2; for (let t3 = 0; t3 < r3.length; t3++) if (r3[t3].texture === e2.texture) throw new Error(s); } } r2.activeTexture(this.contextHandle), r2.bindTexture(r2.TEXTURE_2D, this.uploadValue = e2.texture), this.kernel.setUniform1i(this.id, this.index); } }, sameError: s }; }, { "../../../utils": 114, "./array": 40 }], 62: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelArray: i } = e("./array"), { sameError: s } = e("./memory-optimized-number-texture"); t.exports = { WebGLKernelValueNumberTexture: class extends i { constructor(e2, t2) { super(e2, t2); const [r2, n2] = e2.size; this.checkSize(r2, n2); const { size: i2, dimensions: s2 } = e2; this.bitRatio = this.getBitRatio(e2), this.dimensions = s2, this.textureSize = i2, this.uploadValue = e2.texture, this.forceUploadEachRun = true; } setup() { this.setupTexture(); } getStringValueHandler() { return `const uploadValue_${this.name} = ${this.varName}.texture; `; } getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); if (this.checkContext && e2.context !== this.context) throw new Error(`Value ${this.name} (${this.type}) must be from same context`); const { kernel: t2, context: r2 } = this; if (t2.pipeline) if (t2.immutable) t2.updateTextureArgumentRefs(this, e2); else { if (t2.texture && t2.texture.texture === e2.texture) throw new Error(s); if (t2.mappedTextures) { const { mappedTextures: r3 } = t2; for (let t3 = 0; t3 < r3.length; t3++) if (r3[t3].texture === e2.texture) throw new Error(s); } } r2.activeTexture(this.contextHandle), r2.bindTexture(r2.TEXTURE_2D, this.uploadValue = e2.texture), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "./array": 40, "./memory-optimized-number-texture": 61 }], 63: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelArray: i } = e("./array"); t.exports = { WebGLKernelValueSingleArray: class extends i { constructor(e2, t2) { super(e2, t2), this.bitRatio = 4, this.dimensions = n.getDimensions(e2, true), this.textureSize = n.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio, this.checkSize(this.textureSize[0], this.textureSize[1]), this.uploadValue = new Float32Array(this.uploadArrayLength); } getStringValueHandler() { return n.linesToString([`const uploadValue_${this.name} = new Float32Array(${this.uploadArrayLength})`, `flattenTo(${this.varName}, uploadValue_${this.name})`]); } getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); const { context: t2 } = this; n.flattenTo(e2, this.uploadValue), t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, false), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA, this.textureSize[0], this.textureSize[1], 0, t2.RGBA, t2.FLOAT, this.uploadValue), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "./array": 40 }], 64: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelArray: i } = e("./array"); t.exports = { WebGLKernelValueSingleArray1DI: class extends i { constructor(e2, t2) { super(e2, t2), this.bitRatio = 4, this.setShape(e2); } setShape(e2) { const t2 = n.getDimensions(e2, true); this.textureSize = n.getMemoryOptimizedFloatTextureSize(t2, this.bitRatio), this.dimensions = new Int32Array([t2[1], 1, 1]), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio, this.checkSize(this.textureSize[0], this.textureSize[1]), this.uploadValue = new Float32Array(this.uploadArrayLength); } getStringValueHandler() { return n.linesToString([`const uploadValue_${this.name} = new Float32Array(${this.uploadArrayLength})`, `flattenTo(${this.varName}, uploadValue_${this.name})`]); } getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); const { context: t2 } = this; n.flatten2dArrayTo(e2, this.uploadValue), t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, false), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA, this.textureSize[0], this.textureSize[1], 0, t2.RGBA, t2.FLOAT, this.uploadValue), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "./array": 40 }], 65: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelArray: i } = e("./array"); t.exports = { WebGLKernelValueSingleArray2DI: class extends i { constructor(e2, t2) { super(e2, t2), this.bitRatio = 4, this.setShape(e2); } setShape(e2) { const t2 = n.getDimensions(e2, true); this.textureSize = n.getMemoryOptimizedFloatTextureSize(t2, this.bitRatio), this.dimensions = new Int32Array([t2[1], t2[2], 1]), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio, this.checkSize(this.textureSize[0], this.textureSize[1]), this.uploadValue = new Float32Array(this.uploadArrayLength); } getStringValueHandler() { return n.linesToString([`const uploadValue_${this.name} = new Float32Array(${this.uploadArrayLength})`, `flattenTo(${this.varName}, uploadValue_${this.name})`]); } getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); const { context: t2 } = this; n.flatten3dArrayTo(e2, this.uploadValue), t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, false), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA, this.textureSize[0], this.textureSize[1], 0, t2.RGBA, t2.FLOAT, this.uploadValue), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "./array": 40 }], 66: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelArray: i } = e("./array"); t.exports = { WebGLKernelValueSingleArray3DI: class extends i { constructor(e2, t2) { super(e2, t2), this.bitRatio = 4, this.setShape(e2); } setShape(e2) { const t2 = n.getDimensions(e2, true); this.textureSize = n.getMemoryOptimizedFloatTextureSize(t2, this.bitRatio), this.dimensions = new Int32Array([t2[1], t2[2], t2[3]]), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio, this.checkSize(this.textureSize[0], this.textureSize[1]), this.uploadValue = new Float32Array(this.uploadArrayLength); } getStringValueHandler() { return n.linesToString([`const uploadValue_${this.name} = new Float32Array(${this.uploadArrayLength})`, `flattenTo(${this.varName}, uploadValue_${this.name})`]); } getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); const { context: t2 } = this; n.flatten4dArrayTo(e2, this.uploadValue), t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, false), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA, this.textureSize[0], this.textureSize[1], 0, t2.RGBA, t2.FLOAT, this.uploadValue), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "./array": 40 }], 67: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelArray: i } = e("./array"); t.exports = { WebGLKernelValueSingleInput: class extends i { constructor(e2, t2) { super(e2, t2), this.bitRatio = 4; let [r2, i2, s] = e2.size; this.dimensions = new Int32Array([r2 || 1, i2 || 1, s || 1]), this.textureSize = n.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio, this.checkSize(this.textureSize[0], this.textureSize[1]), this.uploadValue = new Float32Array(this.uploadArrayLength); } getStringValueHandler() { return n.linesToString([`const uploadValue_${this.name} = new Float32Array(${this.uploadArrayLength})`, `flattenTo(${this.varName}.value, uploadValue_${this.name})`]); } getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); const { context: t2 } = this; n.flattenTo(e2.value, this.uploadValue), t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, false), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA, this.textureSize[0], this.textureSize[1], 0, t2.RGBA, t2.FLOAT, this.uploadValue), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "./array": 40 }], 68: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelArray: i } = e("./array"); t.exports = { WebGLKernelValueUnsignedArray: class extends i { constructor(e2, t2) { super(e2, t2), this.bitRatio = this.getBitRatio(e2), this.dimensions = n.getDimensions(e2, true), this.textureSize = n.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio), this.checkSize(this.textureSize[0], this.textureSize[1]), this.TranserArrayType = this.getTransferArrayType(e2), this.preUploadValue = new this.TranserArrayType(this.uploadArrayLength), this.uploadValue = new Uint8Array(this.preUploadValue.buffer); } getStringValueHandler() { return n.linesToString([`const preUploadValue_${this.name} = new ${this.TranserArrayType.name}(${this.uploadArrayLength})`, `const uploadValue_${this.name} = new Uint8Array(preUploadValue_${this.name}.buffer)`, `flattenTo(${this.varName}, preUploadValue_${this.name})`]); } getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); const { context: t2 } = this; n.flattenTo(e2, this.preUploadValue), t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, false), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA, this.textureSize[0], this.textureSize[1], 0, t2.RGBA, t2.UNSIGNED_BYTE, this.uploadValue), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "./array": 40 }], 69: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelArray: i } = e("./array"); t.exports = { WebGLKernelValueUnsignedInput: class extends i { constructor(e2, t2) { super(e2, t2), this.bitRatio = this.getBitRatio(e2); const [r2, i2, s] = e2.size; this.dimensions = new Int32Array([r2 || 1, i2 || 1, s || 1]), this.textureSize = n.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio), this.checkSize(this.textureSize[0], this.textureSize[1]), this.TranserArrayType = this.getTransferArrayType(e2.value), this.preUploadValue = new this.TranserArrayType(this.uploadArrayLength), this.uploadValue = new Uint8Array(this.preUploadValue.buffer); } getStringValueHandler() { return n.linesToString([`const preUploadValue_${this.name} = new ${this.TranserArrayType.name}(${this.uploadArrayLength})`, `const uploadValue_${this.name} = new Uint8Array(preUploadValue_${this.name}.buffer)`, `flattenTo(${this.varName}.value, preUploadValue_${this.name})`]); } getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(value.constructor); const { context: t2 } = this; n.flattenTo(e2.value, this.preUploadValue), t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, false), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA, this.textureSize[0], this.textureSize[1], 0, t2.RGBA, t2.UNSIGNED_BYTE, this.uploadValue), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "./array": 40 }], 70: [function(e, t, r) { const { GLKernel: n } = e("../gl/kernel"), { FunctionBuilder: i } = e("../function-builder"), { WebGLFunctionNode: s } = e("./function-node"), { utils: a } = e("../../utils"), o = e("../../plugins/math-random-uniformly-distributed"), { fragmentShader: u } = e("./fragment-shader"), { vertexShader: l } = e("./vertex-shader"), { glKernelString: h } = e("../gl/kernel-string"), { lookupKernelValueType: c } = e("./kernel-value-maps"); let p = null, d = null, m = null, f = null, g = null; const x = [o], y = [], b = {}; t.exports = { WebGLKernel: class extends n { static get isSupported() { return null !== p || (this.setupFeatureChecks(), p = this.isContextMatch(m)), p; } static setupFeatureChecks() { "undefined" != typeof document ? d = document.createElement("canvas") : "undefined" != typeof OffscreenCanvas && (d = new OffscreenCanvas(0, 0)), d && (m = d.getContext("webgl") || d.getContext("experimental-webgl"), m && m.getExtension && (f = { OES_texture_float: m.getExtension("OES_texture_float"), OES_texture_float_linear: m.getExtension("OES_texture_float_linear"), OES_element_index_uint: m.getExtension("OES_element_index_uint"), WEBGL_draw_buffers: m.getExtension("WEBGL_draw_buffers") }, g = this.getFeatures())); } static isContextMatch(e2) { return "undefined" != typeof WebGLRenderingContext && e2 instanceof WebGLRenderingContext; } static getIsTextureFloat() { return Boolean(f.OES_texture_float); } static getIsDrawBuffers() { return Boolean(f.WEBGL_draw_buffers); } static getChannelCount() { return f.WEBGL_draw_buffers ? m.getParameter(f.WEBGL_draw_buffers.MAX_DRAW_BUFFERS_WEBGL) : 1; } static getMaxTextureSize() { return m.getParameter(m.MAX_TEXTURE_SIZE); } static lookupKernelValueType(e2, t2, r2, n2) { return c(e2, t2, r2, n2); } static get testCanvas() { return d; } static get testContext() { return m; } static get features() { return g; } static get fragmentShader() { return u; } static get vertexShader() { return l; } constructor(e2, t2) { super(e2, t2), this.program = null, this.pipeline = t2.pipeline, this.endianness = a.systemEndianness(), this.extensions = {}, this.argumentTextureCount = 0, this.constantTextureCount = 0, this.fragShader = null, this.vertShader = null, this.drawBuffersMap = null, this.maxTexSize = null, this.onRequestSwitchKernel = null, this.texture = null, this.mappedTextures = null, this.mergeSettings(e2.settings || t2), this.threadDim = null, this.framebuffer = null, this.buffer = null, this.textureCache = [], this.programUniformLocationCache = {}, this.uniform1fCache = {}, this.uniform1iCache = {}, this.uniform2fCache = {}, this.uniform2fvCache = {}, this.uniform2ivCache = {}, this.uniform3fvCache = {}, this.uniform3ivCache = {}, this.uniform4fvCache = {}, this.uniform4ivCache = {}; } initCanvas() { if ("undefined" != typeof document) { const e2 = document.createElement("canvas"); return e2.width = 2, e2.height = 2, e2; } if ("undefined" != typeof OffscreenCanvas) return new OffscreenCanvas(0, 0); } initContext() { const e2 = { alpha: false, depth: false, antialias: false }; return this.canvas.getContext("webgl", e2) || this.canvas.getContext("experimental-webgl", e2); } initPlugins(e2) { const t2 = [], { source: r2 } = this; if ("string" == typeof r2) for (let e3 = 0; e3 < x.length; e3++) { const n2 = x[e3]; r2.match(n2.functionMatch) && t2.push(n2); } else if ("object" == typeof r2 && e2.pluginNames) for (let r3 = 0; r3 < x.length; r3++) { const n2 = x[r3]; e2.pluginNames.some((e3) => e3 === n2.name) && t2.push(n2); } return t2; } initExtensions() { this.extensions = { OES_texture_float: this.context.getExtension("OES_texture_float"), OES_texture_float_linear: this.context.getExtension("OES_texture_float_linear"), OES_element_index_uint: this.context.getExtension("OES_element_index_uint"), WEBGL_draw_buffers: this.context.getExtension("WEBGL_draw_buffers"), WEBGL_color_buffer_float: this.context.getExtension("WEBGL_color_buffer_float") }; } validateSettings(e2) { if (!this.validate) return void (this.texSize = a.getKernelTextureSize({ optimizeFloatMemory: this.optimizeFloatMemory, precision: this.precision }, this.output)); const { features: t2 } = this.constructor; if (true === this.optimizeFloatMemory && !t2.isTextureFloat) throw new Error("Float textures are not supported"); if ("single" === this.precision && !t2.isFloatRead) throw new Error("Single precision not supported"); if (!this.graphical && null === this.precision && t2.isTextureFloat && (this.precision = t2.isFloatRead ? "single" : "unsigned"), this.subKernels && this.subKernels.length > 0 && !this.extensions.WEBGL_draw_buffers) throw new Error("could not instantiate draw buffers extension"); if (null === this.fixIntegerDivisionAccuracy ? this.fixIntegerDivisionAccuracy = !t2.isIntegerDivisionAccurate : this.fixIntegerDivisionAccuracy && t2.isIntegerDivisionAccurate && (this.fixIntegerDivisionAccuracy = false), this.checkOutput(), !this.output || 0 === this.output.length) { if (1 !== e2.length) throw new Error("Auto output only supported for kernels with only one input"); const t3 = a.getVariableType(e2[0], this.strictIntegers); switch (t3) { case "Array": this.output = a.getDimensions(t3); break; case "NumberTexture": case "MemoryOptimizedNumberTexture": case "ArrayTexture(1)": case "ArrayTexture(2)": case "ArrayTexture(3)": case "ArrayTexture(4)": this.output = e2[0].output; break; default: throw new Error("Auto output not supported for input type: " + t3); } } if (this.graphical) { if (2 !== this.output.length) throw new Error("Output must have 2 dimensions on graphical mode"); return "precision" === this.precision && (this.precision = "unsigned", console.warn("Cannot use graphical mode and single precision at the same time")), void (this.texSize = a.clone(this.output)); } null === this.precision && t2.isTextureFloat && (this.precision = "single"), this.texSize = a.getKernelTextureSize({ optimizeFloatMemory: this.optimizeFloatMemory, precision: this.precision }, this.output), this.checkTextureSize(); } updateMaxTexSize() { const { texSize: e2, canvas: t2 } = this; if (null === this.maxTexSize) { let r2 = y.indexOf(t2); -1 === r2 && (r2 = y.length, y.push(t2), b[r2] = [e2[0], e2[1]]), this.maxTexSize = b[r2]; } this.maxTexSize[0] < e2[0] && (this.maxTexSize[0] = e2[0]), this.maxTexSize[1] < e2[1] && (this.maxTexSize[1] = e2[1]); } setupArguments(e2) { this.kernelArguments = [], this.argumentTextureCount = 0; const t2 = null === this.argumentTypes; if (t2 && (this.argumentTypes = []), this.argumentSizes = [], this.argumentBitRatios = [], e2.length < this.argumentNames.length) throw new Error("not enough arguments for kernel"); if (e2.length > this.argumentNames.length) throw new Error("too many arguments for kernel"); const { context: r2 } = this; let n2 = 0; const i2 = () => this.createTexture(), s2 = () => this.constantTextureCount + n2++, o2 = (e3) => { this.switchKernels({ type: "argumentMismatch", needed: e3 }); }, u2 = () => r2.TEXTURE0 + this.constantTextureCount + this.argumentTextureCount++; for (let n3 = 0; n3 < e2.length; n3++) { const l2 = e2[n3], h2 = this.argumentNames[n3]; let c2; t2 ? (c2 = a.getVariableType(l2, this.strictIntegers), this.argumentTypes.push(c2)) : c2 = this.argumentTypes[n3]; const p2 = this.constructor.lookupKernelValueType(c2, this.dynamicArguments ? "dynamic" : "static", this.precision, e2[n3]); if (null === p2) return this.requestFallback(e2); const d2 = new p2(l2, { name: h2, type: c2, tactic: this.tactic, origin: "user", context: r2, checkContext: this.checkContext, kernel: this, strictIntegers: this.strictIntegers, onRequestTexture: i2, onRequestIndex: s2, onUpdateValueMismatch: o2, onRequestContextHandle: u2 }); this.kernelArguments.push(d2), d2.setup(), this.argumentSizes.push(d2.textureSize), this.argumentBitRatios[n3] = d2.bitRatio; } } createTexture() { const e2 = this.context.createTexture(); return this.textureCache.push(e2), e2; } setupConstants(e2) { const { context: t2 } = this; this.kernelConstants = [], this.forceUploadKernelConstants = []; let r2 = null === this.constantTypes; r2 && (this.constantTypes = {}), this.constantBitRatios = {}; let n2 = 0; for (const i2 in this.constants) { const s2 = this.constants[i2]; let o2; r2 ? (o2 = a.getVariableType(s2, this.strictIntegers), this.constantTypes[i2] = o2) : o2 = this.constantTypes[i2]; const u2 = this.constructor.lookupKernelValueType(o2, "static", this.precision, s2); if (null === u2) return this.requestFallback(e2); const l2 = new u2(s2, { name: i2, type: o2, tactic: this.tactic, origin: "constants", context: this.context, checkContext: this.checkContext, kernel: this, strictIntegers: this.strictIntegers, onRequestTexture: () => this.createTexture(), onRequestIndex: () => n2++, onRequestContextHandle: () => t2.TEXTURE0 + this.constantTextureCount++ }); this.constantBitRatios[i2] = l2.bitRatio, this.kernelConstants.push(l2), l2.setup(), l2.forceUploadEachRun && this.forceUploadKernelConstants.push(l2); } } build() { if (this.built) return; if (this.initExtensions(), this.validateSettings(arguments), this.setupConstants(arguments), this.fallbackRequested) return; if (this.setupArguments(arguments), this.fallbackRequested) return; this.updateMaxTexSize(), this.translateSource(); const e2 = this.pickRenderStrategy(arguments); if (e2) return e2; const { texSize: t2, context: r2, canvas: n2 } = this; r2.enable(r2.SCISSOR_TEST), this.pipeline && this.precision, r2.viewport(0, 0, this.maxTexSize[0], this.maxTexSize[1]), n2.width = this.maxTexSize[0], n2.height = this.maxTexSize[1]; const i2 = this.threadDim = Array.from(this.output); for (; i2.length < 3; ) i2.push(1); const s2 = this.getVertexShader(arguments), a2 = r2.createShader(r2.VERTEX_SHADER); r2.shaderSource(a2, s2), r2.compileShader(a2), this.vertShader = a2; const o2 = this.getFragmentShader(arguments), u2 = r2.createShader(r2.FRAGMENT_SHADER); if (r2.shaderSource(u2, o2), r2.compileShader(u2), this.fragShader = u2, this.debug && (console.log("GLSL Shader Output:"), console.log(o2)), !r2.getShaderParameter(a2, r2.COMPILE_STATUS)) throw new Error("Error compiling vertex shader: " + r2.getShaderInfoLog(a2)); if (!r2.getShaderParameter(u2, r2.COMPILE_STATUS)) throw new Error("Error compiling fragment shader: " + r2.getShaderInfoLog(u2)); const l2 = this.program = r2.createProgram(); r2.attachShader(l2, a2), r2.attachShader(l2, u2), r2.linkProgram(l2), this.framebuffer = r2.createFramebuffer(), this.framebuffer.width = t2[0], this.framebuffer.height = t2[1], this.rawValueFramebuffers = {}; const h2 = new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), c2 = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]), p2 = h2.byteLength; let d2 = this.buffer; d2 ? r2.bindBuffer(r2.ARRAY_BUFFER, d2) : (d2 = this.buffer = r2.createBuffer(), r2.bindBuffer(r2.ARRAY_BUFFER, d2), r2.bufferData(r2.ARRAY_BUFFER, h2.byteLength + c2.byteLength, r2.STATIC_DRAW)), r2.bufferSubData(r2.ARRAY_BUFFER, 0, h2), r2.bufferSubData(r2.ARRAY_BUFFER, p2, c2); const m2 = r2.getAttribLocation(this.program, "aPos"); r2.enableVertexAttribArray(m2), r2.vertexAttribPointer(m2, 2, r2.FLOAT, false, 0, 0); const f2 = r2.getAttribLocation(this.program, "aTexCoord"); r2.enableVertexAttribArray(f2), r2.vertexAttribPointer(f2, 2, r2.FLOAT, false, 0, p2), r2.bindFramebuffer(r2.FRAMEBUFFER, this.framebuffer); let g2 = 0; r2.useProgram(this.program); for (let e3 in this.constants) this.kernelConstants[g2++].updateValue(this.constants[e3]); this._setupOutputTexture(), null !== this.subKernels && this.subKernels.length > 0 && (this._mappedTextureSwitched = {}, this._setupSubOutputTextures()), this.buildSignature(arguments), this.built = true; } translateSource() { const e2 = i.fromKernel(this, s, { fixIntegerDivisionAccuracy: this.fixIntegerDivisionAccuracy }); this.translatedSource = e2.getPrototypeString("kernel"), this.setupReturnTypes(e2); } setupReturnTypes(e2) { if (this.graphical || this.returnType || (this.returnType = e2.getKernelResultType()), this.subKernels && this.subKernels.length > 0) for (let t2 = 0; t2 < this.subKernels.length; t2++) { const r2 = this.subKernels[t2]; r2.returnType || (r2.returnType = e2.getSubKernelResultType(t2)); } } run() { const { kernelArguments: e2, texSize: t2, forceUploadKernelConstants: r2, context: n2 } = this; n2.useProgram(this.program), n2.scissor(0, 0, t2[0], t2[1]), this.dynamicOutput && (this.setUniform3iv("uOutputDim", new Int32Array(this.threadDim)), this.setUniform2iv("uTexSize", t2)), this.setUniform2f("ratio", t2[0] / this.maxTexSize[0], t2[1] / this.maxTexSize[1]); for (let e3 = 0; e3 < r2.length; e3++) { const t3 = r2[e3]; if (t3.updateValue(this.constants[t3.name]), this.switchingKernels) return; } for (let t3 = 0; t3 < e2.length; t3++) if (e2[t3].updateValue(arguments[t3]), this.switchingKernels) return; if (this.plugins) for (let e3 = 0; e3 < this.plugins.length; e3++) { const t3 = this.plugins[e3]; t3.onBeforeRun && t3.onBeforeRun(this); } if (this.graphical) return this.pipeline ? (n2.bindRenderbuffer(n2.RENDERBUFFER, null), n2.bindFramebuffer(n2.FRAMEBUFFER, this.framebuffer), this.immutable && this._replaceOutputTexture(), n2.drawArrays(n2.TRIANGLE_STRIP, 0, 4), this.immutable ? this.texture.clone() : this.texture) : (n2.bindRenderbuffer(n2.RENDERBUFFER, null), n2.bindFramebuffer(n2.FRAMEBUFFER, null), void n2.drawArrays(n2.TRIANGLE_STRIP, 0, 4)); n2.bindFramebuffer(n2.FRAMEBUFFER, this.framebuffer), this.immutable && this._replaceOutputTexture(), null !== this.subKernels && (this.immutable && this._replaceSubOutputTextures(), this.drawBuffers()), n2.drawArrays(n2.TRIANGLE_STRIP, 0, 4); } drawBuffers() { this.extensions.WEBGL_draw_buffers.drawBuffersWEBGL(this.drawBuffersMap); } getInternalFormat() { return this.context.RGBA; } getTextureFormat() { const { context: e2 } = this; if (this.getInternalFormat() === e2.RGBA) return e2.RGBA; throw new Error("Unknown internal format"); } _replaceOutputTexture() { if (this.texture.beforeMutate() || this._textureSwitched) { const e2 = this.context; e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0, e2.TEXTURE_2D, this.texture.texture, 0), this._textureSwitched = false; } } _setupOutputTexture() { const e2 = this.context, t2 = this.texSize; if (this.texture) return void e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0, e2.TEXTURE_2D, this.texture.texture, 0); const r2 = this.createTexture(); e2.activeTexture(e2.TEXTURE0 + this.constantTextureCount + this.argumentTextureCount), e2.bindTexture(e2.TEXTURE_2D, r2), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_WRAP_S, e2.CLAMP_TO_EDGE), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_WRAP_T, e2.CLAMP_TO_EDGE), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_MIN_FILTER, e2.NEAREST), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_MAG_FILTER, e2.NEAREST); const n2 = this.getInternalFormat(); "single" === this.precision ? e2.texImage2D(e2.TEXTURE_2D, 0, n2, t2[0], t2[1], 0, e2.RGBA, e2.FLOAT, null) : e2.texImage2D(e2.TEXTURE_2D, 0, n2, t2[0], t2[1], 0, n2, e2.UNSIGNED_BYTE, null), e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0, e2.TEXTURE_2D, r2, 0), this.texture = new this.TextureConstructor({ texture: r2, size: t2, dimensions: this.threadDim, output: this.output, context: this.context, internalFormat: this.getInternalFormat(), textureFormat: this.getTextureFormat(), kernel: this }); } _replaceSubOutputTextures() { const e2 = this.context; for (let t2 = 0; t2 < this.mappedTextures.length; t2++) { const r2 = this.mappedTextures[t2]; (r2.beforeMutate() || this._mappedTextureSwitched[t2]) && (e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0 + t2 + 1, e2.TEXTURE_2D, r2.texture, 0), this._mappedTextureSwitched[t2] = false); } } _setupSubOutputTextures() { const e2 = this.context; if (this.mappedTextures) { for (let t3 = 0; t3 < this.subKernels.length; t3++) e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0 + t3 + 1, e2.TEXTURE_2D, this.mappedTextures[t3].texture, 0); return; } const t2 = this.texSize; this.drawBuffersMap = [e2.COLOR_ATTACHMENT0], this.mappedTextures = []; for (let r2 = 0; r2 < this.subKernels.length; r2++) { const n2 = this.createTexture(); this.drawBuffersMap.push(e2.COLOR_ATTACHMENT0 + r2 + 1), e2.activeTexture(e2.TEXTURE0 + this.constantTextureCount + this.argumentTextureCount + r2), e2.bindTexture(e2.TEXTURE_2D, n2), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_WRAP_S, e2.CLAMP_TO_EDGE), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_WRAP_T, e2.CLAMP_TO_EDGE), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_MIN_FILTER, e2.NEAREST), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_MAG_FILTER, e2.NEAREST), "single" === this.precision ? e2.texImage2D(e2.TEXTURE_2D, 0, e2.RGBA, t2[0], t2[1], 0, e2.RGBA, e2.FLOAT, null) : e2.texImage2D(e2.TEXTURE_2D, 0, e2.RGBA, t2[0], t2[1], 0, e2.RGBA, e2.UNSIGNED_BYTE, null), e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0 + r2 + 1, e2.TEXTURE_2D, n2, 0), this.mappedTextures.push(new this.TextureConstructor({ texture: n2, size: t2, dimensions: this.threadDim, output: this.output, context: this.context, internalFormat: this.getInternalFormat(), textureFormat: this.getTextureFormat(), kernel: this })); } } setUniform1f(e2, t2) { if (this.uniform1fCache.hasOwnProperty(e2)) { if (t2 === this.uniform1fCache[e2]) return; } this.uniform1fCache[e2] = t2; const r2 = this.getUniformLocation(e2); this.context.uniform1f(r2, t2); } setUniform1i(e2, t2) { if (this.uniform1iCache.hasOwnProperty(e2)) { if (t2 === this.uniform1iCache[e2]) return; } this.uniform1iCache[e2] = t2; const r2 = this.getUniformLocation(e2); this.context.uniform1i(r2, t2); } setUniform2f(e2, t2, r2) { if (this.uniform2fCache.hasOwnProperty(e2)) { const n3 = this.uniform2fCache[e2]; if (t2 === n3[0] && r2 === n3[1]) return; } this.uniform2fCache[e2] = [t2, r2]; const n2 = this.getUniformLocation(e2); this.context.uniform2f(n2, t2, r2); } setUniform2fv(e2, t2) { if (this.uniform2fvCache.hasOwnProperty(e2)) { const r3 = this.uniform2fvCache[e2]; if (t2[0] === r3[0] && t2[1] === r3[1]) return; } this.uniform2fvCache[e2] = t2; const r2 = this.getUniformLocation(e2); this.context.uniform2fv(r2, t2); } setUniform2iv(e2, t2) { if (this.uniform2ivCache.hasOwnProperty(e2)) { const r3 = this.uniform2ivCache[e2]; if (t2[0] === r3[0] && t2[1] === r3[1]) return; } this.uniform2ivCache[e2] = t2; const r2 = this.getUniformLocation(e2); this.context.uniform2iv(r2, t2); } setUniform3fv(e2, t2) { if (this.uniform3fvCache.hasOwnProperty(e2)) { const r3 = this.uniform3fvCache[e2]; if (t2[0] === r3[0] && t2[1] === r3[1] && t2[2] === r3[2]) return; } this.uniform3fvCache[e2] = t2; const r2 = this.getUniformLocation(e2); this.context.uniform3fv(r2, t2); } setUniform3iv(e2, t2) { if (this.uniform3ivCache.hasOwnProperty(e2)) { const r3 = this.uniform3ivCache[e2]; if (t2[0] === r3[0] && t2[1] === r3[1] && t2[2] === r3[2]) return; } this.uniform3ivCache[e2] = t2; const r2 = this.getUniformLocation(e2); this.context.uniform3iv(r2, t2); } setUniform4fv(e2, t2) { if (this.uniform4fvCache.hasOwnProperty(e2)) { const r3 = this.uniform4fvCache[e2]; if (t2[0] === r3[0] && t2[1] === r3[1] && t2[2] === r3[2] && t2[3] === r3[3]) return; } this.uniform4fvCache[e2] = t2; const r2 = this.getUniformLocation(e2); this.context.uniform4fv(r2, t2); } setUniform4iv(e2, t2) { if (this.uniform4ivCache.hasOwnProperty(e2)) { const r3 = this.uniform4ivCache[e2]; if (t2[0] === r3[0] && t2[1] === r3[1] && t2[2] === r3[2] && t2[3] === r3[3]) return; } this.uniform4ivCache[e2] = t2; const r2 = this.getUniformLocation(e2); this.context.uniform4iv(r2, t2); } getUniformLocation(e2) { return this.programUniformLocationCache.hasOwnProperty(e2) ? this.programUniformLocationCache[e2] : this.programUniformLocationCache[e2] = this.context.getUniformLocation(this.program, e2); } _getFragShaderArtifactMap(e2) { return { HEADER: this._getHeaderString(), LOOP_MAX: this._getLoopMaxString(), PLUGINS: this._getPluginsString(), CONSTANTS: this._getConstantsString(), DECODE32_ENDIANNESS: this._getDecode32EndiannessString(), ENCODE32_ENDIANNESS: this._getEncode32EndiannessString(), DIVIDE_WITH_INTEGER_CHECK: this._getDivideWithIntegerCheckString(), INJECTED_NATIVE: this._getInjectedNative(), MAIN_CONSTANTS: this._getMainConstantsString(), MAIN_ARGUMENTS: this._getMainArgumentsString(e2), KERNEL: this.getKernelString(), MAIN_RESULT: this.getMainResultString(), FLOAT_TACTIC_DECLARATION: this.getFloatTacticDeclaration(), INT_TACTIC_DECLARATION: this.getIntTacticDeclaration(), SAMPLER_2D_TACTIC_DECLARATION: this.getSampler2DTacticDeclaration(), SAMPLER_2D_ARRAY_TACTIC_DECLARATION: this.getSampler2DArrayTacticDeclaration() }; } _getVertShaderArtifactMap(e2) { return { FLOAT_TACTIC_DECLARATION: this.getFloatTacticDeclaration(), INT_TACTIC_DECLARATION: this.getIntTacticDeclaration(), SAMPLER_2D_TACTIC_DECLARATION: this.getSampler2DTacticDeclaration(), SAMPLER_2D_ARRAY_TACTIC_DECLARATION: this.getSampler2DArrayTacticDeclaration() }; } _getHeaderString() { return null !== this.subKernels ? "#extension GL_EXT_draw_buffers : require\n" : ""; } _getLoopMaxString() { return this.loopMaxIterations ? ` ${parseInt(this.loopMaxIterations)}; ` : " 1000;\n"; } _getPluginsString() { return this.plugins ? this.plugins.map((e2) => e2.source && this.source.match(e2.functionMatch) ? e2.source : "").join("\n") : "\n"; } _getConstantsString() { const e2 = [], { threadDim: t2, texSize: r2 } = this; return this.dynamicOutput ? e2.push("uniform ivec3 uOutputDim", "uniform ivec2 uTexSize") : e2.push(`ivec3 uOutputDim = ivec3(${t2[0]}, ${t2[1]}, ${t2[2]})`, `ivec2 uTexSize = ivec2(${r2[0]}, ${r2[1]})`), a.linesToString(e2); } _getTextureCoordinate() { const e2 = this.subKernels; return null === e2 || e2.length < 1 ? "varying vec2 vTexCoord;\n" : "out vec2 vTexCoord;\n"; } _getDecode32EndiannessString() { return "LE" === this.endianness ? "" : " texel.rgba = texel.abgr;\n"; } _getEncode32EndiannessString() { return "LE" === this.endianness ? "" : " texel.rgba = texel.abgr;\n"; } _getDivideWithIntegerCheckString() { return this.fixIntegerDivisionAccuracy ? "float divWithIntCheck(float x, float y) {\n if (floor(x) == x && floor(y) == y && integerMod(x, y) == 0.0) {\n return float(int(x) / int(y));\n }\n return x / y;\n}\n\nfloat integerCorrectionModulo(float number, float divisor) {\n if (number < 0.0) {\n number = abs(number);\n if (divisor < 0.0) {\n divisor = abs(divisor);\n }\n return -(number - (divisor * floor(divWithIntCheck(number, divisor))));\n }\n if (divisor < 0.0) {\n divisor = abs(divisor);\n }\n return number - (divisor * floor(divWithIntCheck(number, divisor)));\n}" : ""; } _getMainArgumentsString(e2) { const t2 = [], { argumentNames: r2 } = this; for (let n2 = 0; n2 < r2.length; n2++) t2.push(this.kernelArguments[n2].getSource(e2[n2])); return t2.join(""); } _getInjectedNative() { return this.injectedNative || ""; } _getMainConstantsString() { const e2 = [], { constants: t2 } = this; if (t2) { let r2 = 0; for (const n2 in t2) this.constants.hasOwnProperty(n2) && e2.push(this.kernelConstants[r2++].getSource(this.constants[n2])); } return e2.join(""); } getRawValueFramebuffer(e2, t2) { if (this.rawValueFramebuffers[e2] || (this.rawValueFramebuffers[e2] = {}), !this.rawValueFramebuffers[e2][t2]) { const r2 = this.context.createFramebuffer(); r2.width = e2, r2.height = t2, this.rawValueFramebuffers[e2][t2] = r2; } return this.rawValueFramebuffers[e2][t2]; } getKernelResultDeclaration() { switch (this.returnType) { case "Array(2)": return "vec2 kernelResult"; case "Array(3)": return "vec3 kernelResult"; case "Array(4)": return "vec4 kernelResult"; case "LiteralInteger": case "Float": case "Number": case "Integer": return "float kernelResult"; default: if (this.graphical) return "float kernelResult"; throw new Error(`unrecognized output type "${this.returnType}"`); } } getKernelString() { const e2 = [this.getKernelResultDeclaration()], { subKernels: t2 } = this; if (null !== t2) switch (this.returnType) { case "Number": case "Float": case "Integer": for (let r2 = 0; r2 < t2.length; r2++) { const n2 = t2[r2]; e2.push("Integer" === n2.returnType ? `int subKernelResult_${n2.name} = 0` : `float subKernelResult_${n2.name} = 0.0`); } break; case "Array(2)": for (let r2 = 0; r2 < t2.length; r2++) e2.push(`vec2 subKernelResult_${t2[r2].name}`); break; case "Array(3)": for (let r2 = 0; r2 < t2.length; r2++) e2.push(`vec3 subKernelResult_${t2[r2].name}`); break; case "Array(4)": for (let r2 = 0; r2 < t2.length; r2++) e2.push(`vec4 subKernelResult_${t2[r2].name}`); } return a.linesToString(e2) + this.translatedSource; } getMainResultGraphical() { return a.linesToString([" threadId = indexTo3D(index, uOutputDim)", " kernel()", " gl_FragColor = actualColor"]); } getMainResultPackedPixels() { switch (this.returnType) { case "LiteralInteger": case "Number": case "Integer": case "Float": return this.getMainResultKernelPackedPixels() + this.getMainResultSubKernelPackedPixels(); default: throw new Error(`packed output only usable with Numbers, "${this.returnType}" specified`); } } getMainResultKernelPackedPixels() { return a.linesToString([" threadId = indexTo3D(index, uOutputDim)", " kernel()", ` gl_FragData[0] = ${this.useLegacyEncoder ? "legacyEncode32" : "encode32"}(kernelResult)`]); } getMainResultSubKernelPackedPixels() { const e2 = []; if (!this.subKernels) return ""; for (let t2 = 0; t2 < this.subKernels.length; t2++) { "Integer" === this.subKernels[t2].returnType ? e2.push(` gl_FragData[${t2 + 1}] = ${this.useLegacyEncoder ? "legacyEncode32" : "encode32"}(float(subKernelResult_${this.subKernels[t2].name}))`) : e2.push(` gl_FragData[${t2 + 1}] = ${this.useLegacyEncoder ? "legacyEncode32" : "encode32"}(subKernelResult_${this.subKernels[t2].name})`); } return a.linesToString(e2); } getMainResultMemoryOptimizedFloats() { const e2 = [" index *= 4"]; switch (this.returnType) { case "Number": case "Integer": case "Float": const t2 = ["r", "g", "b", "a"]; for (let r2 = 0; r2 < t2.length; r2++) { const n2 = t2[r2]; this.getMainResultKernelMemoryOptimizedFloats(e2, n2), this.getMainResultSubKernelMemoryOptimizedFloats(e2, n2), r2 + 1 < t2.length && e2.push(" index += 1"); } break; default: throw new Error(`optimized output only usable with Numbers, ${this.returnType} specified`); } return a.linesToString(e2); } getMainResultKernelMemoryOptimizedFloats(e2, t2) { e2.push(" threadId = indexTo3D(index, uOutputDim)", " kernel()", ` gl_FragData[0].${t2} = kernelResult`); } getMainResultSubKernelMemoryOptimizedFloats(e2, t2) { if (!this.subKernels) return e2; for (let r2 = 0; r2 < this.subKernels.length; r2++) { "Integer" === this.subKernels[r2].returnType ? e2.push(` gl_FragData[${r2 + 1}].${t2} = float(subKernelResult_${this.subKernels[r2].name})`) : e2.push(` gl_FragData[${r2 + 1}].${t2} = subKernelResult_${this.subKernels[r2].name}`); } } getMainResultKernelNumberTexture() { return [" threadId = indexTo3D(index, uOutputDim)", " kernel()", " gl_FragData[0][0] = kernelResult"]; } getMainResultSubKernelNumberTexture() { const e2 = []; if (!this.subKernels) return e2; for (let t2 = 0; t2 < this.subKernels.length; ++t2) { const r2 = this.subKernels[t2]; "Integer" === r2.returnType ? e2.push(` gl_FragData[${t2 + 1}][0] = float(subKernelResult_${r2.name})`) : e2.push(` gl_FragData[${t2 + 1}][0] = subKernelResult_${r2.name}`); } return e2; } getMainResultKernelArray2Texture() { return [" threadId = indexTo3D(index, uOutputDim)", " kernel()", " gl_FragData[0][0] = kernelResult[0]", " gl_FragData[0][1] = kernelResult[1]"]; } getMainResultSubKernelArray2Texture() { const e2 = []; if (!this.subKernels) return e2; for (let t2 = 0; t2 < this.subKernels.length; ++t2) e2.push(` gl_FragData[${t2 + 1}][0] = subKernelResult_${this.subKernels[t2].name}[0]`, ` gl_FragData[${t2 + 1}][1] = subKernelResult_${this.subKernels[t2].name}[1]`); return e2; } getMainResultKernelArray3Texture() { return [" threadId = indexTo3D(index, uOutputDim)", " kernel()", " gl_FragData[0][0] = kernelResult[0]", " gl_FragData[0][1] = kernelResult[1]", " gl_FragData[0][2] = kernelResult[2]"]; } getMainResultSubKernelArray3Texture() { const e2 = []; if (!this.subKernels) return e2; for (let t2 = 0; t2 < this.subKernels.length; ++t2) e2.push(` gl_FragData[${t2 + 1}][0] = subKernelResult_${this.subKernels[t2].name}[0]`, ` gl_FragData[${t2 + 1}][1] = subKernelResult_${this.subKernels[t2].name}[1]`, ` gl_FragData[${t2 + 1}][2] = subKernelResult_${this.subKernels[t2].name}[2]`); return e2; } getMainResultKernelArray4Texture() { return [" threadId = indexTo3D(index, uOutputDim)", " kernel()", " gl_FragData[0] = kernelResult"]; } getMainResultSubKernelArray4Texture() { const e2 = []; if (!this.subKernels) return e2; switch (this.returnType) { case "Number": case "Float": case "Integer": for (let t2 = 0; t2 < this.subKernels.length; ++t2) { "Integer" === this.subKernels[t2].returnType ? e2.push(` gl_FragData[${t2 + 1}] = float(subKernelResult_${this.subKernels[t2].name})`) : e2.push(` gl_FragData[${t2 + 1}] = subKernelResult_${this.subKernels[t2].name}`); } break; case "Array(2)": for (let t2 = 0; t2 < this.subKernels.length; ++t2) e2.push(` gl_FragData[${t2 + 1}][0] = subKernelResult_${this.subKernels[t2].name}[0]`, ` gl_FragData[${t2 + 1}][1] = subKernelResult_${this.subKernels[t2].name}[1]`); break; case "Array(3)": for (let t2 = 0; t2 < this.subKernels.length; ++t2) e2.push(` gl_FragData[${t2 + 1}][0] = subKernelResult_${this.subKernels[t2].name}[0]`, ` gl_FragData[${t2 + 1}][1] = subKernelResult_${this.subKernels[t2].name}[1]`, ` gl_FragData[${t2 + 1}][2] = subKernelResult_${this.subKernels[t2].name}[2]`); break; case "Array(4)": for (let t2 = 0; t2 < this.subKernels.length; ++t2) e2.push(` gl_FragData[${t2 + 1}][0] = subKernelResult_${this.subKernels[t2].name}[0]`, ` gl_FragData[${t2 + 1}][1] = subKernelResult_${this.subKernels[t2].name}[1]`, ` gl_FragData[${t2 + 1}][2] = subKernelResult_${this.subKernels[t2].name}[2]`, ` gl_FragData[${t2 + 1}][3] = subKernelResult_${this.subKernels[t2].name}[3]`); } return e2; } replaceArtifacts(e2, t2) { return e2.replace(/[ ]*__([A-Z]+[0-9]*([_]?[A-Z]*[0-9]?)*)__;\n/g, (e3, r2) => { if (t2.hasOwnProperty(r2)) return t2[r2]; throw `unhandled artifact ${r2}`; }); } getFragmentShader(e2) { return null !== this.compiledFragmentShader ? this.compiledFragmentShader : this.compiledFragmentShader = this.replaceArtifacts(this.constructor.fragmentShader, this._getFragShaderArtifactMap(e2)); } getVertexShader(e2) { return null !== this.compiledVertexShader ? this.compiledVertexShader : this.compiledVertexShader = this.replaceArtifacts(this.constructor.vertexShader, this._getVertShaderArtifactMap(e2)); } toString() { const e2 = a.linesToString(["const gl = context"]); return h(this.constructor, arguments, this, e2); } destroy(e2) { if (!this.context) return; this.buffer && this.context.deleteBuffer(this.buffer), this.framebuffer && this.context.deleteFramebuffer(this.framebuffer); for (const e3 in this.rawValueFramebuffers) { for (const t3 in this.rawValueFramebuffers[e3]) this.context.deleteFramebuffer(this.rawValueFramebuffers[e3][t3]), delete this.rawValueFramebuffers[e3][t3]; delete this.rawValueFramebuffers[e3]; } if (this.vertShader && this.context.deleteShader(this.vertShader), this.fragShader && this.context.deleteShader(this.fragShader), this.program && this.context.deleteProgram(this.program), this.texture) { this.texture.delete(); const e3 = this.textureCache.indexOf(this.texture.texture); e3 > -1 && this.textureCache.splice(e3, 1), this.texture = null; } if (this.mappedTextures && this.mappedTextures.length) { for (let e3 = 0; e3 < this.mappedTextures.length; e3++) { const t3 = this.mappedTextures[e3]; t3.delete(); const r2 = this.textureCache.indexOf(t3.texture); r2 > -1 && this.textureCache.splice(r2, 1); } this.mappedTextures = null; } if (this.kernelArguments) for (let e3 = 0; e3 < this.kernelArguments.length; e3++) this.kernelArguments[e3].destroy(); if (this.kernelConstants) for (let e3 = 0; e3 < this.kernelConstants.length; e3++) this.kernelConstants[e3].destroy(); for (; this.textureCache.length > 0; ) { const e3 = this.textureCache.pop(); this.context.deleteTexture(e3); } if (e2) { const e3 = y.indexOf(this.canvas); e3 >= 0 && (y[e3] = null, b[e3] = null); } if (this.destroyExtensions(), delete this.context, delete this.canvas, !this.gpu) return; const t2 = this.gpu.kernels.indexOf(this); -1 !== t2 && this.gpu.kernels.splice(t2, 1); } destroyExtensions() { this.extensions.OES_texture_float = null, this.extensions.OES_texture_float_linear = null, this.extensions.OES_element_index_uint = null, this.extensions.WEBGL_draw_buffers = null; } static destroyContext(e2) { const t2 = e2.getExtension("WEBGL_lose_context"); t2 && t2.loseContext(); } toJSON() { const e2 = super.toJSON(); return e2.functionNodes = i.fromKernel(this, s).toJSON(), e2.settings.threadDim = this.threadDim, e2; } } }; }, { "../../plugins/math-random-uniformly-distributed": 112, "../../utils": 114, "../function-builder": 9, "../gl/kernel": 13, "../gl/kernel-string": 12, "./fragment-shader": 37, "./function-node": 38, "./kernel-value-maps": 39, "./vertex-shader": 71 }], 71: [function(e, t, r) { t.exports = { vertexShader: "__FLOAT_TACTIC_DECLARATION__;\n__INT_TACTIC_DECLARATION__;\n__SAMPLER_2D_TACTIC_DECLARATION__;\n\nattribute vec2 aPos;\nattribute vec2 aTexCoord;\n\nvarying vec2 vTexCoord;\nuniform vec2 ratio;\n\nvoid main(void) {\n gl_Position = vec4((aPos + vec2(1)) * ratio + vec2(-1), 0, 1);\n vTexCoord = aTexCoord;\n}" }; }, {}], 72: [function(e, t, r) { const n = `#version 300 es __HEADER__; __FLOAT_TACTIC_DECLARATION__; __INT_TACTIC_DECLARATION__; __SAMPLER_2D_TACTIC_DECLARATION__; __SAMPLER_2D_ARRAY_TACTIC_DECLARATION__; const int LOOP_MAX = __LOOP_MAX__; __PLUGINS__; __CONSTANTS__; in vec2 vTexCoord; float atan2(float v1, float v2) { if (v1 == 0.0 || v2 == 0.0) return 0.0; return atan(v1 / v2); } float cbrt(float x) { if (x >= 0.0) { return pow(x, 1.0 / 3.0); } else { return -pow(x, 1.0 / 3.0); } } float expm1(float x) { return pow(${Math.E}, x) - 1.0; } float fround(highp float x) { return x; } float imul(float v1, float v2) { return float(int(v1) * int(v2)); } float log10(float x) { return log2(x) * (1.0 / log2(10.0)); } float log1p(float x) { return log(1.0 + x); } float _pow(float v1, float v2) { if (v2 == 0.0) return 1.0; return pow(v1, v2); } float _round(float x) { return floor(x + 0.5); } const int BIT_COUNT = 32; int modi(int x, int y) { return x - y * (x / y); } int bitwiseOr(int a, int b) { int result = 0; int n = 1; for (int i = 0; i < BIT_COUNT; i++) { if ((modi(a, 2) == 1) || (modi(b, 2) == 1)) { result += n; } a = a / 2; b = b / 2; n = n * 2; if(!(a > 0 || b > 0)) { break; } } return result; } int bitwiseXOR(int a, int b) { int result = 0; int n = 1; for (int i = 0; i < BIT_COUNT; i++) { if ((modi(a, 2) == 1) != (modi(b, 2) == 1)) { result += n; } a = a / 2; b = b / 2; n = n * 2; if(!(a > 0 || b > 0)) { break; } } return result; } int bitwiseAnd(int a, int b) { int result = 0; int n = 1; for (int i = 0; i < BIT_COUNT; i++) { if ((modi(a, 2) == 1) && (modi(b, 2) == 1)) { result += n; } a = a / 2; b = b / 2; n = n * 2; if(!(a > 0 && b > 0)) { break; } } return result; } int bitwiseNot(int a) { int result = 0; int n = 1; for (int i = 0; i < BIT_COUNT; i++) { if (modi(a, 2) == 0) { result += n; } a = a / 2; n = n * 2; } return result; } int bitwiseZeroFillLeftShift(int n, int shift) { int maxBytes = BIT_COUNT; for (int i = 0; i < BIT_COUNT; i++) { if (maxBytes >= n) { break; } maxBytes *= 2; } for (int i = 0; i < BIT_COUNT; i++) { if (i >= shift) { break; } n *= 2; } int result = 0; int byteVal = 1; for (int i = 0; i < BIT_COUNT; i++) { if (i >= maxBytes) break; if (modi(n, 2) > 0) { result += byteVal; } n = int(n / 2); byteVal *= 2; } return result; } int bitwiseSignedRightShift(int num, int shifts) { return int(floor(float(num) / pow(2.0, float(shifts)))); } int bitwiseZeroFillRightShift(int n, int shift) { int maxBytes = BIT_COUNT; for (int i = 0; i < BIT_COUNT; i++) { if (maxBytes >= n) { break; } maxBytes *= 2; } for (int i = 0; i < BIT_COUNT; i++) { if (i >= shift) { break; } n /= 2; } int result = 0; int byteVal = 1; for (int i = 0; i < BIT_COUNT; i++) { if (i >= maxBytes) break; if (modi(n, 2) > 0) { result += byteVal; } n = int(n / 2); byteVal *= 2; } return result; } vec2 integerMod(vec2 x, float y) { vec2 res = floor(mod(x, y)); return res * step(1.0 - floor(y), -res); } vec3 integerMod(vec3 x, float y) { vec3 res = floor(mod(x, y)); return res * step(1.0 - floor(y), -res); } vec4 integerMod(vec4 x, vec4 y) { vec4 res = floor(mod(x, y)); return res * step(1.0 - floor(y), -res); } float integerMod(float x, float y) { float res = floor(mod(x, y)); return res * (res > floor(y) - 1.0 ? 0.0 : 1.0); } int integerMod(int x, int y) { return x - (y * int(x/y)); } __DIVIDE_WITH_INTEGER_CHECK__; // Here be dragons! // DO NOT OPTIMIZE THIS CODE // YOU WILL BREAK SOMETHING ON SOMEBODY'S MACHINE // LEAVE IT AS IT IS, LEST YOU WASTE YOUR OWN TIME const vec2 MAGIC_VEC = vec2(1.0, -256.0); const vec4 SCALE_FACTOR = vec4(1.0, 256.0, 65536.0, 0.0); const vec4 SCALE_FACTOR_INV = vec4(1.0, 0.00390625, 0.0000152587890625, 0.0); // 1, 1/256, 1/65536 float decode32(vec4 texel) { __DECODE32_ENDIANNESS__; texel *= 255.0; vec2 gte128; gte128.x = texel.b >= 128.0 ? 1.0 : 0.0; gte128.y = texel.a >= 128.0 ? 1.0 : 0.0; float exponent = 2.0 * texel.a - 127.0 + dot(gte128, MAGIC_VEC); float res = exp2(round(exponent)); texel.b = texel.b - 128.0 * gte128.x; res = dot(texel, SCALE_FACTOR) * exp2(round(exponent-23.0)) + res; res *= gte128.y * -2.0 + 1.0; return res; } float decode16(vec4 texel, int index) { int channel = integerMod(index, 2); return texel[channel*2] * 255.0 + texel[channel*2 + 1] * 65280.0; } float decode8(vec4 texel, int index) { int channel = integerMod(index, 4); return texel[channel] * 255.0; } vec4 legacyEncode32(float f) { float F = abs(f); float sign = f < 0.0 ? 1.0 : 0.0; float exponent = floor(log2(F)); float mantissa = (exp2(-exponent) * F); // exponent += floor(log2(mantissa)); vec4 texel = vec4(F * exp2(23.0-exponent)) * SCALE_FACTOR_INV; texel.rg = integerMod(texel.rg, 256.0); texel.b = integerMod(texel.b, 128.0); texel.a = exponent*0.5 + 63.5; texel.ba += vec2(integerMod(exponent+127.0, 2.0), sign) * 128.0; texel = floor(texel); texel *= 0.003921569; // 1/255 __ENCODE32_ENDIANNESS__; return texel; } // https://github.com/gpujs/gpu.js/wiki/Encoder-details vec4 encode32(float value) { if (value == 0.0) return vec4(0, 0, 0, 0); float exponent; float mantissa; vec4 result; float sgn; sgn = step(0.0, -value); value = abs(value); exponent = floor(log2(value)); mantissa = value*pow(2.0, -exponent)-1.0; exponent = exponent+127.0; result = vec4(0,0,0,0); result.a = floor(exponent/2.0); exponent = exponent - result.a*2.0; result.a = result.a + 128.0*sgn; result.b = floor(mantissa * 128.0); mantissa = mantissa - result.b / 128.0; result.b = result.b + exponent*128.0; result.g = floor(mantissa*32768.0); mantissa = mantissa - result.g/32768.0; result.r = floor(mantissa*8388608.0); return result/255.0; } // Dragons end here int index; ivec3 threadId; ivec3 indexTo3D(int idx, ivec3 texDim) { int z = int(idx / (texDim.x * texDim.y)); idx -= z * int(texDim.x * texDim.y); int y = int(idx / texDim.x); int x = int(integerMod(idx, texDim.x)); return ivec3(x, y, z); } float get32(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + texDim.x * (y + texDim.y * z); int w = texSize.x; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; vec4 texel = texture(tex, st / vec2(texSize)); return decode32(texel); } float get16(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + (texDim.x * (y + (texDim.y * z))); int w = texSize.x * 2; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; vec4 texel = texture(tex, st / vec2(texSize.x * 2, texSize.y)); return decode16(texel, index); } float get8(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + (texDim.x * (y + (texDim.y * z))); int w = texSize.x * 4; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; vec4 texel = texture(tex, st / vec2(texSize.x * 4, texSize.y)); return decode8(texel, index); } float getMemoryOptimized32(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + (texDim.x * (y + (texDim.y * z))); int channel = integerMod(index, 4); index = index / 4; int w = texSize.x; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; index = index / 4; vec4 texel = texture(tex, st / vec2(texSize)); return texel[channel]; } vec4 getImage2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + texDim.x * (y + texDim.y * z); int w = texSize.x; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; return texture(tex, st / vec2(texSize)); } vec4 getImage3D(sampler2DArray tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + texDim.x * (y + texDim.y * z); int w = texSize.x; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; return texture(tex, vec3(st / vec2(texSize), z)); } float getFloatFromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { vec4 result = getImage2D(tex, texSize, texDim, z, y, x); return result[0]; } vec2 getVec2FromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { vec4 result = getImage2D(tex, texSize, texDim, z, y, x); return vec2(result[0], result[1]); } vec2 getMemoryOptimizedVec2(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + texDim.x * (y + texDim.y * z); int channel = integerMod(index, 2); index = index / 2; int w = texSize.x; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; vec4 texel = texture(tex, st / vec2(texSize)); if (channel == 0) return vec2(texel.r, texel.g); if (channel == 1) return vec2(texel.b, texel.a); return vec2(0.0, 0.0); } vec3 getVec3FromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { vec4 result = getImage2D(tex, texSize, texDim, z, y, x); return vec3(result[0], result[1], result[2]); } vec3 getMemoryOptimizedVec3(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int fieldIndex = 3 * (x + texDim.x * (y + texDim.y * z)); int vectorIndex = fieldIndex / 4; int vectorOffset = fieldIndex - vectorIndex * 4; int readY = vectorIndex / texSize.x; int readX = vectorIndex - readY * texSize.x; vec4 tex1 = texture(tex, (vec2(readX, readY) + 0.5) / vec2(texSize)); if (vectorOffset == 0) { return tex1.xyz; } else if (vectorOffset == 1) { return tex1.yzw; } else { readX++; if (readX >= texSize.x) { readX = 0; readY++; } vec4 tex2 = texture(tex, vec2(readX, readY) / vec2(texSize)); if (vectorOffset == 2) { return vec3(tex1.z, tex1.w, tex2.x); } else { return vec3(tex1.w, tex2.x, tex2.y); } } } vec4 getVec4FromSampler2D(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { return getImage2D(tex, texSize, texDim, z, y, x); } vec4 getMemoryOptimizedVec4(sampler2D tex, ivec2 texSize, ivec3 texDim, int z, int y, int x) { int index = x + texDim.x * (y + texDim.y * z); int channel = integerMod(index, 2); int w = texSize.x; vec2 st = vec2(float(integerMod(index, w)), float(index / w)) + 0.5; vec4 texel = texture(tex, st / vec2(texSize)); return vec4(texel.r, texel.g, texel.b, texel.a); } vec4 actualColor; void color(float r, float g, float b, float a) { actualColor = vec4(r,g,b,a); } void color(float r, float g, float b) { color(r,g,b,1.0); } float modulo(float number, float divisor) { if (number < 0.0) { number = abs(number); if (divisor < 0.0) { divisor = abs(divisor); } return -mod(number, divisor); } if (divisor < 0.0) { divisor = abs(divisor); } return mod(number, divisor); } __INJECTED_NATIVE__; __MAIN_CONSTANTS__; __MAIN_ARGUMENTS__; __KERNEL__; void main(void) { index = int(vTexCoord.s * float(uTexSize.x)) + int(vTexCoord.t * float(uTexSize.y)) * uTexSize.x; __MAIN_RESULT__; }`; t.exports = { fragmentShader: n }; }, {}], 73: [function(e, t, r) { const { utils: n } = e("../../utils"), { WebGLFunctionNode: i } = e("../web-gl/function-node"); t.exports = { WebGL2FunctionNode: class extends i { astIdentifierExpression(e2, t2) { if ("Identifier" !== e2.type) throw this.astErrorOutput("IdentifierExpression - not an Identifier", e2); const r2 = this.getType(e2), i2 = n.sanitizeName(e2.name); return "Infinity" === e2.name ? t2.push("intBitsToFloat(2139095039)") : "Boolean" === r2 && this.argumentNames.indexOf(i2) > -1 ? t2.push(`bool(user_${i2})`) : t2.push(`user_${i2}`), t2; } } }; }, { "../../utils": 114, "../web-gl/function-node": 38 }], 74: [function(e, t, r) { const { WebGL2KernelValueBoolean: n } = e("./kernel-value/boolean"), { WebGL2KernelValueFloat: i } = e("./kernel-value/float"), { WebGL2KernelValueInteger: s } = e("./kernel-value/integer"), { WebGL2KernelValueHTMLImage: a } = e("./kernel-value/html-image"), { WebGL2KernelValueDynamicHTMLImage: o } = e("./kernel-value/dynamic-html-image"), { WebGL2KernelValueHTMLImageArray: u } = e("./kernel-value/html-image-array"), { WebGL2KernelValueDynamicHTMLImageArray: l } = e("./kernel-value/dynamic-html-image-array"), { WebGL2KernelValueHTMLVideo: h } = e("./kernel-value/html-video"), { WebGL2KernelValueDynamicHTMLVideo: c } = e("./kernel-value/dynamic-html-video"), { WebGL2KernelValueSingleInput: p } = e("./kernel-value/single-input"), { WebGL2KernelValueDynamicSingleInput: d } = e("./kernel-value/dynamic-single-input"), { WebGL2KernelValueUnsignedInput: m } = e("./kernel-value/unsigned-input"), { WebGL2KernelValueDynamicUnsignedInput: f } = e("./kernel-value/dynamic-unsigned-input"), { WebGL2KernelValueMemoryOptimizedNumberTexture: g } = e("./kernel-value/memory-optimized-number-texture"), { WebGL2KernelValueDynamicMemoryOptimizedNumberTexture: x } = e("./kernel-value/dynamic-memory-optimized-number-texture"), { WebGL2KernelValueNumberTexture: y } = e("./kernel-value/number-texture"), { WebGL2KernelValueDynamicNumberTexture: b } = e("./kernel-value/dynamic-number-texture"), { WebGL2KernelValueSingleArray: T } = e("./kernel-value/single-array"), { WebGL2KernelValueDynamicSingleArray: v } = e("./kernel-value/dynamic-single-array"), { WebGL2KernelValueSingleArray1DI: S } = e("./kernel-value/single-array1d-i"), { WebGL2KernelValueDynamicSingleArray1DI: A } = e("./kernel-value/dynamic-single-array1d-i"), { WebGL2KernelValueSingleArray2DI: _ } = e("./kernel-value/single-array2d-i"), { WebGL2KernelValueDynamicSingleArray2DI: E } = e("./kernel-value/dynamic-single-array2d-i"), { WebGL2KernelValueSingleArray3DI: w } = e("./kernel-value/single-array3d-i"), { WebGL2KernelValueDynamicSingleArray3DI: k } = e("./kernel-value/dynamic-single-array3d-i"), { WebGL2KernelValueArray2: I } = e("./kernel-value/array2"), { WebGL2KernelValueArray3: D } = e("./kernel-value/array3"), { WebGL2KernelValueArray4: C } = e("./kernel-value/array4"), { WebGL2KernelValueUnsignedArray: $ } = e("./kernel-value/unsigned-array"), { WebGL2KernelValueDynamicUnsignedArray: L } = e("./kernel-value/dynamic-unsigned-array"), R = { unsigned: { dynamic: { Boolean: n, Integer: s, Float: i, Array: L, "Array(2)": I, "Array(3)": D, "Array(4)": C, "Array1D(2)": false, "Array1D(3)": false, "Array1D(4)": false, "Array2D(2)": false, "Array2D(3)": false, "Array2D(4)": false, "Array3D(2)": false, "Array3D(3)": false, "Array3D(4)": false, Input: f, NumberTexture: b, "ArrayTexture(1)": b, "ArrayTexture(2)": b, "ArrayTexture(3)": b, "ArrayTexture(4)": b, MemoryOptimizedNumberTexture: x, HTMLCanvas: o, OffscreenCanvas: o, HTMLImage: o, ImageBitmap: o, ImageData: o, HTMLImageArray: l, HTMLVideo: c }, static: { Boolean: n, Float: i, Integer: s, Array: $, "Array(2)": I, "Array(3)": D, "Array(4)": C, "Array1D(2)": false, "Array1D(3)": false, "Array1D(4)": false, "Array2D(2)": false, "Array2D(3)": false, "Array2D(4)": false, "Array3D(2)": false, "Array3D(3)": false, "Array3D(4)": false, Input: m, NumberTexture: y, "ArrayTexture(1)": y, "ArrayTexture(2)": y, "ArrayTexture(3)": y, "ArrayTexture(4)": y, MemoryOptimizedNumberTexture: x, HTMLCanvas: a, OffscreenCanvas: a, HTMLImage: a, ImageBitmap: a, ImageData: a, HTMLImageArray: u, HTMLVideo: h } }, single: { dynamic: { Boolean: n, Integer: s, Float: i, Array: v, "Array(2)": I, "Array(3)": D, "Array(4)": C, "Array1D(2)": A, "Array1D(3)": A, "Array1D(4)": A, "Array2D(2)": E, "Array2D(3)": E, "Array2D(4)": E, "Array3D(2)": k, "Array3D(3)": k, "Array3D(4)": k, Input: d, NumberTexture: b, "ArrayTexture(1)": b, "ArrayTexture(2)": b, "ArrayTexture(3)": b, "ArrayTexture(4)": b, MemoryOptimizedNumberTexture: x, HTMLCanvas: o, OffscreenCanvas: o, HTMLImage: o, ImageBitmap: o, ImageData: o, HTMLImageArray: l, HTMLVideo: c }, static: { Boolean: n, Float: i, Integer: s, Array: T, "Array(2)": I, "Array(3)": D, "Array(4)": C, "Array1D(2)": S, "Array1D(3)": S, "Array1D(4)": S, "Array2D(2)": _, "Array2D(3)": _, "Array2D(4)": _, "Array3D(2)": w, "Array3D(3)": w, "Array3D(4)": w, Input: p, NumberTexture: y, "ArrayTexture(1)": y, "ArrayTexture(2)": y, "ArrayTexture(3)": y, "ArrayTexture(4)": y, MemoryOptimizedNumberTexture: g, HTMLCanvas: a, OffscreenCanvas: a, HTMLImage: a, ImageBitmap: a, ImageData: a, HTMLImageArray: u, HTMLVideo: h } } }; t.exports = { kernelValueMaps: R, lookupKernelValueType: function(e2, t2, r2, n2) { if (!e2) throw new Error("type missing"); if (!t2) throw new Error("dynamic missing"); if (!r2) throw new Error("precision missing"); n2.type && (e2 = n2.type); const i2 = R[r2][t2]; if (false === i2[e2]) return null; if (void 0 === i2[e2]) throw new Error(`Could not find a KernelValue for ${e2}`); return i2[e2]; } }; }, { "./kernel-value/array2": 75, "./kernel-value/array3": 76, "./kernel-value/array4": 77, "./kernel-value/boolean": 78, "./kernel-value/dynamic-html-image": 80, "./kernel-value/dynamic-html-image-array": 79, "./kernel-value/dynamic-html-video": 81, "./kernel-value/dynamic-memory-optimized-number-texture": 82, "./kernel-value/dynamic-number-texture": 83, "./kernel-value/dynamic-single-array": 84, "./kernel-value/dynamic-single-array1d-i": 85, "./kernel-value/dynamic-single-array2d-i": 86, "./kernel-value/dynamic-single-array3d-i": 87, "./kernel-value/dynamic-single-input": 88, "./kernel-value/dynamic-unsigned-array": 89, "./kernel-value/dynamic-unsigned-input": 90, "./kernel-value/float": 91, "./kernel-value/html-image": 93, "./kernel-value/html-image-array": 92, "./kernel-value/html-video": 94, "./kernel-value/integer": 95, "./kernel-value/memory-optimized-number-texture": 96, "./kernel-value/number-texture": 97, "./kernel-value/single-array": 98, "./kernel-value/single-array1d-i": 99, "./kernel-value/single-array2d-i": 100, "./kernel-value/single-array3d-i": 101, "./kernel-value/single-input": 102, "./kernel-value/unsigned-array": 103, "./kernel-value/unsigned-input": 104 }], 75: [function(e, t, r) { const { WebGLKernelValueArray2: n } = e("../../web-gl/kernel-value/array2"); t.exports = { WebGL2KernelValueArray2: class extends n { } }; }, { "../../web-gl/kernel-value/array2": 41 }], 76: [function(e, t, r) { const { WebGLKernelValueArray3: n } = e("../../web-gl/kernel-value/array3"); t.exports = { WebGL2KernelValueArray3: class extends n { } }; }, { "../../web-gl/kernel-value/array3": 42 }], 77: [function(e, t, r) { const { WebGLKernelValueArray4: n } = e("../../web-gl/kernel-value/array4"); t.exports = { WebGL2KernelValueArray4: class extends n { } }; }, { "../../web-gl/kernel-value/array4": 43 }], 78: [function(e, t, r) { const { WebGLKernelValueBoolean: n } = e("../../web-gl/kernel-value/boolean"); t.exports = { WebGL2KernelValueBoolean: class extends n { } }; }, { "../../web-gl/kernel-value/boolean": 44 }], 79: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGL2KernelValueHTMLImageArray: i } = e("./html-image-array"); t.exports = { WebGL2KernelValueDynamicHTMLImageArray: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2DArray ${this.id}`, `uniform ${e2} ivec2 ${this.sizeId}`, `uniform ${e2} ivec3 ${this.dimensionsId}`]); } updateValue(e2) { const { width: t2, height: r2 } = e2[0]; this.checkSize(t2, r2), this.dimensions = [t2, r2, e2.length], this.textureSize = [t2, r2], this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "./html-image-array": 92 }], 80: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueDynamicHTMLImage: i } = e("../../web-gl/kernel-value/dynamic-html-image"); t.exports = { WebGL2KernelValueDynamicHTMLImage: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `uniform ${e2} ivec2 ${this.sizeId}`, `uniform ${e2} ivec3 ${this.dimensionsId}`]); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/dynamic-html-image": 45 }], 81: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGL2KernelValueDynamicHTMLImage: i } = e("./dynamic-html-image"); t.exports = { WebGL2KernelValueDynamicHTMLVideo: class extends i { } }; }, { "../../../utils": 114, "./dynamic-html-image": 80 }], 82: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueDynamicMemoryOptimizedNumberTexture: i } = e("../../web-gl/kernel-value/dynamic-memory-optimized-number-texture"); t.exports = { WebGL2KernelValueDynamicMemoryOptimizedNumberTexture: class extends i { getSource() { return n.linesToString([`uniform sampler2D ${this.id}`, `uniform ivec2 ${this.sizeId}`, `uniform ivec3 ${this.dimensionsId}`]); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/dynamic-memory-optimized-number-texture": 47 }], 83: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueDynamicNumberTexture: i } = e("../../web-gl/kernel-value/dynamic-number-texture"); t.exports = { WebGL2KernelValueDynamicNumberTexture: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `uniform ${e2} ivec2 ${this.sizeId}`, `uniform ${e2} ivec3 ${this.dimensionsId}`]); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/dynamic-number-texture": 48 }], 84: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGL2KernelValueSingleArray: i } = e("../../web-gl2/kernel-value/single-array"); t.exports = { WebGL2KernelValueDynamicSingleArray: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `uniform ${e2} ivec2 ${this.sizeId}`, `uniform ${e2} ivec3 ${this.dimensionsId}`]); } updateValue(e2) { this.dimensions = n.getDimensions(e2, true), this.textureSize = n.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio, this.checkSize(this.textureSize[0], this.textureSize[1]), this.uploadValue = new Float32Array(this.uploadArrayLength), this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "../../web-gl2/kernel-value/single-array": 98 }], 85: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGL2KernelValueSingleArray1DI: i } = e("../../web-gl2/kernel-value/single-array1d-i"); t.exports = { WebGL2KernelValueDynamicSingleArray1DI: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `uniform ${e2} ivec2 ${this.sizeId}`, `uniform ${e2} ivec3 ${this.dimensionsId}`]); } updateValue(e2) { this.setShape(e2), this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "../../web-gl2/kernel-value/single-array1d-i": 99 }], 86: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGL2KernelValueSingleArray2DI: i } = e("../../web-gl2/kernel-value/single-array2d-i"); t.exports = { WebGL2KernelValueDynamicSingleArray2DI: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `uniform ${e2} ivec2 ${this.sizeId}`, `uniform ${e2} ivec3 ${this.dimensionsId}`]); } updateValue(e2) { this.setShape(e2), this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "../../web-gl2/kernel-value/single-array2d-i": 100 }], 87: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGL2KernelValueSingleArray3DI: i } = e("../../web-gl2/kernel-value/single-array3d-i"); t.exports = { WebGL2KernelValueDynamicSingleArray3DI: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `uniform ${e2} ivec2 ${this.sizeId}`, `uniform ${e2} ivec3 ${this.dimensionsId}`]); } updateValue(e2) { this.setShape(e2), this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "../../web-gl2/kernel-value/single-array3d-i": 101 }], 88: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGL2KernelValueSingleInput: i } = e("../../web-gl2/kernel-value/single-input"); t.exports = { WebGL2KernelValueDynamicSingleInput: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `uniform ${e2} ivec2 ${this.sizeId}`, `uniform ${e2} ivec3 ${this.dimensionsId}`]); } updateValue(e2) { let [t2, r2, i2] = e2.size; this.dimensions = new Int32Array([t2 || 1, r2 || 1, i2 || 1]), this.textureSize = n.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio), this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio, this.checkSize(this.textureSize[0], this.textureSize[1]), this.uploadValue = new Float32Array(this.uploadArrayLength), this.kernel.setUniform3iv(this.dimensionsId, this.dimensions), this.kernel.setUniform2iv(this.sizeId, this.textureSize), super.updateValue(e2); } } }; }, { "../../../utils": 114, "../../web-gl2/kernel-value/single-input": 102 }], 89: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueDynamicUnsignedArray: i } = e("../../web-gl/kernel-value/dynamic-unsigned-array"); t.exports = { WebGL2KernelValueDynamicUnsignedArray: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `uniform ${e2} ivec2 ${this.sizeId}`, `uniform ${e2} ivec3 ${this.dimensionsId}`]); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/dynamic-unsigned-array": 54 }], 90: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueDynamicUnsignedInput: i } = e("../../web-gl/kernel-value/dynamic-unsigned-input"); t.exports = { WebGL2KernelValueDynamicUnsignedInput: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `uniform ${e2} ivec2 ${this.sizeId}`, `uniform ${e2} ivec3 ${this.dimensionsId}`]); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/dynamic-unsigned-input": 55 }], 91: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueFloat: i } = e("../../web-gl/kernel-value/float"); t.exports = { WebGL2KernelValueFloat: class extends i { } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/float": 56 }], 92: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelArray: i } = e("../../web-gl/kernel-value/array"); t.exports = { WebGL2KernelValueHTMLImageArray: class extends i { constructor(e2, t2) { super(e2, t2), this.checkSize(e2[0].width, e2[0].height), this.dimensions = [e2[0].width, e2[0].height, e2.length], this.textureSize = [e2[0].width, e2[0].height]; } defineTexture() { const { context: e2 } = this; e2.activeTexture(this.contextHandle), e2.bindTexture(e2.TEXTURE_2D_ARRAY, this.texture), e2.texParameteri(e2.TEXTURE_2D_ARRAY, e2.TEXTURE_MAG_FILTER, e2.NEAREST), e2.texParameteri(e2.TEXTURE_2D_ARRAY, e2.TEXTURE_MIN_FILTER, e2.NEAREST); } getStringValueHandler() { return `const uploadValue_${this.name} = ${this.varName}; `; } getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2DArray ${this.id}`, `${e2} ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `${e2} ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { const { context: t2 } = this; t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D_ARRAY, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, true), t2.texImage3D(t2.TEXTURE_2D_ARRAY, 0, t2.RGBA, e2[0].width, e2[0].height, e2.length, 0, t2.RGBA, t2.UNSIGNED_BYTE, null); for (let r2 = 0; r2 < e2.length; r2++) { const n2 = 0, i2 = 0, s = 1; t2.texSubImage3D(t2.TEXTURE_2D_ARRAY, 0, n2, i2, r2, e2[r2].width, e2[r2].height, s, t2.RGBA, t2.UNSIGNED_BYTE, this.uploadValue = e2[r2]); } this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/array": 40 }], 93: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueHTMLImage: i } = e("../../web-gl/kernel-value/html-image"); t.exports = { WebGL2KernelValueHTMLImage: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `${e2} ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `${e2} ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/html-image": 57 }], 94: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGL2KernelValueHTMLImage: i } = e("./html-image"); t.exports = { WebGL2KernelValueHTMLVideo: class extends i { } }; }, { "../../../utils": 114, "./html-image": 93 }], 95: [function(e, t, r) { const { WebGLKernelValueInteger: n } = e("../../web-gl/kernel-value/integer"); t.exports = { WebGL2KernelValueInteger: class extends n { getSource(e2) { const t2 = this.getVariablePrecisionString(); return "constants" === this.origin ? `const ${t2} int ${this.id} = ${parseInt(e2)}; ` : `uniform ${t2} int ${this.id}; `; } updateValue(e2) { "constants" !== this.origin && this.kernel.setUniform1i(this.id, this.uploadValue = e2); } } }; }, { "../../web-gl/kernel-value/integer": 60 }], 96: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueMemoryOptimizedNumberTexture: i } = e("../../web-gl/kernel-value/memory-optimized-number-texture"); t.exports = { WebGL2KernelValueMemoryOptimizedNumberTexture: class extends i { getSource() { const { id: e2, sizeId: t2, textureSize: r2, dimensionsId: i2, dimensions: s } = this, a = this.getVariablePrecisionString(); return n.linesToString([`uniform sampler2D ${e2}`, `${a} ivec2 ${t2} = ivec2(${r2[0]}, ${r2[1]})`, `${a} ivec3 ${i2} = ivec3(${s[0]}, ${s[1]}, ${s[2]})`]); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/memory-optimized-number-texture": 61 }], 97: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueNumberTexture: i } = e("../../web-gl/kernel-value/number-texture"); t.exports = { WebGL2KernelValueNumberTexture: class extends i { getSource() { const { id: e2, sizeId: t2, textureSize: r2, dimensionsId: i2, dimensions: s } = this, a = this.getVariablePrecisionString(); return n.linesToString([`uniform ${a} sampler2D ${e2}`, `${a} ivec2 ${t2} = ivec2(${r2[0]}, ${r2[1]})`, `${a} ivec3 ${i2} = ivec3(${s[0]}, ${s[1]}, ${s[2]})`]); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/number-texture": 62 }], 98: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueSingleArray: i } = e("../../web-gl/kernel-value/single-array"); t.exports = { WebGL2KernelValueSingleArray: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `${e2} ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `${e2} ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); const { context: t2 } = this; n.flattenTo(e2, this.uploadValue), t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, false), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA32F, this.textureSize[0], this.textureSize[1], 0, t2.RGBA, t2.FLOAT, this.uploadValue), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/single-array": 63 }], 99: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueSingleArray1DI: i } = e("../../web-gl/kernel-value/single-array1d-i"); t.exports = { WebGL2KernelValueSingleArray1DI: class extends i { updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); const { context: t2 } = this; n.flattenTo(e2, this.uploadValue), t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, false), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA32F, this.textureSize[0], this.textureSize[1], 0, t2.RGBA, t2.FLOAT, this.uploadValue), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/single-array1d-i": 64 }], 100: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueSingleArray2DI: i } = e("../../web-gl/kernel-value/single-array2d-i"); t.exports = { WebGL2KernelValueSingleArray2DI: class extends i { updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); const { context: t2 } = this; n.flattenTo(e2, this.uploadValue), t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, false), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA32F, this.textureSize[0], this.textureSize[1], 0, t2.RGBA, t2.FLOAT, this.uploadValue), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/single-array2d-i": 65 }], 101: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueSingleArray3DI: i } = e("../../web-gl/kernel-value/single-array3d-i"); t.exports = { WebGL2KernelValueSingleArray3DI: class extends i { updateValue(e2) { if (e2.constructor !== this.initialValueConstructor) return void this.onUpdateValueMismatch(e2.constructor); const { context: t2 } = this; n.flattenTo(e2, this.uploadValue), t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, false), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA32F, this.textureSize[0], this.textureSize[1], 0, t2.RGBA, t2.FLOAT, this.uploadValue), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/single-array3d-i": 66 }], 102: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueSingleInput: i } = e("../../web-gl/kernel-value/single-input"); t.exports = { WebGL2KernelValueSingleInput: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `${e2} ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `${e2} ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } updateValue(e2) { const { context: t2 } = this; n.flattenTo(e2.value, this.uploadValue), t2.activeTexture(this.contextHandle), t2.bindTexture(t2.TEXTURE_2D, this.texture), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, false), t2.texImage2D(t2.TEXTURE_2D, 0, t2.RGBA32F, this.textureSize[0], this.textureSize[1], 0, t2.RGBA, t2.FLOAT, this.uploadValue), this.kernel.setUniform1i(this.id, this.index); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/single-input": 67 }], 103: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueUnsignedArray: i } = e("../../web-gl/kernel-value/unsigned-array"); t.exports = { WebGL2KernelValueUnsignedArray: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `${e2} ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `${e2} ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/unsigned-array": 68 }], 104: [function(e, t, r) { const { utils: n } = e("../../../utils"), { WebGLKernelValueUnsignedInput: i } = e("../../web-gl/kernel-value/unsigned-input"); t.exports = { WebGL2KernelValueUnsignedInput: class extends i { getSource() { const e2 = this.getVariablePrecisionString(); return n.linesToString([`uniform ${e2} sampler2D ${this.id}`, `${e2} ivec2 ${this.sizeId} = ivec2(${this.textureSize[0]}, ${this.textureSize[1]})`, `${e2} ivec3 ${this.dimensionsId} = ivec3(${this.dimensions[0]}, ${this.dimensions[1]}, ${this.dimensions[2]})`]); } } }; }, { "../../../utils": 114, "../../web-gl/kernel-value/unsigned-input": 69 }], 105: [function(e, t, r) { const { WebGLKernel: n } = e("../web-gl/kernel"), { WebGL2FunctionNode: i } = e("./function-node"), { FunctionBuilder: s } = e("../function-builder"), { utils: a } = e("../../utils"), { fragmentShader: o } = e("./fragment-shader"), { vertexShader: u } = e("./vertex-shader"), { lookupKernelValueType: l } = e("./kernel-value-maps"); let h = null, c = null, p = null, d = null, m = null; t.exports = { WebGL2Kernel: class extends n { static get isSupported() { return null !== h || (this.setupFeatureChecks(), h = this.isContextMatch(p)), h; } static setupFeatureChecks() { "undefined" != typeof document ? c = document.createElement("canvas") : "undefined" != typeof OffscreenCanvas && (c = new OffscreenCanvas(0, 0)), c && (p = c.getContext("webgl2"), p && p.getExtension && (d = { EXT_color_buffer_float: p.getExtension("EXT_color_buffer_float"), OES_texture_float_linear: p.getExtension("OES_texture_float_linear") }, m = this.getFeatures())); } static isContextMatch(e2) { return "undefined" != typeof WebGL2RenderingContext && e2 instanceof WebGL2RenderingContext; } static getFeatures() { const e2 = this.testContext; return Object.freeze({ isFloatRead: this.getIsFloatRead(), isIntegerDivisionAccurate: this.getIsIntegerDivisionAccurate(), isSpeedTacticSupported: this.getIsSpeedTacticSupported(), kernelMap: true, isTextureFloat: true, isDrawBuffers: true, channelCount: this.getChannelCount(), maxTextureSize: this.getMaxTextureSize(), lowIntPrecision: e2.getShaderPrecisionFormat(e2.FRAGMENT_SHADER, e2.LOW_INT), lowFloatPrecision: e2.getShaderPrecisionFormat(e2.FRAGMENT_SHADER, e2.LOW_FLOAT), mediumIntPrecision: e2.getShaderPrecisionFormat(e2.FRAGMENT_SHADER, e2.MEDIUM_INT), mediumFloatPrecision: e2.getShaderPrecisionFormat(e2.FRAGMENT_SHADER, e2.MEDIUM_FLOAT), highIntPrecision: e2.getShaderPrecisionFormat(e2.FRAGMENT_SHADER, e2.HIGH_INT), highFloatPrecision: e2.getShaderPrecisionFormat(e2.FRAGMENT_SHADER, e2.HIGH_FLOAT) }); } static getIsTextureFloat() { return true; } static getChannelCount() { return p.getParameter(p.MAX_DRAW_BUFFERS); } static getMaxTextureSize() { return p.getParameter(p.MAX_TEXTURE_SIZE); } static lookupKernelValueType(e2, t2, r2, n2) { return l(e2, t2, r2, n2); } static get testCanvas() { return c; } static get testContext() { return p; } static get features() { return m; } static get fragmentShader() { return o; } static get vertexShader() { return u; } initContext() { return this.canvas.getContext("webgl2", { alpha: false, depth: false, antialias: false }); } initExtensions() { this.extensions = { EXT_color_buffer_float: this.context.getExtension("EXT_color_buffer_float"), OES_texture_float_linear: this.context.getExtension("OES_texture_float_linear") }; } validateSettings(e2) { if (!this.validate) return void (this.texSize = a.getKernelTextureSize({ optimizeFloatMemory: this.optimizeFloatMemory, precision: this.precision }, this.output)); const { features: t2 } = this.constructor; if ("single" === this.precision && !t2.isFloatRead) throw new Error("Float texture outputs are not supported"); if (this.graphical || null !== this.precision || (this.precision = t2.isFloatRead ? "single" : "unsigned"), null === this.fixIntegerDivisionAccuracy ? this.fixIntegerDivisionAccuracy = !t2.isIntegerDivisionAccurate : this.fixIntegerDivisionAccuracy && t2.isIntegerDivisionAccurate && (this.fixIntegerDivisionAccuracy = false), this.checkOutput(), !this.output || 0 === this.output.length) { if (1 !== e2.length) throw new Error("Auto output only supported for kernels with only one input"); const t3 = a.getVariableType(e2[0], this.strictIntegers); switch (t3) { case "Array": this.output = a.getDimensions(t3); break; case "NumberTexture": case "MemoryOptimizedNumberTexture": case "ArrayTexture(1)": case "ArrayTexture(2)": case "ArrayTexture(3)": case "ArrayTexture(4)": this.output = e2[0].output; break; default: throw new Error("Auto output not supported for input type: " + t3); } } if (this.graphical) { if (2 !== this.output.length) throw new Error("Output must have 2 dimensions on graphical mode"); return "single" === this.precision && (console.warn("Cannot use graphical mode and single precision at the same time"), this.precision = "unsigned"), void (this.texSize = a.clone(this.output)); } !this.graphical && null === this.precision && t2.isTextureFloat && (this.precision = "single"), this.texSize = a.getKernelTextureSize({ optimizeFloatMemory: this.optimizeFloatMemory, precision: this.precision }, this.output), this.checkTextureSize(); } translateSource() { const e2 = s.fromKernel(this, i, { fixIntegerDivisionAccuracy: this.fixIntegerDivisionAccuracy }); this.translatedSource = e2.getPrototypeString("kernel"), this.setupReturnTypes(e2); } drawBuffers() { this.context.drawBuffers(this.drawBuffersMap); } getTextureFormat() { const { context: e2 } = this; switch (this.getInternalFormat()) { case e2.R32F: return e2.RED; case e2.RG32F: return e2.RG; case e2.RGBA32F: case e2.RGBA: return e2.RGBA; default: throw new Error("Unknown internal format"); } } getInternalFormat() { const { context: e2 } = this; if ("single" === this.precision) { if (this.pipeline) switch (this.returnType) { case "Number": case "Float": case "Integer": return this.optimizeFloatMemory ? e2.RGBA32F : e2.R32F; case "Array(2)": return e2.RG32F; case "Array(3)": case "Array(4)": return e2.RGBA32F; default: throw new Error("Unhandled return type"); } return e2.RGBA32F; } return e2.RGBA; } _setupOutputTexture() { const e2 = this.context; if (this.texture) return void e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0, e2.TEXTURE_2D, this.texture.texture, 0); e2.bindFramebuffer(e2.FRAMEBUFFER, this.framebuffer); const t2 = e2.createTexture(), r2 = this.texSize; e2.activeTexture(e2.TEXTURE0 + this.constantTextureCount + this.argumentTextureCount), e2.bindTexture(e2.TEXTURE_2D, t2), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_WRAP_S, e2.REPEAT), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_WRAP_T, e2.REPEAT), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_MIN_FILTER, e2.NEAREST), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_MAG_FILTER, e2.NEAREST); const n2 = this.getInternalFormat(); "single" === this.precision ? e2.texStorage2D(e2.TEXTURE_2D, 1, n2, r2[0], r2[1]) : e2.texImage2D(e2.TEXTURE_2D, 0, n2, r2[0], r2[1], 0, n2, e2.UNSIGNED_BYTE, null), e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0, e2.TEXTURE_2D, t2, 0), this.texture = new this.TextureConstructor({ texture: t2, size: r2, dimensions: this.threadDim, output: this.output, context: this.context, internalFormat: this.getInternalFormat(), textureFormat: this.getTextureFormat(), kernel: this }); } _setupSubOutputTextures() { const e2 = this.context; if (this.mappedTextures) { for (let t3 = 0; t3 < this.subKernels.length; t3++) e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0 + t3 + 1, e2.TEXTURE_2D, this.mappedTextures[t3].texture, 0); return; } const t2 = this.texSize; this.drawBuffersMap = [e2.COLOR_ATTACHMENT0], this.mappedTextures = []; for (let r2 = 0; r2 < this.subKernels.length; r2++) { const n2 = this.createTexture(); this.drawBuffersMap.push(e2.COLOR_ATTACHMENT0 + r2 + 1), e2.activeTexture(e2.TEXTURE0 + this.constantTextureCount + this.argumentTextureCount + r2), e2.bindTexture(e2.TEXTURE_2D, n2), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_WRAP_S, e2.CLAMP_TO_EDGE), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_WRAP_T, e2.CLAMP_TO_EDGE), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_MIN_FILTER, e2.NEAREST), e2.texParameteri(e2.TEXTURE_2D, e2.TEXTURE_MAG_FILTER, e2.NEAREST); const i2 = this.getInternalFormat(); "single" === this.precision ? e2.texStorage2D(e2.TEXTURE_2D, 1, i2, t2[0], t2[1]) : e2.texImage2D(e2.TEXTURE_2D, 0, e2.RGBA, t2[0], t2[1], 0, e2.RGBA, e2.UNSIGNED_BYTE, null), e2.framebufferTexture2D(e2.FRAMEBUFFER, e2.COLOR_ATTACHMENT0 + r2 + 1, e2.TEXTURE_2D, n2, 0), this.mappedTextures.push(new this.TextureConstructor({ texture: n2, size: t2, dimensions: this.threadDim, output: this.output, context: this.context, internalFormat: this.getInternalFormat(), textureFormat: this.getTextureFormat(), kernel: this })); } } _getHeaderString() { return ""; } _getTextureCoordinate() { const e2 = this.subKernels, t2 = this.getVariablePrecisionString(this.texSize, this.tactic); return null === e2 || e2.length < 1 ? `in ${t2} vec2 vTexCoord; ` : `out ${t2} vec2 vTexCoord; `; } _getMainArgumentsString(e2) { const t2 = [], r2 = this.argumentNames; for (let n2 = 0; n2 < r2.length; n2++) t2.push(this.kernelArguments[n2].getSource(e2[n2])); return t2.join(""); } getKernelString() { const e2 = [this.getKernelResultDeclaration()], t2 = this.subKernels; if (null !== t2) switch (e2.push("layout(location = 0) out vec4 data0"), this.returnType) { case "Number": case "Float": case "Integer": for (let r2 = 0; r2 < t2.length; r2++) { const n2 = t2[r2]; e2.push("Integer" === n2.returnType ? `int subKernelResult_${n2.name} = 0` : `float subKernelResult_${n2.name} = 0.0`, `layout(location = ${r2 + 1}) out vec4 data${r2 + 1}`); } break; case "Array(2)": for (let r2 = 0; r2 < t2.length; r2++) e2.push(`vec2 subKernelResult_${t2[r2].name}`, `layout(location = ${r2 + 1}) out vec4 data${r2 + 1}`); break; case "Array(3)": for (let r2 = 0; r2 < t2.length; r2++) e2.push(`vec3 subKernelResult_${t2[r2].name}`, `layout(location = ${r2 + 1}) out vec4 data${r2 + 1}`); break; case "Array(4)": for (let r2 = 0; r2 < t2.length; r2++) e2.push(`vec4 subKernelResult_${t2[r2].name}`, `layout(location = ${r2 + 1}) out vec4 data${r2 + 1}`); } else e2.push("out vec4 data0"); return a.linesToString(e2) + this.translatedSource; } getMainResultGraphical() { return a.linesToString([" threadId = indexTo3D(index, uOutputDim)", " kernel()", " data0 = actualColor"]); } getMainResultPackedPixels() { switch (this.returnType) { case "LiteralInteger": case "Number": case "Integer": case "Float": return this.getMainResultKernelPackedPixels() + this.getMainResultSubKernelPackedPixels(); default: throw new Error(`packed output only usable with Numbers, "${this.returnType}" specified`); } } getMainResultKernelPackedPixels() { return a.linesToString([" threadId = indexTo3D(index, uOutputDim)", " kernel()", ` data0 = ${this.useLegacyEncoder ? "legacyEncode32" : "encode32"}(kernelResult)`]); } getMainResultSubKernelPackedPixels() { const e2 = []; if (!this.subKernels) return ""; for (let t2 = 0; t2 < this.subKernels.length; t2++) { "Integer" === this.subKernels[t2].returnType ? e2.push(` data${t2 + 1} = ${this.useLegacyEncoder ? "legacyEncode32" : "encode32"}(float(subKernelResult_${this.subKernels[t2].name}))`) : e2.push(` data${t2 + 1} = ${this.useLegacyEncoder ? "legacyEncode32" : "encode32"}(subKernelResult_${this.subKernels[t2].name})`); } return a.linesToString(e2); } getMainResultKernelMemoryOptimizedFloats(e2, t2) { e2.push(" threadId = indexTo3D(index, uOutputDim)", " kernel()", ` data0.${t2} = kernelResult`); } getMainResultSubKernelMemoryOptimizedFloats(e2, t2) { if (!this.subKernels) return e2; for (let r2 = 0; r2 < this.subKernels.length; r2++) { const n2 = this.subKernels[r2]; "Integer" === n2.returnType ? e2.push(` data${r2 + 1}.${t2} = float(subKernelResult_${n2.name})`) : e2.push(` data${r2 + 1}.${t2} = subKernelResult_${n2.name}`); } } getMainResultKernelNumberTexture() { return [" threadId = indexTo3D(index, uOutputDim)", " kernel()", " data0[0] = kernelResult"]; } getMainResultSubKernelNumberTexture() { const e2 = []; if (!this.subKernels) return e2; for (let t2 = 0; t2 < this.subKernels.length; ++t2) { const r2 = this.subKernels[t2]; "Integer" === r2.returnType ? e2.push(` data${t2 + 1}[0] = float(subKernelResult_${r2.name})`) : e2.push(` data${t2 + 1}[0] = subKernelResult_${r2.name}`); } return e2; } getMainResultKernelArray2Texture() { return [" threadId = indexTo3D(index, uOutputDim)", " kernel()", " data0[0] = kernelResult[0]", " data0[1] = kernelResult[1]"]; } getMainResultSubKernelArray2Texture() { const e2 = []; if (!this.subKernels) return e2; for (let t2 = 0; t2 < this.subKernels.length; ++t2) { const r2 = this.subKernels[t2]; e2.push(` data${t2 + 1}[0] = subKernelResult_${r2.name}[0]`, ` data${t2 + 1}[1] = subKernelResult_${r2.name}[1]`); } return e2; } getMainResultKernelArray3Texture() { return [" threadId = indexTo3D(index, uOutputDim)", " kernel()", " data0[0] = kernelResult[0]", " data0[1] = kernelResult[1]", " data0[2] = kernelResult[2]"]; } getMainResultSubKernelArray3Texture() { const e2 = []; if (!this.subKernels) return e2; for (let t2 = 0; t2 < this.subKernels.length; ++t2) { const r2 = this.subKernels[t2]; e2.push(` data${t2 + 1}[0] = subKernelResult_${r2.name}[0]`, ` data${t2 + 1}[1] = subKernelResult_${r2.name}[1]`, ` data${t2 + 1}[2] = subKernelResult_${r2.name}[2]`); } return e2; } getMainResultKernelArray4Texture() { return [" threadId = indexTo3D(index, uOutputDim)", " kernel()", " data0 = kernelResult"]; } getMainResultSubKernelArray4Texture() { const e2 = []; if (!this.subKernels) return e2; for (let t2 = 0; t2 < this.subKernels.length; ++t2) e2.push(` data${t2 + 1} = subKernelResult_${this.subKernels[t2].name}`); return e2; } destroyExtensions() { this.extensions.EXT_color_buffer_float = null, this.extensions.OES_texture_float_linear = null; } toJSON() { const e2 = super.toJSON(); return e2.functionNodes = s.fromKernel(this, i).toJSON(), e2.settings.threadDim = this.threadDim, e2; } } }; }, { "../../utils": 114, "../function-builder": 9, "../web-gl/kernel": 70, "./fragment-shader": 72, "./function-node": 73, "./kernel-value-maps": 74, "./vertex-shader": 106 }], 106: [function(e, t, r) { t.exports = { vertexShader: "#version 300 es\n__FLOAT_TACTIC_DECLARATION__;\n__INT_TACTIC_DECLARATION__;\n__SAMPLER_2D_TACTIC_DECLARATION__;\n\nin vec2 aPos;\nin vec2 aTexCoord;\n\nout vec2 vTexCoord;\nuniform vec2 ratio;\n\nvoid main(void) {\n gl_Position = vec4((aPos + vec2(1)) * ratio + vec2(-1), 0, 1);\n vTexCoord = aTexCoord;\n}" }; }, {}], 107: [function(e, t, r) { const n = e("./index"), i = n.GPU; for (const e2 in n) n.hasOwnProperty(e2) && "GPU" !== e2 && (i[e2] = n[e2]); function s(e2) { e2.GPU || Object.defineProperty(e2, "GPU", { get: () => i }); } "undefined" != typeof window && s(window), "undefined" != typeof self && s(self), t.exports = n; }, { "./index": 109 }], 108: [function(e, t, r) { const { gpuMock: n } = e("gpu-mock.js"), { utils: i } = e("./utils"), { Kernel: s } = e("./backend/kernel"), { CPUKernel: a } = e("./backend/cpu/kernel"), { HeadlessGLKernel: o } = e("./backend/headless-gl/kernel"), { WebGL2Kernel: u } = e("./backend/web-gl2/kernel"), { WebGLKernel: l } = e("./backend/web-gl/kernel"), { kernelRunShortcut: h } = e("./kernel-run-shortcut"), c = [o, u, l], p = ["gpu", "cpu"], d = { headlessgl: o, webgl2: u, webgl: l }; let m = true; function f(e2) { if (!e2) return {}; const t2 = Object.assign({}, e2); return e2.hasOwnProperty("floatOutput") && (i.warnDeprecated("setting", "floatOutput", "precision"), t2.precision = e2.floatOutput ? "single" : "unsigned"), e2.hasOwnProperty("outputToTexture") && (i.warnDeprecated("setting", "outputToTexture", "pipeline"), t2.pipeline = Boolean(e2.outputToTexture)), e2.hasOwnProperty("outputImmutable") && (i.warnDeprecated("setting", "outputImmutable", "immutable"), t2.immutable = Boolean(e2.outputImmutable)), e2.hasOwnProperty("floatTextures") && (i.warnDeprecated("setting", "floatTextures", "optimizeFloatMemory"), t2.optimizeFloatMemory = Boolean(e2.floatTextures)), t2; } t.exports = { GPU: class { static disableValidation() { m = false; } static enableValidation() { m = true; } static get isGPUSupported() { return c.some((e2) => e2.isSupported); } static get isKernelMapSupported() { return c.some((e2) => e2.isSupported && e2.features.kernelMap); } static get isOffscreenCanvasSupported() { return "undefined" != typeof Worker && "undefined" != typeof OffscreenCanvas || "undefined" != typeof importScripts; } static get isWebGLSupported() { return l.isSupported; } static get isWebGL2Supported() { return u.isSupported; } static get isHeadlessGLSupported() { return o.isSupported; } static get isCanvasSupported() { return "undefined" != typeof HTMLCanvasElement; } static get isGPUHTMLImageArraySupported() { return u.isSupported; } static get isSinglePrecisionSupported() { return c.some((e2) => e2.isSupported && e2.features.isFloatRead && e2.features.isTextureFloat); } constructor(e2) { if (e2 = e2 || {}, this.canvas = e2.canvas || null, this.context = e2.context || null, this.mode = e2.mode, this.Kernel = null, this.kernels = [], this.functions = [], this.nativeFunctions = [], this.injectedNative = null, "dev" !== this.mode) { if (this.chooseKernel(), e2.functions) for (let t2 = 0; t2 < e2.functions.length; t2++) this.addFunction(e2.functions[t2]); if (e2.nativeFunctions) for (const t2 in e2.nativeFunctions) { if (!e2.nativeFunctions.hasOwnProperty(t2)) continue; const r2 = e2.nativeFunctions[t2], { name: n2, source: i2 } = r2; this.addNativeFunction(n2, i2, r2); } } } chooseKernel() { if (this.Kernel) return; let e2 = null; if (this.context) { for (let t2 = 0; t2 < c.length; t2++) { const r2 = c[t2]; if (r2.isContextMatch(this.context)) { if (!r2.isSupported) throw new Error(`Kernel type ${r2.name} not supported`); e2 = r2; break; } } if (null === e2) throw new Error("unknown Context"); } else if (this.mode) { if (this.mode in d) m && !d[this.mode].isSupported || (e2 = d[this.mode]); else if ("gpu" === this.mode) { for (let t2 = 0; t2 < c.length; t2++) if (c[t2].isSupported) { e2 = c[t2]; break; } } else "cpu" === this.mode && (e2 = a); if (!e2) throw new Error(`A requested mode of "${this.mode}" and is not supported`); } else { for (let t2 = 0; t2 < c.length; t2++) if (c[t2].isSupported) { e2 = c[t2]; break; } e2 || (e2 = a); } this.mode || (this.mode = e2.mode), this.Kernel = e2; } createKernel(e2, t2) { if (void 0 === e2) throw new Error("Missing source parameter"); if ("object" != typeof e2 && !i.isFunction(e2) && "string" != typeof e2) throw new Error("source parameter not a function"); const r2 = this.kernels; if ("dev" === this.mode) { const i2 = n(e2, f(t2)); return r2.push(i2), i2; } e2 = "function" == typeof e2 ? e2.toString() : e2; const s2 = {}, o2 = f(t2) || {}; function u2(t3) { console.warn("Falling back to CPU"); const r3 = new a(e2, { argumentTypes: p2.argumentTypes, constantTypes: p2.constantTypes, graphical: p2.graphical, loopMaxIterations: p2.loopMaxIterations, constants: p2.constants, dynamicOutput: p2.dynamicOutput, dynamicArgument: p2.dynamicArguments, output: p2.output, precision: p2.precision, pipeline: p2.pipeline, immutable: p2.immutable, optimizeFloatMemory: p2.optimizeFloatMemory, fixIntegerDivisionAccuracy: p2.fixIntegerDivisionAccuracy, functions: p2.functions, nativeFunctions: p2.nativeFunctions, injectedNative: p2.injectedNative, subKernels: p2.subKernels, strictIntegers: p2.strictIntegers, debug: p2.debug }); r3.build.apply(r3, t3); const n2 = r3.run.apply(r3, t3); return p2.replaceKernel(r3), n2; } t2 && "object" == typeof t2.argumentTypes && (o2.argumentTypes = Object.keys(t2.argumentTypes).map((e3) => t2.argumentTypes[e3])); const l2 = Object.assign({ context: this.context, canvas: this.canvas, functions: this.functions, nativeFunctions: this.nativeFunctions, injectedNative: this.injectedNative, gpu: this, validate: m, onRequestFallback: u2, onRequestSwitchKernel: function t3(n2, i2, a2) { a2.debug && console.warn("Switching kernels"); let o3 = null; if (a2.signature && !s2[a2.signature] && (s2[a2.signature] = a2), a2.dynamicOutput) for (let e3 = n2.length - 1; e3 >= 0; e3--) { const t4 = n2[e3]; "outputPrecisionMismatch" === t4.type && (o3 = t4.needed); } const l3 = a2.constructor, h2 = l3.getArgumentTypes(a2, i2), c3 = l3.getSignature(a2, h2), d2 = s2[c3]; if (d2) return d2.onActivate(a2), d2; const f2 = s2[c3] = new l3(e2, { argumentTypes: h2, constantTypes: a2.constantTypes, graphical: a2.graphical, loopMaxIterations: a2.loopMaxIterations, constants: a2.constants, dynamicOutput: a2.dynamicOutput, dynamicArgument: a2.dynamicArguments, context: a2.context, canvas: a2.canvas, output: o3 || a2.output, precision: a2.precision, pipeline: a2.pipeline, immutable: a2.immutable, optimizeFloatMemory: a2.optimizeFloatMemory, fixIntegerDivisionAccuracy: a2.fixIntegerDivisionAccuracy, functions: a2.functions, nativeFunctions: a2.nativeFunctions, injectedNative: a2.injectedNative, subKernels: a2.subKernels, strictIntegers: a2.strictIntegers, debug: a2.debug, gpu: a2.gpu, validate: m, returnType: a2.returnType, tactic: a2.tactic, onRequestFallback: u2, onRequestSwitchKernel: t3, texture: a2.texture, mappedTextures: a2.mappedTextures, drawBuffersMap: a2.drawBuffersMap }); return f2.build.apply(f2, i2), p2.replaceKernel(f2), r2.push(f2), f2; } }, o2), c2 = new this.Kernel(e2, l2), p2 = h(c2); return this.canvas || (this.canvas = c2.canvas), this.context || (this.context = c2.context), r2.push(c2), p2; } createKernelMap() { let e2, t2; const r2 = typeof arguments[arguments.length - 2]; if ("function" === r2 || "string" === r2 ? (e2 = arguments[arguments.length - 2], t2 = arguments[arguments.length - 1]) : e2 = arguments[arguments.length - 1], "dev" !== this.mode && (!this.Kernel.isSupported || !this.Kernel.features.kernelMap) && this.mode && p.indexOf(this.mode) < 0) throw new Error(`kernelMap not supported on ${this.Kernel.name}`); const n2 = f(t2); if (t2 && "object" == typeof t2.argumentTypes && (n2.argumentTypes = Object.keys(t2.argumentTypes).map((e3) => t2.argumentTypes[e3])), Array.isArray(arguments[0])) { n2.subKernels = []; const e3 = arguments[0]; for (let t3 = 0; t3 < e3.length; t3++) { const r3 = e3[t3].toString(), s2 = i.getFunctionNameFromString(r3); n2.subKernels.push({ name: s2, source: r3, property: t3 }); } } else { n2.subKernels = []; const e3 = arguments[0]; for (let t3 in e3) { if (!e3.hasOwnProperty(t3)) continue; const r3 = e3[t3].toString(), s2 = i.getFunctionNameFromString(r3); n2.subKernels.push({ name: s2 || t3, source: r3, property: t3 }); } } return this.createKernel(e2, n2); } combineKernels() { const e2 = arguments[arguments.length - 1]; if ("cpu" === arguments[0].kernel.constructor.mode) return e2; const t2 = arguments[0].canvas, r2 = arguments[0].context, n2 = arguments.length - 1; for (let e3 = 0; e3 < n2; e3++) arguments[e3].setCanvas(t2).setContext(r2).setPipeline(true); return function() { const t3 = e2.apply(this, arguments); return t3.toArray ? t3.toArray() : t3; }; } setFunctions(e2) { return this.functions = e2, this; } setNativeFunctions(e2) { return this.nativeFunctions = e2, this; } addFunction(e2, t2) { return this.functions.push({ source: e2, settings: t2 }), this; } addNativeFunction(e2, t2, r2) { if (this.kernels.length > 0) throw new Error('Cannot call "addNativeFunction" after "createKernels" has been called.'); return this.nativeFunctions.push(Object.assign({ name: e2, source: t2 }, r2)), this; } injectNative(e2) { return this.injectedNative = e2, this; } destroy() { return new Promise((e2, t2) => { this.kernels || e2(), setTimeout(() => { try { for (let e4 = 0; e4 < this.kernels.length; e4++) this.kernels[e4].destroy(true); let e3 = this.kernels[0]; e3 && (e3.kernel && (e3 = e3.kernel), e3.constructor.destroyContext && e3.constructor.destroyContext(this.context)); } catch (e3) { t2(e3); } e2(); }, 0); }); } }, kernelOrder: c, kernelTypes: p }; }, { "./backend/cpu/kernel": 8, "./backend/headless-gl/kernel": 34, "./backend/kernel": 36, "./backend/web-gl/kernel": 70, "./backend/web-gl2/kernel": 105, "./kernel-run-shortcut": 111, "./utils": 114, "gpu-mock.js": 4 }], 109: [function(e, t, r) { const { GPU: n } = e("./gpu"), { alias: i } = e("./alias"), { utils: s } = e("./utils"), { Input: a, input: o } = e("./input"), { Texture: u } = e("./texture"), { FunctionBuilder: l } = e("./backend/function-builder"), { FunctionNode: h } = e("./backend/function-node"), { CPUFunctionNode: c } = e("./backend/cpu/function-node"), { CPUKernel: p } = e("./backend/cpu/kernel"), { HeadlessGLKernel: d } = e("./backend/headless-gl/kernel"), { WebGLFunctionNode: m } = e("./backend/web-gl/function-node"), { WebGLKernel: f } = e("./backend/web-gl/kernel"), { kernelValueMaps: g } = e("./backend/web-gl/kernel-value-maps"), { WebGL2FunctionNode: x } = e("./backend/web-gl2/function-node"), { WebGL2Kernel: y } = e("./backend/web-gl2/kernel"), { kernelValueMaps: b } = e("./backend/web-gl2/kernel-value-maps"), { GLKernel: T } = e("./backend/gl/kernel"), { Kernel: v } = e("./backend/kernel"), { FunctionTracer: S } = e("./backend/function-tracer"), A = e("./plugins/math-random-uniformly-distributed"); t.exports = { alias: i, CPUFunctionNode: c, CPUKernel: p, GPU: n, FunctionBuilder: l, FunctionNode: h, HeadlessGLKernel: d, Input: a, input: o, Texture: u, utils: s, WebGL2FunctionNode: x, WebGL2Kernel: y, webGL2KernelValueMaps: b, WebGLFunctionNode: m, WebGLKernel: f, webGLKernelValueMaps: g, GLKernel: T, Kernel: v, FunctionTracer: S, plugins: { mathRandom: A } }; }, { "./alias": 5, "./backend/cpu/function-node": 6, "./backend/cpu/kernel": 8, "./backend/function-builder": 9, "./backend/function-node": 10, "./backend/function-tracer": 11, "./backend/gl/kernel": 13, "./backend/headless-gl/kernel": 34, "./backend/kernel": 36, "./backend/web-gl/function-node": 38, "./backend/web-gl/kernel": 70, "./backend/web-gl/kernel-value-maps": 39, "./backend/web-gl2/function-node": 73, "./backend/web-gl2/kernel": 105, "./backend/web-gl2/kernel-value-maps": 74, "./gpu": 108, "./input": 110, "./plugins/math-random-uniformly-distributed": 112, "./texture": 113, "./utils": 114 }], 110: [function(e, t, r) { class n { constructor(e2, t2) { this.value = e2, Array.isArray(t2) ? this.size = t2 : (this.size = new Int32Array(3), t2.z ? this.size = new Int32Array([t2.x, t2.y, t2.z]) : t2.y ? this.size = new Int32Array([t2.x, t2.y]) : this.size = new Int32Array([t2.x])); const [r2, n2, i] = this.size; if (i) { if (this.value.length !== r2 * n2 * i) throw new Error(`Input size ${this.value.length} does not match ${r2} * ${n2} * ${i} = ${n2 * r2 * i}`); } else if (n2) { if (this.value.length !== r2 * n2) throw new Error(`Input size ${this.value.length} does not match ${r2} * ${n2} = ${n2 * r2}`); } else if (this.value.length !== r2) throw new Error(`Input size ${this.value.length} does not match ${r2}`); } toArray() { const { utils: t2 } = e("./utils"), [r2, n2, i] = this.size; return i ? t2.erectMemoryOptimized3DFloat(this.value.subarray ? this.value : new Float32Array(this.value), r2, n2, i) : n2 ? t2.erectMemoryOptimized2DFloat(this.value.subarray ? this.value : new Float32Array(this.value), r2, n2) : this.value; } } t.exports = { Input: n, input: function(e2, t2) { return new n(e2, t2); } }; }, { "./utils": 114 }], 111: [function(e, t, r) { const { utils: n } = e("./utils"); function i(e2, t2) { if (t2.kernel) return void (t2.kernel = e2); const r2 = n.allPropertiesOf(e2); for (let n2 = 0; n2 < r2.length; n2++) { const i2 = r2[n2]; "_" === i2[0] && "_" === i2[1] || ("function" == typeof e2[i2] ? "add" === i2.substring(0, 3) || "set" === i2.substring(0, 3) ? t2[i2] = function() { return t2.kernel[i2].apply(t2.kernel, arguments), t2; } : t2[i2] = function() { return t2.kernel[i2].apply(t2.kernel, arguments); } : (t2.__defineGetter__(i2, () => t2.kernel[i2]), t2.__defineSetter__(i2, (e3) => { t2.kernel[i2] = e3; }))); } t2.kernel = e2; } t.exports = { kernelRunShortcut: function(e2) { let t2 = function() { return e2.build.apply(e2, arguments), t2 = function() { let t3 = e2.run.apply(e2, arguments); if (e2.switchingKernels) { const n2 = e2.resetSwitchingKernels(), i2 = e2.onRequestSwitchKernel(n2, arguments, e2); r2.kernel = e2 = i2, t3 = i2.run.apply(i2, arguments); } return e2.renderKernels ? e2.renderKernels() : e2.renderOutput ? e2.renderOutput() : t3; }, t2.apply(e2, arguments); }; const r2 = function() { return t2.apply(e2, arguments); }; return r2.exec = function() { return new Promise((e3, r3) => { try { e3(t2.apply(this, arguments)); } catch (e4) { r3(e4); } }); }, r2.replaceKernel = function(t3) { i(e2 = t3, r2); }, i(e2, r2), r2; } }; }, { "./utils": 114 }], 112: [function(e, t, r) { const n = { name: "math-random-uniformly-distributed", onBeforeRun: (e2) => { e2.setUniform1f("randomSeed1", Math.random()), e2.setUniform1f("randomSeed2", Math.random()); }, functionMatch: "Math.random()", functionReplace: "nrand(vTexCoord)", functionReturnType: "Number", source: "// https://www.shadertoy.com/view/4t2SDh\n//note: uniformly distributed, normalized rand, [0,1]\nhighp float randomSeedShift = 1.0;\nhighp float slide = 1.0;\nuniform highp float randomSeed1;\nuniform highp float randomSeed2;\n\nhighp float nrand(highp vec2 n) {\n highp float result = fract(sin(dot((n.xy + 1.0) * vec2(randomSeed1 * slide, randomSeed2 * randomSeedShift), vec2(12.9898, 78.233))) * 43758.5453);\n randomSeedShift = result;\n if (randomSeedShift > 0.5) {\n slide += 0.00009; \n } else {\n slide += 0.0009;\n }\n return result;\n}" }; t.exports = n; }, {}], 113: [function(e, t, r) { t.exports = { Texture: class { constructor(e2) { const { texture: t2, size: r2, dimensions: n, output: i, context: s, type: a = "NumberTexture", kernel: o, internalFormat: u, textureFormat: l } = e2; if (!i) throw new Error('settings property "output" required.'); if (!s) throw new Error('settings property "context" required.'); if (!t2) throw new Error('settings property "texture" required.'); if (!o) throw new Error('settings property "kernel" required.'); this.texture = t2, t2._refs ? t2._refs++ : t2._refs = 1, this.size = r2, this.dimensions = n, this.output = i, this.context = s, this.kernel = o, this.type = a, this._deleted = false, this.internalFormat = u, this.textureFormat = l; } toArray() { throw new Error(`Not implemented on ${this.constructor.name}`); } clone() { throw new Error(`Not implemented on ${this.constructor.name}`); } delete() { throw new Error(`Not implemented on ${this.constructor.name}`); } clear() { throw new Error(`Not implemented on ${this.constructor.name}`); } } }; }, {}], 114: [function(e, t, r) { const n = e("acorn"), { Input: i } = e("./input"), { Texture: s } = e("./texture"), a = /function ([^(]*)/, o = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm, u = /([^\s,]+)/g, l = { systemEndianness: () => d, getSystemEndianness() { const e2 = new ArrayBuffer(4), t2 = new Uint32Array(e2), r2 = new Uint8Array(e2); if (t2[0] = 3735928559, 239 === r2[0]) return "LE"; if (222 === r2[0]) return "BE"; throw new Error("unknown endianness"); }, isFunction: (e2) => "function" == typeof e2, isFunctionString: (e2) => "string" == typeof e2 && "function" === e2.slice(0, 8).toLowerCase(), getFunctionNameFromString(e2) { const t2 = a.exec(e2); return t2 && 0 !== t2.length ? t2[1].trim() : null; }, getFunctionBodyFromString: (e2) => e2.substring(e2.indexOf("{") + 1, e2.lastIndexOf("}")), getArgumentNamesFromString(e2) { const t2 = e2.replace(o, ""); let r2 = t2.slice(t2.indexOf("(") + 1, t2.indexOf(")")).match(u); return null === r2 && (r2 = []), r2; }, clone(e2) { if (null === e2 || "object" != typeof e2 || e2.hasOwnProperty("isActiveClone")) return e2; const t2 = e2.constructor(); for (let r2 in e2) Object.prototype.hasOwnProperty.call(e2, r2) && (e2.isActiveClone = null, t2[r2] = l.clone(e2[r2]), delete e2.isActiveClone); return t2; }, isArray: (e2) => !isNaN(e2.length), getVariableType(e2, t2) { if (l.isArray(e2)) return e2.length > 0 && "IMG" === e2[0].nodeName ? "HTMLImageArray" : "Array"; switch (e2.constructor) { case Boolean: return "Boolean"; case Number: return t2 && Number.isInteger(e2) ? "Integer" : "Float"; case s: return e2.type; case i: return "Input"; } if ("nodeName" in e2) switch (e2.nodeName) { case "IMG": case "CANVAS": return "HTMLImage"; case "VIDEO": return "HTMLVideo"; } else { if (e2.hasOwnProperty("type")) return e2.type; if ("undefined" != typeof OffscreenCanvas && e2 instanceof OffscreenCanvas) return "OffscreenCanvas"; if ("undefined" != typeof ImageBitmap && e2 instanceof ImageBitmap) return "ImageBitmap"; if ("undefined" != typeof ImageData && e2 instanceof ImageData) return "ImageData"; } return "Unknown"; }, getKernelTextureSize(e2, t2) { let [r2, n2, i2] = t2, s2 = (r2 || 1) * (n2 || 1) * (i2 || 1); return e2.optimizeFloatMemory && "single" === e2.precision && (r2 = s2 = Math.ceil(s2 / 4)), n2 > 1 && r2 * n2 === s2 ? new Int32Array([r2, n2]) : l.closestSquareDimensions(s2); }, closestSquareDimensions(e2) { const t2 = Math.sqrt(e2); let r2 = Math.ceil(t2), n2 = Math.floor(t2); for (; r2 * n2 < e2; ) r2--, n2 = Math.ceil(e2 / r2); return new Int32Array([n2, Math.ceil(e2 / n2)]); }, getMemoryOptimizedFloatTextureSize(e2, t2) { const r2 = l.roundTo((e2[0] || 1) * (e2[1] || 1) * (e2[2] || 1) * (e2[3] || 1), 4) / t2; return l.closestSquareDimensions(r2); }, getMemoryOptimizedPackedTextureSize(e2, t2) { const [r2, n2, i2] = e2, s2 = l.roundTo((r2 || 1) * (n2 || 1) * (i2 || 1), 4) / (4 / t2); return l.closestSquareDimensions(s2); }, roundTo: (e2, t2) => Math.floor((e2 + t2 - 1) / t2) * t2, getDimensions(e2, t2) { let r2; if (l.isArray(e2)) { const t3 = []; let n2 = e2; for (; l.isArray(n2); ) t3.push(n2.length), n2 = n2[0]; r2 = t3.reverse(); } else if (e2 instanceof s) r2 = e2.output; else { if (!(e2 instanceof i)) throw new Error(`Unknown dimensions of ${e2}`); r2 = e2.size; } if (t2) for (r2 = Array.from(r2); r2.length < 3; ) r2.push(1); return new Int32Array(r2); }, flatten2dArrayTo(e2, t2) { let r2 = 0; for (let n2 = 0; n2 < e2.length; n2++) t2.set(e2[n2], r2), r2 += e2[n2].length; }, flatten3dArrayTo(e2, t2) { let r2 = 0; for (let n2 = 0; n2 < e2.length; n2++) for (let i2 = 0; i2 < e2[n2].length; i2++) t2.set(e2[n2][i2], r2), r2 += e2[n2][i2].length; }, flatten4dArrayTo(e2, t2) { let r2 = 0; for (let n2 = 0; n2 < e2.length; n2++) for (let i2 = 0; i2 < e2[n2].length; i2++) for (let s2 = 0; s2 < e2[n2][i2].length; s2++) t2.set(e2[n2][i2][s2], r2), r2 += e2[n2][i2][s2].length; }, flattenTo(e2, t2) { l.isArray(e2[0]) ? l.isArray(e2[0][0]) ? l.isArray(e2[0][0][0]) ? l.flatten4dArrayTo(e2, t2) : l.flatten3dArrayTo(e2, t2) : l.flatten2dArrayTo(e2, t2) : t2.set(e2); }, splitArray(e2, t2) { const r2 = []; for (let n2 = 0; n2 < e2.length; n2 += t2) r2.push(new e2.constructor(e2.buffer, 4 * n2 + e2.byteOffset, t2)); return r2; }, getAstString(e2, t2) { const r2 = Array.isArray(e2) ? e2 : e2.split(/\r?\n/g), n2 = t2.loc.start, i2 = t2.loc.end, s2 = []; if (n2.line === i2.line) s2.push(r2[n2.line - 1].substring(n2.column, i2.column)); else { s2.push(r2[n2.line - 1].slice(n2.column)); for (let e3 = n2.line; e3 < i2.line; e3++) s2.push(r2[e3]); s2.push(r2[i2.line - 1].slice(0, i2.column)); } return s2.join("\n"); }, allPropertiesOf(e2) { const t2 = []; do { t2.push.apply(t2, Object.getOwnPropertyNames(e2)); } while (e2 = Object.getPrototypeOf(e2)); return t2; }, linesToString: (e2) => e2.length > 0 ? e2.join(";\n") + ";\n" : "\n", warnDeprecated(e2, t2, r2) { r2 ? console.warn(`You are using a deprecated ${e2} "${t2}". It has been replaced with "${r2}". Fixing, but please upgrade as it will soon be removed.`) : console.warn(`You are using a deprecated ${e2} "${t2}". It has been removed. Fixing, but please upgrade as it will soon be removed.`); }, flipPixels: (e2, t2, r2) => { const n2 = r2 / 2 | 0, i2 = 4 * t2, s2 = new Uint8ClampedArray(4 * t2), a2 = e2.slice(0); for (let e3 = 0; e3 < n2; ++e3) { const t3 = e3 * i2, n3 = (r2 - e3 - 1) * i2; s2.set(a2.subarray(t3, t3 + i2)), a2.copyWithin(t3, n3, n3 + i2), a2.set(s2, n3); } return a2; }, erectPackedFloat: (e2, t2) => e2.subarray(0, t2), erect2DPackedFloat: (e2, t2, r2) => { const n2 = new Array(r2); for (let i2 = 0; i2 < r2; i2++) { const r3 = i2 * t2, s2 = r3 + t2; n2[i2] = e2.subarray(r3, s2); } return n2; }, erect3DPackedFloat: (e2, t2, r2, n2) => { const i2 = new Array(n2); for (let s2 = 0; s2 < n2; s2++) { const n3 = new Array(r2); for (let i3 = 0; i3 < r2; i3++) { const a2 = s2 * r2 * t2 + i3 * t2, o2 = a2 + t2; n3[i3] = e2.subarray(a2, o2); } i2[s2] = n3; } return i2; }, erectMemoryOptimizedFloat: (e2, t2) => e2.subarray(0, t2), erectMemoryOptimized2DFloat: (e2, t2, r2) => { const n2 = new Array(r2); for (let i2 = 0; i2 < r2; i2++) { const r3 = i2 * t2; n2[i2] = e2.subarray(r3, r3 + t2); } return n2; }, erectMemoryOptimized3DFloat: (e2, t2, r2, n2) => { const i2 = new Array(n2); for (let s2 = 0; s2 < n2; s2++) { const n3 = new Array(r2); for (let i3 = 0; i3 < r2; i3++) { const a2 = s2 * r2 * t2 + i3 * t2; n3[i3] = e2.subarray(a2, a2 + t2); } i2[s2] = n3; } return i2; }, erectFloat: (e2, t2) => { const r2 = new Float32Array(t2); let n2 = 0; for (let i2 = 0; i2 < t2; i2++) r2[i2] = e2[n2], n2 += 4; return r2; }, erect2DFloat: (e2, t2, r2) => { const n2 = new Array(r2); let i2 = 0; for (let s2 = 0; s2 < r2; s2++) { const r3 = new Float32Array(t2); for (let n3 = 0; n3 < t2; n3++) r3[n3] = e2[i2], i2 += 4; n2[s2] = r3; } return n2; }, erect3DFloat: (e2, t2, r2, n2) => { const i2 = new Array(n2); let s2 = 0; for (let a2 = 0; a2 < n2; a2++) { const n3 = new Array(r2); for (let i3 = 0; i3 < r2; i3++) { const r3 = new Float32Array(t2); for (let n4 = 0; n4 < t2; n4++) r3[n4] = e2[s2], s2 += 4; n3[i3] = r3; } i2[a2] = n3; } return i2; }, erectArray2: (e2, t2) => { const r2 = new Array(t2), n2 = 4 * t2; let i2 = 0; for (let t3 = 0; t3 < n2; t3 += 4) r2[i2++] = e2.subarray(t3, t3 + 2); return r2; }, erect2DArray2: (e2, t2, r2) => { const n2 = new Array(r2), i2 = 4 * t2; for (let s2 = 0; s2 < r2; s2++) { const r3 = new Array(t2), a2 = s2 * i2; let o2 = 0; for (let t3 = 0; t3 < i2; t3 += 4) r3[o2++] = e2.subarray(t3 + a2, t3 + a2 + 2); n2[s2] = r3; } return n2; }, erect3DArray2: (e2, t2, r2, n2) => { const i2 = 4 * t2, s2 = new Array(n2); for (let a2 = 0; a2 < n2; a2++) { const n3 = new Array(r2); for (let s3 = 0; s3 < r2; s3++) { const o2 = new Array(t2), u2 = a2 * i2 * r2 + s3 * i2; let l2 = 0; for (let t3 = 0; t3 < i2; t3 += 4) o2[l2++] = e2.subarray(t3 + u2, t3 + u2 + 2); n3[s3] = o2; } s2[a2] = n3; } return s2; }, erectArray3: (e2, t2) => { const r2 = new Array(t2), n2 = 4 * t2; let i2 = 0; for (let t3 = 0; t3 < n2; t3 += 4) r2[i2++] = e2.subarray(t3, t3 + 3); return r2; }, erect2DArray3: (e2, t2, r2) => { const n2 = 4 * t2, i2 = new Array(r2); for (let s2 = 0; s2 < r2; s2++) { const r3 = new Array(t2), a2 = s2 * n2; let o2 = 0; for (let t3 = 0; t3 < n2; t3 += 4) r3[o2++] = e2.subarray(t3 + a2, t3 + a2 + 3); i2[s2] = r3; } return i2; }, erect3DArray3: (e2, t2, r2, n2) => { const i2 = 4 * t2, s2 = new Array(n2); for (let a2 = 0; a2 < n2; a2++) { const n3 = new Array(r2); for (let s3 = 0; s3 < r2; s3++) { const o2 = new Array(t2), u2 = a2 * i2 * r2 + s3 * i2; let l2 = 0; for (let t3 = 0; t3 < i2; t3 += 4) o2[l2++] = e2.subarray(t3 + u2, t3 + u2 + 3); n3[s3] = o2; } s2[a2] = n3; } return s2; }, erectArray4: (e2, t2) => { const r2 = new Array(e2), n2 = 4 * t2; let i2 = 0; for (let t3 = 0; t3 < n2; t3 += 4) r2[i2++] = e2.subarray(t3, t3 + 4); return r2; }, erect2DArray4: (e2, t2, r2) => { const n2 = 4 * t2, i2 = new Array(r2); for (let s2 = 0; s2 < r2; s2++) { const r3 = new Array(t2), a2 = s2 * n2; let o2 = 0; for (let t3 = 0; t3 < n2; t3 += 4) r3[o2++] = e2.subarray(t3 + a2, t3 + a2 + 4); i2[s2] = r3; } return i2; }, erect3DArray4: (e2, t2, r2, n2) => { const i2 = 4 * t2, s2 = new Array(n2); for (let a2 = 0; a2 < n2; a2++) { const n3 = new Array(r2); for (let s3 = 0; s3 < r2; s3++) { const o2 = new Array(t2), u2 = a2 * i2 * r2 + s3 * i2; let l2 = 0; for (let t3 = 0; t3 < i2; t3 += 4) o2[l2++] = e2.subarray(t3 + u2, t3 + u2 + 4); n3[s3] = o2; } s2[a2] = n3; } return s2; }, flattenFunctionToString: (e2, t2) => { const { findDependency: r2, thisLookup: i2, doNotDefine: s2 } = t2; let a2 = t2.flattened; a2 || (a2 = t2.flattened = {}); const o2 = n.parse(e2), u2 = []; let h2 = 0; const c2 = function e3(t3) { if (Array.isArray(t3)) { const r3 = []; for (let n2 = 0; n2 < t3.length; n2++) r3.push(e3(t3[n2])); return r3.join(""); } switch (t3.type) { case "Program": return e3(t3.body) + ("VariableDeclaration" === t3.body[0].type ? ";" : ""); case "FunctionDeclaration": return `function ${t3.id.name}(${t3.params.map(e3).join(", ")}) ${e3(t3.body)}`; case "BlockStatement": { const r3 = []; h2 += 2; for (let n3 = 0; n3 < t3.body.length; n3++) { const i3 = e3(t3.body[n3]); i3 && r3.push(" ".repeat(h2) + i3, ";\n"); } return h2 -= 2, `{ ${r3.join("")}}`; } case "VariableDeclaration": const n2 = l.normalizeDeclarations(t3).map(e3).filter((e4) => null !== e4); return n2.length < 1 ? "" : `${t3.kind} ${n2.join(",")}`; case "VariableDeclarator": if (t3.init.object && "ThisExpression" === t3.init.object.type) { return i2(t3.init.property.name, true) ? `${t3.id.name} = ${e3(t3.init)}` : null; } return `${t3.id.name} = ${e3(t3.init)}`; case "CallExpression": if ("subarray" === t3.callee.property.name) return `${e3(t3.callee.object)}.${e3(t3.callee.property)}(${t3.arguments.map((t4) => e3(t4)).join(", ")})`; if ("gl" === t3.callee.object.name || "context" === t3.callee.object.name) return `${e3(t3.callee.object)}.${e3(t3.callee.property)}(${t3.arguments.map((t4) => e3(t4)).join(", ")})`; if ("ThisExpression" === t3.callee.object.type) return u2.push(r2("this", t3.callee.property.name)), `${t3.callee.property.name}(${t3.arguments.map((t4) => e3(t4)).join(", ")})`; if (t3.callee.object.name) { const n3 = r2(t3.callee.object.name, t3.callee.property.name); return null === n3 ? `${t3.callee.object.name}.${t3.callee.property.name}(${t3.arguments.map((t4) => e3(t4)).join(", ")})` : (u2.push(n3), `${t3.callee.property.name}(${t3.arguments.map((t4) => e3(t4)).join(", ")})`); } if ("MemberExpression" === t3.callee.object.type) return `${e3(t3.callee.object)}.${t3.callee.property.name}(${t3.arguments.map((t4) => e3(t4)).join(", ")})`; throw new Error("unknown ast.callee"); case "ReturnStatement": return `return ${e3(t3.argument)}`; case "BinaryExpression": return `(${e3(t3.left)}${t3.operator}${e3(t3.right)})`; case "UnaryExpression": return t3.prefix ? `${t3.operator} ${e3(t3.argument)}` : `${e3(t3.argument)} ${t3.operator}`; case "ExpressionStatement": return `${e3(t3.expression)}`; case "SequenceExpression": return `(${e3(t3.expressions)})`; case "ArrowFunctionExpression": return `(${t3.params.map(e3).join(", ")}) => ${e3(t3.body)}`; case "Literal": return t3.raw; case "Identifier": return t3.name; case "MemberExpression": return "ThisExpression" === t3.object.type ? i2(t3.property.name) : t3.computed ? `${e3(t3.object)}[${e3(t3.property)}]` : e3(t3.object) + "." + e3(t3.property); case "ThisExpression": return "this"; case "NewExpression": return `new ${e3(t3.callee)}(${t3.arguments.map((t4) => e3(t4)).join(", ")})`; case "ForStatement": return `for (${e3(t3.init)};${e3(t3.test)};${e3(t3.update)}) ${e3(t3.body)}`; case "AssignmentExpression": return `${e3(t3.left)}${t3.operator}${e3(t3.right)}`; case "UpdateExpression": return `${e3(t3.argument)}${t3.operator}`; case "IfStatement": return `if (${e3(t3.test)}) ${e3(t3.consequent)}`; case "ThrowStatement": return `throw ${e3(t3.argument)}`; case "ObjectPattern": return t3.properties.map(e3).join(", "); case "ArrayPattern": return t3.elements.map(e3).join(", "); case "DebuggerStatement": return "debugger;"; case "ConditionalExpression": return `${e3(t3.test)}?${e3(t3.consequent)}:${e3(t3.alternate)}`; case "Property": if ("init" === t3.kind) return e3(t3.key); } throw new Error(`unhandled ast.type of ${t3.type}`); }(o2); if (u2.length > 0) { const e3 = []; for (let r3 = 0; r3 < u2.length; r3++) { const n2 = u2[r3]; a2[n2] || (a2[n2] = true), n2 && e3.push(l.flattenFunctionToString(n2, t2) + "\n"); } return e3.join("") + c2; } return c2; }, normalizeDeclarations: (e2) => { if ("VariableDeclaration" !== e2.type) throw new Error('Ast is not of type "VariableDeclaration"'); const t2 = []; for (let r2 = 0; r2 < e2.declarations.length; r2++) { const n2 = e2.declarations[r2]; if (n2.id && "ObjectPattern" === n2.id.type && n2.id.properties) { const { properties: e3 } = n2.id; for (let r3 = 0; r3 < e3.length; r3++) { const i2 = e3[r3]; if ("ObjectPattern" === i2.value.type && i2.value.properties) for (let e4 = 0; e4 < i2.value.properties.length; e4++) { const r4 = i2.value.properties[e4]; if ("Property" !== r4.type) throw new Error("unexpected state"); t2.push({ type: "VariableDeclarator", id: { type: "Identifier", name: r4.key.name }, init: { type: "MemberExpression", object: { type: "MemberExpression", object: n2.init, property: { type: "Identifier", name: i2.key.name }, computed: false }, property: { type: "Identifier", name: r4.key.name }, computed: false } }); } else { if ("Identifier" !== i2.value.type) throw new Error("unexpected state"); t2.push({ type: "VariableDeclarator", id: { type: "Identifier", name: i2.value && i2.value.name ? i2.value.name : i2.key.name }, init: { type: "MemberExpression", object: n2.init, property: { type: "Identifier", name: i2.key.name }, computed: false } }); } } } else if (n2.id && "ArrayPattern" === n2.id.type && n2.id.elements) { const { elements: e3 } = n2.id; for (let r3 = 0; r3 < e3.length; r3++) { const i2 = e3[r3]; if ("Identifier" !== i2.type) throw new Error("unexpected state"); t2.push({ type: "VariableDeclarator", id: { type: "Identifier", name: i2.name }, init: { type: "MemberExpression", object: n2.init, property: { type: "Literal", value: r3, raw: r3.toString(), start: i2.start, end: i2.end }, computed: true } }); } } else t2.push(n2); } return t2; }, splitHTMLImageToRGB: (e2, t2) => { const r2 = e2.createKernel(function(e3) { return 255 * e3[this.thread.y][this.thread.x].r; }, { output: [t2.width, t2.height], precision: "unsigned", argumentTypes: { a: "HTMLImage" } }), n2 = e2.createKernel(function(e3) { return 255 * e3[this.thread.y][this.thread.x].g; }, { output: [t2.width, t2.height], precision: "unsigned", argumentTypes: { a: "HTMLImage" } }), i2 = e2.createKernel(function(e3) { return 255 * e3[this.thread.y][this.thread.x].b; }, { output: [t2.width, t2.height], precision: "unsigned", argumentTypes: { a: "HTMLImage" } }), s2 = e2.createKernel(function(e3) { return 255 * e3[this.thread.y][this.thread.x].a; }, { output: [t2.width, t2.height], precision: "unsigned", argumentTypes: { a: "HTMLImage" } }), a2 = [r2(t2), n2(t2), i2(t2), s2(t2)]; return a2.rKernel = r2, a2.gKernel = n2, a2.bKernel = i2, a2.aKernel = s2, a2.gpu = e2, a2; }, splitRGBAToCanvases: (e2, t2, r2, n2) => { const i2 = e2.createKernel(function(e3) { const t3 = e3[this.thread.y][this.thread.x]; this.color(t3.r / 255, 0, 0, 255); }, { output: [r2, n2], graphical: true, argumentTypes: { v: "Array2D(4)" } }); i2(t2); const s2 = e2.createKernel(function(e3) { const t3 = e3[this.thread.y][this.thread.x]; this.color(0, t3.g / 255, 0, 255); }, { output: [r2, n2], graphical: true, argumentTypes: { v: "Array2D(4)" } }); s2(t2); const a2 = e2.createKernel(function(e3) { const t3 = e3[this.thread.y][this.thread.x]; this.color(0, 0, t3.b / 255, 255); }, { output: [r2, n2], graphical: true, argumentTypes: { v: "Array2D(4)" } }); a2(t2); const o2 = e2.createKernel(function(e3) { const t3 = e3[this.thread.y][this.thread.x]; this.color(255, 255, 255, t3.a / 255); }, { output: [r2, n2], graphical: true, argumentTypes: { v: "Array2D(4)" } }); return o2(t2), [i2.canvas, s2.canvas, a2.canvas, o2.canvas]; }, getMinifySafeName: (e2) => { try { const t2 = n.parse(`const value = ${e2.toString()}`), { init: r2 } = t2.body[0].declarations[0]; return r2.body.name || r2.body.body[0].argument.name; } catch (e3) { throw new Error("Unrecognized function type. Please use `() => yourFunctionVariableHere` or function() { return yourFunctionVariableHere; }"); } }, sanitizeName: function(e2) { return h.test(e2) && (e2 = e2.replace(h, "S_S")), c.test(e2) ? e2 = e2.replace(c, "U_U") : p.test(e2) && (e2 = e2.replace(p, "u_u")), e2; } }, h = /\$/, c = /__/, p = /_/, d = l.getSystemEndianness(); t.exports = { utils: l }; }, { "./input": 110, "./texture": 113, acorn: 1 }] }, {}, [107])(107); }); } }); // <stdin> window.gpuJS = require_gpu(); /** * gpu.js * http://gpu.rocks/ * * GPU Accelerated JavaScript * * @version 2.16.0 * @date Thu Feb 13 2025 11:46:50 GMT-0800 (Pacific Standard Time) * * @license MIT * The MIT License * * Copyright (c) 2025 gpu.js Team */ /** * gpu.js * http://gpu.rocks/ * * GPU Accelerated JavaScript * * @version 2.16.0 * @date Thu Feb 13 2025 11:46:48 GMT-0800 (Pacific Standard Time) * * @license MIT * The MIT License * * Copyright (c) 2025 gpu.js Team */
Now we have an easy access to this framework.
Compute shaders
Here we use GPU.js to write a compute shader in Javascript, which use privded array of 2D points and renders their density to a canvas. We shall support the possibillity to update the image in real-time and use PlotRange
, ImageSize
parameters similar to Plot
function
.js function getColor(t) { if (t >= 0 && t <= 0.25) return [255.0 + (- 255.0) * t / 0.25, 255.0 + (- 255.0) * t / 0.25, 255.0]; if (t >= 0.25 && t <= 0.55) return [0.0, 255.0 * (t - 0.25) / 0.3, 255.0 + (- 255.0) * (t - 0.25) / 0.3]; if (t >= 0.55 && t <= 0.85) return [255.0 * (t - 0.55) / 0.3, 255.0, 0.0]; if (t >= 0.85 && t <= 1) return [255.0, 255.0 + (- 255.0) * (t - 0.85) / 0.15, 0.0]; return [255.0,255.0,255.0]; } core.HeatMap = async (args, env) => { const gpu = new window.gpuJS.GPU(); const options = await core._getRules(args, env); env.local.gpu = gpu; let [width, height] = [320, 240]; let plotRange = [[-1,1], [-1,1]]; if (options.ImageSize) { if (Array.isArray(options.ImageSize)) [width, height] = options.ImageSize; else [width, height] = [Math.round(options.ImageSize), Math.round(options.ImageSize/1.6180339)]; } if (options.PlotRange) { plotRange = options.PlotRange; } plotRange = [ plotRange[0][0], width / (plotRange[0][1] - plotRange[0][0]), plotRange[1][0], height / (plotRange[1][1] - plotRange[1][0]) ]; const points = await interpretate(args[0], env); let alpha = 10000.0; if (args.length - Object.keys(options).length > 1) { alpha = await interpretate(args[1], env); env.local.alpha_has = true; } env.local.alpha = alpha; env.local.kernel = gpu.createKernel(function(points, pointCount, alpha) { let intensity = 0; for (let i = 0; i < pointCount; i++) { const pointX = (points[i * 2] - this.constants.plotRange[0]) * this.constants.plotRange[1]; const pointY = (points[i * 2 + 1] - this.constants.plotRange[2]) * this.constants.plotRange[3]; const dx = (this.thread.x - pointX)/this.constants.width; const dy = (this.thread.y - pointY)/this.constants.height; const dist = dx * dx + dy * dy; intensity += 1.0/(dist * alpha + 1.0); // Blurry effect } intensity = Math.min(intensity, 1); // Cap intensity const baseColor = getColor(intensity); let blendedColor = [ baseColor[0] * intensity + (1.0 - intensity)*255, baseColor[1] * intensity + (1.0 - intensity)*255, baseColor[2] * intensity + (1.0 - intensity)*255 ]; this.color(blendedColor[0] / 255, blendedColor[1] / 255, blendedColor[2] / 255); }, { dynamicArguments: true, constants: { plotRange: plotRange, width: width, height: height } }) .setOutput([width, height]) .setGraphical(true) .setFunctions([getColor]); env.element.appendChild(env.local.kernel.canvas); if (points instanceof NumericArrayObject) { env.local.kernel(new Float32Array(points.buffer), points.dims[0], alpha); return; } env.local.kernel(points.flat(), points.length, alpha); } core.HeatMap.virtual = true core.HeatMap.destroy = (args, env) => { env.local.kernel.destroy(); env.local.gpu.destroy(); delete env.local.gpu; delete env.local.kernel; } core.HeatMap.update = async (args, env) => { let alpha = env.local.alpha; if (env.local.alpha_has) { alpha = await interpretate(args[1], env); } const data = await interpretate(args[0], env); if (data instanceof NumericArrayObject) { env.local.kernel(new Float32Array(data.buffer), data.dims[0], alpha); return; } env.local.kernel(data.flat(), data.length, alpha); } this.ondestroy(() => { gpu.destroy(); }); return 'If you see it, it works'
function getColor(t) { if (t >= 0 && t <= 0.25) return [255.0 + (- 255.0) * t / 0.25, 255.0 + (- 255.0) * t / 0.25, 255.0]; if (t >= 0.25 && t <= 0.55) return [0.0, 255.0 * (t - 0.25) / 0.3, 255.0 + (- 255.0) * (t - 0.25) / 0.3]; if (t >= 0.55 && t <= 0.85) return [255.0 * (t - 0.55) / 0.3, 255.0, 0.0]; if (t >= 0.85 && t <= 1) return [255.0, 255.0 + (- 255.0) * (t - 0.85) / 0.15, 0.0]; return [255.0,255.0,255.0]; } core.HeatMap = async (args, env) => { const gpu = new window.gpuJS.GPU(); const options = await core._getRules(args, env); env.local.gpu = gpu; let [width, height] = [320, 240]; let plotRange = [[-1,1], [-1,1]]; if (options.ImageSize) { if (Array.isArray(options.ImageSize)) [width, height] = options.ImageSize; else [width, height] = [Math.round(options.ImageSize), Math.round(options.ImageSize/1.6180339)]; } if (options.PlotRange) { plotRange = options.PlotRange; } plotRange = [ plotRange[0][0], width / (plotRange[0][1] - plotRange[0][0]), plotRange[1][0], height / (plotRange[1][1] - plotRange[1][0]) ]; const points = await interpretate(args[0], env); let alpha = 10000.0; if (args.length - Object.keys(options).length > 1) { alpha = await interpretate(args[1], env); env.local.alpha_has = true; } env.local.alpha = alpha; env.local.kernel = gpu.createKernel(function(points, pointCount, alpha) { let intensity = 0; for (let i = 0; i < pointCount; i++) { const pointX = (points[i * 2] - this.constants.plotRange[0]) * this.constants.plotRange[1]; const pointY = (points[i * 2 + 1] - this.constants.plotRange[2]) * this.constants.plotRange[3]; const dx = (this.thread.x - pointX)/this.constants.width; const dy = (this.thread.y - pointY)/this.constants.height; const dist = dx * dx + dy * dy; intensity += 1.0/(dist * alpha + 1.0); // Blurry effect } intensity = Math.min(intensity, 1); // Cap intensity const baseColor = getColor(intensity); let blendedColor = [ baseColor[0] * intensity + (1.0 - intensity)*255, baseColor[1] * intensity + (1.0 - intensity)*255, baseColor[2] * intensity + (1.0 - intensity)*255 ]; this.color(blendedColor[0] / 255, blendedColor[1] / 255, blendedColor[2] / 255); }, { dynamicArguments: true, constants: { plotRange: plotRange, width: width, height: height } }) .setOutput([width, height]) .setGraphical(true) .setFunctions([getColor]); env.element.appendChild(env.local.kernel.canvas); if (points instanceof NumericArrayObject) { env.local.kernel(new Float32Array(points.buffer), points.dims[0], alpha); return; } env.local.kernel(points.flat(), points.length, alpha); } core.HeatMap.virtual = true core.HeatMap.destroy = (args, env) => { env.local.kernel.destroy(); env.local.gpu.destroy(); delete env.local.gpu; delete env.local.kernel; } core.HeatMap.update = async (args, env) => { let alpha = env.local.alpha; if (env.local.alpha_has) { alpha = await interpretate(args[1], env); } const data = await interpretate(args[0], env); if (data instanceof NumericArrayObject) { env.local.kernel(new Float32Array(data.buffer), data.dims[0], alpha); return; } env.local.kernel(data.flat(), data.length, alpha); } this.ondestroy(() => { gpu.destroy(); }); return 'If you see it, it works'
Output form
To display the heatmap, we need to define an output form in Wolfram Language, that will use Javascript to render the widget
HeatMap /: MakeBoxes[h_HeatMap, StandardForm] := With[{}, ViewBox[h, h] ] HeatMap /: MakeBoxes[h_HeatMap, StandardForm] := With[{ o = CreateFrontEndObject[h] }, MakeBoxes[o, StandardForm] ] /; ByteCount[h] > 1024 Options[HeatMap] = {ImageSize->{320, 240}, PlotRange->{{-1,1}, {-1,1}}};
Test
Create a bunch of points and render it
HeatMap[Exp[-Norm[#]]# &/@ RandomReal[{-Pi,Pi}, {30,2}]]
(*VB[*)(FrontEndRef["ee52e033-8e00-49d5-9427-91a42d3e707e"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKp6aaGqUaGBvrWqQaGOiaWKaY6lqaGJnrWhommhilGKeaG5inAgB7rhUY"*)(*]VB*)
Integration with Graphics
Using basic Inset
we can place it under any graphics
range = {{-1,1}, {-1,1}}/2.0; dataset = Exp[-Norm[#]]# &/@ RandomReal[{-Pi,Pi}, {50,2}]; Graphics[{ ColorData[97][4], PointSize[0.03], Inset[ HeatMap[dataset, 4000, PlotRange->range, ImageSize->{344,244}], (range[[All,1]]+range[[All,2]])/2.0 ], Point[dataset] }, PlotRange->range, ImageSize->{420,320}, ImagePadding->30, Frame->True, Axes->True ]
(*VB[*)(FrontEndRef["7bdb2f83-0227-44a0-a6ba-cc60256bcc48"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKmyelJBmlWRjrGhgZmeuamCQa6CaaJSXqJiebGRiZmiUlJ5tYAACFyxXA"*)(*]VB*)
Make it dynamic
We should take a full advantage of the WebGL and perform smooth animation of the data points. For this we define helper function to guide our points though the calculated path
fixedPoint[args__, maxN_:Infinity] := NestWhile[Function[input, With[{ pos = input[[1]], target = input[[2]], velocity = input[[3]], iteration = input[[4]] }, { pos + 0.01 velocity, target, velocity 0.9 + 0.1 (Normalize /@ ( target - pos)), iteration + 1 }] ], {args}, (Max[Abs[#[[1]]-#[[2]]]]>0.1 && #[[4]] <= maxN)&][[{1,4}]]
Now we generate the data, find the number of interations steps until all points converge the target positions and assign a slider to control the process
(* input data *) range = {{-1,1}, {-1,1}}; points = RandomPoint[RegionDifference[Disk[{0,0}, 0.6], Disk[{0,0}, 0.5]], 100]; (* place points outside the viewport *) offscreenPos = With[{corners = range // Transpose}, RandomPoint[ RegionDifference[ Rectangle @@ (2 corners), Rectangle @@ corners ], Length[points] ] ]; (* procedurally animate each particle *) With[{ vel = 0.1 RandomReal[{-1,1}, {Length[points], 2}], target = points }, points = offscreenPos; With[{ maxIterations = fixedPoint[offscreenPos, target, vel, 0, Infinity][[2]] }, EventHandler[InputRange[0, maxIterations, 1, 0], Function[i, points = fixedPoint[offscreenPos, target, vel, 0, i][[1]] ]] ] ] (* render *) Graphics[{ ColorData[97][4], PointSize[0.03], Inset[ HeatMap[points // Offload, 4000, PlotRange->range, ImageSize->{344,244}], (range[[All,1]]+range[[All,2]])/2.0 ], Point[points // Offload] }, PlotRange->range, ImageSize->{420,320}, ImagePadding->30, Frame->True, Axes->True, TransitionType->None, "Control"->False ]
(*VB[*)(EventObject[<|"Id" -> "08fe085f-837c-4f46-ab45-2247e81e255a", "Initial" -> 0, "View" -> "cd8b94cd-ab75-4cd4-a14f-af3f2da3b45f"|>])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgEKJ6dYJFmaJKfoJiaZm+oCGSa6iYYmabqJacZpRimJxkkmpmkAmqEWvQ=="*)(*]VB*)
(*VB[*)(Graphics[{RGBColor[0.922526, 0.385626, 0.209179], PointSize[0.03], Inset[HeatMap[Offload[points], 4000, PlotRange -> {{-1, 1}, {-1, 1}}, ImageSize -> {344, 244}], {0., 0.}], Point[Offload[points]]}, PlotRange -> {{-1, 1}, {-1, 1}}, ImageSize -> {420, 320}, ImagePadding -> 30, Frame -> True, Axes -> True, TransitionType -> None, "Control" -> False])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KWkcIB6IcC9KLMjITC5OY4HJ+2QWl6Qxw+SD3J2c83Pyi4qubP1mF9r61r7ojv78NRLrbtgXabgzLko4dsoeYjQnkAjIz8wrCc6sSi3aIdf6OnDHPPs0JpAcK5DwzCtOLYHYwg5yRWpiiW9iAUQvSMA/LS0nPzGlmA3ILgCZU5y5gJ+BAWIASFtQaU4qxJac/JKgxLz0VIQc2M0ovMz/QJAJMp2wONxkz9zE9FSQ+9H0RADVZ37BMKuIAQrgDIh3WGFBgc93g8JjS0Aec2DE0MMD0xOQmJKSmZeeKYdpLsiXbkWJualgoZCi0lQ0BSCGY0VqMS55PrBwYl5xZklmfl5IZQFEi19+HprKYFAIOufnlRTl50CsTcwpTgUANdCtJw=="*)(*]VB*)
Try to drag. Its alive!