chunk-LSRYXWJD.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import {
  2. attr,
  3. create
  4. } from "./chunk-IQOBXLIK.js";
  5. import {
  6. getDi
  7. } from "./chunk-L5SG54UC.js";
  8. import {
  9. has,
  10. isNumber,
  11. some
  12. } from "./chunk-4AK4GF4H.js";
  13. // node_modules/.pnpm/diagram-js@13.4.0/node_modules/diagram-js/lib/util/RenderUtil.js
  14. function componentsToPath(elements) {
  15. return elements.flat().join(",").replace(/,?([A-z]),?/g, "$1");
  16. }
  17. function move(point) {
  18. return ["M", point.x, point.y];
  19. }
  20. function lineTo(point) {
  21. return ["L", point.x, point.y];
  22. }
  23. function curveTo(p1, p2, p3) {
  24. return ["C", p1.x, p1.y, p2.x, p2.y, p3.x, p3.y];
  25. }
  26. function drawPath(waypoints, cornerRadius) {
  27. const pointCount = waypoints.length;
  28. const path = [move(waypoints[0])];
  29. for (let i = 1; i < pointCount; i++) {
  30. const pointBefore = waypoints[i - 1];
  31. const point = waypoints[i];
  32. const pointAfter = waypoints[i + 1];
  33. if (!pointAfter || !cornerRadius) {
  34. path.push(lineTo(point));
  35. continue;
  36. }
  37. const effectiveRadius = Math.min(
  38. cornerRadius,
  39. vectorLength(point.x - pointBefore.x, point.y - pointBefore.y),
  40. vectorLength(pointAfter.x - point.x, pointAfter.y - point.y)
  41. );
  42. if (!effectiveRadius) {
  43. path.push(lineTo(point));
  44. continue;
  45. }
  46. const beforePoint = getPointAtLength(point, pointBefore, effectiveRadius);
  47. const beforePoint2 = getPointAtLength(point, pointBefore, effectiveRadius * 0.5);
  48. const afterPoint = getPointAtLength(point, pointAfter, effectiveRadius);
  49. const afterPoint2 = getPointAtLength(point, pointAfter, effectiveRadius * 0.5);
  50. path.push(lineTo(beforePoint));
  51. path.push(curveTo(beforePoint2, afterPoint2, afterPoint));
  52. }
  53. return path;
  54. }
  55. function getPointAtLength(start, end, length) {
  56. const deltaX = end.x - start.x;
  57. const deltaY = end.y - start.y;
  58. const totalLength = vectorLength(deltaX, deltaY);
  59. const percent = length / totalLength;
  60. return {
  61. x: start.x + deltaX * percent,
  62. y: start.y + deltaY * percent
  63. };
  64. }
  65. function vectorLength(x, y) {
  66. return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
  67. }
  68. function createLine(points, attrs, radius) {
  69. if (isNumber(attrs)) {
  70. radius = attrs;
  71. attrs = null;
  72. }
  73. if (!attrs) {
  74. attrs = {};
  75. }
  76. const line = create("path", attrs);
  77. if (isNumber(radius)) {
  78. line.dataset.cornerRadius = String(radius);
  79. }
  80. return updateLine(line, points);
  81. }
  82. function updateLine(gfx, points) {
  83. const cornerRadius = parseInt(gfx.dataset.cornerRadius, 10) || 0;
  84. attr(gfx, {
  85. d: componentsToPath(drawPath(points, cornerRadius))
  86. });
  87. return gfx;
  88. }
  89. // node_modules/.pnpm/bpmn-js@16.3.2/node_modules/bpmn-js/lib/draw/BpmnRenderUtil.js
  90. var black = "hsl(225, 10%, 15%)";
  91. var white = "white";
  92. function isTypedEvent(event, eventDefinitionType) {
  93. return some(event.eventDefinitions, function(definition) {
  94. return definition.$type === eventDefinitionType;
  95. });
  96. }
  97. function isThrowEvent(event) {
  98. return event.$type === "bpmn:IntermediateThrowEvent" || event.$type === "bpmn:EndEvent";
  99. }
  100. function isCollection(element) {
  101. var dataObject = element.dataObjectRef;
  102. return element.isCollection || dataObject && dataObject.isCollection;
  103. }
  104. function getFillColor(element, defaultColor, overrideColor) {
  105. var di = getDi(element);
  106. return overrideColor || di.get("color:background-color") || di.get("bioc:fill") || defaultColor || white;
  107. }
  108. function getStrokeColor(element, defaultColor, overrideColor) {
  109. var di = getDi(element);
  110. return overrideColor || di.get("color:border-color") || di.get("bioc:stroke") || defaultColor || black;
  111. }
  112. function getLabelColor(element, defaultColor, defaultStrokeColor, overrideColor) {
  113. var di = getDi(element), label = di.get("label");
  114. return overrideColor || label && label.get("color:color") || defaultColor || getStrokeColor(element, defaultStrokeColor);
  115. }
  116. function getCirclePath(shape) {
  117. var cx = shape.x + shape.width / 2, cy = shape.y + shape.height / 2, radius = shape.width / 2;
  118. var circlePath = [
  119. ["M", cx, cy],
  120. ["m", 0, -radius],
  121. ["a", radius, radius, 0, 1, 1, 0, 2 * radius],
  122. ["a", radius, radius, 0, 1, 1, 0, -2 * radius],
  123. ["z"]
  124. ];
  125. return componentsToPath(circlePath);
  126. }
  127. function getRoundRectPath(shape, borderRadius) {
  128. var x = shape.x, y = shape.y, width = shape.width, height = shape.height;
  129. var roundRectPath = [
  130. ["M", x + borderRadius, y],
  131. ["l", width - borderRadius * 2, 0],
  132. ["a", borderRadius, borderRadius, 0, 0, 1, borderRadius, borderRadius],
  133. ["l", 0, height - borderRadius * 2],
  134. ["a", borderRadius, borderRadius, 0, 0, 1, -borderRadius, borderRadius],
  135. ["l", borderRadius * 2 - width, 0],
  136. ["a", borderRadius, borderRadius, 0, 0, 1, -borderRadius, -borderRadius],
  137. ["l", 0, borderRadius * 2 - height],
  138. ["a", borderRadius, borderRadius, 0, 0, 1, borderRadius, -borderRadius],
  139. ["z"]
  140. ];
  141. return componentsToPath(roundRectPath);
  142. }
  143. function getDiamondPath(shape) {
  144. var width = shape.width, height = shape.height, x = shape.x, y = shape.y, halfWidth = width / 2, halfHeight = height / 2;
  145. var diamondPath = [
  146. ["M", x + halfWidth, y],
  147. ["l", halfWidth, halfHeight],
  148. ["l", -halfWidth, halfHeight],
  149. ["l", -halfWidth, -halfHeight],
  150. ["z"]
  151. ];
  152. return componentsToPath(diamondPath);
  153. }
  154. function getRectPath(shape) {
  155. var x = shape.x, y = shape.y, width = shape.width, height = shape.height;
  156. var rectPath = [
  157. ["M", x, y],
  158. ["l", width, 0],
  159. ["l", 0, height],
  160. ["l", -width, 0],
  161. ["z"]
  162. ];
  163. return componentsToPath(rectPath);
  164. }
  165. function getBounds(bounds, overrides = {}) {
  166. return {
  167. width: getWidth(bounds, overrides),
  168. height: getHeight(bounds, overrides)
  169. };
  170. }
  171. function getWidth(bounds, overrides = {}) {
  172. return has(overrides, "width") ? overrides.width : bounds.width;
  173. }
  174. function getHeight(bounds, overrides = {}) {
  175. return has(overrides, "height") ? overrides.height : bounds.height;
  176. }
  177. export {
  178. componentsToPath,
  179. createLine,
  180. updateLine,
  181. black,
  182. white,
  183. isTypedEvent,
  184. isThrowEvent,
  185. isCollection,
  186. getFillColor,
  187. getStrokeColor,
  188. getLabelColor,
  189. getCirclePath,
  190. getRoundRectPath,
  191. getDiamondPath,
  192. getRectPath,
  193. getBounds,
  194. getWidth,
  195. getHeight
  196. };
  197. //# sourceMappingURL=chunk-LSRYXWJD.js.map