UNPKG

sketch-json-parse

Version:

sketch-json解析

56 lines (55 loc) 1.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseFill = void 0; const utils_1 = require("../common/utils"); /** * 填充样式解析 * 0. 画板=>取背景色即可 * 1. 填充解析 * a. 对纯色填充、渐变填充进行了解析。 * b. 图片填充及其他填充未进行解析。 * * @param layer */ const parseFill = (layer) => { // 1. 画板 => 取背景色即可 if (layer._class === "artboard") { if (layer.hasBackgroundColor) { return [ { type: 0, color: (0, utils_1.transSketchColor)(layer.backgroundColor), }, ]; } else { layer.style.fills = []; return []; } } // 2. 其他图层 const { fills = [] } = layer.style; return (fills // 过滤出纯色、渐变切可用的填充 .filter(({ isEnabled, fillType }) => isEnabled && [0, 1].includes(fillType)) .map(({ fillType, color, gradient }) => { // 纯色填充 if (fillType === 0) { return { type: 0, color: (0, utils_1.transSketchColor)(color), }; } // 渐变填充 if (fillType === 1 && [0, 1, 2].includes(gradient.gradientType)) { return { type: gradient.gradientType + 1, // 填充类型转换 stops: gradient.stops.map(({ position, color }) => ({ position, color: (0, utils_1.transSketchColor)(color), })), }; } })); }; exports.parseFill = parseFill;