js_prelude.js 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229
  1. /* Web platform APIs for the NebOS browser, written in JavaScript on top of a
  2. * few C primitives (js_browser.c):
  3. * __nb_http(method, url, contentType, body) -> [status, ctype, finalUrl, text]
  4. * __nb_storage(kind[, text]) kind 0 = localStorage, 1 = sessionStorage
  5. * __nb_resolve(base, relative) -> absolute URL
  6. * __nb_nodeproto prototype shared by every DOM node wrapper
  7. * It runs once per page state, before the page's scripts; the primitives are
  8. * removed from the global object afterwards. Embedded by js_prelude.S. */
  9. (function (g) {
  10. "use strict";
  11. var http = g.__nb_http, storage = g.__nb_storage, resolve = g.__nb_resolve;
  12. var nodeproto = g.__nb_nodeproto;
  13. delete g.__nb_http; delete g.__nb_storage; delete g.__nb_resolve;
  14. delete g.__nb_nodeproto;
  15. var hasOwn = Object.prototype.hasOwnProperty;
  16. function def(name, value) {
  17. Object.defineProperty(g, name, { value: value, writable: true,
  18. configurable: true, enumerable: false });
  19. }
  20. /* ---- console, timers, misc globals ---- */
  21. var con = g.console, rawlog = con.log;
  22. /* Errors print with their stack (Vue reports caught errors this way). */
  23. function fmt(a) {
  24. if (a instanceof Error)
  25. return a.name + ": " + a.message + (a.stack ? "\n" + a.stack : "");
  26. if (a !== null && typeof a === "object" && !(typeof a.nodeType === "number")) {
  27. try { return JSON.stringify(a); } catch (e) { return String(a); }
  28. }
  29. return a;
  30. }
  31. function logger(prefix) {
  32. return function () {
  33. var args = Array.prototype.map.call(arguments, fmt);
  34. if (prefix) args.unshift(prefix);
  35. rawlog.apply(con, args);
  36. };
  37. }
  38. con.log = logger("");
  39. con.info = logger("");
  40. con.debug = logger("");
  41. con.dir = logger("");
  42. con.warn = logger("[warn]");
  43. con.error = logger("[error]");
  44. con.trace = logger("[trace]");
  45. ["group", "groupCollapsed", "groupEnd", "time", "timeEnd", "timeLog",
  46. "table", "count", "countReset", "clear"].forEach(function (k) {
  47. if (!con[k]) con[k] = function () {};
  48. });
  49. con.assert = function (c) {
  50. if (!c) con.log.apply(con, ["Assertion failed:"].concat(
  51. Array.prototype.slice.call(arguments, 1)));
  52. };
  53. def("self", g); def("top", g); def("parent", g); def("frames", g);
  54. def("isSecureContext", true);
  55. def("origin", g.location.origin);
  56. /* The engine's own Promise, captured before any page script runs: core-js
  57. * (heise's consent script) installs a Promise polyfill that schedules its
  58. * reactions through queueMicrotask, and a queueMicrotask built on the
  59. * replaced global Promise would call back into the polyfill forever. */
  60. var NativePromise = Promise;
  61. def("queueMicrotask", function (f) { NativePromise.resolve().then(f); });
  62. /* Present so core-js keeps the native Promise (it polyfills browsers that
  63. * lack unhandled-rejection events). */
  64. class PromiseRejectionEvent {
  65. constructor(type, init) {
  66. this.type = type;
  67. this.promise = init && init.promise;
  68. this.reason = init && init.reason;
  69. }
  70. }
  71. def("PromiseRejectionEvent", PromiseRejectionEvent);
  72. def("requestIdleCallback", function (f) {
  73. return setTimeout(function () {
  74. f({ didTimeout: false, timeRemaining: function () { return 10; } });
  75. }, 1);
  76. });
  77. def("cancelIdleCallback", function (id) { clearTimeout(id); });
  78. def("structuredClone", function (v) {
  79. return v === undefined ? v : JSON.parse(JSON.stringify(v));
  80. });
  81. class DOMException extends Error {
  82. constructor(message, name) {
  83. super(message === undefined ? "" : message);
  84. this.name = name === undefined ? "Error" : name;
  85. }
  86. }
  87. def("DOMException", DOMException);
  88. /* ---- base64 ---- */
  89. var B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  90. def("btoa", function (s) {
  91. s = String(s);
  92. var out = "", i;
  93. for (i = 0; i < s.length; i += 3) {
  94. var a = s.charCodeAt(i), b = s.charCodeAt(i + 1),
  95. c = s.charCodeAt(i + 2);
  96. if (a > 255 || b > 255 || c > 255)
  97. throw new DOMException("Invalid character",
  98. "InvalidCharacterError");
  99. var n = (a << 16) | ((b || 0) << 8) | (c || 0);
  100. out += B64[n >> 18 & 63] + B64[n >> 12 & 63] +
  101. (i + 1 < s.length ? B64[n >> 6 & 63] : "=") +
  102. (i + 2 < s.length ? B64[n & 63] : "=");
  103. }
  104. return out;
  105. });
  106. def("atob", function (s) {
  107. s = String(s).replace(/[\s=]/g, "");
  108. var out = "", bits = 0, acc = 0, i;
  109. for (i = 0; i < s.length; i++) {
  110. var v = B64.indexOf(s[i]);
  111. if (v < 0)
  112. throw new DOMException("Invalid character",
  113. "InvalidCharacterError");
  114. acc = (acc << 6) | v;
  115. bits += 6;
  116. if (bits >= 8) {
  117. bits -= 8;
  118. out += String.fromCharCode((acc >> bits) & 255);
  119. }
  120. }
  121. return out;
  122. });
  123. /* ---- text encoding ---- */
  124. function utf8(s) {
  125. var out = [], i;
  126. s = String(s);
  127. for (i = 0; i < s.length; i++) {
  128. var c = s.charCodeAt(i);
  129. if (c >= 0xd800 && c < 0xdc00 && i + 1 < s.length) {
  130. var d = s.charCodeAt(i + 1);
  131. if (d >= 0xdc00 && d < 0xe000) {
  132. c = 0x10000 + ((c - 0xd800) << 10) + (d - 0xdc00);
  133. i++;
  134. }
  135. }
  136. if (c < 0x80) out.push(c);
  137. else if (c < 0x800) out.push(0xc0 | c >> 6, 0x80 | c & 63);
  138. else if (c < 0x10000)
  139. out.push(0xe0 | c >> 12, 0x80 | c >> 6 & 63, 0x80 | c & 63);
  140. else
  141. out.push(0xf0 | c >> 18, 0x80 | c >> 12 & 63,
  142. 0x80 | c >> 6 & 63, 0x80 | c & 63);
  143. }
  144. return new Uint8Array(out);
  145. }
  146. function bytesOf(b) {
  147. if (b instanceof ArrayBuffer) return new Uint8Array(b);
  148. if (ArrayBuffer.isView(b))
  149. return new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
  150. return utf8(b);
  151. }
  152. function unutf8(u) {
  153. var s = "", i = 0;
  154. while (i < u.length) {
  155. var c = u[i++];
  156. if (c >= 0xf0 && i + 2 < u.length + 0) {
  157. c = ((c & 7) << 18) | ((u[i++] & 63) << 12) |
  158. ((u[i++] & 63) << 6) | (u[i++] & 63);
  159. } else if (c >= 0xe0) {
  160. c = ((c & 15) << 12) | ((u[i++] & 63) << 6) | (u[i++] & 63);
  161. } else if (c >= 0xc0) {
  162. c = ((c & 31) << 6) | (u[i++] & 63);
  163. }
  164. s += String.fromCodePoint(c);
  165. }
  166. return s;
  167. }
  168. class TextEncoder {
  169. get encoding() { return "utf-8"; }
  170. encode(s) { return utf8(s === undefined ? "" : s); }
  171. }
  172. class TextDecoder {
  173. constructor(label) { this.encoding = "utf-8"; }
  174. decode(b) { return b ? unutf8(bytesOf(b)) : ""; }
  175. }
  176. def("TextEncoder", TextEncoder);
  177. def("TextDecoder", TextDecoder);
  178. /* ---- URLSearchParams / URL ---- */
  179. function qenc(s) {
  180. return encodeURIComponent(s).replace(/%20/g, "+").replace(/[!'()~]/g,
  181. function (c) {
  182. return "%" + c.charCodeAt(0).toString(16).toUpperCase();
  183. });
  184. }
  185. function qdec(s) {
  186. s = s.replace(/\+/g, " ");
  187. try { return decodeURIComponent(s); } catch (e) { return s; }
  188. }
  189. class URLSearchParams {
  190. constructor(init) {
  191. this._l = [];
  192. this._url = null;
  193. if (init == null) return;
  194. if (init instanceof URLSearchParams) {
  195. this._l = init._l.map(function (p) { return [p[0], p[1]]; });
  196. return;
  197. }
  198. if (typeof init === "object" || typeof init === "function") {
  199. if (typeof init[Symbol.iterator] === "function") {
  200. for (var p of init)
  201. this._l.push([String(p[0]), String(p[1])]);
  202. } else {
  203. for (var k of Object.keys(init))
  204. this._l.push([k, String(init[k])]);
  205. }
  206. return;
  207. }
  208. this._parse(String(init));
  209. }
  210. _parse(s) {
  211. this._l = [];
  212. if (s[0] === "?") s = s.slice(1);
  213. for (var part of s.split("&")) {
  214. if (!part) continue;
  215. var i = part.indexOf("=");
  216. this._l.push(i < 0 ? [qdec(part), ""] :
  217. [qdec(part.slice(0, i)), qdec(part.slice(i + 1))]);
  218. }
  219. }
  220. _upd() {
  221. if (this._url) {
  222. var s = this.toString();
  223. this._url._search = s ? "?" + s : "";
  224. }
  225. }
  226. append(k, v) { this._l.push([String(k), String(v)]); this._upd(); }
  227. delete(k) {
  228. k = String(k);
  229. this._l = this._l.filter(function (p) { return p[0] !== k; });
  230. this._upd();
  231. }
  232. get(k) {
  233. k = String(k);
  234. for (var p of this._l) if (p[0] === k) return p[1];
  235. return null;
  236. }
  237. getAll(k) {
  238. k = String(k);
  239. return this._l.filter(function (p) { return p[0] === k; })
  240. .map(function (p) { return p[1]; });
  241. }
  242. has(k) { return this.get(k) !== null; }
  243. set(k, v) {
  244. k = String(k); v = String(v);
  245. var found = false;
  246. this._l = this._l.filter(function (p) {
  247. if (p[0] !== k) return true;
  248. if (found) return false;
  249. found = true;
  250. p[1] = v;
  251. return true;
  252. });
  253. if (!found) this._l.push([k, v]);
  254. this._upd();
  255. }
  256. sort() {
  257. this._l.sort(function (a, b) {
  258. return a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
  259. });
  260. this._upd();
  261. }
  262. forEach(f, t) { for (var p of this._l.slice()) f.call(t, p[1], p[0], this); }
  263. keys() { return this._l.map(function (p) { return p[0]; })[Symbol.iterator](); }
  264. values() { return this._l.map(function (p) { return p[1]; })[Symbol.iterator](); }
  265. entries() { return this._l.map(function (p) { return [p[0], p[1]]; })[Symbol.iterator](); }
  266. [Symbol.iterator]() { return this.entries(); }
  267. get size() { return this._l.length; }
  268. toString() {
  269. return this._l.map(function (p) {
  270. return qenc(p[0]) + "=" + qenc(p[1]);
  271. }).join("&");
  272. }
  273. }
  274. def("URLSearchParams", URLSearchParams);
  275. var URL_RE = /^([a-zA-Z][a-zA-Z0-9+.\-]*:)(\/\/([^\/?#]*))?([^?#]*)(\?[^#]*)?(#.*)?$/;
  276. class URL {
  277. constructor(url, base) {
  278. url = String(url).trim();
  279. if (!/^[a-zA-Z][a-zA-Z0-9+.\-]*:/.test(url)) {
  280. if (base === undefined)
  281. throw new TypeError("Invalid URL: " + url);
  282. base = new URL(String(base)).href;
  283. url = resolve(base, url);
  284. }
  285. this._parse(url);
  286. }
  287. _parse(u) {
  288. var m = URL_RE.exec(u);
  289. if (!m) throw new TypeError("Invalid URL: " + u);
  290. this._protocol = m[1].toLowerCase();
  291. var auth = m[3] || "", at = auth.lastIndexOf("@");
  292. this._user = "";
  293. this._pass = "";
  294. if (at >= 0) {
  295. var ui = auth.slice(0, at), c = ui.indexOf(":");
  296. auth = auth.slice(at + 1);
  297. this._user = c < 0 ? ui : ui.slice(0, c);
  298. this._pass = c < 0 ? "" : ui.slice(c + 1);
  299. }
  300. var pm = /^(\[[^\]]*\]|[^:]*)(?::(\d*))?$/.exec(auth);
  301. this._hostname = (pm ? pm[1] : auth).toLowerCase();
  302. this._port = (pm && pm[2]) || "";
  303. if ((this._protocol === "https:" && this._port === "443") ||
  304. (this._protocol === "http:" && this._port === "80"))
  305. this._port = "";
  306. this._special = m[2] !== undefined;
  307. this._pathname = m[4] || (this._special ? "/" : "");
  308. this._search = m[5] && m[5].length > 1 ? m[5] : "";
  309. this._hash = m[6] && m[6].length > 1 ? m[6] : "";
  310. if (this._sp) this._sp._parse(this._search);
  311. }
  312. get protocol() { return this._protocol; }
  313. set protocol(v) {
  314. v = String(v);
  315. this._protocol = (v.endsWith(":") ? v : v + ":").toLowerCase();
  316. }
  317. get username() { return this._user; }
  318. set username(v) { this._user = String(v); }
  319. get password() { return this._pass; }
  320. set password(v) { this._pass = String(v); }
  321. get hostname() { return this._hostname; }
  322. set hostname(v) { this._hostname = String(v).toLowerCase(); }
  323. get port() { return this._port; }
  324. set port(v) { this._port = String(v); }
  325. get host() { return this._hostname + (this._port ? ":" + this._port : ""); }
  326. set host(v) {
  327. var m = /^(\[[^\]]*\]|[^:]*)(?::(\d*))?$/.exec(String(v));
  328. if (m) { this._hostname = m[1].toLowerCase(); this._port = m[2] || ""; }
  329. }
  330. get pathname() { return this._pathname; }
  331. set pathname(v) {
  332. v = String(v);
  333. this._pathname = this._special && v[0] !== "/" ? "/" + v : v;
  334. }
  335. get search() { return this._search; }
  336. set search(v) {
  337. v = String(v);
  338. if (v && v[0] !== "?") v = "?" + v;
  339. this._search = v === "?" ? "" : v;
  340. if (this._sp) this._sp._parse(this._search);
  341. }
  342. get hash() { return this._hash; }
  343. set hash(v) {
  344. v = String(v);
  345. if (v && v[0] !== "#") v = "#" + v;
  346. this._hash = v === "#" ? "" : v;
  347. }
  348. get origin() {
  349. return this._special && this._protocol !== "file:" ?
  350. this._protocol + "//" + this.host : "null";
  351. }
  352. get href() {
  353. var a = this._user ? this._user +
  354. (this._pass ? ":" + this._pass : "") + "@" : "";
  355. return this._protocol + (this._special ? "//" + a + this.host : "") +
  356. this._pathname + this._search + this._hash;
  357. }
  358. set href(v) { this._parse(String(v)); }
  359. get searchParams() {
  360. if (!this._sp) {
  361. this._sp = new URLSearchParams(this._search);
  362. this._sp._url = this;
  363. }
  364. return this._sp;
  365. }
  366. toString() { return this.href; }
  367. toJSON() { return this.href; }
  368. static canParse(u, b) {
  369. try { new URL(u, b); return true; } catch (e) { return false; }
  370. }
  371. static parse(u, b) {
  372. try { return new URL(u, b); } catch (e) { return null; }
  373. }
  374. static createObjectURL() { return "blob:nebos/" + Date.now(); }
  375. static revokeObjectURL() {}
  376. }
  377. def("URL", URL);
  378. def("webkitURL", URL);
  379. /* ---- Headers / Blob / FormData / Request / Response ---- */
  380. class Headers {
  381. constructor(init) {
  382. this._m = new Map();
  383. if (!init) return;
  384. if (init instanceof Headers)
  385. init.forEach((v, k) => this.append(k, v));
  386. else if (typeof init[Symbol.iterator] === "function")
  387. for (var p of init) this.append(p[0], p[1]);
  388. else
  389. for (var k of Object.keys(init)) this.append(k, init[k]);
  390. }
  391. append(k, v) {
  392. k = String(k).toLowerCase();
  393. var o = this._m.get(k);
  394. this._m.set(k, o !== undefined ? o + ", " + v : String(v));
  395. }
  396. set(k, v) { this._m.set(String(k).toLowerCase(), String(v)); }
  397. get(k) {
  398. var v = this._m.get(String(k).toLowerCase());
  399. return v === undefined ? null : v;
  400. }
  401. has(k) { return this._m.has(String(k).toLowerCase()); }
  402. delete(k) { this._m.delete(String(k).toLowerCase()); }
  403. forEach(f, t) { for (var [k, v] of this._m) f.call(t, v, k, this); }
  404. keys() { return this._m.keys(); }
  405. values() { return this._m.values(); }
  406. entries() { return this._m.entries(); }
  407. [Symbol.iterator]() { return this._m.entries(); }
  408. }
  409. def("Headers", Headers);
  410. function partText(p) {
  411. if (typeof p === "string") return p;
  412. if (p instanceof Blob) return p._s;
  413. if (p instanceof ArrayBuffer || ArrayBuffer.isView(p))
  414. return unutf8(bytesOf(p));
  415. return String(p);
  416. }
  417. class Blob {
  418. constructor(parts, opts) {
  419. this._s = (parts || []).map(partText).join("");
  420. this.type = (opts && opts.type) || "";
  421. }
  422. get size() { return utf8(this._s).length; }
  423. text() { return Promise.resolve(this._s); }
  424. arrayBuffer() { return Promise.resolve(utf8(this._s).buffer); }
  425. slice(a, b, t) { return new Blob([this._s.slice(a, b)], { type: t }); }
  426. }
  427. class File extends Blob {
  428. constructor(parts, name, opts) {
  429. super(parts, opts);
  430. this.name = String(name);
  431. this.lastModified = (opts && opts.lastModified) || Date.now();
  432. }
  433. }
  434. def("Blob", Blob);
  435. def("File", File);
  436. class FormData {
  437. constructor() { this._l = []; }
  438. append(k, v) { this._l.push([String(k), v]); }
  439. set(k, v) { this.delete(k); this.append(k, v); }
  440. get(k) {
  441. for (var p of this._l) if (p[0] === k) return p[1];
  442. return null;
  443. }
  444. getAll(k) {
  445. return this._l.filter(function (p) { return p[0] === k; })
  446. .map(function (p) { return p[1]; });
  447. }
  448. has(k) { return this.get(k) !== null; }
  449. delete(k) { this._l = this._l.filter(function (p) { return p[0] !== k; }); }
  450. forEach(f, t) { for (var p of this._l) f.call(t, p[1], p[0], this); }
  451. entries() { return this._l.map(function (p) { return [p[0], p[1]]; })[Symbol.iterator](); }
  452. keys() { return this._l.map(function (p) { return p[0]; })[Symbol.iterator](); }
  453. values() { return this._l.map(function (p) { return p[1]; })[Symbol.iterator](); }
  454. [Symbol.iterator]() { return this.entries(); }
  455. }
  456. def("FormData", FormData);
  457. class AbortSignal {
  458. constructor() {
  459. this.aborted = false;
  460. this.reason = undefined;
  461. this.onabort = null;
  462. this._l = [];
  463. }
  464. addEventListener(t, f) { if (t === "abort") this._l.push(f); }
  465. removeEventListener(t, f) { this._l = this._l.filter(function (x) { return x !== f; }); }
  466. throwIfAborted() { if (this.aborted) throw this.reason; }
  467. static abort(r) { var c = new AbortController(); c.abort(r); return c.signal; }
  468. static timeout(ms) {
  469. var c = new AbortController();
  470. setTimeout(function () {
  471. c.abort(new DOMException("signal timed out", "TimeoutError"));
  472. }, ms);
  473. return c.signal;
  474. }
  475. }
  476. class AbortController {
  477. constructor() { this.signal = new AbortSignal(); }
  478. abort(r) {
  479. var s = this.signal, ev;
  480. if (s.aborted) return;
  481. s.aborted = true;
  482. s.reason = r === undefined ?
  483. new DOMException("signal is aborted without reason",
  484. "AbortError") : r;
  485. ev = { type: "abort", target: s };
  486. if (typeof s.onabort === "function") s.onabort(ev);
  487. s._l.forEach(function (f) { f(ev); });
  488. }
  489. }
  490. def("AbortSignal", AbortSignal);
  491. def("AbortController", AbortController);
  492. class Request {
  493. constructor(input, init) {
  494. init = init || {};
  495. if (input instanceof Request) {
  496. this.url = input.url;
  497. this.method = input.method;
  498. this.headers = new Headers(input.headers);
  499. this.body = input.body;
  500. this.signal = input.signal;
  501. } else {
  502. this.url = new URL(String(input), g.location.href).href;
  503. this.method = "GET";
  504. this.headers = new Headers();
  505. this.body = null;
  506. this.signal = null;
  507. }
  508. if (init.method) this.method = String(init.method).toUpperCase();
  509. if (init.headers) this.headers = new Headers(init.headers);
  510. if (init.body !== undefined) this.body = init.body;
  511. if (init.signal) this.signal = init.signal;
  512. this.credentials = init.credentials || "same-origin";
  513. this.mode = init.mode || "cors";
  514. }
  515. clone() { return new Request(this); }
  516. }
  517. def("Request", Request);
  518. class Response {
  519. constructor(body, init) {
  520. init = init || {};
  521. this._b = body == null ? "" : partText(body);
  522. this.status = init.status === undefined ? 200 : init.status;
  523. this.statusText = init.statusText || "";
  524. this.headers = init.headers instanceof Headers ? init.headers :
  525. new Headers(init.headers);
  526. this.ok = this.status >= 200 && this.status < 300;
  527. this.url = init.url || "";
  528. this.redirected = !!init.redirected;
  529. this.type = "basic";
  530. this.bodyUsed = false;
  531. this.body = null;
  532. }
  533. text() { this.bodyUsed = true; return Promise.resolve(this._b); }
  534. json() {
  535. this.bodyUsed = true;
  536. try { return Promise.resolve(JSON.parse(this._b)); }
  537. catch (e) { return Promise.reject(e); }
  538. }
  539. blob() {
  540. this.bodyUsed = true;
  541. return Promise.resolve(new Blob([this._b],
  542. { type: this.headers.get("content-type") || "" }));
  543. }
  544. arrayBuffer() { this.bodyUsed = true; return Promise.resolve(utf8(this._b).buffer); }
  545. formData() { return Promise.reject(new TypeError("formData() is not supported")); }
  546. clone() {
  547. return new Response(this._b, { status: this.status,
  548. statusText: this.statusText, url: this.url,
  549. headers: new Headers(this.headers) });
  550. }
  551. static json(data, init) {
  552. var h = new Headers(init && init.headers);
  553. h.set("content-type", "application/json");
  554. return new Response(JSON.stringify(data),
  555. Object.assign({}, init, { headers: h }));
  556. }
  557. static error() { return new Response(null, { status: 0 }); }
  558. static redirect(url, status) {
  559. return new Response(null, { status: status || 302,
  560. headers: { location: String(url) } });
  561. }
  562. }
  563. def("Response", Response);
  564. var STATUS_TEXT = { 200: "OK", 201: "Created", 204: "No Content",
  565. 301: "Moved Permanently", 302: "Found", 303: "See Other",
  566. 304: "Not Modified", 400: "Bad Request", 401: "Unauthorized",
  567. 403: "Forbidden", 404: "Not Found", 409: "Conflict", 410: "Gone",
  568. 500: "Internal Server Error", 502: "Bad Gateway",
  569. 503: "Service Unavailable" };
  570. /* One synchronous request through the browser's fetch helpers. */
  571. function send(method, url, headers, body) {
  572. var ct = headers.get("content-type");
  573. if (body instanceof URLSearchParams) {
  574. if (!ct) ct = "application/x-www-form-urlencoded;charset=UTF-8";
  575. body = body.toString();
  576. } else if (body instanceof FormData) {
  577. var sp = new URLSearchParams();
  578. body.forEach(function (v, k) {
  579. sp.append(k, typeof v === "string" ? v : "");
  580. });
  581. body = sp.toString();
  582. ct = "application/x-www-form-urlencoded;charset=UTF-8";
  583. } else if (body instanceof Blob) {
  584. if (!ct) ct = body.type;
  585. body = body._s;
  586. } else if (body != null && typeof body !== "string") {
  587. body = partText(body);
  588. } else if (typeof body === "string" && !ct) {
  589. ct = "text/plain;charset=UTF-8";
  590. }
  591. if (method === "GET" || method === "HEAD") body = null;
  592. var r = http(method, url, ct || "", body == null ? "" : body);
  593. var h = new Headers();
  594. if (r[1]) h.set("content-type", r[1]);
  595. return { status: r[0], headers: h, url: r[2] || url, text: r[3] };
  596. }
  597. def("fetch", function (input, init) {
  598. return new Promise(function (res, rej) {
  599. var req, out;
  600. try {
  601. req = new Request(input, init);
  602. } catch (e) {
  603. rej(e);
  604. return;
  605. }
  606. if (req.signal && req.signal.aborted) {
  607. rej(req.signal.reason);
  608. return;
  609. }
  610. try {
  611. out = send(req.method, req.url, req.headers, req.body);
  612. } catch (e) {
  613. rej(new TypeError("Failed to fetch"));
  614. return;
  615. }
  616. res(new Response(out.text, { status: out.status,
  617. statusText: STATUS_TEXT[out.status] || "",
  618. headers: out.headers, url: out.url,
  619. redirected: out.url !== req.url }));
  620. });
  621. });
  622. /* XMLHttpRequest on the same synchronous path; events fire asynchronously
  623. * (from a timer) so the caller can finish wiring its handlers. */
  624. class XMLHttpRequest {
  625. constructor() {
  626. this.readyState = 0;
  627. this.status = 0;
  628. this.statusText = "";
  629. this.responseText = "";
  630. this.response = "";
  631. this.responseType = "";
  632. this.responseURL = "";
  633. this.timeout = 0;
  634. this.withCredentials = false;
  635. this._h = new Headers();
  636. this._rh = new Headers();
  637. this._l = {};
  638. this.upload = { addEventListener: function () {} };
  639. }
  640. open(method, url) {
  641. this._m = String(method).toUpperCase();
  642. this._u = new URL(String(url), g.location.href).href;
  643. this.readyState = 1;
  644. }
  645. setRequestHeader(k, v) { this._h.append(k, v); }
  646. getResponseHeader(k) { return this._rh.get(k); }
  647. getAllResponseHeaders() {
  648. var s = "";
  649. this._rh.forEach(function (v, k) { s += k + ": " + v + "\r\n"; });
  650. return s;
  651. }
  652. overrideMimeType() {}
  653. addEventListener(t, f) { (this._l[t] = this._l[t] || []).push(f); }
  654. removeEventListener(t, f) {
  655. if (this._l[t]) this._l[t] = this._l[t].filter(function (x) { return x !== f; });
  656. }
  657. _fire(t) {
  658. var ev = { type: t, target: this, currentTarget: this,
  659. lengthComputable: false, loaded: 0, total: 0 };
  660. if (typeof this["on" + t] === "function") this["on" + t](ev);
  661. (this._l[t] || []).slice().forEach((f) => f.call(this, ev));
  662. }
  663. abort() { this._aborted = true; }
  664. send(body) {
  665. var self = this, out, err = false;
  666. try {
  667. out = send(this._m, this._u, this._h, body);
  668. } catch (e) {
  669. /* Like a browser's console network error: the page
  670. * only sees status 0, so say why. */
  671. con.error("XMLHttpRequest " + this._m + " " + this._u +
  672. ": " + (e && e.message));
  673. err = true;
  674. }
  675. setTimeout(function () {
  676. if (self._aborted) return;
  677. if (err) {
  678. self.readyState = 4;
  679. self._fire("readystatechange");
  680. self._fire("error");
  681. self._fire("loadend");
  682. return;
  683. }
  684. self.status = out.status;
  685. self.statusText = STATUS_TEXT[out.status] || "";
  686. self._rh = out.headers;
  687. self.responseURL = out.url;
  688. self.responseText = out.text;
  689. if (self.responseType === "json") {
  690. try { self.response = JSON.parse(out.text); }
  691. catch (e) { self.response = null; }
  692. } else {
  693. self.response = out.text;
  694. }
  695. self.readyState = 4;
  696. self._fire("readystatechange");
  697. self._fire("load");
  698. self._fire("loadend");
  699. }, 0);
  700. }
  701. }
  702. XMLHttpRequest.UNSENT = 0;
  703. XMLHttpRequest.OPENED = 1;
  704. XMLHttpRequest.HEADERS_RECEIVED = 2;
  705. XMLHttpRequest.LOADING = 3;
  706. XMLHttpRequest.DONE = 4;
  707. def("XMLHttpRequest", XMLHttpRequest);
  708. /* ---- Web Storage, persisted by the host per origin ---- */
  709. function makeStorage(kind) {
  710. var data = {};
  711. try {
  712. var t = storage(kind);
  713. if (t) data = JSON.parse(t) || {};
  714. } catch (e) {
  715. data = {};
  716. }
  717. function save() { storage(kind, JSON.stringify(data)); }
  718. var api = {
  719. getItem: function (k) {
  720. k = String(k);
  721. return hasOwn.call(data, k) ? data[k] : null;
  722. },
  723. setItem: function (k, v) { data[String(k)] = String(v); save(); },
  724. removeItem: function (k) { delete data[String(k)]; save(); },
  725. clear: function () { data = {}; save(); },
  726. key: function (i) {
  727. var k = Object.keys(data);
  728. return i < k.length ? k[i] : null;
  729. }
  730. };
  731. return new Proxy({}, {
  732. get: function (t, k) {
  733. if (typeof k === "symbol") return undefined;
  734. if (k === "length") return Object.keys(data).length;
  735. if (hasOwn.call(api, k)) return api[k];
  736. return hasOwn.call(data, k) ? data[k] : undefined;
  737. },
  738. set: function (t, k, v) {
  739. if (typeof k === "symbol") return true;
  740. data[k] = String(v);
  741. save();
  742. return true;
  743. },
  744. has: function (t, k) {
  745. return typeof k === "string" &&
  746. (k === "length" || hasOwn.call(api, k) || hasOwn.call(data, k));
  747. },
  748. deleteProperty: function (t, k) {
  749. if (typeof k === "string" && hasOwn.call(data, k)) {
  750. delete data[k];
  751. save();
  752. }
  753. return true;
  754. },
  755. ownKeys: function () { return Object.keys(data); },
  756. getOwnPropertyDescriptor: function (t, k) {
  757. if (typeof k === "string" && hasOwn.call(data, k))
  758. return { value: data[k], writable: true,
  759. enumerable: true, configurable: true };
  760. return undefined;
  761. }
  762. });
  763. }
  764. def("localStorage", makeStorage(0));
  765. def("sessionStorage", makeStorage(1));
  766. /* ---- crypto ---- */
  767. var K256 = [
  768. 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
  769. 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  770. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
  771. 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  772. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
  773. 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  774. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
  775. 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  776. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
  777. 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  778. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  779. function sha256(msg) {
  780. var h = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
  781. 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
  782. var len = msg.length, n = ((len + 9 + 63) >> 6) << 6;
  783. var b = new Uint8Array(n), w = new Array(64), i, j;
  784. b.set(msg);
  785. b[len] = 0x80;
  786. b[n - 4] = (len * 8) >>> 24;
  787. b[n - 3] = (len * 8) >>> 16 & 255;
  788. b[n - 2] = (len * 8) >>> 8 & 255;
  789. b[n - 1] = (len * 8) & 255;
  790. b[n - 5] = Math.floor(len / 0x20000000) & 255;
  791. function rotr(x, r) { return (x >>> r) | (x << (32 - r)); }
  792. for (i = 0; i < n; i += 64) {
  793. for (j = 0; j < 16; j++)
  794. w[j] = (b[i + 4 * j] << 24) | (b[i + 4 * j + 1] << 16) |
  795. (b[i + 4 * j + 2] << 8) | b[i + 4 * j + 3];
  796. for (j = 16; j < 64; j++) {
  797. var s0 = rotr(w[j - 15], 7) ^ rotr(w[j - 15], 18) ^ (w[j - 15] >>> 3);
  798. var s1 = rotr(w[j - 2], 17) ^ rotr(w[j - 2], 19) ^ (w[j - 2] >>> 10);
  799. w[j] = (w[j - 16] + s0 + w[j - 7] + s1) | 0;
  800. }
  801. var a = h[0], bb = h[1], c = h[2], d = h[3], e = h[4], f = h[5],
  802. gg = h[6], hh = h[7];
  803. for (j = 0; j < 64; j++) {
  804. var S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
  805. var ch = (e & f) ^ (~e & gg);
  806. var t1 = (hh + S1 + ch + K256[j] + w[j]) | 0;
  807. var S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
  808. var mj = (a & bb) ^ (a & c) ^ (bb & c);
  809. var t2 = (S0 + mj) | 0;
  810. hh = gg; gg = f; f = e; e = (d + t1) | 0;
  811. d = c; c = bb; bb = a; a = (t1 + t2) | 0;
  812. }
  813. h[0] = (h[0] + a) | 0; h[1] = (h[1] + bb) | 0;
  814. h[2] = (h[2] + c) | 0; h[3] = (h[3] + d) | 0;
  815. h[4] = (h[4] + e) | 0; h[5] = (h[5] + f) | 0;
  816. h[6] = (h[6] + gg) | 0; h[7] = (h[7] + hh) | 0;
  817. }
  818. var out = new Uint8Array(32);
  819. for (i = 0; i < 8; i++) {
  820. out[4 * i] = h[i] >>> 24;
  821. out[4 * i + 1] = h[i] >>> 16 & 255;
  822. out[4 * i + 2] = h[i] >>> 8 & 255;
  823. out[4 * i + 3] = h[i] & 255;
  824. }
  825. return out;
  826. }
  827. /* The entropy is weak (Math.random seeded from the clock, stirred with the
  828. * millisecond timer), like the TLS DRBG; fine for PKCE nonces on a hobby
  829. * OS, not for long-term keys. */
  830. var rngState = sha256(utf8(String(Date.now()) + ":" + Math.random() + ":" +
  831. g.performance.now()));
  832. var rngPos = 0;
  833. function randomByte() {
  834. if (rngPos >= 32) {
  835. var seed = new Uint8Array(40);
  836. seed.set(rngState);
  837. var t = g.performance.now() * 1000 + Math.random() * 4294967296;
  838. for (var i = 0; i < 8; i++)
  839. seed[32 + i] = Math.floor(t / Math.pow(256, i)) & 255;
  840. rngState = sha256(seed);
  841. rngPos = 0;
  842. }
  843. return rngState[rngPos++];
  844. }
  845. var subtle = {
  846. digest: function (alg, data) {
  847. var name = typeof alg === "string" ? alg : alg && alg.name;
  848. if (String(name).toUpperCase().replace("-", "") !== "SHA256")
  849. return Promise.reject(new DOMException(
  850. "Unsupported algorithm " + name, "NotSupportedError"));
  851. return Promise.resolve(sha256(bytesOf(data)).buffer);
  852. }
  853. };
  854. def("crypto", {
  855. subtle: subtle,
  856. getRandomValues: function (a) {
  857. var u = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
  858. for (var i = 0; i < u.length; i++) u[i] = randomByte();
  859. return a;
  860. },
  861. randomUUID: function () {
  862. var b = new Uint8Array(16), i, s = "";
  863. this.getRandomValues(b);
  864. b[6] = (b[6] & 0x0f) | 0x40;
  865. b[8] = (b[8] & 0x3f) | 0x80;
  866. for (i = 0; i < 16; i++) {
  867. s += (b[i] + 0x100).toString(16).slice(1);
  868. if (i === 3 || i === 5 || i === 7 || i === 9) s += "-";
  869. }
  870. return s;
  871. }
  872. });
  873. /* ---- observers (no layout notifications yet: inert) ---- */
  874. class MutationObserver {
  875. constructor(cb) { this._cb = cb; }
  876. observe() {}
  877. disconnect() {}
  878. takeRecords() { return []; }
  879. }
  880. class ResizeObserver {
  881. constructor(cb) { this._cb = cb; }
  882. observe() {}
  883. unobserve() {}
  884. disconnect() {}
  885. }
  886. /* Without scroll geometry every observed target is reported visible, once
  887. * per observe(): lazy loaders and "becomes visible" components (heise's
  888. * a-img) then load their content. Capped per page against infinite-scroll
  889. * sentinels that re-observe forever. */
  890. var ioBudget = 400;
  891. /* One timer drains every deferred callback: a page with hundreds of lazy
  892. * images would otherwise overflow the browser's timer table. */
  893. var laterQ = [], laterArmed = false;
  894. function later(f) {
  895. laterQ.push(f);
  896. if (laterArmed) return;
  897. laterArmed = true;
  898. setTimeout(function () {
  899. var q = laterQ, i;
  900. laterQ = [];
  901. laterArmed = false;
  902. for (i = 0; i < q.length; i++)
  903. try { q[i](); } catch (e) { con.error(e); }
  904. }, 0);
  905. }
  906. class IntersectionObserver {
  907. constructor(cb, opts) {
  908. this._cb = cb;
  909. this._t = [];
  910. this.root = (opts && opts.root) || null;
  911. this.rootMargin = (opts && opts.rootMargin) || "0px";
  912. this.thresholds = [0];
  913. }
  914. observe(t) {
  915. var self = this;
  916. if (!t || this._t.indexOf(t) >= 0 || ioBudget <= 0) return;
  917. ioBudget--;
  918. this._t.push(t);
  919. later(function () {
  920. if (self._t.indexOf(t) < 0) return;
  921. var r = t.getBoundingClientRect();
  922. self._cb([{ target: t, isIntersecting: true,
  923. intersectionRatio: 1, boundingClientRect: r,
  924. intersectionRect: r, rootBounds: null,
  925. time: g.performance.now() }], self);
  926. });
  927. }
  928. unobserve(t) { this._t = this._t.filter(function (x) { return x !== t; }); }
  929. disconnect() { this._t = []; }
  930. takeRecords() { return []; }
  931. }
  932. def("MutationObserver", MutationObserver);
  933. def("ResizeObserver", ResizeObserver);
  934. def("IntersectionObserver", IntersectionObserver);
  935. /* Present with isIntersecting/intersectionRatio on the prototype so the
  936. * common IntersectionObserver polyfill (bundled by heise) keeps ours. */
  937. class IntersectionObserverEntry {
  938. constructor(init) { Object.assign(this, init); }
  939. get isIntersecting() { return !!this._i; }
  940. get intersectionRatio() { return this._r || 0; }
  941. }
  942. def("IntersectionObserverEntry", IntersectionObserverEntry);
  943. /* ---- DOM classes: instanceof works on the node wrappers ---- */
  944. function domClass(name, test) {
  945. var C = function () { throw new TypeError("Illegal constructor"); };
  946. Object.defineProperty(C, "name", { value: name });
  947. Object.defineProperty(C, Symbol.hasInstance, {
  948. value: function (o) {
  949. return o != null && typeof o === "object" &&
  950. typeof o.nodeType === "number" && test(o);
  951. }
  952. });
  953. C.prototype = nodeproto;
  954. def(name, C);
  955. return C;
  956. }
  957. function tag(t) { return function (o) { return o.nodeType === 1 && o.tagName === t; }; }
  958. /* Real accessors and methods on the shared prototype for the members the
  959. * C hook answers. A wrapper's own lookup reaches the hook first, so these
  960. * only serve code that takes them from the prototype, like DOMPurify's
  961. * clobbering-safe `getOwnPropertyDescriptor(Node.prototype, "nodeName")
  962. * .get.call(node)`; without them it read every node as null and treated
  963. * the whole tree as detached. `busy` stops the recursion when the hook
  964. * does not know the name (or `this` is not a wrapper). */
  965. (function () {
  966. var busy = false;
  967. function own(name) {
  968. return Object.getOwnPropertyDescriptor(nodeproto, name);
  969. }
  970. ["nodeName", "nodeType", "parentNode", "nextSibling", "childNodes",
  971. "attributes"].forEach(function (name) {
  972. if (own(name)) return;
  973. Object.defineProperty(nodeproto, name, {
  974. configurable: true, enumerable: false,
  975. get: function () {
  976. if (busy) return undefined;
  977. busy = true;
  978. try { return this[name]; } finally { busy = false; }
  979. },
  980. set: function (v) {
  981. if (busy) return;
  982. busy = true;
  983. try { this[name] = v; } finally { busy = false; }
  984. }
  985. });
  986. });
  987. ["cloneNode", "remove", "removeAttributeNode"].forEach(function (name) {
  988. if (own(name)) return;
  989. Object.defineProperty(nodeproto, name, {
  990. configurable: true, enumerable: false, writable: true,
  991. value: function () {
  992. var f;
  993. if (busy) return undefined;
  994. busy = true;
  995. try { f = this[name]; } finally { busy = false; }
  996. if (typeof f !== "function" || f === nodeproto[name])
  997. return undefined;
  998. return f.apply(this, arguments);
  999. }
  1000. });
  1001. });
  1002. })();
  1003. domClass("EventTarget", function (o) { return true; });
  1004. domClass("Node", function (o) { return true; });
  1005. domClass("Element", function (o) { return o.nodeType === 1; });
  1006. domClass("HTMLElement", function (o) { return o.nodeType === 1; });
  1007. domClass("SVGElement", function (o) { return o.nodeType === 1 && o.namespaceURI === "http://www.w3.org/2000/svg"; });
  1008. domClass("CharacterData", function (o) { return o.nodeType === 3 || o.nodeType === 8; });
  1009. domClass("Text", function (o) { return o.nodeType === 3; });
  1010. domClass("Comment", function (o) { return o.nodeType === 8; });
  1011. domClass("DocumentFragment", function (o) { return o.nodeType === 11; });
  1012. domClass("Document", function (o) { return o.nodeType === 9; });
  1013. domClass("DocumentType", function (o) { return o.nodeType === 10; });
  1014. domClass("Attr", function (o) { return o.nodeType === 2; });
  1015. domClass("HTMLDocument", function (o) { return o.nodeType === 9; });
  1016. domClass("HTMLInputElement", tag("INPUT"));
  1017. domClass("HTMLTextAreaElement", tag("TEXTAREA"));
  1018. domClass("HTMLSelectElement", tag("SELECT"));
  1019. domClass("HTMLOptionElement", tag("OPTION"));
  1020. domClass("HTMLButtonElement", tag("BUTTON"));
  1021. domClass("HTMLFormElement", tag("FORM"));
  1022. domClass("HTMLAnchorElement", tag("A"));
  1023. domClass("HTMLImageElement", tag("IMG"));
  1024. domClass("HTMLTemplateElement", tag("TEMPLATE"));
  1025. domClass("HTMLIFrameElement", tag("IFRAME"));
  1026. domClass("HTMLLinkElement", tag("LINK"));
  1027. domClass("HTMLScriptElement", tag("SCRIPT"));
  1028. domClass("HTMLStyleElement", tag("STYLE"));
  1029. domClass("HTMLCanvasElement", tag("CANVAS"));
  1030. domClass("HTMLMediaElement", function (o) {
  1031. return o.nodeType === 1 && (o.tagName === "VIDEO" || o.tagName === "AUDIO");
  1032. });
  1033. domClass("HTMLVideoElement", tag("VIDEO"));
  1034. domClass("HTMLAudioElement", tag("AUDIO"));
  1035. /* <video>/<audio> are placeholders: the C hook hands these methods to
  1036. * media elements only (so `"play" in div` stays false). play() resolves
  1037. * without playing: pages call it without a catch on scroll, and a
  1038. * rejection would only add an "Uncaught" line per element. */
  1039. /* <canvas> has no drawing backend: getContext() answers null for every
  1040. * context type, like a browser with 2D/WebGL disabled, so libraries take
  1041. * their "no canvas/WebGL" path (MapLibre reports "Failed to initialize
  1042. * WebGL") instead of calling an undefined method. */
  1043. def("__nb_canvas", {
  1044. getContext: function () { return null; },
  1045. toDataURL: function () { return "data:,"; },
  1046. toBlob: function (cb) { if (typeof cb === "function") setTimeout(function () { cb(null); }, 0); },
  1047. transferControlToOffscreen: function () { throw new DOMException("not supported", "NotSupportedError"); }
  1048. });
  1049. def("__nb_media", {
  1050. play: function () { return Promise.resolve(); },
  1051. pause: function () {},
  1052. load: function () {},
  1053. canPlayType: function () { return ""; }
  1054. });
  1055. def("Window", function Window() {});
  1056. /* ---- Custom Elements ----
  1057. * A registered class adopts an existing element: HTMLElement, used as the
  1058. * base constructor, returns the element being upgraded (or a fresh one for
  1059. * `new MyElement()`) with its prototype switched to the subclass, the way
  1060. * the custom-elements polyfills do it. New elements are upgraded when
  1061. * created by script and by a scan after DOM changes (js_browser.c calls
  1062. * __nb_ce_scan from its tick); connectedCallback runs once the element is
  1063. * in the document. attributeChangedCallback fires for the observed
  1064. * attributes present at upgrade, not for later changes. */
  1065. var ceRegistry = new Map(), ceNames = new Map(), ceWaiters = new Map();
  1066. var cePending = [];
  1067. var createEl = g.document.createElement;
  1068. function HTMLElementCtor() {
  1069. var el = cePending.length ? cePending[cePending.length - 1] : null;
  1070. if (!el) {
  1071. var name = ceNames.get(new.target);
  1072. if (!name) throw new TypeError("Illegal constructor");
  1073. el = createEl.call(g.document, name);
  1074. }
  1075. Object.setPrototypeOf(el, new.target.prototype);
  1076. return el;
  1077. }
  1078. HTMLElementCtor.prototype = nodeproto;
  1079. Object.defineProperty(HTMLElementCtor, "name", { value: "HTMLElement" });
  1080. Object.defineProperty(HTMLElementCtor, Symbol.hasInstance, {
  1081. value: function (o) {
  1082. if (this !== HTMLElementCtor)
  1083. return Function.prototype[Symbol.hasInstance].call(this, o);
  1084. return o != null && typeof o === "object" && o.nodeType === 1;
  1085. }
  1086. });
  1087. def("HTMLElement", HTMLElementCtor);
  1088. function ceUpgrade(el) {
  1089. var C, obs, i;
  1090. if (!el || el.nodeType !== 1 || el.__nbce) return;
  1091. C = ceRegistry.get(el.localName);
  1092. if (!C) return;
  1093. el.__nbce = 1;
  1094. cePending.push(el);
  1095. try { new C(); } catch (e) { con.error(e); }
  1096. cePending.pop();
  1097. obs = C.observedAttributes;
  1098. if (obs && typeof el.attributeChangedCallback === "function")
  1099. for (i = 0; i < obs.length; i++)
  1100. if (el.hasAttribute(obs[i]))
  1101. try { el.attributeChangedCallback(obs[i], null, el.getAttribute(obs[i])); }
  1102. catch (e) { con.error(e); }
  1103. ceConnect(el);
  1104. }
  1105. function ceConnect(el) {
  1106. if (el.__nbceConn || !el.isConnected) return;
  1107. el.__nbceConn = 1;
  1108. if (typeof el.connectedCallback === "function") {
  1109. try {
  1110. var r = el.connectedCallback();
  1111. if (r && typeof r.then === "function")
  1112. r.then(null, function (e) { con.error(e); });
  1113. } catch (e) { con.error(e); }
  1114. }
  1115. }
  1116. function ceScan() {
  1117. ceRegistry.forEach(function (C, name) {
  1118. var list = g.document.querySelectorAll(name), i;
  1119. for (i = 0; i < list.length; i++) {
  1120. if (!list[i].__nbce) ceUpgrade(list[i]);
  1121. else ceConnect(list[i]);
  1122. }
  1123. });
  1124. }
  1125. def("__nb_ce_scan", function () { if (ceRegistry.size) ceScan(); });
  1126. def("customElements", {
  1127. define: function (name, C) {
  1128. name = String(name).toLowerCase();
  1129. if (ceRegistry.has(name))
  1130. throw new DOMException("'" + name + "' is already defined", "NotSupportedError");
  1131. ceRegistry.set(name, C);
  1132. ceNames.set(C, name);
  1133. ceScan();
  1134. var w = ceWaiters.get(name);
  1135. if (w) { w.forEach(function (f) { f(C); }); ceWaiters.delete(name); }
  1136. },
  1137. get: function (name) { return ceRegistry.get(String(name).toLowerCase()); },
  1138. getName: function (C) { return ceNames.get(C) || null; },
  1139. whenDefined: function (name) {
  1140. name = String(name).toLowerCase();
  1141. if (ceRegistry.has(name)) return Promise.resolve(ceRegistry.get(name));
  1142. return new Promise(function (res) {
  1143. if (!ceWaiters.has(name)) ceWaiters.set(name, []);
  1144. ceWaiters.get(name).push(res);
  1145. });
  1146. },
  1147. upgrade: function (root) {
  1148. ceUpgrade(root);
  1149. if (root && root.querySelectorAll) ceScan();
  1150. }
  1151. });
  1152. g.document.createElement = function (name, opts) {
  1153. var el = createEl.call(g.document, name);
  1154. var n = String(name).toLowerCase();
  1155. if (ceRegistry.has(n)) ceUpgrade(el);
  1156. if (n === "img") imgLoadShim(el);
  1157. return el;
  1158. };
  1159. /* Document collections (live: recomputed on every access). */
  1160. [["scripts", "script"], ["images", "img"], ["forms", "form"],
  1161. ["embeds", "embed"], ["links", "a[href],area[href]"]].forEach(function (p) {
  1162. Object.defineProperty(g.document, p[0], {
  1163. configurable: true,
  1164. get: function () {
  1165. return p[1].indexOf("[") >= 0 ?
  1166. g.document.querySelectorAll(p[1]) :
  1167. g.document.getElementsByTagName(p[1]);
  1168. }
  1169. });
  1170. });
  1171. /* Script-created images never really load in the page's DOM; fire "load"
  1172. * once a src is set so preload-then-swap code (load a detached <img>, then
  1173. * copy its URL) proceeds. The visible <img> is loaded by the browser. */
  1174. function imgLoadShim(el) {
  1175. later(function () {
  1176. if (el.getAttribute("src"))
  1177. el.dispatchEvent(new Event("load"));
  1178. });
  1179. }
  1180. def("Image", function Image(w, h) {
  1181. var el = g.document.createElement("img");
  1182. if (w !== undefined) el.setAttribute("width", String(w));
  1183. if (h !== undefined) el.setAttribute("height", String(h));
  1184. return el;
  1185. });
  1186. def("ShadowRoot", function ShadowRoot() {});
  1187. var NodeConst = g.Node;
  1188. [["ELEMENT_NODE", 1], ["ATTRIBUTE_NODE", 2], ["TEXT_NODE", 3],
  1189. ["CDATA_SECTION_NODE", 4], ["COMMENT_NODE", 8], ["DOCUMENT_NODE", 9],
  1190. ["DOCUMENT_TYPE_NODE", 10], ["DOCUMENT_FRAGMENT_NODE", 11]]
  1191. .forEach(function (p) { NodeConst[p[0]] = p[1]; });
  1192. /* Methods every node wrapper inherits (the C has-hook answers the rest). */
  1193. var doc = g.document;
  1194. /* <template>.content: the parser keeps a template's children in the tree
  1195. * (hidden); the first access moves them into a fragment, which Alpine's
  1196. * x-for/x-if/x-teleport clone. */
  1197. Object.defineProperty(nodeproto, "content", { configurable: true,
  1198. get: function () {
  1199. if (this.nodeType !== 1 || this.tagName !== "TEMPLATE")
  1200. return undefined;
  1201. if (!this.__nb_tc) {
  1202. var f = doc.createDocumentFragment();
  1203. while (this.firstChild)
  1204. f.appendChild(this.firstChild);
  1205. this.__nb_tc = f;
  1206. }
  1207. return this.__nb_tc;
  1208. } });
  1209. function toNode(n) {
  1210. return typeof n === "object" && n !== null ? n : doc.createTextNode(String(n));
  1211. }
  1212. /* Constraint validation (no UI: reportValidity only answers): required,
  1213. * min/maxlength, pattern, email/url syntax, number min/max and
  1214. * setCustomValidity(). A form is valid when all its controls are. */
  1215. function validity(e) {
  1216. var t = String(e.type || "").toLowerCase(), v = String(e.value || ""),
  1217. a = function (n) { return e.getAttribute(n); }, r = {}, p;
  1218. if (e.disabled || /^(hidden|submit|button|reset|image)$/.test(t)) {
  1219. r.valid = true;
  1220. return r;
  1221. }
  1222. r.customError = !!e.__nb_cv;
  1223. r.valueMissing = e.hasAttribute("required") &&
  1224. (/^(checkbox|radio)$/.test(t) ? !e.checked : v === "");
  1225. if (v) {
  1226. r.tooShort = v.length < +(a("minlength") || 0);
  1227. r.tooLong = a("maxlength") !== null && v.length > +a("maxlength");
  1228. p = a("pattern");
  1229. try { r.patternMismatch = p !== null && !new RegExp("^(?:" + p + ")$").test(v); } catch (x) {}
  1230. r.typeMismatch = t === "email" ? !/^[^\s@]+@[^\s@]+$/.test(v) :
  1231. t === "url" && !/^[a-z][\w+.-]*:/i.test(v);
  1232. r.rangeUnderflow = t === "number" && a("min") !== null && +v < +a("min");
  1233. r.rangeOverflow = t === "number" && a("max") !== null && +v > +a("max");
  1234. }
  1235. r.valid = !Object.keys(r).some(function (k) { return r[k]; });
  1236. return r;
  1237. }
  1238. function checkValidity() {
  1239. var l = /^form$/i.test(this.tagName) ?
  1240. this.querySelectorAll("input,select,textarea") : [this], i;
  1241. for (i = 0; i < l.length; i++)
  1242. if (!validity(l[i]).valid) return false;
  1243. return true;
  1244. }
  1245. Object.defineProperty(nodeproto, "validity", { configurable: true,
  1246. get: function () { return validity(this); } });
  1247. Object.assign(nodeproto, {
  1248. checkValidity: checkValidity,
  1249. reportValidity: checkValidity,
  1250. setCustomValidity: function (m) { this.__nb_cv = String(m); },
  1251. setAttributeNS: function (ns, n, v) {
  1252. this.setAttribute(String(n).replace(/^[^:]*:/, ""), v);
  1253. },
  1254. getAttributeNS: function (ns, n) { return this.getAttribute(n); },
  1255. removeAttributeNS: function (ns, n) { this.removeAttribute(n); },
  1256. hasAttributeNS: function (ns, n) { return this.hasAttribute(n); },
  1257. toggleAttribute: function (n, force) {
  1258. var on = force === undefined ? !this.hasAttribute(n) : !!force;
  1259. if (on) this.setAttribute(n, "");
  1260. else this.removeAttribute(n);
  1261. return on;
  1262. },
  1263. getAttributeNames: function () {
  1264. var a = this.attributes, out = [], i;
  1265. for (i = 0; a && i < a.length; i++) out.push(a[i].name);
  1266. return out;
  1267. },
  1268. closest: function (sel) {
  1269. var e = this;
  1270. while (e && e.nodeType === 1) {
  1271. if (e.matches(sel)) return e;
  1272. e = e.parentNode;
  1273. }
  1274. return null;
  1275. },
  1276. append: function () {
  1277. for (var i = 0; i < arguments.length; i++)
  1278. this.appendChild(toNode(arguments[i]));
  1279. },
  1280. prepend: function () {
  1281. var first = this.firstChild;
  1282. for (var i = 0; i < arguments.length; i++)
  1283. this.insertBefore(toNode(arguments[i]), first);
  1284. },
  1285. before: function () {
  1286. var p = this.parentNode;
  1287. if (!p) return;
  1288. for (var i = 0; i < arguments.length; i++)
  1289. p.insertBefore(toNode(arguments[i]), this);
  1290. },
  1291. after: function () {
  1292. var p = this.parentNode, next = this.nextSibling;
  1293. if (!p) return;
  1294. for (var i = 0; i < arguments.length; i++)
  1295. p.insertBefore(toNode(arguments[i]), next);
  1296. },
  1297. replaceWith: function () {
  1298. var p = this.parentNode;
  1299. if (!p) return;
  1300. this.before.apply(this, arguments);
  1301. p.removeChild(this);
  1302. },
  1303. replaceChildren: function () {
  1304. while (this.firstChild) this.removeChild(this.firstChild);
  1305. this.append.apply(this, arguments);
  1306. },
  1307. insertAdjacentElement: function (pos, el) {
  1308. pos = String(pos).toLowerCase();
  1309. if (pos === "beforebegin") this.before(el);
  1310. else if (pos === "afterbegin") this.prepend(el);
  1311. else if (pos === "beforeend") this.appendChild(el);
  1312. else if (pos === "afterend") this.after(el);
  1313. return el;
  1314. },
  1315. insertAdjacentText: function (pos, text) {
  1316. this.insertAdjacentElement(pos, doc.createTextNode(String(text)));
  1317. },
  1318. insertAdjacentHTML: function (pos, html) {
  1319. var tmp = doc.createElement("div"), nodes = [], c;
  1320. tmp.innerHTML = html;
  1321. for (c = tmp.firstChild; c; c = c.nextSibling) nodes.push(c);
  1322. pos = String(pos).toLowerCase();
  1323. if (pos === "afterbegin") nodes.reverse();
  1324. for (c of nodes) {
  1325. tmp.removeChild(c);
  1326. this.insertAdjacentElement(pos, c);
  1327. }
  1328. },
  1329. getRootNode: function () { return doc; },
  1330. scrollIntoView: function () {},
  1331. scrollTo: function () {},
  1332. scrollBy: function () {},
  1333. animate: function () {
  1334. return { finished: Promise.resolve(), cancel: function () {},
  1335. play: function () {}, pause: function () {},
  1336. onfinish: null };
  1337. },
  1338. attachShadow: function () { return this; },
  1339. compareDocumentPosition: function (other) {
  1340. if (this === other) return 0;
  1341. if (this.contains(other)) return 20;
  1342. if (other.contains && other.contains(this)) return 10;
  1343. return 4;
  1344. },
  1345. isSameNode: function (o) { return this === o; },
  1346. normalize: function () {}
  1347. });
  1348. /* ---- document extras ---- */
  1349. doc.createElementNS = function (ns, name) {
  1350. var el = doc.createElement(String(name).replace(/^[^:]*:/, ""));
  1351. if (ns === "http://www.w3.org/2000/svg")
  1352. el.setAttribute("xmlns", ns);
  1353. return el;
  1354. };
  1355. doc.createRange = function () {
  1356. return {
  1357. createContextualFragment: function (html) {
  1358. var tmp = doc.createElement("div"),
  1359. frag = doc.createDocumentFragment();
  1360. tmp.innerHTML = html;
  1361. while (tmp.firstChild) frag.appendChild(tmp.firstChild);
  1362. return frag;
  1363. },
  1364. selectNodeContents: function () {},
  1365. setStart: function () {}, setEnd: function () {},
  1366. getBoundingClientRect: function () {
  1367. return { x: 0, y: 0, top: 0, left: 0, right: 0, bottom: 0,
  1368. width: 0, height: 0 };
  1369. }
  1370. };
  1371. };
  1372. doc.createTreeWalker = undefined;
  1373. /* NodeIterator over a snapshot of the subtree in document order. A node
  1374. * removed from the root meanwhile is skipped, and the children a sanitizer
  1375. * hoists out of a removed element are still visited, which is what
  1376. * DOMPurify (the Cloudron dashboard's markdown) relies on. */
  1377. def("NodeFilter", {
  1378. FILTER_ACCEPT: 1, FILTER_REJECT: 2, FILTER_SKIP: 3,
  1379. SHOW_ALL: 0xFFFFFFFF, SHOW_ELEMENT: 0x1, SHOW_ATTRIBUTE: 0x2,
  1380. SHOW_TEXT: 0x4, SHOW_CDATA_SECTION: 0x8,
  1381. SHOW_PROCESSING_INSTRUCTION: 0x40, SHOW_COMMENT: 0x80,
  1382. SHOW_DOCUMENT: 0x100, SHOW_DOCUMENT_TYPE: 0x200,
  1383. SHOW_DOCUMENT_FRAGMENT: 0x400
  1384. });
  1385. doc.createNodeIterator = function (root, what, filter) {
  1386. var list = [], stack = [root], i = -1, n, c, kids;
  1387. what = what === undefined ? 0xFFFFFFFF : what >>> 0;
  1388. while (stack.length) {
  1389. n = stack.pop();
  1390. list.push(n);
  1391. kids = [];
  1392. for (c = n.firstChild; c; c = c.nextSibling) kids.push(c);
  1393. while (kids.length) stack.push(kids.pop());
  1394. }
  1395. function shown(x) {
  1396. var t = x.nodeType || 1, r;
  1397. if (t > 32 || !(what & (1 << (t - 1)))) return false;
  1398. if (!filter) return true;
  1399. r = typeof filter === "function" ? filter(x) : filter.acceptNode(x);
  1400. return r === 1;
  1401. }
  1402. function inside(x) { return x === root || root.contains(x); }
  1403. return {
  1404. root: root, whatToShow: what, filter: filter || null,
  1405. referenceNode: root, pointerBeforeReferenceNode: true,
  1406. nextNode: function () {
  1407. while (++i < list.length)
  1408. if (inside(list[i]) && shown(list[i]))
  1409. return (this.referenceNode = list[i]);
  1410. i = list.length;
  1411. return null;
  1412. },
  1413. previousNode: function () {
  1414. while (--i >= 0)
  1415. if (inside(list[i]) && shown(list[i]))
  1416. return (this.referenceNode = list[i]);
  1417. i = -1;
  1418. return null;
  1419. },
  1420. detach: function () {}
  1421. };
  1422. };
  1423. doc.hasFocus = function () { return true; };
  1424. doc.getElementsByName = function (n) {
  1425. return doc.querySelectorAll("[name=\"" + String(n).replace(/"/g, "\\\"") + "\"]");
  1426. };
  1427. doc.hidden = false;
  1428. doc.visibilityState = "visible";
  1429. doc.characterSet = "UTF-8";
  1430. doc.charset = "UTF-8";
  1431. doc.contentType = "text/html";
  1432. doc.referrer = "";
  1433. doc.dir = "";
  1434. /* CSS Font Loading API surface. Faces come from the stylesheets'
  1435. * @font-face rules, loaded before layout; a script-built FontFace resolves
  1436. * at once but is not rendered (the cascade resolves families at parse). */
  1437. g.FontFace = function (family, source, desc) {
  1438. this.family = String(family);
  1439. this.source = source;
  1440. desc = desc || {};
  1441. this.style = desc.style || "normal";
  1442. this.weight = String(desc.weight || "normal");
  1443. this.display = desc.display || "auto";
  1444. this.unicodeRange = desc.unicodeRange || "U+0-10FFFF";
  1445. this.status = "loaded";
  1446. this.loaded = Promise.resolve(this);
  1447. };
  1448. g.FontFace.prototype.load = function () { return this.loaded; };
  1449. (function () {
  1450. var faces = [];
  1451. var fonts = {
  1452. status: "loaded", ready: null, onloading: null,
  1453. onloadingdone: null, onloadingerror: null,
  1454. add: function (f) { if (faces.indexOf(f) < 0) faces.push(f); return fonts; },
  1455. delete: function (f) { var i = faces.indexOf(f); if (i < 0) return false; faces.splice(i, 1); return true; },
  1456. has: function (f) { return faces.indexOf(f) >= 0; },
  1457. clear: function () { faces.length = 0; },
  1458. forEach: function (cb, t) { faces.slice().forEach(function (f) { cb.call(t, f, f, fonts); }); },
  1459. values: function () { return faces.slice()[Symbol.iterator](); },
  1460. load: function () { return Promise.resolve([]); },
  1461. check: function () { return true; },
  1462. addEventListener: function () {},
  1463. removeEventListener: function () {}
  1464. };
  1465. fonts.ready = Promise.resolve(fonts);
  1466. fonts.keys = fonts.values;
  1467. fonts[Symbol.iterator] = fonts.values;
  1468. Object.defineProperty(fonts, "size", { get: function () { return faces.length; } });
  1469. doc.fonts = fonts;
  1470. })();
  1471. /* A separate inert document (jQuery's parseHTML context, DOMPurify): its
  1472. * nodes live in the page's node arena but are detached, so writing to its
  1473. * body never touches the page. Returning the page document here made
  1474. * jQuery's support probe replace the whole page body with two <form>s. */
  1475. function nbInertDocument(title) {
  1476. var html = doc.createElement("html"), head = doc.createElement("head");
  1477. var body = doc.createElement("body"), d;
  1478. html.appendChild(head);
  1479. html.appendChild(body);
  1480. if (title !== undefined) {
  1481. var t = doc.createElement("title");
  1482. t.textContent = String(title);
  1483. head.appendChild(t);
  1484. }
  1485. d = {
  1486. __nbInert: true,
  1487. nodeType: 9, nodeName: "#document", documentElement: html,
  1488. head: head, body: body, readyState: "complete",
  1489. compatMode: "CSS1Compat", characterSet: "UTF-8",
  1490. contentType: "text/html", defaultView: null, location: null,
  1491. cookie: "", URL: "about:blank", baseURI: doc.URL,
  1492. addEventListener: function () {},
  1493. removeEventListener: function () {},
  1494. querySelector: function (s) { return html.querySelector(s); },
  1495. querySelectorAll: function (s) { return html.querySelectorAll(s); },
  1496. getElementsByTagName: function (s) {
  1497. return html.getElementsByTagName(s);
  1498. },
  1499. getElementsByClassName: function (s) {
  1500. return html.getElementsByClassName(s);
  1501. },
  1502. getElementById: function (id) {
  1503. return html.querySelector("[id=\"" +
  1504. String(id).replace(/"/g, "\\\"") + "\"]");
  1505. }
  1506. };
  1507. ["createElement", "createTextNode", "createComment",
  1508. "createDocumentFragment", "createAttribute", "createEvent"].forEach(
  1509. function (m) {
  1510. d[m] = function () { return doc[m].apply(doc, arguments); };
  1511. });
  1512. d.createElementNS = function (ns, n) { return doc.createElement(n); };
  1513. d.implementation = doc.implementation;
  1514. Object.defineProperty(d, "title", { configurable: true,
  1515. get: function () {
  1516. var t = head.querySelector("title");
  1517. return t ? t.textContent : "";
  1518. } });
  1519. return d;
  1520. }
  1521. /* The page document's lookups called on an inert document
  1522. * (`document.getElementsByTagName.call(parsed, "body")`, as DOMPurify does)
  1523. * answer for that document: searching the page instead handed DOMPurify the
  1524. * real <body> to sanitize, and it emptied the page. */
  1525. ["getElementsByTagName", "getElementsByClassName", "querySelector",
  1526. "querySelectorAll", "getElementById"].forEach(function (m) {
  1527. var f = doc[m];
  1528. if (typeof f !== "function") return;
  1529. doc[m] = function () {
  1530. if (this && this !== doc && this.__nbInert)
  1531. return this[m].apply(this, arguments);
  1532. return f.apply(doc, arguments);
  1533. };
  1534. });
  1535. doc.implementation = {
  1536. hasFeature: function () { return true; },
  1537. createHTMLDocument: function (title) { return nbInertDocument(title); }
  1538. };
  1539. /* DOMParser on the same inert document: the markup goes through the
  1540. * innerHTML fragment parser. A whole document is split at its <head> and
  1541. * <body>, so the parsed body holds the body's children and not a nested
  1542. * copy of the <html>/<head>/<body> elements. */
  1543. if (!g.DOMParser) {
  1544. g.DOMParser = function DOMParser() {};
  1545. g.DOMParser.prototype.parseFromString = function (str) {
  1546. var d = nbInertDocument(), s = String(str), m;
  1547. s = s.replace(/<!doctype[^>]*>/i, "");
  1548. m = /<head(\s[^>]*)?>([\s\S]*?)<\/head>/i.exec(s);
  1549. if (m) {
  1550. d.head.innerHTML = m[2];
  1551. s = s.slice(0, m.index) + s.slice(m.index + m[0].length);
  1552. }
  1553. m = /<body(\s[^>]*)?>([\s\S]*?)(<\/body>|$)/i.exec(s);
  1554. s = m ? m[2] : s.replace(/<\/?html(\s[^>]*)?>/gi, "");
  1555. d.body.innerHTML = s;
  1556. return d;
  1557. };
  1558. }
  1559. Object.defineProperty(doc, "activeElement", {
  1560. get: function () { return doc.body; }, configurable: true });
  1561. Object.defineProperty(doc, "defaultView", {
  1562. get: function () { return g; }, configurable: true });
  1563. var nav = g.navigator;
  1564. nav.languages = [nav.language];
  1565. nav.onLine = true;
  1566. nav.cookieEnabled = true;
  1567. nav.maxTouchPoints = 0;
  1568. nav.hardwareConcurrency = 1;
  1569. nav.vendor = "";
  1570. nav.clipboard = {
  1571. writeText: function () { return Promise.resolve(); },
  1572. readText: function () { return Promise.resolve(""); }
  1573. };
  1574. nav.sendBeacon = function () { return true; };
  1575. /* ---- performance: a page-relative clock, User Timing, no resources ----
  1576. * The C side's now() counts from boot; pages expect milliseconds since the
  1577. * navigation (google.com adds it to timing.navigationStart). mark()/
  1578. * measure() keep a small timeline that getEntries*() search; resource and
  1579. * navigation entries are never recorded, so those lists are empty.
  1580. * google.com's results script calls performance.mark/measure/clearMarks
  1581. * around every render and getEntriesByType("resource") in its CSI ping;
  1582. * both threw "not a function" before. */
  1583. (function () {
  1584. var perf = g.performance, rawNow = perf.now, base = rawNow.call(perf);
  1585. var origin = Date.now(), timeline = [];
  1586. function now() { return rawNow.call(perf) - base; }
  1587. function at(v) {
  1588. if (typeof v === "number") return v;
  1589. if (typeof v === "string") {
  1590. for (var i = timeline.length - 1; i >= 0; i--)
  1591. if (timeline[i].entryType === "mark" &&
  1592. timeline[i].name === v)
  1593. return timeline[i].startTime;
  1594. throw new SyntaxError("The mark '" + v + "' does not exist.");
  1595. }
  1596. return undefined;
  1597. }
  1598. function entry(name, type, start, duration, detail) {
  1599. var e = { name: String(name), entryType: type, startTime: start,
  1600. duration: duration, detail: detail === undefined ?
  1601. null : detail };
  1602. e.toJSON = function () { return Object.assign({}, this); };
  1603. timeline.push(e);
  1604. if (timeline.length > 1000) timeline.shift();
  1605. return e;
  1606. }
  1607. function clear(type, name) {
  1608. timeline = timeline.filter(function (e) {
  1609. return e.entryType !== type ||
  1610. (name !== undefined && e.name !== name);
  1611. });
  1612. }
  1613. perf.now = now;
  1614. perf.timeOrigin = origin;
  1615. perf.timing = {
  1616. navigationStart: origin, fetchStart: origin,
  1617. requestStart: origin, responseStart: origin,
  1618. responseEnd: origin, domLoading: origin,
  1619. domInteractive: origin, domContentLoadedEventStart: origin,
  1620. domContentLoadedEventEnd: origin, domComplete: origin,
  1621. loadEventStart: origin, loadEventEnd: origin,
  1622. toJSON: function () { return Object.assign({}, this); }
  1623. };
  1624. perf.navigation = { type: 0, redirectCount: 0 };
  1625. perf.mark = function (name, opts) {
  1626. opts = opts || {};
  1627. return entry(name, "mark", opts.startTime !== undefined ?
  1628. opts.startTime : now(), 0, opts.detail);
  1629. };
  1630. perf.measure = function (name, start, end) {
  1631. var s = 0, e = now(), detail;
  1632. if (start && typeof start === "object") {
  1633. detail = start.detail;
  1634. if (start.start !== undefined) s = at(start.start);
  1635. if (start.end !== undefined) e = at(start.end);
  1636. if (start.duration !== undefined) {
  1637. if (start.start !== undefined) e = s + start.duration;
  1638. else s = e - start.duration;
  1639. }
  1640. } else {
  1641. if (start !== undefined) s = at(start);
  1642. if (end !== undefined) e = at(end);
  1643. }
  1644. return entry(name, "measure", s, e - s, detail);
  1645. };
  1646. perf.clearMarks = function (name) { clear("mark", name); };
  1647. perf.clearMeasures = function (name) { clear("measure", name); };
  1648. perf.clearResourceTimings = function () {};
  1649. perf.setResourceTimingBufferSize = function () {};
  1650. perf.getEntries = function () { return timeline.slice(); };
  1651. perf.getEntriesByType = function (type) {
  1652. return timeline.filter(function (e) { return e.entryType === type; });
  1653. };
  1654. perf.getEntriesByName = function (name, type) {
  1655. return timeline.filter(function (e) {
  1656. return e.name === name &&
  1657. (type === undefined || e.entryType === type);
  1658. });
  1659. };
  1660. perf.toJSON = function () {
  1661. return { timeOrigin: origin, timing: perf.timing.toJSON() };
  1662. };
  1663. })();
  1664. class PerformanceObserver {
  1665. constructor(cb) { this._cb = cb; }
  1666. observe() {}
  1667. disconnect() {}
  1668. takeRecords() { return []; }
  1669. }
  1670. PerformanceObserver.supportedEntryTypes = [];
  1671. def("PerformanceObserver", PerformanceObserver);
  1672. /* ---- Intl: QuickJS has none. A small en-US-only subset; every locale
  1673. * argument is accepted and ignored, and dates are formatted in UTC (the
  1674. * libc's only zone, so Date's local getters agree). ---- */
  1675. (function () {
  1676. var MON = "January February March April May June July August September October November December".split(" "),
  1677. DAY = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" ");
  1678. function opt(o) { return o == null ? {} : Object(o); }
  1679. function ctor(f, p) {
  1680. f.prototype = p;
  1681. f.supportedLocalesOf = function (l) {
  1682. return [].concat(l === undefined ? [] : l).map(String);
  1683. };
  1684. return f;
  1685. }
  1686. function parts2s(p) { return p.map(function (x) { return x.value; }).join(""); }
  1687. function pad2(n) { return (n < 10 ? "0" : "") + n; }
  1688. var CUR = { USD: "$", EUR: "€", GBP: "£", JPY: "¥", INR: "₹" };
  1689. var UNIT = { byte: "byte", kilobyte: "kB", megabyte: "MB", gigabyte: "GB",
  1690. terabyte: "TB", petabyte: "PB", bit: "bit", kilobit: "kb",
  1691. megabit: "Mb", gigabit: "Gb", millisecond: "ms", second: "sec",
  1692. minute: "min", hour: "hr", day: "day", week: "wk", month: "mth",
  1693. year: "yr", percent: "%", meter: "m", kilometer: "km",
  1694. celsius: "°C" };
  1695. function NumberFormat(l, o) {
  1696. if (!(this instanceof NumberFormat)) return new NumberFormat(l, o);
  1697. o = opt(o);
  1698. var st = o.style || "decimal", cur = st === "currency" ?
  1699. String(o.currency).toUpperCase() : undefined,
  1700. dmin = cur ? (cur === "JPY" ? 0 : 2) : 0,
  1701. dmax = cur ? dmin : st === "percent" ? 0 : 3,
  1702. mn = o.minimumFractionDigits, mx = o.maximumFractionDigits;
  1703. if (mn === undefined) mn = mx === undefined ? dmin : Math.min(dmin, mx);
  1704. if (mx === undefined) mx = Math.max(mn, dmax);
  1705. this.o = { locale: "en-US", numberingSystem: "latn", style: st,
  1706. currency: cur, currencyDisplay: o.currencyDisplay || "symbol",
  1707. unit: o.unit, unitDisplay: o.unitDisplay || "short",
  1708. minimumIntegerDigits: o.minimumIntegerDigits || 1,
  1709. minimumFractionDigits: +mn, maximumFractionDigits: +mx,
  1710. maximumSignificantDigits: o.maximumSignificantDigits,
  1711. useGrouping: o.useGrouping === undefined ? "auto" : o.useGrouping,
  1712. notation: o.notation || "standard",
  1713. signDisplay: o.signDisplay || "auto" };
  1714. }
  1715. ctor(NumberFormat, {
  1716. formatToParts: function (x) {
  1717. var o = this.o, p = [], v = Number(x), neg = v < 0 ||
  1718. Object.is(v, -0), sfx = "", s, i, k;
  1719. function add(t, s) { if (s) p.push({ type: t, value: s }); }
  1720. if (isNaN(v)) return [{ type: "nan", value: "NaN" }];
  1721. v = Math.abs(v);
  1722. if (o.style === "percent") v *= 100;
  1723. function rnd(v) {
  1724. var sig = o.maximumSignificantDigits ||
  1725. (o.notation === "compact" && v < 99.5 ? 2 : 0), f, s;
  1726. if (sig) v = +v.toPrecision(sig);
  1727. f = sig ? Math.max(0, sig - 1 - Math.floor(Math.log10(v || 1))) :
  1728. o.notation === "compact" ? 0 : o.maximumFractionDigits;
  1729. s = v.toFixed(Math.min(f, 20));
  1730. while (/\.\d*0$/.test(s) && s.length - s.indexOf(".") - 1 >
  1731. (sig ? 0 : o.minimumFractionDigits))
  1732. s = s.slice(0, -1);
  1733. return s.replace(/\.$/, "");
  1734. }
  1735. if (!isFinite(v)) s = "\u221e";
  1736. else if (o.notation === "compact") {
  1737. for (k = 0; k < 4 && +rnd(v / Math.pow(1000, k)) >= 1000; k++);
  1738. s = rnd(v / Math.pow(1000, k));
  1739. sfx = k ? "KMBT"[k - 1] : "";
  1740. } else s = rnd(v);
  1741. i = s.split(".");
  1742. while (i[0].length < o.minimumIntegerDigits) i[0] = "0" + i[0];
  1743. var sd = o.signDisplay, zero = +s === 0 || s === "0";
  1744. if (sd === "never" || (sd === "exceptZero" || sd === "negative") && zero)
  1745. neg = false;
  1746. add(neg ? "minusSign" : "plusSign", neg ? "-" :
  1747. sd === "always" || sd === "exceptZero" && !zero ? "+" : "");
  1748. if (o.currency) {
  1749. var sym = o.currencyDisplay === "code" ? o.currency + " " :
  1750. CUR[o.currency] || o.currency + " ";
  1751. add("currency", sym);
  1752. }
  1753. if (o.useGrouping !== false && !/^∞/.test(s) &&
  1754. (o.useGrouping !== "min2" || i[0].length > 4))
  1755. i[0].split(/(?=(?:\d{3})+$)/).forEach(function (d, n) {
  1756. if (n) add("group", ",");
  1757. add("integer", d);
  1758. });
  1759. else add(isFinite(v) ? "integer" : "infinity", i[0]);
  1760. if (i[1]) { add("decimal", "."); add("fraction", i[1]); }
  1761. add("compact", sfx);
  1762. if (o.style === "percent") add("percentSign", "%");
  1763. if (o.style === "unit") {
  1764. var u = o.unit, d = o.unitDisplay, w = UNIT[u] || u;
  1765. if (d === "long") w = " " + u + (+s === 1 ? "" : "s");
  1766. else w = (d === "narrow" ? "" : " ") + w +
  1767. (u === "day" && +s !== 1 && d !== "narrow" ? "s" : "");
  1768. add("unit", w);
  1769. }
  1770. return p;
  1771. },
  1772. resolvedOptions: function () { return Object.assign({}, this.o); }
  1773. });
  1774. Object.defineProperty(NumberFormat.prototype, "format", { get: function () {
  1775. var self = this;
  1776. return function (x) { return parts2s(self.formatToParts(x)); };
  1777. } });
  1778. var DFIELDS = ["weekday", "year", "month", "day"],
  1779. TFIELDS = ["dayPeriod", "hour", "minute", "second",
  1780. "fractionalSecondDigits"];
  1781. var DSTY = { full: { weekday: "long", month: "long", day: "numeric",
  1782. year: "numeric" },
  1783. long: { month: "long", day: "numeric", year: "numeric" },
  1784. medium: { month: "short", day: "numeric", year: "numeric" },
  1785. short: { month: "numeric", day: "numeric", year: "2-digit" } };
  1786. function has(o, l) { return l.some(function (k) { return o[k] !== undefined; }); }
  1787. /* need/def: "date"/"time"/"any", "date"/"time"/"all" (ECMA-402
  1788. * ToDateTimeOptions). */
  1789. function dtopts(o, need, def) {
  1790. var r = {}, k;
  1791. o = opt(o);
  1792. for (k in o) r[k] = o[k];
  1793. if (o.dateStyle || o.timeStyle) {
  1794. if (o.dateStyle) Object.assign(r, DSTY[o.dateStyle]);
  1795. if (o.timeStyle) {
  1796. r.hour = "numeric"; r.minute = "2-digit";
  1797. if (o.timeStyle !== "short") r.second = "2-digit";
  1798. if (/full|long/.test(o.timeStyle)) r.timeZoneName = "short";
  1799. }
  1800. } else if (!(need !== "time" && has(o, DFIELDS) ||
  1801. need !== "date" && has(o, TFIELDS))) {
  1802. if (def !== "time") r.year = r.month = r.day = "numeric";
  1803. if (def !== "date") r.hour = r.minute = r.second = "numeric";
  1804. }
  1805. r.locale = "en-US"; r.calendar = "gregory"; r.numberingSystem = "latn";
  1806. r.timeZone = "UTC";
  1807. if (r.hour) {
  1808. r.hour12 = o.hour12 !== undefined ? !!o.hour12 :
  1809. !/h2[34]/.test(o.hourCycle);
  1810. r.hourCycle = r.hour12 ? "h12" : "h23";
  1811. }
  1812. return r;
  1813. }
  1814. function DateTimeFormat(l, o) {
  1815. if (!(this instanceof DateTimeFormat)) return new DateTimeFormat(l, o);
  1816. this.o = this.o || dtopts(o, "any", "date");
  1817. }
  1818. function dtparts(o, d) {
  1819. var p = [], t = new Date(+d), h, m, n, txt;
  1820. function add(ty, v) { p.push({ type: ty, value: String(v) }); }
  1821. function lit(v) { add("literal", v); }
  1822. if (isNaN(t)) throw new RangeError("Invalid time value");
  1823. m = t.getUTCMonth(); n = t.getUTCFullYear();
  1824. function yr() { add("year", o.year === "2-digit" ? pad2(n % 100) : n); }
  1825. function dy() { add("day", o.day === "2-digit" ? pad2(t.getUTCDate()) : t.getUTCDate()); }
  1826. if (o.weekday) {
  1827. txt = DAY[t.getUTCDay()];
  1828. add("weekday", o.weekday === "long" ? txt : o.weekday === "narrow" ? txt[0] : txt.slice(0, 3));
  1829. if (o.month || o.day || o.year) lit(", ");
  1830. }
  1831. if (/^(long|short|narrow)$/.test(o.month)) {
  1832. txt = MON[m];
  1833. add("month", o.month === "long" ? txt : o.month === "narrow" ? txt[0] : txt.slice(0, 3));
  1834. if (o.day) { lit(" "); dy(); }
  1835. if (o.year) { lit(o.day ? ", " : " "); yr(); }
  1836. } else {
  1837. [["month", o.month], ["day", o.day], ["year", o.year]].forEach(function (f) {
  1838. if (!f[1]) return;
  1839. if (p.length && p[p.length - 1].type !== "literal") lit("/");
  1840. if (f[0] === "month") add("month", f[1] === "2-digit" ? pad2(m + 1) : m + 1);
  1841. else if (f[0] === "day") dy();
  1842. else yr();
  1843. });
  1844. }
  1845. if (o.hour || o.minute || o.second) {
  1846. if (p.length) lit(o.dateStyle && /full|long/.test(o.dateStyle) && o.timeStyle ? " at " : ", ");
  1847. h = t.getUTCHours();
  1848. if (o.hour) {
  1849. n = o.hour12 ? h % 12 || 12 : h;
  1850. add("hour", o.hour === "2-digit" || !o.hour12 ? pad2(n) : n);
  1851. }
  1852. if (o.minute) {
  1853. if (o.hour) lit(":");
  1854. add("minute", o.hour || o.minute === "2-digit" ? pad2(t.getUTCMinutes()) : t.getUTCMinutes());
  1855. }
  1856. if (o.second) {
  1857. if (o.hour || o.minute) lit(":");
  1858. add("second", o.hour || o.minute || o.second === "2-digit" ? pad2(t.getUTCSeconds()) : t.getUTCSeconds());
  1859. }
  1860. if (o.fractionalSecondDigits) {
  1861. lit(".");
  1862. add("fractionalSecond", String(1000 + t.getUTCMilliseconds()).slice(1, 1 + o.fractionalSecondDigits));
  1863. }
  1864. if (o.hour && o.hour12) { lit(" "); add("dayPeriod", h < 12 ? "AM" : "PM"); }
  1865. }
  1866. if (o.timeZoneName) { lit(" "); add("timeZoneName", "UTC"); }
  1867. return p;
  1868. }
  1869. ctor(DateTimeFormat, {
  1870. formatToParts: function (d) {
  1871. return dtparts(this.o, d === undefined ? Date.now() : d);
  1872. },
  1873. formatRange: function (a, b) {
  1874. return this.format(a) + " – " + this.format(b);
  1875. },
  1876. resolvedOptions: function () { return Object.assign({}, this.o); }
  1877. });
  1878. Object.defineProperty(DateTimeFormat.prototype, "format", { get: function () {
  1879. var self = this;
  1880. return function (d) { return parts2s(self.formatToParts(d)); };
  1881. } });
  1882. function dtf(need, def) {
  1883. return function (l, o) {
  1884. if (isNaN(this)) return "Invalid Date";
  1885. var f = Object.create(DateTimeFormat.prototype);
  1886. f.o = dtopts(o, need, def);
  1887. return f.format(this);
  1888. };
  1889. }
  1890. Date.prototype.toLocaleString = dtf("any", "all");
  1891. Date.prototype.toLocaleDateString = dtf("date", "date");
  1892. Date.prototype.toLocaleTimeString = dtf("time", "time");
  1893. Number.prototype.toLocaleString = function (l, o) {
  1894. return NumberFormat(l, o).format(this);
  1895. };
  1896. var RTU = { second: "sec.", minute: "min.", hour: "hr.", day: "day",
  1897. week: "wk.", month: "mo.", quarter: "qtr.", year: "yr." };
  1898. function RelativeTimeFormat(l, o) {
  1899. o = opt(o);
  1900. this.o = { locale: "en-US", numberingSystem: "latn",
  1901. style: o.style || "long", numeric: o.numeric || "always" };
  1902. }
  1903. ctor(RelativeTimeFormat, {
  1904. format: function (v, u) {
  1905. v = Number(v);
  1906. u = String(u).replace(/s$/, "");
  1907. if (!RTU[u]) throw new RangeError("Invalid unit: " + u);
  1908. if (this.o.numeric === "auto" && (v === 0 || Math.abs(v) === 1 &&
  1909. u !== "second" && u !== "minute" && u !== "hour")) {
  1910. if (u === "second") return "now";
  1911. if (u === "day") return v ? v < 0 ? "yesterday" : "tomorrow" : "today";
  1912. return (v ? v < 0 ? "last " : "next " : "this ") + u;
  1913. }
  1914. var a = Math.abs(v), w = this.o.style === "long" || u === "day" ?
  1915. u + (a === 1 ? "" : "s") : u === "quarter" && a !== 1 ?
  1916. "qtrs." : RTU[u],
  1917. s = NumberFormat().format(a) + " " + w;
  1918. return v < 0 || Object.is(v, -0) ? s + " ago" : "in " + s;
  1919. },
  1920. formatToParts: function (v, u) {
  1921. return [{ type: "literal", value: this.format(v, u) }];
  1922. },
  1923. resolvedOptions: function () { return Object.assign({}, this.o); }
  1924. });
  1925. var DUR = [["years", "yr", "y"], ["months", "mth", "mo"], ["weeks", "wk", "w"],
  1926. ["days", "day", "d"], ["hours", "hr", "h"], ["minutes", "min", "m"],
  1927. ["seconds", "sec", "s"], ["milliseconds", "ms", "ms"],
  1928. ["microseconds", "μs", "μs"],
  1929. ["nanoseconds", "ns", "ns"]];
  1930. function DurationFormat(l, o) {
  1931. o = opt(o);
  1932. this.o = { locale: "en-US", numberingSystem: "latn",
  1933. style: o.style || "short" };
  1934. }
  1935. ctor(DurationFormat, {
  1936. format: function (d) {
  1937. var st = this.o.style, out = [];
  1938. d = opt(d);
  1939. if (st === "digital") {
  1940. var hms = [d.hours || 0, pad2(d.minutes || 0), pad2(d.seconds || 0)].join(":");
  1941. out = DUR.slice(0, 4).filter(function (u) { return d[u[0]]; })
  1942. .map(function (u) { return d[u[0]] + " " + u[0].slice(0, d[u[0]] === 1 ? -1 : undefined); });
  1943. out.push(hms);
  1944. return out.join(", ");
  1945. }
  1946. DUR.forEach(function (u) {
  1947. var v = d[u[0]];
  1948. if (!v) return;
  1949. out.push(st === "narrow" ? v + u[2] : v + " " +
  1950. (st === "long" ? u[0].slice(0, Math.abs(v) === 1 ? -1 : undefined) :
  1951. u[1] + (u[1] === "day" && v !== 1 ? "s" : "")));
  1952. });
  1953. return out.join(st === "narrow" ? " " : ", ");
  1954. },
  1955. resolvedOptions: function () { return Object.assign({}, this.o); }
  1956. });
  1957. var LANG = { en: "English", de: "German", fr: "French", es: "Spanish",
  1958. it: "Italian", nl: "Dutch", pt: "Portuguese", ru: "Russian",
  1959. zh: "Chinese", ja: "Japanese", ko: "Korean", pl: "Polish",
  1960. tr: "Turkish", cs: "Czech", da: "Danish", sv: "Swedish",
  1961. fi: "Finnish", nb: "Norwegian Bokmål", no: "Norwegian",
  1962. uk: "Ukrainian", hu: "Hungarian", el: "Greek", ro: "Romanian",
  1963. vi: "Vietnamese", id: "Indonesian", ar: "Arabic", he: "Hebrew",
  1964. hi: "Hindi", fa: "Persian", sk: "Slovak", bg: "Bulgarian",
  1965. hr: "Croatian", sr: "Serbian", sl: "Slovenian", et: "Estonian",
  1966. lv: "Latvian", lt: "Lithuanian", ca: "Catalan", gl: "Galician",
  1967. eu: "Basque", th: "Thai", ms: "Malay", ta: "Tamil", bn: "Bangla",
  1968. "en-US": "American English", "en-GB": "British English",
  1969. "pt-BR": "Brazilian Portuguese", "pt-PT": "European Portuguese",
  1970. "es-MX": "Mexican Spanish", "fr-CA": "Canadian French" };
  1971. var REG = { US: "United States", GB: "United Kingdom", DE: "Germany",
  1972. FR: "France", ES: "Spain", IT: "Italy", NL: "Netherlands",
  1973. BR: "Brazil", PT: "Portugal", CN: "China", TW: "Taiwan",
  1974. JP: "Japan", IN: "India", CA: "Canada", AU: "Australia",
  1975. AT: "Austria", CH: "Switzerland", RU: "Russia" };
  1976. function DisplayNames(l, o) {
  1977. o = opt(o);
  1978. this.o = { locale: "en-US", style: o.style || "long",
  1979. type: o.type, fallback: o.fallback || "code" };
  1980. }
  1981. ctor(DisplayNames, {
  1982. of: function (c) {
  1983. c = String(c);
  1984. var t = this.o.type, s = c.split(/[-_]/), r;
  1985. if (t === "region") r = REG[c.toUpperCase()];
  1986. else if (t === "language") {
  1987. r = LANG[s[0].toLowerCase() + "-" + s[1]] || LANG[s[0].toLowerCase()];
  1988. if (r && s[1] && !LANG[s[0].toLowerCase() + "-" + s[1]]) r = REG[s[1].toUpperCase()] ?
  1989. r + " (" + REG[s[1].toUpperCase()] + ")" : r + " (" + s[1] + ")";
  1990. }
  1991. return r || (this.o.fallback === "none" ? undefined : c);
  1992. },
  1993. resolvedOptions: function () { return Object.assign({}, this.o); }
  1994. });
  1995. /* Collation: case- and accent-blind first (ICU's primary strength), then
  1996. * accents, then lower before upper; digit runs compare by value when
  1997. * numeric is set. */
  1998. function fold(s) {
  1999. return /^[\x00-\x7f]*$/.test(s) ? s : s.normalize("NFD").replace(/[̀-ͯ]/g, "");
  2000. }
  2001. /* Code-point order within a class; ICU's classes order whitespace,
  2002. * punctuation/symbols, digits, letters. */
  2003. function cls(c) {
  2004. return c <= 32 ? 0 : c >= 48 && c <= 57 ? 2 : c >= 65 && c <= 90 ||
  2005. c >= 97 && c <= 122 || c > 127 ? 3 : 1;
  2006. }
  2007. function cmp(a, b, num) {
  2008. var i = 0, j = 0, x, y, m, n;
  2009. while (i < a.length && j < b.length) {
  2010. x = a.charCodeAt(i); y = b.charCodeAt(j);
  2011. if (num && cls(x) === 2 && cls(y) === 2) {
  2012. m = /^0*(\d*)/.exec(a.slice(i).match(/^\d+/)[0])[1];
  2013. n = /^0*(\d*)/.exec(b.slice(j).match(/^\d+/)[0])[1];
  2014. if (m.length !== n.length) return m.length < n.length ? -1 : 1;
  2015. if (m !== n) return m < n ? -1 : 1;
  2016. i += a.slice(i).match(/^\d+/)[0].length;
  2017. j += b.slice(j).match(/^\d+/)[0].length;
  2018. continue;
  2019. }
  2020. if (x !== y) return cls(x) - cls(y) || (x < y ? -1 : 1);
  2021. i++; j++;
  2022. }
  2023. return i < a.length ? 1 : j < b.length ? -1 : 0;
  2024. }
  2025. function Collator(l, o) {
  2026. if (!(this instanceof Collator)) return new Collator(l, o);
  2027. o = opt(o);
  2028. var r = this.o = { locale: "en-US", usage: o.usage || "sort",
  2029. sensitivity: o.sensitivity || "variant",
  2030. ignorePunctuation: !!o.ignorePunctuation,
  2031. numeric: !!o.numeric, caseFirst: o.caseFirst || "false",
  2032. collation: "default" };
  2033. this.compare = function (a, b) {
  2034. a = String(a); b = String(b);
  2035. if (r.ignorePunctuation) {
  2036. a = a.replace(/[\s!-/:-@[-`{-~]/g, "");
  2037. b = b.replace(/[\s!-/:-@[-`{-~]/g, "");
  2038. }
  2039. var fa = fold(a), fb = fold(b),
  2040. c = cmp(fa.toLowerCase(), fb.toLowerCase(), r.numeric);
  2041. if (c || r.sensitivity === "base") return c;
  2042. if (r.sensitivity !== "case" && (c = cmp(a.toLowerCase(), b.toLowerCase(), r.numeric)))
  2043. return c;
  2044. if (r.sensitivity === "accent") return 0;
  2045. c = -cmp(r.sensitivity === "case" ? fa : a, r.sensitivity === "case" ? fb : b, r.numeric);
  2046. return r.caseFirst === "upper" ? -c : c;
  2047. };
  2048. }
  2049. ctor(Collator, {
  2050. resolvedOptions: function () { return Object.assign({}, this.o); }
  2051. });
  2052. var coll0 = new Collator();
  2053. String.prototype.localeCompare = function (t, l, o) {
  2054. return (o ? new Collator(l, o) : coll0).compare(this, t);
  2055. };
  2056. function PluralRules(l, o) {
  2057. o = opt(o);
  2058. this.o = { locale: "en-US", type: o.type || "cardinal",
  2059. pluralCategories: o.type === "ordinal" ?
  2060. ["few", "one", "two", "other"] : ["one", "other"] };
  2061. }
  2062. ctor(PluralRules, {
  2063. select: function (n) {
  2064. n = Math.abs(Number(n));
  2065. if (this.o.type !== "ordinal") return n === 1 ? "one" : "other";
  2066. var a = n % 10, b = n % 100;
  2067. return a === 1 && b !== 11 ? "one" : a === 2 && b !== 12 ? "two" :
  2068. a === 3 && b !== 13 ? "few" : "other";
  2069. },
  2070. resolvedOptions: function () { return Object.assign({}, this.o); }
  2071. });
  2072. function ListFormat(l, o) {
  2073. o = opt(o);
  2074. this.o = { locale: "en-US", type: o.type || "conjunction",
  2075. style: o.style || "long" };
  2076. }
  2077. ctor(ListFormat, {
  2078. format: function (l) {
  2079. var a = Array.from(l || [], String), t = this.o.type,
  2080. w = t === "disjunction" ? " or " : t === "unit" ? ", " :
  2081. this.o.style === "long" ? " and " : this.o.style === "short" ? " & " : ", ";
  2082. if (t === "unit" && this.o.style === "narrow") return a.join(" ");
  2083. if (a.length < 3) return a.join(w);
  2084. return a.slice(0, -1).join(", ") + (t === "unit" || w === ", " ?
  2085. ", " : "," + w) + a[a.length - 1];
  2086. },
  2087. resolvedOptions: function () { return Object.assign({}, this.o); }
  2088. });
  2089. function Locale(t) {
  2090. var s = String(t).split(/[-_]/);
  2091. this.baseName = String(t).replace(/_/g, "-");
  2092. this.language = s[0].toLowerCase();
  2093. this.region = s.length > 1 && /^[A-Za-z]{2}$|^\d{3}$/.test(s[s.length - 1]) ?
  2094. s[s.length - 1].toUpperCase() : undefined;
  2095. }
  2096. Locale.prototype.toString = function () { return this.baseName; };
  2097. Locale.prototype.maximize = Locale.prototype.minimize = function () { return this; };
  2098. def("Intl", Object.defineProperty({
  2099. DateTimeFormat: DateTimeFormat, NumberFormat: NumberFormat,
  2100. RelativeTimeFormat: RelativeTimeFormat, DurationFormat: DurationFormat,
  2101. DisplayNames: DisplayNames, Collator: Collator,
  2102. PluralRules: PluralRules, ListFormat: ListFormat, Locale: Locale,
  2103. getCanonicalLocales: function (l) {
  2104. return [].concat(l === undefined ? [] : l).map(String);
  2105. },
  2106. supportedValuesOf: function (k) {
  2107. return k === "timeZone" ? ["UTC"] : k === "calendar" ? ["gregory"] : [];
  2108. }
  2109. }, Symbol.toStringTag, { value: "Intl", configurable: true }));
  2110. })();
  2111. /* ---- CSS namespace ----
  2112. * escape() is the CSSOM serialization of an identifier; supports() gives
  2113. * the cascade's own @supports answer (true unless it asks for selector()),
  2114. * so scripts and stylesheets agree. */
  2115. def("CSS", {
  2116. escape: function (value) {
  2117. var s = String(value), out = "", i, c, first = s.charCodeAt(0);
  2118. if (s.length === 1 && first === 0x2D) return "\\-";
  2119. for (i = 0; i < s.length; i++) {
  2120. c = s.charCodeAt(i);
  2121. if (c === 0) out += "�";
  2122. else if ((c >= 0x01 && c <= 0x1F) || c === 0x7F ||
  2123. (i === 0 && c >= 0x30 && c <= 0x39) ||
  2124. (i === 1 && c >= 0x30 && c <= 0x39 &&
  2125. first === 0x2D))
  2126. out += "\\" + c.toString(16) + " ";
  2127. else if (c >= 0x80 || c === 0x2D || c === 0x5F ||
  2128. (c >= 0x30 && c <= 0x39) ||
  2129. (c >= 0x41 && c <= 0x5A) ||
  2130. (c >= 0x61 && c <= 0x7A))
  2131. out += s.charAt(i);
  2132. else
  2133. out += "\\" + s.charAt(i);
  2134. }
  2135. return out;
  2136. },
  2137. supports: function (prop, value) {
  2138. var q = arguments.length > 1 ? String(prop) + ":" + String(value) :
  2139. String(prop);
  2140. return !/selector\s*\(/i.test(q) && !/^\s*not\s/i.test(q);
  2141. }
  2142. });
  2143. g.history.state = null;
  2144. g.screen = { width: g.innerWidth, height: g.innerHeight,
  2145. availWidth: g.innerWidth, availHeight: g.innerHeight,
  2146. colorDepth: 16, pixelDepth: 16 };
  2147. g.outerWidth = g.innerWidth;
  2148. g.outerHeight = g.innerHeight;
  2149. g.name = "";
  2150. g.closed = false;
  2151. g.open = function () { return null; };
  2152. g.close = function () {};
  2153. g.focus = function () {};
  2154. g.blur = function () {};
  2155. g.print = function () {};
  2156. g.postMessage = function () {};
  2157. g.confirm = function () { return true; };
  2158. g.prompt = function () { return null; };
  2159. /* Parsed <template> children are inert in a browser: move them into each
  2160. * template's content fragment before the page's scripts walk the tree
  2161. * (Alpine would otherwise initialise them in place, in the wrong scope). */
  2162. (function () {
  2163. var tl = doc.getElementsByTagName("template"), a = [], i;
  2164. for (i = 0; i < tl.length; i++)
  2165. a.push(tl[i]);
  2166. for (i = 0; i < a.length; i++)
  2167. void a[i].content;
  2168. })();
  2169. })(globalThis);