New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

aesthetic

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aesthetic - npm Package Compare versions

Comparing version 5.0.1 to 5.1.0

11

CHANGELOG.md

@@ -0,1 +1,12 @@

## 5.1.0 - 2020-01-26
#### 🚀 Updates
- Migrated to Rollup for a smaller filesize.
#### 📦 Dependencies
- Updated all to latest.
- Fixed `aesthetic` peer dependency pointing to the wrong version.
### 5.0.1 - 2019-12-19

@@ -2,0 +13,0 @@

1108

esm/index.js

@@ -0,1 +1,1095 @@

import deepMerge from 'extend';
import { isRTL, toObjectRecursive, getFlushedStyles, purgeStyles, isObject, toArray, formatFontFace, stripClassPrefix } from 'aesthetic-utils';
import uuid from 'uuid/v4';
import convertRTL from 'rtl-css-js';
import Stylis from 'stylis';
import { convertProperty } from 'rtl-css-js/core';
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var CacheManager = function () {
function CacheManager() {
_defineProperty(this, "cache", new Map());
}
var _proto = CacheManager.prototype;
_proto.clear = function clear(filter) {
var _this = this;
if (filter) {
this.cache.forEach(function (units, key) {
_this.cache.set(key, units.filter(function (unit) {
return !filter(unit);
}));
});
} else {
this.cache.clear();
}
return this;
};
_proto.compare = function compare(unit, tags) {
return unit.dir === tags.dir && unit.global === tags.global && unit.theme === tags.theme;
};
_proto.get = function get(key, tags) {
var _this2 = this;
var units = this.cache.get(key);
if (!units || units.length === 0) {
return null;
}
var cache = units.find(function (unit) {
return _this2.compare(unit, tags);
});
return cache ? cache.value : null;
};
_proto.set = function set(key, value, tags) {
var units = this.cache.get(key) || [];
units.push(_extends({}, tags, {
value: value
}));
this.cache.set(key, units);
return value;
};
return CacheManager;
}();
var Ruleset = function () {
function Ruleset(selector, root, parent) {
if (parent === void 0) {
parent = null;
}
_defineProperty(this, "compoundProperties", new Map());
_defineProperty(this, "nested", new Map());
_defineProperty(this, "parent", null);
_defineProperty(this, "properties", {});
_defineProperty(this, "root", void 0);
_defineProperty(this, "selector", void 0);
this.selector = selector;
this.root = root;
this.parent = parent;
}
var _proto = Ruleset.prototype;
_proto.addCompoundProperty = function addCompoundProperty(key, value) {
this.compoundProperties.set(key, value);
return this;
};
_proto.addNested = function addNested(selector, ruleset, merge) {
if (merge === void 0) {
merge = true;
}
if (merge && this.nested.has(selector)) {
this.nested.get(selector).merge(ruleset);
} else {
this.nested.set(selector, ruleset);
}
return this;
};
_proto.addProperty = function addProperty(key, value) {
this.properties[key] = value;
return this;
};
_proto.addProperties = function addProperties(properties) {
Object.assign(this.properties, properties);
return this;
};
_proto.createRuleset = function createRuleset(selector) {
return new Ruleset(selector, this.root, this);
};
_proto.merge = function merge(ruleset) {
var _this = this;
Object.assign(this.properties, ruleset.properties);
ruleset.nested.forEach(function (nested, selector) {
_this.addNested(selector, nested);
});
return this;
};
_proto.toObject = function toObject() {
var props = isRTL(this.root.options.dir) ? convertRTL(this.properties) : this.properties;
var compounds = {};
this.compoundProperties.forEach(function (compound, key) {
compounds[key] = compound;
});
return _extends({}, props, {}, compounds, {}, toObjectRecursive(this.nested));
};
return Ruleset;
}();
var Sheet = function () {
function Sheet(options) {
if (options === void 0) {
options = {};
}
_defineProperty(this, "atRules", {});
_defineProperty(this, "classNames", {});
_defineProperty(this, "options", void 0);
_defineProperty(this, "ruleSets", {});
this.options = options;
}
var _proto = Sheet.prototype;
_proto.addAtRule = function addAtRule(rule, value) {
this.atRules[rule] = value;
return this;
};
_proto.addClassName = function addClassName(selector, value) {
this.classNames[selector] = value;
return this;
};
_proto.addRuleset = function addRuleset(set) {
this.ruleSets[set.selector] = set;
return this;
};
_proto.createRuleset = function createRuleset(selector) {
return new Ruleset(selector, this);
};
_proto.createSheet = function createSheet(options) {
return new Sheet(options || this.options);
};
_proto.toObject = function toObject() {
var _this = this;
var atRules = {};
var sets = {};
Object.keys(this.atRules).forEach(function (key) {
var value = _this.atRules[key];
if (value instanceof Sheet || value instanceof Ruleset) {
sets[key] = value;
} else if (Array.isArray(value)) {
atRules[key] = value.map(function (item) {
return item instanceof Ruleset ? item.toObject() : item;
});
} else {
atRules[key] = value;
}
});
return _extends({}, atRules, {}, toObjectRecursive(sets), {}, toObjectRecursive(this.ruleSets));
};
return Sheet;
}();
var StyleSheetManager = function () {
function StyleSheetManager() {
_defineProperty(this, "element", null);
_defineProperty(this, "sheet", null);
}
var _proto = StyleSheetManager.prototype;
_proto.getFlushedStyles = function getFlushedStyles$1() {
return getFlushedStyles(this.getStyleElement());
};
_proto.getStyleElement = function getStyleElement() {
if (this.element) {
return this.element;
}
this.element = document.createElement('style');
this.element.type = 'text/css';
this.element.media = 'screen';
this.element.setAttribute('data-aesthetic', 'true');
document.head.append(this.element);
this.sheet = this.element.sheet;
return this.element;
};
_proto.injectRule = function injectRule(rule) {
this.getStyleElement();
this.sheet.insertRule(rule, this.sheet.cssRules.length);
return this;
};
_proto.injectStatements = function injectStatements(css) {
this.getStyleElement().textContent += css;
return this;
};
_proto.purgeStyles = function purgeStyles$1() {
purgeStyles(this.getStyleElement());
return this;
};
return StyleSheetManager;
}();
var SELECTOR = /^((\[[\x2Da-z\u017F\u212A]+\])|(::?[\x2Da-z\u017F\u212A]+))$/i;
var CLASS_NAME = /^[a-z\u017F\u212A]{1}[\x2D0-9_a-z\u017F\u212A]+$/i;
function rtlPlugin(context, content) {
if (context !== 1) {
return undefined;
}
var _content$split = content.split(':', 2),
rawKey = _content$split[0],
rawValue = _content$split[1];
var isQuoted = rawValue.trim().startsWith("'");
var unquotedValue = isQuoted ? rawValue.slice(1).slice(0, -1) : rawValue;
var _convertProperty = convertProperty(rawKey.trim(), unquotedValue.trim()),
key = _convertProperty.key,
value = _convertProperty.value;
return key + ":" + (isQuoted ? "'" + value + "'" : value);
}
var UnifiedSyntax = function () {
function UnifiedSyntax() {
var _this = this;
_defineProperty(this, "handlers", {});
_defineProperty(this, "keyframesCount", 0);
_defineProperty(this, "handleAnimationName", function (ruleset, value) {
if (!value) {
return undefined;
}
return (Array.isArray(value) ? value : [value]).map(function (item) {
if (typeof item === 'string') {
return item;
}
var name = item.name || "keyframe-" + (_this.keyframesCount += 1);
_this.convertKeyframe(name, item, ruleset.root);
return name;
}).join(', ');
});
_defineProperty(this, "handleFontFamily", function (ruleset, value) {
if (!value) {
return undefined;
}
var output = new Set();
var fontFaces = {};
toArray(value).forEach(function (item) {
if (typeof item === 'string') {
output.add(item);
return;
}
var name = item.fontFamily;
if (!name) {
return;
}
output.add(name);
if (fontFaces[name]) {
fontFaces[name].push(item);
} else {
fontFaces[name] = [item];
}
});
Object.keys(fontFaces).forEach(function (fontFamily) {
_this.convertFontFaces(fontFamily, fontFaces[fontFamily], ruleset.root);
});
return Array.from(output).join(', ');
});
this.on('property:animationName', this.handleAnimationName);
this.on('property:fontFamily', this.handleFontFamily);
}
var _proto = UnifiedSyntax.prototype;
_proto.convertGlobalSheet = function convertGlobalSheet(globalSheet, options) {
var _this2 = this;
var sheet = new Sheet(options);
Object.keys(globalSheet).forEach(function (rule) {
switch (rule) {
case '@charset':
{
var _charset = globalSheet[rule];
if (typeof _charset === 'string') {
_this2.emit('charset', [sheet, _charset]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error('@charset must be a string.');
}
break;
}
case '@font-face':
{
var faces = globalSheet[rule] || {};
if ("production" !== process.env.NODE_ENV) {
if (!isObject(faces)) {
throw new Error('@font-face must be an object of font family names to font faces.');
}
}
Object.keys(faces).forEach(function (fontFamily) {
_this2.convertFontFaces(fontFamily, toArray(faces[fontFamily]), sheet);
});
break;
}
case '@global':
{
var globals = globalSheet[rule] || {};
if ("production" !== process.env.NODE_ENV) {
if (!isObject(globals)) {
throw new Error('@global must be an object of selectors to ruleset objects.');
}
}
Object.keys(globals).forEach(function (selector) {
if (isObject(globals[selector])) {
_this2.emit('global', [sheet, selector, _this2.convertRuleset(globals[selector], sheet.createRuleset(selector))]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error("@global \"" + selector + "\" must be a ruleset object.");
}
});
break;
}
case '@import':
{
var _paths = globalSheet[rule];
if (typeof _paths === 'string' || Array.isArray(_paths)) {
_this2.emit('import', [sheet, toArray(_paths).map(function (path) {
return String(path);
})]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error('@import must be a string or an array of strings.');
}
break;
}
case '@keyframes':
{
var frames = globalSheet[rule] || {};
if ("production" !== process.env.NODE_ENV) {
if (!isObject(frames)) {
throw new Error('@keyframes must be an object of animation names to keyframes.');
}
}
Object.keys(frames).forEach(function (animationName) {
_this2.convertKeyframe(animationName, frames[animationName], sheet);
});
break;
}
case '@page':
case '@viewport':
{
var style = globalSheet[rule];
if (isObject(style)) {
_this2.emit(rule.slice(1), [sheet, _this2.convertRuleset(style, sheet.createRuleset(rule))]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error(rule + " must be a ruleset object.");
}
break;
}
default:
{
if ("production" !== process.env.NODE_ENV) {
throw new Error("Unknown property \"" + rule + "\". Only at-rules are allowed in the global style sheet.");
}
}
}
});
return sheet;
};
_proto.convertStyleSheet = function convertStyleSheet(styleSheet, options) {
var _this3 = this;
var sheet = new Sheet(options);
Object.keys(styleSheet).forEach(function (selector) {
var ruleset = styleSheet[selector];
if (!ruleset) {
return;
}
if (selector.charAt(0) === '@') {
if ("production" !== process.env.NODE_ENV) {
throw new SyntaxError("At-rules may not be defined in the root, found \"" + selector + "\".");
}
} else if (typeof ruleset === 'string') {
if (ruleset.match(CLASS_NAME)) {
sheet.addClassName(selector, ruleset);
} else {
sheet.addClassName(selector, _this3.convertRawCss(sheet, selector, ruleset));
}
} else if (isObject(ruleset)) {
sheet.addRuleset(_this3.convertRuleset(ruleset, sheet.createRuleset(selector)));
} else if ("production" !== process.env.NODE_ENV) {
throw new Error("Invalid ruleset for \"" + selector + "\". Must be an object or class name.");
}
});
return sheet;
};
_proto.convertRawCss = function convertRawCss(sheet, selector, declaration) {
var styleName = sheet.options.name;
var className = styleName + "-" + selector;
var stylis = new Stylis({
compress: !("production" !== process.env.NODE_ENV),
global: false,
keyframe: true,
prefix: true
});
if (isRTL(sheet.options.dir)) {
stylis.use(rtlPlugin);
}
this.emit('css', [stylis("." + className, declaration.trim()), className]);
return className;
};
_proto.convertRuleset = function convertRuleset(unifiedRuleset, ruleset) {
var _this4 = this;
if ("production" !== process.env.NODE_ENV) {
if (!isObject(unifiedRuleset)) {
throw new TypeError('Ruleset must be an object of properties.');
}
}
var atRules = [];
Object.keys(unifiedRuleset).forEach(function (baseKey) {
var key = baseKey;
var value = unifiedRuleset[key];
if (typeof value === 'undefined') {
return;
}
if (key.startsWith('@')) {
atRules.push(key);
} else if (key.startsWith(':') || key.startsWith('[')) {
_this4.convertSelector(key, value, ruleset);
} else {
var newValue = _this4.emit("property:" + key, [ruleset, value]);
_this4.emit('property', [ruleset, key, newValue || value]);
}
});
atRules.forEach(function (key) {
switch (key) {
case '@fallbacks':
{
var fallbacks = unifiedRuleset[key] || {};
if ("production" !== process.env.NODE_ENV) {
if (!isObject(fallbacks)) {
throw new Error('@fallbacks must be an object of property names to fallback values.');
}
}
Object.keys(fallbacks).forEach(function (property) {
_this4.emit('fallback', [ruleset, property, toArray(fallbacks[property])]);
});
break;
}
case '@media':
case '@supports':
{
var styles = unifiedRuleset[key] || {};
if ("production" !== process.env.NODE_ENV) {
if (!isObject(styles)) {
throw new Error(key + " must be an object of queries to rulesets.");
}
}
Object.keys(styles).forEach(function (query) {
if (isObject(styles[query])) {
var event = key === '@media' ? 'media' : 'support';
_this4.emit(event, [ruleset, query, _this4.convertRuleset(styles[query], ruleset.createRuleset(key + " " + query))]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error(key + " " + query + " must be a mapping of conditions to style objects.");
}
});
break;
}
case '@selectors':
{
var selectors = unifiedRuleset[key] || {};
if ("production" !== process.env.NODE_ENV) {
if (!isObject(selectors)) {
throw new Error('@selectors must be an object of selectors to rulesets.');
}
}
Object.keys(selectors).forEach(function (selector) {
_this4.convertSelector(selector, selectors[selector], ruleset, true);
});
break;
}
default:
{
if ("production" !== process.env.NODE_ENV) {
throw new SyntaxError("Unsupported local at-rule \"" + key + "\".");
}
}
}
});
return ruleset;
};
_proto.convertSelector = function convertSelector(key, value, ruleset, inAtRule) {
var _this5 = this;
if (inAtRule === void 0) {
inAtRule = false;
}
if ("production" !== process.env.NODE_ENV) {
if (!isObject(value)) {
throw new Error("Selector \"" + key + "\" must be a ruleset object.");
} else if ((key.includes(',') || !key.match(SELECTOR)) && !inAtRule) {
throw new Error("Advanced selector \"" + key + "\" must be nested within an @selectors block.");
}
}
key.split(',').forEach(function (k) {
var selector = k.trim();
var type = 'selector';
if (selector.charAt(0) === ':') {
type = 'pseudo';
} else if (selector.charAt(0) === '[') {
type = 'attribute';
}
_this5.emit(type, [ruleset, selector, _this5.convertRuleset(value, ruleset.createRuleset(selector))]);
});
};
_proto.convertFontFaces = function convertFontFaces(fontFamily, faces, sheet) {
var _this6 = this;
var srcPaths = [];
var fontFaces = faces.map(function (font) {
srcPaths.push(font.srcPaths);
return _this6.convertRuleset(formatFontFace(_extends({}, font, {
fontFamily: fontFamily
})), sheet.createRuleset(fontFamily));
});
this.emit('font-face', [sheet, fontFaces, fontFamily, srcPaths]);
};
_proto.convertKeyframe = function convertKeyframe(animationName, frames, sheet) {
var _this7 = this;
var keyframe = sheet.createRuleset(animationName);
Object.keys(frames).forEach(function (key) {
var value = frames[key];
if (typeof value !== 'string' && typeof value !== 'undefined') {
keyframe.addNested(key, _this7.convertRuleset(value, keyframe.createRuleset(key)));
}
});
this.emit('keyframe', [sheet, keyframe, animationName]);
};
_proto.injectFontFaces = function injectFontFaces(value, cache) {
if (value === void 0) {
value = '';
}
if (cache === void 0) {
cache = {};
}
var fontFaces = [];
value.split(',').forEach(function (name) {
var familyName = name.trim();
var fonts = cache[familyName];
if (Array.isArray(fonts)) {
fontFaces.push.apply(fontFaces, fonts);
} else {
fontFaces.push(familyName);
}
});
return fontFaces;
};
_proto.injectKeyframes = function injectKeyframes(value, cache) {
if (value === void 0) {
value = '';
}
if (cache === void 0) {
cache = {};
}
return value.split(',').map(function (name) {
var animationName = name.trim();
return cache[animationName] || animationName;
});
};
_proto.emit = function emit(eventName, args) {
if (this.handlers[eventName]) {
var _this$handlers;
return (_this$handlers = this.handlers)[eventName].apply(_this$handlers, args);
}
return undefined;
};
_proto.off = function off(eventName) {
delete this.handlers[eventName];
return this;
};
_proto.on = function on(eventName, callback) {
this.handlers[eventName] = callback;
return this;
};
return UnifiedSyntax;
}();
var GLOBAL_STYLE_NAME = ':root';
var Adapter = function () {
function Adapter() {
_defineProperty(this, "aesthetic", void 0);
_defineProperty(this, "syntax", new UnifiedSyntax());
_defineProperty(this, "cacheManager", new CacheManager());
_defineProperty(this, "sheetManager", null);
}
var _proto = Adapter.prototype;
_proto.applyGlobalStyles = function applyGlobalStyles(baseOptions) {
if (typeof document !== 'undefined') {
document.documentElement.setAttribute('dir', this.aesthetic.options.rtl ? 'rtl' : 'ltr');
}
var options = this.prepareTransformOptions(_extends({}, baseOptions, {
global: true,
name: GLOBAL_STYLE_NAME
}));
var cacheOptions = _extends({}, options);
delete cacheOptions.dir;
var cache = this.cacheManager.get(GLOBAL_STYLE_NAME, cacheOptions);
var globalSheet = this.aesthetic.getGlobalSheet(options.theme);
if (cache || !globalSheet) {
return this;
}
var parsedSheet = this.cacheManager.set(GLOBAL_STYLE_NAME, this.parseStyleSheet(this.syntax.convertGlobalSheet(globalSheet, options).toObject(), options), cacheOptions);
this.transformStyles(Object.values(parsedSheet), options);
this.flushStyles(GLOBAL_STYLE_NAME);
return this;
};
_proto.createStyleSheet = function createStyleSheet(styleName, baseOptions) {
var options = this.prepareTransformOptions(baseOptions);
var cache = this.cacheManager.get(styleName, options);
if (cache) {
return cache;
}
this.applyGlobalStyles(baseOptions);
var nativeSheet = this.syntax.convertStyleSheet(this.aesthetic.getStyleSheet(styleName, options.theme), _extends({}, options, {
name: styleName
}));
var parsedSheet = this.parseStyleSheet(nativeSheet.toObject(), options);
return this.cacheManager.set(styleName, _extends({}, parsedSheet, {}, nativeSheet.classNames), options);
};
_proto.flushStyles = function flushStyles(styleName) {};
_proto.getCacheManager = function getCacheManager() {
return this.cacheManager;
};
_proto.getStyleSheetManager = function getStyleSheetManager() {
if (this.sheetManager) {
return this.sheetManager;
}
this.sheetManager = new StyleSheetManager();
return this.sheetManager;
};
_proto.isParsedBlock = function isParsedBlock(block) {
return isObject(block);
};
_proto.parseStyleSheet = function parseStyleSheet(styleSheet, options) {
return _extends({}, styleSheet);
};
_proto.purgeStyles = function purgeStyles() {};
_proto.resetGlobalStyles = function resetGlobalStyles(prevTheme) {
this.cacheManager.clear(function (unit) {
return unit.global === true && unit.theme === prevTheme;
});
this.purgeStyles();
return this;
};
_proto.transformStyles = function transformStyles(styles, baseOptions) {
var _this = this;
var options = this.prepareTransformOptions(baseOptions);
var classNames = [];
var nativeBlocks = [];
var parsedBlocks = [];
var inlineName = '';
styles.forEach(function (style) {
if (!style) {
return;
}
if (typeof style === 'string') {
classNames.push.apply(classNames, String(style).split(' ').map(function (s) {
return stripClassPrefix(s).trim();
}));
} else if (isObject(style)) {
if (_this.isParsedBlock(style)) {
parsedBlocks.push(style);
} else {
nativeBlocks.push(style);
}
} else if ("production" !== process.env.NODE_ENV) {
throw new Error('Unsupported style type to transform.');
}
});
if (nativeBlocks.length > 0) {
var nativeSheet = new Sheet(options);
var counter = 0;
inlineName = uuid();
nativeBlocks.forEach(function (block) {
nativeSheet.addRuleset(nativeSheet.createRuleset("inline-" + counter).addProperties(block));
counter += 1;
});
parsedBlocks.push.apply(parsedBlocks, Object.values(this.parseStyleSheet(nativeSheet.toObject(), options)));
}
if (parsedBlocks.length > 0) {
classNames.push(this.transformToClassName(parsedBlocks));
}
if (inlineName) {
this.flushStyles(inlineName);
}
return classNames.join(' ').trim();
};
_proto.prepareTransformOptions = function prepareTransformOptions(options) {
if (options === void 0) {
options = {};
}
var dir = this.aesthetic.options.rtl ? 'rtl' : 'ltr';
return {
dir: options.dir || dir,
global: options.global || false,
name: options.name || '',
theme: options.theme || this.aesthetic.options.theme
};
};
return Adapter;
}();
var ClassNameAdapter = function (_Adapter) {
_inheritsLoose(ClassNameAdapter, _Adapter);
function ClassNameAdapter() {
return _Adapter.apply(this, arguments) || this;
}
var _proto = ClassNameAdapter.prototype;
_proto.transformToClassName = function transformToClassName(styles) {
return styles.filter(function (style) {
return style && typeof style === 'string';
}).join(' ');
};
return ClassNameAdapter;
}(Adapter);
var DEFAULT_OPTIONS = {
adapter: new ClassNameAdapter(),
cxPropName: 'cx',
extendable: false,
passThemeProp: false,
rtl: false,
stylesPropName: 'styles',
theme: 'default',
themePropName: 'theme'
};
var Aesthetic = function () {
function Aesthetic(options) {
if (options === void 0) {
options = {};
}
_defineProperty(this, "globalSheets", {});
_defineProperty(this, "options", _extends({}, DEFAULT_OPTIONS));
_defineProperty(this, "parents", {});
_defineProperty(this, "styleSheets", {});
_defineProperty(this, "themes", {});
this.configure(options);
}
var _proto = Aesthetic.prototype;
_proto.changeTheme = function changeTheme(themeName) {
var adapter = this.getAdapter();
this.getTheme(themeName);
this.configure({
theme: themeName
});
adapter.resetGlobalStyles(this.options.theme);
adapter.applyGlobalStyles({
theme: themeName
});
return this;
};
_proto.configure = function configure(options) {
this.options = _extends({}, this.options, {}, options);
this.options.adapter.aesthetic = this;
};
_proto.extendStyles = function extendStyles() {
for (var _len = arguments.length, styleSheets = new Array(_len), _key = 0; _key < _len; _key++) {
styleSheets[_key] = arguments[_key];
}
return function (theme) {
var sheets = styleSheets.map(function (sheet) {
return sheet(theme);
});
return deepMerge.apply(void 0, [true, {}].concat(sheets));
};
};
_proto.extendTheme = function extendTheme(themeName, parentThemeName, theme, globalSheet) {
return this.registerTheme(themeName, deepMerge(true, {}, this.getTheme(parentThemeName), theme), globalSheet || this.globalSheets[parentThemeName]);
};
_proto.getAdapter = function getAdapter() {
return this.options.adapter;
};
_proto.getGlobalSheet = function getGlobalSheet(themeName) {
var theme = this.getTheme(themeName);
var globalFactory = this.globalSheets[themeName];
if (!globalFactory) {
return null;
}
return globalFactory(theme);
};
_proto.getStyleSheet = function getStyleSheet(styleName, themeName) {
var parentStyleName = this.parents[styleName];
var styleFactory = this.styleSheets[styleName];
var styleSheet = styleFactory(this.getTheme(themeName));
if (parentStyleName) {
return deepMerge(true, {}, this.getStyleSheet(parentStyleName, themeName), styleSheet);
}
return styleSheet;
};
_proto.getTheme = function getTheme(name) {
var themeName = name || this.options.theme;
var theme = this.themes[themeName];
if ("production" !== process.env.NODE_ENV) {
if (!theme || !isObject(theme)) {
throw new Error("Theme \"" + themeName + "\" does not exist.");
}
}
return theme;
};
_proto.registerStyleSheet = function registerStyleSheet(styleName, styleSheet, extendFrom) {
if (extendFrom) {
if ("production" !== process.env.NODE_ENV) {
if (!this.styleSheets[extendFrom]) {
throw new Error("Cannot extend from \"" + extendFrom + "\" as those styles do not exist.");
} else if (extendFrom === styleName) {
throw new Error('Cannot extend styles from itself.');
}
}
this.parents[styleName] = extendFrom;
}
this.styleSheets[styleName] = this.validateDefinition(styleName, styleSheet);
return this;
};
_proto.registerTheme = function registerTheme(themeName, theme, globalSheet) {
if ("production" !== process.env.NODE_ENV) {
if (this.themes[themeName]) {
throw new Error("Theme \"" + themeName + "\" already exists.");
} else if (!isObject(theme)) {
throw new TypeError("Theme \"" + themeName + "\" must be a style object.");
}
}
this.themes[themeName] = theme;
if (globalSheet) {
this.globalSheets[themeName] = this.validateDefinition(themeName, globalSheet);
}
return this;
};
_proto.resetForTesting = function resetForTesting() {
if (process.env.NODE_ENV === 'test') {
this.globalSheets = {};
this.parents = {};
this.styleSheets = {};
this.themes = {};
this.configure(DEFAULT_OPTIONS);
}
};
_proto.validateDefinition = function validateDefinition(key, value) {
if ("production" !== process.env.NODE_ENV) {
if (value !== null && typeof value !== 'function') {
throw new TypeError("Definition for \"" + key + "\" must be null or a function.");
}
}
return value;
};
return Aesthetic;
}();
var instance = new Aesthetic();
/**

@@ -5,12 +1099,4 @@ * @copyright 2017-2019, Miles Johnson

*/
import instance from './instance';
import Adapter from './Adapter';
import Aesthetic from './Aesthetic';
import ClassNameAdapter from './ClassNameAdapter';
import UnifiedSyntax from './UnifiedSyntax';
import Ruleset from './Ruleset';
import Sheet from './Sheet';
export * from './constants';
export * from './types';
export { Adapter, Aesthetic, ClassNameAdapter, UnifiedSyntax, Ruleset, Sheet };
export default instance;
export default instance;
export { Adapter, Aesthetic, ClassNameAdapter, GLOBAL_STYLE_NAME, Ruleset, Sheet, UnifiedSyntax };

@@ -1,9 +0,940 @@

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import convertRTL from 'rtl-css-js';
import { isRTL, toObjectRecursive, getFlushedStyles as getFlushedStyles$1, purgeStyles, toArray, isObject, formatFontFace, stripClassPrefix, getStyleElements } from 'aesthetic-utils';
import uuid from 'uuid/v4';
import Stylis from 'stylis';
import { convertProperty } from 'rtl-css-js/core';
import convertRTL from 'rtl-css-js';
import { getFlushedStyles as getBaseFlushedStyles, getStyleElements, isObject } from 'aesthetic-utils';
import TestAdapter from './TestAdapter';
import { GLOBAL_STYLE_NAME } from './constants';
export { TestAdapter };
export function setupAesthetic(aesthetic, adapter) {
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var CacheManager = function () {
function CacheManager() {
_defineProperty(this, "cache", new Map());
}
var _proto = CacheManager.prototype;
_proto.clear = function clear(filter) {
var _this = this;
if (filter) {
this.cache.forEach(function (units, key) {
_this.cache.set(key, units.filter(function (unit) {
return !filter(unit);
}));
});
} else {
this.cache.clear();
}
return this;
};
_proto.compare = function compare(unit, tags) {
return unit.dir === tags.dir && unit.global === tags.global && unit.theme === tags.theme;
};
_proto.get = function get(key, tags) {
var _this2 = this;
var units = this.cache.get(key);
if (!units || units.length === 0) {
return null;
}
var cache = units.find(function (unit) {
return _this2.compare(unit, tags);
});
return cache ? cache.value : null;
};
_proto.set = function set(key, value, tags) {
var units = this.cache.get(key) || [];
units.push(_extends({}, tags, {
value: value
}));
this.cache.set(key, units);
return value;
};
return CacheManager;
}();
var Ruleset = function () {
function Ruleset(selector, root, parent) {
if (parent === void 0) {
parent = null;
}
_defineProperty(this, "compoundProperties", new Map());
_defineProperty(this, "nested", new Map());
_defineProperty(this, "parent", null);
_defineProperty(this, "properties", {});
_defineProperty(this, "root", void 0);
_defineProperty(this, "selector", void 0);
this.selector = selector;
this.root = root;
this.parent = parent;
}
var _proto = Ruleset.prototype;
_proto.addCompoundProperty = function addCompoundProperty(key, value) {
this.compoundProperties.set(key, value);
return this;
};
_proto.addNested = function addNested(selector, ruleset, merge) {
if (merge === void 0) {
merge = true;
}
if (merge && this.nested.has(selector)) {
this.nested.get(selector).merge(ruleset);
} else {
this.nested.set(selector, ruleset);
}
return this;
};
_proto.addProperty = function addProperty(key, value) {
this.properties[key] = value;
return this;
};
_proto.addProperties = function addProperties(properties) {
Object.assign(this.properties, properties);
return this;
};
_proto.createRuleset = function createRuleset(selector) {
return new Ruleset(selector, this.root, this);
};
_proto.merge = function merge(ruleset) {
var _this = this;
Object.assign(this.properties, ruleset.properties);
ruleset.nested.forEach(function (nested, selector) {
_this.addNested(selector, nested);
});
return this;
};
_proto.toObject = function toObject() {
var props = isRTL(this.root.options.dir) ? convertRTL(this.properties) : this.properties;
var compounds = {};
this.compoundProperties.forEach(function (compound, key) {
compounds[key] = compound;
});
return _extends({}, props, {}, compounds, {}, toObjectRecursive(this.nested));
};
return Ruleset;
}();
var Sheet = function () {
function Sheet(options) {
if (options === void 0) {
options = {};
}
_defineProperty(this, "atRules", {});
_defineProperty(this, "classNames", {});
_defineProperty(this, "options", void 0);
_defineProperty(this, "ruleSets", {});
this.options = options;
}
var _proto = Sheet.prototype;
_proto.addAtRule = function addAtRule(rule, value) {
this.atRules[rule] = value;
return this;
};
_proto.addClassName = function addClassName(selector, value) {
this.classNames[selector] = value;
return this;
};
_proto.addRuleset = function addRuleset(set) {
this.ruleSets[set.selector] = set;
return this;
};
_proto.createRuleset = function createRuleset(selector) {
return new Ruleset(selector, this);
};
_proto.createSheet = function createSheet(options) {
return new Sheet(options || this.options);
};
_proto.toObject = function toObject() {
var _this = this;
var atRules = {};
var sets = {};
Object.keys(this.atRules).forEach(function (key) {
var value = _this.atRules[key];
if (value instanceof Sheet || value instanceof Ruleset) {
sets[key] = value;
} else if (Array.isArray(value)) {
atRules[key] = value.map(function (item) {
return item instanceof Ruleset ? item.toObject() : item;
});
} else {
atRules[key] = value;
}
});
return _extends({}, atRules, {}, toObjectRecursive(sets), {}, toObjectRecursive(this.ruleSets));
};
return Sheet;
}();
var StyleSheetManager = function () {
function StyleSheetManager() {
_defineProperty(this, "element", null);
_defineProperty(this, "sheet", null);
}
var _proto = StyleSheetManager.prototype;
_proto.getFlushedStyles = function getFlushedStyles() {
return getFlushedStyles$1(this.getStyleElement());
};
_proto.getStyleElement = function getStyleElement() {
if (this.element) {
return this.element;
}
this.element = document.createElement('style');
this.element.type = 'text/css';
this.element.media = 'screen';
this.element.setAttribute('data-aesthetic', 'true');
document.head.append(this.element);
this.sheet = this.element.sheet;
return this.element;
};
_proto.injectRule = function injectRule(rule) {
this.getStyleElement();
this.sheet.insertRule(rule, this.sheet.cssRules.length);
return this;
};
_proto.injectStatements = function injectStatements(css) {
this.getStyleElement().textContent += css;
return this;
};
_proto.purgeStyles = function purgeStyles$1() {
purgeStyles(this.getStyleElement());
return this;
};
return StyleSheetManager;
}();
var SELECTOR = /^((\[[\x2Da-z\u017F\u212A]+\])|(::?[\x2Da-z\u017F\u212A]+))$/i;
var CLASS_NAME = /^[a-z\u017F\u212A]{1}[\x2D0-9_a-z\u017F\u212A]+$/i;
function rtlPlugin(context, content) {
if (context !== 1) {
return undefined;
}
var _content$split = content.split(':', 2),
rawKey = _content$split[0],
rawValue = _content$split[1];
var isQuoted = rawValue.trim().startsWith("'");
var unquotedValue = isQuoted ? rawValue.slice(1).slice(0, -1) : rawValue;
var _convertProperty = convertProperty(rawKey.trim(), unquotedValue.trim()),
key = _convertProperty.key,
value = _convertProperty.value;
return key + ":" + (isQuoted ? "'" + value + "'" : value);
}
var UnifiedSyntax = function () {
function UnifiedSyntax() {
var _this = this;
_defineProperty(this, "handlers", {});
_defineProperty(this, "keyframesCount", 0);
_defineProperty(this, "handleAnimationName", function (ruleset, value) {
if (!value) {
return undefined;
}
return (Array.isArray(value) ? value : [value]).map(function (item) {
if (typeof item === 'string') {
return item;
}
var name = item.name || "keyframe-" + (_this.keyframesCount += 1);
_this.convertKeyframe(name, item, ruleset.root);
return name;
}).join(', ');
});
_defineProperty(this, "handleFontFamily", function (ruleset, value) {
if (!value) {
return undefined;
}
var output = new Set();
var fontFaces = {};
toArray(value).forEach(function (item) {
if (typeof item === 'string') {
output.add(item);
return;
}
var name = item.fontFamily;
if (!name) {
return;
}
output.add(name);
if (fontFaces[name]) {
fontFaces[name].push(item);
} else {
fontFaces[name] = [item];
}
});
Object.keys(fontFaces).forEach(function (fontFamily) {
_this.convertFontFaces(fontFamily, fontFaces[fontFamily], ruleset.root);
});
return Array.from(output).join(', ');
});
this.on('property:animationName', this.handleAnimationName);
this.on('property:fontFamily', this.handleFontFamily);
}
var _proto = UnifiedSyntax.prototype;
_proto.convertGlobalSheet = function convertGlobalSheet(globalSheet, options) {
var _this2 = this;
var sheet = new Sheet(options);
Object.keys(globalSheet).forEach(function (rule) {
switch (rule) {
case '@charset':
{
var _charset = globalSheet[rule];
if (typeof _charset === 'string') {
_this2.emit('charset', [sheet, _charset]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error('@charset must be a string.');
}
break;
}
case '@font-face':
{
var faces = globalSheet[rule] || {};
if ("production" !== process.env.NODE_ENV) {
if (!isObject(faces)) {
throw new Error('@font-face must be an object of font family names to font faces.');
}
}
Object.keys(faces).forEach(function (fontFamily) {
_this2.convertFontFaces(fontFamily, toArray(faces[fontFamily]), sheet);
});
break;
}
case '@global':
{
var globals = globalSheet[rule] || {};
if ("production" !== process.env.NODE_ENV) {
if (!isObject(globals)) {
throw new Error('@global must be an object of selectors to ruleset objects.');
}
}
Object.keys(globals).forEach(function (selector) {
if (isObject(globals[selector])) {
_this2.emit('global', [sheet, selector, _this2.convertRuleset(globals[selector], sheet.createRuleset(selector))]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error("@global \"" + selector + "\" must be a ruleset object.");
}
});
break;
}
case '@import':
{
var _paths = globalSheet[rule];
if (typeof _paths === 'string' || Array.isArray(_paths)) {
_this2.emit('import', [sheet, toArray(_paths).map(function (path) {
return String(path);
})]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error('@import must be a string or an array of strings.');
}
break;
}
case '@keyframes':
{
var frames = globalSheet[rule] || {};
if ("production" !== process.env.NODE_ENV) {
if (!isObject(frames)) {
throw new Error('@keyframes must be an object of animation names to keyframes.');
}
}
Object.keys(frames).forEach(function (animationName) {
_this2.convertKeyframe(animationName, frames[animationName], sheet);
});
break;
}
case '@page':
case '@viewport':
{
var style = globalSheet[rule];
if (isObject(style)) {
_this2.emit(rule.slice(1), [sheet, _this2.convertRuleset(style, sheet.createRuleset(rule))]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error(rule + " must be a ruleset object.");
}
break;
}
default:
{
if ("production" !== process.env.NODE_ENV) {
throw new Error("Unknown property \"" + rule + "\". Only at-rules are allowed in the global style sheet.");
}
}
}
});
return sheet;
};
_proto.convertStyleSheet = function convertStyleSheet(styleSheet, options) {
var _this3 = this;
var sheet = new Sheet(options);
Object.keys(styleSheet).forEach(function (selector) {
var ruleset = styleSheet[selector];
if (!ruleset) {
return;
}
if (selector.charAt(0) === '@') {
if ("production" !== process.env.NODE_ENV) {
throw new SyntaxError("At-rules may not be defined in the root, found \"" + selector + "\".");
}
} else if (typeof ruleset === 'string') {
if (ruleset.match(CLASS_NAME)) {
sheet.addClassName(selector, ruleset);
} else {
sheet.addClassName(selector, _this3.convertRawCss(sheet, selector, ruleset));
}
} else if (isObject(ruleset)) {
sheet.addRuleset(_this3.convertRuleset(ruleset, sheet.createRuleset(selector)));
} else if ("production" !== process.env.NODE_ENV) {
throw new Error("Invalid ruleset for \"" + selector + "\". Must be an object or class name.");
}
});
return sheet;
};
_proto.convertRawCss = function convertRawCss(sheet, selector, declaration) {
var styleName = sheet.options.name;
var className = styleName + "-" + selector;
var stylis = new Stylis({
compress: !("production" !== process.env.NODE_ENV),
global: false,
keyframe: true,
prefix: true
});
if (isRTL(sheet.options.dir)) {
stylis.use(rtlPlugin);
}
this.emit('css', [stylis("." + className, declaration.trim()), className]);
return className;
};
_proto.convertRuleset = function convertRuleset(unifiedRuleset, ruleset) {
var _this4 = this;
if ("production" !== process.env.NODE_ENV) {
if (!isObject(unifiedRuleset)) {
throw new TypeError('Ruleset must be an object of properties.');
}
}
var atRules = [];
Object.keys(unifiedRuleset).forEach(function (baseKey) {
var key = baseKey;
var value = unifiedRuleset[key];
if (typeof value === 'undefined') {
return;
}
if (key.startsWith('@')) {
atRules.push(key);
} else if (key.startsWith(':') || key.startsWith('[')) {
_this4.convertSelector(key, value, ruleset);
} else {
var newValue = _this4.emit("property:" + key, [ruleset, value]);
_this4.emit('property', [ruleset, key, newValue || value]);
}
});
atRules.forEach(function (key) {
switch (key) {
case '@fallbacks':
{
var fallbacks = unifiedRuleset[key] || {};
if ("production" !== process.env.NODE_ENV) {
if (!isObject(fallbacks)) {
throw new Error('@fallbacks must be an object of property names to fallback values.');
}
}
Object.keys(fallbacks).forEach(function (property) {
_this4.emit('fallback', [ruleset, property, toArray(fallbacks[property])]);
});
break;
}
case '@media':
case '@supports':
{
var styles = unifiedRuleset[key] || {};
if ("production" !== process.env.NODE_ENV) {
if (!isObject(styles)) {
throw new Error(key + " must be an object of queries to rulesets.");
}
}
Object.keys(styles).forEach(function (query) {
if (isObject(styles[query])) {
var event = key === '@media' ? 'media' : 'support';
_this4.emit(event, [ruleset, query, _this4.convertRuleset(styles[query], ruleset.createRuleset(key + " " + query))]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error(key + " " + query + " must be a mapping of conditions to style objects.");
}
});
break;
}
case '@selectors':
{
var selectors = unifiedRuleset[key] || {};
if ("production" !== process.env.NODE_ENV) {
if (!isObject(selectors)) {
throw new Error('@selectors must be an object of selectors to rulesets.');
}
}
Object.keys(selectors).forEach(function (selector) {
_this4.convertSelector(selector, selectors[selector], ruleset, true);
});
break;
}
default:
{
if ("production" !== process.env.NODE_ENV) {
throw new SyntaxError("Unsupported local at-rule \"" + key + "\".");
}
}
}
});
return ruleset;
};
_proto.convertSelector = function convertSelector(key, value, ruleset, inAtRule) {
var _this5 = this;
if (inAtRule === void 0) {
inAtRule = false;
}
if ("production" !== process.env.NODE_ENV) {
if (!isObject(value)) {
throw new Error("Selector \"" + key + "\" must be a ruleset object.");
} else if ((key.includes(',') || !key.match(SELECTOR)) && !inAtRule) {
throw new Error("Advanced selector \"" + key + "\" must be nested within an @selectors block.");
}
}
key.split(',').forEach(function (k) {
var selector = k.trim();
var type = 'selector';
if (selector.charAt(0) === ':') {
type = 'pseudo';
} else if (selector.charAt(0) === '[') {
type = 'attribute';
}
_this5.emit(type, [ruleset, selector, _this5.convertRuleset(value, ruleset.createRuleset(selector))]);
});
};
_proto.convertFontFaces = function convertFontFaces(fontFamily, faces, sheet) {
var _this6 = this;
var srcPaths = [];
var fontFaces = faces.map(function (font) {
srcPaths.push(font.srcPaths);
return _this6.convertRuleset(formatFontFace(_extends({}, font, {
fontFamily: fontFamily
})), sheet.createRuleset(fontFamily));
});
this.emit('font-face', [sheet, fontFaces, fontFamily, srcPaths]);
};
_proto.convertKeyframe = function convertKeyframe(animationName, frames, sheet) {
var _this7 = this;
var keyframe = sheet.createRuleset(animationName);
Object.keys(frames).forEach(function (key) {
var value = frames[key];
if (typeof value !== 'string' && typeof value !== 'undefined') {
keyframe.addNested(key, _this7.convertRuleset(value, keyframe.createRuleset(key)));
}
});
this.emit('keyframe', [sheet, keyframe, animationName]);
};
_proto.injectFontFaces = function injectFontFaces(value, cache) {
if (value === void 0) {
value = '';
}
if (cache === void 0) {
cache = {};
}
var fontFaces = [];
value.split(',').forEach(function (name) {
var familyName = name.trim();
var fonts = cache[familyName];
if (Array.isArray(fonts)) {
fontFaces.push.apply(fontFaces, fonts);
} else {
fontFaces.push(familyName);
}
});
return fontFaces;
};
_proto.injectKeyframes = function injectKeyframes(value, cache) {
if (value === void 0) {
value = '';
}
if (cache === void 0) {
cache = {};
}
return value.split(',').map(function (name) {
var animationName = name.trim();
return cache[animationName] || animationName;
});
};
_proto.emit = function emit(eventName, args) {
if (this.handlers[eventName]) {
var _this$handlers;
return (_this$handlers = this.handlers)[eventName].apply(_this$handlers, args);
}
return undefined;
};
_proto.off = function off(eventName) {
delete this.handlers[eventName];
return this;
};
_proto.on = function on(eventName, callback) {
this.handlers[eventName] = callback;
return this;
};
return UnifiedSyntax;
}();
var GLOBAL_STYLE_NAME = ':root';
var Adapter = function () {
function Adapter() {
_defineProperty(this, "aesthetic", void 0);
_defineProperty(this, "syntax", new UnifiedSyntax());
_defineProperty(this, "cacheManager", new CacheManager());
_defineProperty(this, "sheetManager", null);
}
var _proto = Adapter.prototype;
_proto.applyGlobalStyles = function applyGlobalStyles(baseOptions) {
if (typeof document !== 'undefined') {
document.documentElement.setAttribute('dir', this.aesthetic.options.rtl ? 'rtl' : 'ltr');
}
var options = this.prepareTransformOptions(_extends({}, baseOptions, {
global: true,
name: GLOBAL_STYLE_NAME
}));
var cacheOptions = _extends({}, options);
delete cacheOptions.dir;
var cache = this.cacheManager.get(GLOBAL_STYLE_NAME, cacheOptions);
var globalSheet = this.aesthetic.getGlobalSheet(options.theme);
if (cache || !globalSheet) {
return this;
}
var parsedSheet = this.cacheManager.set(GLOBAL_STYLE_NAME, this.parseStyleSheet(this.syntax.convertGlobalSheet(globalSheet, options).toObject(), options), cacheOptions);
this.transformStyles(Object.values(parsedSheet), options);
this.flushStyles(GLOBAL_STYLE_NAME);
return this;
};
_proto.createStyleSheet = function createStyleSheet(styleName, baseOptions) {
var options = this.prepareTransformOptions(baseOptions);
var cache = this.cacheManager.get(styleName, options);
if (cache) {
return cache;
}
this.applyGlobalStyles(baseOptions);
var nativeSheet = this.syntax.convertStyleSheet(this.aesthetic.getStyleSheet(styleName, options.theme), _extends({}, options, {
name: styleName
}));
var parsedSheet = this.parseStyleSheet(nativeSheet.toObject(), options);
return this.cacheManager.set(styleName, _extends({}, parsedSheet, {}, nativeSheet.classNames), options);
};
_proto.flushStyles = function flushStyles(styleName) {};
_proto.getCacheManager = function getCacheManager() {
return this.cacheManager;
};
_proto.getStyleSheetManager = function getStyleSheetManager() {
if (this.sheetManager) {
return this.sheetManager;
}
this.sheetManager = new StyleSheetManager();
return this.sheetManager;
};
_proto.isParsedBlock = function isParsedBlock(block) {
return isObject(block);
};
_proto.parseStyleSheet = function parseStyleSheet(styleSheet, options) {
return _extends({}, styleSheet);
};
_proto.purgeStyles = function purgeStyles() {};
_proto.resetGlobalStyles = function resetGlobalStyles(prevTheme) {
this.cacheManager.clear(function (unit) {
return unit.global === true && unit.theme === prevTheme;
});
this.purgeStyles();
return this;
};
_proto.transformStyles = function transformStyles(styles, baseOptions) {
var _this = this;
var options = this.prepareTransformOptions(baseOptions);
var classNames = [];
var nativeBlocks = [];
var parsedBlocks = [];
var inlineName = '';
styles.forEach(function (style) {
if (!style) {
return;
}
if (typeof style === 'string') {
classNames.push.apply(classNames, String(style).split(' ').map(function (s) {
return stripClassPrefix(s).trim();
}));
} else if (isObject(style)) {
if (_this.isParsedBlock(style)) {
parsedBlocks.push(style);
} else {
nativeBlocks.push(style);
}
} else if ("production" !== process.env.NODE_ENV) {
throw new Error('Unsupported style type to transform.');
}
});
if (nativeBlocks.length > 0) {
var nativeSheet = new Sheet(options);
var counter = 0;
inlineName = uuid();
nativeBlocks.forEach(function (block) {
nativeSheet.addRuleset(nativeSheet.createRuleset("inline-" + counter).addProperties(block));
counter += 1;
});
parsedBlocks.push.apply(parsedBlocks, Object.values(this.parseStyleSheet(nativeSheet.toObject(), options)));
}
if (parsedBlocks.length > 0) {
classNames.push(this.transformToClassName(parsedBlocks));
}
if (inlineName) {
this.flushStyles(inlineName);
}
return classNames.join(' ').trim();
};
_proto.prepareTransformOptions = function prepareTransformOptions(options) {
if (options === void 0) {
options = {};
}
var dir = this.aesthetic.options.rtl ? 'rtl' : 'ltr';
return {
dir: options.dir || dir,
global: options.global || false,
name: options.name || '',
theme: options.theme || this.aesthetic.options.theme
};
};
return Adapter;
}();
var TestAdapter = function (_Adapter) {
_inheritsLoose(TestAdapter, _Adapter);
function TestAdapter() {
return _Adapter.apply(this, arguments) || this;
}
var _proto = TestAdapter.prototype;
_proto.isParsedBlock = function isParsedBlock(block) {
return typeof block === 'string';
};
_proto.parseStyleSheet = function parseStyleSheet(styleSheet) {
return Object.keys(styleSheet).reduce(function (obj, key) {
var _extends2;
return _extends({}, obj, (_extends2 = {}, _extends2[key] = key, _extends2));
}, {});
};
_proto.transformToClassName = function transformToClassName(styles) {
return styles.filter(function (style) {
return style && typeof style === 'string';
}).join(' ');
};
return TestAdapter;
}(Adapter);
function setupAesthetic(aesthetic, adapter) {
aesthetic.configure({

@@ -35,6 +966,6 @@ adapter: adapter || new TestAdapter()

}
export function teardownAesthetic(aesthetic) {
function teardownAesthetic(aesthetic) {
aesthetic.resetForTesting();
}
export function cleanupStyleElements() {
function cleanupStyleElements() {
getStyleElements().forEach(function (style) {

@@ -44,6 +975,6 @@ style.remove();

}
export function getFlushedStyles(namespace) {
return getBaseFlushedStyles(getStyleElements(namespace));
function getFlushedStyles(namespace) {
return getFlushedStyles$1(getStyleElements(namespace));
}
export function convertDirection(value, dir) {
function convertDirection(value, dir) {
if (dir !== 'rtl') {

@@ -76,3 +1007,3 @@ return value;

}
export function renderAndExpect(adapter, styleSheet, expectedStyles, _ref2) {
function renderAndExpect(adapter, styleSheet, expectedStyles, _ref2) {
var dir = _ref2.dir,

@@ -99,7 +1030,7 @@ _ref2$global = _ref2.global,

}
export var TEST_CLASS_NAMES = {
var TEST_CLASS_NAMES = {
footer: '.footer',
header: '.header'
};
export var TEST_STATEMENT = {
var TEST_STATEMENT = {
footer: {

@@ -112,4 +1043,4 @@ color: 'blue'

};
export var DIRECTIONS = ['ltr', 'rtl'];
export var FONT_ROBOTO = {
var DIRECTIONS = ['ltr', 'rtl'];
var FONT_ROBOTO = {
fontFamily: 'Roboto',

@@ -121,3 +1052,3 @@ fontStyle: 'normal',

};
export var FONT_ROBOTO_FLAT_SRC = {
var FONT_ROBOTO_FLAT_SRC = {
fontFamily: 'Roboto',

@@ -128,3 +1059,3 @@ fontStyle: 'normal',

};
export var FONT_CIRCULAR_MULTIPLE = [{
var FONT_CIRCULAR_MULTIPLE = [{
fontFamily: 'Circular',

@@ -150,3 +1081,3 @@ fontStyle: 'normal',

}];
export var FONT_CIRCULAR_MULTIPLE_FLAT_SRC = [{
var FONT_CIRCULAR_MULTIPLE_FLAT_SRC = [{
fontFamily: 'Circular',

@@ -172,3 +1103,3 @@ fontStyle: 'normal',

}];
export var KEYFRAME_FADE = {
var KEYFRAME_FADE = {
from: {

@@ -181,3 +1112,3 @@ opacity: 0

};
export var KEYFRAME_SLIDE_PERCENT = {
var KEYFRAME_SLIDE_PERCENT = {
'0%': {

@@ -193,3 +1124,3 @@ left: '0%'

};
export var SYNTAX_UNIFIED_LOCAL = {
var SYNTAX_UNIFIED_LOCAL = {
button: {

@@ -225,3 +1156,3 @@ margin: 0,

};
export var SYNTAX_UNIFIED_GLOBAL_FULL = {
var SYNTAX_UNIFIED_GLOBAL_FULL = {
'@font-face': {

@@ -234,3 +1165,3 @@ Roboto: FONT_ROBOTO

};
export var SYNTAX_UNIFIED_LOCAL_FULL = {
var SYNTAX_UNIFIED_LOCAL_FULL = {
button: _extends({}, SYNTAX_UNIFIED_LOCAL.button, {

@@ -244,3 +1175,3 @@ '@media': {

};
export var SYNTAX_ATTRIBUTE = {
var SYNTAX_ATTRIBUTE = {
attr: {

@@ -253,6 +1184,6 @@ display: 'block',

};
export var SYNTAX_CHARSET = {
var SYNTAX_CHARSET = {
'@charset': 'utf8'
};
export var SYNTAX_DESCENDANT = {
var SYNTAX_DESCENDANT = {
list: {

@@ -268,9 +1199,9 @@ margin: 0,

};
export var SYNTAX_IMPORT = {
var SYNTAX_IMPORT = {
'@import': 'url("./some/path.css")'
};
export var SYNTAX_IMPORT_MULTIPLE = {
var SYNTAX_IMPORT_MULTIPLE = {
'@import': ['url("./some/path.css")', 'url("./another/path.css")']
};
export var SYNTAX_FALLBACKS = {
var SYNTAX_FALLBACKS = {
fallback: {

@@ -286,3 +1217,3 @@ background: 'linear-gradient(...)',

};
export var SYNTAX_FONT_FACE = {
var SYNTAX_FONT_FACE = {
'@font-face': {

@@ -292,3 +1223,3 @@ Roboto: [FONT_ROBOTO]

};
export var SYNTAX_FONT_FACE_MULTIPLE = {
var SYNTAX_FONT_FACE_MULTIPLE = {
'@font-face': {

@@ -298,3 +1229,3 @@ Circular: FONT_CIRCULAR_MULTIPLE

};
export var SYNTAX_FONT_FACE_MIXED = {
var SYNTAX_FONT_FACE_MIXED = {
'@font-face': {

@@ -305,3 +1236,3 @@ Roboto: [FONT_ROBOTO],

};
export var SYNTAX_FONT_FACES_INLINE = {
var SYNTAX_FONT_FACES_INLINE = {
single: {

@@ -314,3 +1245,3 @@ fontFamily: FONT_ROBOTO

};
export var SYNTAX_GLOBAL = {
var SYNTAX_GLOBAL = {
'@global': {

@@ -349,3 +1280,3 @@ body: {

};
export var SYNTAX_KEYFRAMES = {
var SYNTAX_KEYFRAMES = {
'@keyframes': {

@@ -355,3 +1286,3 @@ fade: KEYFRAME_FADE

};
export var SYNTAX_KEYFRAMES_PERCENT = {
var SYNTAX_KEYFRAMES_PERCENT = {
'@keyframes': {

@@ -361,3 +1292,3 @@ slide: KEYFRAME_SLIDE_PERCENT

};
export var SYNTAX_KEYFRAMES_MIXED = {
var SYNTAX_KEYFRAMES_MIXED = {
'@keyframes': {

@@ -368,3 +1299,3 @@ fade: KEYFRAME_FADE,

};
export var SYNTAX_KEYFRAMES_INLINE = {
var SYNTAX_KEYFRAMES_INLINE = {
single: {

@@ -381,3 +1312,3 @@ animationName: _extends({}, KEYFRAME_SLIDE_PERCENT, {

};
export var SYNTAX_MEDIA_QUERY = {
var SYNTAX_MEDIA_QUERY = {
media: {

@@ -398,3 +1329,3 @@ color: 'red',

};
export var SYNTAX_MEDIA_QUERY_NESTED = {
var SYNTAX_MEDIA_QUERY_NESTED = {
media: {

@@ -414,3 +1345,3 @@ color: 'red',

};
export var SYNTAX_MULTI_SELECTOR = {
var SYNTAX_MULTI_SELECTOR = {
multi: {

@@ -425,6 +1356,6 @@ cursor: 'pointer',

};
export var SYNTAX_NAMESPACE = {
var SYNTAX_NAMESPACE = {
'@namespace': 'url(http://www.w3.org/1999/xhtml)'
};
export var SYNTAX_PAGE = {
var SYNTAX_PAGE = {
'@page': {

@@ -437,3 +1368,3 @@ margin: '1cm',

};
export var SYNTAX_PROPERTIES = {
var SYNTAX_PROPERTIES = {
props: {

@@ -446,3 +1377,3 @@ color: 'black',

};
export var SYNTAX_PSEUDO = {
var SYNTAX_PSEUDO = {
pseudo: {

@@ -458,3 +1389,3 @@ position: 'fixed',

};
export var SYNTAX_SUPPORTS = {
var SYNTAX_SUPPORTS = {
sup: {

@@ -472,3 +1403,3 @@ display: 'block',

};
export var SYNTAX_VIEWPORT = {
var SYNTAX_VIEWPORT = {
'@viewport': {

@@ -479,4 +1410,6 @@ width: 'device-width',

};
export var SYNTAX_RAW_CSS = {
var SYNTAX_RAW_CSS = {
button: "\n display: 'block';\n font-size: 16px;\n text-align: 'left';\n\n &:hover {\n color: 'red';\n }\n\n & {\n vertical-align: 'middle';\n }\n\n @media (max-width: 600px) {\n display: 'none';\n }\n\n @supports (display: flex) {\n display: 'flex';\n }\n "
};
};
export { DIRECTIONS, FONT_CIRCULAR_MULTIPLE, FONT_CIRCULAR_MULTIPLE_FLAT_SRC, FONT_ROBOTO, FONT_ROBOTO_FLAT_SRC, KEYFRAME_FADE, KEYFRAME_SLIDE_PERCENT, SYNTAX_ATTRIBUTE, SYNTAX_CHARSET, SYNTAX_DESCENDANT, SYNTAX_FALLBACKS, SYNTAX_FONT_FACE, SYNTAX_FONT_FACES_INLINE, SYNTAX_FONT_FACE_MIXED, SYNTAX_FONT_FACE_MULTIPLE, SYNTAX_GLOBAL, SYNTAX_IMPORT, SYNTAX_IMPORT_MULTIPLE, SYNTAX_KEYFRAMES, SYNTAX_KEYFRAMES_INLINE, SYNTAX_KEYFRAMES_MIXED, SYNTAX_KEYFRAMES_PERCENT, SYNTAX_MEDIA_QUERY, SYNTAX_MEDIA_QUERY_NESTED, SYNTAX_MULTI_SELECTOR, SYNTAX_NAMESPACE, SYNTAX_PAGE, SYNTAX_PROPERTIES, SYNTAX_PSEUDO, SYNTAX_RAW_CSS, SYNTAX_SUPPORTS, SYNTAX_UNIFIED_GLOBAL_FULL, SYNTAX_UNIFIED_LOCAL, SYNTAX_UNIFIED_LOCAL_FULL, SYNTAX_VIEWPORT, TEST_CLASS_NAMES, TEST_STATEMENT, TestAdapter, cleanupStyleElements, convertDirection, getFlushedStyles, renderAndExpect, setupAesthetic, teardownAesthetic };

@@ -1,58 +0,1101 @@

"use strict";
'use strict';
exports.__esModule = true;
var _exportNames = {
Adapter: true,
Aesthetic: true,
ClassNameAdapter: true,
UnifiedSyntax: true,
Ruleset: true,
Sheet: true
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var deepMerge = _interopDefault(require('extend'));
var aestheticUtils = require('aesthetic-utils');
var uuid = _interopDefault(require('uuid/v4'));
var convertRTL = _interopDefault(require('rtl-css-js'));
var Stylis = _interopDefault(require('stylis'));
var core = require('rtl-css-js/core');
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var CacheManager = function () {
function CacheManager() {
_defineProperty(this, "cache", new Map());
}
var _proto = CacheManager.prototype;
_proto.clear = function clear(filter) {
var _this = this;
if (filter) {
this.cache.forEach(function (units, key) {
_this.cache.set(key, units.filter(function (unit) {
return !filter(unit);
}));
});
} else {
this.cache.clear();
}
return this;
};
_proto.compare = function compare(unit, tags) {
return unit.dir === tags.dir && unit.global === tags.global && unit.theme === tags.theme;
};
_proto.get = function get(key, tags) {
var _this2 = this;
var units = this.cache.get(key);
if (!units || units.length === 0) {
return null;
}
var cache = units.find(function (unit) {
return _this2.compare(unit, tags);
});
return cache ? cache.value : null;
};
_proto.set = function set(key, value, tags) {
var units = this.cache.get(key) || [];
units.push(_extends({}, tags, {
value: value
}));
this.cache.set(key, units);
return value;
};
return CacheManager;
}();
var Ruleset = function () {
function Ruleset(selector, root, parent) {
if (parent === void 0) {
parent = null;
}
_defineProperty(this, "compoundProperties", new Map());
_defineProperty(this, "nested", new Map());
_defineProperty(this, "parent", null);
_defineProperty(this, "properties", {});
_defineProperty(this, "root", void 0);
_defineProperty(this, "selector", void 0);
this.selector = selector;
this.root = root;
this.parent = parent;
}
var _proto = Ruleset.prototype;
_proto.addCompoundProperty = function addCompoundProperty(key, value) {
this.compoundProperties.set(key, value);
return this;
};
_proto.addNested = function addNested(selector, ruleset, merge) {
if (merge === void 0) {
merge = true;
}
if (merge && this.nested.has(selector)) {
this.nested.get(selector).merge(ruleset);
} else {
this.nested.set(selector, ruleset);
}
return this;
};
_proto.addProperty = function addProperty(key, value) {
this.properties[key] = value;
return this;
};
_proto.addProperties = function addProperties(properties) {
Object.assign(this.properties, properties);
return this;
};
_proto.createRuleset = function createRuleset(selector) {
return new Ruleset(selector, this.root, this);
};
_proto.merge = function merge(ruleset) {
var _this = this;
Object.assign(this.properties, ruleset.properties);
ruleset.nested.forEach(function (nested, selector) {
_this.addNested(selector, nested);
});
return this;
};
_proto.toObject = function toObject() {
var props = aestheticUtils.isRTL(this.root.options.dir) ? convertRTL(this.properties) : this.properties;
var compounds = {};
this.compoundProperties.forEach(function (compound, key) {
compounds[key] = compound;
});
return _extends({}, props, {}, compounds, {}, aestheticUtils.toObjectRecursive(this.nested));
};
return Ruleset;
}();
var Sheet = function () {
function Sheet(options) {
if (options === void 0) {
options = {};
}
_defineProperty(this, "atRules", {});
_defineProperty(this, "classNames", {});
_defineProperty(this, "options", void 0);
_defineProperty(this, "ruleSets", {});
this.options = options;
}
var _proto = Sheet.prototype;
_proto.addAtRule = function addAtRule(rule, value) {
this.atRules[rule] = value;
return this;
};
_proto.addClassName = function addClassName(selector, value) {
this.classNames[selector] = value;
return this;
};
_proto.addRuleset = function addRuleset(set) {
this.ruleSets[set.selector] = set;
return this;
};
_proto.createRuleset = function createRuleset(selector) {
return new Ruleset(selector, this);
};
_proto.createSheet = function createSheet(options) {
return new Sheet(options || this.options);
};
_proto.toObject = function toObject() {
var _this = this;
var atRules = {};
var sets = {};
Object.keys(this.atRules).forEach(function (key) {
var value = _this.atRules[key];
if (value instanceof Sheet || value instanceof Ruleset) {
sets[key] = value;
} else if (Array.isArray(value)) {
atRules[key] = value.map(function (item) {
return item instanceof Ruleset ? item.toObject() : item;
});
} else {
atRules[key] = value;
}
});
return _extends({}, atRules, {}, aestheticUtils.toObjectRecursive(sets), {}, aestheticUtils.toObjectRecursive(this.ruleSets));
};
return Sheet;
}();
var StyleSheetManager = function () {
function StyleSheetManager() {
_defineProperty(this, "element", null);
_defineProperty(this, "sheet", null);
}
var _proto = StyleSheetManager.prototype;
_proto.getFlushedStyles = function getFlushedStyles() {
return aestheticUtils.getFlushedStyles(this.getStyleElement());
};
_proto.getStyleElement = function getStyleElement() {
if (this.element) {
return this.element;
}
this.element = document.createElement('style');
this.element.type = 'text/css';
this.element.media = 'screen';
this.element.setAttribute('data-aesthetic', 'true');
document.head.append(this.element);
this.sheet = this.element.sheet;
return this.element;
};
_proto.injectRule = function injectRule(rule) {
this.getStyleElement();
this.sheet.insertRule(rule, this.sheet.cssRules.length);
return this;
};
_proto.injectStatements = function injectStatements(css) {
this.getStyleElement().textContent += css;
return this;
};
_proto.purgeStyles = function purgeStyles() {
aestheticUtils.purgeStyles(this.getStyleElement());
return this;
};
return StyleSheetManager;
}();
var SELECTOR = /^((\[[\x2Da-z\u017F\u212A]+\])|(::?[\x2Da-z\u017F\u212A]+))$/i;
var CLASS_NAME = /^[a-z\u017F\u212A]{1}[\x2D0-9_a-z\u017F\u212A]+$/i;
function rtlPlugin(context, content) {
if (context !== 1) {
return undefined;
}
var _content$split = content.split(':', 2),
rawKey = _content$split[0],
rawValue = _content$split[1];
var isQuoted = rawValue.trim().startsWith("'");
var unquotedValue = isQuoted ? rawValue.slice(1).slice(0, -1) : rawValue;
var _convertProperty = core.convertProperty(rawKey.trim(), unquotedValue.trim()),
key = _convertProperty.key,
value = _convertProperty.value;
return key + ":" + (isQuoted ? "'" + value + "'" : value);
}
var UnifiedSyntax = function () {
function UnifiedSyntax() {
var _this = this;
_defineProperty(this, "handlers", {});
_defineProperty(this, "keyframesCount", 0);
_defineProperty(this, "handleAnimationName", function (ruleset, value) {
if (!value) {
return undefined;
}
return (Array.isArray(value) ? value : [value]).map(function (item) {
if (typeof item === 'string') {
return item;
}
var name = item.name || "keyframe-" + (_this.keyframesCount += 1);
_this.convertKeyframe(name, item, ruleset.root);
return name;
}).join(', ');
});
_defineProperty(this, "handleFontFamily", function (ruleset, value) {
if (!value) {
return undefined;
}
var output = new Set();
var fontFaces = {};
aestheticUtils.toArray(value).forEach(function (item) {
if (typeof item === 'string') {
output.add(item);
return;
}
var name = item.fontFamily;
if (!name) {
return;
}
output.add(name);
if (fontFaces[name]) {
fontFaces[name].push(item);
} else {
fontFaces[name] = [item];
}
});
Object.keys(fontFaces).forEach(function (fontFamily) {
_this.convertFontFaces(fontFamily, fontFaces[fontFamily], ruleset.root);
});
return Array.from(output).join(', ');
});
this.on('property:animationName', this.handleAnimationName);
this.on('property:fontFamily', this.handleFontFamily);
}
var _proto = UnifiedSyntax.prototype;
_proto.convertGlobalSheet = function convertGlobalSheet(globalSheet, options) {
var _this2 = this;
var sheet = new Sheet(options);
Object.keys(globalSheet).forEach(function (rule) {
switch (rule) {
case '@charset':
{
var _charset = globalSheet[rule];
if (typeof _charset === 'string') {
_this2.emit('charset', [sheet, _charset]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error('@charset must be a string.');
}
break;
}
case '@font-face':
{
var faces = globalSheet[rule] || {};
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(faces)) {
throw new Error('@font-face must be an object of font family names to font faces.');
}
}
Object.keys(faces).forEach(function (fontFamily) {
_this2.convertFontFaces(fontFamily, aestheticUtils.toArray(faces[fontFamily]), sheet);
});
break;
}
case '@global':
{
var globals = globalSheet[rule] || {};
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(globals)) {
throw new Error('@global must be an object of selectors to ruleset objects.');
}
}
Object.keys(globals).forEach(function (selector) {
if (aestheticUtils.isObject(globals[selector])) {
_this2.emit('global', [sheet, selector, _this2.convertRuleset(globals[selector], sheet.createRuleset(selector))]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error("@global \"" + selector + "\" must be a ruleset object.");
}
});
break;
}
case '@import':
{
var _paths = globalSheet[rule];
if (typeof _paths === 'string' || Array.isArray(_paths)) {
_this2.emit('import', [sheet, aestheticUtils.toArray(_paths).map(function (path) {
return String(path);
})]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error('@import must be a string or an array of strings.');
}
break;
}
case '@keyframes':
{
var frames = globalSheet[rule] || {};
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(frames)) {
throw new Error('@keyframes must be an object of animation names to keyframes.');
}
}
Object.keys(frames).forEach(function (animationName) {
_this2.convertKeyframe(animationName, frames[animationName], sheet);
});
break;
}
case '@page':
case '@viewport':
{
var style = globalSheet[rule];
if (aestheticUtils.isObject(style)) {
_this2.emit(rule.slice(1), [sheet, _this2.convertRuleset(style, sheet.createRuleset(rule))]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error(rule + " must be a ruleset object.");
}
break;
}
default:
{
if ("production" !== process.env.NODE_ENV) {
throw new Error("Unknown property \"" + rule + "\". Only at-rules are allowed in the global style sheet.");
}
}
}
});
return sheet;
};
_proto.convertStyleSheet = function convertStyleSheet(styleSheet, options) {
var _this3 = this;
var sheet = new Sheet(options);
Object.keys(styleSheet).forEach(function (selector) {
var ruleset = styleSheet[selector];
if (!ruleset) {
return;
}
if (selector.charAt(0) === '@') {
if ("production" !== process.env.NODE_ENV) {
throw new SyntaxError("At-rules may not be defined in the root, found \"" + selector + "\".");
}
} else if (typeof ruleset === 'string') {
if (ruleset.match(CLASS_NAME)) {
sheet.addClassName(selector, ruleset);
} else {
sheet.addClassName(selector, _this3.convertRawCss(sheet, selector, ruleset));
}
} else if (aestheticUtils.isObject(ruleset)) {
sheet.addRuleset(_this3.convertRuleset(ruleset, sheet.createRuleset(selector)));
} else if ("production" !== process.env.NODE_ENV) {
throw new Error("Invalid ruleset for \"" + selector + "\". Must be an object or class name.");
}
});
return sheet;
};
_proto.convertRawCss = function convertRawCss(sheet, selector, declaration) {
var styleName = sheet.options.name;
var className = styleName + "-" + selector;
var stylis = new Stylis({
compress: !("production" !== process.env.NODE_ENV),
global: false,
keyframe: true,
prefix: true
});
if (aestheticUtils.isRTL(sheet.options.dir)) {
stylis.use(rtlPlugin);
}
this.emit('css', [stylis("." + className, declaration.trim()), className]);
return className;
};
_proto.convertRuleset = function convertRuleset(unifiedRuleset, ruleset) {
var _this4 = this;
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(unifiedRuleset)) {
throw new TypeError('Ruleset must be an object of properties.');
}
}
var atRules = [];
Object.keys(unifiedRuleset).forEach(function (baseKey) {
var key = baseKey;
var value = unifiedRuleset[key];
if (typeof value === 'undefined') {
return;
}
if (key.startsWith('@')) {
atRules.push(key);
} else if (key.startsWith(':') || key.startsWith('[')) {
_this4.convertSelector(key, value, ruleset);
} else {
var newValue = _this4.emit("property:" + key, [ruleset, value]);
_this4.emit('property', [ruleset, key, newValue || value]);
}
});
atRules.forEach(function (key) {
switch (key) {
case '@fallbacks':
{
var fallbacks = unifiedRuleset[key] || {};
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(fallbacks)) {
throw new Error('@fallbacks must be an object of property names to fallback values.');
}
}
Object.keys(fallbacks).forEach(function (property) {
_this4.emit('fallback', [ruleset, property, aestheticUtils.toArray(fallbacks[property])]);
});
break;
}
case '@media':
case '@supports':
{
var styles = unifiedRuleset[key] || {};
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(styles)) {
throw new Error(key + " must be an object of queries to rulesets.");
}
}
Object.keys(styles).forEach(function (query) {
if (aestheticUtils.isObject(styles[query])) {
var event = key === '@media' ? 'media' : 'support';
_this4.emit(event, [ruleset, query, _this4.convertRuleset(styles[query], ruleset.createRuleset(key + " " + query))]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error(key + " " + query + " must be a mapping of conditions to style objects.");
}
});
break;
}
case '@selectors':
{
var selectors = unifiedRuleset[key] || {};
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(selectors)) {
throw new Error('@selectors must be an object of selectors to rulesets.');
}
}
Object.keys(selectors).forEach(function (selector) {
_this4.convertSelector(selector, selectors[selector], ruleset, true);
});
break;
}
default:
{
if ("production" !== process.env.NODE_ENV) {
throw new SyntaxError("Unsupported local at-rule \"" + key + "\".");
}
}
}
});
return ruleset;
};
_proto.convertSelector = function convertSelector(key, value, ruleset, inAtRule) {
var _this5 = this;
if (inAtRule === void 0) {
inAtRule = false;
}
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(value)) {
throw new Error("Selector \"" + key + "\" must be a ruleset object.");
} else if ((key.includes(',') || !key.match(SELECTOR)) && !inAtRule) {
throw new Error("Advanced selector \"" + key + "\" must be nested within an @selectors block.");
}
}
key.split(',').forEach(function (k) {
var selector = k.trim();
var type = 'selector';
if (selector.charAt(0) === ':') {
type = 'pseudo';
} else if (selector.charAt(0) === '[') {
type = 'attribute';
}
_this5.emit(type, [ruleset, selector, _this5.convertRuleset(value, ruleset.createRuleset(selector))]);
});
};
_proto.convertFontFaces = function convertFontFaces(fontFamily, faces, sheet) {
var _this6 = this;
var srcPaths = [];
var fontFaces = faces.map(function (font) {
srcPaths.push(font.srcPaths);
return _this6.convertRuleset(aestheticUtils.formatFontFace(_extends({}, font, {
fontFamily: fontFamily
})), sheet.createRuleset(fontFamily));
});
this.emit('font-face', [sheet, fontFaces, fontFamily, srcPaths]);
};
_proto.convertKeyframe = function convertKeyframe(animationName, frames, sheet) {
var _this7 = this;
var keyframe = sheet.createRuleset(animationName);
Object.keys(frames).forEach(function (key) {
var value = frames[key];
if (typeof value !== 'string' && typeof value !== 'undefined') {
keyframe.addNested(key, _this7.convertRuleset(value, keyframe.createRuleset(key)));
}
});
this.emit('keyframe', [sheet, keyframe, animationName]);
};
_proto.injectFontFaces = function injectFontFaces(value, cache) {
if (value === void 0) {
value = '';
}
if (cache === void 0) {
cache = {};
}
var fontFaces = [];
value.split(',').forEach(function (name) {
var familyName = name.trim();
var fonts = cache[familyName];
if (Array.isArray(fonts)) {
fontFaces.push.apply(fontFaces, fonts);
} else {
fontFaces.push(familyName);
}
});
return fontFaces;
};
_proto.injectKeyframes = function injectKeyframes(value, cache) {
if (value === void 0) {
value = '';
}
if (cache === void 0) {
cache = {};
}
return value.split(',').map(function (name) {
var animationName = name.trim();
return cache[animationName] || animationName;
});
};
_proto.emit = function emit(eventName, args) {
if (this.handlers[eventName]) {
var _this$handlers;
return (_this$handlers = this.handlers)[eventName].apply(_this$handlers, args);
}
return undefined;
};
_proto.off = function off(eventName) {
delete this.handlers[eventName];
return this;
};
_proto.on = function on(eventName, callback) {
this.handlers[eventName] = callback;
return this;
};
return UnifiedSyntax;
}();
var GLOBAL_STYLE_NAME = ':root';
var Adapter = function () {
function Adapter() {
_defineProperty(this, "aesthetic", void 0);
_defineProperty(this, "syntax", new UnifiedSyntax());
_defineProperty(this, "cacheManager", new CacheManager());
_defineProperty(this, "sheetManager", null);
}
var _proto = Adapter.prototype;
_proto.applyGlobalStyles = function applyGlobalStyles(baseOptions) {
if (typeof document !== 'undefined') {
document.documentElement.setAttribute('dir', this.aesthetic.options.rtl ? 'rtl' : 'ltr');
}
var options = this.prepareTransformOptions(_extends({}, baseOptions, {
global: true,
name: GLOBAL_STYLE_NAME
}));
var cacheOptions = _extends({}, options);
delete cacheOptions.dir;
var cache = this.cacheManager.get(GLOBAL_STYLE_NAME, cacheOptions);
var globalSheet = this.aesthetic.getGlobalSheet(options.theme);
if (cache || !globalSheet) {
return this;
}
var parsedSheet = this.cacheManager.set(GLOBAL_STYLE_NAME, this.parseStyleSheet(this.syntax.convertGlobalSheet(globalSheet, options).toObject(), options), cacheOptions);
this.transformStyles(Object.values(parsedSheet), options);
this.flushStyles(GLOBAL_STYLE_NAME);
return this;
};
_proto.createStyleSheet = function createStyleSheet(styleName, baseOptions) {
var options = this.prepareTransformOptions(baseOptions);
var cache = this.cacheManager.get(styleName, options);
if (cache) {
return cache;
}
this.applyGlobalStyles(baseOptions);
var nativeSheet = this.syntax.convertStyleSheet(this.aesthetic.getStyleSheet(styleName, options.theme), _extends({}, options, {
name: styleName
}));
var parsedSheet = this.parseStyleSheet(nativeSheet.toObject(), options);
return this.cacheManager.set(styleName, _extends({}, parsedSheet, {}, nativeSheet.classNames), options);
};
_proto.flushStyles = function flushStyles(styleName) {};
_proto.getCacheManager = function getCacheManager() {
return this.cacheManager;
};
_proto.getStyleSheetManager = function getStyleSheetManager() {
if (this.sheetManager) {
return this.sheetManager;
}
this.sheetManager = new StyleSheetManager();
return this.sheetManager;
};
_proto.isParsedBlock = function isParsedBlock(block) {
return aestheticUtils.isObject(block);
};
_proto.parseStyleSheet = function parseStyleSheet(styleSheet, options) {
return _extends({}, styleSheet);
};
_proto.purgeStyles = function purgeStyles() {};
_proto.resetGlobalStyles = function resetGlobalStyles(prevTheme) {
this.cacheManager.clear(function (unit) {
return unit.global === true && unit.theme === prevTheme;
});
this.purgeStyles();
return this;
};
_proto.transformStyles = function transformStyles(styles, baseOptions) {
var _this = this;
var options = this.prepareTransformOptions(baseOptions);
var classNames = [];
var nativeBlocks = [];
var parsedBlocks = [];
var inlineName = '';
styles.forEach(function (style) {
if (!style) {
return;
}
if (typeof style === 'string') {
classNames.push.apply(classNames, String(style).split(' ').map(function (s) {
return aestheticUtils.stripClassPrefix(s).trim();
}));
} else if (aestheticUtils.isObject(style)) {
if (_this.isParsedBlock(style)) {
parsedBlocks.push(style);
} else {
nativeBlocks.push(style);
}
} else if ("production" !== process.env.NODE_ENV) {
throw new Error('Unsupported style type to transform.');
}
});
if (nativeBlocks.length > 0) {
var nativeSheet = new Sheet(options);
var counter = 0;
inlineName = uuid();
nativeBlocks.forEach(function (block) {
nativeSheet.addRuleset(nativeSheet.createRuleset("inline-" + counter).addProperties(block));
counter += 1;
});
parsedBlocks.push.apply(parsedBlocks, Object.values(this.parseStyleSheet(nativeSheet.toObject(), options)));
}
if (parsedBlocks.length > 0) {
classNames.push(this.transformToClassName(parsedBlocks));
}
if (inlineName) {
this.flushStyles(inlineName);
}
return classNames.join(' ').trim();
};
_proto.prepareTransformOptions = function prepareTransformOptions(options) {
if (options === void 0) {
options = {};
}
var dir = this.aesthetic.options.rtl ? 'rtl' : 'ltr';
return {
dir: options.dir || dir,
global: options.global || false,
name: options.name || '',
theme: options.theme || this.aesthetic.options.theme
};
};
return Adapter;
}();
var ClassNameAdapter = function (_Adapter) {
_inheritsLoose(ClassNameAdapter, _Adapter);
function ClassNameAdapter() {
return _Adapter.apply(this, arguments) || this;
}
var _proto = ClassNameAdapter.prototype;
_proto.transformToClassName = function transformToClassName(styles) {
return styles.filter(function (style) {
return style && typeof style === 'string';
}).join(' ');
};
return ClassNameAdapter;
}(Adapter);
var DEFAULT_OPTIONS = {
adapter: new ClassNameAdapter(),
cxPropName: 'cx',
extendable: false,
passThemeProp: false,
rtl: false,
stylesPropName: 'styles',
theme: 'default',
themePropName: 'theme'
};
exports.default = void 0;
var _instance = _interopRequireDefault(require("./instance"));
var Aesthetic = function () {
function Aesthetic(options) {
if (options === void 0) {
options = {};
}
var _Adapter = _interopRequireDefault(require("./Adapter"));
_defineProperty(this, "globalSheets", {});
exports.Adapter = _Adapter.default;
_defineProperty(this, "options", _extends({}, DEFAULT_OPTIONS));
var _Aesthetic = _interopRequireDefault(require("./Aesthetic"));
_defineProperty(this, "parents", {});
exports.Aesthetic = _Aesthetic.default;
_defineProperty(this, "styleSheets", {});
var _ClassNameAdapter = _interopRequireDefault(require("./ClassNameAdapter"));
_defineProperty(this, "themes", {});
exports.ClassNameAdapter = _ClassNameAdapter.default;
this.configure(options);
}
var _UnifiedSyntax = _interopRequireDefault(require("./UnifiedSyntax"));
var _proto = Aesthetic.prototype;
exports.UnifiedSyntax = _UnifiedSyntax.default;
_proto.changeTheme = function changeTheme(themeName) {
var adapter = this.getAdapter();
this.getTheme(themeName);
this.configure({
theme: themeName
});
adapter.resetGlobalStyles(this.options.theme);
adapter.applyGlobalStyles({
theme: themeName
});
return this;
};
var _Ruleset = _interopRequireDefault(require("./Ruleset"));
_proto.configure = function configure(options) {
this.options = _extends({}, this.options, {}, options);
this.options.adapter.aesthetic = this;
};
exports.Ruleset = _Ruleset.default;
_proto.extendStyles = function extendStyles() {
for (var _len = arguments.length, styleSheets = new Array(_len), _key = 0; _key < _len; _key++) {
styleSheets[_key] = arguments[_key];
}
var _Sheet = _interopRequireDefault(require("./Sheet"));
return function (theme) {
var sheets = styleSheets.map(function (sheet) {
return sheet(theme);
});
return deepMerge.apply(void 0, [true, {}].concat(sheets));
};
};
exports.Sheet = _Sheet.default;
_proto.extendTheme = function extendTheme(themeName, parentThemeName, theme, globalSheet) {
return this.registerTheme(themeName, deepMerge(true, {}, this.getTheme(parentThemeName), theme), globalSheet || this.globalSheets[parentThemeName]);
};
var _constants = require("./constants");
_proto.getAdapter = function getAdapter() {
return this.options.adapter;
};
Object.keys(_constants).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
exports[key] = _constants[key];
});
_proto.getGlobalSheet = function getGlobalSheet(themeName) {
var theme = this.getTheme(themeName);
var globalFactory = this.globalSheets[themeName];
var _types = require("./types");
if (!globalFactory) {
return null;
}
Object.keys(_types).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
exports[key] = _types[key];
});
return globalFactory(theme);
};
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
_proto.getStyleSheet = function getStyleSheet(styleName, themeName) {
var parentStyleName = this.parents[styleName];
var styleFactory = this.styleSheets[styleName];
var styleSheet = styleFactory(this.getTheme(themeName));
if (parentStyleName) {
return deepMerge(true, {}, this.getStyleSheet(parentStyleName, themeName), styleSheet);
}
return styleSheet;
};
_proto.getTheme = function getTheme(name) {
var themeName = name || this.options.theme;
var theme = this.themes[themeName];
if ("production" !== process.env.NODE_ENV) {
if (!theme || !aestheticUtils.isObject(theme)) {
throw new Error("Theme \"" + themeName + "\" does not exist.");
}
}
return theme;
};
_proto.registerStyleSheet = function registerStyleSheet(styleName, styleSheet, extendFrom) {
if (extendFrom) {
if ("production" !== process.env.NODE_ENV) {
if (!this.styleSheets[extendFrom]) {
throw new Error("Cannot extend from \"" + extendFrom + "\" as those styles do not exist.");
} else if (extendFrom === styleName) {
throw new Error('Cannot extend styles from itself.');
}
}
this.parents[styleName] = extendFrom;
}
this.styleSheets[styleName] = this.validateDefinition(styleName, styleSheet);
return this;
};
_proto.registerTheme = function registerTheme(themeName, theme, globalSheet) {
if ("production" !== process.env.NODE_ENV) {
if (this.themes[themeName]) {
throw new Error("Theme \"" + themeName + "\" already exists.");
} else if (!aestheticUtils.isObject(theme)) {
throw new TypeError("Theme \"" + themeName + "\" must be a style object.");
}
}
this.themes[themeName] = theme;
if (globalSheet) {
this.globalSheets[themeName] = this.validateDefinition(themeName, globalSheet);
}
return this;
};
_proto.resetForTesting = function resetForTesting() {
if (process.env.NODE_ENV === 'test') {
this.globalSheets = {};
this.parents = {};
this.styleSheets = {};
this.themes = {};
this.configure(DEFAULT_OPTIONS);
}
};
_proto.validateDefinition = function validateDefinition(key, value) {
if ("production" !== process.env.NODE_ENV) {
if (value !== null && typeof value !== 'function') {
throw new TypeError("Definition for \"" + key + "\" must be null or a function.");
}
}
return value;
};
return Aesthetic;
}();
var instance = new Aesthetic();
/**

@@ -62,3 +1105,10 @@ * @copyright 2017-2019, Miles Johnson

*/
var _default = _instance.default;
exports.default = _default;
exports.Adapter = Adapter;
exports.Aesthetic = Aesthetic;
exports.ClassNameAdapter = ClassNameAdapter;
exports.GLOBAL_STYLE_NAME = GLOBAL_STYLE_NAME;
exports.Ruleset = Ruleset;
exports.Sheet = Sheet;
exports.UnifiedSyntax = UnifiedSyntax;
exports.default = instance;

@@ -1,29 +0,948 @@

"use strict";
'use strict';
exports.__esModule = true;
exports.setupAesthetic = setupAesthetic;
exports.teardownAesthetic = teardownAesthetic;
exports.cleanupStyleElements = cleanupStyleElements;
exports.getFlushedStyles = getFlushedStyles;
exports.convertDirection = convertDirection;
exports.renderAndExpect = renderAndExpect;
exports.SYNTAX_RAW_CSS = exports.SYNTAX_VIEWPORT = exports.SYNTAX_SUPPORTS = exports.SYNTAX_PSEUDO = exports.SYNTAX_PROPERTIES = exports.SYNTAX_PAGE = exports.SYNTAX_NAMESPACE = exports.SYNTAX_MULTI_SELECTOR = exports.SYNTAX_MEDIA_QUERY_NESTED = exports.SYNTAX_MEDIA_QUERY = exports.SYNTAX_KEYFRAMES_INLINE = exports.SYNTAX_KEYFRAMES_MIXED = exports.SYNTAX_KEYFRAMES_PERCENT = exports.SYNTAX_KEYFRAMES = exports.SYNTAX_GLOBAL = exports.SYNTAX_FONT_FACES_INLINE = exports.SYNTAX_FONT_FACE_MIXED = exports.SYNTAX_FONT_FACE_MULTIPLE = exports.SYNTAX_FONT_FACE = exports.SYNTAX_FALLBACKS = exports.SYNTAX_IMPORT_MULTIPLE = exports.SYNTAX_IMPORT = exports.SYNTAX_DESCENDANT = exports.SYNTAX_CHARSET = exports.SYNTAX_ATTRIBUTE = exports.SYNTAX_UNIFIED_LOCAL_FULL = exports.SYNTAX_UNIFIED_GLOBAL_FULL = exports.SYNTAX_UNIFIED_LOCAL = exports.KEYFRAME_SLIDE_PERCENT = exports.KEYFRAME_FADE = exports.FONT_CIRCULAR_MULTIPLE_FLAT_SRC = exports.FONT_CIRCULAR_MULTIPLE = exports.FONT_ROBOTO_FLAT_SRC = exports.FONT_ROBOTO = exports.DIRECTIONS = exports.TEST_STATEMENT = exports.TEST_CLASS_NAMES = void 0;
Object.defineProperty(exports, '__esModule', { value: true });
var _rtlCssJs = _interopRequireDefault(require("rtl-css-js"));
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var _aestheticUtils = require("aesthetic-utils");
var convertRTL = _interopDefault(require('rtl-css-js'));
var aestheticUtils = require('aesthetic-utils');
var uuid = _interopDefault(require('uuid/v4'));
var Stylis = _interopDefault(require('stylis'));
var core = require('rtl-css-js/core');
var _TestAdapter = _interopRequireDefault(require("./TestAdapter"));
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
exports.TestAdapter = _TestAdapter.default;
return obj;
}
var _constants = require("./constants");
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var CacheManager = function () {
function CacheManager() {
_defineProperty(this, "cache", new Map());
}
var _proto = CacheManager.prototype;
_proto.clear = function clear(filter) {
var _this = this;
if (filter) {
this.cache.forEach(function (units, key) {
_this.cache.set(key, units.filter(function (unit) {
return !filter(unit);
}));
});
} else {
this.cache.clear();
}
return this;
};
_proto.compare = function compare(unit, tags) {
return unit.dir === tags.dir && unit.global === tags.global && unit.theme === tags.theme;
};
_proto.get = function get(key, tags) {
var _this2 = this;
var units = this.cache.get(key);
if (!units || units.length === 0) {
return null;
}
var cache = units.find(function (unit) {
return _this2.compare(unit, tags);
});
return cache ? cache.value : null;
};
_proto.set = function set(key, value, tags) {
var units = this.cache.get(key) || [];
units.push(_extends({}, tags, {
value: value
}));
this.cache.set(key, units);
return value;
};
return CacheManager;
}();
var Ruleset = function () {
function Ruleset(selector, root, parent) {
if (parent === void 0) {
parent = null;
}
_defineProperty(this, "compoundProperties", new Map());
_defineProperty(this, "nested", new Map());
_defineProperty(this, "parent", null);
_defineProperty(this, "properties", {});
_defineProperty(this, "root", void 0);
_defineProperty(this, "selector", void 0);
this.selector = selector;
this.root = root;
this.parent = parent;
}
var _proto = Ruleset.prototype;
_proto.addCompoundProperty = function addCompoundProperty(key, value) {
this.compoundProperties.set(key, value);
return this;
};
_proto.addNested = function addNested(selector, ruleset, merge) {
if (merge === void 0) {
merge = true;
}
if (merge && this.nested.has(selector)) {
this.nested.get(selector).merge(ruleset);
} else {
this.nested.set(selector, ruleset);
}
return this;
};
_proto.addProperty = function addProperty(key, value) {
this.properties[key] = value;
return this;
};
_proto.addProperties = function addProperties(properties) {
Object.assign(this.properties, properties);
return this;
};
_proto.createRuleset = function createRuleset(selector) {
return new Ruleset(selector, this.root, this);
};
_proto.merge = function merge(ruleset) {
var _this = this;
Object.assign(this.properties, ruleset.properties);
ruleset.nested.forEach(function (nested, selector) {
_this.addNested(selector, nested);
});
return this;
};
_proto.toObject = function toObject() {
var props = aestheticUtils.isRTL(this.root.options.dir) ? convertRTL(this.properties) : this.properties;
var compounds = {};
this.compoundProperties.forEach(function (compound, key) {
compounds[key] = compound;
});
return _extends({}, props, {}, compounds, {}, aestheticUtils.toObjectRecursive(this.nested));
};
return Ruleset;
}();
var Sheet = function () {
function Sheet(options) {
if (options === void 0) {
options = {};
}
_defineProperty(this, "atRules", {});
_defineProperty(this, "classNames", {});
_defineProperty(this, "options", void 0);
_defineProperty(this, "ruleSets", {});
this.options = options;
}
var _proto = Sheet.prototype;
_proto.addAtRule = function addAtRule(rule, value) {
this.atRules[rule] = value;
return this;
};
_proto.addClassName = function addClassName(selector, value) {
this.classNames[selector] = value;
return this;
};
_proto.addRuleset = function addRuleset(set) {
this.ruleSets[set.selector] = set;
return this;
};
_proto.createRuleset = function createRuleset(selector) {
return new Ruleset(selector, this);
};
_proto.createSheet = function createSheet(options) {
return new Sheet(options || this.options);
};
_proto.toObject = function toObject() {
var _this = this;
var atRules = {};
var sets = {};
Object.keys(this.atRules).forEach(function (key) {
var value = _this.atRules[key];
if (value instanceof Sheet || value instanceof Ruleset) {
sets[key] = value;
} else if (Array.isArray(value)) {
atRules[key] = value.map(function (item) {
return item instanceof Ruleset ? item.toObject() : item;
});
} else {
atRules[key] = value;
}
});
return _extends({}, atRules, {}, aestheticUtils.toObjectRecursive(sets), {}, aestheticUtils.toObjectRecursive(this.ruleSets));
};
return Sheet;
}();
var StyleSheetManager = function () {
function StyleSheetManager() {
_defineProperty(this, "element", null);
_defineProperty(this, "sheet", null);
}
var _proto = StyleSheetManager.prototype;
_proto.getFlushedStyles = function getFlushedStyles() {
return aestheticUtils.getFlushedStyles(this.getStyleElement());
};
_proto.getStyleElement = function getStyleElement() {
if (this.element) {
return this.element;
}
this.element = document.createElement('style');
this.element.type = 'text/css';
this.element.media = 'screen';
this.element.setAttribute('data-aesthetic', 'true');
document.head.append(this.element);
this.sheet = this.element.sheet;
return this.element;
};
_proto.injectRule = function injectRule(rule) {
this.getStyleElement();
this.sheet.insertRule(rule, this.sheet.cssRules.length);
return this;
};
_proto.injectStatements = function injectStatements(css) {
this.getStyleElement().textContent += css;
return this;
};
_proto.purgeStyles = function purgeStyles() {
aestheticUtils.purgeStyles(this.getStyleElement());
return this;
};
return StyleSheetManager;
}();
var SELECTOR = /^((\[[\x2Da-z\u017F\u212A]+\])|(::?[\x2Da-z\u017F\u212A]+))$/i;
var CLASS_NAME = /^[a-z\u017F\u212A]{1}[\x2D0-9_a-z\u017F\u212A]+$/i;
function rtlPlugin(context, content) {
if (context !== 1) {
return undefined;
}
var _content$split = content.split(':', 2),
rawKey = _content$split[0],
rawValue = _content$split[1];
var isQuoted = rawValue.trim().startsWith("'");
var unquotedValue = isQuoted ? rawValue.slice(1).slice(0, -1) : rawValue;
var _convertProperty = core.convertProperty(rawKey.trim(), unquotedValue.trim()),
key = _convertProperty.key,
value = _convertProperty.value;
return key + ":" + (isQuoted ? "'" + value + "'" : value);
}
var UnifiedSyntax = function () {
function UnifiedSyntax() {
var _this = this;
_defineProperty(this, "handlers", {});
_defineProperty(this, "keyframesCount", 0);
_defineProperty(this, "handleAnimationName", function (ruleset, value) {
if (!value) {
return undefined;
}
return (Array.isArray(value) ? value : [value]).map(function (item) {
if (typeof item === 'string') {
return item;
}
var name = item.name || "keyframe-" + (_this.keyframesCount += 1);
_this.convertKeyframe(name, item, ruleset.root);
return name;
}).join(', ');
});
_defineProperty(this, "handleFontFamily", function (ruleset, value) {
if (!value) {
return undefined;
}
var output = new Set();
var fontFaces = {};
aestheticUtils.toArray(value).forEach(function (item) {
if (typeof item === 'string') {
output.add(item);
return;
}
var name = item.fontFamily;
if (!name) {
return;
}
output.add(name);
if (fontFaces[name]) {
fontFaces[name].push(item);
} else {
fontFaces[name] = [item];
}
});
Object.keys(fontFaces).forEach(function (fontFamily) {
_this.convertFontFaces(fontFamily, fontFaces[fontFamily], ruleset.root);
});
return Array.from(output).join(', ');
});
this.on('property:animationName', this.handleAnimationName);
this.on('property:fontFamily', this.handleFontFamily);
}
var _proto = UnifiedSyntax.prototype;
_proto.convertGlobalSheet = function convertGlobalSheet(globalSheet, options) {
var _this2 = this;
var sheet = new Sheet(options);
Object.keys(globalSheet).forEach(function (rule) {
switch (rule) {
case '@charset':
{
var _charset = globalSheet[rule];
if (typeof _charset === 'string') {
_this2.emit('charset', [sheet, _charset]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error('@charset must be a string.');
}
break;
}
case '@font-face':
{
var faces = globalSheet[rule] || {};
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(faces)) {
throw new Error('@font-face must be an object of font family names to font faces.');
}
}
Object.keys(faces).forEach(function (fontFamily) {
_this2.convertFontFaces(fontFamily, aestheticUtils.toArray(faces[fontFamily]), sheet);
});
break;
}
case '@global':
{
var globals = globalSheet[rule] || {};
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(globals)) {
throw new Error('@global must be an object of selectors to ruleset objects.');
}
}
Object.keys(globals).forEach(function (selector) {
if (aestheticUtils.isObject(globals[selector])) {
_this2.emit('global', [sheet, selector, _this2.convertRuleset(globals[selector], sheet.createRuleset(selector))]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error("@global \"" + selector + "\" must be a ruleset object.");
}
});
break;
}
case '@import':
{
var _paths = globalSheet[rule];
if (typeof _paths === 'string' || Array.isArray(_paths)) {
_this2.emit('import', [sheet, aestheticUtils.toArray(_paths).map(function (path) {
return String(path);
})]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error('@import must be a string or an array of strings.');
}
break;
}
case '@keyframes':
{
var frames = globalSheet[rule] || {};
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(frames)) {
throw new Error('@keyframes must be an object of animation names to keyframes.');
}
}
Object.keys(frames).forEach(function (animationName) {
_this2.convertKeyframe(animationName, frames[animationName], sheet);
});
break;
}
case '@page':
case '@viewport':
{
var style = globalSheet[rule];
if (aestheticUtils.isObject(style)) {
_this2.emit(rule.slice(1), [sheet, _this2.convertRuleset(style, sheet.createRuleset(rule))]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error(rule + " must be a ruleset object.");
}
break;
}
default:
{
if ("production" !== process.env.NODE_ENV) {
throw new Error("Unknown property \"" + rule + "\". Only at-rules are allowed in the global style sheet.");
}
}
}
});
return sheet;
};
_proto.convertStyleSheet = function convertStyleSheet(styleSheet, options) {
var _this3 = this;
var sheet = new Sheet(options);
Object.keys(styleSheet).forEach(function (selector) {
var ruleset = styleSheet[selector];
if (!ruleset) {
return;
}
if (selector.charAt(0) === '@') {
if ("production" !== process.env.NODE_ENV) {
throw new SyntaxError("At-rules may not be defined in the root, found \"" + selector + "\".");
}
} else if (typeof ruleset === 'string') {
if (ruleset.match(CLASS_NAME)) {
sheet.addClassName(selector, ruleset);
} else {
sheet.addClassName(selector, _this3.convertRawCss(sheet, selector, ruleset));
}
} else if (aestheticUtils.isObject(ruleset)) {
sheet.addRuleset(_this3.convertRuleset(ruleset, sheet.createRuleset(selector)));
} else if ("production" !== process.env.NODE_ENV) {
throw new Error("Invalid ruleset for \"" + selector + "\". Must be an object or class name.");
}
});
return sheet;
};
_proto.convertRawCss = function convertRawCss(sheet, selector, declaration) {
var styleName = sheet.options.name;
var className = styleName + "-" + selector;
var stylis = new Stylis({
compress: !("production" !== process.env.NODE_ENV),
global: false,
keyframe: true,
prefix: true
});
if (aestheticUtils.isRTL(sheet.options.dir)) {
stylis.use(rtlPlugin);
}
this.emit('css', [stylis("." + className, declaration.trim()), className]);
return className;
};
_proto.convertRuleset = function convertRuleset(unifiedRuleset, ruleset) {
var _this4 = this;
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(unifiedRuleset)) {
throw new TypeError('Ruleset must be an object of properties.');
}
}
var atRules = [];
Object.keys(unifiedRuleset).forEach(function (baseKey) {
var key = baseKey;
var value = unifiedRuleset[key];
if (typeof value === 'undefined') {
return;
}
if (key.startsWith('@')) {
atRules.push(key);
} else if (key.startsWith(':') || key.startsWith('[')) {
_this4.convertSelector(key, value, ruleset);
} else {
var newValue = _this4.emit("property:" + key, [ruleset, value]);
_this4.emit('property', [ruleset, key, newValue || value]);
}
});
atRules.forEach(function (key) {
switch (key) {
case '@fallbacks':
{
var fallbacks = unifiedRuleset[key] || {};
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(fallbacks)) {
throw new Error('@fallbacks must be an object of property names to fallback values.');
}
}
Object.keys(fallbacks).forEach(function (property) {
_this4.emit('fallback', [ruleset, property, aestheticUtils.toArray(fallbacks[property])]);
});
break;
}
case '@media':
case '@supports':
{
var styles = unifiedRuleset[key] || {};
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(styles)) {
throw new Error(key + " must be an object of queries to rulesets.");
}
}
Object.keys(styles).forEach(function (query) {
if (aestheticUtils.isObject(styles[query])) {
var event = key === '@media' ? 'media' : 'support';
_this4.emit(event, [ruleset, query, _this4.convertRuleset(styles[query], ruleset.createRuleset(key + " " + query))]);
} else if ("production" !== process.env.NODE_ENV) {
throw new Error(key + " " + query + " must be a mapping of conditions to style objects.");
}
});
break;
}
case '@selectors':
{
var selectors = unifiedRuleset[key] || {};
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(selectors)) {
throw new Error('@selectors must be an object of selectors to rulesets.');
}
}
Object.keys(selectors).forEach(function (selector) {
_this4.convertSelector(selector, selectors[selector], ruleset, true);
});
break;
}
default:
{
if ("production" !== process.env.NODE_ENV) {
throw new SyntaxError("Unsupported local at-rule \"" + key + "\".");
}
}
}
});
return ruleset;
};
_proto.convertSelector = function convertSelector(key, value, ruleset, inAtRule) {
var _this5 = this;
if (inAtRule === void 0) {
inAtRule = false;
}
if ("production" !== process.env.NODE_ENV) {
if (!aestheticUtils.isObject(value)) {
throw new Error("Selector \"" + key + "\" must be a ruleset object.");
} else if ((key.includes(',') || !key.match(SELECTOR)) && !inAtRule) {
throw new Error("Advanced selector \"" + key + "\" must be nested within an @selectors block.");
}
}
key.split(',').forEach(function (k) {
var selector = k.trim();
var type = 'selector';
if (selector.charAt(0) === ':') {
type = 'pseudo';
} else if (selector.charAt(0) === '[') {
type = 'attribute';
}
_this5.emit(type, [ruleset, selector, _this5.convertRuleset(value, ruleset.createRuleset(selector))]);
});
};
_proto.convertFontFaces = function convertFontFaces(fontFamily, faces, sheet) {
var _this6 = this;
var srcPaths = [];
var fontFaces = faces.map(function (font) {
srcPaths.push(font.srcPaths);
return _this6.convertRuleset(aestheticUtils.formatFontFace(_extends({}, font, {
fontFamily: fontFamily
})), sheet.createRuleset(fontFamily));
});
this.emit('font-face', [sheet, fontFaces, fontFamily, srcPaths]);
};
_proto.convertKeyframe = function convertKeyframe(animationName, frames, sheet) {
var _this7 = this;
var keyframe = sheet.createRuleset(animationName);
Object.keys(frames).forEach(function (key) {
var value = frames[key];
if (typeof value !== 'string' && typeof value !== 'undefined') {
keyframe.addNested(key, _this7.convertRuleset(value, keyframe.createRuleset(key)));
}
});
this.emit('keyframe', [sheet, keyframe, animationName]);
};
_proto.injectFontFaces = function injectFontFaces(value, cache) {
if (value === void 0) {
value = '';
}
if (cache === void 0) {
cache = {};
}
var fontFaces = [];
value.split(',').forEach(function (name) {
var familyName = name.trim();
var fonts = cache[familyName];
if (Array.isArray(fonts)) {
fontFaces.push.apply(fontFaces, fonts);
} else {
fontFaces.push(familyName);
}
});
return fontFaces;
};
_proto.injectKeyframes = function injectKeyframes(value, cache) {
if (value === void 0) {
value = '';
}
if (cache === void 0) {
cache = {};
}
return value.split(',').map(function (name) {
var animationName = name.trim();
return cache[animationName] || animationName;
});
};
_proto.emit = function emit(eventName, args) {
if (this.handlers[eventName]) {
var _this$handlers;
return (_this$handlers = this.handlers)[eventName].apply(_this$handlers, args);
}
return undefined;
};
_proto.off = function off(eventName) {
delete this.handlers[eventName];
return this;
};
_proto.on = function on(eventName, callback) {
this.handlers[eventName] = callback;
return this;
};
return UnifiedSyntax;
}();
var GLOBAL_STYLE_NAME = ':root';
var Adapter = function () {
function Adapter() {
_defineProperty(this, "aesthetic", void 0);
_defineProperty(this, "syntax", new UnifiedSyntax());
_defineProperty(this, "cacheManager", new CacheManager());
_defineProperty(this, "sheetManager", null);
}
var _proto = Adapter.prototype;
_proto.applyGlobalStyles = function applyGlobalStyles(baseOptions) {
if (typeof document !== 'undefined') {
document.documentElement.setAttribute('dir', this.aesthetic.options.rtl ? 'rtl' : 'ltr');
}
var options = this.prepareTransformOptions(_extends({}, baseOptions, {
global: true,
name: GLOBAL_STYLE_NAME
}));
var cacheOptions = _extends({}, options);
delete cacheOptions.dir;
var cache = this.cacheManager.get(GLOBAL_STYLE_NAME, cacheOptions);
var globalSheet = this.aesthetic.getGlobalSheet(options.theme);
if (cache || !globalSheet) {
return this;
}
var parsedSheet = this.cacheManager.set(GLOBAL_STYLE_NAME, this.parseStyleSheet(this.syntax.convertGlobalSheet(globalSheet, options).toObject(), options), cacheOptions);
this.transformStyles(Object.values(parsedSheet), options);
this.flushStyles(GLOBAL_STYLE_NAME);
return this;
};
_proto.createStyleSheet = function createStyleSheet(styleName, baseOptions) {
var options = this.prepareTransformOptions(baseOptions);
var cache = this.cacheManager.get(styleName, options);
if (cache) {
return cache;
}
this.applyGlobalStyles(baseOptions);
var nativeSheet = this.syntax.convertStyleSheet(this.aesthetic.getStyleSheet(styleName, options.theme), _extends({}, options, {
name: styleName
}));
var parsedSheet = this.parseStyleSheet(nativeSheet.toObject(), options);
return this.cacheManager.set(styleName, _extends({}, parsedSheet, {}, nativeSheet.classNames), options);
};
_proto.flushStyles = function flushStyles(styleName) {};
_proto.getCacheManager = function getCacheManager() {
return this.cacheManager;
};
_proto.getStyleSheetManager = function getStyleSheetManager() {
if (this.sheetManager) {
return this.sheetManager;
}
this.sheetManager = new StyleSheetManager();
return this.sheetManager;
};
_proto.isParsedBlock = function isParsedBlock(block) {
return aestheticUtils.isObject(block);
};
_proto.parseStyleSheet = function parseStyleSheet(styleSheet, options) {
return _extends({}, styleSheet);
};
_proto.purgeStyles = function purgeStyles() {};
_proto.resetGlobalStyles = function resetGlobalStyles(prevTheme) {
this.cacheManager.clear(function (unit) {
return unit.global === true && unit.theme === prevTheme;
});
this.purgeStyles();
return this;
};
_proto.transformStyles = function transformStyles(styles, baseOptions) {
var _this = this;
var options = this.prepareTransformOptions(baseOptions);
var classNames = [];
var nativeBlocks = [];
var parsedBlocks = [];
var inlineName = '';
styles.forEach(function (style) {
if (!style) {
return;
}
if (typeof style === 'string') {
classNames.push.apply(classNames, String(style).split(' ').map(function (s) {
return aestheticUtils.stripClassPrefix(s).trim();
}));
} else if (aestheticUtils.isObject(style)) {
if (_this.isParsedBlock(style)) {
parsedBlocks.push(style);
} else {
nativeBlocks.push(style);
}
} else if ("production" !== process.env.NODE_ENV) {
throw new Error('Unsupported style type to transform.');
}
});
if (nativeBlocks.length > 0) {
var nativeSheet = new Sheet(options);
var counter = 0;
inlineName = uuid();
nativeBlocks.forEach(function (block) {
nativeSheet.addRuleset(nativeSheet.createRuleset("inline-" + counter).addProperties(block));
counter += 1;
});
parsedBlocks.push.apply(parsedBlocks, Object.values(this.parseStyleSheet(nativeSheet.toObject(), options)));
}
if (parsedBlocks.length > 0) {
classNames.push(this.transformToClassName(parsedBlocks));
}
if (inlineName) {
this.flushStyles(inlineName);
}
return classNames.join(' ').trim();
};
_proto.prepareTransformOptions = function prepareTransformOptions(options) {
if (options === void 0) {
options = {};
}
var dir = this.aesthetic.options.rtl ? 'rtl' : 'ltr';
return {
dir: options.dir || dir,
global: options.global || false,
name: options.name || '',
theme: options.theme || this.aesthetic.options.theme
};
};
return Adapter;
}();
var TestAdapter = function (_Adapter) {
_inheritsLoose(TestAdapter, _Adapter);
function TestAdapter() {
return _Adapter.apply(this, arguments) || this;
}
var _proto = TestAdapter.prototype;
_proto.isParsedBlock = function isParsedBlock(block) {
return typeof block === 'string';
};
_proto.parseStyleSheet = function parseStyleSheet(styleSheet) {
return Object.keys(styleSheet).reduce(function (obj, key) {
var _extends2;
return _extends({}, obj, (_extends2 = {}, _extends2[key] = key, _extends2));
}, {});
};
_proto.transformToClassName = function transformToClassName(styles) {
return styles.filter(function (style) {
return style && typeof style === 'string';
}).join(' ');
};
return TestAdapter;
}(Adapter);
function setupAesthetic(aesthetic, adapter) {
aesthetic.configure({
adapter: adapter || new _TestAdapter.default()
adapter: adapter || new TestAdapter()
});

@@ -53,17 +972,13 @@ aesthetic.registerTheme('default', {

}
function teardownAesthetic(aesthetic) {
aesthetic.resetForTesting();
}
function cleanupStyleElements() {
(0, _aestheticUtils.getStyleElements)().forEach(function (style) {
aestheticUtils.getStyleElements().forEach(function (style) {
style.remove();
});
}
function getFlushedStyles(namespace) {
return (0, _aestheticUtils.getFlushedStyles)((0, _aestheticUtils.getStyleElements)(namespace));
return aestheticUtils.getFlushedStyles(aestheticUtils.getStyleElements(namespace));
}
function convertDirection(value, dir) {

@@ -80,3 +995,3 @@ if (dir !== 'rtl') {

if (!(0, _aestheticUtils.isObject)(value)) {
if (!aestheticUtils.isObject(value)) {
return value;

@@ -90,3 +1005,3 @@ }

if ((0, _aestheticUtils.isObject)(prop) || Array.isArray(prop)) {
if (aestheticUtils.isObject(prop) || Array.isArray(prop)) {
nested[key] = convertDirection(prop, dir);

@@ -97,5 +1012,4 @@ } else {

});
return _extends({}, (0, _rtlCssJs.default)(props), {}, nested);
return _extends({}, convertRTL(props), {}, nested);
}
function renderAndExpect(adapter, styleSheet, expectedStyles, _ref2) {

@@ -105,3 +1019,3 @@ var dir = _ref2.dir,

global = _ref2$global === void 0 ? false : _ref2$global;
var name = global ? _constants.GLOBAL_STYLE_NAME : adapter.constructor.name.replace('Adapter', '').toLowerCase();
var name = global ? GLOBAL_STYLE_NAME : adapter.constructor.name.replace('Adapter', '').toLowerCase();
var options = {

@@ -124,3 +1038,2 @@ name: name,

}
var TEST_CLASS_NAMES = {

@@ -130,3 +1043,2 @@ footer: '.footer',

};
exports.TEST_CLASS_NAMES = TEST_CLASS_NAMES;
var TEST_STATEMENT = {

@@ -140,5 +1052,3 @@ footer: {

};
exports.TEST_STATEMENT = TEST_STATEMENT;
var DIRECTIONS = ['ltr', 'rtl'];
exports.DIRECTIONS = DIRECTIONS;
var FONT_ROBOTO = {

@@ -151,3 +1061,2 @@ fontFamily: 'Roboto',

};
exports.FONT_ROBOTO = FONT_ROBOTO;
var FONT_ROBOTO_FLAT_SRC = {

@@ -159,3 +1068,2 @@ fontFamily: 'Roboto',

};
exports.FONT_ROBOTO_FLAT_SRC = FONT_ROBOTO_FLAT_SRC;
var FONT_CIRCULAR_MULTIPLE = [{

@@ -182,3 +1090,2 @@ fontFamily: 'Circular',

}];
exports.FONT_CIRCULAR_MULTIPLE = FONT_CIRCULAR_MULTIPLE;
var FONT_CIRCULAR_MULTIPLE_FLAT_SRC = [{

@@ -205,3 +1112,2 @@ fontFamily: 'Circular',

}];
exports.FONT_CIRCULAR_MULTIPLE_FLAT_SRC = FONT_CIRCULAR_MULTIPLE_FLAT_SRC;
var KEYFRAME_FADE = {

@@ -215,3 +1121,2 @@ from: {

};
exports.KEYFRAME_FADE = KEYFRAME_FADE;
var KEYFRAME_SLIDE_PERCENT = {

@@ -228,3 +1133,2 @@ '0%': {

};
exports.KEYFRAME_SLIDE_PERCENT = KEYFRAME_SLIDE_PERCENT;
var SYNTAX_UNIFIED_LOCAL = {

@@ -261,3 +1165,2 @@ button: {

};
exports.SYNTAX_UNIFIED_LOCAL = SYNTAX_UNIFIED_LOCAL;
var SYNTAX_UNIFIED_GLOBAL_FULL = {

@@ -271,3 +1174,2 @@ '@font-face': {

};
exports.SYNTAX_UNIFIED_GLOBAL_FULL = SYNTAX_UNIFIED_GLOBAL_FULL;
var SYNTAX_UNIFIED_LOCAL_FULL = {

@@ -282,3 +1184,2 @@ button: _extends({}, SYNTAX_UNIFIED_LOCAL.button, {

};
exports.SYNTAX_UNIFIED_LOCAL_FULL = SYNTAX_UNIFIED_LOCAL_FULL;
var SYNTAX_ATTRIBUTE = {

@@ -292,7 +1193,5 @@ attr: {

};
exports.SYNTAX_ATTRIBUTE = SYNTAX_ATTRIBUTE;
var SYNTAX_CHARSET = {
'@charset': 'utf8'
};
exports.SYNTAX_CHARSET = SYNTAX_CHARSET;
var SYNTAX_DESCENDANT = {

@@ -309,11 +1208,8 @@ list: {

};
exports.SYNTAX_DESCENDANT = SYNTAX_DESCENDANT;
var SYNTAX_IMPORT = {
'@import': 'url("./some/path.css")'
};
exports.SYNTAX_IMPORT = SYNTAX_IMPORT;
var SYNTAX_IMPORT_MULTIPLE = {
'@import': ['url("./some/path.css")', 'url("./another/path.css")']
};
exports.SYNTAX_IMPORT_MULTIPLE = SYNTAX_IMPORT_MULTIPLE;
var SYNTAX_FALLBACKS = {

@@ -330,3 +1226,2 @@ fallback: {

};
exports.SYNTAX_FALLBACKS = SYNTAX_FALLBACKS;
var SYNTAX_FONT_FACE = {

@@ -337,3 +1232,2 @@ '@font-face': {

};
exports.SYNTAX_FONT_FACE = SYNTAX_FONT_FACE;
var SYNTAX_FONT_FACE_MULTIPLE = {

@@ -344,3 +1238,2 @@ '@font-face': {

};
exports.SYNTAX_FONT_FACE_MULTIPLE = SYNTAX_FONT_FACE_MULTIPLE;
var SYNTAX_FONT_FACE_MIXED = {

@@ -352,3 +1245,2 @@ '@font-face': {

};
exports.SYNTAX_FONT_FACE_MIXED = SYNTAX_FONT_FACE_MIXED;
var SYNTAX_FONT_FACES_INLINE = {

@@ -362,3 +1254,2 @@ single: {

};
exports.SYNTAX_FONT_FACES_INLINE = SYNTAX_FONT_FACES_INLINE;
var SYNTAX_GLOBAL = {

@@ -398,3 +1289,2 @@ '@global': {

};
exports.SYNTAX_GLOBAL = SYNTAX_GLOBAL;
var SYNTAX_KEYFRAMES = {

@@ -405,3 +1295,2 @@ '@keyframes': {

};
exports.SYNTAX_KEYFRAMES = SYNTAX_KEYFRAMES;
var SYNTAX_KEYFRAMES_PERCENT = {

@@ -412,3 +1301,2 @@ '@keyframes': {

};
exports.SYNTAX_KEYFRAMES_PERCENT = SYNTAX_KEYFRAMES_PERCENT;
var SYNTAX_KEYFRAMES_MIXED = {

@@ -420,3 +1308,2 @@ '@keyframes': {

};
exports.SYNTAX_KEYFRAMES_MIXED = SYNTAX_KEYFRAMES_MIXED;
var SYNTAX_KEYFRAMES_INLINE = {

@@ -434,3 +1321,2 @@ single: {

};
exports.SYNTAX_KEYFRAMES_INLINE = SYNTAX_KEYFRAMES_INLINE;
var SYNTAX_MEDIA_QUERY = {

@@ -452,3 +1338,2 @@ media: {

};
exports.SYNTAX_MEDIA_QUERY = SYNTAX_MEDIA_QUERY;
var SYNTAX_MEDIA_QUERY_NESTED = {

@@ -469,3 +1354,2 @@ media: {

};
exports.SYNTAX_MEDIA_QUERY_NESTED = SYNTAX_MEDIA_QUERY_NESTED;
var SYNTAX_MULTI_SELECTOR = {

@@ -481,7 +1365,5 @@ multi: {

};
exports.SYNTAX_MULTI_SELECTOR = SYNTAX_MULTI_SELECTOR;
var SYNTAX_NAMESPACE = {
'@namespace': 'url(http://www.w3.org/1999/xhtml)'
};
exports.SYNTAX_NAMESPACE = SYNTAX_NAMESPACE;
var SYNTAX_PAGE = {

@@ -495,3 +1377,2 @@ '@page': {

};
exports.SYNTAX_PAGE = SYNTAX_PAGE;
var SYNTAX_PROPERTIES = {

@@ -505,3 +1386,2 @@ props: {

};
exports.SYNTAX_PROPERTIES = SYNTAX_PROPERTIES;
var SYNTAX_PSEUDO = {

@@ -518,3 +1398,2 @@ pseudo: {

};
exports.SYNTAX_PSEUDO = SYNTAX_PSEUDO;
var SYNTAX_SUPPORTS = {

@@ -533,3 +1412,2 @@ sup: {

};
exports.SYNTAX_SUPPORTS = SYNTAX_SUPPORTS;
var SYNTAX_VIEWPORT = {

@@ -541,6 +1419,49 @@ '@viewport': {

};
exports.SYNTAX_VIEWPORT = SYNTAX_VIEWPORT;
var SYNTAX_RAW_CSS = {
button: "\n display: 'block';\n font-size: 16px;\n text-align: 'left';\n\n &:hover {\n color: 'red';\n }\n\n & {\n vertical-align: 'middle';\n }\n\n @media (max-width: 600px) {\n display: 'none';\n }\n\n @supports (display: flex) {\n display: 'flex';\n }\n "
};
exports.SYNTAX_RAW_CSS = SYNTAX_RAW_CSS;
exports.DIRECTIONS = DIRECTIONS;
exports.FONT_CIRCULAR_MULTIPLE = FONT_CIRCULAR_MULTIPLE;
exports.FONT_CIRCULAR_MULTIPLE_FLAT_SRC = FONT_CIRCULAR_MULTIPLE_FLAT_SRC;
exports.FONT_ROBOTO = FONT_ROBOTO;
exports.FONT_ROBOTO_FLAT_SRC = FONT_ROBOTO_FLAT_SRC;
exports.KEYFRAME_FADE = KEYFRAME_FADE;
exports.KEYFRAME_SLIDE_PERCENT = KEYFRAME_SLIDE_PERCENT;
exports.SYNTAX_ATTRIBUTE = SYNTAX_ATTRIBUTE;
exports.SYNTAX_CHARSET = SYNTAX_CHARSET;
exports.SYNTAX_DESCENDANT = SYNTAX_DESCENDANT;
exports.SYNTAX_FALLBACKS = SYNTAX_FALLBACKS;
exports.SYNTAX_FONT_FACE = SYNTAX_FONT_FACE;
exports.SYNTAX_FONT_FACES_INLINE = SYNTAX_FONT_FACES_INLINE;
exports.SYNTAX_FONT_FACE_MIXED = SYNTAX_FONT_FACE_MIXED;
exports.SYNTAX_FONT_FACE_MULTIPLE = SYNTAX_FONT_FACE_MULTIPLE;
exports.SYNTAX_GLOBAL = SYNTAX_GLOBAL;
exports.SYNTAX_IMPORT = SYNTAX_IMPORT;
exports.SYNTAX_IMPORT_MULTIPLE = SYNTAX_IMPORT_MULTIPLE;
exports.SYNTAX_KEYFRAMES = SYNTAX_KEYFRAMES;
exports.SYNTAX_KEYFRAMES_INLINE = SYNTAX_KEYFRAMES_INLINE;
exports.SYNTAX_KEYFRAMES_MIXED = SYNTAX_KEYFRAMES_MIXED;
exports.SYNTAX_KEYFRAMES_PERCENT = SYNTAX_KEYFRAMES_PERCENT;
exports.SYNTAX_MEDIA_QUERY = SYNTAX_MEDIA_QUERY;
exports.SYNTAX_MEDIA_QUERY_NESTED = SYNTAX_MEDIA_QUERY_NESTED;
exports.SYNTAX_MULTI_SELECTOR = SYNTAX_MULTI_SELECTOR;
exports.SYNTAX_NAMESPACE = SYNTAX_NAMESPACE;
exports.SYNTAX_PAGE = SYNTAX_PAGE;
exports.SYNTAX_PROPERTIES = SYNTAX_PROPERTIES;
exports.SYNTAX_PSEUDO = SYNTAX_PSEUDO;
exports.SYNTAX_RAW_CSS = SYNTAX_RAW_CSS;
exports.SYNTAX_SUPPORTS = SYNTAX_SUPPORTS;
exports.SYNTAX_UNIFIED_GLOBAL_FULL = SYNTAX_UNIFIED_GLOBAL_FULL;
exports.SYNTAX_UNIFIED_LOCAL = SYNTAX_UNIFIED_LOCAL;
exports.SYNTAX_UNIFIED_LOCAL_FULL = SYNTAX_UNIFIED_LOCAL_FULL;
exports.SYNTAX_VIEWPORT = SYNTAX_VIEWPORT;
exports.TEST_CLASS_NAMES = TEST_CLASS_NAMES;
exports.TEST_STATEMENT = TEST_STATEMENT;
exports.TestAdapter = TestAdapter;
exports.cleanupStyleElements = cleanupStyleElements;
exports.convertDirection = convertDirection;
exports.getFlushedStyles = getFlushedStyles;
exports.renderAndExpect = renderAndExpect;
exports.setupAesthetic = setupAesthetic;
exports.teardownAesthetic = teardownAesthetic;

6

package.json
{
"name": "aesthetic",
"version": "5.0.1",
"version": "5.1.0",
"description": "Aesthetic is a powerful type-safe, framework agnostic, CSS-in-JS library for styling components through the use of adapters.",

@@ -35,3 +35,3 @@ "keywords": [

"stylis": "^3.5.4",
"uuid": "^3.3.3"
"uuid": "^3.4.0"
},

@@ -42,3 +42,3 @@ "funding": {

},
"gitHead": "55fcac7d6a93ec62194dc2b9024ed54ce0170d42"
"gitHead": "cd4f3bc37d9f34ba5ff1a7e015a2a4fe33e726dd"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc