sketch-json-parse
Version:
sketch-json解析
48 lines (47 loc) • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasShadowByLayer = exports.hasBorderRadiusByLayer = exports.hasBackgroundByLayer = exports.hasBorderByLayer = exports.uniqueId = void 0;
const uniqueId = () => {
return Math.random().toString(32).substr(2, 8);
};
exports.uniqueId = uniqueId;
// 判断图层是否有边框
const hasBorderByLayer = (item) => {
if (!(item.structure.border && item.structure.border.top.width)) {
return false;
}
return true;
};
exports.hasBorderByLayer = hasBorderByLayer;
// 判断图层是否有背景
const hasBackgroundByLayer = (item) => {
var _a, _b, _c, _d, _e, _f;
if (!((_b = (_a = item.style) === null || _a === void 0 ? void 0 : _a.background) === null || _b === void 0 ? void 0 : _b.color) &&
!((_d = (_c = item.style) === null || _c === void 0 ? void 0 : _c.background) === null || _d === void 0 ? void 0 : _d.linearGradient) &&
!((_f = (_e = item.style) === null || _e === void 0 ? void 0 : _e.background) === null || _f === void 0 ? void 0 : _f.radialGradient)) {
return false;
}
return true;
};
exports.hasBackgroundByLayer = hasBackgroundByLayer;
// 判断图层是否有圆角
const hasBorderRadiusByLayer = (item) => {
var _a, _b, _c, _d, _e, _f, _g, _h;
if (!((_b = (_a = item.style) === null || _a === void 0 ? void 0 : _a.borderRadius) === null || _b === void 0 ? void 0 : _b.topLeft) &&
!((_d = (_c = item.style) === null || _c === void 0 ? void 0 : _c.borderRadius) === null || _d === void 0 ? void 0 : _d.topRight) &&
!((_f = (_e = item.style) === null || _e === void 0 ? void 0 : _e.borderRadius) === null || _f === void 0 ? void 0 : _f.bottomLeft) &&
!((_h = (_g = item.style) === null || _g === void 0 ? void 0 : _g.borderRadius) === null || _h === void 0 ? void 0 : _h.bottomRight)) {
return false;
}
return true;
};
exports.hasBorderRadiusByLayer = hasBorderRadiusByLayer;
// 判断图层是否有阴影
const hasShadowByLayer = (item) => {
var _a, _b;
if (!((_b = (_a = item.style) === null || _a === void 0 ? void 0 : _a.boxShadow) === null || _b === void 0 ? void 0 : _b.length)) {
return false;
}
return true;
};
exports.hasShadowByLayer = hasShadowByLayer;