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
05b0ebd5
Commit
05b0ebd5
authored
Apr 22, 2020
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加相对位置的解析
parent
3b226df5
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
152 additions
and
55 deletions
+152
-55
index.es.js
dist/index.es.js
+37
-13
index.es.js.map
dist/index.es.js.map
+1
-1
index.js
dist/index.js
+37
-13
index.js.map
dist/index.js.map
+1
-1
index.umd.js
dist/index.umd.js
+37
-13
index.umd.js.map
dist/index.umd.js.map
+1
-1
package.json
package.json
+1
-0
zeroing.js
src/zeroing.js
+37
-13
No files found.
dist/index.es.js
View file @
05b0ebd5
...
@@ -65,6 +65,17 @@ async function walkNode(node, callback, includeSelf = false) {
...
@@ -65,6 +65,17 @@ async function walkNode(node, callback, includeSelf = false) {
* 导出zeroing的视图
* 导出zeroing的视图
*/
*/
const
relativePosPrefixMap
=
{
l
:
'left'
,
t
:
'top'
,
r
:
'right'
,
b
:
'bottom'
,
h
:
'horizonCenter'
,
v
:
'verticalCenter'
,
wp
:
'percentWidth'
,
hp
:
'percentHeight'
,
};
async
function
execute
(
psdFile
,
options
)
{
async
function
execute
(
psdFile
,
options
)
{
const
tree
=
await
getTree
(
psdFile
);
const
tree
=
await
getTree
(
psdFile
);
...
@@ -78,11 +89,31 @@ async function execute(psdFile, options) {
...
@@ -78,11 +89,31 @@ async function execute(psdFile, options) {
const
imageHashMap
=
{};
const
imageHashMap
=
{};
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
let
{
name
}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
console
.
log
(
'walk node:'
,
name
);
console
.
log
(
'walk node:'
,
name
);
let
properties
=
{
let
properties
=
{
width
,
height
,
alpha
,
visible
,
width
,
height
,
alpha
,
visible
,
};
};
if
(
name
.
includes
(
'|'
))
{
let
arr
=
name
.
split
(
'|'
);
name
=
arr
[
0
];
let
paramsStr
=
arr
[
0
];
let
params
=
paramsStr
.
split
(
';'
);
let
relativePos
=
params
[
0
];
if
(
relativePos
)
{
let
items
=
relativePos
.
split
(
','
);
for
(
let
item
of
items
)
{
let
prefix
=
item
[
0
];
let
field
=
relativePosPrefixMap
[
prefix
];
if
(
field
)
{
properties
[
field
]
=
parseFloat
(
item
.
substr
(
1
));
}
}
}
}
let
viewNode
=
{
let
viewNode
=
{
name
,
name
,
properties
,
properties
,
...
@@ -98,19 +129,12 @@ async function execute(psdFile, options) {
...
@@ -98,19 +129,12 @@ async function execute(psdFile, options) {
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
text
=
fontInfo
.
textValue
;
const
sizes
=
fontInfo
.
sizes
();
const
sizes
=
fontInfo
.
sizes
();
const
colors
=
fontInfo
.
colors
();
const
colors
=
fontInfo
.
colors
();
properties
.
size
=
sizes
?
sizes
[
0
]
||
20
:
20
;
properties
.
size
=
sizes
?
sizes
[
0
]
||
20
:
20
;
let
[
r
,
g
,
b
,
a
]
=
colors
[
0
];
let
[
r
,
g
,
b
,
a
]
=
colors
[
0
];
properties
.
fillColor
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
properties
.
fillColor
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
/*properties.textflow = {
fonts, styles, RunLengthArray,
};*/
viewNode
.
type
=
'label'
;
viewNode
.
type
=
'label'
;
dealLater
=
false
;
dealLater
=
false
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
...
@@ -147,7 +171,7 @@ async function execute(psdFile, options) {
...
@@ -147,7 +171,7 @@ async function execute(psdFile, options) {
try
{
try
{
let
img
=
node
.
origin
.
toPng
();
let
img
=
node
.
origin
.
toPng
();
dataUrl
=
img
.
src
;
dataUrl
=
img
.
src
;
}
catch
(
e
)
{
}
catch
(
e
)
{
}
}
...
@@ -191,11 +215,11 @@ async function execute(psdFile, options) {
...
@@ -191,11 +215,11 @@ async function execute(psdFile, options) {
console
.
log
(
dataString
.
length
);
console
.
log
(
dataString
.
length
);
let
buf
=
new
Buffer
(
dataString
);
let
buf
=
new
Buffer
(
dataString
);
return
await
new
Promise
((
resolve
,
reject
)
=>
{
return
await
new
Promise
((
resolve
,
reject
)
=>
{
zlib
.
gzip
(
buf
,
function
(
err
,
res
)
{
zlib
.
gzip
(
buf
,
function
(
err
,
res
)
{
if
(
err
)
{
if
(
err
)
{
reject
(
err
);
reject
(
err
);
}
else
{
}
else
{
console
.
log
(
res
.
length
);
console
.
log
(
res
.
length
);
resolve
(
res
);
resolve
(
res
);
}
}
...
...
dist/index.es.js.map
View file @
05b0ebd5
This diff is collapsed.
Click to expand it.
dist/index.js
View file @
05b0ebd5
...
@@ -71,6 +71,17 @@ async function walkNode(node, callback, includeSelf = false) {
...
@@ -71,6 +71,17 @@ async function walkNode(node, callback, includeSelf = false) {
* 导出zeroing的视图
* 导出zeroing的视图
*/
*/
const
relativePosPrefixMap
=
{
l
:
'left'
,
t
:
'top'
,
r
:
'right'
,
b
:
'bottom'
,
h
:
'horizonCenter'
,
v
:
'verticalCenter'
,
wp
:
'percentWidth'
,
hp
:
'percentHeight'
,
};
async
function
execute
(
psdFile
,
options
)
{
async
function
execute
(
psdFile
,
options
)
{
const
tree
=
await
getTree
(
psdFile
);
const
tree
=
await
getTree
(
psdFile
);
...
@@ -84,11 +95,31 @@ async function execute(psdFile, options) {
...
@@ -84,11 +95,31 @@ async function execute(psdFile, options) {
const
imageHashMap
=
{};
const
imageHashMap
=
{};
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
let
{
name
}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
console
.
log
(
'walk node:'
,
name
);
console
.
log
(
'walk node:'
,
name
);
let
properties
=
{
let
properties
=
{
width
,
height
,
alpha
,
visible
,
width
,
height
,
alpha
,
visible
,
};
};
if
(
name
.
includes
(
'|'
))
{
let
arr
=
name
.
split
(
'|'
);
name
=
arr
[
0
];
let
paramsStr
=
arr
[
0
];
let
params
=
paramsStr
.
split
(
';'
);
let
relativePos
=
params
[
0
];
if
(
relativePos
)
{
let
items
=
relativePos
.
split
(
','
);
for
(
let
item
of
items
)
{
let
prefix
=
item
[
0
];
let
field
=
relativePosPrefixMap
[
prefix
];
if
(
field
)
{
properties
[
field
]
=
parseFloat
(
item
.
substr
(
1
));
}
}
}
}
let
viewNode
=
{
let
viewNode
=
{
name
,
name
,
properties
,
properties
,
...
@@ -104,19 +135,12 @@ async function execute(psdFile, options) {
...
@@ -104,19 +135,12 @@ async function execute(psdFile, options) {
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
text
=
fontInfo
.
textValue
;
const
sizes
=
fontInfo
.
sizes
();
const
sizes
=
fontInfo
.
sizes
();
const
colors
=
fontInfo
.
colors
();
const
colors
=
fontInfo
.
colors
();
properties
.
size
=
sizes
?
sizes
[
0
]
||
20
:
20
;
properties
.
size
=
sizes
?
sizes
[
0
]
||
20
:
20
;
let
[
r
,
g
,
b
,
a
]
=
colors
[
0
];
let
[
r
,
g
,
b
,
a
]
=
colors
[
0
];
properties
.
fillColor
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
properties
.
fillColor
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
/*properties.textflow = {
fonts, styles, RunLengthArray,
};*/
viewNode
.
type
=
'label'
;
viewNode
.
type
=
'label'
;
dealLater
=
false
;
dealLater
=
false
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
...
@@ -153,7 +177,7 @@ async function execute(psdFile, options) {
...
@@ -153,7 +177,7 @@ async function execute(psdFile, options) {
try
{
try
{
let
img
=
node
.
origin
.
toPng
();
let
img
=
node
.
origin
.
toPng
();
dataUrl
=
img
.
src
;
dataUrl
=
img
.
src
;
}
catch
(
e
)
{
}
catch
(
e
)
{
}
}
...
@@ -197,11 +221,11 @@ async function execute(psdFile, options) {
...
@@ -197,11 +221,11 @@ async function execute(psdFile, options) {
console
.
log
(
dataString
.
length
);
console
.
log
(
dataString
.
length
);
let
buf
=
new
Buffer
(
dataString
);
let
buf
=
new
Buffer
(
dataString
);
return
await
new
Promise
((
resolve
,
reject
)
=>
{
return
await
new
Promise
((
resolve
,
reject
)
=>
{
zlib
.
gzip
(
buf
,
function
(
err
,
res
)
{
zlib
.
gzip
(
buf
,
function
(
err
,
res
)
{
if
(
err
)
{
if
(
err
)
{
reject
(
err
);
reject
(
err
);
}
else
{
}
else
{
console
.
log
(
res
.
length
);
console
.
log
(
res
.
length
);
resolve
(
res
);
resolve
(
res
);
}
}
...
...
dist/index.js.map
View file @
05b0ebd5
This diff is collapsed.
Click to expand it.
dist/index.umd.js
View file @
05b0ebd5
...
@@ -71,6 +71,17 @@
...
@@ -71,6 +71,17 @@
* 导出zeroing的视图
* 导出zeroing的视图
*/
*/
const
relativePosPrefixMap
=
{
l
:
'left'
,
t
:
'top'
,
r
:
'right'
,
b
:
'bottom'
,
h
:
'horizonCenter'
,
v
:
'verticalCenter'
,
wp
:
'percentWidth'
,
hp
:
'percentHeight'
,
};
async
function
execute
(
psdFile
,
options
)
{
async
function
execute
(
psdFile
,
options
)
{
const
tree
=
await
getTree
(
psdFile
);
const
tree
=
await
getTree
(
psdFile
);
...
@@ -84,11 +95,31 @@
...
@@ -84,11 +95,31 @@
const
imageHashMap
=
{};
const
imageHashMap
=
{};
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
let
{
name
}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
console
.
log
(
'walk node:'
,
name
);
console
.
log
(
'walk node:'
,
name
);
let
properties
=
{
let
properties
=
{
width
,
height
,
alpha
,
visible
,
width
,
height
,
alpha
,
visible
,
};
};
if
(
name
.
includes
(
'|'
))
{
let
arr
=
name
.
split
(
'|'
);
name
=
arr
[
0
];
let
paramsStr
=
arr
[
0
];
let
params
=
paramsStr
.
split
(
';'
);
let
relativePos
=
params
[
0
];
if
(
relativePos
)
{
let
items
=
relativePos
.
split
(
','
);
for
(
let
item
of
items
)
{
let
prefix
=
item
[
0
];
let
field
=
relativePosPrefixMap
[
prefix
];
if
(
field
)
{
properties
[
field
]
=
parseFloat
(
item
.
substr
(
1
));
}
}
}
}
let
viewNode
=
{
let
viewNode
=
{
name
,
name
,
properties
,
properties
,
...
@@ -104,19 +135,12 @@
...
@@ -104,19 +135,12 @@
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
text
=
fontInfo
.
textValue
;
const
sizes
=
fontInfo
.
sizes
();
const
sizes
=
fontInfo
.
sizes
();
const
colors
=
fontInfo
.
colors
();
const
colors
=
fontInfo
.
colors
();
properties
.
size
=
sizes
?
sizes
[
0
]
||
20
:
20
;
properties
.
size
=
sizes
?
sizes
[
0
]
||
20
:
20
;
let
[
r
,
g
,
b
,
a
]
=
colors
[
0
];
let
[
r
,
g
,
b
,
a
]
=
colors
[
0
];
properties
.
fillColor
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
properties
.
fillColor
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
/*properties.textflow = {
fonts, styles, RunLengthArray,
};*/
viewNode
.
type
=
'label'
;
viewNode
.
type
=
'label'
;
dealLater
=
false
;
dealLater
=
false
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
...
@@ -153,7 +177,7 @@
...
@@ -153,7 +177,7 @@
try
{
try
{
let
img
=
node
.
origin
.
toPng
();
let
img
=
node
.
origin
.
toPng
();
dataUrl
=
img
.
src
;
dataUrl
=
img
.
src
;
}
catch
(
e
)
{
}
catch
(
e
)
{
}
}
...
@@ -197,11 +221,11 @@
...
@@ -197,11 +221,11 @@
console
.
log
(
dataString
.
length
);
console
.
log
(
dataString
.
length
);
let
buf
=
new
Buffer
(
dataString
);
let
buf
=
new
Buffer
(
dataString
);
return
await
new
Promise
((
resolve
,
reject
)
=>
{
return
await
new
Promise
((
resolve
,
reject
)
=>
{
zlib
.
gzip
(
buf
,
function
(
err
,
res
)
{
zlib
.
gzip
(
buf
,
function
(
err
,
res
)
{
if
(
err
)
{
if
(
err
)
{
reject
(
err
);
reject
(
err
);
}
else
{
}
else
{
console
.
log
(
res
.
length
);
console
.
log
(
res
.
length
);
resolve
(
res
);
resolve
(
res
);
}
}
...
...
dist/index.umd.js.map
View file @
05b0ebd5
This diff is collapsed.
Click to expand it.
package.json
View file @
05b0ebd5
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
"module"
:
"dist/index.es.js"
,
"module"
:
"dist/index.es.js"
,
"license"
:
"
MIT
"
,
"license"
:
"
MIT
"
,
"scripts"
:
{
"scripts"
:
{
"dev"
:
"rollup -c -w"
,
"build"
:
"rollup -c"
"build"
:
"rollup -c"
},
},
"dependencies"
:
{
"dependencies"
:
{
...
...
src/zeroing.js
View file @
05b0ebd5
...
@@ -12,6 +12,17 @@ import generateUUID from 'uuid/v4'
...
@@ -12,6 +12,17 @@ import generateUUID from 'uuid/v4'
import
hash
from
'object-hash'
;
import
hash
from
'object-hash'
;
import
zlib
from
'zlib'
;
import
zlib
from
'zlib'
;
const
relativePosPrefixMap
=
{
l
:
'left'
,
t
:
'top'
,
r
:
'right'
,
b
:
'bottom'
,
h
:
'horizonCenter'
,
v
:
'verticalCenter'
,
wp
:
'percentWidth'
,
hp
:
'percentHeight'
,
};
export
async
function
execute
(
psdFile
,
options
)
{
export
async
function
execute
(
psdFile
,
options
)
{
const
tree
=
await
getTree
(
psdFile
);
const
tree
=
await
getTree
(
psdFile
);
...
@@ -25,11 +36,31 @@ export async function execute(psdFile, options) {
...
@@ -25,11 +36,31 @@ export async function execute(psdFile, options) {
const
imageHashMap
=
{};
const
imageHashMap
=
{};
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
let
{
name
}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
console
.
log
(
'walk node:'
,
name
);
console
.
log
(
'walk node:'
,
name
);
let
properties
=
{
let
properties
=
{
width
,
height
,
alpha
,
visible
,
width
,
height
,
alpha
,
visible
,
};
};
if
(
name
.
includes
(
'|'
))
{
let
arr
=
name
.
split
(
'|'
);
name
=
arr
[
0
];
let
paramsStr
=
arr
[
0
];
let
params
=
paramsStr
.
split
(
';'
);
let
relativePos
=
params
[
0
];
if
(
relativePos
)
{
let
items
=
relativePos
.
split
(
','
);
for
(
let
item
of
items
)
{
let
prefix
=
item
[
0
];
let
field
=
relativePosPrefixMap
[
prefix
];
if
(
field
)
{
properties
[
field
]
=
parseFloat
(
item
.
substr
(
1
));
}
}
}
}
let
viewNode
=
{
let
viewNode
=
{
name
,
name
,
properties
,
properties
,
...
@@ -45,19 +76,12 @@ export async function execute(psdFile, options) {
...
@@ -45,19 +76,12 @@ export async function execute(psdFile, options) {
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
//const fonts = fontInfo.fonts();
//const styles = fontInfo.styles();
//const {RunLengthArray} = fontInfo.engineData.EngineDict.StyleRun;
properties
.
text
=
fontInfo
.
textValue
;
properties
.
text
=
fontInfo
.
textValue
;
const
sizes
=
fontInfo
.
sizes
();
const
sizes
=
fontInfo
.
sizes
();
const
colors
=
fontInfo
.
colors
();
const
colors
=
fontInfo
.
colors
();
properties
.
size
=
sizes
?
sizes
[
0
]
||
20
:
20
;
properties
.
size
=
sizes
?
sizes
[
0
]
||
20
:
20
;
let
[
r
,
g
,
b
,
a
]
=
colors
[
0
];
let
[
r
,
g
,
b
,
a
]
=
colors
[
0
];
properties
.
fillColor
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
properties
.
fillColor
=
`rgba(
${
r
}
,
${
g
}
,
${
b
}
,
${
a
/
255
}
)`
;
/*properties.textflow = {
fonts, styles, RunLengthArray,
};*/
viewNode
.
type
=
'label'
;
viewNode
.
type
=
'label'
;
dealLater
=
false
;
dealLater
=
false
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
...
@@ -94,7 +118,7 @@ export async function execute(psdFile, options) {
...
@@ -94,7 +118,7 @@ export async function execute(psdFile, options) {
try
{
try
{
let
img
=
node
.
origin
.
toPng
();
let
img
=
node
.
origin
.
toPng
();
dataUrl
=
img
.
src
;
dataUrl
=
img
.
src
;
}
catch
(
e
)
{
}
catch
(
e
)
{
}
}
...
@@ -138,11 +162,11 @@ export async function execute(psdFile, options) {
...
@@ -138,11 +162,11 @@ export async function execute(psdFile, options) {
console
.
log
(
dataString
.
length
);
console
.
log
(
dataString
.
length
);
let
buf
=
new
Buffer
(
dataString
);
let
buf
=
new
Buffer
(
dataString
);
return
await
new
Promise
((
resolve
,
reject
)
=>
{
return
await
new
Promise
((
resolve
,
reject
)
=>
{
zlib
.
gzip
(
buf
,
function
(
err
,
res
)
{
zlib
.
gzip
(
buf
,
function
(
err
,
res
)
{
if
(
err
)
{
if
(
err
)
{
reject
(
err
);
reject
(
err
);
}
else
{
}
else
{
console
.
log
(
res
.
length
);
console
.
log
(
res
.
length
);
resolve
(
res
);
resolve
(
res
);
}
}
...
...
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