@uipath/maestro-sdk 1.206.0-preview.306 → 1.207.0-preview.307

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/THIRD-PARTY-NOTICES.md +162 -7
  2. package/dist/bpmn-layout/index.js +994 -18
  3. package/dist/bpmn-packaging/index.js +331 -236
  4. package/dist/bpmn-validation/project-validator.js +611 -317
  5. package/dist/connector-spec/index.js +22021 -4319
  6. package/dist/debug-http-client.js +437 -178
  7. package/dist/debug-service.js +786 -215
  8. package/dist/index.js +31244 -5433
  9. package/dist/json-input.js +438 -174
  10. package/dist/manifest/bpmn-spec.js +214 -231
  11. package/dist/registry/command.js +21815 -3997
  12. package/dist/registry/snapshot.js +380 -174
  13. package/dist/shared-commands/index.js +14899 -1881
  14. package/dist/shared-utils.js +441 -174
  15. package/dist/src/binding-id.d.ts +20 -0
  16. package/dist/src/bpmn-layout/index.d.ts +1 -0
  17. package/dist/src/bpmn-layout/layout.d.ts +31 -0
  18. package/dist/src/bpmn-layout/types.d.ts +11 -0
  19. package/dist/src/bpmn-layout/update.d.ts +40 -0
  20. package/dist/src/bpmn-packaging/binding-resources.d.ts +3 -1
  21. package/dist/src/bpmn-packaging/entity-resources.d.ts +26 -0
  22. package/dist/src/bpmn-packaging/index.d.ts +1 -0
  23. package/dist/src/bpmn-packaging/studio-web-migrations.d.ts +23 -0
  24. package/dist/src/bpmn-packaging/taggable-variables.d.ts +19 -0
  25. package/dist/src/bpmn-packaging/types.d.ts +1 -0
  26. package/dist/src/bpmn-validation/project-validator.d.ts +5 -1
  27. package/dist/src/debug-http-client.d.ts +5 -1
  28. package/dist/src/debug-poll-retry.d.ts +6 -1
  29. package/dist/src/debug-service.d.ts +96 -7
  30. package/dist/src/folder-scope.d.ts +6 -0
  31. package/dist/src/index.d.ts +3 -3
  32. package/dist/src/manifest/bpmn-spec.d.ts +11 -0
  33. package/dist/src/manifest/types.d.ts +25 -1
  34. package/dist/src/registry/index.d.ts +2 -2
  35. package/dist/src/registry/integration-service-fetcher.d.ts +6 -0
  36. package/dist/src/registry/maestro-runtime.d.ts +2 -0
  37. package/dist/src/registry/node-storage.d.ts +29 -3
  38. package/dist/src/registry/node-sync-service.d.ts +64 -5
  39. package/dist/src/row-window.d.ts +1 -0
  40. package/dist/src/shared-commands/debug-folder.d.ts +19 -0
  41. package/dist/src/shared-commands/folder-key.d.ts +15 -0
  42. package/dist/src/shared-commands/incidents.d.ts +3 -1
  43. package/dist/src/shared-commands/index.d.ts +4 -0
  44. package/dist/src/shared-commands/instances.d.ts +2 -4
  45. package/dist/src/shared-commands/process.d.ts +3 -5
  46. package/dist/src/shared-commands/release-pick.d.ts +27 -0
  47. package/dist/src/shared-commands/variable-tags-commands.d.ts +37 -0
  48. package/dist/src/shared-commands/variable-tags-payload.d.ts +42 -0
  49. package/dist/src/shared-commands/variable-tags-release.d.ts +15 -0
  50. package/dist/src/shared-commands/variable-tags-selection.d.ts +113 -0
  51. package/dist/src/shared-utils.d.ts +2 -0
  52. package/dist/src/studio-catalog.d.ts +9 -0
  53. package/dist/src/timestamps.d.ts +13 -0
  54. package/dist/src/types.d.ts +2 -0
  55. package/dist/src/variable-tags/case-catalog.d.ts +8 -0
  56. package/dist/src/variable-tags/catalog-types.d.ts +57 -0
  57. package/dist/src/variable-tags/schema-leaves.d.ts +28 -0
  58. package/dist/src/variables-patch.d.ts +2 -0
  59. package/dist/studio-catalog.js +439 -180
  60. package/dist/with-pims-call.js +490 -182
  61. package/package.json +2 -2
@@ -96078,7 +96078,9 @@ Consider installing the package or pass your own 'workerFactory' to ELK's constr
96078
96078
  centerY = (sourceGapPoint.y + targetGapPoint.y) / 2;
96079
96079
  }
96080
96080
  }
96081
- const pathPoints = [source, { x: sourceGapped.x + sourceGapOffset.x, y: sourceGapped.y + sourceGapOffset.y }, ...points, { x: targetGapped.x + targetGapOffset.x, y: targetGapped.y + targetGapOffset.y }, target];
96081
+ const gappedSource = { x: sourceGapped.x + sourceGapOffset.x, y: sourceGapped.y + sourceGapOffset.y };
96082
+ const gappedTarget = { x: targetGapped.x + targetGapOffset.x, y: targetGapped.y + targetGapOffset.y };
96083
+ const pathPoints = [source, ...gappedSource.x !== points[0].x || gappedSource.y !== points[0].y ? [gappedSource] : [], ...points, ...gappedTarget.x !== points[points.length - 1].x || gappedTarget.y !== points[points.length - 1].y ? [gappedTarget] : [], target];
96082
96084
  return [pathPoints, centerX, centerY, defaultOffsetX, defaultOffsetY];
96083
96085
  }
96084
96086
  function getBend(a, b, c, size) {
@@ -96098,19 +96100,14 @@ Consider installing the package or pass your own 'workerFactory' to ELK's constr
96098
96100
  }
96099
96101
  function getSmoothStepPath({ sourceX, sourceY, sourcePosition = Position.Bottom, targetX, targetY, targetPosition = Position.Top, borderRadius = 5, centerX, centerY, offset = 20, stepPosition = 0.5 }) {
96100
96102
  const [points, labelX, labelY, offsetX, offsetY] = getPoints({ source: { x: sourceX, y: sourceY }, sourcePosition, target: { x: targetX, y: targetY }, targetPosition, center: { x: centerX, y: centerY }, offset, stepPosition });
96101
- const path = points.reduce((res, p, i) => {
96102
- let segment = "";
96103
- if (i > 0 && i < points.length - 1) {
96104
- segment = getBend(points[i - 1], p, points[i + 1], borderRadius);
96105
- } else {
96106
- segment = `${i === 0 ? "M" : "L"}${p.x} ${p.y}`;
96107
- }
96108
- res += segment;
96109
- return res;
96110
- }, "");
96103
+ let path = `M${points[0].x} ${points[0].y}`;
96104
+ for (let i = 1;i < points.length - 1; i++) {
96105
+ path += getBend(points[i - 1], points[i], points[i + 1], borderRadius);
96106
+ }
96107
+ path += `L${points[points.length - 1].x} ${points[points.length - 1].y}`;
96111
96108
  return [path, labelX, labelY, offsetX, offsetY];
96112
96109
  }
