@slopmachine/core 0.1.15 → 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 +43 -1
- package/dist/index.d.ts +43 -1
- package/dist/index.js +38 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +83 -0
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,7 +105,21 @@ 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>;
|
|
95
123
|
interface SlopTextOptions {
|
|
96
124
|
/**
|
|
97
125
|
* The unique identifier of your Slop Machine bucket.
|
|
@@ -123,6 +151,20 @@ interface SlopTextOptions {
|
|
|
123
151
|
*/
|
|
124
152
|
baseUrl?: string;
|
|
125
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
|
+
*/
|
|
126
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>;
|
|
127
169
|
|
|
128
|
-
export { type ImageAspectRatio, type SlopImageOptions, type SlopTextOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildTextUrl, 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,7 +105,21 @@ 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>;
|
|
95
123
|
interface SlopTextOptions {
|
|
96
124
|
/**
|
|
97
125
|
* The unique identifier of your Slop Machine bucket.
|
|
@@ -123,6 +151,20 @@ interface SlopTextOptions {
|
|
|
123
151
|
*/
|
|
124
152
|
baseUrl?: string;
|
|
125
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
|
+
*/
|
|
126
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>;
|
|
127
169
|
|
|
128
|
-
export { type ImageAspectRatio, type SlopImageOptions, type SlopTextOptions, type SlopVideoOptions, type VideoAspectRatio, buildImageUrl, buildTextUrl, 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
|
@@ -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) {
|
|
@@ -73,6 +76,18 @@ function buildImageUrl(options) {
|
|
|
73
76
|
}
|
|
74
77
|
return `${baseUrl}?${params.toString()}`;
|
|
75
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
|
+
}
|
|
76
91
|
function buildVideoUrl(options) {
|
|
77
92
|
const {
|
|
78
93
|
bucketId,
|
|
@@ -106,6 +121,15 @@ function buildVideoUrl(options) {
|
|
|
106
121
|
}
|
|
107
122
|
return `${baseUrl}?${params.toString()}`;
|
|
108
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
|
+
}
|
|
109
133
|
function buildTextUrl(options) {
|
|
110
134
|
const {
|
|
111
135
|
bucketId,
|
|
@@ -131,11 +155,23 @@ function buildTextUrl(options) {
|
|
|
131
155
|
}
|
|
132
156
|
return `${baseUrl}?${params.toString()}`;
|
|
133
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
|
+
}
|
|
134
167
|
// Annotate the CommonJS export names for ESM import in node:
|
|
135
168
|
0 && (module.exports = {
|
|
136
169
|
buildImageUrl,
|
|
137
170
|
buildTextUrl,
|
|
138
171
|
buildVideoUrl,
|
|
139
|
-
interpolatePrompt
|
|
172
|
+
interpolatePrompt,
|
|
173
|
+
preloadImage,
|
|
174
|
+
preloadText,
|
|
175
|
+
preloadVideo
|
|
140
176
|
});
|
|
141
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 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,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,OAAO;AAAA,EAC/B,WAAW,YAAY,QAAQ;AAC7B,WAAO,IAAI,WAAW,MAAM;AAAA,EAC9B;AAEA,MAAI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AAO,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 * 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,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;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,OAAO;AAAA,EAC/B,WAAW,YAAY,QAAQ;AAC7B,WAAO,IAAI,WAAW,MAAM;AAAA,EAC9B;AAEA,MAAI,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,OAAO,WAAW,aAAa;AACjC,cAAQ;AACR;AAAA,IACF;AAIA,UAAM,cAAc,OAAO,GAAG,EAAE,MAAM,UAAU,CAAC,EAC9C,KAAK,MAAM,QAAQ,CAAC,EACpB,MAAM,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,EAC/B,CAAC;AACH;AAwCO,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;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,
|
|
@@ -79,6 +91,15 @@ function buildVideoUrl(options) {
|
|
|
79
91
|
}
|
|
80
92
|
return `${baseUrl}?${params.toString()}`;
|
|
81
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
|
+
}
|
|
82
103
|
function buildTextUrl(options) {
|
|
83
104
|
const {
|
|
84
105
|
bucketId,
|
|
@@ -104,10 +125,22 @@ function buildTextUrl(options) {
|
|
|
104
125
|
}
|
|
105
126
|
return `${baseUrl}?${params.toString()}`;
|
|
106
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
|
+
}
|
|
107
137
|
export {
|
|
108
138
|
buildImageUrl,
|
|
109
139
|
buildTextUrl,
|
|
110
140
|
buildVideoUrl,
|
|
111
|
-
interpolatePrompt
|
|
141
|
+
interpolatePrompt,
|
|
142
|
+
preloadImage,
|
|
143
|
+
preloadText,
|
|
144
|
+
preloadVideo
|
|
112
145
|
};
|
|
113
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 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()}`;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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,OA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AAA,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slopmachine/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
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
|
@@ -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,
|
|
@@ -200,6 +233,28 @@ export function buildVideoUrl(options: SlopVideoOptions): string {
|
|
|
200
233
|
return `${baseUrl}?${params.toString()}`;
|
|
201
234
|
}
|
|
202
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
|
+
|
|
203
258
|
export interface SlopTextOptions {
|
|
204
259
|
/**
|
|
205
260
|
* The unique identifier of your Slop Machine bucket.
|
|
@@ -232,6 +287,12 @@ export interface SlopTextOptions {
|
|
|
232
287
|
baseUrl?: string;
|
|
233
288
|
}
|
|
234
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
|
+
*/
|
|
235
296
|
export function buildTextUrl(options: SlopTextOptions): string {
|
|
236
297
|
const {
|
|
237
298
|
bucketId,
|
|
@@ -261,3 +322,25 @@ export function buildTextUrl(options: SlopTextOptions): string {
|
|
|
261
322
|
|
|
262
323
|
return `${baseUrl}?${params.toString()}`;
|
|
263
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
|
+
}
|