Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
psd-parse
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
psd-parse
Commits
30e0cbff
Commit
30e0cbff
authored
Sep 27, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
节点增加uuid字段
parent
4a712d00
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
115 additions
and
37 deletions
+115
-37
index.es.js
dist/index.es.js
+36
-10
index.es.js.map
dist/index.es.js.map
+1
-1
index.js
dist/index.js
+36
-10
index.js.map
dist/index.js.map
+1
-1
index.umd.js
dist/index.umd.js
+40
-14
index.umd.js.map
dist/index.umd.js.map
+1
-1
No files found.
dist/index.es.js
View file @
30e0cbff
...
@@ -3,6 +3,7 @@ import path from 'path';
...
@@ -3,6 +3,7 @@ import path from 'path';
import
fs
from
'fs-extra'
;
import
fs
from
'fs-extra'
;
import
Color
from
'color'
;
import
Color
from
'color'
;
import
generateUUID
from
'uuid/v4'
;
import
generateUUID
from
'uuid/v4'
;
import
hash
from
'object-hash'
;
/**
/**
* Created by rockyl on 2019-08-09.
* Created by rockyl on 2019-08-09.
...
@@ -228,18 +229,20 @@ async function execute$1(psdFile, options) {
...
@@ -228,18 +229,20 @@ async function execute$1(psdFile, options) {
let
viewRoot
=
{
let
viewRoot
=
{
name
:
path
.
basename
(
psdFile
,
'.psd'
),
name
:
path
.
basename
(
psdFile
,
'.psd'
),
type
:
'node'
,
type
:
'node'
,
uuid
:
generateUUID
(),
};
};
const
assets
=
[];
const
assets
=
[];
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
let
properties
=
{
let
properties
=
{
width
,
height
,
alpha
,
visible
,
width
,
height
,
alpha
,
visible
,
};
};
let
viewNode
=
{
let
viewNode
=
{
name
:
node
.
name
,
name
,
properties
,
properties
,
uuid
:
generateUUID
(),
};
};
if
(
x
!==
0
)
{
if
(
x
!==
0
)
{
properties
.
x
=
x
;
properties
.
x
=
x
;
...
@@ -248,8 +251,8 @@ async function execute$1(psdFile, options) {
...
@@ -248,8 +251,8 @@ async function execute$1(psdFile, options) {
properties
.
y
=
y
;
properties
.
y
=
y
;
}
}
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
const
fonts
=
fontInfo
.
fonts
();
const
fonts
=
fontInfo
.
fonts
();
const
styles
=
fontInfo
.
styles
();
const
styles
=
fontInfo
.
styles
();
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
...
@@ -259,16 +262,16 @@ async function execute$1(psdFile, options) {
...
@@ -259,16 +262,16 @@ async function execute$1(psdFile, options) {
fonts
,
styles
,
RunLengthArray
,
fonts
,
styles
,
RunLengthArray
,
};
};
viewNode
.
type
=
'label'
;
viewNode
.
type
=
'label'
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
const
{
r
,
g
,
b
}
=
solidColor
();
const
{
r
,
g
,
b
}
=
solidColor
();
let
color
=
Color
({
r
,
g
,
b
});
let
color
=
Color
({
r
,
g
,
b
});
viewNode
.
type
=
'rect'
;
viewNode
.
type
=
'rect'
;
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
}
else
{
}
else
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
viewNode
.
type
=
'node'
;
viewNode
.
type
=
'node'
;
}
else
{
}
else
{
viewNode
.
type
=
'image'
;
viewNode
.
type
=
'image'
;
const
uuid
=
generateUUID
();
const
uuid
=
generateUUID
();
...
@@ -278,12 +281,19 @@ async function execute$1(psdFile, options) {
...
@@ -278,12 +281,19 @@ async function execute$1(psdFile, options) {
const
imageFilePath
=
path
.
join
(
imagesPath
,
uuid
+
ext
);
const
imageFilePath
=
path
.
join
(
imagesPath
,
uuid
+
ext
);
await
fs
.
ensureDir
(
path
.
dirname
(
imageFilePath
));
await
fs
.
ensureDir
(
path
.
dirname
(
imageFilePath
));
await
node
.
origin
.
saveAsPng
(
imageFilePath
);
let
png
=
node
.
origin
.
toPng
();
let
buffer
=
await
savePng
(
png
,
imageFilePath
);
//await node.origin.saveAsPng(imageFilePath);
const
hashFileName
=
hash
(
buffer
);
const
hashFilePath
=
path
.
join
(
imagesPath
,
hashFileName
+
ext
);
await
fs
.
rename
(
imageFilePath
,
hashFilePath
);
assets
.
push
({
assets
.
push
({
name
:
uuid
,
name
,
ext
,
ext
,
uuid
,
uuid
,
hash
:
hashFileName
,
});
});
}
}
}
}
...
@@ -303,5 +313,21 @@ async function execute$1(psdFile, options) {
...
@@ -303,5 +313,21 @@ async function execute$1(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
);
});
});
}
export
{
getTree
,
execute
as
toEgret
,
execute$1
as
toZeroing
};
export
{
getTree
,
execute
as
toEgret
,
execute$1
as
toZeroing
};
//# sourceMappingURL=index.es.js.map
//# sourceMappingURL=index.es.js.map
dist/index.es.js.map
View file @
30e0cbff
This diff is collapsed.
Click to expand it.
dist/index.js
View file @
30e0cbff
...
@@ -9,6 +9,7 @@ var path = _interopDefault(require('path'));
...
@@ -9,6 +9,7 @@ var path = _interopDefault(require('path'));
var
fs
=
_interopDefault
(
require
(
'fs-extra'
));
var
fs
=
_interopDefault
(
require
(
'fs-extra'
));
var
Color
=
_interopDefault
(
require
(
'color'
));
var
Color
=
_interopDefault
(
require
(
'color'
));
var
generateUUID
=
_interopDefault
(
require
(
'uuid/v4'
));
var
generateUUID
=
_interopDefault
(
require
(
'uuid/v4'
));
var
hash
=
_interopDefault
(
require
(
'object-hash'
));
/**
/**
* Created by rockyl on 2019-08-09.
* Created by rockyl on 2019-08-09.
...
@@ -234,18 +235,20 @@ async function execute$1(psdFile, options) {
...
@@ -234,18 +235,20 @@ async function execute$1(psdFile, options) {
let
viewRoot
=
{
let
viewRoot
=
{
name
:
path
.
basename
(
psdFile
,
'.psd'
),
name
:
path
.
basename
(
psdFile
,
'.psd'
),
type
:
'node'
,
type
:
'node'
,
uuid
:
generateUUID
(),
};
};
const
assets
=
[];
const
assets
=
[];
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
let
properties
=
{
let
properties
=
{
width
,
height
,
alpha
,
visible
,
width
,
height
,
alpha
,
visible
,
};
};
let
viewNode
=
{
let
viewNode
=
{
name
:
node
.
name
,
name
,
properties
,
properties
,
uuid
:
generateUUID
(),
};
};
if
(
x
!==
0
)
{
if
(
x
!==
0
)
{
properties
.
x
=
x
;
properties
.
x
=
x
;
...
@@ -254,8 +257,8 @@ async function execute$1(psdFile, options) {
...
@@ -254,8 +257,8 @@ async function execute$1(psdFile, options) {
properties
.
y
=
y
;
properties
.
y
=
y
;
}
}
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
const
fonts
=
fontInfo
.
fonts
();
const
fonts
=
fontInfo
.
fonts
();
const
styles
=
fontInfo
.
styles
();
const
styles
=
fontInfo
.
styles
();
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
...
@@ -265,16 +268,16 @@ async function execute$1(psdFile, options) {
...
@@ -265,16 +268,16 @@ async function execute$1(psdFile, options) {
fonts
,
styles
,
RunLengthArray
,
fonts
,
styles
,
RunLengthArray
,
};
};
viewNode
.
type
=
'label'
;
viewNode
.
type
=
'label'
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
const
{
r
,
g
,
b
}
=
solidColor
();
const
{
r
,
g
,
b
}
=
solidColor
();
let
color
=
Color
({
r
,
g
,
b
});
let
color
=
Color
({
r
,
g
,
b
});
viewNode
.
type
=
'rect'
;
viewNode
.
type
=
'rect'
;
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
}
else
{
}
else
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
viewNode
.
type
=
'node'
;
viewNode
.
type
=
'node'
;
}
else
{
}
else
{
viewNode
.
type
=
'image'
;
viewNode
.
type
=
'image'
;
const
uuid
=
generateUUID
();
const
uuid
=
generateUUID
();
...
@@ -284,12 +287,19 @@ async function execute$1(psdFile, options) {
...
@@ -284,12 +287,19 @@ async function execute$1(psdFile, options) {
const
imageFilePath
=
path
.
join
(
imagesPath
,
uuid
+
ext
);
const
imageFilePath
=
path
.
join
(
imagesPath
,
uuid
+
ext
);
await
fs
.
ensureDir
(
path
.
dirname
(
imageFilePath
));
await
fs
.
ensureDir
(
path
.
dirname
(
imageFilePath
));
await
node
.
origin
.
saveAsPng
(
imageFilePath
);
let
png
=
node
.
origin
.
toPng
();
let
buffer
=
await
savePng
(
png
,
imageFilePath
);
//await node.origin.saveAsPng(imageFilePath);
const
hashFileName
=
hash
(
buffer
);
const
hashFilePath
=
path
.
join
(
imagesPath
,
hashFileName
+
ext
);
await
fs
.
rename
(
imageFilePath
,
hashFilePath
);
assets
.
push
({
assets
.
push
({
name
:
uuid
,
name
,
ext
,
ext
,
uuid
,
uuid
,
hash
:
hashFileName
,
});
});
}
}
}
}
...
@@ -309,6 +319,22 @@ async function execute$1(psdFile, options) {
...
@@ -309,6 +319,22 @@ async function execute$1(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
);
});
});
}
exports
.
getTree
=
getTree
;
exports
.
getTree
=
getTree
;
exports
.
toEgret
=
execute
;
exports
.
toEgret
=
execute
;
exports
.
toZeroing
=
execute$1
;
exports
.
toZeroing
=
execute$1
;
...
...
dist/index.js.map
View file @
30e0cbff
This diff is collapsed.
Click to expand it.
dist/index.umd.js
View file @
30e0cbff
(
function
(
global
,
factory
)
{
(
function
(
global
,
factory
)
{
typeof
exports
===
'object'
&&
typeof
module
!==
'undefined'
?
factory
(
exports
,
require
(
'xml'
),
require
(
'path'
),
require
(
'fs-extra'
),
require
(
'color'
),
require
(
'uuid/v4'
))
:
typeof
exports
===
'object'
&&
typeof
module
!==
'undefined'
?
factory
(
exports
,
require
(
'xml'
),
require
(
'path'
),
require
(
'fs-extra'
),
require
(
'color'
),
require
(
'uuid/v4'
)
,
require
(
'object-hash'
)
)
:
typeof
define
===
'function'
&&
define
.
amd
?
define
([
'exports'
,
'xml'
,
'path'
,
'fs-extra'
,
'color'
,
'uuid/v4'
],
factory
)
:
typeof
define
===
'function'
&&
define
.
amd
?
define
([
'exports'
,
'xml'
,
'path'
,
'fs-extra'
,
'color'
,
'uuid/v4'
,
'object-hash'
],
factory
)
:
(
global
=
global
||
self
,
factory
(
global
[
'psd-parse'
]
=
{},
global
.
xml
,
global
.
path
,
global
.
fs
,
global
.
Color
,
global
.
generateUUID
));
(
global
=
global
||
self
,
factory
(
global
[
'psd-parse'
]
=
{},
global
.
xml
,
global
.
path
,
global
.
fs
,
global
.
Color
,
global
.
generateUUID
,
global
.
hash
));
}(
this
,
function
(
exports
,
xml
,
path
,
fs
,
Color
,
generateUUID
)
{
'use strict'
;
}(
this
,
function
(
exports
,
xml
,
path
,
fs
,
Color
,
generateUUID
,
hash
)
{
'use strict'
;
xml
=
xml
&&
xml
.
hasOwnProperty
(
'default'
)
?
xml
[
'default'
]
:
xml
;
xml
=
xml
&&
xml
.
hasOwnProperty
(
'default'
)
?
xml
[
'default'
]
:
xml
;
path
=
path
&&
path
.
hasOwnProperty
(
'default'
)
?
path
[
'default'
]
:
path
;
path
=
path
&&
path
.
hasOwnProperty
(
'default'
)
?
path
[
'default'
]
:
path
;
fs
=
fs
&&
fs
.
hasOwnProperty
(
'default'
)
?
fs
[
'default'
]
:
fs
;
fs
=
fs
&&
fs
.
hasOwnProperty
(
'default'
)
?
fs
[
'default'
]
:
fs
;
Color
=
Color
&&
Color
.
hasOwnProperty
(
'default'
)
?
Color
[
'default'
]
:
Color
;
Color
=
Color
&&
Color
.
hasOwnProperty
(
'default'
)
?
Color
[
'default'
]
:
Color
;
generateUUID
=
generateUUID
&&
generateUUID
.
hasOwnProperty
(
'default'
)
?
generateUUID
[
'default'
]
:
generateUUID
;
generateUUID
=
generateUUID
&&
generateUUID
.
hasOwnProperty
(
'default'
)
?
generateUUID
[
'default'
]
:
generateUUID
;
hash
=
hash
&&
hash
.
hasOwnProperty
(
'default'
)
?
hash
[
'default'
]
:
hash
;
/**
/**
* Created by rockyl on 2019-08-09.
* Created by rockyl on 2019-08-09.
...
@@ -234,18 +235,20 @@
...
@@ -234,18 +235,20 @@
let
viewRoot
=
{
let
viewRoot
=
{
name
:
path
.
basename
(
psdFile
,
'.psd'
),
name
:
path
.
basename
(
psdFile
,
'.psd'
),
type
:
'node'
,
type
:
'node'
,
uuid
:
generateUUID
(),
};
};
const
assets
=
[];
const
assets
=
[];
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
const
{
name
,
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
let
properties
=
{
let
properties
=
{
width
,
height
,
alpha
,
visible
,
width
,
height
,
alpha
,
visible
,
};
};
let
viewNode
=
{
let
viewNode
=
{
name
:
node
.
name
,
name
,
properties
,
properties
,
uuid
:
generateUUID
(),
};
};
if
(
x
!==
0
)
{
if
(
x
!==
0
)
{
properties
.
x
=
x
;
properties
.
x
=
x
;
...
@@ -254,8 +257,8 @@
...
@@ -254,8 +257,8 @@
properties
.
y
=
y
;
properties
.
y
=
y
;
}
}
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
const
fonts
=
fontInfo
.
fonts
();
const
fonts
=
fontInfo
.
fonts
();
const
styles
=
fontInfo
.
styles
();
const
styles
=
fontInfo
.
styles
();
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
...
@@ -265,16 +268,16 @@
...
@@ -265,16 +268,16 @@
fonts
,
styles
,
RunLengthArray
,
fonts
,
styles
,
RunLengthArray
,
};
};
viewNode
.
type
=
'label'
;
viewNode
.
type
=
'label'
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
const
{
r
,
g
,
b
}
=
solidColor
();
const
{
r
,
g
,
b
}
=
solidColor
();
let
color
=
Color
({
r
,
g
,
b
});
let
color
=
Color
({
r
,
g
,
b
});
viewNode
.
type
=
'rect'
;
viewNode
.
type
=
'rect'
;
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
}
else
{
}
else
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
viewNode
.
type
=
'node'
;
viewNode
.
type
=
'node'
;
}
else
{
}
else
{
viewNode
.
type
=
'image'
;
viewNode
.
type
=
'image'
;
const
uuid
=
generateUUID
();
const
uuid
=
generateUUID
();
...
@@ -284,12 +287,19 @@
...
@@ -284,12 +287,19 @@
const
imageFilePath
=
path
.
join
(
imagesPath
,
uuid
+
ext
);
const
imageFilePath
=
path
.
join
(
imagesPath
,
uuid
+
ext
);
await
fs
.
ensureDir
(
path
.
dirname
(
imageFilePath
));
await
fs
.
ensureDir
(
path
.
dirname
(
imageFilePath
));
await
node
.
origin
.
saveAsPng
(
imageFilePath
);
let
png
=
node
.
origin
.
toPng
();
let
buffer
=
await
savePng
(
png
,
imageFilePath
);
//await node.origin.saveAsPng(imageFilePath);
const
hashFileName
=
hash
(
buffer
);
const
hashFilePath
=
path
.
join
(
imagesPath
,
hashFileName
+
ext
);
await
fs
.
rename
(
imageFilePath
,
hashFilePath
);
assets
.
push
({
assets
.
push
({
name
:
uuid
,
name
,
ext
,
ext
,
uuid
,
uuid
,
hash
:
hashFileName
,
});
});
}
}
}
}
...
@@ -309,6 +319,22 @@
...
@@ -309,6 +319,22 @@
}
}
}
}
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
);
});
});
}
exports
.
getTree
=
getTree
;
exports
.
getTree
=
getTree
;
exports
.
toEgret
=
execute
;
exports
.
toEgret
=
execute
;
exports
.
toZeroing
=
execute$1
;
exports
.
toZeroing
=
execute$1
;
...
...
dist/index.umd.js.map
View file @
30e0cbff
This diff is collapsed.
Click to expand it.
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