@rosepetal/node-red-contrib-image-tools 1.1.3 → 1.2.2

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 (62) hide show
  1. package/README.md +1 -13
  2. package/node-red-contrib-image-tools/lib/node-utils.js +218 -17
  3. package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +64 -9
  4. package/node-red-contrib-image-tools/nodes/blend/add-mask.js +81 -9
  5. package/node-red-contrib-image-tools/nodes/blend/add-masks.js +64 -8
  6. package/node-red-contrib-image-tools/nodes/blend/blend.js +64 -10
  7. package/node-red-contrib-image-tools/nodes/io/folder-in.js +12 -1
  8. package/node-red-contrib-image-tools/nodes/io/image-in.js +10 -2
  9. package/node-red-contrib-image-tools/nodes/io/image-out.js +25 -3
  10. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +52 -26
  11. package/node-red-contrib-image-tools/nodes/mix/concat.js +46 -9
  12. package/node-red-contrib-image-tools/nodes/mix/mosaic.js +52 -15
  13. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +53 -5
  14. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +54 -7
  15. package/node-red-contrib-image-tools/nodes/transform/color-convert.html +189 -0
  16. package/node-red-contrib-image-tools/nodes/transform/color-convert.js +153 -0
  17. package/node-red-contrib-image-tools/nodes/transform/crop.js +38 -17
  18. package/node-red-contrib-image-tools/nodes/transform/draw.js +28 -7
  19. package/node-red-contrib-image-tools/nodes/transform/filter.js +34 -15
  20. package/node-red-contrib-image-tools/nodes/transform/padding.js +30 -9
  21. package/node-red-contrib-image-tools/nodes/transform/resize.js +58 -33
  22. package/node-red-contrib-image-tools/nodes/transform/rotate.html +5 -5
  23. package/node-red-contrib-image-tools/nodes/transform/rotate.js +40 -20
  24. package/node-red-contrib-image-tools/package.json +2 -8
  25. package/package.json +2 -1
  26. package/rosepetal-image-engine/binding.gyp +7 -24
  27. package/rosepetal-image-engine/src/add-mask.cpp +2 -2
  28. package/rosepetal-image-engine/src/add-masks.cpp +2 -2
  29. package/rosepetal-image-engine/src/advanced-mosaic.cpp +7 -8
  30. package/rosepetal-image-engine/src/blend.cpp +2 -2
  31. package/rosepetal-image-engine/src/color-convert.cpp +184 -0
  32. package/rosepetal-image-engine/src/concat.cpp +4 -4
  33. package/rosepetal-image-engine/src/crop.cpp +7 -7
  34. package/rosepetal-image-engine/src/draw.cpp +1 -1
  35. package/rosepetal-image-engine/src/filter.cpp +7 -7
  36. package/rosepetal-image-engine/src/image-align.cpp +1 -1
  37. package/rosepetal-image-engine/src/main.cpp +2 -0
  38. package/rosepetal-image-engine/src/mosaic.cpp +8 -9
  39. package/rosepetal-image-engine/src/padding.cpp +8 -7
  40. package/rosepetal-image-engine/src/resize.cpp +105 -27
  41. package/rosepetal-image-engine/src/rotate.cpp +9 -12
  42. package/rosepetal-image-engine/src/utils.h +48 -10
  43. package/docs/nodes/io/array-in.md +0 -119
  44. package/docs/nodes/io/array-out.md +0 -150
  45. package/docs/nodes/io/array-select.md +0 -157
  46. package/docs/nodes/io/queue.md +0 -57
  47. package/docs/nodes/io/save-file.md +0 -30
  48. package/docs/nodes/util/block-detect.md +0 -46
  49. package/node-red-contrib-image-tools/nodes/io/array-in.html +0 -110
  50. package/node-red-contrib-image-tools/nodes/io/array-in.js +0 -113
  51. package/node-red-contrib-image-tools/nodes/io/array-out.html +0 -125
  52. package/node-red-contrib-image-tools/nodes/io/array-out.js +0 -213
  53. package/node-red-contrib-image-tools/nodes/io/array-select.html +0 -156
  54. package/node-red-contrib-image-tools/nodes/io/array-select.js +0 -187
  55. package/node-red-contrib-image-tools/nodes/io/queue.html +0 -119
  56. package/node-red-contrib-image-tools/nodes/io/queue.js +0 -191
  57. package/node-red-contrib-image-tools/nodes/io/save-file.html +0 -243
  58. package/node-red-contrib-image-tools/nodes/io/save-file.js +0 -440
  59. package/node-red-contrib-image-tools/nodes/util/block-detect.html +0 -85
  60. package/node-red-contrib-image-tools/nodes/util/block-detect.js +0 -136
  61. package/node-red-contrib-image-tools/nodes/util/clean-debug.html +0 -201
  62. package/node-red-contrib-image-tools/nodes/util/clean-debug.js +0 -393
