@fnix/lexxy-mathjax 0.2.0 → 0.3.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/README.md CHANGED
@@ -79,6 +79,40 @@ This package persists raw LaTeX (`data-latex`) and re-typesets it on every load,
79
79
  - **Font-size macros changed in MathJax 4.1.2** (`\tiny`/`\Tiny` swapped, `\large`…`\Huge` shifted by one), so existing content can render at a different size. Opt out with the `fontsizev3` TeX package (`loader: { load: ["[tex]/fontsizev3"] }, tex: { packages: { "[+]": ["fontsizev3"] } }`) if you pin a floating `@4` range.
80
80
  - **Accessibility moved, but only for math MathJax typesets itself.** v4 turns assistive MathML off by default and turns the expression explorer (speech/braille) on instead. MathJax's own docs warn that math inserted via a direct conversion call — `tex2chtmlPromise`/`tex2svgPromise`, which is what this package uses, both in the editor and on display pages — "will not become part of the list of math expressions that MathJax knows about in the page", so the explorer never attaches to it. Both `createDOM` (editor) and `typesetMath` (display pages) compensate by setting `role="math"` / `aria-label="Equation: ..."` on every equation directly, rather than relying on the explorer.
81
81
 
82
+ ## Theming
83
+
84
+ The equation editor dialog (`<lexxy-math-editor>`) is styled entirely through CSS custom properties. Set any of these on `:root` or on an ancestor of the dialog to restyle it — a host that sets none gets exactly the defaults below, unchanged:
85
+
86
+ | Property | Default | Controls |
87
+ | --- | --- | --- |
88
+ | `--lexxy-math-backdrop-color` | `rgba(0, 0, 0, 0.35)` | `::backdrop` behind the modal |
89
+ | `--lexxy-math-dialog-bg` | `Canvas` | dialog surface, button faces |
90
+ | `--lexxy-math-dialog-border-color` | `#d4d4d8` | dialog border |
91
+ | `--lexxy-math-dialog-radius` | `0.5rem` | dialog corner radius |
92
+ | `--lexxy-math-dialog-shadow` | `0 10px 30px rgba(0, 0, 0, 0.15)` | dialog drop shadow |
93
+ | `--lexxy-math-text-color` | `CanvasText` | dialog and button text |
94
+ | `--lexxy-math-muted-color` | `#52525b` | the "LaTeX" field label |
95
+ | `--lexxy-math-input-bg` | `Field` | textarea background |
96
+ | `--lexxy-math-input-text-color` | `FieldText` | textarea text |
97
+ | `--lexxy-math-input-border-color` | `#d4d4d8` | textarea, preview and button borders |
98
+ | `--lexxy-math-input-radius` | `0.375rem` | textarea, preview and button radius |
99
+ | `--lexxy-math-focus-color` | `#2563eb` | Save button fill, in-editor selection outline |
100
+ | `--lexxy-math-focus-content-color` | `white` | Save button label |
101
+ | `--lexxy-math-error-color` | `#b91c1c` | failed-equation text and dashed outline |
102
+
103
+ ```css
104
+ :root {
105
+ --lexxy-math-dialog-bg: var(--my-app-surface);
106
+ --lexxy-math-dialog-border-color: var(--my-app-border);
107
+ --lexxy-math-dialog-radius: var(--my-app-radius-lg);
108
+ --lexxy-math-focus-color: var(--my-app-accent);
109
+ }
110
+ ```
111
+
112
+ `Canvas`, `CanvasText`, `Field` and `FieldText` are the browser's own [system colors](https://developer.mozilla.org/en-US/docs/Web/CSS/system-color): they track the page's light/dark scheme automatically, so the dialog follows the OS or `prefers-color-scheme` without any configuration.
113
+
114
+ `--lexxy-math-backdrop-color` targets `::backdrop`, which only inherits custom properties from its originating element in newer browser engines. On older engines the backdrop falls back to today's `rgba(0, 0, 0, 0.35)` rather than breaking.
115
+
82
116
  ## Rails / ActionText integration
83
117
 
84
118
  **1. Allow `data-latex` through the server-side sanitizer** (ActionText strips unknown attributes when rendering):
@@ -211,3 +245,4 @@ The code follows lexxy's own conventions: plain ES modules, vanilla JS, no build
211
245
  - `src/typeset_math.js` — `typesetMath(root)`, the display-page renderer; batches conversions and refreshes MathJax's stylesheet once per call instead of once per equation
212
246
  - `src/auto_typeset.js` — `startMathjaxAutoTypeset()`, wires `typesetMath` to `DOMContentLoaded`/Turbo events
213
247
  - `src/typeset.js` — the `@fnix/lexxy-mathjax/typeset` entry point (re-exports the two above without pulling in lexxy/Lexical)
