bpmn-js 11.4.1 → 12.0.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 (43) hide show
  1. package/dist/bpmn-modeler.development.js +5348 -5378
  2. package/dist/bpmn-modeler.production.min.js +17 -18
  3. package/dist/bpmn-navigated-viewer.development.js +838 -599
  4. package/dist/bpmn-navigated-viewer.production.min.js +3 -5
  5. package/dist/bpmn-viewer.development.js +808 -593
  6. package/dist/bpmn-viewer.production.min.js +4 -6
  7. package/lib/BaseModeler.d.ts +5 -0
  8. package/lib/BaseModeler.js +16 -18
  9. package/lib/BaseViewer.d.ts +366 -0
  10. package/lib/BaseViewer.js +147 -109
  11. package/lib/Modeler.d.ts +15 -0
  12. package/lib/Modeler.js +6 -27
  13. package/lib/NavigatedViewer.d.ts +3 -0
  14. package/lib/NavigatedViewer.js +5 -2
  15. package/lib/Viewer.d.ts +3 -0
  16. package/lib/Viewer.js +2 -8
  17. package/lib/features/align-elements/dist/align-bottom-tool.svg +1 -0
  18. package/lib/features/align-elements/dist/align-horizontal-center-tool.svg +1 -0
  19. package/lib/features/align-elements/dist/align-left-tool.svg +1 -0
  20. package/lib/features/align-elements/dist/align-right-tool.svg +1 -0
  21. package/lib/features/align-elements/dist/align-tool.svg +1 -0
  22. package/lib/features/align-elements/dist/align-top-tool.svg +1 -0
  23. package/lib/features/align-elements/dist/align-vertical-center-tool.svg +1 -0
  24. package/lib/features/modeling/behavior/RootElementReferenceBehavior.js +11 -3
  25. package/lib/features/replace/BpmnReplace.js +3 -12
  26. package/lib/features/replace-preview/BpmnReplacePreview.js +1 -1
  27. package/package.json +13 -11
  28. package/lib/features/create-append-anything/AppendContextPadProvider.js +0 -77
  29. package/lib/features/create-append-anything/AppendMenuProvider.js +0 -187
  30. package/lib/features/create-append-anything/AppendRules.js +0 -83
  31. package/lib/features/create-append-anything/CreateAppendEditorActions.js +0 -58
  32. package/lib/features/create-append-anything/CreateAppendKeyboardBindings.js +0 -90
  33. package/lib/features/create-append-anything/CreateMenuProvider.js +0 -114
  34. package/lib/features/create-append-anything/CreatePaletteProvider.js +0 -72
  35. package/lib/features/create-append-anything/index.js +0 -37
  36. package/lib/features/create-append-anything/util/OptionsUtil.js +0 -617
  37. package/lib/icons/Icons.js +0 -11
  38. package/lib/icons/dist/append.svg +0 -1
  39. package/lib/icons/dist/connect-context-pad.svg +0 -1
  40. package/lib/icons/dist/connect-palette.svg +0 -1
  41. package/lib/icons/resources/append.svg +0 -3
  42. package/lib/icons/resources/create.svg +0 -3
  43. /package/lib/{icons → features/palette}/dist/create.svg +0 -0
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * bpmn-js - bpmn-viewer v11.4.1
2
+ * bpmn-js - bpmn-viewer v12.0.0
3
3
  *
4
4
  * Copyright (c) 2014-present, camunda Services GmbH
5
5
  *
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * Source Code: https://github.com/bpmn-io/bpmn-js
10
10
  *
11
- * Date: 2023-02-16
11
+ * Date: 2023-03-29
12
12
  */
13
13
  (function (global, factory) {
14
14
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -447,6 +447,14 @@
447
447
 
448
448
  var DEFAULT_RENDER_PRIORITY$1 = 1000;
449
449
 
450
+ /**
451
+ * @typedef {import('../model').Base} Base
452
+ * @typedef {import('../model').Connection} Connection
453
+ * @typedef {import('../model').Shape} Shape
454
+ *
455
+ * @typedef {import('../core/EventBus').default} EventBus
456
+ */
457
+
450
458
  /**
451
459
  * The base implementation of shape and connection renderers.
452
460
  *
@@ -485,52 +493,51 @@
485
493
  }
486
494
 
487
495
  /**
488
- * Should check whether *this* renderer can render
489
- * the element/connection.
496
+ * Checks whether an element can be rendered.
490
497
  *
491
- * @param {element} element
498
+ * @param {Base} element The element to be rendered.
492
499
  *
493
- * @returns {boolean}
500
+ * @returns {boolean} Whether the element can be rendered.
494
501
  */
495
- BaseRenderer.prototype.canRender = function() {};
502
+ BaseRenderer.prototype.canRender = function(element) {};
496
503
 
497
504
  /**
498
- * Provides the shape's snap svg element to be drawn on the `canvas`.
505
+ * Draws a shape.
499
506
  *
500
- * @param {djs.Graphics} visuals
501
- * @param {Shape} shape
507
+ * @param {SVGElement} visuals The SVG element to draw the shape into.
508
+ * @param {Shape} shape The shape to be drawn.
502
509
  *
503
- * @returns {Snap.svg} [returns a Snap.svg paper element ]
510
+ * @returns {SVGElement} The SVG element of the shape drawn.
504
511
  */
505
- BaseRenderer.prototype.drawShape = function() {};
512
+ BaseRenderer.prototype.drawShape = function(visuals, shape) {};
506
513
 
507
514
  /**
508
- * Provides the shape's snap svg element to be drawn on the `canvas`.
515
+ * Draws a connection.
509
516
  *
510
- * @param {djs.Graphics} visuals
511
- * @param {Connection} connection
517
+ * @param {SVGElement} visuals The SVG element to draw the connection into.
518
+ * @param {Connection} connection The connection to be drawn.
512
519
  *
513
- * @returns {Snap.svg} [returns a Snap.svg paper element ]
520
+ * @returns {SVGElement} The SVG element of the connection drawn.
514
521
  */
515
- BaseRenderer.prototype.drawConnection = function() {};
522
+ BaseRenderer.prototype.drawConnection = function(visuals, connection) {};
516
523
 
517
524
  /**
518
- * Gets the SVG path of a shape that represents it's visual bounds.
525
+ * Gets the SVG path of the graphical representation of a shape.
519
526
  *
520
- * @param {Shape} shape
527
+ * @param {Shape} shape The shape.
521
528
  *
522
- * @return {string} svg path
529
+ * @return {string} The SVG path of the shape.
523
530
  */
524
- BaseRenderer.prototype.getShapePath = function() {};
531
+ BaseRenderer.prototype.getShapePath = function(shape) {};
525
532
 
526
533
  /**
527
- * Gets the SVG path of a connection that represents it's visual bounds.
534
+ * Gets the SVG path of the graphical representation of a connection.
528
535
  *
529
- * @param {Connection} connection
536
+ * @param {Connection} connection The connection.
530
537
  *
531
- * @return {string} svg path
538
+ * @return {string} The SVG path of the connection.
532
539
  */
533
- BaseRenderer.prototype.getConnectionPath = function() {};
540
+ BaseRenderer.prototype.getConnectionPath = function(connection) {};
534
541
 
535
542
  /**
536
543
  * Is an element of the given BPMN type?
@@ -1337,9 +1344,15 @@
1337
1344
  }
1338
1345
 
1339
1346
  /**
1340
- * @param { [ string, ...any[] ][] } elements
1347
+ * @typedef {(string|number)[]} Component
1341
1348
  *
1342
- * @return { string }
1349
+ * @typedef {import('../util/Types').Point} Point
1350
+ */
1351
+
1352
+ /**
1353
+ * @param {Component[]} elements
1354
+ *
1355
+ * @return {string}
1343
1356
  */
1344
1357
  function componentsToPath(elements) {
1345
1358
  return elements.flat().join(',').replace(/,?([A-z]),?/g, '$1');
@@ -1419,9 +1432,9 @@
1419
1432
  }
1420
1433
 
1421
1434
  /**
1422
- * @param { { x: number, y: number }[] } points
1423
- * @param { any } [attrs]
1424
- * @param { number } [radius]
1435
+ * @param {Point[]} points
1436
+ * @param {*} [attrs]
1437
+ * @param {number} [radius]
1425
1438
  *
1426
1439
  * @return {SVGElement}
1427
1440
  */
@@ -1446,8 +1459,8 @@
1446
1459
  }
1447
1460
 
1448
1461
  /**
1449
- * @param { SVGElement } gfx
1450
- * @param { { x: number, y: number }[]} points
1462
+ * @param {SVGElement} gfx
1463
+ * @param {Point[]} points
1451
1464
  *
1452
1465
  * @return {SVGElement}
1453
1466
  */
@@ -2162,7 +2175,7 @@
2162
2175
  }
2163
2176
 
2164
2177
  /**
2165
- * @param {<SVGElement>} element
2178
+ * @param {SVGElement} element
2166
2179
  * @param {number} x
2167
2180
  * @param {number} y
2168
2181
  * @param {number} angle
@@ -4242,6 +4255,10 @@
4242
4255
  return getRectPath(element);
4243
4256
  };
4244
4257
 
4258
+ /**
4259
+ * @typedef {import('../util/Types').Dimensions} Dimensions
4260
+ */
4261
+
4245
4262
  var DEFAULT_BOX_PADDING = 0;
4246
4263
 
4247
4264
  var DEFAULT_LABEL_SIZE$1 = {
@@ -4315,7 +4332,8 @@
4315
4332
  *
4316
4333
  * Alters the lines passed.
4317
4334
  *
4318
- * @param {Array<string>} lines
4335
+ * @param {string[]} lines
4336
+ *
4319
4337
  * @return {Object} the line descriptor, an object { width, height, text }
4320
4338
  */
4321
4339
  function layoutNext(lines, maxWidth, fakeText) {
@@ -4360,8 +4378,9 @@
4360
4378
  * Shortens a line based on spacing and hyphens.
4361
4379
  * Returns the shortened result on success.
4362
4380
  *
4363
- * @param {string} line
4364
- * @param {number} maxLength the maximum characters of the string
4381
+ * @param {string} line
4382
+ * @param {number} maxLength the maximum characters of the string
4383
+ *
4365
4384
  * @return {string} the shortened string
4366
4385
  */
4367
4386
  function semanticShorten(line, maxLength) {
@@ -5201,6 +5220,10 @@
5201
5220
  pathMap: [ 'type', PathMap ]
5202
5221
  };
5203
5222
 
5223
+ /**
5224
+ * @typedef {import('./').Replacements} Replacements
5225
+ */
5226
+
5204
5227
  /**
5205
5228
  * A simple translation stub to be used for multi-language support
5206
5229
  * in diagrams. Can be easily replaced with a more sophisticated
@@ -5215,7 +5238,7 @@
5215
5238
  * }
5216
5239
  *
5217
5240
  * @param {string} template to interpolate
5218
- * @param {Object} [replacements] a map with substitutes
5241
+ * @param {Replacements} [replacements] a map with substitutes
5219
5242
  *
5220
5243
  * @return {string} the translated string
5221
5244
  */
@@ -5368,8 +5391,6 @@
5368
5391
  }, size);
5369
5392
  }
5370
5393
 
5371
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
5372
-
5373
5394
  function getDefaultExportFromCjs (x) {
5374
5395
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5375
5396
  }
@@ -5386,9 +5407,9 @@
5386
5407
  /**
5387
5408
  * Convert the given bounds to a { top, left, bottom, right } descriptor.
5388
5409
  *
5389
- * @param {Bounds|Point} bounds
5410
+ * @param {Point|Rect} bounds
5390
5411
  *
5391
- * @return {Object}
5412
+ * @return {RectTRBL}
5392
5413
  */
