VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/libs/absol-full/dist/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-full/dist/js/mdls__absol-form__js__processflowdiagrameditor__PFDEBlocks.js
/*** module: node_modules/absol-form/js/processflowdiagrameditor/PFDEBlocks.js ***/
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.directoryOfVec2 = directoryOfVec2;
exports.directoryOutFromRect = directoryOutFromRect;
exports.curveConnectCost = curveConnectCost;
exports.beautifyCurve = beautifyCurve;
exports.beautifyPFDEline = beautifyPFDEline;
exports.PFDEBStart = PFDEBStart;
exports.PFDEBSuccess = PFDEBSuccess;
exports.PFDEBFail = PFDEBFail;
exports.PFDEBProcess = PFDEBProcess;
exports.PFDEBSubProcedure = PFDEBSubProcedure;
exports.pfdeDirs = void 0;

var _FCore = require("../core/FCore");

var _inheritComponentClass = _interopRequireDefault(require("../core/inheritComponentClass"));

require("../../css/processflowdiagram.css");

var _Rectangle = _interopRequireDefault(require("absol/src/Math/Rectangle"));

var _Vec = _interopRequireDefault(require("absol/src/Math/Vec2"));

var _utils = require("absol-acomp/js/utils");

var _stringGenerate = require("absol/src/String/stringGenerate");

var _Attributes = _interopRequireDefault(require("absol/src/AppPattern/Attributes"));

var _OOP = _interopRequireDefault(require("absol/src/HTML5/OOP"));

var _Polyline = _interopRequireDefault(require("absol/src/Math/Polyline"));

var _SegmentLine = _interopRequireDefault(require("absol/src/Math/SegmentLine"));

var _NumRange = _interopRequireDefault(require("absol/src/Math/NumRange"));


var pfdeDirs = [new _Vec.default(1, 0), new _Vec.default(0, 1), new _Vec.default(-1, 0), new _Vec.default(0, -1), new _Vec.default(1, 1), new _Vec.default(-1, 1), new _Vec.default(-1, -1), new _Vec.default(1, -1)];
/**
 *
 * @param {Vec2} v
 * @returns
 */

exports.pfdeDirs = pfdeDirs;

function directoryOfVec2(v) {
  var res = {
    idx: 0
  };
  var max = -Infinity;

  for (var i = 0; i < pfdeDirs.length; ++i) {
    var t = v.dot(pfdeDirs[i]);

    if (t > max) {
      max = t;
      res.idx = i;
    }
  }

  res.dir = pfdeDirs[res.idx];
  res.angle = res.dir.direction();
  return res;
}
/**
 *
 * @param {Vec2} A
 * @param {Vec2} B
 * @param {Vec2} C
 * @param {Vec2} D
 * @returns {boolean}
 */


function isCross(A, B, C, D) {
  var t1 = C.sub(D).cross(D.sub(A));
  var t2 = C.sub(D).cross(D.sub(B));
  if (t1 * t2 >= 0) return false;
  var t3 = A.sub(B).cross(B.sub(C));
  var t4 = A.sub(B).cross(B.sub(D));
  if (t3 * t4 >= 0) return false;
  return true;
}
/**
 *
 *      dir
 *                3
 *       2                      0
 *                 1
 *
 * @param {Rectangle} rect
 * @param {Vec2} point
 * @returns {{pos: Vec2, dir: Vec2, dirIdx: number, angle: number}}
 */


function directoryOutFromRect(rect, point) {
  var Ps = [rect.B(), rect.C(), rect.D(), rect.A(), rect.B()];
  var O = rect.centerPoint();

  for (var i = 0; i < 4; ++i) {
    if (isCross(Ps[i], Ps[i + 1], O, point)) {
      return {
        pos: Ps[i].add(Ps[i + 1].sub(Ps[i]).mult(0.5)),
        dir: pfdeDirs[i],
        dirIdx: i,
        angle: point.sub(O).direction()
      };
    }
  }

  return {
    pos: Ps[1].add(Ps[2 + 1].sub(Ps[i]).mult(0.5)),
    dir: pfdeDirs[1],
    dirIdx: i,
    angle: 0
  };
}
/**
 * //50 is control vector length
 * @param {Vec2} p1
 * @param {Vec2} ctrl1
 * @param {Vec2} ctrl2
 * @param {Vec2} p2
 */


