123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- import {
- asTRBL,
- getMid,
- getOrientation
- } from "./chunk-7FXQS3I2.js";
- import {
- isConnection
- } from "./chunk-RL3RINWF.js";
- import {
- is,
- isAny
- } from "./chunk-L5SG54UC.js";
- import {
- find,
- reduce
- } from "./chunk-4AK4GF4H.js";
- // node_modules/.pnpm/diagram-js@13.4.0/node_modules/diagram-js/lib/features/auto-place/AutoPlaceUtil.js
- var PLACEMENT_DETECTION_PAD = 10;
- var DEFAULT_DISTANCE = 50;
- var DEFAULT_MAX_DISTANCE = 250;
- function findFreePosition(source, element, position, getNextPosition) {
- var connectedAtPosition;
- while (connectedAtPosition = getConnectedAtPosition(source, position, element)) {
- position = getNextPosition(element, position, connectedAtPosition);
- }
- return position;
- }
- function generateGetNextPosition(nextPositionDirection) {
- return function(element, previousPosition, connectedAtPosition) {
- var nextPosition = {
- x: previousPosition.x,
- y: previousPosition.y
- };
- ["x", "y"].forEach(function(axis) {
- var nextPositionDirectionForAxis = nextPositionDirection[axis];
- if (!nextPositionDirectionForAxis) {
- return;
- }
- var dimension = axis === "x" ? "width" : "height";
- var margin = nextPositionDirectionForAxis.margin, minDistance = nextPositionDirectionForAxis.minDistance;
- if (margin < 0) {
- nextPosition[axis] = Math.min(
- connectedAtPosition[axis] + margin - element[dimension] / 2,
- previousPosition[axis] - minDistance + margin
- );
- } else {
- nextPosition[axis] = Math.max(
- connectedAtPosition[axis] + connectedAtPosition[dimension] + margin + element[dimension] / 2,
- previousPosition[axis] + minDistance + margin
- );
- }
- });
- return nextPosition;
- };
- }
- function getConnectedAtPosition(source, position, element) {
- var bounds = {
- x: position.x - element.width / 2,
- y: position.y - element.height / 2,
- width: element.width,
- height: element.height
- };
- var closure = getAutoPlaceClosure(source, element);
- return find(closure, function(target) {
- if (target === element) {
- return false;
- }
- var orientation = getOrientation(target, bounds, PLACEMENT_DETECTION_PAD);
- return orientation === "intersect";
- });
- }
- function getConnectedDistance(source, hints) {
- if (!hints) {
- hints = {};
- }
- function getDefaultWeight(connection) {
- return connection.source === source ? 1 : -1;
- }
- var defaultDistance = hints.defaultDistance || DEFAULT_DISTANCE, direction = hints.direction || "e", filter = hints.filter, getWeight = hints.getWeight || getDefaultWeight, maxDistance = hints.maxDistance || DEFAULT_MAX_DISTANCE, reference = hints.reference || "start";
- if (!filter) {
- filter = noneFilter;
- }
- function getDistance(a, b) {
- if (direction === "n") {
- if (reference === "start") {
- return asTRBL(a).top - asTRBL(b).bottom;
- } else if (reference === "center") {
- return asTRBL(a).top - getMid(b).y;
- } else {
- return asTRBL(a).top - asTRBL(b).top;
- }
- } else if (direction === "w") {
- if (reference === "start") {
- return asTRBL(a).left - asTRBL(b).right;
- } else if (reference === "center") {
- return asTRBL(a).left - getMid(b).x;
- } else {
- return asTRBL(a).left - asTRBL(b).left;
- }
- } else if (direction === "s") {
- if (reference === "start") {
- return asTRBL(b).top - asTRBL(a).bottom;
- } else if (reference === "center") {
- return getMid(b).y - asTRBL(a).bottom;
- } else {
- return asTRBL(b).bottom - asTRBL(a).bottom;
- }
- } else {
- if (reference === "start") {
- return asTRBL(b).left - asTRBL(a).right;
- } else if (reference === "center") {
- return getMid(b).x - asTRBL(a).right;
- } else {
- return asTRBL(b).right - asTRBL(a).right;
- }
- }
- }
- var sourcesDistances = source.incoming.filter(filter).map(function(connection) {
- var weight = getWeight(connection);
- var distance = weight < 0 ? getDistance(connection.source, source) : getDistance(source, connection.source);
- return {
- id: connection.source.id,
- distance,
- weight
- };
- });
- var targetsDistances = source.outgoing.filter(filter).map(function(connection) {
- var weight = getWeight(connection);
- var distance = weight > 0 ? getDistance(source, connection.target) : getDistance(connection.target, source);
- return {
- id: connection.target.id,
- distance,
- weight
- };
- });
- var distances = sourcesDistances.concat(targetsDistances).reduce(function(accumulator, currentValue) {
- accumulator[currentValue.id + "__weight_" + currentValue.weight] = currentValue;
- return accumulator;
- }, {});
- var distancesGrouped = reduce(distances, function(accumulator, currentValue) {
- var distance = currentValue.distance, weight = currentValue.weight;
- if (distance < 0 || distance > maxDistance) {
- return accumulator;
- }
- if (!accumulator[String(distance)]) {
- accumulator[String(distance)] = 0;
- }
- accumulator[String(distance)] += 1 * weight;
- if (!accumulator.distance || accumulator[accumulator.distance] < accumulator[String(distance)]) {
- accumulator.distance = distance;
- }
- return accumulator;
- }, {});
- return distancesGrouped.distance || defaultDistance;
- }
- function getAutoPlaceClosure(source) {
- var allConnected = getConnected(source);
- if (source.host) {
- allConnected = allConnected.concat(getConnected(source.host));
- }
- if (source.attachers) {
- allConnected = allConnected.concat(source.attachers.reduce(function(shapes, attacher) {
- return shapes.concat(getConnected(attacher));
- }, []));
- }
- return allConnected;
- }
- function getConnected(element) {
- return getTargets(element).concat(getSources(element));
- }
- function getSources(shape) {
- return shape.incoming.map(function(connection) {
- return connection.source;
- });
- }
- function getTargets(shape) {
- return shape.outgoing.map(function(connection) {
- return connection.target;
- });
- }
- function noneFilter() {
- return true;
- }
- // node_modules/.pnpm/diagram-js@13.4.0/node_modules/diagram-js/lib/features/auto-place/AutoPlace.js
- var LOW_PRIORITY = 100;
- function AutoPlace(eventBus, modeling, canvas) {
- eventBus.on("autoPlace", LOW_PRIORITY, function(context) {
- var shape = context.shape, source = context.source;
- return getNewShapePosition(source, shape);
- });
- eventBus.on("autoPlace.end", function(event) {
- canvas.scrollToElement(event.shape);
- });
- this.append = function(source, shape, hints) {
- eventBus.fire("autoPlace.start", {
- source,
- shape
- });
- var position = eventBus.fire("autoPlace", {
- source,
- shape
- });
- var newShape = modeling.appendShape(source, shape, position, source.parent, hints);
- eventBus.fire("autoPlace.end", {
- source,
- shape: newShape
- });
- return newShape;
- };
- }
- AutoPlace.$inject = [
- "eventBus",
- "modeling",
- "canvas"
- ];
- function getNewShapePosition(source, element, hints) {
- if (!hints) {
- hints = {};
- }
- var distance = hints.defaultDistance || DEFAULT_DISTANCE;
- var sourceMid = getMid(source), sourceTrbl = asTRBL(source);
- return {
- x: sourceTrbl.right + distance + element.width / 2,
- y: sourceMid.y
- };
- }
- // node_modules/.pnpm/diagram-js@13.4.0/node_modules/diagram-js/lib/features/auto-place/AutoPlaceSelectionBehavior.js
- function AutoPlaceSelectionBehavior(eventBus, selection) {
- eventBus.on("autoPlace.end", 500, function(e) {
- selection.select(e.shape);
- });
- }
- AutoPlaceSelectionBehavior.$inject = [
- "eventBus",
- "selection"
- ];
- // node_modules/.pnpm/diagram-js@13.4.0/node_modules/diagram-js/lib/features/auto-place/index.js
- var auto_place_default = {
- __init__: ["autoPlaceSelectionBehavior"],
- autoPlace: ["type", AutoPlace],
- autoPlaceSelectionBehavior: ["type", AutoPlaceSelectionBehavior]
- };
- // node_modules/.pnpm/bpmn-js@16.3.2/node_modules/bpmn-js/lib/features/auto-place/BpmnAutoPlaceUtil.js
- function getNewShapePosition2(source, element) {
- if (is(element, "bpmn:TextAnnotation")) {
- return getTextAnnotationPosition(source, element);
- }
- if (isAny(element, ["bpmn:DataObjectReference", "bpmn:DataStoreReference"])) {
- return getDataElementPosition(source, element);
- }
- if (is(element, "bpmn:FlowNode")) {
- return getFlowNodePosition(source, element);
- }
- }
- function getFlowNodePosition(source, element) {
- var sourceTrbl = asTRBL(source);
- var sourceMid = getMid(source);
- var horizontalDistance = getConnectedDistance(source, {
- filter: function(connection) {
- return is(connection, "bpmn:SequenceFlow");
- }
- });
- var margin = 30, minDistance = 80, orientation = "left";
- if (is(source, "bpmn:BoundaryEvent")) {
- orientation = getOrientation(source, source.host, -25);
- if (orientation.indexOf("top") !== -1) {
- margin *= -1;
- }
- }
- var position = {
- x: sourceTrbl.right + horizontalDistance + element.width / 2,
- y: sourceMid.y + getVerticalDistance(orientation, minDistance)
- };
- var nextPositionDirection = {
- y: {
- margin,
- minDistance
- }
- };
- return findFreePosition(source, element, position, generateGetNextPosition(nextPositionDirection));
- }
- function getVerticalDistance(orientation, minDistance) {
- if (orientation.includes("top")) {
- return -1 * minDistance;
- } else if (orientation.includes("bottom")) {
- return minDistance;
- } else {
- return 0;
- }
- }
- function getTextAnnotationPosition(source, element) {
- var sourceTrbl = asTRBL(source);
- var position = {
- x: sourceTrbl.right + element.width / 2,
- y: sourceTrbl.top - 50 - element.height / 2
- };
- if (isConnection(source)) {
- position = getMid(source);
- position.x += 100;
- position.y -= 50;
- }
- var nextPositionDirection = {
- y: {
- margin: -30,
- minDistance: 20
- }
- };
- return findFreePosition(source, element, position, generateGetNextPosition(nextPositionDirection));
- }
- function getDataElementPosition(source, element) {
- var sourceTrbl = asTRBL(source);
- var position = {
- x: sourceTrbl.right - 10 + element.width / 2,
- y: sourceTrbl.bottom + 40 + element.width / 2
- };
- var nextPositionDirection = {
- x: {
- margin: 30,
- minDistance: 30
- }
- };
- return findFreePosition(source, element, position, generateGetNextPosition(nextPositionDirection));
- }
- // node_modules/.pnpm/bpmn-js@16.3.2/node_modules/bpmn-js/lib/features/auto-place/BpmnAutoPlace.js
- function AutoPlace2(eventBus) {
- eventBus.on("autoPlace", function(context) {
- var shape = context.shape, source = context.source;
- return getNewShapePosition2(source, shape);
- });
- }
- AutoPlace2.$inject = ["eventBus"];
- // node_modules/.pnpm/bpmn-js@16.3.2/node_modules/bpmn-js/lib/features/auto-place/index.js
- var auto_place_default2 = {
- __depends__: [auto_place_default],
- __init__: ["bpmnAutoPlace"],
- bpmnAutoPlace: ["type", AutoPlace2]
- };
- export {
- getNewShapePosition2 as getNewShapePosition,
- auto_place_default2 as auto_place_default
- };
- //# sourceMappingURL=chunk-YGL7V3UZ.js.map
|