5393
5414
  function asTRBL(bounds) {
5394
5415
  return {
@@ -5403,9 +5424,9 @@
5403
5424
  /**
5404
5425
  * Convert a { top, left, bottom, right } to an objects bounds.
5405
5426
  *
5406
- * @param {Object} trbl
5427
+ * @param {RectTRBL} trbl
5407
5428
  *
5408
- * @return {Bounds}
5429
+ * @return {Rect}
5409
5430
  */
5410
5431
  function asBounds(trbl) {
5411
5432
  return {
@@ -5420,7 +5441,7 @@
5420
5441
  /**
5421
5442
  * Get the mid of the given bounds or point.
5422
5443
  *
5423
- * @param {Bounds|Point} bounds
5444
+ * @param {Point|Rect} bounds
5424
5445
  *
5425
5446
  * @return {Point}
5426
5447
  */
@@ -5435,7 +5456,7 @@
5435
5456
  /**
5436
5457
  * Get the mid of the given Connection.
5437
5458
  *
5438
- * @param {djs.Base.Connection} connection
5459
+ * @param {Connection} connection
5439
5460
  *
5440
5461
  * @return {Point}
5441
5462
  */
@@ -5494,7 +5515,7 @@
5494
5515
  /**
5495
5516
  * Get the mid of the given Element.
5496
5517
  *
5497
- * @param {djs.Base.Connection} connection
5518
+ * @param {Connection} connection
5498
5519
  *
5499
5520
  * @return {Point}
5500
5521
  */
@@ -5904,6 +5925,14 @@
5904
5925
  return isPrimaryButton(event) && originalEvent.shiftKey;
5905
5926
  }
5906
5927
 
5928
+ /**
5929
+ * @typedef {import('../../model').Base} Base
5930
+ *
5931
+ * @typedef {import('../../core/ElementRegistry').default} ElementRegistry
5932
+ * @typedef {import('../../core/EventBus').default} EventBus
5933
+ * @typedef {import('../../draw/Styles').default} Styles
5934
+ */
5935
+
5907
5936
  function allowAll(event) { return true; }
5908
5937
 
5909
5938
  function allowPrimaryAndAuxiliary(event) {
@@ -5933,6 +5962,8 @@
5933
5962
  * prevents the original DOM operation.
5934
5963
  *
5935
5964
  * @param {EventBus} eventBus
5965
+ * @param {ElementRegistry} elementRegistry
5966
+ * @param {Styles} styles
5936
5967
  */
5937
5968
  function InteractionEvents(eventBus, elementRegistry, styles) {
5938
5969
 
@@ -5942,8 +5973,8 @@
5942
5973
  * Fire an interaction event.
5943
5974
  *
5944
5975
  * @param {string} type local event name, e.g. element.click.
5945
- * @param {DOMEvent} event native event
5946
- * @param {djs.model.Base} [element] the diagram element to emit the event on;
5976
+ * @param {MouseEvent|TouchEvent} event native event
5977
+ * @param {Base} [element] the diagram element to emit the event on;
5947
5978
  * defaults to the event target
5948
5979
  */
5949
5980
  function fire(type, event, element) {
@@ -6025,8 +6056,8 @@
6025
6056
  * on the target shape or connection.
6026
6057
  *
6027
6058
  * @param {string} eventName the name of the triggered DOM event
6028
- * @param {MouseEvent} event
6029
- * @param {djs.model.Base} targetElement
6059
+ * @param {MouseEvent|TouchEvent} event
6060
+ * @param {Base} targetElement
6030
6061
  */
6031
6062
  function triggerMouseEvent(eventName, event, targetElement) {
6032
6063
 
@@ -6192,7 +6223,7 @@
6192
6223
  /**
6193
6224
  * Create default hit for the given element.
6194
6225
  *
6195
- * @param {djs.model.Base} element
6226
+ * @param {Base} element
6196
6227
  * @param {SVGElement} gfx
6197
6228
  *
6198
6229
  * @return {SVGElement} created hit
@@ -6264,8 +6295,8 @@
6264
6295
  /**
6265
6296
  * Update default hit of the element.
6266
6297
  *
6267
- * @param {djs.model.Base} element
6268
- * @param {SVGElement} gfx
6298
+ * @param {Base} element
6299
+ * @param {SVGElement} gfx
6269
6300
  *
6270
6301
  * @return {SVGElement} updated hit
6271
6302
  */
@@ -6313,7 +6344,7 @@
6313
6344
  * @event element.hover
6314
6345
  *
6315
6346
  * @type {Object}
6316
- * @property {djs.model.Base} element
6347
+ * @property {Base} element
6317
6348
  * @property {SVGElement} gfx
6318
6349
  * @property {Event} originalEvent
6319
6350
  */
@@ -6324,7 +6355,7 @@
6324
6355
  * @event element.out
6325
6356
  *
6326
6357
  * @type {Object}
6327
- * @property {djs.model.Base} element
6358
+ * @property {Base} element
6328
6359
  * @property {SVGElement} gfx
6329
6360
  * @property {Event} originalEvent
6330
6361
  */
@@ -6335,7 +6366,7 @@
6335
6366
  * @event element.click
6336
6367
  *
6337
6368
  * @type {Object}
6338
- * @property {djs.model.Base} element
6369
+ * @property {Base} element
6339
6370
  * @property {SVGElement} gfx
6340
6371
  * @property {Event} originalEvent
6341
6372
  */
@@ -6346,7 +6377,7 @@
6346
6377
  * @event element.dblclick
6347
6378
  *
6348
6379
  * @type {Object}
6349
- * @property {djs.model.Base} element
6380
+ * @property {Base} element
6350
6381
  * @property {SVGElement} gfx
6351
6382
  * @property {Event} originalEvent
6352
6383
  */
@@ -6357,7 +6388,7 @@
6357
6388
  * @event element.mousedown
6358
6389
  *
6359
6390
  * @type {Object}
6360
- * @property {djs.model.Base} element
6391
+ * @property {Base} element
6361
6392
  * @property {SVGElement} gfx
6362
6393
  * @property {Event} originalEvent
6363
6394
  */
@@ -6368,7 +6399,7 @@
6368
6399
  * @event element.mouseup
6369
6400
  *
6370
6401
  * @type {Object}
6371
- * @property {djs.model.Base} element
6402
+ * @property {Base} element
6372
6403
  * @property {SVGElement} gfx
6373
6404
  * @property {Event} originalEvent
6374
6405
  */
@@ -6380,7 +6411,7 @@
6380
6411
  * @event element.contextmenu
6381
6412
  *
6382
6413
  * @type {Object}
6383
- * @property {djs.model.Base} element
6414
+ * @property {Base} element
6384
6415
  * @property {SVGElement} gfx
6385
6416
  * @property {Event} originalEvent
6386
6417
  */
@@ -6394,10 +6425,10 @@
6394
6425
  * Returns the surrounding bbox for all elements in
6395
6426
  * the array or the element primitive.
6396
6427
  *
6397
- * @param {Array<djs.model.Shape>|djs.model.Shape} elements
6428
+ * @param {Base|Base[]} elements
6398
6429
  * @param {boolean} [stopRecursion=false]
6399
6430
  *
6400
- * @return {Bounds}
6431
+ * @return {Rect}
6401
6432
  */
6402
6433
  function getBBox(elements, stopRecursion) {
6403
6434
 
@@ -6468,6 +6499,12 @@
6468
6499
 
6469
6500
  var LOW_PRIORITY$2 = 500;
6470
6501
 
6502
+ /**
6503
+ * @typedef {import('../../model').Base} Base
6504
+ *
6505
+ * @typedef {import('../../core/EventBus').default} EventBus
6506
+ * @typedef {import('../../draw/Styles').default} Styles
6507
+ */
6471
6508
 
6472
6509
  /**
6473
6510
  * @class
@@ -6477,9 +6514,8 @@
6477
6514
  *
6478
6515
  * @param {EventBus} eventBus
6479
6516
  * @param {Styles} styles
6480
- * @param {ElementRegistry} elementRegistry
6481
6517
  */
6482
- function Outline(eventBus, styles, elementRegistry) {
6518
+ function Outline(eventBus, styles) {
6483
6519
 
6484
6520
  this.offset = 6;
6485
6521
 
@@ -6537,8 +6573,8 @@
6537
6573
  * Updates the outline of a shape respecting the dimension of the
6538
6574
  * element and an outline offset.
6539
6575
  *
6540
- * @param {SVGElement} outline
6541
- * @param {djs.model.Base} element
6576
+ * @param {SVGElement} outline
6577
+ * @param {Base} element
6542
6578
  */
6543
6579
  Outline.prototype.updateShapeOutline = function(outline, element) {
6544
6580
 
@@ -6556,8 +6592,8 @@
6556
6592
  * Updates the outline of a connection respecting the bounding box of
6557
6593
  * the connection and an outline offset.
6558
6594
  *
6559
- * @param {SVGElement} outline
6560
- * @param {djs.model.Base} element
6595
+ * @param {SVGElement} outline
6596
+ * @param {Base} element
6561
6597
  */
6562
6598
  Outline.prototype.updateConnectionOutline = function(outline, connection) {
6563
6599
 
@@ -6580,13 +6616,17 @@
6580
6616
  outline: [ 'type', Outline ]
6581
6617
  };
6582
6618
 
6619
+ /**
6620
+ * @typedef {import('../../core/EventBus').default} EventBus
6621
+ */
6622
+
6583
6623
  /**
6584
6624
  * A service that offers the current selection in a diagram.
6585
6625
  * Offers the api to control the selection, too.
6586
6626
  *
6587
6627
  * @class
6588
6628
  *
6589
- * @param {EventBus} eventBus the event bus
6629
+ * @param {EventBus} eventBus
6590
6630
  */
6591
6631
  function Selection(eventBus, canvas) {
6592
6632
 
@@ -6642,8 +6682,8 @@
6642
6682
  *
6643
6683
  * @method Selection#select
6644
6684
  *
6645
- * @param {Object|Object[]} elements element or array of elements to be selected
6646
- * @param {boolean} [add] whether the element(s) should be appended to the current selection, defaults to false
6685
+ * @param {Object|Object[]} elements element or array of elements to be selected
6686
+ * @param {boolean} [add] whether the element(s) should be appended to the current selection, defaults to false
6647
6687
  */
6648
6688
  Selection.prototype.select = function(elements, add) {
6649
6689
  var selectedElements = this._selectedElements,
@@ -6682,6 +6722,12 @@
6682
6722
  this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
6683
6723
  };
6684
6724
 
6725
+ /**
6726
+ * @typedef {import('../../core/Canvas').default} Canvas
6727
+ * @typedef {import('../../core/EventBus').default} EventBus
6728
+ * @typedef {import('./Selection').default} Selection
6729
+ */
6730
+
6685
6731
  var MARKER_HOVER = 'hover',
6686
6732
  MARKER_SELECTED = 'selected';
6687
6733
 
@@ -6698,6 +6744,7 @@
6698
6744
  *
6699
6745
  * @param {Canvas} canvas
6700
6746
  * @param {EventBus} eventBus
6747
+ * @param {Selection} selection
6701
6748
  */
6702
6749
  function SelectionVisuals(canvas, eventBus, selection) {
6703
6750
  this._canvas = canvas;
@@ -6803,6 +6850,19 @@
6803
6850
  };
6804
6851
  }
6805
6852
 
6853
+ /**
6854
+ * @typedef {import('../../core/Canvas').default} Canvas
6855
+ * @typedef {import('../../core/ElementRegistry').default} ElementRegistry
6856
+ * @typedef {import('../../core/EventBus').default} EventBus
6857
+ * @typedef {import('./Selection').default} Selection
6858
+ */
6859
+
6860
+ /**
6861
+ * @param {EventBus} eventBus
6862
+ * @param {Selection} selection
6863
+ * @param {Canvas} canvas
6864
+ * @param {ElementRegistry} elementRegistry
6865
+ */
6806
6866
  function SelectionBehavior(eventBus, selection, canvas, elementRegistry) {
6807
6867
 
6808
6868
  // Select elements on create
@@ -6923,9 +6983,8 @@
6923
6983
  /**
6924
6984
  * Util that provides unique IDs.
6925
6985
  *
6926
- * @class djs.util.IdGenerator
6986
+ * @class
6927
6987
  * @constructor
6928
- * @memberOf djs.util
6929
6988
  *
6930
6989
  * The ids can be customized via a given prefix and contain a random value to avoid collisions.
6931
6990
  *
@@ -6940,8 +6999,6 @@
6940
6999
  /**
6941
7000
  * Returns a next unique ID.
6942
7001
  *
6943
- * @method djs.util.IdGenerator#next
6944
- *
6945
7002
  * @returns {string} the id
6946
7003
  */
6947
7004
  IdGenerator.prototype.next = function() {
@@ -6953,6 +7010,18 @@
6953
7010
 
6954
7011
  var LOW_PRIORITY$1 = 500;
6955
7012
 
7013
+ /**
7014
+ * @typedef {import('../../core/Canvas').default} Canvas
7015
+ * @typedef {import('../../core/ElementRegistry').default} ElementRegistry
7016
+ * @typedef {import('../../core/EventBus').default} EventBus
7017
+ *
7018
+ * @typedef {import('./Overlays').Overlay} Overlay
7019
+ * @typedef {import('./Overlays').OverlayAttrs} OverlayAttrs
7020
+ * @typedef {import('./Overlays').OverlayContainer} OverlayContainer
7021
+ * @typedef {import('./Overlays').OverlaysConfig} OverlaysConfig
7022
+ * @typedef {import('./Overlays').OverlaysConfigDefault} OverlaysConfigDefault
7023
+ * @typedef {import('./Overlays').OverlaysFilter} OverlaysFilter
7024
+ */
6956
7025
 
6957
7026
  /**
6958
7027
  * A service that allows users to attach overlays to diagram elements.
@@ -6962,6 +7031,7 @@
6962
7031
  * @example
6963
7032
  *
6964
7033
  * // add a pink badge on the top left of the shape
7034
+ *
6965
7035
  * overlays.add(someShape, {
6966
7036
  * position: {
6967
7037
  * top: -5,
@@ -7013,19 +7083,21 @@
7013
7083
  * }
7014
7084
  * }
7015
7085
  *
7016
- * @param {Object} config
7086
+ * @param {OverlaysConfig} config
7017
7087
  * @param {EventBus} eventBus
7018
7088
  * @param {Canvas} canvas
7019
7089
  * @param {ElementRegistry} elementRegistry
7020
7090
  */
7021
7091
  function Overlays(config, eventBus, canvas, elementRegistry) {
7022
-
7023
7092
  this._eventBus = eventBus;
7024
7093
  this._canvas = canvas;
7025
7094
  this._elementRegistry = elementRegistry;
7026
7095
 
7027
7096
  this._ids = ids;
7028
7097
 
7098
+ /**
7099
+ * @type {OverlaysConfigDefault}
7100
+ */
7029
7101
  this._overlayDefaults = assign$1({
7030
7102
 
7031
7103
  // no show constraints
@@ -7036,16 +7108,18 @@
7036
7108
  }, config && config.defaults);
7037
7109
 
7038
7110
  /**
7039
- * Mapping overlayId -> overlay
7111
+ * @type {Map<string, Overlay>}
7040
7112
  */
7041
7113
  this._overlays = {};
7042
7114
 
7043
7115
  /**
7044
- * Mapping elementId -> overlay container
7116
+ * @type {OverlayContainer[]}
7045
7117
  */
7046
7118
  this._overlayContainers = [];
7047
7119
 
7048
- // root html element for all overlays
7120
+ /**
7121
+ * @type {HTMLElement}
7122
+ */
7049
7123
  this._overlayRoot = createRoot(canvas.getContainer());
7050
7124
 
7051
7125
  this._init();
@@ -7061,12 +7135,12 @@
7061
7135
 
7062
7136
 
7063
7137
  /**
7064
- * Returns the overlay with the specified id or a list of overlays
7138
+ * Returns the overlay with the specified ID or a list of overlays
7065
7139
  * for an element with a given type.
7066
7140
  *
7067
7141
  * @example
7068
7142
  *
7069
- * // return the single overlay with the given id
7143
+ * // return the single overlay with the given ID
7070
7144
  * overlays.get('some-id');
7071
7145
  *
7072
7146
  * // return all overlays for the shape
@@ -7075,16 +7149,12 @@
7075
7149
  * // return all overlays on shape with type 'badge'
7076
7150
  * overlays.get({ element: someShape, type: 'badge' });
7077
7151
  *
7078
- * // shape can also be specified as id
7152
+ * // shape can also be specified as ID
7079
7153
  * overlays.get({ element: 'element-id', type: 'badge' });
7080
7154
  *
7155
+ * @param {OverlaysFilter} search The filter to be used to find the overlay(s).
7081
7156
  *
7082
- * @param {Object} search
7083
- * @param {string} [search.id]
7084
- * @param {string|djs.model.Base} [search.element]
7085
- * @param {string} [search.type]
7086
- *
7087
- * @return {Object|Array<Object>} the overlay(s)
7157
+ * @return {Overlay|Overlay[]} The overlay(s).
7088
7158
  */
7089
7159
  Overlays.prototype.get = function(search) {
7090
7160
 
@@ -7116,27 +7186,13 @@
7116
7186
  };
7117
7187
 
7118
7188
  /**
7119
- * Adds a HTML overlay to an element.
7120
- *
7121
- * @param {string|djs.model.Base} element attach overlay to this shape
7122
- * @param {string} [type] optional type to assign to the overlay
7123
- * @param {Object} overlay the overlay configuration
7189
+ * Adds an HTML overlay to an element.
7124
7190
  *
7125
- * @param {string|DOMElement} overlay.html html element to use as an overlay
7126
- * @param {Object} [overlay.show] show configuration
7127
- * @param {number} [overlay.show.minZoom] minimal zoom level to show the overlay
7128
- * @param {number} [overlay.show.maxZoom] maximum zoom level to show the overlay
7129
- * @param {Object} overlay.position where to attach the overlay
7130
- * @param {number} [overlay.position.left] relative to element bbox left attachment
7131
- * @param {number} [overlay.position.top] relative to element bbox top attachment
7132
- * @param {number} [overlay.position.bottom] relative to element bbox bottom attachment
7133
- * @param {number} [overlay.position.right] relative to element bbox right attachment
7134
- * @param {boolean|Object} [overlay.scale=true] false to preserve the same size regardless of
7135
- * diagram zoom
7136
- * @param {number} [overlay.scale.min]
7137
- * @param {number} [overlay.scale.max]
7191
+ * @param {Base|string} element The element to add the overlay to.
7192
+ * @param {string} [type] An optional type that can be used to filter.
7193
+ * @param {OverlayAttrs} overlay The overlay.
7138
7194
  *
7139
- * @return {string} id that may be used to reference the overlay for update or removal
7195
+ * @return {string} The overlay's ID that can be used to get or remove it.
7140
7196
  */
7141
7197
  Overlays.prototype.add = function(element, type, overlay) {
7142
7198
 
@@ -7177,11 +7233,11 @@
7177
7233
 
7178
7234
 
7179
7235
  /**
7180
- * Remove an overlay with the given id or all overlays matching the given filter.
7236
+ * Remove an overlay with the given ID or all overlays matching the given filter.
7181
7237
  *
7182
7238
  * @see Overlays#get for filter options.
7183
7239
  *
7184
- * @param {string|object} [filter]
7240
+ * @param {OverlaysFilter} filter The filter to be used to find the overlay.
7185
7241
  */
7186
7242
  Overlays.prototype.remove = function(filter) {
7187
7243
 
@@ -7217,19 +7273,32 @@
7217
7273
 
7218
7274
  };
7219
7275
 
7276
+ /**
7277
+ * Checks whether overlays are shown.
7278
+ *
7279
+ * @returns {boolean} Whether overlays are shown.
7280
+ */
7220
7281
  Overlays.prototype.isShown = function() {
7221
7282
  return this._overlayRoot.style.display !== 'none';
7222
7283
  };
7223
7284
 
7285
+ /**
7286
+ * Show all overlays.
7287
+ */
7224
7288
  Overlays.prototype.show = function() {
7225
7289
  setVisible(this._overlayRoot);
7226
7290
  };
7227
7291
 
7228
-
7292
+ /**
7293
+ * Hide all overlays.
7294
+ */
7229
7295
  Overlays.prototype.hide = function() {
7230
7296
  setVisible(this._overlayRoot, false);
7231
7297
  };
7232
7298
 
7299
+ /**
7300
+ * Remove all overlays and their container.
7301
+ */
7233
7302
  Overlays.prototype.clear = function() {
7234
7303
  this._overlays = {};
7235
7304
 
@@ -7605,6 +7674,13 @@
7605
7674
  overlays: [ 'type', Overlays ]
7606
7675
  };
7607
7676
 
7677
+ /**
7678
+ * @typedef {import('../../core/Canvas').default} Canvas
7679
+ * @typedef {import('../../core/ElementRegistry').default} ElementRegistry
7680
+ * @typedef {import('../../core/EventBus').default} EventBus
7681
+ * @typedef {import('../../core/GraphicsFactory').default} GraphicsFactory
7682
+ */
7683
+
7608
7684
  /**
7609
7685
  * Adds change support to the diagram, including
7610
7686
  *
@@ -7674,32 +7750,41 @@
7674
7750
  changeSupport: [ 'type', ChangeSupport ]
7675
7751
  };
7676
7752
 
7753
+ /**
7754
+ * @typedef {import('../core/EventBus').default} EventBus
7755
+ * @typedef {import(./CommandInterceptor).HandlerFunction} HandlerFunction
7756
+ * @typedef {import(./CommandInterceptor).ComposeHandlerFunction} ComposeHandlerFunction
7757
+ */
7758
+
7677
7759
  var DEFAULT_PRIORITY$1 = 1000;
7678
7760
 
7679
7761
  /**
7680
- * A utility that can be used to plug-in into the command execution for
7762
+ * A utility that can be used to plug into the command execution for
7681
7763
  * extension and/or validation.
7682
7764
  *
7765
+ * @class
7766
+ * @constructor
7767
+ *
7683
7768
  * @param {EventBus} eventBus
7684
7769
  *
7685
7770
  * @example
7686
7771
  *
7687
- * import inherits from 'inherits-browser';
7688
- *
7689
7772
  * import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
7690
7773
  *
7691
- * function CommandLogger(eventBus) {
7692
- * CommandInterceptor.call(this, eventBus);
7774
+ * class CommandLogger extends CommandInterceptor {
7775
+ * constructor(eventBus) {
7776
+ * super(eventBus);
7693
7777
  *
7694
- * this.preExecute(function(event) {
7695
- * console.log('command pre-execute', event);
7778
+ * this.preExecute('shape.create', (event) => {
7779
+ * console.log('commandStack.shape-create.preExecute', event);
7696
7780
  * });
7697
7781
  * }
7698
- *
7699
- * inherits(CommandLogger, CommandInterceptor);
7700
- *
7701
7782
  */
7702
7783
  function CommandInterceptor(eventBus) {
7784
+
7785
+ /**
7786
+ * @type {EventBus}
7787
+ */
7703
7788
  this._eventBus = eventBus;
7704
7789
  }
7705
7790
 
@@ -7712,16 +7797,15 @@
7712
7797
  }
7713
7798
 
7714
7799
  /**
7715
- * Register an interceptor for a command execution
7716
- *
7717
- * @param {string|Array<string>} [events] list of commands to register on
7718
- * @param {string} [hook] command hook, i.e. preExecute, executed to listen on
7719
- * @param {number} [priority] the priority on which to hook into the execution
7720
- * @param {Function} handlerFn interceptor to be invoked with (event)
7721
- * @param {boolean} unwrap if true, unwrap the event and pass (context, command, event) to the
7722
- * listener instead
7723
- * @param {Object} [that] Pass context (`this`) to the handler function
7724
- */
7800
+ * Intercept a command during one of the phases.
7801
+ *
7802
+ * @param {string|string[]} [events] One or more commands to intercept.
7803
+ * @param {string} [hook] Phase during which to intercept command.
7804
+ * @param {number} [priority] Priority with which command will be intercepted.
7805
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn Callback.
7806
+ * @param {boolean} [unwrap] Whether the event should be unwrapped.
7807
+ * @param {*} [that] `this` value the callback will be called with.
7808
+ */
7725
7809
  CommandInterceptor.prototype.on = function(events, hook, priority, handlerFn, unwrap, that) {
7726
7810
 
7727
7811
  if (isFunction(hook) || isNumber(hook)) {
@@ -7777,24 +7861,19 @@
7777
7861
  ];
7778
7862
 
7779
7863
  /*
7780
- * Install hook shortcuts
7781
- *
7782
- * This will generate the CommandInterceptor#(preExecute|...|reverted) methods
7783
- * which will in term forward to CommandInterceptor#on.
7864
+ * Add prototype methods for each phase of command execution (e.g. execute,
7865
+ * revert).
7784
7866
  */
7785
7867
  forEach$1(hooks, function(hook) {
7786
7868
 
7787
7869
  /**
7788
- * {canExecute|preExecute|preExecuted|execute|executed|postExecute|postExecuted|revert|reverted}
7870
+ * Add prototype method for a specific phase of command execution.
7789
7871
  *
7790
- * A named hook for plugging into the command execution
7791
- *
7792
- * @param {string|Array<string>} [events] list of commands to register on
7793
- * @param {number} [priority] the priority on which to hook into the execution
7794
- * @param {Function} handlerFn interceptor to be invoked with (event)
7795
- * @param {boolean} [unwrap=false] if true, unwrap the event and pass (context, command, event) to the
7796
- * listener instead
7797
- * @param {Object} [that] Pass context (`this`) to the handler function
7872
+ * @param {string|string[]} [events] One or more commands to intercept.
7873
+ * @param {number} [priority] Priority with which command will be intercepted.
7874
+ * @param {ComposeHandlerFunction|HandlerFunction} handlerFn Callback.
7875
+ * @param {boolean} [unwrap] Whether the event should be unwrapped.
7876
+ * @param {*} [that] `this` value the callback will be called with.
7798
7877
  */
7799
7878
  CommandInterceptor.prototype[hook] = function(events, priority, handlerFn, unwrap, that) {
7800
7879
 
@@ -7810,12 +7889,18 @@
7810
7889
  };
7811
7890
  });
7812
7891
 
7892
+ /**
7893
+ * @typedef {import('didi').Injector} Injector
7894
+ *
7895
+ * @typedef {import('../../core/Canvas').default} Canvas
7896
+ */
7897
+
7813
7898
  /**
7814
7899
  * A modeling behavior that ensures we set the correct root element
7815
7900
  * as we undo and redo commands.
7816
7901
  *
7817
7902
  * @param {Canvas} canvas
7818
- * @param {didi.Injector} injector
7903
+ * @param {Injector} injector
7819
7904
  */
7820
7905
  function RootElementsBehavior(canvas, injector) {
7821
7906
 
@@ -7849,111 +7934,10 @@
7849
7934
  rootElementsBehavior: [ 'type', RootElementsBehavior ]
7850
7935
  };
7851
7936
 
7852
- var css_escape = {exports: {}};
7853
-
7854
- /*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
7855
-
7856
- (function (module, exports) {
7857
- (function(root, factory) {
7858
- // https://github.com/umdjs/umd/blob/master/returnExports.js
7859
- {
7860
- // For Node.js.
7861
- module.exports = factory(root);
7862
- }
7863
- }(typeof commonjsGlobal != 'undefined' ? commonjsGlobal : commonjsGlobal, function(root) {
7864
-
7865
- if (root.CSS && root.CSS.escape) {
7866
- return root.CSS.escape;
7867
- }
7868
-
7869
- // https://drafts.csswg.org/cssom/#serialize-an-identifier
7870
- var cssEscape = function(value) {
7871
- if (arguments.length == 0) {
7872
- throw new TypeError('`CSS.escape` requires an argument.');
7873
- }
7874
- var string = String(value);
7875
- var length = string.length;
7876
- var index = -1;
7877
- var codeUnit;
7878
- var result = '';
7879
- var firstCodeUnit = string.charCodeAt(0);
7880
- while (++index < length) {
7881
- codeUnit = string.charCodeAt(index);
7882
- // Note: there’s no need to special-case astral symbols, surrogate
7883
- // pairs, or lone surrogates.
7884
-
7885
- // If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
7886
- // (U+FFFD).
7887
- if (codeUnit == 0x0000) {
7888
- result += '\uFFFD';
7889
- continue;
7890
- }
7891
-
7892
- if (
7893
- // If the character is in the range [\1-\1F] (U+0001 to U+001F) or is
7894
- // U+007F, […]
7895
- (codeUnit >= 0x0001 && codeUnit <= 0x001F) || codeUnit == 0x007F ||
7896
- // If the character is the first character and is in the range [0-9]
7897
- // (U+0030 to U+0039), […]
7898
- (index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
7899
- // If the character is the second character and is in the range [0-9]
7900
- // (U+0030 to U+0039) and the first character is a `-` (U+002D), […]
7901
- (
7902
- index == 1 &&
7903
- codeUnit >= 0x0030 && codeUnit <= 0x0039 &&
7904
- firstCodeUnit == 0x002D
7905
- )
7906
- ) {
7907
- // https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
7908
- result += '\\' + codeUnit.toString(16) + ' ';
7909
- continue;
7910
- }
7911
-
7912
- if (
7913
- // If the character is the first character and is a `-` (U+002D), and
7914
- // there is no second character, […]
7915
- index == 0 &&
7916
- length == 1 &&
7917
- codeUnit == 0x002D
7918
- ) {
7919
- result += '\\' + string.charAt(index);
7920
- continue;
7921
- }
7922
-
7923
- // If the character is not handled by one of the above rules and is
7924
- // greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
7925
- // is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
7926
- // U+005A), or [a-z] (U+0061 to U+007A), […]
7927
- if (
7928
- codeUnit >= 0x0080 ||
7929
- codeUnit == 0x002D ||
7930
- codeUnit == 0x005F ||
7931
- codeUnit >= 0x0030 && codeUnit <= 0x0039 ||
7932
- codeUnit >= 0x0041 && codeUnit <= 0x005A ||
7933
- codeUnit >= 0x0061 && codeUnit <= 0x007A
7934
- ) {
7935
- // the character itself
7936
- result += string.charAt(index);
7937
- continue;
7938
- }
7939
-
7940
- // Otherwise, the escaped character.
7941
- // https://drafts.csswg.org/cssom/#escape-a-character
7942
- result += '\\' + string.charAt(index);
7943
-
7944
- }
7945
- return result;
7946
- };
7947
-
7948
- if (!root.CSS) {
7949
- root.CSS = {};
7950
- }
7951
-
7952
- root.CSS.escape = cssEscape;
7953
- return cssEscape;
7954
-
7955
- }));
7956
- } (css_escape));
7937
+ /**
7938
+ * @param {string} str
7939
+ * @returns {string}
7940
+ */
7957
7941
 
7958
7942
  var HTML_ESCAPE_MAP = {
7959
7943
  '&': '&amp;',
@@ -9088,6 +9072,11 @@
9088
9072
  return value;
9089
9073
  }
9090
9074
 
9075
+ /**
9076
+ * @typedef {import('../core/EventBus').default} EventBus
9077
+ * @typedef {import('./Styles').default} Styles
9078
+ */
9079
+
9091
9080
  // apply default renderer with lowest possible priority
9092
9081
  // so that it only kicks in if noone else could render
9093
9082
  var DEFAULT_RENDER_PRIORITY = 1;
@@ -9205,9 +9194,9 @@
9205
9194
  /**
9206
9195
  * Builds a style definition from a className, a list of traits and an object of additional attributes.
9207
9196
  *
9208
- * @param {string} className
9209
- * @param {Array<string>} traits
9210
- * @param {Object} additionalAttrs
9197
+ * @param {string} className
9198
+ * @param {Array<string>} traits
9199
+ * @param {Object} additionalAttrs
9211
9200
  *
9212
9201
  * @return {Object} the style defintion
9213
9202
  */
@@ -9220,8 +9209,8 @@
9220
9209
  /**
9221
9210
  * Builds a style definition from a list of traits and an object of additional attributes.
9222
9211
  *
9223
- * @param {Array<string>} traits
9224
- * @param {Object} additionalAttrs
9212
+ * @param {Array<string>} traits
9213
+ * @param {Object} additionalAttrs
9225
9214
  *
9226
9215
  * @return {Object} the style defintion
9227
9216
  */
@@ -9258,8 +9247,8 @@
9258
9247
  /**
9259
9248
  * Failsafe remove an element from a collection
9260
9249
  *
9261
- * @param {Array<Object>} [collection]
9262
- * @param {Object} [element]
9250
+ * @param {Array<Object>} [collection]
9251
+ * @param {Object} [element]
9263
9252
  *
9264
9253
  * @return {number} the previous index of the element
9265
9254
  */
@@ -9329,6 +9318,27 @@
9329
9318
  }
9330
9319
  }
9331
9320
 
9321
+ /**
9322
+ * @typedef {import('.').ConnectionLike} ConnectionLike
9323
+ * @typedef {import('.').RootLike} RootLike
9324
+ * @typedef {import('.').ShapeLike} ShapeLike
9325
+ *
9326
+ * @typedef {import('./Canvas').CanvasConfig} CanvasConfig
9327
+ * @typedef {import('./Canvas').CanvasLayer} CanvasLayer
9328
+ * @typedef {import('./Canvas').CanvasLayers} CanvasLayers
9329
+ * @typedef {import('./Canvas').CanvasPlane} CanvasPlane
9330
+ * @typedef {import('./Canvas').CanvasViewbox} CanvasViewbox
9331
+ *
9332
+ * @typedef {import('./ElementRegistry').default} ElementRegistry
9333
+ * @typedef {import('./EventBus').default} EventBus
9334
+ * @typedef {import('./GraphicsFactory').default} GraphicsFactory
9335
+ *
9336
+ * @typedef {import('../util/Types').Dimensions} Dimensions
9337
+ * @typedef {import('../util/Types').Point} Point
9338
+ * @typedef {import('../util/Types').Rect} Rect
9339
+ * @typedef {import('../util/Types').RectTRBL} RectTRBL
9340
+ */
9341
+
9332
9342
  function round(number, resolution) {
9333
9343
  return Math.round(number * resolution) / resolution;
9334
9344
  }
@@ -9349,7 +9359,8 @@
9349
9359
  * Creates a HTML container element for a SVG element with
9350
9360
  * the given configuration
9351
9361
  *
9352
- * @param {Object} options
9362
+ * @param {CanvasConfig} options
9363
+ *
9353
9364
  * @return {HTMLElement} the container element
9354
9365
  */
9355
9366
  function createContainer(options) {
@@ -9409,21 +9420,34 @@
9409
9420
  *
9410
9421
  * @emits Canvas#canvas.init
9411
9422
  *
9412
- * @param {Object} config
9423
+ * @param {CanvasConfig|null} config
9413
9424
  * @param {EventBus} eventBus
9414
9425
  * @param {GraphicsFactory} graphicsFactory
9415
9426
  * @param {ElementRegistry} elementRegistry
9416
9427
  */
9417
9428
  function Canvas(config, eventBus, graphicsFactory, elementRegistry) {
9418
-
9419
9429
  this._eventBus = eventBus;
9420
9430
  this._elementRegistry = elementRegistry;
9421
9431
  this._graphicsFactory = graphicsFactory;
9422
9432
 
9433
+ /**
9434
+ * @type {number}
9435
+ */
9423
9436
  this._rootsIdx = 0;
9424
9437
 
9438
+ /**
9439
+ * @type {CanvasLayers}
9440
+ */
9425
9441
  this._layers = {};
9442
+
9443
+ /**
9444
+ * @type {CanvasPlane[]}
9445
+ */
9426
9446
  this._planes = [];
9447
+
9448
+ /**
9449
+ * @type {RootLike|null}
9450
+ */
9427
9451
  this._rootElement = null;
9428
9452
 
9429
9453
  this._init(config || {});
@@ -9448,6 +9472,8 @@
9448
9472
  * ...
9449
9473
  * </svg>
9450
9474
  * </div>
9475
+ *
9476
+ * @param {CanvasConfig} config
9451
9477
  */
9452
9478
  Canvas.prototype._init = function(config) {
9453
9479
 
@@ -9469,7 +9495,7 @@
9469
9495
  this._viewboxChanged = debounce(bind$2(this._viewboxChanged, this), 300);
9470
9496
  }
9471
9497
 
9472
- eventBus.on('diagram.init', function() {
9498
+ eventBus.on('diagram.init', () => {
9473
9499
 
9474
9500
  /**
9475
9501
  * An event indicating that the canvas is ready to be drawn on.
@@ -9487,7 +9513,7 @@
9487
9513
  viewport: viewport
9488
9514
  });
9489
9515
 
9490
- }, this);
9516
+ });
9491
9517
 
9492
9518
  // reset viewbox on shape changes to
9493
9519
  // recompute the viewbox
@@ -9498,15 +9524,15 @@
9498
9524
  'connection.removed',
9499
9525
  'elements.changed',
9500
9526
  'root.set'
9501
- ], function() {
9527
+ ], () => {
9502
9528
  delete this._cachedViewbox;
9503
- }, this);
9529
+ });
9504
9530
 
9505
9531
  eventBus.on('diagram.destroy', 500, this._destroy, this);
9506
9532
  eventBus.on('diagram.clear', 500, this._clear, this);
9507
9533
  };
9508
9534
 
9509
- Canvas.prototype._destroy = function(emit) {
9535
+ Canvas.prototype._destroy = function() {
9510
9536
  this._eventBus.fire('canvas.destroy', {
9511
9537
  svg: this._svg,
9512
9538
  viewport: this._viewport
@@ -9553,7 +9579,7 @@
9553
9579
  * Returns the default layer on which
9554
9580
  * all elements are drawn.
9555
9581
  *
9556
- * @returns {SVGElement}
9582
+ * @return {SVGElement} The SVG element of the layer.
9557
9583
  */
9558
9584
  Canvas.prototype.getDefaultLayer = function() {
9559
9585
  return this.getLayer(BASE_LAYER, PLANE_LAYER_INDEX);
@@ -9569,10 +9595,10 @@
9569
9595
  * A layer with a certain index is always created above all
9570
9596
  * existing layers with the same index.
9571
9597
  *
9572
- * @param {string} name
9573
- * @param {number} index
9598
+ * @param {string} name The name of the layer.
9599
+ * @param {number} [index] The index of the layer.
9574
9600
  *
9575
- * @returns {SVGElement}
9601
+ * @return {SVGElement} The SVG element of the layer.
9576
9602
  */
9577
9603
  Canvas.prototype.getLayer = function(name, index) {
9578
9604
 
@@ -9601,8 +9627,9 @@
9601
9627
  *
9602
9628
  * This is used to determine the node a layer should be inserted at.
9603
9629
  *
9604
- * @param {Number} index
9605
- * @returns {Number}
9630
+ * @param {number} index
9631
+ *
9632
+ * @return {number}
9606
9633
  */
9607
9634
  Canvas.prototype._getChildIndex = function(index) {
9608
9635
  return reduce(this._layers, function(childIndex, layer) {
@@ -9620,7 +9647,7 @@
9620
9647
  * @param {string} name
9621
9648
  * @param {number} [index=0]
9622
9649
  *
9623
- * @return {Object} layer descriptor with { index, group: SVGGroup }
9650
+ * @return {CanvasLayer}
9624
9651
  */
9625
9652
  Canvas.prototype._createLayer = function(name, index) {
9626
9653
 
@@ -9641,8 +9668,9 @@
9641
9668
  /**
9642
9669
  * Shows a given layer.
9643
9670
  *
9644
- * @param {String} layer
9645
- * @returns {SVGElement}
9671
+ * @param {string} layer The name of the layer.
9672
+ *
9673
+ * @return {SVGElement} The SVG element of the layer.
9646
9674
  */
9647
9675
  Canvas.prototype.showLayer = function(name) {
9648
9676
 
@@ -9676,8 +9704,9 @@
9676
9704
  /**
9677
9705
  * Hides a given layer.
9678
9706
  *
9679
- * @param {String} layer
9680
- * @returns {SVGElement}
9707
+ * @param {string} layer The name of the layer.
9708
+ *
9709
+ * @return {SVGElement} The SVG element of the layer.
9681
9710
  */
9682
9711
  Canvas.prototype.hideLayer = function(name) {
9683
9712
 
@@ -9719,7 +9748,7 @@
9719
9748
  /**
9720
9749
  * Returns the currently active layer. Can be null.
9721
9750
  *
9722
- * @returns {SVGElement|null}
9751
+ * @return {CanvasLayer|null} The active layer of `null`.
9723
9752
  */
9724
9753
  Canvas.prototype.getActiveLayer = function() {
9725
9754
  const plane = this._findPlaneForRoot(this.getRootElement());
@@ -9735,9 +9764,9 @@
9735
9764
  /**
9736
9765
  * Returns the plane which contains the given element.
9737
9766
  *
9738
- * @param {string|djs.model.Base} element
9767
+ * @param {ShapeLike|ConnectionLike|string} element The element or its ID.
9739
9768
  *
9740
- * @return {djs.model.Base} root for element
9769
+ * @return {RootLike|undefined} The root of the element.
9741
9770
  */
9742
9771
  Canvas.prototype.findRoot = function(element) {
9743
9772
  if (typeof element === 'string') {
@@ -9758,7 +9787,7 @@
9758
9787
  /**
9759
9788
  * Return a list of all root elements on the diagram.
9760
9789
  *
9761
- * @return {djs.model.Root[]}
9790
+ * @return {(RootLike)[]} The list of root elements.
9762
9791
  */
9763
9792
  Canvas.prototype.getRootElements = function() {
9764
9793
  return this._planes.map(function(plane) {
@@ -9777,7 +9806,7 @@
9777
9806
  * Returns the html element that encloses the
9778
9807
  * drawing canvas.
9779
9808
  *
9780
- * @return {DOMNode}
9809
+ * @return {HTMLElement} The HTML element of the container.
9781
9810
  */
9782
9811
  Canvas.prototype.getContainer = function() {
9783
9812
  return this._container;
@@ -9817,8 +9846,8 @@
9817
9846
  *
9818
9847
  * @event element.marker.update
9819
9848
  * @type {Object}
9820
- * @property {djs.model.Element} element the shape
9821
- * @property {Object} gfx the graphical representation of the shape
9849
+ * @property {Base} element the shape
9850
+ * @property {SVGElement} gfx the graphical representation of the shape
9822
9851
  * @property {string} marker
9823
9852
  * @property {boolean} add true if the marker was added, false if it got removed
9824
9853
  */
@@ -9833,14 +9862,15 @@
9833
9862
  * integrate extension into the marker life-cycle, too.
9834
9863
  *
9835
9864
  * @example
9865
+ *
9836
9866
  * canvas.addMarker('foo', 'some-marker');
9837
9867
  *
9838
9868
  * const fooGfx = canvas.getGraphics('foo');
9839
9869
  *
9840
9870
  * fooGfx; // <g class="... some-marker"> ... </g>
9841
9871
  *
9842
- * @param {string|djs.model.Base} element
9843
- * @param {string} marker
9872
+ * @param {ShapeLike|ConnectionLike|string} element The element or its ID.
9873
+ * @param {string} marker The marker.
9844
9874
  */
9845
9875
  Canvas.prototype.addMarker = function(element, marker) {
9846
9876
  this._updateMarker(element, marker, true);
@@ -9853,18 +9883,18 @@
9853
9883
  * Fires the element.marker.update event, making it possible to
9854
9884
  * integrate extension into the marker life-cycle, too.
9855
9885
  *
9856
- * @param {string|djs.model.Base} element
9857
- * @param {string} marker
9886
+ * @param {ShapeLike|ConnectionLike|string} element The element or its ID.
9887
+ * @param {string} marker The marker.
9858
9888
  */
9859
9889
  Canvas.prototype.removeMarker = function(element, marker) {
9860
9890
  this._updateMarker(element, marker, false);
9861
9891
  };
9862
9892
 
9863
9893
  /**
9864
- * Check the existence of a marker on element.
9894
+ * Check whether an element has a given marker.
9865
9895
  *
9866
- * @param {string|djs.model.Base} element
9867
- * @param {string} marker
9896
+ * @param {ShapeLike|ConnectionLike|string} element The element or its ID.
9897
+ * @param {string} marker The marker.
9868
9898
  */
9869
9899
  Canvas.prototype.hasMarker = function(element, marker) {
9870
9900
  if (!element.id) {
@@ -9882,8 +9912,8 @@
9882
9912
  * Fires the element.marker.update event, making it possible to
9883
9913
  * integrate extension into the marker life-cycle, too.
9884
9914
  *
9885
- * @param {string|djs.model.Base} element
9886
- * @param {string} marker
9915
+ * @param {ShapeLike|ConnectionLike|string} element The element or its ID.
9916
+ * @param {string} marker The marker.
9887
9917
  */
9888
9918
  Canvas.prototype.toggleMarker = function(element, marker) {
9889
9919
  if (this.hasMarker(element, marker)) {
@@ -9906,7 +9936,7 @@
9906
9936
  * root elements can be null. This is used for applications that want to manage
9907
9937
  * root elements themselves.
9908
9938
  *
9909
- * @returns {Object|djs.model.Root|null} rootElement.
9939
+ * @return {RootLike} The current root element.
9910
9940
  */
9911
9941
  Canvas.prototype.getRootElement = function() {
9912
9942
  const rootElement = this._rootElement;
@@ -9922,11 +9952,10 @@
9922
9952
  /**
9923
9953
  * Adds a given root element and returns it.
9924
9954
  *
9925
- * @param {Object|djs.model.Root} rootElement
9955
+ * @param {ShapeLike} [rootElement] The root element to be added.
9926
9956
  *
9927
- * @return {Object|djs.model.Root} rootElement
9957
+ * @return {RootLike} The added root element or an implicit root element.
9928
9958
  */
9929
-
9930
9959
  Canvas.prototype.addRootElement = function(rootElement) {
9931
9960
  const idx = this._rootsIdx++;
9932
9961
 
@@ -9957,11 +9986,11 @@
9957
9986
  };
9958
9987
 
9959
9988
  /**
9960
- * Removes a given rootElement and returns it.
9989
+ * Removes a given root element and returns it.
9961
9990
  *
9962
- * @param {djs.model.Root|String} rootElement
9991
+ * @param {ShapeLike|string} rootElement The root element or its ID.
9963
9992
  *
9964
- * @return {Object|djs.model.Root} rootElement
9993
+ * @return {ShapeLike|undefined} The removed root element.
9965
9994
  */
9966
9995
  Canvas.prototype.removeRootElement = function(rootElement) {
9967
9996
 
@@ -9995,15 +10024,13 @@
9995
10024
  };
9996
10025
 
9997
10026
 
9998
- // root element handling //////////////////////
9999
-
10000
10027
  /**
10001
10028
  * Sets a given element as the new root element for the canvas
10002
10029
  * and returns the new root element.
10003
10030
  *
10004
- * @param {Object|djs.model.Root} rootElement
10031
+ * @param {RootLike} rootElement The root element to be set.
10005
10032
  *
10006
- * @return {Object|djs.model.Root} new root element
10033
+ * @return {RootLike} The set root element.
10007
10034
  */
10008
10035
  Canvas.prototype.setRootElement = function(rootElement, override) {
10009
10036
 
@@ -10090,8 +10117,6 @@
10090
10117
  this._eventBus.fire('root.set', { element: rootElement });
10091
10118
  };
10092
10119
 
10093
- // add functionality //////////////////////
10094
-
10095
10120
  Canvas.prototype._ensureValid = function(type, element) {
10096
10121
  if (!element.id) {
10097
10122
  throw new Error('element must have an id');
@@ -10132,11 +10157,11 @@
10132
10157
  * Extensions may hook into these events to perform their magic.
10133
10158
  *
10134
10159
  * @param {string} type
10135
- * @param {Object|djs.model.Base} element
10136
- * @param {Object|djs.model.Base} [parent]
10160
+ * @param {ConnectionLike|ShapeLike} element
10161
+ * @param {ShapeLike} [parent]
10137
10162
  * @param {number} [parentIndex]
10138
10163
  *
10139
- * @return {Object|djs.model.Base} the added element
10164
+ * @return {ConnectionLike|ShapeLike} The added element.
10140
10165
  */
10141
10166
  Canvas.prototype._addElement = function(type, element, parent, parentIndex) {
10142
10167
 
@@ -10165,26 +10190,26 @@
10165
10190
  };
10166
10191
 
10167
10192
  /**
10168
- * Adds a shape to the canvas
10193
+ * Adds a shape to the canvas.
10169
10194
  *
10170
- * @param {Object|djs.model.Shape} shape to add to the diagram
10171
- * @param {djs.model.Base} [parent]
10172
- * @param {number} [parentIndex]
10195
+ * @param {ShapeLike} shape The shape to be added
10196
+ * @param {ShapeLike} [parent] The shape's parent.
10197
+ * @param {number} [parentIndex] The index at which to add the shape to the parent's children.
10173
10198
  *
10174
- * @return {djs.model.Shape} the added shape
10199
+ * @return {ShapeLike} The added shape.
10175
10200
  */
10176
10201
  Canvas.prototype.addShape = function(shape, parent, parentIndex) {
10177
10202
  return this._addElement('shape', shape, parent, parentIndex);
10178
10203
  };
10179
10204
 
10180
10205
  /**
10181
- * Adds a connection to the canvas
10206
+ * Adds a connection to the canvas.
10182
10207
  *
10183
- * @param {Object|djs.model.Connection} connection to add to the diagram
10184
- * @param {djs.model.Base} [parent]
10185
- * @param {number} [parentIndex]
10208
+ * @param {ConnectionLike} connection The connection to be added.
10209
+ * @param {ShapeLike} [parent] The connection's parent.
10210
+ * @param {number} [parentIndex] The index at which to add the connection to the parent's children.
10186
10211
  *
10187
- * @return {djs.model.Connection} the added connection
10212
+ * @return {ConnectionLike} The added connection.
10188
10213
  */
10189
10214
  Canvas.prototype.addConnection = function(connection, parent, parentIndex) {
10190
10215
  return this._addElement('connection', connection, parent, parentIndex);
@@ -10225,11 +10250,14 @@
10225
10250
 
10226
10251
 
10227
10252
  /**
10228
- * Removes a shape from the canvas
10253
+ * Removes a shape from the canvas.
10254
+ *
10255
+ * @fires ShapeRemoveEvent
10256
+ * @fires ShapeRemovedEvent
10229
10257
  *
10230
- * @param {string|djs.model.Shape} shape or shape id to be removed
10258
+ * @param {ShapeLike|string} shape The shape or its ID.
10231
10259
  *
10232
- * @return {djs.model.Shape} the removed shape
10260
+ * @return {ShapeLike} The removed shape.
10233
10261
  */
10234
10262
  Canvas.prototype.removeShape = function(shape) {
10235
10263
 
@@ -10238,10 +10266,10 @@
10238
10266
  *
10239
10267
  * @memberOf Canvas
10240
10268
  *
10241
- * @event shape.remove
10269
+ * @event ShapeRemoveEvent
10242
10270
  * @type {Object}
10243
- * @property {djs.model.Shape} element the shape descriptor
10244
- * @property {Object} gfx the graphical representation of the shape
10271
+ * @property {ShapeLike} element The shape.
10272
+ * @property {SVGElement} gfx The graphical element.
10245
10273
  */
10246
10274
 
10247
10275
  /**
@@ -10249,21 +10277,24 @@
10249
10277
  *
10250
10278
  * @memberOf Canvas
10251
10279
  *
10252
- * @event shape.removed
10280
+ * @event ShapeRemoved
10253
10281
  * @type {Object}
10254
- * @property {djs.model.Shape} element the shape descriptor
10255
- * @property {Object} gfx the graphical representation of the shape
10282
+ * @property {ShapeLike} element The shape.
10283
+ * @property {SVGElement} gfx The graphical element.
10256
10284
  */
10257
10285
  return this._removeElement(shape, 'shape');
10258
10286
  };
10259
10287
 
10260
10288
 
10261
10289
  /**
10262
- * Removes a connection from the canvas
10290
+ * Removes a connection from the canvas.
10263
10291
  *
10264
- * @param {string|djs.model.Connection} connection or connection id to be removed
10292
+ * @fires ConnectionRemoveEvent
10293
+ * @fires ConnectionRemovedEvent
10265
10294
  *
10266
- * @return {djs.model.Connection} the removed connection
10295
+ * @param {ConnectionLike|string} connection The connection or its ID.
10296
+ *
10297
+ * @return {ConnectionLike} The removed connection.
10267
10298
  */
10268
10299
  Canvas.prototype.removeConnection = function(connection) {
10269
10300
 
@@ -10272,10 +10303,10 @@
10272
10303
  *
10273
10304
  * @memberOf Canvas
10274
10305
  *
10275
- * @event connection.remove
10306
+ * @event ConnectionRemoveEvent
10276
10307
  * @type {Object}
10277
- * @property {djs.model.Connection} element the connection descriptor
10278
- * @property {Object} gfx the graphical representation of the connection
10308
+ * @property {ConnectionLike} element The connection.
10309
+ * @property {SVGElement} gfx The graphical element.
10279
10310
  */
10280
10311
 
10281
10312
  /**
@@ -10285,20 +10316,20 @@
10285
10316
  *
10286
10317
  * @event connection.removed
10287
10318
  * @type {Object}
10288
- * @property {djs.model.Connection} element the connection descriptor
10289
- * @property {Object} gfx the graphical representation of the connection
10319
+ * @property {ConnectionLike} element The connection.
10320
+ * @property {SVGElement} gfx The graphical element.
10290
10321
  */
10291
10322
  return this._removeElement(connection, 'connection');
10292
10323
  };
10293
10324
 
10294
10325
 
10295
10326
  /**
10296
- * Return the graphical object underlaying a certain diagram element
10327
+ * Returns the graphical element of an element.
10297
10328
  *
10298
- * @param {string|djs.model.Base} element descriptor of the element
10299
- * @param {boolean} [secondary=false] whether to return the secondary connected element
10329
+ * @param {ShapeLike|ConnectionLike|string} element The element or its ID.
10330
+ * @param {boolean} [secondary=false] Whether to return the secondary graphical element.
10300
10331
  *
10301
- * @return {SVGElement}
10332
+ * @return {SVGElement} The graphical element.
10302
10333
  */
10303
10334
  Canvas.prototype.getGraphics = function(element, secondary) {
10304
10335
  return this._elementRegistry.getGraphics(element, secondary);
@@ -10370,13 +10401,9 @@
10370
10401
  * height: zoomedAndScrolledViewbox.outer.height
10371
10402
  * });
10372
10403
  *
10373
- * @param {Object} [box] the new view box to set
10374
- * @param {number} box.x the top left X coordinate of the canvas visible in view box
10375
- * @param {number} box.y the top left Y coordinate of the canvas visible in view box
10376
- * @param {number} box.width the visible width
10377
- * @param {number} box.height
10404
+ * @param {Rect} [box] The viewbox to be set.
10378
10405
  *
10379
- * @return {Object} the current view box
10406
+ * @return {CanvasViewbox} The set viewbox.
10380
10407
  */
10381
10408
  Canvas.prototype.viewbox = function(box) {
10382
10409
 
@@ -10445,10 +10472,9 @@
10445
10472
  /**
10446
10473
  * Gets or sets the scroll of the canvas.
10447
10474
  *
10448
- * @param {Object} [delta] the new scroll to apply.
10475
+ * @param {Point} [delta] The scroll to be set.
10449
10476
  *
10450
- * @param {number} [delta.dx]
10451
- * @param {number} [delta.dy]
10477
+ * @return {Point}
10452
10478
  */
10453
10479
  Canvas.prototype.scroll = function(delta) {
10454
10480
 
@@ -10472,9 +10498,8 @@
10472
10498
  * Scrolls the viewbox to contain the given element.
10473
10499
  * Optionally specify a padding to be applied to the edges.
10474
10500
  *
10475
- * @param {Object|String} [element] the element to scroll to.
10476
- * @param {Object|Number} [padding=100] the padding to be applied. Can also specify top, bottom, left and right.
10477
- *
10501
+ * @param {ShapeLike|ConnectionLike|string} element The element to scroll to or its ID.
10502
+ * @param {RectTRBL|number} [padding=100] The padding to be applied. Can also specify top, bottom, left and right.
10478
10503
  */
10479
10504
  Canvas.prototype.scrollToElement = function(element, padding) {
10480
10505
  let defaultPadding = 100;
@@ -10542,17 +10567,17 @@
10542
10567
  };
10543
10568
 
10544
10569
  /**
10545
- * Gets or sets the current zoom of the canvas, optionally zooming
10546
- * to the specified position.
10570
+ * Gets or sets the current zoom of the canvas, optionally zooming to the
10571
+ * specified position.
10547
10572
  *
10548
- * The getter may return a cached zoom level. Call it with `false` as
10549
- * the first argument to force recomputation of the current level.
10573
+ * The getter may return a cached zoom level. Call it with `false` as the first
10574
+ * argument to force recomputation of the current level.
10550
10575
  *
10551
- * @param {string|number} [newScale] the new zoom level, either a number, i.e. 0.9,
10552
- * or `fit-viewport` to adjust the size to fit the current viewport
10553
- * @param {string|Point} [center] the reference point { x: .., y: ..} to zoom to, 'auto' to zoom into mid or null
10576
+ * @param {number|string} [newScale] The new zoom level, either a number,
10577
+ * i.e. 0.9, or `fit-viewport` to adjust the size to fit the current viewport.
10578
+ * @param {Point} [center] The reference point { x: ..., y: ...} to zoom to.
10554
10579
  *
10555
- * @return {number} the current scale
10580
+ * @return {number} The set zoom level.
10556
10581
  */
10557
10582
  Canvas.prototype.zoom = function(newScale, center) {
10558
10583
 
@@ -10675,9 +10700,9 @@
10675
10700
 
10676
10701
 
10677
10702
  /**
10678
- * Returns the size of the canvas
10703
+ * Returns the size of the canvas.
10679
10704
  *
10680
- * @return {Dimensions}
10705
+ * @return {Dimensions} The size of the canvas.
10681
10706
  */
10682
10707
  Canvas.prototype.getSize = function() {
10683
10708
  return {
@@ -10688,14 +10713,14 @@
10688
10713
 
10689
10714
 
10690
10715
  /**
10691
- * Return the absolute bounding box for the given element
10716
+ * Returns the absolute bounding box of an element.
10717
+ *
10718
+ * The absolute bounding box may be used to display overlays in the callers
10719
+ * (browser) coordinate system rather than the zoomed in/out canvas coordinates.
10692
10720
  *
10693
- * The absolute bounding box may be used to display overlays in the
10694
- * callers (browser) coordinate system rather than the zoomed in/out
10695
- * canvas coordinates.
10721
+ * @param {ShapeLike|ConnectionLike} element The element.
10696
10722
  *
10697
- * @param {ElementDescriptor} element
10698
- * @return {Bounds} the absolute bounding box
10723
+ * @return {Rect} The element's absolute bounding box.
10699
10724
  */
10700
10725
  Canvas.prototype.getAbsoluteBBox = function(element) {
10701
10726
  const vbox = this.viewbox();
@@ -10730,8 +10755,7 @@
10730
10755
  };
10731
10756
 
10732
10757
  /**
10733
- * Fires an event in order other modules can react to the
10734
- * canvas resizing
10758
+ * Fires an event so other modules can react to the canvas resizing.
10735
10759
  */
10736
10760
  Canvas.prototype.resized = function() {
10737
10761
 
@@ -10743,11 +10767,21 @@
10743
10767
 
10744
10768
  var ELEMENT_ID = 'data-element-id';
10745
10769
 
10770
+ /**
10771
+ * @typedef {import('.').ElementLike} ElementLike
10772
+ *
10773
+ * @typedef {import('./EventBus').default} EventBus
10774
+ *
10775
+ * @typedef {import('./ElementRegistry').ElementRegistryCallback} ElementRegistryCallback
10776
+ */
10746
10777
 
10747
10778
  /**
10779
+ * A registry that keeps track of all shapes in the diagram.
10780
+ *
10748
10781
  * @class
10782
+ * @constructor
10749
10783
  *
10750
- * A registry that keeps track of all shapes in the diagram.
10784
+ * @param {EventBus} eventBus
10751
10785
  */
10752
10786
  function ElementRegistry(eventBus) {
10753
10787
  this._elements = {};
@@ -10758,11 +10792,11 @@
10758
10792
  ElementRegistry.$inject = [ 'eventBus' ];
10759
10793
 
10760
10794
  /**
10761
- * Register a pair of (element, gfx, (secondaryGfx)).
10795
+ * Add an element and its graphical representation(s) to the registry.
10762
10796
  *
10763
- * @param {djs.model.Base} element
10764
- * @param {SVGElement} gfx
10765
- * @param {SVGElement} [secondaryGfx] optional other element to register, too
10797
+ * @param {ElementLike} element The element to be added.
10798
+ * @param {SVGElement} gfx The primary graphical representation.
10799
+ * @param {SVGElement} [secondaryGfx] The secondary graphical representation.
10766
10800
  */
10767
10801
  ElementRegistry.prototype.add = function(element, gfx, secondaryGfx) {
10768
10802
 
@@ -10781,9 +10815,9 @@
10781
10815
  };
10782
10816
 
10783
10817
  /**
10784
- * Removes an element from the registry.
10818
+ * Remove an element from the registry.
10785
10819
  *
10786
- * @param {string|djs.model.Base} element
10820
+ * @param {ElementLike|string} element
10787
10821
  */
10788
10822
  ElementRegistry.prototype.remove = function(element) {
10789
10823
  var elements = this._elements,
@@ -10804,10 +10838,10 @@
10804
10838
  };
10805
10839
 
10806
10840
  /**
10807
- * Update the id of an element
10841
+ * Update an elements ID.
10808
10842
  *
10809
- * @param {string|djs.model.Base} element
10810
- * @param {string} newId
10843
+ * @param {ElementLike|string} element The element or its ID.
10844
+ * @param {string} newId The new ID.
10811
10845
  */
10812
10846
  ElementRegistry.prototype.updateId = function(element, newId) {
10813
10847
 
@@ -10833,11 +10867,11 @@
10833
10867
  };
10834
10868
 
10835
10869
  /**
10836
- * Update the graphics of an element
10870
+ * Update the graphical representation of an element.
10837
10871
  *
10838
- * @param {string|djs.model.Base} element
10839
- * @param {SVGElement} gfx
10840
- * @param {boolean} [secondary=false] whether to update the secondary connected element
10872
+ * @param {ElementLike|string} element The element or its ID.
10873
+ * @param {SVGElement} gfx The new graphical representation.
10874
+ * @param {boolean} [secondary=false] Whether to update the secondary graphical representation.
10841
10875
  */
10842
10876
  ElementRegistry.prototype.updateGraphics = function(filter, gfx, secondary) {
10843
10877
  var id = filter.id || filter;
@@ -10858,17 +10892,17 @@
10858
10892
  };
10859
10893
 
10860
10894
  /**
10861
- * Return the model element for a given id or graphics.
10895
+ * Get the element with the given ID or graphical representation.
10862
10896
  *
10863
10897
  * @example
10864
10898
  *
10865
10899
  * elementRegistry.get('SomeElementId_1');
10866
- * elementRegistry.get(gfx);
10867
10900
  *
10901
+ * elementRegistry.get(gfx);
10868
10902
  *
10869
- * @param {string|SVGElement} filter for selecting the element
10903
+ * @param {string|SVGElement} filter The elements ID or graphical representation.
10870
10904
  *
10871
- * @return {djs.model.Base}
10905
+ * @return {ElementLike|undefined} The element.
10872
10906
  */
10873
10907
  ElementRegistry.prototype.get = function(filter) {
10874
10908
  var id;
@@ -10886,9 +10920,9 @@
10886
10920
  /**
10887
10921
  * Return all elements that match a given filter function.
10888
10922
  *
10889
- * @param {Function} fn
10923
+ * @param {ElementRegistryCallback} fn The filter function.
10890
10924
  *
10891
- * @return {Array<djs.model.Base>}
10925
+ * @return {ElementLike[]} The matching elements.
10892
10926
  */
10893
10927
  ElementRegistry.prototype.filter = function(fn) {
10894
10928
 
@@ -10904,11 +10938,11 @@
10904
10938
  };
10905
10939
 
10906
10940
  /**
10907
- * Return the first element that satisfies the provided testing function.
10941
+ * Return the first element that matches the given filter function.
10908
10942
  *
10909
- * @param {Function} fn
10943
+ * @param {Function} fn The filter function.
10910
10944
  *
10911
- * @return {djs.model.Base}
10945
+ * @return {ElementLike|undefined} The matching element.
10912
10946
  */
10913
10947
  ElementRegistry.prototype.find = function(fn) {
10914
10948
  var map = this._elements,
@@ -10927,18 +10961,18 @@
10927
10961
  };
10928
10962
 
10929
10963
  /**
10930
- * Return all rendered model elements.
10964
+ * Get all elements.
10931
10965
  *
10932
- * @return {Array<djs.model.Base>}
10966
+ * @return {ElementLike[]} All elements.
10933
10967
  */
10934
10968
  ElementRegistry.prototype.getAll = function() {
10935
10969
  return this.filter(function(e) { return e; });
10936
10970
  };
10937
10971
 
10938
10972
  /**
10939
- * Iterate over all diagram elements.
10973
+ * Execute a given function for each element.
10940
10974
  *
10941
- * @param {Function} fn
10975
+ * @param {Function} fn The function to execute.
10942
10976
  */
10943
10977
  ElementRegistry.prototype.forEach = function(fn) {
10944
10978
 
@@ -10954,19 +10988,20 @@
10954
10988
  };
10955
10989
 
10956
10990
  /**
10957
- * Return the graphical representation of an element or its id.
10991
+ * Return the graphical representation of an element.
10958
10992
  *
10959
10993
  * @example
10994
+ *
10960
10995
  * elementRegistry.getGraphics('SomeElementId_1');
10996
+ *
10961
10997
  * elementRegistry.getGraphics(rootElement); // <g ...>
10962
10998
  *
10963
10999
  * elementRegistry.getGraphics(rootElement, true); // <svg ...>
10964
11000
  *
11001
+ * @param {ElementLike|string} filter The element or its ID.
11002
+ * @param {boolean} [secondary=false] Whether to return the secondary graphical representation.
10965
11003
  *
10966
- * @param {string|djs.model.Base} filter
10967
- * @param {boolean} [secondary=false] whether to return the secondary connected element
10968
- *
10969
- * @return {SVGElement}
11004
+ * @return {SVGElement} The graphical representation.
10970
11005
  */
10971
11006
  ElementRegistry.prototype.getGraphics = function(filter, secondary) {
10972
11007
  var id = filter.id || filter;
@@ -10976,12 +11011,11 @@
10976
11011
  };
10977
11012
 
10978
11013
  /**
10979
- * Validate the suitability of the given id and signals a problem
10980
- * with an exception.
11014
+ * Validate an ID and throw an error if invalid.
10981
11015
  *
10982
11016
  * @param {string} id
10983
11017
  *
10984
- * @throws {Error} if id is empty or already assigned
11018
+ * @throws {Error} Error indicating that the ID is invalid or already assigned.
10985
11019
  */
10986
11020
  ElementRegistry.prototype._validateId = function(id) {
10987
11021
  if (!id) {
@@ -10993,7 +11027,11 @@
10993
11027
  }
10994
11028
  };
10995
11029
 
10996
- var objectRefs = {exports: {}};
11030
+ var objectRefsExports = {};
11031
+ var objectRefs = {
11032
+ get exports(){ return objectRefsExports; },
11033
+ set exports(v){ objectRefsExports = v; },
11034
+ };
10997
11035
 
10998
11036
  var collection = {};
10999
11037
 
@@ -11313,7 +11351,7 @@
11313
11351
  module.exports.Collection = collection;
11314
11352
  } (objectRefs));
11315
11353
 
11316
- var Refs = /*@__PURE__*/getDefaultExportFromCjs(objectRefs.exports);
11354
+ var Refs = /*@__PURE__*/getDefaultExportFromCjs(objectRefsExports);
11317
11355
 
11318
11356
  var parentRefs = new Refs({ name: 'children', enumerable: true, collection: true }, { name: 'parent' }),
11319
11357
  labelRefs = new Refs({ name: 'labels', enumerable: true, collection: true }, { name: 'labelTarget' }),
@@ -11321,14 +11359,6 @@
11321
11359
  outgoingRefs = new Refs({ name: 'outgoing', collection: true }, { name: 'source' }),
11322
11360
  incomingRefs = new Refs({ name: 'incoming', collection: true }, { name: 'target' });
11323
11361
 
11324
- /**
11325
- * @namespace djs.model
11326
- */
11327
-
11328
- /**
11329
- * @memberOf djs.model
11330
- */
11331
-
11332
11362
  /**
11333
11363
  * The basic graphical representation
11334
11364
  *
@@ -11525,21 +11555,47 @@
11525
11555
  };
11526
11556
 
11527
11557
  /**
11528
- * Creates a new model element of the specified type
11558
+ * Creates a model element of the given type.
11529
11559
  *
11530
11560
  * @method create
11531
11561
  *
11532
11562
  * @example
11533
11563
  *
11534
- * var shape1 = Model.create('shape', { x: 10, y: 10, width: 100, height: 100 });
11535
- * var shape2 = Model.create('shape', { x: 210, y: 210, width: 100, height: 100 });
11564
+ * import * as Model from 'diagram-js/lib/model';
11565
+ *
11566
+ * const connection = Model.create('connection', {
11567
+ * waypoints: [
11568
+ * { x: 100, y: 100 },
11569
+ * { x: 200, y: 100 }
11570
+ * ]
11571
+ * });
11572
+ *
11573
+ * const label = Model.create('label', {
11574
+ * x: 100,
11575
+ * y: 100,
11576
+ * width: 100,
11577
+ * height: 100,
11578
+ * labelTarget: shape
11579
+ * });
11580
+ *
11581
+ * const root = Model.create('root', {
11582
+ * x: 100,
11583
+ * y: 100,
11584
+ * width: 100,
11585
+ * height: 100
11586
+ * });
11536
11587
  *
11537
- * var connection = Model.create('connection', { waypoints: [ { x: 110, y: 55 }, {x: 210, y: 55 } ] });
11588
+ * const shape = Model.create('shape', {
11589
+ * x: 100,
11590
+ * y: 100,
11591
+ * width: 100,
11592
+ * height: 100
11593
+ * });
11538
11594
  *
11539
- * @param {string} type lower-cased model name
11540
- * @param {Object} attrs attributes to initialize the new model instance with
11595
+ * @param {string} type The type of model element to be created.
11596
+ * @param {Object} attrs Attributes to create the model element with.
11541
11597
  *
11542
- * @return {Base} the new model instance
11598
+ * @return {Connection|Label|Root|Shape} The created model element.
11543
11599
  */
11544
11600
  function create(type, attrs) {
11545
11601
  var Type = types$6[type];
@@ -11550,36 +11606,78 @@
11550
11606
  }
11551
11607
 
11552
11608
  /**
11553
- * A factory for diagram-js shapes
11609
+ * @typedef {import('../model/index').Base} Base
11610
+ * @typedef {import('../model/index').Connection} Connection
11611
+ * @typedef {import('../model/index').Label} Label
11612
+ * @typedef {import('../model/index').Root} Root
11613
+ * @typedef {import('../model/index').Shape} Shape
11614
+ * @typedef {import('../model/index').ModelAttrsConnection} ModelAttrsConnection
11615
+ * @typedef {import('../model/index').ModelAttrsLabel} ModelAttrsLabel
11616
+ * @typedef {import('../model/index').ModelAttrsRoot} ModelAttrsRoot
11617
+ * @typedef {import('../model/index').ModelAttrsShape} ModelAttrsShape
11618
+ */
11619
+
11620
+ /**
11621
+ * A factory for model elements.
11622
+ *
11623
+ * @class
11624
+ * @constructor
11554
11625
  */
11555
11626
  function ElementFactory() {
11556
11627
  this._uid = 12;
11557
11628
  }
11558
11629
 
11559
-
11630
+ /**
11631
+ * Create a root element.
11632
+ *
11633
+ * @param {ModelAttrsRoot} attrs The attributes of the root element to be created.
11634
+ *
11635
+ * @return {Root} The created root element.
11636
+ */
11560
11637
  ElementFactory.prototype.createRoot = function(attrs) {
11561
11638
  return this.create('root', attrs);
11562
11639
  };
11563
11640
 
11641
+ /**
11642
+ * Create a label.
11643
+ *
11644
+ * @param {ModelAttrsLabel} attrs The attributes of the label to be created.
11645
+ *
11646
+ * @return {Label} The created label.
11647
+ */
11564
11648
  ElementFactory.prototype.createLabel = function(attrs) {
11565
11649
  return this.create('label', attrs);
11566
11650
  };
11567
11651
 
11652
+ /**
11653
+ * Create a shape.
11654
+ *
11655
+ * @param {ModelAttrsShape} attrs The attributes of the shape to be created.
11656
+ *
11657
+ * @return {Shape} The created shape.
11658
+ */
11568
11659
  ElementFactory.prototype.createShape = function(attrs) {
11569
11660
  return this.create('shape', attrs);
11570
11661
  };
11571
11662
 
11663
+ /**
11664
+ * Create a connection.
11665
+ *
11666
+ * @param {ModelAttrsConnection} attrs The attributes of the connection to be created.
11667
+ *
11668
+ * @return {Connection} The created connection.
11669
+ */
11572
11670
  ElementFactory.prototype.createConnection = function(attrs) {
11573
11671
  return this.create('connection', attrs);
11574
11672
  };
11575
11673
 
11576
11674
  /**
11577
- * Create a model element with the given type and
11578
- * a number of pre-set attributes.
11675
+ * Create a model element of the given type with the given attributes.
11579
11676
  *
11580
- * @param {string} type
11581
- * @param {Object} attrs
11582
- * @return {djs.model.Base} the newly created model instance
11677
+ * @param {string} type The type of the model element.
11678
+ * @param {Object} attrs The attributes of the model element.
11679
+ *
11680
+ * @return {Connection|Label|Root|Shape} The created model element.
11583
11681
  */
11584
11682
  ElementFactory.prototype.create = function(type, attrs) {
11585
11683
 
@@ -11598,6 +11696,16 @@
11598
11696
 
11599
11697
  var slice = Array.prototype.slice;
11600
11698
 
11699
+ /**
11700
+ * @typedef {import('./EventBus').Event} Event
11701
+ * @typedef {import('./EventBus').EventCallback} EventCallback
11702
+ *
11703
+ * @typedef {Object} EventListener
11704
+ * @property {Function} callback
11705
+ * @property {EventListener|null} next
11706
+ * @property {number} priority
11707
+ */
11708
+
11601
11709
  /**
11602
11710
  * A general purpose event bus.
11603
11711
  *
@@ -11702,10 +11810,10 @@
11702
11810
  *
11703
11811
  * Returning anything but `undefined` from a listener will stop the listener propagation.
11704
11812
  *
11705
- * @param {string|Array<string>} events
11706
- * @param {number} [priority=1000] the priority in which this listener is called, larger is higher
11707
- * @param {Function} callback
11708
- * @param {Object} [that] Pass context (`this`) to the callback
11813
+ * @param {string|string[]} events The event(s) to listen to.
11814
+ * @param {number} [priority=1000] The priority with which to listen.
11815
+ * @param {EventCallback} callback The callback.
11816
+ * @param {*} [that] Value of `this` the callback will be called with.
11709
11817
  */
11710
11818
  EventBus.prototype.on = function(events, priority, callback, that) {
11711
11819
 
@@ -11745,12 +11853,12 @@
11745
11853
 
11746
11854
 
11747
11855
  /**
11748
- * Register an event listener that is executed only once.
11856
+ * Register an event listener that is called only once.
11749
11857
  *
11750
- * @param {string} event the event name to register for
11751
- * @param {number} [priority=1000] the priority in which this listener is called, larger is higher
11752
- * @param {Function} callback the callback to execute
11753
- * @param {Object} [that] Pass context (`this`) to the callback
11858
+ * @param {string} event The event to listen to.
11859
+ * @param {number} [priority=1000] The priority with which to listen.
11860
+ * @param {EventCallback} callback The callback.
11861
+ * @param {*} [that] Value of `this` the callback will be called with.
11754
11862
  */
11755
11863
  EventBus.prototype.once = function(event, priority, callback, that) {
11756
11864
  var self = this;
@@ -11789,8 +11897,8 @@
11789
11897
  *
11790
11898
  * If no callback is given, all listeners for a given event name are being removed.
11791
11899
  *
11792
- * @param {string|Array<string>} events
11793
- * @param {Function} [callback]
11900
+ * @param {string|string[]} events The events.
11901
+ * @param {EventCallback} [callback] The callback.
11794
11902
  */
11795
11903
  EventBus.prototype.off = function(events, callback) {
11796
11904
 
@@ -11806,11 +11914,11 @@
11806
11914
 
11807
11915
 
11808
11916
  /**
11809
- * Create an EventBus event.
11917
+ * Create an event recognized be the event bus.
11810
11918
  *
11811
- * @param {Object} data
11919
+ * @param {Object} data Event data.
11812
11920
  *
11813
- * @return {Object} event, recognized by the eventBus
11921
+ * @return {Event} An event that will be recognized by the event bus.
11814
11922
  */
11815
11923
  EventBus.prototype.createEvent = function(data) {
11816
11924
  var event = new InternalEvent();
@@ -11822,7 +11930,7 @@
11822
11930
 
11823
11931
 
11824
11932
  /**
11825
- * Fires a named event.
11933
+ * Fires an event.
11826
11934
  *
11827
11935
  * @example
11828
11936
  *
@@ -11844,12 +11952,11 @@
11844
11952
  *
11845
11953
  * events.fire({ type: 'foo' }, 'I am bar!');
11846
11954
  *
11847
- * @param {string} [name] the optional event name
11848
- * @param {Object} [event] the event object
11849
- * @param {...Object} additional arguments to be passed to the callback functions
11955
+ * @param {string} [type] The event type.
11956
+ * @param {Object} [data] The event or event data.
11957
+ * @param {...*} additional Additional arguments the callback will be called with.
11850
11958
  *
11851
- * @return {boolean} the events return value, if specified or false if the
11852
- * default action was prevented by listeners
11959
+ * @return {*} The return value. Will be set to `false` if the default was prevented.
11853
11960
  */
11854
11961
  EventBus.prototype.fire = function(type, data) {
11855
11962
  var event,
@@ -11914,7 +12021,13 @@
11914
12021
  return returnValue;
11915
12022
  };
11916
12023
 
11917
-
12024
+ /**
12025
+ * Handle an error by firing an event.
12026
+ *
12027
+ * @param {Error} error The error to be handled.
12028
+ *
12029
+ * @return {boolean} Whether the error was handled.
12030
+ */
11918
12031
  EventBus.prototype.handleError = function(error) {
11919
12032
  return this.fire('error', { error: error }) === false;
11920
12033
  };
@@ -11977,7 +12090,7 @@
11977
12090
  return returnValue;
11978
12091
  };
11979
12092
 
11980
- /*
12093
+ /**
11981
12094
  * Add new listener with a certain priority to the list
11982
12095
  * of listeners (for the given event).
11983
12096
  *
@@ -11991,7 +12104,7 @@
11991
12104
  * * after: [ 1500, 1500, (new=1300), 1000, 1000, (new=1000) ]
11992
12105
  *
11993
12106
  * @param {string} event
11994
- * @param {Object} listener { priority, callback }
12107
+ * @param {EventListener} listener
11995
12108
  */
11996
12109
  EventBus.prototype._addListener = function(event, newListener) {
11997
12110
 
@@ -12097,9 +12210,9 @@
12097
12210
  * Invoke function. Be fast...
12098
12211
  *
12099
12212
  * @param {Function} fn
12100
- * @param {Array<Object>} args
12213
+ * @param {*[]} args
12101
12214
  *
12102
- * @return {Any}
12215
+ * @return {*}
12103
12216
  */
12104
12217
  function invokeFunction(fn, args) {
12105
12218
  return fn.apply(null, args);
@@ -12113,11 +12226,11 @@
12113
12226
  */
12114
12227
 
12115
12228
  /**
12116
- * Returns the visual part of a diagram element
12229
+ * Returns the visual part of a diagram element.
12117
12230
  *
12118
- * @param {Snap<SVGElement>} gfx
12231
+ * @param {SVGElement} gfx
12119
12232
  *
12120
- * @return {Snap<SVGElement>}
12233
+ * @return {SVGElement}
12121
12234
  */
12122
12235
  function getVisual(gfx) {
12123
12236
  return gfx.childNodes[0];
@@ -12126,15 +12239,28 @@
12126
12239
  /**
12127
12240
  * Returns the children for a given diagram element.
12128
12241
  *
12129
- * @param {Snap<SVGElement>} gfx
12130
- * @return {Snap<SVGElement>}
12242
+ * @param {SVGElement} gfx
12243
+ * @return {SVGElement}
12131
12244
  */
12132
12245
  function getChildren(gfx) {
12133
12246
  return gfx.parentNode.childNodes[1];
12134
12247
  }
12135
12248
 
12136
12249
  /**
12137
- * A factory that creates graphical elements
12250
+ * @typedef {import('../model').ModelType} ModelType
12251
+ * @typedef {import('../model').ModelTypeConnection} ModelTypeConnection
12252
+ * @typedef {import('../model').ModelTypeShape} ModelTypeShape
12253
+ *
12254
+ * @typedef {import('.').ConnectionLike} ConnectionLike
12255
+ * @typedef {import('.').ElementLike} ElementLike
12256
+ * @typedef {import('.').ShapeLike} ShapeLike
12257
+ *
12258
+ * @typedef {import('./ElementRegistry').default} ElementRegistry
12259
+ * @typedef {import('./EventBus').default} EventBus
12260
+ */
12261
+
12262
+ /**
12263
+ * A factory that creates graphical elements.
12138
12264
  *
12139
12265
  * @param {EventBus} eventBus
12140
12266
  * @param {ElementRegistry} elementRegistry
@@ -12202,7 +12328,7 @@
12202
12328
  * </g>
12203
12329
  *
12204
12330
  * @param {string} type the type of the element, i.e. shape | connection
12205
- * @param {SVGElement} [childrenGfx]
12331
+ * @param {SVGElement} childrenGfx
12206
12332
  * @param {number} [parentIndex] position to create container in parent
12207
12333
  * @param {boolean} [isFrame] is frame element
12208
12334
  *
@@ -12240,11 +12366,25 @@
12240
12366
  return gfx;
12241
12367
  };
12242
12368
 
12369
+ /**
12370
+ * Create a graphical element.
12371
+ *
12372
+ * @param {ModelType} type The type of the element.
12373
+ * @param {ElementLike} element The element.
12374
+ * @param {number} [parentIndex] The index at which to add the graphical element to its parent's children.
12375
+ *
12376
+ * @return {SVGElement} The graphical element.
12377
+ */
12243
12378
  GraphicsFactory.prototype.create = function(type, element, parentIndex) {
12244
12379
  var childrenGfx = this._getChildrenContainer(element.parent);
12245
12380
  return this._createContainer(type, childrenGfx, parentIndex, isFrameElement(element));
12246
12381
  };
12247
12382
 
12383
+ /**
12384
+ * Update the containments of the given elements.
12385
+ *
12386
+ * @param {ElementLike[]} elements The elements.
12387
+ */
12248
12388
  GraphicsFactory.prototype.updateContainments = function(elements) {
12249
12389
 
12250
12390
  var self = this,
@@ -12280,30 +12420,63 @@
12280
12420
  });
12281
12421
  };
12282
12422
 
12423
+ /**
12424
+ * Draw a shape.
12425
+ *
12426
+ * @param {SVGElement} visual The graphical element.
12427
+ * @param {ShapeLike} element The shape.
12428
+ */
12283
12429
  GraphicsFactory.prototype.drawShape = function(visual, element) {
12284
12430
  var eventBus = this._eventBus;
12285
12431
 
12286
12432
  return eventBus.fire('render.shape', { gfx: visual, element: element });
12287
12433
  };
12288
12434
 
12435
+ /**
12436
+ * Get the path of a shape.
12437
+ *
12438
+ * @param {ShapeLike} element The shape.
12439
+ *
12440
+ * @return {string} The path of the shape.
12441
+ */
12289
12442
  GraphicsFactory.prototype.getShapePath = function(element) {
12290
12443
  var eventBus = this._eventBus;
12291
12444
 
12292
12445
  return eventBus.fire('render.getShapePath', element);
12293
12446
  };
12294
12447
 
12448
+ /**
12449
+ * Draw a connection.
12450
+ *
12451
+ * @param {SVGElement} visual The graphical element.
12452
+ * @param {ConnectionLike} element The connection.
12453
+ */
12295
12454
  GraphicsFactory.prototype.drawConnection = function(visual, element) {
12296
12455
  var eventBus = this._eventBus;
12297
12456
 
12298
12457
  return eventBus.fire('render.connection', { gfx: visual, element: element });
12299
12458
  };
12300
12459
 
12301
- GraphicsFactory.prototype.getConnectionPath = function(waypoints) {
12460
+ /**
12461
+ * Get the path of a connection.
12462
+ *
12463
+ * @param {ConnectionLike} element The connection.
12464
+ *
12465
+ * @return {string} The path of the connection.
12466
+ */
12467
+ GraphicsFactory.prototype.getConnectionPath = function(connection) {
12302
12468
  var eventBus = this._eventBus;
12303
12469
 
12304
- return eventBus.fire('render.getConnectionPath', waypoints);
12470
+ return eventBus.fire('render.getConnectionPath', connection);
12305
12471
  };
12306
12472
 
12473
+ /**
12474
+ * Update an elements graphical representation.
12475
+ *
12476
+ * @param {ModelTypeShape|ModelTypeConnection} type The type of the element.
12477
+ * @param {ElementLike} element The element.
12478
+ * @param {SVGElement} gfx The graphical representation.
12479
+ */
12307
12480
  GraphicsFactory.prototype.update = function(type, element, gfx) {
12308
12481
 
12309
12482
  // do NOT update root element
@@ -12333,6 +12506,11 @@
12333
12506
  }
12334
12507
  };
12335
12508
 
12509
+ /**
12510
+ * Remove a graphical element.
12511
+ *
12512
+ * @param {ElementLike} element The element.
12513
+ */
12336
12514
  GraphicsFactory.prototype.remove = function(element) {
12337
12515
  var gfx = this._elementRegistry.getGraphics(element);
12338
12516
 
@@ -12366,13 +12544,17 @@
12366
12544
  };
12367
12545
 
12368
12546
  /**
12369
- * @typedef { import('didi').ModuleDeclaration } Module
12547
+ * @typedef {import('didi').InjectionContext} InjectionContext
12548
+ * @typedef {import('didi').LocalsMap} LocalsMap
12549
+ * @typedef {import('didi').ModuleDeclaration} ModuleDeclaration
12550
+ *
12551
+ * @typedef {import('./Diagram').DiagramOptions} DiagramOptions
12370
12552
  */
12371
12553
 
12372
12554
  /**
12373
12555
  * Bootstrap an injector from a list of modules, instantiating a number of default components
12374
12556
  *
12375
- * @param {Array<Module>} modules
12557
+ * @param {ModuleDeclaration[]} modules
12376
12558
  *
12377
12559
  * @return {Injector} a injector to use to access the components
12378
12560
  */
@@ -12387,7 +12569,8 @@
12387
12569
  /**
12388
12570
  * Creates an injector from passed options.
12389
12571
  *
12390
- * @param {Object} options
12572
+ * @param {DiagramOptions} [options]
12573
+ *
12391
12574
  * @return {Injector}
12392
12575
  */
12393
12576
  function createInjector(options) {
@@ -12410,8 +12593,7 @@
12410
12593
  *
12411
12594
  * To register extensions with the diagram, pass them as Array<Module> to the constructor.
12412
12595
  *
12413
- * @class djs.Diagram
12414
- * @memberOf djs
12596
+ * @class
12415
12597
  * @constructor
12416
12598
  *
12417
12599
  * @example
@@ -12449,9 +12631,9 @@
12449
12631
  *
12450
12632
  * // 'shape ... was added to the diagram' logged to console
12451
12633
  *
12452
- * @param {Object} options
12453
- * @param {Array<Module>} [options.modules] external modules to instantiate with the diagram
12454
- * @param {Injector} [injector] an (optional) injector to bootstrap the diagram with
12634
+ * @param {DiagramOptions} [options]
12635
+ * @param {ModuleDeclaration[]} [options.modules] External modules to instantiate with the diagram.
12636
+ * @param {Injector} [injector] An (optional) injector to bootstrap the diagram with.
12455
12637
  */
12456
12638
  function Diagram(options, injector) {
12457
12639
 
@@ -12461,22 +12643,23 @@
12461
12643
  // API
12462
12644
 
12463
12645
  /**
12464
- * Resolves a diagram service
12646
+ * Resolves a diagram service.
12465
12647
  *
12466
12648
  * @method Diagram#get
12467
12649
  *
12468
- * @param {string} name the name of the diagram service to be retrieved
12469
- * @param {boolean} [strict=true] if false, resolve missing services to null
12650
+ * @param {string} name The name of the service to get.
12651
+ * @param {boolean} [strict=true] If false, resolve missing services to null.
12470
12652
  */
12471
12653
  this.get = injector.get;
12472
12654
 
12473
12655
  /**
12474
- * Executes a function into which diagram services are injected
12656
+ * Executes a function with its dependencies injected.
12475
12657
  *
12476
12658
  * @method Diagram#invoke
12477
12659
  *
12478
- * @param {Function|Object[]} fn the function to resolve
12479
- * @param {Object} locals a number of locals to use to resolve certain dependencies
12660
+ * @param {Function} fn The function to be executed.
12661
+ * @param {InjectionContext} [context] The context.
12662
+ * @param {LocalsMap} [locals] The locals.
12480
12663
  */
12481
12664
  this.invoke = injector.invoke;
12482
12665
 
@@ -20882,7 +21065,20 @@
20882
21065
 
20883
21066
 
20884
21067
  /**
20885
- * @typedef { import('didi').ModuleDeclaration } Module
21068
+ * @typedef {import('didi').ModuleDeclaration} ModuleDeclaration
21069
+ *
21070
+ * @typedef {import('./BaseViewer').BaseModelerOptions} BaseModelerOptions
21071
+ * @typedef {import('./BaseViewer').ModdleElement} ModdleElement
21072
+ * @typedef {import('./BaseViewer').ImportXMLResult} ImportXMLResult
21073
+ * @typedef {import('./BaseViewer').ImportXMLError} ImportXMLError
21074
+ * @typedef {import('./BaseViewer').ImportDefinitionsResult} ImportDefinitionsResult
21075
+ * @typedef {import('./BaseViewer').ImportDefinitionsError} ImportDefinitionsError
21076
+ * @typedef {import('./BaseViewer').ModdleElement} ModdleElement
21077
+ * @typedef {import('./BaseViewer').ModdleElementsById} ModdleElementsById
21078
+ * @typedef {import('./BaseViewer').OpenResult} OpenResult
21079
+ * @typedef {import('./BaseViewer').OpenError} OpenError
21080
+ * @typedef {import('./BaseViewer').SaveXMLOptions} SaveXMLOptions
21081
+ * @typedef {import('./BaseViewer').SaveXMLResult} SaveXMLResult
20886
21082
  */
20887
21083
 
20888
21084
  /**
@@ -20891,20 +21087,20 @@
20891
21087
  * Have a look at {@link Viewer}, {@link NavigatedViewer} or {@link Modeler} for
20892
21088
  * bundles that include actual features.
20893
21089
  *
20894
- * @param {Object} [options] configuration options to pass to the viewer
20895
- * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
20896
- * @param {string|number} [options.width] the width of the viewer
20897
- * @param {string|number} [options.height] the height of the viewer
20898
- * @param {Object} [options.moddleExtensions] extension packages to provide
20899
- * @param {Module[]} [options.modules] a list of modules to override the default modules
20900
- * @param {Module[]} [options.additionalModules] a list of modules to use with the default modules
21090
+ * @param {BaseModelerOptions} [options] The options to configure the viewer.
20901
21091
  */
20902
21092
  function BaseViewer(options) {
20903
21093
 
21094
+ /**
21095
+ * @type {BaseModelerOptions}
21096
+ */
20904
21097
  options = assign$1({}, DEFAULT_OPTIONS, options);
20905
21098
 
20906
21099
  this._moddle = this._createModdle(options);
20907
21100
 
21101
+ /**
21102
+ * @type {HTMLElement}
21103
+ */
20908
21104
  this._container = this._createContainer(options);
20909
21105
 
20910
21106
  /* <project-logo> */
@@ -20918,22 +21114,6 @@
20918
21114
 
20919
21115
  e(BaseViewer, Diagram);
20920
21116
 
20921
- /**
20922
- * The importXML result.
20923
- *
20924
- * @typedef {Object} ImportXMLResult
20925
- *
20926
- * @property {Array<string>} warnings
20927
- */
20928
-
20929
- /**
20930
- * The importXML error.
20931
- *
20932
- * @typedef {Error} ImportXMLError
20933
- *
20934
- * @property {Array<string>} warnings
20935
- */
20936
-
20937
21117
  /**
20938
21118
  * Parse and render a BPMN 2.0 diagram.
20939
21119
  *
@@ -20944,7 +21124,7 @@
20944
21124
  *
20945
21125
  * During import the viewer will fire life-cycle events:
20946
21126
  *
20947
- * * import.parse.start (about to read model from xml)
21127
+ * * import.parse.start (about to read model from XML)
20948
21128
  * * import.parse.complete (model read; may have worked or not)
20949
21129
  * * import.render.start (graphical import start)
20950
21130
  * * import.render.complete (graphical import finished)
@@ -20952,10 +21132,18 @@
20952
21132
  *
20953
21133
  * You can use these events to hook into the life-cycle.
20954
21134
  *
20955
- * @param {string} xml the BPMN 2.0 xml
20956
- * @param {ModdleElement<BPMNDiagram>|string} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
21135
+ * @throws {ImportXMLError} An error thrown during the import of the XML.
21136
+ *
21137
+ * @fires BaseViewer#ImportParseStart
21138
+ * @fires BaseViewer#ImportParseComplete
21139
+ * @fires Importer#ImportRenderStart
21140
+ * @fires Importer#ImportRenderComplete
21141
+ * @fires BaseViewer#ImportDone
20957
21142
  *
20958
- * Returns {Promise<ImportXMLResult, ImportXMLError>}
21143
+ * @param {string} xml The BPMN 2.0 XML to be imported.
21144
+ * @param {ModdleElement|string} [bpmnDiagram] The optional diagram or Id of the BPMN diagram to open.
21145
+ *
21146
+ * @return {Promise<ImportXMLResult>} A promise resolving with warnings that were produced during the import.
20959
21147
  */
20960
21148
  BaseViewer.prototype.importXML = wrapForCompatibility(async function importXML(xml, bpmnDiagram) {
20961
21149
 
@@ -20991,6 +21179,14 @@
20991
21179
 
20992
21180
  // hook in pre-parse listeners +
20993
21181
  // allow xml manipulation
21182
+
21183
+ /**
21184
+ * A `import.parse.start` event.
21185
+ *
21186
+ * @event BaseViewer#ImportParseStart
21187
+ * @type {Object}
21188
+ * @property {string} xml The XML that is to be parsed.
21189
+ */
20994
21190
  xml = this._emit('import.parse.start', { xml: xml }) || xml;
20995
21191
 
20996
21192
  let parseResult;
@@ -21013,6 +21209,18 @@
21013
21209
 
21014
21210
  // hook in post parse listeners +
21015
21211
  // allow definitions manipulation
21212
+
21213
+ /**
21214
+ * A `import.parse.complete` event.
21215
+ *
21216
+ * @event BaseViewer#ImportParseComplete
21217
+ * @type {Object}
21218
+ * @property {Error|null} error An error thrown when parsing the XML.
21219
+ * @property {ModdleElement} definitions The definitions model element.
21220
+ * @property {ModdleElementsById} elementsById The model elements by ID.
21221
+ * @property {ModdleElement[]} references The referenced model elements.
21222
+ * @property {string[]} warnings The warnings produced when parsing the XML.
21223
+ */
21016
21224
  definitions = this._emit('import.parse.complete', ParseCompleteEvent({
21017
21225
  error: null,
21018
21226
  definitions: definitions,
@@ -21025,6 +21233,14 @@
21025
21233
 
21026
21234
  aggregatedWarnings = aggregatedWarnings.concat(importResult.warnings);
21027
21235
 
21236
+ /**
21237
+ * A `import.parse.complete` event.
21238
+ *
21239
+ * @event BaseViewer#ImportDone
21240
+ * @type {Object}
21241
+ * @property {ImportXMLError|null} error An error thrown during import.
21242
+ * @property {string[]} warnings The warnings.
21243
+ */
21028
21244
  this._emit('import.done', { error: null, warnings: aggregatedWarnings });
21029
21245
 
21030
21246
  return { warnings: aggregatedWarnings };
@@ -21041,21 +21257,6 @@
21041
21257
  }
21042
21258
  });
21043
21259
 
21044
- /**
21045
- * The importDefinitions result.
21046
- *
21047
- * @typedef {Object} ImportDefinitionsResult
21048
- *
21049
- * @property {Array<string>} warnings
21050
- */
21051
-
21052
- /**
21053
- * The importDefinitions error.
21054
- *
21055
- * @typedef {Error} ImportDefinitionsError
21056
- *
21057
- * @property {Array<string>} warnings
21058
- */
21059
21260
 
21060
21261
  /**
21061
21262
  * Import parsed definitions and render a BPMN 2.0 diagram.
@@ -21072,10 +21273,12 @@
21072
21273
  *
21073
21274
  * You can use these events to hook into the life-cycle.
21074
21275
  *
21075
- * @param {ModdleElement<Definitions>} definitions parsed BPMN 2.0 definitions
21076
- * @param {ModdleElement<BPMNDiagram>|string} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
21276
+ * @throws {ImportDefinitionsError} An error thrown during the import of the definitions.
21277
+ *
21278
+ * @param {ModdleElement} definitions The definitions.
21279
+ * @param {ModdleElement|string} [bpmnDiagram] The optional diagram or ID of the BPMN diagram to open.
21077
21280
  *
21078
- * Returns {Promise<ImportDefinitionsResult, ImportDefinitionsError>}
21281
+ * @return {Promise<ImportDefinitionsResult>} A promise resolving with warnings that were produced during the import.
21079
21282
  */
21080
21283
  BaseViewer.prototype.importDefinitions = wrapForCompatibility(async function importDefinitions(definitions, bpmnDiagram) {
21081
21284
  this._setDefinitions(definitions);
@@ -21084,21 +21287,6 @@
21084
21287
  return { warnings: result.warnings };
21085
21288
  });
21086
21289
 
21087
- /**
21088
- * The open result.
21089
- *
21090
- * @typedef {Object} OpenResult
21091
- *
21092
- * @property {Array<string>} warnings
21093
- */
21094
-
21095
- /**
21096
- * The open error.
21097
- *
21098
- * @typedef {Error} OpenError
21099
- *
21100
- * @property {Array<string>} warnings
21101
- */
21102
21290
 
21103
21291
  /**
21104
21292
  * Open diagram of previously imported XML.
@@ -21115,9 +21303,11 @@
21115
21303
  *
21116
21304
  * You can use these events to hook into the life-cycle.
21117
21305
  *
21118
- * @param {string|ModdleElement<BPMNDiagram>} [bpmnDiagramOrId] id or the diagram to open
21306
+ * @throws {OpenError} An error thrown during opening.
21307
+ *
21308
+ * @param {ModdleElement|string} bpmnDiagramOrId The diagram or Id of the BPMN diagram to open.
21119
21309
  *
21120
- * Returns {Promise<OpenResult, OpenError>}
21310
+ * @return {Promise<OpenResult>} A promise resolving with warnings that were produced during opening.
21121
21311
  */
21122
21312
  BaseViewer.prototype.open = wrapForCompatibility(async function open(bpmnDiagramOrId) {
21123
21313
 
@@ -21158,14 +21348,6 @@
21158
21348
  return { warnings };
21159
21349
  });
21160
21350
 
21161
- /**
21162
- * The saveXML result.
21163
- *
21164
- * @typedef {Object} SaveXMLResult
21165
- *
21166
- * @property {string} xml
21167
- */
21168
-
21169
21351
  /**
21170
21352
  * Export the currently displayed BPMN 2.0 diagram as
21171
21353
  * a BPMN 2.0 XML document.
@@ -21180,11 +21362,14 @@
21180
21362
  *
21181
21363
  * You can use these events to hook into the life-cycle.
21182
21364
  *
21183
- * @param {Object} [options] export options
21184
- * @param {boolean} [options.format=false] output formatted XML
21185
- * @param {boolean} [options.preamble=true] output preamble
21365
+ * @throws {Error} An error thrown during export.
21366
+ *
21367
+ * @fires BaseViewer#SaveXMLStart
21368
+ * @fires BaseViewer#SaveXMLDone
21186
21369
  *
21187
- * Returns {Promise<SaveXMLResult, Error>}
21370
+ * @param {SaveXMLOptions} [options] The options.
21371
+ *
21372
+ * @return {Promise<SaveXMLResult>} A promise resolving with the XML.
21188
21373
  */
21189
21374
  BaseViewer.prototype.saveXML = wrapForCompatibility(async function saveXML(options) {
21190
21375
 
@@ -21199,6 +21384,14 @@
21199
21384
  }
21200
21385
 
21201
21386
  // allow to fiddle around with definitions
21387
+
21388
+ /**
21389
+ * A `saveXML.start` event.
21390
+ *
21391
+ * @event BaseViewer#SaveXMLStart
21392
+ * @type {Object}
21393
+ * @property {ModdleElement} definitions The definitions model element.
21394
+ */
21202
21395
  definitions = this._emit('saveXML.start', {
21203
21396
  definitions
21204
21397
  }) || definitions;
@@ -21215,6 +21408,14 @@
21215
21408
 
21216
21409
  const result = error ? { error } : { xml };
21217
21410
 
21411
+ /**
21412
+ * A `saveXML.done` event.
21413
+ *
21414
+ * @event BaseViewer#SaveXMLDone
21415
+ * @type {Object}
21416
+ * @property {Error} [error] An error thrown when saving the XML.
21417
+ * @property {string} [xml] The saved XML.
21418
+ */
21218
21419
  this._emit('saveXML.done', result);
21219
21420
 
21220
21421
  if (error) {
@@ -21224,13 +21425,6 @@
21224
21425
  return result;
21225
21426
  });
21226
21427
 
21227
- /**
21228
- * The saveSVG result.
21229
- *
21230
- * @typedef {Object} SaveSVGResult
21231
- *
21232
- * @property {string} svg
21233
- */
21234
21428
 
21235
21429
  /**
21236
21430
  * Export the currently displayed BPMN 2.0 diagram as
@@ -21245,11 +21439,13 @@
21245
21439
  *
21246
21440
  * You can use these events to hook into the life-cycle.
21247
21441
  *
21248
- * @param {Object} [options]
21442
+ * @throws {Error} An error thrown during export.
21443
+ *
21444
+ * @fires BaseViewer#SaveSVGDone
21249
21445
  *
21250
- * Returns {Promise<SaveSVGResult, Error>}
21446
+ * @return {Promise<SaveSVGResult>} A promise resolving with the SVG.
21251
21447
  */
21252
- BaseViewer.prototype.saveSVG = wrapForCompatibility(async function saveSVG(options = {}) {
21448
+ BaseViewer.prototype.saveSVG = wrapForCompatibility(async function saveSVG() {
21253
21449
  this._emit('saveSVG.start');
21254
21450
 
21255
21451
  let svg, err;
@@ -21278,6 +21474,14 @@
21278
21474
  err = e;
21279
21475
  }
21280
21476
 
21477
+ /**
21478
+ * A `saveSVG.done` event.
21479
+ *
21480
+ * @event BaseViewer#SaveSVGDone
21481
+ * @type {Object}
21482
+ * @property {Error} [error] An error thrown when saving the SVG.
21483
+ * @property {string} [svg] The saved SVG.
21484
+ */
21281
21485
  this._emit('saveSVG.done', {
21282
21486
  error: err,
21283
21487
  svg: svg
@@ -21329,21 +21533,17 @@
21329
21533
  /**
21330
21534
  * Return modules to instantiate with.
21331
21535
  *
21332
- * @param {any} options the instance got created with
21333
- *
21334
- * @return {Module[]}
21536
+ * @return {ModuleDeclaration[]} The modules.
21335
21537
  */
21336
- BaseViewer.prototype.getModules = function(options) {
21538
+ BaseViewer.prototype.getModules = function() {
21337
21539
  return this._modules;
21338
21540
  };
21339
21541
 
21340
21542
  /**
21341
21543
  * Remove all drawn elements from the viewer.
21342
21544
  *
21343
- * After calling this method the viewer can still
21344
- * be reused for opening another diagram.
21345
- *
21346
- * @method BaseViewer#clear
21545
+ * After calling this method the viewer can still be reused for opening another
21546
+ * diagram.
21347
21547
  */
21348
21548
  BaseViewer.prototype.clear = function() {
21349
21549
  if (!this.getDefinitions()) {
@@ -21357,8 +21557,8 @@
21357
21557
  };
21358
21558
 
21359
21559
  /**
21360
- * Destroy the viewer instance and remove all its
21361
- * remainders from the document tree.
21560
+ * Destroy the viewer instance and remove all its remainders from the document
21561
+ * tree.
21362
21562
  */
21363
21563
  BaseViewer.prototype.destroy = function() {
21364
21564
 
@@ -21370,29 +21570,34 @@
21370
21570
  };
21371
21571
 
21372
21572
  /**
21373
- * Register an event listener
21573
+ * Register an event listener.
21374
21574
  *
21375
- * Remove a previously added listener via {@link #off(event, callback)}.
21575
+ * Remove an event listener via {@link BaseViewer#off}.
21376
21576
  *
21377
- * @param {string} event
21378
- * @param {number} [priority]
21379
- * @param {Function} callback
21380
- * @param {Object} [that]
21577
+ * @param {string|string[]} events The event(s) to listen to.
21578
+ * @param {number} [priority] The priority with which to listen.
21579
+ * @param {EventCallback} callback The callback.
21580
+ * @param {*} [that] Value of `this` the callback will be called with.
21381
21581
  */
21382
- BaseViewer.prototype.on = function(event, priority, callback, target) {
21383
- return this.get('eventBus').on(event, priority, callback, target);
21582
+ BaseViewer.prototype.on = function(events, priority, callback, that) {
21583
+ return this.get('eventBus').on(events, priority, callback, that);
21384
21584
  };
21385
21585
 
21386
21586
  /**
21387
- * De-register an event listener
21587
+ * Remove an event listener.
21388
21588
  *
21389
- * @param {string} event
21390
- * @param {Function} callback
21589
+ * @param {string|string[]} events The event(s).
21590
+ * @param {Function} [callback] The callback.
21391
21591
  */
21392
- BaseViewer.prototype.off = function(event, callback) {
21393
- this.get('eventBus').off(event, callback);
21592
+ BaseViewer.prototype.off = function(events, callback) {
21593
+ this.get('eventBus').off(events, callback);
21394
21594
  };
21395
21595
 
21596
+ /**
21597
+ * Attach the viewer to an HTML element.
21598
+ *
21599
+ * @param {HTMLElement} parentNode The parent node to attach to.
21600
+ */
21396
21601
  BaseViewer.prototype.attachTo = function(parentNode) {
21397
21602
 
21398
21603
  if (!parentNode) {
@@ -21419,10 +21624,20 @@
21419
21624
  this.get('canvas').resized();
21420
21625
  };
21421
21626
 
21627
+ /**
21628
+ * Get the definitions model element.
21629
+ *
21630
+ * @returns {ModdleElement} The definitions model element.
21631
+ */
21422
21632
  BaseViewer.prototype.getDefinitions = function() {
21423
21633
  return this._definitions;
21424
21634
  };
21425
21635
 
21636
+ /**
21637
+ * Detach the viewer.
21638
+ *
21639
+ * @fires BaseViewer#DetachEvent
21640
+ */
21426
21641
  BaseViewer.prototype.detach = function() {
21427
21642
 
21428
21643
  const container = this._container,
@@ -21432,6 +21647,12 @@
21432
21647
  return;
21433
21648
  }
21434
21649
 
21650
+ /**
21651
+ * A `detach` event.
21652
+ *
21653
+ * @event BaseViewer#DetachEvent
21654
+ * @type {Object}
21655
+ */
21435
21656
  this._emit('detach', {});
21436
21657
 
21437
21658
  parentNode.removeChild(container);
@@ -21469,7 +21690,7 @@
21469
21690
  * @param {string} type
21470
21691
  * @param {Object} event
21471
21692
  *
21472
- * @return {Object} event processing result (if any)
21693
+ * @return {Object} The return value after calling all event listeners.
21473
21694
  */
21474
21695
  BaseViewer.prototype._emit = function(type, event) {
21475
21696
  return this.get('eventBus').fire(type, event);
@@ -21595,7 +21816,7 @@
21595
21816
  /* </project-logo> */
21596
21817
 
21597
21818
  /**
21598
- * @typedef { import('didi').ModuleDeclaration } Module
21819
+ * @typedef { import('./BaseViewer').BaseViewerOptions } BaseViewerOptions
21599
21820
  */
21600
21821
 
21601
21822
  /**
@@ -21637,13 +21858,7 @@
21637
21858
  * bpmnViewer.importXML(...);
21638
21859
  * ```
21639
21860
  *
21640
- * @param {Object} [options] configuration options to pass to the viewer
21641
- * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
21642
- * @param {string|number} [options.width] the width of the viewer
21643
- * @param {string|number} [options.height] the height of the viewer
21644
- * @param {Object} [options.moddleExtensions] extension packages to provide
21645
- * @param {Module[]} [options.modules] a list of modules to override the default modules
21646
- * @param {Module[]} [options.additionalModules] a list of modules to use with the default modules
21861
+ * @param {BaseViewerOptions} [options] The options to configure the viewer.
21647
21862
  */
21648
21863
  function Viewer(options) {
21649
21864
  BaseViewer.call(this, options);