function curveConnectCost(p1, ctrl1, ctrl2, p2) {
  var points = [p1, ctrl1, ctrl2, p2];
  var sign = 0;
  var v0, v1;
  var isCross = false;

  for (var i = 0; i < points.length && !isCross; ++i) {
    v0 = points[i].sub(points[(i + 1) % points.length]);
    v1 = points[(i + 1) % points.length].sub(points[(i + 2) % points.length]);

    if (sign === 0) {
      sign = v0.cross(v1);
    } else {
      if (sign * v0.cross(v1) < 0) {
        isCross = true;
      }
    }
  }

  var dist = p2.sub(p1).abs();
  var ctrLength = ctrl2.sub(ctrl1).abs();
  var v1Length = ctrl1.sub(p1).abs();
  var v2Length = p2.sub(ctrl2).abs();

  if (isCross) {
    //not an arc
    if (dist < ctrLength) {
      return 1e6; //bad case
    } else if (v1Length * v1Length + v2Length * v2Length > ctrLength * ctrLength) {
      return 1e3; //bad case
    } else {
      return 6;
    }
  } else {
    if (ctrl1.dot(ctrl2) > 0) {
      return 5;
    } else if (Math.abs(ctrl1.dot(ctrl2)) < 0.001) {
      return 2;
    } else return 1;
  }
}
/**
 * @param {Vec2} start
 * @param {Vec2} startDir
 * @param {Vec2} end
 * @param {Vec2} endDir
 * @param {Vec2[]} interPoints
 * @returns {number[]}
 */


function beautifyCurve(start, startDir, end, endDir, interPoints) {
  var Q = {};
  Q['-1'] = [{
    val: Infinity,
    prev: 0
  }, {
    val: Infinity,
    prev: 0
  }, {
    val: Infinity,
    prev: 0
  }, {
    val: Infinity,
    prev: 0
  }];
  Q['-1'][startDir].val = 0;
  var point, i, d1, d2;
  var prevPoint = start;
  var ctrl1, ctrl2;
  var cost;

  for (i = 0; i < interPoints.length; ++i) {
    Q[i] = [{
      val: Infinity,
      prev: 0
    }, {
      val: Infinity,
      prev: 0
    }, {
      val: Infinity,
      prev: 0
    }, {
      val: Infinity,
      prev: 0
    }];
    point = interPoints[i];

    for (d1 = 0; d1 < 4; ++d1) {
      ctrl1 = prevPoint.add(pfdeDirs[d1].mult(50));

      for (d2 = 0; d2 < 4; ++d2) {
        ctrl2 = point.add(pfdeDirs[(d2 + 2) % 4].mult(50));
        cost = curveConnectCost(prevPoint, ctrl1, ctrl2, point);

        if (Q[i][d2].val > Q[i - 1][d1].val + cost) {
          Q[i][d2].val = Q[i - 1][d1].val + cost;
          Q[i][d2].prevDir = d1;
        }
      }
    }

    prevPoint = point;
  }

  point = end;
  Q[interPoints.length] = [{
    val: Infinity,
    prev: 0
  }, {
    val: Infinity,
    prev: 0
  }, {
    val: Infinity,
    prev: 0
  }, {
    val: Infinity,
    prev: 0
  }];
  d2 = (endDir + 2) % 4;

  for (d1 = 0; d1 < 4; ++d1) {
    ctrl1 = prevPoint.add(pfdeDirs[d1].mult(50));
    ctrl2 = point.add(pfdeDirs[(d2 + 2) % 4].mult(50));
    cost = curveConnectCost(prevPoint, ctrl1, ctrl2, point);

    if (Q[interPoints.length][d2].val > Q[interPoints.length - 1][d1].val + cost) {
      Q[interPoints.length][d2].val = Q[interPoints.length - 1][d1].val + cost;
      Q[interPoints.length][d2].prevDir = d1;
    }
  }

  var res = [];
  var dir = d2;

  for (i = interPoints.length; i >= 0; --i) {
    res.unshift(Q[i][dir].prevDir);
    dir = Q[i][dir].prevDir;
  }

  return res; //todo: trace back
}

