orcasvn-react-diagrams 0.1.9 → 0.1.11

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/cjs/index.js CHANGED
@@ -2,9 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var React = require('react');
5
+ var React$1 = require('react');
6
6
  var require$$0 = require('react-dom');
7
- var Flexbox = require('react-svg-flexbox');
8
7
 
9
8
  exports.PositioningAnchor = void 0;
10
9
  (function (PositioningAnchor) {
@@ -37,6 +36,8 @@ exports.TextAlign = void 0;
37
36
  TextAlign[TextAlign["center"] = 2] = "center";
38
37
  })(exports.TextAlign || (exports.TextAlign = {}));
39
38
 
39
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
40
+
40
41
  function getDefaultExportFromCjs (x) {
41
42
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
42
43
  }
@@ -752,7 +753,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
752
753
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
753
754
  };
754
755
 
755
- var ShapeWrapper = React.forwardRef(function (shapeProps, ref) {
756
+ var ShapeWrapper = React$1.forwardRef(function (shapeProps, ref) {
756
757
  //if direction is provided, rotation is based on direction
757
758
  var rotation = shapeProps.rotation || 0;
758
759
  if (shapeProps.direction) {
@@ -782,7 +783,7 @@ var ShapeWrapper = React.forwardRef(function (shapeProps, ref) {
782
783
  position.x = position.x - shapeProps.width / 2;
783
784
  position.y = position.y - shapeProps.height / 2;
784
785
  }
785
- var objectOfAllEventAttributes = React.useMemo(function () {
786
+ var objectOfAllEventAttributes = React$1.useMemo(function () {
786
787
  var arrayOfAllEventAttributes = Object.entries(shapeProps).filter(function (_a) {
787
788
  var k = _a[0]; _a[1];
788
789
  return k.startsWith('on');
@@ -792,26 +793,34 @@ var ShapeWrapper = React.forwardRef(function (shapeProps, ref) {
792
793
  var viewboxWidth = shapeProps.width > shapeProps.height ? 100 : shapeProps.width / shapeProps.height * 100;
793
794
  var viewBoxHeight = shapeProps.height > shapeProps.width ? 100 : shapeProps.height / shapeProps.width * 100;
794
795
  var viewBox = shapeProps.viewBox || "0 0 ".concat(viewboxWidth, " ").concat(viewBoxHeight);
795
- return (React.createElement("g", { transform: "rotate(".concat(rotation, ")"), style: { transformOrigin: transformOrigin, transformBox: "content-box" } },
796
- React.createElement("svg", __assign({ ref: ref, style: { overflow: "visible" }, x: position.x, y: position.y, width: shapeProps.width, height: shapeProps.height, className: shapeProps.cssClass, viewBox: viewBox }, objectOfAllEventAttributes), shapeProps.children)));
796
+ return (React$1.createElement("g", { transform: "rotate(".concat(rotation, ")"), style: { transformOrigin: transformOrigin, transformBox: "content-box" } },
797
+ React$1.createElement("svg", __assign({ ref: ref, style: { overflow: "visible" }, x: position.x, y: position.y, width: shapeProps.width, height: shapeProps.height, className: shapeProps.cssClass, viewBox: viewBox }, objectOfAllEventAttributes), shapeProps.children)));
797
798
  });
798
799
 
799
- var CustomShape = React.forwardRef(function (props, ref) {
800
- return (React.createElement(ShapeWrapper, __assign({}, props, { ref: ref }), props.children));
800
+ var CustomShape = React$1.forwardRef(function (props, ref) {
801
+ return (React$1.createElement(ShapeWrapper, __assign({}, props, { ref: ref }), props.children));
801
802
  });
802
803
 
803
- var CustomPort = /** @class */ (function (_super) {
804
- __extends(CustomPort, _super);
805
- function CustomPort(x, y, width, height, renderShape, shapePositioningAnchor, label) {
806
- var _this = _super.call(this, x, y, width, height, label, React.forwardRef(function (props, ref) {
807
- return (React.createElement(CustomShape, { ref: ref, x: props.x, y: props.y, width: props.width, height: props.height, rotation: props.rotation, positioningAnchor: shapePositioningAnchor, onClick: function (e) { var _a; return (_a = props.onSelected) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseDown: function (e) { var _a; return (_a = props.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseUp: function (e) { var _a; return (_a = props.onMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); } }, renderShape));
804
+ var CustomPortFromJSXElement = /** @class */ (function (_super) {
805
+ __extends(CustomPortFromJSXElement, _super);
806
+ function CustomPortFromJSXElement(x, y, width, height, renderCustomShape, label, shapePositioningAnchor) {
807
+ var _this = _super.call(this, x, y, width, height, label, React$1.forwardRef(function (props, ref) {
808
+ return (React$1.createElement(CustomShape, { ref: ref, x: props.x, y: props.y, width: props.width, height: props.height, rotation: props.rotation, positioningAnchor: shapePositioningAnchor, onClick: function (e) { var _a; return (_a = props.onSelected) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseDown: function (e) { var _a; return (_a = props.onMouseDown) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); }, onMouseUp: function (e) { var _a; return (_a = props.onMouseUp) === null || _a === void 0 ? void 0 : _a.call(props, _this.id, e); } }, renderCustomShape));
808
809
  })) || this;
809
810
  return _this;
810
811
  }
811
- return CustomPort;
812
+ return CustomPortFromJSXElement;
812
813
  }(Port$1));
813
814
 
814
- var Circle = React.forwardRef(function (props, ref) {
815
+ var CustomPortFromShape = /** @class */ (function (_super) {
816
+ __extends(CustomPortFromShape, _super);
817
+ function CustomPortFromShape(x, y, width, height, shape, label) {
818
+ return _super.call(this, x, y, width, height, label, shape) || this;
819
+ }
820
+ return CustomPortFromShape;
821
+ }(Port$1));
822
+
823
+ var Circle = React$1.forwardRef(function (props, ref) {
815
824
  var s = { height: 100, width: 100 };
816
825
  if (props.r) {
817
826
  s.height = props.r * 2;
@@ -824,11 +833,11 @@ var Circle = React.forwardRef(function (props, ref) {
824
833
  s.height = props.height;
825
834
  s.width = props.width;
826
835
  }
827
- return (React.createElement(ShapeWrapper, __assign({ viewBox: '0 0 100 100' }, props, { width: s.width, height: s.height, ref: ref }),
828
- React.createElement("circle", { className: "".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", cx: 50, cy: 50, r: 50, fill: props.fill || 'transparent', stroke: props.stroke || "none", strokeWidth: props.strokeWidth })));
836
+ return (React$1.createElement(ShapeWrapper, __assign({ viewBox: '0 0 100 100' }, props, { width: s.width, height: s.height, ref: ref }),
837
+ React$1.createElement("circle", { className: "".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", cx: 50, cy: 50, r: 50, fill: props.fill || 'transparent', stroke: props.stroke || "none", strokeWidth: props.strokeWidth })));
829
838
  });
830
839
 
831
- var Crescent = function (props) {
840
+ var Crescent = React$1.forwardRef(function (props, ref) {
832
841
  var s = { height: 100, width: 100 };
833
842
  if (props.r) {
834
843
  s.height = props.r * 2;
@@ -842,11 +851,12 @@ var Crescent = function (props) {
842
851
  s.width = props.width;
843
852
  }
844
853
  var sw = props.stroke ? (props.strokeWidth || 1) : 0;
845
- return (React.createElement(ShapeWrapper, __assign({ viewBox: '0 0 100 100' }, props, { width: s.width, height: s.height }),
846
- React.createElement("path", { className: "".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", d: "M0,50 A50,50 0 1,1 100,50 Z", fill: props.fill || 'none', stroke: props.stroke || 'none', strokeWidth: sw })));
847
- };
854
+ return (React$1.createElement(ShapeWrapper, __assign({ ref: ref, viewBox: '0 0 100 100' }, props, { width: s.width, height: s.height }),
855
+ React$1.createElement("rect", { width: 100, height: 100, stroke: "transparent", fill: 'transparent' }),
856
+ React$1.createElement("path", { className: "".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", d: "M 0 75 A 50 50 0 1 1 100 75 Z", fill: props.fill || 'none', stroke: props.stroke || 'none', strokeWidth: sw })));
857
+ });
848
858
 
849
- var Rectangle = function (props) {
859
+ var Rectangle = React$1.forwardRef(function (props, ref) {
850
860
  var scaledWidth = props.width;
851
861
  var scaledHeight = props.height;
852
862
  if (props.width > 100 || props.height > 100) {
@@ -862,11 +872,11 @@ var Rectangle = function (props) {
862
872
  }
863
873
  }
864
874
  var sw = props.stroke ? (props.strokeWidth || 1) : 0;
865
- return (React.createElement(ShapeWrapper, __assign({}, props, { height: props.height, width: props.width }),
866
- React.createElement("rect", { className: "rect-border ".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", width: scaledWidth, height: scaledHeight, fill: props.fill || "transparent", stroke: props.stroke || "none", strokeWidth: sw })));
867
- };
875
+ return (React$1.createElement(ShapeWrapper, __assign({}, props, { ref: ref, height: props.height, width: props.width }),
876
+ React$1.createElement("rect", { className: "rect-border ".concat(props.portMoveableAreaCssClass), vectorEffect: "non-scaling-stroke", width: scaledWidth, height: scaledHeight, fill: props.fill || "transparent", stroke: props.stroke || "none", strokeWidth: sw })));
877
+ });
868
878
 
869
- var RectangularFrame = function (props) {
879
+ var RectangularFrame = React$1.forwardRef(function (props, ref) {
870
880
  var scaledWidth = props.width;
871
881
  var scaledHeight = props.height;
872
882
  if (props.width > 100 || props.height > 100) {
@@ -886,11 +896,11 @@ var RectangularFrame = function (props) {
886
896
  var fw = props.frameColor ? (props.frameWidth || 1) : 0;
887
897
  var scaledFw = scaledWidth / props.width * fw;
888
898
  var sw = props.stroke ? (props.strokeWidth || 1) : 0;
889
- return (React.createElement(ShapeWrapper, __assign({}, props, { height: props.height, width: props.width }),
890
- React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: "rectangular-frame-outer-border ".concat(props.portMoveableAreaCssClass), x: vbX, y: vbY, width: scaledWidth, height: scaledHeight, fill: "none", stroke: props.stroke || "none", strokeWidth: sw }),
891
- React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: 'rectangular-frame-hallway', x: vbX + scaledFw / 2, y: vbY + scaledFw / 2, width: scaledWidth - scaledFw, height: scaledHeight - scaledFw, stroke: props.frameColor || "none", strokeWidth: fw, fill: props.fill || "transparent" }),
892
- React.createElement("rect", { vectorEffect: "non-scaling-stroke", className: 'rectangular-frame-inner-border', x: vbX + scaledFw, y: vbY + scaledFw, width: scaledWidth - scaledFw * 2, height: scaledHeight - scaledFw * 2, stroke: props.stroke || "none", strokeWidth: sw, fill: props.fill || "transparent" })));
893
- };
899
+ return (React$1.createElement(ShapeWrapper, __assign({}, props, { ref: ref, height: props.height, width: props.width }),
900
+ React$1.createElement("rect", { vectorEffect: "non-scaling-stroke", className: "rectangular-frame-outer-border ".concat(props.portMoveableAreaCssClass), x: vbX, y: vbY, width: scaledWidth, height: scaledHeight, fill: "none", stroke: props.stroke || "none", strokeWidth: sw }),
901
+ React$1.createElement("rect", { vectorEffect: "non-scaling-stroke", className: 'rectangular-frame-hallway', x: vbX + scaledFw / 2, y: vbY + scaledFw / 2, width: scaledWidth - scaledFw, height: scaledHeight - scaledFw, stroke: props.frameColor || "none", strokeWidth: fw, fill: props.fill || "transparent" }),
902
+ React$1.createElement("rect", { vectorEffect: "non-scaling-stroke", className: 'rectangular-frame-inner-border', x: vbX + scaledFw, y: vbY + scaledFw, width: scaledWidth - scaledFw * 2, height: scaledHeight - scaledFw * 2, stroke: props.stroke || "none", strokeWidth: sw, fill: props.fill || "transparent" })));
903
+ });
894
904
 
895
905
  var createRoot;
896
906
 
@@ -964,17 +974,17 @@ var PORT_MOVING_OFFSET_THRESHOLD = 15;
964
974
  var SelectionFrame = function (props) {
965
975
  var _a;
966
976
  var bbox = (_a = props.targetSVGElement) === null || _a === void 0 ? void 0 : _a.getBBox();
967
- var _b = React.useState(props.width || (bbox === null || bbox === void 0 ? void 0 : bbox.width) || MIN_ELEMENT_SIZE), width = _b[0], setWidth = _b[1];
968
- var _c = React.useState(props.height || (bbox === null || bbox === void 0 ? void 0 : bbox.height) || MIN_ELEMENT_SIZE), height = _c[0], setHeight = _c[1];
977
+ var _b = React$1.useState(props.width || (bbox === null || bbox === void 0 ? void 0 : bbox.width) || MIN_ELEMENT_SIZE), width = _b[0], setWidth = _b[1];
978
+ var _c = React$1.useState(props.height || (bbox === null || bbox === void 0 ? void 0 : bbox.height) || MIN_ELEMENT_SIZE), height = _c[0], setHeight = _c[1];
969
979
  var x = 0;
970
980
  var y = 0;
971
981
  var framePadding = props.framePadding || 0;
972
982
  var r = 5;
973
- var _d = React.useState(false), draggingRect = _d[0], setDraggingRect = _d[1];
974
- var _e = React.useState(false), draggingCircle = _e[0], setDraggingCircle = _e[1];
975
- var _f = React.useState(0), startX = _f[0], setStartX = _f[1];
976
- var _g = React.useState(0), startY = _g[0], setStartY = _g[1];
977
- var _h = React.useState(0), lastMoveTime = _h[0], setLastMoveTime = _h[1];
983
+ var _d = React$1.useState(false), draggingRect = _d[0], setDraggingRect = _d[1];
984
+ var _e = React$1.useState(false), draggingCircle = _e[0], setDraggingCircle = _e[1];
985
+ var _f = React$1.useState(0), startX = _f[0], setStartX = _f[1];
986
+ var _g = React$1.useState(0), startY = _g[0], setStartY = _g[1];
987
+ var _h = React$1.useState(0), lastMoveTime = _h[0], setLastMoveTime = _h[1];
978
988
  var addRectHandleMouseDown = function (event) {
979
989
  event.stopPropagation();
980
990
  if (!draggingCircle) {
@@ -984,7 +994,7 @@ var SelectionFrame = function (props) {
984
994
  setStartY(event.clientY);
985
995
  }
986
996
  };
987
- var rectHandleMouseMove = React.useCallback(function (event) {
997
+ var rectHandleMouseMove = React$1.useCallback(function (event) {
988
998
  var mouseEvent = event;
989
999
  if (draggingRect) {
990
1000
  var offsetX = mouseEvent.clientX - startX;
@@ -1007,7 +1017,7 @@ var SelectionFrame = function (props) {
1007
1017
  }
1008
1018
  }
1009
1019
  }, [draggingRect, props.onMove, props.movingRate, startX, startY, lastMoveTime]);
1010
- React.useEffect(function () {
1020
+ React$1.useEffect(function () {
1011
1021
  var addRectHandleMouseUp = function () {
1012
1022
  //mouse up
1013
1023
  setDraggingRect(false);
@@ -1032,7 +1042,7 @@ var SelectionFrame = function (props) {
1032
1042
  setDraggingCircle(true);
1033
1043
  }
1034
1044
  };
1035
- React.useEffect(function () {
1045
+ React$1.useEffect(function () {
1036
1046
  var circleHandleMouseMove = function (event) {
1037
1047
  var mouseEvent = event;
1038
1048
  if (draggingCircle) {
@@ -1088,15 +1098,15 @@ var SelectionFrame = function (props) {
1088
1098
  leftX -= rectangleSize / 2;
1089
1099
  topY -= rectangleSize / 2;
1090
1100
  }
1091
- return (React.createElement(React.Fragment, null,
1092
- props.dragDropHandlerElement && React.createElement(props.dragDropHandlerElement, { dragging: draggingRect, onMouseDown: addRectHandleMouseDown }),
1093
- React.createElement("rect", { vectorEffect: "non-scaling-stroke", x: leftX, y: topY, width: width, height: height, fill: 'none', stroke: 'blue', strokeWidth: props.strokeWidth || 5, cursor: draggingRect ? 'grabbing' : 'grab', onMouseDown: addRectHandleMouseDown }),
1101
+ return (React$1.createElement(React$1.Fragment, null,
1102
+ props.dragDropHandlerElement && React$1.createElement(props.dragDropHandlerElement, { dragging: draggingRect, onMouseDown: addRectHandleMouseDown }),
1103
+ React$1.createElement("rect", { vectorEffect: "non-scaling-stroke", x: leftX, y: topY, width: width, height: height, fill: 'none', stroke: 'blue', strokeWidth: props.strokeWidth || 5, cursor: draggingRect ? 'grabbing' : 'grab', onMouseDown: addRectHandleMouseDown }),
1094
1104
  props.resizability.enabled ?
1095
- (React.createElement("circle", { cursor: 'se-resize', cx: leftX + width, cy: topY + height, r: r, fill: 'blue', stroke: 'blue', onMouseDown: circleHandleMouseDown })) : null));
1105
+ (React$1.createElement("circle", { cursor: 'se-resize', cx: leftX + width, cy: topY + height, r: r, fill: 'blue', stroke: 'blue', onMouseDown: circleHandleMouseDown })) : null));
1096
1106
  };
1097
1107
 
1098
1108
  var useSelectionFrame = function (props) {
1099
- React.useEffect(function () {
1109
+ React$1.useEffect(function () {
1100
1110
  if (props.targetSVGElement && props.container) {
1101
1111
  //render SelectionFrame component to the parent element of the targetSVGElement
1102
1112
  if (props.container) {
@@ -1105,7 +1115,7 @@ var useSelectionFrame = function (props) {
1105
1115
  svg_1.style.outline = 'none';
1106
1116
  props.targetSVGElement.appendChild(svg_1);
1107
1117
  var root_1 = createRoot(svg_1);
1108
- root_1.render(React.createElement(SelectionFrame, __assign({}, props, { container: props.container })));
1118
+ root_1.render(React$1.createElement(SelectionFrame, __assign({}, props, { container: props.container })));
1109
1119
  return function () {
1110
1120
  root_1.unmount();
1111
1121
  if (props.targetSVGElement) {
@@ -1262,7 +1272,7 @@ var onElementLinkEnded = function (callback) {
1262
1272
  off: off
1263
1273
  };
1264
1274
  };
1265
- var paperEventEmitterContext = React.createContext({
1275
+ var paperEventEmitterContext = React$1.createContext({
1266
1276
  emitter: eventEmitter,
1267
1277
  emitPaperClicked: emitPaperClicked,
1268
1278
  onPaperClicked: onPaperClicked,
@@ -1290,13 +1300,13 @@ var paperEventEmitterContext = React.createContext({
1290
1300
  onElementLinkEnded: onElementLinkEnded,
1291
1301
  });
1292
1302
 
1293
- var Text = React.forwardRef(function (_a, ref) {
1303
+ var Text = React$1.forwardRef(function (_a, ref) {
1294
1304
  var id = _a.id, content = _a.content, x = _a.x, y = _a.y, width = _a.width, height = _a.height, _b = _a.align, align = _b === void 0 ? exports.TextAlign.left : _b, fontSizeProp = _a.fontSize, border = _a.border, container = _a.container, onSelected = _a.onSelected, onMoved = _a.onMoved, onResized = _a.onResized, onContentChanged = _a.onContentChanged;
1295
- var _c = React.useState(false), isSelected = _c[0], setIsSelected = _c[1];
1296
- var _d = React.useState(false), isEditing = _d[0], setIsEditing = _d[1];
1297
- var svgRef = React.useRef();
1298
- var onPaperClicked = React.useContext(paperEventEmitterContext).onPaperClicked;
1299
- React.useEffect(function () {
1305
+ var _c = React$1.useState(false), isSelected = _c[0], setIsSelected = _c[1];
1306
+ var _d = React$1.useState(false), isEditing = _d[0], setIsEditing = _d[1];
1307
+ var svgRef = React$1.useRef();
1308
+ var onPaperClicked = React$1.useContext(paperEventEmitterContext).onPaperClicked;
1309
+ React$1.useEffect(function () {
1300
1310
  var paperClickListener = onPaperClicked(function (ev) {
1301
1311
  var _a;
1302
1312
  var textareaELe = (_a = svgRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('textarea');
@@ -1343,7 +1353,7 @@ var Text = React.forwardRef(function (_a, ref) {
1343
1353
  strokeWidth: 3,
1344
1354
  movingOffsetThreshold: TEXT_MOVING_OFFSET_THRESHOLD,
1345
1355
  });
1346
- var textAlign = React.useMemo(function () {
1356
+ var textAlign = React$1.useMemo(function () {
1347
1357
  switch (align) {
1348
1358
  case exports.TextAlign.left:
1349
1359
  return 'left';
@@ -1357,7 +1367,7 @@ var Text = React.forwardRef(function (_a, ref) {
1357
1367
  }, [align]);
1358
1368
  var fontSize = fontSizeProp || TEXT_FONT_SIZE;
1359
1369
  var borderStyle = border || 'none';
1360
- return (React.createElement("svg", { style: { overflow: "visible" }, x: x, y: y, ref: function (node) {
1370
+ return (React$1.createElement("svg", { style: { overflow: "visible" }, x: x, y: y, ref: function (node) {
1361
1371
  svgRef.current = node;
1362
1372
  if (typeof ref === 'function') {
1363
1373
  ref(node);
@@ -1366,13 +1376,13 @@ var Text = React.forwardRef(function (_a, ref) {
1366
1376
  ref.current = node;
1367
1377
  }
1368
1378
  }, onClick: handleClick },
1369
- React.createElement("foreignObject", { width: width, height: height, style: {
1379
+ React$1.createElement("foreignObject", { width: width, height: height, style: {
1370
1380
  overflow: 'visible',
1371
1381
  userSelect: 'none',
1372
1382
  WebkitUserSelect: 'none',
1373
1383
  msUserSelect: 'none'
1374
1384
  } },
1375
- React.createElement("div", { style: {
1385
+ React$1.createElement("div", { style: {
1376
1386
  width: '100%',
1377
1387
  height: '100%',
1378
1388
  borderWidth: '1px',
@@ -1381,7 +1391,7 @@ var Text = React.forwardRef(function (_a, ref) {
1381
1391
  // whiteSpace: 'pre-wrap',
1382
1392
  boxSizing: 'border-box',
1383
1393
  } },
1384
- React.createElement("textarea", { style: {
1394
+ React$1.createElement("textarea", { style: {
1385
1395
  fontFamily: 'initial',
1386
1396
  display: 'inline-block',
1387
1397
  width: '100%',
@@ -1399,12 +1409,12 @@ var Text = React.forwardRef(function (_a, ref) {
1399
1409
  }
1400
1410
  }, value: content, onChange: handleChangeText })))));
1401
1411
  });
1402
- var Text$1 = React.memo(Text);
1412
+ var Text$1 = React$1.memo(Text);
1403
1413
 
1404
- var Port1 = React.forwardRef(function (props, ref) {
1414
+ var Port1 = React$1.forwardRef(function (props, ref) {
1405
1415
  var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, container = props.container, label = props.label, onPortLabelMoved = props.onPortLabelMoved, onPortLabelResized = props.onPortLabelResized, onPortLabelContentChanged = props.onPortLabelContentChanged, onSelected = props.onSelected, onMouseDown = props.onMouseDown, onMouseUp = props.onMouseUp, calculateRotationAngle = props.calculateRotationAngle, renderShape = props.renderShape;
1406
- var textRef = React.useRef(null);
1407
- var rotationAngle = React.useMemo(function () {
1416
+ var textRef = React$1.useRef(null);
1417
+ var rotationAngle = React$1.useMemo(function () {
1408
1418
  if (!calculateRotationAngle)
1409
1419
  return 0;
1410
1420
  return calculateRotationAngle(x, y);
@@ -1412,22 +1422,22 @@ var Port1 = React.forwardRef(function (props, ref) {
1412
1422
  var renderLabel = function (label) {
1413
1423
  var content = label.content, size = label.size;
1414
1424
  var position = label.position || PORT_LABEL_POSITION;
1415
- return React.createElement(Text$1, { id: label.id, ref: textRef, x: x + position.x, y: y + position.y, width: size.width, height: size.height, content: content, fontSize: label.fontSize, border: label.border, container: container, onMoved: onPortLabelMoved, onResized: onPortLabelResized, onContentChanged: onPortLabelContentChanged });
1425
+ return React$1.createElement(Text$1, { id: label.id, ref: textRef, x: x + position.x, y: y + position.y, width: size.width, height: size.height, content: content, fontSize: label.fontSize, border: label.border, container: container, onMoved: onPortLabelMoved, onResized: onPortLabelResized, onContentChanged: onPortLabelContentChanged });
1416
1426
  };
1417
- var renderedShape = React.useMemo(function () {
1427
+ var renderedShape = React$1.useMemo(function () {
1418
1428
  if (renderShape) {
1419
1429
  var RenderShape = renderShape;
1420
- return (React.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
1430
+ return (React$1.createElement(RenderShape, __assign({ ref: ref }, props, { rotation: rotationAngle })));
1421
1431
  }
1422
1432
  else {
1423
- return React.createElement(Circle, { onMouseDown: function (e) { return onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(id, e); }, onMouseUp: function (e) { return onMouseUp === null || onMouseUp === void 0 ? void 0 : onMouseUp(id, e); }, onClick: function (e) { return onSelected === null || onSelected === void 0 ? void 0 : onSelected(id, e); }, ref: ref, x: x, y: y, positioningAnchor: exports.PositioningAnchor.Center, height: height, width: width, stroke: "black", fill: "black" });
1433
+ return React$1.createElement(Circle, { onMouseDown: function (e) { return onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(id, e); }, onMouseUp: function (e) { return onMouseUp === null || onMouseUp === void 0 ? void 0 : onMouseUp(id, e); }, onClick: function (e) { return onSelected === null || onSelected === void 0 ? void 0 : onSelected(id, e); }, ref: ref, x: x, y: y, positioningAnchor: exports.PositioningAnchor.Center, height: height, width: width, stroke: "black", fill: "black" });
1424
1434
  }
1425
1435
  }, [props]);
1426
- return (React.createElement(React.Fragment, null,
1436
+ return (React$1.createElement(React$1.Fragment, null,
1427
1437
  renderedShape,
1428
1438
  label && renderLabel(label)));
1429
1439
  });
1430
- var Port = React.memo(Port1);
1440
+ var Port = React$1.memo(Port1);
1431
1441
 
1432
1442
  // Render the svg <path> element
1433
1443
  function getCurvePathData(points, smoothing, closed) {
@@ -1588,14 +1598,14 @@ function calculateAngleWithOx(pStart, pEnd) {
1588
1598
  //Defined remove icon for element link, shown when element link is selected.
1589
1599
  function CloseIcon(_a) {
1590
1600
  var onClick = _a.onClick;
1591
- return (React.createElement("svg", { width: 20, height: 20, viewBox: "0 0 24.00 24.00", xmlns: "http://www.w3.org/2000/svg", fill: "#ff0000", transform: "rotate(0)", onMouseDown: function (ev) { ev.stopPropagation(); }, onClick: onClick, cursor: 'pointer' },
1592
- React.createElement("g", { id: "SVGRepo_bgCarrier", strokeWidth: "0", transform: "translate(3.84,3.84), scale(0.68)" },
1593
- React.createElement("rect", { x: "0", y: "0", width: "24.00", height: "24.00", rx: "12", fill: "#ffffff", strokeWidth: "0" })),
1594
- React.createElement("g", { id: "SVGRepo_tracerCarrier", strokeLinecap: "round", strokeLinejoin: "round", stroke: "#CCCCCC", "stroke-width": "0.048" }),
1595
- React.createElement("g", { id: "SVGRepo_iconCarrier" },
1596
- React.createElement("g", null,
1597
- React.createElement("path", { fill: "none", d: "M0 0h24v24H0z" }),
1598
- React.createElement("path", { d: "M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-11.414L9.172 7.757 7.757 9.172 10.586 12l-2.829 2.828 1.415 1.415L12 13.414l2.828 2.829 1.415-1.415L13.414 12l2.829-2.828-1.415-1.415L12 10.586z" })))));
1601
+ return (React$1.createElement("svg", { width: 20, height: 20, viewBox: "0 0 24.00 24.00", xmlns: "http://www.w3.org/2000/svg", fill: "#ff0000", transform: "rotate(0)", onMouseDown: function (ev) { ev.stopPropagation(); }, onClick: onClick, cursor: 'pointer' },
1602
+ React$1.createElement("g", { id: "SVGRepo_bgCarrier", strokeWidth: "0", transform: "translate(3.84,3.84), scale(0.68)" },
1603
+ React$1.createElement("rect", { x: "0", y: "0", width: "24.00", height: "24.00", rx: "12", fill: "#ffffff", strokeWidth: "0" })),
1604
+ React$1.createElement("g", { id: "SVGRepo_tracerCarrier", strokeLinecap: "round", strokeLinejoin: "round", stroke: "#CCCCCC", "stroke-width": "0.048" }),
1605
+ React$1.createElement("g", { id: "SVGRepo_iconCarrier" },
1606
+ React$1.createElement("g", null,
1607
+ React$1.createElement("path", { fill: "none", d: "M0 0h24v24H0z" }),
1608
+ React$1.createElement("path", { d: "M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-11.414L9.172 7.757 7.757 9.172 10.586 12l-2.829 2.828 1.415 1.415L12 13.414l2.828 2.829 1.415-1.415L13.414 12l2.829-2.828-1.415-1.415L12 10.586z" })))));
1599
1609
  }
1600
1610
 
1601
1611
  /**
@@ -7350,25 +7360,25 @@ var getRelativePosition = function (clientPosition, relativeElement) {
7350
7360
  };
7351
7361
  };
7352
7362
 
7353
- var makerStart = React.createElement("circle", { cx: 10, cy: 10, r: 10, fill: "blue" });
7354
- var makerEnd = React.createElement("path", { d: "M0 0 L 20 10 L0 20 Z", fill: "blue" }); //<path d="M0 0 L 10 5 L0 10 Z"></path>
7363
+ var makerStart = React$1.createElement("circle", { cx: 10, cy: 10, r: 10, fill: "blue" });
7364
+ var makerEnd = React$1.createElement("path", { d: "M0 0 L 20 10 L0 20 Z", fill: "blue" }); //<path d="M0 0 L 10 5 L0 10 Z"></path>
7355
7365
  var IElementLink = function (_a) {
7356
7366
  var _b, _c;
7357
7367
  var id = _a.id, path = _a.path, stroke = _a.stroke, _d = _a.strokeWidth, strokeWidth = _d === void 0 ? 4 : _d, pointsProp = _a.points, sourcePosition = _a.sourcePosition, targetPosition = _a.targetPosition, onPathChanged = _a.onPathChanged, onClickDelete = _a.onClickDelete, onSelected = _a.onSelected, onDeselected = _a.onDeselected, container = _a.container, _e = _a.markerStart, markerStart = _e === void 0 ? makerStart : _e, _f = _a.markerEnd, markerEnd = _f === void 0 ? makerEnd : _f, _g = _a.markerDistanceFromPort, markerDistanceFromPort = _g === void 0 ? LINK_MARKER_DISTANCE_FROM_PORT : _g, _h = _a.markerSize, markerSize = _h === void 0 ? LINK_MARKER_SIZE : _h, label = _a.label, sourceLabel = _a.sourceLabel, targetLabel = _a.targetLabel, onLabelMoved = _a.onLabelMoved, onLabelResized = _a.onLabelResized, onLabelContentChanged = _a.onLabelContentChanged;
7358
- var _j = React.useState(path), pathStr = _j[0], setPathStr = _j[1];
7359
- var _k = React.useState(pointsProp !== null && pointsProp !== void 0 ? pointsProp : []), points = _k[0], setPoints = _k[1];
7360
- var _l = React.useState(false), isDragging = _l[0], setIsDragging = _l[1];
7361
- var _m = React.useState(), draggingPointIndex = _m[0], setDraggingPointIndex = _m[1];
7362
- var _o = React.useState({
7368
+ var _j = React$1.useState(path), pathStr = _j[0], setPathStr = _j[1];
7369
+ var _k = React$1.useState(pointsProp !== null && pointsProp !== void 0 ? pointsProp : []), points = _k[0], setPoints = _k[1];
7370
+ var _l = React$1.useState(false), isDragging = _l[0], setIsDragging = _l[1];
7371
+ var _m = React$1.useState(), draggingPointIndex = _m[0], setDraggingPointIndex = _m[1];
7372
+ var _o = React$1.useState({
7363
7373
  current: null,
7364
7374
  }), selectedLabelRef = _o[0], setSelectedLabelRef = _o[1];
7365
- var _p = React.useState(false), isSelectedLink = _p[0], setIsSelectedLink = _p[1];
7366
- var onPaperClicked = React.useContext(paperEventEmitterContext).onPaperClicked;
7367
- var pathRef = React.useRef(null);
7368
- var labelRef = React.useRef(null);
7369
- var sourceLabelRef = React.useRef(null);
7370
- var targetLabelRef = React.useRef(null);
7371
- React.useEffect(function () {
7375
+ var _p = React$1.useState(false), isSelectedLink = _p[0], setIsSelectedLink = _p[1];
7376
+ var onPaperClicked = React$1.useContext(paperEventEmitterContext).onPaperClicked;
7377
+ var pathRef = React$1.useRef(null);
7378
+ var labelRef = React$1.useRef(null);
7379
+ var sourceLabelRef = React$1.useRef(null);
7380
+ var targetLabelRef = React$1.useRef(null);
7381
+ React$1.useEffect(function () {
7372
7382
  var paperClickListener = onPaperClicked(function () {
7373
7383
  setSelectedLabelRef({
7374
7384
  current: null,
@@ -7380,17 +7390,17 @@ var IElementLink = function (_a) {
7380
7390
  paperClickListener.off();
7381
7391
  };
7382
7392
  }, []);
7383
- React.useLayoutEffect(function () {
7393
+ React$1.useLayoutEffect(function () {
7384
7394
  var pointsList = __spreadArray(__spreadArray([sourcePosition], points, true), [targetPosition], false);
7385
7395
  var _pathStr = createSmoothPathString(pointsList, undefined);
7386
7396
  setPathStr(_pathStr);
7387
7397
  }, [sourcePosition, points, targetPosition]);
7388
- React.useEffect(function () {
7398
+ React$1.useEffect(function () {
7389
7399
  if (!pathStr)
7390
7400
  return;
7391
7401
  onPathChanged === null || onPathChanged === void 0 ? void 0 : onPathChanged(pathStr, id);
7392
7402
  }, [pathStr, id]);
7393
- React.useLayoutEffect(function () {
7403
+ React$1.useLayoutEffect(function () {
7394
7404
  //handle when creating and moving point
7395
7405
  var handleMouseMove = function (ev) {
7396
7406
  var mouseEvent = ev;
@@ -7546,7 +7556,7 @@ var IElementLink = function (_a) {
7546
7556
  x: relativePosition.x + relativePositionTo.x,
7547
7557
  y: relativePosition.y + relativePositionTo.y,
7548
7558
  };
7549
- return (React.createElement(Text$1, { id: label.id, x: position.x, y: position.y, width: size.width, height: size.height, content: content, fontSize: label.fontSize, border: label.border, ref: curLabelRef, container: container, onSelected: function () { return setSelectedLabelRef(curLabelRef); }, onMoved: handleLabelMoved, onResized: handleLabelResized, onContentChanged: handleLabelContentChanged }));
7559
+ return (React$1.createElement(Text$1, { id: label.id, x: position.x, y: position.y, width: size.width, height: size.height, content: content, fontSize: label.fontSize, border: label.border, ref: curLabelRef, container: container, onSelected: function () { return setSelectedLabelRef(curLabelRef); }, onMoved: handleLabelMoved, onResized: handleLabelResized, onContentChanged: handleLabelContentChanged }));
7550
7560
  };
7551
7561
  var angleMarkerStart = '0';
7552
7562
  var angleMarkerEnd = '0';
@@ -7564,28 +7574,28 @@ var IElementLink = function (_a) {
7564
7574
  }
7565
7575
  centerPathPosition = (_c = pathRef.current) === null || _c === void 0 ? void 0 : _c.getPointAtLength(pathRef.current.getTotalLength() / 2);
7566
7576
  }
7567
- return (React.createElement("g", null,
7568
- React.createElement("path", { ref: pathRef, d: pathStr, className: isSelectedLink ? CSS_CLASS_LINK_SELECTED : '', fill: "none", stroke: stroke || LINK_DEFAULT_COLOR, strokeWidth: strokeWidth }),
7569
- React.createElement("path", { d: pathStr, fill: "none", stroke: 'transparent', strokeWidth: LINK_CLICKABLE_STROKE_WIDTH, onClick: handleClickPath, onMouseDown: handleMouseDownOnPath }),
7570
- isSelectedLink && centerPathPosition && React.createElement("svg", { x: centerPathPosition.x - 10, y: centerPathPosition.y - 10 },
7571
- React.createElement(CloseIcon, { onClick: onClickDelete })),
7577
+ return (React$1.createElement("g", null,
7578
+ React$1.createElement("path", { ref: pathRef, d: pathStr, className: isSelectedLink ? CSS_CLASS_LINK_SELECTED : '', fill: "none", stroke: stroke || LINK_DEFAULT_COLOR, strokeWidth: strokeWidth }),
7579
+ React$1.createElement("path", { d: pathStr, fill: "none", stroke: 'transparent', strokeWidth: LINK_CLICKABLE_STROKE_WIDTH, onClick: handleClickPath, onMouseDown: handleMouseDownOnPath }),
7580
+ isSelectedLink && centerPathPosition && React$1.createElement("svg", { x: centerPathPosition.x - 10, y: centerPathPosition.y - 10 },
7581
+ React$1.createElement(CloseIcon, { onClick: onClickDelete })),
7572
7582
  label && renderLabel(label, 'middle', centerPathPosition),
7573
7583
  sourceLabel && renderLabel(sourceLabel, 'source', sourcePosition),
7574
7584
  targetLabel && renderLabel(targetLabel, 'target', targetPosition),
7575
- markerStartPosition && React.createElement("g", { transform: "rotate(".concat(angleMarkerStart, ")"), style: { transformOrigin: 'center', transformBox: 'content-box' } },
7576
- React.createElement("svg", { x: markerStartPosition.x - markerSize / 2, y: markerStartPosition.y - markerSize / 2, width: markerSize, height: markerSize }, markerStart)),
7577
- markerEndPosition && React.createElement("g", { transform: "rotate(".concat(angleMarkerEnd, ")"), style: { transformOrigin: 'center', transformBox: 'content-box' } },
7578
- React.createElement("svg", { x: markerEndPosition.x - markerSize / 2, y: markerEndPosition.y - markerSize / 2, width: markerSize, height: markerSize }, markerEnd))));
7585
+ markerStartPosition && React$1.createElement("g", { transform: "rotate(".concat(angleMarkerStart, ")"), style: { transformOrigin: 'center', transformBox: 'content-box' } },
7586
+ React$1.createElement("svg", { x: markerStartPosition.x - markerSize / 2, y: markerStartPosition.y - markerSize / 2, width: markerSize, height: markerSize }, markerStart)),
7587
+ markerEndPosition && React$1.createElement("g", { transform: "rotate(".concat(angleMarkerEnd, ")"), style: { transformOrigin: 'center', transformBox: 'content-box' } },
7588
+ React$1.createElement("svg", { x: markerEndPosition.x - markerSize / 2, y: markerEndPosition.y - markerSize / 2, width: markerSize, height: markerSize }, markerEnd))));
7579
7589
  };
7580
- var ElementLink = React.memo(IElementLink);
7590
+ var ElementLink = React$1.memo(IElementLink);
7581
7591
 
7582
7592
  var Ruler = function (_a) {
7583
7593
  var squareSize = _a.squareSize, border = _a.border;
7584
7594
  var numColumns = Math.ceil(3000 / squareSize);
7585
7595
  var numRows = Math.ceil(3000 / squareSize);
7586
7596
  var tableWidth = numColumns * squareSize;
7587
- return (React.createElement("table", { style: { position: 'absolute', zIndex: -1, top: 0, left: 0, borderCollapse: 'collapse', width: tableWidth } },
7588
- React.createElement("tbody", null, Array.from({ length: numRows }).map(function (_, rowIndex) { return (React.createElement("tr", { key: rowIndex, style: { margin: 0, padding: 0 } }, Array.from({ length: numColumns }).map(function (_, colIndex) { return (React.createElement("td", { key: colIndex, style: {
7597
+ return (React$1.createElement("table", { style: { position: 'absolute', zIndex: -1, top: 0, left: 0, borderCollapse: 'collapse', width: tableWidth } },
7598
+ React$1.createElement("tbody", null, Array.from({ length: numRows }).map(function (_, rowIndex) { return (React$1.createElement("tr", { key: rowIndex, style: { margin: 0, padding: 0 } }, Array.from({ length: numColumns }).map(function (_, colIndex) { return (React$1.createElement("td", { key: colIndex, style: {
7589
7599
  width: squareSize,
7590
7600
  height: squareSize,
7591
7601
  border: border,
@@ -7596,16 +7606,16 @@ var Ruler = function (_a) {
7596
7606
  position: 'relative',
7597
7607
  fontSize: 12,
7598
7608
  } },
7599
- rowIndex === 0 ? React.createElement("span", { style: { marginLeft: "-12px" } }, colIndex * squareSize) : "",
7600
- colIndex === 0 ? React.createElement("span", { style: { top: "-9px", position: "absolute" } }, rowIndex * squareSize) : "")); }))); }))));
7609
+ rowIndex === 0 ? React$1.createElement("span", { style: { marginLeft: "-12px" } }, colIndex * squareSize) : "",
7610
+ colIndex === 0 ? React$1.createElement("span", { style: { top: "-9px", position: "absolute" } }, rowIndex * squareSize) : "")); }))); }))));
7601
7611
  };
7602
7612
 
7603
- var ElementWrapper = React.forwardRef(function (_a, ref) {
7613
+ var ElementWrapper = React$1.forwardRef(function (_a, ref) {
7604
7614
  var x = _a.x, y = _a.y, children = _a.children; _a.portPlaceholders; _a.ports; var onClick = _a.onClick, onMouseMove = _a.onMouseMove, onMouseLeave = _a.onMouseLeave, onMouseUp = _a.onMouseUp;
7605
7615
  var handleMouseDown = function (ev) {
7606
7616
  ev.stopPropagation();
7607
7617
  };
7608
- return (React.createElement("svg", { x: x, y: y, onClick: onClick, onMouseDown: handleMouseDown, ref: ref, style: { overflow: "visible" }, onMouseMove: onMouseMove, onMouseLeave: onMouseLeave, onMouseUp: onMouseUp }, children));
7618
+ return (React$1.createElement("svg", { x: x, y: y, onClick: onClick, onMouseDown: handleMouseDown, ref: ref, style: { overflow: "visible" }, onMouseMove: onMouseMove, onMouseLeave: onMouseLeave, onMouseUp: onMouseUp }, children));
7609
7619
  });
7610
7620
 
7611
7621
  // Calculate the position of the 4 vertices of a rectangle relative to its parent svg
@@ -7651,27 +7661,1249 @@ var checkPositionOnLine = function (position, line) {
7651
7661
  return _line.contains(point);
7652
7662
  };
7653
7663
 
7664
+ var bundle = {exports: {}};
7665
+
7666
+ var cssLayout = {exports: {}};
7667
+
7668
+ (function (module, exports) {
7669
+ // UMD (Universal Module Definition)
7670
+ // See https://github.com/umdjs/umd for reference
7671
+ //
7672
+ // This file uses the following specific UMD implementation:
7673
+ // https://github.com/umdjs/umd/blob/master/returnExports.js
7674
+ (function(root, factory) {
7675
+ {
7676
+ // Node. Does not work with strict CommonJS, but
7677
+ // only CommonJS-like environments that support module.exports,
7678
+ // like Node.
7679
+ module.exports = factory();
7680
+ }
7681
+ }(commonjsGlobal, function() {
7682
+ /**
7683
+ * Copyright (c) 2014, Facebook, Inc.
7684
+ * All rights reserved.
7685
+ *
7686
+ * This source code is licensed under the BSD-style license found in the
7687
+ * LICENSE file in the root directory of this source tree. An additional grant
7688
+ * of patent rights can be found in the PATENTS file in the same directory.
7689
+ */
7690
+
7691
+ var computeLayout = (function() {
7692
+
7693
+ var CSS_UNDEFINED;
7694
+
7695
+ var CSS_DIRECTION_INHERIT = 'inherit';
7696
+ var CSS_DIRECTION_LTR = 'ltr';
7697
+ var CSS_DIRECTION_RTL = 'rtl';
7698
+
7699
+ var CSS_FLEX_DIRECTION_ROW = 'row';
7700
+ var CSS_FLEX_DIRECTION_ROW_REVERSE = 'row-reverse';
7701
+ var CSS_FLEX_DIRECTION_COLUMN = 'column';
7702
+ var CSS_FLEX_DIRECTION_COLUMN_REVERSE = 'column-reverse';
7703
+
7704
+ var CSS_JUSTIFY_FLEX_START = 'flex-start';
7705
+ var CSS_JUSTIFY_CENTER = 'center';
7706
+ var CSS_JUSTIFY_FLEX_END = 'flex-end';
7707
+ var CSS_JUSTIFY_SPACE_BETWEEN = 'space-between';
7708
+ var CSS_JUSTIFY_SPACE_AROUND = 'space-around';
7709
+
7710
+ var CSS_ALIGN_FLEX_START = 'flex-start';
7711
+ var CSS_ALIGN_CENTER = 'center';
7712
+ var CSS_ALIGN_FLEX_END = 'flex-end';
7713
+ var CSS_ALIGN_STRETCH = 'stretch';
7714
+
7715
+ var CSS_POSITION_RELATIVE = 'relative';
7716
+ var CSS_POSITION_ABSOLUTE = 'absolute';
7717
+
7718
+ var leading = {
7719
+ 'row': 'left',
7720
+ 'row-reverse': 'right',
7721
+ 'column': 'top',
7722
+ 'column-reverse': 'bottom'
7723
+ };
7724
+ var trailing = {
7725
+ 'row': 'right',
7726
+ 'row-reverse': 'left',
7727
+ 'column': 'bottom',
7728
+ 'column-reverse': 'top'
7729
+ };
7730
+ var pos = {
7731
+ 'row': 'left',
7732
+ 'row-reverse': 'right',
7733
+ 'column': 'top',
7734
+ 'column-reverse': 'bottom'
7735
+ };
7736
+ var dim = {
7737
+ 'row': 'width',
7738
+ 'row-reverse': 'width',
7739
+ 'column': 'height',
7740
+ 'column-reverse': 'height'
7741
+ };
7742
+
7743
+ // When transpiled to Java / C the node type has layout, children and style
7744
+ // properties. For the JavaScript version this function adds these properties
7745
+ // if they don't already exist.
7746
+ function fillNodes(node) {
7747
+ if (!node.layout || node.isDirty) {
7748
+ node.layout = {
7749
+ width: undefined,
7750
+ height: undefined,
7751
+ top: 0,
7752
+ left: 0,
7753
+ right: 0,
7754
+ bottom: 0
7755
+ };
7756
+ }
7757
+
7758
+ if (!node.style) {
7759
+ node.style = {};
7760
+ }
7761
+
7762
+ if (!node.children) {
7763
+ node.children = [];
7764
+ }
7765
+ node.children.forEach(fillNodes);
7766
+ return node;
7767
+ }
7768
+
7769
+ function isUndefined(value) {
7770
+ return value === undefined;
7771
+ }
7772
+
7773
+ function isRowDirection(flexDirection) {
7774
+ return flexDirection === CSS_FLEX_DIRECTION_ROW ||
7775
+ flexDirection === CSS_FLEX_DIRECTION_ROW_REVERSE;
7776
+ }
7777
+
7778
+ function isColumnDirection(flexDirection) {
7779
+ return flexDirection === CSS_FLEX_DIRECTION_COLUMN ||
7780
+ flexDirection === CSS_FLEX_DIRECTION_COLUMN_REVERSE;
7781
+ }
7782
+
7783
+ function getLeadingMargin(node, axis) {
7784
+ if (node.style.marginStart !== undefined && isRowDirection(axis)) {
7785
+ return node.style.marginStart;
7786
+ }
7787
+
7788
+ var value = null;
7789
+ switch (axis) {
7790
+ case 'row': value = node.style.marginLeft; break;
7791
+ case 'row-reverse': value = node.style.marginRight; break;
7792
+ case 'column': value = node.style.marginTop; break;
7793
+ case 'column-reverse': value = node.style.marginBottom; break;
7794
+ }
7795
+
7796
+ if (value !== undefined) {
7797
+ return value;
7798
+ }
7799
+
7800
+ if (node.style.margin !== undefined) {
7801
+ return node.style.margin;
7802
+ }
7803
+
7804
+ return 0;
7805
+ }
7806
+
7807
+ function getTrailingMargin(node, axis) {
7808
+ if (node.style.marginEnd !== undefined && isRowDirection(axis)) {
7809
+ return node.style.marginEnd;
7810
+ }
7811
+
7812
+ var value = null;
7813
+ switch (axis) {
7814
+ case 'row': value = node.style.marginRight; break;
7815
+ case 'row-reverse': value = node.style.marginLeft; break;
7816
+ case 'column': value = node.style.marginBottom; break;
7817
+ case 'column-reverse': value = node.style.marginTop; break;
7818
+ }
7819
+
7820
+ if (value != null) {
7821
+ return value;
7822
+ }
7823
+
7824
+ if (node.style.margin !== undefined) {
7825
+ return node.style.margin;
7826
+ }
7827
+
7828
+ return 0;
7829
+ }
7830
+
7831
+ function getLeadingPadding(node, axis) {
7832
+ if (node.style.paddingStart !== undefined && node.style.paddingStart >= 0
7833
+ && isRowDirection(axis)) {
7834
+ return node.style.paddingStart;
7835
+ }
7836
+
7837
+ var value = null;
7838
+ switch (axis) {
7839
+ case 'row': value = node.style.paddingLeft; break;
7840
+ case 'row-reverse': value = node.style.paddingRight; break;
7841
+ case 'column': value = node.style.paddingTop; break;
7842
+ case 'column-reverse': value = node.style.paddingBottom; break;
7843
+ }
7844
+
7845
+ if (value != null && value >= 0) {
7846
+ return value;
7847
+ }
7848
+
7849
+ if (node.style.padding !== undefined && node.style.padding >= 0) {
7850
+ return node.style.padding;
7851
+ }
7852
+
7853
+ return 0;
7854
+ }
7855
+
7856
+ function getTrailingPadding(node, axis) {
7857
+ if (node.style.paddingEnd !== undefined && node.style.paddingEnd >= 0
7858
+ && isRowDirection(axis)) {
7859
+ return node.style.paddingEnd;
7860
+ }
7861
+
7862
+ var value = null;
7863
+ switch (axis) {
7864
+ case 'row': value = node.style.paddingRight; break;
7865
+ case 'row-reverse': value = node.style.paddingLeft; break;
7866
+ case 'column': value = node.style.paddingBottom; break;
7867
+ case 'column-reverse': value = node.style.paddingTop; break;
7868
+ }
7869
+
7870
+ if (value != null && value >= 0) {
7871
+ return value;
7872
+ }
7873
+
7874
+ if (node.style.padding !== undefined && node.style.padding >= 0) {
7875
+ return node.style.padding;
7876
+ }
7877
+
7878
+ return 0;
7879
+ }
7880
+
7881
+ function getLeadingBorder(node, axis) {
7882
+ if (node.style.borderStartWidth !== undefined && node.style.borderStartWidth >= 0
7883
+ && isRowDirection(axis)) {
7884
+ return node.style.borderStartWidth;
7885
+ }
7886
+
7887
+ var value = null;
7888
+ switch (axis) {
7889
+ case 'row': value = node.style.borderLeftWidth; break;
7890
+ case 'row-reverse': value = node.style.borderRightWidth; break;
7891
+ case 'column': value = node.style.borderTopWidth; break;
7892
+ case 'column-reverse': value = node.style.borderBottomWidth; break;
7893
+ }
7894
+
7895
+ if (value != null && value >= 0) {
7896
+ return value;
7897
+ }
7898
+
7899
+ if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) {
7900
+ return node.style.borderWidth;
7901
+ }
7902
+
7903
+ return 0;
7904
+ }
7905
+
7906
+ function getTrailingBorder(node, axis) {
7907
+ if (node.style.borderEndWidth !== undefined && node.style.borderEndWidth >= 0
7908
+ && isRowDirection(axis)) {
7909
+ return node.style.borderEndWidth;
7910
+ }
7911
+
7912
+ var value = null;
7913
+ switch (axis) {
7914
+ case 'row': value = node.style.borderRightWidth; break;
7915
+ case 'row-reverse': value = node.style.borderLeftWidth; break;
7916
+ case 'column': value = node.style.borderBottomWidth; break;
7917
+ case 'column-reverse': value = node.style.borderTopWidth; break;
7918
+ }
7919
+
7920
+ if (value != null && value >= 0) {
7921
+ return value;
7922
+ }
7923
+
7924
+ if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) {
7925
+ return node.style.borderWidth;
7926
+ }
7927
+
7928
+ return 0;
7929
+ }
7930
+
7931
+ function getLeadingPaddingAndBorder(node, axis) {
7932
+ return getLeadingPadding(node, axis) + getLeadingBorder(node, axis);
7933
+ }
7934
+
7935
+ function getTrailingPaddingAndBorder(node, axis) {
7936
+ return getTrailingPadding(node, axis) + getTrailingBorder(node, axis);
7937
+ }
7938
+
7939
+ function getBorderAxis(node, axis) {
7940
+ return getLeadingBorder(node, axis) + getTrailingBorder(node, axis);
7941
+ }
7942
+
7943
+ function getMarginAxis(node, axis) {
7944
+ return getLeadingMargin(node, axis) + getTrailingMargin(node, axis);
7945
+ }
7946
+
7947
+ function getPaddingAndBorderAxis(node, axis) {
7948
+ return getLeadingPaddingAndBorder(node, axis) +
7949
+ getTrailingPaddingAndBorder(node, axis);
7950
+ }
7951
+
7952
+ function getJustifyContent(node) {
7953
+ if (node.style.justifyContent) {
7954
+ return node.style.justifyContent;
7955
+ }
7956
+ return 'flex-start';
7957
+ }
7958
+
7959
+ function getAlignContent(node) {
7960
+ if (node.style.alignContent) {
7961
+ return node.style.alignContent;
7962
+ }
7963
+ return 'flex-start';
7964
+ }
7965
+
7966
+ function getAlignItem(node, child) {
7967
+ if (child.style.alignSelf) {
7968
+ return child.style.alignSelf;
7969
+ }
7970
+ if (node.style.alignItems) {
7971
+ return node.style.alignItems;
7972
+ }
7973
+ return 'stretch';
7974
+ }
7975
+
7976
+ function resolveAxis(axis, direction) {
7977
+ if (direction === CSS_DIRECTION_RTL) {
7978
+ if (axis === CSS_FLEX_DIRECTION_ROW) {
7979
+ return CSS_FLEX_DIRECTION_ROW_REVERSE;
7980
+ } else if (axis === CSS_FLEX_DIRECTION_ROW_REVERSE) {
7981
+ return CSS_FLEX_DIRECTION_ROW;
7982
+ }
7983
+ }
7984
+
7985
+ return axis;
7986
+ }
7987
+
7988
+ function resolveDirection(node, parentDirection) {
7989
+ var direction;
7990
+ if (node.style.direction) {
7991
+ direction = node.style.direction;
7992
+ } else {
7993
+ direction = CSS_DIRECTION_INHERIT;
7994
+ }
7995
+
7996
+ if (direction === CSS_DIRECTION_INHERIT) {
7997
+ direction = (parentDirection === undefined ? CSS_DIRECTION_LTR : parentDirection);
7998
+ }
7999
+
8000
+ return direction;
8001
+ }
8002
+
8003
+ function getFlexDirection(node) {
8004
+ if (node.style.flexDirection) {
8005
+ return node.style.flexDirection;
8006
+ }
8007
+ return CSS_FLEX_DIRECTION_COLUMN;
8008
+ }
8009
+
8010
+ function getCrossFlexDirection(flexDirection, direction) {
8011
+ if (isColumnDirection(flexDirection)) {
8012
+ return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
8013
+ } else {
8014
+ return CSS_FLEX_DIRECTION_COLUMN;
8015
+ }
8016
+ }
8017
+
8018
+ function getPositionType(node) {
8019
+ if (node.style.position) {
8020
+ return node.style.position;
8021
+ }
8022
+ return 'relative';
8023
+ }
8024
+
8025
+ function isFlex(node) {
8026
+ return (
8027
+ getPositionType(node) === CSS_POSITION_RELATIVE &&
8028
+ node.style.flex > 0
8029
+ );
8030
+ }
8031
+
8032
+ function isFlexWrap(node) {
8033
+ return node.style.flexWrap === 'wrap';
8034
+ }
8035
+
8036
+ function getDimWithMargin(node, axis) {
8037
+ return node.layout[dim[axis]] + getMarginAxis(node, axis);
8038
+ }
8039
+
8040
+ function isDimDefined(node, axis) {
8041
+ return node.style[dim[axis]] !== undefined && node.style[dim[axis]] >= 0;
8042
+ }
8043
+
8044
+ function isPosDefined(node, pos) {
8045
+ return node.style[pos] !== undefined;
8046
+ }
8047
+
8048
+ function isMeasureDefined(node) {
8049
+ return node.style.measure !== undefined;
8050
+ }
8051
+
8052
+ function getPosition(node, pos) {
8053
+ if (node.style[pos] !== undefined) {
8054
+ return node.style[pos];
8055
+ }
8056
+ return 0;
8057
+ }
8058
+
8059
+ function boundAxis(node, axis, value) {
8060
+ var min = {
8061
+ 'row': node.style.minWidth,
8062
+ 'row-reverse': node.style.minWidth,
8063
+ 'column': node.style.minHeight,
8064
+ 'column-reverse': node.style.minHeight
8065
+ }[axis];
8066
+
8067
+ var max = {
8068
+ 'row': node.style.maxWidth,
8069
+ 'row-reverse': node.style.maxWidth,
8070
+ 'column': node.style.maxHeight,
8071
+ 'column-reverse': node.style.maxHeight
8072
+ }[axis];
8073
+
8074
+ var boundValue = value;
8075
+ if (max !== undefined && max >= 0 && boundValue > max) {
8076
+ boundValue = max;
8077
+ }
8078
+ if (min !== undefined && min >= 0 && boundValue < min) {
8079
+ boundValue = min;
8080
+ }
8081
+ return boundValue;
8082
+ }
8083
+
8084
+ function fmaxf(a, b) {
8085
+ if (a > b) {
8086
+ return a;
8087
+ }
8088
+ return b;
8089
+ }
8090
+
8091
+ // When the user specifically sets a value for width or height
8092
+ function setDimensionFromStyle(node, axis) {
8093
+ // The parent already computed us a width or height. We just skip it
8094
+ if (node.layout[dim[axis]] !== undefined) {
8095
+ return;
8096
+ }
8097
+ // We only run if there's a width or height defined
8098
+ if (!isDimDefined(node, axis)) {
8099
+ return;
8100
+ }
8101
+
8102
+ // The dimensions can never be smaller than the padding and border
8103
+ node.layout[dim[axis]] = fmaxf(
8104
+ boundAxis(node, axis, node.style[dim[axis]]),
8105
+ getPaddingAndBorderAxis(node, axis)
8106
+ );
8107
+ }
8108
+
8109
+ function setTrailingPosition(node, child, axis) {
8110
+ child.layout[trailing[axis]] = node.layout[dim[axis]] -
8111
+ child.layout[dim[axis]] - child.layout[pos[axis]];
8112
+ }
8113
+
8114
+ // If both left and right are defined, then use left. Otherwise return
8115
+ // +left or -right depending on which is defined.
8116
+ function getRelativePosition(node, axis) {
8117
+ if (node.style[leading[axis]] !== undefined) {
8118
+ return getPosition(node, leading[axis]);
8119
+ }
8120
+ return -getPosition(node, trailing[axis]);
8121
+ }
8122
+
8123
+ function layoutNodeImpl(node, parentMaxWidth, /*css_direction_t*/parentDirection) {
8124
+ var/*css_direction_t*/ direction = resolveDirection(node, parentDirection);
8125
+ var/*(c)!css_flex_direction_t*//*(java)!int*/ mainAxis = resolveAxis(getFlexDirection(node), direction);
8126
+ var/*(c)!css_flex_direction_t*//*(java)!int*/ crossAxis = getCrossFlexDirection(mainAxis, direction);
8127
+ var/*(c)!css_flex_direction_t*//*(java)!int*/ resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
8128
+
8129
+ // Handle width and height style attributes
8130
+ setDimensionFromStyle(node, mainAxis);
8131
+ setDimensionFromStyle(node, crossAxis);
8132
+
8133
+ // Set the resolved resolution in the node's layout
8134
+ node.layout.direction = direction;
8135
+
8136
+ // The position is set by the parent, but we need to complete it with a
8137
+ // delta composed of the margin and left/top/right/bottom
8138
+ node.layout[leading[mainAxis]] += getLeadingMargin(node, mainAxis) +
8139
+ getRelativePosition(node, mainAxis);
8140
+ node.layout[trailing[mainAxis]] += getTrailingMargin(node, mainAxis) +
8141
+ getRelativePosition(node, mainAxis);
8142
+ node.layout[leading[crossAxis]] += getLeadingMargin(node, crossAxis) +
8143
+ getRelativePosition(node, crossAxis);
8144
+ node.layout[trailing[crossAxis]] += getTrailingMargin(node, crossAxis) +
8145
+ getRelativePosition(node, crossAxis);
8146
+
8147
+ // Inline immutable values from the target node to avoid excessive method
8148
+ // invocations during the layout calculation.
8149
+ var/*int*/ childCount = node.children.length;
8150
+ var/*float*/ paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis);
8151
+
8152
+ if (isMeasureDefined(node)) {
8153
+ var/*bool*/ isResolvedRowDimDefined = !isUndefined(node.layout[dim[resolvedRowAxis]]);
8154
+
8155
+ var/*float*/ width = CSS_UNDEFINED;
8156
+ if (isDimDefined(node, resolvedRowAxis)) {
8157
+ width = node.style.width;
8158
+ } else if (isResolvedRowDimDefined) {
8159
+ width = node.layout[dim[resolvedRowAxis]];
8160
+ } else {
8161
+ width = parentMaxWidth -
8162
+ getMarginAxis(node, resolvedRowAxis);
8163
+ }
8164
+ width -= paddingAndBorderAxisResolvedRow;
8165
+
8166
+ // We only need to give a dimension for the text if we haven't got any
8167
+ // for it computed yet. It can either be from the style attribute or because
8168
+ // the element is flexible.
8169
+ var/*bool*/ isRowUndefined = !isDimDefined(node, resolvedRowAxis) && !isResolvedRowDimDefined;
8170
+ var/*bool*/ isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) &&
8171
+ isUndefined(node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]]);
8172
+
8173
+ // Let's not measure the text if we already know both dimensions
8174
+ if (isRowUndefined || isColumnUndefined) {
8175
+ var/*css_dim_t*/ measureDim = node.style.measure(
8176
+ /*(c)!node->context,*/
8177
+ /*(java)!layoutContext.measureOutput,*/
8178
+ width
8179
+ );
8180
+ if (isRowUndefined) {
8181
+ node.layout.width = measureDim.width +
8182
+ paddingAndBorderAxisResolvedRow;
8183
+ }
8184
+ if (isColumnUndefined) {
8185
+ node.layout.height = measureDim.height +
8186
+ getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
8187
+ }
8188
+ }
8189
+ if (childCount === 0) {
8190
+ return;
8191
+ }
8192
+ }
8193
+
8194
+ var/*bool*/ isNodeFlexWrap = isFlexWrap(node);
8195
+
8196
+ var/*css_justify_t*/ justifyContent = getJustifyContent(node);
8197
+
8198
+ var/*float*/ leadingPaddingAndBorderMain = getLeadingPaddingAndBorder(node, mainAxis);
8199
+ var/*float*/ leadingPaddingAndBorderCross = getLeadingPaddingAndBorder(node, crossAxis);
8200
+ var/*float*/ paddingAndBorderAxisMain = getPaddingAndBorderAxis(node, mainAxis);
8201
+ var/*float*/ paddingAndBorderAxisCross = getPaddingAndBorderAxis(node, crossAxis);
8202
+
8203
+ var/*bool*/ isMainDimDefined = !isUndefined(node.layout[dim[mainAxis]]);
8204
+ var/*bool*/ isCrossDimDefined = !isUndefined(node.layout[dim[crossAxis]]);
8205
+ var/*bool*/ isMainRowDirection = isRowDirection(mainAxis);
8206
+
8207
+ var/*int*/ i;
8208
+ var/*int*/ ii;
8209
+ var/*css_node_t**/ child;
8210
+ var/*(c)!css_flex_direction_t*//*(java)!int*/ axis;
8211
+
8212
+ var/*css_node_t**/ firstAbsoluteChild = null;
8213
+ var/*css_node_t**/ currentAbsoluteChild = null;
8214
+
8215
+ var/*float*/ definedMainDim = CSS_UNDEFINED;
8216
+ if (isMainDimDefined) {
8217
+ definedMainDim = node.layout[dim[mainAxis]] - paddingAndBorderAxisMain;
8218
+ }
8219
+
8220
+ // We want to execute the next two loops one per line with flex-wrap
8221
+ var/*int*/ startLine = 0;
8222
+ var/*int*/ endLine = 0;
8223
+ // var/*int*/ nextOffset = 0;
8224
+ var/*int*/ alreadyComputedNextLayout = 0;
8225
+ // We aggregate the total dimensions of the container in those two variables
8226
+ var/*float*/ linesCrossDim = 0;
8227
+ var/*float*/ linesMainDim = 0;
8228
+ var/*int*/ linesCount = 0;
8229
+ while (endLine < childCount) {
8230
+ // <Loop A> Layout non flexible children and count children by type
8231
+
8232
+ // mainContentDim is accumulation of the dimensions and margin of all the
8233
+ // non flexible children. This will be used in order to either set the
8234
+ // dimensions of the node if none already exist, or to compute the
8235
+ // remaining space left for the flexible children.
8236
+ var/*float*/ mainContentDim = 0;
8237
+
8238
+ // There are three kind of children, non flexible, flexible and absolute.
8239
+ // We need to know how many there are in order to distribute the space.
8240
+ var/*int*/ flexibleChildrenCount = 0;
8241
+ var/*float*/ totalFlexible = 0;
8242
+ var/*int*/ nonFlexibleChildrenCount = 0;
8243
+
8244
+ // Use the line loop to position children in the main axis for as long
8245
+ // as they are using a simple stacking behaviour. Children that are
8246
+ // immediately stacked in the initial loop will not be touched again
8247
+ // in <Loop C>.
8248
+ var/*bool*/ isSimpleStackMain =
8249
+ (isMainDimDefined && justifyContent === CSS_JUSTIFY_FLEX_START) ||
8250
+ (!isMainDimDefined && justifyContent !== CSS_JUSTIFY_CENTER);
8251
+ var/*int*/ firstComplexMain = (isSimpleStackMain ? childCount : startLine);
8252
+
8253
+ // Use the initial line loop to position children in the cross axis for
8254
+ // as long as they are relatively positioned with alignment STRETCH or
8255
+ // FLEX_START. Children that are immediately stacked in the initial loop
8256
+ // will not be touched again in <Loop D>.
8257
+ var/*bool*/ isSimpleStackCross = true;
8258
+ var/*int*/ firstComplexCross = childCount;
8259
+
8260
+ var/*css_node_t**/ firstFlexChild = null;
8261
+ var/*css_node_t**/ currentFlexChild = null;
8262
+
8263
+ var/*float*/ mainDim = leadingPaddingAndBorderMain;
8264
+ var/*float*/ crossDim = 0;
8265
+
8266
+ var/*float*/ maxWidth;
8267
+ for (i = startLine; i < childCount; ++i) {
8268
+ child = node.children[i];
8269
+ child.lineIndex = linesCount;
8270
+
8271
+ child.nextAbsoluteChild = null;
8272
+ child.nextFlexChild = null;
8273
+
8274
+ var/*css_align_t*/ alignItem = getAlignItem(node, child);
8275
+
8276
+ // Pre-fill cross axis dimensions when the child is using stretch before
8277
+ // we call the recursive layout pass
8278
+ if (alignItem === CSS_ALIGN_STRETCH &&
8279
+ getPositionType(child) === CSS_POSITION_RELATIVE &&
8280
+ isCrossDimDefined &&
8281
+ !isDimDefined(child, crossAxis)) {
8282
+ child.layout[dim[crossAxis]] = fmaxf(
8283
+ boundAxis(child, crossAxis, node.layout[dim[crossAxis]] -
8284
+ paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)),
8285
+ // You never want to go smaller than padding
8286
+ getPaddingAndBorderAxis(child, crossAxis)
8287
+ );
8288
+ } else if (getPositionType(child) === CSS_POSITION_ABSOLUTE) {
8289
+ // Store a private linked list of absolutely positioned children
8290
+ // so that we can efficiently traverse them later.
8291
+ if (firstAbsoluteChild === null) {
8292
+ firstAbsoluteChild = child;
8293
+ }
8294
+ if (currentAbsoluteChild !== null) {
8295
+ currentAbsoluteChild.nextAbsoluteChild = child;
8296
+ }
8297
+ currentAbsoluteChild = child;
8298
+
8299
+ // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both
8300
+ // left and right or top and bottom).
8301
+ for (ii = 0; ii < 2; ii++) {
8302
+ axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
8303
+ if (!isUndefined(node.layout[dim[axis]]) &&
8304
+ !isDimDefined(child, axis) &&
8305
+ isPosDefined(child, leading[axis]) &&
8306
+ isPosDefined(child, trailing[axis])) {
8307
+ child.layout[dim[axis]] = fmaxf(
8308
+ boundAxis(child, axis, node.layout[dim[axis]] -
8309
+ getPaddingAndBorderAxis(node, axis) -
8310
+ getMarginAxis(child, axis) -
8311
+ getPosition(child, leading[axis]) -
8312
+ getPosition(child, trailing[axis])),
8313
+ // You never want to go smaller than padding
8314
+ getPaddingAndBorderAxis(child, axis)
8315
+ );
8316
+ }
8317
+ }
8318
+ }
8319
+
8320
+ var/*float*/ nextContentDim = 0;
8321
+
8322
+ // It only makes sense to consider a child flexible if we have a computed
8323
+ // dimension for the node.
8324
+ if (isMainDimDefined && isFlex(child)) {
8325
+ flexibleChildrenCount++;
8326
+ totalFlexible += child.style.flex;
8327
+
8328
+ // Store a private linked list of flexible children so that we can
8329
+ // efficiently traverse them later.
8330
+ if (firstFlexChild === null) {
8331
+ firstFlexChild = child;
8332
+ }
8333
+ if (currentFlexChild !== null) {
8334
+ currentFlexChild.nextFlexChild = child;
8335
+ }
8336
+ currentFlexChild = child;
8337
+
8338
+ // Even if we don't know its exact size yet, we already know the padding,
8339
+ // border and margin. We'll use this partial information, which represents
8340
+ // the smallest possible size for the child, to compute the remaining
8341
+ // available space.
8342
+ nextContentDim = getPaddingAndBorderAxis(child, mainAxis) +
8343
+ getMarginAxis(child, mainAxis);
8344
+
8345
+ } else {
8346
+ maxWidth = CSS_UNDEFINED;
8347
+ if (!isMainRowDirection) {
8348
+ if (isDimDefined(node, resolvedRowAxis)) {
8349
+ maxWidth = node.layout[dim[resolvedRowAxis]] -
8350
+ paddingAndBorderAxisResolvedRow;
8351
+ } else {
8352
+ maxWidth = parentMaxWidth -
8353
+ getMarginAxis(node, resolvedRowAxis) -
8354
+ paddingAndBorderAxisResolvedRow;
8355
+ }
8356
+ }
8357
+
8358
+ // This is the main recursive call. We layout non flexible children.
8359
+ if (alreadyComputedNextLayout === 0) {
8360
+ layoutNode(/*(java)!layoutContext, */child, maxWidth, direction);
8361
+ }
8362
+
8363
+ // Absolute positioned elements do not take part of the layout, so we
8364
+ // don't use them to compute mainContentDim
8365
+ if (getPositionType(child) === CSS_POSITION_RELATIVE) {
8366
+ nonFlexibleChildrenCount++;
8367
+ // At this point we know the final size and margin of the element.
8368
+ nextContentDim = getDimWithMargin(child, mainAxis);
8369
+ }
8370
+ }
8371
+
8372
+ // The element we are about to add would make us go to the next line
8373
+ if (isNodeFlexWrap &&
8374
+ isMainDimDefined &&
8375
+ mainContentDim + nextContentDim > definedMainDim &&
8376
+ // If there's only one element, then it's bigger than the content
8377
+ // and needs its own line
8378
+ i !== startLine) {
8379
+ nonFlexibleChildrenCount--;
8380
+ alreadyComputedNextLayout = 1;
8381
+ break;
8382
+ }
8383
+
8384
+ // Disable simple stacking in the main axis for the current line as
8385
+ // we found a non-trivial child. The remaining children will be laid out
8386
+ // in <Loop C>.
8387
+ if (isSimpleStackMain &&
8388
+ (getPositionType(child) !== CSS_POSITION_RELATIVE || isFlex(child))) {
8389
+ isSimpleStackMain = false;
8390
+ firstComplexMain = i;
8391
+ }
8392
+
8393
+ // Disable simple stacking in the cross axis for the current line as
8394
+ // we found a non-trivial child. The remaining children will be laid out
8395
+ // in <Loop D>.
8396
+ if (isSimpleStackCross &&
8397
+ (getPositionType(child) !== CSS_POSITION_RELATIVE ||
8398
+ (alignItem !== CSS_ALIGN_STRETCH && alignItem !== CSS_ALIGN_FLEX_START) ||
8399
+ isUndefined(child.layout[dim[crossAxis]]))) {
8400
+ isSimpleStackCross = false;
8401
+ firstComplexCross = i;
8402
+ }
8403
+
8404
+ if (isSimpleStackMain) {
8405
+ child.layout[pos[mainAxis]] += mainDim;
8406
+ if (isMainDimDefined) {
8407
+ setTrailingPosition(node, child, mainAxis);
8408
+ }
8409
+
8410
+ mainDim += getDimWithMargin(child, mainAxis);
8411
+ crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));
8412
+ }
8413
+
8414
+ if (isSimpleStackCross) {
8415
+ child.layout[pos[crossAxis]] += linesCrossDim + leadingPaddingAndBorderCross;
8416
+ if (isCrossDimDefined) {
8417
+ setTrailingPosition(node, child, crossAxis);
8418
+ }
8419
+ }
8420
+
8421
+ alreadyComputedNextLayout = 0;
8422
+ mainContentDim += nextContentDim;
8423
+ endLine = i + 1;
8424
+ }
8425
+
8426
+ // <Loop B> Layout flexible children and allocate empty space
8427
+
8428
+ // In order to position the elements in the main axis, we have two
8429
+ // controls. The space between the beginning and the first element
8430
+ // and the space between each two elements.
8431
+ var/*float*/ leadingMainDim = 0;
8432
+ var/*float*/ betweenMainDim = 0;
8433
+
8434
+ // The remaining available space that needs to be allocated
8435
+ var/*float*/ remainingMainDim = 0;
8436
+ if (isMainDimDefined) {
8437
+ remainingMainDim = definedMainDim - mainContentDim;
8438
+ } else {
8439
+ remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim;
8440
+ }
8441
+
8442
+ // If there are flexible children in the mix, they are going to fill the
8443
+ // remaining space
8444
+ if (flexibleChildrenCount !== 0) {
8445
+ var/*float*/ flexibleMainDim = remainingMainDim / totalFlexible;
8446
+ var/*float*/ baseMainDim;
8447
+ var/*float*/ boundMainDim;
8448
+
8449
+ // If the flex share of remaining space doesn't meet min/max bounds,
8450
+ // remove this child from flex calculations.
8451
+ currentFlexChild = firstFlexChild;
8452
+ while (currentFlexChild !== null) {
8453
+ baseMainDim = flexibleMainDim * currentFlexChild.style.flex +
8454
+ getPaddingAndBorderAxis(currentFlexChild, mainAxis);
8455
+ boundMainDim = boundAxis(currentFlexChild, mainAxis, baseMainDim);
8456
+
8457
+ if (baseMainDim !== boundMainDim) {
8458
+ remainingMainDim -= boundMainDim;
8459
+ totalFlexible -= currentFlexChild.style.flex;
8460
+ }
8461
+
8462
+ currentFlexChild = currentFlexChild.nextFlexChild;
8463
+ }
8464
+ flexibleMainDim = remainingMainDim / totalFlexible;
8465
+
8466
+ // The non flexible children can overflow the container, in this case
8467
+ // we should just assume that there is no space available.
8468
+ if (flexibleMainDim < 0) {
8469
+ flexibleMainDim = 0;
8470
+ }
8471
+
8472
+ currentFlexChild = firstFlexChild;
8473
+ while (currentFlexChild !== null) {
8474
+ // At this point we know the final size of the element in the main
8475
+ // dimension
8476
+ currentFlexChild.layout[dim[mainAxis]] = boundAxis(currentFlexChild, mainAxis,
8477
+ flexibleMainDim * currentFlexChild.style.flex +
8478
+ getPaddingAndBorderAxis(currentFlexChild, mainAxis)
8479
+ );
8480
+
8481
+ maxWidth = CSS_UNDEFINED;
8482
+ if (isDimDefined(node, resolvedRowAxis)) {
8483
+ maxWidth = node.layout[dim[resolvedRowAxis]] -
8484
+ paddingAndBorderAxisResolvedRow;
8485
+ } else if (!isMainRowDirection) {
8486
+ maxWidth = parentMaxWidth -
8487
+ getMarginAxis(node, resolvedRowAxis) -
8488
+ paddingAndBorderAxisResolvedRow;
8489
+ }
8490
+
8491
+ // And we recursively call the layout algorithm for this child
8492
+ layoutNode(/*(java)!layoutContext, */currentFlexChild, maxWidth, direction);
8493
+
8494
+ child = currentFlexChild;
8495
+ currentFlexChild = currentFlexChild.nextFlexChild;
8496
+ child.nextFlexChild = null;
8497
+ }
8498
+
8499
+ // We use justifyContent to figure out how to allocate the remaining
8500
+ // space available
8501
+ } else if (justifyContent !== CSS_JUSTIFY_FLEX_START) {
8502
+ if (justifyContent === CSS_JUSTIFY_CENTER) {
8503
+ leadingMainDim = remainingMainDim / 2;
8504
+ } else if (justifyContent === CSS_JUSTIFY_FLEX_END) {
8505
+ leadingMainDim = remainingMainDim;
8506
+ } else if (justifyContent === CSS_JUSTIFY_SPACE_BETWEEN) {
8507
+ remainingMainDim = fmaxf(remainingMainDim, 0);
8508
+ if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 !== 0) {
8509
+ betweenMainDim = remainingMainDim /
8510
+ (flexibleChildrenCount + nonFlexibleChildrenCount - 1);
8511
+ } else {
8512
+ betweenMainDim = 0;
8513
+ }
8514
+ } else if (justifyContent === CSS_JUSTIFY_SPACE_AROUND) {
8515
+ // Space on the edges is half of the space between elements
8516
+ betweenMainDim = remainingMainDim /
8517
+ (flexibleChildrenCount + nonFlexibleChildrenCount);
8518
+ leadingMainDim = betweenMainDim / 2;
8519
+ }
8520
+ }
8521
+
8522
+ // <Loop C> Position elements in the main axis and compute dimensions
8523
+
8524
+ // At this point, all the children have their dimensions set. We need to
8525
+ // find their position. In order to do that, we accumulate data in
8526
+ // variables that are also useful to compute the total dimensions of the
8527
+ // container!
8528
+ mainDim += leadingMainDim;
8529
+
8530
+ for (i = firstComplexMain; i < endLine; ++i) {
8531
+ child = node.children[i];
8532
+
8533
+ if (getPositionType(child) === CSS_POSITION_ABSOLUTE &&
8534
+ isPosDefined(child, leading[mainAxis])) {
8535
+ // In case the child is position absolute and has left/top being
8536
+ // defined, we override the position to whatever the user said
8537
+ // (and margin/border).
8538
+ child.layout[pos[mainAxis]] = getPosition(child, leading[mainAxis]) +
8539
+ getLeadingBorder(node, mainAxis) +
8540
+ getLeadingMargin(child, mainAxis);
8541
+ } else {
8542
+ // If the child is position absolute (without top/left) or relative,
8543
+ // we put it at the current accumulated offset.
8544
+ child.layout[pos[mainAxis]] += mainDim;
8545
+
8546
+ // Define the trailing position accordingly.
8547
+ if (isMainDimDefined) {
8548
+ setTrailingPosition(node, child, mainAxis);
8549
+ }
8550
+
8551
+ // Now that we placed the element, we need to update the variables
8552
+ // We only need to do that for relative elements. Absolute elements
8553
+ // do not take part in that phase.
8554
+ if (getPositionType(child) === CSS_POSITION_RELATIVE) {
8555
+ // The main dimension is the sum of all the elements dimension plus
8556
+ // the spacing.
8557
+ mainDim += betweenMainDim + getDimWithMargin(child, mainAxis);
8558
+ // The cross dimension is the max of the elements dimension since there
8559
+ // can only be one element in that cross dimension.
8560
+ crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));
8561
+ }
8562
+ }
8563
+ }
8564
+
8565
+ var/*float*/ containerCrossAxis = node.layout[dim[crossAxis]];
8566
+ if (!isCrossDimDefined) {
8567
+ containerCrossAxis = fmaxf(
8568
+ // For the cross dim, we add both sides at the end because the value
8569
+ // is aggregate via a max function. Intermediate negative values
8570
+ // can mess this computation otherwise
8571
+ boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross),
8572
+ paddingAndBorderAxisCross
8573
+ );
8574
+ }
8575
+
8576
+ // <Loop D> Position elements in the cross axis
8577
+ for (i = firstComplexCross; i < endLine; ++i) {
8578
+ child = node.children[i];
8579
+
8580
+ if (getPositionType(child) === CSS_POSITION_ABSOLUTE &&
8581
+ isPosDefined(child, leading[crossAxis])) {
8582
+ // In case the child is absolutely positionned and has a
8583
+ // top/left/bottom/right being set, we override all the previously
8584
+ // computed positions to set it correctly.
8585
+ child.layout[pos[crossAxis]] = getPosition(child, leading[crossAxis]) +
8586
+ getLeadingBorder(node, crossAxis) +
8587
+ getLeadingMargin(child, crossAxis);
8588
+
8589
+ } else {
8590
+ var/*float*/ leadingCrossDim = leadingPaddingAndBorderCross;
8591
+
8592
+ // For a relative children, we're either using alignItems (parent) or
8593
+ // alignSelf (child) in order to determine the position in the cross axis
8594
+ if (getPositionType(child) === CSS_POSITION_RELATIVE) {
8595
+ /*eslint-disable */
8596
+ // This variable is intentionally re-defined as the code is transpiled to a block scope language
8597
+ var/*css_align_t*/ alignItem = getAlignItem(node, child);
8598
+ /*eslint-enable */
8599
+ if (alignItem === CSS_ALIGN_STRETCH) {
8600
+ // You can only stretch if the dimension has not already been set
8601
+ // previously.
8602
+ if (isUndefined(child.layout[dim[crossAxis]])) {
8603
+ child.layout[dim[crossAxis]] = fmaxf(
8604
+ boundAxis(child, crossAxis, containerCrossAxis -
8605
+ paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)),
8606
+ // You never want to go smaller than padding
8607
+ getPaddingAndBorderAxis(child, crossAxis)
8608
+ );
8609
+ }
8610
+ } else if (alignItem !== CSS_ALIGN_FLEX_START) {
8611
+ // The remaining space between the parent dimensions+padding and child
8612
+ // dimensions+margin.
8613
+ var/*float*/ remainingCrossDim = containerCrossAxis -
8614
+ paddingAndBorderAxisCross - getDimWithMargin(child, crossAxis);
8615
+
8616
+ if (alignItem === CSS_ALIGN_CENTER) {
8617
+ leadingCrossDim += remainingCrossDim / 2;
8618
+ } else { // CSS_ALIGN_FLEX_END
8619
+ leadingCrossDim += remainingCrossDim;
8620
+ }
8621
+ }
8622
+ }
8623
+
8624
+ // And we apply the position
8625
+ child.layout[pos[crossAxis]] += linesCrossDim + leadingCrossDim;
8626
+
8627
+ // Define the trailing position accordingly.
8628
+ if (isCrossDimDefined) {
8629
+ setTrailingPosition(node, child, crossAxis);
8630
+ }
8631
+ }
8632
+ }
8633
+
8634
+ linesCrossDim += crossDim;
8635
+ linesMainDim = fmaxf(linesMainDim, mainDim);
8636
+ linesCount += 1;
8637
+ startLine = endLine;
8638
+ }
8639
+
8640
+ // <Loop E>
8641
+ //
8642
+ // Note(prenaux): More than one line, we need to layout the crossAxis
8643
+ // according to alignContent.
8644
+ //
8645
+ // Note that we could probably remove <Loop D> and handle the one line case
8646
+ // here too, but for the moment this is safer since it won't interfere with
8647
+ // previously working code.
8648
+ //
8649
+ // See specs:
8650
+ // http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm
8651
+ // section 9.4
8652
+ //
8653
+ if (linesCount > 1 && isCrossDimDefined) {
8654
+ var/*float*/ nodeCrossAxisInnerSize = node.layout[dim[crossAxis]] -
8655
+ paddingAndBorderAxisCross;
8656
+ var/*float*/ remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim;
8657
+
8658
+ var/*float*/ crossDimLead = 0;
8659
+ var/*float*/ currentLead = leadingPaddingAndBorderCross;
8660
+
8661
+ var/*css_align_t*/ alignContent = getAlignContent(node);
8662
+ if (alignContent === CSS_ALIGN_FLEX_END) {
8663
+ currentLead += remainingAlignContentDim;
8664
+ } else if (alignContent === CSS_ALIGN_CENTER) {
8665
+ currentLead += remainingAlignContentDim / 2;
8666
+ } else if (alignContent === CSS_ALIGN_STRETCH) {
8667
+ if (nodeCrossAxisInnerSize > linesCrossDim) {
8668
+ crossDimLead = (remainingAlignContentDim / linesCount);
8669
+ }
8670
+ }
8671
+
8672
+ var/*int*/ endIndex = 0;
8673
+ for (i = 0; i < linesCount; ++i) {
8674
+ var/*int*/ startIndex = endIndex;
8675
+
8676
+ // compute the line's height and find the endIndex
8677
+ var/*float*/ lineHeight = 0;
8678
+ for (ii = startIndex; ii < childCount; ++ii) {
8679
+ child = node.children[ii];
8680
+ if (getPositionType(child) !== CSS_POSITION_RELATIVE) {
8681
+ continue;
8682
+ }
8683
+ if (child.lineIndex !== i) {
8684
+ break;
8685
+ }
8686
+ if (!isUndefined(child.layout[dim[crossAxis]])) {
8687
+ lineHeight = fmaxf(
8688
+ lineHeight,
8689
+ child.layout[dim[crossAxis]] + getMarginAxis(child, crossAxis)
8690
+ );
8691
+ }
8692
+ }
8693
+ endIndex = ii;
8694
+ lineHeight += crossDimLead;
8695
+
8696
+ for (ii = startIndex; ii < endIndex; ++ii) {
8697
+ child = node.children[ii];
8698
+ if (getPositionType(child) !== CSS_POSITION_RELATIVE) {
8699
+ continue;
8700
+ }
8701
+
8702
+ var/*css_align_t*/ alignContentAlignItem = getAlignItem(node, child);
8703
+ if (alignContentAlignItem === CSS_ALIGN_FLEX_START) {
8704
+ child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);
8705
+ } else if (alignContentAlignItem === CSS_ALIGN_FLEX_END) {
8706
+ child.layout[pos[crossAxis]] = currentLead + lineHeight - getTrailingMargin(child, crossAxis) - child.layout[dim[crossAxis]];
8707
+ } else if (alignContentAlignItem === CSS_ALIGN_CENTER) {
8708
+ var/*float*/ childHeight = child.layout[dim[crossAxis]];
8709
+ child.layout[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2;
8710
+ } else if (alignContentAlignItem === CSS_ALIGN_STRETCH) {
8711
+ child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);
8712
+ // TODO(prenaux): Correctly set the height of items with undefined
8713
+ // (auto) crossAxis dimension.
8714
+ }
8715
+ }
8716
+
8717
+ currentLead += lineHeight;
8718
+ }
8719
+ }
8720
+
8721
+ var/*bool*/ needsMainTrailingPos = false;
8722
+ var/*bool*/ needsCrossTrailingPos = false;
8723
+
8724
+ // If the user didn't specify a width or height, and it has not been set
8725
+ // by the container, then we set it via the children.
8726
+ if (!isMainDimDefined) {
8727
+ node.layout[dim[mainAxis]] = fmaxf(
8728
+ // We're missing the last padding at this point to get the final
8729
+ // dimension
8730
+ boundAxis(node, mainAxis, linesMainDim + getTrailingPaddingAndBorder(node, mainAxis)),
8731
+ // We can never assign a width smaller than the padding and borders
8732
+ paddingAndBorderAxisMain
8733
+ );
8734
+
8735
+ if (mainAxis === CSS_FLEX_DIRECTION_ROW_REVERSE ||
8736
+ mainAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
8737
+ needsMainTrailingPos = true;
8738
+ }
8739
+ }
8740
+
8741
+ if (!isCrossDimDefined) {
8742
+ node.layout[dim[crossAxis]] = fmaxf(
8743
+ // For the cross dim, we add both sides at the end because the value
8744
+ // is aggregate via a max function. Intermediate negative values
8745
+ // can mess this computation otherwise
8746
+ boundAxis(node, crossAxis, linesCrossDim + paddingAndBorderAxisCross),
8747
+ paddingAndBorderAxisCross
8748
+ );
8749
+
8750
+ if (crossAxis === CSS_FLEX_DIRECTION_ROW_REVERSE ||
8751
+ crossAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
8752
+ needsCrossTrailingPos = true;
8753
+ }
8754
+ }
8755
+
8756
+ // <Loop F> Set trailing position if necessary
8757
+ if (needsMainTrailingPos || needsCrossTrailingPos) {
8758
+ for (i = 0; i < childCount; ++i) {
8759
+ child = node.children[i];
8760
+
8761
+ if (needsMainTrailingPos) {
8762
+ setTrailingPosition(node, child, mainAxis);
8763
+ }
8764
+
8765
+ if (needsCrossTrailingPos) {
8766
+ setTrailingPosition(node, child, crossAxis);
8767
+ }
8768
+ }
8769
+ }
8770
+
8771
+ // <Loop G> Calculate dimensions for absolutely positioned elements
8772
+ currentAbsoluteChild = firstAbsoluteChild;
8773
+ while (currentAbsoluteChild !== null) {
8774
+ // Pre-fill dimensions when using absolute position and both offsets for
8775
+ // the axis are defined (either both left and right or top and bottom).
8776
+ for (ii = 0; ii < 2; ii++) {
8777
+ axis = (ii !== 0) ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
8778
+
8779
+ if (!isUndefined(node.layout[dim[axis]]) &&
8780
+ !isDimDefined(currentAbsoluteChild, axis) &&
8781
+ isPosDefined(currentAbsoluteChild, leading[axis]) &&
8782
+ isPosDefined(currentAbsoluteChild, trailing[axis])) {
8783
+ currentAbsoluteChild.layout[dim[axis]] = fmaxf(
8784
+ boundAxis(currentAbsoluteChild, axis, node.layout[dim[axis]] -
8785
+ getBorderAxis(node, axis) -
8786
+ getMarginAxis(currentAbsoluteChild, axis) -
8787
+ getPosition(currentAbsoluteChild, leading[axis]) -
8788
+ getPosition(currentAbsoluteChild, trailing[axis])
8789
+ ),
8790
+ // You never want to go smaller than padding
8791
+ getPaddingAndBorderAxis(currentAbsoluteChild, axis)
8792
+ );
8793
+ }
8794
+
8795
+ if (isPosDefined(currentAbsoluteChild, trailing[axis]) &&
8796
+ !isPosDefined(currentAbsoluteChild, leading[axis])) {
8797
+ currentAbsoluteChild.layout[leading[axis]] =
8798
+ node.layout[dim[axis]] -
8799
+ currentAbsoluteChild.layout[dim[axis]] -
8800
+ getPosition(currentAbsoluteChild, trailing[axis]);
8801
+ }
8802
+ }
8803
+
8804
+ child = currentAbsoluteChild;
8805
+ currentAbsoluteChild = currentAbsoluteChild.nextAbsoluteChild;
8806
+ child.nextAbsoluteChild = null;
8807
+ }
8808
+ }
8809
+
8810
+ function layoutNode(node, parentMaxWidth, parentDirection) {
8811
+ node.shouldUpdate = true;
8812
+
8813
+ var direction = node.style.direction || CSS_DIRECTION_LTR;
8814
+ var skipLayout =
8815
+ !node.isDirty &&
8816
+ node.lastLayout &&
8817
+ node.lastLayout.requestedHeight === node.layout.height &&
8818
+ node.lastLayout.requestedWidth === node.layout.width &&
8819
+ node.lastLayout.parentMaxWidth === parentMaxWidth &&
8820
+ node.lastLayout.direction === direction;
8821
+
8822
+ if (skipLayout) {
8823
+ node.layout.width = node.lastLayout.width;
8824
+ node.layout.height = node.lastLayout.height;
8825
+ node.layout.top = node.lastLayout.top;
8826
+ node.layout.left = node.lastLayout.left;
8827
+ } else {
8828
+ if (!node.lastLayout) {
8829
+ node.lastLayout = {};
8830
+ }
8831
+
8832
+ node.lastLayout.requestedWidth = node.layout.width;
8833
+ node.lastLayout.requestedHeight = node.layout.height;
8834
+ node.lastLayout.parentMaxWidth = parentMaxWidth;
8835
+ node.lastLayout.direction = direction;
8836
+
8837
+ // Reset child layouts
8838
+ node.children.forEach(function(child) {
8839
+ child.layout.width = undefined;
8840
+ child.layout.height = undefined;
8841
+ child.layout.top = 0;
8842
+ child.layout.left = 0;
8843
+ });
8844
+
8845
+ layoutNodeImpl(node, parentMaxWidth, parentDirection);
8846
+
8847
+ node.lastLayout.width = node.layout.width;
8848
+ node.lastLayout.height = node.layout.height;
8849
+ node.lastLayout.top = node.layout.top;
8850
+ node.lastLayout.left = node.layout.left;
8851
+ }
8852
+ }
8853
+
8854
+ return {
8855
+ layoutNodeImpl: layoutNodeImpl,
8856
+ computeLayout: layoutNode,
8857
+ fillNodes: fillNodes
8858
+ };
8859
+ })();
8860
+
8861
+ // This module export is only used for the purposes of unit testing this file. When
8862
+ // the library is packaged this file is included within css-layout.js which forms
8863
+ // the public API.
8864
+ {
8865
+ module.exports = computeLayout;
8866
+ }
8867
+
8868
+
8869
+ return function(node) {
8870
+ /*eslint-disable */
8871
+ // disabling ESLint because this code relies on the above include
8872
+ computeLayout.fillNodes(node);
8873
+ computeLayout.computeLayout(node);
8874
+ /*eslint-enable */
8875
+ };
8876
+ }));
8877
+ } (cssLayout));
8878
+
8879
+ var cssLayoutExports = cssLayout.exports;
8880
+
8881
+ function _interopDefault$1(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var React=_interopDefault$1(React$1),reactDom=require$$0,computeLayout=_interopDefault$1(cssLayoutExports);function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){_defineProperty(e,t,r[t]);});}return e}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n);}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),e}function _typeof2(e){return (_typeof2="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _typeof(e){return (_typeof="function"==typeof Symbol&&"symbol"===_typeof2(Symbol.iterator)?function(e){return _typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":_typeof2(e)})(e)}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){return !t||"object"!==_typeof(t)&&"function"!=typeof t?_assertThisInitialized(e):t}function _getPrototypeOf(e){return (_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf(e,t){return (_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t);}var Flexbox=function(e){function t(){var e;return _classCallCheck(this,t),(e=_possibleConstructorReturn(this,_getPrototypeOf(t).call(this))).childRefs=[],e.shouldUpdateAgain=!1,e.state={layout:{children:[]}},e}return _inherits(t,React.Component),_createClass(t,[{key:"componentDidMount",value:function(){this.forceUpdate();}},{key:"componentDidUpdate",value:function(){if(this.shouldUpdateAgain=!this.shouldUpdateAgain,this.shouldUpdateAgain){var e=this.props,t=e.children,r=e.onLayout,n=e.style,o=this.getChildrenMeasured(this.childRefs),i=this.getFlattenedChildren(t),u=this.getChildrenAsMergedStyles(i,o),c=this.getComputedLayout(u,n);r(c),this.setState({layout:c});}}},{key:"getFlattenedChildren",value:function(e){return e.filter(function(e){return e}).filter(function(e){return "string"!=typeof e}).map(function(e){return Array.isArray(e)?e:[e]}).reduce(function(e,t){return e.concat(t)},[])}},{key:"getChildrenAsMergedStyles",value:function(e,t){return t.map(function(t,r){var n=e[r]||{},o=n&&n.props?n.props.style:{};return {style:_objectSpread({},o,{height:t.height||o.height,width:t.width||o.width})}})}},{key:"getChildrenMeasured",value:function(e){return e&&e.length?e.map(function(e){return e.getBBox?e.getBBox():reactDom.findDOMNode(e).getBBox()}):[]}},{key:"getComputedLayout",value:function(e,t){var r={children:Array.from(e||[]),style:_objectSpread({},t)};return computeLayout(r),r}},{key:"getLayoutChildren",value:function(e){return e&&e.children&&e.children.length?e.children:[]}},{key:"getLayoutAttributesForChild",value:function(e,t){if(t&&t.layout){var r=t.layout,n=r.left,o=r.top;switch(e.type){case"circle":var i=e.props.r||0;return {cx:n+i,cy:o+i};case"ellipse":return {cx:n+(e.props.rx||0),cy:o+(e.props.ry||0)};case"g":case"path":case"polygon":case"polyline":return {transform:"translate(".concat(n," ").concat(o,")")};default:return {x:n,y:o}}}return {}}},{key:"render",value:function(){var e=this,t=this.props,r=t.children,n=t.className,o=t.x,i=t.y,u=this.state.layout;this.childRefs=[];var c=this.getFlattenedChildren(r),a=this.getLayoutChildren(u);return React.createElement("g",{className:n,transform:"translate(".concat(o," ").concat(i,")")},c.map(function(t,r){return React.cloneElement(t,_objectSpread({},t.props,e.getLayoutAttributesForChild(t,a[r]),{key:"child-".concat(r),ref:function(t){return t?e.childRefs.push(t):null}}))}))}}]),t}();Flexbox.defaultProps={children:[],className:null,onLayout:function(){},style:{},x:0,y:0},bundle.exports=Flexbox;
8882
+
8883
+ var bundleExports = bundle.exports;
8884
+ var Flexbox$1 = /*@__PURE__*/getDefaultExportFromCjs(bundleExports);
8885
+
7654
8886
  var Element = function (props) {
7655
- var _a, _b, _c;
8887
+ var _a, _b;
7656
8888
  var id = props.id, x = props.x, y = props.y, width = props.width, height = props.height, portPlaceholderShape = props.portPlaceholderShape, children = props.children, container = props.container, textsPlaceHolderFlexStyle = props.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition = props.textsPlaceHolderFlexboxPosition, textsPlaceHolderClassName = props.textsPlaceHolderClassName, texts = props.texts, portSlideRailSVGClassName = props.portSlideRailSVGClassName, portMoveableAreas = props.portMoveableAreas, portDirection = props.portDirection, onClick = props.onClick, renderShape = props.renderShape; props.onMoved; var onPortMoved = props.onPortMoved; props.onResized; var onPortMouseDown = props.onPortMouseDown, onPortMouseUp = props.onPortMouseUp; props.onMouseMove; props.onMouseLeave; props.onMouseUp; var onMouseUpAtLinkedPortPlaceholder = props.onMouseUpAtLinkedPortPlaceholder, onTextUpdated = props.onTextUpdated;
7657
- var _d = React.useState(), selectedPort = _d[0], setSelectedPort = _d[1];
7658
- var _e = React.useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
7659
- return __assign(__assign({}, p), { id: p.id, ref: React.createRef() });
7660
- })) !== null && _b !== void 0 ? _b : []), ports = _e[0], setPorts = _e[1];
7661
- var _f = React.useState(false), someElementLinkStarted = _f[0], setSomeElementLinkStarted = _f[1];
7662
- var _g = React.useState(), potentialPortPosition = _g[0], setPotentialPortPosition = _g[1];
7663
- var _paperEventEmitterContext = React.useContext(paperEventEmitterContext);
7664
- var elementRef = React.useRef(null);
7665
- var elementLinkStarted = React.useRef();
8889
+ var _c = React$1.useState(), selectedPort = _c[0], setSelectedPort = _c[1];
8890
+ var _d = React$1.useState((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
8891
+ return __assign(__assign({}, p), { id: p.id, ref: React$1.createRef() });
8892
+ })) !== null && _b !== void 0 ? _b : []), ports = _d[0], setPorts = _d[1];
8893
+ var _e = React$1.useState(false), someElementLinkStarted = _e[0], setSomeElementLinkStarted = _e[1];
8894
+ var _f = React$1.useState(), potentialPortPosition = _f[0], setPotentialPortPosition = _f[1];
8895
+ var _paperEventEmitterContext = React$1.useContext(paperEventEmitterContext);
8896
+ var elementRef = React$1.useRef(null);
8897
+ var elementLinkStarted = React$1.useRef();
7666
8898
  //Listen a new port is created, after add new port to ports state
7667
- React.useEffect(function () {
8899
+ React$1.useEffect(function () {
7668
8900
  var _a, _b;
7669
8901
  setPorts((_b = (_a = props.ports) === null || _a === void 0 ? void 0 : _a.map(function (p) {
7670
- return __assign(__assign({}, p), { id: p.id, ref: React.createRef() });
8902
+ return __assign(__assign({}, p), { id: p.id, ref: React$1.createRef() });
7671
8903
  })) !== null && _b !== void 0 ? _b : []);
7672
8904
  }, [props.ports]);
7673
8905
  //Listen trigger of Delete key, handle delete port is selected
7674
- React.useEffect(function () {
8906
+ React$1.useEffect(function () {
7675
8907
  var listener = _paperEventEmitterContext.onCommandDeleteSelectedPort(function () {
7676
8908
  if (selectedPort) {
7677
8909
  setPorts(function (prev) { return prev.filter(function (p) { return p.id !== selectedPort.id; }); });
@@ -7682,7 +8914,7 @@ var Element = function (props) {
7682
8914
  listener.off();
7683
8915
  };
7684
8916
  }, [selectedPort]);
7685
- React.useEffect(function () {
8917
+ React$1.useEffect(function () {
7686
8918
  //Listener onMouseDown event on #paper-container
7687
8919
  var eventListener = _paperEventEmitterContext.onPaperClicked(function (ev) {
7688
8920
  setSelectedPort(undefined);
@@ -7705,7 +8937,7 @@ var Element = function (props) {
7705
8937
  };
7706
8938
  }, [ports, onPortMoved]);
7707
8939
  //Listen creating element link started, ended.
7708
- React.useEffect(function () {
8940
+ React$1.useEffect(function () {
7709
8941
  var elementStartedListener = _paperEventEmitterContext.onElementLinkStarted(function (tempLink) {
7710
8942
  elementLinkStarted.current = tempLink;
7711
8943
  setSomeElementLinkStarted(true);
@@ -7781,7 +9013,7 @@ var Element = function (props) {
7781
9013
  }
7782
9014
  return coordinates;
7783
9015
  };
7784
- var getSlideRailSVG = React.useCallback(function (portSlideRailSVGClassName) {
9016
+ var getSlideRailSVG = React$1.useCallback(function (portSlideRailSVGClassName) {
7785
9017
  var _a;
7786
9018
  var slideRailSVG = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(portSlideRailSVGClassName));
7787
9019
  return slideRailSVG;
@@ -7948,7 +9180,7 @@ var Element = function (props) {
7948
9180
  }
7949
9181
  };
7950
9182
  //Get rotate angle of port by port direction is defined.
7951
- var rotatePort = React.useCallback(function (x, y) {
9183
+ var rotatePort = React$1.useCallback(function (x, y) {
7952
9184
  console.info('calculating port rotation', x, y);
7953
9185
  if (!portSlideRailSVGClassName)
7954
9186
  return 0;
@@ -7988,7 +9220,7 @@ var Element = function (props) {
7988
9220
  }
7989
9221
  return rotationAngle;
7990
9222
  }, [portSlideRailSVGClassName, portDirection, getSlideRailSVG]);
7991
- var renderedShape = React.useMemo(function () {
9223
+ var renderedShape = React$1.useMemo(function () {
7992
9224
  if (renderShape)
7993
9225
  return renderShape(props);
7994
9226
  return null;
@@ -7996,7 +9228,7 @@ var Element = function (props) {
7996
9228
  //Re-render port again after rendered to automation rotate port
7997
9229
  //Because elementRef.current equals null in first render so automation rotate port is incorrect.
7998
9230
  //TODO: check if this is still needed -> Still needed
7999
- React.useLayoutEffect(function () {
9231
+ React$1.useLayoutEffect(function () {
8000
9232
  if (elementRef.current) {
8001
9233
  setPorts(function (prev) { return __spreadArray([], prev, true); });
8002
9234
  }
@@ -8004,7 +9236,7 @@ var Element = function (props) {
8004
9236
  //use selection frame
8005
9237
  useSelectionFrame({
8006
9238
  container: container,
8007
- targetSVGElement: ((_c = selectedPort === null || selectedPort === void 0 ? void 0 : selectedPort.ref) === null || _c === void 0 ? void 0 : _c.current) || undefined,
9239
+ targetSVGElement: (selectedPort === null || selectedPort === void 0 ? void 0 : selectedPort.ref.current) || undefined,
8008
9240
  resizability: {
8009
9241
  enabled: false,
8010
9242
  keepRatio: false
@@ -8014,19 +9246,19 @@ var Element = function (props) {
8014
9246
  movingOffsetThreshold: PORT_MOVING_OFFSET_THRESHOLD,
8015
9247
  onMove: handlePortMove
8016
9248
  });
8017
- return (React.createElement(ElementWrapper, { ref: elementRef, x: x, y: y, onClick: function (e) { return onClick ? onClick(id, e, elementRef.current) : true; }, onMouseMove: handleElementMouseMove, onMouseLeave: handleElementMouseLeave, onMouseUp: handleElementMouseUp },
9249
+ return (React$1.createElement(ElementWrapper, { ref: elementRef, x: x, y: y, onClick: function (e) { return onClick ? onClick(id, e, elementRef.current) : true; }, onMouseMove: handleElementMouseMove, onMouseLeave: handleElementMouseLeave, onMouseUp: handleElementMouseUp },
8018
9250
  renderedShape,
8019
9251
  potentialPortPosition && (portPlaceholderShape
8020
- ? React.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
8021
- : React.createElement("rect", { x: potentialPortPosition.x - PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH / 2, y: potentialPortPosition.y - PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH / 2, width: PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH, height: PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH, rx: PORT_PLACEHOLDER_DEFAULT_SIZE, ry: PORT_PLACEHOLDER_DEFAULT_SIZE, stroke: PORT_PLACEHOLDER_DEFAULT_STROKE, fill: "none", strokeWidth: 3 })), ports === null || ports === void 0 ? void 0 :
9252
+ ? React$1.createElement("svg", { x: potentialPortPosition.x, y: potentialPortPosition.y }, portPlaceholderShape)
9253
+ : React$1.createElement("rect", { x: potentialPortPosition.x - PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH / 2, y: potentialPortPosition.y - PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH / 2, width: PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH, height: PORT_PLACEHOLDER_DEFAULT_STROKE_WIDTH, rx: PORT_PLACEHOLDER_DEFAULT_SIZE, ry: PORT_PLACEHOLDER_DEFAULT_SIZE, stroke: PORT_PLACEHOLDER_DEFAULT_STROKE, fill: "none", strokeWidth: 3 })), ports === null || ports === void 0 ? void 0 :
8022
9254
  ports.map(function (p, index) {
8023
- return React.createElement(Port, { key: p.id, ref: p.ref, id: p.id, x: p.position.x, y: p.position.y, width: p.size.width, height: p.size.height, container: container,
9255
+ return React$1.createElement(Port, { key: p.id, ref: p.ref, id: p.id, x: p.position.x, y: p.position.y, width: p.size.width, height: p.size.height, container: container,
8024
9256
  // rotation={rotatePort(p)}
8025
9257
  calculateRotationAngle: rotatePort, label: p.label, onPortLabelMoved: function (x, y) { return handlePortLabelMoved(x, y, p, index); }, onPortLabelResized: function (w, h) { return handlePortLabelResized(w, h, p, index); }, onPortLabelContentChanged: function (ev, newValue) { return handlePortLabelContentChanged(newValue, p, index); }, onSelected: function (portId, event) { return handleSelectedPort(p, event); }, onMouseDown: handlePortMouseDown, onMouseUp: handlePortMouseUp, renderShape: p.renderShape });
8026
9258
  }),
8027
- React.createElement(Flexbox, { className: textsPlaceHolderClassName, style: textsPlaceHolderFlexStyle, x: textsPlaceHolderFlexboxPosition === null || textsPlaceHolderFlexboxPosition === void 0 ? void 0 : textsPlaceHolderFlexboxPosition.x, y: textsPlaceHolderFlexboxPosition === null || textsPlaceHolderFlexboxPosition === void 0 ? void 0 : textsPlaceHolderFlexboxPosition.y }, texts === null || texts === void 0 ? void 0 : texts.map(function (t, index) {
9259
+ React$1.createElement(Flexbox$1, { className: textsPlaceHolderClassName, style: textsPlaceHolderFlexStyle, x: textsPlaceHolderFlexboxPosition === null || textsPlaceHolderFlexboxPosition === void 0 ? void 0 : textsPlaceHolderFlexboxPosition.x, y: textsPlaceHolderFlexboxPosition === null || textsPlaceHolderFlexboxPosition === void 0 ? void 0 : textsPlaceHolderFlexboxPosition.y }, texts === null || texts === void 0 ? void 0 : texts.map(function (t, index) {
8028
9260
  var _a, _b;
8029
- return React.createElement(Text$1, { id: t.id, key: index, content: t.content, x: (_a = t.position) === null || _a === void 0 ? void 0 : _a.x, y: (_b = t.position) === null || _b === void 0 ? void 0 : _b.y, width: t.size.width, height: t.size.height, align: t.align, fontSize: t.fontSize, border: t.border, container: container, style: t.style, onContentChanged: function (ev, newContent) { return onTextUpdated === null || onTextUpdated === void 0 ? void 0 : onTextUpdated(t.id, newContent); } });
9261
+ return React$1.createElement(Text$1, { id: t.id, key: index, content: t.content, x: (_a = t.position) === null || _a === void 0 ? void 0 : _a.x, y: (_b = t.position) === null || _b === void 0 ? void 0 : _b.y, width: t.size.width, height: t.size.height, align: t.align, fontSize: t.fontSize, border: t.border, container: container, style: t.style, onContentChanged: function (ev, newContent) { return onTextUpdated === null || onTextUpdated === void 0 ? void 0 : onTextUpdated(t.id, newContent); } });
8030
9262
  })),
8031
9263
  children));
8032
9264
  };
@@ -8047,9 +9279,9 @@ var createRect = function (x, y, width, height, strokeWidth, transformOrigin, tr
8047
9279
  };
8048
9280
  function BBoxDebugger(_a) {
8049
9281
  var elementSVG = _a.elementSVG;
8050
- var _b = React.useState(false), isTurnOn = _b[0], setIsTurnOn = _b[1];
8051
- var displayedBBoxDebug = React.useRef([]);
8052
- React.useEffect(function () {
9282
+ var _b = React$1.useState(false), isTurnOn = _b[0], setIsTurnOn = _b[1];
9283
+ var displayedBBoxDebug = React$1.useRef([]);
9284
+ React$1.useEffect(function () {
8053
9285
  var keyPress = function (ev) {
8054
9286
  if (ev.ctrlKey && ev.key === 'b') {
8055
9287
  setIsTurnOn(function (prev) { return !prev; });
@@ -8129,7 +9361,7 @@ function BBoxDebugger(_a) {
8129
9361
  }, 1000);
8130
9362
  return intervalId;
8131
9363
  };
8132
- React.useEffect(function () {
9364
+ React$1.useEffect(function () {
8133
9365
  if (!isTurnOn || !elementSVG)
8134
9366
  return;
8135
9367
  var listChildrenGroupByLevel = getListChildrenAndGroupSameLevel(elementSVG);
@@ -8141,12 +9373,12 @@ function BBoxDebugger(_a) {
8141
9373
  clearBBoxDebugger(displayedBBoxDebug.current);
8142
9374
  };
8143
9375
  }, [isTurnOn, elementSVG]);
8144
- return (React.createElement("div", { style: {
9376
+ return (React$1.createElement("div", { style: {
8145
9377
  position: 'fixed',
8146
9378
  top: 20,
8147
9379
  right: 20
8148
9380
  } },
8149
- React.createElement("div", { style: {
9381
+ React$1.createElement("div", { style: {
8150
9382
  backgroundColor: 'white',
8151
9383
  boxShadow: '0px 1px 4px 1px',
8152
9384
  borderRadius: 4,
@@ -8170,9 +9402,9 @@ var createDebuggerPoint = function (cx, cy) {
8170
9402
  };
8171
9403
  var LinkDebugger = function (_a) {
8172
9404
  var links = _a.links, svgContainer = _a.svgContainer;
8173
- var _b = React.useState(false), isTurnOn = _b[0], setIsTurnOn = _b[1];
8174
- var displayedDebuggerPoint = React.useRef([]);
8175
- React.useEffect(function () {
9405
+ var _b = React$1.useState(false), isTurnOn = _b[0], setIsTurnOn = _b[1];
9406
+ var displayedDebuggerPoint = React$1.useRef([]);
9407
+ React$1.useEffect(function () {
8176
9408
  var keyPress = function (ev) {
8177
9409
  if (ev.ctrlKey && ev.key === 'l') {
8178
9410
  setIsTurnOn(function (prev) { return !prev; });
@@ -8189,7 +9421,7 @@ var LinkDebugger = function (_a) {
8189
9421
  ele === null || ele === void 0 ? void 0 : ele.remove();
8190
9422
  }
8191
9423
  };
8192
- React.useEffect(function () {
9424
+ React$1.useEffect(function () {
8193
9425
  if (isTurnOn) {
8194
9426
  links.forEach(function (link) {
8195
9427
  var _a;
@@ -8204,13 +9436,13 @@ var LinkDebugger = function (_a) {
8204
9436
  clearDebuggerPoint();
8205
9437
  };
8206
9438
  }, [isTurnOn, links]);
8207
- return (React.createElement("div", null));
9439
+ return (React$1.createElement("div", null));
8208
9440
  };
8209
9441
 
8210
9442
  function useKeyboardCommands(_a) {
8211
9443
  var element = _a.element;
8212
- var _b = React.useContext(paperEventEmitterContext), emitCommandDeleteSelectedElement = _b.emitCommandDeleteSelectedElement, emitCommandDeleteSelectedLink = _b.emitCommandDeleteSelectedLink, emitCommandDeleteSelectedPort = _b.emitCommandDeleteSelectedPort, emitCommandDeleteSelectedText = _b.emitCommandDeleteSelectedText;
8213
- React.useEffect(function () {
9444
+ var _b = React$1.useContext(paperEventEmitterContext), emitCommandDeleteSelectedElement = _b.emitCommandDeleteSelectedElement, emitCommandDeleteSelectedLink = _b.emitCommandDeleteSelectedLink, emitCommandDeleteSelectedPort = _b.emitCommandDeleteSelectedPort, emitCommandDeleteSelectedText = _b.emitCommandDeleteSelectedText;
9445
+ React$1.useEffect(function () {
8214
9446
  var callback = function (ev) {
8215
9447
  var keyboardEv = ev;
8216
9448
  if (keyboardEv.key === "Delete") {
@@ -8260,18 +9492,18 @@ function convertElementsToTree(elements) {
8260
9492
  }
8261
9493
  var Paper = function (props) {
8262
9494
  var _a;
8263
- var _b = React.useState(props.elements), elements = _b[0], setElements = _b[1];
8264
- var _c = React.useState([]), elementsInTree = _c[0], setElementsInTree = _c[1];
8265
- var _d = React.useState(), selectedElement = _d[0], setSelectedElement = _d[1];
8266
- var _e = React.useState((_a = props.links) !== null && _a !== void 0 ? _a : []), links = _e[0], setLinks = _e[1];
8267
- var _f = React.useState(), selectedLink = _f[0], setSelectedLink = _f[1];
8268
- var _g = React.useState(), tempLink = _g[0], setTempLink = _g[1];
8269
- var _h = React.useState(props.texts), texts = _h[0], setTexts = _h[1];
8270
- var _j = React.useState(), selectedText = _j[0], setSelectedText = _j[1];
8271
- var _k = React.useState(null), selectedElementSVG = _k[0], setSelectedElementSVG = _k[1];
8272
- var _l = React.useState(false), mouseDownedOnPaper = _l[0], setMouseDownedOnPaper = _l[1];
8273
- var paperEventEmitter = React.useContext(paperEventEmitterContext);
8274
- var paperContainerRef = React.useRef(null);
9495
+ var _b = React$1.useState(props.elements), elements = _b[0], setElements = _b[1];
9496
+ var _c = React$1.useState([]), elementsInTree = _c[0], setElementsInTree = _c[1];
9497
+ var _d = React$1.useState(), selectedElement = _d[0], setSelectedElement = _d[1];
9498
+ var _e = React$1.useState((_a = props.links) !== null && _a !== void 0 ? _a : []), links = _e[0], setLinks = _e[1];
9499
+ var _f = React$1.useState(), selectedLink = _f[0], setSelectedLink = _f[1];
9500
+ var _g = React$1.useState(), tempLink = _g[0], setTempLink = _g[1];
9501
+ var _h = React$1.useState(props.texts), texts = _h[0], setTexts = _h[1];
9502
+ var _j = React$1.useState(), selectedText = _j[0], setSelectedText = _j[1];
9503
+ var _k = React$1.useState(null), selectedElementSVG = _k[0], setSelectedElementSVG = _k[1];
9504
+ var _l = React$1.useState(false), mouseDownedOnPaper = _l[0], setMouseDownedOnPaper = _l[1];
9505
+ var paperEventEmitter = React$1.useContext(paperEventEmitterContext);
9506
+ var paperContainerRef = React$1.useRef(null);
8275
9507
  useKeyboardCommands({
8276
9508
  element: paperContainerRef.current
8277
9509
  });
@@ -8279,7 +9511,7 @@ var Paper = function (props) {
8279
9511
  var parsedElementsInTree = convertElementsToTree(elements);
8280
9512
  setElementsInTree(parsedElementsInTree);
8281
9513
  };
8282
- React.useEffect(function () {
9514
+ React$1.useEffect(function () {
8283
9515
  //Listen parent of elements changed, then update elements tree
8284
9516
  var parentChangedCancelers = elements.map(function (element) {
8285
9517
  var _a;
@@ -8306,7 +9538,7 @@ var Paper = function (props) {
8306
9538
  };
8307
9539
  }, elements);
8308
9540
  //Update elements tree when length of elements change
8309
- React.useEffect(function () {
9541
+ React$1.useEffect(function () {
8310
9542
  updateElementsTree();
8311
9543
  }, [elements.length]);
8312
9544
  //Get all child elements of the deleted element
@@ -8320,7 +9552,7 @@ var Paper = function (props) {
8320
9552
  return __spreadArray(__spreadArray([], childElms, true), childOfChildElements, true);
8321
9553
  };
8322
9554
  //Listen command delete selected for element
8323
- React.useEffect(function () {
9555
+ React$1.useEffect(function () {
8324
9556
  var listener = paperEventEmitter.onCommandDeleteSelectedElement(function () {
8325
9557
  if (selectedElement) {
8326
9558
  var deletedChildElements = getDeletedChildElements(selectedElement);
@@ -8335,7 +9567,7 @@ var Paper = function (props) {
8335
9567
  };
8336
9568
  }, [selectedElement]);
8337
9569
  //Listen command delete selected for link
8338
- React.useEffect(function () {
9570
+ React$1.useEffect(function () {
8339
9571
  var listener = paperEventEmitter.onCommandDeleteSelectedLink(function () {
8340
9572
  if (selectedLink) {
8341
9573
  setLinks(function (prev) { return prev.filter(function (l) { return l.id !== selectedLink.id; }); });
@@ -8347,7 +9579,7 @@ var Paper = function (props) {
8347
9579
  };
8348
9580
  }, [selectedLink]);
8349
9581
  //Listen command delete selected for Text
8350
- React.useEffect(function () {
9582
+ React$1.useEffect(function () {
8351
9583
  var listener = paperEventEmitter.onCommandDeleteSelectedText(function () {
8352
9584
  if (selectedText) {
8353
9585
  setTexts(function (prev) { return prev.filter(function (t) { return t.id !== selectedText.id; }); });
@@ -8433,7 +9665,7 @@ var Paper = function (props) {
8433
9665
  }
8434
9666
  setMouseDownedOnPaper(false);
8435
9667
  };
8436
- var handlePathChange = React.useCallback(function (path, id) {
9668
+ var handlePathChange = React$1.useCallback(function (path, id) {
8437
9669
  //Update path of element link, that changed
8438
9670
  setLinks(function (prevLinks) {
8439
9671
  var updatedLinkIndex = prevLinks.findIndex(function (l) { return l.id === id; });
@@ -8520,7 +9752,7 @@ var Paper = function (props) {
8520
9752
  setTempLink(undefined);
8521
9753
  }
8522
9754
  };
8523
- var handleLinkLabelMoved = React.useCallback(function (offsetX, offsetY, index, labelType) {
9755
+ var handleLinkLabelMoved = React$1.useCallback(function (offsetX, offsetY, index, labelType) {
8524
9756
  setLinks(function (prevLinks) {
8525
9757
  var newLinks = __spreadArray([], prevLinks, true);
8526
9758
  var currentLink = newLinks[index];
@@ -8556,7 +9788,7 @@ var Paper = function (props) {
8556
9788
  return newLinks;
8557
9789
  });
8558
9790
  }, []);
8559
- var handleLinkLabelResized = React.useCallback(function (width, height, index, labelType) {
9791
+ var handleLinkLabelResized = React$1.useCallback(function (width, height, index, labelType) {
8560
9792
  setLinks(function (prevLinks) {
8561
9793
  var newLinks = __spreadArray([], prevLinks, true);
8562
9794
  var currentLink = newLinks[index];
@@ -8589,7 +9821,7 @@ var Paper = function (props) {
8589
9821
  return newLinks;
8590
9822
  });
8591
9823
  }, []);
8592
- var handleLinkLabelContentChanged = React.useCallback(function (newValue, index, labelType) {
9824
+ var handleLinkLabelContentChanged = React$1.useCallback(function (newValue, index, labelType) {
8593
9825
  setLinks(function (prevLinks) {
8594
9826
  var newLinks = __spreadArray([], prevLinks, true);
8595
9827
  var currentLink = newLinks[index];
@@ -8673,7 +9905,7 @@ var Paper = function (props) {
8673
9905
  Cache to avoid re-initializing the function when the component re-renders to
8674
9906
  avoid causing the components using it to re-render unnecessarily
8675
9907
  */
8676
- var onLabelMoved = React.useCallback(function (index) {
9908
+ var onLabelMoved = React$1.useCallback(function (index) {
8677
9909
  return function (offsetX, offsetY, labelType) {
8678
9910
  handleLinkLabelMoved(offsetX, offsetY, index, labelType);
8679
9911
  };
@@ -8682,7 +9914,7 @@ var Paper = function (props) {
8682
9914
  Cache to avoid re-initializing the function when the component re-renders to
8683
9915
  avoid causing the components using it to re-render unnecessarily
8684
9916
  */
8685
- var onLabelResized = React.useCallback(function (index) {
9917
+ var onLabelResized = React$1.useCallback(function (index) {
8686
9918
  return function (width, height, labelType) {
8687
9919
  handleLinkLabelResized(width, height, index, labelType);
8688
9920
  };
@@ -8691,12 +9923,12 @@ var Paper = function (props) {
8691
9923
  Cache to avoid re-initializing the function when the component re-renders to
8692
9924
  avoid causing the components using it to re-render unnecessarily
8693
9925
  */
8694
- var onLabelContentChanged = React.useCallback(function (index) {
9926
+ var onLabelContentChanged = React$1.useCallback(function (index) {
8695
9927
  return function (newValue, labelType) {
8696
9928
  handleLinkLabelContentChanged(newValue, index, labelType);
8697
9929
  };
8698
9930
  }, [handleLinkLabelContentChanged]);
8699
- var handleClickLinkDelete = React.useCallback(function (link, index) {
9931
+ var handleClickLinkDelete = React$1.useCallback(function (link, index) {
8700
9932
  return function () {
8701
9933
  setLinks(function (prevLinks) {
8702
9934
  var newLinks = __spreadArray([], prevLinks, true);
@@ -8747,7 +9979,7 @@ var Paper = function (props) {
8747
9979
  var _a, _b;
8748
9980
  //use the defined react element or the default Element component
8749
9981
  var ReactElement = element.reactElement || Element;
8750
- return (React.createElement("g", { key: element.id }, React.createElement(ReactElement, { key: "element-".concat(element.id), id: element.id, height: element.size.height, width: element.size.width, x: (_a = element.relativePosition) === null || _a === void 0 ? void 0 : _a.x, y: (_b = element.relativePosition) === null || _b === void 0 ? void 0 : _b.y, onClick: function (id, e, ref) {
9982
+ return (React$1.createElement("g", { key: element.id }, React$1.createElement(ReactElement, { key: "element-".concat(element.id), id: element.id, height: element.size.height, width: element.size.width, x: (_a = element.relativePosition) === null || _a === void 0 ? void 0 : _a.x, y: (_b = element.relativePosition) === null || _b === void 0 ? void 0 : _b.y, onClick: function (id, e, ref) {
8751
9983
  e.stopPropagation();
8752
9984
  setSelectedElementSVG(ref);
8753
9985
  setSelectedElement(element);
@@ -8756,15 +9988,15 @@ var Paper = function (props) {
8756
9988
  // portPlaceholderShape={(<Circle x={0} y={0} width={10} height={10} fill='red' positioningAnchor={PositioningAnchor.Center} />)}
8757
9989
  onMouseUpAtLinkedPortPlaceholder: function (elementLink, position) { return handleMouseUpAtLinkedPortPlaceholder(elementLink, position, element); }, onTextUpdated: function (textId, newContent) { return handleElementTextChange(element, textId, newContent); }, textsPlaceHolderClassName: element.textsPlaceHolderClassName, textsPlaceHolderFlexStyle: element.textsPlaceHolderFlexStyle, textsPlaceHolderFlexboxPosition: element.textsPlaceHolderFlexboxPosition }, element.childrenElements && element.childrenElements.map(renderElementInTree))));
8758
9990
  };
8759
- return (React.createElement("div", { style: { position: "relative" } },
8760
- React.createElement(Ruler, { squareSize: 100, border: '1px dashed grey' }),
8761
- React.createElement("svg", { tabIndex: 0, width: size.width, height: size.height, ref: paperContainerRef, id: "paper-container", onMouseMove: handlePaperMouseMove, onMouseDown: handleMouseDownOnPaper, onMouseUp: handleMouseUpOnPaper },
9991
+ return (React$1.createElement("div", { style: { position: "relative" } },
9992
+ React$1.createElement(Ruler, { squareSize: 100, border: '1px dashed grey' }),
9993
+ React$1.createElement("svg", { tabIndex: 0, width: size.width, height: size.height, ref: paperContainerRef, id: "paper-container", onMouseMove: handlePaperMouseMove, onMouseDown: handleMouseDownOnPaper, onMouseUp: handleMouseUpOnPaper },
8762
9994
  paperContainerRef.current ? elementsInTree.map(function (element, index) {
8763
9995
  return renderElementInTree(element);
8764
9996
  }) : "",
8765
9997
  links && links.map(function (link, index) {
8766
9998
  var _a, _b, _c, _d;
8767
- return (React.createElement(ElementLink, { key: link.id, id: link.id, path: link.path, sourcePosition: {
9999
+ return (React$1.createElement(ElementLink, { key: link.id, id: link.id, path: link.path, sourcePosition: {
8768
10000
  x: link.sourceElement.position.x + link.sourcePort.position.x,
8769
10001
  y: link.sourceElement.position.y + link.sourcePort.position.y
8770
10002
  }, targetPosition: {
@@ -8772,26 +10004,27 @@ var Paper = function (props) {
8772
10004
  y: ((_c = link.targetElement) === null || _c === void 0 ? void 0 : _c.position.y) + ((_d = link.targetPort) === null || _d === void 0 ? void 0 : _d.position.y)
8773
10005
  }, points: link.points, onPathChanged: handlePathChange, onClickDelete: handleClickLinkDelete(link, index), onSelected: function () { return handleSelectLink(link); }, onDeselected: function () { return handleDeselectLink(); }, container: paperContainerRef.current, markerStart: link.markerStart, markerEnd: link.markerEnd, markerDistanceFromPort: link.markerDistanceFromPort, markerSize: link.markerSize, label: link.label, sourceLabel: link.sourceLabel, targetLabel: link.targetLabel, onLabelMoved: onLabelMoved(index), onLabelResized: onLabelResized(index), onLabelContentChanged: onLabelContentChanged(index) }));
8774
10006
  }),
8775
- (tempLink === null || tempLink === void 0 ? void 0 : tempLink.tempTargetPosition) && React.createElement(ElementLink, { id: tempLink.id, points: tempLink.points, sourcePosition: {
10007
+ (tempLink === null || tempLink === void 0 ? void 0 : tempLink.tempTargetPosition) && React$1.createElement(ElementLink, { id: tempLink.id, points: tempLink.points, sourcePosition: {
8776
10008
  x: tempLink.sourceElement.position.x + tempLink.sourcePort.position.x,
8777
10009
  y: tempLink.sourceElement.position.y + tempLink.sourcePort.position.y
8778
10010
  }, targetPosition: tempLink.tempTargetPosition, container: paperContainerRef.current, markerStart: tempLink.markerStart, markerEnd: tempLink.markerEnd, markerDistanceFromPort: tempLink.markerDistanceFromPort, markerSize: tempLink.markerSize }),
8779
- texts.map(function (text, index) { return (React.createElement(Text$1, { key: text.id, id: text.id, x: text.position.x, y: text.position.y, width: text.size.width, height: text.size.height, fontSize: text.fontSize, border: text.border, container: paperContainerRef.current, content: text.content, align: text.align, onSelected: function () {
10011
+ texts.map(function (text, index) { return (React$1.createElement(Text$1, { key: text.id, id: text.id, x: text.position.x, y: text.position.y, width: text.size.width, height: text.size.height, fontSize: text.fontSize, border: text.border, container: paperContainerRef.current, content: text.content, align: text.align, onSelected: function () {
8780
10012
  setSelectedText(text);
8781
10013
  } })); })),
8782
- React.createElement(BBoxDebugger, { elementSVG: selectedElementSVG }),
8783
- React.createElement(LinkDebugger, { links: links, svgContainer: paperContainerRef.current })));
10014
+ React$1.createElement(BBoxDebugger, { elementSVG: selectedElementSVG }),
10015
+ React$1.createElement(LinkDebugger, { links: links, svgContainer: paperContainerRef.current })));
8784
10016
  };
8785
10017
 
8786
10018
  function Editor(_a) {
8787
10019
  var editorContext = _a.editorContext;
8788
- return (React.createElement(React.Fragment, null,
8789
- React.createElement(Paper, { size: { width: 3000, height: 3000 }, elements: editorContext.elements, links: editorContext.links, texts: editorContext.texts, onPaperClicked: editorContext.onPaperClicked, onPortMoved: editorContext.onPortMoved, onElementMoved: editorContext.onElementMoved, onElementResized: editorContext.onElementResized, onLinkValidation: editorContext.validateLink, onCreatingLink: editorContext.onCreatingLink, onCreatingPortByLinking: editorContext.onCreatingPortByLinking })));
10020
+ return (React$1.createElement(React$1.Fragment, null,
10021
+ React$1.createElement(Paper, { size: { width: 3000, height: 3000 }, elements: editorContext.elements, links: editorContext.links, texts: editorContext.texts, onPaperClicked: editorContext.onPaperClicked, onPortMoved: editorContext.onPortMoved, onElementMoved: editorContext.onElementMoved, onElementResized: editorContext.onElementResized, onLinkValidation: editorContext.validateLink, onCreatingLink: editorContext.onCreatingLink, onCreatingPortByLinking: editorContext.onCreatingPortByLinking })));
8790
10022
  }
8791
10023
 
8792
10024
  exports.CircleRC = Circle;
8793
10025
  exports.CrescentRC = Crescent;
8794
- exports.CustomPort = CustomPort;
10026
+ exports.CustomPortFromJSXElement = CustomPortFromJSXElement;
10027
+ exports.CustomPortFromShape = CustomPortFromShape;
8795
10028
  exports.CustomShapeRC = CustomShape;
8796
10029
  exports.EditorContext = EditorContext;
8797
10030
  exports.Element = Element$1;