@slopmachine/react 0.0.1
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/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +222 -0
- package/dist/index.mjs +195 -0
- package/package.json +57 -0
- package/src/components/SlopImage.tsx +178 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +28 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsup.config.ts +9 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SlopMachineOptions } from '@slopmachine/core';
|
|
3
|
+
|
|
4
|
+
interface SlopImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src" | "alt">, SlopMachineOptions {
|
|
5
|
+
}
|
|
6
|
+
declare const SlopImage: React.FC<SlopImageProps>;
|
|
7
|
+
|
|
8
|
+
export { SlopImage };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SlopMachineOptions } from '@slopmachine/core';
|
|
3
|
+
|
|
4
|
+
interface SlopImageProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src" | "alt">, SlopMachineOptions {
|
|
5
|
+
}
|
|
6
|
+
declare const SlopImage: React.FC<SlopImageProps>;
|
|
7
|
+
|
|
8
|
+
export { SlopImage };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
SlopImage: () => SlopImage
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/components/SlopImage.tsx
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_clsx = require("clsx");
|
|
30
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
31
|
+
var import_core = require("@slopmachine/core");
|
|
32
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
+
function cn(...inputs) {
|
|
34
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
35
|
+
}
|
|
36
|
+
var SlopImage = ({
|
|
37
|
+
prompt,
|
|
38
|
+
className,
|
|
39
|
+
aspectRatio = "1:1",
|
|
40
|
+
model,
|
|
41
|
+
variables = {},
|
|
42
|
+
baseUrl,
|
|
43
|
+
...props
|
|
44
|
+
}) => {
|
|
45
|
+
const src = (0, import_react.useMemo)(
|
|
46
|
+
() => (0, import_core.buildImageUrl)({ prompt, aspectRatio, variables, baseUrl, model }),
|
|
47
|
+
[prompt, aspectRatio, variables, baseUrl, model]
|
|
48
|
+
);
|
|
49
|
+
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
50
|
+
const [currentSrc, setCurrentSrc] = (0, import_react.useState)(src);
|
|
51
|
+
if (src !== currentSrc) {
|
|
52
|
+
setCurrentSrc(src);
|
|
53
|
+
setIsLoading(true);
|
|
54
|
+
}
|
|
55
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
56
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: `
|
|
57
|
+
@keyframes slop-shimmer {
|
|
58
|
+
0% {
|
|
59
|
+
background-position: 200% 0;
|
|
60
|
+
}
|
|
61
|
+
100% {
|
|
62
|
+
background-position: -200% 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
@keyframes slop-spin {
|
|
66
|
+
from {
|
|
67
|
+
transform: rotate(0deg);
|
|
68
|
+
}
|
|
69
|
+
to {
|
|
70
|
+
transform: rotate(360deg);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
` }),
|
|
74
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
75
|
+
"div",
|
|
76
|
+
{
|
|
77
|
+
className: cn("relative overflow-hidden", className),
|
|
78
|
+
style: {
|
|
79
|
+
aspectRatio: String(aspectRatio).replace(":", "/"),
|
|
80
|
+
backgroundColor: "var(--muted, #f3f4f6)",
|
|
81
|
+
position: "relative",
|
|
82
|
+
overflow: "hidden"
|
|
83
|
+
},
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
86
|
+
"div",
|
|
87
|
+
{
|
|
88
|
+
className: cn(
|
|
89
|
+
"absolute inset-0 z-10 flex items-center justify-center bg-muted transition-opacity duration-300",
|
|
90
|
+
isLoading ? "opacity-100" : "opacity-0 pointer-events-none"
|
|
91
|
+
),
|
|
92
|
+
style: {
|
|
93
|
+
position: "absolute",
|
|
94
|
+
top: 0,
|
|
95
|
+
left: 0,
|
|
96
|
+
right: 0,
|
|
97
|
+
bottom: 0,
|
|
98
|
+
zIndex: 10,
|
|
99
|
+
display: "flex",
|
|
100
|
+
alignItems: "center",
|
|
101
|
+
justifyContent: "center",
|
|
102
|
+
backgroundColor: "var(--muted, #f3f4f6)",
|
|
103
|
+
opacity: isLoading ? 1 : 0,
|
|
104
|
+
pointerEvents: isLoading ? "auto" : "none",
|
|
105
|
+
transition: "opacity 300ms ease-in-out"
|
|
106
|
+
},
|
|
107
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
108
|
+
"div",
|
|
109
|
+
{
|
|
110
|
+
className: "flex flex-col items-center gap-2",
|
|
111
|
+
style: {
|
|
112
|
+
display: "flex",
|
|
113
|
+
flexDirection: "column",
|
|
114
|
+
alignItems: "center",
|
|
115
|
+
gap: "0.5rem"
|
|
116
|
+
},
|
|
117
|
+
children: [
|
|
118
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
119
|
+
"svg",
|
|
120
|
+
{
|
|
121
|
+
className: "spinner size-6 text-muted-foreground",
|
|
122
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
123
|
+
fill: "none",
|
|
124
|
+
viewBox: "0 0 24 24",
|
|
125
|
+
style: {
|
|
126
|
+
width: "24px",
|
|
127
|
+
height: "24px",
|
|
128
|
+
color: "var(--muted-foreground, #6b7280)",
|
|
129
|
+
animation: "slop-spin 1s linear infinite"
|
|
130
|
+
},
|
|
131
|
+
children: [
|
|
132
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
133
|
+
"circle",
|
|
134
|
+
{
|
|
135
|
+
className: "opacity-25",
|
|
136
|
+
cx: "12",
|
|
137
|
+
cy: "12",
|
|
138
|
+
r: "10",
|
|
139
|
+
stroke: "currentColor",
|
|
140
|
+
strokeWidth: "4",
|
|
141
|
+
style: { opacity: 0.25 }
|
|
142
|
+
}
|
|
143
|
+
),
|
|
144
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
145
|
+
"path",
|
|
146
|
+
{
|
|
147
|
+
className: "opacity-75",
|
|
148
|
+
fill: "currentColor",
|
|
149
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z",
|
|
150
|
+
style: { opacity: 0.75 }
|
|
151
|
+
}
|
|
152
|
+
)
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
),
|
|
156
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
157
|
+
"span",
|
|
158
|
+
{
|
|
159
|
+
className: "text-xs text-muted-foreground",
|
|
160
|
+
style: {
|
|
161
|
+
fontSize: "0.75rem",
|
|
162
|
+
color: "var(--muted-foreground, #6b7280)"
|
|
163
|
+
},
|
|
164
|
+
children: "Loading..."
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
),
|
|
172
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
173
|
+
"div",
|
|
174
|
+
{
|
|
175
|
+
className: cn(
|
|
176
|
+
"shimmer-effect absolute inset-0 bg-gradient-to-r from-muted via-muted/50 to-muted",
|
|
177
|
+
isLoading ? "opacity-100" : "opacity-0"
|
|
178
|
+
),
|
|
179
|
+
style: {
|
|
180
|
+
position: "absolute",
|
|
181
|
+
top: 0,
|
|
182
|
+
left: 0,
|
|
183
|
+
right: 0,
|
|
184
|
+
bottom: 0,
|
|
185
|
+
background: "linear-gradient(90deg, var(--muted, #f3f4f6) 0%, var(--muted-foreground, #e5e7eb) 50%, var(--muted, #f3f4f6) 100%)",
|
|
186
|
+
backgroundSize: "200% 100%",
|
|
187
|
+
animation: "slop-shimmer 2s ease-in-out infinite",
|
|
188
|
+
opacity: isLoading ? 1 : 0,
|
|
189
|
+
transition: "opacity 300ms"
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
),
|
|
193
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
194
|
+
"img",
|
|
195
|
+
{
|
|
196
|
+
src,
|
|
197
|
+
alt: prompt,
|
|
198
|
+
onLoad: () => setIsLoading(false),
|
|
199
|
+
className: cn(
|
|
200
|
+
"h-full w-full object-cover transition-opacity duration-500",
|
|
201
|
+
isLoading ? "opacity-0" : "opacity-100"
|
|
202
|
+
),
|
|
203
|
+
style: {
|
|
204
|
+
height: "100%",
|
|
205
|
+
width: "100%",
|
|
206
|
+
objectFit: "cover",
|
|
207
|
+
transition: "opacity 500ms",
|
|
208
|
+
opacity: isLoading ? 0 : 1
|
|
209
|
+
},
|
|
210
|
+
...props
|
|
211
|
+
},
|
|
212
|
+
src
|
|
213
|
+
)
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
)
|
|
217
|
+
] });
|
|
218
|
+
};
|
|
219
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
220
|
+
0 && (module.exports = {
|
|
221
|
+
SlopImage
|
|
222
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// src/components/SlopImage.tsx
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
import { clsx } from "clsx";
|
|
4
|
+
import { twMerge } from "tailwind-merge";
|
|
5
|
+
import { buildImageUrl } from "@slopmachine/core";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
function cn(...inputs) {
|
|
8
|
+
return twMerge(clsx(inputs));
|
|
9
|
+
}
|
|
10
|
+
var SlopImage = ({
|
|
11
|
+
prompt,
|
|
12
|
+
className,
|
|
13
|
+
aspectRatio = "1:1",
|
|
14
|
+
model,
|
|
15
|
+
variables = {},
|
|
16
|
+
baseUrl,
|
|
17
|
+
...props
|
|
18
|
+
}) => {
|
|
19
|
+
const src = useMemo(
|
|
20
|
+
() => buildImageUrl({ prompt, aspectRatio, variables, baseUrl, model }),
|
|
21
|
+
[prompt, aspectRatio, variables, baseUrl, model]
|
|
22
|
+
);
|
|
23
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
24
|
+
const [currentSrc, setCurrentSrc] = useState(src);
|
|
25
|
+
if (src !== currentSrc) {
|
|
26
|
+
setCurrentSrc(src);
|
|
27
|
+
setIsLoading(true);
|
|
28
|
+
}
|
|
29
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
30
|
+
/* @__PURE__ */ jsx("style", { children: `
|
|
31
|
+
@keyframes slop-shimmer {
|
|
32
|
+
0% {
|
|
33
|
+
background-position: 200% 0;
|
|
34
|
+
}
|
|
35
|
+
100% {
|
|
36
|
+
background-position: -200% 0;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
@keyframes slop-spin {
|
|
40
|
+
from {
|
|
41
|
+
transform: rotate(0deg);
|
|
42
|
+
}
|
|
43
|
+
to {
|
|
44
|
+
transform: rotate(360deg);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
` }),
|
|
48
|
+
/* @__PURE__ */ jsxs(
|
|
49
|
+
"div",
|
|
50
|
+
{
|
|
51
|
+
className: cn("relative overflow-hidden", className),
|
|
52
|
+
style: {
|
|
53
|
+
aspectRatio: String(aspectRatio).replace(":", "/"),
|
|
54
|
+
backgroundColor: "var(--muted, #f3f4f6)",
|
|
55
|
+
position: "relative",
|
|
56
|
+
overflow: "hidden"
|
|
57
|
+
},
|
|
58
|
+
children: [
|
|
59
|
+
/* @__PURE__ */ jsx(
|
|
60
|
+
"div",
|
|
61
|
+
{
|
|
62
|
+
className: cn(
|
|
63
|
+
"absolute inset-0 z-10 flex items-center justify-center bg-muted transition-opacity duration-300",
|
|
64
|
+
isLoading ? "opacity-100" : "opacity-0 pointer-events-none"
|
|
65
|
+
),
|
|
66
|
+
style: {
|
|
67
|
+
position: "absolute",
|
|
68
|
+
top: 0,
|
|
69
|
+
left: 0,
|
|
70
|
+
right: 0,
|
|
71
|
+
bottom: 0,
|
|
72
|
+
zIndex: 10,
|
|
73
|
+
display: "flex",
|
|
74
|
+
alignItems: "center",
|
|
75
|
+
justifyContent: "center",
|
|
76
|
+
backgroundColor: "var(--muted, #f3f4f6)",
|
|
77
|
+
opacity: isLoading ? 1 : 0,
|
|
78
|
+
pointerEvents: isLoading ? "auto" : "none",
|
|
79
|
+
transition: "opacity 300ms ease-in-out"
|
|
80
|
+
},
|
|
81
|
+
children: /* @__PURE__ */ jsxs(
|
|
82
|
+
"div",
|
|
83
|
+
{
|
|
84
|
+
className: "flex flex-col items-center gap-2",
|
|
85
|
+
style: {
|
|
86
|
+
display: "flex",
|
|
87
|
+
flexDirection: "column",
|
|
88
|
+
alignItems: "center",
|
|
89
|
+
gap: "0.5rem"
|
|
90
|
+
},
|
|
91
|
+
children: [
|
|
92
|
+
/* @__PURE__ */ jsxs(
|
|
93
|
+
"svg",
|
|
94
|
+
{
|
|
95
|
+
className: "spinner size-6 text-muted-foreground",
|
|
96
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
97
|
+
fill: "none",
|
|
98
|
+
viewBox: "0 0 24 24",
|
|
99
|
+
style: {
|
|
100
|
+
width: "24px",
|
|
101
|
+
height: "24px",
|
|
102
|
+
color: "var(--muted-foreground, #6b7280)",
|
|
103
|
+
animation: "slop-spin 1s linear infinite"
|
|
104
|
+
},
|
|
105
|
+
children: [
|
|
106
|
+
/* @__PURE__ */ jsx(
|
|
107
|
+
"circle",
|
|
108
|
+
{
|
|
109
|
+
className: "opacity-25",
|
|
110
|
+
cx: "12",
|
|
111
|
+
cy: "12",
|
|
112
|
+
r: "10",
|
|
113
|
+
stroke: "currentColor",
|
|
114
|
+
strokeWidth: "4",
|
|
115
|
+
style: { opacity: 0.25 }
|
|
116
|
+
}
|
|
117
|
+
),
|
|
118
|
+
/* @__PURE__ */ jsx(
|
|
119
|
+
"path",
|
|
120
|
+
{
|
|
121
|
+
className: "opacity-75",
|
|
122
|
+
fill: "currentColor",
|
|
123
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z",
|
|
124
|
+
style: { opacity: 0.75 }
|
|
125
|
+
}
|
|
126
|
+
)
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
),
|
|
130
|
+
/* @__PURE__ */ jsx(
|
|
131
|
+
"span",
|
|
132
|
+
{
|
|
133
|
+
className: "text-xs text-muted-foreground",
|
|
134
|
+
style: {
|
|
135
|
+
fontSize: "0.75rem",
|
|
136
|
+
color: "var(--muted-foreground, #6b7280)"
|
|
137
|
+
},
|
|
138
|
+
children: "Loading..."
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
),
|
|
146
|
+
/* @__PURE__ */ jsx(
|
|
147
|
+
"div",
|
|
148
|
+
{
|
|
149
|
+
className: cn(
|
|
150
|
+
"shimmer-effect absolute inset-0 bg-gradient-to-r from-muted via-muted/50 to-muted",
|
|
151
|
+
isLoading ? "opacity-100" : "opacity-0"
|
|
152
|
+
),
|
|
153
|
+
style: {
|
|
154
|
+
position: "absolute",
|
|
155
|
+
top: 0,
|
|
156
|
+
left: 0,
|
|
157
|
+
right: 0,
|
|
158
|
+
bottom: 0,
|
|
159
|
+
background: "linear-gradient(90deg, var(--muted, #f3f4f6) 0%, var(--muted-foreground, #e5e7eb) 50%, var(--muted, #f3f4f6) 100%)",
|
|
160
|
+
backgroundSize: "200% 100%",
|
|
161
|
+
animation: "slop-shimmer 2s ease-in-out infinite",
|
|
162
|
+
opacity: isLoading ? 1 : 0,
|
|
163
|
+
transition: "opacity 300ms"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
),
|
|
167
|
+
/* @__PURE__ */ jsx(
|
|
168
|
+
"img",
|
|
169
|
+
{
|
|
170
|
+
src,
|
|
171
|
+
alt: prompt,
|
|
172
|
+
onLoad: () => setIsLoading(false),
|
|
173
|
+
className: cn(
|
|
174
|
+
"h-full w-full object-cover transition-opacity duration-500",
|
|
175
|
+
isLoading ? "opacity-0" : "opacity-100"
|
|
176
|
+
),
|
|
177
|
+
style: {
|
|
178
|
+
height: "100%",
|
|
179
|
+
width: "100%",
|
|
180
|
+
objectFit: "cover",
|
|
181
|
+
transition: "opacity 500ms",
|
|
182
|
+
opacity: isLoading ? 0 : 1
|
|
183
|
+
},
|
|
184
|
+
...props
|
|
185
|
+
},
|
|
186
|
+
src
|
|
187
|
+
)
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
)
|
|
191
|
+
] });
|
|
192
|
+
};
|
|
193
|
+
export {
|
|
194
|
+
SlopImage
|
|
195
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@slopmachine/react",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "The official React SDK for Slop Machine",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsup",
|
|
17
|
+
"dev": "tsup --watch"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/surrealroad/slopmachine-sdk.git"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"react",
|
|
25
|
+
"ai",
|
|
26
|
+
"slop"
|
|
27
|
+
],
|
|
28
|
+
"author": "Slop Machine",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/react": "^19.2.10",
|
|
32
|
+
"@types/react-dom": "^19.2.3",
|
|
33
|
+
"@vitejs/plugin-react": "^5.1.2",
|
|
34
|
+
"autoprefixer": "^10.4.23",
|
|
35
|
+
"postcss": "^8.5.6",
|
|
36
|
+
"react": "^19.2.4",
|
|
37
|
+
"react-dom": "^19.2.4",
|
|
38
|
+
"tailwindcss": "^4.1.18",
|
|
39
|
+
"tsup": "^8.5.1",
|
|
40
|
+
"typescript": "^5.9.3",
|
|
41
|
+
"vite": "^7.3.1"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@slopmachine/core": "*",
|
|
45
|
+
"@radix-ui/react-label": "^2.1.8",
|
|
46
|
+
"@radix-ui/react-select": "^2.2.6",
|
|
47
|
+
"@radix-ui/react-slot": "^1.2.4",
|
|
48
|
+
"@tailwindcss/postcss": "^4.1.18",
|
|
49
|
+
"@tailwindcss/vite": "^4.1.18",
|
|
50
|
+
"class-variance-authority": "^0.7.1",
|
|
51
|
+
"clsx": "^2.1.1",
|
|
52
|
+
"lucide-react": "^0.563.0",
|
|
53
|
+
"shiki": "^3.21.0",
|
|
54
|
+
"tailwind-merge": "^3.4.0",
|
|
55
|
+
"tailwindcss-animate": "^1.0.7"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import React, { useMemo, useState } from "react";
|
|
2
|
+
import { clsx, type ClassValue } from "clsx";
|
|
3
|
+
import { twMerge } from "tailwind-merge";
|
|
4
|
+
|
|
5
|
+
import { buildImageUrl, type SlopMachineOptions } from "@slopmachine/core";
|
|
6
|
+
|
|
7
|
+
// Utility for Tailwind classes
|
|
8
|
+
function cn(...inputs: ClassValue[]) {
|
|
9
|
+
return twMerge(clsx(inputs));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface SlopImageProps
|
|
13
|
+
extends
|
|
14
|
+
Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src" | "alt">,
|
|
15
|
+
SlopMachineOptions {}
|
|
16
|
+
|
|
17
|
+
export const SlopImage: React.FC<SlopImageProps> = ({
|
|
18
|
+
prompt,
|
|
19
|
+
className,
|
|
20
|
+
aspectRatio = "1:1",
|
|
21
|
+
model,
|
|
22
|
+
variables = {},
|
|
23
|
+
baseUrl,
|
|
24
|
+
...props
|
|
25
|
+
}) => {
|
|
26
|
+
// Construct API URL
|
|
27
|
+
const src = useMemo(
|
|
28
|
+
() => buildImageUrl({ prompt, aspectRatio, variables, baseUrl, model }),
|
|
29
|
+
[prompt, aspectRatio, variables, baseUrl, model],
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
33
|
+
const [currentSrc, setCurrentSrc] = useState(src);
|
|
34
|
+
|
|
35
|
+
if (src !== currentSrc) {
|
|
36
|
+
setCurrentSrc(src);
|
|
37
|
+
setIsLoading(true);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
<style>{`
|
|
43
|
+
@keyframes slop-shimmer {
|
|
44
|
+
0% {
|
|
45
|
+
background-position: 200% 0;
|
|
46
|
+
}
|
|
47
|
+
100% {
|
|
48
|
+
background-position: -200% 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
@keyframes slop-spin {
|
|
52
|
+
from {
|
|
53
|
+
transform: rotate(0deg);
|
|
54
|
+
}
|
|
55
|
+
to {
|
|
56
|
+
transform: rotate(360deg);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
`}</style>
|
|
60
|
+
<div
|
|
61
|
+
className={cn("relative overflow-hidden", className)}
|
|
62
|
+
style={{
|
|
63
|
+
aspectRatio: String(aspectRatio).replace(":", "/"),
|
|
64
|
+
backgroundColor: "var(--muted, #f3f4f6)",
|
|
65
|
+
position: "relative",
|
|
66
|
+
overflow: "hidden",
|
|
67
|
+
}}>
|
|
68
|
+
{/* Loading overlay */}
|
|
69
|
+
<div
|
|
70
|
+
className={cn(
|
|
71
|
+
"absolute inset-0 z-10 flex items-center justify-center bg-muted transition-opacity duration-300",
|
|
72
|
+
isLoading ? "opacity-100" : "opacity-0 pointer-events-none",
|
|
73
|
+
)}
|
|
74
|
+
style={{
|
|
75
|
+
position: "absolute",
|
|
76
|
+
top: 0,
|
|
77
|
+
left: 0,
|
|
78
|
+
right: 0,
|
|
79
|
+
bottom: 0,
|
|
80
|
+
zIndex: 10,
|
|
81
|
+
display: "flex",
|
|
82
|
+
alignItems: "center",
|
|
83
|
+
justifyContent: "center",
|
|
84
|
+
backgroundColor: "var(--muted, #f3f4f6)",
|
|
85
|
+
opacity: isLoading ? 1 : 0,
|
|
86
|
+
pointerEvents: isLoading ? "auto" : "none",
|
|
87
|
+
transition: "opacity 300ms ease-in-out",
|
|
88
|
+
}}>
|
|
89
|
+
<div
|
|
90
|
+
className="flex flex-col items-center gap-2"
|
|
91
|
+
style={{
|
|
92
|
+
display: "flex",
|
|
93
|
+
flexDirection: "column",
|
|
94
|
+
alignItems: "center",
|
|
95
|
+
gap: "0.5rem",
|
|
96
|
+
}}>
|
|
97
|
+
<svg
|
|
98
|
+
className="spinner size-6 text-muted-foreground"
|
|
99
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
100
|
+
fill="none"
|
|
101
|
+
viewBox="0 0 24 24"
|
|
102
|
+
style={{
|
|
103
|
+
width: "24px",
|
|
104
|
+
height: "24px",
|
|
105
|
+
color: "var(--muted-foreground, #6b7280)",
|
|
106
|
+
animation: "slop-spin 1s linear infinite",
|
|
107
|
+
}}>
|
|
108
|
+
<circle
|
|
109
|
+
className="opacity-25"
|
|
110
|
+
cx="12"
|
|
111
|
+
cy="12"
|
|
112
|
+
r="10"
|
|
113
|
+
stroke="currentColor"
|
|
114
|
+
strokeWidth="4"
|
|
115
|
+
style={{ opacity: 0.25 }}
|
|
116
|
+
/>
|
|
117
|
+
<path
|
|
118
|
+
className="opacity-75"
|
|
119
|
+
fill="currentColor"
|
|
120
|
+
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
121
|
+
style={{ opacity: 0.75 }}
|
|
122
|
+
/>
|
|
123
|
+
</svg>
|
|
124
|
+
<span
|
|
125
|
+
className="text-xs text-muted-foreground"
|
|
126
|
+
style={{
|
|
127
|
+
fontSize: "0.75rem",
|
|
128
|
+
color: "var(--muted-foreground, #6b7280)",
|
|
129
|
+
}}>
|
|
130
|
+
Loading...
|
|
131
|
+
</span>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
{/* Shimmer effect underneath */}
|
|
136
|
+
<div
|
|
137
|
+
className={cn(
|
|
138
|
+
"shimmer-effect absolute inset-0 bg-gradient-to-r from-muted via-muted/50 to-muted",
|
|
139
|
+
isLoading ? "opacity-100" : "opacity-0",
|
|
140
|
+
)}
|
|
141
|
+
style={{
|
|
142
|
+
position: "absolute",
|
|
143
|
+
top: 0,
|
|
144
|
+
left: 0,
|
|
145
|
+
right: 0,
|
|
146
|
+
bottom: 0,
|
|
147
|
+
background:
|
|
148
|
+
"linear-gradient(90deg, var(--muted, #f3f4f6) 0%, var(--muted-foreground, #e5e7eb) 50%, var(--muted, #f3f4f6) 100%)",
|
|
149
|
+
backgroundSize: "200% 100%",
|
|
150
|
+
animation: "slop-shimmer 2s ease-in-out infinite",
|
|
151
|
+
opacity: isLoading ? 1 : 0,
|
|
152
|
+
transition: "opacity 300ms",
|
|
153
|
+
}}
|
|
154
|
+
/>
|
|
155
|
+
|
|
156
|
+
{/* Image */}
|
|
157
|
+
<img
|
|
158
|
+
key={src}
|
|
159
|
+
src={src}
|
|
160
|
+
alt={prompt}
|
|
161
|
+
onLoad={() => setIsLoading(false)}
|
|
162
|
+
className={cn(
|
|
163
|
+
"h-full w-full object-cover transition-opacity duration-500",
|
|
164
|
+
isLoading ? "opacity-0" : "opacity-100",
|
|
165
|
+
)}
|
|
166
|
+
style={{
|
|
167
|
+
height: "100%",
|
|
168
|
+
width: "100%",
|
|
169
|
+
objectFit: "cover",
|
|
170
|
+
transition: "opacity 500ms",
|
|
171
|
+
opacity: isLoading ? 0 : 1,
|
|
172
|
+
}}
|
|
173
|
+
{...props}
|
|
174
|
+
/>
|
|
175
|
+
</div>
|
|
176
|
+
</>
|
|
177
|
+
);
|
|
178
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SlopImage } from './components/SlopImage';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* Bundler mode */
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"jsx": "react-jsx",
|
|
16
|
+
|
|
17
|
+
/* Linting */
|
|
18
|
+
"strict": true,
|
|
19
|
+
"noUnusedLocals": true,
|
|
20
|
+
"noUnusedParameters": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
|
|
23
|
+
"declaration": true,
|
|
24
|
+
"baseUrl": "."
|
|
25
|
+
},
|
|
26
|
+
"include": ["src"],
|
|
27
|
+
"exclude": ["node_modules", "dist"]
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/index.ts","./src/components/slopimage.tsx"],"version":"5.9.3"}
|