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

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 (131) hide show
  1. package/.gitattributes +6 -0
  2. package/.github/workflows/build-prebuild.yml +326 -0
  3. package/LICENSE +13 -0
  4. package/README.md +161 -0
  5. package/artifacts/darwin-arm64/package.json +25 -0
  6. package/artifacts/linux-arm64/package.json +26 -0
  7. package/artifacts/linux-x64/package.json +26 -0
  8. package/artifacts/linuxmusl-x64/package.json +26 -0
  9. package/assets/flow_time_example.gif +0 -0
  10. package/assets/nodes/io/array-in-demo.gif +0 -0
  11. package/assets/nodes/io/array-out-demo.gif +0 -0
  12. package/assets/nodes/io/array-select-demo.gif +0 -0
  13. package/assets/nodes/io/image-in-demo.gif +0 -0
  14. package/assets/nodes/mix/concat-demo.gif +0 -0
  15. package/assets/nodes/mix/mosaic-demo.gif +0 -0
  16. package/assets/nodes/transform/crop-demo.gif +0 -0
  17. package/assets/nodes/transform/filter-demo.gif +0 -0
  18. package/assets/nodes/transform/padding-demo.gif +0 -0
  19. package/assets/nodes/transform/resize-demo.gif +0 -0
  20. package/assets/nodes/transform/rotate-demo.gif +0 -0
  21. package/docs/nodes/blend/add-mask.md +275 -0
  22. package/docs/nodes/blend/add-masks.md +284 -0
  23. package/docs/nodes/blend/blend.md +248 -0
  24. package/docs/nodes/io/array-in.md +119 -0
  25. package/docs/nodes/io/array-out.md +150 -0
  26. package/docs/nodes/io/array-select.md +157 -0
  27. package/docs/nodes/io/image-in.md +131 -0
  28. package/docs/nodes/io/image-out.md +179 -0
  29. package/docs/nodes/io/queue.md +57 -0
  30. package/docs/nodes/io/save-file.md +30 -0
  31. package/docs/nodes/mix/advanced-mosaic.md +108 -0
  32. package/docs/nodes/mix/concat.md +127 -0
  33. package/docs/nodes/mix/mosaic.md +146 -0
  34. package/docs/nodes/specialized/cropBB.md +271 -0
  35. package/docs/nodes/specialized/image-align.md +426 -0
  36. package/docs/nodes/transform/crop.md +132 -0
  37. package/docs/nodes/transform/draw.md +77 -0
  38. package/docs/nodes/transform/filter.md +84 -0
  39. package/docs/nodes/transform/padding.md +133 -0
  40. package/docs/nodes/transform/resize.md +158 -0
  41. package/docs/nodes/transform/rotate.md +121 -0
  42. package/docs/nodes/util/block-detect.md +46 -0
  43. package/install.sh +144 -0
  44. package/node-red-contrib-image-tools/lib/cpp-bridge.js +224 -0
  45. package/node-red-contrib-image-tools/lib/node-utils.js +529 -0
  46. package/node-red-contrib-image-tools/nodes/blend/add-bbs.html +590 -0
  47. package/node-red-contrib-image-tools/nodes/blend/add-bbs.js +241 -0
  48. package/node-red-contrib-image-tools/nodes/blend/add-mask.html +449 -0
  49. package/node-red-contrib-image-tools/nodes/blend/add-mask.js +170 -0
  50. package/node-red-contrib-image-tools/nodes/blend/add-masks.html +703 -0
  51. package/node-red-contrib-image-tools/nodes/blend/add-masks.js +321 -0
  52. package/node-red-contrib-image-tools/nodes/blend/blend.html +552 -0
  53. package/node-red-contrib-image-tools/nodes/blend/blend.js +124 -0
  54. package/node-red-contrib-image-tools/nodes/io/array-in.html +110 -0
  55. package/node-red-contrib-image-tools/nodes/io/array-in.js +113 -0
  56. package/node-red-contrib-image-tools/nodes/io/array-out.html +125 -0
  57. package/node-red-contrib-image-tools/nodes/io/array-out.js +213 -0
  58. package/node-red-contrib-image-tools/nodes/io/array-select.html +156 -0
  59. package/node-red-contrib-image-tools/nodes/io/array-select.js +187 -0
  60. package/node-red-contrib-image-tools/nodes/io/folder-in.html +248 -0
  61. package/node-red-contrib-image-tools/nodes/io/folder-in.js +335 -0
  62. package/node-red-contrib-image-tools/nodes/io/image-in.html +146 -0
  63. package/node-red-contrib-image-tools/nodes/io/image-in.js +143 -0
  64. package/node-red-contrib-image-tools/nodes/io/image-out.html +506 -0
  65. package/node-red-contrib-image-tools/nodes/io/image-out.js +545 -0
  66. package/node-red-contrib-image-tools/nodes/io/queue.html +119 -0
  67. package/node-red-contrib-image-tools/nodes/io/queue.js +191 -0
  68. package/node-red-contrib-image-tools/nodes/io/save-file.html +243 -0
  69. package/node-red-contrib-image-tools/nodes/io/save-file.js +440 -0
  70. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.html +2149 -0
  71. package/node-red-contrib-image-tools/nodes/mix/advanced-mosaic.js +195 -0
  72. package/node-red-contrib-image-tools/nodes/mix/concat.html +390 -0
  73. package/node-red-contrib-image-tools/nodes/mix/concat.js +112 -0
  74. package/node-red-contrib-image-tools/nodes/mix/mosaic.html +550 -0
  75. package/node-red-contrib-image-tools/nodes/mix/mosaic.js +151 -0
  76. package/node-red-contrib-image-tools/nodes/specialized/cropBB.html +268 -0
  77. package/node-red-contrib-image-tools/nodes/specialized/cropBB.js +277 -0
  78. package/node-red-contrib-image-tools/nodes/specialized/image-align.html +528 -0
  79. package/node-red-contrib-image-tools/nodes/specialized/image-align.js +306 -0
  80. package/node-red-contrib-image-tools/nodes/transform/crop.html +410 -0
  81. package/node-red-contrib-image-tools/nodes/transform/crop.js +149 -0
  82. package/node-red-contrib-image-tools/nodes/transform/draw.html +719 -0
  83. package/node-red-contrib-image-tools/nodes/transform/draw.js +509 -0
  84. package/node-red-contrib-image-tools/nodes/transform/filter.html +578 -0
  85. package/node-red-contrib-image-tools/nodes/transform/filter.js +177 -0
  86. package/node-red-contrib-image-tools/nodes/transform/padding.html +475 -0
  87. package/node-red-contrib-image-tools/nodes/transform/padding.js +142 -0
  88. package/node-red-contrib-image-tools/nodes/transform/resize.html +429 -0
  89. package/node-red-contrib-image-tools/nodes/transform/resize.js +162 -0
  90. package/node-red-contrib-image-tools/nodes/transform/rotate.html +299 -0
  91. package/node-red-contrib-image-tools/nodes/transform/rotate.js +141 -0
  92. package/node-red-contrib-image-tools/nodes/util/block-detect.html +85 -0
  93. package/node-red-contrib-image-tools/nodes/util/block-detect.js +136 -0
  94. package/node-red-contrib-image-tools/nodes/util/clean-debug.html +201 -0
  95. package/node-red-contrib-image-tools/nodes/util/clean-debug.js +393 -0
  96. package/node-red-contrib-image-tools/package.json +64 -0
  97. package/npm/darwin-arm64/lib/.gitkeep +1 -0
  98. package/npm/darwin-arm64/package.json +25 -0
  99. package/npm/darwin-x64/lib/.gitkeep +1 -0
  100. package/npm/darwin-x64/package.json +25 -0
  101. package/npm/linux-arm64/lib/.gitkeep +1 -0
  102. package/npm/linux-arm64/package.json +26 -0
  103. package/npm/linux-x64/lib/.gitkeep +1 -0
  104. package/npm/linux-x64/package.json +26 -0
  105. package/npm/linuxmusl-x64/lib/.gitkeep +1 -0
  106. package/npm/linuxmusl-x64/package.json +26 -0
  107. package/npm/win32-x64/lib/.gitkeep +1 -0
  108. package/npm/win32-x64/package.json +25 -0
  109. package/package.json +74 -0
  110. package/rosepetal-image-engine/binding.gyp +153 -0
  111. package/rosepetal-image-engine/package.json +19 -0
  112. package/rosepetal-image-engine/src/add-bbs.cpp +433 -0
  113. package/rosepetal-image-engine/src/add-mask.cpp +240 -0
  114. package/rosepetal-image-engine/src/add-masks.cpp +638 -0
  115. package/rosepetal-image-engine/src/advanced-mosaic.cpp +740 -0
  116. package/rosepetal-image-engine/src/blend.cpp +200 -0
  117. package/rosepetal-image-engine/src/concat.cpp +329 -0
  118. package/rosepetal-image-engine/src/crop.cpp +139 -0
  119. package/rosepetal-image-engine/src/draw.cpp +414 -0
  120. package/rosepetal-image-engine/src/filter.cpp +230 -0
  121. package/rosepetal-image-engine/src/filters/kernels.h +171 -0
  122. package/rosepetal-image-engine/src/image-align.cpp +551 -0
  123. package/rosepetal-image-engine/src/main.cpp +36 -0
  124. package/rosepetal-image-engine/src/mosaic.cpp +373 -0
  125. package/rosepetal-image-engine/src/padding.cpp +124 -0
  126. package/rosepetal-image-engine/src/resize.cpp +210 -0
  127. package/rosepetal-image-engine/src/rotate.cpp +177 -0
  128. package/rosepetal-image-engine/src/utils.h +563 -0
  129. package/rosepetal-image-engine/test-formats.js +119 -0
  130. package/scripts/build-opencv-static.ps1 +166 -0
  131. package/scripts/build-opencv-static.sh +147 -0
