@joint/core 4.2.0-alpha.0 → 4.2.0-beta.1

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 (54) hide show
  1. package/README.md +3 -1
  2. package/dist/geometry.js +2 -2
  3. package/dist/geometry.min.js +3 -3
  4. package/dist/joint.d.ts +595 -198
  5. package/dist/joint.js +3895 -1304
  6. package/dist/joint.min.js +3 -3
  7. package/dist/joint.nowrap.js +3895 -1304
  8. package/dist/joint.nowrap.min.js +3 -3
  9. package/dist/vectorizer.js +21 -8
  10. package/dist/vectorizer.min.js +3 -3
  11. package/dist/version.mjs +1 -1
  12. package/package.json +13 -13
  13. package/src/V/index.mjs +20 -5
  14. package/src/alg/Deque.mjs +126 -0
  15. package/src/cellTools/Boundary.mjs +15 -13
  16. package/src/cellTools/Button.mjs +7 -5
  17. package/src/cellTools/Control.mjs +37 -14
  18. package/src/cellTools/HoverConnect.mjs +5 -1
  19. package/src/cellTools/helpers.mjs +44 -3
  20. package/src/config/index.mjs +11 -1
  21. package/src/dia/Cell.mjs +96 -83
  22. package/src/dia/CellCollection.mjs +136 -0
  23. package/src/dia/CellView.mjs +6 -0
  24. package/src/dia/Element.mjs +6 -5
  25. package/src/dia/ElementView.mjs +2 -1
  26. package/src/dia/Graph.mjs +610 -317
  27. package/src/dia/GraphLayer.mjs +53 -0
  28. package/src/dia/GraphLayerCollection.mjs +313 -0
  29. package/src/dia/GraphLayerView.mjs +128 -0
  30. package/src/dia/GraphLayersController.mjs +166 -0
  31. package/src/dia/GraphTopologyIndex.mjs +222 -0
  32. package/src/dia/{layers/GridLayer.mjs → GridLayerView.mjs} +23 -16
  33. package/src/dia/HighlighterView.mjs +22 -0
  34. package/src/dia/{PaperLayer.mjs → LayerView.mjs} +52 -17
  35. package/src/dia/LegacyGraphLayerView.mjs +14 -0
  36. package/src/dia/LinkView.mjs +118 -98
  37. package/src/dia/Paper.mjs +1441 -620
  38. package/src/dia/ToolView.mjs +4 -0
  39. package/src/dia/ToolsView.mjs +14 -5
  40. package/src/dia/attributes/text.mjs +4 -2
  41. package/src/dia/index.mjs +6 -1
  42. package/src/dia/ports.mjs +213 -84
  43. package/src/dia/symbols.mjs +24 -0
  44. package/src/elementTools/HoverConnect.mjs +14 -8
  45. package/src/env/index.mjs +6 -3
  46. package/src/layout/ports/port.mjs +30 -15
  47. package/src/layout/ports/portLabel.mjs +1 -1
  48. package/src/mvc/Collection.mjs +19 -19
  49. package/src/mvc/Model.mjs +13 -10
  50. package/src/mvc/View.mjs +4 -0
  51. package/src/mvc/ViewBase.mjs +1 -1
  52. package/types/geometry.d.ts +64 -60
  53. package/types/joint.d.ts +520 -137
  54. package/types/vectorizer.d.ts +11 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@joint/core",
3
3
  "title": "JointJS",
4
- "version": "4.2.0-alpha.0",
4
+ "version": "4.2.0-beta.1",
5
5
  "description": "JavaScript diagramming library",
6
6
  "sideEffects": false,
7
7
  "main": "./dist/joint.min.js",
@@ -50,7 +50,7 @@
50
50
  "build-bundles": "grunt build:bundles",
51
51
  "test-e2e": "grunt test:e2e",
52
52
  "test-e2e-all": "grunt test:e2e:all",
53
- "lint": "eslint src --ext .mjs,.js",
53
+ "lint": "eslint .",
54
54
  "lint-fix": "yarn run lint --fix",
55
55
  "dist": "grunt dist"
56
56
  },
