Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
psd-parse
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
psd-parse
Commits
3a07ad83
Commit
3a07ad83
authored
Nov 29, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复矢量图的问题
parent
8417141f
Changes
19
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
145 additions
and
57 deletions
+145
-57
index.es.js
dist/index.es.js
+24
-7
index.es.js.map
dist/index.es.js.map
+1
-1
index.js
dist/index.js
+24
-7
index.js.map
dist/index.js.map
+1
-1
index.umd.js
dist/index.umd.js
+24
-7
index.umd.js.map
dist/index.umd.js.map
+1
-1
package.json
package.json
+1
-1
shapes.psd
samples/psd/shapes.psd
+0
-0
generator.cjs.js
samples/zeroing-demo/generator.cjs.js
+43
-23
generator.cjs.js.map
samples/zeroing-demo/generator.cjs.js.map
+1
-1
generator.js
samples/zeroing-demo/generator.js
+1
-1
179bc5df94be78d6590e65ec9be0311468d1816a.png
...575000073871/179bc5df94be78d6590e65ec9be0311468d1816a.png
+0
-0
51cbd8433e50201013e486d6c6710f7b6aca07df.png
...575000073871/51cbd8433e50201013e486d6c6710f7b6aca07df.png
+0
-0
5605a4bbc13e94da18858ea814d3e9258420f75c.png
...575000073871/5605a4bbc13e94da18858ea814d3e9258420f75c.png
+0
-0
f4483c3ddb98dedfb0fce62eb6d1c7a889505e3f.png
...575000073871/f4483c3ddb98dedfb0fce62eb6d1c7a889505e3f.png
+0
-0
51cbd8433e50201013e486d6c6710f7b6aca07df.png
...575000085190/51cbd8433e50201013e486d6c6710f7b6aca07df.png
+0
-0
5605a4bbc13e94da18858ea814d3e9258420f75c.png
...575000085190/5605a4bbc13e94da18858ea814d3e9258420f75c.png
+0
-0
f4483c3ddb98dedfb0fce62eb6d1c7a889505e3f.png
...575000085190/f4483c3ddb98dedfb0fce62eb6d1c7a889505e3f.png
+0
-0
zeroing.js
src/zeroing.js
+24
-7
No files found.
dist/index.es.js
View file @
3a07ad83
...
@@ -235,7 +235,7 @@ async function execute$1(psdFile, options) {
...
@@ -235,7 +235,7 @@ async function execute$1(psdFile, options) {
const
assets
=
[];
const
assets
=
[];
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
let
properties
=
{
let
properties
=
{
width
,
height
,
alpha
,
visible
,
width
,
height
,
alpha
,
visible
,
};
};
...
@@ -244,6 +244,7 @@ async function execute$1(psdFile, options) {
...
@@ -244,6 +244,7 @@ async function execute$1(psdFile, options) {
properties
,
properties
,
uuid
:
generateUUID
(),
uuid
:
generateUUID
(),
};
};
let
dealLater
=
true
;
if
(
x
!==
0
)
{
if
(
x
!==
0
)
{
properties
.
x
=
x
;
properties
.
x
=
x
;
}
}
...
@@ -253,9 +254,9 @@ async function execute$1(psdFile, options) {
...
@@ -253,9 +254,9 @@ async function execute$1(psdFile, options) {
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
const
fonts
=
fontInfo
.
fonts
();
//
const fonts = fontInfo.fonts();
const
styles
=
fontInfo
.
styles
();
//
const styles = fontInfo.styles();
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
//
const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
size
=
fontInfo
.
sizes
()[
0
];
properties
.
size
=
fontInfo
.
sizes
()[
0
];
...
@@ -265,13 +266,29 @@ async function execute$1(psdFile, options) {
...
@@ -265,13 +266,29 @@ async function execute$1(psdFile, options) {
fonts, styles, RunLengthArray,
fonts, styles, RunLengthArray,
};*/
};*/
viewNode
.
type
=
'label'
;
viewNode
.
type
=
'label'
;
dealLater
=
false
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
const
{
r
,
g
,
b
}
=
solidColor
();
const
{
r
,
g
,
b
}
=
solidColor
();
let
color
=
Color
({
r
,
g
,
b
});
let
color
=
Color
({
r
,
g
,
b
});
let
paths
=
layer
.
vectorMask
().
paths
;
if
(
paths
[
2
].
numPoints
===
4
){
let
isRect
=
true
;
for
(
let
i
=
3
;
i
<
paths
.
length
;
i
++
){
if
(
paths
[
i
].
recordType
!==
2
){
isRect
=
false
;
break
;
}
}
if
(
isRect
){
viewNode
.
type
=
'rect'
;
viewNode
.
type
=
'rect'
;
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
}
else
{
dealLater
=
false
;
}
}
}
if
(
dealLater
){
if
(
node
.
hasOwnProperty
(
'children'
))
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
viewNode
.
type
=
'node'
;
viewNode
.
type
=
'node'
;
}
else
{
}
else
{
...
...
dist/index.es.js.map
View file @
3a07ad83
{
"version"
:
3
,
"file"
:
"index.es.js"
,
"sources"
:
[
"../src/psd-tree.js"
,
"../src/utils.js"
,
"../src/egret.js"
,
"../src/zeroing.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = require('psd');
\n\n
export async function getTree(psdFilePath) {\n
\t
const psd = await PSD.open(psdFilePath);
\n\t
const root = {};
\n\t
walk(psd.tree(), root);
\n\n\t
return root;
\n
}
\n\n
function walk(psNode, dataNode) {\n
\t
const {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};
\n\t
const {left, top, width, height, name, layer: {opacity, visible}} = psNode;
\n\t
const x = left - pLeft;
\n\t
const y = top - pTop;
\n\n\t
Object.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});
\n\t
if (psNode.children() && psNode.children().length > 0){\n
\t\t
dataNode.children = [];
\n\t
}
\n\n\t
let children = psNode.children();
\n\t
for (let i = children.length - 1; i >= 0; i--) {\n
\t\t
const childPsNode = children[i];
\n\n\t\t
const childDataNode = {};
\n\t\t
dataNode.children.push(childDataNode);
\n\t\t
walk(childPsNode, childDataNode)
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
export async function walkNode(node, callback, includeSelf = false) {\n
\t
if (includeSelf) {\n
\t\t
await callback(node, null);
\n\t
}
\n\t
if (node.children && node.children.length > 0) {\n
\t\t
for (let childNode of node.children) {\n
\t\t\t
await callback(childNode, node);
\n\t\t\t
const result = await walkNode(childNode, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
export async function walkObject(obj, callback) {\n
\t
if(typeof obj ===
\"
object
\"
){\n
\t\t
for (let key of Object.keys(obj)) {\n
\t\t\t
const value = obj[key];
\n\t\t\t
await callback(key, value, obj);
\n\t\t\t
const result = await walkObject(value, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*
\n
* 导出exml
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import {walkNode, walkObject} from
\"
./utils
\"
;
\n
import xml from
\"
xml
\"
;
\n
import path from
\"
path
\"
;
\n
import fs from
\"
fs-extra
\"
;
\n\n
const elementTpls = {\n
\t
'e:Group': [],
\n\t
'e:Image': {_attr: {source: '
{
res}'}
}
,
\n\t
'e:Button': [
\n\t\t
{_attr: {label: '
{
1}',}
}
,
\n\t\t
{\n
\t\t\t
'e:skinName': [
\n\t\t\t\t
{\n
\t\t\t\t\t
'e:Skin': [
\n\t\t\t\t\t\t
{_attr: {states: 'up,down,disabled'}},
\n\t\t\t\t\t\t
{\n
\t\t\t\t\t\t\t
'e:Image': {_attr: {width: '100%', height: '100%', source: '
{
res}'}},\n\t\t\t\t\t\t
}
,
\n\t\t\t\t\t\t
{\n
\t\t\t\t\t\t\t
'e:Label': {_attr: {id: 'labelDisplay', horizontalCenter: '0', verticalCenter: '0'}},
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
]
\n\t\t\t\t
}
\n\t\t\t
]
\n\t\t
}
\n\t
]
\n
};
\n\n
export async function execute(psdFile, options) {\n
\t
const {skinFilePath, skinClassName, resPath, resGroupName} = options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
const exmlRoot = [
\n\t\t
{\n
\t\t\t
_attr: {\n
\t\t\t\t
class: skinClassName,
\n\t\t\t\t
width: tree.width,
\n\t\t\t\t
height: tree.height,
\n\t\t\t\t
'xmlns:e':
\"
http://ns.egret.com/eui
\"
,
\n\t\t\t\t
'xmlns:w':
\"
http://ns.egret.com/wing
\"
,
\n\t\t\t
},
\n\t\t
},
\n\t
];
\n\t
const exmlData = {\n
\t\t
'e:Skin': exmlRoot
\n\t
};
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {x, y, width, height, alpha, visible} = node;
\n\t\t
let attributes = {width, height, alpha, visible};
\n\t\t
if (x !== 0) {\n
\t\t\t
attributes.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
attributes.y = y;
\n\t\t
}
\n\t\t
let element;
\n\t\t
let tagName;
\n\t\t
let imageResName;
\n\t\t
let params;
\n\n\t\t
let hasChild = node.hasOwnProperty('children');
\n\t\t
if (hasChild) {\n
\t\t\t
tagName = 'e:Group';
\n\t\t
} else {\n
\t\t\t
const nameParams = node.name.split('|');
\n\t\t\t
const nodeName = nameParams[0];
\n\n\t\t\t
attributes.name = nodeName;
\n\t\t\t
imageResName = resGroupName + '_' + nodeName;
\n\t\t\t
const imageFilePath = path.join(resPath, resGroupName + '_p', nodeName + '.png');
\n\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t
await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t
if (nameParams.length === 1) {\n
\t\t\t\t
tagName = 'e:Image';
\n\t\t\t
} else {\n
\t\t\t\t
params = nameParams[1].split(',');
\n\t\t\t\t
tagName = 'e:' + params[0];
\n\t\t\t
}
\n\n\t\t\t
//element[tagName] = {_attr: attributes};
\n\t\t
}
\n\n\t\t
let elementTpl = elementTpls[tagName];
\n\t\t
let elementContent;
\n\t\t
if (elementTpl) {\n
\t\t\t
elementContent = JSON.parse(JSON.stringify(elementTpl));
\n\t\t
} else {\n
\t\t\t
elementContent =
{
}\n\t\t
}
\n\t\t
element = {\n
\t\t\t
[tagName]: elementContent,
\n\t\t
};
\n\n\t\t
let attr;
\n\t\t
if (Array.isArray(elementContent)) {\n
\t\t\t
attr = elementContent.find(item => item._attr);
\n\t\t\t
if (!attr) {\n
\t\t\t\t
attr = {_attr:
{
}};\n\t\t\t\telementContent.unshift(attr);\n\t\t\t}\n\t\t
}
else {\n
\t\t\t
attr = elementContent;
\n\t\t
}
\n\n\t\t
Object.assign(attr._attr, attributes);
\n\n\t\t
if (imageResName) {\n
\t\t\t
await walkObject(element, function (key, value, obj) {\n
\t\t\t\t
if (value === '
{
res
}
') {\n
\t\t\t\t\t
obj[key] = imageResName;
\n\t\t\t\t
} else if (typeof value === 'string') {\n
\t\t\t\t\t
const result = value.match(/
{
(\\d+)
}
/g);
\n\t\t\t\t\t
if(result){\n
\t\t\t\t\t\t
for(let item of result){\n
\t\t\t\t\t\t\t
const pi = parseInt(item.match(/
{
(\\d+)
}
/)[1]);
\n\t\t\t\t\t\t\t
value = value.replace(item, params[pi])
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t\t
obj[key] = value;
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t
})
\n\t\t
}
\n\n\t\t
if (hasChild) {\n
\t\t\t
node.exmlNode = elementContent;
\n\t\t
}
\n\n\t\t
const exmlNode = parent.exmlNode || exmlRoot;
\n\t\t
exmlNode.push(element);
\n\t
});
\n\n\t
let exmlStr = xml(exmlData, {declaration: true, indent: true});
\n\t
await fs.ensureDir(path.dirname(skinFilePath));
\n\t
await fs.writeFile(skinFilePath, exmlStr);
\n\n
}"
,
"/**
\n
* Created by rockyl on 2019-09-26.
\n
*
\n
* 导出zeroing的视图
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import
{
walkNode
}
from
\"
./utils
\"
;
\n
import path from 'path'
\n
import Color from 'color'
\n
import generateUUID from 'uuid/v4'
\n
import fs from
\"
fs-extra
\"
;
\n
import hash from 'object-hash';
\n\n
export async function execute(psdFile, options) {\n
\t
const
{
\n\t\timagesPath,\n\t
}
= options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {name, x, y, width, height, alpha, visible, origin: {layer: {typeTool, solidColor}}} = node;
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
let viewNode = {\n
\t\t\t
name,
\n\t\t\t
properties,
\n\t\t\t
uuid: generateUUID(),
\n\t\t
};
\n\t\t
if (x !== 0) {\n
\t\t\t
properties.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
const fonts = fontInfo.fonts();
\n\t\t\t
const styles = fontInfo.styles();
\n\t\t\t
const
{
RunLengthArray
}
= fontInfo.engineData.EngineDict.StyleRun;
\n\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
properties.size = fontInfo.sizes()[0];
\n\t\t\t
let [r, g, b, a] = fontInfo.colors()[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
/*properties.textflow = {\n
\t\t\t\t
fonts, styles, RunLengthArray,
\n\t\t\t
};*/
\n\t\t\t
viewNode.type = 'label';
\n\t\t
} else if (solidColor) {\n
\t\t\t
const {r, g, b} = solidColor();
\n\t\t\t
let color = Color({r, g, b});
\n\n\t\t\t
viewNode.type = 'rect';
\n\t\t\t
properties.fillColor = '#' + color.rgbNumber().toString(16);
\n\t\t
} else {\n
\t\t\t
if (node.hasOwnProperty('children')) {\n
\t\t\t\t
viewNode.type = 'node';
\n\t\t\t
} else {\n
\t\t\t\t
viewNode.type = 'image';
\n\n\t\t\t\t
const uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
const imageFilePath = path.join(imagesPath, uuid + ext);
\n\t\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t\t
let png = node.origin.toPng();
\n\t\t\t\t
let buffer = await savePng(png, imageFilePath).catch(e=>{});
\n\t\t\t\t
//await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t\t
if(buffer){\n
\t\t\t\t\t
properties.source = 'asset://' + uuid;
\n\n\t\t\t\t\t
const hashFileName = hash(buffer);
\n\t\t\t\t\t
const hashFilePath = path.join(imagesPath, hashFileName + ext);
\n\t\t\t\t\t
await fs.rename(imageFilePath, hashFilePath);
\n\n\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t
hash: hashFileName,
\n\t\t\t\t\t
});
\n\t\t\t\t
}
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
let viewParent = parent.view || viewRoot;
\n\t\t
if (!viewParent.hasOwnProperty('children')) {\n
\t\t\t
viewParent.children = [];
\n\t\t
}
\n\t\t
viewParent.children.push(viewNode);
\n\n\t\t
node.view = viewNode;
\n\t
});
\n\n\t
return {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
}
\n
}
\n\n
function savePng(png, output) {\n
\t
return new Promise((resolve, reject) => {\n
\t\t
let buffer, buffers = [];
\n\t\t
png.pack()
\n\t\t\t
.on('error', reject)
\n\t\t\t
.on('data', (data) => buffers.push(data))
\n\t\t\t
.on('end', () => {\n
\t\t\t\t
buffer = Buffer.concat(buffers)
\n\t\t\t
})
\n\t\t\t
.pipe(fs.createWriteStream(output))
\n\t\t\t
.on('finish', () =>
{
\n\t\t\t\tresolve(buffer);\n\t\t\t});\n\t});\n}\n"],"names":["execute"],"mappings":";;;;;;;AAAA;;;;AAIA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;;AAE3B,AAAO,eAAe,OAAO,CAAC,WAAW,EAAE;CAC1C,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;CACxC,MAAM,IAAI,GAAG,EAAE,CAAC;CAChB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;;CAEvB,OAAO,IAAI,CAAC;CACZ;;AAED,SAAS,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE;CAC/B,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;CAC9D,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,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,CAAC,OAAO,EAAE,MAAM,KAAK;EACvC,IAAI,MAAM,EAAE,OAAO,GAAG,EAAE,CAAC;EACzB,GAAG,CAAC,IAAI,EAAE;IACR,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxC,EAAE,CAAC,KAAK,EAAE,MAAM;IAChB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAC;IAC/B,CAAC;IACD,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAClC,EAAE,CAAC,QAAQ,EAAE,MAAM;IACnB,OAAO,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC,CAAC;EACJ,CAAC,CAAC;CACH;;;;"
}
{
"version"
:
3
,
"file"
:
"index.es.js"
,
"sources"
:
[
"../src/psd-tree.js"
,
"../src/utils.js"
,
"../src/egret.js"
,
"../src/zeroing.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = require('psd');
\n\n
export async function getTree(psdFilePath) {\n
\t
const psd = await PSD.open(psdFilePath);
\n\t
const root = {};
\n\t
walk(psd.tree(), root);
\n\n\t
return root;
\n
}
\n\n
function walk(psNode, dataNode) {\n
\t
const {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};
\n\t
const {left, top, width, height, name, layer: {opacity, visible}} = psNode;
\n\t
const x = left - pLeft;
\n\t
const y = top - pTop;
\n\n\t
Object.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});
\n\t
if (psNode.children() && psNode.children().length > 0){\n
\t\t
dataNode.children = [];
\n\t
}
\n\n\t
let children = psNode.children();
\n\t
for (let i = children.length - 1; i >= 0; i--) {\n
\t\t
const childPsNode = children[i];
\n\n\t\t
const childDataNode = {};
\n\t\t
dataNode.children.push(childDataNode);
\n\t\t
walk(childPsNode, childDataNode)
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
export async function walkNode(node, callback, includeSelf = false) {\n
\t
if (includeSelf) {\n
\t\t
await callback(node, null);
\n\t
}
\n\t
if (node.children && node.children.length > 0) {\n
\t\t
for (let childNode of node.children) {\n
\t\t\t
await callback(childNode, node);
\n\t\t\t
const result = await walkNode(childNode, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
export async function walkObject(obj, callback) {\n
\t
if(typeof obj ===
\"
object
\"
){\n
\t\t
for (let key of Object.keys(obj)) {\n
\t\t\t
const value = obj[key];
\n\t\t\t
await callback(key, value, obj);
\n\t\t\t
const result = await walkObject(value, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*
\n
* 导出exml
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import {walkNode, walkObject} from
\"
./utils
\"
;
\n
import xml from
\"
xml
\"
;
\n
import path from
\"
path
\"
;
\n
import fs from
\"
fs-extra
\"
;
\n\n
const elementTpls = {\n
\t
'e:Group': [],
\n\t
'e:Image': {_attr: {source: '
{
res}'}
}
,
\n\t
'e:Button': [
\n\t\t
{_attr: {label: '
{
1}',}
}
,
\n\t\t
{\n
\t\t\t
'e:skinName': [
\n\t\t\t\t
{\n
\t\t\t\t\t
'e:Skin': [
\n\t\t\t\t\t\t
{_attr: {states: 'up,down,disabled'}},
\n\t\t\t\t\t\t
{\n
\t\t\t\t\t\t\t
'e:Image': {_attr: {width: '100%', height: '100%', source: '
{
res}'}},\n\t\t\t\t\t\t
}
,
\n\t\t\t\t\t\t
{\n
\t\t\t\t\t\t\t
'e:Label': {_attr: {id: 'labelDisplay', horizontalCenter: '0', verticalCenter: '0'}},
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
]
\n\t\t\t\t
}
\n\t\t\t
]
\n\t\t
}
\n\t
]
\n
};
\n\n
export async function execute(psdFile, options) {\n
\t
const {skinFilePath, skinClassName, resPath, resGroupName} = options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
const exmlRoot = [
\n\t\t
{\n
\t\t\t
_attr: {\n
\t\t\t\t
class: skinClassName,
\n\t\t\t\t
width: tree.width,
\n\t\t\t\t
height: tree.height,
\n\t\t\t\t
'xmlns:e':
\"
http://ns.egret.com/eui
\"
,
\n\t\t\t\t
'xmlns:w':
\"
http://ns.egret.com/wing
\"
,
\n\t\t\t
},
\n\t\t
},
\n\t
];
\n\t
const exmlData = {\n
\t\t
'e:Skin': exmlRoot
\n\t
};
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {x, y, width, height, alpha, visible} = node;
\n\t\t
let attributes = {width, height, alpha, visible};
\n\t\t
if (x !== 0) {\n
\t\t\t
attributes.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
attributes.y = y;
\n\t\t
}
\n\t\t
let element;
\n\t\t
let tagName;
\n\t\t
let imageResName;
\n\t\t
let params;
\n\n\t\t
let hasChild = node.hasOwnProperty('children');
\n\t\t
if (hasChild) {\n
\t\t\t
tagName = 'e:Group';
\n\t\t
} else {\n
\t\t\t
const nameParams = node.name.split('|');
\n\t\t\t
const nodeName = nameParams[0];
\n\n\t\t\t
attributes.name = nodeName;
\n\t\t\t
imageResName = resGroupName + '_' + nodeName;
\n\t\t\t
const imageFilePath = path.join(resPath, resGroupName + '_p', nodeName + '.png');
\n\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t
await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t
if (nameParams.length === 1) {\n
\t\t\t\t
tagName = 'e:Image';
\n\t\t\t
} else {\n
\t\t\t\t
params = nameParams[1].split(',');
\n\t\t\t\t
tagName = 'e:' + params[0];
\n\t\t\t
}
\n\n\t\t\t
//element[tagName] = {_attr: attributes};
\n\t\t
}
\n\n\t\t
let elementTpl = elementTpls[tagName];
\n\t\t
let elementContent;
\n\t\t
if (elementTpl) {\n
\t\t\t
elementContent = JSON.parse(JSON.stringify(elementTpl));
\n\t\t
} else {\n
\t\t\t
elementContent =
{
}\n\t\t
}
\n\t\t
element = {\n
\t\t\t
[tagName]: elementContent,
\n\t\t
};
\n\n\t\t
let attr;
\n\t\t
if (Array.isArray(elementContent)) {\n
\t\t\t
attr = elementContent.find(item => item._attr);
\n\t\t\t
if (!attr) {\n
\t\t\t\t
attr = {_attr:
{
}};\n\t\t\t\telementContent.unshift(attr);\n\t\t\t}\n\t\t
}
else {\n
\t\t\t
attr = elementContent;
\n\t\t
}
\n\n\t\t
Object.assign(attr._attr, attributes);
\n\n\t\t
if (imageResName) {\n
\t\t\t
await walkObject(element, function (key, value, obj) {\n
\t\t\t\t
if (value === '
{
res
}
') {\n
\t\t\t\t\t
obj[key] = imageResName;
\n\t\t\t\t
} else if (typeof value === 'string') {\n
\t\t\t\t\t
const result = value.match(/
{
(\\d+)
}
/g);
\n\t\t\t\t\t
if(result){\n
\t\t\t\t\t\t
for(let item of result){\n
\t\t\t\t\t\t\t
const pi = parseInt(item.match(/
{
(\\d+)
}
/)[1]);
\n\t\t\t\t\t\t\t
value = value.replace(item, params[pi])
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t\t
obj[key] = value;
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t
})
\n\t\t
}
\n\n\t\t
if (hasChild) {\n
\t\t\t
node.exmlNode = elementContent;
\n\t\t
}
\n\n\t\t
const exmlNode = parent.exmlNode || exmlRoot;
\n\t\t
exmlNode.push(element);
\n\t
});
\n\n\t
let exmlStr = xml(exmlData, {declaration: true, indent: true});
\n\t
await fs.ensureDir(path.dirname(skinFilePath));
\n\t
await fs.writeFile(skinFilePath, exmlStr);
\n\n
}"
,
"/**
\n
* Created by rockyl on 2019-09-26.
\n
*
\n
* 导出zeroing的视图
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import
{
walkNode
}
from
\"
./utils
\"
;
\n
import path from 'path'
\n
import Color from 'color'
\n
import generateUUID from 'uuid/v4'
\n
import fs from
\"
fs-extra
\"
;
\n
import hash from 'object-hash';
\n\n
export async function execute(psdFile, options) {\n
\t
const
{
\n\t\timagesPath,\n\t
}
= options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
let viewNode = {\n
\t\t\t
name,
\n\t\t\t
properties,
\n\t\t\t
uuid: generateUUID(),
\n\t\t
};
\n\t\t
let dealLater = true;
\n\t\t
if (x !== 0) {\n
\t\t\t
properties.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
//const fonts = fontInfo.fonts();
\n\t\t\t
//const styles = fontInfo.styles();
\n\t\t\t
//const
{
RunLengthArray
}
= fontInfo.engineData.EngineDict.StyleRun;
\n\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
properties.size = fontInfo.sizes()[0];
\n\t\t\t
let [r, g, b, a] = fontInfo.colors()[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
/*properties.textflow = {\n
\t\t\t\t
fonts, styles, RunLengthArray,
\n\t\t\t
};*/
\n\t\t\t
viewNode.type = 'label';
\n\t\t\t
dealLater = false;
\n\t\t
} else if (solidColor) {\n
\t\t\t
const {r, g, b} = solidColor();
\n\t\t\t
let color = Color({r, g, b});
\n\n\t\t\t
let paths = layer.vectorMask().paths;
\n\t\t\t
if(paths[2].numPoints === 4){\n
\t\t\t\t
let isRect = true;
\n\t\t\t\t
for(let i = 3; i < paths.length; i++){\n
\t\t\t\t\t
if(paths[i].recordType !== 2){\n
\t\t\t\t\t\t
isRect = false;
\n\t\t\t\t\t\t
break;
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t\t
if(isRect){\n
\t\t\t\t\t
viewNode.type = 'rect';
\n\t\t\t\t\t
properties.fillColor = '#' + color.rgbNumber().toString(16);
\n\t\t\t\t\t
dealLater = false;
\n\t\t\t\t
}
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
if(dealLater){\n
\t\t\t
if (node.hasOwnProperty('children')) {\n
\t\t\t\t
viewNode.type = 'node';
\n\t\t\t
} else {\n
\t\t\t\t
viewNode.type = 'image';
\n\n\t\t\t\t
const uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
const imageFilePath = path.join(imagesPath, uuid + ext);
\n\t\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t\t
let png = node.origin.toPng();
\n\t\t\t\t
let buffer = await savePng(png, imageFilePath).catch(e=>{});
\n\t\t\t\t
//await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t\t
if(buffer){\n
\t\t\t\t\t
properties.source = 'asset://' + uuid;
\n\n\t\t\t\t\t
const hashFileName = hash(buffer);
\n\t\t\t\t\t
const hashFilePath = path.join(imagesPath, hashFileName + ext);
\n\t\t\t\t\t
await fs.rename(imageFilePath, hashFilePath);
\n\n\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t
hash: hashFileName,
\n\t\t\t\t\t
});
\n\t\t\t\t
}
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
let viewParent = parent.view || viewRoot;
\n\t\t
if (!viewParent.hasOwnProperty('children')) {\n
\t\t\t
viewParent.children = [];
\n\t\t
}
\n\t\t
viewParent.children.push(viewNode);
\n\n\t\t
node.view = viewNode;
\n\t
});
\n\n\t
return {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
}
\n
}
\n\n
function savePng(png, output) {\n
\t
return new Promise((resolve, reject) => {\n
\t\t
let buffer, buffers = [];
\n\t\t
png.pack()
\n\t\t\t
.on('error', reject)
\n\t\t\t
.on('data', (data) => buffers.push(data))
\n\t\t\t
.on('end', () => {\n
\t\t\t\t
buffer = Buffer.concat(buffers)
\n\t\t\t
})
\n\t\t\t
.pipe(fs.createWriteStream(output))
\n\t\t\t
.on('finish', () =>
{
\n\t\t\t\tresolve(buffer);\n\t\t\t});\n\t});\n}\n"],"names":["execute"],"mappings":";;;;;;;AAAA;;;;AAIA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;;AAE3B,AAAO,eAAe,OAAO,CAAC,WAAW,EAAE;CAC1C,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;CACxC,MAAM,IAAI,GAAG,EAAE,CAAC;CAChB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;;CAEvB,OAAO,IAAI,CAAC;CACZ;;AAED,SAAS,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE;CAC/B,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;CAC9D,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC;CAC3E,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;CACvB,MA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AC,IAAI,CAAC,QAAQ,CAAC,CAAC;;EAEnC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;EACrB,CAAC,CAAC;;CAEH,OAAO;EACN,IAAI,EAAE,QAAQ;EACd,MAAM;EACN;CACD;;AAED,SAAS,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE;CAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;EACvC,IAAI,MAAM,EAAE,OAAO,GAAG,EAAE,CAAC;EACzB,GAAG,CAAC,IAAI,EAAE;IACR,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxC,EAAE,CAAC,KAAK,EAAE,MAAM;IAChB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAC;IAC/B,CAAC;IACD,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAClC,EAAE,CAAC,QAAQ,EAAE,MAAM;IACnB,OAAO,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC,CAAC;EACJ,CAAC,CAAC;CACH;;;;"
}
\ No newline at end of file
\ No newline at end of file
dist/index.js
View file @
3a07ad83
...
@@ -241,7 +241,7 @@ async function execute$1(psdFile, options) {
...
@@ -241,7 +241,7 @@ async function execute$1(psdFile, options) {
const
assets
=
[];
const
assets
=
[];
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
let
properties
=
{
let
properties
=
{
width
,
height
,
alpha
,
visible
,
width
,
height
,
alpha
,
visible
,
};
};
...
@@ -250,6 +250,7 @@ async function execute$1(psdFile, options) {
...
@@ -250,6 +250,7 @@ async function execute$1(psdFile, options) {
properties
,
properties
,
uuid
:
generateUUID
(),
uuid
:
generateUUID
(),
};
};
let
dealLater
=
true
;
if
(
x
!==
0
)
{
if
(
x
!==
0
)
{
properties
.
x
=
x
;
properties
.
x
=
x
;
}
}
...
@@ -259,9 +260,9 @@ async function execute$1(psdFile, options) {
...
@@ -259,9 +260,9 @@ async function execute$1(psdFile, options) {
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
const
fonts
=
fontInfo
.
fonts
();
//
const fonts = fontInfo.fonts();
const
styles
=
fontInfo
.
styles
();
//
const styles = fontInfo.styles();
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
//
const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
size
=
fontInfo
.
sizes
()[
0
];
properties
.
size
=
fontInfo
.
sizes
()[
0
];
...
@@ -271,13 +272,29 @@ async function execute$1(psdFile, options) {
...
@@ -271,13 +272,29 @@ async function execute$1(psdFile, options) {
fonts, styles, RunLengthArray,
fonts, styles, RunLengthArray,
};*/
};*/
viewNode
.
type
=
'label'
;
viewNode
.
type
=
'label'
;
dealLater
=
false
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
const
{
r
,
g
,
b
}
=
solidColor
();
const
{
r
,
g
,
b
}
=
solidColor
();
let
color
=
Color
({
r
,
g
,
b
});
let
color
=
Color
({
r
,
g
,
b
});
let
paths
=
layer
.
vectorMask
().
paths
;
if
(
paths
[
2
].
numPoints
===
4
){
let
isRect
=
true
;
for
(
let
i
=
3
;
i
<
paths
.
length
;
i
++
){
if
(
paths
[
i
].
recordType
!==
2
){
isRect
=
false
;
break
;
}
}
if
(
isRect
){
viewNode
.
type
=
'rect'
;
viewNode
.
type
=
'rect'
;
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
}
else
{
dealLater
=
false
;
}
}
}
if
(
dealLater
){
if
(
node
.
hasOwnProperty
(
'children'
))
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
viewNode
.
type
=
'node'
;
viewNode
.
type
=
'node'
;
}
else
{
}
else
{
...
...
dist/index.js.map
View file @
3a07ad83
{
"version"
:
3
,
"file"
:
"index.js"
,
"sources"
:
[
"../src/psd-tree.js"
,
"../src/utils.js"
,
"../src/egret.js"
,
"../src/zeroing.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = require('psd');
\n\n
export async function getTree(psdFilePath) {\n
\t
const psd = await PSD.open(psdFilePath);
\n\t
const root = {};
\n\t
walk(psd.tree(), root);
\n\n\t
return root;
\n
}
\n\n
function walk(psNode, dataNode) {\n
\t
const {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};
\n\t
const {left, top, width, height, name, layer: {opacity, visible}} = psNode;
\n\t
const x = left - pLeft;
\n\t
const y = top - pTop;
\n\n\t
Object.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});
\n\t
if (psNode.children() && psNode.children().length > 0){\n
\t\t
dataNode.children = [];
\n\t
}
\n\n\t
let children = psNode.children();
\n\t
for (let i = children.length - 1; i >= 0; i--) {\n
\t\t
const childPsNode = children[i];
\n\n\t\t
const childDataNode = {};
\n\t\t
dataNode.children.push(childDataNode);
\n\t\t
walk(childPsNode, childDataNode)
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
export async function walkNode(node, callback, includeSelf = false) {\n
\t
if (includeSelf) {\n
\t\t
await callback(node, null);
\n\t
}
\n\t
if (node.children && node.children.length > 0) {\n
\t\t
for (let childNode of node.children) {\n
\t\t\t
await callback(childNode, node);
\n\t\t\t
const result = await walkNode(childNode, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
export async function walkObject(obj, callback) {\n
\t
if(typeof obj ===
\"
object
\"
){\n
\t\t
for (let key of Object.keys(obj)) {\n
\t\t\t
const value = obj[key];
\n\t\t\t
await callback(key, value, obj);
\n\t\t\t
const result = await walkObject(value, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*
\n
* 导出exml
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import {walkNode, walkObject} from
\"
./utils
\"
;
\n
import xml from
\"
xml
\"
;
\n
import path from
\"
path
\"
;
\n
import fs from
\"
fs-extra
\"
;
\n\n
const elementTpls = {\n
\t
'e:Group': [],
\n\t
'e:Image': {_attr: {source: '
{
res}'}
}
,
\n\t
'e:Button': [
\n\t\t
{_attr: {label: '
{
1}',}
}
,
\n\t\t
{\n
\t\t\t
'e:skinName': [
\n\t\t\t\t
{\n
\t\t\t\t\t
'e:Skin': [
\n\t\t\t\t\t\t
{_attr: {states: 'up,down,disabled'}},
\n\t\t\t\t\t\t
{\n
\t\t\t\t\t\t\t
'e:Image': {_attr: {width: '100%', height: '100%', source: '
{
res}'}},\n\t\t\t\t\t\t
}
,
\n\t\t\t\t\t\t
{\n
\t\t\t\t\t\t\t
'e:Label': {_attr: {id: 'labelDisplay', horizontalCenter: '0', verticalCenter: '0'}},
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
]
\n\t\t\t\t
}
\n\t\t\t
]
\n\t\t
}
\n\t
]
\n
};
\n\n
export async function execute(psdFile, options) {\n
\t
const {skinFilePath, skinClassName, resPath, resGroupName} = options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
const exmlRoot = [
\n\t\t
{\n
\t\t\t
_attr: {\n
\t\t\t\t
class: skinClassName,
\n\t\t\t\t
width: tree.width,
\n\t\t\t\t
height: tree.height,
\n\t\t\t\t
'xmlns:e':
\"
http://ns.egret.com/eui
\"
,
\n\t\t\t\t
'xmlns:w':
\"
http://ns.egret.com/wing
\"
,
\n\t\t\t
},
\n\t\t
},
\n\t
];
\n\t
const exmlData = {\n
\t\t
'e:Skin': exmlRoot
\n\t
};
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {x, y, width, height, alpha, visible} = node;
\n\t\t
let attributes = {width, height, alpha, visible};
\n\t\t
if (x !== 0) {\n
\t\t\t
attributes.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
attributes.y = y;
\n\t\t
}
\n\t\t
let element;
\n\t\t
let tagName;
\n\t\t
let imageResName;
\n\t\t
let params;
\n\n\t\t
let hasChild = node.hasOwnProperty('children');
\n\t\t
if (hasChild) {\n
\t\t\t
tagName = 'e:Group';
\n\t\t
} else {\n
\t\t\t
const nameParams = node.name.split('|');
\n\t\t\t
const nodeName = nameParams[0];
\n\n\t\t\t
attributes.name = nodeName;
\n\t\t\t
imageResName = resGroupName + '_' + nodeName;
\n\t\t\t
const imageFilePath = path.join(resPath, resGroupName + '_p', nodeName + '.png');
\n\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t
await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t
if (nameParams.length === 1) {\n
\t\t\t\t
tagName = 'e:Image';
\n\t\t\t
} else {\n
\t\t\t\t
params = nameParams[1].split(',');
\n\t\t\t\t
tagName = 'e:' + params[0];
\n\t\t\t
}
\n\n\t\t\t
//element[tagName] = {_attr: attributes};
\n\t\t
}
\n\n\t\t
let elementTpl = elementTpls[tagName];
\n\t\t
let elementContent;
\n\t\t
if (elementTpl) {\n
\t\t\t
elementContent = JSON.parse(JSON.stringify(elementTpl));
\n\t\t
} else {\n
\t\t\t
elementContent =
{
}\n\t\t
}
\n\t\t
element = {\n
\t\t\t
[tagName]: elementContent,
\n\t\t
};
\n\n\t\t
let attr;
\n\t\t
if (Array.isArray(elementContent)) {\n
\t\t\t
attr = elementContent.find(item => item._attr);
\n\t\t\t
if (!attr) {\n
\t\t\t\t
attr = {_attr:
{
}};\n\t\t\t\telementContent.unshift(attr);\n\t\t\t}\n\t\t
}
else {\n
\t\t\t
attr = elementContent;
\n\t\t
}
\n\n\t\t
Object.assign(attr._attr, attributes);
\n\n\t\t
if (imageResName) {\n
\t\t\t
await walkObject(element, function (key, value, obj) {\n
\t\t\t\t
if (value === '
{
res
}
') {\n
\t\t\t\t\t
obj[key] = imageResName;
\n\t\t\t\t
} else if (typeof value === 'string') {\n
\t\t\t\t\t
const result = value.match(/
{
(\\d+)
}
/g);
\n\t\t\t\t\t
if(result){\n
\t\t\t\t\t\t
for(let item of result){\n
\t\t\t\t\t\t\t
const pi = parseInt(item.match(/
{
(\\d+)
}
/)[1]);
\n\t\t\t\t\t\t\t
value = value.replace(item, params[pi])
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t\t
obj[key] = value;
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t
})
\n\t\t
}
\n\n\t\t
if (hasChild) {\n
\t\t\t
node.exmlNode = elementContent;
\n\t\t
}
\n\n\t\t
const exmlNode = parent.exmlNode || exmlRoot;
\n\t\t
exmlNode.push(element);
\n\t
});
\n\n\t
let exmlStr = xml(exmlData, {declaration: true, indent: true});
\n\t
await fs.ensureDir(path.dirname(skinFilePath));
\n\t
await fs.writeFile(skinFilePath, exmlStr);
\n\n
}"
,
"/**
\n
* Created by rockyl on 2019-09-26.
\n
*
\n
* 导出zeroing的视图
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import
{
walkNode
}
from
\"
./utils
\"
;
\n
import path from 'path'
\n
import Color from 'color'
\n
import generateUUID from 'uuid/v4'
\n
import fs from
\"
fs-extra
\"
;
\n
import hash from 'object-hash';
\n\n
export async function execute(psdFile, options) {\n
\t
const
{
\n\t\timagesPath,\n\t
}
= options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {name, x, y, width, height, alpha, visible, origin: {layer: {typeTool, solidColor}}} = node;
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
let viewNode = {\n
\t\t\t
name,
\n\t\t\t
properties,
\n\t\t\t
uuid: generateUUID(),
\n\t\t
};
\n\t\t
if (x !== 0) {\n
\t\t\t
properties.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
const fonts = fontInfo.fonts();
\n\t\t\t
const styles = fontInfo.styles();
\n\t\t\t
const
{
RunLengthArray
}
= fontInfo.engineData.EngineDict.StyleRun;
\n\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
properties.size = fontInfo.sizes()[0];
\n\t\t\t
let [r, g, b, a] = fontInfo.colors()[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
/*properties.textflow = {\n
\t\t\t\t
fonts, styles, RunLengthArray,
\n\t\t\t
};*/
\n\t\t\t
viewNode.type = 'label';
\n\t\t
} else if (solidColor) {\n
\t\t\t
const {r, g, b} = solidColor();
\n\t\t\t
let color = Color({r, g, b});
\n\n\t\t\t
viewNode.type = 'rect';
\n\t\t\t
properties.fillColor = '#' + color.rgbNumber().toString(16);
\n\t\t
} else {\n
\t\t\t
if (node.hasOwnProperty('children')) {\n
\t\t\t\t
viewNode.type = 'node';
\n\t\t\t
} else {\n
\t\t\t\t
viewNode.type = 'image';
\n\n\t\t\t\t
const uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
const imageFilePath = path.join(imagesPath, uuid + ext);
\n\t\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t\t
let png = node.origin.toPng();
\n\t\t\t\t
let buffer = await savePng(png, imageFilePath).catch(e=>{});
\n\t\t\t\t
//await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t\t
if(buffer){\n
\t\t\t\t\t
properties.source = 'asset://' + uuid;
\n\n\t\t\t\t\t
const hashFileName = hash(buffer);
\n\t\t\t\t\t
const hashFilePath = path.join(imagesPath, hashFileName + ext);
\n\t\t\t\t\t
await fs.rename(imageFilePath, hashFilePath);
\n\n\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t
hash: hashFileName,
\n\t\t\t\t\t
});
\n\t\t\t\t
}
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
let viewParent = parent.view || viewRoot;
\n\t\t
if (!viewParent.hasOwnProperty('children')) {\n
\t\t\t
viewParent.children = [];
\n\t\t
}
\n\t\t
viewParent.children.push(viewNode);
\n\n\t\t
node.view = viewNode;
\n\t
});
\n\n\t
return {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
}
\n
}
\n\n
function savePng(png, output) {\n
\t
return new Promise((resolve, reject) => {\n
\t\t
let buffer, buffers = [];
\n\t\t
png.pack()
\n\t\t\t
.on('error', reject)
\n\t\t\t
.on('data', (data) => buffers.push(data))
\n\t\t\t
.on('end', () => {\n
\t\t\t\t
buffer = Buffer.concat(buffers)
\n\t\t\t
})
\n\t\t\t
.pipe(fs.createWriteStream(output))
\n\t\t\t
.on('finish', () =>
{
\n\t\t\t\tresolve(buffer);\n\t\t\t});\n\t});\n}\n"],"names":["execute"],"mappings":";;;;;;;;;;;;;AAAA;;;;AAIA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;;AAE3B,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IAAI;MACJ,GAAG;MACH,IAAI;MACJ,IAAI,EAAE,YAAY;MAClB,CAAC,CAAC;KACH;IACD;GACD;;EAED,IAAI,UAAU,GAAG,MAAM,CAAC,IAAI,IAAI,QAAQ,CAAC;EACzC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;GAC3C,UAAU,CAAC,QAAQ,GAAG,EAAE,CAAC;GACzB;EACD,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;;EAEnC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;EACrB,CAAC,CAAC;;CAEH,OAAO;EACN,IAAI,EAAE,QAAQ;EACd,MAAM;EACN;CACD;;AAED,SAAS,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE;CAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;EACvC,IAAI,MAAM,EAAE,OAAO,GAAG,EAAE,CAAC;EACzB,GAAG,CAAC,IAAI,EAAE;IACR,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxC,EAAE,CAAC,KAAK,EAAE,MAAM;IAChB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAC;IAC/B,CAAC;IACD,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAClC,EAAE,CAAC,QAAQ,EAAE,MAAM;IACnB,OAAO,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC,CAAC;EACJ,CAAC,CAAC;CACH;;;;;;"
}
{
"version"
:
3
,
"file"
:
"index.js"
,
"sources"
:
[
"../src/psd-tree.js"
,
"../src/utils.js"
,
"../src/egret.js"
,
"../src/zeroing.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = require('psd');
\n\n
export async function getTree(psdFilePath) {\n
\t
const psd = await PSD.open(psdFilePath);
\n\t
const root = {};
\n\t
walk(psd.tree(), root);
\n\n\t
return root;
\n
}
\n\n
function walk(psNode, dataNode) {\n
\t
const {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};
\n\t
const {left, top, width, height, name, layer: {opacity, visible}} = psNode;
\n\t
const x = left - pLeft;
\n\t
const y = top - pTop;
\n\n\t
Object.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});
\n\t
if (psNode.children() && psNode.children().length > 0){\n
\t\t
dataNode.children = [];
\n\t
}
\n\n\t
let children = psNode.children();
\n\t
for (let i = children.length - 1; i >= 0; i--) {\n
\t\t
const childPsNode = children[i];
\n\n\t\t
const childDataNode = {};
\n\t\t
dataNode.children.push(childDataNode);
\n\t\t
walk(childPsNode, childDataNode)
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
export async function walkNode(node, callback, includeSelf = false) {\n
\t
if (includeSelf) {\n
\t\t
await callback(node, null);
\n\t
}
\n\t
if (node.children && node.children.length > 0) {\n
\t\t
for (let childNode of node.children) {\n
\t\t\t
await callback(childNode, node);
\n\t\t\t
const result = await walkNode(childNode, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
export async function walkObject(obj, callback) {\n
\t
if(typeof obj ===
\"
object
\"
){\n
\t\t
for (let key of Object.keys(obj)) {\n
\t\t\t
const value = obj[key];
\n\t\t\t
await callback(key, value, obj);
\n\t\t\t
const result = await walkObject(value, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*
\n
* 导出exml
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import {walkNode, walkObject} from
\"
./utils
\"
;
\n
import xml from
\"
xml
\"
;
\n
import path from
\"
path
\"
;
\n
import fs from
\"
fs-extra
\"
;
\n\n
const elementTpls = {\n
\t
'e:Group': [],
\n\t
'e:Image': {_attr: {source: '
{
res}'}
}
,
\n\t
'e:Button': [
\n\t\t
{_attr: {label: '
{
1}',}
}
,
\n\t\t
{\n
\t\t\t
'e:skinName': [
\n\t\t\t\t
{\n
\t\t\t\t\t
'e:Skin': [
\n\t\t\t\t\t\t
{_attr: {states: 'up,down,disabled'}},
\n\t\t\t\t\t\t
{\n
\t\t\t\t\t\t\t
'e:Image': {_attr: {width: '100%', height: '100%', source: '
{
res}'}},\n\t\t\t\t\t\t
}
,
\n\t\t\t\t\t\t
{\n
\t\t\t\t\t\t\t
'e:Label': {_attr: {id: 'labelDisplay', horizontalCenter: '0', verticalCenter: '0'}},
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
]
\n\t\t\t\t
}
\n\t\t\t
]
\n\t\t
}
\n\t
]
\n
};
\n\n
export async function execute(psdFile, options) {\n
\t
const {skinFilePath, skinClassName, resPath, resGroupName} = options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
const exmlRoot = [
\n\t\t
{\n
\t\t\t
_attr: {\n
\t\t\t\t
class: skinClassName,
\n\t\t\t\t
width: tree.width,
\n\t\t\t\t
height: tree.height,
\n\t\t\t\t
'xmlns:e':
\"
http://ns.egret.com/eui
\"
,
\n\t\t\t\t
'xmlns:w':
\"
http://ns.egret.com/wing
\"
,
\n\t\t\t
},
\n\t\t
},
\n\t
];
\n\t
const exmlData = {\n
\t\t
'e:Skin': exmlRoot
\n\t
};
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {x, y, width, height, alpha, visible} = node;
\n\t\t
let attributes = {width, height, alpha, visible};
\n\t\t
if (x !== 0) {\n
\t\t\t
attributes.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
attributes.y = y;
\n\t\t
}
\n\t\t
let element;
\n\t\t
let tagName;
\n\t\t
let imageResName;
\n\t\t
let params;
\n\n\t\t
let hasChild = node.hasOwnProperty('children');
\n\t\t
if (hasChild) {\n
\t\t\t
tagName = 'e:Group';
\n\t\t
} else {\n
\t\t\t
const nameParams = node.name.split('|');
\n\t\t\t
const nodeName = nameParams[0];
\n\n\t\t\t
attributes.name = nodeName;
\n\t\t\t
imageResName = resGroupName + '_' + nodeName;
\n\t\t\t
const imageFilePath = path.join(resPath, resGroupName + '_p', nodeName + '.png');
\n\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t
await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t
if (nameParams.length === 1) {\n
\t\t\t\t
tagName = 'e:Image';
\n\t\t\t
} else {\n
\t\t\t\t
params = nameParams[1].split(',');
\n\t\t\t\t
tagName = 'e:' + params[0];
\n\t\t\t
}
\n\n\t\t\t
//element[tagName] = {_attr: attributes};
\n\t\t
}
\n\n\t\t
let elementTpl = elementTpls[tagName];
\n\t\t
let elementContent;
\n\t\t
if (elementTpl) {\n
\t\t\t
elementContent = JSON.parse(JSON.stringify(elementTpl));
\n\t\t
} else {\n
\t\t\t
elementContent =
{
}\n\t\t
}
\n\t\t
element = {\n
\t\t\t
[tagName]: elementContent,
\n\t\t
};
\n\n\t\t
let attr;
\n\t\t
if (Array.isArray(elementContent)) {\n
\t\t\t
attr = elementContent.find(item => item._attr);
\n\t\t\t
if (!attr) {\n
\t\t\t\t
attr = {_attr:
{
}};\n\t\t\t\telementContent.unshift(attr);\n\t\t\t}\n\t\t
}
else {\n
\t\t\t
attr = elementContent;
\n\t\t
}
\n\n\t\t
Object.assign(attr._attr, attributes);
\n\n\t\t
if (imageResName) {\n
\t\t\t
await walkObject(element, function (key, value, obj) {\n
\t\t\t\t
if (value === '
{
res
}
') {\n
\t\t\t\t\t
obj[key] = imageResName;
\n\t\t\t\t
} else if (typeof value === 'string') {\n
\t\t\t\t\t
const result = value.match(/
{
(\\d+)
}
/g);
\n\t\t\t\t\t
if(result){\n
\t\t\t\t\t\t
for(let item of result){\n
\t\t\t\t\t\t\t
const pi = parseInt(item.match(/
{
(\\d+)
}
/)[1]);
\n\t\t\t\t\t\t\t
value = value.replace(item, params[pi])
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t\t
obj[key] = value;
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t
})
\n\t\t
}
\n\n\t\t
if (hasChild) {\n
\t\t\t
node.exmlNode = elementContent;
\n\t\t
}
\n\n\t\t
const exmlNode = parent.exmlNode || exmlRoot;
\n\t\t
exmlNode.push(element);
\n\t
});
\n\n\t
let exmlStr = xml(exmlData, {declaration: true, indent: true});
\n\t
await fs.ensureDir(path.dirname(skinFilePath));
\n\t
await fs.writeFile(skinFilePath, exmlStr);
\n\n
}"
,
"/**
\n
* Created by rockyl on 2019-09-26.
\n
*
\n
* 导出zeroing的视图
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import
{
walkNode
}
from
\"
./utils
\"
;
\n
import path from 'path'
\n
import Color from 'color'
\n
import generateUUID from 'uuid/v4'
\n
import fs from
\"
fs-extra
\"
;
\n
import hash from 'object-hash';
\n\n
export async function execute(psdFile, options) {\n
\t
const
{
\n\t\timagesPath,\n\t
}
= options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
let viewNode = {\n
\t\t\t
name,
\n\t\t\t
properties,
\n\t\t\t
uuid: generateUUID(),
\n\t\t
};
\n\t\t
let dealLater = true;
\n\t\t
if (x !== 0) {\n
\t\t\t
properties.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
//const fonts = fontInfo.fonts();
\n\t\t\t
//const styles = fontInfo.styles();
\n\t\t\t
//const
{
RunLengthArray
}
= fontInfo.engineData.EngineDict.StyleRun;
\n\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
properties.size = fontInfo.sizes()[0];
\n\t\t\t
let [r, g, b, a] = fontInfo.colors()[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
/*properties.textflow = {\n
\t\t\t\t
fonts, styles, RunLengthArray,
\n\t\t\t
};*/
\n\t\t\t
viewNode.type = 'label';
\n\t\t\t
dealLater = false;
\n\t\t
} else if (solidColor) {\n
\t\t\t
const {r, g, b} = solidColor();
\n\t\t\t
let color = Color({r, g, b});
\n\n\t\t\t
let paths = layer.vectorMask().paths;
\n\t\t\t
if(paths[2].numPoints === 4){\n
\t\t\t\t
let isRect = true;
\n\t\t\t\t
for(let i = 3; i < paths.length; i++){\n
\t\t\t\t\t
if(paths[i].recordType !== 2){\n
\t\t\t\t\t\t
isRect = false;
\n\t\t\t\t\t\t
break;
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t\t
if(isRect){\n
\t\t\t\t\t
viewNode.type = 'rect';
\n\t\t\t\t\t
properties.fillColor = '#' + color.rgbNumber().toString(16);
\n\t\t\t\t\t
dealLater = false;
\n\t\t\t\t
}
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
if(dealLater){\n
\t\t\t
if (node.hasOwnProperty('children')) {\n
\t\t\t\t
viewNode.type = 'node';
\n\t\t\t
} else {\n
\t\t\t\t
viewNode.type = 'image';
\n\n\t\t\t\t
const uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
const imageFilePath = path.join(imagesPath, uuid + ext);
\n\t\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t\t
let png = node.origin.toPng();
\n\t\t\t\t
let buffer = await savePng(png, imageFilePath).catch(e=>{});
\n\t\t\t\t
//await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t\t
if(buffer){\n
\t\t\t\t\t
properties.source = 'asset://' + uuid;
\n\n\t\t\t\t\t
const hashFileName = hash(buffer);
\n\t\t\t\t\t
const hashFilePath = path.join(imagesPath, hashFileName + ext);
\n\t\t\t\t\t
await fs.rename(imageFilePath, hashFilePath);
\n\n\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t
hash: hashFileName,
\n\t\t\t\t\t
});
\n\t\t\t\t
}
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
let viewParent = parent.view || viewRoot;
\n\t\t
if (!viewParent.hasOwnProperty('children')) {\n
\t\t\t
viewParent.children = [];
\n\t\t
}
\n\t\t
viewParent.children.push(viewNode);
\n\n\t\t
node.view = viewNode;
\n\t
});
\n\n\t
return {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
}
\n
}
\n\n
function savePng(png, output) {\n
\t
return new Promise((resolve, reject) => {\n
\t\t
let buffer, buffers = [];
\n\t\t
png.pack()
\n\t\t\t
.on('error', reject)
\n\t\t\t
.on('data', (data) => buffers.push(data))
\n\t\t\t
.on('end', () => {\n
\t\t\t\t
buffer = Buffer.concat(buffers)
\n\t\t\t
})
\n\t\t\t
.pipe(fs.createWriteStream(output))
\n\t\t\t
.on('finish', () =>
{
\n\t\t\t\tresolve(buffer);\n\t\t\t});\n\t});\n}\n"],"names":["execute"],"mappings":";;;;;;;;;;;;;AAAA;;;;AAIA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;;AAE3B,AAAO,eAAe,OAAO,CAAC,WAAW,EAAE;CAC1C,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,C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,CAAC;IAChB,CAAC,CAAC;EACJ,CAAC,CAAC;CACH;;;;;;"
}
\ No newline at end of file
\ No newline at end of file
dist/index.umd.js
View file @
3a07ad83
...
@@ -241,7 +241,7 @@
...
@@ -241,7 +241,7 @@
const
assets
=
[];
const
assets
=
[];
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
let
properties
=
{
let
properties
=
{
width
,
height
,
alpha
,
visible
,
width
,
height
,
alpha
,
visible
,
};
};
...
@@ -250,6 +250,7 @@
...
@@ -250,6 +250,7 @@
properties
,
properties
,
uuid
:
generateUUID
(),
uuid
:
generateUUID
(),
};
};
let
dealLater
=
true
;
if
(
x
!==
0
)
{
if
(
x
!==
0
)
{
properties
.
x
=
x
;
properties
.
x
=
x
;
}
}
...
@@ -259,9 +260,9 @@
...
@@ -259,9 +260,9 @@
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
const
fonts
=
fontInfo
.
fonts
();
//
const fonts = fontInfo.fonts();
const
styles
=
fontInfo
.
styles
();
//
const styles = fontInfo.styles();
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
//
const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
size
=
fontInfo
.
sizes
()[
0
];
properties
.
size
=
fontInfo
.
sizes
()[
0
];
...
@@ -271,13 +272,29 @@
...
@@ -271,13 +272,29 @@
fonts, styles, RunLengthArray,
fonts, styles, RunLengthArray,
};*/
};*/
viewNode
.
type
=
'label'
;
viewNode
.
type
=
'label'
;
dealLater
=
false
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
const
{
r
,
g
,
b
}
=
solidColor
();
const
{
r
,
g
,
b
}
=
solidColor
();
let
color
=
Color
({
r
,
g
,
b
});
let
color
=
Color
({
r
,
g
,
b
});
let
paths
=
layer
.
vectorMask
().
paths
;
if
(
paths
[
2
].
numPoints
===
4
){
let
isRect
=
true
;
for
(
let
i
=
3
;
i
<
paths
.
length
;
i
++
){
if
(
paths
[
i
].
recordType
!==
2
){
isRect
=
false
;
break
;
}
}
if
(
isRect
){
viewNode
.
type
=
'rect'
;
viewNode
.
type
=
'rect'
;
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
}
else
{
dealLater
=
false
;
}
}
}
if
(
dealLater
){
if
(
node
.
hasOwnProperty
(
'children'
))
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
viewNode
.
type
=
'node'
;
viewNode
.
type
=
'node'
;
}
else
{
}
else
{
...
...
dist/index.umd.js.map
View file @
3a07ad83
{
"version"
:
3
,
"file"
:
"index.umd.js"
,
"sources"
:
[
"../src/psd-tree.js"
,
"../src/utils.js"
,
"../src/egret.js"
,
"../src/zeroing.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = require('psd');
\n\n
export async function getTree(psdFilePath) {\n
\t
const psd = await PSD.open(psdFilePath);
\n\t
const root = {};
\n\t
walk(psd.tree(), root);
\n\n\t
return root;
\n
}
\n\n
function walk(psNode, dataNode) {\n
\t
const {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};
\n\t
const {left, top, width, height, name, layer: {opacity, visible}} = psNode;
\n\t
const x = left - pLeft;
\n\t
const y = top - pTop;
\n\n\t
Object.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});
\n\t
if (psNode.children() && psNode.children().length > 0){\n
\t\t
dataNode.children = [];
\n\t
}
\n\n\t
let children = psNode.children();
\n\t
for (let i = children.length - 1; i >= 0; i--) {\n
\t\t
const childPsNode = children[i];
\n\n\t\t
const childDataNode = {};
\n\t\t
dataNode.children.push(childDataNode);
\n\t\t
walk(childPsNode, childDataNode)
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
export async function walkNode(node, callback, includeSelf = false) {\n
\t
if (includeSelf) {\n
\t\t
await callback(node, null);
\n\t
}
\n\t
if (node.children && node.children.length > 0) {\n
\t\t
for (let childNode of node.children) {\n
\t\t\t
await callback(childNode, node);
\n\t\t\t
const result = await walkNode(childNode, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
export async function walkObject(obj, callback) {\n
\t
if(typeof obj ===
\"
object
\"
){\n
\t\t
for (let key of Object.keys(obj)) {\n
\t\t\t
const value = obj[key];
\n\t\t\t
await callback(key, value, obj);
\n\t\t\t
const result = await walkObject(value, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*
\n
* 导出exml
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import {walkNode, walkObject} from
\"
./utils
\"
;
\n
import xml from
\"
xml
\"
;
\n
import path from
\"
path
\"
;
\n
import fs from
\"
fs-extra
\"
;
\n\n
const elementTpls = {\n
\t
'e:Group': [],
\n\t
'e:Image': {_attr: {source: '
{
res}'}
}
,
\n\t
'e:Button': [
\n\t\t
{_attr: {label: '
{
1}',}
}
,
\n\t\t
{\n
\t\t\t
'e:skinName': [
\n\t\t\t\t
{\n
\t\t\t\t\t
'e:Skin': [
\n\t\t\t\t\t\t
{_attr: {states: 'up,down,disabled'}},
\n\t\t\t\t\t\t
{\n
\t\t\t\t\t\t\t
'e:Image': {_attr: {width: '100%', height: '100%', source: '
{
res}'}},\n\t\t\t\t\t\t
}
,
\n\t\t\t\t\t\t
{\n
\t\t\t\t\t\t\t
'e:Label': {_attr: {id: 'labelDisplay', horizontalCenter: '0', verticalCenter: '0'}},
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
]
\n\t\t\t\t
}
\n\t\t\t
]
\n\t\t
}
\n\t
]
\n
};
\n\n
export async function execute(psdFile, options) {\n
\t
const {skinFilePath, skinClassName, resPath, resGroupName} = options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
const exmlRoot = [
\n\t\t
{\n
\t\t\t
_attr: {\n
\t\t\t\t
class: skinClassName,
\n\t\t\t\t
width: tree.width,
\n\t\t\t\t
height: tree.height,
\n\t\t\t\t
'xmlns:e':
\"
http://ns.egret.com/eui
\"
,
\n\t\t\t\t
'xmlns:w':
\"
http://ns.egret.com/wing
\"
,
\n\t\t\t
},
\n\t\t
},
\n\t
];
\n\t
const exmlData = {\n
\t\t
'e:Skin': exmlRoot
\n\t
};
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {x, y, width, height, alpha, visible} = node;
\n\t\t
let attributes = {width, height, alpha, visible};
\n\t\t
if (x !== 0) {\n
\t\t\t
attributes.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
attributes.y = y;
\n\t\t
}
\n\t\t
let element;
\n\t\t
let tagName;
\n\t\t
let imageResName;
\n\t\t
let params;
\n\n\t\t
let hasChild = node.hasOwnProperty('children');
\n\t\t
if (hasChild) {\n
\t\t\t
tagName = 'e:Group';
\n\t\t
} else {\n
\t\t\t
const nameParams = node.name.split('|');
\n\t\t\t
const nodeName = nameParams[0];
\n\n\t\t\t
attributes.name = nodeName;
\n\t\t\t
imageResName = resGroupName + '_' + nodeName;
\n\t\t\t
const imageFilePath = path.join(resPath, resGroupName + '_p', nodeName + '.png');
\n\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t
await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t
if (nameParams.length === 1) {\n
\t\t\t\t
tagName = 'e:Image';
\n\t\t\t
} else {\n
\t\t\t\t
params = nameParams[1].split(',');
\n\t\t\t\t
tagName = 'e:' + params[0];
\n\t\t\t
}
\n\n\t\t\t
//element[tagName] = {_attr: attributes};
\n\t\t
}
\n\n\t\t
let elementTpl = elementTpls[tagName];
\n\t\t
let elementContent;
\n\t\t
if (elementTpl) {\n
\t\t\t
elementContent = JSON.parse(JSON.stringify(elementTpl));
\n\t\t
} else {\n
\t\t\t
elementContent =
{
}\n\t\t
}
\n\t\t
element = {\n
\t\t\t
[tagName]: elementContent,
\n\t\t
};
\n\n\t\t
let attr;
\n\t\t
if (Array.isArray(elementContent)) {\n
\t\t\t
attr = elementContent.find(item => item._attr);
\n\t\t\t
if (!attr) {\n
\t\t\t\t
attr = {_attr:
{
}};\n\t\t\t\telementContent.unshift(attr);\n\t\t\t}\n\t\t
}
else {\n
\t\t\t
attr = elementContent;
\n\t\t
}
\n\n\t\t
Object.assign(attr._attr, attributes);
\n\n\t\t
if (imageResName) {\n
\t\t\t
await walkObject(element, function (key, value, obj) {\n
\t\t\t\t
if (value === '
{
res
}
') {\n
\t\t\t\t\t
obj[key] = imageResName;
\n\t\t\t\t
} else if (typeof value === 'string') {\n
\t\t\t\t\t
const result = value.match(/
{
(\\d+)
}
/g);
\n\t\t\t\t\t
if(result){\n
\t\t\t\t\t\t
for(let item of result){\n
\t\t\t\t\t\t\t
const pi = parseInt(item.match(/
{
(\\d+)
}
/)[1]);
\n\t\t\t\t\t\t\t
value = value.replace(item, params[pi])
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t\t
obj[key] = value;
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t
})
\n\t\t
}
\n\n\t\t
if (hasChild) {\n
\t\t\t
node.exmlNode = elementContent;
\n\t\t
}
\n\n\t\t
const exmlNode = parent.exmlNode || exmlRoot;
\n\t\t
exmlNode.push(element);
\n\t
});
\n\n\t
let exmlStr = xml(exmlData, {declaration: true, indent: true});
\n\t
await fs.ensureDir(path.dirname(skinFilePath));
\n\t
await fs.writeFile(skinFilePath, exmlStr);
\n\n
}"
,
"/**
\n
* Created by rockyl on 2019-09-26.
\n
*
\n
* 导出zeroing的视图
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import
{
walkNode
}
from
\"
./utils
\"
;
\n
import path from 'path'
\n
import Color from 'color'
\n
import generateUUID from 'uuid/v4'
\n
import fs from
\"
fs-extra
\"
;
\n
import hash from 'object-hash';
\n\n
export async function execute(psdFile, options) {\n
\t
const
{
\n\t\timagesPath,\n\t
}
= options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {name, x, y, width, height, alpha, visible, origin: {layer: {typeTool, solidColor}}} = node;
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
let viewNode = {\n
\t\t\t
name,
\n\t\t\t
properties,
\n\t\t\t
uuid: generateUUID(),
\n\t\t
};
\n\t\t
if (x !== 0) {\n
\t\t\t
properties.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
const fonts = fontInfo.fonts();
\n\t\t\t
const styles = fontInfo.styles();
\n\t\t\t
const
{
RunLengthArray
}
= fontInfo.engineData.EngineDict.StyleRun;
\n\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
properties.size = fontInfo.sizes()[0];
\n\t\t\t
let [r, g, b, a] = fontInfo.colors()[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
/*properties.textflow = {\n
\t\t\t\t
fonts, styles, RunLengthArray,
\n\t\t\t
};*/
\n\t\t\t
viewNode.type = 'label';
\n\t\t
} else if (solidColor) {\n
\t\t\t
const {r, g, b} = solidColor();
\n\t\t\t
let color = Color({r, g, b});
\n\n\t\t\t
viewNode.type = 'rect';
\n\t\t\t
properties.fillColor = '#' + color.rgbNumber().toString(16);
\n\t\t
} else {\n
\t\t\t
if (node.hasOwnProperty('children')) {\n
\t\t\t\t
viewNode.type = 'node';
\n\t\t\t
} else {\n
\t\t\t\t
viewNode.type = 'image';
\n\n\t\t\t\t
const uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
const imageFilePath = path.join(imagesPath, uuid + ext);
\n\t\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t\t
let png = node.origin.toPng();
\n\t\t\t\t
let buffer = await savePng(png, imageFilePath).catch(e=>{});
\n\t\t\t\t
//await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t\t
if(buffer){\n
\t\t\t\t\t
properties.source = 'asset://' + uuid;
\n\n\t\t\t\t\t
const hashFileName = hash(buffer);
\n\t\t\t\t\t
const hashFilePath = path.join(imagesPath, hashFileName + ext);
\n\t\t\t\t\t
await fs.rename(imageFilePath, hashFilePath);
\n\n\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t
hash: hashFileName,
\n\t\t\t\t\t
});
\n\t\t\t\t
}
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
let viewParent = parent.view || viewRoot;
\n\t\t
if (!viewParent.hasOwnProperty('children')) {\n
\t\t\t
viewParent.children = [];
\n\t\t
}
\n\t\t
viewParent.children.push(viewNode);
\n\n\t\t
node.view = viewNode;
\n\t
});
\n\n\t
return {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
}
\n
}
\n\n
function savePng(png, output) {\n
\t
return new Promise((resolve, reject) => {\n
\t\t
let buffer, buffers = [];
\n\t\t
png.pack()
\n\t\t\t
.on('error', reject)
\n\t\t\t
.on('data', (data) => buffers.push(data))
\n\t\t\t
.on('end', () => {\n
\t\t\t\t
buffer = Buffer.concat(buffers)
\n\t\t\t
})
\n\t\t\t
.pipe(fs.createWriteStream(output))
\n\t\t\t
.on('finish', () =>
{
\n\t\t\t\tresolve(buffer);\n\t\t\t});\n\t});\n}\n"],"names":["execute"],"mappings":";;;;;;;;;;;;;CAAA;CACA;CACA;;CAEA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;;AAE3B,CAAO,eAAe,OAAO,CAAC,WAAW,EAAE;CAC3C,CAAC,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;CACzC,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;CACjB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;;CAExB,CAAC,OAAO,IAAI,CAAC;CACb,CAAC;;CAED,SAAS,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE;CAChC,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;CAC/D,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC;CAC5E,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;CACxB,CAAC,MAAM,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;;CAEtB,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,O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AI,MAAM,EAAE,OAAO,GAAG,EAAE,CAAC;CAC3B,EAAE,GAAG,CAAC,IAAI,EAAE;CACZ,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;CACvB,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;CAC5C,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM;CACpB,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAC;CACnC,IAAI,CAAC;CACL,IAAI,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;CACtC,IAAI,EAAE,CAAC,QAAQ,EAAE,MAAM;CACvB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACpB,IAAI,CAAC,CAAC;CACN,EAAE,CAAC,CAAC;CACJ,CAAC;;;;;;;;;;;;;;"
}
{
"version"
:
3
,
"file"
:
"index.umd.js"
,
"sources"
:
[
"../src/psd-tree.js"
,
"../src/utils.js"
,
"../src/egret.js"
,
"../src/zeroing.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = require('psd');
\n\n
export async function getTree(psdFilePath) {\n
\t
const psd = await PSD.open(psdFilePath);
\n\t
const root = {};
\n\t
walk(psd.tree(), root);
\n\n\t
return root;
\n
}
\n\n
function walk(psNode, dataNode) {\n
\t
const {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};
\n\t
const {left, top, width, height, name, layer: {opacity, visible}} = psNode;
\n\t
const x = left - pLeft;
\n\t
const y = top - pTop;
\n\n\t
Object.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});
\n\t
if (psNode.children() && psNode.children().length > 0){\n
\t\t
dataNode.children = [];
\n\t
}
\n\n\t
let children = psNode.children();
\n\t
for (let i = children.length - 1; i >= 0; i--) {\n
\t\t
const childPsNode = children[i];
\n\n\t\t
const childDataNode = {};
\n\t\t
dataNode.children.push(childDataNode);
\n\t\t
walk(childPsNode, childDataNode)
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
export async function walkNode(node, callback, includeSelf = false) {\n
\t
if (includeSelf) {\n
\t\t
await callback(node, null);
\n\t
}
\n\t
if (node.children && node.children.length > 0) {\n
\t\t
for (let childNode of node.children) {\n
\t\t\t
await callback(childNode, node);
\n\t\t\t
const result = await walkNode(childNode, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
export async function walkObject(obj, callback) {\n
\t
if(typeof obj ===
\"
object
\"
){\n
\t\t
for (let key of Object.keys(obj)) {\n
\t\t\t
const value = obj[key];
\n\t\t\t
await callback(key, value, obj);
\n\t\t\t
const result = await walkObject(value, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*
\n
* 导出exml
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import {walkNode, walkObject} from
\"
./utils
\"
;
\n
import xml from
\"
xml
\"
;
\n
import path from
\"
path
\"
;
\n
import fs from
\"
fs-extra
\"
;
\n\n
const elementTpls = {\n
\t
'e:Group': [],
\n\t
'e:Image': {_attr: {source: '
{
res}'}
}
,
\n\t
'e:Button': [
\n\t\t
{_attr: {label: '
{
1}',}
}
,
\n\t\t
{\n
\t\t\t
'e:skinName': [
\n\t\t\t\t
{\n
\t\t\t\t\t
'e:Skin': [
\n\t\t\t\t\t\t
{_attr: {states: 'up,down,disabled'}},
\n\t\t\t\t\t\t
{\n
\t\t\t\t\t\t\t
'e:Image': {_attr: {width: '100%', height: '100%', source: '
{
res}'}},\n\t\t\t\t\t\t
}
,
\n\t\t\t\t\t\t
{\n
\t\t\t\t\t\t\t
'e:Label': {_attr: {id: 'labelDisplay', horizontalCenter: '0', verticalCenter: '0'}},
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
]
\n\t\t\t\t
}
\n\t\t\t
]
\n\t\t
}
\n\t
]
\n
};
\n\n
export async function execute(psdFile, options) {\n
\t
const {skinFilePath, skinClassName, resPath, resGroupName} = options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
const exmlRoot = [
\n\t\t
{\n
\t\t\t
_attr: {\n
\t\t\t\t
class: skinClassName,
\n\t\t\t\t
width: tree.width,
\n\t\t\t\t
height: tree.height,
\n\t\t\t\t
'xmlns:e':
\"
http://ns.egret.com/eui
\"
,
\n\t\t\t\t
'xmlns:w':
\"
http://ns.egret.com/wing
\"
,
\n\t\t\t
},
\n\t\t
},
\n\t
];
\n\t
const exmlData = {\n
\t\t
'e:Skin': exmlRoot
\n\t
};
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {x, y, width, height, alpha, visible} = node;
\n\t\t
let attributes = {width, height, alpha, visible};
\n\t\t
if (x !== 0) {\n
\t\t\t
attributes.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
attributes.y = y;
\n\t\t
}
\n\t\t
let element;
\n\t\t
let tagName;
\n\t\t
let imageResName;
\n\t\t
let params;
\n\n\t\t
let hasChild = node.hasOwnProperty('children');
\n\t\t
if (hasChild) {\n
\t\t\t
tagName = 'e:Group';
\n\t\t
} else {\n
\t\t\t
const nameParams = node.name.split('|');
\n\t\t\t
const nodeName = nameParams[0];
\n\n\t\t\t
attributes.name = nodeName;
\n\t\t\t
imageResName = resGroupName + '_' + nodeName;
\n\t\t\t
const imageFilePath = path.join(resPath, resGroupName + '_p', nodeName + '.png');
\n\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t
await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t
if (nameParams.length === 1) {\n
\t\t\t\t
tagName = 'e:Image';
\n\t\t\t
} else {\n
\t\t\t\t
params = nameParams[1].split(',');
\n\t\t\t\t
tagName = 'e:' + params[0];
\n\t\t\t
}
\n\n\t\t\t
//element[tagName] = {_attr: attributes};
\n\t\t
}
\n\n\t\t
let elementTpl = elementTpls[tagName];
\n\t\t
let elementContent;
\n\t\t
if (elementTpl) {\n
\t\t\t
elementContent = JSON.parse(JSON.stringify(elementTpl));
\n\t\t
} else {\n
\t\t\t
elementContent =
{
}\n\t\t
}
\n\t\t
element = {\n
\t\t\t
[tagName]: elementContent,
\n\t\t
};
\n\n\t\t
let attr;
\n\t\t
if (Array.isArray(elementContent)) {\n
\t\t\t
attr = elementContent.find(item => item._attr);
\n\t\t\t
if (!attr) {\n
\t\t\t\t
attr = {_attr:
{
}};\n\t\t\t\telementContent.unshift(attr);\n\t\t\t}\n\t\t
}
else {\n
\t\t\t
attr = elementContent;
\n\t\t
}
\n\n\t\t
Object.assign(attr._attr, attributes);
\n\n\t\t
if (imageResName) {\n
\t\t\t
await walkObject(element, function (key, value, obj) {\n
\t\t\t\t
if (value === '
{
res
}
') {\n
\t\t\t\t\t
obj[key] = imageResName;
\n\t\t\t\t
} else if (typeof value === 'string') {\n
\t\t\t\t\t
const result = value.match(/
{
(\\d+)
}
/g);
\n\t\t\t\t\t
if(result){\n
\t\t\t\t\t\t
for(let item of result){\n
\t\t\t\t\t\t\t
const pi = parseInt(item.match(/
{
(\\d+)
}
/)[1]);
\n\t\t\t\t\t\t\t
value = value.replace(item, params[pi])
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t\t
obj[key] = value;
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t
})
\n\t\t
}
\n\n\t\t
if (hasChild) {\n
\t\t\t
node.exmlNode = elementContent;
\n\t\t
}
\n\n\t\t
const exmlNode = parent.exmlNode || exmlRoot;
\n\t\t
exmlNode.push(element);
\n\t
});
\n\n\t
let exmlStr = xml(exmlData, {declaration: true, indent: true});
\n\t
await fs.ensureDir(path.dirname(skinFilePath));
\n\t
await fs.writeFile(skinFilePath, exmlStr);
\n\n
}"
,
"/**
\n
* Created by rockyl on 2019-09-26.
\n
*
\n
* 导出zeroing的视图
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import
{
walkNode
}
from
\"
./utils
\"
;
\n
import path from 'path'
\n
import Color from 'color'
\n
import generateUUID from 'uuid/v4'
\n
import fs from
\"
fs-extra
\"
;
\n
import hash from 'object-hash';
\n\n
export async function execute(psdFile, options) {\n
\t
const
{
\n\t\timagesPath,\n\t
}
= options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
let viewNode = {\n
\t\t\t
name,
\n\t\t\t
properties,
\n\t\t\t
uuid: generateUUID(),
\n\t\t
};
\n\t\t
let dealLater = true;
\n\t\t
if (x !== 0) {\n
\t\t\t
properties.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
//const fonts = fontInfo.fonts();
\n\t\t\t
//const styles = fontInfo.styles();
\n\t\t\t
//const
{
RunLengthArray
}
= fontInfo.engineData.EngineDict.StyleRun;
\n\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
properties.size = fontInfo.sizes()[0];
\n\t\t\t
let [r, g, b, a] = fontInfo.colors()[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
/*properties.textflow = {\n
\t\t\t\t
fonts, styles, RunLengthArray,
\n\t\t\t
};*/
\n\t\t\t
viewNode.type = 'label';
\n\t\t\t
dealLater = false;
\n\t\t
} else if (solidColor) {\n
\t\t\t
const {r, g, b} = solidColor();
\n\t\t\t
let color = Color({r, g, b});
\n\n\t\t\t
let paths = layer.vectorMask().paths;
\n\t\t\t
if(paths[2].numPoints === 4){\n
\t\t\t\t
let isRect = true;
\n\t\t\t\t
for(let i = 3; i < paths.length; i++){\n
\t\t\t\t\t
if(paths[i].recordType !== 2){\n
\t\t\t\t\t\t
isRect = false;
\n\t\t\t\t\t\t
break;
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t\t
if(isRect){\n
\t\t\t\t\t
viewNode.type = 'rect';
\n\t\t\t\t\t
properties.fillColor = '#' + color.rgbNumber().toString(16);
\n\t\t\t\t\t
dealLater = false;
\n\t\t\t\t
}
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
if(dealLater){\n
\t\t\t
if (node.hasOwnProperty('children')) {\n
\t\t\t\t
viewNode.type = 'node';
\n\t\t\t
} else {\n
\t\t\t\t
viewNode.type = 'image';
\n\n\t\t\t\t
const uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
const imageFilePath = path.join(imagesPath, uuid + ext);
\n\t\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t\t
let png = node.origin.toPng();
\n\t\t\t\t
let buffer = await savePng(png, imageFilePath).catch(e=>{});
\n\t\t\t\t
//await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t\t
if(buffer){\n
\t\t\t\t\t
properties.source = 'asset://' + uuid;
\n\n\t\t\t\t\t
const hashFileName = hash(buffer);
\n\t\t\t\t\t
const hashFilePath = path.join(imagesPath, hashFileName + ext);
\n\t\t\t\t\t
await fs.rename(imageFilePath, hashFilePath);
\n\n\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t
hash: hashFileName,
\n\t\t\t\t\t
});
\n\t\t\t\t
}
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
let viewParent = parent.view || viewRoot;
\n\t\t
if (!viewParent.hasOwnProperty('children')) {\n
\t\t\t
viewParent.children = [];
\n\t\t
}
\n\t\t
viewParent.children.push(viewNode);
\n\n\t\t
node.view = viewNode;
\n\t
});
\n\n\t
return {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
}
\n
}
\n\n
function savePng(png, output) {\n
\t
return new Promise((resolve, reject) => {\n
\t\t
let buffer, buffers = [];
\n\t\t
png.pack()
\n\t\t\t
.on('error', reject)
\n\t\t\t
.on('data', (data) => buffers.push(data))
\n\t\t\t
.on('end', () => {\n
\t\t\t\t
buffer = Buffer.concat(buffers)
\n\t\t\t
})
\n\t\t\t
.pipe(fs.createWriteStream(output))
\n\t\t\t
.on('finish', () =>
{
\n\t\t\t\tresolve(buffer);\n\t\t\t});\n\t});\n}\n"],"names":["execute"],"mappings":";;;;;;;;;;;;;CAAA;CACA;CACA;;CAEA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;;AAE3B,CAAO,eAAe,OAAO,CAAC,WAAW,EAAE;CAC3C,CAAC,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;CACzC,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;CACjB,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;;CAExB,CAAC,OAAO,IAAI,CAAC;CACb,CAAC;;CAED,SAAS,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE;CAChC,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;CAC/D,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,OAAO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CACN,EAAE,CAAC,CAAC;CACJ,CAAC;;;;;;;;;;;;;;"
}
\ No newline at end of file
\ No newline at end of file
package.json
View file @
3a07ad83
{
{
"name"
:
"psd-parse"
,
"name"
:
"psd-parse"
,
"version"
:
"1.0.
2
"
,
"version"
:
"1.0.
3
"
,
"main"
:
"dist/index.js"
,
"main"
:
"dist/index.js"
,
"license"
:
"
MIT
"
,
"license"
:
"
MIT
"
,
"dependencies"
:
{
"dependencies"
:
{
...
...
samples/psd/shapes.psd
0 → 100644
View file @
3a07ad83
File added
samples/zeroing-demo/generator.cjs.js
View file @
3a07ad83
...
@@ -85,7 +85,7 @@ async function execute(psdFile, options) {
...
@@ -85,7 +85,7 @@ async function execute(psdFile, options) {
const
assets
=
[];
const
assets
=
[];
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
let
properties
=
{
let
properties
=
{
width
,
height
,
alpha
,
visible
,
width
,
height
,
alpha
,
visible
,
};
};
...
@@ -94,6 +94,7 @@ async function execute(psdFile, options) {
...
@@ -94,6 +94,7 @@ async function execute(psdFile, options) {
properties
,
properties
,
uuid
:
generateUUID
(),
uuid
:
generateUUID
(),
};
};
let
dealLater
=
true
;
if
(
x
!==
0
)
{
if
(
x
!==
0
)
{
properties
.
x
=
x
;
properties
.
x
=
x
;
}
}
...
@@ -103,24 +104,41 @@ async function execute(psdFile, options) {
...
@@ -103,24 +104,41 @@ async function execute(psdFile, options) {
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
const
fonts
=
fontInfo
.
fonts
();
//
const fonts = fontInfo.fonts();
const
styles
=
fontInfo
.
styles
();
//
const styles = fontInfo.styles();
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
//
const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
size
=
fontInfo
.
sizes
()[
0
];
let
[
r
,
g
,
b
,
a
]
=
fontInfo
.
colors
()[
0
];
let
[
r
,
g
,
b
,
a
]
=
fontInfo
.
colors
()[
0
];
properties
.
c
olor
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
properties
.
fillC
olor
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
properties
.
textflow
=
{
/*
properties.textflow = {
fonts, styles, RunLengthArray,
fonts, styles, RunLengthArray,
};
};
*/
viewNode
.
type
=
'label'
;
viewNode
.
type
=
'label'
;
dealLater
=
false
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
const
{
r
,
g
,
b
}
=
solidColor
();
const
{
r
,
g
,
b
}
=
solidColor
();
let
color
=
Color
({
r
,
g
,
b
});
let
color
=
Color
({
r
,
g
,
b
});
let
paths
=
layer
.
vectorMask
().
paths
;
if
(
paths
[
2
].
numPoints
===
4
){
let
isRect
=
true
;
for
(
let
i
=
3
;
i
<
paths
.
length
;
i
++
){
if
(
paths
[
i
].
recordType
!==
2
){
isRect
=
false
;
break
;
}
}
if
(
isRect
){
viewNode
.
type
=
'rect'
;
viewNode
.
type
=
'rect'
;
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
}
else
{
dealLater
=
false
;
}
}
}
if
(
dealLater
){
if
(
node
.
hasOwnProperty
(
'children'
))
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
viewNode
.
type
=
'node'
;
viewNode
.
type
=
'node'
;
}
else
{
}
else
{
...
@@ -129,14 +147,15 @@ async function execute(psdFile, options) {
...
@@ -129,14 +147,15 @@ async function execute(psdFile, options) {
const
uuid
=
generateUUID
();
const
uuid
=
generateUUID
();
const
ext
=
'.png'
;
const
ext
=
'.png'
;
properties
.
source
=
'asset://'
+
uuid
;
const
imageFilePath
=
path
.
join
(
imagesPath
,
uuid
+
ext
);
const
imageFilePath
=
path
.
join
(
imagesPath
,
uuid
+
ext
);
await
fs
.
ensureDir
(
path
.
dirname
(
imageFilePath
));
await
fs
.
ensureDir
(
path
.
dirname
(
imageFilePath
));
let
png
=
node
.
origin
.
toPng
();
let
png
=
node
.
origin
.
toPng
();
let
buffer
=
await
savePng
(
png
,
imageFilePath
);
let
buffer
=
await
savePng
(
png
,
imageFilePath
)
.
catch
(
e
=>
{})
;
//await node.origin.saveAsPng(imageFilePath);
//await node.origin.saveAsPng(imageFilePath);
if
(
buffer
){
properties
.
source
=
'asset://'
+
uuid
;
const
hashFileName
=
hash
(
buffer
);
const
hashFileName
=
hash
(
buffer
);
const
hashFilePath
=
path
.
join
(
imagesPath
,
hashFileName
+
ext
);
const
hashFilePath
=
path
.
join
(
imagesPath
,
hashFileName
+
ext
);
await
fs
.
rename
(
imageFilePath
,
hashFilePath
);
await
fs
.
rename
(
imageFilePath
,
hashFilePath
);
...
@@ -149,6 +168,7 @@ async function execute(psdFile, options) {
...
@@ -149,6 +168,7 @@ async function execute(psdFile, options) {
});
});
}
}
}
}
}
let
viewParent
=
parent
.
view
||
viewRoot
;
let
viewParent
=
parent
.
view
||
viewRoot
;
if
(
!
viewParent
.
hasOwnProperty
(
'children'
))
{
if
(
!
viewParent
.
hasOwnProperty
(
'children'
))
{
...
@@ -188,7 +208,7 @@ function savePng(png, output) {
...
@@ -188,7 +208,7 @@ function savePng(png, output) {
(
async
function
generate
()
{
(
async
function
generate
()
{
const
imagesPath
=
'zeroing-demo/images_'
+
Date
.
now
();
const
imagesPath
=
'zeroing-demo/images_'
+
Date
.
now
();
const
{
view
,
assets
}
=
await
execute
(
'psd/
test
.psd'
,
{
const
{
view
,
assets
}
=
await
execute
(
'psd/
shapes
.psd'
,
{
imagesPath
,
imagesPath
,
});
});
...
...
samples/zeroing-demo/generator.cjs.js.map
View file @
3a07ad83
{
"version"
:
3
,
"file"
:
"generator.cjs.js"
,
"sources"
:
[
"../../src/psd-tree.js"
,
"../../src/utils.js"
,
"../../src/zeroing.js"
,
"generator.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = require('psd');
\n\n
export async function getTree(psdFilePath) {\n
\t
const psd = await PSD.open(psdFilePath);
\n\t
const root = {};
\n\t
walk(psd.tree(), root);
\n\n\t
return root;
\n
}
\n\n
function walk(psNode, dataNode) {\n
\t
const {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};
\n\t
const {left, top, width, height, name, layer: {opacity, visible}} = psNode;
\n\t
const x = left - pLeft;
\n\t
const y = top - pTop;
\n\n\t
Object.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});
\n\t
if (psNode.children() && psNode.children().length > 0){\n
\t\t
dataNode.children = [];
\n\t
}
\n\n\t
let children = psNode.children();
\n\t
for (let i = children.length - 1; i >= 0; i--) {\n
\t\t
const childPsNode = children[i];
\n\n\t\t
const childDataNode = {};
\n\t\t
dataNode.children.push(childDataNode);
\n\t\t
walk(childPsNode, childDataNode)
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
export async function walkNode(node, callback, includeSelf = false) {\n
\t
if (includeSelf) {\n
\t\t
await callback(node, null);
\n\t
}
\n\t
if (node.children && node.children.length > 0) {\n
\t\t
for (let childNode of node.children) {\n
\t\t\t
await callback(childNode, node);
\n\t\t\t
const result = await walkNode(childNode, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
export async function walkObject(obj, callback) {\n
\t
if(typeof obj ===
\"
object
\"
){\n
\t\t
for (let key of Object.keys(obj)) {\n
\t\t\t
const value = obj[key];
\n\t\t\t
await callback(key, value, obj);
\n\t\t\t
const result = await walkObject(value, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-09-26.
\n
*
\n
* 导出zeroing的视图
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import
{
walkNode
}
from
\"
./utils
\"
;
\n
import path from 'path'
\n
import Color from 'color'
\n
import generateUUID from 'uuid/v4'
\n
import fs from
\"
fs-extra
\"
;
\n
import hash from 'object-hash';
\n\n
export async function execute(psdFile, options) {\n
\t
const
{
\n\t\timagesPath,\n\t
}
= options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {name, x, y, width, height, alpha, visible, origin: {layer: {typeTool, solidColor}}} = node;
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
let viewNode = {\n
\t\t\t
name,
\n\t\t\t
properties,
\n\t\t\t
uuid: generateUUID(),
\n\t\t
};
\n\t\t
if (x !== 0) {\n
\t\t\t
properties.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
const fonts = fontInfo.fonts();
\n\t\t\t
const styles = fontInfo.styles();
\n\t\t\t
const
{
RunLengthArray
}
= fontInfo.engineData.EngineDict.StyleRun;
\n\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
let [r, g, b, a] = fontInfo.colors()[0];
\n\t\t\t
properties.color = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
properties.textflow = {\n
\t\t\t\t
fonts, styles, RunLengthArray,
\n\t\t\t
};
\n\t\t\t
viewNode.type = 'label';
\n\t\t
} else if (solidColor) {\n
\t\t\t
const {r, g, b} = solidColor();
\n\t\t\t
let color = Color({r, g, b});
\n\n\t\t\t
viewNode.type = 'rect';
\n\t\t\t
properties.fillColor = '#' + color.rgbNumber().toString(16);
\n\t\t
} else {\n
\t\t\t
if (node.hasOwnProperty('children')) {\n
\t\t\t\t
viewNode.type = 'node';
\n\t\t\t
} else {\n
\t\t\t\t
viewNode.type = 'image';
\n\n\t\t\t\t
const uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
properties.source = 'asset://' + uuid;
\n\n\t\t\t\t
const imageFilePath = path.join(imagesPath, uuid + ext);
\n\t\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t\t
let png = node.origin.toPng();
\n\t\t\t\t
let buffer = await savePng(png, imageFilePath);
\n\t\t\t\t
//await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t\t
const hashFileName = hash(buffer);
\n\t\t\t\t
const hashFilePath = path.join(imagesPath, hashFileName + ext);
\n\t\t\t\t
await fs.rename(imageFilePath, hashFilePath);
\n\n\t\t\t\t
assets.push({\n
\t\t\t\t\t
name,
\n\t\t\t\t\t
ext,
\n\t\t\t\t\t
uuid,
\n\t\t\t\t\t
hash: hashFileName,
\n\t\t\t\t
});
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
let viewParent = parent.view || viewRoot;
\n\t\t
if (!viewParent.hasOwnProperty('children')) {\n
\t\t\t
viewParent.children = [];
\n\t\t
}
\n\t\t
viewParent.children.push(viewNode);
\n\n\t\t
node.view = viewNode;
\n\t
});
\n\n\t
return {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
}
\n
}
\n\n
function savePng(png, output) {\n
\t
return new Promise((resolve, reject) => {\n
\t\t
let buffer, buffers = [];
\n\t\t
png.pack()
\n\t\t\t
.on('error', reject)
\n\t\t\t
.on('data', (data) => buffers.push(data))
\n\t\t\t
.on('end', () => {\n
\t\t\t\t
buffer = Buffer.concat(buffers)
\n\t\t\t
})
\n\t\t\t
.pipe(fs.createWriteStream(output))
\n\t\t\t
.on('finish', () =>
{
\n\t\t\t\tresolve(buffer);\n\t\t\t});\n\t});\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
import
{
toZeroing
}
from
\"
../../src/index
\"
;
\n\n
(async function generate() {\n
\t
const imagesPath = 'zeroing-demo/images_' + Date.now();
\n\n\t
const {view, assets} = await toZeroing('psd/test.psd',
{
\n\t\timagesPath,\n\t});\n\n\tconsole.log(assets);\n\tconsole.log(view);\n})();\n"],"names":["toZeroing"],"mappings":";;;;;;;;;;;AAAA;;;;AAIA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;;AAE3B,AAAO,eAAe,OAAO,CAAC,WAAW,EAAE;CAC1C,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;CACxC,MAAM,IAAI,GAAG,EAAE,CAAC;CAChB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;;CAEvB,OAAO,IAAI,CAAC;CACZ;;AAED,SAAS,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE;CAC/B,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;CAC9D,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC;CAC3E,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;CACvB,MAAM,CAAC,GAAG,GAAG,GAA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AAE,CAAC;EACzB,GAAG,CAAC,IAAI,EAAE;IACR,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxC,EAAE,CAAC,KAAK,EAAE,MAAM;IAChB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAC;IAC/B,CAAC;IACD,IAAI,CAAC,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAClC,EAAE,CAAC,QAAQ,EAAE,MAAM;IACnB,OAAO,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC,CAAC;EACJ,CAAC,CAAC;CACH;;AC5HD;;;AAGA,AAEA;AACA,CAAC,eAAe,QAAQ,GAAG;CAC1B,MAAM,UAAU,GAAG,sBAAsB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;;CAEvD,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,MAAMA,OAAS,CAAC,cAAc,EAAE;EACtD,UAAU;EACV,CAAC,CAAC;;CAEH,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CACpB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;CAClB,GAAG,CAAC"
}
{
"version"
:
3
,
"file"
:
"generator.cjs.js"
,
"sources"
:
[
"../../src/psd-tree.js"
,
"../../src/utils.js"
,
"../../src/zeroing.js"
,
"generator.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = require('psd');
\n\n
export async function getTree(psdFilePath) {\n
\t
const psd = await PSD.open(psdFilePath);
\n\t
const root = {};
\n\t
walk(psd.tree(), root);
\n\n\t
return root;
\n
}
\n\n
function walk(psNode, dataNode) {\n
\t
const {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};
\n\t
const {left, top, width, height, name, layer: {opacity, visible}} = psNode;
\n\t
const x = left - pLeft;
\n\t
const y = top - pTop;
\n\n\t
Object.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});
\n\t
if (psNode.children() && psNode.children().length > 0){\n
\t\t
dataNode.children = [];
\n\t
}
\n\n\t
let children = psNode.children();
\n\t
for (let i = children.length - 1; i >= 0; i--) {\n
\t\t
const childPsNode = children[i];
\n\n\t\t
const childDataNode = {};
\n\t\t
dataNode.children.push(childDataNode);
\n\t\t
walk(childPsNode, childDataNode)
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
export async function walkNode(node, callback, includeSelf = false) {\n
\t
if (includeSelf) {\n
\t\t
await callback(node, null);
\n\t
}
\n\t
if (node.children && node.children.length > 0) {\n
\t\t
for (let childNode of node.children) {\n
\t\t\t
await callback(childNode, node);
\n\t\t\t
const result = await walkNode(childNode, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
export async function walkObject(obj, callback) {\n
\t
if(typeof obj ===
\"
object
\"
){\n
\t\t
for (let key of Object.keys(obj)) {\n
\t\t\t
const value = obj[key];
\n\t\t\t
await callback(key, value, obj);
\n\t\t\t
const result = await walkObject(value, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-09-26.
\n
*
\n
* 导出zeroing的视图
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import
{
walkNode
}
from
\"
./utils
\"
;
\n
import path from 'path'
\n
import Color from 'color'
\n
import generateUUID from 'uuid/v4'
\n
import fs from
\"
fs-extra
\"
;
\n
import hash from 'object-hash';
\n\n
export async function execute(psdFile, options) {\n
\t
const
{
\n\t\timagesPath,\n\t
}
= options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
let viewNode = {\n
\t\t\t
name,
\n\t\t\t
properties,
\n\t\t\t
uuid: generateUUID(),
\n\t\t
};
\n\t\t
let dealLater = true;
\n\t\t
if (x !== 0) {\n
\t\t\t
properties.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
//const fonts = fontInfo.fonts();
\n\t\t\t
//const styles = fontInfo.styles();
\n\t\t\t
//const
{
RunLengthArray
}
= fontInfo.engineData.EngineDict.StyleRun;
\n\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
properties.size = fontInfo.sizes()[0];
\n\t\t\t
let [r, g, b, a] = fontInfo.colors()[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
/*properties.textflow = {\n
\t\t\t\t
fonts, styles, RunLengthArray,
\n\t\t\t
};*/
\n\t\t\t
viewNode.type = 'label';
\n\t\t\t
dealLater = false;
\n\t\t
} else if (solidColor) {\n
\t\t\t
const {r, g, b} = solidColor();
\n\t\t\t
let color = Color({r, g, b});
\n\n\t\t\t
let paths = layer.vectorMask().paths;
\n\t\t\t
if(paths[2].numPoints === 4){\n
\t\t\t\t
let isRect = true;
\n\t\t\t\t
for(let i = 3; i < paths.length; i++){\n
\t\t\t\t\t
if(paths[i].recordType !== 2){\n
\t\t\t\t\t\t
isRect = false;
\n\t\t\t\t\t\t
break;
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t\t
if(isRect){\n
\t\t\t\t\t
viewNode.type = 'rect';
\n\t\t\t\t\t
properties.fillColor = '#' + color.rgbNumber().toString(16);
\n\t\t\t\t\t
dealLater = false;
\n\t\t\t\t
}
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
if(dealLater){\n
\t\t\t
if (node.hasOwnProperty('children')) {\n
\t\t\t\t
viewNode.type = 'node';
\n\t\t\t
} else {\n
\t\t\t\t
viewNode.type = 'image';
\n\n\t\t\t\t
const uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
const imageFilePath = path.join(imagesPath, uuid + ext);
\n\t\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t\t
let png = node.origin.toPng();
\n\t\t\t\t
let buffer = await savePng(png, imageFilePath).catch(e=>{});
\n\t\t\t\t
//await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t\t
if(buffer){\n
\t\t\t\t\t
properties.source = 'asset://' + uuid;
\n\n\t\t\t\t\t
const hashFileName = hash(buffer);
\n\t\t\t\t\t
const hashFilePath = path.join(imagesPath, hashFileName + ext);
\n\t\t\t\t\t
await fs.rename(imageFilePath, hashFilePath);
\n\n\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t
hash: hashFileName,
\n\t\t\t\t\t
});
\n\t\t\t\t
}
\n\t\t\t
}
\n\t\t
}
\n\n\t\t
let viewParent = parent.view || viewRoot;
\n\t\t
if (!viewParent.hasOwnProperty('children')) {\n
\t\t\t
viewParent.children = [];
\n\t\t
}
\n\t\t
viewParent.children.push(viewNode);
\n\n\t\t
node.view = viewNode;
\n\t
});
\n\n\t
return {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
}
\n
}
\n\n
function savePng(png, output) {\n
\t
return new Promise((resolve, reject) => {\n
\t\t
let buffer, buffers = [];
\n\t\t
png.pack()
\n\t\t\t
.on('error', reject)
\n\t\t\t
.on('data', (data) => buffers.push(data))
\n\t\t\t
.on('end', () => {\n
\t\t\t\t
buffer = Buffer.concat(buffers)
\n\t\t\t
})
\n\t\t\t
.pipe(fs.createWriteStream(output))
\n\t\t\t
.on('finish', () =>
{
\n\t\t\t\tresolve(buffer);\n\t\t\t});\n\t});\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
import
{
toZeroing
}
from
\"
../../src/index
\"
;
\n\n
(async function generate() {\n
\t
const imagesPath = 'zeroing-demo/images_' + Date.now();
\n\n\t
const {view, assets} = await toZeroing('psd/shapes.psd',
{
\n\t\timagesPath,\n\t});\n\n\tconsole.log(assets);\n\tconsole.log(view);\n})();\n"],"names":["toZeroing"],"mappings":";;;;;;;;;;;AAAA;;;;AAIA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;;AAE3B,AAAO,eAAe,OAAO,CAAC,WAAW,EAAE;CAC1C,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;CACxC,MAAM,IAAI,GAAG,EAAE,CAAC;CAChB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;;CAEvB,OAAO,IAAI,CAAC;CACZ;;AAED,SAAS,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE;CAC/B,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;CAC9D,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC;CAC3E,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;CACvB,MAAM,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;;CAErB,MAAM,CAAC,MAAM,CAAC,QAAQ,E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@ -7,7 +7,7 @@ import {toZeroing} from "../../src/index";
...
@@ -7,7 +7,7 @@ import {toZeroing} from "../../src/index";
(
async
function
generate
()
{
(
async
function
generate
()
{
const
imagesPath
=
'zeroing-demo/images_'
+
Date
.
now
();
const
imagesPath
=
'zeroing-demo/images_'
+
Date
.
now
();
const
{
view
,
assets
}
=
await
toZeroing
(
'psd/
test
.psd'
,
{
const
{
view
,
assets
}
=
await
toZeroing
(
'psd/
shapes
.psd'
,
{
imagesPath
,
imagesPath
,
});
});
...
...
samples/zeroing-demo/images_1575000073871/179bc5df94be78d6590e65ec9be0311468d1816a.png
0 → 100644
View file @
3a07ad83
259 Bytes
samples/zeroing-demo/images_1575000073871/51cbd8433e50201013e486d6c6710f7b6aca07df.png
0 → 100644
View file @
3a07ad83
482 Bytes
samples/zeroing-demo/images_1575000073871/5605a4bbc13e94da18858ea814d3e9258420f75c.png
0 → 100644
View file @
3a07ad83
1.45 KB
samples/zeroing-demo/images_1575000073871/f4483c3ddb98dedfb0fce62eb6d1c7a889505e3f.png
0 → 100644
View file @
3a07ad83
1.06 KB
samples/zeroing-demo/images_1575000085190/51cbd8433e50201013e486d6c6710f7b6aca07df.png
0 → 100644
View file @
3a07ad83
482 Bytes
samples/zeroing-demo/images_1575000085190/5605a4bbc13e94da18858ea814d3e9258420f75c.png
0 → 100644
View file @
3a07ad83
1.45 KB
samples/zeroing-demo/images_1575000085190/f4483c3ddb98dedfb0fce62eb6d1c7a889505e3f.png
0 → 100644
View file @
3a07ad83
1.06 KB
src/zeroing.js
View file @
3a07ad83
...
@@ -28,7 +28,7 @@ export async function execute(psdFile, options) {
...
@@ -28,7 +28,7 @@ export async function execute(psdFile, options) {
const
assets
=
[];
const
assets
=
[];
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
let
properties
=
{
let
properties
=
{
width
,
height
,
alpha
,
visible
,
width
,
height
,
alpha
,
visible
,
};
};
...
@@ -37,6 +37,7 @@ export async function execute(psdFile, options) {
...
@@ -37,6 +37,7 @@ export async function execute(psdFile, options) {
properties
,
properties
,
uuid
:
generateUUID
(),
uuid
:
generateUUID
(),
};
};
let
dealLater
=
true
;
if
(
x
!==
0
)
{
if
(
x
!==
0
)
{
properties
.
x
=
x
;
properties
.
x
=
x
;
}
}
...
@@ -46,9 +47,9 @@ export async function execute(psdFile, options) {
...
@@ -46,9 +47,9 @@ export async function execute(psdFile, options) {
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
const
fonts
=
fontInfo
.
fonts
();
//
const fonts = fontInfo.fonts();
const
styles
=
fontInfo
.
styles
();
//
const styles = fontInfo.styles();
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
//
const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
size
=
fontInfo
.
sizes
()[
0
];
properties
.
size
=
fontInfo
.
sizes
()[
0
];
...
@@ -58,13 +59,29 @@ export async function execute(psdFile, options) {
...
@@ -58,13 +59,29 @@ export async function execute(psdFile, options) {
fonts, styles, RunLengthArray,
fonts, styles, RunLengthArray,
};*/
};*/
viewNode
.
type
=
'label'
;
viewNode
.
type
=
'label'
;
dealLater
=
false
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
const
{
r
,
g
,
b
}
=
solidColor
();
const
{
r
,
g
,
b
}
=
solidColor
();
let
color
=
Color
({
r
,
g
,
b
});
let
color
=
Color
({
r
,
g
,
b
});
let
paths
=
layer
.
vectorMask
().
paths
;
if
(
paths
[
2
].
numPoints
===
4
){
let
isRect
=
true
;
for
(
let
i
=
3
;
i
<
paths
.
length
;
i
++
){
if
(
paths
[
i
].
recordType
!==
2
){
isRect
=
false
;
break
;
}
}
if
(
isRect
){
viewNode
.
type
=
'rect'
;
viewNode
.
type
=
'rect'
;
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
}
else
{
dealLater
=
false
;
}
}
}
if
(
dealLater
){
if
(
node
.
hasOwnProperty
(
'children'
))
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
viewNode
.
type
=
'node'
;
viewNode
.
type
=
'node'
;
}
else
{
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment