@slopmachine/core 0.1.15 → 0.1.20
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 +43 -16
- package/dist/index.d.ts +43 -16
- package/dist/index.js +82 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +128 -64
package/dist/index.d.mts
CHANGED
|
@@ -19,11 +19,6 @@ interface SlopImageOptions {
|
|
|
19
19
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
20
20
|
*/
|
|
21
21
|
aspectRatio?: ImageAspectRatio;
|
|
22
|
-
/**
|
|
23
|
-
* The AI model to use for generation.
|
|
24
|
-
* Overrides the default model specified in the bucket settings.
|
|
25
|
-
*/
|
|
26
|
-
model?: "gemini" | "gemini-flash" | "gemini-pro" | "imagen";
|
|
27
22
|
/**
|
|
28
23
|
* Dynamic variables to interpolate into the prompt.
|
|
29
24
|
* E.g., if prompt is "A photo of a {color} dog", pass { color: "brown" }.
|
|
@@ -42,7 +37,21 @@ interface SlopImageOptions {
|
|
|
42
37
|
baseUrl?: string;
|
|
43
38
|
}
|
|
44
39
|
declare function interpolatePrompt(prompt?: string, variables?: Record<string, string | number | undefined | null>): string;
|
|
40
|
+
/**
|
|
41
|
+
* Builds a URL to render or retrieve an image from Slop Machine.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Configuration options for the image generation.
|
|
44
|
+
* @returns A string containing the fully constructed URL.
|
|
45
|
+
*/
|
|
45
46
|
declare function buildImageUrl(options: SlopImageOptions): string;
|
|
47
|
+
/**
|
|
48
|
+
* Preloads an image from Slop Machine into the browser's cache.
|
|
49
|
+
* Useful for ensuring images are ready before displaying them.
|
|
50
|
+
*
|
|
51
|
+
* @param options - Configuration options for the image generation.
|
|
52
|
+
* @returns A promise that resolves when the image has been loaded.
|
|
53
|
+
*/
|
|
54
|
+
declare function preloadImage(options: SlopImageOptions): Promise<void>;
|
|
46
55
|
type VideoAspectRatio = "9:16" | "16:9";
|
|
47
56
|
interface SlopVideoOptions {
|
|
48
57
|
/**
|
|
@@ -64,11 +73,6 @@ interface SlopVideoOptions {
|
|
|
64
73
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
65
74
|
*/
|
|
66
75
|
aspectRatio?: VideoAspectRatio;
|
|
67
|
-
/**
|
|
68
|
-
* The AI model to use for generation.
|
|
69
|
-
* Overrides the default model specified in the bucket settings.
|
|
70
|
-
*/
|
|
71
|
-
model?: string;
|
|
72
76
|
/**
|
|
73
77
|
* Dynamic variables to interpolate into the prompt.
|
|
74
78
|
* E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
|
|
@@ -91,7 +95,21 @@ interface SlopVideoOptions {
|
|
|
91
95
|
*/
|
|
92
96
|
baseUrl?: string;
|
|
93
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Builds a URL to render or retrieve a video from Slop Machine.
|
|
100
|
+
*
|
|
101
|
+
* @param options - Configuration options for the video generation.
|
|
102
|
+
* @returns A string containing the fully constructed URL.
|
|
103
|
+
*/
|
|
94
104
|
declare function buildVideoUrl(options: SlopVideoOptions): string;
|
|
105
|
+
/**
|
|
106
|
+
* Preloads a video from Slop Machine into the browser's cache.
|
|
107
|
+
* Useful for ensuring videos are ready before displaying them.
|
|
108
|
+
*
|
|
109
|
+
* @param options - Configuration options for the video generation.
|
|
110
|
+
* @returns A promise that resolves when the video preload request has been initiated.
|
|
111
|
+
*/
|
|
112
|
+
declare function preloadVideo(options: SlopVideoOptions): Promise<void>;
|
|
95
113
|
interface SlopTextOptions {
|
|
96
114
|
/**
|
|
97
115
|
* The unique identifier of your Slop Machine bucket.
|
|
@@ -107,11 +125,6 @@ interface SlopTextOptions {
|
|
|
107
125
|
* instead of generating a new one.
|
|
108
126
|
*/
|
|
109
127
|
resultId?: string;
|
|
110
|
-
/**
|
|
111
|
-
* The AI model to use for generation.
|
|
112
|
-
* Overrides the default model specified in the bucket settings.
|
|
113
|
-
*/
|
|
114
|
-
model?: string;
|
|
115
128
|
/**
|
|
116
129
|
* Dynamic variables to interpolate into the prompt.
|
|
117
130
|
* E.g., if prompt is "A story about a {color} dog", pass { color: "brown" }.
|
|
@@ -123,6 +136,20 @@ interface SlopTextOptions {
|
|
|
123
136
|
*/
|
|
124
137
|
baseUrl?: string;
|
|
125
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Builds a URL to render or retrieve text from Slop Machine.
|
|
141
|
+
*
|
|
142
|
+
* @param options - Configuration options for the text generation.
|
|
143
|
+
* @returns A string containing the fully constructed URL.
|
|
144
|
+
*/
|
|
126
145
|
declare function buildTextUrl(options: SlopTextOptions): string;
|
|
146
|
+
/**
|
|
147
|
+
* Preloads text from Slop Machine into the browser's cache.
|
|
148
|
+
* Useful for ensuring text is ready before displaying it.
|
|
149
|
+
*
|
|
150
|
+
* @param options - Configuration options for the text generation.
|
|
151
|
+
* @returns A promise that resolves when the text preload request has been initiated.
|
|
152
|
+
*/
|
|
153
|
+
declare function preloadText(options: SlopTextOptions): Promise<void>;
|
|
127
154
|
|
|
128
|
-
export { type ImageAspectRatio, type SlopImageOptions, type SlopTextOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildTextUrl, buildVideoUrl, interpolatePrompt };
|
|
155
|
+
export { type ImageAspectRatio, type SlopImageOptions, type SlopTextOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildTextUrl, buildVideoUrl, interpolatePrompt, preloadImage, preloadText, preloadVideo };
|
package/dist/index.d.ts
CHANGED
|
@@ -19,11 +19,6 @@ interface SlopImageOptions {
|
|
|
19
19
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
20
20
|
*/
|
|
21
21
|
aspectRatio?: ImageAspectRatio;
|
|
22
|
-
/**
|
|
23
|
-
* The AI model to use for generation.
|
|
24
|
-
* Overrides the default model specified in the bucket settings.
|
|
25
|
-
*/
|
|
26
|
-
model?: "gemini" | "gemini-flash" | "gemini-pro" | "imagen";
|
|
27
22
|
/**
|
|
28
23
|
* Dynamic variables to interpolate into the prompt.
|
|
29
24
|
* E.g., if prompt is "A photo of a {color} dog", pass { color: "brown" }.
|
|
@@ -42,7 +37,21 @@ interface SlopImageOptions {
|
|
|
42
37
|
baseUrl?: string;
|
|
43
38
|
}
|
|
44
39
|
declare function interpolatePrompt(prompt?: string, variables?: Record<string, string | number | undefined | null>): string;
|
|
40
|
+
/**
|
|
41
|
+
* Builds a URL to render or retrieve an image from Slop Machine.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Configuration options for the image generation.
|
|
44
|
+
* @returns A string containing the fully constructed URL.
|
|
45
|
+
*/
|
|
45
46
|
declare function buildImageUrl(options: SlopImageOptions): string;
|
|
47
|
+
/**
|
|
48
|
+
* Preloads an image from Slop Machine into the browser's cache.
|
|
49
|
+
* Useful for ensuring images are ready before displaying them.
|
|
50
|
+
*
|
|
51
|
+
* @param options - Configuration options for the image generation.
|
|
52
|
+
* @returns A promise that resolves when the image has been loaded.
|
|
53
|
+
*/
|
|
54
|
+
declare function preloadImage(options: SlopImageOptions): Promise<void>;
|
|
46
55
|
type VideoAspectRatio = "9:16" | "16:9";
|
|
47
56
|
interface SlopVideoOptions {
|
|
48
57
|
/**
|
|
@@ -64,11 +73,6 @@ interface SlopVideoOptions {
|
|
|
64
73
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
65
74
|
*/
|
|
66
75
|
aspectRatio?: VideoAspectRatio;
|
|
67
|
-
/**
|
|
68
|
-
* The AI model to use for generation.
|
|
69
|
-
* Overrides the default model specified in the bucket settings.
|
|
70
|
-
*/
|
|
71
|
-
model?: string;
|
|
72
76
|
/**
|
|
73
77
|
* Dynamic variables to interpolate into the prompt.
|
|
74
78
|
* E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
|
|
@@ -91,7 +95,21 @@ interface SlopVideoOptions {
|
|
|
91
95
|
*/
|
|
92
96
|
baseUrl?: string;
|
|
93
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Builds a URL to render or retrieve a video from Slop Machine.
|
|
100
|
+
*
|
|
101
|
+
* @param options - Configuration options for the video generation.
|
|
102
|
+
* @returns A string containing the fully constructed URL.
|
|
103
|
+
*/
|
|
94
104
|
declare function buildVideoUrl(options: SlopVideoOptions): string;
|
|
105
|
+
/**
|
|
106
|
+
* Preloads a video from Slop Machine into the browser's cache.
|
|
107
|
+
* Useful for ensuring videos are ready before displaying them.
|
|
108
|
+
*
|
|
109
|
+
* @param options - Configuration options for the video generation.
|
|
110
|
+
* @returns A promise that resolves when the video preload request has been initiated.
|
|
111
|
+
*/
|
|
112
|
+
declare function preloadVideo(options: SlopVideoOptions): Promise<void>;
|
|
95
113
|
interface SlopTextOptions {
|
|
96
114
|
/**
|
|
97
115
|
* The unique identifier of your Slop Machine bucket.
|
|
@@ -107,11 +125,6 @@ interface SlopTextOptions {
|
|
|
107
125
|
* instead of generating a new one.
|
|
108
126
|
*/
|
|
109
127
|
resultId?: string;
|
|
110
|
-
/**
|
|
111
|
-
* The AI model to use for generation.
|
|
112
|
-
* Overrides the default model specified in the bucket settings.
|
|
113
|
-
*/
|
|
114
|
-
model?: string;
|
|
115
128
|
/**
|
|
116
129
|
* Dynamic variables to interpolate into the prompt.
|
|
117
130
|
* E.g., if prompt is "A story about a {color} dog", pass { color: "brown" }.
|
|
@@ -123,6 +136,20 @@ interface SlopTextOptions {
|
|
|
123
136
|
*/
|
|
124
137
|
baseUrl?: string;
|
|
125
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Builds a URL to render or retrieve text from Slop Machine.
|
|
141
|
+
*
|
|
142
|
+
* @param options - Configuration options for the text generation.
|
|
143
|
+
* @returns A string containing the fully constructed URL.
|
|
144
|
+
*/
|
|
126
145
|
declare function buildTextUrl(options: SlopTextOptions): string;
|
|
146
|
+
/**
|
|
147
|
+
* Preloads text from Slop Machine into the browser's cache.
|
|
148
|
+
* Useful for ensuring text is ready before displaying it.
|
|
149
|
+
*
|
|
150
|
+
* @param options - Configuration options for the text generation.
|
|
151
|
+
* @returns A promise that resolves when the text preload request has been initiated.
|
|
152
|
+
*/
|
|
153
|
+
declare function preloadText(options: SlopTextOptions): Promise<void>;
|
|
127
154
|
|
|
128
|
-
export { type ImageAspectRatio, type SlopImageOptions, type SlopTextOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildTextUrl, buildVideoUrl, interpolatePrompt };
|
|
155
|
+
export { type ImageAspectRatio, type SlopImageOptions, type SlopTextOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildTextUrl, buildVideoUrl, interpolatePrompt, preloadImage, preloadText, preloadVideo };
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,10 @@ __export(index_exports, {
|
|
|
23
23
|
buildImageUrl: () => buildImageUrl,
|
|
24
24
|
buildTextUrl: () => buildTextUrl,
|
|
25
25
|
buildVideoUrl: () => buildVideoUrl,
|
|
26
|
-
interpolatePrompt: () => interpolatePrompt
|
|
26
|
+
interpolatePrompt: () => interpolatePrompt,
|
|
27
|
+
preloadImage: () => preloadImage,
|
|
28
|
+
preloadText: () => preloadText,
|
|
29
|
+
preloadVideo: () => preloadVideo
|
|
27
30
|
});
|
|
28
31
|
module.exports = __toCommonJS(index_exports);
|
|
29
32
|
function interpolatePrompt(prompt, variables) {
|
|
@@ -44,42 +47,50 @@ function buildImageUrl(options) {
|
|
|
44
47
|
version,
|
|
45
48
|
resultId,
|
|
46
49
|
aspectRatio = "1:1",
|
|
47
|
-
model,
|
|
48
50
|
quality = "fast",
|
|
49
51
|
variables = {},
|
|
50
52
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage"
|
|
51
53
|
} = options;
|
|
52
54
|
const params = new URLSearchParams();
|
|
53
55
|
params.set("bucketId", bucketId);
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
if (!resultId) {
|
|
57
|
+
if (aspectRatio) {
|
|
58
|
+
params.set("aspectRatio", aspectRatio);
|
|
59
|
+
}
|
|
60
|
+
if (version) {
|
|
61
|
+
params.set("version", String(version));
|
|
62
|
+
}
|
|
63
|
+
if (quality && quality !== "fast") {
|
|
64
|
+
params.set("quality", quality);
|
|
65
|
+
} else if (quality === "fast") {
|
|
66
|
+
params.set("quality", "fast");
|
|
67
|
+
}
|
|
68
|
+
if (Object.keys(variables).length > 0) {
|
|
69
|
+
params.set("variables", JSON.stringify(variables));
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
64
72
|
params.set("resultId", resultId);
|
|
65
73
|
}
|
|
66
|
-
if (quality && quality !== "fast") {
|
|
67
|
-
params.set("quality", quality);
|
|
68
|
-
} else if (quality === "fast") {
|
|
69
|
-
params.set("quality", "fast");
|
|
70
|
-
}
|
|
71
|
-
if (Object.keys(variables).length > 0) {
|
|
72
|
-
params.set("variables", JSON.stringify(variables));
|
|
73
|
-
}
|
|
74
74
|
return `${baseUrl}?${params.toString()}`;
|
|
75
75
|
}
|
|
76
|
+
function preloadImage(options) {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
if (typeof window === "undefined") {
|
|
79
|
+
resolve();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const img = new Image();
|
|
83
|
+
img.onload = () => resolve();
|
|
84
|
+
img.onerror = (err) => reject(err);
|
|
85
|
+
img.src = buildImageUrl(options);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
76
88
|
function buildVideoUrl(options) {
|
|
77
89
|
const {
|
|
78
90
|
bucketId,
|
|
79
91
|
version,
|
|
80
92
|
resultId,
|
|
81
93
|
aspectRatio = "16:9",
|
|
82
|
-
model,
|
|
83
94
|
quality = "fast",
|
|
84
95
|
variables = {},
|
|
85
96
|
duration = 4,
|
|
@@ -87,55 +98,78 @@ function buildVideoUrl(options) {
|
|
|
87
98
|
} = options;
|
|
88
99
|
const params = new URLSearchParams();
|
|
89
100
|
params.set("bucketId", bucketId);
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
if (!resultId) {
|
|
102
|
+
if (aspectRatio) {
|
|
103
|
+
params.set("aspectRatio", aspectRatio);
|
|
104
|
+
}
|
|
105
|
+
if (version) {
|
|
106
|
+
params.set("version", String(version));
|
|
107
|
+
}
|
|
108
|
+
if (duration) {
|
|
109
|
+
params.set("duration", String(duration));
|
|
110
|
+
}
|
|
111
|
+
if (quality) {
|
|
112
|
+
params.set("quality", quality);
|
|
113
|
+
}
|
|
114
|
+
if (Object.keys(variables).length > 0) {
|
|
115
|
+
params.set("variables", JSON.stringify(variables));
|
|
116
|
+
}
|
|
101
117
|
} else {
|
|
102
|
-
params.set("
|
|
103
|
-
}
|
|
104
|
-
if (Object.keys(variables).length > 0) {
|
|
105
|
-
params.set("variables", JSON.stringify(variables));
|
|
118
|
+
params.set("resultId", resultId);
|
|
106
119
|
}
|
|
107
120
|
return `${baseUrl}?${params.toString()}`;
|
|
108
121
|
}
|
|
122
|
+
function preloadVideo(options) {
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
if (typeof window === "undefined") {
|
|
125
|
+
resolve();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
fetch(buildVideoUrl(options), { mode: "no-cors" }).then(() => resolve()).catch((err) => reject(err));
|
|
129
|
+
});
|
|
130
|
+
}
|
|
109
131
|
function buildTextUrl(options) {
|
|
110
132
|
const {
|
|
111
133
|
bucketId,
|
|
112
134
|
version,
|
|
113
135
|
resultId,
|
|
114
|
-
model,
|
|
115
136
|
variables = {},
|
|
116
137
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText"
|
|
117
138
|
} = options;
|
|
118
139
|
const params = new URLSearchParams();
|
|
119
140
|
params.set("bucketId", bucketId);
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
141
|
+
if (!resultId) {
|
|
142
|
+
if (version) {
|
|
143
|
+
params.set("version", String(version));
|
|
144
|
+
}
|
|
145
|
+
if (resultId) {
|
|
146
|
+
params.set("resultId", resultId);
|
|
147
|
+
}
|
|
148
|
+
if (Object.keys(variables).length > 0) {
|
|
149
|
+
params.set("variables", JSON.stringify(variables));
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
127
152
|
params.set("resultId", resultId);
|
|
128
153
|
}
|
|
129
|
-
if (Object.keys(variables).length > 0) {
|
|
130
|
-
params.set("variables", JSON.stringify(variables));
|
|
131
|
-
}
|
|
132
154
|
return `${baseUrl}?${params.toString()}`;
|
|
133
155
|
}
|
|
156
|
+
function preloadText(options) {
|
|
157
|
+
return new Promise((resolve, reject) => {
|
|
158
|
+
if (typeof window === "undefined") {
|
|
159
|
+
resolve();
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
fetch(buildTextUrl(options), { mode: "no-cors" }).then(() => resolve()).catch((err) => reject(err));
|
|
163
|
+
});
|
|
164
|
+
}
|
|
134
165
|
// Annotate the CommonJS export names for ESM import in node:
|
|
135
166
|
0 && (module.exports = {
|
|
136
167
|
buildImageUrl,
|
|
137
168
|
buildTextUrl,
|
|
138
169
|
buildVideoUrl,
|
|
139
|
-
interpolatePrompt
|
|
170
|
+
interpolatePrompt,
|
|
171
|
+
preloadImage,
|
|
172
|
+
preloadText,
|
|
173
|
+
preloadVideo
|
|
140
174
|
});
|
|
141
175
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type ImageAspectRatio =\n | \"1:1\"\n | \"2:3\"\n | \"3:2\"\n | \"3:4\"\n | \"4:3\"\n | \"4:5\"\n | \"5:4\"\n | \"9:16\"\n | \"16:9\"\n | \"21:9\";\n\nexport interface SlopImageOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated image\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated image. Defaults to \"1:1\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: ImageAspectRatio;\n /**\n * The AI model to use for generation.\n * Overrides the default model specified in the bucket settings.\n */\n model?: \"gemini\" | \"gemini-flash\" | \"gemini-pro\" | \"imagen\";\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A photo of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\nexport function interpolatePrompt(\n prompt?: string,\n variables?: Record<string, string | number | undefined | null>,\n): string {\n if (!prompt) return \"\";\n let text = prompt;\n if (!variables) return text;\n\n Object.keys(variables).forEach((key) => {\n const value = variables[key];\n if (value !== undefined && value !== null) {\n text = text.replace(new RegExp(`\\\\{${key}\\\\}`, \"g\"), String(value));\n }\n });\n return text;\n}\n\nexport function buildImageUrl(options: SlopImageOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"1:1\",\n model,\n quality = \"fast\",\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n\n if (model) {\n params.set(\"model\", model);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n }\n if (quality && quality !== \"fast\") {\n params.set(\"quality\", quality);\n } else if (quality === \"fast\") {\n params.set(\"quality\", \"fast\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\nexport type VideoAspectRatio = \"9:16\" | \"16:9\";\n\nexport interface SlopVideoOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated video\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated video. Defaults to \"16:9\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: VideoAspectRatio;\n /**\n * The AI model to use for generation.\n * Overrides the default model specified in the bucket settings.\n */\n model?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A video of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The duration of the generated video in seconds.\n * Must be between 4 and 8. Defaults to 4.\n */\n duration?: number;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\nexport function buildVideoUrl(options: SlopVideoOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"16:9\",\n model,\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n\n if (model) {\n params.set(\"model\", model);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n } else {\n params.set(\"quality\", \"fast\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\nexport interface SlopTextOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated text\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The AI model to use for generation.\n * Overrides the default model specified in the bucket settings.\n */\n model?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A story about a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\nexport function buildTextUrl(options: SlopTextOptions): string {\n const {\n bucketId,\n version,\n resultId,\n model,\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (model) {\n params.set(\"model\", model);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuDO,SAAS,kBACd,QACA,WACQ;AACR,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO;AACX,MAAI,CAAC,UAAW,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\"\n | \"5:4\"\n | \"9:16\"\n | \"16:9\"\n | \"21:9\";\n\nexport interface SlopImageOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated image\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated image. Defaults to \"1:1\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: ImageAspectRatio;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A photo of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\nexport function interpolatePrompt(\n prompt?: string,\n variables?: Record<string, string | number | undefined | null>,\n): string {\n if (!prompt) return \"\";\n let text = prompt;\n if (!variables) return text;\n\n Object.keys(variables).forEach((key) => {\n const value = variables[key];\n if (value !== undefined && value !== null) {\n text = text.replace(new RegExp(`\\\\{${key}\\\\}`, \"g\"), String(value));\n }\n });\n return text;\n}\n\n/**\n * Builds a URL to render or retrieve an image from Slop Machine.\n *\n * @param options - Configuration options for the image generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildImageUrl(options: SlopImageOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"1:1\",\n quality = \"fast\",\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (quality && quality !== \"fast\") {\n params.set(\"quality\", quality);\n } else if (quality === \"fast\") {\n params.set(\"quality\", \"fast\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads an image from Slop Machine into the browser's cache.\n * Useful for ensuring images are ready before displaying them.\n *\n * @param options - Configuration options for the image generation.\n * @returns A promise that resolves when the image has been loaded.\n */\nexport function preloadImage(options: SlopImageOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n const img = new Image();\n img.onload = () => resolve();\n img.onerror = (err) => reject(err);\n img.src = buildImageUrl(options);\n });\n}\n\nexport type VideoAspectRatio = \"9:16\" | \"16:9\";\n\nexport interface SlopVideoOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated video\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated video. Defaults to \"16:9\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: VideoAspectRatio;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A video of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The duration of the generated video in seconds.\n * Must be between 4 and 8. Defaults to 4.\n */\n duration?: number;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\n/**\n * Builds a URL to render or retrieve a video from Slop Machine.\n *\n * @param options - Configuration options for the video generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildVideoUrl(options: SlopVideoOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"16:9\",\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (duration) {\n params.set(\"duration\", String(duration));\n }\n if (quality) {\n params.set(\"quality\", quality);\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads a video from Slop Machine into the browser's cache.\n * Useful for ensuring videos are ready before displaying them.\n *\n * @param options - Configuration options for the video generation.\n * @returns A promise that resolves when the video preload request has been initiated.\n */\nexport function preloadVideo(options: SlopVideoOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // We can just fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildVideoUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\nexport interface SlopTextOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated text\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A story about a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\n/**\n * Builds a URL to render or retrieve text from Slop Machine.\n *\n * @param options - Configuration options for the text generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildTextUrl(options: SlopTextOptions): string {\n const {\n bucketId,\n version,\n resultId,\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads text from Slop Machine into the browser's cache.\n * Useful for ensuring text is ready before displaying it.\n *\n * @param options - Configuration options for the text generation.\n * @returns A promise that resolves when the text preload request has been initiated.\n */\nexport function preloadText(options: SlopTextOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // Fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildTextUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkDO,SAAS,kBACd,QACA,WACQ;AACR,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO;AACX,MAAI,CAAC,UAAW,QAAO;AAEvB,SAAO,KAAK,SAAS,EAAE,QAAQ,CAAC,QAAQ;AACtC,UAAM,QAAQ,UAAU,GAAG;AAC3B,QAAI,UAAU,UAAa,UAAU,MAAM;AACzC,aAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,GAAG,OAAO,GAAG,GAAG,OAAO,KAAK,CAAC;AAAA,IACp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AK,SAAS,EAAE,SAAS,GAAG;AACrC,aAAO,IAAI,aAAa,KAAK,UAAU,SAAS,CAAC;AAAA,IACnD;AAAA,EACF,OAAO;AACL,WAAO,IAAI,YAAY,QAAQ;AAAA,EACjC;AAEA,SAAO,GAAG,OAAO,IAAI,OAAO,SAAS,CAAC;AACxC;AASO,SAAS,YAAY,SAAyC;AACnE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI,OAAO,WAAW,aAAa;AACjC,cAAQ;AACR;AAAA,IACF;AAIA,UAAM,aAAa,OAAO,GAAG,EAAE,MAAM,UAAU,CAAC,EAC7C,KAAK,MAAM,QAAQ,CAAC,EACpB,MAAM,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,EAC/B,CAAC;AACH;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -17,42 +17,50 @@ function buildImageUrl(options) {
|
|
|
17
17
|
version,
|
|
18
18
|
resultId,
|
|
19
19
|
aspectRatio = "1:1",
|
|
20
|
-
model,
|
|
21
20
|
quality = "fast",
|
|
22
21
|
variables = {},
|
|
23
22
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage"
|
|
24
23
|
} = options;
|
|
25
24
|
const params = new URLSearchParams();
|
|
26
25
|
params.set("bucketId", bucketId);
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
if (!resultId) {
|
|
27
|
+
if (aspectRatio) {
|
|
28
|
+
params.set("aspectRatio", aspectRatio);
|
|
29
|
+
}
|
|
30
|
+
if (version) {
|
|
31
|
+
params.set("version", String(version));
|
|
32
|
+
}
|
|
33
|
+
if (quality && quality !== "fast") {
|
|
34
|
+
params.set("quality", quality);
|
|
35
|
+
} else if (quality === "fast") {
|
|
36
|
+
params.set("quality", "fast");
|
|
37
|
+
}
|
|
38
|
+
if (Object.keys(variables).length > 0) {
|
|
39
|
+
params.set("variables", JSON.stringify(variables));
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
37
42
|
params.set("resultId", resultId);
|
|
38
43
|
}
|
|
39
|
-
if (quality && quality !== "fast") {
|
|
40
|
-
params.set("quality", quality);
|
|
41
|
-
} else if (quality === "fast") {
|
|
42
|
-
params.set("quality", "fast");
|
|
43
|
-
}
|
|
44
|
-
if (Object.keys(variables).length > 0) {
|
|
45
|
-
params.set("variables", JSON.stringify(variables));
|
|
46
|
-
}
|
|
47
44
|
return `${baseUrl}?${params.toString()}`;
|
|
48
45
|
}
|
|
46
|
+
function preloadImage(options) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
if (typeof window === "undefined") {
|
|
49
|
+
resolve();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const img = new Image();
|
|
53
|
+
img.onload = () => resolve();
|
|
54
|
+
img.onerror = (err) => reject(err);
|
|
55
|
+
img.src = buildImageUrl(options);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
49
58
|
function buildVideoUrl(options) {
|
|
50
59
|
const {
|
|
51
60
|
bucketId,
|
|
52
61
|
version,
|
|
53
62
|
resultId,
|
|
54
63
|
aspectRatio = "16:9",
|
|
55
|
-
model,
|
|
56
64
|
quality = "fast",
|
|
57
65
|
variables = {},
|
|
58
66
|
duration = 4,
|
|
@@ -60,54 +68,77 @@ function buildVideoUrl(options) {
|
|
|
60
68
|
} = options;
|
|
61
69
|
const params = new URLSearchParams();
|
|
62
70
|
params.set("bucketId", bucketId);
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
if (!resultId) {
|
|
72
|
+
if (aspectRatio) {
|
|
73
|
+
params.set("aspectRatio", aspectRatio);
|
|
74
|
+
}
|
|
75
|
+
if (version) {
|
|
76
|
+
params.set("version", String(version));
|
|
77
|
+
}
|
|
78
|
+
if (duration) {
|
|
79
|
+
params.set("duration", String(duration));
|
|
80
|
+
}
|
|
81
|
+
if (quality) {
|
|
82
|
+
params.set("quality", quality);
|
|
83
|
+
}
|
|
84
|
+
if (Object.keys(variables).length > 0) {
|
|
85
|
+
params.set("variables", JSON.stringify(variables));
|
|
86
|
+
}
|
|
74
87
|
} else {
|
|
75
|
-
params.set("
|
|
76
|
-
}
|
|
77
|
-
if (Object.keys(variables).length > 0) {
|
|
78
|
-
params.set("variables", JSON.stringify(variables));
|
|
88
|
+
params.set("resultId", resultId);
|
|
79
89
|
}
|
|
80
90
|
return `${baseUrl}?${params.toString()}`;
|
|
81
91
|
}
|
|
92
|
+
function preloadVideo(options) {
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
if (typeof window === "undefined") {
|
|
95
|
+
resolve();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
fetch(buildVideoUrl(options), { mode: "no-cors" }).then(() => resolve()).catch((err) => reject(err));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
82
101
|
function buildTextUrl(options) {
|
|
83
102
|
const {
|
|
84
103
|
bucketId,
|
|
85
104
|
version,
|
|
86
105
|
resultId,
|
|
87
|
-
model,
|
|
88
106
|
variables = {},
|
|
89
107
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText"
|
|
90
108
|
} = options;
|
|
91
109
|
const params = new URLSearchParams();
|
|
92
110
|
params.set("bucketId", bucketId);
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
111
|
+
if (!resultId) {
|
|
112
|
+
if (version) {
|
|
113
|
+
params.set("version", String(version));
|
|
114
|
+
}
|
|
115
|
+
if (resultId) {
|
|
116
|
+
params.set("resultId", resultId);
|
|
117
|
+
}
|
|
118
|
+
if (Object.keys(variables).length > 0) {
|
|
119
|
+
params.set("variables", JSON.stringify(variables));
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
100
122
|
params.set("resultId", resultId);
|
|
101
123
|
}
|
|
102
|
-
if (Object.keys(variables).length > 0) {
|
|
103
|
-
params.set("variables", JSON.stringify(variables));
|
|
104
|
-
}
|
|
105
124
|
return `${baseUrl}?${params.toString()}`;
|
|
106
125
|
}
|
|
126
|
+
function preloadText(options) {
|
|
127
|
+
return new Promise((resolve, reject) => {
|
|
128
|
+
if (typeof window === "undefined") {
|
|
129
|
+
resolve();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
fetch(buildTextUrl(options), { mode: "no-cors" }).then(() => resolve()).catch((err) => reject(err));
|
|
133
|
+
});
|
|
134
|
+
}
|
|
107
135
|
export {
|
|
108
136
|
buildImageUrl,
|
|
109
137
|
buildTextUrl,
|
|
110
138
|
buildVideoUrl,
|
|
111
|
-
interpolatePrompt
|
|
139
|
+
interpolatePrompt,
|
|
140
|
+
preloadImage,
|
|
141
|
+
preloadText,
|
|
142
|
+
preloadVideo
|
|
112
143
|
};
|
|
113
144
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type ImageAspectRatio =\n | \"1:1\"\n | \"2:3\"\n | \"3:2\"\n | \"3:4\"\n | \"4:3\"\n | \"4:5\"\n | \"5:4\"\n | \"9:16\"\n | \"16:9\"\n | \"21:9\";\n\nexport interface SlopImageOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated image\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated image. Defaults to \"1:1\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: ImageAspectRatio;\n /**\n * The AI model to use for generation.\n * Overrides the default model specified in the bucket settings.\n */\n model?: \"gemini\" | \"gemini-flash\" | \"gemini-pro\" | \"imagen\";\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A photo of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\nexport function interpolatePrompt(\n prompt?: string,\n variables?: Record<string, string | number | undefined | null>,\n): string {\n if (!prompt) return \"\";\n let text = prompt;\n if (!variables) return text;\n\n Object.keys(variables).forEach((key) => {\n const value = variables[key];\n if (value !== undefined && value !== null) {\n text = text.replace(new RegExp(`\\\\{${key}\\\\}`, \"g\"), String(value));\n }\n });\n return text;\n}\n\nexport function buildImageUrl(options: SlopImageOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"1:1\",\n model,\n quality = \"fast\",\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n\n if (model) {\n params.set(\"model\", model);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n }\n if (quality && quality !== \"fast\") {\n params.set(\"quality\", quality);\n } else if (quality === \"fast\") {\n params.set(\"quality\", \"fast\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\nexport type VideoAspectRatio = \"9:16\" | \"16:9\";\n\nexport interface SlopVideoOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated video\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated video. Defaults to \"16:9\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: VideoAspectRatio;\n /**\n * The AI model to use for generation.\n * Overrides the default model specified in the bucket settings.\n */\n model?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A video of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The duration of the generated video in seconds.\n * Must be between 4 and 8. Defaults to 4.\n */\n duration?: number;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\nexport function buildVideoUrl(options: SlopVideoOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"16:9\",\n model,\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n\n if (model) {\n params.set(\"model\", model);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n } else {\n params.set(\"quality\", \"fast\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\nexport interface SlopTextOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated text\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The AI model to use for generation.\n * Overrides the default model specified in the bucket settings.\n */\n model?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A story about a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\nexport function buildTextUrl(options: SlopTextOptions): string {\n const {\n bucketId,\n version,\n resultId,\n model,\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (model) {\n params.set(\"model\", model);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n"],"mappings":";AAuDO,SAAS,kBACd,QACA,WACQ;AACR,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO;AACX,MAAI,CAAC,UAAW,QAAO;AAEvB,SAAO,KAAK,SAAS,EAAE,QAAQ,CAAC,QAAQ;AACtC,UAAM,QAAQ,UAAU,GAAG;AAC3B,QAAI,UAAU,UAAa,UAAU,MAAM;AACzC,aAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,GAAG,OAAO,GAAG,GAAG,OAAO,KAAK,CAAC;AAAA,IACpE;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAEO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA,UAAU;AAAA,IACV,YAAY,CAAC;AAAA,IACb,UAAU;AAAA,EACZ,IAAI;AAEJ,QAAM,SAAS,I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U,SAAS,CAAC;AAAA,EACnD;AAEA,SAAO,GAAG,OAAO,IAAI,OAAO,SAAS,CAAC;AACxC;AAkCO,SAAS,aAAa,SAAkC;AAC7D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,CAAC;AAAA,IACb,UAAU;AAAA,EACZ,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,OAAO;AACT,WAAO,IAAI,SAAS,KAAK;AAAA,EAC3B;AACA,MAAI,SAAS;AACX,WAAO,IAAI,WAAW,OAAO,OAAO,CAAC;AAAA,EACvC;AACA,MAAI,UAAU;AACZ,WAAO,IAAI,YAAY,QAAQ;AAAA,EACjC;AAEA,MAAI,OAAO,KAAK,SAAS,EAAE,SAAS,GAAG;AACrC,WAAO,IAAI,aAAa,KAAK,UAAU,SAAS,CAAC;AAAA,EACnD;AAEA,SAAO,GAAG,OAAO,IAAI,OAAO,SAAS,CAAC;AACxC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type ImageAspectRatio =\n | \"1:1\"\n | \"2:3\"\n | \"3:2\"\n | \"3:4\"\n | \"4:3\"\n | \"4:5\"\n | \"5:4\"\n | \"9:16\"\n | \"16:9\"\n | \"21:9\";\n\nexport interface SlopImageOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated image\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated image. Defaults to \"1:1\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: ImageAspectRatio;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A photo of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\nexport function interpolatePrompt(\n prompt?: string,\n variables?: Record<string, string | number | undefined | null>,\n): string {\n if (!prompt) return \"\";\n let text = prompt;\n if (!variables) return text;\n\n Object.keys(variables).forEach((key) => {\n const value = variables[key];\n if (value !== undefined && value !== null) {\n text = text.replace(new RegExp(`\\\\{${key}\\\\}`, \"g\"), String(value));\n }\n });\n return text;\n}\n\n/**\n * Builds a URL to render or retrieve an image from Slop Machine.\n *\n * @param options - Configuration options for the image generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildImageUrl(options: SlopImageOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"1:1\",\n quality = \"fast\",\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (quality && quality !== \"fast\") {\n params.set(\"quality\", quality);\n } else if (quality === \"fast\") {\n params.set(\"quality\", \"fast\");\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads an image from Slop Machine into the browser's cache.\n * Useful for ensuring images are ready before displaying them.\n *\n * @param options - Configuration options for the image generation.\n * @returns A promise that resolves when the image has been loaded.\n */\nexport function preloadImage(options: SlopImageOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n const img = new Image();\n img.onload = () => resolve();\n img.onerror = (err) => reject(err);\n img.src = buildImageUrl(options);\n });\n}\n\nexport type VideoAspectRatio = \"9:16\" | \"16:9\";\n\nexport interface SlopVideoOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated video\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * The aspect ratio of the generated video. Defaults to \"16:9\".\n * Common values: \"1:1\", \"16:9\", \"9:16\", \"4:3\", \"3:4\".\n */\n aspectRatio?: VideoAspectRatio;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A video of a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The duration of the generated video in seconds.\n * Must be between 4 and 8. Defaults to 4.\n */\n duration?: number;\n /**\n * The target quality (\"fast\" or \"high\"). Only affects new generations and is ignored for caching.\n * Ignored if `model` is provided.\n * Defaults to \"fast\".\n */\n quality?: \"fast\" | \"high\";\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\n/**\n * Builds a URL to render or retrieve a video from Slop Machine.\n *\n * @param options - Configuration options for the video generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildVideoUrl(options: SlopVideoOptions): string {\n const {\n bucketId,\n version,\n resultId,\n aspectRatio = \"16:9\",\n quality = \"fast\",\n variables = {},\n duration = 4,\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderVideo\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (aspectRatio) {\n params.set(\"aspectRatio\", aspectRatio);\n }\n if (version) {\n params.set(\"version\", String(version));\n }\n if (duration) {\n params.set(\"duration\", String(duration));\n }\n if (quality) {\n params.set(\"quality\", quality);\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads a video from Slop Machine into the browser's cache.\n * Useful for ensuring videos are ready before displaying them.\n *\n * @param options - Configuration options for the video generation.\n * @returns A promise that resolves when the video preload request has been initiated.\n */\nexport function preloadVideo(options: SlopVideoOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // We can just fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildVideoUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n\nexport interface SlopTextOptions {\n /**\n * The unique identifier of your Slop Machine bucket.\n */\n bucketId: string;\n /**\n * The specific version of the prompt/settings to use.\n * If omitted, the latest version will be used.\n */\n version?: number;\n /**\n * Result ID to retrieve a specific previously generated text\n * instead of generating a new one.\n */\n resultId?: string;\n /**\n * Dynamic variables to interpolate into the prompt.\n * E.g., if prompt is \"A story about a {color} dog\", pass { color: \"brown\" }.\n */\n variables?: Record<string, string | number | undefined | null>;\n /**\n * The base URL for the Slop Machine API.\n * Defaults to the production URL. Useful for testing against local deployments.\n */\n baseUrl?: string;\n}\n\n/**\n * Builds a URL to render or retrieve text from Slop Machine.\n *\n * @param options - Configuration options for the text generation.\n * @returns A string containing the fully constructed URL.\n */\nexport function buildTextUrl(options: SlopTextOptions): string {\n const {\n bucketId,\n version,\n resultId,\n variables = {},\n baseUrl = \"https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText\",\n } = options;\n\n const params = new URLSearchParams();\n params.set(\"bucketId\", bucketId);\n\n if (!resultId) {\n if (version) {\n params.set(\"version\", String(version));\n }\n if (resultId) {\n params.set(\"resultId\", resultId);\n }\n\n if (Object.keys(variables).length > 0) {\n params.set(\"variables\", JSON.stringify(variables));\n }\n } else {\n params.set(\"resultId\", resultId);\n }\n\n return `${baseUrl}?${params.toString()}`;\n}\n\n/**\n * Preloads text from Slop Machine into the browser's cache.\n * Useful for ensuring text is ready before displaying it.\n *\n * @param options - Configuration options for the text generation.\n * @returns A promise that resolves when the text preload request has been initiated.\n */\nexport function preloadText(options: SlopTextOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (typeof window === \"undefined\") {\n resolve();\n return;\n }\n\n // Fetch the URL to preload it into the browser's cache.\n // We use no-cors to avoid CORS errors for simple preloads\n fetch(buildTextUrl(options), { mode: \"no-cors\" })\n .then(() => resolve())\n .catch((err) => reject(err));\n });\n}\n"],"mappings":";AAkDO,SAAS,kBACd,QACA,WACQ;AACR,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO;AACX,MAAI,CAAC,UAAW,QAAO;AAEvB,SAAO,KAAK,SAAS,EAAE,QAAQ,CAAC,QAAQ;AACtC,UAAM,QAAQ,UAAU,GAAG;AAC3B,QAAI,UAAU,UAAa,UAAU,MAAM;AACzC,aAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,GAAG,OAAO,GAAG,GAAG,OAAO,KAAK,CAAC;AAAA,IACpE;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAQO,SAAS,cAAc,SAAmC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,UAAU;AAAA,IACV,YAAY,CAAC;AAAA,IACb,UAAU;AAAA,EACZ,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,CAAC,UAAU;AACb,QAAI,aAAa;AACf,aAAO,IAAI,eAAe,WAAW;AAAA,IACvC;AACA,QAAI,SAAS;AACX,aAAO,IAAI,WAAW,OAAO,OAAO,CAAC;AAAA,IACvC;AACA,QAAI,WAAW,YAAY,QAAQ;AACjC,aAAO,IAAI,WAAW,OAAO;AAAA,IAC/B,WAAW,YAAY,QAAQ;AAC7B,aAAO,IAAI,WAAW,MAAM;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|
{
|
|
2
2
|
"name": "@slopmachine/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "The official Core / VanillaJS SDK for Slop Machine",
|
|
5
5
|
"llms": "https://slopmachine-dev.github.io/slopmachine-sdk/llms.txt",
|
|
6
6
|
"llmsFull": "https://slopmachine-dev.github.io/slopmachine-sdk/llms-full.txt",
|
package/src/index.ts
CHANGED
|
@@ -30,11 +30,6 @@ export interface SlopImageOptions {
|
|
|
30
30
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
31
31
|
*/
|
|
32
32
|
aspectRatio?: ImageAspectRatio;
|
|
33
|
-
/**
|
|
34
|
-
* The AI model to use for generation.
|
|
35
|
-
* Overrides the default model specified in the bucket settings.
|
|
36
|
-
*/
|
|
37
|
-
model?: "gemini" | "gemini-flash" | "gemini-pro" | "imagen";
|
|
38
33
|
/**
|
|
39
34
|
* Dynamic variables to interpolate into the prompt.
|
|
40
35
|
* E.g., if prompt is "A photo of a {color} dog", pass { color: "brown" }.
|
|
@@ -70,13 +65,18 @@ export function interpolatePrompt(
|
|
|
70
65
|
return text;
|
|
71
66
|
}
|
|
72
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Builds a URL to render or retrieve an image from Slop Machine.
|
|
70
|
+
*
|
|
71
|
+
* @param options - Configuration options for the image generation.
|
|
72
|
+
* @returns A string containing the fully constructed URL.
|
|
73
|
+
*/
|
|
73
74
|
export function buildImageUrl(options: SlopImageOptions): string {
|
|
74
75
|
const {
|
|
75
76
|
bucketId,
|
|
76
77
|
version,
|
|
77
78
|
resultId,
|
|
78
79
|
aspectRatio = "1:1",
|
|
79
|
-
model,
|
|
80
80
|
quality = "fast",
|
|
81
81
|
variables = {},
|
|
82
82
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderImage",
|
|
@@ -85,32 +85,50 @@ export function buildImageUrl(options: SlopImageOptions): string {
|
|
|
85
85
|
const params = new URLSearchParams();
|
|
86
86
|
params.set("bucketId", bucketId);
|
|
87
87
|
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
if (!resultId) {
|
|
89
|
+
if (aspectRatio) {
|
|
90
|
+
params.set("aspectRatio", aspectRatio);
|
|
91
|
+
}
|
|
92
|
+
if (version) {
|
|
93
|
+
params.set("version", String(version));
|
|
94
|
+
}
|
|
95
|
+
if (quality && quality !== "fast") {
|
|
96
|
+
params.set("quality", quality);
|
|
97
|
+
} else if (quality === "fast") {
|
|
98
|
+
params.set("quality", "fast");
|
|
99
|
+
}
|
|
91
100
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
params.set("version", String(version));
|
|
97
|
-
}
|
|
98
|
-
if (resultId) {
|
|
101
|
+
if (Object.keys(variables).length > 0) {
|
|
102
|
+
params.set("variables", JSON.stringify(variables));
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
99
105
|
params.set("resultId", resultId);
|
|
100
106
|
}
|
|
101
|
-
if (quality && quality !== "fast") {
|
|
102
|
-
params.set("quality", quality);
|
|
103
|
-
} else if (quality === "fast") {
|
|
104
|
-
params.set("quality", "fast");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (Object.keys(variables).length > 0) {
|
|
108
|
-
params.set("variables", JSON.stringify(variables));
|
|
109
|
-
}
|
|
110
107
|
|
|
111
108
|
return `${baseUrl}?${params.toString()}`;
|
|
112
109
|
}
|
|
113
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Preloads an image from Slop Machine into the browser's cache.
|
|
113
|
+
* Useful for ensuring images are ready before displaying them.
|
|
114
|
+
*
|
|
115
|
+
* @param options - Configuration options for the image generation.
|
|
116
|
+
* @returns A promise that resolves when the image has been loaded.
|
|
117
|
+
*/
|
|
118
|
+
export function preloadImage(options: SlopImageOptions): Promise<void> {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
if (typeof window === "undefined") {
|
|
121
|
+
resolve();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const img = new Image();
|
|
126
|
+
img.onload = () => resolve();
|
|
127
|
+
img.onerror = (err) => reject(err);
|
|
128
|
+
img.src = buildImageUrl(options);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
114
132
|
export type VideoAspectRatio = "9:16" | "16:9";
|
|
115
133
|
|
|
116
134
|
export interface SlopVideoOptions {
|
|
@@ -133,11 +151,6 @@ export interface SlopVideoOptions {
|
|
|
133
151
|
* Common values: "1:1", "16:9", "9:16", "4:3", "3:4".
|
|
134
152
|
*/
|
|
135
153
|
aspectRatio?: VideoAspectRatio;
|
|
136
|
-
/**
|
|
137
|
-
* The AI model to use for generation.
|
|
138
|
-
* Overrides the default model specified in the bucket settings.
|
|
139
|
-
*/
|
|
140
|
-
model?: string;
|
|
141
154
|
/**
|
|
142
155
|
* Dynamic variables to interpolate into the prompt.
|
|
143
156
|
* E.g., if prompt is "A video of a {color} dog", pass { color: "brown" }.
|
|
@@ -161,13 +174,18 @@ export interface SlopVideoOptions {
|
|
|
161
174
|
baseUrl?: string;
|
|
162
175
|
}
|
|
163
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Builds a URL to render or retrieve a video from Slop Machine.
|
|
179
|
+
*
|
|
180
|
+
* @param options - Configuration options for the video generation.
|
|
181
|
+
* @returns A string containing the fully constructed URL.
|
|
182
|
+
*/
|
|
164
183
|
export function buildVideoUrl(options: SlopVideoOptions): string {
|
|
165
184
|
const {
|
|
166
185
|
bucketId,
|
|
167
186
|
version,
|
|
168
187
|
resultId,
|
|
169
188
|
aspectRatio = "16:9",
|
|
170
|
-
model,
|
|
171
189
|
quality = "fast",
|
|
172
190
|
variables = {},
|
|
173
191
|
duration = 4,
|
|
@@ -177,29 +195,52 @@ export function buildVideoUrl(options: SlopVideoOptions): string {
|
|
|
177
195
|
const params = new URLSearchParams();
|
|
178
196
|
params.set("bucketId", bucketId);
|
|
179
197
|
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
|
|
198
|
+
if (!resultId) {
|
|
199
|
+
if (aspectRatio) {
|
|
200
|
+
params.set("aspectRatio", aspectRatio);
|
|
201
|
+
}
|
|
202
|
+
if (version) {
|
|
203
|
+
params.set("version", String(version));
|
|
204
|
+
}
|
|
205
|
+
if (duration) {
|
|
206
|
+
params.set("duration", String(duration));
|
|
207
|
+
}
|
|
208
|
+
if (quality) {
|
|
209
|
+
params.set("quality", quality);
|
|
210
|
+
}
|
|
183
211
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (version) {
|
|
188
|
-
params.set("version", String(version));
|
|
189
|
-
}
|
|
190
|
-
if (resultId) {
|
|
191
|
-
params.set("resultId", resultId);
|
|
212
|
+
if (Object.keys(variables).length > 0) {
|
|
213
|
+
params.set("variables", JSON.stringify(variables));
|
|
214
|
+
}
|
|
192
215
|
} else {
|
|
193
|
-
params.set("
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (Object.keys(variables).length > 0) {
|
|
197
|
-
params.set("variables", JSON.stringify(variables));
|
|
216
|
+
params.set("resultId", resultId);
|
|
198
217
|
}
|
|
199
218
|
|
|
200
219
|
return `${baseUrl}?${params.toString()}`;
|
|
201
220
|
}
|
|
202
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Preloads a video from Slop Machine into the browser's cache.
|
|
224
|
+
* Useful for ensuring videos are ready before displaying them.
|
|
225
|
+
*
|
|
226
|
+
* @param options - Configuration options for the video generation.
|
|
227
|
+
* @returns A promise that resolves when the video preload request has been initiated.
|
|
228
|
+
*/
|
|
229
|
+
export function preloadVideo(options: SlopVideoOptions): Promise<void> {
|
|
230
|
+
return new Promise((resolve, reject) => {
|
|
231
|
+
if (typeof window === "undefined") {
|
|
232
|
+
resolve();
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// We can just fetch the URL to preload it into the browser's cache.
|
|
237
|
+
// We use no-cors to avoid CORS errors for simple preloads
|
|
238
|
+
fetch(buildVideoUrl(options), { mode: "no-cors" })
|
|
239
|
+
.then(() => resolve())
|
|
240
|
+
.catch((err) => reject(err));
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
203
244
|
export interface SlopTextOptions {
|
|
204
245
|
/**
|
|
205
246
|
* The unique identifier of your Slop Machine bucket.
|
|
@@ -215,11 +256,6 @@ export interface SlopTextOptions {
|
|
|
215
256
|
* instead of generating a new one.
|
|
216
257
|
*/
|
|
217
258
|
resultId?: string;
|
|
218
|
-
/**
|
|
219
|
-
* The AI model to use for generation.
|
|
220
|
-
* Overrides the default model specified in the bucket settings.
|
|
221
|
-
*/
|
|
222
|
-
model?: string;
|
|
223
259
|
/**
|
|
224
260
|
* Dynamic variables to interpolate into the prompt.
|
|
225
261
|
* E.g., if prompt is "A story about a {color} dog", pass { color: "brown" }.
|
|
@@ -232,12 +268,17 @@ export interface SlopTextOptions {
|
|
|
232
268
|
baseUrl?: string;
|
|
233
269
|
}
|
|
234
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Builds a URL to render or retrieve text from Slop Machine.
|
|
273
|
+
*
|
|
274
|
+
* @param options - Configuration options for the text generation.
|
|
275
|
+
* @returns A string containing the fully constructed URL.
|
|
276
|
+
*/
|
|
235
277
|
export function buildTextUrl(options: SlopTextOptions): string {
|
|
236
278
|
const {
|
|
237
279
|
bucketId,
|
|
238
280
|
version,
|
|
239
281
|
resultId,
|
|
240
|
-
model,
|
|
241
282
|
variables = {},
|
|
242
283
|
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText",
|
|
243
284
|
} = options;
|
|
@@ -245,19 +286,42 @@ export function buildTextUrl(options: SlopTextOptions): string {
|
|
|
245
286
|
const params = new URLSearchParams();
|
|
246
287
|
params.set("bucketId", bucketId);
|
|
247
288
|
|
|
248
|
-
if (
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
params.set("resultId", resultId);
|
|
256
|
-
}
|
|
289
|
+
if (!resultId) {
|
|
290
|
+
if (version) {
|
|
291
|
+
params.set("version", String(version));
|
|
292
|
+
}
|
|
293
|
+
if (resultId) {
|
|
294
|
+
params.set("resultId", resultId);
|
|
295
|
+
}
|
|
257
296
|
|
|
258
|
-
|
|
259
|
-
|
|
297
|
+
if (Object.keys(variables).length > 0) {
|
|
298
|
+
params.set("variables", JSON.stringify(variables));
|
|
299
|
+
}
|
|
300
|
+
} else {
|
|
301
|
+
params.set("resultId", resultId);
|
|
260
302
|
}
|
|
261
303
|
|
|
262
304
|
return `${baseUrl}?${params.toString()}`;
|
|
263
305
|
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Preloads text from Slop Machine into the browser's cache.
|
|
309
|
+
* Useful for ensuring text is ready before displaying it.
|
|
310
|
+
*
|
|
311
|
+
* @param options - Configuration options for the text generation.
|
|
312
|
+
* @returns A promise that resolves when the text preload request has been initiated.
|
|
313
|
+
*/
|
|
314
|
+
export function preloadText(options: SlopTextOptions): Promise<void> {
|
|
315
|
+
return new Promise((resolve, reject) => {
|
|
316
|
+
if (typeof window === "undefined") {
|
|
317
|
+
resolve();
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Fetch the URL to preload it into the browser's cache.
|
|
322
|
+
// We use no-cors to avoid CORS errors for simple preloads
|
|
323
|
+
fetch(buildTextUrl(options), { mode: "no-cors" })
|
|
324
|
+
.then(() => resolve())
|
|
325
|
+
.catch((err) => reject(err));
|
|
326
|
+
});
|
|
327
|
+
}
|