@elicdavis/node-flow 0.1.8 → 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,13 +3879,53 @@ 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;
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;
3849
3929
  var FlowNode = class {
3850
3930
  constructor(config) {
3851
3931
  __privateAdd(this, _FlowNode_instances);
@@ -3854,6 +3934,7 @@ var FlowNode = class {
3854
3934
  __privateAdd(this, _subTitle);
3855
3935
  __privateAdd(this, _infoSymbol);
3856
3936
  __privateAdd(this, _infoText);
3937
+ __privateAdd(this, _messages);
3857
3938
  __privateAdd(this, _input);
3858
3939
  __privateAdd(this, _output);
3859
3940
  __privateAdd(this, _widgets);
@@ -3902,6 +3983,13 @@ var FlowNode = class {
3902
3983
  __privateSet(this, _canEditInfo, (config == null ? void 0 : config.canEditInfo) === void 0 ? false : config.canEditInfo);
3903
3984
  __privateSet(this, _contextMenu2, (config == null ? void 0 : config.contextMenu) === void 0 ? null : config.contextMenu);
3904
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
+ }
3905
3993
  __privateSet(this, _selected, false);
3906
3994
  __privateSet(this, _onSelect, new Array());
3907
3995
  __privateSet(this, _onUnselect, new Array());
@@ -4394,6 +4482,12 @@ var FlowNode = class {
4394
4482
  outputs() {
4395
4483
  return __privateGet(this, _output).length;
4396
4484
  }
4485
+ addMessage(message) {
4486
+ __privateGet(this, _messages).push(new MessageRenderer(message));
4487
+ }
4488
+ clearMessages() {
4489
+ __privateSet(this, _messages, []);
4490
+ }
4397
4491
  render(ctx, camera, state, mousePosition, postProcess) {
4398
4492
  VectorPool.run(() => {
4399
4493
  const tempMeasurement = VectorPool.get();
@@ -4521,6 +4615,13 @@ var FlowNode = class {
4521
4615
  __privateGet(this, _widgetPositions).Push(widget.Draw(ctx, position, camera.zoom, mousePosition));
4522
4616
  startY += widgetSize.y * camera.zoom + scaledElementSpacing;
4523
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
+ }
4524
4625
  });
4525
4626
  }
4526
4627
  };
@@ -4529,6 +4630,7 @@ _title2 = new WeakMap();
4529
4630
  _subTitle = new WeakMap();
4530
4631
  _infoSymbol = new WeakMap();
4531
4632
  _infoText = new WeakMap();
4633
+ _messages = new WeakMap();
4532
4634
  _input = new WeakMap();
4533
4635
  _output = new WeakMap();
4534
4636
  _widgets = new WeakMap();
@@ -4847,15 +4949,15 @@ text_fn = function() {
4847
4949
  };
4848
4950
 
4849
4951
  // src/markdown/entry.ts
4850
- var _text7, _calculatedPositions, _calculatedEntries, _calculatedForWidth, _CodeBlockEntry_instances, calculateLayout_fn;
4952
+ var _text8, _calculatedPositions, _calculatedEntries, _calculatedForWidth, _CodeBlockEntry_instances, calculateLayout_fn;
4851
4953
  var CodeBlockEntry = class {
4852
4954
  constructor(text) {
4853
4955
  __privateAdd(this, _CodeBlockEntry_instances);
4854
- __privateAdd(this, _text7);
4956
+ __privateAdd(this, _text8);
4855
4957
  __privateAdd(this, _calculatedPositions);
4856
4958
  __privateAdd(this, _calculatedEntries);
4857
4959
  __privateAdd(this, _calculatedForWidth);
4858
- __privateSet(this, _text7, text);
4960
+ __privateSet(this, _text8, text);
4859
4961
  __privateSet(this, _calculatedForWidth, -1);
4860
4962
  __privateSet(this, _calculatedEntries, new List());
4861
4963
  __privateSet(this, _calculatedPositions, new List());
@@ -4894,7 +4996,7 @@ var CodeBlockEntry = class {
4894
4996
  return max + padding * 2;
4895
4997
  }
4896
4998
  };
4897
- _text7 = new WeakMap();
4999
+ _text8 = new WeakMap();
4898
5000
  _calculatedPositions = new WeakMap();
4899
5001
  _calculatedEntries = new WeakMap();
4900
5002
  _calculatedForWidth = new WeakMap();
@@ -4908,8 +5010,8 @@ calculateLayout_fn = function(ctx, maxWidth) {
4908
5010
  __privateGet(this, _calculatedEntries).Clear();
4909
5011
  __privateGet(this, _calculatedPositions).Clear();
4910
5012
  let curHeight = 0;
4911
- const lineInc = __privateGet(this, _text7).style().getSize() + Theme.Note.LineSpacing;
4912
- 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");
4913
5015
  for (let entryIndex = 0; entryIndex < entries.length; entryIndex++) {
4914
5016
  const entry = entries[entryIndex];
4915
5017
  let lines = entry.breakIntoLines(ctx, adjustedWith);
@@ -5806,11 +5908,11 @@ var PassSubsystem = class {
5806
5908
  _queue = new WeakMap();
5807
5909
 
5808
5910
  // src/quickMenu.ts
5809
- var _text8;
5911
+ var _text9;
5810
5912
  var QuickMenuGroup = class {
5811
5913
  constructor(text, items) {
5812
- __privateAdd(this, _text8);
5813
- __privateSet(this, _text8, text);
5914
+ __privateAdd(this, _text9);
5915
+ __privateSet(this, _text9, text);
5814
5916
  this.items = items;
5815
5917
  }
5816
5918
  updateRendering(terms) {
@@ -5822,18 +5924,18 @@ var QuickMenuGroup = class {
5822
5924
  shouldRender = true;
5823
5925
  }
5824
5926
  }
5825
- __privateGet(this, _text8).setDisplay(shouldRender ? "flex" /* Flex */ : "none" /* None */);
5927
+ __privateGet(this, _text9).setDisplay(shouldRender ? "flex" /* Flex */ : "none" /* None */);
5826
5928
  }
5827
5929
  };
5828
- _text8 = new WeakMap();
5829
- var _searchText, _text9, _context;
5930
+ _text9 = new WeakMap();
5931
+ var _searchText, _text10, _context;
5830
5932
  var QuickMenuItem = class {
5831
5933
  constructor(searchText, text, context) {
5832
5934
  __privateAdd(this, _searchText);
5833
- __privateAdd(this, _text9);
5935
+ __privateAdd(this, _text10);
5834
5936
  __privateAdd(this, _context);
5835
5937
  __privateSet(this, _searchText, searchText.toLowerCase());
5836
- __privateSet(this, _text9, text);
5938
+ __privateSet(this, _text10, text);
5837
5939
  __privateSet(this, _context, context);
5838
5940
  }
5839
5941
  filter(terms) {
@@ -5851,13 +5953,13 @@ var QuickMenuItem = class {
5851
5953
  return true;
5852
5954
  }
5853
5955
  render(render) {
5854
- __privateGet(this, _text9).setDisplay(render ? "flex" /* Flex */ : "none" /* None */);
5956
+ __privateGet(this, _text10).setDisplay(render ? "flex" /* Flex */ : "none" /* None */);
5855
5957
  }
5856
5958
  rendering() {
5857
- return __privateGet(this, _text9).getDisplay() === "flex" /* Flex */;
5959
+ return __privateGet(this, _text10).getDisplay() === "flex" /* Flex */;
5858
5960
  }
5859
5961
  highlight(highlight) {
5860
- __privateGet(this, _text9).setBackgroundColor(highlight ? Theme.ContextMenu.HighlightColor : "");
5962
+ __privateGet(this, _text10).setBackgroundColor(highlight ? Theme.ContextMenu.HighlightColor : "");
5861
5963
  }
5862
5964
  select() {
5863
5965
  if (__privateGet(this, _context).callback) {
@@ -5866,7 +5968,7 @@ var QuickMenuItem = class {
5866
5968
  }
5867
5969
  };
5868
5970
  _searchText = new WeakMap();
5869
- _text9 = new WeakMap();
5971
+ _text10 = new WeakMap();
5870
5972
  _context = new WeakMap();
5871
5973
  function RecurseBuildContainers(path, config, renderElements, groups) {
5872
5974
  var _a, _b, _c;
@@ -6484,6 +6586,7 @@ export {
6484
6586
  FlowNote,
6485
6587
  GlobalWidgetFactory,
6486
6588
  ImageWidget,
6589
+ MessageType,
6487
6590
  NodeFlowGraph,
6488
6591
  NodeState,
6489
6592
  NumberWidget,