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.prod.util.dragAndDrop.findClosestPosition.js.map Maven / Gradle / Ivy
{
"version": 3,
"sources": ["../../../../src/util/dragAndDrop/findClosestPosition.ts"],
"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"],
"mappings": "aAAA,OAAOA,MAAmB,+BAC1B,OAAOC,MAAiB,6BAExB,MAAMC,EAAmB,CAACC,EAAeC,EAAqBC,EAAqBC,IAAuB,CACzG,MAAMC,EAAoB,KAAK,IAAIJ,EAAQC,CAAW,EAChDI,EAAoB,KAAK,IAAIL,EAAQE,CAAW,EAChDI,EAAmB,KAAK,IAAIN,EAAQG,CAAU,EAC9CI,EAAe,KAAK,IACzBH,EACAC,EACAC,CACD,EACA,IAAIE,EAAmC,CAAC,EAExC,OAAQD,EAAc,CACtB,KAAKH,EACJI,EAAa,CAACX,EAAc,MAAM,EAClC,MACD,KAAKQ,EACJG,EAAa,CAACX,EAAc,GAAIO,EAAoBE,EAAmBT,EAAc,OAASA,EAAc,KAAK,EACjH,MACD,KAAKS,EACJE,EAAa,CAACX,EAAc,KAAK,EACjC,KACD,CAEA,OAAOW,CACR,EAEMC,EAAsB,CAACC,EAA8BV,EAAeW,IAAmC,CAC5G,IAAIC,EAAe,OAAO,kBACtBC,EAAqC,KAGzC,QAASC,EAAI,EAAGA,EAAIJ,EAAS,OAAQI,IAAK,CACzC,MAAMC,EAAKL,EAASI,CAAC,EACf,CACL,KAAAE,EAAM,MAAAC,EAAO,IAAAC,EAAK,OAAAC,CACnB,EAAIJ,EAAG,sBAAsB,EAE7B,IAAIK,EACAT,IAAsBb,EAAY,SACrCsB,EAAaF,EAAMC,EAAS,EAE5BC,EAAaJ,EAAOC,EAAQ,EAG7B,MAAMI,EAAmB,KAAK,IAAIrB,EAAQoB,CAAU,EAEhDC,EAAmBT,IACtBA,EAAeS,EACfR,EAAiBE,EAEnB,CAEA,GAAI,CAACF,EACJ,OAAO,KAGR,KAAM,CACL,MAAAI,EAAO,OAAAE,EAAQ,KAAAH,EAAM,MAAAM,EAAO,IAAAJ,EAAK,OAAAK,CAClC,EAAIV,EAAe,sBAAsB,EACzC,IAAIL,EAEJ,OAAIG,IAAsBb,EAAY,SACrCU,EAAaT,EAAiBC,EAAOkB,EAAKA,EAAMC,EAAS,EAAGI,CAAM,EAElEf,EAAaT,EAAiBC,EAAOgB,EAAMA,EAAOC,EAAQ,EAAGK,CAAK,EAG5D,CACN,QAAST,EACT,WAAAL,CACD,CACD,EAEA,eAAeC",
"names": ["MovePlacement", "Orientation", "closestPlacement", "point", "beforePoint", "centerPoint", "afterPoint", "distToBeforePoint", "distToCenterPoint", "distToAfterPoint", "closestPoint", "placements", "findClosestPosition", "elements", "layoutOrientation", "shortestDist", "closestElement", "i", "el", "left", "width", "top", "height", "elemCenter", "distanceToCenter", "right", "bottom"]
}