function invDirIdx(idx) {
  if (idx < 4) {
    idx = (idx + 2) % 4;
  } else {
    idx = (idx - 2) % 4 + 4;
  }

  return idx;
}
/**
 *
 * @param {Rectangle} rect
 * @param {Vec2} point
 */


function dir8IdxFromRect2Point(rect, point, inv) {
  var dir = new _Vec.default(0, 0);
  if (point.x < rect.x) dir.x = -1;else if (point.x > rect.x + rect.width) dir.x = 1;
  if (point.y < rect.y) dir.y = -1;else if (point.y > rect.y + rect.height) dir.y = 1;
  var res = -1;

  for (var i = 0; i < pfdeDirs.length; ++i) {
    if (dir.equals(pfdeDirs[i])) {
      res = i;
      break;
    }
  }

  if (res >= 0 && inv) {
    res = invDirIdx(res);
  }

  return res;
}
/**
 *
 * @param {Rectangle} startRect
 * @param {Vec2[]} interPoints - length > 0
 * @param {Rectangle}endRect
 * @return {Polyline[]}
 */


function beautifyPFDElineWithInterPoints(startRect, interPoints, endRect) {
  var vtRects = [startRect.clone()];
  var i, j;

  for (i = 0; i < interPoints.length; ++i) {
    vtRects.push(new _Rectangle.default(interPoints[i].x - 0.1, interPoints[i].y - 0.1, 0.2, 0.2));
  }

  vtRects.push(endRect.clone());
  var Q = Array(vtRects.length);
  var prevDir, cost;
  Q[0] = Array(4).fill(0).map((u, j) => ({
    cost: 0,
    idx: 0,
    dir: j
  }));
  var dir, dirList, relativeDir;

  for (i = 1; i < vtRects.length; ++i) {
    Q[i] = Array(4).fill(0).map((u, j) => ({
      cost: Infinity,
      idx: i,
      dir: j
    }));

    if (i === vtRects.length - 1) {
      relativeDir = dir8IdxFromRect2Point(vtRects[i], interPoints[i - 2], true);
    } else {
      relativeDir = dir8IdxFromRect2Point(vtRects[i - 1], interPoints[i - 1], false);
    }

    if (relativeDir < 4) {
      dirList = [relativeDir];
    } else {
      dirList = [relativeDir - 4, (relativeDir - 3) % 4];
    }

    for (j = 0; j < dirList.length; ++j) {
      dir = dirList[j];

      for (prevDir = 0; prevDir < 4; ++prevDir) {
        cost = Q[i - 1][prevDir].cost;

        if (relativeDir < 4) {
          if (prevDir !== dir) {
            cost += 1e3;
          }
        } else {
          if (pfdeDirs[prevDir].add(pfdeDirs[dir]).equals(pfdeDirs[relativeDir])) {
            cost += 1;
          } else {
            cost += 1e3;
          }
        }

        if (Q[i][dir].cost > cost) {
          Q[i][dir].cost = cost;
          Q[i][dir].prevDir = prevDir;
          Q[i][dir].prevIdx = i - 1;
        }
      }
    }

    for (prevDir = 0; prevDir < 4; ++prevDir) {
      for (dir = 0; dir < 4; ++dir) {
        if (dir === prevDir) continue;
        if (Q[i][prevDir].prevIdx === i) continue;
        cost = Q[i][prevDir].cost;

        if (invDirIdx(dir) === prevDir) {
          cost += 1e3;
        } else cost += 1; //rotate 90 degree


        if (cost < Q[i][dir].cost) {
          Q[i][dir].cost = cost;
          Q[i][dir].prevDir = prevDir;
          Q[i][dir].prevIdx = i;
        }
      }
    }
  }

  var minCost = Infinity;

  for (i = 0; i < 4; ++i) {
    if (Q[vtRects.length - 1][i].cost < minCost) {
      minCost = Q[vtRects.length - 1][i].cost;
      dir = i;
    }
  }

  i = vtRects.length - 1;
  var res = [];
  var cur = Q[i][dir];
  var plLinePoints;
  var rectPoints, sPoint, hPoint, smt, ePoint;

  while (cur) {
    plLinePoints = null;

    if (cur.idx === vtRects.length - 1) {
      sPoint = interPoints[cur.idx - 2];
      plLinePoints = [sPoint];
      rectPoints = [endRect.D(), endRect.A(), endRect.B(), endRect.C(), endRect.D()];
      smt = new _SegmentLine.default(rectPoints[cur.dir], rectPoints[cur.dir + 1]);

      if (cur.prevDir === cur.dir) {
        ePoint = smt.orthogonalProjectionPoint(sPoint);
        plLinePoints.push(ePoint);
      } else {
        ePoint = smt.midpoint();
        smt = new _SegmentLine.default(sPoint, sPoint.add(pfdeDirs[cur.prevDir]));
        hPoint = smt.orthogonalProjectionPoint(ePoint);
        plLinePoints.push(hPoint);
        plLinePoints.push(ePoint);
      }
    } else if (cur.idx !== cur.prevIdx && cur.idx > 1) {
      sPoint = interPoints[cur.idx - 2];
      ePoint = interPoints[cur.idx - 1];
      plLinePoints = [sPoint];

      if (cur.prevDir !== cur.dir) {
        smt = new _SegmentLine.default(sPoint, sPoint.add(pfdeDirs[cur.prevDir]));
        hPoint = smt.orthogonalProjectionPoint(ePoint);
        plLinePoints.push(hPoint);
      }

      plLinePoints.push(ePoint);
    } else if (cur.idx !== cur.prevIdx && cur.idx === 1) {
      ePoint = interPoints[0];
      plLinePoints = [ePoint];
      rectPoints = [startRect.B(), startRect.C(), startRect.D(), startRect.A(), startRect.B()];
      smt = new _SegmentLine.default(rectPoints[cur.prevDir], rectPoints[cur.prevDir + 1]);

      if (cur.prevDir === cur.dir) {
        sPoint = smt.orthogonalProjectionPoint(ePoint);
        plLinePoints.unshift(sPoint);
      } else {
        sPoint = smt.midpoint();
        smt = new _SegmentLine.default(sPoint, sPoint.add(pfdeDirs[cur.prevDir]));
        hPoint = smt.orthogonalProjectionPoint(ePoint);
        plLinePoints.unshift(hPoint);
        plLinePoints.unshift(sPoint);
      }
    }

    if (plLinePoints) {
      res.unshift(new _Polyline.default(plLinePoints));
    }

    dir = cur.prevDir;
    i = cur.prevIdx;
    cur = Q[i] && Q[i][dir];
  }

  return res;
}

