kmap-term-tree 0.9.21 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/demo/index.html +124 -10
- package/demo/kmap.html +64 -0
- package/dist/src/KmapTermTree.d.ts +37 -46
- package/dist/src/KmapTermTree.js +641 -216
- package/dist/src/KmapTermTree.js.map +1 -1
- package/dist/src/asciimath-parser.d.ts +17 -0
- package/dist/src/asciimath-parser.js +472 -0
- package/dist/src/asciimath-parser.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/katex-css.d.ts +2 -0
- package/dist/src/katex-css.js +7 -0
- package/dist/src/katex-css.js.map +1 -0
- package/dist/src/model.d.ts +30 -0
- package/dist/src/model.js +26 -0
- package/dist/src/model.js.map +1 -0
- package/dist/src/parser.js.map +1 -1
- package/dist/src/tokenizer.js.map +1 -1
- package/dist/stories/index.stories.d.ts +20 -0
- package/dist/stories/index.stories.js +26 -2
- package/dist/stories/index.stories.js.map +1 -1
- package/dist/test/asciimath-parser.test.d.ts +1 -0
- package/dist/test/asciimath-parser.test.js +45 -0
- package/dist/test/asciimath-parser.test.js.map +1 -0
- package/dist/test/kmap-term-tree.test.js +45 -8
- package/dist/test/kmap-term-tree.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -50
- package/src/KmapTermTree.ts +675 -230
- package/src/asciimath-parser.ts +554 -0
- package/src/index.ts +2 -0
- package/src/katex-css.ts +7 -0
- package/src/model.ts +57 -0
- package/stories/index.stories.ts +35 -2
- package/test/asciimath-parser.test.ts +50 -0
- package/test/kmap-term-tree.test.ts +66 -7
package/demo/index.html
CHANGED
|
@@ -1,27 +1,141 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
|
-
<html lang="
|
|
2
|
+
<html lang="de">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
|
+
<title>kmap-term-tree Demo</title>
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css">
|
|
5
8
|
<style>
|
|
6
9
|
body {
|
|
10
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
11
|
+
background: #f1f5f9;
|
|
12
|
+
color: #1e293b;
|
|
13
|
+
margin: 0;
|
|
14
|
+
padding: 32px 16px;
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
align-items: center;
|
|
18
|
+
}
|
|
19
|
+
.card {
|
|
20
|
+
background: white;
|
|
21
|
+
border-radius: 12px;
|
|
22
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
|
|
23
|
+
max-width: 680px;
|
|
24
|
+
width: 100%;
|
|
25
|
+
padding: 24px;
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
}
|
|
28
|
+
h1 {
|
|
29
|
+
font-size: 1.5rem;
|
|
30
|
+
margin-top: 0;
|
|
31
|
+
margin-bottom: 16px;
|
|
32
|
+
color: #0f172a;
|
|
33
|
+
}
|
|
34
|
+
.input-row {
|
|
35
|
+
display: flex;
|
|
36
|
+
gap: 8px;
|
|
37
|
+
margin-bottom: 16px;
|
|
38
|
+
}
|
|
39
|
+
input[type="text"] {
|
|
40
|
+
flex: 1;
|
|
41
|
+
font-size: 1.1rem;
|
|
42
|
+
padding: 10px 14px;
|
|
43
|
+
border: 1px solid #cbd5e1;
|
|
44
|
+
border-radius: 8px;
|
|
45
|
+
outline: none;
|
|
46
|
+
transition: border-color 0.2s;
|
|
47
|
+
}
|
|
48
|
+
input[type="text"]:focus {
|
|
49
|
+
border-color: #0284c7;
|
|
50
|
+
box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
|
|
51
|
+
}
|
|
52
|
+
.presets {
|
|
53
|
+
display: flex;
|
|
54
|
+
flex-wrap: wrap;
|
|
55
|
+
gap: 6px;
|
|
56
|
+
margin-bottom: 20px;
|
|
57
|
+
}
|
|
58
|
+
button.chip {
|
|
59
|
+
background: #e2e8f0;
|
|
60
|
+
border: none;
|
|
61
|
+
padding: 6px 12px;
|
|
62
|
+
border-radius: 16px;
|
|
63
|
+
font-size: 0.85rem;
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
transition: background 0.15s, color 0.15s;
|
|
66
|
+
}
|
|
67
|
+
button.chip:hover {
|
|
68
|
+
background: #0284c7;
|
|
69
|
+
color: white;
|
|
70
|
+
}
|
|
71
|
+
.controls {
|
|
72
|
+
display: flex;
|
|
73
|
+
gap: 16px;
|
|
74
|
+
margin-bottom: 20px;
|
|
75
|
+
font-size: 0.9rem;
|
|
76
|
+
color: #475569;
|
|
77
|
+
}
|
|
78
|
+
.tree-box {
|
|
7
79
|
background: #fafafa;
|
|
80
|
+
border: 1px solid #e2e8f0;
|
|
81
|
+
border-radius: 8px;
|
|
82
|
+
padding: 20px;
|
|
83
|
+
min-height: 220px;
|
|
84
|
+
display: flex;
|
|
85
|
+
justify-content: center;
|
|
86
|
+
align-items: flex-start;
|
|
8
87
|
}
|
|
9
88
|
</style>
|
|
10
89
|
</head>
|
|
11
90
|
<body>
|
|
12
|
-
<div
|
|
91
|
+
<div class="card">
|
|
92
|
+
<h1>KMap Termbaum (Term Tree)</h1>
|
|
93
|
+
|
|
94
|
+
<div class="input-row">
|
|
95
|
+
<input type="text" id="termInput" value="(2+a)(3-b)" placeholder="AsciiMath Term eingeben, z.B. 2a+3b" />
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<div class="presets">
|
|
99
|
+
<span style="font-size: 0.85rem; color: #64748b; align-self: center; margin-right: 4px;">Beispiele:</span>
|
|
100
|
+
<button class="chip" onclick="setTerm('2a+3b')">2a+3b</button>
|
|
101
|
+
<button class="chip" onclick="setTerm('(2+a)(3-b)')">(2+a)(3-b)</button>
|
|
102
|
+
<button class="chip" onclick="setTerm('(a+b)/(c+d)')">(a+b)/(c+d)</button>
|
|
103
|
+
<button class="chip" onclick="setTerm('2a + sin(3b)')">2a + sin(3b)</button>
|
|
104
|
+
<button class="chip" onclick="setTerm('x^2 - 4')">x^2 - 4</button>
|
|
105
|
+
<button class="chip" onclick="setTerm('sqrt(b^2 - 4ac)')">sqrt(b^2 - 4ac)</button>
|
|
106
|
+
<button class="chip" onclick="setTerm('(-b + sqrt(b^2 - 4ac)) / (2a)')">(-b + sqrt(b^2 - 4ac)) / (2a)</button>
|
|
107
|
+
<button class="chip" onclick="setTerm('5 - -2')">5 - -2</button>
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
<div class="controls">
|
|
111
|
+
<label>
|
|
112
|
+
<input type="checkbox" id="showLabels" onchange="toggleLabels(this.checked)"> Bezeichnungen anzeigen
|
|
113
|
+
</label>
|
|
114
|
+
</div>
|
|
115
|
+
|
|
116
|
+
<div class="tree-box">
|
|
117
|
+
<kmap-term-tree id="termTree" term="(2+a)(3-b)" showDetails></kmap-term-tree>
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
13
120
|
|
|
14
121
|
<script type="module">
|
|
15
|
-
import { html, render } from 'lit-html';
|
|
16
122
|
import '../dist/src/kmap-term-tree.js';
|
|
17
123
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
124
|
+
const input = document.getElementById('termInput');
|
|
125
|
+
const tree = document.getElementById('termTree');
|
|
126
|
+
|
|
127
|
+
input.addEventListener('input', (e) => {
|
|
128
|
+
tree.term = e.target.value;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
window.setTerm = function(val) {
|
|
132
|
+
input.value = val;
|
|
133
|
+
tree.term = val;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
window.toggleLabels = function(checked) {
|
|
137
|
+
tree.showLabels = checked;
|
|
138
|
+
};
|
|
25
139
|
</script>
|
|
26
140
|
</body>
|
|
27
141
|
</html>
|
package/demo/kmap.html
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<style>
|
|
2
|
+
input {
|
|
3
|
+
border-radius: 4px 4px 0 0;
|
|
4
|
+
background-color: inherit;
|
|
5
|
+
border: none;
|
|
6
|
+
border-bottom: 1px solid darkgray;
|
|
7
|
+
padding: 8px;
|
|
8
|
+
transition: background-color .3s ease-in-out, border-bottom-color .3s ease-in-out;
|
|
9
|
+
outline: none;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
input:hover {
|
|
13
|
+
background-color: lightgray;
|
|
14
|
+
border-bottom-color: black;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
input:focus {
|
|
18
|
+
background-color: lightgray;
|
|
19
|
+
border-bottom-color: blue;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
22
|
+
|
|
23
|
+
<h3>Termbaum Generator</h3>
|
|
24
|
+
<p>Hier gibt es ein Tool, das zu einem Term automatisch den Termbaum erzeugt:</p>
|
|
25
|
+
<container>
|
|
26
|
+
<box>
|
|
27
|
+
<div><span style="white-space: nowrap"><b>Term: </b> <input id="term"
|
|
28
|
+
oninput="this.getRootNode().querySelector('#tree').term = event.target.value" /></span>
|
|
29
|
+
</div>
|
|
30
|
+
<p><i>Ändere den Term und schau Dir den Baum dazu an!</i></p>
|
|
31
|
+
<div class="presets">
|
|
32
|
+
<b>Beispiele:</b>
|
|
33
|
+
<button class="chip"
|
|
34
|
+
onclick="this.getRootNode().querySelector('#term').value = '2a+3b'; this.getRootNode().querySelector('#tree').term = '2a+3b'">2a+3b</button>
|
|
35
|
+
<button class="chip"
|
|
36
|
+
onclick="this.getRootNode().querySelector('#term').value = '(2+a)(3-b)'; this.getRootNode().querySelector('#tree').term = '(2+a)(3-b)'">(2+a)(3-b)</button>
|
|
37
|
+
<button class="chip"
|
|
38
|
+
onclick="this.getRootNode().querySelector('#term').value = '(a+b)/(c+d)'; this.getRootNode().querySelector('#tree').term = '(a+b)/(c+d)'">(a+b)/(c+d)</button>
|
|
39
|
+
<button class="chip"
|
|
40
|
+
onclick="this.getRootNode().querySelector('#term').value = '2a + sin(3b)'; this.getRootNode().querySelector('#tree').term = '2a + sin(3b)'">2a
|
|
41
|
+
+ sin(3b)</button>
|
|
42
|
+
<button class="chip"
|
|
43
|
+
onclick="this.getRootNode().querySelector('#term').value = 'x^2 - 4'; this.getRootNode().querySelector('#tree').term = 'x^2 - 4'">x^2
|
|
44
|
+
- 4</button>
|
|
45
|
+
<button class="chip"
|
|
46
|
+
onclick="this.getRootNode().querySelector('#term').value = 'sqrt(b^2 - 4ac)'; this.getRootNode().querySelector('#tree').term = 'sqrt(b^2 - 4ac)'">sqrt(b^2
|
|
47
|
+
- 4ac)</button>
|
|
48
|
+
</div>
|
|
49
|
+
</box>
|
|
50
|
+
<growbox>
|
|
51
|
+
<kmap-term-tree lazy:KmapTermTree:kmap-term-tree id="tree" showDetails></kmap-term-tree>
|
|
52
|
+
</growbox>
|
|
53
|
+
</container>
|
|
54
|
+
|
|
55
|
+
<script>
|
|
56
|
+
const root = document.currentScript ? document.currentScript.getRootNode() : document;
|
|
57
|
+
console.log(root)
|
|
58
|
+
requestAnimationFrame(() => {
|
|
59
|
+
requestAnimationFrame(() => {
|
|
60
|
+
root.querySelector('#term').value = '2a+3b';
|
|
61
|
+
root.querySelector('#tree').term = '2a+3b';
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
</script>
|
|
@@ -1,52 +1,43 @@
|
|
|
1
1
|
import { LitElement, PropertyValues } from 'lit';
|
|
2
|
-
import { TermNode } from "./parser.js";
|
|
3
|
-
import { Token } from "./tokenizer.js";
|
|
4
|
-
interface Connection {
|
|
5
|
-
from: number;
|
|
6
|
-
to: number;
|
|
7
|
-
}
|
|
8
|
-
interface Position {
|
|
9
|
-
x: number;
|
|
10
|
-
y: number;
|
|
11
|
-
width: number;
|
|
12
|
-
height: number;
|
|
13
|
-
}
|
|
14
|
-
interface Edge {
|
|
15
|
-
from: Position;
|
|
16
|
-
to: Position;
|
|
17
|
-
}
|
|
18
2
|
export declare class KmapTermTree extends LitElement {
|
|
19
|
-
|
|
20
|
-
static styles: import("lit").CSSResult;
|
|
21
|
-
private parser;
|
|
3
|
+
static styles: import("lit").CSSResult[];
|
|
22
4
|
term?: string;
|
|
23
5
|
tension: number;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
private
|
|
6
|
+
showLabels: boolean;
|
|
7
|
+
showDetails: boolean;
|
|
8
|
+
private ast?;
|
|
9
|
+
private error?;
|
|
10
|
+
private flatNodes;
|
|
11
|
+
private edges;
|
|
12
|
+
private activeNodeId?;
|
|
13
|
+
private activeSubtreeIds;
|
|
14
|
+
private treeHeight;
|
|
15
|
+
private highlightRect?;
|
|
16
|
+
private formulaElement?;
|
|
17
|
+
private treeCanvasElement?;
|
|
18
|
+
private resizeObserver?;
|
|
19
|
+
private lastObservedWidth;
|
|
20
|
+
private resizeFrameId?;
|
|
21
|
+
private animationTimers;
|
|
22
|
+
connectedCallback(): void;
|
|
23
|
+
disconnectedCallback(): void;
|
|
24
|
+
private onAnimationOrTransitionEnd;
|
|
25
|
+
private triggerLayoutUpdate;
|
|
26
|
+
private watchAncestorAnimations;
|
|
27
|
+
private scheduleAnimationCheck;
|
|
28
|
+
private clearAnimationTimers;
|
|
29
|
+
updateSlotted(event: Event): void;
|
|
30
|
+
protected willUpdate(changedProperties: PropertyValues): void;
|
|
31
|
+
private parseInput;
|
|
32
|
+
protected updated(changedProperties: PropertyValues): Promise<void>;
|
|
33
|
+
private renderKaTeX;
|
|
34
|
+
private recalculateLayout;
|
|
35
|
+
private collectSubtreeIds;
|
|
36
|
+
private onNodeHover;
|
|
37
|
+
private setActiveNode;
|
|
38
|
+
private findNode;
|
|
39
|
+
private getNodeVisualBounds;
|
|
40
|
+
private updateHighlightRect;
|
|
41
|
+
private renderPath;
|
|
39
42
|
render(): import("lit-html").TemplateResult<1>;
|
|
40
|
-
protected updated(_changedProperties: PropertyValues): Promise<void>;
|
|
41
|
-
_connect(connection: Connection): Edge | undefined;
|
|
42
|
-
_findAbsolutePosition(element: HTMLElement): Position;
|
|
43
|
-
private static _prettify;
|
|
44
|
-
}
|
|
45
|
-
export declare class KmapTermTreeEdge extends LitElement {
|
|
46
|
-
static styles: import("lit").CSSResult;
|
|
47
|
-
tension: number;
|
|
48
|
-
edges: Edge[];
|
|
49
|
-
render(): "" | import("lit-html").TemplateResult<2>;
|
|
50
|
-
_path(edge: Edge): string;
|
|
51
43
|
}
|
|
52
|
-
export {};
|