@manyducks.co/dolla 2.0.0-alpha.65 → 2.0.0-alpha.66

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.
package/dist/index.js CHANGED
@@ -1,19 +1,19 @@
1
1
  var E = (e) => {
2
2
  throw TypeError(e);
3
3
  };
4
- var N = (e, t, s) => t.has(e) || E("Cannot " + s);
5
- var r = (e, t, s) => (N(e, t, "read from private field"), s ? s.call(e) : t.get(e)), i = (e, t, s) => t.has(e) ? E("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, s), n = (e, t, s, g) => (N(e, t, "write to private field"), g ? g.call(e, s) : t.set(e, s), s), k = (e, t, s) => (N(e, t, "access private method"), s);
6
- import { R as M, c as U, M as v, a as R, U as C } from "./index-Bh8JrCt1.js";
7
- import { t as O } from "./typeChecking-D0-H8_Xm.js";
8
- import { m as l, w as D, C as m, V as p, L as w, R as F, D as T } from "./markup-DsJHUuod.js";
9
- import { M as Q, a as X, c as Y, p as Z, r as ee, b as te, u as se } from "./markup-DsJHUuod.js";
10
- import { o as S } from "./logger-BuZRMjzE.js";
11
- import { c as ae, s as ne, a as ie } from "./logger-BuZRMjzE.js";
12
- import { F as q } from "./fragment-BahD_BJA.js";
13
- import { g as y } from "./signals-BDlRtifZ.js";
14
- import { $ as le, b as he, d as ce, e as ue, c as me, m as fe, f as de, s as ge, a as we, u as ye, w as be } from "./signals-BDlRtifZ.js";
15
- import { r as xe } from "./ref-BD79iqlg.js";
16
- function V(e) {
4
+ var N = (e, t, r) => t.has(e) || E("Cannot " + r);
5
+ var n = (e, t, r) => (N(e, t, "read from private field"), r ? r.call(e) : t.get(e)), i = (e, t, r) => t.has(e) ? E("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), s = (e, t, r, w) => (N(e, t, "write to private field"), w ? w.call(e, r) : t.set(e, r), r), k = (e, t, r) => (N(e, t, "access private method"), r);
6
+ import { R as U, c as v, M as R, a as C, U as O } from "./index-BEDDzyd9.js";
7
+ import { t as S, i as T } from "./typeChecking-_dGK_0uR.js";
8
+ import { m as l, w as D, C as m, V as M, L as g, R as F, D as q, M as P, a as $ } from "./markup-DjDexAN5.js";
9
+ import { b as ee, c as te, p as re, r as ne, d as ae, u as se } from "./markup-DjDexAN5.js";
10
+ import { o as V } from "./logger-CmXtRdEI.js";
11
+ import { c as oe, s as le, a as ce } from "./logger-CmXtRdEI.js";
12
+ import { F as p } from "./fragment-BahD_BJA.js";
13
+ import { g as y } from "./signals-CkfFHd0d.js";
14
+ import { $ as ue, b as me, d as fe, e as de, c as we, m as ge, f as ye, s as be, a as Ne, u as xe, w as Ee } from "./signals-CkfFHd0d.js";
15
+ import { r as Me } from "./ref-BD79iqlg.js";
16
+ function I(e) {
17
17
  return l("div", {
18
18
  style: {
19
19
  backgroundColor: "#880000",
@@ -70,96 +70,108 @@ function V(e) {
70
70
  ]
71
71
  });
72
72
  }
73
- var c, a, f, o, h, d, u, b, L;
73
+ var h, a, f, o, c, d, u, b, L;
74
74
  class x {
75
75
  constructor(t) {
76
76
  i(this, b);
77
- i(this, c);
77
+ i(this, h);
78
78
  i(this, a);
79
79
  i(this, f);
80
80
  i(this, o);
81
- i(this, h, !1);
82
- i(this, d, V);
81
+ i(this, c, !1);
82
+ i(this, d, I);
83
83
  i(this, u, []);
84
- n(this, f, t.view ?? q), n(this, o, t.router), n(this, a, t.context ?? new m("App"));
84
+ s(this, f, t.view ?? p), s(this, o, t.router), s(this, a, t.context ?? new m("App"));
85
85
  }
86
86
  get context() {
87
- return r(this, a);
87
+ return n(this, a);
88
88
  }
89
89
  setCrashView(t) {
90
- return n(this, d, t), this;
90
+ return s(this, d, t), this;
91
91
  }
92
92
  async mount(t) {
93
- if (r(this, h)) return Promise.resolve();
94
- const s = k(this, b, L).call(this, t);
95
- r(this, u).push(
96
- S((g) => {
97
- r(this, h) && this.unmount(), new p(r(this, a), r(this, d), g).mount(s);
93
+ if (n(this, c)) return Promise.resolve();
94
+ const r = k(this, b, L).call(this, t);
95
+ n(this, u).push(
96
+ V((w) => {
97
+ n(this, c) && this.unmount(), new M(n(this, a), n(this, d), w).mount(r);
98
98
  })
99
- ), m.emit(r(this, a), w.WILL_MOUNT), r(this, o) ? (n(this, c, await r(this, o)[v](s, r(this, a))), r(this, a).setState(R, r(this, o))) : n(this, c, new p(r(this, a), r(this, f), {})), r(this, c).mount(s), n(this, h, !0), m.emit(r(this, a), w.DID_MOUNT);
99
+ ), m.emit(n(this, a), g.WILL_MOUNT), n(this, o) ? (s(this, h, await n(this, o)[R](r, n(this, a))), n(this, a).setState(C, n(this, o))) : s(this, h, new M(n(this, a), n(this, f), {})), n(this, h).mount(r), s(this, c, !0), m.emit(n(this, a), g.DID_MOUNT);
100
100
  }
101
101
  async unmount() {
102
- if (!r(this, h)) return Promise.resolve();
103
- m.emit(r(this, a), w.WILL_UNMOUNT), n(this, h, !1), r(this, c).unmount(!1), r(this, o) && await r(this, o)[C]();
104
- for (const t of r(this, u))
102
+ if (!n(this, c)) return Promise.resolve();
103
+ m.emit(n(this, a), g.WILL_UNMOUNT), s(this, c, !1), n(this, h).unmount(!1), n(this, o) && await n(this, o)[O]();
104
+ for (const t of n(this, u))
105
105
  t();
106
- n(this, u, []), m.emit(r(this, a), w.DID_UNMOUNT);
106
+ s(this, u, []), m.emit(n(this, a), g.DID_UNMOUNT);
107
107
  }
108
108
  }
109
- c = new WeakMap(), a = new WeakMap(), f = new WeakMap(), o = new WeakMap(), h = new WeakMap(), d = new WeakMap(), u = new WeakMap(), b = new WeakSet(), L = function(t) {
109
+ h = new WeakMap(), a = new WeakMap(), f = new WeakMap(), o = new WeakMap(), c = new WeakMap(), d = new WeakMap(), u = new WeakMap(), b = new WeakSet(), L = function(t) {
110
110
  if (typeof t == "string") {
111
- const s = document.querySelector(t);
112
- if (!s)
111
+ const r = document.querySelector(t);
112
+ if (!r)
113
113
  throw new Error(`Selector '${t}' did not many any element.`);
114
- return s;
114
+ return r;
115
115
  } else {
116
116
  if (t instanceof Element)
117
117
  return t;
118
118
  throw new Error("Expected a selector string or DOM element.");
119
119
  }
120
120
  };
121
- function j(e, t) {
122
- return e instanceof M ? new x({ ...t, router: e }) : O(e) === "object" ? new x({ ...t, router: U(e) }) : new x({ ...t, view: e });
121
+ function H(e, t) {
122
+ return e instanceof U ? new x({ ...t, router: e }) : S(e) === "object" ? new x({ ...t, router: v(e) }) : new x({ ...t, view: e });
123
123
  }
124
- const $ = (e) => e;
125
- function K(e, t) {
126
- return new F(t, e.each, e.key ?? $, e.children);
124
+ const _ = (e) => e;
125
+ function J(e, t) {
126
+ return new F(t, e.each, e.key ?? _, e.children);
127
127
  }
128
- function G(e, t) {
129
- return new T(t, () => {
130
- let s = !0;
131
- return e.when != null && e.unless != null ? s = y(e.when) && !y(e.unless) : e.when != null ? s = y(e.when) : e.unless != null && (s = !y(e.unless)), s ? e.children : e.fallback;
128
+ function Q(e, t) {
129
+ return new q(t, () => {
130
+ let r = !0;
131
+ return e.when != null && e.unless != null ? r = y(e.when) && !y(e.unless) : e.when != null ? r = y(e.when) : e.unless != null && (r = !y(e.unless)), r ? e.children : e.fallback;
132
+ });
133
+ }
134
+ function X(e, t) {
135
+ if (T(e.into)) {
136
+ if (document.querySelector(e.into) == null)
137
+ throw t.crash(new Error(`Portal: selector '${e.into}' did not match any element`));
138
+ } else
139
+ e.into;
140
+ return new P($.Portal, {
141
+ parent: e.into,
142
+ content: e.children
132
143
  });
133
144
  }
134
145
  export {
135
- le as $,
136
- K as For,
137
- Q as Markup,
138
- X as MarkupNode,
139
- G as Show,
140
- he as batch,
141
- j as createApp,
142
- Y as createContext,
143
- ae as createLogger,
144
- ce as deepEqual,
145
- ue as effect,
146
+ ue as $,
147
+ J as For,
148
+ P as Markup,
149
+ ee as MarkupNode,
150
+ X as Portal,
151
+ Q as Show,
152
+ me as batch,
153
+ H as createApp,
154
+ te as createContext,
155
+ oe as createLogger,
156
+ fe as deepEqual,
157
+ de as effect,
146
158
  y as get,
147
- me as getEnv,
159
+ we as getEnv,
148
160
  l as m,
149
- fe as memo,
150
- S as onLoggerCrash,
151
- Z as portal,
152
- xe as ref,
153
- ee as render,
154
- te as repeat,
155
- de as setEnv,
156
- ne as setLogFilter,
157
- ie as setLogLevels,
158
- ge as shallowEqual,
159
- we as strictEqual,
161
+ ge as memo,
162
+ V as onLoggerCrash,
163
+ re as portal,
164
+ Me as ref,
165
+ ne as render,
166
+ ae as repeat,
167
+ ye as setEnv,
168
+ le as setLogFilter,
169
+ ce as setLogLevels,
170
+ be as shallowEqual,
171
+ Ne as strictEqual,
160
172
  se as unless,
161
- ye as untracked,
173
+ xe as untracked,
162
174
  D as when,
163
- be as writable
175
+ Ee as writable
164
176
  };
165
177
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/core/views/default-crash-view.ts","../src/core/app.ts","../src/core/views/for.ts","../src/core/views/show.ts"],"sourcesContent":["import { when, m } from \"../markup.js\";\n\n/**\n * Props passed to the crash view when a crash occurs.\n */\nexport interface CrashViewProps {\n /**\n * JavaScript Error object.\n */\n error: Error;\n\n /**\n * A string to identify the logger that reported this error.\n */\n loggerName: string;\n\n /**\n * Unique identifier to pinpoint the specific view that reported the crash.\n */\n tag?: string;\n\n /**\n * Label for the tag.\n */\n tagName?: string;\n}\n\n/**\n * The crash view displayed unless you specify your own.\n */\nexport function DefaultCrashView(props: CrashViewProps) {\n return m(\"div\", {\n style: {\n backgroundColor: \"#880000\",\n color: \"#fff\",\n padding: \"2rem\",\n position: \"fixed\",\n inset: 0,\n fontSize: \"20px\",\n },\n children: [\n m(\"h1\", { style: { marginBottom: \"0.5rem\" }, children: \"The app has crashed\" }),\n m(\"p\", {\n style: { marginBottom: \"0.25rem\" },\n children: [\n m(\"span\", {\n style: { fontFamily: \"monospace\" },\n children: props.loggerName,\n }),\n when(\n props.tag,\n m(\"span\", {\n style: { fontFamily: \"monospace\", opacity: 0.5 },\n children: ` [${props.tagName ? `${props.tagName}: ` : \"\"}${props.tag}]`,\n }),\n ),\n \" says:\",\n ],\n }),\n m(\"blockquote\", {\n style: {\n backgroundColor: \"#991111\",\n padding: \"0.25em\",\n borderRadius: \"6px\",\n fontFamily: \"monospace\",\n marginBottom: \"1rem\",\n },\n children: [\n m(\"span\", {\n style: {\n display: \"inline-block\",\n backgroundColor: \"red\",\n padding: \"0.1em 0.4em\",\n marginRight: \"0.5em\",\n borderRadius: \"4px\",\n fontSize: \"0.9em\",\n fontWeight: \"bold\",\n },\n children: props.error.name,\n }),\n props.error.message,\n ],\n }),\n m(\"p\", { children: \"Please see the browser console for details.\" }),\n ],\n });\n}\n","import { createRouter } from \"../router\";\nimport { MOUNT, ROUTER, Router, RouterOptions, UNMOUNT } from \"../router/router\";\nimport { typeOf } from \"../typeChecking\";\nimport { View } from \"../types\";\nimport { Context, LifecycleEvent } from \"./context\";\nimport { LoggerCrashProps, onLoggerCrash } from \"./logger\";\nimport { MarkupNode } from \"./markup\";\nimport { ViewNode } from \"./nodes/view\";\nimport { DefaultCrashView } from \"./views/default-crash-view\";\nimport { Fragment } from \"./views/fragment\";\n\ninterface AppOptions {\n view?: View<{}>;\n router?: Router;\n context?: Context;\n}\n\nclass App {\n #root!: MarkupNode;\n #context: Context;\n #view: View<{}>;\n #router?: Router;\n #mounted = false;\n #crashView: View<LoggerCrashProps> = DefaultCrashView;\n\n #cleanup: (() => void)[] = [];\n\n get context() {\n return this.#context;\n }\n\n constructor(options: AppOptions) {\n this.#view = options.view ?? Fragment;\n this.#router = options.router;\n this.#context = options.context ?? new Context(\"App\");\n }\n\n setCrashView(view: View<LoggerCrashProps>) {\n this.#crashView = view;\n return this;\n }\n\n async mount(element: string | Element): Promise<void> {\n if (this.#mounted) return Promise.resolve();\n\n const parentElement = this.#getElement(element);\n\n this.#cleanup.push(\n onLoggerCrash((props) => {\n if (this.#mounted) {\n this.unmount();\n }\n new ViewNode(this.#context, this.#crashView, props).mount(parentElement);\n }),\n );\n\n Context.emit(this.#context, LifecycleEvent.WILL_MOUNT);\n\n if (this.#router) {\n this.#root = await this.#router[MOUNT](parentElement, this.#context);\n this.#context.setState(ROUTER, this.#router);\n } else {\n this.#root = new ViewNode(this.#context, this.#view, {});\n }\n this.#root.mount(parentElement);\n this.#mounted = true;\n\n Context.emit(this.#context, LifecycleEvent.DID_MOUNT);\n }\n\n async unmount() {\n if (!this.#mounted) return Promise.resolve();\n\n Context.emit(this.#context, LifecycleEvent.WILL_UNMOUNT);\n this.#mounted = false;\n\n this.#root.unmount(false);\n if (this.#router) {\n await this.#router[UNMOUNT]();\n }\n\n for (const callback of this.#cleanup) {\n callback();\n }\n this.#cleanup = [];\n\n Context.emit(this.#context, LifecycleEvent.DID_UNMOUNT);\n }\n\n #getElement(element: string | Element): Element {\n if (typeof element === \"string\") {\n const match = document.querySelector(element);\n if (!match) {\n throw new Error(`Selector '${element}' did not many any element.`);\n }\n return match;\n } else if (element instanceof Element) {\n return element;\n } else {\n throw new Error(\"Expected a selector string or DOM element.\");\n }\n }\n}\n\nexport interface CreateAppOptions {\n context?: Context;\n}\n\nexport function createApp(view: View<{}>, options?: CreateAppOptions): App;\nexport function createApp(routerOptions: RouterOptions, options?: CreateAppOptions): App;\nexport function createApp(router: Router, options?: CreateAppOptions): App;\n\nexport function createApp(entry: View<{}> | RouterOptions | Router, options?: CreateAppOptions) {\n if (entry instanceof Router) {\n return new App({ ...options, router: entry });\n } else if (typeOf(entry) === \"object\") {\n return new App({ ...options, router: createRouter(entry as RouterOptions) });\n } else {\n return new App({ ...options, view: entry as View<{}> });\n }\n}\n","import type { Renderable } from \"../../types\";\nimport type { Context } from \"../context\";\nimport { type Key, RepeatNode } from \"../nodes/repeat\";\nimport { type Signal } from \"../signals\";\n\nexport interface ForProps<T> {\n /**\n * An array of items to render.\n */\n each: Signal<T[]>;\n /**\n * A function to extract a unique key that identifies each item.\n * If no `key` function is passed, object identity (===) will be used.\n */\n key?: (item: T, index: number) => Key;\n /**\n * A render function. Takes the item and its index in signal form and returns something to display for each item.\n */\n children: (item: Signal<T>, index: Signal<number>, ctx: Context) => Renderable;\n}\n\nconst defaultKeyFn = (x: any) => x;\n\n/**\n *\n */\nexport function For<T>(props: ForProps<T>, context: Context) {\n return new RepeatNode(context, props.each, props.key ?? defaultKeyFn, props.children);\n}\n","import type { Renderable } from \"../../types\";\nimport type { Context } from \"../context\";\nimport { DynamicNode } from \"../nodes/dynamic\";\nimport { get, type Signal } from \"../signals\";\n\nexport interface ShowProps {\n /**\n * If present, children will be rendered only when this signal holds a truthy value.\n */\n when?: Signal<any>;\n\n /**\n * If present, children will be rendered only when this signal holds a falsy value.\n */\n unless?: Signal<any>;\n\n /**\n * Content to render if conditions permit.\n */\n children: Renderable;\n\n /**\n * Content to render when conditions don't permit `children` to render.\n */\n fallback?: Renderable;\n}\n\n/**\n * Conditionally display children.\n */\nexport function Show(props: ShowProps, context: Context) {\n return new DynamicNode(context, () => {\n let shouldShow = true;\n\n if (props.when != null && props.unless != null) {\n shouldShow = get(props.when) && !get(props.unless);\n } else if (props.when != null) {\n shouldShow = get(props.when);\n } else if (props.unless != null) {\n shouldShow = !get(props.unless);\n }\n\n if (shouldShow) {\n return props.children;\n } else {\n return props.fallback;\n }\n });\n}\n"],"names":["DefaultCrashView","props","m","when","App","options","__privateAdd","_App_instances","_root","_context","_view","_router","_mounted","_crashView","_cleanup","__privateSet","Fragment","Context","__privateGet","view","element","parentElement","__privateMethod","getElement_fn","onLoggerCrash","ViewNode","LifecycleEvent","MOUNT","ROUTER","UNMOUNT","callback","match","createApp","entry","Router","typeOf","createRouter","defaultKeyFn","x","For","context","RepeatNode","Show","DynamicNode","shouldShow","get"],"mappings":";;;;;;;;;;;;;;;AA8BO,SAASA,EAAiBC,GAAuB;AACtD,SAAOC,EAAE,OAAO;AAAA,IACd,OAAO;AAAA,MACL,iBAAiB;AAAA,MACjB,OAAO;AAAA,MACP,SAAS;AAAA,MACT,UAAU;AAAA,MACV,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WD,GAASvC,EAAM,MAAMA,EAAM,OAAOoC,GAAcpC,EAAM,QAAQ;AACtF;ACEgB,SAAAyC,EAAKzC,GAAkBuC,GAAkB;AAChD,SAAA,IAAIG,EAAYH,GAAS,MAAM;AACpC,QAAII,IAAa;AAUjB,WARI3C,EAAM,QAAQ,QAAQA,EAAM,UAAU,OACxC2C,IAAaC,EAAI5C,EAAM,IAAI,KAAK,CAAC4C,EAAI5C,EAAM,MAAM,IACxCA,EAAM,QAAQ,OACV2C,IAAAC,EAAI5C,EAAM,IAAI,IAClBA,EAAM,UAAU,SACZ2C,IAAA,CAACC,EAAI5C,EAAM,MAAM,IAG5B2C,IACK3C,EAAM,WAENA,EAAM;AAAA,EACf,CACD;AACH;"}
1
+ {"version":3,"file":"index.js","sources":["../src/core/views/default-crash-view.ts","../src/core/app.ts","../src/core/views/for.ts","../src/core/views/show.ts","../src/core/views/portal.ts"],"sourcesContent":["import { when, m } from \"../markup.js\";\n\n/**\n * Props passed to the crash view when a crash occurs.\n */\nexport interface CrashViewProps {\n /**\n * JavaScript Error object.\n */\n error: Error;\n\n /**\n * A string to identify the logger that reported this error.\n */\n loggerName: string;\n\n /**\n * Unique identifier to pinpoint the specific view that reported the crash.\n */\n tag?: string;\n\n /**\n * Label for the tag.\n */\n tagName?: string;\n}\n\n/**\n * The crash view displayed unless you specify your own.\n */\nexport function DefaultCrashView(props: CrashViewProps) {\n return m(\"div\", {\n style: {\n backgroundColor: \"#880000\",\n color: \"#fff\",\n padding: \"2rem\",\n position: \"fixed\",\n inset: 0,\n fontSize: \"20px\",\n },\n children: [\n m(\"h1\", { style: { marginBottom: \"0.5rem\" }, children: \"The app has crashed\" }),\n m(\"p\", {\n style: { marginBottom: \"0.25rem\" },\n children: [\n m(\"span\", {\n style: { fontFamily: \"monospace\" },\n children: props.loggerName,\n }),\n when(\n props.tag,\n m(\"span\", {\n style: { fontFamily: \"monospace\", opacity: 0.5 },\n children: ` [${props.tagName ? `${props.tagName}: ` : \"\"}${props.tag}]`,\n }),\n ),\n \" says:\",\n ],\n }),\n m(\"blockquote\", {\n style: {\n backgroundColor: \"#991111\",\n padding: \"0.25em\",\n borderRadius: \"6px\",\n fontFamily: \"monospace\",\n marginBottom: \"1rem\",\n },\n children: [\n m(\"span\", {\n style: {\n display: \"inline-block\",\n backgroundColor: \"red\",\n padding: \"0.1em 0.4em\",\n marginRight: \"0.5em\",\n borderRadius: \"4px\",\n fontSize: \"0.9em\",\n fontWeight: \"bold\",\n },\n children: props.error.name,\n }),\n props.error.message,\n ],\n }),\n m(\"p\", { children: \"Please see the browser console for details.\" }),\n ],\n });\n}\n","import { createRouter } from \"../router\";\nimport { MOUNT, ROUTER, Router, RouterOptions, UNMOUNT } from \"../router/router\";\nimport { typeOf } from \"../typeChecking\";\nimport { View } from \"../types\";\nimport { Context, LifecycleEvent } from \"./context\";\nimport { LoggerCrashProps, onLoggerCrash } from \"./logger\";\nimport { MarkupNode } from \"./markup\";\nimport { ViewNode } from \"./nodes/view\";\nimport { DefaultCrashView } from \"./views/default-crash-view\";\nimport { Fragment } from \"./views/fragment\";\n\ninterface AppOptions {\n view?: View<{}>;\n router?: Router;\n context?: Context;\n}\n\nclass App {\n #root!: MarkupNode;\n #context: Context;\n #view: View<{}>;\n #router?: Router;\n #mounted = false;\n #crashView: View<LoggerCrashProps> = DefaultCrashView;\n\n #cleanup: (() => void)[] = [];\n\n get context() {\n return this.#context;\n }\n\n constructor(options: AppOptions) {\n this.#view = options.view ?? Fragment;\n this.#router = options.router;\n this.#context = options.context ?? new Context(\"App\");\n }\n\n setCrashView(view: View<LoggerCrashProps>) {\n this.#crashView = view;\n return this;\n }\n\n async mount(element: string | Element): Promise<void> {\n if (this.#mounted) return Promise.resolve();\n\n const parentElement = this.#getElement(element);\n\n this.#cleanup.push(\n onLoggerCrash((props) => {\n if (this.#mounted) {\n this.unmount();\n }\n new ViewNode(this.#context, this.#crashView, props).mount(parentElement);\n }),\n );\n\n Context.emit(this.#context, LifecycleEvent.WILL_MOUNT);\n\n if (this.#router) {\n this.#root = await this.#router[MOUNT](parentElement, this.#context);\n this.#context.setState(ROUTER, this.#router);\n } else {\n this.#root = new ViewNode(this.#context, this.#view, {});\n }\n this.#root.mount(parentElement);\n this.#mounted = true;\n\n Context.emit(this.#context, LifecycleEvent.DID_MOUNT);\n }\n\n async unmount() {\n if (!this.#mounted) return Promise.resolve();\n\n Context.emit(this.#context, LifecycleEvent.WILL_UNMOUNT);\n this.#mounted = false;\n\n this.#root.unmount(false);\n if (this.#router) {\n await this.#router[UNMOUNT]();\n }\n\n for (const callback of this.#cleanup) {\n callback();\n }\n this.#cleanup = [];\n\n Context.emit(this.#context, LifecycleEvent.DID_UNMOUNT);\n }\n\n #getElement(element: string | Element): Element {\n if (typeof element === \"string\") {\n const match = document.querySelector(element);\n if (!match) {\n throw new Error(`Selector '${element}' did not many any element.`);\n }\n return match;\n } else if (element instanceof Element) {\n return element;\n } else {\n throw new Error(\"Expected a selector string or DOM element.\");\n }\n }\n}\n\nexport interface CreateAppOptions {\n context?: Context;\n}\n\nexport function createApp(view: View<{}>, options?: CreateAppOptions): App;\nexport function createApp(routerOptions: RouterOptions, options?: CreateAppOptions): App;\nexport function createApp(router: Router, options?: CreateAppOptions): App;\n\nexport function createApp(entry: View<{}> | RouterOptions | Router, options?: CreateAppOptions) {\n if (entry instanceof Router) {\n return new App({ ...options, router: entry });\n } else if (typeOf(entry) === \"object\") {\n return new App({ ...options, router: createRouter(entry as RouterOptions) });\n } else {\n return new App({ ...options, view: entry as View<{}> });\n }\n}\n","import type { Renderable } from \"../../types\";\nimport type { Context } from \"../context\";\nimport { type Key, RepeatNode } from \"../nodes/repeat\";\nimport { type Signal } from \"../signals\";\n\nexport interface ForProps<T> {\n /**\n * An array of items to render.\n */\n each: Signal<T[]>;\n /**\n * A function to extract a unique key that identifies each item.\n * If no `key` function is passed, object identity (===) will be used.\n */\n key?: (item: T, index: number) => Key;\n /**\n * A render function. Takes the item and its index in signal form and returns something to display for each item.\n */\n children: (item: Signal<T>, index: Signal<number>, ctx: Context) => Renderable;\n}\n\nconst defaultKeyFn = (x: any) => x;\n\n/**\n *\n */\nexport function For<T>(props: ForProps<T>, context: Context) {\n return new RepeatNode(context, props.each, props.key ?? defaultKeyFn, props.children);\n}\n","import type { Renderable } from \"../../types\";\nimport type { Context } from \"../context\";\nimport { DynamicNode } from \"../nodes/dynamic\";\nimport { get, type Signal } from \"../signals\";\n\nexport interface ShowProps {\n /**\n * If present, children will be rendered only when this signal holds a truthy value.\n */\n when?: Signal<any>;\n\n /**\n * If present, children will be rendered only when this signal holds a falsy value.\n */\n unless?: Signal<any>;\n\n /**\n * Content to render if conditions permit.\n */\n children: Renderable;\n\n /**\n * Content to render when conditions don't permit `children` to render.\n */\n fallback?: Renderable;\n}\n\n/**\n * Conditionally display children.\n */\nexport function Show(props: ShowProps, context: Context) {\n return new DynamicNode(context, () => {\n let shouldShow = true;\n\n if (props.when != null && props.unless != null) {\n shouldShow = get(props.when) && !get(props.unless);\n } else if (props.when != null) {\n shouldShow = get(props.when);\n } else if (props.unless != null) {\n shouldShow = !get(props.unless);\n }\n\n if (shouldShow) {\n return props.children;\n } else {\n return props.fallback;\n }\n });\n}\n","import { isString } from \"../../typeChecking\";\nimport type { Renderable } from \"../../types\";\nimport type { Context } from \"../context\";\nimport { Markup, MarkupType } from \"../markup\";\n\nexport interface PortalProps {\n /**\n * The parent element or a selector that will match it.\n */\n into: Element | string;\n\n /**\n * Content to render inside the `into` element.\n */\n children: Renderable;\n}\n\n/**\n * Render content into any element on the page.\n */\nexport function Portal(props: PortalProps, ctx: Context) {\n let parent: Element;\n\n if (isString(props.into)) {\n const match = document.querySelector(props.into);\n if (match == null) {\n throw ctx.crash(new Error(`Portal: selector '${props.into}' did not match any element`));\n }\n parent = match;\n } else {\n parent = props.into;\n }\n\n return new Markup(MarkupType.Portal, {\n parent: props.into,\n content: props.children,\n });\n}\n"],"names":["DefaultCrashView","props","m","when","App","options","__privateAdd","_App_instances","_root","_context","_view","_router","_mounted","_crashView","_cleanup","__privateSet","Fragment","Context","__privateGet","view","element","parentElement","__privateMethod","getElement_fn","onLoggerCrash","ViewNode","LifecycleEvent","MOUNT","ROUTER","UNMOUNT","callback","match","createApp","entry","Router","typeOf","createRouter","defaultKeyFn","x","For","context","RepeatNode","Show","DynamicNode","shouldShow","get","Portal","ctx","isString","Markup","MarkupType"],"mappings":";;;;;;;;;;;;;;;AA8BO,SAASA,EAAiBC,GAAuB;AACtD,SAAOC,EAAE,OAAO;AAAA,IACd,OAAO;AAAA,MACL,iBAAiB;AAAA,MACjB,OAAO;AAAA,MACP,SAAS;AAAA,MACT,UAAU;AAAA,MACV,OAAO;AAAA,MACP,UAAU;AAAA,IACZ;AAAA,IACA,UAAU;AAAA,MACRA,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,SAAS,GAAG,UAAU,uBAAuB;AAAA,MAC9EA,EAAE,KAAK;AAAA,QACL,OAAO,EAAE,cAAc,UAAU;AAAA,QACjC,UAAU;AAAA,UACRA,EAAE,QAAQ;AAAA,YACR,OAAO,EAAE,YAAY,YAAY;AAAA,YACjC,UAAUD,EAAM;AAAA,UAAA,CACjB;AAAA,UACDE;AAAA,YACEF,EAAM;AAAA,YACNC,EAAE,QAAQ;AAAA,cACR,OAAO,EAAE,YAAY,aAAa,SAAS,IAAI;AAAA,cAC/C,UAAU,KAAKD,EAAM,UAAU,GAAGA,EAAM,OAAO,OAAO,EAAE,GAAGA,EAAM,GAAG;AAAA,YACrE,CAAA;AAAA,UACH;AAAA,UACA;AAAA,QAAA;AAAA,MACF,CACD;AAAA,MACDC,EAAE,cAAc;AAAA,QACd,OAAO;AAAA,UACL,iBAAiB;AAAA,UACjB,SAAS;AAAA,UACT,cAAc;AAAA,UACd,YAAY;AAAA,UACZ,cAAc;AAAA,QAChB;AAAA,QACA,UAAU;AAAA,UACRA,EAAE,QAAQ;AAAA,YACR,OAAO;AAAA,cACL,SAAS;AAAA,cACT,iBAAiB;AAAA,cACjB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n } from "./markup-DsJHUuod.js";
1
+ import { M as n } from "./markup-DjDexAN5.js";
2
2
  import { F as m } from "./fragment-BahD_BJA.js";
3
3
  function u(e, r, t, o, a, i) {
4
4
  return new n(e, t != null ? { ...r, key: t } : r);
@@ -1,4 +1,4 @@
1
- import { M as u } from "./markup-DsJHUuod.js";
1
+ import { M as u } from "./markup-DjDexAN5.js";
2
2
  import { F as m } from "./fragment-BahD_BJA.js";
3
3
  function o(t, n, r) {
4
4
  return new u(t, r != null ? { ...n, key: r } : n);
@@ -1,5 +1,5 @@
1
- import { a as d } from "./typeChecking-D0-H8_Xm.js";
2
- import { g as w, u as i, c as m, p as o, q as h, r as b } from "./signals-BDlRtifZ.js";
1
+ import { i as d } from "./typeChecking-_dGK_0uR.js";
2
+ import { g as i, u as w, c as m, p as o, q as h, r as b } from "./signals-CkfFHd0d.js";
3
3
  let g = {
4
4
  info: "development",
5
5
  log: "development",
@@ -13,7 +13,7 @@ function $(r) {
13
13
  }
14
14
  function k(r, e) {
15
15
  const c = (e == null ? void 0 : e.console) ?? v(), t = (a) => {
16
- let n = i(r);
16
+ let n = w(r);
17
17
  if (g[a] === !1 || d(g[a]) && g[a] !== m() || !s(n))
18
18
  return h;
19
19
  {
@@ -46,7 +46,7 @@ function k(r, e) {
46
46
  u = !0;
47
47
  const n = {
48
48
  error: a,
49
- loggerName: w(r),
49
+ loggerName: i(r),
50
50
  tag: e == null ? void 0 : e.tag,
51
51
  tagName: e == null ? void 0 : e.tagName
52
52
  };
@@ -79,4 +79,4 @@ export {
79
79
  $ as o,
80
80
  x as s
81
81
  };
82
- //# sourceMappingURL=logger-BuZRMjzE.js.map
82
+ //# sourceMappingURL=logger-CmXtRdEI.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger-BuZRMjzE.js","sources":["../src/core/logger.ts"],"sourcesContent":["import { isString } from \"../typeChecking.js\";\nimport type { Env } from \"../types.js\";\nimport { createMatcher, noOp, okhash, type MatcherFunction } from \"../utils.js\";\nimport { getEnv } from \"./env.js\";\nimport { get, untracked, type MaybeSignal } from \"./signals.js\";\n\nexport interface LogLevels {\n info: boolean | Env;\n log: boolean | Env;\n warn: boolean | Env;\n error: boolean | Env;\n}\n\nexport interface Logger {\n info(...args: any[]): void;\n log(...args: any[]): void;\n warn(...args: any[]): void;\n error(...args: any[]): void;\n crash(error: Error): Error;\n}\n\nexport interface LoggerOptions {\n /**\n * Tag value to print with logs.\n */\n tag?: string;\n\n /**\n * Label for tag value. Will be printed without a label if not specified.\n */\n tagName?: string;\n\n /**\n * Console object to use for logging (mostly for testing). Uses window.console by default.\n */\n console?: any;\n}\n\nexport interface LoggerCrashProps {\n error: Error;\n loggerName: string;\n tag?: string;\n tagName?: string;\n}\n\nlet levels: LogLevels = {\n info: \"development\",\n log: \"development\",\n warn: \"development\",\n error: true,\n};\nlet match: MatcherFunction = createMatcher(\"*,-dolla.*\");\nlet crashListeners: ((context: LoggerCrashProps) => void)[] = [];\nlet isCrashed = false;\n\n/**\n * Listen for logged crashes.\n */\nexport function onLoggerCrash(listener: (context: LoggerCrashProps) => void) {\n crashListeners.push(listener);\n\n return function cancel() {\n crashListeners.splice(crashListeners.indexOf(listener), 1);\n };\n}\n\nexport function createLogger(name: MaybeSignal<string>, options?: LoggerOptions): Logger {\n const _console = options?.console ?? _getDefaultConsole();\n\n const bind = (method: keyof LogLevels) => {\n let _name = untracked(name);\n if (levels[method] === false || (isString(levels[method]) && levels[method] !== getEnv()) || !match(_name)) {\n return noOp;\n } else {\n let label = `%c${_name}`;\n if (options?.tag) {\n if (options.tagName) {\n label += ` %c[${options.tagName}: %c${options.tag}%c]`;\n } else {\n label += ` %c[%c${options.tag}%c]`;\n }\n } else {\n label += `%c%c%c`;\n }\n return _console[method].bind(\n _console,\n label,\n `color:${okhash(label)};font-weight:bold`,\n `color:#777`,\n `color:#aaa`,\n `color:#777`,\n );\n }\n };\n\n return {\n get info() {\n return bind(\"info\");\n },\n get log() {\n return bind(\"log\");\n },\n get warn() {\n return bind(\"warn\");\n },\n get error() {\n return bind(\"error\");\n },\n crash(error: Error) {\n if (!isCrashed) {\n isCrashed = true;\n const ctx: LoggerCrashProps = {\n error,\n loggerName: get(name),\n tag: options?.tag,\n tagName: options?.tagName,\n };\n\n for (const listener of crashListeners) {\n listener(ctx);\n }\n\n throw error;\n }\n\n return error;\n },\n };\n}\n\nexport function setLogFilter(filter: string | RegExp) {\n match = createMatcher(filter);\n}\n\nexport function setLogLevels(options: Partial<LogLevels>) {\n for (const key in options) {\n const value = options[key as keyof LogLevels];\n if (value) {\n levels[key as keyof LogLevels] = value;\n }\n }\n}\n\nfunction _getDefaultConsole() {\n if (typeof window !== \"undefined\" && window.console) {\n return window.console;\n }\n if (typeof global !== \"undefined\" && global.console) {\n return global.console;\n }\n}\n"],"names":["levels","match","createMatcher","crashListeners","isCrashed","onLoggerCrash","listener","createLogger","name","options","_console","_getDefaultConsole","bind","method","_name","untracked","isString","getEnv","noOp","label","okhash","error","ctx","get","setLogFilter","filter","setLogLevels","key","value"],"mappings":";;AA6CA,IAAIA,IAAoB;AAAA,EACtB,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AACT,GACIC,IAAyBC,EAAc,YAAY,GACnDC,IAA0D,CAAC,GAC3DC,IAAY;AAKT,SAASC,EAAcC,GAA+C;AAC3E,SAAAH,EAAe,KAAKG,CAAQ,GAErB,WAAkB;AACvB,IAAAH,EAAe,OAAOA,EAAe,QAAQG,CAAQ,GAAG,CAAC;AAAA,EAC3D;AACF;AAEgB,SAAAC,EAAaC,GAA2BC,GAAiC;AACjF,QAAAC,KAAWD,KAAA,gBAAAA,EAAS,YAAWE,EAAmB,GAElDC,IAAO,CAACC,MAA4B;AACpC,QAAAC,IAAQC,EAAUP,CAAI;AAC1B,QAAIR,EAAOa,CAAM,MAAM,MAAUG,EAAShB,EAAOa,CAAM,CAAC,KAAKb,EAAOa,CAAM,MAAMI,OAAa,CAAChB,EAAMa,CAAK;AAChG,aAAAI;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OAAO;AAEhB,MAAI,OAAO,SAAW,OAAe,OAAO;AAC1C,WAAO,OAAO;AAElB;"}
1
+ {"version":3,"file":"logger-CmXtRdEI.js","sources":["../src/core/logger.ts"],"sourcesContent":["import { isString } from \"../typeChecking.js\";\nimport type { Env } from \"../types.js\";\nimport { createMatcher, noOp, okhash, type MatcherFunction } from \"../utils.js\";\nimport { getEnv } from \"./env.js\";\nimport { get, untracked, type MaybeSignal } from \"./signals.js\";\n\nexport interface LogLevels {\n info: boolean | Env;\n log: boolean | Env;\n warn: boolean | Env;\n error: boolean | Env;\n}\n\nexport interface Logger {\n info(...args: any[]): void;\n log(...args: any[]): void;\n warn(...args: any[]): void;\n error(...args: any[]): void;\n crash(error: Error): Error;\n}\n\nexport interface LoggerOptions {\n /**\n * Tag value to print with logs.\n */\n tag?: string;\n\n /**\n * Label for tag value. Will be printed without a label if not specified.\n */\n tagName?: string;\n\n /**\n * Console object to use for logging (mostly for testing). Uses window.console by default.\n */\n console?: any;\n}\n\nexport interface LoggerCrashProps {\n error: Error;\n loggerName: string;\n tag?: string;\n tagName?: string;\n}\n\nlet levels: LogLevels = {\n info: \"development\",\n log: \"development\",\n warn: \"development\",\n error: true,\n};\nlet match: MatcherFunction = createMatcher(\"*,-dolla.*\");\nlet crashListeners: ((context: LoggerCrashProps) => void)[] = [];\nlet isCrashed = false;\n\n/**\n * Listen for logged crashes.\n */\nexport function onLoggerCrash(listener: (context: LoggerCrashProps) => void) {\n crashListeners.push(listener);\n\n return function cancel() {\n crashListeners.splice(crashListeners.indexOf(listener), 1);\n };\n}\n\nexport function createLogger(name: MaybeSignal<string>, options?: LoggerOptions): Logger {\n const _console = options?.console ?? _getDefaultConsole();\n\n const bind = (method: keyof LogLevels) => {\n let _name = untracked(name);\n if (levels[method] === false || (isString(levels[method]) && levels[method] !== getEnv()) || !match(_name)) {\n return noOp;\n } else {\n let label = `%c${_name}`;\n if (options?.tag) {\n if (options.tagName) {\n label += ` %c[${options.tagName}: %c${options.tag}%c]`;\n } else {\n label += ` %c[%c${options.tag}%c]`;\n }\n } else {\n label += `%c%c%c`;\n }\n return _console[method].bind(\n _console,\n label,\n `color:${okhash(label)};font-weight:bold`,\n `color:#777`,\n `color:#aaa`,\n `color:#777`,\n );\n }\n };\n\n return {\n get info() {\n return bind(\"info\");\n },\n get log() {\n return bind(\"log\");\n },\n get warn() {\n return bind(\"warn\");\n },\n get error() {\n return bind(\"error\");\n },\n crash(error: Error) {\n if (!isCrashed) {\n isCrashed = true;\n const ctx: LoggerCrashProps = {\n error,\n loggerName: get(name),\n tag: options?.tag,\n tagName: options?.tagName,\n };\n\n for (const listener of crashListeners) {\n listener(ctx);\n }\n\n throw error;\n }\n\n return error;\n },\n };\n}\n\nexport function setLogFilter(filter: string | RegExp) {\n match = createMatcher(filter);\n}\n\nexport function setLogLevels(options: Partial<LogLevels>) {\n for (const key in options) {\n const value = options[key as keyof LogLevels];\n if (value) {\n levels[key as keyof LogLevels] = value;\n }\n }\n}\n\nfunction _getDefaultConsole() {\n if (typeof window !== \"undefined\" && window.console) {\n return window.console;\n }\n if (typeof global !== \"undefined\" && global.console) {\n return global.console;\n }\n}\n"],"names":["levels","match","createMatcher","crashListeners","isCrashed","onLoggerCrash","listener","createLogger","name","options","_console","_getDefaultConsole","bind","method","_name","untracked","isString","getEnv","noOp","label","okhash","error","ctx","get","setLogFilter","filter","setLogLevels","key","value"],"mappings":";;AA6CA,IAAIA,IAAoB;AAAA,EACtB,MAAM;AAAA,EACN,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AACT,GACIC,IAAyBC,EAAc,YAAY,GACnDC,IAA0D,CAAC,GAC3DC,IAAY;AAKT,SAASC,EAAcC,GAA+C;AAC3E,SAAAH,EAAe,KAAKG,CAAQ,GAErB,WAAkB;AACvB,IAAAH,EAAe,OAAOA,EAAe,QAAQG,CAAQ,GAAG,CAAC;AAAA,EAC3D;AACF;AAEgB,SAAAC,EAAaC,GAA2BC,GAAiC;AACjF,QAAAC,KAA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C9B;AAEO,SAASC,EAAajB,GAA6B;AACxD,aAAWkB,KAAOlB,GAAS;AACnB,UAAAmB,IAAQnB,EAAQkB,CAAsB;AAC5C,IAAIC,MACF5B,EAAO2B,CAAsB,IAAIC;AAAA,EACnC;AAEJ;AAEA,SAASjB,IAAqB;AAC5B,MAAI,OAAO,SAAW,OAAe,OAAO;AAC1C,WAAO,OAAO;AAEhB,MAAI,OAAO,SAAW,OAAe,OAAO;AAC1C,WAAO,OAAO;AAElB;"}
@@ -5,9 +5,9 @@ var J = (n) => {
5
5
  var bt = (n, s, t) => s in n ? gt(n, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[s] = t;
6
6
  var a = (n, s, t) => bt(n, typeof s != "symbol" ? s + "" : s, t), B = (n, s, t) => s.has(n) || J("Cannot " + t);
7
7
  var d = (n, s, t) => (B(n, s, "read from private field"), t ? t.call(n) : s.get(n)), w = (n, s, t) => s.has(n) ? J("Cannot add the same private member more than once") : s instanceof WeakSet ? s.add(n) : s.set(n, t), A = (n, s, t, e) => (B(n, s, "write to private field"), e ? e.call(n, t) : s.set(n, t), t), j = (n, s, t) => (B(n, s, "access private method"), t);
8
- import { b as m, t as yt, i as H, a as Z } from "./typeChecking-D0-H8_Xm.js";
9
- import { u as $, g as N, i as at, j as _, e as x, I as k, t as ht, k as X, l as wt, c as vt, o as xt, n as kt, b as Nt, w as tt, d as Mt, m as St } from "./signals-BDlRtifZ.js";
10
- import { c as Et } from "./logger-BuZRMjzE.js";
8
+ import { b as m, t as yt, a as H, i as Z } from "./typeChecking-_dGK_0uR.js";
9
+ import { u as $, g as N, i as at, j as _, e as x, I as k, t as ht, k as X, l as wt, c as vt, o as xt, n as kt, b as Nt, w as tt, d as Mt, m as St } from "./signals-CkfFHd0d.js";
10
+ import { c as Et } from "./logger-CmXtRdEI.js";
11
11
  var y = /* @__PURE__ */ ((n) => (n[n.WILL_MOUNT = 0] = "WILL_MOUNT", n[n.DID_MOUNT = 1] = "DID_MOUNT", n[n.WILL_UNMOUNT = 2] = "WILL_UNMOUNT", n[n.DID_UNMOUNT = 3] = "DID_UNMOUNT", n[n.DISPOSE = 4] = "DISPOSE", n))(y || {});
12
12
  const V = Symbol("name"), f = Symbol("lifecycle"), b = Symbol("parent"), M = Symbol("stores"), v = Symbol("state");
13
13
  class It {
@@ -1166,14 +1166,14 @@ export {
1166
1166
  pt as M,
1167
1167
  At as R,
1168
1168
  ut as V,
1169
- I as a,
1170
- zt as b,
1169
+ Rt as a,
1170
+ I as b,
1171
1171
  qt as c,
1172
- Rt as d,
1172
+ zt as d,
1173
1173
  Q as m,
1174
1174
  Gt as p,
1175
1175
  mt as r,
1176
1176
  Ft as u,
1177
1177
  Wt as w
1178
1178
  };
1179
- //# sourceMappingURL=markup-DsJHUuod.js.map
1179
+ //# sourceMappingURL=markup-DjDexAN5.js.map