function beautifyPFDElineWithoutInterPoints(startRect, endRect) {
  var sPoint, ePoint, hPoint, dir, smt;
  sPoint = new _Vec.default(0, 0);
  ePoint = new _Vec.default(0, 0);
  dir = new _Vec.default(0, 0);

  if (startRect.x + startRect.width <= endRect.x) {
    dir.x = 1;
  } else if (startRect.x >= endRect.x + endRect.width) {
    dir.x = -1;
  }

  if (startRect.y + startRect.height <= endRect.y) {
    dir.y = 1;
  } else if (startRect.y >= endRect.y + endRect.height) {
    dir.y = -1;
  }

  var startDirIdx;
  var endDirIdx;
  var startDir, endDir;
  var minLength = Infinity;
  var length;
  var bestPolyline = null;
  var nRangeStart, nRangeEnd, nRangeOverlap;
  var rectPoints;

  if (dir.dot(dir) === 0) {
    dir = directoryOfVec2(dir).dir;
  }

  if (dir.dot(dir) === 1) {
    if (dir.x === 0) {
      nRangeStart = new _NumRange.default(startRect.x, startRect.width);
      nRangeEnd = new _NumRange.default(endRect.x, endRect.width);
      nRangeOverlap = nRangeStart.collapsedNumRange(nRangeEnd);
      sPoint.x = nRangeOverlap.centerValue();
      ePoint.x = sPoint.x;

      if (dir.y === 1) {
        sPoint.y = startRect.y + startRect.height;
        ePoint.y = endRect.y;
      } else {
        sPoint.y = startRect.y;
        ePoint.y = endRect.y + endRect.height;
      }
    } else {
      nRangeStart = new _NumRange.default(startRect.y, startRect.height);
      nRangeEnd = new _NumRange.default(endRect.y, endRect.height);
      nRangeOverlap = nRangeStart.collapsedNumRange(nRangeEnd);
      sPoint.y = nRangeOverlap.centerValue();
      ePoint.y = sPoint.y;

      if (dir.x === 1) {
        sPoint.x = startRect.x + startRect.width;
        ePoint.x = endRect.x;
      } else {
        sPoint.x = startRect.x;
        ePoint.x = endRect.x + endRect.width;
      }
    }

    return [new _Polyline.default([sPoint, ePoint])];
  } else {
    for (startDirIdx = 0; startDirIdx < 4; ++startDirIdx) {
      startDir = pfdeDirs[startDirIdx];
      rectPoints = [startRect.B(), startRect.C(), startRect.D(), startRect.A(), startRect.B()];
      smt = new _SegmentLine.default(rectPoints[startDirIdx], rectPoints[startDirIdx + 1]);
      sPoint = smt.midpoint();

      for (endDirIdx = 0; endDirIdx < 4; ++endDirIdx) {
        endDir = pfdeDirs[endDirIdx];
        rectPoints = [endRect.D(), endRect.A(), endRect.B(), endRect.C(), endRect.D()];
        smt = new _SegmentLine.default(rectPoints[endDirIdx], rectPoints[endDirIdx + 1]);
        ePoint = smt.midpoint();

        if (dir.equals(startDir.add(endDir))) {
          smt = new _SegmentLine.default(sPoint, sPoint.add(startDir));
          hPoint = smt.orthogonalProjectionPoint(ePoint);
          length = sPoint.dist(hPoint) + hPoint.dist(ePoint);

          if (length < minLength) {
            minLength = length;
            bestPolyline = new _Polyline.default([sPoint, hPoint, ePoint]);
          }
        }
      }
    }

    return [bestPolyline];
  }
}
/**
 *
 * @param {Rectangle} startRect
 * @param {Vec2[]}interPoints
 * @param {Rectangle}endRect
 * @returns {*|Polyline[]}
 */


