UNPKG

61.7 kBJavaScriptView Raw
1import React from 'react';
2import { css, styleSheet } from 'glamor';
3
4var htmlTagNames = [
5 "a",
6 "abbr",
7 "acronym",
8 "address",
9 "applet",
10 "area",
11 "article",
12 "aside",
13 "audio",
14 "b",
15 "base",
16 "basefont",
17 "bdi",
18 "bdo",
19 "bgsound",
20 "big",
21 "blink",
22 "blockquote",
23 "body",
24 "br",
25 "button",
26 "canvas",
27 "caption",
28 "center",
29 "cite",
30 "code",
31 "col",
32 "colgroup",
33 "command",
34 "content",
35 "data",
36 "datalist",
37 "dd",
38 "del",
39 "details",
40 "dfn",
41 "dialog",
42 "dir",
43 "div",
44 "dl",
45 "dt",
46 "element",
47 "em",
48 "embed",
49 "fieldset",
50 "figcaption",
51 "figure",
52 "font",
53 "footer",
54 "form",
55 "frame",
56 "frameset",
57 "h1",
58 "h2",
59 "h3",
60 "h4",
61 "h5",
62 "h6",
63 "head",
64 "header",
65 "hgroup",
66 "hr",
67 "html",
68 "i",
69 "iframe",
70 "image",
71 "img",
72 "input",
73 "ins",
74 "isindex",
75 "kbd",
76 "keygen",
77 "label",
78 "legend",
79 "li",
80 "link",
81 "listing",
82 "main",
83 "map",
84 "mark",
85 "marquee",
86 "math",
87 "menu",
88 "menuitem",
89 "meta",
90 "meter",
91 "multicol",
92 "nav",
93 "nextid",
94 "nobr",
95 "noembed",
96 "noframes",
97 "noscript",
98 "object",
99 "ol",
100 "optgroup",
101 "option",
102 "output",
103 "p",
104 "param",
105 "picture",
106 "plaintext",
107 "pre",
108 "progress",
109 "q",
110 "rb",
111 "rbc",
112 "rp",
113 "rt",
114 "rtc",
115 "ruby",
116 "s",
117 "samp",
118 "script",
119 "section",
120 "select",
121 "shadow",
122 "slot",
123 "small",
124 "source",
125 "spacer",
126 "span",
127 "strike",
128 "strong",
129 "style",
130 "sub",
131 "summary",
132 "sup",
133 "svg",
134 "table",
135 "tbody",
136 "td",
137 "template",
138 "textarea",
139 "tfoot",
140 "th",
141 "thead",
142 "time",
143 "title",
144 "tr",
145 "track",
146 "tt",
147 "u",
148 "ul",
149 "var",
150 "video",
151 "wbr",
152 "xmp"
153]
154;
155
156var svgTagNames = [
157 "a",
158 "altGlyph",
159 "altGlyphDef",
160 "altGlyphItem",
161 "animate",
162 "animateColor",
163 "animateMotion",
164 "animateTransform",
165 "animation",
166 "audio",
167 "canvas",
168 "circle",
169 "clipPath",
170 "color-profile",
171 "cursor",
172 "defs",
173 "desc",
174 "discard",
175 "ellipse",
176 "feBlend",
177 "feColorMatrix",
178 "feComponentTransfer",
179 "feComposite",
180 "feConvolveMatrix",
181 "feDiffuseLighting",
182 "feDisplacementMap",
183 "feDistantLight",
184 "feDropShadow",
185 "feFlood",
186 "feFuncA",
187 "feFuncB",
188 "feFuncG",
189 "feFuncR",
190 "feGaussianBlur",
191 "feImage",
192 "feMerge",
193 "feMergeNode",
194 "feMorphology",
195 "feOffset",
196 "fePointLight",
197 "feSpecularLighting",
198 "feSpotLight",
199 "feTile",
200 "feTurbulence",
201 "filter",
202 "font",
203 "font-face",
204 "font-face-format",
205 "font-face-name",
206 "font-face-src",
207 "font-face-uri",
208 "foreignObject",
209 "g",
210 "glyph",
211 "glyphRef",
212 "handler",
213 "hatch",
214 "hatchpath",
215 "hkern",
216 "iframe",
217 "image",
218 "line",
219 "linearGradient",
220 "listener",
221 "marker",
222 "mask",
223 "mesh",
224 "meshgradient",
225 "meshpatch",
226 "meshrow",
227 "metadata",
228 "missing-glyph",
229 "mpath",
230 "path",
231 "pattern",
232 "polygon",
233 "polyline",
234 "prefetch",
235 "radialGradient",
236 "rect",
237 "script",
238 "set",
239 "solidColor",
240 "solidcolor",
241 "stop",
242 "style",
243 "svg",
244 "switch",
245 "symbol",
246 "tbreak",
247 "text",
248 "textArea",
249 "textPath",
250 "title",
251 "tref",
252 "tspan",
253 "unknown",
254 "use",
255 "video",
256 "view",
257 "vkern"
258]
259;
260
261var domElements = htmlTagNames.concat(svgTagNames).filter(function (tag, index, array) {
262 return array.indexOf(tag) === index;
263});
264
265var CHANNEL = '__glamorous__'; /* istanbul ignore next */
266
267var isPreact = false;
268
269var _PropTypes = void 0;
270
271/* istanbul ignore next */
272if (isPreact) {
273 if (!React.PropTypes) {
274 _PropTypes = function PropTypes() {
275 return _PropTypes;
276 };
277
278 ['array', 'bool', 'func', 'number', 'object', 'string', 'symbol', 'any', 'arrayOf', 'element', 'instanceOf', 'node', 'objectOf', 'oneOf', 'oneOfType', 'shape', 'exact'].forEach(function (type) {
279 _PropTypes[type] = _PropTypes;
280 });
281 }
282 // copied from preact-compat
283 /* eslint-disable no-eq-null, eqeqeq, consistent-return */
284 if (!React.Children) {
285 var Children = {
286 map: function map(children, fn, ctx) {
287 if (children == null) {
288 return null;
289 }
290 children = Children.toArray(children);
291 if (ctx && ctx !== children) {
292 fn = fn.bind(ctx);
293 }
294 return children.map(fn);
295 },
296 forEach: function forEach(children, fn, ctx) {
297 if (children == null) {
298 return null;
299 }
300 children = Children.toArray(children);
301 if (ctx && ctx !== children) {
302 fn = fn.bind(ctx);
303 }
304 children.forEach(fn);
305 },
306 count: function count(children) {
307 return children && children.length || 0;
308 },
309 only: function only(children) {
310 children = Children.toArray(children);
311 if (children.length !== 1) {
312 throw new Error('Children.only() expects only one child.');
313 }
314 return children[0];
315 },
316 toArray: function toArray(children) {
317 if (children == null) {
318 return [];
319 }
320 return [].concat(children);
321 }
322 };
323 React.Children = Children;
324 }
325 /* eslint-enable no-eq-null, eqeqeq, consistent-return */
326} else if (parseFloat(React.version.slice(0, 4)) >= 15.5) {
327 /* istanbul ignore next */
328 try {
329 _PropTypes = require('prop-types');
330 /* istanbul ignore next */
331 } catch (error) {
332 // ignore
333 }
334}
335/* istanbul ignore next */
336_PropTypes = _PropTypes || React.PropTypes;
337
338/*
339eslint
340 import/no-mutable-exports:0,
341 import/prefer-default-export:0,
342 react/no-deprecated:0
343 */
344
345var classCallCheck = function (instance, Constructor) {
346 if (!(instance instanceof Constructor)) {
347 throw new TypeError("Cannot call a class as a function");
348 }
349};
350
351var _extends = Object.assign || function (target) {
352 for (var i = 1; i < arguments.length; i++) {
353 var source = arguments[i];
354
355 for (var key in source) {
356 if (Object.prototype.hasOwnProperty.call(source, key)) {
357 target[key] = source[key];
358 }
359 }
360 }
361
362 return target;
363};
364
365var inherits = function (subClass, superClass) {
366 if (typeof superClass !== "function" && superClass !== null) {
367 throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
368 }
369
370 subClass.prototype = Object.create(superClass && superClass.prototype, {
371 constructor: {
372 value: subClass,
373 enumerable: false,
374 writable: true,
375 configurable: true
376 }
377 });
378 if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
379};
380
381var objectWithoutProperties = function (obj, keys) {
382 var target = {};
383
384 for (var i in obj) {
385 if (keys.indexOf(i) >= 0) continue;
386 if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
387 target[i] = obj[i];
388 }
389
390 return target;
391};
392
393var possibleConstructorReturn = function (self, call) {
394 if (!self) {
395 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
396 }
397
398 return call && (typeof call === "object" || typeof call === "function") ? call : self;
399};
400
401function generateWarningMessage(Comp) {
402 var componentName = Comp.displayName || Comp.name || 'FunctionComponent';
403 // eslint-disable-next-line max-len
404 return 'glamorous warning: Expected component called "' + componentName + '" which uses withTheme to be within a ThemeProvider but none was found.';
405}
406
407function withTheme(ComponentToTheme) {
408 var _defaultContextTypes;
409
410 var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
411 _ref$noWarn = _ref.noWarn,
412 noWarn = _ref$noWarn === undefined ? false : _ref$noWarn,
413 _ref$createElement = _ref.createElement,
414 createElement = _ref$createElement === undefined ? true : _ref$createElement;
415
416 var ThemedComponent = function (_React$Component) {
417 inherits(ThemedComponent, _React$Component);
418
419 function ThemedComponent() {
420 var _temp, _this, _ret;
421
422 classCallCheck(this, ThemedComponent);
423
424 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
425 args[_key] = arguments[_key];
426 }
427
428 return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.warned = noWarn, _this.state = { theme: {} }, _this.setTheme = function (theme) {
429 return _this.setState({ theme: theme });
430 }, _temp), possibleConstructorReturn(_this, _ret);
431 }
432
433 // eslint-disable-next-line complexity
434 ThemedComponent.prototype.componentWillMount = function componentWillMount() {
435 if (!this.context[CHANNEL]) {
436 if (process.env.NODE_ENV !== 'production' && !this.warned) {
437 this.warned = true;
438 // eslint-disable-next-line no-console
439 console.warn(generateWarningMessage(ComponentToTheme));
440 }
441 }
442 var theme = this.props.theme;
443
444 if (this.context[CHANNEL]) {
445 // if a theme is provided via props,
446 // it takes precedence over context
447 this.setTheme(theme ? theme : this.context[CHANNEL].getState());
448 } else {
449 this.setTheme(theme || {});
450 }
451 };
452
453 ThemedComponent.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
454 if (this.props.theme !== nextProps.theme) {
455 this.setTheme(nextProps.theme);
456 }
457 };
458
459 ThemedComponent.prototype.componentDidMount = function componentDidMount() {
460 if (this.context[CHANNEL] && !this.props.theme) {
461 // subscribe to future theme changes
462 this.subscriptionId = this.context[CHANNEL].subscribe(this.setTheme);
463 }
464 };
465
466 ThemedComponent.prototype.componentWillUnmount = function componentWillUnmount() {
467 // cleanup subscription
468 this.subscriptionId && this.context[CHANNEL].unsubscribe(this.subscriptionId);
469 };
470
471 ThemedComponent.prototype.render = function render() {
472 if (createElement) {
473 return React.createElement(ComponentToTheme, _extends({}, this.props, this.state));
474 } else {
475 // this allows us to effectively use the GlamorousComponent
476 // as our `render` method without going through lifecycle hooks.
477 // Also allows us to forward the context in the scenario where
478 // a user wants to add more context.
479 // eslint-disable-next-line babel/new-cap
480 return ComponentToTheme.call(this, _extends({}, this.props, this.state), this.context);
481 }
482 };
483
484 return ThemedComponent;
485 }(React.Component);
486
487 process.env.NODE_ENV !== "production" ? ThemedComponent.propTypes = {
488 theme: _PropTypes.object
489 } : void 0;
490
491
492 var defaultContextTypes = (_defaultContextTypes = {}, _defaultContextTypes[CHANNEL] = _PropTypes.object, _defaultContextTypes);
493
494 var userDefinedContextTypes = null;
495
496 // configure the contextTypes to be settable by the user,
497 // however also retaining the glamorous channel.
498 Object.defineProperty(ThemedComponent, 'contextTypes', {
499 enumerable: true,
500 configurable: true,
501 set: function set$$1(value) {
502 userDefinedContextTypes = value;
503 },
504 get: function get$$1() {
505 // if the user has provided a contextTypes definition,
506 // merge the default context types with the provided ones.
507 if (userDefinedContextTypes) {
508 return _extends({}, defaultContextTypes, userDefinedContextTypes);
509 }
510 return defaultContextTypes;
511 }
512 });
513
514 return ThemedComponent;
515}
516
517var isFunction_1 = isFunction;
518
519var toString = Object.prototype.toString;
520
521function isFunction (fn) {
522 var string = toString.call(fn);
523 return string === '[object Function]' ||
524 (typeof fn === 'function' && string !== '[object RegExp]') ||
525 (typeof window !== 'undefined' &&
526 // IE8 and below
527 (fn === window.setTimeout ||
528 fn === window.alert ||
529 fn === window.confirm ||
530 fn === window.prompt))
531}
532
533/*!
534 * isobject <https://github.com/jonschlinkert/isobject>
535 *
536 * Copyright (c) 2014-2017, Jon Schlinkert.
537 * Released under the MIT License.
538 */
539
540var isobject = function isObject(val) {
541 return val != null && typeof val === 'object' && Array.isArray(val) === false;
542};
543
544function isObjectObject(o) {
545 return isobject(o) === true
546 && Object.prototype.toString.call(o) === '[object Object]';
547}
548
549var isPlainObject = function isPlainObject(o) {
550 var ctor,prot;
551
552 if (isObjectObject(o) === false) return false;
553
554 // If has modified constructor
555 ctor = o.constructor;
556 if (typeof ctor !== 'function') return false;
557
558 // If has modified prototype
559 prot = ctor.prototype;
560 if (isObjectObject(prot) === false) return false;
561
562 // If constructor does not have an Object-specific method
563 if (prot.hasOwnProperty('isPrototypeOf') === false) {
564 return false;
565 }
566
567 // Most likely a plain Object
568 return true;
569};
570
571function createBroadcast (initialState) {
572 var listeners = {};
573 var id = 1;
574 var _state = initialState;
575
576 function getState () {
577 return _state
578 }
579
580 function setState (state) {
581 _state = state;
582 var keys = Object.keys(listeners);
583 var i = 0;
584 var len = keys.length;
585 for (; i < len; i++) {
586 // if a listener gets unsubscribed during setState we just skip it
587 if (listeners[keys[i]]) { listeners[keys[i]](state); }
588 }
589 }
590
591 // subscribe to changes and return the subscriptionId
592 function subscribe (listener) {
593 if (typeof listener !== 'function') {
594 throw new Error('listener must be a function.')
595 }
596 var currentId = id;
597 listeners[currentId] = listener;
598 id += 1;
599 return currentId
600 }
601
602 // remove subscription by removing the listener function
603 function unsubscribe (id) {
604 listeners[id] = undefined;
605 }
606
607 return { getState: getState, setState: setState, subscribe: subscribe, unsubscribe: unsubscribe }
608}
609
610var _ThemeProvider$childC, _ThemeProvider$contex;
611
612/**
613 * This is a component which will provide a theme to the entire tree
614 * via context and event listener
615 * (because pure components block context updates)
616 * inspired by the styled-components implementation
617 * https://github.com/styled-components/styled-components
618 * @param {Object} theme the theme object..
619 */
620
621var ThemeProvider = function (_React$Component) {
622 inherits(ThemeProvider, _React$Component);
623
624 function ThemeProvider() {
625 var _temp, _this, _ret;
626
627 classCallCheck(this, ThemeProvider);
628
629 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
630 args[_key] = arguments[_key];
631 }
632
633 return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.setOuterTheme = function (theme) {
634 _this.outerTheme = theme;
635 if (_this.broadcast !== undefined) {
636 _this.publishTheme();
637 }
638 }, _temp), possibleConstructorReturn(_this, _ret);
639 }
640
641 // create theme, by merging with outer theme, if present
642 ThemeProvider.prototype.getTheme = function getTheme(passedTheme) {
643 var theme = passedTheme || this.props.theme;
644 if (isFunction_1(theme)) {
645 var mergedTheme = theme(this.outerTheme);
646 if (!isPlainObject(mergedTheme)) {
647 throw new Error('[ThemeProvider] Please return an object from your theme function, ' + 'i.e. theme={() => ({})}!');
648 }
649 return mergedTheme;
650 }
651 return _extends({}, this.outerTheme, theme);
652 };
653
654 ThemeProvider.prototype.getChildContext = function getChildContext() {
655 var _ref;
656
657 return _ref = {}, _ref[CHANNEL] = this.broadcast, _ref;
658 };
659
660 ThemeProvider.prototype.publishTheme = function publishTheme(theme) {
661 this.broadcast.setState(this.getTheme(theme));
662 };
663
664 ThemeProvider.prototype.componentDidMount = function componentDidMount() {
665 // create a new subscription for keeping track of outer theme, if present
666 if (this.context[CHANNEL]) {
667 this.subscriptionId = this.context[CHANNEL].subscribe(this.setOuterTheme);
668 }
669 };
670
671 ThemeProvider.prototype.componentWillMount = function componentWillMount() {
672 // set broadcast state by merging outer theme with own
673 if (this.context[CHANNEL]) {
674 this.setOuterTheme(this.context[CHANNEL].getState());
675 }
676 this.broadcast = createBroadcast(this.getTheme(this.props.theme));
677 };
678
679 ThemeProvider.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
680 if (this.props.theme !== nextProps.theme) {
681 this.publishTheme(nextProps.theme);
682 }
683 };
684
685 ThemeProvider.prototype.componentWillUnmount = function componentWillUnmount() {
686 this.subscriptionId && this.context[CHANNEL].unsubscribe(this.subscriptionId);
687 };
688
689 ThemeProvider.prototype.render = function render() {
690 return this.props.children ? React.Children.only(this.props.children) : null;
691 };
692
693 return ThemeProvider;
694}(React.Component);
695
696ThemeProvider.childContextTypes = (_ThemeProvider$childC = {}, _ThemeProvider$childC[CHANNEL] = _PropTypes.object.isRequired, _ThemeProvider$childC);
697
698ThemeProvider.contextTypes = (_ThemeProvider$contex = {}, _ThemeProvider$contex[CHANNEL] = _PropTypes.object, _ThemeProvider$contex);
699
700process.env.NODE_ENV !== "production" ? ThemeProvider.propTypes = {
701 theme: _PropTypes.oneOfType([_PropTypes.object, _PropTypes.func]).isRequired,
702 children: _PropTypes.node
703} : void 0;
704
705/**
706 * This function takes a className string and gets all the
707 * associated glamor styles. It's used to merge glamor styles
708 * from a className to make sure that specificity is not
709 * a problem when passing a className to a component.
710 * @param {String} [className=''] the className string
711 * @return {Object} { glamorStyles, glamorlessClassName }
712 * - glamorStyles is an array of all the glamor styles objects
713 * - glamorlessClassName is the rest of the className string
714 * without the glamor classNames
715 */
716function extractGlamorStyles(className) {
717 var glamorlessClassName = [];
718 var glamorStyles = [];
719 className.toString().split(' ').forEach(function (name) {
720 if (styleSheet.registered[name.substring(4)] === undefined) {
721 glamorlessClassName.push(name);
722 } else {
723 var style = buildGlamorSrcFromClassName(name);
724 glamorStyles.push(style);
725 }
726 });
727
728 return { glamorlessClassName: glamorlessClassName, glamorStyles: glamorStyles };
729}
730
731/** Glamor's css function returns an object with the shape
732 *
733 * {
734 * [`data-css-${hash}`]: '',
735 * toString() { return `css-${hash}` }
736 * }
737 *
738 * Whenever glamor's build function encounters an object with
739 * this shape it just pulls the resulting styles from the cache.
740 *
741 * note: the toString method is not needed to qualify the shape
742 **/
743function buildGlamorSrcFromClassName(className) {
744 var _ref;
745
746 return _ref = {}, _ref['data-' + className] = '', _ref;
747}
748
749function getGlamorClassName(_ref2) {
750 var styles = _ref2.styles,
751 props = _ref2.props,
752 cssOverrides = _ref2.cssOverrides,
753 cssProp = _ref2.cssProp,
754 context = _ref2.context,
755 displayName = _ref2.displayName;
756
757 var _handleStyles = handleStyles([].concat(styles, [props.className, cssOverrides, cssProp]), props, context),
758 mappedArgs = _handleStyles.mappedArgs,
759 nonGlamorClassNames = _handleStyles.nonGlamorClassNames;
760 // eslint-disable-next-line max-len
761
762
763 var isDev = process.env.NODE_ENV === 'development' || !process.env.NODE_ENV;
764 var devRules = isDev ? { label: displayName } : null;
765 var glamorClassName = css.apply(undefined, [devRules].concat(mappedArgs)).toString();
766 var extras = nonGlamorClassNames.join(' ').trim();
767 return (glamorClassName + ' ' + extras).trim();
768}
769
770// this next function is on a "hot" code-path
771// so it's pretty complex to make sure it's fast.
772// eslint-disable-next-line complexity
773function handleStyles(styles, props, context) {
774 var current = void 0;
775 var mappedArgs = [];
776 var nonGlamorClassNames = [];
777 for (var i = 0; i < styles.length; i++) {
778 current = styles[i];
779 while (typeof current === 'function') {
780 current = current(props, context);
781 }
782 if (typeof current === 'string') {
783 var _extractGlamorStyles = extractGlamorStyles(current),
784 glamorStyles = _extractGlamorStyles.glamorStyles,
785 glamorlessClassName = _extractGlamorStyles.glamorlessClassName;
786
787 mappedArgs.push.apply(mappedArgs, glamorStyles);
788 nonGlamorClassNames.push.apply(nonGlamorClassNames, glamorlessClassName);
789 } else if (Array.isArray(current)) {
790 var recursed = handleStyles(current, props, context);
791 mappedArgs.push.apply(mappedArgs, recursed.mappedArgs);
792 nonGlamorClassNames.push.apply(nonGlamorClassNames, recursed.nonGlamorClassNames);
793 } else {
794 mappedArgs.push(current);
795 }
796 }
797 return { mappedArgs: mappedArgs, nonGlamorClassNames: nonGlamorClassNames };
798}
799
800/*
801 * This is a relatively small abstraction that's ripe for open sourcing.
802 * Documentation is in the README.md
803 */
804
805function createGlamorous(splitProps) {
806 return glamorous;
807
808 /**
809 * This is the main export and the function that people
810 * interact with most directly.
811 *
812 * It accepts a component which can be a string or
813 * a React Component and returns
814 * a "glamorousComponentFactory"
815 * @param {String|ReactComponent} comp the component to render
816 * @param {Object} options helpful info for the GlamorousComponents
817 * @return {Function} the glamorousComponentFactory
818 */
819 function glamorous(comp) {
820 var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
821 var rootEl = config.rootEl,
822 displayName = config.displayName,
823 shouldClassNameUpdate = config.shouldClassNameUpdate,
824 _config$filterProps = config.filterProps,
825 filterProps = _config$filterProps === undefined ? [] : _config$filterProps,
826 _config$forwardProps = config.forwardProps,
827 forwardProps = _config$forwardProps === undefined ? [] : _config$forwardProps,
828 _config$propsAreCssOv = config.propsAreCssOverrides,
829 propsAreCssOverrides = _config$propsAreCssOv === undefined ? comp.propsAreCssOverrides : _config$propsAreCssOv,
830 basePropsToApply = config.withProps;
831
832 Object.assign(glamorousComponentFactory, { withConfig: withConfig });
833 return glamorousComponentFactory;
834
835 function withConfig(newConfig) {
836 return glamorous(comp, _extends({}, config, newConfig));
837 }
838
839 /**
840 * This returns a React Component that renders the comp (closure)
841 * with a className based on the given glamor styles object(s)
842 * @param {...Object|Function} styles the styles to create with glamor.
843 * If any of these are functions, they are invoked with the component
844 * props and the return value is used.
845 * @return {ReactComponent} the ReactComponent function
846 */
847 function glamorousComponentFactory() {
848 for (var _len = arguments.length, styles = Array(_len), _key = 0; _key < _len; _key++) {
849 styles[_key] = arguments[_key];
850 }
851
852 /**
853 * This is a component which will render the comp (closure)
854 * with the glamorous styles (closure). Forwards any valid
855 * props to the underlying component.
856 */
857 var GlamorousComponent = withTheme(function (props, context) {
858 props = getPropsToApply(GlamorousComponent.propsToApply, {}, props, context);
859 var updateClassName = shouldUpdate(props, context, this.previous);
860
861 if (shouldClassNameUpdate) {
862 this.previous = { props: props, context: context };
863 }
864
865 var _splitProps = splitProps(props, GlamorousComponent),
866 toForward = _splitProps.toForward,
867 cssOverrides = _splitProps.cssOverrides,
868 cssProp = _splitProps.cssProp;
869
870 // create className to apply
871
872
873 this.className = updateClassName ? getGlamorClassName({
874 styles: GlamorousComponent.styles,
875 props: props,
876 cssOverrides: cssOverrides,
877 cssProp: cssProp,
878 context: context,
879 displayName: GlamorousComponent.displayName
880 }) : this.className;
881
882 return React.createElement(GlamorousComponent.comp, _extends({
883 // if innerRef is forwarded we don't want to apply it here
884 ref: 'innerRef' in toForward ? undefined : props.innerRef
885 }, toForward, {
886 className: this.className
887 }));
888 }, { noWarn: true, createElement: false });
889
890 process.env.NODE_ENV !== "production" ? GlamorousComponent.propTypes = {
891 // className accepts an object due to glamor's css function
892 // returning an object with a toString method that gives the className
893 className: _PropTypes.oneOfType([_PropTypes.string, _PropTypes.object]),
894 cssOverrides: _PropTypes.object,
895 innerRef: _PropTypes.oneOfType([_PropTypes.func, _PropTypes.object]),
896 glam: _PropTypes.object
897 } : void 0;
898
899 function shouldUpdate(props, context, previous) {
900 // exiting early so components which do not use this
901 // optimization are not penalized by hanging onto
902 // references to previous props and context
903 if (!shouldClassNameUpdate) {
904 return true;
905 }
906 var update = true;
907 if (previous) {
908 if (!shouldClassNameUpdate(previous.props, props, previous.context, context)) {
909 update = false;
910 }
911 }
912
913 return update;
914 }
915
916 Object.assign(GlamorousComponent, getGlamorousComponentMetadata({
917 comp: comp,
918 styles: styles,
919 rootEl: rootEl,
920 filterProps: filterProps,
921 forwardProps: forwardProps,
922 displayName: displayName,
923 propsToApply: basePropsToApply
924 }), {
925 isGlamorousComponent: true,
926 propsAreCssOverrides: propsAreCssOverrides,
927 withComponent: function (newComp) {
928 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
929 var fwp = GlamorousComponent.forwardProps,
930 flp = GlamorousComponent.filterProps,
931 componentProperties = objectWithoutProperties(GlamorousComponent, ['forwardProps', 'filterProps']);
932
933 return glamorous(_extends({}, componentProperties, {
934 comp: newComp,
935 rootEl: getRootEl(newComp)
936 }), _extends({
937 // allows the forwardProps and filterProps to be overridden
938 forwardProps: fwp,
939 filterProps: flp
940 }, options))();
941 },
942 withProps: function () {
943 for (var _len2 = arguments.length, propsToApply = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
944 propsToApply[_key2] = arguments[_key2];
945 }
946
947 return glamorous(GlamorousComponent, { withProps: propsToApply })();
948 },
949 withConfig: withConfig
950 });
951 return GlamorousComponent;
952 }
953 }
954
955 function getGlamorousComponentMetadata(_ref) {
956 var comp = _ref.comp,
957 styles = _ref.styles,
958 rootEl = _ref.rootEl,
959 filterProps = _ref.filterProps,
960 forwardProps = _ref.forwardProps,
961 displayName = _ref.displayName,
962 basePropsToApply = _ref.propsToApply;
963
964 var componentsComp = comp.comp ? comp.comp : comp;
965 var propsToApply = comp.propsToApply ? [].concat(comp.propsToApply, arrayify(basePropsToApply)) : arrayify(basePropsToApply);
966 return {
967 // join styles together (for anyone doing: glamorous(glamorous.a({}), {}))
968 styles: when(comp.styles, styles),
969 // keep track of the ultimate rootEl to render (we never
970 // actually render anything but
971 // the base component, even when people wrap a glamorous
972 // component in glamorous
973 comp: componentsComp,
974 rootEl: rootEl || getRootEl(comp),
975 // join forwardProps and filterProps
976 // (for anyone doing: glamorous(glamorous.a({}), {}))
977 forwardProps: when(comp.forwardProps, forwardProps),
978 filterProps: when(comp.filterProps, filterProps),
979 // set the displayName to something that's slightly more
980 // helpful than `GlamorousComponent` :)
981 displayName: displayName || 'glamorous(' + getDisplayName(comp) + ')',
982 // these are props that should be applied to the component at render time
983 propsToApply: propsToApply
984 };
985 }
986}
987
988/**
989 * reduces the propsToApply given to a single props object
990 * @param {Array} propsToApply an array of propsToApply objects:
991 * - object
992 * - array of propsToApply items
993 * - function that accepts the accumulated props and the context
994 * @param {Object} accumulator an object to apply props onto
995 * @param {Object} props the props that should ultimately take precedence
996 * @param {*} context the context object
997 * @return {Object} the reduced props
998 */
999function getPropsToApply(propsToApply, accumulator, props, context) {
1000 // using forEach rather than reduce here because the reduce solution
1001 // effectively did the same thing because we manipulate the `accumulator`
1002 propsToApply.forEach(function (propsToApplyItem) {
1003 if (typeof propsToApplyItem === 'function') {
1004 return Object.assign(accumulator, propsToApplyItem(Object.assign({}, accumulator, props), context));
1005 } else if (Array.isArray(propsToApplyItem)) {
1006 return Object.assign(accumulator, getPropsToApply(propsToApplyItem, accumulator, props, context));
1007 }
1008 return Object.assign(accumulator, propsToApplyItem);
1009 });
1010 // props wins
1011 return Object.assign(accumulator, props);
1012}
1013
1014function arrayify() {
1015 var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1016
1017 return Array.isArray(x) ? x : [x];
1018}
1019
1020function when(comp, prop) {
1021 return comp ? comp.concat(prop) : prop;
1022}
1023
1024function getRootEl(comp) {
1025 return comp.rootEl ? comp.rootEl : comp.comp || comp;
1026}
1027
1028function getDisplayName(comp) {
1029 return typeof comp === 'string' ? comp : comp.displayName || comp.name || 'unknown';
1030}
1031
1032//
1033// Main
1034//
1035
1036function memoize (fn, options) {
1037 var cache = options && options.cache
1038 ? options.cache
1039 : cacheDefault;
1040
1041 var serializer = options && options.serializer
1042 ? options.serializer
1043 : serializerDefault;
1044
1045 var strategy = options && options.strategy
1046 ? options.strategy
1047 : strategyDefault;
1048
1049 return strategy(fn, {
1050 cache: cache,
1051 serializer: serializer
1052 })
1053}
1054
1055//
1056// Strategy
1057//
1058
1059function isPrimitive (value) {
1060 return value == null || typeof value === 'number' || typeof value === 'boolean' // || typeof value === "string" 'unsafe' primitive for our needs
1061}
1062
1063function monadic (fn, cache, serializer, arg) {
1064 var cacheKey = isPrimitive(arg) ? arg : serializer(arg);
1065
1066 var computedValue = cache.get(cacheKey);
1067 if (typeof computedValue === 'undefined') {
1068 computedValue = fn.call(this, arg);
1069 cache.set(cacheKey, computedValue);
1070 }
1071
1072 return computedValue
1073}
1074
1075function variadic (fn, cache, serializer) {
1076 var args = Array.prototype.slice.call(arguments, 3);
1077 var cacheKey = serializer(args);
1078
1079 var computedValue = cache.get(cacheKey);
1080 if (typeof computedValue === 'undefined') {
1081 computedValue = fn.apply(this, args);
1082 cache.set(cacheKey, computedValue);
1083 }
1084
1085 return computedValue
1086}
1087
1088function assemble (fn, context, strategy, cache, serialize) {
1089 return strategy.bind(
1090 context,
1091 fn,
1092 cache,
1093 serialize
1094 )
1095}
1096
1097function strategyDefault (fn, options) {
1098 var strategy = fn.length === 1 ? monadic : variadic;
1099
1100 return assemble(
1101 fn,
1102 this,
1103 strategy,
1104 options.cache.create(),
1105 options.serializer
1106 )
1107}
1108
1109function strategyVariadic (fn, options) {
1110 var strategy = variadic;
1111
1112 return assemble(
1113 fn,
1114 this,
1115 strategy,
1116 options.cache.create(),
1117 options.serializer
1118 )
1119}
1120
1121function strategyMonadic (fn, options) {
1122 var strategy = monadic;
1123
1124 return assemble(
1125 fn,
1126 this,
1127 strategy,
1128 options.cache.create(),
1129 options.serializer
1130 )
1131}
1132
1133//
1134// Serializer
1135//
1136
1137function serializerDefault () {
1138 return JSON.stringify(arguments)
1139}
1140
1141//
1142// Cache
1143//
1144
1145function ObjectWithoutPrototypeCache () {
1146 this.cache = Object.create(null);
1147}
1148
1149ObjectWithoutPrototypeCache.prototype.has = function (key) {
1150 return (key in this.cache)
1151};
1152
1153ObjectWithoutPrototypeCache.prototype.get = function (key) {
1154 return this.cache[key]
1155};
1156
1157ObjectWithoutPrototypeCache.prototype.set = function (key, value) {
1158 this.cache[key] = value;
1159};
1160
1161var cacheDefault = {
1162 create: function create () {
1163 return new ObjectWithoutPrototypeCache()
1164 }
1165};
1166
1167//
1168// API
1169//
1170
1171var src = memoize;
1172var strategies = {
1173 variadic: strategyVariadic,
1174 monadic: strategyMonadic
1175};
1176src.strategies = strategies;
1177
1178function unwrapExports (x) {
1179 return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x.default : x;
1180}
1181
1182function createCommonjsModule(fn, module) {
1183 return module = { exports: {} }, fn(module, module.exports), module.exports;
1184}
1185
1186function getCjsExportFromNamespace (n) {
1187 return n && n.default || n;
1188}
1189
1190var a = ["coords","download","href","name","rel","shape","target","type","onClick"];
1191var abbr = ["title"];
1192var applet = ["alt","height","name","width"];
1193var area = ["alt","coords","download","href","rel","shape","target","type"];
1194var audio = ["controls","loop","muted","preload","src"];
1195var base = ["href","target"];
1196var basefont = ["size"];
1197var bdo = ["dir"];
1198var blockquote = ["cite"];
1199var button = ["disabled","form","name","type","value"];
1200var canvas = ["height","width"];
1201var col = ["span","width"];
1202var colgroup = ["span","width"];
1203var data = ["value"];
1204var del = ["cite"];
1205var details = ["open"];
1206var dfn = ["title"];
1207var dialog = ["open"];
1208var embed = ["height","src","type","width"];
1209var fieldset = ["disabled","form","name"];
1210var font = ["size"];
1211var form = ["accept","action","method","name","target","onChange","onInput","onInvalid","onSubmit"];
1212var frame = ["name","scrolling","src"];
1213var frameset = ["cols","rows"];
1214var head = ["profile"];
1215var hr = ["size","width"];
1216var html = ["manifest"];
1217var iframe = ["height","name","sandbox","scrolling","src","width"];
1218var img = ["alt","height","name","sizes","src","width"];
1219var input = ["accept","alt","autoCapitalize","autoCorrect","autoSave","checked","defaultChecked","defaultValue","disabled","form","height","list","max","min","multiple","name","onChange","pattern","placeholder","required","results","size","src","step","title","type","value","width"];
1220var ins = ["cite"];
1221var keygen = ["challenge","disabled","form","name"];
1222var label = ["form"];
1223var li = ["type","value"];
1224var link = ["color","href","integrity","media","nonce","rel","scope","sizes","target","title","type"];
1225var map = ["name"];
1226var meta = ["content","name"];
1227var meter = ["high","low","max","min","optimum","value"];
1228var object = ["data","form","height","name","type","width"];
1229var ol = ["reversed","start","type"];
1230var optgroup = ["disabled","label"];
1231var option = ["disabled","label","selected","value"];
1232var output = ["form","name"];
1233var param = ["name","type","value"];
1234var pre = ["width"];
1235var progress = ["max","value"];
1236var q = ["cite"];
1237var script = ["async","defer","integrity","nonce","src","type"];
1238var select = ["defaultValue","disabled","form","multiple","name","onChange","required","size","value"];
1239var slot = ["name"];
1240var source = ["media","sizes","src","type"];
1241var style = ["media","nonce","title","type"];
1242var table = ["summary","width"];
1243var td = ["headers","height","scope","width"];
1244var textarea = ["autoCapitalize","autoCorrect","cols","defaultValue","disabled","form","name","onChange","placeholder","required","rows","value","wrap"];
1245var th = ["headers","height","scope","width"];
1246var track = ["default","kind","label","src"];
1247var ul = ["type"];
1248var video = ["controls","height","loop","muted","playsInline","poster","preload","src","width"];
1249var 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"];
1250var elements = {"html":["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","math","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rb","rp","rt","rtc","ruby","s","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"],"svg":["a","altGlyph","altGlyphDef","altGlyphItem","animate","animateColor","animateMotion","animateTransform","circle","clipPath","color-profile","cursor","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","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","hkern","image","line","linearGradient","marker","mask","metadata","missing-glyph","mpath","path","pattern","polygon","polyline","radialGradient","rect","script","set","stop","style","svg","switch","symbol","text","textPath","title","tref","tspan","use","view","vkern"]};
1251var reactHtmlAttributes = {
1252 a: a,
1253 abbr: abbr,
1254 applet: applet,
1255 area: area,
1256 audio: audio,
1257 base: base,
1258 basefont: basefont,
1259 bdo: bdo,
1260 blockquote: blockquote,
1261 button: button,
1262 canvas: canvas,
1263 col: col,
1264 colgroup: colgroup,
1265 data: data,
1266 del: del,
1267 details: details,
1268 dfn: dfn,
1269 dialog: dialog,
1270 embed: embed,
1271 fieldset: fieldset,
1272 font: font,
1273 form: form,
1274 frame: frame,
1275 frameset: frameset,
1276 head: head,
1277 hr: hr,
1278 html: html,
1279 iframe: iframe,
1280 img: img,
1281 input: input,
1282 ins: ins,
1283 keygen: keygen,
1284 label: label,
1285 li: li,
1286 link: link,
1287 map: map,
1288 meta: meta,
1289 meter: meter,
1290 object: object,
1291 ol: ol,
1292 optgroup: optgroup,
1293 option: option,
1294 output: output,
1295 param: param,
1296 pre: pre,
1297 progress: progress,
1298 q: q,
1299 script: script,
1300 select: select,
1301 slot: slot,
1302 source: source,
1303 style: style,
1304 table: table,
1305 td: td,
1306 textarea: textarea,
1307 th: th,
1308 track: track,
1309 ul: ul,
1310 video: video,
1311 svg: svg,
1312 elements: elements,
1313 "*": ["about","acceptCharset","accessKey","allowFullScreen","allowTransparency","autoComplete","autoFocus","autoPlay","capture","cellPadding","cellSpacing","charSet","classID","className","colSpan","contentEditable","contextMenu","crossOrigin","dangerouslySetInnerHTML","datatype","dateTime","dir","draggable","encType","formAction","formEncType","formMethod","formNoValidate","formTarget","frameBorder","hidden","hrefLang","htmlFor","httpEquiv","icon","id","inlist","inputMode","is","itemID","itemProp","itemRef","itemScope","itemType","keyParams","keyType","lang","marginHeight","marginWidth","maxLength","mediaGroup","minLength","noValidate","prefix","property","radioGroup","readOnly","resource","role","rowSpan","scoped","seamless","security","spellCheck","srcDoc","srcLang","srcSet","style","suppressContentEditableWarning","tabIndex","title","typeof","unselectable","useMap","vocab","wmode"]
1314};
1315
1316var reactHtmlAttributes$1 = Object.freeze({
1317 a: a,
1318 abbr: abbr,
1319 applet: applet,
1320 area: area,
1321 audio: audio,
1322 base: base,
1323 basefont: basefont,
1324 bdo: bdo,
1325 blockquote: blockquote,
1326 button: button,
1327 canvas: canvas,
1328 col: col,
1329 colgroup: colgroup,
1330 data: data,
1331 del: del,
1332 details: details,
1333 dfn: dfn,
1334 dialog: dialog,
1335 embed: embed,
1336 fieldset: fieldset,
1337 font: font,
1338 form: form,
1339 frame: frame,
1340 frameset: frameset,
1341 head: head,
1342 hr: hr,
1343 html: html,
1344 iframe: iframe,
1345 img: img,
1346 input: input,
1347 ins: ins,
1348 keygen: keygen,
1349 label: label,
1350 li: li,
1351 link: link,
1352 map: map,
1353 meta: meta,
1354 meter: meter,
1355 object: object,
1356 ol: ol,
1357 optgroup: optgroup,
1358 option: option,
1359 output: output,
1360 param: param,
1361 pre: pre,
1362 progress: progress,
1363 q: q,
1364 script: script,
1365 select: select,
1366 slot: slot,
1367 source: source,
1368 style: style,
1369 table: table,
1370 td: td,
1371 textarea: textarea,
1372 th: th,
1373 track: track,
1374 ul: ul,
1375 video: video,
1376 svg: svg,
1377 elements: elements,
1378 default: reactHtmlAttributes
1379});
1380
1381var reactHtmlAttributes$2 = getCjsExportFromNamespace(reactHtmlAttributes$1)
1382
1383var dist = createCommonjsModule(function (module, exports) {
1384
1385Object.defineProperty(exports, "__esModule", {
1386 value: true
1387});
1388
1389
1390exports.default = reactHtmlAttributes$2;
1391
1392module.exports = reactHtmlAttributes$2; // for CommonJS compatibility
1393});
1394
1395var reactHTMLAttributes = unwrapExports(dist);
1396
1397/*
1398 * This is used to check if a property name is one of the React-specific
1399 * properties and determine if that property should be forwarded
1400 * to the React component
1401 */
1402
1403/* Logic copied from ReactDOMUnknownPropertyHook */
1404var reactProps = ['children', 'dangerouslySetInnerHTML', 'key', 'ref', 'autoFocus', 'defaultValue', 'valueLink', 'defaultChecked', 'checkedLink', 'innerHTML', 'suppressContentEditableWarning', 'onFocusIn', 'onFocusOut', 'className',
1405
1406/* List copied from https://facebook.github.io/react/docs/events.html */
1407'onCopy', 'onCut', 'onPaste', 'onCompositionEnd', 'onCompositionStart', 'onCompositionUpdate', 'onKeyDown', 'onKeyPress', 'onKeyUp', 'onFocus', 'onBlur', 'onChange', 'onInput', 'onInvalid', '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'];
1408
1409if (isPreact) {
1410 reactProps.push('autocomplete', 'autofocus', 'class', 'for', 'onDblClick', 'onSearch', 'slot', 'srcset');
1411}
1412
1413/* eslint max-lines:0, func-style:0 */
1414
1415var globalReactHtmlProps = reactHTMLAttributes['*'];
1416var supportedSVGTagNames = reactHTMLAttributes.elements.svg;
1417var supportedHtmlTagNames = reactHTMLAttributes.elements.html;
1418
1419// these are valid attributes that have the
1420// same name as CSS properties, and is used
1421// for css overrides API
1422var cssProps = ['color', 'height', 'width'];
1423
1424/* From DOMProperty */
1425var ATTRIBUTE_NAME_START_CHAR =
1426// eslint-disable-next-line max-len
1427':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';
1428// eslint-disable-next-line max-len
1429var ATTRIBUTE_NAME_CHAR = ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
1430var isCustomAttribute = RegExp.prototype.test.bind(new RegExp('^(data|aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$'));
1431
1432var isSvgTag = function (tagName) {
1433 return (
1434 // in our context, we only say that SVG tags are SVG
1435 // if they are not also HTML.
1436 // See https://github.com/paypal/glamorous/issues/245
1437 // the svg tag will always be treated as svg for
1438 // er... obvious reasons
1439 tagName === 'svg' || supportedHtmlTagNames.indexOf(tagName) === -1 && supportedSVGTagNames.indexOf(tagName) !== -1
1440 );
1441};
1442var isHtmlProp = function (name, tagName) {
1443 var elementAttributes = void 0;
1444
1445 if (isSvgTag(tagName)) {
1446 // all SVG attributes supported by React are grouped under 'svg'
1447 elementAttributes = reactHTMLAttributes.svg;
1448 } else {
1449 elementAttributes = reactHTMLAttributes[tagName] || [];
1450 }
1451
1452 return globalReactHtmlProps.indexOf(name) !== -1 || elementAttributes.indexOf(name) !== -1;
1453};
1454var isCssProp = function (name) {
1455 return cssProps.indexOf(name) !== -1;
1456};
1457var isReactProp = function (name) {
1458 return reactProps.indexOf(name) !== -1;
1459};
1460
1461// eslint-disable-next-line complexity
1462var shouldForwardProperty = function (tagName, name) {
1463 return typeof tagName !== 'string' || (isHtmlProp(name, tagName) || isReactProp(name) || isCustomAttribute(name.toLowerCase())) && (!isCssProp(name) || isSvgTag(tagName));
1464};
1465
1466var shouldForwardProperty$1 = src(shouldForwardProperty);
1467
1468// eslint-disable-next-line complexity
1469function splitProps(_ref, _ref2) {
1470 var propsAreCssOverrides = _ref2.propsAreCssOverrides,
1471 rootEl = _ref2.rootEl,
1472 filterProps = _ref2.filterProps,
1473 forwardProps = _ref2.forwardProps;
1474 var cssProp = _ref.css,
1475 innerRef = _ref.innerRef,
1476 theme = _ref.theme,
1477 className = _ref.className,
1478 glam = _ref.glam,
1479 rest = objectWithoutProperties(_ref, ['css', 'innerRef', 'theme', 'className', 'glam']);
1480
1481 // forward innerRef if user wishes to do so
1482 if (innerRef !== undefined && forwardProps.indexOf('innerRef') !== -1) {
1483 rest.innerRef = innerRef;
1484 }
1485 var returnValue = { toForward: {}, cssProp: cssProp, cssOverrides: {} };
1486 if (!propsAreCssOverrides) {
1487 if (typeof rootEl !== 'string' && filterProps.length === 0) {
1488 // if it's not a string and filterProps is empty,
1489 // then we can forward everything (because it's a component)
1490 returnValue.toForward = rest;
1491 return returnValue;
1492 }
1493 }
1494 return Object.keys(rest).reduce(function (split, propName) {
1495 if (filterProps.indexOf(propName) !== -1) {
1496 return split;
1497 } else if (forwardProps.indexOf(propName) !== -1 || shouldForwardProperty$1(rootEl, propName)) {
1498 split.toForward[propName] = rest[propName];
1499 } else if (propsAreCssOverrides) {
1500 split.cssOverrides[propName] = rest[propName];
1501 }
1502 return split;
1503 }, returnValue);
1504}
1505
1506var glamorous = createGlamorous(splitProps);
1507
1508/*
1509 * This creates a glamorousComponentFactory for every DOM element so you can
1510 * simply do:
1511 * const GreenButton = glamorous.button({
1512 * backgroundColor: 'green',
1513 * padding: 20,
1514 * })
1515 * <GreenButton>Click Me!</GreenButton>
1516 */
1517Object.assign(glamorous, domElements.reduce(function (getters, tag) {
1518 // TODO: next breaking change, let's make
1519 // the `displayName` be: `glamorous.${tag}`
1520 getters[tag] = glamorous(tag);
1521 return getters;
1522}, {}));
1523
1524/*
1525 * This creates a glamorous component for each DOM element so you can
1526 * simply do:
1527 * <glamorous.Div
1528 * color="green"
1529 * marginLeft={20}
1530 * >
1531 * I'm green!
1532 * </glamorous.Div>
1533 */
1534Object.assign(glamorous, domElements.reduce(function (comps, tag) {
1535 var capitalTag = capitalize(tag);
1536 comps[capitalTag] = glamorous[tag]();
1537 comps[capitalTag].displayName = 'glamorous.' + capitalTag;
1538 comps[capitalTag].propsAreCssOverrides = true;
1539 return comps;
1540}, {}));
1541
1542function capitalize(s) {
1543 return s.slice(0, 1).toUpperCase() + s.slice(1);
1544}
1545
1546/*
1547 * Fix importing in typescript after rollup compilation
1548 * https://github.com/rollup/rollup/issues/1156
1549 * https://github.com/Microsoft/TypeScript/issues/13017#issuecomment-268657860
1550 */
1551glamorous.default = glamorous;
1552
1553// these exports below are generated
1554// and will be tree-shaken if you're using Webpack 2 or Rollup
1555var A = glamorous['A'];
1556var Abbr = glamorous['Abbr'];
1557var Acronym = glamorous['Acronym'];
1558var Address = glamorous['Address'];
1559var Applet = glamorous['Applet'];
1560var Area = glamorous['Area'];
1561var Article = glamorous['Article'];
1562var Aside = glamorous['Aside'];
1563var Audio = glamorous['Audio'];
1564var B = glamorous['B'];
1565var Base = glamorous['Base'];
1566var Basefont = glamorous['Basefont'];
1567var Bdi = glamorous['Bdi'];
1568var Bdo = glamorous['Bdo'];
1569var Bgsound = glamorous['Bgsound'];
1570var Big = glamorous['Big'];
1571var Blink = glamorous['Blink'];
1572var Blockquote = glamorous['Blockquote'];
1573var Body = glamorous['Body'];
1574var Br = glamorous['Br'];
1575var Button = glamorous['Button'];
1576var Canvas = glamorous['Canvas'];
1577var Caption = glamorous['Caption'];
1578var Center = glamorous['Center'];
1579var Cite = glamorous['Cite'];
1580var Code = glamorous['Code'];
1581var Col = glamorous['Col'];
1582var Colgroup = glamorous['Colgroup'];
1583var Command = glamorous['Command'];
1584var Content = glamorous['Content'];
1585var Data = glamorous['Data'];
1586var Datalist = glamorous['Datalist'];
1587var Dd = glamorous['Dd'];
1588var Del = glamorous['Del'];
1589var Details = glamorous['Details'];
1590var Dfn = glamorous['Dfn'];
1591var Dialog = glamorous['Dialog'];
1592var Dir = glamorous['Dir'];
1593var Div = glamorous['Div'];
1594var Dl = glamorous['Dl'];
1595var Dt = glamorous['Dt'];
1596var Element = glamorous['Element'];
1597var Em = glamorous['Em'];
1598var Embed = glamorous['Embed'];
1599var Fieldset = glamorous['Fieldset'];
1600var Figcaption = glamorous['Figcaption'];
1601var Figure = glamorous['Figure'];
1602var Font = glamorous['Font'];
1603var Footer = glamorous['Footer'];
1604var Form = glamorous['Form'];
1605var Frame = glamorous['Frame'];
1606var Frameset = glamorous['Frameset'];
1607var H1 = glamorous['H1'];
1608var H2 = glamorous['H2'];
1609var H3 = glamorous['H3'];
1610var H4 = glamorous['H4'];
1611var H5 = glamorous['H5'];
1612var H6 = glamorous['H6'];
1613var Head = glamorous['Head'];
1614var Header = glamorous['Header'];
1615var Hgroup = glamorous['Hgroup'];
1616var Hr = glamorous['Hr'];
1617var Html = glamorous['Html'];
1618var I = glamorous['I'];
1619var Iframe = glamorous['Iframe'];
1620var Image = glamorous['Image'];
1621var Img = glamorous['Img'];
1622var Input = glamorous['Input'];
1623var Ins = glamorous['Ins'];
1624var Isindex = glamorous['Isindex'];
1625var Kbd = glamorous['Kbd'];
1626var Keygen = glamorous['Keygen'];
1627var Label = glamorous['Label'];
1628var Legend = glamorous['Legend'];
1629var Li = glamorous['Li'];
1630var Link = glamorous['Link'];
1631var Listing = glamorous['Listing'];
1632var Main = glamorous['Main'];
1633var MapTag = glamorous['Map'];
1634var Mark = glamorous['Mark'];
1635var Marquee = glamorous['Marquee'];
1636var MathTag = glamorous['Math'];
1637var Menu = glamorous['Menu'];
1638var Menuitem = glamorous['Menuitem'];
1639var Meta = glamorous['Meta'];
1640var Meter = glamorous['Meter'];
1641var Multicol = glamorous['Multicol'];
1642var Nav = glamorous['Nav'];
1643var Nextid = glamorous['Nextid'];
1644var Nobr = glamorous['Nobr'];
1645var Noembed = glamorous['Noembed'];
1646var Noframes = glamorous['Noframes'];
1647var Noscript = glamorous['Noscript'];
1648var ObjectTag = glamorous['Object'];
1649var Ol = glamorous['Ol'];
1650var Optgroup = glamorous['Optgroup'];
1651var Option = glamorous['Option'];
1652var Output = glamorous['Output'];
1653var P = glamorous['P'];
1654var Param = glamorous['Param'];
1655var Picture = glamorous['Picture'];
1656var Plaintext = glamorous['Plaintext'];
1657var Pre = glamorous['Pre'];
1658var Progress = glamorous['Progress'];
1659var Q = glamorous['Q'];
1660var Rb = glamorous['Rb'];
1661var Rbc = glamorous['Rbc'];
1662var Rp = glamorous['Rp'];
1663var Rt = glamorous['Rt'];
1664var Rtc = glamorous['Rtc'];
1665var Ruby = glamorous['Ruby'];
1666var S = glamorous['S'];
1667var Samp = glamorous['Samp'];
1668var Script = glamorous['Script'];
1669var Section = glamorous['Section'];
1670var Select = glamorous['Select'];
1671var Shadow = glamorous['Shadow'];
1672var Slot = glamorous['Slot'];
1673var Small = glamorous['Small'];
1674var Source = glamorous['Source'];
1675var Spacer = glamorous['Spacer'];
1676var Span = glamorous['Span'];
1677var Strike = glamorous['Strike'];
1678var Strong = glamorous['Strong'];
1679var Style = glamorous['Style'];
1680var Sub = glamorous['Sub'];
1681var Summary = glamorous['Summary'];
1682var Sup = glamorous['Sup'];
1683var Svg = glamorous['Svg'];
1684var Table = glamorous['Table'];
1685var Tbody = glamorous['Tbody'];
1686var Td = glamorous['Td'];
1687var Template = glamorous['Template'];
1688var Textarea = glamorous['Textarea'];
1689var Tfoot = glamorous['Tfoot'];
1690var Th = glamorous['Th'];
1691var Thead = glamorous['Thead'];
1692var Time = glamorous['Time'];
1693var Title = glamorous['Title'];
1694var Tr = glamorous['Tr'];
1695var Track = glamorous['Track'];
1696var Tt = glamorous['Tt'];
1697var U = glamorous['U'];
1698var Ul = glamorous['Ul'];
1699var Var = glamorous['Var'];
1700var Video = glamorous['Video'];
1701var Wbr = glamorous['Wbr'];
1702var Xmp = glamorous['Xmp'];
1703var AltGlyph = glamorous['AltGlyph'];
1704var AltGlyphDef = glamorous['AltGlyphDef'];
1705var AltGlyphItem = glamorous['AltGlyphItem'];
1706var Animate = glamorous['Animate'];
1707var AnimateColor = glamorous['AnimateColor'];
1708var AnimateMotion = glamorous['AnimateMotion'];
1709var AnimateTransform = glamorous['AnimateTransform'];
1710var Animation = glamorous['Animation'];
1711var Circle = glamorous['Circle'];
1712var ClipPath = glamorous['ClipPath'];
1713var ColorProfile = glamorous['Color-profile'];
1714var Cursor = glamorous['Cursor'];
1715var Defs = glamorous['Defs'];
1716var Desc = glamorous['Desc'];
1717var Discard = glamorous['Discard'];
1718var Ellipse = glamorous['Ellipse'];
1719var FeBlend = glamorous['FeBlend'];
1720var FeColorMatrix = glamorous['FeColorMatrix'];
1721var FeComponentTransfer = glamorous['FeComponentTransfer'];
1722var FeComposite = glamorous['FeComposite'];
1723var FeConvolveMatrix = glamorous['FeConvolveMatrix'];
1724var FeDiffuseLighting = glamorous['FeDiffuseLighting'];
1725var FeDisplacementMap = glamorous['FeDisplacementMap'];
1726var FeDistantLight = glamorous['FeDistantLight'];
1727var FeDropShadow = glamorous['FeDropShadow'];
1728var FeFlood = glamorous['FeFlood'];
1729var FeFuncA = glamorous['FeFuncA'];
1730var FeFuncB = glamorous['FeFuncB'];
1731var FeFuncG = glamorous['FeFuncG'];
1732var FeFuncR = glamorous['FeFuncR'];
1733var FeGaussianBlur = glamorous['FeGaussianBlur'];
1734var FeImage = glamorous['FeImage'];
1735var FeMerge = glamorous['FeMerge'];
1736var FeMergeNode = glamorous['FeMergeNode'];
1737var FeMorphology = glamorous['FeMorphology'];
1738var FeOffset = glamorous['FeOffset'];
1739var FePointLight = glamorous['FePointLight'];
1740var FeSpecularLighting = glamorous['FeSpecularLighting'];
1741var FeSpotLight = glamorous['FeSpotLight'];
1742var FeTile = glamorous['FeTile'];
1743var FeTurbulence = glamorous['FeTurbulence'];
1744var Filter = glamorous['Filter'];
1745var FontFace = glamorous['Font-face'];
1746var FontFaceFormat = glamorous['Font-face-format'];
1747var FontFaceName = glamorous['Font-face-name'];
1748var FontFaceSrc = glamorous['Font-face-src'];
1749var FontFaceUri = glamorous['Font-face-uri'];
1750var ForeignObject = glamorous['ForeignObject'];
1751var G = glamorous['G'];
1752var Glyph = glamorous['Glyph'];
1753var GlyphRef = glamorous['GlyphRef'];
1754var Handler = glamorous['Handler'];
1755var Hatch = glamorous['Hatch'];
1756var Hatchpath = glamorous['Hatchpath'];
1757var Hkern = glamorous['Hkern'];
1758var Line = glamorous['Line'];
1759var LinearGradient = glamorous['LinearGradient'];
1760var Listener = glamorous['Listener'];
1761var Marker = glamorous['Marker'];
1762var Mask = glamorous['Mask'];
1763var Mesh = glamorous['Mesh'];
1764var Meshgradient = glamorous['Meshgradient'];
1765var Meshpatch = glamorous['Meshpatch'];
1766var Meshrow = glamorous['Meshrow'];
1767var Metadata = glamorous['Metadata'];
1768var MissingGlyph = glamorous['Missing-glyph'];
1769var Mpath = glamorous['Mpath'];
1770var Path = glamorous['Path'];
1771var Pattern = glamorous['Pattern'];
1772var Polygon = glamorous['Polygon'];
1773var Polyline = glamorous['Polyline'];
1774var Prefetch = glamorous['Prefetch'];
1775var RadialGradient = glamorous['RadialGradient'];
1776var Rect = glamorous['Rect'];
1777var SetTag = glamorous['Set'];
1778var SolidColor = glamorous['SolidColor'];
1779var Solidcolor = glamorous['Solidcolor'];
1780var Stop = glamorous['Stop'];
1781var Switch = glamorous['Switch'];
1782var SymbolTag = glamorous['Symbol'];
1783var Tbreak = glamorous['Tbreak'];
1784var Text = glamorous['Text'];
1785var TextArea = glamorous['TextArea'];
1786var TextPath = glamorous['TextPath'];
1787var Tref = glamorous['Tref'];
1788var Tspan = glamorous['Tspan'];
1789var Unknown = glamorous['Unknown'];
1790var Use = glamorous['Use'];
1791var View = glamorous['View'];
1792var Vkern = glamorous['Vkern'];
1793
1794export default glamorous;
1795export { ThemeProvider, withTheme, 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, MapTag, Mark, Marquee, MathTag, Menu, Menuitem, Meta, Meter, Multicol, Nav, Nextid, Nobr, Noembed, Noframes, Noscript, ObjectTag, 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, AltGlyph, AltGlyphDef, AltGlyphItem, Animate, AnimateColor, AnimateMotion, AnimateTransform, Animation, Circle, ClipPath, ColorProfile, 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, FontFace, FontFaceFormat, FontFaceName, FontFaceSrc, FontFaceUri, ForeignObject, G, Glyph, GlyphRef, Handler, Hatch, Hatchpath, Hkern, Line, LinearGradient, Listener, Marker, Mask, Mesh, Meshgradient, Meshpatch, Meshrow, Metadata, MissingGlyph, Mpath, Path, Pattern, Polygon, Polyline, Prefetch, RadialGradient, Rect, SetTag, SolidColor, Solidcolor, Stop, Switch, SymbolTag, Tbreak, Text, TextArea, TextPath, Tref, Tspan, Unknown, Use, View, Vkern };