{"version":3,"file":"resolve_subject.mjs","names":[],"sources":["../../../src/client/suite/resolve_subject.ts"],"sourcesContent":["/**\n * Resolves the subject element of an auto snapshot from a CSS selector.\n *\n * When the selector matches multiple elements,\n * the first visible one is used,\n * so hidden matches elsewhere in the document (e.g. Storybook's own UI) do not shadow the rendered subject.\n *\n * If the selector is not provided or matches nothing, `document.body` is used.\n * If the selector only matches hidden elements, it throws right away instead of letting the screenshot wait until timeout.\n */\nexport function resolveSubject(selector: string | undefined): Element {\n\tif (!selector) return document.body\n\tconst matches = Array.from(document.querySelectorAll(selector))\n\tif (matches.length === 0) return document.body\n\tconst visible = matches.find(isVisible)\n\tif (visible) return visible\n\tthrow new Error(\n\t\t`Snapshot subject \\`${selector}\\` is not visible: it matched ${matches.length} element(s), but none of them is visible.`,\n\t)\n}\n\n/**\n * Same definition of visibility as Playwright:\n * the element has a non-empty bounding box and does not have `visibility: hidden`.\n *\n * @see https://playwright.dev/docs/actionability#visible\n */\nfunction isVisible(element: Element) {\n\tconst rect = element.getBoundingClientRect()\n\tif (rect.width === 0 || rect.height === 0) return false\n\treturn getComputedStyle(element).visibility !== 'hidden'\n}\n"],"mappings":";;;;;;;;;;;AAUA,SAAgB,eAAe,UAAuC;AACrE,KAAI,CAAC,SAAU,QAAO,SAAS;CAC/B,MAAM,UAAU,MAAM,KAAK,SAAS,iBAAiB,SAAS,CAAC;AAC/D,KAAI,QAAQ,WAAW,EAAG,QAAO,SAAS;CAC1C,MAAM,UAAU,QAAQ,KAAK,UAAU;AACvC,KAAI,QAAS,QAAO;AACpB,OAAM,IAAI,MACT,sBAAsB,SAAS,gCAAgC,QAAQ,OAAO,2CAC9E;;;;;;;;AASF,SAAS,UAAU,SAAkB;CACpC,MAAM,OAAO,QAAQ,uBAAuB;AAC5C,KAAI,KAAK,UAAU,KAAK,KAAK,WAAW,EAAG,QAAO;AAClD,QAAO,iBAAiB,QAAQ,CAAC,eAAe"}