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
5cc49b8f
Commit
5cc49b8f
authored
Jun 24, 2020
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
放假前提交一波
parent
358bd784
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
142 additions
and
128 deletions
+142
-128
index.es.js
dist/index.es.js
+35
-33
index.es.js.map
dist/index.es.js.map
+1
-1
index.js
dist/index.js
+35
-33
index.js.map
dist/index.js.map
+1
-1
index.umd.js
dist/index.umd.js
+35
-33
index.umd.js.map
dist/index.umd.js.map
+1
-1
zeroing.js
src/zeroing.js
+34
-26
No files found.
dist/index.es.js
View file @
5cc49b8f
...
@@ -72,25 +72,23 @@ const relativePosPrefixMap = {
...
@@ -72,25 +72,23 @@ const relativePosPrefixMap = {
b
:
{
field
:
'bottom'
,},
b
:
{
field
:
'bottom'
,},
h
:
{
field
:
'horizonCenter'
,},
h
:
{
field
:
'horizonCenter'
,},
v
:
{
field
:
'verticalCenter'
,},
v
:
{
field
:
'verticalCenter'
,},
wp
:
{
field
:
'width'
,
},
wp
:
{
field
:
'width'
,},
hp
:
{
field
:
'height'
,
},
hp
:
{
field
:
'height'
,},
lp
:
{
field
:
'left'
,
},
lp
:
{
field
:
'left'
,},
tp
:
{
field
:
'top'
,
},
tp
:
{
field
:
'top'
,},
rp
:
{
field
:
'right'
,
},
rp
:
{
field
:
'right'
,},
bp
:
{
field
:
'bottom'
,
},
bp
:
{
field
:
'bottom'
,},
};
};
const
offsetAll
=
176
;
const
offsetAll
=
176
;
const
enterChar
=
String
.
fromCharCode
(
13
);
async
function
execute
(
psdFile
,
options
)
{
async
function
execute
(
psdFile
,
options
)
{
const
tree
=
await
getTree
(
psdFile
);
const
tree
=
await
getTree
(
psdFile
);
const
{
mode
=
'none'
}
=
options
;
const
{
mode
=
'none'
,
singleView
=
true
}
=
options
;
let
offset
=
{
x
:
0
,
y
:
0
};
let
offset
=
{
x
:
0
,
y
:
0
};
let
cutSize
=
{
x
:
0
,
y
:
0
};
switch
(
mode
)
{
if
(
mode
!==
'none'
){
cutSize
.
y
=
offsetAll
;
}
switch
(
mode
){
case
'top'
:
case
'top'
:
offset
.
y
=
offsetAll
;
offset
.
y
=
offsetAll
;
break
;
break
;
...
@@ -108,10 +106,6 @@ async function execute(psdFile, options) {
...
@@ -108,10 +106,6 @@ async function execute(psdFile, options) {
const
assets
=
[];
const
assets
=
[];
const
imageHashMap
=
{};
const
imageHashMap
=
{};
let
{
width
:
stageWidth
,
height
:
stageHeight
}
=
tree
;
stageWidth
-=
0
;
stageHeight
-=
cutSize
.
y
||
0
;
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
let
{
name
}
=
node
;
let
{
name
}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
...
@@ -121,6 +115,8 @@ async function execute(psdFile, options) {
...
@@ -121,6 +115,8 @@ async function execute(psdFile, options) {
};
};
const
isSecondLayer
=
!
parent
.
origin
.
parent
;
const
isSecondLayer
=
!
parent
.
origin
.
parent
;
const
{
width
:
parentWidth
,
height
:
parentHeight
}
=
parent
;
if
(
name
.
includes
(
'|'
))
{
if
(
name
.
includes
(
'|'
))
{
try
{
try
{
let
arr
=
name
.
split
(
'|'
);
let
arr
=
name
.
split
(
'|'
);
...
@@ -132,7 +128,7 @@ async function execute(psdFile, options) {
...
@@ -132,7 +128,7 @@ async function execute(psdFile, options) {
let
items
=
relativePos
.
split
(
','
);
let
items
=
relativePos
.
split
(
','
);
for
(
let
item
of
items
)
{
for
(
let
item
of
items
)
{
let
result
=
item
.
match
(
/
[
a-zA-Z
]
+/
);
let
result
=
item
.
match
(
/
[
a-zA-Z
]
+/
);
if
(
!
result
)
{
if
(
!
result
)
{
continue
;
continue
;
}
}
let
prefix
=
result
[
0
];
let
prefix
=
result
[
0
];
...
@@ -142,8 +138,8 @@ async function execute(psdFile, options) {
...
@@ -142,8 +138,8 @@ async function execute(psdFile, options) {
let
value
=
item
.
substr
(
prefix
.
length
);
let
value
=
item
.
substr
(
prefix
.
length
);
let
hasValue
=
value
.
length
>
0
;
let
hasValue
=
value
.
length
>
0
;
let
fieldChar
=
prefix
[
0
];
let
fieldChar
=
prefix
[
0
];
if
(
!
hasValue
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
switch
(
fieldChar
)
{
case
'l'
:
case
'l'
:
value
=
x
-
offset
.
x
;
value
=
x
-
offset
.
x
;
break
;
break
;
...
@@ -151,30 +147,30 @@ async function execute(psdFile, options) {
...
@@ -151,30 +147,30 @@ async function execute(psdFile, options) {
value
=
y
-
offset
.
y
;
value
=
y
-
offset
.
y
;
break
;
break
;
case
'r'
:
case
'r'
:
value
=
stage
Width
-
(
x
-
offset
.
x
)
-
width
;
value
=
parent
Width
-
(
x
-
offset
.
x
)
-
width
;
break
;
break
;
case
'b'
:
case
'b'
:
value
=
stage
Height
-
(
y
-
offset
.
y
)
-
height
;
value
=
parent
Height
-
(
y
-
offset
.
y
)
-
height
;
break
;
break
;
case
'h'
:
case
'h'
:
value
=
x
+
width
/
2
-
stage
Width
/
2
;
value
=
x
+
width
/
2
-
parent
Width
/
2
;
break
;
break
;
case
'v'
:
case
'v'
:
value
=
y
+
height
/
2
-
stage
Height
/
2
;
value
=
y
+
height
/
2
-
parent
Height
/
2
;
break
;
break
;
}
}
}
}
let
isPercent
=
prefix
.
endsWith
(
'p'
);
let
isPercent
=
prefix
.
endsWith
(
'p'
);
if
(
isPercent
)
{
if
(
isPercent
)
{
if
(
!
hasValue
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
switch
(
fieldChar
)
{
case
'l'
:
case
'l'
:
case
'r'
:
case
'r'
:
value
/=
stage
Width
;
value
/=
parent
Width
;
break
;
break
;
case
't'
:
case
't'
:
case
'b'
:
case
'b'
:
value
/=
stage
Height
;
value
/=
parent
Height
;
break
;
break
;
}
}
value
=
Math
.
floor
(
value
*
100
);
value
=
Math
.
floor
(
value
*
100
);
...
@@ -190,7 +186,7 @@ async function execute(psdFile, options) {
...
@@ -190,7 +186,7 @@ async function execute(psdFile, options) {
}
}
}
}
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
);
console
.
log
(
e
);
}
}
}
}
...
@@ -201,16 +197,22 @@ async function execute(psdFile, options) {
...
@@ -201,16 +197,22 @@ async function execute(psdFile, options) {
uuid
:
generateUUID
(),
uuid
:
generateUUID
(),
};
};
let
dealLater
=
true
;
let
dealLater
=
true
;
if
(
x
!==
0
)
{
let
px
=
x
;
// - (!singleView && isSecondLayer ? offset.x : 0);
properties
.
x
=
x
;
// - (isSecondLayer ? offset.x : 0);
let
py
=
y
;
// - (!singleView && isSecondLayer ? offset.y : 0);
if
(
px
!==
0
)
{
properties
.
x
=
px
;
}
}
if
(
y
!==
0
)
{
if
(
p
y
!==
0
)
{
properties
.
y
=
y
;
// - (isSecondLayer ? offset.y : 0)
;
properties
.
y
=
py
;
}
}
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
properties
.
text
=
fontInfo
.
textValue
;
let
text
=
fontInfo
.
textValue
;
if
(
text
.
indexOf
(
enterChar
)
<
0
)
{
//如果未包含回车说明是多行,去掉宽度
delete
properties
[
'width'
];
}
properties
.
text
=
text
;
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
;
...
...
dist/index.es.js.map
View file @
5cc49b8f
This diff is collapsed.
Click to expand it.
dist/index.js
View file @
5cc49b8f
...
@@ -78,25 +78,23 @@ const relativePosPrefixMap = {
...
@@ -78,25 +78,23 @@ const relativePosPrefixMap = {
b
:
{
field
:
'bottom'
,},
b
:
{
field
:
'bottom'
,},
h
:
{
field
:
'horizonCenter'
,},
h
:
{
field
:
'horizonCenter'
,},
v
:
{
field
:
'verticalCenter'
,},
v
:
{
field
:
'verticalCenter'
,},
wp
:
{
field
:
'width'
,
},
wp
:
{
field
:
'width'
,},
hp
:
{
field
:
'height'
,
},
hp
:
{
field
:
'height'
,},
lp
:
{
field
:
'left'
,
},
lp
:
{
field
:
'left'
,},
tp
:
{
field
:
'top'
,
},
tp
:
{
field
:
'top'
,},
rp
:
{
field
:
'right'
,
},
rp
:
{
field
:
'right'
,},
bp
:
{
field
:
'bottom'
,
},
bp
:
{
field
:
'bottom'
,},
};
};
const
offsetAll
=
176
;
const
offsetAll
=
176
;
const
enterChar
=
String
.
fromCharCode
(
13
);
async
function
execute
(
psdFile
,
options
)
{
async
function
execute
(
psdFile
,
options
)
{
const
tree
=
await
getTree
(
psdFile
);
const
tree
=
await
getTree
(
psdFile
);
const
{
mode
=
'none'
}
=
options
;
const
{
mode
=
'none'
,
singleView
=
true
}
=
options
;
let
offset
=
{
x
:
0
,
y
:
0
};
let
offset
=
{
x
:
0
,
y
:
0
};
let
cutSize
=
{
x
:
0
,
y
:
0
};
switch
(
mode
)
{
if
(
mode
!==
'none'
){
cutSize
.
y
=
offsetAll
;
}
switch
(
mode
){
case
'top'
:
case
'top'
:
offset
.
y
=
offsetAll
;
offset
.
y
=
offsetAll
;
break
;
break
;
...
@@ -114,10 +112,6 @@ async function execute(psdFile, options) {
...
@@ -114,10 +112,6 @@ async function execute(psdFile, options) {
const
assets
=
[];
const
assets
=
[];
const
imageHashMap
=
{};
const
imageHashMap
=
{};
let
{
width
:
stageWidth
,
height
:
stageHeight
}
=
tree
;
stageWidth
-=
0
;
stageHeight
-=
cutSize
.
y
||
0
;
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
let
{
name
}
=
node
;
let
{
name
}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
...
@@ -127,6 +121,8 @@ async function execute(psdFile, options) {
...
@@ -127,6 +121,8 @@ async function execute(psdFile, options) {
};
};
const
isSecondLayer
=
!
parent
.
origin
.
parent
;
const
isSecondLayer
=
!
parent
.
origin
.
parent
;
const
{
width
:
parentWidth
,
height
:
parentHeight
}
=
parent
;
if
(
name
.
includes
(
'|'
))
{
if
(
name
.
includes
(
'|'
))
{
try
{
try
{
let
arr
=
name
.
split
(
'|'
);
let
arr
=
name
.
split
(
'|'
);
...
@@ -138,7 +134,7 @@ async function execute(psdFile, options) {
...
@@ -138,7 +134,7 @@ async function execute(psdFile, options) {
let
items
=
relativePos
.
split
(
','
);
let
items
=
relativePos
.
split
(
','
);
for
(
let
item
of
items
)
{
for
(
let
item
of
items
)
{
let
result
=
item
.
match
(
/
[
a-zA-Z
]
+/
);
let
result
=
item
.
match
(
/
[
a-zA-Z
]
+/
);
if
(
!
result
)
{
if
(
!
result
)
{
continue
;
continue
;
}
}
let
prefix
=
result
[
0
];
let
prefix
=
result
[
0
];
...
@@ -148,8 +144,8 @@ async function execute(psdFile, options) {
...
@@ -148,8 +144,8 @@ async function execute(psdFile, options) {
let
value
=
item
.
substr
(
prefix
.
length
);
let
value
=
item
.
substr
(
prefix
.
length
);
let
hasValue
=
value
.
length
>
0
;
let
hasValue
=
value
.
length
>
0
;
let
fieldChar
=
prefix
[
0
];
let
fieldChar
=
prefix
[
0
];
if
(
!
hasValue
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
switch
(
fieldChar
)
{
case
'l'
:
case
'l'
:
value
=
x
-
offset
.
x
;
value
=
x
-
offset
.
x
;
break
;
break
;
...
@@ -157,30 +153,30 @@ async function execute(psdFile, options) {
...
@@ -157,30 +153,30 @@ async function execute(psdFile, options) {
value
=
y
-
offset
.
y
;
value
=
y
-
offset
.
y
;
break
;
break
;
case
'r'
:
case
'r'
:
value
=
stage
Width
-
(
x
-
offset
.
x
)
-
width
;
value
=
parent
Width
-
(
x
-
offset
.
x
)
-
width
;
break
;
break
;
case
'b'
:
case
'b'
:
value
=
stage
Height
-
(
y
-
offset
.
y
)
-
height
;
value
=
parent
Height
-
(
y
-
offset
.
y
)
-
height
;
break
;
break
;
case
'h'
:
case
'h'
:
value
=
x
+
width
/
2
-
stage
Width
/
2
;
value
=
x
+
width
/
2
-
parent
Width
/
2
;
break
;
break
;
case
'v'
:
case
'v'
:
value
=
y
+
height
/
2
-
stage
Height
/
2
;
value
=
y
+
height
/
2
-
parent
Height
/
2
;
break
;
break
;
}
}
}
}
let
isPercent
=
prefix
.
endsWith
(
'p'
);
let
isPercent
=
prefix
.
endsWith
(
'p'
);
if
(
isPercent
)
{
if
(
isPercent
)
{
if
(
!
hasValue
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
switch
(
fieldChar
)
{
case
'l'
:
case
'l'
:
case
'r'
:
case
'r'
:
value
/=
stage
Width
;
value
/=
parent
Width
;
break
;
break
;
case
't'
:
case
't'
:
case
'b'
:
case
'b'
:
value
/=
stage
Height
;
value
/=
parent
Height
;
break
;
break
;
}
}
value
=
Math
.
floor
(
value
*
100
);
value
=
Math
.
floor
(
value
*
100
);
...
@@ -196,7 +192,7 @@ async function execute(psdFile, options) {
...
@@ -196,7 +192,7 @@ async function execute(psdFile, options) {
}
}
}
}
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
);
console
.
log
(
e
);
}
}
}
}
...
@@ -207,16 +203,22 @@ async function execute(psdFile, options) {
...
@@ -207,16 +203,22 @@ async function execute(psdFile, options) {
uuid
:
generateUUID
(),
uuid
:
generateUUID
(),
};
};
let
dealLater
=
true
;
let
dealLater
=
true
;
if
(
x
!==
0
)
{
let
px
=
x
;
// - (!singleView && isSecondLayer ? offset.x : 0);
properties
.
x
=
x
;
// - (isSecondLayer ? offset.x : 0);
let
py
=
y
;
// - (!singleView && isSecondLayer ? offset.y : 0);
if
(
px
!==
0
)
{
properties
.
x
=
px
;
}
}
if
(
y
!==
0
)
{
if
(
p
y
!==
0
)
{
properties
.
y
=
y
;
// - (isSecondLayer ? offset.y : 0)
;
properties
.
y
=
py
;
}
}
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
properties
.
text
=
fontInfo
.
textValue
;
let
text
=
fontInfo
.
textValue
;
if
(
text
.
indexOf
(
enterChar
)
<
0
)
{
//如果未包含回车说明是多行,去掉宽度
delete
properties
[
'width'
];
}
properties
.
text
=
text
;
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
;
...
...
dist/index.js.map
View file @
5cc49b8f
This diff is collapsed.
Click to expand it.
dist/index.umd.js
View file @
5cc49b8f
...
@@ -78,25 +78,23 @@
...
@@ -78,25 +78,23 @@
b
:
{
field
:
'bottom'
,},
b
:
{
field
:
'bottom'
,},
h
:
{
field
:
'horizonCenter'
,},
h
:
{
field
:
'horizonCenter'
,},
v
:
{
field
:
'verticalCenter'
,},
v
:
{
field
:
'verticalCenter'
,},
wp
:
{
field
:
'width'
,
},
wp
:
{
field
:
'width'
,},
hp
:
{
field
:
'height'
,
},
hp
:
{
field
:
'height'
,},
lp
:
{
field
:
'left'
,
},
lp
:
{
field
:
'left'
,},
tp
:
{
field
:
'top'
,
},
tp
:
{
field
:
'top'
,},
rp
:
{
field
:
'right'
,
},
rp
:
{
field
:
'right'
,},
bp
:
{
field
:
'bottom'
,
},
bp
:
{
field
:
'bottom'
,},
};
};
const
offsetAll
=
176
;
const
offsetAll
=
176
;
const
enterChar
=
String
.
fromCharCode
(
13
);
async
function
execute
(
psdFile
,
options
)
{
async
function
execute
(
psdFile
,
options
)
{
const
tree
=
await
getTree
(
psdFile
);
const
tree
=
await
getTree
(
psdFile
);
const
{
mode
=
'none'
}
=
options
;
const
{
mode
=
'none'
,
singleView
=
true
}
=
options
;
let
offset
=
{
x
:
0
,
y
:
0
};
let
offset
=
{
x
:
0
,
y
:
0
};
let
cutSize
=
{
x
:
0
,
y
:
0
};
switch
(
mode
)
{
if
(
mode
!==
'none'
){
cutSize
.
y
=
offsetAll
;
}
switch
(
mode
){
case
'top'
:
case
'top'
:
offset
.
y
=
offsetAll
;
offset
.
y
=
offsetAll
;
break
;
break
;
...
@@ -114,10 +112,6 @@
...
@@ -114,10 +112,6 @@
const
assets
=
[];
const
assets
=
[];
const
imageHashMap
=
{};
const
imageHashMap
=
{};
let
{
width
:
stageWidth
,
height
:
stageHeight
}
=
tree
;
stageWidth
-=
0
;
stageHeight
-=
cutSize
.
y
||
0
;
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
await
walkNode
(
tree
,
async
function
(
node
,
parent
)
{
let
{
name
}
=
node
;
let
{
name
}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
const
{
x
,
y
,
width
,
height
,
alpha
,
visible
,
origin
:
{
layer
,
layer
:
{
typeTool
,
solidColor
}}}
=
node
;
...
@@ -127,6 +121,8 @@
...
@@ -127,6 +121,8 @@
};
};
const
isSecondLayer
=
!
parent
.
origin
.
parent
;
const
isSecondLayer
=
!
parent
.
origin
.
parent
;
const
{
width
:
parentWidth
,
height
:
parentHeight
}
=
parent
;
if
(
name
.
includes
(
'|'
))
{
if
(
name
.
includes
(
'|'
))
{
try
{
try
{
let
arr
=
name
.
split
(
'|'
);
let
arr
=
name
.
split
(
'|'
);
...
@@ -138,7 +134,7 @@
...
@@ -138,7 +134,7 @@
let
items
=
relativePos
.
split
(
','
);
let
items
=
relativePos
.
split
(
','
);
for
(
let
item
of
items
)
{
for
(
let
item
of
items
)
{
let
result
=
item
.
match
(
/
[
a-zA-Z
]
+/
);
let
result
=
item
.
match
(
/
[
a-zA-Z
]
+/
);
if
(
!
result
)
{
if
(
!
result
)
{
continue
;
continue
;
}
}
let
prefix
=
result
[
0
];
let
prefix
=
result
[
0
];
...
@@ -148,8 +144,8 @@
...
@@ -148,8 +144,8 @@
let
value
=
item
.
substr
(
prefix
.
length
);
let
value
=
item
.
substr
(
prefix
.
length
);
let
hasValue
=
value
.
length
>
0
;
let
hasValue
=
value
.
length
>
0
;
let
fieldChar
=
prefix
[
0
];
let
fieldChar
=
prefix
[
0
];
if
(
!
hasValue
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
switch
(
fieldChar
)
{
case
'l'
:
case
'l'
:
value
=
x
-
offset
.
x
;
value
=
x
-
offset
.
x
;
break
;
break
;
...
@@ -157,30 +153,30 @@
...
@@ -157,30 +153,30 @@
value
=
y
-
offset
.
y
;
value
=
y
-
offset
.
y
;
break
;
break
;
case
'r'
:
case
'r'
:
value
=
stage
Width
-
(
x
-
offset
.
x
)
-
width
;
value
=
parent
Width
-
(
x
-
offset
.
x
)
-
width
;
break
;
break
;
case
'b'
:
case
'b'
:
value
=
stage
Height
-
(
y
-
offset
.
y
)
-
height
;
value
=
parent
Height
-
(
y
-
offset
.
y
)
-
height
;
break
;
break
;
case
'h'
:
case
'h'
:
value
=
x
+
width
/
2
-
stage
Width
/
2
;
value
=
x
+
width
/
2
-
parent
Width
/
2
;
break
;
break
;
case
'v'
:
case
'v'
:
value
=
y
+
height
/
2
-
stage
Height
/
2
;
value
=
y
+
height
/
2
-
parent
Height
/
2
;
break
;
break
;
}
}
}
}
let
isPercent
=
prefix
.
endsWith
(
'p'
);
let
isPercent
=
prefix
.
endsWith
(
'p'
);
if
(
isPercent
)
{
if
(
isPercent
)
{
if
(
!
hasValue
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
switch
(
fieldChar
)
{
case
'l'
:
case
'l'
:
case
'r'
:
case
'r'
:
value
/=
stage
Width
;
value
/=
parent
Width
;
break
;
break
;
case
't'
:
case
't'
:
case
'b'
:
case
'b'
:
value
/=
stage
Height
;
value
/=
parent
Height
;
break
;
break
;
}
}
value
=
Math
.
floor
(
value
*
100
);
value
=
Math
.
floor
(
value
*
100
);
...
@@ -196,7 +192,7 @@
...
@@ -196,7 +192,7 @@
}
}
}
}
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
);
console
.
log
(
e
);
}
}
}
}
...
@@ -207,16 +203,22 @@
...
@@ -207,16 +203,22 @@
uuid
:
generateUUID
(),
uuid
:
generateUUID
(),
};
};
let
dealLater
=
true
;
let
dealLater
=
true
;
if
(
x
!==
0
)
{
let
px
=
x
;
// - (!singleView && isSecondLayer ? offset.x : 0);
properties
.
x
=
x
;
// - (isSecondLayer ? offset.x : 0);
let
py
=
y
;
// - (!singleView && isSecondLayer ? offset.y : 0);
if
(
px
!==
0
)
{
properties
.
x
=
px
;
}
}
if
(
y
!==
0
)
{
if
(
p
y
!==
0
)
{
properties
.
y
=
y
;
// - (isSecondLayer ? offset.y : 0)
;
properties
.
y
=
py
;
}
}
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
properties
.
text
=
fontInfo
.
textValue
;
let
text
=
fontInfo
.
textValue
;
if
(
text
.
indexOf
(
enterChar
)
<
0
)
{
//如果未包含回车说明是多行,去掉宽度
delete
properties
[
'width'
];
}
properties
.
text
=
text
;
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
;
...
...
dist/index.umd.js.map
View file @
5cc49b8f
This diff is collapsed.
Click to expand it.
src/zeroing.js
View file @
5cc49b8f
...
@@ -19,25 +19,27 @@ const relativePosPrefixMap = {
...
@@ -19,25 +19,27 @@ const relativePosPrefixMap = {
b
:
{
field
:
'bottom'
,},
b
:
{
field
:
'bottom'
,},
h
:
{
field
:
'horizonCenter'
,},
h
:
{
field
:
'horizonCenter'
,},
v
:
{
field
:
'verticalCenter'
,},
v
:
{
field
:
'verticalCenter'
,},
wp
:
{
field
:
'width'
,
},
wp
:
{
field
:
'width'
,},
hp
:
{
field
:
'height'
,
},
hp
:
{
field
:
'height'
,},
lp
:
{
field
:
'left'
,
},
lp
:
{
field
:
'left'
,},
tp
:
{
field
:
'top'
,
},
tp
:
{
field
:
'top'
,},
rp
:
{
field
:
'right'
,
},
rp
:
{
field
:
'right'
,},
bp
:
{
field
:
'bottom'
,
},
bp
:
{
field
:
'bottom'
,},
};
};
const
offsetAll
=
176
;
const
offsetAll
=
176
;
const
enterChar
=
String
.
fromCharCode
(
13
);
export
async
function
execute
(
psdFile
,
options
)
{
export
async
function
execute
(
psdFile
,
options
)
{
const
tree
=
await
getTree
(
psdFile
);
const
tree
=
await
getTree
(
psdFile
);
const
{
mode
=
'none'
}
=
options
;
const
{
mode
=
'none'
,
singleView
=
true
}
=
options
;
let
offset
=
{
x
:
0
,
y
:
0
};
let
offset
=
{
x
:
0
,
y
:
0
};
let
cutSize
=
{
x
:
0
,
y
:
0
};
let
cutSize
=
{
x
:
0
,
y
:
0
};
if
(
mode
!==
'none'
)
{
if
(
mode
!==
'none'
)
{
cutSize
.
y
=
offsetAll
;
cutSize
.
y
=
offsetAll
;
}
}
switch
(
mode
)
{
switch
(
mode
)
{
case
'top'
:
case
'top'
:
offset
.
y
=
offsetAll
;
offset
.
y
=
offsetAll
;
break
;
break
;
...
@@ -81,7 +83,7 @@ export async function execute(psdFile, options) {
...
@@ -81,7 +83,7 @@ export async function execute(psdFile, options) {
let
items
=
relativePos
.
split
(
','
);
let
items
=
relativePos
.
split
(
','
);
for
(
let
item
of
items
)
{
for
(
let
item
of
items
)
{
let
result
=
item
.
match
(
/
[
a-zA-Z
]
+/
);
let
result
=
item
.
match
(
/
[
a-zA-Z
]
+/
);
if
(
!
result
)
{
if
(
!
result
)
{
continue
;
continue
;
}
}
let
prefix
=
result
[
0
];
let
prefix
=
result
[
0
];
...
@@ -91,8 +93,8 @@ export async function execute(psdFile, options) {
...
@@ -91,8 +93,8 @@ export async function execute(psdFile, options) {
let
value
=
item
.
substr
(
prefix
.
length
);
let
value
=
item
.
substr
(
prefix
.
length
);
let
hasValue
=
value
.
length
>
0
;
let
hasValue
=
value
.
length
>
0
;
let
fieldChar
=
prefix
[
0
];
let
fieldChar
=
prefix
[
0
];
if
(
!
hasValue
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
switch
(
fieldChar
)
{
case
'l'
:
case
'l'
:
value
=
x
-
offset
.
x
;
value
=
x
-
offset
.
x
;
break
;
break
;
...
@@ -100,30 +102,30 @@ export async function execute(psdFile, options) {
...
@@ -100,30 +102,30 @@ export async function execute(psdFile, options) {
value
=
y
-
offset
.
y
;
value
=
y
-
offset
.
y
;
break
;
break
;
case
'r'
:
case
'r'
:
value
=
stage
Width
-
(
x
-
offset
.
x
)
-
width
;
value
=
parent
Width
-
(
x
-
offset
.
x
)
-
width
;
break
;
break
;
case
'b'
:
case
'b'
:
value
=
stage
Height
-
(
y
-
offset
.
y
)
-
height
;
value
=
parent
Height
-
(
y
-
offset
.
y
)
-
height
;
break
;
break
;
case
'h'
:
case
'h'
:
value
=
x
+
width
/
2
-
stage
Width
/
2
;
value
=
x
+
width
/
2
-
parent
Width
/
2
;
break
;
break
;
case
'v'
:
case
'v'
:
value
=
y
+
height
/
2
-
stage
Height
/
2
;
value
=
y
+
height
/
2
-
parent
Height
/
2
;
break
;
break
;
}
}
}
}
let
isPercent
=
prefix
.
endsWith
(
'p'
);
let
isPercent
=
prefix
.
endsWith
(
'p'
);
if
(
isPercent
)
{
if
(
isPercent
)
{
if
(
!
hasValue
)
{
if
(
!
hasValue
)
{
switch
(
fieldChar
)
{
switch
(
fieldChar
)
{
case
'l'
:
case
'l'
:
case
'r'
:
case
'r'
:
value
/=
stage
Width
;
value
/=
parent
Width
;
break
;
break
;
case
't'
:
case
't'
:
case
'b'
:
case
'b'
:
value
/=
stage
Height
;
value
/=
parent
Height
;
break
;
break
;
}
}
value
=
Math
.
floor
(
value
*
100
);
value
=
Math
.
floor
(
value
*
100
);
...
@@ -139,7 +141,7 @@ export async function execute(psdFile, options) {
...
@@ -139,7 +141,7 @@ export async function execute(psdFile, options) {
}
}
}
}
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
);
console
.
log
(
e
);
}
}
}
}
...
@@ -150,16 +152,22 @@ export async function execute(psdFile, options) {
...
@@ -150,16 +152,22 @@ export async function execute(psdFile, options) {
uuid
:
generateUUID
(),
uuid
:
generateUUID
(),
};
};
let
dealLater
=
true
;
let
dealLater
=
true
;
if
(
x
!==
0
)
{
let
px
=
x
;
// - (!singleView && isSecondLayer ? offset.x : 0);
properties
.
x
=
x
;
// - (isSecondLayer ? offset.x : 0);
let
py
=
y
;
// - (!singleView && isSecondLayer ? offset.y : 0);
if
(
px
!==
0
)
{
properties
.
x
=
px
;
}
}
if
(
y
!==
0
)
{
if
(
p
y
!==
0
)
{
properties
.
y
=
y
;
// - (isSecondLayer ? offset.y : 0)
;
properties
.
y
=
py
;
}
}
if
(
typeTool
)
{
if
(
typeTool
)
{
let
fontInfo
=
typeTool
();
let
fontInfo
=
typeTool
();
properties
.
text
=
fontInfo
.
textValue
;
let
text
=
fontInfo
.
textValue
;
if
(
text
.
indexOf
(
enterChar
)
<
0
)
{
//如果未包含回车说明是多行,去掉宽度
delete
properties
[
'width'
];
}
properties
.
text
=
text
;
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
;
...
...
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