{"version":3,"file":"utils.cjs","sources":["../../../../../../.yarn/__virtual__/@uiw-react-drag-event-interactive-virtual-1abbdfb42c/4/.yarn/berry/cache/@uiw-react-drag-event-interactive-npm-2.9.2-c933e8d8ee-10c0.zip/node_modules/@uiw/react-drag-event-interactive/esm/utils.js"],"sourcesContent":["import { useRef, useEffect, useCallback } from 'react';\n\n// Saves incoming handler to the ref in order to avoid \"useCallback hell\"\nexport function useEventCallback(handler) {\n  var callbackRef = useRef(handler);\n  useEffect(() => {\n    callbackRef.current = handler;\n  });\n  return useCallback((value, event) => callbackRef.current && callbackRef.current(value, event), []);\n}\n\n// Check if an event was triggered by touch\nexport var isTouch = event => 'touches' in event;\n\n// Browsers introduced an intervention, making touch events passive by default.\n// This workaround removes `preventDefault` call from the touch handlers.\n// https://github.com/facebook/react/issues/19651\nexport var preventDefaultMove = event => {\n  !isTouch(event) && event.preventDefault && event.preventDefault();\n};\n// Clamps a value between an upper and lower bound.\n// We use ternary operators because it makes the minified code\n// 2 times shorter then `Math.min(Math.max(a,b),c)`\nexport var clamp = function clamp(number, min, max) {\n  if (min === void 0) {\n    min = 0;\n  }\n  if (max === void 0) {\n    max = 1;\n  }\n  return number > max ? max : number < min ? min : number;\n};\n// Returns a relative position of the pointer inside the node's bounding box\nexport var getRelativePosition = (node, event) => {\n  var rect = node.getBoundingClientRect();\n\n  // Get user's pointer position from `touches` array if it's a `TouchEvent`\n  var pointer = isTouch(event) ? event.touches[0] : event;\n  return {\n    left: clamp((pointer.pageX - (rect.left + window.pageXOffset)) / rect.width),\n    top: clamp((pointer.pageY - (rect.top + window.pageYOffset)) / rect.height),\n    width: rect.width,\n    height: rect.height,\n    x: pointer.pageX - (rect.left + window.pageXOffset),\n    y: pointer.pageY - (rect.top + window.pageYOffset)\n  };\n};"],"names":["useRef","useEffect","useCallback","clamp"],"mappings":";;;AAGO,SAAS,iBAAiB,SAAS;AACxC,MAAI,cAAcA,MAAAA,OAAO,OAAO;AAChCC,QAAAA,UAAU,MAAM;AACd,gBAAY,UAAU;AAAA,EACxB,CAAC;AACD,SAAOC,kBAAY,CAAC,OAAO,UAAU,YAAY,WAAW,YAAY,QAAQ,OAAO,KAAK,GAAG,CAAA,CAAE;AACnG;AAGU,IAAC,UAAU,WAAS,aAAa;AAKjC,IAAC,qBAAqB,WAAS;AACvC,GAAC,QAAQ,KAAK,KAAK,MAAM,kBAAkB,MAAM,eAAc;AACjE;AAIU,IAAC,QAAQ,SAASC,OAAM,QAAQ,KAAK,KAAK;AAClD,MAAI,QAAQ,QAAQ;AAClB,UAAM;AAAA,EACR;AACA,MAAI,QAAQ,QAAQ;AAClB,UAAM;AAAA,EACR;AACA,SAAO,SAAS,MAAM,MAAM,SAAS,MAAM,MAAM;AACnD;AAEU,IAAC,sBAAsB,CAAC,MAAM,UAAU;AAChD,MAAI,OAAO,KAAK,sBAAqB;AAGrC,MAAI,UAAU,QAAQ,KAAK,IAAI,MAAM,QAAQ,CAAC,IAAI;AAClD,SAAO;AAAA,IACL,MAAM,OAAO,QAAQ,SAAS,KAAK,OAAO,OAAO,gBAAgB,KAAK,KAAK;AAAA,IAC3E,KAAK,OAAO,QAAQ,SAAS,KAAK,MAAM,OAAO,gBAAgB,KAAK,MAAM;AAAA,IAC1E,OAAO,KAAK;AAAA,IACZ,QAAQ,KAAK;AAAA,IACb,GAAG,QAAQ,SAAS,KAAK,OAAO,OAAO;AAAA,IACvC,GAAG,QAAQ,SAAS,KAAK,MAAM,OAAO;AAAA,EAC1C;AACA;;;;;;","x_google_ignoreList":[0]}