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