@ones-editor/editor 0.0.9-beta.7 → 0.0.9-beta.8
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/dist/index.js
CHANGED
|
@@ -2126,8 +2126,8 @@ div.editor-root:not(.readonly) div.editor-content div[data-type=editor-container
|
|
|
2126
2126
|
div.editor-root div.editor-content div[data-type=editor-container] div[data-type=editor-block] div[data-type=block-content] > span.math-box .mathjax-tex-text.mathjax-error {
|
|
2127
2127
|
color: var(--color-0);
|
|
2128
2128
|
}
|
|
2129
|
-
div.editor-root div.editor-content div[data-type=editor-container]
|
|
2130
|
-
|
|
2129
|
+
div.editor-root div.editor-content div[data-type=editor-container] .embed-block.selected[data-embed-type=math] > div[data-type=block-content].mathjax-overflow::before {
|
|
2130
|
+
width: var(--mathjax-width, "100%");
|
|
2131
2131
|
}
|
|
2132
2132
|
div.editor-root div.editor-content div[data-type=editor-container] .embed-block[data-embed-type=math] > div[data-type=block-content] {
|
|
2133
2133
|
align-items: center;
|
|
@@ -44165,6 +44165,8 @@ var __publicField = (obj, key, value) => {
|
|
|
44165
44165
|
}
|
|
44166
44166
|
const logger$1x = getLogger("mathjax-converter");
|
|
44167
44167
|
const MATHJAX_SCRIPT_ID = "MathJax-script";
|
|
44168
|
+
const MATHJAX_BUFFER = 30;
|
|
44169
|
+
const REDUCED_UNIT = 8;
|
|
44168
44170
|
async function initMathjax(editor) {
|
|
44169
44171
|
var _a;
|
|
44170
44172
|
if (!window.MathJax) {
|
|
@@ -44216,6 +44218,23 @@ var __publicField = (obj, key, value) => {
|
|
|
44216
44218
|
lockers.release(lockId);
|
|
44217
44219
|
}
|
|
44218
44220
|
}
|
|
44221
|
+
function analyzeMathjaxSvgWidth(svg) {
|
|
44222
|
+
const dom = new DOMParser().parseFromString(svg, "image/svg+xml");
|
|
44223
|
+
const expect = {
|
|
44224
|
+
width: 0,
|
|
44225
|
+
height: 0
|
|
44226
|
+
};
|
|
44227
|
+
if (dom && dom.firstChild) {
|
|
44228
|
+
const svgElement = dom.firstChild;
|
|
44229
|
+
const height = svgElement.getAttribute("height");
|
|
44230
|
+
const width = svgElement.style.minWidth;
|
|
44231
|
+
if (height) {
|
|
44232
|
+
expect.width = parseInt(width, 10) * REDUCED_UNIT + MATHJAX_BUFFER;
|
|
44233
|
+
expect.height = parseInt(height, 10) * REDUCED_UNIT;
|
|
44234
|
+
}
|
|
44235
|
+
}
|
|
44236
|
+
return expect;
|
|
44237
|
+
}
|
|
44219
44238
|
async function mathjax2DataUrl(editor, tex) {
|
|
44220
44239
|
const svg = await mathjax2Svg(editor, tex);
|
|
44221
44240
|
if (!svg)
|
|
@@ -44230,6 +44249,17 @@ var __publicField = (obj, key, value) => {
|
|
|
44230
44249
|
const path = await editor.doc.uploadResource(file2);
|
|
44231
44250
|
return path.resourceId;
|
|
44232
44251
|
}
|
|
44252
|
+
async function convertAndUploadMathjaxForEmbed(editor, tex) {
|
|
44253
|
+
const svg = await mathjax2Svg(editor, tex);
|
|
44254
|
+
const perfectState = analyzeMathjaxSvgWidth(svg);
|
|
44255
|
+
const data = svg;
|
|
44256
|
+
const file2 = new File([data], "math.svg");
|
|
44257
|
+
const path = await editor.doc.uploadResource(file2);
|
|
44258
|
+
return {
|
|
44259
|
+
resourceId: path.resourceId,
|
|
44260
|
+
...perfectState
|
|
44261
|
+
};
|
|
44262
|
+
}
|
|
44233
44263
|
const logger$1w = getLogger("edit-mathjax");
|
|
44234
44264
|
class MathjaxEditor {
|
|
44235
44265
|
constructor() {
|
|
@@ -44262,15 +44292,17 @@ var __publicField = (obj, key, value) => {
|
|
|
44262
44292
|
(_a = this.onChange) == null ? void 0 : _a.call(this, text2, false);
|
|
44263
44293
|
}, 300));
|
|
44264
44294
|
}
|
|
44265
|
-
editMathjax(elem, tex, onChange) {
|
|
44295
|
+
editMathjax(elem, tex, onChange, options) {
|
|
44266
44296
|
if (!this.editMathjaxPopup) {
|
|
44267
|
-
this.editMathjaxPopup = new Popup(this.createPopupContent(tex)
|
|
44297
|
+
this.editMathjaxPopup = new Popup(this.createPopupContent(tex), {
|
|
44298
|
+
id: "mathjax-popover"
|
|
44299
|
+
});
|
|
44268
44300
|
} else {
|
|
44269
44301
|
const textarea2 = this.getTextarea();
|
|
44270
44302
|
textarea2.value = tex;
|
|
44271
44303
|
}
|
|
44272
44304
|
this.tex = tex;
|
|
44273
|
-
this.editMathjaxPopup.manualShow(elem, { theme: "light" });
|
|
44305
|
+
this.editMathjaxPopup.manualShow(elem, { theme: "light", placement: options == null ? void 0 : options.placement });
|
|
44274
44306
|
this.editMathjaxPopup.removeAllListeners("close");
|
|
44275
44307
|
this.editMathjaxPopup.addListener("close", this.handleClose);
|
|
44276
44308
|
this.onChange = onChange;
|
|
@@ -44311,9 +44343,9 @@ var __publicField = (obj, key, value) => {
|
|
|
44311
44343
|
(_b = this.editMathjaxPopup) == null ? void 0 : _b.removeAllListeners();
|
|
44312
44344
|
}
|
|
44313
44345
|
}
|
|
44314
|
-
function editMathjax(editor, elem, tex, onChange) {
|
|
44346
|
+
function editMathjax(editor, elem, tex, onChange, options) {
|
|
44315
44347
|
const mathjaxEditor = editor.addCustom("mathjax-editor", () => new MathjaxEditor());
|
|
44316
|
-
mathjaxEditor.editMathjax(elem, tex.trim(), onChange);
|
|
44348
|
+
mathjaxEditor.editMathjax(elem, tex.trim(), onChange, options);
|
|
44317
44349
|
}
|
|
44318
44350
|
function createEmptyMathjaxBox() {
|
|
44319
44351
|
const id = genId();
|
|
@@ -44526,25 +44558,45 @@ var __publicField = (obj, key, value) => {
|
|
|
44526
44558
|
const data = editor.getBlockData(block);
|
|
44527
44559
|
const embedData = data.embedData;
|
|
44528
44560
|
editMathjax(editor, elem, embedData.mathjaxText, async (tex) => {
|
|
44529
|
-
const src = await
|
|
44561
|
+
const { resourceId: src, width, height } = await convertAndUploadMathjaxForEmbed(editor, tex);
|
|
44530
44562
|
const newData = {
|
|
44531
44563
|
mathjaxText: tex,
|
|
44532
|
-
src
|
|
44564
|
+
src,
|
|
44565
|
+
width,
|
|
44566
|
+
height
|
|
44533
44567
|
};
|
|
44534
44568
|
editor.updateEmbedData(block, newData);
|
|
44569
|
+
}, {
|
|
44570
|
+
placement: "bottom"
|
|
44535
44571
|
});
|
|
44536
44572
|
}
|
|
44537
44573
|
function createEmbedContent$9(editor, content, block) {
|
|
44538
44574
|
const mathData = block.embedData;
|
|
44575
|
+
const { src, width } = mathData;
|
|
44539
44576
|
const state = editor.addCustom(`mathjax-block-${block.id}`, () => new MathjaxStateData());
|
|
44540
44577
|
editor.domEvents.addEventListener(content, "click", handleClickContent);
|
|
44541
44578
|
if (!mathData.mathjaxText.trim()) {
|
|
44542
44579
|
createElement("span", ["mathjax-tex-text"], content, i18n$1.t("mathjax.emptyText"));
|
|
44543
44580
|
return;
|
|
44544
44581
|
}
|
|
44545
|
-
if (
|
|
44582
|
+
if (src || state.dataUrl) {
|
|
44546
44583
|
const img = createElement("img", ["mathjax"], content);
|
|
44547
|
-
img.src = editor.doc.buildResourceUrl(
|
|
44584
|
+
img.src = editor.doc.buildResourceUrl(src || state.dataUrl);
|
|
44585
|
+
if (width) {
|
|
44586
|
+
img.style.minWidth = `${width}px`;
|
|
44587
|
+
setTimeout(() => {
|
|
44588
|
+
const contentWidth = content.getBoundingClientRect().width;
|
|
44589
|
+
if (width > contentWidth) {
|
|
44590
|
+
addClass(content, "mathjax-overflow");
|
|
44591
|
+
content.style.overflow = "auto";
|
|
44592
|
+
content.style.setProperty("--mathjax-width", `${width}px`);
|
|
44593
|
+
} else {
|
|
44594
|
+
removeClass(content, "mathjax-overflow");
|
|
44595
|
+
content.removeAttribute("data-mathjax-width");
|
|
44596
|
+
content.style.removeProperty("--mathjax-width");
|
|
44597
|
+
}
|
|
44598
|
+
});
|
|
44599
|
+
}
|
|
44548
44600
|
return;
|
|
44549
44601
|
}
|
|
44550
44602
|
if (state.error)
|