How to use the css-tree.clone function in css-tree

To help you get started, we’ve selected a few css-tree examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github css / csso / lib / compress.js View on Github external
var compressOptions = {
        logger: typeof options.logger === 'function' ? options.logger : function() {},
        restructuring: getRestructureOption(options),
        forceMediaMerge: Boolean(options.forceMediaMerge),
        usage: options.usage ? usageUtils.buildIndex(options.usage) : false
    };
    var specialComments = getCommentsOption(options);
    var firstAtrulesAllowed = true;
    var input;
    var output = new List();
    var chunk;
    var chunkNum = 1;
    var chunkChildren;

    if (options.clone) {
        ast = clone(ast);
    }

    if (ast.type === 'StyleSheet') {
        input = ast.children;
        ast.children = output;
    } else {
        input = wrapBlock(ast);
    }

    do {
        chunk = readChunk(input, Boolean(specialComments));
        compressChunk(chunk.stylesheet, firstAtrulesAllowed, chunkNum++, compressOptions);
        chunkChildren = chunk.stylesheet.children;

        if (chunk.comment) {
            // add \n before comment if there is another content in output
github yarnaimo / vanilla-clipper / src / utils / css.ts View on Github external
csstree.walk(ast, (node, item, list) => {
        if (document && node.type === 'Rule' && node.prelude.type === 'SelectorList') {
            const includesURL = (node.block.children.some(node => {
                if (node.type !== 'Declaration' || node.value.type === 'Raw') {
                    return false
                }
                return (node.value.children.some(node => node.type === 'Url') as any) as boolean
            }) as any) as boolean

            if (!includesURL) {
                return
            }

            try {
                const prelude = csstree.clone(node.prelude) as csstree.SelectorList
                processSelectorList(prelude)

                if (!prelude.children.getSize()) {
                    return
                }

                const selector = csstree.generate(prelude)
                const element = document.querySelector(selector)

                if (!element) {
                    list.remove(item)
                }
            } catch (error) {}
        }
    })