UNPKG

sketch-json-parse

Version:

sketch-json解析

42 lines (41 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseBorder = void 0; const utils_1 = require("../common/utils"); /** * 边框解析 * 1. 对纯色填充、渐变填充进行了解析。 * 2. TODO 图片填充及其他填充未进行解析。 * * @param layer */ const parseBorder = (layer) => { const { borders = [] } = layer.style; return borders.filter(({ isEnabled, fillType }) => isEnabled && ([0, 1].includes(fillType))) // 过滤出纯色、渐变切可用的填充边框才解析 .map(({ position, thickness, color, fillType, gradient }) => { let fill; // 纯色填充 if (fillType === 0) { fill = { type: 0, color: (0, utils_1.transSketchColor)(color) }; // 渐变填充 } else if (fillType === 1 && [0, 1, 2].includes(gradient.gradientType)) { fill = { type: gradient.gradientType + 1, // 填充类型转换 stops: gradient.stops.map(({ position, color }) => ({ position, color: (0, utils_1.transSketchColor)(color), })) }; } return { position: +position, thickness, fill }; }); }; exports.parseBorder = parseBorder;