@rosepetal/node-red-contrib-image-tools 1.2.3 → 1.3.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 (42) hide show
  1. package/.github/workflows/build-prebuild.yml +3 -0
  2. package/install.sh +8 -0
  3. package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +219 -3
  4. package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +2 -1
  5. package/node-red-contrib-image-tools/nodes/blend/add-mask.html +258 -3
  6. package/node-red-contrib-image-tools/nodes/blend/add-mask.js +2 -1
  7. package/node-red-contrib-image-tools/nodes/blend/add-masks.html +183 -3
  8. package/node-red-contrib-image-tools/nodes/blend/add-masks.js +2 -1
  9. package/node-red-contrib-image-tools/nodes/blend/blend.html +308 -3
  10. package/node-red-contrib-image-tools/nodes/blend/blend.js +2 -1
  11. package/node-red-contrib-image-tools/nodes/io/folder-in.html +147 -3
  12. package/node-red-contrib-image-tools/nodes/io/folder-in.js +2 -1
  13. package/node-red-contrib-image-tools/nodes/io/image-in.html +81 -2
  14. package/node-red-contrib-image-tools/nodes/io/image-in.js +2 -1
  15. package/node-red-contrib-image-tools/nodes/io/image-out.html +197 -3
  16. package/node-red-contrib-image-tools/nodes/io/image-out.js +2 -1
  17. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +375 -3
  18. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +2 -1
  19. package/node-red-contrib-image-tools/nodes/mix/concat.html +222 -5
  20. package/node-red-contrib-image-tools/nodes/mix/concat.js +2 -1
  21. package/node-red-contrib-image-tools/nodes/mix/mosaic.html +284 -3
  22. package/node-red-contrib-image-tools/nodes/mix/mosaic.js +2 -1
  23. package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +193 -3
  24. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +2 -1
  25. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +260 -2
  26. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +2 -1
  27. package/node-red-contrib-image-tools/nodes/transform/color-convert.html +144 -5
  28. package/node-red-contrib-image-tools/nodes/transform/color-convert.js +2 -1
  29. package/node-red-contrib-image-tools/nodes/transform/crop.html +213 -5
  30. package/node-red-contrib-image-tools/nodes/transform/crop.js +2 -1
  31. package/node-red-contrib-image-tools/nodes/transform/draw.html +128 -3
  32. package/node-red-contrib-image-tools/nodes/transform/draw.js +2 -1
  33. package/node-red-contrib-image-tools/nodes/transform/filter.html +344 -3
  34. package/node-red-contrib-image-tools/nodes/transform/filter.js +2 -1
  35. package/node-red-contrib-image-tools/nodes/transform/padding.html +292 -5
  36. package/node-red-contrib-image-tools/nodes/transform/padding.js +2 -1
  37. package/node-red-contrib-image-tools/nodes/transform/resize.html +177 -3
  38. package/node-red-contrib-image-tools/nodes/transform/resize.js +2 -1
  39. package/node-red-contrib-image-tools/nodes/transform/rotate.html +140 -5
  40. package/node-red-contrib-image-tools/nodes/transform/rotate.js +2 -1
  41. package/package.json +71 -71
  42. package/scripts/dual-register.js +267 -0
@@ -1,5 +1,5 @@
1
1
  <script type="text/javascript">
2
- RED.nodes.registerType('rotate', {
2
+ var _rpNodeCfg = {
3
3
  category : 'RP Image',
4
4
  color : '#DDA0DD',
5
5
  defaults : {
@@ -24,7 +24,7 @@
24
24
  },
25
25
  inputs :1, outputs:1,
26
26
  icon:"font-awesome/fa-rotate-right",
27
- label:function(){ return this.name || "rotate"; },
27
+ label:function(){ return this.name || "rp-rotate"; },
28
28
 
29
29
  oneditprepare:function(){
30
30
  $("#node-input-inputPath").typedInput({default:'msg',types:['msg','flow','global'],typeField:"#node-input-inputPathType"});
@@ -76,7 +76,9 @@
76
76
  $('#node-input-debugEnabled').data('debug-enabled', enabled);
77
77
  });
78
78
  }
79
- });
79
+ };
80
+ RED.nodes.registerType('rp-rotate', _rpNodeCfg);
81
+ RED.nodes.registerType('rotate', Object.assign({}, _rpNodeCfg, { category: 'deprecated' }));
80
82
 
81
83
  // Debug image display renderer - shared across all image processing nodes
