jaxs 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/.env +1 -0
  2. package/.parcel-cache/6f14daf302269614-BundleGraph-0 +0 -0
  3. package/.parcel-cache/7d3d872b02d671a6-AssetGraph-0 +0 -0
  4. package/.parcel-cache/8e029bb14f8992df-RequestGraph-0 +0 -0
  5. package/.parcel-cache/a5394978e4ece10b-AssetGraph-0 +0 -0
  6. package/.parcel-cache/b5686051ae060930.txt +2 -0
  7. package/.parcel-cache/data.mdb +0 -0
  8. package/.parcel-cache/lock.mdb +0 -0
  9. package/README.md +15 -0
  10. package/bun.lockb +0 -0
  11. package/bundle.ts +5 -0
  12. package/bunfig.toml +0 -0
  13. package/cypress/e2e/add-remove-nested-children.cy.js +39 -0
  14. package/cypress/e2e/add-remove-root-children.cy.js +37 -0
  15. package/cypress/jaxs-apps/add-remove-nested-children.html +12 -0
  16. package/cypress/jaxs-apps/add-remove-nested-children.jsx +84 -0
  17. package/cypress/jaxs-apps/add-remove-root-children.html +15 -0
  18. package/cypress/jaxs-apps/add-remove-root-children.jsx +53 -0
  19. package/cypress/jaxs-apps/dist/add-remove-nested-children.afcab974.js +717 -0
  20. package/cypress/jaxs-apps/dist/add-remove-nested-children.afcab974.js.map +1 -0
  21. package/cypress/jaxs-apps/dist/add-remove-nested-children.html +12 -0
  22. package/cypress/jaxs-apps/dist/add-remove-root-children.3bb9b3f5.js +1682 -0
  23. package/cypress/jaxs-apps/dist/add-remove-root-children.3bb9b3f5.js.map +1 -0
  24. package/cypress/jaxs-apps/dist/add-remove-root-children.fbb4ec9b.js +706 -0
  25. package/cypress/jaxs-apps/dist/add-remove-root-children.fbb4ec9b.js.map +1 -0
  26. package/cypress/jaxs-apps/dist/add-remove-root-children.html +15 -0
  27. package/cypress/support/commands.js +25 -0
  28. package/cypress/support/e2e.js +20 -0
  29. package/cypress.config.js +10 -0
  30. package/dist/jaxs.js +1154 -0
  31. package/package.json +38 -0
  32. package/src/app.ts +64 -0
  33. package/src/debugging.js +5 -0
  34. package/src/jaxs.ts +8 -0
  35. package/src/jsx.js +27 -0
  36. package/src/messageBus.ts +70 -0
  37. package/src/navigation/findHref.js +10 -0
  38. package/src/navigation/routeState.js +15 -0
  39. package/src/navigation/setupHistory.js +38 -0
  40. package/src/navigation/setupNavigation.js +25 -0
  41. package/src/navigation.ts +2 -0
  42. package/src/rendering/change/compile.ts +1 -0
  43. package/src/rendering/change/instructions/attributes.ts +78 -0
  44. package/src/rendering/change/instructions/children.ts +128 -0
  45. package/src/rendering/change/instructions/element.ts +42 -0
  46. package/src/rendering/change/instructions/events.ts +51 -0
  47. package/src/rendering/change/instructions/generate.ts +122 -0
  48. package/src/rendering/change/instructions/idMap.js +55 -0
  49. package/src/rendering/change/instructions/node.ts +38 -0
  50. package/src/rendering/change/instructions/text.ts +10 -0
  51. package/src/rendering/change.ts +131 -0
  52. package/src/rendering/dom/attributesAndEvents.ts +33 -0
  53. package/src/rendering/dom/create.ts +68 -0
  54. package/src/rendering/templates/bound.js +55 -0
  55. package/src/rendering/templates/children.ts +91 -0
  56. package/src/rendering/templates/root.ts +55 -0
  57. package/src/rendering/templates/tag.ts +70 -0
  58. package/src/rendering/templates/text.ts +17 -0
  59. package/src/state/equality.js +36 -0
  60. package/src/state/stores.js +63 -0
  61. package/src/state/testingTypes.js +6 -0
  62. package/src/state.js +89 -0
  63. package/src/types.ts +149 -0
  64. package/src/views/conditionals.jsx +18 -0
  65. package/src/views/link.jsx +5 -0
  66. package/src/views.js +7 -0
  67. package/tsconfig.json +26 -0
