{"version":3,"file":"index.mjs","sources":["../../../../../packages/hooks/use-restore-active/index.ts"],"sourcesContent":["import { isRef, watch } from 'vue'\r\nimport type { Ref } from 'vue'\r\n\r\n/**\r\n * This method provides dialogable components the ability to restore previously activated element before\r\n * the dialog gets opened\r\n */\r\nexport const useRestoreActive = (\r\n  toggle: Ref<boolean>,\r\n  initialFocus?: Ref<HTMLElement>\r\n) => {\r\n  let previousActive: HTMLElement\r\n  watch(\r\n    () => toggle.value,\r\n    (val) => {\r\n      if (val) {\r\n        previousActive = document.activeElement as HTMLElement\r\n        if (isRef(initialFocus)) {\r\n          initialFocus.value.focus?.()\r\n        }\r\n      } else {\r\n        if (process.env.NODE_ENV === 'test') {\r\n          previousActive.focus.call(previousActive)\r\n        } else {\r\n          previousActive.focus()\r\n        }\r\n      }\r\n    }\r\n  )\r\n}\r\n"],"names":[],"mappings":";;AACY,MAAC,gBAAgB,GAAG,CAAC,MAAM,EAAE,YAAY,KAAK;AAC1D,EAAE,IAAI,cAAc,CAAC;AACrB,EAAE,KAAK,CAAC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK;AACrC,IAAI,IAAI,EAAE,EAAE,EAAE,CAAC;AACf,IAAI,IAAI,GAAG,EAAE;AACb,MAAM,cAAc,GAAG,QAAQ,CAAC,aAAa,CAAC;AAC9C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,EAAE;AAC/B,QAAQ,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,YAAY,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC9E,OAAO;AACP,KAAK,MAAM;AACX,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,EAAE;AAC3C,QAAQ,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAClD,OAAO,MAAM;AACb,QAAQ,cAAc,CAAC,KAAK,EAAE,CAAC;AAC/B,OAAO;AACP,KAAK;AACL,GAAG,CAAC,CAAC;AACL;;;;"}