82
84
  if (!window.debugImageRendererInitialized) {
@@ -188,7 +190,65 @@
188
190
  }
189
191
  </script>
190
192
 
191
- <script type="text/x-red" data-template-name="rotate">
193
+ <script type="text/x-red" data-template-name="rp-rotate">
194
+ <div class="form-row"><label for="node-input-name"><i class="fa fa-tag"></i> Name</label><input type="text" id="node-input-name"></div>
195
+ <hr>
196
+ <div class="form-row"><label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input</label><input type="text" id="node-input-inputPath" style="width:70%;"><input type="hidden" id="node-input-inputPathType"></div>
197
+ <div class="form-row"><label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output</label><input type="text" id="node-input-outputPath" style="width:70%;"><input type="hidden" id="node-input-outputPathType"></div>
198
+ <div class="form-row">
199
+ <label for="node-input-outputFormat"><i class="fa fa-file-image-o"></i> Output Format</label>
200
+ <select id="node-input-outputFormat" style="width: 200px;">
201
+ <option value="raw">Raw (fastest)</option>
202
+ <option value="jpg">JPEG</option>
203
+ <option value="png">PNG</option>
204
+ <option value="webp">WebP</option>
205
+ </select>
206
+ </div>
207
+ <div class="form-row" id="quality-row">
208
+ <label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
209
+ <input type="number" id="node-input-outputQuality" min="1" max="100" value="90" style="width: 70px;">
210
+ <span style="margin-left: 10px; color: #666;">1-100 (JPG/WebP only)</span>
211
+ </div>
212
+ <div class="form-row" id="png-optimize-row" style="display: none;">
213
+ <label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG Optimize</label>
214
+ <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
215
+ <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG (slower, smaller file)</label>
216
+ </div>
217
+ <div class="form-row" id="webp-lossless-row" style="display: none;">
218
+ <label for="node-input-webpLossless"><i class="fa fa-lock"></i> Lossless</label>
219
+ <input type="checkbox" id="node-input-webpLossless" style="display:inline-block; width:auto; vertical-align:baseline;">
220
+ <label for="node-input-webpLossless" style="width:auto; margin-left:5px;">Encode WebP without loss</label>
221
+ </div>
222
+ <div class="form-row" id="webp-smartsubsample-row" style="display: none;">
223
+ <label for="node-input-webpSmartSubsample"><i class="fa fa-magic"></i> Smart Subsample</label>
224
+ <input type="checkbox" id="node-input-webpSmartSubsample" style="display:inline-block; width:auto; vertical-align:baseline;">
225
+ <label for="node-input-webpSmartSubsample" style="width:auto; margin-left:5px;">Better chroma downsampling (lossy only)</label>
226
+ </div>
227
+ <div class="form-row" id="webp-effort-row" style="display: none;">
228
+ <label for="node-input-webpEffort"><i class="fa fa-tachometer"></i> Effort</label>
229
+ <input type="number" id="node-input-webpEffort" min="0" max="6" placeholder="4" style="width: 70px;">
230
+ <span style="margin-left: 10px; color: #666;">0-6 (higher = smaller file, slower)</span>
231
+ </div>
232
+
233
+ <!-- Debug Configuration -->
234
+ <div class="form-row">
235
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug</label>
236
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
237
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
238
+ </div>
239
+ <div class="form-row" id="debug-width-row" style="display: none;">
240
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug Width</label>
241
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
242
+ <input type="hidden" id="node-input-debugWidthType">
243
+ <span style="margin-left: 10px; color: #666;">pixels</span>
244
+ </div>
245
+
246
+ <hr>
247
+ <div class="form-row"><label for="node-input-angleValue"><i class="fa fa-refresh"></i> Angle (°)</label><input type="text" id="node-input-angleValue" style="width:70%;"><input type="hidden" id="node-input-angleType"></div>
248
+ <div class="form-row"><label for="node-input-padColor"><i class="fa fa-tint"></i> Pad colour</label><input type="color" id="node-input-padColor" style="width:80px;"></div>
249
+ </script>
250
+
251
+ <script type="text/x-red" data-template-name="rotate">
192
252
  <div class="form-row"><label for="node-input-name"><i class="fa fa-tag"></i> Name</label><input type="text" id="node-input-name"></div>
193
253
  <hr>
194
254
  <div class="form-row"><label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input</label><input type="text" id="node-input-inputPath" style="width:70%;"><input type="hidden" id="node-input-inputPathType"></div>
