UNPKG

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