1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6 |
|
7 | require('./slicedToArray-0711941d.js');
|
8 | require('./unsupportedIterableToArray-68db1d3b.js');
|
9 | var React = require('react');
|
10 | var React__default = _interopDefault(React);
|
11 | var _commonjsHelpers = require('./_commonjsHelpers-72d386ba.js');
|
12 | var index = require('./index-b0606964.js');
|
13 | var defineProperty = require('./defineProperty-0921a47c.js');
|
14 | require('./toConsumableArray-d8a4a2c3.js');
|
15 | var _styled = require('styled-components');
|
16 | var _styled__default = _interopDefault(_styled);
|
17 | var getPrototypeOf = require('./getPrototypeOf-2a661a20.js');
|
18 | require('./color.js');
|
19 | var components = require('./components.js');
|
20 | require('./contains-component.js');
|
21 | require('./css.js');
|
22 | require('./dayjs.min-e07657bf.js');
|
23 | require('./date.js');
|
24 | require('./miscellaneous.js');
|
25 | require('./environment.js');
|
26 | require('./font.js');
|
27 | require('./math-f4029164.js');
|
28 | require('./characters.js');
|
29 | require('./format.js');
|
30 | require('./keycodes.js');
|
31 | require('./url.js');
|
32 | var web3 = require('./web3.js');
|
33 | var _extends = require('./extends-40571110.js');
|
34 | var taggedTemplateLiteral = require('./taggedTemplateLiteral-227ed122.js');
|
35 | require('./_react_commonjs-external-bf8fc71c.js');
|
36 |
|
37 | var main = _commonjsHelpers.createCommonjsModule(function (module, exports) {
|
38 |
|
39 | Object.defineProperty(exports, "__esModule", {
|
40 | value: true
|
41 | });
|
42 |
|
43 | 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; };
|
44 |
|
45 | 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; }; }();
|
46 |
|
47 |
|
48 |
|
49 | var _react2 = _interopRequireDefault(React__default);
|
50 |
|
51 |
|
52 |
|
53 | var _propTypes2 = _interopRequireDefault(index.PropTypes);
|
54 |
|
55 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
56 |
|
57 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
58 |
|
59 | function _possibleConstructorReturn(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; }
|
60 |
|
61 | function _inherits(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; }
|
62 |
|
63 | var Identicon = function (_Component) {
|
64 | _inherits(Identicon, _Component);
|
65 |
|
66 | function Identicon(props) {
|
67 | _classCallCheck(this, Identicon);
|
68 |
|
69 | var _this = _possibleConstructorReturn(this, (Identicon.__proto__ || Object.getPrototypeOf(Identicon)).call(this, props));
|
70 |
|
71 | _this.generateIdenticon = _this.generateIdenticon.bind(_this);
|
72 | return _this;
|
73 | }
|
74 |
|
75 | _createClass(Identicon, [{
|
76 | key: 'componentDidMount',
|
77 | value: function componentDidMount() {
|
78 | this.generateIdenticon(_extends({}, this.props));
|
79 | }
|
80 | }, {
|
81 | key: 'componentWillUpdate',
|
82 | value: function componentWillUpdate(nextProps) {
|
83 | if (!this.isEquivalent(this.props, nextProps)) this.generateIdenticon(_extends({}, nextProps));
|
84 | }
|
85 | }, {
|
86 | key: 'isEquivalent',
|
87 | value: function isEquivalent(prevProps, nextProps) {
|
88 | var aProps = Object.getOwnPropertyNames(prevProps);
|
89 | var bProps = Object.getOwnPropertyNames(nextProps);
|
90 |
|
91 | if (aProps.length != bProps.length) {
|
92 | return false;
|
93 | }
|
94 |
|
95 | for (var i = 0; i < aProps.length; i++) {
|
96 | var propName = aProps[i];
|
97 |
|
98 | if (prevProps[propName] !== nextProps[propName]) {
|
99 | return false;
|
100 | }
|
101 | }
|
102 |
|
103 | return true;
|
104 | }
|
105 | }, {
|
106 | key: 'generateIdenticon',
|
107 | value: function generateIdenticon(options) {
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | var randseed = new Array(4);
|
113 |
|
114 | function seedrand(seed) {
|
115 | for (var i = 0; i < randseed.length; i++) {
|
116 | randseed[i] = 0;
|
117 | }
|
118 | for (var _i = 0; _i < seed.length; _i++) {
|
119 | randseed[_i % 4] = (randseed[_i % 4] << 5) - randseed[_i % 4] + seed.charCodeAt(_i);
|
120 | }
|
121 | }
|
122 |
|
123 | function rand() {
|
124 |
|
125 | var t = randseed[0] ^ randseed[0] << 11;
|
126 |
|
127 | randseed[0] = randseed[1];
|
128 | randseed[1] = randseed[2];
|
129 | randseed[2] = randseed[3];
|
130 | randseed[3] = randseed[3] ^ randseed[3] >> 19 ^ t ^ t >> 8;
|
131 |
|
132 | return (randseed[3] >>> 0) / (1 << 31 >>> 0);
|
133 | }
|
134 |
|
135 | function createColor() {
|
136 |
|
137 | var h = Math.floor(rand() * 360);
|
138 |
|
139 | var s = rand() * 60 + 40 + '%';
|
140 |
|
141 | var l = (rand() + rand() + rand() + rand()) * 25 + '%';
|
142 |
|
143 | var color = 'hsl(' + h + ',' + s + ',' + l + ')';
|
144 | return color;
|
145 | }
|
146 |
|
147 | function createImageData(size) {
|
148 | var width = size;
|
149 | var height = size;
|
150 |
|
151 | var dataWidth = Math.ceil(width / 2);
|
152 | var mirrorWidth = width - dataWidth;
|
153 |
|
154 | var data = [];
|
155 | for (var y = 0; y < height; y++) {
|
156 | var row = [];
|
157 | for (var x = 0; x < dataWidth; x++) {
|
158 |
|
159 |
|
160 | row[x] = Math.floor(rand() * 2.3);
|
161 | }
|
162 | var r = row.slice(0, mirrorWidth);
|
163 | r.reverse();
|
164 | row = row.concat(r);
|
165 |
|
166 | for (var i = 0; i < row.length; i++) {
|
167 | data.push(row[i]);
|
168 | }
|
169 | }
|
170 |
|
171 | return data;
|
172 | }
|
173 |
|
174 | function setCanvas(identicon, imageData, color, scale, bgcolor, spotcolor) {
|
175 | var width = Math.sqrt(imageData.length);
|
176 | var size = width * scale;
|
177 |
|
178 | identicon.width = size;
|
179 | identicon.style.width = size + 'px';
|
180 |
|
181 | identicon.height = size;
|
182 | identicon.style.height = size + 'px';
|
183 |
|
184 | var cc = identicon.getContext('2d');
|
185 | cc.fillStyle = bgcolor;
|
186 | cc.fillRect(0, 0, identicon.width, identicon.height);
|
187 | cc.fillStyle = color;
|
188 |
|
189 | for (var i = 0; i < imageData.length; i++) {
|
190 |
|
191 | cc.fillStyle = imageData[i] === 1 ? color : spotcolor;
|
192 |
|
193 |
|
194 | if (imageData[i]) {
|
195 | var row = Math.floor(i / width);
|
196 | var col = i % width;
|
197 |
|
198 | cc.fillRect(col * scale, row * scale, scale, scale);
|
199 | }
|
200 | }
|
201 | }
|
202 |
|
203 | var opts = options || {};
|
204 | var size = opts.size || 8;
|
205 | var scale = opts.scale || 4;
|
206 | var seed = opts.seed || Math.floor(Math.random() * Math.pow(10, 16)).toString(16);
|
207 |
|
208 | seedrand(seed);
|
209 |
|
210 | var color = opts.color || createColor();
|
211 | var bgcolor = opts.bgColor || createColor();
|
212 | var spotcolor = opts.spotColor || createColor();
|
213 | var imageData = createImageData(size);
|
214 | var canvas = setCanvas(this.identicon, imageData, color, scale, bgcolor, spotcolor);
|
215 |
|
216 | return canvas;
|
217 | }
|
218 | }, {
|
219 | key: 'render',
|
220 | value: function render() {
|
221 | var _this2 = this;
|
222 |
|
223 | return _react2.default.createElement('canvas', {
|
224 | ref: function ref(identicon) {
|
225 | _this2.identicon = identicon;
|
226 | },
|
227 | className: this.props.className
|
228 | });
|
229 | }
|
230 | }]);
|
231 |
|
232 | return Identicon;
|
233 | }(React__default.Component);
|
234 |
|
235 | exports.default = Identicon;
|
236 |
|
237 |
|
238 | Identicon.defaultProps = {
|
239 | className: 'identicon'
|
240 | };
|
241 |
|
242 | Identicon.propTypes = {
|
243 | seed: _propTypes2.default.string.isRequired,
|
244 | size: _propTypes2.default.number,
|
245 | scale: _propTypes2.default.number,
|
246 | color: _propTypes2.default.string,
|
247 | bgColor: _propTypes2.default.string,
|
248 | spotColor: _propTypes2.default.string
|
249 | };
|
250 | });
|
251 |
|
252 | var Blockies = _commonjsHelpers.unwrapExports(main);
|
253 |
|
254 | function _templateObject3() {
|
255 | var data = taggedTemplateLiteral._taggedTemplateLiteral(["\n /* display:flex to remove the display:inline on the child without using a\n * selector (Blockies doesn\u2019t allow the style prop to be passed). */\n display: flex;\n width: ", "px;\n height: ", "px;\n background: #fff;\n\n /* add high-res screens support to Blockies */\n transform: scale(", ", ", ");\n transform-origin: 0 0;\n"]);
|
256 |
|
257 | _templateObject3 = function _templateObject3() {
|
258 | return data;
|
259 | };
|
260 |
|
261 | return data;
|
262 | }
|
263 |
|
264 | function _templateObject2() {
|
265 | var data = taggedTemplateLiteral._taggedTemplateLiteral(["\n opacity: ", ";\n"]);
|
266 |
|
267 | _templateObject2 = function _templateObject2() {
|
268 | return data;
|
269 | };
|
270 |
|
271 | return data;
|
272 | }
|
273 |
|
274 | function _templateObject() {
|
275 | var data = taggedTemplateLiteral._taggedTemplateLiteral(["\n display: inline-flex;\n vertical-align: middle;\n overflow: hidden;\n width: ", "px;\n height: ", "px;\n border-radius: ", "px;\n\n // Fix an issue where the border-radius wasn\u2019t visible on Blink browsers.\n // See https://gist.github.com/ayamflow/b602ab436ac9f05660d9c15190f4fd7b\n mask-image: linear-gradient(red, red);\n"]);
|
276 |
|
277 | _templateObject = function _templateObject() {
|
278 | return data;
|
279 | };
|
280 |
|
281 | return data;
|
282 | }
|
283 |
|
284 | function _createSuper(Derived) { return function () { var Super = getPrototypeOf._getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = getPrototypeOf._getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return getPrototypeOf._possibleConstructorReturn(this, result); }; }
|
285 |
|
286 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
287 | var PX_RATIO = typeof devicePixelRatio === 'undefined' ? 2 : devicePixelRatio;
|
288 | var BLOCKIES_SQUARES = 8;
|
289 |
|
290 | var BASE_SCALE = 3;
|
291 |
|
292 | var EthIdenticon = function (_React$Component) {
|
293 | getPrototypeOf._inherits(EthIdenticon, _React$Component);
|
294 |
|
295 | var _super = _createSuper(EthIdenticon);
|
296 |
|
297 | function EthIdenticon() {
|
298 | getPrototypeOf._classCallCheck(this, EthIdenticon);
|
299 |
|
300 | return _super.apply(this, arguments);
|
301 | }
|
302 |
|
303 | getPrototypeOf._createClass(EthIdenticon, [{
|
304 | key: "render",
|
305 | value: function render() {
|
306 | var _this$props = this.props,
|
307 | address = _this$props.address,
|
308 | scale = _this$props.scale,
|
309 | radius = _this$props.radius,
|
310 | soften = _this$props.soften;
|
311 | var blockiesScale = scale * BASE_SCALE;
|
312 | return web3.isAddress(address) ? React__default.createElement(Main, _extends._extends({
|
313 | size: BLOCKIES_SQUARES * blockiesScale,
|
314 | radius: radius
|
315 | }, components.stylingProps(this)), React__default.createElement(BlockiesScaling, {
|
316 | size: BLOCKIES_SQUARES * blockiesScale * PX_RATIO
|
317 | }, React__default.createElement(BlockiesOpacity, {
|
318 | soften: soften
|
319 | }, React__default.createElement(Blockies, {
|
320 | seed: address.toLowerCase(),
|
321 | size: BLOCKIES_SQUARES,
|
322 | scale: blockiesScale * PX_RATIO
|
323 | })))) : null;
|
324 | }
|
325 | }]);
|
326 |
|
327 | return EthIdenticon;
|
328 | }(React__default.Component);
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 | defineProperty._defineProperty(EthIdenticon, "propTypes", {
|
339 | address: index.PropTypes.string.isRequired,
|
340 | scale: index.PropTypes.number,
|
341 | radius: index.PropTypes.number,
|
342 | soften: index.PropTypes.number
|
343 | });
|
344 |
|
345 | defineProperty._defineProperty(EthIdenticon, "defaultProps", {
|
346 | scale: 1,
|
347 | radius: 0,
|
348 | soften: 0.3
|
349 | });
|
350 |
|
351 | var Main = _styled__default.div(_templateObject(), function (p) {
|
352 | return p.size;
|
353 | }, function (p) {
|
354 | return p.size;
|
355 | }, function (p) {
|
356 | return p.radius;
|
357 | });
|
358 | var BlockiesOpacity = _styled__default.div(_templateObject2(), function (p) {
|
359 | return 1 - p.soften;
|
360 | });
|
361 | var BlockiesScaling = _styled__default.div(_templateObject3(), function (p) {
|
362 | return p.size;
|
363 | }, function (p) {
|
364 | return p.size;
|
365 | }, 1 / PX_RATIO, 1 / PX_RATIO);
|
366 |
|
367 | exports.default = EthIdenticon;
|
368 |
|