formula-composer 0.0.0-stage → 0.1.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/LICENSE +22 -0
- package/README.md +122 -2
- package/angular/esm2020/formula-composer-tinymce-angular.mjs +4 -0
- package/angular/esm2020/lib/formula-composer.directive.mjs +52 -0
- package/angular/esm2020/lib/formula-composer.module.mjs +21 -0
- package/angular/esm2020/lib/init.mjs +9 -0
- package/angular/esm2020/lib/provide.mjs +11 -0
- package/angular/esm2020/public-api.mjs +8 -0
- package/angular/fesm2015/formula-composer-tinymce-angular.mjs +99 -0
- package/angular/fesm2020/formula-composer-tinymce-angular.mjs +101 -0
- package/angular/formula-composer-tinymce-angular.d.ts +5 -0
- package/angular/lib/formula-composer.directive.d.ts +22 -0
- package/angular/lib/formula-composer.module.d.ts +15 -0
- package/angular/lib/init.d.ts +23 -0
- package/angular/lib/provide.d.ts +10 -0
- package/angular/package.json +10 -0
- package/angular/public-api.d.ts +5 -0
- package/dist/editor-ui/catalog-types.d.ts +30 -0
- package/dist/editor-ui/catalog.generated.d.ts +2 -0
- package/dist/editor-ui/commands.d.ts +44 -0
- package/dist/editor-ui/dom.d.ts +8 -0
- package/dist/editor-ui/editor.d.ts +86 -0
- package/dist/editor-ui/icons.d.ts +5 -0
- package/dist/editor-ui/index.d.ts +9 -0
- package/dist/editor-ui/index.js +119 -0
- package/dist/editor-ui/modal.d.ts +81 -0
- package/dist/editor-ui/periodic.d.ts +8 -0
- package/dist/editor-ui/pickers.d.ts +23 -0
- package/dist/editor-ui/popover.d.ts +24 -0
- package/dist/editor-ui/special-chars.generated.d.ts +10 -0
- package/dist/editor-ui/strings.d.ts +48 -0
- package/dist/editor-ui/styles.d.ts +3 -0
- package/dist/editor-ui/toolbar.d.ts +47 -0
- package/dist/integration/content.d.ts +52 -0
- package/dist/integration/controller.d.ts +76 -0
- package/dist/integration/index.d.ts +3 -0
- package/dist/integration/index.js +1 -0
- package/dist/integration/options.d.ts +46 -0
- package/dist/math-core/a11y.d.ts +3 -0
- package/dist/math-core/caret-speech.d.ts +3 -0
- package/dist/math-core/editor.d.ts +212 -0
- package/dist/math-core/functions.d.ts +8 -0
- package/dist/math-core/history.d.ts +16 -0
- package/dist/math-core/index.d.ts +17 -0
- package/dist/math-core/index.js +3 -0
- package/dist/math-core/latex/parse.d.ts +11 -0
- package/dist/math-core/latex/serialize.d.ts +4 -0
- package/dist/math-core/latex/symbols.d.ts +32 -0
- package/dist/math-core/mathml.d.ts +33 -0
- package/dist/math-core/model.d.ts +69 -0
- package/dist/math-core/safe-xml.d.ts +7 -0
- package/dist/math-core/sanitize.d.ts +6 -0
- package/dist/math-core/tree-index.d.ts +26 -0
- package/dist/math-core/xml.d.ts +21 -0
- package/dist/renderer/alphanumerics.d.ts +3 -0
- package/dist/renderer/attributes.d.ts +10 -0
- package/dist/renderer/core.d.ts +13 -0
- package/dist/renderer/image.d.ts +29 -0
- package/dist/renderer/index.d.ts +22 -0
- package/dist/renderer/index.js +9 -0
- package/dist/renderer/layout.d.ts +14 -0
- package/dist/renderer/styles.d.ts +9 -0
- package/dist/renderer/view.d.ts +30 -0
- package/dist/renderer/vnode.d.ts +25 -0
- package/dist/tinymce/browser/plugin.min.js +129 -0
- package/dist/tinymce/compat.d.ts +24 -0
- package/dist/tinymce/index.d.ts +5 -0
- package/dist/tinymce/index.js +1 -0
- package/dist/tinymce/init.d.ts +22 -0
- package/dist/tinymce/plugin.d.ts +30 -0
- package/dist/tinymce/tinymce-types.d.ts +127 -0
- package/dist/tinymce-react/editor.d.ts +19 -0
- package/dist/tinymce-react/index.d.ts +3 -0
- package/dist/tinymce-react/index.js +1 -0
- package/dist/tinymce-react/init.d.ts +23 -0
- package/editor-ui/package.json +6 -0
- package/images/edit-formula.png +0 -0
- package/images/editor-content.png +0 -0
- package/integration/package.json +6 -0
- package/math-core/package.json +6 -0
- package/package.json +101 -4
- package/react/package.json +6 -0
- package/renderer/package.json +6 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { MathEditor, type MathEditorOptions } from './editor.js';
|
|
2
|
+
export type ModalState = 'stack' | 'minimized' | 'fullscreen';
|
|
3
|
+
export interface MathModalOptions extends MathEditorOptions {
|
|
4
|
+
/** Open maximized (`modalWindowFullScreen`, MD-010). */
|
|
5
|
+
fullScreen?: boolean;
|
|
6
|
+
/** Right-to-left host (TinyMCE `directionality: 'rtl'`, CFG-019): dock at the bottom left and start new formulas RTL. */
|
|
7
|
+
rtl?: boolean;
|
|
8
|
+
/** Called with the MathML when the user presses Insert. Return `false` to keep the modal open. */
|
|
9
|
+
onInsert: (mathml: string, editor: MathEditor) => boolean | void;
|
|
10
|
+
onClose?: () => void;
|
|
11
|
+
}
|
|
12
|
+
export interface OpenOptions {
|
|
13
|
+
mathml?: string;
|
|
14
|
+
latex?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Reference sizes (MD-001..003). */
|
|
17
|
+
export declare const STACK_SIZE: {
|
|
18
|
+
readonly width: 580;
|
|
19
|
+
readonly height: 338;
|
|
20
|
+
};
|
|
21
|
+
export declare const MINIMIZED_SIZE: {
|
|
22
|
+
readonly width: 250;
|
|
23
|
+
readonly height: 30;
|
|
24
|
+
};
|
|
25
|
+
export declare const FULLSCREEN_MAX: {
|
|
26
|
+
readonly width: 1200;
|
|
27
|
+
readonly height: 700;
|
|
28
|
+
};
|
|
29
|
+
/** MathType-style editor window: stack / minimized / full-screen, drag, resize, cancel confirmation. */
|
|
30
|
+
export declare class MathModal {
|
|
31
|
+
private readonly options;
|
|
32
|
+
readonly element: HTMLDivElement;
|
|
33
|
+
readonly editor: MathEditor;
|
|
34
|
+
private readonly doc;
|
|
35
|
+
private readonly overlay;
|
|
36
|
+
private readonly titleBar;
|
|
37
|
+
private readonly minimizeButton;
|
|
38
|
+
private readonly fullscreenButton;
|
|
39
|
+
private readonly body;
|
|
40
|
+
private readonly confirm;
|
|
41
|
+
private state;
|
|
42
|
+
private previousState;
|
|
43
|
+
private geometry;
|
|
44
|
+
private opened;
|
|
45
|
+
private returnFocus;
|
|
46
|
+
private lockedScroll;
|
|
47
|
+
private readonly onWindowResize;
|
|
48
|
+
private readonly onDocKeyDown;
|
|
49
|
+
constructor(host: HTMLElement, options: MathModalOptions);
|
|
50
|
+
get isOpen(): boolean;
|
|
51
|
+
get currentState(): ModalState;
|
|
52
|
+
/** Opens with a formula (`mathml` or `latex`), or empty. */
|
|
53
|
+
open(content?: OpenOptions): void;
|
|
54
|
+
/** Closes without inserting. */
|
|
55
|
+
close(): void;
|
|
56
|
+
/** Cancel/close/Esc: confirms first when the formula changed (INT-015/016). */
|
|
57
|
+
requestClose(): void;
|
|
58
|
+
insert(): void;
|
|
59
|
+
setState(state: ModalState): void;
|
|
60
|
+
destroy(): void;
|
|
61
|
+
private titleButton;
|
|
62
|
+
private setButtonLabel;
|
|
63
|
+
/** Width of the layout viewport; height and offset of the visible area, which shrinks above a soft keyboard. */
|
|
64
|
+
private viewport;
|
|
65
|
+
private isCompact;
|
|
66
|
+
private lockScroll;
|
|
67
|
+
private unlockScroll;
|
|
68
|
+
private stackGeometry;
|
|
69
|
+
private dockLeft;
|
|
70
|
+
private clampGeometry;
|
|
71
|
+
private applyGeometry;
|
|
72
|
+
private currentGeometry;
|
|
73
|
+
private startDrag;
|
|
74
|
+
private startResize;
|
|
75
|
+
private trackPointer;
|
|
76
|
+
private showConfirm;
|
|
77
|
+
private hideConfirm;
|
|
78
|
+
private handleKey;
|
|
79
|
+
/** Keeps Tab inside the window (the confirmation when shown). */
|
|
80
|
+
private trapFocus;
|
|
81
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolbarItem } from './catalog-types.js';
|
|
2
|
+
/** Row count of the periodic table "More" grid (7 periods, a gap row and the f-block rows). */
|
|
3
|
+
export declare const PERIODIC_TABLE_ROWS = 9;
|
|
4
|
+
export type ElementGroup = 'hydrogen' | 'alkali' | 'alkaline-earth' | 'transition' | 'post-transition' | 'nonmetal' | 'noble-gas' | 'lanthanide' | 'actinide' | 'unknown';
|
|
5
|
+
/** Chemical group of a periodic table control, from the element symbol it inserts. */
|
|
6
|
+
export declare function elementGroup(item: ToolbarItem): ElementGroup | undefined;
|
|
7
|
+
/** Decorative f-block placeholders and connector lines; hidden from assistive technology. */
|
|
8
|
+
export declare function periodicDecorations(doc: Document): Array<HTMLElement | SVGElement>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CharacterToken } from '../math-core/index';
|
|
2
|
+
import type { EditorStrings, SpecialCategory } from './strings.js';
|
|
3
|
+
export interface PickerContent {
|
|
4
|
+
content: HTMLElement;
|
|
5
|
+
initialFocus: HTMLElement;
|
|
6
|
+
}
|
|
7
|
+
export declare const MATRIX_GRID_SIZE = 6;
|
|
8
|
+
/** 6×6 hover grid plus Rows/Columns inputs (PU-001). */
|
|
9
|
+
export declare function matrixPicker(doc: Document, strings: EditorStrings, onPick: (rows: number, columns: number) => void): PickerContent;
|
|
10
|
+
/** Original 5×5 palette. */
|
|
11
|
+
export declare const COLOR_PALETTE: readonly string[];
|
|
12
|
+
export declare function normalizeHex(value: string): string | null;
|
|
13
|
+
/** 5×5 swatches plus a hex input (ST-006). */
|
|
14
|
+
export declare function colorPicker(doc: Document, strings: EditorStrings, current: string | null, onPick: (color: string) => void): PickerContent;
|
|
15
|
+
/** The reference's characters of a category, in its order (PU-002, `special-characters.json`). */
|
|
16
|
+
export declare function charactersOf(category: SpecialCategory): string[];
|
|
17
|
+
/** The token the reference inserts for a character of its special-characters lists (PU-002); undefined for others. */
|
|
18
|
+
export declare function specialCharacterToken(ch: string): CharacterToken | undefined;
|
|
19
|
+
export declare function codeToCharacter(code: string): string | null;
|
|
20
|
+
/** "Code" field, category select and character grid (PU-002). Grid pages in lazily on scroll. */
|
|
21
|
+
export declare function specialCharsPicker(doc: Document, strings: EditorStrings, onPick: (ch: string) => void): PickerContent;
|
|
22
|
+
/** Single numeric value in `em` (contextual spacing commands). */
|
|
23
|
+
export declare function valuePrompt(doc: Document, strings: EditorStrings, label: string, initial: string, onApply: (value: string) => void): PickerContent;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface PopoverOptions {
|
|
2
|
+
anchor: HTMLElement;
|
|
3
|
+
/** Element the popover is positioned in (it must be `position: relative` or similar). */
|
|
4
|
+
container: HTMLElement;
|
|
5
|
+
label: string;
|
|
6
|
+
content: HTMLElement;
|
|
7
|
+
/** Element to focus when opened; defaults to the first focusable element. */
|
|
8
|
+
initialFocus?: HTMLElement;
|
|
9
|
+
onClose?: () => void;
|
|
10
|
+
role?: 'dialog' | 'menu' | 'listbox';
|
|
11
|
+
}
|
|
12
|
+
/** A small non-modal popup anchored to a toolbar control. Closes on Escape, outside click or {@link close}. */
|
|
13
|
+
export declare class Popover {
|
|
14
|
+
private readonly options;
|
|
15
|
+
readonly element: HTMLDivElement;
|
|
16
|
+
private closed;
|
|
17
|
+
private readonly onPointerDown;
|
|
18
|
+
private readonly onKeyDown;
|
|
19
|
+
constructor(options: PopoverOptions);
|
|
20
|
+
get isOpen(): boolean;
|
|
21
|
+
private position;
|
|
22
|
+
/** `restoreFocus` returns focus to the anchor (keyboard dismissal). */
|
|
23
|
+
close(restoreFocus?: boolean): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SpecialCategory } from './strings.js';
|
|
2
|
+
/** Code points of each special-characters category in the reference's order: hex, `start-end` for runs. */
|
|
3
|
+
export declare const SPECIAL_CHARACTERS: Readonly<Record<SpecialCategory, string>>;
|
|
4
|
+
/**
|
|
5
|
+
* The token the reference inserts for each character, in SPECIAL_CHARACTERS order: `i` mi, `o` mo, `n` mn,
|
|
6
|
+
* `v` the form in SPECIAL_CHARACTER_FORMS, `-` nothing (the typing rules apply).
|
|
7
|
+
*/
|
|
8
|
+
export declare const SPECIAL_CHARACTER_TAGS: Readonly<Record<SpecialCategory, string>>;
|
|
9
|
+
/** Characters the reference inserts as another text with a `mathvariant` (hex code → tag, mathvariant, text). */
|
|
10
|
+
export declare const SPECIAL_CHARACTER_FORMS: Readonly<Record<string, readonly ['mi' | 'mn' | 'mo', string, string]>>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { TabId } from './catalog-types.js';
|
|
2
|
+
/** UI chrome strings. Toolbar tooltips come from the catalog (English). */
|
|
3
|
+
export interface EditorStrings {
|
|
4
|
+
title: string;
|
|
5
|
+
insert: string;
|
|
6
|
+
cancel: string;
|
|
7
|
+
minimize: string;
|
|
8
|
+
restore: string;
|
|
9
|
+
fullscreen: string;
|
|
10
|
+
exitFullscreen: string;
|
|
11
|
+
close: string;
|
|
12
|
+
confirmMessage: string;
|
|
13
|
+
confirmDiscard: string;
|
|
14
|
+
confirmReturn: string;
|
|
15
|
+
mathInput: string;
|
|
16
|
+
toolbar: string;
|
|
17
|
+
more: string;
|
|
18
|
+
latex: string;
|
|
19
|
+
latexInput: string;
|
|
20
|
+
latexInvalid: string;
|
|
21
|
+
help: string;
|
|
22
|
+
helpTitle: string;
|
|
23
|
+
rows: string;
|
|
24
|
+
columns: string;
|
|
25
|
+
apply: string;
|
|
26
|
+
hexColor: string;
|
|
27
|
+
code: string;
|
|
28
|
+
category: string;
|
|
29
|
+
resize: string;
|
|
30
|
+
dragHandle: string;
|
|
31
|
+
emptyFormula: string;
|
|
32
|
+
insertFormula: string;
|
|
33
|
+
menuItem: string;
|
|
34
|
+
tabShortcut: string;
|
|
35
|
+
tabs: Readonly<Record<TabId, string>>;
|
|
36
|
+
categories: Readonly<Record<SpecialCategory, string>>;
|
|
37
|
+
}
|
|
38
|
+
export type SpecialCategory = 'symbol' | 'punctuation' | 'letter' | 'mark' | 'number' | 'phonetic' | 'other';
|
|
39
|
+
export declare const SUPPORTED_LANGUAGES: readonly string[];
|
|
40
|
+
/** Normalises `pt-BR` / `pt_BR` / `PT` to the keys above. */
|
|
41
|
+
export declare function normalizeLanguage(language: string | undefined): string;
|
|
42
|
+
export declare function isRtlLanguage(language: string | undefined): boolean;
|
|
43
|
+
export type StringOverrides = Partial<Omit<EditorStrings, 'tabs' | 'categories'>> & {
|
|
44
|
+
tabs?: Partial<EditorStrings['tabs']>;
|
|
45
|
+
categories?: Partial<EditorStrings['categories']>;
|
|
46
|
+
};
|
|
47
|
+
export declare function getStrings(language?: string, overrides?: StringOverrides): EditorStrings;
|
|
48
|
+
export declare function format(template: string, values: Readonly<Record<string, string | number>>): string;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Original styles; theme through the `--sw-*` custom properties. */
|
|
2
|
+
export declare const EDITOR_CSS = "\n.sw-editor,.sw-modal{--sw-bg:#fff;--sw-fg:#1d2733;--sw-muted:#5b6878;--sw-border:#c9d1db;--sw-toolbar:#eef1f5;--sw-tab:#dde3ea;--sw-accent:#2f6fde;--sw-accent-fg:#fff;--sw-hover:#d7e3f7;--sw-focus:#2f6fde;--sw-strip:#5d6c7b;--sw-radius:4px;\n font:13px/1.3 system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif;color:var(--sw-fg);box-sizing:border-box;}\n.sw-editor *,.sw-modal *{box-sizing:border-box;}\n.sw-editor{display:flex;flex-direction:column;min-height:0;height:100%;background:var(--sw-bg);position:relative;}\n.sw-toolbar{background:var(--sw-toolbar);border-bottom:1px solid var(--sw-border);flex:none;}\n.sw-tabbar{display:flex;align-items:flex-end;gap:4px;padding:3px 4px 0;}\n.sw-tablist{display:flex;flex-wrap:wrap;gap:2px;flex:1;min-width:0;}\n.sw-tab{border:1px solid var(--sw-border);border-bottom:none;border-radius:var(--sw-radius) var(--sw-radius) 0 0;background:var(--sw-tab);color:var(--sw-fg);padding:2px 7px;min-width:34px;height:24px;cursor:pointer;font:14px/1 \"STIX Two Math\",\"Cambria Math\",serif;}\n.sw-tab[aria-selected=\"true\"]{background:var(--sw-bg);position:relative;top:1px;}\n.sw-tab:hover{background:var(--sw-hover);}\n.sw-tab-extras{display:flex;gap:2px;padding-bottom:2px;}\n.sw-tab-extra{border:1px solid var(--sw-border);border-radius:var(--sw-radius);background:var(--sw-bg);color:var(--sw-fg);height:22px;min-width:22px;padding:0 6px;cursor:pointer;font:600 12px/1 system-ui,sans-serif;}\n.sw-tab-extra[aria-pressed=\"true\"]{background:var(--sw-accent);color:var(--sw-accent-fg);border-color:var(--sw-accent);}\n.sw-panel{display:flex;flex-wrap:nowrap;overflow-x:auto;overscroll-behavior:contain;scrollbar-width:thin;align-items:flex-start;gap:0;padding:3px 2px;background:var(--sw-bg);min-height:86px;}\n.sw-panel[hidden]{display:none;}\n.sw-panel.sw-inactive{opacity:.45;pointer-events:none;}\n.sw-section{display:grid;grid-template-rows:repeat(3,26px);gap:1px;padding:0 3px;border-inline-end:1px solid var(--sw-border);position:relative;}\n.sw-section[data-rows=\"2\"]{grid-template-rows:repeat(2,39px);}\n.sw-section[data-rows=\"1\"]{grid-template-rows:39px;}\n.sw-section[data-more]{padding-inline-end:13px;}\n.sw-section[hidden]{display:none;}\n.sw-tool{min-width:26px;height:100%;padding:0 3px;border:1px solid transparent;border-radius:var(--sw-radius);background:transparent;color:var(--sw-fg);cursor:pointer;display:inline-flex;align-items:center;justify-content:center;overflow:hidden;}\n.sw-section[data-kind=\"template\"] .sw-tool{min-width:30px;}\n.sw-section[data-rows=\"3\"] .sw-tool{min-width:22px;padding:0 2px;}\n.sw-tool:hover{background:var(--sw-hover);border-color:var(--sw-border);}\n.sw-tool[aria-pressed=\"true\"]{background:var(--sw-hover);border-color:var(--sw-accent);}\n.sw-tool.sw-disabled{opacity:.4;cursor:default;}\n.sw-tool[hidden],.sw-select[hidden]{display:none;}\n.sw-tool-label{font:600 12px/1 system-ui,sans-serif;white-space:nowrap;}\n.sw-tool[data-id=\"TB-GEN-033\"] .sw-tool-label{font-style:italic;font-family:\"Times New Roman\",Times,serif;font-size:14px;}\n.sw-tool[data-id=\"TB-GEN-035\"] .sw-tool-label{display:inline-block;font-style:italic;font-family:\"Times New Roman\",Times,serif;font-size:14px;}\n.sw-tool[data-id=\"TB-GEN-035\"] .sw-tool-label::first-letter{font-style:normal;}\n.sw-icon{pointer-events:none;display:inline-flex;}\n.sw-icon math{font-size:14px;font-family:\"STIX Two Math\",\"FormulaComposer Math\",\"Cambria Math\",math;}\n.sw-section[data-kind=\"template\"] .sw-icon math{font-size:12px;math-style:normal;}\n.sw-more{position:absolute;inset-block:3px;inset-inline-end:2px;width:8px;padding:0 0 1px;border:none;border-radius:2px;background:transparent;color:var(--sw-muted);font-size:8px;line-height:1;cursor:pointer;display:flex;align-items:flex-end;justify-content:center;}\n.sw-more:hover{background:var(--sw-hover);}\n.sw-more[aria-expanded=\"true\"]{background:var(--sw-strip);color:#fff;}\n.sw-select{height:24px;max-width:80px;border:1px solid var(--sw-border);border-radius:var(--sw-radius);background:var(--sw-bg);color:var(--sw-fg);font:12px system-ui,sans-serif;}\n.sw-area{position:relative;flex:1;min-height:60px;overflow:auto;overscroll-behavior:contain;padding:10px 12px;background:var(--sw-bg);cursor:text;}\n.sw-area[hidden]{display:none;}\n.sw-area .sw-canvas{display:inline-block;min-width:100%;padding:2px 2px 6px;}\n.sw-input{position:absolute;left:0;top:0;width:1px;height:1px;opacity:0;padding:0;border:0;resize:none;overflow:hidden;pointer-events:none;}\n.sw-live{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;}\n.sw-latex{flex:1;min-height:60px;margin:8px;padding:8px;border:1px solid var(--sw-border);border-radius:var(--sw-radius);font:14px/1.4 ui-monospace,Menlo,Consolas,monospace;resize:none;color:var(--sw-fg);background:var(--sw-bg);}\n.sw-latex[hidden],.sw-latex-status[hidden]{display:none;}\n.sw-latex[aria-invalid=\"true\"]{border-color:#c62828;}\n.sw-latex-status{margin:0 8px 8px;color:#a32020;font-size:12px;}\n.sw-popover{position:absolute;z-index:5;background:var(--sw-bg);border:1px solid var(--sw-border);border-radius:var(--sw-radius);box-shadow:0 4px 14px rgba(20,30,45,.18);padding:6px;max-width:100%;}\n.sw-popover:has(> .sw-more-grid){padding:2px;border-color:var(--sw-strip);border-radius:3px;background:linear-gradient(var(--sw-bg),var(--sw-toolbar));box-shadow:0 3px 8px rgba(20,30,45,.2);}\n.sw-more-grid{display:grid;grid-template-rows:repeat(3,26px);grid-auto-columns:minmax(26px,auto);gap:1px;width:max-content;}\n.sw-more-grid[data-rows=\"2\"]{grid-template-rows:repeat(2,39px);grid-auto-columns:minmax(34px,auto);}\n.sw-more-grid[data-rows=\"9\"]{grid-template-rows:repeat(9,21px);grid-auto-columns:21px;}\n.sw-more-grid[data-rows=\"9\"] .sw-tool{min-width:0;padding:0;border-radius:0;}\n.sw-more-grid[data-rows=\"9\"] .sw-icon math{font:11px Arial,Helvetica,sans-serif;}\n.sw-more-grid .sw-tool[data-element=\"hydrogen\"]{background:#e7e7e7;}\n.sw-more-grid .sw-tool[data-element=\"alkali\"]{background:#ffaa00;}\n.sw-more-grid .sw-tool[data-element=\"alkaline-earth\"]{background:#f2f44c;}\n.sw-more-grid .sw-tool[data-element=\"transition\"]{background:#ff7799;}\n.sw-more-grid .sw-tool[data-element=\"post-transition\"]{background:#00cccc;}\n.sw-more-grid .sw-tool[data-element=\"nonmetal\"]{background:#00f700;}\n.sw-more-grid .sw-tool[data-element=\"noble-gas\"]{background:#5ff7f7;}\n.sw-more-grid .sw-tool[data-element=\"lanthanide\"]{background:#ffaa88;}\n.sw-more-grid .sw-tool[data-element=\"actinide\"]{background:#ddaacc;}\n.sw-more-grid .sw-tool[data-element=\"unknown\"]{background:#fff;}\n.sw-more-grid .sw-tool[data-element]{color:#000;}\n.sw-more-grid .sw-tool[data-element]:hover{border-color:var(--sw-strip);}\n.sw-periodic-slot{background:#f1c1d0;}\n.sw-periodic-links{width:100%;height:100%;overflow:visible;fill:none;stroke:#8a8a8a;pointer-events:none;}\n.sw-more-grid .sw-tool:focus{outline:2px solid var(--sw-strip);outline-offset:-2px;}\n.sw-picker-form{display:flex;align-items:center;gap:6px;margin-top:6px;flex-wrap:wrap;}\n.sw-picker-form input{width:72px;height:24px;border:1px solid var(--sw-border);border-radius:var(--sw-radius);padding:0 4px;font:12px system-ui,sans-serif;}\n.sw-picker-form input[aria-invalid=\"true\"]{border-color:#c62828;}\n.sw-matrix-grid [role=\"row\"]{display:flex;gap:2px;margin-bottom:2px;}\n.sw-matrix-cell{width:18px;height:18px;border:1px solid var(--sw-border);background:var(--sw-bg);padding:0;cursor:pointer;}\n.sw-matrix-cell.sw-active{background:var(--sw-hover);border-color:var(--sw-accent);}\n.sw-swatches{display:grid;grid-template-columns:repeat(5,22px);gap:3px;}\n.sw-swatch{width:22px;height:22px;border:1px solid var(--sw-border);border-radius:3px;padding:0;cursor:pointer;}\n.sw-swatch[aria-selected=\"true\"]{outline:2px solid var(--sw-accent);outline-offset:1px;}\n.sw-char-grid{display:grid;grid-template-columns:repeat(9,27px);grid-auto-rows:27px;width:max-content;max-height:191px;overflow-x:hidden;overflow-y:auto;margin-top:6px;border-top:1px solid var(--sw-border);border-left:1px solid var(--sw-border);}\n.sw-char{display:flex;align-items:center;justify-content:center;box-sizing:border-box;width:27px;height:27px;border:0;border-right:1px solid var(--sw-border);border-bottom:1px solid var(--sw-border);background:var(--sw-bg);color:var(--sw-fg);font:bold 16px/1 \"STIX Two Math\",\"STIX Two Text\",\"Cambria Math\",serif;cursor:pointer;padding:0;overflow:hidden;}\n.sw-char:hover,.sw-char:focus{background:var(--sw-hover);}\n.sw-help{border-collapse:collapse;font-size:12px;}\n.sw-help caption{font-weight:600;text-align:start;margin-bottom:4px;}\n.sw-help th,.sw-help td{text-align:start;padding:2px 8px 2px 0;font-weight:400;}\n.sw-help kbd{font:11px ui-monospace,Menlo,monospace;}\n.sw-help-popover{display:flex;flex-direction:column;gap:6px;align-items:flex-end;}\n.sw-button{height:28px;padding:0 14px;border:1px solid var(--sw-border);border-radius:var(--sw-radius);background:var(--sw-bg);color:var(--sw-fg);font:13px system-ui,sans-serif;cursor:pointer;}\n.sw-button:hover{background:var(--sw-hover);}\n.sw-button.sw-primary{background:var(--sw-accent);border-color:var(--sw-accent);color:var(--sw-accent-fg);}\n.sw-editor :focus-visible,.sw-modal :focus-visible{outline:2px solid var(--sw-focus);outline-offset:1px;}\n.sw-area:focus-within{box-shadow:inset 0 0 0 2px rgba(47,111,222,.35);}\n.sw-overlay{position:fixed;inset:0;background:rgba(15,20,30,.45);z-index:2147483000;}\n.sw-overlay[hidden],.sw-modal[hidden]{display:none;}\n.sw-modal{position:fixed;z-index:2147483001;display:flex;flex-direction:column;background:var(--sw-bg);border:1px solid #8c99a8;border-radius:6px 6px 0 0;box-shadow:0 8px 28px rgba(15,25,40,.28);overflow:hidden;}\n.sw-modal[data-state=\"fullscreen\"]{border-radius:6px;}\n.sw-modal-titlebar{display:flex;align-items:center;justify-content:space-between;height:30px;flex:none;padding:0 4px 0 10px;background:#33475b;color:#fff;cursor:move;user-select:none;touch-action:none;}\n.sw-modal[data-state=\"minimized\"] .sw-modal-titlebar{cursor:pointer;}\n.sw-modal[data-state=\"fullscreen\"] .sw-modal-titlebar{cursor:default;}\n.sw-modal-title{font-weight:600;font-size:13px;}\n.sw-modal-actions{display:flex;gap:2px;}\n.sw-title-button{width:26px;height:24px;border:none;border-radius:3px;background:transparent;color:#fff;font:15px/1 system-ui,sans-serif;cursor:pointer;}\n.sw-title-button:hover{background:rgba(255,255,255,.16);}\n.sw-title-button[hidden]{display:none;}\n.sw-modal-body{flex:1;min-height:0;display:flex;flex-direction:column;}\n.sw-modal-body[hidden],.sw-modal[data-state=\"minimized\"] .sw-modal-footer,.sw-modal[data-state=\"minimized\"] .sw-resizer{display:none;}\n.sw-modal-footer{display:flex;justify-content:flex-end;gap:8px;padding:8px 10px;border-top:1px solid var(--sw-border);flex:none;}\n.sw-confirm{position:absolute;inset:30px 0 0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;background:rgba(255,255,255,.94);z-index:6;padding:16px;text-align:center;}\n.sw-confirm[hidden]{display:none;}\n.sw-confirm p{margin:0;max-width:360px;font-size:14px;}\n.sw-confirm-actions{display:flex;gap:8px;}\n.sw-resizer{position:absolute;bottom:0;width:12px;height:12px;z-index:4;touch-action:none;}\n.sw-resizer-left{left:0;cursor:nesw-resize;}\n.sw-resizer-right{right:0;cursor:nwse-resize;}\n.sw-modal:not([data-state=\"stack\"]) .sw-resizer{display:none;}\n@media (forced-colors:active){.sw-tool[aria-pressed=\"true\"],.sw-tab[aria-selected=\"true\"]{outline:2px solid Highlight;}}\n";
|
|
3
|
+
export declare function ensureEditorStyles(doc: Document): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { TabId } from './catalog-types.js';
|
|
2
|
+
import { type EditorHost } from './commands.js';
|
|
3
|
+
import { Popover } from './popover.js';
|
|
4
|
+
import { type EditorStrings } from './strings.js';
|
|
5
|
+
export interface ToolbarOptions {
|
|
6
|
+
/** Tabs to show, in order. Defaults to all ten tabs. */
|
|
7
|
+
tabs?: readonly TabId[];
|
|
8
|
+
}
|
|
9
|
+
/** Tabbed toolbar built from the REA catalog. Panels render on first use. */
|
|
10
|
+
export declare class Toolbar {
|
|
11
|
+
private readonly doc;
|
|
12
|
+
private readonly host;
|
|
13
|
+
private readonly strings;
|
|
14
|
+
private readonly popupContainer;
|
|
15
|
+
private readonly afterCommand;
|
|
16
|
+
readonly element: HTMLDivElement;
|
|
17
|
+
readonly extras: HTMLDivElement;
|
|
18
|
+
private readonly tabs;
|
|
19
|
+
private readonly tabButtons;
|
|
20
|
+
private readonly panels;
|
|
21
|
+
private readonly rendered;
|
|
22
|
+
private readonly actions;
|
|
23
|
+
private readonly selects;
|
|
24
|
+
private readonly prefix;
|
|
25
|
+
private selected;
|
|
26
|
+
private popover;
|
|
27
|
+
constructor(doc: Document, host: EditorHost, strings: EditorStrings, popupContainer: HTMLElement, afterCommand: () => void, options?: ToolbarOptions);
|
|
28
|
+
get tabIds(): readonly TabId[];
|
|
29
|
+
get selectedTab(): TabId | undefined;
|
|
30
|
+
selectTab(index: number, focus: boolean): void;
|
|
31
|
+
selectTabById(id: TabId): void;
|
|
32
|
+
private onTabKeyDown;
|
|
33
|
+
private onPanelKeyDown;
|
|
34
|
+
private ensureRendered;
|
|
35
|
+
private icon;
|
|
36
|
+
private mathIcon;
|
|
37
|
+
private createControl;
|
|
38
|
+
private createSelect;
|
|
39
|
+
private createMoreButton;
|
|
40
|
+
/** Opens a popover anchored to `anchor`, replacing any open one. */
|
|
41
|
+
openPopover(anchor: HTMLElement, label: string, content: HTMLElement, initialFocus?: HTMLElement): Popover;
|
|
42
|
+
closePopover(): void;
|
|
43
|
+
get hasOpenPopover(): boolean;
|
|
44
|
+
/** Updates disabled/pressed/visible state after model changes. */
|
|
45
|
+
refresh(): void;
|
|
46
|
+
destroy(): void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type MathDocument } from '../math-core/index';
|
|
2
|
+
import type { ResolvedOptions } from './options.js';
|
|
3
|
+
/** How the host editor marks editing-only attributes in its editing view. */
|
|
4
|
+
export interface HostConventions {
|
|
5
|
+
/** Prefix of attributes that exist only while editing; they are removed from saved formula images. */
|
|
6
|
+
readonly internalAttributePrefix: string;
|
|
7
|
+
/** Marks images measured before the math font loaded, so they are regenerated once it is ready. Must use the prefix. */
|
|
8
|
+
readonly staleAttribute: string;
|
|
9
|
+
/** Extra editing-only attributes for formula images (TinyMCE: `data-mce-resize="false"`). Must use the prefix. */
|
|
10
|
+
readonly imageAttributes: Readonly<Record<string, string>>;
|
|
11
|
+
}
|
|
12
|
+
/** Conventions for hosts without their own (generic `contenteditable` integrations). */
|
|
13
|
+
export declare const DEFAULT_HOST_CONVENTIONS: HostConventions;
|
|
14
|
+
export interface ContentContext {
|
|
15
|
+
options: ResolvedOptions;
|
|
16
|
+
conventions: HostConventions;
|
|
17
|
+
/** Document used to parse HTML and measure formulas. */
|
|
18
|
+
doc: Document;
|
|
19
|
+
fontLoaded: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ParsedFormula {
|
|
22
|
+
doc: MathDocument;
|
|
23
|
+
/** Sanitized MathType-style MathML. */
|
|
24
|
+
mathml: string;
|
|
25
|
+
latex: string | null;
|
|
26
|
+
}
|
|
27
|
+
/** Parses plain or safe-XML MathML and sanitizes it for embedding in HTML. `null` when invalid. */
|
|
28
|
+
export declare function readFormula(source: string): ParsedFormula | null;
|
|
29
|
+
export declare function isEmptyFormula(formula: ParsedFormula): boolean;
|
|
30
|
+
/** Attributes of an editing-view formula image (INT-010). */
|
|
31
|
+
export declare function formulaImageAttributes(formula: ParsedFormula, ctx: ContentContext): Record<string, string>;
|
|
32
|
+
export declare function isFormulaImage(node: unknown, options: ResolvedOptions): node is HTMLImageElement;
|
|
33
|
+
/**
|
|
34
|
+
* Stored HTML → editing view (INT-010, INT-021, LX-005): MathML and safe-XML become formula images,
|
|
35
|
+
* MathML with a LaTeX annotation becomes `$$latex$$` text. `refreshImages` regenerates every formula
|
|
36
|
+
* image from its MathML (used for pasted content); otherwise only images without an SVG source are.
|
|
37
|
+
*/
|
|
38
|
+
export declare function toEditingHtml(html: string, ctx: ContentContext, refreshImages: boolean): string;
|
|
39
|
+
/**
|
|
40
|
+
* Editing view → stored HTML for `saveMode` (INT-017..020). Formula images become MathML (`xml`),
|
|
41
|
+
* safe-XML text (`safeXml`) or cleaned images (`image`, `base64`); `$$latex$$` becomes MathML with a
|
|
42
|
+
* LaTeX annotation.
|
|
43
|
+
*/
|
|
44
|
+
export declare function toSavedHtml(html: string, ctx: ContentContext): string;
|
|
45
|
+
/** `$$…$$` range around a collapsed caret inside a text node (LX-004). */
|
|
46
|
+
export interface LatexRange {
|
|
47
|
+
text: Text;
|
|
48
|
+
start: number;
|
|
49
|
+
end: number;
|
|
50
|
+
latex: string;
|
|
51
|
+
}
|
|
52
|
+
export declare function latexAtCaret(range: Range): LatexRange | null;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type EditorStrings } from '../editor-ui/index';
|
|
2
|
+
import { type HostConventions } from './content.js';
|
|
3
|
+
import type { ResolvedOptions } from './options.js';
|
|
4
|
+
/** Formula image attribute changes; `null` removes the attribute. */
|
|
5
|
+
export type AttributeUpdates = Readonly<Record<string, string | null>>;
|
|
6
|
+
/** Toolbar icon for "insert a math equation" buttons (24×24, `currentColor`). */
|
|
7
|
+
export declare const FORMULA_ICON_SVG: string;
|
|
8
|
+
/**
|
|
9
|
+
* What a rich-text editor provides to Formula Composer. Each change method is one user-visible step:
|
|
10
|
+
* implementations make it a single undo level and keep the editor's own state (selection, change
|
|
11
|
+
* notifications) in sync.
|
|
12
|
+
*/
|
|
13
|
+
export interface EditorAdapter<Bookmark = unknown> {
|
|
14
|
+
/** Document that hosts the editor window and measures formula images (the page document). */
|
|
15
|
+
readonly uiDocument: Document;
|
|
16
|
+
/** Right-to-left host: the editor window docks bottom-left and new formulas start RTL. */
|
|
17
|
+
isRtl(): boolean;
|
|
18
|
+
/** The editor is ready and the content at the selection can be edited. */
|
|
19
|
+
canEdit(): boolean;
|
|
20
|
+
/** Node at the selection; a formula image when one is selected. */
|
|
21
|
+
getSelectedNode(): Node | null;
|
|
22
|
+
/** Selection range inside the content, if any. */
|
|
23
|
+
getSelectionRange(): Range | null;
|
|
24
|
+
/** Selection bookmark that survives focus moving to the editor window. */
|
|
25
|
+
saveSelection(): Bookmark;
|
|
26
|
+
/** Inserts a formula image at `bookmark`, or at the current selection when `null`. */
|
|
27
|
+
insertFormula(attributes: Readonly<Record<string, string>>, bookmark: Bookmark | null): void;
|
|
28
|
+
/** Changes a formula image in place and selects it. */
|
|
29
|
+
updateFormula(img: HTMLImageElement, attributes: AttributeUpdates): void;
|
|
30
|
+
removeFormula(img: HTMLImageElement): void;
|
|
31
|
+
/** Replaces `text[start, end)` and puts the caret after the replacement. */
|
|
32
|
+
replaceText(text: Text, start: number, end: number, replacement: string): void;
|
|
33
|
+
/** Selects a formula image before it is edited (double-click). */
|
|
34
|
+
selectFormula(img: HTMLImageElement): void;
|
|
35
|
+
/** Root of the editable content, or `null` while the editor is not ready. */
|
|
36
|
+
getContentRoot(): HTMLElement | null;
|
|
37
|
+
/** Changes formula images without an undo level or marking the content as changed. */
|
|
38
|
+
refreshFormulas(updates: ReadonlyArray<readonly [HTMLImageElement, AttributeUpdates]>): void;
|
|
39
|
+
focus(): void;
|
|
40
|
+
}
|
|
41
|
+
export interface FormulaControllerOptions {
|
|
42
|
+
options: ResolvedOptions;
|
|
43
|
+
conventions: HostConventions;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Editor-neutral formula editing flow (INT-001..025): finds what to edit (a formula image, the
|
|
47
|
+
* `$$latex$$` at the caret or a new formula), runs the editor window, applies the result through the
|
|
48
|
+
* adapter and converts content between the stored and editing forms. One instance per editor.
|
|
49
|
+
*/
|
|
50
|
+
export declare class FormulaController<Bookmark = unknown> {
|
|
51
|
+
private readonly adapter;
|
|
52
|
+
readonly options: ResolvedOptions;
|
|
53
|
+
readonly strings: EditorStrings;
|
|
54
|
+
private readonly ctx;
|
|
55
|
+
private modal;
|
|
56
|
+
private target;
|
|
57
|
+
private destroyed;
|
|
58
|
+
constructor(adapter: EditorAdapter<Bookmark>, { options, conventions }: FormulaControllerOptions);
|
|
59
|
+
/** Stored HTML → editing view. `refreshImages` regenerates every formula image (pasted content). */
|
|
60
|
+
toEditingHtml(html: string, refreshImages: boolean): string;
|
|
61
|
+
/** Editing view → stored HTML for the configured save mode. */
|
|
62
|
+
toSavedHtml(html: string): string;
|
|
63
|
+
isFormula(node: unknown): node is HTMLImageElement;
|
|
64
|
+
isOpen(): boolean;
|
|
65
|
+
/** Opens the editor for the selected formula, the `$$latex$$` at the caret, or a new formula. */
|
|
66
|
+
open(): void;
|
|
67
|
+
/** Selects a formula image and opens it for editing (double-click). */
|
|
68
|
+
editFormula(img: HTMLImageElement): void;
|
|
69
|
+
/** Regenerates images measured before the math font loaded; call once the editor content is ready. */
|
|
70
|
+
refreshStaleImages(): void;
|
|
71
|
+
destroy(): void;
|
|
72
|
+
private readImage;
|
|
73
|
+
private currentTarget;
|
|
74
|
+
private ensureModal;
|
|
75
|
+
private commit;
|
|
76
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { type ContentContext, DEFAULT_HOST_CONVENTIONS, type HostConventions, type LatexRange, type ParsedFormula, formulaImageAttributes, isEmptyFormula, isFormulaImage, latexAtCaret, readFormula, toEditingHtml, toSavedHtml, } from './content.js';
|
|
2
|
+
export { type AttributeUpdates, type EditorAdapter, FORMULA_ICON_SVG, FormulaController, type FormulaControllerOptions } from './controller.js';
|
|
3
|
+
export { DEFAULT_IMAGE_CLASS, DEFAULT_MATHML_ATTRIBUTE, type FormulaComposerOptions, type ResolvedOptions, type SaveMode, type SylarWirisOptions, resolveOptions, } from './options.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var z=Object.defineProperty;var X=(t,e,n)=>e in t?z(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var p=(t,e,n)=>X(t,typeof e!="symbol"?e+"":e,n);import{encodeSafeXml as y,parseLatex as W,parseMathML as j,sanitizeMathDocument as O,serializeMathML as R,toAccessibleText as G}from"../math-core/index.js";import{createFormulaImage as V,toBase64DataUri as Z}from"../renderer/index.js";var k="data:image/svg+xml;charset=utf8,",q="data:image/svg+xml",K=/\u00ABmath[\s\S]*?\u00AB\/math\u00BB/g,T=/\$\$([\s\S]+?)\$\$/g,Q="LaTeX",J="script, style, textarea, code, pre, title",Y=256,tt={internalAttributePrefix:"data-sw-",staleAttribute:"data-sw-stale",imageAttributes:{}},A=new Map;function g(t){let e=A.get(t);if(e!==void 0)return e;let n;try{let o=j(t),r=O(o.doc);n={doc:r,mathml:R(r),latex:o.latex}}catch{n=null}return A.size>=Y&&A.clear(),A.set(t,n),n}function b(t){return t.doc.root.children.length===0}function h(t,e){let{options:n}=e,o=V(t.doc,e.doc,{fontSize:n.imageFontSize}),r={class:n.imageClassName,src:o.dataUri,[n.imageMathmlAttribute]:y(t.mathml),width:String(o.width),height:String(o.height),role:"math",align:"middle",style:`max-width: none; vertical-align: ${o.verticalAlign}px;`,...e.conventions.imageAttributes};return n.accessibility&&(r.alt=G(t.doc)),e.fontLoaded||(r[e.conventions.staleAttribute]="true"),r}function v(t){return`img.${t.imageClassName}[${t.imageMathmlAttribute}]`}function et(t){return typeof t=="object"&&t!==null&&"nodeType"in t&&t.nodeType===Node.ELEMENT_NODE}function _(t){return typeof t=="object"&&t!==null&&"nodeType"in t&&t.nodeType===Node.TEXT_NODE}function E(t,e){return et(t)&&t.matches(v(e))}function N(t,e){for(let[n,o]of Object.entries(e))t.setAttribute(n,o)}function nt(t,e){let n=e.doc.createElement("img");return N(n,h(t,e)),n}function I(t,e){let n=e.options.parseLatex?t.latex:null;return n!==null?e.doc.createTextNode(`$$${n}$$`):nt(t,e)}function H(t,e){let n=e.createElement("template");return n.innerHTML=t,n}function $(t,e){let n=e.createTreeWalker(t,NodeFilter.SHOW_TEXT),o=[];for(let r=n.nextNode();r;r=n.nextNode())_(r)&&!r.parentElement?.closest(J)&&o.push(r);return o}function w(t,e,n){let o=t.data,r=[],a=0,u=!1;e.lastIndex=0;for(let i=e.exec(o);i;i=e.exec(o)){let c=n(i);c&&(i.index>a&&r.push(t.ownerDocument.createTextNode(o.slice(a,i.index))),r.push(c),a=i.index+i[0].length,u=!0)}return u?(a<o.length&&r.push(t.ownerDocument.createTextNode(o.slice(a))),t.replaceWith(...r),!0):!1}var ot=/<math[\s>/]|\u00ABmath/i;function S(t,e,n){let{options:o,doc:r}=e;if(!ot.test(t)&&!t.includes(o.imageClassName))return t;let a=H(t,r),u=a.content,i=!1,c=new XMLSerializer;for(let s of[...u.querySelectorAll("math")]){if(!u.contains(s))continue;let d=g(c.serializeToString(s));d&&(s.replaceWith(I(d,e)),i=!0)}for(let s of $(u,r))s.data.includes("\xABmath")&&(i=w(s,K,d=>{let l=g(d[0]);return l?I(l,e):null})||i);let f=o.parseLatex&&t.includes(Q);for(let s of u.querySelectorAll(v(o))){if(f){let m=g(s.getAttribute(o.imageMathmlAttribute)??"")?.latex??null;if(m!==null){s.replaceWith(r.createTextNode(`$$${m}$$`)),i=!0;continue}}let d=s.getAttribute("src")??"";if(!n&&d.startsWith(q)&&!s.hasAttribute(e.conventions.staleAttribute)){for(let[m,x]of Object.entries(e.conventions.imageAttributes))s.getAttribute(m)!==x&&(s.setAttribute(m,x),i=!0);continue}let l=g(s.getAttribute(o.imageMathmlAttribute)??"");l&&(N(s,h(l,e)),e.fontLoaded&&s.removeAttribute(e.conventions.staleAttribute),i=!0)}return i?a.innerHTML:t}function rt(t){if(!t.startsWith(k))return t;try{return Z(decodeURIComponent(t.slice(k.length)))}catch{return t}}function at(t,e,n){let{options:o,conventions:r}=n;for(let a of t.getAttributeNames())a.startsWith(r.internalAttributePrefix)&&t.removeAttribute(a);t.setAttribute(o.imageMathmlAttribute,y(e.mathml)),o.saveMode==="base64"&&t.setAttribute("src",rt(t.getAttribute("src")??""))}function it(t){try{return R(O(W(t)),{latexAnnotation:t})}catch{return null}}function L(t,e){let{options:n,doc:o}=e,r=n.parseLatex&&t.includes("$$");if(!r&&!t.includes(n.imageClassName))return t;let a=H(t,o),u=a.content,i=[],c=Math.random().toString(36).slice(2),f=l=>(i.push(l),o.createComment(`sw-${c}-${i.length-1}`)),s=!1;for(let l of[...u.querySelectorAll(v(n))]){let m=g(l.getAttribute(n.imageMathmlAttribute)??"");m&&(n.saveMode==="xml"?l.replaceWith(f(m.mathml)):n.saveMode==="safeXml"?l.replaceWith(f(y(m.mathml))):at(l,m,e),s=!0)}if(r)for(let l of $(u,o))l.data.includes("$$")&&(s=w(l,T,m=>{let x=it(m[1]??"");return x===null?null:f(n.saveMode==="safeXml"?y(x):x)})||s);if(!s)return t;let d=a.innerHTML;return i.forEach((l,m)=>{d=d.split(`<!--sw-${c}-${m}-->`).join(l)}),d}function C(t){let e=t.startContainer;if(!t.collapsed||!_(e))return null;T.lastIndex=0;for(let n=T.exec(e.data);n;n=T.exec(e.data)){let o=n.index+n[0].length;if(t.startOffset>n.index&&t.startOffset<o)return{text:e,start:n.index,end:o,latex:n[1]??""}}return null}import{MathModal as st,getStrings as lt}from"../editor-ui/index.js";import{ensureMathFont as ut}from"../renderer/index.js";var mt='<svg width="24" height="24" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M3 13h3l3 7 5-15h7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M14.5 11l5 6m0-6l-5 6" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>';function dt(t){return t.text.isConnected&&t.text.data.slice(t.start,t.end)===`$$${t.latex}$$`}var F=class{constructor(e,{options:n,conventions:o}){p(this,"adapter",e);p(this,"options");p(this,"strings");p(this,"ctx");p(this,"modal",null);p(this,"target",{kind:"new",bookmark:null});p(this,"destroyed",!1);this.options=n,this.strings=lt(n.language,n.strings),this.ctx={options:n,conventions:o,doc:e.uiDocument,fontLoaded:!1},ut(e.uiDocument).then(()=>{this.ctx.fontLoaded=!0,this.refreshStaleImages()})}toEditingHtml(e,n){return S(e,this.ctx,n)}toSavedHtml(e){return L(e,this.ctx)}isFormula(e){return E(e,this.options)}isOpen(){return this.modal?.isOpen??!1}open(){if(this.destroyed||!this.adapter.canEdit())return;let e=this.ensureModal();if(e.isOpen){if(e.editor.hasChanges()){e.currentState==="minimized"&&e.setState("stack"),e.editor.focus();return}e.close()}this.target=this.currentTarget(),this.target.kind==="image"?e.open({mathml:this.readImage(this.target.img)?.mathml??""}):this.target.kind==="latex"?e.open({latex:this.target.range.latex}):e.open()}editFormula(e){this.adapter.selectFormula(e),this.open()}refreshStaleImages(){if(this.destroyed||!this.ctx.fontLoaded)return;let e=this.adapter.getContentRoot();if(!e)return;let n=this.ctx.conventions.staleAttribute,o=[];for(let r of e.querySelectorAll(`img[${n}]`)){let a=this.readImage(r);a&&o.push([r,{...h(a,this.ctx),[n]:null}])}o.length>0&&this.adapter.refreshFormulas(o)}destroy(){this.destroyed=!0,this.modal?.destroy(),this.modal=null}readImage(e){return g(e.getAttribute(this.options.imageMathmlAttribute)??"")}currentTarget(){let e=this.adapter.getSelectedNode();if(this.isFormula(e))return{kind:"image",img:e};if(this.options.parseLatex){let n=this.adapter.getSelectionRange(),o=n?C(n):null;if(o)return{kind:"latex",range:o}}return{kind:"new",bookmark:this.adapter.saveSelection()}}ensureModal(){return this.modal??(this.modal=new st(this.adapter.uiDocument.body,{language:this.options.language,strings:this.options.strings,tabs:this.options.toolbar,latexToggle:this.options.latexToggle,fullScreen:this.options.openFullScreen,rtl:this.adapter.isRtl(),onInsert:(e,n)=>this.commit(e,n),onClose:()=>{this.destroyed||this.adapter.focus()}})),this.modal}commit(e,n){let o=g(e);if(!o)return!1;let r=this.target;if(this.target={kind:"new",bookmark:null},this.adapter.focus(),r.kind==="latex"&&dt(r.range)){let{text:a,start:u,end:i,latex:c}=r.range,f=b(o)?"":`$$${n.hasChanges()?n.getLatex():c}$$`;return this.adapter.replaceText(a,u,i,f),!0}if(r.kind==="image"&&r.img.isConnected){if(b(o))this.adapter.removeFormula(r.img);else{let a=this.ctx.conventions.staleAttribute;this.adapter.updateFormula(r.img,{alt:null,[a]:null,...h(o,this.ctx)})}return!0}return b(o)||this.adapter.insertFormula(h(o,this.ctx),r.kind==="new"?r.bookmark:null),!0}};import{TOOLBAR_CATALOG as ct,normalizeLanguage as gt}from"../editor-ui/index.js";var B="Wirisformula",U="data-mathml",pt=16,ft=6,ht=96,xt=["xml","safeXml","image","base64"],bt=/^[A-Za-z_][A-Za-z0-9_-]*$/,At=/^data-[a-z0-9][a-z0-9._-]*$/,Tt=new Set(ct.map(t=>t.id));function P(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function M(t,e){return typeof t=="boolean"?t:e}function D(t,e,n){return typeof t=="string"&&e.test(t)?t:n}function yt(t){if(!Array.isArray(t))return;let e=t.filter(n=>typeof n=="string"&&Tt.has(n));return e.length>0?e:void 0}function Mt(t){if(!P(t))return;let e={};for(let[n,o]of Object.entries(t))typeof o=="string"&&(e[n]=o);return e}function vt(t,e){let n=P(t)?t:{},o=xt.find(u=>u===n.saveMode)??"xml",r=n.imageFontSize,a=typeof n.language=="string"?n.language:typeof e=="string"?e:"en";return{saveMode:o,parseLatex:M(n.parseLatex,!0),imageClassName:D(n.imageClassName,bt,B),imageMathmlAttribute:D(n.imageMathmlAttribute,At,U),accessibility:M(n.accessibility,!0),openFullScreen:M(n.openFullScreen,!1),language:gt(a),toolbar:yt(n.toolbar),strings:Mt(n.strings),imageFontSize:typeof r=="number"&&r>=ft&&r<=ht?r:pt,latexToggle:M(n.latexToggle,!0)}}export{tt as DEFAULT_HOST_CONVENTIONS,B as DEFAULT_IMAGE_CLASS,U as DEFAULT_MATHML_ATTRIBUTE,mt as FORMULA_ICON_SVG,F as FormulaController,h as formulaImageAttributes,b as isEmptyFormula,E as isFormulaImage,C as latexAtCaret,g as readFormula,vt as resolveOptions,S as toEditingHtml,L as toSavedHtml};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type StringOverrides, type TabId } from '../editor-ui/index';
|
|
2
|
+
export type SaveMode = 'xml' | 'safeXml' | 'image' | 'base64';
|
|
3
|
+
/** Integration options (TinyMCE: the `formulaComposer` init option). Every field is optional. */
|
|
4
|
+
export interface FormulaComposerOptions {
|
|
5
|
+
/** Output of `getContent` (CFG-001). Default `xml`. */
|
|
6
|
+
saveMode?: SaveMode;
|
|
7
|
+
/** Convert `$$latex$$` text to MathML on save and MathML with a LaTeX annotation back to text on load (CFG-003). Default true. */
|
|
8
|
+
parseLatex?: boolean;
|
|
9
|
+
/** Class of formula images (CFG-004). Default `Wirisformula`, so existing MathType content keeps working. */
|
|
10
|
+
imageClassName?: string;
|
|
11
|
+
/** `data-*` attribute holding safe-XML MathML (CFG-005). Default `data-mathml`. */
|
|
12
|
+
imageMathmlAttribute?: string;
|
|
13
|
+
/** Generate `alt` text (CFG-006). Default true. */
|
|
14
|
+
accessibility?: boolean;
|
|
15
|
+
/** Open the editor maximized (CFG-009). Default false. */
|
|
16
|
+
openFullScreen?: boolean;
|
|
17
|
+
/** UI language; defaults to the host editor's language (TinyMCE `language`, CFG-018). */
|
|
18
|
+
language?: string;
|
|
19
|
+
/** Toolbar tabs to show, in order (CFG-011). Default all. */
|
|
20
|
+
toolbar?: readonly TabId[];
|
|
21
|
+
/** Overrides for UI strings. */
|
|
22
|
+
strings?: StringOverrides;
|
|
23
|
+
/** Formula image font size in CSS pixels. Default 16. */
|
|
24
|
+
imageFontSize?: number;
|
|
25
|
+
/** Show the LaTeX toggle. Default true. */
|
|
26
|
+
latexToggle?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** @deprecated Use {@link FormulaComposerOptions}. */
|
|
29
|
+
export type SylarWirisOptions = FormulaComposerOptions;
|
|
30
|
+
export interface ResolvedOptions {
|
|
31
|
+
saveMode: SaveMode;
|
|
32
|
+
parseLatex: boolean;
|
|
33
|
+
imageClassName: string;
|
|
34
|
+
imageMathmlAttribute: string;
|
|
35
|
+
accessibility: boolean;
|
|
36
|
+
openFullScreen: boolean;
|
|
37
|
+
language: string;
|
|
38
|
+
toolbar: readonly TabId[] | undefined;
|
|
39
|
+
strings: StringOverrides | undefined;
|
|
40
|
+
imageFontSize: number;
|
|
41
|
+
latexToggle: boolean;
|
|
42
|
+
}
|
|
43
|
+
export declare const DEFAULT_IMAGE_CLASS = "Wirisformula";
|
|
44
|
+
export declare const DEFAULT_MATHML_ATTRIBUTE = "data-mathml";
|
|
45
|
+
/** Validates the raw option value; invalid fields fall back to their defaults. */
|
|
46
|
+
export declare function resolveOptions(raw: unknown, editorLanguage: unknown): ResolvedOptions;
|