@@ -66,17 +66,17 @@
66
66
  "devDependencies": {
67
67
  "@babel/core": "7.26.10",
68
68
  "@babel/preset-env": "7.26.9",
69
- "@eslint/eslintrc": "3.3.1",
70
- "@eslint/js": "9.23.0",
71
- "@microsoft/api-extractor": "7.33.7",
69
+ "@eslint/js": "9.38.0",
70
+ "@microsoft/api-extractor": "7.52.10",
72
71
  "@rollup/plugin-babel": "^6.0.4",
73
- "@typescript-eslint/eslint-plugin": "8.28.0",
74
- "@typescript-eslint/parser": "8.27.0",
72
+ "@stylistic/eslint-plugin": "5.5.0",
73
+ "@typescript-eslint/eslint-plugin": "8.46.2",
74
+ "@typescript-eslint/parser": "8.46.2",
75
75
  "async": "2.6.1",
76
76
  "chai": "4.2.0",
77
77
  "core-js": "~3.8.3",
78
78
  "es-module-shims": "0.2.4",
79
- "eslint": "9.23.0",
79
+ "eslint": "9.38.0",
80
80
  "express": "4.21.2",
81
81
  "globals": "16.0.0",
82
82
  "grunt": "1.6.1",
@@ -84,7 +84,7 @@
84
84
  "grunt-contrib-clean": "2.0.0",
85
85
  "grunt-contrib-concat": "1.0.1",
86
86
  "grunt-contrib-copy": "1.0.0",
87
- "grunt-contrib-qunit": "3.1.0",
87
+ "grunt-contrib-qunit": "7.0.1",
88
88
  "grunt-contrib-uglify": "4.0.1",
89
89
  "grunt-contrib-watch": "1.1.0",
90
90
  "grunt-env": "0.4.4",
@@ -100,13 +100,13 @@
100
100
  "karma": "6.4.4",
101
101
  "karma-chrome-launcher": "3.2.0",
102
102
  "karma-coverage": "2.2.1",
103
- "karma-qunit": "2.1.0",
103
+ "karma-qunit": "4.2.1",
104
104
  "karma-sinon": "1.0.5",
105
- "load-grunt-config": "0.19.2",
105
+ "load-grunt-config": "4.0.1",
106
106
  "lodash": "~4.17.21",
107
107
  "mocha": "11.1.0",
108
- "puppeteer": "24.4.0",
109
- "qunit": "2.8.0",
108
+ "puppeteer": "24.22.0",
109
+ "qunit": "2.24.1",
110
110
  "requirejs": "2.3.6",
111
111
  "rollup": "4.36.0",
112
112
  "rollup-plugin-commonjs": "10.1.0",
package/src/V/index.mjs CHANGED
@@ -118,8 +118,11 @@ const V = (function() {
118
118
  });
119
119
 
120
120
  /**
121
- * @param {SVGGElement} toElem
122
- * @returns {SVGMatrix}
121
+ * Calculates the transformation matrix from this element to the target element.
122
+ * @param {SVGElement|V} target - The target element.
123
+ * @param {Object} [opt] - Options object for transformation calculation.
124
+ * @param {boolean} [opt.safe] - Use a safe traversal method to compute the matrix.
125
+ * @returns {DOMMatrix} The transformation matrix from this element to the target element.
123
126
  */
124
127
  VPrototype.getTransformToElement = function(target, opt) {
125
128
  const node = this.node;
@@ -485,10 +488,19 @@ const V = (function() {
485
488
 
486
489
  if (content && typeof content !== 'string') throw new Error('Vectorizer: text() expects the first argument to be a string.');
487
490
 
488
- // Replace all spaces with the Unicode No-break space (http://www.fileformat.info/info/unicode/char/a0/index.htm).
489
- // IE would otherwise collapse all spaces into one.
490
- content = V.sanitizeText(content);
491
491
  opt || (opt = {});
492
+
493
+ // Backwards-compatibility: if no content was provided, treat it as an
494
+ // empty string so that subsequent string operations (e.g. split) do
495
+ // not throw and behaviour matches the previous implementation that
496
+ // always sanitised the input.
497
+ if (content == null) content = '';
498
+
499
+ if (opt.useNoBreakSpace) {
500
+ // Replace all spaces with the Unicode No-break space (http://www.fileformat.info/info/unicode/char/a0/index.htm).
501
+ // IE would otherwise collapse all spaces into one.
502
+ content = V.sanitizeText(content);
503
+ }
492
504
  // Should we allow the text to be selected?
493
505
  var displayEmpty = opt.displayEmpty;
494
506
  // End of Line character
@@ -1332,6 +1344,9 @@ const V = (function() {
1332
1344
  // also exposed so that the programmer can use it in case he needs to. This is useful e.g. in tests
1333
1345
  // when you want to compare the actual DOM text content without having to add the unicode character in
1334
1346
  // the place of all spaces.
1347
+ /**
1348
+ * @deprecated Use regular spaces and rely on xml:space="preserve" instead.
1349
+ */
1335
1350
  V.sanitizeText = function(text) {
1336
1351
 
1337
1352
  return (text || '').replace(/ /g, '\u00A0');
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Deque implementation for managing a double-ended queue.
3
+ * This implementation uses a doubly linked list for efficient operations.
4
+ * It supports operations like push, pop, move to head, and delete.
5
+ * The deque maintains a map for O(1) access to nodes by key.
6
+ */
7
+ export class Deque {
8
+ constructor() {
9
+ this.head = null;
10
+ this.tail = null;
11
+ this.map = new Map(); // key -> node
12
+ }
13
+
14
+ // Return an array of keys in the deque
15
+ keys() {
16
+ let current = this.head;
17
+ const keys = [];
18
+ while (current) {
19
+ keys.push(current.key);
20
+ current = current.next;
21
+ }
22
+ return keys;
23
+ }
24
+
25
+ // Return the first node and remove it from the deque
26
+ popHead() {
27
+ if (!this.head) return null;
28
+ const node = this.head;
29
+ this.map.delete(node.key);
30
+ this.head = node.next;
31
+ if (this.head) {
32
+ this.head.prev = null;
33
+ } else {
34
+ this.tail = null;
35
+ }
36
+ return node;
37
+ }
38
+
39
+ // Add a new node to the back of the deque
40
+ pushTail(key, value) {
41
+ if (this.map.has(key)) {
42
+ throw new Error(`Key "${key}" already exists in the deque.`);
43
+ }
44
+ const node = {
45
+ key,
46
+ value,
47
+ prev: null,
48
+ next: null
49
+ };
50
+ this.map.set(key, node);
51
+ if (!this.tail) {
52
+ this.head = this.tail = node;
53
+ } else {
54
+ this.tail.next = node;
55
+ node.prev = this.tail;
56
+ this.tail = node;
57
+ }
58
+ }
59
+
60
+ // Move a node from the deque to the head
61
+ moveToHead(key) {
62
+ const node = this.map.get(key);
63
+ if (!node) return;
64
+ if (node === this.head) return; // already at head
65
+ // Remove node from its current position
66
+ if (node.prev) node.prev.next = node.next;
67
+ if (node.next) node.next.prev = node.prev;
68
+ if (node === this.tail) this.tail = node.prev; // if it's the tail
69
+ if (node === this.head) this.head = node.next; // if it's the head
70
+ // Move node to head
71
+ node.prev = null;
72
+ node.next = this.head;
73
+ if (this.head) {
74
+ this.head.prev = node; // link old head back to new head
75
+ }
76
+ this.head = node; // update head to be the moved node
77
+ if (!this.tail) {
78
+ this.tail = node; // if it was the only node, set tail as well
79
+ }
80
+ }
81
+
82
+ // Return the first node without removing it
83
+ peekHead() {
84
+ return this.head || null;
85
+ }
86
+
87
+ // Move the head node to the back of the deque
88
+ rotate() {
89
+ if (!this.head || !this.head.next) return;
90
+ this.tail.next = this.head; // link tail to head
91
+ this.head.prev = this.tail; // link head back to tail
92
+ this.tail = this.head; // update tail to be the old head
93
+ this.head = this.head.next; // move head to the next node
94
+ this.tail.next = null; // set new tail's next to null
95
+ this.head.prev = null; // set new head's prev to null
96
+ }
97
+
98
+ // Remove a node from the deque
99
+ delete(key) {
100
+ const node = this.map.get(key);
101
+ if (!node) return;
102
+
103
+ if (node.prev) node.prev.next = node.next;
104
+ else this.head = node.next;
105
+
106
+ if (node.next) node.next.prev = node.prev;
107
+ else this.tail = node.prev;
108
+
109
+ this.map.delete(key);
110
+ }
111
+
112
+ // Does the deque contain a node with the given key?
113
+ has(key) {
114
+ return this.map.has(key);
115
+ }
116
+
117
+ // Get the node with the given key
118
+ get(key) {
119
+ return this.map.get(key) || null;
120
+ }
121
+
122
+ // Number of nodes in the deque
123
+ get length() {
124
+ return this.map.size;
125
+ }
126
+ }
@@ -1,7 +1,7 @@
1
1
 
2
2
  import * as util from '../util/index.mjs';
3
3
  import { ToolView } from '../dia/ToolView.mjs';
4
- import { getViewBBox } from './helpers.mjs';
4
+ import { getToolOptions, getViewBBox } from './helpers.mjs';
5
5
 
6
6
  export const Boundary = ToolView.extend({
7
7
  name: 'boundary',
@@ -21,21 +21,23 @@ export const Boundary = ToolView.extend({
21
21
  this.update();
22
22
  },
23
23
  update: function() {
24
- const { relatedView: view, options, vel } = this;
25
- const { useModelGeometry, rotate } = options;
26
- const padding = util.normalizeSides(options.padding);
27
- let bbox = getViewBBox(view, useModelGeometry).moveAndExpand({
28
- x: -padding.left,
29
- y: -padding.top,
30
- width: padding.left + padding.right,
31
- height: padding.top + padding.bottom
24
+ const { relatedView: view, vel } = this;
25
+ const { useModelGeometry, rotate, relative, padding } = getToolOptions(this);
26
+ const normalizedPadding = util.normalizeSides(padding);
27
+ let bbox = getViewBBox(view, { useModelGeometry, relative }).moveAndExpand({
28
+ x: -normalizedPadding.left,
29
+ y: -normalizedPadding.top,
30
+ width: normalizedPadding.left + normalizedPadding.right,
31
+ height: normalizedPadding.top + normalizedPadding.bottom
32
32
  });
33
- var model = view.model;
34
- if (model.isElement()) {
35
- var angle = model.angle();
33
+ const model = view.model;
34
+ // With relative positioning, rotation is implicit
35
+ // (the tool rotates along with the element).
36
+ if (model.isElement() && !relative) {
37
+ const angle = model.angle();
36
38
  if (angle) {
37
39
  if (rotate) {
38
- var origin = model.getCenter();
40
+ const origin = model.getCenter();
39
41
  vel.rotate(angle, origin.x, origin.y, { absolute: true });
40
42
  } else {
41
43
  bbox = bbox.bbox(angle);
@@ -1,5 +1,5 @@
1
1
  import { ToolView } from '../dia/ToolView.mjs';
2
- import { getViewBBox } from './helpers.mjs';
2
+ import { getToolOptions, getViewBBox } from './helpers.mjs';
3
3
  import * as util from '../util/index.mjs';
4
4
  import * as g from '../g/index.mjs';
5
5
  import V from '../V/index.mjs';
@@ -32,9 +32,9 @@ export const Button = ToolView.extend({
32
32
  return this.relatedView.model.isLink() ? this.getLinkMatrix() : this.getElementMatrix();
33
33
  },
34
34
  getElementMatrix() {
35
- const { relatedView: view, options } = this;
36
- let { x = 0, y = 0, offset = {}, useModelGeometry, rotate, scale } = options;
37
- let bbox = getViewBBox(view, useModelGeometry);
35
+ const { relatedView: view } = this;
36
+ let { x = 0, y = 0, offset = {}, useModelGeometry, rotate, scale, relative } = getToolOptions(this);
37
+ let bbox = getViewBBox(view, { useModelGeometry, relative });
38
38
  const angle = view.model.angle();
39
39
  if (!rotate) bbox = bbox.bbox(angle);
40
40
  const { x: offsetX = 0, y: offsetY = 0 } = offset;
@@ -49,7 +49,9 @@ export const Button = ToolView.extend({
49
49
  y = Number(util.evalCalcExpression(y, bbox));
50
50
  }
51
51
  let matrix = V.createSVGMatrix().translate(bbox.x + bbox.width / 2, bbox.y + bbox.height / 2);
52
- if (rotate) matrix = matrix.rotate(angle);
52
+ // With relative positioning, rotation is implicit
53
+ // (the tool rotates along with the element).
54
+ if (rotate && !relative) matrix = matrix.rotate(angle);
53
55
  matrix = matrix.translate(x + offsetX - bbox.width / 2, y + offsetY - bbox.height / 2);
54
56
  if (scale) matrix = matrix.scale(scale);
55
57
  return matrix;
@@ -1,5 +1,6 @@
1
1
  import { ToolView } from '../dia/ToolView.mjs';
2
2
  import * as util from '../util/index.mjs';
3
+ import { getToolOptions, getViewBBox } from './helpers.mjs';
3
4
 
4
5
  export const Control = ToolView.extend({
5
6
  tagName: 'g',
@@ -72,36 +73,58 @@ export const Control = ToolView.extend({
72
73
  return this;
73
74
  },
74
75
  updateHandle: function(handleNode) {
76
+ const { options: { handleAttributes }} = this;
77
+ handleNode.setAttribute('transform', this.getHandleTransformString());
78
+ if (handleAttributes) {
79
+ for (let attrName in handleAttributes) {
80
+ handleNode.setAttribute(attrName, handleAttributes[attrName]);
81
+ }
82
+ }
83
+ },
84
+ getHandleTransformString() {
75
85
  const { relatedView, options } = this;
86
+ const { scale } = options;
76
87
  const { model } = relatedView;
77
88
  const relativePos = this.getPosition(relatedView, this);
78
- const absolutePos = model.getAbsolutePointFromRelative(relativePos);
79
- const { handleAttributes, scale } = options;
80
- let transformString = `translate(${absolutePos.x},${absolutePos.y})`;
89
+ const translate = this.isOverlay()
90
+ // The tool is rendered in the coordinate system of the paper
91
+ ? model.getAbsolutePointFromRelative(relativePos)
92
+ // The tool is rendered in the coordinate system of the relatedView
93
+ : relativePos;
94
+ let transformString = `translate(${translate.x},${translate.y})`;
81
95
  if (scale) {
82
96
  transformString += ` scale(${scale})`;
83
97
  }
84
- handleNode.setAttribute('transform', transformString);
85
- if (handleAttributes) {
86
- for (let attrName in handleAttributes) {
87
- handleNode.setAttribute(attrName, handleAttributes[attrName]);
88
- }
89
- }
98
+ return transformString;
90
99
  },
91
100
  updateExtras: function(extrasNode) {
92
101
  const { relatedView, options } = this;
93
- const { selector } = this.options;
102
+ const { selector, relative, useModelGeometry } = getToolOptions(this);
94
103
  if (!selector) {
104
+ // Hide the extras if no selector is given.
95
105
  this.toggleExtras(false);
96
106
  return;
97
107
  }
98
- const magnet = relatedView.findNode(selector);
99
- if (!magnet) throw new Error('Control: invalid selector.');
108
+ // Get the size for the extras rectangle and update it.
109
+ let bbox;
110
+ if (useModelGeometry) {
111
+ if (selector !== 'root') {
112
+ // A selector other than null or `root` was provided.
113
+ console.warn('Control: selector will be ignored when `useModelGeometry` is used.');
114
+ }
115
+ bbox = getViewBBox(relatedView, { useModelGeometry, relative });
116
+ } else {
117
+ // The reference node for calculating the bounding box of the extras.
118
+ const el = relatedView.findNode(selector);
119
+ if (!el) throw new Error('Control: invalid selector.');
120
+ bbox = getViewBBox(relatedView, { el });
121
+ }
100
122
  let padding = options.padding;
101
123
  if (!isFinite(padding)) padding = 0;
102
- const bbox = relatedView.getNodeUnrotatedBBox(magnet);
103
124
  const model = relatedView.model;
104
- const angle = model.angle();
125
+ // With relative positioning, rotation is implicit
126
+ // (the tool rotates along with the element).
127
+ const angle = relative ? 0 : model.angle();
105
128
  const center = bbox.center();
106
129
  if (angle) center.rotate(model.getCenter(), -angle);
107
130
  bbox.inflate(padding);
@@ -121,10 +121,14 @@ export const HoverConnect = Connect.extend({
121
121
  return V.createSVGMatrix();
122
122
  },
123
123
 
124
+ getTrackMatrixAbsolute() {
125
+ return this.getTrackMatrix();
126
+ },
127
+
124
128
  getTrackRatioFromEvent(evt) {
125
129
  const { relatedView, trackPath } = this;
126
130
  const localPoint = relatedView.paper.clientToLocalPoint(evt.clientX, evt.clientY);
127
- const trackPoint = V.transformPoint(localPoint, this.getTrackMatrix().inverse());
131
+ const trackPoint = V.transformPoint(localPoint, this.getTrackMatrixAbsolute().inverse());
128
132
  return trackPath.closestPointLength(trackPoint);
129
133
  },
130
134
 
@@ -1,9 +1,50 @@
1
1
  import * as connectionStrategies from '../connectionStrategies/index.mjs';
2
2
 
3
- export function getViewBBox(view, useModelGeometry) {
3
+ /**
4
+ * Common helper for getting a cell view’s bounding box,
5
+ * configurable with `useModelGeometry`, `relative`, and `el`.
6
+ */
7
+ export function getViewBBox(view, {
8
+ useModelGeometry = false,
9
+ relative = false,
10
+ el = view.el
11
+ } = {}) {
4
12
  const { model } = view;
5
- if (useModelGeometry) return model.getBBox();
6
- return (model.isLink()) ? view.getConnection().bbox() : view.getNodeUnrotatedBBox(view.el);
13
+ let bbox;
14
+ if (useModelGeometry) {
15
+ // cell model bbox
16
+ bbox = model.getBBox();
17
+ } else if (model.isLink()) {
18
+ // link view bbox
19
+ bbox = view.getConnection().bbox();
20
+ } else {
21
+ // element view bbox
22
+ bbox = view.getNodeUnrotatedBBox(el);
23
+ }
24
+ if (relative) {
25
+ // Relative to the element position.
26
+ const position = model.position();
27
+ bbox.x -= position.x;
28
+ bbox.y -= position.y;
29
+ }
30
+ return bbox;
31
+ }
32
+
33
+ /**
34
+ * Retrieves the tool options.
35
+ * Automatically overrides `useModelGeometry` and `rotate`
36
+ * if the tool is positioned relative to the element.
37
+ */
38
+ export function getToolOptions(toolView) {
39
+ // Positioning is relative if the tool is drawn within the element view.
40
+ const relative = !toolView.isOverlay();
41
+ const { useModelGeometry, rotate, ...otherOptions } = toolView.options;
42
+ return {
43
+ ...otherOptions,
44
+ useModelGeometry: useModelGeometry || relative,
45
+ rotate: rotate || relative,
46
+ relative,
47
+ };
7
48
  }
8
49
 
9
50
  export function getAnchor(coords, view, magnet) {
@@ -1,4 +1,12 @@
1
1
  export const config = {
2
+ // How the cell attributes are merged when `cell.prop()` is called.
3
+ // DEFAULT: the arrays are merged into the source array.
4
+ cellMergeStrategy: null,
5
+ // How the cell default attributes are merged with the attributes provided
6
+ // in the cell constructor.
7
+ // DEFAULT: the arrays are merged by replacing the source array
8
+ // with the destination array.
9
+ cellDefaultsMergeStrategy: null,
2
10
  // When set to `true` the cell selectors could be defined as CSS selectors.
3
11
  // If not, only JSON Markup selectors are taken into account.
4
12
  useCSSSelectors: false,
@@ -8,5 +16,7 @@ export const config = {
8
16
  defaultTheme: 'default',
9
17
  // The maximum delay required for two consecutive touchend events to be interpreted
10
18
  // as a double-tap.
11
- doubleTapInterval: 300
19
+ doubleTapInterval: 300,
20
+ // Name of the attribute used to store the layer id on the cell model.
21
+ layerAttribute: 'layer',
12
22
  };