blockies-react-svg
Version:
Blockies react SVG function component, blocky identicons, address-unique ethereum avatar, SVG base64 generation in browser or nodejs.
43 lines (39 loc) • 2.48 kB
JavaScript
;
var _tslib = require('./_tslib-f6c1ff74.cjs');
var jsxRuntime = require('react/jsx-runtime');
var blockies = require('./blockies-ce1f6c6e.cjs');
const store = Object.create(null);
function BlockiesSvgSync(props) {
let { address, size = 8, scale = 10, caseSensitive = false } = props, rest = _tslib.__rest(props, ["address", "size", "scale", "caseSensitive"]);
const width = size * scale;
if (!address)
return (jsxRuntime.jsx("svg", Object.assign({}, rest, { width: width, height: width, viewBox: `0 0 ${width} ${width}`, xmlns: 'http://www.w3.org/2000/svg' }, { children: jsxRuntime.jsx("rect", { width: width, height: width, fill: 'black' }) })));
let opts = null;
let imageData = null;
if (!caseSensitive)
address = address.toLowerCase();
if (store[address] && store[address].opts.size === size) {
opts = store[address].opts;
imageData = store[address].imageData;
}
else {
opts = blockies.buildOpts({ seed: address, size, scale });
imageData = blockies.createImageData(opts.size);
store[address] = { opts, imageData };
}
return (jsxRuntime.jsxs("svg", Object.assign({}, rest, { width: width, height: width, viewBox: `0 0 ${width} ${width}`, xmlns: 'http://www.w3.org/2000/svg' }, { children: [jsxRuntime.jsx("rect", { width: width, height: width, fill: opts.bgcolor }), jsxRuntime.jsx("g", Object.assign({ fill: opts.color }, { children: imageData === null || imageData === void 0 ? void 0 : imageData.map((value, i) => {
if (value === 1) {
const row = (i % size) * scale;
const col = Math.floor(i / size) * scale;
return jsxRuntime.jsx("rect", { width: scale, height: scale, x: row, y: col }, `${address}-${i}`);
}
}) })), jsxRuntime.jsx("g", Object.assign({ fill: opts.spotcolor }, { children: imageData === null || imageData === void 0 ? void 0 : imageData.map((value, i) => {
if (value === 2) {
const row = (i % size) * scale;
const col = Math.floor(i / size) * scale;
return jsxRuntime.jsx("rect", { width: scale, height: scale, x: row, y: col }, `${address}-${i}`);
}
}) }))] })));
}
module.exports = BlockiesSvgSync;
//# sourceMappingURL=BlockiesSvgSync.cjs.map