Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
package.dist.util.dragAndDrop.findClosestPosition.js.map Maven / Gradle / Ivy
{"version":3,"file":"findClosestPosition.js","sourceRoot":"","sources":["../../../src/util/dragAndDrop/findClosestPosition.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,8BAA8B,CAAC;AACzD,OAAO,WAAW,MAAM,4BAA4B,CAAC;AAErD,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,WAAmB,EAAE,WAAmB,EAAE,UAAkB,EAAE,EAAE;IACxG,MAAM,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,WAAW,CAAC,CAAC;IACxD,MAAM,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,WAAW,CAAC,CAAC;IACxD,MAAM,gBAAgB,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC;IACtD,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAC5B,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,CAChB,CAAC;IACF,IAAI,UAAU,GAAyB,EAAE,CAAC;IAE1C,QAAQ,YAAY,EAAE;QACtB,KAAK,iBAAiB;YACrB,UAAU,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;YACpC,MAAM;QACP,KAAK,iBAAiB;YACrB,UAAU,GAAG,CAAC,aAAa,CAAC,EAAE,EAAE,iBAAiB,GAAG,gBAAgB,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YACnH,MAAM;QACP,KAAK,gBAAgB;YACpB,UAAU,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YACnC,MAAM;KACN;IAED,OAAO,UAAU,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,CA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GAAG,gBAAgB,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;KACpE;IAED,OAAO;QACN,OAAO,EAAE,cAAc;QACvB,UAAU;KACV,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,mBAAmB,CAAC","sourcesContent":["import MovePlacement from \"../../types/MovePlacement.js\";\nimport Orientation from \"../../types/Orientation.js\";\n\nconst closestPlacement = (point: number, beforePoint: number, centerPoint: number, afterPoint: number) => {\n\tconst distToBeforePoint = Math.abs(point - beforePoint);\n\tconst distToCenterPoint = Math.abs(point - centerPoint);\n\tconst distToAfterPoint = Math.abs(point - afterPoint);\n\tconst closestPoint = Math.min(\n\t\tdistToBeforePoint,\n\t\tdistToCenterPoint,\n\t\tdistToAfterPoint,\n\t);\n\tlet placements: Array = [];\n\n\tswitch (closestPoint) {\n\tcase distToBeforePoint:\n\t\tplacements = [MovePlacement.Before];\n\t\tbreak;\n\tcase distToCenterPoint:\n\t\tplacements = [MovePlacement.On, distToBeforePoint < distToAfterPoint ? MovePlacement.Before : MovePlacement.After];\n\t\tbreak;\n\tcase distToAfterPoint:\n\t\tplacements = [MovePlacement.After];\n\t\tbreak;\n\t}\n\n\treturn placements;\n};\n\nconst findClosestPosition = (elements: Array, point: number, layoutOrientation: Orientation) => {\n\tlet shortestDist = Number.POSITIVE_INFINITY;\n\tlet closestElement: HTMLElement | null = null;\n\n\t// determine which element is most closest to the point\n\tfor (let i = 0; i < elements.length; i++) {\n\t\tconst el = elements[i];\n\t\tconst {\n\t\t\tleft, width, top, height,\n\t\t} = el.getBoundingClientRect();\n\n\t\tlet elemCenter;\n\t\tif (layoutOrientation === Orientation.Vertical) {\n\t\t\telemCenter = top + height / 2;\n\t\t} else { // Horizontal\n\t\t\telemCenter = left + width / 2;\n\t\t}\n\n\t\tconst distanceToCenter = Math.abs(point - elemCenter);\n\n\t\tif (distanceToCenter < shortestDist) {\n\t\t\tshortestDist = distanceToCenter;\n\t\t\tclosestElement = el;\n\t\t}\n\t}\n\n\tif (!closestElement) {\n\t\treturn null;\n\t}\n\n\tconst {\n\t\twidth, height, left, right, top, bottom,\n\t} = closestElement.getBoundingClientRect();\n\tlet placements;\n\n\tif (layoutOrientation === Orientation.Vertical) {\n\t\tplacements = closestPlacement(point, top, top + height / 2, bottom);\n\t} else { // Horizontal\n\t\tplacements = closestPlacement(point, left, left + width / 2, right);\n\t}\n\n\treturn {\n\t\telement: closestElement,\n\t\tplacements,\n\t};\n};\n\nexport default findClosestPosition;\n"]}