camunda-bpmn-js 2.1.1 → 2.2.0

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 (45) hide show
  1. package/dist/base-modeler.development.js +5731 -2372
  2. package/dist/base-modeler.production.min.js +6 -6
  3. package/dist/base-navigated-viewer.development.js +1854 -741
  4. package/dist/base-navigated-viewer.production.min.js +1 -1
  5. package/dist/base-viewer.development.js +1745 -720
  6. package/dist/base-viewer.production.min.js +1 -1
  7. package/dist/camunda-cloud-modeler.development.js +5811 -2421
  8. package/dist/camunda-cloud-modeler.production.min.js +23 -23
  9. package/dist/camunda-cloud-navigated-viewer.development.js +1876 -750
  10. package/dist/camunda-cloud-navigated-viewer.production.min.js +1 -1
  11. package/dist/camunda-cloud-viewer.development.js +1764 -726
  12. package/dist/camunda-cloud-viewer.production.min.js +1 -1
  13. package/dist/camunda-platform-modeler.development.js +5709 -2342
  14. package/dist/camunda-platform-modeler.production.min.js +6 -6
  15. package/dist/camunda-platform-navigated-viewer.development.js +1867 -746
  16. package/dist/camunda-platform-navigated-viewer.production.min.js +1 -1
  17. package/dist/camunda-platform-viewer.development.js +1755 -722
  18. package/dist/camunda-platform-viewer.production.min.js +1 -1
  19. package/lib/base/Modeler.d.ts +15 -0
  20. package/lib/base/Modeler.js +16 -2
  21. package/lib/base/NavigatedViewer.d.ts +2 -0
  22. package/lib/base/Viewer.d.ts +2 -0
  23. package/lib/camunda-cloud/ElementTemplatesValidator.d.ts +1 -0
  24. package/lib/camunda-cloud/Modeler.d.ts +3 -0
  25. package/lib/camunda-cloud/Modeler.js +5 -2
  26. package/lib/camunda-cloud/NavigatedViewer.d.ts +3 -0
  27. package/lib/camunda-cloud/NavigatedViewer.js +4 -2
  28. package/lib/camunda-cloud/Viewer.d.ts +3 -0
  29. package/lib/camunda-cloud/Viewer.js +4 -2
  30. package/lib/camunda-cloud/features/rules/BpmnRules.d.ts +32 -0
  31. package/lib/camunda-cloud/features/rules/BpmnRules.js +110 -87
  32. package/lib/camunda-cloud/features/rules/index.d.ts +6 -0
  33. package/lib/camunda-cloud/util/commonModules.d.ts +9 -0
  34. package/lib/camunda-cloud/util/commonModules.js +5 -0
  35. package/lib/camunda-platform/Modeler.d.ts +3 -0
  36. package/lib/camunda-platform/Modeler.js +4 -2
  37. package/lib/camunda-platform/NavigatedViewer.d.ts +5 -0
  38. package/lib/camunda-platform/NavigatedViewer.js +4 -2
  39. package/lib/camunda-platform/Viewer.d.ts +5 -0
  40. package/lib/camunda-platform/Viewer.js +5 -2
  41. package/lib/camunda-platform/util/commonModules.d.ts +9 -0
  42. package/lib/camunda-platform/util/commonModules.js +5 -0
  43. package/lib/util/ExtensionElementsUtil.d.ts +24 -0
  44. package/lib/util/ExtensionElementsUtil.js +17 -8
  45. package/package.json +14 -7
@@ -9,9 +9,11 @@
9
9
  /**
10
10
  * Flatten array, one level deep.
11
11
  *
12
- * @param {Array<?>} arr
12
+ * @template T
13
13
  *
14
- * @return {Array<?>}
14
+ * @param {T[][]} arr
15
+ *
16
+ * @return {T[]}
15
17
  */
16
18
 
17
19
  const nativeToString$1 = Object.prototype.toString;
@@ -37,6 +39,11 @@
37
39
  return nativeToString$1.call(obj) === '[object Number]';
38
40
  }
39
41
 
42
+ /**
43
+ * @param {any} obj
44
+ *
45
+ * @return {boolean}
46
+ */
40
47
  function isFunction(obj) {
41
48
  const tag = nativeToString$1.call(obj);
42
49
 
@@ -65,22 +72,74 @@
65
72
  return nativeHasOwnProperty$1.call(target, key);
66
73
  }
67
74
 
75
+ /**
76
+ * @template T
77
+ * @typedef { (
78
+ * ((e: T) => boolean) |
79
+ * ((e: T, idx: number) => boolean) |
80
+ * ((e: T, key: string) => boolean) |
81
+ * string |
82
+ * number
83
+ * ) } Matcher
84
+ */
85
+
86
+ /**
87
+ * @template T
88
+ * @template U
89
+ *
90
+ * @typedef { (
91
+ * ((e: T) => U) | string | number
92
+ * ) } Extractor
93
+ */
94
+
95
+
96
+ /**
97
+ * @template T
98
+ * @typedef { (val: T, key: any) => boolean } MatchFn
99
+ */
100
+
101
+ /**
102
+ * @template T
103
+ * @typedef { T[] } ArrayCollection
104
+ */
105
+
106
+ /**
107
+ * @template T
108
+ * @typedef { { [key: string]: T } } StringKeyValueCollection
109
+ */
110
+
111
+ /**
112
+ * @template T
113
+ * @typedef { { [key: number]: T } } NumberKeyValueCollection
114
+ */
115
+
116
+ /**
117
+ * @template T
118
+ * @typedef { StringKeyValueCollection<T> | NumberKeyValueCollection<T> } KeyValueCollection
119
+ */
120
+
121
+ /**
122
+ * @template T
123
+ * @typedef { KeyValueCollection<T> | ArrayCollection<T> } Collection
124
+ */
125
+
68
126
  /**
69
127
  * Find element in collection.
70
128
  *
71
- * @param {Array|Object} collection
72
- * @param {Function|Object} matcher
129
+ * @template T
130
+ * @param {Collection<T>} collection
131
+ * @param {Matcher<T>} matcher
73
132
  *
74
133
  * @return {Object}
75
134
  */
