UNPKG

blockies-react-svg

Version:

Blockies react SVG function component, blocky identicons, address-unique ethereum avatar, SVG base64 generation in browser or nodejs.

41 lines (38 loc) 2.39 kB
import { _ as __rest } from './_tslib-5dd6082a.mjs'; import { jsx, jsxs } from 'react/jsx-runtime'; import { b as buildOpts, c as createImageData } from './blockies-a884f18e.mjs'; const store = Object.create(null); function BlockiesSvgSync(props) { let { address, size = 8, scale = 10, caseSensitive = false } = props, rest = __rest(props, ["address", "size", "scale", "caseSensitive"]); const width = size * scale; if (!address) return (jsx("svg", Object.assign({}, rest, { width: width, height: width, viewBox: `0 0 ${width} ${width}`, xmlns: 'http://www.w3.org/2000/svg' }, { children: 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 = buildOpts({ seed: address, size, scale }); imageData = createImageData(opts.size); store[address] = { opts, imageData }; } return (jsxs("svg", Object.assign({}, rest, { width: width, height: width, viewBox: `0 0 ${width} ${width}`, xmlns: 'http://www.w3.org/2000/svg' }, { children: [jsx("rect", { width: width, height: width, fill: opts.bgcolor }), 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 jsx("rect", { width: scale, height: scale, x: row, y: col }, `${address}-${i}`); } }) })), 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 jsx("rect", { width: scale, height: scale, x: row, y: col }, `${address}-${i}`); } }) }))] }))); } export { BlockiesSvgSync as default }; //# sourceMappingURL=BlockiesSvgSync.mjs.map