{"version":3,"file":"currentInstance-BCYlqmUv.cjs","sources":["../../../src/symbols.ts","../../../src/currentInstance.ts"],"sourcesContent":["export const DEFINE_COMPONENT_OPTIONS_SYMBOL = Symbol(`𝜄`)\nexport const REACTIVE_OBJECT_SYMBOL = Symbol(`𝒂`)\n","import type { LitElement } from 'lit'\nimport { DEFINE_COMPONENT_OPTIONS_SYMBOL } from './symbols'\nimport type { Fn } from './utils/types'\n\ninterface DefinedComponentInstance<Options = Record<string, unknown>> extends LitElement {\n  [DEFINE_COMPONENT_OPTIONS_SYMBOL]: Options\n}\n\nlet currentInstance: unknown = null\n\n/**\n * Set the current instance of a LitElement, _not_ exported.\n * @param instance the instance to set as current\n */\nconst setCurrentInstance = <T extends LitElement>(instance: T) => (currentInstance = instance)\n\n/**\n * Get the current instance of a LitElement.\n * There is only one thread of execution, so there is only one current instance at a time.\n */\nexport const getCurrentInstance = <T extends LitElement>() => currentInstance as T\n\n/**\n * Execute a callback within the given \"current instance\" scope\n * @param instance the getCurrentInstance() instance to use\n * @param callback the callback to execute with the current instance\n */\nexport const withCurrentInstance = <T extends LitElement, Result>(instance: T, callback: Fn<[], Result>): Result => {\n  const old = getCurrentInstance<T>()\n  try {\n    setCurrentInstance(instance)\n    return callback()\n  } finally {\n    setCurrentInstance(old)\n  }\n}\n\n/**\n * Get the options of the current LitElement.\n * These are internal storage for storing hook callbacks.\n */\nexport const getCurrentOptions = <\n  //\n  Options extends {},\n  Element extends DefinedComponentInstance<Options> = LitElement & { [DEFINE_COMPONENT_OPTIONS_SYMBOL]: Options },\n>(): Options => getCurrentInstance<Element>()?.[DEFINE_COMPONENT_OPTIONS_SYMBOL]\n"],"names":["DEFINE_COMPONENT_OPTIONS_SYMBOL","REACTIVE_OBJECT_SYMBOL","currentInstance","setCurrentInstance","instance","getCurrentInstance","withCurrentInstance","callback","old","getCurrentOptions"],"mappings":"aAAO,MAAMA,EAAkC,OAAO,IAAI,EAC7CC,EAAyB,OAAO,IAAI,ECOjD,IAAIC,EAA2B,KAM/B,MAAMC,EAA4CC,GAAiBF,EAAkBE,EAMxEC,EAAqB,IAA4BH,EAOjDI,EAAsB,CAA+BF,EAAaG,IAAqC,CAClH,MAAMC,EAAMH,EAAA,EACZ,GAAI,CACF,OAAAF,EAAmBC,CAAQ,EACpBG,EAAA,CACT,QAAA,CACEJ,EAAmBK,CAAG,CACxB,CACF,EAMaC,EAAoB,IAIjBJ,EAAA,IAAgCL,CAA+B,EAAA,QAAA,EAAAA,EAAA,QAAA,EAAAC,EAAA,QAAA,EAAAQ,EAAA,QAAA,EAAAJ,EAAA,QAAA,EAAAC"}