@rosepetal/node-red-contrib-image-tools 1.1.3 → 1.2.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.
- package/README.md +1 -13
- package/node-red-contrib-image-tools/lib/node-utils.js +218 -17
- package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +64 -9
- package/node-red-contrib-image-tools/nodes/blend/add-mask.js +81 -9
- package/node-red-contrib-image-tools/nodes/blend/add-masks.js +64 -8
- package/node-red-contrib-image-tools/nodes/blend/blend.js +64 -10
- package/node-red-contrib-image-tools/nodes/io/folder-in.js +12 -1
- package/node-red-contrib-image-tools/nodes/io/image-in.js +10 -2
- package/node-red-contrib-image-tools/nodes/io/image-out.js +25 -3
- package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +52 -26
- package/node-red-contrib-image-tools/nodes/mix/concat.js +46 -9
- package/node-red-contrib-image-tools/nodes/mix/mosaic.js +52 -15
- package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +53 -5
- package/node-red-contrib-image-tools/nodes/specialized/image-align.js +54 -7
- package/node-red-contrib-image-tools/nodes/transform/crop.js +38 -17
- package/node-red-contrib-image-tools/nodes/transform/draw.js +28 -7
- package/node-red-contrib-image-tools/nodes/transform/filter.js +34 -15
- package/node-red-contrib-image-tools/nodes/transform/padding.js +30 -9
- package/node-red-contrib-image-tools/nodes/transform/resize.js +58 -33
- package/node-red-contrib-image-tools/nodes/transform/rotate.js +40 -20
- package/node-red-contrib-image-tools/package.json +1 -8
- package/package.json +1 -1
- package/rosepetal-image-engine/binding.gyp +5 -23
- package/rosepetal-image-engine/src/add-mask.cpp +2 -2
- package/rosepetal-image-engine/src/add-masks.cpp +2 -2
- package/rosepetal-image-engine/src/advanced-mosaic.cpp +3 -4
- package/rosepetal-image-engine/src/blend.cpp +2 -2
- package/rosepetal-image-engine/src/concat.cpp +2 -2
- package/rosepetal-image-engine/src/crop.cpp +3 -3
- package/rosepetal-image-engine/src/draw.cpp +1 -1
- package/rosepetal-image-engine/src/filter.cpp +3 -3
- package/rosepetal-image-engine/src/mosaic.cpp +4 -5
- package/rosepetal-image-engine/src/padding.cpp +4 -3
- package/rosepetal-image-engine/src/resize.cpp +101 -23
- package/rosepetal-image-engine/src/rotate.cpp +3 -6
- package/rosepetal-image-engine/src/utils.h +46 -8
- package/docs/nodes/io/array-in.md +0 -119
- package/docs/nodes/io/array-out.md +0 -150
- package/docs/nodes/io/array-select.md +0 -157
- package/docs/nodes/io/queue.md +0 -57
- package/docs/nodes/io/save-file.md +0 -30
- package/docs/nodes/util/block-detect.md +0 -46
- package/node-red-contrib-image-tools/nodes/io/array-in.html +0 -110
- package/node-red-contrib-image-tools/nodes/io/array-in.js +0 -113
- package/node-red-contrib-image-tools/nodes/io/array-out.html +0 -125
- package/node-red-contrib-image-tools/nodes/io/array-out.js +0 -213
- package/node-red-contrib-image-tools/nodes/io/array-select.html +0 -156
- package/node-red-contrib-image-tools/nodes/io/array-select.js +0 -187
- package/node-red-contrib-image-tools/nodes/io/queue.html +0 -119
- package/node-red-contrib-image-tools/nodes/io/queue.js +0 -191
- package/node-red-contrib-image-tools/nodes/io/save-file.html +0 -243
- package/node-red-contrib-image-tools/nodes/io/save-file.js +0 -440
- package/node-red-contrib-image-tools/nodes/util/block-detect.html +0 -85
- package/node-red-contrib-image-tools/nodes/util/block-detect.js +0 -136
- package/node-red-contrib-image-tools/nodes/util/clean-debug.html +0 -201
- package/node-red-contrib-image-tools/nodes/util/clean-debug.js +0 -393
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Node.js logic for the Array‑Out node with timeout, ordering and validation.
|
|
3
|
-
* @author Rosepetal
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
module.exports = function (RED) {
|
|
7
|
-
function ArrayOutNode(config) {
|
|
8
|
-
RED.nodes.createNode(this, config);
|
|
9
|
-
const node = this;
|
|
10
|
-
|
|
11
|
-
/* ────────────────────────────
|
|
12
|
-
░░ 1. Read & validate cfg ░░
|
|
13
|
-
──────────────────────────── */
|
|
14
|
-
node.timeout = parseInt(config.timeout) || 5000;
|
|
15
|
-
node.expectedCount = parseInt(config.expectedCount);
|
|
16
|
-
node.outputPath = config.outputPath || 'payload';
|
|
17
|
-
node.outputPathType = config.outputPathType || 'msg';
|
|
18
|
-
|
|
19
|
-
if (!Number.isInteger(node.expectedCount) || node.expectedCount < 1) {
|
|
20
|
-
node.error('Invalid expectedCount. Must be a positive integer.');
|
|
21
|
-
node.expectedCount = 2; // sensible default
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/* ────────────────────────────
|
|
25
|
-
░░ 2. Internal state ░░
|
|
26
|
-
──────────────────────────── */
|
|
27
|
-
node.collection = {};
|
|
28
|
-
node.timeoutHandle = null;
|
|
29
|
-
node.isCollecting = false;
|
|
30
|
-
node.collectionStartTime = null;
|
|
31
|
-
|
|
32
|
-
setStatusReady();
|
|
33
|
-
|
|
34
|
-
/* ────────────────────────────
|
|
35
|
-
░░ 3. Helper functions ░░
|
|
36
|
-
──────────────────────────── */
|
|
37
|
-
function setStatusReady() {
|
|
38
|
-
node.status({
|
|
39
|
-
fill: 'blue',
|
|
40
|
-
shape: 'dot',
|
|
41
|
-
text: `Ready (expect ${node.expectedCount})`
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function resetCollection() {
|
|
46
|
-
if (node.timeoutHandle) {
|
|
47
|
-
clearTimeout(node.timeoutHandle);
|
|
48
|
-
node.timeoutHandle = null;
|
|
49
|
-
}
|
|
50
|
-
node.collection = {};
|
|
51
|
-
node.isCollecting = false;
|
|
52
|
-
node.collectionStartTime = null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function handleTimeout() {
|
|
56
|
-
const elapsed = Date.now() - node.collectionStartTime;
|
|
57
|
-
|
|
58
|
-
/* Build timeout message with collected data + missing info */
|
|
59
|
-
const collectedPositions = Object.keys(node.collection).map(k => parseInt(k)).sort((a, b) => a - b);
|
|
60
|
-
const missingPositions = [];
|
|
61
|
-
for (let i = 0; i < node.expectedCount; i++) {
|
|
62
|
-
if (!node.collection.hasOwnProperty(i)) {
|
|
63
|
-
missingPositions.push(i);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/* Build the partial array (same logic as normal completion) */
|
|
68
|
-
const result = Array.from({ length: node.expectedCount }, (_, i) =>
|
|
69
|
-
node.collection.hasOwnProperty(i) ? node.collection[i] : null
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
/* Create timeout message */
|
|
73
|
-
const timeoutMsg = {
|
|
74
|
-
meta: {
|
|
75
|
-
timeout: true,
|
|
76
|
-
missingPositions: missingPositions,
|
|
77
|
-
collectedPositions: collectedPositions,
|
|
78
|
-
expectedCount: node.expectedCount,
|
|
79
|
-
collectedCount: collectedPositions.length,
|
|
80
|
-
elapsed: elapsed
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/* Place the partial array where the user wants it */
|
|
85
|
-
if (node.outputPathType === 'msg') {
|
|
86
|
-
RED.util.setMessageProperty(timeoutMsg, node.outputPath, result, true);
|
|
87
|
-
} else if (node.outputPathType === 'flow') {
|
|
88
|
-
node.context().flow.set(node.outputPath, result);
|
|
89
|
-
} else if (node.outputPathType === 'global') {
|
|
90
|
-
node.context().global.set(node.outputPath, result);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/* Send to output 2 only */
|
|
94
|
-
node.send([null, timeoutMsg]);
|
|
95
|
-
|
|
96
|
-
node.status({
|
|
97
|
-
fill: 'yellow',
|
|
98
|
-
shape: 'ring',
|
|
99
|
-
text: `Timeout: sent ${collectedPositions.length}/${node.expectedCount} to output 2`
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
resetCollection();
|
|
103
|
-
setTimeout(setStatusReady, 3000);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function assembleAndOutput(sourceMsg) {
|
|
107
|
-
const elapsed = Date.now() - node.collectionStartTime;
|
|
108
|
-
|
|
109
|
-
/* Build the ordered array (fill gaps with null) */
|
|
110
|
-
const result = Array.from({ length: node.expectedCount }, (_, i) =>
|
|
111
|
-
node.collection.hasOwnProperty(i) ? node.collection[i] : null
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
/* Place the array where the user wants it */
|
|
115
|
-
const outMsg = { ...sourceMsg }; // shallow‑clone to keep headers etc.
|
|
116
|
-
if (node.outputPathType === 'msg') {
|
|
117
|
-
RED.util.setMessageProperty(outMsg, node.outputPath, result, true);
|
|
118
|
-
} else if (node.outputPathType === 'flow') {
|
|
119
|
-
node.context().flow.set(node.outputPath, result);
|
|
120
|
-
} else if (node.outputPathType === 'global') {
|
|
121
|
-
node.context().global.set(node.outputPath, result);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
node.status({
|
|
125
|
-
fill: 'green',
|
|
126
|
-
shape: 'dot',
|
|
127
|
-
text: `Complete: ${result.length} (${elapsed} ms)`
|
|
128
|
-
});
|
|
129
|
-
node.send([outMsg, null]);
|
|
130
|
-
|
|
131
|
-
/* Return to ready after a short pause */
|
|
132
|
-
setTimeout(setStatusReady, 2000);
|
|
133
|
-
resetCollection();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/* ────────────────────────────
|
|
137
|
-
░░ 4. Input handler ░░
|
|
138
|
-
──────────────────────────── */
|
|
139
|
-
node.on('input', function (msg, send, done) {
|
|
140
|
-
try {
|
|
141
|
-
/* 4.1 Basic sanity checks */
|
|
142
|
-
if (!msg.meta || typeof msg.meta.arrayPosition !== 'number') {
|
|
143
|
-
node.warn(
|
|
144
|
-
'Message missing array metadata. Expected msg.meta.arrayPosition (number) from array‑in node'
|
|
145
|
-
);
|
|
146
|
-
return done?.();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const position = msg.meta.arrayPosition;
|
|
150
|
-
|
|
151
|
-
/* 4.2 Validate range */
|
|
152
|
-
if (position < 0 || position >= node.expectedCount) {
|
|
153
|
-
node.warn(
|
|
154
|
-
`Position ${position} out of range 0‑${node.expectedCount - 1}`
|
|
155
|
-
);
|
|
156
|
-
return done?.();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/* 4.3 Extract data – prefer meta.arrayData, fall back to payload */
|
|
160
|
-
const data =
|
|
161
|
-
msg.meta && msg.meta.arrayData !== undefined
|
|
162
|
-
? msg.meta.arrayData
|
|
163
|
-
: msg.payload;
|
|
164
|
-
|
|
165
|
-
/* 4.4 Start collection if first element */
|
|
166
|
-
if (!node.isCollecting) {
|
|
167
|
-
node.isCollecting = true;
|
|
168
|
-
node.collection = {};
|
|
169
|
-
node.collectionStartTime = Date.now();
|
|
170
|
-
node.timeoutHandle = setTimeout(handleTimeout, node.timeout);
|
|
171
|
-
node.status({
|
|
172
|
-
fill: 'yellow',
|
|
173
|
-
shape: 'dot',
|
|
174
|
-
text: 'Collecting… (1/' + node.expectedCount + ')'
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/* 4.5 Store element */
|
|
179
|
-
node.collection[position] = data;
|
|
180
|
-
|
|
181
|
-
/* 4.6 Update collecting status */
|
|
182
|
-
const collected = Object.keys(node.collection).length;
|
|
183
|
-
node.status({
|
|
184
|
-
fill: 'yellow',
|
|
185
|
-
shape: 'dot',
|
|
186
|
-
text: `Collecting… (${collected}/${node.expectedCount})`
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
/* 4.7 Check completion */
|
|
190
|
-
if (collected === node.expectedCount) {
|
|
191
|
-
assembleAndOutput(msg);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
done?.();
|
|
195
|
-
} catch (err) {
|
|
196
|
-
node.status({ fill: 'red', shape: 'ring', text: 'Error' });
|
|
197
|
-
resetCollection();
|
|
198
|
-
if (done) done(err);
|
|
199
|
-
else node.error(err, msg);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
/* ────────────────────────────
|
|
204
|
-
░░ 5. Cleanup ░░
|
|
205
|
-
──────────────────────────── */
|
|
206
|
-
node.on('close', function () {
|
|
207
|
-
resetCollection();
|
|
208
|
-
node.status({});
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
RED.nodes.registerType('array-out', ArrayOutNode);
|
|
213
|
-
};
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('array-select', {
|
|
3
|
-
category: 'RP Image',
|
|
4
|
-
color: '#7b8dff',
|
|
5
|
-
defaults: {
|
|
6
|
-
name: { value: "" },
|
|
7
|
-
inputPath: { value: "payload" },
|
|
8
|
-
inputPathType: { value: "msg" },
|
|
9
|
-
outputPath: { value: "payload" },
|
|
10
|
-
outputPathType: { value: "msg" },
|
|
11
|
-
selection: { value: "0" },
|
|
12
|
-
asArray: { value: false }
|
|
13
|
-
},
|
|
14
|
-
inputs: 1,
|
|
15
|
-
outputs: 1,
|
|
16
|
-
icon: "font-awesome/fa-columns",
|
|
17
|
-
label: function() {
|
|
18
|
-
if (this.name) return this.name;
|
|
19
|
-
return `Array Select [${this.selection}]`;
|
|
20
|
-
},
|
|
21
|
-
oneditprepare: function() {
|
|
22
|
-
// Set up TypedInput for input path
|
|
23
|
-
$("#node-input-inputPath").typedInput({
|
|
24
|
-
default: 'msg',
|
|
25
|
-
types: ['msg', 'flow', 'global'],
|
|
26
|
-
typeField: "#node-input-inputPathType"
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// Set up TypedInput for output path
|
|
30
|
-
$("#node-input-outputPath").typedInput({
|
|
31
|
-
default: 'msg',
|
|
32
|
-
types: ['msg', 'flow', 'global'],
|
|
33
|
-
typeField: "#node-input-outputPathType"
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
</script>
|
|
38
|
-
|
|
39
|
-
<script type="text/x-red" data-template-name="array-select">
|
|
40
|
-
<div class="form-row">
|
|
41
|
-
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
42
|
-
<input type="text" id="node-input-name" placeholder="Name">
|
|
43
|
-
</div>
|
|
44
|
-
|
|
45
|
-
<hr>
|
|
46
|
-
|
|
47
|
-
<div class="form-row">
|
|
48
|
-
<label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input from</label>
|
|
49
|
-
<input type="text" id="node-input-inputPath" style="width: 70%;">
|
|
50
|
-
<input type="hidden" id="node-input-inputPathType">
|
|
51
|
-
</div>
|
|
52
|
-
|
|
53
|
-
<div class="form-row">
|
|
54
|
-
<label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output to</label>
|
|
55
|
-
<input type="text" id="node-input-outputPath" style="width: 70%;">
|
|
56
|
-
<input type="hidden" id="node-input-outputPathType">
|
|
57
|
-
</div>
|
|
58
|
-
|
|
59
|
-
<div class="form-row">
|
|
60
|
-
<label for="node-input-selection"><i class="fa fa-filter"></i> Selection</label>
|
|
61
|
-
<input type="text" id="node-input-selection" style="width: 70%;" placeholder="e.g., 0, 1,3,5, 1:4, 0::2">
|
|
62
|
-
</div>
|
|
63
|
-
|
|
64
|
-
<div class="form-row">
|
|
65
|
-
<label for="node-input-asArray"><i class="fa fa-list"></i> Force Array</label>
|
|
66
|
-
<input type="checkbox" id="node-input-asArray">
|
|
67
|
-
<span style="margin-left: 5px;">Always output as array (even for single items)</span>
|
|
68
|
-
</div>
|
|
69
|
-
|
|
70
|
-
<div class="form-tips">
|
|
71
|
-
<b>Selection Examples:</b><br>
|
|
72
|
-
• <code>0</code> - First element<br>
|
|
73
|
-
• <code>1,3,5</code> - Elements at indices 1, 3, 5<br>
|
|
74
|
-
• <code>1:4</code> - Elements 1 to 3 (range)<br>
|
|
75
|
-
• <code>0::2</code> - Every 2nd element starting from 0<br>
|
|
76
|
-
• <code>-1</code> - Last element<br>
|
|
77
|
-
• <code>-2:-1</code> - Last two elements
|
|
78
|
-
</div>
|
|
79
|
-
</script>
|
|
80
|
-
|
|
81
|
-
<script type="text/x-red" data-help-name="array-select">
|
|
82
|
-
<p>Selects specific elements from an input array using flexible selection syntax including indices, ranges, and patterns.</p>
|
|
83
|
-
|
|
84
|
-
<h3>Details</h3>
|
|
85
|
-
<p>This node provides powerful array element selection capabilities with Python-like slicing syntax. It can extract single elements, multiple specific indices, ranges, or patterns from arrays. The output format is automatically determined based on the selection size, with an option to force array output.</p>
|
|
86
|
-
|
|
87
|
-
<h3>Properties</h3>
|
|
88
|
-
<dl class="message-properties">
|
|
89
|
-
<dt>Input from <span class="property-type">string</span></dt>
|
|
90
|
-
<dd>The location to read the input array from. You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
|
|
91
|
-
<dt>Output to <span class="property-type">string</span></dt>
|
|
92
|
-
<dd>The location where to write the selected element(s). You can select between <code>msg</code>, <code>flow</code>, or <code>global</code> context. Defaults to <code>msg.payload</code>.</dd>
|
|
93
|
-
<dt>Selection <span class="property-type">string</span></dt>
|
|
94
|
-
<dd>Specify which array elements to select using various formats: single indices, comma-separated lists, ranges, or step patterns.</dd>
|
|
95
|
-
<dt>Force Array <span class="property-type">boolean</span></dt>
|
|
96
|
-
<dd>When checked, always outputs an array even for single elements. Default: false (single elements output directly).</dd>
|
|
97
|
-
</dl>
|
|
98
|
-
|
|
99
|
-
<h3>Inputs</h3>
|
|
100
|
-
<dl class="message-properties">
|
|
101
|
-
<dt>payload <span class="property-type">array</span></dt>
|
|
102
|
-
<dd>Input array from which to select elements. <strong>Must be an array</strong> - the node will warn and skip processing if input is not an array.</dd>
|
|
103
|
-
</dl>
|
|
104
|
-
|
|
105
|
-
<h3>Outputs</h3>
|
|
106
|
-
<dl class="message-properties">
|
|
107
|
-
<dt>configured output <span class="property-type">any | array</span></dt>
|
|
108
|
-
<dd>Selected element(s) written to the configured output path. Single elements output directly unless "Force Array" is enabled. Multiple elements always output as array.</dd>
|
|
109
|
-
</dl>
|
|
110
|
-
|
|
111
|
-
<h3>Selection Syntax</h3>
|
|
112
|
-
<ul>
|
|
113
|
-
<li><strong>Single Index:</strong> <code>0</code>, <code>2</code>, <code>-1</code> (negative indices count from end)</li>
|
|
114
|
-
<li><strong>Multiple Indices:</strong> <code>0,2,4</code>, <code>1,3,5</code> (comma-separated)</li>
|
|
115
|
-
<li><strong>Range:</strong> <code>1:4</code> (indices 1 to 3), <code>0:5</code> (indices 0 to 4)</li>
|
|
116
|
-
<li><strong>Step Range:</strong> <code>0::2</code> (every 2nd element), <code>1:7:2</code> (indices 1,3,5)</li>
|
|
117
|
-
<li><strong>Negative Ranges:</strong> <code>-2:</code> (last two elements), <code>:-2</code> (all but last two)</li>
|
|
118
|
-
</ul>
|
|
119
|
-
|
|
120
|
-
<h3>Examples</h3>
|
|
121
|
-
<p><strong>Input Array:</strong> <code>["A", "B", "C", "D", "E"]</code></p>
|
|
122
|
-
<ul>
|
|
123
|
-
<li><strong>Single:</strong> <code>0</code> → <code>"A"</code> (first element)</li>
|
|
124
|
-
<li><strong>Multiple:</strong> <code>1,3</code> → <code>["B", "D"]</code> (specific indices)</li>
|
|
125
|
-
<li><strong>Range:</strong> <code>1:4</code> → <code>["B", "C", "D"]</code> (slice range)</li>
|
|
126
|
-
<li><strong>Step:</strong> <code>0::2</code> → <code>["A", "C", "E"]</code> (every 2nd element)</li>
|
|
127
|
-
<li><strong>Negative:</strong> <code>-1</code> → <code>"E"</code> (last element)</li>
|
|
128
|
-
<li><strong>Last Two:</strong> <code>-2:</code> → <code>["D", "E"]</code> (from 2nd last to end)</li>
|
|
129
|
-
</ul>
|
|
130
|
-
|
|
131
|
-
<h3>Node Interactions</h3>
|
|
132
|
-
<p><strong>Works with:</strong> Array-out (to extract from assembled arrays), Transform nodes (to select processed results), any node that produces arrays</p>
|
|
133
|
-
<p><strong>Common Patterns:</strong> Array-out → Array-select (extract specific results), Transform → Array-select (pick best results), Image processing → Array-select (choose specific images)</p>
|
|
134
|
-
|
|
135
|
-
<h3>Output Behavior</h3>
|
|
136
|
-
<ul>
|
|
137
|
-
<li><strong>Single Element:</strong> Outputs the element directly (unless "Force Array" is checked)</li>
|
|
138
|
-
<li><strong>Multiple Elements:</strong> Always outputs as an array</li>
|
|
139
|
-
<li><strong>Empty Selection:</strong> Outputs empty array <code>[]</code></li>
|
|
140
|
-
<li><strong>Invalid Selection:</strong> No message sent, warning logged</li>
|
|
141
|
-
<li><strong>Out of Bounds:</strong> Invalid indices are ignored, warning logged</li>
|
|
142
|
-
</ul>
|
|
143
|
-
|
|
144
|
-
<h3>Error Handling</h3>
|
|
145
|
-
<p>Comprehensive validation and error reporting:</p>
|
|
146
|
-
<ul>
|
|
147
|
-
<li><strong>Non-array input:</strong> Warning logged, message not propagated</li>
|
|
148
|
-
<li><strong>Empty array:</strong> Warning logged, selection processed normally</li>
|
|
149
|
-
<li><strong>Invalid syntax:</strong> Warning logged, message not propagated</li>
|
|
150
|
-
<li><strong>Out-of-bounds indices:</strong> Invalid indices skipped, warning logged</li>
|
|
151
|
-
<li><strong>Status display:</strong> Shows current selection and processing state</li>
|
|
152
|
-
</ul>
|
|
153
|
-
|
|
154
|
-
<h3>Performance</h3>
|
|
155
|
-
<p>Selection operations are performed efficiently with minimal memory copying. Node status displays selection information and processing state.</p>
|
|
156
|
-
</script>
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Node.js logic for the Array-Select node with single output and flexible selection.
|
|
3
|
-
* @author Rosepetal
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
module.exports = function(RED) {
|
|
7
|
-
function ArraySelectNode(config) {
|
|
8
|
-
RED.nodes.createNode(this, config);
|
|
9
|
-
const node = this;
|
|
10
|
-
|
|
11
|
-
// Store configuration
|
|
12
|
-
node.inputPath = config.inputPath || 'payload';
|
|
13
|
-
node.inputPathType = config.inputPathType || 'msg';
|
|
14
|
-
node.outputPath = config.outputPath || 'payload';
|
|
15
|
-
node.outputPathType = config.outputPathType || 'msg';
|
|
16
|
-
node.selection = config.selection || '0';
|
|
17
|
-
node.asArray = config.asArray || false;
|
|
18
|
-
|
|
19
|
-
// Set initial status
|
|
20
|
-
node.status({
|
|
21
|
-
fill: "blue",
|
|
22
|
-
shape: "dot",
|
|
23
|
-
text: `Ready: ${node.selection}`
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Parse selection string and return indices
|
|
28
|
-
* @param {string} selection - Selection string (e.g., "0", "1,3,5", "1:4", "0::2")
|
|
29
|
-
* @param {number} arrayLength - Length of input array
|
|
30
|
-
* @returns {Array} Array of indices or null if invalid
|
|
31
|
-
*/
|
|
32
|
-
function parseSelection(selection, arrayLength) {
|
|
33
|
-
if (!selection || selection.trim() === '') return null;
|
|
34
|
-
|
|
35
|
-
const sel = selection.trim();
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
// Single index (e.g., "2" or "-1")
|
|
39
|
-
if (/^-?\d+$/.test(sel)) {
|
|
40
|
-
const index = parseInt(sel);
|
|
41
|
-
const normalizedIndex = index < 0 ? arrayLength + index : index;
|
|
42
|
-
if (normalizedIndex >= 0 && normalizedIndex < arrayLength) {
|
|
43
|
-
return [normalizedIndex];
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Multiple indices (e.g., "0,2,4")
|
|
49
|
-
if (sel.includes(',')) {
|
|
50
|
-
const indices = sel.split(',').map(s => {
|
|
51
|
-
const index = parseInt(s.trim());
|
|
52
|
-
return index < 0 ? arrayLength + index : index;
|
|
53
|
-
}).filter(i => i >= 0 && i < arrayLength);
|
|
54
|
-
return indices.length > 0 ? indices : null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Range (e.g., "1:4" or "1:4:2")
|
|
58
|
-
if (sel.includes(':')) {
|
|
59
|
-
const parts = sel.split(':');
|
|
60
|
-
if (parts.length === 2) {
|
|
61
|
-
// Simple range: start:end
|
|
62
|
-
let start = parseInt(parts[0]) || 0;
|
|
63
|
-
let end = parseInt(parts[1]) || arrayLength;
|
|
64
|
-
start = start < 0 ? arrayLength + start : start;
|
|
65
|
-
end = end < 0 ? arrayLength + end : end;
|
|
66
|
-
|
|
67
|
-
const indices = [];
|
|
68
|
-
for (let i = Math.max(0, start); i < Math.min(arrayLength, end); i++) {
|
|
69
|
-
indices.push(i);
|
|
70
|
-
}
|
|
71
|
-
return indices.length > 0 ? indices : null;
|
|
72
|
-
} else if (parts.length === 3) {
|
|
73
|
-
// Step range: start:end:step
|
|
74
|
-
let start = parseInt(parts[0]) || 0;
|
|
75
|
-
let end = parseInt(parts[1]) || arrayLength;
|
|
76
|
-
let step = parseInt(parts[2]) || 1;
|
|
77
|
-
start = start < 0 ? arrayLength + start : start;
|
|
78
|
-
end = end < 0 ? arrayLength + end : end;
|
|
79
|
-
|
|
80
|
-
if (step <= 0) step = 1;
|
|
81
|
-
|
|
82
|
-
const indices = [];
|
|
83
|
-
for (let i = Math.max(0, start); i < Math.min(arrayLength, end); i += step) {
|
|
84
|
-
indices.push(i);
|
|
85
|
-
}
|
|
86
|
-
return indices.length > 0 ? indices : null;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return null;
|
|
91
|
-
} catch (err) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Handle incoming messages
|
|
97
|
-
node.on('input', function(msg, send, done) {
|
|
98
|
-
try {
|
|
99
|
-
// Get data from configured input path
|
|
100
|
-
let inputArray;
|
|
101
|
-
if (node.inputPathType === 'msg') {
|
|
102
|
-
inputArray = RED.util.getMessageProperty(msg, node.inputPath);
|
|
103
|
-
} else if (node.inputPathType === 'flow') {
|
|
104
|
-
inputArray = node.context().flow.get(node.inputPath);
|
|
105
|
-
} else if (node.inputPathType === 'global') {
|
|
106
|
-
inputArray = node.context().global.get(node.inputPath);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Validate input is an array
|
|
110
|
-
if (!Array.isArray(inputArray)) {
|
|
111
|
-
node.warn(`Input must be an array. Received: ${typeof inputArray}`);
|
|
112
|
-
node.status({ fill: "red", shape: "ring", text: "Invalid input: not an array" });
|
|
113
|
-
return done?.();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (inputArray.length === 0) {
|
|
117
|
-
node.warn('Input array is empty');
|
|
118
|
-
node.status({ fill: "yellow", shape: "ring", text: "Empty array" });
|
|
119
|
-
return done?.();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Process selection
|
|
123
|
-
const indices = parseSelection(node.selection, inputArray.length);
|
|
124
|
-
|
|
125
|
-
if (indices && indices.length > 0) {
|
|
126
|
-
const selectedItems = indices.map(idx => inputArray[idx]);
|
|
127
|
-
|
|
128
|
-
// Determine output format
|
|
129
|
-
const result = (node.asArray || selectedItems.length > 1) ? selectedItems : selectedItems[0];
|
|
130
|
-
|
|
131
|
-
// Create clean output message with only the selected result
|
|
132
|
-
let outputMsg = {};
|
|
133
|
-
|
|
134
|
-
// Set output based on configured path
|
|
135
|
-
if (node.outputPathType === 'msg') {
|
|
136
|
-
RED.util.setMessageProperty(outputMsg, node.outputPath, result, true);
|
|
137
|
-
} else if (node.outputPathType === 'flow') {
|
|
138
|
-
node.context().flow.set(node.outputPath, result);
|
|
139
|
-
// For flow context, send minimal message (no payload)
|
|
140
|
-
} else if (node.outputPathType === 'global') {
|
|
141
|
-
node.context().global.set(node.outputPath, result);
|
|
142
|
-
// For global context, send minimal message (no payload)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
node.status({
|
|
146
|
-
fill: "green",
|
|
147
|
-
shape: "dot",
|
|
148
|
-
text: `Selected ${selectedItems.length} from [${inputArray.length}]`
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
send(outputMsg);
|
|
152
|
-
} else {
|
|
153
|
-
// Invalid selection
|
|
154
|
-
node.warn(`Invalid selection "${node.selection}" for array of length ${inputArray.length}`);
|
|
155
|
-
node.status({ fill: "red", shape: "ring", text: "Invalid selection" });
|
|
156
|
-
return done?.();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Reset status after a delay
|
|
160
|
-
setTimeout(() => {
|
|
161
|
-
node.status({
|
|
162
|
-
fill: "blue",
|
|
163
|
-
shape: "dot",
|
|
164
|
-
text: `Ready: ${node.selection}`
|
|
165
|
-
});
|
|
166
|
-
}, 2000);
|
|
167
|
-
|
|
168
|
-
done?.();
|
|
169
|
-
|
|
170
|
-
} catch (err) {
|
|
171
|
-
node.status({ fill: "red", shape: "ring", text: "Error" });
|
|
172
|
-
if (done) {
|
|
173
|
-
done(err);
|
|
174
|
-
} else {
|
|
175
|
-
node.error(err, msg);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
// Clean up on node removal
|
|
181
|
-
node.on('close', function() {
|
|
182
|
-
node.status({});
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
RED.nodes.registerType("array-select", ArraySelectNode);
|
|
187
|
-
};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('queue', {
|
|
3
|
-
category: 'RP Image',
|
|
4
|
-
color: '#87CEEB',
|
|
5
|
-
defaults: {
|
|
6
|
-
name: { value: "" },
|
|
7
|
-
mode: { value: "queue-size" },
|
|
8
|
-
maxQueueSize: { value: 0 },
|
|
9
|
-
intervalMilliseconds: { value: 0 },
|
|
10
|
-
timeout: { value: 0 }
|
|
11
|
-
},
|
|
12
|
-
inputs: 1,
|
|
13
|
-
outputs: 1,
|
|
14
|
-
icon: "font-awesome/fa-clock-o",
|
|
15
|
-
label: function() {
|
|
16
|
-
if (this.name) return this.name;
|
|
17
|
-
return "Queue";
|
|
18
|
-
},
|
|
19
|
-
oneditprepare: function() {
|
|
20
|
-
const modeField = $("#node-input-mode");
|
|
21
|
-
const queueRow = $("#node-row-maxQueueSize");
|
|
22
|
-
const timeoutRow = $("#node-row-timeout");
|
|
23
|
-
const queueTip = $("#node-tip-maxQueueSize");
|
|
24
|
-
const timeoutTip = $("#node-tip-timeout");
|
|
25
|
-
|
|
26
|
-
function toggleModeFields() {
|
|
27
|
-
const mode = modeField.val();
|
|
28
|
-
if (mode === 'timeout') {
|
|
29
|
-
queueRow.hide();
|
|
30
|
-
queueTip.hide();
|
|
31
|
-
timeoutRow.show();
|
|
32
|
-
timeoutTip.show();
|
|
33
|
-
} else {
|
|
34
|
-
queueRow.show();
|
|
35
|
-
queueTip.show();
|
|
36
|
-
timeoutRow.hide();
|
|
37
|
-
timeoutTip.hide();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
modeField.on("change", toggleModeFields);
|
|
42
|
-
toggleModeFields();
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
</script>
|
|
46
|
-
|
|
47
|
-
<script type="text/x-red" data-template-name="queue">
|
|
48
|
-
<div class="form-row">
|
|
49
|
-
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
50
|
-
<input type="text" id="node-input-name" placeholder="Name">
|
|
51
|
-
</div>
|
|
52
|
-
|
|
53
|
-
<hr>
|
|
54
|
-
|
|
55
|
-
<div class="form-row">
|
|
56
|
-
<label for="node-input-mode"><i class="fa fa-exchange"></i> Mode</label>
|
|
57
|
-
<select id="node-input-mode">
|
|
58
|
-
<option value="queue-size">Queue Size Limit</option>
|
|
59
|
-
<option value="timeout">Timeout</option>
|
|
60
|
-
</select>
|
|
61
|
-
</div>
|
|
62
|
-
<div class="form-tips">
|
|
63
|
-
<b>Tip:</b> Pick a mode to decide whether the node caps how many messages can wait or keeps unlimited entries that expire after a timeout.
|
|
64
|
-
</div>
|
|
65
|
-
|
|
66
|
-
<div class="form-row" id="node-row-maxQueueSize">
|
|
67
|
-
<label for="node-input-maxQueueSize"><i class="fa fa-list"></i> Max Queue Size</label>
|
|
68
|
-
<input type="number" id="node-input-maxQueueSize" min="0" step="1" style="width: 70%;" placeholder="0">
|
|
69
|
-
</div>
|
|
70
|
-
<div class="form-tips" id="node-tip-maxQueueSize">
|
|
71
|
-
<b>Tip:</b> When using the queue-size mode, this field limits how many messages are buffered; extra messages are dropped until space frees up.
|
|
72
|
-
</div>
|
|
73
|
-
|
|
74
|
-
<div class="form-row" id="node-row-timeout">
|
|
75
|
-
<label for="node-input-timeout"><i class="fa fa-hourglass-half"></i> Timeout (ms)</label>
|
|
76
|
-
<input type="number" id="node-input-timeout" min="0" step="1" style="width: 70%;" placeholder="0">
|
|
77
|
-
</div>
|
|
78
|
-
<div class="form-tips" id="node-tip-timeout">
|
|
79
|
-
<b>Tip:</b> Timeout mode keeps buffering all messages but removes entries that stay longer than this value, keeping the data fresh.
|
|
80
|
-
</div>
|
|
81
|
-
|
|
82
|
-
<div class="form-row">
|
|
83
|
-
<label for="node-input-intervalMilliseconds"><i class="fa fa-clock-o"></i> Interval (ms)</label>
|
|
84
|
-
<input type="number" id="node-input-intervalMilliseconds" min="0" step="1" style="width: 70%;" placeholder="0">
|
|
85
|
-
</div>
|
|
86
|
-
<div class="form-tips">
|
|
87
|
-
<b>Tip:</b> Interval enforces a minimum delay between forwarded messages; set to 0 to send as fast as possible.
|
|
88
|
-
</div>
|
|
89
|
-
</script>
|
|
90
|
-
|
|
91
|
-
<script type="text/x-red" data-help-name="queue">
|
|
92
|
-
<p>Buffers incoming messages and releases them with optional rate limiting and expiration control.</p>
|
|
93
|
-
|
|
94
|
-
<h3>Mode</h3>
|
|
95
|
-
<p>Choose between a queue-size limit or a timeout strategy; only the controls for the selected mode are applied.</p>
|
|
96
|
-
|
|
97
|
-
<h3>Configuration</h3>
|
|
98
|
-
<dl class="message-properties">
|
|
99
|
-
<dt>Mode <span class="property-type">enum</span></dt>
|
|
100
|
-
<dd>Select <code>Queue Size Limit</code> to cap the number of buffered messages or <code>Timeout</code> to drop entries after a duration.</dd>
|
|
101
|
-
<dt>Max Queue Size <span class="property-type">number</span></dt>
|
|
102
|
-
<dd>Valid only in queue-size mode. Determines how many messages can be held before incoming data is ignored.</dd>
|
|
103
|
-
<dt>Timeout (ms) <span class="property-type">number</span></dt>
|
|
104
|
-
<dd>Valid only in timeout mode. Messages that stay longer than this millisecond value are removed before they reach the output.</dd>
|
|
105
|
-
<dt>Interval (ms) <span class="property-type">number</span></dt>
|
|
106
|
-
<dd>Minimum time to wait between forwarded messages. Zero means send immediately when data is available.</dd>
|
|
107
|
-
</dl>
|
|
108
|
-
|
|
109
|
-
<h3>Behavior</h3>
|
|
110
|
-
<ul>
|
|
111
|
-
<li>Messages are processed in FIFO order while respecting the selected mode.</li>
|
|
112
|
-
<li>Queue-size mode enforces a hard cap, rejecting excess messages.</li>
|
|
113
|
-
<li>Timeout mode keeps buffering but evicts stale entries before sending.</li>
|
|
114
|
-
<li>The interval ensures a steady pace by adding delays between sends when configured.</li>
|
|
115
|
-
</ul>
|
|
116
|
-
|
|
117
|
-
<h3>Status</h3>
|
|
118
|
-
<p>The node status reflects whether the queue is idle, holding messages, or actively sending.</p>
|
|
119
|
-
</script>
|