Commit 5cc49b8f authored by rockyl's avatar rockyl

放假前提交一波

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