{"version":3,"file":"setup-jsdom-polyfills.cjs","sources":["../src/test/setup-jsdom-polyfills.ts"],"sourcesContent":["/**\n * Polyfills for JSDOM test environments\n *\n * These polyfills prevent `NimbusProvider` from crashing in JSDOM\n * environments (e.g., Jest, Vitest).\n *\n * **Usage with Jest:**\n * ```js\n * // jest.config.js\n * module.exports = {\n *   setupFiles: [\n *     '@commercetools/nimbus/setup-jsdom-polyfills'\n *   ]\n * };\n * ```\n *\n * **Usage with Vitest:**\n * ```ts\n * // vitest.config.ts\n * export default defineConfig({\n *   test: {\n *     setupFiles: [\n *       '@commercetools/nimbus/setup-jsdom-polyfills'\n *     ]\n *   }\n * });\n * ```\n\n */\n\n/**\n * Mock structuredClone\n *\n * **Why**: Required by Chakra UI provider for deep cloning objects\n *\n * **Use cases**:\n * - NimbusProvider initialization\n * - Chakra UI theme configuration\n * - Deep cloning of component state\n * - React context value cloning\n */\nif (typeof globalThis.structuredClone !== \"function\") {\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  globalThis.structuredClone = function structuredClone(value: any) {\n    if (value === null || value === undefined) {\n      return value;\n    }\n\n    try {\n      // For objects and arrays, use JSON methods\n      if (typeof value === \"object\") {\n        return JSON.parse(JSON.stringify(value));\n      }\n      // For primitive values, return directly\n      return value;\n    } catch (error) {\n      console.warn(\"structuredClone polyfill failed:\", error);\n\n      // Returns a shallow copy as fallback\n      return Array.isArray(value) ? [...value] : { ...value };\n    }\n  };\n}\n\n/**\n * Mock window.matchMedia\n *\n * **Why**: Required for responsive design and theme system\n *\n * **Use cases**:\n * - Chakra UI color mode and theme detection\n * - Responsive component behavior\n * - Media query hooks (useMediaQuery)\n * - Breakpoint-based rendering\n */\nif (typeof window !== \"undefined\" && !window.matchMedia) {\n  window.matchMedia = (query: string) =>\n    ({\n      matches: false, // Default, can be overridden in tests\n      media: query,\n      onchange: null,\n      addListener: () => {}, // Deprecated but needed\n      removeListener: () => {}, // Deprecated but needed\n      addEventListener: () => {},\n      removeEventListener: () => {},\n      dispatchEvent: () => false,\n    }) as MediaQueryList;\n}\n\n/**\n * Mock ResizeObserver\n *\n * **Why**: Required for components that adjust based on size\n *\n * **Use cases**:\n * - Chakra UI responsive components\n * - React Aria components with responsive behavior\n * - Components that measure container dimensions\n */\nif (typeof globalThis.ResizeObserver === \"undefined\") {\n  class ResizeObserverMock {\n    observe() {}\n    unobserve() {}\n    disconnect() {}\n  }\n  globalThis.ResizeObserver =\n    ResizeObserverMock as unknown as typeof ResizeObserver;\n}\n\n/**\n * Mock IntersectionObserver\n *\n * **Why**: Required for lazy loading and viewport-based effects\n *\n * **Use cases**:\n * - Components that trigger actions when entering viewport\n * - Infinite scroll implementations\n * - Lazy image loading\n * - Visibility tracking for analytics\n */\nif (typeof globalThis.IntersectionObserver === \"undefined\") {\n  class IntersectionObserverMock {\n    readonly root: Element | null = null;\n    readonly rootMargin: string = \"\";\n    readonly thresholds: ReadonlyArray<number> = [];\n\n    disconnect() {}\n    observe() {}\n    takeRecords(): IntersectionObserverEntry[] {\n      return [];\n    }\n    unobserve() {}\n  }\n  globalThis.IntersectionObserver =\n    IntersectionObserverMock as unknown as typeof IntersectionObserver;\n}\n\n/**\n * Mock Element.prototype scroll methods\n *\n * **Why**: Used by navigation, modals, and focus management\n *\n * **Use cases**:\n * - React Aria focus management\n * - Scroll-to-top features\n * - Dialog auto-focus and scroll behavior\n * - Dropdown and menu positioning\n */\nif (typeof Element !== \"undefined\") {\n  Element.prototype.scrollTo = Element.prototype.scrollTo || (() => {});\n  Element.prototype.scrollIntoView =\n    Element.prototype.scrollIntoView || (() => {});\n}\n\n/**\n * Mock requestAnimationFrame\n *\n * **Why**: Used in animations and transitions\n *\n * **Use cases**:\n * - Chakra UI animations and motion components\n * - React Aria transition hooks\n * - Smooth UI updates and state changes\n * - Custom animation implementations\n */\nif (typeof window !== \"undefined\" && !window.requestAnimationFrame) {\n  window.requestAnimationFrame = (callback: FrameRequestCallback) => {\n    return setTimeout(\n      () => callback(Date.now()),\n      1000 / 60\n    ) as unknown as number;\n  };\n}\n"],"names":["value","error","query","ResizeObserverMock","IntersectionObserverMock","callback"],"mappings":"aAyCI,OAAO,WAAW,iBAAoB,aAExC,WAAW,gBAAkB,SAAyBA,EAAY,CAChE,GAAIA,GAAU,KACZ,OAAOA,EAGT,GAAI,CAEF,OAAI,OAAOA,GAAU,SACZ,KAAK,MAAM,KAAK,UAAUA,CAAK,CAAC,EAGlCA,CACT,OAASC,EAAO,CACd,eAAQ,KAAK,mCAAoCA,CAAK,EAG/C,MAAM,QAAQD,CAAK,EAAI,CAAC,GAAGA,CAAK,EAAI,CAAE,GAAGA,CAAA,CAClD,CACF,GAcE,OAAO,OAAW,KAAe,CAAC,OAAO,aAC3C,OAAO,WAAcE,IAClB,CACC,QAAS,GACT,MAAOA,EACP,SAAU,KACV,YAAa,IAAM,CAAC,EACpB,eAAgB,IAAM,CAAC,EACvB,iBAAkB,IAAM,CAAC,EACzB,oBAAqB,IAAM,CAAC,EAC5B,cAAe,IAAM,EAAA,IAc3B,GAAI,OAAO,WAAW,eAAmB,IAAa,CACpD,MAAMC,CAAmB,CACvB,SAAU,CAAC,CACX,WAAY,CAAC,CACb,YAAa,CAAC,CAAA,CAEhB,WAAW,eACTA,CACJ,CAaA,GAAI,OAAO,WAAW,qBAAyB,IAAa,CAC1D,MAAMC,CAAyB,CACpB,KAAuB,KACvB,WAAqB,GACrB,WAAoC,CAAA,EAE7C,YAAa,CAAC,CACd,SAAU,CAAC,CACX,aAA2C,CACzC,MAAO,CAAA,CACT,CACA,WAAY,CAAC,CAAA,CAEf,WAAW,qBACTA,CACJ,CAaI,OAAO,QAAY,MACrB,QAAQ,UAAU,SAAW,QAAQ,UAAU,WAAa,IAAM,CAAC,GACnE,QAAQ,UAAU,eAChB,QAAQ,UAAU,iBAAmB,IAAM,CAAC,IAc5C,OAAO,OAAW,KAAe,CAAC,OAAO,wBAC3C,OAAO,sBAAyBC,GACvB,WACL,IAAMA,EAAS,KAAK,KAAK,EACzB,IAAO,EAAA"}