@pezkuwi/vue-identicon 3.16.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/build/Identicon.d.ts +28 -0
- package/build/Identicon.js +111 -0
- package/build/LICENSE +201 -0
- package/build/README.md +37 -0
- package/build/bundle-pezkuwi-vue-identicon.js +887 -0
- package/build/bundle.d.ts +2 -0
- package/build/bundle.js +2 -0
- package/build/cjs/Identicon.d.ts +28 -0
- package/build/cjs/Identicon.js +115 -0
- package/build/cjs/bundle.d.ts +2 -0
- package/build/cjs/bundle.js +7 -0
- package/build/cjs/icons/Beachball.d.ts +17 -0
- package/build/cjs/icons/Beachball.js +21 -0
- package/build/cjs/icons/Empty.d.ts +11 -0
- package/build/cjs/icons/Empty.js +16 -0
- package/build/cjs/icons/Jdenticon.d.ts +14 -0
- package/build/cjs/icons/Jdenticon.js +19 -0
- package/build/cjs/icons/Polkadot.d.ts +17 -0
- package/build/cjs/icons/Polkadot.js +24 -0
- package/build/cjs/icons/index.d.ts +4 -0
- package/build/cjs/icons/index.js +7 -0
- package/build/cjs/index.d.ts +4 -0
- package/build/cjs/index.js +7 -0
- package/build/cjs/package.json +3 -0
- package/build/cjs/packageDetect.d.ts +1 -0
- package/build/cjs/packageDetect.js +6 -0
- package/build/cjs/packageInfo.d.ts +6 -0
- package/build/cjs/packageInfo.js +4 -0
- package/build/cjs/util.d.ts +6 -0
- package/build/cjs/util.js +15 -0
- package/build/icons/Beachball.d.ts +17 -0
- package/build/icons/Beachball.js +18 -0
- package/build/icons/Empty.d.ts +11 -0
- package/build/icons/Empty.js +13 -0
- package/build/icons/Jdenticon.d.ts +14 -0
- package/build/icons/Jdenticon.js +15 -0
- package/build/icons/Polkadot.d.ts +17 -0
- package/build/icons/Polkadot.js +21 -0
- package/build/icons/index.d.ts +4 -0
- package/build/icons/index.js +4 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +4 -0
- package/build/package.json +213 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageDetect.js +4 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/packageInfo.js +1 -0
- package/build/util.d.ts +6 -0
- package/build/util.js +12 -0
- package/build-tsc/Identicon.d.ts +28 -0
- package/build-tsc/bundle.d.ts +2 -0
- package/build-tsc/icons/Beachball.d.ts +17 -0
- package/build-tsc/icons/Empty.d.ts +11 -0
- package/build-tsc/icons/Jdenticon.d.ts +14 -0
- package/build-tsc/icons/Polkadot.d.ts +17 -0
- package/build-tsc/icons/index.d.ts +4 -0
- package/build-tsc/index.d.ts +4 -0
- package/build-tsc/packageDetect.d.ts +1 -0
- package/build-tsc/packageInfo.d.ts +6 -0
- package/build-tsc/util.d.ts +6 -0
- package/build-tsc-cjs/Identicon.js +115 -0
- package/build-tsc-cjs/bundle.js +7 -0
- package/build-tsc-cjs/icons/Beachball.js +21 -0
- package/build-tsc-cjs/icons/Empty.js +16 -0
- package/build-tsc-cjs/icons/Jdenticon.js +19 -0
- package/build-tsc-cjs/icons/Polkadot.js +24 -0
- package/build-tsc-cjs/icons/index.js +7 -0
- package/build-tsc-cjs/index.js +7 -0
- package/build-tsc-cjs/packageDetect.js +6 -0
- package/build-tsc-cjs/packageInfo.js +4 -0
- package/build-tsc-cjs/util.js +15 -0
- package/build-tsc-esm/Identicon.js +111 -0
- package/build-tsc-esm/bundle.js +2 -0
- package/build-tsc-esm/icons/Beachball.js +18 -0
- package/build-tsc-esm/icons/Empty.js +13 -0
- package/build-tsc-esm/icons/Jdenticon.js +15 -0
- package/build-tsc-esm/icons/Polkadot.js +21 -0
- package/build-tsc-esm/icons/index.js +4 -0
- package/build-tsc-esm/index.js +4 -0
- package/build-tsc-esm/packageDetect.js +4 -0
- package/build-tsc-esm/packageInfo.js +1 -0
- package/build-tsc-esm/util.js +12 -0
- package/index.html +17 -0
- package/package.json +38 -0
- package/src/Identicon.ts +141 -0
- package/src/bundle.ts +5 -0
- package/src/icons/Beachball.ts +32 -0
- package/src/icons/Empty.ts +17 -0
- package/src/icons/Jdenticon.ts +27 -0
- package/src/icons/Polkadot.ts +38 -0
- package/src/icons/index.ts +7 -0
- package/src/index.ts +10 -0
- package/src/packageDetect.ts +12 -0
- package/src/packageInfo.ts +6 -0
- package/src/util.ts +17 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.build.tsbuildinfo +1 -0
|
@@ -0,0 +1,887 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('@pezkuwi/util'), require('@pezkuwi/util-crypto')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'vue', '@pezkuwi/util', '@pezkuwi/util-crypto'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pezkuwiVueIdenticon = {}, global.Vue, global.pezkuwiUtil, global.pezkuwiUtilCrypto));
|
|
5
|
+
})(this, (function (exports, vue, util, utilCrypto) { 'use strict';
|
|
6
|
+
|
|
7
|
+
const global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : window;
|
|
8
|
+
|
|
9
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
|
+
const COLORS = [
|
|
11
|
+
'#ffe119', '#4363d8', '#f58231', '#fabebe', '#e6beff', '#800000', '#000075', '#a9a9a9', '#ffffff', '#000000'
|
|
12
|
+
];
|
|
13
|
+
const SHAPE_COUNT = 5;
|
|
14
|
+
|
|
15
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
16
|
+
function svg(type) {
|
|
17
|
+
return document.createElementNS(SVG_NS, type);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function circle$1(r, cx, cy) {
|
|
21
|
+
const elem = svg('circle');
|
|
22
|
+
elem.setAttributeNS('', 'cx', `${cx}`);
|
|
23
|
+
elem.setAttributeNS('', 'cy', `${cy}`);
|
|
24
|
+
elem.setAttributeNS('', 'r', `${r}`);
|
|
25
|
+
return elem;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function circle(seeder, fill, diameter, count) {
|
|
29
|
+
const center = diameter / 2;
|
|
30
|
+
const angle = seeder() * 360;
|
|
31
|
+
const radius = (((SHAPE_COUNT - count) / SHAPE_COUNT) * (diameter / 2)) + ((diameter / 8) * seeder());
|
|
32
|
+
const offset = (diameter / 4) * (seeder() + ((count + 1) / SHAPE_COUNT));
|
|
33
|
+
const cx = (offset * Math.sin(angle)) + center;
|
|
34
|
+
const cy = (offset * Math.cos(angle)) + center;
|
|
35
|
+
const svg = circle$1(radius, cx, cy);
|
|
36
|
+
svg.setAttributeNS('', 'fill', fill);
|
|
37
|
+
return svg;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function element(size, type = 'svg', x = 0, y = 0) {
|
|
41
|
+
const elem = svg(type);
|
|
42
|
+
elem.setAttributeNS('', 'x', `${x}`);
|
|
43
|
+
elem.setAttributeNS('', 'y', `${y}`);
|
|
44
|
+
elem.setAttributeNS('', 'width', `${size}`);
|
|
45
|
+
elem.setAttributeNS('', 'height', `${size}`);
|
|
46
|
+
return elem;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var r={grad:.9,turn:360,rad:360/(2*Math.PI)},t=function(r){return "string"==typeof r?r.length>0:"number"==typeof r},n=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=Math.pow(10,t)),Math.round(n*r)/n+0},e=function(r,t,n){return void 0===t&&(t=0),void 0===n&&(n=1),r>n?n:r>t?r:t},u=function(r){return (r=isFinite(r)?r%360:0)>0?r:r+360},a=function(r){return {r:e(r.r,0,255),g:e(r.g,0,255),b:e(r.b,0,255),a:e(r.a)}},o=function(r){return {r:n(r.r),g:n(r.g),b:n(r.b),a:n(r.a,3)}},i=/^#([0-9a-f]{3,8})$/i,s=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},h=function(r){var t=r.r,n=r.g,e=r.b,u=r.a,a=Math.max(t,n,e),o=a-Math.min(t,n,e),i=o?a===t?(n-e)/o:a===n?2+(e-t)/o:4+(t-n)/o:0;return {h:60*(i<0?i+6:i),s:a?o/a*100:0,v:a/255*100,a:u}},b=function(r){var t=r.h,n=r.s,e=r.v,u=r.a;t=t/360*6,n/=100,e/=100;var a=Math.floor(t),o=e*(1-n),i=e*(1-(t-a)*n),s=e*(1-(1-t+a)*n),h=a%6;return {r:255*[e,i,o,o,s,e][h],g:255*[s,e,e,i,o,o][h],b:255*[o,o,s,e,e,i][h],a:u}},g=function(r){return {h:u(r.h),s:e(r.s,0,100),l:e(r.l,0,100),a:e(r.a)}},d=function(r){return {h:n(r.h),s:n(r.s),l:n(r.l),a:n(r.a,3)}},f=function(r){return b((n=(t=r).s,{h:t.h,s:(n*=((e=t.l)<50?e:100-e)/100)>0?2*n/(e+n)*100:0,v:e+n,a:t.a}));var t,n,e;},c=function(r){return {h:(t=h(r)).h,s:(u=(200-(n=t.s))*(e=t.v)/100)>0&&u<200?n*e/100/(u<=100?u:200-u)*100:0,l:u/2,a:t.a};var t,n,e,u;},l=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,p=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,v=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,m=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,y={string:[[function(r){var t=i.exec(r);return t?(r=t[1]).length<=4?{r:parseInt(r[0]+r[0],16),g:parseInt(r[1]+r[1],16),b:parseInt(r[2]+r[2],16),a:4===r.length?n(parseInt(r[3]+r[3],16)/255,2):1}:6===r.length||8===r.length?{r:parseInt(r.substr(0,2),16),g:parseInt(r.substr(2,2),16),b:parseInt(r.substr(4,2),16),a:8===r.length?n(parseInt(r.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(r){var t=v.exec(r)||m.exec(r);return t?t[2]!==t[4]||t[4]!==t[6]?null:a({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:void 0===t[7]?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(t){var n=l.exec(t)||p.exec(t);if(!n)return null;var e,u,a=g({h:(e=n[1],u=n[2],void 0===u&&(u="deg"),Number(e)*(r[u]||1)),s:Number(n[3]),l:Number(n[4]),a:void 0===n[5]?1:Number(n[5])/(n[6]?100:1)});return f(a)},"hsl"]],object:[[function(r){var n=r.r,e=r.g,u=r.b,o=r.a,i=void 0===o?1:o;return t(n)&&t(e)&&t(u)?a({r:Number(n),g:Number(e),b:Number(u),a:Number(i)}):null},"rgb"],[function(r){var n=r.h,e=r.s,u=r.l,a=r.a,o=void 0===a?1:a;if(!t(n)||!t(e)||!t(u))return null;var i=g({h:Number(n),s:Number(e),l:Number(u),a:Number(o)});return f(i)},"hsl"],[function(r){var n=r.h,a=r.s,o=r.v,i=r.a,s=void 0===i?1:i;if(!t(n)||!t(a)||!t(o))return null;var h=function(r){return {h:u(r.h),s:e(r.s,0,100),v:e(r.v,0,100),a:e(r.a)}}({h:Number(n),s:Number(a),v:Number(o),a:Number(s)});return b(h)},"hsv"]]},N=function(r,t){for(var n=0;n<t.length;n++){var e=t[n][0](r);if(e)return [e,t[n][1]]}return [null,void 0]},x=function(r){return "string"==typeof r?N(r.trim(),y.string):"object"==typeof r&&null!==r?N(r,y.object):[null,void 0]},M=function(r,t){var n=c(r);return {h:n.h,s:e(n.s+100*t,0,100),l:n.l,a:n.a}},H=function(r){return (299*r.r+587*r.g+114*r.b)/1e3/255},$=function(r,t){var n=c(r);return {h:n.h,s:n.s,l:e(n.l+100*t,0,100),a:n.a}},j=function(){function r(r){this.parsed=x(r)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1};}return r.prototype.isValid=function(){return null!==this.parsed},r.prototype.brightness=function(){return n(H(this.rgba),2)},r.prototype.isDark=function(){return H(this.rgba)<.5},r.prototype.isLight=function(){return H(this.rgba)>=.5},r.prototype.toHex=function(){return r=o(this.rgba),t=r.r,e=r.g,u=r.b,i=(a=r.a)<1?s(n(255*a)):"","#"+s(t)+s(e)+s(u)+i;var r,t,e,u,a,i;},r.prototype.toRgb=function(){return o(this.rgba)},r.prototype.toRgbString=function(){return r=o(this.rgba),t=r.r,n=r.g,e=r.b,(u=r.a)<1?"rgba("+t+", "+n+", "+e+", "+u+")":"rgb("+t+", "+n+", "+e+")";var r,t,n,e,u;},r.prototype.toHsl=function(){return d(c(this.rgba))},r.prototype.toHslString=function(){return r=d(c(this.rgba)),t=r.h,n=r.s,e=r.l,(u=r.a)<1?"hsla("+t+", "+n+"%, "+e+"%, "+u+")":"hsl("+t+", "+n+"%, "+e+"%)";var r,t,n,e,u;},r.prototype.toHsv=function(){return r=h(this.rgba),{h:n(r.h),s:n(r.s),v:n(r.v),a:n(r.a,3)};var r;},r.prototype.invert=function(){return w({r:255-(r=this.rgba).r,g:255-r.g,b:255-r.b,a:r.a});var r;},r.prototype.saturate=function(r){return void 0===r&&(r=.1),w(M(this.rgba,r))},r.prototype.desaturate=function(r){return void 0===r&&(r=.1),w(M(this.rgba,-r))},r.prototype.grayscale=function(){return w(M(this.rgba,-1))},r.prototype.lighten=function(r){return void 0===r&&(r=.1),w($(this.rgba,r))},r.prototype.darken=function(r){return void 0===r&&(r=.1),w($(this.rgba,-r))},r.prototype.rotate=function(r){return void 0===r&&(r=15),this.hue(this.hue()+r)},r.prototype.alpha=function(r){return "number"==typeof r?w({r:(t=this.rgba).r,g:t.g,b:t.b,a:r}):n(this.rgba.a,3);var t;},r.prototype.hue=function(r){var t=c(this.rgba);return "number"==typeof r?w({h:r,s:t.s,l:t.l,a:t.a}):n(t.h)},r.prototype.isEqual=function(r){return this.toHex()===w(r).toHex()},r}(),w=function(r){return r instanceof j?r:new j(r)};
|
|
50
|
+
|
|
51
|
+
const WOBBLE = 30;
|
|
52
|
+
function colors(seeder) {
|
|
53
|
+
const amount = (seeder() * WOBBLE) - (WOBBLE / 2);
|
|
54
|
+
const all = COLORS.map((hex) => w(hex).rotate(amount));
|
|
55
|
+
return (alpha = 1) => {
|
|
56
|
+
const index = Math.floor(all.length * seeder());
|
|
57
|
+
return all.splice(index, 1)[0]
|
|
58
|
+
.alpha(alpha)
|
|
59
|
+
.toHslString();
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function container(diameter, background = 'white', className = '', _style = {}) {
|
|
64
|
+
const element = document.createElement('div');
|
|
65
|
+
const style = Object.assign({
|
|
66
|
+
background,
|
|
67
|
+
borderRadius: `${diameter / 2}px`,
|
|
68
|
+
display: 'inline-block',
|
|
69
|
+
height: `${diameter}px`,
|
|
70
|
+
margin: '0px',
|
|
71
|
+
overflow: 'hidden',
|
|
72
|
+
padding: '0px',
|
|
73
|
+
width: `${diameter}px`
|
|
74
|
+
}, _style);
|
|
75
|
+
element.className = className;
|
|
76
|
+
element.style.background = background;
|
|
77
|
+
Object.keys(style).forEach((key) => {
|
|
78
|
+
element.style[key] = style[key];
|
|
79
|
+
});
|
|
80
|
+
return element;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const DIVISOR = 256 * 256;
|
|
84
|
+
function seeder(_seed = new Uint8Array(32)) {
|
|
85
|
+
const seed = util.isU8a(_seed)
|
|
86
|
+
? _seed
|
|
87
|
+
: util.stringToU8a(_seed);
|
|
88
|
+
let index = (seed[Math.floor(seed.length / 2)] % seed.length) - 1;
|
|
89
|
+
const next = () => {
|
|
90
|
+
index += 1;
|
|
91
|
+
if (index === seed.length) {
|
|
92
|
+
index = 0;
|
|
93
|
+
}
|
|
94
|
+
return seed[index];
|
|
95
|
+
};
|
|
96
|
+
return () => {
|
|
97
|
+
return ((next() * 256) + next()) / DIVISOR;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function beachballIcon(seed, { size = 256 }, className = '', style) {
|
|
102
|
+
const seeder$1 = seeder(seed);
|
|
103
|
+
const colorGen = colors(seeder$1);
|
|
104
|
+
const outer = container(size, 'white', className, style);
|
|
105
|
+
const container$1 = container(size, colorGen());
|
|
106
|
+
const svg = element(size);
|
|
107
|
+
outer.appendChild(container$1);
|
|
108
|
+
container$1.appendChild(svg);
|
|
109
|
+
for (let count = 0; count < SHAPE_COUNT; count++) {
|
|
110
|
+
const fill = colorGen();
|
|
111
|
+
const shape = circle(seeder$1, fill, size, count);
|
|
112
|
+
svg.appendChild(shape);
|
|
113
|
+
}
|
|
114
|
+
return outer;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const S = 64;
|
|
118
|
+
const C = S / 2;
|
|
119
|
+
const Z = S / 64 * 5;
|
|
120
|
+
const SCHEMES = [
|
|
121
|
+
{ colors: [0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 1], freq: 1 },
|
|
122
|
+
{ colors: [0, 1, 3, 2, 4, 3, 0, 1, 3, 2, 4, 3, 0, 1, 3, 2, 4, 3, 5], freq: 20 },
|
|
123
|
+
{ colors: [1, 2, 3, 1, 2, 4, 5, 5, 4, 1, 2, 3, 1, 2, 4, 5, 5, 4, 0], freq: 16 },
|
|
124
|
+
{ colors: [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 3], freq: 32 },
|
|
125
|
+
{ colors: [0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 6], freq: 32 },
|
|
126
|
+
{ colors: [0, 1, 2, 3, 4, 5, 3, 4, 2, 0, 1, 6, 7, 8, 9, 7, 8, 6, 10], freq: 128 },
|
|
127
|
+
{ colors: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 8, 6, 7, 5, 3, 4, 2, 11], freq: 128 }
|
|
128
|
+
];
|
|
129
|
+
const SCHEMES_TOTAL = SCHEMES
|
|
130
|
+
.map((s) => s.freq)
|
|
131
|
+
.reduce((a, b) => a + b);
|
|
132
|
+
const OUTER_CIRCLE = {
|
|
133
|
+
cx: C,
|
|
134
|
+
cy: C,
|
|
135
|
+
fill: '#eee',
|
|
136
|
+
r: C
|
|
137
|
+
};
|
|
138
|
+
let zeroHash = new Uint8Array();
|
|
139
|
+
function getRotation(isSixPoint) {
|
|
140
|
+
const r = isSixPoint
|
|
141
|
+
? (C / 8 * 5)
|
|
142
|
+
: (C / 4 * 3);
|
|
143
|
+
const rroot3o2 = r * Math.sqrt(3) / 2;
|
|
144
|
+
const ro2 = r / 2;
|
|
145
|
+
const rroot3o4 = r * Math.sqrt(3) / 4;
|
|
146
|
+
const ro4 = r / 4;
|
|
147
|
+
const r3o4 = r * 3 / 4;
|
|
148
|
+
return { r, r3o4, ro2, ro4, rroot3o2, rroot3o4 };
|
|
149
|
+
}
|
|
150
|
+
function getCircleXY(isSixPoint = false) {
|
|
151
|
+
const { r, r3o4, ro2, ro4, rroot3o2, rroot3o4 } = getRotation(isSixPoint);
|
|
152
|
+
return [
|
|
153
|
+
[C, C - r],
|
|
154
|
+
[C, C - ro2],
|
|
155
|
+
[C - rroot3o4, C - r3o4],
|
|
156
|
+
[C - rroot3o2, C - ro2],
|
|
157
|
+
[C - rroot3o4, C - ro4],
|
|
158
|
+
[C - rroot3o2, C],
|
|
159
|
+
[C - rroot3o2, C + ro2],
|
|
160
|
+
[C - rroot3o4, C + ro4],
|
|
161
|
+
[C - rroot3o4, C + r3o4],
|
|
162
|
+
[C, C + r],
|
|
163
|
+
[C, C + ro2],
|
|
164
|
+
[C + rroot3o4, C + r3o4],
|
|
165
|
+
[C + rroot3o2, C + ro2],
|
|
166
|
+
[C + rroot3o4, C + ro4],
|
|
167
|
+
[C + rroot3o2, C],
|
|
168
|
+
[C + rroot3o2, C - ro2],
|
|
169
|
+
[C + rroot3o4, C - ro4],
|
|
170
|
+
[C + rroot3o4, C - r3o4],
|
|
171
|
+
[C, C]
|
|
172
|
+
];
|
|
173
|
+
}
|
|
174
|
+
function findScheme(d) {
|
|
175
|
+
let cum = 0;
|
|
176
|
+
const schema = SCHEMES.find((schema) => {
|
|
177
|
+
cum += schema.freq;
|
|
178
|
+
return d < cum;
|
|
179
|
+
});
|
|
180
|
+
if (!schema) {
|
|
181
|
+
throw new Error('Unable to find schema');
|
|
182
|
+
}
|
|
183
|
+
return schema;
|
|
184
|
+
}
|
|
185
|
+
function addressToId(address) {
|
|
186
|
+
if (!zeroHash.length) {
|
|
187
|
+
zeroHash = utilCrypto.blake2AsU8a(new Uint8Array(32), 512);
|
|
188
|
+
}
|
|
189
|
+
return utilCrypto.blake2AsU8a(utilCrypto.decodeAddress(address), 512).map((x, i) => (x + 256 - zeroHash[i]) % 256);
|
|
190
|
+
}
|
|
191
|
+
function getColors(address) {
|
|
192
|
+
const id = addressToId(address);
|
|
193
|
+
const d = Math.floor((id[30] + id[31] * 256) % SCHEMES_TOTAL);
|
|
194
|
+
const rot = (id[28] % 6) * 3;
|
|
195
|
+
const sat = (Math.floor(id[29] * 70 / 256 + 26) % 80) + 30;
|
|
196
|
+
const scheme = findScheme(d);
|
|
197
|
+
const palette = Array.from(id).map((x, i) => {
|
|
198
|
+
const b = (x + i % 28 * 58) % 256;
|
|
199
|
+
if (b === 0) {
|
|
200
|
+
return '#444';
|
|
201
|
+
}
|
|
202
|
+
else if (b === 255) {
|
|
203
|
+
return 'transparent';
|
|
204
|
+
}
|
|
205
|
+
const h = Math.floor(b % 64 * 360 / 64);
|
|
206
|
+
const l = [53, 15, 35, 75][Math.floor(b / 64)];
|
|
207
|
+
return `hsl(${h}, ${sat}%, ${l}%)`;
|
|
208
|
+
});
|
|
209
|
+
return scheme.colors.map((_, i) => palette[scheme.colors[i < 18 ? (i + rot) % 18 : 18]]);
|
|
210
|
+
}
|
|
211
|
+
function polkadotIcon(address, { isAlternative }) {
|
|
212
|
+
const xy = getCircleXY(isAlternative);
|
|
213
|
+
let colors;
|
|
214
|
+
try {
|
|
215
|
+
colors = getColors(address);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
colors = new Array(xy.length).fill('#ddd');
|
|
219
|
+
}
|
|
220
|
+
return [OUTER_CIRCLE].concat(xy.map(([cx, cy], index) => ({
|
|
221
|
+
cx, cy, fill: colors[index], r: Z
|
|
222
|
+
})));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const Beachball = vue.defineComponent({
|
|
226
|
+
props: ['address', 'size', 'isAlternative'],
|
|
227
|
+
render() {
|
|
228
|
+
const { address, isAlternative, size } = this.$props;
|
|
229
|
+
return vue.h({
|
|
230
|
+
template: beachballIcon(address, {
|
|
231
|
+
isAlternative,
|
|
232
|
+
size
|
|
233
|
+
}).outerHTML
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const Empty = vue.defineComponent({
|
|
239
|
+
props: ['size'],
|
|
240
|
+
template: `
|
|
241
|
+
<svg :height="size" :width="size" viewBox="0 0 64 64">
|
|
242
|
+
<circle cx="50%" cy="50%" fill="#eee" r="50%" />
|
|
243
|
+
</svg>
|
|
244
|
+
`
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
function parseHex(hash, startPosition, octets) {
|
|
248
|
+
return parseInt(hash.substr(startPosition, octets), 16);
|
|
249
|
+
}
|
|
250
|
+
function decToHex(v) {
|
|
251
|
+
v |= 0;
|
|
252
|
+
return v < 0 ? "00" :
|
|
253
|
+
v < 16 ? "0" + v.toString(16) :
|
|
254
|
+
v < 256 ? v.toString(16) :
|
|
255
|
+
"ff";
|
|
256
|
+
}
|
|
257
|
+
function hueToRgb(m1, m2, h) {
|
|
258
|
+
h = h < 0 ? h + 6 : h > 6 ? h - 6 : h;
|
|
259
|
+
return decToHex(255 * (
|
|
260
|
+
h < 1 ? m1 + (m2 - m1) * h :
|
|
261
|
+
h < 3 ? m2 :
|
|
262
|
+
h < 4 ? m1 + (m2 - m1) * (4 - h) :
|
|
263
|
+
m1));
|
|
264
|
+
}
|
|
265
|
+
function parseColor(color) {
|
|
266
|
+
if (/^#[0-9a-f]{3,8}$/i.test(color)) {
|
|
267
|
+
let result;
|
|
268
|
+
const colorLength = color.length;
|
|
269
|
+
if (colorLength < 6) {
|
|
270
|
+
const r = color[1],
|
|
271
|
+
g = color[2],
|
|
272
|
+
b = color[3],
|
|
273
|
+
a = color[4] || "";
|
|
274
|
+
result = "#" + r + r + g + g + b + b + a + a;
|
|
275
|
+
}
|
|
276
|
+
if (colorLength == 7 || colorLength > 8) {
|
|
277
|
+
result = color;
|
|
278
|
+
}
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function hsl(hue, saturation, lightness) {
|
|
283
|
+
let result;
|
|
284
|
+
if (saturation == 0) {
|
|
285
|
+
const partialHex = decToHex(lightness * 255);
|
|
286
|
+
result = partialHex + partialHex + partialHex;
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
const m2 = lightness <= 0.5 ? lightness * (saturation + 1) : lightness + saturation - lightness * saturation,
|
|
290
|
+
m1 = lightness * 2 - m2;
|
|
291
|
+
result =
|
|
292
|
+
hueToRgb(m1, m2, hue * 6 + 2) +
|
|
293
|
+
hueToRgb(m1, m2, hue * 6) +
|
|
294
|
+
hueToRgb(m1, m2, hue * 6 - 2);
|
|
295
|
+
}
|
|
296
|
+
return "#" + result;
|
|
297
|
+
}
|
|
298
|
+
function correctedHsl(hue, saturation, lightness) {
|
|
299
|
+
const correctors = [ 0.55, 0.5, 0.5, 0.46, 0.6, 0.55, 0.55 ],
|
|
300
|
+
corrector = correctors[(hue * 6 + 0.5) | 0];
|
|
301
|
+
lightness = lightness < 0.5 ? lightness * corrector * 2 : corrector + (lightness - 0.5) * (1 - corrector) * 2;
|
|
302
|
+
return hsl(hue, saturation, lightness);
|
|
303
|
+
}
|
|
304
|
+
const GLOBAL =
|
|
305
|
+
typeof window !== "undefined" ? window :
|
|
306
|
+
typeof self !== "undefined" ? self :
|
|
307
|
+
typeof global !== "undefined" ? global :
|
|
308
|
+
{};
|
|
309
|
+
const CONFIG_PROPERTIES = {
|
|
310
|
+
V: "jdenticon_config",
|
|
311
|
+
n: "config",
|
|
312
|
+
};
|
|
313
|
+
var rootConfigurationHolder = {};
|
|
314
|
+
function getConfiguration(paddingOrLocalConfig, defaultPadding) {
|
|
315
|
+
const configObject =
|
|
316
|
+
rootConfigurationHolder[CONFIG_PROPERTIES.n] ||
|
|
317
|
+
GLOBAL[CONFIG_PROPERTIES.V] ||
|
|
318
|
+
{ },
|
|
319
|
+
lightnessConfig = configObject["lightness"] || { },
|
|
320
|
+
saturation = configObject["saturation"] || { },
|
|
321
|
+
colorSaturation = "color" in saturation ? saturation["color"] : saturation,
|
|
322
|
+
grayscaleSaturation = saturation["grayscale"],
|
|
323
|
+
backColor = configObject["backColor"],
|
|
324
|
+
padding = configObject["padding"];
|
|
325
|
+
function lightness(configName, defaultRange) {
|
|
326
|
+
let range = lightnessConfig[configName];
|
|
327
|
+
if (!(range && range.length > 1)) {
|
|
328
|
+
range = defaultRange;
|
|
329
|
+
}
|
|
330
|
+
return function (value) {
|
|
331
|
+
value = range[0] + value * (range[1] - range[0]);
|
|
332
|
+
return value < 0 ? 0 : value > 1 ? 1 : value;
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function hueFunction(originalHue) {
|
|
336
|
+
const hueConfig = configObject["hues"];
|
|
337
|
+
let hue;
|
|
338
|
+
if (hueConfig && hueConfig.length > 0) {
|
|
339
|
+
hue = hueConfig[0 | (0.999 * originalHue * hueConfig.length)];
|
|
340
|
+
}
|
|
341
|
+
return typeof hue == "number" ?
|
|
342
|
+
((((hue / 360) % 1) + 1) % 1) :
|
|
343
|
+
originalHue;
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
W: hueFunction,
|
|
347
|
+
o: typeof colorSaturation == "number" ? colorSaturation : 0.5,
|
|
348
|
+
D: typeof grayscaleSaturation == "number" ? grayscaleSaturation : 0,
|
|
349
|
+
p: lightness("color", [0.4, 0.8]),
|
|
350
|
+
F: lightness("grayscale", [0.3, 0.9]),
|
|
351
|
+
G: parseColor(backColor),
|
|
352
|
+
X:
|
|
353
|
+
typeof padding == "number" ? padding :
|
|
354
|
+
defaultPadding
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
class Point {
|
|
358
|
+
constructor(x, y) {
|
|
359
|
+
this.x = x;
|
|
360
|
+
this.y = y;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
class Transform {
|
|
364
|
+
constructor(x, y, size, rotation) {
|
|
365
|
+
this.q = x;
|
|
366
|
+
this.t = y;
|
|
367
|
+
this.H = size;
|
|
368
|
+
this.Y = rotation;
|
|
369
|
+
}
|
|
370
|
+
I(x, y, w, h) {
|
|
371
|
+
const right = this.q + this.H,
|
|
372
|
+
bottom = this.t + this.H,
|
|
373
|
+
rotation = this.Y;
|
|
374
|
+
return rotation === 1 ? new Point(right - y - (h || 0), this.t + x) :
|
|
375
|
+
rotation === 2 ? new Point(right - x - (w || 0), bottom - y - (h || 0)) :
|
|
376
|
+
rotation === 3 ? new Point(this.q + y, bottom - x - (w || 0)) :
|
|
377
|
+
new Point(this.q + x, this.t + y);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
const NO_TRANSFORM = new Transform(0, 0, 0, 0);
|
|
381
|
+
class Graphics {
|
|
382
|
+
constructor(renderer) {
|
|
383
|
+
this.J = renderer;
|
|
384
|
+
this.u = NO_TRANSFORM;
|
|
385
|
+
}
|
|
386
|
+
g(points, invert) {
|
|
387
|
+
const di = invert ? -2 : 2,
|
|
388
|
+
transformedPoints = [];
|
|
389
|
+
for (let i = invert ? points.length - 2 : 0; i < points.length && i >= 0; i += di) {
|
|
390
|
+
transformedPoints.push(this.u.I(points[i], points[i + 1]));
|
|
391
|
+
}
|
|
392
|
+
this.J.g(transformedPoints);
|
|
393
|
+
}
|
|
394
|
+
h(x, y, size, invert) {
|
|
395
|
+
const p = this.u.I(x, y, size, size);
|
|
396
|
+
this.J.h(p, size, invert);
|
|
397
|
+
}
|
|
398
|
+
i(x, y, w, h, invert) {
|
|
399
|
+
this.g([
|
|
400
|
+
x, y,
|
|
401
|
+
x + w, y,
|
|
402
|
+
x + w, y + h,
|
|
403
|
+
x, y + h
|
|
404
|
+
], invert);
|
|
405
|
+
}
|
|
406
|
+
j(x, y, w, h, r, invert) {
|
|
407
|
+
const points = [
|
|
408
|
+
x + w, y,
|
|
409
|
+
x + w, y + h,
|
|
410
|
+
x, y + h,
|
|
411
|
+
x, y
|
|
412
|
+
];
|
|
413
|
+
points.splice(((r || 0) % 4) * 2, 2);
|
|
414
|
+
this.g(points, invert);
|
|
415
|
+
}
|
|
416
|
+
K(x, y, w, h, invert) {
|
|
417
|
+
this.g([
|
|
418
|
+
x + w / 2, y,
|
|
419
|
+
x + w, y + h / 2,
|
|
420
|
+
x + w / 2, y + h,
|
|
421
|
+
x, y + h / 2
|
|
422
|
+
], invert);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
function centerShape(index, g, cell, positionIndex) {
|
|
426
|
+
index = index % 14;
|
|
427
|
+
let k, m, w, h, inner, outer;
|
|
428
|
+
!index ? (
|
|
429
|
+
k = cell * 0.42,
|
|
430
|
+
g.g([
|
|
431
|
+
0, 0,
|
|
432
|
+
cell, 0,
|
|
433
|
+
cell, cell - k * 2,
|
|
434
|
+
cell - k, cell,
|
|
435
|
+
0, cell
|
|
436
|
+
])) :
|
|
437
|
+
index == 1 ? (
|
|
438
|
+
w = 0 | (cell * 0.5),
|
|
439
|
+
h = 0 | (cell * 0.8),
|
|
440
|
+
g.j(cell - w, 0, w, h, 2)) :
|
|
441
|
+
index == 2 ? (
|
|
442
|
+
w = 0 | (cell / 3),
|
|
443
|
+
g.i(w, w, cell - w, cell - w)) :
|
|
444
|
+
index == 3 ? (
|
|
445
|
+
inner = cell * 0.1,
|
|
446
|
+
outer =
|
|
447
|
+
cell < 6 ? 1 :
|
|
448
|
+
cell < 8 ? 2 :
|
|
449
|
+
(0 | (cell * 0.25)),
|
|
450
|
+
inner =
|
|
451
|
+
inner > 1 ? (0 | inner) :
|
|
452
|
+
inner > 0.5 ? 1 :
|
|
453
|
+
inner,
|
|
454
|
+
g.i(outer, outer, cell - inner - outer, cell - inner - outer)) :
|
|
455
|
+
index == 4 ? (
|
|
456
|
+
m = 0 | (cell * 0.15),
|
|
457
|
+
w = 0 | (cell * 0.5),
|
|
458
|
+
g.h(cell - w - m, cell - w - m, w)) :
|
|
459
|
+
index == 5 ? (
|
|
460
|
+
inner = cell * 0.1,
|
|
461
|
+
outer = inner * 4,
|
|
462
|
+
outer > 3 && (outer = 0 | outer),
|
|
463
|
+
g.i(0, 0, cell, cell),
|
|
464
|
+
g.g([
|
|
465
|
+
outer, outer,
|
|
466
|
+
cell - inner, outer,
|
|
467
|
+
outer + (cell - outer - inner) / 2, cell - inner
|
|
468
|
+
], true)) :
|
|
469
|
+
index == 6 ?
|
|
470
|
+
g.g([
|
|
471
|
+
0, 0,
|
|
472
|
+
cell, 0,
|
|
473
|
+
cell, cell * 0.7,
|
|
474
|
+
cell * 0.4, cell * 0.4,
|
|
475
|
+
cell * 0.7, cell,
|
|
476
|
+
0, cell
|
|
477
|
+
]) :
|
|
478
|
+
index == 7 ?
|
|
479
|
+
g.j(cell / 2, cell / 2, cell / 2, cell / 2, 3) :
|
|
480
|
+
index == 8 ? (
|
|
481
|
+
g.i(0, 0, cell, cell / 2),
|
|
482
|
+
g.i(0, cell / 2, cell / 2, cell / 2),
|
|
483
|
+
g.j(cell / 2, cell / 2, cell / 2, cell / 2, 1)) :
|
|
484
|
+
index == 9 ? (
|
|
485
|
+
inner = cell * 0.14,
|
|
486
|
+
outer =
|
|
487
|
+
cell < 4 ? 1 :
|
|
488
|
+
cell < 6 ? 2 :
|
|
489
|
+
(0 | (cell * 0.35)),
|
|
490
|
+
inner =
|
|
491
|
+
cell < 8 ? inner :
|
|
492
|
+
(0 | inner),
|
|
493
|
+
g.i(0, 0, cell, cell),
|
|
494
|
+
g.i(outer, outer, cell - outer - inner, cell - outer - inner, true)) :
|
|
495
|
+
index == 10 ? (
|
|
496
|
+
inner = cell * 0.12,
|
|
497
|
+
outer = inner * 3,
|
|
498
|
+
g.i(0, 0, cell, cell),
|
|
499
|
+
g.h(outer, outer, cell - inner - outer, true)) :
|
|
500
|
+
index == 11 ?
|
|
501
|
+
g.j(cell / 2, cell / 2, cell / 2, cell / 2, 3) :
|
|
502
|
+
index == 12 ? (
|
|
503
|
+
m = cell * 0.25,
|
|
504
|
+
g.i(0, 0, cell, cell),
|
|
505
|
+
g.K(m, m, cell - m, cell - m, true)) :
|
|
506
|
+
(
|
|
507
|
+
!positionIndex && (
|
|
508
|
+
m = cell * 0.4, w = cell * 1.2,
|
|
509
|
+
g.h(m, m, w)
|
|
510
|
+
)
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
function outerShape(index, g, cell) {
|
|
514
|
+
index = index % 4;
|
|
515
|
+
let m;
|
|
516
|
+
!index ?
|
|
517
|
+
g.j(0, 0, cell, cell, 0) :
|
|
518
|
+
index == 1 ?
|
|
519
|
+
g.j(0, cell / 2, cell, cell / 2, 0) :
|
|
520
|
+
index == 2 ?
|
|
521
|
+
g.K(0, 0, cell, cell) :
|
|
522
|
+
(
|
|
523
|
+
m = cell / 6,
|
|
524
|
+
g.h(m, m, cell - 2 * m)
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
function colorTheme(hue, config) {
|
|
528
|
+
hue = config.W(hue);
|
|
529
|
+
return [
|
|
530
|
+
correctedHsl(hue, config.D, config.F(0)),
|
|
531
|
+
correctedHsl(hue, config.o, config.p(0.5)),
|
|
532
|
+
correctedHsl(hue, config.D, config.F(1)),
|
|
533
|
+
correctedHsl(hue, config.o, config.p(1)),
|
|
534
|
+
correctedHsl(hue, config.o, config.p(0))
|
|
535
|
+
];
|
|
536
|
+
}
|
|
537
|
+
function iconGenerator(renderer, hash, config) {
|
|
538
|
+
const parsedConfig = getConfiguration(config, 0.08);
|
|
539
|
+
if (parsedConfig.G) {
|
|
540
|
+
renderer.m(parsedConfig.G);
|
|
541
|
+
}
|
|
542
|
+
let size = renderer.k;
|
|
543
|
+
const padding = (0.5 + size * parsedConfig.X) | 0;
|
|
544
|
+
size -= padding * 2;
|
|
545
|
+
const graphics = new Graphics(renderer);
|
|
546
|
+
const cell = 0 | (size / 4);
|
|
547
|
+
const x = 0 | (padding + size / 2 - cell * 2);
|
|
548
|
+
const y = 0 | (padding + size / 2 - cell * 2);
|
|
549
|
+
function renderShape(colorIndex, shapes, index, rotationIndex, positions) {
|
|
550
|
+
const shapeIndex = parseHex(hash, index, 1);
|
|
551
|
+
let r = rotationIndex ? parseHex(hash, rotationIndex, 1) : 0;
|
|
552
|
+
renderer.L(availableColors[selectedColorIndexes[colorIndex]]);
|
|
553
|
+
for (let i = 0; i < positions.length; i++) {
|
|
554
|
+
graphics.u = new Transform(x + positions[i][0] * cell, y + positions[i][1] * cell, cell, r++ % 4);
|
|
555
|
+
shapes(shapeIndex, graphics, cell, i);
|
|
556
|
+
}
|
|
557
|
+
renderer.M();
|
|
558
|
+
}
|
|
559
|
+
const hue = parseHex(hash, -7) / 0xfffffff,
|
|
560
|
+
availableColors = colorTheme(hue, parsedConfig),
|
|
561
|
+
selectedColorIndexes = [];
|
|
562
|
+
let index;
|
|
563
|
+
function isDuplicate(values) {
|
|
564
|
+
if (values.indexOf(index) >= 0) {
|
|
565
|
+
for (let i = 0; i < values.length; i++) {
|
|
566
|
+
if (selectedColorIndexes.indexOf(values[i]) >= 0) {
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
for (let i = 0; i < 3; i++) {
|
|
573
|
+
index = parseHex(hash, 8 + i, 1) % availableColors.length;
|
|
574
|
+
if (isDuplicate([0, 4]) ||
|
|
575
|
+
isDuplicate([2, 3])) {
|
|
576
|
+
index = 1;
|
|
577
|
+
}
|
|
578
|
+
selectedColorIndexes.push(index);
|
|
579
|
+
}
|
|
580
|
+
renderShape(0, outerShape, 2, 3, [[1, 0], [2, 0], [2, 3], [1, 3], [0, 1], [3, 1], [3, 2], [0, 2]]);
|
|
581
|
+
renderShape(1, outerShape, 4, 5, [[0, 0], [3, 0], [3, 3], [0, 3]]);
|
|
582
|
+
renderShape(2, centerShape, 1, null, [[1, 1], [2, 1], [2, 2], [1, 2]]);
|
|
583
|
+
renderer.finish();
|
|
584
|
+
}
|
|
585
|
+
function sha1(message) {
|
|
586
|
+
const HASH_SIZE_HALF_BYTES = 40;
|
|
587
|
+
const BLOCK_SIZE_WORDS = 16;
|
|
588
|
+
var i = 0,
|
|
589
|
+
f = 0,
|
|
590
|
+
urlEncodedMessage = encodeURI(message) + "%80",
|
|
591
|
+
data = [],
|
|
592
|
+
dataSize,
|
|
593
|
+
hashBuffer = [],
|
|
594
|
+
a = 0x67452301,
|
|
595
|
+
b = 0xefcdab89,
|
|
596
|
+
c = ~a,
|
|
597
|
+
d = ~b,
|
|
598
|
+
e = 0xc3d2e1f0,
|
|
599
|
+
hash = [a, b, c, d, e],
|
|
600
|
+
blockStartIndex = 0,
|
|
601
|
+
hexHash = "";
|
|
602
|
+
function rotl(value, shift) {
|
|
603
|
+
return (value << shift) | (value >>> (32 - shift));
|
|
604
|
+
}
|
|
605
|
+
for ( ; i < urlEncodedMessage.length; f++) {
|
|
606
|
+
data[f >> 2] = data[f >> 2] |
|
|
607
|
+
(
|
|
608
|
+
(
|
|
609
|
+
urlEncodedMessage[i] == "%"
|
|
610
|
+
? parseInt(urlEncodedMessage.substring(i + 1, i += 3), 16)
|
|
611
|
+
: urlEncodedMessage.charCodeAt(i++)
|
|
612
|
+
)
|
|
613
|
+
<< ((3 - (f & 3)) * 8)
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
dataSize = (((f + 7) >> 6) + 1) * BLOCK_SIZE_WORDS;
|
|
617
|
+
data[dataSize - 1] = f * 8 - 8;
|
|
618
|
+
for ( ; blockStartIndex < dataSize; blockStartIndex += BLOCK_SIZE_WORDS) {
|
|
619
|
+
for (i = 0; i < 80; i++) {
|
|
620
|
+
f = rotl(a, 5) + e + (
|
|
621
|
+
i < 20 ? ((b & c) ^ ((~b) & d)) + 0x5a827999 :
|
|
622
|
+
i < 40 ? (b ^ c ^ d) + 0x6ed9eba1 :
|
|
623
|
+
i < 60 ? ((b & c) ^ (b & d) ^ (c & d)) + 0x8f1bbcdc :
|
|
624
|
+
(b ^ c ^ d) + 0xca62c1d6
|
|
625
|
+
) + (
|
|
626
|
+
hashBuffer[i] = i < BLOCK_SIZE_WORDS
|
|
627
|
+
? (data[blockStartIndex + i] | 0)
|
|
628
|
+
: rotl(hashBuffer[i - 3] ^ hashBuffer[i - 8] ^ hashBuffer[i - 14] ^ hashBuffer[i - 16], 1)
|
|
629
|
+
);
|
|
630
|
+
e = d;
|
|
631
|
+
d = c;
|
|
632
|
+
c = rotl(b, 30);
|
|
633
|
+
b = a;
|
|
634
|
+
a = f;
|
|
635
|
+
}
|
|
636
|
+
hash[0] = a = ((hash[0] + a) | 0);
|
|
637
|
+
hash[1] = b = ((hash[1] + b) | 0);
|
|
638
|
+
hash[2] = c = ((hash[2] + c) | 0);
|
|
639
|
+
hash[3] = d = ((hash[3] + d) | 0);
|
|
640
|
+
hash[4] = e = ((hash[4] + e) | 0);
|
|
641
|
+
}
|
|
642
|
+
for (i = 0; i < HASH_SIZE_HALF_BYTES; i++) {
|
|
643
|
+
hexHash += (
|
|
644
|
+
(
|
|
645
|
+
hash[i >> 3] >>>
|
|
646
|
+
((7 - (i & 7)) * 4)
|
|
647
|
+
)
|
|
648
|
+
& 0xf
|
|
649
|
+
).toString(16);
|
|
650
|
+
}
|
|
651
|
+
return hexHash;
|
|
652
|
+
}
|
|
653
|
+
function isValidHash(hashCandidate) {
|
|
654
|
+
return /^[0-9a-f]{11,}$/i.test(hashCandidate) && hashCandidate;
|
|
655
|
+
}
|
|
656
|
+
function computeHash(value) {
|
|
657
|
+
return sha1(value == null ? "" : "" + value);
|
|
658
|
+
}
|
|
659
|
+
function svgValue(value) {
|
|
660
|
+
return ((value * 10 + 0.5) | 0) / 10;
|
|
661
|
+
}
|
|
662
|
+
class SvgPath {
|
|
663
|
+
constructor() {
|
|
664
|
+
this.v = "";
|
|
665
|
+
}
|
|
666
|
+
g(points) {
|
|
667
|
+
let dataString = "";
|
|
668
|
+
for (let i = 0; i < points.length; i++) {
|
|
669
|
+
dataString += (i ? "L" : "M") + svgValue(points[i].x) + " " + svgValue(points[i].y);
|
|
670
|
+
}
|
|
671
|
+
this.v += dataString + "Z";
|
|
672
|
+
}
|
|
673
|
+
h(point, diameter, counterClockwise) {
|
|
674
|
+
const sweepFlag = counterClockwise ? 0 : 1,
|
|
675
|
+
svgRadius = svgValue(diameter / 2),
|
|
676
|
+
svgDiameter = svgValue(diameter),
|
|
677
|
+
svgArc = "a" + svgRadius + "," + svgRadius + " 0 1," + sweepFlag + " ";
|
|
678
|
+
this.v +=
|
|
679
|
+
"M" + svgValue(point.x) + " " + svgValue(point.y + diameter / 2) +
|
|
680
|
+
svgArc + svgDiameter + ",0" +
|
|
681
|
+
svgArc + (-svgDiameter) + ",0";
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
class SvgRenderer {
|
|
685
|
+
constructor(target) {
|
|
686
|
+
this.A;
|
|
687
|
+
this.B = { };
|
|
688
|
+
this.N = target;
|
|
689
|
+
this.k = target.k;
|
|
690
|
+
}
|
|
691
|
+
m(fillColor) {
|
|
692
|
+
const match = /^(#......)(..)?/.exec(fillColor),
|
|
693
|
+
opacity = match[2] ? parseHex(match[2], 0) / 255 : 1;
|
|
694
|
+
this.N.m(match[1], opacity);
|
|
695
|
+
}
|
|
696
|
+
L(color) {
|
|
697
|
+
this.A = this.B[color] || (this.B[color] = new SvgPath());
|
|
698
|
+
}
|
|
699
|
+
M() { }
|
|
700
|
+
g(points) {
|
|
701
|
+
this.A.g(points);
|
|
702
|
+
}
|
|
703
|
+
h(point, diameter, counterClockwise) {
|
|
704
|
+
this.A.h(point, diameter, counterClockwise);
|
|
705
|
+
}
|
|
706
|
+
finish() {
|
|
707
|
+
const pathsByColor = this.B;
|
|
708
|
+
for (let color in pathsByColor) {
|
|
709
|
+
if (pathsByColor.hasOwnProperty(color)) {
|
|
710
|
+
this.N.O(color, pathsByColor[color].v);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
const SVG_CONSTANTS = {
|
|
716
|
+
P: "http://www.w3.org/2000/svg",
|
|
717
|
+
R: "width",
|
|
718
|
+
S: "height",
|
|
719
|
+
};
|
|
720
|
+
class SvgWriter {
|
|
721
|
+
constructor(iconSize) {
|
|
722
|
+
this.k = iconSize;
|
|
723
|
+
this.C =
|
|
724
|
+
'<svg xmlns="' + SVG_CONSTANTS.P + '" width="' +
|
|
725
|
+
iconSize + '" height="' + iconSize + '" viewBox="0 0 ' +
|
|
726
|
+
iconSize + ' ' + iconSize + '">';
|
|
727
|
+
}
|
|
728
|
+
m(fillColor, opacity) {
|
|
729
|
+
if (opacity) {
|
|
730
|
+
this.C += '<rect width="100%" height="100%" fill="' +
|
|
731
|
+
fillColor + '" opacity="' + opacity.toFixed(2) + '"/>';
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
O(color, dataString) {
|
|
735
|
+
this.C += '<path fill="' + color + '" d="' + dataString + '"/>';
|
|
736
|
+
}
|
|
737
|
+
toString() {
|
|
738
|
+
return this.C + "</svg>";
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
function toSvg(hashOrValue, size, config) {
|
|
742
|
+
const writer = new SvgWriter(size);
|
|
743
|
+
iconGenerator(new SvgRenderer(writer),
|
|
744
|
+
isValidHash(hashOrValue) || computeHash(hashOrValue),
|
|
745
|
+
config);
|
|
746
|
+
return writer.toString();
|
|
747
|
+
}
|
|
748
|
+
(
|
|
749
|
+
typeof document !== "undefined" && document.querySelectorAll.bind(document));
|
|
750
|
+
|
|
751
|
+
const Jdenticon = vue.defineComponent({
|
|
752
|
+
props: ['publicKey', 'size'],
|
|
753
|
+
render() {
|
|
754
|
+
const { publicKey, size } = this.$props;
|
|
755
|
+
return vue.h({
|
|
756
|
+
template: toSvg(publicKey.substring(2), size)
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
const isV3 = vue.version.startsWith('3.');
|
|
762
|
+
function adaptVNodeAttrs(data) {
|
|
763
|
+
return isV3
|
|
764
|
+
? data
|
|
765
|
+
: { attrs: data };
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
const Polkadot = vue.defineComponent({
|
|
769
|
+
props: ['address', 'isAlternative', 'size'],
|
|
770
|
+
render() {
|
|
771
|
+
const { address, isAlternative, size } = this.$props;
|
|
772
|
+
const circles = polkadotIcon(address, { isAlternative }).map(({ cx, cy, fill, r }) => vue.h('circle', { ...adaptVNodeAttrs({ cx, cy, fill, r }) }, []));
|
|
773
|
+
return vue.h('svg', {
|
|
774
|
+
...adaptVNodeAttrs({
|
|
775
|
+
height: size,
|
|
776
|
+
viewBox: '0 0 64 64',
|
|
777
|
+
width: size
|
|
778
|
+
})
|
|
779
|
+
}, circles);
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
const DEFAULT_SIZE = 64;
|
|
784
|
+
function resolvePublicKey(value, prefix) {
|
|
785
|
+
if (util.isHex(value) && utilCrypto.isEthereumAddress(value)) {
|
|
786
|
+
return value.padEnd(66, '0');
|
|
787
|
+
}
|
|
788
|
+
return util.isU8a(value) || util.isHex(value)
|
|
789
|
+
? utilCrypto.encodeAddress(value, prefix)
|
|
790
|
+
: value;
|
|
791
|
+
}
|
|
792
|
+
function encodeAccount(value, prefix) {
|
|
793
|
+
try {
|
|
794
|
+
const address = resolvePublicKey(value, prefix);
|
|
795
|
+
const publicKey = util.u8aToHex(utilCrypto.decodeAddress(address, false, prefix));
|
|
796
|
+
return { address, publicKey };
|
|
797
|
+
}
|
|
798
|
+
catch {
|
|
799
|
+
return { address: '', publicKey: '0x' };
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
const Identicon = vue.defineComponent({
|
|
803
|
+
components: {
|
|
804
|
+
Beachball,
|
|
805
|
+
Empty,
|
|
806
|
+
Jdenticon,
|
|
807
|
+
Polkadot
|
|
808
|
+
},
|
|
809
|
+
created: function () {
|
|
810
|
+
this.createData();
|
|
811
|
+
},
|
|
812
|
+
data: function () {
|
|
813
|
+
return {
|
|
814
|
+
address: '',
|
|
815
|
+
iconSize: DEFAULT_SIZE,
|
|
816
|
+
isAlternativeIcon: false,
|
|
817
|
+
publicKey: '0x',
|
|
818
|
+
type: 'empty'
|
|
819
|
+
};
|
|
820
|
+
},
|
|
821
|
+
methods: {
|
|
822
|
+
createData: function () {
|
|
823
|
+
this.iconSize = this.size || DEFAULT_SIZE;
|
|
824
|
+
this.type = this.theme;
|
|
825
|
+
this.isAlternativeIcon = this.isAlternative || false;
|
|
826
|
+
this.recodeAddress();
|
|
827
|
+
},
|
|
828
|
+
recodeAddress: function () {
|
|
829
|
+
const { address, publicKey } = encodeAccount(this.value);
|
|
830
|
+
this.address = address;
|
|
831
|
+
this.publicKey = publicKey;
|
|
832
|
+
}
|
|
833
|
+
},
|
|
834
|
+
props: ['prefix', 'isAlternative', 'size', 'theme', 'value'],
|
|
835
|
+
render() {
|
|
836
|
+
const { address, iconSize, isAlternativeIcon, publicKey, type } = this.$data;
|
|
837
|
+
if (type === 'empty') {
|
|
838
|
+
return vue.h(Empty, {
|
|
839
|
+
...adaptVNodeAttrs({
|
|
840
|
+
key: address,
|
|
841
|
+
size: iconSize
|
|
842
|
+
})
|
|
843
|
+
}, []);
|
|
844
|
+
}
|
|
845
|
+
else if (type === 'jdenticon') {
|
|
846
|
+
return vue.h(Jdenticon, {
|
|
847
|
+
...adaptVNodeAttrs({
|
|
848
|
+
key: address,
|
|
849
|
+
publicKey,
|
|
850
|
+
size: iconSize
|
|
851
|
+
})
|
|
852
|
+
}, []);
|
|
853
|
+
}
|
|
854
|
+
else if (type === 'substrate') {
|
|
855
|
+
throw new Error('substrate type is not supported');
|
|
856
|
+
}
|
|
857
|
+
const cmp = type.charAt(0).toUpperCase() + type.slice(1);
|
|
858
|
+
if (['Beachball', 'Polkadot'].includes(cmp)) {
|
|
859
|
+
const component = cmp === 'Beachball'
|
|
860
|
+
? Beachball
|
|
861
|
+
: Polkadot;
|
|
862
|
+
return vue.h(component, {
|
|
863
|
+
...adaptVNodeAttrs({
|
|
864
|
+
address,
|
|
865
|
+
isAlternative: isAlternativeIcon,
|
|
866
|
+
key: address,
|
|
867
|
+
size: iconSize
|
|
868
|
+
})
|
|
869
|
+
}, []);
|
|
870
|
+
}
|
|
871
|
+
else {
|
|
872
|
+
return vue.h(cmp, {}, []);
|
|
873
|
+
}
|
|
874
|
+
},
|
|
875
|
+
watch: {
|
|
876
|
+
value: function () {
|
|
877
|
+
this.recodeAddress();
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
|
|
882
|
+
const packageInfo = { name: '@pezkuwi/vue-identicon', path: (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('bundle-pezkuwi-vue-identicon.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('bundle-pezkuwi-vue-identicon.js', document.baseURI).href))) ? new URL((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('bundle-pezkuwi-vue-identicon.js', document.baseURI).href))).pathname.substring(0, new URL((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('bundle-pezkuwi-vue-identicon.js', document.baseURI).href))).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '3.16.6' };
|
|
883
|
+
|
|
884
|
+
exports.Identicon = Identicon;
|
|
885
|
+
exports.packageInfo = packageInfo;
|
|
886
|
+
|
|
887
|
+
}));
|