{"version":3,"sources":["jsdelivr-header.js","/npm/alfama@1.3.24/src/utils/crawl.ts","/npm/alfama@1.3.24/src/utils/ts-object-path/index.ts","/npm/alfama@1.3.24/src/utils/cursor.ts","/npm/alfama@1.3.24/src/utils/index.ts","/npm/alfama@1.3.24/src/core/state/utils.ts","/npm/alfama@1.3.24/src/core/state/wire.ts","/npm/alfama@1.3.24/src/core/state/signal.ts","/npm/alfama@1.3.24/src/core/state/store.ts","/npm/alfama@1.3.24/src/core/state/storeAPI.ts","/npm/alfama@1.3.24/src/dom/dom.ts","/npm/alfama@1.3.24/src/dom/utils.ts","/npm/alfama@1.3.24/src/dom/resolver.ts","/npm/alfama@1.3.24/src/dom/traverser.ts","/npm/alfama@1.3.24/src/dom/api.ts","/npm/alfama@1.3.24/src/dom/index.ts","/npm/alfama@1.3.24/src/stdlib/Each/index.tsx","/npm/alfama@1.3.24/src/stdlib/Portal/index.tsx","/npm/alfama@1.3.24/src/stdlib/When/index.tsx"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,yCCLO,IAAM,EAAQ,CACnB,EACA,EACA,IACG,CACH,GAAa,EAAM,EAAS,EAAQ,IAAI,CAC1C,EAGa,GAAe,CAC1B,EACA,EACA,IACG,CAEH,IAAM,EAAmC,CAAA,EAEnC,EAAU,IAAI,IAKpB,IAFA,EAAM,KAAK,CAAE,KAAM,EAAM,EAAG,EAAM,CAAC,EAE5B,EAAM,OAAS,GAAG,CACvB,GAAM,CAAE,KAAA,EAAM,EAAG,CAAgB,EAAI,EAAM,EAAM,OAAS,CAAC,EAEvD,GACF,EAAQ,CAAI,EACZ,EAAM,IAAA,IAEN,EAAQ,IAAI,CAAI,EAEhB,EAAM,EAAM,OAAS,CAAC,EAAE,EAAI,IAEV,EAAK,CAAI,GAAK,CAAA,GAAI,QAAA,EAC3B,QAAS,GAAU,CACrB,EAAQ,IAAI,CAAK,GACpB,EAAM,KAAK,CAAE,KAAM,EAAO,EAAG,EAAM,CAAC,CAExC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AAW,CAAG,EACrC,CAAG,CACvB,EC9La,GAAS,EACpB,SACA,CAAC,EAAO,CAAE,UAAA,EAAW,KAAM,CAAW,KACpC,EAAW,GAAc,CACnB,GAAQ,EAAK,KAAK,EAAQ,EAAK,GAAG,CACxC,CAAC,EACA,EAAiC,MAAQ,EAAM,MACzC,EAAM,SAEjB,ECAa,GAAO,EAClB,OACA,CAAC,EAAO,CAAE,MAAA,EAAO,UAAA,EAAW,QAAA,EAAS,KAAM,EAAY,cAAA,CAAc,IAAM,CACzE,IAAM,EAAa,EAAM,KAAK,EAAM,SAAS,EACvC,EAAQ,EAAW,IAAA,EACnB,EAAW,GACX,OAAO,EAAM,OAAU,WAClB,IAAO,EAAM,MAAmB,CAAK,EAE/B,EAAM,MAAM,CAAuB,GACjC,EAAM,SAGnB,EAAQ,GAAe,CAC3B,IAAM,EAAO,EAAQ,CAAK,EACpB,EAAI,EAAO,EAAA,EAAS,KACpB,EAAmB,CAAC,GAAG,EAAW,CAAC,EACnC,CAAC,EAAU,CAAI,EAAI,EAAU,EAAe,EAAG,CAAU,EAC/D,EAAQ,EAAe,EAAY,CAAI,EACvC,QAAS,KAAK,EACZ,EAAW,EAAe,CAAC,CAE/B,EACA,EAAQ,IAAM,CACZ,EAAW,MAAM,IAAI,CAAI,CAC3B,CAAC,EACD,EAAU,IAAM,CACd,EAAW,MAAM,OAAO,CAAI,CAC9B,CAAC,EACD,IAAM,EAAO,EAAQ,CAAK,EAC1B,OAAO,EAAO,EAAA,EAAS,IACzB,CACF","file":"/npm/alfama@1.3.24/dist/index.js/+esm","sourceRoot":"","sourcesContent":["/**\n * Bundled by jsDelivr using Rollup v4.62.2 and esbuild v0.28.1.\n * Original file: /npm/alfama@1.3.24/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","// Crawl the tree in post-order.\nexport const crawl = <T>(\n  root: T,\n  iterate: (node: T) => void,\n  options: { order: \"post\"; kids: (node: T) => T[] }\n) => {\n  dfsPostOrder(root, iterate, options.kids);\n};\n\n// Helper function for dfsPostOrder.\nexport const dfsPostOrder = <T>(\n  root: T,\n  iterate: (node: T) => void,\n  kids: (node: T) => T[]\n) => {\n  // The stack holds the nodes we need to visit.\n  const stack: { node: T; v: boolean }[] = [];\n  // Keep track of the nodes we've visited.\n  const visited = new Set();\n\n  // Push the root node onto the stack to start the traversal.\n  stack.push({ node: root, v: false });\n\n  while (stack.length > 0) {\n    const { node, v: visitedChildren } = stack[stack.length - 1];\n    // If all the node's children have been visited, visit the node and pop it from the stack.\n    if (visitedChildren) {\n      iterate(node);\n      stack.pop();\n    } else {\n      visited.add(node);\n      // Mark that we've visited the node's children.\n      stack[stack.length - 1].v = true;\n      // Otherwise, push all the unvisited children onto the stack.\n      const children = (kids(node) || []).reverse();\n      children.forEach((child) => {\n        if (!visited.has(child)) {\n          stack.push({ node: child, v: false });\n        }\n      });\n    }\n  }\n};\n\n// Helper function for dfsPreOrder.\nexport const dfsPreOrder = <T>(\n  root: T,\n  iterate: (attrs: { node: T; i: number }) => void | any,\n  kids: (node: T) => T[]\n) => {\n  // The stack holds the nodes we need to visit.\n  const stack: { node: T; i: number }[] = [];\n\n  // Push the root node onto the stack to start the traversal.\n  stack.push({ node: root, i: 0 });\n\n  while (stack.length > 0) {\n    const node = stack.pop();\n    if (!node) return;\n\n    // Visit the node.\n    const v = iterate(node);\n    if (v) return;\n\n    // Push all the children onto the stack in reverse order so that\n    // they are processed in the original order.\n    const k = kids(node.node);\n    //      console.log(\"k\", k);\n    const children = [...(k || [])].reverse();\n    children.forEach((child, i) => {\n      stack.push({ node: child, i });\n    });\n  }\n};\n","export type ObjPathProxy<TRoot, T> = {\n  [P in keyof T]: ObjPathProxy<TRoot, T[P]>;\n};\n\nexport type ObjProxyArg<TRoot, T> =\n  | ObjPathProxy<TRoot, T>\n  | ((p: ObjPathProxy<TRoot, TRoot>) => ObjPathProxy<TRoot, T>);\n\nexport const PATH_FLAG = Symbol();\n\nexport function createProxy<T>(\n  path: PropertyKey[] = [],\n  base: any = {}\n): ObjPathProxy<T, T> {\n  const proxy = new Proxy(\n    // added to ts-object-path\n    { [PATH_FLAG]: path, ...base },\n    {\n      get(target, key) {\n        // added to ts-object-path\n        if (base[key]) {\n          return base[key];\n        }\n        if (key === PATH_FLAG) {\n          return target[PATH_FLAG];\n        }\n        if (typeof key === \"string\") {\n          const intKey = parseInt(key, 10);\n          if (key === intKey.toString()) {\n            key = intKey as any;\n          }\n        }\n        return createProxy([...(path || []), key], base);\n      },\n    }\n  );\n  return proxy as any as ObjPathProxy<T, T>;\n}\n\nexport function getPath<TRoot, T>(proxy: ObjProxyArg<TRoot, T>): PropertyKey[] {\n  if (typeof proxy === \"function\") {\n    proxy = proxy(createProxy<TRoot>());\n  }\n  return (proxy as any)[PATH_FLAG];\n}\n\nexport function isProxy<TRoot, T>(value: any): value is ObjPathProxy<TRoot, T> {\n  return (\n    value &&\n    typeof value === \"object\" &&\n    !!getPath<TRoot, T>(value as ObjPathProxy<TRoot, T>)\n  );\n}\n\nexport function get<TRoot, T>(\n  object: TRoot,\n  proxy: ObjProxyArg<TRoot, T>,\n  defaultValue: T | null | undefined = undefined\n) {\n  return getPath(proxy).reduce(\n    (o, key) => o && valueOrElseDefault(o[key], defaultValue),\n    object as any\n  ) as T;\n}\n\nexport function set<TRoot, T>(\n  object: TRoot,\n  proxy: ObjProxyArg<TRoot, T>,\n  value: T\n): void {\n  getPath(proxy).reduce((o: any, key, index, keys) => {\n    if (index < keys.length - 1) {\n      o[key] = o[key] || (typeof keys[index + 1] === \"number\" ? [] : {});\n      return o[key];\n    }\n    o[key] = value;\n  }, object);\n}\n\nexport function valueOrElseDefault<T>(value: T, defaultValue: T): T {\n  return value !== null && value !== undefined ? value : defaultValue;\n}\n","import { StoreCursor } from \"../core\";\nimport {\n  createProxy,\n  getPath,\n  ObjPathProxy,\n  PATH_FLAG,\n} from \"./ts-object-path\";\n\nexport type { ObjPathProxy } from \"./ts-object-path\";\nexport { PATH_FLAG } from \"./ts-object-path\";\nexport const META_FLAG = Symbol();\n\nexport type CursorProxy<T = unknown, V = unknown> = ObjPathProxy<T, T>;\n\nexport type CursorProxyInternal<T = unknown, V = unknown> = CursorProxy<\n  T,\n  V\n> & {\n  [PATH_FLAG]: string[];\n  [META_FLAG]: V;\n};\n\nexport const wrapWithCursorProxy = <T = unknown, V = unknown>(\n  obj: T,\n  meta: any\n): CursorProxy<T, V> => {\n  const p = createProxy<T>([], {\n    [META_FLAG]: meta,\n  });\n  return p as CursorProxy<T, V>;\n};\n\nexport const isCursorProxy = (proxy: unknown) =>\n  proxy && !!(proxy as CursorProxyInternal)[PATH_FLAG];\n\nexport const getCursor = (cursor: StoreCursor) => [\n  ...(cursor as CursorProxyInternal)[PATH_FLAG],\n];\n\nexport const getReactiveCursor = (cursor: StoreCursor) => [\n  ...(cursor as CursorProxyInternal)[PATH_FLAG],\n];\n\nexport const getCursorProxyMeta = <T = unknown>(cursor: CursorProxy) =>\n  (cursor as CursorProxyInternal)[META_FLAG] as T;\n","export * from \"./crawl\";\nexport * from \"./cursor\";\n\nexport const getValueUsingPath = (\n  record: Record<string, any>,\n  path: string[]\n) => {\n  if (!record) return record;\n  return path.length === 0\n    ? record\n    : path.reduce((record, item) => record[item], record);\n};\n","import * as Constants from \"../constants\";\nimport { Wire, Signal, SignalGetter, ObjPathProxy } from \"./types\";\nimport { isCursorProxy } from \"../../utils\";\n\nexport const isWire = (arg: any): arg is Wire => {\n  return (arg as Wire).type === Constants.WIRE;\n};\n\nexport const isSignal = (arg: any): arg is Signal => {\n  return (arg as Signal).type === Constants.SIGNAL;\n};\n\nexport const isSignalGetter = (arg: any): arg is SignalGetter => {\n  return (arg as SignalGetter).type === Constants.SIGNAL_GETTER;\n};\n\nexport const isStoreCursor = (\n  arg: any\n): arg is ObjPathProxy<unknown, unknown> => {\n  return Boolean(isCursorProxy(arg));\n};\n","import { getCursorProxyMeta } from \"../../utils/index\";\nimport * as Constants from \"../constants\";\nimport {\n  Signal,\n  SignalGetter,\n  StoreCursor,\n  StoreManager,\n  SubToken,\n  Wire,\n  WireFactory,\n  WireFunction,\n} from \"./types\";\nimport { isSignal, isSignalGetter, isStoreCursor } from \"./utils\";\nexport {\n  getCursorProxyMeta as getProxyMeta,\n  getCursor as getProxyPath,\n} from \"../../utils/index\";\nexport type { ObjPathProxy } from \"../../utils/index\";\n\nlet WIRE_COUNTER = 0;\n\nconst S_RUNNING = 0b100 as const;\nconst S_SKIP_RUN_QUEUE = 0b010 as const;\nconst S_NEEDS_RUN = 0b001 as const;\n\nexport const createWire: WireFactory = (arg: WireFunction): Wire => {\n  WIRE_COUNTER++;\n  const wire: Wire = Object.assign(() => {}, {\n    id: WIRE_COUNTER,\n    type: Constants.WIRE,\n    fn: arg,\n    sigs: new Set(),\n    stores: new Map(),\n    tasks: new Set(),\n    state: S_NEEDS_RUN,\n    upper: undefined,\n    lower: new Set(),\n    r: 0,\n    run: () => {\n      const val = runWire(arg, wire.token, wire.subWire);\n      // Clean up unused nested wires\n      return val;\n    },\n    subWire: (subFn: WireFunction) => {\n      const subWire = createWire(subFn);\n      subWire.upper = wire;\n      wire.lower.add(subWire);\n      return subWire;\n    },\n    token: undefined as any,\n  } as Wire);\n  wire.token = getSubtoken(wire);\n  return wire;\n};\n\nconst getSubtoken = (wire: Wire): SubToken => {\n  const token: SubToken = (arg: Signal | StoreCursor | SignalGetter) => {\n    if (isSignal(arg)) {\n      const v = arg.get(token);\n      wire.v = v;\n      return v;\n    } else if (isSignalGetter(arg)) {\n      const sig = arg.sig;\n      const v = sig.get(token);\n      wire.v = v;\n      return v;\n    } else if (isStoreCursor(arg)) {\n      const cursor = arg;\n      const manager = getCursorProxyMeta<StoreManager>(cursor);\n      const v = manager.get(cursor, token);\n      wire.v = v;\n      return v;\n    }\n  };\n  token.wire = wire;\n  token.type = Constants.SUBTOKEN;\n  return token;\n};\n\nexport const runWire = (\n  arg: WireFunction | Signal | StoreCursor | SignalGetter,\n  token: SubToken,\n  subWireFactory: WireFactory\n) => {\n  if (isStoreCursor(arg)) {\n    const cursor = arg;\n    const v = token(cursor);\n    token.wire.v = v;\n    return v;\n  } else if (isSignal(arg)) {\n    const sig = arg;\n    const v = token(sig);\n    token.wire.v = v;\n    return v;\n  } else if (isSignalGetter(arg)) {\n    const sig = arg.sig;\n    const v = token(sig);\n    token.wire.v = v;\n    return v;\n  } else {\n    const fn = arg as WireFunction;\n    const v = fn(token, {\n      createWire: subWireFactory,\n      wire: subWireFactory,\n      previousValue: token.wire.v,\n    });\n    token.wire.v = v;\n    return v;\n  }\n};\n\nexport const wireReset = (wire: Wire<any>): void => {\n  wire.lower.forEach(wireReset);\n  wire.sigs.forEach((signal) => signal.w.delete(wire));\n  wire.stores.forEach((store) => {\n    const manager = getCursorProxyMeta<StoreManager>(store);\n    if (manager) {\n      manager.w.delete(wire);\n    }\n  });\n  _initWire(wire);\n};\n\nconst _initWire = (wire: Wire<any>): void => {\n  wire.state = S_NEEDS_RUN;\n  wire.lower = new Set();\n  // Drop all signals now that they have been unlinked\n  wire.sigs = new Set();\n  wire.stores = new Map();\n};\n\n// Pauses a wire so signal writes won't cause runs. Affects nested wires\nconst wirePause = (wire: Wire): void => {\n  wire.lower.forEach(wirePause);\n  wire.state |= S_SKIP_RUN_QUEUE;\n};\n\n// Resumes a paused wire. Affects nested wires but skips wires belonging to computed-signals. Returns true if any runs were missed during the pause\nconst wireResume = (wire: Wire): boolean => {\n  wire.lower.forEach(wireResume);\n  wire.state &= ~S_SKIP_RUN_QUEUE;\n  return !!(wire.state & S_NEEDS_RUN);\n};\n\nexport const runWires = (wires: Set<Wire<any>>): void => {\n  // Use a new Set() to avoid infinite loops caused by wires writing to signals\n  // during their run.\n  const toRun = new Set(wires);\n  let curr: Wire<any> | undefined;\n  // Mark upstream computeds as stale. Must be in an isolated for-loop\n  toRun.forEach((wire) => {\n    if (wire.state & S_SKIP_RUN_QUEUE) {\n      toRun.delete(wire);\n      wire.state |= S_NEEDS_RUN;\n    }\n    // TODO: Test (#3) + Benchmark with main branch\n    // If a wire's ancestor will run it'll destroy its lower wires. It's more\n    // efficient to not call them at all by deleting from the run list:\n    curr = wire;\n    while ((curr = curr.upper)) if (toRun.has(curr)) return toRun.delete(wire);\n  });\n  toRun.forEach((wire) => {\n    const previousValue = wire.v;\n    const val = runWire(wire.fn, wire.token, wire.subWire);\n\n    wire.r = wire.r + 1;\n    if (val === previousValue) return;\n\n    wire.v = val;\n    for (const task of wire.tasks) {\n      task(val);\n    }\n  });\n};\n","import * as Constants from \"../constants\";\nexport {\n  getCursorProxyMeta as getProxyMeta,\n  getCursor as getProxyPath,\n} from \"../../utils/index\";\nexport type { ObjPathProxy } from \"../../utils/index\";\nimport { Signal, SignalGetter, SignalSetter, SubToken, Wire } from \"./types\";\nimport { runWires } from \"./wire\";\n\nlet SIGNAL_COUNTER = 0;\n\nexport const createSignal = <T = any>(val: T): Signal<T> => {\n  SIGNAL_COUNTER++;\n  const get: SignalGetter<T> = (token?: SubToken) => {\n    if (token) {\n      // Two-way link. Signal writes will now call/update wire W\n      token.wire.sigs.add(sig);\n      sig.w.add(token.wire);\n      return sig.v as T;\n    } else {\n      return sig.v as T;\n    }\n  };\n  get.type = Constants.SIGNAL_GETTER;\n\n  const set: SignalSetter<T> = (value: T) => {\n    if (sig.v === value) return value;\n    sig.v = value;\n    runWires(sig.w);\n    return val;\n  };\n\n  const sig = [get, set] as unknown as Signal<T>;\n  sig.id = SIGNAL_COUNTER;\n  sig.type = Constants.SIGNAL;\n  sig.v = val;\n  sig.w = new Set<Wire>();\n\n  get.sig = sig;\n\n  sig.get = get;\n  sig.set = set;\n\n  return sig;\n};\n\nexport const createComputedSignal = <T = any>(wire: Wire<T>) => {\n  const value = wire.run();\n  const signal = createSignal<T>(value);\n  const handler = () => {\n    if (signal.get() !== wire.v) signal.set(wire.v as T);\n  };\n  wire.tasks.add(handler);\n  return signal;\n};\n","import onChange, { ApplyData } from \"on-change\";\nimport { getCursor, getValueUsingPath } from \"../../utils/index\";\nimport * as Constants from \"../constants\";\nimport { StoreCursor, StoreManager, SubToken, Wire } from \"./types\";\nimport { runWires } from \"./wire\";\nexport {\n  getCursorProxyMeta as getProxyMeta,\n  getCursor as getProxyPath,\n} from \"../../utils/index\";\nexport type { ObjPathProxy } from \"../../utils/index\";\n\nconst encodeCursor = (cursor: string[]) =>\n  cursor.map(encodeURIComponent).join(\"/\");\nconst decodeCursor = (str: string) => str.split(\"/\").map(decodeURIComponent);\n\n// Create the store manager with essential functionalities\nexport const createStoreManager = <T>(\n  id: number,\n  observedObject: Record<any, any>\n): StoreManager<T> => {\n  const manager: StoreManager<T> = {\n    id: \"store|\" + id,\n    v: observedObject,\n    w: new Set<Wire>(),\n    type: Constants.STORE,\n    tasks: new Set(),\n    unsub: () => {\n      onChange.unsubscribe(observedObject);\n    },\n    get: (cursor: StoreCursor, token: SubToken) =>\n      createStoreSubscription(manager, cursor, token.wire),\n  };\n  return manager;\n};\n\n// Get the value from the store based on a cursor path\nconst createStoreSubscription = <T>(\n  manager: StoreManager,\n  cursor: StoreCursor,\n  wire: Wire\n): any => {\n  const cursorPath = getCursor(cursor);\n  const encodedCursor = encodeCursor(cursorPath);\n  manager.w.add(wire);\n  if (wire.stores.has(manager)) {\n    wire.stores.get(manager)?.add(encodedCursor);\n  } else {\n    const set = new Set<string>();\n    set.add(encodedCursor);\n    wire.stores.set(manager, set);\n  }\n  return getValueUsingPath(manager.v as any, cursorPath);\n};\n\n// Handle changes in the store and trigger associated tasks and wires\nexport const handleStoreChange = (\n  manager: StoreManager,\n  path: (string | symbol)[],\n  newValue: any,\n  oldValue: any,\n  changeData: ApplyData\n) => {\n  //  if (path[0] !== \"state\")\n  //    console.log(\n  //      \"handleStoreChange\",\n  //      path,\n  //      newValue,\n  //      oldValue,\n  //      changeData,\n  //      manager.value\n  //    );\n  const changePath = path as string[];\n  adjustCursorForArrayChange(manager, path as string[], changeData);\n  const wiresToRun = findMatchingWires(manager, changePath, changeData);\n  runWires(wiresToRun);\n  triggerStoreTasks(manager, changePath, newValue, changeData);\n};\n\n// Find wires that match the change path\nconst findMatchingWires = (\n  manager: StoreManager,\n  changePath: string[],\n  changeData: ApplyData\n): Set<Wire> => {\n  const matchingWires = new Set<Wire>();\n\n  manager.w.forEach((wire) => {\n    const cursors = wire.stores.get(manager);\n    if (!cursors) return;\n\n    for (const cursorStr of cursors) {\n      const cursor = cursorStr === \"\" ? [] : decodeCursor(cursorStr);\n      const isMatch = matchCursorToChange(cursor, changePath, changeData);\n      isMatch && matchingWires.add(wire);\n    }\n  });\n\n  return matchingWires;\n};\n\n// Determine if a cursor matches the change path\nconst matchCursorToChange = (\n  cursor: string[],\n  changePath: string[],\n  changeData: ApplyData\n): boolean => {\n  if (changeData === undefined) {\n    return cursor.length <= changePath.length\n      ? encodeCursor(changePath.slice(0, cursor.length)) == cursor.join(\"/\")\n      : true;\n  }\n\n  if ([\"splice\", \"push\", \"pop\"].includes(changeData.name)) {\n    return encodeCursor(changePath.slice(0, cursor.length)) == cursor.join(\"/\");\n  }\n\n  return false;\n};\n\n// Trigger tasks based on the change path\nconst triggerStoreTasks = (\n  manager: StoreManager,\n  changePath: string[],\n  newValue: any,\n  changeData: ApplyData\n) => {\n  manager.tasks.forEach(({ path, observor }) => {\n    const isPathMatching =\n      changePath.slice(0, path.length).join(\"/\") === path.join(\"/\");\n    if (isPathMatching) {\n      observor({\n        data: (changeData\n          ? {\n              name: changeData.name,\n              args: changeData.args,\n              result: undefined,\n            }\n          : undefined) as any,\n        path: changePath,\n        value: newValue,\n      });\n    }\n  });\n};\n\n//\n// Function to adjust cursor paths for array changes\nfunction adjustCursorForArrayChange(\n  manager: StoreManager,\n  changePath: string[],\n  change: ApplyData\n): void {\n  if (!change || change.name !== \"splice\") {\n    return;\n  }\n  const args = change.args as [string, string, ...any];\n  const start = parseInt(args[0]);\n  const deleteCount = parseInt(args[1]);\n  const items = args.slice(2);\n\n  //  console.log(\"adjustCursorForArrayChange\", { start, deleteCount });\n\n  manager.w.forEach((wire) => {\n    wire.stores.forEach((cursorSet) => {\n      const { rm: toRemove, add: toAdd } = adjustCursorsInSet(\n        cursorSet,\n        changePath,\n        start,\n        deleteCount,\n        items\n      );\n\n      toRemove.forEach((cursor) => cursorSet.delete(cursor));\n      toAdd.forEach((cursor) => cursorSet.add(cursor));\n\n      //console.log({ toRemove, toAdd }, wire.storesRS);\n    });\n  });\n\n  manager.tasks.forEach((task) => {\n    if (isPathAffected(task.path, changePath)) {\n      const listenerIndex = getListenerIndex(task.path, changePath.length);\n\n      if (start + deleteCount <= listenerIndex) {\n        const newIndex = listenerIndex - deleteCount + items.length;\n        task.path[changePath.length] = newIndex.toString();\n        //console.log(\"Updated task path\", encodeCursor(task.path));\n      }\n    }\n  });\n}\n\nfunction adjustCursorsInSet(\n  cursorSet: Set<string>,\n  changePath: string[],\n  start: number,\n  deleteCount: number,\n  items: any[]\n): { rm: string[]; add: string[] } {\n  const toRemove: string[] = [];\n  const toAdd: string[] = [];\n\n  cursorSet.forEach((cursorString) => {\n    const cursor = decodeCursor(cursorString);\n    if (isPathMatching(cursor, changePath)) {\n      const listenerIndex = getListenerIndex(cursor, changePath.length);\n\n      if (start + deleteCount <= listenerIndex) {\n        toRemove.push(cursorString);\n        cursor[changePath.length] = (\n          listenerIndex -\n          deleteCount +\n          items.length\n        ).toString();\n        toAdd.push(encodeCursor(cursor));\n      }\n    }\n  });\n\n  return { rm: toRemove, add: toAdd };\n}\n\nfunction isPathMatching(cursor: string[], changePath: string[]): boolean {\n  return (\n    encodeCursor(changePath) ===\n    encodeCursor(cursor.slice(0, changePath.length))\n  );\n}\n\nfunction getListenerIndex(cursor: string[], pathLength: number): number {\n  return parseInt(cursor[pathLength]);\n}\n\nfunction isPathAffected(path: string[], changePath: string[]): boolean {\n  return (\n    encodeCursor(changePath) ===\n      encodeCursor(path.slice(0, changePath.length)) &&\n    path.length > changePath.length\n  );\n}\n","import onChange from \"on-change\";\nimport {\n  CursorProxy,\n  getCursor,\n  getCursorProxyMeta,\n  getValueUsingPath,\n  ObjPathProxy,\n  wrapWithCursorProxy,\n} from \"../../utils/index\";\nimport { createStoreManager, handleStoreChange } from \"./store\";\nimport { StoreChange, StoreCursor, StoreManager } from \"./types\";\nexport {\n  getCursorProxyMeta as getProxyMeta,\n  getCursor as getProxyPath,\n} from \"../../utils/index\";\nexport type { ObjPathProxy } from \"../../utils/index\";\n\nlet STORE_COUNTER = 0;\n\nexport const createStore = <T = unknown>(\n  obj: T\n): StoreCursor<T, StoreManager<T>> => {\n  const observedObject = onChange(\n    obj as Record<any, any>,\n    (p, v, pv, data) => handleStoreChange(manager, p, v, pv, data),\n    {\n      pathAsArray: true,\n      ignoreDetached: true,\n    }\n  );\n  STORE_COUNTER++;\n  const manager = createStoreManager(STORE_COUNTER, observedObject);\n\n  const s = wrapWithCursorProxy<T, StoreManager<T>>(observedObject, manager);\n\n  return s as StoreCursor<T>;\n};\n\nexport const reify = <T = unknown>(cursor: T): T => {\n  const s = cursor as unknown as StoreCursor;\n  const manager: StoreManager = getCursorProxyMeta<StoreManager>(\n    s as unknown as ObjPathProxy<unknown, unknown>\n  );\n  if (manager) {\n    const cursorPath = getCursor(s);\n    const v = getValueUsingPath(manager.v as any, cursorPath);\n    return v as T;\n  } else {\n    return cursor;\n  }\n};\n\nexport const produce = <T = unknown>(\n  cursor: T,\n  setter: (obj: T) => void,\n  fv?: any\n): void => {\n  const v = fv ? fv : reify(cursor);\n  setter(v);\n};\n\n// Apply changes to the store based on the cursor and change object\nexport const applyStoreChange = (store: CursorProxy, change: StoreChange) => {\n  if (change.data) {\n    applyDataChange(store, change);\n  } else {\n    applyValueChange(store, change);\n  }\n};\n\n// Apply a change that uses a data operation (e.g., array operations)\nfunction applyDataChange(store: CursorProxy, change: StoreChange) {\n  const target = getValueUsingPath(store, change.path);\n  produce(target, (state) => {\n    (state as any)[change.data.name].apply(state, change.data.args);\n  });\n}\n\n// Apply a direct value change to the store\nfunction applyValueChange(store: CursorProxy, change: StoreChange) {\n  if (change.path.length === 0) {\n    produce(store, (state) => {\n      const newValue = change.value || {};\n      Object.keys(newValue).forEach((key) => {\n        (state as any)[key] = newValue[key];\n      });\n    });\n  } else {\n    const tailKey = change.path[change.path.length - 1];\n    const target = getValueUsingPath(\n      store,\n      change.path.slice(0, change.path.length - 1)\n    );\n    produce(target, (state) => {\n      state[tailKey] = change.value;\n    });\n  }\n}\n","import * as Constants from \"../core/constants\";\nimport { TreeStep } from \"./types\";\nimport { Wire } from \"../core/state\";\nimport * as DOMConstants from \"./constants\";\nconst createTextNode = (arg: string | number | boolean | null | undefined) =>\n  document.createTextNode(arg == null || arg === undefined ? \"\" : arg + \"\");\n\nconst createMarker = (text: string, owner: DocumentFragment) => {\n  const marker = document.createComment(text);\n  // (marker as any).__owner__ = owner;\n  return marker;\n};\n\n// important only use append/prepend\nexport class LiveDocumentFragment extends DocumentFragment {\n  start: Comment;\n  end: Comment;\n  constructor(t?: string) {\n    super();\n    this.start = createMarker(`<${t}>`, this);\n    this.end = createMarker(`</${t}>`, this);\n    super.append(this.start, this.end);\n  }\n  append(...nodes: Node[]) {\n    this.end.before(...nodes);\n  }\n  prepend(...nodes: Node[]) {\n    this.start.after(...nodes);\n  }\n}\n\nexport const createDOMNode = (\n  step: TreeStep,\n  isSvg?: boolean\n): Node | LiveDocumentFragment | undefined => {\n  if (!step || !step.node) return;\n\n  // primitive types\n  if (step.type === DOMConstants.PrimitiveTreeStep) {\n    return createTextNode(step.node);\n  }\n\n  // wire: create text node from wire output\n  if (step.type == DOMConstants.WireTreeStep) {\n    const wire = step.node as Wire;\n    const value = wire.run();\n    let childEL: Node | undefined = undefined;\n    if (\n      [\"string\", \"number\", \"boolean\", \"undefined\"].indexOf(typeof value) > -1\n    ) {\n      childEL = createTextNode(wire.run() + \"\");\n      wire.tasks.add((val: any) => {\n        childEL ? (childEL.textContent = val) : null;\n      });\n    }\n    return childEL;\n  }\n\n  if (step.node && typeof step.node === \"object\") {\n    const props: Record<string, any> =\n      step.node.type === DOMConstants.COMPONENT ||\n      step.node.type === DOMConstants.NATIVE\n        ? step?.node?.p\n        : {};\n\n    // function component\n    if (step.node.type === DOMConstants.COMPONENT) {\n      return new LiveDocumentFragment(step.node.t.__name__);\n    }\n\n    // plain DOM node\n    if (step.node.type === DOMConstants.NATIVE) {\n      const { t } = step.node;\n      const el = isSvg\n        ? document.createElementNS(\"http://www.w3.org/2000/svg\", t)\n        : document.createElement(step.node.t);\n      const { children, ...rest } = props;\n\n      for (const key in rest) {\n        // onClick to onclick\n        // TODO: handle it better?\n\n        const value = rest[key];\n\n        const isFunctionHandler = key[0] == \"o\" && key[1] == \"n\";\n        const finalKey: string = isFunctionHandler ? key.toLowerCase() : key;\n        if (key === \"dangerouslySetInnerHTML\") {\n          el.innerHTML = value.__html;\n        } else if (key == \"ref\" && typeof value === \"function\") {\n          //(value as any)(el);\n        } else if (isFunctionHandler) {\n          // set function on el\n          (el as any)[finalKey] = value;\n        } else {\n          if (value && value.type === Constants.WIRE) {\n            const w: Wire<string> = value;\n            const val = w.run();\n            setAttributeValue(el, finalKey, val);\n            w.tasks.add((val) => {\n              setAttributeValue(el, finalKey, val);\n            });\n          } else {\n            setAttributeValue(el, finalKey, value);\n          }\n        }\n      }\n\n      return el;\n    }\n  }\n};\n\nconst setAttributeValue = (\n  el: HTMLElement | SVGElement,\n  attr: string,\n  val: any\n) => {\n  try {\n    if (val === undefined) {\n      (el as HTMLElement).removeAttribute(attr);\n    } else {\n      (el as HTMLElement).setAttribute(attr, val);\n    }\n    if (el.tagName === \"INPUT\" && attr === \"checked\")\n      (el as HTMLInputElement).checked = !!val;\n    if (el.tagName === \"INPUT\" && attr === \"value\")\n      (el as HTMLInputElement).value = val;\n  } catch (e) {\n    //    console.error(el, attr, val);\n    throw e;\n  }\n};\n","import { crawl } from \"../utils/crawl\";\nimport * as DOMConstants from \"./constants\";\nimport {\n  BaseTreeStep,\n  Component,\n  ComponentTreeStepState,\n  ComponentVElement,\n  Context,\n  NativeVElement,\n  RenderContext,\n  TreeStep,\n  VElement,\n} from \"./types\";\n\nexport const getDescendants = (node: TreeStep): TreeStep[] => {\n  const nodes: TreeStep[] = [];\n  crawl(\n    node,\n    (node) => {\n      nodes.push(node);\n    },\n    {\n      kids: (parent) => {\n        return [...(Array.isArray(parent.k) ? parent.k : [])];\n      },\n      order: \"post\",\n    }\n  );\n  return nodes;\n};\n\n// note: optimised to eagerly return using for for/while loops\n// todo: use Array.some instead of for/while loops\nexport const getTreeStepRenderContextState = (\n  renderContext: RenderContext,\n  step: TreeStep\n) => {\n  const findMatchingResult = (\n    previousState: Map<string[], ComponentTreeStepState>,\n    baseTreeStep: TreeStep\n  ): ComponentTreeStepState | undefined => {\n    for (const key of previousState.keys()) {\n      let currentStep: BaseTreeStep | undefined = baseTreeStep,\n        index = 0,\n        match = true;\n\n      while (currentStep && index < key.length) {\n        if (key[index] !== currentStep.id) {\n          match = false;\n          break;\n        }\n        currentStep = currentStep.parent;\n        index++;\n      }\n\n      if (match && index === key.length && !currentStep) {\n        return previousState.get(key);\n      }\n    }\n  };\n\n  const match = findMatchingResult(renderContext.prev, step);\n  return match;\n};\n\nexport const getContextProvider = (\n  ctxName: Context,\n  node: TreeStep\n): TreeStep | null => {\n  let ancestor = node.parent;\n  while (ancestor) {\n    if (\n      ancestor.type === DOMConstants.ComponentTreeStep &&\n      ancestor.state.ctx.get(ctxName)\n    ) {\n      return ancestor;\n    }\n    ancestor = ancestor.parent;\n  }\n  return null;\n};\n\nexport const checkIfSVG = (step: TreeStep) => {\n  let isSVG = false;\n  let iterNode = step;\n  while (iterNode.parent) {\n    if (\n      iterNode.node &&\n      typeof iterNode.node === \"object\" &&\n      iterNode.node.type === DOMConstants.NATIVE\n    ) {\n      if (iterNode.node.t === \"svg\") {\n        isSVG = true;\n        break;\n      }\n    }\n    iterNode = iterNode.parent;\n  }\n  return isSVG;\n};\n\nexport const getVirtualElementId = (\n  el: VElement,\n  i?: number\n): string | undefined => {\n  const getElKey = (el: NativeVElement | ComponentVElement) =>\n    el.p.key ? \"/\" + el.p.key : \"\";\n  // console.log(\"el\", el);\n  if (\n    el === null ||\n    el === undefined ||\n    typeof el == \"string\" ||\n    typeof el === \"number\" ||\n    typeof el === \"boolean\"\n  ) {\n    return Number.isFinite(i) ? i + \"\" : undefined;\n  } else if (el.type == DOMConstants.NATIVE) {\n    return el.t + getElKey(el);\n  } else if (el.type === DOMConstants.COMPONENT) {\n    return (el.t as Component).__name__ + getElKey(el);\n  } else {\n    return i !== null && Number.isFinite(i) ? i + \"\" : undefined;\n  }\n};\n\nexport const arrayRemove = <T>(array: T[], ...items: T[]): void => {\n  items.forEach((item) => {\n    const index = array.indexOf(item);\n    index !== -1 && array.splice(index, 1);\n  });\n};\n\nexport function createError(code: string | number, desc?: string) {\n  return new Error(\n    `Error ${code}: https://github.com/abhishiv/alfama/wiki/Error-codes#code-${code}`\n  );\n}\n","import {\n  ComponentUtils,\n  VElement,\n  RenderContext,\n  ComponentTreeStep,\n} from \"./types\";\nimport { getUtils } from \"./api\";\n\nexport const resolveComponent = (\n  renderContext: RenderContext,\n  parentStep: ComponentTreeStep\n) => {\n  const { node, parent } = parentStep;\n  const utils: Omit<ComponentUtils, \"utils\"> = getUtils(\n    renderContext,\n    parentStep\n  );\n  const utilsCtx: ComponentUtils = { ...utils, utils: utils as ComponentUtils };\n  const el = node.t.call(utilsCtx, node.p, utilsCtx) as VElement;\n  return el;\n};\n","import {\n  VElement,\n  ComponentVElement,\n  NativeVElement,\n  NativeTreeStep,\n  PrimitiveTreeStep,\n  WireTreeStep,\n  TreeStep,\n  RenderContext,\n  ComponentTreeStep,\n} from \"./types\";\nimport * as DOMConstants from \"./constants\";\nimport { createError, getVirtualElementId, checkIfSVG } from \"./utils\";\nimport { createDOMNode } from \"./dom\";\nimport { resolveComponent } from \"./resolver\";\n\nimport * as Constants from \"../core/constants\";\nimport { crawl } from \"../utils/crawl\";\n\nexport const reifyTree = (\n  renderContext: RenderContext,\n  el: VElement,\n  parent?: TreeStep,\n  afterIndex?: number\n): [TreeStep[], TreeStep] => {\n  const root = getTreeStep(\n    parent,\n    undefined,\n    el,\n    Number.isFinite(afterIndex) ? (afterIndex as number) + 1 : 0\n  ) as TreeStep;\n  const registry: TreeStep[] = [];\n\n  // traverse bottom-up(post-order) and assemble dom tree\n  crawl(\n    root,\n    function (step) {\n      registry.push(step);\n      // step.parent.children.push shouldnt be done here for root.parent at least\n      // reason more about it: maybe reifyTree shouldn't take parent as prop?\n      if (step !== root && step.parent) step.parent.k.push(step);\n      const isSVG = checkIfSVG(step);\n      const dom = createDOMNode(step, isSVG);\n      if (dom) {\n        step.dom = dom as HTMLElement;\n        const children = registry.filter((el) => el.parent === step);\n        if (children.length > 0) {\n          const kids = children\n            .filter((el) => el.dom)\n            .map((el: TreeStep) => el.dom as Node)\n            .flat();\n          (\n            (step as ComponentTreeStep).mount || (dom as unknown as Element)\n          ).append(...kids);\n          //console.log(\"k\", kids);\n        }\n      }\n    },\n    {\n      order: \"post\",\n      kids: getChildrenFromStep.bind(null, renderContext),\n    }\n  );\n  return [registry, root];\n};\n\nconst getComponentChildrenFromStep = (\n  renderContext: RenderContext,\n  parentStep: ComponentTreeStep\n): TreeStep[] => {\n  const el = resolveComponent(renderContext, parentStep);\n  const r = (Array.isArray(el) ? el : [el])\n    .map((item, i) => getTreeStep(parentStep, undefined, item, i) as TreeStep)\n    .flat();\n  return r;\n};\n\nconst getPlainNodeChildrenFromStep = (\n  renderContext: RenderContext,\n  parentStep: NativeTreeStep\n): TreeStep[] => {\n  const { node, parent } = parentStep;\n  return node\n    ? (((node as NativeVElement)?.p?.children || []) as NativeVElement[])\n        .map(\n          (item, i) => getTreeStep(parentStep, undefined, item, i) as TreeStep\n        )\n        .flat()\n    : [];\n};\n\nconst getChildrenFromStep = (\n  renderContext: RenderContext,\n  parentStep: TreeStep\n): TreeStep[] => {\n  if (!parentStep) return [];\n  const { node, parent } = parentStep;\n\n  if (node && typeof node === \"object\") {\n    if (Array.isArray(node)) {\n      // todo fix this\n      return [];\n    }\n    if (node.type === DOMConstants.NATIVE) {\n      // todo: figure how to remove this typecast\n      return getPlainNodeChildrenFromStep(renderContext, parentStep as any);\n    }\n    if (node.type == DOMConstants.COMPONENT) {\n      // todo: figure how to remove this typecast\n      return getComponentChildrenFromStep(renderContext, parentStep as any);\n    }\n  }\n  return [];\n};\n\nexport const getTreeStep = (\n  parentStep: TreeStep | undefined,\n  meta: Record<string, any> | undefined,\n  el: VElement,\n  index?: number\n): TreeStep | TreeStep[] => {\n  if (Array.isArray(el)) {\n    return (el as VElement[]).map(\n      (el, i) => getTreeStep(parentStep, undefined, el, i) as TreeStep\n    );\n  } else {\n    const step: Partial<TreeStep> = {\n      id: getVirtualElementId(el, index),\n      node: el,\n      meta,\n      parent: parentStep,\n      k: [],\n    };\n    if (\n      el === null ||\n      el === undefined ||\n      typeof el == \"string\" ||\n      typeof el === \"number\" ||\n      typeof el === \"boolean\"\n    ) {\n      return {\n        type: DOMConstants.PrimitiveTreeStep,\n        ...step,\n      } as PrimitiveTreeStep;\n    } else if (el.type === DOMConstants.NATIVE) {\n      return {\n        type: DOMConstants.NativeTreeStep,\n        ...step,\n      } as NativeTreeStep;\n      // why this not DOMConstants\n    } else if (el.type === Constants.WIRE) {\n      return {\n        type: DOMConstants.WireTreeStep,\n        ...step,\n      } as WireTreeStep;\n    } else if (el.type === DOMConstants.COMPONENT) {\n      return {\n        type: DOMConstants.ComponentTreeStep,\n        ...step,\n        state: { sigs: {}, ctx: new Map(), stores: {} },\n        wires: [],\n        onMount: [],\n        onUnmount: [],\n      } as ComponentTreeStep;\n    } else {\n      //      console.error(el);\n      throw createError(110);\n    }\n  }\n};\n","import { unrender } from \".\";\nimport {\n  Signal,\n  StoreCursor,\n  createComputedSignal,\n  createSignal,\n  createStore,\n  createWire,\n} from \"../core/state\";\nimport * as DOMConstants from \"./constants\";\nimport { LiveDocumentFragment } from \"./dom\";\nimport { reifyTree } from \"./traverser\";\nimport {\n  ComponentTreeStep,\n  ComponentUtils,\n  RenderContext,\n  TreeStep,\n  VElement,\n} from \"./types\";\nimport {\n  arrayRemove,\n  createError,\n  getContextProvider,\n  getDescendants,\n  getTreeStepRenderContextState,\n  getVirtualElementId,\n} from \"./utils\";\n\nexport const insertElement = (\n  renderContext: RenderContext,\n  parentStep: TreeStep,\n  parentPath: string[],\n  el: VElement,\n  after?: string\n) => {\n  //  console.log(\"insert\", parentPath, el, after);\n\n  const step = parentPath.reduce<TreeStep | undefined>((step, key) => {\n    if (!step) return;\n    const child = step.k.find((el) => el.id === key);\n    return child;\n  }, parentStep);\n  if (!step) throw createError(120);\n\n  const afterIndex = after\n    ? step.k.findIndex((el) => el.id === after)\n    : undefined;\n\n  const [registry, root] = reifyTree(renderContext, el, step, afterIndex);\n\n  addNode(\n    renderContext,\n    step,\n    root,\n    afterIndex && afterIndex > -1 ? step.k[afterIndex as number] : undefined\n  );\n};\n\nexport const removeElement = (\n  renderContext: RenderContext,\n  parentStep: TreeStep,\n  parentPath: string[],\n  key: string\n) => {\n  const step = parentPath.reduce<TreeStep | undefined>((step, key) => {\n    if (!step) return;\n    const child = step.k.find((el) => el.id === key);\n    return child;\n  }, parentStep);\n  if (!step) throw createError(102);\n  const child = step.k.find((el) => el.id === key);\n  if (!child) throw createError(102);\n  removeNode(renderContext, child);\n};\n\nexport const updateElement = (\n  renderContext: RenderContext,\n  parentStep: TreeStep,\n  key: string[],\n  value: string\n) => {\n  // todo\n};\n\nexport const getLiveFragmentChildNodes = (frag: LiveDocumentFragment) => {\n  const els: Node[] = [];\n  let node: Node | null = frag.start;\n  while (node) {\n    els.push(node);\n    if (node === frag.end) {\n      break;\n    }\n    node = node.nextSibling;\n  }\n  return els;\n};\n\nexport const addNode = (\n  renderCtx: RenderContext,\n  parentStep: TreeStep | undefined,\n  node: TreeStep,\n  before?: TreeStep\n) => {\n  //console.log(\"addNode\", parentStep, node, before);\n  const handle = (node: TreeStep) => {\n    const nodes = getDescendants(node);\n    //console.log(\"n\", nodes, nodes.length);\n    nodes.forEach((step) => {\n      renderCtx.reg.add(step);\n    });\n\n    if (!node.dom) return;\n    // dom\n    if (!parentStep) {\n      //      console.log(\"no parent\", renderCtx.el, node.dom);\n      renderCtx.el.append(node.dom);\n    } else {\n      node.parent = parentStep;\n      if (parentStep && before) {\n        const elementsToInsert = node.dom;\n        const beforeIndex = parentStep.k.indexOf(before);\n        parentStep.k.splice(beforeIndex, 0, node);\n\n        const refNode: HTMLElement = before.dom as HTMLElement;\n        refNode.before(elementsToInsert);\n      } else if (parentStep) {\n        const parentDOM = parentStep.dom;\n        const elementsToInsert = node.dom;\n        parentStep.k.push(node);\n        if (parentDOM && (parentDOM as HTMLElement)) {\n          parentDOM.append(elementsToInsert);\n        }\n      }\n    }\n    nodes.forEach((step) => {\n      // call onMount\n      // call ref\n      if (\n        step.type === DOMConstants.ComponentTreeStep ||\n        step.type === DOMConstants.NativeTreeStep\n      ) {\n        if (step.node.p && step.node.p.ref && step.dom) {\n          step.node.p.ref(step.dom);\n        }\n      }\n      if (\n        step.type === DOMConstants.ComponentTreeStep &&\n        step.onMount.length > 0\n      ) {\n        step.onMount.forEach((el) => el());\n      }\n    });\n  };\n  if (Array.isArray(node)) {\n    node.forEach(handle);\n  } else {\n    handle(node);\n  }\n};\n\nexport const rmNodes = (node: Node | LiveDocumentFragment) => {\n  if (node instanceof LiveDocumentFragment) {\n    const childNodes = getLiveFragmentChildNodes(node);\n    //console.log(\"childNodes\", childNodes.length, childNodes);\n    childNodes.forEach((c) => c.parentNode?.removeChild(c));\n  } else {\n    node.parentElement?.removeChild(node);\n  }\n};\n\nexport const removeNode = (renderCtx: RenderContext, node: TreeStep) => {\n  //console.log(\"removeNodes\", nodes);\n  const nodes = getDescendants(node);\n  //  console.log(\"removeNode nodes\", node, nodes);\n  unrender(nodes);\n  nodes.forEach((step) => {\n    renderCtx.reg.delete(step);\n    step;\n    step.parent ? arrayRemove(step.parent.k, step) : null;\n  });\n};\n\nexport const renderTreeStep = (renderCtx: RenderContext, element: VElement) => {\n  // todo: move this to getRenderContext so it clears DOM properly\n  //if (window.ss) return;\n  renderCtx.el.innerHTML = \"\";\n  const [registry, root] = reifyTree(renderCtx, element);\n  const id = getVirtualElementId(root.node);\n  if (!id) throw createError(101);\n  addNode(renderCtx, undefined, root);\n};\n\nexport const getRenderContext = (\n  container: HTMLElement,\n  element: VElement,\n  options = {}\n) => {\n  const id = getVirtualElementId(element);\n  if (!id) throw createError(101);\n\n  const renderContext: RenderContext = (container as any)[id] || {\n    prev: new Map(),\n    el: container,\n    id,\n    reg: new Set(),\n  };\n\n  //console.log(\"renderContext\", renderContext);\n  renderContext.prev.clear();\n\n  // so HMR is properly cleaned up\n  renderContext.reg.forEach((step) => {\n    //console.log(\"step\", step);\n    if (\n      step.type === DOMConstants.ComponentTreeStep &&\n      step.onUnmount.length > 0\n    )\n      step.onUnmount.forEach((el) => el(step));\n    if (step.type === DOMConstants.ComponentTreeStep) {\n      if (step.mount && step.dom) {\n        rmNodes(step.dom);\n      }\n    }\n\n    if (step.type === DOMConstants.ComponentTreeStep) {\n      const ids: string[] = [];\n      let ancestor: TreeStep | undefined = step;\n      while (ancestor) {\n        // since primitive elements can't have children this is safe\n        if (ancestor.id) {\n          ids.push(ancestor.id);\n        }\n        ancestor = ancestor.parent;\n      }\n      // dont preserve stores for now\n      renderContext.prev.set(ids, {\n        ...step.state,\n        //stores: {},\n        //signals: {},\n      });\n    }\n  });\n  //if (window.ss) return;\n\n  renderContext.reg.clear();\n  (container as any)[id] = renderContext;\n\n  return renderContext;\n};\n\nexport const getUtils = (\n  renderContext: RenderContext,\n  parentStep: ComponentTreeStep\n): Omit<ComponentUtils, \"utils\"> => {\n  return {\n    step: parentStep,\n    renderContext,\n    signal(name: string, val) {\n      const match = getTreeStepRenderContextState(renderContext, parentStep);\n\n      // this enables state preservation during HMR\n      const s =\n        match && match.sigs && match.sigs[name]\n          ? (match.sigs[name] as Signal<any>)\n          : (createSignal(val) as Signal<any>);\n      parentStep.state.sigs[name] = s;\n      return s;\n    },\n    computedSignal(name: string, wire) {\n      const match = getTreeStepRenderContextState(renderContext, parentStep);\n\n      // this enables state preservation during HMR\n      const s =\n        match && match.sigs && match.sigs[name]\n          ? (match.sigs[name] as Signal<any>)\n          : (createComputedSignal(wire) as Signal<any>);\n      parentStep.state.sigs[name] = s;\n      return s;\n    },\n    wire(arg) {\n      const w = createWire(arg);\n      parentStep.wires?.push(w);\n      return w;\n    },\n    store(name: string, val) {\n      const match = getTreeStepRenderContextState(renderContext, parentStep);\n\n      // HMR\n      const s =\n        match && match.stores && match.stores[name]\n          ? (match.stores[name] as StoreCursor)\n          : (createStore(val) as StoreCursor);\n      parentStep.state.stores[name] = s;\n      return s as StoreCursor<any>;\n    },\n    setContext(ctx, value?) {\n      parentStep.state.ctx.set(ctx, value || createSignal(undefined));\n    },\n    getContext: (token) => {\n      //console.time(\"ctx\");\n      const ancestor = parentStep && getContextProvider(token, parentStep);\n      //console.timeEnd(\"ctx\");\n      if (ancestor && ancestor.type === DOMConstants.ComponentTreeStep) {\n        return ancestor.state.ctx.get(token);\n      } else {\n        //console.error(token, parentStep);\n        //throw createError(103, `${token.sym.toString()} not found`);\n      }\n    },\n    onUnmount: (cb) => {\n      (parentStep as ComponentTreeStep).onUnmount.push(cb);\n    },\n    onMount: (cb) => {\n      (parentStep as ComponentTreeStep).onMount.push(cb);\n    },\n    api: {\n      insert: insertElement.bind(null, renderContext, parentStep),\n      remove: removeElement.bind(null, renderContext, parentStep),\n      update: updateElement.bind(null, renderContext, parentStep),\n    },\n  };\n};\n","import { StoreManager, Wire, wireReset } from \"../core/state\";\nimport * as DOMConstants from \"../dom/constants\";\nimport { getCursorProxyMeta } from \"../utils\";\nimport { getRenderContext, renderTreeStep, rmNodes } from \"./api\";\nimport type {\n  GenericEventAttrs,\n  HTMLAttrs,\n  HTMLElements,\n  SVGAttrs,\n  SVGElements,\n} from \"./jsx\";\nimport {\n  Component,\n  ComponentUtils,\n  ComponentVElement,\n  Context,\n  NativeVElement,\n  RenderContext,\n  TreeStep,\n  VElement,\n} from \"./types\";\n\nexport {\n  addNode,\n  insertElement,\n  removeElement,\n  removeNode,\n  updateElement,\n} from \"./api\";\nexport * as DOMConstants from \"./constants\";\nexport { reifyTree } from \"./traverser\";\nexport * from \"./types\";\nexport { h };\n\nexport function defineContext<T = any>(arg?: string): Context<T> {\n  return {\n    sym: Symbol(arg),\n  };\n}\n\nexport function component<T = any>(\n  name: string,\n  def: {\n    (props: T, helpers: ComponentUtils): VElement;\n  }\n): Component<T> {\n  (def as Component<T>).__name__ = name;\n  return def as Component<T>;\n}\n\nfunction h(\n  t: string | Component<any>,\n  p?: any,\n  ...children: VElement[]\n): VElement {\n  const props = {\n    ...(p || {}),\n    children: [...(children || [])].map((el) => el),\n  };\n  return {\n    type: typeof t === \"string\" ? DOMConstants.NATIVE : DOMConstants.COMPONENT,\n    p: props,\n    t: t,\n  } as ComponentVElement | NativeVElement;\n}\n\nexport function render(\n  element: VElement,\n  container: HTMLElement,\n  options = {}\n) {\n  const renderContext = getRenderContext(container, element, (options = {}));\n  //console.log(\"root\", renderContext);\n  renderTreeStep(renderContext, element);\n  return renderContext;\n}\n\nexport const unmount = (step: TreeStep) => {\n  if (step.dom) rmNodes(step.dom);\n};\n\nexport function unrender(arg: RenderContext | TreeStep[]) {\n  const steps = Array.isArray(arg) ? arg : Array.from(arg.reg);\n  steps.forEach((step) => {\n    unmount(step);\n    if (step.type == DOMConstants.ComponentTreeStep) {\n      step.wires.forEach((w) => {\n        wireReset(w);\n      });\n      step.wires = [];\n      Object.values(step.state.stores).forEach((s) => {\n        const manager = getCursorProxyMeta<StoreManager>(s as any);\n        manager.tasks.clear();\n        manager.w.clear();\n        // manager.unsubscribe();\n      });\n      step.onUnmount.forEach((el) => el(step));\n      // step.state.stores = {};\n      Object.values(step.state.sigs).forEach((sig) => {\n        sig.w.clear();\n      });\n      step.state.ctx.clear();\n    } else if (step.type == DOMConstants.WireTreeStep) {\n      const wire = step.node as Wire;\n      wireReset(wire);\n    }\n  });\n  return arg;\n}\n\n// used to store parent wire in context\nexport const ParentWireContext = defineContext(\"ParentWireContext\");\n\nexport const Fragment = component(\"Fragment\", (props) => props.children);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype DistributeWire<T> = T extends any ? Wire<T> : never;\nexport type MaybeWire<T> = T | DistributeWire<T>;\n\nexport declare namespace h {\n  export namespace JSX {\n    export type AllowWireForProperties<T> = { [K in keyof T]: MaybeWire<T[K]> };\n\n    export type Element = VElement;\n\n    export interface ElementAttributesProperty {\n      props: unknown;\n    }\n    export interface ElementChildrenAttribute {\n      children: unknown;\n    }\n\n    // Prevent children on components that don't declare them\n    export interface IntrinsicAttributes {\n      children?: VElement[] | VElement;\n      key?: string | number;\n      ref?: (el: any) => void;\n    }\n\n    // Allow children on all DOM elements (not components, see above)\n    // ESLint will error for children on void elements like <img/>\n    export type DOMAttributes<Target extends EventTarget> =\n      GenericEventAttrs<Target> & {};\n\n    export type HTMLAttributes<Target extends EventTarget> =\n      AllowWireForProperties<Omit<HTMLAttrs, \"style\">> & {\n        style?: MaybeWire<string>;\n      } & DOMAttributes<Target> &\n        IntrinsicAttributes;\n\n    export type SVGAttributes<Target extends EventTarget> =\n      AllowWireForProperties<SVGAttrs> &\n        HTMLAttributes<Target> &\n        IntrinsicAttributes;\n\n    export type IntrinsicElements = {\n      [El in keyof HTMLElements]: HTMLAttributes<HTMLElements[El]>;\n    } & { [El in keyof SVGElements]: SVGAttributes<SVGElements[El]> };\n  }\n}\n","/** @jsx h **/\n\nimport {\n  SubToken,\n  StoreCursor,\n  StoreManager,\n  StoreChange,\n  ArrayOrObject,\n  ExtractElement,\n} from \"../../core/state\";\nimport { h, component, Fragment } from \"../../dom/index\";\nimport { ComponentUtils, VElement } from \"../../dom/types\";\nimport { ParentWireContext } from \"../../dom/index\";\nimport { META_FLAG, ObjPathProxy, getCursor } from \"../../utils/index\";\nimport { TreeStep } from \"../../dom/types\";\nimport { getUtils, addNode, removeNode } from \"../../dom/api\";\nimport { reifyTree, getTreeStep } from \"../../dom/traverser\";\nimport { getValueUsingPath } from \"../../utils/index\";\nimport { createError } from \"../../dom/utils\";\n\nexport const Each: <T extends ArrayOrObject>(\n  props: {\n    cursor: StoreCursor<T>;\n    renderItem: (\n      item: () => ExtractElement<T>,\n      index: number | string,\n      list: T\n    ) => VElement;\n  },\n  utils: ComponentUtils\n) => VElement = component(\n  \"Each\",\n  (\n    props,\n    {\n      wire,\n      setContext,\n      signal,\n      utils,\n      step: parentStep,\n      renderContext,\n      onMount,\n      onUnmount,\n    }\n  ) => {\n    const listCursor = props.cursor;\n    const store: StoreManager = (listCursor as any)[META_FLAG];\n    const listCursorPath: string[] = getCursor(listCursor);\n    //    console.log(\"Each\", listCursorPath);\n\n    const listValue: typeof listCursor = getValueUsingPath(\n      store.v as any,\n      listCursorPath\n    ) as typeof listCursor;\n    //console.log(\"value\", value);\n    const isArray = Array.isArray(listValue);\n    if (!isArray) throw createError(110);\n\n    const getItemCursor = (item: ExtractElement<typeof listCursor>) => {\n      const store: StoreManager = (listCursor as any)[META_FLAG];\n      const listValue: typeof listCursor = getValueUsingPath(\n        store.v as any,\n        listCursorPath\n      ) as typeof listCursor;\n      //      console.log(\"listValue\", listValue, item);\n      const index = listValue.indexOf(item);\n      if (index > -1) {\n        return props.cursor[index];\n      } else {\n        // debugger;\n      }\n    };\n\n    const observor = function (change: StoreChange) {\n      const { data, path, value } = change;\n      //console.log(\"Each list change\", change, listCursorPath, path);\n      const pStep = parentStep.k[0];\n      const previousChildren = [...(pStep.k || [])];\n      // list reset\n      if (listCursorPath.join() === path.join() && !data) {\n        previousChildren.forEach((node) => {\n          removeNode(renderContext, node);\n        });\n        const startIndex = 0;\n        (value as typeof props.cursor).forEach((item, index) => {\n          const previousChildren = [...(pStep.k || [])];\n          const [treeStep, el] = renderArray(\n            pStep,\n            props.renderItem,\n            listCursor,\n            value,\n            index,\n            utils,\n            getItemCursor\n          );\n          const [registry, root] = reifyTree(renderContext, el, pStep);\n          const before = previousChildren[startIndex + index] || null;\n          addNode(renderContext, pStep, root, before);\n        });\n        return;\n      }\n\n      // important\n      // filter changes so you don't try to render invalid changes\n\n      if (path.slice(0, listCursorPath.length).join(\"/\") !== path.join(\"/\"))\n        return;\n      //      console.log(\"each\", change, listCursorPath);\n      if (data?.name === \"push\") {\n        //        console.log(\"data\", data);\n        data.args.forEach((arg, i) => {\n          const index = previousChildren.length + i;\n          const [treeStep, el] = renderArray(\n            pStep,\n            props.renderItem,\n            listCursor,\n            value,\n            index,\n            utils,\n            getItemCursor\n          );\n          // console.log({ treeStep, el, index, previousChildren });\n          const [registry, root] = reifyTree(renderContext, el, pStep);\n          addNode(renderContext, pStep, root);\n        });\n      } else if (data?.name === \"pop\") {\n        if (previousChildren.length > 0) {\n          const lastNode = previousChildren[previousChildren.length - 1];\n          removeNode(renderContext, lastNode);\n        }\n      } else if (data?.name === \"splice\") {\n        const args = data.args as [string, string];\n        const startIndex = parseInt(args[0]);\n        const deleteCount = parseInt(args[1]);\n        const [_, __, ...items] = data.args as [string, number, ...any];\n        const nodesToRemove = previousChildren.slice(\n          startIndex,\n          startIndex + deleteCount\n        );\n\n        //        console.log(\n        //          \"Each nodesToRemove\",\n        //          previousChildren,\n        //          nodesToRemove,\n        //          data\n        //        );\n\n        // Remove the nodes that are being spliced out\n        nodesToRemove.forEach((n) => removeNode(renderContext, n));\n\n        // Add the new nodes being spliced in\n        items.forEach((item, i) => {\n          const index = startIndex + i;\n          const previousChildren = [...(pStep.k || [])];\n          const [treeStep, el] = renderArray(\n            pStep,\n            props.renderItem,\n            listCursor,\n            value,\n            index,\n            utils,\n            getItemCursor\n          );\n          const [registry, root] = reifyTree(renderContext, el, pStep);\n          const before = previousChildren[startIndex + i] || null;\n          addNode(renderContext, pStep, root, before);\n        });\n      }\n    };\n    const task = { path: listCursorPath, observor };\n    onMount(() => {\n      store.tasks.add(task);\n    });\n    onUnmount(() => {\n      store.tasks.delete(task);\n    });\n\n    return (\n      <Fragment>\n        {listValue.map((el, index) => {\n          const cursor = getItemCursor.bind(null, el as any) as any;\n          return props.renderItem(cursor, index, listCursor);\n        })}\n      </Fragment>\n    );\n  }\n);\n\nconst renderArray = (\n  parentStep: TreeStep,\n  renderItem: Function,\n  cursor: any,\n  list: any[],\n  index: number,\n  utils: ComponentUtils,\n  getItemCursor: Function\n) => {\n  // console.log(getCursor(cursor));\n  const vEl = renderItem(getItemCursor.bind(null, list[index]), index);\n  const treeStep = getTreeStep(parentStep, undefined, vEl);\n  return [treeStep, vEl];\n};\n","/** @jsx h **/\n\nimport { h, component } from \"../../dom\";\nimport { rmNodes } from \"../../dom/api\";\nimport { ComponentTreeStep, VElement } from \"../../dom/types\";\n\nexport type PortalProps = {\n  mount?: HTMLElement;\n  children: VElement;\n};\n\nexport const Portal = component<PortalProps>(\n  \"Portal\",\n  (props, { onUnmount, step: parentStep }) => {\n    onUnmount((step: any) => {\n      if (step && step.dom) rmNodes(step.dom);\n    });\n    (parentStep as ComponentTreeStep).mount = props.mount;\n    return props.children;\n  }\n);\n","/** @jsx h **/\n\nimport { SubToken } from \"../../core/state\";\nimport { h, component } from \"../../dom\";\nimport { VElement } from \"../../dom/types\";\nimport { ParentWireContext } from \"../../dom/index\";\nimport { addNode, removeNode } from \"../../dom/api\";\nimport { reifyTree } from \"../../dom/traverser\";\n\nexport type WhenViews =\n  | Record<string, () => VElement>\n  | ((value: any) => VElement);\nexport type WhenProps = {\n  condition: ($: SubToken) => any;\n  views: WhenViews;\n  fallback?: () => VElement;\n  options?: { cached?: boolean };\n  key?: string;\n};\n\nexport const When = component<WhenProps>(\n  \"When\",\n  (props, { utils, onUnmount, onMount, step: parentStep, renderContext }) => {\n    const underlying = utils.wire(props.condition);\n    const value = underlying.run();\n    const getView = (value: any) => {\n      if (typeof props.views === \"function\") {\n        return () => (props.views as Function)(value);\n      } else {\n        const view = props.views[value as unknown as any];\n        return view || props.fallback;\n      }\n    };\n    const task = (value: any) => {\n      const view = getView(value);\n      const u = view ? view() : null;\n      const previousChildren = [...parentStep.k];\n      const [registry, root] = reifyTree(renderContext, u, parentStep);\n      addNode(renderContext, parentStep, root);\n      for (var n of previousChildren) {\n        removeNode(renderContext, n);\n      }\n    };\n    onMount(() => {\n      underlying.tasks.add(task);\n    });\n    onUnmount(() => {\n      underlying.tasks.delete(task);\n    });\n    const view = getView(value);\n    return view ? view() : null;\n  }\n);\n"]}