Commit efabca6d authored by 张九刚's avatar 张九刚

新增mode适配

parent f10828d2
{
"name": "psd-parse-web",
"version": "2.0.4",
"version": "2.0.5",
"main": "src/index.js",
"module": "dist/index.es.js",
"license": "MIT",
......
......@@ -5,7 +5,7 @@
*/
var { getTree } = require("./psd-tree");
var { walkNode, trimCustom } = require("./utils");
var { walkNode, trimCustom, getPageStyle } = require("./utils");
var path = require('path');
var Color = require('color');
var generateUUID = require('uuid/v4');
......@@ -30,7 +30,7 @@ const relativePosPrefixMap = {
async function compilePsdToJson(psdFile, options) {
const { assetsPath } = options;
const { mode, assetsPath } = options;
if (!assetsPath) {
console.log("没有指定assets目录");
}
......@@ -60,12 +60,12 @@ async function compilePsdToJson(psdFile, options) {
console.warn(`${page.name}不合法,请保持设计稿根目录为全部文件夹形式`);
} else {
const { x, y, width, height } = page;
const viewNode = {
let viewNode = {
name: folderName,
nodeType: 'Div',
properties: {
style: {
width, height, left: x, top: y, position: "absolute"
width, height, ...getPageStyle(mode, x, y)
},
attrs: {
......@@ -75,12 +75,15 @@ async function compilePsdToJson(psdFile, options) {
uuid: generateUUID(),
children: []
};
viewRoot.children.push(viewNode);
}
await walkNode(page, async (node, parent) => {
let { name } = node;
name = trimCustom(name);
const { x, y, width, height, origin: { layer, layer: { typeTool, solidColor } } } = node;
let properties = {
style: {
......@@ -93,7 +96,7 @@ async function compilePsdToJson(psdFile, options) {
};
let viewNode = {
name,
name:name.split('|')[0], //如果设置了适配的话,作为名字截取掉
properties,
uuid: generateUUID(),
};
......@@ -213,15 +216,9 @@ async function compilePsdToJson(psdFile, options) {
return data;
}
/**
* 单页解析
* @param {*} node
* @param {*} parent
* @param {*} folderName
*/
async function compilePage(node, parent, folderName, assetsPath) {
}
function savePng(png, output) {
return new Promise((resolve, reject) => {
......
......@@ -23,6 +23,75 @@ async function walkObject(obj, callback) {
}
}
}
const DesignHeight = 1624;
const SafetyHeight = 1206;
const HalfHeight = (DesignHeight - SafetyHeight) / 2;
// 不裁剪 ,顶部裁剪,上下裁剪,底部裁剪
const designCutModes = { 'none': 'none', 'top': 'top', 'center': 'center', 'bottom': 'bottom' };
/**
* 获取页面的样式
*/
function getPageStyle(mode, xx, yy) {
let result = {};
switch (mode) {
case designCutModes.top: //顶部裁剪就是底对齐
result = {
bottom: 0,
left: 0,
position: "absolute"
}
break;
case designCutModes.center:
result = {
transform: "translate(-50%, -50%)",
top: "50%",
left: "50%",
position: "fixed"
}
break;
case designCutModes.bottom:
result = {
top: 0,
left: 0,
position: "fixed"
}
break;
default:
result = {
top: xx,
left: yy,
position: "absolute"
}
break;
}
return result;
}
function getXYBySign(value, sign, xx, yy, mode) {
switch (mode) {
case designCutModes.none:
break;
case designCutModes.top:
break;
case designCutModes.center:
break;
case designCutModes.bottom:
break;
default:
break;
}
}
function getValueBySign() {
}
function trimCustom(str) {
var result;
result = str.replace(/(^\s+)|(\s+$)/g, "");
......@@ -32,5 +101,7 @@ function trimCustom(str) {
module.exports = {
walkNode,
walkObject,
trimCustom
trimCustom,
getXYBySign,
getPageStyle
}
\ No newline at end of file
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