comfy-ts 2.21.0 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/{ServeApp-ByMobrWW.js → ServeApp-DuxYdaZZ.js} +142 -7
  2. package/dist/ServeApp-DuxYdaZZ.js.map +1 -0
  3. package/dist/cli.js +5 -5
  4. package/dist/{exampleAssets-B5sMqNia.js → exampleAssets-1NHndnNB.js} +4 -17
  5. package/dist/exampleAssets-1NHndnNB.js.map +1 -0
  6. package/dist/{findDefinedWorkflow-BNZgYIww.js → findDefinedWorkflow-CRsBTTJK.js} +2 -2
  7. package/dist/{findDefinedWorkflow-BNZgYIww.js.map → findDefinedWorkflow-CRsBTTJK.js.map} +1 -1
  8. package/dist/index.cjs +32 -1
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +71 -6
  11. package/dist/index.d.ts +71 -6
  12. package/dist/index.js +31 -2
  13. package/dist/index.js.map +1 -1
  14. package/dist/{run-run-CuBSygku.js → run-run-Y5ZI48vV.js} +5 -5
  15. package/dist/{run-run-CuBSygku.js.map → run-run-Y5ZI48vV.js.map} +1 -1
  16. package/dist/{run-serve-COk_G0Qz.js → run-serve-CICU_wTL.js} +4 -4
  17. package/dist/{run-serve-COk_G0Qz.js.map → run-serve-CICU_wTL.js.map} +1 -1
  18. package/dist/{run-tui-CB6i_x2y.js → run-tui-CViJXsHL.js} +4 -4
  19. package/dist/{run-tui-CB6i_x2y.js.map → run-tui-CViJXsHL.js.map} +1 -1
  20. package/dist/{schemaDrift-CHDVYlaj.js → schemaDrift-CzjaIwZX.js} +22 -2
  21. package/dist/schemaDrift-CzjaIwZX.js.map +1 -0
  22. package/dist/serve-web.js +204 -47
  23. package/dist/web.d.ts +71 -6
  24. package/dist/web.js +31 -2
  25. package/dist/web.js.map +1 -1
  26. package/examples/README.md +2 -0
  27. package/examples/depth-explorer/models.ts +722 -0
  28. package/examples/depth-explorer/serve.ts +140 -0
  29. package/examples/depth-explorer/thumbs/bae.webp +0 -0
  30. package/examples/depth-explorer/thumbs/da3-mono-large.webp +0 -0
  31. package/examples/depth-explorer/thumbs/dav1-vitl.webp +0 -0
  32. package/examples/depth-explorer/thumbs/dav2-vitl.webp +0 -0
  33. package/examples/depth-explorer/thumbs/dsine.webp +0 -0
  34. package/examples/depth-explorer/thumbs/iid-albedo.webp +0 -0
  35. package/examples/depth-explorer/thumbs/iid-metalness.webp +0 -0
  36. package/examples/depth-explorer/thumbs/iid-roughness.webp +0 -0
  37. package/examples/depth-explorer/thumbs/iid-shading.webp +0 -0
  38. package/examples/depth-explorer/thumbs/iid-specular.webp +0 -0
  39. package/examples/depth-explorer/thumbs/leres.webp +0 -0
  40. package/examples/depth-explorer/thumbs/lotus-depth.webp +0 -0
  41. package/examples/depth-explorer/thumbs/marigold2-albedo.webp +0 -0
  42. package/examples/depth-explorer/thumbs/marigold2-depth.webp +0 -0
  43. package/examples/depth-explorer/thumbs/marigold2-normal.webp +0 -0
  44. package/examples/depth-explorer/thumbs/metric3d-depth.webp +0 -0
  45. package/examples/depth-explorer/thumbs/metric3d-normal.webp +0 -0
  46. package/examples/depth-explorer/thumbs/midas-normal.webp +0 -0
  47. package/examples/depth-explorer/thumbs/midas.webp +0 -0
  48. package/examples/depth-explorer/thumbs/moge2-depth.webp +0 -0
  49. package/examples/depth-explorer/thumbs/moge2-normal.webp +0 -0
  50. package/examples/depth-explorer/thumbs/zoe-da.webp +0 -0
  51. package/examples/depth-explorer/thumbs/zoe.webp +0 -0
  52. package/examples/depth-explorer/web/App.tsx +457 -0
  53. package/examples/depth-explorer/web/gl.ts +202 -0
  54. package/examples/depth-explorer/web/index.html +14 -0
  55. package/examples/depth-explorer/web/main.tsx +19 -0
  56. package/examples/depth-explorer/web/pixels.ts +86 -0
  57. package/examples/depth-explorer/web/state.ts +329 -0
  58. package/examples/depth-explorer/web/styles.css +366 -0
  59. package/examples/depth-explorer/web/tsconfig.json +16 -0
  60. package/examples/rvion/17-relight.cflow.ts +110 -0
  61. package/package.json +3 -2
  62. package/src/cli/serve/ServeApp.ts +79 -4
  63. package/src/cli/serve/describeVar.ts +12 -1
  64. package/src/cli/serve/resultHistory.ts +6 -1
  65. package/src/cli/serve/thumbs.ts +66 -0
  66. package/src/cli/serve/web/api.ts +5 -1
  67. package/src/cli/serve/web/components/Gallery.tsx +2 -0
  68. package/src/cli/serve/web/components/controls/BasicControls.tsx +14 -17
  69. package/src/cli/serve/web/components/controls/MediaControl.tsx +62 -9
  70. package/src/cli/serve/web/components/controls/RichSelect.tsx +262 -0
  71. package/src/cli/serve/web/state/RunSt.poll.test.ts +4 -1
  72. package/src/cli/serve/web/state/choiceButtons.ts +26 -2
  73. package/src/cli/serve/web/styles.ts +39 -0
  74. package/src/cli/serve/web/widgets/OutputWidgets.tsx +19 -0
  75. package/src/cli/serve/web/widgets/RelightSt.ts +113 -0
  76. package/src/cli/serve/web/widgets/RelightWidget.tsx +305 -0
  77. package/src/cli/serve/web/widgets/relightGl.ts +305 -0
  78. package/src/cli/serve/web/widgets/widgetStyles.ts +19 -0
  79. package/src/coreExports.ts +9 -0
  80. package/src/vars/ComfyVars.ts +32 -2
  81. package/src/vars/DefinedWorkflow.ts +4 -0
  82. package/src/vars/outputWidgets.ts +47 -0
  83. package/dist/ServeApp-ByMobrWW.js.map +0 -1
  84. package/dist/exampleAssets-B5sMqNia.js.map +0 -1
  85. package/dist/schemaDrift-CHDVYlaj.js.map +0 -1
