1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var contexts_1 = tslib_1.__importDefault(require("./contexts"));
|
5 | var visitors_1 = tslib_1.__importDefault(require("./visitors"));
|
6 | var tree_1 = tslib_1.__importDefault(require("./tree"));
|
7 | function default_1(root, options) {
|
8 | options = options || {};
|
9 | var evaldRoot;
|
10 | var variables = options.variables;
|
11 | var evalEnv = new contexts_1.default.Eval(options);
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | if (typeof variables === 'object' && !Array.isArray(variables)) {
|
26 | variables = Object.keys(variables).map(function (k) {
|
27 | var value = variables[k];
|
28 | if (!(value instanceof tree_1.default.Value)) {
|
29 | if (!(value instanceof tree_1.default.Expression)) {
|
30 | value = new tree_1.default.Expression([value]);
|
31 | }
|
32 | value = new tree_1.default.Value([value]);
|
33 | }
|
34 | return new tree_1.default.Declaration("@" + k, value, false, null, 0);
|
35 | });
|
36 | evalEnv.frames = [new tree_1.default.Ruleset(null, variables)];
|
37 | }
|
38 | var visitors = [
|
39 | new visitors_1.default.JoinSelectorVisitor(),
|
40 | new visitors_1.default.MarkVisibleSelectorsVisitor(true),
|
41 | new visitors_1.default.ExtendVisitor(),
|
42 | new visitors_1.default.ToCSSVisitor({ compress: Boolean(options.compress) })
|
43 | ];
|
44 | var preEvalVisitors = [];
|
45 | var v;
|
46 | var visitorIterator;
|
47 | |
48 |
|
49 |
|
50 |
|
51 |
|
52 | if (options.pluginManager) {
|
53 | visitorIterator = options.pluginManager.visitor();
|
54 | for (var i = 0; i < 2; i++) {
|
55 | visitorIterator.first();
|
56 | while ((v = visitorIterator.get())) {
|
57 | if (v.isPreEvalVisitor) {
|
58 | if (i === 0 || preEvalVisitors.indexOf(v) === -1) {
|
59 | preEvalVisitors.push(v);
|
60 | v.run(root);
|
61 | }
|
62 | }
|
63 | else {
|
64 | if (i === 0 || visitors.indexOf(v) === -1) {
|
65 | if (v.isPreVisitor) {
|
66 | visitors.unshift(v);
|
67 | }
|
68 | else {
|
69 | visitors.push(v);
|
70 | }
|
71 | }
|
72 | }
|
73 | }
|
74 | }
|
75 | }
|
76 | evaldRoot = root.eval(evalEnv);
|
77 | for (var i = 0; i < visitors.length; i++) {
|
78 | visitors[i].run(evaldRoot);
|
79 | }
|
80 |
|
81 | if (options.pluginManager) {
|
82 | visitorIterator.first();
|
83 | while ((v = visitorIterator.get())) {
|
84 | if (visitors.indexOf(v) === -1 && preEvalVisitors.indexOf(v) === -1) {
|
85 | v.run(evaldRoot);
|
86 | }
|
87 | }
|
88 | }
|
89 | return evaldRoot;
|
90 | }
|
91 | exports.default = default_1;
|
92 | ;
|
93 |
|
\ | No newline at end of file |