@@ -0,0 +1,719 @@
1
+ <script type="text/javascript">
2
+ (function() {
3
+ const DEFAULT_POINT = Object.freeze({
4
+ mode: 'single',
5
+ listType: 'json', listValue: '',
6
+ xType: 'num', xValue: '0.5',
7
+ yType: 'num', yValue: '0.5',
8
+ radiusType: 'num', radiusValue: '0.02',
9
+ colorType: 'str', colorValue: '#ff0000',
10
+ opacityType: 'num', opacityValue: '1'
11
+ });
12
+
13
+ const DEFAULT_LINE = Object.freeze({
14
+ mode: 'single',
15
+ listType: 'json', listValue: '',
16
+ x1Type: 'num', x1Value: '0.1',
17
+ y1Type: 'num', y1Value: '0.1',
18
+ x2Type: 'num', x2Value: '0.9',
19
+ y2Type: 'num', y2Value: '0.9',
20
+ thicknessType: 'num', thicknessValue: '0.01',
21
+ colorType: 'str', colorValue: '#00ff00',
22
+ opacityType: 'num', opacityValue: '1'
23
+ });
24
+
25
+ function mergeDefaults(base, data) {
26
+ return $.extend(true, {}, base, data);
27
+ }
28
+
29
+ function normalizeHexColor(value) {
30
+ if (typeof value !== 'string') {
31
+ return null;
32
+ }
33
+ let hex = value.trim();
34
+ if (!hex || hex[0] !== '#') {
35
+ return null;
36
+ }
37
+ if (hex.length === 4) {
38
+ hex = '#' + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];
39
+ }
40
+ if (/^#[0-9a-f]{6}$/i.test(hex)) {
41
+ return hex.toLowerCase();
42
+ }
43
+ return null;
44
+ }
45
+
46
+ const TABLE_CONFIG = Object.freeze({
47
+ points: {
48
+ container: '#points-container',
49
+ rowClass: 'rp-point-row',
50
+ columns: [
51
+ { field: 'list', inputClass: 'point-list' },
52
+ { field: 'x', inputClass: 'point-x' },
53
+ { field: 'y', inputClass: 'point-y' },
54
+ { field: 'radius', inputClass: 'point-radius' },
55
+ { field: 'color', inputClass: 'point-color' },
56
+ { field: 'opacity', inputClass: 'point-opacity' }
57
+ ]
58
+ },
59
+ lines: {
60
+ container: '#lines-container',
61
+ rowClass: 'rp-line-row',
62
+ columns: [
63
+ { field: 'list', inputClass: 'line-list' },
64
+ { field: 'x1', inputClass: 'line-x1' },
65
+ { field: 'y1', inputClass: 'line-y1' },
66
+ { field: 'x2', inputClass: 'line-x2' },
67
+ { field: 'y2', inputClass: 'line-y2' },
68
+ { field: 'thickness', inputClass: 'line-thickness' },
69
+ { field: 'color', inputClass: 'line-color' },
70
+ { field: 'opacity', inputClass: 'line-opacity' }
71
+ ]
72
+ }
73
+ });
74
+
75
+ function getFieldKeys(column) {
76
+ const base = column.field;
77
+ return {
78
+ typeKey: column.typeKey || (base + 'Type'),
79
+ valueKey: column.valueKey || (base + 'Value')
80
+ };
81
+ }
82
+
83
+ RED.nodes.registerType('draw', {
84
+ category: 'RP Image',
85
+ color: '#DDA0DD',
86
+ defaults: {
87
+ name: { value: "" },
88
+ inputPath: { value: "payload" },
89
+ inputPathType: { value: "msg" },
90
+ outputPath: { value: "payload" },
91
+ outputPathType: { value: "msg" },
92
+ outputFormat: { value: "raw" },
93
+ outputQuality: { value: 90 },
94
+ pngOptimize: { value: false },
95
+ debugEnabled: { value: false },
96
+ debugWidth: { value: 200 },
97
+ debugWidthType: { value: "num" },
98
+ points: { value: [] },
99
+ lines: { value: [] }
100
+ },
101
+ inputs: 1,
102
+ outputs: 1,
103
+ icon: "font-awesome/fa-paint-brush",
104
+ label: function () {
105
+ return this.name || "draw";
106
+ },
107
+ oneditprepare: function () {
108
+ const node = this;
109
+ const markDirty = () => RED.nodes.dirty(true);
110
+
111
+ $("#node-input-inputPath").typedInput({
112
+ default: 'msg',
113
+ types: ['msg', 'flow', 'global'],
114
+ typeField: "#node-input-inputPathType"
115
+ });
116
+
117
+ $("#node-input-outputPath").typedInput({
118
+ default: 'msg',
119
+ types: ['msg', 'flow', 'global'],
120
+ typeField: "#node-input-outputPathType"
121
+ });
122
+
123
+ $("#node-input-debugWidth").typedInput({
124
+ default: 'num',
125
+ types: ['num', 'msg', 'flow', 'global'],
126
+ typeField: "#node-input-debugWidthType"
127
+ });
128
+
129
+ function updateQualityVisibility() {
130
+ const format = $('#node-input-outputFormat').val();
131
+ $('#quality-row').toggle(format === 'jpg' || format === 'webp');
132
+ $('#png-optimize-row').toggle(format === 'png');
133
+ }
134
+ $('#node-input-outputFormat').on('change', function () {
135
+ updateQualityVisibility();
136
+ markDirty();
137
+ });
138
+ updateQualityVisibility();
139
+
140
+ function updateDebugVisibility() {
141
+ $('#debug-width-row').toggle($('#node-input-debugEnabled').is(':checked'));
142
+ }
143
+ $('#node-input-debugEnabled').on('change', function () {
144
+ updateDebugVisibility();
145
+ markDirty();
146
+ });
147
+ updateDebugVisibility();
148
+
149
+ node.points = Array.isArray(node.points)
150
+ ? node.points.map(function (entry) { return mergeDefaults(DEFAULT_POINT, entry); })
151
+ : [];
152
+
153
+ node.lines = Array.isArray(node.lines)
154
+ ? node.lines.map(function (entry) { return mergeDefaults(DEFAULT_LINE, entry); })
155
+ : [];
156
+
157
+ function buildTypedCell(row, options) {
158
+ const cell = $('<td style="padding:8px; border:1px solid #ddd; vertical-align:middle;">').appendTo(row);
159
+ const typeField = $('<input type="hidden">').addClass(options.typeClass).appendTo(cell);
160
+ const input = $('<input type="text" style="width:100%;">').addClass(options.inputClass).appendTo(cell);
161
+ if (options.placeholder) {
162
+ input.attr('placeholder', options.placeholder);
163
+ }
164
+ input.typedInput({
165
+ default: options.defaultType,
166
+ types: options.types,
167
+ typeField
168
+ });
169
+ input.typedInput('value', options.defaultValue);
170
+ input.on('change input typedInput:change typedInput:close', function () {
171
+ options.onChange(input);
172
+ markDirty();
173
+ });
174
+ return input;
175
+ }
176
+
177
+ function buildColorCell(row, options) {
178
+ const cell = $('<td style="padding:8px; border:1px solid #ddd; vertical-align:middle;">').appendTo(row);
179
+ const typeField = $('<input type="hidden">').addClass(options.typeClass).appendTo(cell);
180
+ const controls = $('<div style="display:flex; gap:6px; align-items:center;">').appendTo(cell);
181
+ const input = $('<input type="text" style="flex:1 1 auto;">').addClass(options.inputClass).appendTo(controls);
182
+ input.typedInput({
183
+ default: options.defaultType,
184
+ types: ['str', 'msg', 'flow', 'global'],
185
+ typeField
186
+ });
187
+ input.typedInput('value', options.defaultValue);
188
+
189
+ const picker = $('<input type="color" style="width:38px; height:28px; padding:0; border:1px solid #ccc; border-radius:4px;">')
190
+ .addClass(options.pickerClass)
191
+ .attr('title', 'Available when type is string')
192
+ .appendTo(controls);
193
+
194
+ function syncPicker() {
195
+ const type = input.typedInput('type');
196
+ const hex = normalizeHexColor(input.typedInput('value'));
197
+ const isString = type === 'str';
198
+ if (hex) {
199
+ picker.val(hex);
200
+ } else if (!picker.val()) {
201
+ picker.val('#ffffff');
202
+ }
203
+ picker.prop('disabled', !isString);
204
+ picker.css('opacity', isString ? 1 : 0.5);
205
+ }
206
+
207
+ input.on('change input typedInput:change typedInput:close', function () {
208
+ options.onChange(input);
209
+ syncPicker();
210
+ markDirty();
211
+ });
212
+
213
+ picker.on('input', function () {
214
+ if (input.typedInput('type') !== 'str') {
215
+ input.typedInput('type', 'str');
216
+ }
217
+ input.typedInput('value', $(this).val());
218
+ options.onChange(input);
219
+ markDirty();
220
+ syncPicker();
221
+ });
222
+
223
+ syncPicker();
224
+ return input;
225
+ }
226
+
227
+ function togglePointMode(row, point) {
228
+ const isList = point.mode === 'list';
229
+ const xyInputs = row.find('.point-x, .point-y');
230
+ xyInputs.each(function () {
231
+ const input = $(this);
232
+ input.prop('disabled', isList);
233
+ input.closest('td').css('opacity', isList ? 0.5 : 1);
234
+ });
235
+
236
+ const listInput = row.find('.point-list');
237
+ listInput.each(function () {
238
+ const input = $(this);
239
+ const disabled = !isList;
240
+ input.prop('disabled', disabled);
241
+ input.closest('td').css('opacity', disabled ? 0.5 : 1);
242
+ });
243
+ }
244
+
245
+ function toggleLineMode(row, line) {
246
+ const isList = line.mode === 'list';
247
+ const coordInputs = row.find('.line-x1, .line-y1, .line-x2, .line-y2');
248
+ coordInputs.each(function () {
249
+ const input = $(this);
250
+ input.prop('disabled', isList);
251
+ input.closest('td').css('opacity', isList ? 0.5 : 1);
252
+ });
253
+
254
+ const listInput = row.find('.line-list');
255
+ listInput.each(function () {
256
+ const input = $(this);
257
+ const disabled = !isList;
258
+ input.prop('disabled', disabled);
259
+ input.closest('td').css('opacity', disabled ? 0.5 : 1);
260
+ });
261
+ }
262
+
263
+ function createPointRow(point, index) {
264
+ const row = $('<tr class="rp-point-row">').attr('data-index', index);
265
+
266
+ const modeCell = $('<td style="padding:8px; border:1px solid #ddd; vertical-align:middle;">').appendTo(row);
267
+ const modeSelect = $('<select style="width:100%;">')
268
+ .addClass('point-mode')
269
+ .append('<option value="single">Single values</option>')
270
+ .append('<option value="list">List</option>')
271
+ .val(point.mode || 'single')
272
+ .appendTo(modeCell);
273
+ modeSelect.on('change', function () {
274
+ point.mode = $(this).val();
275
+ togglePointMode(row, point);
276
+ markDirty();
277
+ });
278
+
279
+ buildTypedCell(row, {
280
+ typeClass: 'point-x-type',
281
+ inputClass: 'point-x',
282
+ defaultType: point.xType,
283
+ defaultValue: point.xValue,
284
+ types: ['num', 'msg', 'flow', 'global'],
285
+ placeholder: '0.0 - 1.0',
286
+ onChange: function (input) {
287
+ point.xType = input.typedInput('type');
288
+ point.xValue = input.typedInput('value');
289
+ }
290
+ });
291
+
292
+ buildTypedCell(row, {
293
+ typeClass: 'point-y-type',
294
+ inputClass: 'point-y',
295
+ defaultType: point.yType,
296
+ defaultValue: point.yValue,
297
+ types: ['num', 'msg', 'flow', 'global'],
298
+ placeholder: '0.0 - 1.0',
299
+ onChange: function (input) {
300
+ point.yType = input.typedInput('type');
301
+ point.yValue = input.typedInput('value');
302
+ }
303
+ });
304
+
305
+ buildTypedCell(row, {
306
+ typeClass: 'point-list-type',
307
+ inputClass: 'point-list',
308
+ defaultType: point.listType,
309
+ defaultValue: point.listValue,
310
+ types: ['json', 'msg', 'flow', 'global'],
311
+ placeholder: '[[0.1,0.2], ...]',
312
+ onChange: function (input) {
313
+ point.listType = input.typedInput('type');
314
+ point.listValue = input.typedInput('value');
315
+ }
316
+ });
317
+
318
+ buildTypedCell(row, {
319
+ typeClass: 'point-radius-type',
320
+ inputClass: 'point-radius',
321
+ defaultType: point.radiusType,
322
+ defaultValue: point.radiusValue,
323
+ types: ['num', 'msg', 'flow', 'global'],
324
+ placeholder: '0.00',
325
+ onChange: function (input) {
326
+ point.radiusType = input.typedInput('type');
327
+ point.radiusValue = input.typedInput('value');
328
+ }
329
+ });
330
+
331
+ buildColorCell(row, {
332
+ typeClass: 'point-color-type',
333
+ inputClass: 'point-color',
334
+ pickerClass: 'point-color-picker',
335
+ defaultType: point.colorType,
336
+ defaultValue: point.colorValue,
337
+ onChange: function (input) {
338
+ point.colorType = input.typedInput('type');
339
+ point.colorValue = input.typedInput('value');
340
+ }
341
+ });
342
+
343
+ buildTypedCell(row, {
344
+ typeClass: 'point-opacity-type',
345
+ inputClass: 'point-opacity',
346
+ defaultType: point.opacityType,
347
+ defaultValue: point.opacityValue,
348
+ types: ['num', 'msg', 'flow', 'global'],
349
+ placeholder: '0.0 - 1.0',
350
+ onChange: function (input) {
351
+ point.opacityType = input.typedInput('type');
352
+ point.opacityValue = input.typedInput('value');
353
+ }
354
+ });
355
+
356
+ const actionsCell = $('<td style="padding:8px; border:1px solid #ddd; text-align:center;">').appendTo(row);
357
+ const removeButton = $('<button type="button" style="background:#ff4444; color:#fff; border:none; padding:4px 10px; border-radius:4px; cursor:pointer;">Remove</button>')
358
+ .appendTo(actionsCell);
359
+ removeButton.on('click', function () {
360
+ node.points.splice(index, 1);
361
+ renderPointsTable();
362
+ markDirty();
363
+ });
364
+
365
+ togglePointMode(row, point);
366
+ return row;
367
+ }
368
+
369
+ function renderPointsTable() {
370
+ const container = $('#points-container');
371
+ container.empty();
372
+
373
+ const table = $('<table class="rp-draw-table" style="width:100%; border-collapse:collapse; margin:10px 0;">');
374
+ const thead = $('<thead>').appendTo(table);
375
+ const headerRow = $('<tr style="background-color:#f0f0f0; font-weight:bold;">').appendTo(thead);
376
+ ['Mode', 'X', 'Y', 'List', 'Radius', 'Color', 'Opacity', 'Actions'].forEach(function (title) {
377
+ $('<th style="padding:8px; border:1px solid #ddd; text-align:left;">').text(title).appendTo(headerRow);
378
+ });
379
+
380
+ const tbody = $('<tbody>').appendTo(table);
381
+ if (node.points.length) {
382
+ node.points.forEach(function (point, index) {
383
+ tbody.append(createPointRow(point, index));
384
+ });
385
+ } else {
386
+ $('<tr class="rp-point-empty"><td colspan="8" style="padding:12px; border:1px solid #ddd; text-align:center; color:#777;">No points defined. Use "Add point" to create one.</td></tr>')
387
+ .appendTo(tbody);
388
+ }
389
+
390
+ container.append(table);
391
+
392
+ const addButton = $('<button type="button" style="background:#4CAF50; color:#fff; border:none; padding:6px 12px; border-radius:4px; cursor:pointer;">Add point</button>');
393
+ addButton.on('click', function () {
394
+ node.points.push(mergeDefaults(DEFAULT_POINT));
395
+ renderPointsTable();
396
+ markDirty();
397
+ });
398
+ container.append(addButton);
399
+ }
400
+
401
+ function createLineRow(line, index) {
402
+ const row = $('<tr class="rp-line-row">').attr('data-index', index);
403
+
404
+ const modeCell = $('<td style="padding:8px; border:1px solid #ddd; vertical-align:middle;">').appendTo(row);
405
+ const modeSelect = $('<select style="width:100%;">')
406
+ .addClass('line-mode')
407
+ .append('<option value="single">Single values</option>')
408
+ .append('<option value="list">List</option>')
409
+ .val(line.mode || 'single')
410
+ .appendTo(modeCell);
411
+ modeSelect.on('change', function () {
412
+ line.mode = $(this).val();
413
+ toggleLineMode(row, line);
414
+ markDirty();
415
+ });
416
+
417
+ buildTypedCell(row, {
418
+ typeClass: 'line-x1-type',
419
+ inputClass: 'line-x1',
420
+ defaultType: line.x1Type,
421
+ defaultValue: line.x1Value,
422
+ types: ['num', 'msg', 'flow', 'global'],
423
+ placeholder: '0.0 - 1.0',
424
+ onChange: function (input) {
425
+ line.x1Type = input.typedInput('type');
426
+ line.x1Value = input.typedInput('value');
427
+ }
428
+ });
429
+
430
+ buildTypedCell(row, {
431
+ typeClass: 'line-y1-type',
432
+ inputClass: 'line-y1',
433
+ defaultType: line.y1Type,
434
+ defaultValue: line.y1Value,
435
+ types: ['num', 'msg', 'flow', 'global'],
436
+ placeholder: '0.0 - 1.0',
437
+ onChange: function (input) {
438
+ line.y1Type = input.typedInput('type');
439
+ line.y1Value = input.typedInput('value');
440
+ }
441
+ });
442
+
443
+ buildTypedCell(row, {
444
+ typeClass: 'line-x2-type',
445
+ inputClass: 'line-x2',
446
+ defaultType: line.x2Type,
447
+ defaultValue: line.x2Value,
448
+ types: ['num', 'msg', 'flow', 'global'],
449
+ placeholder: '0.0 - 1.0',
450
+ onChange: function (input) {
451
+ line.x2Type = input.typedInput('type');
452
+ line.x2Value = input.typedInput('value');
453
+ }
454
+ });
455
+
456
+ buildTypedCell(row, {
457
+ typeClass: 'line-y2-type',
458
+ inputClass: 'line-y2',
459
+ defaultType: line.y2Type,
460
+ defaultValue: line.y2Value,
461
+ types: ['num', 'msg', 'flow', 'global'],
462
+ placeholder: '0.0 - 1.0',
463
+ onChange: function (input) {
464
+ line.y2Type = input.typedInput('type');
465
+ line.y2Value = input.typedInput('value');
466
+ }
467
+ });
468
+
469
+ buildTypedCell(row, {
470
+ typeClass: 'line-list-type',
471
+ inputClass: 'line-list',
472
+ defaultType: line.listType,
473
+ defaultValue: line.listValue,
474
+ types: ['json', 'msg', 'flow', 'global'],
475
+ placeholder: '[[0,0,1,1], ...]',
476
+ onChange: function (input) {
477
+ line.listType = input.typedInput('type');
478
+ line.listValue = input.typedInput('value');
479
+ }
480
+ });
481
+
482
+ buildTypedCell(row, {
483
+ typeClass: 'line-thickness-type',
484
+ inputClass: 'line-thickness',
485
+ defaultType: line.thicknessType,
486
+ defaultValue: line.thicknessValue,
487
+ types: ['num', 'msg', 'flow', 'global'],
488
+ placeholder: '0.00',
489
+ onChange: function (input) {
490
+ line.thicknessType = input.typedInput('type');
491
+ line.thicknessValue = input.typedInput('value');
492
+ }
493
+ });
494
+
495
+ buildColorCell(row, {
496
+ typeClass: 'line-color-type',
497
+ inputClass: 'line-color',
498
+ pickerClass: 'line-color-picker',
499
+ defaultType: line.colorType,
500
+ defaultValue: line.colorValue,
501
+ onChange: function (input) {
502
+ line.colorType = input.typedInput('type');
503
+ line.colorValue = input.typedInput('value');
504
+ }
505
+ });
506
+
507
+ buildTypedCell(row, {
508
+ typeClass: 'line-opacity-type',
509
+ inputClass: 'line-opacity',
510
+ defaultType: line.opacityType,
511
+ defaultValue: line.opacityValue,
512
+ types: ['num', 'msg', 'flow', 'global'],
513
+ placeholder: '0.0 - 1.0',
514
+ onChange: function (input) {
515
+ line.opacityType = input.typedInput('type');
516
+ line.opacityValue = input.typedInput('value');
517
+ }
518
+ });
519
+
520
+ const actionsCell = $('<td style="padding:8px; border:1px solid #ddd; text-align:center;">').appendTo(row);
521
+ const removeButton = $('<button type="button" style="background:#ff4444; color:#fff; border:none; padding:4px 10px; border-radius:4px; cursor:pointer;">Remove</button>')
522
+ .appendTo(actionsCell);
523
+ removeButton.on('click', function () {
524
+ node.lines.splice(index, 1);
525
+ renderLinesTable();
526
+ markDirty();
527
+ });
528
+
529
+ toggleLineMode(row, line);
530
+ return row;
531
+ }
532
+
533
+ function renderLinesTable() {
534
+ const container = $('#lines-container');
535
+ container.empty();
536
+
537
+ const table = $('<table class="rp-draw-table" style="width:100%; border-collapse:collapse; margin:10px 0;">');
538
+ const thead = $('<thead>').appendTo(table);
539
+ const headerRow = $('<tr style="background-color:#f0f0f0; font-weight:bold;">').appendTo(thead);
540
+ ['Mode', 'X1', 'Y1', 'X2', 'Y2', 'List', 'Thickness', 'Color', 'Opacity', 'Actions'].forEach(function (title) {
541
+ $('<th style="padding:8px; border:1px solid #ddd; text-align:left;">').text(title).appendTo(headerRow);
542
+ });
543
+
544
+ const tbody = $('<tbody>').appendTo(table);
545
+ if (node.lines.length) {
546
+ node.lines.forEach(function (line, index) {
547
+ tbody.append(createLineRow(line, index));
548
+ });
549
+ } else {
550
+ $('<tr class="rp-line-empty"><td colspan="10" style="padding:12px; border:1px solid #ddd; text-align:center; color:#777;">No lines defined. Use "Add line" to create one.</td></tr>')
551
+ .appendTo(tbody);
552
+ }
553
+
554
+ container.append(table);
555
+
556
+ const addButton = $('<button type="button" style="background:#4CAF50; color:#fff; border:none; padding:6px 12px; border-radius:4px; cursor:pointer;">Add line</button>');
557
+ addButton.on('click', function () {
558
+ node.lines.push(mergeDefaults(DEFAULT_LINE));
559
+ renderLinesTable();
560
+ markDirty();
561
+ });
562
+ container.append(addButton);
563
+ }
564
+
565
+ renderPointsTable();
566
+ renderLinesTable();
567
+ },
568
+ oneditsave: function () {
569
+ function readTableValues(tableKey) {
570
+ const cfg = TABLE_CONFIG[tableKey];
571
+ const rows = $(cfg.container).find('tr.' + cfg.rowClass);
572
+ const values = [];
573
+
574
+ rows.each(function () {
575
+ const row = $(this);
576
+ const entry = {};
577
+
578
+ if (tableKey === 'points') {
579
+ entry.mode = row.find('.point-mode').val() || 'single';
580
+ } else if (tableKey === 'lines') {
581
+ entry.mode = row.find('.line-mode').val() || 'single';
582
+ }
583
+
584
+ cfg.columns.forEach(function (column) {
585
+ const selector = column.inputClass ? '.' + column.inputClass : null;
586
+ if (!selector) {
587
+ return;
588
+ }
589
+ const input = row.find(selector);
590
+ if (!input.length || typeof input.typedInput !== 'function') {
591
+ return;
592
+ }
593
+ const keys = getFieldKeys(column);
594
+ entry[keys.typeKey] = input.typedInput('type');
595
+ entry[keys.valueKey] = input.typedInput('value');
596
+ });
597
+
598
+ if (Object.keys(entry).length) {
599
+ values.push(entry);
600
+ }
601
+ });
602
+
603
+ return values;
604
+ }
605
+
606
+ this.points = readTableValues('points');
607
+ this.lines = readTableValues('lines');
608
+ }
609
+ });
610
+ })();
611
+ </script>
612
+
613
+ <script type="text/x-red" data-template-name="draw">
614
+ <!-- Name -->
615
+ <div class="form-row">
616
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
617
+ <input type="text" id="node-input-name" placeholder="draw">
618
+ </div>
619
+
620
+ <hr>
621
+
622
+ <!-- Standard I/O -->
623
+ <div class="form-row">
624
+ <label for="node-input-inputPath"><i class="fa fa-sign-in"></i> Input from</label>
625
+ <input type="text" id="node-input-inputPath" style="width: 70%;">
626
+ <input type="hidden" id="node-input-inputPathType">
627
+ </div>
628
+ <div class="form-row">
629
+ <label for="node-input-outputPath"><i class="fa fa-sign-out"></i> Output to</label>
630
+ <input type="text" id="node-input-outputPath" style="width: 70%;">
631
+ <input type="hidden" id="node-input-outputPathType">
632
+ </div>
633
+ <div class="form-row">
634
+ <label for="node-input-outputFormat"><i class="fa fa-picture-o"></i> Output format</label>
635
+ <select id="node-input-outputFormat" style="width: 200px;">
636
+ <option value="raw">Raw (fastest)</option>
637
+ <option value="jpg">JPEG</option>
638
+ <option value="png">PNG</option>
639
+ <option value="webp">WebP</option>
640
+ </select>
641
+ </div>
642
+ <div class="form-row" id="quality-row">
643
+ <label for="node-input-outputQuality"><i class="fa fa-sliders"></i> Quality</label>
644
+ <input type="number" id="node-input-outputQuality" min="1" max="100" style="width: 70px;">
645
+ <span style="margin-left: 8px; color:#666;">1-100 (JPG/WebP only)</span>
646
+ </div>
647
+ <div class="form-row" id="png-optimize-row" style="display:none;">
648
+ <label for="node-input-pngOptimize"><i class="fa fa-compress"></i> PNG optimize</label>
649
+ <input type="checkbox" id="node-input-pngOptimize" style="display:inline-block; width:auto; vertical-align:baseline;">
650
+ <label for="node-input-pngOptimize" style="width:auto; margin-left:5px;">Compress PNG output</label>
651
+ </div>
652
+
653
+ <!-- Debug configuration -->
654
+ <div class="form-row">
655
+ <label for="node-input-debugEnabled"><i class="fa fa-bug"></i> Debug preview</label>
656
+ <input type="checkbox" id="node-input-debugEnabled" style="display:inline-block; width:auto; vertical-align:baseline;">
657
+ <label for="node-input-debugEnabled" style="width:auto; margin-left:5px;">Show processed image</label>
658
+ </div>
659
+ <div class="form-row" id="debug-width-row" style="display:none;">
660
+ <label for="node-input-debugWidth"><i class="fa fa-arrows-h"></i> Debug width</label>
661
+ <input type="text" id="node-input-debugWidth" style="width: 120px;">
662
+ <input type="hidden" id="node-input-debugWidthType">
663
+ <span style="margin-left: 8px; color:#666;">pixels</span>
664
+ </div>
665
+
666
+ <hr>
667
+
668
+ <!-- Points configuration -->
669
+ <div class="form-row">
670
+ <label style="width:100%;"><i class="fa fa-dot-circle-o"></i> Points</label>
671
+ <div id="points-container" style="width:100%;"></div>
672
+ </div>
673
+ <div class="form-tips" style="font-size:0.85em; color:#666;">
674
+ <b>Point settings:</b>
675
+ <ul>
676
+ <li><b>X, Y</b> - normalized coordinates (0.0-1.0) from the top-left of the image.</li>
677
+ <li><b>Radius</b> - relative point size; larger values draw bigger dots.</li>
678
+ <li><b>Color</b> - pick a fixed colour or source it from the flow via the typed selector.</li>
679
+ <li><b>Opacity</b> - blend amount from 0 (transparent) to 1 (solid).</li>
680
+ <li><b>Mode</b> - switch to <em>List</em> to feed [[x,y], ...] from msg/flow/global/JSON for bulk points.</li>
681
+ <li>Use <b>Add point</b> and <b>Remove</b> to manage rows.</li>
682
+ </ul>
683
+ </div>
684
+
685
+ <hr>
686
+
687
+ <!-- Lines configuration -->
688
+ <div class="form-row">
689
+ <label style="width:100%;"><i class="fa fa-minus"></i> Lines</label>
690
+ <div id="lines-container" style="width:100%;"></div>
691
+ </div>
692
+ <div class="form-tips" style="font-size:0.85em; color:#666;">
693
+ <b>Line settings:</b>
694
+ <ul>
695
+ <li><b>X1/Y1 & X2/Y2</b> - start and end coordinates (normalized 0.0-1.0).</li>
696
+ <li><b>Thickness</b> - relative stroke width; higher values make bolder lines.</li>
697
+ <li><b>Color & Opacity</b> - pick a stroke colour and blend level, or reference flow data.</li>
698
+ <li><b>Mode</b> - switch to <em>List</em> to feed [[x0,y0,x1,y1], ...] for multiple segments.</li>
699
+ <li>Use <b>Add line</b> and <b>Remove</b> to maintain the list.</li>
700
+ </ul>
701
+ </div>
702
+ </script>
703
+
704
+ <script type="text/x-red" data-help-name="draw">
705
+ <p><b>draw</b> overlays configurable points and line segments onto an image. The editor provides typed values for every field, plus integrated color pickers for quick selection of fixed colors.</p>
706
+
707
+ <h3>Inputs</h3>
708
+ <p>Accepts a single image from the configured message or context path in either Rosepetal raw format or an encoded buffer.</p>
709
+
710
+ <h3>Configuration</h3>
711
+ <p>Each point entry sets X/Y coordinates, point radius, color, and opacity. Each line entry defines start and end coordinates, thickness, color, and opacity. Coordinates and sizes are normalized (0-1) so they scale with any image resolution. All fields support fixed values, message properties, or flow/global context references through the typed input selector.</p>
712
+ <p>Switch a row to <b>List</b> mode to emit multiple shapes from one card. For points, supply <code>[[x,y], ...]</code>. For lines, supply <code>[[x0,y0,x1,y1], ...]</code>. The row's radius/thickness/color/opacity apply to every entry in the list.</p>
713
+
714
+ <h3>Output</h3>
715
+ <p>The annotated image is written to the selected location. Choose <code>raw</code> to retain the native Rosepetal structure or encode to JPG/PNG/WebP with quality and optimization controls.</p>
716
+
717
+ <h3>Debug</h3>
718
+ <p>Enable the debug preview to emit a resized image over the shared debug channel for live inspection in the editor.</p>
719
+ </script>