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
005b9d53
Commit
005b9d53
authored
Nov 19, 2020
by
张九刚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改node版本
parent
21a0f975
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
12 deletions
+45
-12
zeroing.js
src/zeroing.js
+45
-12
No files found.
src/zeroing.js
View file @
005b9d53
...
...
@@ -11,7 +11,7 @@ var Color = require('color');
var
generateUUID
=
require
(
'uuid/v4'
);
var
fs
=
require
(
"fs-extra"
);
var
hash
=
require
(
'object-hash'
);
var
zlib
=
require
(
'zlib'
);
var
zlib
=
require
(
'zlib'
);
const
relativePosPrefixMap
=
{
l
:
{
field
:
'left'
,
},
t
:
{
field
:
'top'
,
},
...
...
@@ -29,8 +29,16 @@ const relativePosPrefixMap = {
const
offsetAll
=
176
;
async
function
execute
(
psdFile
,
options
=
{})
{
console
.
log
(
"psdFile:"
,
psdFile
);
async
function
execute
(
psdFile
,
options
)
{
console
.
log
(
"psdFile:"
,
psdFile
);
const
{
imagesPath
}
=
options
;
if
(
!
imagesPath
)
{
console
.
log
(
"没有指定cache目录"
);
}
const
tree
=
await
getTree
(
psdFile
);
const
{
mode
=
'none'
,
singleView
=
true
}
=
options
;
...
...
@@ -53,7 +61,7 @@ async function execute(psdFile, options = {}) {
let
viewRoot
=
{
name
:
path
.
basename
(
psdFile
,
'.psd'
),
componentNam
e
:
'Div'
,
nodeTyp
e
:
'Div'
,
uuid
:
generateUUID
(),
};
...
...
@@ -195,7 +203,7 @@ async function execute(psdFile, options = {}) {
properties
.
style
.
fontSize
=
sizes
?
sizes
[
0
]
||
20
:
20
;
let
[
r
,
g
,
b
,
a
]
=
colors
[
0
];
properties
.
style
.
color
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
viewNode
.
componentNam
e
=
'Label'
;
viewNode
.
nodeTyp
e
=
'Label'
;
dealLater
=
false
;
}
else
if
(
solidColor
&&
layer
.
vectorMask
)
{
let
paths
=
layer
.
vectorMask
().
paths
;
...
...
@@ -208,7 +216,7 @@ async function execute(psdFile, options = {}) {
}
}
if
(
isRect
)
{
viewNode
.
componentNam
e
=
'Div'
;
viewNode
.
nodeTyp
e
=
'Div'
;
const
{
r
,
g
,
b
}
=
solidColor
();
properties
.
style
.
backgroundColor
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
, 1)`
;
dealLater
=
false
;
...
...
@@ -218,24 +226,28 @@ async function execute(psdFile, options = {}) {
if
(
dealLater
)
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
viewNode
.
componentNam
e
=
'Div'
;
viewNode
.
nodeTyp
e
=
'Div'
;
}
else
{
viewNode
.
componentNam
e
=
'Image'
;
viewNode
.
nodeTyp
e
=
'Image'
;
let
uuid
=
generateUUID
();
const
ext
=
'.png'
;
let
dataUrl
;
let
buffer
;
try
{
let
img
=
node
.
origin
.
toPng
();
dataUrl
=
img
.
src
;
const
imageFilePath
=
path
.
join
(
imagesPath
,
uuid
+
ext
);
buffer
=
await
savePng
(
img
,
imageFilePath
).
catch
(
e
=>
{
});
dataUrl
=
buffer
.
toString
(
'base64'
);
}
catch
(
e
)
{
}
if
(
dataUrl
)
{
// let base64Data = dataUrl.replace(/^data:image\/\w+;base64,/, "");
// let buffer = new Buffer.from(base64Data, 'base64');
let
base64Data
=
dataUrl
.
replace
(
/^data:image
\/\w
+;base64,/
,
""
);
let
buffer
=
new
Buffer
(
base64Data
,
'base64'
);
const
fileNameHash
=
hash
(
buffer
);
if
(
imageHashMap
.
hasOwnProperty
(
fileNameHash
))
{
uuid
=
imageHashMap
[
fileNameHash
];
...
...
@@ -263,6 +275,11 @@ async function execute(psdFile, options = {}) {
node
.
view
=
viewNode
;
});
if
(
viewRoot
.
children
&&
viewRoot
.
children
.
length
)
{
viewRoot
.
children
.
map
(
item
=>
{
item
.
viewType
=
'Page'
})
}
let
data
=
{
pluginVersion
:
"0.0.1"
,
reference
:
"psd"
,
...
...
@@ -285,6 +302,22 @@ async function execute(psdFile, options = {}) {
})
}
function
savePng
(
png
,
output
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
buffer
,
buffers
=
[];
png
.
pack
()
.
on
(
'error'
,
reject
)
.
on
(
'data'
,
(
data
)
=>
buffers
.
push
(
data
))
.
on
(
'end'
,
()
=>
{
buffer
=
Buffer
.
concat
(
buffers
)
})
.
pipe
(
fs
.
createWriteStream
(
output
))
.
on
(
'finish'
,
()
=>
{
resolve
(
buffer
);
});
});
}
...
...
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