{"version":3,"file":"index.mjs","sources":["../../../../../packages/hooks/use-id/index.ts"],"sourcesContent":["import { computed, getCurrentInstance, inject, unref } from 'vue'\nimport { debugWarn, isClient } from '@element-plus/utils'\nimport { useGetDerivedNamespace } from '../use-namespace'\n\nimport type { InjectionKey, Ref } from 'vue'\nimport type { MaybeRef } from '@vueuse/core'\n\nexport type ElIdInjectionContext = {\n prefix: number\n current: number\n}\n\nconst defaultIdInjection = {\n prefix: Math.floor(Math.random() * 10000),\n current: 0,\n}\n\nexport const ID_INJECTION_KEY: InjectionKey =\n Symbol('elIdInjection')\n\nexport const useIdInjection = (): ElIdInjectionContext => {\n return getCurrentInstance()\n ? inject(ID_INJECTION_KEY, defaultIdInjection)\n : defaultIdInjection\n}\n\nexport const useId = (deterministicId?: MaybeRef): Ref => {\n const idInjection = useIdInjection()\n if (!isClient && idInjection === defaultIdInjection) {\n debugWarn(\n 'IdInjection',\n `Looks like you are using server rendering, you must provide a id provider to ensure the hydration process to be succeed\nusage: app.provide(ID_INJECTION_KEY, {\n prefix: number,\n current: number,\n})`\n )\n }\n\n const namespace = useGetDerivedNamespace()\n const idRef = computed(\n () =>\n unref(deterministicId) ||\n `${namespace.value}-id-${idInjection.prefix}-${idInjection.current++}`\n )\n\n return idRef\n}\n"],"names":[],"mappings":";;;;;;AAGA,MAAM,kBAAkB,GAAG;AAC3B,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;AACzC,EAAE,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AACU,MAAC,gBAAgB,GAAG,MAAM,CAAC,eAAe,EAAE;AAC5C,MAAC,cAAc,GAAG,MAAM;AACpC,EAAE,OAAO,kBAAkB,EAAE,GAAG,MAAM,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,GAAG,kBAAkB,CAAC;AAClG,EAAE;AACU,MAAC,KAAK,GAAG,CAAC,eAAe,KAAK;AAC1C,EAAE,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;AACvC,EAAE,IAAI,CAAC,QAAQ,IAAI,WAAW,KAAK,kBAAkB,EAAE;AACvD,IAAI,SAAS,CAAC,aAAa,EAAE,CAAC;AAC9B;AACA;AACA;AACA,EAAE,CAAC,CAAC,CAAC;AACL,GAAG;AACH,EAAE,MAAM,SAAS,GAAG,sBAAsB,EAAE,CAAC;AAC7C,EAAE,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;AACjI,EAAE,OAAO,KAAK,CAAC;AACf;;;;"}