@barocss/math-editor 0.4.0 → 0.6.1

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.
Files changed (76) hide show
  1. package/API-SESSION.md +35 -1
  2. package/API-WEB-COMPONENT.md +2 -0
  3. package/CHANGELOG.md +109 -0
  4. package/CLIPBOARD.md +54 -0
  5. package/EDITING-SCENARIOS.md +209 -0
  6. package/GETTING-STARTED.md +54 -0
  7. package/IMPLEMENTATION.md +105 -0
  8. package/KEYBOARD.md +41 -0
  9. package/LATEX-GUIDE.md +52 -2
  10. package/LATEX-MODEL.md +12 -0
  11. package/LATEX-SCOPE.md +10 -1
  12. package/README.md +119 -23
  13. package/RELEASING.md +95 -10
  14. package/RENDERING-TESTS.md +79 -0
  15. package/ROADMAP.md +238 -6
  16. package/STYLING.md +28 -1
  17. package/TEXT-EDITORS.md +157 -0
  18. package/VALIDATION.md +433 -0
  19. package/dist/context-tools.d.ts +21 -0
  20. package/dist/context-tools.js +37 -0
  21. package/dist/dom/caret-geometry.js +1 -1
  22. package/dist/dom/context-keyboard.d.ts +2 -0
  23. package/dist/dom/context-keyboard.js +22 -0
  24. package/dist/dom/help.d.ts +5 -0
  25. package/dist/dom/help.js +104 -0
  26. package/dist/dom/menu-position.d.ts +3 -0
  27. package/dist/dom/menu-position.js +49 -4
  28. package/dist/dom/readable-layout.d.ts +3 -0
  29. package/dist/dom/readable-layout.js +52 -0
  30. package/dist/dom/toolbar-catalog.d.ts +1 -1
  31. package/dist/dom/toolbar.d.ts +2 -0
  32. package/dist/dom/toolbar.js +8 -1
  33. package/dist/dom.d.ts +13 -1
  34. package/dist/dom.js +323 -51
  35. package/dist/enter-policy.js +1 -1
  36. package/dist/latex.js +11 -0
  37. package/dist/lines.d.ts +2 -0
  38. package/dist/lines.js +15 -0
  39. package/dist/locales/en.js +33 -3
  40. package/dist/locales/en.json +33 -3
  41. package/dist/locales/ko.js +33 -3
  42. package/dist/locales/ko.json +33 -3
  43. package/dist/math-editor-toolbar.js +2 -1
  44. package/dist/math-editor.d.ts +4 -1
  45. package/dist/math-editor.js +506 -296
  46. package/dist/math-layout.d.ts +12 -0
  47. package/dist/math-layout.js +59 -0
  48. package/dist/math-spacing.d.ts +13 -0
  49. package/dist/math-spacing.js +87 -0
  50. package/dist/model.d.ts +6 -0
  51. package/dist/model.js +72 -5
  52. package/dist/range.d.ts +10 -2
  53. package/dist/range.js +31 -6
  54. package/dist/root-transform.d.ts +19 -0
  55. package/dist/root-transform.js +69 -0
  56. package/dist/selection-shortcuts.d.ts +13 -0
  57. package/dist/selection-shortcuts.js +35 -0
  58. package/dist/session.d.ts +1 -0
  59. package/dist/session.js +1 -1
  60. package/dist/suggestions.d.ts +9 -0
  61. package/dist/suggestions.js +53 -0
  62. package/dist/symbols.d.ts +1 -1
  63. package/dist/symbols.js +1 -0
  64. package/dist/vertical-navigation.d.ts +5 -0
  65. package/dist/vertical-navigation.js +33 -0
  66. package/dist/web-component.js +9 -1
  67. package/package.json +11 -3
  68. package/src/fonts/KaTeX_Math-Italic.woff2 +0 -0
  69. package/src/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  70. package/src/fonts/README.md +18 -0
  71. package/src/shapes/README.md +21 -0
  72. package/src/shapes/parenthesis-bottom.svg +1 -0
  73. package/src/shapes/parenthesis-top.svg +1 -0
  74. package/src/shapes/parenthesis.svg +1 -0
  75. package/src/shapes/radical.svg +1 -0
  76. package/src/style.css +882 -61
package/ROADMAP.md CHANGED
@@ -1,8 +1,163 @@
1
1
  # Math editor roadmap
2
2
 
3
- This roadmap describes priorities, not release promises. The current package is an independent editing prototype. Production integration requires the reliability work below even if additional notation is implemented first.
3
+ ## Learning and discoverability implemented, 2026-09-13
4
4
 
5
+ - Five interactive site exercises use their own field and validate normalized formula models: correction, fraction wrapping, power, root conversion and LaTeX insertion.
6
+ - Beginner, clipboard and keyboard guides are in the documentation navigation. Outdated claims that norms/integrals/brace annotations were still planned were removed from the LaTeX guide.
7
+ - Localized F1/toolbar help works in React and native fields, including toolbar-free inline. Closing restores native input selection. Custom controls can use `showHelp()`; separate native toolbars connect with `onHelp`.
8
+ - EDIT-035 and the extended 17-target host chain pass; see [validation](VALIDATION.md).
5
9
 
