1import { useCallback } from 'react';
2import { saveAs } from 'file-saver';
3import { sigil, stringRenderer } from 'urbit-sigil-js';
4import * as ob from 'urbit-ob';
11} from 'lib/SigilDownloader';
13export default function useSigilDownloader(canvasRef) {
14 const downloadSigil = useCallback(
15 (point, colors, size) => {
16 const patp = ob.patp(point);
18 const _size = size / window.devicePixelRatio;
20 const DATA_URI_PREFIX = 'data:image/svg+xml;base64,';
22 // initialize canvas element
23 const canvas = initCanvas(canvasRef.current, { x: _size, y: _size });
24 const ctx = canvas.getContext('2d');
26 // make sigil svg and encoded into base64
29 renderer: stringRenderer,
32 margin: (54 / 256) * _size,
36 const svgDocument = new DOMParser().parseFromString(svg, 'image/svg+xml');
37 svgDocument.documentElement.width.baseVal.valueAsString = `${size}px`;
38 svgDocument.documentElement.height.baseVal.valueAsString = `${size}px`;
39 const svgText = new XMLSerializer().serializeToString(svgDocument);
40 const svg64 = btoa(svgText);
42 return loadImg(DATA_URI_PREFIX + svg64, _size, _size)
44 ctx.drawImage(img, 0, 0, _size, _size);
45 const png = dataURItoBlob(canvas.toDataURL('image/png'));
46 saveAs(png, `${patp.slice(1)}-sigil.png`);
47 ctx.clearRect(0, 0, _size, _size);
49 .catch(() => 'Error generating sigil')
51 cleanupCanvas(canvasRef.current);
57 return { downloadSigil };
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list