Commit 9969fdc8 authored by rockyl's avatar rockyl

兼容蒙板图层

parent 144f980e
......@@ -155,7 +155,7 @@ async function execute(psdFile, options) {
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
} else if (solidColor && layer.vectorMask) {
const {r, g, b} = solidColor();
let color = Color({r, g, b});
......
{"version":3,"file":"index.es.js","sources":["../src/psd-tree.js","../src/utils.js","../src/zeroing.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-08-09.\n */\n\nconst PSD = window['require']('psd');\n\nexport async function getTree(file) {\n\tlet psd = await PSD.fromDroppedFile(file);\n\n\tconst root = {};\n\twalk(psd.tree(), root);\n\n\treturn root;\n}\n\nfunction walk(psNode, dataNode) {\n\tconst {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};\n\tconst {left, top, width, height, name, layer: {opacity, visible}} = psNode;\n\tconst x = left - pLeft;\n\tconst y = top - pTop;\n\n\tObject.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});\n\tif (psNode.children() && psNode.children().length > 0){\n\t\tdataNode.children = [];\n\t}\n\n\tlet children = psNode.children();\n\tfor (let i = children.length - 1; i >= 0; i--) {\n\t\tconst childPsNode = children[i];\n\n\t\tconst childDataNode = {};\n\t\tdataNode.children.push(childDataNode);\n\t\twalk(childPsNode, childDataNode)\n\t}\n}\n","/**\n * Created by rockyl on 2019-08-10.\n */\n\nexport async function walkNode(node, callback, includeSelf = false) {\n\tif (includeSelf) {\n\t\tawait callback(node, null);\n\t}\n\tif (node.children && node.children.length > 0) {\n\t\tfor (let childNode of node.children) {\n\t\t\tawait callback(childNode, node);\n\t\t\tconst result = await walkNode(childNode, callback);\n\t\t\tif (result === true) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport async function walkObject(obj, callback) {\n\tif(typeof obj === \"object\"){\n\t\tfor (let key of Object.keys(obj)) {\n\t\t\tconst value = obj[key];\n\t\t\tawait callback(key, value, obj);\n\t\t\tconst result = await walkObject(value, callback);\n\t\t\tif (result === true) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n","/**\n * Created by rockyl on 2019-09-26.\n *\n * 导出zeroing的视图\n */\n\nimport {getTree} from \"./psd-tree\";\nimport {walkNode} from \"./utils\";\nimport path from 'path'\nimport Color from 'color'\nimport generateUUID from 'uuid/v4'\nimport hash from 'object-hash';\nimport zlib from 'zlib';\n\nconst relativePosPrefixMap = {\n\tl: {field: 'left',},\n\tt: {field: 'top',},\n\tr: {field: 'right',},\n\tb: {field: 'bottom',},\n\th: {field: 'horizonCenter',},\n\tv: {field: 'verticalCenter',},\n\twp: {field: 'width', isPercent: true},\n\thp: {field: 'height', isPercent: true},\n};\n\nexport async function execute(psdFile, options) {\n\tconst tree = await getTree(psdFile);\n\n\tlet viewRoot = {\n\t\tname: path.basename(psdFile.name, '.psd'),\n\t\ttype: 'node',\n\t\tuuid: generateUUID(),\n\t};\n\n\tconst assets = [];\n\tconst imageHashMap = {};\n\n\tawait walkNode(tree, async function (node, parent) {\n\t\tlet {name} = node;\n\t\tconst {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;\n\t\t//console.log('walk node:', name);\n\t\tlet properties = {\n\t\t\twidth, height, alpha, visible,\n\t\t};\n\n\t\tif (name.includes('|')) {\n\t\t\ttry {\n\t\t\t\tlet arr = name.split('|');\n\t\t\t\tname = arr[0];\n\t\t\t\tlet paramsStr = arr[1];\n\t\t\t\tlet params = paramsStr.split(';');\n\t\t\t\tlet relativePos = params[0];\n\t\t\t\tif (relativePos) {\n\t\t\t\t\tlet items = relativePos.split(',');\n\t\t\t\t\tfor (let item of items) {\n\t\t\t\t\t\tlet result = item.match(/[a-zA-Z]+/);\n\t\t\t\t\t\tif(!result){\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet prefix = result[0];\n\t\t\t\t\t\tlet mapItem = relativePosPrefixMap[prefix];\n\t\t\t\t\t\tif (mapItem) {\n\t\t\t\t\t\t\tconst {field, isPercent} = mapItem;\n\t\t\t\t\t\t\tlet value = item.substr(prefix.length);\n\t\t\t\t\t\t\tif (isPercent) {\n\t\t\t\t\t\t\t\tvalue += '%';\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tvalue = parseFloat(value);\n\t\t\t\t\t\t\t\tif (isNaN(value)) {\n\t\t\t\t\t\t\t\t\tvalue = 0;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tproperties[field] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}catch (e) {\n\t\t\t\tconsole.log(e);\n\t\t\t}\n\t\t}\n\n\t\tlet viewNode = {\n\t\t\tname,\n\t\t\tproperties,\n\t\t\tuuid: generateUUID(),\n\t\t};\n\t\tlet dealLater = true;\n\t\tif (x !== 0) {\n\t\t\tproperties.x = x;\n\t\t}\n\t\tif (y !== 0) {\n\t\t\tproperties.y = y;\n\t\t}\n\n\t\tif (typeTool) {\n\t\t\tlet fontInfo = typeTool();\n\t\t\tproperties.text = fontInfo.textValue;\n\t\t\tconst sizes = fontInfo.sizes();\n\t\t\tconst colors = fontInfo.colors();\n\t\t\tproperties.size = sizes ? sizes[0] || 20 : 20;\n\t\t\tlet [r, g, b, a] = colors[0];\n\t\t\tproperties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;\n\t\t\tviewNode.type = 'label';\n\t\t\tdealLater = false;\n\t\t} else if (solidColor) {\n\t\t\tconst {r, g, b} = solidColor();\n\t\t\tlet color = Color({r, g, b});\n\n\t\t\tlet paths = layer.vectorMask().paths;\n\t\t\tif (paths[2].numPoints === 4) {\n\t\t\t\tlet isRect = true;\n\t\t\t\tfor (let i = 3; i < paths.length; i++) {\n\t\t\t\t\tif (paths[i].recordType !== 2) {\n\t\t\t\t\t\tisRect = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (isRect) {\n\t\t\t\t\tviewNode.type = 'rect';\n\t\t\t\t\tproperties.fillColor = '#' + color.rgbNumber().toString(16);\n\t\t\t\t\tdealLater = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (dealLater) {\n\t\t\tif (node.hasOwnProperty('children')) {\n\t\t\t\tviewNode.type = 'node';\n\t\t\t} else {\n\t\t\t\tviewNode.type = 'image';\n\n\t\t\t\tlet uuid = generateUUID();\n\t\t\t\tconst ext = '.png';\n\n\t\t\t\tlet dataUrl;\n\t\t\t\ttry {\n\t\t\t\t\tlet img = node.origin.toPng();\n\t\t\t\t\tdataUrl = img.src;\n\t\t\t\t} catch (e) {\n\n\t\t\t\t}\n\n\t\t\t\tif (dataUrl) {\n\t\t\t\t\tlet base64Data = dataUrl.replace(/^data:image\\/\\w+;base64,/, \"\");\n\t\t\t\t\tlet buffer = new Buffer(base64Data, 'base64');\n\t\t\t\t\tconst fileNameHash = hash(buffer);\n\t\t\t\t\tif (imageHashMap.hasOwnProperty(fileNameHash)) {\n\t\t\t\t\t\tuuid = imageHashMap[fileNameHash];\n\t\t\t\t\t} else {\n\t\t\t\t\t\timageHashMap[fileNameHash] = uuid;\n\t\t\t\t\t\tassets.push({\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\text,\n\t\t\t\t\t\t\tuuid,\n\t\t\t\t\t\t\tbase64Data,\n\t\t\t\t\t\t\thash: fileNameHash,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tproperties.source = 'asset://' + uuid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlet viewParent = parent.view || viewRoot;\n\t\tif (!viewParent.hasOwnProperty('children')) {\n\t\t\tviewParent.children = [];\n\t\t}\n\t\tviewParent.children.push(viewNode);\n\n\t\tnode.view = viewNode;\n\t});\n\n\tlet data = {\n\t\tview: viewRoot,\n\t\tassets,\n\t};\n\n\tlet dataString = JSON.stringify(data);\n\n\tlet buf = new Buffer(dataString);\n\treturn await new Promise((resolve, reject) => {\n\t\tzlib.gzip(buf, function (err, res) {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t} else {\n\t\t\t\tconsole.log(res.length);\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;;;;AAAA;;;;AAIA,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;;AAErC,AAAO,eAAe,OAAO,CAAC,IAAI,EAAE;CACnC,IAAI,GAAG,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;;CAE1C,MAAM,IAAI,GAAG,EAAE,CAAC;CAChB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;;CAEvB,OAAO,IAAI,CAAC;CACZ;;AAED,SAAS,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE;CAC/B,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;CAC9D,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC;CAC3E,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;CACvB,MAAM,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;;CAErB,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,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;MAC9C,IAAI,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;MAClC,MAAM;MACN,YAAY,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;MAClC,MAAM,CAAC,IAAI,CAAC;OACX,IAAI;OACJ,GAAG;OACH,IAAI;OACJ,UAAU;OACV,IAAI,EAAE,YAAY;OAClB,CAAC,CAAC;MACH;;KAED,UAAU,CAAC,MAAM,GAAG,UAAU,GAAG,IAAI,CAAC;KACtC;IACD;GACD;;EAED,IAAI,UAAU,GAAG,MAAM,CAAC,IAAI,IAAI,QAAQ,CAAC;EACzC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;GAC3C,UAAU,CAAC,QAAQ,GAAG,EAAE,CAAC;GACzB;EACD,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;;EAEnC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;EACrB,CAAC,CAAC;;CAEH,IAAI,IAAI,GAAG;EACV,IAAI,EAAE,QAAQ;EACd,MAAM;EACN,CAAC;;CAEF,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;;CAEtC,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;CACjC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;EAC7C,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE;GAClC,IAAI,GAAG,EAAE;IACR,MAAM,CAAC,GAAG,CAAC,CAAC;IACZ,MAAM;IACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,CAAC;IACb;GACD,EAAC;EACF,CAAC;CACF;;;;"}
\ No newline at end of file
{"version":3,"file":"index.es.js","sources":["../src/psd-tree.js","../src/utils.js","../src/zeroing.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-08-09.\n */\n\nconst PSD = window['require']('psd');\n\nexport async function getTree(file) {\n\tlet psd = await PSD.fromDroppedFile(file);\n\n\tconst root = {};\n\twalk(psd.tree(), root);\n\n\treturn root;\n}\n\nfunction walk(psNode, dataNode) {\n\tconst {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};\n\tconst {left, top, width, height, name, layer: {opacity, visible}} = psNode;\n\tconst x = left - pLeft;\n\tconst y = top - pTop;\n\n\tObject.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});\n\tif (psNode.children() && psNode.children().length > 0){\n\t\tdataNode.children = [];\n\t}\n\n\tlet children = psNode.children();\n\tfor (let i = children.length - 1; i >= 0; i--) {\n\t\tconst childPsNode = children[i];\n\n\t\tconst childDataNode = {};\n\t\tdataNode.children.push(childDataNode);\n\t\twalk(childPsNode, childDataNode)\n\t}\n}\n","/**\n * Created by rockyl on 2019-08-10.\n */\n\nexport async function walkNode(node, callback, includeSelf = false) {\n\tif (includeSelf) {\n\t\tawait callback(node, null);\n\t}\n\tif (node.children && node.children.length > 0) {\n\t\tfor (let childNode of node.children) {\n\t\t\tawait callback(childNode, node);\n\t\t\tconst result = await walkNode(childNode, callback);\n\t\t\tif (result === true) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport async function walkObject(obj, callback) {\n\tif(typeof obj === \"object\"){\n\t\tfor (let key of Object.keys(obj)) {\n\t\t\tconst value = obj[key];\n\t\t\tawait callback(key, value, obj);\n\t\t\tconst result = await walkObject(value, callback);\n\t\t\tif (result === true) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n","/**\n * Created by rockyl on 2019-09-26.\n *\n * 导出zeroing的视图\n */\n\nimport {getTree} from \"./psd-tree\";\nimport {walkNode} from \"./utils\";\nimport path from 'path'\nimport Color from 'color'\nimport generateUUID from 'uuid/v4'\nimport hash from 'object-hash';\nimport zlib from 'zlib';\n\nconst relativePosPrefixMap = {\n\tl: {field: 'left',},\n\tt: {field: 'top',},\n\tr: {field: 'right',},\n\tb: {field: 'bottom',},\n\th: {field: 'horizonCenter',},\n\tv: {field: 'verticalCenter',},\n\twp: {field: 'width', isPercent: true},\n\thp: {field: 'height', isPercent: true},\n};\n\nexport async function execute(psdFile, options) {\n\tconst tree = await getTree(psdFile);\n\n\tlet viewRoot = {\n\t\tname: path.basename(psdFile.name, '.psd'),\n\t\ttype: 'node',\n\t\tuuid: generateUUID(),\n\t};\n\n\tconst assets = [];\n\tconst imageHashMap = {};\n\n\tawait walkNode(tree, async function (node, parent) {\n\t\tlet {name} = node;\n\t\tconst {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;\n\t\t//console.log('walk node:', name);\n\t\tlet properties = {\n\t\t\twidth, height, alpha, visible,\n\t\t};\n\n\t\tif (name.includes('|')) {\n\t\t\ttry {\n\t\t\t\tlet arr = name.split('|');\n\t\t\t\tname = arr[0];\n\t\t\t\tlet paramsStr = arr[1];\n\t\t\t\tlet params = paramsStr.split(';');\n\t\t\t\tlet relativePos = params[0];\n\t\t\t\tif (relativePos) {\n\t\t\t\t\tlet items = relativePos.split(',');\n\t\t\t\t\tfor (let item of items) {\n\t\t\t\t\t\tlet result = item.match(/[a-zA-Z]+/);\n\t\t\t\t\t\tif(!result){\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet prefix = result[0];\n\t\t\t\t\t\tlet mapItem = relativePosPrefixMap[prefix];\n\t\t\t\t\t\tif (mapItem) {\n\t\t\t\t\t\t\tconst {field, isPercent} = mapItem;\n\t\t\t\t\t\t\tlet value = item.substr(prefix.length);\n\t\t\t\t\t\t\tif (isPercent) {\n\t\t\t\t\t\t\t\tvalue += '%';\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tvalue = parseFloat(value);\n\t\t\t\t\t\t\t\tif (isNaN(value)) {\n\t\t\t\t\t\t\t\t\tvalue = 0;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tproperties[field] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}catch (e) {\n\t\t\t\tconsole.log(e);\n\t\t\t}\n\t\t}\n\n\t\tlet viewNode = {\n\t\t\tname,\n\t\t\tproperties,\n\t\t\tuuid: generateUUID(),\n\t\t};\n\t\tlet dealLater = true;\n\t\tif (x !== 0) {\n\t\t\tproperties.x = x;\n\t\t}\n\t\tif (y !== 0) {\n\t\t\tproperties.y = y;\n\t\t}\n\n\t\tif (typeTool) {\n\t\t\tlet fontInfo = typeTool();\n\t\t\tproperties.text = fontInfo.textValue;\n\t\t\tconst sizes = fontInfo.sizes();\n\t\t\tconst colors = fontInfo.colors();\n\t\t\tproperties.size = sizes ? sizes[0] || 20 : 20;\n\t\t\tlet [r, g, b, a] = colors[0];\n\t\t\tproperties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;\n\t\t\tviewNode.type = 'label';\n\t\t\tdealLater = false;\n\t\t} else if (solidColor && layer.vectorMask) {\n\t\t\tconst {r, g, b} = solidColor();\n\t\t\tlet color = Color({r, g, b});\n\n\t\t\tlet paths = layer.vectorMask().paths;\n\t\t\tif (paths[2].numPoints === 4) {\n\t\t\t\tlet isRect = true;\n\t\t\t\tfor (let i = 3; i < paths.length; i++) {\n\t\t\t\t\tif (paths[i].recordType !== 2) {\n\t\t\t\t\t\tisRect = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (isRect) {\n\t\t\t\t\tviewNode.type = 'rect';\n\t\t\t\t\tproperties.fillColor = '#' + color.rgbNumber().toString(16);\n\t\t\t\t\tdealLater = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (dealLater) {\n\t\t\tif (node.hasOwnProperty('children')) {\n\t\t\t\tviewNode.type = 'node';\n\t\t\t} else {\n\t\t\t\tviewNode.type = 'image';\n\n\t\t\t\tlet uuid = generateUUID();\n\t\t\t\tconst ext = '.png';\n\n\t\t\t\tlet dataUrl;\n\t\t\t\ttry {\n\t\t\t\t\tlet img = node.origin.toPng();\n\t\t\t\t\tdataUrl = img.src;\n\t\t\t\t} catch (e) {\n\n\t\t\t\t}\n\n\t\t\t\tif (dataUrl) {\n\t\t\t\t\tlet base64Data = dataUrl.replace(/^data:image\\/\\w+;base64,/, \"\");\n\t\t\t\t\tlet buffer = new Buffer(base64Data, 'base64');\n\t\t\t\t\tconst fileNameHash = hash(buffer);\n\t\t\t\t\tif (imageHashMap.hasOwnProperty(fileNameHash)) {\n\t\t\t\t\t\tuuid = imageHashMap[fileNameHash];\n\t\t\t\t\t} else {\n\t\t\t\t\t\timageHashMap[fileNameHash] = uuid;\n\t\t\t\t\t\tassets.push({\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\text,\n\t\t\t\t\t\t\tuuid,\n\t\t\t\t\t\t\tbase64Data,\n\t\t\t\t\t\t\thash: fileNameHash,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tproperties.source = 'asset://' + uuid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlet viewParent = parent.view || viewRoot;\n\t\tif (!viewParent.hasOwnProperty('children')) {\n\t\t\tviewParent.children = [];\n\t\t}\n\t\tviewParent.children.push(viewNode);\n\n\t\tnode.view = viewNode;\n\t});\n\n\tlet data = {\n\t\tview: viewRoot,\n\t\tassets,\n\t};\n\n\tlet dataString = JSON.stringify(data);\n\n\tlet buf = new Buffer(dataString);\n\treturn await new Promise((resolve, reject) => {\n\t\tzlib.gzip(buf, function (err, res) {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t} else {\n\t\t\t\tconsole.log(res.length);\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;;;;AAAA;;;;AAIA,MAAM,GAAG,G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AAI,CAAC;KACtC;IACD;GACD;;EAED,IAAI,UAAU,GAAG,MAAM,CAAC,IAAI,IAAI,QAAQ,CAAC;EACzC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;GAC3C,UAAU,CAAC,QAAQ,GAAG,EAAE,CAAC;GACzB;EACD,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;;EAEnC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;EACrB,CAAC,CAAC;;CAEH,IAAI,IAAI,GAAG;EACV,IAAI,EAAE,QAAQ;EACd,MAAM;EACN,CAAC;;CAEF,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;;CAEtC,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;CACjC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;EAC7C,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE;GAClC,IAAI,GAAG,EAAE;IACR,MAAM,CAAC,GAAG,CAAC,CAAC;IACZ,MAAM;IACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,CAAC;IACb;GACD,EAAC;EACF,CAAC;CACF;;;;"}
\ No newline at end of file
......@@ -161,7 +161,7 @@ async function execute(psdFile, options) {
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
} else if (solidColor && layer.vectorMask) {
const {r, g, b} = solidColor();
let color = Color({r, g, b});
......
{"version":3,"file":"index.js","sources":["../src/psd-tree.js","../src/utils.js","../src/zeroing.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-08-09.\n */\n\nconst PSD = window['require']('psd');\n\nexport async function getTree(file) {\n\tlet psd = await PSD.fromDroppedFile(file);\n\n\tconst root = {};\n\twalk(psd.tree(), root);\n\n\treturn root;\n}\n\nfunction walk(psNode, dataNode) {\n\tconst {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};\n\tconst {left, top, width, height, name, layer: {opacity, visible}} = psNode;\n\tconst x = left - pLeft;\n\tconst y = top - pTop;\n\n\tObject.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});\n\tif (psNode.children() && psNode.children().length > 0){\n\t\tdataNode.children = [];\n\t}\n\n\tlet children = psNode.children();\n\tfor (let i = children.length - 1; i >= 0; i--) {\n\t\tconst childPsNode = children[i];\n\n\t\tconst childDataNode = {};\n\t\tdataNode.children.push(childDataNode);\n\t\twalk(childPsNode, childDataNode)\n\t}\n}\n","/**\n * Created by rockyl on 2019-08-10.\n */\n\nexport async function walkNode(node, callback, includeSelf = false) {\n\tif (includeSelf) {\n\t\tawait callback(node, null);\n\t}\n\tif (node.children && node.children.length > 0) {\n\t\tfor (let childNode of node.children) {\n\t\t\tawait callback(childNode, node);\n\t\t\tconst result = await walkNode(childNode, callback);\n\t\t\tif (result === true) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport async function walkObject(obj, callback) {\n\tif(typeof obj === \"object\"){\n\t\tfor (let key of Object.keys(obj)) {\n\t\t\tconst value = obj[key];\n\t\t\tawait callback(key, value, obj);\n\t\t\tconst result = await walkObject(value, callback);\n\t\t\tif (result === true) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n","/**\n * Created by rockyl on 2019-09-26.\n *\n * 导出zeroing的视图\n */\n\nimport {getTree} from \"./psd-tree\";\nimport {walkNode} from \"./utils\";\nimport path from 'path'\nimport Color from 'color'\nimport generateUUID from 'uuid/v4'\nimport hash from 'object-hash';\nimport zlib from 'zlib';\n\nconst relativePosPrefixMap = {\n\tl: {field: 'left',},\n\tt: {field: 'top',},\n\tr: {field: 'right',},\n\tb: {field: 'bottom',},\n\th: {field: 'horizonCenter',},\n\tv: {field: 'verticalCenter',},\n\twp: {field: 'width', isPercent: true},\n\thp: {field: 'height', isPercent: true},\n};\n\nexport async function execute(psdFile, options) {\n\tconst tree = await getTree(psdFile);\n\n\tlet viewRoot = {\n\t\tname: path.basename(psdFile.name, '.psd'),\n\t\ttype: 'node',\n\t\tuuid: generateUUID(),\n\t};\n\n\tconst assets = [];\n\tconst imageHashMap = {};\n\n\tawait walkNode(tree, async function (node, parent) {\n\t\tlet {name} = node;\n\t\tconst {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;\n\t\t//console.log('walk node:', name);\n\t\tlet properties = {\n\t\t\twidth, height, alpha, visible,\n\t\t};\n\n\t\tif (name.includes('|')) {\n\t\t\ttry {\n\t\t\t\tlet arr = name.split('|');\n\t\t\t\tname = arr[0];\n\t\t\t\tlet paramsStr = arr[1];\n\t\t\t\tlet params = paramsStr.split(';');\n\t\t\t\tlet relativePos = params[0];\n\t\t\t\tif (relativePos) {\n\t\t\t\t\tlet items = relativePos.split(',');\n\t\t\t\t\tfor (let item of items) {\n\t\t\t\t\t\tlet result = item.match(/[a-zA-Z]+/);\n\t\t\t\t\t\tif(!result){\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet prefix = result[0];\n\t\t\t\t\t\tlet mapItem = relativePosPrefixMap[prefix];\n\t\t\t\t\t\tif (mapItem) {\n\t\t\t\t\t\t\tconst {field, isPercent} = mapItem;\n\t\t\t\t\t\t\tlet value = item.substr(prefix.length);\n\t\t\t\t\t\t\tif (isPercent) {\n\t\t\t\t\t\t\t\tvalue += '%';\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tvalue = parseFloat(value);\n\t\t\t\t\t\t\t\tif (isNaN(value)) {\n\t\t\t\t\t\t\t\t\tvalue = 0;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tproperties[field] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}catch (e) {\n\t\t\t\tconsole.log(e);\n\t\t\t}\n\t\t}\n\n\t\tlet viewNode = {\n\t\t\tname,\n\t\t\tproperties,\n\t\t\tuuid: generateUUID(),\n\t\t};\n\t\tlet dealLater = true;\n\t\tif (x !== 0) {\n\t\t\tproperties.x = x;\n\t\t}\n\t\tif (y !== 0) {\n\t\t\tproperties.y = y;\n\t\t}\n\n\t\tif (typeTool) {\n\t\t\tlet fontInfo = typeTool();\n\t\t\tproperties.text = fontInfo.textValue;\n\t\t\tconst sizes = fontInfo.sizes();\n\t\t\tconst colors = fontInfo.colors();\n\t\t\tproperties.size = sizes ? sizes[0] || 20 : 20;\n\t\t\tlet [r, g, b, a] = colors[0];\n\t\t\tproperties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;\n\t\t\tviewNode.type = 'label';\n\t\t\tdealLater = false;\n\t\t} else if (solidColor) {\n\t\t\tconst {r, g, b} = solidColor();\n\t\t\tlet color = Color({r, g, b});\n\n\t\t\tlet paths = layer.vectorMask().paths;\n\t\t\tif (paths[2].numPoints === 4) {\n\t\t\t\tlet isRect = true;\n\t\t\t\tfor (let i = 3; i < paths.length; i++) {\n\t\t\t\t\tif (paths[i].recordType !== 2) {\n\t\t\t\t\t\tisRect = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (isRect) {\n\t\t\t\t\tviewNode.type = 'rect';\n\t\t\t\t\tproperties.fillColor = '#' + color.rgbNumber().toString(16);\n\t\t\t\t\tdealLater = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (dealLater) {\n\t\t\tif (node.hasOwnProperty('children')) {\n\t\t\t\tviewNode.type = 'node';\n\t\t\t} else {\n\t\t\t\tviewNode.type = 'image';\n\n\t\t\t\tlet uuid = generateUUID();\n\t\t\t\tconst ext = '.png';\n\n\t\t\t\tlet dataUrl;\n\t\t\t\ttry {\n\t\t\t\t\tlet img = node.origin.toPng();\n\t\t\t\t\tdataUrl = img.src;\n\t\t\t\t} catch (e) {\n\n\t\t\t\t}\n\n\t\t\t\tif (dataUrl) {\n\t\t\t\t\tlet base64Data = dataUrl.replace(/^data:image\\/\\w+;base64,/, \"\");\n\t\t\t\t\tlet buffer = new Buffer(base64Data, 'base64');\n\t\t\t\t\tconst fileNameHash = hash(buffer);\n\t\t\t\t\tif (imageHashMap.hasOwnProperty(fileNameHash)) {\n\t\t\t\t\t\tuuid = imageHashMap[fileNameHash];\n\t\t\t\t\t} else {\n\t\t\t\t\t\timageHashMap[fileNameHash] = uuid;\n\t\t\t\t\t\tassets.push({\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\text,\n\t\t\t\t\t\t\tuuid,\n\t\t\t\t\t\t\tbase64Data,\n\t\t\t\t\t\t\thash: fileNameHash,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tproperties.source = 'asset://' + uuid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlet viewParent = parent.view || viewRoot;\n\t\tif (!viewParent.hasOwnProperty('children')) {\n\t\t\tviewParent.children = [];\n\t\t}\n\t\tviewParent.children.push(viewNode);\n\n\t\tnode.view = viewNode;\n\t});\n\n\tlet data = {\n\t\tview: viewRoot,\n\t\tassets,\n\t};\n\n\tlet dataString = JSON.stringify(data);\n\n\tlet buf = new Buffer(dataString);\n\treturn await new Promise((resolve, reject) => {\n\t\tzlib.gzip(buf, function (err, res) {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t} else {\n\t\t\t\tconsole.log(res.length);\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;AAIA,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;;AAErC,AAAO,eAAe,OAAO,CAAC,IAAI,EAAE;CACnC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AC,UAAU,CAAC,EAAE;GAC3C,UAAU,CAAC,QAAQ,GAAG,EAAE,CAAC;GACzB;EACD,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;;EAEnC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;EACrB,CAAC,CAAC;;CAEH,IAAI,IAAI,GAAG;EACV,IAAI,EAAE,QAAQ;EACd,MAAM;EACN,CAAC;;CAEF,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;;CAEtC,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;CACjC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;EAC7C,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE;GAClC,IAAI,GAAG,EAAE;IACR,MAAM,CAAC,GAAG,CAAC,CAAC;IACZ,MAAM;IACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,CAAC;IACb;GACD,EAAC;EACF,CAAC;CACF;;;;;"}
\ No newline at end of file
{"version":3,"file":"index.js","sources":["../src/psd-tree.js","../src/utils.js","../src/zeroing.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-08-09.\n */\n\nconst PSD = window['require']('psd');\n\nexport async function getTree(file) {\n\tlet psd = await PSD.fromDroppedFile(file);\n\n\tconst root = {};\n\twalk(psd.tree(), root);\n\n\treturn root;\n}\n\nfunction walk(psNode, dataNode) {\n\tconst {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};\n\tconst {left, top, width, height, name, layer: {opacity, visible}} = psNode;\n\tconst x = left - pLeft;\n\tconst y = top - pTop;\n\n\tObject.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});\n\tif (psNode.children() && psNode.children().length > 0){\n\t\tdataNode.children = [];\n\t}\n\n\tlet children = psNode.children();\n\tfor (let i = children.length - 1; i >= 0; i--) {\n\t\tconst childPsNode = children[i];\n\n\t\tconst childDataNode = {};\n\t\tdataNode.children.push(childDataNode);\n\t\twalk(childPsNode, childDataNode)\n\t}\n}\n","/**\n * Created by rockyl on 2019-08-10.\n */\n\nexport async function walkNode(node, callback, includeSelf = false) {\n\tif (includeSelf) {\n\t\tawait callback(node, null);\n\t}\n\tif (node.children && node.children.length > 0) {\n\t\tfor (let childNode of node.children) {\n\t\t\tawait callback(childNode, node);\n\t\t\tconst result = await walkNode(childNode, callback);\n\t\t\tif (result === true) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport async function walkObject(obj, callback) {\n\tif(typeof obj === \"object\"){\n\t\tfor (let key of Object.keys(obj)) {\n\t\t\tconst value = obj[key];\n\t\t\tawait callback(key, value, obj);\n\t\t\tconst result = await walkObject(value, callback);\n\t\t\tif (result === true) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n","/**\n * Created by rockyl on 2019-09-26.\n *\n * 导出zeroing的视图\n */\n\nimport {getTree} from \"./psd-tree\";\nimport {walkNode} from \"./utils\";\nimport path from 'path'\nimport Color from 'color'\nimport generateUUID from 'uuid/v4'\nimport hash from 'object-hash';\nimport zlib from 'zlib';\n\nconst relativePosPrefixMap = {\n\tl: {field: 'left',},\n\tt: {field: 'top',},\n\tr: {field: 'right',},\n\tb: {field: 'bottom',},\n\th: {field: 'horizonCenter',},\n\tv: {field: 'verticalCenter',},\n\twp: {field: 'width', isPercent: true},\n\thp: {field: 'height', isPercent: true},\n};\n\nexport async function execute(psdFile, options) {\n\tconst tree = await getTree(psdFile);\n\n\tlet viewRoot = {\n\t\tname: path.basename(psdFile.name, '.psd'),\n\t\ttype: 'node',\n\t\tuuid: generateUUID(),\n\t};\n\n\tconst assets = [];\n\tconst imageHashMap = {};\n\n\tawait walkNode(tree, async function (node, parent) {\n\t\tlet {name} = node;\n\t\tconst {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;\n\t\t//console.log('walk node:', name);\n\t\tlet properties = {\n\t\t\twidth, height, alpha, visible,\n\t\t};\n\n\t\tif (name.includes('|')) {\n\t\t\ttry {\n\t\t\t\tlet arr = name.split('|');\n\t\t\t\tname = arr[0];\n\t\t\t\tlet paramsStr = arr[1];\n\t\t\t\tlet params = paramsStr.split(';');\n\t\t\t\tlet relativePos = params[0];\n\t\t\t\tif (relativePos) {\n\t\t\t\t\tlet items = relativePos.split(',');\n\t\t\t\t\tfor (let item of items) {\n\t\t\t\t\t\tlet result = item.match(/[a-zA-Z]+/);\n\t\t\t\t\t\tif(!result){\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet prefix = result[0];\n\t\t\t\t\t\tlet mapItem = relativePosPrefixMap[prefix];\n\t\t\t\t\t\tif (mapItem) {\n\t\t\t\t\t\t\tconst {field, isPercent} = mapItem;\n\t\t\t\t\t\t\tlet value = item.substr(prefix.length);\n\t\t\t\t\t\t\tif (isPercent) {\n\t\t\t\t\t\t\t\tvalue += '%';\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tvalue = parseFloat(value);\n\t\t\t\t\t\t\t\tif (isNaN(value)) {\n\t\t\t\t\t\t\t\t\tvalue = 0;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tproperties[field] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}catch (e) {\n\t\t\t\tconsole.log(e);\n\t\t\t}\n\t\t}\n\n\t\tlet viewNode = {\n\t\t\tname,\n\t\t\tproperties,\n\t\t\tuuid: generateUUID(),\n\t\t};\n\t\tlet dealLater = true;\n\t\tif (x !== 0) {\n\t\t\tproperties.x = x;\n\t\t}\n\t\tif (y !== 0) {\n\t\t\tproperties.y = y;\n\t\t}\n\n\t\tif (typeTool) {\n\t\t\tlet fontInfo = typeTool();\n\t\t\tproperties.text = fontInfo.textValue;\n\t\t\tconst sizes = fontInfo.sizes();\n\t\t\tconst colors = fontInfo.colors();\n\t\t\tproperties.size = sizes ? sizes[0] || 20 : 20;\n\t\t\tlet [r, g, b, a] = colors[0];\n\t\t\tproperties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;\n\t\t\tviewNode.type = 'label';\n\t\t\tdealLater = false;\n\t\t} else if (solidColor && layer.vectorMask) {\n\t\t\tconst {r, g, b} = solidColor();\n\t\t\tlet color = Color({r, g, b});\n\n\t\t\tlet paths = layer.vectorMask().paths;\n\t\t\tif (paths[2].numPoints === 4) {\n\t\t\t\tlet isRect = true;\n\t\t\t\tfor (let i = 3; i < paths.length; i++) {\n\t\t\t\t\tif (paths[i].recordType !== 2) {\n\t\t\t\t\t\tisRect = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (isRect) {\n\t\t\t\t\tviewNode.type = 'rect';\n\t\t\t\t\tproperties.fillColor = '#' + color.rgbNumber().toString(16);\n\t\t\t\t\tdealLater = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (dealLater) {\n\t\t\tif (node.hasOwnProperty('children')) {\n\t\t\t\tviewNode.type = 'node';\n\t\t\t} else {\n\t\t\t\tviewNode.type = 'image';\n\n\t\t\t\tlet uuid = generateUUID();\n\t\t\t\tconst ext = '.png';\n\n\t\t\t\tlet dataUrl;\n\t\t\t\ttry {\n\t\t\t\t\tlet img = node.origin.toPng();\n\t\t\t\t\tdataUrl = img.src;\n\t\t\t\t} catch (e) {\n\n\t\t\t\t}\n\n\t\t\t\tif (dataUrl) {\n\t\t\t\t\tlet base64Data = dataUrl.replace(/^data:image\\/\\w+;base64,/, \"\");\n\t\t\t\t\tlet buffer = new Buffer(base64Data, 'base64');\n\t\t\t\t\tconst fileNameHash = hash(buffer);\n\t\t\t\t\tif (imageHashMap.hasOwnProperty(fileNameHash)) {\n\t\t\t\t\t\tuuid = imageHashMap[fileNameHash];\n\t\t\t\t\t} else {\n\t\t\t\t\t\timageHashMap[fileNameHash] = uuid;\n\t\t\t\t\t\tassets.push({\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\text,\n\t\t\t\t\t\t\tuuid,\n\t\t\t\t\t\t\tbase64Data,\n\t\t\t\t\t\t\thash: fileNameHash,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tproperties.source = 'asset://' + uuid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlet viewParent = parent.view || viewRoot;\n\t\tif (!viewParent.hasOwnProperty('children')) {\n\t\t\tviewParent.children = [];\n\t\t}\n\t\tviewParent.children.push(viewNode);\n\n\t\tnode.view = viewNode;\n\t});\n\n\tlet data = {\n\t\tview: viewRoot,\n\t\tassets,\n\t};\n\n\tlet dataString = JSON.stringify(data);\n\n\tlet buf = new Buffer(dataString);\n\treturn await new Promise((resolve, reject) => {\n\t\tzlib.gzip(buf, function (err, res) {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t} else {\n\t\t\t\tconsole.log(res.length);\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;AAIA,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;;AAErC,AAAO,eAAe,OAAO,CAAC,IAAI,EAAE;CACnC,IAAI,GAAG,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;;CAE1C,MAAM,IAAI,GAAG,EAAE,CAAC;CAChB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;;CAEvB,OAAO,IAAI,CAAC;CACZ;;AAED,SAAS,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE;CAC/B,MAAM,CAAC,IAAI,EAAE,KAAK,GA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;CAEF,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;;CAEtC,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;CACjC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;EAC7C,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE;GAClC,IAAI,GAAG,EAAE;IACR,MAAM,CAAC,GAAG,CAAC,CAAC;IACZ,MAAM;IACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,CAAC;IACb;GACD,EAAC;EACF,CAAC;CACF;;;;;"}
\ No newline at end of file
......@@ -161,7 +161,7 @@
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
} else if (solidColor && layer.vectorMask) {
const {r, g, b} = solidColor();
let color = Color({r, g, b});
......
{"version":3,"file":"index.umd.js","sources":["../src/psd-tree.js","../src/utils.js","../src/zeroing.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-08-09.\n */\n\nconst PSD = window['require']('psd');\n\nexport async function getTree(file) {\n\tlet psd = await PSD.fromDroppedFile(file);\n\n\tconst root = {};\n\twalk(psd.tree(), root);\n\n\treturn root;\n}\n\nfunction walk(psNode, dataNode) {\n\tconst {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};\n\tconst {left, top, width, height, name, layer: {opacity, visible}} = psNode;\n\tconst x = left - pLeft;\n\tconst y = top - pTop;\n\n\tObject.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});\n\tif (psNode.children() && psNode.children().length > 0){\n\t\tdataNode.children = [];\n\t}\n\n\tlet children = psNode.children();\n\tfor (let i = children.length - 1; i >= 0; i--) {\n\t\tconst childPsNode = children[i];\n\n\t\tconst childDataNode = {};\n\t\tdataNode.children.push(childDataNode);\n\t\twalk(childPsNode, childDataNode)\n\t}\n}\n","/**\n * Created by rockyl on 2019-08-10.\n */\n\nexport async function walkNode(node, callback, includeSelf = false) {\n\tif (includeSelf) {\n\t\tawait callback(node, null);\n\t}\n\tif (node.children && node.children.length > 0) {\n\t\tfor (let childNode of node.children) {\n\t\t\tawait callback(childNode, node);\n\t\t\tconst result = await walkNode(childNode, callback);\n\t\t\tif (result === true) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport async function walkObject(obj, callback) {\n\tif(typeof obj === \"object\"){\n\t\tfor (let key of Object.keys(obj)) {\n\t\t\tconst value = obj[key];\n\t\t\tawait callback(key, value, obj);\n\t\t\tconst result = await walkObject(value, callback);\n\t\t\tif (result === true) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n","/**\n * Created by rockyl on 2019-09-26.\n *\n * 导出zeroing的视图\n */\n\nimport {getTree} from \"./psd-tree\";\nimport {walkNode} from \"./utils\";\nimport path from 'path'\nimport Color from 'color'\nimport generateUUID from 'uuid/v4'\nimport hash from 'object-hash';\nimport zlib from 'zlib';\n\nconst relativePosPrefixMap = {\n\tl: {field: 'left',},\n\tt: {field: 'top',},\n\tr: {field: 'right',},\n\tb: {field: 'bottom',},\n\th: {field: 'horizonCenter',},\n\tv: {field: 'verticalCenter',},\n\twp: {field: 'width', isPercent: true},\n\thp: {field: 'height', isPercent: true},\n};\n\nexport async function execute(psdFile, options) {\n\tconst tree = await getTree(psdFile);\n\n\tlet viewRoot = {\n\t\tname: path.basename(psdFile.name, '.psd'),\n\t\ttype: 'node',\n\t\tuuid: generateUUID(),\n\t};\n\n\tconst assets = [];\n\tconst imageHashMap = {};\n\n\tawait walkNode(tree, async function (node, parent) {\n\t\tlet {name} = node;\n\t\tconst {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;\n\t\t//console.log('walk node:', name);\n\t\tlet properties = {\n\t\t\twidth, height, alpha, visible,\n\t\t};\n\n\t\tif (name.includes('|')) {\n\t\t\ttry {\n\t\t\t\tlet arr = name.split('|');\n\t\t\t\tname = arr[0];\n\t\t\t\tlet paramsStr = arr[1];\n\t\t\t\tlet params = paramsStr.split(';');\n\t\t\t\tlet relativePos = params[0];\n\t\t\t\tif (relativePos) {\n\t\t\t\t\tlet items = relativePos.split(',');\n\t\t\t\t\tfor (let item of items) {\n\t\t\t\t\t\tlet result = item.match(/[a-zA-Z]+/);\n\t\t\t\t\t\tif(!result){\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet prefix = result[0];\n\t\t\t\t\t\tlet mapItem = relativePosPrefixMap[prefix];\n\t\t\t\t\t\tif (mapItem) {\n\t\t\t\t\t\t\tconst {field, isPercent} = mapItem;\n\t\t\t\t\t\t\tlet value = item.substr(prefix.length);\n\t\t\t\t\t\t\tif (isPercent) {\n\t\t\t\t\t\t\t\tvalue += '%';\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tvalue = parseFloat(value);\n\t\t\t\t\t\t\t\tif (isNaN(value)) {\n\t\t\t\t\t\t\t\t\tvalue = 0;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tproperties[field] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}catch (e) {\n\t\t\t\tconsole.log(e);\n\t\t\t}\n\t\t}\n\n\t\tlet viewNode = {\n\t\t\tname,\n\t\t\tproperties,\n\t\t\tuuid: generateUUID(),\n\t\t};\n\t\tlet dealLater = true;\n\t\tif (x !== 0) {\n\t\t\tproperties.x = x;\n\t\t}\n\t\tif (y !== 0) {\n\t\t\tproperties.y = y;\n\t\t}\n\n\t\tif (typeTool) {\n\t\t\tlet fontInfo = typeTool();\n\t\t\tproperties.text = fontInfo.textValue;\n\t\t\tconst sizes = fontInfo.sizes();\n\t\t\tconst colors = fontInfo.colors();\n\t\t\tproperties.size = sizes ? sizes[0] || 20 : 20;\n\t\t\tlet [r, g, b, a] = colors[0];\n\t\t\tproperties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;\n\t\t\tviewNode.type = 'label';\n\t\t\tdealLater = false;\n\t\t} else if (solidColor) {\n\t\t\tconst {r, g, b} = solidColor();\n\t\t\tlet color = Color({r, g, b});\n\n\t\t\tlet paths = layer.vectorMask().paths;\n\t\t\tif (paths[2].numPoints === 4) {\n\t\t\t\tlet isRect = true;\n\t\t\t\tfor (let i = 3; i < paths.length; i++) {\n\t\t\t\t\tif (paths[i].recordType !== 2) {\n\t\t\t\t\t\tisRect = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (isRect) {\n\t\t\t\t\tviewNode.type = 'rect';\n\t\t\t\t\tproperties.fillColor = '#' + color.rgbNumber().toString(16);\n\t\t\t\t\tdealLater = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (dealLater) {\n\t\t\tif (node.hasOwnProperty('children')) {\n\t\t\t\tviewNode.type = 'node';\n\t\t\t} else {\n\t\t\t\tviewNode.type = 'image';\n\n\t\t\t\tlet uuid = generateUUID();\n\t\t\t\tconst ext = '.png';\n\n\t\t\t\tlet dataUrl;\n\t\t\t\ttry {\n\t\t\t\t\tlet img = node.origin.toPng();\n\t\t\t\t\tdataUrl = img.src;\n\t\t\t\t} catch (e) {\n\n\t\t\t\t}\n\n\t\t\t\tif (dataUrl) {\n\t\t\t\t\tlet base64Data = dataUrl.replace(/^data:image\\/\\w+;base64,/, \"\");\n\t\t\t\t\tlet buffer = new Buffer(base64Data, 'base64');\n\t\t\t\t\tconst fileNameHash = hash(buffer);\n\t\t\t\t\tif (imageHashMap.hasOwnProperty(fileNameHash)) {\n\t\t\t\t\t\tuuid = imageHashMap[fileNameHash];\n\t\t\t\t\t} else {\n\t\t\t\t\t\timageHashMap[fileNameHash] = uuid;\n\t\t\t\t\t\tassets.push({\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\text,\n\t\t\t\t\t\t\tuuid,\n\t\t\t\t\t\t\tbase64Data,\n\t\t\t\t\t\t\thash: fileNameHash,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tproperties.source = 'asset://' + uuid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlet viewParent = parent.view || viewRoot;\n\t\tif (!viewParent.hasOwnProperty('children')) {\n\t\t\tviewParent.children = [];\n\t\t}\n\t\tviewParent.children.push(viewNode);\n\n\t\tnode.view = viewNode;\n\t});\n\n\tlet data = {\n\t\tview: viewRoot,\n\t\tassets,\n\t};\n\n\tlet dataString = JSON.stringify(data);\n\n\tlet buf = new Buffer(dataString);\n\treturn await new Promise((resolve, reject) => {\n\t\tzlib.gzip(buf, function (err, res) {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t} else {\n\t\t\t\tconsole.log(res.length);\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;;;;;;;;;;CAAA;CACA;CACA;;CAEA,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;;AAErC,CAAO,eAAe,OAAO,CAAC,IAAI,EAAE;CACpC,CAAC,IAAI,GAAG,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;;CAE3C,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;CACjB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;;CAExB,CAAC,OAAO,IAAI,CAAC;CACb,CAAC;;CAED,SAAS,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE;CAChC,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,MAA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AAI,CAAC,GAAG,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE;CACrC,GAAG,IAAI,GAAG,EAAE;CACZ,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;CAChB,IAAI,MAAM;CACV,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CAC5B,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;CACjB,IAAI;CACJ,GAAG,EAAC;CACJ,EAAE,CAAC;CACH,CAAC;;;;;;;;;;;;;"}
\ No newline at end of file
{"version":3,"file":"index.umd.js","sources":["../src/psd-tree.js","../src/utils.js","../src/zeroing.js"],"sourcesContent":["/**\n * Created by rockyl on 2019-08-09.\n */\n\nconst PSD = window['require']('psd');\n\nexport async function getTree(file) {\n\tlet psd = await PSD.fromDroppedFile(file);\n\n\tconst root = {};\n\twalk(psd.tree(), root);\n\n\treturn root;\n}\n\nfunction walk(psNode, dataNode) {\n\tconst {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};\n\tconst {left, top, width, height, name, layer: {opacity, visible}} = psNode;\n\tconst x = left - pLeft;\n\tconst y = top - pTop;\n\n\tObject.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});\n\tif (psNode.children() && psNode.children().length > 0){\n\t\tdataNode.children = [];\n\t}\n\n\tlet children = psNode.children();\n\tfor (let i = children.length - 1; i >= 0; i--) {\n\t\tconst childPsNode = children[i];\n\n\t\tconst childDataNode = {};\n\t\tdataNode.children.push(childDataNode);\n\t\twalk(childPsNode, childDataNode)\n\t}\n}\n","/**\n * Created by rockyl on 2019-08-10.\n */\n\nexport async function walkNode(node, callback, includeSelf = false) {\n\tif (includeSelf) {\n\t\tawait callback(node, null);\n\t}\n\tif (node.children && node.children.length > 0) {\n\t\tfor (let childNode of node.children) {\n\t\t\tawait callback(childNode, node);\n\t\t\tconst result = await walkNode(childNode, callback);\n\t\t\tif (result === true) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport async function walkObject(obj, callback) {\n\tif(typeof obj === \"object\"){\n\t\tfor (let key of Object.keys(obj)) {\n\t\t\tconst value = obj[key];\n\t\t\tawait callback(key, value, obj);\n\t\t\tconst result = await walkObject(value, callback);\n\t\t\tif (result === true) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n","/**\n * Created by rockyl on 2019-09-26.\n *\n * 导出zeroing的视图\n */\n\nimport {getTree} from \"./psd-tree\";\nimport {walkNode} from \"./utils\";\nimport path from 'path'\nimport Color from 'color'\nimport generateUUID from 'uuid/v4'\nimport hash from 'object-hash';\nimport zlib from 'zlib';\n\nconst relativePosPrefixMap = {\n\tl: {field: 'left',},\n\tt: {field: 'top',},\n\tr: {field: 'right',},\n\tb: {field: 'bottom',},\n\th: {field: 'horizonCenter',},\n\tv: {field: 'verticalCenter',},\n\twp: {field: 'width', isPercent: true},\n\thp: {field: 'height', isPercent: true},\n};\n\nexport async function execute(psdFile, options) {\n\tconst tree = await getTree(psdFile);\n\n\tlet viewRoot = {\n\t\tname: path.basename(psdFile.name, '.psd'),\n\t\ttype: 'node',\n\t\tuuid: generateUUID(),\n\t};\n\n\tconst assets = [];\n\tconst imageHashMap = {};\n\n\tawait walkNode(tree, async function (node, parent) {\n\t\tlet {name} = node;\n\t\tconst {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;\n\t\t//console.log('walk node:', name);\n\t\tlet properties = {\n\t\t\twidth, height, alpha, visible,\n\t\t};\n\n\t\tif (name.includes('|')) {\n\t\t\ttry {\n\t\t\t\tlet arr = name.split('|');\n\t\t\t\tname = arr[0];\n\t\t\t\tlet paramsStr = arr[1];\n\t\t\t\tlet params = paramsStr.split(';');\n\t\t\t\tlet relativePos = params[0];\n\t\t\t\tif (relativePos) {\n\t\t\t\t\tlet items = relativePos.split(',');\n\t\t\t\t\tfor (let item of items) {\n\t\t\t\t\t\tlet result = item.match(/[a-zA-Z]+/);\n\t\t\t\t\t\tif(!result){\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet prefix = result[0];\n\t\t\t\t\t\tlet mapItem = relativePosPrefixMap[prefix];\n\t\t\t\t\t\tif (mapItem) {\n\t\t\t\t\t\t\tconst {field, isPercent} = mapItem;\n\t\t\t\t\t\t\tlet value = item.substr(prefix.length);\n\t\t\t\t\t\t\tif (isPercent) {\n\t\t\t\t\t\t\t\tvalue += '%';\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tvalue = parseFloat(value);\n\t\t\t\t\t\t\t\tif (isNaN(value)) {\n\t\t\t\t\t\t\t\t\tvalue = 0;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tproperties[field] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}catch (e) {\n\t\t\t\tconsole.log(e);\n\t\t\t}\n\t\t}\n\n\t\tlet viewNode = {\n\t\t\tname,\n\t\t\tproperties,\n\t\t\tuuid: generateUUID(),\n\t\t};\n\t\tlet dealLater = true;\n\t\tif (x !== 0) {\n\t\t\tproperties.x = x;\n\t\t}\n\t\tif (y !== 0) {\n\t\t\tproperties.y = y;\n\t\t}\n\n\t\tif (typeTool) {\n\t\t\tlet fontInfo = typeTool();\n\t\t\tproperties.text = fontInfo.textValue;\n\t\t\tconst sizes = fontInfo.sizes();\n\t\t\tconst colors = fontInfo.colors();\n\t\t\tproperties.size = sizes ? sizes[0] || 20 : 20;\n\t\t\tlet [r, g, b, a] = colors[0];\n\t\t\tproperties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;\n\t\t\tviewNode.type = 'label';\n\t\t\tdealLater = false;\n\t\t} else if (solidColor && layer.vectorMask) {\n\t\t\tconst {r, g, b} = solidColor();\n\t\t\tlet color = Color({r, g, b});\n\n\t\t\tlet paths = layer.vectorMask().paths;\n\t\t\tif (paths[2].numPoints === 4) {\n\t\t\t\tlet isRect = true;\n\t\t\t\tfor (let i = 3; i < paths.length; i++) {\n\t\t\t\t\tif (paths[i].recordType !== 2) {\n\t\t\t\t\t\tisRect = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (isRect) {\n\t\t\t\t\tviewNode.type = 'rect';\n\t\t\t\t\tproperties.fillColor = '#' + color.rgbNumber().toString(16);\n\t\t\t\t\tdealLater = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (dealLater) {\n\t\t\tif (node.hasOwnProperty('children')) {\n\t\t\t\tviewNode.type = 'node';\n\t\t\t} else {\n\t\t\t\tviewNode.type = 'image';\n\n\t\t\t\tlet uuid = generateUUID();\n\t\t\t\tconst ext = '.png';\n\n\t\t\t\tlet dataUrl;\n\t\t\t\ttry {\n\t\t\t\t\tlet img = node.origin.toPng();\n\t\t\t\t\tdataUrl = img.src;\n\t\t\t\t} catch (e) {\n\n\t\t\t\t}\n\n\t\t\t\tif (dataUrl) {\n\t\t\t\t\tlet base64Data = dataUrl.replace(/^data:image\\/\\w+;base64,/, \"\");\n\t\t\t\t\tlet buffer = new Buffer(base64Data, 'base64');\n\t\t\t\t\tconst fileNameHash = hash(buffer);\n\t\t\t\t\tif (imageHashMap.hasOwnProperty(fileNameHash)) {\n\t\t\t\t\t\tuuid = imageHashMap[fileNameHash];\n\t\t\t\t\t} else {\n\t\t\t\t\t\timageHashMap[fileNameHash] = uuid;\n\t\t\t\t\t\tassets.push({\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\text,\n\t\t\t\t\t\t\tuuid,\n\t\t\t\t\t\t\tbase64Data,\n\t\t\t\t\t\t\thash: fileNameHash,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tproperties.source = 'asset://' + uuid;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tlet viewParent = parent.view || viewRoot;\n\t\tif (!viewParent.hasOwnProperty('children')) {\n\t\t\tviewParent.children = [];\n\t\t}\n\t\tviewParent.children.push(viewNode);\n\n\t\tnode.view = viewNode;\n\t});\n\n\tlet data = {\n\t\tview: viewRoot,\n\t\tassets,\n\t};\n\n\tlet dataString = JSON.stringify(data);\n\n\tlet buf = new Buffer(dataString);\n\treturn await new Promise((resolve, reject) => {\n\t\tzlib.gzip(buf, function (err, res) {\n\t\t\tif (err) {\n\t\t\t\treject(err);\n\t\t\t} else {\n\t\t\t\tconsole.log(res.length);\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;;;;;;;;;;CAAA;CACA;CACA;;CAEA,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;;AAErC,CAAO,eAAe,OAAO,CAAC,IAAI,EAAE;CACpC,CAAC,IAAI,GAAG,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;;CAE3C,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;CACjB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;;CAExB,CAAC,OAAO,IAAI,CAAC;CACb,CAAC;;CAED,SAAS,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE;CAChC,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;CAC/D,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC;CAC5E,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;CACxB,CAAC,MAAM,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;;CAEtB,CAAC,MA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G,EAAC;CACJ,EAAE,CAAC;CACH,CAAC;;;;;;;;;;;;;"}
\ No newline at end of file
......@@ -102,7 +102,7 @@ export async function execute(psdFile, options) {
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
} else if (solidColor && layer.vectorMask) {
const {r, g, b} = solidColor();
let color = Color({r, g, b});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment