@unngh/google-vision 1.0.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/CHANGELOG.md +10 -0
- package/LICENSE +9 -0
- package/README.md +111 -0
- package/dist/browser.d.ts +106 -0
- package/dist/browser.js +117 -0
- package/dist/browser.js.map +1 -0
- package/dist/google_vision-FY62C7II.js +36811 -0
- package/dist/google_vision-FY62C7II.js.map +1 -0
- package/dist/google_vision-I7LAM27R.js +36811 -0
- package/dist/google_vision-I7LAM27R.js.map +1 -0
- package/dist/google_vision.runtime.js +22421 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/node.cjs +36984 -0
- package/dist/node.cjs.map +1 -0
- package/dist/node.d.cts +107 -0
- package/dist/node.d.ts +107 -0
- package/dist/node.js +127 -0
- package/dist/node.js.map +1 -0
- package/package.json +71 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
* Initial release of the Google Vision JS interop package
|
|
6
|
+
* Dart `dart:js_interop` wrapper for the google_vision core library
|
|
7
|
+
* Supports API key and JWT authentication
|
|
8
|
+
* Image annotation: label detection, face detection, text detection, safe search, and more
|
|
9
|
+
* Compiles to JavaScript via `dart compile js` for Node.js and browser usage
|
|
10
|
+
* Publishable to npm
|
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Faith of Life Network
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Google Vision JS
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
[](https://pub.dev/packages/google_vision_js)
|
|
6
|
+
[](https://www.npmjs.com/package/@unngh/google-vision)
|
|
7
|
+
|
|
8
|
+
JavaScript interop wrapper for the Google Vision API. Enables Vision AI features — image labeling, face detection, OCR, safe search, and more — in Node.js and browser environments.
|
|
9
|
+
|
|
10
|
+
This package wraps the [google_vision](https://pub.dev/packages/google_vision) Dart library using `dart:js_interop` and compiles to JavaScript via `dart compile js`.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- Label Detection
|
|
15
|
+
- Face Detection
|
|
16
|
+
- Text Detection (OCR)
|
|
17
|
+
- Document Text Detection
|
|
18
|
+
- Safe Search Detection
|
|
19
|
+
- Landmark Detection
|
|
20
|
+
- Logo Detection
|
|
21
|
+
- Image Properties
|
|
22
|
+
- Crop Hints
|
|
23
|
+
- Web Detection
|
|
24
|
+
- Object Localization
|
|
25
|
+
- API Key and JWT authentication
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
### npm
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install @unngh/google-vision
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### pub.dev
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
dart pub add google_vision_js
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Prerequisites
|
|
42
|
+
|
|
43
|
+
### 1. Enable the Vision API
|
|
44
|
+
|
|
45
|
+
Go to the [Google Cloud Console](https://console.cloud.google.com/), select or create a project, and enable the [Vision API](https://console.cloud.google.com/apis/library/vision.googleapis.com).
|
|
46
|
+
|
|
47
|
+
### 2. Get an API key
|
|
48
|
+
|
|
49
|
+
1. In the Cloud Console, go to **APIs & Services > Credentials**.
|
|
50
|
+
2. Click **Create Credentials > API Key**.
|
|
51
|
+
3. Copy the generated API key.
|
|
52
|
+
4. (Optional but recommended) Restrict the key to the Vision API to prevent unauthorized usage.
|
|
53
|
+
|
|
54
|
+
> **Tip:** For production use, consider [service account authentication](#authentication) with JWT instead of an API key. Service accounts provide more granular permissions and are the recommended approach for server-side applications.
|
|
55
|
+
|
|
56
|
+
### 3. Set the API key
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
export GOOGLE_VISION_API_KEY="your-api-key-here"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
import { GoogleVisionJs } from '@unngh/google-vision';
|
|
66
|
+
|
|
67
|
+
const vision = new GoogleVisionJs();
|
|
68
|
+
|
|
69
|
+
// Authenticate with API key
|
|
70
|
+
vision.withApiKey(process.env.GOOGLE_VISION_API_KEY);
|
|
71
|
+
|
|
72
|
+
// Detect labels in an image
|
|
73
|
+
const labels = await vision.image.labelDetection({
|
|
74
|
+
imageUri: 'https://example.com/image.jpg'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log(labels);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Authentication
|
|
81
|
+
|
|
82
|
+
### API Key
|
|
83
|
+
|
|
84
|
+
The simplest way to authenticate. Best for quick starts and testing.
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
vision.withApiKey('YOUR_API_KEY');
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### JWT (Service Account)
|
|
91
|
+
|
|
92
|
+
The recommended approach for production. Uses a Google Cloud service account JSON key file.
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
95
|
+
const credentials = fs.readFileSync('./service-account.json', 'utf-8');
|
|
96
|
+
await vision.withJwt(credentials);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Building from source
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Install Dart dependencies
|
|
103
|
+
dart pub get
|
|
104
|
+
|
|
105
|
+
# Compile to JavaScript
|
|
106
|
+
dart run tool/compile_js.dart
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type definitions for the dart2js-compiled google_vision
|
|
3
|
+
* runtime and the public API surface.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Raw handle returned by `GoogleVisionJs.create()`.
|
|
7
|
+
*
|
|
8
|
+
* Each method on this handle is a closure that captures the underlying
|
|
9
|
+
* Dart `GoogleVision` instance. Promise-returning methods use native
|
|
10
|
+
* JS `Promise`, automatically converted from Dart `Future` by dart2js.
|
|
11
|
+
*/
|
|
12
|
+
interface VisionJsHandle {
|
|
13
|
+
/** Synchronous — returns the handle for chaining. */
|
|
14
|
+
withApiKey(apiKey: string): VisionJsHandle;
|
|
15
|
+
/** Asynchronous — resolves with the handle after JWT auth. */
|
|
16
|
+
withJwt(credentialsJson: string, scope?: string): Promise<VisionJsHandle>;
|
|
17
|
+
/** Image source can be a URL string or an object with `imageUri` / `content` (base64). */
|
|
18
|
+
imageLabelDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any>[]>;
|
|
19
|
+
imageTextDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any>[]>;
|
|
20
|
+
imageFaceDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any>[]>;
|
|
21
|
+
imageSafeSearchDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any> | null>;
|
|
22
|
+
imageCropHints(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any> | null>;
|
|
23
|
+
imageDocumentTextDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any> | null>;
|
|
24
|
+
imageProperties(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any> | null>;
|
|
25
|
+
imageLandmarkDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any>[]>;
|
|
26
|
+
imageLogoDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any>[]>;
|
|
27
|
+
imageObjectLocalization(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any>[]>;
|
|
28
|
+
imageWebDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any> | null>;
|
|
29
|
+
fileLabelDetection(gcsUri: string, maxResults?: number): Promise<Record<string, any>[]>;
|
|
30
|
+
fileTextDetection(gcsUri: string, maxResults?: number): Promise<Record<string, any>[]>;
|
|
31
|
+
fileDocumentTextDetection(gcsUri: string, maxResults?: number): Promise<Record<string, any>[]>;
|
|
32
|
+
fileFaceDetection(gcsUri: string, maxResults?: number): Promise<Record<string, any>[]>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Image source: either a URL string or an object with `imageUri` or `content`.
|
|
36
|
+
*/
|
|
37
|
+
interface ImageSource {
|
|
38
|
+
imageUri?: string;
|
|
39
|
+
content?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Loads the dart2js-compiled runtime and returns the `GoogleVisionJs`
|
|
44
|
+
* namespace installed on `globalThis`. Dispatch is platform-specific — see
|
|
45
|
+
* `browser.ts` and `node.ts` for the actual loader implementations.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
type DartRuntimeLoader = () => Promise<void>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* google_vision_js — public TypeScript API.
|
|
52
|
+
*
|
|
53
|
+
* This facade wraps the dart2js-compiled `google_vision` core, exposing an
|
|
54
|
+
* idiomatic JavaScript API: Promise-based methods, `image` and `file`
|
|
55
|
+
* sub-APIs that mirror the Dart API shape.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/** Sub-API for image-based Google Vision operations. */
|
|
59
|
+
declare class GoogleVisionImage {
|
|
60
|
+
private readonly handle;
|
|
61
|
+
constructor(handle: VisionJsHandle);
|
|
62
|
+
labelDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any>[]>;
|
|
63
|
+
textDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any>[]>;
|
|
64
|
+
faceDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any>[]>;
|
|
65
|
+
safeSearchDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any> | null>;
|
|
66
|
+
cropHints(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any> | null>;
|
|
67
|
+
documentTextDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any> | null>;
|
|
68
|
+
imageProperties(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any> | null>;
|
|
69
|
+
landmarkDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any>[]>;
|
|
70
|
+
logoDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any>[]>;
|
|
71
|
+
objectLocalization(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any>[]>;
|
|
72
|
+
webDetection(imageSource: string | ImageSource, maxResults?: number): Promise<Record<string, any> | null>;
|
|
73
|
+
}
|
|
74
|
+
/** Sub-API for file-based Google Vision operations (PDFs, GCS files). */
|
|
75
|
+
declare class GoogleVisionFile {
|
|
76
|
+
private readonly handle;
|
|
77
|
+
constructor(handle: VisionJsHandle);
|
|
78
|
+
labelDetection(gcsUri: string, maxResults?: number): Promise<Record<string, any>[]>;
|
|
79
|
+
textDetection(gcsUri: string, maxResults?: number): Promise<Record<string, any>[]>;
|
|
80
|
+
documentTextDetection(gcsUri: string, maxResults?: number): Promise<Record<string, any>[]>;
|
|
81
|
+
faceDetection(gcsUri: string, maxResults?: number): Promise<Record<string, any>[]>;
|
|
82
|
+
}
|
|
83
|
+
declare class GoogleVision$1 {
|
|
84
|
+
private readonly handle;
|
|
85
|
+
readonly image: GoogleVisionImage;
|
|
86
|
+
readonly file: GoogleVisionFile;
|
|
87
|
+
protected constructor(handle: VisionJsHandle);
|
|
88
|
+
static create(loader?: DartRuntimeLoader): Promise<GoogleVision$1>;
|
|
89
|
+
/** Authenticate using an API key (synchronous, chainable). */
|
|
90
|
+
withApiKey(apiKey: string): this;
|
|
91
|
+
/** Authenticate using JWT credentials (asynchronous, chainable). */
|
|
92
|
+
withJwt(credentialsJson: string, scope?: string): Promise<this>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Browser entrypoint for google_vision_js.
|
|
97
|
+
*
|
|
98
|
+
* Loads the dart2js runtime (which references browser globals already
|
|
99
|
+
* present) and re-exports the public API.
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
declare class GoogleVision extends GoogleVision$1 {
|
|
103
|
+
static create(): Promise<GoogleVision>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { GoogleVision, type ImageSource };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// src/runtime.ts
|
|
2
|
+
var cached;
|
|
3
|
+
async function getRuntime(loader) {
|
|
4
|
+
if (cached) return cached;
|
|
5
|
+
await loader();
|
|
6
|
+
const ns = globalThis.GoogleVisionJs;
|
|
7
|
+
if (!ns) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"google_vision_js runtime failed to initialise: globalThis.GoogleVisionJs was not installed."
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
cached = ns;
|
|
13
|
+
return ns;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/index.ts
|
|
17
|
+
var GoogleVisionImage = class {
|
|
18
|
+
constructor(handle) {
|
|
19
|
+
this.handle = handle;
|
|
20
|
+
}
|
|
21
|
+
handle;
|
|
22
|
+
labelDetection(imageSource, maxResults) {
|
|
23
|
+
return this.handle.imageLabelDetection(imageSource, maxResults);
|
|
24
|
+
}
|
|
25
|
+
textDetection(imageSource, maxResults) {
|
|
26
|
+
return this.handle.imageTextDetection(imageSource, maxResults);
|
|
27
|
+
}
|
|
28
|
+
faceDetection(imageSource, maxResults) {
|
|
29
|
+
return this.handle.imageFaceDetection(imageSource, maxResults);
|
|
30
|
+
}
|
|
31
|
+
safeSearchDetection(imageSource, maxResults) {
|
|
32
|
+
return this.handle.imageSafeSearchDetection(imageSource, maxResults);
|
|
33
|
+
}
|
|
34
|
+
cropHints(imageSource, maxResults) {
|
|
35
|
+
return this.handle.imageCropHints(imageSource, maxResults);
|
|
36
|
+
}
|
|
37
|
+
documentTextDetection(imageSource, maxResults) {
|
|
38
|
+
return this.handle.imageDocumentTextDetection(imageSource, maxResults);
|
|
39
|
+
}
|
|
40
|
+
imageProperties(imageSource, maxResults) {
|
|
41
|
+
return this.handle.imageProperties(imageSource, maxResults);
|
|
42
|
+
}
|
|
43
|
+
landmarkDetection(imageSource, maxResults) {
|
|
44
|
+
return this.handle.imageLandmarkDetection(imageSource, maxResults);
|
|
45
|
+
}
|
|
46
|
+
logoDetection(imageSource, maxResults) {
|
|
47
|
+
return this.handle.imageLogoDetection(imageSource, maxResults);
|
|
48
|
+
}
|
|
49
|
+
objectLocalization(imageSource, maxResults) {
|
|
50
|
+
return this.handle.imageObjectLocalization(imageSource, maxResults);
|
|
51
|
+
}
|
|
52
|
+
webDetection(imageSource, maxResults) {
|
|
53
|
+
return this.handle.imageWebDetection(imageSource, maxResults);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var GoogleVisionFile = class {
|
|
57
|
+
constructor(handle) {
|
|
58
|
+
this.handle = handle;
|
|
59
|
+
}
|
|
60
|
+
handle;
|
|
61
|
+
labelDetection(gcsUri, maxResults) {
|
|
62
|
+
return this.handle.fileLabelDetection(gcsUri, maxResults);
|
|
63
|
+
}
|
|
64
|
+
textDetection(gcsUri, maxResults) {
|
|
65
|
+
return this.handle.fileTextDetection(gcsUri, maxResults);
|
|
66
|
+
}
|
|
67
|
+
documentTextDetection(gcsUri, maxResults) {
|
|
68
|
+
return this.handle.fileDocumentTextDetection(gcsUri, maxResults);
|
|
69
|
+
}
|
|
70
|
+
faceDetection(gcsUri, maxResults) {
|
|
71
|
+
return this.handle.fileFaceDetection(gcsUri, maxResults);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var GoogleVision = class _GoogleVision {
|
|
75
|
+
constructor(handle) {
|
|
76
|
+
this.handle = handle;
|
|
77
|
+
this.image = new GoogleVisionImage(handle);
|
|
78
|
+
this.file = new GoogleVisionFile(handle);
|
|
79
|
+
}
|
|
80
|
+
handle;
|
|
81
|
+
image;
|
|
82
|
+
file;
|
|
83
|
+
static async create(loader) {
|
|
84
|
+
if (!loader) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
"No Dart runtime loader provided. Import from '@unngh/google-vision/node' or '@unngh/google-vision/browser' instead."
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
const ns = await getRuntime(loader);
|
|
90
|
+
const handle = ns.create();
|
|
91
|
+
return new _GoogleVision(handle);
|
|
92
|
+
}
|
|
93
|
+
/** Authenticate using an API key (synchronous, chainable). */
|
|
94
|
+
withApiKey(apiKey) {
|
|
95
|
+
this.handle.withApiKey(apiKey);
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
/** Authenticate using JWT credentials (asynchronous, chainable). */
|
|
99
|
+
async withJwt(credentialsJson, scope) {
|
|
100
|
+
await this.handle.withJwt(credentialsJson, scope);
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/browser.ts
|
|
106
|
+
var loadDart = async () => {
|
|
107
|
+
await import("./google_vision-FY62C7II.js");
|
|
108
|
+
};
|
|
109
|
+
var GoogleVision2 = class extends GoogleVision {
|
|
110
|
+
static async create() {
|
|
111
|
+
return await GoogleVision.create(loadDart);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
export {
|
|
115
|
+
GoogleVision2 as GoogleVision
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime.ts","../src/index.ts","../src/browser.ts"],"sourcesContent":["/**\n * Loads the dart2js-compiled runtime and returns the `GoogleVisionJs`\n * namespace installed on `globalThis`. Dispatch is platform-specific — see\n * `browser.ts` and `node.ts` for the actual loader implementations.\n */\n\nimport type { VisionJsNamespace } from './types.js';\n\nlet cached: VisionJsNamespace | undefined;\n\nexport type DartRuntimeLoader = () => Promise<void>;\n\nexport async function getRuntime(\n loader: DartRuntimeLoader,\n): Promise<VisionJsNamespace> {\n if (cached) return cached;\n await loader();\n const ns = (globalThis as any).GoogleVisionJs as\n | VisionJsNamespace\n | undefined;\n if (!ns) {\n throw new Error(\n 'google_vision_js runtime failed to initialise: ' +\n 'globalThis.GoogleVisionJs was not installed.',\n );\n }\n cached = ns;\n return ns;\n}\n","/**\n * google_vision_js — public TypeScript API.\n *\n * This facade wraps the dart2js-compiled `google_vision` core, exposing an\n * idiomatic JavaScript API: Promise-based methods, `image` and `file`\n * sub-APIs that mirror the Dart API shape.\n */\n\nimport type { DartRuntimeLoader } from './runtime.js';\nimport { getRuntime } from './runtime.js';\nimport type {\n ImageSource,\n VisionJsHandle,\n} from './types.js';\n\nexport type { ImageSource } from './types.js';\n\n/** Sub-API for image-based Google Vision operations. */\nclass GoogleVisionImage {\n constructor(private readonly handle: VisionJsHandle) {}\n\n labelDetection(\n imageSource: string | ImageSource,\n maxResults?: number,\n ): Promise<Record<string, any>[]> {\n return this.handle.imageLabelDetection(imageSource, maxResults);\n }\n\n textDetection(\n imageSource: string | ImageSource,\n maxResults?: number,\n ): Promise<Record<string, any>[]> {\n return this.handle.imageTextDetection(imageSource, maxResults);\n }\n\n faceDetection(\n imageSource: string | ImageSource,\n maxResults?: number,\n ): Promise<Record<string, any>[]> {\n return this.handle.imageFaceDetection(imageSource, maxResults);\n }\n\n safeSearchDetection(\n imageSource: string | ImageSource,\n maxResults?: number,\n ): Promise<Record<string, any> | null> {\n return this.handle.imageSafeSearchDetection(imageSource, maxResults);\n }\n\n cropHints(\n imageSource: string | ImageSource,\n maxResults?: number,\n ): Promise<Record<string, any> | null> {\n return this.handle.imageCropHints(imageSource, maxResults);\n }\n\n documentTextDetection(\n imageSource: string | ImageSource,\n maxResults?: number,\n ): Promise<Record<string, any> | null> {\n return this.handle.imageDocumentTextDetection(imageSource, maxResults);\n }\n\n imageProperties(\n imageSource: string | ImageSource,\n maxResults?: number,\n ): Promise<Record<string, any> | null> {\n return this.handle.imageProperties(imageSource, maxResults);\n }\n\n landmarkDetection(\n imageSource: string | ImageSource,\n maxResults?: number,\n ): Promise<Record<string, any>[]> {\n return this.handle.imageLandmarkDetection(imageSource, maxResults);\n }\n\n logoDetection(\n imageSource: string | ImageSource,\n maxResults?: number,\n ): Promise<Record<string, any>[]> {\n return this.handle.imageLogoDetection(imageSource, maxResults);\n }\n\n objectLocalization(\n imageSource: string | ImageSource,\n maxResults?: number,\n ): Promise<Record<string, any>[]> {\n return this.handle.imageObjectLocalization(imageSource, maxResults);\n }\n\n webDetection(\n imageSource: string | ImageSource,\n maxResults?: number,\n ): Promise<Record<string, any> | null> {\n return this.handle.imageWebDetection(imageSource, maxResults);\n }\n}\n\n/** Sub-API for file-based Google Vision operations (PDFs, GCS files). */\nclass GoogleVisionFile {\n constructor(private readonly handle: VisionJsHandle) {}\n\n labelDetection(\n gcsUri: string,\n maxResults?: number,\n ): Promise<Record<string, any>[]> {\n return this.handle.fileLabelDetection(gcsUri, maxResults);\n }\n\n textDetection(\n gcsUri: string,\n maxResults?: number,\n ): Promise<Record<string, any>[]> {\n return this.handle.fileTextDetection(gcsUri, maxResults);\n }\n\n documentTextDetection(\n gcsUri: string,\n maxResults?: number,\n ): Promise<Record<string, any>[]> {\n return this.handle.fileDocumentTextDetection(gcsUri, maxResults);\n }\n\n faceDetection(\n gcsUri: string,\n maxResults?: number,\n ): Promise<Record<string, any>[]> {\n return this.handle.fileFaceDetection(gcsUri, maxResults);\n }\n}\n\nexport class GoogleVision {\n readonly image: GoogleVisionImage;\n readonly file: GoogleVisionFile;\n\n protected constructor(private readonly handle: VisionJsHandle) {\n this.image = new GoogleVisionImage(handle);\n this.file = new GoogleVisionFile(handle);\n }\n\n static async create(\n loader?: DartRuntimeLoader,\n ): Promise<GoogleVision> {\n if (!loader) {\n throw new Error(\n 'No Dart runtime loader provided. Import from ' +\n \"'@unngh/google-vision/node' or '@unngh/google-vision/browser' instead.\",\n );\n }\n const ns = await getRuntime(loader);\n const handle = ns.create();\n return new GoogleVision(handle);\n }\n\n /** Authenticate using an API key (synchronous, chainable). */\n withApiKey(apiKey: string): this {\n this.handle.withApiKey(apiKey);\n return this;\n }\n\n /** Authenticate using JWT credentials (asynchronous, chainable). */\n async withJwt(\n credentialsJson: string,\n scope?: string,\n ): Promise<this> {\n await this.handle.withJwt(credentialsJson, scope);\n return this;\n }\n}\n","/**\n * Browser entrypoint for google_vision_js.\n *\n * Loads the dart2js runtime (which references browser globals already\n * present) and re-exports the public API.\n */\n\nimport { GoogleVision as Base } from './index.js';\n\nexport * from './index.js';\n\n/**\n * In production builds, `../build/dart/google_vision.js` is emitted by\n * dart2js and bundled alongside the TS output by tsup. The dynamic import\n * lets bundlers (vite/webpack/rollup) split it into a separate chunk.\n */\nconst loadDart = async () => {\n // @ts-expect-error -- resolved at build time; present in dist/.\n await import('../build/dart/google_vision.js');\n};\n\nexport class GoogleVision extends Base {\n static override async create(): Promise<GoogleVision> {\n return (await Base.create(loadDart)) as GoogleVision;\n }\n}\n"],"mappings":"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","names":["GoogleVision"]}
|