Commit 05b0ebd5 authored by rockyl's avatar rockyl

增加相对位置的解析

parent 3b226df5
......@@ -65,6 +65,17 @@ async function walkNode(node, callback, includeSelf = false) {
* 导出zeroing的视图
*/
const relativePosPrefixMap = {
l: 'left',
t: 'top',
r: 'right',
b: 'bottom',
h: 'horizonCenter',
v: 'verticalCenter',
wp: 'percentWidth',
hp: 'percentHeight',
};
async function execute(psdFile, options) {
const tree = await getTree(psdFile);
......@@ -78,11 +89,31 @@ async function execute(psdFile, options) {
const imageHashMap = {};
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
let {name} = node;
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
console.log('walk node:', name);
let properties = {
width, height, alpha, visible,
};
if (name.includes('|')) {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[0];
let params = paramsStr.split(';');
let relativePos = params[0];
if (relativePos) {
let items = relativePos.split(',');
for (let item of items) {
let prefix = item[0];
let field = relativePosPrefixMap[prefix];
if (field) {
properties[field] = parseFloat(item.substr(1));
}
}
}
}
let viewNode = {
name,
properties,
......@@ -98,19 +129,12 @@ async function execute(psdFile, options) {
if (typeTool) {
let fontInfo = typeTool();
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties.text = fontInfo.textValue;
const sizes = fontInfo.sizes();
const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
let [r, g, b, a] = colors[0];
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
/*properties.textflow = {
fonts, styles, RunLengthArray,
};*/
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
......@@ -147,7 +171,7 @@ async function execute(psdFile, options) {
try {
let img = node.origin.toPng();
dataUrl = img.src;
}catch (e) {
} catch (e) {
}
......@@ -191,11 +215,11 @@ async function execute(psdFile, options) {
console.log(dataString.length);
let buf = new Buffer(dataString);
return await new Promise((resolve, reject)=>{
zlib.gzip(buf,function(err,res){
if(err){
return await new Promise((resolve, reject) => {
zlib.gzip(buf, function (err, res) {
if (err) {
reject(err);
}else{
} else {
console.log(res.length);
resolve(res);
}
......
This diff is collapsed.
......@@ -71,6 +71,17 @@ async function walkNode(node, callback, includeSelf = false) {
* 导出zeroing的视图
*/
const relativePosPrefixMap = {
l: 'left',
t: 'top',
r: 'right',
b: 'bottom',
h: 'horizonCenter',
v: 'verticalCenter',
wp: 'percentWidth',
hp: 'percentHeight',
};
async function execute(psdFile, options) {
const tree = await getTree(psdFile);
......@@ -84,11 +95,31 @@ async function execute(psdFile, options) {
const imageHashMap = {};
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
let {name} = node;
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
console.log('walk node:', name);
let properties = {
width, height, alpha, visible,
};
if (name.includes('|')) {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[0];
let params = paramsStr.split(';');
let relativePos = params[0];
if (relativePos) {
let items = relativePos.split(',');
for (let item of items) {
let prefix = item[0];
let field = relativePosPrefixMap[prefix];
if (field) {
properties[field] = parseFloat(item.substr(1));
}
}
}
}
let viewNode = {
name,
properties,
......@@ -104,19 +135,12 @@ async function execute(psdFile, options) {
if (typeTool) {
let fontInfo = typeTool();
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties.text = fontInfo.textValue;
const sizes = fontInfo.sizes();
const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
let [r, g, b, a] = colors[0];
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
/*properties.textflow = {
fonts, styles, RunLengthArray,
};*/
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
......@@ -153,7 +177,7 @@ async function execute(psdFile, options) {
try {
let img = node.origin.toPng();
dataUrl = img.src;
}catch (e) {
} catch (e) {
}
......@@ -197,11 +221,11 @@ async function execute(psdFile, options) {
console.log(dataString.length);
let buf = new Buffer(dataString);
return await new Promise((resolve, reject)=>{
zlib.gzip(buf,function(err,res){
if(err){
return await new Promise((resolve, reject) => {
zlib.gzip(buf, function (err, res) {
if (err) {
reject(err);
}else{
} else {
console.log(res.length);
resolve(res);
}
......
This diff is collapsed.
......@@ -71,6 +71,17 @@
* 导出zeroing的视图
*/
const relativePosPrefixMap = {
l: 'left',
t: 'top',
r: 'right',
b: 'bottom',
h: 'horizonCenter',
v: 'verticalCenter',
wp: 'percentWidth',
hp: 'percentHeight',
};
async function execute(psdFile, options) {
const tree = await getTree(psdFile);
......@@ -84,11 +95,31 @@
const imageHashMap = {};
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
let {name} = node;
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
console.log('walk node:', name);
let properties = {
width, height, alpha, visible,
};
if (name.includes('|')) {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[0];
let params = paramsStr.split(';');
let relativePos = params[0];
if (relativePos) {
let items = relativePos.split(',');
for (let item of items) {
let prefix = item[0];
let field = relativePosPrefixMap[prefix];
if (field) {
properties[field] = parseFloat(item.substr(1));
}
}
}
}
let viewNode = {
name,
properties,
......@@ -104,19 +135,12 @@
if (typeTool) {
let fontInfo = typeTool();
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties.text = fontInfo.textValue;
const sizes = fontInfo.sizes();
const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
let [r, g, b, a] = colors[0];
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
/*properties.textflow = {
fonts, styles, RunLengthArray,
};*/
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
......@@ -153,7 +177,7 @@
try {
let img = node.origin.toPng();
dataUrl = img.src;
}catch (e) {
} catch (e) {
}
......@@ -197,11 +221,11 @@
console.log(dataString.length);
let buf = new Buffer(dataString);
return await new Promise((resolve, reject)=>{
zlib.gzip(buf,function(err,res){
if(err){
return await new Promise((resolve, reject) => {
zlib.gzip(buf, function (err, res) {
if (err) {
reject(err);
}else{
} else {
console.log(res.length);
resolve(res);
}
......
This diff is collapsed.
......@@ -5,6 +5,7 @@
"module": "dist/index.es.js",
"license": "MIT",
"scripts": {
"dev": "rollup -c -w",
"build": "rollup -c"
},
"dependencies": {
......
......@@ -12,6 +12,17 @@ import generateUUID from 'uuid/v4'
import hash from 'object-hash';
import zlib from 'zlib';
const relativePosPrefixMap = {
l: 'left',
t: 'top',
r: 'right',
b: 'bottom',
h: 'horizonCenter',
v: 'verticalCenter',
wp: 'percentWidth',
hp: 'percentHeight',
};
export async function execute(psdFile, options) {
const tree = await getTree(psdFile);
......@@ -25,11 +36,31 @@ export async function execute(psdFile, options) {
const imageHashMap = {};
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
let {name} = node;
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
console.log('walk node:', name);
let properties = {
width, height, alpha, visible,
};
if (name.includes('|')) {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[0];
let params = paramsStr.split(';');
let relativePos = params[0];
if (relativePos) {
let items = relativePos.split(',');
for (let item of items) {
let prefix = item[0];
let field = relativePosPrefixMap[prefix];
if (field) {
properties[field] = parseFloat(item.substr(1));
}
}
}
}
let viewNode = {
name,
properties,
......@@ -45,19 +76,12 @@ export async function execute(psdFile, options) {
if (typeTool) {
let fontInfo = typeTool();
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties.text = fontInfo.textValue;
const sizes = fontInfo.sizes();
const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
let [r, g, b, a] = colors[0];
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
/*properties.textflow = {
fonts, styles, RunLengthArray,
};*/
viewNode.type = 'label';
dealLater = false;
} else if (solidColor) {
......@@ -94,7 +118,7 @@ export async function execute(psdFile, options) {
try {
let img = node.origin.toPng();
dataUrl = img.src;
}catch (e) {
} catch (e) {
}
......@@ -138,11 +162,11 @@ export async function execute(psdFile, options) {
console.log(dataString.length);
let buf = new Buffer(dataString);
return await new Promise((resolve, reject)=>{
zlib.gzip(buf,function(err,res){
if(err){
return await new Promise((resolve, reject) => {
zlib.gzip(buf, function (err, res) {
if (err) {
reject(err);
}else{
} else {
console.log(res.length);
resolve(res);
}
......
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