Commit 144f980e authored by rockyl's avatar rockyl

支持宽高百分比

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