@umbraci/jsmind 0.10.13 → 0.10.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/jsmind.js +1 -1
- package/dist/jsmind.js.map +1 -1
- package/dist/jsmind.multi-select.js +9 -0
- package/dist/jsmind.multi-select.js.map +1 -0
- package/es/jsmind.js +1 -1
- package/es/jsmind.js.map +1 -1
- package/es/jsmind.multi-select.js +9 -0
- package/es/jsmind.multi-select.js.map +1 -0
- package/lib/jsmind.js +1 -1
- package/lib/jsmind.js.map +1 -1
- package/lib/jsmind.multi-select.js +9 -0
- package/lib/jsmind.multi-select.js.map +1 -0
- package/package.json +5 -1
- package/types/generated/index.d.ts +0 -8
- package/types/generated/jsmind.common.d.ts +0 -68
- package/types/generated/jsmind.d.ts +0 -632
- package/types/generated/jsmind.data_provider.d.ts +0 -56
- package/types/generated/jsmind.dom.d.ts +0 -59
- package/types/generated/jsmind.enhanced-plugin.d.ts +0 -103
- package/types/generated/jsmind.format.d.ts +0 -113
- package/types/generated/jsmind.graph.d.ts +0 -180
- package/types/generated/jsmind.layout_provider.d.ts +0 -182
- package/types/generated/jsmind.mind.d.ts +0 -129
- package/types/generated/jsmind.node.d.ts +0 -69
- package/types/generated/jsmind.option.d.ts +0 -79
- package/types/generated/jsmind.plugin.d.ts +0 -21
- package/types/generated/jsmind.shortcut_provider.d.ts +0 -52
- package/types/generated/jsmind.util.d.ts +0 -26
- package/types/generated/jsmind.view_provider.d.ts +0 -374
- package/types/generated/plugins/history/history-diff.d.ts +0 -310
- package/types/generated/plugins/history/jsmind.history.d.ts +0 -87
- package/types/generated/plugins/jsmind.draggable-node.d.ts +0 -262
- package/types/generated/plugins/jsmind.multiline-text-v2.d.ts +0 -58
- package/types/generated/plugins/jsmind.multiline-text.d.ts +0 -43
- package/types/generated/plugins/jsmind.screenshot.d.ts +0 -83
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jsMindMultiSelect={})}(this,(function(e){"use strict";"function"!=typeof String.prototype.startsWith&&(String.prototype.startsWith=function(e){return this.slice(0,e.length)===e});const t=1,s=4,i=1,n=2,l=3,o=4;var _=function(){};let d="undefined"==typeof console?{level:_,log:_,debug:_,info:_,warn:_,error:_}:{level:function(e){d.debug=e>i?_:console.debug;d.info=e>n?_:console.info;d.warn=e>l?_:console.warn;d.error=e>o?_:console.error},log:console.log,debug:console.debug,info:console.info,warn:console.warn,error:console.error};class c{static instanceName="";static preload=!1;constructor({jm:e,pluginOpt:t}){this.jm=e,this.options=t||{}}beforePluginRemove(){}beforePluginDestroy(){this.beforePluginRemove()}}const r={enable_multi_select:!1,include_descendants:!0,shift_simple_mode:!1,allow_ctrl:!0,allow_shift:!0,filter:null};class h{constructor(e,t){this.jm=e,this.options=t,this._ensure_selection_state(),this._selection_mode=null,this._last_selected_node=null}_ensure_selection_state(){this.jm.mind||(this.jm.mind={}),this.jm.mind.selected_nodes||(this.jm.mind.selected_nodes=new Set),this.jm.view||(this.jm.view={}),this.jm.view.multi_selected_nodes||(this.jm.view.multi_selected_nodes=new Map)}get_selected_nodes(){return this._ensure_selection_state(),this.jm.mind&&this.jm.mind.selected_nodes?Array.from(this.jm.mind.selected_nodes).map((e=>e.id)):[]}is_node_selected(e){const t=this._resolve_node(e);return!(!t||!this.jm.mind)&&(this._ensure_selection_state(),this.jm.mind.selected_nodes.has(t))}select_node(e){const t=this._resolve_node(e);if(!t)return void d.error("[multiSelect] node not found: "+e);if(this._ensure_selection_state(),this._clear_selection_state(),this._ensure_selection_state(),!this.jm.mind||!this.jm.mind.selected_nodes)return void d.error("[multiSelect] jm.mind or selected_nodes is not available");this.jm.mind.selected=t,this._last_selected_node=t,this.jm.mind.selected_nodes.has(t)||this.jm.mind.selected_nodes.add(t),this._mark_node_selected(t),this._selection_mode="single";const s=[t.id];this._invoke_select_event({evt:"select_node",data:s,node:t.id,nodes:s})}select_clear(){this._ensure_selection_state(),this.jm.mind&&(this.jm.mind.selected=null,this._last_selected_node=null,this._clear_selection_state())}toggle_node_selection(e){const t=this._resolve_node(e);if(t&&this.jm.layout.is_visible(t))if(this._ensure_selection_state(),this.jm.mind.selected_nodes.has(t))this._deselect_subtree(t);else{this._selection_mode="multi";this._append_selection([t]).length&&(this.jm.mind.selected=t,this._last_selected_node=t,this._invoke_select_event({evt:"multi_select",data:[t.id],node:t.id,nodes:[t.id]}))}}toggle_subtree_selection(e,t){const s=this._resolve_node(e);if(!s)return void d.error("[multiSelect] node not found: "+e);if(!this.jm.layout.is_visible(s))return;const i=t&&void 0!==t.include_descendants?!!t.include_descendants:!1!==this.options.include_descendants;if(this._ensure_selection_state(),this.jm.mind.selected_nodes.has(s)&&"multi"===this._selection_mode){let e=this._collect_subtree_nodes(s,{includeChildren:!0,respectFilter:!1,skipRootFilter:!1});e.length||(e=[s]);const t=this._remove_selection(e);if(t.length){this.jm.mind.selected&&this.jm.mind.selected.id===s.id&&(this.jm.mind.selected=null),this._selection_mode=this._derive_selection_mode();const e=t.map((e=>e.id));this._invoke_select_event({evt:"multi_deselect",data:e,node:s.id,nodes:e})}}else{this._selection_mode="multi";let e=this._collect_subtree_nodes(s,{includeChildren:i,respectFilter:!0,skipRootFilter:!0});e.length||(e=[s]);const t=this._append_selection(e,{focusNode:s});this._ensure_selection_state();const n=s.parent&&!this.jm.mind.selected_nodes.has(s.parent)?this._ensure_ancestor_selection([s],s,{requireAncestorChainSelected:!0}):[],l=t.concat(n);if(l.length){this.jm.mind.selected=s;const e=l.map((e=>e.id));this._invoke_select_event({evt:"multi_select",data:e,node:s.id,nodes:e})}}}get_selection_mode(){return this._selection_mode}_handle_node_click(e){const{e:t,node:s,element:i}=e;if(!s||!i)return;this._ensure_selection_state();const n=this._get_multi_select_mode(t);if("ctrl"===n)this.toggle_node_selection(s);else if("shift"===n){const e=this.jm.get_node(s);if(!e)return void d.warn("[multiSelect] Node not found for shift selection: "+s);if(this.options.shift_simple_mode)this.is_node_selected(s)?this._deselect_subtree(e):this._range_select_nodes(s);else if(this.is_node_selected(s))this._deselect_subtree(e);else{const t=!1!==this.options.include_descendants;let s=this._collect_subtree_nodes(e,{includeChildren:t,respectFilter:!0,skipRootFilter:!0});s.length||(s=[e]);const i=this._append_selection(s,{focusNode:e});if(i.length){this.jm.mind.selected=e,this._last_selected_node=e,this._selection_mode=this._derive_selection_mode();const t=i.map((e=>e.id));this._invoke_select_event({evt:"multi_select",data:t,node:e.id,nodes:t})}else this._ensure_selection_state(),this.jm.mind.selected_nodes.has(e)||(this.jm.mind.selected_nodes.add(e),this._mark_node_selected(e)),this.jm.mind.selected=e,this._last_selected_node=e,this._selection_mode=this._derive_selection_mode(),this._invoke_select_event({evt:"multi_select",data:[e.id],node:e.id,nodes:[e.id]})}}else this.select_node(s)}_handle_node_removed(e){this._ensure_selection_state(),this.jm.mind.selected_nodes.has(e)&&this.jm.mind.selected_nodes.delete(e),this._last_selected_node&&this._last_selected_node.id===e.id&&(this._last_selected_node=null),this.jm.view.multi_selected_nodes&&this.jm.view.multi_selected_nodes.has(e.id)&&this._unmark_node_selected(e)}_get_multi_select_mode(e){return e?!1!==this.options.allow_shift&&!0===e.shiftKey?"shift":!1===this.options.allow_ctrl||!0!==e.ctrlKey&&!0!==e.metaKey?null:"ctrl":null}_append_selection(e,t){if(!e||!e.length)return[];if(this._ensure_selection_state(),!this.jm.mind||!this.jm.mind.selected_nodes)return d.warn("[multiSelect] Cannot append selection: selected_nodes not available"),[];const s=[];for(let t=0;t<e.length;t++){const i=e[t];this.jm.mind.selected_nodes.has(i)||(this.jm.mind.selected_nodes.add(i),s.push(i))}if(s.length){const e=t&&t.focusNode?t.focusNode:null;this._mark_nodes_selected(s,e||s[s.length-1])}return s}_remove_selection(e){if(!e||!e.length)return[];this._ensure_selection_state();const t=[];for(let s=0;s<e.length;s++){const i=e[s];this.jm.mind.selected_nodes.has(i)&&(this.jm.mind.selected_nodes.delete(i),t.push(i))}return t.length&&this._unmark_nodes_selected(t),t}_deselect_subtree(e){let t=this._collect_subtree_nodes(e,{includeChildren:!0,respectFilter:!1,skipRootFilter:!1});t.length||(t=[e]);const s=this._remove_selection(t);if(s.length){this.jm.mind.selected&&this.jm.mind.selected.id===e.id&&(this.jm.mind.selected=null),this._selection_mode=this._derive_selection_mode();const t=s.map((e=>e.id));this._invoke_select_event({evt:"multi_deselect",data:t,node:e.id,nodes:t})}}_clear_selection_state(){if(this._ensure_selection_state(),this._selection_mode=null,this.jm.mind&&this.jm.mind.selected_nodes||this._ensure_selection_state(),!this.jm.mind||!this.jm.mind.selected_nodes||0===this.jm.mind.selected_nodes.size)return this._clear_all_selected_nodes_view(),[];const e=Array.from(this.jm.mind.selected_nodes);return this.jm.mind.selected_nodes.clear(),this._unmark_nodes_selected(e),e}_collect_subtree_nodes(e,t){const s=t||{},i=!1!==s.includeChildren,n=!!s.respectFilter,l=!!s.skipRootFilter,o=n?this._get_selection_filter():null,_=[],d=(e,t)=>{let s=!0;if(!o||l&&t||(s=!1!==o(e)),s&&_.push(e),i&&e.children)for(let t=0;t<e.children.length;t++)d(e.children[t],!1)};return d(e,!0),_}_ensure_ancestor_selection(e,t,s){if(!e||!e.length)return[];this._ensure_selection_state();const i=!(!s||!s.requireAncestorChainSelected),n=[],l=Object.create(null);for(let t=0;t<e.length;t++){let s=e[t].parent;if(!s)continue;const o=[];let _=!i;for(;s;){if(this.jm.mind.selected_nodes.has(s)){_=!0;break}o.push(s),s=s.parent}if(_)for(let e=0;e<o.length;e++){const t=o[e];this.jm.mind.selected_nodes.has(t)||l[t.id]||(n.push(t),l[t.id]=!0)}}if(!n.length)return[];const o=t||e[e.length-1];return this._append_selection(n,{focusNode:o})}_get_selection_filter(){return this.options&&"function"==typeof this.options.filter?this.options.filter:null}_range_select_nodes(e){const t=this._resolve_node(e);if(!t||!this.jm.layout.is_visible(t))return;if(this._ensure_selection_state(),0===this.jm.mind.selected_nodes.size){let e=this._collect_subtree_nodes(t,{includeChildren:!0,respectFilter:!0,skipRootFilter:!0});e.length||(e=[t]);const s=this._append_selection(e);if(s.length){this.jm.mind.selected=t,this._last_selected_node=t,this._selection_mode=this._derive_selection_mode();const e=s.map((e=>e.id));this._invoke_select_event({evt:"multi_select",data:e,node:t.id,nodes:e})}return}this._ensure_selection_state();const s=Array.from(this.jm.mind.selected_nodes),i=this._last_selected_node&&this.jm.mind.selected_nodes.has(this._last_selected_node)?this._last_selected_node:s[0],n=this._find_nodes_between(i,t);if(!n.length){const e=[t],s=this._append_selection(e);if(s.length){this.jm.mind.selected=t,this._last_selected_node=t,this._selection_mode=this._derive_selection_mode();const e=s.map((e=>e.id));this._invoke_select_event({evt:"multi_select",data:e,node:t.id,nodes:e})}return}this._ensure_selection_state();const l=n.filter((e=>!this.jm.mind.selected_nodes.has(e))),o=this._append_selection(l);if(o.length){this.jm.mind.selected=t,this._last_selected_node=t,this._selection_mode=this._derive_selection_mode();const e=o.map((e=>e.id));this._invoke_select_event({evt:"multi_select",data:e,node:t.id,nodes:e})}}_find_nodes_between(e,t){if(!e||!t)return[];const s=[],i=e=>{if(this.jm.layout.is_visible(e)&&s.push(e),e.children)for(let t=0;t<e.children.length;t++)i(e.children[t])};this.jm.mind&&this.jm.mind.root&&i(this.jm.mind.root);let n=-1,l=-1;for(let i=0;i<s.length;i++)s[i].id===e.id&&(n=i),s[i].id===t.id&&(l=i);if(-1===n||-1===l)return[];const o=Math.min(n,l),_=Math.max(n,l);return s.slice(o,_+1)}_derive_selection_mode(){this._ensure_selection_state();const e=this.jm.mind.selected_nodes.size;return 0===e?null:e>1?"multi":"single"}_mark_nodes_selected(e,t){if(e&&e.length){for(let t=0;t<e.length;t++)this._mark_node_selected(e[t]);this.jm.view.selected_node=t||e[e.length-1]}}_mark_node_selected(e){if(!e||this.jm.view.multi_selected_nodes.has(e.id))return;const t=e._data&&e._data.view&&e._data.view.element;t&&(t.classList?t.classList.add("selected"):/(\s|^)selected(\s|$)/.test(t.className)||(t.className+=" selected"),this.jm.view.multi_selected_nodes.set(e.id,e))}_unmark_nodes_selected(e){if(e&&e.length)for(let t=0;t<e.length;t++)this._unmark_node_selected(e[t])}_unmark_node_selected(e){if(e){if(this.jm.view.multi_selected_nodes.has(e.id)){const t=e._data&&e._data.view&&e._data.view.element;t&&(t.classList?t.classList.remove("selected"):t.className=t.className.replace(/\s*selected\b/i,"")),this.jm.view.multi_selected_nodes.delete(e.id)}this.jm.view.selected_node&&this.jm.view.selected_node.id===e.id&&(this.jm.view.selected_node=null)}}_clear_all_selected_nodes_view(){if(this._ensure_selection_state(),!this.jm.view.multi_selected_nodes||!this.jm.view.multi_selected_nodes.size)return void(this.jm.view&&(this.jm.view.selected_node=null));const e=Array.from(this.jm.view.multi_selected_nodes.values());for(let t=0;t<e.length;t++)this._unmark_node_selected(e[t]);this.jm.view&&(this.jm.view.selected_node=null)}_invoke_select_event(e){try{e.nodes||(e.nodes=e.data||[]),e.data||(e.data=e.nodes||[]),this.jm.invoke_event_handle(s,e)}catch(e){d.warn("[multiSelect] failed to invoke select event",e)}}_resolve_node(e){return e?"string"==typeof e?this.jm.get_node(e):e:null}}class a extends c{static instanceName="multiSelectPlugin";static preload=!1;constructor({jm:e,pluginOpt:t}){super({jm:e,pluginOpt:t});const s=Object.assign({},r,t||{});this.options=s,this._mounted=!1,this._core=null,this._listener=null,this._enabled=!!s.enable_multi_select,this._initCore()}_initCore(){const e=this.jm,s=this.options,i=this;this._core=new h(e,s),this._mountAPI(),this._listener=(e,s)=>{try{e===t&&i._core.select_clear()}catch(e){d.warn("[multiSelect] listener error",e)}},e.add_event_listener(this._listener),this._original_select_node=e.select_node.bind(e),this._original_select_clear=e.select_clear.bind(e),e.select_node=e=>i._enabled?i._core.select_node(e):i._original_select_node(e),e.select_clear=()=>i._enabled?i._core.select_clear():i._original_select_clear();const n=e.constructor.$;this._domClickHandler=function(t){if(!i._enabled)return;const s=t.target||t.currentTarget,n=e.view.get_binded_nodeid(s);n&&e.view.is_node(s)?(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation&&t.stopImmediatePropagation(),i._core._handle_node_click({e:t,node:n,element:s,evt:"click"})):n||t.ctrlKey||t.metaKey||t.shiftKey||i._core.select_clear()},e.view&&e.view.e_nodes?(n.on(e.view.e_nodes,"click",this._domClickHandler),d.info("[multiSelect] plugin click handler attached")):d.warn("[multiSelect] nodes container not ready; DOM handler not attached"),this._enabled&&"function"==typeof e.disable_event_handle&&e.disable_event_handle("mousedown"),d.info("[multiSelect] API mounted and event listener attached.")}_mountAPI(){if(this._mounted)return;const e=this.jm,t=this,s={get_selected_nodes:()=>t._core?t._core.get_selected_nodes():(d.warn("[multiSelect] Core not initialized"),[]),is_node_selected:e=>!!t._core&&t._core.is_node_selected(e),select_node:e=>{t._core?t._core.select_node(e):d.warn("[multiSelect] Core not initialized")},select_clear:()=>{t._core&&t._core.select_clear()},toggle_node_selection:e=>{t._core?t._core.toggle_node_selection(e):d.warn("[multiSelect] Core not initialized")},toggle_subtree_selection:e=>{t._core?t._core.toggle_subtree_selection(e):d.warn("[multiSelect] Core not initialized")},get_selection_mode:()=>t._core?t._core.get_selection_mode():null,getOptions:()=>{const e=t._core?t._core.options:t.options;return Object.assign({},e,{enable_multi_select:t._enabled})},enable:()=>t.setEnabled(!0),disable:()=>t.setEnabled(!1),setEnabled:e=>t.setEnabled(e),setOptions:e=>t.setOptions(e)};Object.defineProperty(e,"multiSelect",{value:s,configurable:!0,enumerable:!1,writable:!1}),this._mounted=!0,d.info("[multiSelect] API mounted.")}beforePluginRemove(){try{if(this._listener&&this.jm&&Array.isArray(this.jm.event_handles)){const e=this.jm.event_handles.indexOf(this._listener);e>=0&&this.jm.event_handles.splice(e,1)}"function"==typeof this.jm.enable_event_handle&&this.jm.enable_event_handle("mousedown"),this._domClickHandler&&this.jm&&this.jm.view&&this.jm.view.e_nodes&&(this._domClickHandler=null),this._original_select_node&&(this.jm.select_node=this._original_select_node),this._original_select_clear&&(this.jm.select_clear=this._original_select_clear),this.jm&&Object.prototype.hasOwnProperty.call(this.jm,"multiSelect")&&delete this.jm.multiSelect,this._mounted=!1}catch(e){d.error("[multiSelect] remove failed:",e)}}setEnabled(e){const t=!!e;this._enabled!==t&&(this._enabled=t,this.options.enable_multi_select=this._enabled,this._enabled?"function"==typeof this.jm.disable_event_handle&&this.jm.disable_event_handle("mousedown"):"function"==typeof this.jm.enable_event_handle&&this.jm.enable_event_handle("mousedown"))}setOptions(e){const t=Object.assign({},e||{});this.options=Object.assign({},this.options,t),this._core&&this._core.options&&(this._core.options=Object.assign({},this._core.options,t))}beforePluginDestroy(){d.debug("[multiSelect] beforePluginDestroy"),this.beforePluginRemove()}}e.MultiSelectCore=h,e.MultiSelectPlugin=a,e.default=a,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
9
|
+
//# sourceMappingURL=jsmind.multi-select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsmind.multi-select.js","sources":["../src/jsmind.common.js","../src/jsmind.enhanced-plugin.js","../src/plugins/jsmind.multi-select.js"],"sourcesContent":["/**\r\n * @license BSD\r\n * @copyright 2014-2025 UmbraCi\r\n *\r\n * Project Home:\r\n * https://github.com/UmbraCi/jsmind/\r\n */\r\n\r\n/**\r\n * Library version string.\r\n * @type {string}\r\n */\r\nexport const __version__ = '0.9.0';\r\n/**\r\n * Library author.\r\n * @type {string}\r\n */\r\nexport const __author__ = 'UmbraCi';\r\n\r\nif (typeof String.prototype.startsWith != 'function') {\r\n String.prototype.startsWith = function (p) {\r\n return this.slice(0, p.length) === p;\r\n };\r\n}\r\n\r\n/**\r\n * Direction constants and parser.\r\n * @typedef {{left:number,center:number,right:number,of:(dir:(string|number))=>number|undefined}} DirectionType\r\n */\r\n/** @type {DirectionType} */\r\nexport const Direction = {\r\n left: -1,\r\n center: 0,\r\n right: 1,\r\n of: function (dir) {\r\n if (!dir || dir === -1 || dir === 0 || dir === 1) {\r\n return dir;\r\n }\r\n if (dir === '-1' || dir === '0' || dir === '1') {\r\n return parseInt(dir);\r\n }\r\n if (dir.toLowerCase() === 'left') {\r\n return this.left;\r\n }\r\n if (dir.toLowerCase() === 'right') {\r\n return this.right;\r\n }\r\n if (dir.toLowerCase() === 'center') {\r\n return this.center;\r\n }\r\n },\r\n};\r\n/** @enum {number} */\r\nexport const EventType = { show: 1, resize: 2, edit: 3, select: 4, reset: 5, history_change: 6 };\r\n/** @enum {number} */\r\nexport const Key = { meta: 1 << 13, ctrl: 1 << 12, alt: 1 << 11, shift: 1 << 10 };\r\n/** @enum {number} */\r\nexport const LogLevel = { debug: 1, info: 2, warn: 3, error: 4, disable: 9 };\r\n\r\n// an noop function define\r\nvar _noop = function () {};\r\n/**\r\n * Logger facade with dynamic level.\r\n * @type {{level:(lvl:number)=>void,log:Function,debug:Function,info:Function,warn:Function,error:Function}}\r\n */\r\nexport let logger =\r\n typeof console === 'undefined'\r\n ? {\r\n level: _noop,\r\n log: _noop,\r\n debug: _noop,\r\n info: _noop,\r\n warn: _noop,\r\n error: _noop,\r\n }\r\n : {\r\n level: setup_logger_level,\r\n log: console.log,\r\n debug: console.debug,\r\n info: console.info,\r\n warn: console.warn,\r\n error: console.error,\r\n };\r\n\r\n/**\r\n * Set logger level.\r\n * @param {number} log_level\r\n */\r\nfunction setup_logger_level(log_level) {\r\n if (log_level > LogLevel.debug) {\r\n logger.debug = _noop;\r\n } else {\r\n logger.debug = console.debug;\r\n }\r\n if (log_level > LogLevel.info) {\r\n logger.info = _noop;\r\n } else {\r\n logger.info = console.info;\r\n }\r\n if (log_level > LogLevel.warn) {\r\n logger.warn = _noop;\r\n } else {\r\n logger.warn = console.warn;\r\n }\r\n if (log_level > LogLevel.error) {\r\n logger.error = _noop;\r\n } else {\r\n logger.error = console.error;\r\n }\r\n}\r\n","/**\r\n * @license BSD\r\n * @copyright 2014-2025 UmbraCi\r\n *\r\n * Project Home:\r\n * https://github.com/UmbraCi/jsmind/\r\n */\r\n\r\nimport { logger } from './jsmind.common.js';\r\n\r\n/**\r\n * Enhanced Plugin Manager\r\n * Manages the lifecycle of enhanced plugins with synchronous initialization,\r\n * preload support, and lifecycle hooks.\r\n */\r\nexport class EnhancedPluginManager {\r\n /**\r\n * @param {import('./jsmind.js').default} jm - jsMind instance\r\n */\r\n constructor(jm) {\r\n this.jm = jm;\r\n /** @type {Map<string, EnhancedPlugin>} */\r\n this.plugins = new Map();\r\n }\r\n\r\n /**\r\n * Initialize preload plugins (before core modules)\r\n */\r\n initPreloadPlugins() {\r\n const preloadPlugins = this.jm.constructor.enhancedPluginList.filter(d => d.preload);\r\n logger.info('Initializing ' + preloadPlugins.length + ' preload plugins');\r\n preloadPlugins.forEach(descriptor => {\r\n this._initPlugin(descriptor);\r\n });\r\n }\r\n\r\n /**\r\n * Initialize normal plugins (after core modules)\r\n */\r\n initNormalPlugins() {\r\n const normalPlugins = this.jm.constructor.enhancedPluginList.filter(d => !d.preload);\r\n logger.info('Initializing ' + normalPlugins.length + ' normal plugins');\r\n normalPlugins.forEach(descriptor => {\r\n this._initPlugin(descriptor);\r\n });\r\n }\r\n\r\n /**\r\n * Internal method: Initialize a single plugin\r\n * @param {PluginDescriptor} descriptor\r\n * @private\r\n */\r\n _initPlugin(descriptor) {\r\n try {\r\n const { PluginClass, pluginOpt } = descriptor;\r\n\r\n // Check instanceName\r\n if (!PluginClass.instanceName) {\r\n throw new Error('Plugin ' + PluginClass.name + ' must define static instanceName');\r\n }\r\n\r\n // Check naming conflict\r\n if (this.plugins.has(PluginClass.instanceName)) {\r\n logger.warn(\r\n 'Plugin ' + PluginClass.instanceName + ' already exists, will be replaced'\r\n );\r\n }\r\n\r\n // Instantiate plugin\r\n const instance = new PluginClass({\r\n jm: this.jm,\r\n pluginOpt: pluginOpt || {},\r\n });\r\n\r\n // Save instance\r\n this.plugins.set(PluginClass.instanceName, instance);\r\n this.jm[PluginClass.instanceName] = instance;\r\n descriptor.instance = instance;\r\n\r\n logger.info('Enhanced plugin ' + PluginClass.instanceName + ' initialized');\r\n } catch (error) {\r\n logger.error('Failed to initialize plugin ' + descriptor.PluginClass.name + ':', error);\r\n }\r\n }\r\n\r\n /**\r\n * Remove a plugin\r\n * @param {typeof EnhancedPlugin} PluginClass\r\n */\r\n removePlugin(PluginClass) {\r\n const instanceName = PluginClass.instanceName;\r\n if (!instanceName) {\r\n return;\r\n }\r\n\r\n const instance = this.plugins.get(instanceName);\r\n if (!instance) {\r\n return;\r\n }\r\n\r\n try {\r\n // Call lifecycle hook\r\n if (typeof instance.beforePluginRemove === 'function') {\r\n instance.beforePluginRemove();\r\n }\r\n\r\n // Remove from Map\r\n this.plugins.delete(instanceName);\r\n\r\n // Remove from jsMind instance\r\n delete this.jm[instanceName];\r\n\r\n // Remove from plugin list\r\n const list = this.jm.constructor.enhancedPluginList;\r\n const index = list.findIndex(d => d.PluginClass === PluginClass);\r\n if (index !== -1) {\r\n list.splice(index, 1);\r\n }\r\n\r\n logger.info('Enhanced plugin ' + instanceName + ' removed');\r\n } catch (error) {\r\n logger.error('Failed to remove plugin ' + instanceName + ':', error);\r\n }\r\n }\r\n\r\n /**\r\n * Destroy all plugins\r\n */\r\n destroyAllPlugins() {\r\n this.plugins.forEach((instance, instanceName) => {\r\n try {\r\n // Call lifecycle hook\r\n if (typeof instance.beforePluginDestroy === 'function') {\r\n instance.beforePluginDestroy();\r\n }\r\n } catch (error) {\r\n logger.error('Failed to destroy plugin ' + instanceName + ':', error);\r\n }\r\n });\r\n\r\n this.plugins.clear();\r\n }\r\n\r\n /**\r\n * Get plugin instance by name\r\n * @param {string} instanceName\r\n * @returns {EnhancedPlugin | undefined}\r\n */\r\n getPlugin(instanceName) {\r\n return this.plugins.get(instanceName);\r\n }\r\n}\r\n\r\n/**\r\n * Enhanced Plugin Base Class\r\n * Provides standard interface for enhanced plugins\r\n */\r\nexport class EnhancedPlugin {\r\n /**\r\n * Plugin instance name (must be defined by subclass)\r\n * @type {string}\r\n */\r\n static instanceName = '';\r\n\r\n /**\r\n * Whether to initialize before core modules\r\n * @type {boolean}\r\n */\r\n static preload = false;\r\n\r\n /**\r\n * @param {{ jm: import('./jsmind.js').default, pluginOpt: object }} params\r\n */\r\n constructor({ jm, pluginOpt }) {\r\n this.jm = jm;\r\n this.options = pluginOpt || {};\r\n }\r\n\r\n /**\r\n * Called before plugin is removed\r\n * Override this method to clean up resources\r\n */\r\n beforePluginRemove() {\r\n // Default implementation: do nothing\r\n }\r\n\r\n /**\r\n * Called before jsMind instance is destroyed\r\n * Override this method to clean up resources\r\n */\r\n beforePluginDestroy() {\r\n // Default implementation: call beforePluginRemove\r\n this.beforePluginRemove();\r\n }\r\n}\r\n\r\n/**\r\n * Plugin descriptor\r\n * @typedef {object} PluginDescriptor\r\n * @property {typeof EnhancedPlugin} PluginClass - Plugin class\r\n * @property {string} instanceName - Plugin instance name\r\n * @property {boolean} preload - Whether to preload\r\n * @property {object} pluginOpt - Plugin options\r\n * @property {EnhancedPlugin | null} instance - Plugin instance (after initialization)\r\n */\r\n","/**\r\n * @license BSD\r\n * @copyright 2014-2025 UmbraCi\r\n *\r\n * Project Home:\r\n * https://github.com/UmbraCi/jsmind/\r\n */\r\n\r\nimport {EnhancedPlugin} from '../jsmind.enhanced-plugin.js';\r\nimport {EventType, logger} from '../jsmind.common.js';\r\n\r\n/**\r\n * Default options for multi-select plugin.\r\n * @typedef {Object} MultiSelectOptions\r\n * @property {boolean} [enable_multi_select=true] - Enable multi-select feature\r\n * @property {boolean} [include_descendants=true] - Include descendants in subtree selection\r\n * @property {boolean} [shift_simple_mode=false] - Shift mode: false=simple subtree, true=advanced range\r\n * @property {((node:import('../jsmind.node.js').Node)=>boolean)|null} [filter=null] - Node filter function\r\n */\r\nconst DEFAULT_OPTIONS = {\r\n enable_multi_select: false, // default off; can be enabled at runtime\r\n include_descendants: true,\r\n shift_simple_mode: false,\r\n allow_ctrl: true,\r\n allow_shift: true,\r\n filter: null,\r\n};\r\n\r\n/**\r\n * Multi-Select Core - Handles all multi-select logic\r\n */\r\nclass MultiSelectCore {\r\n /**\r\n * @param {import('../jsmind.js').default} jm - jsMind instance\r\n * @param {MultiSelectOptions} options - Plugin options\r\n */\r\n constructor(jm, options) {\r\n this.jm = jm;\r\n this.options = options;\r\n\r\n // Initialize selection state\r\n this._ensure_selection_state();\r\n\r\n this._selection_mode = null; // 'single' | 'multi' | null\r\n this._last_selected_node = null;\r\n }\r\n\r\n /**\r\n * Ensure selection state is initialized\r\n * @private\r\n */\r\n _ensure_selection_state() {\r\n if (!this.jm.mind) {\r\n this.jm.mind = {};\r\n }\r\n if (!this.jm.mind.selected_nodes) {\r\n this.jm.mind.selected_nodes = new Set();\r\n }\r\n\r\n if (!this.jm.view) {\r\n this.jm.view = {};\r\n }\r\n if (!this.jm.view.multi_selected_nodes) {\r\n this.jm.view.multi_selected_nodes = new Map();\r\n }\r\n }\r\n\r\n /**\r\n * Get all selected nodes\r\n * @returns {string[]} Array of selected node IDs\r\n */\r\n get_selected_nodes() {\r\n this._ensure_selection_state();\r\n if (!this.jm.mind || !this.jm.mind.selected_nodes) {\r\n return [];\r\n }\r\n return Array.from(this.jm.mind.selected_nodes).map(node => node.id);\r\n }\r\n\r\n /**\r\n * Check if a node is selected\r\n * @param {string|import('../jsmind.node.js').Node} node - Node ID or Node instance\r\n * @returns {boolean}\r\n */\r\n is_node_selected(node) {\r\n const nodeObj = this._resolve_node(node);\r\n if (!nodeObj || !this.jm.mind) {\r\n return false;\r\n }\r\n this._ensure_selection_state();\r\n return this.jm.mind.selected_nodes.has(nodeObj);\r\n }\r\n\r\n /**\r\n * Select a single node (clears other selections)\r\n * @param {string|import('../jsmind.node.js').Node} node - Node ID or Node instance\r\n */\r\n select_node(node) {\r\n const nodeObj = this._resolve_node(node);\r\n if (!nodeObj) {\r\n logger.error('[multiSelect] node not found: ' + node);\r\n return;\r\n }\r\n\r\n this._ensure_selection_state();\r\n\r\n // Clear selection state first\r\n this._clear_selection_state();\r\n\r\n // Ensure again after clear, in case mind was reset\r\n this._ensure_selection_state();\r\n\r\n if (!this.jm.mind || !this.jm.mind.selected_nodes) {\r\n logger.error('[multiSelect] jm.mind or selected_nodes is not available');\r\n return;\r\n }\r\n\r\n // Set selection state\r\n this.jm.mind.selected = nodeObj;\r\n this._last_selected_node = nodeObj;\r\n\r\n // Force add node to selection (since we just cleared it)\r\n if (!this.jm.mind.selected_nodes.has(nodeObj)) {\r\n this.jm.mind.selected_nodes.add(nodeObj);\r\n }\r\n\r\n // Mark node as selected in view\r\n this._mark_node_selected(nodeObj);\r\n\r\n this._selection_mode = 'single';\r\n\r\n // Always use nodeObj.id for event data\r\n const nodeIds = [nodeObj.id];\r\n\r\n // Invoke event with proper data structure\r\n this._invoke_select_event({\r\n evt: 'select_node',\r\n data: nodeIds,\r\n node: nodeObj.id,\r\n nodes: nodeIds,\r\n });\r\n }\r\n\r\n /**\r\n * Clear all selections\r\n */\r\n select_clear() {\r\n this._ensure_selection_state();\r\n if (this.jm.mind) {\r\n this.jm.mind.selected = null;\r\n this._last_selected_node = null;\r\n this._clear_selection_state();\r\n }\r\n }\r\n\r\n /**\r\n * Toggle node selection (equivalent to Ctrl/Cmd+Click)\r\n * @param {string|import('../jsmind.node.js').Node} node - Node ID or Node instance\r\n */\r\n toggle_node_selection(node) {\r\n const nodeObj = this._resolve_node(node);\r\n if (!nodeObj || !this.jm.layout.is_visible(nodeObj)) {\r\n return;\r\n }\r\n\r\n this._ensure_selection_state();\r\n if (this.jm.mind.selected_nodes.has(nodeObj)) {\r\n this._deselect_subtree(nodeObj);\r\n } else {\r\n this._selection_mode = 'multi';\r\n const added = this._append_selection([nodeObj]);\r\n if (added.length) {\r\n this.jm.mind.selected = nodeObj;\r\n this._last_selected_node = nodeObj;\r\n this._invoke_select_event({\r\n evt: 'multi_select',\r\n data: [nodeObj.id],\r\n node: nodeObj.id,\r\n nodes: [nodeObj.id],\r\n });\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Toggle subtree selection\r\n * @param {string|import('../jsmind.node.js').Node} node - Node ID or Node instance\r\n */\r\n toggle_subtree_selection(node, opts) {\r\n const nodeObj = this._resolve_node(node);\r\n if (!nodeObj) {\r\n logger.error('[multiSelect] node not found: ' + node);\r\n return;\r\n }\r\n\r\n if (!this.jm.layout.is_visible(nodeObj)) {\r\n return;\r\n }\r\n\r\n const includeDesc = (opts && typeof opts.include_descendants !== 'undefined')\r\n ? !!opts.include_descendants\r\n : this.options.include_descendants !== false; // default true\r\n\r\n this._ensure_selection_state();\r\n // If node is not selected or not in multi mode, select subtree\r\n if (!this.jm.mind.selected_nodes.has(nodeObj) || this._selection_mode !== 'multi') {\r\n this._selection_mode = 'multi';\r\n let nodes = this._collect_subtree_nodes(nodeObj, {\r\n includeChildren: includeDesc,\r\n respectFilter: true,\r\n skipRootFilter: true,\r\n });\r\n if (!nodes.length) {\r\n nodes = [nodeObj];\r\n }\r\n\r\n const added = this._append_selection(nodes, {focusNode: nodeObj});\r\n this._ensure_selection_state();\r\n const ancestors = nodeObj.parent && !this.jm.mind.selected_nodes.has(nodeObj.parent)\r\n ? this._ensure_ancestor_selection([nodeObj], nodeObj, {\r\n requireAncestorChainSelected: true,\r\n })\r\n : [];\r\n const allAdded = added.concat(ancestors);\r\n\r\n if (allAdded.length) {\r\n this.jm.mind.selected = nodeObj;\r\n const nodeIds = allAdded.map(n => n.id);\r\n this._invoke_select_event({\r\n evt: 'multi_select',\r\n data: nodeIds,\r\n node: nodeObj.id,\r\n nodes: nodeIds,\r\n });\r\n }\r\n } else {\r\n // Deselect subtree\r\n let nodes = this._collect_subtree_nodes(nodeObj, {\r\n includeChildren: true,\r\n respectFilter: false,\r\n skipRootFilter: false,\r\n });\r\n if (!nodes.length) {\r\n nodes = [nodeObj];\r\n }\r\n\r\n const removed = this._remove_selection(nodes);\r\n if (removed.length) {\r\n if (this.jm.mind.selected && this.jm.mind.selected.id === nodeObj.id) {\r\n this.jm.mind.selected = null;\r\n }\r\n this._selection_mode = this._derive_selection_mode();\r\n const nodeIds = removed.map(n => n.id);\r\n this._invoke_select_event({\r\n evt: 'multi_deselect',\r\n data: nodeIds,\r\n node: nodeObj.id,\r\n nodes: nodeIds,\r\n });\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Get current selection mode\r\n * @returns {'single'|'multi'|null}\r\n */\r\n get_selection_mode() {\r\n return this._selection_mode;\r\n }\r\n\r\n /**\r\n * Handle node click event\r\n * @param {Object} payload - Click event payload\r\n * @param {MouseEvent} payload.e - Mouse event\r\n * @param {string} payload.node - Node ID\r\n * @param {HTMLElement} payload.element - Node element\r\n * @param {string} payload.evt - Event type\r\n */\r\n _handle_node_click(payload) {\r\n const {e, node, element} = payload;\r\n if (!node || !element) {\r\n return;\r\n }\r\n\r\n // Ensure selection state is initialized\r\n this._ensure_selection_state();\r\n\r\n const mode = this._get_multi_select_mode(e);\r\n\r\n if (mode === 'ctrl') {\r\n // Ctrl/Cmd + Click: Toggle node selection\r\n this.toggle_node_selection(node);\r\n } else if (mode === 'shift') {\r\n // Shift + Click: Range selection\r\n const nodeObj = this.jm.get_node(node);\r\n if (!nodeObj) {\r\n logger.warn('[multiSelect] Node not found for shift selection: ' + node);\r\n return;\r\n }\r\n\r\n if (this.options.shift_simple_mode) {\r\n // Advanced range mode\r\n if (this.is_node_selected(node)) {\r\n this._deselect_subtree(nodeObj);\r\n } else {\r\n this._range_select_nodes(node);\r\n }\r\n } else {\r\n // Simple subtree mode\r\n if (this.is_node_selected(node)) {\r\n this._deselect_subtree(nodeObj);\r\n } else {\r\n const includeChildren = this.options.include_descendants !== false;\r\n let nodes = this._collect_subtree_nodes(nodeObj, {\r\n includeChildren: includeChildren,\r\n respectFilter: true,\r\n skipRootFilter: true,\r\n });\r\n if (!nodes.length) {\r\n nodes = [nodeObj];\r\n }\r\n\r\n const added = this._append_selection(nodes, {focusNode: nodeObj});\r\n if (added.length) {\r\n this.jm.mind.selected = nodeObj;\r\n this._last_selected_node = nodeObj;\r\n this._selection_mode = this._derive_selection_mode();\r\n const nodeIds = added.map(n => n.id);\r\n this._invoke_select_event({\r\n evt: 'multi_select',\r\n data: nodeIds,\r\n node: nodeObj.id,\r\n nodes: nodeIds,\r\n });\r\n } else {\r\n // Fallback: at least select the clicked node\r\n this._ensure_selection_state();\r\n if (!this.jm.mind.selected_nodes.has(nodeObj)) {\r\n this.jm.mind.selected_nodes.add(nodeObj);\r\n this._mark_node_selected(nodeObj);\r\n }\r\n this.jm.mind.selected = nodeObj;\r\n this._last_selected_node = nodeObj;\r\n this._selection_mode = this._derive_selection_mode();\r\n this._invoke_select_event({\r\n evt: 'multi_select',\r\n data: [nodeObj.id],\r\n node: nodeObj.id,\r\n nodes: [nodeObj.id],\r\n });\r\n }\r\n }\r\n }\r\n } else {\r\n // Normal click - single select\r\n this.select_node(node);\r\n }\r\n }\r\n\r\n /**\r\n * Handle node removed event\r\n * @param {import('../jsmind.node.js').Node} node - Removed node\r\n */\r\n _handle_node_removed(node) {\r\n this._ensure_selection_state();\r\n if (this.jm.mind.selected_nodes.has(node)) {\r\n this.jm.mind.selected_nodes.delete(node);\r\n }\r\n if (this._last_selected_node && this._last_selected_node.id === node.id) {\r\n this._last_selected_node = null;\r\n }\r\n if (this.jm.view.multi_selected_nodes && this.jm.view.multi_selected_nodes.has(node.id)) {\r\n this._unmark_node_selected(node);\r\n }\r\n }\r\n\r\n /**\r\n * Get multi-select mode from event\r\n * @param {MouseEvent} e - Mouse event\r\n * @returns {'ctrl'|'shift'|null}\r\n */\r\n _get_multi_select_mode(e) {\r\n if (!e) {\r\n return null;\r\n }\r\n // Check shift key first (higher priority)\r\n if (this.options.allow_shift !== false && e.shiftKey === true) {\r\n return 'shift';\r\n }\r\n // Check ctrl/cmd key\r\n if (this.options.allow_ctrl !== false && (e.ctrlKey === true || e.metaKey === true)) {\r\n return 'ctrl';\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Append nodes to selection\r\n * @param {import('../jsmind.node.js').Node[]} nodes - Nodes to select\r\n * @param {Object} [options] - Options\r\n * @param {import('../jsmind.node.js').Node} [options.focusNode] - Focus node\r\n * @returns {import('../jsmind.node.js').Node[]} Actually added nodes\r\n */\r\n _append_selection(nodes, options) {\r\n if (!nodes || !nodes.length) {\r\n return [];\r\n }\r\n\r\n this._ensure_selection_state();\r\n if (!this.jm.mind || !this.jm.mind.selected_nodes) {\r\n logger.warn('[multiSelect] Cannot append selection: selected_nodes not available');\r\n return [];\r\n }\r\n\r\n const added = [];\r\n for (let i = 0; i < nodes.length; i++) {\r\n const node = nodes[i];\r\n if (!this.jm.mind.selected_nodes.has(node)) {\r\n this.jm.mind.selected_nodes.add(node);\r\n added.push(node);\r\n }\r\n }\r\n\r\n if (added.length) {\r\n const focusNode = options && options.focusNode ? options.focusNode : null;\r\n this._mark_nodes_selected(added, focusNode || added[added.length - 1]);\r\n }\r\n\r\n return added;\r\n }\r\n\r\n /**\r\n * Remove nodes from selection\r\n * @param {import('../jsmind.node.js').Node[]} nodes - Nodes to deselect\r\n * @returns {import('../jsmind.node.js').Node[]} Actually removed nodes\r\n */\r\n _remove_selection(nodes) {\r\n if (!nodes || !nodes.length) {\r\n return [];\r\n }\r\n\r\n this._ensure_selection_state();\r\n const removed = [];\r\n for (let i = 0; i < nodes.length; i++) {\r\n const node = nodes[i];\r\n if (this.jm.mind.selected_nodes.has(node)) {\r\n this.jm.mind.selected_nodes.delete(node);\r\n removed.push(node);\r\n }\r\n }\r\n\r\n if (removed.length) {\r\n this._unmark_nodes_selected(removed);\r\n }\r\n\r\n return removed;\r\n }\r\n\r\n /**\r\n * Deselect subtree\r\n * @param {import('../jsmind.node.js').Node} node - Root node of subtree\r\n */\r\n _deselect_subtree(node) {\r\n let nodes = this._collect_subtree_nodes(node, {\r\n includeChildren: true,\r\n respectFilter: false,\r\n skipRootFilter: false,\r\n });\r\n if (!nodes.length) {\r\n nodes = [node];\r\n }\r\n\r\n const removed = this._remove_selection(nodes);\r\n if (removed.length) {\r\n if (this.jm.mind.selected && this.jm.mind.selected.id === node.id) {\r\n this.jm.mind.selected = null;\r\n }\r\n this._selection_mode = this._derive_selection_mode();\r\n const nodeIds = removed.map(n => n.id);\r\n this._invoke_select_event({\r\n evt: 'multi_deselect',\r\n data: nodeIds,\r\n node: node.id,\r\n nodes: nodeIds,\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Clear selection state\r\n * @returns {import('../jsmind.node.js').Node[]} Removed nodes\r\n */\r\n _clear_selection_state() {\r\n this._ensure_selection_state();\r\n this._selection_mode = null;\r\n\r\n // Double check after ensure\r\n if (!this.jm.mind || !this.jm.mind.selected_nodes) {\r\n this._ensure_selection_state();\r\n }\r\n\r\n if (!this.jm.mind || !this.jm.mind.selected_nodes || this.jm.mind.selected_nodes.size === 0) {\r\n this._clear_all_selected_nodes_view();\r\n return [];\r\n }\r\n\r\n const nodes = Array.from(this.jm.mind.selected_nodes);\r\n this.jm.mind.selected_nodes.clear();\r\n this._unmark_nodes_selected(nodes);\r\n return nodes;\r\n }\r\n\r\n /**\r\n * Collect subtree nodes\r\n * @param {import('../jsmind.node.js').Node} node - Root node\r\n * @param {Object} options - Options\r\n * @param {boolean} [options.includeChildren=true] - Include children\r\n * @param {boolean} [options.respectFilter=false] - Respect filter\r\n * @param {boolean} [options.skipRootFilter=false] - Skip root filter\r\n * @returns {import('../jsmind.node.js').Node[]}\r\n */\r\n _collect_subtree_nodes(node, options) {\r\n const opts = options || {};\r\n const includeChildren = opts.includeChildren !== false;\r\n const respectFilter = !!opts.respectFilter;\r\n const skipRootFilter = !!opts.skipRootFilter;\r\n\r\n const filter = respectFilter ? this._get_selection_filter() : null;\r\n const result = [];\r\n\r\n const collect = (n, isRoot) => {\r\n let shouldInclude = true;\r\n if (filter && (!skipRootFilter || !isRoot)) {\r\n shouldInclude = filter(n) !== false;\r\n }\r\n\r\n if (shouldInclude) {\r\n result.push(n);\r\n }\r\n\r\n if (includeChildren && n.children) {\r\n for (let i = 0; i < n.children.length; i++) {\r\n collect(n.children[i], false);\r\n }\r\n }\r\n };\r\n\r\n collect(node, true);\r\n return result;\r\n }\r\n\r\n /**\r\n * Ensure ancestor selection\r\n * @param {import('../jsmind.node.js').Node[]} nodes - Nodes\r\n * @param {import('../jsmind.node.js').Node} focusNode - Focus node\r\n * @param {Object} options - Options\r\n * @returns {import('../jsmind.node.js').Node[]}\r\n */\r\n _ensure_ancestor_selection(nodes, focusNode, options) {\r\n if (!nodes || !nodes.length) {\r\n return [];\r\n }\r\n\r\n this._ensure_selection_state();\r\n const requireAncestorChainSelected = !!(options && options.requireAncestorChainSelected);\r\n const added = [];\r\n const addedMap = Object.create(null);\r\n\r\n for (let i = 0; i < nodes.length; i++) {\r\n let parent = nodes[i].parent;\r\n if (!parent) {\r\n continue;\r\n }\r\n\r\n const path = [];\r\n let shouldAdd = !requireAncestorChainSelected;\r\n\r\n // Check if any ancestor is already selected\r\n while (parent) {\r\n if (this.jm.mind.selected_nodes.has(parent)) {\r\n shouldAdd = true;\r\n break;\r\n }\r\n path.push(parent);\r\n parent = parent.parent;\r\n }\r\n\r\n if (shouldAdd) {\r\n for (let j = 0; j < path.length; j++) {\r\n const p = path[j];\r\n if (!this.jm.mind.selected_nodes.has(p) && !addedMap[p.id]) {\r\n added.push(p);\r\n addedMap[p.id] = true;\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (!added.length) {\r\n return [];\r\n }\r\n\r\n const focus = focusNode || nodes[nodes.length - 1];\r\n return this._append_selection(added, {focusNode: focus});\r\n }\r\n\r\n /**\r\n * Get selection filter\r\n * @returns {Function|null}\r\n */\r\n _get_selection_filter() {\r\n if (this.options && typeof this.options.filter === 'function') {\r\n return this.options.filter;\r\n }\r\n return null;\r\n }\r\n\r\n /**\r\n * Range select nodes (advanced mode)\r\n * @param {string} nodeId - Target node ID\r\n */\r\n _range_select_nodes(nodeId) {\r\n const nodeObj = this._resolve_node(nodeId);\r\n if (!nodeObj || !this.jm.layout.is_visible(nodeObj)) {\r\n return;\r\n }\r\n\r\n this._ensure_selection_state();\r\n // If no selection, select subtree\r\n if (this.jm.mind.selected_nodes.size === 0) {\r\n let nodes = this._collect_subtree_nodes(nodeObj, {\r\n includeChildren: true,\r\n respectFilter: true,\r\n skipRootFilter: true,\r\n });\r\n if (!nodes.length) {\r\n nodes = [nodeObj];\r\n }\r\n\r\n const added = this._append_selection(nodes);\r\n if (added.length) {\r\n this.jm.mind.selected = nodeObj;\r\n this._last_selected_node = nodeObj;\r\n this._selection_mode = this._derive_selection_mode();\r\n const nodeIds = added.map(n => n.id);\r\n this._invoke_select_event({\r\n evt: 'multi_select',\r\n data: nodeIds,\r\n node: nodeObj.id,\r\n nodes: nodeIds,\r\n });\r\n }\r\n return;\r\n }\r\n\r\n // Find anchor node\r\n this._ensure_selection_state();\r\n const selectedArray = Array.from(this.jm.mind.selected_nodes);\r\n const anchor =\r\n this._last_selected_node && this.jm.mind.selected_nodes.has(this._last_selected_node)\r\n ? this._last_selected_node\r\n : selectedArray[0];\r\n\r\n // Find nodes between anchor and target\r\n const nodesBetween = this._find_nodes_between(anchor, nodeObj);\r\n if (!nodesBetween.length) {\r\n const nodes = [nodeObj];\r\n const added = this._append_selection(nodes);\r\n if (added.length) {\r\n this.jm.mind.selected = nodeObj;\r\n this._last_selected_node = nodeObj;\r\n this._selection_mode = this._derive_selection_mode();\r\n const nodeIds = added.map(n => n.id);\r\n this._invoke_select_event({\r\n evt: 'multi_select',\r\n data: nodeIds,\r\n node: nodeObj.id,\r\n nodes: nodeIds,\r\n });\r\n }\r\n return;\r\n }\r\n\r\n // Select all nodes between anchor and target\r\n this._ensure_selection_state();\r\n const toAdd = nodesBetween.filter(n => !this.jm.mind.selected_nodes.has(n));\r\n const added = this._append_selection(toAdd);\r\n if (added.length) {\r\n this.jm.mind.selected = nodeObj;\r\n this._last_selected_node = nodeObj;\r\n this._selection_mode = this._derive_selection_mode();\r\n const nodeIds = added.map(n => n.id);\r\n this._invoke_select_event({\r\n evt: 'multi_select',\r\n data: nodeIds,\r\n node: nodeObj.id,\r\n nodes: nodeIds,\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Find nodes between two nodes\r\n * @param {import('../jsmind.node.js').Node} from - Start node\r\n * @param {import('../jsmind.node.js').Node} to - End node\r\n * @returns {import('../jsmind.node.js').Node[]}\r\n */\r\n _find_nodes_between(from, to) {\r\n if (!from || !to) {\r\n return [];\r\n }\r\n\r\n // Collect all visible nodes in order\r\n const allNodes = [];\r\n const collect = node => {\r\n if (this.jm.layout.is_visible(node)) {\r\n allNodes.push(node);\r\n }\r\n if (node.children) {\r\n for (let i = 0; i < node.children.length; i++) {\r\n collect(node.children[i]);\r\n }\r\n }\r\n };\r\n\r\n if (this.jm.mind && this.jm.mind.root) {\r\n collect(this.jm.mind.root);\r\n }\r\n\r\n // Find indices\r\n let fromIndex = -1;\r\n let toIndex = -1;\r\n for (let i = 0; i < allNodes.length; i++) {\r\n if (allNodes[i].id === from.id) {\r\n fromIndex = i;\r\n }\r\n if (allNodes[i].id === to.id) {\r\n toIndex = i;\r\n }\r\n }\r\n\r\n if (fromIndex === -1 || toIndex === -1) {\r\n return [];\r\n }\r\n\r\n const start = Math.min(fromIndex, toIndex);\r\n const end = Math.max(fromIndex, toIndex);\r\n return allNodes.slice(start, end + 1);\r\n }\r\n\r\n /**\r\n * Derive selection mode from current state\r\n * @returns {'single'|'multi'|null}\r\n */\r\n _derive_selection_mode() {\r\n this._ensure_selection_state();\r\n const count = this.jm.mind.selected_nodes.size;\r\n if (count === 0) {\r\n return null;\r\n }\r\n return count > 1 ? 'multi' : 'single';\r\n }\r\n\r\n /**\r\n * Mark nodes as selected in view\r\n * @param {import('../jsmind.node.js').Node[]} nodes - Nodes to mark\r\n * @param {import('../jsmind.node.js').Node} focusNode - Focus node\r\n */\r\n _mark_nodes_selected(nodes, focusNode) {\r\n if (nodes && nodes.length) {\r\n for (let i = 0; i < nodes.length; i++) {\r\n this._mark_node_selected(nodes[i]);\r\n }\r\n this.jm.view.selected_node = focusNode || nodes[nodes.length - 1];\r\n }\r\n }\r\n\r\n /**\r\n * Mark a node as selected in view\r\n * @param {import('../jsmind.node.js').Node} node - Node to mark\r\n */\r\n _mark_node_selected(node) {\r\n if (!node || this.jm.view.multi_selected_nodes.has(node.id)) {\r\n return;\r\n }\r\n\r\n const element = node._data && node._data.view && node._data.view.element;\r\n if (element) {\r\n if (element.classList) {\r\n element.classList.add('selected');\r\n } else if (!/(\\s|^)selected(\\s|$)/.test(element.className)) {\r\n element.className += ' selected';\r\n }\r\n this.jm.view.multi_selected_nodes.set(node.id, node);\r\n }\r\n }\r\n\r\n /**\r\n * Unmark nodes as selected in view\r\n * @param {import('../jsmind.node.js').Node[]} nodes - Nodes to unmark\r\n */\r\n _unmark_nodes_selected(nodes) {\r\n if (nodes && nodes.length) {\r\n for (let i = 0; i < nodes.length; i++) {\r\n this._unmark_node_selected(nodes[i]);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Unmark a node as selected in view\r\n * @param {import('../jsmind.node.js').Node} node - Node to unmark\r\n */\r\n _unmark_node_selected(node) {\r\n if (node) {\r\n if (this.jm.view.multi_selected_nodes.has(node.id)) {\r\n const element = node._data && node._data.view && node._data.view.element;\r\n if (element) {\r\n if (element.classList) {\r\n element.classList.remove('selected');\r\n } else {\r\n element.className = element.className.replace(/\\s*selected\\b/i, '');\r\n }\r\n }\r\n this.jm.view.multi_selected_nodes.delete(node.id);\r\n }\r\n if (this.jm.view.selected_node && this.jm.view.selected_node.id === node.id) {\r\n this.jm.view.selected_node = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Clear all selected nodes view\r\n */\r\n _clear_all_selected_nodes_view() {\r\n this._ensure_selection_state();\r\n if (!this.jm.view.multi_selected_nodes || !this.jm.view.multi_selected_nodes.size) {\r\n if (this.jm.view) {\r\n this.jm.view.selected_node = null;\r\n }\r\n return;\r\n }\r\n\r\n const nodes = Array.from(this.jm.view.multi_selected_nodes.values());\r\n for (let i = 0; i < nodes.length; i++) {\r\n this._unmark_node_selected(nodes[i]);\r\n }\r\n if (this.jm.view) {\r\n this.jm.view.selected_node = null;\r\n }\r\n }\r\n\r\n /**\r\n * Invoke select event\r\n * @param {Object} data - Event data\r\n */\r\n _invoke_select_event(data) {\r\n try {\r\n // Ensure nodes is always an array\r\n if (!data.nodes) {\r\n data.nodes = data.data || [];\r\n }\r\n // Ensure data is always an array\r\n if (!data.data) {\r\n data.data = data.nodes || [];\r\n }\r\n this.jm.invoke_event_handle(EventType.select, data);\r\n } catch (e) {\r\n logger.warn('[multiSelect] failed to invoke select event', e);\r\n }\r\n }\r\n\r\n /**\r\n * Resolve node from ID or Node instance\r\n * @param {string|import('../jsmind.node.js').Node} node - Node ID or Node instance\r\n * @returns {import('../jsmind.node.js').Node|null}\r\n */\r\n _resolve_node(node) {\r\n if (!node) {\r\n return null;\r\n }\r\n if (typeof node === 'string') {\r\n return this.jm.get_node(node);\r\n }\r\n return node;\r\n }\r\n}\r\n\r\n/**\r\n * Multi-Select Plugin - Enhanced plugin for jsMind\r\n */\r\nexport class MultiSelectPlugin extends EnhancedPlugin {\r\n static instanceName = 'multiSelectPlugin';\r\n static preload = false;\r\n\r\n /**\r\n * @param {{ jm: import('../jsmind.js').default, pluginOpt: object }} params\r\n */\r\n constructor({jm, pluginOpt}) {\r\n super({jm, pluginOpt});\r\n\r\n const options = Object.assign({}, DEFAULT_OPTIONS, pluginOpt || {});\r\n this.options = options;\r\n this._mounted = false;\r\n this._core = null;\r\n this._listener = null;\r\n this._enabled = !!options.enable_multi_select; // runtime gate\r\n\r\n this._initCore();\r\n }\r\n\r\n /**\r\n * Initialize core and mount API\r\n */\r\n _initCore() {\r\n const jm = this.jm;\r\n const options = this.options;\r\n const plugin = this; // Save reference for closure\r\n\r\n // Create core instance\r\n this._core = new MultiSelectCore(jm, options);\r\n\r\n // Mount API\r\n this._mountAPI();\r\n\r\n // Setup event listener\r\n this._listener = (type, data) => {\r\n try {\r\n if (type === EventType.show) {\r\n plugin._core.select_clear();\r\n }\r\n } catch (e) {\r\n logger.warn('[multiSelect] listener error', e);\r\n }\r\n };\r\n\r\n jm.add_event_listener(this._listener);\r\n\r\n // Patch core selection APIs to route through plugin to avoid duplicate events\r\n this._original_select_node = jm.select_node.bind(jm);\r\n this._original_select_clear = jm.select_clear.bind(jm);\r\n jm.select_node = (node) => {\r\n // Route based on runtime gate\r\n if (plugin._enabled) return plugin._core.select_node(node);\r\n return plugin._original_select_node(node);\r\n };\r\n jm.select_clear = () => {\r\n if (plugin._enabled) return plugin._core.select_clear();\r\n return plugin._original_select_clear();\r\n };\r\n\r\n // Always bind our click handler once; gate controls interception\r\n const $ = jm.constructor.$;\r\n this._domClickHandler = function (e) {\r\n // Gate: only intercept when enabled\r\n if (!plugin._enabled) {\r\n return;\r\n }\r\n const element = e.target || e.currentTarget;\r\n const node_id = jm.view.get_binded_nodeid(element);\r\n\r\n // Only intercept jmnode, let expander clicks pass through\r\n if (node_id && jm.view.is_node(element)) {\r\n e.preventDefault();\r\n e.stopPropagation();\r\n if (e.stopImmediatePropagation) e.stopImmediatePropagation();\r\n\r\n plugin._core._handle_node_click({\r\n e,\r\n node: node_id,\r\n element,\r\n evt: 'click',\r\n });\r\n } else if (!node_id) {\r\n // Blank click without modifiers clears selection\r\n if (!e.ctrlKey && !e.metaKey && !e.shiftKey) {\r\n plugin._core.select_clear();\r\n }\r\n }\r\n };\r\n\r\n if (jm.view && jm.view.e_nodes) {\r\n $.on(jm.view.e_nodes, 'click', this._domClickHandler);\r\n logger.info('[multiSelect] plugin click handler attached');\r\n } else {\r\n logger.warn('[multiSelect] nodes container not ready; DOM handler not attached');\r\n }\r\n\r\n // Respect initial enabled state: toggle core default handler\r\n if (this._enabled && typeof jm.disable_event_handle === 'function') {\r\n jm.disable_event_handle('mousedown');\r\n }\r\n\r\n logger.info('[multiSelect] API mounted and event listener attached.');\r\n }\r\n\r\n /**\r\n * Mount API to jsMind instance\r\n */\r\n _mountAPI() {\r\n if (this._mounted) {\r\n return;\r\n }\r\n\r\n const jm = this.jm;\r\n const plugin = this; // Save reference for closure\r\n\r\n const api = {\r\n get_selected_nodes: () => {\r\n if (!plugin._core) {\r\n logger.warn('[multiSelect] Core not initialized');\r\n return [];\r\n }\r\n return plugin._core.get_selected_nodes();\r\n },\r\n is_node_selected: node => {\r\n if (!plugin._core) {\r\n return false;\r\n }\r\n return plugin._core.is_node_selected(node);\r\n },\r\n select_node: node => {\r\n if (!plugin._core) {\r\n logger.warn('[multiSelect] Core not initialized');\r\n return;\r\n }\r\n plugin._core.select_node(node);\r\n },\r\n select_clear: () => {\r\n if (!plugin._core) {\r\n return;\r\n }\r\n plugin._core.select_clear();\r\n },\r\n toggle_node_selection: node => {\r\n if (!plugin._core) {\r\n logger.warn('[multiSelect] Core not initialized');\r\n return;\r\n }\r\n plugin._core.toggle_node_selection(node);\r\n },\r\n toggle_subtree_selection: node => {\r\n if (!plugin._core) {\r\n logger.warn('[multiSelect] Core not initialized');\r\n return;\r\n }\r\n plugin._core.toggle_subtree_selection(node);\r\n },\r\n get_selection_mode: () => {\r\n if (!plugin._core) {\r\n return null;\r\n }\r\n return plugin._core.get_selection_mode();\r\n },\r\n getOptions: () => {\r\n const base = plugin._core ? plugin._core.options : plugin.options;\r\n return Object.assign({}, base, {enable_multi_select: plugin._enabled});\r\n },\r\n enable: () => plugin.setEnabled(true),\r\n disable: () => plugin.setEnabled(false),\r\n setEnabled: (flag) => plugin.setEnabled(flag),\r\n setOptions: (partial) => plugin.setOptions(partial),\r\n };\r\n\r\n Object.defineProperty(jm, 'multiSelect', {\r\n value: api,\r\n configurable: true,\r\n enumerable: false,\r\n writable: false,\r\n });\r\n\r\n this._mounted = true;\r\n logger.info('[multiSelect] API mounted.');\r\n }\r\n\r\n /**\r\n * Cleanup before plugin removal\r\n */\r\n beforePluginRemove() {\r\n try {\r\n // Remove event listener\r\n if (this._listener && this.jm && Array.isArray(this.jm.event_handles)) {\r\n const index = this.jm.event_handles.indexOf(this._listener);\r\n if (index >= 0) {\r\n this.jm.event_handles.splice(index, 1);\r\n }\r\n }\r\n\r\n // Re-enable core mousedown handle\r\n if (typeof this.jm.enable_event_handle === 'function') {\r\n this.jm.enable_event_handle('mousedown');\r\n }\r\n\r\n // Remove DOM click handler if attached\r\n if (this._domClickHandler && this.jm && this.jm.view && this.jm.view.e_nodes) {\r\n // No off() helper; leave it attached (noop when disabled). If needed, we could rebuild view.\r\n this._domClickHandler = null;\r\n }\r\n\r\n // Restore API wrappers\r\n if (this._original_select_node) {\r\n this.jm.select_node = this._original_select_node;\r\n }\r\n if (this._original_select_clear) {\r\n this.jm.select_clear = this._original_select_clear;\r\n }\r\n\r\n // Remove API namespace\r\n if (this.jm && Object.prototype.hasOwnProperty.call(this.jm, 'multiSelect')) {\r\n delete this.jm.multiSelect;\r\n }\r\n\r\n this._mounted = false;\r\n } catch (e) {\r\n logger.error('[multiSelect] remove failed:', e);\r\n }\r\n }\r\n\r\n // Runtime enable/disable and options update\r\n setEnabled(flag) {\r\n const next = !!flag;\r\n if (this._enabled === next) return;\r\n this._enabled = next;\r\n // Keep options in sync for getOptions()\r\n this.options.enable_multi_select = this._enabled;\r\n if (this._enabled) {\r\n if (typeof this.jm.disable_event_handle === 'function') {\r\n this.jm.disable_event_handle('mousedown');\r\n }\r\n } else {\r\n if (typeof this.jm.enable_event_handle === 'function') {\r\n this.jm.enable_event_handle('mousedown');\r\n }\r\n }\r\n }\r\n\r\n setOptions(partial) {\r\n const next = Object.assign({}, partial || {});\r\n // Update plugin-level options\r\n this.options = Object.assign({}, this.options, next);\r\n // Propagate to core so that _get_multi_select_mode sees changes\r\n if (this._core && this._core.options) {\r\n this._core.options = Object.assign({}, this._core.options, next);\r\n }\r\n }\r\n\r\n /**\r\n * Cleanup before plugin destroy\r\n */\r\n beforePluginDestroy() {\r\n logger.debug('[multiSelect] beforePluginDestroy');\r\n this.beforePluginRemove();\r\n }\r\n}\r\n\r\n// Export for compatibility\r\nexport {MultiSelectCore};\r\nexport default MultiSelectPlugin;\r\n\r\n"],"names":["String","prototype","startsWith","p","this","slice","length","EventType","LogLevel","_noop","logger","console","level","log","debug","info","warn","error","log_level","EnhancedPlugin","static","constructor","jm","pluginOpt","options","beforePluginRemove","beforePluginDestroy","DEFAULT_OPTIONS","enable_multi_select","include_descendants","shift_simple_mode","allow_ctrl","allow_shift","filter","MultiSelectCore","_ensure_selection_state","_selection_mode","_last_selected_node","mind","selected_nodes","Set","view","multi_selected_nodes","Map","get_selected_nodes","Array","from","map","node","id","is_node_selected","nodeObj","_resolve_node","has","select_node","_clear_selection_state","selected","add","_mark_node_selected","nodeIds","_invoke_select_event","evt","data","nodes","select_clear","toggle_node_selection","layout","is_visible","_deselect_subtree","_append_selection","toggle_subtree_selection","opts","includeDesc","_collect_subtree_nodes","includeChildren","respectFilter","skipRootFilter","removed","_remove_selection","_derive_selection_mode","n","added","focusNode","ancestors","parent","_ensure_ancestor_selection","requireAncestorChainSelected","allAdded","concat","get_selection_mode","_handle_node_click","payload","e","element","mode","_get_multi_select_mode","get_node","_range_select_nodes","_handle_node_removed","delete","_unmark_node_selected","shiftKey","ctrlKey","metaKey","i","push","_mark_nodes_selected","_unmark_nodes_selected","size","_clear_all_selected_nodes_view","clear","_get_selection_filter","result","collect","isRoot","shouldInclude","children","addedMap","Object","create","path","shouldAdd","j","focus","nodeId","selectedArray","anchor","nodesBetween","_find_nodes_between","toAdd","to","allNodes","root","fromIndex","toIndex","start","Math","min","end","max","count","selected_node","_data","classList","test","className","set","remove","replace","values","invoke_event_handle","MultiSelectPlugin","super","assign","_mounted","_core","_listener","_enabled","_initCore","plugin","_mountAPI","type","add_event_listener","_original_select_node","bind","_original_select_clear","$","_domClickHandler","target","currentTarget","node_id","get_binded_nodeid","is_node","preventDefault","stopPropagation","stopImmediatePropagation","e_nodes","on","disable_event_handle","api","getOptions","base","enable","setEnabled","disable","flag","setOptions","partial","defineProperty","value","configurable","enumerable","writable","isArray","event_handles","index","indexOf","splice","enable_event_handle","hasOwnProperty","call","multiSelect","next"],"mappings":";;;;;;;yPAmB0C,mBAA/BA,OAAOC,UAAUC,aACxBF,OAAOC,UAAUC,WAAa,SAAUC,GACpC,OAAOC,KAAKC,MAAM,EAAGF,EAAEG,UAAYH,CAC3C,GA+BO,MAAMI,EAAoB,EAApBA,EAAmD,EAInDC,EAAoB,EAApBA,EAA6B,EAA7BA,EAAsC,EAAtCA,EAAgD,EAG7D,IAAIC,EAAQ,WAAY,EAKjB,IAAIC,EACY,oBAAZC,QACD,CACIC,MAAOH,EACPI,IAAKJ,EACLK,MAAOL,EACPM,KAAMN,EACNO,KAAMP,EACNQ,MAAOR,GAEX,CACIG,MAYd,SAA4BM,GAEpBR,EAAOI,MADPI,EAAYV,EACGC,EAEAE,QAAQG,MAGvBJ,EAAOK,KADPG,EAAYV,EACEC,EAEAE,QAAQI,KAGtBL,EAAOM,KADPE,EAAYV,EACEC,EAEAE,QAAQK,KAGtBN,EAAOO,MADPC,EAAYV,EACGC,EAEAE,QAAQM,KAE/B,EAhCcJ,IAAKF,QAAQE,IACbC,MAAOH,QAAQG,MACfC,KAAMJ,QAAQI,KACdC,KAAML,QAAQK,KACdC,MAAON,QAAQM,OC4EtB,MAAME,EAKTC,oBAAsB,GAMtBA,gBAAiB,EAKjB,WAAAC,EAAYC,GAAEA,EAAEC,UAAEA,IACdnB,KAAKkB,GAAKA,EACVlB,KAAKoB,QAAUD,GAAa,EAC/B,CAMD,kBAAAE,GAEC,CAMD,mBAAAC,GAEItB,KAAKqB,oBACR,EC9KL,MAAME,EAAkB,CACpBC,qBAAqB,EACrBC,qBAAqB,EACrBC,mBAAmB,EACnBC,YAAY,EACZC,aAAa,EACbC,OAAQ,MAMZ,MAAMC,EAKF,WAAAb,CAAYC,EAAIE,GACZpB,KAAKkB,GAAKA,EACVlB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KsJ,UAAW,CACnB,CAAC,MAAO9D,GACLlF,EAAOO,MAAM,+BAAgC2E,EAChD,CACJ,CAGD,UAAA2F,CAAWE,GACP,MAAMiB,IAASjB,EACXrL,KAAKyJ,WAAa6C,IACtBtM,KAAKyJ,SAAW6C,EAEhBtM,KAAKoB,QAAQI,oBAAsBxB,KAAKyJ,SACpCzJ,KAAKyJ,SACuC,mBAAjCzJ,KAAKkB,GAAG4J,sBACf9K,KAAKkB,GAAG4J,qBAAqB,aAGU,mBAAhC9K,KAAKkB,GAAGgL,qBACflM,KAAKkB,GAAGgL,oBAAoB,aAGvC,CAED,UAAAZ,CAAWC,GACP,MAAMe,EAAOpF,OAAOmC,OAAO,CAAA,EAAIkC,GAAW,CAAA,GAE1CvL,KAAKoB,QAAU8F,OAAOmC,OAAO,CAAE,EAAErJ,KAAKoB,QAASkL,GAE3CtM,KAAKuJ,OAASvJ,KAAKuJ,MAAMnI,UACzBpB,KAAKuJ,MAAMnI,QAAU8F,OAAOmC,OAAO,GAAIrJ,KAAKuJ,MAAMnI,QAASkL,GAElE,CAKD,mBAAAhL,GACIhB,EAAOI,MAAM,qCACbV,KAAKqB,oBACR"}
|
package/es/jsmind.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* Project Home:
|
|
6
6
|
* https://github.com/hizzgdev/jsmind/
|
|
7
7
|
*/
|
|
8
|
-
const e="0.9.0";"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 s=function(){};let o="undefined"==typeof console?{level:s,log:s,debug:s,info:s,warn:s,error:s}:{level:function(e){o.debug=e>n.debug?s:console.debug;o.info=e>n.info?s:console.info;o.warn=e>n.warn?s:console.warn;o.error=e>n.error?s: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),d={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 s=new(r.w.BlobBuilder||r.w.MozBlobBuilder||r.w.WebKitBlobBuilder||r.w.MSBlobBuilder);s.append(e),n=s.getBlob(t)}if(navigator.msSaveBlob)navigator.msSaveBlob(n,i);else{var o=(r.w.URL||r.w.webkitURL).createObjectURL(n),d=r.c("a");if("download"in d){d.style.visibility="hidden",d.href=o,d.download=i,r.d.body.appendChild(d);var a=r.d.createEvent("MouseEvents");a.initEvent("click",!0,!0),d.dispatchEvent(a),r.d.body.removeChild(d)}else location.href=o}}},json:{json2string:function(e){return JSON.stringify(e)},string2json:function(e){return JSON.parse(e)},merge:function(e,t){for(var i in t)i in e?"object"!=typeof e[i]||"[object object]"!=Object.prototype.toString.call(e[i]).toLowerCase()||e[i].length?e[i]=t[i]:d.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}}},a={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}},selection:{enable_multi_select:!1,include_descendants:!1,shift_simple_mode:!1,filter:null},fieldNames:{id:"id",topic:"topic",children:"children",parentid:"parentid",isroot:"isroot",direction:"direction",expanded:"expanded"},plugin:{}};class l{constructor(e,t,i,n,s,r,d,a){e?"number"==typeof t?(void 0===a&&(a=!0),this.id=e,this.index=t,this.topic=i,this.data=n||{},this.isroot=s,this.parent=r,this.direction=d,this.expanded=!!a,this.children=[],this._data={}):o.error("invalid node index"):o.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",s=i.topic||"topic",o=i.children||"children",r=i.direction||"direction",d=i.expanded||"expanded",a={};if(a[n]=this.id,a[s]=this.topic,a[d]=this.expanded,this.parent&&this.parent.isroot&&(a[r]=-1===this.direction?"left":"right"),null!=this.data)for(var l in this.data)a[l]=this.data[l];return t&&this.children.length>0&&(a[o]=this.children.map((t=>t.toObject(e,!0)))),a}}class h{constructor(){this.name=null,this.author=null,this.version=null,this.root=null,this.selected=null,this.selected_nodes=new Set,this.nodes={}}get_node(e){return e in this.nodes?this.nodes[e]:(o.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):(o.error("root node is already exist"),null)}add_node(e,i,n,s,r,d,a){if(!l.is_node(e))return o.error("the parent_node "+e+" is not a node."),null;var h=new l(i,a||-1,n,s,!1,e,e.direction,d);return e.isroot&&(h.direction=r||t.right),this._put_node(h)?(e.children.push(h),this._update_index(e)):(o.error("fail, the node id '"+h.id+"' has been already exist."),h=null),h}insert_node_before(e,t,i,n,s){if(!l.is_node(e))return o.error("the node_before "+e+" is not a node."),null;var r=e.index-.5;return this.add_node(e.parent,t,i,n,s,!0,r)}get_node_before(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.get_node_before(t):(o.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,s){if(!l.is_node(e))return o.error("the node_after "+e+" is not a node."),null;var r=e.index+.5;return this.add_node(e.parent,t,i,n,s,!0,r)}get_node_after(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.get_node_after(t):(o.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)):(o.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,s){if(e&&n){var r=this.get_node(n);if(l.inherited(e,r))return o.error("can not move a node to its children"),null;if(e.parent.id!=n){for(var d=e.parent.children,a=d.length;a--;)if(d[a].id==e.id){d.splice(a,1);break}let t=e.parent;e.parent=r,r.children.push(e),this._update_index(t)}e.parent.isroot?s==t.left?e.direction=s: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 o.error("the parameter node "+e+" is not a node."),!1;if(e.isroot)return o.error("fail, can not remove root node"),!1;null!=this.selected&&this.selected.id==e.id&&(this.selected=null),this._purge_selection(e);for(var t=e.children,i=t.length;i--;)this.remove_node(t[i]);t.length=0;for(var n=e.parent,s=n.children,r=s.length;r--;)if(s[r].id==e.id){s.splice(r,1);break}for(var d in delete this.nodes[e.id],e)delete e[d];return e=null,this._update_index(n),!0}_purge_selection(e){this.selected_nodes.has(e)&&this.selected_nodes.delete(e);for(var t=e.children||[],i=0;i<t.length;i++)this._purge_selection(t[i])}_put_node(e){return e.id in this.nodes?(o.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},c={node_tree:{example:{meta:_,format:"node_tree",data:{id:"root",topic:"jsMind node_tree example"}},get_mind:function(e,t){var i=c.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=c.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=c.node_tree,s=i||{},o=s.id||"id",r=s.topic||"topic",d=s.children||"children",a=n._extract_data(t,i);if(e.set_root(t[o],t[r],a),d in t)for(var l=t[d],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",s=i.topic||"topic",o=i.children||"children",r=i.direction||"direction",d=i.expanded||"expanded",a={};for(var l in e)l!=n&&l!=s&&l!=o&&l!=r&&l!=d&&(a[l]=e[l]);return a},_extract_subnode:function(e,i,n,s){var o=c.node_tree,r=s||{},d=r.id||"id",a=r.topic||"topic",l=r.children||"children",h=r.direction||"direction",_=r.expanded||"expanded",u=o._extract_data(n,s),p=null;i.isroot&&(p="left"==n[h]?t.left:t.right);var v=e.add_node(i,n[d],n[a],u,p,n[_]);if(n[l])for(var f=n[l],g=0;g<f.length;g++)o._extract_subnode(e,v,f[g],s)},_build_node:function(e,i){var n=c.node_tree;if(e instanceof l){var s=i||{},o=s.id||"id",r=s.topic||"topic",d=s.children||"children",a=s.direction||"direction",h=s.expanded||"expanded",_={};if(_[o]=e.id,_[r]=e.topic,_[h]=e.expanded,e.parent&&e.parent.isroot&&(_[a]=e.direction==t.left?"left":"right"),null!=e.data){var u=e.data;for(var p in u)_[p]=u[p]}var v=e.children;if(v.length>0){_[d]=[];for(var f=0;f<v.length;f++)_[d].push(n._build_node(v[f],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=c.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=c.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=c.node_array,s=t.slice(0);s.reverse();var r=n._extract_root(e,s,i);r?n._extract_subnode(e,r,s,i):o.error("root node can not be found")},_extract_root:function(e,t,i){for(var n=c.node_array,s=i||{},o=s.id||"id",r=s.topic||"topic",d=s.isroot||"isroot",a=t.length;a--;)if(d in t[a]&&t[a][d]){var l=t[a],h=n._extract_data(l,i),_=e.set_root(l[o],l[r],h);return t.splice(a,1),_}return null},_extract_subnode:function(e,i,n,s){for(var o=c.node_array,r=s||{},d=r.id||"id",a=r.topic||"topic",l=r.parentid||"parentid",h=r.direction||"direction",_=r.expanded||"expanded",u=n.length,p=null,v=null,f=0;u--;)if((p=n[u])[l]==i.id){v=o._extract_data(p,s);var g=null,m=p[h];m&&(g="left"==m?t.left:t.right);var y=e.add_node(i,p[d],p[a],v,g,p[_]);n.splice(u,1),f++;var w=o._extract_subnode(e,y,n,s);w>0&&(u=n.length,f+=w)}return f},_extract_data:function(e,t){var i=t||{},n=i.id||"id",s=i.topic||"topic",o=i.parentid||"parentid",r=i.isroot||"isroot",d=i.direction||"direction",a=i.expanded||"expanded",l={};for(var h in e)h!=n&&h!=s&&h!=o&&h!=r&&h!=d&&h!=a&&(l[h]=e[h]);return l},_array:function(e,t,i){c.node_array._array_node(e.root,t,i)},_array_node:function(e,i,n){var s=c.node_array;if(e instanceof l){var o=n||{},r=o.id||"id",d=o.topic||"topic",a=o.parentid||"parentid",h=o.isroot||"isroot",_=o.direction||"direction",u=o.expanded||"expanded",p={};if(p[r]=e.id,p[d]=e.topic,p[u]=e.expanded,e.parent&&(p[a]=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 f in v)p[f]=v[f]}i.push(p);for(var g=e.children.length,m=0;m<g;m++)s._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=c.freemind,n=new h;n.name=e.meta.name,n.author=e.meta.author,n.version=e.meta.version;var s=e.data,o=i._parse_xml(s),r=i._find_root(o);return i._load_node(n,null,r),n},get_data:function(e,t){var i=c.freemind,n={};n.meta={name:e.name,author:e.author,version:e.version},n.format="freemind";var s=[];return s.push('<map version="1.0.1">'),i._build_map(e.root,s),s.push("</map>"),n.data=s.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,s=0;s<t.length;s++)if(1==(n=t[s]).nodeType&&"map"==n.tagName){i=n;break}if(i){var o=i.childNodes;i=null;for(s=0;s<o.length;s++)if(1==(n=o[s]).nodeType&&"node"==n.tagName){i=n;break}}return i},_load_node:function(e,i,n){var s=c.freemind,o=n.getAttribute("ID"),r=n.getAttribute("TEXT"),d=n.getAttribute("FOLDED");if(null==r)for(var a=n.childNodes,l=null,h=0;h<a.length;h++)if(1==(l=a[h]).nodeType&&"richcontent"===l.tagName){r=l.textContent;break}var _=s._load_attributes(n),u="expanded"in _?"true"==_.expanded:"true"!=d;delete _.expanded;var p=n.getAttribute("COLOR");p&&(_["foreground-color"]=p);var v=n.getAttribute("BACKGROUND_COLOR");v&&(_["background-color"]=v);var f=n.getAttribute("POSITION"),g=null;f&&(g="left"==f?t.left:t.right);var m=null;m=i?e.add_node(i,o,r,_,g,u):e.set_root(o,r,_);var y=n.childNodes,w=null;for(h=0;h<y.length;h++)1==(w=y[h]).nodeType&&"node"==w.tagName&&s._load_node(e,m,w)},_load_attributes:function(e){for(var t=e.childNodes,i=null,n={},s=0;s<t.length;s++)1==(i=t[s]).nodeType&&"attribute"===i.tagName&&(n[i.getAttribute("NAME")]=i.getAttribute("VALUE"));return n},_build_map:function(e,i){var n=c.freemind,s=null,o=e.data;if(e.parent&&e.parent.isroot&&(s=e.direction===t.left?"left":"right"),i.push("<node"),i.push(' ID="'+e.id+'"'),s&&i.push(' POSITION="'+s+'"'),e.expanded||i.push(' FOLDED="true"'),o["foreground-color"]&&i.push(' COLOR="'+o["foreground-color"]+'"'),o["background-color"]&&i.push(' BACKGROUND_COLOR="'+o["background-color"]+'"'),i.push(' TEXT="'+n._escape(e.topic)+'">'),null!=o)for(var r in o)"foreground-color"!==r&&"background-color"!==r&&i.push('<attribute NAME="'+r+'" VALUE="'+o[r]+'"/>');for(var d=e.children,a=0;a<d.length;a++)n._build_map(d[a],i);i.push("</node>")},_escape:function(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/"/g,""")}},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=c.text,n=new h;n.name=e.meta.name,n.author=e.meta.author,n.version=e.meta.version;var s=e.data.split(/\n|\r/);return i._fill_nodes(n,s,0,0),n},_fill_nodes:function(e,t){let i=[],n=0;for(;n<t.length;){let s=t[n],o=s.match(/\s*/)[0].length,r=s.substr(o);if(0==o&&i.length>0)return void log.error("more than 1 root node was found: "+r);if(o>i.length)return void log.error("a suspended node was found: "+r);let a=i.length-o;for(;a--;)i.pop();if(0==o&&0==i.length){let t=e.set_root(d.uuid.newid(),r);i.push(t)}else{let t=e.add_node(i[o-1],d.uuid.newid(),r,{},null);i.push(t)}n++}i.length=0},get_data:function(e){var t=c.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 s of t)e.push(n+s.topic),s.children&&c.text._build_lines(e,s.children,i+1)}}};class u{constructor(e){this.jm=e}init(){o.debug("data.init")}reset(){o.debug("data.reset")}load(e){var t=null,i=null;t="object"==typeof e?e.format?e.format:"node_tree":"freemind";var n=this.jm.options.fieldNames;return"node_array"==t?i=c.node_array.get_mind(e,n):"node_tree"==t?i=c.node_tree.get_mind(e,n):"freemind"==t?i=c.freemind.get_mind(e,n):"text"==t?i=c.text.get_mind(e,n):o.warn("unsupported format"),i}get_data(e){var t=null,i=this.jm.options.fieldNames;return"node_array"==e?t=c.node_array.get_data(this.jm.mind,i):"node_tree"==e?t=c.node_tree.get_data(this.jm.mind,i):"freemind"==e?t=c.freemind.get_data(this.jm.mind):"text"==e?t=c.text.get_data(this.jm.mind):o.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(){o.debug("layout.init")}reset(){o.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,s=0,o=0;o<n;o++)i[o].direction===t.left?s--:s++;return n>1&&s>0?t.left:t.right}layout(){o.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,s=n.length;if(i.direction=t.center,i.side_index=0,this.isside)for(var o=s;o--;)this._layout_direction_side(n[o],t.right,o);else{o=s;for(var r=null;o--;)(r=n[o]).direction==t.left?this._layout_direction_side(r,t.left,o):this._layout_direction_side(r,t.right,o)}}_layout_direction_side(e,t,i){var n=null;"layout"in e._data?n=e._data.layout:(n={},e._data.layout=n);var s=e.children,o=s.length;n.direction=t,n.side_index=i;for(var r=o;r--;)this._layout_direction_side(s[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,s=n.length,o=[],r=[],d=null;s--;)(d=n[s])._data.layout.direction==t.right?r.unshift(d):o.unshift(d);i.left_nodes=o,i.right_nodes=r,i.outer_height_left=this._layout_offset_subnodes(o),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,s=null,o=0,r=null,d=0,a=null;n--;)r=(s=e[n])._data.layout,null==a&&(a=s.parent._data),o=this._layout_offset_subnodes(s.children),s.expanded||(o=0,this.set_visible(s.children,!1)),o=Math.max(s._data.view.height,o),this._should_reserve_cousin_space(s)&&(o+=this.opts.cousin_space),r.outer_height=o,r.offset_y=d-o/2,r.offset_x=this.opts.hspace*r.direction+a.view.width*(a.layout.direction+r.direction)/2,s.parent.isroot||(r.offset_x+=this.opts.pspace*r.direction),d=d-o-this.opts.vspace,t+=o;i>1&&(t+=this.opts.vspace*(i-1)),n=i;for(var l=t/2;n--;)(s=e[n])._data.layout.offset_y+=l;return t}_layout_offset_subnodes_height(e){for(var t=0,i=e.length,n=i,s=null,o=0,r=null,d=0,a=null;n--;)r=(s=e[n])._data.layout,null==a&&(a=s.parent._data),o=this._layout_offset_subnodes_height(s.children),s.expanded||(o=0),o=Math.max(s._data.view.height,o),this._should_reserve_cousin_space(s)&&(o+=this.opts.cousin_space),r.outer_height=o,r.offset_y=d-o/2,d=d-o-this.opts.vspace,t+=o;i>1&&(t+=this.opts.vspace*(i-1)),n=i;for(var l=t/2;n--;)(s=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,s=t.offset_y;if(!e.isroot){var o=this.get_node_offset(e.parent);n+=o.x,s+=o.y}i.x=n,i.y=s}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,s=this.get_node_offset(e);i.x=s.x+(n.width+this.opts.pspace)*e._data.layout.direction,i.y=s.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 s=this.jm.mind.root;this.part_layout(s),this.set_visible(s.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 s=this.jm.mind.root;this.part_layout(s),this.set_visible(s.children,!0)}}expand_to_depth(e,t,i){if(!(e<1))for(var n=t||this.jm.mind.root.children,s=i||1,o=n.length,r=null;o--;)r=n[o],s<e&&(r.expanded||this.expand_node(r),this.expand_to_depth(e,r.children,s+1)),s==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 o.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,s)=>{try{this.opts.custom_line_render.call(this,{ctx:e,start_point:{x:t,y:i},end_point:{x:n,y:s}})}catch(e){o.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 s=v.c("path");s.setAttribute("stroke",n||this.opts.line_color),s.setAttribute("stroke-width",this.opts.line_width),s.setAttribute("fill","transparent"),this.lines.push(s),this.e_svg.appendChild(s),this.drawing(s,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,s){e.setAttribute("d","M "+t+" "+i+" C "+(t+2*(n-t)/3)+" "+i+", "+t+" "+s+", "+n+" "+s)}_line_to(e,t,i,n,s){e.setAttribute("d","M "+t+" "+i+" L "+n+" "+s)}}class f{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,s)=>{try{this.opts.custom_line_render.call(this,{ctx:e,start_point:{x:t,y:i},end_point:{x:n,y:s}})}catch(e){o.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 s=this.canvas_ctx;s.strokeStyle=n||this.opts.line_color,s.lineWidth=this.opts.line_width,s.lineCap="round",this.drawing(s,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,s){e.beginPath(),e.moveTo(t,i),e.bezierCurveTo(t+2*(n-t)/3,i,t,s,n,s),e.stroke()}_line_to(e,t,i,n,s){e.beginPath(),e.moveTo(t,i),e.lineTo(n,s),e.stroke()}}class g{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.multi_selected_nodes=new Map,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(o.debug(this.opts),o.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 f(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 o.error("the options.view.container was not be found in dom")}add_event(e,t,i,n){let s=n?this.e_panel:this.e_nodes;r.on(s,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(){o.debug("view.reset"),this.selected_node=null,this.multi_selected_nodes.clear(),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(){o.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,s=this.e_panel.clientHeight;n<t&&(n=t),s<i&&(s=i),this.size.w=n,this.size.h=s}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():(o.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 s=r.c("jmexpander");r.t(s,"-"),s.setAttribute("nodeid",e.id),s.style.visibility="hidden",t.appendChild(s),i.expander=s}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){this._unmark_node_selected(e),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,s=e._data.view.expander;this.e_nodes.removeChild(n),this.e_nodes.removeChild(s),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){this.clear_all_selected_nodes(),e&&(this.selected_node=e,this._mark_node_selected(e))}select_clear(){this.clear_all_selected_nodes()}append_selected_nodes(e,t){if(e&&e.length){for(var i=0;i<e.length;i++)this._mark_node_selected(e[i]);this.selected_node=t||e[e.length-1]}}remove_selected_nodes(e){if(e&&e.length)for(var t=0;t<e.length;t++)this._unmark_node_selected(e[t])}clear_all_selected_nodes(){if(this.multi_selected_nodes.size){for(var e=Array.from(this.multi_selected_nodes.values()),t=0;t<e.length;t++)this._unmark_node_selected(e[t]);this.selected_node=null}else this.selected_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 o.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),d.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},s=(this.e_panel.scrollLeft+n.x)*e/this.zoom_current-n.x,o=(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=s,this.e_panel.scrollTop=o,!0}show(e){o.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,s=null,o=this.get_view_offset();for(var r in e)i=(s=(t=e[r])._data.view).element,this.layout.is_visible(t)?(this.reset_node_custom_style(t),n=this.layout.get_node_point(t),s.abs_x=o.x+n.x,s.abs_y=o.y+n.y,i.style.left=o.x+n.x+"px",i.style.top=o.y+n.y+"px",i.style.display="",i.style.visibility="visible",this._show_expander(t,o)):(i.style.display="none",s.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 s=this.layout.get_expander_point(e);i.style.left=t.x+s.x+"px",i.style.top=t.y+s.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=""}_mark_node_selected(e){if(e&&!this.multi_selected_nodes.has(e.id)){var t=e._data.view.element;t&&(/(\s|^)selected(\s|$)/.test(t.className)||(t.className+=" selected"),this.clear_selected_node_custom_style(e),this.multi_selected_nodes.set(e.id,e))}}_unmark_node_selected(e){if(e){if(this.multi_selected_nodes.has(e.id)){var t=e._data.view.element;t&&(t.className=t.className.replace(/\s*selected\b/i,"")),this.restore_selected_node_custom_style(e),this.multi_selected_nodes.delete(e.id)}this.selected_node&&this.selected_node.id==e.id&&(this.selected_node=null)}}clear_lines(){this.graph.clear()}show_lines(){this.clear_lines();var e=this.jm.mind.nodes,t=null,i=null,n=null,s=null,o=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),s=t.data["leading-line-color"],this.graph.draw_line(n,i,o,s))}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 o.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,s=t.abs_y+t.height/2;return this.e_panel.scrollTo(n*this.zoom_current-i.width/2,s*this.zoom_current-i.height/2),!0}zoomIn(e){return o.warn("please use zoom_in instead"),this.zoom_in(e)}zoomOut(e){return o.warn("please use zoom_out instead"),this.zoom_out(e)}setZoom(e,t){return o.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=d.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 s=e.find_node_before(n);if(!s){var o=e.find_node_before(n.parent);o&&o.children.length>0&&(s=o.children[o.children.length-1])}s&&e.select_node(s),i.stopPropagation(),i.preventDefault()}}handle_down(e,t){var i=t||event,n=e.get_selected_node();if(n){var s=e.find_node_after(n);if(!s){var o=e.find_node_after(n.parent);o&&o.children.length>0&&(s=o.children[0])}s&&e.select_node(s),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,s=e.get_selected_node(),o=null;if(s){if(s.isroot){for(var r=s.children,d=[],a=0;a<r.length;a++)r[a].direction===i&&d.push(a);o=r[d[Math.floor((d.length-1)/2)]]}else if(s.direction===i){var l=(d=s.children).length;l>0&&(o=d[Math.floor((l-1)/2)])}else o=s.parent;o&&e.select_node(o),n.stopPropagation(),n.preventDefault()}}}const y={plugins:[]};function w(e){if(!(e instanceof x))throw new Error("can not register plugin, it is not an instance of Plugin");if(y.plugins.map((e=>e.name)).includes(e.name))throw new Error("can not register plugin "+e.name+": plugin name already exist");y.plugins.push(e)}function b(e,t){r.w.setTimeout((function(){!function(e,t){y.plugins.forEach((i=>i.fn_init(e,t[i.name])))}(e,t)}),0)}class x{constructor(e,t){if(!e)throw new Error("plugin must has a name");if(!t||"function"!=typeof t)throw new Error("plugin must has an init function");this.name=e,this.fn_init=t}}class k{constructor(e){this.jm=e,this.plugins=new Map}initPreloadPlugins(){const e=this.jm.constructor.enhancedPluginList.filter((e=>e.preload));o.info("Initializing "+e.length+" preload plugins"),e.forEach((e=>{this._initPlugin(e)}))}initNormalPlugins(){const e=this.jm.constructor.enhancedPluginList.filter((e=>!e.preload));o.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)&&o.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,o.info("Enhanced plugin "+t.instanceName+" initialized")}catch(t){o.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.enhancedPluginList,s=n.findIndex((t=>t.PluginClass===e));-1!==s&&n.splice(s,1),o.info("Enhanced plugin "+t+" removed")}catch(e){o.error("Failed to remove plugin "+t+":",e)}}destroyAllPlugins(){this.plugins.forEach(((e,t)=>{try{"function"==typeof e.beforePluginDestroy&&e.beforePluginDestroy()}catch(e){o.error("Failed to destroy plugin "+t+":",e)}})),this.plugins.clear()}getPlugin(e){return this.plugins.get(e)}}class z{static instanceName="";static preload=!1;constructor({jm:e,pluginOpt:t}){this.jm=e,this.options=t||{}}beforePluginRemove(){}beforePluginDestroy(){this.beforePluginRemove()}}class j{static mind=h;static node=l;static direction=t;static event_type=i;static $=r;static plugin=x;static register_plugin=w;static util=d;static enhanced_plugin=z;static enhancedPluginList=[];static usePlugin(e,t={}){if(j.enhancedPluginList.some((t=>t.PluginClass===e)))return o.warn("Plugin "+e.name+" already registered"),j;if(!e.instanceName)throw new Error("Plugin "+e.name+" must define static instanceName");return j.enhancedPluginList.push({PluginClass:e,instanceName:e.instanceName,preload:e.preload||!1,pluginOpt:t,instance:null}),j}static hasEnhancedPlugin(e){return j.enhancedPluginList.some((t=>t.PluginClass===e))}constructor(t){j.current=this,this.options=function(e){var t={};if(d.json.merge(t,a),d.json.merge(t,e),!t.container)throw new Error("the options.container should not be null or empty.");return t}(t),o.level(n[this.options.log_level]),this.version=e,this.initialized=!1,this.mind=null,this._selection_mode=null,this._last_selected_node=null,this.event_handles=[],this.init()}init(){if(!this.initialized){this.initialized=!0,this.enhancedPluginManager=new k(this),this.enhancedPluginManager.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 u(this),this.layout=new p(this,e),this.view=new g(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.enhancedPluginManager.initNormalPlugins(),b(this,this.options.plugin)}}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,n=this.view.get_binded_nodeid(t),s=this._get_multi_select_mode(e);if(n){if(this.view.is_node(t))if("ctrl"===s)this._toggle_node_selection(n);else if("shift"===s)if(this.options.selection&&this.options.selection.shift_simple_mode)this.is_node_selected(n)?this._deselect_subtree(n):this._range_select_nodes(n);else{var o=this.get_node(n);if(o)if(this.is_node_selected(n))this._deselect_subtree(n);else{var r=this._collect_subtree_nodes(o,{includeChildren:!0,respectFilter:!0,skipRootFilter:!0});r.length||(r=[o]);var d=this._append_selection(r,{focusNode:o});if(d.length){this.mind.selected=o,this._last_selected_node=o,this._selection_mode=this._derive_selection_mode();var a=d.map((function(e){return e.id}));this.invoke_event_handle(i.select,{evt:"multi_select",data:a,node:o.id,nodes:a})}}}else this.select_node(n)}else null===s&&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):(o.error("the node[id="+e+"] can not be found."),!1)}this.get_editable()?this.view.edit_node_begin(e):o.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 o.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 o.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 o.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||c.node_array.example;this.mind=this.data.load(n),this.mind?(o.debug("data.load ok"),this.view.load(),o.debug("view.load ok"),this.layout.layout(),o.debug("layout.layout ok"),this.view.show(!t),o.debug("view.show ok"),this.invoke_event_handle(i.show,{data:[e]})):o.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 o.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,s,o){var r=t.of(o);void 0===r&&(r=this.layout.calculate_next_child_direction(e));var d=this.mind.add_node(e,i,n,s,r);return d&&(this.view.add_node(d),this.view.reset_node_custom_style(d)),d}_refresh_node_ui(e){this.layout.layout(),this.view.show(!1),this.expand_node(e)}add_node(e,n,s,r,d){if(!this.get_editable())return o.error("fail, this mind map is not editable"),null;var a=this.get_node(e);if(!a)return o.error("parent node not found"),null;var l=this._add_node_data(a,n,s,r,d);return l&&(this._refresh_node_ui(a),this.invoke_event_handle(i.edit,{evt:"add_node",data:[a.id,n,s,r,t.of(d)],node:n})),l}add_nodes(e,t){if(!this.get_editable())return o.error("fail, this mind map is not editable"),[];var n=this.get_node(e);if(!n)return o.error("parent node not found"),[];if(!Array.isArray(t)||0===t.length)return o.warn("nodes_data should be a non-empty array"),[];const s=this._count_expected_nodes(t);let r=t.map((e=>this._add_nodes_recursive(n,e))).flat().filter((e=>null!==e));const d=r.length;return d===s?(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):(o.warn(`Expected ${s} nodes, but only created ${d}. Cleaning up...`),this._cleanup_partial_nodes(r),[])}_add_nodes_recursive(e,t){var i=[];if(!t.id||!t.topic)return o.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,s,r,d){if(this.get_editable()){var a=this.get_node(e),l=t.of(d);void 0===l&&(l=this.layout.calculate_next_child_direction(a.parent));var h=this.mind.insert_node_before(a,n,s,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:[a.id,n,s,r,l],node:n})),h}return o.error("fail, this mind map is not editable"),null}insert_node_after(e,n,s,r,d){if(this.get_editable()){var a=this.get_node(e),l=t.of(d);void 0===l&&(l=this.layout.calculate_next_child_direction(a.parent));var h=this.mind.insert_node_after(a,n,s,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:[a.id,n,s,r,l],node:n})),h}return o.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):(o.error("the node[id="+e+"] can not be found."),!1)}if(this.get_editable()){if(e.isroot)return o.error("fail, can not remove root node"),!1;var n=e.id,s=e.parent.id,r=this.get_node(s);return this.view.save_location(r),this.view.remove_node(e),this.mind.remove_node(e),this._last_selected_node&&this._last_selected_node.id===n&&(this._last_selected_node=null),this.layout.layout(),this.view.show(!1),this.view.restore_location(r),this.invoke_event_handle(i.edit,{evt:"remove_node",data:[n],node:s}),!0}return o.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 d.text.is_empty(t)?void o.warn("fail, topic can not be empty"):n.topic===t?(o.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 s=n.id,r=!1;if(void 0!==t.topic){if(d.text.is_empty(t.topic))return void o.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 a in t.data)t.data.hasOwnProperty(a)&&n.data[a]!==t.data[a]&&(n.data[a]=t.data[a],r=!0);if(void 0!==t.id){if("string"!=typeof t.id||""===t.id.trim())return void o.error("fail, new node id must be a non-empty string");if(n.id!==t.id){if(n.isroot)return void o.error("fail, cannot change root node id");if(t.id in this.mind.nodes)return void o.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 o.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:[s,t],node:s})}}else o.error("fail, node not found")}else o.error("fail, this mind map is not editable")}move_node(e,t,n,s){if(this.get_editable()){var r=this.get_node(e),d=this.mind.move_node(r,t,n,s);d&&(this.view.update_node(d),this.layout.layout(),this.view.show(!1),this.invoke_event_handle(i.edit,{evt:"move_node",data:[e,t,n,s],node:e}))}else o.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 o.error("the node[id="+e+"] can not be found.")}this.layout.is_visible(e)&&(this._clear_selection_state(),this.mind.selected=e,this._last_selected_node=e,this._append_selection([e]),this._selection_mode="single",this.invoke_event_handle(i.select,{evt:"select_node",data:[],node:e.id,nodes:[e.id]}))}get_selected_node(){return this.mind?this.mind.selected:null}get_selected_nodes(){return this.mind?Array.from(this.mind.selected_nodes):[]}select_clear(){this.mind&&(this.mind.selected=null,this._last_selected_node=null,this._clear_selection_state())}toggle_subtree_selection(e){if(this.options.selection&&this.options.selection.enable_multi_select){if(!l.is_node(e)){var t=this.get_node(e);return t?void this.toggle_subtree_selection(t):void o.error("the node[id="+e+"] can not be found.")}if(this.layout.is_visible(e))if(!this.mind.selected_nodes.has(e)||"multi"!==this._selection_mode){this._selection_mode="multi";var n=!1!==this.options.selection.include_descendants,s=this._collect_subtree_nodes(e,{includeChildren:n,respectFilter:!0,skipRootFilter:!0});s.length||(s=[e]);var r=this._append_selection(s,{focusNode:e}),d=e.parent&&!this.mind.selected_nodes.has(e.parent)?this._ensure_ancestor_selection([e],e,{requireAncestorChainSelected:!0}):[],a=r.concat(d);if(a.length){this.mind.selected=e;var h=a.map((e=>e.id));this.invoke_event_handle(i.select,{evt:"multi_select",data:h,node:e.id,nodes:h})}}else{var _=this._collect_subtree_nodes(e,{includeChildren:!0,respectFilter:!1,skipRootFilter:!1});_.length||(_=[e]);var c=this._remove_selection(_);if(c.length){this.mind.selected&&this.mind.selected.id===e.id&&(this.mind.selected=null);var u=c.map((e=>e.id));this._selection_mode=this._derive_selection_mode(),this.invoke_event_handle(i.select,{evt:"multi_deselect",data:u,node:e.id,nodes:u})}}}else this.select_node(e)}is_node_selected(e){var t=e;return l.is_node(e)||(t=this.get_node(e)),!(!t||!this.mind)&&this.mind.selected_nodes.has(t)}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):o.error("the node[id="+e+"] can not be found.")}}_append_selection(e,t){if(!e||!e.length)return[];for(var i=[],n=0;n<e.length;n++){var s=e[n];this.mind.selected_nodes.has(s)||(this.mind.selected_nodes.add(s),i.push(s))}if(i.length){var o=t&&t.focusNode?t.focusNode:null;this.view.append_selected_nodes(i,o||i[i.length-1])}return i}_remove_selection(e){if(!e||!e.length)return[];for(var t=[],i=0;i<e.length;i++){var n=e[i];this.mind.selected_nodes.has(n)&&(this.mind.selected_nodes.delete(n),t.push(n))}return t.length&&this.view.remove_selected_nodes(t),t}_deselect_subtree(e){var t=l.is_node(e)?e:this.get_node(e);if(t){var n=this._collect_subtree_nodes(t,{includeChildren:!0,respectFilter:!1,skipRootFilter:!1});n.length||(n=[t]);var s=this._remove_selection(n);if(s.length){this.mind.selected&&this.mind.selected.id===t.id&&(this.mind.selected=null);var r=s.map((function(e){return e.id}));this._selection_mode=this._derive_selection_mode(),this.invoke_event_handle(i.select,{evt:"multi_deselect",data:r,node:t.id,nodes:r})}}else o.error("the node[id="+e+"] can not be found.")}_clear_selection_state(){if(this._selection_mode=null,!this.mind.selected_nodes.size)return this.view.clear_all_selected_nodes(),[];var e=Array.from(this.mind.selected_nodes);return this.mind.selected_nodes.clear(),this.view.remove_selected_nodes(e),e}_collect_subtree_nodes(e,t){var i=t||{},n=!1!==i.includeChildren,s=!!i.respectFilter,o=!!i.skipRootFilter,r=s?this._get_selection_filter():null,d=[],a=function(e,t){var i=!0;if(!r||o&&t||(i=!1!==r(e)),i&&d.push(e),n)for(var s=e.children||[],l=0;l<s.length;l++)a(s[l],!1)};return a(e,!0),d}_ensure_ancestor_selection(e,t,i){if(!e||!e.length)return[];for(var n=!(!i||!i.requireAncestorChainSelected),s=[],o=Object.create(null),r=0;r<e.length;r++){var d=e[r].parent;if(d){for(var a=[],l=!n;d;){if(this.mind.selected_nodes.has(d)){l=!0;break}a.push(d),d=d.parent}if(l)for(var h=0;h<a.length;h++){var _=a[h];this.mind.selected_nodes.has(_)||o[_.id]||(s.push(_),o[_.id]=!0)}}}if(!s.length)return[];var c=t||e[e.length-1];return this._append_selection(s,{focusNode:c})}_get_selection_filter(){var e=this.options.selection||{};return e&&"function"==typeof e.filter?e.filter:null}_get_multi_select_mode(e){return(this.options.selection||{}).enable_multi_select&&e?e.shiftKey?"shift":e.ctrlKey||e.metaKey?"ctrl":null:null}_toggle_node_selection(e){var t=l.is_node(e)?e:this.get_node(e);t&&this.layout.is_visible(t)&&(this.mind.selected_nodes.has(t)?this._deselect_subtree(t):(this._selection_mode="multi",this._append_selection([t]).length&&(this.mind.selected=t,this._last_selected_node=t,this.invoke_event_handle(i.select,{evt:"multi_select",data:[t.id],node:t.id,nodes:[t.id]}))))}_range_select_nodes(e){var t=l.is_node(e)?e:this.get_node(e);if(t&&this.layout.is_visible(t))if(0!==this.mind.selected_nodes.size){var n=Array.from(this.mind.selected_nodes)[0],s=this._last_selected_node&&this.mind.selected_nodes.has(this._last_selected_node)?this._last_selected_node:n,o=this._find_nodes_between(s,t);o.length||(o=[t]);var r=new Set,d=!1,a=!this._is_ancestor_of(s,t)&&!this._is_ancestor_of(t,s),h=this._find_lca(s,t),_=this._child_on_path(h,t),c=this._child_on_path(h,s),u=(c=this._child_on_path(h,s),this._child_on_path(h,t));if(h&&c&&u&&c!==u&&s===c&&t===u&&!d){var p=Array.isArray(h.children)?h.children:[],v=p.indexOf(c),f=p.indexOf(u);if(v>=0&&f>=0){for(var g=Math.min(v,f),m=Math.max(v,f),y=g;y<=m;y++)for(var w=p[y],b=this._collect_subtree_nodes(w,{includeChildren:!0,respectFilter:!1,skipRootFilter:!0}),x=0;x<b.length;x++)r.add(b[x]);d=!0}}if(a&&c&&u&&s===c&&t===u){for(var k=[],z=0;z<o.length;z++){var j=o[z];j!==s&&(this._is_ancestor_of(s,j)||this._is_ancestor_of(j,t)||k.push(j))}for(var C=this._remove_descendant_nodes(k),P=0;P<C.length;P++)for(var N=C[P],A=this._collect_subtree_nodes(N,{includeChildren:!0,respectFilter:!1,skipRootFilter:!0}),M=0;M<A.length;M++)r.add(A[M]);if(_&&t!==_)if((Z=t.parent)&&Array.isArray(Z.children))for(var E=Z.children.indexOf(t),F=0;F<=E;F++)for(var L=Z.children[F],O=this._collect_subtree_nodes(L,{includeChildren:!0,respectFilter:!1,skipRootFilter:!0}),R=0;R<O.length;R++)r.add(O[R]);else r.add(t);else for(var T=this._collect_subtree_nodes(t,{includeChildren:!0,respectFilter:!1,skipRootFilter:!0}),I=0;I<T.length;I++)r.add(T[I]);d=!0}if(!d)if(_){if(t===_)for(var S=this._collect_subtree_nodes(t,{includeChildren:!0,respectFilter:!1,skipRootFilter:!0}),D=0;D<S.length;D++)r.add(S[D]);else if((Z=t.parent)&&Array.isArray(Z.children))for(E=Z.children.indexOf(t),F=0;F<=E;F++){L=Z.children[F];for(var B=this._collect_subtree_nodes(L,{includeChildren:!0,respectFilter:!1,skipRootFilter:!0}),K=0;K<B.length;K++)r.add(B[K])}else for(var W=this._collect_subtree_nodes(t,{includeChildren:!0,respectFilter:!1,skipRootFilter:!0}),H=0;H<W.length;H++)r.add(W[H])}else{var X=t.parent;if(X&&Array.isArray(X.children))for(var U=X.children.indexOf(t),V=0;V<=U;V++)for(var $=X.children[V],Y=this._collect_subtree_nodes($,{includeChildren:!0,respectFilter:!1,skipRootFilter:!0}),q=0;q<Y.length;q++)r.add(Y[q]);else r.add(t)}if(0===r.size&&t)for(var G=this._collect_subtree_nodes(t,{includeChildren:!0,respectFilter:!1,skipRootFilter:!0}),J=0;J<G.length;J++)r.add(G[J]);if(_&&t!==_&&t.parent&&Array.isArray(t.parent.children))for(var Z,Q=(E=(Z=t.parent).children.indexOf(t))+1;Q<Z.children.length;Q++)for(var ee=Z.children[Q],te=this._collect_subtree_nodes(ee,{includeChildren:!0,respectFilter:!1,skipRootFilter:!0}),ie=0;ie<te.length;ie++)r.has(te[ie])&&r.delete(te[ie]);t&&r.add(t);var ne=Array.from(r).filter(function(e){return!this.mind.selected_nodes.has(e)}.bind(this));if((se=this._append_selection(ne)).length){this.mind.selected=t,this._last_selected_node=t,this._selection_mode=this._derive_selection_mode();re=se.map((function(e){return e.id}));this.invoke_event_handle(i.select,{evt:"multi_select",data:re,node:t.id,nodes:re})}}else{var se,oe=this._collect_subtree_nodes(t,{includeChildren:!0,respectFilter:!0,skipRootFilter:!0});if(oe.length||(oe=[t]),(se=this._append_selection(oe)).length){this.mind.selected=t,this._last_selected_node=t,this._selection_mode=this._derive_selection_mode();var re=se.map((e=>e.id));this.invoke_event_handle(i.select,{evt:"multi_select",data:re,node:t.id,nodes:re})}}}_find_nodes_between(e,t){if(!e||!t)return[];var i=[],n=e=>{if(this.layout.is_visible(e)&&i.push(e),e.children&&e.children.length)for(var t=0;t<e.children.length;t++)n(e.children[t])};this.mind&&this.mind.root&&n(this.mind.root);for(var s=-1,o=-1,r=0;r<i.length;r++)i[r].id===e.id&&(s=r),i[r].id===t.id&&(o=r);if(-1===s||-1===o)return[];var d=Math.min(s,o),a=Math.max(s,o);return i.slice(d,a+1)}_is_ancestor_of(e,t){if(!e||!t)return!1;for(var i=t.parent;i;){if(i===e)return!0;i=i.parent}return!1}_get_path_nodes(e,t){if(!e||!t)return[];for(var i=[],n=t;n&&(i.push(n),n!==e);)n=n.parent;return i.length&&i[i.length-1]===e?(i.reverse(),i):[]}_find_nearest_selected_ancestor(e){if(!e||!this.mind||!this.mind.selected_nodes)return null;for(var t=e.parent;t;){if(this.mind.selected_nodes.has(t))return t;t=t.parent}return null}_find_lca(e,t){if(!e||!t)return null;if(e===t)return e.parent||e;for(var i=new Set,n=e;n;)i.add(n),n=n.parent;for(n=t;n;){if(i.has(n))return n;n=n.parent}return null}_child_on_path(e,t){if(!e||!t)return null;if(e===t)return null;for(var i=t;i&&i.parent&&i.parent!==e;)i=i.parent;return i&&i.parent===e?i:null}_remove_ancestor_nodes(e,t){if(!e||!e.length)return[];for(var i=t||new Set,n=[],s=0;s<e.length;s++){var o=e[s];if(i.has(o))n.push(o);else{for(var r=!1,d=0;d<e.length;d++)if(s!==d&&this._is_ancestor_of(o,e[d])){r=!0;break}r||n.push(o)}}return n}_remove_descendant_nodes(e){if(!e||!e.length)return[];for(var t=[],i=0;i<e.length;i++){for(var n=e[i],s=!1,o=0;o<e.length;o++)if(i!==o&&this._is_ancestor_of(e[o],n)){s=!0;break}s||t.push(n)}return t}_expand_with_descendants(e,t){var i=!(!t||!t.respectFilter),n=new Set;if(!e||!e.length)return n;for(var s=0;s<e.length;s++)for(var o=e[s],r=this._collect_subtree_nodes(o,{includeChildren:!0,respectFilter:i,skipRootFilter:!0}),d=0;d<r.length;d++)n.add(r[d]);return n}_promote_parents_when_children_selected(e){if(!e||!e.size)return e||new Set;for(var t=new Set(e),i=this.mind&&this.mind.selected_nodes?this.mind.selected_nodes:new Set,n=!0;n;){n=!1;var s=[];if(t.forEach((function(e){var n=e.parent;if(n&&!t.has(n)){for(var o=!1,r=n.parent;r;){if(i.has(r)){o=!0;break}r=r.parent}o&&s.push(n)}})),s.length){for(var o=0;o<s.length;o++)t.add(s[o]);n=!0}}return t}_derive_selection_mode(){var e=this.mind.selected_nodes.size;return 0===e?null:e>1?"multi":"single"}find_node_before(e){if(!l.is_node(e)){var t=this.get_node(e);return t?this.find_node_before(t):void o.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,s=null,r=null,d=0;d<n.length;d++)r=n[d],e.direction===r.direction&&(e.id===r.id&&(i=s),s=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 o.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,s=!1,r=null,d=0;d<n.length;d++)if(r=n[d],e.direction===r.direction){if(s){i=r;break}e.id===r.id&&(s=!0)}}else i=this.mind.get_node_after(e);return i}set_node_color(e,t,i){if(!this.get_editable())return o.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 o.error("fail, this mind map is not editable"),null;var s=this.mind.get_node(e);s&&(t&&(s.data["font-size"]=t),i&&(s.data["font-weight"]=i),n&&(s.data["font-style"]=n),this.view.reset_node_custom_style(s),this.view.update_node(s),this.layout.layout(),this.view.show(!1))}set_node_background_image(e,t,i,n,s){if(!this.get_editable())return o.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),s&&(r.data["background-rotation"]=s),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 o.error("fail, this mind map is not editable"),null;var i=this.mind.get_node(e);if(i){if(!i.data["background-image"])return o.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.enhancedPluginManager&&this.enhancedPluginManager.removePlugin(e)}getPlugin(e){if(this.enhancedPluginManager)return this.enhancedPluginManager.getPlugin(e)}destroy(){this.enhancedPluginManager&&this.enhancedPluginManager.destroyAllPlugins(),this.clear_event_listener(),this.view&&this.view.reset(),this.mind=null,this.initialized=!1}static show(e,t){o.warn("`jsMind.show(options, mind)` is deprecated, please use `jm = new jsMind(options); jm.show(mind);` instead");var i=new j(e);return i.show(t),i}}export{j as default};
|
|
8
|
+
const e="0.9.0";"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)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}_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 w=e.add_node(i,p[a],p[d],v,f,p[_]);n.splice(c,1),g++;var y=s._extract_subnode(e,w,n,o);y>0&&(c=n.length,g+=y)}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 w=n.childNodes,y=null;for(h=0;h<w.length;h++)1==(y=w[h]).nodeType&&"node"==y.tagName&&o._load_node(e,m,y)},_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,"&").replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/"/g,""")}},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";var n=this.jm.options.fieldNames;return"node_array"==t?i=u.node_array.get_mind(e,n):"node_tree"==t?i=u.node_tree.get_mind(e,n):"freemind"==t?i=u.freemind.get_mind(e,n):"text"==t?i=u.text.get_mind(e,n):s.warn("unsupported format"),i}get_data(e){var t=null,i=this.jm.options.fieldNames;return"node_array"==e?t=u.node_array.get_data(this.jm.mind,i):"node_tree"==e?t=u.node_tree.get_data(this.jm.mind,i):"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()}}}const w={plugins:[]};function y(e){if(!(e instanceof x))throw new Error("can not register plugin, it is not an instance of Plugin");if(w.plugins.map((e=>e.name)).includes(e.name))throw new Error("can not register plugin "+e.name+": plugin name already exist");w.plugins.push(e)}function b(e,t){r.w.setTimeout((function(){!function(e,t){w.plugins.forEach((i=>i.fn_init(e,t[i.name])))}(e,t)}),0)}class x{constructor(e,t){if(!e)throw new Error("plugin must has a name");if(!t||"function"!=typeof t)throw new Error("plugin must has an init function");this.name=e,this.fn_init=t}}class z{constructor(e){this.jm=e,this.plugins=new Map}initPreloadPlugins(){const e=this.jm.constructor.enhancedPluginList.filter((e=>e.preload));s.info("Initializing "+e.length+" preload plugins"),e.forEach((e=>{this._initPlugin(e)}))}initNormalPlugins(){const e=this.jm.constructor.enhancedPluginList.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("Enhanced 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.enhancedPluginList,o=n.findIndex((t=>t.PluginClass===e));-1!==o&&n.splice(o,1),s.info("Enhanced 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 j{static instanceName="";static preload=!1;constructor({jm:e,pluginOpt:t}){this.jm=e,this.options=t||{}}beforePluginRemove(){}beforePluginDestroy(){this.beforePluginRemove()}}class k{static mind=h;static node=l;static direction=t;static event_type=i;static $=r;static plugin=x;static register_plugin=y;static util=a;static enhanced_plugin=j;static enhancedPluginList=[];static usePlugin(e,t={}){if(k.enhancedPluginList.some((t=>t.PluginClass===e)))return s.warn("Plugin "+e.name+" already registered"),k;if(!e.instanceName)throw new Error("Plugin "+e.name+" must define static instanceName");return k.enhancedPluginList.push({PluginClass:e,instanceName:e.instanceName,preload:e.preload||!1,pluginOpt:t,instance:null}),k}static hasEnhancedPlugin(e){return k.enhancedPluginList.some((t=>t.PluginClass===e))}constructor(t){k.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.enhancedPluginManager=new z(this),this.enhancedPluginManager.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.enhancedPluginManager.initNormalPlugins(),b(this,this.options.plugin)}}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.enhancedPluginManager&&this.enhancedPluginManager.removePlugin(e)}getPlugin(e){if(this.enhancedPluginManager)return this.enhancedPluginManager.getPlugin(e)}destroy(){this.enhancedPluginManager&&this.enhancedPluginManager.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 k(e);return i.show(t),i}}export{k as default};
|
|
9
9
|
//# sourceMappingURL=jsmind.js.map
|