{"version":3,"file":"forwardRefs.mjs","names":["Refs","Symbol","getDescriptor","obj","key","currentObj","descriptor","Reflect","getOwnPropertyDescriptor","Object","getPrototypeOf","undefined","forwardRefs","target","_len","arguments","length","refs","Array","_key","Proxy","get","has","startsWith","ref","value","val","bind","set","_","setupState","childRefs","queue","slice","shift","push"],"sources":["../../src/composables/forwardRefs.ts"],"sourcesContent":["// Types\nimport type { ComponentPublicInstance, Ref, UnwrapRef } from 'vue'\nimport type { UnionToIntersection } from '@/util'\n\nconst Refs = Symbol('Forwarded refs')\n\n/** Omit properties starting with P */\ntype OmitPrefix = [Extract] extends [never] ? T : Omit\n\ntype OmitProps = T extends { $props: any } ? Omit : T\n\nfunction getDescriptor (obj: any, key: PropertyKey) {\n let currentObj = obj\n while (currentObj) {\n const descriptor = Reflect.getOwnPropertyDescriptor(currentObj, key)\n if (descriptor) return descriptor\n currentObj = Object.getPrototypeOf(currentObj)\n }\n return undefined\n}\n\nexport function forwardRefs | undefined>[]> (\n target: T,\n ...refs: U\n): T & UnionToIntersection<{ [K in keyof U]: OmitPrefix>>, '$'> }[number]> {\n (target as any)[Refs] = refs\n\n return new Proxy(target, {\n get (target, key) {\n if (Reflect.has(target, key)) {\n return Reflect.get(target, key)\n }\n\n // Skip internal properties\n if (typeof key === 'symbol' || key.startsWith('__')) return\n\n for (const ref of refs) {\n if (ref.value && Reflect.has(ref.value, key)) {\n const val = Reflect.get(ref.value, key)\n return typeof val === 'function'\n ? val.bind(ref.value)\n : val\n }\n }\n },\n has (target, key) {\n if (Reflect.has(target, key)) {\n return true\n }\n\n // Skip internal properties\n if (typeof key === 'symbol' || key.startsWith('__')) return false\n\n for (const ref of refs) {\n if (ref.value && Reflect.has(ref.value, key)) {\n return true\n }\n }\n return false\n },\n set (target, key, value) {\n if (Reflect.has(target, key)) {\n return Reflect.set(target, key, value)\n }\n\n // Skip internal properties\n if (typeof key === 'symbol' || key.startsWith('__')) return false\n\n for (const ref of refs) {\n if (ref.value && Reflect.has(ref.value, key)) {\n return Reflect.set(ref.value, key, value)\n }\n }\n\n return false\n },\n getOwnPropertyDescriptor (target, key) {\n const descriptor = Reflect.getOwnPropertyDescriptor(target, key)\n if (descriptor) return descriptor\n\n // Skip internal properties\n if (typeof key === 'symbol' || key.startsWith('__')) return\n\n // Check each ref's own properties\n for (const ref of refs) {\n if (!ref.value) continue\n const descriptor = getDescriptor(ref.value, key) ?? ('_' in ref.value ? getDescriptor(ref.value._?.setupState, key) : undefined)\n if (descriptor) return descriptor\n }\n\n // Recursive search up each ref's prototype\n for (const ref of refs) {\n const childRefs = ref.value && (ref.value as any)[Refs]\n if (!childRefs) continue\n const queue = childRefs.slice()\n while (queue.length) {\n const ref = queue.shift()\n const descriptor = getDescriptor(ref.value, key)\n if (descriptor) return descriptor\n const childRefs = ref.value && (ref.value as any)[Refs]\n if (childRefs) queue.push(...childRefs)\n }\n }\n\n return undefined\n },\n }) as any\n}\n"],"mappings":"AAAA;;AAIA,MAAMA,IAAI,GAAGC,MAAM,CAAC,gBAAgB,CAAC;;AAErC;;AAKA,SAASC,aAAaA,CAAEC,GAAQ,EAAEC,GAAgB,EAAE;EAClD,IAAIC,UAAU,GAAGF,GAAG;EACpB,OAAOE,UAAU,EAAE;IACjB,MAAMC,UAAU,GAAGC,OAAO,CAACC,wBAAwB,CAACH,UAAU,EAAED,GAAG,CAAC;IACpE,IAAIE,UAAU,EAAE,OAAOA,UAAU;IACjCD,UAAU,GAAGI,MAAM,CAACC,cAAc,CAACL,UAAU,CAAC;EAChD;EACA,OAAOM,SAAS;AAClB;AAEA,OAAO,SAASC,WAAWA,CACzBC,MAAS,EAEsG;EAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAD5GC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;EAAA;EAENN,MA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