How to use the css-tree.generate 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 GNS3 / gns3-web-ui / src / app / cartography / helpers / css-fixer.ts View on Github external
});

    // fixes font-size when unit (pt|px) is not defined
    ast.children.forEach(child => {
      if (child.property === 'font-size') {
        child.value.children.forEach(value => {
          if (value.type === 'Number') {
            const fontSize = value.value.toString();
            if (!(fontSize.indexOf('pt') >= 0 || fontSize.indexOf('px') >= 0)) {
              value.value = `${fontSize}pt`;
            }
          }
        });
      }
    });
    return csstree.generate(ast);
  }
}
github endorphinjs / endorphin / packages / css-module / index.js View on Github external
// Use second pass to replace locally defined animations with scoped names
    walk(ast, {
        visit: 'Declaration',
        enter(node) {
            if (cssName(node.property) === 'animation' || cssName(node.property) === 'animation-name') {
                walk(node.value, value => {
                    if (value.type === 'Identifier' && value.name in animations) {
                        value.name = animations[value.name];
                    }
                });
            }
        }
    });

    return generate(ast, options);
};
github pocketjoso / penthouse / src / postformatting / unused-fontface-remover.js View on Github external
function decodeFontName (node) {
  let name = csstree.generate(node)
  // TODO: use string decode
  if (name[0] === '"' || name[0] === "'") {
    name = name.substr(1, name.length - 2)
  }
  return name
}
github react-native-community / react-native-svg / src / css.tsx View on Github external
return selectors.filter(({ atrule }) => {
    if (atrule === null) {
      return true;
    }
    const { name, prelude } = atrule;
    const atPrelude = prelude as AtrulePrelude;
    const first = atPrelude && atPrelude.children.first();
    const mq = first && first.type === 'MediaQueryList';
    const query = mq ? csstree.generate(atPrelude) : name;
    return useMqs.includes(query);
  });
}
github marktext / marktext / src / muya / lib / utils / exportStyledHTML.js View on Github external
const cleanedStyles = styleSheets.map(ast => {
      const cleanedAST = fromPlainObject(cleaner(ast, checker))
      return generate(cleanedAST)
    })
    const finalCSS = collectImportantComments(cleanedStyles.join('\n'))
github wane / wane / src / compiler / style-parser / css.ts View on Github external
list.insertData(dataToInsert, item)
              } else if (item.next == null) {
                list.appendData(dataToInsert)
              } else {
                list.insertData(dataToInsert, item.next)
              }
              isChunkDone = true
              return
            }
          })
        }
      })
    },
  })

  const output = csstree.generate(ast)
  return output
}
github peterbe / minimalcss / src / run.js View on Github external
.forEach(entry => {
            const name = utils.unquoteString(
              csstree.generate({
                type: 'Value',
                children: entry.nodes
              })
            );
            activeFontFamilyNames.add(name);
          });
      }
github Cherrison / CrackMinApp / nodejs / nodejs / wuWxss.js View on Github external
}
							list[son.property]=ans;
						}else list[son.property]=item;
					}
				});
				for(let name in list)if(!name.startsWith('-'))
					for(let type of removeType){
						let fullName=`-${type}-${name}`;
						if(list[fullName]){
							node.children.remove(list[fullName]);
							delete list[fullName];
						}
					}
			}
		});
		return cssbeautify(csstree.generate(ast),{indent:'    ',autosemicolon:true});
	}
	wu.scanDirByExt(dir,".html",files=>{
github svg / svgo / lib / css-tools.js View on Github external
return selectors.filter(function(selector) {
        if (selector.atrule === null) {
            return ~useMqs.indexOf('');
        }

        var mqName = selector.atrule.name;
        var mqStr = mqName;
        if (selector.atrule.expression &&
            selector.atrule.expression.children.first().type === 'MediaQueryList') {
            var mqExpr = csstree.generate(selector.atrule.expression);
            mqStr = [mqName, mqExpr].join(' ');
        }

        return ~useMqs.indexOf(mqStr);
    });
}
github react-native-community / react-native-svg / src / css.tsx View on Github external
return selectors.filter(({ pseudos }) =>
    usePseudos.includes(
      csstree.generate({
        type: 'Selector',
        children: new List().fromArray(
          pseudos.map(pseudo => pseudo.item.data),
        ),
      }),
    ),
  );