10
+ Possible later convenience work: configurable key bindings with host-conflict rules, and selection-only image export. These are not implemented by the help API. Prioritize demonstrated input problems and platform validation before adding more notation.
11
+
12
+ ## Completed milestone: reliable editing of supported notation — 2026-09-13
13
+
14
+ Complete an uninterrupted formula workflow: **input → select → wrap or transform → navigate → delete → copy/paste → undo/redo → save → reopen and edit**. The JSON tree, exported LaTeX, visible notation and active caret must agree at each relevant checkpoint.
15
+
16
+ This section defines the current work and its completion criteria. The dated records below are historical evidence; their old “next” and “awaiting release” statements do not define current priority or publication status. Dates describe verification runs, not release promises.
17
+
18
+ ### Starting baseline
19
+
20
+ - EDIT-019: 17 standalone/integration targets, 499 continuous-editing checkpoints.
21
+ - EDIT-033: 63 selection-shortcut cases, 510 checkpoints, including 21 comparisons of actual edited output with KaTeX.
22
+ - EDIT-034: React block and native DOM block/inline, 131 held-arrow checkpoints.
23
+ - Rendering: 91 formulas, 330 renderer/mode/size combinations. These are selected geometry checks, not complete pixel or behavior coverage.
24
+ - Core: 1,677 tests in 42 files at the latest recorded run.
25
+
26
+ See [validation](VALIDATION.md) and [editing scenarios](EDITING-SCENARIOS.md). The starting counts above are historical; the closure results below supersede them.
27
+
28
+ ### Execution order and bounded deliverables
29
+
30
+ All six batches are **complete for the environment and checks stated here**. The local gate passed 1,736 core tests, 113 editing cases / 4,311 checkpoints and 330 KaTeX comparisons. Strict type checks, core build and site/docs build passed. [Validation](VALIDATION.md) contains the per-suite evidence. The CI workflow is configured and its entry point passed locally; remote execution and publishing remain separate actions.
31
+
32
+ | Order | Batch | Scope | Completion check |
33
+ | --- | --- | --- | --- |
34
+ | 1 | Structure and grid deletion | EDIT-006/015: Backspace and Delete inside/outside empty and populated structures; selected ranges; matrix, cases and alignment rows/cells | Define the expected action before implementation. Preserve all content not explicitly deleted. One Undo restores the exact tree and a valid caret. Follow deletion with typing and Redo. |
35
+ | 2 | Range interchange | EDIT-007/015: text plus nested structures; copy, cut and paste within/across instances; matrix rectangles; supported LaTeX fallback; malformed and mismatched payloads | Preserve selected structure and unselected content. Cut is undoable. Rejected paste changes nothing. Distinguish controlled clipboard-event checks from actual system clipboard verification. |
36
+ | 3 | Lines and keyboard navigation | EDIT-012/013/016/034: line split/merge; cases/alignment row edits; matrix traversal; repeat keys; vertical movement; suggestion navigation | Preserve the preferred horizontal caret position across repeated vertical movement where geometry permits. Menus own their documented keys. Inline Enter follows the host contract and creates no formula line. |
37
+ | 4 | Selection and transformations | EDIT-002–005/021–033: direct wrapping, suggestion-based conversion, nearest nested target, Escape and continued input without a toolbar | Current supported transformations remain discoverable by keyboard. They preserve operands, use the intended slot and support one-step Undo. Do not add new notation as a prerequisite. |
38
+ | 5 | Host lifecycle | EDIT-008–011/018/019: extend current host chains with the completed operations; Apply/Cancel; storage reload; read-only; multiple instances; teardown | Draft operations do not modify stored host content. Apply creates one host history event where supported. Reopened formulas remain editable. Menus and listeners do not survive instance destruction. |
39
+ | 6 | Consolidated verification and release checks | Run the required suites on the same candidate source; update scenario status, support limits, docs and release notes; connect the required checks to CI | Checks fail on regressions or missing required results, retain reports/screenshots and work without a developer-specific absolute CLI path. No required in-scope scenario remains unrun or failed. Publishing is a separate action. |
40
+
41
+ For each batch: reproduce → specify the expected tree/caret → add a failing case → fix the shared behavior → compare editor/KaTeX → rerun affected scenarios → record evidence. Rerun the complete geometry set when shared layout rules change. Keep every discovered regression as a stable scenario.
42
+
43
+ ### Structure and visual comparison contract
44
+
45
+ 1. Cover every currently supported structure kind in the catalog with a populated edit and an empty-slot/boundary case where applicable. Shared structural families may share fixtures, but each catalog kind must map to coverage or an explicit non-applicable reason.
46
+ 2. Keep the existing catalog-driven parser/exporter combination checks. Add browser combinations by behavior: structure in a fraction slot, a script, a radical/fence, an operator bound, or a grid cell. Include repeated siblings, compound operands, mixed text/math and at least three nested structural levels. This is a finite representative matrix, not every possible expression.
47
+ 3. For changed flows, compare **the LaTeX produced by actual editing**, not only a separately imported formula. Verify the expected JSON structure independently; a visually correct preview cannot excuse lost or misplaced model content.
48
+ 4. Compare idle and focused states at 22px and 36px, with matching KaTeX display mode. Check baseline/relative positions, script and index size, fences/radicals, operator bounds, horizontal spacing, clipping and input-induced movement.
49
+ 5. Retain the existing metric thresholds: font difference ≤ 0.1px, relative vertical-center difference ≤ 0.25em, active-position change ≤ 0.2em, and horizontal difference ≤ 0.25em where comparable anchors are defined. These proxies are not complete glyph-ink measurements. Add a check when a visible defect is outside the measured anchors; do not relax thresholds to hide it.
50
+ 6. Review screenshots of changed notation. Reject obscured symbols, overlapping slots, clipped content or a position that suggests the wrong mathematical attachment, even if a measured probe passes. Record intentional differences for empty slots, focus backgrounds and caret hit areas. Exact pixel equality with KaTeX is not a milestone requirement.
51
+
52
+ Detailed comparison tables and screenshots stay in the source-only rendering ledger. Public guides describe supported behavior and limitations.
53
+
54
+ ### Environments included in this milestone
55
+
56
+ - Automated editing and visual acceptance: desktop Chromium on macOS, with the recorded browser and font versions.
57
+ - Core surfaces: React block and native DOM block/inline. Smoke-check Pure JS, Web Component, Vue, Svelte and Solid wrappers for focus, option updates, independent instances and teardown; shared DOM passes alone do not certify wrapper lifecycle.
58
+ - Existing host configurations: Tiptap, ProseMirror, Lexical, Quill, Slate, TinyMCE inline host and CKEditor ClassicEditor in their current block/inline math demos; Editor.js and Gutenberg standalone in block mode. Run the relevant chain in each host that supports the operation.
59
+ - Editor.js host history is not configured in the current demo. Formula history is required; do not count host Undo as passed. Gutenberg RichText inline math and additional host configurations are outside this scope.
60
+ - English/Korean labels and custom-locale fallback must remain valid. Include a narrow desktop container to check clipping and suggestion placement, without claiming touch support.
61
+
62
+ ### Closure rule
63
+
64
+ Close this milestone only when all six batches have executable coverage, the required checks pass on the candidate source, and no known in-scope content-loss, blocked-input, incorrect-structure or visual-attachment defect remains. Each result must identify its scenario, renderer/mode, source fingerprint and observed limitation. A test count alone is not completion evidence.
65
+
66
+ If a new defect is within this contract, fix and rerun before closure. If it requires a new notation family, platform or product, record it in the later queue instead of silently expanding the milestone. “Complete” refers to this bounded milestone, not all TeX or every device.
67
+
68
+ ### Subsequent milestones
69
+
70
+ | Next stage | Work deferred from the current milestone |
71
+ | --- | --- |
72
+ | Platform validation | Safari, Firefox, Windows Chromium, real Korean IME, actual OS/application clipboard exchange, touch/mobile input and screen-reader verification. The earlier deferral of real OS input testing remains explicit; synthetic checks do not replace it. |
73
+ | Library operating contract | Versioned JSON migration/recovery, measured document-size/depth and performance budgets, supported host-version policy and broader installed-host configurations such as TinyMCE iframe and WordPress admin. |
74
+ | Demand-led expansion | Additional LaTeX environments/style declarations, reviewed language packs, new editor integrations and optional radial suggestions. Require a concrete input/editing use case first. |
75
+
76
+ Full TeX documents, arbitrary macros/packages, symbolic computation, collaboration and a paper-writing service are separate products or projects. They are not required to finish this editor milestone.
77
+
78
+ ## Historical implementation records
79
+
80
+ The following entries preserve past decisions and dated evidence. Use the completed milestone and subsequent milestones above for current scope.
81
+
82
+ ## Direct selection shortcuts — workspace, 2026-09-13
83
+
84
+ Implemented immediate range wrapping for `(`, `[`, `{`, `|`, `/`, `^` and `_` in both renderers. Selection content, script/fraction caret placement and one-step Undo use the existing model operation. Other characters still replace selections. Unselected input and literal text retain their current behavior.
85
+
86
+ Validation: EDIT-033 passes 63 cases / 510 checkpoints; geometry passes 91 formulas / 330 combinations after correcting fraction sizing and spacing. EDIT-019 still passes 17 targets / 499 checkpoints.
87
+
88
+ EDIT-033 adds a repeatable browser suite for keyboard, native and dragged selections. VIS-080–093 add block/inline KaTeX position comparisons for the resulting formulas. Continue running editing and rendering checks together when shortcuts or notation change. Ambiguous keys such as `<` (relation, angle bracket, arrow prefix) and word commands such as `sqrt` remain suggestions.
89
+
90
+ ## Current focus: continuous editing — workspace, 2026-09-10
91
+
92
+ The rendering pass is now the maintenance baseline. Further contour refinement
93
+ is deferred; keep existing checks when notation or layout changes.
94
+
95
+ EDIT-019 now runs through keyboard input, range wrapping, radical conversion,
96
+ matrix input, five-step Undo/Redo, empty-root deletion and restoration, then a
97
+ second typing/history chain without resetting the editor. React standalone block
98
+ plus Quill/Tiptap/ProseMirror/Lexical/TinyMCE/CKEditor/Slate in-place block/inline and
99
+ Editor.js/Gutenberg block pass (17 targets, 499 checkpoints). Host checks verify unchanged draft data,
100
+ Save, reload/Restore, re-edit and Cancel. One-step host Undo/Redo passes where
101
+ configured; the Editor.js demo has no host history integration. Inline also
102
+ checks Enter commit without new paragraphs, right-boundary exit and prose
103
+ continuation at the correct host position.
104
+
105
+ Run `pnpm --filter @barocss/math-editor test:editing`. Timestamped reports include
106
+ checkpoints, browser scope, fixture copy and source fingerprints. The Tiptap sample now separates document Restore from subsequent typing in host history;
107
+ TinyMCE now keeps empty formulas visible with a localized placeholder. Its
108
+ block/inline checks use an inline TinyMCE host; classic iframe mode is separate.
109
+ All nine integration demos now pass this chain. Gutenberg uses the standalone
110
+ provider demo; WordPress admin and other host configurations remain separate.
111
+ Next: range clipboard and populated/grid deletion sequences. Real OS IME
112
+ and clipboard remain deferred; this is not a release-wide certification.
113
+
114
+
115
+ ## Named-function and fraction spacing — workspace, 2026-09-10
116
+
117
+ Named functions and fractions now share horizontal spacing with adjacent text.
118
+ Repeated functions, parentheses after functions, products of functions and
119
+ repeated fractions have paired editor/KaTeX comparisons. Named-function thin
120
+ spacing remains in first and nested exponents. Fixed function glyph padding and
121
+ fraction outer margins no longer accumulate across these expressions.
122
+
123
+ Next: the remaining wrapper atom classes, longer mixed expressions, explicit
124
+ spacing commands, and full painted-bound comparisons. Passing selected anchors
125
+ does not imply whole-expression pixel equality.
126
+
127
+
128
+ ## Contextual operator layout — workspace, 2026-09-10
129
+
130
+ The shared model-to-presentation pass now distinguishes display, text, script and
131
+ scriptscript operator contexts. React and DOM use it for small glyphs, nested
132
+ bound sizes and automatic side limits. Explicit limits remain supported.
133
+
134
+ New comparisons cover numerator/denominator operators, one/two levels of
135
+ superscripts, an operator inside another bound, inline/text fractions and an
136
+ explicit stacked inline integral. Full ink alignment, all multi-operator mixtures
137
+ and narrow-host/cross-browser checks remain separate work.
138
+
139
+ ## Radical and parenthesis outlines — workspace, 2026-09-10
140
+
141
+ Root strokes and short/tall parenthesis contours now use KaTeX-derived SVG masks.
142
+ Tall parentheses retain bounded end caps and extend the straight middle. The
143
+ package includes these assets with their provenance and existing KaTeX MIT notice.
144
+ This removes the old radical polygon without adding a KaTeX runtime dependency.
145
+
146
+ Full KaTeX size-variant selection, vertical brace silhouettes, operators inside
147
+ scripts and cross-browser geometry remain separate work. The renderer continues
148
+ to reserve its existing editing boxes and caret hit areas.
149
+
150
+ ## LaTeX compatibility and nested-root layout — workspace, 2026-09-10
151
+
152
+ - Fixed math-mode literal caret/tilde export while retaining text-run JSON semantics.
153
+ - Protected complex optional root indices during export; all 55 structure kinds
154
+ now have KaTeX render and JSON round-trip regression checks in that slot.
155
+ - Added clearance between nested radical rules and a browser gap measurement.
156
+ - Still open: radical hook outlines, fence ink geometry, operators inside scripts,
157
+ explicit style combinations, broader interaction sequences and other browsers.
158
+
159
+ These are workspace changes. Browser evidence remains in the source-only rendering
160
+ ledger; a metric PASS does not mean complete visual parity or release certification.
6
161
 
