@angular/cdk
Version:
Angular Material Component Development Kit
1 lines • 3.74 kB
Source Map (JSON)
{"version":3,"file":"_shadow-dom-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/cdk/platform/features/shadow-dom.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nlet shadowDomIsSupported: boolean;\n\n/** Checks whether the user's browser support Shadow DOM. */\nexport function _supportsShadowDom(): boolean {\n if (shadowDomIsSupported == null) {\n const head = typeof document !== 'undefined' ? document.head : null;\n shadowDomIsSupported = !!(head && ((head as any).createShadowRoot || head.attachShadow));\n }\n\n return shadowDomIsSupported;\n}\n\n/** Gets the shadow root of an element, if supported and the element is inside the Shadow DOM. */\nexport function _getShadowRoot(element: HTMLElement): ShadowRoot | null {\n if (_supportsShadowDom()) {\n const rootNode = element.getRootNode ? element.getRootNode() : null;\n\n // Note that this should be caught by `_supportsShadowDom`, but some\n // teams have been able to hit this code path on unsupported browsers.\n if (typeof ShadowRoot !== 'undefined' && ShadowRoot && rootNode instanceof ShadowRoot) {\n return rootNode;\n }\n }\n\n return null;\n}\n\n/**\n * Gets the currently-focused element on the page while\n * also piercing through Shadow DOM boundaries.\n */\nexport function _getFocusedElementPierceShadowDom(): HTMLElement | null {\n let activeElement =\n typeof document !== 'undefined' && document\n ? (document.activeElement as HTMLElement | null)\n : null;\n\n while (activeElement && activeElement.shadowRoot) {\n const newActiveElement = activeElement.shadowRoot.activeElement as HTMLElement | null;\n if (newActiveElement === activeElement) {\n break;\n } else {\n activeElement = newActiveElement;\n }\n }\n\n return activeElement;\n}\n\n/** Gets the target of an event while accounting for Shadow DOM. */\nexport function _getEventTarget<T extends EventTarget>(event: Event): T | null {\n // If an event is bound outside the Shadow DOM, the `event.target` will point to the shadow root\n // so we have to use `composedPath` instead. Note that `composedPath` can throw if it's called\n // during event replay (see #33386).\n // TODO(crisbeto): it seems like `preventDefault` throws during replay as well.\n if (event.composedPath) {\n try {\n return event.composedPath()[0] as T | null;\n } catch {}\n }\n return event.target as T | null;\n}\n"],"names":[],"mappings":"AAQA,IAAI,oBAA6B;SAGjB,kBAAkB,GAAA;EAChC,IAAI,oBAAoB,IAAI,IAAI,EAAE;IAChC,MAAM,IAAI,GAAG,OAAO,QAAQ,KAAK,WAAW,GAAG,QAAQ,CAAC,IAAI,GAAG,IAAI;AACnE,IAAA,oBAAoB,GAAG,CAAC,EAAE,IAAI,KAAM,IAAY,CAAC,gBAAgB,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC;AAC1F,EAAA;AAEA,EAAA,OAAO,oBAAoB;AAC7B;AAGM,SAAU,cAAc,CAAC,OAAoB,EAAA;EACjD,IAAI,kBAAkB,EAAE,EAAE;AACxB,IAAA,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,GAAG,IAAI;IAInE,IAAI,OAAO,UAAU,KAAK,WAAW,IAAI,UAAU,IAAI,QAAQ,YAAY,UAAU,EAAE;AACrF,MAAA,OAAO,QAAQ;AACjB,IAAA;AACF,EAAA;AAEA,EAAA,OAAO,IAAI;AACb;SAMgB,iCAAiC,GAAA;AAC/C,EAAA,IAAI,aAAa,GACf,OAAO,QAAQ,KAAK,WAAW,IAAI,QAAA,GAC9B,QAAQ,CAAC,aAAA,GACV,IAAI;AAEV,EAAA,OAAO,aAAa,IAAI,aAAa,CAAC,UAAU,EAAE;AAChD,IAAA,MAAM,gBAAgB,GAAG,aAAa,CAAC,UAAU,CAAC,aAAmC;IACrF,IAAI,gBAAgB,KAAK,aAAa,EAAE;AACtC,MAAA;AACF,IAAA,CAAA,MAAO;AACL,MAAA,aAAa,GAAG,gBAAgB;AAClC,IAAA;AACF,EAAA;AAEA,EAAA,OAAO,aAAa;AACtB;AAGM,SAAU,eAAe,CAAwB,KAAY,EAAA;EAKjE,IAAI,KAAK,CAAC,YAAY,EAAE;IACtB,IAAI;AACF,MAAA,OAAO,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAa;IAC5C,CAAA,CAAE,MAAM,CAAC;AACX,EAAA;EACA,OAAO,KAAK,CAAC,MAAkB;AACjC;;;;"}