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KAAK,4BAAM,cAAc,IAAI,yCAC/C,4BAAM,YAAY,GAAG,KAAK,OAAO,SAAS,CAAC,cAAc,GAAG,IAC5D;AACN;AAEO,SAAS,0CAAiB,MAAsB;IACrD,IAAI,CAAE,CAAA,kBAAkB,OAAM,KAAM,CAAC,CAAA,GAAA,qCAAU,EAAE,SAC/C,OAAO;IAGT,IAAI,aAAa,kBAAkB;IACnC,IAAI,aAAa,kBAAkB,eAAe,OAAO,iBAAiB;IAC1E,IAAI,cAAc,kBAAkB,oBAAoB,CAAC,wCAAkB,GAAG,CAAC,OAAO,IAAI;IAE1F,OAAO,cAAc,cAAc;AACrC;AAEO,SAAS,0CAAiB,KAAoB;IACnD,OAAO,CAAA,GAAA,+BAAI,MAAM,MAAM,OAAO,GAAG,MAAM,OAAO;AAChD;AAEO,SAAS;IACd,OAAO,4BAAM,MAAM;AACrB","sources":["packages/react-aria/src/utils/keyboard.tsx"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {addEvent} from './domHelpers';\nimport {getActiveElement, getEventTarget} from './shadowdom/DOMFunctions';\nimport {getMetaValue} from './getMetaValue';\nimport {isAndroid, isMac, isWebKit} from './platform';\nimport {isFocusable} from './isFocusable';\n\nconst KEYBOARD_HEIGHT = 100;\nconst KEYBOARD_TIMEOUT = 600;\n\n// Tracks layout state of the on-screen keyboard.\nconst state: KeyboardState = {\n  isOpen: false,\n  screenWidth: 0,\n  screenHeight: 0,\n  screenAngle: 0,\n  screenTimeout: 0,\n  startTimeStamp: 0,\n  endTimeStamp: 0,\n  resizeTimeStamp: 0,\n  resizeTimeout: 0\n};\n\n// HTML input types that do not cause the software keyboard to appear.\nconst nonTextInputTypes = new Set([\n  'checkbox',\n  'radio',\n  'range',\n  'color',\n  'file',\n  'image',\n  'button',\n  'submit',\n  'reset'\n]);\n\ninterface KeyboardState {\n  isOpen: boolean;\n  screenHeight: number;\n  screenWidth: number;\n  screenAngle: number;\n  screenTimeout: number;\n  startTimeStamp: number;\n  endTimeStamp: number;\n  resizeTimeStamp: number;\n  resizeTimeout: number;\n}\n\ninterface KeyPressEvent {\n  altKey: boolean;\n  ctrlKey: boolean;\n  metaKey: boolean;\n}\n\ninterface TouchScreen {\n  width: number;\n  height: number;\n  angle: number;\n}\n\nif (\n  process.env.NODE_ENV === 'test' &&\n  typeof window !== 'undefined' &&\n  !Reflect.has(window, 'visualViewport')\n) {\n  const visualViewport = Object.assign(new EventTarget(), {\n    offsetTop: 0,\n    offsetLeft: 0,\n    pageTop: 0,\n    pageLeft: 0,\n    scale: 1\n  });\n\n  Reflect.defineProperty(visualViewport, 'width', {\n    get: () => window.innerWidth,\n    configurable: true\n  });\n\n  Reflect.defineProperty(visualViewport, 'height', {\n    get: () => window.innerHeight,\n    configurable: true\n  });\n\n  Reflect.defineProperty(window, 'visualViewport', {\n    value: visualViewport,\n    configurable: true,\n    writable: true\n  });\n}\n\nif (\n  process.env.NODE_ENV === 'test' &&\n  typeof window !== 'undefined' &&\n  !Reflect.has(window.screen, 'orientation')\n) {\n  const orientation = Object.assign(new EventTarget(), {\n    type: 'landscape-primary'\n  });\n\n  Reflect.defineProperty(window.screen, 'orientation', {\n    value: orientation,\n    configurable: true,\n    writable: true\n  });\n\n  Reflect.defineProperty(window.screen.orientation, 'angle', {\n    get: () => window.orientation ?? 0,\n    configurable: true\n  });\n}\n\nfunction getTouchScreen(): TouchScreen {\n  // Normalize the screen by any scaling to get the layout coordinate space.\n  let screenWidth = Number(window.visualViewport?.width ?? window.innerWidth);\n  let screenHeight = Number(window.visualViewport?.height ?? window.innerHeight);\n  let visualScale = Number(window.visualViewport?.scale ?? 1);\n\n  return {\n    width: screenWidth * visualScale,\n    height: screenHeight * visualScale,\n    angle: window.screen.orientation?.angle ?? 0\n  };\n}\n\nfunction onResizeStart(e: Event): void {\n  // So we don't constantly call clearTimeout and setTimeout, keep track of the\n  // current timeout time and only reschedule the timer when it is getting close.\n  if (state.resizeTimeStamp <= e.timeStamp + 50) {\n    state.resizeTimeStamp = e.timeStamp + 150;\n\n    window.clearTimeout(state.resizeTimeout);\n    state.resizeTimeout = window.setTimeout(onResizeEnd, 150);\n  }\n}\n\nfunction onResizeEnd(): void {\n  let viewportMeta = getMetaValue('viewport');\n\n  // Overlaying keyboards do not impact geometry, so there is nothing to measure.\n  // https://caniuse.com/mdn-html_elements_meta_name_viewport_interactive-widget\n  if (isAndroid() && viewportMeta?.includes('overlays-content')) {\n    return;\n  }\n\n  let time = performance.now();\n  let screen = getTouchScreen();\n\n  let elapsed = time - state.startTimeStamp;\n  let delta = state.screenHeight - screen.height;\n  let rotation = state.screenAngle - screen.angle;\n\n  // Update the screen once an open keyboard that rotated along closes. The state swap was\n  // deferred, so the old width predicts the height it should close towards.\n  if (Math.abs(rotation) % 180 && state.screenWidth - screen.height < KEYBOARD_HEIGHT) {\n    state.screenWidth = screen.width;\n    state.screenHeight = screen.height;\n    state.screenAngle = screen.angle;\n    delta = 0;\n  }\n\n  // Update the screen if a resize happens outside the capture timeframe. We debounce\n  // because WebKit may fire its single opening resize before the focus event.\n  if (elapsed > KEYBOARD_TIMEOUT) {\n    window.clearTimeout(state.screenTimeout);\n\n    state.screenTimeout = window.setTimeout(() => {\n      let activeElement = document.hasFocus() ? getActiveElement() : null;\n      let willKeyboardOpen = willOpenKeyboard(activeElement);\n      let screen = getTouchScreen();\n\n      if (Math.abs(state.screenAngle - screen.angle) % 180) {\n        return;\n      }\n\n      if (state.isOpen && willKeyboardOpen) {\n        return;\n      }\n\n      state.screenWidth = screen.width;\n      state.screenHeight = screen.height;\n      state.screenAngle = screen.angle;\n\n      state.isOpen = false;\n    }, KEYBOARD_TIMEOUT);\n  }\n\n  // Otherwise, record an opening if the height changed by more than our threshold.\n  // This may fail if the layout viewport changes for other reasons during this timeframe.\n  if (elapsed <= KEYBOARD_TIMEOUT && delta >= KEYBOARD_HEIGHT) {\n    state.endTimeStamp = time;\n  }\n\n  // Store the new open state since the viewport is stable when this is reached.\n  state.isOpen = delta >= KEYBOARD_HEIGHT;\n}\n\nfunction onOrientationChange(): void {\n  let screen = getTouchScreen();\n\n  let rotation = state.screenAngle - screen.angle;\n\n  // Rotation may cause the resize buffer to be filled, but we need to make sure a screen\n  // estimate is already available in case focus lands before it expires. This could fail\n  // if a top bar exceeds the keyboard threshold, in which case we may need to revisit.\n  if (Math.abs(rotation) % 180 && !state.isOpen) {\n    let width = state.screenWidth;\n    let height = state.screenHeight;\n\n    state.screenWidth = height;\n    state.screenHeight = width;\n  }\n\n  if (!state.isOpen) {\n    state.screenAngle = screen.angle;\n  }\n}\n\nfunction onFocus(e: FocusEvent): void {\n  let target = getEventTarget(e);\n  let willKeyboardOpen = willOpenKeyboard(target as Element);\n\n  let time = performance.now();\n  let screen = getTouchScreen();\n\n  let delta = state.screenHeight - screen.height;\n\n  // Update the screen and start the timer if we are about to open.\n  if (delta < KEYBOARD_HEIGHT && willKeyboardOpen) {\n    state.screenWidth = screen.width;\n    state.screenHeight = screen.height;\n    state.screenAngle = screen.angle;\n    state.startTimeStamp = time;\n  }\n\n  // This focus will open a keyboard so reset the buffer.\n  if (willKeyboardOpen) {\n    window.clearTimeout(state.screenTimeout);\n  }\n\n  // Stop the timer if the keyboard is already open.\n  if (delta >= KEYBOARD_HEIGHT && willKeyboardOpen) {\n    state.endTimeStamp = time;\n  }\n}\n\nfunction setupGlobalEvents(): void {\n  let screen = getTouchScreen();\n\n  // WebKit only fires a single event per resize.\n  addEvent(window.visualViewport, 'resize', isWebKit() ? onResizeEnd : onResizeStart);\n  // oxlint-disable-next-line - looks like the lint for this is a little too aggressive\n  addEvent(window.screen.orientation, 'change', onOrientationChange);\n  addEvent(window, 'focus', onFocus, {capture: true, passive: true});\n\n  // Store the initial screen dimensions.\n  state.screenWidth = screen.width;\n  state.screenHeight = screen.height;\n  state.screenAngle = screen.angle;\n}\n\nif (typeof document !== 'undefined') {\n  if (document.readyState !== 'loading') {\n    setupGlobalEvents();\n  } else {\n    addEvent(document, 'DOMContentLoaded', setupGlobalEvents);\n  }\n}\n\nexport function supportsKeyboard(): boolean {\n  let viewportMeta = getMetaValue('viewport');\n\n  // Overlaying keyboards do not impact geometry, so there is nothing to await.\n  // https://caniuse.com/mdn-html_elements_meta_name_viewport_interactive-widget\n  if (isAndroid() && viewportMeta?.includes('overlays-content')) {\n    return false;\n  }\n\n  // WebKit may resize before focus, but an open keyboard always means we have support.\n  if (state.isOpen) {\n    return true;\n  }\n\n  // As long as no input has ever been focused, we return default support.\n  if (!state.startTimeStamp) {\n    return window.navigator.maxTouchPoints > 0;\n  }\n\n  // If keyboard geometry changed within the timeout period, we have support.\n  if (state.endTimeStamp >= state.startTimeStamp) {\n    return true;\n  }\n\n  // If a geometry change is mid-flight we return the most recent support.\n  // Supported platforms may have a hardware keyboard, which this won't catch, but thats\n  // about as far as we can reasonably go to exclude non-touch devices.\n  return performance.now() - state.startTimeStamp <= KEYBOARD_TIMEOUT\n    ? state.endTimeStamp > 0 || window.navigator.maxTouchPoints > 0\n    : false;\n}\n\nexport function willOpenKeyboard(target: Element | null): boolean {\n  if (!(target instanceof Element) || !isFocusable(target)) {\n    return false;\n  }\n\n  let isTextArea = target instanceof HTMLTextAreaElement;\n  let isEditable = target instanceof HTMLElement && target.isContentEditable;\n  let isTextInput = target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type);\n\n  return isTextArea || isEditable || isTextInput;\n}\n\nexport function isCtrlKeyPressed(event: KeyPressEvent): boolean {\n  return isMac() ? event.metaKey : event.ctrlKey;\n}\n\nexport function isKeyboardOpen(): boolean {\n  return state.isOpen;\n}\n"],"names":[],"version":3,"file":"keyboard.cjs.map"}