7
162
  ## Editing utilities — workspace, 2026-09-09
8
163
 
@@ -27,11 +182,11 @@ base-size and compact-spacing controls. See [Styling & themes](STYLING.md).
27
182
 
28
183
  ## Selection-to-caret keyboard behavior — workspace, 2026-09-09
29
184
 
30
- Both renderers now restore the caret when a plain arrow follows a Shift+arrow or
31
- pointer model selection. Left/Up uses the ordered start; Right/Down uses the end.
32
- Typing continues at that position without replacing the former range. Wrapping
33
- suggestions remain selectable with Alt+Up/Down or the pointer. The operation does
34
- not change the formula or create Undo entries.
185
+ A visible wrapping menu owns Up/Down in both renderers. The selected formula
186
+ stays selected while the highlighted suggestion changes; Enter applies it.
187
+ Left/Right returns to the ordered start/end of the selection. Shift+arrows
188
+ continues to adjust the range. Alt+Up/Down remains supported. When the wrapping
189
+ menu is closed, plain arrows restore the caret without changing the formula.
35
190
 
36
191
  ## Matrix rectangles and transpose — workspace, 2026-09-09
37
192
 
@@ -277,3 +432,80 @@ core and all nine plugins now use MIT, with a LICENSE file in each package.
277
432
  Plugin publication remains pending. See the [integration roadmap](../math-editor-integrations/ROADMAP.md),