function beautifyPFDEline(startRect, interPoints, endRect) {
  interPoints = interPoints || [];
  interPoints = interPoints.filter(p => !startRect.containsPoint(p) && !endRect.containsPoint(p));

  if (interPoints.length === 0) {
    return beautifyPFDElineWithoutInterPoints(startRect, endRect);
  } else {
    return beautifyPFDElineWithInterPoints(startRect, interPoints, endRect);
  }
}

function testBT() {
  var startRect = new _Rectangle.default(0, 0, 50, 20);
  var endRect = new _Rectangle.default(400, 500, 50, 20);
  var interPoints = [new _Vec.default(150, 150), new _Vec.default(100, 300), new _Vec.default(420, 420)];
  var res = beautifyPFDElineWithInterPoints(startRect, interPoints, endRect);
  console.log(res);
} // testBT();

/**
 *
 * @param {ProcessFlowDiagramEditor} editor
 * @param {Object} data
 * @constructor
 */


function PFDEBlock(editor, data) {
  editor.blocks.push(this);
  this.attributes = new _Attributes.default(this);
  Object.assign(this.attributes, data.attributes);
  this.attributes.id = this.attributes.id || (0, _stringGenerate.randomIdent)(8);
  this.editor = editor;
  this.bound = new _Rectangle.default(0, 0, 0, 0);

  if (data.position) {
    if (typeof data.position.x === "number") this.bound.x = data.position.x;
    if (typeof data.position.y === "number") this.bound.y = data.position.y;
  }

  _OOP.default.drillProperty(this, this, 'rect', 'bound');

  this.computedPinData = null;
  /**
   *
   * @type {PFDELine[]}
   */

  this.lines = [];
  this.render();
  if (data.position) this.position = data.position;
  this.attributes.loadAttributeHandlers(this.attributeHandlers);
  this.dragging = false;
}

PFDEBlock.prototype.nodeType = 'BLOCK';
PFDEBlock.prototype.tag = 'Common';
PFDEBlock.prototype.hasPinOut = true;
PFDEBlock.prototype.hasPinIn = true;
PFDEBlock.prototype.canGoTo = true;
PFDEBlock.prototype.canDelete = true;
Object.defineProperty(PFDEBlock.prototype, 'id', {
  set: function (value) {
    this.attributes.id = value;
  },
  get: function () {
    return this.attributes.id;
  }
});

PFDEBlock.prototype.exportData = function () {
  return {
    tag: this.tag,
    attributes: this.attributes.export()
  };
};

