File tree Expand file tree Collapse file tree 1 file changed +70
-0
lines changed
Expand file tree Collapse file tree 1 file changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ import { EnumToken } from '../ast/types.js' ;
2+ import '../ast/minify.js' ;
3+ import '../ast/walk.js' ;
4+ import '../parser/parse.js' ;
5+ import '../parser/tokenize.js' ;
6+ import '../parser/utils/config.js' ;
7+ import './color/utils/constants.js' ;
8+ import '../renderer/sourcemap/lib/encode.js' ;
9+
10+ function length2Px ( value ) {
11+ let result = null ;
12+ if ( value . typ == EnumToken . NumberTokenType ) {
13+ result = + value . val ;
14+ }
15+ else {
16+ switch ( value . unit ) {
17+ case 'cm' :
18+ // @ts -ignore
19+ result = value . val * 37.8 ;
20+ break ;
21+ case 'mm' :
22+ // @ts -ignore
23+ result = value . val * 3.78 ;
24+ break ;
25+ case 'Q' :
26+ // @ts -ignore
27+ result = value . val * 37.8 / 40 ;
28+ break ;
29+ case 'in' :
30+ // @ts -ignore
31+ result = value . val / 96 ;
32+ break ;
33+ case 'pc' :
34+ // @ts -ignore
35+ result = value . val / 16 ;
36+ break ;
37+ case 'pt' :
38+ // @ts -ignore
39+ result = value . val * 4 / 3 ;
40+ break ;
41+ case 'px' :
42+ result = + value . val ;
43+ break ;
44+ }
45+ }
46+ return isNaN ( result ) ? null : result ;
47+ }
48+ /**
49+ * minify number
50+ * @param val
51+ */
52+ function minifyNumber ( val ) {
53+ val = String ( + val ) ;
54+ if ( val === '0' ) {
55+ return '0' ;
56+ }
57+ const chr = val . charAt ( 0 ) ;
58+ if ( chr == '-' ) {
59+ const slice = val . slice ( 0 , 2 ) ;
60+ if ( slice == '-0' ) {
61+ return val . length == 2 ? '0' : '-' + val . slice ( 2 ) ;
62+ }
63+ }
64+ if ( chr == '0' ) {
65+ return val . slice ( 1 ) ;
66+ }
67+ return val ;
68+ }
69+
70+ export { length2Px , minifyNumber } ;
You can’t perform that action at this time.
0 commit comments