278
433
  [validation record](../math-editor-integrations/VALIDATION.md), and
279
434
  [release guide](../math-editor-integrations/docs/RELEASING.md).
435
+
436
+ ## Radical conversions — workspace, 2026-09-09
437
+
438
+ Implemented contextual square-root/indexed-root conversion suggestions in React
439
+ and native DOM. The radicand tree and IDs are retained; conversion adds a selected
440
+ index `2`. Square-root conversion accepts only an empty index or `2`. Changes
441
+ participate in normal Undo/Redo and use English/Korean locale messages. Other
442
+ structure conversions are not included in this step.
443
+
444
+ ## Editing scenario register — workspace, 2026-09-09
445
+
446
+ [Editing scenarios](EDITING-SCENARIOS.md) defines EDIT-001 through EDIT-020,
447
+ expected behavior, test mappings, environment scope and a run-record template.
448
+ It distinguishes historical evidence from current verification. The EDIT-019
449
+ sustained chain and source-fingerprinted runner were added on 2026-09-10. Other
450
+ scenario assertions and CI/release enforcement remain separate work.
451
+
452
+ ## Rendering regression baseline — workspace, 2026-09-09
453
+
454
+ [Rendering checks](RENDERING-TESTS.md) now defines executable size and position
455
+ comparisons for fractional exponents/subscripts and a tall indexed-root base.
456
+ React and native DOM share compact script-fraction rules. Empty non-grid slots
457
+ now remove their wrapper with Delete or Backspace and retain other content.
458
+ Next: paired scripts, multi-line collision, explicit style overrides and other
459
+ notation families. Current checks do not implement an automated CI release gate.
460
+
461
+ ## Contextual structure footer — workspace, 2026-09-09
462
+
463
+ Added query-independent radical actions, index editing, disabled explanations,
464
+ F6/Escape access and embedding opt-out. EDIT-021 through EDIT-028 extend the
465
+ scenario register with discovery, target, focus, locale, composition guard and
466
+ lifecycle cases. Future work: context actions for additional structure families,
467
+ explicit Tab-order assertions and broader framework/device coverage.
468
+
469
+ ## Inline-first fence transformations — workspace, 2026-09-09
470
+
471
+ Implemented eight fence presentations through the existing suggestion list,
472
+ Alt+Down discovery/reopening, nearest-wrapper targeting, retained caret/content
473
+ and one-step conversion history. Optional footer controls support F6 and horizontal
474
+ navigation. EDIT-029 through EDIT-032 add keyboard, cancellation, iframe, locale
475
+ and no-toolbar coverage. Additional transformation families and the proposed
476
+ optional radial menu remain future work; the list layout remains the default.
477
+
478
+ ## Horizontal text spacing — workspace, 2026-09-10
479
+
480
+ Replaced fixed inter-token gaps with shared binary/relation/punctuation spacing,
481
+ including unary-sign context and compact script rows. Removed per-token padding
482
+ from mathematical glyph measurement. Empty expression inputs remain available;
483
+ inactive structural caret boundaries are narrower. VIS-066 through VIS-073 add
484
+ addition, equality, unary signs, parentheses, named functions, fractions,
485
+ punctuation and script comparisons at 22 px and 36 px in React and native DOM.
486
+
487
+ Next: longer expressions, complete atom classification across structure wrappers,
488
+ named-function boundaries, explicit spacing commands and browser font differences.
489
+ The source-only rendering ledger records measured limits and remaining work.
490
+
491
+ ## Text editor integrations — 2026-09-13
492
+
493
+ - Implemented: optional direct LaTeX completion and caret preview for the three browser adapters; keyboard template navigation and source-preserving command insertion.
494
+ - Implemented: grouped Examples navigation and per-example installation, usage and guide links.
495
+ - Remaining: VS Code native source completion, wider platform/assistive-technology validation, and custom TeX dialect completion.
496
+
497
+ - Implemented: shared LaTeX source-range discovery and draft popup; separate CodeMirror 6, CodeMirror 5, and Monaco packages.
498
+ - Implemented: VS Code Edit Formula and Insert Formula commands, Webview UI, and VSIX build. VS Code 1.103.1 desktop command and Webview round-trip checks passed.
499
+ - Added: workspace-source examples, English/Korean popup messages, source conflict protection, unchanged-source preservation, and one-step host undo.
500
+ - Next: host syntax-tree resolvers for additional Markdown/TeX dialects, rebasing non-overlapping source edits, multi-caret policy, and broader VS Code platform QA.
501
+ - Separate project: typed WGSL/GLSL expression editing. No shader parser is used by these adapters.
502
+ - Publication: the four browser text packages are in the math release allowlist. The VS Code extension remains a separate release.
503
+
504
+ ## Editing readability and navigation — 2026-09-14
505
+
506
+ - Added a configurable 14px editing minimum and extra line space for raised scripts.
507
+ - Corrected fraction descendant sizes, nested fence alignment and radical geometry in scripts.
508
+ - Added lexical/structural movement and selection: Ctrl+arrows, or Option+arrows on macOS, with Shift to select.
509
+ - Added 100/125/150% visual text-popup zoom; default 125%, with a saved browser preference.
510
+ - Documented a 26px editing base and optional 16px minimum for complex formulas. Output size stays separate.
511
+ - Remaining: exact glyph contours/spacing, the full updated rendering audit, cross-editor suggestion dismissal, and wider browser/platform checks. Focused browser checks are recorded in the source rendering ledger; historical all-suite PASS results are not evidence for the new size policy.
package/STYLING.md CHANGED
@@ -49,11 +49,27 @@ Try the website's **Theme**, **Math size** and **Compact spacing** controls in t
49
49
 
