Commit 5cc49b8f authored by rockyl's avatar rockyl

放假前提交一波

parent 358bd784
......@@ -72,25 +72,23 @@ const relativePosPrefixMap = {
b: {field: 'bottom',},
h: {field: 'horizonCenter',},
v: {field: 'verticalCenter',},
wp: {field: 'width', },
hp: {field: 'height', },
lp: {field: 'left', },
tp: {field: 'top', },
rp: {field: 'right', },
bp: {field: 'bottom', },
wp: {field: 'width',},
hp: {field: 'height',},
lp: {field: 'left',},
tp: {field: 'top',},
rp: {field: 'right',},
bp: {field: 'bottom',},
};
const offsetAll = 176;
const enterChar = String.fromCharCode(13);
async function execute(psdFile, options) {
const tree = await getTree(psdFile);
const {mode = 'none'} = options;
const {mode = 'none', singleView = true} = options;
let offset = {x: 0, y: 0};
let cutSize = {x: 0, y: 0};
if(mode !== 'none'){
cutSize.y = offsetAll;
}
switch(mode){
switch (mode) {
case 'top':
offset.y = offsetAll;
break;
......@@ -108,10 +106,6 @@ async function execute(psdFile, options) {
const assets = [];
const imageHashMap = {};
let {width: stageWidth, height: stageHeight} = tree;
stageWidth -= 0;
stageHeight -= cutSize.y || 0;
await walkNode(tree, async function (node, parent) {
let {name} = node;
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
......@@ -121,6 +115,8 @@ async function execute(psdFile, options) {
};
const isSecondLayer = !parent.origin.parent;
const {width: parentWidth, height: parentHeight} = parent;
if (name.includes('|')) {
try {
let arr = name.split('|');
......@@ -132,7 +128,7 @@ async function execute(psdFile, options) {
let items = relativePos.split(',');
for (let item of items) {
let result = item.match(/[a-zA-Z]+/);
if(!result){
if (!result) {
continue;
}
let prefix = result[0];
......@@ -142,8 +138,8 @@ async function execute(psdFile, options) {
let value = item.substr(prefix.length);
let hasValue = value.length > 0;
let fieldChar = prefix[0];
if(!hasValue){
switch(fieldChar){
if (!hasValue) {
switch (fieldChar) {
case 'l':
value = x - offset.x;
break;
......@@ -151,30 +147,30 @@ async function execute(psdFile, options) {
value = y - offset.y;
break;
case 'r':
value = stageWidth - (x - offset.x) - width;
value = parentWidth - (x - offset.x) - width;
break;
case 'b':
value = stageHeight - (y - offset.y) - height;
value = parentHeight - (y - offset.y) - height;
break;
case 'h':
value = x + width / 2 - stageWidth / 2;
value = x + width / 2 - parentWidth / 2;
break;
case 'v':
value = y + height / 2 - stageHeight / 2;
value = y + height / 2 - parentHeight / 2;
break;
}
}
let isPercent = prefix.endsWith('p');
if (isPercent) {
if(!hasValue){
switch(fieldChar){
if (!hasValue) {
switch (fieldChar) {
case 'l':
case 'r':
value /= stageWidth;
value /= parentWidth;
break;
case 't':
case 'b':
value /= stageHeight;
value /= parentHeight;
break;
}
value = Math.floor(value * 100);
......@@ -190,7 +186,7 @@ async function execute(psdFile, options) {
}
}
}
}catch (e) {
} catch (e) {
console.log(e);
}
}
......@@ -201,16 +197,22 @@ async function execute(psdFile, options) {
uuid: generateUUID(),
};
let dealLater = true;
if (x !== 0) {
properties.x = x;// - (isSecondLayer ? offset.x : 0);
let px = x;// - (!singleView && isSecondLayer ? offset.x : 0);
let py = y;// - (!singleView && isSecondLayer ? offset.y : 0);
if (px !== 0) {
properties.x = px;
}
if (y !== 0) {
properties.y = y;// - (isSecondLayer ? offset.y : 0);
if (py !== 0) {
properties.y = py;
}
if (typeTool) {
let fontInfo = typeTool();
properties.text = fontInfo.textValue;
let text = fontInfo.textValue;
if (text.indexOf(enterChar) < 0) { //如果未包含回车说明是多行,去掉宽度
delete properties['width'];
}
properties.text = text;
const sizes = fontInfo.sizes();
const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
......
This diff is collapsed.
......@@ -78,25 +78,23 @@ const relativePosPrefixMap = {
b: {field: 'bottom',},
h: {field: 'horizonCenter',},
v: {field: 'verticalCenter',},
wp: {field: 'width', },
hp: {field: 'height', },
lp: {field: 'left', },
tp: {field: 'top', },
rp: {field: 'right', },
bp: {field: 'bottom', },
wp: {field: 'width',},
hp: {field: 'height',},
lp: {field: 'left',},
tp: {field: 'top',},
rp: {field: 'right',},
bp: {field: 'bottom',},
};
const offsetAll = 176;
const enterChar = String.fromCharCode(13);
async function execute(psdFile, options) {
const tree = await getTree(psdFile);
const {mode = 'none'} = options;
const {mode = 'none', singleView = true} = options;
let offset = {x: 0, y: 0};
let cutSize = {x: 0, y: 0};
if(mode !== 'none'){
cutSize.y = offsetAll;
}
switch(mode){
switch (mode) {
case 'top':
offset.y = offsetAll;
break;
......@@ -114,10 +112,6 @@ async function execute(psdFile, options) {
const assets = [];
const imageHashMap = {};
let {width: stageWidth, height: stageHeight} = tree;
stageWidth -= 0;
stageHeight -= cutSize.y || 0;
await walkNode(tree, async function (node, parent) {
let {name} = node;
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
......@@ -127,6 +121,8 @@ async function execute(psdFile, options) {
};
const isSecondLayer = !parent.origin.parent;
const {width: parentWidth, height: parentHeight} = parent;
if (name.includes('|')) {
try {
let arr = name.split('|');
......@@ -138,7 +134,7 @@ async function execute(psdFile, options) {
let items = relativePos.split(',');
for (let item of items) {
let result = item.match(/[a-zA-Z]+/);
if(!result){
if (!result) {
continue;
}
let prefix = result[0];
......@@ -148,8 +144,8 @@ async function execute(psdFile, options) {
let value = item.substr(prefix.length);
let hasValue = value.length > 0;
let fieldChar = prefix[0];
if(!hasValue){
switch(fieldChar){
if (!hasValue) {
switch (fieldChar) {
case 'l':
value = x - offset.x;
break;
......@@ -157,30 +153,30 @@ async function execute(psdFile, options) {
value = y - offset.y;
break;
case 'r':
value = stageWidth - (x - offset.x) - width;
value = parentWidth - (x - offset.x) - width;
break;
case 'b':
value = stageHeight - (y - offset.y) - height;
value = parentHeight - (y - offset.y) - height;
break;
case 'h':
value = x + width / 2 - stageWidth / 2;
value = x + width / 2 - parentWidth / 2;
break;
case 'v':
value = y + height / 2 - stageHeight / 2;
value = y + height / 2 - parentHeight / 2;
break;
}
}
let isPercent = prefix.endsWith('p');
if (isPercent) {
if(!hasValue){
switch(fieldChar){
if (!hasValue) {
switch (fieldChar) {
case 'l':
case 'r':
value /= stageWidth;
value /= parentWidth;
break;
case 't':
case 'b':
value /= stageHeight;
value /= parentHeight;
break;
}
value = Math.floor(value * 100);
......@@ -196,7 +192,7 @@ async function execute(psdFile, options) {
}
}
}
}catch (e) {
} catch (e) {
console.log(e);
}
}
......@@ -207,16 +203,22 @@ async function execute(psdFile, options) {
uuid: generateUUID(),
};
let dealLater = true;
if (x !== 0) {
properties.x = x;// - (isSecondLayer ? offset.x : 0);
let px = x;// - (!singleView && isSecondLayer ? offset.x : 0);
let py = y;// - (!singleView && isSecondLayer ? offset.y : 0);
if (px !== 0) {
properties.x = px;
}
if (y !== 0) {
properties.y = y;// - (isSecondLayer ? offset.y : 0);
if (py !== 0) {
properties.y = py;
}
if (typeTool) {
let fontInfo = typeTool();
properties.text = fontInfo.textValue;
let text = fontInfo.textValue;
if (text.indexOf(enterChar) < 0) { //如果未包含回车说明是多行,去掉宽度
delete properties['width'];
}
properties.text = text;
const sizes = fontInfo.sizes();
const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
......
This diff is collapsed.
......@@ -78,25 +78,23 @@
b: {field: 'bottom',},
h: {field: 'horizonCenter',},
v: {field: 'verticalCenter',},
wp: {field: 'width', },
hp: {field: 'height', },
lp: {field: 'left', },
tp: {field: 'top', },
rp: {field: 'right', },
bp: {field: 'bottom', },
wp: {field: 'width',},
hp: {field: 'height',},
lp: {field: 'left',},
tp: {field: 'top',},
rp: {field: 'right',},
bp: {field: 'bottom',},
};
const offsetAll = 176;
const enterChar = String.fromCharCode(13);
async function execute(psdFile, options) {
const tree = await getTree(psdFile);
const {mode = 'none'} = options;
const {mode = 'none', singleView = true} = options;
let offset = {x: 0, y: 0};
let cutSize = {x: 0, y: 0};
if(mode !== 'none'){
cutSize.y = offsetAll;
}
switch(mode){
switch (mode) {
case 'top':
offset.y = offsetAll;
break;
......@@ -114,10 +112,6 @@
const assets = [];
const imageHashMap = {};
let {width: stageWidth, height: stageHeight} = tree;
stageWidth -= 0;
stageHeight -= cutSize.y || 0;
await walkNode(tree, async function (node, parent) {
let {name} = node;
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
......@@ -127,6 +121,8 @@
};
const isSecondLayer = !parent.origin.parent;
const {width: parentWidth, height: parentHeight} = parent;
if (name.includes('|')) {
try {
let arr = name.split('|');
......@@ -138,7 +134,7 @@
let items = relativePos.split(',');
for (let item of items) {
let result = item.match(/[a-zA-Z]+/);
if(!result){
if (!result) {
continue;
}
let prefix = result[0];
......@@ -148,8 +144,8 @@
let value = item.substr(prefix.length);
let hasValue = value.length > 0;
let fieldChar = prefix[0];
if(!hasValue){
switch(fieldChar){
if (!hasValue) {
switch (fieldChar) {
case 'l':
value = x - offset.x;
break;
......@@ -157,30 +153,30 @@
value = y - offset.y;
break;
case 'r':
value = stageWidth - (x - offset.x) - width;
value = parentWidth - (x - offset.x) - width;
break;
case 'b':
value = stageHeight - (y - offset.y) - height;
value = parentHeight - (y - offset.y) - height;
break;
case 'h':
value = x + width / 2 - stageWidth / 2;
value = x + width / 2 - parentWidth / 2;
break;
case 'v':
value = y + height / 2 - stageHeight / 2;
value = y + height / 2 - parentHeight / 2;
break;
}
}
let isPercent = prefix.endsWith('p');
if (isPercent) {
if(!hasValue){
switch(fieldChar){
if (!hasValue) {
switch (fieldChar) {
case 'l':
case 'r':
value /= stageWidth;
value /= parentWidth;
break;
case 't':
case 'b':
value /= stageHeight;
value /= parentHeight;
break;
}
value = Math.floor(value * 100);
......@@ -196,7 +192,7 @@
}
}
}
}catch (e) {
} catch (e) {
console.log(e);
}
}
......@@ -207,16 +203,22 @@
uuid: generateUUID(),
};
let dealLater = true;
if (x !== 0) {
properties.x = x;// - (isSecondLayer ? offset.x : 0);
let px = x;// - (!singleView && isSecondLayer ? offset.x : 0);
let py = y;// - (!singleView && isSecondLayer ? offset.y : 0);
if (px !== 0) {
properties.x = px;
}
if (y !== 0) {
properties.y = y;// - (isSecondLayer ? offset.y : 0);
if (py !== 0) {
properties.y = py;
}
if (typeTool) {
let fontInfo = typeTool();
properties.text = fontInfo.textValue;
let text = fontInfo.textValue;
if (text.indexOf(enterChar) < 0) { //如果未包含回车说明是多行,去掉宽度
delete properties['width'];
}
properties.text = text;
const sizes = fontInfo.sizes();
const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
......
This diff is collapsed.
......@@ -19,25 +19,27 @@ const relativePosPrefixMap = {
b: {field: 'bottom',},
h: {field: 'horizonCenter',},
v: {field: 'verticalCenter',},
wp: {field: 'width', },
hp: {field: 'height', },
lp: {field: 'left', },
tp: {field: 'top', },
rp: {field: 'right', },
bp: {field: 'bottom', },
wp: {field: 'width',},
hp: {field: 'height',},
lp: {field: 'left',},
tp: {field: 'top',},
rp: {field: 'right',},
bp: {field: 'bottom',},
};
const offsetAll = 176;
const enterChar = String.fromCharCode(13);
export async function execute(psdFile, options) {
const tree = await getTree(psdFile);
const {mode = 'none'} = options;
const {mode = 'none', singleView = true} = options;
let offset = {x: 0, y: 0};
let cutSize = {x: 0, y: 0};
if(mode !== 'none'){
if (mode !== 'none') {
cutSize.y = offsetAll;
}
switch(mode){
switch (mode) {
case 'top':
offset.y = offsetAll;
break;
......@@ -81,7 +83,7 @@ export async function execute(psdFile, options) {
let items = relativePos.split(',');
for (let item of items) {
let result = item.match(/[a-zA-Z]+/);
if(!result){
if (!result) {
continue;
}
let prefix = result[0];
......@@ -91,8 +93,8 @@ export async function execute(psdFile, options) {
let value = item.substr(prefix.length);
let hasValue = value.length > 0;
let fieldChar = prefix[0];
if(!hasValue){
switch(fieldChar){
if (!hasValue) {
switch (fieldChar) {
case 'l':
value = x - offset.x;
break;
......@@ -100,30 +102,30 @@ export async function execute(psdFile, options) {
value = y - offset.y;
break;
case 'r':
value = stageWidth - (x - offset.x) - width;
value = parentWidth - (x - offset.x) - width;
break;
case 'b':
value = stageHeight - (y - offset.y) - height;
value = parentHeight - (y - offset.y) - height;
break;
case 'h':
value = x + width / 2 - stageWidth / 2;
value = x + width / 2 - parentWidth / 2;
break;
case 'v':
value = y + height / 2 - stageHeight / 2;
value = y + height / 2 - parentHeight / 2;
break;
}
}
let isPercent = prefix.endsWith('p');
if (isPercent) {
if(!hasValue){
switch(fieldChar){
if (!hasValue) {
switch (fieldChar) {
case 'l':
case 'r':
value /= stageWidth;
value /= parentWidth;
break;
case 't':
case 'b':
value /= stageHeight;
value /= parentHeight;
break;
}
value = Math.floor(value * 100);
......@@ -139,7 +141,7 @@ export async function execute(psdFile, options) {
}
}
}
}catch (e) {
} catch (e) {
console.log(e);
}
}
......@@ -150,16 +152,22 @@ export async function execute(psdFile, options) {
uuid: generateUUID(),
};
let dealLater = true;
if (x !== 0) {
properties.x = x;// - (isSecondLayer ? offset.x : 0);
let px = x;// - (!singleView && isSecondLayer ? offset.x : 0);
let py = y;// - (!singleView && isSecondLayer ? offset.y : 0);
if (px !== 0) {
properties.x = px;
}
if (y !== 0) {
properties.y = y;// - (isSecondLayer ? offset.y : 0);
if (py !== 0) {
properties.y = py;
}
if (typeTool) {
let fontInfo = typeTool();
properties.text = fontInfo.textValue;
let text = fontInfo.textValue;
if (text.indexOf(enterChar) < 0) { //如果未包含回车说明是多行,去掉宽度
delete properties['width'];
}
properties.text = text;
const sizes = fontInfo.sizes();
const colors = fontInfo.colors();
properties.size = sizes ? sizes[0] || 20 : 20;
......
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