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';
import
fs
from
'fs-extra'
;
import
Color
from
'color'
;
import
generateUUID
from
'uuid/v4'
;
import
hash
from
'object-hash'
;
/**
* Created by rockyl on 2019-08-09.
...
...
@@ -228,18 +229,20 @@ async function execute$1(psdFile, options) {
let
viewRoot
=
{
name
:
path
.
basename
(
psdFile
,
'.psd'
),
type
:
'node'
,
uuid
:
generateUUID
(),
};
const
assets
=
[];
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
=
{
width
,
height
,
alpha
,
visible
,
};
let
viewNode
=
{
name
:
node
.
name
,
name
,
properties
,
uuid
:
generateUUID
(),
};
if
(
x
!==
0
)
{
properties
.
x
=
x
;
...
...
@@ -248,8 +251,8 @@ async function execute$1(psdFile, options) {
properties
.
y
=
y
;
}
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
const
fonts
=
fontInfo
.
fonts
();
const
styles
=
fontInfo
.
styles
();
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
...
...
@@ -259,16 +262,16 @@ async function execute$1(psdFile, options) {
fonts
,
styles
,
RunLengthArray
,
};
viewNode
.
type
=
'label'
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
const
{
r
,
g
,
b
}
=
solidColor
();
let
color
=
Color
({
r
,
g
,
b
});
viewNode
.
type
=
'rect'
;
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
}
else
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
}
else
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
viewNode
.
type
=
'node'
;
}
else
{
}
else
{
viewNode
.
type
=
'image'
;
const
uuid
=
generateUUID
();
...
...
@@ -278,12 +281,19 @@ async function execute$1(psdFile, options) {
const
imageFilePath
=
path
.
join
(
imagesPath
,
uuid
+
ext
);
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
({
name
:
uuid
,
name
,
ext
,
uuid
,
hash
:
hashFileName
,
});
}
}
...
...
@@ -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
};
//# 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'));
var
fs
=
_interopDefault
(
require
(
'fs-extra'
));
var
Color
=
_interopDefault
(
require
(
'color'
));
var
generateUUID
=
_interopDefault
(
require
(
'uuid/v4'
));
var
hash
=
_interopDefault
(
require
(
'object-hash'
));
/**
* Created by rockyl on 2019-08-09.
...
...
@@ -234,18 +235,20 @@ async function execute$1(psdFile, options) {
let
viewRoot
=
{
name
:
path
.
basename
(
psdFile
,
'.psd'
),
type
:
'node'
,
uuid
:
generateUUID
(),
};
const
assets
=
[];
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
=
{
width
,
height
,
alpha
,
visible
,
};
let
viewNode
=
{
name
:
node
.
name
,
name
,
properties
,
uuid
:
generateUUID
(),
};
if
(
x
!==
0
)
{
properties
.
x
=
x
;
...
...
@@ -254,8 +257,8 @@ async function execute$1(psdFile, options) {
properties
.
y
=
y
;
}
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
const
fonts
=
fontInfo
.
fonts
();
const
styles
=
fontInfo
.
styles
();
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
...
...
@@ -265,16 +268,16 @@ async function execute$1(psdFile, options) {
fonts
,
styles
,
RunLengthArray
,
};
viewNode
.
type
=
'label'
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
const
{
r
,
g
,
b
}
=
solidColor
();
let
color
=
Color
({
r
,
g
,
b
});
viewNode
.
type
=
'rect'
;
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
}
else
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
}
else
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
viewNode
.
type
=
'node'
;
}
else
{
}
else
{
viewNode
.
type
=
'image'
;
const
uuid
=
generateUUID
();
...
...
@@ -284,12 +287,19 @@ async function execute$1(psdFile, options) {
const
imageFilePath
=
path
.
join
(
imagesPath
,
uuid
+
ext
);
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
({
name
:
uuid
,
name
,
ext
,
uuid
,
hash
:
hashFileName
,
});
}
}
...
...
@@ -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
.
toEgret
=
execute
;
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
)
{
typeof
exports
===
'object'
&&
typeof
module
!==
'undefined'
?
factory
(
exports
,
require
(
'xml'
),
require
(
'path'
),
require
(
'fs-extra'
),
require
(
'color'
),
require
(
'uuid/v4'
))
:
typeof
define
===
'function'
&&
define
.
amd
?
define
([
'exports'
,
'xml'
,
'path'
,
'fs-extra'
,
'color'
,
'uuid/v4'
],
factory
)
:
(
global
=
global
||
self
,
factory
(
global
[
'psd-parse'
]
=
{},
global
.
xml
,
global
.
path
,
global
.
fs
,
global
.
Color
,
global
.
generateUUID
));
}(
this
,
function
(
exports
,
xml
,
path
,
fs
,
Color
,
generateUUID
)
{
'use strict'
;
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'
,
'object-hash'
],
factory
)
:
(
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
,
hash
)
{
'use strict'
;
xml
=
xml
&&
xml
.
hasOwnProperty
(
'default'
)
?
xml
[
'default'
]
:
xml
;
path
=
path
&&
path
.
hasOwnProperty
(
'default'
)
?
path
[
'default'
]
:
path
;
fs
=
fs
&&
fs
.
hasOwnProperty
(
'default'
)
?
fs
[
'default'
]
:
fs
;
Color
=
Color
&&
Color
.
hasOwnProperty
(
'default'
)
?
Color
[
'default'
]
:
Color
;
generateUUID
=
generateUUID
&&
generateUUID
.
hasOwnProperty
(
'default'
)
?
generateUUID
[
'default'
]
:
generateUUID
;
hash
=
hash
&&
hash
.
hasOwnProperty
(
'default'
)
?
hash
[
'default'
]
:
hash
;
/**
* Created by rockyl on 2019-08-09.
...
...
@@ -234,18 +235,20 @@
let
viewRoot
=
{
name
:
path
.
basename
(
psdFile
,
'.psd'
),
type
:
'node'
,
uuid
:
generateUUID
(),
};
const
assets
=
[];
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
=
{
width
,
height
,
alpha
,
visible
,
};
let
viewNode
=
{
name
:
node
.
name
,
name
,
properties
,
uuid
:
generateUUID
(),
};
if
(
x
!==
0
)
{
properties
.
x
=
x
;
...
...
@@ -254,8 +257,8 @@
properties
.
y
=
y
;
}
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
const
fonts
=
fontInfo
.
fonts
();
const
styles
=
fontInfo
.
styles
();
const
{
RunLengthArray
}
=
fontInfo
.
engineData
.
EngineDict
.
StyleRun
;
...
...
@@ -265,16 +268,16 @@
fonts
,
styles
,
RunLengthArray
,
};
viewNode
.
type
=
'label'
;
}
else
if
(
solidColor
)
{
}
else
if
(
solidColor
)
{
const
{
r
,
g
,
b
}
=
solidColor
();
let
color
=
Color
({
r
,
g
,
b
});
viewNode
.
type
=
'rect'
;
properties
.
fillColor
=
'#'
+
color
.
rgbNumber
().
toString
(
16
);
}
else
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
}
else
{
if
(
node
.
hasOwnProperty
(
'children'
))
{
viewNode
.
type
=
'node'
;
}
else
{
}
else
{
viewNode
.
type
=
'image'
;
const
uuid
=
generateUUID
();
...
...
@@ -284,12 +287,19 @@
const
imageFilePath
=
path
.
join
(
imagesPath
,
uuid
+
ext
);
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
({
name
:
uuid
,
name
,
ext
,
uuid
,
hash
:
hashFileName
,
});
}
}
...
...
@@ -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
.
toEgret
=
execute
;
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