Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function toJSS(css, ...values) {
const stylesheetString = Array.isArray(css) ? handleTags(css, ...values) : css;
const { stylesheet } = ParseCSS(utils.clean(stylesheetString));
const directions = ['top', 'right', 'bottom', 'left'];
const changeArr = ['margin', 'padding', 'border-width', 'border-radius'];
const numberize = ['width', 'height', 'font-size', 'line-height'].concat(directions);
// special properties and shorthands that need to be broken down separately
const specialProperties = {};
['border', 'border-top', 'border-right', 'border-bottom', 'border-left'].forEach((name) => {
specialProperties[name] = {
regex: /^\s*([0-9]+)(px)?\s+(solid|dotted|dashed)?\s*([a-z0-9#,\(\)\.\s]+)\s*$/i,
map: {
1: `${name}-width`,
3: name === 'border' ? `${name}-style` : null,
4: `${name}-color`,
},
};
});
this.header = {
disabled: false,
frameId: window.remoteDebugger.frameId,
hasSourceURL: Boolean(styleSheet.href),
isInline: styleSheet.ownerNode.tagName.toLowerCase() === 'style',
origin: 'regular',
ownerNode: styleSheet.ownerNode._nodeId,
sourceURL: styleSheet.href,
startColumn: 0,
startLine: 0,
styleSheetId: this.styleSheetId,
title: ''
}
const cssTextLines = this.cssText.split('\n')
this.rules = parseCss(this.cssText).stylesheet.rules
.filter((rule) => rule.type === 'rule')
.map((rule) => {
const rulePos = rule.position
const start = rule.declarations.length ? first(rule.declarations).position.start : 0
const lines = cssTextLines.slice(rulePos.start.line - 1, rulePos.end.line)
let cssText = ''
if (lines.length === 0) {
cssText = cssTextLines[start.line - 1]
} else {
const linesJoined = lines.join('\n')
cssText = linesJoined.slice(linesJoined.indexOf('{') + 1, linesJoined.indexOf('}'))
}
const cssProperties = StyleSheet.getCssProperties(rule, cssTextLines)
const range = cssProperties.length ? StyleSheet.getRange(
const transform = (css, options) => {
const { stylesheet } = parseCSS(css);
const result = {};
for (const r in stylesheet.rules) {
const rule = stylesheet.rules[r];
for (const s in rule.selectors) {
if (
rule.selectors[s].indexOf(".") !== 0 ||
rule.selectors[s].indexOf(":") !== -1 ||
rule.selectors[s].indexOf("[") !== -1 ||
rule.selectors[s].indexOf("~") !== -1 ||
rule.selectors[s].indexOf(">") !== -1 ||
rule.selectors[s].indexOf("+") !== -1 ||
rule.selectors[s].indexOf(" ") !== -1
) {
continue;
const transform = (css, options) => {
const { stylesheet } = parseCSS(css)
const rules = sortRules(stylesheet.rules)
const result = {}
for (const r in rules) {
const rule = rules[r]
for (const s in rule.selectors) {
if (rule.selectors[s] === ':export') {
if (!result.__exportProps) {
result.__exportProps = {}
}
rule.declarations.forEach(({ property, value }) => {
const isAlreadyDefinedAsClass =
result[property] !== undefined &&
result.__exportProps[property] === undefined