@richardmcquiston01/ai-tools 0.1.2 → 0.3.0
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 +60 -1
- package/dist/browser-image-codec.d.ts +3 -0
- package/dist/browser-image-codec.d.ts.map +1 -0
- package/dist/browser-image-codec.js +32 -0
- package/dist/browser-image-codec.js.map +1 -0
- package/dist/onnx-background-remover.d.ts +49 -0
- package/dist/onnx-background-remover.d.ts.map +1 -0
- package/dist/onnx-background-remover.js +80 -0
- package/dist/onnx-background-remover.js.map +1 -0
- package/dist/provider.d.ts +3 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +6 -0
- package/dist/provider.js.map +1 -0
- package/package.json +34 -5
package/README.md
CHANGED
|
@@ -36,9 +36,68 @@ const upscaler = await loadUpscaleModel(4);
|
|
|
36
36
|
const bigger: ImageData = await upscaler.upscale(image);
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
## Entry points
|
|
40
|
+
|
|
41
|
+
TensorFlow.js and ONNX Runtime are large, and most apps need only one of them. Import from the entry point you need so a bundler never has to include the rest:
|
|
42
|
+
|
|
43
|
+
| Import | Brings | Heavy dependency |
|
|
44
|
+
| ------------------------------------------------- | ----------------------------------- | --------------------------- |
|
|
45
|
+
| `@richardmcquiston01/ai-tools/background-removal` | `loadBackgroundRemovalModel` | ONNX Runtime Web |
|
|
46
|
+
| `@richardmcquiston01/ai-tools/auto-crop` | `computeCropRegion` | none |
|
|
47
|
+
| `@richardmcquiston01/ai-tools/upscale` | `loadUpscaleModel` | TensorFlow.js, the upscaler |
|
|
48
|
+
| `@richardmcquiston01/ai-tools/provider` | `OnnxBackgroundRemover` (see below) | none until the model loads |
|
|
49
|
+
| `@richardmcquiston01/ai-tools` | all of the above except `provider` | everything |
|
|
50
|
+
|
|
51
|
+
The main entry keeps working as before; the others are for apps that care about size. `computeCropRegion` is plain maths, so auto-crop's region helper never needs a model runtime (running the model for the saliency mask still does: that is `background-removal`).
|
|
52
|
+
|
|
53
|
+
## The model file
|
|
54
|
+
|
|
55
|
+
The U²-Net model is exported, so a bundler can emit it for you and you can drop any copy step. With Vite:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import modelUrl from "@richardmcquiston01/ai-tools/models/u2netp.onnx?url";
|
|
59
|
+
import { loadBackgroundRemovalModel } from "@richardmcquiston01/ai-tools/background-removal";
|
|
60
|
+
|
|
61
|
+
const model = await loadBackgroundRemovalModel(modelUrl);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
In Node, `import.meta.resolve("@richardmcquiston01/ai-tools/models/u2netp.onnx")` gives its location. The licence and attribution files in `models/` are exported the same way.
|
|
65
|
+
|
|
66
|
+
## As an `ImageGenerator` (optional)
|
|
67
|
+
|
|
68
|
+
`@richardmcquiston01/ai-tools/provider` wraps background removal as an `ImageGenerator` from [`@richardmcquiston01/ai-providers`](https://www.npmjs.com/package/@richardmcquiston01/ai-providers), so an app can offer it next to other providers (a local ComfyUI, a hosted API) and swap between them through one interface. `ai-providers` is an optional peer dependency: install it only if you use this entry point.
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import {
|
|
72
|
+
browserImageCodec,
|
|
73
|
+
lazyBackgroundRemovalModel,
|
|
74
|
+
OnnxBackgroundRemover,
|
|
75
|
+
REMOVE_BACKGROUND_MODE,
|
|
76
|
+
} from "@richardmcquiston01/ai-tools/provider";
|
|
77
|
+
|
|
78
|
+
const remover = new OnnxBackgroundRemover({
|
|
79
|
+
// ONNX Runtime is imported on first use, so listing the provider costs nothing.
|
|
80
|
+
loadModel: lazyBackgroundRemovalModel("/models/u2netp.onnx"),
|
|
81
|
+
// Providers exchange encoded images; the codec turns them into pixels and back.
|
|
82
|
+
codec: browserImageCodec,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const result = await remover.generateImage({
|
|
86
|
+
instructions: "",
|
|
87
|
+
prompt: "",
|
|
88
|
+
images: [{ mimeType: "image/png", data: pngBytes }],
|
|
89
|
+
mode: REMOVE_BACKGROUND_MODE,
|
|
90
|
+
});
|
|
91
|
+
if (result.ok)
|
|
92
|
+
use(result.value.image); // a PNG with a transparent background
|
|
93
|
+
else console.error(result.error); // names the provider and what failed
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`browserImageCodec` needs the DOM (canvas); pass your own `ImageCodec` elsewhere. The model is loaded once and shared between runs, and a failed load is retried on the next call.
|
|
97
|
+
|
|
39
98
|
## Model files and offline use
|
|
40
99
|
|
|
41
|
-
- **Background removal:** the package ships `models/u2netp.onnx` (about 4.5 MB). Serve or import it
|
|
100
|
+
- **Background removal:** the package ships `models/u2netp.onnx` (about 4.5 MB) and exports it (see above). Serve or import it and pass it to `loadBackgroundRemovalModel`; nothing is fetched on your behalf.
|
|
42
101
|
- **Upscaling:** by default the model definitions load their weights from a public CDN mirror of `@upscalerjs/esrgan-slim`. For a self-contained deployment, serve that package's `models/<scale>x/` directory and pass the resolved `model.json` URL as `modelUrl`.
|
|
43
102
|
- **Size:** TensorFlow.js and ONNX Runtime are large. Load this package lazily (`await import(...)`) rather than in your main bundle.
|
|
44
103
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-image-codec.d.ts","sourceRoot":"","sources":["../src/browser-image-codec.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,8BAA8B,CAAC;AAW5E,eAAO,MAAM,iBAAiB,EAAE,UA4B/B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function createContext(width, height) {
|
|
2
|
+
const canvas = document.createElement("canvas");
|
|
3
|
+
canvas.width = width;
|
|
4
|
+
canvas.height = height;
|
|
5
|
+
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
6
|
+
if (!ctx)
|
|
7
|
+
throw new Error("Canvas is unavailable in this browser.");
|
|
8
|
+
return ctx;
|
|
9
|
+
}
|
|
10
|
+
export const browserImageCodec = {
|
|
11
|
+
async encode(image) {
|
|
12
|
+
const ctx = createContext(image.width, image.height);
|
|
13
|
+
ctx.putImageData(new ImageData(image.data, image.width, image.height), 0, 0);
|
|
14
|
+
const blob = await new Promise((resolve) => ctx.canvas.toBlob(resolve, "image/png"));
|
|
15
|
+
if (!blob)
|
|
16
|
+
throw new Error("The browser could not encode the image as PNG.");
|
|
17
|
+
return { mimeType: "image/png", data: new Uint8Array(await blob.arrayBuffer()) };
|
|
18
|
+
},
|
|
19
|
+
async decode(image) {
|
|
20
|
+
const bitmap = await createImageBitmap(new Blob([image.data], { type: image.mimeType }));
|
|
21
|
+
try {
|
|
22
|
+
const ctx = createContext(bitmap.width, bitmap.height);
|
|
23
|
+
ctx.drawImage(bitmap, 0, 0);
|
|
24
|
+
const { data } = ctx.getImageData(0, 0, bitmap.width, bitmap.height);
|
|
25
|
+
return { width: bitmap.width, height: bitmap.height, data };
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
bitmap.close();
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=browser-image-codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-image-codec.js","sourceRoot":"","sources":["../src/browser-image-codec.ts"],"names":[],"mappings":"AAOA,SAAS,aAAa,CAAC,KAAa,EAAE,MAAc;IAClD,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC;IAClE,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IACpE,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,CAAC,MAAM,iBAA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MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;QAC9D,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The in-browser U²-Net background remover, as an `ImageGenerator`.
|
|
3
|
+
*
|
|
4
|
+
* It runs the model from this package (ONNX Runtime Web) on the visitor's own
|
|
5
|
+
* machine, so it needs no server, no account and no network once the model is
|
|
6
|
+
* cached — and, being an `ImageGenerator` from
|
|
7
|
+
* `@richardmcquiston01/ai-providers`, it is interchangeable with any other
|
|
8
|
+
* provider (a local ComfyUI, a hosted API). Providers exchange *encoded*
|
|
9
|
+
* images, so an {@link ImageCodec} turns them into pixels and back.
|
|
10
|
+
*/
|
|
11
|
+
import { type AiImage, type ImageGenerator, type ImageRequest, type ImageResult, type Result } from "@richardmcquiston01/ai-providers";
|
|
12
|
+
import type { BackgroundRemovalModel, LoadBackgroundRemovalModelOptions } from "./background-removal.js";
|
|
13
|
+
/** The one thing this provider does. */
|
|
14
|
+
export declare const REMOVE_BACKGROUND_MODE = "remove-background";
|
|
15
|
+
/** RGBA pixels, row-major: structurally an `ImageData`, without needing one. */
|
|
16
|
+
export interface PixelBuffer {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
data: Uint8ClampedArray;
|
|
20
|
+
}
|
|
21
|
+
/** Converts between the encoded images providers exchange and RGBA pixels. */
|
|
22
|
+
export interface ImageCodec {
|
|
23
|
+
encode(image: PixelBuffer): Promise<AiImage>;
|
|
24
|
+
decode(image: AiImage): Promise<PixelBuffer>;
|
|
25
|
+
}
|
|
26
|
+
export interface OnnxBackgroundRemoverOptions {
|
|
27
|
+
/** Loads the model. Called once; a failed load is retried on the next run. */
|
|
28
|
+
loadModel: () => Promise<BackgroundRemovalModel>;
|
|
29
|
+
codec: ImageCodec;
|
|
30
|
+
}
|
|
31
|
+
export declare class OnnxBackgroundRemover implements ImageGenerator {
|
|
32
|
+
readonly provider = "onnx-web";
|
|
33
|
+
readonly model = "u2netp";
|
|
34
|
+
private readonly loadModel;
|
|
35
|
+
private readonly codec;
|
|
36
|
+
private modelPromise;
|
|
37
|
+
constructor(options: OnnxBackgroundRemoverOptions);
|
|
38
|
+
listModes(): Promise<Result<readonly string[]>>;
|
|
39
|
+
generateImage(request: ImageRequest): Promise<Result<ImageResult>>;
|
|
40
|
+
/** Load the model once and share it; forget a failed load so it can retry. */
|
|
41
|
+
private getModel;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A `loadModel` for {@link OnnxBackgroundRemover} that imports ONNX Runtime
|
|
45
|
+
* only when the model is first needed, so a bundler keeps it out of the chunk
|
|
46
|
+
* that merely lists the provider.
|
|
47
|
+
*/
|
|
48
|
+
export declare function lazyBackgroundRemovalModel(model: string | ArrayBuffer | Uint8Array, options?: LoadBackgroundRemovalModelOptions): () => Promise<BackgroundRemovalModel>;
|
|
49
|
+
//# sourceMappingURL=onnx-background-remover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onnx-background-remover.d.ts","sourceRoot":"","sources":["../src/onnx-background-remover.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAIL,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,MAAM,EACZ,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EACV,sBAAsB,EACtB,iCAAiC,EAClC,MAAM,yBAAyB,CAAC;AAEjC,wCAAwC;AACxC,eAAO,MAAM,sBAAsB,sBAAsB,CAAC;AAE1D,gFAAgF;AAChF,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED,8EAA8E;AAC9E,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7C,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC9C;AAED,MAAM,WAAW,4BAA4B;IAC3C,8EAA8E;IAC9E,SAAS,EAAE,MAAM,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACjD,KAAK,EAAE,UAAU,CAAC;CACnB;AAED,qBAAa,qBAAsB,YAAW,cAAc;IAC1D,QAAQ,CAAC,QAAQ,cAAc;IAC/B,QAAQ,CAAC,KAAK,YAAY;IAE1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwC;IAClE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,YAAY,CAAgD;gBAExD,OAAO,EAAE,4BAA4B;IAK3C,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,SAAS,MAAM,EAAE,CAAC,CAAC;IAI/C,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAqCxE,8EAA8E;IAC9E,OAAO,CAAC,QAAQ;CASjB;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,EACxC,OAAO,CAAC,EAAE,iCAAiC,GAC1C,MAAM,OAAO,CAAC,sBAAsB,CAAC,CAKvC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The in-browser U²-Net background remover, as an `ImageGenerator`.
|
|
3
|
+
*
|
|
4
|
+
* It runs the model from this package (ONNX Runtime Web) on the visitor's own
|
|
5
|
+
* machine, so it needs no server, no account and no network once the model is
|
|
6
|
+
* cached — and, being an `ImageGenerator` from
|
|
7
|
+
* `@richardmcquiston01/ai-providers`, it is interchangeable with any other
|
|
8
|
+
* provider (a local ComfyUI, a hosted API). Providers exchange *encoded*
|
|
9
|
+
* images, so an {@link ImageCodec} turns them into pixels and back.
|
|
10
|
+
*/
|
|
11
|
+
import { describeUnknownError, err, ok, } from "@richardmcquiston01/ai-providers";
|
|
12
|
+
/** The one thing this provider does. */
|
|
13
|
+
export const REMOVE_BACKGROUND_MODE = "remove-background";
|
|
14
|
+
export class OnnxBackgroundRemover {
|
|
15
|
+
provider = "onnx-web";
|
|
16
|
+
model = "u2netp";
|
|
17
|
+
loadModel;
|
|
18
|
+
codec;
|
|
19
|
+
modelPromise = null;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.loadModel = options.loadModel;
|
|
22
|
+
this.codec = options.codec;
|
|
23
|
+
}
|
|
24
|
+
async listModes() {
|
|
25
|
+
return ok([REMOVE_BACKGROUND_MODE]);
|
|
26
|
+
}
|
|
27
|
+
async generateImage(request) {
|
|
28
|
+
const label = `${this.provider} (model "${this.model}")`;
|
|
29
|
+
if (request.mode !== null && request.mode !== REMOVE_BACKGROUND_MODE) {
|
|
30
|
+
return err(`${label} has no mode "${request.mode}"; its only mode is "${REMOVE_BACKGROUND_MODE}".`);
|
|
31
|
+
}
|
|
32
|
+
const input = request.images[0];
|
|
33
|
+
if (!input) {
|
|
34
|
+
return err(`${label} needs the image to cut out, but the request had none.`);
|
|
35
|
+
}
|
|
36
|
+
if (request.signal?.aborted) {
|
|
37
|
+
return err(`${label} was cancelled before it started.`);
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const model = await this.getModel();
|
|
41
|
+
const pixels = await this.codec.decode(input);
|
|
42
|
+
const cutout = await model.removeBackground(new ImageData(pixels.data, pixels.width, pixels.height));
|
|
43
|
+
// The model can't be interrupted mid-run, so honour a cancel afterwards.
|
|
44
|
+
if (request.signal?.aborted) {
|
|
45
|
+
return err(`${label} was cancelled while it was running.`);
|
|
46
|
+
}
|
|
47
|
+
const image = await this.codec.encode({
|
|
48
|
+
width: cutout.width,
|
|
49
|
+
height: cutout.height,
|
|
50
|
+
data: cutout.data,
|
|
51
|
+
});
|
|
52
|
+
return ok({ image, notes: null });
|
|
53
|
+
}
|
|
54
|
+
catch (cause) {
|
|
55
|
+
return err(`${label} failed: ${describeUnknownError(cause)}`, cause);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Load the model once and share it; forget a failed load so it can retry. */
|
|
59
|
+
getModel() {
|
|
60
|
+
if (!this.modelPromise) {
|
|
61
|
+
this.modelPromise = this.loadModel().catch((cause) => {
|
|
62
|
+
this.modelPromise = null;
|
|
63
|
+
throw cause;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return this.modelPromise;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A `loadModel` for {@link OnnxBackgroundRemover} that imports ONNX Runtime
|
|
71
|
+
* only when the model is first needed, so a bundler keeps it out of the chunk
|
|
72
|
+
* that merely lists the provider.
|
|
73
|
+
*/
|
|
74
|
+
export function lazyBackgroundRemovalModel(model, options) {
|
|
75
|
+
return async () => {
|
|
76
|
+
const { loadBackgroundRemovalModel } = await import("./background-removal.js");
|
|
77
|
+
return loadBackgroundRemovalModel(model, options);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=onnx-background-remover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onnx-background-remover.js","sourceRoot":"","sources":["../src/onnx-background-remover.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EACL,oBAAoB,EACpB,GAAG,EACH,EAAE,GAMH,MAAM,kCAAkC,CAAC;AAM1C,wCAAwC;AACxC,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAqB1D,MAAM,OAAO,qBAAqB;IACvB,QAAQ,GAAG,UAAU,CAAC;IACtB,KAAK,GAAG,QAAQ,CAAC;IAET,SAAS,CAAwC;IACjD,KAAK,CAAa;IAC3B,YAAY,GAA2C,IAAI,CAAC;IAEpE,YAAY,OAAqC;QAC/C,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}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Entry point for `@richardmcquiston01/ai-tools/provider`: the background
|
|
2
|
+
// remover as an `ImageGenerator`. Kept apart from the main entry so that code
|
|
3
|
+
// that only wants the raw models never needs `@richardmcquiston01/ai-providers`.
|
|
4
|
+
export * from "./onnx-background-remover.js";
|
|
5
|
+
export * from "./browser-image-codec.js";
|
|
6
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E;AAC9E,iFAAiF;AACjF,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@richardmcquiston01/ai-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "In-browser AI image tools (background removal, upscaling, auto-crop) for laser/CNC/maker workflows",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"background-removal",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"cnc",
|
|
13
13
|
"engraving",
|
|
14
14
|
"maker",
|
|
15
|
-
"typescript"
|
|
15
|
+
"typescript",
|
|
16
|
+
"image-generator"
|
|
16
17
|
],
|
|
17
18
|
"license": "MIT",
|
|
18
19
|
"homepage": "https://github.com/RichardMcQuiston01/maker-image-tools#readme",
|
|
@@ -31,7 +32,24 @@
|
|
|
31
32
|
".": {
|
|
32
33
|
"types": "./dist/index.d.ts",
|
|
33
34
|
"default": "./dist/index.js"
|
|
34
|
-
}
|
|
35
|
+
},
|
|
36
|
+
"./background-removal": {
|
|
37
|
+
"types": "./dist/background-removal.d.ts",
|
|
38
|
+
"default": "./dist/background-removal.js"
|
|
39
|
+
},
|
|
40
|
+
"./upscale": {
|
|
41
|
+
"types": "./dist/upscale.d.ts",
|
|
42
|
+
"default": "./dist/upscale.js"
|
|
43
|
+
},
|
|
44
|
+
"./auto-crop": {
|
|
45
|
+
"types": "./dist/auto-crop.d.ts",
|
|
46
|
+
"default": "./dist/auto-crop.js"
|
|
47
|
+
},
|
|
48
|
+
"./provider": {
|
|
49
|
+
"types": "./dist/provider.d.ts",
|
|
50
|
+
"default": "./dist/provider.js"
|
|
51
|
+
},
|
|
52
|
+
"./models/*": "./models/*"
|
|
35
53
|
},
|
|
36
54
|
"files": [
|
|
37
55
|
"dist",
|
|
@@ -48,15 +66,26 @@
|
|
|
48
66
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
49
67
|
},
|
|
50
68
|
"dependencies": {
|
|
51
|
-
"@richardmcquiston01/core-image": "0.
|
|
69
|
+
"@richardmcquiston01/core-image": "0.3.0",
|
|
52
70
|
"@tensorflow/tfjs": "4.11.0",
|
|
53
71
|
"@upscalerjs/esrgan-slim": "1.0.0",
|
|
54
72
|
"onnxruntime-web": "1.27.0",
|
|
55
73
|
"upscaler": "1.0.0"
|
|
56
74
|
},
|
|
57
75
|
"devDependencies": {
|
|
76
|
+
"@richardmcquiston01/ai-providers": "^0.1.0",
|
|
77
|
+
"esbuild": "^0.25.12",
|
|
58
78
|
"jsdom": "^25.0.1",
|
|
59
79
|
"typescript": "^5.7.3",
|
|
60
80
|
"vitest": "^3.0.4"
|
|
61
|
-
}
|
|
81
|
+
},
|
|
82
|
+
"peerDependencies": {
|
|
83
|
+
"@richardmcquiston01/ai-providers": "^0.1.0"
|
|
84
|
+
},
|
|
85
|
+
"peerDependenciesMeta": {
|
|
86
|
+
"@richardmcquiston01/ai-providers": {
|
|
87
|
+
"optional": true
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"sideEffects": false
|
|
62
91
|
}
|