50
50
  ## Public CSS variables
51
51
 
52
+ For complex fractions, start with a **26px editing base** instead of enlarging
53
+ only the numerator or denominator. Use a **16px minimum** if nested text remains
54
+ hard to read. Keep the KaTeX preview/export size separate from editing size:
55
+
56
+ ```css
57
+ .product-math {
58
+ --me-font-size: 26px;
59
+ --me-min-font-size: 16px;
60
+ }
61
+ ```
62
+
63
+ 복잡한 분수는 편집 기본 크기를 **26px**, 중첩 글자의 최소 크기를 **16px**로
64
+ 설정해 보세요. KaTeX 미리보기와 이미지 출력 크기는 앱에서 별도로 설정합니다.
65
+ 수식이 커지면 줄 높이도 늘어날 수 있도록 호스트 영역의 고정 높이를 피하세요.
66
+
52
67
  Unset variables preserve the existing default appearance. Some controls intentionally have slightly different default shades/radii; a supplied token unifies them. Set lengths such as the base font size in `px` or `rem` when the editor and its portal have different parents.
53
68
 
54
69
  | Variable | Controls | Default behavior |
55
70
  | --- | --- | --- |
56
71
  | `--me-font-size` | Base formula text and relative script sizes | `22px` in standalone editors |
