Comparing version 1.0.0-alpha.5 to 4.1.0
@@ -11,29 +11,20 @@ (function (global, factory) { | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
babelHelpers.classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
babelHelpers.defineProperty = function (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; | ||
}; | ||
babelHelpers.createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
babelHelpers.extends = Object.assign || function (target) { | ||
@@ -53,573 +44,71 @@ for (var i = 1; i < arguments.length; i++) { | ||
babelHelpers.inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
babelHelpers.possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
babelHelpers; | ||
/* weak */ | ||
var RULE_TYPE = 1; | ||
function __commonjs(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } | ||
/** | ||
* converts camel cased to dash cased properties | ||
* | ||
* @param {string} property - camel cased CSS property | ||
* @returns {string} dash cased CSS property | ||
*/ | ||
function camelToDashCase(property) { | ||
return property.replace(/([a-z]|^)([A-Z])/g, function (match, p1, p2) { | ||
return p1 + '-' + p2.toLowerCase(); | ||
}).replace('ms-', '-ms-'); | ||
} | ||
/** | ||
* generates a valid CSS string containing styles | ||
* | ||
* @param {Object} styles - object containing CSS declarations | ||
* @returns {string} valid CSS string with dash cased properties | ||
*/ | ||
function cssifyObject(styles) { | ||
return Object.keys(styles).reduce(function (css, prop) { | ||
// prevents the semicolon after | ||
// the last rule declaration | ||
if (css.length > 0) { | ||
css += ';'; | ||
function createDOMInterface(renderer, node) { | ||
return function (change) { | ||
// only use insertRule in production as browser devtools might have | ||
// weird behavior if used together with insertRule at runtime | ||
if (false && change.type === RULE_TYPE && !change.media) {} else { | ||
node.textContent = renderer.renderToString(); | ||
} | ||
css += camelToDashCase(prop) + ':' + styles[prop]; | ||
return css; | ||
}, ''); | ||
}; | ||
} | ||
/** | ||
* generates a hashcode from a string | ||
* taken from http://stackoverflow.com/a/7616484 | ||
* | ||
* @param {string} str - str used to generate the unique hash code | ||
* @return {string} compressed content hash | ||
*/ | ||
function generateHash(str) { | ||
var hash = 0; | ||
var iterator = 0; | ||
var char = void 0; | ||
var length = str.length; | ||
/* weak */ | ||
var warning = function warning() { | ||
return true; | ||
}; | ||
// return a `s` for empty strings | ||
// to symbolize `static` | ||
if (length === 0) { | ||
return 's'; | ||
} | ||
for (; iterator < length; ++iterator) { | ||
char = str.charCodeAt(iterator); | ||
hash = (hash << 5) - hash + char; | ||
hash |= 0; | ||
} | ||
return hash.toString(36); | ||
if (true) { | ||
warning = function warning(condition, message) { | ||
if (!condition) { | ||
if (typeof console !== 'undefined') { | ||
console.error(message); // eslint-disable-line | ||
} | ||
} | ||
}; | ||
} | ||
/** | ||
* stringifies an object without any special character | ||
* uses a sort version of the obj to get same hash codes | ||
* | ||
* @param {Object} obj - obj that gets stringified | ||
* @return {string} stringyfied sorted object | ||
*/ | ||
function sortedStringify(obj) { | ||
if (obj === undefined) { | ||
return ''; | ||
} | ||
var warning$1 = warning; | ||
return Object.keys(obj).sort().reduce(function (str, prop) { | ||
// only concatenate property and value | ||
// without any special characters | ||
str += prop + obj[prop]; | ||
return str; | ||
}, ''); | ||
function isValidHTMLElement(mountNode) { | ||
return mountNode && mountNode.nodeType === 1; | ||
} | ||
var StyleSheet = function () { | ||
/** | ||
* StyleSheet is a low-level Selector container | ||
*/ | ||
function StyleSheet() { | ||
babelHelpers.classCallCheck(this, StyleSheet); | ||
this.listeners = new Set(); | ||
this._init(); | ||
function render(renderer, mountNode) { | ||
// mountNode must be a valid HTML element to be able | ||
// to set mountNode.textContent later on | ||
if (!isValidHTMLElement(mountNode)) { | ||
throw new Error('You need to specify a valid element node (nodeType = 1) to render into.'); | ||
} | ||
/** | ||
* clears the sheet's cache but keeps all listeners | ||
*/ | ||
// warns if the DOM node either is not a valid <style> element thus the styles do not get applied as Expected | ||
// or if the node already got the data-fela-stylesheet attribute applied suggesting it is already used by another Renderer | ||
warning$1(mountNode.nodeName === 'STYLE', 'You are using a node other than `<style>`. Your styles might not get applied correctly.'); | ||
warning$1(!mountNode.hasAttribute('data-fela-stylesheet'), 'This node is already used by another renderer. Rendering might overwrite other styles.'); | ||
// mark and clean the DOM node to prevent side-effects | ||
mountNode.setAttribute('data-fela-stylesheet', ''); | ||
babelHelpers.createClass(StyleSheet, [{ | ||
key: 'clear', | ||
value: function clear() { | ||
this._init(); | ||
} | ||
var updateNode = createDOMInterface(renderer, mountNode); | ||
renderer.subscribe(updateNode); | ||
/** | ||
* renders all cached selector styles into a single valid CSS string | ||
* clusters media query styles into groups to reduce output size | ||
*/ | ||
var css = renderer.renderToString(); | ||
}, { | ||
key: 'renderToString', | ||
value: function renderToString() { | ||
var _this = this; | ||
var css = this._renderCache(this.cache); | ||
this.mediaCache.forEach(function (cache, media) { | ||
css += _this._renderMediaQuery(media, _this._renderCache(cache)); | ||
}); | ||
return css; | ||
} | ||
/** | ||
* Adds a new subscription to get notified on every rerender | ||
* | ||
* @param {Function} callback - callback function which will be executed | ||
* @return {Object} equivalent unsubscribe method | ||
*/ | ||
}, { | ||
key: 'subscribe', | ||
value: function subscribe(callback) { | ||
var _this2 = this; | ||
this.listeners.add(callback); | ||
return { | ||
unsubscribe: function unsubscribe() { | ||
return _this2.listeners.delete(callback); | ||
} | ||
}; | ||
} | ||
/** | ||
* calls each listener with the current CSS markup of all caches | ||
* gets only called if the markup actually changes | ||
* | ||
* @param {Function} callback - callback function which will be executed | ||
* @return {Object} equivalent unsubscribe method | ||
*/ | ||
}, { | ||
key: '_emitChange', | ||
value: function _emitChange() { | ||
var css = this.renderToString(); | ||
this.listeners.forEach(function (listener) { | ||
return listener(css); | ||
}); | ||
} | ||
/** | ||
* initializes the stylesheet by setting up the caches | ||
*/ | ||
}, { | ||
key: '_init', | ||
value: function _init() { | ||
this.cache = new Map(); | ||
this.mediaCache = new Map(); | ||
this.ids = new Map(); | ||
this._counter = -1; | ||
} | ||
/** | ||
* renders a new selector variation and caches the result | ||
* | ||
* @param {Selector|Function} selector - Selector which gets rendered | ||
* @param {Object?} props - properties used to render | ||
* @param {Function[]?} plugins - array of plugins to process styles | ||
* @return {string} className to reference the rendered selector | ||
*/ | ||
}, { | ||
key: '_renderSelectorVariation', | ||
value: function _renderSelectorVariation(selector) { | ||
var _this3 = this; | ||
var props = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var plugins = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; | ||
var isFunctionalSelector = selector instanceof Function; | ||
var isMediaSelector = !isFunctionalSelector && selector.renderMedia instanceof Function; | ||
// rendering a Selector for the first time | ||
// will create cache entries and an ID reference | ||
if (!this.cache.has(selector)) { | ||
this.ids.set(selector, ++this._counter); | ||
this.cache.set(selector, new Map()); | ||
// iterate all used media strings to create | ||
// selector caches for each media as well | ||
if (isMediaSelector) { | ||
selector.mediaStrings.forEach(function (media) { | ||
if (!_this3.mediaCache.has(media)) { | ||
_this3.mediaCache.set(media, new Map()); | ||
} | ||
_this3.mediaCache.get(media).set(selector, new Map()); | ||
}); | ||
} | ||
} | ||
var cachedSelector = this.cache.get(selector); | ||
var propsReference = this._generatePropsReference(props); | ||
// uses the reference ID and the props to generate an unique className | ||
var className = this._renderClassName(this.ids.get(selector), propsReference); | ||
// only if the cached selector has not already been rendered | ||
// with a specific set of properties it actually renders | ||
if (!cachedSelector.has(propsReference)) { | ||
(function () { | ||
// get the render method of either class-like selectors | ||
// or pure functional selectors without a constructor | ||
var pluginInterface = { | ||
plugins: plugins, | ||
processStyles: _this3._processStyles, | ||
styles: isFunctionalSelector ? selector(props) : selector.render(props), | ||
className: className, | ||
props: props | ||
}; | ||
cachedSelector.set(propsReference, _this3._processStyles(pluginInterface)); | ||
if (isMediaSelector) { | ||
selector.mediaStrings.forEach(function (media) { | ||
pluginInterface.styles = selector.renderMedia(props, media); | ||
pluginInterface.media = media; | ||
var processedStyles = _this3._processStyles(pluginInterface); | ||
_this3.mediaCache.get(media).get(selector).set(propsReference, processedStyles); | ||
}); | ||
} | ||
// emit changes as the styles stack changed | ||
_this3._emitChange(); | ||
})(); | ||
} | ||
return className; | ||
} | ||
/** | ||
* executes each plugin using a predefined plugin interface | ||
* | ||
* @param {Object} pluginInterface - interface containing relevant processing data | ||
* @return {Object} processed and validated styles | ||
*/ | ||
}, { | ||
key: '_processStyles', | ||
value: function _processStyles(pluginInterface) { | ||
var plugins = pluginInterface.plugins; | ||
var styles = pluginInterface.styles; | ||
// pipes each plugin by passes the plugin interface | ||
// NOTE: as the styles are passed directly they're editable | ||
// therefore the plugin order might matter | ||
plugins.forEach(function (plugin) { | ||
return plugin(pluginInterface); | ||
}); | ||
return styles; | ||
} | ||
/** | ||
* generates an unique reference id by content hashing props | ||
* | ||
* @param {Object} props - props that get hashed | ||
* @return {string} reference - unique props reference | ||
*/ | ||
}, { | ||
key: '_generatePropsReference', | ||
value: function _generatePropsReference(props) { | ||
return generateHash(sortedStringify(props)); | ||
} | ||
/** | ||
* generates an unique className using a Selectors reference ID | ||
* as well as a content hash of the passed props | ||
* | ||
* @param {number} id - Selectors reference ID stored within the stylesheet | ||
* @param {strng} reference - generated props reference | ||
* @return {string} className - unique className reference | ||
*/ | ||
}, { | ||
key: '_renderClassName', | ||
value: function _renderClassName(id, reference) { | ||
return 'c' + id + '-' + reference; | ||
} | ||
}, { | ||
key: '_splitPseudoClasses', | ||
value: function _splitPseudoClasses(styles) { | ||
var _this4 = this; | ||
var pseudo = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1]; | ||
var out = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
Object.keys(styles).forEach(function (property) { | ||
var value = styles[property]; | ||
if (value instanceof Object) { | ||
_this4._splitPseudoClasses(value, pseudo + property, out); | ||
} else { | ||
if (!out[pseudo]) { | ||
out[pseudo] = {}; | ||
} | ||
out[pseudo][property] = value; | ||
} | ||
}); | ||
return out; | ||
} | ||
/** | ||
* renders a single ruleset into a CSS string | ||
* | ||
* @param {string} className - rendered selector | ||
* @param {Object} styles - style declarations | ||
* @return {string} valid selector CSS string | ||
*/ | ||
}, { | ||
key: '_renderSelector', | ||
value: function _renderSelector(className, styles) { | ||
return '.' + className + '{' + cssifyObject(styles) + '}'; | ||
} | ||
/** | ||
* renders a set of media styles into a CSS string | ||
* | ||
* @param {string} media - media string | ||
* @param {string} selectors - CSS string of all selectors | ||
* @return {string} valid media query CSS string | ||
*/ | ||
}, { | ||
key: '_renderMediaQuery', | ||
value: function _renderMediaQuery(media, selectors) { | ||
return '@media(' + media + '){' + selectors + '}'; | ||
} | ||
/** | ||
* renders a whole cache into a CSS string | ||
* clusters media queries into single @media groups | ||
* | ||
* @param {Map} cache - cache including styles and media styles | ||
* @return {string} valid CSS string | ||
*/ | ||
}, { | ||
key: '_renderCache', | ||
value: function _renderCache(cache) { | ||
var _this5 = this; | ||
var css = ''; | ||
cache.forEach(function (variation, selector) { | ||
var id = _this5.ids.get(selector); | ||
variation.forEach(function (styles, propsReference) { | ||
var className = _this5._renderClassName(id, propsReference); | ||
var splitPseudos = _this5._splitPseudoClasses(styles); | ||
Object.keys(splitPseudos).forEach(function (pseudo) { | ||
css += _this5._renderSelector(className + pseudo, splitPseudos[pseudo]); | ||
}); | ||
}); | ||
}); | ||
return css; | ||
} | ||
}]); | ||
return StyleSheet; | ||
}(); | ||
var NODE_TYPE = 1; | ||
var NODE_NAME = 'STYLE'; | ||
var Renderer = function () { | ||
function Renderer(node) { | ||
var _this = this; | ||
babelHelpers.classCallCheck(this, Renderer); | ||
// Check if the passed node is a valid element node which allows | ||
// setting the `textContent` property to update the node's content | ||
if (node.nodeType !== NODE_TYPE || node.textContent === undefined) { | ||
console.error('You need to specify a valid element node (nodeType = 1) to render into.'); // eslint-disable-line | ||
return false; | ||
} | ||
// TODO: DEV-MODE | ||
// In dev-mode we should allow using elements other than <style> as | ||
// one might want to render the CSS markup into a visible node to be able to | ||
// validate and observe the styles on runtime | ||
if (node.nodeName !== NODE_NAME) { | ||
console.warn('You are using a node other than `<style>`. Your styles might not get applied correctly.'); // eslint-disable-line | ||
} | ||
if (node.hasAttribute('data-fela-stylesheet')) { | ||
console.warn('This node is already used by another renderer. Rendering might overwrite other styles.'); // eslint-disable-line | ||
} | ||
node.setAttribute('data-fela-stylesheet', ''); | ||
this.node = node; | ||
this.stylesheet = new StyleSheet(); | ||
this.stylesheet.subscribe(function (css) { | ||
return _this.node.textContent = css; | ||
}); | ||
if (mountNode.textContent !== css) { | ||
// render currently rendered styles to the DOM once | ||
mountNode.textContent = css; | ||
} | ||
/** | ||
* renders a Selector variation of props into a DOM node | ||
* | ||
* @param {Selector} selector - Selector instance that is rendered | ||
* @param {Object?} props - list of props to render | ||
* @param {Function[]?} plugins - array of plugins to process styles | ||
* @return {string} className reference of the rendered selector | ||
*/ | ||
} | ||
var index = { | ||
render: render | ||
}; | ||
babelHelpers.createClass(Renderer, [{ | ||
key: 'render', | ||
value: function render(selector, props, plugins) { | ||
// renders the passed selector variation into the stylesheet which | ||
// adds the variation to the cache and updates the DOM automatically | ||
// if the variation has already been added it will do nothing but return | ||
// the cached className to reference the mounted CSS selector | ||
return this.stylesheet._renderSelectorVariation(selector, props, plugins); | ||
} | ||
return index; | ||
/** | ||
* clears the stylesheet associated with a DOM node | ||
*/ | ||
}, { | ||
key: 'clear', | ||
value: function clear() { | ||
this.stylesheet.clear(); | ||
this.node.textContent = ''; | ||
} | ||
}]); | ||
return Renderer; | ||
}(); | ||
var Selector = function () { | ||
/** | ||
* Selector is a dynamic style container | ||
* | ||
* @param {Function} composer - values to resolve dynamic styles | ||
*/ | ||
function Selector(composer) { | ||
babelHelpers.classCallCheck(this, Selector); | ||
this.composer = composer; | ||
} | ||
/** | ||
* resolves the styles with given set of props | ||
* | ||
* @param {Object?} props - values to resolve dynamic styles | ||
* @return {Object} rendered styles | ||
*/ | ||
babelHelpers.createClass(Selector, [{ | ||
key: "render", | ||
value: function render() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
return this.composer(props); | ||
} | ||
}]); | ||
return Selector; | ||
}(); | ||
var MediaSelector = function (_Selector) { | ||
babelHelpers.inherits(MediaSelector, _Selector); | ||
/** | ||
* MediaSelector is an enhanced Selector providing | ||
* support for media query | ||
* | ||
* @param {Function} composer - values to resolve dynamic styles | ||
* @param {Object} mediaComposer - set of additional media composer | ||
*/ | ||
function MediaSelector(composer) { | ||
var mediaComposer = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
babelHelpers.classCallCheck(this, MediaSelector); | ||
var _this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(MediaSelector).call(this, composer)); | ||
_this.mediaComposer = mediaComposer; | ||
// safe media strings to iterate later on | ||
_this.mediaStrings = Object.keys(mediaComposer); | ||
if (Object.keys(mediaComposer).length === 0) { | ||
console.warn('You are using a MediaSelector without specifying at least one media style composer. Prefer using basic Selectors instead.'); // eslint-disable-line | ||
} | ||
return _this; | ||
} | ||
/** | ||
* resolves media styles with given set of props | ||
* | ||
* @param {Object?} props - values to resolve dynamic styles | ||
* @param {string?} media - media environment to render | ||
* @return {Object} rendered styles | ||
*/ | ||
babelHelpers.createClass(MediaSelector, [{ | ||
key: 'renderMedia', | ||
value: function renderMedia() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var media = arguments[1]; | ||
// renders styles by resolving and processing them | ||
var composer = this.mediaComposer[media]; | ||
return composer(props); | ||
} | ||
}]); | ||
return MediaSelector; | ||
}(Selector); | ||
var felaDOM = { Renderer: Renderer, MediaSelector: MediaSelector }; | ||
return felaDOM; | ||
})); | ||
//# sourceMappingURL=fela-dom.js.map |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.FelaDOM=t()}(this,function(){"use strict";function e(e){return e.replace(/([a-z]|^)([A-Z])/g,function(e,t,n){return t+"-"+n.toLowerCase()}).replace("ms-","-ms-")}function t(t){return Object.keys(t).reduce(function(n,r){return n.length>0&&(n+=";"),n+=e(r)+":"+t[r]},"")}function n(e){var t=0,n=0,r=void 0,o=e.length;if(0===o)return"s";for(;o>n;++n)r=e.charCodeAt(n),t=(t<<5)-t+r,t|=0;return t.toString(36)}function r(e){return void 0===e?"":Object.keys(e).sort().reduce(function(t,n){return t+=n+e[n]},"")}var o={};o["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},o.classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},o.createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o["extends"]=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},o.inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},o.possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t};var s=function(){function e(){o.classCallCheck(this,e),this.listeners=new Set,this._init()}return o.createClass(e,[{key:"clear",value:function(){this._init()}},{key:"renderToString",value:function(){var e=this,t=this._renderCache(this.cache);return this.mediaCache.forEach(function(n,r){t+=e._renderMediaQuery(r,e._renderCache(n))}),t}},{key:"subscribe",value:function(e){var t=this;return this.listeners.add(e),{unsubscribe:function(){return t.listeners["delete"](e)}}}},{key:"_emitChange",value:function(){var e=this.renderToString();this.listeners.forEach(function(t){return t(e)})}},{key:"_init",value:function(){this.cache=new Map,this.mediaCache=new Map,this.ids=new Map,this._counter=-1}},{key:"_renderSelectorVariation",value:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=arguments.length<=2||void 0===arguments[2]?[]:arguments[2],o=e instanceof Function,s=!o&&e.renderMedia instanceof Function;this.cache.has(e)||(this.ids.set(e,++this._counter),this.cache.set(e,new Map),s&&e.mediaStrings.forEach(function(n){t.mediaCache.has(n)||t.mediaCache.set(n,new Map),t.mediaCache.get(n).set(e,new Map)}));var i=this.cache.get(e),a=this._generatePropsReference(n),c=this._renderClassName(this.ids.get(e),a);return i.has(a)||!function(){var u={plugins:r,processStyles:t._processStyles,styles:o?e(n):e.render(n),className:c,props:n};i.set(a,t._processStyles(u)),s&&e.mediaStrings.forEach(function(r){u.styles=e.renderMedia(n,r),u.media=r;var o=t._processStyles(u);t.mediaCache.get(r).get(e).set(a,o)}),t._emitChange()}(),c}},{key:"_processStyles",value:function(e){var t=e.plugins,n=e.styles;return t.forEach(function(t){return t(e)}),n}},{key:"_generatePropsReference",value:function(e){return n(r(e))}},{key:"_renderClassName",value:function(e,t){return"c"+e+"-"+t}},{key:"_splitPseudoClasses",value:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?"":arguments[1],r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];return Object.keys(e).forEach(function(o){var s=e[o];s instanceof Object?t._splitPseudoClasses(s,n+o,r):(r[n]||(r[n]={}),r[n][o]=s)}),r}},{key:"_renderSelector",value:function(e,n){return"."+e+"{"+t(n)+"}"}},{key:"_renderMediaQuery",value:function(e,t){return"@media("+e+"){"+t+"}"}},{key:"_renderCache",value:function(e){var t=this,n="";return e.forEach(function(e,r){var o=t.ids.get(r);e.forEach(function(e,r){var s=t._renderClassName(o,r),i=t._splitPseudoClasses(e);Object.keys(i).forEach(function(e){n+=t._renderSelector(s+e,i[e])})})}),n}}]),e}(),i=1,a="STYLE",c=function(){function e(t){var n=this;return o.classCallCheck(this,e),t.nodeType!==i||void 0===t.textContent?(console.error("You need to specify a valid element node (nodeType = 1) to render into."),!1):(t.nodeName!==a&&console.warn("You are using a node other than `<style>`. Your styles might not get applied correctly."),t.hasAttribute("data-fela-stylesheet")&&console.warn("This node is already used by another renderer. Rendering might overwrite other styles."),t.setAttribute("data-fela-stylesheet",""),this.node=t,this.stylesheet=new s,void this.stylesheet.subscribe(function(e){return n.node.textContent=e}))}return o.createClass(e,[{key:"render",value:function(e,t,n){return this.stylesheet._renderSelectorVariation(e,t,n)}},{key:"clear",value:function(){this.stylesheet.clear(),this.node.textContent=""}}]),e}(),u=function(){function e(t){o.classCallCheck(this,e),this.composer=t}return o.createClass(e,[{key:"render",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return this.composer(e)}}]),e}(),l=function(e){function t(e){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];o.classCallCheck(this,t);var r=o.possibleConstructorReturn(this,Object.getPrototypeOf(t).call(this,e));return r.mediaComposer=n,r.mediaStrings=Object.keys(n),0===Object.keys(n).length&&console.warn("You are using a MediaSelector without specifying at least one media style composer. Prefer using basic Selectors instead."),r}return o.inherits(t,e),o.createClass(t,[{key:"renderMedia",value:function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=arguments[1],n=this.mediaComposer[t];return n(e)}}]),t}(u),f={Renderer:c,MediaSelector:l};return f}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.FelaDOM=t()}(this,function(){"use strict";function e(e,t){return function(n){n.type!==r||n.media?t.textContent=e.renderToString():t.sheet.insertRule(n.selector+"{"+n.declaration+"}",t.sheet.cssRules.length)}}function t(e){return e&&1===e.nodeType}function n(n,o){if(!t(o))throw new Error("You need to specify a valid element node (nodeType = 1) to render into.");o.setAttribute("data-fela-stylesheet","");var r=e(n,o);n.subscribe(r);var i=n.renderToString();o.textContent!==i&&(o.textContent=i)}var o={};o.typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o.defineProperty=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},o.extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e};var r=1,i={render:n};return i}); |
{ | ||
"name": "fela-dom", | ||
"version": "1.0.0-alpha.5", | ||
"description": "Fela package for working with the DOM", | ||
"main": "felaDOM.js", | ||
"files": [ | ||
"LICENSE", | ||
"README.md", | ||
"felaDOM.js", | ||
"server.js", | ||
"dist" | ||
], | ||
"repository": "https://github.com/rofrischmann/fela/", | ||
"keywords": [ | ||
"fela", | ||
"dynamic styling", | ||
"stylesheet", | ||
"css", | ||
"styling", | ||
"cssinjs" | ||
], | ||
"author": "Robin Frischmann", | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"fela": "^1.0.0-alpha.5" | ||
} | ||
"name": "fela-dom", | ||
"version": "4.1.0", | ||
"description": "Fela package for working with the DOM", | ||
"main": "index.js", | ||
"files": [ | ||
"LICENSE", | ||
"README.md", | ||
"index.js", | ||
"/dist" | ||
], | ||
"repository": "https://github.com/rofrischmann/fela/", | ||
"keywords": [ | ||
"fela", | ||
"dynamic styling", | ||
"stylesheet", | ||
"css", | ||
"styling", | ||
"cssinjs" | ||
], | ||
"author": "Robin Frischmann", | ||
"license": "MIT" | ||
} |
# fela-dom | ||
NPM package shipping DOM bindings for [Fela](https://github.com/rofrischmann/fela).<br> | ||
NPM package shipping DOM bindings for [Fela](fela.js.org). | ||
Check out the [Fela repository](https://github.com/rofrischmann/fela) for further information. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
0
1
10925
7
90