76
135
  function find(collection, matcher) {
77
136
 
78
- matcher = toMatcher(matcher);
137
+ const matchFn = toMatcher(matcher);
79
138
 
80
139
  let match;
81
140
 
82
141
  forEach$1(collection, function(val, key) {
83
- if (matcher(val, key)) {
142
+ if (matchFn(val, key)) {
84
143
  match = val;
85
144
 
86
145
  return false;
@@ -95,19 +154,20 @@
95
154
  /**
96
155
  * Find element index in collection.
97
156
  *
98
- * @param {Array|Object} collection
99
- * @param {Function} matcher
157
+ * @template T
158
+ * @param {Collection<T>} collection
159
+ * @param {Matcher<T>} matcher
100
160
  *
101
- * @return {Object}
161
+ * @return {number}
102
162
  */
103
163
  function findIndex(collection, matcher) {
104
164
 
105
- matcher = toMatcher(matcher);
165
+ const matchFn = toMatcher(matcher);
106
166
 
107
167
  let idx = isArray$2(collection) ? -1 : undefined;
108
168
 
109
169
  forEach$1(collection, function(val, key) {
110
- if (matcher(val, key)) {
170
+ if (matchFn(val, key)) {
111
171
  idx = key;
112
172
 
113
173
  return false;
@@ -119,19 +179,22 @@
119
179
 
120
180
 
121
181
  /**
122
- * Find element in collection.
182
+ * Filter elements in collection.
123
183
  *
124
- * @param {Array|Object} collection
125
- * @param {Function} matcher
184
+ * @template T
185
+ * @param {Collection<T>} collection
186
+ * @param {Matcher<T>} matcher
126
187
  *
127
- * @return {Array} result
188
+ * @return {T[]} result
128
189
  */
129
190
  function filter(collection, matcher) {
130
191
 
192
+ const matchFn = toMatcher(matcher);
193
+
131
194
  let result = [];
132
195
 
133
196
  forEach$1(collection, function(val, key) {
134
- if (matcher(val, key)) {
197
+ if (matchFn(val, key)) {
135
198
  result.push(val);
136
199
  }
137
200
  });
@@ -144,10 +207,11 @@
144
207
  * Iterate over collection; returning something
145
208
  * (non-undefined) will stop iteration.
146
209
  *
147
- * @param {Array|Object} collection
148
- * @param {Function} iterator
210
+ * @template T
211
+ * @param {Collection<T>} collection
212
+ * @param { ((item: T, idx: number) => (boolean|void)) | ((item: T, key: string) => (boolean|void)) } iterator
149
213
  *
150
- * @return {Object} return result that stopped the iteration
214
+ * @return {T} return result that stopped the iteration
151
215
  */
152
216
  function forEach$1(collection, iterator) {
153
217
 
@@ -178,11 +242,14 @@
178
242
  /**
179
243
  * Reduce collection, returning a single result.
180
244
  *
181
- * @param {Object|Array} collection
182
- * @param {Function} iterator
183
- * @param {Any} result
245
+ * @template T
246
+ * @template V
184
247
  *
185
- * @return {Any} result returned from last iterator
248
+ * @param {Collection<T>} collection
249
+ * @param {(result: V, entry: T, index: any) => V} iterator
250
+ * @param {V} result
251
+ *
252
+ * @return {V} result returned from last iterator
186
253
  */
187
254
  function reduce(collection, iterator, result) {
188
255
 
@@ -252,13 +319,17 @@
252
319
  *
253
320
  * @example
254
321
  *
322
+ * ```javascript
255
323
  * const matcher = matchPattern({ id: 1 });
256
324
  *
257
325
  * let element = find(elements, matcher);
326
+ * ```
327
+ *
328
+ * @template T
258
329
  *
259
- * @param {Object} pattern
330
+ * @param {T} pattern
260
331
  *
261
- * @return {Function} matcherFn
332
+ * @return { (el: any) => boolean } matcherFn
262
333
  */
263
334
  function matchPattern(pattern) {
264
335
 
@@ -272,6 +343,12 @@
272
343
  }
273
344
 
274
345
 
346
+ /**
347
+ * @template T
348
+ * @param {Matcher<T>} matcher
349
+ *
350
+ * @return {MatchFn<T>}
351
+ */
275
352
  function toMatcher(matcher) {
276
353
  return isFunction(matcher) ? matcher : (e) => {
277
354
  return e === matcher;
@@ -287,6 +364,16 @@
287
364
  return Number(arg);
288
365
  }
289
366
 
367
+ /* global setTimeout clearTimeout */
368
+
369
+ /**
370
+ * @typedef { {
371
+ * (...args: any[]): any;
372
+ * flush: () => void;
373
+ * cancel: () => void;
374
+ * } } DebouncedFunction
375
+ */
376
+
290
377
  /**
291
378
  * Debounce fn, calling it only once if the given time
292
379
  * elapsed between calls.
@@ -297,7 +384,7 @@
297
384
  * @param {Function} fn
298
385
  * @param {Number} timeout
299
386
  *
300
- * @return {Function} debounced function
387
+ * @return {DebouncedFunction} debounced function
301
388
  */
302
389
  function debounce(fn, timeout) {
303
390
 
@@ -343,6 +430,9 @@
343
430
  clear();
344
431
  }
345
432
 
433
+ /**
434
+ * @type { DebouncedFunction }
435
+ */
346
436
  function callback(...args) {
347
437
  lastNow = Date.now();
348
438
 
@@ -386,12 +476,15 @@
386
476
  }
387
477
 
388
478
  /**
389
- * Pick given properties from the target object.
479
+ * Pick properties from the given target.
390
480
  *
391
- * @param {Object} target
392
- * @param {Array} properties
481
+ * @template T
482
+ * @template {any[]} V
393
483
  *
394
- * @return {Object} target
484
+ * @param {T} target
485
+ * @param {V} properties
486
+ *
487
+ * @return Pick<T, V>
395
488
  */
396
489
  function pick(target, properties) {
397
490
 
@@ -412,10 +505,13 @@
412
505
  /**
413
506
  * Pick all target properties, excluding the given ones.
414
507
  *
415
- * @param {Object} target
416
- * @param {Array} properties
508
+ * @template T
509
+ * @template {any[]} V
417
510
  *
418
- * @return {Object} target
511
+ * @param {T} target
512
+ * @param {V} properties
513
+ *
514
+ * @return {Omit<T, V>} target
419
515
  */
420
516
  function omit(target, properties) {
421
517
 
@@ -436,9 +532,9 @@
436
532
  var DEFAULT_RENDER_PRIORITY$1 = 1000;
437
533
 
438
534
  /**
439
- * @typedef {import('../model').Base} Base
440
- * @typedef {import('../model').Connection} Connection
441
- * @typedef {import('../model').Shape} Shape
535
+ * @typedef {import('../core/Types').ElementLike} Element
536
+ * @typedef {import('../core/Types').ConnectionLike} Connection
537
+ * @typedef {import('../core/Types').ShapeLike} Shape
442
538
  *
443
539
  * @typedef {import('../core/EventBus').default} EventBus
444
540
  */
@@ -483,9 +579,9 @@
483
579
  /**
484
580
  * Checks whether an element can be rendered.
485
581
  *
486
- * @param {Base} element The element to be rendered.
582
+ * @param {Element} element The element to be rendered.
487
583
  *
488
- * @returns {boolean} Whether the element can be rendered.
584
+ * @return {boolean} Whether the element can be rendered.
489
585
  */
490
586
  BaseRenderer.prototype.canRender = function(element) {};
491
587
 
@@ -495,7 +591,7 @@
495
591
  * @param {SVGElement} visuals The SVG element to draw the shape into.
496
592
  * @param {Shape} shape The shape to be drawn.
497
593
  *
498
- * @returns {SVGElement} The SVG element of the shape drawn.
594
+ * @return {SVGElement} The SVG element of the shape drawn.
499
595
  */
500
596
  BaseRenderer.prototype.drawShape = function(visuals, shape) {};
501
597
 
@@ -505,7 +601,7 @@
505
601
  * @param {SVGElement} visuals The SVG element to draw the connection into.
506
602
  * @param {Connection} connection The connection to be drawn.
507
603
  *
508
- * @returns {SVGElement} The SVG element of the connection drawn.
604
+ * @return {SVGElement} The SVG element of the connection drawn.
509
605
  */
510
606
  BaseRenderer.prototype.drawConnection = function(visuals, connection) {};
511
607
 
@@ -527,10 +623,15 @@
527
623
  */
528
624
  BaseRenderer.prototype.getConnectionPath = function(connection) {};
529
625
 
626
+ /**
627
+ * @typedef { import('../model/Types').Element } Element
628
+ * @typedef { import('../model/Types').ModdleElement } ModdleElement
629
+ */
630
+
530
631
  /**
531
632
  * Is an element of the given BPMN type?
532
633
  *
533
- * @param {djs.model.Base|ModdleElement} element
634
+ * @param {Element|ModdleElement} element
534
635
  * @param {string} type
535
636
  *
536
637
  * @return {boolean}
@@ -545,8 +646,8 @@
545
646
  /**
546
647
  * Return true if element has any of the given types.
547
648
  *
548
- * @param {djs.model.Base} element
549
- * @param {Array<string>} types
649
+ * @param {Element|ModdleElement} element
650
+ * @param {string[]} types
550
651
  *
551
652
  * @return {boolean}
552
653
  */
@@ -559,7 +660,7 @@
559
660
  /**
560
661
  * Return the business object for a given element.
561
662
  *
562
- * @param {djs.model.Base|ModdleElement} element
663
+ * @param {Element|ModdleElement} element
563
664
  *
564
665
  * @return {ModdleElement}
565
666
  */
@@ -570,7 +671,7 @@
570
671
  /**
571
672
  * Return the di object for a given element.
572
673
  *
573
- * @param {djs.model.Base} element
674
+ * @param {Element} element
574
675
  *
575
676
  * @return {ModdleElement}
576
677
  */
@@ -578,6 +679,17 @@
578
679
  return element && element.di;
579
680
  }
580
681
 
682
+ /**
683
+ * @typedef {import('../model/Types').Element} Element
684
+ * @typedef {import('../model/Types').ModdleElement} ModdleElement
685
+ */
686
+
687
+ /**
688
+ * @param {Element} element
689
+ * @param {ModdleElement} [di]
690
+ *
691
+ * @return {boolean}
692
+ */
581
693
  function isExpanded(element, di) {
582
694
 
583
695
  if (is$1(element, 'bpmn:CallActivity')) {
@@ -601,10 +713,184 @@
601
713
  return true;
602
714
  }
603
715
 
716
+ /**
717
+ * @param {Element} element
718
+ *
719
+ * @return {boolean}
720
+ */
604
721
  function isEventSubProcess(element) {
605
722
  return element && !!getBusinessObject(element).triggeredByEvent;
606
723
  }
607
724
 
725
+ /**
726
+ * @typedef {import('diagram-js/lib/util/Types').Point} Point
727
+ * @typedef {import('diagram-js/lib/util/Types').Rect} Rect
728
+ *
729
+ * @typedef {import('../model/Types').Element} Element
730
+ * @typedef {import('../model/Types').ModdleElement} ModdleElement
731
+ */
732
+
733
+ var DEFAULT_LABEL_SIZE$1 = {
734
+ width: 90,
735
+ height: 20
736
+ };
737
+
738
+ var FLOW_LABEL_INDENT = 15;
739
+
740
+
741
+ /**
742
+ * Return true if the given semantic has an external label.
743
+ *
744
+ * @param {Element} semantic
745
+ *
746
+ * @return {boolean}
747
+ */
748
+ function isLabelExternal(semantic) {
749
+ return is$1(semantic, 'bpmn:Event') ||
750
+ is$1(semantic, 'bpmn:Gateway') ||
751
+ is$1(semantic, 'bpmn:DataStoreReference') ||
752
+ is$1(semantic, 'bpmn:DataObjectReference') ||
753
+ is$1(semantic, 'bpmn:DataInput') ||
754
+ is$1(semantic, 'bpmn:DataOutput') ||
755
+ is$1(semantic, 'bpmn:SequenceFlow') ||
756
+ is$1(semantic, 'bpmn:MessageFlow') ||
757
+ is$1(semantic, 'bpmn:Group');
758
+ }
759
+
760
+ /**
761
+ * Get the position of a sequence flow label.
762
+ *
763
+ * @param {Point[]} waypoints
764
+ *
765
+ * @return {Point}
766
+ */
767
+ function getFlowLabelPosition(waypoints) {
768
+
769
+ // get the waypoints mid
770
+ var mid = waypoints.length / 2 - 1;
771
+
772
+ var first = waypoints[Math.floor(mid)];
773
+ var second = waypoints[Math.ceil(mid + 0.01)];
774
+
775
+ // get position
776
+ var position = getWaypointsMid(waypoints);
777
+
778
+ // calculate angle
779
+ var angle = Math.atan((second.y - first.y) / (second.x - first.x));
780
+
781
+ var x = position.x,
782
+ y = position.y;
783
+
784
+ if (Math.abs(angle) < Math.PI / 2) {
785
+ y -= FLOW_LABEL_INDENT;
786
+ } else {
787
+ x += FLOW_LABEL_INDENT;
788
+ }
789
+
790
+ return { x: x, y: y };
791
+ }
792
+
793
+
794
+ /**
795
+ * Get the middle of a number of waypoints.
796
+ *
797
+ * @param {Point[]} waypoints
798
+ *
799
+ * @return {Point}
800
+ */
801
+ function getWaypointsMid(waypoints) {
802
+
803
+ var mid = waypoints.length / 2 - 1;
804
+
805
+ var first = waypoints[Math.floor(mid)];
806
+ var second = waypoints[Math.ceil(mid + 0.01)];
807
+
808
+ return {
809
+ x: first.x + (second.x - first.x) / 2,
810
+ y: first.y + (second.y - first.y) / 2
811
+ };
812
+ }
813
+
814
+ /**
815
+ * Get the middle of the external label of an element.
816
+ *
817
+ * @param {Element} element
818
+ *
819
+ * @return {Point}
820
+ */
821
+ function getExternalLabelMid(element) {
822
+
823
+ if (element.waypoints) {
824
+ return getFlowLabelPosition(element.waypoints);
825
+ } else if (is$1(element, 'bpmn:Group')) {
826
+ return {
827
+ x: element.x + element.width / 2,
828
+ y: element.y + DEFAULT_LABEL_SIZE$1.height / 2
829
+ };
830
+ } else {
831
+ return {
832
+ x: element.x + element.width / 2,
833
+ y: element.y + element.height + DEFAULT_LABEL_SIZE$1.height / 2
834
+ };
835
+ }
836
+ }
837
+
838
+
839
+ /**
840
+ * Return the bounds of an elements label, parsed from the elements DI or
841
+ * generated from its bounds.
842
+ *
843
+ * @param {ModdleElement} di
844
+ * @param {Element} element
845
+ *
846
+ * @return {Rect}
847
+ */
848
+ function getExternalLabelBounds(di, element) {
849
+
850
+ var mid,
851
+ size,
852
+ bounds,
853
+ label = di.label;
854
+
855
+ if (label && label.bounds) {
856
+ bounds = label.bounds;
857
+
858
+ size = {
859
+ width: Math.max(DEFAULT_LABEL_SIZE$1.width, bounds.width),
860
+ height: bounds.height
861
+ };
862
+
863
+ mid = {
864
+ x: bounds.x + bounds.width / 2,
865
+ y: bounds.y + bounds.height / 2
866
+ };
867
+ } else {
868
+
869
+ mid = getExternalLabelMid(element);
870
+
871
+ size = DEFAULT_LABEL_SIZE$1;
872
+ }
873
+
874
+ return assign$1({
875
+ x: mid.x - size.width / 2,
876
+ y: mid.y - size.height / 2
877
+ }, size);
878
+ }
879
+
880
+ /**
881
+ * @param {Element} element
882
+ *
883
+ * @return {boolean}
884
+ */
885
+ function isLabel(element) {
886
+ return element && !!element.labelTarget;
887
+ }
888
+
889
+
890
+ /**
891
+ * @typedef { import('../model').DiagramElement } DiagramElement
892
+ */
893
+
608
894
  function getLabelAttr(semantic) {
609
895
  if (
610
896
  is$1(semantic, 'bpmn:FlowElement') ||
@@ -638,6 +924,11 @@
638
924
  return categoryValueRef.value || '';
639
925
  }
640
926
 
927
+ /**
928
+ * @param {DiagramElement} element
929
+ *
930
+ * @return {string} label
931
+ */
641
932
  function getLabel(element) {
642
933
  var semantic = element.businessObject,
643
934
  attr = getLabelAttr(semantic);
@@ -1338,7 +1629,7 @@
1338
1629
  */
1339
1630
 
1340
1631
  /**
1341
- * @param {Component[]} elements
1632
+ * @param {Component[] | Component[][]} elements
1342
1633
  *
1343
1634
  * @return {string}
1344
1635
  */
@@ -1346,18 +1637,40 @@
1346
1637
  return elements.flat().join(',').replace(/,?([A-z]),?/g, '$1');
1347
1638
  }
1348
1639
 
1640
+ /**
1641
+ * @param {Point} point
1642
+ *
1643
+ * @return {Component[]}
1644
+ */
1349
1645
  function move(point) {
1350
1646
  return [ 'M', point.x, point.y ];
1351
1647
  }
1352
1648
 
1649
+ /**
1650
+ * @param {Point} point
1651
+ *
1652
+ * @return {Component[]}
1653
+ */
1353
1654
  function lineTo(point) {
1354
1655
  return [ 'L', point.x, point.y ];
1355
1656
  }
1356
1657
 
1658
+ /**
1659
+ * @param {Point} p1
1660
+ * @param {Point} p2
1661
+ * @param {Point} p3
1662
+ *
1663
+ * @return {Component[]}
1664
+ */
1357
1665
  function curveTo(p1, p2, p3) {
1358
1666
  return [ 'C', p1.x, p1.y, p2.x, p2.y, p3.x, p3.y ];
1359
1667
  }
1360
1668
 
1669
+ /**
1670
+ * @param {Point[]} waypoints
1671
+ * @param {number} [cornerRadius]
1672
+ * @return {Component[][]}
1673
+ */
1361
1674
  function drawPath(waypoints, cornerRadius) {
1362
1675
  const pointCount = waypoints.length;
1363
1676
 
@@ -1421,7 +1734,7 @@
1421
1734
 
1422
1735
  /**
1423
1736
  * @param {Point[]} points
1424
- * @param {*} [attrs]
1737
+ * @param {number|Object} [attrs]
1425
1738
  * @param {number} [radius]
1426
1739
  *
1427
1740
  * @return {SVGElement}
@@ -1470,54 +1783,75 @@
1470
1783
  /**
1471
1784
  * Checks if eventDefinition of the given element matches with semantic type.
1472
1785
  *
1473
- * @return {boolean} true if element is of the given semantic type
1786
+ * @param {ModdleElement} event
1787
+ * @param {string} eventDefinitionType
1788
+ *
1789
+ * @return {boolean}
1474
1790
  */
1475
- function isTypedEvent(event, eventDefinitionType, filter) {
1476
-
1477
- function matches(definition, filter) {
1478
- return every(filter, function(val, key) {
1479
-
1480
- // we want a == conversion here, to be able to catch
1481
- // undefined == false and friends
1482
- /* jshint -W116 */
1483
- return definition[key] == val;
1484
- });
1485
- }
1486
-
1791
+ function isTypedEvent(event, eventDefinitionType) {
1487
1792
  return some(event.eventDefinitions, function(definition) {
1488
- return definition.$type === eventDefinitionType && matches(event, filter);
1793
+ return definition.$type === eventDefinitionType;
1489
1794
  });
1490
1795
  }
1491
1796
 
1797
+ /**
1798
+ * Check if element is a throw event.
1799
+ *
1800
+ * @param {ModdleElement} event
1801
+ *
1802
+ * @return {boolean}
1803
+ */
1492
1804
  function isThrowEvent(event) {
1493
1805
  return (event.$type === 'bpmn:IntermediateThrowEvent') || (event.$type === 'bpmn:EndEvent');
1494
1806
  }
1495
1807
 
1808
+ /**
1809
+ * Check if element is a throw event.
1810
+ *
1811
+ * @param {ModdleElement} element
1812
+ *
1813
+ * @return {boolean}
1814
+ */
1496
1815
  function isCollection(element) {
1497
1816
  var dataObject = element.dataObjectRef;
1498
1817
 
1499
1818
  return element.isCollection || (dataObject && dataObject.isCollection);
1500
1819
  }
1501
1820
 
1502
- function getSemantic(element) {
1503
- return element.businessObject;
1504
- }
1505
-
1506
1821
 
1507
1822
  // color access //////////////////////
1508
1823
 
1824
+ /**
1825
+ * @param {Element} element
1826
+ * @param {string} [defaultColor]
1827
+ *
1828
+ * @return {string}
1829
+ */
1509
1830
  function getFillColor(element, defaultColor) {
1510
1831
  var di = getDi(element);
1511
1832
 
1512
1833
  return di.get('color:background-color') || di.get('bioc:fill') || defaultColor || 'white';
1513
1834
  }
1514
1835
 
1836
+ /**
1837
+ * @param {Element} element
1838
+ * @param {string} [defaultColor]
1839
+ *
1840
+ * @return {string}
1841
+ */
1515
1842
  function getStrokeColor(element, defaultColor) {
1516
1843
  var di = getDi(element);
1517
1844
 
1518
1845
  return di.get('color:border-color') || di.get('bioc:stroke') || defaultColor || black;
1519
1846
  }
1520
1847
 
1848
+ /**
1849
+ * @param {Element} element
1850
+ * @param {string} [defaultColor]
1851
+ * @param {string} [defaultStrokeColor]
1852
+ *
1853
+ * @return {string}
1854
+ */
1521
1855
  function getLabelColor(element, defaultColor, defaultStrokeColor) {
1522
1856
  var di = getDi(element),
1523
1857
  label = di.get('label');
@@ -1528,6 +1862,11 @@
1528
1862
 
1529
1863
  // cropping path customizations //////////////////////
1530
1864
 
1865
+ /**
1866
+ * @param {ShapeLike} shape
1867
+ *
1868
+ * @return {string} path
1869
+ */
1531
1870
  function getCirclePath(shape) {
1532
1871
 
1533
1872
  var cx = shape.x + shape.width / 2,
@@ -1545,6 +1884,12 @@
1545
1884
  return componentsToPath(circlePath);
1546
1885
  }
1547
1886
 
1887
+ /**
1888
+ * @param {ShapeLike} shape
1889
+ * @param {number} [borderRadius]
1890
+ *
1891
+ * @return {string} path
1892
+ */
1548
1893
  function getRoundRectPath(shape, borderRadius) {
1549
1894
 
1550
1895
  var x = shape.x,
@@ -1568,6 +1913,11 @@
1568
1913
  return componentsToPath(roundRectPath);
1569
1914
  }
1570
1915
 
1916
+ /**
1917
+ * @param {ShapeLike} shape
1918
+ *
1919
+ * @return {string} path
1920
+ */
1571
1921
  function getDiamondPath(shape) {
1572
1922
 
1573
1923
  var width = shape.width,
@@ -1588,6 +1938,11 @@
1588
1938
  return componentsToPath(diamondPath);
1589
1939
  }
1590
1940
 
1941
+ /**
1942
+ * @param {ShapeLike} shape
1943
+ *
1944
+ * @return {string} path
1945
+ */
1591
1946
  function getRectPath(shape) {
1592
1947
  var x = shape.x,
1593
1948
  y = shape.y,
@@ -2169,11 +2524,11 @@
2169
2524
  }
2170
2525
 
2171
2526
  /**
2172
- * @param {SVGElement} element
2527
+ * @param {SVGElement} gfx
2173
2528
  * @param {number} x
2174
2529
  * @param {number} y
2175
- * @param {number} angle
2176
- * @param {number} amount
2530
+ * @param {number} [angle]
2531
+ * @param {number} [amount]
2177
2532
  */
2178
2533
  function transform(gfx, x, y, angle, amount) {
2179
2534
  var translate = createTransform();
@@ -2190,7 +2545,7 @@
2190
2545
 
2191
2546
 
2192
2547
  /**
2193
- * @param {SVGElement} element
2548
+ * @param {SVGElement} gfx
2194
2549
  * @param {number} x
2195
2550
  * @param {number} y
2196
2551
  */
@@ -2203,7 +2558,7 @@
2203
2558
 
2204
2559
 
2205
2560
  /**
2206
- * @param {SVGElement} element
2561
+ * @param {SVGElement} gfx
2207
2562
  * @param {number} angle
2208
2563
  */
2209
2564
  function rotate(gfx, angle) {
@@ -2386,6 +2741,29 @@
2386
2741
 
2387
2742
  var ELEMENT_LABEL_DISTANCE = 10;
2388
2743
 
2744
+ /**
2745
+ * @typedef { Partial<{
2746
+ * defaultFillColor: string,
2747
+ * defaultStrokeColor: string,
2748
+ * defaultLabelColor: string
2749
+ * }> } BpmnRendererConfig
2750
+ */
2751
+
2752
+ /**
2753
+ * @typedef { import('../model').DiagramElement } DiagramElement
2754
+ */
2755
+
2756
+ /**
2757
+ * A renderer for BPMN elements
2758
+ *
2759
+ * @param {BpmnRendererConfig} config
2760
+ * @param {import('diagram-js/lib/core/EventBus').default} eventBus
2761
+ * @param {import('diagram-js/lib/draw/Styles').default} styles
2762
+ * @param {import('./PathMap').default} pathMap
2763
+ * @param {import('diagram-js/lib/core/Canvas').default} canvas
2764
+ * @param {import('./TextRenderer').default} textRenderer
2765
+ * @param {number} [priority]
2766
+ */
2389
2767
  function BpmnRenderer(
2390
2768
  config, eventBus, styles, pathMap,
2391
2769
  canvas, textRenderer, priority) {
@@ -2745,7 +3123,7 @@
2745
3123
 
2746
3124
  function renderEventContent(element, parentGfx) {
2747
3125
 
2748
- var event = getSemantic(element);
3126
+ var event = getBusinessObject(element);
2749
3127
  var isThrowing = isThrowEvent(event);
2750
3128
 
2751
3129
  if (event.eventDefinitions && event.eventDefinitions.length > 1) {
@@ -2818,7 +3196,7 @@
2818
3196
  }
2819
3197
 
2820
3198
  function renderEmbeddedLabel(parentGfx, element, align) {
2821
- var semantic = getSemantic(element);
3199
+ var semantic = getBusinessObject(element);
2822
3200
 
2823
3201
  return renderLabel(parentGfx, semantic.name, {
2824
3202
  box: element,
@@ -2884,7 +3262,7 @@
2884
3262
  stroke: getStrokeColor(element, defaultStrokeColor)
2885
3263
  };
2886
3264
 
2887
- var semantic = getSemantic(element);
3265
+ var semantic = getBusinessObject(element);
2888
3266
 
2889
3267
  if (!semantic.isInterrupting) {
2890
3268
  attrs = {
@@ -3345,7 +3723,7 @@
3345
3723
  return task;
3346
3724
  },
3347
3725
  'bpmn:ReceiveTask' : function(parentGfx, element) {
3348
- var semantic = getSemantic(element);
3726
+ var semantic = getBusinessObject(element);
3349
3727
 
3350
3728
  var task = renderer('bpmn:Task')(parentGfx, element);
3351
3729
  var pathData;
@@ -3501,12 +3879,12 @@
3501
3879
  stroke: getStrokeColor(element, defaultStrokeColor),
3502
3880
  strokeWidth
3503
3881
  });
3504
- var text = getSemantic(element).name;
3882
+ var text = getBusinessObject(element).name;
3505
3883
  renderLaneLabel(parentGfx, text, element);
3506
3884
  } else {
3507
3885
 
3508
3886
  // collapsed pool draw text inline
3509
- var text2 = getSemantic(element).name;
3887
+ var text2 = getBusinessObject(element).name;
3510
3888
  renderLabel(parentGfx, text2, {
3511
3889
  box: element, align: 'center-middle',
3512
3890
  style: {
@@ -3515,7 +3893,7 @@
3515
3893
  });
3516
3894
  }
3517
3895
 
3518
- var participantMultiplicity = !!(getSemantic(element).participantMultiplicity);
3896
+ var participantMultiplicity = !!(getBusinessObject(element).participantMultiplicity);
3519
3897
 
3520
3898
  if (participantMultiplicity) {
3521
3899
  renderer('ParticipantMultiplicityMarker')(parentGfx, element);
@@ -3532,7 +3910,7 @@
3532
3910
  ...attrs
3533
3911
  });
3534
3912
 
3535
- var semantic = getSemantic(element);
3913
+ var semantic = getBusinessObject(element);
3536
3914
 
3537
3915
  if (semantic.$type === 'bpmn:Lane') {
3538
3916
  var text = semantic.name;
@@ -3623,7 +4001,7 @@
3623
4001
  },
3624
4002
  'bpmn:EventBasedGateway': function(parentGfx, element) {
3625
4003
 
3626
- var semantic = getSemantic(element);
4004
+ var semantic = getBusinessObject(element);
3627
4005
 
3628
4006
  var diamond = renderer('bpmn:Gateway')(parentGfx, element);
3629
4007
 
@@ -3705,7 +4083,7 @@
3705
4083
  stroke: getStrokeColor(element, defaultStrokeColor)
3706
4084
  });
3707
4085
 
3708
- var sequenceFlow = getSemantic(element);
4086
+ var sequenceFlow = getBusinessObject(element);
3709
4087
 
3710
4088
  var source;
3711
4089
 
@@ -3732,7 +4110,7 @@
3732
4110
  },
3733
4111
  'bpmn:Association': function(parentGfx, element, attrs) {
3734
4112
 
3735
- var semantic = getSemantic(element);
4113
+ var semantic = getBusinessObject(element);
3736
4114
 
3737
4115
  var fill = getFillColor(element, defaultFillColor),
3738
4116
  stroke = getStrokeColor(element, defaultStrokeColor);
@@ -3772,7 +4150,7 @@
3772
4150
  },
3773
4151
  'bpmn:MessageFlow': function(parentGfx, element) {
3774
4152
 
3775
- var semantic = getSemantic(element),
4153
+ var semantic = getBusinessObject(element),
3776
4154
  di = getDi(element);
3777
4155
 
3778
4156
  var fill = getFillColor(element, defaultFillColor),
@@ -3847,7 +4225,7 @@
3847
4225
  stroke: getStrokeColor(element, defaultStrokeColor)
3848
4226
  });
3849
4227
 
3850
- var semantic = getSemantic(element);
4228
+ var semantic = getBusinessObject(element);
3851
4229
 
3852
4230
  if (isCollection(semantic)) {
3853
4231
  renderDataItemCollection(parentGfx, element);
@@ -3903,7 +4281,7 @@
3903
4281
  },
3904
4282
  'bpmn:BoundaryEvent': function(parentGfx, element) {
3905
4283
 
3906
- var semantic = getSemantic(element),
4284
+ var semantic = getBusinessObject(element),
3907
4285
  cancel = semantic.cancelActivity;
3908
4286
 
3909
4287
  var attrs = {
@@ -3969,7 +4347,7 @@
3969
4347
  stroke: getStrokeColor(element, defaultStrokeColor)
3970
4348
  });
3971
4349
 
3972
- var text = getSemantic(element).text || '';
4350
+ var text = getBusinessObject(element).text || '';
3973
4351
  renderLabel(parentGfx, text, {
3974
4352
  box: element,
3975
4353
  align: 'left-top',
@@ -4118,7 +4496,7 @@
4118
4496
  };
4119
4497
 
4120
4498
  function attachTaskMarkers(parentGfx, element, taskMarkers) {
4121
- var obj = getSemantic(element);
4499
+ var obj = getBusinessObject(element);
4122
4500
 
4123
4501
  var subprocess = taskMarkers && taskMarkers.indexOf('SubProcessMarker') !== -1;
4124
4502
  var position;
@@ -4212,10 +4590,23 @@
4212
4590
  ];
4213
4591
 
4214
4592
 
4593
+ /**
4594
+ * @param {DiagramElement} element
4595
+ *
4596
+ * @return {boolean}
4597
+ */
4215
4598
  BpmnRenderer.prototype.canRender = function(element) {
4216
4599
  return is$1(element, 'bpmn:BaseElement');
4217
4600
  };
4218
4601
 
4602
+ /**
4603
+ * Draw shape into parentGfx.
4604
+ *
4605
+ * @param {SVGElement} parentGfx
4606
+ * @param {DiagramElement} element
4607
+ *
4608
+ * @return {SVGElement} mainGfx
4609
+ */
4219
4610
  BpmnRenderer.prototype.drawShape = function(parentGfx, element) {
4220
4611
  var type = element.type;
4221
4612
  var h = this._renderer(type);
@@ -4224,6 +4615,14 @@
4224
4615
  return h(parentGfx, element);
4225
4616
  };
4226
4617
 
4618
+ /**
4619
+ * Draw connection into parentGfx.
4620
+ *
4621
+ * @param {SVGElement} parentGfx
4622
+ * @param {DiagramElement} element
4623
+ *
4624
+ * @return {SVGElement} mainGfx
4625
+ */
4227
4626
  BpmnRenderer.prototype.drawConnection = function(parentGfx, element) {
4228
4627
  var type = element.type;
4229
4628
  var h = this._renderer(type);
@@ -4232,6 +4631,13 @@
4232
4631
  return h(parentGfx, element);
4233
4632
  };
4234
4633
 
4634
+ /**
4635
+ * Get shape path.
4636
+ *
4637
+ * @param {DiagramElement} element
4638
+ *
4639
+ * @return {string} path
4640
+ */
4235
4641
  BpmnRenderer.prototype.getShapePath = function(element) {
4236
4642
 
4237
4643
  if (is$1(element, 'bpmn:Event')) {
@@ -4251,16 +4657,55 @@
4251
4657
 
4252
4658
  /**
4253
4659
  * @typedef {import('../util/Types').Dimensions} Dimensions
4660
+ *
4661
+ * @typedef { {
4662
+ * top: number;
4663
+ * left: number;
4664
+ * right: number;
4665
+ * bottom: number;
4666
+ * } } Padding
4667
+ *
4668
+ * @typedef { number | Partial<Padding> } PaddingConfig
4669
+ *
4670
+ * @typedef { {
4671
+ * horizontal: 'center' | 'left';
4672
+ * vertical: 'top' | 'center';
4673
+ * } } Alignment
4674
+ *
4675
+ * @typedef { 'center-middle' | 'center-top' } AlignmentConfig
4676
+ *
4677
+ * @typedef { Partial<{
4678
+ * align: AlignmentConfig;
4679
+ * style: Record<string, number | string>;
4680
+ * padding: PaddingConfig;
4681
+ * }> } BaseTextConfig
4682
+ *
4683
+ * @typedef { BaseTextConfig & Partial<{
4684
+ * size: Dimensions;
4685
+ * }> } TextConfig
4686
+ *
4687
+ * @typedef { BaseTextConfig & Partial<{
4688
+ * box: Dimensions;
4689
+ * fitBox: boolean;
4690
+ * }> } TextLayoutConfig
4691
+ *
4692
+ * @typedef { Dimensions & {
4693
+ * text: string;
4694
+ * } } LineDescriptor
4254
4695
  */
4255
4696
 
4256
4697
  var DEFAULT_BOX_PADDING = 0;
4257
4698
 
4258
- var DEFAULT_LABEL_SIZE$1 = {
4699
+ var DEFAULT_LABEL_SIZE = {
4259
4700
  width: 150,
4260
4701
  height: 50
4261
4702
  };
4262
4703
 
4263
4704
 
4705
+ /**
4706
+ * @param {AlignmentConfig} align
4707
+ * @return {Alignment}
4708
+ */
4264
4709
  function parseAlign(align) {
4265
4710
 
4266
4711
  var parts = align.split('-');
@@ -4271,6 +4716,11 @@
4271
4716
  };
4272
4717
  }
4273
4718
 
4719
+ /**
4720
+ * @param {PaddingConfig} padding
4721
+ *
4722
+ * @return {Padding}
4723
+ */
4274
4724
  function parsePadding(padding) {
4275
4725
 
4276
4726
  if (isObject(padding)) {
@@ -4285,6 +4735,12 @@
4285
4735
  }
4286
4736
  }
4287
4737
 
4738
+ /**
4739
+ * @param {string} text
4740
+ * @param {SVGTextElement} fakeText
4741
+ *
4742
+ * @return {import('../util/Types').Dimensions}
4743
+ */
4288
4744
  function getTextBBox(text, fakeText) {
4289
4745
 
4290
4746
  fakeText.textContent = text;
@@ -4327,8 +4783,10 @@
4327
4783
  * Alters the lines passed.
4328
4784
  *
4329
4785
  * @param {string[]} lines
4786
+ * @param {number} maxWidth
4787
+ * @param {SVGTextElement} fakeText
4330
4788
  *
4331
- * @return {Object} the line descriptor, an object { width, height, text }
4789
+ * @return {LineDescriptor} the line descriptor
4332
4790
  */
4333
4791
  function layoutNext(lines, maxWidth, fakeText) {
4334
4792
 
@@ -4351,6 +4809,14 @@
4351
4809
  }
4352
4810
  }
4353
4811
 
4812
+ /**
4813
+ * @param {string[]} lines
4814
+ * @param {string} fitLine
4815
+ * @param {string} originalLine
4816
+ * @param {Dimensions} textBBox
4817
+ *
4818
+ * @return {LineDescriptor}
4819
+ */
4354
4820
  function fit(lines, fitLine, originalLine, textBBox) {
4355
4821
  if (fitLine.length < originalLine.length) {
4356
4822
  var remainder = originalLine.slice(fitLine.length).trim();
@@ -4414,6 +4880,13 @@
4414
4880
  }
4415
4881
 
4416
4882
 
4883
+ /**
4884
+ * @param {string} line
4885
+ * @param {number} width
4886
+ * @param {number} maxWidth
4887
+ *
4888
+ * @return {string}
4889
+ */
4417
4890
  function shortenLine(line, width, maxWidth) {
4418
4891
  var length = Math.max(line.length * (maxWidth / width), 1);
4419
4892
 
@@ -4430,6 +4903,9 @@
4430
4903
  }
4431
4904
 
4432
4905
 
4906
+ /**
4907
+ * @return {SVGSVGElement}
4908
+ */
4433
4909
  function getHelperSvg() {
4434
4910
  var helperSvg = document.getElementById('helper-svg');
4435
4911
 
@@ -4457,16 +4933,12 @@
4457
4933
  /**
4458
4934
  * Creates a new label utility
4459
4935
  *
4460
- * @param {Object} config
4461
- * @param {Dimensions} config.size
4462
- * @param {number} config.padding
4463
- * @param {Object} config.style
4464
- * @param {string} config.align
4936
+ * @param {TextConfig} config
4465
4937
  */
4466
4938
  function Text(config) {
4467
4939
 
4468
4940
  this._config = assign$1({}, {
4469
- size: DEFAULT_LABEL_SIZE$1,
4941
+ size: DEFAULT_LABEL_SIZE,
4470
4942
  padding: DEFAULT_BOX_PADDING,
4471
4943
  style: {},
4472
4944
  align: 'center-top'
@@ -4477,7 +4949,7 @@
4477
4949
  * Returns the layouted text as an SVG element.
4478
4950
  *
4479
4951
  * @param {string} text
4480
- * @param {Object} options
4952
+ * @param {TextLayoutConfig} options
4481
4953
  *
4482
4954
  * @return {SVGElement}
4483
4955
  */
@@ -4489,7 +4961,7 @@
4489
4961
  * Returns a labels layouted dimensions.
4490
4962
  *
4491
4963
  * @param {string} text to layout
4492
- * @param {Object} options
4964
+ * @param {TextLayoutConfig} options
4493
4965
  *
4494
4966
  * @return {Dimensions}
4495
4967
  */
@@ -4500,18 +4972,13 @@
4500
4972
  /**
4501
4973
  * Creates and returns a label and its bounding box.
4502
4974
  *
4503
- * @method Text#createText
4504
- *
4505
4975
  * @param {string} text the text to render on the label
4506
- * @param {Object} options
4507
- * @param {string} options.align how to align in the bounding box.
4508
- * Any of { 'center-middle', 'center-top' },
4509
- * defaults to 'center-top'.
4510
- * @param {string} options.style style to be applied to the text
4511
- * @param {boolean} options.fitBox indicates if box will be recalculated to
4512
- * fit text
4976
+ * @param {TextLayoutConfig} options
4513
4977
  *
4514
- * @return {Object} { element, dimensions }
4978
+ * @return { {
4979
+ * element: SVGElement,
4980
+ * dimensions: Dimensions
4981
+ * } }
4515
4982
  */
4516
4983
  Text.prototype.layoutText = function(text, options) {
4517
4984
  var box = assign$1({}, this._config.size, options.box),
@@ -4627,7 +5094,30 @@
4627
5094
 
4628
5095
  var MIN_TEXT_ANNOTATION_HEIGHT = 30;
4629
5096
 
5097
+ /**
5098
+ * @typedef { {
5099
+ * fontFamily: string;
5100
+ * fontSize: number;
5101
+ * fontWeight: string;
5102
+ * lineHeight: number;
5103
+ * } } TextRendererStyle
5104
+ *
5105
+ * @typedef { {
5106
+ * defaultStyle?: Partial<TextRendererStyle>;
5107
+ * externalStyle?: Partial<TextRendererStyle>;
5108
+ * } } TextRendererConfig
5109
+ *
5110
+ * @typedef { import('diagram-js/lib/util/Text').TextLayoutConfig } TextLayoutConfig
5111
+ *
5112
+ * @typedef { import('diagram-js/lib/util/Types').Rect } Rect
5113
+ */
5114
+
4630
5115
 
5116
+ /**
5117
+ * Renders text and computes text bounding boxes.
5118
+ *
5119
+ * @param {TextRendererConfig} [config]
5120
+ */
4631
5121
  function TextRenderer(config) {
4632
5122
 
4633
5123
  var defaultStyle = assign$1({
@@ -4651,19 +5141,17 @@
4651
5141
  * Get the new bounds of an externally rendered,
4652
5142
  * layouted label.
4653
5143
  *
4654
- * @param {Bounds} bounds
4655
- * @param {string} text
5144
+ * @param {Rect} bounds
5145
+ * @param {string} text
4656
5146
  *
4657
- * @return {Bounds}
5147
+ * @return {Rect}
4658
5148
  */
4659
5149
  this.getExternalLabelBounds = function(bounds, text) {
4660
5150
 
4661
5151
  var layoutedDimensions = textUtil.getDimensions(text, {
4662
5152
  box: {
4663
5153
  width: 90,
4664
- height: 30,
4665
- x: bounds.width / 2 + bounds.x,
4666
- y: bounds.height / 2 + bounds.y
5154
+ height: 30
4667
5155
  },
4668
5156
  style: externalStyle
4669
5157
  });
@@ -4681,10 +5169,10 @@
4681
5169
  /**
4682
5170
  * Get the new bounds of text annotation.
4683
5171
  *
4684
- * @param {Bounds} bounds
4685
- * @param {string} text
5172
+ * @param {Rect} bounds
5173
+ * @param {string} text
4686
5174
  *
4687
- * @return {Bounds}
5175
+ * @return {Rect}
4688
5176
  */
4689
5177
  this.getTextAnnotationBounds = function(bounds, text) {
4690
5178
 
@@ -4707,7 +5195,7 @@
4707
5195
  * Create a layouted text element.
4708
5196
  *
4709
5197
  * @param {string} text
4710
- * @param {Object} [options]
5198
+ * @param {TextLayoutConfig} [options]
4711
5199
  *
4712
5200
  * @return {SVGElement} rendered text
4713
5201
  */
@@ -4736,9 +5224,8 @@
4736
5224
  ];
4737
5225
 
4738
5226
  /**
4739
- * Map containing SVG paths needed by BpmnRenderer.
5227
+ * Map containing SVG paths needed by BpmnRenderer
4740
5228
  */
4741
-
4742
5229
  function PathMap() {
4743
5230
 
4744
5231
  /**
@@ -5080,6 +5567,13 @@
5080
5567
  }
5081
5568
  };
5082
5569
 
5570
+ /**
5571
+ * Return raw path for the given ID.
5572
+ *
5573
+ * @param {string} pathId
5574
+ *
5575
+ * @return {string} raw path
5576
+ */
5083
5577
  this.getRawPath = function getRawPath(pathId) {
5084
5578
  return this.pathMap[pathId].d;
5085
5579
  };
@@ -5132,6 +5626,7 @@
5132
5626
  * </ul>
5133
5627
  * </p>
5134
5628
  *
5629
+ * @return {string} scaled path
5135
5630
  */
5136
5631
  this.getScaledPath = function getScaledPath(pathId, param) {
5137
5632
  var rawPath = this.pathMap[pathId];
@@ -5215,7 +5710,9 @@
5215
5710
  };
5216
5711
 
5217
5712
  /**
5218
- * @typedef {import('./').Replacements} Replacements
5713
+ * @typedef { {
5714
+ * [key: string]: string;
5715
+ * } } TranslateReplacements
5219
5716
  */
5220
5717
 
5221
5718
  /**
@@ -5225,14 +5722,16 @@
5225
5722
  *
5226
5723
  * @example
5227
5724
  *
5725
+ * ```javascript
5228
5726
  * // use it inside any diagram component by injecting `translate`.
5229
5727
  *
5230
5728
  * function MyService(translate) {
5231
5729
  * alert(translate('HELLO {you}', { you: 'You!' }));
5232
5730
  * }
5731
+ * ```
5233
5732
  *
5234
5733
  * @param {string} template to interpolate
5235
- * @param {Replacements} [replacements] a map with substitutes
5734
+ * @param {TranslateReplacements} [replacements] a map with substitutes
5236
5735
  *
5237
5736
  * @return {string} the translated string
5238
5737
  */
@@ -5245,154 +5744,22 @@
5245
5744
  });
5246
5745
  }
5247
5746
 
5747
+ /**
5748
+ * @type { import('didi').ModuleDeclaration }
5749
+ */
5248
5750
  var TranslateModule = {
5249
5751
  translate: [ 'value', translate ]
5250
5752
  };
5251
5753
 
5252
- var DEFAULT_LABEL_SIZE = {
5253
- width: 90,
5254
- height: 20
5255
- };
5256
-
5257
- var FLOW_LABEL_INDENT = 15;
5258
-
5259
-
5260
- /**
5261
- * Returns true if the given semantic has an external label
5262
- *
5263
- * @param {BpmnElement} semantic
5264
- * @return {boolean} true if has label
5265
- */
5266
- function isLabelExternal(semantic) {
5267
- return is$1(semantic, 'bpmn:Event') ||
5268
- is$1(semantic, 'bpmn:Gateway') ||
5269
- is$1(semantic, 'bpmn:DataStoreReference') ||
5270
- is$1(semantic, 'bpmn:DataObjectReference') ||
5271
- is$1(semantic, 'bpmn:DataInput') ||
5272
- is$1(semantic, 'bpmn:DataOutput') ||
5273
- is$1(semantic, 'bpmn:SequenceFlow') ||
5274
- is$1(semantic, 'bpmn:MessageFlow') ||
5275
- is$1(semantic, 'bpmn:Group');
5276
- }
5277
-
5278
- /**
5279
- * Get the position for sequence flow labels
5280
- *
5281
- * @param {Array<Point>} waypoints
5282
- * @return {Point} the label position
5283
- */
5284
- function getFlowLabelPosition(waypoints) {
5285
-
5286
- // get the waypoints mid
5287
- var mid = waypoints.length / 2 - 1;
5288
-
5289
- var first = waypoints[Math.floor(mid)];
5290
- var second = waypoints[Math.ceil(mid + 0.01)];
5291
-
5292
- // get position
5293
- var position = getWaypointsMid(waypoints);
5294
-
5295
- // calculate angle
5296
- var angle = Math.atan((second.y - first.y) / (second.x - first.x));
5297
-
5298
- var x = position.x,
5299
- y = position.y;
5300
-
5301
- if (Math.abs(angle) < Math.PI / 2) {
5302
- y -= FLOW_LABEL_INDENT;
5303
- } else {
5304
- x += FLOW_LABEL_INDENT;
5305
- }
5306
-
5307
- return { x: x, y: y };
5308
- }
5309
-
5310
-
5311
- /**
5312
- * Get the middle of a number of waypoints
5313
- *
5314
- * @param {Array<Point>} waypoints
5315
- * @return {Point} the mid point
5316
- */
5317
- function getWaypointsMid(waypoints) {
5318
-
5319
- var mid = waypoints.length / 2 - 1;
5320
-
5321
- var first = waypoints[Math.floor(mid)];
5322
- var second = waypoints[Math.ceil(mid + 0.01)];
5323
-
5324
- return {
5325
- x: first.x + (second.x - first.x) / 2,
5326
- y: first.y + (second.y - first.y) / 2
5327
- };
5328
- }
5329
-
5330
-
5331
- function getExternalLabelMid(element) {
5332
-
5333
- if (element.waypoints) {
5334
- return getFlowLabelPosition(element.waypoints);
5335
- } else if (is$1(element, 'bpmn:Group')) {
5336
- return {
5337
- x: element.x + element.width / 2,
5338
- y: element.y + DEFAULT_LABEL_SIZE.height / 2
5339
- };
5340
- } else {
5341
- return {
5342
- x: element.x + element.width / 2,
5343
- y: element.y + element.height + DEFAULT_LABEL_SIZE.height / 2
5344
- };
5345
- }
5754
+ function getDefaultExportFromCjs (x) {
5755
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5346
5756
  }
5347
5757
 
5348
-
5349
5758
  /**
5350
- * Returns the bounds of an elements label, parsed from the elements DI or
5351
- * generated from its bounds.
5759
+ * @param {Point} point
5352
5760
  *
5353
- * @param {BpmndDi} di
5354
- * @param {djs.model.Base} element
5761
+ * @returns {Point}
5355
5762
  */
5356
- function getExternalLabelBounds(di, element) {
5357
-
5358
- var mid,
5359
- size,
5360
- bounds,
5361
- label = di.label;
5362
-
5363
- if (label && label.bounds) {
5364
- bounds = label.bounds;
5365
-
5366
- size = {
5367
- width: Math.max(DEFAULT_LABEL_SIZE.width, bounds.width),
5368
- height: bounds.height
5369
- };
5370
-
5371
- mid = {
5372
- x: bounds.x + bounds.width / 2,
5373
- y: bounds.y + bounds.height / 2
5374
- };
5375
- } else {
5376
-
5377
- mid = getExternalLabelMid(element);
5378
-
5379
- size = DEFAULT_LABEL_SIZE;
5380
- }
5381
-
5382
- return assign$1({
5383
- x: mid.x - size.width / 2,
5384
- y: mid.y - size.height / 2
5385
- }, size);
5386
- }
5387
-
5388
- function isLabel(element) {
5389
- return element && !!element.labelTarget;
5390
- }
5391
-
5392
- function getDefaultExportFromCjs (x) {
5393
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5394
- }
5395
-
5396
5763
  function roundPoint(point) {
5397
5764
 
5398
5765
  return {
@@ -5513,7 +5880,7 @@
5513
5880
  /**
5514
5881
  * Get the mid of the given Element.
5515
5882
  *
5516
- * @param {Connection} connection
5883
+ * @param {Element} element
5517
5884
  *
5518
5885
  * @return {Point}
5519
5886
  */
@@ -5543,6 +5910,23 @@
5543
5910
  return '<' + e.$type + (e.id ? ' id="' + e.id : '') + '" />';
5544
5911
  }
5545
5912
 
5913
+ /**
5914
+ * @typedef {import('diagram-js/lib/core/Canvas').default} Canvas
5915
+ * @typedef {import('diagram-js/lib/core/ElementRegistry').default} ElementRegistry
5916
+ * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
5917
+ * @typedef {import('diagram-js/lib/i18n/translate/translate').default} Translate
5918
+ *
5919
+ * @typedef {import('../features/modeling/ElementFactory').default} ElementFactory
5920
+ * @typedef {import('../draw/TextRenderer').default} TextRenderer
5921
+ *
5922
+ * @typedef {import('../model/Types').Element} Element
5923
+ * @typedef {import('../model/Types').Label} Label
5924
+ * @typedef {import('../model/Types').Shape} Shape
5925
+ * @typedef {import('../model/Types').Connection} Connection
5926
+ * @typedef {import('../model/Types').Root} Root
5927
+ * @typedef {import('../model/Types').ModdleElement} ModdleElement
5928
+ */
5929
+
5546
5930
  /**
5547
5931
  * @param {ModdleElement} semantic
5548
5932
  * @param {ModdleElement} di
@@ -5614,8 +5998,14 @@
5614
5998
 
5615
5999
 
5616
6000
  /**
5617
- * Add bpmn element (semantic) to the canvas onto the
5618
- * specified parent shape.
6001
+ * Add a BPMN element (semantic) to the canvas making it a child of the
6002
+ * given parent.
6003
+ *
6004
+ * @param {ModdleElement} semantic
6005
+ * @param {ModdleElement} di
6006
+ * @param {Shape} parentElement
6007
+ *
6008
+ * @return {Shape | Root | Connection}
5619
6009
  */
5620
6010
  BpmnImporter.prototype.add = function(semantic, di, parentElement) {
5621
6011
  var element,
@@ -5724,10 +6114,10 @@
5724
6114
 
5725
6115
 
5726
6116
  /**
5727
- * Attach the boundary element to the given host
6117
+ * Attach a boundary element to the given host.
5728
6118
  *
5729
6119
  * @param {ModdleElement} boundarySemantic
5730
- * @param {djs.model.Base} boundaryElement
6120
+ * @param {Shape} boundaryElement
5731
6121
  */
5732
6122
  BpmnImporter.prototype._attachBoundary = function(boundarySemantic, boundaryElement) {
5733
6123
  var translate = this._translate;
@@ -5760,7 +6150,13 @@
5760
6150
 
5761
6151
 
5762
6152
  /**
5763
- * add label for an element
6153
+ * Add a label to a given element.
6154
+ *
6155
+ * @param {ModdleElement} semantic
6156
+ * @param {ModdleElement} di
6157
+ * @param {Element} element
6158
+ *
6159
+ * @return {Label}
5764
6160
  */
5765
6161
  BpmnImporter.prototype.addLabel = function(semantic, di, element) {
5766
6162
  var bounds,
@@ -5792,11 +6188,14 @@
5792
6188
  };
5793
6189
 
5794
6190
  /**
5795
- * Return the drawn connection end based on the given side.
6191
+ * Get the source or target of the given connection.
6192
+ *
6193
+ * @param {ModdleElement} semantic
6194
+ * @param {'source' | 'target'} side
5796
6195
  *
5797
- * @throws {Error} if the end is not yet drawn
6196
+ * @return {Element}
5798
6197
  */
5799
- BpmnImporter.prototype._getEnd = function(semantic, side) {
6198
+ BpmnImporter.prototype._getConnectedElement = function(semantic, side) {
5800
6199
 
5801
6200
  var element,
5802
6201
  refSemantic,
@@ -5834,11 +6233,11 @@
5834
6233
  };
5835
6234
 
5836
6235
  BpmnImporter.prototype._getSource = function(semantic) {
5837
- return this._getEnd(semantic, 'source');
6236
+ return this._getConnectedElement(semantic, 'source');
5838
6237
  };
5839
6238
 
5840
6239
  BpmnImporter.prototype._getTarget = function(semantic) {
5841
- return this._getEnd(semantic, 'target');
6240
+ return this._getConnectedElement(semantic, 'target');
5842
6241
  };
5843
6242
 
5844
6243
 
@@ -5877,6 +6276,15 @@
5877
6276
  ]
5878
6277
  };
5879
6278
 
6279
+ /**
6280
+ * @typedef {import('../util/Types').Point} Point
6281
+ */
6282
+
6283
+ /**
6284
+ * @param {import('../core/EventBus').Event} event
6285
+ *
6286
+ * @return {Event}
6287
+ */
5880
6288
  function getOriginal(event) {
5881
6289
  return event.originalEvent || event.srcEvent;
5882
6290
  }
@@ -5885,22 +6293,43 @@
5885
6293
  return (/mac/i).test(navigator.platform);
5886
6294
  }
5887
6295
 
6296
+ /**
6297
+ * @param {MouseEvent} event
6298
+ * @param {string} button
6299
+ *
6300
+ * @return {boolean}
6301
+ */
5888
6302
  function isButton(event, button) {
5889
6303
  return (getOriginal(event) || event).button === button;
5890
6304
  }
5891
6305
 
6306
+ /**
6307
+ * @param {MouseEvent} event
6308
+ *
6309
+ * @return {boolean}
6310
+ */
5892
6311
  function isPrimaryButton(event) {
5893
6312
 
5894
6313
  // button === 0 -> left áka primary mouse button
5895
6314
  return isButton(event, 0);
5896
6315
  }
5897
6316
 
6317
+ /**
6318
+ * @param {MouseEvent} event
6319
+ *
6320
+ * @return {boolean}
6321
+ */
5898
6322
  function isAuxiliaryButton(event) {
5899
6323
 
5900
6324
  // button === 1 -> auxiliary áka wheel button
5901
6325
  return isButton(event, 1);
5902
6326
  }
5903
6327
 
6328
+ /**
6329
+ * @param {MouseEvent} event
6330
+ *
6331
+ * @return {boolean}
6332
+ */
5904
6333
  function hasPrimaryModifier(event) {
5905
6334
  var originalEvent = getOriginal(event) || event;
5906
6335
 
@@ -5916,7 +6345,11 @@
5916
6345
  }
5917
6346
  }
5918
6347
 
5919
-
6348
+ /**
6349
+ * @param {MouseEvent} event
6350
+ *
6351
+ * @return {boolean}
6352
+ */
5920
6353
  function hasSecondaryModifier(event) {
5921
6354
  var originalEvent = getOriginal(event) || event;
5922
6355
 
@@ -5924,11 +6357,13 @@
5924
6357
  }
5925
6358
 
5926
6359
  /**
5927
- * @typedef {import('../../model').Base} Base
6360
+ * @typedef {import('../../model/Types').Element} Element
5928
6361
  *
5929
6362
  * @typedef {import('../../core/ElementRegistry').default} ElementRegistry
5930
6363
  * @typedef {import('../../core/EventBus').default} EventBus
5931
6364
  * @typedef {import('../../draw/Styles').default} Styles
6365
+ *
6366
+ * @typedef {import('../../util/Types').Point} Point
5932
6367
  */
5933
6368
 
5934
6369
  function allowAll(event) { return true; }
@@ -5972,7 +6407,7 @@
5972
6407
  *
5973
6408
  * @param {string} type local event name, e.g. element.click.
5974
6409
  * @param {MouseEvent|TouchEvent} event native event
5975
- * @param {Base} [element] the diagram element to emit the event on;
6410
+ * @param {Element} [element] the diagram element to emit the event on;
5976
6411
  * defaults to the event target
5977
6412
  */
5978
6413
  function fire(type, event, element) {
@@ -6055,7 +6490,7 @@
6055
6490
  *
6056
6491
  * @param {string} eventName the name of the triggered DOM event
6057
6492
  * @param {MouseEvent|TouchEvent} event
6058
- * @param {Base} targetElement
6493
+ * @param {Element} targetElement
6059
6494
  */
6060
6495
  function triggerMouseEvent(eventName, event, targetElement) {
6061
6496
 
@@ -6221,7 +6656,7 @@
6221
6656
  /**
6222
6657
  * Create default hit for the given element.
6223
6658
  *
6224
- * @param {Base} element
6659
+ * @param {Element} element
6225
6660
  * @param {SVGElement} gfx
6226
6661
  *
6227
6662
  * @return {SVGElement} created hit
@@ -6248,7 +6683,7 @@
6248
6683
  * Create hits for the given waypoints.
6249
6684
  *
6250
6685
  * @param {SVGElement} gfx
6251
- * @param {Array<Point>} waypoints
6686
+ * @param {Point[]} waypoints
6252
6687
  *
6253
6688
  * @return {SVGElement}
6254
6689
  */
@@ -6267,7 +6702,7 @@
6267
6702
  * Create hits for a box.
6268
6703
  *
6269
6704
  * @param {SVGElement} gfx
6270
- * @param {string} hitType
6705
+ * @param {string} type
6271
6706
  * @param {Object} attrs
6272
6707
  *
6273
6708
  * @return {SVGElement}
@@ -6293,7 +6728,7 @@
6293
6728
  /**
6294
6729
  * Update default hit of the element.
6295
6730
  *
6296
- * @param {Base} element
6731
+ * @param {Element} element
6297
6732
  * @param {SVGElement} gfx
6298
6733
  *
6299
6734
  * @return {SVGElement} updated hit
@@ -6342,7 +6777,7 @@
6342
6777
  * @event element.hover
6343
6778
  *
6344
6779
  * @type {Object}
6345
- * @property {Base} element
6780
+ * @property {Element} element
6346
6781
  * @property {SVGElement} gfx
6347
6782
  * @property {Event} originalEvent
6348
6783
  */
@@ -6353,7 +6788,7 @@
6353
6788
  * @event element.out
6354
6789
  *
6355
6790
  * @type {Object}
6356
- * @property {Base} element
6791
+ * @property {Element} element
6357
6792
  * @property {SVGElement} gfx
6358
6793
  * @property {Event} originalEvent
6359
6794
  */
@@ -6364,7 +6799,7 @@
6364
6799
  * @event element.click
6365
6800
  *
6366
6801
  * @type {Object}
6367
- * @property {Base} element
6802
+ * @property {Element} element
6368
6803
  * @property {SVGElement} gfx
6369
6804
  * @property {Event} originalEvent
6370
6805
  */
@@ -6375,7 +6810,7 @@
6375
6810
  * @event element.dblclick
6376
6811
  *
6377
6812
  * @type {Object}
6378
- * @property {Base} element
6813
+ * @property {Element} element
6379
6814
  * @property {SVGElement} gfx
6380
6815
  * @property {Event} originalEvent
6381
6816
  */
@@ -6386,7 +6821,7 @@
6386
6821
  * @event element.mousedown
6387
6822
  *
6388
6823
  * @type {Object}
6389
- * @property {Base} element
6824
+ * @property {Element} element
6390
6825
  * @property {SVGElement} gfx
6391
6826
  * @property {Event} originalEvent
6392
6827
  */
@@ -6397,7 +6832,7 @@
6397
6832
  * @event element.mouseup
6398
6833
  *
6399
6834
  * @type {Object}
6400
- * @property {Base} element
6835
+ * @property {Element} element
6401
6836
  * @property {SVGElement} gfx
6402
6837
  * @property {Event} originalEvent
6403
6838
  */
@@ -6409,11 +6844,14 @@
6409
6844
  * @event element.contextmenu
6410
6845
  *
6411
6846
  * @type {Object}
6412
- * @property {Base} element
6847
+ * @property {Element} element
6413
6848
  * @property {SVGElement} gfx
6414
6849
  * @property {Event} originalEvent
6415
6850
  */
6416
6851
 
6852
+ /**
6853
+ * @type { import('didi').ModuleDeclaration }
6854
+ */
6417
6855
  var InteractionEventsModule = {
6418
6856
  __init__: [ 'interactionEvents' ],
6419
6857
  interactionEvents: [ 'type', InteractionEvents ]
@@ -6423,7 +6861,7 @@
6423
6861
  * Returns the surrounding bbox for all elements in
6424
6862
  * the array or the element primitive.
6425
6863
  *
6426
- * @param {Base|Base[]} elements
6864
+ * @param {Element|Element[]} elements
6427
6865
  * @param {boolean} [stopRecursion=false]
6428
6866
  *
6429
6867
  * @return {Rect}
@@ -6476,7 +6914,13 @@
6476
6914
  };
6477
6915
  }
6478
6916
 
6479
-
6917
+ /**
6918
+ * Get the element's type
6919
+ *
6920
+ * @param {Element} element
6921
+ *
6922
+ * @return {'connection' | 'shape' | 'root'}
6923
+ */
6480
6924
  function getType(element) {
6481
6925
 
6482
6926
  if ('waypoints' in element) {
@@ -6490,15 +6934,19 @@
6490
6934
  return 'root';
6491
6935
  }
6492
6936
 
6937
+ /**
6938
+ * @param {Element} element
6939
+ *
6940
+ * @return {boolean}
6941
+ */
6493
6942
  function isFrameElement(element) {
6494
-
6495
6943
  return !!(element && element.isFrame);
6496
6944
  }
6497
6945
 
6498
6946
  var LOW_PRIORITY$2 = 500;
6499
6947
 
6500
6948
  /**
6501
- * @typedef {import('../../model').Base} Base
6949
+ * @typedef {import('../../model/Types').Element} Element
6502
6950
  *
6503
6951
  * @typedef {import('../../core/EventBus').default} EventBus
6504
6952
  * @typedef {import('../../draw/Styles').default} Styles
@@ -6572,7 +7020,7 @@
6572
7020
  * element and an outline offset.
6573
7021
  *
6574
7022
  * @param {SVGElement} outline
6575
- * @param {Base} element
7023
+ * @param {Element} element
6576
7024
  */
6577
7025
  Outline.prototype.updateShapeOutline = function(outline, element) {
6578
7026
 
@@ -6591,7 +7039,7 @@
6591
7039
  * the connection and an outline offset.
6592
7040
  *
6593
7041
  * @param {SVGElement} outline
6594
- * @param {Base} element
7042
+ * @param {Element} connection
6595
7043
  */
6596
7044
  Outline.prototype.updateConnectionOutline = function(outline, connection) {
6597
7045
 
@@ -6609,12 +7057,16 @@
6609
7057
 
6610
7058
  Outline.$inject = [ 'eventBus', 'styles', 'elementRegistry' ];
6611
7059
 
7060
+ /**
7061
+ * @type { import('didi').ModuleDeclaration }
7062
+ */
6612
7063
  var OutlineModule = {
6613
7064
  __init__: [ 'outline' ],
6614
7065
  outline: [ 'type', Outline ]
6615
7066
  };
6616
7067
 
6617
7068
  /**
7069
+ * @typedef {import('../../core/Canvas').default} Canvas
6618
7070
  * @typedef {import('../../core/EventBus').default} EventBus
6619
7071
  */
6620
7072
 
@@ -6622,15 +7074,17 @@
6622
7074
  * A service that offers the current selection in a diagram.
6623
7075
  * Offers the api to control the selection, too.
6624
7076
  *
6625
- * @class
6626
- *
6627
7077
  * @param {EventBus} eventBus
7078
+ * @param {Canvas} canvas
6628
7079
  */
6629
7080
  function Selection(eventBus, canvas) {
6630
7081
 
6631
7082
  this._eventBus = eventBus;
6632
7083
  this._canvas = canvas;
6633
7084
 
7085
+ /**
7086
+ * @type {Object[]}
7087
+ */
6634
7088
  this._selectedElements = [];
6635
7089
 
6636
7090
  var self = this;
@@ -6647,7 +7101,11 @@
6647
7101
 
6648
7102
  Selection.$inject = [ 'eventBus', 'canvas' ];
6649
7103
 
6650
-
7104
+ /**
7105
+ * Deselect an element.
7106
+ *
7107
+ * @param {Object} element The element to deselect.
7108
+ */
6651
7109
  Selection.prototype.deselect = function(element) {
6652
7110
  var selectedElements = this._selectedElements;
6653
7111
 
@@ -6662,26 +7120,33 @@
6662
7120
  }
6663
7121
  };
6664
7122
 
6665
-
7123
+ /**
7124
+ * Get the selected elements.
7125
+ *
7126
+ * @return {Object[]} The selected elements.
7127
+ */
6666
7128
  Selection.prototype.get = function() {
6667
7129
  return this._selectedElements;
6668
7130
  };
6669
7131
 
7132
+ /**
7133
+ * Check whether an element is selected.
7134
+ *
7135
+ * @param {Object} element The element.
7136
+ *
7137
+ * @return {boolean} Whether the element is selected.
7138
+ */
6670
7139
  Selection.prototype.isSelected = function(element) {
6671
7140
  return this._selectedElements.indexOf(element) !== -1;
6672
7141
  };
6673
7142
 
6674
7143
 
6675
7144
  /**
6676
- * This method selects one or more elements on the diagram.
6677
- *
6678
- * By passing an additional add parameter you can decide whether or not the element(s)
6679
- * should be added to the already existing selection or not.
6680
- *
6681
- * @method Selection#select
7145
+ * Select one or many elements.
6682
7146
  *
6683
- * @param {Object|Object[]} elements element or array of elements to be selected
6684
- * @param {boolean} [add] whether the element(s) should be appended to the current selection, defaults to false
7147
+ * @param {Object|Object[]} elements The element(s) to select.
7148
+ * @param {boolean} [add] Whether to add the element(s) to the selected elements.
7149
+ * Defaults to `false`.
6685
7150
  */
6686
7151
  Selection.prototype.select = function(elements, add) {
6687
7152
  var selectedElements = this._selectedElements,
@@ -6967,6 +7432,9 @@
6967
7432
  return !element.hidden;
6968
7433
  }
6969
7434
 
7435
+ /**
7436
+ * @type { import('didi').ModuleDeclaration }
7437
+ */
6970
7438
  var SelectionModule = {
6971
7439
  __init__: [ 'selectionVisuals', 'selectionBehavior' ],
6972
7440
  __depends__: [
@@ -6986,7 +7454,7 @@
6986
7454
  *
6987
7455
  * The ids can be customized via a given prefix and contain a random value to avoid collisions.
6988
7456
  *
6989
- * @param {string} prefix a prefix to prepend to generated ids (for better readability)
7457
+ * @param {string} [prefix] a prefix to prepend to generated ids (for better readability)
6990
7458
  */
6991
7459
  function IdGenerator(prefix) {
6992
7460
 
@@ -6997,7 +7465,7 @@
6997
7465
  /**
6998
7466
  * Returns a next unique ID.
6999
7467
  *
7000
- * @returns {string} the id
7468
+ * @return {string} the id
7001
7469
  */
7002
7470
  IdGenerator.prototype.next = function() {
7003
7471
  return this._prefix + (++this._counter);
@@ -7013,12 +7481,54 @@
7013
7481
  * @typedef {import('../../core/ElementRegistry').default} ElementRegistry
7014
7482
  * @typedef {import('../../core/EventBus').default} EventBus
7015
7483
  *
7016
- * @typedef {import('./Overlays').Overlay} Overlay
7017
- * @typedef {import('./Overlays').OverlayAttrs} OverlayAttrs
7018
- * @typedef {import('./Overlays').OverlayContainer} OverlayContainer
7019
- * @typedef {import('./Overlays').OverlaysConfig} OverlaysConfig
7020
- * @typedef {import('./Overlays').OverlaysConfigDefault} OverlaysConfigDefault
7021
- * @typedef {import('./Overlays').OverlaysFilter} OverlaysFilter
7484
+ * @typedef {import('../../model/Types').Element} Element
7485
+ *
7486
+ * @typedef { {
7487
+ * minZoom?: number,
7488
+ * maxZoom?: number
7489
+ * } } OverlaysConfigShow
7490
+ *
7491
+ * @typedef { {
7492
+ * min?: number,
7493
+ * max?: number
7494
+ * } } OverlaysConfigScale
7495
+ *
7496
+ * @typedef { {
7497
+ * id: string,
7498
+ * type: string | null,
7499
+ * element: Element | string
7500
+ * } & OverlayAttrs } Overlay
7501
+ *
7502
+ * @typedef { {
7503
+ * html: HTMLElement | string,
7504
+ * position: {
7505
+ * top?: number,
7506
+ * right?: number,
7507
+ * bottom?: number,
7508
+ * left?: number
7509
+ * }
7510
+ * } & OverlaysConfigDefault } OverlayAttrs
7511
+ *
7512
+ * @typedef { {
7513
+ * html: HTMLElement,
7514
+ * element: Element,
7515
+ * overlays: Overlay[]
7516
+ * } } OverlayContainer
7517
+ *
7518
+ * @typedef {{
7519
+ * defaults?: OverlaysConfigDefault
7520
+ * }} OverlaysConfig
7521
+ *
7522
+ * @typedef { {
7523
+ * show?: OverlaysConfigShow,
7524
+ * scale?: OverlaysConfigScale | boolean
7525
+ * } } OverlaysConfigDefault
7526
+ *
7527
+ * @typedef { {
7528
+ * id?: string;
7529
+ * element?: Element | string;
7530
+ * type?: string;
7531
+ * } | string } OverlaysFilter
7022
7532
  */
7023
7533
 
7024
7534
  /**
@@ -7028,6 +7538,7 @@
7028
7538
  *
7029
7539
  * @example
7030
7540
  *
7541
+ * ```javascript
7031
7542
  * // add a pink badge on the top left of the shape
7032
7543
  *
7033
7544
  * overlays.add(someShape, {
@@ -7057,8 +7568,9 @@
7057
7568
  * }
7058
7569
  * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
7059
7570
  * });
7571
+ * ```
7060
7572
  *
7061
- *
7573
+ * ```javascript
7062
7574
  * // remove an overlay
7063
7575
  *
7064
7576
  * var id = overlays.add(...);
@@ -7080,6 +7592,7 @@
7080
7592
  * }
7081
7593
  * }
7082
7594
  * }
7595
+ * ```
7083
7596
  *
7084
7597
  * @param {OverlaysConfig} config
7085
7598
  * @param {EventBus} eventBus
@@ -7138,6 +7651,7 @@
7138
7651
  *
7139
7652
  * @example
7140
7653
  *
7654
+ * ```javascript
7141
7655
  * // return the single overlay with the given ID
7142
7656
  * overlays.get('some-id');
7143
7657
  *
@@ -7149,6 +7663,7 @@
7149
7663
  *
7150
7664
  * // shape can also be specified as ID
7151
7665
  * overlays.get({ element: 'element-id', type: 'badge' });
7666
+ * ```
7152
7667
  *
7153
7668
  * @param {OverlaysFilter} search The filter to be used to find the overlay(s).
7154
7669
  *
@@ -7186,7 +7701,7 @@
7186
7701
  /**
7187
7702
  * Adds an HTML overlay to an element.
7188
7703
  *
7189
- * @param {Base|string} element The element to add the overlay to.
7704
+ * @param {Element|string} element The element to add the overlay to.
7190
7705
  * @param {string} [type] An optional type that can be used to filter.
7191
7706
  * @param {OverlayAttrs} overlay The overlay.
7192
7707
  *
@@ -7274,7 +7789,7 @@
7274
7789
  /**
7275
7790
  * Checks whether overlays are shown.
7276
7791
  *
7277
- * @returns {boolean} Whether overlays are shown.
7792
+ * @return {boolean} Whether overlays are shown.
7278
7793
  */
7279
7794
  Overlays.prototype.isShown = function() {
7280
7795
  return this._overlayRoot.style.display !== 'none';
@@ -7667,6 +8182,9 @@
7667
8182
  });
7668
8183
  }
7669
8184
 
8185
+ /**
8186
+ * @type { import('didi').ModuleDeclaration }
8187
+ */
7670
8188
  var OverlaysModule = {
7671
8189
  __init__: [ 'overlays' ],
7672
8190
  overlays: [ 'type', Overlays ]
@@ -7743,15 +8261,22 @@
7743
8261
  'graphicsFactory'
7744
8262
  ];
7745
8263
 
8264
+ /**
8265
+ * @type { import('didi').ModuleDeclaration }
8266
+ */
7746
8267
  var ChangeSupportModule = {
7747
8268
  __init__: [ 'changeSupport' ],
7748
8269
  changeSupport: [ 'type', ChangeSupport ]
7749
8270
  };
7750
8271
 
7751
8272
  /**
8273
+ * @typedef {import('../core/Types').ElementLike} ElementLike
7752
8274
  * @typedef {import('../core/EventBus').default} EventBus
7753
- * @typedef {import(./CommandInterceptor).HandlerFunction} HandlerFunction
7754
- * @typedef {import(./CommandInterceptor).ComposeHandlerFunction} ComposeHandlerFunction
8275
+ * @typedef {import('./CommandStack').CommandContext} CommandContext
8276
+ *
8277
+ * @typedef {string|string[]} Events
8278
+ * @typedef { (context: CommandContext) => ElementLike[] | void } HandlerFunction
8279
+ * @typedef { (context: CommandContext) => void } ComposeHandlerFunction
7755
8280
  */
7756
8281
 
7757
8282
  var DEFAULT_PRIORITY$1 = 1000;
@@ -7763,10 +8288,9 @@
7763
8288
  * @class
7764
8289
  * @constructor
7765
8290
  *
7766
- * @param {EventBus} eventBus
7767
- *
7768
8291
  * @example
7769
8292
  *
8293
+ * ```javascript
7770
8294
  * import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
7771
8295
  *
7772
8296
  * class CommandLogger extends CommandInterceptor {
@@ -7777,6 +8301,9 @@
7777
8301
  * console.log('commandStack.shape-create.preExecute', event);
7778
8302
  * });
7779
8303
  * }
8304
+ * ```
8305
+ *
8306
+ * @param {EventBus} eventBus
7780
8307
  */
7781
8308
  function CommandInterceptor(eventBus) {
7782
8309
 
@@ -7794,16 +8321,17 @@
7794
8321
  };
7795
8322
  }
7796
8323
 
8324
+
7797
8325
  /**
7798
- * Intercept a command during one of the phases.
7799
- *
7800
- * @param {string|string[]} [events] One or more commands to intercept.
7801
- * @param {string} [hook] Phase during which to intercept command.
7802
- * @param {number} [priority] Priority with which command will be intercepted.
7803
- * @param {ComposeHandlerFunction|HandlerFunction} handlerFn Callback.
7804
- * @param {boolean} [unwrap] Whether the event should be unwrapped.
7805
- * @param {*} [that] `this` value the callback will be called with.
7806
- */
8326
+ * Intercept a command during one of the phases.
8327
+ *
8328
+ * @param {Events} [events] command(s) to intercept
8329
+ * @param {string} [hook] phase to intercept
8330
+ * @param {number} [priority]
8331
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn
8332
+ * @param {boolean} [unwrap] whether the event should be unwrapped
8333
+ * @param {any} [that]
8334
+ */
7807
8335
  CommandInterceptor.prototype.on = function(events, hook, priority, handlerFn, unwrap, that) {
7808
8336
 
7809
8337
  if (isFunction(hook) || isNumber(hook)) {
@@ -7845,35 +8373,130 @@
7845
8373
  });
7846
8374
  };
7847
8375
 
8376
+ /**
8377
+ * Add a <canExecute> phase of command interceptor.
8378
+ *
8379
+ * @param {Events} [events] command(s) to intercept
8380
+ * @param {number} [priority]
8381
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn
8382
+ * @param {boolean} [unwrap] whether the event should be unwrapped
8383
+ * @param {any} [that]
8384
+ */
8385
+ CommandInterceptor.prototype.canExecute = createHook('canExecute');
8386
+
8387
+ /**
8388
+ * Add a <preExecute> phase of command interceptor.
8389
+ *
8390
+ * @param {Events} [events] command(s) to intercept
8391
+ * @param {number} [priority]
8392
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn
8393
+ * @param {boolean} [unwrap] whether the event should be unwrapped
8394
+ * @param {any} [that]
8395
+ */
8396
+ CommandInterceptor.prototype.preExecute = createHook('preExecute');
7848
8397
 
7849
- var hooks = [
7850
- 'canExecute',
7851
- 'preExecute',
7852
- 'preExecuted',
7853
- 'execute',
7854
- 'executed',
7855
- 'postExecute',
7856
- 'postExecuted',
7857
- 'revert',
7858
- 'reverted'
7859
- ];
8398
+ /**
8399
+ * Add a <preExecuted> phase of command interceptor.
8400
+ *
8401
+ * @param {Events} [events] command(s) to intercept
8402
+ * @param {number} [priority]
8403
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn
8404
+ * @param {boolean} [unwrap] whether the event should be unwrapped
8405
+ * @param {any} [that]
8406
+ */
8407
+ CommandInterceptor.prototype.preExecuted = createHook('preExecuted');
8408
+
8409
+ /**
8410
+ * Add a <execute> phase of command interceptor.
8411
+ *
8412
+ * @param {Events} [events] command(s) to intercept
8413
+ * @param {number} [priority]
8414
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn
8415
+ * @param {boolean} [unwrap] whether the event should be unwrapped
8416
+ * @param {any} [that]
8417
+ */
8418
+ CommandInterceptor.prototype.execute = createHook('execute');
8419
+
8420
+ /**
8421
+ * Add a <executed> phase of command interceptor.
8422
+ *
8423
+ * @param {Events} [events] command(s) to intercept
8424
+ * @param {number} [priority]
8425
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn
8426
+ * @param {boolean} [unwrap] whether the event should be unwrapped
8427
+ * @param {any} [that]
8428
+ */
8429
+ CommandInterceptor.prototype.executed = createHook('executed');
8430
+
8431
+ /**
8432
+ * Add a <postExecute> phase of command interceptor.
8433
+ *
8434
+ * @param {Events} [events] command(s) to intercept
8435
+ * @param {number} [priority]
8436
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn
8437
+ * @param {boolean} [unwrap] whether the event should be unwrapped
8438
+ * @param {any} [that]
8439
+ */
8440
+ CommandInterceptor.prototype.postExecute = createHook('postExecute');
8441
+
8442
+ /**
8443
+ * Add a <postExecuted> phase of command interceptor.
8444
+ *
8445
+ * @param {Events} [events] command(s) to intercept
8446
+ * @param {number} [priority]
8447
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn
8448
+ * @param {boolean} [unwrap] whether the event should be unwrapped
8449
+ * @param {any} [that]
8450
+ */
8451
+ CommandInterceptor.prototype.postExecuted = createHook('postExecuted');
8452
+
8453
+ /**
8454
+ * Add a <revert> phase of command interceptor.
8455
+ *
8456
+ * @param {Events} [events] command(s) to intercept
8457
+ * @param {number} [priority]
8458
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn
8459
+ * @param {boolean} [unwrap] whether the event should be unwrapped
8460
+ * @param {any} [that]
8461
+ */
8462
+ CommandInterceptor.prototype.revert = createHook('revert');
8463
+
8464
+ /**
8465
+ * Add a <reverted> phase of command interceptor.
8466
+ *
8467
+ * @param {Events} [events] command(s) to intercept
8468
+ * @param {number} [priority]
8469
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn
8470
+ * @param {boolean} [unwrap] whether the event should be unwrapped
8471
+ * @param {any} [that]
8472
+ */
8473
+ CommandInterceptor.prototype.reverted = createHook('reverted');
7860
8474
 
7861
8475
  /*
7862
8476
  * Add prototype methods for each phase of command execution (e.g. execute,
7863
8477
  * revert).
8478
+ *
8479
+ * @param {string} hook
8480
+ *
8481
+ * @return { (
8482
+ * events?: Events,
8483
+ * priority?: number,
8484
+ * handlerFn: ComposeHandlerFunction|HandlerFunction,
8485
+ * unwrap?: boolean
8486
+ * ) => any }
7864
8487
  */
7865
- forEach$1(hooks, function(hook) {
8488
+ function createHook(hook) {
7866
8489
 
7867
8490
  /**
7868
- * Add prototype method for a specific phase of command execution.
8491
+ * @this {CommandInterceptor}
7869
8492
  *
7870
- * @param {string|string[]} [events] One or more commands to intercept.
7871
- * @param {number} [priority] Priority with which command will be intercepted.
7872
- * @param {ComposeHandlerFunction|HandlerFunction} handlerFn Callback.
7873
- * @param {boolean} [unwrap] Whether the event should be unwrapped.
7874
- * @param {*} [that] `this` value the callback will be called with.
8493
+ * @param {Events} [events]
8494
+ * @param {number} [priority]
8495
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn
8496
+ * @param {boolean} [unwrap]
8497
+ * @param {any} [that]
7875
8498
  */
7876
- CommandInterceptor.prototype[hook] = function(events, priority, handlerFn, unwrap, that) {
8499
+ const hookFn = function(events, priority, handlerFn, unwrap, that) {
7877
8500
 
7878
8501
  if (isFunction(events) || isNumber(events)) {
7879
8502
  that = unwrap;
@@ -7885,7 +8508,9 @@
7885
8508
 
7886
8509
  this.on(events, hook, priority, handlerFn, unwrap, that);
7887
8510
  };
7888
- });
8511
+
8512
+ return hookFn;
8513
+ }
7889
8514
 
7890
8515
  /**
7891
8516
  * @typedef {import('didi').Injector} Injector
@@ -7927,6 +8552,9 @@
7927
8552
 
7928
8553
  RootElementsBehavior.$inject = [ 'canvas', 'injector' ];
7929
8554
 
8555
+ /**
8556
+ * @type { import('didi').ModuleDeclaration }
8557
+ */
7930
8558
  var RootElementsModule = {
7931
8559
  __init__: [ 'rootElementsBehavior' ],
7932
8560
  rootElementsBehavior: [ 'type', RootElementsBehavior ]
@@ -7934,7 +8562,8 @@
7934
8562
 
7935
8563
  /**
7936
8564
  * @param {string} str
7937
- * @returns {string}
8565
+ *
8566
+ * @return {string}
7938
8567
  */
7939
8568
 
7940
8569
  var HTML_ESCAPE_MAP = {
@@ -7945,6 +8574,11 @@
7945
8574
  '\'': '&#39;'
7946
8575
  };
7947
8576
 
8577
+ /**
8578
+ * @param {string} str
8579
+ *
8580
+ * @return {string}
8581
+ */
7948
8582
  function escapeHTML(str) {
7949
8583
  str = '' + str;
7950
8584
 
@@ -7953,14 +8587,19 @@
7953
8587
  });
7954
8588
  }
7955
8589
 
8590
+ /**
8591
+ * @typedef {import('../model/Types').Element} Element
8592
+ * @typedef {import('../model/Types').ModdleElement} ModdleElement
8593
+ */
8594
+
7956
8595
  var planeSuffix = '_plane';
7957
8596
 
7958
8597
  /**
7959
8598
  * Get plane ID for a primary shape.
7960
8599
  *
7961
- * @param {djs.model.Base|ModdleElement} element
8600
+ * @param {Element|ModdleElement} element
7962
8601
  *
7963
- * @returns {String}
8602
+ * @return {string}
7964
8603
  */
7965
8604
  function getPlaneIdFromShape(element) {
7966
8605
  var id = element.id;
@@ -7976,32 +8615,40 @@
7976
8615
  return id + planeSuffix;
7977
8616
  }
7978
8617
 
8618
+ /**
8619
+ * @typedef {import('diagram-js/lib/core/Canvas').default} Canvas
8620
+ * @typedef {import('diagram-js/lib/core/ElementRegistry').default} ElementRegistry
8621
+ * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
8622
+ *
8623
+ * @typedef {import('../../model/Types').Element} Element
8624
+ * @typedef {import('../../model/Types').Shape} Shape
8625
+ */
8626
+
7979
8627
  var OPEN_CLASS = 'bjs-breadcrumbs-shown';
7980
8628
 
7981
8629
 
7982
8630
  /**
7983
8631
  * Adds overlays that allow switching planes on collapsed subprocesses.
7984
8632
  *
7985
- * @param {eventBus} eventBus
7986
- * @param {elementRegistry} elementRegistry
7987
- * @param {overlays} overlays
7988
- * @param {canvas} canvas
8633
+ * @param {EventBus} eventBus
8634
+ * @param {ElementRegistry} elementRegistry
8635
+ * @param {Canvas} canvas
7989
8636
  */
7990
- function DrilldownBreadcrumbs(eventBus, elementRegistry, overlays, canvas) {
8637
+ function DrilldownBreadcrumbs(eventBus, elementRegistry, canvas) {
7991
8638
  var breadcrumbs = domify$1('<ul class="bjs-breadcrumbs"></ul>');
7992
8639
  var container = canvas.getContainer();
7993
8640
  var containerClasses = classes(container);
7994
8641
  container.appendChild(breadcrumbs);
7995
8642
 
7996
- var boParents = [];
8643
+ var businessObjectParents = [];
7997
8644
 
7998
8645
  // update breadcrumbs if name or ID of the primary shape changes
7999
- eventBus.on('element.changed', function(e) {
8000
- var shape = e.element,
8001
- bo = getBusinessObject(shape);
8646
+ eventBus.on('element.changed', function(event) {
8647
+ var shape = event.element,
8648
+ businessObject = getBusinessObject(shape);
8002
8649
 
8003
- var isPresent = find(boParents, function(el) {
8004
- return el === bo;
8650
+ var isPresent = find(businessObjectParents, function(element) {
8651
+ return element === businessObject;
8005
8652
  });
8006
8653
 
8007
8654
  if (!isPresent) {
@@ -8015,14 +8662,14 @@
8015
8662
  * Updates the displayed breadcrumbs. If no element is provided, only the
8016
8663
  * labels are updated.
8017
8664
  *
8018
- * @param {djs.model.Base} [element]
8665
+ * @param {Element} [element]
8019
8666
  */
8020
8667
  function updateBreadcrumbs(element) {
8021
8668
  if (element) {
8022
- boParents = getBoParentChain(element);
8669
+ businessObjectParents = getBusinessObjectParentChain(element);
8023
8670
  }
8024
8671
 
8025
- var path = boParents.map(function(parent) {
8672
+ var path = businessObjectParents.map(function(parent) {
8026
8673
  var title = escapeHTML(parent.name || parent.id);
8027
8674
  var link = domify$1('<li><span class="bjs-crumb"><a title="' + title + '">' + title + '</a></span></li>');
8028
8675
 
@@ -8032,8 +8679,9 @@
8032
8679
  // element in the elementRegisty. Instead, we search for the corresponding participant
8033
8680
  if (!parentPlane && is$1(parent, 'bpmn:Process')) {
8034
8681
  var participant = elementRegistry.find(function(element) {
8035
- var bo = getBusinessObject(element);
8036
- return bo && bo.processRef && bo.processRef === parent;
8682
+ var businessObject = getBusinessObject(element);
8683
+
8684
+ return businessObject && businessObject.get('processRef') && businessObject.get('processRef') === parent;
8037
8685
  });
8038
8686
 
8039
8687
  parentPlane = canvas.findRoot(participant.id);
@@ -8050,10 +8698,11 @@
8050
8698
 
8051
8699
  // show breadcrumbs and expose state to .djs-container
8052
8700
  var visible = path.length > 1;
8701
+
8053
8702
  containerClasses.toggle(OPEN_CLASS, visible);
8054
8703
 
8055
- path.forEach(function(el) {
8056
- breadcrumbs.appendChild(el);
8704
+ path.forEach(function(element) {
8705
+ breadcrumbs.appendChild(element);
8057
8706
  });
8058
8707
  }
8059
8708
 
@@ -8063,7 +8712,7 @@
8063
8712
 
8064
8713
  }
8065
8714
 
8066
- DrilldownBreadcrumbs.$inject = [ 'eventBus', 'elementRegistry', 'overlays', 'canvas' ];
8715
+ DrilldownBreadcrumbs.$inject = [ 'eventBus', 'elementRegistry', 'canvas' ];
8067
8716
 
8068
8717
 
8069
8718
  // helpers //////////
@@ -8072,16 +8721,16 @@
8072
8721
  * Returns the parents for the element using the business object chain,
8073
8722
  * starting with the root element.
8074
8723
  *
8075
- * @param {djs.model.Shape} child
8724
+ * @param {Shape} child
8076
8725
  *
8077
- * @returns {Array<djs.model.Shape>} parents
8726
+ * @return {Shape}
8078
8727
  */
8079
- function getBoParentChain(child) {
8080
- var bo = getBusinessObject(child);
8728
+ function getBusinessObjectParentChain(child) {
8729
+ var businessObject = getBusinessObject(child);
8081
8730
 
8082
8731
  var parents = [];
8083
8732
 
8084
- for (var element = bo; element; element = element.$parent) {
8733
+ for (var element = businessObject; element; element = element.$parent) {
8085
8734
  if (is$1(element, 'bpmn:SubProcess') || is$1(element, 'bpmn:Process')) {
8086
8735
  parents.push(element);
8087
8736
  }
@@ -8090,13 +8739,18 @@
8090
8739
  return parents.reverse();
8091
8740
  }
8092
8741
 
8742
+ /**
8743
+ * @typedef {import('diagram-js/lib/core/Canvas').default} Canvas
8744
+ * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
8745
+ */
8746
+
8093
8747
  /**
8094
8748
  * Move collapsed subprocesses into view when drilling down.
8095
8749
  *
8096
8750
  * Zoom and scroll are saved in a session.
8097
8751
  *
8098
- * @param {eventBus} eventBus
8099
- * @param {canvas} canvas
8752
+ * @param {EventBus} eventBus
8753
+ * @param {Canvas} canvas
8100
8754
  */
8101
8755
  function DrilldownCentering(eventBus, canvas) {
8102
8756
 
@@ -8207,6 +8861,18 @@
8207
8861
  };
8208
8862
  }
8209
8863
 
8864
+ /**
8865
+ * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
8866
+ * @typedef {import('../../model/Types').Moddle} Moddle
8867
+ *
8868
+ * @typedef {import('../../model/Types').Element} Element
8869
+ * @typedef {import('../../model/Types').Shape} Shape
8870
+ *
8871
+ * @typedef {import('diagram-js/lib/core/Canvas').CanvasPlane} CanvasPlane
8872
+ *
8873
+ * @typedef {import('diagram-js/lib/util/Types').Rect} Rect
8874
+ */
8875
+
8210
8876
  var DEFAULT_POSITION = {
8211
8877
  x: 180,
8212
8878
  y: 160
@@ -8214,10 +8880,10 @@
8214
8880
 
8215
8881
  /**
8216
8882
  * Hook into `import.render.start` and create new planes for diagrams with
8217
- * collapsed subprocesses and all dis on the same plane.
8883
+ * collapsed subprocesses and all DI elements on the same plane.
8218
8884
  *
8219
- * @param {eventBus} eventBus
8220
- * @param {moddle} moddle
8885
+ * @param {EventBus} eventBus
8886
+ * @param {Moddle} moddle
8221
8887
  */
8222
8888
  function SubprocessCompatibility(eventBus, moddle) {
8223
8889
  this._eventBus = eventBus;
@@ -8226,11 +8892,14 @@
8226
8892
  var self = this;
8227
8893
 
8228
8894
  eventBus.on('import.render.start', 1500, function(e, context) {
8229
- self.handleImport(context.definitions);
8895
+ self._handleImport(context.definitions);
8230
8896
  });
8231
8897
  }
8232
8898
 
8233
- SubprocessCompatibility.prototype.handleImport = function(definitions) {
8899
+ /**
8900
+ * @param {ModdleElement} definitions
8901
+ */
8902
+ SubprocessCompatibility.prototype._handleImport = function(definitions) {
8234
8903
  if (!definitions.diagrams) {
8235
8904
  return;
8236
8905
  }
@@ -8249,12 +8918,12 @@
8249
8918
 
8250
8919
  var newDiagrams = [];
8251
8920
  definitions.diagrams.forEach(function(diagram) {
8252
- var createdDiagrams = self.createNewDiagrams(diagram.plane);
8921
+ var createdDiagrams = self._createNewDiagrams(diagram.plane);
8253
8922
  Array.prototype.push.apply(newDiagrams, createdDiagrams);
8254
8923
  });
8255
8924
 
8256
8925
  newDiagrams.forEach(function(diagram) {
8257
- self.movePlaneElementsToOrigin(diagram.plane);
8926
+ self._movePlaneElementsToOrigin(diagram.plane);
8258
8927
  });
8259
8928
  };
8260
8929
 
@@ -8262,29 +8931,30 @@
8262
8931
  /**
8263
8932
  * Moves all DI elements from collapsed subprocesses to a new plane.
8264
8933
  *
8265
- * @param {Object} plane
8266
- * @return {Array} new diagrams created for the collapsed subprocesses
8934
+ * @param {CanvasPlane} plane
8935
+ *
8936
+ * @return {ModdleElement[]} new diagrams created for the collapsed subprocesses
8267
8937
  */
8268
- SubprocessCompatibility.prototype.createNewDiagrams = function(plane) {
8938
+ SubprocessCompatibility.prototype._createNewDiagrams = function(plane) {
8269
8939
  var self = this;
8270
8940
 
8271
8941
  var collapsedElements = [];
8272
8942
  var elementsToMove = [];
8273
8943
 
8274
8944
  plane.get('planeElement').forEach(function(diElement) {
8275
- var bo = diElement.bpmnElement;
8945
+ var businessObject = diElement.bpmnElement;
8276
8946
 
8277
- if (!bo) {
8947
+ if (!businessObject) {
8278
8948
  return;
8279
8949
  }
8280
8950
 
8281
- var parent = bo.$parent;
8951
+ var parent = businessObject.$parent;
8282
8952
 
8283
- if (is$1(bo, 'bpmn:SubProcess') && !diElement.isExpanded) {
8284
- collapsedElements.push(bo);
8953
+ if (is$1(businessObject, 'bpmn:SubProcess') && !diElement.isExpanded) {
8954
+ collapsedElements.push(businessObject);
8285
8955
  }
8286
8956
 
8287
- if (shouldMoveToPlane(bo, plane)) {
8957
+ if (shouldMoveToPlane(businessObject, plane)) {
8288
8958
 
8289
8959
  // don't change the array while we iterate over it
8290
8960
  elementsToMove.push({ diElement: diElement, parent: parent });
@@ -8295,9 +8965,11 @@
8295
8965
 
8296
8966
  // create new planes for all collapsed subprocesses, even when they are empty
8297
8967
  collapsedElements.forEach(function(element) {
8298
- if (!self._processToDiagramMap[element.id]) {
8299
- var diagram = self.createDiagram(element);
8968
+ if (!self._processToDiagramMap[ element.id ]) {
8969
+ var diagram = self._createDiagram(element);
8970
+
8300
8971
  self._processToDiagramMap[element.id] = diagram;
8972
+
8301
8973
  newDiagrams.push(diagram);
8302
8974
  }
8303
8975
  });
@@ -8316,14 +8988,18 @@
8316
8988
  return;
8317
8989
  }
8318
8990
 
8319
- var diagram = self._processToDiagramMap[parent.id];
8320
- self.moveToDiPlane(diElement, diagram.plane);
8991
+ var diagram = self._processToDiagramMap[ parent.id ];
8992
+
8993
+ self._moveToDiPlane(diElement, diagram.plane);
8321
8994
  });
8322
8995
 
8323
8996
  return newDiagrams;
8324
8997
  };
8325
8998
 
8326
- SubprocessCompatibility.prototype.movePlaneElementsToOrigin = function(plane) {
8999
+ /**
9000
+ * @param {CanvasPlane} plane
9001
+ */
9002
+ SubprocessCompatibility.prototype._movePlaneElementsToOrigin = function(plane) {
8327
9003
  var elements = plane.get('planeElement');
8328
9004
 
8329
9005
  // get bounding box of all elements
@@ -8347,33 +9023,50 @@
8347
9023
  });
8348
9024
  };
8349
9025
 
8350
-
8351
- SubprocessCompatibility.prototype.moveToDiPlane = function(diElement, newPlane) {
9026
+ /**
9027
+ * @param {ModdleElement} diElement
9028
+ * @param {CanvasPlane} newPlane
9029
+ */
9030
+ SubprocessCompatibility.prototype._moveToDiPlane = function(diElement, newPlane) {
8352
9031
  var containingDiagram = findRootDiagram(diElement);
8353
9032
 
8354
9033
  // remove DI from old Plane and add it to the new one
8355
9034
  var parentPlaneElement = containingDiagram.plane.get('planeElement');
9035
+
8356
9036
  parentPlaneElement.splice(parentPlaneElement.indexOf(diElement), 1);
9037
+
8357
9038
  newPlane.get('planeElement').push(diElement);
8358
9039
  };
8359
9040
 
9041
+ /**
9042
+ * @param {ModdleElement} businessObject
9043
+ *
9044
+ * @return {ModdleElement}
9045
+ */
9046
+ SubprocessCompatibility.prototype._createDiagram = function(businessObject) {
9047
+ var plane = this._moddle.create('bpmndi:BPMNPlane', {
9048
+ bpmnElement: businessObject
9049
+ });
8360
9050
 
8361
- SubprocessCompatibility.prototype.createDiagram = function(bo) {
8362
- var plane = this._moddle.create('bpmndi:BPMNPlane', { bpmnElement: bo });
8363
9051
  var diagram = this._moddle.create('bpmndi:BPMNDiagram', {
8364
9052
  plane: plane
8365
9053
  });
9054
+
8366
9055
  plane.$parent = diagram;
8367
- plane.bpmnElement = bo;
9056
+
9057
+ plane.bpmnElement = businessObject;
9058
+
8368
9059
  diagram.$parent = this._definitions;
9060
+
8369
9061
  this._definitions.diagrams.push(diagram);
9062
+
8370
9063
  return diagram;
8371
9064
  };
8372
9065
 
8373
9066
  SubprocessCompatibility.$inject = [ 'eventBus', 'moddle' ];
8374
9067
 
8375
9068
 
8376
- // helpers //////////////////////////
9069
+ // helpers //////////
8377
9070
 
8378
9071
  function findRootDiagram(element) {
8379
9072
  if (is$1(element, 'bpmndi:BPMNDiagram')) {
@@ -8383,6 +9076,11 @@
8383
9076
  }
8384
9077
  }
8385
9078
 
9079
+ /**
9080
+ * @param {CanvasPlane} plane
9081
+ *
9082
+ * @return {Rect}
9083
+ */
8386
9084
  function getPlaneBounds(plane) {
8387
9085
  var planeTrbl = {
8388
9086
  top: Infinity,
@@ -8405,8 +9103,14 @@
8405
9103
  return asBounds(planeTrbl);
8406
9104
  }
8407
9105
 
8408
- function shouldMoveToPlane(bo, plane) {
8409
- var parent = bo.$parent;
9106
+ /**
9107
+ * @param {ModdleElement} businessObject
9108
+ * @param {CanvasPlane} plane
9109
+ *
9110
+ * @return {boolean}
9111
+ */
9112
+ function shouldMoveToPlane(businessObject, plane) {
9113
+ var parent = businessObject.$parent;
8410
9114
 
8411
9115
  // don't move elements that are already on the plane
8412
9116
  if (!is$1(parent, 'bpmn:SubProcess') || parent === plane.bpmnElement) {
@@ -8415,18 +9119,35 @@
8415
9119
 
8416
9120
  // dataAssociations are children of the subprocess but rendered on process level
8417
9121
  // cf. https://github.com/bpmn-io/bpmn-js/issues/1619
8418
- if (isAny(bo, [ 'bpmn:DataInputAssociation', 'bpmn:DataOutputAssociation' ])) {
9122
+ if (isAny(businessObject, [ 'bpmn:DataInputAssociation', 'bpmn:DataOutputAssociation' ])) {
8419
9123
  return false;
8420
9124
  }
8421
9125
 
8422
9126
  return true;
8423
9127
  }
8424
9128
 
9129
+ /**
9130
+ * @typedef {import('diagram-js/lib/core/Canvas').default} Canvas
9131
+ * @typedef {import('diagram-js/lib/core/ElementRegistry').default} ElementRegistry
9132
+ * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
9133
+ * @typedef {import('diagram-js/lib/features/overlays/Overlays').default} Overlays
9134
+ *
9135
+ * @typedef {import('../../model/Types').Element} Element
9136
+ * @typedef {import('../../model/Types').Parent} Parent
9137
+ * @typedef {import('../../model/Types').Shape} Shape
9138
+ */
9139
+
8425
9140
  var LOW_PRIORITY = 250;
8426
9141
  var ARROW_DOWN_SVG = '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4.81801948,3.50735931 L10.4996894,9.1896894 L10.5,4 L12,4 L12,12 L4,12 L4,10.5 L9.6896894,10.4996894 L3.75735931,4.56801948 C3.46446609,4.27512627 3.46446609,3.80025253 3.75735931,3.50735931 C4.05025253,3.21446609 4.52512627,3.21446609 4.81801948,3.50735931 Z"/></svg>';
8427
9142
 
8428
9143
  var EMPTY_MARKER = 'bjs-drilldown-empty';
8429
9144
 
9145
+ /**
9146
+ * @param {Canvas} canvas
9147
+ * @param {EventBus} eventBus
9148
+ * @param {ElementRegistry} elementRegistry
9149
+ * @param {Overlays} overlays
9150
+ */
8430
9151
  function DrilldownOverlayBehavior(
8431
9152
  canvas, eventBus, elementRegistry, overlays
8432
9153
  ) {
@@ -8443,10 +9164,10 @@
8443
9164
  var shape = context.shape;
8444
9165
 
8445
9166
  // Add overlay to the collapsed shape
8446
- if (self.canDrillDown(shape)) {
8447
- self.addOverlay(shape);
9167
+ if (self._canDrillDown(shape)) {
9168
+ self._addOverlay(shape);
8448
9169
  } else {
8449
- self.removeOverlay(shape);
9170
+ self._removeOverlay(shape);
8450
9171
  }
8451
9172
  }, true);
8452
9173
 
@@ -8455,10 +9176,10 @@
8455
9176
  var shape = context.shape;
8456
9177
 
8457
9178
  // Add overlay to the collapsed shape
8458
- if (self.canDrillDown(shape)) {
8459
- self.addOverlay(shape);
9179
+ if (self._canDrillDown(shape)) {
9180
+ self._addOverlay(shape);
8460
9181
  } else {
8461
- self.removeOverlay(shape);
9182
+ self._removeOverlay(shape);
8462
9183
  }
8463
9184
  }, true);
8464
9185
 
@@ -8470,13 +9191,13 @@
8470
9191
  shape = context.shape;
8471
9192
 
8472
9193
  // Add overlay to the collapsed shape
8473
- if (self.canDrillDown(shape)) {
8474
- self.addOverlay(shape);
9194
+ if (self._canDrillDown(shape)) {
9195
+ self._addOverlay(shape);
8475
9196
  }
8476
9197
 
8477
- self.updateDrilldownOverlay(oldParent);
8478
- self.updateDrilldownOverlay(newParent);
8479
- self.updateDrilldownOverlay(shape);
9198
+ self._updateDrilldownOverlay(oldParent);
9199
+ self._updateDrilldownOverlay(newParent);
9200
+ self._updateDrilldownOverlay(shape);
8480
9201
  }, true);
8481
9202
 
8482
9203
 
@@ -8487,21 +9208,21 @@
8487
9208
  shape = context.shape;
8488
9209
 
8489
9210
  // Add overlay to the collapsed shape
8490
- if (self.canDrillDown(shape)) {
8491
- self.addOverlay(shape);
9211
+ if (self._canDrillDown(shape)) {
9212
+ self._addOverlay(shape);
8492
9213
  }
8493
9214
 
8494
- self.updateDrilldownOverlay(oldParent);
8495
- self.updateDrilldownOverlay(newParent);
8496
- self.updateDrilldownOverlay(shape);
9215
+ self._updateDrilldownOverlay(oldParent);
9216
+ self._updateDrilldownOverlay(newParent);
9217
+ self._updateDrilldownOverlay(shape);
8497
9218
  }, true);
8498
9219
 
8499
9220
 
8500
9221
  eventBus.on('import.render.complete', function() {
8501
9222
  elementRegistry.filter(function(e) {
8502
- return self.canDrillDown(e);
9223
+ return self._canDrillDown(e);
8503
9224
  }).map(function(el) {
8504
- self.addOverlay(el);
9225
+ self._addOverlay(el);
8505
9226
  });
8506
9227
  });
8507
9228
 
@@ -8509,7 +9230,10 @@
8509
9230
 
8510
9231
  e(DrilldownOverlayBehavior, CommandInterceptor);
8511
9232
 
8512
- DrilldownOverlayBehavior.prototype.updateDrilldownOverlay = function(shape) {
9233
+ /**
9234
+ * @param {Shape} shape
9235
+ */
9236
+ DrilldownOverlayBehavior.prototype._updateDrilldownOverlay = function(shape) {
8513
9237
  var canvas = this._canvas;
8514
9238
 
8515
9239
  if (!shape) {
@@ -8517,51 +9241,61 @@
8517
9241
  }
8518
9242
 
8519
9243
  var root = canvas.findRoot(shape);
9244
+
8520
9245
  if (root) {
8521
- this.updateOverlayVisibility(root);
9246
+ this._updateOverlayVisibility(root);
8522
9247
  }
8523
9248
  };
8524
9249
 
8525
-
8526
- DrilldownOverlayBehavior.prototype.canDrillDown = function(element) {
9250
+ /**
9251
+ * @param {Element} element
9252
+ *
9253
+ * @return {boolean}
9254
+ */
9255
+ DrilldownOverlayBehavior.prototype._canDrillDown = function(element) {
8527
9256
  var canvas = this._canvas;
9257
+
8528
9258
  return is$1(element, 'bpmn:SubProcess') && canvas.findRoot(getPlaneIdFromShape(element));
8529
9259
  };
8530
9260
 
8531
9261
  /**
8532
- * Updates visibility of the drilldown overlay. If the plane has no elements,
8533
- * the drilldown will be only shown when the element is selected.
9262
+ * Update the visibility of the drilldown overlay. If the plane has no elements,
9263
+ * the drilldown will only be shown when the element is selected.
8534
9264
  *
8535
- * @param {djs.model.Shape|djs.model.Root} element collapsed shape or root element
9265
+ * @param {Parent} element The collapsed root or shape.
8536
9266
  */
8537
- DrilldownOverlayBehavior.prototype.updateOverlayVisibility = function(element) {
9267
+ DrilldownOverlayBehavior.prototype._updateOverlayVisibility = function(element) {
8538
9268
  var overlays = this._overlays;
8539
9269
 
8540
- var bo = element.businessObject;
9270
+ var businessObject = getBusinessObject(element);
8541
9271
 
8542
- var overlay = overlays.get({ element: bo.id, type: 'drilldown' })[0];
9272
+ var overlay = overlays.get({ element: businessObject.id, type: 'drilldown' })[0];
8543
9273
 
8544
9274
  if (!overlay) {
8545
9275
  return;
8546
9276
  }
8547
9277
 
8548
- var hasContent = bo && bo.flowElements && bo.flowElements.length;
8549
- classes(overlay.html).toggle(EMPTY_MARKER, !hasContent);
9278
+ var hasFlowElements = businessObject
9279
+ && businessObject.get('flowElements')
9280
+ && businessObject.get('flowElements').length;
9281
+
9282
+ classes(overlay.html).toggle(EMPTY_MARKER, !hasFlowElements);
8550
9283
  };
8551
9284
 
8552
9285
  /**
8553
- * Attaches a drilldown button to the given element. We assume that the plane has
8554
- * the same id as the element.
9286
+ * Add a drilldown button to the given element assuming the plane has the same
9287
+ * ID as the element.
8555
9288
  *
8556
- * @param {djs.model.Shape} element collapsed shape
9289
+ * @param {Shape} element The collapsed shape.
8557
9290
  */
8558
- DrilldownOverlayBehavior.prototype.addOverlay = function(element) {
8559
- var canvas = this._canvas;
8560
- var overlays = this._overlays;
9291
+ DrilldownOverlayBehavior.prototype._addOverlay = function(element) {
9292
+ var canvas = this._canvas,
9293
+ overlays = this._overlays;
8561
9294
 
8562
9295
  var existingOverlays = overlays.get({ element: element, type: 'drilldown' });
9296
+
8563
9297
  if (existingOverlays.length) {
8564
- this.removeOverlay(element);
9298
+ this._removeOverlay(element);
8565
9299
  }
8566
9300
 
8567
9301
  var button = domify$1('<button class="bjs-drilldown">' + ARROW_DOWN_SVG + '</button>');
@@ -8578,10 +9312,10 @@
8578
9312
  html: button
8579
9313
  });
8580
9314
 
8581
- this.updateOverlayVisibility(element);
9315
+ this._updateOverlayVisibility(element);
8582
9316
  };
8583
9317
 
8584
- DrilldownOverlayBehavior.prototype.removeOverlay = function(element) {
9318
+ DrilldownOverlayBehavior.prototype._removeOverlay = function(element) {
8585
9319
  var overlays = this._overlays;
8586
9320
 
8587
9321
  overlays.remove({
@@ -9087,7 +9821,6 @@
9087
9821
  */
9088
9822
  function DefaultRenderer(eventBus, styles) {
9089
9823
 
9090
- //
9091
9824
  BaseRenderer.call(this, eventBus, DEFAULT_RENDER_PRIORITY);
9092
9825
 
9093
9826
  this.CONNECTION_STYLE = styles.style([ 'no-fill' ], { strokeWidth: 5, stroke: 'fuchsia' });
@@ -9098,10 +9831,16 @@
9098
9831
  e(DefaultRenderer, BaseRenderer);
9099
9832
 
9100
9833
 
9834
+ /**
9835
+ * @private
9836
+ */
9101
9837
  DefaultRenderer.prototype.canRender = function() {
9102
9838
  return true;
9103
9839
  };
9104
9840
 
9841
+ /**
9842
+ * @private
9843
+ */
9105
9844
  DefaultRenderer.prototype.drawShape = function drawShape(visuals, element, attrs) {
9106
9845
  var rect = create$1('rect');
9107
9846
 
@@ -9123,6 +9862,9 @@
9123
9862
  return rect;
9124
9863
  };
9125
9864
 
9865
+ /**
9866
+ * @private
9867
+ */
9126
9868
  DefaultRenderer.prototype.drawConnection = function drawConnection(visuals, connection, attrs) {
9127
9869
 
9128
9870
  var line = createLine(connection.waypoints, assign$1({}, this.CONNECTION_STYLE, attrs || {}));
@@ -9131,6 +9873,9 @@
9131
9873
  return line;
9132
9874
  };
9133
9875
 
9876
+ /**
9877
+ * @private
9878
+ */
9134
9879
  DefaultRenderer.prototype.getShapePath = function getShapePath(shape) {
9135
9880
 
9136
9881
  var x = shape.x,
@@ -9149,6 +9894,9 @@
9149
9894
  return componentsToPath(shapePath);
9150
9895
  };
9151
9896
 
9897
+ /**
9898
+ * @private
9899
+ */
9152
9900
  DefaultRenderer.prototype.getConnectionPath = function getConnectionPath(connection) {
9153
9901
  var waypoints = connection.waypoints;
9154
9902
 
@@ -9166,7 +9914,6 @@
9166
9914
  return componentsToPath(connectionPath);
9167
9915
  };
9168
9916
 
9169
-
9170
9917
  DefaultRenderer.$inject = [ 'eventBus', 'styles' ];
9171
9918
 
9172
9919
  /**
@@ -9190,13 +9937,14 @@
9190
9937
  var self = this;
9191
9938
 
9192
9939
  /**
9193
- * Builds a style definition from a className, a list of traits and an object of additional attributes.
9940
+ * Builds a style definition from a className, a list of traits and an object
9941
+ * of additional attributes.
9194
9942
  *
9195
9943
  * @param {string} className
9196
- * @param {Array<string>} traits
9197
- * @param {Object} additionalAttrs
9944
+ * @param {string[]} [traits]
9945
+ * @param {Object} [additionalAttrs]
9198
9946
  *
9199
- * @return {Object} the style defintion
9947
+ * @return {Object} the style definition
9200
9948
  */
9201
9949
  this.cls = function(className, traits, additionalAttrs) {
9202
9950
  var attrs = this.style(traits, additionalAttrs);
@@ -9205,12 +9953,13 @@
9205
9953
  };
9206
9954
 
9207
9955
  /**
9208
- * Builds a style definition from a list of traits and an object of additional attributes.
9956
+ * Builds a style definition from a list of traits and an object of additional
9957
+ * attributes.
9209
9958
  *
9210
- * @param {Array<string>} traits
9959
+ * @param {string[]} [traits]
9211
9960
  * @param {Object} additionalAttrs
9212
9961
  *
9213
- * @return {Object} the style defintion
9962
+ * @return {Object} the style definition
9214
9963
  */
9215
9964
  this.style = function(traits, additionalAttrs) {
9216
9965
 
@@ -9226,6 +9975,17 @@
9226
9975
  return additionalAttrs ? assign$1(attrs, additionalAttrs) : attrs;
9227
9976
  };
9228
9977
 
9978
+
9979
+ /**
9980
+ * Computes a style definition from a list of traits and an object of
9981
+ * additional attributes, with custom style definition object.
9982
+ *
9983
+ * @param {Object} custom
9984
+ * @param {string[]} [traits]
9985
+ * @param {Object} defaultStyles
9986
+ *
9987
+ * @return {Object} the style definition
9988
+ */
9229
9989
  this.computeStyle = function(custom, traits, defaultStyles) {
9230
9990
  if (!isArray$2(traits)) {
9231
9991
  defaultStyles = traits;
@@ -9236,6 +9996,9 @@
9236
9996
  };
9237
9997
  }
9238
9998
 
9999
+ /**
10000
+ * @type { import('didi').ModuleDeclaration }
10001
+ */
9239
10002
  var DrawModule = {
9240
10003
  __init__: [ 'defaultRenderer' ],
9241
10004
  defaultRenderer: [ 'type', DefaultRenderer ],
@@ -9271,7 +10034,7 @@
9271
10034
  *
9272
10035
  * @param {Array<Object>} collection
9273
10036
  * @param {Object} element
9274
- * @param {number} idx
10037
+ * @param {number} [idx]
9275
10038
  */
9276
10039
  function add(collection, element, idx) {
9277
10040
 
@@ -9317,15 +10080,34 @@
9317
10080
  }
9318
10081
 
9319
10082
  /**
9320
- * @typedef {import('.').ConnectionLike} ConnectionLike
9321
- * @typedef {import('.').RootLike} RootLike
9322
- * @typedef {import('.').ShapeLike} ShapeLike
9323
- *
9324
- * @typedef {import('./Canvas').CanvasConfig} CanvasConfig
9325
- * @typedef {import('./Canvas').CanvasLayer} CanvasLayer
9326
- * @typedef {import('./Canvas').CanvasLayers} CanvasLayers
9327
- * @typedef {import('./Canvas').CanvasPlane} CanvasPlane
9328
- * @typedef {import('./Canvas').CanvasViewbox} CanvasViewbox
10083
+ * @typedef {import('./Types').ConnectionLike} ConnectionLike
10084
+ * @typedef {import('./Types').RootLike} RootLike
10085
+ * @typedef {import('./Types').ParentLike } ParentLike
10086
+ * @typedef {import('./Types').ShapeLike} ShapeLike
10087
+ *
10088
+ * @typedef { {
10089
+ * container?: HTMLElement;
10090
+ * deferUpdate?: boolean;
10091
+ * width?: number;
10092
+ * height?: number;
10093
+ * } } CanvasConfig
10094
+ * @typedef { {
10095
+ * group: SVGElement;
10096
+ * index: number;
10097
+ * visible: boolean;
10098
+ * } } CanvasLayer
10099
+ * @typedef { {
10100
+ * [key: string]: CanvasLayer;
10101
+ * } } CanvasLayers
10102
+ * @typedef { {
10103
+ * rootElement: ShapeLike;
10104
+ * layer: CanvasLayer;
10105
+ * } } CanvasPlane
10106
+ * @typedef { {
10107
+ * scale: number;
10108
+ * inner: Rect;
10109
+ * outer: Dimensions;
10110
+ * } & Rect } CanvasViewbox
9329
10111
  *
9330
10112
  * @typedef {import('./ElementRegistry').default} ElementRegistry
9331
10113
  * @typedef {import('./EventBus').default} EventBus
@@ -9666,7 +10448,7 @@
9666
10448
  /**
9667
10449
  * Shows a given layer.
9668
10450
  *
9669
- * @param {string} layer The name of the layer.
10451
+ * @param {string} name The name of the layer.
9670
10452
  *
9671
10453
  * @return {SVGElement} The SVG element of the layer.
9672
10454
  */
@@ -9702,7 +10484,7 @@
9702
10484
  /**
9703
10485
  * Hides a given layer.
9704
10486
  *
9705
- * @param {string} layer The name of the layer.
10487
+ * @param {string} name The name of the layer.
9706
10488
  *
9707
10489
  * @return {SVGElement} The SVG element of the layer.
9708
10490
  */
@@ -9844,7 +10626,7 @@
9844
10626
  *
9845
10627
  * @event element.marker.update
9846
10628
  * @type {Object}
9847
- * @property {Base} element the shape
10629
+ * @property {Element} element the shape
9848
10630
  * @property {SVGElement} gfx the graphical representation of the shape
9849
10631
  * @property {string} marker
9850
10632
  * @property {boolean} add true if the marker was added, false if it got removed
@@ -9861,11 +10643,13 @@
9861
10643
  *
9862
10644
  * @example
9863
10645
  *
10646
+ * ```javascript
9864
10647
  * canvas.addMarker('foo', 'some-marker');
9865
10648
  *
9866
10649
  * const fooGfx = canvas.getGraphics('foo');
9867
10650
  *
9868
10651
  * fooGfx; // <g class="... some-marker"> ... </g>
10652
+ * ```
9869
10653
  *
9870
10654
  * @param {ShapeLike|ConnectionLike|string} element The element or its ID.
9871
10655
  * @param {string} marker The marker.
@@ -9950,7 +10734,7 @@
9950
10734
  /**
9951
10735
  * Adds a given root element and returns it.
9952
10736
  *
9953
- * @param {ShapeLike} [rootElement] The root element to be added.
10737
+ * @param {RootLike} [rootElement] The root element to be added.
9954
10738
  *
9955
10739
  * @return {RootLike} The added root element or an implicit root element.
9956
10740
  */
@@ -9986,9 +10770,9 @@
9986
10770
  /**
9987
10771
  * Removes a given root element and returns it.
9988
10772
  *
9989
- * @param {ShapeLike|string} rootElement The root element or its ID.
10773
+ * @param {RootLike|string} rootElement element or element ID
9990
10774
  *
9991
- * @return {ShapeLike|undefined} The removed root element.
10775
+ * @return {RootLike|undefined} removed element
9992
10776
  */
9993
10777
  Canvas.prototype.removeRootElement = function(rootElement) {
9994
10778
 
@@ -10030,11 +10814,7 @@
10030
10814
  *
10031
10815
  * @return {RootLike} The set root element.
10032
10816
  */
10033
- Canvas.prototype.setRootElement = function(rootElement, override) {
10034
-
10035
- if (isDefined(override)) {
10036
- throw new Error('override not supported');
10037
- }
10817
+ Canvas.prototype.setRootElement = function(rootElement) {
10038
10818
 
10039
10819
  if (rootElement === this._rootElement) {
10040
10820
  return;
@@ -10191,7 +10971,7 @@
10191
10971
  * Adds a shape to the canvas.
10192
10972
  *
10193
10973
  * @param {ShapeLike} shape The shape to be added
10194
- * @param {ShapeLike} [parent] The shape's parent.
10974
+ * @param {ParentLike} [parent] The shape's parent.
10195
10975
  * @param {number} [parentIndex] The index at which to add the shape to the parent's children.
10196
10976
  *
10197
10977
  * @return {ShapeLike} The added shape.
@@ -10204,7 +10984,7 @@
10204
10984
  * Adds a connection to the canvas.
10205
10985
  *
10206
10986
  * @param {ConnectionLike} connection The connection to be added.
10207
- * @param {ShapeLike} [parent] The connection's parent.
10987
+ * @param {ParentLike} [parent] The connection's parent.
10208
10988
  * @param {number} [parentIndex] The index at which to add the connection to the parent's children.
10209
10989
  *
10210
10990
  * @return {ConnectionLike} The added connection.
@@ -10275,7 +11055,7 @@
10275
11055
  *
10276
11056
  * @memberOf Canvas
10277
11057
  *
10278
- * @event ShapeRemoved
11058
+ * @event ShapeRemovedEvent
10279
11059
  * @type {Object}
10280
11060
  * @property {ShapeLike} element The shape.
10281
11061
  * @property {SVGElement} gfx The graphical element.
@@ -10312,7 +11092,7 @@
10312
11092
  *
10313
11093
  * @memberOf Canvas
10314
11094
  *
10315
- * @event connection.removed
11095
+ * @event ConnectionRemovedEvent
10316
11096
  * @type {Object}
10317
11097
  * @property {ConnectionLike} element The connection.
10318
11098
  * @property {SVGElement} gfx The graphical element.
@@ -10371,6 +11151,7 @@
10371
11151
  *
10372
11152
  * @example
10373
11153
  *
11154
+ * ```javascript
10374
11155
  * canvas.viewbox({ x: 100, y: 100, width: 500, height: 500 })
10375
11156
  *
10376
11157
  * // sets the visible area of the diagram to (100|100) -> (600|100)
@@ -10398,6 +11179,7 @@
10398
11179
  * width: zoomedAndScrolledViewbox.outer.width,
10399
11180
  * height: zoomedAndScrolledViewbox.outer.height
10400
11181
  * });
11182
+ * ```
10401
11183
  *
10402
11184
  * @param {Rect} [box] The viewbox to be set.
10403
11185
  *
@@ -10571,7 +11353,7 @@
10571
11353
  * The getter may return a cached zoom level. Call it with `false` as the first
10572
11354
  * argument to force recomputation of the current level.
10573
11355
  *
10574
- * @param {number|string} [newScale] The new zoom level, either a number,
11356
+ * @param {number|'fit-viewport'} [newScale] The new zoom level, either a number,
10575
11357
  * i.e. 0.9, or `fit-viewport` to adjust the size to fit the current viewport.
10576
11358
  * @param {Point} [center] The reference point { x: ..., y: ...} to zoom to.
10577
11359
  *
@@ -10766,11 +11548,12 @@
10766
11548
  var ELEMENT_ID = 'data-element-id';
10767
11549
 
10768
11550
  /**
10769
- * @typedef {import('.').ElementLike} ElementLike
11551
+ * @typedef {import('./Types').ElementLike} ElementLike
10770
11552
  *
10771
11553
  * @typedef {import('./EventBus').default} EventBus
10772
11554
  *
10773
- * @typedef {import('./ElementRegistry').ElementRegistryCallback} ElementRegistryCallback
11555
+ * @typedef { (element: ElementLike, gfx: SVGElement) => boolean|any } ElementRegistryFilterCallback
11556
+ * @typedef { (element: ElementLike, gfx: SVGElement) => any } ElementRegistryForEachCallback
10774
11557
  */
10775
11558
 
10776
11559
  /**
@@ -10782,6 +11565,16 @@
10782
11565
  * @param {EventBus} eventBus
10783
11566
  */
10784
11567
  function ElementRegistry(eventBus) {
11568
+
11569
+ /**
11570
+ * @type { {
11571
+ * [id: string]: {
11572
+ * element: ElementLike;
11573
+ * gfx?: SVGElement;
11574
+ * secondaryGfx?: SVGElement;
11575
+ * }
11576
+ * } }
11577
+ */
10785
11578
  this._elements = {};
10786
11579
 
10787
11580
  this._eventBus = eventBus;
@@ -10867,7 +11660,7 @@
10867
11660
  /**
10868
11661
  * Update the graphical representation of an element.
10869
11662
  *
10870
- * @param {ElementLike|string} element The element or its ID.
11663
+ * @param {ElementLike|string} filter The element or its ID.
10871
11664
  * @param {SVGElement} gfx The new graphical representation.
10872
11665
  * @param {boolean} [secondary=false] Whether to update the secondary graphical representation.
10873
11666
  */
@@ -10894,9 +11687,11 @@
10894
11687
  *
10895
11688
  * @example
10896
11689
  *
11690
+ * ```javascript
10897
11691
  * elementRegistry.get('SomeElementId_1');
10898
11692
  *
10899
11693
  * elementRegistry.get(gfx);
11694
+ * ```
10900
11695
  *
10901
11696
  * @param {string|SVGElement} filter The elements ID or graphical representation.
10902
11697
  *
@@ -10918,7 +11713,7 @@
10918
11713
  /**
10919
11714
  * Return all elements that match a given filter function.
10920
11715
  *
10921
- * @param {ElementRegistryCallback} fn The filter function.
11716
+ * @param {ElementRegistryFilterCallback} fn The filter function.
10922
11717
  *
10923
11718
  * @return {ElementLike[]} The matching elements.
10924
11719
  */
@@ -10938,7 +11733,7 @@
10938
11733
  /**
10939
11734
  * Return the first element that matches the given filter function.
10940
11735
  *
10941
- * @param {Function} fn The filter function.
11736
+ * @param {ElementRegistryFilterCallback} fn The filter function.
10942
11737
  *
10943
11738
  * @return {ElementLike|undefined} The matching element.
10944
11739
  */
@@ -10970,7 +11765,7 @@
10970
11765
  /**
10971
11766
  * Execute a given function for each element.
10972
11767
  *
10973
- * @param {Function} fn The function to execute.
11768
+ * @param {ElementRegistryForEachCallback} fn The function to execute.
10974
11769
  */
10975
11770
  ElementRegistry.prototype.forEach = function(fn) {
10976
11771
 
@@ -10990,11 +11785,13 @@
10990
11785
  *
10991
11786
  * @example
10992
11787
  *
11788
+ * ```javascript
10993
11789
  * elementRegistry.getGraphics('SomeElementId_1');
10994
11790
  *
10995
11791
  * elementRegistry.getGraphics(rootElement); // <g ...>
10996
11792
  *
10997
11793
  * elementRegistry.getGraphics(rootElement, true); // <svg ...>
11794
+ * ```
10998
11795
  *
10999
11796
  * @param {ElementLike|string} filter The element or its ID.
11000
11797
  * @param {boolean} [secondary=false] Whether to return the secondary graphical representation.
@@ -11357,19 +12154,26 @@
11357
12154
  outgoingRefs = new Refs({ name: 'outgoing', collection: true }, { name: 'source' }),
11358
12155
  incomingRefs = new Refs({ name: 'incoming', collection: true }, { name: 'target' });
11359
12156
 
12157
+ /**
12158
+ * @typedef {import('./Types').Element} Element
12159
+ * @typedef {import('./Types').Shape} Shape
12160
+ * @typedef {import('./Types').Root} Root
12161
+ * @typedef {import('./Types').Label} Label
12162
+ * @typedef {import('./Types').Connection} Connection
12163
+ */
12164
+
11360
12165
  /**
11361
12166
  * The basic graphical representation
11362
12167
  *
11363
12168
  * @class
11364
- *
11365
- * @abstract
12169
+ * @constructor
11366
12170
  */
11367
- function Base$1() {
12171
+ function ElementImpl() {
11368
12172
 
11369
12173
  /**
11370
12174
  * The object that backs up the shape
11371
12175
  *
11372
- * @name Base#businessObject
12176
+ * @name Element#businessObject
11373
12177
  * @type Object
11374
12178
  */
11375
12179
  Object.defineProperty(this, 'businessObject', {
@@ -11380,7 +12184,7 @@
11380
12184
  /**
11381
12185
  * Single label support, will mapped to multi label array
11382
12186
  *
11383
- * @name Base#label
12187
+ * @name Element#label
11384
12188
  * @type Object
11385
12189
  */
11386
12190
  Object.defineProperty(this, 'label', {
@@ -11403,7 +12207,7 @@
11403
12207
  /**
11404
12208
  * The parent shape
11405
12209
  *
11406
- * @name Base#parent
12210
+ * @name Element#parent
11407
12211
  * @type Shape
11408
12212
  */
11409
12213
  parentRefs.bind(this, 'parent');
@@ -11411,7 +12215,7 @@
11411
12215
  /**
11412
12216
  * The list of labels
11413
12217
  *
11414
- * @name Base#labels
12218
+ * @name Element#labels
11415
12219
  * @type Label
11416
12220
  */
11417
12221
  labelRefs.bind(this, 'labels');
@@ -11419,7 +12223,7 @@
11419
12223
  /**
11420
12224
  * The list of outgoing connections
11421
12225
  *
11422
- * @name Base#outgoing
12226
+ * @name Element#outgoing
11423
12227
  * @type Array<Connection>
11424
12228
  */
11425
12229
  outgoingRefs.bind(this, 'outgoing');
@@ -11427,7 +12231,7 @@
11427
12231
  /**
11428
12232
  * The list of incoming connections
11429
12233
  *
11430
- * @name Base#incoming
12234
+ * @name Element#incoming
11431
12235
  * @type Array<Connection>
11432
12236
  */
11433
12237
  incomingRefs.bind(this, 'incoming');
@@ -11440,40 +12244,40 @@
11440
12244
  * @class
11441
12245
  * @constructor
11442
12246
  *
11443
- * @extends Base
12247
+ * @extends ElementImpl
11444
12248
  */
11445
- function Shape() {
11446
- Base$1.call(this);
12249
+ function ShapeImpl() {
12250
+ ElementImpl.call(this);
11447
12251
 
11448
12252
  /**
11449
12253
  * Indicates frame shapes
11450
12254
  *
11451
- * @name Shape#isFrame
12255
+ * @name ShapeImpl#isFrame
11452
12256
  * @type boolean
11453
12257
  */
11454
12258
 
11455
12259
  /**
11456
12260
  * The list of children
11457
12261
  *
11458
- * @name Shape#children
11459
- * @type Array<Base>
12262
+ * @name ShapeImpl#children
12263
+ * @type Element[]
11460
12264
  */
11461
12265
  parentRefs.bind(this, 'children');
11462
12266
 
11463
12267
  /**
11464
- * @name Shape#host
12268
+ * @name ShapeImpl#host
11465
12269
  * @type Shape
11466
12270
  */
11467
12271
  attacherRefs.bind(this, 'host');
11468
12272
 
11469
12273
  /**
11470
- * @name Shape#attachers
12274
+ * @name ShapeImpl#attachers
11471
12275
  * @type Shape
11472
12276
  */
11473
12277
  attacherRefs.bind(this, 'attachers');
11474
12278
  }
11475
12279
 
11476
- e(Shape, Base$1);
12280
+ e(ShapeImpl, ElementImpl);
11477
12281
 
11478
12282
 
11479
12283
  /**
@@ -11482,13 +12286,21 @@
11482
12286
  * @class
11483
12287
  * @constructor
11484
12288
  *
11485
- * @extends Shape
12289
+ * @extends ElementImpl
11486
12290
  */
11487
- function Root() {
11488
- Shape.call(this);
12291
+ function RootImpl() {
12292
+ ElementImpl.call(this);
12293
+
12294
+ /**
12295
+ * The list of children
12296
+ *
12297
+ * @name RootImpl#children
12298
+ * @type Element[]
12299
+ */
12300
+ parentRefs.bind(this, 'children');
11489
12301
  }
11490
12302
 
11491
- e(Root, Shape);
12303
+ e(RootImpl, ShapeImpl);
11492
12304
 
11493
12305
 
11494
12306
  /**
@@ -11497,21 +12309,21 @@
11497
12309
  * @class
11498
12310
  * @constructor
11499
12311
  *
11500
- * @extends Shape
12312
+ * @extends ShapeImpl
11501
12313
  */
11502
- function Label() {
11503
- Shape.call(this);
12314
+ function LabelImpl() {
12315
+ ShapeImpl.call(this);
11504
12316
 
11505
12317
  /**
11506
12318
  * The labeled element
11507
12319
  *
11508
- * @name Label#labelTarget
11509
- * @type Base
12320
+ * @name LabelImpl#labelTarget
12321
+ * @type Element
11510
12322
  */
11511
12323
  labelRefs.bind(this, 'labelTarget');
11512
12324
  }
11513
12325
 
11514
- e(Label, Shape);
12326
+ e(LabelImpl, ShapeImpl);
11515
12327
 
11516
12328
 
11517
12329
  /**
@@ -11520,45 +12332,69 @@
11520
12332
  * @class
11521
12333
  * @constructor
11522
12334
  *
11523
- * @extends Base
12335
+ * @extends ElementImpl
11524
12336
  */
11525
- function Connection() {
11526
- Base$1.call(this);
12337
+ function ConnectionImpl() {
12338
+ ElementImpl.call(this);
11527
12339
 
11528
12340
  /**
11529
12341
  * The element this connection originates from
11530
12342
  *
11531
- * @name Connection#source
11532
- * @type Base
12343
+ * @name ConnectionImpl#source
12344
+ * @type Element
11533
12345
  */
11534
12346
  outgoingRefs.bind(this, 'source');
11535
12347
 
11536
12348
  /**
11537
12349
  * The element this connection points to
11538
12350
  *
11539
- * @name Connection#target
11540
- * @type Base
12351
+ * @name ConnectionImpl#target
12352
+ * @type Element
11541
12353
  */
11542
12354
  incomingRefs.bind(this, 'target');
11543
12355
  }
11544
12356
 
11545
- e(Connection, Base$1);
12357
+ e(ConnectionImpl, ElementImpl);
11546
12358
 
11547
12359
 
11548
12360
  var types$7 = {
11549
- connection: Connection,
11550
- shape: Shape,
11551
- label: Label,
11552
- root: Root
12361
+ connection: ConnectionImpl,
12362
+ shape: ShapeImpl,
12363
+ label: LabelImpl,
12364
+ root: RootImpl
11553
12365
  };
11554
12366
 
11555
12367
  /**
11556
- * Creates a model element of the given type.
12368
+ * Creates a root element.
12369
+ *
12370
+ * @overlord
12371
+ *
12372
+ * @example
12373
+ *
12374
+ * ```javascript
12375
+ * import * as Model from 'diagram-js/lib/model';
12376
+ *
12377
+ * const root = Model.create('root', {
12378
+ * x: 100,
12379
+ * y: 100,
12380
+ * width: 100,
12381
+ * height: 100
12382
+ * });
12383
+ * ```
12384
+ *
12385
+ * @param {'root'} type
12386
+ * @param {any} [attrs]
12387
+ *
12388
+ * @return {Root}
12389
+ */
12390
+ /**
12391
+ * Creates a connection.
11557
12392
  *
11558
- * @method create
12393
+ * @overlord
11559
12394
  *
11560
12395
  * @example
11561
12396
  *
12397
+ * ```javascript
11562
12398
  * import * as Model from 'diagram-js/lib/model';
11563
12399
  *
11564
12400
  * const connection = Model.create('connection', {
@@ -11567,33 +12403,56 @@
11567
12403
  * { x: 200, y: 100 }
11568
12404
  * ]
11569
12405
  * });
12406
+ * ```
11570
12407
  *
11571
- * const label = Model.create('label', {
11572
- * x: 100,
11573
- * y: 100,
11574
- * width: 100,
11575
- * height: 100,
11576
- * labelTarget: shape
11577
- * });
12408
+ * @param {'connection'} type
12409
+ * @param {any} [attrs]
11578
12410
  *
11579
- * const root = Model.create('root', {
12411
+ * @return {Connection}
12412
+ */
12413
+ /**
12414
+ * Creates a shape.
12415
+ *
12416
+ * @overlord
12417
+ *
12418
+ * @example
12419
+ *
12420
+ * ```javascript
12421
+ * import * as Model from 'diagram-js/lib/model';
12422
+ *
12423
+ * const shape = Model.create('shape', {
11580
12424
  * x: 100,
11581
12425
  * y: 100,
11582
12426
  * width: 100,
11583
12427
  * height: 100
11584
12428
  * });
12429
+ * ```
11585
12430
  *
11586
- * const shape = Model.create('shape', {
12431
+ * @param {'shape'} type
12432
+ * @param {any} [attrs]
12433
+ *
12434
+ * @return {Shape}
12435
+ */
12436
+ /**
12437
+ * Creates a label.
12438
+ *
12439
+ * @example
12440
+ *
12441
+ * ```javascript
12442
+ * import * as Model from 'diagram-js/lib/model';
12443
+ *
12444
+ * const label = Model.create('label', {
11587
12445
  * x: 100,
11588
12446
  * y: 100,
11589
12447
  * width: 100,
11590
- * height: 100
12448
+ * height: 100,
12449
+ * labelTarget: shape
11591
12450
  * });
12451
+ * ```
11592
12452
  *
11593
- * @param {string} type The type of model element to be created.
11594
- * @param {Object} attrs Attributes to create the model element with.
11595
- *
11596
- * @return {Connection|Label|Root|Shape} The created model element.
12453
+ * @param {'label'} type
12454
+ * @param {Object} [attrs]
12455
+ * @return {Label}
11597
12456
  */
11598
12457
  function create(type, attrs) {
11599
12458
  var Type = types$7[type];
@@ -11604,22 +12463,20 @@
11604
12463
  }
11605
12464
 
11606
12465
  /**
11607
- * @typedef {import('../model/index').Base} Base
11608
- * @typedef {import('../model/index').Connection} Connection
11609
- * @typedef {import('../model/index').Label} Label
11610
- * @typedef {import('../model/index').Root} Root
11611
- * @typedef {import('../model/index').Shape} Shape
11612
- * @typedef {import('../model/index').ModelAttrsConnection} ModelAttrsConnection
11613
- * @typedef {import('../model/index').ModelAttrsLabel} ModelAttrsLabel
11614
- * @typedef {import('../model/index').ModelAttrsRoot} ModelAttrsRoot
11615
- * @typedef {import('../model/index').ModelAttrsShape} ModelAttrsShape
12466
+ * @typedef {import('../model/Types').Element} Element
12467
+ * @typedef {import('../model/Types').Connection} Connection
12468
+ * @typedef {import('../model/Types').Label} Label
12469
+ * @typedef {import('../model/Types').Root} Root
12470
+ * @typedef {import('../model/Types').Shape} Shape
11616
12471
  */
11617
12472
 
11618
12473
  /**
11619
12474
  * A factory for model elements.
11620
12475
  *
11621
- * @class
11622
- * @constructor
12476
+ * @template {Connection} [T=Connection]
12477
+ * @template {Label} [U=Label]
12478
+ * @template {Root} [V=Root]
12479
+ * @template {Shape} [W=Shape]
11623
12480
  */
11624
12481
  function ElementFactory() {
11625
12482
  this._uid = 12;
@@ -11628,9 +12485,9 @@
11628
12485
  /**
11629
12486
  * Create a root element.
11630
12487
  *
11631
- * @param {ModelAttrsRoot} attrs The attributes of the root element to be created.
12488
+ * @param {Partial<Root>} [attrs]
11632
12489
  *
11633
- * @return {Root} The created root element.
12490
+ * @return {V} The created root element.
11634
12491
  */
11635
12492
  ElementFactory.prototype.createRoot = function(attrs) {
11636
12493
  return this.create('root', attrs);
@@ -11639,9 +12496,9 @@
11639
12496
  /**
11640
12497
  * Create a label.
11641
12498
  *
11642
- * @param {ModelAttrsLabel} attrs The attributes of the label to be created.
12499
+ * @param {Partial<Label>} [attrs]
11643
12500
  *
11644
- * @return {Label} The created label.
12501
+ * @return {U} The created label.
11645
12502
  */
11646
12503
  ElementFactory.prototype.createLabel = function(attrs) {
11647
12504
  return this.create('label', attrs);
@@ -11650,9 +12507,9 @@
11650
12507
  /**
11651
12508
  * Create a shape.
11652
12509
  *
11653
- * @param {ModelAttrsShape} attrs The attributes of the shape to be created.
12510
+ * @param {Partial<Shape>} [attrs]
11654
12511
  *
11655
- * @return {Shape} The created shape.
12512
+ * @return {W} The created shape.
11656
12513
  */
11657
12514
  ElementFactory.prototype.createShape = function(attrs) {
11658
12515
  return this.create('shape', attrs);
@@ -11661,21 +12518,44 @@
11661
12518
  /**
11662
12519
  * Create a connection.
11663
12520
  *
11664
- * @param {ModelAttrsConnection} attrs The attributes of the connection to be created.
12521
+ * @param {Partial<Connection>} [attrs]
11665
12522
  *
11666
- * @return {Connection} The created connection.
12523
+ * @return {T} The created connection.
11667
12524
  */
11668
12525
  ElementFactory.prototype.createConnection = function(attrs) {
11669
12526
  return this.create('connection', attrs);
11670
12527
  };
11671
12528
 
11672
12529
  /**
11673
- * Create a model element of the given type with the given attributes.
12530
+ * Create a root element.
12531
+ *
12532
+ * @overlord
12533
+ * @param {'root'} type
12534
+ * @param {Partial<Root>} [attrs]
12535
+ * @return {V}
12536
+ */
12537
+ /**
12538
+ * Create a shape.
12539
+ *
12540
+ * @overlord
12541
+ * @param {'shape'} type
12542
+ * @param {Partial<Shape>} [attrs]
12543
+ * @return {W}
12544
+ */
12545
+ /**
12546
+ * Create a connection.
11674
12547
  *
11675
- * @param {string} type The type of the model element.
11676
- * @param {Object} attrs The attributes of the model element.
12548
+ * @overlord
12549
+ * @param {'connection'} type
12550
+ * @param {Partial<Connection>} [attrs]
12551
+ * @return {T}
12552
+ */
12553
+ /**
12554
+ * Create a label.
11677
12555
  *
11678
- * @return {Connection|Label|Root|Shape} The created model element.
12556
+ * @param {'label'} type
12557
+ * @param {Partial<Label>} [attrs]
12558
+ * @return {U}
11679
12559
  */
11680
12560
  ElementFactory.prototype.create = function(type, attrs) {
11681
12561
 
@@ -11695,13 +12575,27 @@
11695
12575
  var slice = Array.prototype.slice;
11696
12576
 
11697
12577
  /**
11698
- * @typedef {import('./EventBus').Event} Event
11699
- * @typedef {import('./EventBus').EventCallback} EventCallback
12578
+ * @typedef { {
12579
+ * stopPropagation(): void;
12580
+ * preventDefault(): void;
12581
+ * cancelBubble: boolean;
12582
+ * defaultPrevented: boolean;
12583
+ * returnValue: any;
12584
+ * } } Event
12585
+ */
12586
+
12587
+ /**
12588
+ * @template E
11700
12589
  *
11701
- * @typedef {Object} EventListener
11702
- * @property {Function} callback
11703
- * @property {EventListener|null} next
11704
- * @property {number} priority
12590
+ * @typedef { (event: E & Event, ...any) => any } EventBusEventCallback
12591
+ */
12592
+
12593
+ /**
12594
+ * @typedef { {
12595
+ * priority: number;
12596
+ * next: EventBusListener | null;
12597
+ * callback: EventBusEventCallback<any>;
12598
+ * } } EventBusListener
11705
12599
  */
11706
12600
 
11707
12601
  /**
@@ -11788,6 +12682,10 @@
11788
12682
  * ```
11789
12683
  */
11790
12684
  function EventBus() {
12685
+
12686
+ /**
12687
+ * @type { Record<string, EventBusListener> }
12688
+ */
11791
12689
  this._listeners = {};
11792
12690
 
11793
12691
  // cleanup on destroy on lowest priority to allow
@@ -11808,10 +12706,12 @@
11808
12706
  *
11809
12707
  * Returning anything but `undefined` from a listener will stop the listener propagation.
11810
12708
  *
11811
- * @param {string|string[]} events The event(s) to listen to.
11812
- * @param {number} [priority=1000] The priority with which to listen.
11813
- * @param {EventCallback} callback The callback.
11814
- * @param {*} [that] Value of `this` the callback will be called with.
12709
+ * @template T
12710
+ *
12711
+ * @param {string|string[]} events to subscribe to
12712
+ * @param {number} [priority=1000] listen priority
12713
+ * @param {EventBusEventCallback<T>} callback
12714
+ * @param {any} [that] callback context
11815
12715
  */
11816
12716
  EventBus.prototype.on = function(events, priority, callback, that) {
11817
12717
 
@@ -11849,16 +12749,17 @@
11849
12749
  });
11850
12750
  };
11851
12751
 
11852
-
11853
12752
  /**
11854
12753
  * Register an event listener that is called only once.
11855
12754
  *
11856
- * @param {string} event The event to listen to.
11857
- * @param {number} [priority=1000] The priority with which to listen.
11858
- * @param {EventCallback} callback The callback.
11859
- * @param {*} [that] Value of `this` the callback will be called with.
12755
+ * @template T
12756
+ *
12757
+ * @param {string|string[]} events to subscribe to
12758
+ * @param {number} [priority=1000] the listen priority
12759
+ * @param {EventBusEventCallback<T>} callback
12760
+ * @param {any} [that] callback context
11860
12761
  */
11861
- EventBus.prototype.once = function(event, priority, callback, that) {
12762
+ EventBus.prototype.once = function(events, priority, callback, that) {
11862
12763
  var self = this;
11863
12764
 
11864
12765
  if (isFunction(priority)) {
@@ -11876,7 +12777,7 @@
11876
12777
 
11877
12778
  var result = callback.apply(that, arguments);
11878
12779
 
11879
- self.off(event, wrappedCallback);
12780
+ self.off(events, wrappedCallback);
11880
12781
 
11881
12782
  return result;
11882
12783
  }
@@ -11886,7 +12787,7 @@
11886
12787
  // callback
11887
12788
  wrappedCallback[FN_REF] = callback;
11888
12789
 
11889
- this.on(event, priority, wrappedCallback);
12790
+ this.on(events, priority, wrappedCallback);
11890
12791
  };
11891
12792
 
11892
12793
 
@@ -11895,8 +12796,8 @@
11895
12796
  *
11896
12797
  * If no callback is given, all listeners for a given event name are being removed.
11897
12798
  *
11898
- * @param {string|string[]} events The events.
11899
- * @param {EventCallback} [callback] The callback.
12799
+ * @param {string|string[]} events
12800
+ * @param {EventBusEventCallback} [callback]
11900
12801
  */
11901
12802
  EventBus.prototype.off = function(events, callback) {
11902
12803
 
@@ -11932,6 +12833,7 @@
11932
12833
  *
11933
12834
  * @example
11934
12835
  *
12836
+ * ```javascript
11935
12837
  * // fire event by name
11936
12838
  * events.fire('foo');
11937
12839
  *
@@ -11949,12 +12851,13 @@
11949
12851
  * });
11950
12852
  *
11951
12853
  * events.fire({ type: 'foo' }, 'I am bar!');
12854
+ * ```
11952
12855
  *
11953
- * @param {string} [type] The event type.
11954
- * @param {Object} [data] The event or event data.
11955
- * @param {...*} additional Additional arguments the callback will be called with.
12856
+ * @param {string} [type] event type
12857
+ * @param {Object} [data] event or event data
12858
+ * @param {...any} [args] additional arguments the callback will be called with.
11956
12859
  *
11957
- * @return {*} The return value. Will be set to `false` if the default was prevented.
12860
+ * @return {any} The return value. Will be set to `false` if the default was prevented.
11958
12861
  */
11959
12862
  EventBus.prototype.fire = function(type, data) {
11960
12863
  var event,
@@ -12035,6 +12938,13 @@
12035
12938
  this._listeners = {};
12036
12939
  };
12037
12940
 
12941
+ /**
12942
+ * @param {Event} event
12943
+ * @param {any[]} args
12944
+ * @param {EventBusListener} listener
12945
+ *
12946
+ * @return {any}
12947
+ */
12038
12948
  EventBus.prototype._invokeListeners = function(event, args, listener) {
12039
12949
 
12040
12950
  var returnValue;
@@ -12054,6 +12964,13 @@
12054
12964
  return returnValue;
12055
12965
  };
12056
12966
 
12967
+ /**
12968
+ * @param {Event} event
12969
+ * @param {any[]} args
12970
+ * @param {EventBusListener} listener
12971
+ *
12972
+ * @return {any}
12973
+ */
12057
12974
  EventBus.prototype._invokeListener = function(event, args, listener) {
12058
12975
 
12059
12976
  var returnValue;
@@ -12102,7 +13019,7 @@
12102
13019
  * * after: [ 1500, 1500, (new=1300), 1000, 1000, (new=1000) ]
12103
13020
  *
12104
13021
  * @param {string} event
12105
- * @param {EventListener} listener
13022
+ * @param {EventBusListener} newListener
12106
13023
  */
12107
13024
  EventBus.prototype._addListener = function(event, newListener) {
12108
13025
 
@@ -12142,10 +13059,19 @@
12142
13059
  };
12143
13060
 
12144
13061
 
13062
+ /**
13063
+ * @param {string} name
13064
+ *
13065
+ * @return {EventBusListener}
13066
+ */
12145
13067
  EventBus.prototype._getListeners = function(name) {
12146
13068
  return this._listeners[name];
12147
13069
  };
12148
13070
 
13071
+ /**
13072
+ * @param {string} name
13073
+ * @param {EventBusListener} listener
13074
+ */
12149
13075
  EventBus.prototype._setListeners = function(name, listener) {
12150
13076
  this._listeners[name] = listener;
12151
13077
  };
@@ -12208,9 +13134,9 @@
12208
13134
  * Invoke function. Be fast...
12209
13135
  *
12210
13136
  * @param {Function} fn
12211
- * @param {*[]} args
13137
+ * @param {any[]} args
12212
13138
  *
12213
- * @return {*}
13139
+ * @return {any}
12214
13140
  */
12215
13141
  function invokeFunction(fn, args) {
12216
13142
  return fn.apply(null, args);
@@ -12245,13 +13171,9 @@
12245
13171
  }
12246
13172
 
12247
13173
  /**
12248
- * @typedef {import('../model').ModelType} ModelType
12249
- * @typedef {import('../model').ModelTypeConnection} ModelTypeConnection
12250
- * @typedef {import('../model').ModelTypeShape} ModelTypeShape
12251
- *
12252
- * @typedef {import('.').ConnectionLike} ConnectionLike
12253
- * @typedef {import('.').ElementLike} ElementLike
12254
- * @typedef {import('.').ShapeLike} ShapeLike
13174
+ * @typedef {import('./Types').ConnectionLike} ConnectionLike
13175
+ * @typedef {import('./Types').ElementLike} ElementLike
13176
+ * @typedef {import('./Types').ShapeLike} ShapeLike
12255
13177
  *
12256
13178
  * @typedef {import('./ElementRegistry').default} ElementRegistry
12257
13179
  * @typedef {import('./EventBus').default} EventBus
@@ -12270,7 +13192,10 @@
12270
13192
 
12271
13193
  GraphicsFactory.$inject = [ 'eventBus' , 'elementRegistry' ];
12272
13194
 
12273
-
13195
+ /**
13196
+ * @param { { parent?: any } } element
13197
+ * @return {SVGElement}
13198
+ */
12274
13199
  GraphicsFactory.prototype._getChildrenContainer = function(element) {
12275
13200
 
12276
13201
  var gfx = this._elementRegistry.getGraphics(element);
@@ -12367,7 +13292,7 @@
12367
13292
  /**
12368
13293
  * Create a graphical element.
12369
13294
  *
12370
- * @param {ModelType} type The type of the element.
13295
+ * @param { 'shape' | 'connection' | 'label' | 'root' } type The type of the element.
12371
13296
  * @param {ElementLike} element The element.
12372
13297
  * @param {number} [parentIndex] The index at which to add the graphical element to its parent's children.
12373
13298
  *
@@ -12423,6 +13348,8 @@
12423
13348
  *
12424
13349
  * @param {SVGElement} visual The graphical element.
12425
13350
  * @param {ShapeLike} element The shape.
13351
+ *
13352
+ * @return {SVGElement}
12426
13353
  */
12427
13354
  GraphicsFactory.prototype.drawShape = function(visual, element) {
12428
13355
  var eventBus = this._eventBus;
@@ -12448,6 +13375,8 @@
12448
13375
  *
12449
13376
  * @param {SVGElement} visual The graphical element.
12450
13377
  * @param {ConnectionLike} element The connection.
13378
+ *
13379
+ * @return {SVGElement}
12451
13380
  */
12452
13381
  GraphicsFactory.prototype.drawConnection = function(visual, element) {
12453
13382
  var eventBus = this._eventBus;
@@ -12458,7 +13387,7 @@
12458
13387
  /**
12459
13388
  * Get the path of a connection.
12460
13389
  *
12461
- * @param {ConnectionLike} element The connection.
13390
+ * @param {ConnectionLike} connection The connection.
12462
13391
  *
12463
13392
  * @return {string} The path of the connection.
12464
13393
  */
@@ -12471,9 +13400,9 @@
12471
13400
  /**
12472
13401
  * Update an elements graphical representation.
12473
13402
  *
12474
- * @param {ModelTypeShape|ModelTypeConnection} type The type of the element.
12475
- * @param {ElementLike} element The element.
12476
- * @param {SVGElement} gfx The graphical representation.
13403
+ * @param {'shape'|'connection'} type
13404
+ * @param {ElementLike} element
13405
+ * @param {SVGElement} gfx
12477
13406
  */
12478
13407
  GraphicsFactory.prototype.update = function(type, element, gfx) {
12479
13408
 
@@ -12531,6 +13460,9 @@
12531
13460
  parentNode.insertBefore(newNode, node);
12532
13461
  }
12533
13462
 
13463
+ /**
13464
+ * @type { import('didi').ModuleDeclaration }
13465
+ */
12534
13466
  var CoreModule = {
12535
13467
  __depends__: [ DrawModule ],
12536
13468
  __init__: [ 'canvas' ],
@@ -12546,7 +13478,9 @@
12546
13478
  * @typedef {import('didi').LocalsMap} LocalsMap
12547
13479
  * @typedef {import('didi').ModuleDeclaration} ModuleDeclaration
12548
13480
  *
12549
- * @typedef {import('./Diagram').DiagramOptions} DiagramOptions
13481
+ * @typedef { {
13482
+ * modules?: ModuleDeclaration[];
13483
+ * } & Record<string, any> } DiagramOptions
12550
13484
  */
12551
13485
 
12552
13486
  /**
@@ -12575,6 +13509,9 @@
12575
13509
 
12576
13510
  options = options || {};
12577
13511
 
13512
+ /**
13513
+ * @type { ModuleDeclaration }
13514
+ */
12578
13515
  var configModule = {
12579
13516
  'config': [ 'value', options ]
12580
13517
  };
@@ -12594,11 +13531,10 @@
12594
13531
  * @class
12595
13532
  * @constructor
12596
13533
  *
12597
- * @example
12598
- *
12599
- * <caption>Creating a plug-in that logs whenever a shape is added to the canvas.</caption>
13534
+ * @example Creating a plug-in that logs whenever a shape is added to the canvas.
12600
13535
  *
12601
- * // plug-in implemenentation
13536
+ * ```javascript
13537
+ * // plug-in implementation
12602
13538
  * function MyLoggingPlugin(eventBus) {
12603
13539
  * eventBus.on('shape.added', function(event) {
12604
13540
  * console.log('shape ', event.shape, ' was added to the diagram');
@@ -12610,10 +13546,11 @@
12610
13546
  * __init__: [ 'myLoggingPlugin' ],
12611
13547
  * myLoggingPlugin: [ 'type', MyLoggingPlugin ]
12612
13548
  * };
13549
+ * ```
12613
13550
  *
13551
+ * Use the plug-in in a Diagram instance:
12614
13552
  *
12615
- * // instantiate the diagram with the new plug-in
12616
- *
13553
+ * ```javascript
12617
13554
  * import MyLoggingModule from 'path-to-my-logging-plugin';
12618
13555
  *
12619
13556
  * var diagram = new Diagram({
@@ -12628,36 +13565,39 @@
12628
13565
  * });
12629
13566
  *
12630
13567
  * // 'shape ... was added to the diagram' logged to console
13568
+ * ```
12631
13569
  *
12632
13570
  * @param {DiagramOptions} [options]
12633
- * @param {ModuleDeclaration[]} [options.modules] External modules to instantiate with the diagram.
12634
13571
  * @param {Injector} [injector] An (optional) injector to bootstrap the diagram with.
12635
13572
  */
12636
13573
  function Diagram(options, injector) {
12637
13574
 
12638
- // create injector unless explicitly specified
12639
- this.injector = injector = injector || createInjector(options);
13575
+ this._injector = injector = injector || createInjector(options);
12640
13576
 
12641
13577
  // API
12642
13578
 
12643
13579
  /**
12644
13580
  * Resolves a diagram service.
12645
13581
  *
12646
- * @method Diagram#get
13582
+ * @template T
12647
13583
  *
12648
13584
  * @param {string} name The name of the service to get.
12649
13585
  * @param {boolean} [strict=true] If false, resolve missing services to null.
13586
+ *
13587
+ * @return {T|null}
12650
13588
  */
12651
13589
  this.get = injector.get;
12652
13590
 
12653
13591
  /**
12654
13592
  * Executes a function with its dependencies injected.
12655
13593
  *
12656
- * @method Diagram#invoke
13594
+ * @template T
12657
13595
  *
12658
- * @param {Function} fn The function to be executed.
12659
- * @param {InjectionContext} [context] The context.
12660
- * @param {LocalsMap} [locals] The locals.
13596
+ * @param {Function} func function to be invoked
13597
+ * @param {InjectionContext} [context] context of the invocation
13598
+ * @param {LocalsMap} [locals] locals provided
13599
+ *
13600
+ * @return {T|null}
12661
13601
  */
12662
13602
  this.invoke = injector.invoke;
12663
13603
 
@@ -12677,9 +13617,11 @@
12677
13617
  *
12678
13618
  * @example
12679
13619
  *
13620
+ * ```javascript
12680
13621
  * eventBus.on('diagram.init', function() {
12681
13622
  * eventBus.fire('my-custom-event', { foo: 'BAR' });
12682
13623
  * });
13624
+ * ```
12683
13625
  *
12684
13626
  * @type {Object}
12685
13627
  */
@@ -12689,8 +13631,6 @@
12689
13631
 
12690
13632
  /**
12691
13633
  * Destroys the diagram
12692
- *
12693
- * @method Diagram#destroy
12694
13634
  */
12695
13635
  Diagram.prototype.destroy = function() {
12696
13636
  this.get('eventBus').fire('diagram.destroy');
@@ -20228,6 +21168,10 @@
20228
21168
  return new BpmnModdle(pks, options);
20229
21169
  }
20230
21170
 
21171
+ /**
21172
+ * @typedef {import('../model/Types').ModdleElement} ModdleElement
21173
+ */
21174
+
20231
21175
  // TODO(nikku): remove with future bpmn-js version
20232
21176
 
20233
21177
  /**
@@ -20237,6 +21181,10 @@
20237
21181
  * 2) If Promise class is implemented in current environment.
20238
21182
  *
20239
21183
  * @private
21184
+ *
21185
+ * @param {Function} api
21186
+ *
21187
+ * @return {Function}
20240
21188
  */
20241
21189
  function wrapForCompatibility(api) {
20242
21190
 
@@ -20285,6 +21233,11 @@
20285
21233
 
20286
21234
  var DI_ERROR_MESSAGE = 'Tried to access di from the businessObject. The di is available through the diagram element only. For more information, see https://github.com/bpmn-io/bpmn-js/issues/1472';
20287
21235
 
21236
+ /**
21237
+ * @private
21238
+ *
21239
+ * @param {ModdleElement} businessObject
21240
+ */
20288
21241
  function ensureCompatDiRef(businessObject) {
20289
21242
 
20290
21243
  // bpmnElement can have multiple independent DIs
@@ -20299,10 +21252,16 @@
20299
21252
  }
20300
21253
 
20301
21254
  /**
20302
- * Returns true if an element has the given meta-model type
21255
+ * @typedef {import('diagram-js/lib/i18n/translate/translate').default} Translate
20303
21256
  *
20304
- * @param {ModdleElement} element
20305
- * @param {string} type
21257
+ * @typedef {import('../model/Types').ModdleElement} ModdleElement
21258
+ */
21259
+
21260
+ /**
21261
+ * Returns true if an element is of the given meta-model type.
21262
+ *
21263
+ * @param {ModdleElement} element
21264
+ * @param {string} type
20306
21265
  *
20307
21266
  * @return {boolean}
20308
21267
  */
@@ -20314,6 +21273,10 @@
20314
21273
  /**
20315
21274
  * Find a suitable display candidate for definitions where the DI does not
20316
21275
  * correctly specify one.
21276
+ *
21277
+ * @param {ModdleElement} definitions
21278
+ *
21279
+ * @return {ModdleElement}
20317
21280
  */
20318
21281
  function findDisplayCandidate(definitions) {
20319
21282
  return find(definitions.rootElements, function(e) {
@@ -20321,7 +21284,10 @@
20321
21284
  });
20322
21285
  }
20323
21286
 
20324
-
21287
+ /**
21288
+ * @param {Record<'element' | 'root' | 'error', Function>} handler
21289
+ * @param {Translate} translate
21290
+ */
20325
21291
  function BpmnTreeWalker(handler, translate) {
20326
21292
 
20327
21293
  // list of containers already walked
@@ -20390,7 +21356,7 @@
20390
21356
 
20391
21357
  // DI handling //////////////////////
20392
21358
 
20393
- function registerDi(di) {
21359
+ var registerDi = this.registerDi = function registerDi(di) {
20394
21360
  var bpmnElement = di.bpmnElement;
20395
21361
 
20396
21362
  if (bpmnElement) {
@@ -20414,7 +21380,7 @@
20414
21380
  { element: di }
20415
21381
  );
20416
21382
  }
20417
- }
21383
+ };
20418
21384
 
20419
21385
  function handleDiagram(diagram) {
20420
21386
  handlePlane(diagram.plane);
@@ -20434,14 +21400,14 @@
20434
21400
  // Semantic handling //////////////////////
20435
21401
 
20436
21402
  /**
20437
- * Handle definitions and return the rendered diagram (if any)
21403
+ * Handle definitions and return the rendered diagram (if any).
20438
21404
  *
20439
21405
  * @param {ModdleElement} definitions to walk and import
20440
21406
  * @param {ModdleElement} [diagram] specific diagram to import and display
20441
21407
  *
20442
21408
  * @throws {Error} if no diagram to display could be found
20443
21409
  */
20444
- function handleDefinitions(definitions, diagram) {
21410
+ this.handleDefinitions = function handleDefinitions(definitions, diagram) {
20445
21411
 
20446
21412
  // make sure we walk the correct bpmnElement
20447
21413
 
@@ -20518,10 +21484,10 @@
20518
21484
  }
20519
21485
 
20520
21486
  // handle all deferred elements
20521
- handleDeferred();
20522
- }
21487
+ handleDeferred(deferred);
21488
+ };
20523
21489
 
20524
- function handleDeferred() {
21490
+ var handleDeferred = this.handleDeferred = function handleDeferred() {
20525
21491
 
20526
21492
  var fn;
20527
21493
 
@@ -20531,7 +21497,7 @@
20531
21497
 
20532
21498
  fn();
20533
21499
  }
20534
- }
21500
+ };
20535
21501
 
20536
21502
  function handleProcess(process, context) {
20537
21503
  handleFlowElementsContainer(process, context);
@@ -20607,10 +21573,10 @@
20607
21573
  forEach$1(ioSpecification.dataOutputs, contextual(handleDataOutput, context));
20608
21574
  }
20609
21575
 
20610
- function handleSubProcess(subProcess, context) {
21576
+ var handleSubProcess = this.handleSubProcess = function handleSubProcess(subProcess, context) {
20611
21577
  handleFlowElementsContainer(subProcess, context);
20612
21578
  handleArtifacts(subProcess.artifacts, context);
20613
- }
21579
+ };
20614
21580
 
20615
21581
  function handleFlowNode(flowNode, context) {
20616
21582
  var childCtx = visitIfDi(flowNode, context);
@@ -20735,44 +21701,29 @@
20735
21701
  }
20736
21702
  });
20737
21703
  }
20738
-
20739
- // API //////////////////////
20740
-
20741
- return {
20742
- handleDeferred: handleDeferred,
20743
- handleDefinitions: handleDefinitions,
20744
- handleSubProcess: handleSubProcess,
20745
- registerDi: registerDi
20746
- };
20747
21704
  }
20748
21705
 
20749
21706
  /**
20750
- * The importBpmnDiagram result.
21707
+ * @typedef {import('../model/Types').ModdleElement} ModdleElement
20751
21708
  *
20752
- * @typedef {Object} ImportBPMNDiagramResult
21709
+ * @typedef { {
21710
+ * warnings: string[];
21711
+ * } } ImportBPMNDiagramResult
20753
21712
  *
20754
- * @property {Array<string>} warnings
21713
+ * @typedef {ImportBPMNDiagramResult & Error} ImportBPMNDiagramError
20755
21714
  */
20756
21715
 
20757
- /**
20758
- * The importBpmnDiagram error.
20759
- *
20760
- * @typedef {Error} ImportBPMNDiagramError
20761
- *
20762
- * @property {Array<string>} warnings
20763
- */
20764
-
20765
21716
  /**
20766
21717
  * Import the definitions into a diagram.
20767
21718
  *
20768
21719
  * Errors and warnings are reported through the specified callback.
20769
21720
  *
20770
- * @param {djs.Diagram} diagram
20771
- * @param {ModdleElement<Definitions>} definitions
20772
- * @param {ModdleElement<BPMNDiagram>} [bpmnDiagram] the diagram to be rendered
20773
- * (if not provided, the first one will be rendered)
21721
+ * @param {ModdleElement} diagram
21722
+ * @param {ModdleElement} definitions
21723
+ * @param {ModdleElement} [bpmnDiagram] The diagram to be rendered (if not
21724
+ * provided, the first one will be rendered).
20774
21725
  *
20775
- * Returns {Promise<ImportBPMNDiagramResult, ImportBPMNDiagramError>}
21726
+ * @return {Promise<ImportBPMNDiagramResult>}
20776
21727
  */
20777
21728
  function importBpmnDiagram(diagram, definitions, bpmnDiagram) {
20778
21729
 
@@ -20788,8 +21739,8 @@
20788
21739
  * Walk the diagram semantically, importing (=drawing)
20789
21740
  * all elements you encounter.
20790
21741
  *
20791
- * @param {ModdleElement<Definitions>} definitions
20792
- * @param {ModdleElement<BPMNDiagram>} bpmnDiagram
21742
+ * @param {ModdleElement} definitions
21743
+ * @param {ModdleElement} bpmnDiagram
20793
21744
  */
20794
21745
  function render(definitions, bpmnDiagram) {
20795
21746
 
@@ -20864,10 +21815,10 @@
20864
21815
  * Returns all diagrams in the same hierarchy as the requested diagram.
20865
21816
  * Includes all parent and sub process diagrams.
20866
21817
  *
20867
- * @param {Array} definitions
20868
- * @param {Object} bpmnDiagram
21818
+ * @param {ModdleElement} definitions
21819
+ * @param {ModdleElement} bpmnDiagram
20869
21820
  *
20870
- * @returns {Array<Object>}
21821
+ * @return {ModdleElement[]}
20871
21822
  */
20872
21823
  function getDiagramsToImport(definitions, bpmnDiagram) {
20873
21824
  if (!bpmnDiagram) {
@@ -21019,7 +21970,7 @@
21019
21970
  BPMNIO_IMG +
21020
21971
  '</a>' +
21021
21972
  '<span>' +
21022
- 'Web-based tooling for BPMN, DMN and CMMN diagrams ' +
21973
+ 'Web-based tooling for BPMN, DMN and forms ' +
21023
21974
  'powered by <a href="https://bpmn.io" target="_blank" rel="noopener">bpmn.io</a>.' +
21024
21975
  '</span>' +
21025
21976
  '</div>' +
@@ -21061,22 +22012,89 @@
21061
22012
  * @see http://bpmn.io/license for more information.
21062
22013
  */
21063
22014
 
22015
+ /**
22016
+ * @template T
22017
+ *
22018
+ * @typedef {import('diagram-js/lib/core/EventBus').EventBusEventCallback<T>} EventBusEventCallback
22019
+ */
21064
22020
 
21065
22021
  /**
21066
22022
  * @typedef {import('didi').ModuleDeclaration} ModuleDeclaration
21067
22023
  *
21068
- * @typedef {import('./BaseViewer').BaseModelerOptions} BaseModelerOptions
21069
- * @typedef {import('./BaseViewer').ModdleElement} ModdleElement
21070
- * @typedef {import('./BaseViewer').ImportXMLResult} ImportXMLResult
21071
- * @typedef {import('./BaseViewer').ImportXMLError} ImportXMLError
21072
- * @typedef {import('./BaseViewer').ImportDefinitionsResult} ImportDefinitionsResult
21073
- * @typedef {import('./BaseViewer').ImportDefinitionsError} ImportDefinitionsError
21074
- * @typedef {import('./BaseViewer').ModdleElement} ModdleElement
21075
- * @typedef {import('./BaseViewer').ModdleElementsById} ModdleElementsById
21076
- * @typedef {import('./BaseViewer').OpenResult} OpenResult
21077
- * @typedef {import('./BaseViewer').OpenError} OpenError
21078
- * @typedef {import('./BaseViewer').SaveXMLOptions} SaveXMLOptions
21079
- * @typedef {import('./BaseViewer').SaveXMLResult} SaveXMLResult
22024
+ * @typedef {import('./model/Types').Moddle} Moddle
22025
+ * @typedef {import('./model/Types').ModdleElement} ModdleElement
22026
+ * @typedef {import('./model/Types').ModdleExtension} ModdleExtension
22027
+ *
22028
+ * @typedef { {
22029
+ * width?: number|string;
22030
+ * height?: number|string;
22031
+ * position?: string;
22032
+ * container?: string|HTMLElement;
22033
+ * moddleExtensions?: ModdleExtensions;
22034
+ * additionalModules?: ModuleDeclaration[];
22035
+ * } & Record<string, any> } BaseViewerOptions
22036
+ *
22037
+ * @typedef {Record<string, ModdleElement>} ModdleElementsById
22038
+ *
22039
+ * @typedef { {
22040
+ * [key: string]: ModdleExtension;
22041
+ * } } ModdleExtensions
22042
+ *
22043
+ * @typedef { {
22044
+ * warnings: string[];
22045
+ * } } ImportXMLResult
22046
+ *
22047
+ * @typedef {ImportXMLResult & Error} ImportXMLError
22048
+ *
22049
+ * @typedef {ImportXMLResult} ImportDefinitionsResult
22050
+ *
22051
+ * @typedef {ImportXMLError} ImportDefinitionsError
22052
+ *
22053
+ * @typedef {ImportXMLResult} OpenResult
22054
+ *
22055
+ * @typedef {ImportXMLError} OpenError
22056
+ *
22057
+ * @typedef { {
22058
+ * format?: boolean;
22059
+ * preamble?: boolean;
22060
+ * } } SaveXMLOptions
22061
+ *
22062
+ * @typedef { {
22063
+ * xml?: string;
22064
+ * error?: Error;
22065
+ * } } SaveXMLResult
22066
+ *
22067
+ * @typedef { {
22068
+ * svg: string;
22069
+ * } } SaveSVGResult
22070
+ *
22071
+ * @typedef { {
22072
+ * xml: string;
22073
+ * } } ImportParseStartEvent
22074
+ *
22075
+ * @typedef { {
22076
+ * error?: ImportXMLError;
22077
+ * definitions?: ModdleElement;
22078
+ * elementsById?: ModdleElementsById;
22079
+ * references?: ModdleElement[];
22080
+ * warnings: string[];
22081
+ * } } ImportParseCompleteEvent
22082
+ *
22083
+ * @typedef { {
22084
+ * error?: ImportXMLError;
22085
+ * warnings: string[];
22086
+ * } } ImportDoneEvent
22087
+ *
22088
+ * @typedef { {
22089
+ * definitions: ModdleElement;
22090
+ * } } SaveXMLStartEvent
22091
+ *
22092
+ * @typedef {SaveXMLResult} SaveXMLDoneEvent
22093
+ *
22094
+ * @typedef { {
22095
+ * error?: Error;
22096
+ * svg: string;
22097
+ * } } SaveSVGDoneEvent
21080
22098
  */
21081
22099
 
21082
22100
  /**
@@ -21085,15 +22103,18 @@
21085
22103
  * Have a look at {@link Viewer}, {@link NavigatedViewer} or {@link Modeler} for
21086
22104
  * bundles that include actual features.
21087
22105
  *
21088
- * @param {BaseModelerOptions} [options] The options to configure the viewer.
22106
+ * @param {BaseViewerOptions} [options] The options to configure the viewer.
21089
22107
  */
21090
22108
  function BaseViewer(options) {
21091
22109
 
21092
22110
  /**
21093
- * @type {BaseModelerOptions}
22111
+ * @type {BaseViewerOptions}
21094
22112
  */
21095
22113
  options = assign$1({}, DEFAULT_OPTIONS, options);
21096
22114
 
22115
+ /**
22116
+ * @type {Moddle}
22117
+ */
21097
22118
  this._moddle = this._createModdle(options);
21098
22119
 
21099
22120
  /**
@@ -21132,18 +22153,18 @@
21132
22153
  *
21133
22154
  * @throws {ImportXMLError} An error thrown during the import of the XML.
21134
22155
  *
21135
- * @fires BaseViewer#ImportParseStart
21136
- * @fires BaseViewer#ImportParseComplete
21137
- * @fires Importer#ImportRenderStart
21138
- * @fires Importer#ImportRenderComplete
21139
- * @fires BaseViewer#ImportDone
22156
+ * @fires BaseViewer#ImportParseStartEvent
22157
+ * @fires BaseViewer#ImportParseCompleteEvent
22158
+ * @fires Importer#ImportRenderStartEvent
22159
+ * @fires Importer#ImportRenderCompleteEvent
22160
+ * @fires BaseViewer#ImportDoneEvent
21140
22161
  *
21141
22162
  * @param {string} xml The BPMN 2.0 XML to be imported.
21142
22163
  * @param {ModdleElement|string} [bpmnDiagram] The optional diagram or Id of the BPMN diagram to open.
21143
22164
  *
21144
22165
  * @return {Promise<ImportXMLResult>} A promise resolving with warnings that were produced during the import.
21145
22166
  */
21146
- BaseViewer.prototype.importXML = wrapForCompatibility(async function importXML(xml, bpmnDiagram) {
22167
+ BaseViewer.prototype.importXML = async function importXML(xml, bpmnDiagram) {
21147
22168
 
21148
22169
  const self = this;
21149
22170
 
@@ -21181,9 +22202,8 @@
21181
22202
  /**
21182
22203
  * A `import.parse.start` event.
21183
22204
  *
21184
- * @event BaseViewer#ImportParseStart
21185
- * @type {Object}
21186
- * @property {string} xml The XML that is to be parsed.
22205
+ * @event BaseViewer#ImportParseStartEvent
22206
+ * @type {ImportParseStartEvent}
21187
22207
  */
21188
22208
  xml = this._emit('import.parse.start', { xml: xml }) || xml;
21189
22209
 
@@ -21211,13 +22231,8 @@
21211
22231
  /**
21212
22232
  * A `import.parse.complete` event.
21213
22233
  *
21214
- * @event BaseViewer#ImportParseComplete
21215
- * @type {Object}
21216
- * @property {Error|null} error An error thrown when parsing the XML.
21217
- * @property {ModdleElement} definitions The definitions model element.
21218
- * @property {ModdleElementsById} elementsById The model elements by ID.
21219
- * @property {ModdleElement[]} references The referenced model elements.
21220
- * @property {string[]} warnings The warnings produced when parsing the XML.
22234
+ * @event BaseViewer#ImportParseCompleteEvent
22235
+ * @type {ImportParseCompleteEvent}
21221
22236
  */
21222
22237
  definitions = this._emit('import.parse.complete', ParseCompleteEvent({
21223
22238
  error: null,
@@ -21234,10 +22249,8 @@
21234
22249
  /**
21235
22250
  * A `import.parse.complete` event.
21236
22251
  *
21237
- * @event BaseViewer#ImportDone
21238
- * @type {Object}
21239
- * @property {ImportXMLError|null} error An error thrown during import.
21240
- * @property {string[]} warnings The warnings.
22252
+ * @event BaseViewer#ImportDoneEvent
22253
+ * @type {ImportDoneEvent}
21241
22254
  */
21242
22255
  this._emit('import.done', { error: null, warnings: aggregatedWarnings });
21243
22256
 
@@ -21253,7 +22266,9 @@
21253
22266
 
21254
22267
  throw error;
21255
22268
  }
21256
- });
22269
+ };
22270
+
22271
+ BaseViewer.prototype.importXML = wrapForCompatibility(BaseViewer.prototype.importXML);
21257
22272
 
21258
22273
 
21259
22274
  /**
@@ -21278,12 +22293,14 @@
21278
22293
  *
21279
22294
  * @return {Promise<ImportDefinitionsResult>} A promise resolving with warnings that were produced during the import.
21280
22295
  */
21281
- BaseViewer.prototype.importDefinitions = wrapForCompatibility(async function importDefinitions(definitions, bpmnDiagram) {
22296
+ BaseViewer.prototype.importDefinitions = async function importDefinitions(definitions, bpmnDiagram) {
21282
22297
  this._setDefinitions(definitions);
21283
22298
  const result = await this.open(bpmnDiagram);
21284
22299
 
21285
22300
  return { warnings: result.warnings };
21286
- });
22301
+ };
22302
+
22303
+ BaseViewer.prototype.importDefinitions = wrapForCompatibility(BaseViewer.prototype.importDefinitions);
21287
22304
 
21288
22305
 
21289
22306
  /**
@@ -21307,7 +22324,7 @@
21307
22324
  *
21308
22325
  * @return {Promise<OpenResult>} A promise resolving with warnings that were produced during opening.
21309
22326
  */
21310
- BaseViewer.prototype.open = wrapForCompatibility(async function open(bpmnDiagramOrId) {
22327
+ BaseViewer.prototype.open = async function open(bpmnDiagramOrId) {
21311
22328
 
21312
22329
  const definitions = this._definitions;
21313
22330
  let bpmnDiagram = bpmnDiagramOrId;
@@ -21344,7 +22361,9 @@
21344
22361
  const { warnings } = await importBpmnDiagram(this, definitions, bpmnDiagram);
21345
22362
 
21346
22363
  return { warnings };
21347
- });
22364
+ };
22365
+
22366
+ BaseViewer.prototype.open = wrapForCompatibility(BaseViewer.prototype.open);
21348
22367
 
21349
22368
  /**
21350
22369
  * Export the currently displayed BPMN 2.0 diagram as
@@ -21369,7 +22388,7 @@
21369
22388
  *
21370
22389
  * @return {Promise<SaveXMLResult>} A promise resolving with the XML.
21371
22390
  */
21372
- BaseViewer.prototype.saveXML = wrapForCompatibility(async function saveXML(options) {
22391
+ BaseViewer.prototype.saveXML = async function saveXML(options) {
21373
22392
 
21374
22393
  options = options || {};
21375
22394
 
@@ -21386,9 +22405,8 @@
21386
22405
  /**
21387
22406
  * A `saveXML.start` event.
21388
22407
  *
21389
- * @event BaseViewer#SaveXMLStart
21390
- * @type {Object}
21391
- * @property {ModdleElement} definitions The definitions model element.
22408
+ * @event BaseViewer#SaveXMLStartEvent
22409
+ * @type {SaveXMLStartEvent}
21392
22410
  */
21393
22411
  definitions = this._emit('saveXML.start', {
21394
22412
  definitions
@@ -21409,10 +22427,8 @@
21409
22427
  /**
21410
22428
  * A `saveXML.done` event.
21411
22429
  *
21412
- * @event BaseViewer#SaveXMLDone
21413
- * @type {Object}
21414
- * @property {Error} [error] An error thrown when saving the XML.
21415
- * @property {string} [xml] The saved XML.
22430
+ * @event BaseViewer#SaveXMLDoneEvent
22431
+ * @type {SaveXMLDoneEvent}
21416
22432
  */
21417
22433
  this._emit('saveXML.done', result);
21418
22434
 
@@ -21421,7 +22437,9 @@
21421
22437
  }
21422
22438
 
21423
22439
  return result;
21424
- });
22440
+ };
22441
+
22442
+ BaseViewer.prototype.saveXML = wrapForCompatibility(BaseViewer.prototype.saveXML);
21425
22443
 
21426
22444
 
21427
22445
  /**
@@ -21443,7 +22461,7 @@
21443
22461
  *
21444
22462
  * @return {Promise<SaveSVGResult>} A promise resolving with the SVG.
21445
22463
  */
21446
- BaseViewer.prototype.saveSVG = wrapForCompatibility(async function saveSVG() {
22464
+ BaseViewer.prototype.saveSVG = async function saveSVG() {
21447
22465
  this._emit('saveSVG.start');
21448
22466
 
21449
22467
  let svg, err;
@@ -21475,10 +22493,8 @@
21475
22493
  /**
21476
22494
  * A `saveSVG.done` event.
21477
22495
  *
21478
- * @event BaseViewer#SaveSVGDone
21479
- * @type {Object}
21480
- * @property {Error} [error] An error thrown when saving the SVG.
21481
- * @property {string} [svg] The saved SVG.
22496
+ * @event BaseViewer#SaveSVGDoneEvent
22497
+ * @type {SaveSVGDoneEvent}
21482
22498
  */
21483
22499
  this._emit('saveSVG.done', {
21484
22500
  error: err,
@@ -21490,7 +22506,9 @@
21490
22506
  }
21491
22507
 
21492
22508
  return { svg };
21493
- });
22509
+ };
22510
+
22511
+ BaseViewer.prototype.saveSVG = wrapForCompatibility(BaseViewer.prototype.saveSVG);
21494
22512
 
21495
22513
  /**
21496
22514
  * Get a named diagram service.
@@ -21572,10 +22590,12 @@
21572
22590
  *
21573
22591
  * Remove an event listener via {@link BaseViewer#off}.
21574
22592
  *
22593
+ * @template T
22594
+ *
21575
22595
  * @param {string|string[]} events The event(s) to listen to.
21576
22596
  * @param {number} [priority] The priority with which to listen.
21577
- * @param {EventCallback} callback The callback.
21578
- * @param {*} [that] Value of `this` the callback will be called with.
22597
+ * @param {EventBusEventCallback<T>} callback The callback.
22598
+ * @param {any} [that] Value of `this` the callback will be called with.
21579
22599
  */
21580
22600
  BaseViewer.prototype.on = function(events, priority, callback, that) {
21581
22601
  return this.get('eventBus').on(events, priority, callback, that);
@@ -21625,7 +22645,7 @@
21625
22645
  /**
21626
22646
  * Get the definitions model element.
21627
22647
  *
21628
- * @returns {ModdleElement} The definitions model element.
22648
+ * @return {ModdleElement} The definitions model element.
21629
22649
  */
21630
22650
  BaseViewer.prototype.getDefinitions = function() {
21631
22651
  return this._definitions;
@@ -21694,6 +22714,11 @@
21694
22714
  return this.get('eventBus').fire(type, event);
21695
22715
  };
21696
22716
 
22717
+ /**
22718
+ * @param {BaseViewerOptions} options
22719
+ *
22720
+ * @return {HTMLElement}
22721
+ */
21697
22722
  BaseViewer.prototype._createContainer = function(options) {
21698
22723
 
21699
22724
  const container = domify$1('<div class="bjs-container"></div>');
@@ -21707,6 +22732,11 @@
21707
22732
  return container;
21708
22733
  };
21709
22734
 
22735
+ /**
22736
+ * @param {BaseViewerOptions} options
22737
+ *
22738
+ * @return {Moddle}
22739
+ */
21710
22740
  BaseViewer.prototype._createModdle = function(options) {
21711
22741
  const moddleOptions = assign$1({}, this._moddleExtensions, options.moddleExtensions);
21712
22742
 
@@ -22424,13 +23454,21 @@
22424
23454
  iconRendererModule
22425
23455
  ];
22426
23456
 
23457
+ /**
23458
+ * @type { {
23459
+ * zeebe: any
23460
+ * } }
23461
+ */
22427
23462
  const commonModdleExtensions = {
22428
23463
  zeebe: zeebeModdle
22429
23464
  };
22430
23465
 
22431
23466
  /**
22432
- *
22433
- * @param {Object} options
23467
+ * @typedef {import('bpmn-js/lib/BaseViewer').BaseViewerOptions} BaseViewerOptions
23468
+ */
23469
+
23470
+ /**
23471
+ * @param {BaseViewerOptions} options
22434
23472
  */
22435
23473
  function Viewer(options = {}) {
22436
23474