import {Layer} from "../../../picasso-layout/src/types"; const sortLayer = (data: Layer[]) => { for (let i = 0; i < data.length; i++) { let firstLayer = JSON.parse(JSON.stringify(data[i])); for (let j = i + 1; j < data.length; j++) { let nextLayer = JSON.parse(JSON.stringify(data[j])); // 同行 if ( ((firstLayer.structure.y + firstLayer.structure.height > nextLayer.structure.y && nextLayer.structure.y >= firstLayer.structure.y) || (firstLayer.structure.y < nextLayer.structure.y + nextLayer.structure.height && nextLayer.structure.y + nextLayer.structure.height <= firstLayer.structure.y + firstLayer.structure.height)) && nextLayer.structure.x < firstLayer.structure.x ) { data[i] = nextLayer; data[j] = firstLayer; firstLayer = nextLayer; } else if ( ((firstLayer.structure.x + firstLayer.structure.width > nextLayer.structure.x && nextLayer.structure.x >= firstLayer.structure.x) || (firstLayer.structure.x < nextLayer.structure.x + nextLayer.structure.width && nextLayer.structure.x + nextLayer.structure.width <= firstLayer.structure.x + firstLayer.structure.width)) && nextLayer.structure.y < firstLayer.structure.y ) { data[i] = nextLayer; data[j] = firstLayer; firstLayer = nextLayer; } } } return data; } const sortDSL = (data: Layer[]) => { data = sortLayer(data); for (let i = 0; i < data.length; i++) { if (data[i].children && !!data[i].children.length) { data[i].children = sortDSL(data[i].children); } } return data }; export default sortDSL;