1import React, { useRef, useState } from 'react';
2import * as ob from 'urbit-ob';
3import { saveAs } from 'file-saver';
4import { sigil, stringRenderer } from 'urbit-sigil-js';
6import { dataURItoBlob, loadImg, initCanvas } from 'lib/SigilDownloader';
8import { DownloadButton } from 'components/Buttons';
10export default function DownloadSigilButton({
12 children = 'Download Sigil',
15 const [downloaded, setDownloaded] = useState(false);
16 const downloadSigil = () => {
17 const patp = ob.patp(point);
19 const _size = 1024 / window.devicePixelRatio;
22 const DATA_URI_PREFIX = 'data:image/svg+xml;base64,';
24 // initialize canvas element
25 const canvas = initCanvas(canvasRef.current, { x: _size, y: _size });
26 const ctx = canvas.getContext('2d');
28 // make sigil svg and encoded into base64
31 renderer: stringRenderer,
33 colors: ['#FFFFFF', '#000000'],
34 margin: (54 / 256) * _size,
38 const svgDocument = new DOMParser().parseFromString(svg, 'image/svg+xml');
39 svgDocument.documentElement.width.baseVal.valueAsString = `${pngSize}px`;
40 svgDocument.documentElement.height.baseVal.valueAsString = `${pngSize}px`;
41 const svgText = new XMLSerializer().serializeToString(svgDocument);
42 const svg64 = btoa(svgText);
44 const pngTask = loadImg(DATA_URI_PREFIX + svg64, _size, _size).then(img => {
45 ctx.drawImage(img, 0, 0, _size, _size);
46 const png = dataURItoBlob(canvas.toDataURL('image/png'));
47 saveAs(png, `${patp.slice(1)}-sigil.png`);
48 ctx.clearRect(0, 0, pngSize, pngSize);
55 const canvasRef = useRef(null);
62 onClick={downloadSigil}
64 downloaded ? 'Downloaded!' : 'Download the sigil for this point'
69 <canvas style={{ display: 'none' }} ref={canvasRef} />
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