sketch-json-parse
Version:
sketch-json解析
59 lines (58 loc) • 2.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const getBorderWidth_1 = require("./getBorderWidth");
const utils_1 = require("./utils");
/**
*处理绝对定位
*
* @param {*} dataIsPositionLayout 需要绝对定位的数组
* @param {*} parent 父图层
* @param {*} data 通过其他方式布局的数组
* @returns
*/
const handleOverlap = (dataIsPositionLayout, parent, data) => {
var _a;
if (!parent || dataIsPositionLayout.length == 0) {
return data;
}
const { borderTopWidth: parentBorderTopWidth, borderLeftWidth: parentBorderLeftWidth, } = (0, getBorderWidth_1.default)(parent);
if (parent._class == "artboard") {
parent.style["overflow"] = "hidden";
}
// if (!parent.style['position']) {
// parent.style['position'] = 'relative';
// }
for (let i = 0; i < dataIsPositionLayout.length; i++) {
if (!((_a = dataIsPositionLayout[i].children) === null || _a === void 0 ? void 0 : _a.length)) {
const fixedPointView = Object.assign(Object.assign({}, dataIsPositionLayout[i]), { componentName: "FixedPointView", id: (0, utils_1.uniqueId)() });
fixedPointView.style["left"] =
fixedPointView.structure.x - parent.structure.x - parentBorderLeftWidth;
fixedPointView.style["top"] =
fixedPointView.structure.y - parent.structure.y - parentBorderTopWidth;
fixedPointView.style["width"] = fixedPointView.structure.width || "auto";
fixedPointView.style["height"] = fixedPointView.structure.height;
fixedPointView.style["zIndex"] = fixedPointView.structure.zIndex;
const item = JSON.parse(JSON.stringify(dataIsPositionLayout[i]));
// 设置为false,避免递归处理
item.isPosition = false;
fixedPointView.children = [item];
dataIsPositionLayout[i] = fixedPointView;
}
else {
// dataIsPositionLayout[i].style.position = 'absolute';
dataIsPositionLayout[i]["componentName"] = "FixedPointView";
dataIsPositionLayout[i].style['left'] = dataIsPositionLayout[i].structure.x - parent.structure.x - parentBorderLeftWidth;
dataIsPositionLayout[i].style['top'] = dataIsPositionLayout[i].structure.y - parent.structure.y - parentBorderTopWidth;
dataIsPositionLayout[i].style["width"] =
dataIsPositionLayout[i].structure.width || "auto";
dataIsPositionLayout[i].style["height"] =
dataIsPositionLayout[i].structure.height;
dataIsPositionLayout[i].style["zIndex"] = dataIsPositionLayout[i].structure.zIndex;
}
}
data = [...data, ...dataIsPositionLayout];
parent.children = data;
data = parent.children;
return data;
};
exports.default = handleOverlap;