Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (c) 2018 SQUARESPACE, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squarespace.less.jsonast;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import com.squarespace.less.core.FlexList;
import com.squarespace.less.core.Pair;
import com.squarespace.less.model.Alpha;
import com.squarespace.less.model.Anonymous;
import com.squarespace.less.model.Argument;
import com.squarespace.less.model.Assignment;
import com.squarespace.less.model.AttributeElement;
import com.squarespace.less.model.BaseColor;
import com.squarespace.less.model.Block;
import com.squarespace.less.model.BlockDirective;
import com.squarespace.less.model.BlockNode;
import com.squarespace.less.model.Combinator;
import com.squarespace.less.model.Comment;
import com.squarespace.less.model.Condition;
import com.squarespace.less.model.Definition;
import com.squarespace.less.model.Dimension;
import com.squarespace.less.model.Directive;
import com.squarespace.less.model.Element;
import com.squarespace.less.model.Expression;
import com.squarespace.less.model.ExpressionList;
import com.squarespace.less.model.Feature;
import com.squarespace.less.model.Features;
import com.squarespace.less.model.FunctionCall;
import com.squarespace.less.model.Guard;
import com.squarespace.less.model.Import;
import com.squarespace.less.model.Keyword;
import com.squarespace.less.model.Media;
import com.squarespace.less.model.Mixin;
import com.squarespace.less.model.MixinCall;
import com.squarespace.less.model.MixinCallArgs;
import com.squarespace.less.model.MixinParams;
import com.squarespace.less.model.Node;
import com.squarespace.less.model.NodeType;
import com.squarespace.less.model.Operation;
import com.squarespace.less.model.Parameter;
import com.squarespace.less.model.Paren;
import com.squarespace.less.model.Property;
import com.squarespace.less.model.Quoted;
import com.squarespace.less.model.RGBColor;
import com.squarespace.less.model.Ratio;
import com.squarespace.less.model.Rule;
import com.squarespace.less.model.Ruleset;
import com.squarespace.less.model.Selector;
import com.squarespace.less.model.Selectors;
import com.squarespace.less.model.Shorthand;
import com.squarespace.less.model.StructuralNode;
import com.squarespace.less.model.Stylesheet;
import com.squarespace.less.model.TextElement;
import com.squarespace.less.model.TransparentColor;
import com.squarespace.less.model.UnicodeRange;
import com.squarespace.less.model.Unit;
import com.squarespace.less.model.Url;
import com.squarespace.less.model.ValueElement;
import com.squarespace.less.model.Variable;
public class AstEmitter {
public static final int NULL = -1;
public static final int ALPHA = 0;
public static final int ANONYMOUS = 1;
public static final int ARGUMENT = 2;
public static final int ASSIGNMENT = 3;
public static final int ATTR_ELEMENT = 4;
public static final int BLOCK_DIRECTIVE = 5;
public static final int COLOR = 6;
public static final int COMMENT = 7;
public static final int CONDITION = 8;
public static final int DEFINITION = 9;
public static final int DIMENSION = 10;
public static final int DIRECTIVE = 11;
public static final int EXPRESSION = 12;
public static final int EXPRESSION_LIST = 13;
public static final int FALSE = 14;
public static final int FEATURE = 15;
public static final int FEATURES = 16;
public static final int FUNCTION_CALL = 17;
public static final int GUARD = 18;
public static final int IMPORT = 19;
public static final int KEYWORD = 20;
public static final int MEDIA = 21;
public static final int MIXIN = 22;
public static final int MIXIN_ARGS = 23;
public static final int MIXIN_CALL = 24;
public static final int MIXIN_PARAMS = 25;
public static final int OPERATION = 26;
public static final int PARAMETER = 27;
public static final int PAREN = 28;
public static final int PROPERTY = 29;
public static final int QUOTED = 30;
public static final int RATIO = 31;
public static final int RULE = 32;
public static final int RULESET = 33;
public static final int SELECTOR = 34;
public static final int SELECTORS = 35;
public static final int SHORTHAND = 36;
public static final int STYLESHEET = 37;
public static final int TEXT_ELEMENT = 38;
public static final int TRUE = 39;
public static final int UNICODE_RANGE = 40;
public static final int URL = 41;
public static final int VALUE_ELEMENT = 42;
public static final int VARIABLE = 43;
private static final int VERSION = 1;
/** Root node we're converting to JSON AST (typically a STYLESHEET node). */
private final Node root;
/** Current buffer we're emitting to */
private AstBuffer buf;
private AstEmitter(Node root) {
this.root = root;
}
public static String render(Node root) {
return render(root, false);
}
public static String render(Node root, boolean savePositions) {
return new AstEmitter(root).process(savePositions);
}
private String process(boolean savePositions) {
// Pass 1: escape and index all strings
AstOptimizer optimizer = new AstOptimizer();
buf = optimizer;
emit(root);
Pair