UNPKG

glamorous

Version:

React component styling solved

1,306 lines (1,130 loc) • 39.7 kB
'use strict'; function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var React = require('react'); var React__default = _interopDefault(React); var glamor = require('glamor'); var htmlTagNames = [ "a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "command", "content", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "element", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "iframe", "image", "img", "input", "ins", "isindex", "kbd", "keygen", "label", "legend", "li", "link", "listing", "main", "map", "mark", "marquee", "math", "menu", "menuitem", "meta", "meter", "multicol", "nav", "nextid", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "plaintext", "pre", "progress", "q", "rb", "rbc", "rp", "rt", "rtc", "ruby", "s", "samp", "script", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "svg", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp" ] ; var svgTagNames = [ "a", "altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor", "animateMotion", "animateTransform", "animation", "audio", "canvas", "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "discard", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignObject", "g", "glyph", "glyphRef", "handler", "hatch", "hatchpath", "hkern", "iframe", "image", "line", "linearGradient", "listener", "marker", "mask", "mesh", "meshgradient", "meshpatch", "meshrow", "metadata", "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline", "prefetch", "radialGradient", "rect", "script", "set", "solidColor", "solidcolor", "stop", "style", "svg", "switch", "symbol", "tbreak", "text", "textArea", "textPath", "title", "tref", "tspan", "unknown", "use", "video", "view", "vkern" ] ; var domElements = htmlTagNames.concat(svgTagNames).filter(function (tag, index, array) { return array.indexOf(tag) === index; }); var CHANNEL = '__glamorous__'; /* eslint import/no-mutable-exports:0, import/prefer-default-export:0 */ var PropTypes = void 0; /* istanbul ignore next */ if (React__default.version.slice(0, 4) === '15.5') { /* istanbul ignore next */ try { PropTypes = require('prop-types'); /* istanbul ignore next */ } catch (error) { // ignore } } /* istanbul ignore next */ PropTypes = PropTypes || React__default.PropTypes; var classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; var 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; }; }(); var 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; }; var _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; }; var 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; }; var objectWithoutProperties = function (obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }; var 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; }; var toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }; function generateWarningMessage(componentName) { // eslint-disable-next-line max-len return 'glamorous warning: Expected component called "' + componentName + '" which uses withTheme to be within a ThemeProvider but none was found.'; } function withTheme(ComponentToTheme) { var ThemedComponent = function (_Component) { inherits(ThemedComponent, _Component); function ThemedComponent() { var _ref; var _temp, _this, _ret; classCallCheck(this, ThemedComponent); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ThemedComponent.__proto__ || Object.getPrototypeOf(ThemedComponent)).call.apply(_ref, [this].concat(args))), _this), _this.state = { theme: {} }, _this.setTheme = function (theme) { return _this.setState({ theme: theme }); }, _temp), possibleConstructorReturn(_this, _ret); } createClass(ThemedComponent, [{ key: 'componentWillMount', value: function componentWillMount() { if (!this.context[CHANNEL]) { if (process.env.NODE_ENV !== 'production') { // eslint-disable-next-line no-console console.warn(generateWarningMessage(ComponentToTheme.displayName || ComponentToTheme.name || 'Stateless Function')); } return; } this.setState({ theme: this.context[CHANNEL].getState() }); } }, { key: 'componentDidMount', value: function componentDidMount() { if (this.context[CHANNEL]) { this.unsubscribe = this.context[CHANNEL].subscribe(this.setTheme); } } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { // cleanup subscription this.unsubscribe && this.unsubscribe(); } }, { key: 'render', value: function render() { return React__default.createElement(ComponentToTheme, _extends({}, this.props, this.state)); } }]); return ThemedComponent; }(React.Component); ThemedComponent.contextTypes = defineProperty({}, CHANNEL, PropTypes.object); return ThemedComponent; } function createBroadcast (initialState) { var listeners = []; var _state = initialState; var getState = function () { return _state; }; var setState = function (state) { _state = state; listeners.forEach(function (listener) { return listener(_state); }); }; var subscribe = function (listener) { listeners.push(listener); return function unsubscribe () { listeners = listeners.filter(function (item) { return item !== listener; }); } }; return { getState: getState, setState: setState, subscribe: subscribe } } /** * This is a component which will provide a theme to the entire tree * via context and event listener * (because pure components block context updates) * inspired by the styled-components implementation * https://github.com/styled-components/styled-components * @param {Object} theme the theme object.. */ var ThemeProvider = function (_Component) { inherits(ThemeProvider, _Component); function ThemeProvider() { var _ref; var _temp, _this, _ret; classCallCheck(this, ThemeProvider); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref = ThemeProvider.__proto__ || Object.getPrototypeOf(ThemeProvider)).call.apply(_ref, [this].concat(args))), _this), _this.broadcast = createBroadcast(_this.props.theme), _this.setOuterTheme = function (theme) { _this.outerTheme = theme; }, _temp), possibleConstructorReturn(_this, _ret); } createClass(ThemeProvider, [{ key: 'getTheme', // create theme, by merging with outer theme, if present value: function getTheme(passedTheme) { var theme = passedTheme || this.props.theme; return _extends({}, this.outerTheme, theme); } }, { key: 'getChildContext', value: function getChildContext() { return defineProperty({}, CHANNEL, this.broadcast); } }, { key: 'componentDidMount', value: function componentDidMount() { // create a new subscription for keeping track of outer theme, if present if (this.context[CHANNEL]) { this.unsubscribe = this.context[CHANNEL].subscribe(this.setOuterTheme); } } }, { key: 'componentWillMount', value: function componentWillMount() { // set broadcast state by merging outer theme with own if (this.context[CHANNEL]) { this.setOuterTheme(this.context[CHANNEL].getState()); this.broadcast.setState(this.getTheme()); } } }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { if (this.props.theme !== nextProps.theme) { this.broadcast.setState(this.getTheme(nextProps.theme)); } } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { this.unsubscribe && this.unsubscribe(); } }, { key: 'render', value: function render() { return this.props.children ? React__default.Children.only(this.props.children) : null; } }]); return ThemeProvider; }(React.Component); ThemeProvider.childContextTypes = defineProperty({}, CHANNEL, PropTypes.object.isRequired); ThemeProvider.contextTypes = defineProperty({}, CHANNEL, PropTypes.object); ThemeProvider.propTypes = { theme: PropTypes.object.isRequired, children: PropTypes.node }; /** * This function takes a className string and gets all the * associated glamor styles. It's used to merge glamor styles * from a className to make sure that specificity is not * a problem when passing a className to a component. * @param {String} [className=''] the className string * @return {Object} { glamorStyles, glamorlessClassName } * - glamorStyles is an array of all the glamor styles objects * - glamorlessClassName is the rest of the className string * without the glamor classNames */ function extractGlamorStyles() { var className = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; return className.toString().split(' ').reduce(function (groups, name) { if (name.indexOf('css-') === 0) { var style = getGlamorStylesFromClassName(name); groups.glamorStyles.push(style); } else { // eslint-disable-next-line max-len groups.glamorlessClassName = (groups.glamorlessClassName + ' ' + name).trim(); } return groups; }, { glamorlessClassName: '', glamorStyles: [] }); } function getGlamorClassName$1(styles, props, cssOverrides, theme) { var className = void 0, current = void 0; var mappedArgs = []; var nonGlamorClassNames = []; for (var i = 0; i < styles.length; i++) { current = styles[i]; if (typeof current === 'function') { mappedArgs.push(current(props, theme)); } else if (typeof current === 'string') { className = getGlamorStylesFromClassName(current); if (className) { mappedArgs.push(className); } else { nonGlamorClassNames.push(current); } } else { mappedArgs.push(current); } } var _extractGlamorStyles = extractGlamorStyles(props.className), parentGlamorStyles = _extractGlamorStyles.glamorStyles, glamorlessClassName = _extractGlamorStyles.glamorlessClassName; var glamorClassName = glamor.css.apply(undefined, mappedArgs.concat(toConsumableArray(parentGlamorStyles), [cssOverrides])).toString(); var extras = nonGlamorClassNames.join(' '); return (glamorlessClassName + ' ' + glamorClassName + ' ' + extras).trim(); } function getGlamorStylesFromClassName(className) { var id = className.slice('css-'.length); if (glamor.styleSheet.registered[id]) { return glamor.styleSheet.registered[id].style; } else { return null; } } /* * This is a relatively small abstraction that's ripe for open sourcing. * Documentation is in the README.md */ function createGlamorous(splitProps) { /** * This is the main export and the function that people * interact with most directly. * * It accepts a component which can be a string or * a React Component and returns * a "glamorousComponentFactory" * @param {String|ReactComponent} comp the component to render * @param {Object} options helpful info for the GlamorousComponents * @return {Function} the glamorousComponentFactory */ return function glamorous(comp) { var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, rootEl = _ref.rootEl, displayName = _ref.displayName, _ref$forwardProps = _ref.forwardProps, forwardProps = _ref$forwardProps === undefined ? [] : _ref$forwardProps; return glamorousComponentFactory; /** * This returns a React Component that renders the comp (closure) * with a className based on the given glamor styles object(s) * @param {...Object|Function} styles the styles to create with glamor. * If any of these are functions, they are invoked with the component * props and the return value is used. * @return {ReactComponent} the ReactComponent function */ function glamorousComponentFactory() { for (var _len = arguments.length, styles = Array(_len), _key = 0; _key < _len; _key++) { styles[_key] = arguments[_key]; } /** * This is a component which will render the comp (closure) * with the glamorous styles (closure). Forwards any valid * props to the underlying component. * @param {Object} theme the theme object * @return {ReactElement} React.createElement */ var GlamorousComponent = function (_Component) { inherits(GlamorousComponent, _Component); function GlamorousComponent() { var _ref2; var _temp, _this, _ret; classCallCheck(this, GlamorousComponent); for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } return _ret = (_temp = (_this = possibleConstructorReturn(this, (_ref2 = GlamorousComponent.__proto__ || Object.getPrototypeOf(GlamorousComponent)).call.apply(_ref2, [this].concat(args))), _this), _this.state = { theme: null }, _this.setTheme = function (theme) { return _this.setState({ theme: theme }); }, _temp), possibleConstructorReturn(_this, _ret); } createClass(GlamorousComponent, [{ key: 'componentWillMount', value: function componentWillMount() { var theme = this.props.theme; if (this.context[CHANNEL]) { // if a theme is provided via props, // it takes precedence over context this.setTheme(theme ? theme : this.context[CHANNEL].getState()); } else { this.setTheme(theme || {}); } } }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { if (this.props.theme !== nextProps.theme) { this.setTheme(nextProps.theme); } } }, { key: 'componentDidMount', value: function componentDidMount() { if (this.context[CHANNEL] && !this.props.theme) { // subscribe to future theme changes this.unsubscribe = this.context[CHANNEL].subscribe(this.setTheme); } } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { // cleanup subscription this.unsubscribe && this.unsubscribe(); } }, { key: 'render', value: function render() { // in this function, we're willing to sacrafice a little on // readability to get better performance because it actually // matters. var props = this.props; var _splitProps = splitProps(props, GlamorousComponent), toForward = _splitProps.toForward, cssOverrides = _splitProps.cssOverrides; // freeze the theme object in dev mode var theme = process.env.NODE_ENV === 'production' ? this.state.theme : Object.freeze(this.state.theme); // create className to apply var fullClassName = getGlamorClassName$1(GlamorousComponent.styles, props, cssOverrides, theme); return React__default.createElement(GlamorousComponent.comp, _extends({ ref: props.innerRef }, toForward, { className: fullClassName })); } }]); return GlamorousComponent; }(React.Component); GlamorousComponent.propTypes = { className: PropTypes.string, cssOverrides: PropTypes.object, theme: PropTypes.object, innerRef: PropTypes.func, glam: PropTypes.object }; GlamorousComponent.contextTypes = defineProperty({}, CHANNEL, PropTypes.object); Object.assign(GlamorousComponent, getGlamorousComponentMetadata({ comp: comp, styles: styles, rootEl: rootEl, forwardProps: forwardProps, displayName: displayName })); return GlamorousComponent; } }; function getGlamorousComponentMetadata(_ref3) { var comp = _ref3.comp, styles = _ref3.styles, rootEl = _ref3.rootEl, forwardProps = _ref3.forwardProps, displayName = _ref3.displayName; var componentsComp = comp.comp ? comp.comp : comp; return { // join styles together (for anyone doing: glamorous(glamorous.a({}), {})) styles: when(comp.styles, styles), // keep track of the ultimate rootEl to render (we never // actually render anything but // the base component, even when people wrap a glamorous // component in glamorous comp: componentsComp, rootEl: rootEl || componentsComp, // join forwardProps (for anyone doing: glamorous(glamorous.a({}), {})) forwardProps: when(comp.forwardProps, forwardProps), // set the displayName to something that's slightly more // helpful than `GlamorousComponent` :) displayName: displayName || 'glamorous(' + getDisplayName(comp) + ')' }; } function when(comp, prop) { return comp ? comp.concat(prop) : prop; } function getDisplayName(comp) { return typeof comp === 'string' ? comp : comp.displayName || comp.name || 'unknown'; } } // // Main // var index$1 = function memoize (fn, options) { var cache = options && options.cache ? options.cache : cacheDefault; var serializer = options && options.serializer ? options.serializer : serializerDefault; var strategy = options && options.strategy ? options.strategy : strategyDefault; return strategy(fn, { cache: cache, serializer: serializer }) }; // // Strategy // function isPrimitive (value) { return value == null || (typeof value !== 'function' && typeof value !== 'object') } function monadic (fn, cache, serializer, arg) { var cacheKey = isPrimitive(arg) ? arg : serializer(arg); if (!cache.has(cacheKey)) { var computedValue = fn.call(this, arg); cache.set(cacheKey, computedValue); return computedValue } return cache.get(cacheKey) } function variadic (fn, cache, serializer) { var args = Array.prototype.slice.call(arguments, 3); var cacheKey = serializer(args); if (!cache.has(cacheKey)) { var computedValue = fn.apply(this, args); cache.set(cacheKey, computedValue); return computedValue } return cache.get(cacheKey) } function strategyDefault (fn, options) { var memoized = fn.length === 1 ? monadic : variadic; memoized = memoized.bind( this, fn, options.cache.create(), options.serializer ); return memoized } // // Serializer // function serializerDefault () { return JSON.stringify(arguments) } // // Cache // function ObjectWithoutPrototypeCache () { this.cache = Object.create(null); } ObjectWithoutPrototypeCache.prototype.has = function (key) { return (key in this.cache) }; ObjectWithoutPrototypeCache.prototype.get = function (key) { return this.cache[key] }; ObjectWithoutPrototypeCache.prototype.set = function (key, value) { this.cache[key] = value; }; var cacheDefault = { create: function create () { return new ObjectWithoutPrototypeCache() } }; function unwrapExports (x) { return x && x.__esModule ? x['default'] : x; } function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } var a = ["coords","download","href","name","rel","shape","target","type"]; var abbr = ["title"]; var applet = ["alt","height","name","width"]; var area = ["alt","coords","download","href","rel","shape","target","type"]; var audio = ["controls","loop","muted","preload","src"]; var base = ["href","target"]; var basefont = ["size"]; var bdo = ["dir"]; var blockquote = ["cite"]; var button = ["disabled","form","name","type","value"]; var canvas = ["height","width"]; var col = ["span","width"]; var colgroup = ["span","width"]; var data = ["value"]; var del = ["cite"]; var details = ["open"]; var dfn = ["title"]; var dialog = ["open"]; var embed = ["height","src","type","width"]; var fieldset = ["disabled","form","name"]; var font = ["size"]; var form = ["accept","action","method","name","target"]; var frame = ["name","scrolling","src"]; var frameset = ["cols","rows"]; var head = ["profile"]; var hr = ["size","width"]; var html = ["manifest"]; var iframe = ["height","name","sandbox","scrolling","src","width"]; var img = ["alt","height","name","sizes","src","width"]; var input = ["accept","alt","autoCapitalize","autoCorrect","checked","defaultChecked","defaultValue","disabled","form","height","list","max","min","multiple","name","onChange","pattern","placeholder","required","size","src","step","title","type","value","width"]; var ins = ["cite"]; var keygen = ["challenge","disabled","form","name"]; var label = ["form"]; var li = ["type","value"]; var link = ["color","href","integrity","media","nonce","rel","scope","sizes","target","title","type"]; var map = ["name"]; var menu = ["label","type"]; var menuitem = ["checked","default","disabled","icon","label","title","type"]; var meta = ["content","name"]; var meter = ["high","low","max","min","optimum","value"]; var object = ["data","form","height","name","type","width"]; var ol = ["reversed","start","type"]; var optgroup = ["disabled","label"]; var option = ["disabled","label","selected","value"]; var output = ["form","name"]; var param = ["name","type","value"]; var pre = ["width"]; var progress = ["max","value"]; var q = ["cite"]; var script = ["async","defer","integrity","nonce","src","type"]; var select = ["defaultValue","disabled","form","multiple","name","onChange","required","size","value"]; var slot = ["name"]; var source = ["media","sizes","src","type"]; var style = ["media","nonce","title","type"]; var table = ["summary","width"]; var td = ["headers","height","scope","width"]; var textarea = ["autoCapitalize","autoCorrect","cols","defaultValue","disabled","form","name","onChange","placeholder","required","rows","value","wrap"]; var th = ["headers","height","scope","width"]; var track = ["default","kind","label","src"]; var ul = ["type"]; var video = ["controls","height","loop","muted","poster","preload","src","width"]; var svg = ["accentHeight","accumulate","additive","alignmentBaseline","allowReorder","alphabetic","amplitude","arabicForm","ascent","attributeName","attributeType","autoReverse","azimuth","baseFrequency","baseProfile","baselineShift","bbox","begin","bias","by","calcMode","capHeight","clip","clipPath","clipPathUnits","clipRule","color","colorInterpolation","colorInterpolationFilters","colorProfile","colorRendering","contentScriptType","contentStyleType","cursor","cx","cy","d","decelerate","descent","diffuseConstant","direction","display","divisor","dominantBaseline","dur","dx","dy","edgeMode","elevation","enableBackground","end","exponent","externalResourcesRequired","fill","fillOpacity","fillRule","filter","filterRes","filterUnits","floodColor","floodOpacity","focusable","fontFamily","fontSize","fontSizeAdjust","fontStretch","fontStyle","fontVariant","fontWeight","format","from","fx","fy","g1","g2","glyphName","glyphOrientationHorizontal","glyphOrientationVertical","glyphRef","gradientTransform","gradientUnits","hanging","height","horizAdvX","horizOriginX","ideographic","imageRendering","in","in2","intercept","k","k1","k2","k3","k4","kernelMatrix","kernelUnitLength","kerning","keyPoints","keySplines","keyTimes","lengthAdjust","letterSpacing","lightingColor","limitingConeAngle","local","markerEnd","markerHeight","markerMid","markerStart","markerUnits","markerWidth","mask","maskContentUnits","maskUnits","mathematical","mode","numOctaves","offset","opacity","operator","order","orient","orientation","origin","overflow","overlinePosition","overlineThickness","paintOrder","panose1","pathLength","patternContentUnits","patternTransform","patternUnits","pointerEvents","points","pointsAtX","pointsAtY","pointsAtZ","preserveAlpha","preserveAspectRatio","primitiveUnits","r","radius","refX","refY","renderingIntent","repeatCount","repeatDur","requiredExtensions","requiredFeatures","restart","result","rotate","rx","ry","scale","seed","shapeRendering","slope","spacing","specularConstant","specularExponent","speed","spreadMethod","startOffset","stdDeviation","stemh","stemv","stitchTiles","stopColor","stopOpacity","strikethroughPosition","strikethroughThickness","string","stroke","strokeDasharray","strokeDashoffset","strokeLinecap","strokeLinejoin","strokeMiterlimit","strokeOpacity","strokeWidth","surfaceScale","systemLanguage","tableValues","targetX","targetY","textAnchor","textDecoration","textLength","textRendering","to","transform","u1","u2","underlinePosition","underlineThickness","unicode","unicodeBidi","unicodeRange","unitsPerEm","vAlphabetic","vHanging","vIdeographic","vMathematical","values","vectorEffect","version","vertAdvY","vertOriginX","vertOriginY","viewBox","viewTarget","visibility","width","widths","wordSpacing","writingMode","x","x1","x2","xChannelSelector","xHeight","xlinkActuate","xlinkArcrole","xlinkHref","xlinkRole","xlinkShow","xlinkTitle","xlinkType","xmlBase","xmlLang","xmlSpace","xmlns","xmlnsXlink","y","y1","y2","yChannelSelector","z","zoomAndPan"]; var reactHtmlAttributes = { a: a, abbr: abbr, applet: applet, area: area, audio: audio, base: base, basefont: basefont, bdo: bdo, blockquote: blockquote, button: button, canvas: canvas, col: col, colgroup: colgroup, data: data, del: del, details: details, dfn: dfn, dialog: dialog, embed: embed, fieldset: fieldset, font: font, form: form, frame: frame, frameset: frameset, head: head, hr: hr, html: html, iframe: iframe, img: img, input: input, ins: ins, keygen: keygen, label: label, li: li, link: link, map: map, menu: menu, menuitem: menuitem, meta: meta, meter: meter, object: object, ol: ol, optgroup: optgroup, option: option, output: output, param: param, pre: pre, progress: progress, q: q, script: script, select: select, slot: slot, source: source, style: style, table: table, td: td, textarea: textarea, th: th, track: track, ul: ul, video: video, svg: svg, "*": ["acceptCharset","accessKey","allowFullScreen","allowTransparency","autoComplete","autoFocus","autoPlay","capture","cellPadding","cellSpacing","charSet","classID","className","colSpan","contentEditable","contextMenu","crossOrigin","dangerouslySetInnerHTML","dateTime","dir","draggable","encType","formAction","formEncType","formMethod","formNoValidate","formTarget","frameBorder","hidden","hrefLang","htmlFor","httpEquiv","id","inputMode","is","itemID","itemProp","itemRef","itemScope","itemType","keyParams","keyType","lang","marginHeight","marginWidth","maxLength","mediaGroup","minLength","noValidate","radioGroup","readOnly","role","rowSpan","scoped","seamless","spellCheck","srcDoc","srcLang","srcSet","style","suppressContentEditableWarning","tabIndex","title","useMap","wmode"] }; var reactHtmlAttributes$1 = Object.freeze({ a: a, abbr: abbr, applet: applet, area: area, audio: audio, base: base, basefont: basefont, bdo: bdo, blockquote: blockquote, button: button, canvas: canvas, col: col, colgroup: colgroup, data: data, del: del, details: details, dfn: dfn, dialog: dialog, embed: embed, fieldset: fieldset, font: font, form: form, frame: frame, frameset: frameset, head: head, hr: hr, html: html, iframe: iframe, img: img, input: input, ins: ins, keygen: keygen, label: label, li: li, link: link, map: map, menu: menu, menuitem: menuitem, meta: meta, meter: meter, object: object, ol: ol, optgroup: optgroup, option: option, output: output, param: param, pre: pre, progress: progress, q: q, script: script, select: select, slot: slot, source: source, style: style, table: table, td: td, textarea: textarea, th: th, track: track, ul: ul, video: video, svg: svg, default: reactHtmlAttributes }); var reactHtmlAttributes$2 = ( reactHtmlAttributes$1 && reactHtmlAttributes ) || reactHtmlAttributes$1; var index$2 = createCommonjsModule(function (module, exports) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = reactHtmlAttributes$2; module.exports = reactHtmlAttributes$2; // for CommonJS compatibility }); var reactHTMLAttributes = unwrapExports(index$2); /* * This is used to check if a property name is one of the React-specific * properties and determine if that property should be forwarded * to the React component */ /* Logic copied from ReactDOMUnknownPropertyHook */ var reactProps = ['children', 'dangerouslySetInnerHTML', 'key', 'ref', 'autoFocus', 'defaultValue', 'valueLink', 'defaultChecked', 'checkedLink', 'innerHTML', 'suppressContentEditableWarning', 'onFocusIn', 'onFocusOut', 'className', /* List copied from https://facebook.github.io/react/docs/events.html */ 'onCopy', 'onCut', 'onPaste', 'onCompositionEnd', 'onCompositionStart', 'onCompositionUpdate', 'onKeyDown', 'onKeyPress', 'onKeyUp', 'onFocus', 'onBlur', 'onChange', 'onInput', 'onSubmit', 'onClick', 'onContextMenu', 'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit', 'onDragLeave', 'onDragOver', 'onDragStart', 'onDrop', 'onMouseDown', 'onMouseEnter', 'onMouseLeave', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp', 'onSelect', 'onTouchCancel', 'onTouchEnd', 'onTouchMove', 'onTouchStart', 'onScroll', 'onWheel', 'onAbort', 'onCanPlay', 'onCanPlayThrough', 'onDurationChange', 'onEmptied', 'onEncrypted', 'onEnded', 'onError', 'onLoadedData', 'onLoadedMetadata', 'onLoadStart', 'onPause', 'onPlay', 'onPlaying', 'onProgress', 'onRateChange', 'onSeeked', 'onSeeking', 'onStalled', 'onSuspend', 'onTimeUpdate', 'onVolumeChange', 'onWaiting', 'onLoad', 'onAnimationStart', 'onAnimationEnd', 'onAnimationIteration', 'onTransitionEnd', 'onCopyCapture', 'onCutCapture', 'onPasteCapture', 'onCompositionEndCapture', 'onCompositionStartCapture', 'onCompositionUpdateCapture', 'onKeyDownCapture', 'onKeyPressCapture', 'onKeyUpCapture', 'onFocusCapture', 'onBlurCapture', 'onChangeCapture', 'onInputCapture', 'onSubmitCapture', 'onClickCapture', 'onContextMenuCapture', 'onDoubleClickCapture', 'onDragCapture', 'onDragEndCapture', 'onDragEnterCapture', 'onDragExitCapture', 'onDragLeaveCapture', 'onDragOverCapture', 'onDragStartCapture', 'onDropCapture', 'onMouseDownCapture', 'onMouseEnterCapture', 'onMouseLeaveCapture', 'onMouseMoveCapture', 'onMouseOutCapture', 'onMouseOverCapture', 'onMouseUpCapture', 'onSelectCapture', 'onTouchCancelCapture', 'onTouchEndCapture', 'onTouchMoveCapture', 'onTouchStartCapture', 'onScrollCapture', 'onWheelCapture', 'onAbortCapture', 'onCanPlayCapture', 'onCanPlayThroughCapture', 'onDurationChangeCapture', 'onEmptiedCapture', 'onEncryptedCapture', 'onEndedCapture', 'onErrorCapture', 'onLoadedDataCapture', 'onLoadedMetadataCapture', 'onLoadStartCapture', 'onPauseCapture', 'onPlayCapture', 'onPlayingCapture', 'onProgressCapture', 'onRateChangeCapture', 'onSeekedCapture', 'onSeekingCapture', 'onStalledCapture', 'onSuspendCapture', 'onTimeUpdateCapture', 'onVolumeChangeCapture', 'onWaitingCapture', 'onLoadCapture', 'onAnimationStartCapture', 'onAnimationEndCapture', 'onAnimationIterationCapture', 'onTransitionEndCapture']; /* eslint max-lines:0, func-style:0 */ // copied from: // https://github.com/styled-components/styled-components/tree/ // 956e8210b6277860c89404f9cb08735f97eaa7e1/src/utils/validAttr.js /* Trying to avoid the unknown-prop errors on glamorous components by filtering by React's attribute whitelist. */ var globalReactHtmlProps = reactHTMLAttributes['*']; // these are valid attributes that have the // same name as CSS properties, and is used // for css overrides API var cssProps = ['color', 'height', 'width']; /* From DOMProperty */ // eslint-disable-next-line max-len var ATTRIBUTE_NAME_START_CHAR = ':A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD'; // eslint-disable-next-line max-len var ATTRIBUTE_NAME_CHAR = ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040'; var isCustomAttribute = RegExp.prototype.test.bind(new RegExp('^(data|aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$')); var isHtmlProp = function isHtmlProp(name, tagName) { var elementAttributes = reactHTMLAttributes[tagName]; return globalReactHtmlProps.indexOf(name) !== -1 || (elementAttributes === undefined ? false : elementAttributes.indexOf(name) !== -1); }; var isCssProp = function isCssProp(name) { return cssProps.indexOf(name) !== -1; }; var isReactProp = function isReactProp(name) { return reactProps.indexOf(name) !== -1; }; // eslint-disable-next-line complexity var shouldForwardProperty = function shouldForwardProperty(tagName, name) { return typeof tagName !== 'string' || (isHtmlProp(name, tagName) || isReactProp(name) || isCustomAttribute(name.toLowerCase())) && (tagName === 'svg' || !isCssProp(name)); }; var shouldForwardProperty$1 = index$1(shouldForwardProperty); function splitProps(_ref, _ref2) { var propsAreCssOverrides = _ref2.propsAreCssOverrides, rootEl = _ref2.rootEl, forwardProps = _ref2.forwardProps; var _ref$css = _ref.css, cssOverrides = _ref$css === undefined ? {} : _ref$css, theme = _ref.theme, className = _ref.className, innerRef = _ref.innerRef, glam = _ref.glam, rest = objectWithoutProperties(_ref, ['css', 'theme', 'className', 'innerRef', 'glam']); var returnValue = { toForward: {}, cssOverrides: cssOverrides }; if (!propsAreCssOverrides) { if (typeof rootEl !== 'string') { // if it's not a string, then we can forward everything // (because it's a component) returnValue.toForward = rest; return returnValue; } } return Object.keys(rest).reduce(function (split, propName) { if (forwardProps.indexOf(propName) !== -1 || shouldForwardProperty$1(rootEl, propName)) { split.toForward[propName] = rest[propName]; } else if (propsAreCssOverrides) { split.cssOverrides[propName] = rest[propName]; } return split; }, returnValue); } var glamorous$2 = createGlamorous(splitProps); /* * This creates a glamorousComponentFactory for every DOM element so you can * simply do: * const GreenButton = glamorous.button({ * backgroundColor: 'green', * padding: 20, * }) * <GreenButton>Click Me!</GreenButton> */ Object.assign(glamorous$2, domElements.reduce(function (getters, tag) { getters[tag] = glamorous$2(tag); return getters; }, {})); /* * This creates a glamorous component for each DOM element so you can * simply do: * <glamorous.Div * color="green" * marginLeft={20} * > * I'm green! * </glamorous.Div> */ Object.assign(glamorous$2, domElements.reduce(function (comps, tag) { var capitalTag = capitalize(tag); comps[capitalTag] = glamorous$2[tag](); comps[capitalTag].displayName = 'glamorous.' + capitalTag; comps[capitalTag].propsAreCssOverrides = true; return comps; }, {})); function capitalize(s) { return s.slice(0, 1).toUpperCase() + s.slice(1); } var glamorousStar = Object.freeze({ default: glamorous$2, ThemeProvider: ThemeProvider, withTheme: withTheme }); var glamorous = glamorous$2; Object.assign(glamorous, Object.keys(glamorousStar).reduce(function (e, prop) { if (prop !== 'default') { // eslint-disable-next-line import/namespace e[prop] = glamorousStar[prop]; } return e; }, {})); module.exports = glamorous;