@joint/core 4.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.
- package/LICENSE +376 -0
- package/README.md +49 -0
- package/dist/geometry.js +6486 -0
- package/dist/geometry.min.js +8 -0
- package/dist/joint.d.ts +5536 -0
- package/dist/joint.js +39629 -0
- package/dist/joint.min.js +8 -0
- package/dist/joint.nowrap.js +39626 -0
- package/dist/joint.nowrap.min.js +8 -0
- package/dist/vectorizer.js +9135 -0
- package/dist/vectorizer.min.js +8 -0
- package/dist/version.mjs +3 -0
- package/index.js +3 -0
- package/joint.mjs +27 -0
- package/package.json +192 -0
- package/src/V/annotation.mjs +0 -0
- package/src/V/index.mjs +2642 -0
- package/src/anchors/index.mjs +123 -0
- package/src/config/index.mjs +12 -0
- package/src/connectionPoints/index.mjs +202 -0
- package/src/connectionStrategies/index.mjs +73 -0
- package/src/connectors/curve.mjs +553 -0
- package/src/connectors/index.mjs +6 -0
- package/src/connectors/jumpover.mjs +452 -0
- package/src/connectors/normal.mjs +12 -0
- package/src/connectors/rounded.mjs +17 -0
- package/src/connectors/smooth.mjs +44 -0
- package/src/connectors/straight.mjs +110 -0
- package/src/dia/Cell.mjs +945 -0
- package/src/dia/CellView.mjs +1316 -0
- package/src/dia/Element.mjs +519 -0
- package/src/dia/ElementView.mjs +859 -0
- package/src/dia/Graph.mjs +1112 -0
- package/src/dia/HighlighterView.mjs +319 -0
- package/src/dia/Link.mjs +565 -0
- package/src/dia/LinkView.mjs +2207 -0
- package/src/dia/Paper.mjs +3171 -0
- package/src/dia/PaperLayer.mjs +75 -0
- package/src/dia/ToolView.mjs +69 -0
- package/src/dia/ToolsView.mjs +128 -0
- package/src/dia/attributes/calc.mjs +128 -0
- package/src/dia/attributes/connection.mjs +75 -0
- package/src/dia/attributes/defs.mjs +76 -0
- package/src/dia/attributes/eval.mjs +64 -0
- package/src/dia/attributes/index.mjs +69 -0
- package/src/dia/attributes/legacy.mjs +148 -0
- package/src/dia/attributes/offset.mjs +53 -0
- package/src/dia/attributes/props.mjs +30 -0
- package/src/dia/attributes/shape.mjs +92 -0
- package/src/dia/attributes/text.mjs +180 -0
- package/src/dia/index.mjs +13 -0
- package/src/dia/layers/GridLayer.mjs +176 -0
- package/src/dia/ports.mjs +874 -0
- package/src/elementTools/Control.mjs +153 -0
- package/src/elementTools/HoverConnect.mjs +37 -0
- package/src/elementTools/index.mjs +5 -0
- package/src/env/index.mjs +43 -0
- package/src/g/bezier.mjs +175 -0
- package/src/g/curve.mjs +956 -0
- package/src/g/ellipse.mjs +245 -0
- package/src/g/extend.mjs +64 -0
- package/src/g/geometry.helpers.mjs +58 -0
- package/src/g/index.mjs +17 -0
- package/src/g/intersection.mjs +511 -0
- package/src/g/line.bearing.mjs +30 -0
- package/src/g/line.length.mjs +5 -0
- package/src/g/line.mjs +356 -0
- package/src/g/line.squaredLength.mjs +10 -0
- package/src/g/path.mjs +2260 -0
- package/src/g/point.mjs +375 -0
- package/src/g/points.mjs +247 -0
- package/src/g/polygon.mjs +51 -0
- package/src/g/polyline.mjs +523 -0
- package/src/g/rect.mjs +556 -0
- package/src/g/types.mjs +10 -0
- package/src/highlighters/addClass.mjs +27 -0
- package/src/highlighters/index.mjs +5 -0
- package/src/highlighters/list.mjs +111 -0
- package/src/highlighters/mask.mjs +220 -0
- package/src/highlighters/opacity.mjs +17 -0
- package/src/highlighters/stroke.mjs +100 -0
- package/src/layout/index.mjs +4 -0
- package/src/layout/ports/port.mjs +188 -0
- package/src/layout/ports/portLabel.mjs +224 -0
- package/src/linkAnchors/index.mjs +76 -0
- package/src/linkTools/Anchor.mjs +235 -0
- package/src/linkTools/Arrowhead.mjs +103 -0
- package/src/linkTools/Boundary.mjs +48 -0
- package/src/linkTools/Button.mjs +121 -0
- package/src/linkTools/Connect.mjs +85 -0
- package/src/linkTools/HoverConnect.mjs +161 -0
- package/src/linkTools/Segments.mjs +393 -0
- package/src/linkTools/Vertices.mjs +253 -0
- package/src/linkTools/helpers.mjs +33 -0
- package/src/linkTools/index.mjs +8 -0
- package/src/mvc/Collection.mjs +560 -0
- package/src/mvc/Data.mjs +46 -0
- package/src/mvc/Dom/Dom.mjs +587 -0
- package/src/mvc/Dom/Event.mjs +130 -0
- package/src/mvc/Dom/animations.mjs +122 -0
- package/src/mvc/Dom/events.mjs +69 -0
- package/src/mvc/Dom/index.mjs +13 -0
- package/src/mvc/Dom/methods.mjs +392 -0
- package/src/mvc/Dom/props.mjs +77 -0
- package/src/mvc/Dom/vars.mjs +5 -0
- package/src/mvc/Events.mjs +337 -0
- package/src/mvc/Listener.mjs +33 -0
- package/src/mvc/Model.mjs +239 -0
- package/src/mvc/View.mjs +323 -0
- package/src/mvc/ViewBase.mjs +182 -0
- package/src/mvc/index.mjs +9 -0
- package/src/mvc/mvcUtils.mjs +90 -0
- package/src/polyfills/array.js +4 -0
- package/src/polyfills/base64.js +68 -0
- package/src/polyfills/index.mjs +5 -0
- package/src/polyfills/number.js +3 -0
- package/src/polyfills/string.js +3 -0
- package/src/polyfills/typedArray.js +47 -0
- package/src/routers/index.mjs +6 -0
- package/src/routers/manhattan.mjs +856 -0
- package/src/routers/metro.mjs +91 -0
- package/src/routers/normal.mjs +6 -0
- package/src/routers/oneSide.mjs +60 -0
- package/src/routers/orthogonal.mjs +323 -0
- package/src/routers/rightAngle.mjs +1056 -0
- package/src/shapes/index.mjs +3 -0
- package/src/shapes/standard.mjs +755 -0
- package/src/util/cloneCells.mjs +67 -0
- package/src/util/getRectPoint.mjs +65 -0
- package/src/util/index.mjs +5 -0
- package/src/util/svgTagTemplate.mjs +110 -0
- package/src/util/util.mjs +1754 -0
- package/src/util/utilHelpers.mjs +2402 -0
- package/src/util/wrappers.mjs +56 -0
- package/types/geometry.d.ts +815 -0
- package/types/index.d.ts +53 -0
- package/types/joint.d.ts +4391 -0
- package/types/joint.head.d.ts +12 -0
- package/types/vectorizer.d.ts +327 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import * as mvc from '../mvc/index.mjs';
|
|
2
|
+
import V from '../V/index.mjs';
|
|
3
|
+
import { isPlainObject, result } from '../util/util.mjs';
|
|
4
|
+
|
|
5
|
+
function toArray(obj) {
|
|
6
|
+
if (!obj) return [];
|
|
7
|
+
if (Array.isArray(obj)) return obj;
|
|
8
|
+
return [obj];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const HighlighterView = mvc.View.extend({
|
|
12
|
+
|
|
13
|
+
tagName: 'g',
|
|
14
|
+
svgElement: true,
|
|
15
|
+
className: 'highlight',
|
|
16
|
+
|
|
17
|
+
HIGHLIGHT_FLAG: 1,
|
|
18
|
+
UPDATE_PRIORITY: 3,
|
|
19
|
+
DETACHABLE: false,
|
|
20
|
+
UPDATABLE: true,
|
|
21
|
+
MOUNTABLE: true,
|
|
22
|
+
|
|
23
|
+
cellView: null,
|
|
24
|
+
nodeSelector: null,
|
|
25
|
+
node: null,
|
|
26
|
+
updateRequested: false,
|
|
27
|
+
postponedUpdate: false,
|
|
28
|
+
transformGroup: null,
|
|
29
|
+
detachedTransformGroup: null,
|
|
30
|
+
|
|
31
|
+
requestUpdate(cellView, nodeSelector) {
|
|
32
|
+
const { paper } = cellView;
|
|
33
|
+
this.cellView = cellView;
|
|
34
|
+
this.nodeSelector = nodeSelector;
|
|
35
|
+
if (paper) {
|
|
36
|
+
this.updateRequested = true;
|
|
37
|
+
paper.requestViewUpdate(this, this.HIGHLIGHT_FLAG, this.UPDATE_PRIORITY);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
confirmUpdate() {
|
|
42
|
+
// The cellView is now rendered/updated since it has a higher update priority.
|
|
43
|
+
this.updateRequested = false;
|
|
44
|
+
const { cellView, nodeSelector } = this;
|
|
45
|
+
if (!cellView.isMounted()) {
|
|
46
|
+
this.postponedUpdate = true;
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
this.update(cellView, nodeSelector);
|
|
50
|
+
this.mount();
|
|
51
|
+
this.transform();
|
|
52
|
+
return 0;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
findNode(cellView, nodeSelector = null) {
|
|
56
|
+
let el;
|
|
57
|
+
if (typeof nodeSelector === 'string') {
|
|
58
|
+
el = cellView.findNode(nodeSelector);
|
|
59
|
+
} else if (isPlainObject(nodeSelector)) {
|
|
60
|
+
const isLink = cellView.model.isLink();
|
|
61
|
+
const { label = null, port, selector } = nodeSelector;
|
|
62
|
+
if (isLink && label !== null) {
|
|
63
|
+
// Link Label Selector
|
|
64
|
+
el = cellView.findLabelNode(label, selector);
|
|
65
|
+
} else if (!isLink && port) {
|
|
66
|
+
// Element Port Selector
|
|
67
|
+
el = cellView.findPortNode(port, selector);
|
|
68
|
+
} else {
|
|
69
|
+
// Cell Selector
|
|
70
|
+
el = cellView.findNode(selector);
|
|
71
|
+
}
|
|
72
|
+
} else if (nodeSelector) {
|
|
73
|
+
el = V.toNode(nodeSelector);
|
|
74
|
+
if (!(el instanceof SVGElement)) el = null;
|
|
75
|
+
}
|
|
76
|
+
return el ? el : null;
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
getNodeMatrix(cellView, node) {
|
|
80
|
+
const { options } = this;
|
|
81
|
+
const { layer } = options;
|
|
82
|
+
const { rotatableNode } = cellView;
|
|
83
|
+
const nodeMatrix = cellView.getNodeMatrix(node);
|
|
84
|
+
if (rotatableNode) {
|
|
85
|
+
if (layer) {
|
|
86
|
+
if (rotatableNode.contains(node)) {
|
|
87
|
+
return nodeMatrix;
|
|
88
|
+
}
|
|
89
|
+
// The node is outside of the rotatable group.
|
|
90
|
+
// Compensate the rotation set by transformGroup.
|
|
91
|
+
return cellView.getRootRotateMatrix().inverse().multiply(nodeMatrix);
|
|
92
|
+
} else {
|
|
93
|
+
return cellView.getNodeRotateMatrix(node).multiply(nodeMatrix);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return nodeMatrix;
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
mount() {
|
|
100
|
+
const { MOUNTABLE, cellView, el, options, transformGroup, detachedTransformGroup, postponedUpdate, nodeSelector } = this;
|
|
101
|
+
if (!MOUNTABLE || transformGroup) return;
|
|
102
|
+
if (postponedUpdate) {
|
|
103
|
+
// The cellView was not mounted when the update was requested.
|
|
104
|
+
// The update was postponed until the cellView is mounted.
|
|
105
|
+
this.update(cellView, nodeSelector);
|
|
106
|
+
this.transform();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const { vel: cellViewRoot, paper } = cellView;
|
|
110
|
+
const { layer: layerName } = options;
|
|
111
|
+
if (layerName) {
|
|
112
|
+
let vGroup;
|
|
113
|
+
if (detachedTransformGroup) {
|
|
114
|
+
vGroup = detachedTransformGroup;
|
|
115
|
+
this.detachedTransformGroup = null;
|
|
116
|
+
} else {
|
|
117
|
+
vGroup = V('g').addClass('highlight-transform').append(el);
|
|
118
|
+
}
|
|
119
|
+
this.transformGroup = vGroup;
|
|
120
|
+
paper.getLayerView(layerName).insertSortedNode(vGroup.node, options.z);
|
|
121
|
+
} else {
|
|
122
|
+
// TODO: prepend vs append
|
|
123
|
+
if (!el.parentNode || el.nextSibling) {
|
|
124
|
+
// Not appended yet or not the last child
|
|
125
|
+
cellViewRoot.append(el);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
unmount() {
|
|
131
|
+
const { MOUNTABLE, transformGroup, vel } = this;
|
|
132
|
+
if (!MOUNTABLE) return;
|
|
133
|
+
if (transformGroup) {
|
|
134
|
+
this.transformGroup = null;
|
|
135
|
+
this.detachedTransformGroup = transformGroup;
|
|
136
|
+
transformGroup.remove();
|
|
137
|
+
} else {
|
|
138
|
+
vel.remove();
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
transform() {
|
|
143
|
+
const { transformGroup, cellView, updateRequested } = this;
|
|
144
|
+
if (!transformGroup || cellView.model.isLink() || updateRequested) return;
|
|
145
|
+
const translateMatrix = cellView.getRootTranslateMatrix();
|
|
146
|
+
const rotateMatrix = cellView.getRootRotateMatrix();
|
|
147
|
+
const transformMatrix = translateMatrix.multiply(rotateMatrix);
|
|
148
|
+
transformGroup.attr('transform', V.matrixToTransformString(transformMatrix));
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
update() {
|
|
152
|
+
const { node: prevNode, cellView, nodeSelector, updateRequested, id } = this;
|
|
153
|
+
if (updateRequested) return;
|
|
154
|
+
this.postponedUpdate = false;
|
|
155
|
+
const node = this.node = this.findNode(cellView, nodeSelector);
|
|
156
|
+
if (prevNode) {
|
|
157
|
+
this.unhighlight(cellView, prevNode);
|
|
158
|
+
}
|
|
159
|
+
if (node) {
|
|
160
|
+
this.highlight(cellView, node);
|
|
161
|
+
this.mount();
|
|
162
|
+
} else {
|
|
163
|
+
this.unmount();
|
|
164
|
+
cellView.notify('cell:highlight:invalid', id, this);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
onRemove() {
|
|
169
|
+
const { node, cellView, id, constructor } = this;
|
|
170
|
+
if (node) {
|
|
171
|
+
this.unhighlight(cellView, node);
|
|
172
|
+
}
|
|
173
|
+
this.unmount();
|
|
174
|
+
constructor._removeRef(cellView, id);
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
highlight(_cellView, _node) {
|
|
178
|
+
// to be overridden
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
unhighlight(_cellView, _node) {
|
|
182
|
+
// to be overridden
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
// Update Attributes
|
|
186
|
+
|
|
187
|
+
listenToUpdateAttributes(cellView) {
|
|
188
|
+
const attributes = result(this, 'UPDATE_ATTRIBUTES');
|
|
189
|
+
if (!Array.isArray(attributes) || attributes.length === 0) return;
|
|
190
|
+
this.listenTo(cellView.model, 'change', this.onCellAttributeChange);
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
onCellAttributeChange() {
|
|
194
|
+
const { cellView } = this;
|
|
195
|
+
if (!cellView) return;
|
|
196
|
+
const { model, paper } = cellView;
|
|
197
|
+
const attributes = result(this, 'UPDATE_ATTRIBUTES');
|
|
198
|
+
if (!attributes.some(attribute => model.hasChanged(attribute))) return;
|
|
199
|
+
paper.requestViewUpdate(this, this.HIGHLIGHT_FLAG, this.UPDATE_PRIORITY);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
}, {
|
|
203
|
+
|
|
204
|
+
_views: {},
|
|
205
|
+
|
|
206
|
+
// Used internally by CellView highlight()
|
|
207
|
+
highlight: function(cellView, node, opt) {
|
|
208
|
+
const id = this.uniqueId(node, opt);
|
|
209
|
+
this.add(cellView, node, id, opt);
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
// Used internally by CellView unhighlight()
|
|
213
|
+
unhighlight: function(cellView, node, opt) {
|
|
214
|
+
const id = this.uniqueId(node, opt);
|
|
215
|
+
this.remove(cellView, id);
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
get(cellView, id = null) {
|
|
219
|
+
const { cid } = cellView;
|
|
220
|
+
const { _views } = this;
|
|
221
|
+
const refs = _views[cid];
|
|
222
|
+
if (id === null) {
|
|
223
|
+
// all highlighters
|
|
224
|
+
const views = [];
|
|
225
|
+
if (!refs) return views;
|
|
226
|
+
for (let hid in refs) {
|
|
227
|
+
const ref = refs[hid];
|
|
228
|
+
if (ref instanceof this) {
|
|
229
|
+
views.push(ref);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return views;
|
|
233
|
+
} else {
|
|
234
|
+
// single highlighter
|
|
235
|
+
if (!refs) return null;
|
|
236
|
+
if (id in refs) {
|
|
237
|
+
const ref = refs[id];
|
|
238
|
+
if (ref instanceof this) return ref;
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
|
|
244
|
+
add(cellView, nodeSelector, id, opt = {}) {
|
|
245
|
+
if (!id) throw new Error('dia.HighlighterView: An ID required.');
|
|
246
|
+
// Search the existing view amongst all the highlighters
|
|
247
|
+
const previousView = HighlighterView.get(cellView, id);
|
|
248
|
+
if (previousView) previousView.remove();
|
|
249
|
+
const view = new this(opt);
|
|
250
|
+
view.id = id;
|
|
251
|
+
this._addRef(cellView, id, view);
|
|
252
|
+
view.requestUpdate(cellView, nodeSelector);
|
|
253
|
+
view.listenToUpdateAttributes(cellView);
|
|
254
|
+
return view;
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
_addRef(cellView, id, view) {
|
|
258
|
+
const { cid } = cellView;
|
|
259
|
+
const { _views } = this;
|
|
260
|
+
let refs = _views[cid];
|
|
261
|
+
if (!refs) refs = _views[cid] = {};
|
|
262
|
+
refs[id] = view;
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
_removeRef(cellView, id) {
|
|
266
|
+
const { cid } = cellView;
|
|
267
|
+
const { _views } = this;
|
|
268
|
+
const refs = _views[cid];
|
|
269
|
+
if (!refs) return;
|
|
270
|
+
if (id) delete refs[id];
|
|
271
|
+
for (let _ in refs) return;
|
|
272
|
+
delete _views[cid];
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
remove(cellView, id = null) {
|
|
276
|
+
toArray(this.get(cellView, id)).forEach(view => {
|
|
277
|
+
view.remove();
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
removeAll(paper, id = null) {
|
|
282
|
+
const { _views } = this;
|
|
283
|
+
|
|
284
|
+
for (let cid in _views) {
|
|
285
|
+
for (let hid in _views[cid]) {
|
|
286
|
+
const view = _views[cid][hid];
|
|
287
|
+
|
|
288
|
+
if (view.cellView.paper === paper && view instanceof this && (id === null || hid === id)) {
|
|
289
|
+
view.remove();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
update(cellView, id = null, dirty = false) {
|
|
296
|
+
toArray(this.get(cellView, id)).forEach(view => {
|
|
297
|
+
if (dirty || view.UPDATABLE) view.update();
|
|
298
|
+
});
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
transform(cellView, id = null) {
|
|
302
|
+
toArray(this.get(cellView, id)).forEach(view => {
|
|
303
|
+
if (view.UPDATABLE) view.transform();
|
|
304
|
+
});
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
unmount(cellView, id = null) {
|
|
308
|
+
toArray(this.get(cellView, id)).forEach(view => view.unmount());
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
mount(cellView, id = null) {
|
|
312
|
+
toArray(this.get(cellView, id)).forEach(view => view.mount());
|
|
313
|
+
},
|
|
314
|
+
|
|
315
|
+
uniqueId(node, opt = '') {
|
|
316
|
+
return V.ensureId(node) + JSON.stringify(opt);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
});
|