@slopmachine/react 0.0.1 → 0.1.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 +51 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -1
- package/dist/index.mjs +9 -2
- package/package.json +3 -3
- package/src/components/SlopImage.tsx +12 -3
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @slopmachine/react
|
|
2
|
+
|
|
3
|
+
The official React SDK for Slop Machine. This package provides React components to easily integrate Slop Machine image generation into your applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @slopmachine/react
|
|
9
|
+
# or
|
|
10
|
+
yarn add @slopmachine/react
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @slopmachine/react
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { SlopImage } from "@slopmachine/react";
|
|
19
|
+
|
|
20
|
+
function App() {
|
|
21
|
+
return (
|
|
22
|
+
<div style={{ width: "400px", height: "400px" }}>
|
|
23
|
+
<SlopImage
|
|
24
|
+
prompt="A cute cat drinking coffee in a {style} style"
|
|
25
|
+
aspectRatio="1:1"
|
|
26
|
+
variables={{ style: "anime" }}
|
|
27
|
+
/>
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default App;
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API / Props
|
|
36
|
+
|
|
37
|
+
### `SlopImage`
|
|
38
|
+
|
|
39
|
+
The `SlopImage` component inherits from standard `React.ImgHTMLAttributes<HTMLImageElement>` (excluding `src` and `alt`) and accepts the following additional props:
|
|
40
|
+
|
|
41
|
+
| Prop | Type | Default | Description |
|
|
42
|
+
| :------------ | :----------------------- | :----------- | :------------------------------------------------------ |
|
|
43
|
+
| `prompt` | `string` | **Required** | The prompt to use for image generation. |
|
|
44
|
+
| `aspectRatio` | `string` | `"1:1"` | The aspect ratio of the image (e.g. `"16:9"`, `"1:1"`). |
|
|
45
|
+
| `variables` | `Record<string, string>` | `{}` | Variables to interpolate into the prompt. |
|
|
46
|
+
| `model` | `string` | `undefined` | The AI model to use for generation. |
|
|
47
|
+
| `baseUrl` | `string` | `undefined` | Custom base URL for the Slop Machine API. |
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { SlopImageOptions } from '@slopmachine/core';
|
|
3
3
|
|
|
4
|
-
interface SlopImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src" | "alt">,
|
|
4
|
+
interface SlopImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src" | "alt">, SlopImageOptions {
|
|
5
5
|
}
|
|
6
6
|
declare const SlopImage: React.FC<SlopImageProps>;
|
|
7
7
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { SlopImageOptions } from '@slopmachine/core';
|
|
3
3
|
|
|
4
|
-
interface SlopImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src" | "alt">,
|
|
4
|
+
interface SlopImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src" | "alt">, SlopImageOptions {
|
|
5
5
|
}
|
|
6
6
|
declare const SlopImage: React.FC<SlopImageProps>;
|
|
7
7
|
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,10 @@ var SlopImage = ({
|
|
|
46
46
|
() => (0, import_core.buildImageUrl)({ prompt, aspectRatio, variables, baseUrl, model }),
|
|
47
47
|
[prompt, aspectRatio, variables, baseUrl, model]
|
|
48
48
|
);
|
|
49
|
+
const alt = (0, import_react.useMemo)(
|
|
50
|
+
() => (0, import_core.interpolatePrompt)(prompt, variables) ?? "Generated image",
|
|
51
|
+
[prompt, variables]
|
|
52
|
+
);
|
|
49
53
|
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
50
54
|
const [currentSrc, setCurrentSrc] = (0, import_react.useState)(src);
|
|
51
55
|
if (src !== currentSrc) {
|
|
@@ -194,7 +198,7 @@ var SlopImage = ({
|
|
|
194
198
|
"img",
|
|
195
199
|
{
|
|
196
200
|
src,
|
|
197
|
-
alt
|
|
201
|
+
alt,
|
|
198
202
|
onLoad: () => setIsLoading(false),
|
|
199
203
|
className: cn(
|
|
200
204
|
"h-full w-full object-cover transition-opacity duration-500",
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import { useMemo, useState } from "react";
|
|
3
3
|
import { clsx } from "clsx";
|
|
4
4
|
import { twMerge } from "tailwind-merge";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
buildImageUrl,
|
|
7
|
+
interpolatePrompt
|
|
8
|
+
} from "@slopmachine/core";
|
|
6
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
10
|
function cn(...inputs) {
|
|
8
11
|
return twMerge(clsx(inputs));
|
|
@@ -20,6 +23,10 @@ var SlopImage = ({
|
|
|
20
23
|
() => buildImageUrl({ prompt, aspectRatio, variables, baseUrl, model }),
|
|
21
24
|
[prompt, aspectRatio, variables, baseUrl, model]
|
|
22
25
|
);
|
|
26
|
+
const alt = useMemo(
|
|
27
|
+
() => interpolatePrompt(prompt, variables) ?? "Generated image",
|
|
28
|
+
[prompt, variables]
|
|
29
|
+
);
|
|
23
30
|
const [isLoading, setIsLoading] = useState(true);
|
|
24
31
|
const [currentSrc, setCurrentSrc] = useState(src);
|
|
25
32
|
if (src !== currentSrc) {
|
|
@@ -168,7 +175,7 @@ var SlopImage = ({
|
|
|
168
175
|
"img",
|
|
169
176
|
{
|
|
170
177
|
src,
|
|
171
|
-
alt
|
|
178
|
+
alt,
|
|
172
179
|
onLoad: () => setIsLoading(false),
|
|
173
180
|
className: cn(
|
|
174
181
|
"h-full w-full object-cover transition-opacity duration-500",
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slopmachine/react",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "The official React SDK for Slop Machine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
10
11
|
"import": "./dist/index.mjs",
|
|
11
|
-
"require": "./dist/index.js"
|
|
12
|
-
"types": "./dist/index.d.ts"
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
@@ -2,7 +2,11 @@ import React, { useMemo, useState } from "react";
|
|
|
2
2
|
import { clsx, type ClassValue } from "clsx";
|
|
3
3
|
import { twMerge } from "tailwind-merge";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
buildImageUrl,
|
|
7
|
+
interpolatePrompt,
|
|
8
|
+
type SlopImageOptions,
|
|
9
|
+
} from "@slopmachine/core";
|
|
6
10
|
|
|
7
11
|
// Utility for Tailwind classes
|
|
8
12
|
function cn(...inputs: ClassValue[]) {
|
|
@@ -12,7 +16,7 @@ function cn(...inputs: ClassValue[]) {
|
|
|
12
16
|
interface SlopImageProps
|
|
13
17
|
extends
|
|
14
18
|
Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src" | "alt">,
|
|
15
|
-
|
|
19
|
+
SlopImageOptions {}
|
|
16
20
|
|
|
17
21
|
export const SlopImage: React.FC<SlopImageProps> = ({
|
|
18
22
|
prompt,
|
|
@@ -29,6 +33,11 @@ export const SlopImage: React.FC<SlopImageProps> = ({
|
|
|
29
33
|
[prompt, aspectRatio, variables, baseUrl, model],
|
|
30
34
|
);
|
|
31
35
|
|
|
36
|
+
const alt = useMemo(
|
|
37
|
+
() => interpolatePrompt(prompt, variables) ?? "Generated image",
|
|
38
|
+
[prompt, variables],
|
|
39
|
+
);
|
|
40
|
+
|
|
32
41
|
const [isLoading, setIsLoading] = useState(true);
|
|
33
42
|
const [currentSrc, setCurrentSrc] = useState(src);
|
|
34
43
|
|
|
@@ -157,7 +166,7 @@ export const SlopImage: React.FC<SlopImageProps> = ({
|
|
|
157
166
|
<img
|
|
158
167
|
key={src}
|
|
159
168
|
src={src}
|
|
160
|
-
alt={
|
|
169
|
+
alt={alt}
|
|
161
170
|
onLoad={() => setIsLoading(false)}
|
|
162
171
|
className={cn(
|
|
163
172
|
"h-full w-full object-cover transition-opacity duration-500",
|