@lmjs/core 1.0.7 → 2.0.0

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,1173 @@
1
+ let _w = self;
2
+ var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g
3
+
4
+ function parseMe(css, options) {
5
+ options = options || {};
6
+
7
+ /**
8
+ * Positional.
9
+ */
10
+
11
+ var lineno = 1;
12
+ var column = 1;
13
+
14
+ /**
15
+ * Update lineno and column based on `str`.
16
+ */
17
+
18
+ function updatePosition(str) {
19
+ var lines = str.match(/\n/g);
20
+ if (lines) lineno += lines.length;
21
+ var i = str.lastIndexOf('\n');
22
+ column = ~i ? str.length - i : column + str.length;
23
+ }
24
+
25
+ /**
26
+ * Mark position and patch `node.position`.
27
+ */
28
+
29
+ function position() {
30
+ var start = { line: lineno, column: column };
31
+ return function (node) {
32
+ node.position = new Position(start);
33
+ whitespace();
34
+ return node;
35
+ };
36
+ }
37
+
38
+ /**
39
+ * Store position information for a node
40
+ */
41
+
42
+ function Position(start) {
43
+ this.start = start;
44
+ this.end = { line: lineno, column: column };
45
+ this.source = options.source;
46
+ }
47
+
48
+ /**
49
+ * Non-enumerable source string
50
+ */
51
+
52
+ Position.prototype.content = css;
53
+
54
+ /**
55
+ * Error `msg`.
56
+ */
57
+
58
+ var errorsList = [];
59
+
60
+ function error(msg) {
61
+ var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
62
+ err.reason = msg;
63
+ err.filename = options.source;
64
+ err.line = lineno;
65
+ err.column = column;
66
+ err.source = css;
67
+
68
+ if (options.silent) {
69
+ errorsList.push(err);
70
+ } else {
71
+ throw err;
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Parse stylesheet.
77
+ */
78
+
79
+ function stylesheet() {
80
+ var rulesList = rules();
81
+
82
+ return {
83
+ type: 'stylesheet',
84
+ stylesheet: {
85
+ source: options.source,
86
+ rules: rulesList,
87
+ parsingErrors: errorsList
88
+ }
89
+ };
90
+ }
91
+
92
+ /**
93
+ * Opening brace.
94
+ */
95
+
96
+ function open() {
97
+ return match(/^{\s*/);
98
+ }
99
+
100
+ /**
101
+ * Closing brace.
102
+ */
103
+
104
+ function close() {
105
+ return match(/^}/);
106
+ }
107
+
108
+ /**
109
+ * Parse ruleset.
110
+ */
111
+
112
+ function rules() {
113
+ var node;
114
+ var rules = [];
115
+ whitespace();
116
+ comments(rules);
117
+ while (css.length && css.charAt(0) != '}' && (node = atrule() || rule())) {
118
+ if (node !== false) {
119
+ rules.push(node);
120
+ comments(rules);
121
+ }
122
+ }
123
+ return rules;
124
+ }
125
+
126
+ /**
127
+ * Match `re` and return captures.
128
+ */
129
+
130
+ function match(re) {
131
+ var m = re.exec(css);
132
+ if (!m) return;
133
+ var str = m[0];
134
+ updatePosition(str);
135
+ css = css.slice(str.length);
136
+ return m;
137
+ }
138
+
139
+ /**
140
+ * Parse whitespace.
141
+ */
142
+
143
+ function whitespace() {
144
+ match(/^\s*/);
145
+ }
146
+
147
+ /**
148
+ * Parse comments;
149
+ */
150
+
151
+ function comments(rules) {
152
+ var c;
153
+ rules = rules || [];
154
+ while (c = comment()) {
155
+ if (c !== false) {
156
+ rules.push(c);
157
+ }
158
+ }
159
+ return rules;
160
+ }
161
+
162
+ /**
163
+ * Parse comment.
164
+ */
165
+
166
+ function comment() {
167
+ var pos = position();
168
+ if ('/' != css.charAt(0) || '*' != css.charAt(1)) return;
169
+
170
+ var i = 2;
171
+ while ("" != css.charAt(i) && ('*' != css.charAt(i) || '/' != css.charAt(i + 1))) ++i;
172
+ i += 2;
173
+
174
+ if ("" === css.charAt(i - 1)) {
175
+ return error('End of comment missing');
176
+ }
177
+
178
+ var str = css.slice(2, i - 2);
179
+ column += 2;
180
+ updatePosition(str);
181
+ css = css.slice(i);
182
+ column += 2;
183
+
184
+ return pos({
185
+ type: 'comment',
186
+ comment: str
187
+ });
188
+ }
189
+
190
+ /**
191
+ * Parse selector.
192
+ */
193
+
194
+ function selector() {
195
+ var m = match(/^([^{]+)/);
196
+ if (!m) return;
197
+ /* @fix Remove all comments from selectors
198
+ * http://ostermiller.org/findcomment.html */
199
+ return trim(m[0])
200
+ .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
201
+ .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function (m) {
202
+ return m.replace(/,/g, '\u200C');
203
+ })
204
+ .split(/\s*(?![^(]*\)),\s*/)
205
+ .map(function (s) {
206
+ return s.replace(/\u200C/g, ',');
207
+ });
208
+ }
209
+
210
+ /**
211
+ * Parse declaration.
212
+ */
213
+
214
+ function declaration() {
215
+ var pos = position();
216
+
217
+ // prop
218
+ var prop = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
219
+ if (!prop) return;
220
+ prop = trim(prop[0]);
221
+
222
+ // :
223
+ if (!match(/^:\s*/)) return error("property missing ':'");
224
+
225
+ // val
226
+ var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
227
+
228
+ var ret = pos({
229
+ type: 'declaration',
230
+ property: prop.replace(commentre, ''),
231
+ value: val ? trim(val[0]).replace(commentre, '') : ''
232
+ });
233
+
234
+ // ;
235
+ match(/^[;\s]*/);
236
+
237
+ return ret;
238
+ }
239
+
240
+ /**
241
+ * Parse declarations.
242
+ */
243
+
244
+ function declarations() {
245
+ var decls = [];
246
+
247
+ if (!open()) return error("missing '{'");
248
+ comments(decls);
249
+
250
+ // declarations
251
+ var decl;
252
+ while (decl = declaration()) {
253
+ if (decl !== false) {
254
+ decls.push(decl);
255
+ comments(decls);
256
+ }
257
+ }
258
+
259
+ if (!close()) return error("missing '}'");
260
+ return decls;
261
+ }
262
+
263
+ /**
264
+ * Parse keyframe.
265
+ */
266
+
267
+ function keyframe() {
268
+ var m;
269
+ var vals = [];
270
+ var pos = position();
271
+
272
+ while (m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/)) {
273
+ vals.push(m[1]);
274
+ match(/^,\s*/);
275
+ }
276
+
277
+ if (!vals.length) return;
278
+
279
+ return pos({
280
+ type: 'keyframe',
281
+ values: vals,
282
+ declarations: declarations()
283
+ });
284
+ }
285
+
286
+ /**
287
+ * Parse keyframes.
288
+ */
289
+
290
+ function atkeyframes() {
291
+ var pos = position();
292
+ var m = match(/^@([-\w]+)?keyframes\s*/);
293
+
294
+ if (!m) return;
295
+ var vendor = m[1];
296
+
297
+ // identifier
298
+ var m = match(/^([-\w]+)\s*/);
299
+ if (!m) return error("@keyframes missing name");
300
+ var name = m[1];
301
+
302
+ if (!open()) return error("@keyframes missing '{'");
303
+
304
+ var frame;
305
+ var frames = comments();
306
+ while (frame = keyframe()) {
307
+ frames.push(frame);
308
+ frames = frames.concat(comments());
309
+ }
310
+
311
+ if (!close()) return error("@keyframes missing '}'");
312
+
313
+ return pos({
314
+ type: 'keyframes',
315
+ name: name,
316
+ vendor: vendor,
317
+ keyframes: frames
318
+ });
319
+ }
320
+
321
+ /**
322
+ * Parse supports.
323
+ */
324
+
325
+ function atsupports() {
326
+ var pos = position();
327
+ var m = match(/^@supports *([^{]+)/);
328
+
329
+ if (!m) return;
330
+ var supports = trim(m[1]);
331
+
332
+ if (!open()) return error("@supports missing '{'");
333
+
334
+ var style = comments().concat(rules());
335
+
336
+ if (!close()) return error("@supports missing '}'");
337
+
338
+ return pos({
339
+ type: 'supports',
340
+ supports: supports,
341
+ rules: style
342
+ });
343
+ }
344
+
345
+ /**
346
+ * Parse host.
347
+ */
348
+
349
+ function athost() {
350
+ var pos = position();
351
+ var m = match(/^@host\s*/);
352
+
353
+ if (!m) return;
354
+
355
+ if (!open()) return error("@host missing '{'");
356
+
357
+ var style = comments().concat(rules());
358
+
359
+ if (!close()) return error("@host missing '}'");
360
+
361
+ return pos({
362
+ type: 'host',
363
+ rules: style
364
+ });
365
+ }
366
+
367
+ /**
368
+ * Parse media.
369
+ */
370
+
371
+ function atmedia() {
372
+ var pos = position();
373
+ var m = match(/^@media *([^{]+)/);
374
+
375
+ if (!m) return;
376
+ var media = trim(m[1]);
377
+
378
+ if (!open()) return error("@media missing '{'");
379
+
380
+ var style = comments().concat(rules());
381
+
382
+ if (!close()) return error("@media missing '}'");
383
+
384
+ return pos({
385
+ type: 'media',
386
+ media: media,
387
+ rules: style
388
+ });
389
+ }
390
+
391
+
392
+ /**
393
+ * Parse custom-media.
394
+ */
395
+
396
+ function atcustommedia() {
397
+ var pos = position();
398
+ var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
399
+ if (!m) return;
400
+
401
+ return pos({
402
+ type: 'custom-media',
403
+ name: trim(m[1]),
404
+ media: trim(m[2])
405
+ });
406
+ }
407
+
408
+ /**
409
+ * Parse paged media.
410
+ */
411
+
412
+ function atpage() {
413
+ var pos = position();
414
+ var m = match(/^@page */);
415
+ if (!m) return;
416
+
417
+ var sel = selector() || [];
418
+
419
+ if (!open()) return error("@page missing '{'");
420
+ var decls = comments();
421
+
422
+ // declarations
423
+ var decl;
424
+ while (decl = declaration()) {
425
+ decls.push(decl);
426
+ decls = decls.concat(comments());
427
+ }
428
+
429
+ if (!close()) return error("@page missing '}'");
430
+
431
+ return pos({
432
+ type: 'page',
433
+ selectors: sel,
434
+ declarations: decls
435
+ });
436
+ }
437
+
438
+ /**
439
+ * Parse document.
440
+ */
441
+
442
+ function atdocument() {
443
+ var pos = position();
444
+ var m = match(/^@([-\w]+)?document *([^{]+)/);
445
+ if (!m) return;
446
+
447
+ var vendor = trim(m[1]);
448
+ var doc = trim(m[2]);
449
+
450
+ if (!open()) return error("@document missing '{'");
451
+
452
+ var style = comments().concat(rules());
453
+
454
+ if (!close()) return error("@document missing '}'");
455
+
456
+ return pos({
457
+ type: 'document',
458
+ document: doc,
459
+ vendor: vendor,
460
+ rules: style
461
+ });
462
+ }
463
+
464
+ /**
465
+ * Parse font-face.
466
+ */
467
+
468
+ function atfontface() {
469
+ var pos = position();
470
+ var m = match(/^@font-face\s*/);
471
+ if (!m) return;
472
+
473
+ if (!open()) return error("@font-face missing '{'");
474
+ var decls = comments();
475
+
476
+ // declarations
477
+ var decl;
478
+ while (decl = declaration()) {
479
+ decls.push(decl);
480
+ decls = decls.concat(comments());
481
+ }
482
+
483
+ if (!close()) return error("@font-face missing '}'");
484
+
485
+ return pos({
486
+ type: 'font-face',
487
+ declarations: decls
488
+ });
489
+ }
490
+
491
+ /**
492
+ * Parse import
493
+ */
494
+
495
+ var atimport = _compileAtrule('import');
496
+
497
+ /**
498
+ * Parse charset
499
+ */
500
+
501
+ var atcharset = _compileAtrule('charset');
502
+
503
+ /**
504
+ * Parse namespace
505
+ */
506
+
507
+ var atnamespace = _compileAtrule('namespace');
508
+
509
+ /**
510
+ * Parse non-block at-rules
511
+ */
512
+
513
+
514
+ function _compileAtrule(name) {
515
+ var re = new RegExp('^@' + name + '\\s*([^;]+);');
516
+ return function () {
517
+ var pos = position();
518
+ var m = match(re);
519
+ if (!m) return;
520
+ var ret = { type: name };
521
+ ret[name] = m[1].trim();
522
+ return pos(ret);
523
+ }
524
+ }
525
+
526
+ /**
527
+ * Parse at rule.
528
+ */
529
+
530
+ function atrule() {
531
+ if (css[0] != '@') return;
532
+
533
+ return atkeyframes()
534
+ || atmedia()
535
+ || atcustommedia()
536
+ || atsupports()
537
+ || atimport()
538
+ || atcharset()
539
+ || atnamespace()
540
+ || atdocument()
541
+ || atpage()
542
+ || athost()
543
+ || atfontface();
544
+ }
545
+
546
+ /**
547
+ * Parse rule.
548
+ */
549
+
550
+ function rule() {
551
+ var pos = position();
552
+ var sel = selector();
553
+
554
+ if (!sel) return error('selector missing');
555
+ comments();
556
+
557
+ return pos({
558
+ type: 'rule',
559
+ selectors: sel,
560
+ declarations: declarations()
561
+ });
562
+ }
563
+
564
+ return addParent(stylesheet());
565
+ };
566
+
567
+ /**
568
+ * Trim `str`.
569
+ */
570
+
571
+ function trim(str) {
572
+ return str ? str.replace(/^\s+|\s+$/g, '') : '';
573
+ }
574
+
575
+ /**
576
+ * Adds non-enumerable parent node reference to each node.
577
+ */
578
+
579
+ function addParent(obj, parent) {
580
+ var isNode = obj && typeof obj.type === 'string';
581
+ var childParent = isNode ? obj : parent;
582
+
583
+ for (var k in obj) {
584
+ var value = obj[k];
585
+ if (Array.isArray(value)) {
586
+ value.forEach(function (v) { addParent(v, childParent); });
587
+ } else if (value && typeof value === 'object') {
588
+ addParent(value, childParent);
589
+ }
590
+ }
591
+
592
+ if (isNode) {
593
+ Object.defineProperty(obj, 'parent', {
594
+ configurable: true,
595
+ writable: true,
596
+ enumerable: false,
597
+ value: parent || null
598
+ });
599
+ }
600
+
601
+ return obj;
602
+ }
603
+
604
+
605
+
606
+
607
+
608
+ /*COMPRESSS*/
609
+
610
+ class Compress {
611
+ options = {};
612
+ indentation = null;
613
+ constructor(options) {
614
+ this.options = options ?? {};
615
+ this.indentation = options?.indent ?? null;
616
+ }
617
+ }
618
+
619
+ Compress.prototype.emit = function (str) {
620
+ return str;
621
+ };
622
+
623
+ /**
624
+ * Visit `node`.
625
+ */
626
+
627
+ Compress.prototype.visit = function (node) {
628
+ return this[node.type](node);
629
+ };
630
+
631
+ /**
632
+ * Map visit over array of `nodes`, optionally using a `delim`
633
+ */
634
+
635
+ Compress.prototype.mapVisit = function (nodes, delim) {
636
+ var buf = '';
637
+ delim = delim || '';
638
+
639
+ for (var i = 0, length = nodes.length; i < length; i++) {
640
+ buf += this.visit(nodes[i]);
641
+ if (delim && i < length - 1) buf += this.emit(delim);
642
+ }
643
+
644
+ return buf;
645
+ };
646
+
647
+
648
+ Compress.prototype.compile = function (node) {
649
+ return node.stylesheet
650
+ .rules.map(this.visit, this)
651
+ .join('');
652
+ };
653
+
654
+ /**
655
+ * Visit comment node.
656
+ */
657
+
658
+ Compress.prototype.comment = function (node) {
659
+ return this.emit('', node.position);
660
+ };
661
+
662
+ /**
663
+ * Visit import node.
664
+ */
665
+
666
+ Compress.prototype.import = function (node) {
667
+ return this.emit('@import ' + node.import + ';', node.position);
668
+ };
669
+
670
+ /**
671
+ * Visit media node.
672
+ */
673
+
674
+ Compress.prototype.media = function (node) {
675
+ return this.emit('@media ' + node.media, node.position)
676
+ + this.emit('{')
677
+ + this.mapVisit(node.rules)
678
+ + this.emit('}');
679
+ };
680
+
681
+ /**
682
+ * Visit document node.
683
+ */
684
+
685
+ Compress.prototype.document = function (node) {
686
+ var doc = '@' + (node.vendor || '') + 'document ' + node.document;
687
+
688
+ return this.emit(doc, node.position)
689
+ + this.emit('{')
690
+ + this.mapVisit(node.rules)
691
+ + this.emit('}');
692
+ };
693
+
694
+ /**
695
+ * Visit charset node.
696
+ */
697
+
698
+ Compress.prototype.charset = function (node) {
699
+ return this.emit('@charset ' + node.charset + ';', node.position);
700
+ };
701
+
702
+ /**
703
+ * Visit namespace node.
704
+ */
705
+
706
+ Compress.prototype.namespace = function (node) {
707
+ return this.emit('@namespace ' + node.namespace + ';', node.position);
708
+ };
709
+
710
+ /**
711
+ * Visit supports node.
712
+ */
713
+
714
+ Compress.prototype.supports = function (node) {
715
+ return this.emit('@supports ' + node.supports, node.position)
716
+ + this.emit('{')
717
+ + this.mapVisit(node.rules)
718
+ + this.emit('}');
719
+ };
720
+
721
+ /**
722
+ * Visit keyframes node.
723
+ */
724
+
725
+ Compress.prototype.keyframes = function (node) {
726
+ return this.emit('@'
727
+ + (node.vendor || '')
728
+ + 'keyframes '
729
+ + node.name, node.position)
730
+ + this.emit('{')
731
+ + this.mapVisit(node.keyframes)
732
+ + this.emit('}');
733
+ };
734
+
735
+ /**
736
+ * Visit keyframe node.
737
+ */
738
+
739
+ Compress.prototype.keyframe = function (node) {
740
+ var decls = node.declarations;
741
+
742
+ return this.emit(node.values.join(','), node.position)
743
+ + this.emit('{')
744
+ + this.mapVisit(decls)
745
+ + this.emit('}');
746
+ };
747
+
748
+ /**
749
+ * Visit page node.
750
+ */
751
+
752
+ Compress.prototype.page = function (node) {
753
+ var sel = node.selectors.length
754
+ ? node.selectors.join(', ')
755
+ : '';
756
+
757
+ return this.emit('@page ' + sel, node.position)
758
+ + this.emit('{')
759
+ + this.mapVisit(node.declarations)
760
+ + this.emit('}');
761
+ };
762
+
763
+ /**
764
+ * Visit font-face node.
765
+ */
766
+
767
+ Compress.prototype['font-face'] = function (node) {
768
+ return this.emit('@font-face', node.position)
769
+ + this.emit('{')
770
+ + this.mapVisit(node.declarations)
771
+ + this.emit('}');
772
+ };
773
+
774
+ /**
775
+ * Visit host node.
776
+ */
777
+
778
+ Compress.prototype.host = function (node) {
779
+ return this.emit('@host', node.position)
780
+ + this.emit('{')
781
+ + this.mapVisit(node.rules)
782
+ + this.emit('}');
783
+ };
784
+
785
+ /**
786
+ * Visit custom-media node.
787
+ */
788
+
789
+ Compress.prototype['custom-media'] = function (node) {
790
+ return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position);
791
+ };
792
+
793
+ /**
794
+ * Visit rule node.
795
+ */
796
+
797
+ Compress.prototype.rule = function (node) {
798
+ var decls = node.declarations;
799
+ if (!decls.length) return '';
800
+
801
+ return this.emit(node.selectors.join(','), node.position)
802
+ + this.emit('{')
803
+ + this.mapVisit(decls)
804
+ + this.emit('}');
805
+ };
806
+
807
+ /**
808
+ * Visit declaration node.
809
+ */
810
+
811
+ Compress.prototype.declaration = function (node) {
812
+ return this.emit(node.property + ':' + node.value, node.position) + this.emit(';');
813
+ };
814
+
815
+
816
+ /*END COMPRESSS*/
817
+
818
+
819
+
820
+
821
+
822
+
823
+
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+
832
+
833
+
834
+
835
+ /*IDENTITY*/
836
+
837
+ class Identity {
838
+ options = {};
839
+ indentation = null;
840
+ constructor(options) {
841
+ this.options = options ?? {};
842
+ this.indentation = options?.indent ?? null;
843
+ }
844
+ }
845
+
846
+ Identity.prototype.emit = function (str) {
847
+ return str;
848
+ };
849
+
850
+ /**
851
+ * Visit `node`.
852
+ */
853
+
854
+ Identity.prototype.visit = function (node) {
855
+ return this[node.type](node);
856
+ };
857
+
858
+ /**
859
+ * Map visit over array of `nodes`, optionally using a `delim`
860
+ */
861
+
862
+ Identity.prototype.mapVisit = function (nodes, delim) {
863
+ var buf = '';
864
+ delim = delim || '';
865
+
866
+ for (var i = 0, length = nodes.length; i < length; i++) {
867
+ buf += this.visit(nodes[i]);
868
+ if (delim && i < length - 1) buf += this.emit(delim);
869
+ }
870
+
871
+ return buf;
872
+ };
873
+
874
+
875
+
876
+
877
+ Identity.prototype.compile = function (node) {
878
+ return this.stylesheet(node);
879
+ };
880
+
881
+ /**
882
+ * Visit stylesheet node.
883
+ */
884
+
885
+ Identity.prototype.stylesheet = function (node) {
886
+ return this.mapVisit(node.stylesheet.rules, '\n\n');
887
+ };
888
+
889
+ /**
890
+ * Visit comment node.
891
+ */
892
+
893
+ Identity.prototype.comment = function (node) {
894
+ return this.emit(this.indent() + '/*' + node.comment + '*/', node.position);
895
+ };
896
+
897
+ /**
898
+ * Visit import node.
899
+ */
900
+
901
+ Identity.prototype.import = function (node) {
902
+ return this.emit('@import ' + node.import + ';', node.position);
903
+ };
904
+
905
+ /**
906
+ * Visit media node.
907
+ */
908
+
909
+ Identity.prototype.media = function (node) {
910
+ return this.emit('@media ' + node.media, node.position)
911
+ + this.emit(
912
+ ' {\n'
913
+ + this.indent(1))
914
+ + this.mapVisit(node.rules, '\n\n')
915
+ + this.emit(
916
+ this.indent(-1)
917
+ + '\n}');
918
+ };
919
+
920
+ /**
921
+ * Visit document node.
922
+ */
923
+
924
+ Identity.prototype.document = function (node) {
925
+ var doc = '@' + (node.vendor || '') + 'document ' + node.document;
926
+
927
+ return this.emit(doc, node.position)
928
+ + this.emit(
929
+ ' '
930
+ + ' {\n'
931
+ + this.indent(1))
932
+ + this.mapVisit(node.rules, '\n\n')
933
+ + this.emit(
934
+ this.indent(-1)
935
+ + '\n}');
936
+ };
937
+
938
+ /**
939
+ * Visit charset node.
940
+ */
941
+
942
+ Identity.prototype.charset = function (node) {
943
+ return this.emit('@charset ' + node.charset + ';', node.position);
944
+ };
945
+
946
+ /**
947
+ * Visit namespace node.
948
+ */
949
+
950
+ Identity.prototype.namespace = function (node) {
951
+ return this.emit('@namespace ' + node.namespace + ';', node.position);
952
+ };
953
+
954
+ /**
955
+ * Visit supports node.
956
+ */
957
+
958
+ Identity.prototype.supports = function (node) {
959
+ return this.emit('@supports ' + node.supports, node.position)
960
+ + this.emit(
961
+ ' {\n'
962
+ + this.indent(1))
963
+ + this.mapVisit(node.rules, '\n\n')
964
+ + this.emit(
965
+ this.indent(-1)
966
+ + '\n}');
967
+ };
968
+
969
+ /**
970
+ * Visit keyframes node.
971
+ */
972
+
973
+ Identity.prototype.keyframes = function (node) {
974
+ return this.emit('@' + (node.vendor || '') + 'keyframes ' + node.name, node.position)
975
+ + this.emit(
976
+ ' {\n'
977
+ + this.indent(1))
978
+ + this.mapVisit(node.keyframes, '\n')
979
+ + this.emit(
980
+ this.indent(-1)
981
+ + '}');
982
+ };
983
+
984
+ /**
985
+ * Visit keyframe node.
986
+ */
987
+
988
+ Identity.prototype.keyframe = function (node) {
989
+ var decls = node.declarations;
990
+
991
+ return this.emit(this.indent())
992
+ + this.emit(node.values.join(', '), node.position)
993
+ + this.emit(
994
+ ' {\n'
995
+ + this.indent(1))
996
+ + this.mapVisit(decls, '\n')
997
+ + this.emit(
998
+ this.indent(-1)
999
+ + '\n'
1000
+ + this.indent() + '}\n');
1001
+ };
1002
+
1003
+ /**
1004
+ * Visit page node.
1005
+ */
1006
+
1007
+ Identity.prototype.page = function (node) {
1008
+ var sel = node.selectors.length
1009
+ ? node.selectors.join(', ') + ' '
1010
+ : '';
1011
+
1012
+ return this.emit('@page ' + sel, node.position)
1013
+ + this.emit('{\n')
1014
+ + this.emit(this.indent(1))
1015
+ + this.mapVisit(node.declarations, '\n')
1016
+ + this.emit(this.indent(-1))
1017
+ + this.emit('\n}');
1018
+ };
1019
+
1020
+ /**
1021
+ * Visit font-face node.
1022
+ */
1023
+
1024
+ Identity.prototype['font-face'] = function (node) {
1025
+ return this.emit('@font-face ', node.position)
1026
+ + this.emit('{\n')
1027
+ + this.emit(this.indent(1))
1028
+ + this.mapVisit(node.declarations, '\n')
1029
+ + this.emit(this.indent(-1))
1030
+ + this.emit('\n}');
1031
+ };
1032
+
1033
+ /**
1034
+ * Visit host node.
1035
+ */
1036
+
1037
+ Identity.prototype.host = function (node) {
1038
+ return this.emit('@host', node.position)
1039
+ + this.emit(
1040
+ ' {\n'
1041
+ + this.indent(1))
1042
+ + this.mapVisit(node.rules, '\n\n')
1043
+ + this.emit(
1044
+ this.indent(-1)
1045
+ + '\n}');
1046
+ };
1047
+
1048
+ /**
1049
+ * Visit custom-media node.
1050
+ */
1051
+
1052
+ Identity.prototype['custom-media'] = function (node) {
1053
+ return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position);
1054
+ };
1055
+
1056
+ /**
1057
+ * Visit rule node.
1058
+ */
1059
+
1060
+ Identity.prototype.rule = function (node) {
1061
+ var indent = this.indent();
1062
+ var decls = node.declarations;
1063
+ if (!decls.length) return '';
1064
+
1065
+ return this.emit(node.selectors.map(function (s) { return indent + s }).join(',\n'), node.position)
1066
+ + this.emit(' {\n')
1067
+ + this.emit(this.indent(1))
1068
+ + this.mapVisit(decls, '\n')
1069
+ + this.emit(this.indent(-1))
1070
+ + this.emit('\n' + this.indent() + '}');
1071
+ };
1072
+
1073
+ /**
1074
+ * Visit declaration node.
1075
+ */
1076
+
1077
+ Identity.prototype.declaration = function (node) {
1078
+ return this.emit(this.indent())
1079
+ + this.emit(node.property + ': ' + node.value, node.position)
1080
+ + this.emit(';');
1081
+ };
1082
+
1083
+ /**
1084
+ * Increase, decrease or return current indentation.
1085
+ */
1086
+
1087
+ Identity.prototype.indent = function (level) {
1088
+ this.level = this.level || 1;
1089
+
1090
+ if (null != level) {
1091
+ this.level += level;
1092
+ return '';
1093
+ }
1094
+
1095
+ return Array(this.level).join(this.indentation || ' ');
1096
+ };
1097
+
1098
+ /*END IDENTITY*/
1099
+
1100
+
1101
+
1102
+
1103
+ function stringifyMe(node, options) {
1104
+ options = options || {};
1105
+
1106
+ var compiler = options.compress
1107
+ ? new Compress(options)
1108
+ : new Identity(options);
1109
+
1110
+ // source maps
1111
+ if (options.sourcemap) {
1112
+ var sourcemaps = require('./source-map-support');
1113
+ sourcemaps(compiler);
1114
+
1115
+ var code = compiler.compile(node);
1116
+ compiler.applySourceMaps();
1117
+
1118
+ var map = options.sourcemap === 'generator'
1119
+ ? compiler.map
1120
+ : compiler.map.toJSON();
1121
+
1122
+ return { code: code, map: map };
1123
+ }
1124
+
1125
+ var code = compiler.compile(node);
1126
+ return code;
1127
+ };
1128
+
1129
+
1130
+ // $('style[scoped]').each(function () {
1131
+ // var ojj = parseMe($(this).text());
1132
+
1133
+ // let pre = ".kiki";
1134
+ // for (let x = 0; x < ojj?.stylesheet?.rules?.length; x++) {
1135
+ // for (let y = 0; y < ojj?.stylesheet?.rules[x].selectors.length; y++) {
1136
+ // ojj.stylesheet.rules[x].selectors[y] = pre + " " + ojj?.stylesheet?.rules[x].selectors[y];
1137
+ // }
1138
+ // }
1139
+ // var okkN = stringifyMe(ojj, { compress: false });
1140
+ // var okk = stringifyMe(ojj, { compress: true });
1141
+ // $(this).text(okk);
1142
+ // cl([ojj, okkN, okk]);
1143
+ // });
1144
+
1145
+
1146
+ (function () {
1147
+ 'use strict';
1148
+ _w.on('css-ready', function (e) {
1149
+ var csses = e.data.csses;
1150
+ var key = e.data.key;
1151
+ var pre = e.data.pre;
1152
+
1153
+ for (let index = 0; index < csses.length; index++) {
1154
+ var css = csses[index];
1155
+
1156
+ var ojj = parseMe(css, { silent: true });
1157
+ for (let x = 0; x < ojj?.stylesheet?.rules?.length; x++) {
1158
+ for (let y = 0; y < ojj?.stylesheet?.rules[x].selectors.length; y++) {
1159
+ if (ojj?.stylesheet?.rules[x].selectors[y] == "*") ojj.stylesheet.rules[x].selectors[y] = pre + ", " + pre + " " + ojj?.stylesheet?.rules[x].selectors[y];
1160
+ else ojj.stylesheet.rules[x].selectors[y] = pre + " " + ojj?.stylesheet?.rules[x].selectors[y];
1161
+ }
1162
+ }
1163
+ var okk = stringifyMe(ojj, { compress: true });
1164
+ csses[index] = okk;
1165
+ }
1166
+
1167
+ _w.trigger('css-ready', {
1168
+ "csses": csses,
1169
+ key: key
1170
+ });
1171
+ });
1172
+ return;
1173
+ })();