Commit 144f980e authored by rockyl's avatar rockyl

支持宽高百分比

parent 9524069b
...@@ -66,14 +66,14 @@ async function walkNode(node, callback, includeSelf = false) { ...@@ -66,14 +66,14 @@ async function walkNode(node, callback, includeSelf = false) {
*/ */
const relativePosPrefixMap = { const relativePosPrefixMap = {
l: 'left', l: {field: 'left',},
t: 'top', t: {field: 'top',},
r: 'right', r: {field: 'right',},
b: 'bottom', b: {field: 'bottom',},
h: 'horizonCenter', h: {field: 'horizonCenter',},
v: 'verticalCenter', v: {field: 'verticalCenter',},
wp: 'percentWidth', wp: {field: 'width', isPercent: true},
hp: 'percentHeight', hp: {field: 'height', isPercent: true},
}; };
async function execute(psdFile, options) { async function execute(psdFile, options) {
...@@ -97,24 +97,38 @@ async function execute(psdFile, options) { ...@@ -97,24 +97,38 @@ async function execute(psdFile, options) {
}; };
if (name.includes('|')) { if (name.includes('|')) {
let arr = name.split('|'); try {
name = arr[0]; let arr = name.split('|');
let paramsStr = arr[1]; name = arr[0];
let params = paramsStr.split(';'); let paramsStr = arr[1];
let relativePos = params[0]; let params = paramsStr.split(';');
if (relativePos) { let relativePos = params[0];
let items = relativePos.split(','); if (relativePos) {
for (let item of items) { let items = relativePos.split(',');
let prefix = item[0]; for (let item of items) {
let field = relativePosPrefixMap[prefix]; let result = item.match(/[a-zA-Z]+/);
if (field) { if(!result){
let value = parseFloat(item.substr(1)); continue;
if(isNaN(value)){ }
value = 0; let prefix = result[0];
let mapItem = relativePosPrefixMap[prefix];
if (mapItem) {
const {field, isPercent} = mapItem;
let value = item.substr(prefix.length);
if (isPercent) {
value += '%';
} else {
value = parseFloat(value);
if (isNaN(value)) {
value = 0;
}
}
properties[field] = value;
} }
properties[field] = value;
} }
} }
}catch (e) {
console.log(e);
} }
} }
...@@ -216,7 +230,6 @@ async function execute(psdFile, options) { ...@@ -216,7 +230,6 @@ async function execute(psdFile, options) {
}; };
let dataString = JSON.stringify(data); let dataString = JSON.stringify(data);
console.log(dataString.length);
let buf = new Buffer(dataString); let buf = new Buffer(dataString);
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
......
This diff is collapsed.
...@@ -72,14 +72,14 @@ async function walkNode(node, callback, includeSelf = false) { ...@@ -72,14 +72,14 @@ async function walkNode(node, callback, includeSelf = false) {
*/ */
const relativePosPrefixMap = { const relativePosPrefixMap = {
l: 'left', l: {field: 'left',},
t: 'top', t: {field: 'top',},
r: 'right', r: {field: 'right',},
b: 'bottom', b: {field: 'bottom',},
h: 'horizonCenter', h: {field: 'horizonCenter',},
v: 'verticalCenter', v: {field: 'verticalCenter',},
wp: 'percentWidth', wp: {field: 'width', isPercent: true},
hp: 'percentHeight', hp: {field: 'height', isPercent: true},
}; };
async function execute(psdFile, options) { async function execute(psdFile, options) {
...@@ -103,24 +103,38 @@ async function execute(psdFile, options) { ...@@ -103,24 +103,38 @@ async function execute(psdFile, options) {
}; };
if (name.includes('|')) { if (name.includes('|')) {
let arr = name.split('|'); try {
name = arr[0]; let arr = name.split('|');
let paramsStr = arr[1]; name = arr[0];
let params = paramsStr.split(';'); let paramsStr = arr[1];
let relativePos = params[0]; let params = paramsStr.split(';');
if (relativePos) { let relativePos = params[0];
let items = relativePos.split(','); if (relativePos) {
for (let item of items) { let items = relativePos.split(',');
let prefix = item[0]; for (let item of items) {
let field = relativePosPrefixMap[prefix]; let result = item.match(/[a-zA-Z]+/);
if (field) { if(!result){
let value = parseFloat(item.substr(1)); continue;
if(isNaN(value)){ }
value = 0; let prefix = result[0];
let mapItem = relativePosPrefixMap[prefix];
if (mapItem) {
const {field, isPercent} = mapItem;
let value = item.substr(prefix.length);
if (isPercent) {
value += '%';
} else {
value = parseFloat(value);
if (isNaN(value)) {
value = 0;
}
}
properties[field] = value;
} }
properties[field] = value;
} }
} }
}catch (e) {
console.log(e);
} }
} }
...@@ -222,7 +236,6 @@ async function execute(psdFile, options) { ...@@ -222,7 +236,6 @@ async function execute(psdFile, options) {
}; };
let dataString = JSON.stringify(data); let dataString = JSON.stringify(data);
console.log(dataString.length);
let buf = new Buffer(dataString); let buf = new Buffer(dataString);
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
......
This diff is collapsed.
...@@ -72,14 +72,14 @@ ...@@ -72,14 +72,14 @@
*/ */
const relativePosPrefixMap = { const relativePosPrefixMap = {
l: 'left', l: {field: 'left',},
t: 'top', t: {field: 'top',},
r: 'right', r: {field: 'right',},
b: 'bottom', b: {field: 'bottom',},
h: 'horizonCenter', h: {field: 'horizonCenter',},
v: 'verticalCenter', v: {field: 'verticalCenter',},
wp: 'percentWidth', wp: {field: 'width', isPercent: true},
hp: 'percentHeight', hp: {field: 'height', isPercent: true},
}; };
async function execute(psdFile, options) { async function execute(psdFile, options) {
...@@ -103,24 +103,38 @@ ...@@ -103,24 +103,38 @@
}; };
if (name.includes('|')) { if (name.includes('|')) {
let arr = name.split('|'); try {
name = arr[0]; let arr = name.split('|');
let paramsStr = arr[1]; name = arr[0];
let params = paramsStr.split(';'); let paramsStr = arr[1];
let relativePos = params[0]; let params = paramsStr.split(';');
if (relativePos) { let relativePos = params[0];
let items = relativePos.split(','); if (relativePos) {
for (let item of items) { let items = relativePos.split(',');
let prefix = item[0]; for (let item of items) {
let field = relativePosPrefixMap[prefix]; let result = item.match(/[a-zA-Z]+/);
if (field) { if(!result){
let value = parseFloat(item.substr(1)); continue;
if(isNaN(value)){ }
value = 0; let prefix = result[0];
let mapItem = relativePosPrefixMap[prefix];
if (mapItem) {
const {field, isPercent} = mapItem;
let value = item.substr(prefix.length);
if (isPercent) {
value += '%';
} else {
value = parseFloat(value);
if (isNaN(value)) {
value = 0;
}
}
properties[field] = value;
} }
properties[field] = value;
} }
} }
}catch (e) {
console.log(e);
} }
} }
...@@ -222,7 +236,6 @@ ...@@ -222,7 +236,6 @@
}; };
let dataString = JSON.stringify(data); let dataString = JSON.stringify(data);
console.log(dataString.length);
let buf = new Buffer(dataString); let buf = new Buffer(dataString);
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
......
This diff is collapsed.
...@@ -13,14 +13,14 @@ import hash from 'object-hash'; ...@@ -13,14 +13,14 @@ import hash from 'object-hash';
import zlib from 'zlib'; import zlib from 'zlib';
const relativePosPrefixMap = { const relativePosPrefixMap = {
l: 'left', l: {field: 'left',},
t: 'top', t: {field: 'top',},
r: 'right', r: {field: 'right',},
b: 'bottom', b: {field: 'bottom',},
h: 'horizonCenter', h: {field: 'horizonCenter',},
v: 'verticalCenter', v: {field: 'verticalCenter',},
wp: 'percentWidth', wp: {field: 'width', isPercent: true},
hp: 'percentHeight', hp: {field: 'height', isPercent: true},
}; };
export async function execute(psdFile, options) { export async function execute(psdFile, options) {
...@@ -44,24 +44,38 @@ export async function execute(psdFile, options) { ...@@ -44,24 +44,38 @@ export async function execute(psdFile, options) {
}; };
if (name.includes('|')) { if (name.includes('|')) {
let arr = name.split('|'); try {
name = arr[0]; let arr = name.split('|');
let paramsStr = arr[1]; name = arr[0];
let params = paramsStr.split(';'); let paramsStr = arr[1];
let relativePos = params[0]; let params = paramsStr.split(';');
if (relativePos) { let relativePos = params[0];
let items = relativePos.split(','); if (relativePos) {
for (let item of items) { let items = relativePos.split(',');
let prefix = item[0]; for (let item of items) {
let field = relativePosPrefixMap[prefix]; let result = item.match(/[a-zA-Z]+/);
if (field) { if(!result){
let value = parseFloat(item.substr(1)); continue;
if(isNaN(value)){ }
value = 0; let prefix = result[0];
let mapItem = relativePosPrefixMap[prefix];
if (mapItem) {
const {field, isPercent} = mapItem;
let value = item.substr(prefix.length);
if (isPercent) {
value += '%';
} else {
value = parseFloat(value);
if (isNaN(value)) {
value = 0;
}
}
properties[field] = value;
} }
properties[field] = value;
} }
} }
}catch (e) {
console.log(e);
} }
} }
...@@ -163,7 +177,6 @@ export async function execute(psdFile, options) { ...@@ -163,7 +177,6 @@ export async function execute(psdFile, options) {
}; };
let dataString = JSON.stringify(data); let dataString = JSON.stringify(data);
console.log(dataString.length);
let buf = new Buffer(dataString); let buf = new Buffer(dataString);
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
......
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