@nodetool-ai/image-nodes 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +94 -0
  2. package/dist/.nodetool-build-stamp +1 -0
  3. package/dist/index.d.ts +19 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +19 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/nodes/game.d.ts +68 -0
  8. package/dist/nodes/game.d.ts.map +1 -0
  9. package/dist/nodes/game.js +551 -0
  10. package/dist/nodes/game.js.map +1 -0
  11. package/dist/nodes/gpu-device.d.ts +59 -0
  12. package/dist/nodes/gpu-device.d.ts.map +1 -0
  13. package/dist/nodes/gpu-device.js +144 -0
  14. package/dist/nodes/gpu-device.js.map +1 -0
  15. package/dist/nodes/image-io.d.ts +122 -0
  16. package/dist/nodes/image-io.d.ts.map +1 -0
  17. package/dist/nodes/image-io.js +381 -0
  18. package/dist/nodes/image-io.js.map +1 -0
  19. package/dist/nodes/image.d.ts +649 -0
  20. package/dist/nodes/image.d.ts.map +1 -0
  21. package/dist/nodes/image.js +2827 -0
  22. package/dist/nodes/image.js.map +1 -0
  23. package/dist/nodes/lib-grid.d.ts +19 -0
  24. package/dist/nodes/lib-grid.d.ts.map +1 -0
  25. package/dist/nodes/lib-grid.js +134 -0
  26. package/dist/nodes/lib-grid.js.map +1 -0
  27. package/dist/nodes/lib-image-channel.d.ts +38 -0
  28. package/dist/nodes/lib-image-channel.d.ts.map +1 -0
  29. package/dist/nodes/lib-image-channel.js +55 -0
  30. package/dist/nodes/lib-image-channel.js.map +1 -0
  31. package/dist/nodes/lib-image-color-grading.d.ts +3 -0
  32. package/dist/nodes/lib-image-color-grading.d.ts.map +1 -0
  33. package/dist/nodes/lib-image-color-grading.js +1080 -0
  34. package/dist/nodes/lib-image-color-grading.js.map +1 -0
  35. package/dist/nodes/lib-image-color.d.ts +96 -0
  36. package/dist/nodes/lib-image-color.d.ts.map +1 -0
  37. package/dist/nodes/lib-image-color.js +150 -0
  38. package/dist/nodes/lib-image-color.js.map +1 -0
  39. package/dist/nodes/lib-image-draw.d.ts +4 -0
  40. package/dist/nodes/lib-image-draw.d.ts.map +1 -0
  41. package/dist/nodes/lib-image-draw.js +464 -0
  42. package/dist/nodes/lib-image-draw.js.map +1 -0
  43. package/dist/nodes/lib-image-effects.d.ts +72 -0
  44. package/dist/nodes/lib-image-effects.d.ts.map +1 -0
  45. package/dist/nodes/lib-image-effects.js +123 -0
  46. package/dist/nodes/lib-image-effects.js.map +1 -0
  47. package/dist/nodes/lib-image-enhance.d.ts +3 -0
  48. package/dist/nodes/lib-image-enhance.d.ts.map +1 -0
  49. package/dist/nodes/lib-image-enhance.js +442 -0
  50. package/dist/nodes/lib-image-enhance.js.map +1 -0
  51. package/dist/nodes/lib-image-filter-extras.d.ts +72 -0
  52. package/dist/nodes/lib-image-filter-extras.d.ts.map +1 -0
  53. package/dist/nodes/lib-image-filter-extras.js +110 -0
  54. package/dist/nodes/lib-image-filter-extras.js.map +1 -0
  55. package/dist/nodes/lib-image-filter.d.ts +3 -0
  56. package/dist/nodes/lib-image-filter.d.ts.map +1 -0
  57. package/dist/nodes/lib-image-filter.js +588 -0
  58. package/dist/nodes/lib-image-filter.js.map +1 -0
  59. package/dist/nodes/lib-image-generators.d.ts +71 -0
  60. package/dist/nodes/lib-image-generators.d.ts.map +1 -0
  61. package/dist/nodes/lib-image-generators.js +158 -0
  62. package/dist/nodes/lib-image-generators.js.map +1 -0
  63. package/dist/nodes/lib-image-keyer.d.ts +34 -0
  64. package/dist/nodes/lib-image-keyer.d.ts.map +1 -0
  65. package/dist/nodes/lib-image-keyer.js +61 -0
  66. package/dist/nodes/lib-image-keyer.js.map +1 -0
  67. package/dist/nodes/lib-image-mask.d.ts +47 -0
  68. package/dist/nodes/lib-image-mask.d.ts.map +1 -0
  69. package/dist/nodes/lib-image-mask.js +59 -0
  70. package/dist/nodes/lib-image-mask.js.map +1 -0
  71. package/dist/nodes/lib-image-utils.d.ts +16 -0
  72. package/dist/nodes/lib-image-utils.d.ts.map +1 -0
  73. package/dist/nodes/lib-image-utils.js +61 -0
  74. package/dist/nodes/lib-image-utils.js.map +1 -0
  75. package/dist/nodes/lib-image-warp.d.ts +112 -0
  76. package/dist/nodes/lib-image-warp.d.ts.map +1 -0
  77. package/dist/nodes/lib-image-warp.js +236 -0
  78. package/dist/nodes/lib-image-warp.js.map +1 -0
  79. package/dist/nodes/lib-shader-utils.d.ts +105 -0
  80. package/dist/nodes/lib-shader-utils.d.ts.map +1 -0
  81. package/dist/nodes/lib-shader-utils.js +452 -0
  82. package/dist/nodes/lib-shader-utils.js.map +1 -0
  83. package/dist/nodes/sketch.d.ts +62 -0
  84. package/dist/nodes/sketch.d.ts.map +1 -0
  85. package/dist/nodes/sketch.js +325 -0
  86. package/dist/nodes/sketch.js.map +1 -0
  87. package/package.json +83 -0
