Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
psd-parse-web
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-web
Commits
5cc49b8f
Commit
5cc49b8f
authored
Jun 24, 2020
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
放假前提交一波
parent
358bd784
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
142 additions
and
128 deletions
+142
-128
index.es.js
dist/index.es.js
+35
-33
index.es.js.map
dist/index.es.js.map
+1
-1
index.js
dist/index.js
+35
-33
index.js.map
dist/index.js.map
+1
-1
index.umd.js
dist/index.umd.js
+35
-33
index.umd.js.map
dist/index.umd.js.map
+1
-1
zeroing.js
src/zeroing.js
+34
-26
No files found.
dist/index.es.js
View file @
5cc49b8f
...
...
@@ -72,25 +72,23 @@ const relativePosPrefixMap = {
b
:
{
field
:
'bottom'
,},
h
:
{
field
:
'horizonCenter'
,},
v
:
{
field
:
'verticalCenter'
,},
wp
:
{
field
:
'width'
,
},
hp
:
{
field
:
'height'
,
},
lp
:
{
field
:
'left'
,
},
tp
:
{
field
:
'top'
,
},
rp
:
{
field
:
'right'
,
},
bp
:
{
field
:
'bottom'
,
},
wp
:
{
field
:
'width'
,},
hp
:
{
field
:
'height'
,},
lp
:
{
field
:
'left'
,},
tp
:
{
field
:
'top'
,},
rp
:
{
field
:
'right'
,},
bp
:
{
field
:
'bottom'
,},
};
const
offsetAll
=
176
;
const
enterChar
=
String
.
fromCharCode
(
13
);
async
function
execute
(
psdFile
,
options
)
{
const
tree
=
await
getTree
(
psdFile
);
const
{
mode
=
'none'
}
=
options
;
const
{
mode
=
'none'
,
singleView
=
true
}
=
options
;
let
offset
=
{
x
:
0
,
y
:
0
};
let
cutSize
=
{
x
:
0
,
y
:
0
};
if
(
mode
!==
'none'
){
cutSize
.
y
=
offsetAll
;
}
switch
(
mode
){
switch
(
mode
)
{
case
'top'
:
offset
.
y
=
offsetAll
;
break
;
...
...
@@ -108,10 +106,6 @@ async function execute(psdFile, options) {
const
assets
=
[];
const
imageHashMap
=
{};
let
{
width
:
stageWidth
,
height
:
stageHeight
}
=
tree
;
stageWidth
-=
0
;
stageHeight
-=
cutSize
.
y
||
0
;
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
let
{
name
}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
...
...
@@ -121,6 +115,8 @@ async function execute(psdFile, options) {
};
const
isSecondLayer
=
!
parent
.
origin
.
parent
;
const
{
width
:
parentWidth
,
height
:
parentHeight
}
=
parent
;
if
(
name
.
includes
(
'|'
))
{
try
{
let
arr
=
name
.
split
(
'|'
);
...
...
@@ -132,7 +128,7 @@ async function execute(psdFile, options) {
let
items
=
relativePos
.
split
(
','
);
for
(
let
item
of
items
)
{
let
result
=
item
.
match
(
/
[
a-zA-Z
]
+/
);
if
(
!
result
)
{
if
(
!
result
)
{
continue
;
}
let
prefix
=
result
[
0
];
...
...
@@ -142,8 +138,8 @@ async function execute(psdFile, options) {
let
value
=
item
.
substr
(
prefix
.
length
);
let
hasValue
=
value
.
length
>
0
;
let
fieldChar
=
prefix
[
0
];
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
case
'l'
:
value
=
x
-
offset
.
x
;
break
;
...
...
@@ -151,30 +147,30 @@ async function execute(psdFile, options) {
value
=
y
-
offset
.
y
;
break
;
case
'r'
:
value
=
stage
Width
-
(
x
-
offset
.
x
)
-
width
;
value
=
parent
Width
-
(
x
-
offset
.
x
)
-
width
;
break
;
case
'b'
:
value
=
stage
Height
-
(
y
-
offset
.
y
)
-
height
;
value
=
parent
Height
-
(
y
-
offset
.
y
)
-
height
;
break
;
case
'h'
:
value
=
x
+
width
/
2
-
stage
Width
/
2
;
value
=
x
+
width
/
2
-
parent
Width
/
2
;
break
;
case
'v'
:
value
=
y
+
height
/
2
-
stage
Height
/
2
;
value
=
y
+
height
/
2
-
parent
Height
/
2
;
break
;
}
}
let
isPercent
=
prefix
.
endsWith
(
'p'
);
if
(
isPercent
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
case
'l'
:
case
'r'
:
value
/=
stage
Width
;
value
/=
parent
Width
;
break
;
case
't'
:
case
'b'
:
value
/=
stage
Height
;
value
/=
parent
Height
;
break
;
}
value
=
Math
.
floor
(
value
*
100
);
...
...
@@ -190,7 +186,7 @@ async function execute(psdFile, options) {
}
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
);
}
}
...
...
@@ -201,16 +197,22 @@ async function execute(psdFile, options) {
uuid
:
generateUUID
(),
};
let
dealLater
=
true
;
if
(
x
!==
0
)
{
properties
.
x
=
x
;
// - (isSecondLayer ? offset.x : 0);
let
px
=
x
;
// - (!singleView && isSecondLayer ? offset.x : 0);
let
py
=
y
;
// - (!singleView && isSecondLayer ? offset.y : 0);
if
(
px
!==
0
)
{
properties
.
x
=
px
;
}
if
(
y
!==
0
)
{
properties
.
y
=
y
;
// - (isSecondLayer ? offset.y : 0)
;
if
(
p
y
!==
0
)
{
properties
.
y
=
py
;
}
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
properties
.
text
=
fontInfo
.
textValue
;
let
text
=
fontInfo
.
textValue
;
if
(
text
.
indexOf
(
enterChar
)
<
0
)
{
//如果未包含回车说明是多行,去掉宽度
delete
properties
[
'width'
];
}
properties
.
text
=
text
;
const
sizes
=
fontInfo
.
sizes
();
const
colors
=
fontInfo
.
colors
();
properties
.
size
=
sizes
?
sizes
[
0
]
||
20
:
20
;
...
...
dist/index.es.js.map
View file @
5cc49b8f
{
"version"
:
3
,
"file"
:
"index.es.js"
,
"sources"
:
[
"../src/psd-tree.js"
,
"../src/utils.js"
,
"../src/zeroing.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = window['require']('psd');
\n\n
export async function getTree(file) {\n
\t
let psd = await PSD.fromDroppedFile(file);
\n\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 hash from 'object-hash';
\n
import zlib from 'zlib';
\n\n
const relativePosPrefixMap = {\n
\t
l: {field: 'left',},
\n\t
t: {field: 'top',},
\n\t
r: {field: 'right',},
\n\t
b: {field: 'bottom',},
\n\t
h: {field: 'horizonCenter',},
\n\t
v: {field: 'verticalCenter',},
\n\t
wp: {field: 'width', },
\n\t
hp: {field: 'height', },
\n\t
lp: {field: 'left', },
\n\t
tp: {field: 'top', },
\n\t
rp: {field: 'right', },
\n\t
bp: {field: 'bottom', },
\n
};
\n\n
const offsetAll = 176;
\n\n
export async function execute(psdFile, options) {\n
\t
const tree = await getTree(psdFile);
\n\t
const {mode = 'none'} = options;
\n\t
let offset = {x: 0, y: 0};
\n\t
let cutSize = {x: 0, y: 0};
\n\t
if(mode !== 'none'){\n
\t\t
cutSize.y = offsetAll;
\n\t
}
\n\t
switch(mode){\n
\t\t
case 'top':
\n\t\t\t
offset.y = offsetAll;
\n\t\t\t
break;
\n\t\t
case 'center':
\n\t\t\t
offset.y = offsetAll / 2;
\n\t\t\t
break;
\n\t
}
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile.name, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\t
const imageHashMap = {};
\n\n\t
let {width: stageWidth, height: stageHeight} = tree;
\n\t
stageWidth -= cutSize.x || 0;
\n\t
stageHeight -= cutSize.y || 0;
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
let
{
name
}
= node;
\n\t\t
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
\n\t\t
//console.log('walk node:', name);
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
const isSecondLayer = !parent.origin.parent;
\n\n\t\t
const {width: parentWidth, height: parentHeight} = parent;
\n\n\t\t
if (name.includes('|')) {\n
\t\t\t
try {\n
\t\t\t\t
let arr = name.split('|');
\n\t\t\t\t
name = arr[0];
\n\t\t\t\t
let paramsStr = arr[1];
\n\t\t\t\t
let params = paramsStr.split(';');
\n\t\t\t\t
let relativePos = params[0];
\n\t\t\t\t
if (relativePos) {\n
\t\t\t\t\t
let items = relativePos.split(',');
\n\t\t\t\t\t
for (let item of items) {\n
\t\t\t\t\t\t
let result = item.match(/[a-zA-Z]+/);
\n\t\t\t\t\t\t
if(!result)
{
\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t
}
\n\t\t\t\t\t\t
let prefix = result[0];
\n\t\t\t\t\t\t
let mapItem = relativePosPrefixMap[prefix];
\n\t\t\t\t\t\t
if (mapItem) {\n
\t\t\t\t\t\t\t
let
{
field,
}
= mapItem;
\n\t\t\t\t\t\t\t
let value = item.substr(prefix.length);
\n\t\t\t\t\t\t\t
let hasValue = value.length > 0;
\n\t\t\t\t\t\t\t
let fieldChar = prefix[0];
\n\t\t\t\t\t\t\t
if(!hasValue){\n
\t\t\t\t\t\t\t\t
switch(fieldChar){\n
\t\t\t\t\t\t\t\t\t
case 'l':
\n\t\t\t\t\t\t\t\t\t\t
value = x - offset.x;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 't':
\n\t\t\t\t\t\t\t\t\t\t
value = y - offset.y;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'r':
\n\t\t\t\t\t\t\t\t\t\t
value = stageWidth - (x - offset.x) - width;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'b':
\n\t\t\t\t\t\t\t\t\t\t
value = stageHeight - (y - offset.y) - height;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'h':
\n\t\t\t\t\t\t\t\t\t\t
value = x + width / 2 - stageWidth / 2;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'v':
\n\t\t\t\t\t\t\t\t\t\t
value = y + height / 2 - stageHeight / 2;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
let isPercent = prefix.endsWith('p');
\n\t\t\t\t\t\t\t
if (isPercent) {\n
\t\t\t\t\t\t\t\t
if(!hasValue){\n
\t\t\t\t\t\t\t\t\t
switch(fieldChar){\n
\t\t\t\t\t\t\t\t\t\t
case 'l':
\n\t\t\t\t\t\t\t\t\t\t
case 'r':
\n\t\t\t\t\t\t\t\t\t\t\t
value /= stageWidth;
\n\t\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t\t
case 't':
\n\t\t\t\t\t\t\t\t\t\t
case 'b':
\n\t\t\t\t\t\t\t\t\t\t\t
value /= stageHeight;
\n\t\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t\t\t
value = Math.floor(value * 100);
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t\t
value += '%';
\n\t\t\t\t\t\t\t
} else {\n
\t\t\t\t\t\t\t\t
value = parseFloat(value);
\n\t\t\t\t\t\t\t\t
if (isNaN(value)) {\n
\t\t\t\t\t\t\t\t\t
value = 0;
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
properties[field] = value;
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t
}catch (e)
{
\n\t\t\t\tconsole.log(e);\n\t\t\t}\n\t\t
}
\n\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;// - (isSecondLayer ? offset.x : 0);
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;// - (isSecondLayer ? offset.y : 0);
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
const sizes = fontInfo.sizes();
\n\t\t\t
const colors = fontInfo.colors();
\n\t\t\t
properties.size = sizes ? sizes[0] || 20 : 20;
\n\t\t\t
let [r, g, b, a] = colors[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
viewNode.type = 'label';
\n\t\t\t
dealLater = false;
\n\t\t
} else if (solidColor && layer.vectorMask) {\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
const {r, g, b} = solidColor();
\n\t\t\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, 1)`;
\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
let uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
let dataUrl;
\n\t\t\t\t
try {\n
\t\t\t\t\t
let img = node.origin.toPng();
\n\t\t\t\t\t
dataUrl = img.src;
\n\t\t\t\t
} catch (e)
{
\n\n\t\t\t\t
}
\n\n\t\t\t\t
if (dataUrl) {\n
\t\t\t\t\t
let base64Data = dataUrl.replace(/^data:image
\\
/
\\
w+;base64,/,
\"\"
);
\n\t\t\t\t\t
let buffer = new Buffer(base64Data, 'base64');
\n\t\t\t\t\t
const fileNameHash = hash(buffer);
\n\t\t\t\t\t
if (imageHashMap.hasOwnProperty(fileNameHash)) {\n
\t\t\t\t\t\t
uuid = imageHashMap[fileNameHash];
\n\t\t\t\t\t
} else {\n
\t\t\t\t\t\t
imageHashMap[fileNameHash] = uuid;
\n\t\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t\t
base64Data,
\n\t\t\t\t\t\t\t
hash: fileNameHash,
\n\t\t\t\t\t\t
});
\n\t\t\t\t\t
}
\n\n\t\t\t\t\t
properties.source = 'asset://' + uuid;
\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
let data = {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
};
\n\n\t
let dataString = JSON.stringify(data);
\n\n\t
let buf = new Buffer(dataString);
\n\t
return await new Promise((resolve, reject) => {\n
\t\t
zlib.gzip(buf, function (err, res) {\n
\t\t\t
if (err)
{
\n\t\t\t\treject(err);\n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AAI,GAAG;EACV,IAAI,EAAE,QAAQ;EACd,MAAM;EACN,CAAC;;CAEF,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;;CAEtC,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;CACjC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;EAC7C,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE;GAClC,IAAI,GAAG,EAAE;IACR,MAAM,CAAC,GAAG,CAAC,CAAC;IACZ,MAAM;IACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,CAAC;IACb;GACD,EAAC;EACF,CAAC;CACF;;;;"
}
\ No newline at end of file
{
"version"
:
3
,
"file"
:
"index.es.js"
,
"sources"
:
[
"../src/psd-tree.js"
,
"../src/utils.js"
,
"../src/zeroing.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = window['require']('psd');
\n\n
export async function getTree(file) {\n
\t
let psd = await PSD.fromDroppedFile(file);
\n\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 hash from 'object-hash';
\n
import zlib from 'zlib';
\n\n
const relativePosPrefixMap = {\n
\t
l: {field: 'left',},
\n\t
t: {field: 'top',},
\n\t
r: {field: 'right',},
\n\t
b: {field: 'bottom',},
\n\t
h: {field: 'horizonCenter',},
\n\t
v: {field: 'verticalCenter',},
\n\t
wp: {field: 'width',},
\n\t
hp: {field: 'height',},
\n\t
lp: {field: 'left',},
\n\t
tp: {field: 'top',},
\n\t
rp: {field: 'right',},
\n\t
bp: {field: 'bottom',},
\n
};
\n\n
const offsetAll = 176;
\n\n
const enterChar = String.fromCharCode(13);
\n\n
export async function execute(psdFile, options) {\n
\t
const tree = await getTree(psdFile);
\n\t
const {mode = 'none', singleView = true} = options;
\n\t
let offset = {x: 0, y: 0};
\n\t
let cutSize = {x: 0, y: 0};
\n\t
if (mode !== 'none') {\n
\t\t
cutSize.y = offsetAll;
\n\t
}
\n\t
switch (mode) {\n
\t\t
case 'top':
\n\t\t\t
offset.y = offsetAll;
\n\t\t\t
break;
\n\t\t
case 'center':
\n\t\t\t
offset.y = offsetAll / 2;
\n\t\t\t
break;
\n\t
}
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile.name, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\t
const imageHashMap = {};
\n\n\t
let {width: stageWidth, height: stageHeight} = tree;
\n\t
stageWidth -= cutSize.x || 0;
\n\t
stageHeight -= cutSize.y || 0;
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
let
{
name
}
= node;
\n\t\t
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
\n\t\t
//console.log('walk node:', name);
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
const isSecondLayer = !parent.origin.parent;
\n\n\t\t
const {width: parentWidth, height: parentHeight} = parent;
\n\n\t\t
if (name.includes('|')) {\n
\t\t\t
try {\n
\t\t\t\t
let arr = name.split('|');
\n\t\t\t\t
name = arr[0];
\n\t\t\t\t
let paramsStr = arr[1];
\n\t\t\t\t
let params = paramsStr.split(';');
\n\t\t\t\t
let relativePos = params[0];
\n\t\t\t\t
if (relativePos) {\n
\t\t\t\t\t
let items = relativePos.split(',');
\n\t\t\t\t\t
for (let item of items) {\n
\t\t\t\t\t\t
let result = item.match(/[a-zA-Z]+/);
\n\t\t\t\t\t\t
if (!result)
{
\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t
}
\n\t\t\t\t\t\t
let prefix = result[0];
\n\t\t\t\t\t\t
let mapItem = relativePosPrefixMap[prefix];
\n\t\t\t\t\t\t
if (mapItem) {\n
\t\t\t\t\t\t\t
let
{
field,
}
= mapItem;
\n\t\t\t\t\t\t\t
let value = item.substr(prefix.length);
\n\t\t\t\t\t\t\t
let hasValue = value.length > 0;
\n\t\t\t\t\t\t\t
let fieldChar = prefix[0];
\n\t\t\t\t\t\t\t
if (!hasValue) {\n
\t\t\t\t\t\t\t\t
switch (fieldChar) {\n
\t\t\t\t\t\t\t\t\t
case 'l':
\n\t\t\t\t\t\t\t\t\t\t
value = x - offset.x;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 't':
\n\t\t\t\t\t\t\t\t\t\t
value = y - offset.y;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'r':
\n\t\t\t\t\t\t\t\t\t\t
value = parentWidth - (x - offset.x) - width;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'b':
\n\t\t\t\t\t\t\t\t\t\t
value = parentHeight - (y - offset.y) - height;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'h':
\n\t\t\t\t\t\t\t\t\t\t
value = x + width / 2 - parentWidth / 2;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'v':
\n\t\t\t\t\t\t\t\t\t\t
value = y + height / 2 - parentHeight / 2;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
let isPercent = prefix.endsWith('p');
\n\t\t\t\t\t\t\t
if (isPercent) {\n
\t\t\t\t\t\t\t\t
if (!hasValue) {\n
\t\t\t\t\t\t\t\t\t
switch (fieldChar) {\n
\t\t\t\t\t\t\t\t\t\t
case 'l':
\n\t\t\t\t\t\t\t\t\t\t
case 'r':
\n\t\t\t\t\t\t\t\t\t\t\t
value /= parentWidth;
\n\t\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t\t
case 't':
\n\t\t\t\t\t\t\t\t\t\t
case 'b':
\n\t\t\t\t\t\t\t\t\t\t\t
value /= parentHeight;
\n\t\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t\t\t
value = Math.floor(value * 100);
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t\t
value += '%';
\n\t\t\t\t\t\t\t
} else {\n
\t\t\t\t\t\t\t\t
value = parseFloat(value);
\n\t\t\t\t\t\t\t\t
if (isNaN(value)) {\n
\t\t\t\t\t\t\t\t\t
value = 0;
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
properties[field] = value;
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t
} catch (e)
{
\n\t\t\t\tconsole.log(e);\n\t\t\t}\n\t\t
}
\n\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
let px = x;// - (!singleView && isSecondLayer ? offset.x : 0);
\n\t\t
let py = y;// - (!singleView && isSecondLayer ? offset.y : 0);
\n\t\t
if (px !== 0) {\n
\t\t\t
properties.x = px;
\n\t\t
}
\n\t\t
if (py !== 0) {\n
\t\t\t
properties.y = py;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
let text = fontInfo.textValue;
\n\t\t\t
if (text.indexOf(enterChar) < 0) { //如果未包含回车说明是多行,去掉宽度
\n\t\t\t\t
delete properties['width'];
\n\t\t\t
}
\n\t\t\t
properties.text = text;
\n\t\t\t
const sizes = fontInfo.sizes();
\n\t\t\t
const colors = fontInfo.colors();
\n\t\t\t
properties.size = sizes ? sizes[0] || 20 : 20;
\n\t\t\t
let [r, g, b, a] = colors[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
viewNode.type = 'label';
\n\t\t\t
dealLater = false;
\n\t\t
} else if (solidColor && layer.vectorMask) {\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
const {r, g, b} = solidColor();
\n\t\t\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, 1)`;
\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
let uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
let dataUrl;
\n\t\t\t\t
try {\n
\t\t\t\t\t
let img = node.origin.toPng();
\n\t\t\t\t\t
dataUrl = img.src;
\n\t\t\t\t
} catch (e)
{
\n\n\t\t\t\t
}
\n\n\t\t\t\t
if (dataUrl) {\n
\t\t\t\t\t
let base64Data = dataUrl.replace(/^data:image
\\
/
\\
w+;base64,/,
\"\"
);
\n\t\t\t\t\t
let buffer = new Buffer(base64Data, 'base64');
\n\t\t\t\t\t
const fileNameHash = hash(buffer);
\n\t\t\t\t\t
if (imageHashMap.hasOwnProperty(fileNameHash)) {\n
\t\t\t\t\t\t
uuid = imageHashMap[fileNameHash];
\n\t\t\t\t\t
} else {\n
\t\t\t\t\t\t
imageHashMap[fileNameHash] = uuid;
\n\t\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t\t
base64Data,
\n\t\t\t\t\t\t\t
hash: fileNameHash,
\n\t\t\t\t\t\t
});
\n\t\t\t\t\t
}
\n\n\t\t\t\t\t
properties.source = 'asset://' + uuid;
\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
let data = {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
};
\n\n\t
let dataString = JSON.stringify(data);
\n\n\t
let buf = new Buffer(dataString);
\n\t
return await new Promise((resolve, reject) => {\n
\t\t
zlib.gzip(buf, function (err, res) {\n
\t\t\t
if (err)
{
\n\t\t\t\treject(err);\n\t\t\t
}
else
{
\n\t\t\t\tconsole.log(res.length);\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;;;;AAAA;;;;AAIA,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;;AAErC,AAAO,eAAe,OAAO,CAAC,IAAI,EAAE;CACnC,IAAI,GAAG,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;;CAE1C,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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/index.js
View file @
5cc49b8f
...
...
@@ -78,25 +78,23 @@ const relativePosPrefixMap = {
b
:
{
field
:
'bottom'
,},
h
:
{
field
:
'horizonCenter'
,},
v
:
{
field
:
'verticalCenter'
,},
wp
:
{
field
:
'width'
,
},
hp
:
{
field
:
'height'
,
},
lp
:
{
field
:
'left'
,
},
tp
:
{
field
:
'top'
,
},
rp
:
{
field
:
'right'
,
},
bp
:
{
field
:
'bottom'
,
},
wp
:
{
field
:
'width'
,},
hp
:
{
field
:
'height'
,},
lp
:
{
field
:
'left'
,},
tp
:
{
field
:
'top'
,},
rp
:
{
field
:
'right'
,},
bp
:
{
field
:
'bottom'
,},
};
const
offsetAll
=
176
;
const
enterChar
=
String
.
fromCharCode
(
13
);
async
function
execute
(
psdFile
,
options
)
{
const
tree
=
await
getTree
(
psdFile
);
const
{
mode
=
'none'
}
=
options
;
const
{
mode
=
'none'
,
singleView
=
true
}
=
options
;
let
offset
=
{
x
:
0
,
y
:
0
};
let
cutSize
=
{
x
:
0
,
y
:
0
};
if
(
mode
!==
'none'
){
cutSize
.
y
=
offsetAll
;
}
switch
(
mode
){
switch
(
mode
)
{
case
'top'
:
offset
.
y
=
offsetAll
;
break
;
...
...
@@ -114,10 +112,6 @@ async function execute(psdFile, options) {
const
assets
=
[];
const
imageHashMap
=
{};
let
{
width
:
stageWidth
,
height
:
stageHeight
}
=
tree
;
stageWidth
-=
0
;
stageHeight
-=
cutSize
.
y
||
0
;
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
let
{
name
}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
...
...
@@ -127,6 +121,8 @@ async function execute(psdFile, options) {
};
const
isSecondLayer
=
!
parent
.
origin
.
parent
;
const
{
width
:
parentWidth
,
height
:
parentHeight
}
=
parent
;
if
(
name
.
includes
(
'|'
))
{
try
{
let
arr
=
name
.
split
(
'|'
);
...
...
@@ -138,7 +134,7 @@ async function execute(psdFile, options) {
let
items
=
relativePos
.
split
(
','
);
for
(
let
item
of
items
)
{
let
result
=
item
.
match
(
/
[
a-zA-Z
]
+/
);
if
(
!
result
)
{
if
(
!
result
)
{
continue
;
}
let
prefix
=
result
[
0
];
...
...
@@ -148,8 +144,8 @@ async function execute(psdFile, options) {
let
value
=
item
.
substr
(
prefix
.
length
);
let
hasValue
=
value
.
length
>
0
;
let
fieldChar
=
prefix
[
0
];
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
case
'l'
:
value
=
x
-
offset
.
x
;
break
;
...
...
@@ -157,30 +153,30 @@ async function execute(psdFile, options) {
value
=
y
-
offset
.
y
;
break
;
case
'r'
:
value
=
stage
Width
-
(
x
-
offset
.
x
)
-
width
;
value
=
parent
Width
-
(
x
-
offset
.
x
)
-
width
;
break
;
case
'b'
:
value
=
stage
Height
-
(
y
-
offset
.
y
)
-
height
;
value
=
parent
Height
-
(
y
-
offset
.
y
)
-
height
;
break
;
case
'h'
:
value
=
x
+
width
/
2
-
stage
Width
/
2
;
value
=
x
+
width
/
2
-
parent
Width
/
2
;
break
;
case
'v'
:
value
=
y
+
height
/
2
-
stage
Height
/
2
;
value
=
y
+
height
/
2
-
parent
Height
/
2
;
break
;
}
}
let
isPercent
=
prefix
.
endsWith
(
'p'
);
if
(
isPercent
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
case
'l'
:
case
'r'
:
value
/=
stage
Width
;
value
/=
parent
Width
;
break
;
case
't'
:
case
'b'
:
value
/=
stage
Height
;
value
/=
parent
Height
;
break
;
}
value
=
Math
.
floor
(
value
*
100
);
...
...
@@ -196,7 +192,7 @@ async function execute(psdFile, options) {
}
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
);
}
}
...
...
@@ -207,16 +203,22 @@ async function execute(psdFile, options) {
uuid
:
generateUUID
(),
};
let
dealLater
=
true
;
if
(
x
!==
0
)
{
properties
.
x
=
x
;
// - (isSecondLayer ? offset.x : 0);
let
px
=
x
;
// - (!singleView && isSecondLayer ? offset.x : 0);
let
py
=
y
;
// - (!singleView && isSecondLayer ? offset.y : 0);
if
(
px
!==
0
)
{
properties
.
x
=
px
;
}
if
(
y
!==
0
)
{
properties
.
y
=
y
;
// - (isSecondLayer ? offset.y : 0)
;
if
(
p
y
!==
0
)
{
properties
.
y
=
py
;
}
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
properties
.
text
=
fontInfo
.
textValue
;
let
text
=
fontInfo
.
textValue
;
if
(
text
.
indexOf
(
enterChar
)
<
0
)
{
//如果未包含回车说明是多行,去掉宽度
delete
properties
[
'width'
];
}
properties
.
text
=
text
;
const
sizes
=
fontInfo
.
sizes
();
const
colors
=
fontInfo
.
colors
();
properties
.
size
=
sizes
?
sizes
[
0
]
||
20
:
20
;
...
...
dist/index.js.map
View file @
5cc49b8f
{
"version"
:
3
,
"file"
:
"index.js"
,
"sources"
:
[
"../src/psd-tree.js"
,
"../src/utils.js"
,
"../src/zeroing.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = window['require']('psd');
\n\n
export async function getTree(file) {\n
\t
let psd = await PSD.fromDroppedFile(file);
\n\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 hash from 'object-hash';
\n
import zlib from 'zlib';
\n\n
const relativePosPrefixMap = {\n
\t
l: {field: 'left',},
\n\t
t: {field: 'top',},
\n\t
r: {field: 'right',},
\n\t
b: {field: 'bottom',},
\n\t
h: {field: 'horizonCenter',},
\n\t
v: {field: 'verticalCenter',},
\n\t
wp: {field: 'width', },
\n\t
hp: {field: 'height', },
\n\t
lp: {field: 'left', },
\n\t
tp: {field: 'top', },
\n\t
rp: {field: 'right', },
\n\t
bp: {field: 'bottom', },
\n
};
\n\n
const offsetAll = 176;
\n\n
export async function execute(psdFile, options) {\n
\t
const tree = await getTree(psdFile);
\n\t
const {mode = 'none'} = options;
\n\t
let offset = {x: 0, y: 0};
\n\t
let cutSize = {x: 0, y: 0};
\n\t
if(mode !== 'none'){\n
\t\t
cutSize.y = offsetAll;
\n\t
}
\n\t
switch(mode){\n
\t\t
case 'top':
\n\t\t\t
offset.y = offsetAll;
\n\t\t\t
break;
\n\t\t
case 'center':
\n\t\t\t
offset.y = offsetAll / 2;
\n\t\t\t
break;
\n\t
}
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile.name, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\t
const imageHashMap = {};
\n\n\t
let {width: stageWidth, height: stageHeight} = tree;
\n\t
stageWidth -= cutSize.x || 0;
\n\t
stageHeight -= cutSize.y || 0;
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
let
{
name
}
= node;
\n\t\t
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
\n\t\t
//console.log('walk node:', name);
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
const isSecondLayer = !parent.origin.parent;
\n\n\t\t
const {width: parentWidth, height: parentHeight} = parent;
\n\n\t\t
if (name.includes('|')) {\n
\t\t\t
try {\n
\t\t\t\t
let arr = name.split('|');
\n\t\t\t\t
name = arr[0];
\n\t\t\t\t
let paramsStr = arr[1];
\n\t\t\t\t
let params = paramsStr.split(';');
\n\t\t\t\t
let relativePos = params[0];
\n\t\t\t\t
if (relativePos) {\n
\t\t\t\t\t
let items = relativePos.split(',');
\n\t\t\t\t\t
for (let item of items) {\n
\t\t\t\t\t\t
let result = item.match(/[a-zA-Z]+/);
\n\t\t\t\t\t\t
if(!result)
{
\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t
}
\n\t\t\t\t\t\t
let prefix = result[0];
\n\t\t\t\t\t\t
let mapItem = relativePosPrefixMap[prefix];
\n\t\t\t\t\t\t
if (mapItem) {\n
\t\t\t\t\t\t\t
let
{
field,
}
= mapItem;
\n\t\t\t\t\t\t\t
let value = item.substr(prefix.length);
\n\t\t\t\t\t\t\t
let hasValue = value.length > 0;
\n\t\t\t\t\t\t\t
let fieldChar = prefix[0];
\n\t\t\t\t\t\t\t
if(!hasValue){\n
\t\t\t\t\t\t\t\t
switch(fieldChar){\n
\t\t\t\t\t\t\t\t\t
case 'l':
\n\t\t\t\t\t\t\t\t\t\t
value = x - offset.x;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 't':
\n\t\t\t\t\t\t\t\t\t\t
value = y - offset.y;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'r':
\n\t\t\t\t\t\t\t\t\t\t
value = stageWidth - (x - offset.x) - width;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'b':
\n\t\t\t\t\t\t\t\t\t\t
value = stageHeight - (y - offset.y) - height;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'h':
\n\t\t\t\t\t\t\t\t\t\t
value = x + width / 2 - stageWidth / 2;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'v':
\n\t\t\t\t\t\t\t\t\t\t
value = y + height / 2 - stageHeight / 2;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
let isPercent = prefix.endsWith('p');
\n\t\t\t\t\t\t\t
if (isPercent) {\n
\t\t\t\t\t\t\t\t
if(!hasValue){\n
\t\t\t\t\t\t\t\t\t
switch(fieldChar){\n
\t\t\t\t\t\t\t\t\t\t
case 'l':
\n\t\t\t\t\t\t\t\t\t\t
case 'r':
\n\t\t\t\t\t\t\t\t\t\t\t
value /= stageWidth;
\n\t\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t\t
case 't':
\n\t\t\t\t\t\t\t\t\t\t
case 'b':
\n\t\t\t\t\t\t\t\t\t\t\t
value /= stageHeight;
\n\t\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t\t\t
value = Math.floor(value * 100);
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t\t
value += '%';
\n\t\t\t\t\t\t\t
} else {\n
\t\t\t\t\t\t\t\t
value = parseFloat(value);
\n\t\t\t\t\t\t\t\t
if (isNaN(value)) {\n
\t\t\t\t\t\t\t\t\t
value = 0;
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
properties[field] = value;
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t
}catch (e)
{
\n\t\t\t\tconsole.log(e);\n\t\t\t}\n\t\t
}
\n\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;// - (isSecondLayer ? offset.x : 0);
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;// - (isSecondLayer ? offset.y : 0);
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
const sizes = fontInfo.sizes();
\n\t\t\t
const colors = fontInfo.colors();
\n\t\t\t
properties.size = sizes ? sizes[0] || 20 : 20;
\n\t\t\t
let [r, g, b, a] = colors[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
viewNode.type = 'label';
\n\t\t\t
dealLater = false;
\n\t\t
} else if (solidColor && layer.vectorMask) {\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
const {r, g, b} = solidColor();
\n\t\t\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, 1)`;
\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
let uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
let dataUrl;
\n\t\t\t\t
try {\n
\t\t\t\t\t
let img = node.origin.toPng();
\n\t\t\t\t\t
dataUrl = img.src;
\n\t\t\t\t
} catch (e)
{
\n\n\t\t\t\t
}
\n\n\t\t\t\t
if (dataUrl) {\n
\t\t\t\t\t
let base64Data = dataUrl.replace(/^data:image
\\
/
\\
w+;base64,/,
\"\"
);
\n\t\t\t\t\t
let buffer = new Buffer(base64Data, 'base64');
\n\t\t\t\t\t
const fileNameHash = hash(buffer);
\n\t\t\t\t\t
if (imageHashMap.hasOwnProperty(fileNameHash)) {\n
\t\t\t\t\t\t
uuid = imageHashMap[fileNameHash];
\n\t\t\t\t\t
} else {\n
\t\t\t\t\t\t
imageHashMap[fileNameHash] = uuid;
\n\t\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t\t
base64Data,
\n\t\t\t\t\t\t\t
hash: fileNameHash,
\n\t\t\t\t\t\t
});
\n\t\t\t\t\t
}
\n\n\t\t\t\t\t
properties.source = 'asset://' + uuid;
\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
let data = {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
};
\n\n\t
let dataString = JSON.stringify(data);
\n\n\t
let buf = new Buffer(dataString);
\n\t
return await new Promise((resolve, reject) => {\n
\t\t
zlib.gzip(buf, function (err, res) {\n
\t\t\t
if (err)
{
\n\t\t\t\treject(err);\n\t\t\t
}
else
{
\n\t\t\t\tconsole.log(res.length);\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;AAIA,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;;AAErC,AAAO,eAAe,OAAO,CAAC,IAAI,EAAE;CACnC,IAAI,GAAG,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;;CAE1C,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,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C,IAAI,CAAC;OACX,IAAI;OACJ,GAAG;OACH,IAAI;OACJ,UAAU;OACV,IAAI,EAAE,YAAY;OAClB,CAAC,CAAC;MACH;;KAED,UAAU,CAAC,MAAM,GAAG,UAAU,GAAG,IAAI,CAAC;KACtC;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,IAAI,IAAI,GAAG;EACV,IAAI,EAAE,QAAQ;EACd,MAAM;EACN,CAAC;;CAEF,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;;CAEtC,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;CACjC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;EAC7C,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE;GAClC,IAAI,GAAG,EAAE;IACR,MAAM,CAAC,GAAG,CAAC,CAAC;IACZ,MAAM;IACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,CAAC;IACb;GACD,EAAC;EACF,CAAC;CACF;;;;;"
}
\ No newline at end of file
{
"version"
:
3
,
"file"
:
"index.js"
,
"sources"
:
[
"../src/psd-tree.js"
,
"../src/utils.js"
,
"../src/zeroing.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = window['require']('psd');
\n\n
export async function getTree(file) {\n
\t
let psd = await PSD.fromDroppedFile(file);
\n\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 hash from 'object-hash';
\n
import zlib from 'zlib';
\n\n
const relativePosPrefixMap = {\n
\t
l: {field: 'left',},
\n\t
t: {field: 'top',},
\n\t
r: {field: 'right',},
\n\t
b: {field: 'bottom',},
\n\t
h: {field: 'horizonCenter',},
\n\t
v: {field: 'verticalCenter',},
\n\t
wp: {field: 'width',},
\n\t
hp: {field: 'height',},
\n\t
lp: {field: 'left',},
\n\t
tp: {field: 'top',},
\n\t
rp: {field: 'right',},
\n\t
bp: {field: 'bottom',},
\n
};
\n\n
const offsetAll = 176;
\n\n
const enterChar = String.fromCharCode(13);
\n\n
export async function execute(psdFile, options) {\n
\t
const tree = await getTree(psdFile);
\n\t
const {mode = 'none', singleView = true} = options;
\n\t
let offset = {x: 0, y: 0};
\n\t
let cutSize = {x: 0, y: 0};
\n\t
if (mode !== 'none') {\n
\t\t
cutSize.y = offsetAll;
\n\t
}
\n\t
switch (mode) {\n
\t\t
case 'top':
\n\t\t\t
offset.y = offsetAll;
\n\t\t\t
break;
\n\t\t
case 'center':
\n\t\t\t
offset.y = offsetAll / 2;
\n\t\t\t
break;
\n\t
}
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile.name, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\t
const imageHashMap = {};
\n\n\t
let {width: stageWidth, height: stageHeight} = tree;
\n\t
stageWidth -= cutSize.x || 0;
\n\t
stageHeight -= cutSize.y || 0;
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
let
{
name
}
= node;
\n\t\t
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
\n\t\t
//console.log('walk node:', name);
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
const isSecondLayer = !parent.origin.parent;
\n\n\t\t
const {width: parentWidth, height: parentHeight} = parent;
\n\n\t\t
if (name.includes('|')) {\n
\t\t\t
try {\n
\t\t\t\t
let arr = name.split('|');
\n\t\t\t\t
name = arr[0];
\n\t\t\t\t
let paramsStr = arr[1];
\n\t\t\t\t
let params = paramsStr.split(';');
\n\t\t\t\t
let relativePos = params[0];
\n\t\t\t\t
if (relativePos) {\n
\t\t\t\t\t
let items = relativePos.split(',');
\n\t\t\t\t\t
for (let item of items) {\n
\t\t\t\t\t\t
let result = item.match(/[a-zA-Z]+/);
\n\t\t\t\t\t\t
if (!result)
{
\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t
}
\n\t\t\t\t\t\t
let prefix = result[0];
\n\t\t\t\t\t\t
let mapItem = relativePosPrefixMap[prefix];
\n\t\t\t\t\t\t
if (mapItem) {\n
\t\t\t\t\t\t\t
let
{
field,
}
= mapItem;
\n\t\t\t\t\t\t\t
let value = item.substr(prefix.length);
\n\t\t\t\t\t\t\t
let hasValue = value.length > 0;
\n\t\t\t\t\t\t\t
let fieldChar = prefix[0];
\n\t\t\t\t\t\t\t
if (!hasValue) {\n
\t\t\t\t\t\t\t\t
switch (fieldChar) {\n
\t\t\t\t\t\t\t\t\t
case 'l':
\n\t\t\t\t\t\t\t\t\t\t
value = x - offset.x;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 't':
\n\t\t\t\t\t\t\t\t\t\t
value = y - offset.y;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'r':
\n\t\t\t\t\t\t\t\t\t\t
value = parentWidth - (x - offset.x) - width;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'b':
\n\t\t\t\t\t\t\t\t\t\t
value = parentHeight - (y - offset.y) - height;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'h':
\n\t\t\t\t\t\t\t\t\t\t
value = x + width / 2 - parentWidth / 2;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'v':
\n\t\t\t\t\t\t\t\t\t\t
value = y + height / 2 - parentHeight / 2;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
let isPercent = prefix.endsWith('p');
\n\t\t\t\t\t\t\t
if (isPercent) {\n
\t\t\t\t\t\t\t\t
if (!hasValue) {\n
\t\t\t\t\t\t\t\t\t
switch (fieldChar) {\n
\t\t\t\t\t\t\t\t\t\t
case 'l':
\n\t\t\t\t\t\t\t\t\t\t
case 'r':
\n\t\t\t\t\t\t\t\t\t\t\t
value /= parentWidth;
\n\t\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t\t
case 't':
\n\t\t\t\t\t\t\t\t\t\t
case 'b':
\n\t\t\t\t\t\t\t\t\t\t\t
value /= parentHeight;
\n\t\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t\t\t
value = Math.floor(value * 100);
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t\t
value += '%';
\n\t\t\t\t\t\t\t
} else {\n
\t\t\t\t\t\t\t\t
value = parseFloat(value);
\n\t\t\t\t\t\t\t\t
if (isNaN(value)) {\n
\t\t\t\t\t\t\t\t\t
value = 0;
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
properties[field] = value;
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t
} catch (e)
{
\n\t\t\t\tconsole.log(e);\n\t\t\t}\n\t\t
}
\n\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
let px = x;// - (!singleView && isSecondLayer ? offset.x : 0);
\n\t\t
let py = y;// - (!singleView && isSecondLayer ? offset.y : 0);
\n\t\t
if (px !== 0) {\n
\t\t\t
properties.x = px;
\n\t\t
}
\n\t\t
if (py !== 0) {\n
\t\t\t
properties.y = py;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
let text = fontInfo.textValue;
\n\t\t\t
if (text.indexOf(enterChar) < 0) { //如果未包含回车说明是多行,去掉宽度
\n\t\t\t\t
delete properties['width'];
\n\t\t\t
}
\n\t\t\t
properties.text = text;
\n\t\t\t
const sizes = fontInfo.sizes();
\n\t\t\t
const colors = fontInfo.colors();
\n\t\t\t
properties.size = sizes ? sizes[0] || 20 : 20;
\n\t\t\t
let [r, g, b, a] = colors[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
viewNode.type = 'label';
\n\t\t\t
dealLater = false;
\n\t\t
} else if (solidColor && layer.vectorMask) {\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
const {r, g, b} = solidColor();
\n\t\t\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, 1)`;
\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
let uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
let dataUrl;
\n\t\t\t\t
try {\n
\t\t\t\t\t
let img = node.origin.toPng();
\n\t\t\t\t\t
dataUrl = img.src;
\n\t\t\t\t
} catch (e)
{
\n\n\t\t\t\t
}
\n\n\t\t\t\t
if (dataUrl) {\n
\t\t\t\t\t
let base64Data = dataUrl.replace(/^data:image
\\
/
\\
w+;base64,/,
\"\"
);
\n\t\t\t\t\t
let buffer = new Buffer(base64Data, 'base64');
\n\t\t\t\t\t
const fileNameHash = hash(buffer);
\n\t\t\t\t\t
if (imageHashMap.hasOwnProperty(fileNameHash)) {\n
\t\t\t\t\t\t
uuid = imageHashMap[fileNameHash];
\n\t\t\t\t\t
} else {\n
\t\t\t\t\t\t
imageHashMap[fileNameHash] = uuid;
\n\t\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t\t
base64Data,
\n\t\t\t\t\t\t\t
hash: fileNameHash,
\n\t\t\t\t\t\t
});
\n\t\t\t\t\t
}
\n\n\t\t\t\t\t
properties.source = 'asset://' + uuid;
\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
let data = {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
};
\n\n\t
let dataString = JSON.stringify(data);
\n\n\t
let buf = new Buffer(dataString);
\n\t
return await new Promise((resolve, reject) => {\n
\t\t
zlib.gzip(buf, function (err, res) {\n
\t\t\t
if (err)
{
\n\t\t\t\treject(err);\n\t\t\t
}
else
{
\n\t\t\t\tconsole.log(res.length);\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;A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AC;;CAEF,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;;CAEtC,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;CACjC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;EAC7C,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE;GAClC,IAAI,GAAG,EAAE;IACR,MAAM,CAAC,GAAG,CAAC,CAAC;IACZ,MAAM;IACN,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,CAAC;IACb;GACD,EAAC;EACF,CAAC;CACF;;;;;"
}
\ No newline at end of file
dist/index.umd.js
View file @
5cc49b8f
...
...
@@ -78,25 +78,23 @@
b
:
{
field
:
'bottom'
,},
h
:
{
field
:
'horizonCenter'
,},
v
:
{
field
:
'verticalCenter'
,},
wp
:
{
field
:
'width'
,
},
hp
:
{
field
:
'height'
,
},
lp
:
{
field
:
'left'
,
},
tp
:
{
field
:
'top'
,
},
rp
:
{
field
:
'right'
,
},
bp
:
{
field
:
'bottom'
,
},
wp
:
{
field
:
'width'
,},
hp
:
{
field
:
'height'
,},
lp
:
{
field
:
'left'
,},
tp
:
{
field
:
'top'
,},
rp
:
{
field
:
'right'
,},
bp
:
{
field
:
'bottom'
,},
};
const
offsetAll
=
176
;
const
enterChar
=
String
.
fromCharCode
(
13
);
async
function
execute
(
psdFile
,
options
)
{
const
tree
=
await
getTree
(
psdFile
);
const
{
mode
=
'none'
}
=
options
;
const
{
mode
=
'none'
,
singleView
=
true
}
=
options
;
let
offset
=
{
x
:
0
,
y
:
0
};
let
cutSize
=
{
x
:
0
,
y
:
0
};
if
(
mode
!==
'none'
){
cutSize
.
y
=
offsetAll
;
}
switch
(
mode
){
switch
(
mode
)
{
case
'top'
:
offset
.
y
=
offsetAll
;
break
;
...
...
@@ -114,10 +112,6 @@
const
assets
=
[];
const
imageHashMap
=
{};
let
{
width
:
stageWidth
,
height
:
stageHeight
}
=
tree
;
stageWidth
-=
0
;
stageHeight
-=
cutSize
.
y
||
0
;
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
let
{
name
}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
...
...
@@ -127,6 +121,8 @@
};
const
isSecondLayer
=
!
parent
.
origin
.
parent
;
const
{
width
:
parentWidth
,
height
:
parentHeight
}
=
parent
;
if
(
name
.
includes
(
'|'
))
{
try
{
let
arr
=
name
.
split
(
'|'
);
...
...
@@ -138,7 +134,7 @@
let
items
=
relativePos
.
split
(
','
);
for
(
let
item
of
items
)
{
let
result
=
item
.
match
(
/
[
a-zA-Z
]
+/
);
if
(
!
result
)
{
if
(
!
result
)
{
continue
;
}
let
prefix
=
result
[
0
];
...
...
@@ -148,8 +144,8 @@
let
value
=
item
.
substr
(
prefix
.
length
);
let
hasValue
=
value
.
length
>
0
;
let
fieldChar
=
prefix
[
0
];
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
case
'l'
:
value
=
x
-
offset
.
x
;
break
;
...
...
@@ -157,30 +153,30 @@
value
=
y
-
offset
.
y
;
break
;
case
'r'
:
value
=
stage
Width
-
(
x
-
offset
.
x
)
-
width
;
value
=
parent
Width
-
(
x
-
offset
.
x
)
-
width
;
break
;
case
'b'
:
value
=
stage
Height
-
(
y
-
offset
.
y
)
-
height
;
value
=
parent
Height
-
(
y
-
offset
.
y
)
-
height
;
break
;
case
'h'
:
value
=
x
+
width
/
2
-
stage
Width
/
2
;
value
=
x
+
width
/
2
-
parent
Width
/
2
;
break
;
case
'v'
:
value
=
y
+
height
/
2
-
stage
Height
/
2
;
value
=
y
+
height
/
2
-
parent
Height
/
2
;
break
;
}
}
let
isPercent
=
prefix
.
endsWith
(
'p'
);
if
(
isPercent
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
case
'l'
:
case
'r'
:
value
/=
stage
Width
;
value
/=
parent
Width
;
break
;
case
't'
:
case
'b'
:
value
/=
stage
Height
;
value
/=
parent
Height
;
break
;
}
value
=
Math
.
floor
(
value
*
100
);
...
...
@@ -196,7 +192,7 @@
}
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
);
}
}
...
...
@@ -207,16 +203,22 @@
uuid
:
generateUUID
(),
};
let
dealLater
=
true
;
if
(
x
!==
0
)
{
properties
.
x
=
x
;
// - (isSecondLayer ? offset.x : 0);
let
px
=
x
;
// - (!singleView && isSecondLayer ? offset.x : 0);
let
py
=
y
;
// - (!singleView && isSecondLayer ? offset.y : 0);
if
(
px
!==
0
)
{
properties
.
x
=
px
;
}
if
(
y
!==
0
)
{
properties
.
y
=
y
;
// - (isSecondLayer ? offset.y : 0)
;
if
(
p
y
!==
0
)
{
properties
.
y
=
py
;
}
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
properties
.
text
=
fontInfo
.
textValue
;
let
text
=
fontInfo
.
textValue
;
if
(
text
.
indexOf
(
enterChar
)
<
0
)
{
//如果未包含回车说明是多行,去掉宽度
delete
properties
[
'width'
];
}
properties
.
text
=
text
;
const
sizes
=
fontInfo
.
sizes
();
const
colors
=
fontInfo
.
colors
();
properties
.
size
=
sizes
?
sizes
[
0
]
||
20
:
20
;
...
...
dist/index.umd.js.map
View file @
5cc49b8f
{
"version"
:
3
,
"file"
:
"index.umd.js"
,
"sources"
:
[
"../src/psd-tree.js"
,
"../src/utils.js"
,
"../src/zeroing.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = window['require']('psd');
\n\n
export async function getTree(file) {\n
\t
let psd = await PSD.fromDroppedFile(file);
\n\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 hash from 'object-hash';
\n
import zlib from 'zlib';
\n\n
const relativePosPrefixMap = {\n
\t
l: {field: 'left',},
\n\t
t: {field: 'top',},
\n\t
r: {field: 'right',},
\n\t
b: {field: 'bottom',},
\n\t
h: {field: 'horizonCenter',},
\n\t
v: {field: 'verticalCenter',},
\n\t
wp: {field: 'width', },
\n\t
hp: {field: 'height', },
\n\t
lp: {field: 'left', },
\n\t
tp: {field: 'top', },
\n\t
rp: {field: 'right', },
\n\t
bp: {field: 'bottom', },
\n
};
\n\n
const offsetAll = 176;
\n\n
export async function execute(psdFile, options) {\n
\t
const tree = await getTree(psdFile);
\n\t
const {mode = 'none'} = options;
\n\t
let offset = {x: 0, y: 0};
\n\t
let cutSize = {x: 0, y: 0};
\n\t
if(mode !== 'none'){\n
\t\t
cutSize.y = offsetAll;
\n\t
}
\n\t
switch(mode){\n
\t\t
case 'top':
\n\t\t\t
offset.y = offsetAll;
\n\t\t\t
break;
\n\t\t
case 'center':
\n\t\t\t
offset.y = offsetAll / 2;
\n\t\t\t
break;
\n\t
}
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile.name, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\t
const imageHashMap = {};
\n\n\t
let {width: stageWidth, height: stageHeight} = tree;
\n\t
stageWidth -= cutSize.x || 0;
\n\t
stageHeight -= cutSize.y || 0;
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
let
{
name
}
= node;
\n\t\t
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
\n\t\t
//console.log('walk node:', name);
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
const isSecondLayer = !parent.origin.parent;
\n\n\t\t
const {width: parentWidth, height: parentHeight} = parent;
\n\n\t\t
if (name.includes('|')) {\n
\t\t\t
try {\n
\t\t\t\t
let arr = name.split('|');
\n\t\t\t\t
name = arr[0];
\n\t\t\t\t
let paramsStr = arr[1];
\n\t\t\t\t
let params = paramsStr.split(';');
\n\t\t\t\t
let relativePos = params[0];
\n\t\t\t\t
if (relativePos) {\n
\t\t\t\t\t
let items = relativePos.split(',');
\n\t\t\t\t\t
for (let item of items) {\n
\t\t\t\t\t\t
let result = item.match(/[a-zA-Z]+/);
\n\t\t\t\t\t\t
if(!result)
{
\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t
}
\n\t\t\t\t\t\t
let prefix = result[0];
\n\t\t\t\t\t\t
let mapItem = relativePosPrefixMap[prefix];
\n\t\t\t\t\t\t
if (mapItem) {\n
\t\t\t\t\t\t\t
let
{
field,
}
= mapItem;
\n\t\t\t\t\t\t\t
let value = item.substr(prefix.length);
\n\t\t\t\t\t\t\t
let hasValue = value.length > 0;
\n\t\t\t\t\t\t\t
let fieldChar = prefix[0];
\n\t\t\t\t\t\t\t
if(!hasValue){\n
\t\t\t\t\t\t\t\t
switch(fieldChar){\n
\t\t\t\t\t\t\t\t\t
case 'l':
\n\t\t\t\t\t\t\t\t\t\t
value = x - offset.x;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 't':
\n\t\t\t\t\t\t\t\t\t\t
value = y - offset.y;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'r':
\n\t\t\t\t\t\t\t\t\t\t
value = stageWidth - (x - offset.x) - width;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'b':
\n\t\t\t\t\t\t\t\t\t\t
value = stageHeight - (y - offset.y) - height;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'h':
\n\t\t\t\t\t\t\t\t\t\t
value = x + width / 2 - stageWidth / 2;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'v':
\n\t\t\t\t\t\t\t\t\t\t
value = y + height / 2 - stageHeight / 2;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
let isPercent = prefix.endsWith('p');
\n\t\t\t\t\t\t\t
if (isPercent) {\n
\t\t\t\t\t\t\t\t
if(!hasValue){\n
\t\t\t\t\t\t\t\t\t
switch(fieldChar){\n
\t\t\t\t\t\t\t\t\t\t
case 'l':
\n\t\t\t\t\t\t\t\t\t\t
case 'r':
\n\t\t\t\t\t\t\t\t\t\t\t
value /= stageWidth;
\n\t\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t\t
case 't':
\n\t\t\t\t\t\t\t\t\t\t
case 'b':
\n\t\t\t\t\t\t\t\t\t\t\t
value /= stageHeight;
\n\t\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t\t\t
value = Math.floor(value * 100);
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t\t
value += '%';
\n\t\t\t\t\t\t\t
} else {\n
\t\t\t\t\t\t\t\t
value = parseFloat(value);
\n\t\t\t\t\t\t\t\t
if (isNaN(value)) {\n
\t\t\t\t\t\t\t\t\t
value = 0;
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
properties[field] = value;
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t
}catch (e)
{
\n\t\t\t\tconsole.log(e);\n\t\t\t}\n\t\t
}
\n\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;// - (isSecondLayer ? offset.x : 0);
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;// - (isSecondLayer ? offset.y : 0);
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
const sizes = fontInfo.sizes();
\n\t\t\t
const colors = fontInfo.colors();
\n\t\t\t
properties.size = sizes ? sizes[0] || 20 : 20;
\n\t\t\t
let [r, g, b, a] = colors[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
viewNode.type = 'label';
\n\t\t\t
dealLater = false;
\n\t\t
} else if (solidColor && layer.vectorMask) {\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
const {r, g, b} = solidColor();
\n\t\t\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, 1)`;
\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
let uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
let dataUrl;
\n\t\t\t\t
try {\n
\t\t\t\t\t
let img = node.origin.toPng();
\n\t\t\t\t\t
dataUrl = img.src;
\n\t\t\t\t
} catch (e)
{
\n\n\t\t\t\t
}
\n\n\t\t\t\t
if (dataUrl) {\n
\t\t\t\t\t
let base64Data = dataUrl.replace(/^data:image
\\
/
\\
w+;base64,/,
\"\"
);
\n\t\t\t\t\t
let buffer = new Buffer(base64Data, 'base64');
\n\t\t\t\t\t
const fileNameHash = hash(buffer);
\n\t\t\t\t\t
if (imageHashMap.hasOwnProperty(fileNameHash)) {\n
\t\t\t\t\t\t
uuid = imageHashMap[fileNameHash];
\n\t\t\t\t\t
} else {\n
\t\t\t\t\t\t
imageHashMap[fileNameHash] = uuid;
\n\t\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t\t
base64Data,
\n\t\t\t\t\t\t\t
hash: fileNameHash,
\n\t\t\t\t\t\t
});
\n\t\t\t\t\t
}
\n\n\t\t\t\t\t
properties.source = 'asset://' + uuid;
\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
let data = {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
};
\n\n\t
let dataString = JSON.stringify(data);
\n\n\t
let buf = new Buffer(dataString);
\n\t
return await new Promise((resolve, reject) => {\n
\t\t
zlib.gzip(buf, function (err, res) {\n
\t\t\t
if (err)
{
\n\t\t\t\treject(err);\n\t\t\t
}
else
{
\n\t\t\t\tconsole.log(res.length);\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;;;;;;;;;;CAAA;CACA;CACA;;CAEA,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;;AAErC,CAAO,eAAe,OAAO,CAAC,IAAI,EAAE;CACpC,CAAC,IAAI,GAAG,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;;CAE3C,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;CACjB,C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,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;;CAEvC,CAAC,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;CAClC,CAAC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;CAC/C,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE;CACrC,GAAG,IAAI,GAAG,EAAE;CACZ,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;CAChB,IAAI,MAAM;CACV,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CAC5B,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;CACjB,IAAI;CACJ,GAAG,EAAC;CACJ,EAAE,CAAC;CACH,CAAC;;;;;;;;;;;;;"
}
\ No newline at end of file
{
"version"
:
3
,
"file"
:
"index.umd.js"
,
"sources"
:
[
"../src/psd-tree.js"
,
"../src/utils.js"
,
"../src/zeroing.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = window['require']('psd');
\n\n
export async function getTree(file) {\n
\t
let psd = await PSD.fromDroppedFile(file);
\n\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 hash from 'object-hash';
\n
import zlib from 'zlib';
\n\n
const relativePosPrefixMap = {\n
\t
l: {field: 'left',},
\n\t
t: {field: 'top',},
\n\t
r: {field: 'right',},
\n\t
b: {field: 'bottom',},
\n\t
h: {field: 'horizonCenter',},
\n\t
v: {field: 'verticalCenter',},
\n\t
wp: {field: 'width',},
\n\t
hp: {field: 'height',},
\n\t
lp: {field: 'left',},
\n\t
tp: {field: 'top',},
\n\t
rp: {field: 'right',},
\n\t
bp: {field: 'bottom',},
\n
};
\n\n
const offsetAll = 176;
\n\n
const enterChar = String.fromCharCode(13);
\n\n
export async function execute(psdFile, options) {\n
\t
const tree = await getTree(psdFile);
\n\t
const {mode = 'none', singleView = true} = options;
\n\t
let offset = {x: 0, y: 0};
\n\t
let cutSize = {x: 0, y: 0};
\n\t
if (mode !== 'none') {\n
\t\t
cutSize.y = offsetAll;
\n\t
}
\n\t
switch (mode) {\n
\t\t
case 'top':
\n\t\t\t
offset.y = offsetAll;
\n\t\t\t
break;
\n\t\t
case 'center':
\n\t\t\t
offset.y = offsetAll / 2;
\n\t\t\t
break;
\n\t
}
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile.name, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\t
const imageHashMap = {};
\n\n\t
let {width: stageWidth, height: stageHeight} = tree;
\n\t
stageWidth -= cutSize.x || 0;
\n\t
stageHeight -= cutSize.y || 0;
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
let
{
name
}
= node;
\n\t\t
const {x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
\n\t\t
//console.log('walk node:', name);
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
const isSecondLayer = !parent.origin.parent;
\n\n\t\t
const {width: parentWidth, height: parentHeight} = parent;
\n\n\t\t
if (name.includes('|')) {\n
\t\t\t
try {\n
\t\t\t\t
let arr = name.split('|');
\n\t\t\t\t
name = arr[0];
\n\t\t\t\t
let paramsStr = arr[1];
\n\t\t\t\t
let params = paramsStr.split(';');
\n\t\t\t\t
let relativePos = params[0];
\n\t\t\t\t
if (relativePos) {\n
\t\t\t\t\t
let items = relativePos.split(',');
\n\t\t\t\t\t
for (let item of items) {\n
\t\t\t\t\t\t
let result = item.match(/[a-zA-Z]+/);
\n\t\t\t\t\t\t
if (!result)
{
\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t
}
\n\t\t\t\t\t\t
let prefix = result[0];
\n\t\t\t\t\t\t
let mapItem = relativePosPrefixMap[prefix];
\n\t\t\t\t\t\t
if (mapItem) {\n
\t\t\t\t\t\t\t
let
{
field,
}
= mapItem;
\n\t\t\t\t\t\t\t
let value = item.substr(prefix.length);
\n\t\t\t\t\t\t\t
let hasValue = value.length > 0;
\n\t\t\t\t\t\t\t
let fieldChar = prefix[0];
\n\t\t\t\t\t\t\t
if (!hasValue) {\n
\t\t\t\t\t\t\t\t
switch (fieldChar) {\n
\t\t\t\t\t\t\t\t\t
case 'l':
\n\t\t\t\t\t\t\t\t\t\t
value = x - offset.x;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 't':
\n\t\t\t\t\t\t\t\t\t\t
value = y - offset.y;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'r':
\n\t\t\t\t\t\t\t\t\t\t
value = parentWidth - (x - offset.x) - width;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'b':
\n\t\t\t\t\t\t\t\t\t\t
value = parentHeight - (y - offset.y) - height;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'h':
\n\t\t\t\t\t\t\t\t\t\t
value = x + width / 2 - parentWidth / 2;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
case 'v':
\n\t\t\t\t\t\t\t\t\t\t
value = y + height / 2 - parentHeight / 2;
\n\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
let isPercent = prefix.endsWith('p');
\n\t\t\t\t\t\t\t
if (isPercent) {\n
\t\t\t\t\t\t\t\t
if (!hasValue) {\n
\t\t\t\t\t\t\t\t\t
switch (fieldChar) {\n
\t\t\t\t\t\t\t\t\t\t
case 'l':
\n\t\t\t\t\t\t\t\t\t\t
case 'r':
\n\t\t\t\t\t\t\t\t\t\t\t
value /= parentWidth;
\n\t\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t\t
case 't':
\n\t\t\t\t\t\t\t\t\t\t
case 'b':
\n\t\t\t\t\t\t\t\t\t\t\t
value /= parentHeight;
\n\t\t\t\t\t\t\t\t\t\t\t
break;
\n\t\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t\t\t
value = Math.floor(value * 100);
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t\t
value += '%';
\n\t\t\t\t\t\t\t
} else {\n
\t\t\t\t\t\t\t\t
value = parseFloat(value);
\n\t\t\t\t\t\t\t\t
if (isNaN(value)) {\n
\t\t\t\t\t\t\t\t\t
value = 0;
\n\t\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
}
\n\t\t\t\t\t\t\t
properties[field] = value;
\n\t\t\t\t\t\t
}
\n\t\t\t\t\t
}
\n\t\t\t\t
}
\n\t\t\t
} catch (e)
{
\n\t\t\t\tconsole.log(e);\n\t\t\t}\n\t\t
}
\n\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
let px = x;// - (!singleView && isSecondLayer ? offset.x : 0);
\n\t\t
let py = y;// - (!singleView && isSecondLayer ? offset.y : 0);
\n\t\t
if (px !== 0) {\n
\t\t\t
properties.x = px;
\n\t\t
}
\n\t\t
if (py !== 0) {\n
\t\t\t
properties.y = py;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
let text = fontInfo.textValue;
\n\t\t\t
if (text.indexOf(enterChar) < 0) { //如果未包含回车说明是多行,去掉宽度
\n\t\t\t\t
delete properties['width'];
\n\t\t\t
}
\n\t\t\t
properties.text = text;
\n\t\t\t
const sizes = fontInfo.sizes();
\n\t\t\t
const colors = fontInfo.colors();
\n\t\t\t
properties.size = sizes ? sizes[0] || 20 : 20;
\n\t\t\t
let [r, g, b, a] = colors[0];
\n\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, ${a / 255})`;
\n\t\t\t
viewNode.type = 'label';
\n\t\t\t
dealLater = false;
\n\t\t
} else if (solidColor && layer.vectorMask) {\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
const {r, g, b} = solidColor();
\n\t\t\t\t\t
properties.fillColor = `rgba(${r}, ${g}, ${b}, 1)`;
\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
let uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
let dataUrl;
\n\t\t\t\t
try {\n
\t\t\t\t\t
let img = node.origin.toPng();
\n\t\t\t\t\t
dataUrl = img.src;
\n\t\t\t\t
} catch (e)
{
\n\n\t\t\t\t
}
\n\n\t\t\t\t
if (dataUrl) {\n
\t\t\t\t\t
let base64Data = dataUrl.replace(/^data:image
\\
/
\\
w+;base64,/,
\"\"
);
\n\t\t\t\t\t
let buffer = new Buffer(base64Data, 'base64');
\n\t\t\t\t\t
const fileNameHash = hash(buffer);
\n\t\t\t\t\t
if (imageHashMap.hasOwnProperty(fileNameHash)) {\n
\t\t\t\t\t\t
uuid = imageHashMap[fileNameHash];
\n\t\t\t\t\t
} else {\n
\t\t\t\t\t\t
imageHashMap[fileNameHash] = uuid;
\n\t\t\t\t\t\t
assets.push({\n
\t\t\t\t\t\t\t
name,
\n\t\t\t\t\t\t\t
ext,
\n\t\t\t\t\t\t\t
uuid,
\n\t\t\t\t\t\t\t
base64Data,
\n\t\t\t\t\t\t\t
hash: fileNameHash,
\n\t\t\t\t\t\t
});
\n\t\t\t\t\t
}
\n\n\t\t\t\t\t
properties.source = 'asset://' + uuid;
\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
let data = {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
};
\n\n\t
let dataString = JSON.stringify(data);
\n\n\t
let buf = new Buffer(dataString);
\n\t
return await new Promise((resolve, reject) => {\n
\t\t
zlib.gzip(buf, function (err, res) {\n
\t\t\t
if (err)
{
\n\t\t\t\treject(err);\n\t\t\t
}
else
{
\n\t\t\t\tconsole.log(res.length);\n\t\t\t\tresolve(res);\n\t\t\t}\n\t\t})\n\t})\n}\n"],"names":[],"mappings":";;;;;;;;;;;;CAAA;CACA;CACA;;CAEA,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;;AAErC,CAAO,eAAe,OAAO,CAAC,IAAI,EAAE;CACpC,CAAC,IAAI,GAAG,GAAG,MAAM,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;;CAE3C,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,EA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OAAO,EAAE,MAAM,KAAK;CAC/C,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,EAAE,GAAG,EAAE;CACrC,GAAG,IAAI,GAAG,EAAE;CACZ,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;CAChB,IAAI,MAAM;CACV,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CAC5B,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;CACjB,IAAI;CACJ,GAAG,EAAC;CACJ,EAAE,CAAC;CACH,CAAC;;;;;;;;;;;;;"
}
\ No newline at end of file
src/zeroing.js
View file @
5cc49b8f
...
...
@@ -19,25 +19,27 @@ const relativePosPrefixMap = {
b
:
{
field
:
'bottom'
,},
h
:
{
field
:
'horizonCenter'
,},
v
:
{
field
:
'verticalCenter'
,},
wp
:
{
field
:
'width'
,
},
hp
:
{
field
:
'height'
,
},
lp
:
{
field
:
'left'
,
},
tp
:
{
field
:
'top'
,
},
rp
:
{
field
:
'right'
,
},
bp
:
{
field
:
'bottom'
,
},
wp
:
{
field
:
'width'
,},
hp
:
{
field
:
'height'
,},
lp
:
{
field
:
'left'
,},
tp
:
{
field
:
'top'
,},
rp
:
{
field
:
'right'
,},
bp
:
{
field
:
'bottom'
,},
};
const
offsetAll
=
176
;
const
enterChar
=
String
.
fromCharCode
(
13
);
export
async
function
execute
(
psdFile
,
options
)
{
const
tree
=
await
getTree
(
psdFile
);
const
{
mode
=
'none'
}
=
options
;
const
{
mode
=
'none'
,
singleView
=
true
}
=
options
;
let
offset
=
{
x
:
0
,
y
:
0
};
let
cutSize
=
{
x
:
0
,
y
:
0
};
if
(
mode
!==
'none'
)
{
if
(
mode
!==
'none'
)
{
cutSize
.
y
=
offsetAll
;
}
switch
(
mode
)
{
switch
(
mode
)
{
case
'top'
:
offset
.
y
=
offsetAll
;
break
;
...
...
@@ -81,7 +83,7 @@ export async function execute(psdFile, options) {
let
items
=
relativePos
.
split
(
','
);
for
(
let
item
of
items
)
{
let
result
=
item
.
match
(
/
[
a-zA-Z
]
+/
);
if
(
!
result
)
{
if
(
!
result
)
{
continue
;
}
let
prefix
=
result
[
0
];
...
...
@@ -91,8 +93,8 @@ export async function execute(psdFile, options) {
let
value
=
item
.
substr
(
prefix
.
length
);
let
hasValue
=
value
.
length
>
0
;
let
fieldChar
=
prefix
[
0
];
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
case
'l'
:
value
=
x
-
offset
.
x
;
break
;
...
...
@@ -100,30 +102,30 @@ export async function execute(psdFile, options) {
value
=
y
-
offset
.
y
;
break
;
case
'r'
:
value
=
stage
Width
-
(
x
-
offset
.
x
)
-
width
;
value
=
parent
Width
-
(
x
-
offset
.
x
)
-
width
;
break
;
case
'b'
:
value
=
stage
Height
-
(
y
-
offset
.
y
)
-
height
;
value
=
parent
Height
-
(
y
-
offset
.
y
)
-
height
;
break
;
case
'h'
:
value
=
x
+
width
/
2
-
stage
Width
/
2
;
value
=
x
+
width
/
2
-
parent
Width
/
2
;
break
;
case
'v'
:
value
=
y
+
height
/
2
-
stage
Height
/
2
;
value
=
y
+
height
/
2
-
parent
Height
/
2
;
break
;
}
}
let
isPercent
=
prefix
.
endsWith
(
'p'
);
if
(
isPercent
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
case
'l'
:
case
'r'
:
value
/=
stage
Width
;
value
/=
parent
Width
;
break
;
case
't'
:
case
'b'
:
value
/=
stage
Height
;
value
/=
parent
Height
;
break
;
}
value
=
Math
.
floor
(
value
*
100
);
...
...
@@ -139,7 +141,7 @@ export async function execute(psdFile, options) {
}
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
);
}
}
...
...
@@ -150,16 +152,22 @@ export async function execute(psdFile, options) {
uuid
:
generateUUID
(),
};
let
dealLater
=
true
;
if
(
x
!==
0
)
{
properties
.
x
=
x
;
// - (isSecondLayer ? offset.x : 0);
let
px
=
x
;
// - (!singleView && isSecondLayer ? offset.x : 0);
let
py
=
y
;
// - (!singleView && isSecondLayer ? offset.y : 0);
if
(
px
!==
0
)
{
properties
.
x
=
px
;
}
if
(
y
!==
0
)
{
properties
.
y
=
y
;
// - (isSecondLayer ? offset.y : 0)
;
if
(
p
y
!==
0
)
{
properties
.
y
=
py
;
}
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
properties
.
text
=
fontInfo
.
textValue
;
let
text
=
fontInfo
.
textValue
;
if
(
text
.
indexOf
(
enterChar
)
<
0
)
{
//如果未包含回车说明是多行,去掉宽度
delete
properties
[
'width'
];
}
properties
.
text
=
text
;
const
sizes
=
fontInfo
.
sizes
();
const
colors
=
fontInfo
.
colors
();
properties
.
size
=
sizes
?
sizes
[
0
]
||
20
:
20
;
...
...
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