72
+ | `--me-min-font-size` | Minimum editing glyph/input size, including nested fractions and scripts | `14px`; `0px` disables the floor |
57
73
  | `--me-ui-font-family` | Toolbars, menus and helper text | `system-ui, sans-serif` |
58
74
  | `--me-text` | UI text and neutral math glyphs | Dark green/gray |
59
75
  | `--me-muted` | Help text, line numbers, menu details | Muted gray/green |
@@ -85,7 +101,18 @@ Unset variables preserve the existing default appearance. Some controls intentio
85
101
  | `--me-menu-shadow` | Floating menu shadow | Soft dark shadow |
86
102
  | `--me-menu-z-index` | Suggestion menu stacking level | `1000` |
87
103
 
88
- Inline mode retains its content-driven minimum height. Explicit LaTeX sizing commands and specialty mathematical fonts retain their own metrics; the base-size token is not an image scaling API. Formula export/KaTeX rendering is owned by the consumer and does not inherit semantic editing colors automatically.
104
+ Inline mode retains its content-driven minimum height. The editor reserves extra line space when scripts extend beyond the row. The host must allow this height to grow instead of clipping the editor into a fixed-height line.
105
+
106
+ Nested math uses TeX size ratios with a readable `14px` floor. The same floor applies to glyphs, measuring spans and focused inputs, so fractions and fences grow with their contents. Explicit small LaTeX styles are also subject to this editing floor. To use a larger minimum:
107
+
108
+ ```css
109
+ .product-math {
110
+ --me-font-size: 22px;
111
+ --me-min-font-size: 16px;
112
+ }
113
+ ```
114
+
115
+ Set `--me-min-font-size: 0px` for unmodified TeX size ratios, for example in a typography comparison. Use a nonnegative length in `px` or `rem`. The floor changes editing layout only; it does not add sizing commands to LaTeX, change history, or enlarge suggestion menu labels. Formula export/KaTeX rendering is owned by the consumer and does not inherit this floor or semantic editing colors automatically. The base-size token is not an image scaling API.
89
116
 
90
117
  ## Dark and monochrome themes
91
118
 