PFDEBlock.prototype.exportDiagram = function () {
  var position = this.position;
  return {
    position: {
      x: position.x,
      y: position.y
    }
  };
};

PFDEBlock.prototype.isConnectedTo = function (v) {
  return this.lines.some(line => line.v === v || line.v.id === v);
};
/**
 * @param {boolean=} silent - default: false - true: do not call onBlockRemoved
 */


PFDEBlock.prototype.remove = function (silent) {
  this.lines.slice().forEach(line => line.remove(silent));
  this.domElt.remove();
  var idx = this.editor.blocks.indexOf(this);

  if (idx >= 0) {
    this.editor.blocks.splice(idx, 1);
    if (!silent) this.editor.interactDelegate.onBlockRemoved(this);
  }
};

PFDEBlock.prototype.share = {
  prerenderDiv: null
};

PFDEBlock.prototype.calcBound = function () {
  var bound;
  bound = this.domElt.getBoundingClientRect();
  var placeHolder;

  if (!bound.width && !bound.height) {
    if (!this.share.prerenderDiv) {
      this.share.prerenderDiv = (0, _FCore._)({
        class: 'pfde-prerender',
        style: {
          fontSize: '14px',
          position: 'fixed',
          left: 0,
          top: 0,
          width: '500px',
          height: '500px',
          zIndex: '-1000',
          opacity: 0,
          visibility: 'hidden',
          pointerEvents: 'none'
        }
      }).addTo(document.body);
    }

    placeHolder = (0, _FCore._)('div');
    this.domElt.selfReplace(placeHolder);
    bound = this.domElt.getBoundingClientRect();
    placeHolder.selfReplace(this.domElt);
  }

  this.bound.width = bound.width;
  this.bound.height = bound.height;
  this.lines.forEach(line => line.updatePosition());
};

PFDEBlock.prototype.attributeHandlers = {};
PFDEBlock.prototype.attributeHandlers.id = {
  set: function (value) {
    if (typeof value !== "string") value = value + '';
    value = value || (0, _stringGenerate.randomIdent)(8);
    this.domElt.attr('data-id', value);
    this.$displayName.firstChild.data = this.attributes.displayName || value;
    setTimeout(() => this.calcBound(), 50);
    return value;
  }
};
PFDEBlock.prototype.attributeHandlers.displayName = {
  set: function (value) {
    this.$displayName.firstChild.data = value || this.attributes.id;
    setTimeout(() => this.calcBound(), 50);
    return value || undefined;
  }
};
/**
 *
 * @param {Vec2} v
 * @returns {{pos: Vec2, dir: Vec2, dirIdx: number, angle: number}}
 */

PFDEBlock.prototype.getPinPositionToPoint = function (v) {
  var bound = this.bound;
  return directoryOutFromRect(bound, v);
};

PFDEBlock.prototype.typeIcon = 'span.mdi.mdi-puzzle';

PFDEBlock.prototype.renderHeader = function () {
  this.$header = (0, _FCore._)({
    class: 'as-cde-node-header',
    child: [(0, _FCore._)(this.typeIcon).addClass('as-cde-node-type-icon'), {
      class: 'as-cde-node-name-ctn',
      child: [{
        class: 'as-cde-node-name',
        child: {
          text: this.attributes.displayName || this.attributes.id
        }
      }, {
        class: 'as-cde-node-description',
        child: {
          text: this.attributes.description || ''
        }
      }]
    }]
  });
  this.$header.headerOfPFDEBlock = this;
  this.$displayName = (0, _FCore.$)('.as-cde-node-name', this.$header);
  this.$displayName.on('dblclick', () => {
    this.editDisplayName();
  });

  if (this.canGoTo) {
    this.$goToBtn = (0, _FCore._)({
      tag: 'button',
      class: ['as-transparent-button', 'pfde-block-go-to-btn'],
      child: 'span.mdi.mdi-logout-variant'
    });
    this.$header.addChild(this.$goToBtn);
    this.$goToBtn.on('click', () => {
      if (!this.dragging) this.editor.interactDelegate.goToBlock(this);
    });
  }
};

