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,6 +97,7 @@ async function execute(psdFile, options) {
};
if (name.includes('|')) {
try {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[1];
......@@ -105,17 +106,30 @@ async function execute(psdFile, options) {
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)){
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;
}
}
}
}catch (e) {
console.log(e);
}
}
let viewNode = {
......@@ -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,6 +103,7 @@ async function execute(psdFile, options) {
};
if (name.includes('|')) {
try {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[1];
......@@ -111,17 +112,30 @@ async function execute(psdFile, options) {
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)){
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;
}
}
}
}catch (e) {
console.log(e);
}
}
let viewNode = {
......@@ -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,6 +103,7 @@
};
if (name.includes('|')) {
try {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[1];
......@@ -111,17 +112,30 @@
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)){
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;
}
}
}
}catch (e) {
console.log(e);
}
}
let viewNode = {
......@@ -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,6 +44,7 @@ export async function execute(psdFile, options) {
};
if (name.includes('|')) {
try {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[1];
......@@ -52,17 +53,30 @@ export async function execute(psdFile, options) {
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)){
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;
}
}
}
}catch (e) {
console.log(e);
}
}
let viewNode = {
......@@ -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