js_prelude.js 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  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. err = true;
  670. }
  671. setTimeout(function () {
  672. if (self._aborted) return;
  673. if (err) {
  674. self.readyState = 4;
  675. self._fire("readystatechange");
  676. self._fire("error");
  677. self._fire("loadend");
  678. return;
  679. }
  680. self.status = out.status;
  681. self.statusText = STATUS_TEXT[out.status] || "";
  682. self._rh = out.headers;
  683. self.responseURL = out.url;
  684. self.responseText = out.text;
  685. if (self.responseType === "json") {
  686. try { self.response = JSON.parse(out.text); }
  687. catch (e) { self.response = null; }
  688. } else {
  689. self.response = out.text;
  690. }
  691. self.readyState = 4;
  692. self._fire("readystatechange");
  693. self._fire("load");
  694. self._fire("loadend");
  695. }, 0);
  696. }
  697. }
  698. XMLHttpRequest.UNSENT = 0;
  699. XMLHttpRequest.OPENED = 1;
  700. XMLHttpRequest.HEADERS_RECEIVED = 2;
  701. XMLHttpRequest.LOADING = 3;
  702. XMLHttpRequest.DONE = 4;
  703. def("XMLHttpRequest", XMLHttpRequest);
  704. /* ---- Web Storage, persisted by the host per origin ---- */
  705. function makeStorage(kind) {
  706. var data = {};
  707. try {
  708. var t = storage(kind);
  709. if (t) data = JSON.parse(t) || {};
  710. } catch (e) {
  711. data = {};
  712. }
  713. function save() { storage(kind, JSON.stringify(data)); }
  714. var api = {
  715. getItem: function (k) {
  716. k = String(k);
  717. return hasOwn.call(data, k) ? data[k] : null;
  718. },
  719. setItem: function (k, v) { data[String(k)] = String(v); save(); },
  720. removeItem: function (k) { delete data[String(k)]; save(); },
  721. clear: function () { data = {}; save(); },
  722. key: function (i) {
  723. var k = Object.keys(data);
  724. return i < k.length ? k[i] : null;
  725. }
  726. };
  727. return new Proxy({}, {
  728. get: function (t, k) {
  729. if (typeof k === "symbol") return undefined;
  730. if (k === "length") return Object.keys(data).length;
  731. if (hasOwn.call(api, k)) return api[k];
  732. return hasOwn.call(data, k) ? data[k] : undefined;
  733. },
  734. set: function (t, k, v) {
  735. if (typeof k === "symbol") return true;
  736. data[k] = String(v);
  737. save();
  738. return true;
  739. },
  740. has: function (t, k) {
  741. return typeof k === "string" &&
  742. (k === "length" || hasOwn.call(api, k) || hasOwn.call(data, k));
  743. },
  744. deleteProperty: function (t, k) {
  745. if (typeof k === "string" && hasOwn.call(data, k)) {
  746. delete data[k];
  747. save();
  748. }
  749. return true;
  750. },
  751. ownKeys: function () { return Object.keys(data); },
  752. getOwnPropertyDescriptor: function (t, k) {
  753. if (typeof k === "string" && hasOwn.call(data, k))
  754. return { value: data[k], writable: true,
  755. enumerable: true, configurable: true };
  756. return undefined;
  757. }
  758. });
  759. }
  760. def("localStorage", makeStorage(0));
  761. def("sessionStorage", makeStorage(1));
  762. /* ---- crypto ---- */
  763. var K256 = [
  764. 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
  765. 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  766. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
  767. 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  768. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
  769. 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  770. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
  771. 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  772. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
  773. 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  774. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  775. function sha256(msg) {
  776. var h = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
  777. 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
  778. var len = msg.length, n = ((len + 9 + 63) >> 6) << 6;
  779. var b = new Uint8Array(n), w = new Array(64), i, j;
  780. b.set(msg);
  781. b[len] = 0x80;
  782. b[n - 4] = (len * 8) >>> 24;
  783. b[n - 3] = (len * 8) >>> 16 & 255;
  784. b[n - 2] = (len * 8) >>> 8 & 255;
  785. b[n - 1] = (len * 8) & 255;
  786. b[n - 5] = Math.floor(len / 0x20000000) & 255;
  787. function rotr(x, r) { return (x >>> r) | (x << (32 - r)); }
  788. for (i = 0; i < n; i += 64) {
  789. for (j = 0; j < 16; j++)
  790. w[j] = (b[i + 4 * j] << 24) | (b[i + 4 * j + 1] << 16) |
  791. (b[i + 4 * j + 2] << 8) | b[i + 4 * j + 3];
  792. for (j = 16; j < 64; j++) {
  793. var s0 = rotr(w[j - 15], 7) ^ rotr(w[j - 15], 18) ^ (w[j - 15] >>> 3);
  794. var s1 = rotr(w[j - 2], 17) ^ rotr(w[j - 2], 19) ^ (w[j - 2] >>> 10);
  795. w[j] = (w[j - 16] + s0 + w[j - 7] + s1) | 0;
  796. }
  797. var a = h[0], bb = h[1], c = h[2], d = h[3], e = h[4], f = h[5],
  798. gg = h[6], hh = h[7];
  799. for (j = 0; j < 64; j++) {
  800. var S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
  801. var ch = (e & f) ^ (~e & gg);
  802. var t1 = (hh + S1 + ch + K256[j] + w[j]) | 0;
  803. var S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
  804. var mj = (a & bb) ^ (a & c) ^ (bb & c);
  805. var t2 = (S0 + mj) | 0;
  806. hh = gg; gg = f; f = e; e = (d + t1) | 0;
  807. d = c; c = bb; bb = a; a = (t1 + t2) | 0;
  808. }
  809. h[0] = (h[0] + a) | 0; h[1] = (h[1] + bb) | 0;
  810. h[2] = (h[2] + c) | 0; h[3] = (h[3] + d) | 0;
  811. h[4] = (h[4] + e) | 0; h[5] = (h[5] + f) | 0;
  812. h[6] = (h[6] + gg) | 0; h[7] = (h[7] + hh) | 0;
  813. }
  814. var out = new Uint8Array(32);
  815. for (i = 0; i < 8; i++) {
  816. out[4 * i] = h[i] >>> 24;
  817. out[4 * i + 1] = h[i] >>> 16 & 255;
  818. out[4 * i + 2] = h[i] >>> 8 & 255;
  819. out[4 * i + 3] = h[i] & 255;
  820. }
  821. return out;
  822. }
  823. /* The entropy is weak (Math.random seeded from the clock, stirred with the
  824. * millisecond timer), like the TLS DRBG; fine for PKCE nonces on a hobby
  825. * OS, not for long-term keys. */
  826. var rngState = sha256(utf8(String(Date.now()) + ":" + Math.random() + ":" +
  827. g.performance.now()));
  828. var rngPos = 0;
  829. function randomByte() {
  830. if (rngPos >= 32) {
  831. var seed = new Uint8Array(40);
  832. seed.set(rngState);
  833. var t = g.performance.now() * 1000 + Math.random() * 4294967296;
  834. for (var i = 0; i < 8; i++)
  835. seed[32 + i] = Math.floor(t / Math.pow(256, i)) & 255;
  836. rngState = sha256(seed);
  837. rngPos = 0;
  838. }
  839. return rngState[rngPos++];
  840. }
  841. var subtle = {
  842. digest: function (alg, data) {
  843. var name = typeof alg === "string" ? alg : alg && alg.name;
  844. if (String(name).toUpperCase().replace("-", "") !== "SHA256")
  845. return Promise.reject(new DOMException(
  846. "Unsupported algorithm " + name, "NotSupportedError"));
  847. return Promise.resolve(sha256(bytesOf(data)).buffer);
  848. }
  849. };
  850. def("crypto", {
  851. subtle: subtle,
  852. getRandomValues: function (a) {
  853. var u = new Uint8Array(a.buffer, a.byteOffset, a.byteLength);
  854. for (var i = 0; i < u.length; i++) u[i] = randomByte();
  855. return a;
  856. },
  857. randomUUID: function () {
  858. var b = new Uint8Array(16), i, s = "";
  859. this.getRandomValues(b);
  860. b[6] = (b[6] & 0x0f) | 0x40;
  861. b[8] = (b[8] & 0x3f) | 0x80;
  862. for (i = 0; i < 16; i++) {
  863. s += (b[i] + 0x100).toString(16).slice(1);
  864. if (i === 3 || i === 5 || i === 7 || i === 9) s += "-";
  865. }
  866. return s;
  867. }
  868. });
  869. /* ---- observers (no layout notifications yet: inert) ---- */
  870. class MutationObserver {
  871. constructor(cb) { this._cb = cb; }
  872. observe() {}
  873. disconnect() {}
  874. takeRecords() { return []; }
  875. }
  876. class ResizeObserver {
  877. constructor(cb) { this._cb = cb; }
  878. observe() {}
  879. unobserve() {}
  880. disconnect() {}
  881. }
  882. /* Without scroll geometry every observed target is reported visible, once
  883. * per observe(): lazy loaders and "becomes visible" components (heise's
  884. * a-img) then load their content. Capped per page against infinite-scroll
  885. * sentinels that re-observe forever. */
  886. var ioBudget = 400;
  887. /* One timer drains every deferred callback: a page with hundreds of lazy
  888. * images would otherwise overflow the browser's timer table. */
  889. var laterQ = [], laterArmed = false;
  890. function later(f) {
  891. laterQ.push(f);
  892. if (laterArmed) return;
  893. laterArmed = true;
  894. setTimeout(function () {
  895. var q = laterQ, i;
  896. laterQ = [];
  897. laterArmed = false;
  898. for (i = 0; i < q.length; i++)
  899. try { q[i](); } catch (e) { con.error(e); }
  900. }, 0);
  901. }
  902. class IntersectionObserver {
  903. constructor(cb, opts) {
  904. this._cb = cb;
  905. this._t = [];
  906. this.root = (opts && opts.root) || null;
  907. this.rootMargin = (opts && opts.rootMargin) || "0px";
  908. this.thresholds = [0];
  909. }
  910. observe(t) {
  911. var self = this;
  912. if (!t || this._t.indexOf(t) >= 0 || ioBudget <= 0) return;
  913. ioBudget--;
  914. this._t.push(t);
  915. later(function () {
  916. if (self._t.indexOf(t) < 0) return;
  917. var r = t.getBoundingClientRect();
  918. self._cb([{ target: t, isIntersecting: true,
  919. intersectionRatio: 1, boundingClientRect: r,
  920. intersectionRect: r, rootBounds: null,
  921. time: g.performance.now() }], self);
  922. });
  923. }
  924. unobserve(t) { this._t = this._t.filter(function (x) { return x !== t; }); }
  925. disconnect() { this._t = []; }
  926. takeRecords() { return []; }
  927. }
  928. def("MutationObserver", MutationObserver);
  929. def("ResizeObserver", ResizeObserver);
  930. def("IntersectionObserver", IntersectionObserver);
  931. /* Present with isIntersecting/intersectionRatio on the prototype so the
  932. * common IntersectionObserver polyfill (bundled by heise) keeps ours. */
  933. class IntersectionObserverEntry {
  934. constructor(init) { Object.assign(this, init); }
  935. get isIntersecting() { return !!this._i; }
  936. get intersectionRatio() { return this._r || 0; }
  937. }
  938. def("IntersectionObserverEntry", IntersectionObserverEntry);
  939. /* ---- DOM classes: instanceof works on the node wrappers ---- */
  940. function domClass(name, test) {
  941. var C = function () { throw new TypeError("Illegal constructor"); };
  942. Object.defineProperty(C, "name", { value: name });
  943. Object.defineProperty(C, Symbol.hasInstance, {
  944. value: function (o) {
  945. return o != null && typeof o === "object" &&
  946. typeof o.nodeType === "number" && test(o);
  947. }
  948. });
  949. C.prototype = nodeproto;
  950. def(name, C);
  951. return C;
  952. }
  953. function tag(t) { return function (o) { return o.nodeType === 1 && o.tagName === t; }; }
  954. /* Real accessors and methods on the shared prototype for the members the
  955. * C hook answers. A wrapper's own lookup reaches the hook first, so these
  956. * only serve code that takes them from the prototype, like DOMPurify's
  957. * clobbering-safe `getOwnPropertyDescriptor(Node.prototype, "nodeName")
  958. * .get.call(node)`; without them it read every node as null and treated
  959. * the whole tree as detached. `busy` stops the recursion when the hook
  960. * does not know the name (or `this` is not a wrapper). */
  961. (function () {
  962. var busy = false;
  963. function own(name) {
  964. return Object.getOwnPropertyDescriptor(nodeproto, name);
  965. }
  966. ["nodeName", "nodeType", "parentNode", "nextSibling", "childNodes",
  967. "attributes"].forEach(function (name) {
  968. if (own(name)) return;
  969. Object.defineProperty(nodeproto, name, {
  970. configurable: true, enumerable: false,
  971. get: function () {
  972. if (busy) return undefined;
  973. busy = true;
  974. try { return this[name]; } finally { busy = false; }
  975. },
  976. set: function (v) {
  977. if (busy) return;
  978. busy = true;
  979. try { this[name] = v; } finally { busy = false; }
  980. }
  981. });
  982. });
  983. ["cloneNode", "remove", "removeAttributeNode"].forEach(function (name) {
  984. if (own(name)) return;
  985. Object.defineProperty(nodeproto, name, {
  986. configurable: true, enumerable: false, writable: true,
  987. value: function () {
  988. var f;
  989. if (busy) return undefined;
  990. busy = true;
  991. try { f = this[name]; } finally { busy = false; }
  992. if (typeof f !== "function" || f === nodeproto[name])
  993. return undefined;
  994. return f.apply(this, arguments);
  995. }
  996. });
  997. });
  998. })();
  999. domClass("EventTarget", function (o) { return true; });
  1000. domClass("Node", function (o) { return true; });
  1001. domClass("Element", function (o) { return o.nodeType === 1; });
  1002. domClass("HTMLElement", function (o) { return o.nodeType === 1; });
  1003. domClass("SVGElement", function (o) { return o.nodeType === 1 && o.namespaceURI === "http://www.w3.org/2000/svg"; });
  1004. domClass("CharacterData", function (o) { return o.nodeType === 3 || o.nodeType === 8; });
  1005. domClass("Text", function (o) { return o.nodeType === 3; });
  1006. domClass("Comment", function (o) { return o.nodeType === 8; });
  1007. domClass("DocumentFragment", function (o) { return o.nodeType === 11; });
  1008. domClass("Document", function (o) { return o.nodeType === 9; });
  1009. domClass("DocumentType", function (o) { return o.nodeType === 10; });
  1010. domClass("Attr", function (o) { return o.nodeType === 2; });
  1011. domClass("HTMLDocument", function (o) { return o.nodeType === 9; });
  1012. domClass("HTMLInputElement", tag("INPUT"));
  1013. domClass("HTMLTextAreaElement", tag("TEXTAREA"));
  1014. domClass("HTMLSelectElement", tag("SELECT"));
  1015. domClass("HTMLOptionElement", tag("OPTION"));
  1016. domClass("HTMLButtonElement", tag("BUTTON"));
  1017. domClass("HTMLFormElement", tag("FORM"));
  1018. domClass("HTMLAnchorElement", tag("A"));
  1019. domClass("HTMLImageElement", tag("IMG"));
  1020. domClass("HTMLTemplateElement", tag("TEMPLATE"));
  1021. domClass("HTMLIFrameElement", tag("IFRAME"));
  1022. domClass("HTMLLinkElement", tag("LINK"));
  1023. domClass("HTMLScriptElement", tag("SCRIPT"));
  1024. domClass("HTMLStyleElement", tag("STYLE"));
  1025. domClass("HTMLCanvasElement", tag("CANVAS"));
  1026. def("Window", function Window() {});
  1027. /* ---- Custom Elements ----
  1028. * A registered class adopts an existing element: HTMLElement, used as the
  1029. * base constructor, returns the element being upgraded (or a fresh one for
  1030. * `new MyElement()`) with its prototype switched to the subclass, the way
  1031. * the custom-elements polyfills do it. New elements are upgraded when
  1032. * created by script and by a scan after DOM changes (js_browser.c calls
  1033. * __nb_ce_scan from its tick); connectedCallback runs once the element is
  1034. * in the document. attributeChangedCallback fires for the observed
  1035. * attributes present at upgrade, not for later changes. */
  1036. var ceRegistry = new Map(), ceNames = new Map(), ceWaiters = new Map();
  1037. var cePending = [];
  1038. var createEl = g.document.createElement;
  1039. function HTMLElementCtor() {
  1040. var el = cePending.length ? cePending[cePending.length - 1] : null;
  1041. if (!el) {
  1042. var name = ceNames.get(new.target);
  1043. if (!name) throw new TypeError("Illegal constructor");
  1044. el = createEl.call(g.document, name);
  1045. }
  1046. Object.setPrototypeOf(el, new.target.prototype);
  1047. return el;
  1048. }
  1049. HTMLElementCtor.prototype = nodeproto;
  1050. Object.defineProperty(HTMLElementCtor, "name", { value: "HTMLElement" });
  1051. Object.defineProperty(HTMLElementCtor, Symbol.hasInstance, {
  1052. value: function (o) {
  1053. if (this !== HTMLElementCtor)
  1054. return Function.prototype[Symbol.hasInstance].call(this, o);
  1055. return o != null && typeof o === "object" && o.nodeType === 1;
  1056. }
  1057. });
  1058. def("HTMLElement", HTMLElementCtor);
  1059. function ceUpgrade(el) {
  1060. var C, obs, i;
  1061. if (!el || el.nodeType !== 1 || el.__nbce) return;
  1062. C = ceRegistry.get(el.localName);
  1063. if (!C) return;
  1064. el.__nbce = 1;
  1065. cePending.push(el);
  1066. try { new C(); } catch (e) { con.error(e); }
  1067. cePending.pop();
  1068. obs = C.observedAttributes;
  1069. if (obs && typeof el.attributeChangedCallback === "function")
  1070. for (i = 0; i < obs.length; i++)
  1071. if (el.hasAttribute(obs[i]))
  1072. try { el.attributeChangedCallback(obs[i], null, el.getAttribute(obs[i])); }
  1073. catch (e) { con.error(e); }
  1074. ceConnect(el);
  1075. }
  1076. function ceConnect(el) {
  1077. if (el.__nbceConn || !el.isConnected) return;
  1078. el.__nbceConn = 1;
  1079. if (typeof el.connectedCallback === "function") {
  1080. try {
  1081. var r = el.connectedCallback();
  1082. if (r && typeof r.then === "function")
  1083. r.then(null, function (e) { con.error(e); });
  1084. } catch (e) { con.error(e); }
  1085. }
  1086. }
  1087. function ceScan() {
  1088. ceRegistry.forEach(function (C, name) {
  1089. var list = g.document.querySelectorAll(name), i;
  1090. for (i = 0; i < list.length; i++) {
  1091. if (!list[i].__nbce) ceUpgrade(list[i]);
  1092. else ceConnect(list[i]);
  1093. }
  1094. });
  1095. }
  1096. def("__nb_ce_scan", function () { if (ceRegistry.size) ceScan(); });
  1097. def("customElements", {
  1098. define: function (name, C) {
  1099. name = String(name).toLowerCase();
  1100. if (ceRegistry.has(name))
  1101. throw new DOMException("'" + name + "' is already defined", "NotSupportedError");
  1102. ceRegistry.set(name, C);
  1103. ceNames.set(C, name);
  1104. ceScan();
  1105. var w = ceWaiters.get(name);
  1106. if (w) { w.forEach(function (f) { f(C); }); ceWaiters.delete(name); }
  1107. },
  1108. get: function (name) { return ceRegistry.get(String(name).toLowerCase()); },
  1109. getName: function (C) { return ceNames.get(C) || null; },
  1110. whenDefined: function (name) {
  1111. name = String(name).toLowerCase();
  1112. if (ceRegistry.has(name)) return Promise.resolve(ceRegistry.get(name));
  1113. return new Promise(function (res) {
  1114. if (!ceWaiters.has(name)) ceWaiters.set(name, []);
  1115. ceWaiters.get(name).push(res);
  1116. });
  1117. },
  1118. upgrade: function (root) {
  1119. ceUpgrade(root);
  1120. if (root && root.querySelectorAll) ceScan();
  1121. }
  1122. });
  1123. g.document.createElement = function (name, opts) {
  1124. var el = createEl.call(g.document, name);
  1125. var n = String(name).toLowerCase();
  1126. if (ceRegistry.has(n)) ceUpgrade(el);
  1127. if (n === "img") imgLoadShim(el);
  1128. return el;
  1129. };
  1130. /* Document collections (live: recomputed on every access). */
  1131. [["scripts", "script"], ["images", "img"], ["forms", "form"],
  1132. ["embeds", "embed"], ["links", "a[href],area[href]"]].forEach(function (p) {
  1133. Object.defineProperty(g.document, p[0], {
  1134. configurable: true,
  1135. get: function () {
  1136. return p[1].indexOf("[") >= 0 ?
  1137. g.document.querySelectorAll(p[1]) :
  1138. g.document.getElementsByTagName(p[1]);
  1139. }
  1140. });
  1141. });
  1142. /* Script-created images never really load in the page's DOM; fire "load"
  1143. * once a src is set so preload-then-swap code (load a detached <img>, then
  1144. * copy its URL) proceeds. The visible <img> is loaded by the browser. */
  1145. function imgLoadShim(el) {
  1146. later(function () {
  1147. if (el.getAttribute("src"))
  1148. el.dispatchEvent(new Event("load"));
  1149. });
  1150. }
  1151. def("Image", function Image(w, h) {
  1152. var el = g.document.createElement("img");
  1153. if (w !== undefined) el.setAttribute("width", String(w));
  1154. if (h !== undefined) el.setAttribute("height", String(h));
  1155. return el;
  1156. });
  1157. def("ShadowRoot", function ShadowRoot() {});
  1158. var NodeConst = g.Node;
  1159. [["ELEMENT_NODE", 1], ["ATTRIBUTE_NODE", 2], ["TEXT_NODE", 3],
  1160. ["CDATA_SECTION_NODE", 4], ["COMMENT_NODE", 8], ["DOCUMENT_NODE", 9],
  1161. ["DOCUMENT_TYPE_NODE", 10], ["DOCUMENT_FRAGMENT_NODE", 11]]
  1162. .forEach(function (p) { NodeConst[p[0]] = p[1]; });
  1163. /* Methods every node wrapper inherits (the C has-hook answers the rest). */
  1164. var doc = g.document;
  1165. /* <template>.content: the parser keeps a template's children in the tree
  1166. * (hidden); the first access moves them into a fragment, which Alpine's
  1167. * x-for/x-if/x-teleport clone. */
  1168. Object.defineProperty(nodeproto, "content", { configurable: true,
  1169. get: function () {
  1170. if (this.nodeType !== 1 || this.tagName !== "TEMPLATE")
  1171. return undefined;
  1172. if (!this.__nb_tc) {
  1173. var f = doc.createDocumentFragment();
  1174. while (this.firstChild)
  1175. f.appendChild(this.firstChild);
  1176. this.__nb_tc = f;
  1177. }
  1178. return this.__nb_tc;
  1179. } });
  1180. function toNode(n) {
  1181. return typeof n === "object" && n !== null ? n : doc.createTextNode(String(n));
  1182. }
  1183. Object.assign(nodeproto, {
  1184. setAttributeNS: function (ns, n, v) {
  1185. this.setAttribute(String(n).replace(/^[^:]*:/, ""), v);
  1186. },
  1187. getAttributeNS: function (ns, n) { return this.getAttribute(n); },
  1188. removeAttributeNS: function (ns, n) { this.removeAttribute(n); },
  1189. hasAttributeNS: function (ns, n) { return this.hasAttribute(n); },
  1190. toggleAttribute: function (n, force) {
  1191. var on = force === undefined ? !this.hasAttribute(n) : !!force;
  1192. if (on) this.setAttribute(n, "");
  1193. else this.removeAttribute(n);
  1194. return on;
  1195. },
  1196. getAttributeNames: function () {
  1197. var a = this.attributes, out = [], i;
  1198. for (i = 0; a && i < a.length; i++) out.push(a[i].name);
  1199. return out;
  1200. },
  1201. closest: function (sel) {
  1202. var e = this;
  1203. while (e && e.nodeType === 1) {
  1204. if (e.matches(sel)) return e;
  1205. e = e.parentNode;
  1206. }
  1207. return null;
  1208. },
  1209. append: function () {
  1210. for (var i = 0; i < arguments.length; i++)
  1211. this.appendChild(toNode(arguments[i]));
  1212. },
  1213. prepend: function () {
  1214. var first = this.firstChild;
  1215. for (var i = 0; i < arguments.length; i++)
  1216. this.insertBefore(toNode(arguments[i]), first);
  1217. },
  1218. before: function () {
  1219. var p = this.parentNode;
  1220. if (!p) return;
  1221. for (var i = 0; i < arguments.length; i++)
  1222. p.insertBefore(toNode(arguments[i]), this);
  1223. },
  1224. after: function () {
  1225. var p = this.parentNode, next = this.nextSibling;
  1226. if (!p) return;
  1227. for (var i = 0; i < arguments.length; i++)
  1228. p.insertBefore(toNode(arguments[i]), next);
  1229. },
  1230. replaceWith: function () {
  1231. var p = this.parentNode;
  1232. if (!p) return;
  1233. this.before.apply(this, arguments);
  1234. p.removeChild(this);
  1235. },
  1236. replaceChildren: function () {
  1237. while (this.firstChild) this.removeChild(this.firstChild);
  1238. this.append.apply(this, arguments);
  1239. },
  1240. insertAdjacentElement: function (pos, el) {
  1241. pos = String(pos).toLowerCase();
  1242. if (pos === "beforebegin") this.before(el);
  1243. else if (pos === "afterbegin") this.prepend(el);
  1244. else if (pos === "beforeend") this.appendChild(el);
  1245. else if (pos === "afterend") this.after(el);
  1246. return el;
  1247. },
  1248. insertAdjacentText: function (pos, text) {
  1249. this.insertAdjacentElement(pos, doc.createTextNode(String(text)));
  1250. },
  1251. insertAdjacentHTML: function (pos, html) {
  1252. var tmp = doc.createElement("div"), nodes = [], c;
  1253. tmp.innerHTML = html;
  1254. for (c = tmp.firstChild; c; c = c.nextSibling) nodes.push(c);
  1255. pos = String(pos).toLowerCase();
  1256. if (pos === "afterbegin") nodes.reverse();
  1257. for (c of nodes) {
  1258. tmp.removeChild(c);
  1259. this.insertAdjacentElement(pos, c);
  1260. }
  1261. },
  1262. getRootNode: function () { return doc; },
  1263. scrollIntoView: function () {},
  1264. scrollTo: function () {},
  1265. scrollBy: function () {},
  1266. animate: function () {
  1267. return { finished: Promise.resolve(), cancel: function () {},
  1268. play: function () {}, pause: function () {},
  1269. onfinish: null };
  1270. },
  1271. attachShadow: function () { return this; },
  1272. compareDocumentPosition: function (other) {
  1273. if (this === other) return 0;
  1274. if (this.contains(other)) return 20;
  1275. if (other.contains && other.contains(this)) return 10;
  1276. return 4;
  1277. },
  1278. isSameNode: function (o) { return this === o; },
  1279. normalize: function () {}
  1280. });
  1281. /* ---- document extras ---- */
  1282. doc.createElementNS = function (ns, name) {
  1283. var el = doc.createElement(String(name).replace(/^[^:]*:/, ""));
  1284. if (ns === "http://www.w3.org/2000/svg")
  1285. el.setAttribute("xmlns", ns);
  1286. return el;
  1287. };
  1288. doc.createRange = function () {
  1289. return {
  1290. createContextualFragment: function (html) {
  1291. var tmp = doc.createElement("div"),
  1292. frag = doc.createDocumentFragment();
  1293. tmp.innerHTML = html;
  1294. while (tmp.firstChild) frag.appendChild(tmp.firstChild);
  1295. return frag;
  1296. },
  1297. selectNodeContents: function () {},
  1298. setStart: function () {}, setEnd: function () {},
  1299. getBoundingClientRect: function () {
  1300. return { x: 0, y: 0, top: 0, left: 0, right: 0, bottom: 0,
  1301. width: 0, height: 0 };
  1302. }
  1303. };
  1304. };
  1305. doc.createTreeWalker = undefined;
  1306. /* NodeIterator over a snapshot of the subtree in document order. A node
  1307. * removed from the root meanwhile is skipped, and the children a sanitizer
  1308. * hoists out of a removed element are still visited, which is what
  1309. * DOMPurify (the Cloudron dashboard's markdown) relies on. */
  1310. def("NodeFilter", {
  1311. FILTER_ACCEPT: 1, FILTER_REJECT: 2, FILTER_SKIP: 3,
  1312. SHOW_ALL: 0xFFFFFFFF, SHOW_ELEMENT: 0x1, SHOW_ATTRIBUTE: 0x2,
  1313. SHOW_TEXT: 0x4, SHOW_CDATA_SECTION: 0x8,
  1314. SHOW_PROCESSING_INSTRUCTION: 0x40, SHOW_COMMENT: 0x80,
  1315. SHOW_DOCUMENT: 0x100, SHOW_DOCUMENT_TYPE: 0x200,
  1316. SHOW_DOCUMENT_FRAGMENT: 0x400
  1317. });
  1318. doc.createNodeIterator = function (root, what, filter) {
  1319. var list = [], stack = [root], i = -1, n, c, kids;
  1320. what = what === undefined ? 0xFFFFFFFF : what >>> 0;
  1321. while (stack.length) {
  1322. n = stack.pop();
  1323. list.push(n);
  1324. kids = [];
  1325. for (c = n.firstChild; c; c = c.nextSibling) kids.push(c);
  1326. while (kids.length) stack.push(kids.pop());
  1327. }
  1328. function shown(x) {
  1329. var t = x.nodeType || 1, r;
  1330. if (t > 32 || !(what & (1 << (t - 1)))) return false;
  1331. if (!filter) return true;
  1332. r = typeof filter === "function" ? filter(x) : filter.acceptNode(x);
  1333. return r === 1;
  1334. }
  1335. function inside(x) { return x === root || root.contains(x); }
  1336. return {
  1337. root: root, whatToShow: what, filter: filter || null,
  1338. referenceNode: root, pointerBeforeReferenceNode: true,
  1339. nextNode: function () {
  1340. while (++i < list.length)
  1341. if (inside(list[i]) && shown(list[i]))
  1342. return (this.referenceNode = list[i]);
  1343. i = list.length;
  1344. return null;
  1345. },
  1346. previousNode: function () {
  1347. while (--i >= 0)
  1348. if (inside(list[i]) && shown(list[i]))
  1349. return (this.referenceNode = list[i]);
  1350. i = -1;
  1351. return null;
  1352. },
  1353. detach: function () {}
  1354. };
  1355. };
  1356. doc.hasFocus = function () { return true; };
  1357. doc.getElementsByName = function (n) {
  1358. return doc.querySelectorAll("[name=\"" + String(n).replace(/"/g, "\\\"") + "\"]");
  1359. };
  1360. doc.hidden = false;
  1361. doc.visibilityState = "visible";
  1362. doc.characterSet = "UTF-8";
  1363. doc.charset = "UTF-8";
  1364. doc.contentType = "text/html";
  1365. doc.referrer = "";
  1366. doc.dir = "";
  1367. doc.fonts = { ready: Promise.resolve(), add: function () {},
  1368. load: function () { return Promise.resolve([]); },
  1369. check: function () { return true; },
  1370. addEventListener: function () {} };
  1371. /* A separate inert document (jQuery's parseHTML context, DOMPurify): its
  1372. * nodes live in the page's node arena but are detached, so writing to its
  1373. * body never touches the page. Returning the page document here made
  1374. * jQuery's support probe replace the whole page body with two <form>s. */
  1375. function nbInertDocument(title) {
  1376. var html = doc.createElement("html"), head = doc.createElement("head");
  1377. var body = doc.createElement("body"), d;
  1378. html.appendChild(head);
  1379. html.appendChild(body);
  1380. if (title !== undefined) {
  1381. var t = doc.createElement("title");
  1382. t.textContent = String(title);
  1383. head.appendChild(t);
  1384. }
  1385. d = {
  1386. __nbInert: true,
  1387. nodeType: 9, nodeName: "#document", documentElement: html,
  1388. head: head, body: body, readyState: "complete",
  1389. compatMode: "CSS1Compat", characterSet: "UTF-8",
  1390. contentType: "text/html", defaultView: null, location: null,
  1391. cookie: "", URL: "about:blank", baseURI: doc.URL,
  1392. addEventListener: function () {},
  1393. removeEventListener: function () {},
  1394. querySelector: function (s) { return html.querySelector(s); },
  1395. querySelectorAll: function (s) { return html.querySelectorAll(s); },
  1396. getElementsByTagName: function (s) {
  1397. return html.getElementsByTagName(s);
  1398. },
  1399. getElementsByClassName: function (s) {
  1400. return html.getElementsByClassName(s);
  1401. },
  1402. getElementById: function (id) {
  1403. return html.querySelector("[id=\"" +
  1404. String(id).replace(/"/g, "\\\"") + "\"]");
  1405. }
  1406. };
  1407. ["createElement", "createTextNode", "createComment",
  1408. "createDocumentFragment", "createAttribute", "createEvent"].forEach(
  1409. function (m) {
  1410. d[m] = function () { return doc[m].apply(doc, arguments); };
  1411. });
  1412. d.createElementNS = function (ns, n) { return doc.createElement(n); };
  1413. d.implementation = doc.implementation;
  1414. Object.defineProperty(d, "title", { configurable: true,
  1415. get: function () {
  1416. var t = head.querySelector("title");
  1417. return t ? t.textContent : "";
  1418. } });
  1419. return d;
  1420. }
  1421. /* The page document's lookups called on an inert document
  1422. * (`document.getElementsByTagName.call(parsed, "body")`, as DOMPurify does)
  1423. * answer for that document: searching the page instead handed DOMPurify the
  1424. * real <body> to sanitize, and it emptied the page. */
  1425. ["getElementsByTagName", "getElementsByClassName", "querySelector",
  1426. "querySelectorAll", "getElementById"].forEach(function (m) {
  1427. var f = doc[m];
  1428. if (typeof f !== "function") return;
  1429. doc[m] = function () {
  1430. if (this && this !== doc && this.__nbInert)
  1431. return this[m].apply(this, arguments);
  1432. return f.apply(doc, arguments);
  1433. };
  1434. });
  1435. doc.implementation = {
  1436. hasFeature: function () { return true; },
  1437. createHTMLDocument: function (title) { return nbInertDocument(title); }
  1438. };
  1439. /* DOMParser on the same inert document: the markup goes through the
  1440. * innerHTML fragment parser. A whole document is split at its <head> and
  1441. * <body>, so the parsed body holds the body's children and not a nested
  1442. * copy of the <html>/<head>/<body> elements. */
  1443. if (!g.DOMParser) {
  1444. g.DOMParser = function DOMParser() {};
  1445. g.DOMParser.prototype.parseFromString = function (str) {
  1446. var d = nbInertDocument(), s = String(str), m;
  1447. s = s.replace(/<!doctype[^>]*>/i, "");
  1448. m = /<head(\s[^>]*)?>([\s\S]*?)<\/head>/i.exec(s);
  1449. if (m) {
  1450. d.head.innerHTML = m[2];
  1451. s = s.slice(0, m.index) + s.slice(m.index + m[0].length);
  1452. }
  1453. m = /<body(\s[^>]*)?>([\s\S]*?)(<\/body>|$)/i.exec(s);
  1454. s = m ? m[2] : s.replace(/<\/?html(\s[^>]*)?>/gi, "");
  1455. d.body.innerHTML = s;
  1456. return d;
  1457. };
  1458. }
  1459. Object.defineProperty(doc, "activeElement", {
  1460. get: function () { return doc.body; }, configurable: true });
  1461. Object.defineProperty(doc, "defaultView", {
  1462. get: function () { return g; }, configurable: true });
  1463. var nav = g.navigator;
  1464. nav.languages = [nav.language];
  1465. nav.onLine = true;
  1466. nav.cookieEnabled = true;
  1467. nav.maxTouchPoints = 0;
  1468. nav.hardwareConcurrency = 1;
  1469. nav.vendor = "";
  1470. nav.clipboard = {
  1471. writeText: function () { return Promise.resolve(); },
  1472. readText: function () { return Promise.resolve(""); }
  1473. };
  1474. nav.sendBeacon = function () { return true; };
  1475. /* ---- performance: a page-relative clock, User Timing, no resources ----
  1476. * The C side's now() counts from boot; pages expect milliseconds since the
  1477. * navigation (google.com adds it to timing.navigationStart). mark()/
  1478. * measure() keep a small timeline that getEntries*() search; resource and
  1479. * navigation entries are never recorded, so those lists are empty.
  1480. * google.com's results script calls performance.mark/measure/clearMarks
  1481. * around every render and getEntriesByType("resource") in its CSI ping;
  1482. * both threw "not a function" before. */
  1483. (function () {
  1484. var perf = g.performance, rawNow = perf.now, base = rawNow.call(perf);
  1485. var origin = Date.now(), timeline = [];
  1486. function now() { return rawNow.call(perf) - base; }
  1487. function at(v) {
  1488. if (typeof v === "number") return v;
  1489. if (typeof v === "string") {
  1490. for (var i = timeline.length - 1; i >= 0; i--)
  1491. if (timeline[i].entryType === "mark" &&
  1492. timeline[i].name === v)
  1493. return timeline[i].startTime;
  1494. throw new SyntaxError("The mark '" + v + "' does not exist.");
  1495. }
  1496. return undefined;
  1497. }
  1498. function entry(name, type, start, duration, detail) {
  1499. var e = { name: String(name), entryType: type, startTime: start,
  1500. duration: duration, detail: detail === undefined ?
  1501. null : detail };
  1502. e.toJSON = function () { return Object.assign({}, this); };
  1503. timeline.push(e);
  1504. if (timeline.length > 1000) timeline.shift();
  1505. return e;
  1506. }
  1507. function clear(type, name) {
  1508. timeline = timeline.filter(function (e) {
  1509. return e.entryType !== type ||
  1510. (name !== undefined && e.name !== name);
  1511. });
  1512. }
  1513. perf.now = now;
  1514. perf.timeOrigin = origin;
  1515. perf.timing = {
  1516. navigationStart: origin, fetchStart: origin,
  1517. requestStart: origin, responseStart: origin,
  1518. responseEnd: origin, domLoading: origin,
  1519. domInteractive: origin, domContentLoadedEventStart: origin,
  1520. domContentLoadedEventEnd: origin, domComplete: origin,
  1521. loadEventStart: origin, loadEventEnd: origin,
  1522. toJSON: function () { return Object.assign({}, this); }
  1523. };
  1524. perf.navigation = { type: 0, redirectCount: 0 };
  1525. perf.mark = function (name, opts) {
  1526. opts = opts || {};
  1527. return entry(name, "mark", opts.startTime !== undefined ?
  1528. opts.startTime : now(), 0, opts.detail);
  1529. };
  1530. perf.measure = function (name, start, end) {
  1531. var s = 0, e = now(), detail;
  1532. if (start && typeof start === "object") {
  1533. detail = start.detail;
  1534. if (start.start !== undefined) s = at(start.start);
  1535. if (start.end !== undefined) e = at(start.end);
  1536. if (start.duration !== undefined) {
  1537. if (start.start !== undefined) e = s + start.duration;
  1538. else s = e - start.duration;
  1539. }
  1540. } else {
  1541. if (start !== undefined) s = at(start);
  1542. if (end !== undefined) e = at(end);
  1543. }
  1544. return entry(name, "measure", s, e - s, detail);
  1545. };
  1546. perf.clearMarks = function (name) { clear("mark", name); };
  1547. perf.clearMeasures = function (name) { clear("measure", name); };
  1548. perf.clearResourceTimings = function () {};
  1549. perf.setResourceTimingBufferSize = function () {};
  1550. perf.getEntries = function () { return timeline.slice(); };
  1551. perf.getEntriesByType = function (type) {
  1552. return timeline.filter(function (e) { return e.entryType === type; });
  1553. };
  1554. perf.getEntriesByName = function (name, type) {
  1555. return timeline.filter(function (e) {
  1556. return e.name === name &&
  1557. (type === undefined || e.entryType === type);
  1558. });
  1559. };
  1560. perf.toJSON = function () {
  1561. return { timeOrigin: origin, timing: perf.timing.toJSON() };
  1562. };
  1563. })();
  1564. class PerformanceObserver {
  1565. constructor(cb) { this._cb = cb; }
  1566. observe() {}
  1567. disconnect() {}
  1568. takeRecords() { return []; }
  1569. }
  1570. PerformanceObserver.supportedEntryTypes = [];
  1571. def("PerformanceObserver", PerformanceObserver);
  1572. /* ---- CSS namespace ----
  1573. * escape() is the CSSOM serialization of an identifier; supports() gives
  1574. * the cascade's own @supports answer (true unless it asks for selector()),
  1575. * so scripts and stylesheets agree. */
  1576. def("CSS", {
  1577. escape: function (value) {
  1578. var s = String(value), out = "", i, c, first = s.charCodeAt(0);
  1579. if (s.length === 1 && first === 0x2D) return "\\-";
  1580. for (i = 0; i < s.length; i++) {
  1581. c = s.charCodeAt(i);
  1582. if (c === 0) out += "�";
  1583. else if ((c >= 0x01 && c <= 0x1F) || c === 0x7F ||
  1584. (i === 0 && c >= 0x30 && c <= 0x39) ||
  1585. (i === 1 && c >= 0x30 && c <= 0x39 &&
  1586. first === 0x2D))
  1587. out += "\\" + c.toString(16) + " ";
  1588. else if (c >= 0x80 || c === 0x2D || c === 0x5F ||
  1589. (c >= 0x30 && c <= 0x39) ||
  1590. (c >= 0x41 && c <= 0x5A) ||
  1591. (c >= 0x61 && c <= 0x7A))
  1592. out += s.charAt(i);
  1593. else
  1594. out += "\\" + s.charAt(i);
  1595. }
  1596. return out;
  1597. },
  1598. supports: function (prop, value) {
  1599. var q = arguments.length > 1 ? String(prop) + ":" + String(value) :
  1600. String(prop);
  1601. return !/selector\s*\(/i.test(q) && !/^\s*not\s/i.test(q);
  1602. }
  1603. });
  1604. g.history.state = null;
  1605. g.screen = { width: g.innerWidth, height: g.innerHeight,
  1606. availWidth: g.innerWidth, availHeight: g.innerHeight,
  1607. colorDepth: 16, pixelDepth: 16 };
  1608. g.outerWidth = g.innerWidth;
  1609. g.outerHeight = g.innerHeight;
  1610. g.name = "";
  1611. g.closed = false;
  1612. g.open = function () { return null; };
  1613. g.close = function () {};
  1614. g.focus = function () {};
  1615. g.blur = function () {};
  1616. g.print = function () {};
  1617. g.postMessage = function () {};
  1618. g.confirm = function () { return true; };
  1619. g.prompt = function () { return null; };
  1620. /* Parsed <template> children are inert in a browser: move them into each
  1621. * template's content fragment before the page's scripts walk the tree
  1622. * (Alpine would otherwise initialise them in place, in the wrong scope). */
  1623. (function () {
  1624. var tl = doc.getElementsByTagName("template"), a = [], i;
  1625. for (i = 0; i < tl.length; i++)
  1626. a.push(tl[i]);
  1627. for (i = 0; i < a.length; i++)
  1628. void a[i].content;
  1629. })();
  1630. })(globalThis);