PFDEBlock.prototype.renderPinConnectCtn = function () {
  this.$pinConnectCtn = (0, _FCore._)({
    class: 'pfde-block-pin-to-connect-ctn',
    child: ['.pfde-block-pin-to-connect.as-left', '.pfde-block-pin-to-connect.as-right', '.pfde-block-pin-to-connect.as-top', '.pfde-block-pin-to-connect.as-bottom']
  });
};

PFDEBlock.prototype.render = function () {
  this.renderPinConnectCtn();
  this.renderHeader();
  this.domElt = (0, _FCore._)({
    class: ['pfde-block', 'as-cde-node'],
    attr: {
      'data-tag': this.tag
    },
    child: [this.$pinConnectCtn, this.$header]
  });
  this.domElt.pfdeBlock = this;
  this.editor.$nodeLayer.addChild(this.domElt);
  this.calcBound();
};

PFDEBlock.prototype.calcPins = function () {
  // if (this.computedPinData) return this.computedPinData;
  this.computedPinData = {};
  this.computedPinData.lines = this.lines.map((obj, idx) => {
    var res = {
      idx: idx
    };
    res.obj = obj;
    var l;

    if (obj.u === this) {
      res.dirIdx = obj.startDir.idx;
      res.of = 'u';
      res.locked = obj.lockedPathStart;
      res.nextPoint = obj.originSimplifiedLine.points[2] || obj.originSimplifiedLine.points[1];
    } else {
      l = obj.originSimplifiedLine.points.length;
      res.nextPoint = obj.originSimplifiedLine.points[l - 3] || obj.originSimplifiedLine.points[l - 2];
      res.dirIdx = invDirIdx(obj.endDir.idx);
      res.of = 'v';
      res.locked = obj.lockedPathEnd;
    }

    return res;
  });
  this.computedPinData.lineByDirIdx = this.computedPinData.lines.reduce((ac, line) => {
    ac[line.dirIdx].push(line);
    return ac;
  }, [[], [], [], []]);
  this.computedPinData.lineByDirIdx.forEach((lines, idx) => {
    lines.sort((a, b) => {
      var nextPointA = a.nextPoint;
      var nextPointB = b.nextPoint;
      var res = 0;

      if (idx === 0 || idx === 2) {
        res = nextPointA.y - nextPointB.y;
      } else {
        res = nextPointA.x - nextPointB.x;
      }

      if (Math.abs(res) < 10) {
        res = a.idx - b.idx;
      }

      return res;
    });
    var line,
        i,
        j,
        offset = 0;
    var d = {};
    var arr = [];
    i = 0;
    j = lines.length - 1;

    while (i <= j) {
      arr.push(lines[i]);

      if (i !== j) {
        arr.push(lines[j]);
      }

      i++;
      j--;
    }

    if (lines.length % 2 === 0) offset = 1;
    arr = arr.reverse();
    var k;

    for (i = 0; i < arr.length; ++i) {
      line = arr[i];

      if (line.locked) {
        //todo: not handle now
        if (idx === 0 || idx === 2) {
          line.delta = new _Vec.default(0, 0);
        }

        continue;
      } else if (i % 2 === 0) {
        k = offset + i;
      } else {
        k = offset - i - 1;
      }

      if (idx === 0 || idx === 2) {
        line.delta = new _Vec.default(0, 8 * k); // d[line.idx] = k;
      } else {
        line.delta = new _Vec.default(8 * k, 0);
      }
    }
  });
  return this.computedPinData;
};
/**
 * @param {PFDELine} line
 * @returns {Vec2}
 */


PFDEBlock.prototype.getPinDelta = function (line) {
  var pinData = this.calcPins();
  return pinData.lines.find(l => l.obj === line).delta;
}; //
// PFDEBlock.prototype.getPinOuts = function () {
//     var pinData = this.calcPins();
//     return pinData.lines.find()
// };


