js_prelude.js 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  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. def("queueMicrotask", function (f) { Promise.resolve().then(f); });
  57. def("requestIdleCallback", function (f) {
  58. return setTimeout(function () {
  59. f({ didTimeout: false, timeRemaining: function () { return 10; } });
  60. }, 1);
  61. });
  62. def("cancelIdleCallback", function (id) { clearTimeout(id); });
  63. def("structuredClone", function (v) {
  64. return v === undefined ? v : JSON.parse(JSON.stringify(v));
  65. });
  66. class DOMException extends Error {
  67. constructor(message, name) {
  68. super(message === undefined ? "" : message);
  69. this.name = name === undefined ? "Error" : name;
  70. }
  71. }
  72. def("DOMException", DOMException);
  73. /* ---- base64 ---- */
  74. var B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  75. def("btoa", function (s) {
  76. s = String(s);
  77. var out = "", i;
  78. for (i = 0; i < s.length; i += 3) {
  79. var a = s.charCodeAt(i), b = s.charCodeAt(i + 1),
  80. c = s.charCodeAt(i + 2);
  81. if (a > 255 || b > 255 || c > 255)
  82. throw new DOMException("Invalid character",
  83. "InvalidCharacterError");
  84. var n = (a << 16) | ((b || 0) << 8) | (c || 0);
  85. out += B64[n >> 18 & 63] + B64[n >> 12 & 63] +
  86. (i + 1 < s.length ? B64[n >> 6 & 63] : "=") +
  87. (i + 2 < s.length ? B64[n & 63] : "=");
  88. }
  89. return out;
  90. });
  91. def("atob", function (s) {
  92. s = String(s).replace(/[\s=]/g, "");
  93. var out = "", bits = 0, acc = 0, i;
  94. for (i = 0; i < s.length; i++) {
  95. var v = B64.indexOf(s[i]);
  96. if (v < 0)
  97. throw new DOMException("Invalid character",
  98. "InvalidCharacterError");
  99. acc = (acc << 6) | v;
  100. bits += 6;
  101. if (bits >= 8) {
  102. bits -= 8;
  103. out += String.fromCharCode((acc >> bits) & 255);
  104. }
  105. }
  106. return out;
  107. });
  108. /* ---- text encoding ---- */
  109. function utf8(s) {
  110. var out = [], i;
  111. s = String(s);
  112. for (i = 0; i < s.length; i++) {
  113. var c = s.charCodeAt(i);
  114. if (c >= 0xd800 && c < 0xdc00 && i + 1 < s.length) {
  115. var d = s.charCodeAt(i + 1);
  116. if (d >= 0xdc00 && d < 0xe000) {
  117. c = 0x10000 + ((c - 0xd800) << 10) + (d - 0xdc00);
  118. i++;
  119. }
  120. }
  121. if (c < 0x80) out.push(c);
  122. else if (c < 0x800) out.push(0xc0 | c >> 6, 0x80 | c & 63);
  123. else if (c < 0x10000)
  124. out.push(0xe0 | c >> 12, 0x80 | c >> 6 & 63, 0x80 | c & 63);
  125. else
  126. out.push(0xf0 | c >> 18, 0x80 | c >> 12 & 63,
  127. 0x80 | c >> 6 & 63, 0x80 | c & 63);
  128. }
  129. return new Uint8Array(out);
  130. }
  131. function bytesOf(b) {
  132. if (b instanceof ArrayBuffer) return new Uint8Array(b);
  133. if (ArrayBuffer.isView(b))
  134. return new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
  135. return utf8(b);
  136. }
  137. function unutf8(u) {
  138. var s = "", i = 0;
  139. while (i < u.length) {
  140. var c = u[i++];
  141. if (c >= 0xf0 && i + 2 < u.length + 0) {
  142. c = ((c & 7) << 18) | ((u[i++] & 63) << 12) |
  143. ((u[i++] & 63) << 6) | (u[i++] & 63);
  144. } else if (c >= 0xe0) {
  145. c = ((c & 15) << 12) | ((u[i++] & 63) << 6) | (u[i++] & 63);
  146. } else if (c >= 0xc0) {
  147. c = ((c & 31) << 6) | (u[i++] & 63);
  148. }
  149. s += String.fromCodePoint(c);
  150. }
  151. return s;
  152. }
  153. class TextEncoder {
  154. get encoding() { return "utf-8"; }
  155. encode(s) { return utf8(s === undefined ? "" : s); }
  156. }
  157. class TextDecoder {
  158. constructor(label) { this.encoding = "utf-8"; }
  159. decode(b) { return b ? unutf8(bytesOf(b)) : ""; }
  160. }
  161. def("TextEncoder", TextEncoder);
  162. def("TextDecoder", TextDecoder);
  163. /* ---- URLSearchParams / URL ---- */
  164. function qenc(s) {
  165. return encodeURIComponent(s).replace(/%20/g, "+").replace(/[!'()~]/g,
  166. function (c) {
  167. return "%" + c.charCodeAt(0).toString(16).toUpperCase();
  168. });
  169. }
  170. function qdec(s) {
  171. s = s.replace(/\+/g, " ");
  172. try { return decodeURIComponent(s); } catch (e) { return s; }
  173. }
  174. class URLSearchParams {
  175. constructor(init) {
  176. this._l = [];
  177. this._url = null;
  178. if (init == null) return;
  179. if (init instanceof URLSearchParams) {
  180. this._l = init._l.map(function (p) { return [p[0], p[1]]; });
  181. return;
  182. }
  183. if (typeof init === "object" || typeof init === "function") {
  184. if (typeof init[Symbol.iterator] === "function") {
  185. for (var p of init)
  186. this._l.push([String(p[0]), String(p[1])]);
  187. } else {
  188. for (var k of Object.keys(init))
  189. this._l.push([k, String(init[k])]);
  190. }
  191. return;
  192. }
  193. this._parse(String(init));
  194. }
  195. _parse(s) {
  196. this._l = [];
  197. if (s[0] === "?") s = s.slice(1);
  198. for (var part of s.split("&")) {
  199. if (!part) continue;
  200. var i = part.indexOf("=");
  201. this._l.push(i < 0 ? [qdec(part), ""] :
  202. [qdec(part.slice(0, i)), qdec(part.slice(i + 1))]);
  203. }
  204. }
  205. _upd() {
  206. if (this._url) {
  207. var s = this.toString();
  208. this._url._search = s ? "?" + s : "";
  209. }
  210. }
  211. append(k, v) { this._l.push([String(k), String(v)]); this._upd(); }
  212. delete(k) {
  213. k = String(k);
  214. this._l = this._l.filter(function (p) { return p[0] !== k; });
  215. this._upd();
  216. }
  217. get(k) {
  218. k = String(k);
  219. for (var p of this._l) if (p[0] === k) return p[1];
  220. return null;
  221. }
  222. getAll(k) {
  223. k = String(k);
  224. return this._l.filter(function (p) { return p[0] === k; })
  225. .map(function (p) { return p[1]; });
  226. }
  227. has(k) { return this.get(k) !== null; }
  228. set(k, v) {
  229. k = String(k); v = String(v);
  230. var found = false;
  231. this._l = this._l.filter(function (p) {
  232. if (p[0] !== k) return true;
  233. if (found) return false;
  234. found = true;
  235. p[1] = v;
  236. return true;
  237. });
  238. if (!found) this._l.push([k, v]);
  239. this._upd();
  240. }
  241. sort() {
  242. this._l.sort(function (a, b) {
  243. return a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
  244. });
  245. this._upd();
  246. }
  247. forEach(f, t) { for (var p of this._l.slice()) f.call(t, p[1], p[0], this); }
  248. keys() { return this._l.map(function (p) { return p[0]; })[Symbol.iterator](); }
  249. values() { return this._l.map(function (p) { return p[1]; })[Symbol.iterator](); }
  250. entries() { return this._l.map(function (p) { return [p[0], p[1]]; })[Symbol.iterator](); }
  251. [Symbol.iterator]() { return this.entries(); }
  252. get size() { return this._l.length; }
  253. toString() {
  254. return this._l.map(function (p) {
  255. return qenc(p[0]) + "=" + qenc(p[1]);
  256. }).join("&");
  257. }
  258. }
  259. def("URLSearchParams", URLSearchParams);
  260. var URL_RE = /^([a-zA-Z][a-zA-Z0-9+.\-]*:)(\/\/([^\/?#]*))?([^?#]*)(\?[^#]*)?(#.*)?$/;
  261. class URL {
  262. constructor(url, base) {
  263. url = String(url).trim();
  264. if (!/^[a-zA-Z][a-zA-Z0-9+.\-]*:/.test(url)) {
  265. if (base === undefined)
  266. throw new TypeError("Invalid URL: " + url);
  267. base = new URL(String(base)).href;
  268. url = resolve(base, url);
  269. }
  270. this._parse(url);
  271. }
  272. _parse(u) {
  273. var m = URL_RE.exec(u);
  274. if (!m) throw new TypeError("Invalid URL: " + u);
  275. this._protocol = m[1].toLowerCase();
  276. var auth = m[3] || "", at = auth.lastIndexOf("@");
  277. this._user = "";
  278. this._pass = "";
  279. if (at >= 0) {
  280. var ui = auth.slice(0, at), c = ui.indexOf(":");
  281. auth = auth.slice(at + 1);
  282. this._user = c < 0 ? ui : ui.slice(0, c);
  283. this._pass = c < 0 ? "" : ui.slice(c + 1);
  284. }
  285. var pm = /^(\[[^\]]*\]|[^:]*)(?::(\d*))?$/.exec(auth);
  286. this._hostname = (pm ? pm[1] : auth).toLowerCase();
  287. this._port = (pm && pm[2]) || "";
  288. if ((this._protocol === "https:" && this._port === "443") ||
  289. (this._protocol === "http:" && this._port === "80"))
  290. this._port = "";
  291. this._special = m[2] !== undefined;
  292. this._pathname = m[4] || (this._special ? "/" : "");
  293. this._search = m[5] && m[5].length > 1 ? m[5] : "";
  294. this._hash = m[6] && m[6].length > 1 ? m[6] : "";
  295. if (this._sp) this._sp._parse(this._search);
  296. }
  297. get protocol() { return this._protocol; }
  298. set protocol(v) {
  299. v = String(v);
  300. this._protocol = (v.endsWith(":") ? v : v + ":").toLowerCase();
  301. }
  302. get username() { return this._user; }
  303. set username(v) { this._user = String(v); }
  304. get password() { return this._pass; }
  305. set password(v) { this._pass = String(v); }
  306. get hostname() { return this._hostname; }
  307. set hostname(v) { this._hostname = String(v).toLowerCase(); }
  308. get port() { return this._port; }
  309. set port(v) { this._port = String(v); }
  310. get host() { return this._hostname + (this._port ? ":" + this._port : ""); }
  311. set host(v) {
  312. var m = /^(\[[^\]]*\]|[^:]*)(?::(\d*))?$/.exec(String(v));
  313. if (m) { this._hostname = m[1].toLowerCase(); this._port = m[2] || ""; }
  314. }
  315. get pathname() { return this._pathname; }
  316. set pathname(v) {
  317. v = String(v);
  318. this._pathname = this._special && v[0] !== "/" ? "/" + v : v;
  319. }
  320. get search() { return this._search; }
  321. set search(v) {
  322. v = String(v);
  323. if (v && v[0] !== "?") v = "?" + v;
  324. this._search = v === "?" ? "" : v;
  325. if (this._sp) this._sp._parse(this._search);
  326. }
  327. get hash() { return this._hash; }
  328. set hash(v) {
  329. v = String(v);
  330. if (v && v[0] !== "#") v = "#" + v;
  331. this._hash = v === "#" ? "" : v;
  332. }
  333. get origin() {
  334. return this._special && this._protocol !== "file:" ?
  335. this._protocol + "//" + this.host : "null";
  336. }
  337. get href() {
  338. var a = this._user ? this._user +
  339. (this._pass ? ":" + this._pass : "") + "@" : "";
  340. return this._protocol + (this._special ? "//" + a + this.host : "") +
  341. this._pathname + this._search + this._hash;
  342. }
  343. set href(v) { this._parse(String(v)); }
  344. get searchParams() {
  345. if (!this._sp) {
  346. this._sp = new URLSearchParams(this._search);
  347. this._sp._url = this;
  348. }
  349. return this._sp;
  350. }
  351. toString() { return this.href; }
  352. toJSON() { return this.href; }
  353. static canParse(u, b) {
  354. try { new URL(u, b); return true; } catch (e) { return false; }
  355. }
  356. static parse(u, b) {
  357. try { return new URL(u, b); } catch (e) { return null; }
  358. }
  359. static createObjectURL() { return "blob:nebos/" + Date.now(); }
  360. static revokeObjectURL() {}
  361. }
  362. def("URL", URL);
  363. def("webkitURL", URL);
  364. /* ---- Headers / Blob / FormData / Request / Response ---- */
  365. class Headers {
  366. constructor(init) {
  367. this._m = new Map();
  368. if (!init) return;
  369. if (init instanceof Headers)
  370. init.forEach((v, k) => this.append(k, v));
  371. else if (typeof init[Symbol.iterator] === "function")
  372. for (var p of init) this.append(p[0], p[1]);
  373. else
  374. for (var k of Object.keys(init)) this.append(k, init[k]);
  375. }
  376. append(k, v) {
  377. k = String(k).toLowerCase();
  378. var o = this._m.get(k);
  379. this._m.set(k, o !== undefined ? o + ", " + v : String(v));
  380. }
  381. set(k, v) { this._m.set(String(k).toLowerCase(), String(v)); }
  382. get(k) {
  383. var v = this._m.get(String(k).toLowerCase());
  384. return v === undefined ? null : v;
  385. }
  386. has(k) { return this._m.has(String(k).toLowerCase()); }
  387. delete(k) { this._m.delete(String(k).toLowerCase()); }
  388. forEach(f, t) { for (var [k, v] of this._m) f.call(t, v, k, this); }
  389. keys() { return this._m.keys(); }
  390. values() { return this._m.values(); }
  391. entries() { return this._m.entries(); }
  392. [Symbol.iterator]() { return this._m.entries(); }
  393. }
  394. def("Headers", Headers);
  395. function partText(p) {
  396. if (typeof p === "string") return p;
  397. if (p instanceof Blob) return p._s;
  398. if (p instanceof ArrayBuffer || ArrayBuffer.isView(p))
  399. return unutf8(bytesOf(p));
  400. return String(p);
  401. }
  402. class Blob {
  403. constructor(parts, opts) {
  404. this._s = (parts || []).map(partText).join("");
  405. this.type = (opts && opts.type) || "";
  406. }
  407. get size() { return utf8(this._s).length; }
  408. text() { return Promise.resolve(this._s); }
  409. arrayBuffer() { return Promise.resolve(utf8(this._s).buffer); }
  410. slice(a, b, t) { return new Blob([this._s.slice(a, b)], { type: t }); }
  411. }
  412. class File extends Blob {
  413. constructor(parts, name, opts) {
  414. super(parts, opts);
  415. this.name = String(name);
  416. this.lastModified = (opts && opts.lastModified) || Date.now();
  417. }
  418. }
  419. def("Blob", Blob);
  420. def("File", File);
  421. class FormData {
  422. constructor() { this._l = []; }
  423. append(k, v) { this._l.push([String(k), v]); }
  424. set(k, v) { this.delete(k); this.append(k, v); }
  425. get(k) {
  426. for (var p of this._l) if (p[0] === k) return p[1];
  427. return null;
  428. }
  429. getAll(k) {
  430. return this._l.filter(function (p) { return p[0] === k; })
  431. .map(function (p) { return p[1]; });
  432. }
  433. has(k) { return this.get(k) !== null; }
  434. delete(k) { this._l = this._l.filter(function (p) { return p[0] !== k; }); }
  435. forEach(f, t) { for (var p of this._l) f.call(t, p[1], p[0], this); }
  436. entries() { return this._l.map(function (p) { return [p[0], p[1]]; })[Symbol.iterator](); }
  437. keys() { return this._l.map(function (p) { return p[0]; })[Symbol.iterator](); }
  438. values() { return this._l.map(function (p) { return p[1]; })[Symbol.iterator](); }
  439. [Symbol.iterator]() { return this.entries(); }
  440. }
  441. def("FormData", FormData);
  442. class AbortSignal {
  443. constructor() {
  444. this.aborted = false;
  445. this.reason = undefined;
  446. this.onabort = null;
  447. this._l = [];
  448. }
  449. addEventListener(t, f) { if (t === "abort") this._l.push(f); }
  450. removeEventListener(t, f) { this._l = this._l.filter(function (x) { return x !== f; }); }
  451. throwIfAborted() { if (this.aborted) throw this.reason; }
  452. static abort(r) { var c = new AbortController(); c.abort(r); return c.signal; }
  453. static timeout(ms) {
  454. var c = new AbortController();
  455. setTimeout(function () {
  456. c.abort(new DOMException("signal timed out", "TimeoutError"));
  457. }, ms);
  458. return c.signal;
  459. }
  460. }
  461. class AbortController {
  462. constructor() { this.signal = new AbortSignal(); }
  463. abort(r) {
  464. var s = this.signal, ev;
  465. if (s.aborted) return;
  466. s.aborted = true;
  467. s.reason = r === undefined ?
  468. new DOMException("signal is aborted without reason",
  469. "AbortError") : r;
  470. ev = { type: "abort", target: s };
  471. if (typeof s.onabort === "function") s.onabort(ev);
  472. s._l.forEach(function (f) { f(ev); });
  473. }
  474. }
  475. def("AbortSignal", AbortSignal);
  476. def("AbortController", AbortController);
  477. class Request {
  478. constructor(input, init) {
  479. init = init || {};
  480. if (input instanceof Request) {
  481. this.url = input.url;
  482. this.method = input.method;
  483. this.headers = new Headers(input.headers);
  484. this.body = input.body;
  485. this.signal = input.signal;
  486. } else {
  487. this.url = new URL(String(input), g.location.href).href;
  488. this.method = "GET";
  489. this.headers = new Headers();
  490. this.body = null;
  491. this.signal = null;
  492. }
  493. if (init.method) this.method = String(init.method).toUpperCase();
  494. if (init.headers) this.headers = new Headers(init.headers);
  495. if (init.body !== undefined) this.body = init.body;
  496. if (init.signal) this.signal = init.signal;
  497. this.credentials = init.credentials || "same-origin";
  498. this.mode = init.mode || "cors";
  499. }
  500. clone() { return new Request(this); }
  501. }
  502. def("Request", Request);
  503. class Response {
  504. constructor(body, init) {
  505. init = init || {};
  506. this._b = body == null ? "" : partText(body);
  507. this.status = init.status === undefined ? 200 : init.status;
  508. this.statusText = init.statusText || "";
  509. this.headers = init.headers instanceof Headers ? init.headers :
  510. new Headers(init.headers);
  511. this.ok = this.status >= 200 && this.status < 300;
  512. this.url = init.url || "";
  513. this.redirected = !!init.redirected;
  514. this.type = "basic";
  515. this.bodyUsed = false;
  516. this.body = null;
  517. }
  518. text() { this.bodyUsed = true; return Promise.resolve(this._b); }
  519. json() {
  520. this.bodyUsed = true;
  521. try { return Promise.resolve(JSON.parse(this._b)); }
  522. catch (e) { return Promise.reject(e); }
  523. }
  524. blob() {
  525. this.bodyUsed = true;
  526. return Promise.resolve(new Blob([this._b],
  527. { type: this.headers.get("content-type") || "" }));
  528. }
  529. arrayBuffer() { this.bodyUsed = true; return Promise.resolve(utf8(this._b).buffer); }
  530. formData() { return Promise.reject(new TypeError("formData() is not supported")); }
  531. clone() {
  532. return new Response(this._b, { status: this.status,
  533. statusText: this.statusText, url: this.url,
  534. headers: new Headers(this.headers) });
  535. }
  536. static json(data, init) {
  537. var h = new Headers(init && init.headers);
  538. h.set("content-type", "application/json");
  539. return new Response(JSON.stringify(data),
  540. Object.assign({}, init, { headers: h }));
  541. }
  542. static error() { return new Response(null, { status: 0 }); }
  543. static redirect(url, status) {
  544. return new Response(null, { status: status || 302,
  545. headers: { location: String(url) } });
  546. }
  547. }
  548. def("Response", Response);
  549. var STATUS_TEXT = { 200: "OK", 201: "Created", 204: "No Content",
  550. 301: "Moved Permanently", 302: "Found", 303: "See Other",
  551. 304: "Not Modified", 400: "Bad Request", 401: "Unauthorized",
  552. 403: "Forbidden", 404: "Not Found", 409: "Conflict", 410: "Gone",
  553. 500: "Internal Server Error", 502: "Bad Gateway",
  554. 503: "Service Unavailable" };
  555. /* One synchronous request through the browser's fetch helpers. */
  556. function send(method, url, headers, body) {
  557. var ct = headers.get("content-type");
  558. if (body instanceof URLSearchParams) {
  559. if (!ct) ct = "application/x-www-form-urlencoded;charset=UTF-8";
  560. body = body.toString();
  561. } else if (body instanceof FormData) {
  562. var sp = new URLSearchParams();
  563. body.forEach(function (v, k) {
  564. sp.append(k, typeof v === "string" ? v : "");
  565. });
  566. body = sp.toString();
  567. ct = "application/x-www-form-urlencoded;charset=UTF-8";
  568. } else if (body instanceof Blob) {
  569. if (!ct) ct = body.type;
  570. body = body._s;
  571. } else if (body != null && typeof body !== "string") {
  572. body = partText(body);
  573. } else if (typeof body === "string" && !ct) {
  574. ct = "text/plain;charset=UTF-8";
  575. }
  576. if (method === "GET" || method === "HEAD") body = null;
  577. var r = http(method, url, ct || "", body == null ? "" : body);
  578. var h = new Headers();
  579. if (r[1]) h.set("content-type", r[1]);
  580. return { status: r[0], headers: h, url: r[2] || url, text: r[3] };
  581. }
  582. def("fetch", function (input, init) {
  583. return new Promise(function (res, rej) {
  584. var req, out;
  585. try {
  586. req = new Request(input, init);
  587. } catch (e) {
  588. rej(e);
  589. return;
  590. }
  591. if (req.signal && req.signal.aborted) {
  592. rej(req.signal.reason);
  593. return;
  594. }
  595. try {
  596. out = send(req.method, req.url, req.headers, req.body);
  597. } catch (e) {
  598. rej(new TypeError("Failed to fetch"));
  599. return;
  600. }
  601. res(new Response(out.text, { status: out.status,
  602. statusText: STATUS_TEXT[out.status] || "",
  603. headers: out.headers, url: out.url,
  604. redirected: out.url !== req.url }));
  605. });
  606. });
  607. /* XMLHttpRequest on the same synchronous path; events fire asynchronously
  608. * (from a timer) so the caller can finish wiring its handlers. */
  609. class XMLHttpRequest {
  610. constructor() {
  611. this.readyState = 0;
  612. this.status = 0;
  613. this.statusText = "";
  614. this.responseText = "";
  615. this.response = "";
  616. this.responseType = "";
  617. this.responseURL = "";
  618. this.timeout = 0;
  619. this.withCredentials = false;
  620. this._h = new Headers();
  621. this._rh = new Headers();
  622. this._l = {};
  623. this.upload = { addEventListener: function () {} };
  624. }
  625. open(method, url) {
  626. this._m = String(method).toUpperCase();
  627. this._u = new URL(String(url), g.location.href).href;
  628. this.readyState = 1;
  629. }
  630. setRequestHeader(k, v) { this._h.append(k, v); }
  631. getResponseHeader(k) { return this._rh.get(k); }
  632. getAllResponseHeaders() {
  633. var s = "";
  634. this._rh.forEach(function (v, k) { s += k + ": " + v + "\r\n"; });
  635. return s;
  636. }
  637. overrideMimeType() {}
  638. addEventListener(t, f) { (this._l[t] = this._l[t] || []).push(f); }
  639. removeEventListener(t, f) {
  640. if (this._l[t]) this._l[t] = this._l[t].filter(function (x) { return x !== f; });
  641. }
  642. _fire(t) {
  643. var ev = { type: t, target: this, currentTarget: this,
  644. lengthComputable: false, loaded: 0, total: 0 };
  645. if (typeof this["on" + t] === "function") this["on" + t](ev);
  646. (this._l[t] || []).slice().forEach((f) => f.call(this, ev));
  647. }
  648. abort() { this._aborted = true; }
  649. send(body) {
  650. var self = this, out, err = false;
  651. try {
  652. out = send(this._m, this._u, this._h, body);
  653. } catch (e) {
  654. err = true;
  655. }
  656. setTimeout(function () {
  657. if (self._aborted) return;
  658. if (err) {
  659. self.readyState = 4;
  660. self._fire("readystatechange");
  661. self._fire("error");
  662. self._fire("loadend");
  663. return;
  664. }
  665. self.status = out.status;
  666. self.statusText = STATUS_TEXT[out.status] || "";
  667. self._rh = out.headers;
  668. self.responseURL = out.url;
  669. self.responseText = out.text;
  670. if (self.responseType === "json") {
  671. try { self.response = JSON.parse(out.text); }
  672. catch (e) { self.response = null; }
  673. } else {
  674. self.response = out.text;
  675. }
  676. self.readyState = 4;
  677. self._fire("readystatechange");
  678. self._fire("load");
  679. self._fire("loadend");
  680. }, 0);
  681. }
  682. }
  683. XMLHttpRequest.UNSENT = 0;
  684. XMLHttpRequest.OPENED = 1;
  685. XMLHttpRequest.HEADERS_RECEIVED = 2;
  686. XMLHttpRequest.LOADING = 3;
  687. XMLHttpRequest.DONE = 4;
  688. def("XMLHttpRequest", XMLHttpRequest);
  689. /* ---- Web Storage, persisted by the host per origin ---- */
  690. function makeStorage(kind) {
  691. var data = {};
  692. try {
  693. var t = storage(kind);
  694. if (t) data = JSON.parse(t) || {};
  695. } catch (e) {
  696. data = {};
  697. }
  698. function save() { storage(kind, JSON.stringify(data)); }
  699. var api = {
  700. getItem: function (k) {
  701. k = String(k);
  702. return hasOwn.call(data, k) ? data[k] : null;
  703. },
  704. setItem: function (k, v) { data[String(k)] = String(v); save(); },
  705. removeItem: function (k) { delete data[String(k)]; save(); },
  706. clear: function () { data = {}; save(); },
  707. key: function (i) {
  708. var k = Object.keys(data);
  709. return i < k.length ? k[i] : null;
  710. }
  711. };
  712. return new Proxy({}, {
  713. get: function (t, k) {
  714. if (typeof k === "symbol") return undefined;
  715. if (k === "length") return Object.keys(data).length;
  716. if (hasOwn.call(api, k)) return api[k];
  717. return hasOwn.call(data, k) ? data[k] : undefined;
  718. },
  719. set: function (t, k, v) {
  720. if (typeof k === "symbol") return true;
  721. data[k] = String(v);
  722. save();
  723. return true;
  724. },
  725. has: function (t, k) {
  726. return typeof k === "string" &&
  727. (k === "length" || hasOwn.call(api, k) || hasOwn.call(data, k));
  728. },
  729. deleteProperty: function (t, k) {
  730. if (typeof k === "string" && hasOwn.call(data, k)) {
  731. delete data[k];
  732. save();
  733. }
  734. return true;
  735. },
  736. ownKeys: function () { return Object.keys(data); },
  737. getOwnPropertyDescriptor: function (t, k) {
  738. if (typeof k === "string" && hasOwn.call(data, k))
  739. return { value: data[k], writable: true,
  740. enumerable: true, configurable: true };
  741. return undefined;
  742. }
  743. });
  744. }
  745. def("localStorage", makeStorage(0));
  746. def("sessionStorage", makeStorage(1));
  747. /* ---- crypto ---- */
  748. var K256 = [
  749. 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
  750. 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  751. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
  752. 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  753. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
  754. 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  755. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
  756. 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  757. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
  758. 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  759. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  760. function sha256(msg) {
  761. var h = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
  762. 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
  763. var len = msg.length, n = ((len + 9 + 63) >> 6) << 6;
  764. var b = new Uint8Array(n), w = new Array(64), i, j;
  765. b.set(msg);
  766. b[len] = 0x80;
  767. b[n - 4] = (len * 8) >>> 24;
  768. b[n - 3] = (len * 8) >>> 16 & 255;
  769. b[n - 2] = (len * 8) >>> 8 & 255;
  770. b[n - 1] = (len * 8) & 255;
  771. b[n - 5] = Math.floor(len / 0x20000000) & 255;
  772. function rotr(x, r) { return (x >>> r) | (x << (32 - r)); }
  773. for (i = 0; i < n; i += 64) {
  774. for (j = 0; j < 16; j++)
  775. w[j] = (b[i + 4 * j] << 24) | (b[i + 4 * j + 1] << 16) |
  776. (b[i + 4 * j + 2] << 8) | b[i + 4 * j + 3];
  777. for (j = 16; j < 64; j++) {
  778. var s0 = rotr(w[j - 15], 7) ^ rotr(w[j - 15], 18) ^ (w[j - 15] >>> 3);
  779. var s1 = rotr(w[j - 2], 17) ^ rotr(w[j - 2], 19) ^ (w[j - 2] >>> 10);
  780. w[j] = (w[j - 16] + s0 + w[j - 7] + s1) | 0;
  781. }
  782. var a = h[0], bb = h[1], c = h[2], d = h[3], e = h[4], f = h[5],
  783. gg = h[6], hh = h[7];
  784. for (j = 0; j < 64; j++) {
  785. var S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
  786. var ch = (e & f) ^ (~e & gg);
  787. var t1 = (hh + S1 + ch + K256[j] + w[j]) | 0;
  788. var S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
  789. var mj = (a & bb) ^ (a & c) ^ (bb & c);
  790. var t2 = (S0 + mj) | 0;
  791. hh = gg; gg = f; f = e; e = (d + t1) | 0;
  792. d = c; c = bb; bb = a; a = (t1 + t2) | 0;
  793. }
  794. h[0] = (h[0] + a) | 0; h[1] = (h[1] + bb) | 0;
  795. h[2] = (h[2] + c) | 0; h[3] = (h[3] + d) | 0;
  796. h[4] = (h[4] + e) | 0; h[5] = (h[5] + f) | 0;
  797. h[6] = (h[6] + gg) | 0; h[7] = (h[7] + hh) | 0;
  798. }
  799. var out = new Uint8Array(32);
  800. for (i = 0; i < 8; i++) {
  801. out[4 * i] = h[i] >>> 24;
  802. out[4 * i + 1] = h[i] >>> 16 & 255;
  803. out[4 * i + 2] = h[i] >>> 8 & 255;
  804. out[4 * i + 3] = h[i] & 255;
  805. }
  806. return out;
  807. }
  808. /* The entropy is weak (Math.random seeded from the clock, stirred with the
  809. * millisecond timer), like the TLS DRBG; fine for PKCE nonces on a hobby
  810. * OS, not for long-term keys. */
  811. var rngState = sha256(utf8(String(Date.now()) + ":" + Math.random() + ":" +
  812. g.performance.now()));
  813. var rngPos = 0;
  814. function randomByte() {
  815. if (rngPos >= 32) {
  816. var seed = new Uint8Array(40);
  817. seed.set(rngState);
  818. var t = g.performance.now() * 1000 + Math.random() * 4294967296;
  819. for (var i = 0; i < 8; i++)
  820. seed[32 + i] = Math.floor(t / Math.pow(256, i)) & 255;
  821. rngState = sha256(seed);
  822. rngPos = 0;
  823. }
  824. return rngState[rngPos++];
  825. }
  826. var subtle = {
  827. digest: function (alg, data) {
  828. var name = typeof alg === "string" ? alg : alg && alg.name;
  829. if (String(name).toUpperCase().replace("-", "") !== "SHA256")
  830. return Promise.reject(new DOMException(
  831. "Unsupported algorithm " + name, "NotSupportedError"));
  832. return Promise.resolve(sha256(bytesOf(data)).buffer);
  833. }
  834. };
  835. def("crypto", {
  836. subtle: subtle,
  837. getRandomValues: function (a) {
  838. var u = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
  839. for (var i = 0; i < u.length; i++) u[i] = randomByte();
  840. return a;
  841. },
  842. randomUUID: function () {
  843. var b = new Uint8Array(16), i, s = "";
  844. this.getRandomValues(b);
  845. b[6] = (b[6] & 0x0f) | 0x40;
  846. b[8] = (b[8] & 0x3f) | 0x80;
  847. for (i = 0; i < 16; i++) {
  848. s += (b[i] + 0x100).toString(16).slice(1);
  849. if (i === 3 || i === 5 || i === 7 || i === 9) s += "-";
  850. }
  851. return s;
  852. }
  853. });
  854. /* ---- observers (no layout notifications yet: inert) ---- */
  855. class MutationObserver {
  856. constructor(cb) { this._cb = cb; }
  857. observe() {}
  858. disconnect() {}
  859. takeRecords() { return []; }
  860. }
  861. class ResizeObserver {
  862. constructor(cb) { this._cb = cb; }
  863. observe() {}
  864. unobserve() {}
  865. disconnect() {}
  866. }
  867. class IntersectionObserver {
  868. constructor(cb, opts) { this._cb = cb; this.root = null; this.thresholds = [0]; }
  869. observe() {}
  870. unobserve() {}
  871. disconnect() {}
  872. takeRecords() { return []; }
  873. }
  874. def("MutationObserver", MutationObserver);
  875. def("ResizeObserver", ResizeObserver);
  876. def("IntersectionObserver", IntersectionObserver);
  877. /* ---- DOM classes: instanceof works on the node wrappers ---- */
  878. function domClass(name, test) {
  879. var C = function () { throw new TypeError("Illegal constructor"); };
  880. Object.defineProperty(C, "name", { value: name });
  881. Object.defineProperty(C, Symbol.hasInstance, {
  882. value: function (o) {
  883. return o != null && typeof o === "object" &&
  884. typeof o.nodeType === "number" && test(o);
  885. }
  886. });
  887. C.prototype = nodeproto;
  888. def(name, C);
  889. return C;
  890. }
  891. function tag(t) { return function (o) { return o.nodeType === 1 && o.tagName === t; }; }
  892. domClass("EventTarget", function (o) { return true; });
  893. domClass("Node", function (o) { return true; });
  894. domClass("Element", function (o) { return o.nodeType === 1; });
  895. domClass("HTMLElement", function (o) { return o.nodeType === 1; });
  896. domClass("SVGElement", function (o) { return o.nodeType === 1 && o.namespaceURI === "http://www.w3.org/2000/svg"; });
  897. domClass("CharacterData", function (o) { return o.nodeType === 3 || o.nodeType === 8; });
  898. domClass("Text", function (o) { return o.nodeType === 3; });
  899. domClass("Comment", function (o) { return o.nodeType === 8; });
  900. domClass("DocumentFragment", function (o) { return o.nodeType === 11; });
  901. domClass("Document", function (o) { return o.nodeType === 9; });
  902. domClass("HTMLDocument", function (o) { return o.nodeType === 9; });
  903. domClass("HTMLInputElement", tag("INPUT"));
  904. domClass("HTMLTextAreaElement", tag("TEXTAREA"));
  905. domClass("HTMLSelectElement", tag("SELECT"));
  906. domClass("HTMLOptionElement", tag("OPTION"));
  907. domClass("HTMLButtonElement", tag("BUTTON"));
  908. domClass("HTMLFormElement", tag("FORM"));
  909. domClass("HTMLAnchorElement", tag("A"));
  910. domClass("HTMLImageElement", tag("IMG"));
  911. domClass("HTMLTemplateElement", tag("TEMPLATE"));
  912. domClass("HTMLIFrameElement", tag("IFRAME"));
  913. domClass("HTMLLinkElement", tag("LINK"));
  914. domClass("HTMLScriptElement", tag("SCRIPT"));
  915. domClass("HTMLStyleElement", tag("STYLE"));
  916. domClass("HTMLCanvasElement", tag("CANVAS"));
  917. def("Window", function Window() {});
  918. def("ShadowRoot", function ShadowRoot() {});
  919. var NodeConst = g.Node;
  920. [["ELEMENT_NODE", 1], ["ATTRIBUTE_NODE", 2], ["TEXT_NODE", 3],
  921. ["CDATA_SECTION_NODE", 4], ["COMMENT_NODE", 8], ["DOCUMENT_NODE", 9],
  922. ["DOCUMENT_TYPE_NODE", 10], ["DOCUMENT_FRAGMENT_NODE", 11]]
  923. .forEach(function (p) { NodeConst[p[0]] = p[1]; });
  924. /* Methods every node wrapper inherits (the C has-hook answers the rest). */
  925. var doc = g.document;
  926. function toNode(n) {
  927. return typeof n === "object" && n !== null ? n : doc.createTextNode(String(n));
  928. }
  929. Object.assign(nodeproto, {
  930. setAttributeNS: function (ns, n, v) {
  931. this.setAttribute(String(n).replace(/^[^:]*:/, ""), v);
  932. },
  933. getAttributeNS: function (ns, n) { return this.getAttribute(n); },
  934. removeAttributeNS: function (ns, n) { this.removeAttribute(n); },
  935. hasAttributeNS: function (ns, n) { return this.hasAttribute(n); },
  936. toggleAttribute: function (n, force) {
  937. var on = force === undefined ? !this.hasAttribute(n) : !!force;
  938. if (on) this.setAttribute(n, "");
  939. else this.removeAttribute(n);
  940. return on;
  941. },
  942. getAttributeNames: function () {
  943. var a = this.attributes, out = [], i;
  944. for (i = 0; a && i < a.length; i++) out.push(a[i].name);
  945. return out;
  946. },
  947. closest: function (sel) {
  948. var e = this;
  949. while (e && e.nodeType === 1) {
  950. if (e.matches(sel)) return e;
  951. e = e.parentNode;
  952. }
  953. return null;
  954. },
  955. append: function () {
  956. for (var i = 0; i < arguments.length; i++)
  957. this.appendChild(toNode(arguments[i]));
  958. },
  959. prepend: function () {
  960. var first = this.firstChild;
  961. for (var i = 0; i < arguments.length; i++)
  962. this.insertBefore(toNode(arguments[i]), first);
  963. },
  964. before: function () {
  965. var p = this.parentNode;
  966. if (!p) return;
  967. for (var i = 0; i < arguments.length; i++)
  968. p.insertBefore(toNode(arguments[i]), this);
  969. },
  970. after: function () {
  971. var p = this.parentNode, next = this.nextSibling;
  972. if (!p) return;
  973. for (var i = 0; i < arguments.length; i++)
  974. p.insertBefore(toNode(arguments[i]), next);
  975. },
  976. replaceWith: function () {
  977. var p = this.parentNode;
  978. if (!p) return;
  979. this.before.apply(this, arguments);
  980. p.removeChild(this);
  981. },
  982. replaceChildren: function () {
  983. while (this.firstChild) this.removeChild(this.firstChild);
  984. this.append.apply(this, arguments);
  985. },
  986. insertAdjacentElement: function (pos, el) {
  987. pos = String(pos).toLowerCase();
  988. if (pos === "beforebegin") this.before(el);
  989. else if (pos === "afterbegin") this.prepend(el);
  990. else if (pos === "beforeend") this.appendChild(el);
  991. else if (pos === "afterend") this.after(el);
  992. return el;
  993. },
  994. insertAdjacentText: function (pos, text) {
  995. this.insertAdjacentElement(pos, doc.createTextNode(String(text)));
  996. },
  997. insertAdjacentHTML: function (pos, html) {
  998. var tmp = doc.createElement("div"), nodes = [], c;
  999. tmp.innerHTML = html;
  1000. for (c = tmp.firstChild; c; c = c.nextSibling) nodes.push(c);
  1001. pos = String(pos).toLowerCase();
  1002. if (pos === "afterbegin") nodes.reverse();
  1003. for (c of nodes) {
  1004. tmp.removeChild(c);
  1005. this.insertAdjacentElement(pos, c);
  1006. }
  1007. },
  1008. getRootNode: function () { return doc; },
  1009. scrollIntoView: function () {},
  1010. scrollTo: function () {},
  1011. scrollBy: function () {},
  1012. animate: function () {
  1013. return { finished: Promise.resolve(), cancel: function () {},
  1014. play: function () {}, pause: function () {},
  1015. onfinish: null };
  1016. },
  1017. attachShadow: function () { return this; },
  1018. compareDocumentPosition: function (other) {
  1019. if (this === other) return 0;
  1020. if (this.contains(other)) return 20;
  1021. if (other.contains && other.contains(this)) return 10;
  1022. return 4;
  1023. },
  1024. isSameNode: function (o) { return this === o; },
  1025. normalize: function () {}
  1026. });
  1027. /* ---- document extras ---- */
  1028. doc.createElementNS = function (ns, name) {
  1029. var el = doc.createElement(String(name).replace(/^[^:]*:/, ""));
  1030. if (ns === "http://www.w3.org/2000/svg")
  1031. el.setAttribute("xmlns", ns);
  1032. return el;
  1033. };
  1034. doc.createRange = function () {
  1035. return {
  1036. createContextualFragment: function (html) {
  1037. var tmp = doc.createElement("div"),
  1038. frag = doc.createDocumentFragment();
  1039. tmp.innerHTML = html;
  1040. while (tmp.firstChild) frag.appendChild(tmp.firstChild);
  1041. return frag;
  1042. },
  1043. selectNodeContents: function () {},
  1044. setStart: function () {}, setEnd: function () {},
  1045. getBoundingClientRect: function () {
  1046. return { x: 0, y: 0, top: 0, left: 0, right: 0, bottom: 0,
  1047. width: 0, height: 0 };
  1048. }
  1049. };
  1050. };
  1051. doc.createTreeWalker = undefined;
  1052. doc.hasFocus = function () { return true; };
  1053. doc.getElementsByName = function (n) {
  1054. return doc.querySelectorAll("[name=\"" + String(n).replace(/"/g, "\\\"") + "\"]");
  1055. };
  1056. doc.hidden = false;
  1057. doc.visibilityState = "visible";
  1058. doc.characterSet = "UTF-8";
  1059. doc.charset = "UTF-8";
  1060. doc.contentType = "text/html";
  1061. doc.referrer = "";
  1062. doc.dir = "";
  1063. doc.fonts = { ready: Promise.resolve(), add: function () {},
  1064. load: function () { return Promise.resolve([]); },
  1065. check: function () { return true; },
  1066. addEventListener: function () {} };
  1067. doc.implementation = {
  1068. hasFeature: function () { return true; },
  1069. createHTMLDocument: function () { return doc; }
  1070. };
  1071. Object.defineProperty(doc, "activeElement", {
  1072. get: function () { return doc.body; }, configurable: true });
  1073. Object.defineProperty(doc, "currentScript", {
  1074. get: function () { return null; }, configurable: true });
  1075. Object.defineProperty(doc, "defaultView", {
  1076. get: function () { return g; }, configurable: true });
  1077. var nav = g.navigator;
  1078. nav.languages = [nav.language];
  1079. nav.onLine = true;
  1080. nav.cookieEnabled = true;
  1081. nav.maxTouchPoints = 0;
  1082. nav.hardwareConcurrency = 1;
  1083. nav.vendor = "";
  1084. nav.clipboard = {
  1085. writeText: function () { return Promise.resolve(); },
  1086. readText: function () { return Promise.resolve(""); }
  1087. };
  1088. nav.sendBeacon = function () { return true; };
  1089. g.history.state = null;
  1090. g.screen = { width: g.innerWidth, height: g.innerHeight,
  1091. availWidth: g.innerWidth, availHeight: g.innerHeight,
  1092. colorDepth: 16, pixelDepth: 16 };
  1093. g.outerWidth = g.innerWidth;
  1094. g.outerHeight = g.innerHeight;
  1095. g.name = "";
  1096. g.closed = false;
  1097. g.open = function () { return null; };
  1098. g.close = function () {};
  1099. g.focus = function () {};
  1100. g.blur = function () {};
  1101. g.print = function () {};
  1102. g.postMessage = function () {};
  1103. g.confirm = function () { return true; };
  1104. g.prompt = function () { return null; };
  1105. g.dispatchEvent = g.dispatchEvent || function () { return true; };
  1106. })(globalThis);