@@ -246,7 +306,82 @@
246
306
  <div class="form-row"><label for="node-input-padColor"><i class="fa fa-tint"></i> Pad colour</label><input type="color" id="node-input-padColor" style="width:80px;"></div>
247
307
  </script>
248
308
 
249
- <script type="text/x-red" data-help-name="rotate">
309
+ <script type="text/x-red" data-help-name="rp-rotate">
310
+ <p>Rotates images by a specified angle with customizable padding color using high-performance C++ processing.</p>
311
+
312
+ <h3>Details</h3>
313
+ <p>This node rotates images counter-clockwise by a specified angle in degrees. When rotation creates areas outside the original image bounds, these areas are filled with the specified padding color. The rotation operation supports both single images and arrays, with dynamic angle values from various sources.</p>
314
+
315
+ <h3>Properties</h3>
316
+ <dl class="message-properties">
317
+ <dt>Input from <span class="property-type">string</span></dt>
318
+ <dd>The location to read image data from. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
319
+ <dt>Output to <span class="property-type">string</span></dt>
320
+ <dd>The location where the rotated image will be stored. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
321
+ <dt>Output Format <span class="property-type">string</span></dt>
322
+ <dd>Choose output format: <code>raw</code> (fastest, standard image object), <code>jpg</code>, <code>png</code>, or <code>webp</code> (encoded file buffers).</dd>
323
+ <dt>Quality <span class="property-type">number</span></dt>
324
+ <dd>Compression quality for JPEG and WebP formats (1-100). Only visible when jpg or webp format is selected. Default: 90.</dd>
325
+ <dt>Angle <span class="property-type">number|string</span></dt>
326
+ <dd>Rotation angle in degrees (counter-clockwise). Can be a fixed number or dynamic value from msg property, flow, or global context. Supports decimal values.</dd>
327
+ <dt>Pad Color <span class="property-type">string</span></dt>
328
+ <dd>Color to fill areas created by rotation, specified as hexadecimal color (#RRGGBB). Default: #000000 (black).</dd>
329
+ </dl>
330
+
331
+ <h3>Inputs</h3>
332
+ <dl class="message-properties">
333
+ <dt>payload <span class="property-type">object | array</span></dt>
334
+ <dd>Single image object or array of image objects in standard format: <code>{ data: Buffer, width: number, height: number, channels: number, colorSpace: string, dtype: string }</code></dd>
335
+ </dl>
336
+
337
+ <h3>Outputs</h3>
338
+ <dl class="message-properties">
339
+ <dt>payload <span class="property-type">object | array | Buffer</span></dt>
340
+ <dd>Rotated image(s). Format depends on Output Format setting: raw image object(s) or encoded file buffer(s).</dd>
341
+ </dl>
342
+
343
+ <h3>Rotation Behavior</h3>
344
+ <ul>
345
+ <li><strong>Direction:</strong> Counter-clockwise rotation (positive angles)</li>
346
+ <li><strong>Angle Range:</strong> Any angle supported (0-360° and beyond)</li>
347
+ <li><strong>Padding:</strong> Areas outside original bounds filled with specified color</li>
348
+ <li><strong>Precision:</strong> Decimal angles supported (e.g., 45.5°, 30.25°)</li>
349
+ <li><strong>Canvas Size:</strong> Output canvas automatically sized to contain rotated image</li>
350
+ </ul>
351
+
352
+ <h3>Examples</h3>
353
+ <ul>
354
+ <li><strong>90° Rotation:</strong> Angle: 90 → Image rotated 90° counter-clockwise</li>
355
+ <li><strong>Custom Angle:</strong> Angle: 45.5 → Image rotated 45.5° counter-clockwise</li>
356
+ <li><strong>Dynamic Angle:</strong> Angle: msg.rotationAngle → Use angle from message property</li>
357
+ <li><strong>White Padding:</strong> Pad Color: #FFFFFF → White background for rotated areas</li>
358
+ <li><strong>Transparent Padding:</strong> For RGBA images, use appropriate color with alpha channel</li>
359
+ </ul>
360
+
361
+ <h3>Node Interactions</h3>
362
+ <p><strong>Input Sources:</strong> Image-in, Array-out, other transform nodes</p>
363
+ <p><strong>Output Destinations:</strong> Other transform nodes, Mix nodes (concat, mosaic), Array-in for collections</p>
364
+ <p><strong>Common Workflows:</strong> Image correction, artistic effects, batch rotation for image alignment</p>
365
+
366
+ <h3>Output Formats</h3>
367
+ <ul>
368
+ <li><strong>Raw:</strong> Standard image object (fastest, for further processing)</li>
369
+ <li><strong>JPEG:</strong> Compressed file buffer with quality setting</li>
370
+ <li><strong>PNG:</strong> Lossless compressed file buffer</li>
371
+ <li><strong>WebP:</strong> Modern compressed format with quality setting</li>
372
+ </ul>
373
+
374
+ <h3>Color Format</h3>
375
+ <p>Pad color is specified as hexadecimal (#RRGGBB) and passed directly to the C++ engine. The color picker provides an easy way to select colors visually.</p>
376
+
377
+ <h3>Error Handling</h3>
378
+ <p>The node validates input data and angle values, displaying warnings for invalid inputs. Invalid angles default to 0°. Processing errors are logged and the message is not propagated.</p>
379
+
380
+ <h3>Performance</h3>
381
+ <p>Uses optimized C++ backend with OpenCV for high-performance rotation processing. Node status displays processing time. Array inputs are processed in parallel for optimal performance.</p>
382
+ </script>
383
+
384
+ <script type="text/x-red" data-help-name="rotate">
250
385
  <p>Rotates images by a specified angle with customizable padding color using high-performance C++ processing.</p>
251
386
 
252
387
  <h3>Details</h3>
@@ -165,5 +165,6 @@ module.exports = function (RED) {
165
165
  });
166
166
  }