@@ -0,0 +1,305 @@
1
+ // the relight renderer, raw WebGL2: one full quad, every pixel lit at its 3D position
2
+ // P = (x · aspect, y, depth · depthScale) (near = white in the depth map)
3
+ // by a point light and up to MAX_MOTES drifting light motes. Normals from the normal map (OpenGL,
4
+ // green up), else from the depth gradient. Shadows: a short march through the depth map toward
5
+ // each light. Materials: albedo, roughness, metalness and a specular (non diffuse) map, each
6
+ // optional. Pure renderer: the widget state owns every parameter.
7
+
8
+ export const MAX_MOTES = 16
9
+
10
+ export type RelightMaps = {
11
+ image: TexImageSource
12
+ depth?: TexImageSource
13
+ normal?: TexImageSource
14
+ albedo?: TexImageSource
15
+ roughness?: TexImageSource
16
+ metalness?: TexImageSource
17
+ specular?: TexImageSource
18
+ }
19
+
20
+ export type RelightView = 'lit' | 'albedo' | 'normal' | 'depth' | 'roughness' | 'metalness' | 'specular' | 'shadow'
21
+ export const VIEW_INDEX: Record<RelightView, number> = {
22
+ lit: 0,
23
+ albedo: 1,
24
+ normal: 2,
25
+ depth: 3,
26
+ roughness: 4,
27
+ metalness: 5,
28
+ specular: 6,
29
+ shadow: 7,
30
+ }
31
+
32
+ export type RelightParams = {
33
+ /** light position: x, y in 0..1 over the image (y down), z above the surface, in image heights */
34
+ light: [number, number, number]
35
+ color: [number, number, number]
36
+ intensity: number
37
+ /** distance (image heights) where the light falls to half */
38
+ falloff: number
39
+ /** how much of the original photo stays under the new light */
40
+ ambient: number
41
+ depthScale: number
42
+ shadows: boolean
43
+ /** each mote: x, y, z like the light */
44
+ motes: [number, number, number][]
45
+ moteIntensity: number
46
+ /** draw the light and the motes as glowing blobs */
47
+ showLights: boolean
48
+ view: RelightView
49
+ exposure: number
50
+ }
51
+
52
+ const VS = `#version 300 es
53
+ in vec2 a_uv;
54
+ uniform vec2 u_fit;
55
+ out vec2 v_uv;
56
+ void main() {
57
+ v_uv = a_uv;
58
+ gl_Position = vec4((a_uv.x * 2.0 - 1.0) * u_fit.x, (1.0 - a_uv.y * 2.0) * u_fit.y, 0.0, 1.0);
59
+ }`
60
+
61
+ const FS = `#version 300 es
62
+ precision highp float;
63
+ #define MAX_MOTES ${MAX_MOTES}
64
+ in vec2 v_uv;
65
+ uniform sampler2D u_image, u_depth, u_normal, u_albedo, u_rough, u_metal, u_spec;
66
+ uniform bool u_hasDepth, u_hasNormal, u_hasAlbedo, u_hasRough, u_hasMetal, u_hasSpec;
67
+ uniform float u_aspect, u_depthScale, u_intensity, u_falloff, u_ambient, u_moteIntensity, u_exposure;
68
+ uniform vec3 u_light, u_color;
69
+ uniform bool u_shadows, u_showLights;
70
+ uniform int u_moteCount, u_view;
71
+ uniform vec3 u_motes[MAX_MOTES];
72
+ uniform vec2 u_texel;
73
+ out vec4 o;
74
+
75
+ float depthAt(vec2 uv) { return u_hasDepth ? texture(u_depth, uv).r : 0.5; }
76
+ vec3 posAt(vec2 uv) { return vec3(uv.x * u_aspect, 1.0 - uv.y, depthAt(uv) * u_depthScale); }
77
+ vec3 lightPos(vec3 l) { return vec3(l.x * u_aspect, 1.0 - l.y, l.z); }
78
+
79
+ vec3 normalAt(vec2 uv) {
80
+ if (u_hasNormal) return normalize(texture(u_normal, uv).rgb * 2.0 - 1.0);
81
+ vec3 px = posAt(uv + vec2(u_texel.x, 0.0)) - posAt(uv - vec2(u_texel.x, 0.0));
82
+ vec3 py = posAt(uv - vec2(0.0, u_texel.y)) - posAt(uv + vec2(0.0, u_texel.y));
83
+ return normalize(cross(px, py));
84
+ }
85
+
86
+ /** 1 = lit, 0 = a surface between P and the light */
87
+ float shadow(vec2 uv, vec3 P, vec3 L) {
88
+ if (!u_shadows || !u_hasDepth) return 1.0;
89
+ vec3 d = L - P;
90
+ float occ = 0.0;
91
+ for (int i = 1; i <= 24; i++) {
92
+ float t = float(i) / 24.0;
93
+ vec3 q = P + d * t * 0.9;
94
+ vec2 quv = vec2(q.x / u_aspect, 1.0 - q.y);
95
+ if (quv.x < 0.0 || quv.x > 1.0 || quv.y < 0.0 || quv.y > 1.0) break;
96
+ float h = depthAt(quv) * u_depthScale;
97
+ occ = max(occ, smoothstep(0.004, 0.03, h - q.z));
98
+ }
99
+ return 1.0 - occ;
100
+ }
101
+
102
+ vec3 shade(vec2 uv, vec3 P, vec3 N, vec3 base, float rough, float metal, float specBoost, vec3 Lp, vec3 col, float power) {
103
+ vec3 Lv = Lp - P;
104
+ float dist = length(Lv);
105
+ vec3 L = Lv / dist;
106
+ float att = power / (1.0 + pow(dist / max(u_falloff, 0.01), 2.0));
107
+ float ndl = max(dot(N, L), 0.0);
108
+ vec3 V = vec3(0.0, 0.0, 1.0);
109
+ vec3 H = normalize(L + V);
110
+ float shin = mix(512.0, 6.0, rough);
111
+ float spec = pow(max(dot(N, H), 0.0), shin) * (shin + 8.0) / 25.0;
112
+ vec3 F0 = mix(vec3(0.04), base, metal) * specBoost;
113
+ vec3 diffuse = base * (1.0 - metal) * ndl;
114
+ vec3 specular = F0 * spec * ndl;
115
+ return (diffuse + specular) * col * att * shadow(uv, P, Lp);
116
+ }
117
+
118
+ float glow(vec2 uv, vec3 l, float size) {
119
+ vec2 d = (uv - l.xy) * vec2(u_aspect, 1.0);
120
+ float r = size * (0.6 + 0.6 / (0.3 + l.z));
121
+ return exp(-dot(d, d) / (r * r));
122
+ }
123
+
124
+ void main() {
125
+ vec2 uv = v_uv;
126
+ vec3 photo = texture(u_image, uv).rgb;
127
+ vec3 base = u_hasAlbedo ? texture(u_albedo, uv).rgb : photo;
128
+ float rough = u_hasRough ? texture(u_rough, uv).r : 0.6;
129
+ float metal = u_hasMetal ? texture(u_metal, uv).r : 0.0;
130
+ float specMap = u_hasSpec ? texture(u_spec, uv).r : 0.0;
131
+ vec3 N = normalAt(uv);
132
+ vec3 P = posAt(uv);
133
+
134
+ if (u_view == 1) { o = vec4(base, 1.0); return; }
135
+ if (u_view == 2) { o = vec4(N * 0.5 + 0.5, 1.0); return; }
136
+ if (u_view == 3) { o = vec4(vec3(depthAt(uv)), 1.0); return; }
137
+ if (u_view == 4) { o = vec4(vec3(rough), 1.0); return; }
138
+ if (u_view == 5) { o = vec4(vec3(metal), 1.0); return; }
139
+ if (u_view == 6) { o = vec4(vec3(specMap), 1.0); return; }
140
+ if (u_view == 7) { o = vec4(vec3(shadow(uv, P, lightPos(u_light))), 1.0); return; }
141
+
142
+ float specBoost = u_hasSpec ? 0.6 + specMap * 6.0 : 1.0;
143
+ vec3 c = photo * u_ambient;
144
+ c += shade(uv, P, N, base, rough, metal, specBoost, lightPos(u_light), u_color, u_intensity);
145
+ for (int i = 0; i < MAX_MOTES; i++) {
146
+ if (i >= u_moteCount) break;
147
+ c += shade(uv, P, N, base, rough, metal, specBoost, lightPos(u_motes[i]), u_color, u_moteIntensity);
148
+ }
149
+ c = vec3(1.0) - exp(-c * u_exposure);
150
+ if (u_showLights) {
151
+ c += u_color * glow(uv, u_light, 0.018) * 1.2;
152
+ for (int i = 0; i < MAX_MOTES; i++) {
153
+ if (i >= u_moteCount) break;
154
+ c += u_color * glow(uv, u_motes[i], 0.006) * 0.9;
155
+ }
156
+ }
157
+ o = vec4(c, 1.0);
158
+ }`
159
+
160
+ const SLOTS = ['image', 'depth', 'normal', 'albedo', 'roughness', 'metalness', 'specular'] as const
161
+ type Slot = (typeof SLOTS)[number]
162
+ const SAMPLER: Record<Slot, string> = {
163
+ image: 'u_image',
164
+ depth: 'u_depth',
165
+ normal: 'u_normal',
166
+ albedo: 'u_albedo',
167
+ roughness: 'u_rough',
168
+ metalness: 'u_metal',
169
+ specular: 'u_spec',
170
+ }
171
+ const HAS: Record<Slot, string | null> = {
172
+ image: null,
173
+ depth: 'u_hasDepth',
174
+ normal: 'u_hasNormal',
175
+ albedo: 'u_hasAlbedo',
176
+ roughness: 'u_hasRough',
177
+ metalness: 'u_hasMetal',
178
+ specular: 'u_hasSpec',
179
+ }
180
+
181
+ function compile(gl: WebGL2RenderingContext): WebGLProgram {
182
+ const prog = gl.createProgram()
183
+ for (const [type, src] of [
184
+ [gl.VERTEX_SHADER, VS],
185
+ [gl.FRAGMENT_SHADER, FS],
186
+ ] as const) {
187
+ const sh = gl.createShader(type)
188
+ if (sh == null) throw new Error('relight: createShader failed')
189
+ gl.shaderSource(sh, src)
190
+ gl.compileShader(sh)
191
+ if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) throw new Error(`relight shader: ${gl.getShaderInfoLog(sh)}`)
192
+ gl.attachShader(prog, sh)
193
+ }
194
+ gl.bindAttribLocation(prog, 0, 'a_uv')
195
+ gl.linkProgram(prog)
196
+ if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) throw new Error(`relight link: ${gl.getProgramInfoLog(prog)}`)
197
+ return prog
198
+ }
199
+
200
+ export class RelightGl {
201
+ private gl: WebGL2RenderingContext
202
+ private prog: WebGLProgram
203
+ private vao: WebGLVertexArrayObject
204
+ private tex = new Map<Slot, WebGLTexture>()
205
+ private has = new Set<Slot>()
206
+ private aspect = 1
207
+ private texel: [number, number] = [1 / 512, 1 / 512]
208
+
209
+ constructor(private canvas: HTMLCanvasElement) {
210
+ const gl = canvas.getContext('webgl2', { antialias: false, preserveDrawingBuffer: true })
211
+ if (gl == null) throw new Error('relight needs WebGL2, which this browser does not offer')
212
+ this.gl = gl
213
+ this.prog = compile(gl)
214
+ this.vao = gl.createVertexArray()
215
+ gl.bindVertexArray(this.vao)
216
+ gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer())
217
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]), gl.STATIC_DRAW)
218
+ gl.enableVertexAttribArray(0)
219
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0)
220
+ gl.bindVertexArray(null)
221
+ for (const s of SLOTS) {
222
+ const t = gl.createTexture()
223
+ gl.bindTexture(gl.TEXTURE_2D, t)
224
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
225
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
226
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
227
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
228
+ gl.texImage2D(
229
+ gl.TEXTURE_2D,
230
+ 0,
231
+ gl.RGBA,
232
+ 1,
233
+ 1,
234
+ 0,
235
+ gl.RGBA,
236
+ gl.UNSIGNED_BYTE,
237
+ new Uint8Array([128, 128, 255, 255]),
238
+ )
239
+ this.tex.set(s, t)
240
+ }
241
+ }
242
+
243
+ /** the maps, any sizes: each is sampled by uv. `aspect` is the photo's width / height */
244
+ setMaps(maps: RelightMaps, aspect: number, width: number, height: number): void {
245
+ const gl = this.gl
246
+ this.aspect = aspect
247
+ this.texel = [1 / Math.max(1, width), 1 / Math.max(1, height)]
248
+ this.has.clear()
249
+ for (const s of SLOTS) {
250
+ const img = maps[s]
251
+ if (img == null) continue
252
+ gl.bindTexture(gl.TEXTURE_2D, this.tex.get(s) ?? null)
253
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img)
254
+ this.has.add(s)
255
+ }
256
+ }
257
+
258
+ hasMap(s: Slot): boolean {
259
+ return this.has.has(s)
260
+ }
261
+
262
+ draw(p: RelightParams): void {
263
+ const gl = this.gl
264
+ const dpr = window.devicePixelRatio || 1
265
+ const w = Math.round(this.canvas.clientWidth * dpr)
266
+ const h = Math.round(this.canvas.clientHeight * dpr)
267
+ if (w === 0 || h === 0) return
268
+ if (this.canvas.width !== w || this.canvas.height !== h) {
269
+ this.canvas.width = w
270
+ this.canvas.height = h
271
+ }
272
+ gl.viewport(0, 0, w, h)
273
+ gl.clearColor(0, 0, 0, 0)
274
+ gl.clear(gl.COLOR_BUFFER_BIT)
275
+ gl.useProgram(this.prog)
276
+ const u = (name: string): WebGLUniformLocation | null => gl.getUniformLocation(this.prog, name)
277
+ SLOTS.forEach((s, i) => {
278
+ gl.activeTexture(gl.TEXTURE0 + i)
279
+ gl.bindTexture(gl.TEXTURE_2D, this.tex.get(s) ?? null)
280
+ gl.uniform1i(u(SAMPLER[s]), i)
281
+ const flag = HAS[s]
282
+ if (flag != null) gl.uniform1i(u(flag), this.has.has(s) ? 1 : 0)
283
+ })
284
+ // the canvas keeps the photo's aspect (css), so the quad fills it
285
+ gl.uniform2f(u('u_fit'), 1, 1)
286
+ gl.uniform1f(u('u_aspect'), this.aspect)
287
+ gl.uniform2f(u('u_texel'), this.texel[0], this.texel[1])
288
+ gl.uniform1f(u('u_depthScale'), p.depthScale)
289
+ gl.uniform1f(u('u_intensity'), p.intensity)
290
+ gl.uniform1f(u('u_falloff'), p.falloff)
291
+ gl.uniform1f(u('u_ambient'), p.ambient)
292
+ gl.uniform1f(u('u_exposure'), p.exposure)
293
+ gl.uniform1f(u('u_moteIntensity'), p.moteIntensity)
294
+ gl.uniform3f(u('u_light'), p.light[0], p.light[1], p.light[2])
295
+ gl.uniform3f(u('u_color'), p.color[0], p.color[1], p.color[2])
296
+ gl.uniform1i(u('u_shadows'), p.shadows ? 1 : 0)
297
+ gl.uniform1i(u('u_showLights'), p.showLights ? 1 : 0)
298
+ gl.uniform1i(u('u_view'), VIEW_INDEX[p.view])
299
+ const n = Math.min(MAX_MOTES, p.motes.length)
300
+ gl.uniform1i(u('u_moteCount'), n)
301
+ if (n > 0) gl.uniform3fv(u('u_motes'), new Float32Array(p.motes.slice(0, n).flat()))
302
+ gl.bindVertexArray(this.vao)
303
+ gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4)
304
+ }
305
+ }
@@ -0,0 +1,19 @@
1
+ // the output widgets' rules, one string: the panel's stylesheet embeds it, and a page outside the
2
+ // panel (examples/depth-explorer) injects it beside its own. Reads the panel's colour tokens
3
+ export const WIDGET_STYLES = /* css */ `
4
+ .output-widgets { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
5
+ .relight { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #0b0c10; }
6
+ .relight-stage { display: flex; justify-content: center; background: #07080b; }
7
+ .relight-canvas { display: block; width: 100%; max-height: 70vh; max-width: calc(70vh * 4); object-fit: contain; cursor: crosshair; touch-action: none; }
8
+ .relight-bar { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; background: var(--panel-2); border-top: 1px solid var(--hairline); }
9
+ .relight-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
10
+ .relight-title { font-weight: 600; margin-right: 6px; }
11
+ .relight-segs { display: flex; flex-wrap: wrap; gap: 4px; }
12
+ .relight .seg { font: inherit; font-size: 12px; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 3px 9px; cursor: pointer; }
13
+ .relight .seg.on { background: var(--sel-bg); border-color: var(--sel-border); color: var(--sel-text); }
14
+ .relight-slider { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); }
15
+ .relight-slider input { width: 92px; accent-color: var(--accent); }
16
+ .relight-color input { width: 28px; height: 22px; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: none; cursor: pointer; }
17
+ .relight-hint { color: var(--dim); font-size: 12px; margin-left: auto; }
18
+ .relight-missing { color: var(--amber); font-size: 12px; padding: 6px 0; }
19
+ `
@@ -113,6 +113,7 @@ export type {
113
113
  VarKind,
114
114
  VarsSpec,
115
115
  VarUi,
116
+ ChoiceOptionLook,
116
117
  AnyChoiceVar,
117
118
  ChoiceSelect,
118
119
  VarValues,
@@ -152,6 +153,14 @@ export {
152
153
  type SlotNameOf,
153
154
  type SlotValueOf,
154
155
  } from 'src/vars/DefinedWorkflow.ts'
156
+ export {
157
+ widget,
158
+ resolveWidgetRoles,
159
+ type OutputWidget,
160
+ type OutputWidgetKind,
161
+ type RelightRoles,
162
+ type RelightWidget,
163
+ } from 'src/vars/outputWidgets.ts'
155
164
  export {
156
165
  clearLoraKeywordOverride,
157
166
  getLoraKeyword,
@@ -46,6 +46,28 @@ export type VarKind = 'text' | 'prompt' | 'int' | 'float' | 'seed' | 'toggle' |
46
46
  */
47
47
  /** how a var LOOKS in the panel, set by the workflow: `v.int(8).ui({ icon, color, description })`.
48
48
  * Every slot is optional, a color is any css color */
49
+ /** how one option of a choice var looks in the panel. Every field is optional: a bare option
50
+ * shows its value */
51
+ export type ChoiceOptionLook = {
52
+ /** a 24×24 svg path drawn in the color, or a whole `<svg …>` string */
53
+ icon?: string
54
+ color?: string
55
+ /** the name shown instead of the raw value (the value stays the payload) */
56
+ label?: string
57
+ description?: string
58
+ /** a picture: an http(s) url, or a local path relative to the workflow file */
59
+ thumb?: string
60
+ /** when it came out: `2025`, `2025-11` */
61
+ date?: string
62
+ /** what it weighs on disk: `1.3 GB` */
63
+ size?: string
64
+ /** 1 (rough) to 5 (the best of its kind) */
65
+ quality?: number
66
+ /** how long it takes: `0.9 s`, `30 s` */
67
+ speed?: string
68
+ tags?: string[]
69
+ }
70
+
49
71
  export type VarUi = {
50
72
  /** shown as a (?) after the label, the text is its tooltip */
51
73
  description?: string
@@ -62,8 +84,8 @@ export type VarUi = {
62
84
  groupColor?: string
63
85
  border?: string
64
86
  /** choice vars: a look per option, keyed by the option value. The lit option is filled
65
- * with its own color */
66
- options?: Record<string, { icon?: string; color?: string }>
87
+ * with its own color; a dropdown row shows the rest (ChoiceOptionLook) */
88
+ options?: Record<string, ChoiceOptionLook>
67
89
  /** the field is shown but disabled unless every named var holds one of the listed values:
68
90
  * `{ model: ['aesthetic', 'base'] }`. Checked against the var names when the workflow loads.
69
91
  * Display only: a disabled var's value still reaches the build */
@@ -909,6 +931,10 @@ export type MediaVarOpts = {
909
931
  /** the text var a file's `<name>.txt` sidecar fills, when a driver sets this var from a file
910
932
  * and leaves that one unset: a voice clip's transcript (`comfy-ts run`) */
911
933
  sidecarText?: TextVar
934
+ /** one-click starting files: `{ 'a lioness': exampleImagePath(…), 'a ruin': 'https://…' }`.
935
+ * A local path that is not on this machine is shown disabled, a url is fetched when a run
936
+ * uses it. Key order is display order */
937
+ presets?: Record<string, string>
912
938
  }
913
939
  export type ImageVarOpts = MediaVarOpts
914
940
  export type AudioVarOpts = MediaVarOpts
@@ -965,6 +991,10 @@ export abstract class MediaVar extends ComfyVar<string> {
965
991
  get extensions(): readonly string[] {
966
992
  return this.opts.extensions ?? DEFAULT_MEDIA_EXTENSIONS[this.kind]
967
993
  }
994
+ /** the one-click starting files, `~/` expanded, in their declared order */
995
+ get presets(): { label: string; value: string }[] {
996
+ return Object.entries(this.opts.presets ?? {}).map(([label, value]) => ({ label, value: expandUserPath(value) }))
997
+ }
968
998
  override set(value: string): this {
969
999
  return super.set(expandUserPath(value))
970
1000
  }
@@ -3,6 +3,7 @@ import type { ComfyExecution } from 'src/runner/ComfyExecution.ts'
3
3
  import type { ComfyWorkflow, RunSettings } from 'src/runner/ComfyWorkflow.ts'
4
4
  import type { SdkForHost } from 'src/types/comfy-sdk.ts'
5
5
  import type { LorasInput } from 'src/vars/lanes.ts'
6
+ import type { OutputWidget } from 'src/vars/outputWidgets.ts'
6
7
  import {
7
8
  type AnyVar,
8
9
  type ChoiceVar,
@@ -73,6 +74,9 @@ export type DefineWorkflowSpec<ID extends string, V extends VarsSpec> = {
73
74
  /** free search tags for the serve omnibox, added to the ones read from the graph
74
75
  * (`image`, `audio`, `video`, `text`, `llm`, `edit`) */
75
76
  tags?: string[]
77
+ /** built-in web panel widgets drawn over a run's outputs (`widget.relight(...)`), each role
78
+ * naming the `tag` of a save node. The CLI and the TUI ignore them */
79
+ widgets?: OutputWidget[]
76
80
  }
77
81
 
78
82
  /** type predicate (not a cast): a VarsSpec is a plain record, never callable */
@@ -0,0 +1,47 @@
1
+ // output widgets: a module names a BUILT-IN web panel widget and maps its roles to output tags
2
+ // (the `tag` of a save node's metadata). The panel renders it over the run's tagged images; the
3
+ // CLI and the TUI ignore it. Pure data: the web bundle imports this file.
4
+
5
+ /** the maps a relight widget reads, each the tag of one output image */
6
+ export type RelightRoles = {
7
+ /** the photo itself; the base colour when no albedo is given */
8
+ image: string
9
+ /** near = white; places each pixel in 3D and casts the shadows */
10
+ depth?: string
11
+ /** OpenGL convention (green up) */
12
+ normal?: string
13
+ albedo?: string
14
+ /** white = rough */
15
+ roughness?: string
16
+ /** white = metal */
17
+ metalness?: string
18
+ /** the non diffuse part of the light (reflections, highlights) */
19
+ specular?: string
20
+ }
21
+
22
+ export type RelightWidget = { kind: 'relight'; title?: string; roles: RelightRoles }
23
+
24
+ export type OutputWidget = RelightWidget
25
+ export type OutputWidgetKind = OutputWidget['kind']
26
+
27
+ export const widget = {
28
+ /** a point light moved over the image in 3D: left/right, up/down, nearer/farther */
29
+ relight(roles: RelightRoles, opts: { title?: string } = {}): RelightWidget {
30
+ if (roles.depth == null && roles.normal == null)
31
+ throw new Error(
32
+ 'widget.relight needs a `depth` or a `normal` role: without either there is no surface to light',
33
+ )
34
+ return { kind: 'relight', roles, ...(opts.title != null ? { title: opts.title } : {}) }
35
+ },
36
+ }
37
+
38
+ /** the roles of a widget whose tag one of the images carries, as role → index in `images` */
39
+ export function resolveWidgetRoles(w: OutputWidget, images: { tags?: string[] }[]): Map<string, number> {
40
+ const out = new Map<string, number>()
41
+ for (const [role, tag] of Object.entries(w.roles)) {
42
+ if (typeof tag !== 'string') continue
43
+ const ix = images.findIndex((img) => img.tags?.includes(tag) === true)
44
+ if (ix >= 0) out.set(role, ix)
45
+ }
46
+ return out
47
+ }