wc-img-ai 0.0.2 → 0.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 +43 -6
- package/dist/wc-img-ai.js +3 -0
- package/package.json +6 -1
- package/types/ai-image.d.ts +16 -1
package/README.md
CHANGED
|
@@ -3,15 +3,52 @@
|
|
|
3
3
|
By simply providing an src to an api that does the AI for you, and you can simply get ai-rendered images anywhere you need based on the alt-attribute.
|
|
4
4
|
|
|
5
5
|
```html
|
|
6
|
-
<script
|
|
7
|
-
type="module"
|
|
8
|
-
src="/src/ai-image.ts"
|
|
9
|
-
></script>
|
|
10
|
-
|
|
11
6
|
<img
|
|
12
7
|
is="ai-image"
|
|
13
|
-
src="/api/
|
|
8
|
+
src="/api/myimage"
|
|
14
9
|
alt="a sleeping little kitten"
|
|
15
10
|
data-fallback="https://placekitten.com/12/12"
|
|
16
11
|
/>
|
|
17
12
|
```
|
|
13
|
+
|
|
14
|
+
## installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pnpm i wc-img-ai
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```html
|
|
21
|
+
<script type="module">
|
|
22
|
+
import "wc-img-ai"
|
|
23
|
+
</script>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The api server itself needs to receive this body and return a string with the url of the image
|
|
27
|
+
|
|
28
|
+
### Function: POST
|
|
29
|
+
|
|
30
|
+
This function sends a request to the an API to generate an image based on a given prompt.
|
|
31
|
+
|
|
32
|
+
#### Request Body Format
|
|
33
|
+
|
|
34
|
+
- **prompt** (string): The description or prompt based on which the image will be generated.
|
|
35
|
+
- **width** (number): The width of the desired image in pixels.
|
|
36
|
+
- **height** (number): The height of the desired image in pixels.
|
|
37
|
+
|
|
38
|
+
#### Example Request Body
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"prompt": "a sleeping little kitten",
|
|
43
|
+
"width": 300,
|
|
44
|
+
"height": 300
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
#### Return
|
|
49
|
+
|
|
50
|
+
it is expected to return a simple string
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
"https://example.com/path/to/generated/image.jpg"
|
|
54
|
+
```
|
package/dist/wc-img-ai.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wc-img-ai",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"description": "Use AI to generate images for your img tags.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "John Romani",
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
"dist",
|
|
22
22
|
"types"
|
|
23
23
|
],
|
|
24
|
+
"main": "./dist/wc-img-ai.js",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./dist/wc-img-ai.js",
|
|
27
|
+
"./wc-img-ai.d.ts": "./types/wc-img-ai.d.ts"
|
|
28
|
+
},
|
|
24
29
|
"devDependencies": {
|
|
25
30
|
"@typescript-eslint/eslint-plugin": "^6.17.0",
|
|
26
31
|
"@typescript-eslint/parser": "^6.17.0",
|
package/types/ai-image.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
export declare class AIImage extends HTMLImageElement {
|
|
2
|
+
static get observedAttributes(): string[];
|
|
3
|
+
private _fallbackSrc;
|
|
4
|
+
private _prompt;
|
|
5
|
+
private _originalSrc;
|
|
6
|
+
private svgPlaceholder;
|
|
7
|
+
private _endpoint;
|
|
8
|
+
private ph_w;
|
|
9
|
+
private ph_h;
|
|
10
|
+
constructor();
|
|
11
|
+
get src(): string;
|
|
12
|
+
set src(value: string);
|
|
13
|
+
set fallbackSrc(value: string | null);
|
|
14
|
+
attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
|
|
15
|
+
protected getGeneratedImage: (endpoint: string, prompt: string, width: number, height: number) => Promise<string | undefined>;
|
|
16
|
+
}
|
|
1
17
|
declare global {
|
|
2
18
|
interface AIImage extends HTMLImageElement {
|
|
3
19
|
"data-fallback"?: string;
|
|
@@ -6,4 +22,3 @@ declare global {
|
|
|
6
22
|
"ai-image": AIImage;
|
|
7
23
|
}
|
|
8
24
|
}
|
|
9
|
-
export {};
|