-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathCSS_stringify.html
234 lines (191 loc) · 6.36 KB
/
CSS_stringify.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>CSS.stringify()</title>
<link href="jsoneditor/jsoneditor.min.css" rel="stylesheet" type="text/css">
<script src="jsoneditor/jsoneditor.min.js"></script>
<script src="cssparser.min.js?cachebust=20170317"></script>
<script>
window.onload = function() {
// create the editor
var sourceOptions = {
"mode": "text",
"indentation": 2
};
var sourceEditor = new JSONEditor(document.getElementById("source"), sourceOptions);
var treeOptions = {
"mode": "code",
"indentation": 2
};
var treeEditor = new JSONEditor(document.getElementById("json"), treeOptions);
var transform = function(type) {
try {
var sourceText = sourceEditor.getText()
var ast = cssparser.parse(sourceText);
if (ast) {
document.getElementById("result").innerHTML = "CSS is valid!";
document.getElementById("result").className = "pass";
treeEditor.set(ast.toJSON(type));
}
} catch (e) {
document.getElementById("result").innerHTML = e;
document.getElementById("result").className = "fail";
}
}
document.getElementById("button-atomic").onclick = function() {
transform('atomic')
};
document.getElementById("button-deep").onclick = function() {
transform('deep')
};
document.getElementById("button-simple").onclick = function() {
transform('simple')
};
// load CSS preset for testing.
sourceEditor.setText(document.getElementById('preset').value)
}
</script>
<style>
body {
font-family: sans-serif;
}
.editorContainer {
overflow: hidden;
width: 100%;
height: 100%;
}
.left {
float: left;
}
.right {
float: right;
}
.editor {
width: calc(50% - 5px);
height: 600px;
}
#result {
padding: 1em;
}
.controls {
padding: 1em;
}
.pass {
background-color: #efe;
color: #393;
border: 2px solid #393;
}
.fail {
background-color: #fee;
color: #933;
border: 2px solid #933;
}
#preset {
display: none;
}
</style>
</head>
<body>
<h1>CSS.stringify()</h1>
<p>
<img src="https://img.shields.io/github/issues-raw/cwdoh/cssparser.js.svg" alt="Issues">
<img src="https://img.shields.io/github/issues-closed-raw/cwdoh/cssparser.js.svg" alt="Closed issues">
<img src="https://img.shields.io/github/issues-pr-raw/cwdoh/cssparser.js.svg" alt="Pull Requests">
<img src="https://img.shields.io/github/issues-pr-closed-raw/cwdoh/cssparser.js.svg" alt="Closed Pull Requests">
<img src="https://img.shields.io/github/contributors/cwdoh/cssparser.js.svg" alt="Contributors">
</p>
<p>'CSS.stringify()' supports to transform CSS Document to JSON style.</p>
<p>This project is based on cssparser.js(<a href="//github.com/cwdoh/cssparser.js">Project on github</a>, <a href="//cwdoh.github.com/cssparser.js">Project site</a>).</p>
<p>
Thanks to <a href="https://github.com/josdejong/jsoneditor">JSONEditor</a> for using great Source/JSON Editor at this demo.
</p>
<div class="editorContainer">
<div id="source" class="editor left"></div>
<div id="json" class="editor right"></div>
</div>
<div class="controls">
<button id="button-atomic">Transform (Atomic)</button>
<button id="button-deep">Transform (Deep)</button>
<button id="button-simple">Transform (Simple)</button>
<h2>Results</h2>
<pre id="result"></pre>
</div>
<!--[if !IE]><script>fixScale(document);</script><![endif]-->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-40929587-1");
pageTracker._trackPageview();
} catch (err) {}
</script>
<textarea id="preset">
/* Sample at-rule CSS @CSSTricks.com [1]
*
* [1] https://css-tricks.com/the-at-rules-of-css/
*/
@charset "UTF-8";
@import 'global.css';
/* Namespace for XHTML */
@namespace url(http://www.w3.org/1999/xhtml);
/* Namespace for SVG embedded in XHTML */
@namespace svg url(http://www.w3.org/2000/svg);
@document
/* Rules for a specific page */
url(http://css-tricks.com/),
/* Rules for pages with a URL that begin with... */
url-prefix(http://css-tricks.com/snippets/),
/* Rules for any page hosted on a domain */
domain(css-tricks.com),
/* Rules for all secure pages */
regexp("https:.*")
{
/* Start styling */
body { font-family: Comic Sans; }
}
@font-face {
font-family: 'MyWebFont';
src: url('myfont.woff2') format('woff2'),
url('myfont.woff') format('woff');
}
@keyframes pulse {
0% {
background-color: #001f3f;
}
end {
background-color: #ff4136;
}
}
/* iPhone in Portrait and Landscape */
@media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2) {
.module { width: 100%; }
}
@media print {
}
@page :first {
margin: 1in;
}
/* Check one supported condition */
@supports (display: flex) {
.module { display: flex; }
}
/* Check multiple conditions */
@supports (display: flex) and (-webkit-appearance: checkbox) {
.module { display: flex; }
}
</textarea>
<p>
<img src="https://img.shields.io/github/forks/cwdoh/cssparser.js.svg?style=social&label=Fork" alt="Fork">
<img src="https://img.shields.io/github/stars/cwdoh/cssparser.js.svg?style=social&label=Star" alt="Star">
<img src="https://img.shields.io/github/watchers/cwdoh/cssparser.js.svg?style=social&label=Watch" alt="Watch">
<img src="https://img.shields.io/npm/dm/cssparser.svg" alt="npm downloads in the last month">
<img src="https://img.shields.io/npm/dt/cssparser.svg" alt="npm total downloads">
</p>
</body>
</html>