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sourcesContent":["import { getWindow } from './dom/getWindow';\nimport { isDirectionalKeyCode } from './keyboard';\nimport { setFocusVisibility } from './setFocusVisibility';\n\ntype AppWindow =\n | (Window & {\n __hasInitializeFocusRects__: boolean;\n FabricConfig?: { disableFocusRects?: boolean };\n })\n | undefined;\n\n/**\n * Initializes the logic which:\n *\n * 1. Subscribes keydown and mousedown events. (It will only do it once per window,\n * so it's safe to call this method multiple times.)\n * 2. When the user presses directional keyboard keys, adds the 'ms-Fabric--isFocusVisible' classname\n * to the document body, removes the 'ms-Fabric-isFocusHidden' classname.\n * 3. When the user clicks a mouse button, adds the 'ms-Fabric-isFocusHidden' classname to the\n * document body, removes the 'ms-Fabric--isFocusVisible' classname.\n *\n * This logic allows components on the page to conditionally render focus treatments based on\n * the existence of global classnames, which simplifies logic overall.\n *\n * @param window - the window used to add the event listeners\n * @deprecated Use useFocusRects hook or FocusRects component instead.\n */\nexport function initializeFocusRects(window?: Window): void {\n const win = (window || getWindow()) as AppWindow;\n if (!win || win.FabricConfig?.disableFocusRects === true) {\n return;\n }\n\n if (!win.__hasInitializeFocusRects__) {\n win.__hasInitializeFocusRects__ = true;\n win.addEventListener('mousedown', _onMouseDown, true);\n win.addEventListener('pointerdown', _onPointerDown, true);\n win.addEventListener('keydown', _onKeyDown as () => void, true);\n }\n}\n\nfunction _onMouseDown(ev: MouseEvent): void {\n setFocusVisibility(false, ev.target as Element);\n}\n\nfunction _onPointerDown(ev: PointerEvent): void {\n if (ev.pointerType !== 'mouse') {\n setFocusVisibility(false, ev.target as Element);\n }\n}\n\nfunction _onKeyDown(ev: KeyboardEvent): void {\n // eslint-disable-next-line deprecation/deprecation\n isDirectionalKeyCode(ev.which) && setFocusVisibility(true, ev.target as Element);\n}\n"]} |