@elicdavis/node-flow 0.1.8 → 0.1.10

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/dist/index.mjs CHANGED
@@ -38,6 +38,11 @@ var Theme = {
38
38
  },
39
39
  Port: {
40
40
  FontColor: "#afb9bb"
41
+ },
42
+ Message: {
43
+ InfoColor: "#afb9bb",
44
+ WarnColor: "#f1f663ff",
45
+ ErrorColor: "#FF0000"
41
46
  }
42
47
  },
43
48
  BoxSelect: {
@@ -1137,18 +1142,24 @@ function splitStringIntoLines(ctx, str, maxWidth) {
1137
1142
  }
1138
1143
 
1139
1144
  // src/types/text.ts
1140
- var _measured, _size2, _style, _value, _Text_instances, measure_fn;
1145
+ var _measured, _size2, _style, _value, _maxWidth2, _lineSpacing, _textToRender, _Text_instances, measure_fn;
1141
1146
  var _Text = class _Text {
1142
- constructor(value, style) {
1147
+ constructor(value, style, config) {
1143
1148
  __privateAdd(this, _Text_instances);
1144
1149
  __privateAdd(this, _measured);
1145
1150
  __privateAdd(this, _size2);
1146
1151
  __privateAdd(this, _style);
1147
1152
  __privateAdd(this, _value);
1153
+ __privateAdd(this, _maxWidth2);
1154
+ __privateAdd(this, _lineSpacing);
1155
+ __privateAdd(this, _textToRender);
1148
1156
  __privateSet(this, _value, value);
1149
1157
  __privateSet(this, _measured, false);
1150
1158
  __privateSet(this, _size2, Zero());
1151
1159
  __privateSet(this, _style, new TextStyle(style));
1160
+ __privateSet(this, _maxWidth2, (config == null ? void 0 : config.MaxWidth) ? config == null ? void 0 : config.MaxWidth : -1);
1161
+ __privateSet(this, _lineSpacing, (config == null ? void 0 : config.LineSpacing) ? config == null ? void 0 : config.LineSpacing : 5);
1162
+ __privateSet(this, _textToRender, [value]);
1152
1163
  if (!document.fonts.check(`16px "${__privateGet(this, _style).getFont()}"`)) {
1153
1164
  document.fonts.addEventListener("loadingdone", (event) => {
1154
1165
  __privateSet(this, _measured, false);
@@ -1215,6 +1226,10 @@ var _Text = class _Text {
1215
1226
  CopyVector2(out, __privateGet(this, _size2));
1216
1227
  ScaleVector(out, scale);
1217
1228
  }
1229
+ height(ctx) {
1230
+ __privateMethod(this, _Text_instances, measure_fn).call(this, ctx);
1231
+ return __privateGet(this, _size2).y;
1232
+ }
1218
1233
  setColor(color) {
1219
1234
  __privateGet(this, _style).setColor(color);
1220
1235
  }
@@ -1228,8 +1243,17 @@ var _Text = class _Text {
1228
1243
  __privateGet(this, _style).setWeight(weight);
1229
1244
  }
1230
1245
  render(ctx, scale, position) {
1246
+ __privateMethod(this, _Text_instances, measure_fn).call(this, ctx);
1231
1247
  __privateGet(this, _style).setupStyle(ctx, scale);
1232
- ctx.fillText(__privateGet(this, _value), position.x, position.y);
1248
+ let yOffset = 0;
1249
+ for (let i = 0; i < __privateGet(this, _textToRender).length; i++) {
1250
+ ctx.fillText(
1251
+ __privateGet(this, _textToRender)[i],
1252
+ position.x,
1253
+ position.y + yOffset
1254
+ );
1255
+ yOffset += (__privateGet(this, _style).getSize() + __privateGet(this, _lineSpacing)) * scale;
1256
+ }
1233
1257
  }
1234
1258
  style() {
1235
1259
  return __privateGet(this, _style);
@@ -1239,15 +1263,31 @@ _measured = new WeakMap();
1239
1263
  _size2 = new WeakMap();
1240
1264
  _style = new WeakMap();
1241
1265
  _value = new WeakMap();
1266
+ _maxWidth2 = new WeakMap();
1267
+ _lineSpacing = new WeakMap();
1268
+ _textToRender = new WeakMap();
1242
1269
  _Text_instances = new WeakSet();
1243
1270
  measure_fn = function(ctx) {
1244
1271
  if (__privateGet(this, _measured)) {
1245
1272
  return;
1246
1273
  }
1247
1274
  __privateGet(this, _style).setupStyle(ctx, 1);
1248
- const measurements = ctx.measureText(__privateGet(this, _value));
1249
- __privateGet(this, _size2).x = measurements.width;
1250
- __privateGet(this, _size2).y = measurements.actualBoundingBoxAscent + measurements.actualBoundingBoxDescent;
1275
+ if (__privateGet(this, _maxWidth2) == -1) {
1276
+ const measurements = ctx.measureText(__privateGet(this, _value));
1277
+ __privateGet(this, _size2).x = measurements.width;
1278
+ __privateGet(this, _size2).y = measurements.actualBoundingBoxAscent + measurements.actualBoundingBoxDescent;
1279
+ __privateSet(this, _textToRender, [__privateGet(this, _value)]);
1280
+ __privateSet(this, _measured, true);
1281
+ return;
1282
+ }
1283
+ __privateSet(this, _textToRender, splitStringIntoLines(ctx, __privateGet(this, _value), __privateGet(this, _maxWidth2)));
1284
+ __privateGet(this, _size2).x = 0;
1285
+ __privateGet(this, _size2).y = 0;
1286
+ for (let i = 0; i < __privateGet(this, _textToRender).length; i++) {
1287
+ const measurements = ctx.measureText(__privateGet(this, _textToRender)[i]);
1288
+ __privateGet(this, _size2).x = Math.max(__privateGet(this, _size2).x, measurements.width);
1289
+ }
1290
+ __privateGet(this, _size2).y += (__privateGet(this, _textToRender).length - 1) * __privateGet(this, _lineSpacing) + __privateGet(this, _style).getSize() * __privateGet(this, _textToRender).length;
1251
1291
  __privateSet(this, _measured, true);
1252
1292
  };
1253
1293
  var Text = _Text;
@@ -2515,14 +2555,14 @@ _disabledStyle = new WeakMap();
2515
2555
  _callback6 = new WeakMap();
2516
2556
 
2517
2557
  // src/widgets/image.ts
2518
- var _url, _image, _maxWidth2, _maxHeight2;
2558
+ var _url, _image, _maxWidth3, _maxHeight2;
2519
2559
  var ImageWidget = class {
2520
2560
  constructor(config) {
2521
2561
  __privateAdd(this, _url);
2522
2562
  __privateAdd(this, _image);
2523
- __privateAdd(this, _maxWidth2);
2563
+ __privateAdd(this, _maxWidth3);
2524
2564
  __privateAdd(this, _maxHeight2);
2525
- __privateSet(this, _maxWidth2, (config == null ? void 0 : config.maxWidth) === void 0 ? 150 : config == null ? void 0 : config.maxWidth);
2565
+ __privateSet(this, _maxWidth3, (config == null ? void 0 : config.maxWidth) === void 0 ? 150 : config == null ? void 0 : config.maxWidth);
2526
2566
  __privateSet(this, _maxHeight2, (config == null ? void 0 : config.maxHeight) === void 0 ? 150 : config == null ? void 0 : config.maxHeight);
2527
2567
  if (config == null ? void 0 : config.image) {
2528
2568
  this.SetUrl(config == null ? void 0 : config.image);
@@ -2552,8 +2592,8 @@ var ImageWidget = class {
2552
2592
  return { "x": 0, "y": 0 };
2553
2593
  }
2554
2594
  let adjust = 1;
2555
- if (__privateGet(this, _image).width > __privateGet(this, _maxWidth2)) {
2556
- adjust = __privateGet(this, _maxWidth2) / __privateGet(this, _image).width;
2595
+ if (__privateGet(this, _image).width > __privateGet(this, _maxWidth3)) {
2596
+ adjust = __privateGet(this, _maxWidth3) / __privateGet(this, _image).width;
2557
2597
  }
2558
2598
  if (__privateGet(this, _image).height > __privateGet(this, _maxHeight2)) {
2559
2599
  let heightAdjust = __privateGet(this, _maxHeight2) / __privateGet(this, _image).height;
@@ -2595,7 +2635,7 @@ var ImageWidget = class {
2595
2635
  };
2596
2636
  _url = new WeakMap();
2597
2637
  _image = new WeakMap();
2598
- _maxWidth2 = new WeakMap();
2638
+ _maxWidth3 = new WeakMap();
2599
2639
  _maxHeight2 = new WeakMap();
2600
2640
 
2601
2641
  // src/widgets/text.ts
@@ -3839,13 +3879,59 @@ function FormPopup(config) {
3839
3879
 
3840
3880
  // src/node.ts
3841
3881
  var MINIMUM_NODE_WIDTH = 150;
3882
+ var MessageType = /* @__PURE__ */ ((MessageType2) => {
3883
+ MessageType2["Info"] = "info";
3884
+ MessageType2["Warning"] = "warning";
3885
+ MessageType2["Error"] = "error";
3886
+ return MessageType2;
3887
+ })(MessageType || {});
3888
+ function MessageTypeColor(messageType) {
3889
+ switch (messageType) {
3890
+ case "info" /* Info */:
3891
+ return Theme.Node.Message.InfoColor;
3892
+ case "warning" /* Warning */:
3893
+ return Theme.Node.Message.WarnColor;
3894
+ case "error" /* Error */:
3895
+ return Theme.Node.Message.ErrorColor;
3896
+ default:
3897
+ throw new Error(`unrecognized message type ${messageType}`);
3898
+ }
3899
+ }
3842
3900
  var NodeState = /* @__PURE__ */ ((NodeState2) => {
3843
3901
  NodeState2[NodeState2["Idle"] = 0] = "Idle";
3844
3902
  NodeState2[NodeState2["MouseOver"] = 1] = "MouseOver";
3845
3903
  NodeState2[NodeState2["Grabbed"] = 2] = "Grabbed";
3846
3904
  return NodeState2;
3847
3905
  })(NodeState || {});
3848
- var _position, _title2, _subTitle, _infoSymbol, _infoText, _input, _output, _widgets, _locked, _canEditTitle, _canEditInfo, _canEditPorts, _contextMenu2, _metadata, _onSelect, _onUnselect, _onFiledrop, _onDragStop, _titleChangeCallback, _infoChangeCallback, _titleColor, _selectedStyle, _stateStyles, _padding2, _portTextStyle, _elementSpacing, _selected, _inputPortPositions, _outputPortPositions, _widgetPositions, _data, _registeredAnyPropertyChangeCallbacks, _registeredPropertyChangeCallbacks, _FlowNode_instances, popupNodeTitleSelection_fn, popupNodeInfoSelection_fn, popupNewButtonWidget_fn, widgetSubmenu_fn, calculateStyle_fn;
3906
+ var _text7, _alwaysShow;
3907
+ var MessageRenderer = class {
3908
+ constructor(config) {
3909
+ __privateAdd(this, _text7);
3910
+ __privateAdd(this, _alwaysShow);
3911
+ __privateSet(this, _alwaysShow, config.alwaysShow ? config.alwaysShow : false);
3912
+ __privateSet(this, _text7, new Text(
3913
+ config.message,
3914
+ {
3915
+ color: config.color ? config.color : MessageTypeColor(config.type ? config.type : "info" /* Info */)
3916
+ },
3917
+ {
3918
+ LineSpacing: 2.5,
3919
+ MaxWidth: 200
3920
+ }
3921
+ ));
3922
+ }
3923
+ render(ctx, scale, position, hovering) {
3924
+ if (!__privateGet(this, _alwaysShow) && !hovering) {
3925
+ return 0;
3926
+ }
3927
+ ctx.textAlign = "center" /* Center */;
3928
+ __privateGet(this, _text7).render(ctx, scale, position);
3929
+ return __privateGet(this, _text7).height(ctx) * scale;
3930
+ }
3931
+ };
3932
+ _text7 = new WeakMap();
3933
+ _alwaysShow = new WeakMap();
3934
+ var _position, _title2, _subTitle, _infoSymbol, _infoText, _messages, _input, _output, _widgets, _locked, _canEditTitle, _canEditInfo, _canEditPorts, _contextMenu2, _metadata, _onSelect, _onUnselect, _onFiledrop, _onDragStop, _titleChangeCallback, _infoChangeCallback, _titleColor, _selectedStyle, _stateStyles, _padding2, _portTextStyle, _elementSpacing, _selected, _inputPortPositions, _outputPortPositions, _widgetPositions, _data, _registeredAnyPropertyChangeCallbacks, _registeredPropertyChangeCallbacks, _FlowNode_instances, popupNodeTitleSelection_fn, popupNodeInfoSelection_fn, popupNewButtonWidget_fn, widgetSubmenu_fn, calculateStyle_fn;
3849
3935
  var FlowNode = class {
3850
3936
  constructor(config) {
3851
3937
  __privateAdd(this, _FlowNode_instances);
@@ -3854,6 +3940,7 @@ var FlowNode = class {
3854
3940
  __privateAdd(this, _subTitle);
3855
3941
  __privateAdd(this, _infoSymbol);
3856
3942
  __privateAdd(this, _infoText);
3943
+ __privateAdd(this, _messages);
3857
3944
  __privateAdd(this, _input);
3858
3945
  __privateAdd(this, _output);
3859
3946
  __privateAdd(this, _widgets);
@@ -3902,6 +3989,13 @@ var FlowNode = class {
3902
3989
  __privateSet(this, _canEditInfo, (config == null ? void 0 : config.canEditInfo) === void 0 ? false : config.canEditInfo);
3903
3990
  __privateSet(this, _contextMenu2, (config == null ? void 0 : config.contextMenu) === void 0 ? null : config.contextMenu);
3904
3991
  __privateSet(this, _metadata, config == null ? void 0 : config.metadata);
3992
+ __privateSet(this, _messages, []);
3993
+ if (config == null ? void 0 : config.messages) {
3994
+ for (let i = 0; i < config.messages.length; i++) {
3995
+ const message = config.messages[i];
3996
+ __privateGet(this, _messages).push(new MessageRenderer(message));
3997
+ }
3998
+ }
3905
3999
  __privateSet(this, _selected, false);
3906
4000
  __privateSet(this, _onSelect, new Array());
3907
4001
  __privateSet(this, _onUnselect, new Array());
@@ -4394,6 +4488,12 @@ var FlowNode = class {
4394
4488
  outputs() {
4395
4489
  return __privateGet(this, _output).length;
4396
4490
  }
4491
+ addMessage(message) {
4492
+ __privateGet(this, _messages).push(new MessageRenderer(message));
4493
+ }
4494
+ clearMessages() {
4495
+ __privateSet(this, _messages, []);
4496
+ }
4397
4497
  render(ctx, camera, state, mousePosition, postProcess) {
4398
4498
  VectorPool.run(() => {
4399
4499
  const tempMeasurement = VectorPool.get();
@@ -4521,6 +4621,13 @@ var FlowNode = class {
4521
4621
  __privateGet(this, _widgetPositions).Push(widget.Draw(ctx, position, camera.zoom, mousePosition));
4522
4622
  startY += widgetSize.y * camera.zoom + scaledElementSpacing;
4523
4623
  }
4624
+ const messageStart = VectorPool.get();
4625
+ messageStart.x = nodeBounds.Position.x + nodeBounds.Size.x / 2;
4626
+ messageStart.y = nodeBounds.Position.y + nodeBounds.Size.y + 15 * camera.zoom;
4627
+ for (let i = 0; i < __privateGet(this, _messages).length; i++) {
4628
+ const message = __privateGet(this, _messages)[i];
4629
+ messageStart.y += message.render(ctx, camera.zoom, messageStart, !(state === 0 /* Idle */)) + 10 * camera.zoom;
4630
+ }
4524
4631
  });
4525
4632
  }
4526
4633
  };
@@ -4529,6 +4636,7 @@ _title2 = new WeakMap();
4529
4636
  _subTitle = new WeakMap();
4530
4637
  _infoSymbol = new WeakMap();
4531
4638
  _infoText = new WeakMap();
4639
+ _messages = new WeakMap();
4532
4640
  _input = new WeakMap();
4533
4641
  _output = new WeakMap();
4534
4642
  _widgets = new WeakMap();
@@ -4847,15 +4955,15 @@ text_fn = function() {
4847
4955
  };
4848
4956
 
4849
4957
  // src/markdown/entry.ts
4850
- var _text7, _calculatedPositions, _calculatedEntries, _calculatedForWidth, _CodeBlockEntry_instances, calculateLayout_fn;
4958
+ var _text8, _calculatedPositions, _calculatedEntries, _calculatedForWidth, _CodeBlockEntry_instances, calculateLayout_fn;
4851
4959
  var CodeBlockEntry = class {
4852
4960
  constructor(text) {
4853
4961
  __privateAdd(this, _CodeBlockEntry_instances);
4854
- __privateAdd(this, _text7);
4962
+ __privateAdd(this, _text8);
4855
4963
  __privateAdd(this, _calculatedPositions);
4856
4964
  __privateAdd(this, _calculatedEntries);
4857
4965
  __privateAdd(this, _calculatedForWidth);
4858
- __privateSet(this, _text7, text);
4966
+ __privateSet(this, _text8, text);
4859
4967
  __privateSet(this, _calculatedForWidth, -1);
4860
4968
  __privateSet(this, _calculatedEntries, new List());
4861
4969
  __privateSet(this, _calculatedPositions, new List());
@@ -4894,7 +5002,7 @@ var CodeBlockEntry = class {
4894
5002
  return max + padding * 2;
4895
5003
  }
4896
5004
  };
4897
- _text7 = new WeakMap();
5005
+ _text8 = new WeakMap();
4898
5006
  _calculatedPositions = new WeakMap();
4899
5007
  _calculatedEntries = new WeakMap();
4900
5008
  _calculatedForWidth = new WeakMap();
@@ -4908,8 +5016,8 @@ calculateLayout_fn = function(ctx, maxWidth) {
4908
5016
  __privateGet(this, _calculatedEntries).Clear();
4909
5017
  __privateGet(this, _calculatedPositions).Clear();
4910
5018
  let curHeight = 0;
4911
- const lineInc = __privateGet(this, _text7).style().getSize() + Theme.Note.LineSpacing;
4912
- let entries = __privateGet(this, _text7).split("\n");
5019
+ const lineInc = __privateGet(this, _text8).style().getSize() + Theme.Note.LineSpacing;
5020
+ let entries = __privateGet(this, _text8).split("\n");
4913
5021
  for (let entryIndex = 0; entryIndex < entries.length; entryIndex++) {
4914
5022
  const entry = entries[entryIndex];
4915
5023
  let lines = entry.breakIntoLines(ctx, adjustedWith);
@@ -5806,11 +5914,11 @@ var PassSubsystem = class {
5806
5914
  _queue = new WeakMap();
5807
5915
 
5808
5916
  // src/quickMenu.ts
5809
- var _text8;
5917
+ var _text9;
5810
5918
  var QuickMenuGroup = class {
5811
5919
  constructor(text, items) {
5812
- __privateAdd(this, _text8);
5813
- __privateSet(this, _text8, text);
5920
+ __privateAdd(this, _text9);
5921
+ __privateSet(this, _text9, text);
5814
5922
  this.items = items;
5815
5923
  }
5816
5924
  updateRendering(terms) {
@@ -5822,18 +5930,18 @@ var QuickMenuGroup = class {
5822
5930
  shouldRender = true;
5823
5931
  }
5824
5932
  }
5825
- __privateGet(this, _text8).setDisplay(shouldRender ? "flex" /* Flex */ : "none" /* None */);
5933
+ __privateGet(this, _text9).setDisplay(shouldRender ? "flex" /* Flex */ : "none" /* None */);
5826
5934
  }
5827
5935
  };
5828
- _text8 = new WeakMap();
5829
- var _searchText, _text9, _context;
5936
+ _text9 = new WeakMap();
5937
+ var _searchText, _text10, _context;
5830
5938
  var QuickMenuItem = class {
5831
5939
  constructor(searchText, text, context) {
5832
5940
  __privateAdd(this, _searchText);
5833
- __privateAdd(this, _text9);
5941
+ __privateAdd(this, _text10);
5834
5942
  __privateAdd(this, _context);
5835
5943
  __privateSet(this, _searchText, searchText.toLowerCase());
5836
- __privateSet(this, _text9, text);
5944
+ __privateSet(this, _text10, text);
5837
5945
  __privateSet(this, _context, context);
5838
5946
  }
5839
5947
  filter(terms) {
@@ -5851,13 +5959,13 @@ var QuickMenuItem = class {
5851
5959
  return true;
5852
5960
  }
5853
5961
  render(render) {
5854
- __privateGet(this, _text9).setDisplay(render ? "flex" /* Flex */ : "none" /* None */);
5962
+ __privateGet(this, _text10).setDisplay(render ? "flex" /* Flex */ : "none" /* None */);
5855
5963
  }
5856
5964
  rendering() {
5857
- return __privateGet(this, _text9).getDisplay() === "flex" /* Flex */;
5965
+ return __privateGet(this, _text10).getDisplay() === "flex" /* Flex */;
5858
5966
  }
5859
5967
  highlight(highlight) {
5860
- __privateGet(this, _text9).setBackgroundColor(highlight ? Theme.ContextMenu.HighlightColor : "");
5968
+ __privateGet(this, _text10).setBackgroundColor(highlight ? Theme.ContextMenu.HighlightColor : "");
5861
5969
  }
5862
5970
  select() {
5863
5971
  if (__privateGet(this, _context).callback) {
@@ -5866,7 +5974,7 @@ var QuickMenuItem = class {
5866
5974
  }
5867
5975
  };
5868
5976
  _searchText = new WeakMap();
5869
- _text9 = new WeakMap();
5977
+ _text10 = new WeakMap();
5870
5978
  _context = new WeakMap();
5871
5979
  function RecurseBuildContainers(path, config, renderElements, groups) {
5872
5980
  var _a, _b, _c;
@@ -6484,6 +6592,7 @@ export {
6484
6592
  FlowNote,
6485
6593
  GlobalWidgetFactory,
6486
6594
  ImageWidget,
6595
+ MessageType,
6487
6596
  NodeFlowGraph,
6488
6597
  NodeState,
6489
6598
  NumberWidget,