jaxs 0.3.2 → 0.4.2

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 (69) hide show
  1. package/dist/jaxs.d.ts +648 -0
  2. package/dist/jaxs.js +810 -1071
  3. package/dist/jaxs.umd.cjs +1 -0
  4. package/package.json +41 -34
  5. package/.env +0 -1
  6. package/README.md +0 -15
  7. package/bun.lockb +0 -0
  8. package/bundle.ts +0 -5
  9. package/bunfig.toml +0 -0
  10. package/cypress/e2e/add-remove-nested-children.cy.js +0 -39
  11. package/cypress/e2e/add-remove-root-children.cy.js +0 -37
  12. package/cypress/e2e/svg-renders.cy.js +0 -10
  13. package/cypress/jaxs-apps/add-remove-nested-children.html +0 -12
  14. package/cypress/jaxs-apps/add-remove-nested-children.jsx +0 -85
  15. package/cypress/jaxs-apps/add-remove-root-children.html +0 -15
  16. package/cypress/jaxs-apps/add-remove-root-children.jsx +0 -54
  17. package/cypress/jaxs-apps/dist/add-remove-nested-children.afcab974.js +0 -1022
  18. package/cypress/jaxs-apps/dist/add-remove-nested-children.afcab974.js.map +0 -1
  19. package/cypress/jaxs-apps/dist/add-remove-nested-children.html +0 -12
  20. package/cypress/jaxs-apps/dist/add-remove-root-children.3bb9b3f5.js +0 -1665
  21. package/cypress/jaxs-apps/dist/add-remove-root-children.3bb9b3f5.js.map +0 -1
  22. package/cypress/jaxs-apps/dist/add-remove-root-children.fbb4ec9b.js +0 -1011
  23. package/cypress/jaxs-apps/dist/add-remove-root-children.fbb4ec9b.js.map +0 -1
  24. package/cypress/jaxs-apps/dist/add-remove-root-children.html +0 -15
  25. package/cypress/jaxs-apps/dist/svg.04290504.js +0 -644
  26. package/cypress/jaxs-apps/dist/svg.04290504.js.map +0 -1
  27. package/cypress/jaxs-apps/dist/svg.html +0 -11
  28. package/cypress/jaxs-apps/svg.html +0 -11
  29. package/cypress/jaxs-apps/svg.jsx +0 -15
  30. package/cypress/support/commands.js +0 -25
  31. package/cypress/support/e2e.js +0 -20
  32. package/cypress.config.js +0 -10
  33. package/src/app.ts +0 -84
  34. package/src/debugging.js +0 -5
  35. package/src/jaxs.ts +0 -7
  36. package/src/jsx.js +0 -27
  37. package/src/messageBus.ts +0 -70
  38. package/src/navigation/findHref.js +0 -10
  39. package/src/navigation/routeState.js +0 -15
  40. package/src/navigation/setupHistory.js +0 -38
  41. package/src/navigation/setupNavigation.js +0 -25
  42. package/src/navigation.ts +0 -2
  43. package/src/rendering/change/compile.ts +0 -1
  44. package/src/rendering/change/instructions/attributes.ts +0 -81
  45. package/src/rendering/change/instructions/children.ts +0 -127
  46. package/src/rendering/change/instructions/element.ts +0 -49
  47. package/src/rendering/change/instructions/events.ts +0 -51
  48. package/src/rendering/change/instructions/generate.ts +0 -122
  49. package/src/rendering/change/instructions/idMap.js +0 -55
  50. package/src/rendering/change/instructions/node.ts +0 -55
  51. package/src/rendering/change/instructions/text.ts +0 -10
  52. package/src/rendering/change.ts +0 -139
  53. package/src/rendering/dom/attributesAndEvents.ts +0 -33
  54. package/src/rendering/dom/create.ts +0 -66
  55. package/src/rendering/dom/svg.ts +0 -18
  56. package/src/rendering/templates/bound.js +0 -56
  57. package/src/rendering/templates/children.ts +0 -99
  58. package/src/rendering/templates/root.ts +0 -55
  59. package/src/rendering/templates/tag.ts +0 -92
  60. package/src/rendering/templates/text.ts +0 -17
  61. package/src/state/equality.js +0 -36
  62. package/src/state/stores.js +0 -63
  63. package/src/state/testingTypes.js +0 -6
  64. package/src/state.js +0 -89
  65. package/src/types.ts +0 -160
  66. package/src/views/conditionals.jsx +0 -18
  67. package/src/views/link.jsx +0 -5
  68. package/src/views.js +0 -7
  69. package/tsconfig.json +0 -26
