@slithy/prim-interface 0.2.8 → 0.2.10

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.
Files changed (2) hide show
  1. package/dist/index.js +9 -1
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -129,8 +129,16 @@ function saveVector(svgString, options) {
129
129
  async function copyVector(svgString) {
130
130
  await navigator.clipboard.writeText(svgString);
131
131
  }
132
+ function dataUrlToBlob(dataUrl) {
133
+ const [header, data] = dataUrl.split(",");
134
+ const mime = header.match(/:(.*?);/)[1];
135
+ const bytes = atob(data);
136
+ const arr = new Uint8Array(bytes.length);
137
+ for (let i = 0; i < bytes.length; i++) arr[i] = bytes.charCodeAt(i);
138
+ return new Blob([arr], { type: mime });
139
+ }
132
140
  async function copyRaster(canvas) {
133
- const blob = await new Promise((resolve, reject) => canvas.toBlob((b) => b ? resolve(b) : reject(new Error("toBlob failed"))));
141
+ const blob = dataUrlToBlob(canvas.toDataURL("image/png"));
134
142
  await navigator.clipboard.write([new ClipboardItem({ "image/png": blob })]);
135
143
  }
136
144
  async function share(canvas, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slithy/prim-interface",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "Browser-facing API for primitive-based image reconstruction.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -22,8 +22,8 @@
22
22
  "tsup": "^8",
23
23
  "typescript": "^5",
24
24
  "vitest": "^4",
25
- "@slithy/tsconfig": "0.0.0",
26
- "@slithy/eslint-config": "0.0.0"
25
+ "@slithy/eslint-config": "0.0.0",
26
+ "@slithy/tsconfig": "0.0.0"
27
27
  },
28
28
  "author": {
29
29
  "name": "Matthew Campagna",