@manyducks.co/dolla 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,7 +39,7 @@ And here's a counter with a lot more going on, plus some comments to explain wha
39
39
  ```jsx
40
40
  import { html, createAtom, createRoot, onMount, onCleanup, onEffect, showIf } from "@manyducks.co/dolla";
41
41
 
42
- function Counter() {
42
+ function Counter(props) {
43
43
  // An atom is the basic building block of dynamic state.
44
44
  // It consists of a getter function and a setter function, returned as a tuple:
45
45
  const [count, setCount] = createAtom(0);
@@ -1,4 +1,4 @@
1
- import type { Store } from "../types.js";
1
+ import { Store } from "../types.js";
2
2
  import { ViewNode } from "./markup/nodes/view.js";
3
3
  import { Unwrapped } from "./signals.js";
4
4
  export type LifecycleListener = () => any;
@@ -38,4 +38,9 @@ export declare function addStore<Props, Returns>(context: Context, store: Store<
38
38
  export declare function getStore<Returns>(context: Context, store: Store<any, Returns> & {
39
39
  [STORE_ID]?: symbol;
40
40
  }): Returns;
41
+ type AddStoreHook<Props, Returns> = Props extends undefined ? (context: Context) => Returns : (context: Context, props: Props) => Returns;
42
+ type GetStoreHook<Returns> = (context: Context) => Returns;
43
+ type StoreHooks<Props, Returns> = [AddStoreHook<Props, Returns>, GetStoreHook<Returns>];
44
+ export declare function createStore<Returns, Props = undefined>(name: string, fn: (context: Context, props: Props) => Returns): StoreHooks<Props, Returns>;
45
+ export declare function createStore<Returns, Props = undefined>(fn: (context: Context, props: Props) => Returns): StoreHooks<Props, Returns>;
41
46
  export {};
@@ -1,9 +1,9 @@
1
- import { Context } from "./context.js";
1
+ import { Context } from "./context";
2
2
  export declare const noOp: () => void;
3
3
  export type LogLevel = "info" | "log" | "warn" | "error" | "silent";
4
4
  export declare const setLogLevel: (level: LogLevel) => void;
5
5
  export declare const setLogFilter: (filter: (name: string) => boolean) => void;
6
- export declare function getDebug(context: Context, ...tags: [string, any][]): {
6
+ export declare function getDebug(c: Context, ...tags: [string, any][]): {
7
7
  readonly info: (...args: any[]) => void;
8
8
  readonly trace: (...args: any[]) => void;
9
9
  readonly log: (...args: any[]) => void;
@@ -2,12 +2,12 @@ export { createRoot } from "./root.js";
2
2
  export type { DollaPlugin } from "./root.js";
3
3
  export { batch, compose, createAtom, createEffect, createSetter, createStream, peek, subscribe, unwrap, } from "./signals.js";
4
4
  export type { Getter, Setter } from "./signals.js";
5
- export { addStore, getNearestViewNode, getRootElement, getStore, onCleanup, onEffect, onMount } from "./context.js";
5
+ export { addStore, createStore, getNearestViewNode, getRootElement, getStore, onCleanup, onEffect, onMount, } from "./context.js";
6
6
  export type { Context } from "./context.js";
7
7
  export { createDebug, getDebug, setLogFilter, setLogLevel } from "./debug.js";
8
8
  export { createPortal, forEach, hideIf, showIf } from "./markup/helpers.js";
9
9
  export { html } from "./markup/html.js";
10
- export { ViewNode } from "./markup/nodes/view.js";
10
+ export { createView, ViewNode } from "./markup/nodes/view.js";
11
11
  export type { Markup, MarkupNode } from "./markup/types.js";
12
12
  export { createMarkup, render } from "./markup/utils.js";
13
13
  export { createRef } from "./ref.js";
@@ -1,4 +1,4 @@
1
- import type { View } from "../../../types.js";
1
+ import type { Renderable, View } from "../../../types.js";
2
2
  import { ComponentState, Context } from "../../context.js";
3
3
  import { MarkupNode } from "../types.js";
4
4
  export declare const VIEW: unique symbol;
@@ -15,3 +15,9 @@ export declare class ViewNode<P> extends MarkupNode {
15
15
  unmount(skipDOM?: boolean): void;
16
16
  move(parent: Element, after?: Node): void;
17
17
  }
18
+ type GenericProps = {
19
+ [prop: string]: any;
20
+ };
21
+ export declare function createView<Props = GenericProps>(name: string, callback: (context: Context, props: Props) => Renderable): View<Props>;
22
+ export declare function createView<Props = GenericProps>(callback: (context: Context, props: Props) => Renderable): View<Props>;
23
+ export {};
@@ -462,7 +462,7 @@ function xe(e) {
462
462
  }
463
463
  //#endregion
464
464
  //#region src/core/markup/types.ts
465
- var Se = Symbol(), Ce = Symbol(), we = Symbol(), A = class {
465
+ var Se = Symbol.for("$_IS_MARKUP"), Ce = Symbol.for("$_IS_MARKUP_NODE"), we = Symbol.for("$_IS_MARKUP_NODE_CLASS"), A = class {
466
466
  static [we] = !0;
467
467
  get [Ce]() {
468
468
  return !0;
@@ -558,7 +558,7 @@ var N = class extends A {
558
558
  a && (r = a);
559
559
  }
560
560
  }
561
- }, Te = Symbol("parentElement"), P = Symbol("debug"), F = Symbol("isSVG"), Ee = ["ref", "children"], De = class extends A {
561
+ }, Te = Symbol.for("$_PARENT_ELEMENT"), P = Symbol.for("$_DEBUG"), F = Symbol.for("$_IS_SVG"), Ee = ["ref", "children"], De = class extends A {
562
562
  #e;
563
563
  #t;
564
564
  #n;
@@ -568,7 +568,7 @@ var N = class extends A {
568
568
  #o;
569
569
  constructor(e, t, n) {
570
570
  if (super(), this.#t = n, this.#n = e, t === "svg" ? (this.#n = K(e), this.#n[F] = !0, this.#r = !0) : this.#n[F] && t === "foreignObject" && (this.#n = K(e), this.#n[F] = !1, this.#r = !1), this.#n[F] ? this.#e = document.createElementNS("http://www.w3.org/2000/svg", t) : this.#e = document.createElement(t), this.#n[P]) {
571
- let e = Be(this.#n);
571
+ let e = Ve(this.#n);
572
572
  e && (this.#e.dataset.view = e.context.name);
573
573
  }
574
574
  }
@@ -748,7 +748,7 @@ function H(e, t, n) {
748
748
  }
749
749
  //#endregion
750
750
  //#region src/core/markup/nodes/view.ts
751
- var Ie = Symbol.for("ViewNode"), U = class extends A {
751
+ var Ie = Symbol.for("$_VIEW_NODE"), U = class extends A {
752
752
  #e;
753
753
  #t;
754
754
  #n;
@@ -776,17 +776,26 @@ var Ie = Symbol.for("ViewNode"), U = class extends A {
776
776
  move(e, t) {
777
777
  this.#n?.move(e, t);
778
778
  }
779
- }, W = Symbol("Context.mountListeners"), G = Symbol("Context.cleanupListeners");
779
+ };
780
+ function Le(...e) {
781
+ let t, n;
782
+ return e.length === 2 ? (r(typeof e[0] == "string", "When 2 args, the first must be a string"), r(typeof e[1] == "function", "When 2 args, the second must be a function"), t = e[0], n = e[1]) : e.length === 1 && (r(typeof e[0] == "function", "When 1 arg, the value must be a function"), n = e[0]), function(e) {
783
+ return t && (this.name = t), n(this, e);
784
+ };
785
+ }
786
+ //#endregion
787
+ //#region src/core/context.ts
788
+ var W = Symbol.for("$_CONTEXT_MOUNT_LISTENERS"), G = Symbol.for("$_CONTEXT_CLEANUP_LISTENERS");
780
789
  function K(e) {
781
790
  return Object.assign(Object.create(e ?? null), { isMounted: !1 });
782
791
  }
783
792
  function q(e) {
784
- e.isMounted || (e.isMounted = !0, Le(e, W));
793
+ e.isMounted || (e.isMounted = !0, Re(e, W));
785
794
  }
786
795
  function J(e) {
787
- e.isMounted && (e.isMounted = !1, Le(e, G));
796
+ e.isMounted && (e.isMounted = !1, Re(e, G));
788
797
  }
789
- function Le(e, t) {
798
+ function Re(e, t) {
790
799
  if (Object.hasOwn(e, t)) {
791
800
  for (let n of e[t]) n();
792
801
  e[t].length = 0;
@@ -798,30 +807,58 @@ function Y(e, t) {
798
807
  function X(e, t) {
799
808
  Object.hasOwn(e, G) ? e[G].push(t) : e[G] = [t];
800
809
  }
801
- function Re(e, t, n) {
810
+ function ze(e, t, n) {
802
811
  e.isMounted ? X(e, T(t, n)) : Y(e, () => {
803
812
  X(e, T(t, n));
804
813
  });
805
814
  }
806
- function ze(e) {
815
+ function Be(e) {
807
816
  return e[Te];
808
817
  }
809
- function Be(e) {
818
+ function Ve(e) {
810
819
  return e[Ie];
811
820
  }
812
- var Z = Symbol("Dolla.StoreId");
813
- function Ve(e, t, ...n) {
821
+ var Z = Symbol.for("$_STORE_ID");
822
+ function He(e, t, ...n) {
814
823
  t[Z] ??= Symbol(t.name), r(!Object.hasOwn(e, t[Z]), "Store was already provided on this context.");
815
824
  let i = K(e);
816
825
  return Y(e, () => q(i)), X(e, () => J(i)), i.name = t.name, e[t[Z]] = t.call(i, n[0], i);
817
826
  }
818
- function He(e, t) {
827
+ function Ue(e, t) {
819
828
  let n = t[Z], i = n ? e[n] : void 0;
820
829
  return r(i != null, `Store '${t.name}' is not provided by this context.`), i;
821
830
  }
831
+ function We(e, t) {
832
+ r(!Object.hasOwn(e, this.id), "Store was already provided on this context.");
833
+ let n = K(e);
834
+ return Y(e, () => q(n)), X(e, () => J(n)), this.name && (n.name = this.name), e[this.id] = this.fn(n, t);
835
+ }
836
+ function Ge(e) {
837
+ let t = e[this.id];
838
+ return r(t != null, "Store is not provided by this context."), t;
839
+ }
840
+ function Ke(...e) {
841
+ if (e.length === 2) {
842
+ r(typeof e[0] == "string", "When 2 args are present the first must be a string"), r(typeof e[1] == "function", "When 2 args are present the second must be a function"), e[1][Z] ??= Symbol(e[0]);
843
+ let t = {
844
+ id: Symbol(),
845
+ fn: e[1],
846
+ name: e[0]
847
+ };
848
+ return [We.bind(t), Ge.bind(t)];
849
+ } else {
850
+ r(e.length === 1 && typeof e[0] == "function", "Expected one function as an argument"), e[0][Z] ??= Symbol();
851
+ let t = {
852
+ id: Symbol(),
853
+ fn: e[0],
854
+ name: e[0].name
855
+ };
856
+ return [We.bind(t), Ge.bind(t)];
857
+ }
858
+ }
822
859
  //#endregion
823
860
  //#region src/core/root.ts
824
- function Ue(e, t) {
861
+ function qe(e, t) {
825
862
  let n = a(e) ? document.querySelector(e) : e;
826
863
  r(n, "Element cannot be null.");
827
864
  let i = K();
@@ -846,58 +883,57 @@ function Ue(e, t) {
846
883
  }
847
884
  //#endregion
848
885
  //#region src/core/debug.ts
849
- var We = () => {}, Ge = {
886
+ var Je = () => {}, Ye = {
850
887
  trace: 1,
851
888
  info: 1,
852
889
  log: 2,
853
890
  warn: 3,
854
891
  error: 4,
855
892
  silent: 5
856
- }, Ke = 1, qe = (e) => !e.startsWith("dolla:"), Je = (e) => {
857
- Ke = Ge[e] || 1;
858
- }, Ye = (e) => {
859
- qe = e;
893
+ }, Xe = 1, Ze = (e) => !e.startsWith("dolla:"), Qe = (e) => {
894
+ Xe = Ye[e] || 1;
895
+ }, $e = (e) => {
896
+ Ze = e;
860
897
  }, Q = globalThis.console || {};
861
- function Xe(e, ...t) {
862
- let n = e.name, r, i = (e, i) => {
863
- if (i < Ke || !qe(n) || !Q[e]) return We;
864
- if (!r) {
865
- let e = "%c" + n, i = [`color:${Qe(n)};font-weight:bold`];
866
- for (let [n, r] of t) e += `%c[${n}: %c${r}%c]`, i.push("color:#777", "color:#aaa", "color:#777");
867
- r = [e, ...i];
898
+ function et(e, ...t) {
899
+ return tt(e.name, ...t);
900
+ }
901
+ function tt(e, ...t) {
902
+ let n, r = (r, i) => {
903
+ if (i < Xe || !Ze(e) || !Q[r]) return Je;
904
+ if (!n) {
905
+ let r = "%c" + e, i = [`color:${nt(e)};font-weight:bold`];
906
+ for (let [e, n] of t) r += `%c[${e}: %c${n}%c]`, i.push("color:#777", "color:#aaa", "color:#777");
907
+ n = [r, ...i];
868
908
  }
869
- return Q[e].bind(Q, ...r);
909
+ return Q[r].bind(Q, ...n);
870
910
  };
871
911
  return {
872
912
  get info() {
873
- return i("info", 1);
913
+ return r("info", 1);
874
914
  },
875
915
  get trace() {
876
- return i("trace", 1);
916
+ return r("trace", 1);
877
917
  },
878
918
  get log() {
879
- return i("log", 2);
919
+ return r("log", 2);
880
920
  },
881
921
  get warn() {
882
- return i("warn", 3);
922
+ return r("warn", 3);
883
923
  },
884
924
  get error() {
885
- return i("error", 4);
925
+ return r("error", 4);
886
926
  }
887
927
  };
888
928
  }
889
- function Ze(e, ...t) {
890
- let n = K();
891
- return n.name = e, Xe(n, ...t);
892
- }
893
- function Qe(e) {
929
+ function nt(e) {
894
930
  let t = 0;
895
931
  for (let n = 0; n < e.length; n++) t = (t + e.charCodeAt(n) * 10) % 360;
896
932
  return `oklch(0.68 0.15 ${t}deg)`;
897
933
  }
898
934
  //#endregion
899
935
  //#region src/core/markup/nodes/portal.ts
900
- var $e = class extends A {
936
+ var rt = class extends A {
901
937
  #e = V("");
902
938
  #t;
903
939
  #n;
@@ -921,7 +957,7 @@ var $e = class extends A {
921
957
  move(e, t) {
922
958
  Fe(e, this.#e, t);
923
959
  }
924
- }, et = class extends A {
960
+ }, it = class extends A {
925
961
  #e = V("");
926
962
  #t;
927
963
  #n;
@@ -988,31 +1024,31 @@ var $e = class extends A {
988
1024
  };
989
1025
  //#endregion
990
1026
  //#region src/core/markup/helpers.ts
991
- function tt(e, t, n) {
992
- return o(e) ? L(et, { args: [
1027
+ function at(e, t, n) {
1028
+ return o(e) ? L(it, { args: [
993
1029
  e,
994
1030
  t,
995
1031
  n
996
1032
  ] }) : Array.from(e).map((e, t) => n(() => e, () => t));
997
1033
  }
998
- function nt(e, t, n) {
1034
+ function ot(e, t, n) {
999
1035
  return o(e) ? L(N, { args: [w(() => e() ? t : n)] }) : e ? t : n;
1000
1036
  }
1001
- function rt(e, t, n) {
1002
- return nt(e, t, n);
1037
+ function st(e, t, n) {
1038
+ return ot(e, t, n);
1003
1039
  }
1004
- function it(e, t, n) {
1005
- return nt(e, n, t);
1040
+ function ct(e, t, n) {
1041
+ return ot(e, n, t);
1006
1042
  }
1007
- function at(e, t) {
1008
- return L($e, { args: [t, e] });
1043
+ function lt(e, t) {
1044
+ return L(rt, { args: [t, e] });
1009
1045
  }
1010
1046
  //#endregion
1011
1047
  //#region src/core/markup/html.ts
1012
1048
  var $ = /* @__PURE__ */ function(e) {
1013
1049
  return e[e.Slash = 0] = "Slash", e[e.Text = 1] = "Text", e[e.Whitespace = 2] = "Whitespace", e[e.TagName = 3] = "TagName", e[e.Comment = 4] = "Comment", e[e.PropSet = 5] = "PropSet", e[e.PropAppend = 6] = "PropAppend", e;
1014
1050
  }($ || {});
1015
- function ot(e, ...t) {
1051
+ function ut(e, ...t) {
1016
1052
  let n = [e, ...t], r = $.Text, i = "", a = "", o = [0], s = "", c = (e) => {
1017
1053
  r === $.Text && (e || (i = i.replace(/^\s*\n\s*|\s*\n\s*$/g, ""))) ? o.push(e ? n[e] : i) : r === $.TagName && (e || i) ? (o[1] = e ? n[e] : i, r = $.Whitespace) : r === $.Whitespace && i === "..." && e ? o[2] = Object.assign(o[2] || {}, n[e]) : r === $.Whitespace && i && !e ? (o[2] = o[2] || {})[i] = !0 : r >= $.PropSet && (r === $.PropSet ? ((o[2] = o[2] || {})[s] = e ? i ? i + n[e] : n[e] : i, r = $.PropAppend) : (e || i) && (o[2][s] += e ? i + n[e] : i)), i = "";
1018
1054
  };
@@ -1047,13 +1083,13 @@ function ot(e, ...t) {
1047
1083
  }
1048
1084
  //#endregion
1049
1085
  //#region src/core/ref.ts
1050
- function st() {
1086
+ function dt() {
1051
1087
  let e;
1052
1088
  return ((...t) => t.length ? (e = t[0], () => {
1053
1089
  e = void 0;
1054
1090
  }) : e);
1055
1091
  }
1056
1092
  //#endregion
1057
- export { ge as A, t as B, R as C, w as D, be as E, r as F, i as I, o as L, D as M, O as N, C as O, E as P, l as R, L as S, N as T, X as _, it as a, U as b, Xe as c, Ue as d, Ve as f, He as g, ze as h, tt as i, xe as j, T as k, Ye as l, Be as m, ot as n, rt as o, K as p, at as r, Ze as s, st as t, Je as u, Re as v, P as w, H as x, Y as y, a as z };
1093
+ export { T as A, a as B, L as C, be as D, N as E, E as F, r as I, i as L, xe as M, D as N, w as O, O as P, o as R, H as S, P as T, t as V, X as _, ct as a, U as b, et as c, qe as d, He as f, Ue as g, Be as h, at as i, ge as j, C as k, $e as l, Ve as m, ut as n, st as o, Ke as p, lt as r, tt as s, dt as t, Qe as u, ze as v, R as w, Le as x, Y as y, l as z };
1058
1094
 
1059
- //# sourceMappingURL=core-CHBZF6Mb.js.map
1095
+ //# sourceMappingURL=core-C4DWUGxz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-C4DWUGxz.js","names":["#root","#context","#slot","#root","#unsubscribe","#update","#cleanup","#children","#props","#context","#ownContext","#root","#applyProps","#childNodes","#refCleanup","#unsubscribers","#applyStyles","#applyClasses","#attach","#props","#view","#node","#context","#value","#parent","#anchor","#childNode","#context","#items","#key","#render","#root","#unsubscribe","#connectedItems"],"sources":["../src/utils.ts","../src/core/signals.ts","../src/core/markup/types.ts","../src/core/markup/nodes/dom.ts","../src/core/markup/scheduler.ts","../src/core/markup/nodes/dynamic.ts","../src/core/symbols.ts","../src/core/markup/nodes/element.ts","../src/core/markup/utils.ts","../src/core/markup/nodes/view.ts","../src/core/context.ts","../src/core/root.ts","../src/core/debug.ts","../src/core/markup/nodes/portal.ts","../src/core/markup/nodes/repeat.ts","../src/core/markup/helpers.ts","../src/core/markup/html.ts","../src/core/ref.ts"],"sourcesContent":["/*=============================*\\\n|| ID Generator ||\n\\*=============================*/\n\nlet lastId = 0;\nexport function uniqueId() {\n return (lastId++).toString(36);\n}\n\n/*=============================*\\\n|| Object Utils ||\n\\*=============================*/\n\n/**\n * Returns a new object without the specified keys.\n * If called without object, returns a function that takes an object\n * and returns a version with the original keys omitted.\n *\n * @param keys - An array of keys to omit.\n * @param object - An object to clone without the omitted keys.\n */\nexport function omit<O extends Record<any, any>>(keys: (keyof O)[], object: O): Record<any, any> {\n const newObject: Record<any, any> = {};\n\n for (const key in object) {\n if (!keys.includes(key)) {\n newObject[key] = object[key];\n }\n }\n\n return newObject;\n}\n\n/*=============================*\\\n|| Type Checking ||\n\\*=============================*/\n\n/**\n * Throws a TypeError unless `condition` is truthy.\n *\n * @param value - Value whose truthiness is in question.\n * @param errorMessage - Optional message for the thrown TypeError.\n */\nexport function assert<T = any>(value: T, errorMessage: string): asserts value is NonNullable<T> {\n if (!value) throw new TypeError(errorMessage);\n}\n\n/**\n * Returns true if `value` is an array.\n */\nexport function isArray(value: unknown): value is Array<unknown> {\n return Array.isArray(value);\n}\n\n/**\n * Returns true when `value` is an array and `check` returns true for every item.\n *\n * @param check - Function to check items against.\n * @param value - A possible array.\n */\nexport function isArrayOf<T>(check: (item: unknown) => boolean, value: unknown): value is T[];\nexport function isArrayOf<T>(check: (item: unknown) => boolean): (value: unknown) => value is T[];\n\nexport function isArrayOf<T>(check: (item: unknown) => boolean, value?: unknown) {\n if (value) {\n return isArray(value) && value.every((item) => check(item));\n } else {\n return (value: unknown) => isArrayOf<T>(check, value);\n }\n}\n\n/**\n * Returns true if `value` is a string.\n */\nexport function isString(value: unknown): value is string {\n return typeof value === \"string\";\n}\n\n/**\n * Returns true if `value` is a function (but not a class).\n */\nexport function isFunction<T = (...args: unknown[]) => unknown>(value: unknown): value is T {\n return typeof value === \"function\" && !isClass(value);\n}\n\nexport function isClass(value: unknown) {\n return /^\\s*class\\s+/.test(String(value));\n}\n\n/**\n * Returns true if `value` is a number.\n */\nexport function isNumber(value: unknown): value is number {\n return typeof value === \"number\" && !isNaN(value);\n}\n\n/**\n * Returns `true` if `value` is an instance of `constructor`.\n *\n * @param constructor - The constructor `value` must be an instance of.\n * @param value - A value that may be an instance of `constructor`.\n */\nexport function isInstanceOf<T extends Function>(constructor: T, value: unknown): value is T;\nexport function isInstanceOf<T extends Function>(constructor: T): (value: unknown) => value is T;\n\nexport function isInstanceOf<T extends Function>(constructor: T, value?: unknown) {\n if (value) {\n return value instanceof constructor;\n } else {\n return (value: unknown) => isInstanceOf(constructor, value);\n }\n}\n\n/**\n * Returns true if `value` is a JavaScript Promise.\n */\nexport function isPromise<T = unknown>(value: unknown): value is Promise<T> {\n return value instanceof Promise;\n}\n\n/**\n * Returns true if `value` is a plain JavaScript object.\n */\nexport function isObject<T = Record<string | number | symbol, unknown>>(value: unknown): value is T {\n return value != null && typeof value === \"object\" && !isArray(value);\n}\n","import { isFunction } from \"../utils.js\";\nimport { Context, onCleanup } from \"./index.js\";\n\ninterface ReactiveNode {\n _deps?: Link;\n _depsTail?: Link;\n _subs?: Link;\n _subsTail?: Link;\n _flags: ReactiveFlags;\n}\n\ninterface EffectNode extends ReactiveNode {\n _fn(): void | (() => void);\n _cleanup?: () => void;\n}\n\ninterface ComputedNode<T = any> extends ReactiveNode {\n _value: T | undefined;\n _getter: (previousValue?: T) => T;\n}\n\ninterface ValueNode<T = any> extends ReactiveNode {\n _currentValue: T;\n _pendingValue: T;\n\n /**\n * If true, notify only when value is !== previous.\n */\n _skipEqualValues: boolean;\n}\n\ninterface Link {\n _version: number;\n _dep: ReactiveNode;\n _sub: ReactiveNode;\n _prevSub: Link | undefined;\n _nextSub: Link | undefined;\n _prevDep: Link | undefined;\n _nextDep: Link | undefined;\n}\n\ninterface Stack<T> {\n _value: T;\n _prev: Stack<T> | undefined;\n}\n\n/*==================================*\\\n|| Signal Internals ||\n\\*==================================*/\n\nconst enum ReactiveFlags {\n None = 0,\n Mutable = 1,\n Watching = 2,\n RecursedCheck = 4,\n Recursed = 8,\n Dirty = 16,\n Pending = 32,\n}\n\nlet cycle = 0;\nlet batchDepth = 0;\nlet notifyIndex = 0;\nlet queuedLength = 0;\nlet activeSub: ReactiveNode | undefined;\n\nconst queued: (EffectNode | undefined)[] = [];\n\nfunction link(dep: ReactiveNode, sub: ReactiveNode, version: number): void {\n const prevDep = sub._depsTail;\n if (prevDep !== undefined && prevDep._dep === dep) {\n return;\n }\n const nextDep = prevDep !== undefined ? prevDep._nextDep : sub._deps;\n if (nextDep !== undefined && nextDep._dep === dep) {\n nextDep._version = version;\n sub._depsTail = nextDep;\n return;\n }\n const prevSub = dep._subsTail;\n if (prevSub !== undefined && prevSub._version === version && prevSub._sub === sub) {\n return;\n }\n const newLink =\n (sub._depsTail =\n dep._subsTail =\n {\n _version: version,\n _dep: dep,\n _sub: sub,\n _prevDep: prevDep,\n _nextDep: nextDep,\n _prevSub: prevSub,\n _nextSub: undefined,\n });\n if (nextDep !== undefined) {\n nextDep._prevDep = newLink;\n }\n if (prevDep !== undefined) {\n prevDep._nextDep = newLink;\n } else {\n sub._deps = newLink;\n }\n if (prevSub !== undefined) {\n prevSub._nextSub = newLink;\n } else {\n dep._subs = newLink;\n }\n}\n\nfunction unwatched(node: ReactiveNode): void {\n if (!(node._flags & ReactiveFlags.Mutable)) {\n effectCleanup.call(node);\n } else if (node._depsTail !== undefined) {\n node._depsTail = undefined;\n node._flags = ReactiveFlags.Mutable | ReactiveFlags.Dirty;\n purgeDeps(node);\n }\n}\n\nfunction unlink(link: Link, sub = link._sub): Link | undefined {\n const dep = link._dep;\n const prevDep = link._prevDep;\n const nextDep = link._nextDep;\n const nextSub = link._nextSub;\n const prevSub = link._prevSub;\n if (nextDep !== undefined) {\n nextDep._prevDep = prevDep;\n } else {\n sub._depsTail = prevDep;\n }\n if (prevDep !== undefined) {\n prevDep._nextDep = nextDep;\n } else {\n sub._deps = nextDep;\n }\n if (nextSub !== undefined) {\n nextSub._prevSub = prevSub;\n } else {\n dep._subsTail = prevSub;\n }\n if (prevSub !== undefined) {\n prevSub._nextSub = nextSub;\n } else if ((dep._subs = nextSub) === undefined) {\n unwatched(dep);\n }\n return nextDep;\n}\n\nfunction notify(effect: EffectNode): void {\n let insertIndex = queuedLength;\n let firstInsertedIndex = insertIndex;\n\n do {\n queued[insertIndex++] = effect;\n effect._flags &= ~ReactiveFlags.Watching;\n effect = effect._subs?._sub as EffectNode;\n if (effect === undefined || !(effect._flags & ReactiveFlags.Watching)) {\n break;\n }\n } while (true);\n\n queuedLength = insertIndex;\n\n while (firstInsertedIndex < --insertIndex) {\n const left = queued[firstInsertedIndex];\n queued[firstInsertedIndex++] = queued[insertIndex];\n queued[insertIndex] = left;\n }\n}\n\nfunction update(node: ReactiveNode): boolean {\n if (node._depsTail !== undefined) {\n return updateComputed(node as ComputedNode);\n } else {\n return updateValue(node as ValueNode);\n }\n}\n\nfunction propagate(link: Link): void {\n let next = link._nextSub;\n let stack: Stack<Link | undefined> | undefined;\n\n top: do {\n const sub = link._sub;\n let flags = sub._flags;\n\n if (\n !(flags & (ReactiveFlags.RecursedCheck | ReactiveFlags.Recursed | ReactiveFlags.Dirty | ReactiveFlags.Pending))\n ) {\n sub._flags = flags | ReactiveFlags.Pending;\n } else if (!(flags & (ReactiveFlags.RecursedCheck | ReactiveFlags.Recursed))) {\n flags = ReactiveFlags.None;\n } else if (!(flags & ReactiveFlags.RecursedCheck)) {\n sub._flags = (flags & ~ReactiveFlags.Recursed) | ReactiveFlags.Pending;\n } else if (!(flags & (ReactiveFlags.Dirty | ReactiveFlags.Pending)) && isValidLink(link, sub)) {\n sub._flags = flags | (ReactiveFlags.Recursed | ReactiveFlags.Pending);\n flags &= ReactiveFlags.Mutable;\n } else {\n flags = ReactiveFlags.None;\n }\n\n if (flags & ReactiveFlags.Watching) {\n notify(sub as EffectNode);\n }\n\n if (flags & ReactiveFlags.Mutable) {\n const subSubs = sub._subs;\n if (subSubs !== undefined) {\n const nextSub = (link = subSubs)._nextSub;\n if (nextSub !== undefined) {\n stack = { _value: next, _prev: stack };\n next = nextSub;\n }\n continue;\n }\n }\n\n if ((link = next!) !== undefined) {\n next = link._nextSub;\n continue;\n }\n\n while (stack !== undefined) {\n link = stack._value!;\n stack = stack._prev;\n if (link !== undefined) {\n next = link._nextSub;\n continue top;\n }\n }\n\n break;\n } while (true);\n}\n\nfunction checkDirty(link: Link, sub: ReactiveNode): boolean {\n let stack: Stack<Link> | undefined;\n let checkDepth = 0;\n let dirty = false;\n\n top: do {\n const dep = link._dep;\n const flags = dep._flags;\n\n if (sub._flags & ReactiveFlags.Dirty) {\n dirty = true;\n } else if (\n (flags & (ReactiveFlags.Mutable | ReactiveFlags.Dirty)) ===\n (ReactiveFlags.Mutable | ReactiveFlags.Dirty)\n ) {\n if (update(dep)) {\n const subs = dep._subs!;\n if (subs._nextSub !== undefined) {\n shallowPropagate(subs);\n }\n dirty = true;\n }\n } else if (\n (flags & (ReactiveFlags.Mutable | ReactiveFlags.Pending)) ===\n (ReactiveFlags.Mutable | ReactiveFlags.Pending)\n ) {\n if (link._nextSub !== undefined || link._prevSub !== undefined) {\n stack = { _value: link, _prev: stack };\n }\n link = dep._deps!;\n sub = dep;\n ++checkDepth;\n continue;\n }\n\n if (!dirty) {\n const nextDep = link._nextDep;\n if (nextDep !== undefined) {\n link = nextDep;\n continue;\n }\n }\n\n while (checkDepth--) {\n const firstSub = sub._subs!;\n const hasMultipleSubs = firstSub._nextSub !== undefined;\n if (hasMultipleSubs) {\n link = stack!._value;\n stack = stack!._prev;\n } else {\n link = firstSub;\n }\n if (dirty) {\n if (update(sub)) {\n if (hasMultipleSubs) {\n shallowPropagate(firstSub);\n }\n sub = link._sub;\n continue;\n }\n dirty = false;\n } else {\n sub._flags &= ~ReactiveFlags.Pending;\n }\n sub = link._sub;\n const nextDep = link._nextDep;\n if (nextDep !== undefined) {\n link = nextDep;\n continue top;\n }\n }\n\n return dirty;\n } while (true);\n}\n\nfunction shallowPropagate(link: Link): void {\n do {\n const sub = link._sub;\n const flags = sub._flags;\n if ((flags & (ReactiveFlags.Pending | ReactiveFlags.Dirty)) === ReactiveFlags.Pending) {\n sub._flags = flags | ReactiveFlags.Dirty;\n if ((flags & (ReactiveFlags.Watching | ReactiveFlags.RecursedCheck)) === ReactiveFlags.Watching) {\n notify(sub as EffectNode);\n }\n }\n } while ((link = link._nextSub!) !== undefined);\n}\n\nfunction isValidLink(checkLink: Link, sub: ReactiveNode): boolean {\n let link = sub._depsTail;\n while (link !== undefined) {\n if (link === checkLink) {\n return true;\n }\n link = link._prevDep;\n }\n return false;\n}\n\nfunction setActiveSub(sub?: ReactiveNode) {\n const prevSub = activeSub;\n activeSub = sub;\n return prevSub;\n}\n\nfunction updateComputed(c: ComputedNode): boolean {\n ++cycle;\n c._depsTail = undefined;\n c._flags = ReactiveFlags.Mutable | ReactiveFlags.RecursedCheck;\n const prevSub = setActiveSub(c);\n try {\n const oldValue = c._value;\n return oldValue !== (c._value = c._getter(oldValue));\n } finally {\n activeSub = prevSub;\n c._flags &= ~ReactiveFlags.RecursedCheck;\n purgeDeps(c);\n }\n}\n\nfunction updateValue(v: ValueNode): boolean {\n v._flags = ReactiveFlags.Mutable;\n const didChange = v._currentValue !== (v._currentValue = v._pendingValue);\n return v._skipEqualValues ? didChange : true;\n}\n\nfunction run(e: EffectNode): void {\n const flags = e._flags;\n if (flags & ReactiveFlags.Dirty || (flags & ReactiveFlags.Pending && checkDirty(e._deps!, e))) {\n ++cycle;\n e._depsTail = undefined;\n e._flags = ReactiveFlags.Watching | ReactiveFlags.RecursedCheck;\n const prevSub = setActiveSub(e);\n try {\n e._cleanup?.();\n e._cleanup = undefined;\n const result = e._fn();\n if (isFunction(result)) e._cleanup = result;\n } finally {\n activeSub = prevSub;\n e._flags &= ~ReactiveFlags.RecursedCheck;\n purgeDeps(e);\n }\n } else {\n e._flags = ReactiveFlags.Watching;\n }\n}\n\nfunction flush(): void {\n try {\n while (notifyIndex < queuedLength) {\n const effect = queued[notifyIndex]!;\n queued[notifyIndex++] = undefined;\n run(effect);\n }\n } finally {\n while (notifyIndex < queuedLength) {\n const effect = queued[notifyIndex]!;\n queued[notifyIndex++] = undefined;\n effect._flags |= ReactiveFlags.Watching | ReactiveFlags.Recursed;\n }\n notifyIndex = 0;\n queuedLength = 0;\n }\n}\n\nfunction purgeDeps(sub: ReactiveNode) {\n const depsTail = sub._depsTail;\n let dep = depsTail !== undefined ? depsTail._nextDep : sub._deps;\n while (dep !== undefined) {\n dep = unlink(dep, sub);\n }\n}\n\n/*==================================*\\\n|| API Implementation ||\n\\*==================================*/\n\nfunction resolveValue<T>(next: SetterAction<T>, current: T): T {\n if (isFunction(next)) return peek(() => next(current)) as T;\n return next as T;\n}\n\nfunction computedGetter(this: ComputedNode) {\n const flags = this._flags;\n if (\n flags & ReactiveFlags.Dirty ||\n (flags & ReactiveFlags.Pending &&\n (checkDirty(this._deps!, this) || ((this._flags = flags & ~ReactiveFlags.Pending), false)))\n ) {\n if (updateComputed(this)) {\n const subs = this._subs;\n if (subs !== undefined) {\n shallowPropagate(subs);\n }\n }\n } else if (!flags) {\n this._flags = ReactiveFlags.Mutable | ReactiveFlags.RecursedCheck;\n const prevSub = setActiveSub(this);\n try {\n this._value = unwrap(this._getter());\n } finally {\n activeSub = prevSub;\n this._flags &= ~ReactiveFlags.RecursedCheck;\n }\n }\n const sub = activeSub;\n if (sub !== undefined) {\n link(this, sub, cycle);\n }\n return this._value!;\n}\n\nfunction computedSetter(this: ComputedNode, next: SetterAction<any>) {\n const value = resolveValue(next, this._value);\n if (this._value !== value) {\n this._value = value;\n\n // Clear Dirty and Pending so _computedGetter skips updateComputed\n this._flags &= ~(ReactiveFlags.Dirty | ReactiveFlags.Pending);\n\n // Manually push the Dirty flag to all subscribers\n let link = this._subs;\n while (link !== undefined) {\n const sub = link._sub;\n const subFlags = sub._flags;\n\n // Only modify and notify if it isn't already queued for an update\n if ((subFlags & (ReactiveFlags.Dirty | ReactiveFlags.Pending)) === 0) {\n // Force the node to be Dirty so it bypasses checkDirty() upon flush\n sub._flags = subFlags | ReactiveFlags.Dirty;\n notify(sub as EffectNode);\n }\n\n link = link._nextSub;\n }\n\n // Trigger queued effects\n if (!batchDepth) {\n flush();\n }\n }\n return value;\n}\n\nfunction valueGetter<T>(this: ValueNode<T>): T {\n if (this._flags & ReactiveFlags.Dirty) {\n if (updateValue(this)) {\n const subs = this._subs;\n if (subs !== undefined) {\n shallowPropagate(subs);\n }\n }\n }\n let sub = activeSub;\n while (sub !== undefined) {\n if (sub._flags & (ReactiveFlags.Mutable | ReactiveFlags.Watching)) {\n link(this, sub, cycle);\n break;\n }\n sub = sub._subs?._sub;\n }\n return this._currentValue;\n}\n\nfunction valueSetter<T>(this: ValueNode<T>, next: SetterAction<T>): void {\n const value = resolveValue(next, this._pendingValue);\n if (this._pendingValue !== (this._pendingValue = value)) {\n this._flags = ReactiveFlags.Mutable | ReactiveFlags.Dirty;\n const subs = this._subs;\n if (subs !== undefined) {\n propagate(subs);\n if (!batchDepth) {\n flush();\n }\n }\n }\n}\n\nfunction customSetter<T>(this: Getter<T>, callback: (current: T) => T | void, value: SetterAction<T>): T {\n const next = typeof value === \"function\" ? (value as (current: T) => T)(peek(this)) : value;\n const returned = callback(next);\n return returned ?? next;\n}\n\nfunction effectCleanup(this: ReactiveNode): void {\n this._depsTail = undefined;\n this._flags = ReactiveFlags.None;\n purgeDeps(this);\n const sub = this._subs;\n if (sub !== undefined) {\n unlink(sub);\n }\n (this as EffectNode)._cleanup?.();\n (this as EffectNode)._cleanup = undefined;\n}\n\n/*==================================*\\\n|| Public API ||\n\\*==================================*/\n\n/**\n * Returns the currently held value. Registers the state as a dependency when called within a tracking context.\n */\nexport type Getter<T> = () => T;\n\n/**\n * A value that may be a static value or a getter function.\n * Can be converted to a plain value with `unwrap`.\n */\nexport type MaybeGetter<T> = T | Getter<T>;\n\n/**\n * Updates the value of an atom. Takes a new plain value, or an update function to compute one.\n */\nexport type Setter<T> = (next: SetterAction<T>) => T;\nexport type SetterAction<T> = T | ((prev: T) => T);\n\n/**\n * A getter and setter pair, as returned from `createAtom`.\n */\nexport type AtomAccessors<T> = [Getter<T>, Setter<T>];\n\n/**\n * Creates a new atom with a default `undefined` value.\n * Returns a `[getter, setter]` function tuple.\n *\n * @example\n * const [getValue, setValue] = createAtom();\n */\nexport function createAtom<T>(): AtomAccessors<T | undefined>;\n\n/**\n * Creates a new atom with a value computed from an existing getter.\n * This is usually used to create a 'settable' getter, in which you can store\n * a temporary value until it gets overwritten by a _real_ update.\n *\n * @example\n * const [getValue, setValue] = createAtom(\"\");\n * const [getInputValue, setInputValue] = createAtom(getValue);\n *\n * setInputValue(\"temporary\");\n * getValue(\"\");\n * getInputValue(); // \"temporary\"\n *\n * setValue(\"overwritten\");\n * getValue(\"overwritten\");\n * getInputValue(); // \"overwritten\"\n */\nexport function createAtom<T>(initialValue: Getter<T>): AtomAccessors<T>;\n\n/**\n * Creates a new atom with a value computed from an existing getter.\n * This is usually used to create a 'settable' getter, in which you can store\n * a temporary value until it gets overwritten by a _real_ update.\n *\n * @example\n * const [getValue, setValue] = createAtom(\"\");\n * const [getInputValue, setInputValue] = createAtom(getValue);\n *\n * setInputValue(\"temporary\");\n * getValue(\"\");\n * getInputValue(); // \"temporary\"\n *\n * setValue(\"overwritten\");\n * getValue(\"overwritten\");\n * getInputValue(); // \"overwritten\"\n */\nexport function createAtom<T>(initialValue: MaybeGetter<T>): AtomAccessors<T>;\n\n/**\n * Creates a new atom with an initial value.\n * Returns a `[getter, setter]` function tuple.\n *\n * @example\n * const [getCount, setCount] = createAtom(5);\n */\nexport function createAtom<T>(initialValue: T): AtomAccessors<T>;\n\nexport function createAtom<T>(value?: T) {\n if (isFunction<Getter<T>>(value)) {\n const node: ComputedNode<T> = {\n _value: undefined,\n _subs: undefined,\n _subsTail: undefined,\n _deps: undefined,\n _depsTail: undefined,\n _flags: ReactiveFlags.None,\n _getter: value as (previousValue?: T | undefined) => T,\n };\n return [computedGetter.bind(node), computedSetter.bind(node)];\n } else {\n const node: ValueNode<T> = {\n _currentValue: value as T,\n _pendingValue: value as T,\n _subs: undefined,\n _subsTail: undefined,\n _flags: ReactiveFlags.Mutable,\n _skipEqualValues: true,\n };\n return [valueGetter.bind(node), valueSetter.bind(node)];\n }\n}\n\n/**\n * Creates a customsetter with a `getter` as its source.\n */\nexport function createSetter<T>(getter: Getter<T>, callback: (current: T) => T | void): Setter<T> {\n return customSetter.bind(getter, callback as any) as Setter<T>;\n}\n\nexport function compose<T>(getter: T | ((previousValue?: T) => Getter<T> | T)): Getter<T> {\n if (!isFunction(getter)) {\n // Creates a getter out of a plain value; reverse unwrap.\n return () => getter as T;\n }\n return computedGetter.bind({\n _value: undefined,\n _subs: undefined,\n _subsTail: undefined,\n _deps: undefined,\n _depsTail: undefined,\n _flags: ReactiveFlags.None,\n _getter: getter,\n });\n}\n\nfunction _depsGetter(this: MaybeGetter<any>[], fn: (...values: any[]) => void) {\n // Trigger getters for all deps.\n const values = this.map((dep) => unwrap(dep));\n // Ignore tracking in original getter.\n return peek(() => fn(...values));\n}\n\nexport type Unwrapped<T> = {\n [K in keyof T]: T[K] extends () => infer R ? R : T[K];\n};\n\n/**\n * Creates an effect with auto-tracking for getters called within its callback.\n */\nexport function createEffect(fn: () => void): () => void;\n\n/**\n * Creates an effect that tracks getters in its `deps` array.\n * Unwrapped values from `deps` are passed as arguments to the callback.\n */\nexport function createEffect<const T extends readonly any[]>(\n fn: (...values: Unwrapped<T>) => void,\n deps?: T,\n): () => void;\n\nexport function createEffect(fn: (...values: any[]) => void, deps?: any[]): () => void {\n const e: EffectNode = {\n _fn: deps ? _depsGetter.bind(deps, fn) : fn,\n _cleanup: undefined,\n _subs: undefined,\n _subsTail: undefined,\n _deps: undefined,\n _depsTail: undefined,\n _flags: ReactiveFlags.Watching | ReactiveFlags.RecursedCheck,\n };\n const prevSub = setActiveSub(e);\n if (prevSub !== undefined) {\n link(e, prevSub, 0);\n }\n try {\n const result = e._fn();\n if (isFunction(result)) e._cleanup = result;\n } finally {\n activeSub = prevSub;\n e._flags &= ~ReactiveFlags.RecursedCheck;\n }\n return effectCleanup.bind(e);\n}\n\nconst [count, setCount] = createAtom(5);\ncreateEffect(\n (value, second) => {\n console.log(\"count is now\", value);\n },\n [count, \"on\"],\n);\n\n/**\n * Unwraps a `MaybeGetter<T>` into a plain `T`.\n * Tracks the value if it is a getter.\n * Use the non-tracking `peek` if you're being stealthy.\n */\nexport function unwrap<T>(value: T | Getter<T>): T {\n if (isFunction<Getter<T>>(value)) {\n return value();\n } else {\n return value;\n }\n}\n\n/**\n * Unwraps a `MaybeGetter<T>` into a plain `T`. Will _not_ track if the value is a getter.\n */\nexport function peek<T>(value: T | Getter<T>): T {\n const prevSub = setActiveSub(undefined);\n try {\n return unwrap(value);\n } finally {\n setActiveSub(prevSub);\n }\n}\n\n/**\n * Groups several signal changes into a single transaction.\n * Suspends effects until `callback` finishes, then runs all updates at once.\n */\nexport function batch(callback: () => void): void {\n ++batchDepth;\n try {\n callback();\n } finally {\n if (!--batchDepth) {\n flush();\n }\n }\n}\n\nexport function subscribe<T>(target: Getter<T>, fn: (value: T) => any): () => void {\n return createEffect(() => {\n const value = target();\n peek(() => fn(value));\n });\n}\n\nexport interface StreamOptions<T> {\n /**\n * An initial value for non-nullable streams.\n */\n initialValue?: T;\n\n /**\n * Cancel pending `next` listeners when this context is unmounted.\n */\n context?: Context;\n\n /**\n * Number of emitted values to keep. Defaults to 0 (latest value only).\n */\n history?: number;\n}\n\nexport interface StreamOptionsWithValue<T> extends StreamOptions<T> {\n initialValue: T;\n}\n\nexport interface Stream<T> {\n readonly latest: T;\n current: Getter<T>;\n next(): Promise<T>;\n\n map<O>(callback: (value: T, previous?: O) => O): Stream<O>;\n reduce<O>(callback: (reduced: O, value: T) => O, initialValue: O): Stream<O>;\n filter(callback: (value: T, previous?: T) => boolean, defaultValue: T): Stream<T>;\n filter(callback: (value: T, previous?: T) => boolean, defaultValue?: T): Stream<T | undefined>;\n\n throttle(milliseconds: number): Stream<T>;\n debounce(milliseconds: number): Stream<T>;\n delay(milliseconds: number, initialValue?: T): Stream<T>;\n}\n\ninterface CreateStreamLinkOptions<T> {\n value: Getter<T>;\n signal: AbortSignal;\n}\n\nfunction _createStreamLink<T>({ value, signal }: CreateStreamLinkOptions<T>): Stream<T> {\n return {\n get latest() {\n return peek(value);\n },\n current: value,\n next() {\n return new Promise((resolve, reject) => {\n let skippedFirst = false;\n const stopEffect = createEffect(() => {\n const latest = value();\n if (!skippedFirst) {\n skippedFirst = true;\n } else {\n resolve(latest);\n stopEffect();\n }\n });\n signal.addEventListener(\"abort\", () => {\n reject(new Error(\"Aborted by the parent context unmounting.\"));\n stopEffect();\n });\n });\n },\n\n map(callback) {\n return _createStreamLink({ value: compose((previous) => callback(value(), previous)), signal });\n },\n reduce(callback, initialValue) {\n return _createStreamLink({ value: compose((previous) => callback(previous ?? initialValue, value())), signal });\n },\n filter(callback, defaultValue) {\n return _createStreamLink<T>({\n value: compose((previous) => {\n const latest = value();\n if (callback(latest, previous)) return latest;\n else return previous ?? defaultValue!;\n }),\n signal,\n });\n },\n\n throttle(milliseconds) {\n // Accepts only one new value per X milliseconds\n const [current, setCurrent] = createAtom<T>(peek(value));\n let nextAllowedAt = Date.now() + milliseconds;\n\n return _createStreamLink({\n value: compose(() => {\n const local = current();\n const latest = value();\n const now = Date.now();\n\n if (now >= nextAllowedAt) {\n nextAllowedAt = now;\n return setCurrent(latest);\n }\n\n return local;\n }),\n signal,\n });\n },\n debounce(milliseconds) {\n // Emits the latest value after no values have been emitted for X milliseconds\n const [current, setCurrent] = createAtom<T>(peek(value));\n let isSyncing = false;\n let latestTimeout: any;\n\n signal.addEventListener(\"abort\", () => {\n clearTimeout(latestTimeout);\n });\n\n return _createStreamLink({\n value: compose(() => {\n const local = current();\n const latest = value();\n\n if (!isSyncing) {\n clearTimeout(latestTimeout);\n latestTimeout = setTimeout(() => {\n isSyncing = true;\n setCurrent(latest);\n isSyncing = false;\n latestTimeout = undefined;\n }, milliseconds);\n }\n\n return local;\n }),\n signal,\n });\n },\n delay(milliseconds: number, defaultValue?: T) {\n // Returns a stream that emits the same values X milliseconds later\n const [current, setCurrent] = createAtom<T>(defaultValue ?? peek(value));\n let isSyncing = false;\n let latestTimeout: any;\n\n signal.addEventListener(\"abort\", () => {\n clearTimeout(latestTimeout);\n });\n\n return _createStreamLink({\n value: compose(() => {\n const local = current();\n const latest = value();\n\n if (!isSyncing) {\n latestTimeout = setTimeout(() => {\n isSyncing = true;\n setCurrent(latest);\n isSyncing = false;\n latestTimeout = undefined;\n }, milliseconds);\n }\n\n return local;\n }),\n signal,\n });\n },\n };\n}\n\nexport function createStream<T>(options: StreamOptionsWithValue<T>): [Stream<T>, Setter<T>];\nexport function createStream<T>(options: StreamOptions<T>): [Stream<T | undefined>, Setter<T | undefined>];\n\nexport function createStream<T>(options?: StreamOptions<T>) {\n const node: ValueNode<T> = {\n _currentValue: options?.initialValue as T,\n _pendingValue: options?.initialValue as T,\n _subs: undefined,\n _subsTail: undefined,\n _flags: ReactiveFlags.Mutable,\n _skipEqualValues: false,\n };\n\n const value = valueGetter.bind(node);\n const setValue = valueSetter.bind(node);\n\n const abortController = new AbortController();\n const stream = _createStreamLink({ value, signal: abortController.signal });\n\n if (options?.context) {\n onCleanup(options.context, () => {\n abortController.abort();\n });\n }\n\n return [stream, setValue];\n}\n","import type { IntrinsicElements, View } from \"../../types.js\";\nimport { Context } from \"../index.js\";\n\n/**\n * Determines the type of the `props` object for any kind of Markup type.\n */\nexport type PropsOf<T extends string | View<any> | (new (...args: any[]) => MarkupNode)> =\n T extends View<infer P>\n ? P\n : T extends new (...args: infer Args) => MarkupNode\n ? { args: Args extends [Context, ...infer Rest] ? Rest : [] }\n : T extends keyof IntrinsicElements\n ? IntrinsicElements[T]\n : any;\n\nexport const IS_MARKUP = Symbol.for(\"$_IS_MARKUP\");\nexport const IS_MARKUP_NODE = Symbol.for(\"$_IS_MARKUP_NODE\");\nexport const IS_MARKUP_NODE_CLASS = Symbol.for(\"$_IS_MARKUP_NODE_CLASS\");\n\n/**\n * A set of basic metadata that can be constructed into a `MarkupNode`.\n */\nexport interface Markup<\n Type extends string | View<any> | (new (...args: any[]) => MarkupNode) =\n | string\n | View<any>\n | (new (...args: any[]) => MarkupNode),\n> {\n [IS_MARKUP]: true;\n type: Type;\n props: PropsOf<Type>;\n}\n\nexport interface MountTarget {\n insertBefore(node: Node, child: Node | null): any;\n moveBefore?: (node: Node, child: Node | null) => any;\n appendChild(node: Node): any;\n}\n\n/**\n * A node that can be mounted by the Markup layout engine. Can be extended to create new custom node types.\n *\n * A `MarkupNode` instance can be passed anywhere a `Renderable` is required.\n */\nexport abstract class MarkupNode {\n static [IS_MARKUP_NODE_CLASS] = true;\n\n get [IS_MARKUP_NODE]() {\n return true;\n }\n\n /**\n * Returns a single DOM node to represent this MarkupNode's position in the DOM.\n * Usually the parent element, but it can be an empty Text node used as a marker.\n *\n * It only needs to be defined while the node is mounted, so it can be created in the `mount` function.\n */\n abstract getRoot(): Node | undefined;\n\n /**\n * Returns true while this node is mounted.\n */\n abstract isMounted(): boolean;\n\n /**\n * Mount this node to a `parent` element.\n * If passed, this node will be mounted as the next sibling of `after`.\n */\n abstract mount(parent: MountTarget, after?: Node): void;\n\n /**\n * Unmount this MarkupNode from its parent element.\n *\n * The `skipDOM` option can be passed as an optimization when unmounting a parent node.\n * A value of `true` indicates that no DOM operations need to happen because the parent is already being unmounted.\n *\n * @param skipDOM - No DOM updates will be performed when true. Lifecycle methods will be called regardless.\n */\n abstract unmount(skipDOM?: boolean): void;\n\n /**\n * Moves a node without unmounting and remounting (if the browser supports Element.moveBefore).\n */\n abstract move(parent: MountTarget, after?: Node): void;\n}\n","import { Context } from \"../../context.js\";\nimport { MarkupNode, type MountTarget } from \"../types.js\";\nimport { addChild, moveAfter } from \"../utils.js\";\n\n/**\n * A lightweight MarkupNode wrapper for a plain DOM node.\n */\nexport class DOMNode extends MarkupNode {\n #root: Node;\n\n constructor(_context: Context, node: Node) {\n super();\n this.#root = node;\n }\n\n override getRoot() {\n return this.#root;\n }\n\n override isMounted() {\n return this.#root.parentNode != null;\n }\n\n override mount(parent: MountTarget, after?: Node) {\n addChild(parent, this.#root, after);\n }\n\n override unmount(skipDOM = false) {\n if (skipDOM) return;\n this.#root.parentNode?.removeChild(this.#root);\n }\n\n override move(parent: Element, after?: Node) {\n moveAfter(parent, this.#root, after);\n }\n}\n","const pendingUpdates = new Set<() => void>();\nlet isScheduled = false;\n\nfunction flushUpdates() {\n for (const update of pendingUpdates) update();\n pendingUpdates.clear();\n isScheduled = false;\n}\n\nexport function scheduleUpdate(updateFn: () => void) {\n updateFn();\n\n // pendingUpdates.add(updateFn);\n // if (!isScheduled) {\n // isScheduled = true;\n // queueMicrotask(flushUpdates);\n // }\n}\n","import type { Context } from \"../../context.js\";\nimport { subscribe, type Getter } from \"../../signals.js\";\nimport { scheduleUpdate } from \"../scheduler.js\";\nimport { MarkupNode, MountTarget } from \"../types.js\";\nimport { addChild, createTextNode, toMarkupNodes } from \"../utils.js\";\nimport { DOMNode } from \"./dom.js\";\n\n/**\n * Renders any kind of content; markup, signals, DOM nodes, etc.\n * If it can be rendered by Dolla then Dynamic will do it.\n */\n\nexport class DynamicNode extends MarkupNode {\n #root = createTextNode(\"\");\n #children: MarkupNode[] = [];\n #context: Context;\n #slot: Getter<any>;\n #unsubscribe?: () => void;\n\n constructor(context: Context, slot: Getter<any>) {\n super();\n this.#context = context;\n this.#slot = slot;\n }\n\n override getRoot() {\n return this.#root;\n }\n\n override isMounted() {\n return this.#root.parentNode != null;\n }\n\n override mount(parent: MountTarget, after?: Node) {\n if (!this.isMounted()) {\n addChild(parent, this.#root, after);\n this.#unsubscribe = subscribe(this.#slot, (content) => {\n scheduleUpdate(() => {\n this.#update(content);\n });\n });\n }\n }\n\n override unmount(skipDOM = false) {\n this.#unsubscribe?.();\n\n if (this.isMounted()) {\n if (!skipDOM) {\n this.#root.parentNode?.removeChild(this.#root);\n }\n this.#cleanup(skipDOM);\n }\n }\n\n override move(parent: MountTarget, after?: Node) {\n let referenceNode: Node | null = after?.nextSibling ?? null;\n\n if (parent.moveBefore) {\n try {\n parent.moveBefore(this.#root, referenceNode);\n referenceNode = this.#root.nextSibling;\n\n for (let i = 0; i < this.#children.length; i++) {\n const childRoot = this.#children[i].getRoot();\n if (childRoot) {\n (parent as any).moveBefore(childRoot, referenceNode);\n }\n }\n return;\n } catch {\n // Fallthrough to standard insertBefore\n }\n }\n\n // Standard DOM fallback (moves root AND children)\n parent.insertBefore(this.#root, referenceNode);\n referenceNode = this.#root.nextSibling;\n\n for (let i = 0; i < this.#children.length; i++) {\n this.#children[i].move(parent, this.#children[i - 1]?.getRoot() ?? this.#root);\n }\n }\n\n #cleanup(skipDOM: boolean) {\n for (let i = 0; i < this.#children.length; i++) {\n this.#children[i].unmount(skipDOM);\n }\n this.#children.length = 0;\n }\n\n #update(content: any) {\n if (!this.isMounted()) return;\n\n // Fast-path for primitive text updates\n const isPrimitive = typeof content === \"string\" || typeof content === \"number\";\n if (isPrimitive && this.#children.length === 1) {\n const child = this.#children[0];\n if (child instanceof DOMNode) {\n const domNode = child.getRoot();\n if (domNode && domNode.nodeType === Node.TEXT_NODE) {\n domNode.nodeValue = String(content);\n return;\n }\n }\n }\n\n this.#cleanup(false);\n\n if (content == null || content === false) return;\n\n const nodes = toMarkupNodes(this.#context, content);\n\n const parent = this.#root.parentElement!;\n let referenceNode: Node = this.#root;\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n node.mount(parent, referenceNode);\n this.#children.push(node);\n\n const nextRoot = node.getRoot();\n if (nextRoot) referenceNode = nextRoot;\n }\n }\n}\n","export const PARENT_ELEMENT = Symbol.for(\"$_PARENT_ELEMENT\");\nexport const DEBUG = Symbol.for(\"$_DEBUG\");\n","import { isArray, isFunction, isNumber, isObject, isString, omit } from \"../../../utils.js\";\nimport { Context, createContext, getNearestViewNode, mountContext, unmountContext } from \"../../context.js\";\nimport { Ref } from \"../../ref.js\";\nimport { type Getter, subscribe } from \"../../signals.js\";\nimport { DEBUG } from \"../../symbols.js\";\nimport { scheduleUpdate } from \"../scheduler.js\";\nimport { MarkupNode, MountTarget } from \"../types.js\";\nimport { addChild, addListener, toMarkupNodes } from \"../utils.js\";\n\nconst IS_SVG = Symbol.for(\"$_IS_SVG\");\n\n// Properties in this list will not be processed by applyProps because they are already handled elsewhere.\nconst ignoredProps = [\"ref\", \"children\"];\n\n/**\n * Renders an HTML or SVG element.\n */\nexport class ElementNode extends MarkupNode {\n #root: HTMLElement | SVGElement;\n\n readonly #props: Record<string, any>;\n\n #context: Context;\n #ownContext = false;\n #childNodes: MarkupNode[] = [];\n #unsubscribers = new Set<() => void>();\n\n #refCleanup?: () => void;\n\n constructor(context: Context, tag: string, props: Record<string, any>) {\n super();\n\n this.#props = props;\n this.#context = context;\n\n if (tag === \"svg\") {\n // This and all nested views will be created as SVG elements.\n this.#context = createContext(context);\n this.#context[IS_SVG] = true;\n this.#ownContext = true;\n } else if (this.#context[IS_SVG] && tag === \"foreignObject\") {\n // No longer in SVG.\n this.#context = createContext(context);\n this.#context[IS_SVG] = false;\n this.#ownContext = false;\n }\n\n // Create node with the appropriate constructor.\n if (this.#context[IS_SVG]) {\n this.#root = document.createElementNS(\"http://www.w3.org/2000/svg\", tag);\n } else {\n this.#root = document.createElement(tag);\n }\n\n // Add view name as a data attribute debug mode.\n if (this.#context[DEBUG]) {\n const view = getNearestViewNode(this.#context);\n if (view) {\n this.#root.dataset.view = view.context.name;\n }\n }\n }\n\n override getRoot() {\n return this.#root;\n }\n\n override isMounted() {\n return this.#root.parentNode != null;\n }\n\n override mount(parent: MountTarget, after?: Node) {\n const wasMounted = this.isMounted();\n\n if (!wasMounted) {\n this.#applyProps(this.#root, omit(ignoredProps, this.#props));\n\n if (this.#props.children) {\n this.#childNodes = toMarkupNodes(this.#context, this.#props.children);\n for (const child of this.#childNodes) {\n child.mount(this.#root);\n }\n }\n }\n\n const targetSibling = after?.nextSibling ?? null;\n if (this.#root.parentNode !== parent || this.#root.nextSibling !== targetSibling) {\n addChild(parent, this.#root, targetSibling);\n }\n\n if (!wasMounted) {\n if (isFunction<Ref<any>>(this.#props.ref)) {\n const result = this.#props.ref(this.#root);\n if (isFunction(result)) {\n this.#refCleanup = result;\n }\n }\n\n if (this.#ownContext) mountContext(this.#context);\n }\n }\n\n override unmount(skipDOM = false) {\n if (!skipDOM && this.#root.parentNode) {\n this.#root.parentNode.removeChild(this.#root);\n }\n\n for (const child of this.#childNodes) {\n child.unmount(true); // Skip DOM removal for children\n }\n\n // Clear reactivity\n this.#unsubscribers.forEach((unsubscribe) => unsubscribe());\n this.#unsubscribers.clear();\n\n if (this.#ownContext) unmountContext(this.#context);\n\n // Clear ref\n if (this.#refCleanup) {\n this.#refCleanup();\n this.#refCleanup = undefined;\n }\n\n // Release memory\n this.#childNodes.length = 0;\n }\n\n override move(parent: MountTarget, after?: Node) {\n if (parent.moveBefore) {\n try {\n parent.moveBefore(this.#root, after?.nextSibling ?? null);\n return;\n } catch {}\n }\n this.mount(parent, after);\n }\n\n #attach<T>(value: Getter<T> | T, callback: (value: T) => void) {\n if (isFunction<Getter<T>>(value)) {\n this.#unsubscribers.add(\n subscribe(value, (current) => {\n scheduleUpdate(() => callback(current));\n }),\n );\n } else {\n // No need to schedule since DOM node is not connected yet.\n callback(value);\n }\n }\n\n #applyProps(element: any, props: Record<string, unknown>) {\n for (const key in props) {\n const value = props[key];\n\n if (key === \"style\") {\n this.#applyStyles(element, value);\n } else if (key === \"class\" || key === \"className\") {\n this.#applyClasses(element, value);\n } else if (key === \"for\") {\n this.#attach(value, (current) => {\n element.htmlFor = current;\n });\n } else if (key[0] === \".\" || key.startsWith(\"prop:\")) {\n // Keys starting with `.` or `prop:` are set as props.\n\n const _key = key.substring(5);\n this.#attach(value, (current) => {\n element[_key] = current;\n });\n } else if (key[0] === \":\" || key.startsWith(\"attr:\")) {\n // Keys starting with `:` or `attr:` are set as attributes.\n\n const _key = key.substring(5).toLowerCase();\n this.#attach(value, (current) => {\n setAttribute(element, _key, current);\n });\n } else if (key[0] === \"@\" && isFunction(value)) {\n // Anything that's a function starting with `@` is an event listener.\n\n const eventName = key.substring(1);\n this.#unsubscribers.add(addListener(element, eventName, value));\n } else if (key.startsWith(\"on\") && isFunction(value)) {\n // Anything that's a function starting with `on` is an event listener.\n\n const eventName = key.toLowerCase().slice(2);\n this.#unsubscribers.add(addListener(element, eventName, value));\n } else if (key in element && !this.#context[IS_SVG]) {\n // Set as property if the element has one.\n\n if (typeof element[key] === \"boolean\") {\n this.#attach(value, (current) => {\n const isTrue = Boolean(current);\n element[key] = isTrue;\n setAttribute(element, key, isTrue);\n });\n } else {\n this.#attach(value, (current) => {\n element[key] = current;\n });\n }\n } else {\n // Fall back to attributes.\n\n this.#attach(value, (current) => {\n setAttribute(element, key, current);\n });\n }\n }\n }\n\n #applyStyles(element: HTMLElement | SVGElement, styles: unknown) {\n const localUnsubs = new Set<() => void>();\n\n const apply = (current: unknown) => {\n localUnsubs.forEach((unsub) => {\n unsub();\n this.#unsubscribers.delete(unsub);\n });\n localUnsubs.clear();\n element.style.cssText = \"\";\n\n const mapped = getStyleMap(current);\n for (const [name, { value, priority }] of Object.entries(mapped)) {\n if (isFunction(value)) {\n const unsub = subscribe(value, (v) => {\n if (v) element.style.setProperty(name, asPixelsIfNumber(v), priority);\n else element.style.removeProperty(name);\n });\n this.#unsubscribers.add(unsub);\n localUnsubs.add(unsub);\n } else if (value != null) {\n element.style.setProperty(name, asPixelsIfNumber(value), priority);\n }\n }\n };\n\n if (isFunction(styles)) {\n this.#unsubscribers.add(subscribe(styles, apply));\n } else {\n apply(styles);\n }\n }\n\n #applyClasses(element: HTMLElement | SVGElement, classes: unknown) {\n const localUnsubs = new Set<() => void>();\n\n const apply = (current: unknown) => {\n // Clean up nested subscriptions if the top-level signal emits a new object\n localUnsubs.forEach((unsub) => {\n unsub();\n this.#unsubscribers.delete(unsub);\n });\n localUnsubs.clear();\n setAttribute(element, \"class\", null);\n\n const mapped = getClassMap(current);\n for (const [name, value] of Object.entries(mapped)) {\n if (name === \"undefined\") continue;\n\n if (isFunction(value)) {\n const unsub = subscribe(value, (isActive) => element.classList.toggle(name, !!isActive));\n this.#unsubscribers.add(unsub);\n localUnsubs.add(unsub);\n } else if (value) {\n element.classList.add(name);\n }\n }\n };\n\n if (isFunction(classes)) {\n this.#unsubscribers.add(subscribe(classes, apply));\n } else {\n apply(classes);\n }\n }\n}\n\n/**\n * Parse classes into a single object. Classes can be passed as a string, an object with class keys can boolean values, or an array with a mix of both.\n */\nfunction getClassMap(classes: unknown): Record<string, unknown> {\n if (isString(classes)) return Object.fromEntries(classes.split(\" \").map((c) => [c, true]));\n if (isArray(classes)) return Object.assign({}, ...classes.filter(Boolean).map(getClassMap));\n if (isObject(classes)) return classes as Record<string, unknown>;\n return {};\n}\n\n/**\n * Parse styles into a single object.\n */\nfunction getStyleMap(styles: unknown): Record<string, { value: unknown; priority?: string }> {\n if (isString(styles)) {\n return Object.fromEntries(\n styles\n .split(\";\")\n .filter((s) => s.trim())\n .map((line) => {\n const [key, val] = line.split(\":\");\n return [\n camelToKebab(key.trim()),\n {\n value: val.replace(\"!important\", \"\").trim(),\n priority: val.includes(\"!important\") ? \"important\" : \"\",\n },\n ];\n }),\n );\n }\n if (isArray(styles)) return Object.assign({}, ...styles.filter(Boolean).map(getStyleMap));\n if (isObject(styles)) {\n return Object.fromEntries(\n Object.entries(styles).map(([k, v]) => [k.startsWith(\"--\") ? k : camelToKebab(k), { value: v }]),\n );\n }\n return {};\n}\n\n/**\n * Converts a camelCase string to kebab-case.\n */\nfunction camelToKebab(value: string): string {\n return value.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? \"-\" : \"\") + $.toLowerCase());\n}\n\nfunction asPixelsIfNumber(value: any): string {\n if (isNumber(value)) {\n return `${value}px`;\n } else {\n return value;\n }\n}\n\nfunction setAttribute(element: Element, name: string, value: any) {\n if (value) {\n element.setAttribute(name, String(value));\n } else {\n element.removeAttribute(name);\n }\n}\n","import type { Renderable, View } from \"../../types.js\";\nimport { isArray, isFunction, isNumber, isString } from \"../../utils.js\";\nimport { Context, createContext } from \"../context.js\";\nimport { DOMNode } from \"./nodes/dom.js\";\nimport { DynamicNode } from \"./nodes/dynamic.js\";\nimport { ElementNode } from \"./nodes/element.js\";\nimport { ViewNode } from \"./nodes/view.js\";\nimport { IS_MARKUP, IS_MARKUP_NODE, IS_MARKUP_NODE_CLASS, Markup, MarkupNode, MountTarget, PropsOf } from \"./types.js\";\n\nexport function createMarkup<Type extends string | View<any> | (new (...args: any[]) => MarkupNode)>(\n type: Type,\n props: PropsOf<Type>,\n): Markup<Type> {\n return {\n [IS_MARKUP]: true,\n type,\n props,\n };\n}\n\nexport function isMarkup<T extends string | View<any> | (new (...args: any[]) => MarkupNode)>(\n value: any,\n): value is Markup<T> {\n return value && value[IS_MARKUP];\n}\n\nexport function isMarkupNode(value: any): value is MarkupNode {\n return value && value[IS_MARKUP_NODE];\n}\n\nexport function isMarkupNodeClass(value: any): value is new (...args: any[]) => MarkupNode {\n return value && value[IS_MARKUP_NODE_CLASS];\n}\n\n/**\n * Takes any `Renderable` value and returns a `MarkupNode` that will display it.\n */\nexport function render(content: Renderable, context = createContext()): MarkupNode {\n const nodes = toMarkupNodes(context, content);\n if (nodes.length === 1) {\n return nodes[0]; // if it's just one item return it\n }\n // otherwise wrap it in something that can display multiple nodes\n return new DynamicNode(context, () => nodes);\n}\n\n/**\n * Convert basically anything into an array of `MarkupNode`\n */\nexport function toMarkupNodes(context: Context, ...content: any[]): MarkupNode[] {\n const nodes: MarkupNode[] = [];\n\n // Internal processor to avoid intermediate array allocations\n function process(item: any) {\n if (item == null || item === false) return;\n\n if (isArray(item)) {\n for (let i = 0; i < item.length; i++) {\n process(item[i]);\n }\n } else if (isString(item) || isNumber(item)) {\n nodes.push(new DOMNode(context, createTextNode(String(item))));\n } else if (isMarkup(item)) {\n const { type, props } = item;\n\n if (isMarkupNodeClass(type)) {\n nodes.push(new type(context, ...props.args));\n } else if (isFunction(type)) {\n nodes.push(new ViewNode(context, type as View<any>, props));\n } else if (isString(type)) {\n nodes.push(new ElementNode(context, type, props));\n }\n } else if (isMarkupNode(item)) {\n nodes.push(item);\n } else if (item instanceof Node) {\n nodes.push(new DOMNode(context, item));\n } else if (isFunction(item)) {\n nodes.push(new DynamicNode(context, item));\n }\n }\n\n for (let i = 0; i < content.length; i++) {\n process(content[i]);\n }\n\n return nodes;\n}\n\nexport function addChild(parent: MountTarget, node: Node, after?: Node | null) {\n if (after) {\n parent.insertBefore(node, after?.nextSibling);\n } else {\n parent.appendChild(node);\n }\n}\n\nexport function createTextNode(text: string) {\n return document.createTextNode(text);\n}\n\n/**\n * Moves an element using `moveBefore` if the browser supports it, otherwise falls back to `insertBefore`.\n */\nexport function moveAfter(parent: MountTarget, node: Node, after?: Node | null) {\n const before = after?.nextSibling ?? null;\n if (parent.moveBefore) {\n try {\n parent.moveBefore(node, before);\n return;\n } catch {}\n }\n parent.insertBefore(node, before);\n}\n\nexport function addListener<T extends Event>(target: EventTarget, event: string, listener: (event: T) => any) {\n target.addEventListener(event, listener as any);\n return () => target.removeEventListener(event, listener as any);\n}\n","import type { Renderable, View } from \"../../../types.js\";\nimport { assert } from \"../../../utils.js\";\nimport { ComponentState, Context, createContext, mountContext, unmountContext } from \"../../context.js\";\nimport { peek } from \"../../signals.js\";\nimport { MarkupNode } from \"../types.js\";\nimport { createTextNode, render } from \"../utils.js\";\nimport { DOMNode } from \"./dom.js\";\n\nexport const VIEW = Symbol.for(\"$_VIEW_NODE\");\n\n/**\n * Renders a View.\n */\nexport class ViewNode<P> extends MarkupNode {\n readonly #props: P;\n readonly #view: View<P>;\n #node?: MarkupNode;\n\n readonly context: Context<ComponentState & Record<string | symbol, any>>;\n\n constructor(context: Context, view: View<P>, props: P) {\n super();\n this.context = createContext(context) as Context<ComponentState>;\n this.context[VIEW] = this;\n this.context.name = view.name;\n this.#props = props;\n this.#view = view;\n }\n\n getRoot() {\n return this.#node?.getRoot();\n }\n\n isMounted() {\n return this.context.isMounted;\n }\n\n mount(parent: Element, after?: Node) {\n const wasMounted = this.isMounted();\n\n if (!wasMounted) {\n const viewContent = peek(() => this.#view.call(this.context, this.#props, this.context));\n\n if (viewContent != null && viewContent !== false) {\n this.#node = render(viewContent, this.context);\n } else {\n this.#node = new DOMNode(this.context, createTextNode(\"\"));\n }\n }\n\n this.#node!.mount(parent, after);\n\n if (!wasMounted) mountContext(this.context);\n }\n\n unmount(skipDOM = false) {\n this.#node?.unmount(skipDOM);\n unmountContext(this.context);\n }\n\n move(parent: Element, after?: Node) {\n this.#node?.move(parent, after);\n }\n}\n\ntype GenericProps = {\n [prop: string]: any;\n};\n\nexport function createView<Props = GenericProps>(\n name: string,\n callback: (context: Context, props: Props) => Renderable,\n): View<Props>;\n\nexport function createView<Props = GenericProps>(callback: (context: Context, props: Props) => Renderable): View<Props>;\n\nexport function createView<Props = GenericProps>(...args: any[]): View<Props> {\n let name: string | undefined;\n let callback: (context: Context, props: Props) => Renderable;\n\n if (args.length === 2) {\n assert(typeof args[0] === \"string\", \"When 2 args, the first must be a string\");\n assert(typeof args[1] === \"function\", \"When 2 args, the second must be a function\");\n\n name = args[0];\n callback = args[1];\n } else if (args.length === 1) {\n assert(typeof args[0] === \"function\", \"When 1 arg, the value must be a function\");\n\n callback = args[0];\n }\n\n return function (props) {\n if (name) {\n this.name = name;\n }\n return callback(this, props);\n };\n}\n","import { Store } from \"../types.js\";\nimport { assert } from \"../utils.js\";\nimport { VIEW, ViewNode } from \"./markup/nodes/view.js\";\nimport { createEffect, Unwrapped } from \"./signals.js\";\nimport { PARENT_ELEMENT } from \"./symbols.js\";\n\nexport type LifecycleListener = () => any;\n\ntype ContextState = {\n isMounted: boolean;\n};\n\nexport type ComponentState = ContextState & {\n name: string;\n};\n\nexport type Context<T = Record<string | symbol, any>> = ContextState & T;\n\n/*===================================*\\\n|| Context ||\n\\*===================================*/\n\nconst MOUNT_LISTENERS = Symbol.for(\"$_CONTEXT_MOUNT_LISTENERS\");\nconst CLEANUP_LISTENERS = Symbol.for(\"$_CONTEXT_CLEANUP_LISTENERS\");\n\nexport function createContext(parent?: Context): Context {\n return Object.assign(Object.create(parent ?? null), { isMounted: false });\n}\n\nexport function mountContext(context: Context) {\n if (context.isMounted) return;\n context.isMounted = true;\n _callListeners(context, MOUNT_LISTENERS);\n}\n\nexport function unmountContext(context: Context) {\n if (!context.isMounted) return;\n context.isMounted = false;\n _callListeners(context, CLEANUP_LISTENERS);\n}\n\nfunction _callListeners(context: Context, key: symbol) {\n if (!Object.hasOwn(context, key)) return;\n for (const callback of context[key]) callback();\n context[key].length = 0;\n}\n\n/*===================================*\\\n|| Lifecycle Hooks ||\n\\*===================================*/\n\nexport function onMount(context: Context, fn: LifecycleListener) {\n if (!Object.hasOwn(context, MOUNT_LISTENERS)) context[MOUNT_LISTENERS] = [fn];\n else context[MOUNT_LISTENERS].push(fn);\n}\n\nexport function onCleanup(context: Context, fn: LifecycleListener) {\n if (!Object.hasOwn(context, CLEANUP_LISTENERS)) context[CLEANUP_LISTENERS] = [fn];\n else context[CLEANUP_LISTENERS].push(fn);\n}\n\n/**\n * Creates an effect with auto-tracking for getters called within its callback.\n */\nexport function onEffect(context: Context, fn: () => void): void;\n\n/**\n * Creates an effect that tracks getters in its `deps` array.\n * Unwrapped values from `deps` are passed as arguments to the callback.\n */\nexport function onEffect<const T extends readonly any[]>(\n context: Context,\n fn: (...values: Unwrapped<T>) => void,\n deps: T,\n): void;\n\nexport function onEffect(context: Context, fn: () => void, deps?: any[]) {\n if (context.isMounted) {\n onCleanup(context, createEffect(fn, deps));\n } else {\n onMount(context, () => {\n onCleanup(context, createEffect(fn, deps));\n });\n }\n}\n\n/*===================================*\\\n|| Traversal Hooks ||\n\\*===================================*/\n\n/**\n * Returns the parent element of the root we're mounted in.\n */\nexport function getRootElement(context: Context): Element {\n return context[PARENT_ELEMENT];\n}\n\n/**\n * Returns the ViewNode of the nearest view up the context chain.\n */\nexport function getNearestViewNode<Props = unknown>(context: Context): ViewNode<Props> | undefined {\n return context[VIEW];\n}\n\n/*===================================*\\\n|| Stores ||\n\\*===================================*/\n\nexport const STORE_ID = Symbol.for(\"$_STORE_ID\");\n\nexport function addStore<Props, Returns>(\n context: Context,\n store: Store<Props, Returns> & { [STORE_ID]?: symbol },\n ...args: undefined extends Props ? [props?: Props] : [props: Props]\n) {\n // Tag the store function with a unique symbol if it doesn't have one.\n store[STORE_ID] ??= Symbol(store.name);\n\n assert(!Object.hasOwn(context, store[STORE_ID]), \"Store was already provided on this context.\");\n\n // Give the store its own context bound to this lifecycle.\n const storeContext = createContext(context) as Context<ComponentState>;\n onMount(context, () => mountContext(storeContext));\n onCleanup(context, () => unmountContext(storeContext));\n storeContext.name = store.name;\n\n return (context[store[STORE_ID]!] = store.call(storeContext, args[0] as Props, storeContext));\n}\n\nexport function getStore<Returns>(context: Context, store: Store<any, Returns> & { [STORE_ID]?: symbol }): Returns {\n const id = store[STORE_ID];\n const result = id ? context[id] : undefined;\n assert(result != null, `Store '${store.name}' is not provided by this context.`);\n return result;\n}\n\ntype AddStoreHook<Props, Returns> = Props extends undefined\n ? (context: Context) => Returns\n : (context: Context, props: Props) => Returns;\ntype GetStoreHook<Returns> = (context: Context) => Returns;\n\ntype StoreHooks<Props, Returns> = [AddStoreHook<Props, Returns>, GetStoreHook<Returns>];\n\ntype StoreConfig<Props, Returns> = {\n id: symbol;\n fn: (context: Context, props: Props) => Returns;\n name?: string;\n};\n\nfunction _initStore(this: StoreConfig<any, any>, context: Context, props: any) {\n assert(!Object.hasOwn(context, this.id), \"Store was already provided on this context.\");\n\n // Give the store its own context bound to this lifecycle.\n const storeContext = createContext(context) as Context<ComponentState>;\n onMount(context, () => mountContext(storeContext));\n onCleanup(context, () => unmountContext(storeContext));\n if (this.name) {\n storeContext.name = this.name;\n }\n\n return (context[this.id] = this.fn(storeContext, props));\n}\n\nfunction _getStore(this: StoreConfig<any, any>, context: Context) {\n const result = context[this.id];\n assert(result != null, `Store is not provided by this context.`);\n return result;\n}\n\nexport function createStore<Returns, Props = undefined>(\n name: string,\n fn: (context: Context, props: Props) => Returns,\n): StoreHooks<Props, Returns>;\n\nexport function createStore<Returns, Props = undefined>(\n fn: (context: Context, props: Props) => Returns,\n): StoreHooks<Props, Returns>;\n\nexport function createStore<Returns, Props = undefined>(...args: any[]): StoreHooks<Props, Returns> {\n if (args.length === 2) {\n assert(typeof args[0] === \"string\", \"When 2 args are present the first must be a string\");\n assert(typeof args[1] === \"function\", \"When 2 args are present the second must be a function\");\n args[1][STORE_ID] ??= Symbol(args[0]); // Tag the store function.\n const config = { id: Symbol(), fn: args[1], name: args[0] };\n return [_initStore.bind(config), _getStore.bind(config)] as StoreHooks<Props, Returns>;\n } else {\n assert(args.length === 1 && typeof args[0] === \"function\", \"Expected one function as an argument\");\n args[0][STORE_ID] ??= Symbol();\n const config = { id: Symbol(), fn: args[0], name: args[0].name };\n return [_initStore.bind(config), _getStore.bind(config)] as StoreHooks<Props, Returns>;\n }\n}\n","import type { Renderable, View } from \"../types.js\";\nimport { assert, isFunction, isString } from \"../utils.js\";\nimport { type Context, createContext, mountContext, unmountContext } from \"./context.js\";\nimport { ViewNode } from \"./markup/nodes/view.js\";\nimport { type MarkupNode } from \"./markup/types.js\";\nimport { render } from \"./markup/utils.js\";\nimport { DEBUG, PARENT_ELEMENT } from \"./symbols.js\";\n\n/**\n * Plugins are simply functions that take a context object.\n * A plugin can return a Promise to suspend app mounting.\n * Hooks can be used to attach app lifecycle logic.\n */\nexport type DollaPlugin = (context: Context) => any;\n\nexport interface DollaRootOptions {\n /**\n * Adds additional view info to the DOM to help with debugging.\n */\n debug?: boolean;\n}\n\nexport interface DollaRoot {\n /**\n * Registers a plugin to be added before `mount`.\n */\n plugin(plugin: DollaPlugin): DollaRoot;\n\n /**\n * Mounts a `view` to this root.\n */\n mount(view: View<{}>): Promise<void>;\n\n /**\n * Mounts any renderable content to this root.\n */\n mount(content: Renderable): Promise<void>;\n\n /**\n * Unmounts the currently mounted content.\n */\n unmount(): void;\n}\n\nexport function createRoot(selector: string, options?: DollaRootOptions): DollaRoot;\nexport function createRoot(element: Element, options?: DollaRootOptions): DollaRoot;\nexport function createRoot(target: string | Element, options?: DollaRootOptions) {\n const element = isString(target) ? document.querySelector(target) : target;\n assert(element, \"Element cannot be null.\");\n\n const context = createContext();\n context.name = \"dolla:root\";\n\n const plugins: DollaPlugin[] = [];\n\n context[PARENT_ELEMENT] = element;\n context[DEBUG] = Boolean(options?.debug);\n\n let rootNode: MarkupNode | null = null;\n\n const self: DollaRoot = { plugin, mount, unmount };\n\n function plugin(plugin: DollaPlugin) {\n plugins.push(plugin);\n return self;\n }\n\n async function mount(content: View<{}> | Renderable) {\n if (context.isMounted) return;\n\n await Promise.all(plugins.map((fn) => fn(context)));\n\n rootNode = isFunction<View<{}>>(content) ? new ViewNode(context, content, {}) : render(content, context);\n rootNode?.mount(element!);\n\n mountContext(context);\n }\n\n async function unmount() {\n if (!context.isMounted) return;\n\n rootNode?.unmount(false);\n rootNode = null;\n\n unmountContext(context);\n }\n\n return self;\n}\n","import { Context } from \"./context\";\n\nexport const noOp = () => {};\n\nexport type LogLevel = \"info\" | \"log\" | \"warn\" | \"error\" | \"silent\";\nconst LEVELS: Record<string, number> = { trace: 1, info: 1, log: 2, warn: 3, error: 4, silent: 5 };\n\nlet logLevel = 1;\nlet logFilter = (name: string) => !name.startsWith(\"dolla:\");\n\n// 3. Extracted configuration setters (replacing static class methods)\nexport const setLogLevel = (level: LogLevel) => {\n logLevel = LEVELS[level] || 1;\n};\nexport const setLogFilter = (filter: (name: string) => boolean) => {\n logFilter = filter;\n};\n\nconst cnsl: any = globalThis.console || {};\n\nexport function getDebug(c: Context, ...tags: [string, any][]) {\n return createDebug(c.name, ...tags);\n}\n\nexport function createDebug(name: string, ...tags: [string, any][]) {\n let args: any[];\n\n const make = (method: string, level: number): ((...args: any[]) => void) => {\n if (level < logLevel || !logFilter(name) || !cnsl[method]) return noOp;\n\n // Build and cache the console arguments on the first valid log\n if (!args) {\n let p = \"%c\" + name;\n let s = [`color:${okhash(name)};font-weight:bold`];\n for (const [k, v] of tags) {\n p += `%c[${k}: %c${v}%c]`;\n s.push(\"color:#777\", \"color:#aaa\", \"color:#777\");\n }\n args = [p, ...s];\n }\n\n return cnsl[method].bind(cnsl, ...args);\n };\n\n return {\n get info() {\n return make(\"info\", 1);\n },\n get trace() {\n return make(\"trace\", 1);\n },\n get log() {\n return make(\"log\", 2);\n },\n get warn() {\n return make(\"warn\", 3);\n },\n get error() {\n return make(\"error\", 4);\n },\n };\n}\n\n/* ----- HELPERS----- */\n\n/**\n * Takes any string and returns an OKLCH color.\n */\nfunction okhash(value: string) {\n let hue = 0;\n for (let i = 0; i < value.length; i++) {\n hue = (hue + value.charCodeAt(i) * 10) % 360;\n }\n return `oklch(0.68 0.15 ${hue}deg)`;\n}\n","import type { Renderable } from \"../../../types.js\";\nimport { Context } from \"../../context.js\";\nimport { MarkupNode, MountTarget } from \"../types.js\";\nimport { addChild, createTextNode, moveAfter, render } from \"../utils.js\";\n\n/**\n * Renders content into a specified parent node.\n */\nexport class PortalNode extends MarkupNode {\n // Acts as a physical placeholder in the logical DOM tree\n #anchor = createTextNode(\"\");\n\n #context: Context;\n #value: Renderable;\n #parent: MountTarget;\n #childNode?: MarkupNode;\n\n constructor(context: Context, value: Renderable, parent: MountTarget) {\n super();\n this.#context = context;\n this.#value = value;\n this.#parent = parent;\n }\n\n override getRoot() {\n // Return the anchor, allowing siblings to mount correctly around it\n return this.#anchor;\n }\n\n override isMounted() {\n return this.#anchor.parentNode != null;\n }\n\n override mount(logicalParent: MountTarget, after?: Node) {\n if (!this.isMounted()) {\n // Mount the anchor in the standard document flow\n addChild(logicalParent, this.#anchor, after);\n\n // Render the content and mount it to the portal target\n if (!this.#childNode) {\n this.#childNode = render(this.#value, this.#context);\n }\n this.#childNode.mount(this.#parent);\n }\n }\n\n override unmount(skipDOM = false) {\n if (this.isMounted()) {\n if (!skipDOM) {\n this.#anchor.parentNode?.removeChild(this.#anchor);\n }\n\n // Portals always force unmount the DOM of their children\n if (this.#childNode?.isMounted()) {\n this.#childNode.unmount(false);\n }\n }\n }\n\n override move(logicalParent: MountTarget, after?: Node) {\n moveAfter(logicalParent, this.#anchor, after);\n }\n}\n","import type { Renderable } from \"../../../types.js\";\nimport type { Context } from \"../../context.js\";\nimport { batch, type Getter, createAtom, subscribe, type Setter } from \"../../signals.js\";\nimport { scheduleUpdate } from \"../scheduler.js\";\nimport { MarkupNode } from \"../types.js\";\nimport { addChild, createTextNode, render } from \"../utils.js\";\n\n// ----- Types ----- //\n\nexport type Key = any;\n\nexport type KeyFn<T> = (item: T, index: number) => Key;\nexport type RenderFn<T> = (item: Getter<T>, index: Getter<number>) => Renderable;\n\ntype ConnectedItem<T> = {\n _key: Key;\n _item: Getter<T>;\n _setItem: Setter<T>;\n _index: Getter<number>;\n _setIndex: Setter<number>;\n _node: MarkupNode;\n};\n\n// ----- Code ----- //\n\n/**\n * Renders a list of items.\n */\nexport class RepeatNode<T> extends MarkupNode {\n #root = createTextNode(\"\");\n\n #context;\n\n #items: Getter<Iterable<T>>;\n #key: KeyFn<T>;\n #render: RenderFn<T>;\n\n #unsubscribe: (() => void) | null = null;\n #connectedItems: Map<Key, ConnectedItem<T>> = new Map();\n\n constructor(context: Context, items: Getter<Iterable<T>>, key: KeyFn<T>, render: RenderFn<T>) {\n super();\n this.#context = context;\n\n this.#items = items;\n this.#key = key;\n this.#render = render;\n }\n\n override getRoot() {\n return this.#root;\n }\n\n override isMounted() {\n return this.#root.parentNode != null;\n }\n\n override mount(parent: Element, after?: Node) {\n if (!this.isMounted()) {\n addChild(parent, this.#root, after);\n\n this.#unsubscribe = subscribe(this.#items, (items) => {\n scheduleUpdate(() => {\n this._update(Array.from(items));\n });\n });\n }\n }\n\n override unmount(skipDOM = false) {\n if (this.#unsubscribe) {\n this.#unsubscribe();\n this.#unsubscribe = null;\n }\n\n if (!skipDOM && this.isMounted()) {\n this.#root.parentNode?.removeChild(this.#root);\n }\n\n this._cleanup(skipDOM);\n }\n\n override move(parent: Element, after?: Node) {\n // TODO: Implement move\n return this.mount(parent, after);\n }\n\n private _cleanup(skipDOM: boolean) {\n for (const item of this.#connectedItems.values()) {\n item._node.unmount(skipDOM);\n }\n this.#connectedItems.clear();\n }\n\n private _update(value: T[]) {\n if (!this.isMounted()) return;\n\n if (value.length === 0) {\n return this._cleanup(false);\n }\n\n const nextItems = new Map<Key, ConnectedItem<T>>();\n\n batch(() => {\n // Track keys for the incoming list\n const nextKeys = new Set(value.map((item, index) => this.#key(item, index)));\n\n // Unmount deleted items immediately.\n // This collapses the DOM tree so surviving items sit adjacent to each other.\n for (const [key, connected] of this.#connectedItems.entries()) {\n if (!nextKeys.has(key)) {\n connected._node.unmount(false);\n }\n }\n\n // Prepare state and allocate new nodes.\n for (let i = 0; i < value.length; i++) {\n const itemVal = value[i];\n const key = this.#key(itemVal, i);\n let connected = this.#connectedItems.get(key);\n\n if (connected && nextKeys.has(key)) {\n connected._setItem(itemVal);\n connected._setIndex(i);\n } else {\n const [_item, _setItem] = createAtom(itemVal);\n const [_index, _setIndex] = createAtom(i);\n\n const renderContent = this.#render(\n () => _item(),\n () => _index(),\n );\n const _node = render(renderContent, this.#context);\n\n connected = {\n _key: key,\n _node,\n _item,\n _setItem,\n _index,\n _setIndex,\n };\n }\n nextItems.set(key, connected);\n }\n });\n\n this.#connectedItems = nextItems;\n\n // Forward pass to insert or move nodes.\n const parent = this.#root.parentElement!;\n let referenceNode: Node = this.#root;\n\n for (const connected of this.#connectedItems.values()) {\n const expectedNext = referenceNode.nextSibling;\n\n if (!connected._node.isMounted()) {\n // Node is new. Mount it exactly at the current cursor.\n connected._node.mount(parent, referenceNode);\n } else if (connected._node.getRoot() !== expectedNext) {\n // Node is out of order. Move it.\n connected._node.move(parent, referenceNode);\n }\n\n // Advance the cursor.\n referenceNode = connected._node.getRoot()!;\n }\n }\n}\n","import { createMarkup, Renderable } from \"..\";\nimport { isFunction } from \"../../utils\";\nimport { type Getter, compose } from \"../signals\";\nimport { DynamicNode } from \"./nodes/dynamic\";\nimport { PortalNode } from \"./nodes/portal\";\nimport { KeyFn, RenderFn, RepeatNode } from \"./nodes/repeat\";\n\n/**\n * Displays a dynamic list. Items will be added and removed as the list is updated.\n *\n * @param items - List items. Can be reactive.\n * @param keyFn - Takes (item, index) as plain values and returns a unique key to identify that item (usually the item's ID).\n * @param renderFn - Takes (item, index) as Reactive values and returns content to display for that item.\n */\nexport function forEach<T>(\n items: Getter<Iterable<T>> | Iterable<T>,\n keyFn: KeyFn<T>,\n renderFn: RenderFn<T>,\n): Renderable {\n if (isFunction(items)) {\n return createMarkup(RepeatNode<T>, { args: [items, keyFn, renderFn] });\n } else {\n return Array.from(items).map((item, index) =>\n renderFn(\n () => item,\n () => index,\n ),\n );\n }\n}\n\n/**\n * Displays content conditionally. When `condition` is truthy, display `content`. When `condition` is falsy, display `fallback`.\n *\n * @param condition - Condition to hide or show content on. Can be reactive.\n * @param whenTruthy - Content to display when condition is truthy.\n * @param whenFalsy - Content to display when condition is falsy.\n */\nfunction _conditional(condition: any, whenTruthy?: Renderable, whenFalsy?: Renderable): Renderable {\n if (isFunction(condition)) {\n return createMarkup(DynamicNode, {\n args: [compose(() => (condition() ? whenTruthy : whenFalsy))],\n });\n } else if (condition) {\n return whenTruthy;\n } else {\n return whenFalsy;\n }\n}\n\n/**\n * Shows content only when `condition` is truthy.\n * It can be a plain value or a Getter to track dynamically.\n *\n * @param condition - Condition to hide or show content on.\n * @param content - Content to display when condition is truthy.\n * @param fallback - Content to display when condition is falsy.\n */\nexport function showIf(condition: any, content: Renderable, fallback?: Renderable): Renderable {\n return _conditional(condition, content, fallback);\n}\n\n/**\n * Shows content only when `condition` is falsy.\n * It can be a plain value or a Getter to track dynamically.\n *\n * @param condition - Condition to hide or show content on.\n * @param content - Content to display when condition is falsy.\n * @param fallback - Content to display when condition is truthy.\n */\nexport function hideIf(condition: any, content: Renderable, fallback?: Renderable): Renderable {\n return _conditional(condition, fallback, content);\n}\n\n/**\n * Creates a portal that renders `content` into another element on the page.\n **/\nexport function createPortal(parent: Element, content: Renderable) {\n return createMarkup(PortalNode, { args: [content, parent] });\n}\n","// This file is a heavily modified version of the 'htm' library.\n// Original source: https://github.com/developit/htm\n//\n// --- Original htm License ---\n// Copyright 2018 Jason Miller\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { Markup } from \"./types.js\";\nimport { createMarkup } from \"./utils.js\";\n\nexport type Template = Markup | Markup[];\n\nconst enum Mode {\n Slash = 0,\n Text = 1,\n Whitespace = 2,\n TagName = 3,\n Comment = 4,\n PropSet = 5,\n PropAppend = 6,\n}\n\nexport function html(statics: TemplateStringsArray, ...args: any[]): Template {\n const fields = [statics, ...args];\n\n let mode = Mode.Text;\n let buffer = \"\";\n let quote = \"\";\n let current: any[] = [0];\n let propName = \"\";\n\n const commit = (field?: number) => {\n if (mode === Mode.Text && (field || (buffer = buffer.replace(/^\\s*\\n\\s*|\\s*\\n\\s*$/g, \"\")))) {\n current.push(field ? fields[field] : buffer);\n } else if (mode === Mode.TagName && (field || buffer)) {\n current[1] = field ? fields[field] : buffer;\n mode = Mode.Whitespace;\n } else if (mode === Mode.Whitespace && buffer === \"...\" && field) {\n current[2] = Object.assign(current[2] || {}, fields[field]);\n } else if (mode === Mode.Whitespace && buffer && !field) {\n (current[2] = current[2] || {})[buffer] = true;\n } else if (mode >= Mode.PropSet) {\n if (mode === Mode.PropSet) {\n (current[2] = current[2] || {})[propName] = field ? (buffer ? buffer + fields[field] : fields[field]) : buffer;\n mode = Mode.PropAppend;\n } else if (field || buffer) {\n current[2][propName] += field ? buffer + fields[field] : buffer;\n }\n }\n\n buffer = \"\";\n };\n\n for (let i = 0; i < statics.length; i++) {\n if (i) {\n if (mode === Mode.Text) commit();\n commit(i);\n }\n\n for (let j = 0; j < statics[i].length; j++) {\n const char = statics[i][j];\n\n if (mode === Mode.Text) {\n if (char === \"<\") {\n // commit buffer\n commit();\n current = [current, \"\", null];\n mode = Mode.TagName;\n } else {\n buffer += char;\n }\n } else if (mode === Mode.Comment) {\n // Ignore everything until the last three characters are '-', '-' and '>'\n if (buffer === \"--\" && char === \">\") {\n mode = Mode.Text;\n buffer = \"\";\n } else {\n buffer = char + buffer[0];\n }\n } else if (quote) {\n if (char === quote) {\n quote = \"\";\n } else {\n buffer += char;\n }\n } else if (char === '\"' || char === \"'\") {\n quote = char;\n } else if (char === \">\") {\n commit();\n mode = Mode.Text;\n } else if (!mode) {\n // Ignore everything until the tag ends\n } else if (char === \"=\") {\n mode = Mode.PropSet;\n propName = buffer;\n buffer = \"\";\n } else if (char === \"/\" && (mode < Mode.PropSet || statics[i][j + 1] === \">\")) {\n commit();\n if (mode === Mode.TagName) {\n current = current[0];\n }\n const node = current;\n current = current[0];\n\n const type = node[1];\n const props = node[2] || {};\n const children = node.slice(3);\n\n current.push(createMarkup(type, { ...props, children }));\n\n mode = Mode.Slash;\n } else if (char === \" \" || char === \"\\t\" || char === \"\\n\" || char === \"\\r\") {\n // <a disabled>\n commit();\n mode = Mode.Whitespace;\n } else {\n buffer += char;\n }\n\n if (mode === Mode.TagName && buffer === \"!--\") {\n mode = Mode.Comment;\n current = current[0];\n }\n }\n }\n commit();\n\n return current.length > 2 ? current.slice(1) : current[1];\n}\n","import { assert } from \"../utils\";\n\nexport interface Ref<T> {\n /**\n * Call with no arguments to get the stored value.\n * Throws an error if the ref is empty (this means you forgot to pass it or it was called after teardown).\n */\n (): T;\n\n /**\n * Call with an argument to initialize the value. Returns a cleanup function.\n * The cleanup function should clear any references to the DOM node.\n */\n (value: T): () => void;\n}\n\nexport function createRef<T = HTMLElement>(): Ref<T> {\n let currentValue: T | undefined;\n\n return ((...args: [T]) => {\n if (args.length) {\n currentValue = args[0];\n return () => {\n currentValue = undefined;\n };\n } else {\n // assert(currentValue !== undefined, \"Empty ref!\");\n return currentValue;\n }\n }) as Ref<T>;\n}\n"],"mappings":";AAIA,IAAI,IAAS;AACb,SAAgB,IAAW;AACzB,SAAQ,KAAU,SAAS,GAAG;;AAehC,SAAgB,EAAiC,GAAmB,GAA6B;CAC/F,IAAM,IAA8B,EAAE;AAEtC,MAAK,IAAM,KAAO,EAChB,CAAK,EAAK,SAAS,EAAI,KACrB,EAAU,KAAO,EAAO;AAI5B,QAAO;;AAaT,SAAgB,EAAgB,GAAU,GAAuD;AAC/F,KAAI,CAAC,EAAO,OAAU,UAAU,EAAa;;AAM/C,SAAgB,EAAQ,GAAyC;AAC/D,QAAO,MAAM,QAAQ,EAAM;;AAuB7B,SAAgB,EAAS,GAAiC;AACxD,QAAO,OAAO,KAAU;;AAM1B,SAAgB,EAAgD,GAA4B;AAC1F,QAAO,OAAO,KAAU,cAAc,CAAC,EAAQ,EAAM;;AAGvD,SAAgB,EAAQ,GAAgB;AACtC,QAAO,eAAe,KAAK,OAAO,EAAM,CAAC;;AAM3C,SAAgB,EAAS,GAAiC;AACxD,QAAO,OAAO,KAAU,YAAY,CAAC,MAAM,EAAM;;AA8BnD,S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