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
efabca6d
Commit
efabca6d
authored
Jun 10, 2021
by
张九刚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增mode适配
parent
f10828d2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
15 deletions
+83
-15
package.json
package.json
+1
-1
compilelocal.js
src/compilelocal.js
+10
-13
utils.js
src/utils.js
+72
-1
No files found.
package.json
View file @
efabca6d
{
{
"name"
:
"psd-parse-web"
,
"name"
:
"psd-parse-web"
,
"version"
:
"2.0.
4
"
,
"version"
:
"2.0.
5
"
,
"main"
:
"src/index.js"
,
"main"
:
"src/index.js"
,
"module"
:
"dist/index.es.js"
,
"module"
:
"dist/index.es.js"
,
"license"
:
"
MIT
"
,
"license"
:
"
MIT
"
,
...
...
src/compilelocal.js
View file @
efabca6d
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
*/
*/
var
{
getTree
}
=
require
(
"./psd-tree"
);
var
{
getTree
}
=
require
(
"./psd-tree"
);
var
{
walkNode
,
trimCustom
}
=
require
(
"./utils"
);
var
{
walkNode
,
trimCustom
,
getPageStyle
}
=
require
(
"./utils"
);
var
path
=
require
(
'path'
);
var
path
=
require
(
'path'
);
var
Color
=
require
(
'color'
);
var
Color
=
require
(
'color'
);
var
generateUUID
=
require
(
'uuid/v4'
);
var
generateUUID
=
require
(
'uuid/v4'
);
...
@@ -30,7 +30,7 @@ const relativePosPrefixMap = {
...
@@ -30,7 +30,7 @@ const relativePosPrefixMap = {
async
function
compilePsdToJson
(
psdFile
,
options
)
{
async
function
compilePsdToJson
(
psdFile
,
options
)
{
const
{
assetsPath
}
=
options
;
const
{
mode
,
assetsPath
}
=
options
;
if
(
!
assetsPath
)
{
if
(
!
assetsPath
)
{
console
.
log
(
"没有指定assets目录"
);
console
.
log
(
"没有指定assets目录"
);
}
}
...
@@ -60,12 +60,12 @@ async function compilePsdToJson(psdFile, options) {
...
@@ -60,12 +60,12 @@ async function compilePsdToJson(psdFile, options) {
console
.
warn
(
`
${
page
.
name
}
不合法,请保持设计稿根目录为全部文件夹形式`
);
console
.
warn
(
`
${
page
.
name
}
不合法,请保持设计稿根目录为全部文件夹形式`
);
}
else
{
}
else
{
const
{
x
,
y
,
width
,
height
}
=
page
;
const
{
x
,
y
,
width
,
height
}
=
page
;
cons
t
viewNode
=
{
le
t
viewNode
=
{
name
:
folderName
,
name
:
folderName
,
nodeType
:
'Div'
,
nodeType
:
'Div'
,
properties
:
{
properties
:
{
style
:
{
style
:
{
width
,
height
,
left
:
x
,
top
:
y
,
position
:
"absolute"
width
,
height
,
...
getPageStyle
(
mode
,
x
,
y
)
},
},
attrs
:
{
attrs
:
{
...
@@ -75,12 +75,15 @@ async function compilePsdToJson(psdFile, options) {
...
@@ -75,12 +75,15 @@ async function compilePsdToJson(psdFile, options) {
uuid
:
generateUUID
(),
uuid
:
generateUUID
(),
children
:
[]
children
:
[]
};
};
viewRoot
.
children
.
push
(
viewNode
);
viewRoot
.
children
.
push
(
viewNode
);
}
}
await
walkNode
(
page
,
async
(
node
,
parent
)
=>
{
await
walkNode
(
page
,
async
(
node
,
parent
)
=>
{
let
{
name
}
=
node
;
let
{
name
}
=
node
;
name
=
trimCustom
(
name
);
name
=
trimCustom
(
name
);
const
{
x
,
y
,
width
,
height
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}
}
}
=
node
;
const
{
x
,
y
,
width
,
height
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}
}
}
=
node
;
let
properties
=
{
let
properties
=
{
style
:
{
style
:
{
...
@@ -93,7 +96,7 @@ async function compilePsdToJson(psdFile, options) {
...
@@ -93,7 +96,7 @@ async function compilePsdToJson(psdFile, options) {
};
};
let
viewNode
=
{
let
viewNode
=
{
name
,
name
:
name
.
split
(
'|'
)[
0
],
//如果设置了适配的话,作为名字截取掉
properties
,
properties
,
uuid
:
generateUUID
(),
uuid
:
generateUUID
(),
};
};
...
@@ -213,15 +216,9 @@ async function compilePsdToJson(psdFile, options) {
...
@@ -213,15 +216,9 @@ async function compilePsdToJson(psdFile, options) {
return
data
;
return
data
;
}
}
/**
* 单页解析
* @param {*} node
* @param {*} parent
* @param {*} folderName
*/
async
function
compilePage
(
node
,
parent
,
folderName
,
assetsPath
)
{
}
function
savePng
(
png
,
output
)
{
function
savePng
(
png
,
output
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
src/utils.js
View file @
efabca6d
...
@@ -23,6 +23,75 @@ async function walkObject(obj, callback) {
...
@@ -23,6 +23,75 @@ async function walkObject(obj, callback) {
}
}
}
}
}
}
const
DesignHeight
=
1624
;
const
SafetyHeight
=
1206
;
const
HalfHeight
=
(
DesignHeight
-
SafetyHeight
)
/
2
;
// 不裁剪 ,顶部裁剪,上下裁剪,底部裁剪
const
designCutModes
=
{
'none'
:
'none'
,
'top'
:
'top'
,
'center'
:
'center'
,
'bottom'
:
'bottom'
};
/**
* 获取页面的样式
*/
function
getPageStyle
(
mode
,
xx
,
yy
)
{
let
result
=
{};
switch
(
mode
)
{
case
designCutModes
.
top
:
//顶部裁剪就是底对齐
result
=
{
bottom
:
0
,
left
:
0
,
position
:
"absolute"
}
break
;
case
designCutModes
.
center
:
result
=
{
transform
:
"translate(-50%, -50%)"
,
top
:
"50%"
,
left
:
"50%"
,
position
:
"fixed"
}
break
;
case
designCutModes
.
bottom
:
result
=
{
top
:
0
,
left
:
0
,
position
:
"fixed"
}
break
;
default
:
result
=
{
top
:
xx
,
left
:
yy
,
position
:
"absolute"
}
break
;
}
return
result
;
}
function
getXYBySign
(
value
,
sign
,
xx
,
yy
,
mode
)
{
switch
(
mode
)
{
case
designCutModes
.
none
:
break
;
case
designCutModes
.
top
:
break
;
case
designCutModes
.
center
:
break
;
case
designCutModes
.
bottom
:
break
;
default
:
break
;
}
}
function
getValueBySign
()
{
}
function
trimCustom
(
str
)
{
function
trimCustom
(
str
)
{
var
result
;
var
result
;
result
=
str
.
replace
(
/
(
^
\s
+
)
|
(\s
+$
)
/g
,
""
);
result
=
str
.
replace
(
/
(
^
\s
+
)
|
(\s
+$
)
/g
,
""
);
...
@@ -32,5 +101,7 @@ function trimCustom(str) {
...
@@ -32,5 +101,7 @@ function trimCustom(str) {
module
.
exports
=
{
module
.
exports
=
{
walkNode
,
walkNode
,
walkObject
,
walkObject
,
trimCustom
trimCustom
,
getXYBySign
,
getPageStyle
}
}
\ No newline at end of file
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