PFDEBlock.prototype.editDisplayName = function () {
  return new Promise(resolve => {
    var cpStyle = getComputedStyle(this.$displayName);
    var style = ['background-color', 'color', 'font', 'padding', 'border', 'display', 'width'].reduce((ac, name) => {
      ac[name] = cpStyle.getPropertyValue(name);
      return ac;
    }, {
      outline: 'none'
    });
    var paddingLeft = parseFloat(cpStyle.getPropertyValue('padding-left').replace('px', '')) || 0;
    var paddingRight = parseFloat(cpStyle.getPropertyValue('padding-right').replace('px', '')) || 0;

    var applyWidthOf = text => {
      var width = (0, _utils.measureText)(text, style.font).width;
      input.addStyle('width', width + paddingLeft + paddingRight + 'px');
      this.calcBound();
      this.lines.forEach(line => line.updatePosition());
    };

    var input = (0, _FCore._)({
      tag: 'input',
      style: style,
      props: {
        value: this.attributes.displayName || this.attributes.id
      },
      on: {
        blur: () => {
          var value = input.value.trim();
          this.attributes.displayName = value;
          input.remove();
          this.$displayName.removeStyle('display');
          resolve(value);
        },
        keyup: () => {
          applyWidthOf(input.value);
        },
        keydown: event => {
          var key = event.key;

          if (key.length === 1 && !event.ctrlKey && !event.altKey) {
            applyWidthOf(input.value + key);
          } else if (key === 'Enter') input.blur();
        }
      }
    });
    this.$displayName.addStyle('display', 'none');
    this.$displayName.parentElement.addChildBefore(input, this.$displayName);
    input.focus();
    input.select();
  });
};

Object.defineProperty(PFDEBlock.prototype, 'position', {
  set: function (value) {
    value = value || _Vec.default.ZERO;
    var x = (0, _utils.isRealNumber)(value.x) ? value.x : 0;
    var y = (0, _utils.isRealNumber)(value.y) ? value.y : 0;
    this.bound.x = x;
    this.bound.y = y;
    this.domElt.addStyle({
      left: this.bound.x + 'px',
      top: this.bound.y + 'px'
    });
    this.lines.forEach(line => {
      line.calcPath();
      line.updatePosition();
    });
  },
  get: function () {
    return this.bound.A();
  }
});
Object.defineProperty(PFDEBlock.prototype, 'hovering', {
  set: function (value) {
    if (value) {
      this.domElt.addClass('as-hovering');
    } else {
      this.domElt.removeClass('as-hovering');
    }
  },
  get: function () {
    return this.domElt.hasClass('as-hovering');
  }
});
/**
 * @extends PFDEBlock
 * @constructor
 */

function PFDEBStart(editor, data) {
  data = data || {};
  data.displayName = data.displayName || "Bắt đầu";
  PFDEBlock.call(this, editor, data);
}

(0, _inheritComponentClass.default)(PFDEBStart, PFDEBlock);
PFDEBStart.prototype.typeIcon = 'span.mdi.mdi-ray-start-arrow';
PFDEBStart.prototype.tag = 'Start';
PFDEBStart.prototype.canDelete = false;

function PFDEBSuccess(editor, data) {
  data = data || {};
  data.displayName = data.displayName || "Thành công";
  PFDEBlock.call(this, editor, data);
}

(0, _inheritComponentClass.default)(PFDEBSuccess, PFDEBlock);
PFDEBSuccess.prototype.typeIcon = 'span.mdi.mdi-flag-checkered';
PFDEBSuccess.prototype.tag = 'Success';
PFDEBSuccess.prototype.canGoTo = false;
PFDEBSuccess.prototype.canDelete = false;
PFDEBSuccess.prototype.hasPinOut = false;

function PFDEBFail(editor, data) {
  data = data || {};
  data.displayName = data.displayName || "Thất bại";
  PFDEBlock.call(this, editor, data);
}

(0, _inheritComponentClass.default)(PFDEBFail, PFDEBlock);
PFDEBFail.prototype.typeIcon = 'span.mdi.mdi-flag-off-outline';
PFDEBFail.prototype.tag = 'Fail';
PFDEBFail.prototype.canGoTo = false;
PFDEBFail.prototype.canDelete = false;
PFDEBFail.prototype.hasPinOut = false;

function PFDEBProcess(editor, data) {
  PFDEBlock.apply(this, arguments);
}

(0, _inheritComponentClass.default)(PFDEBProcess, PFDEBlock);

function PFDEBSubProcedure(editor, data) {
  PFDEBlock.apply(this, arguments);
}

(0, _inheritComponentClass.default)(PFDEBSubProcedure, PFDEBlock);
PFDEBSubProcedure.prototype.typeIcon = 'span.mdi.mdi-chart-sankey-variant';
PFDEBSubProcedure.prototype.tag = 'SubProcedure';

VaKeR 2022