total5 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,858 @@
1
+ // Total.js HTML/JS/CSS minificators
2
+ // The MIT License
3
+ // Copyright 2016-2023 (c) Peter Širka <petersirka@gmail.com>
4
+
5
+ 'use strict';
6
+
7
+ const REG_HTML_1 = /[\n\r\t]+/g;
8
+ const REG_HTML_2 = /\s{2,}/g;
9
+ const REG_HTML_4 = /\n\s{2,}./g;
10
+ const REG_HTML_5 = />\n\s{1,}</g;
11
+ const REG_HTML_6 = /[<\w"\u0080-\u07ff\u0400-\u04FF]+\s{2,}[\w\u0080-\u07ff\u0400-\u04FF>]+/;
12
+ const REG_HTML_9 = />\n\s+/g;
13
+ const REG_HTML_10 = /(\w|\W)\n\s+</g;
14
+ const REG_HTML_WIN = /\r/g;
15
+ const REG_CSS_0 = /\s{2,}|\t/g;
16
+ const REG_CSS_1 = /\n/g;
17
+ const REG_CSS_2 = /\s?\{\s{1,}/g;
18
+ const REG_CSS_3 = /\s?\}\s{1,}/g;
19
+ const REG_CSS_4 = /\s?:\s{1,}/g;
20
+ const REG_CSS_5 = /\s?;\s{1,}/g;
21
+ const REG_CSS_6 = /,\s{1,}/g;
22
+ const REG_CSS_7 = /\s\}/g;
23
+ const REG_CSS_8 = /\s\{/g;
24
+ const REG_CSS_9 = /;\}/g;
25
+ const REG_CSS_10 = /\$[a-z0-9-_]+(\s)*:.*?;/gi;
26
+ const REG_CSS_11 = /\$.*?(\s|;|\}|!)/gi;
27
+ const REG_CSS_12 = /(margin|padding):.*?(;|})/g;
28
+ const REG_CSS_13 = /#(0{6}|1{6}|2{6}|3{6}|4{6}|5{6}|6{6}|7{6}|8{6}|9{6}|0{6}|A{6}|B{6}|C{6}|D{6}|E{6}|F{6})+[\s;,)}]/gi;
29
+ const REG_CSS_14 = /\s>\s/g;
30
+ const REG_HTTPHTTPS = /^http(s)?:\/\//i;
31
+
32
+ exports.js = function(value) {
33
+
34
+ var index = 0;
35
+ var output = [];
36
+ var isCS = false; // comment multiline
37
+ var isCI = false; // comment inline
38
+ var alpha = /[0-9a-z$]/i;
39
+ var white = /\W/;
40
+ var skip = { '$': true, '_': true };
41
+ var newlines = { '\n': 1, '\r': 1 };
42
+ var regexp = false;
43
+ var scope, prev, next, last;
44
+ var vtmp = false;
45
+ var regvar = /^(\s)*var /;
46
+ var vindex = 0;
47
+
48
+ while (true) {
49
+
50
+ var c = value[index];
51
+ var prev = value[index - 1];
52
+ var next = value[index + 1];
53
+
54
+ index++;
55
+
56
+ if (c === undefined)
57
+ break;
58
+
59
+ if (!scope) {
60
+
61
+ if (!regexp) {
62
+
63
+ if (!isCI && c === '/' && next === '*') {
64
+ isCS = true;
65
+ continue;
66
+ } else if (!isCI && c === '*' && next === '/') {
67
+ isCS = false;
68
+ index++;
69
+ continue;
70
+ }
71
+
72
+ if (isCS)
73
+ continue;
74
+
75
+ if (c === '/' && next === '/') {
76
+ isCI = true;
77
+ continue;
78
+ } else if (isCI && newlines[c]) {
79
+ isCI = false;
80
+ alpha.test(last) && output.push(' ');
81
+ last = '';
82
+ continue;
83
+ }
84
+
85
+ if (isCI)
86
+ continue;
87
+ }
88
+
89
+ if (c === '\t' || newlines[c]) {
90
+ if (!last || !alpha.test(last))
91
+ continue;
92
+ output.push(' ');
93
+ last = '';
94
+ continue;
95
+ }
96
+
97
+ if (!regexp && (c === ' ' && (white.test(prev) || white.test(next)))) {
98
+ // if (!skip[prev] && !skip[next])
99
+ if (!skip[prev]) {
100
+ if (!skip[next] || !alpha.test(prev))
101
+ continue;
102
+ }
103
+ }
104
+
105
+ if (regexp) {
106
+ if ((last !== '\\' && c === '/') || (last === '\\' && c === '/' && output[output.length - 2] === '\\'))
107
+ regexp = false;
108
+ } else
109
+ regexp = (last === '=' || last === '(' || last === ':' || last === '{' || last === '[' || last === '?') && (c === '/');
110
+ }
111
+
112
+ if (scope && c === '\\') {
113
+ output.push(c);
114
+ output.push(next);
115
+ index++;
116
+ last = next;
117
+ continue;
118
+ }
119
+
120
+ if (!regexp && (c === '"' || c === '\'' || c === '`')) {
121
+
122
+ if (scope && scope !== c) {
123
+ output.push(c);
124
+ continue;
125
+ }
126
+
127
+ if (c === scope)
128
+ scope = 0;
129
+ else
130
+ scope = c;
131
+ }
132
+
133
+ // var
134
+ if (!scope && c === 'v' && next === 'a') {
135
+ var v = c + value[index] + value[index + 1] + value[index + 2];
136
+ if (v === 'var ') {
137
+ if (vtmp && output[output.length - 1] === ';') {
138
+ output.pop();
139
+ output.push(',');
140
+ } else
141
+ output.push('var ');
142
+ index += 3;
143
+ vtmp = true;
144
+ continue;
145
+ }
146
+ } else {
147
+ if (vtmp) {
148
+ vindex = index + 1;
149
+ while (true) {
150
+ if (!value[vindex] || !white.test(value[vindex]))
151
+ break;
152
+ vindex++;
153
+ }
154
+ if (c === '(' || c === ')' || (c === ';' && !regvar.test(value.substring(vindex, vindex + 20))))
155
+ vtmp = false;
156
+ }
157
+ }
158
+
159
+ if ((c === '+' || c === '-') && next === ' ') {
160
+ if (value[index + 1] === c) {
161
+ index += 2;
162
+ output.push(c);
163
+ output.push(' ');
164
+ output.push(c);
165
+ last = c;
166
+ continue;
167
+ }
168
+ }
169
+
170
+ if (!scope && (c === '}' && last === ';') || ((c === '}' || c === ']') && output[output.length - 1] === ' ' && alpha.test(output[output.length - 2])))
171
+ output.pop();
172
+
173
+ output.push(c);
174
+ last = c;
175
+ }
176
+
177
+ return output.join('').trim();
178
+ };
179
+
180
+ exports.css = function(value) {
181
+ try {
182
+ var isvariable = false;
183
+ value = cssnested(value, '', () => isvariable = true);
184
+ value = cssautovendor(value);
185
+ if (isvariable)
186
+ value = cssvariables(value);
187
+ return value;
188
+ } catch (ex) {
189
+ F.error(new Error('CSS compiler error: ' + ex.message));
190
+ return '';
191
+ }
192
+ };
193
+
194
+ exports.html = function(html, ischunk) {
195
+
196
+ html = exports.htmlremovecomments(html.replace(REG_HTML_WIN, ''));
197
+
198
+ var tags = ['script', 'textarea', 'pre', 'code', 'readme'];
199
+ var id = '[' + new Date().getTime() + ']#';
200
+ var cache = {};
201
+ var indexer = 0;
202
+ var length = tags.length;
203
+ var chars = 65;
204
+ var tagBeg, tagEnd, beg, end, len, key, value;
205
+
206
+ for (var i = 0; i < length; i++) {
207
+ var o = tags[i];
208
+
209
+ tagBeg = '<' + o;
210
+ tagEnd = '</' + o;
211
+
212
+ beg = html.indexOf(tagBeg);
213
+ end = 0;
214
+ len = tagEnd.length;
215
+
216
+ while (beg !== -1) {
217
+
218
+ end = html.indexOf(tagEnd, beg + 3);
219
+ if (end === -1) {
220
+ if (ischunk)
221
+ end = html.length;
222
+ else
223
+ break;
224
+ }
225
+
226
+ key = id + (indexer++) + String.fromCharCode(chars++);
227
+ if (chars > 90)
228
+ chars = 65;
229
+
230
+ value = html.substring(beg, end + len);
231
+
232
+ if (!i) {
233
+ end = value.indexOf('>');
234
+ len = value.indexOf('type="text/template"');
235
+
236
+ if (len < end && len !== -1) {
237
+ beg = html.indexOf(tagBeg, beg + tagBeg.length);
238
+ continue;
239
+ }
240
+
241
+ len = value.indexOf('type="text/html"');
242
+
243
+ if (len < end && len !== -1) {
244
+ beg = html.indexOf(tagBeg, beg + tagBeg.length);
245
+ continue;
246
+ }
247
+
248
+ len = value.indexOf('type="text/ng-template"');
249
+
250
+ if (len < end && len !== -1) {
251
+ beg = html.indexOf(tagBeg, beg + tagBeg.length);
252
+ continue;
253
+ }
254
+ }
255
+
256
+ cache[key] = value;
257
+ html = replacer(html, value, key);
258
+ beg = html.indexOf(tagBeg, beg + tagBeg.length);
259
+ }
260
+ }
261
+
262
+ while (true) {
263
+ if (!REG_HTML_6.test(html))
264
+ break;
265
+ html = html.replace(REG_HTML_6, text => text.replace(/\s+/g, ' '));
266
+ }
267
+
268
+ html = html.replace(REG_HTML_9, '>').replace(REG_HTML_10, function(text) {
269
+ return text.trim().replace(/\s/g, '');
270
+ }).replace(REG_HTML_5, '><').replace(REG_HTML_4, function(text) {
271
+ var c = text[text.length - 1];
272
+ return c === '<' ? c : ' ' + c;
273
+ }).replace(REG_HTML_1, '').replace(REG_HTML_2, '');
274
+
275
+ for (var k in cache)
276
+ html = replacer(html, k, cache[k]);
277
+
278
+ return exports.htmlcss(exports.htmljs(html));
279
+ };
280
+
281
+ exports.htmlremovecomments = function(value) {
282
+ var tagBeg = '<!--';
283
+ var tagEnd = '-->';
284
+ var beg = value.indexOf(tagBeg);
285
+ var end = 0;
286
+
287
+ while (beg !== -1) {
288
+ end = value.indexOf(tagEnd, beg + 4);
289
+
290
+ if (end === -1)
291
+ break;
292
+
293
+ var comment = value.substring(beg, end + 3);
294
+ if (comment.indexOf('[if') !== -1 || comment.indexOf('[endif') !== -1) {
295
+ beg = value.indexOf(tagBeg, end + 3);
296
+ } else {
297
+ value = replacer(value, comment, '');
298
+ beg = value.indexOf(tagBeg, beg);
299
+ }
300
+ }
301
+ return value;
302
+ };
303
+
304
+ exports.merge = async function(filename, filenames, minify = true) {
305
+
306
+ // @filename {String/Boolean}
307
+
308
+ var isbuffer = false;
309
+ var writer = null;
310
+
311
+ if (typeof(filename) === 'string') {
312
+ writer = F.Fs.createWriteStream(filename);
313
+ } else {
314
+ writer = [];
315
+ isbuffer = true;
316
+ }
317
+
318
+ for (let i = 0; i < filenames.length; i++) {
319
+
320
+ let path = filenames[i];
321
+ let response = '';
322
+
323
+ if (REG_HTTPHTTPS.test(path))
324
+ response = await mergedownload(path, minify);
325
+ else
326
+ response = await mergefile(path, minify);
327
+
328
+ if (DEBUG)
329
+ mergedebug(writer, path, response.ext, i);
330
+
331
+ if (response.body) {
332
+ if (isbuffer)
333
+ writer.push(Buffer.from(response.body, 'utf8'));
334
+ else
335
+ writer.write(response.body, 'utf8');
336
+ }
337
+ }
338
+
339
+ if (isbuffer)
340
+ return Buffer.concat(writer);
341
+
342
+ writer.end();
343
+ return filename;
344
+ };
345
+
346
+ function mergedebug(writer, filename, ext, index) {
347
+
348
+ if (filename.substring(0, F.directory.length) === F.directory)
349
+ filename = filename.substring(F.directory.length);
350
+
351
+ var plus = '===========================================================================================';
352
+ var beg = ext === 'js' ? '/*\n' : ext === 'css' ? '/*!\n' : '<!--\n';
353
+ var end = ext === 'js' || ext === 'css' ? '\n */' : '\n-->';
354
+ var mid = ext !== 'html' ? ' * ' : ' ';
355
+ var line = (index > 0 ? '\n\n' : '') + beg + mid + plus + '\n' + mid + 'MERGED: ' + filename + '\n' + mid + plus + end + '\n\n';
356
+
357
+ if (writer instanceof Array)
358
+ writer.push(Buffer.from(line, 'utf8'));
359
+ else
360
+ writer.write(line, 'utf8');
361
+ }
362
+
363
+ async function mergedownload(url, minify = true) {
364
+ return new Promise(function(resolve) {
365
+ var opt = {};
366
+ opt.method = 'GET';
367
+ opt.url = url;
368
+ opt.callback = function(err, response) {
369
+
370
+ if (err) {
371
+ resolve('');
372
+ F.error(err, 'total5/minificators/merge');
373
+ return;
374
+ }
375
+
376
+ var index = url.lastIndexOf('?');
377
+ var ext = '';
378
+
379
+ if (index !== -1)
380
+ url = url.substring(0, index);
381
+
382
+ url = url.toLowerCase();
383
+
384
+ var isminified = (/(-|_|@|.)min(.|@|-|_)/).test(url);
385
+
386
+ index = url.lastIndexOf('.');
387
+
388
+ if (index !== -1) {
389
+ ext = url.substring(index + 1);
390
+ index = ext.indexOf('?');
391
+ if (index !== -1)
392
+ ext = ext.substring(0, index);
393
+ ext = ext.toLowerCase();
394
+ }
395
+
396
+ var output = { ext: ext };
397
+
398
+ response.body = response.body.ROOT();
399
+
400
+ if (minify && !isminified) {
401
+ switch (ext) {
402
+ case 'js':
403
+ output.body = exports.js(response.body);
404
+ resolve(output);
405
+ return;
406
+ case 'css':
407
+ output.body = exports.css(response.body);
408
+ resolve(output);
409
+ return;
410
+ case 'html':
411
+ output.body = exports.html(response.body);
412
+ resolve(output);
413
+ return;
414
+ }
415
+ }
416
+
417
+ output.body = response.body;
418
+ resolve(output);
419
+ };
420
+
421
+ F.TUtils.request(opt);
422
+ });
423
+ }
424
+
425
+ async function mergefile(filename, minify) {
426
+ return new Promise(function(resolve) {
427
+
428
+ F.Fs.readFile(filename, 'utf8', function(err, response) {
429
+
430
+ if (err) {
431
+ resolve('');
432
+ F.error(err, 'total5/minificators/merge');
433
+ return;
434
+ }
435
+
436
+ var isminified = (/(-|_|@|.)min(-|_|@|.)/).test(filename);
437
+ var index = filename.lastIndexOf('.');
438
+ var ext = '';
439
+
440
+ if (index !== -1) {
441
+ ext = filename.substring(index + 1);
442
+ index = ext.indexOf('?');
443
+ if (index !== -1)
444
+ ext = ext.substring(0, index);
445
+ ext = ext.toLowerCase();
446
+ }
447
+
448
+ var output = { ext: ext };
449
+
450
+ response = response.ROOT();
451
+
452
+ if (minify && !isminified) {
453
+ switch (ext) {
454
+ case 'js':
455
+ output.body = exports.js(response);
456
+ resolve(output);
457
+ return;
458
+ case 'css':
459
+ output.body = exports.css(response);
460
+ resolve(output);
461
+ return;
462
+ case 'html':
463
+ output.body = exports.html(response);
464
+ resolve(output);
465
+ return;
466
+ }
467
+ }
468
+
469
+ output.body = response;
470
+ resolve(output);
471
+ });
472
+
473
+ });
474
+ }
475
+
476
+ function cssnested(css, id, variable) {
477
+
478
+ if (!css)
479
+ return css;
480
+
481
+ var index = 0;
482
+ var output = '';
483
+ var A = false;
484
+ var count = 0;
485
+ var beg;
486
+ var begAt;
487
+ var valid = false;
488
+ var plus = '';
489
+ var skip = false;
490
+ var skipImport = '';
491
+ var isComment = false;
492
+ var comment = '';
493
+ var skipView = false;
494
+ var skipType;
495
+
496
+ while (true) {
497
+
498
+ var a = css[index++];
499
+ if (!a)
500
+ break;
501
+
502
+ if (a === '/' && css[index] === '*') {
503
+ isComment = true;
504
+ index++;
505
+ comment = '';
506
+ continue;
507
+ }
508
+
509
+ if (isComment) {
510
+ comment += a;
511
+ if (a === '*' && css[index] === '/') {
512
+ isComment = false;
513
+ index++;
514
+ if (comment === 'auto*')
515
+ output += '/*auto*/';
516
+ }
517
+ continue;
518
+ }
519
+
520
+ if (a === '\n' || a === '\r')
521
+ continue;
522
+
523
+ if (a === '$' && variable)
524
+ variable();
525
+
526
+ if (a === '@' && css[index] === '{')
527
+ skipView = true;
528
+
529
+ if (skipView) {
530
+ plus += a;
531
+ if (a === '}')
532
+ skipView = false;
533
+ continue;
534
+ }
535
+
536
+ if (a === '\'' || a === '"') {
537
+ if (a === skipType && css[index] !== '\\')
538
+ skipType = '';
539
+ else if (!skipType) {
540
+ skipType = a;
541
+ }
542
+ }
543
+
544
+ if (skipType) {
545
+ plus += a;
546
+ continue;
547
+ }
548
+
549
+ if (a === '@') {
550
+ begAt = index;
551
+ skip = true;
552
+ }
553
+
554
+ if (skip && !skipImport && (a === ';' || a === '{')) {
555
+ skipImport = a;
556
+ if (a === ';') {
557
+ output += css.substring(begAt - 1, index);
558
+ skip = false;
559
+ plus = '';
560
+ continue;
561
+ }
562
+ }
563
+
564
+ plus += a;
565
+
566
+ if (a === '{') {
567
+
568
+ if (A) {
569
+ count++;
570
+ continue;
571
+ }
572
+
573
+ A = true;
574
+ count = 0;
575
+ beg = index;
576
+ valid = false;
577
+ continue;
578
+ }
579
+
580
+ if (a === '}') {
581
+
582
+ if (count > 0) {
583
+ count--;
584
+ valid = true;
585
+ continue;
586
+ }
587
+
588
+ if (!valid) {
589
+ output += plus;
590
+ plus = '';
591
+ A = false;
592
+ skip = false;
593
+ skipImport = '';
594
+ continue;
595
+ }
596
+
597
+ if (skip) {
598
+
599
+ if (plus.indexOf('@keyframes') !== -1) {
600
+ output += plus;
601
+ } else {
602
+ begAt = plus.indexOf('{');
603
+ output += plus.substring(0, begAt + 1) + cssnested_process(plus.substring(begAt), id).trim() + '}';
604
+ }
605
+
606
+ A = false;
607
+ skip = false;
608
+ skipImport = '';
609
+ plus = '';
610
+
611
+ continue;
612
+ }
613
+
614
+ var ni = beg - 1;
615
+ var name = '';
616
+
617
+ while (true) {
618
+ var b = css[ni--];
619
+ if (b === '{')
620
+ continue;
621
+ if (b === '}' || b === '\n' || b === '\r' || b === undefined || (skipImport && skipImport === b))
622
+ break;
623
+ name = b + name;
624
+ }
625
+
626
+ A = false;
627
+ skip = false;
628
+ skipImport = '';
629
+ plus = '';
630
+ output += cssnested_process(css.substring(beg - 1, index), (id || '') + name.trim());
631
+ }
632
+ }
633
+
634
+ return output + plus;
635
+ }
636
+
637
+ function cssautovendor(css) {
638
+ return css.replace(REG_CSS_0, ' ').replace(REG_CSS_1, '').replace(REG_CSS_2, '{').replace(REG_CSS_3, '}').replace(REG_CSS_4, ':').replace(REG_CSS_5, ';').replace(REG_CSS_6, function(search, index, text) {
639
+ for (var i = index; i > 0; i--) {
640
+ if ((text[i] === '\'' || text[i] === '"') && (text[i - 1] === ':'))
641
+ return search;
642
+ }
643
+ return ',';
644
+ }).replace(REG_CSS_7, '}').replace(REG_CSS_8, '{').replace(REG_CSS_9, '}').replace(REG_CSS_12, cssmarginpadding).replace(REG_CSS_13, csscolors).replace(REG_CSS_14, '>').trim();
645
+ }
646
+
647
+ function csscolors(text) {
648
+ return text.substring(0, 4) + text.charAt(text.length - 1);
649
+ }
650
+
651
+ function cssmarginpadding(text) {
652
+
653
+ // margin
654
+ // padding
655
+
656
+ var prop = '';
657
+ var val;
658
+ var l = text.length - 1;
659
+ var last = text[l];
660
+
661
+ if (text[0] === 'm') {
662
+ prop = 'margin:';
663
+ val = text.substring(7, l);
664
+ } else {
665
+ prop = 'padding:';
666
+ val = text.substring(8, l);
667
+ }
668
+
669
+ var a = val.split(' ');
670
+
671
+ for (var i = 0; i < a.length; i++) {
672
+ if (a[i][0] === '0' && a[i].charCodeAt(1) > 58)
673
+ a[i] = '0';
674
+ }
675
+
676
+ // 0 0 0 0 --> 0
677
+ if (a[0] === '0' && a[1] === '0' && a[2] === '0' && a[3] === '0')
678
+ return prop + '0' + last;
679
+
680
+ // 20px 0 0 0 --> 20px 0 0
681
+ if (a[0] !== '0' && a[1] === '0' && a[2] === '0' && a[3] === '0')
682
+ return prop + a[0] + ' 0 0' + last;
683
+
684
+ // 20px 30px 20px 30px --> 20px 30px
685
+ if (a[1] && a[2] && a[3] && a[0] === a[2] && a[1] === a[3])
686
+ return prop + a[0] + ' ' + a[1] + last;
687
+
688
+ // 20px 30px 10px 30px --> 20px 30px 10px
689
+ if (a[2] && a[3] && a[1] === a[3] && a[0] !== a[2])
690
+ return prop + a[0] + ' ' + a[1] + ' ' + a[2] + last;
691
+
692
+ return text;
693
+ }
694
+
695
+ function cssnested_process(css, name) {
696
+ css = css.trim();
697
+ css = cssnested_make(css.substring(1, css.length - 1), name);
698
+ return cssnested(css, name);
699
+ }
700
+
701
+ function cssnested_make(css, name) {
702
+
703
+ var index = 0;
704
+ var plus = '';
705
+ var output = '';
706
+ var count = 0;
707
+ var A = false;
708
+ var valid = false;
709
+
710
+ while (true) {
711
+ var a = css[index++];
712
+
713
+ if (!a)
714
+ break;
715
+
716
+ if (a === '\n' || a === '\r')
717
+ continue;
718
+
719
+ if (a !== ' ' || plus[plus.length -1] !== ' ')
720
+ plus += a;
721
+
722
+ if (a === '{') {
723
+
724
+ if (A) {
725
+ count++;
726
+ continue;
727
+ }
728
+
729
+ A = true;
730
+ count = 0;
731
+ valid = false;
732
+ continue;
733
+ }
734
+
735
+ if (a === '}') {
736
+
737
+ if (count > 0) {
738
+ count--;
739
+ valid = true;
740
+ continue;
741
+ }
742
+
743
+ if (!valid) {
744
+ output += name + ' ' + plus.trim();
745
+ plus = '';
746
+ A = false;
747
+ continue;
748
+ }
749
+
750
+ output += plus;
751
+ }
752
+ }
753
+
754
+ return output;
755
+ }
756
+
757
+ function cssvariables(value) {
758
+
759
+ if (!value)
760
+ return value;
761
+
762
+ var variables = {};
763
+
764
+ value = value.replace(REG_CSS_10, function(text) {
765
+ var index = text.indexOf(':');
766
+ if (index === -1)
767
+ return text;
768
+ var key = text.substring(0, index).trim();
769
+ variables[key] = text.substring(index + 1, text.length - 1).trim();
770
+ return '';
771
+ });
772
+
773
+ value = value.replace(REG_CSS_11, function(text) {
774
+
775
+ var index = text.indexOf('||');
776
+ var variable = '';
777
+ var last = text[text.length - 1];
778
+ var len = text.length;
779
+
780
+ if (last === ';' || last === '}' || last === '!' || last === ' ')
781
+ len = len - 1;
782
+ else
783
+ last = '';
784
+
785
+ if (index !== -1)
786
+ variable = variables[text.substring(0, index).trim()] || text.substring(index + 2, len).trim();
787
+ else
788
+ variable = variables[text.substring(0, len).trim()];
789
+
790
+ return variable ? (variable + last) : text;
791
+ }).trim();
792
+
793
+ return value;
794
+ }
795
+
796
+ exports.htmljs = function(html, index = 0) {
797
+
798
+ if (!F.config.$minifyjs)
799
+ return html;
800
+
801
+ var strFrom = '<script type="text/javascript">';
802
+ var strTo = '</script>';
803
+
804
+ var indexBeg = html.indexOf(strFrom, index);
805
+ if (indexBeg === -1) {
806
+ strFrom = '<script>';
807
+ indexBeg = html.indexOf(strFrom, index);
808
+ if (indexBeg === -1)
809
+ return html;
810
+ }
811
+
812
+ var indexEnd = html.indexOf(strTo, indexBeg + strFrom.length);
813
+ if (indexEnd === -1)
814
+ return html;
815
+
816
+ var js = html.substring(indexBeg, indexEnd + strTo.length).trim();
817
+ var beg = html.indexOf(js);
818
+ if (beg === -1)
819
+ return html;
820
+
821
+ var val = js.substring(strFrom.length, js.length - strTo.length).trim();
822
+ var compiled = exports.js(val);
823
+ html = replacer(html, js, strFrom + compiled.trim() + strTo.trim());
824
+ return exports.htmljs(html, indexBeg + compiled.length + 9);
825
+ };
826
+
827
+ exports.htmlcss = function(html, index = 0) {
828
+
829
+ if (!F.config.$minifycss)
830
+ return html;
831
+
832
+ var strFrom = '<style';
833
+ var strTo = '</style>';
834
+
835
+ var indexBeg = html.indexOf(strFrom, index);
836
+ if (indexBeg === -1)
837
+ return html;
838
+
839
+ var indexBeg2 = html.indexOf('>', indexBeg + strFrom.length);
840
+ if (indexBeg2 === -1)
841
+ return html;
842
+
843
+ strFrom = html.substring(indexBeg, indexBeg2 + 1);
844
+ var indexEnd = html.indexOf(strTo, indexBeg2 + strFrom.length);
845
+ if (indexEnd === -1)
846
+ return html;
847
+
848
+ var css = html.substring(indexBeg, indexEnd + strTo.length);
849
+ var val = css.substring(strFrom.length, css.length - strTo.length).trim();
850
+ var compiled = exports.css(val);
851
+ html = replacer(html, css, (strFrom + compiled.trim() + strTo).trim());
852
+ return exports.htmlcss(html, indexBeg2 + compiled.length + 8);
853
+ };
854
+
855
+ function replacer(str, find, text) {
856
+ var beg = str.indexOf(find);
857
+ return beg === -1 ? str : (str.substring(0, beg) + text + str.substring(beg + find.length));
858
+ }