248
+ - `styles/lexxy-mathjax.css` — presentation for equations and the editor dialog; the `--lexxy-math-*` custom properties it exposes are a public contract (see [Theming](#theming)), covered by `test/styles.test.js`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fnix/lexxy-mathjax",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "MathJax LaTeX equation extension for Lexxy, the rich text editor for Rails.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -23,27 +23,33 @@ lexxy-editor .lexxy-math:hover {
23
23
 
24
24
  lexxy-editor .lexxy-math.selected,
25
25
  lexxy-editor [data-lexical-decorator="true"]:focus .lexxy-math {
26
- outline: 2px solid var(--lexxy-focus-color, #2563eb);
26
+ outline: 2px solid var(--lexxy-math-focus-color, #2563eb);
27
27
  }
28
28
 
29
29
  .lexxy-math--error {
30
- color: #b91c1c;
30
+ color: var(--lexxy-math-error-color, #b91c1c);
31
31
  font-family: monospace;
32
- outline: 1px dashed #b91c1c;
32
+ outline: 1px dashed var(--lexxy-math-error-color, #b91c1c);
33
33
  }
34
34
 
35
35
  /* Equation editor dialog */
36
36
 
37
37
  .lexxy-math-editor::backdrop {
38
- background: rgba(0, 0, 0, 0.35);
38
+ background: var(--lexxy-math-backdrop-color, rgba(0, 0, 0, 0.35));
39
39
  }
40
40
 
41
41
  .lexxy-math-editor {
42
+ /* Restores the UA's `dialog:modal { margin: auto }` centring, which any host reset
43
+ that zeroes margin on `*` (Tailwind preflight, normalize.css, Bootstrap reboot)
44
+ overrides — author origin beats UA origin regardless of cascade layers. Do not remove. */
45
+ margin: auto;
42
46
  min-width: min(28rem, 90vw);
43
- border: 1px solid #d4d4d8;
44
- border-radius: 0.5rem;
47
+ background: var(--lexxy-math-dialog-bg, Canvas);
48
+ color: var(--lexxy-math-text-color, CanvasText);
49
+ border: 1px solid var(--lexxy-math-dialog-border-color, #d4d4d8);
50
+ border-radius: var(--lexxy-math-dialog-radius, 0.5rem);
45
51
  padding: 1rem;
46
- box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
52
+ box-shadow: var(--lexxy-math-dialog-shadow, 0 10px 30px rgba(0, 0, 0, 0.15));
47
53
  }
48
54
 
49
55
  .lexxy-math-editor form {
@@ -57,15 +63,17 @@ lexxy-editor [data-lexical-decorator="true"]:focus .lexxy-math {
57
63
  flex-direction: column;
58
64
  gap: 0.25rem;
59
65
  font-size: 0.85rem;
60
- color: #52525b;
66
+ color: var(--lexxy-math-muted-color, #52525b);
61
67
  }
62
68
 
63
69
  .lexxy-math-editor textarea {
64
70
  font-family: ui-monospace, monospace;
65
71
  font-size: 0.95rem;
66
72
  padding: 0.5rem;
67
- border: 1px solid #d4d4d8;
68
- border-radius: 0.375rem;
73
+ background: var(--lexxy-math-input-bg, Field);
74
+ color: var(--lexxy-math-input-text-color, FieldText);
75
+ border: 1px solid var(--lexxy-math-input-border-color, #d4d4d8);
76
+ border-radius: var(--lexxy-math-input-radius, 0.375rem);
69
77
  resize: vertical;
70
78
  }
71
79
 
@@ -75,8 +83,8 @@ lexxy-editor [data-lexical-decorator="true"]:focus .lexxy-math {
75
83
  align-items: center;
76
84
  justify-content: center;
77
85
  padding: 0.5rem;
78
- border: 1px dashed #d4d4d8;
79
- border-radius: 0.375rem;
86
+ border: 1px dashed var(--lexxy-math-input-border-color, #d4d4d8);
87
+ border-radius: var(--lexxy-math-input-radius, 0.375rem);
80
88
  overflow-x: auto;
81
89
  }
82
90
 
@@ -101,14 +109,15 @@ lexxy-editor [data-lexical-decorator="true"]:focus .lexxy-math {
101
109
 
102
110
  .lexxy-math-editor__actions button {
103
111
  padding: 0.35rem 0.9rem;
104
- border-radius: 0.375rem;
105
- border: 1px solid #d4d4d8;
106
- background: white;
112
+ border-radius: var(--lexxy-math-input-radius, 0.375rem);
113
+ border: 1px solid var(--lexxy-math-input-border-color, #d4d4d8);
114
+ background: var(--lexxy-math-dialog-bg, Canvas);
115
+ color: var(--lexxy-math-text-color, CanvasText);
107
116
  cursor: pointer;
108
117
  }
109
118
 
110
119
  .lexxy-math-editor__actions button[data-behavior="confirm"] {
111
- background: var(--lexxy-focus-color, #2563eb);
112
- border-color: var(--lexxy-focus-color, #2563eb);
113
- color: white;
120
+ background: var(--lexxy-math-focus-color, #2563eb);
121
+ border-color: var(--lexxy-math-focus-color, #2563eb);
122
+ color: var(--lexxy-math-focus-content-color, white);
114
123
  }