@@ -0,0 +1,1682 @@
1
+ // modules are defined as an array
2
+ // [ module function, map of requires ]
3
+ //
4
+ // map of requires is short require name -> numeric require
5
+ //
6
+ // anything defined in a previous bundle is accessed via the
7
+ // orig method which is the require for previous bundles
8
+
9
+ (function (modules, entry, mainEntry, parcelRequireName, globalName) {
10
+ /* eslint-disable no-undef */
11
+ var globalObject =
12
+ typeof globalThis !== 'undefined'
13
+ ? globalThis
14
+ : typeof self !== 'undefined'
15
+ ? self
16
+ : typeof window !== 'undefined'
17
+ ? window
18
+ : typeof global !== 'undefined'
19
+ ? global
20
+ : {};
21
+ /* eslint-enable no-undef */
22
+
23
+ // Save the require from previous bundle to this closure if any
24
+ var previousRequire =
25
+ typeof globalObject[parcelRequireName] === 'function' &&
26
+ globalObject[parcelRequireName];
27
+
28
+ var cache = previousRequire.cache || {};
29
+ // Do not use `require` to prevent Webpack from trying to bundle this call
30
+ var nodeRequire =
31
+ typeof module !== 'undefined' &&
32
+ typeof module.require === 'function' &&
33
+ module.require.bind(module);
34
+
35
+ function newRequire(name, jumped) {
36
+ if (!cache[name]) {
37
+ if (!modules[name]) {
38
+ // if we cannot find the module within our internal map or
39
+ // cache jump to the current global require ie. the last bundle
40
+ // that was added to the page.
41
+ var currentRequire =
42
+ typeof globalObject[parcelRequireName] === 'function' &&
43
+ globalObject[parcelRequireName];
44
+ if (!jumped && currentRequire) {
45
+ return currentRequire(name, true);
46
+ }
47
+
48
+ // If there are other bundles on this page the require from the
49
+ // previous one is saved to 'previousRequire'. Repeat this as
50
+ // many times as there are bundles until the module is found or
51
+ // we exhaust the require chain.
52
+ if (previousRequire) {
53
+ return previousRequire(name, true);
54
+ }
55
+
56
+ // Try the node require function if it exists.
57
+ if (nodeRequire && typeof name === 'string') {
58
+ return nodeRequire(name);
59
+ }
60
+
61
+ var err = new Error("Cannot find module '" + name + "'");
62
+ err.code = 'MODULE_NOT_FOUND';
63
+ throw err;
64
+ }
65
+
66
+ localRequire.resolve = resolve;
67
+ localRequire.cache = {};
68
+
69
+ var module = (cache[name] = new newRequire.Module(name));
70
+
71
+ modules[name][0].call(
72
+ module.exports,
73
+ localRequire,
74
+ module,
75
+ module.exports,
76
+ this
77
+ );
78
+ }
79
+
80
+ return cache[name].exports;
81
+
82
+ function localRequire(x) {
83
+ var res = localRequire.resolve(x);
84
+ return res === false ? {} : newRequire(res);
85
+ }
86
+
87
+ function resolve(x) {
88
+ var id = modules[name][1][x];
89
+ return id != null ? id : x;
90
+ }
91
+ }
92
+
93
+ function Module(moduleName) {
94
+ this.id = moduleName;
95
+ this.bundle = newRequire;
96
+ this.exports = {};
97
+ }
98
+
99
+ newRequire.isParcelRequire = true;
100
+ newRequire.Module = Module;
101
+ newRequire.modules = modules;
102
+ newRequire.cache = cache;
103
+ newRequire.parent = previousRequire;
104
+ newRequire.register = function (id, exports) {
105
+ modules[id] = [
106
+ function (require, module) {
107
+ module.exports = exports;
108
+ },
109
+ {},
110
+ ];
111
+ };
112
+
113
+ Object.defineProperty(newRequire, 'root', {
114
+ get: function () {
115
+ return globalObject[parcelRequireName];
116
+ },
117
+ });
118
+
119
+ globalObject[parcelRequireName] = newRequire;
120
+
121
+ for (var i = 0; i < entry.length; i++) {
122
+ newRequire(entry[i]);
123
+ }
124
+
125
+ if (mainEntry) {
126
+ // Expose entry point to Node, AMD or browser globals
127
+ // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
128
+ var mainExports = newRequire(mainEntry);
129
+
130
+ // CommonJS
131
+ if (typeof exports === 'object' && typeof module !== 'undefined') {
132
+ module.exports = mainExports;
133
+
134
+ // RequireJS
135
+ } else if (typeof define === 'function' && define.amd) {
136
+ define(function () {
137
+ return mainExports;
138
+ });
139
+
140
+ // <script>
141
+ } else if (globalName) {
142
+ this[globalName] = mainExports;
143
+ }
144
+ }
145
+ })({"gAaC1":[function(require,module,exports) {
146
+ var global = arguments[3];
147
+ var HMR_HOST = null;
148
+ var HMR_PORT = null;
149
+ var HMR_SECURE = false;
150
+ var HMR_ENV_HASH = "d6ea1d42532a7575";
151
+ module.bundle.HMR_BUNDLE_ID = "64a677193bb9b3f5";
152
+ "use strict";
153
+ /* global HMR_HOST, HMR_PORT, HMR_ENV_HASH, HMR_SECURE, chrome, browser, __parcel__import__, __parcel__importScripts__, ServiceWorkerGlobalScope */ /*::
154
+ import type {
155
+ HMRAsset,
156
+ HMRMessage,
157
+ } from '@parcel/reporter-dev-server/src/HMRServer.js';
158
+ interface ParcelRequire {
159
+ (string): mixed;
160
+ cache: {|[string]: ParcelModule|};
161
+ hotData: {|[string]: mixed|};
162
+ Module: any;
163
+ parent: ?ParcelRequire;
164
+ isParcelRequire: true;
165
+ modules: {|[string]: [Function, {|[string]: string|}]|};
166
+ HMR_BUNDLE_ID: string;
167
+ root: ParcelRequire;
168
+ }
169
+ interface ParcelModule {
170
+ hot: {|
171
+ data: mixed,
172
+ accept(cb: (Function) => void): void,
173
+ dispose(cb: (mixed) => void): void,
174
+ // accept(deps: Array<string> | string, cb: (Function) => void): void,
175
+ // decline(): void,
176
+ _acceptCallbacks: Array<(Function) => void>,
177
+ _disposeCallbacks: Array<(mixed) => void>,
178
+ |};
179
+ }
180
+ interface ExtensionContext {
181
+ runtime: {|
182
+ reload(): void,
183
+ getURL(url: string): string;
184
+ getManifest(): {manifest_version: number, ...};
185
+ |};
186
+ }
187
+ declare var module: {bundle: ParcelRequire, ...};
188
+ declare var HMR_HOST: string;
189
+ declare var HMR_PORT: string;
190
+ declare var HMR_ENV_HASH: string;
191
+ declare var HMR_SECURE: boolean;
192
+ declare var chrome: ExtensionContext;
193
+ declare var browser: ExtensionContext;
194
+ declare var __parcel__import__: (string) => Promise<void>;
195
+ declare var __parcel__importScripts__: (string) => Promise<void>;
196
+ declare var globalThis: typeof self;
197
+ declare var ServiceWorkerGlobalScope: Object;
198
+ */ var OVERLAY_ID = "__parcel__error__overlay__";
199
+ var OldModule = module.bundle.Module;
200
+ function Module(moduleName) {
201
+ OldModule.call(this, moduleName);
202
+ this.hot = {
203
+ data: module.bundle.hotData[moduleName],
204
+ _acceptCallbacks: [],
205
+ _disposeCallbacks: [],
206
+ accept: function(fn) {
207
+ this._acceptCallbacks.push(fn || function() {});
208
+ },
209
+ dispose: function(fn) {
210
+ this._disposeCallbacks.push(fn);
211
+ }
212
+ };
213
+ module.bundle.hotData[moduleName] = undefined;
214
+ }
215
+ module.bundle.Module = Module;
216
+ module.bundle.hotData = {};
217
+ var checkedAssets /*: {|[string]: boolean|} */ , assetsToDispose /*: Array<[ParcelRequire, string]> */ , assetsToAccept /*: Array<[ParcelRequire, string]> */ ;
218
+ function getHostname() {
219
+ return HMR_HOST || (location.protocol.indexOf("http") === 0 ? location.hostname : "localhost");
220
+ }
221
+ function getPort() {
222
+ return HMR_PORT || location.port;
223
+ }
224
+ // eslint-disable-next-line no-redeclare
225
+ var parent = module.bundle.parent;
226
+ if ((!parent || !parent.isParcelRequire) && typeof WebSocket !== "undefined") {
227
+ var hostname = getHostname();
228
+ var port = getPort();
229
+ var protocol = HMR_SECURE || location.protocol == "https:" && ![
230
+ "localhost",
231
+ "127.0.0.1",
232
+ "0.0.0.0"
233
+ ].includes(hostname) ? "wss" : "ws";
234
+ var ws;
235
+ try {
236
+ ws = new WebSocket(protocol + "://" + hostname + (port ? ":" + port : "") + "/");
237
+ } catch (err) {
238
+ if (err.message) console.error(err.message);
239
+ ws = {};
240
+ }
241
+ // Web extension context
242
+ var extCtx = typeof browser === "undefined" ? typeof chrome === "undefined" ? null : chrome : browser;
243
+ // Safari doesn't support sourceURL in error stacks.
244
+ // eval may also be disabled via CSP, so do a quick check.
245
+ var supportsSourceURL = false;
246
+ try {
247
+ (0, eval)('throw new Error("test"); //# sourceURL=test.js');
248
+ } catch (err) {
249
+ supportsSourceURL = err.stack.includes("test.js");
250
+ }
251
+ // $FlowFixMe
252
+ ws.onmessage = async function(event /*: {data: string, ...} */ ) {
253
+ checkedAssets = {} /*: {|[string]: boolean|} */ ;
254
+ assetsToAccept = [];
255
+ assetsToDispose = [];
256
+ var data /*: HMRMessage */ = JSON.parse(event.data);
257
+ if (data.type === "update") {
258
+ // Remove error overlay if there is one
259
+ if (typeof document !== "undefined") removeErrorOverlay();
260
+ let assets = data.assets.filter((asset)=>asset.envHash === HMR_ENV_HASH);
261
+ // Handle HMR Update
262
+ let handled = assets.every((asset)=>{
263
+ return asset.type === "css" || asset.type === "js" && hmrAcceptCheck(module.bundle.root, asset.id, asset.depsByBundle);
264
+ });
265
+ if (handled) {
266
+ console.clear();
267
+ // Dispatch custom event so other runtimes (e.g React Refresh) are aware.
268
+ if (typeof window !== "undefined" && typeof CustomEvent !== "undefined") window.dispatchEvent(new CustomEvent("parcelhmraccept"));
269
+ await hmrApplyUpdates(assets);
270
+ // Dispose all old assets.
271
+ let processedAssets = {} /*: {|[string]: boolean|} */ ;
272
+ for(let i = 0; i < assetsToDispose.length; i++){
273
+ let id = assetsToDispose[i][1];
274
+ if (!processedAssets[id]) {
275
+ hmrDispose(assetsToDispose[i][0], id);
276
+ processedAssets[id] = true;
277
+ }
278
+ }
279
+ // Run accept callbacks. This will also re-execute other disposed assets in topological order.
280
+ processedAssets = {};
281
+ for(let i = 0; i < assetsToAccept.length; i++){
282
+ let id = assetsToAccept[i][1];
283
+ if (!processedAssets[id]) {
284
+ hmrAccept(assetsToAccept[i][0], id);
285
+ processedAssets[id] = true;
286
+ }
287
+ }
288
+ } else fullReload();
289
+ }
290
+ if (data.type === "error") {
291
+ // Log parcel errors to console
292
+ for (let ansiDiagnostic of data.diagnostics.ansi){
293
+ let stack = ansiDiagnostic.codeframe ? ansiDiagnostic.codeframe : ansiDiagnostic.stack;
294
+ console.error("\uD83D\uDEA8 [parcel]: " + ansiDiagnostic.message + "\n" + stack + "\n\n" + ansiDiagnostic.hints.join("\n"));
295
+ }
296
+ if (typeof document !== "undefined") {
297
+ // Render the fancy html overlay
298
+ removeErrorOverlay();
299
+ var overlay = createErrorOverlay(data.diagnostics.html);
300
+ // $FlowFixMe
301
+ document.body.appendChild(overlay);
302
+ }
303
+ }
304
+ };
305
+ ws.onerror = function(e) {
306
+ if (e.message) console.error(e.message);
307
+ };
308
+ ws.onclose = function() {
309
+ console.warn("[parcel] \uD83D\uDEA8 Connection to the HMR server was lost");
310
+ };
311
+ }
312
+ function removeErrorOverlay() {
313
+ var overlay = document.getElementById(OVERLAY_ID);
314
+ if (overlay) {
315
+ overlay.remove();
316
+ console.log("[parcel] \u2728 Error resolved");
317
+ }
318
+ }
319
+ function createErrorOverlay(diagnostics) {
320
+ var overlay = document.createElement("div");
321
+ overlay.id = OVERLAY_ID;
322
+ let errorHTML = '<div style="background: black; opacity: 0.85; font-size: 16px; color: white; position: fixed; height: 100%; width: 100%; top: 0px; left: 0px; padding: 30px; font-family: Menlo, Consolas, monospace; z-index: 9999;">';
323
+ for (let diagnostic of diagnostics){
324
+ let stack = diagnostic.frames.length ? diagnostic.frames.reduce((p, frame)=>{
325
+ return `${p}
326
+ <a href="/__parcel_launch_editor?file=${encodeURIComponent(frame.location)}" style="text-decoration: underline; color: #888" onclick="fetch(this.href); return false">${frame.location}</a>
327
+ ${frame.code}`;
328
+ }, "") : diagnostic.stack;
329
+ errorHTML += `
330
+ <div>
331
+ <div style="font-size: 18px; font-weight: bold; margin-top: 20px;">
332
+ \u{1F6A8} ${diagnostic.message}
333
+ </div>
334
+ <pre>${stack}</pre>
335
+ <div>
336
+ ${diagnostic.hints.map((hint)=>"<div>\uD83D\uDCA1 " + hint + "</div>").join("")}
337
+ </div>
338
+ ${diagnostic.documentation ? `<div>\u{1F4DD} <a style="color: violet" href="${diagnostic.documentation}" target="_blank">Learn more</a></div>` : ""}
339
+ </div>
340
+ `;
341
+ }
342
+ errorHTML += "</div>";
343
+ overlay.innerHTML = errorHTML;
344
+ return overlay;
345
+ }
346
+ function fullReload() {
347
+ if ("reload" in location) location.reload();
348
+ else if (extCtx && extCtx.runtime && extCtx.runtime.reload) extCtx.runtime.reload();
349
+ }
350
+ function getParents(bundle, id) /*: Array<[ParcelRequire, string]> */ {
351
+ var modules = bundle.modules;
352
+ if (!modules) return [];
353
+ var parents = [];
354
+ var k, d, dep;
355
+ for(k in modules)for(d in modules[k][1]){
356
+ dep = modules[k][1][d];
357
+ if (dep === id || Array.isArray(dep) && dep[dep.length - 1] === id) parents.push([
358
+ bundle,
359
+ k
360
+ ]);
361
+ }
362
+ if (bundle.parent) parents = parents.concat(getParents(bundle.parent, id));
363
+ return parents;
364
+ }
365
+ function updateLink(link) {
366
+ var href = link.getAttribute("href");
367
+ if (!href) return;
368
+ var newLink = link.cloneNode();
369
+ newLink.onload = function() {
370
+ if (link.parentNode !== null) // $FlowFixMe
371
+ link.parentNode.removeChild(link);
372
+ };
373
+ newLink.setAttribute("href", // $FlowFixMe
374
+ href.split("?")[0] + "?" + Date.now());
375
+ // $FlowFixMe
376
+ link.parentNode.insertBefore(newLink, link.nextSibling);
377
+ }
378
+ var cssTimeout = null;
379
+ function reloadCSS() {
380
+ if (cssTimeout) return;
381
+ cssTimeout = setTimeout(function() {
382
+ var links = document.querySelectorAll('link[rel="stylesheet"]');
383
+ for(var i = 0; i < links.length; i++){
384
+ // $FlowFixMe[incompatible-type]
385
+ var href /*: string */ = links[i].getAttribute("href");
386
+ var hostname = getHostname();
387
+ var servedFromHMRServer = hostname === "localhost" ? new RegExp("^(https?:\\/\\/(0.0.0.0|127.0.0.1)|localhost):" + getPort()).test(href) : href.indexOf(hostname + ":" + getPort());
388
+ var absolute = /^https?:\/\//i.test(href) && href.indexOf(location.origin) !== 0 && !servedFromHMRServer;
389
+ if (!absolute) updateLink(links[i]);
390
+ }
391
+ cssTimeout = null;
392
+ }, 50);
393
+ }
394
+ function hmrDownload(asset) {
395
+ if (asset.type === "js") {
396
+ if (typeof document !== "undefined") {
397
+ let script = document.createElement("script");
398
+ script.src = asset.url + "?t=" + Date.now();
399
+ if (asset.outputFormat === "esmodule") script.type = "module";
400
+ return new Promise((resolve, reject)=>{
401
+ var _document$head;
402
+ script.onload = ()=>resolve(script);
403
+ script.onerror = reject;
404
+ (_document$head = document.head) === null || _document$head === void 0 || _document$head.appendChild(script);
405
+ });
406
+ } else if (typeof importScripts === "function") {
407
+ // Worker scripts
408
+ if (asset.outputFormat === "esmodule") return import(asset.url + "?t=" + Date.now());
409
+ else return new Promise((resolve, reject)=>{
410
+ try {
411
+ importScripts(asset.url + "?t=" + Date.now());
412
+ resolve();
413
+ } catch (err) {
414
+ reject(err);
415
+ }
416
+ });
417
+ }
418
+ }
419
+ }
420
+ async function hmrApplyUpdates(assets) {
421
+ global.parcelHotUpdate = Object.create(null);
422
+ let scriptsToRemove;
423
+ try {
424
+ // If sourceURL comments aren't supported in eval, we need to load
425
+ // the update from the dev server over HTTP so that stack traces
426
+ // are correct in errors/logs. This is much slower than eval, so
427
+ // we only do it if needed (currently just Safari).
428
+ // https://bugs.webkit.org/show_bug.cgi?id=137297
429
+ // This path is also taken if a CSP disallows eval.
430
+ if (!supportsSourceURL) {
431
+ let promises = assets.map((asset)=>{
432
+ var _hmrDownload;
433
+ return (_hmrDownload = hmrDownload(asset)) === null || _hmrDownload === void 0 ? void 0 : _hmrDownload.catch((err)=>{
434
+ // Web extension fix
435
+ if (extCtx && extCtx.runtime && extCtx.runtime.getManifest().manifest_version == 3 && typeof ServiceWorkerGlobalScope != "undefined" && global instanceof ServiceWorkerGlobalScope) {
436
+ extCtx.runtime.reload();
437
+ return;
438
+ }
439
+ throw err;
440
+ });
441
+ });
442
+ scriptsToRemove = await Promise.all(promises);
443
+ }
444
+ assets.forEach(function(asset) {
445
+ hmrApply(module.bundle.root, asset);
446
+ });
447
+ } finally{
448
+ delete global.parcelHotUpdate;
449
+ if (scriptsToRemove) scriptsToRemove.forEach((script)=>{
450
+ if (script) {
451
+ var _document$head2;
452
+ (_document$head2 = document.head) === null || _document$head2 === void 0 || _document$head2.removeChild(script);
453
+ }
454
+ });
455
+ }
456
+ }
457
+ function hmrApply(bundle /*: ParcelRequire */ , asset /*: HMRAsset */ ) {
458
+ var modules = bundle.modules;
459
+ if (!modules) return;
460
+ if (asset.type === "css") reloadCSS();
461
+ else if (asset.type === "js") {
462
+ let deps = asset.depsByBundle[bundle.HMR_BUNDLE_ID];
463
+ if (deps) {
464
+ if (modules[asset.id]) {
465
+ // Remove dependencies that are removed and will become orphaned.
466
+ // This is necessary so that if the asset is added back again, the cache is gone, and we prevent a full page reload.
467
+ let oldDeps = modules[asset.id][1];
468
+ for(let dep in oldDeps)if (!deps[dep] || deps[dep] !== oldDeps[dep]) {
469
+ let id = oldDeps[dep];
470
+ let parents = getParents(module.bundle.root, id);
471
+ if (parents.length === 1) hmrDelete(module.bundle.root, id);
472
+ }
473
+ }
474
+ if (supportsSourceURL) // Global eval. We would use `new Function` here but browser
475
+ // support for source maps is better with eval.
476
+ (0, eval)(asset.output);
477
+ // $FlowFixMe
478
+ let fn = global.parcelHotUpdate[asset.id];
479
+ modules[asset.id] = [
480
+ fn,
481
+ deps
482
+ ];
483
+ } else if (bundle.parent) hmrApply(bundle.parent, asset);
484
+ }
485
+ }
486
+ function hmrDelete(bundle, id) {
487
+ let modules = bundle.modules;
488
+ if (!modules) return;
489
+ if (modules[id]) {
490
+ // Collect dependencies that will become orphaned when this module is deleted.
491
+ let deps = modules[id][1];
492
+ let orphans = [];
493
+ for(let dep in deps){
494
+ let parents = getParents(module.bundle.root, deps[dep]);
495
+ if (parents.length === 1) orphans.push(deps[dep]);
496
+ }
497
+ // Delete the module. This must be done before deleting dependencies in case of circular dependencies.
498
+ delete modules[id];
499
+ delete bundle.cache[id];
500
+ // Now delete the orphans.
501
+ orphans.forEach((id)=>{
502
+ hmrDelete(module.bundle.root, id);
503
+ });
504
+ } else if (bundle.parent) hmrDelete(bundle.parent, id);
505
+ }
506
+ function hmrAcceptCheck(bundle /*: ParcelRequire */ , id /*: string */ , depsByBundle /*: ?{ [string]: { [string]: string } }*/ ) {
507
+ if (hmrAcceptCheckOne(bundle, id, depsByBundle)) return true;
508
+ // Traverse parents breadth first. All possible ancestries must accept the HMR update, or we'll reload.
509
+ let parents = getParents(module.bundle.root, id);
510
+ let accepted = false;
511
+ while(parents.length > 0){
512
+ let v = parents.shift();
513
+ let a = hmrAcceptCheckOne(v[0], v[1], null);
514
+ if (a) // If this parent accepts, stop traversing upward, but still consider siblings.
515
+ accepted = true;
516
+ else {
517
+ // Otherwise, queue the parents in the next level upward.
518
+ let p = getParents(module.bundle.root, v[1]);
519
+ if (p.length === 0) {
520
+ // If there are no parents, then we've reached an entry without accepting. Reload.
521
+ accepted = false;
522
+ break;
523
+ }
524
+ parents.push(...p);
525
+ }
526
+ }
527
+ return accepted;
528
+ }
529
+ function hmrAcceptCheckOne(bundle /*: ParcelRequire */ , id /*: string */ , depsByBundle /*: ?{ [string]: { [string]: string } }*/ ) {
530
+ var modules = bundle.modules;
531
+ if (!modules) return;
532
+ if (depsByBundle && !depsByBundle[bundle.HMR_BUNDLE_ID]) {
533
+ // If we reached the root bundle without finding where the asset should go,
534
+ // there's nothing to do. Mark as "accepted" so we don't reload the page.
535
+ if (!bundle.parent) return true;
536
+ return hmrAcceptCheck(bundle.parent, id, depsByBundle);
537
+ }
538
+ if (checkedAssets[id]) return true;
539
+ checkedAssets[id] = true;
540
+ var cached = bundle.cache[id];
541
+ assetsToDispose.push([
542
+ bundle,
543
+ id
544
+ ]);
545
+ if (!cached || cached.hot && cached.hot._acceptCallbacks.length) {
546
+ assetsToAccept.push([
547
+ bundle,
548
+ id
549
+ ]);
550
+ return true;
551
+ }
552
+ }
553
+ function hmrDispose(bundle /*: ParcelRequire */ , id /*: string */ ) {
554
+ var cached = bundle.cache[id];
555
+ bundle.hotData[id] = {};
556
+ if (cached && cached.hot) cached.hot.data = bundle.hotData[id];
557
+ if (cached && cached.hot && cached.hot._disposeCallbacks.length) cached.hot._disposeCallbacks.forEach(function(cb) {
558
+ cb(bundle.hotData[id]);
559
+ });
560
+ delete bundle.cache[id];
561
+ }
562
+ function hmrAccept(bundle /*: ParcelRequire */ , id /*: string */ ) {
563
+ // Execute the module.
564
+ bundle(id);
565
+ // Run the accept callbacks in the new version of the module.
566
+ var cached = bundle.cache[id];
567
+ if (cached && cached.hot && cached.hot._acceptCallbacks.length) cached.hot._acceptCallbacks.forEach(function(cb) {
568
+ var assetsToAlsoAccept = cb(function() {
569
+ return getParents(module.bundle.root, id);
570
+ });
571
+ if (assetsToAlsoAccept && assetsToAccept.length) {
572
+ assetsToAlsoAccept.forEach(function(a) {
573
+ hmrDispose(a[0], a[1]);
574
+ });
575
+ // $FlowFixMe[method-unbinding]
576
+ assetsToAccept.push.apply(assetsToAccept, assetsToAlsoAccept);
577
+ }
578
+ });
579
+ }
580
+
581
+ },{}],"bAfYR":[function(require,module,exports) {
582
+ var parcelHelpers = require("@parcel/transformer-js/src/esmodule-helpers.js");
583
+ parcelHelpers.defineInteropFlag(exports);
584
+ parcelHelpers.export(exports, "views", ()=>views);
585
+ parcelHelpers.export(exports, "render", ()=>render);
586
+ parcelHelpers.export(exports, "navigation", ()=>exports_navigation);
587
+ parcelHelpers.export(exports, "jsx", ()=>jsx_default);
588
+ parcelHelpers.export(exports, "createBus", ()=>createBus);
589
+ parcelHelpers.export(exports, "createApp", ()=>createApp);
590
+ parcelHelpers.export(exports, "bind", ()=>bind);
591
+ parcelHelpers.export(exports, "State", ()=>State);
592
+ var __defProp = Object.defineProperty;
593
+ var __export = (target, all)=>{
594
+ for(var name in all)__defProp(target, name, {
595
+ get: all[name],
596
+ enumerable: true,
597
+ configurable: true,
598
+ set: (newValue)=>all[name] = ()=>newValue
599
+ });
600
+ };
601
+ // src/rendering/dom/create.ts
602
+ var setAttributesOnElement = (element, attributes)=>{
603
+ for(const key in attributes){
604
+ if (key === "__self") continue;
605
+ if (key === "value") element.value = attributes[key];
606
+ else element.setAttribute(key, attributes[key]);
607
+ }
608
+ };
609
+ var setEventsOnElement = (element, events, publish)=>{
610
+ const eventMaps = {};
611
+ for(const domEvent in events){
612
+ const eventName = events[domEvent];
613
+ const listener = (event)=>publish(eventName, event);
614
+ element.addEventListener(domEvent, listener);
615
+ eventMaps[domEvent] = {
616
+ domEvent,
617
+ busEvent: eventName,
618
+ listener
619
+ };
620
+ }
621
+ element.eventMaps = eventMaps;
622
+ };
623
+ var createNode = (type, document)=>{
624
+ document = document || window.document;
625
+ return document.createElement(type);
626
+ };
627
+ var createTextNode = (value, document)=>{
628
+ document = document || window.document;
629
+ return document.createTextNode(value);
630
+ };
631
+ var createDecoratedNode = (type, attributes, events, renderKit)=>{
632
+ const dom = createNode(type, renderKit.document);
633
+ setAttributesOnElement(dom, attributes);
634
+ setEventsOnElement(dom, events, renderKit.publish);
635
+ return dom;
636
+ };
637
+ // src/rendering/dom/attributesAndEvents.ts
638
+ var separateAttrsAndEvents = (combined, defaultValue = "")=>{
639
+ const attributes = {};
640
+ const events = {};
641
+ for(const key in combined){
642
+ const value = combined[key];
643
+ if (key.match(/^on.+/i)) {
644
+ const eventKey = key.slice(2).toLowerCase();
645
+ events[eventKey] = value;
646
+ } else attributes[key] = normalizeValueForKey(combined, key, defaultValue);
647
+ }
648
+ return {
649
+ attributes,
650
+ events
651
+ };
652
+ };
653
+ var normalizeValueForKey = (object, key, defaultValue = "")=>{
654
+ if (object[key] === undefined) return defaultValue;
655
+ return object[key];
656
+ };
657
+ // src/rendering/templates/text.ts
658
+ class TextTemplate {
659
+ value;
660
+ constructor(content){
661
+ this.value = content.toString();
662
+ }
663
+ render(renderKit) {
664
+ const textNode = createTextNode(this.value, renderKit.document);
665
+ if (!textNode) return [];
666
+ textNode.__jsx = "TextNode";
667
+ return [
668
+ textNode
669
+ ];
670
+ }
671
+ }
672
+ // src/rendering/templates/children.ts
673
+ var ensureArray = (children)=>{
674
+ if (Array.isArray(children)) return children.flat();
675
+ if (!children) return [];
676
+ return [
677
+ children
678
+ ];
679
+ };
680
+ var recursiveRender = (children, renderKit, rendered = [])=>children.reduce(renderReducer(renderKit), rendered).flat();
681
+ var renderReducer = (renderKit)=>(aggregate, view)=>{
682
+ if (!view) return aggregate;
683
+ if (Array.isArray(view)) {
684
+ const dom = recursiveRender(view, renderKit, aggregate);
685
+ return dom;
686
+ }
687
+ view.render(renderKit).forEach((template)=>aggregate.push(template));
688
+ return aggregate;
689
+ };
690
+ var replaceTextNodes = (child)=>{
691
+ if (isTextNode(child)) return textNode(child);
692
+ return child;
693
+ };
694
+ var isTextNode = (child)=>{
695
+ return typeof child === "string" || typeof child === "number";
696
+ };
697
+ var textNode = (content)=>{
698
+ return new TextTemplate(content);
699
+ };
700
+ class Children {
701
+ collection;
702
+ parentElement;
703
+ constructor(jsxChildren){
704
+ this.collection = ensureArray(jsxChildren);
705
+ this.collection = this.collection.map(replaceTextNodes);
706
+ this.collection = this.collection.flat();
707
+ }
708
+ render(renderKit, parentElement) {
709
+ this.parentElement = parentElement;
710
+ const dom = this.generateDom(renderKit);
711
+ this.attachToParent(dom);
712
+ return dom;
713
+ }
714
+ generateDom(renderKit) {
715
+ return recursiveRender(this.collection, renderKit);
716
+ }
717
+ attachToParent(dom) {
718
+ if (this.parentElement === undefined) return;
719
+ const parent = this.parentElement;
720
+ dom.forEach((node)=>parent.appendChild(node));
721
+ }
722
+ }
723
+ // src/rendering/templates/tag.ts
724
+ class Tag {
725
+ type;
726
+ events;
727
+ attributes;
728
+ children;
729
+ constructor(tagType, combinedAttributes, children2){
730
+ this.type = tagType;
731
+ const { events, attributes } = separateAttrsAndEvents(combinedAttributes);
732
+ this.events = events;
733
+ this.attributes = attributes;
734
+ this.children = new Children(children2);
735
+ }
736
+ render(renderKit) {
737
+ const dom = this.generateDom(renderKit);
738
+ if (!dom) return [];
739
+ this.children.render(renderKit, dom);
740
+ return [
741
+ dom
742
+ ];
743
+ }
744
+ generateDom(renderKit) {
745
+ const node = createDecoratedNode(this.type, this.attributes, this.events, renderKit);
746
+ node.__jsx = this.key();
747
+ return node;
748
+ }
749
+ key() {
750
+ return this.attributes.key || this.source() || this.createKey();
751
+ }
752
+ source() {
753
+ if (this.attributes.__source) {
754
+ const { fileName, lineNumber, columnNumber } = this.attributes.__source;
755
+ return `${fileName}:${lineNumber}:${columnNumber}`;
756
+ }
757
+ }
758
+ createKey() {
759
+ const id = this.attributes.id ? `#${this.attributes.id}` : "";
760
+ const type = this.attributes.type ? `[type=${this.attributes.type}]` : "";
761
+ const name = this.attributes.name ? `[name=${this.attributes.name}]` : "";
762
+ return `${this.type}${id}${type}${name}`;
763
+ }
764
+ }
765
+ // src/jsx.js
766
+ var ensureChildrenArray = (maybeChildren, attributes)=>maybeChildren || attributes.children || [];
767
+ var packageAttributes = (maybeAttributes, maybeChildren)=>{
768
+ const attributes = maybeAttributes || {};
769
+ const children3 = ensureChildrenArray(maybeChildren, attributes);
770
+ attributes.children = attributes.children || children3;
771
+ return attributes;
772
+ };
773
+ var jsx = (type, attributes, ...children3)=>{
774
+ if (typeof type === "string") return new Tag(type, attributes, children3);
775
+ return type(packageAttributes(attributes, children3));
776
+ };
777
+ jsx.fragment = (attributes, maybeChildren)=>{
778
+ const children3 = ensureChildrenArray(maybeChildren, attributes);
779
+ return new Children(children3);
780
+ };
781
+ var jsx_default = jsx;
782
+ // src/rendering/templates/root.ts
783
+ class Root {
784
+ template;
785
+ selector;
786
+ renderKit;
787
+ dom;
788
+ parentElement;
789
+ constructor(template, selector, renderKit){
790
+ this.template = template;
791
+ this.selector = selector;
792
+ this.renderKit = renderKit;
793
+ this.dom = [];
794
+ this.parentElement = null;
795
+ }
796
+ renderAndAttach(renderKit) {
797
+ this.parentElement = this.getParentElement();
798
+ this.dom = this.render({
799
+ ...renderKit,
800
+ parent: this.parentElement
801
+ });
802
+ if (this.parentElement) this.attach();
803
+ }
804
+ render(renderKit) {
805
+ return this.template.render(renderKit);
806
+ }
807
+ attach() {
808
+ this.parentElement && (this.parentElement.innerHTML = "");
809
+ this.dom.forEach((element)=>{
810
+ this.parentElement && this.parentElement.appendChild(element);
811
+ });
812
+ }
813
+ getParentElement() {
814
+ return this.renderKit.document.querySelector(this.selector);
815
+ }
816
+ }
817
+ var render = (template, selector, renderKit)=>{
818
+ const root = new Root(template, selector, renderKit);
819
+ root.renderAndAttach(renderKit);
820
+ return root;
821
+ };
822
+ // src/state/testingTypes.js
823
+ var isBoolean = (value)=>typeof value === "boolean";
824
+ var isNumber = (value)=>typeof value === "number";
825
+ var isString = (value)=>typeof value === "string";
826
+ var isArray = (value)=>Array.isArray(value);
827
+ var isObject = (value)=>value !== null && !isArray(value) && typeof value === "object";
828
+ // src/state/equality.js
829
+ var areElementEqual = (oldValue, newValue)=>oldValue === newValue;
830
+ var keyLengthSame = (oldValue, newValue)=>Object.keys(oldValue).length === Object.keys(newValue).length;
831
+ var areObjectsEqual = (oldValue, newValue)=>{
832
+ if (!(isObject(oldValue) && isObject(newValue))) return false;
833
+ if (!keyLengthSame(oldValue, newValue)) return false;
834
+ Object.keys(oldValue).every((key)=>{
835
+ const oldInnerValue = oldValue[key];
836
+ const newInnerValue = newValue[key];
837
+ return areEqual(oldInnerValue, newInnerValue);
838
+ });
839
+ };
840
+ var areArraysEqual = (oldValue, newValue)=>{
841
+ if (!(isArray(oldValue) && isArray(newValue))) return false;
842
+ if (oldValue.length !== newValue.length) return false;
843
+ oldValue.every((oldInnerValue, index)=>{
844
+ const newInnerValue = newValue[index];
845
+ return areEqual(oldInnerValue, newInnerValue);
846
+ });
847
+ };
848
+ var areEqual = (oldValue, newValue)=>{
849
+ if (isObject(oldValue)) return areObjectsEqual(oldValue, newValue);
850
+ if (isArray(oldValue)) return areArraysEqual(oldValue, newValue);
851
+ return areElementEqual(oldValue, newValue);
852
+ };
853
+ // src/state/stores.js
854
+ class GeneralStore {
855
+ nullEvent = {};
856
+ constructor({ name, value, parent }){
857
+ this.name = name;
858
+ this.value = value;
859
+ this.parent = parent;
860
+ this.initialState = value;
861
+ }
862
+ update(newValue) {
863
+ if (this.isEqual(newValue)) return;
864
+ this.value = newValue;
865
+ return this.parent.publish(this.event());
866
+ }
867
+ reset() {
868
+ this.update(this.initialState);
869
+ }
870
+ isEqual(newValue) {
871
+ return areElementEqual(this.value, newValue);
872
+ }
873
+ event() {
874
+ return {
875
+ name: this.name,
876
+ value: this.value
877
+ };
878
+ }
879
+ }
880
+ class BooleanStore extends GeneralStore {
881
+ toggle() {
882
+ this.update(!this.value);
883
+ }
884
+ }
885
+ class NumericStore extends GeneralStore {
886
+ }
887
+ class StringStore extends GeneralStore {
888
+ }
889
+ class ListStore extends GeneralStore {
890
+ isEqual(newValue) {
891
+ return areArraysEqual(this.value, newValue);
892
+ }
893
+ push(newValue) {
894
+ const value = [
895
+ ...this.value,
896
+ newValue
897
+ ];
898
+ this.update(value);
899
+ }
900
+ }
901
+ class RecordStore extends GeneralStore {
902
+ isEqual(newValue) {
903
+ return areObjectsEqual(this.value, newValue);
904
+ }
905
+ }
906
+ // src/state.js
907
+ var eventPrefix = "state-change";
908
+ var eventName = (name)=>`${eventPrefix}:${name}`;
909
+ class State {
910
+ constructor(publish){
911
+ this.publisher = publish;
912
+ this.stores = {};
913
+ this.events = [];
914
+ this.transacting = false;
915
+ }
916
+ create(name, value) {
917
+ const StoreClass = this.storeTypeFor(value);
918
+ const store = new StoreClass({
919
+ name,
920
+ value,
921
+ parent: this
922
+ });
923
+ this.addStore(name, store);
924
+ }
925
+ add(store) {
926
+ const name = store.name;
927
+ this.addStore(name, store);
928
+ }
929
+ getStore(name) {
930
+ return this.stores[name];
931
+ }
932
+ addStore(name, store) {
933
+ this.stores[name] = store;
934
+ this[name] = store;
935
+ }
936
+ storeTypeFor(value) {
937
+ if (isArray(value)) return ListStore;
938
+ if (isObject(value)) return RecordStore;
939
+ if (isNumber(value)) return NumericStore;
940
+ if (isBoolean(value)) return BooleanStore;
941
+ if (isString(value)) return StringStore;
942
+ return GeneralStore;
943
+ }
944
+ publish(event) {
945
+ this.events.push(event);
946
+ if (!this.transacting) this.publishAll();
947
+ }
948
+ publishAll() {
949
+ const publishedStores = [];
950
+ this.events.reverse().forEach((event)=>{
951
+ const { name, value } = event;
952
+ if (!publishedStores.includes(name)) {
953
+ publishedStores.push(name);
954
+ this.publisher(`${eventPrefix}:${name}`, value);
955
+ }
956
+ });
957
+ this.events = [];
958
+ }
959
+ transaction(setter) {
960
+ this.transacting = true;
961
+ setter(this);
962
+ this.transacting = false;
963
+ this.publishAll();
964
+ }
965
+ value() {
966
+ return Object.keys(this.stores).reduce((valueObject, key)=>{
967
+ valueObject[key] = this.stores[key].value;
968
+ return valueObject;
969
+ }, {});
970
+ }
971
+ }
972
+ // src/types.ts
973
+ var ChangeInstructions;
974
+ (function(ChangeInstructions2) {
975
+ ChangeInstructions2[ChangeInstructions2["removeNode"] = 0] = "removeNode";
976
+ ChangeInstructions2[ChangeInstructions2["insertNode"] = 1] = "insertNode";
977
+ ChangeInstructions2[ChangeInstructions2["replaceNode"] = 2] = "replaceNode";
978
+ ChangeInstructions2[ChangeInstructions2["removeAttribute"] = 3] = "removeAttribute";
979
+ ChangeInstructions2[ChangeInstructions2["addAttribute"] = 4] = "addAttribute";
980
+ ChangeInstructions2[ChangeInstructions2["updateAttribute"] = 5] = "updateAttribute";
981
+ ChangeInstructions2[ChangeInstructions2["removeEvent"] = 6] = "removeEvent";
982
+ ChangeInstructions2[ChangeInstructions2["addEvent"] = 7] = "addEvent";
983
+ ChangeInstructions2[ChangeInstructions2["updateEvent"] = 8] = "updateEvent";
984
+ ChangeInstructions2[ChangeInstructions2["changeValue"] = 9] = "changeValue";
985
+ ChangeInstructions2[ChangeInstructions2["changeText"] = 10] = "changeText";
986
+ })(ChangeInstructions || (ChangeInstructions = {}));
987
+ // src/rendering/change/instructions/generate.ts
988
+ var changeText = (source, target)=>({
989
+ source,
990
+ target,
991
+ type: ChangeInstructions.changeText,
992
+ data: {}
993
+ });
994
+ var replaceNode = (source, target)=>({
995
+ source,
996
+ target,
997
+ type: ChangeInstructions.replaceNode,
998
+ data: {}
999
+ });
1000
+ var removeAttribute = (source, target, data)=>({
1001
+ source,
1002
+ target,
1003
+ data,
1004
+ type: ChangeInstructions.removeAttribute
1005
+ });
1006
+ var addAttribute = (source, target, data)=>({
1007
+ source,
1008
+ target,
1009
+ data,
1010
+ type: ChangeInstructions.addAttribute
1011
+ });
1012
+ var updateAttribute = (source, target, data)=>({
1013
+ source,
1014
+ target,
1015
+ data,
1016
+ type: ChangeInstructions.updateAttribute
1017
+ });
1018
+ var removeEvent = (source, target, data)=>({
1019
+ source,
1020
+ target,
1021
+ data,
1022
+ type: ChangeInstructions.removeEvent
1023
+ });
1024
+ var addEvent = (source, target, data)=>({
1025
+ source,
1026
+ target,
1027
+ data,
1028
+ type: ChangeInstructions.addEvent
1029
+ });
1030
+ var updateEvent = (source, target, data)=>({
1031
+ source,
1032
+ target,
1033
+ data,
1034
+ type: ChangeInstructions.updateEvent
1035
+ });
1036
+ var removeNode = (source)=>({
1037
+ source,
1038
+ target: source,
1039
+ type: ChangeInstructions.removeNode,
1040
+ data: {}
1041
+ });
1042
+ var insertNode = (target, data)=>({
1043
+ target,
1044
+ source: target,
1045
+ type: ChangeInstructions.insertNode,
1046
+ data
1047
+ });
1048
+ var changeValue = (source, target, data)=>({
1049
+ source,
1050
+ target,
1051
+ type: ChangeInstructions.changeValue,
1052
+ data
1053
+ });
1054
+ // src/rendering/change/instructions/idMap.js
1055
+ var nullMatch = {
1056
+ index: -1
1057
+ };
1058
+ class IdMap {
1059
+ constructor(){
1060
+ this.map = {};
1061
+ }
1062
+ populate(list) {
1063
+ list.forEach((element, i)=>{
1064
+ const id = element.__jsx;
1065
+ if (id) {
1066
+ this.map[id] = this.map[id] || [];
1067
+ this.map[id].push({
1068
+ element,
1069
+ index: i
1070
+ });
1071
+ }
1072
+ });
1073
+ }
1074
+ pullMatch(element) {
1075
+ const id = element && element.__jsx;
1076
+ if (!id) return nullMatch;
1077
+ if (!(this.map[id] && this.map[id].length)) return nullMatch;
1078
+ return this.map[id].shift();
1079
+ }
1080
+ clear(element) {
1081
+ const id = element && element.__jsx;
1082
+ if (!(id && this.map[id] && this.map[id].length)) return;
1083
+ const matches = this.map[id];
1084
+ this.map[id] = matches.reduce((collection, possibleMatch)=>{
1085
+ if (possibleMatch.element !== element) collection.push(possibleMatch);
1086
+ return collection;
1087
+ }, []);
1088
+ }
1089
+ check(element) {
1090
+ const id = element && element.__jsx;
1091
+ if (!(id && this.map[id])) return false;
1092
+ return this.map[id].length > 0;
1093
+ }
1094
+ remaining() {
1095
+ return Object.values(this.map).flat();
1096
+ }
1097
+ }
1098
+ var createIdMap = (list)=>{
1099
+ const map = new IdMap;
1100
+ map.populate(list);
1101
+ return map;
1102
+ };
1103
+ // src/rendering/change/instructions/attributes.ts
1104
+ var compileForAttributes = (source, target)=>{
1105
+ const instructions = [];
1106
+ const sourceAttributes = source.attributes;
1107
+ const sourceLength = sourceAttributes.length;
1108
+ const targetAttributes = target.attributes;
1109
+ const targetLength = targetAttributes.length;
1110
+ let index;
1111
+ let innerIndex;
1112
+ let matchingAttribute;
1113
+ for(index = 0; index < sourceLength; index++){
1114
+ matchingAttribute = null;
1115
+ const sourceAttribute = sourceAttributes.item(index);
1116
+ if (!sourceAttribute) continue;
1117
+ for(innerIndex = 0; innerIndex < targetLength; innerIndex++){
1118
+ const targetAttribute = targetAttributes.item(innerIndex);
1119
+ if (!targetAttribute) continue;
1120
+ if (sourceAttribute.name == targetAttribute.name) {
1121
+ matchingAttribute = targetAttribute;
1122
+ break;
1123
+ }
1124
+ }
1125
+ if (!matchingAttribute) instructions.push(removeAttribute(source, target, {
1126
+ name: sourceAttribute.name
1127
+ }));
1128
+ else if (sourceAttribute.value !== matchingAttribute.value) instructions.push(updateAttribute(source, target, {
1129
+ name: sourceAttribute.name,
1130
+ value: matchingAttribute.value
1131
+ }));
1132
+ }
1133
+ for(index = 0; index < targetLength; index++){
1134
+ matchingAttribute = null;
1135
+ const targetAttribute = targetAttributes.item(index);
1136
+ if (!targetAttribute) continue;
1137
+ for(innerIndex = 0; innerIndex < sourceLength; innerIndex++){
1138
+ const sourceAttribute = sourceAttributes.item(innerIndex);
1139
+ if (!sourceAttribute) continue;
1140
+ if (sourceAttribute.name == targetAttribute.name) {
1141
+ matchingAttribute = sourceAttribute;
1142
+ break;
1143
+ }
1144
+ }
1145
+ if (!matchingAttribute) instructions.push(addAttribute(source, target, {
1146
+ name: targetAttribute.name,
1147
+ value: targetAttribute.value
1148
+ }));
1149
+ }
1150
+ return instructions;
1151
+ };
1152
+ // src/rendering/change/instructions/events.ts
1153
+ var compileForEvents = (source, target)=>{
1154
+ const instructions = [];
1155
+ const sourceEventMaps = source.eventMaps;
1156
+ const targetEventMaps = target.eventMaps;
1157
+ const sourceDomEvents = Object.keys(sourceEventMaps);
1158
+ const targetDomEvents = Object.keys(targetEventMaps);
1159
+ sourceDomEvents.forEach((domEvent)=>{
1160
+ const sourceEventMap = sourceEventMaps[domEvent];
1161
+ const targetEventMap = targetEventMaps[domEvent];
1162
+ if (!targetEventMap) instructions.push(removeEvent(source, target, {
1163
+ name: sourceEventMap.domEvent,
1164
+ value: sourceEventMap.listener
1165
+ }));
1166
+ else if (targetEventMap.busEvent !== sourceEventMap.busEvent) instructions.push(updateEvent(source, target, {
1167
+ name: domEvent,
1168
+ targetValue: targetEventMap.listener,
1169
+ sourceValue: sourceEventMap.listener
1170
+ }));
1171
+ });
1172
+ targetDomEvents.forEach((domEvent)=>{
1173
+ const sourceEventMap = sourceEventMaps[domEvent];
1174
+ const targetEventMap = targetEventMaps[domEvent];
1175
+ if (!sourceEventMap) instructions.push(addEvent(source, target, {
1176
+ name: targetEventMap.domEvent,
1177
+ value: targetEventMap.listener
1178
+ }));
1179
+ });
1180
+ return instructions;
1181
+ };
1182
+ // src/rendering/change/instructions/element.ts
1183
+ var compileForElement = (source, target)=>{
1184
+ const attributeInstructions = compileForAttributes(source, target);
1185
+ const eventInstructions = compileForEvents(source, target);
1186
+ const valueInstructions = compileForInputValue(source, target);
1187
+ return attributeInstructions.concat(eventInstructions).concat(valueInstructions);
1188
+ };
1189
+ var compileForInputValue = (sourceElement, targetElement)=>{
1190
+ const instructions = [];
1191
+ if (sourceElement.tagName !== "INPUT") return instructions;
1192
+ const source = sourceElement;
1193
+ const target = targetElement;
1194
+ if (source.value !== target.value) instructions.push(changeValue(source, target, {
1195
+ name: "value",
1196
+ value: target.value
1197
+ }));
1198
+ return instructions;
1199
+ };
1200
+ // src/rendering/change/instructions/text.ts
1201
+ var compileForText = (source, target)=>{
1202
+ if (source.textContent !== target.textContent) return [
1203
+ changeText(source, target)
1204
+ ];
1205
+ return [];
1206
+ };
1207
+ // src/rendering/change/instructions/node.ts
1208
+ var NodeTypes;
1209
+ (function(NodeTypes2) {
1210
+ NodeTypes2[NodeTypes2["ElementNode"] = 1] = "ElementNode";
1211
+ NodeTypes2[NodeTypes2["TextNode"] = 3] = "TextNode";
1212
+ })(NodeTypes || (NodeTypes = {}));
1213
+ var compileForNodeGenerator = (compileForCollection)=>(source, target)=>{
1214
+ let instructions = [];
1215
+ if (source.nodeType === NodeTypes.ElementNode) {
1216
+ const sourceElement = source;
1217
+ const targetElement = target;
1218
+ const baseInstructions = compileForElement(sourceElement, targetElement);
1219
+ const childrenInstructions = compileForCollection(sourceElement.childNodes, targetElement.childNodes, sourceElement);
1220
+ instructions = baseInstructions.concat(childrenInstructions);
1221
+ } else if (source.nodeType === NodeTypes.TextNode) instructions = compileForText(source, target);
1222
+ return instructions;
1223
+ };
1224
+ // src/debugging.js
1225
+ var debug = (...message)=>{};
1226
+ // src/rendering/change/instructions/children.ts
1227
+ var compileChildren = (sourceList, targetList, parent)=>{
1228
+ const baseInstructions = [];
1229
+ const length = largerLength(sourceList, targetList);
1230
+ const sourceMap = createIdMap(sourceList);
1231
+ const targetMap = createIdMap(targetList);
1232
+ const nodesPairsToDiff = [];
1233
+ let index = 0;
1234
+ for(; index < length; index++){
1235
+ const source = sourceList[index];
1236
+ const target = targetList[index];
1237
+ debug("\n", "loop index", index, source && source.__jsx, target && target.__jsx);
1238
+ if (target && targetMap.check(target)) {
1239
+ debug("target", target.__jsx, "index", index);
1240
+ const matchingSource = sourceMap.pullMatch(target);
1241
+ targetMap.clear(target);
1242
+ if (matchingSource.element) {
1243
+ debug("matching source found for target");
1244
+ if (matchingSource.index !== index) {
1245
+ debug("moving source", matchingSource.element.__jsx, index);
1246
+ baseInstructions.push(insertNode(matchingSource.element, {
1247
+ parent,
1248
+ index
1249
+ }));
1250
+ }
1251
+ debug("updating to match target", matchingSource.element.__jsx, matchingSource.element.classList, target.__jsx, target.classList);
1252
+ nodesPairsToDiff.push({
1253
+ source: matchingSource.element,
1254
+ target
1255
+ });
1256
+ } else if (source) {
1257
+ debug("NO matching source for target but source in slot", source.__jsx);
1258
+ if (targetMap.check(source)) {
1259
+ debug("adding", target.__jsx, "at", index);
1260
+ baseInstructions.push(insertNode(target, {
1261
+ parent,
1262
+ index
1263
+ }));
1264
+ } else {
1265
+ debug("replacing", source.__jsx, target.__jsx, "at", index);
1266
+ sourceMap.clear(source);
1267
+ baseInstructions.push(replaceNode(source, target));
1268
+ }
1269
+ } else {
1270
+ debug("adding target to end", target.__jsx);
1271
+ baseInstructions.push(insertNode(target, {
1272
+ parent,
1273
+ index
1274
+ }));
1275
+ }
1276
+ } else if (source) {
1277
+ const matchingSource = sourceMap.pullMatch(source);
1278
+ if (matchingSource.element) {
1279
+ debug("removing", source.__jsx);
1280
+ baseInstructions.push(removeNode(source));
1281
+ }
1282
+ }
1283
+ }
1284
+ sourceMap.remaining().forEach(({ element: element2 })=>{
1285
+ debug("removing", element2.__jsx);
1286
+ baseInstructions.push(removeNode(element2));
1287
+ });
1288
+ const nodeInstructions = nodesPairsToDiff.reduce((collection, { source, target })=>{
1289
+ return collection.concat(compileForNode(source, target));
1290
+ }, []);
1291
+ return baseInstructions.concat(nodeInstructions).sort(instructionsSorter);
1292
+ };
1293
+ var instructionsSorter = (left, right)=>{
1294
+ if (left.type > right.type) return 1;
1295
+ if (left.type < right.type) return -1;
1296
+ return 0;
1297
+ };
1298
+ var largerLength = (sourceList, targetList)=>{
1299
+ const sourceLength = Array.from(sourceList).length;
1300
+ const targetLength = Array.from(targetList).length;
1301
+ return sourceLength > targetLength ? sourceLength : targetLength;
1302
+ };
1303
+ var compileForNode = compileForNodeGenerator(compileChildren);
1304
+ // src/rendering/change.ts
1305
+ var change = (source, target, parent)=>{
1306
+ const instructions = compileChildren(source, target, parent);
1307
+ debug("instructions", instructions.map((instruction)=>instruction.type));
1308
+ instructions.forEach((instruction)=>{
1309
+ performInstruction(instruction);
1310
+ });
1311
+ };
1312
+ var performInstruction = (instruction)=>{
1313
+ const performer = performers[instruction.type] || noop;
1314
+ performer(instruction);
1315
+ };
1316
+ var noop = (_instruction)=>{};
1317
+ var changeText2 = (instruction)=>{
1318
+ const { source, target } = instruction;
1319
+ source.nodeValue = target.textContent;
1320
+ };
1321
+ var removeNode2 = (instruction)=>{
1322
+ const { source } = instruction;
1323
+ source.remove();
1324
+ debug("removeNode called on", source.nodeName);
1325
+ };
1326
+ var insertNode2 = (instruction)=>{
1327
+ const { target, data } = instruction;
1328
+ const { parent, index } = data;
1329
+ const sibling = parent.childNodes[index];
1330
+ if (!sibling) parent.appendChild(target);
1331
+ else if (sibling && sibling !== target) parent.insertBefore(target, sibling);
1332
+ };
1333
+ var replaceNode2 = (instruction)=>{
1334
+ const { source, target } = instruction;
1335
+ source.replaceWith(target);
1336
+ debug("replaceNode called on", source.nodeName, "with", target.nodeName);
1337
+ debug("parent", source.parentElement);
1338
+ };
1339
+ var removeAttribute2 = (instruction)=>{
1340
+ const { source, data } = instruction;
1341
+ const { name } = data;
1342
+ source.removeAttribute(name);
1343
+ };
1344
+ var addAttribute2 = (instruction)=>{
1345
+ const { source, data } = instruction;
1346
+ const { name, value } = data;
1347
+ source.setAttribute(name, value);
1348
+ };
1349
+ var updateAttribute2 = (instruction)=>{
1350
+ addAttribute2(instruction);
1351
+ };
1352
+ var removeEvent2 = (instruction)=>{
1353
+ const data = instruction.data;
1354
+ const source = instruction.source;
1355
+ const { name, value } = data;
1356
+ source.removeEventListener(name, value);
1357
+ };
1358
+ var addEvent2 = (instruction)=>{
1359
+ const data = instruction.data;
1360
+ const source = instruction.source;
1361
+ const { name, value } = data;
1362
+ source.addEventListener(name, value);
1363
+ };
1364
+ var updateEvent2 = (instruction)=>{
1365
+ const data = instruction.data;
1366
+ const source = instruction.source;
1367
+ const { name, sourceValue, targetValue } = data;
1368
+ source.removeEventListener(name, sourceValue);
1369
+ source.addEventListener(name, targetValue);
1370
+ };
1371
+ var changeValue2 = (instruction)=>{
1372
+ const data = instruction.data;
1373
+ const source = instruction.source;
1374
+ const { value } = data;
1375
+ source.value = value;
1376
+ };
1377
+ var performers = {
1378
+ [ChangeInstructions.changeText]: changeText2,
1379
+ [ChangeInstructions.removeNode]: removeNode2,
1380
+ [ChangeInstructions.insertNode]: insertNode2,
1381
+ [ChangeInstructions.replaceNode]: replaceNode2,
1382
+ [ChangeInstructions.removeAttribute]: removeAttribute2,
1383
+ [ChangeInstructions.addAttribute]: addAttribute2,
1384
+ [ChangeInstructions.updateAttribute]: updateAttribute2,
1385
+ [ChangeInstructions.removeEvent]: removeEvent2,
1386
+ [ChangeInstructions.addEvent]: addEvent2,
1387
+ [ChangeInstructions.updateEvent]: updateEvent2,
1388
+ [ChangeInstructions.changeValue]: changeValue2
1389
+ };
1390
+ // src/rendering/templates/bound.js
1391
+ class Bound {
1392
+ constructor(TemplateClass, viewModel, subscriptions, attributes2){
1393
+ this.TemplateClass = TemplateClass;
1394
+ this.viewModel = viewModel;
1395
+ this.attributes = attributes2 || {};
1396
+ this.subscriptions = subscriptions;
1397
+ this.dom = [];
1398
+ }
1399
+ render(renderKit) {
1400
+ this.parentElement = renderKit.parent;
1401
+ this.renderKit = renderKit;
1402
+ this.subscribeForRerender();
1403
+ this.dom = this._render(renderKit);
1404
+ return this.dom;
1405
+ }
1406
+ _render(renderKit) {
1407
+ const props = {
1408
+ ...this.attributes,
1409
+ ...this.viewModel(renderKit.state.value())
1410
+ };
1411
+ const template = this.TemplateClass(props);
1412
+ const dom = !template ? [] : template.render(renderKit);
1413
+ return dom;
1414
+ }
1415
+ rerender() {
1416
+ if (!this.parentElement) this.parentElement = this.dom[0] && this.dom[0].parentElement;
1417
+ const newDom = this._render(this.renderKit);
1418
+ change(this.dom, newDom, this.parentElement);
1419
+ if (this.parentElement) this.dom = Array.from(this.parentElement.childNodes);
1420
+ }
1421
+ subscribeForRerender() {
1422
+ this.subscriptions.forEach((storeName)=>{
1423
+ this.renderKit.subscribe(eventName(storeName), ()=>this.rerender());
1424
+ });
1425
+ }
1426
+ }
1427
+ var bind = ({ Template, viewModel, subscriptions })=>{
1428
+ subscriptions = subscriptions || [];
1429
+ return (attributes2)=>new Bound(Template, viewModel, subscriptions, attributes2);
1430
+ };
1431
+ // src/messageBus.ts
1432
+ class MessageBus {
1433
+ listeners;
1434
+ options;
1435
+ constructor(){
1436
+ this.options = {};
1437
+ this.listeners = {};
1438
+ }
1439
+ subscribe(eventName2, listener) {
1440
+ this.ensureListenerCollection(eventName2);
1441
+ this.listeners[eventName2].push(listener);
1442
+ }
1443
+ publish(eventName2, payload) {
1444
+ const listeners = this.listeners[eventName2];
1445
+ if (!listeners) return false;
1446
+ listeners.forEach((listener)=>{
1447
+ listener(payload, this.buildListenerKit(eventName2));
1448
+ });
1449
+ return true;
1450
+ }
1451
+ ensureListenerCollection(eventName2) {
1452
+ if (this.listeners[eventName2]) return;
1453
+ this.listeners[eventName2] = [];
1454
+ }
1455
+ buildListenerKit(eventName2) {
1456
+ return {
1457
+ eventName: eventName2,
1458
+ publish: this.publish.bind(this),
1459
+ ...this.options
1460
+ };
1461
+ }
1462
+ addListenerOptions(options) {
1463
+ this.options = {
1464
+ ...this.options,
1465
+ ...options
1466
+ };
1467
+ }
1468
+ }
1469
+ var createBus = ()=>{
1470
+ const bus = new MessageBus;
1471
+ const publish = bus.publish.bind(bus);
1472
+ const subscribe = bus.subscribe.bind(bus);
1473
+ return {
1474
+ bus,
1475
+ publish,
1476
+ subscribe
1477
+ };
1478
+ };
1479
+ // src/navigation/routeState.js
1480
+ var createRouteState = (state2)=>{
1481
+ const store = new RecordStore({
1482
+ name: "route",
1483
+ value: {
1484
+ host: "",
1485
+ path: "",
1486
+ query: ""
1487
+ },
1488
+ parent: state2
1489
+ });
1490
+ state2.add(store);
1491
+ };
1492
+ // src/navigation/setupHistory.js
1493
+ var locationChangeEvent = "locationChange";
1494
+ var routeChangeEvent = "routeChange";
1495
+ var extractQueryParams = (queryString)=>{
1496
+ return queryString.replace(/^\?/, "").split("&").reduce((aggregate, pairString)=>{
1497
+ if (!pairString) return aggregate;
1498
+ const pair = pairString.split("=");
1499
+ aggregate[pair[0]] = pair[1];
1500
+ return aggregate;
1501
+ }, {});
1502
+ };
1503
+ var onLocationChange = (_payload, { publish, state: state2 })=>{
1504
+ const { host, pathname, search } = window.location;
1505
+ const path = pathname;
1506
+ const query = extractQueryParams(search);
1507
+ state2.route.update({
1508
+ host,
1509
+ path,
1510
+ query
1511
+ });
1512
+ publish(routeChangeEvent, {
1513
+ host,
1514
+ path,
1515
+ query
1516
+ });
1517
+ };
1518
+ var setupHistory = (app)=>{
1519
+ const { publish, subscribe, state: state2 } = app;
1520
+ createRouteState(state2);
1521
+ window.addEventListener("popstate", ()=>publish(locationChangeEvent));
1522
+ subscribe(locationChangeEvent, onLocationChange);
1523
+ };
1524
+ // src/navigation/findHref.js
1525
+ var findHref = (node2)=>{
1526
+ if (!node2 || !node2.getAttribute) return "";
1527
+ while(!node2.getAttribute("href")){
1528
+ node2 = node2.parentNode;
1529
+ if (!node2 || !node2.getAttribute) return "";
1530
+ }
1531
+ return node2.getAttribute("href");
1532
+ };
1533
+ // src/navigation/setupNavigation.js
1534
+ var linkNavigationEvent = "goToHref";
1535
+ var programmaticNavigationEvent = "navigate";
1536
+ var navigate = (path, { publish })=>{
1537
+ window.history.pushState(null, "", path);
1538
+ publish(locationChangeEvent);
1539
+ };
1540
+ var onLinkClick = (domEvent, { publish })=>{
1541
+ if (!domEvent || !domEvent.target) return;
1542
+ domEvent.preventDefault();
1543
+ const href = findHref(domEvent.target);
1544
+ navigate(href, {
1545
+ publish
1546
+ });
1547
+ };
1548
+ var setupNavigation = (app)=>{
1549
+ const { subscribe } = app;
1550
+ subscribe(linkNavigationEvent, onLinkClick);
1551
+ subscribe(programmaticNavigationEvent, navigate);
1552
+ };
1553
+ // src/app.ts
1554
+ var setupBus = (app)=>{
1555
+ const { publish, subscribe, bus } = createBus();
1556
+ app.publish = publish;
1557
+ app.subscribe = subscribe;
1558
+ app.bus = bus;
1559
+ };
1560
+ var setupState = (app)=>{
1561
+ const state3 = new State(app.publish);
1562
+ app.state = state3;
1563
+ };
1564
+ var connectBusToState = (app)=>{
1565
+ const { bus } = app;
1566
+ bus.addListenerOptions({
1567
+ state: app.state
1568
+ });
1569
+ };
1570
+ var setupRenderKit = (app, document)=>{
1571
+ app.renderKit = {
1572
+ publish: app.publish,
1573
+ subscribe: app.subscribe,
1574
+ state: app.state,
1575
+ document
1576
+ };
1577
+ };
1578
+ var triggerRoute = (app)=>{
1579
+ const publish = app.publish;
1580
+ setTimeout(()=>{
1581
+ publish(locationChangeEvent, null);
1582
+ }, 0);
1583
+ };
1584
+ var addRender = (app)=>{
1585
+ app.render = (template, selector)=>{
1586
+ return render(template, selector, app.renderKit);
1587
+ };
1588
+ };
1589
+ var createApp = (document = window.document)=>{
1590
+ const app = {};
1591
+ setupBus(app);
1592
+ setupState(app);
1593
+ connectBusToState(app);
1594
+ setupRenderKit(app, document);
1595
+ setupHistory(app);
1596
+ setupNavigation(app);
1597
+ triggerRoute(app);
1598
+ addRender(app);
1599
+ return app;
1600
+ };
1601
+ // src/navigation.ts
1602
+ var exports_navigation = {};
1603
+ __export(exports_navigation, {
1604
+ setupNavigation: ()=>{
1605
+ return setupNavigation;
1606
+ },
1607
+ setupHistory: ()=>{
1608
+ return setupHistory;
1609
+ }
1610
+ });
1611
+ // src/views/conditionals.jsx
1612
+ var exports_conditionals = {};
1613
+ __export(exports_conditionals, {
1614
+ Unless: ()=>{
1615
+ return Unless;
1616
+ },
1617
+ IfElse: ()=>{
1618
+ return IfElse;
1619
+ },
1620
+ If: ()=>{
1621
+ return If;
1622
+ }
1623
+ });
1624
+ var If = ({ condition, children: children3 })=>{
1625
+ if (!condition) return;
1626
+ return jsx_default(jsx_default.fragment, null, children3);
1627
+ };
1628
+ var Unless = ({ condition, children: children3 })=>{
1629
+ if (condition) return;
1630
+ return jsx_default(jsx_default.fragment, null, children3);
1631
+ };
1632
+ var IfElse = ({ condition, children: children3 })=>{
1633
+ const [first, ...rest] = children3;
1634
+ if (condition) return jsx_default(jsx_default.fragment, null, first);
1635
+ return jsx_default(jsx_default.fragment, null, rest);
1636
+ };
1637
+ // src/views/link.jsx
1638
+ var Link = ({ children: children3, ...props })=>{
1639
+ return jsx_default("a", {
1640
+ ...props,
1641
+ onClick: "goToHref"
1642
+ }, children3);
1643
+ };
1644
+ // src/views.js
1645
+ var views = {
1646
+ ...exports_conditionals,
1647
+ Link
1648
+ };
1649
+
1650
+ },{"@parcel/transformer-js/src/esmodule-helpers.js":"gkKU3"}],"gkKU3":[function(require,module,exports) {
1651
+ exports.interopDefault = function(a) {
1652
+ return a && a.__esModule ? a : {
1653
+ default: a
1654
+ };
1655
+ };
1656
+ exports.defineInteropFlag = function(a) {
1657
+ Object.defineProperty(a, "__esModule", {
1658
+ value: true
1659
+ });
1660
+ };
1661
+ exports.exportAll = function(source, dest) {
1662
+ Object.keys(source).forEach(function(key) {
1663
+ if (key === "default" || key === "__esModule" || Object.prototype.hasOwnProperty.call(dest, key)) return;
1664
+ Object.defineProperty(dest, key, {
1665
+ enumerable: true,
1666
+ get: function() {
1667
+ return source[key];
1668
+ }
1669
+ });
1670
+ });
1671
+ return dest;
1672
+ };
1673
+ exports.export = function(dest, destName, get) {
1674
+ Object.defineProperty(dest, destName, {
1675
+ enumerable: true,
1676
+ get: get
1677
+ });
1678
+ };
1679
+
1680
+ },{}]},["gAaC1"], null, "parcelRequireee15")
1681
+
1682
+ //# sourceMappingURL=add-remove-root-children.3bb9b3f5.js.map