{"version":3,"file":"shims.cjs","names":[],"sources":["../src/shims/index.ts"],"sourcesContent":["/**\n * Runtime-binding shims — use `@nhtio/adk` (or any bundle) WITHOUT importing it into your module\n * graph.\n *\n * @module @nhtio/adk/shims\n *\n * @remarks\n * ## Why this exists\n *\n * Most consumers `import` the ADK directly and let the bundler wire it in. Some cannot: importing\n * ADK **source** eagerly evaluates its entire module graph, and on constrained runtimes that eager\n * evaluation is itself a problem — the motivating case is this repository's own docs site, which\n * hand-rolled this exact pattern four times (~590 lines, one drifting hand-maintained manifest type\n * per copy) after discovering that importing `@nhtio/adk` into the VitePress app's graph overflowed\n * the JS call stack on iOS WebKit (\"Maximum call stack size exceeded\") — see\n * `docs/.vitepress/repl/index.ts` for the full account of that failure and the compiled-bundle\n * workaround it settled on. The same shape recurs anywhere a module must reference ADK types and\n * values without eagerly linking to an ADK build at import time: CDN / no-bundler pages, Worker\n * threads, plugin systems that inject a host-provided implementation, code-split lazy chunks, and\n * version hot-swap (retiring one loaded bundle for another without reloading every importer).\n *\n * This module ships the **mechanism** those call sites all rediscover independently — a resolver\n * seam plus a memoizing handle — and nothing else. It has no opinion on *how* you load a bundle\n * (`fetch` + dynamic `import()`, a bundler-native `import()`, a Worker `postMessage` handshake, a\n * host-injected global); that policy is entirely yours, supplied as a single function.\n *\n * ## The pattern\n *\n * You hand {@link createAdkShim} an {@link AdkResolverFn} — a zero-argument function that produces\n * your bundle, synchronously or asynchronously. The returned {@link AdkShim} gives you four ways to\n * consume it:\n *\n * - `await shim.resolve()` — the async, always-correct path. Single-flight: concurrent callers\n *   during an in-flight resolution share one resolver invocation, not one each.\n * - `shim.get()` — the sync path, for code that has already awaited `resolve()` at least once\n *   and now wants to read the bundle without re-awaiting. Throws\n *   {@link E_SHIM_NOT_RESOLVED} if nothing is resolved yet.\n * - `shim.proxy` — a `Proxy<TBundle>` that transparently delegates every property read to the\n *   resolved bundle once one exists, and throws {@link E_SHIM_NOT_RESOLVED} (naming the exact\n *   property that was touched) if read too early. This directly replaces the `export let Foo:\n *   typeof AdkModule.Foo` holder pattern the docs app hand-wrote per symbol — one `proxy` object\n *   stands in for the whole bundle's worth of holders, and destructuring `const { Foo } =\n *   shim.proxy` reads through it exactly the same way a real module namespace would.\n * - `shim.resolved` — a live boolean for \"is there currently a dereferenceable bundle\", for call\n *   sites that want to branch without risking a throw.\n *\n * ## API CONTRACT: importing this module evaluates essentially nothing\n *\n * `@nhtio/adk/shims` is a **leaf**: aside from {@link createException} (used only to mint the three\n * exception classes below, and itself graph-free — see the note at the bottom of this remarks\n * block), it has zero runtime imports from the rest of the ADK. Every ADK *type* used here —\n * {@link AdkNamespace} — is an erased `typeof import(...)` type query, which the compiler discards\n * entirely; it costs nothing at runtime and pulls in no value bindings. `import * as shims from\n * '@nhtio/adk/shims'` therefore does not construct a single ADK class, does not touch a single\n * battery, and cannot itself be the thing that overflows a call stack. That is the entire point:\n * this module is safe to import eagerly from anywhere — including the eager, top-of-file position\n * a `resolve()`-calling module needs — precisely because it never touches the graph it is a seam\n * for.\n *\n * ## Why `shims` is NOT re-exported from the root `@nhtio/adk` barrel\n *\n * Root-barrel re-export would defeat the entire purpose. If `@nhtio/adk/shims` were exported from\n * `@nhtio/adk` itself, then `import { createAdkShim } from '@nhtio/adk'` would drag in the very\n * module graph this subpath exists to let you avoid — you cannot get \"a seam for deferring ADK's\n * import\" without importing ADK. Keeping `shims` a sibling **subpath**, never re-exported upward,\n * is what lets a leaf-conscious consumer write `import { createAdkShim } from '@nhtio/adk/shims'`\n * and mean it.\n *\n * ## GC-safe memoization\n *\n * A resolved bundle is held via `WeakRef` (constraining `TBundle extends object`, since only\n * objects are valid `WeakRef` targets) — never strongly retained by the shim itself, so a shim you\n * hold onto cannot alone keep an entire ADK bundle (and everything it closes over) alive forever.\n * Only the in-flight resolution *promise* is held strongly, and only for the duration of that one\n * flight. If the bundle is collected (or, for a resolver like the canonical dynamic-import one, was\n * never going to be collected in practice — the JS module registry itself caches an imported module\n * strongly for the life of the realm; the `WeakRef` here only releases the *shim's own handle* to\n * it), the shim degrades predictably:\n *\n * - `resolved` reports `false`.\n * - `get()` and `proxy` property reads throw {@link E_SHIM_NOT_RESOLVED}.\n * - `resolve()` transparently re-invokes the resolver (idempotent for the dynamic-import case —\n *   re-`import()`-ing an already-loaded module resolves instantly from the registry cache — and a\n *   correctness requirement for any other resolver you supply, since this path can legitimately\n *   run twice).\n *\n * Long-lived synchronous consumers — anything that reads `get()` / `proxy` on a timer or from an\n * event handler without ever `await`-ing `resolve()` again — should either hold their own strong\n * reference to the value they read out of the bundle, or re-`await resolve()` before each sync\n * read, rather than assuming a resolved bundle stays resolved indefinitely.\n *\n * Environments without `WeakRef` (checked once, with `typeof WeakRef === 'function'`, at\n * {@link createAdkShim} construction time) fall back to an ordinary strong reference for that\n * shim's lifetime — documented behavior, not a silent downgrade: such a shim's bundle lives as long\n * as the shim does.\n *\n * ## Example resolvers (illustrative only — this module ships no loading policy)\n *\n * URL dynamic-import, guarded against SSR (mirrors the docs app's real loader):\n * ```ts\n * const shim = createAdkShim(() => {\n *   if (typeof window === 'undefined') {\n *     throw new Error('this bundle is client-only (no SSR)')\n *   }\n *   const url = new URL('/repl/adk-repl.es.js', window.location.origin).href\n *   return import(/* @vite-ignore *\\/ url)\n * })\n * ```\n *\n * Same-graph passthrough (no deferral at all — useful as a drop-in when the caller doesn't need\n * one, e.g. tests):\n * ```ts\n * const shim = createAdkShim(() => import('@nhtio/adk'))\n * ```\n *\n * Worker / plugin injection sketch (the resolver awaits a handshake instead of an import):\n * ```ts\n * const shim = createAdkShim(\n *   () => new Promise((resolvePromise) => {\n *     worker.postMessage({ type: 'request-adk-bundle' })\n *     worker.addEventListener('message', function onMsg(e) {\n *       if (e.data?.type !== 'adk-bundle') return\n *       worker.removeEventListener('message', onMsg)\n *       resolvePromise(e.data.bundle)\n *     })\n *   })\n * )\n * ```\n *\n * ## `TBundle` is a compile-time contract, not a runtime guarantee\n *\n * The generic `TBundle` you supply to {@link createAdkShim} (or, at the ambient\n * {@link registerAdkResolver} / {@link adk} call sites, the default `AdkNamespace`) tells the\n * compiler what shape to expect back from your resolver — it performs no runtime validation of the\n * value your resolver actually produces. Getting this contract right is on you, exactly as it would\n * be for a real `import` statement whose resolved module happens not to match its `.d.ts`. Compose\n * it with `&` when your resolver's bundle carries more than the root namespace, e.g. a battery\n * bundled alongside core:\n * ```ts\n * type MyBundle = AdkNamespace & typeof import('@nhtio/adk/batteries/context/thrift')\n * const shim = createAdkShim<MyBundle>(() => loadMyPrecompiledBundle())\n * ```\n *\n * ## A note on `createException`'s own leaf-ness\n *\n * `createException`'s import closure was verified (not assumed) to be graph-free before this module\n * was written: `../lib/utils/exceptions` imports only `./validation` (which imports only\n * `../classes/base_exception` + the external `@nhtio/validation` package), the external\n * `@nhtio/validation` package itself, the external `fast-printf` package, and\n * `../classes/base_exception` directly (which imports nothing at all). None of those files reach\n * into `lib/contracts`, `lib/classes` beyond `base_exception`, `batteries`, or any other part of the\n * ADK's runtime graph — so importing it here does not compromise this module's leaf guarantee.\n */\n\nimport { createException } from '../lib/utils/exceptions'\nimport type * as AdkNamespaceModule from '../index'\n\n/**\n * Erased, type-only alias for the full `@nhtio/adk` root namespace. Declared via a top-of-file\n * `import type * as` (rather than an inline `typeof import(...)` type query) so it is a single,\n * lintable reference — but it is exactly as free at runtime either way: a type-only import is\n * erased entirely, no value import is emitted for it, which is what makes it safe to use as the\n * default `TBundle` throughout this module without compromising the leaf guarantee documented\n * above.\n */\ntype AdkNamespace = typeof AdkNamespaceModule\n\n/**\n * Thrown when {@link AdkShim.get} or a {@link AdkShim.proxy} property read is attempted before the\n * shim has a dereferenceable bundle — either because {@link AdkShim.resolve} has never been awaited\n * to completion, or because a previously resolved bundle's `WeakRef` has since been garbage\n * collected. The message names the exact accessor that triggered the throw (`\"get()\"` for the\n * `get()` method itself, or the property name for a `proxy` read) so the failure points straight at\n * the offending call site.\n *\n * @remarks\n * Recoverable by the caller: `await shim.resolve()` (or re-register a resolver and resolve, for the\n * ambient {@link adk} shim) and retry the sync read.\n */\nexport const E_SHIM_NOT_RESOLVED = createException<[string]>(\n  'E_SHIM_NOT_RESOLVED',\n  'Cannot access \"%s\" on this ADK shim: it has no resolved bundle right now (either resolve() has ' +\n    'never completed, or the previously resolved bundle was garbage collected). Await ' +\n    'shim.resolve() before reading synchronously via get() or proxy.',\n  'E_SHIM_NOT_RESOLVED',\n  425,\n  true\n)\n\n/**\n * Thrown when an {@link AdkResolverFn} rejects (or throws synchronously). The original failure is\n * preserved on `.cause` so callers can inspect the underlying reason (a failed `fetch`, a malformed\n * bundle, a Worker handshake that never completed, …); the message additionally embeds its `.message`\n * for log lines that only surface the top-level error.\n *\n * @remarks\n * Non-fatal by design: a resolver failure is an environmental/runtime condition (a bad network, a\n * missing asset, an unregistered ambient resolver), not a programming error, and the memo is cleared\n * on this path — the very next {@link AdkShim.resolve} call re-invokes the resolver and can still\n * succeed. The ambient {@link adk} shim raises this same exception, with a distinct cause message,\n * when {@link AdkShim.resolve} is called before any {@link registerAdkResolver} registration.\n */\nexport const E_SHIM_RESOLUTION_FAILED = createException<[string]>(\n  'E_SHIM_RESOLUTION_FAILED',\n  'The registered resolver failed to produce a bundle: %s',\n  'E_SHIM_RESOLUTION_FAILED',\n  500,\n  false\n)\n\n/**\n * Thrown by {@link registerAdkResolver} when it is called again after the ambient {@link adk} shim\n * has already resolved once successfully.\n *\n * @remarks\n * This is a split-brain guard, not a general \"can't change your mind\" restriction: re-registering\n * a resolver **before** the first successful resolution silently overwrites the previous\n * registration (last writer wins, no throw) — that path is expected during application bootstrap,\n * where a resolver might be registered speculatively and then replaced before anything ever reads\n * `adk`. Once a real bundle has been handed out through the ambient shim, though, swapping the\n * resolver underneath already-resolved consumers risks two different call sites silently observing\n * two different ADK builds through the same shared `adk` handle — a bug that is far harder to\n * diagnose than a loud, immediate throw at the mis-timed `registerAdkResolver` call site. If you\n * need a second, independently swappable binding, construct a fresh {@link createAdkShim} instance\n * instead of trying to repoint the ambient one.\n */\nexport const E_SHIM_RESOLVER_ALREADY_RESOLVED = createException(\n  'E_SHIM_RESOLVER_ALREADY_RESOLVED',\n  'registerAdkResolver() was called after the ambient `adk` shim already resolved once. ' +\n    'Re-registering post-resolution risks a split-brain state where different call sites observe ' +\n    'different bundles through the same shared handle. Construct a fresh createAdkShim() instance ' +\n    'instead if you need an independently swappable resolver.',\n  'E_SHIM_RESOLVER_ALREADY_RESOLVED',\n  409,\n  true\n)\n\n/**\n * The seam: a zero-argument, consumer-supplied function that produces the bundle a shim wraps,\n * synchronously or asynchronously. All environment-specific loading knowledge — where the bundle\n * lives, how it's fetched, whether it's cached upstream — lives inside this one function; the shim\n * itself is entirely agnostic to how `TBundle` gets produced.\n *\n * @typeParam TBundle - The shape of the value this resolver produces. Defaults to\n *   {@link AdkNamespace} (the full `@nhtio/adk` root namespace) since that is the motivating case,\n *   but any object shape works — see {@link createAdkShim}'s battery-intersection example.\n * @returns The bundle, or a `Promise` of it. Rejecting (or throwing synchronously) surfaces as\n *   {@link E_SHIM_RESOLUTION_FAILED} from the owning shim's `resolve()`.\n */\nexport type AdkResolverFn<TBundle = AdkNamespace> = () => TBundle | Promise<TBundle>\n\n/**\n * A memoizing handle over a lazily-resolved bundle, returned by {@link createAdkShim}. See the\n * module-level remarks for the full GC-safety contract and the rationale for each accessor.\n *\n * @typeParam TBundle - The shape of the wrapped bundle. Must extend `object` — only objects are\n *   valid `WeakRef` targets, and this shim's memoization relies on `WeakRef` where available.\n */\nexport interface AdkShim<TBundle extends object> {\n  /**\n   * Resolve the bundle, awaiting the underlying {@link AdkResolverFn} if necessary.\n   *\n   * @remarks\n   * Single-flight: if a resolution is already in progress, concurrent callers share that one\n   * in-flight promise rather than triggering a second resolver invocation. Already-resolved calls\n   * (including after re-resolving following a garbage-collected memo) return the cached bundle via\n   * an already-settled promise without touching the resolver at all.\n   *\n   * @returns A promise settling with the resolved bundle.\n   * @throws {@link E_SHIM_RESOLUTION_FAILED} if the resolver rejects or throws. The memo is cleared\n   *   on this path, so a subsequent call re-invokes the resolver.\n   */\n  resolve(): Promise<TBundle>\n  /**\n   * Synchronously read the currently resolved bundle.\n   *\n   * @remarks\n   * For code that has already `await`-ed {@link resolve} at least once (directly, or transitively\n   * via something that did) and now wants to read the bundle without paying for another `await`.\n   * There is no synchronous equivalent of running an async resolver — if nothing is resolved yet\n   * (or the memo was garbage collected), this throws rather than blocking or returning a stale\n   * value.\n   *\n   * @returns The resolved bundle.\n   * @throws {@link E_SHIM_NOT_RESOLVED} if there is no currently dereferenceable bundle.\n   */\n  get(): TBundle\n  /**\n   * `true` when the bundle is currently dereferenceable (resolved, and — where `WeakRef` is\n   * available — not yet garbage collected). Live: re-evaluated on every read, so this can flip from\n   * `true` back to `false` between two reads with no code in between, if the collector runs.\n   */\n  readonly resolved: boolean\n  /**\n   * A `Proxy<TBundle>` that delegates every property read to the resolved bundle. Reading a\n   * property before anything has resolved (or after the memo has been collected) throws\n   * {@link E_SHIM_NOT_RESOLVED} naming the exact property that was touched, instead of returning\n   * `undefined` — the failure points at the call site instead of surfacing as a confusing\n   * \"cannot call undefined\" a few frames later.\n   *\n   * @remarks\n   * Bound function properties: reading a method off `proxy` returns it pre-bound to the resolved\n   * bundle, so `const { foo } = shim.proxy; foo()` behaves the same as `shim.get().foo()` — you can\n   * destructure without losing `this`. This is the direct replacement for the hand-rolled `export\n   * let Foo: typeof AdkModule.Foo` holder pattern: one `proxy` stands in for an entire bundle's\n   * worth of individually-declared holders, populated the same way (assign real values once\n   * resolved) but without the drift risk of hand-maintaining one `let` per symbol.\n   */\n  readonly proxy: TBundle\n}\n\n/**\n * Construct a new {@link AdkShim} around a resolver.\n *\n * @remarks\n * Every call returns an independent shim with its own private memoization state — nothing is\n * shared between instances, and constructing one never invokes `resolveFn` eagerly (resolution\n * happens lazily, on first {@link AdkShim.resolve} call). Use this directly when you want a scoped,\n * non-ambient binding (e.g. one shim per loaded plugin version); use {@link registerAdkResolver} /\n * {@link adk} instead for the \"one shared binding used across many files\" ergonomics the docs app's\n * flagship agent needs.\n *\n * @typeParam TBundle - The shape of the bundle this shim wraps. Defaults to {@link AdkNamespace}.\n * @param resolveFn - The resolver this shim wraps. See {@link AdkResolverFn} and the module-level\n *   `@example` fences for the supported shapes (URL dynamic-import, same-graph passthrough, Worker\n *   handshake).\n * @returns A new, independently-memoized {@link AdkShim}.\n *\n * @example\n * Composing a battery into the resolved shape (the \"battery-intersection\" recipe):\n * ```ts\n * type MyBundle = AdkNamespace & typeof import('@nhtio/adk/batteries/context/thrift')\n * const shim = createAdkShim<MyBundle>(() => loadMyPrecompiledBundle())\n * const { subtractToFit } = await shim.resolve()\n * ```\n */\nexport function createAdkShim<TBundle extends object = AdkNamespace>(\n  resolveFn: AdkResolverFn<TBundle>\n): AdkShim<TBundle> {\n  // Captured once at construction (not re-checked per call) so a shim's GC-safety strategy is fixed\n  // for its lifetime, and so tests can deterministically stub the global before constructing a shim.\n  const WeakRefCtor: typeof WeakRef | undefined =\n    typeof WeakRef === 'function' ? WeakRef : undefined\n\n  let weakRef: WeakRef<TBundle> | undefined\n  let strongRef: TBundle | undefined\n  let inFlight: Promise<TBundle> | null = null\n\n  const peek = (): TBundle | undefined => {\n    return WeakRefCtor ? weakRef?.deref() : strongRef\n  }\n\n  const remember = (bundle: TBundle): void => {\n    if (WeakRefCtor) {\n      weakRef = new WeakRefCtor(bundle)\n    } else {\n      strongRef = bundle\n    }\n  }\n\n  const resolve = (): Promise<TBundle> => {\n    const cached = peek()\n    if (cached !== undefined) {\n      return Promise.resolve(cached)\n    }\n    if (inFlight) {\n      return inFlight\n    }\n    const attempt: Promise<TBundle> = Promise.resolve()\n      .then(() => resolveFn())\n      .then(\n        (bundle) => {\n          inFlight = null\n          remember(bundle)\n          return bundle\n        },\n        (err: unknown) => {\n          inFlight = null\n          // Leaf module (src/shims): importing ../lib/utils/guards for isError() would add a\n          // second value import, breaking the zero-runtime-import leaf contract this module\n          // documents and its spec enforces.\n          // eslint-disable-next-line adk/prefer-is-error -- see comment above\n          const reason = err instanceof Error ? err.message : String(err)\n          throw new E_SHIM_RESOLUTION_FAILED([reason], { cause: err })\n        }\n      )\n    inFlight = attempt\n    return attempt\n  }\n\n  const get = (): TBundle => {\n    const cached = peek()\n    if (cached === undefined) {\n      throw new E_SHIM_NOT_RESOLVED(['get()'])\n    }\n    return cached\n  }\n\n  const proxy = new Proxy({} as TBundle, {\n    get(_target, prop) {\n      const cached = peek()\n      if (cached === undefined) {\n        throw new E_SHIM_NOT_RESOLVED([String(prop)])\n      }\n      const value = Reflect.get(cached as object, prop)\n      return typeof value === 'function' ? value.bind(cached) : value\n    },\n  }) as TBundle\n\n  return {\n    resolve,\n    get,\n    get resolved(): boolean {\n      return peek() !== undefined\n    },\n    proxy,\n  }\n}\n\n// ── Ambient registry ──────────────────────────────────────────────────────────\n//\n// Module-scope ergonomics for the \"many files, one shared binding\" case (the flagship agent's\n// docs/.vitepress/theme/components/agent/agent_adk.ts use-case): every file imports the same `adk`\n// value instead of each constructing (and separately resolving) its own shim.\n\nlet registeredResolver: AdkResolverFn<AdkNamespace> | null = null\nlet ambientResolvedOnce = false\n\n/**\n * Register (or replace) the resolver the ambient {@link adk} shim delegates to.\n *\n * @remarks\n * Call once, early, before anything reads {@link adk}. Re-registering **before** the ambient shim's\n * first successful resolution silently overwrites the previous registration — the newest call wins,\n * no throw, no warning; this is the expected shape for a speculative registration made during\n * bootstrap that gets superseded before anything actually resolves. Re-registering **after** the\n * first successful resolution throws {@link E_SHIM_RESOLVER_ALREADY_RESOLVED} — see that\n * exception's docs for why swapping resolvers under already-resolved consumers is treated as a\n * hard error rather than a silent replace.\n *\n * @typeParam TBundle - The shape the supplied resolver produces. Defaults to {@link AdkNamespace}.\n * @param resolver - The resolver {@link adk} will delegate to going forward.\n * @throws {@link E_SHIM_RESOLVER_ALREADY_RESOLVED} if the ambient shim already resolved once.\n */\nexport function registerAdkResolver<TBundle extends object = AdkNamespace>(\n  resolver: AdkResolverFn<TBundle>\n): void {\n  if (ambientResolvedOnce) {\n    throw new E_SHIM_RESOLVER_ALREADY_RESOLVED()\n  }\n  registeredResolver = resolver as unknown as AdkResolverFn<AdkNamespace>\n}\n\n/**\n * The ambient, module-scope {@link AdkShim} instance. Delegates to whatever resolver was last\n * passed to {@link registerAdkResolver} — resolving before any registration raises\n * {@link E_SHIM_RESOLUTION_FAILED} with a cause explaining that no resolver has been registered yet.\n *\n * @remarks\n * Use this when many files across a module graph want to share one binding (import `adk` and read\n * `adk.proxy` / `await adk.resolve()` from anywhere) rather than threading a shim instance through\n * every call site. For an independent, separately-resolvable binding — e.g. loading two different\n * bundle versions side by side — construct your own via {@link createAdkShim} instead.\n */\nexport const adk: AdkShim<AdkNamespace> = createAdkShim<AdkNamespace>(async () => {\n  if (!registeredResolver) {\n    throw new Error(\n      'No resolver has been registered for the ambient `adk` shim. Call registerAdkResolver(resolve) ' +\n        'before adk.resolve(), adk.get(), or reading adk.proxy.'\n    )\n  }\n  const bundle = await registeredResolver()\n  ambientResolvedOnce = true\n  return bundle\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmLA,IAAa,sBAAsB,mBAAA,gBACjC,uBACA,qPAGA,uBACA,KACA,IACF;;;;;;;;;;;;;;AAeA,IAAa,2BAA2B,mBAAA,gBACtC,4BACA,0DACA,4BACA,KACA,KACF;;;;;;;;;;;;;;;;;AAkBA,IAAa,mCAAmC,mBAAA,gBAC9C,oCACA,0UAIA,oCACA,KACA,IACF;;;;;;;;;;;;;;;;;;;;;;;;;;AAqGA,SAAgB,cACd,WACkB;CAGlB,MAAM,cACJ,OAAO,YAAY,aAAa,UAAU,KAAA;CAE5C,IAAI;CACJ,IAAI;CACJ,IAAI,WAAoC;CAExC,MAAM,aAAkC;EACtC,OAAO,cAAc,SAAS,MAAM,IAAI;CAC1C;CAEA,MAAM,YAAY,WAA0B;EAC1C,IAAI,aACF,UAAU,IAAI,YAAY,MAAM;OAEhC,YAAY;CAEhB;CAEA,MAAM,gBAAkC;EACtC,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,KAAA,GACb,OAAO,QAAQ,QAAQ,MAAM;EAE/B,IAAI,UACF,OAAO;EAET,MAAM,UAA4B,QAAQ,QAAQ,EAC/C,WAAW,UAAU,CAAC,EACtB,MACE,WAAW;GACV,WAAW;GACX,SAAS,MAAM;GACf,OAAO;EACT,IACC,QAAiB;GAChB,WAAW;GAMX,MAAM,IAAI,yBAAyB,CADpB,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CACpB,GAAG,EAAE,OAAO,IAAI,CAAC;EAC7D,CACF;EACF,WAAW;EACX,OAAO;CACT;CAEA,MAAM,YAAqB;EACzB,MAAM,SAAS,KAAK;EACpB,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,oBAAoB,CAAC,OAAO,CAAC;EAEzC,OAAO;CACT;CAaA,OAAO;EACL;EACA;EACA,IAAI,WAAoB;GACtB,OAAO,KAAK,MAAM,KAAA;EACpB;EACA,OAAA,IAjBgB,MAAM,CAAC,GAAc,EACrC,IAAI,SAAS,MAAM;GACjB,MAAM,SAAS,KAAK;GACpB,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,oBAAoB,CAAC,OAAO,IAAI,CAAC,CAAC;GAE9C,MAAM,QAAQ,QAAQ,IAAI,QAAkB,IAAI;GAChD,OAAO,OAAO,UAAU,aAAa,MAAM,KAAK,MAAM,IAAI;EAC5D,EACF,CAQE;CACF;AACF;AAQA,IAAI,qBAAyD;AAC7D,IAAI,sBAAsB;;;;;;;;;;;;;;;;;AAkB1B,SAAgB,oBACd,UACM;CACN,IAAI,qBACF,MAAM,IAAI,iCAAiC;CAE7C,qBAAqB;AACvB;;;;;;;;;;;;AAaA,IAAa,MAA6B,cAA4B,YAAY;CAChF,IAAI,CAAC,oBACH,MAAM,IAAI,MACR,sJAEF;CAEF,MAAM,SAAS,MAAM,mBAAmB;CACxC,sBAAsB;CACtB,OAAO;AACT,CAAC"}