Commit e1de4f5d authored by 任建锋's avatar 任建锋

--

parent 6da75550
......@@ -82,7 +82,24 @@ const relativePosPrefixMap = {
async function execute(psdFile, options) {
const tree = await getTree(psdFile);
const offset = options ? options.offset : {x: 0, y: 0};
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) {
case 'top':
offset.y = offsetAll;
break;
case 'center':
offset.y = offsetAll / 2;
break;
}
const isCenter = mode === 'center';
let viewRoot = {
name: path.basename(psdFile.name, '.psd'),
......@@ -93,9 +110,9 @@ async function execute(psdFile, options) {
const assets = [];
const imageHashMap = {};
let {width: stageWidth, height: stageHeight} = tree;
stageWidth -= offset.x || 0;
stageHeight -= offset.y || 0;
let {width: stageWidthOrigin, height: stageHeightOrigin} = tree;
const stageWidth = stageWidthOrigin - cutSize.x || 0;
const stageHeight = stageHeightOrigin - cutSize.y || 0;
await walkNode(tree, async function (node, parent) {
let {name} = node;
......@@ -110,15 +127,22 @@ async function execute(psdFile, options) {
},
className:""
};
const isSecondLayer = !parent.origin.parent;
const isSecondLayer = singleView && !parent.origin.parent || !singleView && parent.origin.parent && !parent.origin.parent.parent;
const shouldVerticalCenter = isSecondLayer && isCenter;
if (name.includes('|')) {
if (name.includes('|') || shouldVerticalCenter) {
try {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[1];
let params = paramsStr.split(';');
let relativePos = params[0];
let relativePos;
if(paramsStr){
let params = paramsStr.split(';');
relativePos = params[0];
}else if(shouldVerticalCenter){
relativePos = 'v';
}
if (relativePos) {
let items = relativePos.split(',');
for (let item of items) {
......@@ -142,16 +166,16 @@ async function execute(psdFile, options) {
value = y - offset.y;
break;
case 'r':
value = stageWidth - width;
value = stageWidth - (x - offset.x) - width;
break;
case 'b':
value = stageHeight - height;
value = stageHeight - (y - offset.y) - height;
break;
case 'h':
value = x + width / 2 - stageWidth / 2;
value = x + width / 2 - stageWidthOrigin / 2;
break;
case 'v':
value = y + height / 2 - stageHeight / 2;
value = y + height / 2 - stageHeightOrigin / 2;
break;
}
}
......
This diff is collapsed.
......@@ -88,7 +88,24 @@ const relativePosPrefixMap = {
async function execute(psdFile, options) {
const tree = await getTree(psdFile);
const offset = options ? options.offset : {x: 0, y: 0};
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) {
case 'top':
offset.y = offsetAll;
break;
case 'center':
offset.y = offsetAll / 2;
break;
}
const isCenter = mode === 'center';
let viewRoot = {
name: path.basename(psdFile.name, '.psd'),
......@@ -99,9 +116,9 @@ async function execute(psdFile, options) {
const assets = [];
const imageHashMap = {};
let {width: stageWidth, height: stageHeight} = tree;
stageWidth -= offset.x || 0;
stageHeight -= offset.y || 0;
let {width: stageWidthOrigin, height: stageHeightOrigin} = tree;
const stageWidth = stageWidthOrigin - cutSize.x || 0;
const stageHeight = stageHeightOrigin - cutSize.y || 0;
await walkNode(tree, async function (node, parent) {
let {name} = node;
......@@ -116,15 +133,22 @@ async function execute(psdFile, options) {
},
className:""
};
const isSecondLayer = !parent.origin.parent;
const isSecondLayer = singleView && !parent.origin.parent || !singleView && parent.origin.parent && !parent.origin.parent.parent;
const shouldVerticalCenter = isSecondLayer && isCenter;
if (name.includes('|')) {
if (name.includes('|') || shouldVerticalCenter) {
try {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[1];
let params = paramsStr.split(';');
let relativePos = params[0];
let relativePos;
if(paramsStr){
let params = paramsStr.split(';');
relativePos = params[0];
}else if(shouldVerticalCenter){
relativePos = 'v';
}
if (relativePos) {
let items = relativePos.split(',');
for (let item of items) {
......@@ -148,16 +172,16 @@ async function execute(psdFile, options) {
value = y - offset.y;
break;
case 'r':
value = stageWidth - width;
value = stageWidth - (x - offset.x) - width;
break;
case 'b':
value = stageHeight - height;
value = stageHeight - (y - offset.y) - height;
break;
case 'h':
value = x + width / 2 - stageWidth / 2;
value = x + width / 2 - stageWidthOrigin / 2;
break;
case 'v':
value = y + height / 2 - stageHeight / 2;
value = y + height / 2 - stageHeightOrigin / 2;
break;
}
}
......
This diff is collapsed.
......@@ -88,7 +88,24 @@
async function execute(psdFile, options) {
const tree = await getTree(psdFile);
const offset = options ? options.offset : {x: 0, y: 0};
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) {
case 'top':
offset.y = offsetAll;
break;
case 'center':
offset.y = offsetAll / 2;
break;
}
const isCenter = mode === 'center';
let viewRoot = {
name: path.basename(psdFile.name, '.psd'),
......@@ -99,9 +116,9 @@
const assets = [];
const imageHashMap = {};
let {width: stageWidth, height: stageHeight} = tree;
stageWidth -= offset.x || 0;
stageHeight -= offset.y || 0;
let {width: stageWidthOrigin, height: stageHeightOrigin} = tree;
const stageWidth = stageWidthOrigin - cutSize.x || 0;
const stageHeight = stageHeightOrigin - cutSize.y || 0;
await walkNode(tree, async function (node, parent) {
let {name} = node;
......@@ -116,15 +133,22 @@
},
className:""
};
const isSecondLayer = !parent.origin.parent;
const isSecondLayer = singleView && !parent.origin.parent || !singleView && parent.origin.parent && !parent.origin.parent.parent;
const shouldVerticalCenter = isSecondLayer && isCenter;
if (name.includes('|')) {
if (name.includes('|') || shouldVerticalCenter) {
try {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[1];
let params = paramsStr.split(';');
let relativePos = params[0];
let relativePos;
if(paramsStr){
let params = paramsStr.split(';');
relativePos = params[0];
}else if(shouldVerticalCenter){
relativePos = 'v';
}
if (relativePos) {
let items = relativePos.split(',');
for (let item of items) {
......@@ -148,16 +172,16 @@
value = y - offset.y;
break;
case 'r':
value = stageWidth - width;
value = stageWidth - (x - offset.x) - width;
break;
case 'b':
value = stageHeight - height;
value = stageHeight - (y - offset.y) - height;
break;
case 'h':
value = x + width / 2 - stageWidth / 2;
value = x + width / 2 - stageWidthOrigin / 2;
break;
case 'v':
value = y + height / 2 - stageHeight / 2;
value = y + height / 2 - stageHeightOrigin / 2;
break;
}
}
......
This diff is collapsed.
......@@ -29,7 +29,24 @@ const relativePosPrefixMap = {
export async function execute(psdFile, options) {
const tree = await getTree(psdFile);
const offset = options ? options.offset : {x: 0, y: 0};
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) {
case 'top':
offset.y = offsetAll;
break;
case 'center':
offset.y = offsetAll / 2;
break;
}
const isCenter = mode === 'center';
let viewRoot = {
name: path.basename(psdFile.name, '.psd'),
......@@ -40,9 +57,9 @@ export async function execute(psdFile, options) {
const assets = [];
const imageHashMap = {};
let {width: stageWidth, height: stageHeight} = tree;
stageWidth -= offset.x || 0;
stageHeight -= offset.y || 0;
let {width: stageWidthOrigin, height: stageHeightOrigin} = tree;
const stageWidth = stageWidthOrigin - cutSize.x || 0;
const stageHeight = stageHeightOrigin - cutSize.y || 0;
await walkNode(tree, async function (node, parent) {
let {name} = node;
......@@ -57,15 +74,24 @@ export async function execute(psdFile, options) {
},
className:""
};
const isSecondLayer = !parent.origin.parent;
const isSecondLayer = singleView && !parent.origin.parent || !singleView && parent.origin.parent && !parent.origin.parent.parent;
const shouldVerticalCenter = isSecondLayer && isCenter;
if (name.includes('|')) {
const {width: parentWidth, height: parentHeight} = parent;
if (name.includes('|') || shouldVerticalCenter) {
try {
let arr = name.split('|');
name = arr[0];
let paramsStr = arr[1];
let params = paramsStr.split(';');
let relativePos = params[0];
let relativePos;
if(paramsStr){
let params = paramsStr.split(';');
relativePos = params[0];
}else if(shouldVerticalCenter){
relativePos = 'v';
}
if (relativePos) {
let items = relativePos.split(',');
for (let item of items) {
......@@ -89,16 +115,16 @@ export async function execute(psdFile, options) {
value = y - offset.y;
break;
case 'r':
value = stageWidth - width;
value = stageWidth - (x - offset.x) - width;
break;
case 'b':
value = stageHeight - height;
value = stageHeight - (y - offset.y) - height;
break;
case 'h':
value = x + width / 2 - stageWidth / 2;
value = x + width / 2 - stageWidthOrigin / 2;
break;
case 'v':
value = y + height / 2 - stageHeight / 2;
value = y + height / 2 - stageHeightOrigin / 2;
break;
}
}
......
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