kmap-term-tree 0.9.21 → 0.9.22

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 CHANGED
@@ -1,27 +1,141 @@
1
1
  <!doctype html>
2
- <html lang="en-GB">
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 id="demo"></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 title = 'Hello owc World!';
19
- render(
20
- html`
21
- <kmap-term-tree>2a+2b</kmap-term-tree>
22
- `,
23
- document.querySelector('#demo')
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>
@@ -1,52 +1,35 @@
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
- shadowRoot: ShadowRoot;
20
- static styles: import("lit").CSSResult;
21
- private parser;
3
+ static styles: import("lit").CSSResult[];
22
4
  term?: string;
23
5
  tension: number;
24
- tokens?: Token[];
25
- nodes?: TermNode[];
26
- termNode?: TermNode;
27
- depths?: {
28
- [key: string]: number;
29
- };
30
- maxDepths?: number;
31
- connections?: Connection[];
32
- edgesElement?: KmapTermTreeEdge;
33
- tokensElement?: HTMLDivElement;
34
- updateSlotted({ target }: {
35
- target: any;
36
- }): void;
37
- protected update(_changedProperties: PropertyValues): void;
38
- private calcDepths;
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
+ connectedCallback(): void;
20
+ disconnectedCallback(): void;
21
+ updateSlotted(event: Event): void;
22
+ protected willUpdate(changedProperties: PropertyValues): void;
23
+ private parseInput;
24
+ protected updated(changedProperties: PropertyValues): Promise<void>;
25
+ private renderKaTeX;
26
+ private recalculateLayout;
27
+ private collectSubtreeIds;
28
+ private onNodeHover;
29
+ private setActiveNode;
30
+ private findNode;
31
+ private getNodeVisualBounds;
32
+ private updateHighlightRect;
33
+ private renderPath;
39
34
  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
35
  }
52
- export {};