mind-elixir 5.8.3-beta.1 → 5.8.3

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.
@@ -1,4 +1,4 @@
1
- const L = `- Root Node
1
+ const b = `- Root Node
2
2
  - Child Node 1
3
3
  - Child Node 1-1 {"color": "#e87a90", "fontSize": "18px"}
4
4
  - Child Node 1-2
@@ -21,158 +21,147 @@ const L = `- Root Node
21
21
  - Child Node 4-3 [^id8]
22
22
  - } Summary of all previous nodes
23
23
  - Child Node 4-4
24
- - > [^id1] <-Link position is not restricted, as long as the id can be found during rendering-> [^id8]
24
+ - > [^id1] <-Link position is not restricted, as long as the id can be found during rendering-> [^id8]
25
+
25
26
  `;
26
- function b(r) {
27
- const e = r.split(`
28
- `).filter((t) => t.trim()), d = {
27
+ function R(r, n = "Root") {
28
+ const s = r.split(`
29
+ `).filter((l) => l.trim());
30
+ if (s.length === 0)
31
+ throw new Error("Failed to parse plaintext: no root node found");
32
+ const e = {
29
33
  arrowLines: [],
30
- summaryLines: [],
31
34
  nodeIdMap: /* @__PURE__ */ new Map()
32
- }, n = y(e, 0, -2, d);
33
- if (!n.node)
35
+ }, d = [], t = [], o = [];
36
+ for (const l of s) {
37
+ const m = I(l), a = C(l);
38
+ for (; t.length > 0 && t[t.length - 1].indent >= m; )
39
+ t.pop();
40
+ const f = t.length > 0 ? t[t.length - 1].node : null, p = f ? f.children ??= [] : o;
41
+ if (a.type === "arrow") {
42
+ e.arrowLines.push({
43
+ content: a.content,
44
+ parentChildren: p
45
+ });
46
+ continue;
47
+ }
48
+ if (a.type === "summary") {
49
+ const g = M(a.content, p, f?.id ?? "");
50
+ g && d.push(g);
51
+ continue;
52
+ }
53
+ const w = c(), u = {
54
+ topic: a.topic,
55
+ id: w
56
+ };
57
+ a.style && (u.style = a.style), a.refId && e.nodeIdMap.set(a.refId, w), p.push(u), t.push({ indent: m, node: u });
58
+ }
59
+ if (o.length === 0)
34
60
  throw new Error("Failed to parse plaintext: no root node found");
35
- const s = d.arrowLines.map(({ content: t }) => N(t, d)).filter((t) => t !== null), o = d.summaryLines.map(({ content: t, parentChildren: i, parentId: l }) => g(t, i, l)).filter((t) => t !== null);
36
- return {
37
- nodeData: n.node,
38
- arrows: s.length > 0 ? s : void 0,
39
- summaries: o.length > 0 ? o : void 0
61
+ let i;
62
+ o.length === 1 ? i = o[0] : i = {
63
+ topic: n,
64
+ id: c(),
65
+ children: o
40
66
  };
41
- }
42
- function y(r, e, d, n) {
43
- if (e >= r.length)
44
- return { node: null, nextIndex: e };
45
- const s = r[e], o = I(s);
46
- if (o <= d)
47
- return { node: null, nextIndex: e };
48
- const t = w(s);
49
- if (t.type === "arrow" || t.type === "summary")
50
- return { node: null, nextIndex: e + 1 };
51
- const i = u(), l = {
52
- topic: t.topic,
53
- id: i
67
+ const h = e.arrowLines.map(({ content: l }) => y(l, e)).filter((l) => l !== null);
68
+ return {
69
+ nodeData: i,
70
+ arrows: h.length > 0 ? h : void 0,
71
+ summaries: d.length > 0 ? d : void 0
54
72
  };
55
- t.style && (l.style = t.style), t.refId && n.nodeIdMap.set(t.refId, i);
56
- const c = [];
57
- let a = e + 1;
58
- for (; a < r.length; ) {
59
- const m = r[a], p = I(m);
60
- if (p <= o)
61
- break;
62
- if (p === o + 2) {
63
- const f = w(m);
64
- if (f.type === "arrow")
65
- n.arrowLines.push({
66
- content: f.content,
67
- parentChildren: c
68
- }), a++;
69
- else if (f.type === "summary")
70
- n.summaryLines.push({
71
- content: f.content,
72
- parentChildren: c,
73
- parentId: i
74
- // Pass parent node ID
75
- }), a++;
76
- else {
77
- const h = y(r, a, o, n);
78
- h.node && c.push(h.node), a = h.nextIndex;
79
- }
80
- } else
81
- a++;
82
- }
83
- return c.length > 0 && (l.children = c), { node: l, nextIndex: a };
84
73
  }
85
74
  function I(r) {
86
- const e = r.match(/^(\s*)/);
87
- return e ? e[1].length : 0;
75
+ const n = r.match(/^(\s*)/);
76
+ return n ? n[1].length : 0;
88
77
  }
89
- function C(r) {
78
+ function N(r) {
90
79
  try {
91
- const e = r.trim().startsWith("{") ? r : `{${r}}`;
92
- return JSON.parse(e);
80
+ const n = r.trim().startsWith("{") ? r : `{${r}}`;
81
+ return JSON.parse(n);
93
82
  } catch {
94
83
  return {};
95
84
  }
96
85
  }
97
- function w(r) {
98
- const d = r.trim().replace(/^-\s*/, "");
99
- if (d.startsWith(">"))
86
+ function C(r) {
87
+ const s = r.trim().replace(/^-\s*/, "");
88
+ if (s.startsWith(">"))
100
89
  return {
101
90
  type: "arrow",
102
91
  topic: "",
103
- content: d.substring(1).trim()
92
+ content: s.substring(1).trim()
104
93
  };
105
- if (d.startsWith("}"))
94
+ if (s.startsWith("}"))
106
95
  return {
107
96
  type: "summary",
108
97
  topic: "",
109
- content: d.substring(1).trim()
98
+ content: s.substring(1).trim()
110
99
  };
111
- let n = d, s, o;
112
- const t = n.match(/\[\^(\w+)\]/);
113
- t && (s = t[1], n = n.replace(t[0], "").trim());
114
- const i = n.match(/\{([^}]+)\}/);
115
- return i && (o = C(i[1]), n = n.replace(i[0], "").trim()), {
100
+ let e = s, d, t;
101
+ const o = e.match(/\[\^(\w+)\]/);
102
+ o && (d = o[1], e = e.replace(o[0], "").trim());
103
+ const i = e.match(/\{([^}]+)\}/);
104
+ return i && (t = N(i[1]), e = e.replace(i[0], "").trim()), {
116
105
  type: "node",
117
- topic: n,
118
- content: n,
119
- refId: s,
120
- style: o
106
+ topic: e,
107
+ content: e,
108
+ refId: d,
109
+ style: t
121
110
  };
122
111
  }
123
- function N(r, e) {
124
- const d = r.match(/\[\^(\w+)\]\s*<-([^-]*)->\s*\[\^(\w+)\]/);
125
- if (d) {
126
- const o = d[1], t = d[2].trim(), i = d[3];
112
+ function y(r, n) {
113
+ const s = r.match(/\[\^(\w+)\]\s*<-([^-]*)->\s*\[\^(\w+)\]/);
114
+ if (s) {
115
+ const t = s[1], o = s[2].trim(), i = s[3];
127
116
  return {
128
- id: u(),
129
- label: t,
130
- from: e.nodeIdMap.get(o) || o,
131
- to: e.nodeIdMap.get(i) || i,
117
+ id: c(),
118
+ label: o,
119
+ from: n.nodeIdMap.get(t) || t,
120
+ to: n.nodeIdMap.get(i) || i,
132
121
  bidirectional: !0
133
122
  };
134
123
  }
135
- const n = r.match(/\[\^(\w+)\]\s*>-([^-]*)->\s*\[\^(\w+)\]/);
136
- if (n) {
137
- const o = n[1], t = n[2].trim(), i = n[3];
124
+ const e = r.match(/\[\^(\w+)\]\s*>-([^-]*)->\s*\[\^(\w+)\]/);
125
+ if (e) {
126
+ const t = e[1], o = e[2].trim(), i = e[3];
138
127
  return {
139
- id: u(),
140
- label: t,
141
- from: e.nodeIdMap.get(o) || o,
142
- to: e.nodeIdMap.get(i) || i
128
+ id: c(),
129
+ label: o,
130
+ from: n.nodeIdMap.get(t) || t,
131
+ to: n.nodeIdMap.get(i) || i
143
132
  };
144
133
  }
145
- const s = r.match(/\[\^(\w+)\]\s*<-([^-]*)-<\s*\[\^(\w+)\]/);
146
- if (s) {
147
- const o = s[3], t = s[2].trim(), i = s[1];
134
+ const d = r.match(/\[\^(\w+)\]\s*<-([^-]*)-<\s*\[\^(\w+)\]/);
135
+ if (d) {
136
+ const t = d[3], o = d[2].trim(), i = d[1];
148
137
  return {
149
- id: u(),
150
- label: t,
151
- from: e.nodeIdMap.get(o) || o,
152
- to: e.nodeIdMap.get(i) || i
138
+ id: c(),
139
+ label: o,
140
+ from: n.nodeIdMap.get(t) || t,
141
+ to: n.nodeIdMap.get(i) || i
153
142
  };
154
143
  }
155
144
  return null;
156
145
  }
157
- function g(r, e, d) {
158
- const n = r.match(/^:(\d+)\s+(.*)/);
159
- let s, o;
160
- if (n ? (s = parseInt(n[1], 10), o = n[2]) : (s = e.length, o = r.trim()), e.length === 0 || s === 0)
146
+ function M(r, n, s) {
147
+ const e = r.match(/^:(\d+)\s+(.*)/);
148
+ let d, t;
149
+ if (e ? (d = parseInt(e[1], 10), t = e[2]) : (d = n.length, t = r.trim()), n.length === 0 || d === 0)
161
150
  return null;
162
- const t = e.slice(-s), i = e.indexOf(t[0]), l = e.indexOf(t[t.length - 1]);
151
+ const o = n.slice(-d), i = n.indexOf(o[0]), h = n.indexOf(o[o.length - 1]);
163
152
  return {
164
- id: u(),
165
- label: o,
166
- parent: d,
153
+ id: c(),
154
+ label: t,
155
+ parent: s,
167
156
  start: i,
168
- end: l
157
+ end: h
169
158
  };
170
159
  }
171
- let M = 0;
172
- function u() {
173
- return `node-${Date.now()}-${M++}`;
160
+ let L = 0;
161
+ function c() {
162
+ return `node-${Date.now()}-${L++}`;
174
163
  }
175
164
  export {
176
- L as plaintextExample,
177
- b as plaintextToMindElixir
165
+ b as plaintextExample,
166
+ R as plaintextToMindElixir
178
167
  };
@@ -1,5 +1,5 @@
1
1
  import type { MindElixirData } from '../types';
2
- export declare const plaintextExample = "- Root Node\n - Child Node 1\n - Child Node 1-1 {\"color\": \"#e87a90\", \"fontSize\": \"18px\"}\n - Child Node 1-2\n - Child Node 1-3\n - }:2 Summary of first two nodes\n - Child Node 2\n - Child Node 2-1 [^id1]\n - Child Node 2-2 [^id2]\n - Child Node 2-3\n - > [^id1] <-Bidirectional Link-> [^id2]\n - Child Node 3\n - Child Node 3-1 [^id3]\n - Child Node 3-2 [^id4]\n - Child Node 3-3 [^id5] {\"fontFamily\": \"Arial\", \"fontWeight\": \"bold\"}\n - > [^id3] >-Unidirectional Link-> [^id4]\n - > [^id3] <-Unidirectional Link-< [^id5]\n - Child Node 4\n - Child Node 4-1 [^id6]\n - Child Node 4-2 [^id7]\n - Child Node 4-3 [^id8]\n - } Summary of all previous nodes\n - Child Node 4-4\n - > [^id1] <-Link position is not restricted, as long as the id can be found during rendering-> [^id8]\n";
2
+ export declare const plaintextExample = "- Root Node\n - Child Node 1\n - Child Node 1-1 {\"color\": \"#e87a90\", \"fontSize\": \"18px\"}\n - Child Node 1-2\n - Child Node 1-3\n - }:2 Summary of first two nodes\n - Child Node 2\n - Child Node 2-1 [^id1]\n - Child Node 2-2 [^id2]\n - Child Node 2-3\n - > [^id1] <-Bidirectional Link-> [^id2]\n - Child Node 3\n - Child Node 3-1 [^id3]\n - Child Node 3-2 [^id4]\n - Child Node 3-3 [^id5] {\"fontFamily\": \"Arial\", \"fontWeight\": \"bold\"}\n - > [^id3] >-Unidirectional Link-> [^id4]\n - > [^id3] <-Unidirectional Link-< [^id5]\n - Child Node 4\n - Child Node 4-1 [^id6]\n - Child Node 4-2 [^id7]\n - Child Node 4-3 [^id8]\n - } Summary of all previous nodes\n - Child Node 4-4\n- > [^id1] <-Link position is not restricted, as long as the id can be found during rendering-> [^id8]\n\n";
3
3
  /**
4
4
  * Convert plaintext format to MindElixirData
5
5
  *
@@ -12,7 +12,12 @@ export declare const plaintextExample = "- Root Node\n - Child Node 1\n - Ch
12
12
  * - Child 2 [^id2]
13
13
  * - > [^id1] <-label-> [^id2]
14
14
  *
15
+ * When the plaintext contains more than one top-level node, a synthetic root
16
+ * node is automatically created to wrap them as first-level children.
17
+ *
15
18
  * @param plaintext - The plaintext string to convert
19
+ * @param rootName - Optional name for the synthetic root node when multiple
20
+ * top-level nodes are detected (defaults to 'Root')
16
21
  * @returns MindElixirData object
17
22
  */
18
- export declare function plaintextToMindElixir(plaintext: string): MindElixirData;
23
+ export declare function plaintextToMindElixir(plaintext: string, rootName?: string): MindElixirData;
package/package.json CHANGED
@@ -1,112 +1,112 @@
1
- {
2
- "name": "mind-elixir",
3
- "version": "5.8.3-beta.1",
4
- "type": "module",
5
- "description": "Mind elixir is a free open source mind map core.",
6
- "keywords": [
7
- "mind-elixir",
8
- "mindmap",
9
- "dom",
10
- "visualization"
11
- ],
12
- "scripts": {
13
- "prepare": "husky install",
14
- "lint": "eslint --cache --max-warnings 0 \"src/**/*.{js,json,ts}\" --fix",
15
- "dev": "vite",
16
- "build": "node build.js && tsc",
17
- "tsc": "tsc",
18
- "preview": "vite preview",
19
- "test": "playwright test",
20
- "test:ui": "playwright test --ui",
21
- "test:clean": "rimraf .nyc_output coverage",
22
- "test:coverage": "pnpm test:clean && pnpm test && pnpm nyc && npx http-server ./coverage",
23
- "nyc": "nyc report --reporter=html",
24
- "doc": "api-extractor run --local --verbose",
25
- "doc:md": "api-documenter markdown --input-folder ./api --output-folder ./md",
26
- "beta": "npm run build && npm publish --tag beta"
27
- },
28
- "exports": {
29
- ".": {
30
- "types": "./dist/types/index.d.ts",
31
- "import": "./dist/MindElixir.js",
32
- "require": "./dist/MindElixir.js"
33
- },
34
- "./lite": {
35
- "import": "./dist/MindElixirLite.iife.js"
36
- },
37
- "./example": {
38
- "types": "./dist/types/exampleData/1.d.ts",
39
- "import": "./dist/example.js",
40
- "require": "./dist/example.js"
41
- },
42
- "./LayoutSsr": {
43
- "types": "./dist/types/utils/LayoutSsr.d.ts",
44
- "import": "./dist/LayoutSsr.js",
45
- "require": "./dist/LayoutSsr.js"
46
- },
47
- "./readme.md": "./readme.md",
48
- "./package.json": "./package.json",
49
- "./style": "./dist/MindElixir.css",
50
- "./style.css": "./dist/MindElixir.css",
51
- "./plaintextConverter": {
52
- "types": "./dist/types/utils/plaintextConverter.d.ts",
53
- "import": "./dist/PlaintextConverter.js"
54
- }
55
- },
56
- "typesVersions": {
57
- "*": {
58
- "example": [
59
- "./dist/types/exampleData/1.d.ts"
60
- ]
61
- }
62
- },
63
- "main": "dist/MindElixir.js",
64
- "types": "dist/types/index.d.ts",
65
- "lint-staged": {
66
- "src/**/*.{ts,js}": [
67
- "eslint --cache --fix"
68
- ],
69
- "src/**/*.{json,less}": [
70
- "prettier --write"
71
- ]
72
- },
73
- "files": [
74
- "package.json",
75
- "dist"
76
- ],
77
- "repository": "github:SSShooter/mind-elixir-core",
78
- "homepage": "https://mind-elixir.com/",
79
- "author": "ssshooter",
80
- "license": "MIT",
81
- "devDependencies": {
82
- "@commitlint/cli": "^20.0.0",
83
- "@commitlint/config-conventional": "^20.0.0",
84
- "@eslint/eslintrc": "^3.3.1",
85
- "@eslint/js": "^9.36.0",
86
- "@microsoft/api-documenter": "^7.26.34",
87
- "@microsoft/api-extractor": "^7.52.13",
88
- "@playwright/test": "^1.58.0",
89
- "@rollup/plugin-strip": "^3.0.4",
90
- "@types/node": "^24.5.2",
91
- "@typescript-eslint/eslint-plugin": "^8.44.1",
92
- "@typescript-eslint/parser": "^8.44.1",
93
- "@viselect/vanilla": "3.9.0",
94
- "@zumer/snapdom": "^1.9.11",
95
- "eslint": "^9.36.0",
96
- "eslint-config-prettier": "^10.1.8",
97
- "eslint-plugin-prettier": "^5.5.4",
98
- "globals": "^16.4.0",
99
- "husky": "^9.1.7",
100
- "katex": "^0.16.22",
101
- "less": "^4.4.1",
102
- "lint-staged": "^16.2.1",
103
- "marked": "^16.3.0",
104
- "nyc": "^17.1.0",
105
- "prettier": "3.6.2",
106
- "rimraf": "^6.0.1",
107
- "simple-markdown-to-html": "^1.0.0",
108
- "typescript": "^5.9.2",
109
- "vite": "^7.1.7",
110
- "vite-plugin-istanbul": "^7.2.0"
111
- }
1
+ {
2
+ "name": "mind-elixir",
3
+ "version": "5.8.3",
4
+ "type": "module",
5
+ "description": "Mind elixir is a free open source mind map core.",
6
+ "keywords": [
7
+ "mind-elixir",
8
+ "mindmap",
9
+ "dom",
10
+ "visualization"
11
+ ],
12
+ "scripts": {
13
+ "prepare": "husky install",
14
+ "lint": "eslint --cache --max-warnings 0 \"src/**/*.{js,json,ts}\" --fix",
15
+ "dev": "vite",
16
+ "build": "node build.js && tsc",
17
+ "tsc": "tsc",
18
+ "preview": "vite preview",
19
+ "test": "playwright test",
20
+ "test:ui": "playwright test --ui",
21
+ "test:clean": "rimraf .nyc_output coverage",
22
+ "test:coverage": "pnpm test:clean && pnpm test && pnpm nyc && npx http-server ./coverage",
23
+ "nyc": "nyc report --reporter=html",
24
+ "doc": "api-extractor run --local --verbose",
25
+ "doc:md": "api-documenter markdown --input-folder ./api --output-folder ./md",
26
+ "beta": "npm run build && npm publish --tag beta"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/types/index.d.ts",
31
+ "import": "./dist/MindElixir.js",
32
+ "require": "./dist/MindElixir.js"
33
+ },
34
+ "./lite": {
35
+ "import": "./dist/MindElixirLite.iife.js"
36
+ },
37
+ "./example": {
38
+ "types": "./dist/types/exampleData/1.d.ts",
39
+ "import": "./dist/example.js",
40
+ "require": "./dist/example.js"
41
+ },
42
+ "./LayoutSsr": {
43
+ "types": "./dist/types/utils/LayoutSsr.d.ts",
44
+ "import": "./dist/LayoutSsr.js",
45
+ "require": "./dist/LayoutSsr.js"
46
+ },
47
+ "./readme.md": "./readme.md",
48
+ "./package.json": "./package.json",
49
+ "./style": "./dist/MindElixir.css",
50
+ "./style.css": "./dist/MindElixir.css",
51
+ "./plaintextConverter": {
52
+ "types": "./dist/types/utils/plaintextConverter.d.ts",
53
+ "import": "./dist/PlaintextConverter.js"
54
+ }
55
+ },
56
+ "typesVersions": {
57
+ "*": {
58
+ "example": [
59
+ "./dist/types/exampleData/1.d.ts"
60
+ ]
61
+ }
62
+ },
63
+ "main": "dist/MindElixir.js",
64
+ "types": "dist/types/index.d.ts",
65
+ "lint-staged": {
66
+ "src/**/*.{ts,js}": [
67
+ "eslint --cache --fix"
68
+ ],
69
+ "src/**/*.{json,less}": [
70
+ "prettier --write"
71
+ ]
72
+ },
73
+ "files": [
74
+ "package.json",
75
+ "dist"
76
+ ],
77
+ "repository": "github:SSShooter/mind-elixir-core",
78
+ "homepage": "https://mind-elixir.com/",
79
+ "author": "ssshooter",
80
+ "license": "MIT",
81
+ "devDependencies": {
82
+ "@commitlint/cli": "^20.0.0",
83
+ "@commitlint/config-conventional": "^20.0.0",
84
+ "@eslint/eslintrc": "^3.3.1",
85
+ "@eslint/js": "^9.36.0",
86
+ "@microsoft/api-documenter": "^7.26.34",
87
+ "@microsoft/api-extractor": "^7.52.13",
88
+ "@playwright/test": "^1.58.0",
89
+ "@rollup/plugin-strip": "^3.0.4",
90
+ "@types/node": "^24.5.2",
91
+ "@typescript-eslint/eslint-plugin": "^8.44.1",
92
+ "@typescript-eslint/parser": "^8.44.1",
93
+ "@viselect/vanilla": "3.9.0",
94
+ "@zumer/snapdom": "^1.9.11",
95
+ "eslint": "^9.36.0",
96
+ "eslint-config-prettier": "^10.1.8",
97
+ "eslint-plugin-prettier": "^5.5.4",
98
+ "globals": "^16.4.0",
99
+ "husky": "^9.1.7",
100
+ "katex": "^0.16.22",
101
+ "less": "^4.4.1",
102
+ "lint-staged": "^16.2.1",
103
+ "marked": "^16.3.0",
104
+ "nyc": "^17.1.0",
105
+ "prettier": "3.6.2",
106
+ "rimraf": "^6.0.1",
107
+ "simple-markdown-to-html": "^1.0.0",
108
+ "typescript": "^5.9.2",
109
+ "vite": "^7.1.7",
110
+ "vite-plugin-istanbul": "^7.2.0"
111
+ }
112
112
  }