@barocss/math-editor 0.2.1 → 0.4.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/ADAPTERS.md +25 -14
- package/API-JAVASCRIPT.md +1 -1
- package/API-REACT.md +5 -1
- package/API-SESSION.md +168 -6
- package/API-SOLID.md +1 -1
- package/API-SVELTE.md +1 -1
- package/API-VUE.md +1 -1
- package/API-WEB-COMPONENT.md +1 -1
- package/CHANGELOG.md +45 -0
- package/EMBEDDING.md +4 -0
- package/IMPLEMENTATION.md +27 -2
- package/JSON-MODEL.md +1 -0
- package/LATEX-GUIDE.md +8 -1
- package/LATEX-SCOPE.md +2 -2
- package/LICENSE +1 -3
- package/README.md +145 -37
- package/ROADMAP.md +93 -11
- package/STYLING.md +157 -0
- package/SUPPORT.md +24 -12
- package/VALIDATION.md +113 -4
- package/dist/core.d.ts +5 -1
- package/dist/core.js +5 -1
- package/dist/document-codec.d.ts +0 -1
- package/dist/document-codec.js +0 -1
- package/dist/dom/caret-geometry.d.ts +3 -0
- package/dist/dom/caret-geometry.js +41 -0
- package/dist/dom/elements.d.ts +1 -2
- package/dist/dom/elements.js +2 -3
- package/dist/dom/latex-panel.d.ts +10 -0
- package/dist/dom/latex-panel.js +59 -0
- package/dist/dom/matrix-selection.d.ts +11 -0
- package/dist/dom/matrix-selection.js +30 -0
- package/dist/dom/menu-position.d.ts +14 -2
- package/dist/dom/menu-position.js +84 -15
- package/dist/dom/presentation-controls.d.ts +4 -0
- package/dist/dom/presentation-controls.js +56 -0
- package/dist/dom/quick-panel.d.ts +12 -0
- package/dist/dom/quick-panel.js +102 -0
- package/dist/dom/selection.d.ts +29 -0
- package/dist/dom/selection.js +53 -0
- package/dist/dom/symbol-panel.d.ts +9 -0
- package/dist/dom/symbol-panel.js +146 -0
- package/dist/dom/theme.d.ts +6 -0
- package/dist/dom/theme.js +68 -0
- package/dist/dom/toolbar-catalog.d.ts +10 -0
- package/dist/dom/toolbar-catalog.js +35 -0
- package/dist/dom/toolbar.d.ts +13 -2
- package/dist/dom/toolbar.js +295 -28
- package/dist/dom.d.ts +7 -1
- package/dist/dom.js +510 -128
- package/dist/editor-labels.d.ts +0 -1
- package/dist/editor-labels.js +0 -1
- package/dist/enter-policy.d.ts +0 -1
- package/dist/enter-policy.js +0 -1
- package/dist/fences.d.ts +0 -1
- package/dist/fences.js +0 -1
- package/dist/i18n.d.ts +0 -1
- package/dist/i18n.js +0 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/latex-insertion.d.ts +12 -0
- package/dist/latex-insertion.js +26 -0
- package/dist/latex-paste-panel.d.ts +3 -0
- package/dist/latex-paste-panel.js +18 -0
- package/dist/latex.d.ts +0 -1
- package/dist/latex.js +0 -1
- package/dist/lines.d.ts +0 -1
- package/dist/lines.js +0 -1
- package/dist/locales/en.js +27 -1
- package/dist/locales/en.json +27 -1
- package/dist/locales/ko.js +27 -1
- package/dist/locales/ko.json +27 -1
- package/dist/math-editor-toolbar.d.ts +4 -2
- package/dist/math-editor-toolbar.js +3 -4
- package/dist/math-editor.d.ts +5 -2
- package/dist/math-editor.js +285 -46
- package/dist/matrix-range.d.ts +40 -0
- package/dist/matrix-range.js +242 -0
- package/dist/matrix.d.ts +0 -1
- package/dist/matrix.js +0 -1
- package/dist/model.d.ts +0 -1
- package/dist/model.js +0 -1
- package/dist/outputs.d.ts +0 -1
- package/dist/outputs.js +0 -1
- package/dist/preferences.d.ts +24 -0
- package/dist/preferences.js +66 -0
- package/dist/presentation-controls.d.ts +10 -0
- package/dist/presentation-controls.js +10 -0
- package/dist/presentation.d.ts +13 -0
- package/dist/presentation.js +86 -0
- package/dist/quick-panel.d.ts +2 -0
- package/dist/quick-panel.js +17 -0
- package/dist/range.d.ts +2 -1
- package/dist/range.js +11 -1
- package/dist/react.d.ts +0 -1
- package/dist/react.js +0 -1
- package/dist/session.d.ts +31 -2
- package/dist/session.js +108 -7
- package/dist/solid.d.ts +0 -1
- package/dist/solid.js +0 -1
- package/dist/suggestions.d.ts +4 -1
- package/dist/suggestions.js +100 -12
- package/dist/svelte.d.ts +0 -1
- package/dist/svelte.js +0 -1
- package/dist/symbol-browser.d.ts +0 -1
- package/dist/symbol-browser.js +0 -1
- package/dist/symbols.d.ts +0 -1
- package/dist/symbols.js +0 -1
- package/dist/templates.d.ts +0 -1
- package/dist/templates.js +0 -1
- package/dist/tokens.d.ts +0 -1
- package/dist/tokens.js +0 -1
- package/dist/vertical-navigation.d.ts +15 -0
- package/dist/vertical-navigation.js +145 -0
- package/dist/vue.d.ts +0 -1
- package/dist/vue.js +0 -1
- package/dist/web-component.d.ts +0 -1
- package/dist/web-component.js +0 -1
- package/package.json +1 -1
- package/src/style.css +254 -129
- package/dist/core.d.ts.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/document-codec.d.ts.map +0 -1
- package/dist/document-codec.js.map +0 -1
- package/dist/dom/elements.d.ts.map +0 -1
- package/dist/dom/elements.js.map +0 -1
- package/dist/dom/menu-position.d.ts.map +0 -1
- package/dist/dom/menu-position.js.map +0 -1
- package/dist/dom/toolbar.d.ts.map +0 -1
- package/dist/dom/toolbar.js.map +0 -1
- package/dist/dom.d.ts.map +0 -1
- package/dist/dom.js.map +0 -1
- package/dist/editor-labels.d.ts.map +0 -1
- package/dist/editor-labels.js.map +0 -1
- package/dist/enter-policy.d.ts.map +0 -1
- package/dist/enter-policy.js.map +0 -1
- package/dist/fences.d.ts.map +0 -1
- package/dist/fences.js.map +0 -1
- package/dist/i18n.d.ts.map +0 -1
- package/dist/i18n.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/latex.d.ts.map +0 -1
- package/dist/latex.js.map +0 -1
- package/dist/lines.d.ts.map +0 -1
- package/dist/lines.js.map +0 -1
- package/dist/math-editor-toolbar.d.ts.map +0 -1
- package/dist/math-editor-toolbar.js.map +0 -1
- package/dist/math-editor.d.ts.map +0 -1
- package/dist/math-editor.js.map +0 -1
- package/dist/matrix.d.ts.map +0 -1
- package/dist/matrix.js.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/outputs.d.ts.map +0 -1
- package/dist/outputs.js.map +0 -1
- package/dist/range.d.ts.map +0 -1
- package/dist/range.js.map +0 -1
- package/dist/react.d.ts.map +0 -1
- package/dist/react.js.map +0 -1
- package/dist/session.d.ts.map +0 -1
- package/dist/session.js.map +0 -1
- package/dist/solid.d.ts.map +0 -1
- package/dist/solid.js.map +0 -1
- package/dist/suggestions.d.ts.map +0 -1
- package/dist/suggestions.js.map +0 -1
- package/dist/svelte.d.ts.map +0 -1
- package/dist/svelte.js.map +0 -1
- package/dist/symbol-browser.d.ts.map +0 -1
- package/dist/symbol-browser.js.map +0 -1
- package/dist/symbols.d.ts.map +0 -1
- package/dist/symbols.js.map +0 -1
- package/dist/templates.d.ts.map +0 -1
- package/dist/templates.js.map +0 -1
- package/dist/tokens.d.ts.map +0 -1
- package/dist/tokens.js.map +0 -1
- package/dist/vue.d.ts.map +0 -1
- package/dist/vue.js.map +0 -1
- package/dist/web-component.d.ts.map +0 -1
- package/dist/web-component.js.map +0 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { documentRows, isGrid, isLiteralText, textNodes, } from './model.js';
|
|
2
|
+
/** Candidate slots in semantic order; paired scripts may also move along their shared column. */
|
|
3
|
+
function verticalSlots(node, slot, direction) {
|
|
4
|
+
if (isGrid(node)) {
|
|
5
|
+
const target = slot + direction * node.columns;
|
|
6
|
+
return target >= 0 && target < node.slots.length ? [target] : [];
|
|
7
|
+
}
|
|
8
|
+
switch (node.type) {
|
|
9
|
+
case 'fraction':
|
|
10
|
+
case 'binomial':
|
|
11
|
+
case 'indexedRoot':
|
|
12
|
+
case 'overset':
|
|
13
|
+
case 'overbrace':
|
|
14
|
+
case 'xrightarrow':
|
|
15
|
+
case 'xleftarrow':
|
|
16
|
+
case 'subscript':
|
|
17
|
+
return slot + direction >= 0 && slot + direction < 2 ? [slot + direction] : [];
|
|
18
|
+
case 'underset':
|
|
19
|
+
case 'underbrace':
|
|
20
|
+
return slot - direction >= 0 && slot - direction < 2 ? [slot - direction] : [];
|
|
21
|
+
case 'superscript':
|
|
22
|
+
return slot - direction >= 0 && slot - direction < 2 ? [slot - direction] : [];
|
|
23
|
+
case 'scripts':
|
|
24
|
+
if (slot === 0)
|
|
25
|
+
return [direction === -1 ? 2 : 1];
|
|
26
|
+
if (slot === 1 && direction === -1)
|
|
27
|
+
return [0, 2];
|
|
28
|
+
if (slot === 2 && direction === 1)
|
|
29
|
+
return [0, 1];
|
|
30
|
+
return [];
|
|
31
|
+
case 'limit':
|
|
32
|
+
case 'limsup':
|
|
33
|
+
case 'liminf':
|
|
34
|
+
return slot - direction >= 0 && slot - direction < 2 ? [slot - direction] : [];
|
|
35
|
+
case 'sum':
|
|
36
|
+
case 'product':
|
|
37
|
+
case 'integral':
|
|
38
|
+
case 'doubleIntegral':
|
|
39
|
+
case 'tripleIntegral':
|
|
40
|
+
case 'contourIntegral':
|
|
41
|
+
if (slot === 2)
|
|
42
|
+
return [direction === -1 ? 1 : 0];
|
|
43
|
+
if (slot === 0 && direction === -1)
|
|
44
|
+
return [2, 1];
|
|
45
|
+
if (slot === 1 && direction === 1)
|
|
46
|
+
return [2, 0];
|
|
47
|
+
return [];
|
|
48
|
+
default:
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function caretOffsets(text) {
|
|
53
|
+
const offsets = [0];
|
|
54
|
+
for (const character of text)
|
|
55
|
+
offsets.push(offsets.at(-1) + character.length);
|
|
56
|
+
return offsets;
|
|
57
|
+
}
|
|
58
|
+
function focusRows(state, targets, direction, geometry) {
|
|
59
|
+
const nodes = targets.flatMap((root) => textNodes({ version: 1, root }));
|
|
60
|
+
if (!nodes.length)
|
|
61
|
+
return state;
|
|
62
|
+
const origin = geometry?.({
|
|
63
|
+
id: state.caret.id,
|
|
64
|
+
offset: state.caret.start,
|
|
65
|
+
affinity: state.caret.affinity,
|
|
66
|
+
});
|
|
67
|
+
let nearest;
|
|
68
|
+
let horizontal = Infinity;
|
|
69
|
+
let vertical = Infinity;
|
|
70
|
+
if (origin && Number.isFinite(origin.x) && Number.isFinite(origin.y)) {
|
|
71
|
+
for (const node of nodes) {
|
|
72
|
+
for (const offset of caretOffsets(node.text)) {
|
|
73
|
+
// React renders adjacent lexical tokens with distinct physical caret positions.
|
|
74
|
+
for (const affinity of ['backward', 'forward']) {
|
|
75
|
+
const point = { id: node.id, offset, affinity };
|
|
76
|
+
const position = geometry?.(point);
|
|
77
|
+
if (!position || !Number.isFinite(position.x) || !Number.isFinite(position.y))
|
|
78
|
+
continue;
|
|
79
|
+
const dy = (position.y - origin.y) * direction;
|
|
80
|
+
if (dy <= 0)
|
|
81
|
+
continue;
|
|
82
|
+
const dx = Math.abs(position.x - origin.x);
|
|
83
|
+
if (dx < horizontal - 0.5 || (Math.abs(dx - horizontal) <= 0.5 && dy < vertical)) {
|
|
84
|
+
nearest = point;
|
|
85
|
+
horizontal = dx;
|
|
86
|
+
vertical = dy;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Without layout, preserve the existing offset/clamping behavior in the first target slot.
|
|
93
|
+
const fallback = nodes[0];
|
|
94
|
+
const offset = nearest?.offset ??
|
|
95
|
+
caretOffsets(fallback.text)
|
|
96
|
+
.filter((at) => at <= state.caret.start)
|
|
97
|
+
.at(-1);
|
|
98
|
+
return {
|
|
99
|
+
...state,
|
|
100
|
+
caret: {
|
|
101
|
+
id: nearest?.id ?? fallback.id,
|
|
102
|
+
start: offset,
|
|
103
|
+
end: offset,
|
|
104
|
+
...(nearest ? { affinity: nearest.affinity } : {}),
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Move through the nearest vertical structure, then enclosing grids and equation lines.
|
|
110
|
+
* Geometry is optional so the same operation works in headless sessions and either renderer.
|
|
111
|
+
* Native text selections and literal text retain their own arrow-key behavior.
|
|
112
|
+
*/
|
|
113
|
+
export function moveVertical(state, direction, geometry) {
|
|
114
|
+
if (state.caret.start !== state.caret.end || isLiteralText(state.document, state.caret.id))
|
|
115
|
+
return state;
|
|
116
|
+
const path = [];
|
|
117
|
+
const find = (row) => {
|
|
118
|
+
for (const node of row.children) {
|
|
119
|
+
if (node.type === 'text') {
|
|
120
|
+
if (node.id === state.caret.id)
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
for (let slot = 0; slot < node.slots.length; slot++) {
|
|
125
|
+
path.push({ structure: node, slot });
|
|
126
|
+
if (find(node.slots[slot]))
|
|
127
|
+
return true;
|
|
128
|
+
path.pop();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
};
|
|
134
|
+
const lines = documentRows(state.document);
|
|
135
|
+
const line = lines.findIndex(find);
|
|
136
|
+
if (line < 0)
|
|
137
|
+
return state;
|
|
138
|
+
for (const { structure, slot } of path.reverse()) {
|
|
139
|
+
const targets = verticalSlots(structure, slot, direction).map((index) => structure.slots[index]);
|
|
140
|
+
if (targets.length)
|
|
141
|
+
return focusRows(state, targets, direction, geometry);
|
|
142
|
+
}
|
|
143
|
+
const target = lines[line + direction];
|
|
144
|
+
return target ? focusRows(state, [target], direction, geometry) : state;
|
|
145
|
+
}
|
package/dist/vue.d.ts
CHANGED
|
@@ -2,4 +2,3 @@ import type { ObjectDirective } from 'vue';
|
|
|
2
2
|
import { type DOMMathEditorOptions } from './dom.js';
|
|
3
3
|
/** Use as v-math-editor. session/defaultValue are mount-only. */
|
|
4
4
|
export declare const vMathEditor: ObjectDirective<HTMLElement, DOMMathEditorOptions>;
|
|
5
|
-
//# sourceMappingURL=vue.d.ts.map
|
package/dist/vue.js
CHANGED
package/dist/web-component.d.ts
CHANGED
|
@@ -7,4 +7,3 @@ export interface MathEditorElement extends HTMLElement {
|
|
|
7
7
|
}
|
|
8
8
|
/** Explicit registration; importing this module is safe without a browser. Uses light DOM. */
|
|
9
9
|
export declare function defineMathEditor(tagName?: string): CustomElementConstructor;
|
|
10
|
-
//# sourceMappingURL=web-component.d.ts.map
|
package/dist/web-component.js
CHANGED