package/dist/jaxs.js CHANGED
@@ -1,1156 +1,895 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, {
5
- get: all[name],
6
- enumerable: true,
7
- configurable: true,
8
- set: (newValue) => all[name] = () => newValue
9
- });
10
- };
11
-
12
- // src/rendering/dom/create.ts
13
- var setAttributesOnElement = (element, attributes) => {
14
- for (const key in attributes) {
15
- if (key === "__self")
16
- continue;
17
- if (key === "value") {
18
- element.value = attributes[key];
19
- } else {
20
- element.setAttribute(key, attributes[key]);
21
- }
22
- }
23
- };
24
- var setEventsOnElement = (element, events, publish) => {
25
- const eventMaps = {};
26
- for (const domEvent in events) {
27
- const eventName = events[domEvent];
28
- const listener = (event) => publish(eventName, event);
29
- element.addEventListener(domEvent, listener);
30
- eventMaps[domEvent] = {
31
- domEvent,
32
- busEvent: eventName,
33
- listener
1
+ const tt = (e, t) => t.createElement(e), et = (e, t) => {
2
+ for (const s in t) {
3
+ if (s === "__self") continue;
4
+ const n = t[s].toString();
5
+ s === "value" ? e.value = n : e.setAttribute(s, n);
6
+ }
7
+ }, st = (e, t, s) => {
8
+ const n = {};
9
+ for (const r in t) {
10
+ const o = t[r], a = (h) => s(o, h);
11
+ e.addEventListener(r, a), n[r] = {
12
+ domEvent: r,
13
+ busEvent: o,
14
+ listener: a
34
15
  };
35
16
  }
36
- element.eventMaps = eventMaps;
37
- };
38
- var createNode = (type, document) => {
39
- return document.createElement(type);
40
- };
41
- var createTextNode = (value, document) => {
42
- return document.createTextNode(value);
43
- };
44
- var createDecoratedNode = (type, attributes, events, renderKit) => {
45
- const dom = createNode(type, renderKit.document);
46
- setAttributesOnElement(dom, attributes);
47
- setEventsOnElement(dom, events, renderKit.publish);
48
- return dom;
49
- };
50
-
51
- // src/rendering/dom/attributesAndEvents.ts
52
- var separateAttrsAndEvents = (combined, defaultValue = "") => {
53
- const attributes = {};
54
- const events = {};
55
- for (const key in combined) {
56
- const value = combined[key];
57
- if (key.match(/^on.+/i)) {
58
- const eventKey = key.slice(2).toLowerCase();
59
- events[eventKey] = value;
17
+ e.eventMaps = n;
18
+ }, nt = (e, t, s, n) => {
19
+ const r = tt(e, n.document);
20
+ return et(r, t), st(r, s, n.publish), r;
21
+ }, N = "http://www.w3.org/2000/svg", rt = (e) => e === "svg", ot = (e, t, s) => {
22
+ const n = s.createElementNS(N, e);
23
+ for (const r in t)
24
+ r === "__self" || r === "xmlns" || n.setAttributeNS(null, r, t[r].toString());
25
+ return n;
26
+ }, it = (e) => e.namespaceURI === N, at = (e, t) => t.createTextNode(e);
27
+ class ct {
28
+ constructor(t) {
29
+ this.value = t.toString(), this.isSvg = !1;
30
+ }
31
+ render(t) {
32
+ const s = at(this.value, t.document);
33
+ return s.__jsx = "TextNode", [s];
34
+ }
35
+ }
36
+ const ut = (e) => typeof e == "string" || typeof e == "number", ht = (e) => new ct(e), lt = (e) => ut(e) ? ht(e) : e, dt = (e) => (t) => (t && (t.isSvg = t.isSvg || e), t), pt = (e, t) => mt(e).map(lt).flat().map(dt(t)), mt = (e) => Array.isArray(e) ? e.flat() : e ? [e] : [], j = (e, t = {}) => e || t.children || [], bt = (e, t = "") => {
37
+ const s = {}, n = {};
38
+ for (const r in e) {
39
+ const o = e[r];
40
+ if (r.match(/^on.+/i)) {
41
+ const a = r.slice(2).toLowerCase();
42
+ n[a] = o ? o.toString() : "";
60
43
  } else {
61
- attributes[key] = normalizeValueForKey(combined, key, defaultValue);
44
+ if (o === !1) continue;
45
+ r === "__source" ? s.__source = e.__source : s[r] = ft(r, o, t);
62
46
  }
63
47
  }
64
48
  return {
65
- attributes,
66
- events
49
+ attributes: s,
50
+ events: n
67
51
  };
68
- };
69
- var normalizeValueForKey = (object, key, defaultValue = "") => {
70
- if (object[key] === undefined)
71
- return defaultValue;
72
- return object[key];
73
- };
74
-
75
- // src/rendering/dom/svg.ts
76
- var namespace = "http://www.w3.org/2000/svg";
77
- var isSvgTag = (tagType) => tagType === "svg";
78
- var isSvg = (element) => element.namespaceURI === namespace;
79
- var createSvgNode = (type, attributes, renderKit) => {
80
- const { document } = renderKit;
81
- const node = document.createElementNS(namespace, type);
82
- for (const key in attributes) {
83
- if (key === "__self" || key === "xmlns")
84
- continue;
85
- node.setAttributeNS(null, key, attributes[key]);
86
- }
87
- return node;
88
- };
89
-
90
- // src/rendering/templates/text.ts
91
- class TextTemplate {
92
- value;
93
- constructor(content) {
94
- this.value = content.toString();
95
- }
96
- render(renderKit) {
97
- const textNode = createTextNode(this.value, renderKit.document);
98
- if (!textNode)
99
- return [];
100
- textNode.__jsx = "TextNode";
101
- return [textNode];
102
- }
103
- }
104
-
105
- // src/rendering/templates/children.ts
106
- var ensureArray = (children) => {
107
- if (Array.isArray(children)) {
108
- return children.flat();
109
- }
110
- if (!children) {
111
- return [];
112
- }
113
- return [children];
114
- };
115
- var recursiveRender = (children, renderKit, rendered = []) => children.reduce(renderReducer(renderKit), rendered).flat();
116
- var renderReducer = (renderKit) => (aggregate, view) => {
117
- if (!view)
118
- return aggregate;
119
- if (Array.isArray(view)) {
120
- const dom = recursiveRender(view, renderKit, aggregate);
121
- return dom;
122
- }
123
- view.render(renderKit).forEach((template) => aggregate.push(template));
124
- return aggregate;
125
- };
126
- var replaceTextNodes = (child) => {
127
- if (isTextNode(child)) {
128
- return textNode(child);
129
- }
130
- return child;
131
- };
132
- var isTextNode = (child) => {
133
- return typeof child === "string" || typeof child === "number";
134
- };
135
- var textNode = (content) => {
136
- return new TextTemplate(content);
137
- };
138
- var withSvgFlag = (isSvg2) => (template) => {
139
- template && (template.isSvg = template.isSvg || isSvg2);
140
- return template;
141
- };
142
-
143
- class Children {
144
- collection;
145
- parentElement;
146
- isSvg;
147
- constructor(jsxChildren, isSvg2 = false) {
148
- this.collection = ensureArray(jsxChildren);
149
- this.collection = this.collection.map(replaceTextNodes);
150
- this.collection = this.collection.flat();
151
- this.collection = this.collection.map(withSvgFlag(isSvg2));
152
- this.isSvg = isSvg2;
153
- }
154
- render(renderKit, parentElement) {
155
- this.parentElement = parentElement;
156
- const dom = this.generateDom(renderKit);
157
- this.attachToParent(dom);
158
- return dom;
159
- }
160
- generateDom(renderKit) {
161
- return recursiveRender(this.collection, renderKit);
162
- }
163
- attachToParent(dom) {
164
- if (this.parentElement === undefined)
165
- return;
166
- const parent = this.parentElement;
167
- dom.forEach((node) => parent.appendChild(node));
52
+ }, ft = (e, t, s = "") => t == null ? s : t.toString(), vt = (e, t) => {
53
+ const s = e || {}, n = j(t, s);
54
+ return s.children = s.children || n, s;
55
+ }, k = (e, t, s = []) => e.reduce(gt(t), s).flat(), gt = (e) => (t, s) => s ? Array.isArray(s) ? k(s, e, t) : (s.render(e).forEach((n) => t.push(n)), t) : t;
56
+ class O {
57
+ constructor(t, s = !1) {
58
+ this.collection = pt(t, s), this.isSvg = s;
59
+ }
60
+ render(t, s) {
61
+ this.parentElement = s;
62
+ const n = this.generateDom(t);
63
+ return this.attachToParent(n), n;
64
+ }
65
+ generateDom(t) {
66
+ return k(this.collection, t);
67
+ }
68
+ attachToParent(t) {
69
+ if (this.parentElement === void 0) return;
70
+ const s = this.parentElement;
71
+ t.forEach((n) => s.appendChild(n));
168
72
  }
169
73
  }
170
-
171
- // src/rendering/templates/tag.ts
172
- class Tag {
173
- type;
174
- events;
175
- attributes;
176
- children;
177
- isSvg;
178
- constructor(tagType, combinedAttributes, children2, isSvg2 = false) {
179
- this.type = tagType;
180
- const { events, attributes } = separateAttrsAndEvents(combinedAttributes);
181
- this.events = events;
182
- this.attributes = attributes;
183
- this.isSvg = isSvg2 || isSvgTag(this.type);
184
- this.children = new Children(children2, this.isSvg);
185
- }
186
- render(renderKit) {
187
- const dom = this.generateDom(renderKit);
188
- if (!dom)
189
- return [];
190
- this.children.render(renderKit, dom);
191
- return [dom];
192
- }
193
- generateDom(renderKit) {
194
- if (this.isSvg) {
195
- return this.generateSvnDom(renderKit);
196
- } else {
197
- return this.generateHtmlDom(renderKit);
198
- }
199
- }
200
- generateHtmlDom(renderKit) {
201
- const node = createDecoratedNode(this.type, this.attributes, this.events, renderKit);
202
- node.__jsx = this.key();
203
- return node;
204
- }
205
- generateSvnDom(renderKit) {
206
- const node = createSvgNode(this.type, this.attributes, renderKit);
207
- node.__jsx = this.key();
208
- return node;
74
+ class yt {
75
+ constructor(t, s) {
76
+ this.type = t, this.attributes = s;
209
77
  }
210
- key() {
211
- return this.attributes.key || this.source() || this.createKey();
78
+ generate() {
79
+ return this.attributes.key || this.sourceKey() || this.createKeyFromAttributes();
212
80
  }
213
- source() {
81
+ sourceKey() {
214
82
  if (this.attributes.__source) {
215
- const { fileName, lineNumber, columnNumber } = this.attributes.__source;
216
- return `${fileName}:${lineNumber}:${columnNumber}`;
83
+ const { fileName: t, lineNumber: s, columnNumber: n } = this.attributes.__source;
84
+ return `${t}:${s}:${n}`;
217
85
  }
218
86
  }
219
- createKey() {
220
- const id = this.attributes.id ? `#${this.attributes.id}` : "";
221
- const type = this.attributes.type ? `[type=${this.attributes.type}]` : "";
222
- const name = this.attributes.name ? `[name=${this.attributes.name}]` : "";
223
- return `${this.type}${id}${type}${name}`;
87
+ createKeyFromAttributes() {
88
+ const t = this.attributes.id ? `#${this.attributes.id}` : "", s = this.attributes.type ? `[type=${this.attributes.type}]` : "", n = this.attributes.name ? `[name=${this.attributes.name}]` : "";
89
+ return `${this.type}${t}${s}${n}`;
224
90
  }
225
91
  }
226
-
227
- // src/jsx.js
228
- var ensureChildrenArray = (maybeChildren, attributes) => maybeChildren || attributes.children || [];
229
- var packageAttributes = (maybeAttributes, maybeChildren) => {
230
- const attributes = maybeAttributes || {};
231
- const children3 = ensureChildrenArray(maybeChildren, attributes);
232
- attributes.children = attributes.children || children3;
233
- return attributes;
234
- };
235
- var jsx = (type, attributes, ...children3) => {
236
- if (typeof type === "string") {
237
- return new Tag(type, attributes, children3);
92
+ class Et {
93
+ constructor(t, s, n = [], r = !1) {
94
+ this.type = t;
95
+ const { events: o, attributes: a } = bt(s);
96
+ this.events = o, this.attributes = a, this.isSvg = r || rt(this.type), this.children = new O(n, this.isSvg);
97
+ }
98
+ render(t) {
99
+ const s = this.generateDom(t);
100
+ return s ? (this.children.render(t, s), [s]) : [];
101
+ }
102
+ generateDom(t) {
103
+ return this.isSvg ? this.generateSvgDom(t) : this.generateHtmlDom(t);
104
+ }
105
+ generateHtmlDom(t) {
106
+ const s = nt(
107
+ this.type,
108
+ this.attributes,
109
+ this.events,
110
+ t
111
+ );
112
+ return s.__jsx = this.jsxKey(), s;
113
+ }
114
+ generateSvgDom(t) {
115
+ const s = ot(this.type, this.attributes, t.document);
116
+ return s.__jsx = this.jsxKey(), s;
117
+ }
118
+ jsxKey() {
119
+ return new yt(this.type, this.attributes).generate();
238
120
  }
239
- return type(packageAttributes(attributes, children3));
240
- };
241
- jsx.fragment = (attributes, maybeChildren) => {
242
- const children3 = ensureChildrenArray(maybeChildren, attributes);
243
- return new Children(children3);
121
+ }
122
+ const At = (e, t, ...s) => typeof e == "string" ? new Et(e, t, s) : e(vt(t, s));
123
+ At.fragment = (e, t) => {
124
+ const s = j(t, e);
125
+ return new O(s);
244
126
  };
245
- var jsx_default = jsx;
246
- // src/rendering/templates/root.ts
247
- class Root {
248
- template;
249
- selector;
250
- renderKit;
251
- dom;
252
- parentElement;
253
- constructor(template, selector, renderKit) {
254
- this.template = template;
255
- this.selector = selector;
256
- this.renderKit = renderKit;
257
- this.dom = [];
258
- this.parentElement = null;
259
- }
260
- renderAndAttach(renderKit) {
261
- this.parentElement = this.getParentElement();
262
- this.dom = this.render({ ...renderKit, parent: this.parentElement });
263
- if (this.parentElement) {
264
- this.attach();
265
- }
127
+ class St {
128
+ constructor(t, s, n) {
129
+ this.template = t, this.selector = s, this.renderKit = n, this.dom = [];
130
+ }
131
+ renderAndAttach(t) {
132
+ this.parentElement = this.getParentElement(), this.dom = this.render({ ...t, parent: this.parentElement }), this.parentElement && this.attach();
266
133
  }
267
- render(renderKit) {
268
- return this.template.render(renderKit);
134
+ render(t) {
135
+ return this.template.render(t);
269
136
  }
270
137
  attach() {
271
- this.parentElement && (this.parentElement.innerHTML = "");
272
- this.dom.forEach((element) => {
273
- this.parentElement && this.parentElement.appendChild(element);
138
+ this.parentElement && (this.parentElement.innerHTML = ""), this.dom.forEach((t) => {
139
+ this.parentElement && this.parentElement.appendChild(t);
274
140
  });
275
141
  }
276
142
  getParentElement() {
277
143
  return this.renderKit.document.querySelector(this.selector);
278
144
  }
279
145
  }
280
- var render = (template, selector, renderKit) => {
281
- const root = new Root(template, selector, renderKit);
282
- root.renderAndAttach(renderKit);
283
- return root;
284
- };
285
- // src/state/testingTypes.js
286
- var isBoolean = (value) => typeof value === "boolean";
287
- var isNumber = (value) => typeof value === "number";
288
- var isString = (value) => typeof value === "string";
289
- var isArray = (value) => Array.isArray(value);
290
- var isObject = (value) => value !== null && !isArray(value) && typeof value === "object";
291
-
292
- // src/state/equality.js
293
- var areElementEqual = (oldValue, newValue) => oldValue === newValue;
294
- var keyLengthSame = (oldValue, newValue) => Object.keys(oldValue).length === Object.keys(newValue).length;
295
- var areObjectsEqual = (oldValue, newValue) => {
296
- if (!(isObject(oldValue) && isObject(newValue)))
297
- return false;
298
- if (!keyLengthSame(oldValue, newValue))
299
- return false;
300
- Object.keys(oldValue).every((key) => {
301
- const oldInnerValue = oldValue[key];
302
- const newInnerValue = newValue[key];
303
- return areEqual(oldInnerValue, newInnerValue);
146
+ const xt = (e, t, s) => {
147
+ const n = new St(e, t, s);
148
+ return n.renderAndAttach(s), n;
149
+ }, $ = "go-to-href", m = "navigation:location-change", M = "navigation:route-change", wt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
150
+ __proto__: null,
151
+ linkNavigationEvent: $,
152
+ locationChangeEvent: m,
153
+ routeChangeEvent: M
154
+ }, Symbol.toStringTag, { value: "Module" })), F = (e) => {
155
+ e.createRecord("route", {
156
+ host: "",
157
+ path: "",
158
+ query: {}
304
159
  });
305
- };
306
- var areArraysEqual = (oldValue, newValue) => {
307
- if (!(isArray(oldValue) && isArray(newValue)))
308
- return false;
309
- if (oldValue.length !== newValue.length)
310
- return false;
311
- oldValue.every((oldInnerValue, index) => {
312
- const newInnerValue = newValue[index];
313
- return areEqual(oldInnerValue, newInnerValue);
314
- });
315
- };
316
- var areEqual = (oldValue, newValue) => {
317
- if (isObject(oldValue))
318
- return areObjectsEqual(oldValue, newValue);
319
- if (isArray(oldValue))
320
- return areArraysEqual(oldValue, newValue);
321
- return areElementEqual(oldValue, newValue);
322
- };
323
-
324
- // src/state/stores.js
325
- class GeneralStore {
326
- nullEvent = {};
327
- constructor({ name, value, parent }) {
328
- this.name = name;
329
- this.value = value;
330
- this.parent = parent;
331
- this.initialState = value;
332
- }
333
- update(newValue) {
334
- if (this.isEqual(newValue))
335
- return;
336
- this.value = newValue;
337
- return this.parent.publish(this.event());
160
+ }, T = (e) => {
161
+ const t = e.closest("[href]");
162
+ return t && t.getAttribute("href") || "";
163
+ }, D = (e, { publish: t, window: s }) => {
164
+ s.history.pushState(null, "", e), t(m, null);
165
+ }, U = (e, t) => {
166
+ if (!e || !e.target) return;
167
+ e.preventDefault();
168
+ const s = T(e.target);
169
+ D(s, t);
170
+ }, z = (e) => e.replace(/^\?/, "").split("&").reduce((t, s) => {
171
+ if (!s) return t;
172
+ const n = s.split("=");
173
+ return t[n[0]] = n[1], t;
174
+ }, {}), L = (e, t) => {
175
+ const { state: s, publish: n, window: r } = t, { host: o, pathname: a, search: h } = r.location, i = a, d = z(h), u = {
176
+ host: o,
177
+ path: i,
178
+ query: d
179
+ };
180
+ s.store("route").update(u), n(M, u);
181
+ }, B = (e) => {
182
+ const { subscribe: t } = e;
183
+ t($, U);
184
+ }, P = (e) => {
185
+ const { publish: t, subscribe: s, state: n, window: r } = e;
186
+ F(n), r.addEventListener("popstate", () => t(m, null)), s(m, L);
187
+ }, V = (e) => {
188
+ setTimeout(() => e.publish(m, null), 0);
189
+ }, K = (e) => {
190
+ P(e), B(e), V(e);
191
+ }, _t = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
192
+ __proto__: null,
193
+ publishLocation: V,
194
+ startNavigation: K,
195
+ subscribeToHistoryChange: P,
196
+ subscribeToNavigation: B
197
+ }, Symbol.toStringTag, { value: "Module" }));
198
+ class R {
199
+ constructor({ window: t, document: s, publish: n, subscribe: r, bus: o, state: a, renderKit: h }) {
200
+ this.window = t, this.document = s, this.publish = n, this.subscribe = r, this.bus = o, this.state = a, this.renderKit = h, this.roots = [];
201
+ }
202
+ render(t, s) {
203
+ const n = xt(t, s, this.renderKit);
204
+ return this.roots.push(n), n;
205
+ }
206
+ startNavigation() {
207
+ K(this);
338
208
  }
339
- reset() {
340
- this.update(this.initialState);
209
+ }
210
+ const pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
211
+ __proto__: null,
212
+ App: R
213
+ }, Symbol.toStringTag, { value: "Module" }));
214
+ class q {
215
+ constructor() {
216
+ this.lookup = {};
217
+ }
218
+ add(t, s, n) {
219
+ this.ensureArrayFor(t);
220
+ const r = {
221
+ listener: s,
222
+ index: n,
223
+ matcher: t
224
+ };
225
+ return this.lookup[t].push(r), () => this.remove(r);
226
+ }
227
+ remove(t) {
228
+ this.lookup[t.matcher] && (this.lookup[t.matcher] = this.lookup[t.matcher].reduce((s, n) => (n !== t && s.push(n), s), []));
229
+ }
230
+ matches(t) {
231
+ return this.lookup[t] || [];
232
+ }
233
+ ensureArrayFor(t) {
234
+ this.lookup[t] || (this.lookup[t] = []);
235
+ }
236
+ }
237
+ class J {
238
+ constructor() {
239
+ this.lookup = [];
240
+ }
241
+ add(t, s, n) {
242
+ const r = {
243
+ listener: s,
244
+ index: n,
245
+ matcher: t
246
+ };
247
+ return this.lookup.push(r), () => this.remove(r);
341
248
  }
342
- isEqual(newValue) {
343
- return areElementEqual(this.value, newValue);
249
+ remove(t) {
250
+ this.lookup = this.lookup.reduce((s, n) => (n !== t && s.push(n), s), []);
344
251
  }
345
- event() {
252
+ matches(t) {
253
+ return this.lookup.filter(
254
+ (s) => s.matcher.test(t)
255
+ );
256
+ }
257
+ }
258
+ class H {
259
+ constructor() {
260
+ this.exactSubscriptions = new q(), this.fuzzySubscriptions = new J(), this.currentIndex = 0;
261
+ }
262
+ subscribe(t, s) {
263
+ let n;
264
+ return typeof t == "string" ? n = this.exactSubscriptions.add(
265
+ t,
266
+ s,
267
+ this.currentIndex
268
+ ) : n = this.fuzzySubscriptions.add(
269
+ t,
270
+ s,
271
+ this.currentIndex
272
+ ), this.currentIndex += 1, n;
273
+ }
274
+ publish(t, s) {
275
+ [
276
+ ...this.exactSubscriptions.matches(t),
277
+ ...this.fuzzySubscriptions.matches(t)
278
+ ].sort((r, o) => r.index - o.index).forEach((r) => {
279
+ r.listener(s, this.listenerOptions(t));
280
+ });
281
+ }
282
+ addListenerOptions(t) {
283
+ this.options = t;
284
+ }
285
+ listenerOptions(t) {
346
286
  return {
347
- name: this.name,
348
- value: this.value
287
+ eventName: t,
288
+ ...this.options,
289
+ publish: this.publish.bind(this)
349
290
  };
350
291
  }
351
292
  }
352
-
353
- class BooleanStore extends GeneralStore {
354
- toggle() {
355
- this.update(!this.value);
293
+ const I = () => {
294
+ const e = new H();
295
+ return {
296
+ bus: e,
297
+ publish: (n, r) => e.publish(n, r),
298
+ subscribe: (n, r) => e.subscribe(n, r)
299
+ };
300
+ }, me = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
301
+ __proto__: null,
302
+ ExactSubscriptions: q,
303
+ FuzzySubscriptions: J,
304
+ JaxsBus: H,
305
+ createBus: I
306
+ }, Symbol.toStringTag, { value: "Module" })), b = (e) => Array.isArray(e), g = (e) => e !== null && !b(e) && typeof e == "object", Nt = (e, t) => e === t, jt = (e, t) => Object.keys(e).length === Object.keys(t).length, kt = (e, t) => !(g(e) && g(t)) || !jt(e, t) ? !1 : Object.keys(e).every((s) => {
307
+ const n = e[s], r = t[s];
308
+ return E(n, r);
309
+ }), Ot = (e, t) => !(b(e) && b(t)) || e.length !== t.length ? !1 : e.every((s, n) => {
310
+ const r = t[n];
311
+ return E(s, r);
312
+ }), E = (e, t) => g(e) ? kt(e, t) : b(e) ? Ot(e, t) : Nt(e, t);
313
+ class f {
314
+ constructor(t) {
315
+ this.store = t;
316
+ }
317
+ update(t) {
318
+ this.store.update(t);
319
+ }
320
+ reset() {
321
+ this.store.update(this.store.initialState);
322
+ }
323
+ get value() {
324
+ return this.store.value;
325
+ }
326
+ addUpdaterFunction(t, s) {
327
+ this.constructor.prototype[t] = (...n) => {
328
+ const r = s(this.value, ...n);
329
+ this.update(r);
330
+ };
331
+ }
332
+ addUpdaterFunctions(t) {
333
+ for (const s in t)
334
+ this.addUpdaterFunction(s, t[s]);
356
335
  }
357
336
  }
358
-
359
- class NumericStore extends GeneralStore {
337
+ class A extends f {
338
+ addUpdaterFunction(t, s) {
339
+ this.constructor.prototype[t] = (...n) => {
340
+ const r = s(this.value, ...n);
341
+ this.update(r);
342
+ };
343
+ }
344
+ push(t) {
345
+ const s = [...this.value, t];
346
+ this.update(s);
347
+ }
348
+ pop() {
349
+ const t = [...this.value], s = t.pop();
350
+ return this.update(t), s;
351
+ }
352
+ unshift(t) {
353
+ const s = [t, ...this.value];
354
+ this.update(s);
355
+ }
356
+ shift() {
357
+ const t = [...this.value], s = t.shift();
358
+ return this.update(t), s;
359
+ }
360
+ addSorter(t, s) {
361
+ this[t] = () => {
362
+ this.sortBy(s);
363
+ };
364
+ }
365
+ sortBy(t) {
366
+ const s = [...this.value];
367
+ s.sort(t), this.update(s);
368
+ }
369
+ insertAt(t, s) {
370
+ const n = [...this.value];
371
+ n.splice(t, 0, s), this.update(n);
372
+ }
360
373
  }
361
-
362
- class StringStore extends GeneralStore {
374
+ class y {
375
+ constructor(t) {
376
+ this.name = t.name, this.parent = t.parent, this._value = t.value, this.initialState = structuredClone(t.value), this.updater = new f(this);
377
+ }
378
+ get value() {
379
+ return this._value;
380
+ }
381
+ set value(t) {
382
+ throw new Error("Cannot set value directly. Use an updater!");
383
+ }
384
+ update(t) {
385
+ if (typeof t == "function") {
386
+ const s = this.getUpdatedValue(t);
387
+ this.updateValue(s);
388
+ } else
389
+ this.updateValue(t);
390
+ }
391
+ updateValue(t) {
392
+ E(this._value, t) || (this._value = t, this.parent.notify(this.name));
393
+ }
394
+ getUpdatedValue(t) {
395
+ return t(this.value);
396
+ }
397
+ addUpdaters(t) {
398
+ this.updater.addUpdaterFunctions(t);
399
+ }
400
+ addUpdater(t, s) {
401
+ this.updater.addUpdaterFunction(t, s);
402
+ }
403
+ addSorter(t, s) {
404
+ this.updater instanceof A && this.updater.addSorter(t, s);
405
+ }
363
406
  }
364
-
365
- class ListStore extends GeneralStore {
366
- isEqual(newValue) {
367
- return areArraysEqual(this.value, newValue);
407
+ class Q extends f {
408
+ toggle() {
409
+ const t = !this.value;
410
+ this.update(t);
411
+ }
412
+ setTrue() {
413
+ this.update(!0);
368
414
  }
369
- push(newValue) {
370
- const value = [...this.value, newValue];
371
- this.update(value);
415
+ setFalse() {
416
+ this.update(!1);
417
+ }
418
+ addUpdaterFunction(t, s) {
419
+ this.constructor.prototype[t] = (...n) => {
420
+ const r = s(this.value, ...n);
421
+ this.update(r);
422
+ };
372
423
  }
373
424
  }
374
-
375
- class RecordStore extends GeneralStore {
376
- isEqual(newValue) {
377
- return areObjectsEqual(this.value, newValue);
425
+ class W extends f {
426
+ addUpdaterFunction(t, s) {
427
+ this.constructor.prototype[t] = (...n) => {
428
+ const r = s(this.value, ...n);
429
+ this.update(r);
430
+ };
431
+ }
432
+ updateAttribute(t, s) {
433
+ const n = { ...this.value };
434
+ n[t] = s, this.update(n);
378
435
  }
379
436
  }
380
-
381
- // src/state.js
382
- var eventPrefix = "state-change";
383
- var eventName = (name) => `${eventPrefix}:${name}`;
384
-
385
- class State {
386
- constructor(publish) {
387
- this.publisher = publish;
388
- this.stores = {};
389
- this.events = [];
390
- this.transacting = false;
391
- }
392
- create(name, value) {
393
- const StoreClass = this.storeTypeFor(value);
394
- const store = new StoreClass({ name, value, parent: this });
395
- this.addStore(name, store);
396
- }
397
- add(store) {
398
- const name = store.name;
399
- this.addStore(name, store);
400
- }
401
- getStore(name) {
402
- return this.stores[name];
403
- }
404
- addStore(name, store) {
405
- this.stores[name] = store;
406
- this[name] = store;
407
- }
408
- storeTypeFor(value) {
409
- if (isArray(value))
410
- return ListStore;
411
- if (isObject(value))
412
- return RecordStore;
413
- if (isNumber(value))
414
- return NumericStore;
415
- if (isBoolean(value))
416
- return BooleanStore;
417
- if (isString(value))
418
- return StringStore;
419
- return GeneralStore;
420
- }
421
- publish(event) {
422
- this.events.push(event);
423
- if (!this.transacting)
424
- this.publishAll();
437
+ const S = "state";
438
+ class G {
439
+ constructor(t) {
440
+ this.publisher = t, this.stores = {}, this.eventNamePrefix = S, this.notifications = /* @__PURE__ */ new Set(), this.inTransaction = !1;
441
+ }
442
+ create(t, s) {
443
+ const n = new y({
444
+ name: t,
445
+ parent: this,
446
+ value: s
447
+ });
448
+ return this.stores[t] = n, n;
449
+ }
450
+ createBoolean(t, s) {
451
+ const n = this.create(t, s);
452
+ return n.updater = new Q(n), n;
453
+ }
454
+ createRecord(t, s) {
455
+ const n = this.create(t, s);
456
+ return n.updater = new W(n), n;
457
+ }
458
+ createList(t, s) {
459
+ const n = this.create(t, s);
460
+ return n.updater = new A(n), n;
461
+ }
462
+ store(t) {
463
+ return this.stores[t] || new y({
464
+ name: t,
465
+ parent: this,
466
+ value: void 0
467
+ });
468
+ }
469
+ get(t) {
470
+ return this.store(t).value;
471
+ }
472
+ getAll(t) {
473
+ return t.reduce((s, n) => (s[n] = this.get(n), s), {});
474
+ }
475
+ notify(t) {
476
+ this.inTransaction ? this.notifications.add(t) : this.publish(t);
477
+ }
478
+ update(t, s) {
479
+ this.store(t).update(s);
480
+ }
481
+ transaction(t) {
482
+ this.inTransaction = !0, t(this.stores), this.inTransaction = !1, this.publishAll();
425
483
  }
426
484
  publishAll() {
427
- const publishedStores = [];
428
- this.events.reverse().forEach((event) => {
429
- const { name, value } = event;
430
- if (!publishedStores.includes(name)) {
431
- publishedStores.push(name);
432
- this.publisher(`${eventPrefix}:${name}`, value);
433
- }
485
+ this.notifications.forEach((t) => {
486
+ this.publish(t);
487
+ }), this.notifications.clear();
488
+ }
489
+ publish(t) {
490
+ this.publisher(this.event(t), {
491
+ state: this,
492
+ store: this.store(t)
434
493
  });
435
- this.events = [];
436
494
  }
437
- transaction(setter) {
438
- this.transacting = true;
439
- setter(this);
440
- this.transacting = false;
441
- this.publishAll();
495
+ event(t) {
496
+ return `${this.eventNamePrefix}:${t}`;
442
497
  }
443
- value() {
444
- return Object.keys(this.stores).reduce((valueObject, key) => {
445
- valueObject[key] = this.stores[key].value;
446
- return valueObject;
447
- }, {});
498
+ }
499
+ const X = (e) => new G(e), be = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
500
+ __proto__: null,
501
+ State: G,
502
+ Store: y,
503
+ StoreUpdaterBoolean: Q,
504
+ StoreUpdaterList: A,
505
+ StoreUpdaterObject: W,
506
+ createState: X,
507
+ eventName: S
508
+ }, Symbol.toStringTag, { value: "Module" }));
509
+ class $t {
510
+ constructor(t) {
511
+ this.setupDomEnvironment(t);
512
+ }
513
+ setup() {
514
+ return this.setupBus(), this.setupState(), this.addBusOptions(), this.setRenderKit(), new R({
515
+ window: this.window,
516
+ document: this.document,
517
+ publish: this.publish,
518
+ subscribe: this.subscribe,
519
+ bus: this.bus,
520
+ state: this.state,
521
+ renderKit: this.renderKit
522
+ });
523
+ }
524
+ setupDomEnvironment(t) {
525
+ t.window ? (this.window = t.window, this.document = this.window.document) : t.document ? (this.window = t.document.defaultView, this.document = t.document) : (this.window = window, this.document = document);
526
+ }
527
+ setupBus() {
528
+ const { publish: t, subscribe: s, bus: n } = I();
529
+ this.publish = t, this.subscribe = s, this.bus = n;
530
+ }
531
+ setupState() {
532
+ this.state = X(this.publish);
533
+ }
534
+ addBusOptions() {
535
+ this.bus.addListenerOptions({
536
+ state: this.state,
537
+ document: this.document,
538
+ window: this.window
539
+ });
540
+ }
541
+ setRenderKit() {
542
+ this.renderKit = {
543
+ publish: this.publish,
544
+ subscribe: this.subscribe,
545
+ state: this.state,
546
+ document: this.document,
547
+ window: this.window
548
+ };
448
549
  }
449
550
  }
450
-
451
- // src/types.ts
452
- var ChangeInstructions;
453
- (function(ChangeInstructions2) {
454
- ChangeInstructions2[ChangeInstructions2["removeNode"] = 0] = "removeNode";
455
- ChangeInstructions2[ChangeInstructions2["insertNode"] = 1] = "insertNode";
456
- ChangeInstructions2[ChangeInstructions2["replaceNode"] = 2] = "replaceNode";
457
- ChangeInstructions2[ChangeInstructions2["removeAttribute"] = 3] = "removeAttribute";
458
- ChangeInstructions2[ChangeInstructions2["addAttribute"] = 4] = "addAttribute";
459
- ChangeInstructions2[ChangeInstructions2["updateAttribute"] = 5] = "updateAttribute";
460
- ChangeInstructions2[ChangeInstructions2["removeEvent"] = 6] = "removeEvent";
461
- ChangeInstructions2[ChangeInstructions2["addEvent"] = 7] = "addEvent";
462
- ChangeInstructions2[ChangeInstructions2["updateEvent"] = 8] = "updateEvent";
463
- ChangeInstructions2[ChangeInstructions2["changeValue"] = 9] = "changeValue";
464
- ChangeInstructions2[ChangeInstructions2["changeText"] = 10] = "changeText";
465
- })(ChangeInstructions || (ChangeInstructions = {}));
466
-
467
- // src/rendering/change/instructions/generate.ts
468
- var changeText = (source, target) => ({
469
- source,
470
- target,
471
- type: ChangeInstructions.changeText,
551
+ const fe = (e = {}) => {
552
+ const s = new $t(e).setup();
553
+ return s.startNavigation(), s;
554
+ };
555
+ var c = /* @__PURE__ */ ((e) => (e[e.removeNode = 0] = "removeNode", e[e.insertNode = 1] = "insertNode", e[e.replaceNode = 2] = "replaceNode", e[e.removeAttribute = 3] = "removeAttribute", e[e.addAttribute = 4] = "addAttribute", e[e.updateAttribute = 5] = "updateAttribute", e[e.removeEvent = 6] = "removeEvent", e[e.addEvent = 7] = "addEvent", e[e.updateEvent = 8] = "updateEvent", e[e.changeValue = 9] = "changeValue", e[e.changeText = 10] = "changeText", e))(c || {});
556
+ const ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
557
+ __proto__: null,
558
+ ChangeInstructionTypes: c
559
+ }, Symbol.toStringTag, { value: "Module" })), Mt = (e, t) => ({
560
+ source: e,
561
+ target: t,
562
+ type: c.changeText,
472
563
  data: {}
473
- });
474
- var replaceNode = (source, target) => ({
475
- source,
476
- target,
477
- type: ChangeInstructions.replaceNode,
564
+ }), Ft = (e, t) => ({
565
+ source: e,
566
+ target: t,
567
+ type: c.replaceNode,
478
568
  data: {}
479
- });
480
- var removeAttribute = (source, target, data) => ({
481
- source,
482
- target,
483
- data,
484
- type: ChangeInstructions.removeAttribute
485
- });
486
- var addAttribute = (source, target, data) => ({
487
- source,
488
- target,
489
- data,
490
- type: ChangeInstructions.addAttribute
491
- });
492
- var updateAttribute = (source, target, data) => ({
493
- source,
494
- target,
495
- data,
496
- type: ChangeInstructions.updateAttribute
497
- });
498
- var removeEvent = (source, target, data) => ({
499
- source,
500
- target,
501
- data,
502
- type: ChangeInstructions.removeEvent
503
- });
504
- var addEvent = (source, target, data) => ({
505
- source,
506
- target,
507
- data,
508
- type: ChangeInstructions.addEvent
509
- });
510
- var updateEvent = (source, target, data) => ({
511
- source,
512
- target,
513
- data,
514
- type: ChangeInstructions.updateEvent
515
- });
516
- var removeNode = (source) => ({
517
- source,
518
- target: source,
519
- type: ChangeInstructions.removeNode,
569
+ }), Tt = (e, t, s) => ({
570
+ source: e,
571
+ target: t,
572
+ data: s,
573
+ type: c.removeAttribute
574
+ }), Dt = (e, t, s) => ({
575
+ source: e,
576
+ target: t,
577
+ data: s,
578
+ type: c.addAttribute
579
+ }), Ut = (e, t, s) => ({
580
+ source: e,
581
+ target: t,
582
+ data: s,
583
+ type: c.updateAttribute
584
+ }), zt = (e, t, s) => ({
585
+ source: e,
586
+ target: t,
587
+ data: s,
588
+ type: c.removeEvent
589
+ }), Lt = (e, t, s) => ({
590
+ source: e,
591
+ target: t,
592
+ data: s,
593
+ type: c.addEvent
594
+ }), Bt = (e, t, s) => ({
595
+ source: e,
596
+ target: t,
597
+ data: s,
598
+ type: c.updateEvent
599
+ }), x = (e) => ({
600
+ source: e,
601
+ target: e,
602
+ // for type crap only
603
+ type: c.removeNode,
520
604
  data: {}
521
- });
522
- var insertNode = (target, data) => ({
523
- target,
524
- source: target,
525
- type: ChangeInstructions.insertNode,
526
- data
527
- });
528
- var changeValue = (source, target, data) => ({
529
- source,
530
- target,
531
- type: ChangeInstructions.changeValue,
532
- data
533
- });
534
-
535
- // src/rendering/change/instructions/idMap.js
536
- var nullMatch = { index: -1 };
537
-
538
- class IdMap {
605
+ }), v = (e, t) => ({
606
+ target: e,
607
+ source: e,
608
+ // for type crap only
609
+ type: c.insertNode,
610
+ data: t
611
+ }), Pt = (e, t, s) => ({
612
+ source: e,
613
+ target: t,
614
+ type: c.changeValue,
615
+ data: s
616
+ }), Vt = (e, t) => e.type > t.type ? 1 : e.type < t.type ? -1 : 0, w = { index: -1 };
617
+ class Kt {
539
618
  constructor() {
540
619
  this.map = {};
541
620
  }
542
- populate(list) {
543
- list.forEach((element, i) => {
544
- const id = element.__jsx;
545
- if (id) {
546
- this.map[id] = this.map[id] || [];
547
- this.map[id].push({
548
- element,
549
- index: i
550
- });
551
- }
621
+ populate(t) {
622
+ t.forEach((s, n) => {
623
+ const r = s.__jsx;
624
+ r && (this.map[r] = this.map[r] || [], this.map[r].push({
625
+ element: s,
626
+ index: n
627
+ }));
552
628
  });
553
629
  }
554
- pullMatch(element) {
555
- const id = element && element.__jsx;
556
- if (!id)
557
- return nullMatch;
558
- if (!(this.map[id] && this.map[id].length))
559
- return nullMatch;
560
- return this.map[id].shift();
561
- }
562
- clear(element) {
563
- const id = element && element.__jsx;
564
- if (!(id && this.map[id] && this.map[id].length))
565
- return;
566
- const matches = this.map[id];
567
- this.map[id] = matches.reduce((collection, possibleMatch) => {
568
- if (possibleMatch.element !== element)
569
- collection.push(possibleMatch);
570
- return collection;
571
- }, []);
572
- }
573
- check(element) {
574
- const id = element && element.__jsx;
575
- if (!(id && this.map[id]))
576
- return false;
577
- return this.map[id].length > 0;
630
+ pullMatch(t) {
631
+ const s = t && t.__jsx;
632
+ return !s || !(this.map[s] && this.map[s].length) ? w : this.map[s].shift();
633
+ }
634
+ clear(t) {
635
+ const s = t && t.__jsx;
636
+ if (!(s && this.map[s] && this.map[s].length)) return;
637
+ const n = this.map[s];
638
+ this.map[s] = n.reduce((r, o) => (o.element !== t && r.push(o), r), []);
639
+ }
640
+ check(t) {
641
+ const s = t && t.__jsx;
642
+ return s && this.map[s] ? this.map[s].length > 0 : !1;
578
643
  }
579
644
  remaining() {
580
645
  return Object.values(this.map).flat();
581
646
  }
582
647
  }
583
- var createIdMap = (list) => {
584
- const map = new IdMap;
585
- map.populate(list);
586
- return map;
587
- };
588
-
589
- // src/rendering/change/instructions/attributes.ts
590
- var compileForAttributes = (source, target, isSvg2 = false) => {
591
- const instructions = [];
592
- const sourceAttributes = source.attributes;
593
- const sourceLength = sourceAttributes.length;
594
- const targetAttributes = target.attributes;
595
- const targetLength = targetAttributes.length;
596
- let index;
597
- let innerIndex;
598
- let matchingAttribute;
599
- for (index = 0;index < sourceLength; index++) {
600
- matchingAttribute = null;
601
- const sourceAttribute = sourceAttributes.item(index);
602
- if (!sourceAttribute)
603
- continue;
604
- for (innerIndex = 0;innerIndex < targetLength; innerIndex++) {
605
- const targetAttribute = targetAttributes.item(innerIndex);
606
- if (!targetAttribute)
607
- continue;
608
- if (sourceAttribute.name == targetAttribute.name) {
609
- matchingAttribute = targetAttribute;
610
- break;
648
+ const _ = (e) => {
649
+ const t = new Kt();
650
+ return t.populate(e), t;
651
+ }, Y = (e, t, s = !1) => {
652
+ const n = [], r = e.attributes, o = r.length, a = t.attributes, h = a.length;
653
+ let i, d, u;
654
+ for (i = 0; i < o; i++) {
655
+ u = null;
656
+ const l = r.item(i);
657
+ if (l) {
658
+ for (d = 0; d < h; d++) {
659
+ const p = a.item(d);
660
+ if (p && l.name == p.name) {
661
+ u = p;
662
+ break;
663
+ }
611
664
  }
612
- }
613
- if (!matchingAttribute) {
614
- instructions.push(removeAttribute(source, target, { name: sourceAttribute.name, isSvg: isSvg2 }));
615
- } else if (sourceAttribute.value !== matchingAttribute.value) {
616
- instructions.push(updateAttribute(source, target, {
617
- name: sourceAttribute.name,
618
- value: matchingAttribute.value,
619
- isSvg: isSvg2
620
- }));
665
+ u ? l.value !== u.value && n.push(
666
+ Ut(e, t, {
667
+ name: l.name,
668
+ value: u.value,
669
+ isSvg: s
670
+ })
671
+ ) : n.push(
672
+ Tt(e, t, { name: l.name, isSvg: s })
673
+ );
621
674
  }
622
675
  }
623
- for (index = 0;index < targetLength; index++) {
624
- matchingAttribute = null;
625
- const targetAttribute = targetAttributes.item(index);
626
- if (!targetAttribute)
627
- continue;
628
- for (innerIndex = 0;innerIndex < sourceLength; innerIndex++) {
629
- const sourceAttribute = sourceAttributes.item(innerIndex);
630
- if (!sourceAttribute)
631
- continue;
632
- if (sourceAttribute.name == targetAttribute.name) {
633
- matchingAttribute = sourceAttribute;
634
- break;
635
- }
636
- }
637
- if (!matchingAttribute) {
638
- instructions.push(addAttribute(source, target, {
639
- name: targetAttribute.name,
640
- value: targetAttribute.value,
641
- isSvg: isSvg2
642
- }));
643
- }
644
- }
645
- return instructions;
646
- };
647
-
648
- // src/rendering/change/instructions/events.ts
649
- var compileForEvents = (source, target) => {
650
- const instructions = [];
651
- const sourceEventMaps = source.eventMaps;
652
- const targetEventMaps = target.eventMaps;
653
- const sourceDomEvents = Object.keys(sourceEventMaps);
654
- const targetDomEvents = Object.keys(targetEventMaps);
655
- sourceDomEvents.forEach((domEvent) => {
656
- const sourceEventMap = sourceEventMaps[domEvent];
657
- const targetEventMap = targetEventMaps[domEvent];
658
- if (!targetEventMap) {
659
- instructions.push(removeEvent(source, target, {
660
- name: sourceEventMap.domEvent,
661
- value: sourceEventMap.listener
662
- }));
663
- } else if (targetEventMap.busEvent !== sourceEventMap.busEvent) {
664
- instructions.push(updateEvent(source, target, {
665
- name: domEvent,
666
- targetValue: targetEventMap.listener,
667
- sourceValue: sourceEventMap.listener
668
- }));
669
- }
670
- });
671
- targetDomEvents.forEach((domEvent) => {
672
- const sourceEventMap = sourceEventMaps[domEvent];
673
- const targetEventMap = targetEventMaps[domEvent];
674
- if (!sourceEventMap) {
675
- instructions.push(addEvent(source, target, {
676
- name: targetEventMap.domEvent,
677
- value: targetEventMap.listener
678
- }));
679
- }
680
- });
681
- return instructions;
682
- };
683
-
684
- // src/rendering/change/instructions/element.ts
685
- var compileForElement = (source, target) => {
686
- const attributeInstructions = compileForAttributes(source, target);
687
- const eventInstructions = compileForEvents(source, target);
688
- const valueInstructions = compileForInputValue(source, target);
689
- return attributeInstructions.concat(eventInstructions).concat(valueInstructions);
690
- };
691
- var compileForSvg = (source, target) => {
692
- return compileForAttributes(source, target, true);
693
- };
694
- var compileForInputValue = (sourceElement, targetElement) => {
695
- const instructions = [];
696
- if (sourceElement.tagName !== "INPUT") {
697
- return instructions;
698
- }
699
- const source = sourceElement;
700
- const target = targetElement;
701
- if (source.value !== target.value) {
702
- instructions.push(changeValue(source, target, { name: "value", value: target.value }));
703
- }
704
- return instructions;
705
- };
706
-
707
- // src/rendering/change/instructions/text.ts
708
- var compileForText = (source, target) => {
709
- if (source.textContent !== target.textContent) {
710
- return [changeText(source, target)];
711
- }
712
- return [];
713
- };
714
-
715
- // src/rendering/change/instructions/node.ts
716
- var NodeTypes;
717
- (function(NodeTypes2) {
718
- NodeTypes2[NodeTypes2["ElementNode"] = 1] = "ElementNode";
719
- NodeTypes2[NodeTypes2["TextNode"] = 3] = "TextNode";
720
- })(NodeTypes || (NodeTypes = {}));
721
- var compileForNodeGenerator = (compileForCollection) => (source, target) => {
722
- let instructions = [];
723
- if (source.nodeType === NodeTypes.ElementNode && isSvg(source)) {
724
- const sourceElement = source;
725
- const targetElement = target;
726
- const baseInstructions = compileForSvg(sourceElement, targetElement);
727
- const childrenInstructions = compileForCollection(sourceElement.childNodes, targetElement.childNodes, sourceElement);
728
- instructions = baseInstructions.concat(childrenInstructions);
729
- } else if (source.nodeType === NodeTypes.ElementNode) {
730
- const sourceElement = source;
731
- const targetElement = target;
732
- const baseInstructions = compileForElement(sourceElement, targetElement);
733
- const childrenInstructions = compileForCollection(sourceElement.childNodes, targetElement.childNodes, sourceElement);
734
- instructions = baseInstructions.concat(childrenInstructions);
735
- } else if (source.nodeType === NodeTypes.TextNode) {
736
- instructions = compileForText(source, target);
737
- }
738
- return instructions;
739
- };
740
-
741
- // src/rendering/change/instructions/children.ts
742
- var compileChildren = (sourceList, targetList, parent) => {
743
- const baseInstructions = [];
744
- const length = largerLength(sourceList, targetList);
745
- const sourceMap = createIdMap(sourceList);
746
- const targetMap = createIdMap(targetList);
747
- const nodesPairsToDiff = [];
748
- let index = 0;
749
- for (;index < length; index++) {
750
- const source = sourceList[index];
751
- const target = targetList[index];
752
- if (target && targetMap.check(target)) {
753
- const matchingSource = sourceMap.pullMatch(target);
754
- targetMap.clear(target);
755
- if (matchingSource.element) {
756
- if (matchingSource.index !== index) {
757
- baseInstructions.push(insertNode(matchingSource.element, { parent, index }));
676
+ for (i = 0; i < h; i++) {
677
+ u = null;
678
+ const l = a.item(i);
679
+ if (l) {
680
+ for (d = 0; d < o; d++) {
681
+ const p = r.item(d);
682
+ if (p && p.name == l.name) {
683
+ u = p;
684
+ break;
758
685
  }
759
- nodesPairsToDiff.push({
760
- source: matchingSource.element,
761
- target
762
- });
763
- } else if (source) {
764
- if (targetMap.check(source)) {
765
- baseInstructions.push(insertNode(target, { parent, index }));
766
- } else {
767
- sourceMap.clear(source);
768
- baseInstructions.push(replaceNode(source, target));
769
- }
770
- } else {
771
- baseInstructions.push(insertNode(target, { parent, index }));
772
- }
773
- } else if (source) {
774
- const matchingSource = sourceMap.pullMatch(source);
775
- if (matchingSource.element) {
776
- baseInstructions.push(removeNode(source));
777
686
  }
687
+ u || n.push(
688
+ Dt(e, t, {
689
+ name: l.name,
690
+ value: l.value,
691
+ isSvg: s
692
+ })
693
+ );
778
694
  }
779
695
  }
780
- sourceMap.remaining().forEach(({ element: element2 }) => {
781
- baseInstructions.push(removeNode(element2));
696
+ return n;
697
+ }, Rt = (e, t) => {
698
+ const s = [], n = e.eventMaps, r = t.eventMaps, o = Object.keys(n), a = Object.keys(r);
699
+ return o.forEach((h) => {
700
+ const i = n[h], d = r[h];
701
+ d ? d.busEvent !== i.busEvent && s.push(
702
+ Bt(e, t, {
703
+ name: h,
704
+ targetValue: d.listener,
705
+ sourceValue: i.listener
706
+ })
707
+ ) : s.push(
708
+ zt(e, t, {
709
+ name: i.domEvent,
710
+ value: i.listener
711
+ })
712
+ );
713
+ }), a.forEach((h) => {
714
+ const i = n[h], d = r[h];
715
+ i || s.push(
716
+ Lt(e, t, {
717
+ name: d.domEvent,
718
+ value: d.listener
719
+ })
720
+ );
721
+ }), s;
722
+ }, qt = (e) => e.tagName !== "INPUT", Jt = (e, t) => e.value === t.value, Ht = (e, t) => {
723
+ if (qt(e) || Jt(e, t))
724
+ return [];
725
+ const s = e, n = t;
726
+ return [Pt(s, n, { name: "value", value: n.value })];
727
+ }, It = (e, t) => {
728
+ const s = Y(e, t), n = Rt(e, t), r = Ht(e, t);
729
+ return s.concat(n).concat(r);
730
+ }, Qt = (e, t) => Y(e, t, !0), Wt = (e, t) => e.textContent !== t.textContent ? [Mt(e, t)] : [], Gt = (e, t, s) => {
731
+ let n = [];
732
+ if (e.nodeType === 1 && it(e)) {
733
+ const r = e, o = t, a = Qt(r, o), h = s(
734
+ r.childNodes,
735
+ o.childNodes,
736
+ r
737
+ );
738
+ n = a.concat(h);
739
+ } else if (e.nodeType === 1) {
740
+ const r = e, o = t, a = It(r, o), h = s(
741
+ r.childNodes,
742
+ o.childNodes,
743
+ r
744
+ );
745
+ n = a.concat(h);
746
+ } else e.nodeType === 3 && (n = Wt(e, t));
747
+ return n;
748
+ }, Z = (e, t, s) => {
749
+ const n = [], r = Xt(e, t), o = _(e), a = _(t), h = [];
750
+ let i = 0;
751
+ for (; i < r; i++) {
752
+ const u = e[i], l = t[i];
753
+ if (l && a.check(l)) {
754
+ const p = o.pullMatch(l);
755
+ a.clear(l), p.element ? (p.index !== i && n.push(
756
+ v(p.element, {
757
+ parent: s,
758
+ index: i
759
+ })
760
+ ), h.push({
761
+ source: p.element,
762
+ target: l
763
+ })) : u ? a.check(u) ? n.push(
764
+ v(l, { parent: s, index: i })
765
+ ) : (o.clear(u), n.push(
766
+ Ft(u, l)
767
+ )) : n.push(
768
+ v(l, { parent: s, index: i })
769
+ );
770
+ } else u && o.pullMatch(u).element && n.push(x(u));
771
+ }
772
+ o.remaining().forEach(({ element: u }) => {
773
+ n.push(x(u));
782
774
  });
783
- const nodeInstructions = nodesPairsToDiff.reduce((collection, { source, target }) => {
784
- return collection.concat(compileForNode(source, target));
785
- }, []);
786
- return baseInstructions.concat(nodeInstructions).sort(instructionsSorter);
787
- };
788
- var instructionsSorter = (left, right) => {
789
- if (left.type > right.type)
790
- return 1;
791
- if (left.type < right.type)
792
- return -1;
793
- return 0;
794
- };
795
- var largerLength = (sourceList, targetList) => {
796
- const sourceLength = Array.from(sourceList).length;
797
- const targetLength = Array.from(targetList).length;
798
- return sourceLength > targetLength ? sourceLength : targetLength;
799
- };
800
- var compileForNode = compileForNodeGenerator(compileChildren);
801
- // src/rendering/change.ts
802
- var change = (source, target, parent) => {
803
- const instructions = compileChildren(source, target, parent);
804
- instructions.forEach((instruction) => {
805
- performInstruction(instruction);
775
+ const d = h.reduce(
776
+ (u, { source: l, target: p }) => u.concat(
777
+ Gt(l, p, Z)
778
+ ),
779
+ []
780
+ );
781
+ return n.concat(d).sort(Vt);
782
+ }, Xt = (e, t) => {
783
+ const s = e.length, n = t.length;
784
+ return s > n ? s : n;
785
+ }, Yt = (e, t, s) => {
786
+ Z(e, t, s).forEach((r) => {
787
+ Zt(r);
806
788
  });
807
- };
808
- var performInstruction = (instruction) => {
809
- const performer = performers[instruction.type] || noop;
810
- performer(instruction);
811
- };
812
- var noop = (_instruction) => {
813
- };
814
- var changeText2 = (instruction) => {
815
- const { source, target } = instruction;
816
- source.nodeValue = target.textContent;
817
- };
818
- var removeNode2 = (instruction) => {
819
- const { source } = instruction;
820
- source.remove();
821
- };
822
- var insertNode2 = (instruction) => {
823
- const { target, data } = instruction;
824
- const { parent, index } = data;
825
- const sibling = parent.childNodes[index];
826
- if (!sibling) {
827
- parent.appendChild(target);
828
- } else if (sibling && sibling !== target) {
829
- parent.insertBefore(target, sibling);
830
- }
831
- };
832
- var replaceNode2 = (instruction) => {
833
- const { source, target } = instruction;
834
- source.replaceWith(target);
835
- };
836
- var removeAttribute2 = (instruction) => {
837
- const { source, data } = instruction;
838
- const { name, isSvg: isSvg2 } = data;
839
- if (isSvg2) {
840
- source.removeAttributeNS(null, name);
841
- } else {
842
- source.removeAttribute(name);
843
- }
844
- };
845
- var addAttribute2 = (instruction) => {
846
- const { source, data } = instruction;
847
- const { name, value, isSvg: isSvg2 } = data;
848
- if (isSvg2) {
849
- source.setAttributeNS(null, name, value);
850
- } else {
851
- source.setAttribute(name, value);
852
- }
853
- };
854
- var updateAttribute2 = (instruction) => {
855
- addAttribute2(instruction);
856
- };
857
- var removeEvent2 = (instruction) => {
858
- const data = instruction.data;
859
- const source = instruction.source;
860
- const { name, value } = data;
861
- source.removeEventListener(name, value);
862
- };
863
- var addEvent2 = (instruction) => {
864
- const data = instruction.data;
865
- const source = instruction.source;
866
- const { name, value } = data;
867
- source.addEventListener(name, value);
868
- };
869
- var updateEvent2 = (instruction) => {
870
- const data = instruction.data;
871
- const source = instruction.source;
872
- const { name, sourceValue, targetValue } = data;
873
- source.removeEventListener(name, sourceValue);
874
- source.addEventListener(name, targetValue);
875
- };
876
- var changeValue2 = (instruction) => {
877
- const data = instruction.data;
878
- const source = instruction.source;
879
- const { value } = data;
880
- source.value = value;
881
- };
882
- var performers = {
883
- [ChangeInstructions.changeText]: changeText2,
884
- [ChangeInstructions.removeNode]: removeNode2,
885
- [ChangeInstructions.insertNode]: insertNode2,
886
- [ChangeInstructions.replaceNode]: replaceNode2,
887
- [ChangeInstructions.removeAttribute]: removeAttribute2,
888
- [ChangeInstructions.addAttribute]: addAttribute2,
889
- [ChangeInstructions.updateAttribute]: updateAttribute2,
890
- [ChangeInstructions.removeEvent]: removeEvent2,
891
- [ChangeInstructions.addEvent]: addEvent2,
892
- [ChangeInstructions.updateEvent]: updateEvent2,
893
- [ChangeInstructions.changeValue]: changeValue2
894
- };
895
-
896
- // src/rendering/templates/bound.js
897
- var passThroughViewModel = (state2) => state2;
898
-
899
- class Bound {
900
- constructor(TemplateClass, viewModel, subscriptions, attributes2) {
901
- this.TemplateClass = TemplateClass;
902
- this.viewModel = viewModel || passThroughViewModel;
903
- this.attributes = attributes2 || {};
904
- this.subscriptions = subscriptions;
905
- this.dom = [];
906
- }
907
- render(renderKit) {
908
- this.parentElement = renderKit.parent;
909
- this.renderKit = renderKit;
910
- this.subscribeForRerender();
911
- this.dom = this._render(renderKit);
912
- return this.dom;
913
- }
914
- _render(renderKit) {
915
- const props = {
789
+ }, Zt = (e) => {
790
+ (he[e.type] || Ct)(e);
791
+ }, Ct = (e) => {
792
+ }, te = (e) => {
793
+ const { source: t, target: s } = e;
794
+ t.nodeValue = s.textContent;
795
+ }, ee = (e) => {
796
+ const { source: t } = e;
797
+ t.remove();
798
+ }, se = (e) => {
799
+ const { target: t, data: s } = e, { parent: n, index: r } = s, o = n.childNodes[r];
800
+ o ? o && o !== t && n.insertBefore(t, o) : n.appendChild(t);
801
+ }, ne = (e) => {
802
+ const { source: t, target: s } = e;
803
+ t.replaceWith(s);
804
+ }, re = (e) => {
805
+ const { source: t, data: s } = e, { name: n, isSvg: r } = s;
806
+ r ? t.removeAttributeNS(null, n) : t.removeAttribute(n);
807
+ }, C = (e) => {
808
+ const { source: t, data: s } = e, { name: n, value: r, isSvg: o } = s;
809
+ o ? t.setAttributeNS(null, n, r) : t.setAttribute(n, r);
810
+ }, oe = (e) => {
811
+ C(e);
812
+ }, ie = (e) => {
813
+ const t = e.data, s = e.source, { name: n, value: r } = t;
814
+ s.removeEventListener(n, r);
815
+ }, ae = (e) => {
816
+ const t = e.data, s = e.source, { name: n, value: r } = t;
817
+ s.addEventListener(n, r);
818
+ }, ce = (e) => {
819
+ const t = e.data, s = e.source, { name: n, sourceValue: r, targetValue: o } = t;
820
+ s.removeEventListener(n, r), s.addEventListener(n, o);
821
+ }, ue = (e) => {
822
+ const t = e.data, s = e.source, { value: n } = t;
823
+ s.value = n;
824
+ }, he = {
825
+ [c.changeText]: te,
826
+ [c.removeNode]: ee,
827
+ [c.insertNode]: se,
828
+ [c.replaceNode]: ne,
829
+ [c.removeAttribute]: re,
830
+ [c.addAttribute]: C,
831
+ [c.updateAttribute]: oe,
832
+ [c.removeEvent]: ie,
833
+ [c.addEvent]: ae,
834
+ [c.updateEvent]: ce,
835
+ [c.changeValue]: ue
836
+ };
837
+ class le {
838
+ constructor({ Template: t, subscriptions: s, attributes: n, viewModel: r }) {
839
+ this.Template = t, this.viewModel = r, this.attributes = n, this.subscriptions = s, this.dom = [], this.parentElement = null;
840
+ }
841
+ render(t) {
842
+ return this.parentElement = t.parent, this.renderKit = t, this.subscribeForRerender(), this.dom = this.generateDom(t), this.dom;
843
+ }
844
+ generateDom(t) {
845
+ const s = {
916
846
  ...this.attributes,
917
- ...this.viewModel(renderKit.state.value())
918
- };
919
- const template = this.TemplateClass(props);
920
- const dom = !template ? [] : template.render(renderKit);
921
- return dom;
847
+ ...this.viewModel(
848
+ t.state.getAll(this.subscriptions)
849
+ )
850
+ }, n = this.Template(s);
851
+ return n ? n.render(t) : [];
922
852
  }
923
853
  rerender() {
924
- if (!this.parentElement) {
925
- this.parentElement = this.dom[0] && this.dom[0].parentElement;
926
- }
927
- const newDom = this._render(this.renderKit);
928
- change(this.dom, newDom, this.parentElement);
929
- if (this.parentElement) {
930
- this.dom = Array.from(this.parentElement.childNodes);
854
+ if (!this.parentElement && this.dom[0]) {
855
+ const s = this.dom[0].parentElement;
856
+ this.parentElement = s;
931
857
  }
858
+ const t = this.generateDom(this.renderKit);
859
+ Yt(this.dom, t, this.parentElement), this.parentElement && (this.dom = Array.from(this.parentElement.childNodes));
932
860
  }
933
861
  subscribeForRerender() {
934
- this.subscriptions.forEach((storeName) => {
935
- this.renderKit.subscribe(eventName(storeName), () => this.rerender());
862
+ const { subscribe: t } = this.renderKit;
863
+ this.subscriptions.forEach((s) => {
864
+ t(this.eventName(s), () => this.rerender());
936
865
  });
937
866
  }
938
- }
939
- var bind = ({ Template, viewModel, subscriptions }) => {
940
- subscriptions = subscriptions || [];
941
- return (attributes2) => new Bound(Template, viewModel, subscriptions, attributes2);
942
- };
943
- // src/messageBus.ts
944
- class MessageBus {
945
- listeners;
946
- options;
947
- constructor() {
948
- this.options = {};
949
- this.listeners = {};
950
- }
951
- subscribe(eventName2, listener) {
952
- this.ensureListenerCollection(eventName2);
953
- this.listeners[eventName2].push(listener);
954
- }
955
- publish(eventName2, payload) {
956
- const listeners = this.listeners[eventName2];
957
- if (!listeners)
958
- return false;
959
- listeners.forEach((listener) => {
960
- listener(payload, this.buildListenerKit(eventName2));
961
- });
962
- return true;
963
- }
964
- ensureListenerCollection(eventName2) {
965
- if (this.listeners[eventName2])
966
- return;
967
- this.listeners[eventName2] = [];
968
- }
969
- buildListenerKit(eventName2) {
970
- return {
971
- eventName: eventName2,
972
- publish: this.publish.bind(this),
973
- ...this.options
974
- };
975
- }
976
- addListenerOptions(options) {
977
- this.options = {
978
- ...this.options,
979
- ...options
980
- };
867
+ eventName(t) {
868
+ return `${S}:${t}`;
981
869
  }
982
870
  }
983
- var createBus = () => {
984
- const bus = new MessageBus;
985
- const publish = bus.publish.bind(bus);
986
- const subscribe = bus.subscribe.bind(bus);
987
- return {
988
- bus,
989
- publish,
990
- subscribe
991
- };
992
- };
993
- // src/navigation/routeState.js
994
- var createRouteState = (state2) => {
995
- const store = new RecordStore({
996
- name: "route",
997
- value: {
998
- host: "",
999
- path: "",
1000
- query: ""
1001
- },
1002
- parent: state2
1003
- });
1004
- state2.add(store);
1005
- };
1006
-
1007
- // src/navigation/setupHistory.js
1008
- var locationChangeEvent = "locationChange";
1009
- var routeChangeEvent = "routeChange";
1010
- var extractQueryParams = (queryString) => {
1011
- return queryString.replace(/^\?/, "").split("&").reduce((aggregate, pairString) => {
1012
- if (!pairString)
1013
- return aggregate;
1014
- const pair = pairString.split("=");
1015
- aggregate[pair[0]] = pair[1];
1016
- return aggregate;
1017
- }, {});
1018
- };
1019
- var onLocationChange = (_payload, { publish, state: state2, window }) => {
1020
- const { host, pathname, search } = window.location;
1021
- const path = pathname;
1022
- const query = extractQueryParams(search);
1023
- state2.route.update({
1024
- host,
1025
- path,
1026
- query
1027
- });
1028
- publish(routeChangeEvent, { host, path, query });
1029
- };
1030
- var setupHistory = (app) => {
1031
- const { publish, subscribe, state: state2, window } = app;
1032
- createRouteState(state2);
1033
- window.addEventListener("popstate", () => publish(locationChangeEvent));
1034
- subscribe(locationChangeEvent, onLocationChange);
1035
- };
1036
-
1037
- // src/navigation/findHref.js
1038
- var findHref = (node2) => {
1039
- if (!node2 || !node2.getAttribute)
1040
- return "";
1041
- while (!node2.getAttribute("href")) {
1042
- node2 = node2.parentNode;
1043
- if (!node2 || !node2.getAttribute)
1044
- return "";
1045
- }
1046
- return node2.getAttribute("href");
1047
- };
1048
-
1049
- // src/navigation/setupNavigation.js
1050
- var linkNavigationEvent = "goToHref";
1051
- var programmaticNavigationEvent = "navigate";
1052
- var navigate = (path, { publish, window }) => {
1053
- window.history.pushState(null, "", path);
1054
- publish(locationChangeEvent);
1055
- };
1056
- var onLinkClick = (domEvent, { publish, window }) => {
1057
- if (!domEvent || !domEvent.target)
1058
- return;
1059
- domEvent.preventDefault();
1060
- const href = findHref(domEvent.target);
1061
- navigate(href, { publish, window });
1062
- };
1063
- var setupNavigation = (app) => {
1064
- const { subscribe } = app;
1065
- subscribe(linkNavigationEvent, onLinkClick);
1066
- subscribe(programmaticNavigationEvent, navigate);
1067
- };
1068
-
1069
- // src/app.ts
1070
- var setupBus = (app) => {
1071
- const { publish, subscribe, bus } = createBus();
1072
- app.publish = publish;
1073
- app.subscribe = subscribe;
1074
- app.bus = bus;
1075
- };
1076
- var setupState = (app) => {
1077
- const state3 = new State(app.publish);
1078
- app.state = state3;
1079
- };
1080
- var connectBusToState = (app) => {
1081
- const { bus } = app;
1082
- bus.addListenerOptions({
1083
- state: app.state,
1084
- document: app.document,
1085
- window: app.window
1086
- });
1087
- };
1088
- var setupRenderKit = (app) => {
1089
- app.renderKit = {
1090
- publish: app.publish,
1091
- subscribe: app.subscribe,
1092
- state: app.state,
1093
- document: app.document,
1094
- window: app.window
1095
- };
1096
- };
1097
- var triggerRoute = (app) => {
1098
- const publish = app.publish;
1099
- setTimeout(() => {
1100
- publish(locationChangeEvent, null);
1101
- }, 0);
1102
- };
1103
- var addRender = (app) => {
1104
- app.render = (template, selector) => {
1105
- return render(template, selector, app.renderKit);
1106
- };
1107
- };
1108
- var setupDomEnvironment = (app, domEnvironment) => {
1109
- const { window, document } = domEnvironment;
1110
- if (window) {
1111
- app.window = window;
1112
- app.document = window.document;
1113
- } else if (document) {
1114
- app.window = document.defaultView;
1115
- app.document = document;
1116
- } else {
1117
- app.window = window;
1118
- app.document = window?.document;
1119
- }
1120
- };
1121
- var createApp = (domEnvironment) => {
1122
- const app = {};
1123
- setupDomEnvironment(app, domEnvironment || {});
1124
- setupBus(app);
1125
- setupState(app);
1126
- connectBusToState(app);
1127
- setupRenderKit(app);
1128
- setupHistory(app);
1129
- setupNavigation(app);
1130
- triggerRoute(app);
1131
- addRender(app);
1132
- return app;
1133
- };
1134
- // src/navigation.ts
1135
- var exports_navigation = {};
1136
- __export(exports_navigation, {
1137
- setupNavigation: () => {
1138
- {
1139
- return setupNavigation;
1140
- }
1141
- },
1142
- setupHistory: () => {
1143
- {
1144
- return setupHistory;
1145
- }
1146
- }
1147
- });
871
+ const de = (e) => e, ge = ({
872
+ Template: e,
873
+ viewModel: t,
874
+ subscriptions: s
875
+ }) => (s = s || [], t = t || de, (n) => new le({ Template: e, viewModel: t, subscriptions: s, attributes: n })), ye = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
876
+ __proto__: null,
877
+ createRouteState: F,
878
+ events: wt,
879
+ extractQueryParams: z,
880
+ findHref: T,
881
+ navigate: D,
882
+ onLinkClick: U,
883
+ onLocationChange: L,
884
+ start: _t
885
+ }, Symbol.toStringTag, { value: "Module" }));
1148
886
  export {
1149
- render,
1150
- exports_navigation as navigation,
1151
- jsx_default as jsx,
1152
- createBus,
1153
- createApp,
1154
- bind,
1155
- State
887
+ ve as JaxsTypes,
888
+ pe as appBuilding,
889
+ ge as bind,
890
+ fe as createApp,
891
+ At as jsx,
892
+ me as messageBus,
893
+ ye as navigation,
894
+ be as state
1156
895
  };