96113
- var defaultOptions = { nodeOrigin: [0, 0], nodeExtent: infiniteExtent, elevateNodesOnSelect: true, defaults: {} };
96110
+ var defaultOptions = { nodeOrigin: [0, 0], nodeExtent: infiniteExtent, elevateNodesOnSelect: true, zIndexMode: "basic", defaults: {} };
96114
96111
  var adoptUserNodesDefaultOptions = { ...defaultOptions, checkEquality: true };
96115
96112
  var ResizeControlVariant;
96116
96113
  (function(ResizeControlVariant2) {
@@ -103644,13 +103641,15 @@ var ProjectDimensions = {
103644
103641
  SolutionKey: "SolutionKey",
103645
103642
  SolutionProjectKey: "SolutionProjectKey",
103646
103643
  SolutionIdentityStatus: "SolutionIdentityStatus",
103647
- PreviousSolutionKey: "PreviousSolutionKey"
103644
+ PreviousSolutionKey: "PreviousSolutionKey",
103645
+ PreviousProjectKey: "PreviousProjectKey"
103648
103646
  };
103649
103647
  var GUID_KEY_DIMENSIONS = new Set([
103650
103648
  ProjectDimensions.ProjectKey,
103651
103649
  ProjectDimensions.SolutionKey,
103652
103650
  ProjectDimensions.SolutionProjectKey,
103653
- ProjectDimensions.PreviousSolutionKey
103651
+ ProjectDimensions.PreviousSolutionKey,
103652
+ ProjectDimensions.PreviousProjectKey
103654
103653
  ]);
103655
103654
  var ShipDimensions = {
103656
103655
  ShipKind: "ShipKind",
@@ -103749,7 +103748,7 @@ var CURATED_DIMENSIONS = new Set([
103749
103748
  ...Object.values(ProjectDimensions)
103750
103749
  ]);
103751
103750
 
103752
- // ../common/src/telemetry/pseudonymize.ts
103751
+ // ../common/src/sha256.ts
103753
103752
  var SHA256_K = new Uint32Array([
103754
103753
  1116352408,
103755
103754
  1899447441,
@@ -104089,7 +104088,7 @@ function rootElementName(xml) {
104089
104088
  function escapeRegExp(value) {
104090
104089
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
104091
104090
  }
104092
- var ATTRIBUTES = `(?:[^>"']|"[^"]*"|'[^']*')*`;
104091
+ var ATTRIBUTES = `(?:[^>"'/]|/(?!>)|"[^"]*"|'[^']*')*`;
104093
104092
  function declaredOn(tag, attr) {
104094
104093
  const declaration = new RegExp(`\\b${escapeRegExp(attr)}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`).exec(tag);
104095
104094
  return declaration?.[1] ?? declaration?.[2];
@@ -104655,11 +104654,988 @@ async function applyBpmnLayout(xml) {
104655
104654
  }
104656
104655
  return layout;
104657
104656
  }
104657
+ // src/bpmn-layout/update.ts
104658
+ var DOCK_SLACK = 5;
104659
+ function readAttr(tag, name) {
104660
+ const match = new RegExp(`\\s${escapeRegExp(name)}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`).exec(tag);
104661
+ return match ? match[1] ?? match[2] : undefined;
104662
+ }
104663
+ function readBox(tag) {
104664
+ const box = {
104665
+ x: Number(readAttr(tag, "x")),
104666
+ y: Number(readAttr(tag, "y")),
104667
+ w: Number(readAttr(tag, "width")),
104668
+ h: Number(readAttr(tag, "height"))
104669
+ };
104670
+ return Object.values(box).every(Number.isFinite) ? box : undefined;
104671
+ }
104672
+ function readPoint(tag) {
104673
+ const point = {
104674
+ x: Number(readAttr(tag, "x")),
104675
+ y: Number(readAttr(tag, "y"))
104676
+ };
104677
+ return Number.isFinite(point.x) && Number.isFinite(point.y) ? point : undefined;
104678
+ }
104679
+ function formatNumber(value) {
104680
+ return Number.isInteger(value) ? String(value) : String(Math.round(value * 100) / 100);
104681
+ }
104682
+ function rewriteTag(tag, values) {
104683
+ let result = tag;
104684
+ for (const [name, value] of Object.entries(values)) {
104685
+ const pattern = new RegExp(`(\\s${escapeRegExp(name)}\\s*=\\s*)(["'])([^"']*)\\2`);
104686
+ const match = pattern.exec(result);
104687
+ if (!match || Number(match[3]) === value)
104688
+ continue;
104689
+ result = result.replace(pattern, `$1$2${formatNumber(value)}$2`);
104690
+ }
104691
+ return result;
104692
+ }
104693
+ function elementEnd(masked, name, tagEnd, selfClosing, limit) {
104694
+ if (selfClosing)
104695
+ return tagEnd;
104696
+ const close = masked.indexOf(`</${name}>`, tagEnd);
104697
+ return close === -1 || close > limit ? -1 : close + name.length + 3;
104698
+ }
104699
+ function tagsIn(masked, xml, local, span) {
104700
+ const pattern = new RegExp(`<((?:[\\w-]+:)?${local})\\b${ATTRIBUTES}/?>`, "g");
104701
+ pattern.lastIndex = span.start;
104702
+ const tags = [];
104703
+ for (;; ) {
104704
+ const match = pattern.exec(masked);
104705
+ if (!match || match.index >= span.end)
104706
+ break;
104707
+ const end = match.index + match[0].length;
104708
+ tags.push({
104709
+ start: match.index,
104710
+ end,
104711
+ text: xml.slice(match.index, end),
104712
+ name: match[1]
104713
+ });
104714
+ }
104715
+ return tags;
104716
+ }
104717
+ function readEntry(masked, xml, kind, openTag, span, bodyStart) {
104718
+ const element = readAttr(openTag, "bpmnElement");
104719
+ if (!element)
104720
+ return;
104721
+ const entry = {
104722
+ kind,
104723
+ element,
104724
+ ...span,
104725
+ expanded: readAttr(openTag, "isExpanded") === "true",
104726
+ waypoints: []
104727
+ };
104728
+ const body = { start: bodyStart, end: span.end };
104729
+ const labelOpen = new RegExp(`<((?:[\\w-]+:)?BPMNLabel)\\b${ATTRIBUTES}(/?)>`, "g");
104730
+ labelOpen.lastIndex = bodyStart;
104731
+ const label = labelOpen.exec(masked);
104732
+ if (label && label.index < span.end) {
104733
+ const tagEnd = label.index + label[0].length;
104734
+ const end = elementEnd(masked, label[1], tagEnd, label[2] === "/", span.end);
104735
+ if (end !== -1)
104736
+ entry.label = { start: label.index, end };
104737
+ }
104738
+ const inLabel = (offset) => entry.label !== undefined && offset >= entry.label.start && offset < entry.label.end;
104739
+ for (const tag of tagsIn(masked, xml, "Bounds", body)) {
104740
+ const box = readBox(tag.text);
104741
+ if (!box)
104742
+ continue;
104743
+ if (inLabel(tag.start)) {
104744
+ if (entry.label)
104745
+ entry.label.bounds = { ...tag, box };
104746
+ } else {
104747
+ entry.bounds ??= { ...tag, box };
104748
+ }
104749
+ }
104750
+ for (const tag of tagsIn(masked, xml, "waypoint", body)) {
104751
+ const point = readPoint(tag.text);
104752
+ if (point && !inLabel(tag.start)) {
104753
+ entry.waypoints.push({ ...tag, point });
104754
+ }
104755
+ }
104756
+ return entry;
104757
+ }
104758
+ function indentBefore(xml, offset) {
104759
+ let start = offset;
104760
+ while (start > 0 && (xml[start - 1] === " " || xml[start - 1] === "\t")) {
104761
+ start--;
104762
+ }
104763
+ return xml[start - 1] === `
104764
+ ` ? xml.slice(start, offset) : "";
104765
+ }
104766
+ function parseDi(xml) {
104767
+ const masked = maskComments(xml);
104768
+ const di = {
104769
+ planes: [],
104770
+ shapePrefix: "bpmndi:",
104771
+ ids: new Set([...masked.matchAll(/\sid\s*=\s*(?:"([^"]*)"|'([^']*)')/g)].map((match) => match[1] ?? match[2]))
104772
+ };
104773
+ const planeOpen = new RegExp(`<((?:[\\w-]+:)?BPMNPlane)\\b${ATTRIBUTES}(/?)>`, "g");
104774
+ for (const open of masked.matchAll(planeOpen)) {
104775
+ if (open[2] === "/")
104776
+ continue;
104777
+ const name = open[1];
104778
+ const bodyStart = open.index + open[0].length;
104779
+ const close = masked.indexOf(`</${name}>`, bodyStart);
104780
+ if (close === -1)
104781
+ continue;
104782
+ di.shapePrefix = name.slice(0, -"BPMNPlane".length);
104783
+ const plane = {
104784
+ element: readAttr(open[0], "bpmnElement"),
104785
+ close,
104786
+ indent: "",
104787
+ entries: []
104788
+ };
104789
+ const entryOpen = new RegExp(`<((?:[\\w-]+:)?(BPMNShape|BPMNEdge))\\b${ATTRIBUTES}(/?)>`, "g");
104790
+ entryOpen.lastIndex = bodyStart;
104791
+ for (;; ) {
104792
+ const match = entryOpen.exec(masked);
104793
+ if (!match || match.index >= close)
104794
+ break;
104795
+ const tagEnd = match.index + match[0].length;
104796
+ const end = elementEnd(masked, match[1], tagEnd, match[3] === "/", close);
104797
+ if (end === -1)
104798
+ break;
104799
+ const entry = readEntry(masked, xml, match[2] === "BPMNShape" ? "shape" : "edge", xml.slice(match.index, tagEnd), { start: match.index, end }, tagEnd);
104800
+ if (entry) {
104801
+ plane.entries.push(entry);
104802
+ plane.indent = indentBefore(xml, match.index) || plane.indent;
104803
+ }
104804
+ entryOpen.lastIndex = end;
104805
+ }
104806
+ di.planes.push(plane);
104807
+ }
104808
+ return di;
104809
+ }
104810
+ function collectIds(value, ids, seen) {
104811
+ if (value === null || typeof value !== "object" || seen.has(value))
104812
+ return;
104813
+ seen.add(value);
104814
+ if (Array.isArray(value)) {
104815
+ for (const item of value)
104816
+ collectIds(item, ids, seen);
104817
+ return;
104818
+ }
104819
+ const record = value;
104820
+ if (typeof record.id === "string")
104821
+ ids.add(record.id);
104822
+ for (const [key, child] of Object.entries(record)) {
104823
+ if (key.startsWith("$") || key === "diagrams")
104824
+ continue;
104825
+ collectIds(child, ids, seen);
104826
+ }
104827
+ }
104828
+ function collectLanes(laneSets, model) {
104829
+ for (const laneSet of laneSets ?? []) {
104830
+ for (const lane of laneSet.lanes ?? []) {
104831
+ collectLane(lane, model);
104832
+ }
104833
+ }
104834
+ }
104835
+ function collectLane(lane, model) {
104836
+ if (!lane.id)
104837
+ return;
104838
+ model.frames.add(lane.id);
104839
+ model.types.set(lane.id, "bpmn:Lane");
104840
+ for (const ref of lane.flowNodeRef ?? []) {
104841
+ if (ref.id)
104842
+ model.laneOf.set(ref.id, lane.id);
104843
+ }
104844
+ collectLanes(lane.childLaneSet ? [lane.childLaneSet] : [], model);
104845
+ }
104846
+ function collectScope(scope, container, model) {
104847
+ collectLanes(scope.laneSets, model);
104848
+ for (const element of [
104849
+ ...scope.flowElements ?? [],
104850
+ ...scope.artifacts ?? []
104851
+ ]) {
104852
+ const { id, $type: type } = element;
104853
+ if (!id || !type)
104854
+ continue;
104855
+ model.types.set(id, type);
104856
+ if (type === "bpmn:SequenceFlow" || type === "bpmn:Association") {
104857
+ const src = element.sourceRef?.id;
104858
+ const tgt = element.targetRef?.id;
104859
+ if (src && tgt)
104860
+ model.flows.set(id, { type, src, tgt });
104861
+ continue;
104862
+ }
104863
+ if (type === "bpmn:DataObject")
104864
+ continue;
104865
+ model.nodes.set(id, {
104866
+ type,
104867
+ container,
104868
+ attachedTo: element.attachedToRef?.id
104869
+ });
104870
+ if (element.$instanceOf?.("bpmn:SubProcess") === true || SUB_PROCESS_TYPES.has(type)) {
104871
+ collectScope(element, id, model);
104872
+ }
104873
+ }
104874
+ }
104875
+ function collectModel(root) {
104876
+ const model = {
104877
+ ids: new Set,
104878
+ nodes: new Map,
104879
+ flows: new Map,
104880
+ laneOf: new Map,
104881
+ frames: new Set,
104882
+ types: new Map,
104883
+ participantOf: new Map,
104884
+ collaborationOf: new Map
104885
+ };
104886
+ collectIds(root, model.ids, new Set);
104887
+ for (const element of root.rootElements ?? []) {
104888
+ if (element.$type === "bpmn:Process" && element.id) {
104889
+ collectScope(element, element.id, model);
104890
+ }
104891
+ if (element.$type === "bpmn:Collaboration" && element.id) {
104892
+ collectCollaboration(element, element.id, model);
104893
+ }
104894
+ }
104895
+ return model;
104896
+ }
104897
+ function collectCollaboration(element, id, model) {
104898
+ const collaboration = element;
104899
+ model.types.set(id, "bpmn:Collaboration");
104900
+ for (const participant of collaboration.participants ?? []) {
104901
+ if (!participant.id)
104902
+ continue;
104903
+ model.frames.add(participant.id);
104904
+ model.types.set(participant.id, "bpmn:Participant");
104905
+ const process = participant.processRef?.id;
104906
+ if (process) {
104907
+ model.participantOf.set(process, participant.id);
104908
+ model.collaborationOf.set(process, id);
104909
+ }
104910
+ }
104911
+ for (const flow of collaboration.messageFlows ?? []) {
104912
+ const src = flow.sourceRef?.id;
104913
+ const tgt = flow.targetRef?.id;
104914
+ if (flow.id && src && tgt) {
104915
+ model.types.set(flow.id, "bpmn:MessageFlow");
104916
+ model.flows.set(flow.id, { type: "bpmn:MessageFlow", src, tgt });
104917
+ }
104918
+ }
104919
+ }
104920
+ var isActivity = (type) => !EVENT_TYPES.has(type) && !GATEWAY_TYPES.has(type) && !ARTIFACT_TYPES.has(type);
104921
+ var overlaps = (a, b, marginX = 0, marginY = 0) => a.x < b.x + b.w + marginX && b.x < a.x + a.w + marginX && a.y < b.y + b.h + marginY && b.y < a.y + a.h + marginY;
104922
+ var contains = (box, point, slack) => point.x >= box.x - slack && point.x <= box.x + box.w + slack && point.y >= box.y - slack && point.y <= box.y + box.h + slack;
104923
+ var centre = (box) => ({
104924
+ x: box.x + box.w / 2,
104925
+ y: box.y + box.h / 2
104926
+ });
104927
+ function route(a, b) {
104928
+ const ay = a.y + a.h / 2;
104929
+ const by = b.y + b.h / 2;
104930
+ const round = (point) => ({
104931
+ x: Math.round(point.x),
104932
+ y: Math.round(point.y)
104933
+ });
104934
+ const sameRow = a.y < b.y + b.h && b.y < a.y + a.h;
104935
+ if (sameRow && b.x < a.x + a.w) {
104936
+ const self = a === b || sameBox(a, b);
104937
+ const sx = self ? a.x + a.w * 2 / 3 : a.x + a.w / 2;
104938
+ const tx = self ? a.x + a.w / 3 : b.x + b.w / 2;
104939
+ const below = Math.max(a.y + a.h, b.y + b.h) + V_GAP / 2;
104940
+ return [
104941
+ { x: sx, y: a.y + a.h },
104942
+ { x: sx, y: below },
104943
+ { x: tx, y: below },
104944
+ { x: tx, y: b.y + b.h }
104945
+ ].map(round);
104946
+ }
104947
+ if (b.x >= a.x + a.w) {
104948
+ const sx = a.x + a.w;
104949
+ const tx = b.x;
104950
+ if (Math.abs(ay - by) < 1) {
104951
+ return [round({ x: sx, y: ay }), round({ x: tx, y: by })];
104952
+ }
104953
+ const mx = (sx + tx) / 2;
104954
+ return [
104955
+ { x: sx, y: ay },
104956
+ { x: mx, y: ay },
104957
+ { x: mx, y: by },
104958
+ { x: tx, y: by }
104959
+ ].map(round);
104960
+ }
104961
+ const sx = a.x + a.w / 2;
104962
+ const tx = b.x + b.w / 2;
104963
+ const down = by > ay;
104964
+ const sy = down ? a.y + a.h : a.y;
104965
+ const ty = down ? b.y : b.y + b.h;
104966
+ const my = (sy + ty) / 2;
104967
+ return [
104968
+ { x: sx, y: sy },
104969
+ { x: sx, y: my },
104970
+ { x: tx, y: my },
104971
+ { x: tx, y: ty }
104972
+ ].map(round);
104973
+ }
104974
+ var SUB_PROCESS_SIZE = { w: 350, h: 200 };
104975
+ var POOL_HEADER = 30;
104976
+
104977
+ class DiagramUpdate {
104978
+ di;
104979
+ model;
104980
+ shapes = new Map;
104981
+ edges = new Map;
104982
+ removed = [];
104983
+ added = [];
104984
+ unplaced = [];
104985
+ duplicate;
104986
+ frameTypes = new Set;
104987
+ drawn = new Set;
104988
+ constructor(di, model) {
104989
+ this.di = di;
104990
+ this.model = model;
104991
+ for (const plane of di.planes) {
104992
+ for (const entry of plane.entries) {
104993
+ if (!model.ids.has(entry.element)) {
104994
+ this.removed.push(entry);
104995
+ continue;
104996
+ }
104997
+ const seen = entry.kind === "shape" ? this.shapes.get(entry.element) : this.edges.get(entry.element);
104998
+ if (seen && seen.plane !== plane) {
104999
+ this.duplicate ??= entry.element;
105000
+ }
105001
+ if (entry.kind === "shape")
105002
+ this.drawn.add(entry.element);
105003
+ if (entry.kind === "shape" && entry.bounds) {
105004
+ this.shapes.set(entry.element, {
105005
+ plane,
105006
+ box: { ...entry.bounds.box },
105007
+ label: entry.label?.bounds ? { ...entry.label.bounds.box } : undefined,
105008
+ entry
105009
+ });
105010
+ if (model.frames.has(entry.element) || entry.expanded || model.types.get(entry.element) === "bpmn:Group") {
105011
+ this.frameTypes.add(entry.element);
105012
+ }
105013
+ } else if (entry.kind === "edge") {
105014
+ this.edges.set(entry.element, {
105015
+ plane,
105016
+ points: entry.waypoints.map((tag) => ({
105017
+ ...tag.point
105018
+ })),
105019
+ label: entry.label?.bounds ? { ...entry.label.bounds.box } : undefined,
105020
+ entry,
105021
+ rerouted: false
105022
+ });
105023
+ }
105024
+ }
105025
+ }
105026
+ }
105027
+ isFrame(id) {
105028
+ return this.frameTypes.has(id);
105029
+ }
105030
+ isExpanded(id) {
105031
+ const shape = id ? this.shapes.get(id) : undefined;
105032
+ return shape?.entry?.expanded === true || shape?.expanded === true;
105033
+ }
105034
+ opensAsFrame(id) {
105035
+ if (!SUB_PROCESS_TYPES.has(this.model.types.get(id) ?? "")) {
105036
+ return false;
105037
+ }
105038
+ return [...this.model.nodes.values()].some((node) => node.container === id);
105039
+ }
105040
+ sizeFor(id, plane) {
105041
+ if (this.opensAsFrame(id))
105042
+ return { ...SUB_PROCESS_SIZE };
105043
+ const type = this.model.types.get(id) ?? "";
105044
+ if (!isActivity(type))
105045
+ return nodeDims(type);
105046
+ const sizes = [...this.shapes].filter(([other, shape]) => shape.plane === plane && !this.isFrame(other) && isActivity(this.model.types.get(other) ?? "")).map(([, shape]) => shape.box);
105047
+ if (sizes.length === 0)
105048
+ return nodeDims(type);
105049
+ const median = (values) => values.sort((a, b) => a - b)[Math.floor(values.length / 2)];
105050
+ return {
105051
+ w: median(sizes.map((box) => box.w)),
105052
+ h: median(sizes.map((box) => box.h))
105053
+ };
105054
+ }
105055
+ ancestors(id) {
105056
+ const result = new Set;
105057
+ let current = id;
105058
+ while (current !== undefined) {
105059
+ const lane = this.model.laneOf.get(current);
105060
+ if (lane)
105061
+ result.add(lane);
105062
+ const participant = this.model.participantOf.get(current);
105063
+ if (participant)
105064
+ result.add(participant);
105065
+ current = this.model.nodes.get(current)?.container;
105066
+ if (current !== undefined)
105067
+ result.add(current);
105068
+ }
105069
+ return result;
105070
+ }
105071
+ ownFrames(id, plane) {
105072
+ return [...this.ancestors(id)].map((other) => this.shapes.get(other)).filter((shape) => shape !== undefined && shape.plane === plane).map((shape) => shape.box);
105073
+ }
105074
+ blockers(plane, box, id) {
105075
+ const around = this.ancestors(id);
105076
+ return [...this.shapes].filter(([other, shape]) => shape.plane === plane && other !== id && (!this.isFrame(other) || this.isExpanded(other) && !around.has(other)) && overlaps(shape.box, box, H_GAP / 2, 10)).map(([other, shape]) => [other, shape.box]);
105077
+ }
105078
+ framesAt(plane, point) {
105079
+ return [...this.shapes].filter(([id, shape]) => shape.plane === plane && this.isFrame(id) && this.model.types.get(id) !== "bpmn:Group" && contains(shape.box, point, 0)).map(([, shape]) => shape.box);
105080
+ }
105081
+ makeRoom(plane, axis, cut, size) {
105082
+ const extent = axis === "x" ? "w" : "h";
105083
+ const grows = (id, box) => this.isFrame(id) && box[axis] < cut && box[axis] + box[extent] > cut;
105084
+ const moving = new Set;
105085
+ for (const [id, shape] of this.shapes) {
105086
+ if (shape.plane !== plane)
105087
+ continue;
105088
+ const hostId = this.model.nodes.get(id)?.attachedTo;
105089
+ const host = hostId ? this.shapes.get(hostId) : undefined;
105090
+ const anchor = host ?? shape;
105091
+ if (anchor.box[axis] >= cut)
105092
+ moving.add(id);
105093
+ else if (hostId && host && grows(hostId, host.box) && shape.box[axis] + shape.box[extent] / 2 >= host.box[axis] + host.box[extent] - 1) {
105094
+ moving.add(id);
105095
+ }
105096
+ }
105097
+ for (const [id, shape] of this.shapes) {
105098
+ if (shape.plane !== plane)
105099
+ continue;
105100
+ if (moving.has(id)) {
105101
+ shape.box[axis] += size;
105102
+ if (shape.label)
105103
+ shape.label[axis] += size;
105104
+ } else if (this.isFrame(id) && shape.box[axis] + shape.box[extent] > cut) {
105105
+ shape.box[extent] += size;
105106
+ }
105107
+ }
105108
+ for (const edge of this.edges.values()) {
105109
+ if (edge.plane !== plane)
105110
+ continue;
105111
+ for (const point of edge.points) {
105112
+ if (point[axis] >= cut)
105113
+ point[axis] += size;
105114
+ }
105115
+ if (edge.label && edge.label[axis] >= cut)
105116
+ edge.label[axis] += size;
105117
+ }
105118
+ }
105119
+ planeFor(id) {
105120
+ const container = this.model.nodes.get(id)?.container;
105121
+ for (const [other, node] of this.model.nodes) {
105122
+ if (node.container === container && this.shapes.has(other)) {
105123
+ return this.shapes.get(other)?.plane;
105124
+ }
105125
+ }
105126
+ if (container && this.isExpanded(container)) {
105127
+ return this.shapes.get(container)?.plane;
105128
+ }
105129
+ const collaboration = container ? this.model.collaborationOf.get(container) : undefined;
105130
+ return this.di.planes.find((plane) => plane.element === container || collaboration !== undefined && plane.element === collaboration);
105131
+ }
105132
+ laneBox(id) {
105133
+ const lane = this.model.laneOf.get(id);
105134
+ return lane ? this.shapes.get(lane)?.box : undefined;
105135
+ }
105136
+ addShape(id, plane, box) {
105137
+ const expanded = this.opensAsFrame(id);
105138
+ this.shapes.set(id, { plane, box, expanded });
105139
+ if (expanded)
105140
+ this.frameTypes.add(id);
105141
+ this.added.push(id);
105142
+ }
105143
+ levelWith(ref, h, lane) {
105144
+ let cy = ref.y + ref.h / 2;
105145
+ if (lane && h >= lane.h)
105146
+ return lane.y;
105147
+ if (lane && (cy - h / 2 < lane.y || cy + h / 2 > lane.y + lane.h)) {
105148
+ cy = lane.y + lane.h / 2;
105149
+ }
105150
+ return cy - h / 2;
105151
+ }
105152
+ successors(id) {
105153
+ const result = new Set;
105154
+ for (const flow of this.model.flows.values()) {
105155
+ if (flow.type === "bpmn:SequenceFlow" && flow.src === id) {
105156
+ result.add(flow.tgt);
105157
+ }
105158
+ }
105159
+ return result;
105160
+ }
105161
+ placeAfter(id, pred, predId) {
105162
+ const { plane } = pred;
105163
+ const { w, h } = this.sizeFor(id, plane);
105164
+ const lane = this.laneBox(id) ?? this.laneBox(predId);
105165
+ const box = {
105166
+ x: pred.box.x + pred.box.w + H_GAP,
105167
+ y: this.levelWith(pred.box, h, lane),
105168
+ w,
105169
+ h
105170
+ };
105171
+ const cut = pred.box.x + pred.box.w + 1;
105172
+ const blockers = this.blockers(plane, box, id);
105173
+ const branches = this.successors(predId);
105174
+ if (blockers.some(([other, otherBox]) => branches.has(other) || otherBox.x < cut)) {
105175
+ this.stackBelow(plane, box, id);
105176
+ } else if (blockers.length > 0) {
105177
+ const nearest = Math.min(...blockers.map(([, other]) => other.x));
105178
+ this.makeRoom(plane, "x", cut, box.x + box.w + H_GAP - nearest);
105179
+ }
105180
+ this.fitFrames(id, plane, centre(pred.box), box, cut, lane);
105181
+ this.addShape(id, plane, box);
105182
+ }
105183
+ placeBefore(id, succ, succId) {
105184
+ const { plane } = succ;
105185
+ const { w, h } = this.sizeFor(id, plane);
105186
+ const lane = this.laneBox(id) ?? this.laneBox(succId);
105187
+ const box = {
105188
+ x: succ.box.x - H_GAP - w,
105189
+ y: this.levelWith(succ.box, h, lane),
105190
+ w,
105191
+ h
105192
+ };
105193
+ const frames = [
105194
+ ...this.framesAt(plane, centre(succ.box)),
105195
+ ...lane ? [lane] : []
105196
+ ];
105197
+ const outside = frames.some((frame) => box.x < frame.x);
105198
+ if (outside || this.blockers(plane, box, id).length > 0) {
105199
+ const cut = succ.box.x;
105200
+ this.makeRoom(plane, "x", cut, w + H_GAP);
105201
+ box.x = cut;
105202
+ }
105203
+ this.fitFrames(id, plane, centre(box), box, box.x, lane);
105204
+ this.addShape(id, plane, box);
105205
+ }
105206
+ stackBelow(plane, box, id) {
105207
+ for (let blockers = this.blockers(plane, box, id);blockers.length > 0; blockers = this.blockers(plane, box, id)) {
105208
+ box.y = Math.max(box.y + box.h + V_GAP, ...blockers.map(([, other]) => other.y + other.h + V_GAP));
105209
+ }
105210
+ }
105211
+ fitFrames(id, plane, anchor, box, cut, lane) {
105212
+ const own = [...this.ownFrames(id, plane), ...lane ? [lane] : []];
105213
+ const right = Math.max(0, ...[...this.framesAt(plane, anchor), ...own].map((frame) => box.x + box.w + H_GAP / 2 - (frame.x + frame.w)));
105214
+ if (right > 0)
105215
+ this.makeRoom(plane, "x", cut, right);
105216
+ own.sort((a, b) => a.y + a.h - (b.y + b.h));
105217
+ for (const frame of own) {
105218
+ const below = box.y + box.h + V_GAP / 2 - (frame.y + frame.h);
105219
+ if (below > 0)
105220
+ this.makeRoom(plane, "y", frame.y + frame.h - 1, below);
105221
+ }
105222
+ }
105223
+ placeArtifact(id) {
105224
+ for (const flow of this.model.flows.values()) {
105225
+ const partner = flow.src === id ? flow.tgt : flow.tgt === id ? flow.src : undefined;
105226
+ const shape = partner ? this.shapes.get(partner) : undefined;
105227
+ if (!shape)
105228
+ continue;
105229
+ const { w, h } = this.sizeFor(id, shape.plane);
105230
+ const box = {
105231
+ x: shape.box.x + shape.box.w / 2 - w / 2,
105232
+ y: shape.box.y - h - V_GAP,
105233
+ w,
105234
+ h
105235
+ };
105236
+ if (this.blockers(shape.plane, box, id).length > 0) {
105237
+ box.y = shape.box.y + shape.box.h + V_GAP;
105238
+ this.stackBelow(shape.plane, box, id);
105239
+ }
105240
+ this.addShape(id, shape.plane, box);
105241
+ return true;
105242
+ }
105243
+ return false;
105244
+ }
105245
+ placeBoundary(id, hostId, host) {
105246
+ const { w, h } = this.sizeFor(id, host.plane);
105247
+ const { x, y, w: hw, h: hh } = host.box;
105248
+ const taken = [...this.model.nodes].filter(([other, node]) => other !== id && node.attachedTo === hostId).map(([other]) => this.shapes.get(other)?.box).filter((box) => box !== undefined);
105249
+ const across = Math.max(0, Math.floor((hw - w - 10) / (w + 10))) + 1;
105250
+ const down = Math.max(1, Math.floor((hh - h) / (h + 10)));
105251
+ const candidates = [];
105252
+ for (const top of [y + hh - h / 2, y - h / 2]) {
105253
+ for (let slot = 0;slot < across; slot++) {
105254
+ candidates.push({
105255
+ x: x + hw - w - 10 - slot * (w + 10),
105256
+ y: top,
105257
+ w,
105258
+ h
105259
+ });
105260
+ }
105261
+ }
105262
+ for (const left of [x + hw - w / 2, x - w / 2]) {
105263
+ for (let slot = 0;slot < down; slot++) {
105264
+ candidates.push({
105265
+ x: left,
105266
+ y: y + hh * (slot + 1) / (down + 1) - h / 2,
105267
+ w,
105268
+ h
105269
+ });
105270
+ }
105271
+ }
105272
+ const box = candidates.find((candidate) => !taken.some((other) => overlaps(other, candidate)));
105273
+ if (box)
105274
+ this.addShape(id, host.plane, box);
105275
+ return box !== undefined;
105276
+ }
105277
+ tryPlace(id) {
105278
+ const node = this.model.nodes.get(id);
105279
+ if (!node)
105280
+ return false;
105281
+ const host = node.attachedTo ? this.shapes.get(node.attachedTo) : undefined;
105282
+ if (node.attachedTo && host) {
105283
+ return this.placeBoundary(id, node.attachedTo, host);
105284
+ }
105285
+ if (ARTIFACT_TYPES.has(node.type))
105286
+ return this.placeArtifact(id);
105287
+ const sequence = [...this.model.flows.values()].filter((flow) => flow.type === "bpmn:SequenceFlow");
105288
+ for (const flow of sequence) {
105289
+ const pred = flow.tgt === id ? this.shapes.get(flow.src) : undefined;
105290
+ if (pred) {
105291
+ this.placeAfter(id, pred, flow.src);
105292
+ return true;
105293
+ }
105294
+ }
105295
+ for (const flow of sequence) {
105296
+ const succ = flow.src === id ? this.shapes.get(flow.tgt) : undefined;
105297
+ if (succ) {
105298
+ this.placeBefore(id, succ, flow.tgt);
105299
+ return true;
105300
+ }
105301
+ }
105302
+ return false;
105303
+ }
105304
+ looseFrame(id) {
105305
+ const container = this.model.nodes.get(id)?.container;
105306
+ const sub = container ? this.shapes.get(container) : undefined;
105307
+ if (sub && this.isExpanded(container)) {
105308
+ return { box: sub.box, inset: H_GAP / 2 };
105309
+ }
105310
+ const lane = this.laneBox(id);
105311
+ if (lane)
105312
+ return { box: lane, inset: H_GAP };
105313
+ const participant = container ? this.model.participantOf.get(container) : undefined;
105314
+ const pool = participant ? this.shapes.get(participant) : undefined;
105315
+ return pool ? { box: pool.box, inset: POOL_HEADER + H_GAP } : undefined;
105316
+ }
105317
+ placeLoose(id) {
105318
+ const host = this.model.nodes.get(id)?.attachedTo;
105319
+ if (host && this.shapes.has(host))
105320
+ return false;
105321
+ const plane = this.planeFor(id);
105322
+ if (!plane)
105323
+ return false;
105324
+ const { w, h } = this.sizeFor(id, plane);
105325
+ const frame = this.looseFrame(id);
105326
+ const others = [...this.shapes].filter(([other, shape]) => shape.plane === plane && !this.isFrame(other)).map(([, shape]) => shape.box);
105327
+ const box = frame ? {
105328
+ x: frame.box.x + frame.inset,
105329
+ y: frame.box.y + frame.box.h / 2 - h / 2,
105330
+ w,
105331
+ h
105332
+ } : {
105333
+ x: Math.min(...others.map((other) => other.x), 160),
105334
+ y: Math.max(...others.map((other) => other.y + other.h), 0) + V_GAP * 2,
105335
+ w,
105336
+ h
105337
+ };
105338
+ while (this.blockers(plane, box, id).length > 0)
105339
+ box.x += w + H_GAP;
105340
+ if (frame) {
105341
+ const cut = Math.min(box.x, frame.box.x + frame.box.w - 1);
105342
+ this.fitFrames(id, plane, centre(box), box, cut, frame.box);
105343
+ }
105344
+ this.addShape(id, plane, box);
105345
+ return true;
105346
+ }
105347
+ drawable(id) {
105348
+ const container = this.model.nodes.get(id)?.container;
105349
+ const lane = this.model.laneOf.get(id);
105350
+ if (lane && !this.drawn.has(lane) && [...this.model.laneOf].some(([node, other]) => this.model.nodes.get(node)?.container === container && this.drawn.has(other))) {
105351
+ return false;
105352
+ }
105353
+ const participant = container ? this.model.participantOf.get(container) : undefined;
105354
+ if (participant && !this.drawn.has(participant) && [...this.model.participantOf.values()].some((other) => this.drawn.has(other))) {
105355
+ return false;
105356
+ }
105357
+ const containerType = this.model.types.get(container ?? "");
105358
+ if (!containerType || containerType === "bpmn:Process")
105359
+ return true;
105360
+ return this.isExpanded(container) || this.di.planes.some((plane) => plane.element === container) || [...this.model.nodes].some(([other, node]) => node.container === container && this.shapes.has(other));
105361
+ }
105362
+ placeMissing() {
105363
+ let pending = [...this.model.nodes.keys()].filter((id) => !this.drawn.has(id));
105364
+ while (pending.length > 0) {
105365
+ const before = pending.length;
105366
+ pending = pending.filter((id) => !(this.drawable(id) && this.tryPlace(id)));
105367
+ if (pending.length < before)
105368
+ continue;
105369
+ const loose = pending.findIndex((id) => this.drawable(id) && this.placeLoose(id));
105370
+ if (loose === -1)
105371
+ break;
105372
+ pending.splice(loose, 1);
105373
+ }
105374
+ this.unplaced = pending;
105375
+ }
105376
+ routeEdges() {
105377
+ const added = [];
105378
+ for (const [id, flow] of this.model.flows) {
105379
+ const source = this.shapes.get(flow.src);
105380
+ const target = this.shapes.get(flow.tgt);
105381
+ if (!source || !target || source.plane !== target.plane)
105382
+ continue;
105383
+ const edge = this.edges.get(id);
105384
+ if (!edge) {
105385
+ this.edges.set(id, {
105386
+ plane: source.plane,
105387
+ points: route(source.box, target.box),
105388
+ rerouted: false
105389
+ });
105390
+ added.push(id);
105391
+ continue;
105392
+ }
105393
+ const first = edge.points[0];
105394
+ const last = edge.points.at(-1);
105395
+ const attached = first !== undefined && last !== undefined && edge.points.length >= 2 && contains(source.box, first, DOCK_SLACK) && contains(target.box, last, DOCK_SLACK);
105396
+ if (!attached) {
105397
+ edge.points = route(source.box, target.box);
105398
+ edge.label = undefined;
105399
+ edge.rerouted = true;
105400
+ }
105401
+ }
105402
+ return added;
105403
+ }
105404
+ }
105405
+ var DC_URI = "http://www.omg.org/spec/DD/20100524/DC";
105406
+ var DI_URI = "http://www.omg.org/spec/DD/20100524/DI";
105407
+ function rootPrefix(xml, uri) {
105408
+ const name = rootElementName(xml);
105409
+ if (!name)
105410
+ return;
105411
+ const tag = new RegExp(`<${escapeRegExp(name)}\\b${ATTRIBUTES}/?>`).exec(maskComments(xml))?.[0];
105412
+ const match = tag ? new RegExp(`\\sxmlns(?::([\\w.-]+))?\\s*=\\s*["']${escapeRegExp(uri)}["']`).exec(tag) : null;
105413
+ if (!match)
105414
+ return;
105415
+ return match[1] ? `${match[1]}:` : "";
105416
+ }
105417
+ var SCAFFOLD = {
105418
+ "bpmn:StartEvent": { x: 256, y: 144, w: 96, h: 96 },
105419
+ "bpmn:EndEvent": { x: 512, y: 144, w: 96, h: 96 }
105420
+ };
105421
+ function isScaffold(xml, entries, model) {
105422
+ const shapes = entries.filter((entry) => entry.kind === "shape");
105423
+ const types = new Set(shapes.map((entry) => model.types.get(entry.element)));
105424
+ const drawn = new Set(entries.map((entry) => entry.element));
105425
+ return shapes.length === 2 && types.size === 2 && shapes.every((entry) => {
105426
+ const expected = SCAFFOLD[model.types.get(entry.element) ?? ""];
105427
+ return expected !== undefined && entry.bounds !== undefined && sameBox(entry.bounds.box, expected) && !/color|fill|stroke/i.test(xml.slice(entry.start, entry.end));
105428
+ }) && [...model.nodes.keys()].some((id) => !drawn.has(id));
105429
+ }
105430
+ function uniqueId(base, ids) {
105431
+ let id = base;
105432
+ for (let n = 2;ids.has(id); n++)
105433
+ id = `${base}_${n}`;
105434
+ ids.add(id);
105435
+ return id;
105436
+ }
105437
+ function boxValues(box) {
105438
+ return { x: box.x, y: box.y, width: box.w, height: box.h };
105439
+ }
105440
+ function sameBox(a, b) {
105441
+ return a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h;
105442
+ }
105443
+ function removal(xml, span) {
105444
+ let start = span.start;
105445
+ while (start > 0 && /\s/.test(xml[start - 1]))
105446
+ start--;
105447
+ return { start, end: span.end, text: "" };
105448
+ }
105449
+ function writeEdits(xml, edits) {
105450
+ let result = xml;
105451
+ for (const edit of [...edits].sort((a, b) => b.start - a.start)) {
105452
+ result = result.slice(0, edit.start) + edit.text + result.slice(edit.end);
105453
+ }
105454
+ return result;
105455
+ }
105456
+ function updateBpmnLayout(xml, root) {
105457
+ const di = parseDi(xml);
105458
+ const shapeEntries = di.planes.flatMap((plane) => plane.entries.filter((entry) => entry.kind === "shape"));
105459
+ const unchanged = {
105460
+ success: true,
105461
+ changed: false,
105462
+ content: xml,
105463
+ shapeCount: 0,
105464
+ edgeCount: 0,
105465
+ preserved: 0,
105466
+ moved: 0,
105467
+ added: [],
105468
+ removed: [],
105469
+ rerouted: []
105470
+ };
105471
+ if (shapeEntries.length === 0)
105472
+ return { ...unchanged, hasDiagram: false };
105473
+ const model = collectModel(root);
105474
+ if (isScaffold(xml, shapeEntries, model)) {
105475
+ return { ...unchanged, hasDiagram: false };
105476
+ }
105477
+ const update = new DiagramUpdate(di, model);
105478
+ update.placeMissing();
105479
+ if (update.unplaced.length > 0) {
105480
+ const ids = update.unplaced.map((id) => `"${id}"`).join(", ");
105481
+ return {
105482
+ success: false,
105483
+ message: `Cannot draw ${ids} in the existing diagram: no plane, expanded frame, lane or pool shows where they belong, or their host has no free edge left`,
105484
+ instructions: "Draw them in Studio Web, or expand the collapsed sub-process that holds them. " + "To lay the whole process out again instead, delete the bpmndi:BPMNDiagram section and run format: that discards the current layout."
105485
+ };
105486
+ }
105487
+ const addedEdges = update.routeEdges();
105488
+ const dcBound = rootPrefix(xml, DC_URI);
105489
+ const diBound = rootPrefix(xml, DI_URI);
105490
+ const dc = dcBound ?? "dc:";
105491
+ const wp = diBound ?? "di:";
105492
+ let needsPrefixes = false;
105493
+ const edits = update.removed.map((entry) => removal(xml, entry));
105494
+ const inserts = new Map;
105495
+ const insert = (plane, text) => {
105496
+ inserts.set(plane, [...inserts.get(plane) ?? [], text]);
105497
+ };
105498
+ const waypointTags = (points, separator = "") => {
105499
+ needsPrefixes = true;
105500
+ return points.map((point) => `<${wp}waypoint x="${formatNumber(point.x)}" y="${formatNumber(point.y)}" />`).join(separator);
105501
+ };
105502
+ let moved = 0;
105503
+ for (const [id, shape] of update.shapes) {
105504
+ const { entry } = shape;
105505
+ if (!entry) {
105506
+ const diId = uniqueId(`${id}_di`, di.ids);
105507
+ const box = boxValues(shape.box);
105508
+ const expanded = shape.expanded ? ' isExpanded="true"' : "";
105509
+ needsPrefixes = true;
105510
+ insert(shape.plane, `<${di.shapePrefix}BPMNShape id="${escapeXmlAttr(diId)}" bpmnElement="${escapeXmlAttr(id)}"${expanded}>` + `<${dc}Bounds x="${formatNumber(box.x)}" y="${formatNumber(box.y)}" width="${formatNumber(box.width)}" height="${formatNumber(box.height)}" />` + `</${di.shapePrefix}BPMNShape>`);
105511
+ continue;
105512
+ }
105513
+ let shapeMoved = false;
105514
+ if (entry.bounds && !sameBox(entry.bounds.box, shape.box)) {
105515
+ edits.push({
105516
+ ...entry.bounds,
105517
+ text: rewriteTag(entry.bounds.text, boxValues(shape.box))
105518
+ });
105519
+ shapeMoved = true;
105520
+ }
105521
+ const label = entry.label?.bounds;
105522
+ if (label && shape.label && !sameBox(label.box, shape.label)) {
105523
+ edits.push({
105524
+ ...label,
105525
+ text: rewriteTag(label.text, boxValues(shape.label))
105526
+ });
105527
+ }
105528
+ if (shapeMoved)
105529
+ moved++;
105530
+ }
105531
+ const rerouted = [];
105532
+ for (const [id, edge] of update.edges) {
105533
+ const { entry } = edge;
105534
+ if (!entry) {
105535
+ const diId = uniqueId(`${id}_di`, di.ids);
105536
+ insert(edge.plane, `<${di.shapePrefix}BPMNEdge id="${escapeXmlAttr(diId)}" bpmnElement="${escapeXmlAttr(id)}">` + waypointTags(edge.points) + `</${di.shapePrefix}BPMNEdge>`);
105537
+ continue;
105538
+ }
105539
+ if (edge.rerouted) {
105540
+ rerouted.push(id);
105541
+ const first = entry.waypoints[0];
105542
+ const last = entry.waypoints.at(-1);
105543
+ if (first && last) {
105544
+ const second = entry.waypoints[1];
105545
+ const gap = second ? xml.slice(first.end, second.start) : "";
105546
+ edits.push({
105547
+ start: first.start,
105548
+ end: last.end,
105549
+ text: waypointTags(edge.points, /^\s*$/.test(gap) ? gap : "")
105550
+ });
105551
+ } else {
105552
+ const diId = readAttr(xml.slice(entry.start, entry.end), "id");
105553
+ edits.push({
105554
+ ...entry,
105555
+ text: `<${di.shapePrefix}BPMNEdge${diId ? ` id="${escapeXmlAttr(diId)}"` : ""} bpmnElement="${escapeXmlAttr(id)}">` + waypointTags(edge.points) + `</${di.shapePrefix}BPMNEdge>`
105556
+ });
105557
+ continue;
105558
+ }
105559
+ if (entry.label)
105560
+ edits.push(removal(xml, entry.label));
105561
+ continue;
105562
+ }
105563
+ for (const [index, tag] of entry.waypoints.entries()) {
105564
+ const point = edge.points[index];
105565
+ if (point.x !== tag.point.x || point.y !== tag.point.y) {
105566
+ edits.push({ ...tag, text: rewriteTag(tag.text, point) });
105567
+ }
105568
+ }
105569
+ const label = entry.label?.bounds;
105570
+ if (label && edge.label && !sameBox(label.box, edge.label)) {
105571
+ edits.push({
105572
+ ...label,
105573
+ text: rewriteTag(label.text, boxValues(edge.label))
105574
+ });
105575
+ }
105576
+ }
105577
+ for (const [plane, texts] of inserts) {
105578
+ let at = plane.close;
105579
+ while (at > 0 && /\s/.test(xml[at - 1]))
105580
+ at--;
105581
+ const indent = plane.indent || " ";
105582
+ edits.push({
105583
+ start: at,
105584
+ end: at,
105585
+ text: texts.map((text) => `
105586
+ ${indent}${text}`).join("")
105587
+ });
105588
+ }
105589
+ const removed = update.removed.map((entry) => entry.element);
105590
+ const preserved = di.planes.reduce((sum, plane) => sum + plane.entries.length, 0) - removed.length - rerouted.length;
105591
+ const counts = {
105592
+ shapeCount: update.shapes.size,
105593
+ edgeCount: update.edges.size,
105594
+ preserved,
105595
+ moved,
105596
+ added: [...update.added, ...addedEdges],
105597
+ removed,
105598
+ rerouted
105599
+ };
105600
+ if (edits.length === 0) {
105601
+ return { ...unchanged, ...counts, hasDiagram: true };
105602
+ }
105603
+ if (update.duplicate !== undefined) {
105604
+ return {
105605
+ success: false,
105606
+ message: `"${update.duplicate}" is drawn on more than one diagram plane, so an in-place update would leave one view stale`,
105607
+ instructions: "Remove the extra bpmndi:BPMNDiagram, or make the change in Studio Web."
105608
+ };
105609
+ }
105610
+ let content = writeEdits(xml, edits);
105611
+ if (needsPrefixes && (dcBound === undefined || diBound === undefined)) {
105612
+ const rootName = rootElementName(content);
105613
+ if (rootName) {
105614
+ const namespaces = ensureDiNamespaces(content, rootName);
105615
+ if (!namespaces.ok) {
105616
+ return {
105617
+ success: false,
105618
+ message: `Root element already binds ${namespaces.attr} to a different namespace`,
105619
+ instructions: `The root binds ${namespaces.attr} to "${namespaces.boundTo}", not the BPMN DI namespace. ` + "Rename that prefix on the root, then run this again."
105620
+ };
105621
+ }
105622
+ content = namespaces.xml;
105623
+ }
105624
+ }
105625
+ return {
105626
+ success: true,
105627
+ hasDiagram: true,
105628
+ changed: true,
105629
+ content,
105630
+ ...counts
105631
+ };
105632
+ }
104658
105633
  export {
104659
105634
  applyBpmnLayout,
104660
105635
  generateBpmnLayout,
104661
105636
  parseBpmnProcesses,
104662
- parseBpmnXml
105637
+ parseBpmnXml,
105638
+ updateBpmnLayout
104663
105639
  };
104664
105640
 
104665
- //# debugId=EDB131FC4CF4331364756E2164756E21
105641
+ //# debugId=6CDB4EC48066F12764756E2164756E21