-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
236 lines (202 loc) · 9.76 KB
/
index.html
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<!-- saved from url=(0036)https://css.github.io/csso/csso.html -->
<html style=""><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CSSO – CSS optimizer</title>
<link rel="stylesheet" href="./CSSO – CSS optimizer_files/csso.css" type="text/css">
</head>
<body style="background: rgb(23, 23, 23) !important;">
<script src="./CSSO – CSS optimizer_files/csso.min.js.Без названия"></script>
<script src="./CSSO – CSS optimizer_files/cssbeautify.js.Без названия"></script>
<script src="./CSSO – CSS optimizer_files/base64.js.Без названия"></script>
<script src="./CSSO – CSS optimizer_files/diff.js.Без названия"></script>
<div class="layout">
<div class="toolbar" style="background: rgb(0, 115, 0) !important;">
toolbar
</div>
<div class="main">
<div class="main-section">
<div class="header" style="background: rgb(2, 77, 127) !important;">
<span class="caption">Source</span>
<button id="beautifySource" style="background: rgb(43, 43, 43) !important;">Beautify</button>
</div>
<textarea id="source" class="editor" style="background: rgb(23, 23, 23) !important;">.foo { color: #ff0000; }
.bar { color: rgba(255, 0, 0, 1); }</textarea>
</div>
<div class="main-section" id="result">
<div class="header" style="background: rgb(2, 77, 127) !important;">
<span class="caption">Result</span>
<label for="sourceMap">
<input type="checkbox" id="sourceMap"> Source map
</label>
<label for="restructure">
<input type="checkbox" id="restructure" checked=""> Restructure
</label>
<label for="beautify">
<input type="checkbox" id="beautify"> Beautify
</label>
</div>
<div id="output" class="output">.bar,.foo{color:red}</div>
<div id="change-log">
<div class="header" style="background: rgb(59, 65, 71) !important;">Show transformations</div>
<div id="transformations" class="content" style="background: rgb(44, 44, 45) !important;"><h2 style="background: rgb(23, 23, 23) !important;">result</h2><div class="delta"></div></div>
</div>
<div class="stat-block" style="background: rgb(52, 56, 60) !important;">
<div id="stat">Original: 60 bytes
Compressed: 20 bytes (33.33%)
Saving: 40 bytes (66.67%)
Time: 35 ms</div>
<div class="powered">
Powered by <a href="https://github.com/css/csso">CSSO</a> <span id="version">4.0.2</span>
</div>
</div>
<div id="error" style="background: rgb(23, 23, 23) !important;">
<div class="header" style="background: rgb(174, 24, 24) !important;">
<span class="caption">Error</span>
</div>
<div id="errorMessage"></div>
</div>
</div>
</div>
</div>
<script>
var lastSource;
var lastResult;
var lastResultMap;
function beautifySourceCSS() {
source.value = cssbeautify(source.value);
}
function setText(element, text) {
element.innerHTML = '';
element.appendChild(document.createTextNode(text));
}
function processParseError(source, details, message) {
function formatLines(start, end) {
return lines.slice(start, end).map(function(line, idx) {
var num = String(start + idx + 1);
while (num.length < maxNumLength) {
num = ' ' + num;
}
return num + ' |' + line;
}).join('\n');
}
var lines = source.split(/\n|\r\n?|\f/);
var column = details.column;
var line = details.line;
var startLine = Math.max(1, line - 3);
var endLine = Math.min(line + 3, lines.length + 1);
var maxNumLength = Math.max(4, String(endLine).length) + 1;
return [
'CSS parse error: ' + message + '\n',
formatLines(startLine - 1, line),
new Array(column + maxNumLength + 2).join('-') + '^',
formatLines(line, endLine)
].join('\n');
}
function updateStat(originalSize, resultSize, time) {
function percent(value) {
return value ? ' (' + (100 * value).toFixed(2) + '%)' : '';
}
var delta = originalSize - resultSize;
stat.innerHTML =
'Original: ' + originalSize + ' bytes\n' +
'Compressed: ' + resultSize + ' bytes' + percent(resultSize / originalSize) + '\n' +
'Saving: ' + delta + ' bytes' + percent(delta / originalSize) + '\n' +
'Time: ' + time + ' ms';
}
function setOutput() {
var css = lastResult;
if (sourceMap.checked && lastResultMap) {
css += '\n/*# sourceMappingURL=application/json;base64,' + Base64.encode(lastResultMap) + ' */';
} else if (beautify.checked) {
css = cssbeautify(css);
}
setText(output, css);
}
function outputChanges(steps) {
var lastStep = '';
var transformations = '';
if (result.classList.contains('show-transformations')) {
steps.forEach(function(item) {
if (item.css !== lastStep && lastStep) {
// transformations += '<span class="delta empty-delta">(no transformations)</span><br/>';
transformations += '<h2>' + item.name + '</h2>';
transformations +=
'<div class="delta">' +
JsDiff.diffCss(lastStep, item.css).map(function(chunk) {
if (chunk.removed) {
return '<span class="removed">' + chunk.value + '</span>';
} else if (chunk.added) {
return '<span class="added">' + chunk.value + '</span>';
} else {
return chunk.value;
}
}).join('') +
'</div>';
}
lastStep = item.css;
});
}
document.getElementById('transformations').innerHTML =
transformations +
'<h2>result</h2><div class="delta">' +
lastStep +
'</div>';
}
function process(force) {
var time;
if (force !== true && source.value === lastSource) {
return;
}
beautify.disabled = sourceMap.checked;
var time = (window.performance || Date).now();
var steps = [];
try {
lastSource = source.value;
lastResult = csso.minify(source.value, {
restructure: restructure.checked,
sourceMap: sourceMap.checked,
logger: function(name, ast) {
if (ast) {
steps.push({
name: name,
css: csso.syntax.generate(ast)
});
}
}
});
lastResultMap = lastResult.map ? lastResult.map.toString() : null;
lastResult = lastResult.css;
error.classList.remove('show');
} catch(e) {
if (e.parseError) {
setText(errorMessage, processParseError(source.value, e.parseError, e.message));
} else {
setText(errorMessage, e.message);
}
error.classList.add('show');
return;
}
updateStat(
lastSource.length,
lastResult.length,
Math.round((window.performance || Date).now() - time)
);
setOutput();
outputChanges(steps);
}
source.addEventListener('input', process, false);
source.addEventListener('keyup', process, false);
beautifySource.addEventListener('click', beautifySourceCSS, false);
beautify.addEventListener('change', setOutput, false);
restructure.addEventListener('change', process.bind(null, true), false);
sourceMap.addEventListener('change', process.bind(null, true), false);
document.querySelector('#change-log .header').addEventListener('click', function() {
result.classList.toggle('show-transformations');
if (result.classList.contains('show-transformations')) {
process(true);
}
}, false);
document.getElementById('version').innerHTML = csso.version;
process();
</script>
</body><link type="text/css" id="dma-temp-global-css" class="dmn-custom-append-data" rel="stylesheet" href="chrome-extension://bhbekkddpbpbibiknkcjamlkhoghieie/css/global-new.css"><link type="text/css" id="dma-universal-css" class="dmn-custom-append-data" rel="stylesheet" href="chrome-extension://bhbekkddpbpbibiknkcjamlkhoghieie/css/universal.css"></html>