Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'stylis' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
// @flow
import Stylis from 'stylis'
import type { Interpolation } from '../types'
const stylis = new Stylis({
global: false,
cascade: true,
keyframe: false,
prefix: true,
compress: false,
semicolon: true,
})
const stringifyRules = (
rules: Array,
selector: ?string,
prefix: ?string,
): string => {
const flatCSS = rules
.join('')
.replace(/^\s*\/\/.*$/gm, '') // replace JS comments
return match;
});
return existingComponents.map(function (_ref, i) {
var componentId = _ref.componentId,
matchIndex = _ref.matchIndex;
var nextComp = existingComponents[i + 1];
var cssFromDOM = nextComp ? css.slice(matchIndex, nextComp.matchIndex) : css.slice(matchIndex);
return { componentId: componentId, cssFromDOM: cssFromDOM };
});
});
//
// NOTE: This stylis instance is only used to split rules from SSR'd style tags
var stylisSplitter = new Stylis({
global: false,
cascade: true,
keyframe: false,
prefix: false,
compress: false,
semicolon: true
});
var stylis = new Stylis({
global: false,
cascade: true,
keyframe: false,
prefix: true,
compress: false,
semicolon: false // NOTE: This means "autocomplete missing semicolons"
});
let insertRules = realCSS => {
let style = getStyleElement()
/* Get unique classname */
let className = getHash(realCSS)
/* Convert nested CSS */
let styles = stylis(`.${className}`, realCSS)
style.innerHTML += styles
return className
}
//
var COMMENT_REGEX = /^\s*\/\/.*$/gm;
// NOTE: This stylis instance is only used to split rules from SSR'd style tags
var stylisSplitter = new Stylis({
global: false,
cascade: true,
keyframe: false,
prefix: false,
compress: false,
semicolon: true
});
var stylis = new Stylis({
global: false,
cascade: true,
keyframe: false,
prefix: true,
compress: false,
semicolon: false // NOTE: This means "autocomplete missing semicolons"
});
// Wrap `insertRulePlugin to build a list of rules,
// and then make our own plugin to return the rules. This
// makes it easier to hook into the existing SSR architecture
var parsingRules = [];
// eslint-disable-next-line consistent-return
var returnRulesPlugin = function returnRulesPlugin(context) {
if (context === -2) {
/* Handle objects */
ruleSet.push(
// $FlowFixMe have to add %checks somehow to isPlainObject
isPlainObject(chunk) ? objToCss(chunk) : chunk.toString());
return ruleSet;
}, []);
};
//
var COMMENT_REGEX = /^\s*\/\/.*$/gm;
// NOTE: This stylis instance is only used to split rules from SSR'd style tags
var stylisSplitter = new Stylis({
global: false,
cascade: true,
keyframe: false,
prefix: false,
compress: false,
semicolon: true
});
var stylis = new Stylis({
global: false,
cascade: true,
keyframe: false,
prefix: true,
compress: false,
semicolon: false // NOTE: This means "autocomplete missing semicolons"
});
/* Handle objects */
ruleSet.push(
// $FlowFixMe have to add %checks somehow to isPlainObject
isPlainObject(chunk) ? objToCss(chunk) : chunk.toString());
return ruleSet;
}, []);
};
//
var COMMENT_REGEX = /^\s*\/\/.*$/gm;
// NOTE: This stylis instance is only used to split rules from SSR'd style tags
var stylisSplitter = new Stylis({
global: false,
cascade: true,
keyframe: false,
prefix: false,
compress: false,
semicolon: true
});
var stylis = new Stylis({
global: false,
cascade: true,
keyframe: false,
prefix: true,
compress: false,
semicolon: false // NOTE: This means "autocomplete missing semicolons"
});
generateAndInjectStyles (executionContext) {
const flatCSS = flatten(this.rules, executionContext).join('')
.replace(/^\s*\/\/.*$/gm, '') // replace JS comments
const hash = hashStr(flatCSS)
if (!inserted[hash]) {
const selector = nameGenerator(hash)
inserted[hash] = selector
const css = stylis(`.${selector}`, flatCSS)
this.insertedRule.appendRule(css)
}
return inserted[hash]
}
}
function insertStyles(styles) {
const className = getClassName(styles)
// skip if these styles are already inserted
if (isAlreadyInserted(className)) return className
insertedClasses.push(className)
const container = document.head.querySelector('#usecss')
const raw = stylis(`.` + className, styles)
container.append(raw)
return className
}
let cssText = '';
let preprocessor;
if (typeof options.preprocessor === 'function') {
// eslint-disable-next-line prefer-destructuring
preprocessor = options.preprocessor;
} else {
switch (options.preprocessor) {
case 'none':
preprocessor = (selector, text) => `${selector} {${text}}\n`;
break;
case 'stylis':
default:
stylis.use(null)((context, decl) => {
if (context === STYLIS_DECLARATION && options.outputFilename) {
// When writing to a file, we need to adjust the relative paths inside url(..) expressions
// It'll allow css-loader to resolve an imported asset properly
return decl.replace(
/\b(url\()(\.[^)]+)(\))/g,
(match, p1, p2, p3) =>
p1 +
// Replace asset path with new path relative to the output CSS
path.relative(
/* $FlowFixMe */
path.dirname(options.outputFilename),
// Get the absolute path to the asset from the path relative to the JS file
path.resolve(path.dirname(options.filename), p2)
) +
p3
);
//
var COMMENT_REGEX = /^\s*\/\/.*$/gm;
// NOTE: This stylis instance is only used to split rules from SSR'd style tags
var stylisSplitter = new Stylis({
global: false,
cascade: true,
keyframe: false,
prefix: false,
compress: false,
semicolon: true,
});
var stylis = new Stylis({
global: false,
cascade: true,
keyframe: false,
prefix: true,
compress: false,
semicolon: false, // NOTE: This means "autocomplete missing semicolons"
});
// Wrap `insertRulePlugin to build a list of rules,
// and then make our own plugin to return the rules. This
// makes it easier to hook into the existing SSR architecture
var parsingRules = [];
// eslint-disable-next-line consistent-return
var returnRulesPlugin = function returnRulesPlugin(context) {