chunk-YGL7V3UZ.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. import {
  2. asTRBL,
  3. getMid,
  4. getOrientation
  5. } from "./chunk-7FXQS3I2.js";
  6. import {
  7. isConnection
  8. } from "./chunk-RL3RINWF.js";
  9. import {
  10. is,
  11. isAny
  12. } from "./chunk-L5SG54UC.js";
  13. import {
  14. find,
  15. reduce
  16. } from "./chunk-4AK4GF4H.js";
  17. // node_modules/.pnpm/diagram-js@13.4.0/node_modules/diagram-js/lib/features/auto-place/AutoPlaceUtil.js
  18. var PLACEMENT_DETECTION_PAD = 10;
  19. var DEFAULT_DISTANCE = 50;
  20. var DEFAULT_MAX_DISTANCE = 250;
  21. function findFreePosition(source, element, position, getNextPosition) {
  22. var connectedAtPosition;
  23. while (connectedAtPosition = getConnectedAtPosition(source, position, element)) {
  24. position = getNextPosition(element, position, connectedAtPosition);
  25. }
  26. return position;
  27. }
  28. function generateGetNextPosition(nextPositionDirection) {
  29. return function(element, previousPosition, connectedAtPosition) {
  30. var nextPosition = {
  31. x: previousPosition.x,
  32. y: previousPosition.y
  33. };
  34. ["x", "y"].forEach(function(axis) {
  35. var nextPositionDirectionForAxis = nextPositionDirection[axis];
  36. if (!nextPositionDirectionForAxis) {
  37. return;
  38. }
  39. var dimension = axis === "x" ? "width" : "height";
  40. var margin = nextPositionDirectionForAxis.margin, minDistance = nextPositionDirectionForAxis.minDistance;
  41. if (margin < 0) {
  42. nextPosition[axis] = Math.min(
  43. connectedAtPosition[axis] + margin - element[dimension] / 2,
  44. previousPosition[axis] - minDistance + margin
  45. );
  46. } else {
  47. nextPosition[axis] = Math.max(
  48. connectedAtPosition[axis] + connectedAtPosition[dimension] + margin + element[dimension] / 2,
  49. previousPosition[axis] + minDistance + margin
  50. );
  51. }
  52. });
  53. return nextPosition;
  54. };
  55. }
  56. function getConnectedAtPosition(source, position, element) {
  57. var bounds = {
  58. x: position.x - element.width / 2,
  59. y: position.y - element.height / 2,
  60. width: element.width,
  61. height: element.height
  62. };
  63. var closure = getAutoPlaceClosure(source, element);
  64. return find(closure, function(target) {
  65. if (target === element) {
  66. return false;
  67. }
  68. var orientation = getOrientation(target, bounds, PLACEMENT_DETECTION_PAD);
  69. return orientation === "intersect";
  70. });
  71. }
  72. function getConnectedDistance(source, hints) {
  73. if (!hints) {
  74. hints = {};
  75. }
  76. function getDefaultWeight(connection) {
  77. return connection.source === source ? 1 : -1;
  78. }
  79. 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";
  80. if (!filter) {
  81. filter = noneFilter;
  82. }
  83. function getDistance(a, b) {
  84. if (direction === "n") {
  85. if (reference === "start") {
  86. return asTRBL(a).top - asTRBL(b).bottom;
  87. } else if (reference === "center") {
  88. return asTRBL(a).top - getMid(b).y;
  89. } else {
  90. return asTRBL(a).top - asTRBL(b).top;
  91. }
  92. } else if (direction === "w") {
  93. if (reference === "start") {
  94. return asTRBL(a).left - asTRBL(b).right;
  95. } else if (reference === "center") {
  96. return asTRBL(a).left - getMid(b).x;
  97. } else {
  98. return asTRBL(a).left - asTRBL(b).left;
  99. }
  100. } else if (direction === "s") {
  101. if (reference === "start") {
  102. return asTRBL(b).top - asTRBL(a).bottom;
  103. } else if (reference === "center") {
  104. return getMid(b).y - asTRBL(a).bottom;
  105. } else {
  106. return asTRBL(b).bottom - asTRBL(a).bottom;
  107. }
  108. } else {
  109. if (reference === "start") {
  110. return asTRBL(b).left - asTRBL(a).right;
  111. } else if (reference === "center") {
  112. return getMid(b).x - asTRBL(a).right;
  113. } else {
  114. return asTRBL(b).right - asTRBL(a).right;
  115. }
  116. }
  117. }
  118. var sourcesDistances = source.incoming.filter(filter).map(function(connection) {
  119. var weight = getWeight(connection);
  120. var distance = weight < 0 ? getDistance(connection.source, source) : getDistance(source, connection.source);
  121. return {
  122. id: connection.source.id,
  123. distance,
  124. weight
  125. };
  126. });
  127. var targetsDistances = source.outgoing.filter(filter).map(function(connection) {
  128. var weight = getWeight(connection);
  129. var distance = weight > 0 ? getDistance(source, connection.target) : getDistance(connection.target, source);
  130. return {
  131. id: connection.target.id,
  132. distance,
  133. weight
  134. };
  135. });
  136. var distances = sourcesDistances.concat(targetsDistances).reduce(function(accumulator, currentValue) {
  137. accumulator[currentValue.id + "__weight_" + currentValue.weight] = currentValue;
  138. return accumulator;
  139. }, {});
  140. var distancesGrouped = reduce(distances, function(accumulator, currentValue) {
  141. var distance = currentValue.distance, weight = currentValue.weight;
  142. if (distance < 0 || distance > maxDistance) {
  143. return accumulator;
  144. }
  145. if (!accumulator[String(distance)]) {
  146. accumulator[String(distance)] = 0;
  147. }
  148. accumulator[String(distance)] += 1 * weight;
  149. if (!accumulator.distance || accumulator[accumulator.distance] < accumulator[String(distance)]) {
  150. accumulator.distance = distance;
  151. }
  152. return accumulator;
  153. }, {});
  154. return distancesGrouped.distance || defaultDistance;
  155. }
  156. function getAutoPlaceClosure(source) {
  157. var allConnected = getConnected(source);
  158. if (source.host) {
  159. allConnected = allConnected.concat(getConnected(source.host));
  160. }
  161. if (source.attachers) {
  162. allConnected = allConnected.concat(source.attachers.reduce(function(shapes, attacher) {
  163. return shapes.concat(getConnected(attacher));
  164. }, []));
  165. }
  166. return allConnected;
  167. }
  168. function getConnected(element) {
  169. return getTargets(element).concat(getSources(element));
  170. }
  171. function getSources(shape) {
  172. return shape.incoming.map(function(connection) {
  173. return connection.source;
  174. });
  175. }
  176. function getTargets(shape) {
  177. return shape.outgoing.map(function(connection) {
  178. return connection.target;
  179. });
  180. }
  181. function noneFilter() {
  182. return true;
  183. }
  184. // node_modules/.pnpm/diagram-js@13.4.0/node_modules/diagram-js/lib/features/auto-place/AutoPlace.js
  185. var LOW_PRIORITY = 100;
  186. function AutoPlace(eventBus, modeling, canvas) {
  187. eventBus.on("autoPlace", LOW_PRIORITY, function(context) {
  188. var shape = context.shape, source = context.source;
  189. return getNewShapePosition(source, shape);
  190. });
  191. eventBus.on("autoPlace.end", function(event) {
  192. canvas.scrollToElement(event.shape);
  193. });
  194. this.append = function(source, shape, hints) {
  195. eventBus.fire("autoPlace.start", {
  196. source,
  197. shape
  198. });
  199. var position = eventBus.fire("autoPlace", {
  200. source,
  201. shape
  202. });
  203. var newShape = modeling.appendShape(source, shape, position, source.parent, hints);
  204. eventBus.fire("autoPlace.end", {
  205. source,
  206. shape: newShape
  207. });
  208. return newShape;
  209. };
  210. }
  211. AutoPlace.$inject = [
  212. "eventBus",
  213. "modeling",
  214. "canvas"
  215. ];
  216. function getNewShapePosition(source, element, hints) {
  217. if (!hints) {
  218. hints = {};
  219. }
  220. var distance = hints.defaultDistance || DEFAULT_DISTANCE;
  221. var sourceMid = getMid(source), sourceTrbl = asTRBL(source);
  222. return {
  223. x: sourceTrbl.right + distance + element.width / 2,
  224. y: sourceMid.y
  225. };
  226. }
  227. // node_modules/.pnpm/diagram-js@13.4.0/node_modules/diagram-js/lib/features/auto-place/AutoPlaceSelectionBehavior.js
  228. function AutoPlaceSelectionBehavior(eventBus, selection) {
  229. eventBus.on("autoPlace.end", 500, function(e) {
  230. selection.select(e.shape);
  231. });
  232. }
  233. AutoPlaceSelectionBehavior.$inject = [
  234. "eventBus",
  235. "selection"
  236. ];
  237. // node_modules/.pnpm/diagram-js@13.4.0/node_modules/diagram-js/lib/features/auto-place/index.js
  238. var auto_place_default = {
  239. __init__: ["autoPlaceSelectionBehavior"],
  240. autoPlace: ["type", AutoPlace],
  241. autoPlaceSelectionBehavior: ["type", AutoPlaceSelectionBehavior]
  242. };
  243. // node_modules/.pnpm/bpmn-js@16.3.2/node_modules/bpmn-js/lib/features/auto-place/BpmnAutoPlaceUtil.js
  244. function getNewShapePosition2(source, element) {
  245. if (is(element, "bpmn:TextAnnotation")) {
  246. return getTextAnnotationPosition(source, element);
  247. }
  248. if (isAny(element, ["bpmn:DataObjectReference", "bpmn:DataStoreReference"])) {
  249. return getDataElementPosition(source, element);
  250. }
  251. if (is(element, "bpmn:FlowNode")) {
  252. return getFlowNodePosition(source, element);
  253. }
  254. }
  255. function getFlowNodePosition(source, element) {
  256. var sourceTrbl = asTRBL(source);
  257. var sourceMid = getMid(source);
  258. var horizontalDistance = getConnectedDistance(source, {
  259. filter: function(connection) {
  260. return is(connection, "bpmn:SequenceFlow");
  261. }
  262. });
  263. var margin = 30, minDistance = 80, orientation = "left";
  264. if (is(source, "bpmn:BoundaryEvent")) {
  265. orientation = getOrientation(source, source.host, -25);
  266. if (orientation.indexOf("top") !== -1) {
  267. margin *= -1;
  268. }
  269. }
  270. var position = {
  271. x: sourceTrbl.right + horizontalDistance + element.width / 2,
  272. y: sourceMid.y + getVerticalDistance(orientation, minDistance)
  273. };
  274. var nextPositionDirection = {
  275. y: {
  276. margin,
  277. minDistance
  278. }
  279. };
  280. return findFreePosition(source, element, position, generateGetNextPosition(nextPositionDirection));
  281. }
  282. function getVerticalDistance(orientation, minDistance) {
  283. if (orientation.includes("top")) {
  284. return -1 * minDistance;
  285. } else if (orientation.includes("bottom")) {
  286. return minDistance;
  287. } else {
  288. return 0;
  289. }
  290. }
  291. function getTextAnnotationPosition(source, element) {
  292. var sourceTrbl = asTRBL(source);
  293. var position = {
  294. x: sourceTrbl.right + element.width / 2,
  295. y: sourceTrbl.top - 50 - element.height / 2
  296. };
  297. if (isConnection(source)) {
  298. position = getMid(source);
  299. position.x += 100;
  300. position.y -= 50;
  301. }
  302. var nextPositionDirection = {
  303. y: {
  304. margin: -30,
  305. minDistance: 20
  306. }
  307. };
  308. return findFreePosition(source, element, position, generateGetNextPosition(nextPositionDirection));
  309. }
  310. function getDataElementPosition(source, element) {
  311. var sourceTrbl = asTRBL(source);
  312. var position = {
  313. x: sourceTrbl.right - 10 + element.width / 2,
  314. y: sourceTrbl.bottom + 40 + element.width / 2
  315. };
  316. var nextPositionDirection = {
  317. x: {
  318. margin: 30,
  319. minDistance: 30
  320. }
  321. };
  322. return findFreePosition(source, element, position, generateGetNextPosition(nextPositionDirection));
  323. }
  324. // node_modules/.pnpm/bpmn-js@16.3.2/node_modules/bpmn-js/lib/features/auto-place/BpmnAutoPlace.js
  325. function AutoPlace2(eventBus) {
  326. eventBus.on("autoPlace", function(context) {
  327. var shape = context.shape, source = context.source;
  328. return getNewShapePosition2(source, shape);
  329. });
  330. }
  331. AutoPlace2.$inject = ["eventBus"];
  332. // node_modules/.pnpm/bpmn-js@16.3.2/node_modules/bpmn-js/lib/features/auto-place/index.js
  333. var auto_place_default2 = {
  334. __depends__: [auto_place_default],
  335. __init__: ["bpmnAutoPlace"],
  336. bpmnAutoPlace: ["type", AutoPlace2]
  337. };
  338. export {
  339. getNewShapePosition2 as getNewShapePosition,
  340. auto_place_default2 as auto_place_default
  341. };
  342. //# sourceMappingURL=chunk-YGL7V3UZ.js.map