167
167
 
168
- RED.nodes.registerType('rotate', RotateNode);
168
+ RED.nodes.registerType('rp-rotate', RotateNode);
169
+ RED.nodes.registerType('rotate', RotateNode); // legacy compat
169
170
  };
package/package.json CHANGED
@@ -1,75 +1,75 @@
1
1
  {
2
- "name": "@rosepetal/node-red-contrib-image-tools",
3
- "version": "1.2.3",
4
- "description": "Node-RED Image Processing Toolkit",
5
- "main": "install.sh",
6
- "directories": {
7
- "doc": "docs"
8
- },
9
- "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/rosepetal-ai/node-red-contrib-image-tools.git"
15
- },
16
- "keywords": [
17
- "node-red",
18
- "image",
19
- "opencv",
20
- "performance"
21
- ],
22
- "author": "Rosepetal SL (https://www.rosepetal.ai)",
23
- "contributors": [
24
- {
25
- "name": "Nil Allue",
26
- "email": "nil.allue@rosepetal.ai"
27
- }
28
- ],
29
- "license": "Apache-2.0",
30
- "bugs": {
31
- "url": "https://github.com/rosepetal-ai/node-red-contrib-image-tools/issues"
32
- },
33
- "homepage": "https://github.com/rosepetal-ai/node-red-contrib-image-tools#readme",
34
- "dependencies": {
35
- "sharp": "^0.34.2"
36
- },
37
- "optionalDependencies": {
38
- "@rosepetal/node-red-contrib-image-tools-linux-x64": "1.1.3",
39
- "@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.1.3",
40
- "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.1.3",
41
- "@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.1.3",
42
- "@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.1.3"
43
- },
44
- "node-red": {
45
- "version": ">=1.0.0",
46
- "nodes": {
47
- "image-in": "node-red-contrib-image-tools/nodes/io/image-in.js",
48
- "folder-in": "node-red-contrib-image-tools/nodes/io/folder-in.js",
49
- "image-out": "node-red-contrib-image-tools/nodes/io/image-out.js",
50
- "array-in": "node-red-contrib-image-tools/nodes/io/array-in.js",
51
- "array-out": "node-red-contrib-image-tools/nodes/io/array-out.js",
52
- "array-select": "node-red-contrib-image-tools/nodes/io/array-select.js",
53
- "cropBB": "node-red-contrib-image-tools/nodes/specialized/cropBB.js",
54
- "image-align": "node-red-contrib-image-tools/nodes/specialized/image-align.js",
55
- "resize": "node-red-contrib-image-tools/nodes/transform/resize.js",
56
- "rotate": "node-red-contrib-image-tools/nodes/transform/rotate.js",
57
- "crop": "node-red-contrib-image-tools/nodes/transform/crop.js",
58
- "concat": "node-red-contrib-image-tools/nodes/mix/concat.js",
59
- "padding": "node-red-contrib-image-tools/nodes/transform/padding.js",
60
- "filter": "node-red-contrib-image-tools/nodes/transform/filter.js",
61
- "draw": "node-red-contrib-image-tools/nodes/transform/draw.js",
62
- "color-convert": "node-red-contrib-image-tools/nodes/transform/color-convert.js",
63
- "mosaic": "node-red-contrib-image-tools/nodes/mix/mosaic.js",
64
- "advanced-mosaic": "node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js",
65
- "blend": "node-red-contrib-image-tools/nodes/blend/blend.js",
66
- "add-mask": "node-red-contrib-image-tools/nodes/blend/add-mask.js",
67
- "add-masks": "node-red-contrib-image-tools/nodes/blend/add-masks.js",
68
- "add-bbs": "node-red-contrib-image-tools/nodes/blend/add-bbs.js",
69
- "queue": "node-red-contrib-image-tools/nodes/io/queue.js",
70
- "save-file": "node-red-contrib-image-tools/nodes/io/save-file.js",
71
- "clean-debug": "node-red-contrib-image-tools/nodes/util/clean-debug.js",
72
- "block-detect": "node-red-contrib-image-tools/nodes/util/block-detect.js"
2
+ "name": "@rosepetal/node-red-contrib-image-tools",
3
+ "version": "1.3.0",
4
+ "description": "Node-RED Image Processing Toolkit",
5
+ "main": "install.sh",
6
+ "directories": {
7
+ "doc": "docs"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/rosepetal-ai/node-red-contrib-image-tools.git"
15
+ },
16
+ "keywords": [
17
+ "node-red",
18
+ "image",
19
+ "opencv",
20
+ "performance"
21
+ ],
22
+ "author": "Rosepetal SL (https://www.rosepetal.ai)",
23
+ "contributors": [
24
+ {
25
+ "name": "Nil Allue",
26
+ "email": "nil.allue@rosepetal.ai"
27
+ }
28
+ ],
29
+ "license": "Apache-2.0",
30
+ "bugs": {
31
+ "url": "https://github.com/rosepetal-ai/node-red-contrib-image-tools/issues"
32
+ },
33
+ "homepage": "https://github.com/rosepetal-ai/node-red-contrib-image-tools#readme",
34
+ "dependencies": {
35
+ "sharp": "^0.34.2"
36
+ },
37
+ "optionalDependencies": {
38
+ "@rosepetal/node-red-contrib-image-tools-linux-x64": "1.1.3",
39
+ "@rosepetal/node-red-contrib-image-tools-linux-arm64": "1.1.3",
40
+ "@rosepetal/node-red-contrib-image-tools-linuxmusl-x64": "1.1.3",
41
+ "@rosepetal/node-red-contrib-image-tools-darwin-x64": "1.1.3",
42
+ "@rosepetal/node-red-contrib-image-tools-darwin-arm64": "1.1.3"
43
+ },
44
+ "node-red": {
45
+ "version": ">=1.0.0",
46
+ "nodes": {
47
+ "rp-image-in": "node-red-contrib-image-tools/nodes/io/image-in.js",
48
+ "rp-folder-in": "node-red-contrib-image-tools/nodes/io/folder-in.js",
49
+ "rp-image-out": "node-red-contrib-image-tools/nodes/io/image-out.js",
50
+ "rp-array-in": "node-red-contrib-image-tools/nodes/io/array-in.js",
51
+ "rp-array-out": "node-red-contrib-image-tools/nodes/io/array-out.js",
52
+ "rp-array-select": "node-red-contrib-image-tools/nodes/io/array-select.js",
53
+ "rp-cropBB": "node-red-contrib-image-tools/nodes/specialized/cropBB.js",
54
+ "rp-image-align": "node-red-contrib-image-tools/nodes/specialized/image-align.js",
55
+ "rp-resize": "node-red-contrib-image-tools/nodes/transform/resize.js",
56
+ "rp-rotate": "node-red-contrib-image-tools/nodes/transform/rotate.js",
57
+ "rp-crop": "node-red-contrib-image-tools/nodes/transform/crop.js",
58
+ "rp-concat": "node-red-contrib-image-tools/nodes/mix/concat.js",
59
+ "rp-padding": "node-red-contrib-image-tools/nodes/transform/padding.js",
60
+ "rp-filter": "node-red-contrib-image-tools/nodes/transform/filter.js",
61
+ "rp-draw": "node-red-contrib-image-tools/nodes/transform/draw.js",
62
+ "rp-color-convert": "node-red-contrib-image-tools/nodes/transform/color-convert.js",
63
+ "rp-mosaic": "node-red-contrib-image-tools/nodes/mix/mosaic.js",
64
+ "rp-advanced-mosaic": "node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js",
65
+ "rp-blend": "node-red-contrib-image-tools/nodes/blend/blend.js",
66
+ "rp-add-mask": "node-red-contrib-image-tools/nodes/blend/add-mask.js",
67
+ "rp-add-masks": "node-red-contrib-image-tools/nodes/blend/add-masks.js",
68
+ "rp-add-bbs": "node-red-contrib-image-tools/nodes/blend/add-bbs.js",
69
+ "rp-queue": "node-red-contrib-image-tools/nodes/io/queue.js",
70
+ "rp-save-file": "node-red-contrib-image-tools/nodes/io/save-file.js",
71
+ "rp-clean-debug": "node-red-contrib-image-tools/nodes/util/clean-debug.js",
72
+ "rp-block-detect": "node-red-contrib-image-tools/nodes/util/block-detect.js"
73
73
  }
74
74
  }
75
75
  }
@@ -0,0 +1,267 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Legacy Compatibility Injection Script (CI use)
4
+ *
5
+ * Runs on source files that already use 'rp-' prefixed type names.
6
+ * Adds legacy registrations under the OLD names (without 'rp-' prefix)
7
+ * so existing user flows keep working after upgrading.
8
+ *
9
+ * - Legacy types are hidden from palette (category: 'deprecated')
10
+ * - Legacy template/help blocks are duplicated for old type names
11
+ * - Source code in git stays clean (rp- only)
12
+ * - Run this in CI before npm publish
13
+ *
14
+ * Usage: node scripts/dual-register.js [--dry-run]
15
+ */
16
+
17
+ const fs = require('fs');
18
+ const path = require('path');
19
+
20
+ const DRY_RUN = process.argv.includes('--dry-run');
21
+ const BASE = path.join(__dirname, '..', 'node-red-contrib-image-tools', 'nodes');
22
+
23
+ // Maps old type name → file path (old name is what gets added as legacy)
24
+ const NODES = [
25
+ { oldType: 'image-in', path: 'io/image-in' },
26
+ { oldType: 'folder-in', path: 'io/folder-in' },
27
+ { oldType: 'image-out', path: 'io/image-out' },
28
+ { oldType: 'resize', path: 'transform/resize' },
29
+ { oldType: 'crop', path: 'transform/crop' },
30
+ { oldType: 'rotate', path: 'transform/rotate' },
31
+ { oldType: 'padding', path: 'transform/padding' },
32
+ { oldType: 'filter', path: 'transform/filter' },
33
+ { oldType: 'draw', path: 'transform/draw' },
34
+ { oldType: 'color-convert', path: 'transform/color-convert' },
35
+ { oldType: 'concat', path: 'mix/concat' },
36
+ { oldType: 'mosaic', path: 'mix/mosaic' },
37
+ { oldType: 'advanced-mosaic', path: 'mix/advanced-mosaic' },
38
+ { oldType: 'blend', path: 'blend/blend' },
39
+ { oldType: 'add-mask', path: 'blend/add-mask' },
40
+ { oldType: 'add-masks', path: 'blend/add-masks' },
41
+ { oldType: 'add-bbs', path: 'blend/add-bbs' },
42
+ { oldType: 'cropBB', path: 'specialized/cropBB' },
43
+ { oldType: 'image-align', path: 'specialized/image-align' },
44
+ ];
45
+
46
+ function escapeRegex(str) {
47
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
48
+ }
49
+
50
+ /**
51
+ * Find the position of the matching closing brace for an opening brace.
52
+ * Handles nested braces, strings (single/double/template), line and block comments.
53
+ */
54
+ function findMatchingBrace(content, openPos) {
55
+ let depth = 0;
56
+ for (let i = openPos; i < content.length; i++) {
57
+ const ch = content[i];
58
+
59
+ // Skip single-quoted strings
60
+ if (ch === "'") {
61
+ i++;
62
+ while (i < content.length && content[i] !== "'") {
63
+ if (content[i] === '\\') i++;
64
+ i++;
65
+ }
66
+ continue;
67
+ }
68
+ // Skip double-quoted strings
69
+ if (ch === '"') {
70
+ i++;
71
+ while (i < content.length && content[i] !== '"') {
72
+ if (content[i] === '\\') i++;
73
+ i++;
74
+ }
75
+ continue;
76
+ }
77
+ // Skip template literals
78
+ if (ch === '`') {
79
+ i++;
80
+ while (i < content.length && content[i] !== '`') {
81
+ if (content[i] === '\\') i++;
82
+ i++;
83
+ }
84
+ continue;
85
+ }
86
+ // Skip line comments
87
+ if (ch === '/' && i + 1 < content.length && content[i + 1] === '/') {
88
+ i += 2;
89
+ while (i < content.length && content[i] !== '\n') i++;
90
+ continue;
91
+ }
92
+ // Skip block comments
93
+ if (ch === '/' && i + 1 < content.length && content[i + 1] === '*') {
94
+ i += 2;
95
+ while (i < content.length && !(content[i] === '*' && content[i + 1] === '/')) i++;
96
+ i++;
97
+ continue;
98
+ }
99
+
100
+ if (ch === '{') depth++;
101
+ else if (ch === '}') {
102
+ depth--;
103
+ if (depth === 0) return i;
104
+ }
105
+ }
106
+ return -1;
107
+ }
108
+
109
+ // ─────────────────────────────────────────────────────────────
110
+ // JS: Find registerType('rp-TYPE', C) → add registerType('TYPE', C)
111
+ // ─────────────────────────────────────────────────────────────
112
+
113
+ function addLegacyJs(filePath, oldType) {
114
+ const rpType = 'rp-' + oldType;
115
+ let content = fs.readFileSync(filePath, 'utf8');
116
+
117
+ // Find: RED.nodes.registerType('rp-TYPE', Constructor);
118
+ const regex = new RegExp(
119
+ `([ \\t]*)(RED\\.nodes\\.registerType\\s*\\(\\s*['"])${escapeRegex(rpType)}(['"]\\s*,\\s*)(\\w+)(\\s*\\)\\s*;)`,
120
+ );
121
+
122
+ const match = content.match(regex);
123
+ if (!match) {
124
+ console.error(` JS: ✗ Could not find registerType('${rpType}', ...) in ${path.basename(filePath)}`);
125
+ return false;
126
+ }
127
+
128
+ const [fullMatch, indent, prefix, midQuote, constructor, suffix] = match;
129
+
130
+ // Add legacy registration on the next line
131
+ const legacyLine = `\n${indent}${prefix}${oldType}${midQuote}${constructor}${suffix} // legacy compat`;
132
+
133
+ content = content.replace(fullMatch, fullMatch + legacyLine);
134
+
135
+ if (!DRY_RUN) fs.writeFileSync(filePath, content);
136
+ console.log(` JS: ✓ Added legacy registerType('${oldType}', ${constructor})`);
137
+ return true;
138
+ }
139
+
140
+ // ─────────────────────────────────────────────────────────────
141
+ // HTML: Add legacy registration + duplicate template/help
142
+ // ─────────────────────────────────────────────────────────────
143
+
144
+ function addLegacyHtmlRegistration(content, oldType) {
145
+ const rpType = 'rp-' + oldType;
146
+
147
+ // Find: RED.nodes.registerType('rp-TYPE',
148
+ const rtRegex = new RegExp(
149
+ `(RED\\.nodes\\.registerType\\s*\\(\\s*['"])${escapeRegex(rpType)}(['"]\\s*,\\s*)`,
150
+ );
151
+ const rtMatch = content.match(rtRegex);
152
+ if (!rtMatch) {
153
+ console.error(` HTML: ✗ Could not find registerType('${rpType}') in registration block`);
154
+ return null;
155
+ }
156
+
157
+ const rtStart = rtMatch.index;
158
+ const afterComma = rtStart + rtMatch[0].length;
159
+
160
+ // Find the opening { of the config object
161
+ let openBrace = afterComma;
162
+ while (openBrace < content.length && content[openBrace] !== '{') openBrace++;
163
+ if (openBrace >= content.length) {
164
+ console.error(` HTML: ✗ Could not find config object opening brace`);
165
+ return null;
166
+ }
167
+
168
+ // Find the matching closing }
169
+ const closeBrace = findMatchingBrace(content, openBrace);
170
+ if (closeBrace === -1) {
171
+ console.error(` HTML: ✗ Could not match braces for config object`);
172
+ return null;
173
+ }
174
+
175
+ // Find the ); that closes the registerType call
176
+ let callEnd = closeBrace + 1;
177
+ while (callEnd < content.length && /\s/.test(content[callEnd])) callEnd++;
178
+ if (callEnd < content.length && content[callEnd] === ')') callEnd++;
179
+ if (callEnd < content.length && content[callEnd] === ';') callEnd++;
180
+
181
+ // Extract config object text (already has rp- labels — that's fine for legacy too)
182
+ const configText = content.substring(openBrace, closeBrace + 1);
183
+
184
+ // Get indentation of the registerType line
185
+ const lineStart = content.lastIndexOf('\n', rtStart) + 1;
186
+ const indentMatch = content.substring(lineStart, rtStart).match(/^(\s*)/);
187
+ const indent = indentMatch ? indentMatch[1] : ' ';
188
+
189
+ // Replace: original registerType → _rpNodeCfg variable + rp-TYPE registration + legacy registration
190
+ const replacement =
191
+ `var _rpNodeCfg = ${configText};\n` +
192
+ `${indent}RED.nodes.registerType('${rpType}', _rpNodeCfg);\n` +
193
+ `${indent}RED.nodes.registerType('${oldType}', Object.assign({}, _rpNodeCfg, { category: 'deprecated' }));`;
194
+
195
+ return content.substring(0, rtStart) + replacement + content.substring(callEnd);
196
+ }
197
+
198
+ function addLegacyScriptBlock(content, attrName, oldType) {
199
+ const rpType = 'rp-' + oldType;
200
+
201
+ // Find the rp-TYPE block: <script type="text/x-red" data-xxx-name="rp-TYPE"> ... </script>
202
+ const regex = new RegExp(
203
+ `(<script\\s+type="text/(?:x-red|html)"\\s+${escapeRegex(attrName)}=")${escapeRegex(rpType)}(">[\\s\\S]*?</script>)`,
204
+ );
205
+
206
+ const match = content.match(regex);
207
+ if (!match) {
208
+ console.error(` HTML: ✗ Could not find ${attrName}="${rpType}" block`);
209
+ return content;
210
+ }
211
+
212
+ const fullBlock = match[0];
213
+ // Create legacy block with old type name (without rp- prefix)
214
+ const legacyBlock = match[1] + oldType + match[2];
215
+
216
+ // Append legacy block after the rp-TYPE block
217
+ return content.replace(fullBlock, fullBlock + '\n\n' + legacyBlock);
218
+ }
219
+
220
+ function addLegacyHtml(filePath, oldType) {
221
+ let content = fs.readFileSync(filePath, 'utf8');
222
+
223
+ // 1. Add legacy JS registration
224
+ const transformed = addLegacyHtmlRegistration(content, oldType);
225
+ if (transformed === null) return false;
226
+ content = transformed;
227
+
228
+ // 2. Duplicate template block for legacy type name
229
+ content = addLegacyScriptBlock(content, 'data-template-name', oldType);
230
+
231
+ // 3. Duplicate help block for legacy type name
232
+ content = addLegacyScriptBlock(content, 'data-help-name', oldType);
233
+
234
+ if (!DRY_RUN) fs.writeFileSync(filePath, content);
235
+ console.log(` HTML: ✓ Added legacy registration + template + help for '${oldType}'`);
236
+ return true;
237
+ }
238
+
239
+ // ─────────────────────────────────────────────────────────────
240
+ // Main
241
+ // ─────────────────────────────────────────────────────────────
242
+
243
+ console.log('=== Add Legacy Compatibility (CI) ===');
244
+ if (DRY_RUN) console.log('(DRY RUN — no files will be modified)\n');
245
+ else console.log('');
246
+
247
+ let jsOk = 0, htmlOk = 0, jsFail = 0, htmlFail = 0;
248
+
249
+ for (const node of NODES) {
250
+ console.log(`[${node.oldType}]`);
251
+ const jsFile = path.join(BASE, node.path + '.js');
252
+ const htmlFile = path.join(BASE, node.path + '.html');
253
+
254
+ if (addLegacyJs(jsFile, node.oldType)) jsOk++;
255
+ else jsFail++;
256
+
257
+ if (addLegacyHtml(htmlFile, node.oldType)) htmlOk++;
258
+ else htmlFail++;
259
+
260
+ console.log('');
261
+ }
262
+
263
+ console.log('\n=== Summary ===');
264
+ console.log(` JS: ${jsOk} ok, ${jsFail} failed`);
265
+ console.log(` HTML: ${htmlOk} ok, ${htmlFail} failed`);
266
+ if (DRY_RUN) console.log('\n(Dry run — re-run without --dry-run to apply changes)');
267
+ else console.log('\nDone! Legacy compatibility added. Ready to publish.');