chunk-PSXVIVF4.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import {
  2. isLabel
  3. } from "./chunk-RL3RINWF.js";
  4. import {
  5. is
  6. } from "./chunk-L5SG54UC.js";
  7. import {
  8. assign
  9. } from "./chunk-4AK4GF4H.js";
  10. // node_modules/.pnpm/bpmn-js@16.3.2/node_modules/bpmn-js/lib/util/LabelUtil.js
  11. var DEFAULT_LABEL_SIZE = {
  12. width: 90,
  13. height: 20
  14. };
  15. var FLOW_LABEL_INDENT = 15;
  16. function isLabelExternal(semantic) {
  17. return is(semantic, "bpmn:Event") || is(semantic, "bpmn:Gateway") || is(semantic, "bpmn:DataStoreReference") || is(semantic, "bpmn:DataObjectReference") || is(semantic, "bpmn:DataInput") || is(semantic, "bpmn:DataOutput") || is(semantic, "bpmn:SequenceFlow") || is(semantic, "bpmn:MessageFlow") || is(semantic, "bpmn:Group");
  18. }
  19. function hasExternalLabel(element) {
  20. return isLabel(element.label);
  21. }
  22. function getFlowLabelPosition(waypoints) {
  23. var mid = waypoints.length / 2 - 1;
  24. var first = waypoints[Math.floor(mid)];
  25. var second = waypoints[Math.ceil(mid + 0.01)];
  26. var position = getWaypointsMid(waypoints);
  27. var angle = Math.atan((second.y - first.y) / (second.x - first.x));
  28. var x = position.x, y = position.y;
  29. if (Math.abs(angle) < Math.PI / 2) {
  30. y -= FLOW_LABEL_INDENT;
  31. } else {
  32. x += FLOW_LABEL_INDENT;
  33. }
  34. return { x, y };
  35. }
  36. function getWaypointsMid(waypoints) {
  37. var mid = waypoints.length / 2 - 1;
  38. var first = waypoints[Math.floor(mid)];
  39. var second = waypoints[Math.ceil(mid + 0.01)];
  40. return {
  41. x: first.x + (second.x - first.x) / 2,
  42. y: first.y + (second.y - first.y) / 2
  43. };
  44. }
  45. function getExternalLabelMid(element) {
  46. if (element.waypoints) {
  47. return getFlowLabelPosition(element.waypoints);
  48. } else if (is(element, "bpmn:Group")) {
  49. return {
  50. x: element.x + element.width / 2,
  51. y: element.y + DEFAULT_LABEL_SIZE.height / 2
  52. };
  53. } else {
  54. return {
  55. x: element.x + element.width / 2,
  56. y: element.y + element.height + DEFAULT_LABEL_SIZE.height / 2
  57. };
  58. }
  59. }
  60. function getExternalLabelBounds(di, element) {
  61. var mid, size, bounds, label = di.label;
  62. if (label && label.bounds) {
  63. bounds = label.bounds;
  64. size = {
  65. width: Math.max(DEFAULT_LABEL_SIZE.width, bounds.width),
  66. height: bounds.height
  67. };
  68. mid = {
  69. x: bounds.x + bounds.width / 2,
  70. y: bounds.y + bounds.height / 2
  71. };
  72. } else {
  73. mid = getExternalLabelMid(element);
  74. size = DEFAULT_LABEL_SIZE;
  75. }
  76. return assign({
  77. x: mid.x - size.width / 2,
  78. y: mid.y - size.height / 2
  79. }, size);
  80. }
  81. function getLabelAttr(semantic) {
  82. if (is(semantic, "bpmn:FlowElement") || is(semantic, "bpmn:Participant") || is(semantic, "bpmn:Lane") || is(semantic, "bpmn:SequenceFlow") || is(semantic, "bpmn:MessageFlow") || is(semantic, "bpmn:DataInput") || is(semantic, "bpmn:DataOutput")) {
  83. return "name";
  84. }
  85. if (is(semantic, "bpmn:TextAnnotation")) {
  86. return "text";
  87. }
  88. if (is(semantic, "bpmn:Group")) {
  89. return "categoryValueRef";
  90. }
  91. }
  92. function getCategoryValue(semantic) {
  93. var categoryValueRef = semantic["categoryValueRef"];
  94. if (!categoryValueRef) {
  95. return "";
  96. }
  97. return categoryValueRef.value || "";
  98. }
  99. function getLabel(element) {
  100. var semantic = element.businessObject, attr = getLabelAttr(semantic);
  101. if (attr) {
  102. if (attr === "categoryValueRef") {
  103. return getCategoryValue(semantic);
  104. }
  105. return semantic[attr] || "";
  106. }
  107. }
  108. function setLabel(element, text) {
  109. var semantic = element.businessObject, attr = getLabelAttr(semantic);
  110. if (attr) {
  111. if (attr === "categoryValueRef") {
  112. semantic["categoryValueRef"].value = text;
  113. } else {
  114. semantic[attr] = text;
  115. }
  116. }
  117. return element;
  118. }
  119. export {
  120. DEFAULT_LABEL_SIZE,
  121. FLOW_LABEL_INDENT,
  122. isLabelExternal,
  123. hasExternalLabel,
  124. getFlowLabelPosition,
  125. getWaypointsMid,
  126. getExternalLabelMid,
  127. getExternalLabelBounds,
  128. getLabel,
  129. setLabel
  130. };
  131. //# sourceMappingURL=chunk-PSXVIVF4.js.map