@slithy/prim-interface 0.2.7 → 0.2.9
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.
- package/README.md +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +20 -8
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -80,7 +80,7 @@ Higher-level (rasterize SVG at save time for crisp output):
|
|
|
80
80
|
|
|
81
81
|
- **`saveRasterFromVector(svgString, width, height, format?, quality?, options?)`** — downloads PNG or JPEG rasterized from the SVG
|
|
82
82
|
- **`copyRasterFromVector(svgString, width, height)`** — copies a PNG rasterized from the SVG to the clipboard
|
|
83
|
-
- **`shareFromVector(svgString, width, height)`** — shares a PNG rasterized from the SVG via the Web Share API
|
|
83
|
+
- **`shareFromVector(svgString, width, height, options?)`** — shares a PNG rasterized from the SVG via the Web Share API
|
|
84
84
|
|
|
85
85
|
Lower-level (operate directly on a canvas or SVG string):
|
|
86
86
|
|
|
@@ -88,7 +88,7 @@ Lower-level (operate directly on a canvas or SVG string):
|
|
|
88
88
|
- **`saveVector(svgString, options?)`** — downloads SVG
|
|
89
89
|
- **`copyRaster(canvas)`** — copies PNG to clipboard
|
|
90
90
|
- **`copyVector(svgString)`** — copies SVG markup to clipboard
|
|
91
|
-
- **`share(canvas)`** — shares via Web Share API if available
|
|
91
|
+
- **`share(canvas, options?)`** — shares via Web Share API if available
|
|
92
92
|
|
|
93
93
|
**`SaveOptions`** controls download filenames, formatted as `${filename}--${suffix}.${ext}`:
|
|
94
94
|
|
package/dist/index.d.ts
CHANGED
|
@@ -50,10 +50,10 @@ interface SaveOptions {
|
|
|
50
50
|
declare function saveRaster(canvas: HTMLCanvasElement, format?: 'png' | 'jpeg', quality?: number, options?: SaveOptions): void;
|
|
51
51
|
declare function saveRasterFromVector(svgString: string, width: number, height: number, format?: 'png' | 'jpeg', quality?: number, options?: SaveOptions): Promise<void>;
|
|
52
52
|
declare function copyRasterFromVector(svgString: string, width: number, height: number): Promise<void>;
|
|
53
|
-
declare function shareFromVector(svgString: string, width: number, height: number): Promise<void>;
|
|
53
|
+
declare function shareFromVector(svgString: string, width: number, height: number, options?: SaveOptions): Promise<void>;
|
|
54
54
|
declare function saveVector(svgString: string, options?: SaveOptions): void;
|
|
55
55
|
declare function copyVector(svgString: string): Promise<void>;
|
|
56
56
|
declare function copyRaster(canvas: HTMLCanvasElement): Promise<void>;
|
|
57
|
-
declare function share(canvas: HTMLCanvasElement): Promise<void>;
|
|
57
|
+
declare function share(canvas: HTMLCanvasElement, options?: SaveOptions): Promise<void>;
|
|
58
58
|
|
|
59
59
|
export { type Config, type JobHandle, type RunCallbacks, type SaveOptions, type StepResult, copyRaster, copyRasterFromVector, copyVector, run, saveRaster, saveRasterFromVector, saveVector, share, shareFromVector };
|
package/dist/index.js
CHANGED
|
@@ -113,12 +113,19 @@ async function saveRasterFromVector(svgString, width, height, format = "png", qu
|
|
|
113
113
|
saveRaster(canvas, format, quality, options);
|
|
114
114
|
}
|
|
115
115
|
async function copyRasterFromVector(svgString, width, height) {
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
await navigator.clipboard.write([
|
|
117
|
+
new ClipboardItem({
|
|
118
|
+
"image/png": svgToCanvas(svgString, width, height).then(
|
|
119
|
+
(canvas) => new Promise(
|
|
120
|
+
(resolve, reject) => canvas.toBlob((b) => b ? resolve(b) : reject(new Error("toBlob failed")))
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
})
|
|
124
|
+
]);
|
|
118
125
|
}
|
|
119
|
-
async function shareFromVector(svgString, width, height) {
|
|
126
|
+
async function shareFromVector(svgString, width, height, options) {
|
|
120
127
|
const canvas = await svgToCanvas(svgString, width, height);
|
|
121
|
-
return share(canvas);
|
|
128
|
+
return share(canvas, options);
|
|
122
129
|
}
|
|
123
130
|
function saveVector(svgString, options) {
|
|
124
131
|
const blob = new Blob([svgString], { type: "image/svg+xml" });
|
|
@@ -130,12 +137,17 @@ async function copyVector(svgString) {
|
|
|
130
137
|
await navigator.clipboard.writeText(svgString);
|
|
131
138
|
}
|
|
132
139
|
async function copyRaster(canvas) {
|
|
133
|
-
|
|
134
|
-
|
|
140
|
+
await navigator.clipboard.write([
|
|
141
|
+
new ClipboardItem({
|
|
142
|
+
"image/png": new Promise(
|
|
143
|
+
(resolve, reject) => canvas.toBlob((b) => b ? resolve(b) : reject(new Error("toBlob failed")))
|
|
144
|
+
)
|
|
145
|
+
})
|
|
146
|
+
]);
|
|
135
147
|
}
|
|
136
|
-
async function share(canvas) {
|
|
148
|
+
async function share(canvas, options) {
|
|
137
149
|
const blob = await new Promise((resolve, reject) => canvas.toBlob((b) => b ? resolve(b) : reject(new Error("toBlob failed"))));
|
|
138
|
-
const file = new File([blob], "
|
|
150
|
+
const file = new File([blob], buildFilename("png", options), { type: "image/png" });
|
|
139
151
|
if (navigator.canShare({ files: [file] })) {
|
|
140
152
|
await navigator.share({ files: [file] });
|
|
141
153
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slithy/prim-interface",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
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/
|
|
26
|
-
"@slithy/
|
|
25
|
+
"@slithy/tsconfig": "0.0.0",
|
|
26
|
+
"@slithy/eslint-config": "0.0.0"
|
|
27
27
|
},
|
|
28
28
|
"author": {
|
|
29
29
|
"name": "Matthew Campagna",
|