@@ -0,0 +1,452 @@
1
+ /**
2
+ * Shared runner for `@nodetool-ai/gpu/pool` shader nodes.
3
+ *
4
+ * Environment-aware: acquires a Dawn `GPUContext` on Node and a
5
+ * `navigator.gpu` context in the browser, so the same shader path runs
6
+ * client-side (pure-browser sub-graphs) and server-side. Codec work (decode
7
+ * input / encode PNG) goes through the sharp-free {@link import("./image-io.js")}
8
+ * seam, which uses Canvas in the browser and `sharp` on Node.
9
+ *
10
+ * One helper per shader category builds a `BaseNode` per published or internal
11
+ * module from the pool. Every node body funnels into {@link runShaderNode}
12
+ * (single-pass) or {@link runRecipeNode} (multi-pass recipes), which decode
13
+ * the input(s) via `decodeRgba`, upload to a `LabeledTexture`, run
14
+ * `Executor.encode` / `RecipeRunner.encode` against the cached Dawn device,
15
+ * and emit raw RGBA via {@link rawRgbaImageRef} so chained shader nodes skip
16
+ * the PNG re-encode.
17
+ *
18
+ * Alpha conversion: the pool's contract is premultiplied between modules,
19
+ * while the node-graph carries straight-alpha RGBA (`decodeRgba` /
20
+ * `rawRgbaImageRef`). The helper premultiplies on upload and un-premultiplies
21
+ * on readback so per-module shaders see canonical premultiplied throughout.
22
+ */
23
+ import { createExecutor, createRecipeRunner } from "@nodetool-ai/gpu/pool";
24
+ import { isGpuTextureImage } from "@nodetool-ai/protocol";
25
+ import { decodeRgba, rawRgbaImageRef } from "./image-io.js";
26
+ import { GPU_TEXTURES_ENABLED, createLabeledTexture, getGpuContext, gpuTextureImageRef, premultiplyInPlace, readbackStraightAlpha, trackRunTexture } from "./gpu-device.js";
27
+ import { isNonEmptyString, isNumber, isObjectLike, isString } from "@nodetool-ai/node-sdk";
28
+ // Cache the executor / recipe runner / registry at module scope so the
29
+ // sampler WeakMap inside the executor (and the recipe runner's internal
30
+ // pipeline cache) survives across node invocations. Re-creating them per
31
+ // call defeats those caches.
32
+ const cachedExecutor = createExecutor();
33
+ const cachedRecipeRunner = createRecipeRunner();
34
+ let cachedRegistry = null;
35
+ async function importRegistry() {
36
+ const { createDefaultRegistry } = await import("@nodetool-ai/gpu/pool");
37
+ return createDefaultRegistry();
38
+ }
39
+ async function getRegistry() {
40
+ // Reset the cache on rejection so a transient dynamic-import failure doesn't
41
+ // poison every future recipe node in the process (mirrors getGpuContext).
42
+ if (!cachedRegistry) {
43
+ cachedRegistry = importRegistry().catch((err) => {
44
+ cachedRegistry = null;
45
+ throw err;
46
+ });
47
+ }
48
+ return cachedRegistry;
49
+ }
50
+ /** Texture usage that lets a labeled texture be sampled and copied from. */
51
+ const INPUT_USAGE = 0x04 /* TEXTURE_BINDING */ | 0x02 /* COPY_DST */ | 0x01; /* COPY_SRC */
52
+ /** Texture usage for outputs the executor's fragment arm writes to. */
53
+ const OUTPUT_USAGE = 0x10 /* RENDER_ATTACHMENT */ |
54
+ 0x04 /* TEXTURE_BINDING */ |
55
+ 0x01; /* COPY_SRC */
56
+ /** Texture usage for outputs the compute arm storage-writes to. */
57
+ const COMPUTE_OUTPUT_USAGE = 0x08 /* STORAGE_BINDING */ | 0x04 /* TEXTURE_BINDING */ | 0x01; /* COPY_SRC */
58
+ async function uploadStraightAlpha(device, image, context, label = "shader-input") {
59
+ // A GPU-texture ImageRef is already a texture on this device — sample it
60
+ // directly, skipping decode + upload (the whole point of GPU chaining).
61
+ // Borrowed: the run owns it, so this node must not free it.
62
+ if (isGpuTextureImage(image)) {
63
+ return {
64
+ texture: image.texture,
65
+ width: image.width,
66
+ height: image.height,
67
+ borrowed: true
68
+ };
69
+ }
70
+ const decoded = await decodeRgba(image, context);
71
+ if (decoded.rgba.length === 0)
72
+ return null;
73
+ const pixels = new Uint8Array(decoded.rgba);
74
+ premultiplyInPlace(pixels);
75
+ const texture = createLabeledTexture(device, {
76
+ label,
77
+ width: decoded.width,
78
+ height: decoded.height,
79
+ format: "rgba8unorm",
80
+ usage: INPUT_USAGE
81
+ });
82
+ device.queue.writeTexture({ texture: texture.texture }, pixels, { bytesPerRow: decoded.width * 4, rowsPerImage: decoded.height }, { width: decoded.width, height: decoded.height });
83
+ return {
84
+ texture,
85
+ width: decoded.width,
86
+ height: decoded.height,
87
+ borrowed: false
88
+ };
89
+ }
90
+ function resolveOutputDims(module, source, opts) {
91
+ const declared = module.io.output.dimensions;
92
+ if (declared === "host-specified" || declared === "derived") {
93
+ const w = opts.outputWidth ?? source?.width;
94
+ const h = opts.outputHeight ?? source?.height;
95
+ if (!w || !h) {
96
+ throw new Error(`${module.id}@${module.version}: outputWidth/outputHeight required (dimensions=${declared})`);
97
+ }
98
+ return { width: w, height: h };
99
+ }
100
+ // same-as:<inputName> — for the published catalog this is always "source".
101
+ if (!source) {
102
+ throw new Error(`${module.id}@${module.version}: dimensions=${declared} but no source input bound`);
103
+ }
104
+ return { width: source.width, height: source.height };
105
+ }
106
+ /**
107
+ * Run a single-pass {@link ShaderModule} against the cached Dawn device. The
108
+ * dispatch (fragment vs compute) is picked from `module.kind`.
109
+ */
110
+ export async function runShaderNode(module, params, sourceImage, opts = {}, context) {
111
+ const ctx = await getGpuContext();
112
+ const device = ctx.device;
113
+ // Textures this node OWNS (uploaded here) — freed in `finally`. Borrowed
114
+ // GPU-texture inputs belong to the run's registry and are never freed here.
115
+ // Every upload happens inside the try and is pushed onto `owned` the instant
116
+ // its texture exists, so a later upload that throws (e.g. a second input
117
+ // fails to decode) can't leak the textures already created.
118
+ const owned = [];
119
+ let output;
120
+ let handedOff = false;
121
+ try {
122
+ const source = sourceImage
123
+ ? await uploadStraightAlpha(device, sourceImage, context, `${module.id}-source`)
124
+ : null;
125
+ if (source && !source.borrowed)
126
+ owned.push(source.texture);
127
+ if (!source &&
128
+ module.io.inputs.source &&
129
+ !module.io.inputs.source.optional) {
130
+ // No source bound and module requires one — no-op with an empty ImageRef
131
+ // rather than fail loud (mirrors lib-image-filter), but warn so the blank
132
+ // result is visible instead of propagating silently through a chain.
133
+ console.warn(`${module.id}: required input "source" missing — emitting empty image.`);
134
+ return { type: "image", data: "" };
135
+ }
136
+ const inputs = {};
137
+ if (source)
138
+ inputs.source = source.texture;
139
+ for (const [name, ref] of Object.entries(opts.extraInputs ?? {})) {
140
+ const uploaded = await uploadStraightAlpha(device, ref, context, `${module.id}-${name}`);
141
+ if (uploaded) {
142
+ inputs[name] = uploaded.texture;
143
+ if (!uploaded.borrowed)
144
+ owned.push(uploaded.texture);
145
+ }
146
+ }
147
+ // Bail out before encoding if any *required* declared input is unbound —
148
+ // executor.encode would throw "missing required input" otherwise. Mirrors
149
+ // the source-missing no-op above so a stray null upstream produces an
150
+ // empty image rather than a hard failure.
151
+ for (const [name, contract] of Object.entries(module.io.inputs)) {
152
+ if (contract.optional)
153
+ continue;
154
+ if (!inputs[name]) {
155
+ console.warn(`${module.id}: required input "${name}" missing — emitting empty image.`);
156
+ return { type: "image", data: "" };
157
+ }
158
+ }
159
+ // Keep the output on the GPU when chaining client-side (browser, inside a
160
+ // run): the next node samples it directly and the run frees it later. On
161
+ // Node/Dawn (server) or outside a run, read it back to a CPU RGBA buffer.
162
+ const runId = context?.jobId;
163
+ const keepOnGpu = GPU_TEXTURES_ENABLED && isNonEmptyString(runId);
164
+ const dims = resolveOutputDims(module, source, opts);
165
+ output = createLabeledTexture(device, {
166
+ label: `${module.id}-output`,
167
+ width: dims.width,
168
+ height: dims.height,
169
+ format: "rgba8unorm",
170
+ usage: module.kind === "compute" ? COMPUTE_OUTPUT_USAGE : OUTPUT_USAGE
171
+ });
172
+ ctx.uniformRing.beginSubmission();
173
+ const encoder = device.createCommandEncoder({
174
+ label: `${module.id}-encode`
175
+ });
176
+ if (module.kind === "compute") {
177
+ const [wx, wy] = module.workgroupSize;
178
+ cachedExecutor.encode({
179
+ ctx,
180
+ module,
181
+ encoder,
182
+ inputs,
183
+ output,
184
+ params: params,
185
+ dispatch: {
186
+ kind: "compute",
187
+ x: Math.ceil(dims.width / wx),
188
+ y: Math.ceil(dims.height / wy),
189
+ z: 1
190
+ }
191
+ });
192
+ }
193
+ else {
194
+ cachedExecutor.encode({
195
+ ctx,
196
+ module,
197
+ encoder,
198
+ inputs,
199
+ output,
200
+ params: params,
201
+ dispatch: { kind: "fragment" }
202
+ });
203
+ }
204
+ device.queue.submit([encoder.finish()]);
205
+ if (keepOnGpu) {
206
+ trackRunTexture(runId, output);
207
+ handedOff = true;
208
+ return gpuTextureImageRef(output, dims.width, dims.height);
209
+ }
210
+ const rgba = await readbackStraightAlpha(device, output);
211
+ return rawRgbaImageRef(rgba, dims.width, dims.height);
212
+ }
213
+ finally {
214
+ // Free this node's own textures (inputs it uploaded, and the output unless
215
+ // it was handed off to the run as a GPU-texture ref).
216
+ for (const t of owned)
217
+ t.destroy();
218
+ if (output && !handedOff)
219
+ output.destroy();
220
+ }
221
+ }
222
+ /** Run a multi-pass {@link RecipeModule} (e.g. `filters.glow`, `mixer.dropShadow`). */
223
+ export async function runRecipeNode(recipe, params, sourceImage, opts = {}, context) {
224
+ const ctx = await getGpuContext();
225
+ const device = ctx.device;
226
+ const registry = await getRegistry();
227
+ // Textures this node OWNS (uploaded here) — freed in `finally`. Every upload
228
+ // happens inside the try and is pushed onto `owned` the instant its texture
229
+ // exists, so a later upload that throws can't leak textures already created.
230
+ const owned = [];
231
+ let output;
232
+ let handedOff = false;
233
+ try {
234
+ const source = sourceImage
235
+ ? await uploadStraightAlpha(device, sourceImage, context, `${recipe.id}-source`)
236
+ : null;
237
+ if (!source) {
238
+ // No source bound — no-op with an empty ImageRef rather than fail loud,
239
+ // but warn so the blank result is visible instead of propagating silently.
240
+ console.warn(`${recipe.id}: required input "source" missing — emitting empty image.`);
241
+ return { type: "image", data: "" };
242
+ }
243
+ if (!source.borrowed)
244
+ owned.push(source.texture);
245
+ const inputs = { source: source.texture };
246
+ for (const [name, ref] of Object.entries(opts.extraInputs ?? {})) {
247
+ const uploaded = await uploadStraightAlpha(device, ref, context, `${recipe.id}-${name}`);
248
+ if (uploaded) {
249
+ inputs[name] = uploaded.texture;
250
+ if (!uploaded.borrowed)
251
+ owned.push(uploaded.texture);
252
+ }
253
+ }
254
+ for (const [name, contract] of Object.entries(recipe.io.inputs)) {
255
+ if (contract.optional)
256
+ continue;
257
+ if (!inputs[name]) {
258
+ console.warn(`${recipe.id}: required input "${name}" missing — emitting empty image.`);
259
+ return { type: "image", data: "" };
260
+ }
261
+ }
262
+ const runId = context?.jobId;
263
+ const keepOnGpu = GPU_TEXTURES_ENABLED && isNonEmptyString(runId);
264
+ const dims = resolveOutputDims(recipe, source, opts);
265
+ output = createLabeledTexture(device, {
266
+ label: `${recipe.id}-output`,
267
+ width: dims.width,
268
+ height: dims.height,
269
+ format: "rgba8unorm",
270
+ usage: OUTPUT_USAGE | COMPUTE_OUTPUT_USAGE
271
+ });
272
+ ctx.uniformRing.beginSubmission();
273
+ const encoder = device.createCommandEncoder({
274
+ label: `${recipe.id}-encode`
275
+ });
276
+ cachedRecipeRunner.encode({
277
+ ctx,
278
+ module: recipe,
279
+ encoder,
280
+ inputs,
281
+ output,
282
+ params: params,
283
+ registry
284
+ });
285
+ device.queue.submit([encoder.finish()]);
286
+ if (keepOnGpu) {
287
+ trackRunTexture(runId, output);
288
+ handedOff = true;
289
+ return gpuTextureImageRef(output, dims.width, dims.height);
290
+ }
291
+ const rgba = await readbackStraightAlpha(device, output);
292
+ return rawRgbaImageRef(rgba, dims.width, dims.height);
293
+ }
294
+ finally {
295
+ for (const t of owned)
296
+ t.destroy();
297
+ if (output && !handedOff)
298
+ output.destroy();
299
+ }
300
+ }
301
+ /**
302
+ * Coerce an arbitrary prop value to a finite number, falling back when it is
303
+ * `NaN`/`Infinity`/non-numeric. Shared by every `lib.image.*` node body that
304
+ * reads scalar props off `this.serialize()`.
305
+ */
306
+ export function num(value, fallback) {
307
+ const n = Number(value);
308
+ return Number.isFinite(n) ? n : fallback;
309
+ }
310
+ /* ------------------------------------------------------------------- *
311
+ * Property factories — translate a module's TypeGPU param defaults *
312
+ * + paramUi hints into the `@prop` PropOptions shape node-sdk expects.*
313
+ * ------------------------------------------------------------------- */
314
+ /** Standard `image` input slot for shader nodes consuming a source texture. */
315
+ export const IMAGE_PROP = {
316
+ type: "image",
317
+ default: {
318
+ type: "image",
319
+ uri: "",
320
+ asset_id: null,
321
+ data: null,
322
+ metadata: null
323
+ },
324
+ title: "Image",
325
+ description: "Input image"
326
+ };
327
+ /** Optional second image slot (mask, alpha source, displacement map, …). */
328
+ export function extraImageProp(title, description) {
329
+ return {
330
+ type: "image",
331
+ default: {
332
+ type: "image",
333
+ uri: "",
334
+ asset_id: null,
335
+ data: null,
336
+ metadata: null
337
+ },
338
+ title,
339
+ description
340
+ };
341
+ }
342
+ /** Numeric scalar prop with min/max/step taken from a module's `paramUi`. */
343
+ export function floatProp(defaultValue, ui = {}) {
344
+ const prop = {
345
+ type: "float",
346
+ default: defaultValue,
347
+ title: ui.label ?? "",
348
+ description: ui.notes ?? ""
349
+ };
350
+ if (ui.min !== undefined) {
351
+ prop.min = ui.min;
352
+ }
353
+ if (ui.max !== undefined) {
354
+ prop.max = ui.max;
355
+ }
356
+ return prop;
357
+ }
358
+ /** Integer-valued scalar (radius, mode enum, channel count). */
359
+ export function intProp(defaultValue, ui = {}) {
360
+ const prop = {
361
+ type: "int",
362
+ default: Math.round(defaultValue),
363
+ title: ui.label ?? "",
364
+ description: ui.notes ?? ""
365
+ };
366
+ if (ui.min !== undefined) {
367
+ prop.min = ui.min;
368
+ }
369
+ if (ui.max !== undefined) {
370
+ prop.max = ui.max;
371
+ }
372
+ return prop;
373
+ }
374
+ /** Hex/CSS color prop. Stored as `{ type: "color", value: "#RRGGBBAA" }`. */
375
+ export function colorProp(defaultHex, ui = {}) {
376
+ return {
377
+ type: "color",
378
+ default: { type: "color", value: defaultHex },
379
+ title: ui.label ?? "",
380
+ description: ui.notes ?? ""
381
+ };
382
+ }
383
+ /**
384
+ * Parse a color value to a `[r, g, b, a]` tuple in [0,1].
385
+ *
386
+ * Accepted shapes:
387
+ * - `{ type: "color", value: "#rrggbb" | "#rrggbbaa" }` — the node-graph
388
+ * color prop form
389
+ * - `"#rrggbb"` / `"#rrggbbaa"` / `"rrggbb"` — bare hex strings
390
+ * - `[r, g, b, a]` / `[r, g, b]` — already-normalized floats in [0,1]
391
+ *
392
+ * Returns `fallback` for anything else, including hex strings that fail to
393
+ * parse (NaN bytes).
394
+ */
395
+ export function colorValueToVec4(color, fallback = [0, 0, 0, 1]) {
396
+ if (Array.isArray(color)) {
397
+ const [r, g, b, a] = color;
398
+ const out = [
399
+ isNumber(r) ? r : fallback[0],
400
+ isNumber(g) ? g : fallback[1],
401
+ isNumber(b) ? b : fallback[2],
402
+ isNumber(a) ? a : fallback[3]
403
+ ];
404
+ return out.some((v) => !Number.isFinite(v)) ? fallback : out;
405
+ }
406
+ let value;
407
+ if (isString(color)) {
408
+ value = color;
409
+ }
410
+ else if (isObjectLike(color)) {
411
+ const maybe = color.value;
412
+ if (isString(maybe))
413
+ value = maybe;
414
+ }
415
+ if (value == null)
416
+ return fallback;
417
+ let hex = value.startsWith("#") ? value.slice(1) : value;
418
+ // Expand 3-/4-digit shorthand (#fff, #fff8) by doubling each nibble.
419
+ if (hex.length === 3 || hex.length === 4) {
420
+ hex = hex
421
+ .split("")
422
+ .map((c) => c + c)
423
+ .join("");
424
+ }
425
+ const parseByte = (s) => parseInt(s, 16) / 255;
426
+ let parsed = null;
427
+ if (hex.length === 6) {
428
+ parsed = [
429
+ parseByte(hex.slice(0, 2)),
430
+ parseByte(hex.slice(2, 4)),
431
+ parseByte(hex.slice(4, 6)),
432
+ 1
433
+ ];
434
+ }
435
+ else if (hex.length === 8) {
436
+ parsed = [
437
+ parseByte(hex.slice(0, 2)),
438
+ parseByte(hex.slice(2, 4)),
439
+ parseByte(hex.slice(4, 6)),
440
+ parseByte(hex.slice(6, 8))
441
+ ];
442
+ }
443
+ if (!parsed || parsed.some((v) => !Number.isFinite(v)))
444
+ return fallback;
445
+ return parsed;
446
+ }
447
+ /** Premultiply a straight-alpha `[r,g,b,a]` tuple. */
448
+ export function premultiplyVec4(rgba) {
449
+ const [r, g, b, a] = rgba;
450
+ return [r * a, g * a, b * a, a];
451
+ }
452
+ //# sourceMappingURL=lib-shader-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib-shader-utils.js","sourceRoot":"","sources":["../../src/nodes/lib-shader-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EACL,cAAc,EACd,kBAAkB,EAGnB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EAEhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,YAAY,EACZ,QAAQ,EACT,MAAM,uBAAuB,CAAC;AAE/B,uEAAuE;AACvE,wEAAwE;AACxE,yEAAyE;AACzE,6BAA6B;AAC7B,MA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AK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC1B,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC1B,CAAC;SACF,CAAC;IACJ,CAAC;SAAM,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,GAAG;YACP,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC1B,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC1B,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC1B,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SAC3B,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAAE,OAAO,QAAQ,CAAC;IACxE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,eAAe,CAC7B,IAAsC;IAEtC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;IAC1B,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Sketch nodes — operate on persisted sketch documents (the image editor's
3
+ * layered documents) referenced by the `sketch` type.
4
+ *
5
+ * Rendering matches the web editor's export flatten
6
+ * (`web/src/components/sketch/serialization`): visible raster layers are
7
+ * composited bottom→top with per-layer opacity and blend mode, placed by
8
+ * translation (`transform.x/y + raster bounds`). Scale/rotation transforms
9
+ * and non-destructive layer effects are not applied server-side.
10
+ */
11
+ import { BaseNode } from "@nodetool-ai/node-sdk";
12
+ import type { ImageRef, SketchRef } from "@nodetool-ai/protocol";
13
+ import type { ProcessingContext } from "@nodetool-ai/runtime";
14
+ export declare class RenderSketchNode extends BaseNode {
15
+ static readonly nodeType = "nodetool.sketch.RenderSketch";
16
+ static readonly title = "Render Sketch";
17
+ static readonly description = "Render a sketch document to a flat image (plus its mask layer when one is set).\n sketch, render, flatten, image, mask\n\n Use cases:\n - Use a hand-drawn sketch as input for image generation (img2img, ControlNet-style guidance)\n - Produce an inpainting mask painted in the sketch editor\n - Turn editor compositions into workflow images without manual exporting";
18
+ static readonly metadataOutputTypes: {
19
+ image: string;
20
+ mask: string;
21
+ };
22
+ static readonly inlineFields: string[];
23
+ static readonly inputFields: string[];
24
+ sketch: SketchRef;
25
+ process(context?: ProcessingContext): Promise<Record<string, unknown>>;
26
+ }
27
+ export declare class SketchLayersNode extends BaseNode {
28
+ static readonly nodeType = "nodetool.sketch.SketchLayers";
29
+ static readonly title = "Sketch Layers";
30
+ static readonly description = "Extract each visible layer of a sketch document as a separate image.\n sketch, layers, split, extract\n\n Use cases:\n - Process foreground/background layers through different pipelines\n - Batch-restyle each layer of a composition independently\n - Feed named layers into compositing or animation nodes";
31
+ static readonly metadataOutputTypes: {
32
+ layers: string;
33
+ names: string;
34
+ };
35
+ static readonly inlineFields: string[];
36
+ static readonly inputFields: string[];
37
+ sketch: SketchRef;
38
+ process(context?: ProcessingContext): Promise<Record<string, unknown>>;
39
+ }
40
+ /** Output handles CreateSketchNode.process() emits. */
41
+ type CreateSketchNodeOutputs = {
42
+ output: {
43
+ type: string;
44
+ id: string;
45
+ };
46
+ };
47
+ export declare class CreateSketchNode extends BaseNode {
48
+ static readonly nodeType = "nodetool.sketch.CreateSketch";
49
+ static readonly title = "Create Sketch";
50
+ static readonly description = "Create a new sketch document from an image, ready to edit in the sketch editor.\n sketch, create, image, editor, handoff\n\n Use cases:\n - Hand a generated image to the sketch editor for manual touch-up\n - Start a paint-over from a photo or render\n - Round-trip: generate, refine by hand, feed back into the workflow";
51
+ static readonly metadataOutputTypes: {
52
+ output: string;
53
+ };
54
+ static readonly inlineFields: string[];
55
+ static readonly inputFields: string[];
56
+ image: ImageRef;
57
+ name: string;
58
+ process(context?: ProcessingContext): Promise<CreateSketchNodeOutputs>;
59
+ }
60
+ export declare const SKETCH_NODES: (typeof RenderSketchNode | typeof SketchLayersNode | typeof CreateSketchNode)[];
61
+ export {};
62
+ //# sourceMappingURL=sketch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sketch.d.ts","sourceRoot":"","sources":["../../src/nodes/sketch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAQ,MAAM,uBAAuB,CAAC;AAMvD,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAgP9D,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,MAAM,CAAC,QAAQ,CAAC,QAAQ,kCAAkC;IAC1D,MAAM,CAAC,QAAQ,CAAC,KAAK,mBAAmB;IACxC,MAAM,CAAC,QAAQ,CAAC,WAAW,gYACoW;IAC/X,MAAM,CAAC,QAAQ,CAAC,mBAAmB;QACjC,KAAK;QACL,IAAI;MACJ;IACF,MAAM,CAAC,QAAQ,CAAC,YAAY,WAAc;IAC1C,MAAM,CAAC,QAAQ,CAAC,WAAW,WAAc;IAQjC,MAAM,EAAE,SAAS,CAAC;IAEpB,OAAO,CACX,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAkBlC;CACF;AAED,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,MAAM,CAAC,QAAQ,CAAC,QAAQ,kCAAkC;IAC1D,MAAM,CAA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