@@ -1,157 +0,0 @@
1
- # Array-Select Node
2
-
3
- ## Purpose & Use Cases
4
-
5
- The `array-select` node provides powerful array element selection with Python-like slicing syntax. It extracts specific elements, ranges, or patterns from arrays, making it essential for filtering and selecting processed results.
6
-
7
- **Real-World Applications:**
8
- - **Result Filtering**: Select best results from batch processing operations
9
- - **Data Sampling**: Extract samples from large datasets for analysis
10
- - **Quality Control**: Pick specific items that passed validation
11
- - **A/B Testing**: Select specific variants for comparison
12
- - **Image Gallery Creation**: Choose specific images from collections
13
-
14
- ![Array-Select Demo](../../../assets/nodes/io/array-select-demo.gif)
15
-
16
- ## Input/Output Specification
17
-
18
- ### Inputs
19
- - **Array Data**: Input array from the configured path
20
- - **Selection String**: Pattern specifying which elements to extract
21
-
22
- ### Outputs
23
- - **Single Element**: Direct element output (unless Force Array enabled)
24
- - **Multiple Elements**: Always output as array
25
- - **Invalid Selection**: No message sent, warning logged
26
-
27
- ## Configuration Options
28
-
29
- ### Input From
30
- - **Default**: `msg.payload`
31
- - **Options**:
32
- - `msg.*` - Read from message property
33
- - `flow.*` - Read from flow context
34
- - `global.*` - Read from global context
35
- - **Validation**: Input must be an array
36
-
37
- ### Selection Pattern
38
- - **Type**: String with flexible syntax
39
- - **Formats**:
40
- - **Single Index**: `0`, `2`, `-1`
41
- - **Multiple Indices**: `1,3,5` (comma-separated)
42
- - **Range**: `1:4` (slice from index 1 to 3)
43
- - **Step Pattern**: `0::2` (every 2nd element)
44
- - **Negative Indexing**: `-1` (last), `-2:` (last two)
45
-
46
- ### Force Array
47
- - **Type**: Boolean checkbox
48
- - **Default**: false
49
- - **Behavior**: When enabled, single elements output as arrays
50
- - **Use Case**: Ensure consistent array output format
51
-
52
- ## Performance Notes
53
-
54
- ### Selection Efficiency
55
- - **Minimal Memory Copy**: Efficient element extraction without full array duplication
56
- - **Index Validation**: Fast bounds checking with graceful error handling
57
- - **Pattern Parsing**: Optimized pattern recognition and processing
58
- - **Status Display**: Real-time selection information and processing state
59
-
60
- ### Error Handling
61
- - **Input Validation**: Comprehensive array and pattern validation
62
- - **Graceful Degradation**: Invalid indices skipped with warnings
63
- - **Bounds Checking**: Out-of-range indices handled safely
64
-
65
- ## Selection Syntax Guide
66
-
67
- ### Basic Selection
68
- ```
69
- Array: ["A", "B", "C", "D", "E"]
70
-
71
- 0 → "A" // First element
72
- -1 → "E" // Last element
73
- 1,3 → ["B", "D"] // Multiple specific indices
74
- ```
75
-
76
- ### Range Selection
77
- ```
78
- Array: ["A", "B", "C", "D", "E"]
79
-
80
- 1:4 → ["B", "C", "D"] // Range from 1 to 3
81
- 0:3 → ["A", "B", "C"] // First three elements
82
- -2: → ["D", "E"] // Last two elements
83
- ```
84
-
85
- ### Step Patterns
86
- ```
87
- Array: ["A", "B", "C", "D", "E", "F"]
88
-
89
- 0::2 → ["A", "C", "E"] // Every 2nd starting at 0
90
- 1::2 → ["B", "D", "F"] // Every 2nd starting at 1
91
- 1:5:2 → ["B", "D"] // Range 1-4, every 2nd
92
- ```
93
-
94
- ### Advanced Patterns
95
- ```
96
- Array: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
97
-
98
- ::3 → [0, 3, 6, 9] // Every 3rd element
99
- 2:8:2 → [2, 4, 6] // Range 2-7, step 2
100
- -3: → [7, 8, 9] // Last 3 elements
101
- :-3 → [0, 1, 2, 3, 4, 5, 6] // All but last 3
102
- ```
103
-
104
- ## Real-World Examples
105
-
106
- ### Best Result Selection
107
- ```
108
- [Batch Process] → [Array-Out] → [Array-Select: "0,2,4"] → [Top Results]
109
- ```
110
- Select 1st, 3rd, and 5th results from batch processing.
111
-
112
- ### Quality Control Sampling
113
- ```
114
- [Production Line] → [Array-Out] → [Array-Select: "::10"] → [Quality Check]
115
- ```
116
- Sample every 10th item for quality inspection.
117
-
118
- ### Image Gallery Creation
119
- ```
120
- [Image Array] → [Array-Select: "1:6"] → [Display Gallery]
121
- ```
122
- Select images 2-6 for gallery display.
123
-
124
- ### A/B Test Splitting
125
- ```
126
- [User Array] → [Array-Select: "0::2"] → [Group A]
127
- → [Array-Select: "1::2"] → [Group B]
128
- ```
129
- Split users into alternating test groups.
130
-
131
- ### Last N Results
132
- ```
133
- [Processing Queue] → [Array-Out] → [Array-Select: "-5:"] → [Recent Results]
134
- ```
135
- Get the last 5 processed items.
136
-
137
- ## Common Issues & Troubleshooting
138
-
139
- ### Invalid Input Type
140
- - **Issue**: Input is not an array
141
- - **Result**: Warning logged, message not sent
142
- - **Solution**: Verify input is array type, use array-out to create arrays
143
-
144
- ### Out of Bounds Indices
145
- - **Issue**: Selection indices exceed array length
146
- - **Result**: Invalid indices ignored, partial results returned
147
- - **Example**: Array length 5, selection "1,3,7" returns elements at indices 1,3 only
148
-
149
- ### Empty Selection Results
150
- - **Issue**: Selection pattern matches no elements
151
- - **Result**: Empty array `[]` output
152
- - **Common Cause**: Range beyond array bounds
153
-
154
- ### Syntax Errors
155
- - **Issue**: Invalid selection pattern syntax
156
- - **Result**: Warning logged, message not sent
157
- - **Solution**: Verify pattern follows documented syntax
@@ -1,57 +0,0 @@
1
- # Queue Node
2
-
3
- ## Purpose & Use Cases
4
-
5
- The `queue` node buffers incoming messages, enforces a minimum interval between outputs, and discards stale entries. It helps coordinate bursty producers with slower consumers by smoothing throughput and avoiding overload.
6
-
7
- **Common Scenarios:**
8
- - Throttle high-frequency image sources before storage or slow analysis stages
9
- - Prevent downstream rate limits from being exceeded when batch processing arrays
10
- - Provide simple back-pressure where only a fixed number of messages can be buffered
11
- - Drop stale detections or frames that are no longer relevant after a timeout
12
-
13
- ## Input/Output Specification
14
-
15
- ### Inputs
16
- - **Incoming Message**: Any Node-RED message to be enqueued.
17
-
18
- ### Outputs
19
- - **Queued Message**: Messages are forwarded in FIFO order while respecting the configured interval.
20
-
21
- When timeout mode is selected, messages that exceed the configured timeout are silently discarded with a warning in the node's log.
22
-
23
- ## Configuration Options
24
-
25
- ### Mode
26
- - **Type**: Dropdown (`Queue Size Limit` / `Timeout`)
27
- - **Default**: `Queue Size Limit`
28
- - **Purpose**: Select whether the node enforces a hard buffer capacity or lets messages expire after a timeout; the controls shown below change depending on the selected mode.
29
-
30
- ### Queue Size Limit
31
- - **Type**: Number (integer)
32
- - **Default**: `0` (no limit)
33
- - **Purpose**: Available only in queue-size mode. Controls how many messages may be enqueued before excess messages are ignored.
34
-
35
- ### Timeout (ms)
36
- - **Type**: Number (integer)
37
- - **Default**: `0` (no timeout)
38
- - **Purpose**: Available only in timeout mode. Messages that stay longer than this duration are removed before they reach the output.
39
-
40
- ### Interval (ms)
41
- - **Type**: Number (integer)
42
- - **Default**: `0` (no enforced delay)
43
- - **Purpose**: Minimum time that must elapse between forwarded messages. When set to 0, messages flow out as soon as they are available.
44
-
45
- ## Behavior & Status
46
-
47
- - Messages are processed in first-in-first-out order.
48
- - The node emits messages immediately when the interval requirement has already been satisfied.
49
- - If necessary, the node waits the remaining interval before releasing the next message.
50
- - When messages expire due to timeout (and timeout mode is active) they are removed from the queue and a warning is logged.
51
- - Node status indicates whether the queue is idle, holding messages, or actively sending.
52
-
53
- ## Best Practices
54
-
55
- - Pair with Array nodes to control the rate of batch processing pipelines.
56
- - Use timeouts to keep sensor readings or camera frames current.
57
- - Combine with Catch or Status nodes to monitor when the queue reaches capacity or drops messages.
@@ -1,30 +0,0 @@
1
- # save-file
2
-
3
- Write incoming data to disk as an image, JSON, text, or binary file. The node can auto-detect the best mode from the payload or a provided filename/extension.
4
-
5
- ## Inputs
6
- - **payload** (default): Data to write. Supports raw image objects (`{data,width,height,channels,colorSpace}`), encoded image buffers, plain objects/arrays, strings, or buffers.
7
- - **Alternative path**: Use the *Input* field to read from any `msg`/`flow`/`global` property.
8
-
9
- ## Properties
10
- - **Folder** (*str | env | msg | flow | global*) – Destination directory. Created if missing.
11
- - **Filename** (*str | msg | flow | global*) – Optional name without path separators. If left blank, a timestamped name is generated. If you include an extension here, it is respected.
12
- - **File Type** (*auto | image | json | text | binary*) – Force the save mode or let the node decide. Auto uses the extension, raw image structure, or Sharp metadata for buffers.
13
- - **Image Format** (*jpg | png | webp*) – Encoding for image saves. Quality and PNG optimization are available.
14
- - **JSON Indent** – Spacing for pretty-printed JSON output.
15
- - **Overwrite protection** – Enabled by default; adds a numeric suffix when the file already exists.
16
- - **Result to** – Where to store summary metadata `{ path, filename, type, extension, sizeBytes, format? }` (default `msg.savedFile`).
17
-
18
- ## Behavior
19
- - Raw image inputs are validated and encoded with Sharp; BGR/BGRA channels are auto-swapped.
20
- - JSON inputs are pretty-printed; valid JSON strings are kept as-is.
21
- - Text mode writes stringified content; binary mode writes buffers directly (or stringified when not a buffer).
22
- - When overwrite protection is enabled, the node keeps adding `_<n>` until a free filename is found.
23
-
24
- ## Status
25
- - Shows the final filename, duration, and whether an overwrite was avoided.
26
-
27
- ## Example flows
28
- - Save final inference results as `results.json` in `/data/out`.
29
- - Persist camera frames as WebP by setting *File Type = image* and *Image Format = webp*.
30
- - Archive arbitrary payloads by pointing *Input* to `msg.myBuffer` and enabling overwrite protection.
@@ -1,46 +0,0 @@
1
- # Block Detect Node
2
-
3
- ## Purpose & Use Cases
4
-
5
- The `block-detect` node gives you a lightweight watchdog that keeps an eye on Node-RED's event loop. When long running synchronous work or runaway CPU usage blocks the event loop, flows become sluggish, timers fire late, and HTTP endpoints stall. Dropping this node anywhere in your workspace makes it easy to detect those situations without wiring any messages.
6
-
7
- **Typical scenarios**
8
-
9
- - **Production health checks** &mdash; raise a warning in the runtime log when flows or custom code keep the event loop busy for too long.
10
- - **Profiling new nodes** &mdash; temporarily add the node next to experimental flows to confirm they remain non-blocking.
11
- - **Shared environments** &mdash; monitor collaborative / multi-tenant Node-RED instances for noisy neighbours that block everyone else.
12
-
13
- ## How It Works
14
-
15
- - The node samples the Node.js [`monitorEventLoopDelay`](https://nodejs.org/api/perf_hooks.html#perf_hooks_monitor_event_loop_delay_options) histogram every *N* milliseconds (default one second).
16
- - When the measured delay exceeds the configured threshold for a number of consecutive samples, the node writes an alert to the runtime log (`warn`, `error`, or plain `log`) and changes its editor status to red.
17
- - If `monitorEventLoopDelay` is unavailable (very old Node.js builds), it falls back to measuring timer drift, which still provides a useful signal with minimal CPU overhead.
18
- - A cooldown timer prevents log flooding when the system stays blocked for longer periods.
19
-
20
- ## Configuration
21
-
22
- | Option | Description |
23
- |--------|-------------|
24
- | **Threshold (ms)** | Maximum acceptable event loop delay. Samples above this value count as "blocking". Default: `120 ms`. |
25
- | **Sample interval (ms)** | How often to collect a measurement. Smaller values react faster but use slightly more CPU. Default: `1000 ms`. |
26
- | **Consecutive hits** | Number of back-to-back samples that must exceed the threshold before an alert fires. Helps filter out one-off spikes. Default: `1`. |
27
- | **Cooldown (ms)** | Minimum time between alerts so your logs do not get spammed while a problem persists. Default: `30,000 ms`. |
28
- | **Show live delay metrics** | When enabled (default) the node's status displays the latest average and max delay so you can watch it in real time. |
29
-
30
- The node has no inputs or outputs and can sit anywhere in your flow.
31
-
32
- > The watchdog internally samples `monitorEventLoopDelay` with a medium (20&nbsp;ms) resolution, which provides enough fidelity for alerts while keeping CPU overhead negligible.
33
-
34
- Alerts are always emitted with `node.warn(...)` so they appear in the standard Node-RED log without additional configuration.
35
-
36
- ## Interpreting the Status
37
-
38
- - **Green dot** &mdash; Event loop delay is within the safe range.
39
- - **Yellow ring** &mdash; Recent samples exceeded the threshold but not enough to trigger an alert yet.
40
- - **Red dot** &mdash; Blocking detected. Check the runtime log for details about the max/avg delay.
41
-
42
- ## Tips
43
-
44
- - Run multiple watchdogs with different thresholds (for example *warn at 120&nbsp;ms*, *error at 500&nbsp;ms*) if you want layered alerting.
45
- - Pair the node with system level monitoring (CPU, memory) to quickly confirm whether the blocking originated from Node-RED or external processes.
46
- - Because the watchdog is passive and does not emit messages, it is safe to leave it deployed permanently even in large workspaces.
@@ -1,110 +0,0 @@
1
- <script type="text/javascript">
2
- RED.nodes.registerType('array-in', {
3
- category: 'RP Image',
4
- color: '#87CEEB',
5
- defaults: {
6
- name: { value: "" },
7
- inputPath: { value: "payload" },
8
- inputPathType: { value: "msg" },
9
- arrayPositionType: { value: "num" },
10
- arrayPositionValue: { value: 0 }
11
- },
12
- inputs: 1,
13
- outputs: 1,
14
- icon: "font-awesome/fa-sign-in",
15
- label: function() {
16
- if (this.name) return this.name;
17
-
18
- const posDisplay = this.arrayPositionType === 'num'
19
- ? this.arrayPositionValue
20
- : `${this.arrayPositionType}.${this.arrayPositionValue}`;
21
- return `Array In [${posDisplay}]`;
22
- },
23
- oneditprepare: function() {
24
- // Set up TypedInput for input path
25
- $("#node-input-inputPath").typedInput({
26
- default: 'msg',
27
- types: ['msg', 'flow', 'global'],
28
- typeField: "#node-input-inputPathType"
29
- });
30
-
31
- // Set up TypedInput for array position
32
- $("#node-input-arrayPositionValue").typedInput({
33
- default: 'num',
34
- types: ['num', 'msg', 'flow', 'global'],
35
- typeField: "#node-input-arrayPositionType"
36
- });
37
- }
38
- });
39
- </script>
40
-
41
- <script type="text/x-red" data-template-name="array-in">
42
- <div class="form-row">
43
- <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
44
- <input type="text" id="node-input-name" placeholder="Name">
45
- </div>
46
-
47
- <hr>
48
-
49
- <div class="form-row">
50
- <label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input from</label>
51
- <input type="text" id="node-input-inputPath" style="width: 70%;">
52
- <input type="hidden" id="node-input-inputPathType">
53
- </div>
54
-
55
- <div class="form-row">
56
- <label for="node-input-arrayPositionValue"><i class="fa fa-sort-numeric-asc"></i> Array Position</label>
57
- <input type="text" id="node-input-arrayPositionValue" style="width: 70%;" placeholder="0">
58
- <input type="hidden" id="node-input-arrayPositionType">
59
- </div>
60
-
61
- <div class="form-tips">
62
- <b>Tip:</b> Array position can be a fixed number (starting from 0) or dynamically resolved from msg, flow, or global context. This determines where this data will be placed in the output array.
63
- </div>
64
- </script>
65
-
66
- <script type="text/x-red" data-help-name="array-in">
67
- <p>Collects data from a specified input path and tags it for ordered array assembly with a position index.</p>
68
-
69
- <h3>Details</h3>
70
- <p>This node is designed to work with the array-out node to create ordered arrays from multiple data sources. It extracts data from the specified input path and tags it with a position index, allowing multiple array-in nodes to feed into a single array-out node for ordered collection.</p>
71
-
72
- <h3>Properties</h3>
73
- <dl class="message-properties">
74
- <dt>Input from <span class="property-type">string</span></dt>
75
- <dd>The location to read data from. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
76
- <dt>Array Position <span class="property-type">number | msg | flow | global</span></dt>
77
- <dd>The index position (0, 1, 2...) where this data should be placed in the final array. Can be a fixed number or dynamically resolved from message properties, flow context, or global context. Must resolve to a non-negative integer.</dd>
78
- </dl>
79
-
80
- <h3>Inputs</h3>
81
- <dl class="message-properties">
82
- <dt>payload <span class="property-type">any</span></dt>
83
- <dd>Input message containing the data to be extracted. The actual data location is determined by the "Input from" property. The payload is only replaced when the input is set to <code>msg.payload</code>; otherwise it is left untouched.</dd>
84
- </dl>
85
-
86
- <h3>Outputs</h3>
87
- <p>The node passes through the original message with added metadata for array assembly. When the input path is <code>msg.payload</code> the payload is mirrored; for all other inputs the existing payload is preserved and only the metadata is updated.</p>
88
- <dl class="message-properties">
89
- <dt>meta.arrayPosition <span class="property-type">number</span></dt>
90
- <dd>The configured array position index.</dd>
91
- <dt>meta.arrayData <span class="property-type">any</span></dt>
92
- <dd>The data extracted from the specified input path.</dd>
93
- </dl>
94
-
95
- <h3>Examples</h3>
96
- <ul>
97
- <li><strong>Basic Array Assembly:</strong> Three array-in nodes with positions 0, 1, 2 feeding into an array-out will create: <code>[data0, data1, data2]</code></li>
98
- <li><strong>Dynamic Positioning:</strong> Set array position from <code>msg.index</code> to dynamically determine where data should be placed based on message content</li>
99
- <li><strong>Image Collection:</strong> Multiple image-in nodes → array-in nodes (positions 0, 1, 2...) → array-out → transform nodes that support arrays</li>
100
- <li><strong>Mixed Data Sources:</strong> Combine data from different context levels (msg, flow, global) into a single ordered array</li>
101
- <li><strong>Conditional Assembly:</strong> Use flow variables to set positions based on processing conditions or user preferences</li>
102
- </ul>
103
-
104
- <h3>Node Interactions</h3>
105
- <p><strong>Works with:</strong> Must be used with array-out node for array assembly. Can receive data from any node that outputs to the specified input path.</p>
106
- <p><strong>Best Practice:</strong> Use sequential positions starting from 0, ensure each array-in node connected to the same array-out has a unique position.</p>
107
-
108
- <h3>Error Handling</h3>
109
- <p>If the input path contains no data or is invalid, the node will set <code>meta.arrayData</code> to <code>null</code> and display a warning.</p>
110
- </script>
@@ -1,113 +0,0 @@
1
- /**
2
- * @file Node.js logic for the Array-In node with input path and array position.
3
- * @author Rosepetal
4
- */
5
-
6
- module.exports = function(RED) {
7
- const NodeUtils = require('../../lib/node-utils.js')(RED);
8
-
9
- function ArrayInNode(config) {
10
- RED.nodes.createNode(this, config);
11
- const node = this;
12
-
13
- // Store configuration with validation
14
- node.inputPath = config.inputPath || 'payload';
15
- node.inputPathType = config.inputPathType || 'msg';
16
-
17
- // Dynamic position configuration
18
- node.arrayPositionType = config.arrayPositionType || 'num';
19
- node.arrayPositionValue = config.arrayPositionValue !== undefined ? config.arrayPositionValue : 0;
20
-
21
- // Set initial status
22
- const statusText = node.arrayPositionType === 'num'
23
- ? `Position: ${node.arrayPositionValue}`
24
- : `Position: ${node.arrayPositionType}.${node.arrayPositionValue}`;
25
- node.status({
26
- fill: "blue",
27
- shape: "dot",
28
- text: statusText
29
- });
30
-
31
- // Handle incoming messages
32
- node.on('input', function(msg, send, done) {
33
- try {
34
- // Resolve array position dynamically
35
- let resolvedPosition;
36
- try {
37
- resolvedPosition = NodeUtils.resolveArrayPosition(
38
- node,
39
- node.arrayPositionType,
40
- node.arrayPositionValue,
41
- msg
42
- );
43
- } catch (err) {
44
- node.warn(`Failed to resolve array position: ${err.message}`);
45
- node.status({ fill: "red", shape: "ring", text: "Invalid position" });
46
- return done ? done() : null;
47
- }
48
-
49
- // Get data from configured input path
50
- let arrayData;
51
- if (node.inputPathType === 'msg') {
52
- arrayData = RED.util.getMessageProperty(msg, node.inputPath);
53
- } else if (node.inputPathType === 'flow') {
54
- arrayData = node.context().flow.get(node.inputPath);
55
- } else if (node.inputPathType === 'global') {
56
- arrayData = node.context().global.get(node.inputPath);
57
- }
58
-
59
- // Handle undefined data gracefully
60
- if (arrayData === undefined) {
61
- node.warn(`No data found at ${node.inputPathType}.${node.inputPath}`);
62
- arrayData = null;
63
- }
64
-
65
- // Initialize msg.meta if it doesn't exist
66
- if (!msg.meta) {
67
- msg.meta = {};
68
- }
69
-
70
- // Add array metadata and optionally mirror into payload
71
- msg.meta.arrayPosition = resolvedPosition;
72
- msg.meta.arrayData = arrayData;
73
-
74
- const normalizedPath = typeof node.inputPath === 'string'
75
- ? node.inputPath.trim()
76
- : node.inputPath;
77
- const shouldMirrorPayload =
78
- node.inputPathType === 'msg' &&
79
- normalizedPath === 'payload';
80
-
81
- if (shouldMirrorPayload) {
82
- msg.payload = arrayData;
83
- }
84
-
85
- // Update status
86
- node.status({
87
- fill: "green",
88
- shape: "dot",
89
- text: `Position: ${resolvedPosition}`
90
- });
91
-
92
- // Send the message with array metadata
93
- send(msg);
94
- if (done) { done(); }
95
-
96
- } catch (err) {
97
- node.status({ fill: "red", shape: "ring", text: "Error" });
98
- if (done) {
99
- done(err);
100
- } else {
101
- node.error(err, msg);
102
- }
103
- }
104
- });
105
-
106
- // Clean up on node removal
107
- node.on('close', function() {
108
- node.status({});
109
- });
110
- }
111
-
112
- RED.nodes.registerType("array-in", ArrayInNode);
113
- };
@@ -1,125 +0,0 @@
1
- <script type="text/javascript">
2
- RED.nodes.registerType('array-out', {
3
- category: 'RP Image',
4
- color: '#87CEEB',
5
- defaults: {
6
- name: { value: "" },
7
- timeout: { value: 5000 },
8
- expectedCount: { value: 2, required: true, validate: RED.validators.number() },
9
- outputPath: { value: "payload" },
10
- outputPathType: { value: "msg" }
11
- },
12
- inputs: 1,
13
- outputs: 2,
14
- icon: "font-awesome/fa-sign-out",
15
- label: function() {
16
- return this.name || `Array Out (${this.expectedCount} items)`;
17
- },
18
- oneditprepare: function() {
19
- // Set up TypedInput for output path
20
- $("#node-input-outputPath").typedInput({
21
- default: 'msg',
22
- types: ['msg', 'flow', 'global'],
23
- typeField: "#node-input-outputPathType"
24
- });
25
- }
26
- });
27
- </script>
28
-
29
- <script type="text/x-red" data-template-name="array-out">
30
- <div class="form-row">
31
- <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
32
- <input type="text" id="node-input-name" placeholder="Name">
33
- </div>
34
-
35
- <hr>
36
-
37
- <div class="form-row">
38
- <label for="node-input-timeout"><i class="fa fa-clock-o"></i> Timeout (ms)</label>
39
- <input type="number" id="node-input-timeout" min="100" step="100" style="width: 70%;" placeholder="5000">
40
- </div>
41
-
42
- <div class="form-row">
43
- <label for="node-input-expectedCount"><i class="fa fa-hashtag"></i> Expected Count</label>
44
- <input type="number" id="node-input-expectedCount" min="1" step="1" style="width: 70%;" placeholder="2" required>
45
- </div>
46
-
47
- <div class="form-row">
48
- <label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output to</label>
49
- <input type="text" id="node-input-outputPath" style="width: 70%;">
50
- <input type="hidden" id="node-input-outputPathType">
51
- </div>
52
-
53
- <div class="form-tips">
54
- <b>Timeout:</b> Maximum time to wait for all array elements after the first message arrives. If timeout occurs, collected data and missing position info are sent to output 2.<br>
55
- <b>Expected Count:</b> Number of array elements required before outputting the assembled array.
56
- </div>
57
- </script>
58
-
59
- <script type="text/x-red" data-help-name="array-out">
60
- <p>Collects messages from multiple array-in nodes and assembles them into an ordered array based on position indices.</p>
61
-
62
- <h3>Details</h3>
63
- <p>This node works as the collection point for multiple array-in nodes. It waits for messages containing array metadata, collects them based on their position indices, and outputs a complete array when all expected elements are received. The node includes timeout protection and performance monitoring.</p>
64
-
65
- <h3>Properties</h3>
66
- <dl class="message-properties">
67
- <dt>Timeout <span class="property-type">number</span></dt>
68
- <dd>Maximum time in milliseconds to wait for all array elements after the first message arrives. Default: 5000ms. If timeout occurs, collected data and missing position info are sent to output 2.</dd>
69
- <dt>Expected Count <span class="property-type">number</span></dt>
70
- <dd>Number of array elements required before outputting the assembled array. Must match the number of array-in nodes connected. Required field, minimum value: 1.</dd>
71
- <dt>Output to <span class="property-type">string</span></dt>
72
- <dd>The location where the assembled array 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>
73
- </dl>
74
-
75
- <h3>Inputs</h3>
76
- <dl class="message-properties">
77
- <dt>payload <span class="property-type">any</span></dt>
78
- <dd>Messages from array-in nodes containing array metadata.</dd>
79
- <dt>meta.arrayPosition <span class="property-type">number</span></dt>
80
- <dd>The array position index (0, 1, 2...) provided by array-in nodes.</dd>
81
- <dt>meta.arrayData <span class="property-type">any</span></dt>
82
- <dd>The actual data to be placed in the array at the specified position.</dd>
83
- </dl>
84
-
85
- <h3>Outputs</h3>
86
- <dl class="message-properties">
87
- <dt>Output 1 - Complete Array <span class="property-type">array</span></dt>
88
- <dd>The complete assembled array when all expected elements are received: [data0, data1, data2...]</dd>
89
- <dt>Output 2 - Timeout Data <span class="property-type">object</span></dt>
90
- <dd>On timeout: collected data array (with nulls for missing) plus metadata about missing positions</dd>
91
- </dl>
92
-
93
- <h3>Operation Flow</h3>
94
- <ol>
95
- <li><strong>First Message:</strong> Starts timeout timer and begins collection</li>
96
- <li><strong>Collection:</strong> Gathers messages from array-in nodes, validates positions</li>
97
- <li><strong>Assembly:</strong> Places data at specified array positions based on meta.arrayPosition</li>
98
- <li><strong>Success:</strong> Outputs assembled array when all expected elements received</li>
99
- <li><strong>Timeout:</strong> Sends collected data + missing info to output 2</li>
100
- <li><strong>Reset:</strong> Ready for next collection cycle</li>
101
- </ol>
102
-
103
- <h3>Examples</h3>
104
- <ul>
105
- <li><strong>Basic Array Assembly:</strong> With Expected Count = 3, array-in nodes at positions 0, 1, 2 will produce: <code>["data0", "data1", "data2"]</code></li>
106
- <li><strong>Image Array:</strong> Three image-in → array-in (positions 0,1,2) → array-out → creates array of image objects for batch processing</li>
107
- <li><strong>Mixed Data:</strong> Combine different data types from various sources into a single ordered array</li>
108
- </ul>
109
-
110
- <h3>Node Interactions</h3>
111
- <p><strong>Requires:</strong> Multiple array-in nodes, each with unique position indices (0, 1, 2...)</p>
112
- <p><strong>Works with:</strong> Transform nodes that support array inputs (resize, rotate, etc.), array-select for element extraction</p>
113
- <p><strong>Best Practice:</strong> Set Expected Count to match the number of array-in nodes. Use reasonable timeout values based on your processing requirements.</p>
114
-
115
- <h3>Error Handling</h3>
116
- <p>The node handles various error conditions:</p>
117
- <ul>
118
- <li><strong>Missing metadata:</strong> Messages without proper array metadata are ignored</li>
119
- <li><strong>Duplicate positions:</strong> Later messages overwrite earlier ones at the same position</li>
120
- <li><strong>Timeout:</strong> Collection resets, node status shows timeout, no output sent</li>
121
- </ul>
122
-
123
- <h3>Performance</h3>
124
- <p>Node status displays collection timing when successful. The timeout mechanism prevents indefinite waiting for missing array elements.</p>
125
- </script>