![]() 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 : |
/*** module: node_modules/absol-form/js/processflowdiagrameditor/PFDELine.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PFDEIntermediatePoint = PFDEIntermediatePoint; exports.PFDEDrawingLine = PFDEDrawingLine; exports.default = void 0; var _GCore = _interopRequireDefault(require("../core/GCore")); var _Color = _interopRequireDefault(require("absol/src/Color/Color")); var _stringGenerate = require("absol/src/String/stringGenerate"); var _FCore = require("../core/FCore"); var _Turtle = _interopRequireDefault(require("absol-svg/js/controller/Turtle")); var _Vec = _interopRequireDefault(require("absol/src/Math/Vec2")); var _Attributes = _interopRequireDefault(require("absol/src/AppPattern/Attributes")); var _OOP = _interopRequireDefault(require("absol/src/HTML5/OOP")); var _PFDEBlocks = require("./PFDEBlocks"); var _Polyline = _interopRequireDefault(require("absol/src/Math/Polyline")); var _stringUtils = require("absol/src/String/stringUtils"); var _SegmentLine = _interopRequireDefault(require("absol/src/Math/SegmentLine")); function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } /** * * @param {ProcessFlowDiagramEditor} editor * @param {PFDEBlock} u * @param {PFDEBlock} v * @param {PFDLineData=} data * @param extraData * @constructor */ function PFDELine(editor, u, v, data, extraData) { editor.lines.push(this); data = Object.assign({}, data || {}); data.id = data.id || (0, _stringGenerate.randomIdent)(8); /** * * @type {PFDEIntermediatePoint[]} */ this.intermediatePoints = []; if (extraData && extraData.intermediatePoints) { this.intermediatePoints = extraData.intermediatePoints.map(point => new PFDEIntermediatePoint(this, point)); } this.color = extraData.color || null; this.attributes = new _Attributes.default(this); _OOP.default.drillProperty(this, this.attributes, 'id'); Object.keys(this.attributeHandlers).forEach(key => { if (key in data) this.attributes[key] = data[key]; }); this.editor = editor; this.u = u; this.v = v; // this.data = data; u.lines.push(this); if (u !== v) v.lines.push(this); /** * * @type {Polyline[]} */ this.viewPolylines = [new _Polyline.default([])]; this.render(); this.attributes.loadAttributeHandlers(this.attributeHandlers); this.calcPath(); /** * @type {string} * @memberof PFDELine# * @name id */ u.lines.forEach(line => line.updatePosition()); if (u !== v) v.lines.forEach(line => line.updatePosition()); } PFDELine.prototype.nodeType = "LINE"; PFDELine.prototype.canDelete = true; PFDELine.prototype.shareColors = {}; PFDELine.prototype.getAutoColor = function () { var id = this.id; var color; var hash = (0, _stringUtils.stringHashCode)(id + ''); hash = Math.abs(hash) % (256 * 256 * 256); color = _Color.default.parse('#' + ('00000' + hash.toString(16)).slice(-6)); var hsla = color.toHSLA(); if (hsla[2] > 0.8) { hsla[2] -= 0.4; color = _Color.default.fromHSLA.apply(_Color.default, _toConsumableArray(hsla)); } return color; }; /** * render and add to editor */ PFDELine.prototype.render = function () { var markerId = (0, _stringGenerate.randomIdent)(8); var lineColor = this.color; this.$marker = _GCore.default._({ tag: 'marker', style: { '--line-color': lineColor }, attr: { id: markerId, markerWidth: '3', markerHeight: '8', orient: 'auto', refX: '4.1', refY: '4' }, child: { tag: 'path', attr: { d: 'M0,0 V8 L4,4 Z' }, style: { fill: 'var(--line-color)' } } }); this.$intermediatePoints = this.intermediatePoints.map(it => it.domElt); this.$itGroup = _GCore.default._({ style: { '--line-color': lineColor }, child: this.$intermediatePoints }); this.domElt = _GCore.default._({ tag: 'g', class: ['as-cde-line-group'], attr: { 'data-line-id': this.attributes.id }, style: { '--line-color': lineColor }, child: [{ tag: 'path', class: 'as-cde-hit-line' }, { tag: 'path', class: 'as-cde-line', style: { 'marker-end': `url(#${markerId})` } }, { tag: 'path', class: 'as-cde-line-lock' }, { tag: 'text', class: 'as-cde-line-text-shadow', style: { backgroundColor: 'white' }, attr: { x: 0, y: 0, "text-anchor": 'middle', 'dominant-baseline': "middle" }, child: { text: '' } }, { tag: 'text', class: 'as-cde-line-text', style: { backgroundColor: 'white' }, attr: { x: 0, y: 0, "text-anchor": 'middle', 'dominant-baseline': "middle" }, child: { text: '' } }], props: { pfdeLine: this } }); _OOP.default.drillProperty(this.domElt, this.attributes, 'lineId', 'id'); this.$paths = (0, _FCore.$$)('path', this.domElt); this.$texts = (0, _FCore.$$)('text', this.domElt); this.editor.$lineDefs.addChild(this.$marker); this.editor.$lineLayer.addChild(this.domElt); this.editor.$intermediatePointLayer.addChild(this.$itGroup); }; PFDELine.prototype.attributeHandlers = {}; PFDELine.prototype.attributeHandlers.id = { set: function (value) { if (typeof value !== "string") value = value + ''; value = value || (0, _stringGenerate.randomIdent)(8); this.domElt.attr('data-line-id', value); return value; } }; PFDELine.prototype.attributeHandlers.text = { set: function (value) { value = value + ''; this.$texts.forEach(elt => elt.firstChild.data = value); return value; }, export: function (ref) { return ref.get() || undefined; } }; /** * * @param {boolean=} silent - not fire event */ PFDELine.prototype.remove = function (silent) { var u = this.u; var v = this.v; this.domElt.remove(); this.$itGroup.remove(); this.$marker.remove(); var idx = this.u.lines.indexOf(this); if (idx >= 0) this.u.lines.splice(idx, 1); idx = this.v.lines.indexOf(this); if (idx >= 0) this.v.lines.splice(idx, 1); idx = this.editor.lines.indexOf(this); if (idx >= 0) this.editor.lines.splice(idx, 1); if (idx >= 0) { if (!silent) this.editor.interactDelegate.onLineRemoved(this); } u.lines.forEach(line => line.updatePosition()); if (u !== v) v.lines.forEach(line => line.updatePosition()); }; PFDELine.prototype.calcPath = function () { var u = this.u; var v = this.v; var interPoints = this.intermediatePoints.map(point => point.position); this.originPolyLines = (0, _PFDEBlocks.beautifyPFDEline)(u.bound, interPoints, v.bound); var points = this.originPolyLines.reduce((ac, pl) => { return ac.concat(pl.points); }, []); this.originSimplifiedLine = new _Polyline.default(points).simplify(); var startSM = new _SegmentLine.default(points[0], points[1]); this.lockedPathStart = this.originSimplifiedLine.points.length < 3 || interPoints.some(point => { return startSM.nearestPointToPoint(point).dist(point) < 0.001; }); var endSM = new _SegmentLine.default(points[points.length - 2], points[points.length - 1]); this.lockedPathEnd = this.originSimplifiedLine.points.length < 3 || interPoints.some(point => { return endSM.nearestPointToPoint(point).dist(point) < 0.001; }); this.startDir = (0, _PFDEBlocks.directoryOfVec2)(points[1].sub(points[0])); this.endDir = (0, _PFDEBlocks.directoryOfVec2)(points[points.length - 1].sub(points[points.length - 2])); this.u.computedPinData = null; //force update this.v.computedPinData = null; return this.originPolyLines; }; /** * @param {boolean} reverse * @return {Vec2[]} */ PFDELine.prototype.getPolyLinePoints = function (reverse) { var points = this.viewPolylines.reduce((ac, cr) => { return ac.concat(cr.points); }, []); if (reverse) points = points.slice().reverse(); return new _Polyline.default(points).simplify().points; }; PFDELine.prototype.updatePath = function () { //line var polyLines = this.originPolyLines; if (!polyLines) return; this.viewPolylines = polyLines.map(pl => pl.copy()); var startDelta = this.u.getPinDelta(this) || new _Vec.default(0, 0); var endDelta = this.v.getPinDelta(this) || new _Vec.default(0, 0); var points = this.viewPolylines.reduce((ac, cr) => { return ac.concat(cr.points); }, []); var i = 0; var prevPoint = points[0].copy(); while (i < points.length) { if (Math.abs(points[i].x - prevPoint.x) < 0.001 || Math.abs(points[i].y - prevPoint.y) < 0.001) { points[i].x += startDelta.x; points[i].y += startDelta.y; i++; } else break; } i = points.length - 1; prevPoint = points[points.length - 1].copy(); while (i >= 0) { if (Math.abs(points[i].x - prevPoint.x) < 0.001 || Math.abs(points[i].y - prevPoint.y) < 0.001) { points[i].x += endDelta.x; points[i].y += endDelta.y; i--; } else break; } var turtle = new _Turtle.default(); turtle.moveTo(points[0].x, points[0].y); for (i = 1; i < points.length; ++i) { turtle.lineTo(points[i].x, points[i].y); } this.$paths.forEach(pathElt => pathElt.attr('d', turtle.getPath())); }; PFDELine.prototype.updatePosition = function () { this.updatePath(); }; PFDELine.prototype.export = function () { return Object.assign({}, this.attributes.export, { u: this.u.id, v: this.v.id, id: this.id }); }; PFDELine.prototype.exportDiagram = function () { return { intermediatePoints: this.exportIntermediatePoints(), color: this.color.toString('hex6') }; }; PFDELine.prototype.exportIntermediatePoints = function () { if (this.intermediatePoints.length === 0) return undefined; return this.intermediatePoints.map(function (point) { return { x: point.x, y: point.y }; }); }; PFDELine.prototype.addIntermediatePoint = function (data, at) { var newPoint = new PFDEIntermediatePoint(this, data); if (this.intermediatePoints[at]) { this.intermediatePoints.splice(at, 0, newPoint); } else { this.intermediatePoints.push(newPoint); } this.domElt.addChild(newPoint.domElt); //todo: add before text this.updatePosition(); //todo: update other return newPoint; }; Object.defineProperty(PFDELine.prototype, 'loopBack', { return: function () { return this.u === this.v; } }); Object.defineProperty(PFDELine.prototype, 'color', { get: function () { return this._color || this.getAutoColor(); }, set: function (value) { if (typeof value === "string") { try { value = _Color.default.parse(value); } catch (error) { value = null; } } if (value instanceof _Color.default) { this._color = value; } else { this._color = null; } if (this.domElt) { this.domElt.addStyle('--line-color', this.color.toString('hex6')); this.$marker.addStyle('--line-color', this.color.toString('hex6')); this.$itGroup.addStyle('--line-color', this.color.toString('hex6')); } } }); var _default = PFDELine; /** * * @param {null|PFDELine} line - null for new point * @param data * @constructor */ exports.default = _default; function PFDEIntermediatePoint(line, data) { this.line = line; this._position = new _Vec.default(0, 0); if (data && typeof data.x === "number" && typeof data.y === "number") { this._position.x = data.x; this._position.y = data.y; } if (typeof data.id === "string") { this.id = data.id; } else { this.id = (0, _stringGenerate.randomIdent)(8) + '_' + Date.now(); } this.render(); } PFDEIntermediatePoint.prototype.nodeType = "INTERMEDIATE_POINT"; PFDEIntermediatePoint.prototype.render = function () { this.domElt = _GCore.default._({ tag: 'g', class: 'as-cde-intermediate-point', child: [{ tag: 'circle', class: 'as-cde-intermediate-point-circle-highlight', attr: { cx: 0, cy: 0, r: 8 } }, { tag: 'circle', class: 'as-cde-intermediate-point-circle', attr: { cx: 0, cy: 0, r: 5 } }] }); this.domElt.pfdeIntermediatePoint = this; if (!this.line) this.domElt.addClass('pfde-new-point'); this.updatePosition(); }; PFDEIntermediatePoint.prototype.updatePosition = function () { this.domElt.attr('transform', `translate(${this._position.x}, ${this._position.y})`); }; PFDEIntermediatePoint.prototype.remove = function () { if (this.domElt.parentElement) this.domElt.remove(); if (!this.line) return; var idx = this.line.intermediatePoints.indexOf(this); if (idx < 0) return; this.line.intermediatePoints.splice(idx, 1); this.line.updatePosition(); this.line = null; }; Object.defineProperty(PFDEIntermediatePoint.prototype, 'position', { enumerable: true, configurable: true, set: function (value) { if (value && typeof value.x === "number" && typeof value.y === "number") { this._position.x = value.x; this._position.y = value.y; this.updatePosition(); if (this.line) this.line.updatePosition(); } }, get: function () { return this._position.copy(); } }); Object.defineProperty(PFDEIntermediatePoint.prototype, 'x', { get: function () { return this._position.x; } }); Object.defineProperty(PFDEIntermediatePoint.prototype, 'y', { get: function () { return this._position.y; } }); /** * * @param {ProcessFlowDiagramEditor} editor * @param {PFDEBlock} u * @constructor */ function PFDEDrawingLine(editor, u) { this.editor = editor; this.u = u; this.v = null; /** * * @type {PFDEIntermediatePoint[]} */ this.intermediatePoints = []; this.tartgetPoint = null; this.render(); } PFDEDrawingLine.prototype.nodeType = "DRAWING_LINE"; PFDEDrawingLine.prototype.render = function () { this.$newLineMarker = _GCore.default._({ tag: 'marker', attr: { id: (0, _stringGenerate.randomIdent)(8), markerWidth: '3', markerHeight: '8', orient: 'auto', refX: '4.1', refY: '4' }, child: { tag: 'path', attr: { d: 'M0,0 V8 L4,4 Z' } } }); this.$newLineMarkerPath = (0, _FCore.$)('path', this.$newLineMarker); this.editor.$lineDefs.addChild(this.$newLineMarker); this.$newLine = _GCore.default._({ tag: 'path', class: 'as-cde-line', attr: { d: new _Turtle.default().moveTo(10, 10).lineBy(100, 100).getPath() }, style: { '--line-color': 'red', 'marker-end': `url(#${this.$newLineMarker.id})`, display: 'none', pointerEvents: 'none' } }); this.domElt = _GCore.default._({ tag: 'g', class: 'as-cde-drawing-line', child: [this.$newLine] }); }; PFDEDrawingLine.prototype.remove = function () { this.domElt.remove(); this.$newLineMarker.remove(); }; PFDEDrawingLine.prototype.updatePath = function () {}; PFDEDrawingLine.prototype.updatePosition = function () {};