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,EAAtB,GAAG,mBAAG,KAAI,CAAC,WAAW,KAAA,EAAK,IAAI,cAAA,CAElC;oBAED,MAAM,CAAC,uBAAuB,OAA9B,MAAM,iBAAyB,GAAG,GAAK,IAAI,UAAE;gBAC/C,CAAC;aACF,CAAC,CAAC;YACH,OAAO,cAAM,OAAA,UAAU,EAAV,CAAU,CAAC;QAC1B,CAAC;;;OAAA;IACH,qBAAC;AAAD,CAAC,AA1ED,IA0EC;;AACD,gBAAgB;AAChB,MAAM,UAAU,qBAAqB;IACnC,IAAM,MAAM,GAAkC;QAC5C,UAAU;QACV,MAAM;QACN,QAAQ;QACR,OAAO;QACP,MAAM;QACN,KAAK;QACL,UAAU;QACV,MAAM;QACN,SAAS;QACT,WAAW;QACX,WAAW;QACX,UAAU;QACV,WAAW;QACX,MAAM;QACN,OAAO;QACP,SAAS;QACT,UAAU;QACV,OAAO;QACP,SAAS;QACT,UAAU;QACV,OAAO;QACP,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,WAAW;QACX,UAAU;QACV,WAAW;QACX,SAAS;QACT,OAAO;QACP,eAAe;QACf,aAAa;QACb,cAAc;QACd,cAAc;QACd,aAAa;QACb,YAAY;QACZ,aAAa;QACb,WAAW;QACX,QAAQ;QACR,QAAQ;QACR,iBAAiB;QACjB,aAAa;QACb,QAAQ;QACR,QAAQ;QACR,aAAa;QACb,UAAU;QACV,WAAW;QACX,YAAY;QACZ,OAAO;KACR,CAAC;IACF,SAAS,oBAAoB;QAC3B,MAAM,IAAI,KAAK,CAAC,8MAIf,CAAC,CAAC;IACL,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK;QACnB,QAAQ,CAAC,gBAAgB,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* istanbul ignore file */\n\n/*\nSomething in this file does not compile correctly while measuring code coverage\nand will lead to a\n Uncaught [ReferenceError: cov_1zb8w312au is not defined]\nif we do not ignore this file in code coverage.\n\nAs we only use this file in our internal tests, we can safely ignore it.\n*/\n\nimport { within, screen } from \"@testing-library/dom\";\nimport { JSDOM, VirtualConsole } from \"jsdom\";\nimport { applyStackTrace, captureStackTrace } from \"./traces.js\";\n\n/** @internal */\nexport interface BaseRender {\n id: string;\n phase: \"mount\" | \"update\" | \"nested-update\";\n actualDuration: number;\n baseDuration: number;\n startTime: number;\n commitTime: number;\n /**\n * The number of renders that have happened so far (including this render).\n */\n count: number;\n}\n\ntype Screen = typeof screen;\n/** @internal */\nexport type SyncScreen = {\n [K in keyof Screen]: K extends `find${string}` ?\n {\n /** @deprecated A snapshot is static, so avoid async queries! */\n (...args: Parameters): ReturnType;\n }\n : Screen[K];\n};\n\n/** @internal */\nexport interface Render extends BaseRender {\n /**\n * The snapshot, as returned by the `takeSnapshot` option of `profile`.\n * (If using `profileHook`, this is the return value of the hook.)\n */\n snapshot: Snapshot;\n /**\n * A DOM snapshot of the rendered component, if the `snapshotDOM`\n * option of `profile` was enabled.\n */\n readonly domSnapshot: HTMLElement;\n /**\n * Returns a callback to receive a `screen` instance that is scoped to the\n * DOM snapshot of this `Render` instance.\n * Note: this is used as a callback to prevent linter errors.\n * @example\n * ```diff\n * const { withinDOM } = RenderedComponent.takeRender();\n * -expect(screen.getByText(\"foo\")).toBeInTheDocument();\n * +expect(withinDOM().getByText(\"foo\")).toBeInTheDocument();\n * ```\n */\n withinDOM: () => SyncScreen;\n\n renderedComponents: Array;\n}\n\n/** @internal */\nexport class RenderInstance implements Render {\n id: string;\n phase: \"mount\" | \"update\" | \"nested-update\";\n actualDuration: number;\n baseDuration: number;\n startTime: number;\n commitTime: number;\n count: number;\n\n constructor(\n baseRender: BaseRender,\n public snapshot: Snapshot,\n private stringifiedDOM: string | undefined,\n public renderedComponents: Array\n ) {\n this.id = baseRender.id;\n this.phase = baseRender.phase;\n this.actualDuration = baseRender.actualDuration;\n this.baseDuration = baseRender.baseDuration;\n this.startTime = baseRender.startTime;\n this.commitTime = baseRender.commitTime;\n this.count = baseRender.count;\n }\n\n private _domSnapshot: HTMLElement | undefined;\n get domSnapshot() {\n if (this._domSnapshot) return this._domSnapshot;\n if (!this.stringifiedDOM) {\n throw new Error(\n \"DOM snapshot is not available - please set the `snapshotDOM` option\"\n );\n }\n\n const virtualConsole = new VirtualConsole();\n const stackTrace = captureStackTrace(\"RenderInstance.get\");\n virtualConsole.on(\"jsdomError\", (error) => {\n throw applyStackTrace(error, stackTrace);\n });\n\n const snapDOM = new JSDOM(this.stringifiedDOM, {\n runScripts: \"dangerously\",\n virtualConsole,\n });\n const document = snapDOM.window.document;\n const body = document.body;\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.text = `\n ${errorOnDomInteraction.toString()};\n ${errorOnDomInteraction.name}();\n `;\n body.appendChild(script);\n body.removeChild(script);\n\n return (this._domSnapshot = body);\n }\n\n get withinDOM() {\n const snapScreen = Object.assign(within(this.domSnapshot), {\n debug: (\n ...[dom = this.domSnapshot, ...rest]: Parameters\n ) => {\n screen.debug(dom, ...rest);\n },\n logTestingPlaygroundURL: (\n ...[dom = this.domSnapshot, ...rest]: Parameters<\n typeof screen.logTestingPlaygroundURL\n >\n ) => {\n screen.logTestingPlaygroundURL(dom, ...rest);\n },\n });\n return () => snapScreen;\n }\n}\n/** @internal */\nexport function errorOnDomInteraction() {\n const events: Array = [\n \"auxclick\",\n \"blur\",\n \"change\",\n \"click\",\n \"copy\",\n \"cut\",\n \"dblclick\",\n \"drag\",\n \"dragend\",\n \"dragenter\",\n \"dragleave\",\n \"dragover\",\n \"dragstart\",\n \"drop\",\n \"focus\",\n \"focusin\",\n \"focusout\",\n \"input\",\n \"keydown\",\n \"keypress\",\n \"keyup\",\n \"mousedown\",\n \"mouseenter\",\n \"mouseleave\",\n \"mousemove\",\n \"mouseout\",\n \"mouseover\",\n \"mouseup\",\n \"paste\",\n \"pointercancel\",\n \"pointerdown\",\n \"pointerenter\",\n \"pointerleave\",\n \"pointermove\",\n \"pointerout\",\n \"pointerover\",\n \"pointerup\",\n \"scroll\",\n \"select\",\n \"selectionchange\",\n \"selectstart\",\n \"submit\",\n \"toggle\",\n \"touchcancel\",\n \"touchend\",\n \"touchmove\",\n \"touchstart\",\n \"wheel\",\n ];\n function warnOnDomInteraction() {\n throw new Error(`\n DOM interaction with a snapshot detected in test.\n Please don't interact with the DOM you get from \\`withinDOM\\`,\n but still use \\`screen\\' to get elements for simulating user interaction.\n `);\n }\n events.forEach((event) => {\n document.addEventListener(event, warnOnDomInteraction);\n });\n}\n"]}