js_prelude.js 76 KB

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