@umbraci/jsmind 0.10.18 → 1.0.0-beta

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 (55) hide show
  1. package/README.md +7 -7
  2. package/dist/jsmind.draggable-node.js +7 -472
  3. package/dist/jsmind.draggable-node.js.map +1 -1
  4. package/dist/jsmind.history.js +7 -980
  5. package/dist/jsmind.history.js.map +1 -1
  6. package/dist/jsmind.js +7 -2624
  7. package/dist/jsmind.js.map +1 -1
  8. package/dist/jsmind.multi-select.js +7 -671
  9. package/dist/jsmind.multi-select.js.map +1 -1
  10. package/dist/jsmind.multiline-text.js +7 -156
  11. package/dist/jsmind.multiline-text.js.map +1 -1
  12. package/dist/jsmind.screenshot.js +7 -156
  13. package/dist/jsmind.screenshot.js.map +1 -1
  14. package/es/jsmind.draggable-node.js +7 -443
  15. package/es/jsmind.draggable-node.js.map +1 -1
  16. package/es/jsmind.history.js +7 -944
  17. package/es/jsmind.history.js.map +1 -1
  18. package/es/jsmind.js +7 -2570
  19. package/es/jsmind.js.map +1 -1
  20. package/es/jsmind.multi-select.js +7 -621
  21. package/es/jsmind.multi-select.js.map +1 -1
  22. package/es/jsmind.multiline-text.js +7 -136
  23. package/es/jsmind.multiline-text.js.map +1 -1
  24. package/es/jsmind.screenshot.js +7 -136
  25. package/es/jsmind.screenshot.js.map +1 -1
  26. package/lib/jsmind.draggable-node.js +7 -450
  27. package/lib/jsmind.draggable-node.js.map +1 -1
  28. package/lib/jsmind.history.js +7 -946
  29. package/lib/jsmind.history.js.map +1 -1
  30. package/lib/jsmind.js +7 -2571
  31. package/lib/jsmind.js.map +1 -1
  32. package/lib/jsmind.multi-select.js +7 -623
  33. package/lib/jsmind.multi-select.js.map +1 -1
  34. package/lib/jsmind.multiline-text.js +7 -141
  35. package/lib/jsmind.multiline-text.js.map +1 -1
  36. package/lib/jsmind.screenshot.js +7 -145
  37. package/lib/jsmind.screenshot.js.map +1 -1
  38. package/package.json +26 -25
  39. package/types/generated/jsmind.d.ts +21 -24
  40. package/types/generated/jsmind.mind.d.ts +7 -0
  41. package/types/generated/{jsmind.enhanced-plugin.d.ts → jsmind.plugin-system.d.ts} +10 -10
  42. package/types/generated/jsmind.plugin.d.ts +93 -13
  43. package/types/generated/jsmind.view_provider.d.ts +1 -1
  44. package/types/generated/plugins/history/history-diff.d.ts +10 -0
  45. package/types/generated/plugins/history/jsmind.history.d.ts +2 -2
  46. package/types/generated/plugins/jsmind.draggable-node.d.ts +13 -3
  47. package/types/generated/plugins/jsmind.multi-select.d.ts +3 -3
  48. package/types/generated/plugins/jsmind.multiline-text.d.ts +67 -21
  49. package/types/generated/plugins/jsmind.screenshot.d.ts +12 -3
  50. package/types/tsconfig.declaration.json +6 -1
  51. package/dist/jsmind.copy-paste.js +0 -283
  52. package/dist/jsmind.copy-paste.js.map +0 -1
  53. package/es/jsmind.copy-paste.js +0 -260
  54. package/es/jsmind.copy-paste.js.map +0 -1
  55. package/types/generated/plugins/jsmind.multiline-text-v2.d.ts +0 -58
