{"version":3,"file":"utils.js","names":[],"sources":["esm/utils.js"],"sourcesContent":["const keyName = \"__reactResponderId\";\nconst canUseDOM = !!(typeof window !== \"undefined\" && window.document && window.document.createElement);\nconst getBoundingClientRect = (node) => {\n  if (!node) return;\n  if (node.nodeType !== 1) return;\n  if (node.getBoundingClientRect) {\n    return node.getBoundingClientRect();\n  }\n};\nfunction getEventPath(domEvent) {\n  if (domEvent.type === \"selectionchange\") {\n    const target = window.getSelection()?.anchorNode;\n    return composedPathFallback(target);\n  }\n  const path = domEvent.composedPath != null ? domEvent.composedPath() : composedPathFallback(domEvent.target);\n  return path;\n}\nfunction composedPathFallback(target) {\n  const path = [];\n  while (target != null && target !== document.body) {\n    path.push(target);\n    target = target.parentNode;\n  }\n  return path;\n}\nfunction getResponderId(node) {\n  if (node != null) {\n    return node[keyName];\n  }\n  return null;\n}\nfunction setResponderId(node, id) {\n  if (node != null) {\n    node[keyName] = id;\n  }\n}\nfunction getResponderPaths(domEvent) {\n  const idPath = [];\n  const nodePath = [];\n  const eventPath = getEventPath(domEvent);\n  for (let i = 0; i < eventPath.length; i++) {\n    const node = eventPath[i];\n    const id = getResponderId(node);\n    if (id != null) {\n      idPath.push(id);\n      nodePath.push(node);\n    }\n  }\n  return { idPath, nodePath };\n}\nfunction getLowestCommonAncestor(pathA, pathB) {\n  let pathALength = pathA.length;\n  let pathBLength = pathB.length;\n  if (\n    // If either path is empty\n    pathALength === 0 || pathBLength === 0 || // If the last elements aren't the same there can't be a common ancestor\n    // that is connected to the responder system\n    pathA[pathALength - 1] !== pathB[pathBLength - 1]\n  ) {\n    return null;\n  }\n  let itemA = pathA[0];\n  let indexA = 0;\n  let itemB = pathB[0];\n  let indexB = 0;\n  if (pathALength - pathBLength > 0) {\n    indexA = pathALength - pathBLength;\n    itemA = pathA[indexA];\n    pathALength = pathBLength;\n  }\n  if (pathBLength - pathALength > 0) {\n    indexB = pathBLength - pathALength;\n    itemB = pathB[indexB];\n    pathBLength = pathALength;\n  }\n  let depth = pathALength;\n  while (depth--) {\n    if (itemA === itemB) {\n      return itemA;\n    }\n    itemA = pathA[indexA++];\n    itemB = pathB[indexB++];\n  }\n  return null;\n}\nfunction hasTargetTouches(target, touches) {\n  if (!touches || touches.length === 0) {\n    return false;\n  }\n  for (let i = 0; i < touches.length; i++) {\n    const node = touches[i].target;\n    if (node != null) {\n      if (target.contains(node)) {\n        return true;\n      }\n    }\n  }\n  return false;\n}\nfunction hasValidSelection(domEvent) {\n  if (domEvent.type === \"selectionchange\") {\n    return isSelectionValid();\n  }\n  return domEvent.type === \"select\";\n}\nfunction isPrimaryPointerDown(domEvent) {\n  const { altKey, button, buttons, ctrlKey, type } = domEvent;\n  const isTouch = type === \"touchstart\" || type === \"touchmove\";\n  const isPrimaryMouseDown = type === \"mousedown\" && (button === 0 || buttons === 1);\n  const isPrimaryMouseMove = type === \"mousemove\" && buttons === 1;\n  const noModifiers = altKey === false && ctrlKey === false;\n  if (isTouch || isPrimaryMouseDown && noModifiers || isPrimaryMouseMove && noModifiers) {\n    return true;\n  }\n  return false;\n}\nfunction isSelectionValid() {\n  const selection = window.getSelection();\n  if (!selection) return false;\n  const string = selection.toString();\n  const anchorNode = selection.anchorNode;\n  const focusNode = selection.focusNode;\n  const isTextNode = anchorNode && anchorNode.nodeType === window.Node.TEXT_NODE || focusNode && focusNode.nodeType === window.Node.TEXT_NODE;\n  return string.length >= 1 && string !== \"\\n\" && !!isTextNode;\n}\nexport {\n  canUseDOM,\n  getBoundingClientRect,\n  getLowestCommonAncestor,\n  getResponderPaths,\n  hasTargetTouches,\n  hasValidSelection,\n  isPrimaryPointerDown,\n  isSelectionValid,\n  setResponderId\n};\n//# sourceMappingURL=utils.js.map\n"],"mappings":";AAAA,MAAM,UAAU;AAChB,MAAM,YAAY,CAAC,EAAE,OAAO,WAAW,eAAe,OAAO,YAAY,OAAO,SAAS;AACzF,MAAM,yBAAyB,SAAS;CACtC,IAAI,CAAC,MAAM;CACX,IAAI,KAAK,aAAa,GAAG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