UNPKG

jeri

Version:

JavaScript Extended-Range Image viewer

1,585 lines (1,364 loc) • 261 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("react"), require("react-dom")); else if(typeof define === 'function' && define.amd) define("Jeri", ["react", "react-dom"], factory); else if(typeof exports === 'object') exports["Jeri"] = factory(require("react"), require("react-dom")); else root["Jeri"] = factory(root["React"], root["ReactDOM"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_0__, __WEBPACK_EXTERNAL_MODULE_15__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "./"; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 14); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_0__; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // Prototype identity matrix var IDENTITY4x4 = new Float32Array(16); for (var i = 0; i < 4; ++i) { IDENTITY4x4[i + 4 * i] = 1.0; } var Matrix4x4 = /** @class */ (function () { function Matrix4x4(buffer) { if (buffer === void 0) { buffer = IDENTITY4x4; } this.data = new Float32Array(buffer); } Matrix4x4.create = function () { return new Matrix4x4; }; Matrix4x4.fromScaling = function (matrix, scaling) { if (scaling.length !== 3) { throw new Error('Matrix4x4.fromScaling requires a 3-dimentional vector as input'); } scaling.forEach(function (scale, i) { matrix.data[i + 4 * i] = scale; }); }; Matrix4x4.multiply = function (output, a, b) { var data = new Float32Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); for (var i = 0; i < 4; ++i) { for (var j = 0; j < 4; ++j) { for (var k = 0; k < 4; ++k) { data[4 * j + i] += a.data[4 * k + i] * b.data[4 * j + k]; } } } output.data = data; }; Matrix4x4.scale = function (output, a, scale) { if (scale.length !== 3) { throw new Error('Matrix4x4.scale expects the third argument to have 3 numbers'); } var data = new Float32Array(a.data); for (var i = 0; i < 3; ++i) { for (var j = 0; j < 4; ++j) { data[4 * i + j] *= scale[i]; } } output.data = data; }; Matrix4x4.translate = function (output, a, translation) { if (translation.length !== 3) { throw new Error('Matrix4x4.translate expects the third argument to have 3 numbers'); } var data = new Float32Array(a.data); for (var i = 0; i < 4; ++i) { for (var j = 0; j < 3; ++j) { data[12 + i] += a.data[4 * j + i] * translation[j]; } } output.data = data; }; Matrix4x4.clone = function (a) { return new Matrix4x4(a.data); }; Matrix4x4.invert = function (output, matrix) { var m = matrix.data; var o = output.data; // tslint:disable:whitespace // tslint:disable:max-line-length o[0] = -m[7] * m[10] * m[13] + m[6] * m[11] * m[13] + m[7] * m[9] * m[14] - m[5] * m[11] * m[14] - m[6] * m[9] * m[15] + m[5] * m[10] * m[15]; o[1] = m[3] * m[10] * m[13] - m[2] * m[11] * m[13] - m[3] * m[9] * m[14] + m[1] * m[11] * m[14] + m[2] * m[9] * m[15] - m[1] * m[10] * m[15]; o[2] = -m[3] * m[6] * m[13] + m[2] * m[7] * m[13] + m[3] * m[5] * m[14] - m[1] * m[7] * m[14] - m[2] * m[5] * m[15] + m[1] * m[6] * m[15]; o[3] = m[3] * m[6] * m[9] - m[2] * m[7] * m[9] - m[3] * m[5] * m[10] + m[1] * m[7] * m[10] + m[2] * m[5] * m[11] - m[1] * m[6] * m[11]; o[4] = m[7] * m[10] * m[12] - m[6] * m[11] * m[12] - m[7] * m[8] * m[14] + m[4] * m[11] * m[14] + m[6] * m[8] * m[15] - m[4] * m[10] * m[15]; o[5] = -m[3] * m[10] * m[12] + m[2] * m[11] * m[12] + m[3] * m[8] * m[14] - m[0] * m[11] * m[14] - m[2] * m[8] * m[15] + m[0] * m[10] * m[15]; o[6] = m[3] * m[6] * m[12] - m[2] * m[7] * m[12] - m[3] * m[4] * m[14] + m[0] * m[7] * m[14] + m[2] * m[4] * m[15] - m[0] * m[6] * m[15]; o[7] = -m[3] * m[6] * m[8] + m[2] * m[7] * m[8] + m[3] * m[4] * m[10] - m[0] * m[7] * m[10] - m[2] * m[4] * m[11] + m[0] * m[6] * m[11]; o[8] = -m[7] * m[9] * m[12] + m[5] * m[11] * m[12] + m[7] * m[8] * m[13] - m[4] * m[11] * m[13] - m[5] * m[8] * m[15] + m[4] * m[9] * m[15]; o[9] = m[3] * m[9] * m[12] - m[1] * m[11] * m[12] - m[3] * m[8] * m[13] + m[0] * m[11] * m[13] + m[1] * m[8] * m[15] - m[0] * m[9] * m[15]; o[10] = -m[3] * m[5] * m[12] + m[1] * m[7] * m[12] + m[3] * m[4] * m[13] - m[0] * m[7] * m[13] - m[1] * m[4] * m[15] + m[0] * m[5] * m[15]; o[11] = m[3] * m[5] * m[8] - m[1] * m[7] * m[8] - m[3] * m[4] * m[9] + m[0] * m[7] * m[9] + m[1] * m[4] * m[11] - m[0] * m[5] * m[11]; o[12] = m[6] * m[9] * m[12] - m[5] * m[10] * m[12] - m[6] * m[8] * m[13] + m[4] * m[10] * m[13] + m[5] * m[8] * m[14] - m[4] * m[9] * m[14]; o[13] = -m[2] * m[9] * m[12] + m[1] * m[10] * m[12] + m[2] * m[8] * m[13] - m[0] * m[10] * m[13] - m[1] * m[8] * m[14] + m[0] * m[9] * m[14]; o[14] = m[2] * m[5] * m[12] - m[1] * m[6] * m[12] - m[2] * m[4] * m[13] + m[0] * m[6] * m[13] + m[1] * m[4] * m[14] - m[0] * m[5] * m[14]; o[15] = -m[2] * m[5] * m[8] + m[1] * m[6] * m[8] + m[2] * m[4] * m[9] - m[0] * m[6] * m[9] - m[1] * m[4] * m[10] + m[0] * m[5] * m[10]; // tslint:enable:whitespace // tslint:enable:max-line-length var determinant = m[0] * o[0] + m[1] * o[4] + m[2] * o[8] + m[3] * o[12]; if (determinant === 0.0) { throw new Error('Matrix is not invertible.'); } var inverseDeterminant = 1.0 / determinant; for (var i = 0; i < 16; ++i) { o[i] *= inverseDeterminant; } }; return Matrix4x4; }()); exports.Matrix4x4 = Matrix4x4; var Vector4 = /** @class */ (function () { function Vector4() { this.data = new Float32Array([0, 0, 0, 0]); } Vector4.create = function () { return new Vector4; }; Vector4.set = function (output, x, y, z, w) { output.data[0] = x; output.data[1] = y; output.data[2] = z; output.data[3] = w; }; Vector4.fromValues = function (x, y, z, w) { var vector = new Vector4; Vector4.set(vector, x, y, z, w); return vector; }; Vector4.transformMat4 = function (output, vector, matrix) { var v = vector.data; var m = matrix.data; var data = new Float32Array([0, 0, 0, 0]); for (var i = 0; i < 4; ++i) { for (var j = 0; j < 4; ++j) { data[i] += v[j] * m[4 * j + i]; } } output.data = data; }; return Vector4; }()); exports.Vector4 = Vector4; // function assertEqual(a: mat4 | vec4, b: Matrix4x4 | Vector4, message: string): void { // for (let i = 0; i < a.length; ++i) { // if (Math.abs(a[i] - b.data[i]) > 0.001) { // throw new Error('Failed:' + message + '\n' + a + '\n' + b.data); // } // } // } // function test() { // const a = mat4.create(); // const b = Matrix4x4.create(); // assertEqual(a, b, 'after creation'); // for (let ii = 0; ii < 16; ++ii) { // a[ii] = b.data[ii] = Math.random(); // } // const c = mat4.create(); // const d = Matrix4x4.create(); // mat4.fromScaling(c, [4, 3, 2]); // Matrix4x4.fromScaling(d, [4, 3, 2]); // assertEqual(c, d, 'fromScaling'); // mat4.translate(c, a, [2, 3, 4]); // Matrix4x4.translate(d, b, [2, 3, 4]); // // assertEqual(a, b, 'after translation ab'); // assertEqual(c, d, 'after translation cd'); // mat4.scale(a, c, [2, 3, 4]); // Matrix4x4.scale(b, d, [2, 3, 4]); // assertEqual(a, b, 'after scaling ab'); // // assertEqual(c, d, 'after scaling cd'); // mat4.translate(c, a, [2, 3, 4]); // Matrix4x4.translate(d, b, [2, 3, 4]); // // assertEqual(a, b, 'after translation again ab'); // assertEqual(c, d, 'after translation again cd'); // mat4.invert(a, c); // Matrix4x4.invert(b, d); // assertEqual(a, b, 'after invert ab'); // assertEqual(c, d, 'after invert cd'); // const e = mat4.create(); // const f = Matrix4x4.create(); // mat4.multiply(e, c, a); // Matrix4x4.multiply(f, d, b); // assertEqual(e, f, 'after multiply ef'); // assertEqual(c, d, 'after multiply cd'); // assertEqual(a, b, 'after multiply ab'); // mat4.scale(a, c, [5, -3, 4]); // Matrix4x4.scale(b, d, [5, -3, 4]); // assertEqual(a, b, 'after scaling again ab'); // assertEqual(c, d, 'after scaling again cd'); // // assertEqual(c, d, 'after scaling cd'); // const q = mat4.clone(a); // const i = Matrix4x4.clone(b); // assertEqual(q, i, 'after cloning'); // const v1 = vec4.create(); // const w1 = Vector4.create(); // assertEqual(v1, w1, 'vectors after init'); // vec4.set(v1, 3, 4, 5, 6); // Vector4.set(w1, 3, 4, 5, 6); // assertEqual(v1, w1, 'vectors after set'); // const v2 = vec4.fromValues(6, 5, 4, 3); // const w2 = Vector4.fromValues(6, 5, 4, 3); // assertEqual(v2, w2, 'vectors after fromValues'); // vec4.transformMat4(v1, v2, a); // Vector4.transformMat4(w1, w2, b); // assertEqual(v1, w1, 'vectors after tranformMat4'); // } /***/ }), /* 2 */ /***/ (function(module, exports) { // shim for using process in browser var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it // don't break things. But we need to wrap it in a try catch in case it is // wrapped in strict mode code which doesn't define any globals. It's inside a // function because try/catches deoptimize in certain engines. var cachedSetTimeout; var cachedClearTimeout; function defaultSetTimout() { throw new Error('setTimeout has not been defined'); } function defaultClearTimeout () { throw new Error('clearTimeout has not been defined'); } (function () { try { if (typeof setTimeout === 'function') { cachedSetTimeout = setTimeout; } else { cachedSetTimeout = defaultSetTimout; } } catch (e) { cachedSetTimeout = defaultSetTimout; } try { if (typeof clearTimeout === 'function') { cachedClearTimeout = clearTimeout; } else { cachedClearTimeout = defaultClearTimeout; } } catch (e) { cachedClearTimeout = defaultClearTimeout; } } ()) function runTimeout(fun) { if (cachedSetTimeout === setTimeout) { //normal enviroments in sane situations return setTimeout(fun, 0); } // if setTimeout wasn't available but was latter defined if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { cachedSetTimeout = setTimeout; return setTimeout(fun, 0); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedSetTimeout(fun, 0); } catch(e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedSetTimeout.call(null, fun, 0); } catch(e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error return cachedSetTimeout.call(this, fun, 0); } } } function runClearTimeout(marker) { if (cachedClearTimeout === clearTimeout) { //normal enviroments in sane situations return clearTimeout(marker); } // if clearTimeout wasn't available but was latter defined if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { cachedClearTimeout = clearTimeout; return clearTimeout(marker); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedClearTimeout(marker); } catch (e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedClearTimeout.call(null, marker); } catch (e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. // Some versions of I.E. have different rules for clearTimeout vs setTimeout return cachedClearTimeout.call(this, marker); } } } var queue = []; var draining = false; var currentQueue; var queueIndex = -1; function cleanUpNextTick() { if (!draining || !currentQueue) { return; } draining = false; if (currentQueue.length) { queue = currentQueue.concat(queue); } else { queueIndex = -1; } if (queue.length) { drainQueue(); } } function drainQueue() { if (draining) { return; } var timeout = runTimeout(cleanUpNextTick); draining = true; var len = queue.length; while(len) { currentQueue = queue; queue = []; while (++queueIndex < len) { if (currentQueue) { currentQueue[queueIndex].run(); } } queueIndex = -1; len = queue.length; } currentQueue = null; draining = false; runClearTimeout(timeout); } process.nextTick = function (fun) { var args = new Array(arguments.length - 1); if (arguments.length > 1) { for (var i = 1; i < arguments.length; i++) { args[i - 1] = arguments[i]; } } queue.push(new Item(fun, args)); if (queue.length === 1 && !draining) { runTimeout(drainQueue); } }; // v8 likes predictible objects function Item(fun, array) { this.fun = fun; this.array = array; } Item.prototype.run = function () { this.fun.apply(null, this.array); }; process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; process.version = ''; // empty string to avoid regexp issues process.versions = {}; function noop() {} process.on = noop; process.addListener = noop; process.once = noop; process.off = noop; process.removeListener = noop; process.removeAllListeners = noop; process.emit = noop; process.prependListener = noop; process.prependOnceListener = noop; process.listeners = function (name) { return [] } process.binding = function (name) { throw new Error('process.binding is not supported'); }; process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; process.umask = function() { return 0; }; /***/ }), /* 3 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); /* WEBPACK VAR INJECTION */(function(process) {/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "css", function() { return css; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "keyframes", function() { return keyframes; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "injectGlobal", function() { return injectGlobal; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ThemeProvider", function() { return ThemeProvider; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "withTheme", function() { return wrapWithTheme; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ServerStyleSheet", function() { return ServerStyleSheet; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "StyleSheetManager", function() { return StyleSheetManager; }); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_is_plain_object__ = __webpack_require__(23); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_is_plain_object___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_is_plain_object__); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_stylis__ = __webpack_require__(25); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_stylis___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_stylis__); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_react__ = __webpack_require__(0); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_react___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_react__); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_prop_types__ = __webpack_require__(26); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_prop_types___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_prop_types__); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_is_function__ = __webpack_require__(31); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_is_function___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_4_is_function__); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_hoist_non_react_statics__ = __webpack_require__(32); /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_hoist_non_react_statics___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_5_hoist_non_react_statics__); /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * * @typechecks */ var _uppercasePattern = /([A-Z])/g; /** * Hyphenates a camelcased string, for example: * * > hyphenate('backgroundColor') * < "background-color" * * For CSS style names, use `hyphenateStyleName` instead which works properly * with all vendor prefixes, including `ms`. * * @param {string} string * @return {string} */ function hyphenate$2(string) { return string.replace(_uppercasePattern, '-$1').toLowerCase(); } var hyphenate_1 = hyphenate$2; var hyphenate = hyphenate_1; var msPattern = /^ms-/; /** * Hyphenates a camelcased CSS property name, for example: * * > hyphenateStyleName('backgroundColor') * < "background-color" * > hyphenateStyleName('MozTransition') * < "-moz-transition" * > hyphenateStyleName('msTransition') * < "-ms-transition" * * As Modernizr suggests (http://modernizr.com/docs/#prefixed), an `ms` prefix * is converted to `-ms-`. * * @param {string} string * @return {string} */ function hyphenateStyleName(string) { return hyphenate(string).replace(msPattern, '-ms-'); } var hyphenateStyleName_1 = hyphenateStyleName; // var objToCss = function objToCss(obj, prevKey) { var css = Object.keys(obj).filter(function (key) { var chunk = obj[key]; return chunk !== undefined && chunk !== null && chunk !== false && chunk !== ''; }).map(function (key) { if (__WEBPACK_IMPORTED_MODULE_0_is_plain_object___default()(obj[key])) return objToCss(obj[key], key); return hyphenateStyleName_1(key) + ': ' + obj[key] + ';'; }).join(' '); return prevKey ? prevKey + ' {\n ' + css + '\n}' : css; }; var flatten = function flatten(chunks, executionContext) { return chunks.reduce(function (ruleSet, chunk) { /* Remove falsey values */ if (chunk === undefined || chunk === null || chunk === false || chunk === '') return ruleSet; /* Flatten ruleSet */ if (Array.isArray(chunk)) return [].concat(ruleSet, flatten(chunk, executionContext)); /* Handle other components */ // $FlowFixMe not sure how to make this pass if (chunk.hasOwnProperty('styledComponentId')) return [].concat(ruleSet, ['.' + chunk.styledComponentId]); /* Either execute or defer the function */ if (typeof chunk === 'function') { return executionContext ? ruleSet.concat.apply(ruleSet, flatten([chunk(executionContext)], executionContext)) : ruleSet.concat(chunk); } /* Handle objects */ // $FlowFixMe have to add %checks somehow to isPlainObject return ruleSet.concat(__WEBPACK_IMPORTED_MODULE_0_is_plain_object___default()(chunk) ? objToCss(chunk) : chunk.toString()); }, []); }; // var stylis = new __WEBPACK_IMPORTED_MODULE_1_stylis___default.a({ global: false, cascade: true, keyframe: false, prefix: true, compress: false, semicolon: true }); var stringifyRules = function stringifyRules(rules, selector, prefix) { var flatCSS = rules.join('').replace(/^\s*\/\/.*$/gm, ''); // replace JS comments var cssStr = selector && prefix ? prefix + ' ' + selector + ' { ' + flatCSS + ' }' : flatCSS; return stylis(prefix || !selector ? '' : selector, cssStr); }; // var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); var charsLength = chars.length; /* Some high number, usually 9-digit base-10. Map it to base-šŸ˜Ž */ var generateAlphabeticName = function generateAlphabeticName(code) { var name = ''; var x = void 0; for (x = code; x > charsLength; x = Math.floor(x / charsLength)) { name = chars[x % charsLength] + name; } return chars[x % charsLength] + name; }; // var interleave = (function (strings, interpolations) { return interpolations.reduce(function (array, interp, i) { return array.concat(interp, strings[i + 1]); }, [strings[0]]); }); // var css = (function (strings) { for (var _len = arguments.length, interpolations = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { interpolations[_key - 1] = arguments[_key]; } return flatten(interleave(strings, interpolations)); }); // var SC_COMPONENT_ID = /^[^\S\n]*?\/\* sc-component-id:\s+(\S+)\s+\*\//mg; var extractCompsFromCSS = (function (maybeCSS) { var css = '' + (maybeCSS || ''); // Definitely a string, and a clone var existingComponents = []; css.replace(SC_COMPONENT_ID, function (match, componentId, matchIndex) { existingComponents.push({ componentId: componentId, matchIndex: matchIndex }); return match; }); return existingComponents.map(function (_ref, i) { var componentId = _ref.componentId, matchIndex = _ref.matchIndex; var nextComp = existingComponents[i + 1]; var cssFromDOM = nextComp ? css.slice(matchIndex, nextComp.matchIndex) : css.slice(matchIndex); return { componentId: componentId, cssFromDOM: cssFromDOM }; }); }); // /* eslint-disable camelcase, no-undef */ var getNonce = (function () { return true ? __webpack_require__.nc : null; }); var classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; var createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }; var objectWithoutProperties = function (obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }; var possibleConstructorReturn = function (self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }; // /* eslint-disable no-underscore-dangle */ /* * Browser Style Sheet with Rehydration * * <style data-styled-components="x y z" * data-styled-components-is-local="true"> * /Ā· sc-component-id: a Ā·/ * .sc-a { ... } * .x { ... } * /Ā· sc-component-id: b Ā·/ * .sc-b { ... } * .y { ... } * .z { ... } * </style> * * Note: replace Ā· with * in the above snippet. * */ var COMPONENTS_PER_TAG = 40; var BrowserTag = function () { function BrowserTag(el, isLocal) { var existingSource = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; classCallCheck(this, BrowserTag); this.el = el; this.isLocal = isLocal; this.ready = false; var extractedComps = extractCompsFromCSS(existingSource); this.size = extractedComps.length; this.components = extractedComps.reduce(function (acc, obj) { acc[obj.componentId] = obj; // eslint-disable-line no-param-reassign return acc; }, {}); } BrowserTag.prototype.isFull = function isFull() { return this.size >= COMPONENTS_PER_TAG; }; BrowserTag.prototype.addComponent = function addComponent(componentId) { if (!this.ready) this.replaceElement(); if (this.components[componentId]) throw new Error('Trying to add Component \'' + componentId + '\' twice!'); var comp = { componentId: componentId, textNode: document.createTextNode('') }; this.el.appendChild(comp.textNode); this.size += 1; this.components[componentId] = comp; }; BrowserTag.prototype.inject = function inject(componentId, css, name) { if (!this.ready) this.replaceElement(); var comp = this.components[componentId]; if (!comp) throw new Error('Must add a new component before you can inject css into it'); if (comp.textNode.data === '') comp.textNode.appendData('\n/* sc-component-id: ' + componentId + ' */\n'); comp.textNode.appendData(css); if (name) { var existingNames = this.el.getAttribute(SC_ATTR); this.el.setAttribute(SC_ATTR, existingNames ? existingNames + ' ' + name : name); } var nonce = getNonce(); if (nonce) { this.el.setAttribute('nonce', nonce); } }; BrowserTag.prototype.toHTML = function toHTML() { return this.el.outerHTML; }; BrowserTag.prototype.toReactElement = function toReactElement() { throw new Error('BrowserTag doesn\'t implement toReactElement!'); }; BrowserTag.prototype.clone = function clone() { throw new Error('BrowserTag cannot be cloned!'); }; /* Because we care about source order, before we can inject anything we need to * create a text node for each component and replace the existing CSS. */ BrowserTag.prototype.replaceElement = function replaceElement() { var _this = this; this.ready = true; // We have nothing to inject. Use the current el. if (this.size === 0) return; // Build up our replacement style tag var newEl = this.el.cloneNode(); newEl.appendChild(document.createTextNode('\n')); Object.keys(this.components).forEach(function (key) { var comp = _this.components[key]; // eslint-disable-next-line no-param-reassign comp.textNode = document.createTextNode(comp.cssFromDOM); newEl.appendChild(comp.textNode); }); if (!this.el.parentNode) throw new Error("Trying to replace an element that wasn't mounted!"); // The ol' switcheroo this.el.parentNode.replaceChild(newEl, this.el); this.el = newEl; }; return BrowserTag; }(); /* Factory function to separate DOM operations from logical ones*/ var BrowserStyleSheet = { create: function create() { var tags = []; var names = {}; /* Construct existing state from DOM */ var nodes = document.querySelectorAll('[' + SC_ATTR + ']'); var nodesLength = nodes.length; for (var i = 0; i < nodesLength; i += 1) { var el = nodes[i]; tags.push(new BrowserTag(el, el.getAttribute(LOCAL_ATTR) === 'true', el.innerHTML)); var attr = el.getAttribute(SC_ATTR); if (attr) { attr.trim().split(/\s+/).forEach(function (name) { names[name] = true; }); } } /* Factory for making more tags */ var tagConstructor = function tagConstructor(isLocal) { var el = document.createElement('style'); el.type = 'text/css'; el.setAttribute(SC_ATTR, ''); el.setAttribute(LOCAL_ATTR, isLocal ? 'true' : 'false'); if (!document.head) throw new Error('Missing document <head>'); document.head.appendChild(el); return new BrowserTag(el, isLocal); }; return new StyleSheet(tagConstructor, tags, names); } }; // var SC_ATTR = 'data-styled-components'; var LOCAL_ATTR = 'data-styled-components-is-local'; var CONTEXT_KEY = '__styled-components-stylesheet__'; var instance = null; // eslint-disable-next-line no-use-before-define var clones = []; var StyleSheet = function () { function StyleSheet(tagConstructor) { var tags = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; var names = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; classCallCheck(this, StyleSheet); this.hashes = {}; this.deferredInjections = {}; this.stylesCacheable = typeof document !== 'undefined'; this.tagConstructor = tagConstructor; this.tags = tags; this.names = names; this.constructComponentTagMap(); } // helper for `ComponentStyle` to know when it cache static styles. // staticly styled-component can not safely cache styles on the server // without all `ComponentStyle` instances saving a reference to the // the styleSheet instance they last rendered with, // or listening to creation / reset events. otherwise you might create // a component with one stylesheet and render it another api response // with another, losing styles on from your server-side render. StyleSheet.prototype.constructComponentTagMap = function constructComponentTagMap() { var _this = this; this.componentTags = {}; this.tags.forEach(function (tag) { Object.keys(tag.components).forEach(function (componentId) { _this.componentTags[componentId] = tag; }); }); }; /* Best level of caching—get the name from the hash straight away. */ StyleSheet.prototype.getName = function getName(hash) { return this.hashes[hash.toString()]; }; /* Second level of caching—if the name is already in the dom, don't * inject anything and record the hash for getName next time. */ StyleSheet.prototype.alreadyInjected = function alreadyInjected(hash, name) { if (!this.names[name]) return false; this.hashes[hash.toString()] = name; return true; }; /* Third type of caching—don't inject components' componentId twice. */ StyleSheet.prototype.hasInjectedComponent = function hasInjectedComponent(componentId) { return !!this.componentTags[componentId]; }; StyleSheet.prototype.deferredInject = function deferredInject(componentId, isLocal, css) { if (this === instance) { clones.forEach(function (clone) { clone.deferredInject(componentId, isLocal, css); }); } this.getOrCreateTag(componentId, isLocal); this.deferredInjections[componentId] = css; }; StyleSheet.prototype.inject = function inject(componentId, isLocal, css, hash, name) { if (this === instance) { clones.forEach(function (clone) { clone.inject(componentId, isLocal, css); }); } var tag = this.getOrCreateTag(componentId, isLocal); var deferredInjection = this.deferredInjections[componentId]; if (deferredInjection) { tag.inject(componentId, deferredInjection); delete this.deferredInjections[componentId]; } tag.inject(componentId, css, name); if (hash && name) { this.hashes[hash.toString()] = name; } }; StyleSheet.prototype.toHTML = function toHTML() { return this.tags.map(function (tag) { return tag.toHTML(); }).join(''); }; StyleSheet.prototype.toReactElements = function toReactElements() { return this.tags.map(function (tag, i) { return tag.toReactElement('sc-' + i); }); }; StyleSheet.prototype.getOrCreateTag = function getOrCreateTag(componentId, isLocal) { var existingTag = this.componentTags[componentId]; if (existingTag) { return existingTag; } var lastTag = this.tags[this.tags.length - 1]; var componentTag = !lastTag || lastTag.isFull() || lastTag.isLocal !== isLocal ? this.createNewTag(isLocal) : lastTag; this.componentTags[componentId] = componentTag; componentTag.addComponent(componentId); return componentTag; }; StyleSheet.prototype.createNewTag = function createNewTag(isLocal) { var newTag = this.tagConstructor(isLocal); this.tags.push(newTag); return newTag; }; StyleSheet.reset = function reset(isServer) { instance = StyleSheet.create(isServer); }; /* We can make isServer totally implicit once Jest 20 drops and we * can change environment on a per-test basis. */ StyleSheet.create = function create() { var isServer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : typeof document === 'undefined'; return (isServer ? ServerStyleSheet : BrowserStyleSheet).create(); }; StyleSheet.clone = function clone(oldSheet) { var newSheet = new StyleSheet(oldSheet.tagConstructor, oldSheet.tags.map(function (tag) { return tag.clone(); }), _extends({}, oldSheet.names)); newSheet.hashes = _extends({}, oldSheet.hashes); newSheet.deferredInjections = _extends({}, oldSheet.deferredInjections); clones.push(newSheet); return newSheet; }; createClass(StyleSheet, null, [{ key: 'instance', get: function get$$1() { return instance || (instance = StyleSheet.create()); } }]); return StyleSheet; }(); var _StyleSheetManager$ch; // var StyleSheetManager = function (_Component) { inherits(StyleSheetManager, _Component); function StyleSheetManager() { classCallCheck(this, StyleSheetManager); return possibleConstructorReturn(this, _Component.apply(this, arguments)); } StyleSheetManager.prototype.getChildContext = function getChildContext() { var _ref; return _ref = {}, _ref[CONTEXT_KEY] = this.props.sheet, _ref; }; StyleSheetManager.prototype.render = function render() { /* eslint-disable react/prop-types */ // Flow v0.43.1 will report an error accessing the `children` property, // but v0.47.0 will not. It is necessary to use a type cast instead of // a "fixme" comment to satisfy both Flow versions. return __WEBPACK_IMPORTED_MODULE_2_react___default.a.Children.only(this.props.children); }; return StyleSheetManager; }(__WEBPACK_IMPORTED_MODULE_2_react__["Component"]); StyleSheetManager.childContextTypes = (_StyleSheetManager$ch = {}, _StyleSheetManager$ch[CONTEXT_KEY] = __WEBPACK_IMPORTED_MODULE_3_prop_types___default.a.oneOfType([__WEBPACK_IMPORTED_MODULE_3_prop_types___default.a.instanceOf(StyleSheet), __WEBPACK_IMPORTED_MODULE_3_prop_types___default.a.instanceOf(ServerStyleSheet)]).isRequired, _StyleSheetManager$ch); StyleSheetManager.propTypes = { sheet: __WEBPACK_IMPORTED_MODULE_3_prop_types___default.a.oneOfType([__WEBPACK_IMPORTED_MODULE_3_prop_types___default.a.instanceOf(StyleSheet), __WEBPACK_IMPORTED_MODULE_3_prop_types___default.a.instanceOf(ServerStyleSheet)]).isRequired }; // /* eslint-disable no-underscore-dangle */ var ServerTag = function () { function ServerTag(isLocal) { classCallCheck(this, ServerTag); this.isLocal = isLocal; this.components = {}; this.size = 0; this.names = []; } ServerTag.prototype.isFull = function isFull() { return false; }; ServerTag.prototype.addComponent = function addComponent(componentId) { if (this.components[componentId]) throw new Error('Trying to add Component \'' + componentId + '\' twice!'); this.components[componentId] = { componentId: componentId, css: '' }; this.size += 1; }; ServerTag.prototype.concatenateCSS = function concatenateCSS() { var _this = this; return Object.keys(this.components).reduce(function (styles, k) { return styles + _this.components[k].css; }, ''); }; ServerTag.prototype.inject = function inject(componentId, css, name) { var comp = this.components[componentId]; if (!comp) throw new Error('Must add a new component before you can inject css into it'); if (comp.css === '') comp.css = '/* sc-component-id: ' + componentId + ' */\n'; comp.css += css.replace(/\n*$/, '\n'); if (name) this.names.push(name); }; ServerTag.prototype.toHTML = function toHTML() { var attrs = ['type="text/css"', SC_ATTR + '="' + this.names.join(' ') + '"', LOCAL_ATTR + '="' + (this.isLocal ? 'true' : 'false') + '"']; var nonce = getNonce(); if (nonce) { attrs.push('nonce="' + nonce + '"'); } return '<style ' + attrs.join(' ') + '>' + this.concatenateCSS() + '</style>'; }; ServerTag.prototype.toReactElement = function toReactElement(key) { var _attrs; var attrs = (_attrs = {}, _attrs[SC_ATTR] = this.names.join(' '), _attrs[LOCAL_ATTR] = this.isLocal.toString(), _attrs); var nonce = getNonce(); if (nonce) { attrs.nonce = nonce; } return __WEBPACK_IMPORTED_MODULE_2_react___default.a.createElement('style', _extends({ key: key, type: 'text/css' }, attrs, { dangerouslySetInnerHTML: { __html: this.concatenateCSS() } })); }; ServerTag.prototype.clone = function clone() { var _this2 = this; var copy = new ServerTag(this.isLocal); copy.names = [].concat(this.names); copy.size = this.size; copy.components = Object.keys(this.components).reduce(function (acc, key) { acc[key] = _extends({}, _this2.components[key]); // eslint-disable-line no-param-reassign return acc; }, {}); return copy; }; return ServerTag; }(); var ServerStyleSheet = function () { function ServerStyleSheet() { classCallCheck(this, ServerStyleSheet); this.instance = StyleSheet.clone(StyleSheet.instance); } ServerStyleSheet.prototype.collectStyles = function collectStyles(children) { if (this.closed) throw new Error("Can't collect styles once you've called getStyleTags!"); return __WEBPACK_IMPORTED_MODULE_2_react___default.a.createElement( StyleSheetManager, { sheet: this.instance }, children ); }; ServerStyleSheet.prototype.getStyleTags = function getStyleTags() { if (!this.closed) { clones.splice(clones.indexOf(this.instance), 1); this.closed = true; } return this.instance.toHTML(); }; ServerStyleSheet.prototype.getStyleElement = function getStyleElement() { if (!this.closed) { clones.splice(clones.indexOf(this.instance), 1); this.closed = true; } return this.instance.toReactElements(); }; ServerStyleSheet.create = function create() { return new StyleSheet(function (isLocal) { return new ServerTag(isLocal); }); }; return ServerStyleSheet; }(); // var LIMIT = 200; var createWarnTooManyClasses = (function (displayName) { var generatedClasses = {}; var warningSeen = false; return function (className) { if (!warningSeen) { generatedClasses[className] = true; if (Object.keys(generatedClasses).length >= LIMIT) { // Unable to find latestRule in test environment. /* eslint-disable no-console, prefer-template */ console.warn('Over ' + LIMIT + ' classes were generated for component ' + displayName + '. \n' + 'Consider using the attrs method, together with a style object for frequently changed styles.\n' + 'Example:\n' + ' const Component = styled.div.attrs({\n' + ' style: ({ background }) => ({\n' + ' background,\n' + ' }),\n' + ' })`width: 100%;`\n\n' + ' <Component />'); warningSeen = true; generatedClasses = {}; } } }; }); // /* Trying to avoid the unknown-prop errors on styled components by filtering by React's attribute whitelist. */ /* Logic copied from ReactDOMUnknownPropertyHook */ var reactProps = { children: true, dangerouslySetInnerHTML: true, key: true, ref: true, autoFocus: true, defaultValue: true, valueLink: true, defaultChecked: true, checkedLink: true, innerHTML: true, suppressContentEditableWarning: true, onFocusIn: true, onFocusOut: true, className: true, /* List copied from https://facebook.github.io/react/docs/events.html */ onCopy: true, onCut: true, onPaste: true, onCompositionEnd: true, onCompositionStart: true, onCompositionUpdate: true, onKeyDown: true, onKeyPress: true, onKeyUp: true, onFocus: true, onBlur: true, onChange: true, onInput: true, onSubmit: true, onReset: true, onClick: true, onContextMenu: true, onDoubleClick: true, onDrag: true, onDragEnd: true, onDragEnter: true, onDragExit: true, onDragLeave: true, onDragOver: true, onDragStart: true, onDrop: true, onMouseDown: true, onMouseEnter: true, onMouseLeave: true, onMouseMove: true, onMouseOut: true, onMouseOver: true, onMouseUp: true, onSelect: true, onTouchCancel: true, onTouchEnd: true, onTouchMove: true, onTouchStart: true, onScroll: true, onWheel: true, onAbort: true, onCanPlay: true, onCanPlayThrough: true, onDurationChange: true, onEmptied: true, onEncrypted: true, onEnded: true, onError: true, onLoadedData: true, onLoadedMetadata: true, onLoadStart: true, onPause: true, onPlay: true, onPlaying: true, onProgress: true, onRateChange: true, onSeeked: true, onSeeking: true, onStalled: true, onSuspend: true, onTimeUpdate: true, onVolumeChange: true, onWaiting: true, onLoad: true, onAnimationStart: true, onAnimationEnd: true, onAnimationIteration: true, onTransitionEnd: true, onCopyCapture: true, onCutCapture: true, onPasteCapture: true, onCompositionEndCapture: true, onCompositionStartCapture: true, onCompositionUpdateCapture: true, onKeyDownCapture: true, onKeyPressCapture: true, onKeyUpCapture: true, onFocusCapture: true, onBlurCapture: true, onChangeCapture: true, onInputCapture: true, onSubmitCapture: true, onResetCapture: true, onClickCapture: true, onContextMenuCapture: true, onDoubleClickCapture: true, onDragCapture: true, onDragEndCapture: true, onDragEnterCapture: true, onDragExitCapture: true, onDragLeaveCapture: true, onDragOverCapture: true, onDragStartCapture: true, onDropCapture: true, onMouseDownCapture: true, onMouseEnterCapture: true, onMouseLeaveCapture: true, onMouseMoveCapture: true, onMouseOutCapture: true, onMouseOverCapture: true, onMouseUpCapture: true, onSelectCapture: true, onTouchCancelCapture: true, onTouchEndCapture: true, onTouchMoveCapture: true, onTouchStartCapture: true, onScrollCapture: true, onWheelCapture: true, onAbortCapture: true, onCanPlayCapture: true, onCanPlayThroughCapture: true, onDurationChangeCapture: true, onEmptiedCapture: true, onEncryptedCapture: true, onEndedCapture: true, onErrorCapture: true, onLoadedDataCapture: true, onLoadedMetadataCapture: true, onLoadStartCapture: true, onPauseCapture: true, onPlayCapture: true, onPlayingCapture: true, onProgressCapture: true, onRateChangeCapture: true, onSeekedCapture: true, onSeekingCapture: true, onStalledCapture: true, onSuspendCapture: true, onTimeUpdateCapture: true, onVolumeChangeCapture: true, onWaitingCapture: true, onLoadCapture: true, onAnimationStartCapture: true, onAnimationEndCapture: true, onAnimationIterationCapture: true, onTransitionEndCapture: true }; /* From HTMLDOMPropertyConfig */ var htmlProps = { /** * Standard Properties */ accept: true, acceptCharset: true, accessKey: true, action: true, allowFullScreen: true, allowTransparency: true, alt: true, // specifies target context for links with `preload` type as: true, async: true, autoComplete: true, // autoFocus is polyfilled/normalized by AutoFocusUtils // autoFocus: true, autoPlay: true, capture: true, cellPadding: true, cellSpacing: true, charSet: true, challenge: true, checked: true, cite: true, classID: true, className: true, cols: true, colSpan: true, content: true, contentEditable: true, contextMenu: true, controls: true, coords: true, crossOrigin: true, data: true, // For `<object />` acts as `src`. dateTime: true, default: true, defer: true, dir: true, disabled: true, download: true, draggable: true, encType: true, form: true, formAction: true, formEncType: true, formMethod: true, formNoValidate: true, formTarget: true, frameBorder: true, headers: true, height: true, hidden: true, high: true, href: true, hrefLang: true, htmlFor: true, httpEquiv: true, icon: true, id: true, inputMode: true, integrity: true, is: true, keyParams: true, keyType: true, kind: true, label: true, lang: true, list: true, loop: true, low: true, manifest: true, marginHeight: true, marginWidth: true, max: true, maxLength: true, media: true, mediaGroup: true, method: true, min: true, minLength: true, // Caution; `option.selected` is not updated if `select.multiple` is // disabled with `removeAttribute`. multiple: true, muted: true, name: true, nonce: true, noValidate: true, open: true, optimum: true, pattern: true, placeholder: true, playsInline: true, poster: true, preload: true, profile: true, radioGroup: true, readOnly: true, referrerPolicy: true, rel: true, required: true, reversed: true, role: true, rows: true, rowSpan: true, sandbox: true, scope: true, scoped: true, scrolling: true, seamless: true, selected: true, shape: true, size: true, sizes: true, span: true, spellCheck: true, src: true, srcDoc: true, srcLang: true, srcSet: true, start: true, step: true, style: true, summary: true, tabIndex: true, target: true, title: true, // Setting .type throws on non-<input> tags type: true, useMap: true, value: true, width: true, wmode: true, wrap: true, /** * RDFa Properties */ about: true, datatype: true, inlist: true, prefix: true, // property is also supported for OpenGraph in meta tags. property: true, resource: true, typeof: true, vocab