@@ -0,0 +1,157 @@
1
+ # LaTeX editing in text editors
2
+
3
+ The browser text-editor adapters support a visual popup and optional LaTeX source completion with a formula preview. They do not replace the host's text model. WGSL and GLSL expression editing is a separate project.
4
+
5
+ ## Available implementations
6
+
7
+ | Package or extension | Editing surface | Lifecycle |
8
+ | --- | --- | --- |
9
+ | `@barocss/math-editor-text` | Shared range scanner and DOM popup | Explicit controller cleanup |
10
+ | `@barocss/math-editor-codemirror6` | Caret popup, Alt+Enter | CodeMirror 6 view plugin |
11
+ | `@barocss/math-editor-codemirror5` | Caret popup, Alt+Enter | Attachment with `destroy()` |
12
+ | `@barocss/math-editor-monaco` | Caret popup, Alt+Enter | Attachment and editor disposal |
13
+ | Barocss Math Editor for VS Code | Webview beside the document | VS Code extension lifecycle |
14
+
15
+ [Open the browser examples](../text-editors.html). The three examples import individual workspace packages directly from source. Published package exports target their own build artifacts. The new packages start at 0.1.0; npm and Marketplace publication are separate steps.
16
+
17
+ ## CodeMirror 6
18
+
19
+ ```sh
20
+ npm install @barocss/math-editor @barocss/math-editor-text @barocss/math-editor-codemirror6 @codemirror/state @codemirror/view @codemirror/commands
21
+ ```
22
+
23
+ ```ts
24
+ import { mathEditor } from '@barocss/math-editor-codemirror6';
25
+ import '@barocss/math-editor/style.css';
26
+ import '@barocss/math-editor-text/style.css';
27
+
28
+ // Add to your EditorState extensions alongside the host's history extension.
29
+ const extension = mathEditor({
30
+ locale: 'en',
31
+ syntax: 'markdown',
32
+ onError: message => { statusElement.textContent = message; },
33
+ });
34
+ ```
35
+
36
+ For CodeMirror 5 and Monaco, import `attachMathEditor` from the corresponding package and pass the host editor instance. The return value has `open()` and `destroy()`. CodeMirror 5 also has `refresh()`; call it after changing host options such as read-only mode. CodeMirror 6 exports the `openMathEditor(view)` command for custom controls. CodeMirror 5 uses its own package because its API differs from CodeMirror 6. Monaco applications retain their normal worker configuration.
37
+
38
+
39
+ ## Direct LaTeX input
40
+
41
+ [Try source completion](../text-editors.html?mode=source). Choose **LaTeX completion** on the example page. The visual popup remains the default for existing integrations.
42
+
43
+ Pass `sourceEditing` to the CodeMirror 5, CodeMirror 6, or Monaco adapter. An empty object enables completion without a preview. To show a preview, install KaTeX separately and supply a renderer:
44
+
45
+ ```sh
46
+ npm install katex
47
+ ```
48
+
49
+ ```ts
50
+ import katex from 'katex';
51
+ import 'katex/dist/katex.min.css';
52
+ import '@barocss/math-editor/style.css';
53
+ import '@barocss/math-editor-text/style.css';
54
+
55
+ const options = {
56
+ locale: 'en',
57
+ sourceEditing: {
58
+ renderPreview(latex, element, displayMode) {
59
+ katex.render(latex, element, {
60
+ displayMode,
61
+ throwOnError: true,
62
+ trust: false,
63
+ maxExpand: 1000,
64
+ });
65
+ },
66
+ },
67
+ };
68
+ // CodeMirror 6: mathEditor(options), included in EditorState extensions.
69
+ // CodeMirror 5 / Monaco: attachMathEditor(editor, options).
70
+ ```
71
+
72
+ | Action | Result |
73
+ | --- | --- |
74
+ | Type `\frac`, `\sqrt`, or another command inside a detected math range | Show localized catalog suggestions below the caret |
75
+ | Place the caret after `a`, `4ab`, or `x_i^2` | Offer fractions, roots, scripts and fences that retain the operand |
76
+ | Select a complete expression inside one math range | Preview the selection and offer source-preserving wrappers after drag release |
77
+ | Ctrl+Space inside a math range | Open the catalog without typing a command |
78
+ | Up / Down with suggestions open | Choose a candidate without moving the source caret |
79
+ | Enter or Tab after choosing a suggestion | Apply the selected command or operand wrapper and enter its next argument |
80
+ | Tab / Shift+Tab after insertion | Move through template arguments; this takes priority over operand wrapping suggestions |
81
+ | Tab after the last argument | Exit the inserted template |
82
+ | Escape | Dismiss source tools without changing source or collapsing its selection |
83
+ | Alt+Enter | Open the existing visual editor |
84
+
85
+ The preview sits above the caret when space permits. Incomplete syntax displays a short status instead of changing the source or blocking typing. The renderer is optional and is owned by the host. It must render only trusted UI; when using KaTeX, keep `trust: false` for document content.
86
+
87
+ Completion uses the math-editor catalog and serializer to create an **isolated insertion**. It does not parse or normalize the surrounding formula. For example, `\rightarrow` suggestions may insert the catalog's equivalent `\to ` spelling. A trailing space terminates a control word so it cannot absorb the following variable. Operand wrapping fills a catalog template with the original variable/number run and simple scripts, without reserializing the source. For example, `4ab` becomes `\frac{4ab}{}` and the caret enters the denominator. Existing-structure transformations remain visual-editor actions.
88
+
89
+ Automatic operand and selection menus do not preselect an action. Until you choose an item with Up/Down, Enter and Tab retain their normal host behavior. Typing a command or explicitly opening Ctrl+Space still preselects a completion.
90
+
91
+ Selection mode shows the selected source and keyboard hints in a fixed menu header. Up/Down keeps the native selection; Enter/Tab or a click wraps exactly that range. Shift+Arrow continues to adjust the selection. The shared core parser validates selected expressions without serializing them. Split command names, unbalanced groups, literal text, cross-formula selections and ordinary document text do not get math wrapping suggestions.
92
+
93
+ A position-aware lexical scan distinguishes command names, operand spans, comments, and braced text/environment names. Completing `\fr|ac{a}{b}` replaces the complete command name while preserving the arguments. Text and comments do not offer math wrappers. This is not a full TeX semantic parser: custom macros and arbitrary compound-expression boundaries are not inferred. Source mode accepts whitespace beside paired delimiters, including the trailing space inserted after a symbol command. The default visual-import scanner remains strict.
94
+
95
+ The shared dropdown keeps focus in the host and applies changes through the host edit/history API. It handles navigation keys only while its suggestions or template navigation are active. IME composition suspends suggestions. Read-only state, selection outside the math range, and host disposal remove the tools. Multi-caret completion, arbitrary TeX macro completion, and full snippet-language syntax are not supported. Argument navigation ends after leaving the template, undoing its insertion, or replacing across its argument boundaries.
96
+
97
+ `latexCompletions(query, locale)` is also exported from `@barocss/math-editor-text`. Each result includes `id`, `label`, `glyph`, `insert`, and UTF-16 `stops` relative to `insert`. A host can use this data in its own native completion provider instead of enabling the supplied dropdown. The `messages` option includes `suggestions`, `preview`, and `incomplete`; suggestion labels use the core locale catalog.
98
+
99
+ This source-completion mode applies to the three browser adapters. The VS Code extension currently retains its separate visual Webview workflow.
100
+
101
+ ## User workflow
102
+
103
+ 1. Place the caret within `$…$`, `$$…$$`, `\(…\)`, or `\[…\]`. Alternatively, select a bare LaTeX expression.
104
+ 2. Press Alt+Enter (Option+Enter on macOS) or click **Edit formula**.
105
+ 3. Edit the draft. Math suggestions and clipboard controls operate inside the popup.
106
+ 4. Apply to replace the formula contents. Cancel to preserve the original.
107
+ 5. Continue in the host text editor. Undo once to reverse the applied edit.
108
+
109
+ Opening the affordance never steals focus. An unchanged Apply does not normalize the original or add an undo entry. Changed formulas use the core serializer, which can normalize commands and whitespace inside the edited range. Existing dollar/backslash delimiters and surrounding prose remain intact. Leading/trailing whitespace inside the delimiters is preserved, including blank lines and indentation. For example, `$$\nx+1\n$$` becomes `$$\ny+1\n$$` after changing `x` to `y`. Newly serialized rows retain the source CRLF/LF convention; one-line display formulas remain one line.
110
+
111
+ While the popup is open, move the source caret to another formula to switch its contents. This does not take focus from the source editor. Moving outside math hides the popup; entering another formula shows it again. Unapplied drafts survive formula switches while the source version is unchanged. Apply changes only the current formula. If other drafts remain, Apply or Cancel first shows a warning. The explicit discard button finishes the session; returning to another formula keeps its draft. Repeated Enter/Escape does not confirm discarding.
112
+
113
+ ## Source safety and limitations
114
+
115
+ The default scanner skips ordinary Markdown code fences, inline code, indented code lines, and HTML comments. LaTeX mode skips percent line comments and common `\verb`, `verbatim`, `lstlisting`, and `minted` literal constructs. It supports a bounded set of equation, alignment, cases, and matrix environments. Detection is followed by the core LaTeX parser; unsupported syntax cannot overwrite the source. Complete environment ranges can be normalized when edited.
116
+
117
+ The scanner is not a full Markdown/TeX parser. Hosts with custom macros, custom literal environments, or nested Markdown containers should provide `resolveRange(source, selection)` using their syntax tree. A return value of `undefined` disables automatic fallback for that position. Source offsets are UTF-16 positions.
118
+
119
+ Any source edit or document switch invalidates an open draft, including edit-then-undo. External changes while editing in the popup still block Apply. Returning to the source caret reloads its current formula from the new source. Old-version drafts are not restored or rebased. Read-only documents reject Apply. Multiple selections are rejected. Multi-caret batch editing and concurrent-edit rebasing are not implemented.
120
+
121
+ ## Localization and styling
122
+
123
+ `locale` controls the math editor. The popup includes English and Korean dictionaries. `messages` overrides individual popup labels for additional locales. Register core locale messages separately for mathematical suggestions and controls.
124
+
125
+ The popup exposes `--me-text-background`, `--me-text-foreground`, `--me-text-border`, `--me-text-muted`, `--me-text-accent`, and `--me-text-on-accent`. Import both the core and text popup styles.
126
+
127
+ ## VS Code
128
+
129
+ The extension supplies **Barocss: Edit Formula** and **Barocss: Insert Formula**. It uses a Webview and the public VS Code document API, not the internal Monaco DOM. In Markdown and LaTeX documents, Alt+Enter opens editing; users can change that binding in VS Code.
130
+
131
+ Build and package from the workspace:
132
+
133
+ ```sh
134
+ pnpm --filter barocss-math-editor type-check
135
+ pnpm --filter barocss-math-editor package
136
+ ```
137
+
138
+ Install the generated VSIX through **Extensions: Install from VSIX**. Desktop Extension Host validation and Marketplace publication must be checked separately from browser adapter tests.
139
+
140
+ ## Validation scenarios
141
+
142
+ | Scenario | Expected result |
143
+ | --- | --- |
144
+ | Caret enters a formula | Edit affordance appears without taking focus |
145
+ | Apply `x` → `y` | Only the formula contents change |
146
+ | Undo / Redo | One host history step restores/reapplies the edit |
147
+ | Cancel | Original text and history remain unchanged |
148
+ | Apply unchanged draft | Exact original source remains |
149
+ | Source edited while popup is open | Conflict shown; newer source preserved |
150
+ | Unsupported command | Error shown; source preserved |
151
+ | Caret in Markdown code | No automatic formula popup |
152
+ | Read-only host | No source edit allowed |
153
+ | Host destroyed | Popup and listeners removed |
154
+
155
+ Browser scenario source: `apps/math-text-demo/test/editing.browser.js`. Range tests: `packages/math-editor-text/test/ranges.test.ts`.
156
+
157
+ When wrapping a compound source expression in an exponent, visible parentheses preserve its scope: selecting `a+b` inserts `{\left(a+b\right)}^{}`. A single variable, number, or already grouped structure does not receive redundant parentheses. Source text inside the base remains unchanged.