package/lib/jsmind.js CHANGED
@@ -1,2573 +1,9 @@
1
1
  /**
2
- * @license BSD-3-Clause
3
- * @copyright 2014-2025 hizzgdev@163.com
4
- *
5
- * Project Home:
6
- * https://github.com/hizzgdev/jsmind/
7
- */
8
- 'use strict';
9
- const e = '0.9.0';
10
- 'function' != typeof String.prototype.startsWith &&
11
- (String.prototype.startsWith = function (e) {
12
- return this.slice(0, e.length) === e;
13
- });
14
- const t = {
15
- left: -1,
16
- center: 0,
17
- right: 1,
18
- of: function (e) {
19
- return e && -1 !== e && 0 !== e && 1 !== e
20
- ? '-1' === e || '0' === e || '1' === e
21
- ? parseInt(e)
22
- : 'left' === e.toLowerCase()
23
- ? this.left
24
- : 'right' === e.toLowerCase()
25
- ? this.right
26
- : 'center' === e.toLowerCase()
27
- ? this.center
28
- : void 0
29
- : e;
30
- },
31
- },
32
- i = { show: 1, resize: 2, edit: 3, select: 4, reset: 5, history_change: 6 },
33
- n = { debug: 1, info: 2, warn: 3, error: 4, disable: 9 };
34
- var o = function () {};
35
- let s =
36
- 'undefined' == typeof console
37
- ? { level: o, log: o, debug: o, info: o, warn: o, error: o }
38
- : {
39
- level: function (e) {
40
- s.debug = e > n.debug ? o : console.debug;
41
- s.info = e > n.info ? o : console.info;
42
- s.warn = e > n.warn ? o : console.warn;
43
- s.error = e > n.error ? o : console.error;
44
- },
45
- log: console.log,
46
- debug: console.debug,
47
- info: console.info,
48
- warn: console.warn,
49
- error: console.error,
50
- };
51
- const r = new (class {
52
- constructor(e) {
53
- (this.w = e),
54
- (this.d = e.document),
55
- (this.g = function (e) {
56
- return this.d.getElementById(e);
57
- }),
58
- (this.c = function (e) {
59
- return this.d.createElement(e);
60
- }),
61
- (this.t = function (e, t) {
62
- e.hasChildNodes()
63
- ? (e.firstChild.nodeValue = t)
64
- : e.appendChild(this.d.createTextNode(t));
65
- }),
66
- (this.h = function (e, t) {
67
- t instanceof HTMLElement
68
- ? ((e.innerHTML = ''), e.appendChild(t))
69
- : (e.innerHTML = t);
70
- }),
71
- (this.i = function (e) {
72
- return (
73
- !!e &&
74
- 'object' == typeof e &&
75
- 1 === e.nodeType &&
76
- 'object' == typeof e.style &&
77
- 'object' == typeof e.ownerDocument
78
- );
79
- }),
80
- (this.on = function (e, t, i) {
81
- e.addEventListener ? e.addEventListener(t, i, !1) : e.attachEvent('on' + t, i);
82
- });
83
- }
84
- })(window),
85
- a = {
86
- file: {
87
- read: function (e, t) {
88
- var i = new FileReader();
89
- (i.onload = function () {
90
- 'function' == typeof t && t(this.result, e.name);
91
- }),
92
- i.readAsText(e);
93
- },
94
- save: function (e, t, i) {
95
- var n;
96
- if ('function' == typeof r.w.Blob) n = new Blob([e], { type: t });
97
- else {
98
- var o = new (r.w.BlobBuilder ||
99
- r.w.MozBlobBuilder ||
100
- r.w.WebKitBlobBuilder ||
101
- r.w.MSBlobBuilder)();
102
- o.append(e), (n = o.getBlob(t));
103
- }
104
- if (navigator.msSaveBlob) navigator.msSaveBlob(n, i);
105
- else {
106
- var s = (r.w.URL || r.w.webkitURL).createObjectURL(n),
107
- a = r.c('a');
108
- if ('download' in a) {
109
- (a.style.visibility = 'hidden'),
110
- (a.href = s),
111
- (a.download = i),
112
- r.d.body.appendChild(a);
113
- var d = r.d.createEvent('MouseEvents');
114
- d.initEvent('click', !0, !0), a.dispatchEvent(d), r.d.body.removeChild(a);
115
- } else location.href = s;
116
- }
117
- },
118
- },
119
- json: {
120
- json2string: function (e) {
121
- return JSON.stringify(e);
122
- },
123
- string2json: function (e) {
124
- return JSON.parse(e);
125
- },
126
- merge: function (e, t) {
127
- for (var i in t)
128
- i in e
129
- ? 'object' != typeof e[i] ||
130
- '[object object]' != Object.prototype.toString.call(e[i]).toLowerCase() ||
131
- e[i].length
132
- ? (e[i] = t[i])
133
- : a.json.merge(e[i], t[i])
134
- : (e[i] = t[i]);
135
- return e;
136
- },
137
- },
138
- uuid: {
139
- newid: function () {
140
- return (
141
- new Date().getTime().toString(16) + Math.random().toString(16).substring(2)
142
- ).substring(2, 18);
143
- },
144
- },
145
- text: {
146
- is_empty: function (e) {
147
- return !e || 0 == e.replace(/\s*/, '').length;
148
- },
149
- },
150
- },
151
- d = {
152
- container: '',
153
- editable: !1,
154
- theme: null,
155
- mode: 'full',
156
- support_html: !0,
157
- log_level: 'info',
158
- view: {
159
- engine: 'canvas',
160
- enable_device_pixel_ratio: !1,
161
- hmargin: 100,
162
- vmargin: 50,
163
- line_width: 2,
164
- line_color: '#555',
165
- line_style: 'curved',
166
- draggable: !1,
167
- hide_scrollbars_when_draggable: !1,
168
- node_overflow: 'hidden',
169
- zoom: { min: 0.5, max: 2.1, step: 0.1, mask_key: 4096 },
170
- custom_node_render: null,
171
- expander_style: 'char',
172
- },
173
- layout: { hspace: 30, vspace: 20, pspace: 13, cousin_space: 0 },
174
- default_event_handle: {
175
- enable_mousedown_handle: !0,
176
- enable_click_handle: !0,
177
- enable_dblclick_handle: !0,
178
- enable_mousewheel_handle: !0,
179
- },
180
- shortcut: {
181
- enable: !0,
182
- handles: {},
183
- mapping: {
184
- addchild: [45, 4109],
185
- addbrother: 13,
186
- editnode: 113,
187
- delnode: 46,
188
- toggle: 32,
189
- left: 37,
190
- up: 38,
191
- right: 39,
192
- down: 40,
193
- },
194
- },
195
- fieldNames: {
196
- id: 'id',
197
- topic: 'topic',
198
- children: 'children',
199
- parentid: 'parentid',
200
- isroot: 'isroot',
201
- direction: 'direction',
202
- expanded: 'expanded',
203
- },
204
- plugin: {},
205
- };
206
- class l {
207
- constructor(e, t, i, n, o, r, a, d) {
208
- e
209
- ? 'number' == typeof t
210
- ? (void 0 === d && (d = !0),
211
- (this.id = e),
212
- (this.index = t),
213
- (this.topic = i),
214
- (this.data = n || {}),
215
- (this.isroot = o),
216
- (this.parent = r),
217
- (this.direction = a),
218
- (this.expanded = !!d),
219
- (this.children = []),
220
- (this._data = {}))
221
- : s.error('invalid node index')
222
- : s.error('invalid node id');
223
- }
224
- get_location() {
225
- var e = this._data.view;
226
- return { x: e.abs_x, y: e.abs_y };
227
- }
228
- get_size() {
229
- var e = this._data.view;
230
- return { w: e.width, h: e.height };
231
- }
232
- static compare(e, t) {
233
- var i = e.index,
234
- n = t.index;
235
- return i >= 0 && n >= 0 ? i - n : -1 == i && -1 == n ? 0 : -1 == i ? 1 : -1 == n ? -1 : 0;
236
- }
237
- static inherited(e, t) {
238
- if (e && t) {
239
- if (e.id === t.id) return !0;
240
- if (e.isroot) return !0;
241
- for (var i = e.id, n = t; !n.isroot; ) if ((n = n.parent).id === i) return !0;
242
- }
243
- return !1;
244
- }
245
- static is_node(e) {
246
- return !!e && e instanceof l;
247
- }
248
- toObject(e, t = !1) {
249
- var i = e || {},
250
- n = i.id || 'id',
251
- o = i.topic || 'topic',
252
- s = i.children || 'children',
253
- r = i.direction || 'direction',
254
- a = i.expanded || 'expanded',
255
- d = {};
256
- if (
257
- ((d[n] = this.id),
258
- (d[o] = this.topic),
259
- (d[a] = this.expanded),
260
- this.parent && this.parent.isroot && (d[r] = -1 === this.direction ? 'left' : 'right'),
261
- null != this.data)
262
- )
263
- for (var l in this.data) d[l] = this.data[l];
264
- return (
265
- t && this.children.length > 0 && (d[s] = this.children.map(t => t.toObject(e, !0))), d
266
- );
267
- }
268
- }
269
- class h {
270
- constructor() {
271
- (this.name = null),
272
- (this.author = null),
273
- (this.version = null),
274
- (this.root = null),
275
- (this.selected = null),
276
- (this.nodes = {});
277
- }
278
- get_node(e) {
279
- return e in this.nodes
280
- ? this.nodes[e]
281
- : (s.warn('the node[id=' + e + '] can not be found'), null);
282
- }
283
- set_root(e, t, i) {
284
- return null == this.root
285
- ? ((this.root = new l(e, 0, t, i, !0)), this._put_node(this.root), this.root)
286
- : (s.error('root node is already exist'), null);
287
- }
288
- add_node(e, i, n, o, r, a, d) {
289
- if (!l.is_node(e)) return s.error('the parent_node ' + e + ' is not a node.'), null;
290
- var h = new l(i, d || -1, n, o, !1, e, e.direction, a);
291
- return (
292
- e.isroot && (h.direction = r || t.right),
293
- this._put_node(h)
294
- ? (e.children.push(h), this._update_index(e))
295
- : (s.error("fail, the node id '" + h.id + "' has been already exist."), (h = null)),
296
- h
297
- );
298
- }
299
- insert_node_before(e, t, i, n, o) {
300
- if (!l.is_node(e)) return s.error('the node_before ' + e + ' is not a node.'), null;
301
- var r = e.index - 0.5;
302
- return this.add_node(e.parent, t, i, n, o, !0, r);
303
- }
304
- get_node_before(e) {
305
- if (!l.is_node(e)) {
306
- var t = this.get_node(e);
307
- return t
308
- ? this.get_node_before(t)
309
- : (s.error('the node[id=' + e + '] can not be found.'), null);
310
- }
311
- if (e.isroot) return null;
312
- var i = e.index - 2;
313
- return i >= 0 ? e.parent.children[i] : null;
314
- }
315
- insert_node_after(e, t, i, n, o) {
316
- if (!l.is_node(e)) return s.error('the node_after ' + e + ' is not a node.'), null;
317
- var r = e.index + 0.5;
318
- return this.add_node(e.parent, t, i, n, o, !0, r);
319
- }
320
- get_node_after(e) {
321
- if (!l.is_node(e)) {
322
- var t = this.get_node(e);
323
- return t
324
- ? this.get_node_after(t)
325
- : (s.error('the node[id=' + e + '] can not be found.'), null);
326
- }
327
- if (e.isroot) return null;
328
- var i = e.index;
329
- return e.parent.children.length > i ? e.parent.children[i] : null;
330
- }
331
- move_node(e, t, i, n) {
332
- return l.is_node(e)
333
- ? (i || (i = e.parent.id), this._move_node(e, t, i, n))
334
- : (s.error('the parameter node ' + e + ' is not a node.'), null);
335
- }
336
- _flow_node_direction(e, t) {
337
- void 0 === t ? (t = e.direction) : (e.direction = t);
338
- for (var i = e.children.length; i--; ) this._flow_node_direction(e.children[i], t);
339
- }
340
- _move_node_internal(e, t) {
341
- if (e && t)
342
- if ('_last_' == t) (e.index = -1), this._update_index(e.parent);
343
- else if ('_first_' == t) (e.index = 0), this._update_index(e.parent);
344
- else {
345
- var i = t ? this.get_node(t) : null;
346
- null != i &&
347
- null != i.parent &&
348
- i.parent.id == e.parent.id &&
349
- ((e.index = i.index - 0.5), this._update_index(e.parent));
350
- }
351
- return e;
352
- }
353
- _move_node(e, i, n, o) {
354
- if (e && n) {
355
- var r = this.get_node(n);
356
- if (l.inherited(e, r)) return s.error('can not move a node to its children'), null;
357
- if (e.parent.id != n) {
358
- for (var a = e.parent.children, d = a.length; d--; )
359
- if (a[d].id == e.id) {
360
- a.splice(d, 1);
361
- break;
362
- }
363
- let t = e.parent;
364
- (e.parent = r), r.children.push(e), this._update_index(t);
365
- }
366
- e.parent.isroot
367
- ? o == t.left
368
- ? (e.direction = o)
369
- : (e.direction = t.right)
370
- : (e.direction = e.parent.direction),
371
- this._move_node_internal(e, i),
372
- this._flow_node_direction(e);
373
- }
374
- return e;
375
- }
376
- remove_node(e) {
377
- if (!l.is_node(e)) return s.error('the parameter node ' + e + ' is not a node.'), !1;
378
- if (e.isroot) return s.error('fail, can not remove root node'), !1;
379
- null != this.selected && this.selected.id == e.id && (this.selected = null);
380
- for (var t = e.children, i = t.length; i--; ) this.remove_node(t[i]);
381
- t.length = 0;
382
- for (var n = e.parent, o = n.children, r = o.length; r--; )
383
- if (o[r].id == e.id) {
384
- o.splice(r, 1);
385
- break;
386
- }
387
- for (var a in (delete this.nodes[e.id], e)) delete e[a];
388
- return (e = null), this._update_index(n), !0;
389
- }
390
- _put_node(e) {
391
- return e.id in this.nodes
392
- ? (s.warn("the node_id '" + e.id + "' has been already exist."), !1)
393
- : ((this.nodes[e.id] = e), !0);
394
- }
395
- _update_index(e) {
396
- if (e instanceof l) {
397
- e.children.sort(l.compare);
398
- for (var t = 0; t < e.children.length; t++) e.children[t].index = t + 1;
399
- }
400
- }
401
- }
402
- const _ = { name: 'jsMind', author: 'UmbraCi', version: e },
403
- u = {
404
- node_tree: {
405
- example: {
406
- meta: _,
407
- format: 'node_tree',
408
- data: { id: 'root', topic: 'jsMind node_tree example' },
409
- },
410
- get_mind: function (e, t) {
411
- var i = u.node_tree,
412
- n = new h();
413
- return (
414
- (n.name = e.meta.name),
415
- (n.author = e.meta.author),
416
- (n.version = e.meta.version),
417
- i._parse(n, e.data, t),
418
- n
419
- );
420
- },
421
- get_data: function (e, t) {
422
- var i = u.node_tree,
423
- n = {};
424
- return (
425
- (n.meta = { name: e.name, author: e.author, version: e.version }),
426
- (n.format = 'node_tree'),
427
- (n.data = i._build_node(e.root, t)),
428
- n
429
- );
430
- },
431
- _parse: function (e, t, i) {
432
- var n = u.node_tree,
433
- o = i || {},
434
- s = o.id || 'id',
435
- r = o.topic || 'topic',
436
- a = o.children || 'children',
437
- d = n._extract_data(t, i);
438
- if ((e.set_root(t[s], t[r], d), a in t))
439
- for (var l = t[a], h = 0; h < l.length; h++)
440
- n._extract_subnode(e, e.root, l[h], i);
441
- },
442
- _extract_data: function (e, t) {
443
- var i = t || {},
444
- n = i.id || 'id',
445
- o = i.topic || 'topic',
446
- s = i.children || 'children',
447
- r = i.direction || 'direction',
448
- a = i.expanded || 'expanded',
449
- d = {};
450
- for (var l in e) l != n && l != o && l != s && l != r && l != a && (d[l] = e[l]);
451
- return d;
452
- },
453
- _extract_subnode: function (e, i, n, o) {
454
- var s = u.node_tree,
455
- r = o || {},
456
- a = r.id || 'id',
457
- d = r.topic || 'topic',
458
- l = r.children || 'children',
459
- h = r.direction || 'direction',
460
- _ = r.expanded || 'expanded',
461
- c = s._extract_data(n, o),
462
- p = null;
463
- i.isroot && (p = 'left' == n[h] ? t.left : t.right);
464
- var v = e.add_node(i, n[a], n[d], c, p, n[_]);
465
- if (n[l])
466
- for (var g = n[l], f = 0; f < g.length; f++) s._extract_subnode(e, v, g[f], o);
467
- },
468
- _build_node: function (e, i) {
469
- var n = u.node_tree;
470
- if (e instanceof l) {
471
- var o = i || {},
472
- s = o.id || 'id',
473
- r = o.topic || 'topic',
474
- a = o.children || 'children',
475
- d = o.direction || 'direction',
476
- h = o.expanded || 'expanded',
477
- _ = {};
478
- if (
479
- ((_[s] = e.id),
480
- (_[r] = e.topic),
481
- (_[h] = e.expanded),
482
- e.parent &&
483
- e.parent.isroot &&
484
- (_[d] = e.direction == t.left ? 'left' : 'right'),
485
- null != e.data)
486
- ) {
487
- var c = e.data;
488
- for (var p in c) _[p] = c[p];
489
- }
490
- var v = e.children;
491
- if (v.length > 0) {
492
- _[a] = [];
493
- for (var g = 0; g < v.length; g++) _[a].push(n._build_node(v[g], i));
494
- }
495
- return _;
496
- }
497
- },
498
- },
499
- node_array: {
500
- example: {
501
- meta: _,
502
- format: 'node_array',
503
- data: [{ id: 'root', topic: 'jsMind node_array example', isroot: !0 }],
504
- },
505
- get_mind: function (e, t) {
506
- var i = u.node_array,
507
- n = new h();
508
- return (
509
- (n.name = e.meta.name),
510
- (n.author = e.meta.author),
511
- (n.version = e.meta.version),
512
- i._parse(n, e.data, t),
513
- n
514
- );
515
- },
516
- get_data: function (e, t) {
517
- var i = u.node_array,
518
- n = {};
519
- return (
520
- (n.meta = { name: e.name, author: e.author, version: e.version }),
521
- (n.format = 'node_array'),
522
- (n.data = []),
523
- i._array(e, n.data, t),
524
- n
525
- );
526
- },
527
- _parse: function (e, t, i) {
528
- var n = u.node_array,
529
- o = t.slice(0);
530
- o.reverse();
531
- var r = n._extract_root(e, o, i);
532
- r ? n._extract_subnode(e, r, o, i) : s.error('root node can not be found');
533
- },
534
- _extract_root: function (e, t, i) {
535
- for (
536
- var n = u.node_array,
537
- o = i || {},
538
- s = o.id || 'id',
539
- r = o.topic || 'topic',
540
- a = o.isroot || 'isroot',
541
- d = t.length;
542
- d--;
543
-
544
- )
545
- if (a in t[d] && t[d][a]) {
546
- var l = t[d],
547
- h = n._extract_data(l, i),
548
- _ = e.set_root(l[s], l[r], h);
549
- return t.splice(d, 1), _;
550
- }
551
- return null;
552
- },
553
- _extract_subnode: function (e, i, n, o) {
554
- for (
555
- var s = u.node_array,
556
- r = o || {},
557
- a = r.id || 'id',
558
- d = r.topic || 'topic',
559
- l = r.parentid || 'parentid',
560
- h = r.direction || 'direction',
561
- _ = r.expanded || 'expanded',
562
- c = n.length,
563
- p = null,
564
- v = null,
565
- g = 0;
566
- c--;
567
-
568
- )
569
- if ((p = n[c])[l] == i.id) {
570
- v = s._extract_data(p, o);
571
- var f = null,
572
- m = p[h];
573
- m && (f = 'left' == m ? t.left : t.right);
574
- var w = e.add_node(i, p[a], p[d], v, f, p[_]);
575
- n.splice(c, 1), g++;
576
- var y = s._extract_subnode(e, w, n, o);
577
- y > 0 && ((c = n.length), (g += y));
578
- }
579
- return g;
580
- },
581
- _extract_data: function (e, t) {
582
- var i = t || {},
583
- n = i.id || 'id',
584
- o = i.topic || 'topic',
585
- s = i.parentid || 'parentid',
586
- r = i.isroot || 'isroot',
587
- a = i.direction || 'direction',
588
- d = i.expanded || 'expanded',
589
- l = {};
590
- for (var h in e)
591
- h != n && h != o && h != s && h != r && h != a && h != d && (l[h] = e[h]);
592
- return l;
593
- },
594
- _array: function (e, t, i) {
595
- u.node_array._array_node(e.root, t, i);
596
- },
597
- _array_node: function (e, i, n) {
598
- var o = u.node_array;
599
- if (e instanceof l) {
600
- var s = n || {},
601
- r = s.id || 'id',
602
- a = s.topic || 'topic',
603
- d = s.parentid || 'parentid',
604
- h = s.isroot || 'isroot',
605
- _ = s.direction || 'direction',
606
- c = s.expanded || 'expanded',
607
- p = {};
608
- if (
609
- ((p[r] = e.id),
610
- (p[a] = e.topic),
611
- (p[c] = e.expanded),
612
- e.parent && (p[d] = e.parent.id),
613
- e.isroot && (p[h] = !0),
614
- e.parent &&
615
- e.parent.isroot &&
616
- (p[_] = e.direction == t.left ? 'left' : 'right'),
617
- null != e.data)
618
- ) {
619
- var v = e.data;
620
- for (var g in v) p[g] = v[g];
621
- }
622
- i.push(p);
623
- for (var f = e.children.length, m = 0; m < f; m++)
624
- o._array_node(e.children[m], i, n);
625
- }
626
- },
627
- },
628
- freemind: {
629
- example: {
630
- meta: _,
631
- format: 'freemind',
632
- data: '<map version="1.0.1"><node ID="root" TEXT="jsMind freemind example"/></map>',
633
- },
634
- get_mind: function (e, t) {
635
- var i = u.freemind,
636
- n = new h();
637
- (n.name = e.meta.name), (n.author = e.meta.author), (n.version = e.meta.version);
638
- var o = e.data,
639
- s = i._parse_xml(o),
640
- r = i._find_root(s);
641
- return i._load_node(n, null, r), n;
642
- },
643
- get_data: function (e, t) {
644
- var i = u.freemind,
645
- n = {};
646
- (n.meta = { name: e.name, author: e.author, version: e.version }),
647
- (n.format = 'freemind');
648
- var o = [];
649
- return (
650
- o.push('<map version="1.0.1">'),
651
- i._build_map(e.root, o),
652
- o.push('</map>'),
653
- (n.data = o.join('')),
654
- n
655
- );
656
- },
657
- _parse_xml: function (e) {
658
- var t = null;
659
- window.DOMParser
660
- ? (t = new DOMParser().parseFromString(e, 'text/xml'))
661
- : (((t = new ActiveXObject('Microsoft.XMLDOM')).async = !1), t.loadXML(e));
662
- return t;
663
- },
664
- _find_root: function (e) {
665
- for (var t = e.childNodes, i = null, n = null, o = 0; o < t.length; o++)
666
- if (1 == (n = t[o]).nodeType && 'map' == n.tagName) {
667
- i = n;
668
- break;
669
- }
670
- if (i) {
671
- var s = i.childNodes;
672
- i = null;
673
- for (o = 0; o < s.length; o++)
674
- if (1 == (n = s[o]).nodeType && 'node' == n.tagName) {
675
- i = n;
676
- break;
677
- }
678
- }
679
- return i;
680
- },
681
- _load_node: function (e, i, n) {
682
- var o = u.freemind,
683
- s = n.getAttribute('ID'),
684
- r = n.getAttribute('TEXT'),
685
- a = n.getAttribute('FOLDED');
686
- if (null == r)
687
- for (var d = n.childNodes, l = null, h = 0; h < d.length; h++)
688
- if (1 == (l = d[h]).nodeType && 'richcontent' === l.tagName) {
689
- r = l.textContent;
690
- break;
691
- }
692
- var _ = o._load_attributes(n),
693
- c = 'expanded' in _ ? 'true' == _.expanded : 'true' != a;
694
- delete _.expanded;
695
- var p = n.getAttribute('COLOR');
696
- p && (_['foreground-color'] = p);
697
- var v = n.getAttribute('BACKGROUND_COLOR');
698
- v && (_['background-color'] = v);
699
- var g = n.getAttribute('POSITION'),
700
- f = null;
701
- g && (f = 'left' == g ? t.left : t.right);
702
- var m = null;
703
- m = i ? e.add_node(i, s, r, _, f, c) : e.set_root(s, r, _);
704
- var w = n.childNodes,
705
- y = null;
706
- for (h = 0; h < w.length; h++)
707
- 1 == (y = w[h]).nodeType && 'node' == y.tagName && o._load_node(e, m, y);
708
- },
709
- _load_attributes: function (e) {
710
- for (var t = e.childNodes, i = null, n = {}, o = 0; o < t.length; o++)
711
- 1 == (i = t[o]).nodeType &&
712
- 'attribute' === i.tagName &&
713
- (n[i.getAttribute('NAME')] = i.getAttribute('VALUE'));
714
- return n;
715
- },
716
- _build_map: function (e, i) {
717
- var n = u.freemind,
718
- o = null,
719
- s = e.data;
720
- if (
721
- (e.parent && e.parent.isroot && (o = e.direction === t.left ? 'left' : 'right'),
722
- i.push('<node'),
723
- i.push(' ID="' + e.id + '"'),
724
- o && i.push(' POSITION="' + o + '"'),
725
- e.expanded || i.push(' FOLDED="true"'),
726
- s['foreground-color'] && i.push(' COLOR="' + s['foreground-color'] + '"'),
727
- s['background-color'] &&
728
- i.push(' BACKGROUND_COLOR="' + s['background-color'] + '"'),
729
- i.push(' TEXT="' + n._escape(e.topic) + '">'),
730
- null != s)
731
- )
732
- for (var r in s)
733
- 'foreground-color' !== r &&
734
- 'background-color' !== r &&
735
- i.push('<attribute NAME="' + r + '" VALUE="' + s[r] + '"/>');
736
- for (var a = e.children, d = 0; d < a.length; d++) n._build_map(a[d], i);
737
- i.push('</node>');
738
- },
739
- _escape: function (e) {
740
- return e
741
- .replace(/&/g, '&amp;')
742
- .replace(/</g, '&lt;')
743
- .replace(/>/g, '&gt;')
744
- .replace(/'/g, '&apos;')
745
- .replace(/"/g, '&quot;');
746
- },
747
- },
748
- text: {
749
- example: {
750
- meta: _,
751
- format: 'text',
752
- data: 'jsMind text example\n node1\n node1-sub\n node1-sub\n node2',
753
- },
754
- _line_regex: /\s*/,
755
- get_mind: function (e, t) {
756
- var i = u.text,
757
- n = new h();
758
- (n.name = e.meta.name), (n.author = e.meta.author), (n.version = e.meta.version);
759
- var o = e.data.split(/\n|\r/);
760
- return i._fill_nodes(n, o, 0, 0), n;
761
- },
762
- _fill_nodes: function (e, t) {
763
- let i = [],
764
- n = 0;
765
- for (; n < t.length; ) {
766
- let o = t[n],
767
- s = o.match(/\s*/)[0].length,
768
- r = o.substr(s);
769
- if (0 == s && i.length > 0)
770
- return void log.error('more than 1 root node was found: ' + r);
771
- if (s > i.length) return void log.error('a suspended node was found: ' + r);
772
- let d = i.length - s;
773
- for (; d--; ) i.pop();
774
- if (0 == s && 0 == i.length) {
775
- let t = e.set_root(a.uuid.newid(), r);
776
- i.push(t);
777
- } else {
778
- let t = e.add_node(i[s - 1], a.uuid.newid(), r, {}, null);
779
- i.push(t);
780
- }
781
- n++;
782
- }
783
- i.length = 0;
784
- },
785
- get_data: function (e) {
786
- var t = u.text,
787
- i = {};
788
- (i.meta = { name: e.name, author: e.author, version: e.version }),
789
- (i.format = 'text');
790
- let n = [];
791
- return t._build_lines(n, [e.root], 0), (i.data = n.join('\n')), i;
792
- },
793
- _build_lines: function (e, t, i) {
794
- let n = new Array(i + 1).join(' ');
795
- for (let o of t)
796
- e.push(n + o.topic), o.children && u.text._build_lines(e, o.children, i + 1);
797
- },
798
- },
799
- };
800
- class c {
801
- constructor(e) {
802
- this.jm = e;
803
- }
804
- init() {
805
- s.debug('data.init');
806
- }
807
- reset() {
808
- s.debug('data.reset');
809
- }
810
- load(e) {
811
- var t = null,
812
- i = null;
813
- t = 'object' == typeof e ? (e.format ? e.format : 'node_tree') : 'freemind';
814
- var n = this.jm.options.fieldNames;
815
- return (
816
- 'node_array' == t
817
- ? (i = u.node_array.get_mind(e, n))
818
- : 'node_tree' == t
819
- ? (i = u.node_tree.get_mind(e, n))
820
- : 'freemind' == t
821
- ? (i = u.freemind.get_mind(e, n))
822
- : 'text' == t
823
- ? (i = u.text.get_mind(e, n))
824
- : s.warn('unsupported format'),
825
- i
826
- );
827
- }
828
- get_data(e) {
829
- var t = null,
830
- i = this.jm.options.fieldNames;
831
- return (
832
- 'node_array' == e
833
- ? (t = u.node_array.get_data(this.jm.mind, i))
834
- : 'node_tree' == e
835
- ? (t = u.node_tree.get_data(this.jm.mind, i))
836
- : 'freemind' == e
837
- ? (t = u.freemind.get_data(this.jm.mind))
838
- : 'text' == e
839
- ? (t = u.text.get_data(this.jm.mind))
840
- : s.error('unsupported ' + e + ' format'),
841
- t
842
- );
843
- }
844
- }
845
- class p {
846
- constructor(e, t) {
847
- (this.opts = t),
848
- (this.jm = e),
849
- (this.isside = 'side' == this.opts.mode),
850
- (this.bounds = null),
851
- (this.cache_valid = !1);
852
- }
853
- init() {
854
- s.debug('layout.init');
855
- }
856
- reset() {
857
- s.debug('layout.reset'), (this.bounds = { n: 0, s: 0, w: 0, e: 0 });
858
- }
859
- calculate_next_child_direction(e) {
860
- if (this.isside) return t.right;
861
- for (var i = e.children || [], n = i.length, o = 0, s = 0; s < n; s++)
862
- i[s].direction === t.left ? o-- : o++;
863
- return n > 1 && o > 0 ? t.left : t.right;
864
- }
865
- layout() {
866
- s.debug('layout.layout'), this.layout_direction(), this.layout_offset();
867
- }
868
- layout_direction() {
869
- this._layout_direction_root();
870
- }
871
- _layout_direction_root() {
872
- var e = this.jm.mind.root,
873
- i = null;
874
- 'layout' in e._data ? (i = e._data.layout) : ((i = {}), (e._data.layout = i));
875
- var n = e.children,
876
- o = n.length;
877
- if (((i.direction = t.center), (i.side_index = 0), this.isside))
878
- for (var s = o; s--; ) this._layout_direction_side(n[s], t.right, s);
879
- else {
880
- s = o;
881
- for (var r = null; s--; )
882
- (r = n[s]).direction == t.left
883
- ? this._layout_direction_side(r, t.left, s)
884
- : this._layout_direction_side(r, t.right, s);
885
- }
886
- }
887
- _layout_direction_side(e, t, i) {
888
- var n = null;
889
- 'layout' in e._data ? (n = e._data.layout) : ((n = {}), (e._data.layout = n));
890
- var o = e.children,
891
- s = o.length;
892
- (n.direction = t), (n.side_index = i);
893
- for (var r = s; r--; ) this._layout_direction_side(o[r], t, r);
894
- }
895
- layout_offset() {
896
- var e = this.jm.mind.root,
897
- i = e._data.layout;
898
- (i.offset_x = 0), (i.offset_y = 0), (i.outer_height = 0);
899
- for (var n = e.children, o = n.length, s = [], r = [], a = null; o--; )
900
- (a = n[o])._data.layout.direction == t.right ? r.unshift(a) : s.unshift(a);
901
- (i.left_nodes = s),
902
- (i.right_nodes = r),
903
- (i.outer_height_left = this._layout_offset_subnodes(s)),
904
- (i.outer_height_right = this._layout_offset_subnodes(r)),
905
- (this.bounds.e = e._data.view.width / 2),
906
- (this.bounds.w = 0 - this.bounds.e),
907
- (this.bounds.n = 0),
908
- (this.bounds.s = Math.max(i.outer_height_left, i.outer_height_right));
909
- }
910
- _layout_offset_subnodes(e) {
911
- for (var t = 0, i = e.length, n = i, o = null, s = 0, r = null, a = 0, d = null; n--; )
912
- (r = (o = e[n])._data.layout),
913
- null == d && (d = o.parent._data),
914
- (s = this._layout_offset_subnodes(o.children)),
915
- o.expanded || ((s = 0), this.set_visible(o.children, !1)),
916
- (s = Math.max(o._data.view.height, s)),
917
- this._should_reserve_cousin_space(o) && (s += this.opts.cousin_space),
918
- (r.outer_height = s),
919
- (r.offset_y = a - s / 2),
920
- (r.offset_x =
921
- this.opts.hspace * r.direction +
922
- (d.view.width * (d.layout.direction + r.direction)) / 2),
923
- o.parent.isroot || (r.offset_x += this.opts.pspace * r.direction),
924
- (a = a - s - this.opts.vspace),
925
- (t += s);
926
- i > 1 && (t += this.opts.vspace * (i - 1)), (n = i);
927
- for (var l = t / 2; n--; ) (o = e[n])._data.layout.offset_y += l;
928
- return t;
929
- }
930
- _layout_offset_subnodes_height(e) {
931
- for (var t = 0, i = e.length, n = i, o = null, s = 0, r = null, a = 0, d = null; n--; )
932
- (r = (o = e[n])._data.layout),
933
- null == d && (d = o.parent._data),
934
- (s = this._layout_offset_subnodes_height(o.children)),
935
- o.expanded || (s = 0),
936
- (s = Math.max(o._data.view.height, s)),
937
- this._should_reserve_cousin_space(o) && (s += this.opts.cousin_space),
938
- (r.outer_height = s),
939
- (r.offset_y = a - s / 2),
940
- (a = a - s - this.opts.vspace),
941
- (t += s);
942
- i > 1 && (t += this.opts.vspace * (i - 1)), (n = i);
943
- for (var l = t / 2; n--; ) (o = e[n])._data.layout.offset_y += l;
944
- return t;
945
- }
946
- _should_reserve_cousin_space(e) {
947
- return e.children.length > 0 && e.parent.children.length > 1;
948
- }
949
- get_node_offset(e) {
950
- var t = e._data.layout,
951
- i = null;
952
- if (
953
- ('_offset_' in t && this.cache_valid
954
- ? (i = t._offset_)
955
- : ((i = { x: -1, y: -1 }), (t._offset_ = i)),
956
- -1 == i.x || -1 == i.y)
957
- ) {
958
- var n = t.offset_x,
959
- o = t.offset_y;
960
- if (!e.isroot) {
961
- var s = this.get_node_offset(e.parent);
962
- (n += s.x), (o += s.y);
963
- }
964
- (i.x = n), (i.y = o);
965
- }
966
- return i;
967
- }
968
- get_node_point(e) {
969
- var t = e._data.view,
970
- i = this.get_node_offset(e),
971
- n = {};
972
- return (
973
- (n.x = i.x + (t.width * (e._data.layout.direction - 1)) / 2),
974
- (n.y = i.y - t.height / 2),
975
- n
976
- );
977
- }
978
- get_node_point_in(e) {
979
- return this.get_node_offset(e);
980
- }
981
- get_node_point_out(e) {
982
- var t = e._data.layout,
983
- i = null;
984
- if (
985
- ('_pout_' in t && this.cache_valid
986
- ? (i = t._pout_)
987
- : ((i = { x: -1, y: -1 }), (t._pout_ = i)),
988
- -1 == i.x || -1 == i.y)
989
- )
990
- if (e.isroot) (i.x = 0), (i.y = 0);
991
- else {
992
- var n = e._data.view,
993
- o = this.get_node_offset(e);
994
- (i.x = o.x + (n.width + this.opts.pspace) * e._data.layout.direction), (i.y = o.y);
995
- }
996
- return i;
997
- }
998
- get_expander_point(e) {
999
- var i = this.get_node_point_out(e),
1000
- n = {};
1001
- return (
1002
- e._data.layout.direction == t.right ? (n.x = i.x - this.opts.pspace) : (n.x = i.x),
1003
- (n.y = i.y - Math.ceil(this.opts.pspace / 2)),
1004
- n
1005
- );
1006
- }
1007
- get_min_size() {
1008
- var e = this.jm.mind.nodes,
1009
- t = null,
1010
- i = null;
1011
- for (var n in e)
1012
- (t = e[n]),
1013
- (i = this.get_node_point_out(t)).x > this.bounds.e && (this.bounds.e = i.x),
1014
- i.x < this.bounds.w && (this.bounds.w = i.x);
1015
- return { w: this.bounds.e - this.bounds.w, h: this.bounds.s - this.bounds.n };
1016
- }
1017
- toggle_node(e) {
1018
- e.isroot || (e.expanded ? this.collapse_node(e) : this.expand_node(e));
1019
- }
1020
- expand_node(e) {
1021
- (e.expanded = !0),
1022
- this.part_layout(e),
1023
- this.set_visible(e.children, !0),
1024
- this.jm.invoke_event_handle(i.show, { evt: 'expand_node', data: [], node: e.id });
1025
- }
1026
- collapse_node(e) {
1027
- (e.expanded = !1),
1028
- this.part_layout(e),
1029
- this.set_visible(e.children, !1),
1030
- this.jm.invoke_event_handle(i.show, { evt: 'collapse_node', data: [], node: e.id });
1031
- }
1032
- expand_all() {
1033
- var e,
1034
- t = this.jm.mind.nodes,
1035
- i = 0;
1036
- for (var n in t) (e = t[n]).expanded || ((e.expanded = !0), i++);
1037
- if (i > 0) {
1038
- var o = this.jm.mind.root;
1039
- this.part_layout(o), this.set_visible(o.children, !0);
1040
- }
1041
- }
1042
- collapse_all() {
1043
- var e,
1044
- t = this.jm.mind.nodes,
1045
- i = 0;
1046
- for (var n in t) (e = t[n]).expanded && !e.isroot && ((e.expanded = !1), i++);
1047
- if (i > 0) {
1048
- var o = this.jm.mind.root;
1049
- this.part_layout(o), this.set_visible(o.children, !0);
1050
- }
1051
- }
1052
- expand_to_depth(e, t, i) {
1053
- if (!(e < 1))
1054
- for (var n = t || this.jm.mind.root.children, o = i || 1, s = n.length, r = null; s--; )
1055
- (r = n[s]),
1056
- o < e &&
1057
- (r.expanded || this.expand_node(r),
1058
- this.expand_to_depth(e, r.children, o + 1)),
1059
- o == e && r.expanded && this.collapse_node(r);
1060
- }
1061
- part_layout(e) {
1062
- var i = this.jm.mind.root;
1063
- if (i) {
1064
- var n = i._data.layout;
1065
- e.isroot
1066
- ? ((n.outer_height_right = this._layout_offset_subnodes_height(n.right_nodes)),
1067
- (n.outer_height_left = this._layout_offset_subnodes_height(n.left_nodes)))
1068
- : e._data.layout.direction == t.right
1069
- ? (n.outer_height_right = this._layout_offset_subnodes_height(n.right_nodes))
1070
- : (n.outer_height_left = this._layout_offset_subnodes_height(n.left_nodes)),
1071
- (this.bounds.s = Math.max(n.outer_height_left, n.outer_height_right)),
1072
- (this.cache_valid = !1);
1073
- } else s.warn('can not found root node');
1074
- }
1075
- set_visible(e, t) {
1076
- for (var i = e.length, n = null; i--; )
1077
- (n = e[i])._data.layout,
1078
- n.expanded ? this.set_visible(n.children, t) : this.set_visible(n.children, !1),
1079
- n.isroot || (n._data.layout.visible = t);
1080
- }
1081
- is_expand(e) {
1082
- return e.expanded;
1083
- }
1084
- is_visible(e) {
1085
- var t = e._data.layout;
1086
- return !('visible' in t && !t.visible);
1087
- }
1088
- }
1089
- class v {
1090
- constructor(e) {
1091
- (this.view = e),
1092
- (this.opts = e.opts),
1093
- (this.e_svg = v.c('svg')),
1094
- this.e_svg.setAttribute('class', 'jsmind'),
1095
- (this.size = { w: 0, h: 0 }),
1096
- (this.lines = []),
1097
- (this.line_drawing = { straight: this._line_to, curved: this._bezier_to }),
1098
- this.init_line_render();
1099
- }
1100
- static c(e) {
1101
- return r.d.createElementNS('http://www.w3.org/2000/svg', e);
1102
- }
1103
- init_line_render() {
1104
- 'function' == typeof this.opts.custom_line_render
1105
- ? (this.drawing = (e, t, i, n, o) => {
1106
- try {
1107
- this.opts.custom_line_render.call(this, {
1108
- ctx: e,
1109
- start_point: { x: t, y: i },
1110
- end_point: { x: n, y: o },
1111
- });
1112
- } catch (e) {
1113
- s.error('custom line renderer error: ', e);
1114
- }
1115
- })
1116
- : (this.drawing = this.line_drawing[this.opts.line_style] || this.line_drawing.curved);
1117
- }
1118
- element() {
1119
- return this.e_svg;
1120
- }
1121
- set_size(e, t) {
1122
- (this.size.w = e),
1123
- (this.size.h = t),
1124
- this.e_svg.setAttribute('width', e),
1125
- this.e_svg.setAttribute('height', t);
1126
- }
1127
- clear() {
1128
- for (var e = this.lines.length; e--; ) this.e_svg.removeChild(this.lines[e]);
1129
- this.lines.length = 0;
1130
- }
1131
- draw_line(e, t, i, n) {
1132
- var o = v.c('path');
1133
- o.setAttribute('stroke', n || this.opts.line_color),
1134
- o.setAttribute('stroke-width', this.opts.line_width),
1135
- o.setAttribute('fill', 'transparent'),
1136
- this.lines.push(o),
1137
- this.e_svg.appendChild(o),
1138
- this.drawing(o, t.x + i.x, t.y + i.y, e.x + i.x, e.y + i.y);
1139
- }
1140
- copy_to(e, t) {
1141
- var i = new Image();
1142
- (i.onload = function () {
1143
- e.drawImage(i, 0, 0), t && t();
1144
- }),
1145
- (i.src =
1146
- 'data:image/svg+xml;base64,' +
1147
- btoa(new XMLSerializer().serializeToString(this.e_svg)));
1148
- }
1149
- _bezier_to(e, t, i, n, o) {
1150
- e.setAttribute(
1151
- 'd',
1152
- 'M ' +
1153
- t +
1154
- ' ' +
1155
- i +
1156
- ' C ' +
1157
- (t + (2 * (n - t)) / 3) +
1158
- ' ' +
1159
- i +
1160
- ', ' +
1161
- t +
1162
- ' ' +
1163
- o +
1164
- ', ' +
1165
- n +
1166
- ' ' +
1167
- o
1168
- );
1169
- }
1170
- _line_to(e, t, i, n, o) {
1171
- e.setAttribute('d', 'M ' + t + ' ' + i + ' L ' + n + ' ' + o);
1172
- }
1173
- }
1174
- class g {
1175
- constructor(e) {
1176
- (this.opts = e.opts),
1177
- (this.e_canvas = r.c('canvas')),
1178
- (this.e_canvas.className = 'jsmind'),
1179
- (this.canvas_ctx = this.e_canvas.getContext('2d')),
1180
- (this.size = { w: 0, h: 0 }),
1181
- (this.line_drawing = { straight: this._line_to, curved: this._bezier_to }),
1182
- (this.dpr = e.device_pixel_ratio),
1183
- this.init_line_render();
1184
- }
1185
- init_line_render() {
1186
- 'function' == typeof this.opts.custom_line_render
1187
- ? (this.drawing = (e, t, i, n, o) => {
1188
- try {
1189
- this.opts.custom_line_render.call(this, {
1190
- ctx: e,
1191
- start_point: { x: t, y: i },
1192
- end_point: { x: n, y: o },
1193
- });
1194
- } catch (e) {
1195
- s.error('custom line render error: ', e);
1196
- }
1197
- })
1198
- : (this.drawing = this.line_drawing[this.opts.line_style] || this.line_drawing.curved);
1199
- }
1200
- element() {
1201
- return this.e_canvas;
1202
- }
1203
- set_size(e, t) {
1204
- (this.size.w = e),
1205
- (this.size.h = t),
1206
- this.e_canvas.width && this.e_canvas.height && this.canvas_ctx.scale
1207
- ? ((this.e_canvas.width = e * this.dpr),
1208
- (this.e_canvas.height = t * this.dpr),
1209
- (this.e_canvas.style.width = e + 'px'),
1210
- (this.e_canvas.style.height = t + 'px'),
1211
- this.canvas_ctx.scale(this.dpr, this.dpr))
1212
- : ((this.e_canvas.width = e), (this.e_canvas.height = t));
1213
- }
1214
- clear() {
1215
- this.canvas_ctx.clearRect(0, 0, this.size.w, this.size.h);
1216
- }
1217
- draw_line(e, t, i, n) {
1218
- var o = this.canvas_ctx;
1219
- (o.strokeStyle = n || this.opts.line_color),
1220
- (o.lineWidth = this.opts.line_width),
1221
- (o.lineCap = 'round'),
1222
- this.drawing(o, t.x + i.x, t.y + i.y, e.x + i.x, e.y + i.y);
1223
- }
1224
- copy_to(e, t) {
1225
- e.drawImage(this.e_canvas, 0, 0, this.size.w, this.size.h), t && t();
1226
- }
1227
- _bezier_to(e, t, i, n, o) {
1228
- e.beginPath(),
1229
- e.moveTo(t, i),
1230
- e.bezierCurveTo(t + (2 * (n - t)) / 3, i, t, o, n, o),
1231
- e.stroke();
1232
- }
1233
- _line_to(e, t, i, n, o) {
1234
- e.beginPath(), e.moveTo(t, i), e.lineTo(n, o), e.stroke();
1235
- }
1236
- }
1237
- class f {
1238
- constructor(e, t) {
1239
- (this.opts = t),
1240
- (this.jm = e),
1241
- (this.layout = e.layout),
1242
- (this.container = null),
1243
- (this.e_panel = null),
1244
- (this.e_nodes = null),
1245
- (this.size = { w: 0, h: 0 }),
1246
- (this.selected_node = null),
1247
- (this.editing_node = null),
1248
- (this.graph = null),
1249
- (this.render_node = t.custom_node_render
1250
- ? this._custom_node_render
1251
- : this._default_node_render),
1252
- (this.zoom_current = 1),
1253
- (this.device_pixel_ratio =
1254
- (this.opts.enable_device_pixel_ratio && r.w.devicePixelRatio) || 1),
1255
- (this._initialized = !1);
1256
- }
1257
- init() {
1258
- if (
1259
- (s.debug(this.opts),
1260
- s.debug('view.init'),
1261
- (this.container = r.i(this.opts.container)
1262
- ? this.opts.container
1263
- : r.g(this.opts.container)),
1264
- this.container)
1265
- ) {
1266
- var e;
1267
- (this.graph =
1268
- ((e = this), 'svg' === this.opts.engine.toLowerCase() ? new v(e) : new g(e))),
1269
- (this.e_panel = r.c('div')),
1270
- (this.e_nodes = r.c('jmnodes')),
1271
- (this.e_editor = r.c('input')),
1272
- (this.e_panel.className =
1273
- 'jsmind-inner jmnode-overflow-' + this.opts.node_overflow),
1274
- (this.e_panel.tabIndex = 1),
1275
- this.e_panel.appendChild(this.graph.element()),
1276
- this.e_panel.appendChild(this.e_nodes),
1277
- (this.e_editor.className = 'jsmind-editor'),
1278
- (this.e_editor.type = 'text');
1279
- var t = this;
1280
- r.on(this.e_editor, 'keydown', function (e) {
1281
- var i = e || event;
1282
- 13 == i.keyCode && (t.edit_node_end(), i.stopPropagation());
1283
- }),
1284
- r.on(this.e_editor, 'blur', function (e) {
1285
- t.edit_node_end();
1286
- }),
1287
- this.container.appendChild(this.e_panel),
1288
- this.container.offsetParent ||
1289
- new IntersectionObserver((e, t) => {
1290
- e[0].isIntersecting && (t.unobserve(this.e_panel), this.resize());
1291
- }).observe(this.e_panel);
1292
- } else s.error('the options.view.container was not be found in dom');
1293
- }
1294
- add_event(e, t, i, n) {
1295
- let o = n ? this.e_panel : this.e_nodes;
1296
- r.on(o, t, function (t) {
1297
- var n = t || event;
1298
- i.call(e, n);
1299
- });
1300
- }
1301
- get_binded_nodeid(e) {
1302
- if (null == e) return null;
1303
- var t = e.tagName.toLowerCase();
1304
- return 'jmnode' == t || 'jmexpander' == t
1305
- ? e.getAttribute('nodeid')
1306
- : 'jmnodes' == t || 'body' == t || 'html' == t
1307
- ? null
1308
- : this.get_binded_nodeid(e.parentElement);
1309
- }
1310
- is_node(e) {
1311
- if (null == e) return !1;
1312
- var t = e.tagName.toLowerCase();
1313
- return (
1314
- 'jmnode' == t ||
1315
- ('jmnodes' != t && 'body' != t && 'html' != t && this.is_node(e.parentElement))
1316
- );
1317
- }
1318
- is_expander(e) {
1319
- return 'jmexpander' == e.tagName.toLowerCase();
1320
- }
1321
- reset() {
1322
- s.debug('view.reset'),
1323
- (this.selected_node = null),
1324
- this.clear_lines(),
1325
- this.clear_nodes(),
1326
- this.reset_theme();
1327
- }
1328
- reset_theme() {
1329
- var e = this.jm.options.theme;
1330
- this.e_nodes.className = e ? 'theme-' + e : '';
1331
- }
1332
- reset_custom_style() {
1333
- var e = this.jm.mind.nodes;
1334
- for (var t in e) this.reset_node_custom_style(e[t]);
1335
- }
1336
- load() {
1337
- s.debug('view.load'),
1338
- this.setup_canvas_draggable(this.opts.draggable),
1339
- this.init_nodes(),
1340
- (this._initialized = !0);
1341
- }
1342
- expand_size() {
1343
- var e = this.layout.get_min_size(),
1344
- t = e.w + 2 * this.opts.hmargin,
1345
- i = e.h + 2 * this.opts.vmargin,
1346
- n = this.e_panel.clientWidth,
1347
- o = this.e_panel.clientHeight;
1348
- n < t && (n = t), o < i && (o = i), (this.size.w = n), (this.size.h = o);
1349
- }
1350
- init_nodes_size(e) {
1351
- var t = e._data.view;
1352
- (t.width = t.element.clientWidth), (t.height = t.element.clientHeight);
1353
- }
1354
- init_nodes() {
1355
- var e = this.jm.mind.nodes,
1356
- t = r.d.createDocumentFragment();
1357
- for (var i in e) this.create_node_element(e[i], t);
1358
- this.e_nodes.appendChild(t),
1359
- this.run_in_c11y_mode_if_needed(() => {
1360
- for (var t in e) this.init_nodes_size(e[t]);
1361
- });
1362
- }
1363
- add_node(e) {
1364
- this.create_node_element(e, this.e_nodes),
1365
- this.run_in_c11y_mode_if_needed(() => {
1366
- this.init_nodes_size(e);
1367
- });
1368
- }
1369
- run_in_c11y_mode_if_needed(e) {
1370
- this.container.offsetParent
1371
- ? e()
1372
- : (s.warn(
1373
- 'init nodes in compatibility mode. because the container or its parent has style {display:none}. '
1374
- ),
1375
- (this.e_panel.style.position = 'absolute'),
1376
- (this.e_panel.style.top = '-100000'),
1377
- r.d.body.appendChild(this.e_panel),
1378
- e(),
1379
- this.container.appendChild(this.e_panel),
1380
- (this.e_panel.style.position = null),
1381
- (this.e_panel.style.top = null));
1382
- }
1383
- create_node_element(e, t) {
1384
- var i = null;
1385
- 'view' in e._data ? (i = e._data.view) : ((i = {}), (e._data.view = i));
1386
- var n = r.c('jmnode');
1387
- if (e.isroot) n.className = 'root';
1388
- else {
1389
- var o = r.c('jmexpander');
1390
- r.t(o, '-'),
1391
- o.setAttribute('nodeid', e.id),
1392
- (o.style.visibility = 'hidden'),
1393
- t.appendChild(o),
1394
- (i.expander = o);
1395
- }
1396
- e.topic && this.render_node(n, e),
1397
- n.setAttribute('nodeid', e.id),
1398
- (n.style.visibility = 'hidden'),
1399
- this._reset_node_custom_style(n, e.data),
1400
- t.appendChild(n),
1401
- (i.element = n);
1402
- }
1403
- remove_node(e) {
1404
- null != this.selected_node && this.selected_node.id == e.id && (this.selected_node = null),
1405
- null != this.editing_node &&
1406
- this.editing_node.id == e.id &&
1407
- (e._data.view.element.removeChild(this.e_editor), (this.editing_node = null));
1408
- for (var t = e.children, i = t.length; i--; ) this.remove_node(t[i]);
1409
- if (e._data.view) {
1410
- var n = e._data.view.element,
1411
- o = e._data.view.expander;
1412
- this.e_nodes.removeChild(n),
1413
- this.e_nodes.removeChild(o),
1414
- (e._data.view.element = null),
1415
- (e._data.view.expander = null);
1416
- }
1417
- }
1418
- update_node(e) {
1419
- var t = e._data.view,
1420
- i = t.element;
1421
- if ((e.topic && this.render_node(i, e), this.layout.is_visible(e)))
1422
- (t.width = i.clientWidth), (t.height = i.clientHeight);
1423
- else {
1424
- let e = i.getAttribute('style');
1425
- (i.style = 'visibility: visible; left:0; top:0;'),
1426
- (t.width = i.clientWidth),
1427
- (t.height = i.clientHeight),
1428
- (i.style = e);
1429
- }
1430
- }
1431
- select_node(e) {
1432
- if (this.selected_node) {
1433
- var t = this.selected_node._data.view.element;
1434
- (t.className = t.className.replace(/\s*selected\b/i, '')),
1435
- this.restore_selected_node_custom_style(this.selected_node);
1436
- }
1437
- e &&
1438
- ((this.selected_node = e),
1439
- (e._data.view.element.className += ' selected'),
1440
- this.clear_selected_node_custom_style(e));
1441
- }
1442
- select_clear() {
1443
- this.select_node(null);
1444
- }
1445
- get_editing_node() {
1446
- return this.editing_node;
1447
- }
1448
- is_editing() {
1449
- return !!this.editing_node;
1450
- }
1451
- edit_node_begin(e) {
1452
- if (e.topic) {
1453
- null != this.editing_node && this.edit_node_end(), (this.editing_node = e);
1454
- var t = e._data.view.element,
1455
- i = e.topic,
1456
- n = getComputedStyle(t);
1457
- (this.e_editor.value = i),
1458
- (this.e_editor.style.width =
1459
- t.clientWidth -
1460
- parseInt(n.getPropertyValue('padding-left')) -
1461
- parseInt(n.getPropertyValue('padding-right')) +
1462
- 'px'),
1463
- (t.innerHTML = ''),
1464
- t.appendChild(this.e_editor),
1465
- (t.style.zIndex = 5),
1466
- this.e_editor.focus(),
1467
- this.e_editor.select();
1468
- } else s.warn("don't edit image nodes");
1469
- }
1470
- edit_node_end() {
1471
- if (null != this.editing_node) {
1472
- var e = this.editing_node;
1473
- this.editing_node = null;
1474
- var t = e._data.view.element,
1475
- i = this.e_editor.value;
1476
- (t.style.zIndex = 'auto'),
1477
- t.removeChild(this.e_editor),
1478
- a.text.is_empty(i) || e.topic === i
1479
- ? this.render_node(t, e)
1480
- : this.jm.update_node(e.id, i);
1481
- }
1482
- this.e_panel.focus();
1483
- }
1484
- get_view_offset() {
1485
- var e = this.layout.bounds;
1486
- return { x: (this.size.w - e.e - e.w) / 2, y: this.size.h / 2 };
1487
- }
1488
- resize() {
1489
- this.graph.set_size(1, 1),
1490
- (this.e_nodes.style.width = '1px'),
1491
- (this.e_nodes.style.height = '1px'),
1492
- this.expand_size(),
1493
- this._show();
1494
- }
1495
- _show() {
1496
- this.graph.set_size(this.size.w, this.size.h),
1497
- (this.e_nodes.style.width = this.size.w + 'px'),
1498
- (this.e_nodes.style.height = this.size.h + 'px'),
1499
- this.show_nodes(),
1500
- this.show_lines(),
1501
- this.jm.invoke_event_handle(i.resize, { data: [] });
1502
- }
1503
- zoom_in(e) {
1504
- return this.set_zoom(this.zoom_current + this.opts.zoom.step, e);
1505
- }
1506
- zoom_out(e) {
1507
- return this.set_zoom(this.zoom_current - this.opts.zoom.step, e);
1508
- }
1509
- set_zoom(e, t) {
1510
- if (e < this.opts.zoom.min || e > this.opts.zoom.max) return !1;
1511
- let i = this.e_panel.getBoundingClientRect();
1512
- if (
1513
- e < 1 &&
1514
- e < this.zoom_current &&
1515
- this.size.w * e < i.width &&
1516
- this.size.h * e < i.height
1517
- )
1518
- return !1;
1519
- let n = t ? { x: t.x - i.x, y: t.y - i.y } : { x: i.width / 2, y: i.height / 2 },
1520
- o = ((this.e_panel.scrollLeft + n.x) * e) / this.zoom_current - n.x,
1521
- s = ((this.e_panel.scrollTop + n.y) * e) / this.zoom_current - n.y;
1522
- this.zoom_current = e;
1523
- for (var r = 0; r < this.e_panel.children.length; r++)
1524
- this.e_panel.children[r].style.zoom = e;
1525
- return this._show(), (this.e_panel.scrollLeft = o), (this.e_panel.scrollTop = s), !0;
1526
- }
1527
- show(e) {
1528
- s.debug(`view.show: {keep_center: ${e}}`),
1529
- this.expand_size(),
1530
- this._show(),
1531
- e && this.center_node(this.jm.mind.root);
1532
- }
1533
- relayout() {
1534
- this.expand_size(), this._show();
1535
- }
1536
- save_location(e) {
1537
- var t = e._data.view;
1538
- t._saved_location = {
1539
- x: parseInt(t.element.style.left) - this.e_panel.scrollLeft,
1540
- y: parseInt(t.element.style.top) - this.e_panel.scrollTop,
1541
- };
1542
- }
1543
- restore_location(e) {
1544
- var t = e._data.view;
1545
- (this.e_panel.scrollLeft = parseInt(t.element.style.left) - t._saved_location.x),
1546
- (this.e_panel.scrollTop = parseInt(t.element.style.top) - t._saved_location.y);
1547
- }
1548
- clear_nodes() {
1549
- var e = this.jm.mind;
1550
- if (null != e) {
1551
- var t = e.nodes,
1552
- i = null;
1553
- for (var n in t) ((i = t[n])._data.view.element = null), (i._data.view.expander = null);
1554
- this.e_nodes.innerHTML = '';
1555
- }
1556
- }
1557
- show_nodes() {
1558
- var e = this.jm.mind.nodes,
1559
- t = null,
1560
- i = null,
1561
- n = null,
1562
- o = null,
1563
- s = this.get_view_offset();
1564
- for (var r in e)
1565
- (i = (o = (t = e[r])._data.view).element),
1566
- this.layout.is_visible(t)
1567
- ? (this.reset_node_custom_style(t),
1568
- (n = this.layout.get_node_point(t)),
1569
- (o.abs_x = s.x + n.x),
1570
- (o.abs_y = s.y + n.y),
1571
- (i.style.left = s.x + n.x + 'px'),
1572
- (i.style.top = s.y + n.y + 'px'),
1573
- (i.style.display = ''),
1574
- (i.style.visibility = 'visible'),
1575
- this._show_expander(t, s))
1576
- : ((i.style.display = 'none'), (o.expander.style.display = 'none'));
1577
- }
1578
- _show_expander(e, t) {
1579
- if (e.isroot) return;
1580
- var i = e._data.view.expander;
1581
- if (0 == e.children.length)
1582
- return (i.style.display = 'none'), void (i.style.visibility = 'hidden');
1583
- let n = this._get_expander_text(e);
1584
- r.t(i, n);
1585
- let o = this.layout.get_expander_point(e);
1586
- (i.style.left = t.x + o.x + 'px'),
1587
- (i.style.top = t.y + o.y + 'px'),
1588
- (i.style.display = ''),
1589
- (i.style.visibility = 'visible');
1590
- }
1591
- _get_expander_text(e) {
1592
- let t = this.opts.expander_style ? this.opts.expander_style.toLowerCase() : 'char';
1593
- return 'number' === t
1594
- ? e.children.length > 99
1595
- ? '...'
1596
- : e.children.length
1597
- : 'char' === t
1598
- ? e.expanded
1599
- ? '-'
1600
- : '+'
1601
- : void 0;
1602
- }
1603
- _default_node_render(e, t) {
1604
- this.opts.support_html ? r.h(e, t.topic) : r.t(e, t.topic);
1605
- }
1606
- _custom_node_render(e, t) {
1607
- this.opts.custom_node_render(this.jm, e, t) || this._default_node_render(e, t);
1608
- }
1609
- reset_node_custom_style(e) {
1610
- this._reset_node_custom_style(e._data.view.element, e.data);
1611
- }
1612
- _reset_node_custom_style(e, t) {
1613
- if (
1614
- ('background-color' in t && (e.style.backgroundColor = t['background-color']),
1615
- 'foreground-color' in t && (e.style.color = t['foreground-color']),
1616
- 'width' in t && (e.style.width = t.width + 'px'),
1617
- 'height' in t && (e.style.height = t.height + 'px'),
1618
- 'font-size' in t && (e.style.fontSize = t['font-size'] + 'px'),
1619
- 'font-weight' in t && (e.style.fontWeight = t['font-weight']),
1620
- 'font-style' in t && (e.style.fontStyle = t['font-style']),
1621
- 'background-image' in t)
1622
- ) {
1623
- var i = t['background-image'];
1624
- if (i.startsWith('data') && t.width && t.height) {
1625
- var n = new Image();
1626
- (n.onload = function () {
1627
- var t = r.c('canvas');
1628
- (t.width = e.clientWidth), (t.height = e.clientHeight);
1629
- if (t.getContext) {
1630
- t.getContext('2d').drawImage(this, 2, 2, e.clientWidth, e.clientHeight);
1631
- var i = t.toDataURL();
1632
- e.style.backgroundImage = 'url(' + i + ')';
1633
- }
1634
- }),
1635
- (n.src = i);
1636
- } else e.style.backgroundImage = 'url(' + i + ')';
1637
- (e.style.backgroundSize = '99%'),
1638
- 'background-rotation' in t &&
1639
- (e.style.transform = 'rotate(' + t['background-rotation'] + 'deg)');
1640
- }
1641
- }
1642
- restore_selected_node_custom_style(e) {
1643
- var t = e._data.view.element,
1644
- i = e.data;
1645
- 'background-color' in i && (t.style.backgroundColor = i['background-color']),
1646
- 'foreground-color' in i && (t.style.color = i['foreground-color']);
1647
- }
1648
- clear_selected_node_custom_style(e) {
1649
- var t = e._data.view.element;
1650
- (t.style.backgroundColor = ''), (t.style.color = '');
1651
- }
1652
- clear_lines() {
1653
- this.graph.clear();
1654
- }
1655
- show_lines() {
1656
- this.clear_lines();
1657
- var e = this.jm.mind.nodes,
1658
- t = null,
1659
- i = null,
1660
- n = null,
1661
- o = null,
1662
- s = this.get_view_offset();
1663
- for (var r in e)
1664
- (t = e[r]).isroot ||
1665
- (this.layout.is_visible(t) &&
1666
- ((i = this.layout.get_node_point_in(t)),
1667
- (n = this.layout.get_node_point_out(t.parent)),
1668
- (o = t.data['leading-line-color']),
1669
- this.graph.draw_line(n, i, s, o)));
1670
- }
1671
- setup_canvas_draggable(e) {
1672
- if (((this.opts.draggable = e), !this._initialized)) {
1673
- let e,
1674
- t,
1675
- i = !1;
1676
- this.opts.hide_scrollbars_when_draggable && (this.e_panel.style = 'overflow: hidden'),
1677
- r.on(this.container, 'mousedown', n => {
1678
- this.opts.draggable && ((i = !0), (e = n.clientX), (t = n.clientY));
1679
- }),
1680
- r.on(this.container, 'mouseup', () => {
1681
- i = !1;
1682
- }),
1683
- r.on(this.container, 'mousemove', n => {
1684
- this.opts.draggable &&
1685
- i &&
1686
- (this.e_panel.scrollBy(e - n.clientX, t - n.clientY),
1687
- (e = n.clientX),
1688
- (t = n.clientY));
1689
- });
1690
- }
1691
- }
1692
- center_node(e) {
1693
- if (!this.layout.is_visible(e))
1694
- return s.warn('can not scroll to the node, because it is invisible'), !1;
1695
- let t = e._data.view,
1696
- i = this.e_panel.getBoundingClientRect(),
1697
- n = t.abs_x + t.width / 2,
1698
- o = t.abs_y + t.height / 2;
1699
- return (
1700
- this.e_panel.scrollTo(
1701
- n * this.zoom_current - i.width / 2,
1702
- o * this.zoom_current - i.height / 2
1703
- ),
1704
- !0
1705
- );
1706
- }
1707
- zoomIn(e) {
1708
- return s.warn('please use zoom_in instead'), this.zoom_in(e);
1709
- }
1710
- zoomOut(e) {
1711
- return s.warn('please use zoom_out instead'), this.zoom_out(e);
1712
- }
1713
- setZoom(e, t) {
1714
- return s.warn('please use set_zoom instead'), this.set_zoom(e, t);
1715
- }
1716
- }
1717
- class m {
1718
- constructor(e, t) {
1719
- (this.jm = e),
1720
- (this.opts = t),
1721
- (this.mapping = t.mapping),
1722
- (this.handles = t.handles),
1723
- (this._newid = null),
1724
- (this._mapping = {});
1725
- }
1726
- init() {
1727
- for (var e in (r.on(this.jm.view.e_panel, 'keydown', this.handler.bind(this)),
1728
- (this.handles.addchild = this.handle_addchild),
1729
- (this.handles.addbrother = this.handle_addbrother),
1730
- (this.handles.editnode = this.handle_editnode),
1731
- (this.handles.delnode = this.handle_delnode),
1732
- (this.handles.toggle = this.handle_toggle),
1733
- (this.handles.up = this.handle_up),
1734
- (this.handles.down = this.handle_down),
1735
- (this.handles.left = this.handle_left),
1736
- (this.handles.right = this.handle_right),
1737
- this.mapping))
1738
- if (this.mapping[e] && e in this.handles) {
1739
- let t = this.mapping[e];
1740
- Array.isArray(t) || (t = [t]);
1741
- for (let i of t) this._mapping[i] = this.handles[e];
1742
- }
1743
- 'function' == typeof this.opts.id_generator
1744
- ? (this._newid = this.opts.id_generator)
1745
- : (this._newid = a.uuid.newid);
1746
- }
1747
- enable_shortcut() {
1748
- this.opts.enable = !0;
1749
- }
1750
- disable_shortcut() {
1751
- this.opts.enable = !1;
1752
- }
1753
- handler(e) {
1754
- if ((9 == e.which && e.preventDefault(), !this.jm.view.is_editing())) {
1755
- var t = e || event;
1756
- if (!this.opts.enable) return !0;
1757
- var i =
1758
- t.keyCode +
1759
- (t.metaKey << 13) +
1760
- (t.ctrlKey << 12) +
1761
- (t.altKey << 11) +
1762
- (t.shiftKey << 10);
1763
- i in this._mapping && this._mapping[i].call(this, this.jm, e);
1764
- }
1765
- }
1766
- handle_addchild(e, t) {
1767
- var i = e.get_selected_node();
1768
- if (i) {
1769
- var n = this._newid();
1770
- e.add_node(i, n, 'New Node') && (e.select_node(n), e.begin_edit(n));
1771
- }
1772
- }
1773
- handle_addbrother(e, t) {
1774
- var i = e.get_selected_node();
1775
- if (i && !i.isroot) {
1776
- var n = this._newid();
1777
- e.insert_node_after(i, n, 'New Node') && (e.select_node(n), e.begin_edit(n));
1778
- }
1779
- }
1780
- handle_editnode(e, t) {
1781
- var i = e.get_selected_node();
1782
- i && e.begin_edit(i);
1783
- }
1784
- handle_delnode(e, t) {
1785
- var i = e.get_selected_node();
1786
- i && !i.isroot && (e.select_node(i.parent), e.remove_node(i));
1787
- }
1788
- handle_toggle(e, t) {
1789
- var i = t || event,
1790
- n = e.get_selected_node();
1791
- n && (e.toggle_node(n.id), i.stopPropagation(), i.preventDefault());
1792
- }
1793
- handle_up(e, t) {
1794
- var i = t || event,
1795
- n = e.get_selected_node();
1796
- if (n) {
1797
- var o = e.find_node_before(n);
1798
- if (!o) {
1799
- var s = e.find_node_before(n.parent);
1800
- s && s.children.length > 0 && (o = s.children[s.children.length - 1]);
1801
- }
1802
- o && e.select_node(o), i.stopPropagation(), i.preventDefault();
1803
- }
1804
- }
1805
- handle_down(e, t) {
1806
- var i = t || event,
1807
- n = e.get_selected_node();
1808
- if (n) {
1809
- var o = e.find_node_after(n);
1810
- if (!o) {
1811
- var s = e.find_node_after(n.parent);
1812
- s && s.children.length > 0 && (o = s.children[0]);
1813
- }
1814
- o && e.select_node(o), i.stopPropagation(), i.preventDefault();
1815
- }
1816
- }
1817
- handle_left(e, i) {
1818
- this._handle_direction(e, i, t.left);
1819
- }
1820
- handle_right(e, i) {
1821
- this._handle_direction(e, i, t.right);
1822
- }
1823
- _handle_direction(e, t, i) {
1824
- var n = t || event,
1825
- o = e.get_selected_node(),
1826
- s = null;
1827
- if (o) {
1828
- if (o.isroot) {
1829
- for (var r = o.children, a = [], d = 0; d < r.length; d++)
1830
- r[d].direction === i && a.push(d);
1831
- s = r[a[Math.floor((a.length - 1) / 2)]];
1832
- } else if (o.direction === i) {
1833
- var l = (a = o.children).length;
1834
- l > 0 && (s = a[Math.floor((l - 1) / 2)]);
1835
- } else s = o.parent;
1836
- s && e.select_node(s), n.stopPropagation(), n.preventDefault();
1837
- }
1838
- }
1839
- }
1840
- const w = { plugins: [] };
1841
- function y(e) {
1842
- if (!(e instanceof x))
1843
- throw new Error('can not register plugin, it is not an instance of Plugin');
1844
- if (w.plugins.map(e => e.name).includes(e.name))
1845
- throw new Error('can not register plugin ' + e.name + ': plugin name already exist');
1846
- w.plugins.push(e);
1847
- }
1848
- function b(e, t) {
1849
- r.w.setTimeout(function () {
1850
- !(function (e, t) {
1851
- w.plugins.forEach(i => i.fn_init(e, t[i.name]));
1852
- })(e, t);
1853
- }, 0);
1854
- }
1855
- class x {
1856
- constructor(e, t) {
1857
- if (!e) throw new Error('plugin must has a name');
1858
- if (!t || 'function' != typeof t) throw new Error('plugin must has an init function');
1859
- (this.name = e), (this.fn_init = t);
1860
- }
1861
- }
1862
- class z {
1863
- constructor(e) {
1864
- (this.jm = e), (this.plugins = new Map());
1865
- }
1866
- initPreloadPlugins() {
1867
- const e = this.jm.constructor.enhancedPluginList.filter(e => e.preload);
1868
- s.info('Initializing ' + e.length + ' preload plugins'),
1869
- e.forEach(e => {
1870
- this._initPlugin(e);
1871
- });
1872
- }
1873
- initNormalPlugins() {
1874
- const e = this.jm.constructor.enhancedPluginList.filter(e => !e.preload);
1875
- s.info('Initializing ' + e.length + ' normal plugins'),
1876
- e.forEach(e => {
1877
- this._initPlugin(e);
1878
- });
1879
- }
1880
- _initPlugin(e) {
1881
- try {
1882
- const { PluginClass: t, pluginOpt: i } = e;
1883
- if (!t.instanceName)
1884
- throw new Error('Plugin ' + t.name + ' must define static instanceName');
1885
- this.plugins.has(t.instanceName) &&
1886
- s.warn('Plugin ' + t.instanceName + ' already exists, will be replaced');
1887
- const n = new t({ jm: this.jm, pluginOpt: i || {} });
1888
- this.plugins.set(t.instanceName, n),
1889
- (this.jm[t.instanceName] = n),
1890
- (e.instance = n),
1891
- s.info('Enhanced plugin ' + t.instanceName + ' initialized');
1892
- } catch (t) {
1893
- s.error('Failed to initialize plugin ' + e.PluginClass.name + ':', t);
1894
- }
1895
- }
1896
- removePlugin(e) {
1897
- const t = e.instanceName;
1898
- if (!t) return;
1899
- const i = this.plugins.get(t);
1900
- if (i)
1901
- try {
1902
- 'function' == typeof i.beforePluginRemove && i.beforePluginRemove(),
1903
- this.plugins.delete(t),
1904
- delete this.jm[t];
1905
- const n = this.jm.constructor.enhancedPluginList,
1906
- o = n.findIndex(t => t.PluginClass === e);
1907
- -1 !== o && n.splice(o, 1), s.info('Enhanced plugin ' + t + ' removed');
1908
- } catch (e) {
1909
- s.error('Failed to remove plugin ' + t + ':', e);
1910
- }
1911
- }
1912
- destroyAllPlugins() {
1913
- this.plugins.forEach((e, t) => {
1914
- try {
1915
- 'function' == typeof e.beforePluginDestroy && e.beforePluginDestroy();
1916
- } catch (e) {
1917
- s.error('Failed to destroy plugin ' + t + ':', e);
1918
- }
1919
- }),
1920
- this.plugins.clear();
1921
- }
1922
- getPlugin(e) {
1923
- return this.plugins.get(e);
1924
- }
1925
- }
1926
- class j {
1927
- static instanceName = '';
1928
- static preload = !1;
1929
- constructor({ jm: e, pluginOpt: t }) {
1930
- (this.jm = e), (this.options = t || {});
1931
- }
1932
- beforePluginRemove() {}
1933
- beforePluginDestroy() {
1934
- this.beforePluginRemove();
1935
- }
1936
- }
1937
- class k {
1938
- static mind = h;
1939
- static node = l;
1940
- static direction = t;
1941
- static event_type = i;
1942
- static $ = r;
1943
- static plugin = x;
1944
- static register_plugin = y;
1945
- static util = a;
1946
- static enhanced_plugin = j;
1947
- static enhancedPluginList = [];
1948
- static usePlugin(e, t = {}) {
1949
- if (k.enhancedPluginList.some(t => t.PluginClass === e))
1950
- return s.warn('Plugin ' + e.name + ' already registered'), k;
1951
- if (!e.instanceName)
1952
- throw new Error('Plugin ' + e.name + ' must define static instanceName');
1953
- return (
1954
- k.enhancedPluginList.push({
1955
- PluginClass: e,
1956
- instanceName: e.instanceName,
1957
- preload: e.preload || !1,
1958
- pluginOpt: t,
1959
- instance: null,
1960
- }),
1961
- k
1962
- );
1963
- }
1964
- static hasEnhancedPlugin(e) {
1965
- return k.enhancedPluginList.some(t => t.PluginClass === e);
1966
- }
1967
- constructor(t) {
1968
- (k.current = this),
1969
- (this.options = (function (e) {
1970
- var t = {};
1971
- if ((a.json.merge(t, d), a.json.merge(t, e), !t.container))
1972
- throw new Error('the options.container should not be null or empty.');
1973
- return t;
1974
- })(t)),
1975
- s.level(n[this.options.log_level]),
1976
- (this.version = e),
1977
- (this.initialized = !1),
1978
- (this.mind = null),
1979
- (this.event_handles = []),
1980
- this.init();
1981
- }
1982
- init() {
1983
- if (!this.initialized) {
1984
- (this.initialized = !0),
1985
- (this.enhancedPluginManager = new z(this)),
1986
- this.enhancedPluginManager.initPreloadPlugins();
1987
- var e = {
1988
- mode: this.options.mode,
1989
- hspace: this.options.layout.hspace,
1990
- vspace: this.options.layout.vspace,
1991
- pspace: this.options.layout.pspace,
1992
- cousin_space: this.options.layout.cousin_space,
1993
- },
1994
- t = {
1995
- container: this.options.container,
1996
- support_html: this.options.support_html,
1997
- engine: this.options.view.engine,
1998
- enable_device_pixel_ratio: this.options.view.enable_device_pixel_ratio,
1999
- hmargin: this.options.view.hmargin,
2000
- vmargin: this.options.view.vmargin,
2001
- line_width: this.options.view.line_width,
2002
- line_color: this.options.view.line_color,
2003
- line_style: this.options.view.line_style,
2004
- custom_line_render: this.options.view.custom_line_render,
2005
- draggable: this.options.view.draggable,
2006
- hide_scrollbars_when_draggable:
2007
- this.options.view.hide_scrollbars_when_draggable,
2008
- node_overflow: this.options.view.node_overflow,
2009
- zoom: this.options.view.zoom,
2010
- custom_node_render: this.options.view.custom_node_render,
2011
- expander_style: this.options.view.expander_style,
2012
- };
2013
- (this.data = new c(this)),
2014
- (this.layout = new p(this, e)),
2015
- (this.view = new f(this, t)),
2016
- (this.shortcut = new m(this, this.options.shortcut)),
2017
- this.data.init(),
2018
- this.layout.init(),
2019
- this.view.init(),
2020
- this.shortcut.init(),
2021
- this._event_bind(),
2022
- this.enhancedPluginManager.initNormalPlugins(),
2023
- b(this, this.options.plugin);
2024
- }
2025
- }
2026
- get_editable() {
2027
- return this.options.editable;
2028
- }
2029
- enable_edit() {
2030
- this.options.editable = !0;
2031
- }
2032
- disable_edit() {
2033
- this.options.editable = !1;
2034
- }
2035
- get_view_draggable() {
2036
- return this.options.view.draggable;
2037
- }
2038
- enable_view_draggable() {
2039
- (this.options.view.draggable = !0), this.view.setup_canvas_draggable(!0);
2040
- }
2041
- disable_view_draggable() {
2042
- (this.options.view.draggable = !1), this.view.setup_canvas_draggable(!1);
2043
- }
2044
- enable_event_handle(e) {
2045
- this.options.default_event_handle['enable_' + e + '_handle'] = !0;
2046
- }
2047
- disable_event_handle(e) {
2048
- this.options.default_event_handle['enable_' + e + '_handle'] = !1;
2049
- }
2050
- set_theme(e) {
2051
- var t = this.options.theme;
2052
- (this.options.theme = e || null),
2053
- t != this.options.theme && (this.view.reset_theme(), this.view.reset_custom_style());
2054
- }
2055
- _event_bind() {
2056
- this.view.add_event(this, 'mousedown', this.mousedown_handle),
2057
- this.view.add_event(this, 'click', this.click_handle),
2058
- this.view.add_event(this, 'dblclick', this.dblclick_handle),
2059
- this.view.add_event(this, 'wheel', this.mousewheel_handle, !0);
2060
- }
2061
- mousedown_handle(e) {
2062
- if (this.options.default_event_handle.enable_mousedown_handle) {
2063
- var t = e.target || event.srcElement,
2064
- i = this.view.get_binded_nodeid(t);
2065
- i ? this.view.is_node(t) && this.select_node(i) : this.select_clear();
2066
- }
2067
- }
2068
- click_handle(e) {
2069
- if (this.options.default_event_handle.enable_click_handle) {
2070
- var t = e.target || event.srcElement;
2071
- if (this.view.is_expander(t)) {
2072
- var i = this.view.get_binded_nodeid(t);
2073
- i && this.toggle_node(i);
2074
- }
2075
- }
2076
- }
2077
- dblclick_handle(e) {
2078
- if (this.options.default_event_handle.enable_dblclick_handle && this.get_editable()) {
2079
- var t = e.target || event.srcElement;
2080
- if (this.view.is_node(t)) {
2081
- var i = this.view.get_binded_nodeid(t);
2082
- i && this.begin_edit(i);
2083
- }
2084
- }
2085
- }
2086
- mousewheel_handle(e) {
2087
- var t = (e.metaKey << 13) + (e.ctrlKey << 12) + (e.altKey << 11) + (e.shiftKey << 10);
2088
- if (
2089
- this.options.default_event_handle.enable_mousewheel_handle &&
2090
- this.options.view.zoom.mask_key === t
2091
- ) {
2092
- var i = e || event;
2093
- i.preventDefault(), i.deltaY < 0 ? this.view.zoom_in(i) : this.view.zoom_out(i);
2094
- }
2095
- }
2096
- begin_edit(e) {
2097
- if (!l.is_node(e)) {
2098
- var t = this.get_node(e);
2099
- return t
2100
- ? this.begin_edit(t)
2101
- : (s.error('the node[id=' + e + '] can not be found.'), !1);
2102
- }
2103
- this.get_editable()
2104
- ? this.view.edit_node_begin(e)
2105
- : s.error('fail, this mind map is not editable.');
2106
- }
2107
- end_edit() {
2108
- this.view.edit_node_end();
2109
- }
2110
- toggle_node(e) {
2111
- if (!l.is_node(e)) {
2112
- var t = this.get_node(e);
2113
- return t
2114
- ? void this.toggle_node(t)
2115
- : void s.error('the node[id=' + e + '] can not be found.');
2116
- }
2117
- e.isroot ||
2118
- (this.view.save_location(e),
2119
- this.layout.toggle_node(e),
2120
- this.view.relayout(),
2121
- this.view.restore_location(e));
2122
- }
2123
- expand_node(e) {
2124
- if (!l.is_node(e)) {
2125
- var t = this.get_node(e);
2126
- return t
2127
- ? void this.expand_node(t)
2128
- : void s.error('the node[id=' + e + '] can not be found.');
2129
- }
2130
- e.isroot ||
2131
- (this.view.save_location(e),
2132
- this.layout.expand_node(e),
2133
- this.view.relayout(),
2134
- this.view.restore_location(e));
2135
- }
2136
- collapse_node(e) {
2137
- if (!l.is_node(e)) {
2138
- var t = this.get_node(e);
2139
- return t
2140
- ? void this.collapse_node(t)
2141
- : void s.error('the node[id=' + e + '] can not be found.');
2142
- }
2143
- e.isroot ||
2144
- (this.view.save_location(e),
2145
- this.layout.collapse_node(e),
2146
- this.view.relayout(),
2147
- this.view.restore_location(e));
2148
- }
2149
- expand_all() {
2150
- this.layout.expand_all(), this.view.relayout();
2151
- }
2152
- collapse_all() {
2153
- this.layout.collapse_all(), this.view.relayout();
2154
- }
2155
- expand_to_depth(e) {
2156
- this.layout.expand_to_depth(e), this.view.relayout();
2157
- }
2158
- _reset() {
2159
- this.invoke_event_handle(i.reset, { data: [] }),
2160
- this.view.reset(),
2161
- this.layout.reset(),
2162
- this.data.reset();
2163
- }
2164
- _show(e, t) {
2165
- var n = e || u.node_array.example;
2166
- (this.mind = this.data.load(n)),
2167
- this.mind
2168
- ? (s.debug('data.load ok'),
2169
- this.view.load(),
2170
- s.debug('view.load ok'),
2171
- this.layout.layout(),
2172
- s.debug('layout.layout ok'),
2173
- this.view.show(!t),
2174
- s.debug('view.show ok'),
2175
- this.invoke_event_handle(i.show, { data: [e] }))
2176
- : s.error('data.load error');
2177
- }
2178
- show(e, t) {
2179
- this._reset(), this._show(e, t);
2180
- }
2181
- get_meta() {
2182
- return { name: this.mind.name, author: this.mind.author, version: this.mind.version };
2183
- }
2184
- get_data(e) {
2185
- var t = e || 'node_tree';
2186
- return this.data.get_data(t);
2187
- }
2188
- get_root() {
2189
- return this.mind.root;
2190
- }
2191
- get_node(e) {
2192
- return l.is_node(e) ? e : this.mind.get_node(e);
2193
- }
2194
- get_node_level(e) {
2195
- var t = this.get_node(e);
2196
- if (!t) return s.warn('the node[id=' + e + '] can not be found.'), -1;
2197
- if (t.isroot) return 0;
2198
- for (var i = 0, n = t; n.parent && !n.parent.isroot; ) i++, (n = n.parent);
2199
- return i + 1;
2200
- }
2201
- _add_node_data(e, i, n, o, s) {
2202
- var r = t.of(s);
2203
- void 0 === r && (r = this.layout.calculate_next_child_direction(e));
2204
- var a = this.mind.add_node(e, i, n, o, r);
2205
- return a && (this.view.add_node(a), this.view.reset_node_custom_style(a)), a;
2206
- }
2207
- _refresh_node_ui(e) {
2208
- this.layout.layout(), this.view.show(!1), this.expand_node(e);
2209
- }
2210
- add_node(e, n, o, r, a) {
2211
- if (!this.get_editable()) return s.error('fail, this mind map is not editable'), null;
2212
- var d = this.get_node(e);
2213
- if (!d) return s.error('parent node not found'), null;
2214
- var l = this._add_node_data(d, n, o, r, a);
2215
- return (
2216
- l &&
2217
- (this._refresh_node_ui(d),
2218
- this.invoke_event_handle(i.edit, {
2219
- evt: 'add_node',
2220
- data: [d.id, n, o, r, t.of(a)],
2221
- node: n,
2222
- })),
2223
- l
2224
- );
2225
- }
2226
- add_nodes(e, t) {
2227
- if (!this.get_editable()) return s.error('fail, this mind map is not editable'), [];
2228
- var n = this.get_node(e);
2229
- if (!n) return s.error('parent node not found'), [];
2230
- if (!Array.isArray(t) || 0 === t.length)
2231
- return s.warn('nodes_data should be a non-empty array'), [];
2232
- const o = this._count_expected_nodes(t);
2233
- let r = t
2234
- .map(e => this._add_nodes_recursive(n, e))
2235
- .flat()
2236
- .filter(e => null !== e);
2237
- const a = r.length;
2238
- return a === o
2239
- ? (this._refresh_node_ui(n),
2240
- this.invoke_event_handle(i.edit, {
2241
- evt: 'add_nodes',
2242
- data: [n.id, t],
2243
- nodes: r.map(e => e.id),
2244
- }),
2245
- r)
2246
- : (s.warn(`Expected ${o} nodes, but only created ${a}. Cleaning up...`),
2247
- this._cleanup_partial_nodes(r),
2248
- []);
2249
- }
2250
- _add_nodes_recursive(e, t) {
2251
- var i = [];
2252
- if (!t.id || !t.topic) return s.warn('invalid node data:', t), [];
2253
- var n = this._add_node_data(e, t.id, t.topic, t.data || {}, t.direction);
2254
- if (n && (i.push(n), Array.isArray(t.children))) {
2255
- const e = t.children.map(e => this._add_nodes_recursive(n, e)).flat();
2256
- i = i.concat(e);
2257
- }
2258
- return i;
2259
- }
2260
- _count_expected_nodes(e) {
2261
- if (!Array.isArray(e)) return 0;
2262
- var t = (this.options.fieldNames || {}).children || 'children';
2263
- return e.reduce((e, i) => (e++, (e += this._count_expected_nodes(i && i[t]))), 0);
2264
- }
2265
- _cleanup_partial_nodes(e) {
2266
- 0 !== e.length &&
2267
- [...e].reverse().forEach(e => {
2268
- e && !e.isroot && (this.view.remove_node(e), this.mind.remove_node(e));
2269
- });
2270
- }
2271
- insert_node_before(e, n, o, r, a) {
2272
- if (this.get_editable()) {
2273
- var d = this.get_node(e),
2274
- l = t.of(a);
2275
- void 0 === l && (l = this.layout.calculate_next_child_direction(d.parent));
2276
- var h = this.mind.insert_node_before(d, n, o, r, l);
2277
- return (
2278
- h &&
2279
- (this.view.add_node(h),
2280
- this.layout.layout(),
2281
- this.view.show(!1),
2282
- this.invoke_event_handle(i.edit, {
2283
- evt: 'insert_node_before',
2284
- data: [d.id, n, o, r, l],
2285
- node: n,
2286
- })),
2287
- h
2288
- );
2289
- }
2290
- return s.error('fail, this mind map is not editable'), null;
2291
- }
2292
- insert_node_after(e, n, o, r, a) {
2293
- if (this.get_editable()) {
2294
- var d = this.get_node(e),
2295
- l = t.of(a);
2296
- void 0 === l && (l = this.layout.calculate_next_child_direction(d.parent));
2297
- var h = this.mind.insert_node_after(d, n, o, r, l);
2298
- return (
2299
- h &&
2300
- (this.view.add_node(h),
2301
- this.layout.layout(),
2302
- this.view.show(!1),
2303
- this.invoke_event_handle(i.edit, {
2304
- evt: 'insert_node_after',
2305
- data: [d.id, n, o, r, l],
2306
- node: n,
2307
- })),
2308
- h
2309
- );
2310
- }
2311
- return s.error('fail, this mind map is not editable'), null;
2312
- }
2313
- remove_node(e) {
2314
- if (!l.is_node(e)) {
2315
- var t = this.get_node(e);
2316
- return t
2317
- ? this.remove_node(t)
2318
- : (s.error('the node[id=' + e + '] can not be found.'), !1);
2319
- }
2320
- if (this.get_editable()) {
2321
- if (e.isroot) return s.error('fail, can not remove root node'), !1;
2322
- var n = e.id,
2323
- o = e.parent.id,
2324
- r = this.get_node(o);
2325
- return (
2326
- this.view.save_location(r),
2327
- this.view.remove_node(e),
2328
- this.mind.remove_node(e),
2329
- this.layout.layout(),
2330
- this.view.show(!1),
2331
- this.view.restore_location(r),
2332
- this.invoke_event_handle(i.edit, { evt: 'remove_node', data: [n], node: o }),
2333
- !0
2334
- );
2335
- }
2336
- return s.error('fail, this mind map is not editable'), !1;
2337
- }
2338
- update_node(e, t) {
2339
- if (this.get_editable()) {
2340
- var n = this.get_node(e);
2341
- if (n) {
2342
- if ('string' == typeof t)
2343
- return a.text.is_empty(t)
2344
- ? void s.warn('fail, topic can not be empty')
2345
- : n.topic === t
2346
- ? (s.info('nothing changed'), void this.view.update_node(n))
2347
- : ((n.topic = t),
2348
- this.view.update_node(n),
2349
- this.layout.layout(),
2350
- this.view.show(!1),
2351
- void this.invoke_event_handle(i.edit, {
2352
- evt: 'update_node',
2353
- data: [e, t],
2354
- node: e,
2355
- }));
2356
- if ('object' == typeof t && null !== t) {
2357
- var o = n.id,
2358
- r = !1;
2359
- if (void 0 !== t.topic) {
2360
- if (a.text.is_empty(t.topic))
2361
- return void s.warn('fail, topic can not be empty');
2362
- n.topic !== t.topic && ((n.topic = t.topic), (r = !0));
2363
- }
2364
- if (t.data && 'object' == typeof t.data)
2365
- for (var d in t.data)
2366
- t.data.hasOwnProperty(d) &&
2367
- n.data[d] !== t.data[d] &&
2368
- ((n.data[d] = t.data[d]), (r = !0));
2369
- if (void 0 !== t.id) {
2370
- if ('string' != typeof t.id || '' === t.id.trim())
2371
- return void s.error('fail, new node id must be a non-empty string');
2372
- if (n.id !== t.id) {
2373
- if (n.isroot) return void s.error('fail, cannot change root node id');
2374
- if (t.id in this.mind.nodes)
2375
- return void s.error('fail, new id "' + t.id + '" already exists');
2376
- var l = n.id;
2377
- delete this.mind.nodes[l],
2378
- (n.id = t.id),
2379
- (this.mind.nodes[t.id] = n),
2380
- this.mind.selected &&
2381
- this.mind.selected.id === l &&
2382
- (this.mind.selected = n),
2383
- (r = !0);
2384
- }
2385
- }
2386
- if (
2387
- (['index', 'expanded', 'direction'].forEach(function (e) {
2388
- void 0 !== t[e] && n[e] !== t[e] && ((n[e] = t[e]), (r = !0));
2389
- }),
2390
- !r)
2391
- )
2392
- return s.info('nothing changed'), void this.view.update_node(n);
2393
- this.view.update_node(n),
2394
- this.layout.layout(),
2395
- this.view.show(!1),
2396
- this.invoke_event_handle(i.edit, {
2397
- evt: 'update_node',
2398
- data: [o, t],
2399
- node: o,
2400
- });
2401
- }
2402
- } else s.error('fail, node not found');
2403
- } else s.error('fail, this mind map is not editable');
2404
- }
2405
- move_node(e, t, n, o) {
2406
- if (this.get_editable()) {
2407
- var r = this.get_node(e),
2408
- a = this.mind.move_node(r, t, n, o);
2409
- a &&
2410
- (this.view.update_node(a),
2411
- this.layout.layout(),
2412
- this.view.show(!1),
2413
- this.invoke_event_handle(i.edit, {
2414
- evt: 'move_node',
2415
- data: [e, t, n, o],
2416
- node: e,
2417
- }));
2418
- } else s.error('fail, this mind map is not editable');
2419
- }
2420
- select_node(e) {
2421
- if (!l.is_node(e)) {
2422
- var t = this.get_node(e);
2423
- return t
2424
- ? void this.select_node(t)
2425
- : void s.error('the node[id=' + e + '] can not be found.');
2426
- }
2427
- this.layout.is_visible(e) &&
2428
- ((this.mind.selected = e),
2429
- this.view.select_node(e),
2430
- this.invoke_event_handle(i.select, { evt: 'select_node', data: [], node: e.id }));
2431
- }
2432
- get_selected_node() {
2433
- return this.mind ? this.mind.selected : null;
2434
- }
2435
- select_clear() {
2436
- this.mind && ((this.mind.selected = null), this.view.select_clear());
2437
- }
2438
- is_node_visible(e) {
2439
- return this.layout.is_visible(e);
2440
- }
2441
- scroll_node_to_center(e) {
2442
- if (l.is_node(e)) this.view.center_node(e);
2443
- else {
2444
- var t = this.get_node(e);
2445
- t ? this.scroll_node_to_center(t) : s.error('the node[id=' + e + '] can not be found.');
2446
- }
2447
- }
2448
- find_node_before(e) {
2449
- if (!l.is_node(e)) {
2450
- var t = this.get_node(e);
2451
- return t
2452
- ? this.find_node_before(t)
2453
- : void s.error('the node[id=' + e + '] can not be found.');
2454
- }
2455
- if (e.isroot) return null;
2456
- var i = null;
2457
- if (e.parent.isroot)
2458
- for (var n = e.parent.children, o = null, r = null, a = 0; a < n.length; a++)
2459
- (r = n[a]), e.direction === r.direction && (e.id === r.id && (i = o), (o = r));
2460
- else i = this.mind.get_node_before(e);
2461
- return i;
2462
- }
2463
- find_node_after(e) {
2464
- if (!l.is_node(e)) {
2465
- var t = this.get_node(e);
2466
- return t
2467
- ? this.find_node_after(t)
2468
- : void s.error('the node[id=' + e + '] can not be found.');
2469
- }
2470
- if (e.isroot) return null;
2471
- var i = null;
2472
- if (e.parent.isroot) {
2473
- for (var n = e.parent.children, o = !1, r = null, a = 0; a < n.length; a++)
2474
- if (((r = n[a]), e.direction === r.direction)) {
2475
- if (o) {
2476
- i = r;
2477
- break;
2478
- }
2479
- e.id === r.id && (o = !0);
2480
- }
2481
- } else i = this.mind.get_node_after(e);
2482
- return i;
2483
- }
2484
- set_node_color(e, t, i) {
2485
- if (!this.get_editable()) return s.error('fail, this mind map is not editable'), null;
2486
- var n = this.mind.get_node(e);
2487
- n &&
2488
- (t && (n.data['background-color'] = t),
2489
- i && (n.data['foreground-color'] = i),
2490
- this.view.reset_node_custom_style(n));
2491
- }
2492
- set_node_font_style(e, t, i, n) {
2493
- if (!this.get_editable()) return s.error('fail, this mind map is not editable'), null;
2494
- var o = this.mind.get_node(e);
2495
- o &&
2496
- (t && (o.data['font-size'] = t),
2497
- i && (o.data['font-weight'] = i),
2498
- n && (o.data['font-style'] = n),
2499
- this.view.reset_node_custom_style(o),
2500
- this.view.update_node(o),
2501
- this.layout.layout(),
2502
- this.view.show(!1));
2503
- }
2504
- set_node_background_image(e, t, i, n, o) {
2505
- if (!this.get_editable()) return s.error('fail, this mind map is not editable'), null;
2506
- var r = this.mind.get_node(e);
2507
- r &&
2508
- (t && (r.data['background-image'] = t),
2509
- i && (r.data.width = i),
2510
- n && (r.data.height = n),
2511
- o && (r.data['background-rotation'] = o),
2512
- this.view.reset_node_custom_style(r),
2513
- this.view.update_node(r),
2514
- this.layout.layout(),
2515
- this.view.show(!1));
2516
- }
2517
- set_node_background_rotation(e, t) {
2518
- if (!this.get_editable()) return s.error('fail, this mind map is not editable'), null;
2519
- var i = this.mind.get_node(e);
2520
- if (i) {
2521
- if (!i.data['background-image'])
2522
- return (
2523
- s.error('fail, only can change rotation angle of node with background image'),
2524
- null
2525
- );
2526
- (i.data['background-rotation'] = t),
2527
- this.view.reset_node_custom_style(i),
2528
- this.view.update_node(i),
2529
- this.layout.layout(),
2530
- this.view.show(!1);
2531
- }
2532
- }
2533
- resize() {
2534
- this.view.resize();
2535
- }
2536
- add_event_listener(e) {
2537
- 'function' == typeof e && this.event_handles.push(e);
2538
- }
2539
- clear_event_listener() {
2540
- this.event_handles = [];
2541
- }
2542
- invoke_event_handle(e, t) {
2543
- var i = this;
2544
- r.w.setTimeout(function () {
2545
- i._invoke_event_handle(e, t);
2546
- }, 0);
2547
- }
2548
- _invoke_event_handle(e, t) {
2549
- for (var i = this.event_handles.length, n = 0; n < i; n++) this.event_handles[n](e, t);
2550
- }
2551
- removePlugin(e) {
2552
- this.enhancedPluginManager && this.enhancedPluginManager.removePlugin(e);
2553
- }
2554
- getPlugin(e) {
2555
- if (this.enhancedPluginManager) return this.enhancedPluginManager.getPlugin(e);
2556
- }
2557
- destroy() {
2558
- this.enhancedPluginManager && this.enhancedPluginManager.destroyAllPlugins(),
2559
- this.clear_event_listener(),
2560
- this.view && this.view.reset(),
2561
- (this.mind = null),
2562
- (this.initialized = !1);
2563
- }
2564
- static show(e, t) {
2565
- s.warn(
2566
- '`jsMind.show(options, mind)` is deprecated, please use `jm = new jsMind(options); jm.show(mind);` instead'
2567
- );
2568
- var i = new k(e);
2569
- return i.show(t), i;
2570
- }
2571
- }
2572
- module.exports = k;
2
+ * @license BSD-3-Clause
3
+ * @copyright 2014-2025 hizzgdev@163.com
4
+ *
5
+ * Project Home:
6
+ * https://github.com/hizzgdev/jsmind/
7
+ */
8
+ "use strict";const e="0.9.1";"function"!=typeof String.prototype.startsWith&&(String.prototype.startsWith=function(e){return this.slice(0,e.length)===e});const t={left:-1,center:0,right:1,of:function(e){return e&&-1!==e&&0!==e&&1!==e?"-1"===e||"0"===e||"1"===e?parseInt(e):"left"===e.toLowerCase()?this.left:"right"===e.toLowerCase()?this.right:"center"===e.toLowerCase()?this.center:void 0:e}},i={show:1,resize:2,edit:3,select:4,reset:5,history_change:6},n={debug:1,info:2,warn:3,error:4,disable:9};var o=function(){};let s="undefined"==typeof console?{level:o,log:o,debug:o,info:o,warn:o,error:o}:{level:function(e){s.debug=e>n.debug?o:console.debug;s.info=e>n.info?o:console.info;s.warn=e>n.warn?o:console.warn;s.error=e>n.error?o:console.error},log:console.log,debug:console.debug,info:console.info,warn:console.warn,error:console.error};const r=new class{constructor(e){this.w=e,this.d=e.document,this.g=function(e){return this.d.getElementById(e)},this.c=function(e){return this.d.createElement(e)},this.t=function(e,t){e.hasChildNodes()?e.firstChild.nodeValue=t:e.appendChild(this.d.createTextNode(t))},this.h=function(e,t){t instanceof HTMLElement?(e.innerHTML="",e.appendChild(t)):e.innerHTML=t},this.i=function(e){return!!e&&"object"==typeof e&&1===e.nodeType&&"object"==typeof e.style&&"object"==typeof e.ownerDocument},this.on=function(e,t,i){e.addEventListener?e.addEventListener(t,i,!1):e.attachEvent("on"+t,i)}}}(window),a={file:{read:function(e,t){var i=new FileReader;i.onload=function(){"function"==typeof t&&t(this.result,e.name)},i.readAsText(e)},save:function(e,t,i){var n;if("function"==typeof r.w.Blob)n=new Blob([e],{type:t});else{var o=new(r.w.BlobBuilder||r.w.MozBlobBuilder||r.w.WebKitBlobBuilder||r.w.MSBlobBuilder);o.append(e),n=o.getBlob(t)}if(navigator.msSaveBlob)navigator.msSaveBlob(n,i);else{var s=(r.w.URL||r.w.webkitURL).createObjectURL(n),a=r.c("a");if("download"in a){a.style.visibility="hidden",a.href=s,a.download=i,r.d.body.appendChild(a);var d=r.d.createEvent("MouseEvents");d.initEvent("click",!0,!0),a.dispatchEvent(d),r.d.body.removeChild(a)}else location.href=s}}},json:{json2string:function(e){return JSON.stringify(e)},string2json:function(e){return JSON.parse(e)},merge:function(e,t){for(var i in t)"__proto__"!==i&&"constructor"!==i&&"prototype"!==i&&(i in e?"object"!=typeof e[i]||"[object object]"!=Object.prototype.toString.call(e[i]).toLowerCase()||e[i].length?e[i]=t[i]:a.json.merge(e[i],t[i]):e[i]=t[i]);return e}},uuid:{newid:function(){return((new Date).getTime().toString(16)+Math.random().toString(16).substring(2)).substring(2,18)}},text:{is_empty:function(e){return!e||0==e.replace(/\s*/,"").length}}},d={container:"",editable:!1,theme:null,mode:"full",support_html:!0,log_level:"info",view:{engine:"canvas",enable_device_pixel_ratio:!1,hmargin:100,vmargin:50,line_width:2,line_color:"#555",line_style:"curved",draggable:!1,hide_scrollbars_when_draggable:!1,node_overflow:"hidden",zoom:{min:.5,max:2.1,step:.1,mask_key:4096},custom_node_render:null,expander_style:"char"},layout:{hspace:30,vspace:20,pspace:13,cousin_space:0},default_event_handle:{enable_mousedown_handle:!0,enable_click_handle:!0,enable_dblclick_handle:!0,enable_mousewheel_handle:!0},shortcut:{enable:!0,handles:{},mapping:{addchild:[45,4109],addbrother:13,editnode:113,delnode:46,toggle:32,left:37,up:38,right:39,down:40}},fieldNames:{id:"id",topic:"topic",children:"children",parentid:"parentid",isroot:"isroot",direction:"direction",expanded:"expanded"},plugin:{}};class l{constructor(e,t,i,n,o,r,a,d){e?"number"==typeof t?(void 0===d&&(d=!0),this.id=e,this.index=t,this.topic=i,this.data=n||{},this.isroot=o,this.parent=r,this.direction=a,this.expanded=!!d,this.children=[],this._data={}):s.error("invalid node index"):s.error("invalid node id")}get_location(){var e=this._data.view;return{x:e.abs_x,y:e.abs_y}}get_size(){var e=this._data.view;return{w:e.width,h:e.height}}static compare(e,t){var i=e.index,n=t.index;return i>=0&&n>=0?i-n:-1==i&&-1==n?0:-1==i?1:-1==n?-1:0}static inherited(e,t){if(e&&t){if(e.id===t.id)return!0;if(e.isroot)return!0;for(var i=e.id,n=t;!n.isroot;)if((n=n.parent).id===i)return!0}return!1}static is_node(e){return!!e&&e instanceof l}toObject(e,t=!1){var i=e||{},n=i.id||"id",o=i.topic||"topic",s=i.children||"children",r=i.direction||"direction",a=i.expanded||"expanded",d={};if(d[n]=this.id,d[o]=this.topic,d[a]=this.expanded,this.parent&&this.parent.isroot&&(d[r]=-1===this.direction?"left":"right"),null!=this.data)for(var l in this.data)d[l]=this.data[l];return t&&this.children.length>0&&(d[s]=this.children.map(t=>t.toObject(e,!0))),d}}class h{constructor(){this.name=null,this.author=null,this.version=null,this.root=null,this.selected=null,this.nodes={}}get_node(e){return e in this.nodes?this.nodes[e]:(s.warn("the node[id="+e+"] can not be found"),null)}set_root(e,t,i){return null==this.root?(this.root=new l(e,0,t,i,!0),this._put_node(this.root),this.root):(s.error("root node is already exist"),null)}add_node(e,i,n,o,r,a,d){if(!l.is_node(e))return s.error("the parent_node "+e+" is not a node."),null;var h=new l(i,d||-1,n,o,!1,e,e.direction,a);return e.isroot&&(h.direction=r||t.right),this._put_node(h)?(e.children.push(h),this._update_index(e)):(s.error("fail, the node id '"+h.id+"' has been already exist."),h=null),h}insert_node_before(e,t,i,n,o){if(!l.is_node(e))return s.error("the node_before "+e+" is not a node."),null;var r=e.index-.5;return this.add_node(e.parent,t,i,n,o,!0,r)}get_node_before(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.get_node_before(t):(s.error("the node[id="+e+"] can not be found."),null)}if(e.isroot)return null;var i=e.index-2;return i>=0?e.parent.children[i]:null}insert_node_after(e,t,i,n,o){if(!l.is_node(e))return s.error("the node_after "+e+" is not a node."),null;var r=e.index+.5;return this.add_node(e.parent,t,i,n,o,!0,r)}get_node_after(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.get_node_after(t):(s.error("the node[id="+e+"] can not be found."),null)}if(e.isroot)return null;var i=e.index;return e.parent.children.length>i?e.parent.children[i]:null}move_node(e,t,i,n){return l.is_node(e)?(i||(i=e.parent.id),this._move_node(e,t,i,n)):(s.error("the parameter node "+e+" is not a node."),null)}_flow_node_direction(e,t){void 0===t?t=e.direction:e.direction=t;for(var i=e.children.length;i--;)this._flow_node_direction(e.children[i],t)}_move_node_internal(e,t){if(e&&t)if("_last_"==t)e.index=-1,this._update_index(e.parent);else if("_first_"==t)e.index=0,this._update_index(e.parent);else{var i=t?this.get_node(t):null;null!=i&&null!=i.parent&&i.parent.id==e.parent.id&&(e.index=i.index-.5,this._update_index(e.parent))}return e}_move_node(e,i,n,o){if(e&&n){var r=this.get_node(n);if(l.inherited(e,r))return s.error("can not move a node to its children"),null;if(e.parent.id!=n){for(var a=e.parent.children,d=a.length;d--;)if(a[d].id==e.id){a.splice(d,1);break}let t=e.parent;e.parent=r,r.children.push(e),this._update_index(t)}e.parent.isroot?o==t.left?e.direction=o:e.direction=t.right:e.direction=e.parent.direction,this._move_node_internal(e,i),this._flow_node_direction(e)}return e}remove_node(e){if(!l.is_node(e))return s.error("the parameter node "+e+" is not a node."),!1;if(e.isroot)return s.error("fail, can not remove root node"),!1;null!=this.selected&&this.selected.id==e.id&&(this.selected=null);for(var t=e.children,i=t.length;i--;)this.remove_node(t[i]);t.length=0;for(var n=e.parent,o=n.children,r=o.length;r--;)if(o[r].id==e.id){o.splice(r,1);break}for(var a in delete this.nodes[e.id],e)delete e[a];return e=null,this._update_index(n),!0}change_node_id(e,t){if(!e||!t)return s.error("invalid node id"),!1;if(e===t)return s.warn("nothing changed"),!0;const i=this.get_node(e);return i?i.isroot?(s.error("fail, can not change root node id"),!1):t in this.nodes?(s.error("fail, the node id '"+t+"' has been already exist."),!1):(delete this.nodes[e],i.id=t,this.nodes[t]=i,!0):(s.error("the node[id="+e+"] can not be found."),!1)}_put_node(e){return e.id in this.nodes?(s.warn("the node_id '"+e.id+"' has been already exist."),!1):(this.nodes[e.id]=e,!0)}_update_index(e){if(e instanceof l){e.children.sort(l.compare);for(var t=0;t<e.children.length;t++)e.children[t].index=t+1}}}const _={name:"jsMind",author:"UmbraCi",version:e},u={node_tree:{example:{meta:_,format:"node_tree",data:{id:"root",topic:"jsMind node_tree example"}},get_mind:function(e,t){var i=u.node_tree,n=new h;return n.name=e.meta.name,n.author=e.meta.author,n.version=e.meta.version,i._parse(n,e.data,t),n},get_data:function(e,t){var i=u.node_tree,n={};return n.meta={name:e.name,author:e.author,version:e.version},n.format="node_tree",n.data=i._build_node(e.root,t),n},_parse:function(e,t,i){var n=u.node_tree,o=i||{},s=o.id||"id",r=o.topic||"topic",a=o.children||"children",d=n._extract_data(t,i);if(e.set_root(t[s],t[r],d),a in t)for(var l=t[a],h=0;h<l.length;h++)n._extract_subnode(e,e.root,l[h],i)},_extract_data:function(e,t){var i=t||{},n=i.id||"id",o=i.topic||"topic",s=i.children||"children",r=i.direction||"direction",a=i.expanded||"expanded",d={};for(var l in e)l!=n&&l!=o&&l!=s&&l!=r&&l!=a&&(d[l]=e[l]);return d},_extract_subnode:function(e,i,n,o){var s=u.node_tree,r=o||{},a=r.id||"id",d=r.topic||"topic",l=r.children||"children",h=r.direction||"direction",_=r.expanded||"expanded",c=s._extract_data(n,o),p=null;i.isroot&&(p="left"==n[h]?t.left:t.right);var v=e.add_node(i,n[a],n[d],c,p,n[_]);if(n[l])for(var g=n[l],f=0;f<g.length;f++)s._extract_subnode(e,v,g[f],o)},_build_node:function(e,i){var n=u.node_tree;if(e instanceof l){var o=i||{},s=o.id||"id",r=o.topic||"topic",a=o.children||"children",d=o.direction||"direction",h=o.expanded||"expanded",_={};if(_[s]=e.id,_[r]=e.topic,_[h]=e.expanded,e.parent&&e.parent.isroot&&(_[d]=e.direction==t.left?"left":"right"),null!=e.data){var c=e.data;for(var p in c)_[p]=c[p]}var v=e.children;if(v.length>0){_[a]=[];for(var g=0;g<v.length;g++)_[a].push(n._build_node(v[g],i))}return _}}},node_array:{example:{meta:_,format:"node_array",data:[{id:"root",topic:"jsMind node_array example",isroot:!0}]},get_mind:function(e,t){var i=u.node_array,n=new h;return n.name=e.meta.name,n.author=e.meta.author,n.version=e.meta.version,i._parse(n,e.data,t),n},get_data:function(e,t){var i=u.node_array,n={};return n.meta={name:e.name,author:e.author,version:e.version},n.format="node_array",n.data=[],i._array(e,n.data,t),n},_parse:function(e,t,i){var n=u.node_array,o=t.slice(0);o.reverse();var r=n._extract_root(e,o,i);r?n._extract_subnode(e,r,o,i):s.error("root node can not be found")},_extract_root:function(e,t,i){for(var n=u.node_array,o=i||{},s=o.id||"id",r=o.topic||"topic",a=o.isroot||"isroot",d=t.length;d--;)if(a in t[d]&&t[d][a]){var l=t[d],h=n._extract_data(l,i),_=e.set_root(l[s],l[r],h);return t.splice(d,1),_}return null},_extract_subnode:function(e,i,n,o){for(var s=u.node_array,r=o||{},a=r.id||"id",d=r.topic||"topic",l=r.parentid||"parentid",h=r.direction||"direction",_=r.expanded||"expanded",c=n.length,p=null,v=null,g=0;c--;)if((p=n[c])[l]==i.id){v=s._extract_data(p,o);var f=null,m=p[h];m&&(f="left"==m?t.left:t.right);var y=e.add_node(i,p[a],p[d],v,f,p[_]);n.splice(c,1),g++;var w=s._extract_subnode(e,y,n,o);w>0&&(c=n.length,g+=w)}return g},_extract_data:function(e,t){var i=t||{},n=i.id||"id",o=i.topic||"topic",s=i.parentid||"parentid",r=i.isroot||"isroot",a=i.direction||"direction",d=i.expanded||"expanded",l={};for(var h in e)h!=n&&h!=o&&h!=s&&h!=r&&h!=a&&h!=d&&(l[h]=e[h]);return l},_array:function(e,t,i){u.node_array._array_node(e.root,t,i)},_array_node:function(e,i,n){var o=u.node_array;if(e instanceof l){var s=n||{},r=s.id||"id",a=s.topic||"topic",d=s.parentid||"parentid",h=s.isroot||"isroot",_=s.direction||"direction",c=s.expanded||"expanded",p={};if(p[r]=e.id,p[a]=e.topic,p[c]=e.expanded,e.parent&&(p[d]=e.parent.id),e.isroot&&(p[h]=!0),e.parent&&e.parent.isroot&&(p[_]=e.direction==t.left?"left":"right"),null!=e.data){var v=e.data;for(var g in v)p[g]=v[g]}i.push(p);for(var f=e.children.length,m=0;m<f;m++)o._array_node(e.children[m],i,n)}}},freemind:{example:{meta:_,format:"freemind",data:'<map version="1.0.1"><node ID="root" TEXT="jsMind freemind example"/></map>'},get_mind:function(e,t){var i=u.freemind,n=new h;n.name=e.meta.name,n.author=e.meta.author,n.version=e.meta.version;var o=e.data,s=i._parse_xml(o),r=i._find_root(s);return i._load_node(n,null,r),n},get_data:function(e,t){var i=u.freemind,n={};n.meta={name:e.name,author:e.author,version:e.version},n.format="freemind";var o=[];return o.push('<map version="1.0.1">'),i._build_map(e.root,o),o.push("</map>"),n.data=o.join(""),n},_parse_xml:function(e){var t=null;window.DOMParser?t=(new DOMParser).parseFromString(e,"text/xml"):((t=new ActiveXObject("Microsoft.XMLDOM")).async=!1,t.loadXML(e));return t},_find_root:function(e){for(var t=e.childNodes,i=null,n=null,o=0;o<t.length;o++)if(1==(n=t[o]).nodeType&&"map"==n.tagName){i=n;break}if(i){var s=i.childNodes;i=null;for(o=0;o<s.length;o++)if(1==(n=s[o]).nodeType&&"node"==n.tagName){i=n;break}}return i},_load_node:function(e,i,n){var o=u.freemind,s=n.getAttribute("ID"),r=n.getAttribute("TEXT"),a=n.getAttribute("FOLDED");if(null==r)for(var d=n.childNodes,l=null,h=0;h<d.length;h++)if(1==(l=d[h]).nodeType&&"richcontent"===l.tagName){r=l.textContent;break}var _=o._load_attributes(n),c="expanded"in _?"true"==_.expanded:"true"!=a;delete _.expanded;var p=n.getAttribute("COLOR");p&&(_["foreground-color"]=p);var v=n.getAttribute("BACKGROUND_COLOR");v&&(_["background-color"]=v);var g=n.getAttribute("POSITION"),f=null;g&&(f="left"==g?t.left:t.right);var m=null;m=i?e.add_node(i,s,r,_,f,c):e.set_root(s,r,_);var y=n.childNodes,w=null;for(h=0;h<y.length;h++)1==(w=y[h]).nodeType&&"node"==w.tagName&&o._load_node(e,m,w)},_load_attributes:function(e){for(var t=e.childNodes,i=null,n={},o=0;o<t.length;o++)1==(i=t[o]).nodeType&&"attribute"===i.tagName&&(n[i.getAttribute("NAME")]=i.getAttribute("VALUE"));return n},_build_map:function(e,i){var n=u.freemind,o=null,s=e.data;if(e.parent&&e.parent.isroot&&(o=e.direction===t.left?"left":"right"),i.push("<node"),i.push(' ID="'+e.id+'"'),o&&i.push(' POSITION="'+o+'"'),e.expanded||i.push(' FOLDED="true"'),s["foreground-color"]&&i.push(' COLOR="'+s["foreground-color"]+'"'),s["background-color"]&&i.push(' BACKGROUND_COLOR="'+s["background-color"]+'"'),i.push(' TEXT="'+n._escape(e.topic)+'">'),null!=s)for(var r in s)"foreground-color"!==r&&"background-color"!==r&&i.push('<attribute NAME="'+r+'" VALUE="'+s[r]+'"/>');for(var a=e.children,d=0;d<a.length;d++)n._build_map(a[d],i);i.push("</node>")},_escape:function(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&apos;").replace(/"/g,"&quot;")}},text:{example:{meta:_,format:"text",data:"jsMind text example\n node1\n node1-sub\n node1-sub\n node2"},_line_regex:/\s*/,get_mind:function(e,t){var i=u.text,n=new h;n.name=e.meta.name,n.author=e.meta.author,n.version=e.meta.version;var o=e.data.split(/\n|\r/);return i._fill_nodes(n,o,0,0),n},_fill_nodes:function(e,t){let i=[],n=0;for(;n<t.length;){let o=t[n],s=o.match(/\s*/)[0].length,r=o.substr(s);if(0==s&&i.length>0)return void log.error("more than 1 root node was found: "+r);if(s>i.length)return void log.error("a suspended node was found: "+r);let d=i.length-s;for(;d--;)i.pop();if(0==s&&0==i.length){let t=e.set_root(a.uuid.newid(),r);i.push(t)}else{let t=e.add_node(i[s-1],a.uuid.newid(),r,{},null);i.push(t)}n++}i.length=0},get_data:function(e){var t=u.text,i={};i.meta={name:e.name,author:e.author,version:e.version},i.format="text";let n=[];return t._build_lines(n,[e.root],0),i.data=n.join("\n"),i},_build_lines:function(e,t,i){let n=new Array(i+1).join(" ");for(let o of t)e.push(n+o.topic),o.children&&u.text._build_lines(e,o.children,i+1)}}};class c{constructor(e){this.jm=e}init(){s.debug("data.init")}reset(){s.debug("data.reset")}load(e){var t=null,i=null;t="object"==typeof e?e.format?e.format:"node_tree":"freemind";const n=this.jm&&this.jm.options?this.jm.options.fieldNames:void 0,o=t=>void 0===n?t.get_mind(e):t.get_mind(e,n);return"node_array"==t?i=o(u.node_array):"node_tree"==t?i=o(u.node_tree):"freemind"==t?i=o(u.freemind):"text"==t?i=o(u.text):s.warn("unsupported format"),i}get_data(e){var t=null;const i=this.jm&&this.jm.options?this.jm.options.fieldNames:void 0,n=e=>void 0===i?e.get_data(this.jm.mind):e.get_data(this.jm.mind,i);return"node_array"==e?t=n(u.node_array):"node_tree"==e?t=n(u.node_tree):"freemind"==e?t=u.freemind.get_data(this.jm.mind):"text"==e?t=u.text.get_data(this.jm.mind):s.error("unsupported "+e+" format"),t}}class p{constructor(e,t){this.opts=t,this.jm=e,this.isside="side"==this.opts.mode,this.bounds=null,this.cache_valid=!1}init(){s.debug("layout.init")}reset(){s.debug("layout.reset"),this.bounds={n:0,s:0,w:0,e:0}}calculate_next_child_direction(e){if(this.isside)return t.right;for(var i=e.children||[],n=i.length,o=0,s=0;s<n;s++)i[s].direction===t.left?o--:o++;return n>1&&o>0?t.left:t.right}layout(){s.debug("layout.layout"),this.layout_direction(),this.layout_offset()}layout_direction(){this._layout_direction_root()}_layout_direction_root(){var e=this.jm.mind.root,i=null;"layout"in e._data?i=e._data.layout:(i={},e._data.layout=i);var n=e.children,o=n.length;if(i.direction=t.center,i.side_index=0,this.isside)for(var s=o;s--;)this._layout_direction_side(n[s],t.right,s);else{s=o;for(var r=null;s--;)(r=n[s]).direction==t.left?this._layout_direction_side(r,t.left,s):this._layout_direction_side(r,t.right,s)}}_layout_direction_side(e,t,i){var n=null;"layout"in e._data?n=e._data.layout:(n={},e._data.layout=n);var o=e.children,s=o.length;n.direction=t,n.side_index=i;for(var r=s;r--;)this._layout_direction_side(o[r],t,r)}layout_offset(){var e=this.jm.mind.root,i=e._data.layout;i.offset_x=0,i.offset_y=0,i.outer_height=0;for(var n=e.children,o=n.length,s=[],r=[],a=null;o--;)(a=n[o])._data.layout.direction==t.right?r.unshift(a):s.unshift(a);i.left_nodes=s,i.right_nodes=r,i.outer_height_left=this._layout_offset_subnodes(s),i.outer_height_right=this._layout_offset_subnodes(r),this.bounds.e=e._data.view.width/2,this.bounds.w=0-this.bounds.e,this.bounds.n=0,this.bounds.s=Math.max(i.outer_height_left,i.outer_height_right)}_layout_offset_subnodes(e){for(var t=0,i=e.length,n=i,o=null,s=0,r=null,a=0,d=null;n--;)r=(o=e[n])._data.layout,null==d&&(d=o.parent._data),s=this._layout_offset_subnodes(o.children),o.expanded||(s=0,this.set_visible(o.children,!1)),s=Math.max(o._data.view.height,s),this._should_reserve_cousin_space(o)&&(s+=this.opts.cousin_space),r.outer_height=s,r.offset_y=a-s/2,r.offset_x=this.opts.hspace*r.direction+d.view.width*(d.layout.direction+r.direction)/2,o.parent.isroot||(r.offset_x+=this.opts.pspace*r.direction),a=a-s-this.opts.vspace,t+=s;i>1&&(t+=this.opts.vspace*(i-1)),n=i;for(var l=t/2;n--;)(o=e[n])._data.layout.offset_y+=l;return t}_layout_offset_subnodes_height(e){for(var t=0,i=e.length,n=i,o=null,s=0,r=null,a=0,d=null;n--;)r=(o=e[n])._data.layout,null==d&&(d=o.parent._data),s=this._layout_offset_subnodes_height(o.children),o.expanded||(s=0),s=Math.max(o._data.view.height,s),this._should_reserve_cousin_space(o)&&(s+=this.opts.cousin_space),r.outer_height=s,r.offset_y=a-s/2,a=a-s-this.opts.vspace,t+=s;i>1&&(t+=this.opts.vspace*(i-1)),n=i;for(var l=t/2;n--;)(o=e[n])._data.layout.offset_y+=l;return t}_should_reserve_cousin_space(e){return e.children.length>0&&e.parent.children.length>1}get_node_offset(e){var t=e._data.layout,i=null;if("_offset_"in t&&this.cache_valid?i=t._offset_:(i={x:-1,y:-1},t._offset_=i),-1==i.x||-1==i.y){var n=t.offset_x,o=t.offset_y;if(!e.isroot){var s=this.get_node_offset(e.parent);n+=s.x,o+=s.y}i.x=n,i.y=o}return i}get_node_point(e){var t=e._data.view,i=this.get_node_offset(e),n={};return n.x=i.x+t.width*(e._data.layout.direction-1)/2,n.y=i.y-t.height/2,n}get_node_point_in(e){return this.get_node_offset(e)}get_node_point_out(e){var t=e._data.layout,i=null;if("_pout_"in t&&this.cache_valid?i=t._pout_:(i={x:-1,y:-1},t._pout_=i),-1==i.x||-1==i.y)if(e.isroot)i.x=0,i.y=0;else{var n=e._data.view,o=this.get_node_offset(e);i.x=o.x+(n.width+this.opts.pspace)*e._data.layout.direction,i.y=o.y}return i}get_expander_point(e){var i=this.get_node_point_out(e),n={};return e._data.layout.direction==t.right?n.x=i.x-this.opts.pspace:n.x=i.x,n.y=i.y-Math.ceil(this.opts.pspace/2),n}get_min_size(){var e=this.jm.mind.nodes,t=null,i=null;for(var n in e)t=e[n],(i=this.get_node_point_out(t)).x>this.bounds.e&&(this.bounds.e=i.x),i.x<this.bounds.w&&(this.bounds.w=i.x);return{w:this.bounds.e-this.bounds.w,h:this.bounds.s-this.bounds.n}}toggle_node(e){e.isroot||(e.expanded?this.collapse_node(e):this.expand_node(e))}expand_node(e){e.expanded=!0,this.part_layout(e),this.set_visible(e.children,!0),this.jm.invoke_event_handle(i.show,{evt:"expand_node",data:[],node:e.id})}collapse_node(e){e.expanded=!1,this.part_layout(e),this.set_visible(e.children,!1),this.jm.invoke_event_handle(i.show,{evt:"collapse_node",data:[],node:e.id})}expand_all(){var e,t=this.jm.mind.nodes,i=0;for(var n in t)(e=t[n]).expanded||(e.expanded=!0,i++);if(i>0){var o=this.jm.mind.root;this.part_layout(o),this.set_visible(o.children,!0)}}collapse_all(){var e,t=this.jm.mind.nodes,i=0;for(var n in t)(e=t[n]).expanded&&!e.isroot&&(e.expanded=!1,i++);if(i>0){var o=this.jm.mind.root;this.part_layout(o),this.set_visible(o.children,!0)}}expand_to_depth(e,t,i){if(!(e<1))for(var n=t||this.jm.mind.root.children,o=i||1,s=n.length,r=null;s--;)r=n[s],o<e&&(r.expanded||this.expand_node(r),this.expand_to_depth(e,r.children,o+1)),o==e&&r.expanded&&this.collapse_node(r)}part_layout(e){var i=this.jm.mind.root;if(i){var n=i._data.layout;e.isroot?(n.outer_height_right=this._layout_offset_subnodes_height(n.right_nodes),n.outer_height_left=this._layout_offset_subnodes_height(n.left_nodes)):e._data.layout.direction==t.right?n.outer_height_right=this._layout_offset_subnodes_height(n.right_nodes):n.outer_height_left=this._layout_offset_subnodes_height(n.left_nodes),this.bounds.s=Math.max(n.outer_height_left,n.outer_height_right),this.cache_valid=!1}else s.warn("can not found root node")}set_visible(e,t){for(var i=e.length,n=null;i--;)(n=e[i])._data.layout,n.expanded?this.set_visible(n.children,t):this.set_visible(n.children,!1),n.isroot||(n._data.layout.visible=t)}is_expand(e){return e.expanded}is_visible(e){var t=e._data.layout;return!("visible"in t&&!t.visible)}}class v{constructor(e){this.view=e,this.opts=e.opts,this.e_svg=v.c("svg"),this.e_svg.setAttribute("class","jsmind"),this.size={w:0,h:0},this.lines=[],this.line_drawing={straight:this._line_to,curved:this._bezier_to},this.init_line_render()}static c(e){return r.d.createElementNS("http://www.w3.org/2000/svg",e)}init_line_render(){"function"==typeof this.opts.custom_line_render?this.drawing=(e,t,i,n,o)=>{try{this.opts.custom_line_render.call(this,{ctx:e,start_point:{x:t,y:i},end_point:{x:n,y:o}})}catch(e){s.error("custom line renderer error: ",e)}}:this.drawing=this.line_drawing[this.opts.line_style]||this.line_drawing.curved}element(){return this.e_svg}set_size(e,t){this.size.w=e,this.size.h=t,this.e_svg.setAttribute("width",e),this.e_svg.setAttribute("height",t)}clear(){for(var e=this.lines.length;e--;)this.e_svg.removeChild(this.lines[e]);this.lines.length=0}draw_line(e,t,i,n){var o=v.c("path");o.setAttribute("stroke",n||this.opts.line_color),o.setAttribute("stroke-width",this.opts.line_width),o.setAttribute("fill","transparent"),this.lines.push(o),this.e_svg.appendChild(o),this.drawing(o,t.x+i.x,t.y+i.y,e.x+i.x,e.y+i.y)}copy_to(e,t){var i=new Image;i.onload=function(){e.drawImage(i,0,0),t&&t()},i.src="data:image/svg+xml;base64,"+btoa((new XMLSerializer).serializeToString(this.e_svg))}_bezier_to(e,t,i,n,o){e.setAttribute("d","M "+t+" "+i+" C "+(t+2*(n-t)/3)+" "+i+", "+t+" "+o+", "+n+" "+o)}_line_to(e,t,i,n,o){e.setAttribute("d","M "+t+" "+i+" L "+n+" "+o)}}class g{constructor(e){this.opts=e.opts,this.e_canvas=r.c("canvas"),this.e_canvas.className="jsmind",this.canvas_ctx=this.e_canvas.getContext("2d"),this.size={w:0,h:0},this.line_drawing={straight:this._line_to,curved:this._bezier_to},this.dpr=e.device_pixel_ratio,this.init_line_render()}init_line_render(){"function"==typeof this.opts.custom_line_render?this.drawing=(e,t,i,n,o)=>{try{this.opts.custom_line_render.call(this,{ctx:e,start_point:{x:t,y:i},end_point:{x:n,y:o}})}catch(e){s.error("custom line render error: ",e)}}:this.drawing=this.line_drawing[this.opts.line_style]||this.line_drawing.curved}element(){return this.e_canvas}set_size(e,t){this.size.w=e,this.size.h=t,this.e_canvas.width&&this.e_canvas.height&&this.canvas_ctx.scale?(this.e_canvas.width=e*this.dpr,this.e_canvas.height=t*this.dpr,this.e_canvas.style.width=e+"px",this.e_canvas.style.height=t+"px",this.canvas_ctx.scale(this.dpr,this.dpr)):(this.e_canvas.width=e,this.e_canvas.height=t)}clear(){this.canvas_ctx.clearRect(0,0,this.size.w,this.size.h)}draw_line(e,t,i,n){var o=this.canvas_ctx;o.strokeStyle=n||this.opts.line_color,o.lineWidth=this.opts.line_width,o.lineCap="round",this.drawing(o,t.x+i.x,t.y+i.y,e.x+i.x,e.y+i.y)}copy_to(e,t){e.drawImage(this.e_canvas,0,0,this.size.w,this.size.h),t&&t()}_bezier_to(e,t,i,n,o){e.beginPath(),e.moveTo(t,i),e.bezierCurveTo(t+2*(n-t)/3,i,t,o,n,o),e.stroke()}_line_to(e,t,i,n,o){e.beginPath(),e.moveTo(t,i),e.lineTo(n,o),e.stroke()}}class f{constructor(e,t){this.opts=t,this.jm=e,this.layout=e.layout,this.container=null,this.e_panel=null,this.e_nodes=null,this.size={w:0,h:0},this.selected_node=null,this.editing_node=null,this.graph=null,this.render_node=t.custom_node_render?this._custom_node_render:this._default_node_render,this.zoom_current=1,this.device_pixel_ratio=this.opts.enable_device_pixel_ratio&&r.w.devicePixelRatio||1,this._initialized=!1}init(){if(s.debug(this.opts),s.debug("view.init"),this.container=r.i(this.opts.container)?this.opts.container:r.g(this.opts.container),this.container){var e;this.graph=(e=this,"svg"===this.opts.engine.toLowerCase()?new v(e):new g(e)),this.e_panel=r.c("div"),this.e_nodes=r.c("jmnodes"),this.e_editor=r.c("input"),this.e_panel.className="jsmind-inner jmnode-overflow-"+this.opts.node_overflow,this.e_panel.tabIndex=1,this.e_panel.appendChild(this.graph.element()),this.e_panel.appendChild(this.e_nodes),this.e_editor.className="jsmind-editor",this.e_editor.type="text";var t=this;r.on(this.e_editor,"keydown",function(e){var i=e||event;13==i.keyCode&&(t.edit_node_end(),i.stopPropagation())}),r.on(this.e_editor,"blur",function(e){t.edit_node_end()}),this.container.appendChild(this.e_panel),this.container.offsetParent||new IntersectionObserver((e,t)=>{e[0].isIntersecting&&(t.unobserve(this.e_panel),this.resize())}).observe(this.e_panel)}else s.error("the options.view.container was not be found in dom")}add_event(e,t,i,n){let o=n?this.e_panel:this.e_nodes;r.on(o,t,function(t){var n=t||event;i.call(e,n)})}get_binded_nodeid(e){if(null==e)return null;var t=e.tagName.toLowerCase();return"jmnode"==t||"jmexpander"==t?e.getAttribute("nodeid"):"jmnodes"==t||"body"==t||"html"==t?null:this.get_binded_nodeid(e.parentElement)}is_node(e){if(null==e)return!1;var t=e.tagName.toLowerCase();return"jmnode"==t||"jmnodes"!=t&&"body"!=t&&"html"!=t&&this.is_node(e.parentElement)}is_expander(e){return"jmexpander"==e.tagName.toLowerCase()}reset(){s.debug("view.reset"),this.selected_node=null,this.clear_lines(),this.clear_nodes(),this.reset_theme()}reset_theme(){var e=this.jm.options.theme;this.e_nodes.className=e?"theme-"+e:""}reset_custom_style(){var e=this.jm.mind.nodes;for(var t in e)this.reset_node_custom_style(e[t])}load(){s.debug("view.load"),this.setup_canvas_draggable(this.opts.draggable),this.init_nodes(),this._initialized=!0}expand_size(){var e=this.layout.get_min_size(),t=e.w+2*this.opts.hmargin,i=e.h+2*this.opts.vmargin,n=this.e_panel.clientWidth,o=this.e_panel.clientHeight;n<t&&(n=t),o<i&&(o=i),this.size.w=n,this.size.h=o}init_nodes_size(e){var t=e._data.view;t.width=t.element.clientWidth,t.height=t.element.clientHeight}init_nodes(){var e=this.jm.mind.nodes,t=r.d.createDocumentFragment();for(var i in e)this.create_node_element(e[i],t);this.e_nodes.appendChild(t),this.run_in_c11y_mode_if_needed(()=>{for(var t in e)this.init_nodes_size(e[t])})}add_node(e){this.create_node_element(e,this.e_nodes),this.run_in_c11y_mode_if_needed(()=>{this.init_nodes_size(e)})}run_in_c11y_mode_if_needed(e){this.container.offsetParent?e():(s.warn("init nodes in compatibility mode. because the container or its parent has style {display:none}. "),this.e_panel.style.position="absolute",this.e_panel.style.top="-100000",r.d.body.appendChild(this.e_panel),e(),this.container.appendChild(this.e_panel),this.e_panel.style.position=null,this.e_panel.style.top=null)}create_node_element(e,t){var i=null;"view"in e._data?i=e._data.view:(i={},e._data.view=i);var n=r.c("jmnode");if(e.isroot)n.className="root";else{var o=r.c("jmexpander");r.t(o,"-"),o.setAttribute("nodeid",e.id),o.style.visibility="hidden",t.appendChild(o),i.expander=o}e.topic&&this.render_node(n,e),n.setAttribute("nodeid",e.id),n.style.visibility="hidden",this._reset_node_custom_style(n,e.data),t.appendChild(n),i.element=n}remove_node(e){null!=this.selected_node&&this.selected_node.id==e.id&&(this.selected_node=null),null!=this.editing_node&&this.editing_node.id==e.id&&(e._data.view.element.removeChild(this.e_editor),this.editing_node=null);for(var t=e.children,i=t.length;i--;)this.remove_node(t[i]);if(e._data.view){var n=e._data.view.element,o=e._data.view.expander;this.e_nodes.removeChild(n),this.e_nodes.removeChild(o),e._data.view.element=null,e._data.view.expander=null}}update_node(e){var t=e._data.view,i=t.element;if(e.topic&&this.render_node(i,e),this.layout.is_visible(e))t.width=i.clientWidth,t.height=i.clientHeight;else{let e=i.getAttribute("style");i.style="visibility: visible; left:0; top:0;",t.width=i.clientWidth,t.height=i.clientHeight,i.style=e}}select_node(e){if(this.selected_node){var t=this.selected_node._data.view.element;t.className=t.className.replace(/\s*selected\b/i,""),this.restore_selected_node_custom_style(this.selected_node)}e&&(this.selected_node=e,e._data.view.element.className+=" selected",this.clear_selected_node_custom_style(e))}select_clear(){this.select_node(null)}get_editing_node(){return this.editing_node}is_editing(){return!!this.editing_node}edit_node_begin(e){if(e.topic){null!=this.editing_node&&this.edit_node_end(),this.editing_node=e;var t=e._data.view.element,i=e.topic,n=getComputedStyle(t);this.e_editor.value=i,this.e_editor.style.width=t.clientWidth-parseInt(n.getPropertyValue("padding-left"))-parseInt(n.getPropertyValue("padding-right"))+"px",t.innerHTML="",t.appendChild(this.e_editor),t.style.zIndex=5,this.e_editor.focus(),this.e_editor.select()}else s.warn("don't edit image nodes")}edit_node_end(){if(null!=this.editing_node){var e=this.editing_node;this.editing_node=null;var t=e._data.view.element,i=this.e_editor.value;t.style.zIndex="auto",t.removeChild(this.e_editor),a.text.is_empty(i)||e.topic===i?this.render_node(t,e):this.jm.update_node(e.id,i)}this.e_panel.focus()}get_view_offset(){var e=this.layout.bounds;return{x:(this.size.w-e.e-e.w)/2,y:this.size.h/2}}resize(){this.graph.set_size(1,1),this.e_nodes.style.width="1px",this.e_nodes.style.height="1px",this.expand_size(),this._show()}_show(){this.graph.set_size(this.size.w,this.size.h),this.e_nodes.style.width=this.size.w+"px",this.e_nodes.style.height=this.size.h+"px",this.show_nodes(),this.show_lines(),this.jm.invoke_event_handle(i.resize,{data:[]})}zoom_in(e){return this.set_zoom(this.zoom_current+this.opts.zoom.step,e)}zoom_out(e){return this.set_zoom(this.zoom_current-this.opts.zoom.step,e)}set_zoom(e,t){if(e<this.opts.zoom.min||e>this.opts.zoom.max)return!1;let i=this.e_panel.getBoundingClientRect();if(e<1&&e<this.zoom_current&&this.size.w*e<i.width&&this.size.h*e<i.height)return!1;let n=t?{x:t.x-i.x,y:t.y-i.y}:{x:i.width/2,y:i.height/2},o=(this.e_panel.scrollLeft+n.x)*e/this.zoom_current-n.x,s=(this.e_panel.scrollTop+n.y)*e/this.zoom_current-n.y;this.zoom_current=e;for(var r=0;r<this.e_panel.children.length;r++)this.e_panel.children[r].style.zoom=e;return this._show(),this.e_panel.scrollLeft=o,this.e_panel.scrollTop=s,!0}show(e){s.debug(`view.show: {keep_center: ${e}}`),this.expand_size(),this._show(),e&&this.center_node(this.jm.mind.root)}relayout(){this.expand_size(),this._show()}save_location(e){var t=e._data.view;t._saved_location={x:parseInt(t.element.style.left)-this.e_panel.scrollLeft,y:parseInt(t.element.style.top)-this.e_panel.scrollTop}}restore_location(e){var t=e._data.view;this.e_panel.scrollLeft=parseInt(t.element.style.left)-t._saved_location.x,this.e_panel.scrollTop=parseInt(t.element.style.top)-t._saved_location.y}clear_nodes(){var e=this.jm.mind;if(null!=e){var t=e.nodes,i=null;for(var n in t)(i=t[n])._data.view.element=null,i._data.view.expander=null;this.e_nodes.innerHTML=""}}show_nodes(){var e=this.jm.mind.nodes,t=null,i=null,n=null,o=null,s=this.get_view_offset();for(var r in e)i=(o=(t=e[r])._data.view).element,this.layout.is_visible(t)?(this.reset_node_custom_style(t),n=this.layout.get_node_point(t),o.abs_x=s.x+n.x,o.abs_y=s.y+n.y,i.style.left=s.x+n.x+"px",i.style.top=s.y+n.y+"px",i.style.display="",i.style.visibility="visible",this._show_expander(t,s)):(i.style.display="none",o.expander.style.display="none")}_show_expander(e,t){if(e.isroot)return;var i=e._data.view.expander;if(0==e.children.length)return i.style.display="none",void(i.style.visibility="hidden");let n=this._get_expander_text(e);r.t(i,n);let o=this.layout.get_expander_point(e);i.style.left=t.x+o.x+"px",i.style.top=t.y+o.y+"px",i.style.display="",i.style.visibility="visible"}_get_expander_text(e){let t=this.opts.expander_style?this.opts.expander_style.toLowerCase():"char";return"number"===t?e.children.length>99?"...":e.children.length:"char"===t?e.expanded?"−":"+":void 0}_default_node_render(e,t){this.opts.support_html?r.h(e,t.topic):r.t(e,t.topic)}_custom_node_render(e,t){this.opts.custom_node_render(this.jm,e,t)||this._default_node_render(e,t)}reset_node_custom_style(e){this._reset_node_custom_style(e._data.view.element,e.data)}_reset_node_custom_style(e,t){if("background-color"in t&&(e.style.backgroundColor=t["background-color"]),"foreground-color"in t&&(e.style.color=t["foreground-color"]),"width"in t&&(e.style.width=t.width+"px"),"height"in t&&(e.style.height=t.height+"px"),"font-size"in t&&(e.style.fontSize=t["font-size"]+"px"),"font-weight"in t&&(e.style.fontWeight=t["font-weight"]),"font-style"in t&&(e.style.fontStyle=t["font-style"]),"background-image"in t){var i=t["background-image"];if(i.startsWith("data")&&t.width&&t.height){var n=new Image;n.onload=function(){var t=r.c("canvas");t.width=e.clientWidth,t.height=e.clientHeight;if(t.getContext){t.getContext("2d").drawImage(this,2,2,e.clientWidth,e.clientHeight);var i=t.toDataURL();e.style.backgroundImage="url("+i+")"}},n.src=i}else e.style.backgroundImage="url("+i+")";e.style.backgroundSize="99%","background-rotation"in t&&(e.style.transform="rotate("+t["background-rotation"]+"deg)")}}restore_selected_node_custom_style(e){var t=e._data.view.element,i=e.data;"background-color"in i&&(t.style.backgroundColor=i["background-color"]),"foreground-color"in i&&(t.style.color=i["foreground-color"])}clear_selected_node_custom_style(e){var t=e._data.view.element;t.style.backgroundColor="",t.style.color=""}clear_lines(){this.graph.clear()}show_lines(){this.clear_lines();var e=this.jm.mind.nodes,t=null,i=null,n=null,o=null,s=this.get_view_offset();for(var r in e)(t=e[r]).isroot||this.layout.is_visible(t)&&(i=this.layout.get_node_point_in(t),n=this.layout.get_node_point_out(t.parent),o=t.data["leading-line-color"],this.graph.draw_line(n,i,s,o))}setup_canvas_draggable(e){if(this.opts.draggable=e,!this._initialized){let e,t,i=!1;this.opts.hide_scrollbars_when_draggable&&(this.e_panel.style="overflow: hidden"),r.on(this.container,"mousedown",n=>{this.opts.draggable&&(i=!0,e=n.clientX,t=n.clientY)}),r.on(this.container,"mouseup",()=>{i=!1}),r.on(this.container,"mousemove",n=>{this.opts.draggable&&i&&(this.e_panel.scrollBy(e-n.clientX,t-n.clientY),e=n.clientX,t=n.clientY)})}}center_node(e){if(!this.layout.is_visible(e))return s.warn("can not scroll to the node, because it is invisible"),!1;let t=e._data.view,i=this.e_panel.getBoundingClientRect(),n=t.abs_x+t.width/2,o=t.abs_y+t.height/2;return this.e_panel.scrollTo(n*this.zoom_current-i.width/2,o*this.zoom_current-i.height/2),!0}zoomIn(e){return s.warn("please use zoom_in instead"),this.zoom_in(e)}zoomOut(e){return s.warn("please use zoom_out instead"),this.zoom_out(e)}setZoom(e,t){return s.warn("please use set_zoom instead"),this.set_zoom(e,t)}}class m{constructor(e,t){this.jm=e,this.opts=t,this.mapping=t.mapping,this.handles=t.handles,this._newid=null,this._mapping={}}init(){for(var e in r.on(this.jm.view.e_panel,"keydown",this.handler.bind(this)),this.handles.addchild=this.handle_addchild,this.handles.addbrother=this.handle_addbrother,this.handles.editnode=this.handle_editnode,this.handles.delnode=this.handle_delnode,this.handles.toggle=this.handle_toggle,this.handles.up=this.handle_up,this.handles.down=this.handle_down,this.handles.left=this.handle_left,this.handles.right=this.handle_right,this.mapping)if(this.mapping[e]&&e in this.handles){let t=this.mapping[e];Array.isArray(t)||(t=[t]);for(let i of t)this._mapping[i]=this.handles[e]}"function"==typeof this.opts.id_generator?this._newid=this.opts.id_generator:this._newid=a.uuid.newid}enable_shortcut(){this.opts.enable=!0}disable_shortcut(){this.opts.enable=!1}handler(e){if(9==e.which&&e.preventDefault(),!this.jm.view.is_editing()){var t=e||event;if(!this.opts.enable)return!0;var i=t.keyCode+(t.metaKey<<13)+(t.ctrlKey<<12)+(t.altKey<<11)+(t.shiftKey<<10);i in this._mapping&&this._mapping[i].call(this,this.jm,e)}}handle_addchild(e,t){var i=e.get_selected_node();if(i){var n=this._newid();e.add_node(i,n,"New Node")&&(e.select_node(n),e.begin_edit(n))}}handle_addbrother(e,t){var i=e.get_selected_node();if(i&&!i.isroot){var n=this._newid();e.insert_node_after(i,n,"New Node")&&(e.select_node(n),e.begin_edit(n))}}handle_editnode(e,t){var i=e.get_selected_node();i&&e.begin_edit(i)}handle_delnode(e,t){var i=e.get_selected_node();i&&!i.isroot&&(e.select_node(i.parent),e.remove_node(i))}handle_toggle(e,t){var i=t||event,n=e.get_selected_node();n&&(e.toggle_node(n.id),i.stopPropagation(),i.preventDefault())}handle_up(e,t){var i=t||event,n=e.get_selected_node();if(n){var o=e.find_node_before(n);if(!o){var s=e.find_node_before(n.parent);s&&s.children.length>0&&(o=s.children[s.children.length-1])}o&&e.select_node(o),i.stopPropagation(),i.preventDefault()}}handle_down(e,t){var i=t||event,n=e.get_selected_node();if(n){var o=e.find_node_after(n);if(!o){var s=e.find_node_after(n.parent);s&&s.children.length>0&&(o=s.children[0])}o&&e.select_node(o),i.stopPropagation(),i.preventDefault()}}handle_left(e,i){this._handle_direction(e,i,t.left)}handle_right(e,i){this._handle_direction(e,i,t.right)}_handle_direction(e,t,i){var n=t||event,o=e.get_selected_node(),s=null;if(o){if(o.isroot){for(var r=o.children,a=[],d=0;d<r.length;d++)r[d].direction===i&&a.push(d);s=r[a[Math.floor((a.length-1)/2)]]}else if(o.direction===i){var l=(a=o.children).length;l>0&&(s=a[Math.floor((l-1)/2)])}else s=o.parent;s&&e.select_node(s),n.stopPropagation(),n.preventDefault()}}}class y{constructor(e){this.jm=e,this.plugins=new Map}initPreloadPlugins(){const e=this.jm.constructor.pluginList.filter(e=>e.preload);s.info("Initializing "+e.length+" preload plugins"),e.forEach(e=>{this._initPlugin(e)})}initNormalPlugins(){const e=this.jm.constructor.pluginList.filter(e=>!e.preload);s.info("Initializing "+e.length+" normal plugins"),e.forEach(e=>{this._initPlugin(e)})}_initPlugin(e){try{const{PluginClass:t,pluginOpt:i}=e;if(!t.instanceName)throw new Error("Plugin "+t.name+" must define static instanceName");this.plugins.has(t.instanceName)&&s.warn("Plugin "+t.instanceName+" already exists, will be replaced");const n=new t({jm:this.jm,pluginOpt:i||{}});this.plugins.set(t.instanceName,n),this.jm[t.instanceName]=n,e.instance=n,s.info("Plugin "+t.instanceName+" initialized")}catch(t){s.error("Failed to initialize plugin "+e.PluginClass.name+":",t)}}removePlugin(e){const t=e.instanceName;if(!t)return;const i=this.plugins.get(t);if(i)try{"function"==typeof i.beforePluginRemove&&i.beforePluginRemove(),this.plugins.delete(t),delete this.jm[t];const n=this.jm.constructor.pluginList,o=n.findIndex(t=>t.PluginClass===e);-1!==o&&n.splice(o,1),s.info("Plugin "+t+" removed")}catch(e){s.error("Failed to remove plugin "+t+":",e)}}destroyAllPlugins(){this.plugins.forEach((e,t)=>{try{"function"==typeof e.beforePluginDestroy&&e.beforePluginDestroy()}catch(e){s.error("Failed to destroy plugin "+t+":",e)}}),this.plugins.clear()}getPlugin(e){return this.plugins.get(e)}}class w{static instanceName="";static preload=!1;constructor({jm:e,pluginOpt:t}){this.jm=e,this.options=t||{}}beforePluginRemove(){}beforePluginDestroy(){this.beforePluginRemove()}}class b{static mind=h;static node=l;static direction=t;static event_type=i;static $=r;static plugin=w;static util=a;static plugin_base=w;static pluginList=[];static usePlugin(e,t={}){if(b.pluginList.some(t=>t.PluginClass===e))return s.warn("Plugin "+e.name+" already registered"),b;if(!e.instanceName)throw new Error("Plugin "+e.name+" must define static instanceName");return b.pluginList.push({PluginClass:e,instanceName:e.instanceName,preload:e.preload||!1,pluginOpt:t,instance:null}),b}static hasPlugin(e){return b.pluginList.some(t=>t.PluginClass===e)}constructor(t){b.current=this,this.options=function(e){var t={};if(a.json.merge(t,d),a.json.merge(t,e),!t.container)throw new Error("the options.container should not be null or empty.");return t}(t),s.level(n[this.options.log_level]),this.version=e,this.initialized=!1,this.mind=null,this.event_handles=[],this.init()}init(){if(!this.initialized){this.initialized=!0,this.pluginManager=new y(this),this.pluginManager.initPreloadPlugins();var e={mode:this.options.mode,hspace:this.options.layout.hspace,vspace:this.options.layout.vspace,pspace:this.options.layout.pspace,cousin_space:this.options.layout.cousin_space},t={container:this.options.container,support_html:this.options.support_html,engine:this.options.view.engine,enable_device_pixel_ratio:this.options.view.enable_device_pixel_ratio,hmargin:this.options.view.hmargin,vmargin:this.options.view.vmargin,line_width:this.options.view.line_width,line_color:this.options.view.line_color,line_style:this.options.view.line_style,custom_line_render:this.options.view.custom_line_render,draggable:this.options.view.draggable,hide_scrollbars_when_draggable:this.options.view.hide_scrollbars_when_draggable,node_overflow:this.options.view.node_overflow,zoom:this.options.view.zoom,custom_node_render:this.options.view.custom_node_render,expander_style:this.options.view.expander_style};this.data=new c(this),this.layout=new p(this,e),this.view=new f(this,t),this.shortcut=new m(this,this.options.shortcut),this.data.init(),this.layout.init(),this.view.init(),this.shortcut.init(),this._event_bind(),this.pluginManager.initNormalPlugins()}}get_editable(){return this.options.editable}enable_edit(){this.options.editable=!0}disable_edit(){this.options.editable=!1}get_view_draggable(){return this.options.view.draggable}enable_view_draggable(){this.options.view.draggable=!0,this.view.setup_canvas_draggable(!0)}disable_view_draggable(){this.options.view.draggable=!1,this.view.setup_canvas_draggable(!1)}enable_event_handle(e){this.options.default_event_handle["enable_"+e+"_handle"]=!0}disable_event_handle(e){this.options.default_event_handle["enable_"+e+"_handle"]=!1}set_theme(e){var t=this.options.theme;this.options.theme=e||null,t!=this.options.theme&&(this.view.reset_theme(),this.view.reset_custom_style())}_event_bind(){this.view.add_event(this,"mousedown",this.mousedown_handle),this.view.add_event(this,"click",this.click_handle),this.view.add_event(this,"dblclick",this.dblclick_handle),this.view.add_event(this,"wheel",this.mousewheel_handle,!0)}mousedown_handle(e){if(this.options.default_event_handle.enable_mousedown_handle){var t=e.target||event.srcElement,i=this.view.get_binded_nodeid(t);i?this.view.is_node(t)&&this.select_node(i):this.select_clear()}}click_handle(e){if(this.options.default_event_handle.enable_click_handle){var t=e.target||event.srcElement;if(this.view.is_expander(t)){var i=this.view.get_binded_nodeid(t);i&&this.toggle_node(i)}}}dblclick_handle(e){if(this.options.default_event_handle.enable_dblclick_handle&&this.get_editable()){var t=e.target||event.srcElement;if(this.view.is_node(t)){var i=this.view.get_binded_nodeid(t);i&&this.begin_edit(i)}}}mousewheel_handle(e){var t=(e.metaKey<<13)+(e.ctrlKey<<12)+(e.altKey<<11)+(e.shiftKey<<10);if(this.options.default_event_handle.enable_mousewheel_handle&&this.options.view.zoom.mask_key===t){var i=e||event;i.preventDefault(),i.deltaY<0?this.view.zoom_in(i):this.view.zoom_out(i)}}begin_edit(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.begin_edit(t):(s.error("the node[id="+e+"] can not be found."),!1)}this.get_editable()?this.view.edit_node_begin(e):s.error("fail, this mind map is not editable.")}end_edit(){this.view.edit_node_end()}toggle_node(e){if(!l.is_node(e)){var t=this.get_node(e);return t?void this.toggle_node(t):void s.error("the node[id="+e+"] can not be found.")}e.isroot||(this.view.save_location(e),this.layout.toggle_node(e),this.view.relayout(),this.view.restore_location(e))}expand_node(e){if(!l.is_node(e)){var t=this.get_node(e);return t?void this.expand_node(t):void s.error("the node[id="+e+"] can not be found.")}e.isroot||(this.view.save_location(e),this.layout.expand_node(e),this.view.relayout(),this.view.restore_location(e))}collapse_node(e){if(!l.is_node(e)){var t=this.get_node(e);return t?void this.collapse_node(t):void s.error("the node[id="+e+"] can not be found.")}e.isroot||(this.view.save_location(e),this.layout.collapse_node(e),this.view.relayout(),this.view.restore_location(e))}expand_all(){this.layout.expand_all(),this.view.relayout()}collapse_all(){this.layout.collapse_all(),this.view.relayout()}expand_to_depth(e){this.layout.expand_to_depth(e),this.view.relayout()}_reset(){this.invoke_event_handle(i.reset,{data:[]}),this.view.reset(),this.layout.reset(),this.data.reset()}_show(e,t){var n=e||u.node_array.example;this.mind=this.data.load(n),this.mind?(s.debug("data.load ok"),this.view.load(),s.debug("view.load ok"),this.layout.layout(),s.debug("layout.layout ok"),this.view.show(!t),s.debug("view.show ok"),this.invoke_event_handle(i.show,{data:[e]})):s.error("data.load error")}show(e,t){this._reset(),this._show(e,t)}get_meta(){return{name:this.mind.name,author:this.mind.author,version:this.mind.version}}get_data(e){var t=e||"node_tree";return this.data.get_data(t)}get_root(){return this.mind.root}get_node(e){return l.is_node(e)?e:this.mind.get_node(e)}get_node_level(e){var t=this.get_node(e);if(!t)return s.warn("the node[id="+e+"] can not be found."),-1;if(t.isroot)return 0;for(var i=0,n=t;n.parent&&!n.parent.isroot;)i++,n=n.parent;return i+1}_add_node_data(e,i,n,o,s){var r=t.of(s);void 0===r&&(r=this.layout.calculate_next_child_direction(e));var a=this.mind.add_node(e,i,n,o,r);return a&&(this.view.add_node(a),this.view.reset_node_custom_style(a)),a}_refresh_node_ui(e){this.layout.layout(),this.view.show(!1),this.expand_node(e)}add_node(e,n,o,r,a){if(!this.get_editable())return s.error("fail, this mind map is not editable"),null;var d=this.get_node(e);if(!d)return s.error("parent node not found"),null;var l=this._add_node_data(d,n,o,r,a);return l&&(this._refresh_node_ui(d),this.invoke_event_handle(i.edit,{evt:"add_node",data:[d.id,n,o,r,t.of(a)],node:n})),l}add_nodes(e,t){if(!this.get_editable())return s.error("fail, this mind map is not editable"),[];var n=this.get_node(e);if(!n)return s.error("parent node not found"),[];if(!Array.isArray(t)||0===t.length)return s.warn("nodes_data should be a non-empty array"),[];const o=this._count_expected_nodes(t);let r=t.map(e=>this._add_nodes_recursive(n,e)).flat().filter(e=>null!==e);const a=r.length;return a===o?(this._refresh_node_ui(n),this.invoke_event_handle(i.edit,{evt:"add_nodes",data:[n.id,t],nodes:r.map(e=>e.id)}),r):(s.warn(`Expected ${o} nodes, but only created ${a}. Cleaning up...`),this._cleanup_partial_nodes(r),[])}_add_nodes_recursive(e,t){var i=[];if(!t.id||!t.topic)return s.warn("invalid node data:",t),[];var n=this._add_node_data(e,t.id,t.topic,t.data||{},t.direction);if(n&&(i.push(n),Array.isArray(t.children))){const e=t.children.map(e=>this._add_nodes_recursive(n,e)).flat();i=i.concat(e)}return i}_count_expected_nodes(e){if(!Array.isArray(e))return 0;var t=(this.options.fieldNames||{}).children||"children";return e.reduce((e,i)=>(e++,e+=this._count_expected_nodes(i&&i[t])),0)}_cleanup_partial_nodes(e){0!==e.length&&[...e].reverse().forEach(e=>{e&&!e.isroot&&(this.view.remove_node(e),this.mind.remove_node(e))})}insert_node_before(e,n,o,r,a){if(this.get_editable()){var d=this.get_node(e),l=t.of(a);void 0===l&&(l=this.layout.calculate_next_child_direction(d.parent));var h=this.mind.insert_node_before(d,n,o,r,l);return h&&(this.view.add_node(h),this.layout.layout(),this.view.show(!1),this.invoke_event_handle(i.edit,{evt:"insert_node_before",data:[d.id,n,o,r,l],node:n})),h}return s.error("fail, this mind map is not editable"),null}insert_node_after(e,n,o,r,a){if(this.get_editable()){var d=this.get_node(e),l=t.of(a);void 0===l&&(l=this.layout.calculate_next_child_direction(d.parent));var h=this.mind.insert_node_after(d,n,o,r,l);return h&&(this.view.add_node(h),this.layout.layout(),this.view.show(!1),this.invoke_event_handle(i.edit,{evt:"insert_node_after",data:[d.id,n,o,r,l],node:n})),h}return s.error("fail, this mind map is not editable"),null}remove_node(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.remove_node(t):(s.error("the node[id="+e+"] can not be found."),!1)}if(this.get_editable()){if(e.isroot)return s.error("fail, can not remove root node"),!1;var n=e.id,o=e.parent.id,r=this.get_node(o);return this.view.save_location(r),this.view.remove_node(e),this.mind.remove_node(e),this.layout.layout(),this.view.show(!1),this.view.restore_location(r),this.invoke_event_handle(i.edit,{evt:"remove_node",data:[n],node:o}),!0}return s.error("fail, this mind map is not editable"),!1}update_node(e,t){if(this.get_editable()){var n=this.get_node(e);if(n){if("string"==typeof t)return a.text.is_empty(t)?void s.warn("fail, topic can not be empty"):n.topic===t?(s.info("nothing changed"),void this.view.update_node(n)):(n.topic=t,this.view.update_node(n),this.layout.layout(),this.view.show(!1),void this.invoke_event_handle(i.edit,{evt:"update_node",data:[e,t],node:e}));if("object"==typeof t&&null!==t){var o=n.id,r=!1;if(void 0!==t.topic){if(a.text.is_empty(t.topic))return void s.warn("fail, topic can not be empty");n.topic!==t.topic&&(n.topic=t.topic,r=!0)}if(t.data&&"object"==typeof t.data)for(var d in t.data)t.data.hasOwnProperty(d)&&n.data[d]!==t.data[d]&&(n.data[d]=t.data[d],r=!0);if(void 0!==t.id){if("string"!=typeof t.id||""===t.id.trim())return void s.error("fail, new node id must be a non-empty string");if(n.id!==t.id){if(n.isroot)return void s.error("fail, cannot change root node id");if(t.id in this.mind.nodes)return void s.error('fail, new id "'+t.id+'" already exists');var l=n.id;delete this.mind.nodes[l],n.id=t.id,this.mind.nodes[t.id]=n,this.mind.selected&&this.mind.selected.id===l&&(this.mind.selected=n),r=!0}}if(["index","expanded","direction"].forEach(function(e){void 0!==t[e]&&n[e]!==t[e]&&(n[e]=t[e],r=!0)}),!r)return s.info("nothing changed"),void this.view.update_node(n);this.view.update_node(n),this.layout.layout(),this.view.show(!1),this.invoke_event_handle(i.edit,{evt:"update_node",data:[o,t],node:o})}}else s.error("fail, node not found")}else s.error("fail, this mind map is not editable")}move_node(e,t,n,o){if(this.get_editable()){var r=this.get_node(e),a=this.mind.move_node(r,t,n,o);a&&(this.view.update_node(a),this.layout.layout(),this.view.show(!1),this.invoke_event_handle(i.edit,{evt:"move_node",data:[e,t,n,o],node:e}))}else s.error("fail, this mind map is not editable")}select_node(e){if(!l.is_node(e)){var t=this.get_node(e);return t?void this.select_node(t):void s.error("the node[id="+e+"] can not be found.")}this.layout.is_visible(e)&&(this.mind.selected=e,this.view.select_node(e),this.invoke_event_handle(i.select,{evt:"select_node",data:[],node:e.id}))}get_selected_node(){return this.mind?this.mind.selected:null}select_clear(){this.mind&&(this.mind.selected=null,this.view.select_clear())}is_node_visible(e){return this.layout.is_visible(e)}scroll_node_to_center(e){if(l.is_node(e))this.view.center_node(e);else{var t=this.get_node(e);t?this.scroll_node_to_center(t):s.error("the node[id="+e+"] can not be found.")}}find_node_before(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.find_node_before(t):void s.error("the node[id="+e+"] can not be found.")}if(e.isroot)return null;var i=null;if(e.parent.isroot)for(var n=e.parent.children,o=null,r=null,a=0;a<n.length;a++)r=n[a],e.direction===r.direction&&(e.id===r.id&&(i=o),o=r);else i=this.mind.get_node_before(e);return i}find_node_after(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.find_node_after(t):void s.error("the node[id="+e+"] can not be found.")}if(e.isroot)return null;var i=null;if(e.parent.isroot){for(var n=e.parent.children,o=!1,r=null,a=0;a<n.length;a++)if(r=n[a],e.direction===r.direction){if(o){i=r;break}e.id===r.id&&(o=!0)}}else i=this.mind.get_node_after(e);return i}set_node_color(e,t,i){if(!this.get_editable())return s.error("fail, this mind map is not editable"),null;var n=this.mind.get_node(e);n&&(t&&(n.data["background-color"]=t),i&&(n.data["foreground-color"]=i),this.view.reset_node_custom_style(n))}set_node_font_style(e,t,i,n){if(!this.get_editable())return s.error("fail, this mind map is not editable"),null;var o=this.mind.get_node(e);o&&(t&&(o.data["font-size"]=t),i&&(o.data["font-weight"]=i),n&&(o.data["font-style"]=n),this.view.reset_node_custom_style(o),this.view.update_node(o),this.layout.layout(),this.view.show(!1))}set_node_background_image(e,t,i,n,o){if(!this.get_editable())return s.error("fail, this mind map is not editable"),null;var r=this.mind.get_node(e);r&&(t&&(r.data["background-image"]=t),i&&(r.data.width=i),n&&(r.data.height=n),o&&(r.data["background-rotation"]=o),this.view.reset_node_custom_style(r),this.view.update_node(r),this.layout.layout(),this.view.show(!1))}set_node_background_rotation(e,t){if(!this.get_editable())return s.error("fail, this mind map is not editable"),null;var i=this.mind.get_node(e);if(i){if(!i.data["background-image"])return s.error("fail, only can change rotation angle of node with background image"),null;i.data["background-rotation"]=t,this.view.reset_node_custom_style(i),this.view.update_node(i),this.layout.layout(),this.view.show(!1)}}resize(){this.view.resize()}add_event_listener(e){"function"==typeof e&&this.event_handles.push(e)}clear_event_listener(){this.event_handles=[]}invoke_event_handle(e,t){var i=this;r.w.setTimeout(function(){i._invoke_event_handle(e,t)},0)}_invoke_event_handle(e,t){for(var i=this.event_handles.length,n=0;n<i;n++)this.event_handles[n](e,t)}removePlugin(e){this.pluginManager&&this.pluginManager.removePlugin(e)}getPlugin(e){if(this.pluginManager)return this.pluginManager.getPlugin(e)}destroy(){this.pluginManager&&this.pluginManager.destroyAllPlugins(),this.clear_event_listener(),this.view&&this.view.reset(),this.mind=null,this.initialized=!1}static show(e,t){s.warn("`jsMind.show(options, mind)` is deprecated, please use `jm = new jsMind(options); jm.show(mind);` instead");var i=new b(e);return i.show(t),i}}module.exports=b;
2573
9
  //# sourceMappingURL=jsmind.js.map