{"version":3,"sources":["../../../../src/visualBuilder/utils/getChildrenDirection.ts"],"sourcesContent":["import getChildElements from \"./getChildElements\";\n\n\nconst validPositions = [\"vertical\", \"horizontal\", \"none\"] as const;\ntype ValidPositions = typeof validPositions[number];\n\nexport default function getChildrenDirection(\n    editableElement: Element,\n    parentCslpValue: string\n): ValidPositions {\n    if (!editableElement) {\n        return \"none\";\n    }\n\n    const parentElement = editableElement.closest(\n        `[data-cslp=\"${parentCslpValue}\"]`\n    );\n\n    if (!parentElement) {\n        return \"none\";\n    }\n\n    const directionFromParentElement =\n        parentElement.getAttribute(\"data-add-direction\");\n\n    const isValidParentDirection = validPositions.includes(\n        directionFromParentElement as ValidPositions\n    );\n\n\n    if (directionFromParentElement && isValidParentDirection) {\n        return directionFromParentElement as ValidPositions;\n    }\n    const [firstChildElement, secondChildElement, removeClone] =\n        getChildElements(parentElement, parentCslpValue);\n\n    if (!firstChildElement) return \"none\";\n\n    // get horizontal and vertical position differences\n    const firstChildBounds = firstChildElement.getBoundingClientRect();\n    const secondChildBounds = secondChildElement.getBoundingClientRect();\n\n    const deltaX = Math.abs(firstChildBounds.left - secondChildBounds.left);\n    const deltaY = Math.abs(firstChildBounds.top - secondChildBounds.top);\n\n    const dir = deltaX > deltaY ? \"horizontal\" : \"vertical\";\n\n    // remove the clone that was created in case there was only one child\n    removeClone();\n\n    return dir;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAA6B;AAG7B,IAAM,iBAAiB,CAAC,YAAY,cAAc,MAAM;AAGzC,SAAR,qBACH,iBACA,iBACc;AACd,MAAI,CAAC,iBAAiB;AAClB,WAAO;AAAA,EACX;AAEA,QAAM,gBAAgB,gBAAgB;AAAA,IAClC,eAAe,eAAe;AAAA,EAClC;AAEA,MAAI,CAAC,eAAe;AAChB,WAAO;AAAA,EACX;AAEA,QAAM,6BACF,cAAc,aAAa,oBAAoB;AAEnD,QAAM,yBAAyB,eAAe;AAAA,IAC1C;AAAA,EACJ;AAGA,MAAI,8BAA8B,wBAAwB;AACtD,WAAO;AAAA,EACX;AACA,QAAM,CAAC,mBAAmB,oBAAoB,WAAW,QACrD,wBAAAA,SAAiB,eAAe,eAAe;AAEnD,MAAI,CAAC,kBAAmB,QAAO;AAG/B,QAAM,mBAAmB,kBAAkB,sBAAsB;AACjE,QAAM,oBAAoB,mBAAmB,sBAAsB;AAEnE,QAAM,SAAS,KAAK,IAAI,iBAAiB,OAAO,kBAAkB,IAAI;AACtE,QAAM,SAAS,KAAK,IAAI,iBAAiB,MAAM,kBAAkB,GAAG;AAEpE,QAAM,MAAM,SAAS,SAAS,eAAe;AAG7C,cAAY;AAEZ,SAAO;AACX;","names":["getChildElements"]}