15 | This extension works in the devtools environment, so it can read the resources information. You will need to restart your browser or re-open the devtools panel, and switch to the Resources Saver tab.
16 |
17 |
18 | All resources will be saved in the "Downloads" folder as (<DOMAIN>).
19 |
20 |
21 | Tick "Download from all domains ..." to download all resources from all domains.
22 |
23 |
24 | If "Compress all assets ... (Recommended)" is ticked, all resources will be added into one compressed file as (<DOMAIN>.zip).
25 |
26 |
27 | If you want to manually save the file(s), enable the option in Main Menu > Settings > Downloads > "Ask where to save each file before downloading".
28 |
67 | H2
68 | Donec lacinia, felis nec sagittis feugiat
69 |
70 |
71 | H3
72 | Sed ullamcorper tincidunt libero, sed tempus sem rhoncus non.
73 |
74 |
75 | H4
76 | Etiam in nulla eros, quis laoreet orci. Morbi ullamcorper tempor nunc sed ullamcorper.
77 |
78 |
79 | DEFAULT
80 | In hac habitasse platea dictumst. Sed hendrerit scelerisque pellentesque. Suspendisse id eros quis sem tristique varius sed eget velit. Phasellus pellentesque ipsum non quam vulputate euismod. Nullam eget viverra lorem. Ut eu tortor metus. Mauris eget quam nulla, eu suscipit magna. Nullam vitae lectus quam, a consequat tortor. Ut sed arcu arcu. Aliquam aliquet lacinia lorem, id tristique nunc pulvinar eget.
81 |
82 |
83 | SMALL
84 |
85 | Proin volutpat, magna at vehicula blandit, massa lectus aliquam dolor, ut porta magna odio eu nunc. Nam nisi diam, commodo vitae hendrerit non, consequat sed est. Proin fringilla, nunc non vulputate hendrerit, turpis purus vestibulum diam, a venenatis nunc lectus nec quam. Quisque euismod fermentum mauris, at accumsan mi pulvinar in. Fusce libero lectus, fringilla non congue vel, cursus nec metus. Nunc ac ante quam.
86 |
87 |
88 |
89 | BIG
90 |
91 | Curabitur auctor orci vel felis sodales porttitor. Aenean non neque auctor tellus suscipit vulputate ut quis nunc. Integer tellus purus, venenatis a cursus nec, vestibulum eget turpis. Nulla pulvinar dictum elit, vulputate sodales nunc laoreet eget. Aliquam vitae urna ac risus scelerisque iaculis.
92 |
93 |
94 |
95 |
96 |
97 |
98 | H1
99 | Dosis-Book
100 |
101 |
102 | H2
103 | Donec lacinia, felis nec sagittis feugiat
104 |
105 |
106 | H3
107 | Sed ullamcorper tincidunt libero, sed tempus sem rhoncus non.
108 |
109 |
110 | H4
111 | Etiam in nulla eros, quis laoreet orci. Morbi ullamcorper tempor nunc sed ullamcorper.
112 |
113 |
114 | DEFAULT
115 | In hac habitasse platea dictumst. Sed hendrerit scelerisque pellentesque. Suspendisse id eros quis sem tristique varius sed eget velit. Phasellus pellentesque ipsum non quam vulputate euismod. Nullam eget viverra lorem. Ut eu tortor metus. Mauris eget quam nulla, eu suscipit magna. Nullam vitae lectus quam, a consequat tortor. Ut sed arcu arcu. Aliquam aliquet lacinia lorem, id tristique nunc pulvinar eget.
116 |
117 |
118 | SMALL
119 |
120 | Proin volutpat, magna at vehicula blandit, massa lectus aliquam dolor, ut porta magna odio eu nunc. Nam nisi diam, commodo vitae hendrerit non, consequat sed est. Proin fringilla, nunc non vulputate hendrerit, turpis purus vestibulum diam, a venenatis nunc lectus nec quam. Quisque euismod fermentum mauris, at accumsan mi pulvinar in. Fusce libero lectus, fringilla non congue vel, cursus nec metus. Nunc ac ante quam.
121 |
122 |
123 |
124 | BIG
125 |
126 | Curabitur auctor orci vel felis sodales porttitor. Aenean non neque auctor tellus suscipit vulputate ut quis nunc. Integer tellus purus, venenatis a cursus nec, vestibulum eget turpis. Nulla pulvinar dictum elit, vulputate sodales nunc laoreet eget. Aliquam vitae urna ac risus scelerisque iaculis.
127 |
128 |
129 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/src/styles.css:
--------------------------------------------------------------------------------
1 | @import url("https://fonts.googleapis.com/css?family=Dosis:400,600");
2 |
3 | @keyframes fadeInDown {
4 | from {
5 | opacity: 0;
6 | transform: translate3d(0, -100px, 0);
7 | }
8 | to {
9 | opacity: 1;
10 | transform: translate3d(0, 0, 0);
11 | }
12 | }
13 |
14 | @keyframes fadeInLeft {
15 | from {
16 | opacity: 0;
17 | transform: translate3d(-100px, 0, 0);
18 | }
19 | to {
20 | opacity: 1;
21 | transform: translate3d(0, 0, 0);
22 | }
23 | }
24 |
25 | @keyframes dimming {
26 | 0% {
27 | opacity: 1;
28 | transform: scale(1);
29 | }
30 | 50% {
31 | opacity: 0.85;
32 | transform: scale(0.95);
33 | }
34 | 100% {
35 | opacity: 1;
36 | transform: scale(1);
37 | }
38 | }
39 |
40 | html, body {
41 | font-family: 'Dosis', Helvetica, Tahoma, sans-serif;
42 | font-weight: 400;
43 | font-size: 14px;
44 | letter-spacing: 0.25px;
45 | background: #FFFFFF;
46 | }
47 |
48 | * {
49 | margin: 0;
50 | padding: 0;
51 | outline: 0;
52 | }
53 |
54 | ul {
55 | margin: 0;
56 | padding: 10px 10px;
57 | }
58 |
59 | ul li {
60 | list-style: none;
61 | margin: 0;
62 | padding: 0 0 10px 0;
63 | }
64 |
65 | input[type=checkbox] {
66 | width: 15px;
67 | height: 15px;
68 | cursor: pointer;
69 | }
70 |
71 | label, button {
72 | cursor: pointer;
73 | }
74 |
75 | a {
76 | outline: none;
77 | text-decoration: none;
78 | transition: all .3s ease-out;
79 | color: DarkGreen;
80 | }
81 |
82 | a:visited {
83 | color: #551a8b;
84 | }
85 |
86 | a:hover {
87 | color: #551a8b;
88 | }
89 |
90 | #options {
91 | padding: 10px 0px;
92 | }
93 |
94 | .popup-body {
95 | background-color: #EEE;
96 | }
97 |
98 | .up-popup {
99 | width: 300px;
100 | padding: 15px 25px 15px 15px;
101 | border-radius: 3px;
102 | margin: 5px;
103 | box-shadow: #EEE 0px 0px 0px 5px;
104 | background-color: white;
105 | animation: fadeInDown 1s both cubic-bezier(0.1, 0.71, 0.28, 1.14) 0s 1;
106 | }
107 |
108 | .up-popup .heading {
109 | padding: 10px 0;
110 | animation: fadeInDown 0.75s both cubic-bezier(0.1, 0.71, 0.28, 1.14) 0s 1;
111 | position: relative;
112 | }
113 |
114 | .up-popup .heading::after {
115 | width: 100%;
116 | height: 2px;
117 | background-color: #EEE;
118 | position: absolute;
119 | content: '';
120 | bottom: 0;
121 | left: 0;
122 | animation: fadeInDown 0.5s both cubic-bezier(0.1, 0.71, 0.28, 1.14) 0.1s 1;
123 | }
124 |
125 | .up-popup a {
126 | animation: fadeInLeft 0.75s both cubic-bezier(0.1, 0.71, 0.28, 1.14) 0.2s 1;
127 | }
128 |
129 | .up-popup ul li:nth-child(1) {
130 | animation: fadeInDown 0.75s both cubic-bezier(0.1, 0.71, 0.28, 1.14);
131 | animation-delay: 0.2s;
132 | }
133 |
134 | .up-popup ul li:nth-child(2) {
135 | animation: fadeInDown 0.75s both cubic-bezier(0.1, 0.71, 0.28, 1.14);
136 | animation-delay: 0.3s;
137 | }
138 |
139 | .up-popup ul li:nth-child(3) {
140 | animation: fadeInDown 0.75s both cubic-bezier(0.1, 0.71, 0.28, 1.14);
141 | animation-delay: 0.4s;
142 | }
143 |
144 | .up-popup ul li:nth-child(4) {
145 | animation: fadeInDown 0.75s both cubic-bezier(0.1, 0.71, 0.28, 1.14);
146 | animation-delay: 0.5s;
147 | }
148 |
149 | .up-popup ul li:nth-child(5) {
150 | animation: fadeInDown 0.75s both cubic-bezier(0.1, 0.71, 0.28, 1.14);
151 | animation-delay: 0.6s;
152 | }
153 |
154 | .up-popup ul li:nth-child(6) {
155 | animation: fadeInDown 0.75s both cubic-bezier(0.1, 0.71, 0.28, 1.14);
156 | animation-delay: 0.7s;
157 | }
158 |
159 | .up-popup ul li:nth-child(7) {
160 | animation: fadeInDown 0.75s both cubic-bezier(0.1, 0.71, 0.28, 1.14);
161 | animation-delay: 0.8s;
162 | }
163 |
164 | .up-popup ul li:nth-child(8) {
165 | animation: fadeInDown 0.75s both cubic-bezier(0.1, 0.71, 0.28, 1.14);
166 | animation-delay: 0.9s;
167 | }
168 |
169 | .up-popup ul li:nth-child(9) {
170 | animation: fadeInDown 0.75s both cubic-bezier(0.1, 0.71, 0.28, 1.14);
171 | animation-delay: 1s;
172 | }
173 |
174 | .up-popup ul li:nth-child(10) {
175 | animation: fadeInDown 0.75s both cubic-bezier(0.1, 0.71, 0.28, 1.14);
176 | animation-delay: 1.1s;
177 | }
178 |
179 | .sub-title {
180 | color: #888;
181 | font-size: 12px;
182 | font-weight: 600;
183 | display: block;
184 | text-align: right;
185 | }
186 |
187 | .up-content {
188 | padding: 30px;
189 | text-align: left;
190 | min-width: 380px;
191 | }
192 |
193 | .up-content h1 {
194 | padding: 10px 0;
195 | border-bottom: 1px solid #EEE;
196 | display: flex;
197 | justify-content: space-between;
198 | align-items: center;
199 | }
200 |
201 | .up-content h1 button {
202 | margin-left: 10px;
203 | padding: 5px 30px;
204 | height: 30px;
205 | background-color: RoyalBlue;
206 | vertical-align: text-bottom;
207 | font-style: bold;
208 | }
209 |
210 | .up-content button {
211 | display: inline-block;
212 | vertical-align: text-top;
213 | border: 0;
214 | background-color: #2aa32a;
215 | color: white;
216 | padding: 5px 10px;
217 | transition: all .3s ease-out;
218 | animation: fadeInLeft 1s both cubic-bezier(0.1, 0.71, 0.28, 1.14) 0s 1;
219 | }
220 |
221 | .up-content button:hover {
222 | background-color: RoyalBlue;
223 | }
224 |
225 | .up-content button[disabled] {
226 | animation: dimming 2s both ease-in-out 0s infinite;
227 | background-color: #222222;
228 | }
229 |
230 | .up-content #debug p {
231 | background-color: #EEE;
232 | padding: 15px;
233 | transition: all 0.5s cubic-bezier(0.1, 0.71, 0.28, 1.14);
234 | border-bottom: 2px solid #FFF;
235 | animation: fadeInDown 1s both cubic-bezier(0.1, 0.71, 0.28, 1.14) 0s 1;
236 | }
237 |
238 | .up-content #debug p.all-done {
239 | background-color: #e0f2de;
240 | }
241 |
242 | .up-content #debug ul {
243 | transition: all 0.5s cubic-bezier(0.1, 0.71, 0.28, 1.14);
244 | display: flex;
245 | flex-flow: row nowrap;
246 | padding: 0;
247 | animation: fadeInLeft 1s both cubic-bezier(0.1, 0.71, 0.28, 1.14) 0s 1;
248 | }
249 |
250 | .up-content #debug ul.each-done {
251 | border-bottom: 1px solid rgba(0, 128, 0, 0.5);
252 | }
253 |
254 | .up-content #debug ul.each-failed {
255 | border-bottom: 1px solid rgba(255, 0, 0, 0.5);
256 | }
257 |
258 | .up-content #debug ul li {
259 | padding: 15px;
260 | animation: fadeInLeft 1s both cubic-bezier(0.1, 0.71, 0.28, 1.14) 0.05s 1;
261 | }
262 |
263 | .up-content #debug ul li:nth-child(1) {
264 | flex: 0 0 50px;
265 | background-color: rgba(255, 236, 186, 0.5);
266 | text-align: right;
267 | animation: fadeInLeft 1s both cubic-bezier(0.1, 0.71, 0.28, 1.14) 0.1s 1;
268 | }
269 |
270 | .up-content #debug ul li:nth-child(2) {
271 | flex: 0 0 70px;
272 | background-color: rgba(255, 243, 214, 0.5);
273 | animation: fadeInLeft 1s both cubic-bezier(0.1, 0.71, 0.28, 1.14) 0.15s 1;
274 | }
275 |
276 | .up-content #debug ul li:nth-child(3) {
277 | flex: 1;
278 | word-break: break-all;
279 | background-color: rgba(255, 251, 242, 0.5);
280 | animation: fadeInLeft 1s both cubic-bezier(0.1, 0.71, 0.28, 1.14) 0.2s 1;
281 | }
282 |
283 | #refresh {
284 | position: absolute;
285 | top: 45px;
286 | left: 218px;
287 | padding: 5px;
288 | border-radius: 50%;
289 | cursor: pointer;
290 | transition: all .3s ease-out;
291 | }
292 |
293 | #refresh #refresh-tip {
294 | display: block;
295 | position: absolute;
296 | font-size: 11px;
297 | width: 200px;
298 | left: -90px;
299 | top: -20px;
300 | padding: 5px 5px 5px 10px;
301 | background-color: indianred;
302 | color: white;
303 | opacity: 0;
304 | transition: all .5s cubic-bezier(0.1, 0.71, 0.28, 1.14);
305 | }
306 |
307 | #refresh img {
308 | transition: all .3s cubic-bezier(0.1, 0.71, 0.28, 1.14);
309 | }
310 |
311 | #refresh:hover {
312 | background-color: rgba(0, 0, 0, 0.1);
313 | }
314 |
315 | #refresh:hover #refresh-tip {
316 | top: -32px;
317 | opacity: 1;
318 | }
319 |
320 | #refresh:hover img {
321 | transform: rotate(180deg);
322 | }
323 |
324 |
325 | #up-save {
326 |
327 | }
328 |
329 | #list-sites {
330 | padding: 10px 0;
331 | list-style: none;
332 | }
333 |
334 | #list-sites > li {
335 | padding: 10px 10px 10px 40px;
336 | margin-bottom: 5px;
337 | background-color: #EFEFEF;
338 | position: relative;
339 | line-break: anywhere;
340 | }
341 |
342 | #list-sites > li::before {
343 | content: "W";
344 | display: flex;
345 | font-weight: bold;
346 | flex-flow: row nowrap;
347 | justify-content: center;
348 | align-items: center;
349 | width: 32px;
350 | height: 32px;
351 | border-radius: 50%;
352 | position: absolute;
353 | top: calc(50% - 16px);
354 | left: 4px;
355 | }
356 |
357 | #list-sites > li.is-downloading {
358 | background: #f2f0de;
359 | }
360 |
361 | #list-sites > li.is-downloading::before {
362 | content: "";
363 | background: url("./loading.svg") center center no-repeat;
364 | background-size: cover;
365 | }
366 |
367 | #list-sites > li.is-downloaded {
368 | background: #e0f2de;
369 | }
370 |
371 | #list-sites > li.is-downloaded::before {
372 | content: "D";
373 | background: none;
374 | }
375 |
376 | #list-sites > li.is-failed {
377 | background: #f2dede;
378 | }
379 |
380 | #list-sites > li.is-failed::before {
381 | content: "F";
382 | background: none;
383 | }
384 |
385 | #list-input-modal {
386 | width: 100vw;
387 | height: 100vh;
388 | position: fixed;
389 | display: flex;
390 | flex-flow: row nowrap;
391 | justify-content: center;
392 | align-items: center;
393 | z-index: -1;
394 | top: 0;
395 | left: 0;
396 | background-color: rgba(0, 0, 0, 0.15);
397 | pointer-events: none;
398 | opacity: 0;
399 | transition: opacity .15s ease-out;
400 | }
401 |
402 | #list-input-modal.showed {
403 | z-index: 999;
404 | pointer-events: all;
405 | opacity: 1;
406 | }
407 |
408 | #list-input-modal-container {
409 | position: relative;
410 | padding: 20px;
411 | border-radius: 3px;
412 | background: #FFFFFF;
413 | box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.25);
414 | transform: translate(0, -30px);
415 | transition: transform 0.3s cubic-bezier(0.1, 0.71, 0.28, 1.14);
416 | }
417 |
418 | #list-input-modal.showed #list-input-modal-container {
419 | transform: translate(0, 0);
420 | }
421 |
422 | #list-input-modal-container > div.button-group {
423 | position: absolute;
424 | z-index: 1;
425 | top: 20px;
426 | right: 20px;
427 | background: white;
428 | padding: 0;
429 | }
430 |
431 | #list-input-modal-container button {
432 | background-color: #2aa32a;
433 | border: none;
434 | color: white;
435 | padding: 5px 10px;
436 | border-radius: 1px;
437 | transition: background-color .15s ease-out;
438 | }
439 |
440 | #list-input-modal-container button.modal-okay:hover {
441 | background-color: RoyalBlue;
442 | }
443 |
444 | #list-input-modal-container button.modal-close {
445 | background-color: rgba(0, 0, 0, 0.05);
446 | color: black;
447 | }
448 |
449 | #list-input-area {
450 | width: 80vw;
451 | height: 500px;
452 | margin-top: 10px;
453 | background-color: rgba(0, 0, 0, 0.05);
454 | border: none;
455 | border-radius: 3px;
456 | box-sizing: border-box;
457 | padding: 20px;
458 | }
459 |
460 | #status {
461 | margin-bottom: 10px;
462 | background-color: #EFEFEF;
463 | padding: 10px 10px 10px 15px;
464 | word-break: break-all;
465 | word-wrap: break-word;
466 | font-style: italic;
467 | }
468 |
469 | #open-folder {
470 | margin: 10px 0 0 0;
471 | padding: 20px 0;
472 | border-top: 1px dashed #EFEFEF;
473 | }
474 |
475 | #version {
476 | font-size: 10px;
477 | position: absolute;
478 | top: 30px;
479 | left: 30px;
480 | color: Blue;
481 | pointer-events: none;
482 | }
483 |
484 | .success {
485 | color: DarkGreen;
486 | }
487 |
488 | .failed {
489 | color: red;
490 | }
491 |
--------------------------------------------------------------------------------
/src/zip/zip.js:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2013 Gildas Lormeau. All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | 1. Redistributions of source code must retain the above copyright notice,
8 | this list of conditions and the following disclaimer.
9 |
10 | 2. Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in
12 | the documentation and/or other materials provided with the distribution.
13 |
14 | 3. The names of the authors may not be used to endorse or promote products
15 | derived from this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
18 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
20 | INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 | OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 | */
28 |
29 | (function(obj) {
30 | "use strict";
31 |
32 | var ERR_BAD_FORMAT = "File format is not recognized.";
33 | var ERR_CRC = "CRC failed.";
34 | var ERR_ENCRYPTED = "File contains encrypted entry.";
35 | var ERR_ZIP64 = "File is using Zip64 (4gb+ file size).";
36 | var ERR_READ = "Error while reading zip file.";
37 | var ERR_WRITE = "Error while writing zip file.";
38 | var ERR_WRITE_DATA = "Error while writing file data.";
39 | var ERR_READ_DATA = "Error while reading file data.";
40 | var ERR_DUPLICATED_NAME = "File already exists.";
41 | var CHUNK_SIZE = 512 * 1024;
42 |
43 | var TEXT_PLAIN = "text/plain";
44 |
45 | var appendABViewSupported;
46 | try {
47 | appendABViewSupported = new Blob([ new DataView(new ArrayBuffer(0)) ]).size === 0;
48 | } catch (e) {
49 | }
50 |
51 | function Crc32() {
52 | this.crc = -1;
53 | }
54 | Crc32.prototype.append = function append(data) {
55 | var crc = this.crc | 0, table = this.table;
56 | for (var offset = 0, len = data.length | 0; offset < len; offset++)
57 | crc = (crc >>> 8) ^ table[(crc ^ data[offset]) & 0xFF];
58 | this.crc = crc;
59 | };
60 | Crc32.prototype.get = function get() {
61 | return ~this.crc;
62 | };
63 | Crc32.prototype.table = (function() {
64 | var i, j, t, table = []; // Uint32Array is actually slower than []
65 | for (i = 0; i < 256; i++) {
66 | t = i;
67 | for (j = 0; j < 8; j++)
68 | if (t & 1)
69 | t = (t >>> 1) ^ 0xEDB88320;
70 | else
71 | t = t >>> 1;
72 | table[i] = t;
73 | }
74 | return table;
75 | })();
76 |
77 | // "no-op" codec
78 | function NOOP() {}
79 | NOOP.prototype.append = function append(bytes, onprogress) {
80 | return bytes;
81 | };
82 | NOOP.prototype.flush = function flush() {};
83 |
84 | function blobSlice(blob, index, length) {
85 | if (index < 0 || length < 0 || index + length > blob.size)
86 | throw new RangeError('offset:' + index + ', length:' + length + ', size:' + blob.size);
87 | if (blob.slice)
88 | return blob.slice(index, index + length);
89 | else if (blob.webkitSlice)
90 | return blob.webkitSlice(index, index + length);
91 | else if (blob.mozSlice)
92 | return blob.mozSlice(index, index + length);
93 | else if (blob.msSlice)
94 | return blob.msSlice(index, index + length);
95 | }
96 |
97 | function getDataHelper(byteLength, bytes) {
98 | var dataBuffer, dataArray;
99 | dataBuffer = new ArrayBuffer(byteLength);
100 | dataArray = new Uint8Array(dataBuffer);
101 | if (bytes)
102 | dataArray.set(bytes, 0);
103 | return {
104 | buffer : dataBuffer,
105 | array : dataArray,
106 | view : new DataView(dataBuffer)
107 | };
108 | }
109 |
110 | // Readers
111 | function Reader() {
112 | }
113 |
114 | function TextReader(text) {
115 | var that = this, blobReader;
116 |
117 | function init(callback, onerror) {
118 | var blob = new Blob([ text ], {
119 | type : TEXT_PLAIN
120 | });
121 | blobReader = new BlobReader(blob);
122 | blobReader.init(function() {
123 | that.size = blobReader.size;
124 | callback();
125 | }, onerror);
126 | }
127 |
128 | function readUint8Array(index, length, callback, onerror) {
129 | blobReader.readUint8Array(index, length, callback, onerror);
130 | }
131 |
132 | that.size = 0;
133 | that.init = init;
134 | that.readUint8Array = readUint8Array;
135 | }
136 | TextReader.prototype = new Reader();
137 | TextReader.prototype.constructor = TextReader;
138 |
139 | function Data64URIReader(dataURI) {
140 | var that = this, dataStart;
141 |
142 | function init(callback) {
143 | var dataEnd = dataURI.length;
144 | while (dataURI.charAt(dataEnd - 1) == "=")
145 | dataEnd--;
146 | dataStart = dataURI.indexOf(",") + 1;
147 | that.size = Math.floor((dataEnd - dataStart) * 0.75);
148 | callback();
149 | }
150 |
151 | function readUint8Array(index, length, callback) {
152 | var i, data = getDataHelper(length);
153 | var start = Math.floor(index / 3) * 4;
154 | var end = Math.ceil((index + length) / 3) * 4;
155 | var bytes = obj.atob(dataURI.substring(start + dataStart, end + dataStart));
156 | var delta = index - Math.floor(start / 4) * 3;
157 | for (i = delta; i < delta + length; i++)
158 | data.array[i - delta] = bytes.charCodeAt(i);
159 | callback(data.array);
160 | }
161 |
162 | that.size = 0;
163 | that.init = init;
164 | that.readUint8Array = readUint8Array;
165 | }
166 |
167 | Data64URIReader.prototype = new Reader();
168 | Data64URIReader.prototype.constructor = Data64URIReader;
169 |
170 | function BlobReader(blob) {
171 | var that = this;
172 |
173 | function init(callback) {
174 | that.size = blob.size;
175 | callback();
176 | }
177 |
178 | function readUint8Array(index, length, callback, onerror) {
179 | var reader = new FileReader();
180 | reader.onload = function(e) {
181 | callback(new Uint8Array(e.target.result));
182 | };
183 | reader.onerror = onerror;
184 | try {
185 | reader.readAsArrayBuffer(blobSlice(blob, index, length));
186 | } catch (e) {
187 | onerror(e);
188 | }
189 | }
190 |
191 | that.size = 0;
192 | that.init = init;
193 | that.readUint8Array = readUint8Array;
194 | }
195 | BlobReader.prototype = new Reader();
196 | BlobReader.prototype.constructor = BlobReader;
197 |
198 | // Writers
199 |
200 | function Writer() {
201 | }
202 | Writer.prototype.getData = function(callback) {
203 | callback(this.data);
204 | };
205 |
206 | function TextWriter(encoding) {
207 | var that = this, blob;
208 |
209 | function init(callback) {
210 | blob = new Blob([], {
211 | type : TEXT_PLAIN
212 | });
213 | callback();
214 | }
215 |
216 | function writeUint8Array(array, callback) {
217 | blob = new Blob([ blob, appendABViewSupported ? array : array.buffer ], {
218 | type : TEXT_PLAIN
219 | });
220 | callback();
221 | }
222 |
223 | function getData(callback, onerror) {
224 | var reader = new FileReader();
225 | reader.onload = function(e) {
226 | callback(e.target.result);
227 | };
228 | reader.onerror = onerror;
229 | reader.readAsText(blob, encoding);
230 | }
231 |
232 | that.init = init;
233 | that.writeUint8Array = writeUint8Array;
234 | that.getData = getData;
235 | }
236 | TextWriter.prototype = new Writer();
237 | TextWriter.prototype.constructor = TextWriter;
238 |
239 | function Data64URIWriter(contentType) {
240 | var that = this, data = "", pending = "";
241 |
242 | function init(callback) {
243 | data += "data:" + (contentType || "") + ";base64,";
244 | callback();
245 | }
246 |
247 | function writeUint8Array(array, callback) {
248 | var i, delta = pending.length, dataString = pending;
249 | pending = "";
250 | for (i = 0; i < (Math.floor((delta + array.length) / 3) * 3) - delta; i++)
251 | dataString += String.fromCharCode(array[i]);
252 | for (; i < array.length; i++)
253 | pending += String.fromCharCode(array[i]);
254 | if (dataString.length > 2)
255 | data += obj.btoa(dataString);
256 | else
257 | pending = dataString;
258 | callback();
259 | }
260 |
261 | function getData(callback) {
262 | callback(data + obj.btoa(pending));
263 | }
264 |
265 | that.init = init;
266 | that.writeUint8Array = writeUint8Array;
267 | that.getData = getData;
268 | }
269 | Data64URIWriter.prototype = new Writer();
270 | Data64URIWriter.prototype.constructor = Data64URIWriter;
271 |
272 | function BlobWriter(contentType) {
273 | var blob, that = this;
274 |
275 | function init(callback) {
276 | blob = new Blob([], {
277 | type : contentType
278 | });
279 | callback();
280 | }
281 |
282 | function writeUint8Array(array, callback) {
283 | blob = new Blob([ blob, appendABViewSupported ? array : array.buffer ], {
284 | type : contentType
285 | });
286 | callback();
287 | }
288 |
289 | function getData(callback) {
290 | callback(blob);
291 | }
292 |
293 | that.init = init;
294 | that.writeUint8Array = writeUint8Array;
295 | that.getData = getData;
296 | }
297 | BlobWriter.prototype = new Writer();
298 | BlobWriter.prototype.constructor = BlobWriter;
299 |
300 | /**
301 | * inflate/deflate core functions
302 | * @param worker {Worker} web worker for the task.
303 | * @param initialMessage {Object} initial message to be sent to the worker. should contain
304 | * sn(serial number for distinguishing multiple tasks sent to the worker), and codecClass.
305 | * This function may add more properties before sending.
306 | */
307 | function launchWorkerProcess(worker, initialMessage, reader, writer, offset, size, onprogress, onend, onreaderror, onwriteerror) {
308 | var chunkIndex = 0, index, outputSize, sn = initialMessage.sn, crc;
309 |
310 | function onflush() {
311 | worker.removeEventListener('message', onmessage, false);
312 | onend(outputSize, crc);
313 | }
314 |
315 | function onmessage(event) {
316 | var message = event.data, data = message.data, err = message.error;
317 | if (err) {
318 | err.toString = function () { return 'Error: ' + this.message; };
319 | onreaderror(err);
320 | return;
321 | }
322 | if (message.sn !== sn)
323 | return;
324 | if (typeof message.codecTime === 'number')
325 | worker.codecTime += message.codecTime; // should be before onflush()
326 | if (typeof message.crcTime === 'number')
327 | worker.crcTime += message.crcTime;
328 |
329 | switch (message.type) {
330 | case 'append':
331 | if (data) {
332 | outputSize += data.length;
333 | writer.writeUint8Array(data, function() {
334 | step();
335 | }, onwriteerror);
336 | } else
337 | step();
338 | break;
339 | case 'flush':
340 | crc = message.crc;
341 | if (data) {
342 | outputSize += data.length;
343 | writer.writeUint8Array(data, function() {
344 | onflush();
345 | }, onwriteerror);
346 | } else
347 | onflush();
348 | break;
349 | case 'progress':
350 | if (onprogress)
351 | onprogress(index + message.loaded, size);
352 | break;
353 | case 'importScripts': //no need to handle here
354 | case 'newTask':
355 | case 'echo':
356 | break;
357 | default:
358 | console.warn('zip.js:launchWorkerProcess: unknown message: ', message);
359 | }
360 | }
361 |
362 | function step() {
363 | index = chunkIndex * CHUNK_SIZE;
364 | if (index < size) {
365 | reader.readUint8Array(offset + index, Math.min(CHUNK_SIZE, size - index), function(array) {
366 | if (onprogress)
367 | onprogress(index, size);
368 | var msg = index === 0 ? initialMessage : {sn : sn};
369 | msg.type = 'append';
370 | msg.data = array;
371 | worker.postMessage(msg, [array.buffer]);
372 | chunkIndex++;
373 | }, onreaderror);
374 | } else {
375 | worker.postMessage({
376 | sn: sn,
377 | type: 'flush'
378 | });
379 | }
380 | }
381 |
382 | outputSize = 0;
383 | worker.addEventListener('message', onmessage, false);
384 | step();
385 | }
386 |
387 | function launchProcess(process, reader, writer, offset, size, crcType, onprogress, onend, onreaderror, onwriteerror) {
388 | var chunkIndex = 0, index, outputSize = 0,
389 | crcInput = crcType === 'input',
390 | crcOutput = crcType === 'output',
391 | crc = new Crc32();
392 | function step() {
393 | var outputData;
394 | index = chunkIndex * CHUNK_SIZE;
395 | if (index < size)
396 | reader.readUint8Array(offset + index, Math.min(CHUNK_SIZE, size - index), function(inputData) {
397 | var outputData;
398 | try {
399 | outputData = process.append(inputData, function(loaded) {
400 | if (onprogress)
401 | onprogress(index + loaded, size);
402 | });
403 | } catch (e) {
404 | onreaderror(e);
405 | return;
406 | }
407 | if (outputData) {
408 | outputSize += outputData.length;
409 | writer.writeUint8Array(outputData, function() {
410 | chunkIndex++;
411 | setTimeout(step, 1);
412 | }, onwriteerror);
413 | if (crcOutput)
414 | crc.append(outputData);
415 | } else {
416 | chunkIndex++;
417 | setTimeout(step, 1);
418 | }
419 | if (crcInput)
420 | crc.append(inputData);
421 | if (onprogress)
422 | onprogress(index, size);
423 | }, onreaderror);
424 | else {
425 | try {
426 | outputData = process.flush();
427 | } catch (e) {
428 | onreaderror(e);
429 | return;
430 | }
431 | if (outputData) {
432 | if (crcOutput)
433 | crc.append(outputData);
434 | outputSize += outputData.length;
435 | writer.writeUint8Array(outputData, function() {
436 | onend(outputSize, crc.get());
437 | }, onwriteerror);
438 | } else
439 | onend(outputSize, crc.get());
440 | }
441 | }
442 |
443 | step();
444 | }
445 |
446 | function inflate(worker, sn, reader, writer, offset, size, computeCrc32, onend, onprogress, onreaderror, onwriteerror) {
447 | var crcType = computeCrc32 ? 'output' : 'none';
448 | if (obj.zip.useWebWorkers) {
449 | var initialMessage = {
450 | sn: sn,
451 | codecClass: 'Inflater',
452 | crcType: crcType,
453 | };
454 | launchWorkerProcess(worker, initialMessage, reader, writer, offset, size, onprogress, onend, onreaderror, onwriteerror);
455 | } else
456 | launchProcess(new obj.zip.Inflater(), reader, writer, offset, size, crcType, onprogress, onend, onreaderror, onwriteerror);
457 | }
458 |
459 | function deflate(worker, sn, reader, writer, level, onend, onprogress, onreaderror, onwriteerror) {
460 | var crcType = 'input';
461 | if (obj.zip.useWebWorkers) {
462 | var initialMessage = {
463 | sn: sn,
464 | options: {level: level},
465 | codecClass: 'Deflater',
466 | crcType: crcType,
467 | };
468 | launchWorkerProcess(worker, initialMessage, reader, writer, 0, reader.size, onprogress, onend, onreaderror, onwriteerror);
469 | } else
470 | launchProcess(new obj.zip.Deflater(), reader, writer, 0, reader.size, crcType, onprogress, onend, onreaderror, onwriteerror);
471 | }
472 |
473 | function copy(worker, sn, reader, writer, offset, size, computeCrc32, onend, onprogress, onreaderror, onwriteerror) {
474 | var crcType = 'input';
475 | if (obj.zip.useWebWorkers && computeCrc32) {
476 | var initialMessage = {
477 | sn: sn,
478 | codecClass: 'NOOP',
479 | crcType: crcType,
480 | };
481 | launchWorkerProcess(worker, initialMessage, reader, writer, offset, size, onprogress, onend, onreaderror, onwriteerror);
482 | } else
483 | launchProcess(new NOOP(), reader, writer, offset, size, crcType, onprogress, onend, onreaderror, onwriteerror);
484 | }
485 |
486 | // ZipReader
487 |
488 | function decodeASCII(str) {
489 | var i, out = "", charCode, extendedASCII = [ '\u00C7', '\u00FC', '\u00E9', '\u00E2', '\u00E4', '\u00E0', '\u00E5', '\u00E7', '\u00EA', '\u00EB',
490 | '\u00E8', '\u00EF', '\u00EE', '\u00EC', '\u00C4', '\u00C5', '\u00C9', '\u00E6', '\u00C6', '\u00F4', '\u00F6', '\u00F2', '\u00FB', '\u00F9',
491 | '\u00FF', '\u00D6', '\u00DC', '\u00F8', '\u00A3', '\u00D8', '\u00D7', '\u0192', '\u00E1', '\u00ED', '\u00F3', '\u00FA', '\u00F1', '\u00D1',
492 | '\u00AA', '\u00BA', '\u00BF', '\u00AE', '\u00AC', '\u00BD', '\u00BC', '\u00A1', '\u00AB', '\u00BB', '_', '_', '_', '\u00A6', '\u00A6',
493 | '\u00C1', '\u00C2', '\u00C0', '\u00A9', '\u00A6', '\u00A6', '+', '+', '\u00A2', '\u00A5', '+', '+', '-', '-', '+', '-', '+', '\u00E3',
494 | '\u00C3', '+', '+', '-', '-', '\u00A6', '-', '+', '\u00A4', '\u00F0', '\u00D0', '\u00CA', '\u00CB', '\u00C8', 'i', '\u00CD', '\u00CE',
495 | '\u00CF', '+', '+', '_', '_', '\u00A6', '\u00CC', '_', '\u00D3', '\u00DF', '\u00D4', '\u00D2', '\u00F5', '\u00D5', '\u00B5', '\u00FE',
496 | '\u00DE', '\u00DA', '\u00DB', '\u00D9', '\u00FD', '\u00DD', '\u00AF', '\u00B4', '\u00AD', '\u00B1', '_', '\u00BE', '\u00B6', '\u00A7',
497 | '\u00F7', '\u00B8', '\u00B0', '\u00A8', '\u00B7', '\u00B9', '\u00B3', '\u00B2', '_', ' ' ];
498 | for (i = 0; i < str.length; i++) {
499 | charCode = str.charCodeAt(i) & 0xFF;
500 | if (charCode > 127)
501 | out += extendedASCII[charCode - 128];
502 | else
503 | out += String.fromCharCode(charCode);
504 | }
505 | return out;
506 | }
507 |
508 | function decodeUTF8(string) {
509 | return decodeURIComponent(escape(string));
510 | }
511 |
512 | function getString(bytes) {
513 | var i, str = "";
514 | for (i = 0; i < bytes.length; i++)
515 | str += String.fromCharCode(bytes[i]);
516 | return str;
517 | }
518 |
519 | function getDate(timeRaw) {
520 | var date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & 0x0000ffff;
521 | try {
522 | return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5,
523 | (time & 0x001F) * 2, 0);
524 | } catch (e) {
525 | }
526 | }
527 |
528 | function readCommonHeader(entry, data, index, centralDirectory, onerror) {
529 | entry.version = data.view.getUint16(index, true);
530 | entry.bitFlag = data.view.getUint16(index + 2, true);
531 | entry.compressionMethod = data.view.getUint16(index + 4, true);
532 | entry.lastModDateRaw = data.view.getUint32(index + 6, true);
533 | entry.lastModDate = getDate(entry.lastModDateRaw);
534 | if ((entry.bitFlag & 0x01) === 0x01) {
535 | onerror(ERR_ENCRYPTED);
536 | return;
537 | }
538 | if (centralDirectory || (entry.bitFlag & 0x0008) != 0x0008) {
539 | entry.crc32 = data.view.getUint32(index + 10, true);
540 | entry.compressedSize = data.view.getUint32(index + 14, true);
541 | entry.uncompressedSize = data.view.getUint32(index + 18, true);
542 | }
543 | if (entry.compressedSize === 0xFFFFFFFF || entry.uncompressedSize === 0xFFFFFFFF) {
544 | onerror(ERR_ZIP64);
545 | return;
546 | }
547 | entry.filenameLength = data.view.getUint16(index + 22, true);
548 | entry.extraFieldLength = data.view.getUint16(index + 24, true);
549 | }
550 |
551 | function createZipReader(reader, callback, onerror) {
552 | var inflateSN = 0;
553 |
554 | function Entry() {
555 | }
556 |
557 | Entry.prototype.getData = function(writer, onend, onprogress, checkCrc32) {
558 | var that = this;
559 |
560 | function testCrc32(crc32) {
561 | var dataCrc32 = getDataHelper(4);
562 | dataCrc32.view.setUint32(0, crc32);
563 | return that.crc32 == dataCrc32.view.getUint32(0);
564 | }
565 |
566 | function getWriterData(uncompressedSize, crc32) {
567 | if (checkCrc32 && !testCrc32(crc32))
568 | onerror(ERR_CRC);
569 | else
570 | writer.getData(function(data) {
571 | onend(data);
572 | });
573 | }
574 |
575 | function onreaderror(err) {
576 | onerror(err || ERR_READ_DATA);
577 | }
578 |
579 | function onwriteerror(err) {
580 | onerror(err || ERR_WRITE_DATA);
581 | }
582 |
583 | reader.readUint8Array(that.offset, 30, function(bytes) {
584 | var data = getDataHelper(bytes.length, bytes), dataOffset;
585 | if (data.view.getUint32(0) != 0x504b0304) {
586 | onerror(ERR_BAD_FORMAT);
587 | return;
588 | }
589 | readCommonHeader(that, data, 4, false, onerror);
590 | dataOffset = that.offset + 30 + that.filenameLength + that.extraFieldLength;
591 | writer.init(function() {
592 | if (that.compressionMethod === 0)
593 | copy(that._worker, inflateSN++, reader, writer, dataOffset, that.compressedSize, checkCrc32, getWriterData, onprogress, onreaderror, onwriteerror);
594 | else
595 | inflate(that._worker, inflateSN++, reader, writer, dataOffset, that.compressedSize, checkCrc32, getWriterData, onprogress, onreaderror, onwriteerror);
596 | }, onwriteerror);
597 | }, onreaderror);
598 | };
599 |
600 | function seekEOCDR(eocdrCallback) {
601 | // "End of central directory record" is the last part of a zip archive, and is at least 22 bytes long.
602 | // Zip file comment is the last part of EOCDR and has max length of 64KB,
603 | // so we only have to search the last 64K + 22 bytes of a archive for EOCDR signature (0x06054b50).
604 | var EOCDR_MIN = 22;
605 | if (reader.size < EOCDR_MIN) {
606 | onerror(ERR_BAD_FORMAT);
607 | return;
608 | }
609 | var ZIP_COMMENT_MAX = 256 * 256, EOCDR_MAX = EOCDR_MIN + ZIP_COMMENT_MAX;
610 |
611 | // In most cases, the EOCDR is EOCDR_MIN bytes long
612 | doSeek(EOCDR_MIN, function() {
613 | // If not found, try within EOCDR_MAX bytes
614 | doSeek(Math.min(EOCDR_MAX, reader.size), function() {
615 | onerror(ERR_BAD_FORMAT);
616 | });
617 | });
618 |
619 | // seek last length bytes of file for EOCDR
620 | function doSeek(length, eocdrNotFoundCallback) {
621 | reader.readUint8Array(reader.size - length, length, function(bytes) {
622 | for (var i = bytes.length - EOCDR_MIN; i >= 0; i--) {
623 | if (bytes[i] === 0x50 && bytes[i + 1] === 0x4b && bytes[i + 2] === 0x05 && bytes[i + 3] === 0x06) {
624 | eocdrCallback(new DataView(bytes.buffer, i, EOCDR_MIN));
625 | return;
626 | }
627 | }
628 | eocdrNotFoundCallback();
629 | }, function() {
630 | onerror(ERR_READ);
631 | });
632 | }
633 | }
634 |
635 | var zipReader = {
636 | getEntries : function(callback) {
637 | var worker = this._worker;
638 | // look for End of central directory record
639 | seekEOCDR(function(dataView) {
640 | var datalength, fileslength;
641 | datalength = dataView.getUint32(16, true);
642 | fileslength = dataView.getUint16(8, true);
643 | if (datalength < 0 || datalength >= reader.size) {
644 | onerror(ERR_BAD_FORMAT);
645 | return;
646 | }
647 | reader.readUint8Array(datalength, reader.size - datalength, function(bytes) {
648 | var i, index = 0, entries = [], entry, filename, comment, data = getDataHelper(bytes.length, bytes);
649 | for (i = 0; i < fileslength; i++) {
650 | entry = new Entry();
651 | entry._worker = worker;
652 | if (data.view.getUint32(index) != 0x504b0102) {
653 | onerror(ERR_BAD_FORMAT);
654 | return;
655 | }
656 | readCommonHeader(entry, data, index + 6, true, onerror);
657 | entry.commentLength = data.view.getUint16(index + 32, true);
658 | entry.directory = ((data.view.getUint8(index + 38) & 0x10) == 0x10);
659 | entry.offset = data.view.getUint32(index + 42, true);
660 | filename = getString(data.array.subarray(index + 46, index + 46 + entry.filenameLength));
661 | entry.filename = ((entry.bitFlag & 0x0800) === 0x0800) ? decodeUTF8(filename) : decodeASCII(filename);
662 | if (!entry.directory && entry.filename.charAt(entry.filename.length - 1) == "/")
663 | entry.directory = true;
664 | comment = getString(data.array.subarray(index + 46 + entry.filenameLength + entry.extraFieldLength, index + 46
665 | + entry.filenameLength + entry.extraFieldLength + entry.commentLength));
666 | entry.comment = ((entry.bitFlag & 0x0800) === 0x0800) ? decodeUTF8(comment) : decodeASCII(comment);
667 | entries.push(entry);
668 | index += 46 + entry.filenameLength + entry.extraFieldLength + entry.commentLength;
669 | }
670 | callback(entries);
671 | }, function() {
672 | onerror(ERR_READ);
673 | });
674 | });
675 | },
676 | close : function(callback) {
677 | if (this._worker) {
678 | this._worker.terminate();
679 | this._worker = null;
680 | }
681 | if (callback)
682 | callback();
683 | },
684 | _worker: null
685 | };
686 |
687 | if (!obj.zip.useWebWorkers)
688 | callback(zipReader);
689 | else {
690 | createWorker('inflater',
691 | function(worker) {
692 | zipReader._worker = worker;
693 | callback(zipReader);
694 | },
695 | function(err) {
696 | onerror(err);
697 | }
698 | );
699 | }
700 | }
701 |
702 | // ZipWriter
703 |
704 | function encodeUTF8(string) {
705 | return unescape(encodeURIComponent(string));
706 | }
707 |
708 | function getBytes(str) {
709 | var i, array = [];
710 | for (i = 0; i < str.length; i++)
711 | array.push(str.charCodeAt(i));
712 | return array;
713 | }
714 |
715 | function createZipWriter(writer, callback, onerror, dontDeflate) {
716 | var files = {}, filenames = [], datalength = 0;
717 | var deflateSN = 0;
718 |
719 | function onwriteerror(err) {
720 | onerror(err || ERR_WRITE);
721 | }
722 |
723 | function onreaderror(err) {
724 | onerror(err || ERR_READ_DATA);
725 | }
726 |
727 | var zipWriter = {
728 | add : function(name, reader, onend, onprogress, options) {
729 | var header, filename, date;
730 | var worker = this._worker;
731 |
732 | function writeHeader(callback) {
733 | var data;
734 | date = options.lastModDate || new Date();
735 | header = getDataHelper(26);
736 | files[name] = {
737 | headerArray : header.array,
738 | directory : options.directory,
739 | filename : filename,
740 | offset : datalength,
741 | comment : getBytes(encodeUTF8(options.comment || ""))
742 | };
743 | header.view.setUint32(0, 0x14000808);
744 | if (options.version)
745 | header.view.setUint8(0, options.version);
746 | if (!dontDeflate && options.level !== 0 && !options.directory)
747 | header.view.setUint16(4, 0x0800);
748 | header.view.setUint16(6, (((date.getHours() << 6) | date.getMinutes()) << 5) | date.getSeconds() / 2, true);
749 | header.view.setUint16(8, ((((date.getFullYear() - 1980) << 4) | (date.getMonth() + 1)) << 5) | date.getDate(), true);
750 | header.view.setUint16(22, filename.length, true);
751 | data = getDataHelper(30 + filename.length);
752 | data.view.setUint32(0, 0x504b0304);
753 | data.array.set(header.array, 4);
754 | data.array.set(filename, 30);
755 | datalength += data.array.length;
756 | writer.writeUint8Array(data.array, callback, onwriteerror);
757 | }
758 |
759 | function writeFooter(compressedLength, crc32) {
760 | var footer = getDataHelper(16);
761 | datalength += compressedLength || 0;
762 | footer.view.setUint32(0, 0x504b0708);
763 | if (typeof crc32 != "undefined") {
764 | header.view.setUint32(10, crc32, true);
765 | footer.view.setUint32(4, crc32, true);
766 | }
767 | if (reader) {
768 | footer.view.setUint32(8, compressedLength, true);
769 | header.view.setUint32(14, compressedLength, true);
770 | footer.view.setUint32(12, reader.size, true);
771 | header.view.setUint32(18, reader.size, true);
772 | }
773 | writer.writeUint8Array(footer.array, function() {
774 | datalength += 16;
775 | onend();
776 | }, onwriteerror);
777 | }
778 |
779 | function writeFile() {
780 | options = options || {};
781 | name = name.trim();
782 | if (options.directory && name.charAt(name.length - 1) != "/")
783 | name += "/";
784 | if (files.hasOwnProperty(name)) {
785 | onerror(ERR_DUPLICATED_NAME);
786 | return;
787 | }
788 | filename = getBytes(encodeUTF8(name));
789 | filenames.push(name);
790 | writeHeader(function() {
791 | if (reader)
792 | if (dontDeflate || options.level === 0)
793 | copy(worker, deflateSN++, reader, writer, 0, reader.size, true, writeFooter, onprogress, onreaderror, onwriteerror);
794 | else
795 | deflate(worker, deflateSN++, reader, writer, options.level, writeFooter, onprogress, onreaderror, onwriteerror);
796 | else
797 | writeFooter();
798 | }, onwriteerror);
799 | }
800 |
801 | if (reader)
802 | reader.init(writeFile, onreaderror);
803 | else
804 | writeFile();
805 | },
806 | close : function(callback) {
807 | if (this._worker) {
808 | this._worker.terminate();
809 | this._worker = null;
810 | }
811 |
812 | var data, length = 0, index = 0, indexFilename, file;
813 | for (indexFilename = 0; indexFilename < filenames.length; indexFilename++) {
814 | file = files[filenames[indexFilename]];
815 | length += 46 + file.filename.length + file.comment.length;
816 | }
817 | data = getDataHelper(length + 22);
818 | for (indexFilename = 0; indexFilename < filenames.length; indexFilename++) {
819 | file = files[filenames[indexFilename]];
820 | data.view.setUint32(index, 0x504b0102);
821 | data.view.setUint16(index + 4, 0x1400);
822 | data.array.set(file.headerArray, index + 6);
823 | data.view.setUint16(index + 32, file.comment.length, true);
824 | if (file.directory)
825 | data.view.setUint8(index + 38, 0x10);
826 | data.view.setUint32(index + 42, file.offset, true);
827 | data.array.set(file.filename, index + 46);
828 | data.array.set(file.comment, index + 46 + file.filename.length);
829 | index += 46 + file.filename.length + file.comment.length;
830 | }
831 | data.view.setUint32(index, 0x504b0506);
832 | data.view.setUint16(index + 8, filenames.length, true);
833 | data.view.setUint16(index + 10, filenames.length, true);
834 | data.view.setUint32(index + 12, length, true);
835 | data.view.setUint32(index + 16, datalength, true);
836 | writer.writeUint8Array(data.array, function() {
837 | writer.getData(callback);
838 | }, onwriteerror);
839 | },
840 | _worker: null
841 | };
842 |
843 | if (!obj.zip.useWebWorkers)
844 | callback(zipWriter);
845 | else {
846 | createWorker('deflater',
847 | function(worker) {
848 | zipWriter._worker = worker;
849 | callback(zipWriter);
850 | },
851 | function(err) {
852 | onerror(err);
853 | }
854 | );
855 | }
856 | }
857 |
858 | function resolveURLs(urls) {
859 | var a = document.createElement('a');
860 | return urls.map(function(url) {
861 | a.href = url;
862 | return a.href;
863 | });
864 | }
865 |
866 | var DEFAULT_WORKER_SCRIPTS = {
867 | deflater: ['z-worker.js', 'deflate.js'],
868 | inflater: ['z-worker.js', 'inflate.js']
869 | };
870 | function createWorker(type, callback, onerror) {
871 | if (obj.zip.workerScripts !== null && obj.zip.workerScriptsPath !== null) {
872 | onerror(new Error('Either zip.workerScripts or zip.workerScriptsPath may be set, not both.'));
873 | return;
874 | }
875 | var scripts;
876 | if (obj.zip.workerScripts) {
877 | scripts = obj.zip.workerScripts[type];
878 | if (!Array.isArray(scripts)) {
879 | onerror(new Error('zip.workerScripts.' + type + ' is not an array!'));
880 | return;
881 | }
882 | scripts = resolveURLs(scripts);
883 | } else {
884 | scripts = DEFAULT_WORKER_SCRIPTS[type].slice(0);
885 | scripts[0] = (obj.zip.workerScriptsPath || '') + scripts[0];
886 | }
887 | var worker = new Worker(scripts[0]);
888 | // record total consumed time by inflater/deflater/crc32 in this worker
889 | worker.codecTime = worker.crcTime = 0;
890 | worker.postMessage({ type: 'importScripts', scripts: scripts.slice(1) });
891 | worker.addEventListener('message', onmessage);
892 | function onmessage(ev) {
893 | var msg = ev.data;
894 | if (msg.error) {
895 | worker.terminate(); // should before onerror(), because onerror() may throw.
896 | onerror(msg.error);
897 | return;
898 | }
899 | if (msg.type === 'importScripts') {
900 | worker.removeEventListener('message', onmessage);
901 | worker.removeEventListener('error', errorHandler);
902 | callback(worker);
903 | }
904 | }
905 | // catch entry script loading error and other unhandled errors
906 | worker.addEventListener('error', errorHandler);
907 | function errorHandler(err) {
908 | worker.terminate();
909 | onerror(err);
910 | }
911 | }
912 |
913 | function onerror_default(error) {
914 | console.error(error);
915 | }
916 | obj.zip = {
917 | Reader : Reader,
918 | Writer : Writer,
919 | BlobReader : BlobReader,
920 | Data64URIReader : Data64URIReader,
921 | TextReader : TextReader,
922 | BlobWriter : BlobWriter,
923 | Data64URIWriter : Data64URIWriter,
924 | TextWriter : TextWriter,
925 | createReader : function(reader, callback, onerror) {
926 | onerror = onerror || onerror_default;
927 |
928 | reader.init(function() {
929 | createZipReader(reader, callback, onerror);
930 | }, onerror);
931 | },
932 | createWriter : function(writer, callback, onerror, dontDeflate) {
933 | onerror = onerror || onerror_default;
934 | dontDeflate = !!dontDeflate;
935 |
936 | writer.init(function() {
937 | createZipWriter(writer, callback, onerror, dontDeflate);
938 | }, onerror);
939 | },
940 | useWebWorkers : true,
941 | /**
942 | * Directory containing the default worker scripts (z-worker.js, deflate.js, and inflate.js), relative to current base url.
943 | * E.g.: zip.workerScripts = './';
944 | */
945 | workerScriptsPath : null,
946 | /**
947 | * Advanced option to control which scripts are loaded in the Web worker. If this option is specified, then workerScriptsPath must not be set.
948 | * workerScripts.deflater/workerScripts.inflater should be arrays of urls to scripts for deflater/inflater, respectively.
949 | * Scripts in the array are executed in order, and the first one should be z-worker.js, which is used to start the worker.
950 | * All urls are relative to current base url.
951 | * E.g.:
952 | * zip.workerScripts = {
953 | * deflater: ['z-worker.js', 'deflate.js'],
954 | * inflater: ['z-worker.js', 'inflate.js']
955 | * };
956 | */
957 | workerScripts : null,
958 | };
959 |
960 | })(this);
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/src/beautify/beautify-css.js:
--------------------------------------------------------------------------------
1 | /*jshint curly:false, eqeqeq:true, laxbreak:true, noempty:false */
2 | /* AUTO-GENERATED. DO NOT MODIFY. */
3 | /*
4 |
5 | The MIT License (MIT)
6 |
7 | Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
8 |
9 | Permission is hereby granted, free of charge, to any person
10 | obtaining a copy of this software and associated documentation files
11 | (the "Software"), to deal in the Software without restriction,
12 | including without limitation the rights to use, copy, modify, merge,
13 | publish, distribute, sublicense, and/or sell copies of the Software,
14 | and to permit persons to whom the Software is furnished to do so,
15 | subject to the following conditions:
16 |
17 | The above copyright notice and this permission notice shall be
18 | included in all copies or substantial portions of the Software.
19 |
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 | SOFTWARE.
28 |
29 |
30 | CSS Beautifier
31 | ---------------
32 |
33 | Written by Harutyun Amirjanyan, (amirjanyan@gmail.com)
34 |
35 | Based on code initially developed by: Einar Lielmanis,
36 | http://jsbeautifier.org/
37 |
38 | Usage:
39 | css_beautify(source_text);
40 | css_beautify(source_text, options);
41 |
42 | The options are (default in brackets):
43 | indent_size (4) — indentation size,
44 | indent_char (space) — character to indent with,
45 | selector_separator_newline (true) - separate selectors with newline or
46 | not (e.g. "a,\nbr" or "a, br")
47 | end_with_newline (false) - end with a newline
48 | newline_between_rules (true) - add a new line after every css rule
49 | space_around_selector_separator (false) - ensure space around selector separators:
50 | '>', '+', '~' (e.g. "a>b" -> "a > b")
51 | e.g
52 |
53 | css_beautify(css_source_text, {
54 | 'indent_size': 1,
55 | 'indent_char': '\t',
56 | 'selector_separator': ' ',
57 | 'end_with_newline': false,
58 | 'newline_between_rules': true,
59 | 'space_around_selector_separator': true
60 | });
61 | */
62 |
63 | // http://www.w3.org/TR/CSS21/syndata.html#tokenization
64 | // http://www.w3.org/TR/css3-syntax/
65 |
66 | (function() {
67 | var legacy_beautify_css =
68 | /******/ (function(modules) { // webpackBootstrap
69 | /******/ // The module cache
70 | /******/ var installedModules = {};
71 | /******/
72 | /******/ // The require function
73 | /******/ function __webpack_require__(moduleId) {
74 | /******/
75 | /******/ // Check if module is in cache
76 | /******/ if(installedModules[moduleId]) {
77 | /******/ return installedModules[moduleId].exports;
78 | /******/ }
79 | /******/ // Create a new module (and put it into the cache)
80 | /******/ var module = installedModules[moduleId] = {
81 | /******/ i: moduleId,
82 | /******/ l: false,
83 | /******/ exports: {}
84 | /******/ };
85 | /******/
86 | /******/ // Execute the module function
87 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
88 | /******/
89 | /******/ // Flag the module as loaded
90 | /******/ module.l = true;
91 | /******/
92 | /******/ // Return the exports of the module
93 | /******/ return module.exports;
94 | /******/ }
95 | /******/
96 | /******/
97 | /******/ // expose the modules object (__webpack_modules__)
98 | /******/ __webpack_require__.m = modules;
99 | /******/
100 | /******/ // expose the module cache
101 | /******/ __webpack_require__.c = installedModules;
102 | /******/
103 | /******/ // identity function for calling harmony imports with the correct context
104 | /******/ __webpack_require__.i = function(value) { return value; };
105 | /******/
106 | /******/ // define getter function for harmony exports
107 | /******/ __webpack_require__.d = function(exports, name, getter) {
108 | /******/ if(!__webpack_require__.o(exports, name)) {
109 | /******/ Object.defineProperty(exports, name, {
110 | /******/ configurable: false,
111 | /******/ enumerable: true,
112 | /******/ get: getter
113 | /******/ });
114 | /******/ }
115 | /******/ };
116 | /******/
117 | /******/ // getDefaultExport function for compatibility with non-harmony modules
118 | /******/ __webpack_require__.n = function(module) {
119 | /******/ var getter = module && module.__esModule ?
120 | /******/ function getDefault() { return module['default']; } :
121 | /******/ function getModuleExports() { return module; };
122 | /******/ __webpack_require__.d(getter, 'a', getter);
123 | /******/ return getter;
124 | /******/ };
125 | /******/
126 | /******/ // Object.prototype.hasOwnProperty.call
127 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
128 | /******/
129 | /******/ // __webpack_public_path__
130 | /******/ __webpack_require__.p = "";
131 | /******/
132 | /******/ // Load entry module and return exports
133 | /******/ return __webpack_require__(__webpack_require__.s = 4);
134 | /******/ })
135 | /************************************************************************/
136 | /******/ ([
137 | /* 0 */
138 | /***/ (function(module, exports, __webpack_require__) {
139 |
140 | /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
141 | /*
142 |
143 | The MIT License (MIT)
144 |
145 | Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
146 |
147 | Permission is hereby granted, free of charge, to any person
148 | obtaining a copy of this software and associated documentation files
149 | (the "Software"), to deal in the Software without restriction,
150 | including without limitation the rights to use, copy, modify, merge,
151 | publish, distribute, sublicense, and/or sell copies of the Software,
152 | and to permit persons to whom the Software is furnished to do so,
153 | subject to the following conditions:
154 |
155 | The above copyright notice and this permission notice shall be
156 | included in all copies or substantial portions of the Software.
157 |
158 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
159 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
160 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
161 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
162 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
163 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
164 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
165 | SOFTWARE.
166 | */
167 |
168 | var mergeOpts = __webpack_require__(2).mergeOpts;
169 | var acorn = __webpack_require__(1);
170 | var Output = __webpack_require__(3).Output;
171 |
172 |
173 | var lineBreak = acorn.lineBreak;
174 | var allLineBreaks = acorn.allLineBreaks;
175 |
176 | function Beautifier(source_text, options) {
177 | options = options || {};
178 |
179 | // Allow the setting of language/file-type specific options
180 | // with inheritance of overall settings
181 | options = mergeOpts(options, 'css');
182 |
183 | source_text = source_text || '';
184 |
185 | var newlinesFromLastWSEat = 0;
186 | var indentSize = options.indent_size ? parseInt(options.indent_size, 10) : 4;
187 | var indentCharacter = options.indent_char || ' ';
188 | var preserve_newlines = (options.preserve_newlines === undefined) ? false : options.preserve_newlines;
189 | var selectorSeparatorNewline = (options.selector_separator_newline === undefined) ? true : options.selector_separator_newline;
190 | var end_with_newline = (options.end_with_newline === undefined) ? false : options.end_with_newline;
191 | var newline_between_rules = (options.newline_between_rules === undefined) ? true : options.newline_between_rules;
192 | var space_around_combinator = (options.space_around_combinator === undefined) ? false : options.space_around_combinator;
193 | space_around_combinator = space_around_combinator || ((options.space_around_selector_separator === undefined) ? false : options.space_around_selector_separator);
194 | var eol = options.eol ? options.eol : 'auto';
195 |
196 | if (options.indent_with_tabs) {
197 | indentCharacter = '\t';
198 | indentSize = 1;
199 | }
200 |
201 | if (eol === 'auto') {
202 | eol = '\n';
203 | if (source_text && lineBreak.test(source_text || '')) {
204 | eol = source_text.match(lineBreak)[0];
205 | }
206 | }
207 |
208 | eol = eol.replace(/\\r/, '\r').replace(/\\n/, '\n');
209 |
210 | // HACK: newline parsing inconsistent. This brute force normalizes the input.
211 | source_text = source_text.replace(allLineBreaks, '\n');
212 |
213 | // tokenizer
214 | var whiteRe = /^\s+$/;
215 |
216 | var pos = -1,
217 | ch;
218 | var parenLevel = 0;
219 |
220 | function next() {
221 | ch = source_text.charAt(++pos);
222 | return ch || '';
223 | }
224 |
225 | function peek(skipWhitespace) {
226 | var result = '';
227 | var prev_pos = pos;
228 | if (skipWhitespace) {
229 | eatWhitespace();
230 | }
231 | result = source_text.charAt(pos + 1) || '';
232 | pos = prev_pos - 1;
233 | next();
234 | return result;
235 | }
236 |
237 | function eatString(endChars) {
238 | var start = pos;
239 | while (next()) {
240 | if (ch === "\\") {
241 | next();
242 | } else if (endChars.indexOf(ch) !== -1) {
243 | break;
244 | } else if (ch === "\n") {
245 | break;
246 | }
247 | }
248 | return source_text.substring(start, pos + 1);
249 | }
250 |
251 | function peekString(endChar) {
252 | var prev_pos = pos;
253 | var str = eatString(endChar);
254 | pos = prev_pos - 1;
255 | next();
256 | return str;
257 | }
258 |
259 | function eatWhitespace(preserve_newlines_local) {
260 | var result = 0;
261 | while (whiteRe.test(peek())) {
262 | next();
263 | if (ch === '\n' && preserve_newlines_local && preserve_newlines) {
264 | output.add_new_line(true);
265 | result++;
266 | }
267 | }
268 | newlinesFromLastWSEat = result;
269 | return result;
270 | }
271 |
272 | function skipWhitespace() {
273 | var result = '';
274 | if (ch && whiteRe.test(ch)) {
275 | result = ch;
276 | }
277 | while (whiteRe.test(next())) {
278 | result += ch;
279 | }
280 | return result;
281 | }
282 |
283 | function eatComment() {
284 | var start = pos;
285 | var singleLine = peek() === "/";
286 | next();
287 | while (next()) {
288 | if (!singleLine && ch === "*" && peek() === "/") {
289 | next();
290 | break;
291 | } else if (singleLine && ch === "\n") {
292 | return source_text.substring(start, pos);
293 | }
294 | }
295 |
296 | return source_text.substring(start, pos) + ch;
297 | }
298 |
299 |
300 | function lookBack(str) {
301 | return source_text.substring(pos - str.length, pos).toLowerCase() ===
302 | str;
303 | }
304 |
305 | // Nested pseudo-class if we are insideRule
306 | // and the next special character found opens
307 | // a new block
308 | function foundNestedPseudoClass() {
309 | var openParen = 0;
310 | for (var i = pos + 1; i < source_text.length; i++) {
311 | var ch = source_text.charAt(i);
312 | if (ch === "{") {
313 | return true;
314 | } else if (ch === '(') {
315 | // pseudoclasses can contain ()
316 | openParen += 1;
317 | } else if (ch === ')') {
318 | if (openParen === 0) {
319 | return false;
320 | }
321 | openParen -= 1;
322 | } else if (ch === ";" || ch === "}") {
323 | return false;
324 | }
325 | }
326 | return false;
327 | }
328 |
329 | // printer
330 | var baseIndentString = '';
331 | var preindent_index = 0;
332 | if (source_text && source_text.length) {
333 | while ((source_text.charAt(preindent_index) === ' ' ||
334 | source_text.charAt(preindent_index) === '\t')) {
335 | preindent_index += 1;
336 | }
337 | baseIndentString = source_text.substring(0, preindent_index);
338 | source_text = source_text.substring(preindent_index);
339 | }
340 |
341 |
342 | var singleIndent = new Array(indentSize + 1).join(indentCharacter);
343 | var indentLevel;
344 | var nestedLevel;
345 | var output;
346 |
347 | function print_string(output_string) {
348 | if (output.just_added_newline()) {
349 | output.set_indent(indentLevel);
350 | }
351 | output.add_token(output_string);
352 | }
353 |
354 | function preserveSingleSpace(isAfterSpace) {
355 | if (isAfterSpace) {
356 | output.space_before_token = true;
357 | }
358 | }
359 |
360 | function indent() {
361 | indentLevel++;
362 | }
363 |
364 | function outdent() {
365 | if (indentLevel > 0) {
366 | indentLevel--;
367 | }
368 | }
369 |
370 | /*_____________________--------------------_____________________*/
371 |
372 | this.beautify = function() {
373 | // reset
374 | output = new Output(singleIndent, baseIndentString);
375 | indentLevel = 0;
376 | nestedLevel = 0;
377 |
378 | pos = -1;
379 | ch = null;
380 | parenLevel = 0;
381 |
382 | var insideRule = false;
383 | var insidePropertyValue = false;
384 | var enteringConditionalGroup = false;
385 | var top_ch = '';
386 | var last_top_ch = '';
387 |
388 | while (true) {
389 | var whitespace = skipWhitespace();
390 | var isAfterSpace = whitespace !== '';
391 | var isAfterNewline = whitespace.indexOf('\n') !== -1;
392 | last_top_ch = top_ch;
393 | top_ch = ch;
394 |
395 | if (!ch) {
396 | break;
397 | } else if (ch === '/' && peek() === '*') { /* css comment */
398 | var header = indentLevel === 0;
399 |
400 | if (isAfterNewline || header) {
401 | output.add_new_line();
402 | }
403 |
404 | print_string(eatComment());
405 | output.add_new_line();
406 | if (header) {
407 | output.add_new_line(true);
408 | }
409 | } else if (ch === '/' && peek() === '/') { // single line comment
410 | if (!isAfterNewline && last_top_ch !== '{') {
411 | output.trim(true);
412 | }
413 | output.space_before_token = true;
414 | print_string(eatComment());
415 | output.add_new_line();
416 | } else if (ch === '@') {
417 | preserveSingleSpace(isAfterSpace);
418 |
419 | // deal with less propery mixins @{...}
420 | if (peek() === '{') {
421 | print_string(eatString('}'));
422 | } else {
423 | print_string(ch);
424 |
425 | // strip trailing space, if present, for hash property checks
426 | var variableOrRule = peekString(": ,;{}()[]/='\"");
427 |
428 | if (variableOrRule.match(/[ :]$/)) {
429 | // we have a variable or pseudo-class, add it and insert one space before continuing
430 | next();
431 | variableOrRule = eatString(": ").replace(/\s$/, '');
432 | print_string(variableOrRule);
433 | output.space_before_token = true;
434 | }
435 |
436 | variableOrRule = variableOrRule.replace(/\s$/, '');
437 |
438 | // might be a nesting at-rule
439 | if (variableOrRule in this.NESTED_AT_RULE) {
440 | nestedLevel += 1;
441 | if (variableOrRule in this.CONDITIONAL_GROUP_RULE) {
442 | enteringConditionalGroup = true;
443 | }
444 | }
445 | }
446 | } else if (ch === '#' && peek() === '{') {
447 | preserveSingleSpace(isAfterSpace);
448 | print_string(eatString('}'));
449 | } else if (ch === '{') {
450 | if (peek(true) === '}') {
451 | eatWhitespace();
452 | next();
453 | output.space_before_token = true;
454 | print_string("{}");
455 | if (!eatWhitespace(true)) {
456 | output.add_new_line();
457 | }
458 |
459 | if (newlinesFromLastWSEat < 2 && newline_between_rules && indentLevel === 0) {
460 | output.add_new_line(true);
461 | }
462 | } else {
463 | indent();
464 | output.space_before_token = true;
465 | print_string(ch);
466 | if (!eatWhitespace(true)) {
467 | output.add_new_line();
468 | }
469 |
470 | // when entering conditional groups, only rulesets are allowed
471 | if (enteringConditionalGroup) {
472 | enteringConditionalGroup = false;
473 | insideRule = (indentLevel > nestedLevel);
474 | } else {
475 | // otherwise, declarations are also allowed
476 | insideRule = (indentLevel >= nestedLevel);
477 | }
478 | }
479 | } else if (ch === '}') {
480 | outdent();
481 | output.add_new_line();
482 | print_string(ch);
483 | insideRule = false;
484 | insidePropertyValue = false;
485 | if (nestedLevel) {
486 | nestedLevel--;
487 | }
488 |
489 | if (!eatWhitespace(true)) {
490 | output.add_new_line();
491 | }
492 |
493 | if (newlinesFromLastWSEat < 2 && newline_between_rules && indentLevel === 0) {
494 | output.add_new_line(true);
495 | }
496 | } else if (ch === ":") {
497 | eatWhitespace();
498 | if ((insideRule || enteringConditionalGroup) &&
499 | !(lookBack("&") || foundNestedPseudoClass()) &&
500 | !lookBack("(")) {
501 | // 'property: value' delimiter
502 | // which could be in a conditional group query
503 | print_string(':');
504 | if (!insidePropertyValue) {
505 | insidePropertyValue = true;
506 | output.space_before_token = true;
507 | }
508 | } else {
509 | // sass/less parent reference don't use a space
510 | // sass nested pseudo-class don't use a space
511 |
512 | // preserve space before pseudoclasses/pseudoelements, as it means "in any child"
513 | if (lookBack(" ")) {
514 | output.space_before_token = true;
515 | }
516 | if (peek() === ":") {
517 | // pseudo-element
518 | next();
519 | print_string("::");
520 | } else {
521 | // pseudo-class
522 | print_string(':');
523 | }
524 | }
525 | } else if (ch === '"' || ch === '\'') {
526 | preserveSingleSpace(isAfterSpace);
527 | print_string(eatString(ch));
528 | } else if (ch === ';') {
529 | insidePropertyValue = false;
530 | print_string(ch);
531 | if (!eatWhitespace(true)) {
532 | output.add_new_line();
533 | }
534 | } else if (ch === '(') { // may be a url
535 | if (lookBack("url")) {
536 | print_string(ch);
537 | eatWhitespace();
538 | if (next()) {
539 | if (ch !== ')' && ch !== '"' && ch !== '\'') {
540 | print_string(eatString(')'));
541 | } else {
542 | pos--;
543 | }
544 | }
545 | } else {
546 | parenLevel++;
547 | preserveSingleSpace(isAfterSpace);
548 | print_string(ch);
549 | eatWhitespace();
550 | }
551 | } else if (ch === ')') {
552 | print_string(ch);
553 | parenLevel--;
554 | } else if (ch === ',') {
555 | print_string(ch);
556 | if (!eatWhitespace(true) && selectorSeparatorNewline && !insidePropertyValue && parenLevel < 1) {
557 | output.add_new_line();
558 | } else {
559 | output.space_before_token = true;
560 | }
561 | } else if ((ch === '>' || ch === '+' || ch === '~') &&
562 | !insidePropertyValue && parenLevel < 1) {
563 | //handle combinator spacing
564 | if (space_around_combinator) {
565 | output.space_before_token = true;
566 | print_string(ch);
567 | output.space_before_token = true;
568 | } else {
569 | print_string(ch);
570 | eatWhitespace();
571 | // squash extra whitespace
572 | if (ch && whiteRe.test(ch)) {
573 | ch = '';
574 | }
575 | }
576 | } else if (ch === ']') {
577 | print_string(ch);
578 | } else if (ch === '[') {
579 | preserveSingleSpace(isAfterSpace);
580 | print_string(ch);
581 | } else if (ch === '=') { // no whitespace before or after
582 | eatWhitespace();
583 | print_string('=');
584 | if (whiteRe.test(ch)) {
585 | ch = '';
586 | }
587 | } else if (ch === '!') { // !important
588 | print_string(' ');
589 | print_string(ch);
590 | } else {
591 | preserveSingleSpace(isAfterSpace);
592 | print_string(ch);
593 | }
594 | }
595 |
596 | var sweetCode = output.get_code(end_with_newline, eol);
597 |
598 | return sweetCode;
599 | };
600 |
601 | // https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule
602 | this.NESTED_AT_RULE = {
603 | "@page": true,
604 | "@font-face": true,
605 | "@keyframes": true,
606 | // also in CONDITIONAL_GROUP_RULE below
607 | "@media": true,
608 | "@supports": true,
609 | "@document": true
610 | };
611 | this.CONDITIONAL_GROUP_RULE = {
612 | "@media": true,
613 | "@supports": true,
614 | "@document": true
615 | };
616 | }
617 |
618 | module.exports.Beautifier = Beautifier;
619 |
620 |
621 | /***/ }),
622 | /* 1 */
623 | /***/ (function(module, exports) {
624 |
625 | /* jshint curly: false */
626 | // This section of code is taken from acorn.
627 | //
628 | // Acorn was written by Marijn Haverbeke and released under an MIT
629 | // license. The Unicode regexps (for identifiers and whitespace) were
630 | // taken from [Esprima](http://esprima.org) by Ariya Hidayat.
631 | //
632 | // Git repositories for Acorn are available at
633 | //
634 | // http://marijnhaverbeke.nl/git/acorn
635 | // https://github.com/marijnh/acorn.git
636 |
637 | // ## Character categories
638 |
639 | // Big ugly regular expressions that match characters in the
640 | // whitespace, identifier, and identifier-start categories. These
641 | // are only applied when a character is found to actually have a
642 | // code point above 128.
643 |
644 | var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/; // jshint ignore:line
645 | var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
646 | var nonASCIIidentifierChars = "\u0300-\u036f\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u0620-\u0649\u0672-\u06d3\u06e7-\u06e8\u06fb-\u06fc\u0730-\u074a\u0800-\u0814\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0840-\u0857\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962-\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09d7\u09df-\u09e0\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2-\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b5f-\u0b60\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62-\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2-\u0ce3\u0ce6-\u0cef\u0d02\u0d03\u0d46-\u0d48\u0d57\u0d62-\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e34-\u0e3a\u0e40-\u0e45\u0e50-\u0e59\u0eb4-\u0eb9\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f41-\u0f47\u0f71-\u0f84\u0f86-\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u1000-\u1029\u1040-\u1049\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u170e-\u1710\u1720-\u1730\u1740-\u1750\u1772\u1773\u1780-\u17b2\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u1920-\u192b\u1930-\u193b\u1951-\u196d\u19b0-\u19c0\u19c8-\u19c9\u19d0-\u19d9\u1a00-\u1a15\u1a20-\u1a53\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1b46-\u1b4b\u1b50-\u1b59\u1b6b-\u1b73\u1bb0-\u1bb9\u1be6-\u1bf3\u1c00-\u1c22\u1c40-\u1c49\u1c5b-\u1c7d\u1cd0-\u1cd2\u1d00-\u1dbe\u1e01-\u1f15\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2d81-\u2d96\u2de0-\u2dff\u3021-\u3028\u3099\u309a\ua640-\ua66d\ua674-\ua67d\ua69f\ua6f0-\ua6f1\ua7f8-\ua800\ua806\ua80b\ua823-\ua827\ua880-\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8f3-\ua8f7\ua900-\ua909\ua926-\ua92d\ua930-\ua945\ua980-\ua983\ua9b3-\ua9c0\uaa00-\uaa27\uaa40-\uaa41\uaa4c-\uaa4d\uaa50-\uaa59\uaa7b\uaae0-\uaae9\uaaf2-\uaaf3\uabc0-\uabe1\uabec\uabed\uabf0-\uabf9\ufb20-\ufb28\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
647 | var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
648 | var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
649 |
650 | // Whether a single character denotes a newline.
651 |
652 | exports.newline = /[\n\r\u2028\u2029]/;
653 |
654 | // Matches a whole line break (where CRLF is considered a single
655 | // line break). Used to count lines.
656 |
657 | // in javascript, these two differ
658 | // in python they are the same, different methods are called on them
659 | exports.lineBreak = new RegExp('\r\n|' + exports.newline.source);
660 | exports.allLineBreaks = new RegExp(exports.lineBreak.source, 'g');
661 |
662 |
663 | // Test whether a given character code starts an identifier.
664 |
665 | exports.isIdentifierStart = function(code) {
666 | // permit $ (36) and @ (64). @ is used in ES7 decorators.
667 | if (code < 65) return code === 36 || code === 64;
668 | // 65 through 91 are uppercase letters.
669 | if (code < 91) return true;
670 | // permit _ (95).
671 | if (code < 97) return code === 95;
672 | // 97 through 123 are lowercase letters.
673 | if (code < 123) return true;
674 | return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
675 | };
676 |
677 | // Test whether a given character is part of an identifier.
678 |
679 | exports.isIdentifierChar = function(code) {
680 | if (code < 48) return code === 36;
681 | if (code < 58) return true;
682 | if (code < 65) return false;
683 | if (code < 91) return true;
684 | if (code < 97) return code === 95;
685 | if (code < 123) return true;
686 | return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
687 | };
688 |
689 |
690 | /***/ }),
691 | /* 2 */
692 | /***/ (function(module, exports) {
693 |
694 | /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
695 | /*
696 |
697 | The MIT License (MIT)
698 |
699 | Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
700 |
701 | Permission is hereby granted, free of charge, to any person
702 | obtaining a copy of this software and associated documentation files
703 | (the "Software"), to deal in the Software without restriction,
704 | including without limitation the rights to use, copy, modify, merge,
705 | publish, distribute, sublicense, and/or sell copies of the Software,
706 | and to permit persons to whom the Software is furnished to do so,
707 | subject to the following conditions:
708 |
709 | The above copyright notice and this permission notice shall be
710 | included in all copies or substantial portions of the Software.
711 |
712 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
713 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
714 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
715 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
716 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
717 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
718 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
719 | SOFTWARE.
720 | */
721 |
722 | function mergeOpts(allOptions, targetType) {
723 | var finalOpts = {};
724 | var name;
725 |
726 | for (name in allOptions) {
727 | if (name !== targetType) {
728 | finalOpts[name] = allOptions[name];
729 | }
730 | }
731 |
732 | //merge in the per type settings for the targetType
733 | if (targetType in allOptions) {
734 | for (name in allOptions[targetType]) {
735 | finalOpts[name] = allOptions[targetType][name];
736 | }
737 | }
738 | return finalOpts;
739 | }
740 |
741 | module.exports.mergeOpts = mergeOpts;
742 |
743 |
744 | /***/ }),
745 | /* 3 */
746 | /***/ (function(module, exports) {
747 |
748 | /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
749 | /*
750 |
751 | The MIT License (MIT)
752 |
753 | Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
754 |
755 | Permission is hereby granted, free of charge, to any person
756 | obtaining a copy of this software and associated documentation files
757 | (the "Software"), to deal in the Software without restriction,
758 | including without limitation the rights to use, copy, modify, merge,
759 | publish, distribute, sublicense, and/or sell copies of the Software,
760 | and to permit persons to whom the Software is furnished to do so,
761 | subject to the following conditions:
762 |
763 | The above copyright notice and this permission notice shall be
764 | included in all copies or substantial portions of the Software.
765 |
766 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
767 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
768 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
769 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
770 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
771 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
772 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
773 | SOFTWARE.
774 | */
775 |
776 | function OutputLine(parent) {
777 | var _character_count = 0;
778 | // use indent_count as a marker for lines that have preserved indentation
779 | var _indent_count = -1;
780 |
781 | var _items = [];
782 | var _empty = true;
783 |
784 | this.set_indent = function(level) {
785 | _character_count = parent.baseIndentLength + level * parent.indent_length;
786 | _indent_count = level;
787 | };
788 |
789 | this.get_character_count = function() {
790 | return _character_count;
791 | };
792 |
793 | this.is_empty = function() {
794 | return _empty;
795 | };
796 |
797 | this.last = function() {
798 | if (!this._empty) {
799 | return _items[_items.length - 1];
800 | } else {
801 | return null;
802 | }
803 | };
804 |
805 | this.push = function(input) {
806 | _items.push(input);
807 | _character_count += input.length;
808 | _empty = false;
809 | };
810 |
811 | this.pop = function() {
812 | var item = null;
813 | if (!_empty) {
814 | item = _items.pop();
815 | _character_count -= item.length;
816 | _empty = _items.length === 0;
817 | }
818 | return item;
819 | };
820 |
821 | this.remove_indent = function() {
822 | if (_indent_count > 0) {
823 | _indent_count -= 1;
824 | _character_count -= parent.indent_length;
825 | }
826 | };
827 |
828 | this.trim = function() {
829 | while (this.last() === ' ') {
830 | _items.pop();
831 | _character_count -= 1;
832 | }
833 | _empty = _items.length === 0;
834 | };
835 |
836 | this.toString = function() {
837 | var result = '';
838 | if (!this._empty) {
839 | if (_indent_count >= 0) {
840 | result = parent.indent_cache[_indent_count];
841 | }
842 | result += _items.join('');
843 | }
844 | return result;
845 | };
846 | }
847 |
848 | function Output(indent_string, baseIndentString) {
849 | baseIndentString = baseIndentString || '';
850 | this.indent_cache = [baseIndentString];
851 | this.baseIndentLength = baseIndentString.length;
852 | this.indent_length = indent_string.length;
853 | this.raw = false;
854 |
855 | var lines = [];
856 | this.baseIndentString = baseIndentString;
857 | this.indent_string = indent_string;
858 | this.previous_line = null;
859 | this.current_line = null;
860 | this.space_before_token = false;
861 |
862 | this.add_outputline = function() {
863 | this.previous_line = this.current_line;
864 | this.current_line = new OutputLine(this);
865 | lines.push(this.current_line);
866 | };
867 |
868 | // initialize
869 | this.add_outputline();
870 |
871 |
872 | this.get_line_number = function() {
873 | return lines.length;
874 | };
875 |
876 | // Using object instead of string to allow for later expansion of info about each line
877 | this.add_new_line = function(force_newline) {
878 | if (this.get_line_number() === 1 && this.just_added_newline()) {
879 | return false; // no newline on start of file
880 | }
881 |
882 | if (force_newline || !this.just_added_newline()) {
883 | if (!this.raw) {
884 | this.add_outputline();
885 | }
886 | return true;
887 | }
888 |
889 | return false;
890 | };
891 |
892 | this.get_code = function(end_with_newline, eol) {
893 | var sweet_code = lines.join('\n').replace(/[\r\n\t ]+$/, '');
894 |
895 | if (end_with_newline) {
896 | sweet_code += '\n';
897 | }
898 |
899 | if (eol !== '\n') {
900 | sweet_code = sweet_code.replace(/[\n]/g, eol);
901 | }
902 |
903 | return sweet_code;
904 | };
905 |
906 | this.set_indent = function(level) {
907 | // Never indent your first output indent at the start of the file
908 | if (lines.length > 1) {
909 | while (level >= this.indent_cache.length) {
910 | this.indent_cache.push(this.indent_cache[this.indent_cache.length - 1] + this.indent_string);
911 | }
912 |
913 | this.current_line.set_indent(level);
914 | return true;
915 | }
916 | this.current_line.set_indent(0);
917 | return false;
918 | };
919 |
920 | this.add_raw_token = function(token) {
921 | for (var x = 0; x < token.newlines; x++) {
922 | this.add_outputline();
923 | }
924 | this.current_line.push(token.whitespace_before);
925 | this.current_line.push(token.text);
926 | this.space_before_token = false;
927 | };
928 |
929 | this.add_token = function(printable_token) {
930 | this.add_space_before_token();
931 | this.current_line.push(printable_token);
932 | };
933 |
934 | this.add_space_before_token = function() {
935 | if (this.space_before_token && !this.just_added_newline()) {
936 | this.current_line.push(' ');
937 | }
938 | this.space_before_token = false;
939 | };
940 |
941 | this.remove_indent = function(index) {
942 | var output_length = lines.length;
943 | while (index < output_length) {
944 | lines[index].remove_indent();
945 | index++;
946 | }
947 | };
948 |
949 | this.trim = function(eat_newlines) {
950 | eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
951 |
952 | this.current_line.trim(indent_string, baseIndentString);
953 |
954 | while (eat_newlines && lines.length > 1 &&
955 | this.current_line.is_empty()) {
956 | lines.pop();
957 | this.current_line = lines[lines.length - 1];
958 | this.current_line.trim();
959 | }
960 |
961 | this.previous_line = lines.length > 1 ? lines[lines.length - 2] : null;
962 | };
963 |
964 | this.just_added_newline = function() {
965 | return this.current_line.is_empty();
966 | };
967 |
968 | this.just_added_blankline = function() {
969 | if (this.just_added_newline()) {
970 | if (lines.length === 1) {
971 | return true; // start of the file and newline = blank
972 | }
973 |
974 | var line = lines[lines.length - 2];
975 | return line.is_empty();
976 | }
977 | return false;
978 | };
979 | }
980 |
981 | module.exports.Output = Output;
982 |
983 |
984 | /***/ }),
985 | /* 4 */
986 | /***/ (function(module, exports, __webpack_require__) {
987 |
988 | /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
989 | /*
990 |
991 | The MIT License (MIT)
992 |
993 | Copyright (c) 2007-2017 Einar Lielmanis, Liam Newman, and contributors.
994 |
995 | Permission is hereby granted, free of charge, to any person
996 | obtaining a copy of this software and associated documentation files
997 | (the "Software"), to deal in the Software without restriction,
998 | including without limitation the rights to use, copy, modify, merge,
999 | publish, distribute, sublicense, and/or sell copies of the Software,
1000 | and to permit persons to whom the Software is furnished to do so,
1001 | subject to the following conditions:
1002 |
1003 | The above copyright notice and this permission notice shall be
1004 | included in all copies or substantial portions of the Software.
1005 |
1006 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1007 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1008 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1009 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1010 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1011 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1012 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1013 | SOFTWARE.
1014 | */
1015 |
1016 | var Beautifier = __webpack_require__(0).Beautifier;
1017 |
1018 | function css_beautify(source_text, options) {
1019 | var beautifier = new Beautifier(source_text, options);
1020 | return beautifier.beautify();
1021 | }
1022 |
1023 | module.exports = css_beautify;
1024 |
1025 | /***/ })
1026 | /******/ ]);
1027 | var css_beautify = legacy_beautify_css;
1028 | /* Footer */
1029 | if (typeof define === "function" && define.amd) {
1030 | // Add support for AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
1031 | define([], function() {
1032 | return {
1033 | css_beautify: css_beautify
1034 | };
1035 | });
1036 | } else if (typeof exports !== "undefined") {
1037 | // Add support for CommonJS. Just put this file somewhere on your require.paths
1038 | // and you will be able to `var html_beautify = require("beautify").html_beautify`.
1039 | exports.css_beautify = css_beautify;
1040 | } else if (typeof window !== "undefined") {
1041 | // If we're running a web page and don't have either of the above, add our one global
1042 | window.css_beautify = css_beautify;
1043 | } else if (typeof global !== "undefined") {
1044 | // If we don't even have window, try global.
1045 | global.css_beautify = css_beautify;
1046 | }
1047 |
1048 | }());
1049 |
--------------------------------------------------------------------------------
/src/content.js:
--------------------------------------------------------------------------------
1 | // Report Table
2 | var reportElement = document.createElement('div');
3 | var reportFailedElement = document.createElement('div');
4 |
5 | // Downloading Flag
6 | var isDownloading = false;
7 |
8 | // Resource Collector
9 | var reqs = {};
10 |
11 | // Reset Resource Collector
12 | function resetResourceCollector() {
13 | reqs = {};
14 | }
15 |
16 | // List download sites state
17 | var downloadSites = {
18 | sites: [
19 | // {
20 | // url: "https://google.com.au",
21 | // isDownloading: false,
22 | // isDownloaded: false,
23 | // isFailed: false,
24 | // },
25 | ],
26 | get listHtml() {
27 | return this.sites.map(function (site) {
28 | return `