@slopmachine/core 0.1.14 → 0.1.16
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 +75 -1
- package/dist/index.d.ts +75 -1
- package/dist/index.js +65 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
- package/src/index.ts +145 -7
package/dist/index.d.mts
CHANGED
|
@@ -42,7 +42,21 @@ interface SlopImageOptions {
|
|
|
42
42
|
baseUrl?: string;
|
|
43
43
|
}
|
|
44
44
|
declare function interpolatePrompt(prompt?: string, variables?: Record<string, string | number | undefined | null>): string;
|
|
45
|
+
/**
|
|
46
|
+
* Builds a URL to render or retrieve an image from Slop Machine.
|
|
47
|
+
*
|
|
48
|
+
* @param options - Configuration options for the image generation.
|
|
49
|
+
* @returns A string containing the fully constructed URL.
|
|
50
|
+
*/
|
|
45
51
|
declare function buildImageUrl(options: SlopImageOptions): string;
|
|
52
|
+
/**
|
|
53
|
+
* Preloads an image from Slop Machine into the browser's cache.
|
|
54
|
+
* Useful for ensuring images are ready before displaying them.
|
|
55
|
+
*
|
|
56
|
+
* @param options - Configuration options for the image generation.
|
|
57
|
+
* @returns A promise that resolves when the image has been loaded.
|
|
58
|
+
*/
|
|
59
|
+
declare function preloadImage(options: SlopImageOptions): Promise<void>;
|
|
46
60
|
type VideoAspectRatio = "9:16" | "16:9";
|
|
47
61
|
interface SlopVideoOptions {
|
|
48
62
|
/**
|
|
@@ -91,6 +105,66 @@ interface SlopVideoOptions {
|
|
|
91
105
|
*/
|
|
92
106
|
baseUrl?: string;
|
|
93
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Builds a URL to render or retrieve a video from Slop Machine.
|
|
110
|
+
*
|
|
111
|
+
* @param options - Configuration options for the video generation.
|
|
112
|
+
* @returns A string containing the fully constructed URL.
|
|
113
|
+
*/
|
|
94
114
|
declare function buildVideoUrl(options: SlopVideoOptions): string;
|
|
115
|
+
/**
|
|
116
|
+
* Preloads a video from Slop Machine into the browser's cache.
|
|
117
|
+
* Useful for ensuring videos are ready before displaying them.
|
|
118
|
+
*
|
|
119
|
+
* @param options - Configuration options for the video generation.
|
|
120
|
+
* @returns A promise that resolves when the video preload request has been initiated.
|
|
121
|
+
*/
|
|
122
|
+
declare function preloadVideo(options: SlopVideoOptions): Promise<void>;
|
|
123
|
+
interface SlopTextOptions {
|
|
124
|
+
/**
|
|
125
|
+
* The unique identifier of your Slop Machine bucket.
|
|
126
|
+
*/
|
|
127
|
+
bucketId: string;
|
|
128
|
+
/**
|
|
129
|
+
* The specific version of the prompt/settings to use.
|
|
130
|
+
* If omitted, the latest version will be used.
|
|
131
|
+
*/
|
|
132
|
+
version?: number;
|
|
133
|
+
/**
|
|
134
|
+
* Result ID to retrieve a specific previously generated text
|
|
135
|
+
* instead of generating a new one.
|
|
136
|
+
*/
|
|
137
|
+
resultId?: string;
|
|
138
|
+
/**
|
|
139
|
+
* The AI model to use for generation.
|
|
140
|
+
* Overrides the default model specified in the bucket settings.
|
|
141
|
+
*/
|
|
142
|
+
model?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Dynamic variables to interpolate into the prompt.
|
|
145
|
+
* E.g., if prompt is "A story about a {color} dog", pass { color: "brown" }.
|
|
146
|
+
*/
|
|
147
|
+
variables?: Record<string, string | number | undefined | null>;
|
|
148
|
+
/**
|
|
149
|
+
* The base URL for the Slop Machine API.
|
|
150
|
+
* Defaults to the production URL. Useful for testing against local deployments.
|
|
151
|
+
*/
|
|
152
|
+
baseUrl?: string;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Builds a URL to render or retrieve text from Slop Machine.
|
|
156
|
+
*
|
|
157
|
+
* @param options - Configuration options for the text generation.
|
|
158
|
+
* @returns A string containing the fully constructed URL.
|
|
159
|
+
*/
|
|
160
|
+
declare function buildTextUrl(options: SlopTextOptions): string;
|
|
161
|
+
/**
|
|
162
|
+
* Preloads text from Slop Machine into the browser's cache.
|
|
163
|
+
* Useful for ensuring text is ready before displaying it.
|
|
164
|
+
*
|
|
165
|
+
* @param options - Configuration options for the text generation.
|
|
166
|
+
* @returns A promise that resolves when the text preload request has been initiated.
|
|
167
|
+
*/
|
|
168
|
+
declare function preloadText(options: SlopTextOptions): Promise<void>;
|
|
95
169
|
|
|
96
|
-
export { type ImageAspectRatio, type SlopImageOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildVideoUrl, interpolatePrompt };
|
|
170
|
+
export { type ImageAspectRatio, type SlopImageOptions, type SlopTextOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildTextUrl, buildVideoUrl, interpolatePrompt, preloadImage, preloadText, preloadVideo };
|
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,21 @@ interface SlopImageOptions {
|
|
|
42
42
|
baseUrl?: string;
|
|
43
43
|
}
|
|
44
44
|
declare function interpolatePrompt(prompt?: string, variables?: Record<string, string | number | undefined | null>): string;
|
|
45
|
+
/**
|
|
46
|
+
* Builds a URL to render or retrieve an image from Slop Machine.
|
|
47
|
+
*
|
|
48
|
+
* @param options - Configuration options for the image generation.
|
|
49
|
+
* @returns A string containing the fully constructed URL.
|
|
50
|
+
*/
|
|
45
51
|
declare function buildImageUrl(options: SlopImageOptions): string;
|
|
52
|
+
/**
|
|
53
|
+
* Preloads an image from Slop Machine into the browser's cache.
|
|
54
|
+
* Useful for ensuring images are ready before displaying them.
|
|
55
|
+
*
|
|
56
|
+
* @param options - Configuration options for the image generation.
|
|
57
|
+
* @returns A promise that resolves when the image has been loaded.
|
|
58
|
+
*/
|
|
59
|
+
declare function preloadImage(options: SlopImageOptions): Promise<void>;
|
|
46
60
|
type VideoAspectRatio = "9:16" | "16:9";
|
|
47
61
|
interface SlopVideoOptions {
|
|
48
62
|
/**
|
|
@@ -91,6 +105,66 @@ interface SlopVideoOptions {
|
|
|
91
105
|
*/
|
|
92
106
|
baseUrl?: string;
|
|
93
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Builds a URL to render or retrieve a video from Slop Machine.
|
|
110
|
+
*
|
|
111
|
+
* @param options - Configuration options for the video generation.
|
|
112
|
+
* @returns A string containing the fully constructed URL.
|
|
113
|
+
*/
|
|
94
114
|
declare function buildVideoUrl(options: SlopVideoOptions): string;
|
|
115
|
+
/**
|
|
116
|
+
* Preloads a video from Slop Machine into the browser's cache.
|
|
117
|
+
* Useful for ensuring videos are ready before displaying them.
|
|
118
|
+
*
|
|
119
|
+
* @param options - Configuration options for the video generation.
|
|
120
|
+
* @returns A promise that resolves when the video preload request has been initiated.
|
|
121
|
+
*/
|
|
122
|
+
declare function preloadVideo(options: SlopVideoOptions): Promise<void>;
|
|
123
|
+
interface SlopTextOptions {
|
|
124
|
+
/**
|
|
125
|
+
* The unique identifier of your Slop Machine bucket.
|
|
126
|
+
*/
|
|
127
|
+
bucketId: string;
|
|
128
|
+
/**
|
|
129
|
+
* The specific version of the prompt/settings to use.
|
|
130
|
+
* If omitted, the latest version will be used.
|
|
131
|
+
*/
|
|
132
|
+
version?: number;
|
|
133
|
+
/**
|
|
134
|
+
* Result ID to retrieve a specific previously generated text
|
|
135
|
+
* instead of generating a new one.
|
|
136
|
+
*/
|
|
137
|
+
resultId?: string;
|
|
138
|
+
/**
|
|
139
|
+
* The AI model to use for generation.
|
|
140
|
+
* Overrides the default model specified in the bucket settings.
|
|
141
|
+
*/
|
|
142
|
+
model?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Dynamic variables to interpolate into the prompt.
|
|
145
|
+
* E.g., if prompt is "A story about a {color} dog", pass { color: "brown" }.
|
|
146
|
+
*/
|
|
147
|
+
variables?: Record<string, string | number | undefined | null>;
|
|
148
|
+
/**
|
|
149
|
+
* The base URL for the Slop Machine API.
|
|
150
|
+
* Defaults to the production URL. Useful for testing against local deployments.
|
|
151
|
+
*/
|
|
152
|
+
baseUrl?: string;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Builds a URL to render or retrieve text from Slop Machine.
|
|
156
|
+
*
|
|
157
|
+
* @param options - Configuration options for the text generation.
|
|
158
|
+
* @returns A string containing the fully constructed URL.
|
|
159
|
+
*/
|
|
160
|
+
declare function buildTextUrl(options: SlopTextOptions): string;
|
|
161
|
+
/**
|
|
162
|
+
* Preloads text from Slop Machine into the browser's cache.
|
|
163
|
+
* Useful for ensuring text is ready before displaying it.
|
|
164
|
+
*
|
|
165
|
+
* @param options - Configuration options for the text generation.
|
|
166
|
+
* @returns A promise that resolves when the text preload request has been initiated.
|
|
167
|
+
*/
|
|
168
|
+
declare function preloadText(options: SlopTextOptions): Promise<void>;
|
|
95
169
|
|
|
96
|
-
export { type ImageAspectRatio, type SlopImageOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildVideoUrl, interpolatePrompt };
|
|
170
|
+
export { type ImageAspectRatio, type SlopImageOptions, type SlopTextOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildTextUrl, buildVideoUrl, interpolatePrompt, preloadImage, preloadText, preloadVideo };
|
package/dist/index.js
CHANGED
|
@@ -21,8 +21,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
buildImageUrl: () => buildImageUrl,
|
|
24
|
+
buildTextUrl: () => buildTextUrl,
|
|
24
25
|
buildVideoUrl: () => buildVideoUrl,
|
|
25
|
-
interpolatePrompt: () => interpolatePrompt
|
|
26
|
+
interpolatePrompt: () => interpolatePrompt,
|
|
27
|
+
preloadImage: () => preloadImage,
|
|
28
|
+
preloadText: () => preloadText,
|
|
29
|
+
preloadVideo: () => preloadVideo
|
|
26
30
|
});
|
|
27
31
|
module.exports = __toCommonJS(index_exports);
|
|
28
32
|
function interpolatePrompt(prompt, variables) {
|
|
@@ -72,6 +76,18 @@ function buildImageUrl(options) {
|
|
|
72
76
|
}
|
|
73
77
|
return `${baseUrl}?${params.toString()}`;
|
|
74
78
|
}
|
|
79
|
+
function preloadImage(options) {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
if (typeof window === "undefined") {
|
|
82
|
+
resolve();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const img = new Image();
|
|
86
|
+
img.onload = () => resolve();
|
|
87
|
+
img.onerror = (err) => reject(err);
|
|
88
|
+
img.src = buildImageUrl(options);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
75
91
|
function buildVideoUrl(options) {
|
|
76
92
|
const {
|
|
77
93
|
bucketId,
|
|
@@ -98,12 +114,6 @@ function buildVideoUrl(options) {
|
|
|
98
114
|
if (resultId) {
|
|
99
115
|
params.set("resultId", resultId);
|
|
100
116
|
} else {
|
|
101
|
-
const clampedDuration = Math.max(4, Math.min(8, duration));
|
|
102
|
-
params.set("duration", String(clampedDuration));
|
|
103
|
-
}
|
|
104
|
-
if (quality && quality !== "fast") {
|
|
105
|
-
params.set("quality", quality);
|
|
106
|
-
} else if (quality === "fast") {
|
|
107
117
|
params.set("quality", "fast");
|
|
108
118
|
}
|
|
109
119
|
if (Object.keys(variables).length > 0) {
|
|
@@ -111,10 +121,57 @@ function buildVideoUrl(options) {
|
|
|
111
121
|
}
|
|
112
122
|
return `${baseUrl}?${params.toString()}`;
|
|
113
123
|
}
|
|
124
|
+
function preloadVideo(options) {
|
|
125
|
+
return new Promise((resolve, reject) => {
|
|
126
|
+
if (typeof window === "undefined") {
|
|
127
|
+
resolve();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
fetch(buildVideoUrl(options), { mode: "no-cors" }).then(() => resolve()).catch((err) => reject(err));
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function buildTextUrl(options) {
|
|
134
|
+
const {
|
|
135
|
+
bucketId,
|
|
136
|
+
version,
|
|
137
|
+
resultId,
|
|
138
|
+
model,
|
|
139
|
+
variables = {},
|
|
140
|
+
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText"
|
|
141
|
+
} = options;
|
|
142
|
+
const params = new URLSearchParams();
|
|
143
|
+
params.set("bucketId", bucketId);
|
|
144
|
+
if (model) {
|
|
145
|
+
params.set("model", model);
|
|
146
|
+
}
|
|
147
|
+
if (version) {
|
|
148
|
+
params.set("version", String(version));
|
|
149
|
+
}
|
|
150
|
+
if (resultId) {
|
|
151
|
+
params.set("resultId", resultId);
|
|
152
|
+
}
|
|
153
|
+
if (Object.keys(variables).length > 0) {
|
|
154
|
+
params.set("variables", JSON.stringify(variables));
|
|
155
|
+
}
|
|
156
|
+
return `${baseUrl}?${params.toString()}`;
|
|
157
|
+
}
|
|
158
|
+
function preloadText(options) {
|
|
159
|
+
return new Promise((resolve, reject) => {
|
|
160
|
+
if (typeof window === "undefined") {
|
|
161
|
+
resolve();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
fetch(buildTextUrl(options), { mode: "no-cors" }).then(() => resolve()).catch((err) => reject(err));
|
|
165
|
+
});
|
|
166
|
+
}
|
|
114
167
|
// Annotate the CommonJS export names for ESM import in node:
|
|
115
168
|
0 && (module.exports = {
|
|
116
169
|
buildImageUrl,
|
|
170
|
+
buildTextUrl,
|
|
117
171
|
buildVideoUrl,
|
|
118
|
-
interpolatePrompt
|
|
172
|
+
interpolatePrompt,
|
|
173
|
+
preloadImage,
|
|
174
|
+
preloadText,
|
|
175
|
+
preloadVideo
|
|
119
176
|
});
|
|
120
177
|
//# 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 // Only append duration if resultId is NOT provided\n const clampedDuration = Math.max(4, Math.min(8, duration));\n params.set(\"duration\", String(clampedDuration));\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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,aAAa;AACf,WAAO,IAAI,eAAe,WAAW;AAAA,EACvC;AAEA,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;AACA,MAAI,WAAW,YAAY,QAAQ;AACjC,WAAO,IAAI,WAAW,O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Content":["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\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 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\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 * 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\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 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\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 * 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\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 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\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;AAuDO,SAAS,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ACJ;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;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
|
@@ -46,6 +46,18 @@ function buildImageUrl(options) {
|
|
|
46
46
|
}
|
|
47
47
|
return `${baseUrl}?${params.toString()}`;
|
|
48
48
|
}
|
|
49
|
+
function preloadImage(options) {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
if (typeof window === "undefined") {
|
|
52
|
+
resolve();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const img = new Image();
|
|
56
|
+
img.onload = () => resolve();
|
|
57
|
+
img.onerror = (err) => reject(err);
|
|
58
|
+
img.src = buildImageUrl(options);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
49
61
|
function buildVideoUrl(options) {
|
|
50
62
|
const {
|
|
51
63
|
bucketId,
|
|
@@ -72,12 +84,6 @@ function buildVideoUrl(options) {
|
|
|
72
84
|
if (resultId) {
|
|
73
85
|
params.set("resultId", resultId);
|
|
74
86
|
} else {
|
|
75
|
-
const clampedDuration = Math.max(4, Math.min(8, duration));
|
|
76
|
-
params.set("duration", String(clampedDuration));
|
|
77
|
-
}
|
|
78
|
-
if (quality && quality !== "fast") {
|
|
79
|
-
params.set("quality", quality);
|
|
80
|
-
} else if (quality === "fast") {
|
|
81
87
|
params.set("quality", "fast");
|
|
82
88
|
}
|
|
83
89
|
if (Object.keys(variables).length > 0) {
|
|
@@ -85,9 +91,56 @@ function buildVideoUrl(options) {
|
|
|
85
91
|
}
|
|
86
92
|
return `${baseUrl}?${params.toString()}`;
|
|
87
93
|
}
|
|
94
|
+
function preloadVideo(options) {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
if (typeof window === "undefined") {
|
|
97
|
+
resolve();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
fetch(buildVideoUrl(options), { mode: "no-cors" }).then(() => resolve()).catch((err) => reject(err));
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function buildTextUrl(options) {
|
|
104
|
+
const {
|
|
105
|
+
bucketId,
|
|
106
|
+
version,
|
|
107
|
+
resultId,
|
|
108
|
+
model,
|
|
109
|
+
variables = {},
|
|
110
|
+
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText"
|
|
111
|
+
} = options;
|
|
112
|
+
const params = new URLSearchParams();
|
|
113
|
+
params.set("bucketId", bucketId);
|
|
114
|
+
if (model) {
|
|
115
|
+
params.set("model", model);
|
|
116
|
+
}
|
|
117
|
+
if (version) {
|
|
118
|
+
params.set("version", String(version));
|
|
119
|
+
}
|
|
120
|
+
if (resultId) {
|
|
121
|
+
params.set("resultId", resultId);
|
|
122
|
+
}
|
|
123
|
+
if (Object.keys(variables).length > 0) {
|
|
124
|
+
params.set("variables", JSON.stringify(variables));
|
|
125
|
+
}
|
|
126
|
+
return `${baseUrl}?${params.toString()}`;
|
|
127
|
+
}
|
|
128
|
+
function preloadText(options) {
|
|
129
|
+
return new Promise((resolve, reject) => {
|
|
130
|
+
if (typeof window === "undefined") {
|
|
131
|
+
resolve();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
fetch(buildTextUrl(options), { mode: "no-cors" }).then(() => resolve()).catch((err) => reject(err));
|
|
135
|
+
});
|
|
136
|
+
}
|
|
88
137
|
export {
|
|
89
138
|
buildImageUrl,
|
|
139
|
+
buildTextUrl,
|
|
90
140
|
buildVideoUrl,
|
|
91
|
-
interpolatePrompt
|
|
141
|
+
interpolatePrompt,
|
|
142
|
+
preloadImage,
|
|
143
|
+
preloadText,
|
|
144
|
+
preloadVideo
|
|
92
145
|
};
|
|
93
146
|
//# 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 // Only append duration if resultId is NOT provided\n const clampedDuration = Math.max(4, Math.min(8, duration));\n params.set(\"duration\", String(clampedDuration));\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"],"mappings":";AAuDO,SAAS,kBACd,QACA,WACQ;AACR,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,OAAO;AACX,MAAI,CAAC,UAA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,IAAI;AAEJ,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,YAAY,QAAQ;AAE/B,MAAI,aAAa;AACf,WAAO,IAAI,eAAe,WAAW;AAAA,EACvC;AAEA,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,OAAO;AAEL,UAAM,kBAAkB,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,QAAQ,CAAC;AACzD,WAAO,IAAI,YAAY,OAAO,eAAe,CAAC;AAAA,EAChD;AACA,MAAI,WAAW,YAAY,QAAQ;AACjC,WAAO,IAAI,WAAW,OAAO;AAAA,EAC/B,WAAW,YAAY,QAAQ;AAC7B,WAAO,IAAI,WAAW,MAAM;AAAA,EAC9B;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 * 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\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 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\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 * 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\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 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\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 * 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\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 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\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":";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;AAQO,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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,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/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slopmachine/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
|
+
"description": "The official Core / VanillaJS SDK for Slop Machine",
|
|
5
|
+
"llms": "https://slopmachine-dev.github.io/slopmachine-sdk/llms.txt",
|
|
6
|
+
"llmsFull": "https://slopmachine-dev.github.io/slopmachine-sdk/llms-full.txt",
|
|
4
7
|
"main": "dist/index.js",
|
|
5
8
|
"module": "dist/index.mjs",
|
|
6
9
|
"types": "dist/index.d.ts",
|
package/src/index.ts
CHANGED
|
@@ -70,6 +70,12 @@ export function interpolatePrompt(
|
|
|
70
70
|
return text;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Builds a URL to render or retrieve an image from Slop Machine.
|
|
75
|
+
*
|
|
76
|
+
* @param options - Configuration options for the image generation.
|
|
77
|
+
* @returns A string containing the fully constructed URL.
|
|
78
|
+
*/
|
|
73
79
|
export function buildImageUrl(options: SlopImageOptions): string {
|
|
74
80
|
const {
|
|
75
81
|
bucketId,
|
|
@@ -111,6 +117,27 @@ export function buildImageUrl(options: SlopImageOptions): string {
|
|
|
111
117
|
return `${baseUrl}?${params.toString()}`;
|
|
112
118
|
}
|
|
113
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Preloads an image from Slop Machine into the browser's cache.
|
|
122
|
+
* Useful for ensuring images are ready before displaying them.
|
|
123
|
+
*
|
|
124
|
+
* @param options - Configuration options for the image generation.
|
|
125
|
+
* @returns A promise that resolves when the image has been loaded.
|
|
126
|
+
*/
|
|
127
|
+
export function preloadImage(options: SlopImageOptions): Promise<void> {
|
|
128
|
+
return new Promise((resolve, reject) => {
|
|
129
|
+
if (typeof window === "undefined") {
|
|
130
|
+
resolve();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const img = new Image();
|
|
135
|
+
img.onload = () => resolve();
|
|
136
|
+
img.onerror = (err) => reject(err);
|
|
137
|
+
img.src = buildImageUrl(options);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
114
141
|
export type VideoAspectRatio = "9:16" | "16:9";
|
|
115
142
|
|
|
116
143
|
export interface SlopVideoOptions {
|
|
@@ -161,6 +188,12 @@ export interface SlopVideoOptions {
|
|
|
161
188
|
baseUrl?: string;
|
|
162
189
|
}
|
|
163
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Builds a URL to render or retrieve a video from Slop Machine.
|
|
193
|
+
*
|
|
194
|
+
* @param options - Configuration options for the video generation.
|
|
195
|
+
* @returns A string containing the fully constructed URL.
|
|
196
|
+
*/
|
|
164
197
|
export function buildVideoUrl(options: SlopVideoOptions): string {
|
|
165
198
|
const {
|
|
166
199
|
bucketId,
|
|
@@ -190,13 +223,6 @@ export function buildVideoUrl(options: SlopVideoOptions): string {
|
|
|
190
223
|
if (resultId) {
|
|
191
224
|
params.set("resultId", resultId);
|
|
192
225
|
} else {
|
|
193
|
-
// Only append duration if resultId is NOT provided
|
|
194
|
-
const clampedDuration = Math.max(4, Math.min(8, duration));
|
|
195
|
-
params.set("duration", String(clampedDuration));
|
|
196
|
-
}
|
|
197
|
-
if (quality && quality !== "fast") {
|
|
198
|
-
params.set("quality", quality);
|
|
199
|
-
} else if (quality === "fast") {
|
|
200
226
|
params.set("quality", "fast");
|
|
201
227
|
}
|
|
202
228
|
|
|
@@ -206,3 +232,115 @@ export function buildVideoUrl(options: SlopVideoOptions): string {
|
|
|
206
232
|
|
|
207
233
|
return `${baseUrl}?${params.toString()}`;
|
|
208
234
|
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Preloads a video from Slop Machine into the browser's cache.
|
|
238
|
+
* Useful for ensuring videos are ready before displaying them.
|
|
239
|
+
*
|
|
240
|
+
* @param options - Configuration options for the video generation.
|
|
241
|
+
* @returns A promise that resolves when the video preload request has been initiated.
|
|
242
|
+
*/
|
|
243
|
+
export function preloadVideo(options: SlopVideoOptions): Promise<void> {
|
|
244
|
+
return new Promise((resolve, reject) => {
|
|
245
|
+
if (typeof window === "undefined") {
|
|
246
|
+
resolve();
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// We can just fetch the URL to preload it into the browser's cache.
|
|
251
|
+
// We use no-cors to avoid CORS errors for simple preloads
|
|
252
|
+
fetch(buildVideoUrl(options), { mode: "no-cors" })
|
|
253
|
+
.then(() => resolve())
|
|
254
|
+
.catch((err) => reject(err));
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface SlopTextOptions {
|
|
259
|
+
/**
|
|
260
|
+
* The unique identifier of your Slop Machine bucket.
|
|
261
|
+
*/
|
|
262
|
+
bucketId: string;
|
|
263
|
+
/**
|
|
264
|
+
* The specific version of the prompt/settings to use.
|
|
265
|
+
* If omitted, the latest version will be used.
|
|
266
|
+
*/
|
|
267
|
+
version?: number;
|
|
268
|
+
/**
|
|
269
|
+
* Result ID to retrieve a specific previously generated text
|
|
270
|
+
* instead of generating a new one.
|
|
271
|
+
*/
|
|
272
|
+
resultId?: string;
|
|
273
|
+
/**
|
|
274
|
+
* The AI model to use for generation.
|
|
275
|
+
* Overrides the default model specified in the bucket settings.
|
|
276
|
+
*/
|
|
277
|
+
model?: string;
|
|
278
|
+
/**
|
|
279
|
+
* Dynamic variables to interpolate into the prompt.
|
|
280
|
+
* E.g., if prompt is "A story about a {color} dog", pass { color: "brown" }.
|
|
281
|
+
*/
|
|
282
|
+
variables?: Record<string, string | number | undefined | null>;
|
|
283
|
+
/**
|
|
284
|
+
* The base URL for the Slop Machine API.
|
|
285
|
+
* Defaults to the production URL. Useful for testing against local deployments.
|
|
286
|
+
*/
|
|
287
|
+
baseUrl?: string;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Builds a URL to render or retrieve text from Slop Machine.
|
|
292
|
+
*
|
|
293
|
+
* @param options - Configuration options for the text generation.
|
|
294
|
+
* @returns A string containing the fully constructed URL.
|
|
295
|
+
*/
|
|
296
|
+
export function buildTextUrl(options: SlopTextOptions): string {
|
|
297
|
+
const {
|
|
298
|
+
bucketId,
|
|
299
|
+
version,
|
|
300
|
+
resultId,
|
|
301
|
+
model,
|
|
302
|
+
variables = {},
|
|
303
|
+
baseUrl = "https://us-central1-slopmachine-12bfb.cloudfunctions.net/renderText",
|
|
304
|
+
} = options;
|
|
305
|
+
|
|
306
|
+
const params = new URLSearchParams();
|
|
307
|
+
params.set("bucketId", bucketId);
|
|
308
|
+
|
|
309
|
+
if (model) {
|
|
310
|
+
params.set("model", model);
|
|
311
|
+
}
|
|
312
|
+
if (version) {
|
|
313
|
+
params.set("version", String(version));
|
|
314
|
+
}
|
|
315
|
+
if (resultId) {
|
|
316
|
+
params.set("resultId", resultId);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (Object.keys(variables).length > 0) {
|
|
320
|
+
params.set("variables", JSON.stringify(variables));
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return `${baseUrl}?${params.toString()}`;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Preloads text from Slop Machine into the browser's cache.
|
|
328
|
+
* Useful for ensuring text is ready before displaying it.
|
|
329
|
+
*
|
|
330
|
+
* @param options - Configuration options for the text generation.
|
|
331
|
+
* @returns A promise that resolves when the text preload request has been initiated.
|
|
332
|
+
*/
|
|
333
|
+
export function preloadText(options: SlopTextOptions): Promise<void> {
|
|
334
|
+
return new Promise((resolve, reject) => {
|
|
335
|
+
if (typeof window === "undefined") {
|
|
336
|
+
resolve();
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Fetch the URL to preload it into the browser's cache.
|
|
341
|
+
// We use no-cors to avoid CORS errors for simple preloads
|
|
342
|
+
fetch(buildTextUrl(options), { mode: "no-cors" })
|
|
343
|
+
.then(() => resolve())
|
|
344
|
+
.catch((err) => reject(err));
|
|
345
|
+
});
|
|
346
|
+
}
|