@slithy/prim-interface 1.0.2 → 1.0.4

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 CHANGED
@@ -105,7 +105,7 @@ interface StepResult {
105
105
 
106
106
  **`onComplete(serialized)`** — called when all steps finish. Receives a `SerializedOutput` — a compact, storage-ready representation of the full run that can be replayed via `replayOutput()`.
107
107
 
108
- **`onStop()`** — called when the job is stopped via `job.stop()`.
108
+ **`onStop(serialized)`** — called when the job is stopped via `job.stop()`. Receives the `SerializedOutput` of shapes placed so far, or `null` if stopped before any shapes were placed.
109
109
 
110
110
  **`onError(message)`** — called if the job fails (e.g. image failed to load or decode). The job is considered stopped after this; no further callbacks will fire.
111
111
 
@@ -113,13 +113,13 @@ interface StepResult {
113
113
 
114
114
  Higher-level (rasterize SVG at save time for crisp output):
115
115
 
116
- - **`saveRasterFromVector(svgString, width, height, format?, quality?, options?, background?)`** — downloads PNG or JPEG rasterized from the SVG. `background` fills the canvas before drawing: JPEG defaults to `'white'` (prevents black transparent areas); PNG defaults to transparent. Pass a `Background` value to override.
116
+ - **`saveRasterFromVector(svgString, width, height, options?)`** — downloads PNG or JPEG rasterized from the SVG. `background` fills the canvas before drawing: JPEG defaults to `'white'` (prevents black transparent areas); PNG defaults to transparent.
117
117
  - **`copyRasterFromVector(svgString, width, height)`** — copies a transparent PNG rasterized from the SVG to the clipboard
118
118
  - **`shareFromVector(svgString, width, height, options?)`** — shares a transparent PNG rasterized from the SVG via the Web Share API
119
119
 
120
120
  Lower-level (operate directly on a canvas or SVG string):
121
121
 
122
- - **`saveRaster(canvas, format?, quality?, options?)`** — downloads PNG or JPEG from a canvas
122
+ - **`saveRaster(canvas, options?)`** — downloads PNG or JPEG from a canvas
123
123
  - **`saveVector(svgString, options?)`** — downloads SVG
124
124
  - **`copyRaster(canvas)`** — copies PNG to clipboard
125
125
  - **`copyVector(svgString)`** — copies SVG markup to clipboard
@@ -134,7 +134,13 @@ interface SaveOptions {
134
134
  }
135
135
  ```
136
136
 
137
- Example: `saveRaster(canvas, 'png', 0.92, { filename: 'mountains', suffix: 'v2' })` `mountains--v2.png`
137
+ **`SaveRasterOptions`** extends `SaveOptions` with `format?: 'png' | 'jpeg'` and `quality?: number`.
138
+
139
+ **`SaveRasterFromVectorOptions`** extends `SaveOptions` with `format?`, `quality?`, and `background?: Background`.
140
+
141
+ **`ShareFromVectorOptions`** extends `SaveOptions` with `background?: Background`.
142
+
143
+ Example: `saveRaster(canvas, { format: 'png', quality: 0.92, filename: 'mountains', suffix: 'v2' })` → `mountains--v2.png`
138
144
 
139
145
  ### `replayOutput(data: SerializedOutput): ReplayResult`
140
146
 
@@ -148,13 +154,13 @@ const { raster, svg, svgString } = replayOutput(serializedData);
148
154
 
149
155
  **Shapes:** `Triangle`, `Rectangle`, `Ellipse`, `Circle`, `Square`, `Hexagon`, `Glyph`
150
156
 
151
- **Factories:** `makeNGon`, `makeRect`
157
+ **Factories:** `makeNGon`, `makeRect`, `makeCircle`, `makeEllipse`, `makeGlyph`
152
158
 
153
- **Factory option types:** `NGonOptions`, `RectOptions`
159
+ **Factory option types:** `NGonOptions`, `RectOptions`, `CircleOptions`, `EllipseOptions`, `GlyphOptions`
154
160
 
155
161
  **Functions:** `stepPerf`, `replayOutput`
156
162
 
157
- **Types:** `RGB`, `SerializedOutput`, `StepData`, `ReplayResult`, `ShapeInterface`, `Bbox`, `Background`
163
+ **Types:** `RGB`, `SerializedOutput`, `StepData`, `ReplayResult`, `ShapeInterface`, `Bbox`, `Background`, `SaveRasterOptions`, `SaveRasterFromVectorOptions`, `ShareFromVectorOptions`
158
164
 
159
165
  `Background` controls the canvas fill for `saveRasterFromVector`:
160
166
 
package/dist/index.d.ts CHANGED
@@ -62,6 +62,8 @@ interface SaveRasterFromVectorOptions extends SaveOptions {
62
62
  }
63
63
  interface ShareFromVectorOptions extends SaveOptions {
64
64
  background?: Background;
65
+ format?: 'png' | 'jpeg';
66
+ quality?: number;
65
67
  }
66
68
  type Background = string | [png: string, jpeg: string];
67
69
  declare function saveRaster(canvas: HTMLCanvasElement, options?: SaveRasterOptions): void;
@@ -71,6 +73,6 @@ declare function shareFromVector(svgString: string, width: number, height: numbe
71
73
  declare function saveVector(svgString: string, options?: SaveOptions): void;
72
74
  declare function copyVector(svgString: string): Promise<void>;
73
75
  declare function copyRaster(canvas: HTMLCanvasElement): Promise<void>;
74
- declare function share(canvas: HTMLCanvasElement, options?: SaveOptions): Promise<void>;
76
+ declare function share(canvas: HTMLCanvasElement, options?: SaveRasterOptions): Promise<void>;
75
77
 
76
78
  export { type Background, type Config, type JobHandle, type RunCallbacks, type SaveOptions, type SaveRasterFromVectorOptions, type SaveRasterOptions, type ShareFromVectorOptions, type StepResult, copyRaster, copyRasterFromVector, copyVector, run, runWorker, saveRaster, saveRasterFromVector, saveVector, share, shareFromVector };
package/dist/index.js CHANGED
@@ -225,7 +225,8 @@ async function copyRasterFromVector(svgString, width, height) {
225
225
  return copyRaster(canvas);
226
226
  }
227
227
  async function shareFromVector(svgString, width, height, options) {
228
- const canvas = await svgToCanvas(svgString, width, height, resolveBackground(options?.background, "png"));
228
+ const format = options?.format ?? "png";
229
+ const canvas = await svgToCanvas(svgString, width, height, resolveBackground(options?.background, format));
229
230
  return share(canvas, options);
230
231
  }
231
232
  function saveVector(svgString, options) {
@@ -250,8 +251,12 @@ async function copyRaster(canvas) {
250
251
  await navigator.clipboard.write([new ClipboardItem({ "image/png": blob })]);
251
252
  }
252
253
  async function share(canvas, options) {
253
- const blob = await new Promise((resolve, reject) => canvas.toBlob((b) => b ? resolve(b) : reject(new Error("toBlob failed"))));
254
- const file = new File([blob], buildFilename("png", options), { type: "image/png" });
254
+ const format = options?.format ?? "png";
255
+ const quality = options?.quality ?? 0.92;
256
+ const mimeType = format === "jpeg" ? "image/jpeg" : "image/png";
257
+ const ext = format === "jpeg" ? "jpg" : "png";
258
+ const blob = await new Promise((resolve, reject) => canvas.toBlob((b) => b ? resolve(b) : reject(new Error("toBlob failed")), mimeType, quality));
259
+ const file = new File([blob], buildFilename(ext, options), { type: mimeType });
255
260
  if (navigator.canShare({ files: [file] })) {
256
261
  await navigator.share({ files: [file] });
257
262
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slithy/prim-interface",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Browser-facing API for primitive-based image reconstruction.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -17,27 +17,17 @@
17
17
  "dist"
18
18
  ],
19
19
  "sideEffects": false,
20
- "scripts": {
21
- "clean": "rm -rf dist",
22
- "prepack": "rm -rf dist && tsup src/index.ts src/worker-entry.ts --format esm --dts",
23
- "build": "rm -rf dist && tsup src/index.ts src/worker-entry.ts --format esm --dts",
24
- "dev": "tsup src/index.ts src/worker-entry.ts --format esm --watch",
25
- "typecheck": "tsc --noEmit",
26
- "lint": "eslint .",
27
- "test": "vitest run",
28
- "test:watch": "vitest"
29
- },
30
20
  "dependencies": {
31
- "@slithy/prim-lib": "workspace:*"
21
+ "@slithy/prim-lib": "0.8.0"
32
22
  },
33
23
  "devDependencies": {
34
- "@slithy/eslint-config": "workspace:*",
35
- "@slithy/tsconfig": "workspace:*",
36
24
  "@vitest/coverage-v8": "^4.1.2",
37
25
  "jsdom": "^29.0.1",
38
26
  "tsup": "^8",
39
27
  "typescript": "^5",
40
- "vitest": "^4.1.2"
28
+ "vitest": "^4.1.2",
29
+ "@slithy/tsconfig": "0.0.0",
30
+ "@slithy/eslint-config": "0.0.0"
41
31
  },
42
32
  "author": {
43
33
  "name": "Matthew Campagna",
@@ -58,5 +48,14 @@
58
48
  },
59
49
  "publishConfig": {
60
50
  "access": "public"
51
+ },
52
+ "scripts": {
53
+ "clean": "rm -rf dist",
54
+ "build": "rm -rf dist && tsup src/index.ts src/worker-entry.ts --format esm --dts",
55
+ "dev": "tsup src/index.ts src/worker-entry.ts --format esm --watch",
56
+ "typecheck": "tsc --noEmit",
57
+ "lint": "eslint .",
58
+ "test": "vitest run",
59
+ "test:watch": "vitest"
61
60
  }
62
- }
61
+ }