@elicdavis/node-flow 0.1.7 → 0.1.9

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,7 +3879,53 @@ function FormPopup(config) {
3839
3879
 
3840
3880
  // src/node.ts
3841
3881
  var MINIMUM_NODE_WIDTH = 150;
3842
- 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;
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
+ }
3900
+ var NodeState = /* @__PURE__ */ ((NodeState2) => {
3901
+ NodeState2[NodeState2["Idle"] = 0] = "Idle";
3902
+ NodeState2[NodeState2["MouseOver"] = 1] = "MouseOver";
3903
+ NodeState2[NodeState2["Grabbed"] = 2] = "Grabbed";
3904
+ return NodeState2;
3905
+ })(NodeState || {});
3906
+ var _text7;
3907
+ var MessageRenderer = class {
3908
+ constructor(config) {
3909
+ __privateAdd(this, _text7);
3910
+ __privateSet(this, _text7, new Text(
3911
+ config.message,
3912
+ {
3913
+ color: MessageTypeColor(config.type ? config.type : "info" /* Info */)
3914
+ },
3915
+ {
3916
+ LineSpacing: 2.5,
3917
+ MaxWidth: 200
3918
+ }
3919
+ ));
3920
+ }
3921
+ render(ctx, scale, position) {
3922
+ ctx.textAlign = "center" /* Center */;
3923
+ __privateGet(this, _text7).render(ctx, scale, position);
3924
+ return __privateGet(this, _text7).height(ctx) * scale;
3925
+ }
3926
+ };
3927
+ _text7 = new WeakMap();
3928
+ 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;
3843
3929
  var FlowNode = class {
3844
3930
  constructor(config) {
3845
3931
  __privateAdd(this, _FlowNode_instances);
@@ -3848,6 +3934,7 @@ var FlowNode = class {
3848
3934
  __privateAdd(this, _subTitle);
3849
3935
  __privateAdd(this, _infoSymbol);
3850
3936
  __privateAdd(this, _infoText);
3937
+ __privateAdd(this, _messages);
3851
3938
  __privateAdd(this, _input);
3852
3939
  __privateAdd(this, _output);
3853
3940
  __privateAdd(this, _widgets);
@@ -3896,6 +3983,13 @@ var FlowNode = class {
3896
3983
  __privateSet(this, _canEditInfo, (config == null ? void 0 : config.canEditInfo) === void 0 ? false : config.canEditInfo);
3897
3984
  __privateSet(this, _contextMenu2, (config == null ? void 0 : config.contextMenu) === void 0 ? null : config.contextMenu);
3898
3985
  __privateSet(this, _metadata, config == null ? void 0 : config.metadata);
3986
+ __privateSet(this, _messages, []);
3987
+ if (config == null ? void 0 : config.messages) {
3988
+ for (let i = 0; i < config.messages.length; i++) {
3989
+ const message = config.messages[i];
3990
+ __privateGet(this, _messages).push(new MessageRenderer(message));
3991
+ }
3992
+ }
3899
3993
  __privateSet(this, _selected, false);
3900
3994
  __privateSet(this, _onSelect, new Array());
3901
3995
  __privateSet(this, _onUnselect, new Array());
@@ -4388,6 +4482,12 @@ var FlowNode = class {
4388
4482
  outputs() {
4389
4483
  return __privateGet(this, _output).length;
4390
4484
  }
4485
+ addMessage(message) {
4486
+ __privateGet(this, _messages).push(new MessageRenderer(message));
4487
+ }
4488
+ clearMessages() {
4489
+ __privateSet(this, _messages, []);
4490
+ }
4391
4491
  render(ctx, camera, state, mousePosition, postProcess) {
4392
4492
  VectorPool.run(() => {
4393
4493
  const tempMeasurement = VectorPool.get();
@@ -4515,6 +4615,13 @@ var FlowNode = class {
4515
4615
  __privateGet(this, _widgetPositions).Push(widget.Draw(ctx, position, camera.zoom, mousePosition));
4516
4616
  startY += widgetSize.y * camera.zoom + scaledElementSpacing;
4517
4617
  }
4618
+ const messageStart = VectorPool.get();
4619
+ messageStart.x = nodeBounds.Position.x + nodeBounds.Size.x / 2;
4620
+ messageStart.y = nodeBounds.Position.y + nodeBounds.Size.y + 15 * camera.zoom;
4621
+ for (let i = 0; i < __privateGet(this, _messages).length; i++) {
4622
+ const message = __privateGet(this, _messages)[i];
4623
+ messageStart.y += message.render(ctx, camera.zoom, messageStart) + 10 * camera.zoom;
4624
+ }
4518
4625
  });
4519
4626
  }
4520
4627
  };
@@ -4523,6 +4630,7 @@ _title2 = new WeakMap();
4523
4630
  _subTitle = new WeakMap();
4524
4631
  _infoSymbol = new WeakMap();
4525
4632
  _infoText = new WeakMap();
4633
+ _messages = new WeakMap();
4526
4634
  _input = new WeakMap();
4527
4635
  _output = new WeakMap();
4528
4636
  _widgets = new WeakMap();
@@ -4841,15 +4949,15 @@ text_fn = function() {
4841
4949
  };
4842
4950
 
4843
4951
  // src/markdown/entry.ts
4844
- var _text7, _calculatedPositions, _calculatedEntries, _calculatedForWidth, _CodeBlockEntry_instances, calculateLayout_fn;
4952
+ var _text8, _calculatedPositions, _calculatedEntries, _calculatedForWidth, _CodeBlockEntry_instances, calculateLayout_fn;
4845
4953
  var CodeBlockEntry = class {
4846
4954
  constructor(text) {
4847
4955
  __privateAdd(this, _CodeBlockEntry_instances);
4848
- __privateAdd(this, _text7);
4956
+ __privateAdd(this, _text8);
4849
4957
  __privateAdd(this, _calculatedPositions);
4850
4958
  __privateAdd(this, _calculatedEntries);
4851
4959
  __privateAdd(this, _calculatedForWidth);
4852
- __privateSet(this, _text7, text);
4960
+ __privateSet(this, _text8, text);
4853
4961
  __privateSet(this, _calculatedForWidth, -1);
4854
4962
  __privateSet(this, _calculatedEntries, new List());
4855
4963
  __privateSet(this, _calculatedPositions, new List());
@@ -4888,7 +4996,7 @@ var CodeBlockEntry = class {
4888
4996
  return max + padding * 2;
4889
4997
  }
4890
4998
  };
4891
- _text7 = new WeakMap();
4999
+ _text8 = new WeakMap();
4892
5000
  _calculatedPositions = new WeakMap();
4893
5001
  _calculatedEntries = new WeakMap();
4894
5002
  _calculatedForWidth = new WeakMap();
@@ -4902,8 +5010,8 @@ calculateLayout_fn = function(ctx, maxWidth) {
4902
5010
  __privateGet(this, _calculatedEntries).Clear();
4903
5011
  __privateGet(this, _calculatedPositions).Clear();
4904
5012
  let curHeight = 0;
4905
- const lineInc = __privateGet(this, _text7).style().getSize() + Theme.Note.LineSpacing;
4906
- let entries = __privateGet(this, _text7).split("\n");
5013
+ const lineInc = __privateGet(this, _text8).style().getSize() + Theme.Note.LineSpacing;
5014
+ let entries = __privateGet(this, _text8).split("\n");
4907
5015
  for (let entryIndex = 0; entryIndex < entries.length; entryIndex++) {
4908
5016
  const entry = entries[entryIndex];
4909
5017
  let lines = entry.breakIntoLines(ctx, adjustedWith);
@@ -5800,11 +5908,11 @@ var PassSubsystem = class {
5800
5908
  _queue = new WeakMap();
5801
5909
 
5802
5910
  // src/quickMenu.ts
5803
- var _text8;
5911
+ var _text9;
5804
5912
  var QuickMenuGroup = class {
5805
5913
  constructor(text, items) {
5806
- __privateAdd(this, _text8);
5807
- __privateSet(this, _text8, text);
5914
+ __privateAdd(this, _text9);
5915
+ __privateSet(this, _text9, text);
5808
5916
  this.items = items;
5809
5917
  }
5810
5918
  updateRendering(terms) {
@@ -5816,18 +5924,18 @@ var QuickMenuGroup = class {
5816
5924
  shouldRender = true;
5817
5925
  }
5818
5926
  }
5819
- __privateGet(this, _text8).setDisplay(shouldRender ? "flex" /* Flex */ : "none" /* None */);
5927
+ __privateGet(this, _text9).setDisplay(shouldRender ? "flex" /* Flex */ : "none" /* None */);
5820
5928
  }
5821
5929
  };
5822
- _text8 = new WeakMap();
5823
- var _searchText, _text9, _context;
5930
+ _text9 = new WeakMap();
5931
+ var _searchText, _text10, _context;
5824
5932
  var QuickMenuItem = class {
5825
5933
  constructor(searchText, text, context) {
5826
5934
  __privateAdd(this, _searchText);
5827
- __privateAdd(this, _text9);
5935
+ __privateAdd(this, _text10);
5828
5936
  __privateAdd(this, _context);
5829
5937
  __privateSet(this, _searchText, searchText.toLowerCase());
5830
- __privateSet(this, _text9, text);
5938
+ __privateSet(this, _text10, text);
5831
5939
  __privateSet(this, _context, context);
5832
5940
  }
5833
5941
  filter(terms) {
@@ -5845,13 +5953,13 @@ var QuickMenuItem = class {
5845
5953
  return true;
5846
5954
  }
5847
5955
  render(render) {
5848
- __privateGet(this, _text9).setDisplay(render ? "flex" /* Flex */ : "none" /* None */);
5956
+ __privateGet(this, _text10).setDisplay(render ? "flex" /* Flex */ : "none" /* None */);
5849
5957
  }
5850
5958
  rendering() {
5851
- return __privateGet(this, _text9).getDisplay() === "flex" /* Flex */;
5959
+ return __privateGet(this, _text10).getDisplay() === "flex" /* Flex */;
5852
5960
  }
5853
5961
  highlight(highlight) {
5854
- __privateGet(this, _text9).setBackgroundColor(highlight ? Theme.ContextMenu.HighlightColor : "");
5962
+ __privateGet(this, _text10).setBackgroundColor(highlight ? Theme.ContextMenu.HighlightColor : "");
5855
5963
  }
5856
5964
  select() {
5857
5965
  if (__privateGet(this, _context).callback) {
@@ -5860,7 +5968,7 @@ var QuickMenuItem = class {
5860
5968
  }
5861
5969
  };
5862
5970
  _searchText = new WeakMap();
5863
- _text9 = new WeakMap();
5971
+ _text10 = new WeakMap();
5864
5972
  _context = new WeakMap();
5865
5973
  function RecurseBuildContainers(path, config, renderElements, groups) {
5866
5974
  var _a, _b, _c;
@@ -6478,7 +6586,9 @@ export {
6478
6586
  FlowNote,
6479
6587
  GlobalWidgetFactory,
6480
6588
  ImageWidget,
6589
+ MessageType,
6481
6590
  NodeFlowGraph,
6591
+ NodeState,
6482
6592
  NumberWidget,
6483
6593
  Publisher,
6484
6594
  SliderWidget,