// import cloneDeep from 'lodash/cloneDeep';
// import { getLineInfo, getSelectionBox } from './selection-box';
// import { getSelectedObjectPath } from './common';
// import { SUPA_PLAYER_CLASS_PREFIX } from '../../../constants';
// export function getBoundingBox(obj, slides) {
// const { slideIndex, objectIndex } = getSelectedObjectPath(slides, obj.id);
// const playerDOM = document.querySelector('.supa-player-holder');
// const objDOM = playerDOM.querySelector(`div[slide-index='${slideIndex}'][object-index='${objectIndex}']`);
// const selectionBox = getSelectionBox(objDOM, obj);
// // For lines we have an extended box that already includes the curve point,
// // so use it in bounding-box calculations when available.
// const points = selectionBox.lineBoxWithCurvePoints || selectionBox.objectPoints;
// const x = points.map((coords) => coords[0]);
// const y = points.map((coords) => coords[1]);
// const minX = Math.min(...x);
// const minY = Math.min(...y);
// const maxX = Math.max(...x);
// const maxY = Math.max(...y);
// return {
// obj,
// box: {
// minX,
// minY,
// maxX,
// maxY,
// midX: (minX + maxX) / 2,
// midY: (minY + maxY) / 2,
// },
// };
// }
// function getSize(obj, slides, zoom) {
// const { slideIndex, objectIndex } = getSelectedObjectPath(slides, obj.id);
// const playerDOM = document.querySelector('.editor__player .supa-player-holder');
// const objDOM = playerDOM?.querySelector(`div[slide-index='${slideIndex}'][object-index='${objectIndex}']`);
// const transformLayer = objDOM?.querySelector(`.${SUPA_PLAYER_CLASS_PREFIX}slide-object-transform-layer`);
// if (!objDOM || !transformLayer) return undefined;
// const boundings = objDOM.getBoundingClientRect();
// const boundings2 = transformLayer.getBoundingClientRect();
// console.log('objDOM', objDOM, transformLayer);
// const diffX = (boundings2.width - boundings.width) / 2 / zoom;
// const diffY = (boundings2.height - boundings.height) / 2 / zoom;
// let result = {
// offsetX: Math.round(diffX),
// offsetY: Math.round(diffY),
// width: Math.round(boundings.width / zoom),
// height: Math.round(boundings.height / zoom),
// };
// // For lines use getLineInfo + curve point so alignSingle* can use same logic (no DOM)
// if (obj.type === 'line') {
// const lineInfo = getLineInfo(obj);
// const curvePoint = obj.style?.points?.[0];
// const points = [
// [lineInfo.start.x, lineInfo.start.y],
// [lineInfo.end.x, lineInfo.end.y],
// ...(curvePoint ? [curvePoint] : []),
// ];
// if (points.length) {
// const xs = points.map((p) => p[0]);
// const ys = points.map((p) => p[1]);
// const minX = Math.min(...xs);
// const maxX = Math.max(...xs);
// const minY = Math.min(...ys);
// const maxY = Math.max(...ys);
// result = {
// ...result,
// width: maxX - minX,
// height: maxY - minY,
// box: {
// minX,
// maxX,
// minY,
// maxY,
// midX: (minX + maxX) / 2,
// midY: (minY + maxY) / 2,
// },
// };
// }
// }
// return result;
// }
// function getAlignedGroupChilds(alignedObject, slides, key, parentOffset) {
// if (alignedObject.type !== 'group') return [];
// const diff = parentOffset - alignedObject[key];
// return alignedObject.objects.map((id) => {
// const { slideIndex, objectIndex } = getSelectedObjectPath(slides, id);
// const obj = slides[slideIndex].objects[objectIndex];
// return { ...obj, [key]: Math.round(obj[key] + diff) };
// });
// }
// export function getBoundingBoxWithExtremeParam(boundingBoxes, param, type) {
// const f = (type === 'first')
// ? (e1, e2) => e1.box[param] > e2.box[param]
// : (e1, e2) => e1.box[param] < e2.box[param];
// return boundingBoxes.reduce((res, curr) => (f(res, curr) ? curr : res), boundingBoxes[0]);
// }
// function spread(direction, selectedObjects, slides) {
// const min = direction === 'x' ? 'minX' : 'minY';
// const max = direction === 'x' ? 'maxX' : 'maxY';
// const mid = direction === 'x' ? 'midX' : 'midY';
// const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
// const cloneBoundingBoxes = cloneDeep(boundingBoxes);
// const firstBox = getBoundingBoxWithExtremeParam(cloneBoundingBoxes, min, 'first');
// const lastBox = getBoundingBoxWithExtremeParam(cloneBoundingBoxes, max, 'last');
// const middleBoxes = cloneBoundingBoxes
// .filter((x) => ![firstBox, lastBox].includes(x))
// .sort((a, b) => a.box[mid] - b.box[mid]);
// const length = lastBox.box[min] - firstBox.box[max];
// const middleBoxesLength = middleBoxes.reduce(
// (acc, curr) => acc + (curr.box[max] - curr.box[min]),
// 0,
// );
// const step = (length - middleBoxesLength) / (middleBoxes.length + 1);
// let acc = firstBox.box[max] + step;
// const groupChildsUpdated = [];
// middleBoxes.forEach((x) => {
// const boxLength = x.box[max] - x.box[min];
// const newVal = Math.round(boxLength / 2 + acc - x.box[mid]);
// groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, direction, x.obj[direction] + newVal));
// x.obj[direction] += newVal;
// acc += step + boxLength;
// });
// return [...middleBoxes.map((item) => item.obj), ...groupChildsUpdated];
// }
// export const alignFunctions = {
// alignLeft: (selectedObjects, slides) => {
// const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
// const minX = Math.min(...boundingBoxes.map((x) => x.box.minX));
// const cloneBoundingBoxes = cloneDeep(boundingBoxes);
// const groupChildsUpdated = [];
// cloneBoundingBoxes.forEach((x) => {
// groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, 'x', x.obj.x + Math.round(minX - x.box.minX)));
// x.obj.x += Math.round(minX - x.box.minX);
// });
// return [...cloneBoundingBoxes.map((item) => item.obj), ...groupChildsUpdated];
// },
// alignRight: (selectedObjects, slides) => {
// const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
// const maxX = Math.max(...boundingBoxes.map((x) => x.box.maxX));
// const cloneBoundingBoxes = cloneDeep(boundingBoxes);
// const groupChildsUpdated = [];
// cloneBoundingBoxes.forEach((x) => {
// groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, 'x', x.obj.x + Math.round(maxX - x.box.maxX)));
// x.obj.x += Math.round(maxX - x.box.maxX);
// });
// return [...cloneBoundingBoxes.map((item) => item.obj), ...groupChildsUpdated];
// },
// alignBottom: (selectedObjects, slides) => {
// const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
// const maxY = Math.max(...boundingBoxes.map((x) => x.box.maxY));
// const cloneBoundingBoxes = cloneDeep(boundingBoxes);
// const groupChildsUpdated = [];
// cloneBoundingBoxes.forEach((x) => {
// groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, 'y', x.obj.y + Math.round(maxY - x.box.maxY)));
// x.obj.y += Math.round(maxY - x.box.maxY);
// });
// return [...cloneBoundingBoxes.map((item) => item.obj), ...groupChildsUpdated];
// },
// alignTop: (selectedObjects, slides) => {
// const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
// const minY = Math.min(...boundingBoxes.map((x) => x.box.minY));
// const cloneBoundingBoxes = cloneDeep(boundingBoxes);
// const groupChildsUpdated = [];
// cloneBoundingBoxes.forEach((x) => {
// groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, 'y', x.obj.y + Math.round(minY - x.box.minY)));
// x.obj.y += Math.round(minY - x.box.minY);
// });
// return [...cloneBoundingBoxes.map((item) => item.obj), ...groupChildsUpdated];
// },
// alignHorizontal: (selectedObjects, slides) => {
// const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
// const minX = Math.min(...boundingBoxes.map((x) => x.box.minX));
// const maxX = Math.max(...boundingBoxes.map((x) => x.box.maxX));
// const midX = (minX + maxX) / 2;
// const cloneBoundingBoxes = cloneDeep(boundingBoxes);
// const groupChildsUpdated = [];
// cloneBoundingBoxes.forEach((x) => {
// groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, 'x', x.obj.x + Math.round(midX - x.box.midX)));
// x.obj.x += Math.round(midX - x.box.midX);
// });
// return [...cloneBoundingBoxes.map((item) => item.obj), ...groupChildsUpdated];
// },
// alignVertical: (selectedObjects, slides) => {
// const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
// const minY = Math.min(...boundingBoxes.map((x) => x.box.minY));
// const maxY = Math.max(...boundingBoxes.map((x) => x.box.maxY));
// const midY = (minY + maxY) / 2;
// const cloneBoundingBoxes = cloneDeep(boundingBoxes);
// const groupChildsUpdated = [];
// cloneBoundingBoxes.forEach((x) => {
// groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, 'y', x.obj.y + Math.round(midY - x.box.midY)));
// x.obj.y += Math.round(midY - x.box.midY);
// });
// return [...cloneBoundingBoxes.map((item) => item.obj), ...groupChildsUpdated];
// },
// spreadHorizontal: (selectedObjects, slides) => spread('x', selectedObjects, slides),
// spreadVertical: (selectedObjects, slides) => spread('y', selectedObjects, slides),
// alignSingleLeft: (selectedObjects, slides, size, zoom) => {
// const obj = selectedObjects[0];
// const sizeResult = getSize(obj, slides, zoom);
// if (!sizeResult) return [];
// const { offsetX, box } = sizeResult;
// console.log('offsetX', offsetX)
// const newX = box
// ? obj.x + Math.round(offsetX - box.minX)
// : Math.round(0 + offsetX);
// const groupChilds = getAlignedGroupChilds(obj, slides, 'x', newX);
// return [{ ...cloneDeep(obj), x: newX }, ...groupChilds];
// },
// alignSingleVertical: (selectedObjects, slides, size, zoom) => {
// const obj = selectedObjects[0];
// const sizeResult = getSize(obj, slides, zoom);
// if (!sizeResult) return [];
// const { height, box } = sizeResult;
// const newY = box
// ? obj.y + Math.round((size[1] / 2) - box.midY)
// : Math.round((size[1] / 2) - (height / 2));
// const groupChilds = getAlignedGroupChilds(obj, slides, 'y', newY);
// return [{ ...cloneDeep(obj), y: newY }, ...groupChilds];
// },
// alignSingleRight: (selectedObjects, slides, size, zoom) => {
// const obj = selectedObjects[0];
// const sizeResult = getSize(obj, slides, zoom);
// if (!sizeResult) return [];
// const { width, offsetX, box } = sizeResult;
// const newX = box
// ? obj.x + Math.round((size[0] - offsetX) - box.maxX)
// : Math.round(size[0] - width - offsetX);
// const groupChilds = getAlignedGroupChilds(obj, slides, 'x', newX);
// return [{ ...cloneDeep(obj), x: newX }, ...groupChilds];
// },
// alignSingleTop: (selectedObjects, slides, size, zoom) => {
// const obj = selectedObjects[0];
// const sizeResult = getSize(obj, slides, zoom);
// if (!sizeResult) return [];
// const { offsetY, box } = sizeResult;
// const newY = box
// ? obj.y + Math.round(offsetY - box.minY)
// : Math.round(0 + offsetY);
// const groupChilds = getAlignedGroupChilds(obj, slides, 'y', newY);
// return [{ ...cloneDeep(obj), y: newY }, ...groupChilds];
// },
// alignSingleHorizontal: (selectedObjects, slides, size, zoom) => {
// const obj = selectedObjects[0];
// const sizeResult = getSize(obj, slides, zoom);
// if (!sizeResult) return [];
// const { width, box } = sizeResult;
// const newX = box
// ? obj.x + Math.round((size[0] / 2) - box.midX)
// : Math.round((size[0] / 2) - (width / 2));
// const groupChilds = getAlignedGroupChilds(obj, slides, 'x', newX);
// return [{ ...cloneDeep(obj), x: newX }, ...groupChilds];
// },
// alignSingleBottom: (selectedObjects, slides, size, zoom) => {
// const obj = selectedObjects[0];
// const sizeResult = getSize(obj, slides, zoom);
// if (!sizeResult) return [];
// const { height, offsetY, box } = sizeResult;
// const newY = box
// ? obj.y + Math.round((size[1] - offsetY) - box.maxY)
// : Math.round(size[1] - height - offsetY);
// const groupChilds = getAlignedGroupChilds(obj, slides, 'y', newY);
// return [{ ...cloneDeep(obj), y: newY }, ...groupChilds];
// },
// };
import cloneDeep from 'lodash/cloneDeep';
import { getLineInfo, getSelectionBox, invertPointBeyondLine } from './selection-box';
import { getSelectedObjectPath } from './common';
import { SUPA_PLAYER_CLASS_PREFIX } from '../../../constants';
export function getBoundingBox(obj, slides) {
const { slideIndex, objectIndex } = getSelectedObjectPath(slides, obj.id);
const playerDOM = document.querySelector('.supa-player-holder');
const objDOM = playerDOM.querySelector(`div[slide-index='${slideIndex}'][object-index='${objectIndex}']`);
const selectionBox = getSelectionBox(objDOM, obj);
// For lines we have an extended box that already includes the curve point,
// so use it in bounding-box calculations when available.
const points = selectionBox.lineBoxWithCurvePoints || selectionBox.objectPoints;
const x = points.map((coords) => coords[0]);
const y = points.map((coords) => coords[1]);
const minX = Math.min(...x);
const minY = Math.min(...y);
const maxX = Math.max(...x);
const maxY = Math.max(...y);
return {
obj,
box: {
minX,
minY,
maxX,
maxY,
midX: (minX + maxX) / 2,
midY: (minY + maxY) / 2,
},
};
}
function getSize(obj, slides, zoom) {
const { slideIndex, objectIndex } = getSelectedObjectPath(slides, obj.id);
const playerDOM = document.querySelector('.editor__player .supa-player-holder');
const objDOM = playerDOM?.querySelector(`div[slide-index='${slideIndex}'][object-index='${objectIndex}']`);
const transformLayer = objDOM?.querySelector(`.${SUPA_PLAYER_CLASS_PREFIX}slide-object-transform-layer`);
if (!objDOM || !transformLayer) return undefined;
const boundings = objDOM.getBoundingClientRect();
const boundings2 = transformLayer.getBoundingClientRect();
const diffX = (boundings2.width - boundings.width) / 2 / zoom;
const diffY = (boundings2.height - boundings.height) / 2 / zoom;
return {
offsetX: Math.round(diffX),
offsetY: Math.round(diffY),
width: Math.round(boundings.width / zoom),
height: Math.round(boundings.height / zoom),
};
}
function getAlignedGroupChilds(alignedObject, slides, key, parentOffset) {
if (alignedObject.type !== 'group') return [];
const diff = parentOffset - alignedObject[key];
return alignedObject.objects.map((id) => {
const { slideIndex, objectIndex } = getSelectedObjectPath(slides, id);
const obj = slides[slideIndex].objects[objectIndex];
return { ...obj, [key]: Math.round(obj[key] + diff) };
});
}
function getLinePointsInfo(obj) {
const lineInfo = getLineInfo(obj);
const curvePointRaw = obj.style?.points?.[0];
const curvePoint = curvePointRaw
? invertPointBeyondLine(
curvePointRaw,
lineInfo.start,
lineInfo.end,
lineInfo.direction,
lineInfo.normal,
obj.reflect_x,
obj.reflect_y,
)
: null;
const xs = [lineInfo.start.x, lineInfo.end.x, ...(curvePoint ? [curvePoint.x] : [])];
const ys = [lineInfo.start.y, lineInfo.end.y, ...(curvePoint ? [curvePoint.y] : [])];
const minX = Math.min(...xs);
const maxX = Math.max(...xs);
const minY = Math.min(...ys);
const maxY = Math.max(...ys);
return {
minX,
maxX,
minY,
maxY,
midX: (minX + maxX) / 2,
midY: (minY + maxY) / 2,
};
}
export function getBoundingBoxWithExtremeParam(boundingBoxes, param, type) {
const f = (type === 'first')
? (e1, e2) => e1.box[param] > e2.box[param]
: (e1, e2) => e1.box[param] < e2.box[param];
return boundingBoxes.reduce((res, curr) => (f(res, curr) ? curr : res), boundingBoxes[0]);
}
function spread(direction, selectedObjects, slides) {
const min = direction === 'x' ? 'minX' : 'minY';
const max = direction === 'x' ? 'maxX' : 'maxY';
const mid = direction === 'x' ? 'midX' : 'midY';
const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
const cloneBoundingBoxes = cloneDeep(boundingBoxes);
const firstBox = getBoundingBoxWithExtremeParam(cloneBoundingBoxes, min, 'first');
const lastBox = getBoundingBoxWithExtremeParam(cloneBoundingBoxes, max, 'last');
const middleBoxes = cloneBoundingBoxes
.filter((x) => ![firstBox, lastBox].includes(x))
.sort((a, b) => a.box[mid] - b.box[mid]);
const length = lastBox.box[min] - firstBox.box[max];
const middleBoxesLength = middleBoxes.reduce(
(acc, curr) => acc + (curr.box[max] - curr.box[min]),
0,
);
const step = (length - middleBoxesLength) / (middleBoxes.length + 1);
let acc = firstBox.box[max] + step;
const groupChildsUpdated = [];
middleBoxes.forEach((x) => {
const boxLength = x.box[max] - x.box[min];
const newVal = Math.round(boxLength / 2 + acc - x.box[mid]);
groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, direction, x.obj[direction] + newVal));
x.obj[direction] += newVal;
acc += step + boxLength;
});
return [...middleBoxes.map((item) => item.obj), ...groupChildsUpdated];
}
export const alignFunctions = {
alignLeft: (selectedObjects, slides) => {
const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
const minX = Math.min(...boundingBoxes.map((x) => x.box.minX));
const cloneBoundingBoxes = cloneDeep(boundingBoxes);
const groupChildsUpdated = [];
cloneBoundingBoxes.forEach((x) => {
groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, 'x', x.obj.x + Math.round(minX - x.box.minX)));
x.obj.x += Math.round(minX - x.box.minX);
});
return [...cloneBoundingBoxes.map((item) => item.obj), ...groupChildsUpdated];
},
alignRight: (selectedObjects, slides) => {
const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
const maxX = Math.max(...boundingBoxes.map((x) => x.box.maxX));
const cloneBoundingBoxes = cloneDeep(boundingBoxes);
const groupChildsUpdated = [];
cloneBoundingBoxes.forEach((x) => {
groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, 'x', x.obj.x + Math.round(maxX - x.box.maxX)));
x.obj.x += Math.round(maxX - x.box.maxX);
});
return [...cloneBoundingBoxes.map((item) => item.obj), ...groupChildsUpdated];
},
alignBottom: (selectedObjects, slides) => {
const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
const maxY = Math.max(...boundingBoxes.map((x) => x.box.maxY));
const cloneBoundingBoxes = cloneDeep(boundingBoxes);
const groupChildsUpdated = [];
cloneBoundingBoxes.forEach((x) => {
groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, 'y', x.obj.y + Math.round(maxY - x.box.maxY)));
x.obj.y += Math.round(maxY - x.box.maxY);
});
return [...cloneBoundingBoxes.map((item) => item.obj), ...groupChildsUpdated];
},
alignTop: (selectedObjects, slides) => {
const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
const minY = Math.min(...boundingBoxes.map((x) => x.box.minY));
const cloneBoundingBoxes = cloneDeep(boundingBoxes);
const groupChildsUpdated = [];
cloneBoundingBoxes.forEach((x) => {
groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, 'y', x.obj.y + Math.round(minY - x.box.minY)));
x.obj.y += Math.round(minY - x.box.minY);
});
return [...cloneBoundingBoxes.map((item) => item.obj), ...groupChildsUpdated];
},
alignHorizontal: (selectedObjects, slides) => {
const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
const minX = Math.min(...boundingBoxes.map((x) => x.box.minX));
const maxX = Math.max(...boundingBoxes.map((x) => x.box.maxX));
const midX = (minX + maxX) / 2;
const cloneBoundingBoxes = cloneDeep(boundingBoxes);
const groupChildsUpdated = [];
cloneBoundingBoxes.forEach((x) => {
groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, 'x', x.obj.x + Math.round(midX - x.box.midX)));
x.obj.x += Math.round(midX - x.box.midX);
});
return [...cloneBoundingBoxes.map((item) => item.obj), ...groupChildsUpdated];
},
alignVertical: (selectedObjects, slides) => {
const boundingBoxes = selectedObjects.map((obj) => getBoundingBox(obj, slides));
const minY = Math.min(...boundingBoxes.map((x) => x.box.minY));
const maxY = Math.max(...boundingBoxes.map((x) => x.box.maxY));
const midY = (minY + maxY) / 2;
const cloneBoundingBoxes = cloneDeep(boundingBoxes);
const groupChildsUpdated = [];
cloneBoundingBoxes.forEach((x) => {
groupChildsUpdated.push(...getAlignedGroupChilds(x.obj, slides, 'y', x.obj.y + Math.round(midY - x.box.midY)));
x.obj.y += Math.round(midY - x.box.midY);
});
return [...cloneBoundingBoxes.map((item) => item.obj), ...groupChildsUpdated];
},
spreadHorizontal: (selectedObjects, slides) => spread('x', selectedObjects, slides),
spreadVertical: (selectedObjects, slides) => spread('y', selectedObjects, slides),
alignSingleLeft: (selectedObjects, slides, size, zoom) => {
const obj = selectedObjects[0];
if (obj.type === 'line') {
const { minX } = getLinePointsInfo(obj);
const newX = obj.x + Math.round(0 - minX);
const groupChilds = getAlignedGroupChilds(obj, slides, 'x', newX);
return [{ ...cloneDeep(obj), x: newX }, ...groupChilds];
}
const sizeResult = getSize(obj, slides, zoom);
if (!sizeResult) return [];
const { offsetX } = sizeResult;
const newX = Math.round(0 + offsetX);
const groupChilds = getAlignedGroupChilds(obj, slides, 'x', newX);
return [{ ...cloneDeep(obj), x: newX }, ...groupChilds];
},
alignSingleVertical: (selectedObjects, slides, size, zoom) => {
const obj = selectedObjects[0];
if (obj.type === 'line') {
const { midY } = getLinePointsInfo(obj);
const newY = obj.y + Math.round((size[1] / 2) - midY);
const groupChilds = getAlignedGroupChilds(obj, slides, 'y', newY);
return [{ ...cloneDeep(obj), y: newY }, ...groupChilds];
}
const sizeResult = getSize(obj, slides, zoom);
if (!sizeResult) return [];
const { height } = sizeResult;
const newY = Math.round((size[1] / 2) - (height / 2));
const groupChilds = getAlignedGroupChilds(obj, slides, 'y', newY);
return [{ ...cloneDeep(obj), y: newY }, ...groupChilds];
},
alignSingleRight: (selectedObjects, slides, size, zoom) => {
const obj = selectedObjects[0];
if (obj.type === 'line') {
const { maxX } = getLinePointsInfo(obj);
const newX = obj.x + Math.round(size[0] - maxX);
const groupChilds = getAlignedGroupChilds(obj, slides, 'x', newX);
return [{ ...cloneDeep(obj), x: newX }, ...groupChilds];
}
const sizeResult = getSize(obj, slides, zoom);
if (!sizeResult) return [];
const { width, offsetX } = sizeResult;
const newX = Math.round(size[0] - width - offsetX);
const groupChilds = getAlignedGroupChilds(obj, slides, 'x', newX);
return [{ ...cloneDeep(obj), x: newX }, ...groupChilds];
},
alignSingleTop: (selectedObjects, slides, size, zoom) => {
const obj = selectedObjects[0];
if (obj.type === 'line') {
const { minY } = getLinePointsInfo(obj);
const newY = obj.y + Math.round(0 - minY);
const groupChilds = getAlignedGroupChilds(obj, slides, 'y', newY);
return [{ ...cloneDeep(obj), y: newY }, ...groupChilds];
}
const sizeResult = getSize(obj, slides, zoom);
if (!sizeResult) return [];
const { offsetY } = sizeResult;
const newY = Math.round(0 + offsetY);
const groupChilds = getAlignedGroupChilds(obj, slides, 'y', newY);
return [{ ...cloneDeep(obj), y: newY }, ...groupChilds];
},
alignSingleHorizontal: (selectedObjects, slides, size, zoom) => {
const obj = selectedObjects[0];
if (obj.type === 'line') {
const { midX } = getLinePointsInfo(obj);
const newX = obj.x + Math.round((size[0] / 2) - midX);
const groupChilds = getAlignedGroupChilds(obj, slides, 'x', newX);
return [{ ...cloneDeep(obj), x: newX }, ...groupChilds];
}
const sizeResult = getSize(obj, slides, zoom);
if (!sizeResult) return [];
const { width } = sizeResult;
const newX = Math.round((size[0] / 2) - (width / 2));
const groupChilds = getAlignedGroupChilds(obj, slides, 'x', newX);
return [{ ...cloneDeep(obj), x: newX }, ...groupChilds];
},
alignSingleBottom: (selectedObjects, slides, size, zoom) => {
const obj = selectedObjects[0];
if (obj.type === 'line') {
const { maxY } = getLinePointsInfo(obj);
const newY = obj.y + Math.round(size[1] - maxY);
const groupChilds = getAlignedGroupChilds(obj, slides, 'y', newY);
return [{ ...cloneDeep(obj), y: newY }, ...groupChilds];
}
const sizeResult = getSize(obj, slides, zoom);
if (!sizeResult) return [];
const { height, offsetY } = sizeResult;
const newY = Math.round(size[1] - height - offsetY);
const groupChilds = getAlignedGroupChilds(obj, slides, 'y', newY);
return [{ ...cloneDeep(obj), y: newY }, ...groupChilds];
},
};