-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcss-compatibility.py
More file actions
95 lines (90 loc) · 2.39 KB
/
Copy pathcss-compatibility.py
File metadata and controls
95 lines (90 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#coding:utf-8
# 雅詩 CSS 相容性最佳化工具
# by 神楽坂雅詩
import sys
print("css-compatibility:")
def keyframes(fileLine):
working = False
nowLine = list()
newFile = list()
nowType = [
"@-webkit-keyframes",
"@-moz-keyframes",
"@-ms-keyframes",
"@-o-keyframes"
]
nowJob = "@keyframes"
for line in fileLine:
if nowJob in line:
print(line)
working = True
if working:
nowLine.append(line)
newFile.append(line)
if len(line) > 0 and line[0:1] == "}":
working = False
for newType in nowType:
if len(nowLine) > 0:
nowLine0 = nowLine[0]
nowLine[0] = nowLine[0].replace(nowJob, newType)
for newLine in nowLine:
newFile.append(newLine)
nowLine[0] = nowLine0
nowLine = list()
return newFile
def animation(fileLine):
working = False
nowLine = list()
newFile = list()
nowType = [
"-webkit-animation",
"-moz-animation",
"-ms-animation",
"-o-animation"
]
nowJob = "animation"
for line in fileLine:
newFile.append(line)
if nowJob in line:
print(line)
for newType in nowType:
newFile.append(line.replace(nowJob, newType))
return newFile
def transform(fileLine):
working = False
nowLine = list()
newFile = list()
nowType = [
"-webkit-transform",
"-moz-transform",
"-ms-transform",
"-o-transform"
]
nowJob = "transform"
for line in fileLine:
newFile.append(line)
if nowJob in line:
print(line)
newFile.append(line)
for newType in nowType:
newFile.append(line.replace(nowJob, newType))
return newFile
if len(sys.argv) < 3 :
print("help: css-compatibility.py <in.css> <out.css>")
quit()
f = open(sys.argv[1], 'r', encoding='utf-8')
fileLine = list()
for line in f.readlines():
fileLine.append(line)
f.close()
fileLine = keyframes(fileLine)
fileLine = animation(fileLine)
fileLine = transform(fileLine)
fw = open(sys.argv[2], 'w')
for line in fileLine:
line = line.replace("\r", "")
line = line.replace("\n", "")
fw.write(line)
fw.write("\n")
fw.close()
print("css compatibility ok")