", "");
+ }
+ });
+ if (tocHTML === "") {
+ targetElement.innerHTML = "";
+ return "";
+ }
+ var tempElement = document.createElement("div");
+ if (vditor) {
+ vditor.lute.SetToC(true);
+ if (vditor.currentMode === "wysiwyg" && !vditor.preview.element.contains(contentElement)) {
+ tempElement.innerHTML = vditor.lute.SpinVditorDOM("[ToC]
" + tocHTML);
+ }
+ else if (vditor.currentMode === "ir" && !vditor.preview.element.contains(contentElement)) {
+ tempElement.innerHTML = vditor.lute.SpinVditorIRDOM("[ToC]
" + tocHTML);
+ }
+ else {
+ tempElement.innerHTML = vditor.lute.HTML2VditorDOM("[ToC]
" + tocHTML);
+ }
+ vditor.lute.SetToC(vditor.options.preview.markdown.toc);
+ }
+ else {
+ targetElement.classList.add("vditor-outline");
+ var lute = Lute.New();
+ lute.SetToC(true);
+ tempElement.innerHTML = lute.HTML2VditorDOM("[ToC]
" + tocHTML);
+ }
+ var headingsElement = tempElement.firstElementChild.querySelectorAll("li > span[data-target-id]");
+ headingsElement.forEach(function (item, index) {
+ if (item.nextElementSibling && item.nextElementSibling.tagName === "UL") {
+ var iconHTML = "";
+ if (!document.getElementById("vditorIconScript")) {
+ iconHTML = '';
+ }
+ item.innerHTML = "".concat(iconHTML, "").concat(item.innerHTML, "");
+ }
+ else {
+ item.innerHTML = "".concat(item.innerHTML, "");
+ }
+ item.setAttribute("data-target-id", ids[index]);
+ });
+ tocHTML = tempElement.firstElementChild.innerHTML;
+ if (headingsElement.length === 0) {
+ targetElement.innerHTML = "";
+ return tocHTML;
+ }
+ targetElement.innerHTML = tocHTML;
+ if (vditor) {
+ (0,_mathRender__WEBPACK_IMPORTED_MODULE_0__/* .mathRender */ .H)(targetElement, {
+ cdn: vditor.options.cdn,
+ math: vditor.options.preview.math,
+ });
+ }
+ targetElement.firstElementChild.addEventListener("click", function (event) {
+ var target = event.target;
+ while (target && !target.isEqualNode(targetElement)) {
+ if (target.classList.contains("vditor-outline__action")) {
+ if (target.classList.contains("vditor-outline__action--close")) {
+ target.classList.remove("vditor-outline__action--close");
+ target.parentElement.nextElementSibling.setAttribute("style", "display:block");
+ }
+ else {
+ target.classList.add("vditor-outline__action--close");
+ target.parentElement.nextElementSibling.setAttribute("style", "display:none");
+ }
+ event.preventDefault();
+ event.stopPropagation();
+ break;
+ }
+ else if (target.getAttribute("data-target-id")) {
+ event.preventDefault();
+ event.stopPropagation();
+ var idElement = document.getElementById(target.getAttribute("data-target-id"));
+ if (!idElement) {
+ return;
+ }
+ if (vditor) {
+ if (vditor.options.height === "auto") {
+ var windowScrollY = idElement.offsetTop + vditor.element.offsetTop;
+ if (!vditor.options.toolbarConfig.pin) {
+ windowScrollY += vditor.toolbar.element.offsetHeight;
+ }
+ window.scrollTo(window.scrollX, windowScrollY);
+ }
+ else {
+ if (vditor.element.offsetTop < window.scrollY) {
+ window.scrollTo(window.scrollX, vditor.element.offsetTop);
+ }
+ if (vditor.preview.element.contains(contentElement)) {
+ contentElement.parentElement.scrollTop = idElement.offsetTop;
+ }
+ else {
+ contentElement.scrollTop = idElement.offsetTop;
+ }
+ }
+ }
+ else {
+ window.scrollTo(window.scrollX, idElement.offsetTop);
+ }
+ break;
+ }
+ target = target.parentElement;
+ }
+ });
+ return tocHTML;
+};
+
+
+/***/ }),
+
+/***/ 229:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "B": () => (/* binding */ plantumlRender)
+/* harmony export */ });
+/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(145);
+/* harmony import */ var _util_addScript__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(413);
+/* harmony import */ var _adapterRender__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(840);
+
+
+
+var plantumlRender = function (element, cdn) {
+ if (element === void 0) { element = document; }
+ if (cdn === void 0) { cdn = _constants__WEBPACK_IMPORTED_MODULE_0__/* .Constants.CDN */ .g.CDN; }
+ var plantumlElements = _adapterRender__WEBPACK_IMPORTED_MODULE_1__.plantumlRenderAdapter.getElements(element);
+ if (plantumlElements.length === 0) {
+ return;
+ }
+ (0,_util_addScript__WEBPACK_IMPORTED_MODULE_2__/* .addScript */ .G)("".concat(cdn, "/dist/js/plantuml/plantuml-encoder.min.js"), "vditorPlantumlScript").then(function () {
+ plantumlElements.forEach(function (e) {
+ if (e.parentElement.classList.contains("vditor-wysiwyg__pre") ||
+ e.parentElement.classList.contains("vditor-ir__marker--pre")) {
+ return;
+ }
+ var text = _adapterRender__WEBPACK_IMPORTED_MODULE_1__.plantumlRenderAdapter.getCode(e).trim();
+ if (!text) {
+ return;
+ }
+ try {
+ e.innerHTML = "");
+ }
+ catch (error) {
+ e.className = "vditor-reset--error";
+ e.innerHTML = "plantuml render error:
".concat(error);
+ }
+ });
+ });
+};
+
+
+/***/ }),
+
+/***/ 214:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "X": () => (/* binding */ setLute)
+/* harmony export */ });
+var setLute = function (options) {
+ var lute = Lute.New();
+ lute.PutEmojis(options.emojis);
+ lute.SetEmojiSite(options.emojiSite);
+ lute.SetHeadingAnchor(options.headingAnchor);
+ lute.SetInlineMathAllowDigitAfterOpenMarker(options.inlineMathDigit);
+ lute.SetAutoSpace(options.autoSpace);
+ lute.SetToC(options.toc);
+ lute.SetFootnotes(options.footnotes);
+ lute.SetFixTermTypo(options.fixTermTypo);
+ lute.SetVditorCodeBlockPreview(options.codeBlockPreview);
+ lute.SetVditorMathBlockPreview(options.mathBlockPreview);
+ lute.SetSanitize(options.sanitize);
+ lute.SetChineseParagraphBeginningSpace(options.paragraphBeginningSpace);
+ lute.SetRenderListStyle(options.listStyle);
+ lute.SetLinkBase(options.linkBase);
+ lute.SetLinkPrefix(options.linkPrefix);
+ lute.SetMark(options.mark);
+ lute.SetGFMAutoLink(options.gfmAutoLink);
+ if (options.lazyLoadImage) {
+ lute.SetImageLazyLoading(options.lazyLoadImage);
+ }
+ return lute;
+};
+
+
+/***/ }),
+
+/***/ 190:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "E": () => (/* binding */ previewImage)
+/* harmony export */ });
+var previewImage = function (oldImgElement, lang, theme) {
+ if (lang === void 0) { lang = "zh_CN"; }
+ if (theme === void 0) { theme = "classic"; }
+ var oldImgRect = oldImgElement.getBoundingClientRect();
+ var height = 36;
+ document.body.insertAdjacentHTML("beforeend", "\n
\n \n \n ").concat(window.VditorI18n.spin, "\n \n \n X ").concat(window.VditorI18n.close, "\n \n
\n
\n
.concat(oldImgElement.getAttribute("src"),)
\n
\n
"));
+ document.body.style.overflow = "hidden";
+ // 图片从原始位置移动到预览正中间的动画效果
+ var imgElement = document.querySelector(".vditor-img img");
+ var translate3d = "translate3d(".concat(Math.max(0, window.innerWidth - oldImgElement.naturalWidth) / 2, "px, ").concat(Math.max(0, window.innerHeight - height - oldImgElement.naturalHeight) / 2, "px, 0)");
+ setTimeout(function () {
+ imgElement.setAttribute("style", "transition: transform .3s ease-in-out;transform: ".concat(translate3d));
+ setTimeout(function () {
+ imgElement.parentElement.scrollTo((imgElement.parentElement.scrollWidth - imgElement.parentElement.clientWidth) / 2, (imgElement.parentElement.scrollHeight - imgElement.parentElement.clientHeight) / 2);
+ }, 400);
+ });
+ // 旋转
+ var btnElement = document.querySelector(".vditor-img__btn");
+ btnElement.addEventListener("click", function () {
+ var deg = parseInt(btnElement.getAttribute("data-deg"), 10) + 90;
+ if ((deg / 90) % 2 === 1 && oldImgElement.naturalWidth > imgElement.parentElement.clientHeight) {
+ imgElement.style.transform = "translate3d(".concat(Math.max(0, window.innerWidth - oldImgElement.naturalWidth) / 2, "px, ").concat(oldImgElement.naturalWidth / 2 - oldImgElement.naturalHeight / 2, "px, 0) rotateZ(").concat(deg, "deg)");
+ }
+ else {
+ imgElement.style.transform = "".concat(translate3d, " rotateZ(").concat(deg, "deg)");
+ }
+ btnElement.setAttribute("data-deg", deg.toString());
+ setTimeout(function () {
+ imgElement.parentElement.scrollTo((imgElement.parentElement.scrollWidth - imgElement.parentElement.clientWidth) / 2, (imgElement.parentElement.scrollHeight - imgElement.parentElement.clientHeight) / 2);
+ }, 400);
+ });
+};
+
+
+/***/ }),
+
+/***/ 580:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "Y": () => (/* binding */ setCodeTheme)
+/* harmony export */ });
+/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(145);
+/* harmony import */ var _util_addStyle__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(290);
+
+
+var setCodeTheme = function (codeTheme, cdn) {
+ if (cdn === void 0) { cdn = _constants__WEBPACK_IMPORTED_MODULE_0__/* .Constants.CDN */ .g.CDN; }
+ if (!_constants__WEBPACK_IMPORTED_MODULE_0__/* .Constants.CODE_THEME.includes */ .g.CODE_THEME.includes(codeTheme)) {
+ codeTheme = "github";
+ }
+ var vditorHljsStyle = document.getElementById("vditorHljsStyle");
+ var href = "".concat(cdn, "/dist/js/highlight.js/styles/").concat(codeTheme, ".min.css");
+ if (!vditorHljsStyle) {
+ (0,_util_addStyle__WEBPACK_IMPORTED_MODULE_1__/* .addStyle */ .c)(href, "vditorHljsStyle");
+ }
+ else if (vditorHljsStyle.getAttribute('href') !== href) {
+ vditorHljsStyle.remove();
+ (0,_util_addStyle__WEBPACK_IMPORTED_MODULE_1__/* .addStyle */ .c)(href, "vditorHljsStyle");
+ }
+};
+
+
+/***/ }),
+
+/***/ 538:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "Z": () => (/* binding */ setContentTheme)
+/* harmony export */ });
+/* harmony import */ var _util_addStyle__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(290);
+
+var setContentTheme = function (contentTheme, path) {
+ if (!contentTheme || !path) {
+ return;
+ }
+ var vditorContentTheme = document.getElementById("vditorContentTheme");
+ var cssPath = "".concat(path, "/").concat(contentTheme, ".css");
+ if (!vditorContentTheme) {
+ (0,_util_addStyle__WEBPACK_IMPORTED_MODULE_0__/* .addStyle */ .c)(cssPath, "vditorContentTheme");
+ }
+ else if (vditorContentTheme.getAttribute("href") !== cssPath) {
+ vditorContentTheme.remove();
+ (0,_util_addStyle__WEBPACK_IMPORTED_MODULE_0__/* .addStyle */ .c)(cssPath, "vditorContentTheme");
+ }
+};
+
+
+/***/ }),
+
+/***/ 413:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "J": () => (/* binding */ addScriptSync),
+/* harmony export */ "G": () => (/* binding */ addScript)
+/* harmony export */ });
+var addScriptSync = function (path, id) {
+ if (document.getElementById(id)) {
+ return false;
+ }
+ var xhrObj = new XMLHttpRequest();
+ xhrObj.open("GET", path, false);
+ xhrObj.setRequestHeader("Accept", "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01");
+ xhrObj.send("");
+ var scriptElement = document.createElement("script");
+ scriptElement.type = "text/javascript";
+ scriptElement.text = xhrObj.responseText;
+ scriptElement.id = id;
+ document.head.appendChild(scriptElement);
+};
+var addScript = function (path, id) {
+ return new Promise(function (resolve, reject) {
+ if (document.getElementById(id)) {
+ // 脚本加载后再次调用直接返回
+ resolve(true);
+ return false;
+ }
+ var scriptElement = document.createElement("script");
+ scriptElement.src = path;
+ scriptElement.async = true;
+ // 循环调用时 Chrome 不会重复请求 js
+ document.head.appendChild(scriptElement);
+ scriptElement.onerror = function (event) {
+ reject(event);
+ };
+ scriptElement.onload = function () {
+ if (document.getElementById(id)) {
+ // 循环调用需清除 DOM 中的 script 标签
+ scriptElement.remove();
+ resolve(true);
+ return false;
+ }
+ scriptElement.id = id;
+ resolve(true);
+ };
+ });
+};
+
+
+/***/ }),
+
+/***/ 290:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "c": () => (/* binding */ addStyle)
+/* harmony export */ });
+var addStyle = function (url, id) {
+ if (!document.getElementById(id)) {
+ var styleElement = document.createElement("link");
+ styleElement.id = id;
+ styleElement.rel = "stylesheet";
+ styleElement.type = "text/css";
+ styleElement.href = url;
+ document.getElementsByTagName("head")[0].appendChild(styleElement);
+ }
+};
+
+
+/***/ }),
+
+/***/ 105:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "X": () => (/* binding */ code160to32)
+/* harmony export */ });
+var code160to32 = function (text) {
+ // 非打断空格转换为空格
+ return text.replace(/\u00a0/g, " ");
+};
+
+
+/***/ }),
+
+/***/ 410:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "G6": () => (/* binding */ isSafari),
+/* harmony export */ "vU": () => (/* binding */ isFirefox),
+/* harmony export */ "pK": () => (/* binding */ accessLocalStorage),
+/* harmony export */ "Le": () => (/* binding */ getEventName),
+/* harmony export */ "yl": () => (/* binding */ isCtrl),
+/* harmony export */ "ns": () => (/* binding */ updateHotkeyTip),
+/* harmony export */ "i7": () => (/* binding */ isChrome)
+/* harmony export */ });
+var isSafari = function () {
+ return navigator.userAgent.indexOf("Safari") > -1 && navigator.userAgent.indexOf("Chrome") === -1;
+};
+var isFirefox = function () {
+ return navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
+};
+var accessLocalStorage = function () {
+ try {
+ return typeof localStorage !== "undefined";
+ }
+ catch (e) {
+ return false;
+ }
+};
+// 用户 iPhone 点击延迟/需要双击的处理
+var getEventName = function () {
+ if (navigator.userAgent.indexOf("iPhone") > -1) {
+ return "touchstart";
+ }
+ else {
+ return "click";
+ }
+};
+// 区别 mac 上的 ctrl 和 meta
+var isCtrl = function (event) {
+ if (navigator.platform.toUpperCase().indexOf("MAC") >= 0) {
+ // mac
+ if (event.metaKey && !event.ctrlKey) {
+ return true;
+ }
+ return false;
+ }
+ else {
+ if (!event.metaKey && event.ctrlKey) {
+ return true;
+ }
+ return false;
+ }
+};
+// Mac,Windows 快捷键展示
+var updateHotkeyTip = function (hotkey) {
+ if (/Mac/.test(navigator.platform) || navigator.platform === "iPhone") {
+ if (hotkey.indexOf("⇧") > -1 && isFirefox()) {
+ // Mac Firefox 按下 shift 后,key 同 windows 系统
+ hotkey = hotkey.replace(";", ":").replace("=", "+").replace("-", "_");
+ }
+ }
+ else {
+ if (hotkey.startsWith("⌘")) {
+ hotkey = hotkey.replace("⌘", "⌘+");
+ }
+ else if (hotkey.startsWith("⌥") && hotkey.substr(1, 1) !== "⌘") {
+ hotkey = hotkey.replace("⌥", "⌥+");
+ }
+ else {
+ hotkey = hotkey.replace("⇧⌘", "⌘+⇧+").replace("⌥⌘", "⌥+⌘+");
+ }
+ hotkey = hotkey.replace("⌘", "Ctrl").replace("⇧", "Shift")
+ .replace("⌥", "Alt");
+ if (hotkey.indexOf("Shift") > -1) {
+ hotkey = hotkey.replace(";", ":").replace("=", "+").replace("-", "_");
+ }
+ }
+ return hotkey;
+};
+var isChrome = function () {
+ return /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
+};
+
+
+/***/ }),
+
+/***/ 494:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "Wb": () => (/* binding */ genUUID),
+/* harmony export */ "on": () => (/* binding */ getSearch),
+/* harmony export */ "Qf": () => (/* binding */ looseJsonParse)
+/* harmony export */ });
+var genUUID = function () { return ([1e7].toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function (c) {
+ return (parseInt(c, 10) ^ (window.crypto.getRandomValues(new Uint32Array(1))[0] & (15 >> (parseInt(c, 10) / 4)))).toString(16);
+}); };
+var getSearch = function (key, link) {
+ if (link === void 0) { link = window.location.search; }
+ var params = link.substring(link.indexOf("?"));
+ var hashIndex = params.indexOf("#");
+ // REF https://developer.mozilla.org/zh-CN/docs/Web/API/URLSearchParams
+ var urlSearchParams = new URLSearchParams(params.substring(0, hashIndex >= 0 ? hashIndex : undefined));
+ return urlSearchParams.get(key);
+};
+var looseJsonParse = function (text) {
+ return Function("\"use strict\";return (".concat(text, ")"))();
+};
+
+
+/***/ }),
+
+/***/ 106:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "JQ": () => (/* binding */ hasTopClosestByClassName),
+/* harmony export */ "E2": () => (/* binding */ hasTopClosestByTag),
+/* harmony export */ "O9": () => (/* binding */ getTopList),
+/* harmony export */ "a1": () => (/* binding */ hasClosestByAttribute),
+/* harmony export */ "F9": () => (/* binding */ hasClosestBlock),
+/* harmony export */ "lG": () => (/* binding */ hasClosestByMatchTag),
+/* harmony export */ "fb": () => (/* binding */ hasClosestByClassName),
+/* harmony export */ "DX": () => (/* binding */ getLastNode)
+/* harmony export */ });
+/* unused harmony export hasTopClosestByAttribute */
+/* harmony import */ var _hasClosestByHeadings__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(771);
+
+var hasTopClosestByClassName = function (element, className) {
+ var closest = hasClosestByClassName(element, className);
+ var parentClosest = false;
+ var findTop = false;
+ while (closest && !closest.classList.contains("vditor-reset") && !findTop) {
+ parentClosest = hasClosestByClassName(closest.parentElement, className);
+ if (parentClosest) {
+ closest = parentClosest;
+ }
+ else {
+ findTop = true;
+ }
+ }
+ return closest || false;
+};
+var hasTopClosestByAttribute = function (element, attr, value) {
+ var closest = hasClosestByAttribute(element, attr, value);
+ var parentClosest = false;
+ var findTop = false;
+ while (closest && !closest.classList.contains("vditor-reset") && !findTop) {
+ parentClosest = hasClosestByAttribute(closest.parentElement, attr, value);
+ if (parentClosest) {
+ closest = parentClosest;
+ }
+ else {
+ findTop = true;
+ }
+ }
+ return closest || false;
+};
+var hasTopClosestByTag = function (element, nodeName) {
+ var closest = (0,_hasClosestByHeadings__WEBPACK_IMPORTED_MODULE_0__/* .hasClosestByTag */ .S)(element, nodeName);
+ var parentClosest = false;
+ var findTop = false;
+ while (closest && !closest.classList.contains("vditor-reset") && !findTop) {
+ parentClosest = (0,_hasClosestByHeadings__WEBPACK_IMPORTED_MODULE_0__/* .hasClosestByTag */ .S)(closest.parentElement, nodeName);
+ if (parentClosest) {
+ closest = parentClosest;
+ }
+ else {
+ findTop = true;
+ }
+ }
+ return closest || false;
+};
+var getTopList = function (element) {
+ var topUlElement = hasTopClosestByTag(element, "UL");
+ var topOlElement = hasTopClosestByTag(element, "OL");
+ var topListElement = topUlElement;
+ if (topOlElement && (!topUlElement || (topUlElement && topOlElement.contains(topUlElement)))) {
+ topListElement = topOlElement;
+ }
+ return topListElement;
+};
+var hasClosestByAttribute = function (element, attr, value) {
+ if (!element) {
+ return false;
+ }
+ if (element.nodeType === 3) {
+ element = element.parentElement;
+ }
+ var e = element;
+ var isClosest = false;
+ while (e && !isClosest && !e.classList.contains("vditor-reset")) {
+ if (e.getAttribute(attr) === value) {
+ isClosest = true;
+ }
+ else {
+ e = e.parentElement;
+ }
+ }
+ return isClosest && e;
+};
+var hasClosestBlock = function (element) {
+ if (!element) {
+ return false;
+ }
+ if (element.nodeType === 3) {
+ element = element.parentElement;
+ }
+ var e = element;
+ var isClosest = false;
+ var blockElement = hasClosestByAttribute(element, "data-block", "0");
+ if (blockElement) {
+ return blockElement;
+ }
+ while (e && !isClosest && !e.classList.contains("vditor-reset")) {
+ if (e.tagName === "H1" ||
+ e.tagName === "H2" ||
+ e.tagName === "H3" ||
+ e.tagName === "H4" ||
+ e.tagName === "H5" ||
+ e.tagName === "H6" ||
+ e.tagName === "P" ||
+ e.tagName === "BLOCKQUOTE" ||
+ e.tagName === "OL" ||
+ e.tagName === "UL") {
+ isClosest = true;
+ }
+ else {
+ e = e.parentElement;
+ }
+ }
+ return isClosest && e;
+};
+var hasClosestByMatchTag = function (element, nodeName) {
+ if (!element) {
+ return false;
+ }
+ if (element.nodeType === 3) {
+ element = element.parentElement;
+ }
+ var e = element;
+ var isClosest = false;
+ while (e && !isClosest && !e.classList.contains("vditor-reset")) {
+ if (e.nodeName === nodeName) {
+ isClosest = true;
+ }
+ else {
+ e = e.parentElement;
+ }
+ }
+ return isClosest && e;
+};
+var hasClosestByClassName = function (element, className) {
+ if (!element) {
+ return false;
+ }
+ if (element.nodeType === 3) {
+ element = element.parentElement;
+ }
+ var e = element;
+ var isClosest = false;
+ while (e && !isClosest && !e.classList.contains("vditor-reset")) {
+ if (e.classList.contains(className)) {
+ isClosest = true;
+ }
+ else {
+ e = e.parentElement;
+ }
+ }
+ return isClosest && e;
+};
+var getLastNode = function (node) {
+ while (node && node.lastChild) {
+ node = node.lastChild;
+ }
+ return node;
+};
+
+
+/***/ }),
+
+/***/ 771:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "S": () => (/* binding */ hasClosestByTag),
+/* harmony export */ "W": () => (/* binding */ hasClosestByHeadings)
+/* harmony export */ });
+// NOTE: 减少 method.ts 打包,故从 hasClosest.ts 中拆分
+var hasClosestByTag = function (element, nodeName) {
+ if (!element) {
+ return false;
+ }
+ if (element.nodeType === 3) {
+ element = element.parentElement;
+ }
+ var e = element;
+ var isClosest = false;
+ while (e && !isClosest && !e.classList.contains("vditor-reset")) {
+ if (e.nodeName.indexOf(nodeName) === 0) {
+ isClosest = true;
+ }
+ else {
+ e = e.parentElement;
+ }
+ }
+ return isClosest && e;
+};
+var hasClosestByHeadings = function (element) {
+ var headingElement = hasClosestByTag(element, "H");
+ if (headingElement && headingElement.tagName.length === 2 && headingElement.tagName !== "HR") {
+ return headingElement;
+ }
+ return false;
+};
+
+
+/***/ }),
+
+/***/ 673:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "T": () => (/* binding */ merge)
+/* harmony export */ });
+var merge = function () {
+ var options = [];
+ for (var _i = 0; _i < arguments.length; _i++) {
+ options[_i] = arguments[_i];
+ }
+ var target = {};
+ var merger = function (obj) {
+ for (var prop in obj) {
+ if (obj.hasOwnProperty(prop)) {
+ if (Object.prototype.toString.call(obj[prop]) === "[object Object]") {
+ target[prop] = merge(target[prop], obj[prop]);
+ }
+ else {
+ target[prop] = obj[prop];
+ }
+ }
+ }
+ };
+ for (var i = 0; i < options.length; i++) {
+ merger(options[i]);
+ }
+ return target;
+};
+
+
+/***/ }),
+
+/***/ 810:
+/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
+
+"use strict";
+/* harmony export */ __webpack_require__.d(__webpack_exports__, {
+/* harmony export */ "zh": () => (/* binding */ getEditorRange),
+/* harmony export */ "Ny": () => (/* binding */ getCursorPosition),
+/* harmony export */ "Gb": () => (/* binding */ selectIsEditor),
+/* harmony export */ "Hc": () => (/* binding */ setSelectionFocus),
+/* harmony export */ "im": () => (/* binding */ getSelectPosition),
+/* harmony export */ "$j": () => (/* binding */ setSelectionByPosition),
+/* harmony export */ "ib": () => (/* binding */ setRangeByWbr),
+/* harmony export */ "oC": () => (/* binding */ insertHTML)
+/* harmony export */ });
+/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(145);
+/* harmony import */ var _compatibility__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(410);
+/* harmony import */ var _hasClosest__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(106);
+
+
+
+var getEditorRange = function (vditor) {
+ var range;
+ var element = vditor[vditor.currentMode].element;
+ if (getSelection().rangeCount > 0) {
+ range = getSelection().getRangeAt(0);
+ if (element.isEqualNode(range.startContainer) || element.contains(range.startContainer)) {
+ return range;
+ }
+ }
+ if (vditor[vditor.currentMode].range) {
+ return vditor[vditor.currentMode].range;
+ }
+ element.focus();
+ range = element.ownerDocument.createRange();
+ range.setStart(element, 0);
+ range.collapse(true);
+ return range;
+};
+var getCursorPosition = function (editor) {
+ var range = window.getSelection().getRangeAt(0);
+ if (!editor.contains(range.startContainer) && !(0,_hasClosest__WEBPACK_IMPORTED_MODULE_1__/* .hasClosestByClassName */ .fb)(range.startContainer, "vditor-panel--none")) {
+ return {
+ left: 0,
+ top: 0,
+ };
+ }
+ var parentRect = editor.parentElement.getBoundingClientRect();
+ var cursorRect;
+ if (range.getClientRects().length === 0) {
+ if (range.startContainer.nodeType === 3) {
+ // 空行时,会出现没有 br 的情况,需要根据父元素 获取位置信息
+ var parent_1 = range.startContainer.parentElement;
+ if (parent_1 && parent_1.getClientRects().length > 0) {
+ cursorRect = parent_1.getClientRects()[0];
+ }
+ else {
+ return {
+ left: 0,
+ top: 0,
+ };
+ }
+ }
+ else {
+ var children = range.startContainer.children;
+ if (children[range.startOffset] &&
+ children[range.startOffset].getClientRects().length > 0) {
+ // markdown 模式回车
+ cursorRect = children[range.startOffset].getClientRects()[0];
+ }
+ else if (range.startContainer.childNodes.length > 0) {
+ // in table or code block
+ var cloneRange = range.cloneRange();
+ range.selectNode(range.startContainer.childNodes[Math.max(0, range.startOffset - 1)]);
+ cursorRect = range.getClientRects()[0];
+ range.setEnd(cloneRange.endContainer, cloneRange.endOffset);
+ range.setStart(cloneRange.startContainer, cloneRange.startOffset);
+ }
+ else {
+ cursorRect = range.startContainer.getClientRects()[0];
+ }
+ if (!cursorRect) {
+ var parentElement = range.startContainer.childNodes[range.startOffset];
+ while (!parentElement.getClientRects ||
+ (parentElement.getClientRects && parentElement.getClientRects().length === 0)) {
+ parentElement = parentElement.parentElement;
+ }
+ cursorRect = parentElement.getClientRects()[0];
+ }
+ }
+ }
+ else {
+ cursorRect = range.getClientRects()[0];
+ }
+ return {
+ left: cursorRect.left - parentRect.left,
+ top: cursorRect.top - parentRect.top,
+ };
+};
+var selectIsEditor = function (editor, range) {
+ if (!range) {
+ if (getSelection().rangeCount === 0) {
+ return false;
+ }
+ else {
+ range = getSelection().getRangeAt(0);
+ }
+ }
+ var container = range.commonAncestorContainer;
+ return editor.isEqualNode(container) || editor.contains(container);
+};
+var setSelectionFocus = function (range) {
+ var selection = window.getSelection();
+ selection.removeAllRanges();
+ selection.addRange(range);
+};
+var getSelectPosition = function (selectElement, editorElement, range) {
+ var position = {
+ end: 0,
+ start: 0,
+ };
+ if (!range) {
+ if (getSelection().rangeCount === 0) {
+ return position;
+ }
+ range = window.getSelection().getRangeAt(0);
+ }
+ if (selectIsEditor(editorElement, range)) {
+ var preSelectionRange = range.cloneRange();
+ if (selectElement.childNodes[0] && selectElement.childNodes[0].childNodes[0]) {
+ preSelectionRange.setStart(selectElement.childNodes[0].childNodes[0], 0);
+ }
+ else {
+ preSelectionRange.selectNodeContents(selectElement);
+ }
+ preSelectionRange.setEnd(range.startContainer, range.startOffset);
+ position.start = preSelectionRange.toString().length;
+ position.end = position.start + range.toString().length;
+ }
+ return position;
+};
+var setSelectionByPosition = function (start, end, editor) {
+ var charIndex = 0;
+ var line = 0;
+ var pNode = editor.childNodes[line];
+ var foundStart = false;
+ var stop = false;
+ start = Math.max(0, start);
+ end = Math.max(0, end);
+ var range = editor.ownerDocument.createRange();
+ range.setStart(pNode || editor, 0);
+ range.collapse(true);
+ while (!stop && pNode) {
+ var nextCharIndex = charIndex + pNode.textContent.length;
+ if (!foundStart && start >= charIndex && start <= nextCharIndex) {
+ if (start === 0) {
+ range.setStart(pNode, 0);
+ }
+ else {
+ if (pNode.childNodes[0].nodeType === 3) {
+ range.setStart(pNode.childNodes[0], start - charIndex);
+ }
+ else if (pNode.nextSibling) {
+ range.setStartBefore(pNode.nextSibling);
+ }
+ else {
+ range.setStartAfter(pNode);
+ }
+ }
+ foundStart = true;
+ if (start === end) {
+ stop = true;
+ break;
+ }
+ }
+ if (foundStart && end >= charIndex && end <= nextCharIndex) {
+ if (end === 0) {
+ range.setEnd(pNode, 0);
+ }
+ else {
+ if (pNode.childNodes[0].nodeType === 3) {
+ range.setEnd(pNode.childNodes[0], end - charIndex);
+ }
+ else if (pNode.nextSibling) {
+ range.setEndBefore(pNode.nextSibling);
+ }
+ else {
+ range.setEndAfter(pNode);
+ }
+ }
+ stop = true;
+ }
+ charIndex = nextCharIndex;
+ pNode = editor.childNodes[++line];
+ }
+ if (!stop && editor.childNodes[line - 1]) {
+ range.setStartBefore(editor.childNodes[line - 1]);
+ }
+ setSelectionFocus(range);
+ return range;
+};
+var setRangeByWbr = function (element, range) {
+ var wbrElement = element.querySelector("wbr");
+ if (!wbrElement) {
+ return;
+ }
+ if (!wbrElement.previousElementSibling) {
+ if (wbrElement.previousSibling) {
+ // text
+ range.setStart(wbrElement.previousSibling, wbrElement.previousSibling.textContent.length);
+ }
+ else if (wbrElement.nextSibling) {
+ if (wbrElement.nextSibling.nodeType === 3) {
+ // text
+ range.setStart(wbrElement.nextSibling, 0);
+ }
+ else {
+ //
https://github.com/Vanessa219/vditor/issues/400
+ range.setStartBefore(wbrElement.nextSibling);
+ }
+ }
+ else {
+ // 内容为空
+ range.setStart(wbrElement.parentElement, 0);
+ }
+ }
+ else {
+ if (wbrElement.previousElementSibling.isSameNode(wbrElement.previousSibling)) {
+ if (wbrElement.previousElementSibling.lastChild) {
+ // text
+ range.setStartBefore(wbrElement);
+ range.collapse(true);
+ setSelectionFocus(range);
+ // fix Chrome set range bug: **c**
+ if ((0,_compatibility__WEBPACK_IMPORTED_MODULE_2__/* .isChrome */ .i7)() && (wbrElement.previousElementSibling.tagName === "EM" ||
+ wbrElement.previousElementSibling.tagName === "STRONG" ||
+ wbrElement.previousElementSibling.tagName === "S")) {
+ range.insertNode(document.createTextNode(_constants__WEBPACK_IMPORTED_MODULE_0__/* .Constants.ZWSP */ .g.ZWSP));
+ range.collapse(false);
+ }
+ wbrElement.remove();
+ return;
+ }
+ else {
+ //
+ range.setStartAfter(wbrElement.previousElementSibling);
+ }
+ }
+ else {
+ // texttext
+ range.setStart(wbrElement.previousSibling, wbrElement.previousSibling.textContent.length);
+ }
+ }
+ range.collapse(true);
+ wbrElement.remove();
+ setSelectionFocus(range);
+};
+var insertHTML = function (html, vditor) {
+ // 使用 lute 方法会添加 p 元素,只有一个 p 元素的时候进行删除
+ var tempElement = document.createElement("div");
+ tempElement.innerHTML = html;
+ var tempBlockElement = tempElement.querySelectorAll("p");
+ if (tempBlockElement.length === 1 && !tempBlockElement[0].previousSibling && !tempBlockElement[0].nextSibling &&
+ vditor[vditor.currentMode].element.children.length > 0 && tempElement.firstElementChild.tagName === "P") {
+ html = tempBlockElement[0].innerHTML.trim();
+ }
+ var pasteElement = document.createElement("div");
+ pasteElement.innerHTML = html;
+ var range = getEditorRange(vditor);
+ if (range.toString() !== "") {
+ vditor[vditor.currentMode].preventInput = true;
+ document.execCommand("delete", false, "");
+ }
+ if (pasteElement.firstElementChild &&
+ pasteElement.firstElementChild.getAttribute("data-block") === "0") {
+ // 粘贴内容为块元素时,应在下一段落中插入
+ pasteElement.lastElementChild.insertAdjacentHTML("beforeend", "");
+ var blockElement = (0,_hasClosest__WEBPACK_IMPORTED_MODULE_1__/* .hasClosestBlock */ .F9)(range.startContainer);
+ if (!blockElement) {
+ vditor[vditor.currentMode].element.insertAdjacentHTML("beforeend", pasteElement.innerHTML);
+ }
+ else {
+ blockElement.insertAdjacentHTML("afterend", pasteElement.innerHTML);
+ }
+ setRangeByWbr(vditor[vditor.currentMode].element, range);
+ }
+ else {
+ var pasteTemplate = document.createElement("template");
+ pasteTemplate.innerHTML = html;
+ range.insertNode(pasteTemplate.content.cloneNode(true));
+ range.collapse(false);
+ setSelectionFocus(range);
+ }
+};
+
+
+/***/ })
+
+/******/ });
+/************************************************************************/
+/******/ // The module cache
+/******/ var __webpack_module_cache__ = {};
+/******/
+/******/ // The require function
+/******/ function __webpack_require__(moduleId) {
+/******/ // Check if module is in cache
+/******/ var cachedModule = __webpack_module_cache__[moduleId];
+/******/ if (cachedModule !== undefined) {
+/******/ return cachedModule.exports;
+/******/ }
+/******/ // Create a new module (and put it into the cache)
+/******/ var module = __webpack_module_cache__[moduleId] = {
+/******/ // no module.id needed
+/******/ // no module.loaded needed
+/******/ exports: {}
+/******/ };
+/******/
+/******/ // Execute the module function
+/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
+/******/
+/******/ // Return the exports of the module
+/******/ return module.exports;
+/******/ }
+/******/
+/************************************************************************/
+/******/ /* webpack/runtime/define property getters */
+/******/ (() => {
+/******/ // define getter functions for harmony exports
+/******/ __webpack_require__.d = (exports, definition) => {
+/******/ for(var key in definition) {
+/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
+/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
+/******/ }
+/******/ }
+/******/ };
+/******/ })();
+/******/
+/******/ /* webpack/runtime/hasOwnProperty shorthand */
+/******/ (() => {
+/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
+/******/ })();
+/******/
+/******/ /* webpack/runtime/make namespace object */
+/******/ (() => {
+/******/ // define __esModule on exports
+/******/ __webpack_require__.r = (exports) => {
+/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
+/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
+/******/ }
+/******/ Object.defineProperty(exports, '__esModule', { value: true });
+/******/ };
+/******/ })();
+/******/
+/************************************************************************/
+var __webpack_exports__ = {};
+// This entry need to be wrapped in an IIFE because it need to be in strict mode.
+(() => {
+"use strict";
+
+// EXPORTS
+__webpack_require__.d(__webpack_exports__, {
+ "default": () => (/* binding */ src)
+});
+
+// EXTERNAL MODULE: ./src/method.ts + 4 modules
+var method = __webpack_require__(408);
+// EXTERNAL MODULE: ./src/ts/constants.ts
+var constants = __webpack_require__(145);
+// EXTERNAL MODULE: ./src/ts/util/code160to32.ts
+var code160to32 = __webpack_require__(105);
+;// CONCATENATED MODULE: ./src/ts/markdown/getMarkdown.ts
+
+var getMarkdown = function (vditor) {
+ if (vditor.currentMode === "sv") {
+ return (0,code160to32/* code160to32 */.X)("".concat(vditor.sv.element.textContent, "\n").replace(/\n\n$/, "\n"));
+ }
+ else if (vditor.currentMode === "wysiwyg") {
+ return vditor.lute.VditorDOM2Md(vditor.wysiwyg.element.innerHTML);
+ }
+ else if (vditor.currentMode === "ir") {
+ return vditor.lute.VditorIRDOM2Md(vditor.ir.element.innerHTML);
+ }
+ return "";
+};
+
+// EXTERNAL MODULE: ./src/ts/util/addScript.ts
+var addScript = __webpack_require__(413);
+;// CONCATENATED MODULE: ./src/ts/devtools/index.ts
+
+
+var DevTools = /** @class */ (function () {
+ function DevTools() {
+ this.element = document.createElement("div");
+ this.element.className = "vditor-devtools";
+ this.element.innerHTML = '';
+ }
+ DevTools.prototype.renderEchart = function (vditor) {
+ var _this = this;
+ if (vditor.devtools.element.style.display !== "block") {
+ return;
+ }
+ (0,addScript/* addScript */.G)("".concat(vditor.options.cdn, "/dist/js/echarts/echarts.min.js?v=5.5.1"), "vditorEchartsScript").then(function () {
+ if (!_this.ASTChart) {
+ _this.ASTChart = echarts.init(vditor.devtools.element.lastElementChild);
+ }
+ try {
+ _this.element.lastElementChild.style.display = "block";
+ _this.element.firstElementChild.innerHTML = "";
+ _this.ASTChart.setOption({
+ series: [
+ {
+ data: JSON.parse(vditor.lute.RenderEChartsJSON(getMarkdown(vditor))),
+ initialTreeDepth: -1,
+ label: {
+ align: "left",
+ backgroundColor: "rgba(68, 77, 86, .68)",
+ borderRadius: 3,
+ color: "#d1d5da",
+ fontSize: 12,
+ lineHeight: 12,
+ offset: [9, 12],
+ padding: [2, 4, 2, 4],
+ position: "top",
+ verticalAlign: "middle",
+ },
+ lineStyle: {
+ color: "#4285f4",
+ type: "curve",
+ width: 1,
+ },
+ orient: "vertical",
+ roam: true,
+ type: "tree",
+ },
+ ],
+ toolbox: {
+ bottom: 25,
+ emphasis: {
+ iconStyle: {
+ color: "#4285f4",
+ },
+ },
+ feature: {
+ restore: {
+ show: true,
+ },
+ saveAsImage: {
+ show: true,
+ },
+ },
+ right: 15,
+ show: true,
+ },
+ });
+ _this.ASTChart.resize();
+ }
+ catch (e) {
+ _this.element.lastElementChild.style.display = "none";
+ _this.element.firstElementChild.innerHTML = e;
+ }
+ });
+ };
+ return DevTools;
+}());
+
+
+// EXTERNAL MODULE: ./src/ts/util/compatibility.ts
+var compatibility = __webpack_require__(410);
+;// CONCATENATED MODULE: ./src/ts/toolbar/setToolbar.ts
+
+
+var removeCurrentToolbar = function (toolbar, names) {
+ names.forEach(function (name) {
+ if (!toolbar[name]) {
+ return;
+ }
+ var itemElement = toolbar[name].children[0];
+ if (itemElement && itemElement.classList.contains("vditor-menu--current")) {
+ itemElement.classList.remove("vditor-menu--current");
+ }
+ });
+};
+var setCurrentToolbar = function (toolbar, names) {
+ names.forEach(function (name) {
+ if (!toolbar[name]) {
+ return;
+ }
+ var itemElement = toolbar[name].children[0];
+ if (itemElement && !itemElement.classList.contains("vditor-menu--current")) {
+ itemElement.classList.add("vditor-menu--current");
+ }
+ });
+};
+var enableToolbar = function (toolbar, names) {
+ names.forEach(function (name) {
+ if (!toolbar[name]) {
+ return;
+ }
+ var itemElement = toolbar[name].children[0];
+ if (itemElement && itemElement.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ itemElement.classList.remove(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED);
+ }
+ });
+};
+var disableToolbar = function (toolbar, names) {
+ names.forEach(function (name) {
+ if (!toolbar[name]) {
+ return;
+ }
+ var itemElement = toolbar[name].children[0];
+ if (itemElement && !itemElement.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ itemElement.classList.add(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED);
+ }
+ });
+};
+var hideToolbar = function (toolbar, names) {
+ names.forEach(function (name) {
+ if (!toolbar[name]) {
+ return;
+ }
+ if (toolbar[name]) {
+ toolbar[name].style.display = "none";
+ }
+ });
+};
+var showToolbar = function (toolbar, names) {
+ names.forEach(function (name) {
+ if (!toolbar[name]) {
+ return;
+ }
+ if (toolbar[name]) {
+ toolbar[name].style.display = "block";
+ }
+ });
+};
+// "subToolbar", "hint", "popover"
+var hidePanel = function (vditor, panels, exceptElement) {
+ if (panels.includes("subToolbar")) {
+ vditor.toolbar.element.querySelectorAll(".vditor-hint").forEach(function (item) {
+ if (exceptElement && item.isEqualNode(exceptElement)) {
+ return;
+ }
+ item.style.display = "none";
+ });
+ if (vditor.toolbar.elements.emoji) {
+ vditor.toolbar.elements.emoji.lastElementChild.style.display = "none";
+ }
+ }
+ if (panels.includes("hint")) {
+ vditor.hint.element.style.display = "none";
+ }
+ if (vditor.wysiwyg.popover && panels.includes("popover")) {
+ vditor.wysiwyg.popover.style.display = "none";
+ }
+};
+var toggleSubMenu = function (vditor, panelElement, actionBtn, level) {
+ actionBtn.addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ event.stopPropagation();
+ if (actionBtn.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ return;
+ }
+ vditor.toolbar.element.querySelectorAll(".vditor-hint--current").forEach(function (item) {
+ item.classList.remove("vditor-hint--current");
+ });
+ if (panelElement.style.display === "block") {
+ panelElement.style.display = "none";
+ }
+ else {
+ hidePanel(vditor, ["subToolbar", "hint", "popover"], actionBtn.parentElement.parentElement);
+ if (!actionBtn.classList.contains("vditor-tooltipped")) {
+ actionBtn.classList.add("vditor-hint--current");
+ }
+ panelElement.style.display = "block";
+ if (vditor.toolbar.element.getBoundingClientRect().right - actionBtn.getBoundingClientRect().right < 250) {
+ panelElement.classList.add("vditor-panel--left");
+ }
+ else {
+ panelElement.classList.remove("vditor-panel--left");
+ }
+ }
+ });
+};
+
+// EXTERNAL MODULE: ./src/ts/util/hasClosest.ts
+var hasClosest = __webpack_require__(106);
+// EXTERNAL MODULE: ./src/ts/util/hasClosestByHeadings.ts
+var hasClosestByHeadings = __webpack_require__(771);
+;// CONCATENATED MODULE: ./src/ts/util/log.ts
+var log = function (method, content, type, print) {
+ if (print) {
+ // @ts-ignore
+ console.log("".concat(method, " - ").concat(type, ": ").concat(content));
+ }
+};
+
+// EXTERNAL MODULE: ./src/ts/markdown/abcRender.ts
+var abcRender = __webpack_require__(135);
+// EXTERNAL MODULE: ./src/ts/markdown/chartRender.ts
+var chartRender = __webpack_require__(775);
+// EXTERNAL MODULE: ./src/ts/markdown/codeRender.ts
+var codeRender = __webpack_require__(428);
+// EXTERNAL MODULE: ./src/ts/markdown/flowchartRender.ts
+var flowchartRender = __webpack_require__(325);
+// EXTERNAL MODULE: ./src/ts/markdown/graphvizRender.ts
+var graphvizRender = __webpack_require__(483);
+// EXTERNAL MODULE: ./src/ts/markdown/highlightRender.ts
+var highlightRender = __webpack_require__(999);
+// EXTERNAL MODULE: ./src/ts/markdown/mathRender.ts
+var mathRender = __webpack_require__(472);
+// EXTERNAL MODULE: ./src/ts/markdown/mermaidRender.ts
+var mermaidRender = __webpack_require__(637);
+// EXTERNAL MODULE: ./src/ts/markdown/markmapRender.ts
+var markmapRender = __webpack_require__(11);
+// EXTERNAL MODULE: ./src/ts/markdown/mindmapRender.ts
+var mindmapRender = __webpack_require__(194);
+// EXTERNAL MODULE: ./src/ts/markdown/plantumlRender.ts
+var plantumlRender = __webpack_require__(229);
+// EXTERNAL MODULE: ./src/ts/markdown/SMILESRender.ts
+var SMILESRender = __webpack_require__(825);
+;// CONCATENATED MODULE: ./src/ts/util/processCode.ts
+
+
+
+
+
+
+
+
+
+
+
+
+var processPasteCode = function (html, text, type) {
+ if (type === void 0) { type = "sv"; }
+ var tempElement = document.createElement("div");
+ tempElement.innerHTML = html;
+ var isCode = false;
+ if (tempElement.childElementCount === 1 &&
+ tempElement.lastElementChild.style.fontFamily.indexOf("monospace") > -1) {
+ // VS Code
+ isCode = true;
+ }
+ var pres = tempElement.querySelectorAll("pre");
+ if (tempElement.childElementCount === 1 && pres.length === 1
+ && pres[0].className !== "vditor-wysiwyg"
+ && pres[0].className !== "vditor-sv") {
+ // IDE
+ isCode = true;
+ }
+ if (html.indexOf('\n') === 0) {
+ // Xcode
+ isCode = true;
+ }
+ if (tempElement.childElementCount === 1 && tempElement.firstElementChild.tagName === "TABLE" &&
+ tempElement.querySelector(".line-number") && tempElement.querySelector(".line-content")) {
+ // 网页源码
+ isCode = true;
+ }
+ if (isCode) {
+ var code = text || html;
+ if (/\n/.test(code) || pres.length === 1) {
+ if (type === "wysiwyg") {
+ return "
".concat(code.replace(/&/g, "&").replace(/
");
+ }
+ return "\n```\n" + code.replace(/&/g, "&").replace(/".concat(code.replace(/&/g, "&").replace(/");
+ }
+ return "`".concat(code, "`");
+ }
+ }
+ return false;
+};
+var processCodeRender = function (previewPanel, vditor) {
+ if (!previewPanel) {
+ return;
+ }
+ if (previewPanel.parentElement.getAttribute("data-type") === "html-block") {
+ previewPanel.setAttribute("data-render", "1");
+ return;
+ }
+ var language = previewPanel.firstElementChild.className.replace("language-", "");
+ if (language === "abc") {
+ (0,abcRender/* abcRender */.Q)(previewPanel, vditor.options.cdn);
+ }
+ else if (language === "mermaid") {
+ (0,mermaidRender/* mermaidRender */.i)(previewPanel, vditor.options.cdn, vditor.options.theme);
+ }
+ else if (language === "smiles") {
+ (0,SMILESRender/* SMILESRender */.J)(previewPanel, vditor.options.cdn, vditor.options.theme);
+ }
+ else if (language === "markmap") {
+ (0,markmapRender/* markmapRender */.K)(previewPanel, vditor.options.cdn);
+ }
+ else if (language === "flowchart") {
+ (0,flowchartRender/* flowchartRender */.P)(previewPanel, vditor.options.cdn);
+ }
+ else if (language === "echarts") {
+ (0,chartRender/* chartRender */.p)(previewPanel, vditor.options.cdn, vditor.options.theme);
+ }
+ else if (language === "mindmap") {
+ (0,mindmapRender/* mindmapRender */.P)(previewPanel, vditor.options.cdn, vditor.options.theme);
+ }
+ else if (language === "plantuml") {
+ (0,plantumlRender/* plantumlRender */.B)(previewPanel, vditor.options.cdn);
+ }
+ else if (language === "graphviz") {
+ (0,graphvizRender/* graphvizRender */.v)(previewPanel, vditor.options.cdn);
+ }
+ else if (language === "math") {
+ (0,mathRender/* mathRender */.H)(previewPanel, { cdn: vditor.options.cdn, math: vditor.options.preview.math });
+ }
+ else {
+ var cRender = vditor.options.customRenders.find(function (item) {
+ if (item.language === language) {
+ item.render(previewPanel, vditor);
+ return true;
+ }
+ });
+ if (!cRender) {
+ (0,highlightRender/* highlightRender */.s)(Object.assign({}, vditor.options.preview.hljs), previewPanel, vditor.options.cdn);
+ (0,codeRender/* codeRender */.O)(previewPanel, vditor.options.preview.hljs);
+ }
+ }
+ previewPanel.setAttribute("data-render", "1");
+};
+
+// EXTERNAL MODULE: ./src/ts/util/selection.ts
+var selection = __webpack_require__(810);
+;// CONCATENATED MODULE: ./src/ts/util/toc.ts
+
+
+
+
+var renderToc = function (vditor) {
+ if (vditor.currentMode === "sv") {
+ return;
+ }
+ var editorElement = vditor[vditor.currentMode].element;
+ var tocHTML = vditor.outline.render(vditor);
+ if (tocHTML === "") {
+ tocHTML = "[ToC]";
+ }
+ editorElement.querySelectorAll('[data-type="toc-block"]').forEach(function (item) {
+ item.innerHTML = tocHTML;
+ (0,mathRender/* mathRender */.H)(item, {
+ cdn: vditor.options.cdn,
+ math: vditor.options.preview.math,
+ });
+ });
+};
+var clickToc = function (event, vditor) {
+ var spanElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(event.target, "SPAN");
+ if (spanElement && (0,hasClosest/* hasClosestByClassName */.fb)(spanElement, "vditor-toc")) {
+ var headingElement = vditor[vditor.currentMode].element.querySelector("#" + spanElement.getAttribute("data-target-id"));
+ if (headingElement) {
+ if (vditor.options.height === "auto") {
+ var windowScrollY = headingElement.offsetTop + vditor.element.offsetTop;
+ if (!vditor.options.toolbarConfig.pin) {
+ windowScrollY += vditor.toolbar.element.offsetHeight;
+ }
+ window.scrollTo(window.scrollX, windowScrollY);
+ }
+ else {
+ if (vditor.element.offsetTop < window.scrollY) {
+ window.scrollTo(window.scrollX, vditor.element.offsetTop);
+ }
+ vditor[vditor.currentMode].element.scrollTop = headingElement.offsetTop;
+ }
+ }
+ return;
+ }
+};
+var keydownToc = function (blockElement, vditor, event, range) {
+ // toc 前无元素,插入空块
+ if (blockElement.previousElementSibling &&
+ blockElement.previousElementSibling.classList.contains("vditor-toc")) {
+ if (event.key === "Backspace" &&
+ (0,selection/* getSelectPosition */.im)(blockElement, vditor[vditor.currentMode].element, range).start === 0) {
+ blockElement.previousElementSibling.remove();
+ execAfterRender(vditor);
+ return true;
+ }
+ if (insertBeforeBlock(vditor, event, range, blockElement, blockElement.previousElementSibling)) {
+ return true;
+ }
+ }
+ // toc 后无元素,插入空块
+ if (blockElement.nextElementSibling &&
+ blockElement.nextElementSibling.classList.contains("vditor-toc")) {
+ if (event.key === "Delete" &&
+ (0,selection/* getSelectPosition */.im)(blockElement, vditor[vditor.currentMode].element, range).start
+ >= blockElement.textContent.trimRight().length) {
+ blockElement.nextElementSibling.remove();
+ execAfterRender(vditor);
+ return true;
+ }
+ if (insertAfterBlock(vditor, event, range, blockElement, blockElement.nextElementSibling)) {
+ return true;
+ }
+ }
+ // toc 删除
+ if (event.key === "Backspace" || event.key === "Delete") {
+ var tocElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-toc");
+ if (tocElement) {
+ tocElement.remove();
+ execAfterRender(vditor);
+ return true;
+ }
+ }
+};
+
+;// CONCATENATED MODULE: ./src/ts/ir/input.ts
+
+
+
+
+
+
+
+
+
+
+var input = function (vditor, range, ignoreSpace, event) {
+ if (ignoreSpace === void 0) { ignoreSpace = false; }
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer);
+ // 前后可以输入空格
+ if (blockElement && !ignoreSpace && blockElement.getAttribute("data-type") !== "code-block") {
+ if ((isHrMD(blockElement.innerHTML) && blockElement.previousElementSibling) ||
+ isHeadingMD(blockElement.innerHTML)) {
+ return;
+ }
+ // 前后空格处理
+ var startOffset = (0,selection/* getSelectPosition */.im)(blockElement, vditor.ir.element, range).start;
+ // 开始可以输入空格
+ var startSpace = true;
+ for (var i = startOffset - 1;
+ // 软换行后有空格
+ i > blockElement.textContent.substr(0, startOffset).lastIndexOf("\n"); i--) {
+ if (blockElement.textContent.charAt(i) !== " " &&
+ // 多个 tab 前删除不形成代码块 https://github.com/Vanessa219/vditor/issues/162 1
+ blockElement.textContent.charAt(i) !== "\t") {
+ startSpace = false;
+ break;
+ }
+ }
+ if (startOffset === 0) {
+ startSpace = false;
+ }
+ // 结尾可以输入空格
+ var endSpace = true;
+ for (var i = startOffset - 1; i < blockElement.textContent.length; i++) {
+ if (blockElement.textContent.charAt(i) !== " " && blockElement.textContent.charAt(i) !== "\n") {
+ endSpace = false;
+ break;
+ }
+ }
+ if (startSpace) {
+ if (typeof vditor.options.input === "function") {
+ vditor.options.input(getMarkdown(vditor));
+ }
+ return;
+ }
+ // https://github.com/Vanessa219/vditor/issues/729
+ if (endSpace && /^#{1,6} $/.test(blockElement.textContent)) {
+ endSpace = false;
+ }
+ if (endSpace) {
+ var markerElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-ir__marker");
+ if (markerElement) {
+ // inline marker space https://github.com/Vanessa219/vditor/issues/239
+ }
+ else {
+ var previousNode = range.startContainer.previousSibling;
+ if (previousNode && previousNode.nodeType !== 3 && previousNode.classList.contains("vditor-ir__node--expand")) {
+ // FireFox https://github.com/Vanessa219/vditor/issues/239
+ previousNode.classList.remove("vditor-ir__node--expand");
+ }
+ if (typeof vditor.options.input === "function") {
+ vditor.options.input(getMarkdown(vditor));
+ }
+ return;
+ }
+ }
+ }
+ vditor.ir.element.querySelectorAll(".vditor-ir__node--expand").forEach(function (item) {
+ item.classList.remove("vditor-ir__node--expand");
+ });
+ if (!blockElement) {
+ // 使用顶级块元素,应使用 innerHTML
+ blockElement = vditor.ir.element;
+ }
+ // document.exeComment insertHTML 会插入 wbr
+ if (!blockElement.querySelector("wbr")) {
+ var previewRenderElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-ir__preview");
+ if (previewRenderElement) {
+ previewRenderElement.previousElementSibling.insertAdjacentHTML("beforeend", "");
+ }
+ else {
+ range.insertNode(document.createElement("wbr"));
+ }
+ }
+ // 清除浏览器自带的样式
+ blockElement.querySelectorAll("[style]").forEach(function (item) {
+ item.removeAttribute("style");
+ });
+ if (blockElement.getAttribute("data-type") === "link-ref-defs-block") {
+ // 修改链接引用
+ blockElement = vditor.ir.element;
+ }
+ var isIRElement = blockElement.isEqualNode(vditor.ir.element);
+ var footnoteElement = (0,hasClosest/* hasClosestByAttribute */.a1)(blockElement, "data-type", "footnotes-block");
+ var html = "";
+ if (!isIRElement) {
+ var blockquoteElement = (0,hasClosestByHeadings/* hasClosestByTag */.S)(range.startContainer, "BLOCKQUOTE");
+ // 列表需要到最顶层
+ var topListElement = (0,hasClosest/* getTopList */.O9)(range.startContainer);
+ if (topListElement) {
+ blockElement = topListElement;
+ }
+ // 应到引用层,否则 > --- 会解析为 front-matter;列表中有 blockquote 则解析 blockquote;blockquote 中有列表则解析列表
+ if (blockquoteElement && (!topListElement || (topListElement && !blockquoteElement.contains(topListElement)))) {
+ blockElement = blockquoteElement;
+ }
+ // 修改脚注
+ if (footnoteElement) {
+ blockElement = footnoteElement;
+ }
+ html = blockElement.outerHTML;
+ if (blockElement.tagName === "UL" || blockElement.tagName === "OL") {
+ // 如果为列表的话,需要把上下的列表都重绘
+ var listPrevElement = blockElement.previousElementSibling;
+ var listNextElement = blockElement.nextElementSibling;
+ if (listPrevElement && (listPrevElement.tagName === "UL" || listPrevElement.tagName === "OL")) {
+ html = listPrevElement.outerHTML + html;
+ listPrevElement.remove();
+ }
+ if (listNextElement && (listNextElement.tagName === "UL" || listNextElement.tagName === "OL")) {
+ html = html + listNextElement.outerHTML;
+ listNextElement.remove();
+ }
+ // firefox 列表回车不会产生新的 list item https://github.com/Vanessa219/vditor/issues/194
+ html = html.replace("
", "
");
+ }
+ else if (blockElement.previousElementSibling &&
+ blockElement.previousElementSibling.textContent.replace(constants/* Constants.ZWSP */.g.ZWSP, "") !== "" &&
+ event && event.inputType === "insertParagraph") {
+ // 换行时需要处理上一段落
+ html = blockElement.previousElementSibling.outerHTML + html;
+ blockElement.previousElementSibling.remove();
+ }
+ if (!blockElement.innerText.startsWith("```")) {
+ // 添加链接引用
+ vditor.ir.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach(function (item) {
+ if (item && !blockElement.isEqualNode(item)) {
+ html += item.outerHTML;
+ item.remove();
+ }
+ });
+ // 添加脚注
+ vditor.ir.element.querySelectorAll("[data-type='footnotes-block']").forEach(function (item) {
+ if (item && !blockElement.isEqualNode(item)) {
+ html += item.outerHTML;
+ item.remove();
+ }
+ });
+ }
+ }
+ else {
+ html = blockElement.innerHTML;
+ }
+ log("SpinVditorIRDOM", html, "argument", vditor.options.debugger);
+ html = vditor.lute.SpinVditorIRDOM(html);
+ log("SpinVditorIRDOM", html, "result", vditor.options.debugger);
+ if (isIRElement) {
+ blockElement.innerHTML = html;
+ }
+ else {
+ blockElement.outerHTML = html;
+ // 更新正文中的 tip
+ if (footnoteElement) {
+ var footnoteItemElement = (0,hasClosest/* hasClosestByAttribute */.a1)(vditor.ir.element.querySelector("wbr"), "data-type", "footnotes-def");
+ if (footnoteItemElement) {
+ var footnoteItemText = footnoteItemElement.textContent;
+ var marker = footnoteItemText.substring(1, footnoteItemText.indexOf("]:"));
+ var footnoteRefElement = vditor.ir.element.querySelector("sup[data-type=\"footnotes-ref\"][data-footnotes-label=\"".concat(marker, "\"]"));
+ if (footnoteRefElement) {
+ footnoteRefElement.setAttribute("aria-label", footnoteItemText.substr(marker.length + 3).trim().substr(0, 24));
+ }
+ }
+ }
+ }
+ // linkref 合并及添加
+ var firstLinkRefDefElement;
+ var allLinkRefDefsElement = vditor.ir.element.querySelectorAll("[data-type='link-ref-defs-block']");
+ allLinkRefDefsElement.forEach(function (item, index) {
+ if (index === 0) {
+ firstLinkRefDefElement = item;
+ }
+ else {
+ firstLinkRefDefElement.insertAdjacentHTML("beforeend", item.innerHTML);
+ item.remove();
+ }
+ });
+ if (allLinkRefDefsElement.length > 0) {
+ vditor.ir.element.insertAdjacentElement("beforeend", allLinkRefDefsElement[0]);
+ }
+ // 脚注合并后添加的末尾
+ var firstFootnoteElement;
+ var allFootnoteElement = vditor.ir.element.querySelectorAll("[data-type='footnotes-block']");
+ allFootnoteElement.forEach(function (item, index) {
+ if (index === 0) {
+ firstFootnoteElement = item;
+ }
+ else {
+ firstFootnoteElement.insertAdjacentHTML("beforeend", item.innerHTML);
+ item.remove();
+ }
+ });
+ if (allFootnoteElement.length > 0) {
+ vditor.ir.element.insertAdjacentElement("beforeend", allFootnoteElement[0]);
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor.ir.element, range);
+ vditor.ir.element.querySelectorAll(".vditor-ir__preview[data-render='2']").forEach(function (item) {
+ processCodeRender(item, vditor);
+ });
+ renderToc(vditor);
+ process_processAfterRender(vditor, {
+ enableAddUndoStack: true,
+ enableHint: true,
+ enableInput: true,
+ });
+};
+
+;// CONCATENATED MODULE: ./src/ts/util/hotKey.ts
+
+// 是否匹配 ⇧⌘[] / ⌘[] / ⌥[] / ⌥⌘[] / ⇧Tab / []
+var matchHotKey = function (hotKey, event) {
+ if (hotKey === "") {
+ return false;
+ }
+ // []
+ if (hotKey.indexOf("⇧") === -1 && hotKey.indexOf("⌘") === -1 && hotKey.indexOf("⌥") === -1) {
+ if (!(0,compatibility/* isCtrl */.yl)(event) && !event.altKey && !event.shiftKey && event.code === hotKey) {
+ return true;
+ }
+ return false;
+ }
+ // 是否匹配 ⇧Tab
+ if (hotKey === "⇧Tab") {
+ if (!(0,compatibility/* isCtrl */.yl)(event) && !event.altKey && event.shiftKey && event.code === "Tab") {
+ return true;
+ }
+ return false;
+ }
+ var hotKeys = hotKey.split("");
+ if (hotKey.startsWith("⌥")) {
+ // 是否匹配 ⌥[] / ⌥⌘[]
+ var keyCode = hotKeys.length === 3 ? hotKeys[2] : hotKeys[1];
+ if ((hotKeys.length === 3 ? (0,compatibility/* isCtrl */.yl)(event) : !(0,compatibility/* isCtrl */.yl)(event)) && event.altKey && !event.shiftKey &&
+ event.code === (/^[0-9]$/.test(keyCode) ? "Digit" : "Key") + keyCode) {
+ return true;
+ }
+ return false;
+ }
+ // 是否匹配 ⇧⌘[] / ⌘[]
+ if (hotKey === "⌘Enter") {
+ hotKeys = ["⌘", "Enter"];
+ }
+ var hasShift = hotKeys.length > 2 && (hotKeys[0] === "⇧");
+ var key = (hasShift ? hotKeys[2] : hotKeys[1]);
+ if (hasShift && ((0,compatibility/* isFirefox */.vU)() || !/Mac/.test(navigator.platform))) {
+ if (key === "-") {
+ key = "_";
+ }
+ else if (key === "=") {
+ key = "+";
+ }
+ }
+ if ((0,compatibility/* isCtrl */.yl)(event) && event.key.toLowerCase() === key.toLowerCase() && !event.altKey
+ && ((!hasShift && !event.shiftKey) || (hasShift && event.shiftKey))) {
+ return true;
+ }
+ return false;
+};
+
+;// CONCATENATED MODULE: ./src/ts/ir/expandMarker.ts
+
+
+var nextIsNode = function (range) {
+ var startContainer = range.startContainer;
+ if (startContainer.nodeType === 3 && startContainer.nodeValue.length !== range.startOffset) {
+ return false;
+ }
+ var nextNode = startContainer.nextSibling;
+ while (nextNode && nextNode.textContent === "") {
+ nextNode = nextNode.nextSibling;
+ }
+ if (!nextNode) {
+ // *em*|**string**
+ var markerElement = (0,hasClosest/* hasClosestByClassName */.fb)(startContainer, "vditor-ir__marker");
+ if (markerElement && !markerElement.nextSibling) {
+ var parentNextNode = startContainer.parentElement.parentElement.nextSibling;
+ if (parentNextNode && parentNextNode.nodeType !== 3 &&
+ parentNextNode.classList.contains("vditor-ir__node")) {
+ return parentNextNode;
+ }
+ }
+ return false;
+ }
+ else if (nextNode && nextNode.nodeType !== 3 && nextNode.classList.contains("vditor-ir__node") &&
+ !nextNode.getAttribute("data-block")) {
+ // test|*em*
+ return nextNode;
+ }
+ return false;
+};
+var previousIsNode = function (range) {
+ var startContainer = range.startContainer;
+ var previousNode = startContainer.previousSibling;
+ if (startContainer.nodeType === 3 && range.startOffset === 0 && previousNode && previousNode.nodeType !== 3 &&
+ // *em*|text
+ previousNode.classList.contains("vditor-ir__node") && !previousNode.getAttribute("data-block")) {
+ return previousNode;
+ }
+ return false;
+};
+var expandMarker = function (range, vditor) {
+ vditor.ir.element.querySelectorAll(".vditor-ir__node--expand").forEach(function (item) {
+ item.classList.remove("vditor-ir__node--expand");
+ });
+ var nodeElement = (0,hasClosest/* hasTopClosestByClassName */.JQ)(range.startContainer, "vditor-ir__node");
+ var nodeElementEnd = !range.collapsed && (0,hasClosest/* hasTopClosestByClassName */.JQ)(range.endContainer, "vditor-ir__node");
+ // 选中文本为同一个 nodeElement 内时,需要展开
+ if (!range.collapsed && (!nodeElement || nodeElement !== nodeElementEnd)) {
+ return;
+ }
+ if (nodeElement) {
+ nodeElement.classList.add("vditor-ir__node--expand");
+ nodeElement.classList.remove("vditor-ir__node--hidden");
+ // https://github.com/Vanessa219/vditor/issues/615 safari中光标位置跳动
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ var nextNode = nextIsNode(range);
+ if (nextNode) {
+ nextNode.classList.add("vditor-ir__node--expand");
+ nextNode.classList.remove("vditor-ir__node--hidden");
+ return;
+ }
+ var previousNode = previousIsNode(range);
+ if (previousNode) {
+ previousNode.classList.add("vditor-ir__node--expand");
+ previousNode.classList.remove("vditor-ir__node--hidden");
+ return;
+ }
+};
+
+;// CONCATENATED MODULE: ./src/ts/ir/processKeydown.ts
+
+
+
+
+
+
+
+
+
+
+
+var processKeydown = function (vditor, event) {
+ vditor.ir.composingLock = event.isComposing;
+ if (event.isComposing) {
+ return false;
+ }
+ // 添加第一次记录 undo 的光标
+ if (event.key.indexOf("Arrow") === -1 && event.key !== "Meta" && event.key !== "Control" && event.key !== "Alt" &&
+ event.key !== "Shift" && event.key !== "CapsLock" && event.key !== "Escape" && !/^F\d{1,2}$/.test(event.key)) {
+ vditor.undo.recordFirstPosition(vditor, event);
+ }
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var startContainer = range.startContainer;
+ if (!fixGSKeyBackspace(event, vditor, startContainer)) {
+ return false;
+ }
+ fixCJKPosition(range, vditor, event);
+ fixHR(range);
+ // 仅处理以下快捷键操作
+ if (event.key !== "Enter" && event.key !== "Tab" && event.key !== "Backspace" && event.key.indexOf("Arrow") === -1
+ && !(0,compatibility/* isCtrl */.yl)(event) && event.key !== "Escape" && event.key !== "Delete") {
+ return false;
+ }
+ // 斜体、粗体、内联代码块中换行
+ var newlineElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-newline", "1");
+ if (!(0,compatibility/* isCtrl */.yl)(event) && !event.altKey && !event.shiftKey && event.key === "Enter" && newlineElement
+ && range.startOffset < newlineElement.textContent.length) {
+ var beforeMarkerElement = newlineElement.previousElementSibling;
+ if (beforeMarkerElement) {
+ range.insertNode(document.createTextNode(beforeMarkerElement.textContent));
+ range.collapse(false);
+ }
+ var afterMarkerElement = newlineElement.nextSibling;
+ if (afterMarkerElement) {
+ range.insertNode(document.createTextNode(afterMarkerElement.textContent));
+ range.collapse(true);
+ }
+ }
+ var pElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "P");
+ // md 处理
+ if (fixMarkdown(event, vditor, pElement, range)) {
+ return true;
+ }
+ // li
+ if (fixList(range, vditor, pElement, event)) {
+ return true;
+ }
+ // blockquote
+ if (fixBlockquote(vditor, range, event, pElement)) {
+ return true;
+ }
+ // 代码块
+ var preRenderElement = (0,hasClosest/* hasClosestByClassName */.fb)(startContainer, "vditor-ir__marker--pre");
+ if (preRenderElement && preRenderElement.tagName === "PRE") {
+ var codeRenderElement = preRenderElement.firstChild;
+ if (fixCodeBlock(vditor, event, preRenderElement, range)) {
+ return true;
+ }
+ // 数学公式上无元素,按上或左将添加新块
+ if ((codeRenderElement.getAttribute("data-type") === "math-block"
+ || codeRenderElement.getAttribute("data-type") === "html-block") &&
+ insertBeforeBlock(vditor, event, range, codeRenderElement, preRenderElement.parentElement)) {
+ return true;
+ }
+ // 代码块下无元素或者为代码块/table 元素,添加空块
+ if (insertAfterBlock(vditor, event, range, codeRenderElement, preRenderElement.parentElement)) {
+ return true;
+ }
+ }
+ // 代码块语言
+ var preBeforeElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "code-block-info");
+ if (preBeforeElement) {
+ if (event.key === "Enter" || event.key === "Tab") {
+ range.selectNodeContents(preBeforeElement.nextElementSibling.firstChild);
+ range.collapse(true);
+ event.preventDefault();
+ hidePanel(vditor, ["hint"]);
+ return true;
+ }
+ if (event.key === "Backspace") {
+ var start = (0,selection/* getSelectPosition */.im)(preBeforeElement, vditor.ir.element).start;
+ if (start === 1) { // 删除零宽空格
+ range.setStart(startContainer, 0);
+ }
+ if (start === 2) { // 删除时清空自动补全语言
+ vditor.hint.recentLanguage = "";
+ }
+ }
+ if (insertBeforeBlock(vditor, event, range, preBeforeElement, preBeforeElement.parentElement)) {
+ // 上无元素,按上或左将添加新块
+ hidePanel(vditor, ["hint"]);
+ return true;
+ }
+ }
+ // table
+ var cellElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TD") ||
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TH");
+ if (event.key.indexOf("Arrow") > -1 && cellElement) {
+ var tableElement = isFirstCell(cellElement);
+ if (tableElement && insertBeforeBlock(vditor, event, range, cellElement, tableElement)) {
+ return true;
+ }
+ var table2Element = isLastCell(cellElement);
+ if (table2Element && insertAfterBlock(vditor, event, range, cellElement, table2Element)) {
+ return true;
+ }
+ }
+ if (fixTable(vditor, event, range)) {
+ return true;
+ }
+ // task list
+ if (fixTask(vditor, range, event)) {
+ return true;
+ }
+ // tab
+ if (fixTab(vditor, range, event)) {
+ return true;
+ }
+ var headingElement = (0,hasClosestByHeadings/* hasClosestByHeadings */.W)(startContainer);
+ if (headingElement) {
+ // enter++: 标题变大
+ if (matchHotKey("⌘=", event)) {
+ var headingMarkerElement = headingElement.querySelector(".vditor-ir__marker--heading");
+ if (headingMarkerElement && headingMarkerElement.textContent.trim().length > 1) {
+ process_processHeading(vditor, headingMarkerElement.textContent.substr(1));
+ }
+ event.preventDefault();
+ return true;
+ }
+ // enter++: 标题变小
+ if (matchHotKey("⌘-", event)) {
+ var headingMarkerElement = headingElement.querySelector(".vditor-ir__marker--heading");
+ if (headingMarkerElement && headingMarkerElement.textContent.trim().length < 6) {
+ process_processHeading(vditor, headingMarkerElement.textContent.trim() + "# ");
+ }
+ event.preventDefault();
+ return true;
+ }
+ }
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(startContainer);
+ if (event.key === "Backspace" && !(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey && range.toString() === "") {
+ if (fixDelete(vditor, range, event, pElement)) {
+ return true;
+ }
+ if (blockElement && blockElement.previousElementSibling
+ && blockElement.tagName !== "UL" && blockElement.tagName !== "OL"
+ && (blockElement.previousElementSibling.getAttribute("data-type") === "code-block" ||
+ blockElement.previousElementSibling.getAttribute("data-type") === "math-block")) {
+ var rangeStart = (0,selection/* getSelectPosition */.im)(blockElement, vditor.ir.element, range).start;
+ if (rangeStart === 0 || (rangeStart === 1 && blockElement.innerText.startsWith(constants/* Constants.ZWSP */.g.ZWSP))) {
+ // 当前块删除后光标落于代码渲染块上,当前块会被删除,因此需要阻止事件,不能和 keyup 中的代码块处理合并
+ range.selectNodeContents(blockElement.previousElementSibling.querySelector(".vditor-ir__marker--pre code"));
+ range.collapse(false);
+ expandMarker(range, vditor);
+ if (blockElement.textContent.trim().replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "") {
+ // 当前块为空且不是最后一个时,需要删除
+ blockElement.remove();
+ process_processAfterRender(vditor);
+ }
+ event.preventDefault();
+ return true;
+ }
+ }
+ // 光标位于标题前,marker 后
+ if (headingElement) {
+ var headingLength = headingElement.firstElementChild.textContent.length;
+ if ((0,selection/* getSelectPosition */.im)(headingElement, vditor.ir.element).start === headingLength && headingLength !== 0) {
+ range.setStart(headingElement.firstElementChild.firstChild, headingLength - 1);
+ range.collapse(true);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ }
+ }
+ if ((event.key === "ArrowUp" || event.key === "ArrowDown") && blockElement) {
+ // https://github.com/Vanessa219/vditor/issues/358
+ blockElement.querySelectorAll(".vditor-ir__node").forEach(function (item) {
+ if (!item.contains(startContainer)) {
+ item.classList.add("vditor-ir__node--hidden");
+ }
+ });
+ if (fixFirefoxArrowUpTable(event, blockElement, range)) {
+ return true;
+ }
+ }
+ fixCursorDownInlineMath(range, event.key);
+ if (blockElement && keydownToc(blockElement, vditor, event, range)) {
+ event.preventDefault();
+ return true;
+ }
+ return false;
+};
+
+// EXTERNAL MODULE: ./src/ts/preview/image.ts
+var preview_image = __webpack_require__(190);
+;// CONCATENATED MODULE: ./src/ts/sv/combineFootnote.ts
+/**
+ * 合并脚注
+ * @param elements vditor.sv.element
+ * @param afterCombine 每个脚注块合并完成后的回调, param: root为合并后的脚注块
+ */
+var combineFootnote = function (elements, afterCombine) {
+ elements.querySelectorAll("[data-type=footnotes-link]").forEach(function (el) {
+ var root = el.parentElement;
+ var footnote = root.nextSibling;
+ // 寻找所有该脚注的块
+ while (footnote) {
+ if (footnote.textContent.startsWith(" ")) {
+ // 解析到四个空格,加入到root并继续解析
+ var thisNode = footnote;
+ thisNode.childNodes.forEach(function (node) {
+ root.append(node.cloneNode(true));
+ });
+ footnote = footnote.nextSibling;
+ thisNode.remove();
+ }
+ else {
+ // 非空格停止解析
+ break;
+ }
+ }
+ afterCombine && afterCombine(root);
+ });
+};
+
+;// CONCATENATED MODULE: ./src/ts/sv/inputEvent.ts
+
+
+
+
+
+var inputEvent = function (vditor, event) {
+ var _a;
+ var range = getSelection().getRangeAt(0).cloneRange();
+ var startContainer = range.startContainer;
+ if (range.startContainer.nodeType !== 3 && range.startContainer.tagName === "DIV") {
+ startContainer = range.startContainer.childNodes[range.startOffset - 1];
+ }
+ var blockElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-block", "0");
+ // 不调用 lute 解析
+ if (blockElement && event && (event.inputType === "deleteContentBackward" || event.data === " ")) {
+ // 开始可以输入空格
+ var startOffset = (0,selection/* getSelectPosition */.im)(blockElement, vditor.sv.element, range).start;
+ var startSpace = true;
+ for (var i = startOffset - 1;
+ // 软换行后有空格
+ i > blockElement.textContent.substr(0, startOffset).lastIndexOf("\n"); i--) {
+ if (blockElement.textContent.charAt(i) !== " " &&
+ // 多个 tab 前删除不形成代码块 https://github.com/Vanessa219/vditor/issues/162 1
+ blockElement.textContent.charAt(i) !== "\t") {
+ startSpace = false;
+ break;
+ }
+ }
+ if (startOffset === 0) {
+ startSpace = false;
+ }
+ if (startSpace) {
+ processAfterRender(vditor);
+ return;
+ }
+ if (event.inputType === "deleteContentBackward") {
+ // https://github.com/Vanessa219/vditor/issues/584 代码块 marker 删除
+ var codeBlockMarkerElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "code-block-open-marker") ||
+ (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "code-block-close-marker");
+ if (codeBlockMarkerElement) {
+ if (codeBlockMarkerElement.getAttribute("data-type") === "code-block-close-marker") {
+ var openMarkerElement = getSideByType(startContainer, "code-block-open-marker");
+ if (openMarkerElement) {
+ openMarkerElement.textContent = codeBlockMarkerElement.textContent;
+ processAfterRender(vditor);
+ return;
+ }
+ }
+ if (codeBlockMarkerElement.getAttribute("data-type") === "code-block-open-marker") {
+ var openMarkerElement = getSideByType(startContainer, "code-block-close-marker", false);
+ if (openMarkerElement) {
+ openMarkerElement.textContent = codeBlockMarkerElement.textContent;
+ processAfterRender(vditor);
+ return;
+ }
+ }
+ }
+ // https://github.com/Vanessa219/vditor/issues/877 数学公式输入删除生成节点
+ var mathBlockMarkerElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "math-block-open-marker");
+ if (mathBlockMarkerElement) {
+ var mathBlockCloseElement = mathBlockMarkerElement.nextElementSibling.nextElementSibling;
+ if (mathBlockCloseElement && mathBlockCloseElement.getAttribute("data-type") === "math-block-close-marker") {
+ mathBlockCloseElement.remove();
+ processAfterRender(vditor);
+ }
+ return;
+ }
+ blockElement.querySelectorAll('[data-type="code-block-open-marker"]').forEach(function (item) {
+ if (item.textContent.length === 1) {
+ item.remove();
+ }
+ });
+ blockElement.querySelectorAll('[data-type="code-block-close-marker"]').forEach(function (item) {
+ if (item.textContent.length === 1) {
+ item.remove();
+ }
+ });
+ // 标题删除
+ var headingElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "heading-marker");
+ if (headingElement && headingElement.textContent.indexOf("#") === -1) {
+ processAfterRender(vditor);
+ return;
+ }
+ }
+ // 删除或空格不解析,否则会 format 回去
+ if ((event.data === " " || event.inputType === "deleteContentBackward") &&
+ ((0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "padding") // 场景:b 前进行删除 [> 1. a\n> b]
+ || (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "li-marker") // 场景:删除最后一个字符 [* 1\n* ]
+ || (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "task-marker") // 场景:删除最后一个字符 [* [ ] ]
+ || (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "blockquote-marker") // 场景:删除最后一个字符 [> ]
+ )) {
+ processAfterRender(vditor);
+ return;
+ }
+ }
+ if (blockElement && blockElement.textContent.trimRight() === "$$") {
+ // 内联数学公式
+ processAfterRender(vditor);
+ return;
+ }
+ if (!blockElement) {
+ blockElement = vditor.sv.element;
+ }
+ if (((_a = blockElement.firstElementChild) === null || _a === void 0 ? void 0 : _a.getAttribute("data-type")) === "link-ref-defs-block") {
+ // 修改链接引用
+ blockElement = vditor.sv.element;
+ }
+ if ((0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "footnotes-link")) {
+ // 修改脚注角标
+ blockElement = vditor.sv.element;
+ }
+ // 添加光标位置
+ if (blockElement.textContent.indexOf(Lute.Caret) === -1) {
+ // 点击工具栏会插入 Caret
+ range.insertNode(document.createTextNode(Lute.Caret));
+ }
+ // 清除浏览器自带的样式
+ blockElement.querySelectorAll("[style]").forEach(function (item) {
+ item.removeAttribute("style");
+ });
+ blockElement.querySelectorAll("font").forEach(function (item) {
+ item.outerHTML = item.innerHTML;
+ });
+ var html = blockElement.textContent;
+ var isSVElement = blockElement.isEqualNode(vditor.sv.element);
+ if (isSVElement) {
+ html = blockElement.textContent;
+ }
+ else {
+ // 添加前一个块元素
+ if (blockElement.previousElementSibling) {
+ html = blockElement.previousElementSibling.textContent + html;
+ blockElement.previousElementSibling.remove();
+ }
+ if (blockElement.previousElementSibling && html.indexOf("---\n") === 0) {
+ // 确认 yaml-front 是否为首行
+ html = blockElement.previousElementSibling.textContent + html;
+ blockElement.previousElementSibling.remove();
+ }
+ // 添加链接引用
+ var footnotes_1 = "";
+ vditor.sv.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach(function (item, index) {
+ if (item && !blockElement.isEqualNode(item.parentElement)) {
+ footnotes_1 += item.parentElement.textContent + "\n";
+ item.parentElement.remove();
+ }
+ });
+ // 添加脚注到文章头,便于lute处理
+ vditor.sv.element.querySelectorAll("[data-type='footnotes-link']").forEach(function (item, index) {
+ if (item && !blockElement.isEqualNode(item.parentElement)) {
+ footnotes_1 += item.parentElement.textContent + "\n";
+ item.parentElement.remove();
+ }
+ });
+ html = footnotes_1 + html;
+ }
+ html = processSpinVditorSVDOM(html, vditor);
+ if (isSVElement) {
+ blockElement.innerHTML = html;
+ }
+ else {
+ blockElement.outerHTML = html;
+ }
+ vditor.sv.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach(function (item) {
+ vditor.sv.element.insertAdjacentElement("beforeend", item.parentElement);
+ });
+ // 合并脚注
+ combineFootnote(vditor.sv.element, function (root) {
+ vditor.sv.element.insertAdjacentElement("beforeend", root);
+ });
+ (0,selection/* setRangeByWbr */.ib)(vditor.sv.element, range);
+ scrollCenter(vditor);
+ processAfterRender(vditor, {
+ enableAddUndoStack: true,
+ enableHint: true,
+ enableInput: true,
+ });
+};
+
+;// CONCATENATED MODULE: ./src/ts/sv/processKeydown.ts
+
+
+
+
+
+
+
+var processKeydown_processKeydown = function (vditor, event) {
+ var _a, _b, _c, _d, _e;
+ vditor.sv.composingLock = event.isComposing;
+ if (event.isComposing) {
+ return false;
+ }
+ if (event.key.indexOf("Arrow") === -1 && event.key !== "Meta" && event.key !== "Control" && event.key !== "Alt" &&
+ event.key !== "Shift" && event.key !== "CapsLock" && event.key !== "Escape" && !/^F\d{1,2}$/.test(event.key)) {
+ vditor.undo.recordFirstPosition(vditor, event);
+ }
+ // 仅处理以下快捷键操作
+ if (event.key !== "Enter" && event.key !== "Tab" && event.key !== "Backspace" && event.key.indexOf("Arrow") === -1
+ && !(0,compatibility/* isCtrl */.yl)(event) && event.key !== "Escape") {
+ return false;
+ }
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var startContainer = range.startContainer;
+ if (range.startContainer.nodeType !== 3 && range.startContainer.tagName === "DIV") {
+ startContainer = range.startContainer.childNodes[range.startOffset - 1];
+ }
+ var textElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "text");
+ // blockquote
+ var blockquoteMarkerElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "blockquote-marker");
+ if (!blockquoteMarkerElement && range.startOffset === 0 && textElement && textElement.previousElementSibling &&
+ textElement.previousElementSibling.getAttribute("data-type") === "blockquote-marker") {
+ blockquoteMarkerElement = textElement.previousElementSibling;
+ }
+ // 回车逐个删除 blockquote marker 标记
+ if (blockquoteMarkerElement) {
+ if (event.key === "Enter" && !(0,compatibility/* isCtrl */.yl)(event) && !event.altKey &&
+ blockquoteMarkerElement.nextElementSibling.textContent.trim() === "" &&
+ (0,selection/* getSelectPosition */.im)(blockquoteMarkerElement, vditor.sv.element, range).start ===
+ blockquoteMarkerElement.textContent.length) {
+ if (((_a = blockquoteMarkerElement.previousElementSibling) === null || _a === void 0 ? void 0 : _a.getAttribute("data-type")) === "padding") {
+ // 列表中存在多行 BQ 时,标记回车需跳出列表
+ blockquoteMarkerElement.previousElementSibling.setAttribute("data-action", "enter-remove");
+ }
+ blockquoteMarkerElement.remove();
+ processAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ }
+ // list item
+ var listMarkerElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "li-marker");
+ var taskMarkerElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "task-marker");
+ var listLastMarkerElement = listMarkerElement;
+ if (!listLastMarkerElement) {
+ if (taskMarkerElement && taskMarkerElement.nextElementSibling.getAttribute("data-type") !== "task-marker") {
+ listLastMarkerElement = taskMarkerElement;
+ }
+ }
+ if (!listLastMarkerElement && range.startOffset === 0 && textElement && textElement.previousElementSibling &&
+ (textElement.previousElementSibling.getAttribute("data-type") === "li-marker" ||
+ textElement.previousElementSibling.getAttribute("data-type") === "task-marker")) {
+ listLastMarkerElement = textElement.previousElementSibling;
+ }
+ if (listLastMarkerElement) {
+ var startIndex = (0,selection/* getSelectPosition */.im)(listLastMarkerElement, vditor.sv.element, range).start;
+ var isTask = listLastMarkerElement.getAttribute("data-type") === "task-marker";
+ var listFirstMarkerElement = listLastMarkerElement;
+ if (isTask) {
+ listFirstMarkerElement = listLastMarkerElement.previousElementSibling.previousElementSibling
+ .previousElementSibling;
+ }
+ if (startIndex === listLastMarkerElement.textContent.length) {
+ // 回车清空列表标记符
+ if (event.key === "Enter" && !(0,compatibility/* isCtrl */.yl)(event) && !event.altKey && !event.shiftKey &&
+ listLastMarkerElement.nextElementSibling.textContent.trim() === "") {
+ if (((_b = listFirstMarkerElement.previousElementSibling) === null || _b === void 0 ? void 0 : _b.getAttribute("data-type")) === "padding") {
+ listFirstMarkerElement.previousElementSibling.remove();
+ inputEvent(vditor);
+ }
+ else {
+ if (isTask) {
+ listFirstMarkerElement.remove();
+ listLastMarkerElement.previousElementSibling.previousElementSibling.remove();
+ listLastMarkerElement.previousElementSibling.remove();
+ }
+ listLastMarkerElement.nextElementSibling.remove();
+ listLastMarkerElement.remove();
+ processAfterRender(vditor);
+ }
+ event.preventDefault();
+ return true;
+ }
+ // 第一个 marker 后 tab 进行缩进
+ if (event.key === "Tab") {
+ if (event.shiftKey) {
+ if (listFirstMarkerElement.previousElementSibling.getAttribute("data-type") === "padding") {
+ listFirstMarkerElement.previousElementSibling.remove();
+ }
+ }
+ else {
+ listFirstMarkerElement.insertAdjacentHTML("beforebegin", "".concat(listFirstMarkerElement.textContent.replace(/\S/g, " "), ""));
+ }
+ if (/^\d/.test(listFirstMarkerElement.textContent)) {
+ listFirstMarkerElement.textContent = listFirstMarkerElement.textContent.replace(/^\d{1,}/, "1");
+ range.selectNodeContents(listLastMarkerElement.firstChild);
+ range.collapse(false);
+ }
+ inputEvent(vditor);
+ event.preventDefault();
+ return true;
+ }
+ }
+ }
+ // tab
+ if (fixTab(vditor, range, event)) {
+ return true;
+ }
+ var blockElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-block", "0");
+ var spanElement = (0,hasClosestByHeadings/* hasClosestByTag */.S)(startContainer, "SPAN");
+ // 回车
+ if (event.key === "Enter" && !(0,compatibility/* isCtrl */.yl)(event) && !event.altKey && !event.shiftKey && blockElement) {
+ var isFirst = false;
+ var newLineMatch = blockElement.textContent.match(/^\n+/);
+ if ((0,selection/* getSelectPosition */.im)(blockElement, vditor.sv.element).start <= (newLineMatch ? newLineMatch[0].length : 0)) {
+ // 允许段落开始换行
+ isFirst = true;
+ }
+ var newLineText = "\n";
+ if (spanElement) {
+ if (((_c = spanElement.previousElementSibling) === null || _c === void 0 ? void 0 : _c.getAttribute("data-action")) === "enter-remove") {
+ // https://github.com/Vanessa219/vditor/issues/596
+ spanElement.previousElementSibling.remove();
+ processAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ else {
+ newLineText += processPreviousMarkers(spanElement);
+ }
+ }
+ range.insertNode(document.createTextNode(newLineText));
+ range.collapse(false);
+ if (blockElement && blockElement.textContent.trim() !== "" && !isFirst) {
+ inputEvent(vditor);
+ }
+ else {
+ processAfterRender(vditor);
+ }
+ event.preventDefault();
+ return true;
+ }
+ // 删除后光标前有 newline 的处理
+ if (event.key === "Backspace" && !(0,compatibility/* isCtrl */.yl)(event) && !event.altKey && !event.shiftKey) {
+ if (spanElement && ((_d = spanElement.previousElementSibling) === null || _d === void 0 ? void 0 : _d.getAttribute("data-type")) === "newline" &&
+ (0,selection/* getSelectPosition */.im)(spanElement, vditor.sv.element, range).start === 1 &&
+ // 飘号的处理需在 inputEvent 中,否则上下飘号对不齐
+ spanElement.getAttribute("data-type").indexOf("code-block-") === -1) {
+ // 光标在每一行的第一个字符后
+ range.setStart(spanElement, 0);
+ range.extractContents();
+ if (spanElement.textContent.trim() !== "") {
+ inputEvent(vditor);
+ }
+ else {
+ processAfterRender(vditor);
+ }
+ event.preventDefault();
+ return true;
+ }
+ // 每一段第一个字符前
+ if (blockElement && (0,selection/* getSelectPosition */.im)(blockElement, vditor.sv.element, range).start === 0 &&
+ blockElement.previousElementSibling) {
+ range.extractContents();
+ var previousLastElement = blockElement.previousElementSibling.lastElementChild;
+ if (previousLastElement.getAttribute("data-type") === "newline") {
+ previousLastElement.remove();
+ previousLastElement = blockElement.previousElementSibling.lastElementChild;
+ }
+ // 场景:末尾无法删除 [```\ntext\n```\n\n]
+ if (previousLastElement.getAttribute("data-type") !== "newline") {
+ previousLastElement.insertAdjacentHTML("afterend", blockElement.innerHTML);
+ blockElement.remove();
+ }
+ if (blockElement.textContent.trim() !== "" && !((_e = blockElement.previousElementSibling) === null || _e === void 0 ? void 0 : _e.querySelector('[data-type="code-block-open-marker"]'))) {
+ inputEvent(vditor);
+ }
+ else {
+ if (previousLastElement.getAttribute("data-type") !== "newline") {
+ // https://github.com/Vanessa219/vditor/issues/597
+ range.selectNodeContents(previousLastElement.lastChild);
+ range.collapse(false);
+ }
+ processAfterRender(vditor);
+ }
+ event.preventDefault();
+ return true;
+ }
+ }
+ return false;
+};
+
+// EXTERNAL MODULE: ./src/ts/ui/setContentTheme.ts
+var setContentTheme = __webpack_require__(538);
+;// CONCATENATED MODULE: ./src/ts/ui/setTheme.ts
+var setTheme = function (vditor) {
+ if (vditor.options.theme === "dark") {
+ vditor.element.classList.add("vditor--dark");
+ }
+ else {
+ vditor.element.classList.remove("vditor--dark");
+ }
+};
+
+;// CONCATENATED MODULE: ./src/ts/ui/initUI.ts
+
+
+
+
+
+
+var initUI = function (vditor) {
+ vditor.element.innerHTML = "";
+ vditor.element.classList.add("vditor");
+ // 支持 RTL
+ if (vditor.options.rtl) {
+ vditor.element.setAttribute("dir", "rtl");
+ }
+ setTheme(vditor);
+ (0,setContentTheme/* setContentTheme */.Z)(vditor.options.preview.theme.current, vditor.options.preview.theme.path);
+ if (typeof vditor.options.height === "number") {
+ vditor.element.style.height = vditor.options.height + "px";
+ }
+ else {
+ vditor.element.style.height = vditor.options.height;
+ }
+ if (typeof vditor.options.minHeight === "number") {
+ vditor.element.style.minHeight = vditor.options.minHeight + "px";
+ }
+ if (typeof vditor.options.width === "number") {
+ vditor.element.style.width = vditor.options.width + "px";
+ }
+ else {
+ vditor.element.style.width = vditor.options.width;
+ }
+ vditor.element.appendChild(vditor.toolbar.element);
+ var contentElement = document.createElement("div");
+ contentElement.className = "vditor-content";
+ if (vditor.options.outline.position === "left") {
+ contentElement.appendChild(vditor.outline.element);
+ }
+ contentElement.appendChild(vditor.wysiwyg.element.parentElement);
+ contentElement.appendChild(vditor.sv.element);
+ contentElement.appendChild(vditor.ir.element.parentElement);
+ contentElement.appendChild(vditor.preview.element);
+ if (vditor.toolbar.elements.devtools) {
+ contentElement.appendChild(vditor.devtools.element);
+ }
+ if (vditor.options.outline.position === "right") {
+ vditor.outline.element.classList.add("vditor-outline--right");
+ contentElement.appendChild(vditor.outline.element);
+ }
+ if (vditor.upload) {
+ contentElement.appendChild(vditor.upload.element);
+ }
+ if (vditor.options.resize.enable) {
+ contentElement.appendChild(vditor.resize.element);
+ }
+ contentElement.appendChild(vditor.hint.element);
+ contentElement.appendChild(vditor.tip.element);
+ vditor.element.appendChild(contentElement);
+ contentElement.addEventListener("click", function () {
+ hidePanel(vditor, ["subToolbar"]);
+ });
+ if (vditor.toolbar.elements.export) {
+ // for export pdf
+ vditor.element.insertAdjacentHTML("beforeend", '');
+ }
+ setEditMode(vditor, vditor.options.mode, afterRender(vditor));
+ document.execCommand("DefaultParagraphSeparator", false, "p");
+ if (navigator.userAgent.indexOf("iPhone") > -1 && typeof window.visualViewport !== "undefined") {
+ // https://github.com/Vanessa219/vditor/issues/379
+ var pendingUpdate_1 = false;
+ var viewportHandler = function (event) {
+ if (pendingUpdate_1) {
+ return;
+ }
+ pendingUpdate_1 = true;
+ requestAnimationFrame(function () {
+ pendingUpdate_1 = false;
+ var layoutViewport = vditor.toolbar.element;
+ layoutViewport.style.transform = "none";
+ if (layoutViewport.getBoundingClientRect().top < 0) {
+ layoutViewport.style.transform = "translate(0, ".concat(-layoutViewport.getBoundingClientRect().top, "px)");
+ }
+ });
+ };
+ window.visualViewport.addEventListener("scroll", viewportHandler);
+ window.visualViewport.addEventListener("resize", viewportHandler);
+ }
+};
+var setPadding = function (vditor) {
+ var minPadding = window.innerWidth <= constants/* Constants.MOBILE_WIDTH */.g.MOBILE_WIDTH ? 10 : 35;
+ if (vditor.wysiwyg.element.parentElement.style.display !== "none") {
+ var padding = (vditor.wysiwyg.element.parentElement.clientWidth
+ - vditor.options.preview.maxWidth) / 2;
+ vditor.wysiwyg.element.style.padding = "10px ".concat(Math.max(minPadding, padding), "px");
+ }
+ if (vditor.ir.element.parentElement.style.display !== "none") {
+ var padding = (vditor.ir.element.parentElement.clientWidth
+ - vditor.options.preview.maxWidth) / 2;
+ vditor.ir.element.style.padding = "10px ".concat(Math.max(minPadding, padding), "px");
+ }
+ if (vditor.preview.element.style.display !== "block") {
+ vditor.toolbar.element.style.paddingLeft = Math.max(5, parseInt(vditor[vditor.currentMode].element.style.paddingLeft || "0", 10) +
+ (vditor.options.outline.position === "left" ? vditor.outline.element.offsetWidth : 0)) + "px";
+ }
+ else {
+ vditor.toolbar.element.style.paddingLeft = (5 +
+ (vditor.options.outline.position === "left" ? vditor.outline.element.offsetWidth : 0)) + "px";
+ }
+};
+var setTypewriterPosition = function (vditor) {
+ if (!vditor.options.typewriterMode) {
+ return;
+ }
+ var height = window.innerHeight;
+ if (typeof vditor.options.height === "number") {
+ height = vditor.options.height;
+ if (typeof vditor.options.minHeight === "number") {
+ height = Math.max(height, vditor.options.minHeight);
+ }
+ height = Math.min(window.innerHeight, height);
+ }
+ else {
+ height = vditor.element.clientHeight;
+ }
+ if (vditor.element.classList.contains("vditor--fullscreen")) {
+ height = window.innerHeight;
+ }
+ // 由于 Firefox padding-bottom bug,只能使用 :after
+ vditor[vditor.currentMode].element.style.setProperty("--editor-bottom", ((height - vditor.toolbar.element.offsetHeight) / 2) + "px");
+};
+var resizeCb;
+function UIUnbindListener() {
+ window.removeEventListener("resize", resizeCb);
+}
+var afterRender = function (vditor) {
+ setTypewriterPosition(vditor);
+ UIUnbindListener();
+ window.addEventListener("resize", resizeCb = function () {
+ setPadding(vditor);
+ setTypewriterPosition(vditor);
+ });
+ // set default value
+ var initValue = (0,compatibility/* accessLocalStorage */.pK)() && localStorage.getItem(vditor.options.cache.id);
+ if (!vditor.options.cache.enable || !initValue) {
+ if (vditor.options.value) {
+ initValue = vditor.options.value;
+ }
+ else if (vditor.originalInnerHTML) {
+ initValue = vditor.lute.HTML2Md(vditor.originalInnerHTML);
+ }
+ else if (!vditor.options.cache.enable) {
+ initValue = "";
+ }
+ }
+ return initValue || "";
+};
+
+;// CONCATENATED MODULE: ./src/ts/ir/highlightToolbarIR.ts
+
+
+
+
+
+var highlightToolbarIR = function (vditor) {
+ clearTimeout(vditor[vditor.currentMode].hlToolbarTimeoutId);
+ vditor[vditor.currentMode].hlToolbarTimeoutId = window.setTimeout(function () {
+ if (vditor[vditor.currentMode].element.getAttribute("contenteditable") === "false") {
+ return;
+ }
+ if (!(0,selection/* selectIsEditor */.Gb)(vditor[vditor.currentMode].element)) {
+ return;
+ }
+ removeCurrentToolbar(vditor.toolbar.elements, constants/* Constants.EDIT_TOOLBARS */.g.EDIT_TOOLBARS);
+ enableToolbar(vditor.toolbar.elements, constants/* Constants.EDIT_TOOLBARS */.g.EDIT_TOOLBARS);
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var typeElement = range.startContainer;
+ if (range.startContainer.nodeType === 3) {
+ typeElement = range.startContainer.parentElement;
+ }
+ if (typeElement.classList.contains("vditor-reset")) {
+ typeElement = typeElement.childNodes[range.startOffset];
+ }
+ var headingElement = vditor.currentMode === "sv" ?
+ (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "heading") : (0,hasClosestByHeadings/* hasClosestByHeadings */.W)(typeElement);
+ if (headingElement) {
+ setCurrentToolbar(vditor.toolbar.elements, ["headings"]);
+ }
+ var quoteElement = vditor.currentMode === "sv" ? (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "blockquote") :
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "BLOCKQUOTE");
+ if (quoteElement) {
+ setCurrentToolbar(vditor.toolbar.elements, ["quote"]);
+ }
+ var strongElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "strong");
+ if (strongElement) {
+ setCurrentToolbar(vditor.toolbar.elements, ["bold"]);
+ }
+ var emElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "em");
+ if (emElement) {
+ setCurrentToolbar(vditor.toolbar.elements, ["italic"]);
+ }
+ var sElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "s");
+ if (sElement) {
+ setCurrentToolbar(vditor.toolbar.elements, ["strike"]);
+ }
+ var aElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "a");
+ if (aElement) {
+ setCurrentToolbar(vditor.toolbar.elements, ["link"]);
+ }
+ var liElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "LI");
+ if (liElement) {
+ if (liElement.classList.contains("vditor-task")) {
+ setCurrentToolbar(vditor.toolbar.elements, ["check"]);
+ }
+ else if (liElement.parentElement.tagName === "OL") {
+ setCurrentToolbar(vditor.toolbar.elements, ["ordered-list"]);
+ }
+ else if (liElement.parentElement.tagName === "UL") {
+ setCurrentToolbar(vditor.toolbar.elements, ["list"]);
+ }
+ enableToolbar(vditor.toolbar.elements, ["outdent", "indent"]);
+ }
+ else {
+ disableToolbar(vditor.toolbar.elements, ["outdent", "indent"]);
+ }
+ var codeBlockElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "code-block");
+ if (codeBlockElement) {
+ disableToolbar(vditor.toolbar.elements, ["headings", "bold", "italic", "strike", "line", "quote",
+ "list", "ordered-list", "check", "code", "inline-code", "upload", "link", "table", "record"]);
+ setCurrentToolbar(vditor.toolbar.elements, ["code"]);
+ }
+ var codeElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "code");
+ if (codeElement) {
+ disableToolbar(vditor.toolbar.elements, ["headings", "bold", "italic", "strike", "line", "quote",
+ "list", "ordered-list", "check", "code", "upload", "link", "table", "record"]);
+ setCurrentToolbar(vditor.toolbar.elements, ["inline-code"]);
+ }
+ var tableElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "table");
+ if (tableElement) {
+ disableToolbar(vditor.toolbar.elements, ["headings", "list", "ordered-list", "check", "line",
+ "quote", "code", "table"]);
+ }
+ }, 200);
+};
+
+;// CONCATENATED MODULE: ./src/ts/wysiwyg/afterRenderEvent.ts
+
+
+var afterRenderEvent = function (vditor, options) {
+ if (options === void 0) { options = {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: true,
+ }; }
+ if (options.enableHint) {
+ vditor.hint.render(vditor);
+ }
+ clearTimeout(vditor.wysiwyg.afterRenderTimeoutId);
+ vditor.wysiwyg.afterRenderTimeoutId = window.setTimeout(function () {
+ if (vditor.wysiwyg.composingLock) {
+ return;
+ }
+ var text = getMarkdown(vditor);
+ if (typeof vditor.options.input === "function" && options.enableInput) {
+ vditor.options.input(text);
+ }
+ if (vditor.options.counter.enable) {
+ vditor.counter.render(vditor, text);
+ }
+ if (vditor.options.cache.enable && (0,compatibility/* accessLocalStorage */.pK)()) {
+ localStorage.setItem(vditor.options.cache.id, text);
+ if (vditor.options.cache.after) {
+ vditor.options.cache.after(text);
+ }
+ }
+ if (vditor.devtools) {
+ vditor.devtools.renderEchart(vditor);
+ }
+ if (options.enableAddUndoStack) {
+ vditor.undo.addToUndoStack(vditor);
+ }
+ }, vditor.options.undoDelay);
+};
+
+;// CONCATENATED MODULE: ./src/ts/wysiwyg/inlineTag.ts
+
+
+var previoueIsEmptyA = function (node) {
+ var previousNode = node.previousSibling;
+ while (previousNode) {
+ if (previousNode.nodeType !== 3 && previousNode.tagName === "A" && !previousNode.previousSibling
+ && previousNode.innerHTML.replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" && previousNode.nextSibling) {
+ return previousNode;
+ }
+ previousNode = previousNode.previousSibling;
+ }
+ return false;
+};
+var nextIsCode = function (range) {
+ var nextNode = range.startContainer.nextSibling;
+ while (nextNode && nextNode.textContent === "") {
+ nextNode = nextNode.nextSibling;
+ }
+ if (nextNode && nextNode.nodeType !== 3 && (nextNode.tagName === "CODE" ||
+ nextNode.getAttribute("data-type") === "math-inline" ||
+ nextNode.getAttribute("data-type") === "html-entity" ||
+ nextNode.getAttribute("data-type") === "html-inline")) {
+ return true;
+ }
+ return false;
+};
+var getNextHTML = function (node) {
+ var html = "";
+ var nextNode = node.nextSibling;
+ while (nextNode) {
+ if (nextNode.nodeType === 3) {
+ html += nextNode.textContent;
+ }
+ else {
+ html += nextNode.outerHTML;
+ }
+ nextNode = nextNode.nextSibling;
+ }
+ return html;
+};
+var getPreviousHTML = function (node) {
+ var html = "";
+ var previousNode = node.previousSibling;
+ while (previousNode) {
+ if (previousNode.nodeType === 3) {
+ html = previousNode.textContent + html;
+ }
+ else {
+ html = previousNode.outerHTML + html;
+ }
+ previousNode = previousNode.previousSibling;
+ }
+ return html;
+};
+var getRenderElementNextNode = function (blockCodeElement) {
+ var nextNode = blockCodeElement;
+ while (nextNode && !nextNode.nextSibling) {
+ nextNode = nextNode.parentElement;
+ }
+ return nextNode.nextSibling;
+};
+var splitElement = function (range) {
+ var previousHTML = getPreviousHTML(range.startContainer);
+ var nextHTML = getNextHTML(range.startContainer);
+ var text = range.startContainer.textContent;
+ var offset = range.startOffset;
+ var beforeHTML = "";
+ var afterHTML = "";
+ if (text.substr(0, offset) !== "" && text.substr(0, offset) !== constants/* Constants.ZWSP */.g.ZWSP || previousHTML) {
+ beforeHTML = "".concat(previousHTML).concat(text.substr(0, offset));
+ }
+ if (text.substr(offset) !== "" && text.substr(offset) !== constants/* Constants.ZWSP */.g.ZWSP || nextHTML) {
+ afterHTML = "".concat(text.substr(offset)).concat(nextHTML);
+ }
+ return {
+ afterHTML: afterHTML,
+ beforeHTML: beforeHTML,
+ };
+};
+var modifyPre = function (vditor, range) {
+ // 没有被块元素包裹
+ Array.from(vditor.wysiwyg.element.childNodes).find(function (node) {
+ if (node.nodeType === 3) {
+ var pElement = document.createElement("p");
+ pElement.setAttribute("data-block", "0");
+ pElement.textContent = node.textContent;
+ // 为空按下 tab 且 tab = ' ' 时,range.startContainer 不为 node
+ var cloneRangeOffset = range.startContainer.nodeType === 3 ? range.startOffset : node.textContent.length;
+ node.parentNode.insertBefore(pElement, node);
+ node.remove();
+ range.setStart(pElement.firstChild, Math.min(pElement.firstChild.textContent.length, cloneRangeOffset));
+ range.collapse(true);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ return true;
+ }
+ else if (!node.getAttribute("data-block")) {
+ if (node.tagName === "P") {
+ node.remove();
+ }
+ else {
+ if (node.tagName === "DIV") {
+ range.insertNode(document.createElement("wbr"));
+ // firefox 列表换行产生 div
+ node.outerHTML = "".concat(node.innerHTML, "
");
+ }
+ else {
+ if (node.tagName === "BR") {
+ // firefox 空换行产生 BR
+ node.outerHTML = "".concat(node.outerHTML, "
");
+ }
+ else {
+ range.insertNode(document.createElement("wbr"));
+ node.outerHTML = "".concat(node.outerHTML, "
");
+ }
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ range = getSelection().getRangeAt(0);
+ }
+ return true;
+ }
+ });
+};
+
+;// CONCATENATED MODULE: ./src/ts/wysiwyg/setHeading.ts
+
+
+
+var setHeading = function (vditor, tagName) {
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer);
+ if (!blockElement) {
+ blockElement = range.startContainer.childNodes[range.startOffset];
+ }
+ if (!blockElement && vditor.wysiwyg.element.children.length === 0) {
+ blockElement = vditor.wysiwyg.element;
+ }
+ if (blockElement && !blockElement.classList.contains("vditor-wysiwyg__block")) {
+ range.insertNode(document.createElement("wbr"));
+ // Firefox 需要 trim https://github.com/Vanessa219/vditor/issues/207
+ if (blockElement.innerHTML.trim() === "") {
+ // Firefox 光标对不齐 https://github.com/Vanessa219/vditor/issues/199 1
+ blockElement.innerHTML = "
";
+ }
+ if (blockElement.tagName === "BLOCKQUOTE" || blockElement.classList.contains("vditor-reset")) {
+ blockElement.innerHTML = "<".concat(tagName, " data-block=\"0\">").concat(blockElement.innerHTML.trim(), "").concat(tagName, ">");
+ }
+ else {
+ blockElement.outerHTML = "<".concat(tagName, " data-block=\"0\">").concat(blockElement.innerHTML.trim(), "").concat(tagName, ">");
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ renderToc(vditor);
+ }
+};
+var removeHeading = function (vditor) {
+ var range = getSelection().getRangeAt(0);
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer);
+ if (!blockElement) {
+ blockElement = range.startContainer.childNodes[range.startOffset];
+ }
+ if (blockElement) {
+ range.insertNode(document.createElement("wbr"));
+ blockElement.outerHTML = "".concat(blockElement.innerHTML, "
");
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ }
+ vditor.wysiwyg.popover.style.display = "none";
+};
+
+;// CONCATENATED MODULE: ./src/ts/wysiwyg/showCode.ts
+
+
+var showCode = function (previewElement, vditor, first) {
+ if (first === void 0) { first = true; }
+ var previousElement = previewElement.previousElementSibling;
+ var range = previousElement.ownerDocument.createRange();
+ if (previousElement.tagName === "CODE") {
+ previousElement.style.display = "inline-block";
+ if (first) {
+ range.setStart(previousElement.firstChild, 1);
+ }
+ else {
+ range.selectNodeContents(previousElement);
+ }
+ }
+ else {
+ previousElement.style.display = "block";
+ if (!previousElement.firstChild.firstChild) {
+ previousElement.firstChild.appendChild(document.createTextNode(""));
+ }
+ range.selectNodeContents(previousElement.firstChild);
+ }
+ if (first) {
+ range.collapse(true);
+ }
+ else {
+ range.collapse(false);
+ }
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ if (previewElement.firstElementChild.classList.contains("language-mindmap")) {
+ return;
+ }
+ scrollCenter(vditor);
+};
+
+;// CONCATENATED MODULE: ./src/ts/wysiwyg/processKeydown.ts
+
+
+
+
+
+
+
+
+
+
+
+
+
+var wysiwyg_processKeydown_processKeydown = function (vditor, event) {
+ // Chrome firefox 触发 compositionend 机制不一致 https://github.com/Vanessa219/vditor/issues/188
+ vditor.wysiwyg.composingLock = event.isComposing;
+ if (event.isComposing) {
+ return false;
+ }
+ // 添加第一次记录 undo 的光标
+ if (event.key.indexOf("Arrow") === -1 && event.key !== "Meta" && event.key !== "Control" && event.key !== "Alt" &&
+ event.key !== "Shift" && event.key !== "CapsLock" && event.key !== "Escape" && !/^F\d{1,2}$/.test(event.key)) {
+ vditor.undo.recordFirstPosition(vditor, event);
+ }
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var startContainer = range.startContainer;
+ if (!fixGSKeyBackspace(event, vditor, startContainer)) {
+ return false;
+ }
+ fixCJKPosition(range, vditor, event);
+ fixHR(range);
+ // 仅处理以下快捷键操作
+ if (event.key !== "Enter" && event.key !== "Tab" && event.key !== "Backspace" && event.key.indexOf("Arrow") === -1
+ && !(0,compatibility/* isCtrl */.yl)(event) && event.key !== "Escape" && event.key !== "Delete") {
+ return false;
+ }
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(startContainer);
+ var pElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "P");
+ // md 处理
+ if (fixMarkdown(event, vditor, pElement, range)) {
+ return true;
+ }
+ // li
+ if (fixList(range, vditor, pElement, event)) {
+ return true;
+ }
+ // table
+ if (fixTable(vditor, event, range)) {
+ return true;
+ }
+ // code render
+ var codeRenderElement = (0,hasClosest/* hasClosestByClassName */.fb)(startContainer, "vditor-wysiwyg__block");
+ if (codeRenderElement) {
+ // esc: 退出编辑,仅展示渲染
+ if (event.key === "Escape" && codeRenderElement.children.length === 2) {
+ vditor.wysiwyg.popover.style.display = "none";
+ codeRenderElement.firstElementChild.style.display = "none";
+ vditor.wysiwyg.element.blur();
+ event.preventDefault();
+ return true;
+ }
+ // alt+enter: 代码块切换到语言 https://github.com/Vanessa219/vditor/issues/54
+ if (!(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && event.altKey && event.key === "Enter" &&
+ codeRenderElement.getAttribute("data-type") === "code-block") {
+ var inputElemment = vditor.wysiwyg.popover.querySelector(".vditor-input");
+ inputElemment.focus();
+ inputElemment.select();
+ event.preventDefault();
+ return true;
+ }
+ if (codeRenderElement.getAttribute("data-block") === "0") {
+ if (fixCodeBlock(vditor, event, codeRenderElement.firstElementChild, range)) {
+ return true;
+ }
+ if (insertAfterBlock(vditor, event, range, codeRenderElement.firstElementChild, codeRenderElement)) {
+ return true;
+ }
+ if (codeRenderElement.getAttribute("data-type") !== "yaml-front-matter" &&
+ insertBeforeBlock(vditor, event, range, codeRenderElement.firstElementChild, codeRenderElement)) {
+ return true;
+ }
+ }
+ }
+ // blockquote
+ if (fixBlockquote(vditor, range, event, pElement)) {
+ return true;
+ }
+ // 顶层 blockquote
+ var topBQElement = (0,hasClosest/* hasTopClosestByTag */.E2)(startContainer, "BLOCKQUOTE");
+ if (topBQElement) {
+ if (!event.shiftKey && event.altKey && event.key === "Enter") {
+ if (!(0,compatibility/* isCtrl */.yl)(event)) {
+ // alt+enter: 跳出多层 blockquote 嵌套之后 https://github.com/Vanessa219/vditor/issues/51
+ range.setStartAfter(topBQElement);
+ }
+ else {
+ // ctrl+alt+enter: 跳出多层 blockquote 嵌套之前
+ range.setStartBefore(topBQElement);
+ }
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ var node = document.createElement("p");
+ node.setAttribute("data-block", "0");
+ node.innerHTML = "\n";
+ range.insertNode(node);
+ range.collapse(true);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ afterRenderEvent(vditor);
+ scrollCenter(vditor);
+ event.preventDefault();
+ return true;
+ }
+ }
+ // h1-h6
+ var headingElement = (0,hasClosestByHeadings/* hasClosestByHeadings */.W)(startContainer);
+ if (headingElement) {
+ if (headingElement.tagName === "H6" && startContainer.textContent.length === range.startOffset &&
+ !(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey && event.key === "Enter") {
+ // enter: H6 回车解析问题 https://github.com/Vanessa219/vditor/issues/48
+ var pTempElement = document.createElement("p");
+ pTempElement.textContent = "\n";
+ pTempElement.setAttribute("data-block", "0");
+ startContainer.parentElement.insertAdjacentElement("afterend", pTempElement);
+ range.setStart(pTempElement, 0);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ afterRenderEvent(vditor);
+ scrollCenter(vditor);
+ event.preventDefault();
+ return true;
+ }
+ // enter++: 标题变大
+ if (matchHotKey("⌘=", event)) {
+ var index = parseInt(headingElement.tagName.substr(1), 10) - 1;
+ if (index > 0) {
+ setHeading(vditor, "h".concat(index));
+ afterRenderEvent(vditor);
+ }
+ event.preventDefault();
+ return true;
+ }
+ // enter++: 标题变小
+ if (matchHotKey("⌘-", event)) {
+ var index = parseInt(headingElement.tagName.substr(1), 10) + 1;
+ if (index < 7) {
+ setHeading(vditor, "h".concat(index));
+ afterRenderEvent(vditor);
+ }
+ event.preventDefault();
+ return true;
+ }
+ if (event.key === "Backspace" && !(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey
+ && headingElement.textContent.length === 1) {
+ // 删除后变为空
+ removeHeading(vditor);
+ }
+ }
+ // task list
+ if (fixTask(vditor, range, event)) {
+ return true;
+ }
+ // alt+enter
+ if (event.altKey && event.key === "Enter" && !(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey) {
+ // 切换到链接、链接引用、脚注引用弹出的输入框中
+ var aElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "A");
+ var linRefElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "link-ref");
+ var footnoteRefElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "footnotes-ref");
+ if (aElement || linRefElement || footnoteRefElement ||
+ (headingElement && headingElement.tagName.length === 2)) {
+ var inputElement = vditor.wysiwyg.popover.querySelector("input");
+ inputElement.focus();
+ inputElement.select();
+ }
+ }
+ // 删除有子工具栏的块
+ if (removeBlockElement(vditor, event)) {
+ return true;
+ }
+ // 对有子工具栏的块上移
+ if (matchHotKey("⇧⌘U", event)) {
+ var itemElement = vditor.wysiwyg.popover.querySelector('[data-type="up"]');
+ if (itemElement) {
+ itemElement.click();
+ event.preventDefault();
+ return true;
+ }
+ }
+ // 对有子工具栏的块下移
+ if (matchHotKey("⇧⌘D", event)) {
+ var itemElement = vditor.wysiwyg.popover.querySelector('[data-type="down"]');
+ if (itemElement) {
+ itemElement.click();
+ event.preventDefault();
+ return true;
+ }
+ }
+ if (fixTab(vditor, range, event)) {
+ return true;
+ }
+ // shift+enter:软换行,但 table/hr/heading 处理、cell 内换行、block render 换行处理单独写在上面,li & p 使用浏览器默认
+ if (!(0,compatibility/* isCtrl */.yl)(event) && event.shiftKey && !event.altKey && event.key === "Enter" &&
+ startContainer.parentElement.tagName !== "LI" && startContainer.parentElement.tagName !== "P") {
+ if (["STRONG", "STRIKE", "S", "I", "EM", "B"].includes(startContainer.parentElement.tagName)) {
+ // 行内元素软换行需继续 https://github.com/Vanessa219/vditor/issues/170
+ range.insertNode(document.createTextNode("\n" + constants/* Constants.ZWSP */.g.ZWSP));
+ }
+ else {
+ range.insertNode(document.createTextNode("\n"));
+ }
+ range.collapse(false);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ afterRenderEvent(vditor);
+ scrollCenter(vditor);
+ event.preventDefault();
+ return true;
+ }
+ // 删除
+ if (event.key === "Backspace" && !(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey && range.toString() === "") {
+ if (fixDelete(vditor, range, event, pElement)) {
+ return true;
+ }
+ if (blockElement) {
+ if (blockElement.previousElementSibling
+ && blockElement.previousElementSibling.classList.contains("vditor-wysiwyg__block")
+ && blockElement.previousElementSibling.getAttribute("data-block") === "0"
+ // https://github.com/Vanessa219/vditor/issues/946
+ && blockElement.tagName !== "UL" && blockElement.tagName !== "OL") {
+ var rangeStart = (0,selection/* getSelectPosition */.im)(blockElement, vditor.wysiwyg.element, range).start;
+ if ((rangeStart === 0 && range.startOffset === 0) || // https://github.com/Vanessa219/vditor/issues/894
+ (rangeStart === 1 && blockElement.innerText.startsWith(constants/* Constants.ZWSP */.g.ZWSP))) {
+ // 当前块删除后光标落于代码渲染块上,当前块会被删除,因此需要阻止事件,不能和 keyup 中的代码块处理合并
+ showCode(blockElement.previousElementSibling.lastElementChild, vditor, false);
+ if (blockElement.innerHTML.trim().replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "") {
+ // 当前块为空且不是最后一个时,需要删除
+ blockElement.remove();
+ afterRenderEvent(vditor);
+ }
+ event.preventDefault();
+ return true;
+ }
+ }
+ var rangeStartOffset = range.startOffset;
+ if (range.toString() === "" && startContainer.nodeType === 3 &&
+ startContainer.textContent.charAt(rangeStartOffset - 2) === "\n" &&
+ startContainer.textContent.charAt(rangeStartOffset - 1) !== constants/* Constants.ZWSP */.g.ZWSP
+ && ["STRONG", "STRIKE", "S", "I", "EM", "B"].includes(startContainer.parentElement.tagName)) {
+ // 保持行内元素软换行需继续的一致性
+ startContainer.textContent = startContainer.textContent.substring(0, rangeStartOffset - 1) +
+ constants/* Constants.ZWSP */.g.ZWSP;
+ range.setStart(startContainer, rangeStartOffset);
+ range.collapse(true);
+ afterRenderEvent(vditor);
+ event.preventDefault();
+ return true;
+ }
+ // inline code、math、html 行前零宽字符后进行删除
+ if (startContainer.textContent === constants/* Constants.ZWSP */.g.ZWSP && range.startOffset === 1
+ && !startContainer.previousSibling && nextIsCode(range)) {
+ startContainer.textContent = "";
+ // 不能返回,其前面为代码渲染块时需进行以下处理:修正光标位于 inline math/html 前,按下删除按钮 code 中内容会被删除
+ }
+ // 修正光标位于 inline math/html, html-entity 前,按下删除按钮 code 中内容会被删除, 不能返回,还需要进行后续处理
+ blockElement.querySelectorAll("span.vditor-wysiwyg__block[data-type='math-inline']").forEach(function (item) {
+ item.firstElementChild.style.display = "inline";
+ item.lastElementChild.style.display = "none";
+ });
+ blockElement.querySelectorAll("span.vditor-wysiwyg__block[data-type='html-entity']").forEach(function (item) {
+ item.firstElementChild.style.display = "inline";
+ item.lastElementChild.style.display = "none";
+ });
+ }
+ }
+ if ((0,compatibility/* isFirefox */.vU)() && range.startOffset === 1 && startContainer.textContent.indexOf(constants/* Constants.ZWSP */.g.ZWSP) > -1 &&
+ startContainer.previousSibling && startContainer.previousSibling.nodeType !== 3 &&
+ startContainer.previousSibling.tagName === "CODE" &&
+ (event.key === "Backspace" || event.key === "ArrowLeft")) {
+ // https://github.com/Vanessa219/vditor/issues/410
+ range.selectNodeContents(startContainer.previousSibling);
+ range.collapse(false);
+ event.preventDefault();
+ return true;
+ }
+ if (fixFirefoxArrowUpTable(event, blockElement, range)) {
+ event.preventDefault();
+ return true;
+ }
+ fixCursorDownInlineMath(range, event.key);
+ if (event.key === "ArrowDown") {
+ // 光标位于内联数学公式前,按下键无作用
+ var nextElement = startContainer.nextSibling;
+ if (nextElement && nextElement.nodeType !== 3 && nextElement.getAttribute("data-type") === "math-inline") {
+ range.setStartAfter(nextElement);
+ }
+ }
+ if (blockElement && keydownToc(blockElement, vditor, event, range)) {
+ event.preventDefault();
+ return true;
+ }
+ return false;
+};
+var removeBlockElement = function (vditor, event) {
+ // 删除有子工具栏的块
+ if (matchHotKey("⇧⌘X", event)) {
+ var itemElement = vditor.wysiwyg.popover.querySelector('[data-type="remove"]');
+ if (itemElement) {
+ itemElement.click();
+ }
+ event.preventDefault();
+ return true;
+ }
+};
+
+;// CONCATENATED MODULE: ./src/ts/wysiwyg/highlightToolbarWYSIWYG.ts
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+var highlightToolbarWYSIWYG = function (vditor) {
+ clearTimeout(vditor.wysiwyg.hlToolbarTimeoutId);
+ vditor.wysiwyg.hlToolbarTimeoutId = window.setTimeout(function () {
+ if (vditor.wysiwyg.element.getAttribute("contenteditable") === "false") {
+ return;
+ }
+ if (!(0,selection/* selectIsEditor */.Gb)(vditor.wysiwyg.element)) {
+ return;
+ }
+ removeCurrentToolbar(vditor.toolbar.elements, constants/* Constants.EDIT_TOOLBARS */.g.EDIT_TOOLBARS);
+ enableToolbar(vditor.toolbar.elements, constants/* Constants.EDIT_TOOLBARS */.g.EDIT_TOOLBARS);
+ var range = getSelection().getRangeAt(0);
+ var typeElement = range.startContainer;
+ if (range.startContainer.nodeType === 3) {
+ typeElement = range.startContainer.parentElement;
+ }
+ else {
+ typeElement = typeElement.childNodes[range.startOffset >= typeElement.childNodes.length
+ ? typeElement.childNodes.length - 1
+ : range.startOffset];
+ }
+ var footnotesElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "footnotes-block");
+ if (footnotesElement) {
+ vditor.wysiwyg.popover.innerHTML = "";
+ genClose(footnotesElement, vditor);
+ setPopoverPosition(vditor, footnotesElement);
+ return;
+ }
+ // 工具栏高亮和禁用
+ var liElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "LI");
+ if (liElement) {
+ if (liElement.classList.contains("vditor-task")) {
+ setCurrentToolbar(vditor.toolbar.elements, ["check"]);
+ }
+ else if (liElement.parentElement.tagName === "OL") {
+ setCurrentToolbar(vditor.toolbar.elements, ["ordered-list"]);
+ }
+ else if (liElement.parentElement.tagName === "UL") {
+ setCurrentToolbar(vditor.toolbar.elements, ["list"]);
+ }
+ enableToolbar(vditor.toolbar.elements, ["outdent", "indent"]);
+ }
+ else {
+ disableToolbar(vditor.toolbar.elements, ["outdent", "indent"]);
+ }
+ if ((0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "BLOCKQUOTE")) {
+ setCurrentToolbar(vditor.toolbar.elements, ["quote"]);
+ }
+ if ((0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "B") ||
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "STRONG")) {
+ setCurrentToolbar(vditor.toolbar.elements, ["bold"]);
+ }
+ if ((0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "I") ||
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "EM")) {
+ setCurrentToolbar(vditor.toolbar.elements, ["italic"]);
+ }
+ if ((0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "STRIKE") ||
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "S")) {
+ setCurrentToolbar(vditor.toolbar.elements, ["strike"]);
+ }
+ // comments
+ vditor.wysiwyg.element
+ .querySelectorAll(".vditor-comment--focus")
+ .forEach(function (item) {
+ item.classList.remove("vditor-comment--focus");
+ });
+ var commentElement = (0,hasClosest/* hasClosestByClassName */.fb)(typeElement, "vditor-comment");
+ if (commentElement) {
+ var ids_1 = commentElement.getAttribute("data-cmtids").split(" ");
+ if (ids_1.length > 1 && commentElement.nextSibling.isSameNode(commentElement.nextElementSibling)) {
+ var nextIds_1 = commentElement.nextElementSibling
+ .getAttribute("data-cmtids")
+ .split(" ");
+ ids_1.find(function (id) {
+ if (nextIds_1.includes(id)) {
+ ids_1 = [id];
+ return true;
+ }
+ });
+ }
+ vditor.wysiwyg.element
+ .querySelectorAll(".vditor-comment")
+ .forEach(function (item) {
+ if (item.getAttribute("data-cmtids").indexOf(ids_1[0]) > -1) {
+ item.classList.add("vditor-comment--focus");
+ }
+ });
+ }
+ var aElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "A");
+ if (aElement) {
+ setCurrentToolbar(vditor.toolbar.elements, ["link"]);
+ }
+ var tableElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "TABLE");
+ var headingElement = (0,hasClosestByHeadings/* hasClosestByHeadings */.W)(typeElement);
+ if ((0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "CODE")) {
+ if ((0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "PRE")) {
+ disableToolbar(vditor.toolbar.elements, [
+ "headings",
+ "bold",
+ "italic",
+ "strike",
+ "line",
+ "quote",
+ "list",
+ "ordered-list",
+ "check",
+ "code",
+ "inline-code",
+ "upload",
+ "link",
+ "table",
+ "record",
+ ]);
+ setCurrentToolbar(vditor.toolbar.elements, ["code"]);
+ }
+ else {
+ disableToolbar(vditor.toolbar.elements, [
+ "headings",
+ "bold",
+ "italic",
+ "strike",
+ "line",
+ "quote",
+ "list",
+ "ordered-list",
+ "check",
+ "code",
+ "upload",
+ "link",
+ "table",
+ "record",
+ ]);
+ setCurrentToolbar(vditor.toolbar.elements, ["inline-code"]);
+ }
+ }
+ else if (headingElement) {
+ disableToolbar(vditor.toolbar.elements, ["bold"]);
+ setCurrentToolbar(vditor.toolbar.elements, ["headings"]);
+ }
+ else if (tableElement) {
+ disableToolbar(vditor.toolbar.elements, ["table"]);
+ }
+ // toc popover
+ var tocElement = (0,hasClosest/* hasClosestByClassName */.fb)(typeElement, "vditor-toc");
+ if (tocElement) {
+ vditor.wysiwyg.popover.innerHTML = "";
+ genClose(tocElement, vditor);
+ setPopoverPosition(vditor, tocElement);
+ return;
+ }
+ // quote popover
+ var blockquoteElement = (0,hasClosestByHeadings/* hasClosestByTag */.S)(typeElement, "BLOCKQUOTE");
+ if (blockquoteElement) {
+ vditor.wysiwyg.popover.innerHTML = "";
+ genUp(range, blockquoteElement, vditor);
+ genDown(range, blockquoteElement, vditor);
+ genClose(blockquoteElement, vditor);
+ setPopoverPosition(vditor, blockquoteElement);
+ }
+ // list item popover
+ if (liElement) {
+ vditor.wysiwyg.popover.innerHTML = "";
+ genUp(range, liElement, vditor);
+ genDown(range, liElement, vditor);
+ genClose(liElement, vditor);
+ setPopoverPosition(vditor, liElement);
+ }
+ // table popover
+ if (tableElement) {
+ var lang = vditor.options.lang;
+ var options = vditor.options;
+ vditor.wysiwyg.popover.innerHTML = "";
+ var updateTable_1 = function () {
+ var oldRow = tableElement.rows.length;
+ var oldColumn = tableElement.rows[0].cells.length;
+ var row = parseInt(input_1.value, 10) || oldRow;
+ var column = parseInt(input2_1.value, 10) || oldColumn;
+ if (row === oldRow && oldColumn === column) {
+ return;
+ }
+ if (oldColumn !== column) {
+ var columnDiff = column - oldColumn;
+ for (var i = 0; i < tableElement.rows.length; i++) {
+ if (columnDiff > 0) {
+ for (var j = 0; j < columnDiff; j++) {
+ if (i === 0) {
+ tableElement.rows[i].lastElementChild.insertAdjacentHTML("afterend", " | ");
+ }
+ else {
+ tableElement.rows[i].lastElementChild.insertAdjacentHTML("afterend", " | ");
+ }
+ }
+ }
+ else {
+ for (var k = oldColumn - 1; k >= column; k--) {
+ tableElement.rows[i].cells[k].remove();
+ }
+ }
+ }
+ }
+ if (oldRow !== row) {
+ var rowDiff = row - oldRow;
+ if (rowDiff > 0) {
+ var rowHTML = "";
+ for (var m = 0; m < column; m++) {
+ rowHTML += "| | ";
+ }
+ for (var l = 0; l < rowDiff; l++) {
+ if (tableElement.querySelector("tbody")) {
+ tableElement
+ .querySelector("tbody")
+ .insertAdjacentHTML("beforeend", rowHTML);
+ }
+ else {
+ tableElement
+ .querySelector("thead")
+ .insertAdjacentHTML("afterend", rowHTML + "
");
+ }
+ }
+ }
+ else {
+ for (var m = oldRow - 1; m >= row; m--) {
+ tableElement.rows[m].remove();
+ if (tableElement.rows.length === 1) {
+ tableElement.querySelector("tbody").remove();
+ }
+ }
+ }
+ }
+ if (typeof vditor.options.input === "function") {
+ vditor.options.input(getMarkdown(vditor));
+ }
+ };
+ var setAlign_1 = function (type) {
+ setTableAlign(tableElement, type);
+ if (type === "right") {
+ left_1.classList.remove("vditor-icon--current");
+ center_1.classList.remove("vditor-icon--current");
+ right_1.classList.add("vditor-icon--current");
+ }
+ else if (type === "center") {
+ left_1.classList.remove("vditor-icon--current");
+ right_1.classList.remove("vditor-icon--current");
+ center_1.classList.add("vditor-icon--current");
+ }
+ else {
+ center_1.classList.remove("vditor-icon--current");
+ right_1.classList.remove("vditor-icon--current");
+ left_1.classList.add("vditor-icon--current");
+ }
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ afterRenderEvent(vditor);
+ };
+ var td = (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "TD");
+ var th = (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "TH");
+ var alignType = "left";
+ if (td) {
+ alignType = td.getAttribute("align") || "left";
+ }
+ else if (th) {
+ alignType = th.getAttribute("align") || "center";
+ }
+ var left_1 = document.createElement("button");
+ left_1.setAttribute("type", "button");
+ left_1.setAttribute("aria-label", window.VditorI18n.alignLeft + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⇧⌘L") + ">");
+ left_1.setAttribute("data-type", "left");
+ left_1.innerHTML =
+ '';
+ left_1.className =
+ "vditor-icon vditor-tooltipped vditor-tooltipped__n" +
+ (alignType === "left" ? " vditor-icon--current" : "");
+ left_1.onclick = function () {
+ setAlign_1("left");
+ };
+ var center_1 = document.createElement("button");
+ center_1.setAttribute("type", "button");
+ center_1.setAttribute("aria-label", window.VditorI18n.alignCenter + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⇧⌘C") + ">");
+ center_1.setAttribute("data-type", "center");
+ center_1.innerHTML =
+ '';
+ center_1.className =
+ "vditor-icon vditor-tooltipped vditor-tooltipped__n" +
+ (alignType === "center" ? " vditor-icon--current" : "");
+ center_1.onclick = function () {
+ setAlign_1("center");
+ };
+ var right_1 = document.createElement("button");
+ right_1.setAttribute("type", "button");
+ right_1.setAttribute("aria-label", window.VditorI18n.alignRight + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⇧⌘R") + ">");
+ right_1.setAttribute("data-type", "right");
+ right_1.innerHTML =
+ '';
+ right_1.className =
+ "vditor-icon vditor-tooltipped vditor-tooltipped__n" +
+ (alignType === "right" ? " vditor-icon--current" : "");
+ right_1.onclick = function () {
+ setAlign_1("right");
+ };
+ var insertRowElement = document.createElement("button");
+ insertRowElement.setAttribute("type", "button");
+ insertRowElement.setAttribute("aria-label", window.VditorI18n.insertRowBelow + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⌘=") + ">");
+ insertRowElement.setAttribute("data-type", "insertRow");
+ insertRowElement.innerHTML =
+ '';
+ insertRowElement.className =
+ "vditor-icon vditor-tooltipped vditor-tooltipped__n";
+ insertRowElement.onclick = function () {
+ var startContainer = getSelection().getRangeAt(0)
+ .startContainer;
+ var cellElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TD") ||
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TH");
+ if (cellElement) {
+ insertRow(vditor, range, cellElement);
+ }
+ };
+ var insertRowBElement = document.createElement("button");
+ insertRowBElement.setAttribute("type", "button");
+ insertRowBElement.setAttribute("aria-label", window.VditorI18n.insertRowAbove + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⇧⌘F") + ">");
+ insertRowBElement.setAttribute("data-type", "insertRow");
+ insertRowBElement.innerHTML =
+ '';
+ insertRowBElement.className =
+ "vditor-icon vditor-tooltipped vditor-tooltipped__n";
+ insertRowBElement.onclick = function () {
+ var startContainer = getSelection().getRangeAt(0)
+ .startContainer;
+ var cellElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TD") ||
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TH");
+ if (cellElement) {
+ insertRowAbove(vditor, range, cellElement);
+ }
+ };
+ var insertColumnElement = document.createElement("button");
+ insertColumnElement.setAttribute("type", "button");
+ insertColumnElement.setAttribute("aria-label", window.VditorI18n.insertColumnRight + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⇧⌘=") + ">");
+ insertColumnElement.setAttribute("data-type", "insertColumn");
+ insertColumnElement.innerHTML =
+ '';
+ insertColumnElement.className =
+ "vditor-icon vditor-tooltipped vditor-tooltipped__n";
+ insertColumnElement.onclick = function () {
+ var startContainer = getSelection().getRangeAt(0)
+ .startContainer;
+ var cellElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TD") ||
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TH");
+ if (cellElement) {
+ insertColumn(vditor, tableElement, cellElement);
+ }
+ };
+ var insertColumnBElement = document.createElement("button");
+ insertColumnBElement.setAttribute("type", "button");
+ insertColumnBElement.setAttribute("aria-label", window.VditorI18n.insertColumnLeft + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⇧⌘G") + ">");
+ insertColumnBElement.setAttribute("data-type", "insertColumn");
+ insertColumnBElement.innerHTML =
+ '';
+ insertColumnBElement.className =
+ "vditor-icon vditor-tooltipped vditor-tooltipped__n";
+ insertColumnBElement.onclick = function () {
+ var startContainer = getSelection().getRangeAt(0)
+ .startContainer;
+ var cellElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TD") ||
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TH");
+ if (cellElement) {
+ insertColumn(vditor, tableElement, cellElement, "beforebegin");
+ }
+ };
+ var deleteRowElement = document.createElement("button");
+ deleteRowElement.setAttribute("type", "button");
+ deleteRowElement.setAttribute("aria-label", window.VditorI18n["delete-row"] + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⌘-") + ">");
+ deleteRowElement.setAttribute("data-type", "deleteRow");
+ deleteRowElement.innerHTML =
+ '';
+ deleteRowElement.className =
+ "vditor-icon vditor-tooltipped vditor-tooltipped__n";
+ deleteRowElement.onclick = function () {
+ var startContainer = getSelection().getRangeAt(0)
+ .startContainer;
+ var cellElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TD") ||
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TH");
+ if (cellElement) {
+ deleteRow(vditor, range, cellElement);
+ }
+ };
+ var deleteColumnElement = document.createElement("button");
+ deleteColumnElement.setAttribute("type", "button");
+ deleteColumnElement.setAttribute("aria-label", window.VditorI18n["delete-column"] + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⇧⌘-") + ">");
+ deleteColumnElement.setAttribute("data-type", "deleteColumn");
+ deleteColumnElement.innerHTML =
+ '';
+ deleteColumnElement.className =
+ "vditor-icon vditor-tooltipped vditor-tooltipped__n";
+ deleteColumnElement.onclick = function () {
+ var startContainer = getSelection().getRangeAt(0)
+ .startContainer;
+ var cellElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TD") ||
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TH");
+ if (cellElement) {
+ deleteColumn(vditor, range, tableElement, cellElement);
+ }
+ };
+ var inputWrap = document.createElement("span");
+ inputWrap.setAttribute("aria-label", window.VditorI18n.row);
+ inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var input_1 = document.createElement("input");
+ inputWrap.appendChild(input_1);
+ input_1.type = "number";
+ input_1.min = "1";
+ input_1.className = "vditor-input";
+ input_1.style.width = "42px";
+ input_1.style.textAlign = "center";
+ input_1.setAttribute("placeholder", window.VditorI18n.row);
+ input_1.value = tableElement.rows.length.toString();
+ input_1.oninput = function () {
+ updateTable_1();
+ };
+ input_1.onkeydown = function (event) {
+ if (event.isComposing) {
+ return;
+ }
+ if (event.key === "Tab") {
+ input2_1.focus();
+ input2_1.select();
+ event.preventDefault();
+ return;
+ }
+ if (removeBlockElement(vditor, event)) {
+ return;
+ }
+ if (focusToElement(event, range)) {
+ return;
+ }
+ };
+ var input2Wrap = document.createElement("span");
+ input2Wrap.setAttribute("aria-label", window.VditorI18n.column);
+ input2Wrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var input2_1 = document.createElement("input");
+ input2Wrap.appendChild(input2_1);
+ input2_1.type = "number";
+ input2_1.min = "1";
+ input2_1.className = "vditor-input";
+ input2_1.style.width = "42px";
+ input2_1.style.textAlign = "center";
+ input2_1.setAttribute("placeholder", window.VditorI18n.column);
+ input2_1.value = tableElement.rows[0].cells.length.toString();
+ input2_1.oninput = function () {
+ updateTable_1();
+ };
+ input2_1.onkeydown = function (event) {
+ if (event.isComposing) {
+ return;
+ }
+ if (event.key === "Tab") {
+ input_1.focus();
+ input_1.select();
+ event.preventDefault();
+ return;
+ }
+ if (removeBlockElement(vditor, event)) {
+ return;
+ }
+ if (focusToElement(event, range)) {
+ return;
+ }
+ };
+ genUp(range, tableElement, vditor);
+ genDown(range, tableElement, vditor);
+ genClose(tableElement, vditor);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", left_1);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", center_1);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", right_1);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", insertRowBElement);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", insertRowElement);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", insertColumnBElement);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", insertColumnElement);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", deleteRowElement);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", deleteColumnElement);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", inputWrap);
+ vditor.wysiwyg.popover.insertAdjacentHTML("beforeend", " x ");
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", input2Wrap);
+ setPopoverPosition(vditor, tableElement);
+ }
+ // link ref popover
+ var linkRefElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "link-ref");
+ if (linkRefElement) {
+ genLinkRefPopover(vditor, linkRefElement, range);
+ }
+ // footnote popover
+ var footnotesRefElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-type", "footnotes-ref");
+ if (footnotesRefElement) {
+ var lang = vditor.options.lang;
+ var options = vditor.options;
+ vditor.wysiwyg.popover.innerHTML = "";
+ var inputWrap = document.createElement("span");
+ inputWrap.setAttribute("aria-label", window.VditorI18n.footnoteRef + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⌥Enter") + ">");
+ inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var input_2 = document.createElement("input");
+ inputWrap.appendChild(input_2);
+ input_2.className = "vditor-input";
+ input_2.setAttribute("placeholder", window.VditorI18n.footnoteRef + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⌥Enter") + ">");
+ input_2.style.width = "120px";
+ input_2.value = footnotesRefElement.getAttribute("data-footnotes-label");
+ input_2.oninput = function () {
+ if (input_2.value.trim() !== "") {
+ footnotesRefElement.setAttribute("data-footnotes-label", input_2.value);
+ }
+ if (typeof vditor.options.input === "function") {
+ vditor.options.input(getMarkdown(vditor));
+ }
+ };
+ input_2.onkeydown = function (event) {
+ if (event.isComposing) {
+ return;
+ }
+ if (removeBlockElement(vditor, event)) {
+ return;
+ }
+ if (focusToElement(event, range)) {
+ return;
+ }
+ };
+ genClose(footnotesRefElement, vditor);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", inputWrap);
+ setPopoverPosition(vditor, footnotesRefElement);
+ }
+ // block popover: math-inline, math-block, html-block, html-inline, code-block, html-entity
+ var blockRenderElement = (0,hasClosest/* hasClosestByClassName */.fb)(typeElement, "vditor-wysiwyg__block");
+ var isBlock = blockRenderElement ? blockRenderElement.getAttribute("data-type").indexOf("block") > -1 : false;
+ vditor.wysiwyg.element
+ .querySelectorAll(".vditor-wysiwyg__preview")
+ .forEach(function (itemElement) {
+ if (!blockRenderElement || (blockRenderElement && isBlock && !blockRenderElement.contains(itemElement))) {
+ var previousElement = itemElement.previousElementSibling;
+ previousElement.style.display = "none";
+ }
+ });
+ if (blockRenderElement && isBlock) {
+ vditor.wysiwyg.popover.innerHTML = "";
+ genUp(range, blockRenderElement, vditor);
+ genDown(range, blockRenderElement, vditor);
+ genClose(blockRenderElement, vditor);
+ if (blockRenderElement.getAttribute("data-type") === "code-block") {
+ var languageWrap = document.createElement("span");
+ languageWrap.setAttribute("aria-label", window.VditorI18n.language + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⌥Enter") + ">");
+ languageWrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var language_1 = document.createElement("input");
+ languageWrap.appendChild(language_1);
+ var codeElement_1 = blockRenderElement.firstElementChild.firstElementChild;
+ language_1.className = "vditor-input";
+ language_1.setAttribute("placeholder", window.VditorI18n.language + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⌥Enter") + ">");
+ language_1.value =
+ codeElement_1.className.indexOf("language-") > -1
+ ? codeElement_1.className.split("-")[1].split(" ")[0]
+ : "";
+ language_1.oninput = function (e) {
+ if (language_1.value.trim() !== "") {
+ codeElement_1.className = "language-".concat(language_1.value);
+ }
+ else {
+ codeElement_1.className = "";
+ vditor.hint.recentLanguage = "";
+ }
+ if (blockRenderElement.lastElementChild.classList.contains("vditor-wysiwyg__preview")) {
+ blockRenderElement.lastElementChild.innerHTML =
+ blockRenderElement.firstElementChild.innerHTML;
+ processCodeRender(blockRenderElement.lastElementChild, vditor);
+ }
+ afterRenderEvent(vditor);
+ // 当鼠标点选语言时,触发自定义input事件
+ if (e.detail === 1) {
+ // 选择语言后,输入焦点切换到代码输入框
+ range.setStart(codeElement_1.firstChild, 0);
+ range.collapse(true);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ };
+ language_1.onkeydown = function (event) {
+ if (event.isComposing) {
+ return;
+ }
+ if (removeBlockElement(vditor, event)) {
+ return;
+ }
+ if (event.key === "Escape" &&
+ vditor.hint.element.style.display === "block") {
+ vditor.hint.element.style.display = "none";
+ event.preventDefault();
+ return;
+ }
+ vditor.hint.select(event, vditor);
+ focusToElement(event, range);
+ };
+ language_1.onkeyup = function (event) {
+ var _a, _b;
+ if (event.isComposing ||
+ event.key === "Enter" ||
+ event.key === "ArrowUp" ||
+ event.key === "Escape" ||
+ event.key === "ArrowDown") {
+ return;
+ }
+ var matchLangData = [];
+ var key = language_1.value.substring(0, language_1.selectionStart);
+ (vditor.options.preview.hljs.langs || constants/* Constants.ALIAS_CODE_LANGUAGES.concat */.g.ALIAS_CODE_LANGUAGES.concat(((_b = (_a = window.hljs) === null || _a === void 0 ? void 0 : _a.listLanguages()) !== null && _b !== void 0 ? _b : []).sort())).forEach(function (keyName) {
+ if (keyName.indexOf(key.toLowerCase()) > -1) {
+ matchLangData.push({
+ html: keyName,
+ value: keyName,
+ });
+ }
+ });
+ vditor.hint.genHTML(matchLangData, key, vditor);
+ event.preventDefault();
+ };
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", languageWrap);
+ }
+ setPopoverPosition(vditor, blockRenderElement);
+ }
+ else {
+ blockRenderElement = undefined;
+ }
+ if (headingElement) {
+ vditor.wysiwyg.popover.innerHTML = "";
+ var inputWrap = document.createElement("span");
+ inputWrap.setAttribute("aria-label", "ID" + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⌥Enter") + ">");
+ inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var input_3 = document.createElement("input");
+ inputWrap.appendChild(input_3);
+ input_3.className = "vditor-input";
+ input_3.setAttribute("placeholder", "ID" + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⌥Enter") + ">");
+ input_3.style.width = "120px";
+ input_3.value = headingElement.getAttribute("data-id") || "";
+ input_3.oninput = function () {
+ headingElement.setAttribute("data-id", input_3.value);
+ if (typeof vditor.options.input === "function") {
+ vditor.options.input(getMarkdown(vditor));
+ }
+ };
+ input_3.onkeydown = function (event) {
+ if (event.isComposing) {
+ return;
+ }
+ if (removeBlockElement(vditor, event)) {
+ return;
+ }
+ if (focusToElement(event, range)) {
+ return;
+ }
+ };
+ genUp(range, headingElement, vditor);
+ genDown(range, headingElement, vditor);
+ genClose(headingElement, vditor);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", inputWrap);
+ setPopoverPosition(vditor, headingElement);
+ }
+ // a popover
+ if (aElement) {
+ genAPopover(vditor, aElement, range);
+ }
+ if (!blockquoteElement &&
+ !liElement &&
+ !tableElement &&
+ !blockRenderElement &&
+ !aElement &&
+ !linkRefElement &&
+ !footnotesRefElement &&
+ !headingElement &&
+ !tocElement) {
+ var blockElement = (0,hasClosest/* hasClosestByAttribute */.a1)(typeElement, "data-block", "0");
+ if (blockElement &&
+ blockElement.parentElement.isEqualNode(vditor.wysiwyg.element)) {
+ vditor.wysiwyg.popover.innerHTML = "";
+ genUp(range, blockElement, vditor);
+ genDown(range, blockElement, vditor);
+ genClose(blockElement, vditor);
+ setPopoverPosition(vditor, blockElement);
+ }
+ else {
+ vditor.wysiwyg.popover.style.display = "none";
+ }
+ }
+ // 反斜杠特殊处理
+ vditor.wysiwyg.element
+ .querySelectorAll('span[data-type="backslash"] > span')
+ .forEach(function (item) {
+ item.style.display = "none";
+ });
+ var backslashElement = (0,hasClosest/* hasClosestByAttribute */.a1)(range.startContainer, "data-type", "backslash");
+ if (backslashElement) {
+ backslashElement.querySelector("span").style.display = "inline";
+ }
+ }, 200);
+};
+var setPopoverPosition = function (vditor, element) {
+ var targetElement = element;
+ var tableElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(element, "TABLE");
+ if (tableElement) {
+ targetElement = tableElement;
+ }
+ vditor.wysiwyg.popover.style.left = "0";
+ vditor.wysiwyg.popover.style.display = "block";
+ vditor.wysiwyg.popover.style.top =
+ Math.max(-8, targetElement.offsetTop - 21 - vditor.wysiwyg.element.scrollTop) + "px";
+ vditor.wysiwyg.popover.style.left =
+ Math.min(targetElement.offsetLeft, vditor.wysiwyg.element.clientWidth - vditor.wysiwyg.popover.clientWidth) + "px";
+ vditor.wysiwyg.popover.setAttribute("data-top", (targetElement.offsetTop - 21).toString());
+};
+var genLinkRefPopover = function (vditor, linkRefElement, range) {
+ if (range === void 0) { range = getSelection().getRangeAt(0); }
+ vditor.wysiwyg.popover.innerHTML = "";
+ var updateLinkRef = function () {
+ if (input.value.trim() !== "") {
+ if (linkRefElement.tagName === "IMG") {
+ linkRefElement.setAttribute("alt", input.value);
+ }
+ else {
+ linkRefElement.textContent = input.value;
+ }
+ }
+ // data-link-label
+ if (input1.value.trim() !== "") {
+ linkRefElement.setAttribute("data-link-label", input1.value);
+ }
+ if (typeof vditor.options.input === "function") {
+ vditor.options.input(getMarkdown(vditor));
+ }
+ };
+ var inputWrap = document.createElement("span");
+ inputWrap.setAttribute("aria-label", window.VditorI18n.textIsNotEmpty);
+ inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var input = document.createElement("input");
+ inputWrap.appendChild(input);
+ input.className = "vditor-input";
+ input.setAttribute("placeholder", window.VditorI18n.textIsNotEmpty);
+ input.style.width = "120px";
+ input.value =
+ linkRefElement.getAttribute("alt") || linkRefElement.textContent;
+ input.oninput = function () {
+ updateLinkRef();
+ };
+ input.onkeydown = function (event) {
+ if (removeBlockElement(vditor, event)) {
+ return;
+ }
+ if (focusToElement(event, range)) {
+ return;
+ }
+ linkHotkey(vditor, linkRefElement, event, input1);
+ };
+ var input1Wrap = document.createElement("span");
+ input1Wrap.setAttribute("aria-label", window.VditorI18n.linkRef);
+ input1Wrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var input1 = document.createElement("input");
+ input1Wrap.appendChild(input1);
+ input1.className = "vditor-input";
+ input1.setAttribute("placeholder", window.VditorI18n.linkRef);
+ input1.value = linkRefElement.getAttribute("data-link-label");
+ input1.oninput = function () {
+ updateLinkRef();
+ };
+ input1.onkeydown = function (event) {
+ if (removeBlockElement(vditor, event)) {
+ return;
+ }
+ if (focusToElement(event, range)) {
+ return;
+ }
+ linkHotkey(vditor, linkRefElement, event, input);
+ };
+ genClose(linkRefElement, vditor);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", inputWrap);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", input1Wrap);
+ setPopoverPosition(vditor, linkRefElement);
+};
+var genUp = function (range, element, vditor) {
+ var previousElement = element.previousElementSibling;
+ if (!previousElement ||
+ (!element.parentElement.isEqualNode(vditor.wysiwyg.element) &&
+ element.tagName !== "LI")) {
+ return;
+ }
+ var upElement = document.createElement("button");
+ upElement.setAttribute("type", "button");
+ upElement.setAttribute("data-type", "up");
+ upElement.setAttribute("aria-label", window.VditorI18n.up + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⇧⌘U") + ">");
+ upElement.innerHTML = '';
+ upElement.className = "vditor-icon vditor-tooltipped vditor-tooltipped__n";
+ upElement.onclick = function () {
+ range.insertNode(document.createElement("wbr"));
+ previousElement.insertAdjacentElement("beforebegin", element);
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ afterRenderEvent(vditor);
+ highlightToolbarWYSIWYG(vditor);
+ scrollCenter(vditor);
+ };
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", upElement);
+};
+var genDown = function (range, element, vditor) {
+ var nextElement = element.nextElementSibling;
+ if (!nextElement ||
+ (!element.parentElement.isEqualNode(vditor.wysiwyg.element) &&
+ element.tagName !== "LI")) {
+ return;
+ }
+ var downElement = document.createElement("button");
+ downElement.setAttribute("type", "button");
+ downElement.setAttribute("data-type", "down");
+ downElement.setAttribute("aria-label", window.VditorI18n.down + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⇧⌘D") + ">");
+ downElement.innerHTML =
+ '';
+ downElement.className =
+ "vditor-icon vditor-tooltipped vditor-tooltipped__n";
+ downElement.onclick = function () {
+ range.insertNode(document.createElement("wbr"));
+ nextElement.insertAdjacentElement("afterend", element);
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ afterRenderEvent(vditor);
+ highlightToolbarWYSIWYG(vditor);
+ scrollCenter(vditor);
+ };
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", downElement);
+};
+var genClose = function (element, vditor) {
+ var close = document.createElement("button");
+ close.setAttribute("type", "button");
+ close.setAttribute("data-type", "remove");
+ close.setAttribute("aria-label", window.VditorI18n.remove + "<" + (0,compatibility/* updateHotkeyTip */.ns)("⇧⌘X") + ">");
+ close.innerHTML =
+ '';
+ close.className = "vditor-icon vditor-tooltipped vditor-tooltipped__n";
+ close.onclick = function () {
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ range.setStartAfter(element);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ element.remove();
+ afterRenderEvent(vditor);
+ highlightToolbarWYSIWYG(vditor);
+ if (["H1", "H2", "H3", "H4", "H5", "H6"].includes(element.tagName)) {
+ renderToc(vditor);
+ }
+ };
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", close);
+};
+var linkHotkey = function (vditor, element, event, nextInputElement) {
+ if (event.isComposing) {
+ return;
+ }
+ if (event.key === "Tab") {
+ nextInputElement.focus();
+ nextInputElement.select();
+ event.preventDefault();
+ return;
+ }
+ if (!(0,compatibility/* isCtrl */.yl)(event) &&
+ !event.shiftKey &&
+ event.altKey &&
+ event.key === "Enter") {
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ // firefox 不会打断 link https://github.com/Vanessa219/vditor/issues/193
+ element.insertAdjacentHTML("afterend", constants/* Constants.ZWSP */.g.ZWSP);
+ range.setStartAfter(element.nextSibling);
+ range.collapse(true);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ event.preventDefault();
+ }
+};
+var genAPopover = function (vditor, aElement, range) {
+ vditor.wysiwyg.popover.innerHTML = "";
+ var updateA = function () {
+ if (input.value.trim() !== "") {
+ aElement.innerHTML = input.value;
+ }
+ aElement.setAttribute("href", input1.value);
+ aElement.setAttribute("title", input2.value);
+ afterRenderEvent(vditor);
+ };
+ aElement.querySelectorAll("[data-marker]").forEach(function (item) {
+ item.removeAttribute("data-marker");
+ });
+ var inputWrap = document.createElement("span");
+ inputWrap.setAttribute("aria-label", window.VditorI18n.textIsNotEmpty);
+ inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var input = document.createElement("input");
+ inputWrap.appendChild(input);
+ input.className = "vditor-input";
+ input.setAttribute("placeholder", window.VditorI18n.textIsNotEmpty);
+ input.style.width = "120px";
+ input.value = aElement.innerHTML || "";
+ input.oninput = function () {
+ updateA();
+ };
+ input.onkeydown = function (event) {
+ if (removeBlockElement(vditor, event)) {
+ return;
+ }
+ if (focusToElement(event, range)) {
+ return;
+ }
+ linkHotkey(vditor, aElement, event, input1);
+ };
+ var input1Wrap = document.createElement("span");
+ input1Wrap.setAttribute("aria-label", window.VditorI18n.link);
+ input1Wrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var input1 = document.createElement("input");
+ input1Wrap.appendChild(input1);
+ input1.className = "vditor-input";
+ input1.setAttribute("placeholder", window.VditorI18n.link);
+ input1.value = aElement.getAttribute("href") || "";
+ input1.oninput = function () {
+ updateA();
+ };
+ input1.onkeydown = function (event) {
+ if (removeBlockElement(vditor, event)) {
+ return;
+ }
+ if (focusToElement(event, range)) {
+ return;
+ }
+ linkHotkey(vditor, aElement, event, input2);
+ };
+ var input2Wrap = document.createElement("span");
+ input2Wrap.setAttribute("aria-label", window.VditorI18n.tooltipText);
+ input2Wrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var input2 = document.createElement("input");
+ input2Wrap.appendChild(input2);
+ input2.className = "vditor-input";
+ input2.setAttribute("placeholder", window.VditorI18n.tooltipText);
+ input2.style.width = "60px";
+ input2.value = aElement.getAttribute("title") || "";
+ input2.oninput = function () {
+ updateA();
+ };
+ input2.onkeydown = function (event) {
+ if (removeBlockElement(vditor, event)) {
+ return;
+ }
+ if (focusToElement(event, range)) {
+ return;
+ }
+ linkHotkey(vditor, aElement, event, input);
+ };
+ genClose(aElement, vditor);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", inputWrap);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", input1Wrap);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", input2Wrap);
+ setPopoverPosition(vditor, aElement);
+};
+var genImagePopover = function (event, vditor) {
+ var imgElement = event.target;
+ vditor.wysiwyg.popover.innerHTML = "";
+ var updateImg = function () {
+ imgElement.setAttribute("src", inputElement.value);
+ imgElement.setAttribute("alt", alt.value);
+ imgElement.setAttribute("title", title.value);
+ if (typeof vditor.options.input === "function") {
+ vditor.options.input(getMarkdown(vditor));
+ }
+ };
+ var inputWrap = document.createElement("span");
+ inputWrap.setAttribute("aria-label", window.VditorI18n.imageURL);
+ inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var inputElement = document.createElement("input");
+ inputWrap.appendChild(inputElement);
+ inputElement.className = "vditor-input";
+ inputElement.setAttribute("placeholder", window.VditorI18n.imageURL);
+ inputElement.value = imgElement.getAttribute("src") || "";
+ inputElement.oninput = function () {
+ updateImg();
+ };
+ inputElement.onkeydown = function (elementEvent) {
+ removeBlockElement(vditor, elementEvent);
+ };
+ var altWrap = document.createElement("span");
+ altWrap.setAttribute("aria-label", window.VditorI18n.alternateText);
+ altWrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var alt = document.createElement("input");
+ altWrap.appendChild(alt);
+ alt.className = "vditor-input";
+ alt.setAttribute("placeholder", window.VditorI18n.alternateText);
+ alt.style.width = "52px";
+ alt.value = imgElement.getAttribute("alt") || "";
+ alt.oninput = function () {
+ updateImg();
+ };
+ alt.onkeydown = function (elementEvent) {
+ removeBlockElement(vditor, elementEvent);
+ };
+ var titleWrap = document.createElement("span");
+ titleWrap.setAttribute("aria-label", window.VditorI18n.title);
+ titleWrap.className = "vditor-tooltipped vditor-tooltipped__n";
+ var title = document.createElement("input");
+ titleWrap.appendChild(title);
+ title.className = "vditor-input";
+ title.setAttribute("placeholder", window.VditorI18n.title);
+ title.value = imgElement.getAttribute("title") || "";
+ title.oninput = function () {
+ updateImg();
+ };
+ title.onkeydown = function (elementEvent) {
+ removeBlockElement(vditor, elementEvent);
+ };
+ genClose(imgElement, vditor);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", inputWrap);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", altWrap);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", titleWrap);
+ setPopoverPosition(vditor, imgElement);
+};
+var focusToElement = function (event, range) {
+ if ((!(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && event.key === "Enter") || event.key === "Escape") {
+ if (range) {
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ event.preventDefault();
+ event.stopPropagation();
+ return true;
+ }
+};
+
+;// CONCATENATED MODULE: ./src/ts/util/highlightToolbar.ts
+
+
+var highlightToolbar = function (vditor) {
+ if (vditor.currentMode === "wysiwyg") {
+ highlightToolbarWYSIWYG(vditor);
+ }
+ else if (vditor.currentMode === "ir") {
+ highlightToolbarIR(vditor);
+ }
+};
+
+;// CONCATENATED MODULE: ./src/ts/wysiwyg/renderDomByMd.ts
+
+
+var renderDomByMd = function (vditor, md, options) {
+ if (options === void 0) { options = {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: true,
+ }; }
+ var editorElement = vditor.wysiwyg.element;
+ editorElement.innerHTML = vditor.lute.Md2VditorDOM(md);
+ editorElement.querySelectorAll(".vditor-wysiwyg__preview[data-render='2']").forEach(function (item) {
+ processCodeRender(item, vditor);
+ item.previousElementSibling.setAttribute("style", "display:none");
+ });
+ afterRenderEvent(vditor, options);
+};
+
+;// CONCATENATED MODULE: ./src/ts/wysiwyg/toolbarEvent.ts
+
+
+
+
+
+
+
+
+
+var cancelBES = function (range, vditor, commandName) {
+ var element = range.startContainer.parentElement;
+ var jump = false;
+ var lastTagName = "";
+ var lastEndTagName = "";
+ var splitHTML = splitElement(range);
+ var lastBeforeHTML = splitHTML.beforeHTML;
+ var lastAfterHTML = splitHTML.afterHTML;
+ while (element && !jump) {
+ var tagName = element.tagName;
+ if (tagName === "STRIKE") {
+ tagName = "S";
+ }
+ if (tagName === "I") {
+ tagName = "EM";
+ }
+ if (tagName === "B") {
+ tagName = "STRONG";
+ }
+ if (tagName === "S" || tagName === "STRONG" || tagName === "EM") {
+ var insertHTML = "";
+ var previousHTML = "";
+ var nextHTML = "";
+ if (element.parentElement.getAttribute("data-block") !== "0") {
+ previousHTML = getPreviousHTML(element);
+ nextHTML = getNextHTML(element);
+ }
+ if (lastBeforeHTML || previousHTML) {
+ insertHTML = "".concat(previousHTML, "<").concat(tagName, ">").concat(lastBeforeHTML, "").concat(tagName, ">");
+ lastBeforeHTML = insertHTML;
+ }
+ if ((commandName === "bold" && tagName === "STRONG") ||
+ (commandName === "italic" && tagName === "EM") ||
+ (commandName === "strikeThrough" && tagName === "S")) {
+ // 取消
+ insertHTML += "".concat(lastTagName).concat(constants/* Constants.ZWSP */.g.ZWSP, "").concat(lastEndTagName);
+ jump = true;
+ }
+ if (lastAfterHTML || nextHTML) {
+ lastAfterHTML = "<".concat(tagName, ">").concat(lastAfterHTML, "").concat(tagName, ">").concat(nextHTML);
+ insertHTML += lastAfterHTML;
+ }
+ if (element.parentElement.getAttribute("data-block") !== "0") {
+ element = element.parentElement;
+ element.innerHTML = insertHTML;
+ }
+ else {
+ element.outerHTML = insertHTML;
+ element = element.parentElement;
+ }
+ lastTagName = "<".concat(tagName, ">") + lastTagName;
+ lastEndTagName = "".concat(tagName, ">") + lastEndTagName;
+ }
+ else {
+ jump = true;
+ }
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+};
+var toolbarEvent = function (vditor, actionBtn, event) {
+ if (vditor.wysiwyg.composingLock // Mac Chrome 中韩文结束会出发此事件,导致重复末尾字符 https://github.com/Vanessa219/vditor/issues/188
+ && event instanceof CustomEvent // 点击按钮应忽略输入法 https://github.com/Vanessa219/vditor/issues/473
+ ) {
+ return;
+ }
+ var useHighlight = true;
+ var useRender = true;
+ if (vditor.wysiwyg.element.querySelector("wbr")) {
+ vditor.wysiwyg.element.querySelector("wbr").remove();
+ }
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var commandName = actionBtn.getAttribute("data-type");
+ // 移除
+ if (actionBtn.classList.contains("vditor-menu--current")) {
+ if (commandName === "strike") {
+ commandName = "strikeThrough";
+ }
+ if (commandName === "quote") {
+ var quoteElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "BLOCKQUOTE");
+ if (!quoteElement) {
+ quoteElement = range.startContainer.childNodes[range.startOffset];
+ }
+ if (quoteElement) {
+ useHighlight = false;
+ actionBtn.classList.remove("vditor-menu--current");
+ range.insertNode(document.createElement("wbr"));
+ quoteElement.outerHTML = quoteElement.innerHTML.trim() === "" ?
+ "".concat(quoteElement.innerHTML, "
") : quoteElement.innerHTML;
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ }
+ }
+ else if (commandName === "inline-code") {
+ var inlineCodeElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "CODE");
+ if (!inlineCodeElement) {
+ inlineCodeElement = range.startContainer.childNodes[range.startOffset];
+ }
+ if (inlineCodeElement) {
+ inlineCodeElement.outerHTML = inlineCodeElement.innerHTML.replace(constants/* Constants.ZWSP */.g.ZWSP, "") + "";
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ }
+ }
+ else if (commandName === "link") {
+ if (!range.collapsed) {
+ document.execCommand("unlink", false, "");
+ }
+ else {
+ range.selectNode(range.startContainer.parentElement);
+ document.execCommand("unlink", false, "");
+ }
+ }
+ else if (commandName === "check" || commandName === "list" || commandName === "ordered-list") {
+ listToggle(vditor, range, commandName);
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ useHighlight = false;
+ actionBtn.classList.remove("vditor-menu--current");
+ }
+ else {
+ // bold, italic, strike
+ useHighlight = false;
+ actionBtn.classList.remove("vditor-menu--current");
+ if (range.toString() === "") {
+ cancelBES(range, vditor, commandName);
+ }
+ else {
+ document.execCommand(commandName, false, "");
+ }
+ }
+ }
+ else {
+ // 添加
+ if (vditor.wysiwyg.element.childNodes.length === 0) {
+ vditor.wysiwyg.element.innerHTML = '
';
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ }
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer);
+ if (commandName === "quote") {
+ if (!blockElement) {
+ blockElement = range.startContainer.childNodes[range.startOffset];
+ }
+ if (blockElement) {
+ useHighlight = false;
+ actionBtn.classList.add("vditor-menu--current");
+ range.insertNode(document.createElement("wbr"));
+ var liElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "LI");
+ // li 中软换行
+ if (liElement && blockElement.contains(liElement)) {
+ liElement.innerHTML = "".concat(liElement.innerHTML, "
");
+ }
+ else {
+ blockElement.outerHTML = "".concat(blockElement.outerHTML, "
");
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ }
+ }
+ else if (commandName === "check" || commandName === "list" || commandName === "ordered-list") {
+ listToggle(vditor, range, commandName, false);
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ useHighlight = false;
+ removeCurrentToolbar(vditor.toolbar.elements, ["check", "list", "ordered-list"]);
+ actionBtn.classList.add("vditor-menu--current");
+ }
+ else if (commandName === "inline-code") {
+ if (range.toString() === "") {
+ var node = document.createElement("code");
+ node.textContent = constants/* Constants.ZWSP */.g.ZWSP;
+ range.insertNode(node);
+ range.setStart(node.firstChild, 1);
+ range.collapse(true);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ else if (range.startContainer.nodeType === 3) {
+ var node = document.createElement("code");
+ range.surroundContents(node);
+ range.insertNode(node);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ actionBtn.classList.add("vditor-menu--current");
+ }
+ else if (commandName === "code") {
+ var node = document.createElement("div");
+ node.className = "vditor-wysiwyg__block";
+ node.setAttribute("data-type", "code-block");
+ node.setAttribute("data-block", "0");
+ node.setAttribute("data-marker", "```");
+ if (range.toString() === "") {
+ node.innerHTML = "\n
";
+ }
+ else {
+ node.innerHTML = "".concat(range.toString(), "
");
+ range.deleteContents();
+ }
+ range.insertNode(node);
+ if (blockElement) {
+ blockElement.outerHTML = vditor.lute.SpinVditorDOM(blockElement.outerHTML);
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ vditor.wysiwyg.element.querySelectorAll(".vditor-wysiwyg__preview[data-render='2']").forEach(function (item) {
+ processCodeRender(item, vditor);
+ });
+ actionBtn.classList.add("vditor-menu--disabled");
+ }
+ else if (commandName === "link") {
+ if (range.toString() === "") {
+ var aElement = document.createElement("a");
+ aElement.innerText = constants/* Constants.ZWSP */.g.ZWSP;
+ range.insertNode(aElement);
+ range.setStart(aElement.firstChild, 1);
+ range.collapse(true);
+ genAPopover(vditor, aElement, range);
+ var textInputElement = vditor.wysiwyg.popover.querySelector("input");
+ textInputElement.value = "";
+ textInputElement.focus();
+ useRender = false;
+ }
+ else {
+ var node = document.createElement("a");
+ node.setAttribute("href", "");
+ node.innerHTML = range.toString();
+ range.surroundContents(node);
+ range.insertNode(node);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ genAPopover(vditor, node, range);
+ var textInputElements = vditor.wysiwyg.popover.querySelectorAll("input");
+ textInputElements[0].value = node.innerText;
+ textInputElements[1].focus();
+ }
+ useHighlight = false;
+ actionBtn.classList.add("vditor-menu--current");
+ }
+ else if (commandName === "table") {
+ var tableHTML_1 = "";
+ if (range.toString().trim() === "") {
+ if (blockElement && blockElement.innerHTML.trim().replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "") {
+ blockElement.outerHTML = tableHTML_1;
+ }
+ else {
+ document.execCommand("insertHTML", false, tableHTML_1);
+ }
+ range.selectNode(vditor.wysiwyg.element.querySelector("wbr").previousSibling);
+ vditor.wysiwyg.element.querySelector("wbr").remove();
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ else {
+ tableHTML_1 = "";
+ var tableText = range.toString().split("\n");
+ var delimiter_1 = tableText[0].split(",").length > tableText[0].split("\t").length ? "," : "\t";
+ tableText.forEach(function (rows, index) {
+ if (index === 0) {
+ rows.split(delimiter_1).forEach(function (header, subIndex) {
+ if (subIndex === 0) {
+ tableHTML_1 += "| ".concat(header, " | ");
+ }
+ else {
+ tableHTML_1 += "".concat(header, " | ");
+ }
+ });
+ tableHTML_1 += "
";
+ }
+ else {
+ if (index === 1) {
+ tableHTML_1 += "";
+ }
+ else {
+ tableHTML_1 += "
";
+ }
+ rows.split(delimiter_1).forEach(function (cell) {
+ tableHTML_1 += "| ".concat(cell, " | ");
+ });
+ tableHTML_1 += "
";
+ }
+ });
+ tableHTML_1 += "
";
+ document.execCommand("insertHTML", false, tableHTML_1);
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ }
+ useHighlight = false;
+ actionBtn.classList.add("vditor-menu--disabled");
+ }
+ else if (commandName === "line") {
+ if (blockElement) {
+ var hrHTML = '
\n
';
+ if (blockElement.innerHTML.trim() === "") {
+ blockElement.outerHTML = hrHTML;
+ }
+ else {
+ blockElement.insertAdjacentHTML("afterend", hrHTML);
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ }
+ }
+ else {
+ // bold, italic, strike
+ useHighlight = false;
+ actionBtn.classList.add("vditor-menu--current");
+ if (commandName === "strike") {
+ commandName = "strikeThrough";
+ }
+ if (range.toString() === "" && (commandName === "bold" || commandName === "italic" || commandName === "strikeThrough")) {
+ var tagName = "strong";
+ if (commandName === "italic") {
+ tagName = "em";
+ }
+ else if (commandName === "strikeThrough") {
+ tagName = "s";
+ }
+ var node = document.createElement(tagName);
+ node.textContent = constants/* Constants.ZWSP */.g.ZWSP;
+ range.insertNode(node);
+ if (node.previousSibling && node.previousSibling.textContent === constants/* Constants.ZWSP */.g.ZWSP) {
+ // 移除多层嵌套中的 zwsp
+ node.previousSibling.textContent = "";
+ }
+ range.setStart(node.firstChild, 1);
+ range.collapse(true);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ else {
+ document.execCommand(commandName, false, "");
+ }
+ }
+ }
+ if (useHighlight) {
+ highlightToolbarWYSIWYG(vditor);
+ }
+ if (useRender) {
+ afterRenderEvent(vditor);
+ }
+};
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/MenuItem.ts
+
+
+
+
+
+
+var MenuItem = /** @class */ (function () {
+ function MenuItem(vditor, menuItem) {
+ var _a;
+ var _this = this;
+ this.element = document.createElement("div");
+ if (menuItem.className) {
+ (_a = this.element.classList).add.apply(_a, menuItem.className.split(" "));
+ }
+ var hotkey = menuItem.hotkey ? " <".concat((0,compatibility/* updateHotkeyTip */.ns)(menuItem.hotkey), ">") : "";
+ if (menuItem.level === 2) {
+ hotkey = menuItem.hotkey ? " <".concat((0,compatibility/* updateHotkeyTip */.ns)(menuItem.hotkey), ">") : "";
+ }
+ var tip = menuItem.tip ? menuItem.tip + hotkey : "".concat(window.VditorI18n[menuItem.name]).concat(hotkey);
+ var tagName = menuItem.name === "upload" ? "div" : "button";
+ if (menuItem.level === 2) {
+ this.element.innerHTML = "<".concat(tagName, " data-type=\"").concat(menuItem.name, "\">").concat(tip, "").concat(tagName, ">");
+ }
+ else {
+ this.element.classList.add("vditor-toolbar__item");
+ var iconElement = document.createElement(tagName);
+ iconElement.setAttribute("data-type", menuItem.name);
+ iconElement.className = "vditor-tooltipped vditor-tooltipped__".concat(menuItem.tipPosition);
+ iconElement.setAttribute("aria-label", tip);
+ iconElement.innerHTML = menuItem.icon;
+ this.element.appendChild(iconElement);
+ }
+ if (!menuItem.prefix) {
+ return;
+ }
+ this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ if (_this.element.firstElementChild.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ return;
+ }
+ if (vditor.currentMode === "wysiwyg") {
+ toolbarEvent(vditor, _this.element.children[0], event);
+ }
+ else if (vditor.currentMode === "ir") {
+ process_processToolbar(vditor, _this.element.children[0], menuItem.prefix || "", menuItem.suffix || "");
+ }
+ else {
+ processToolbar(vditor, _this.element.children[0], menuItem.prefix || "", menuItem.suffix || "");
+ }
+ });
+ }
+ return MenuItem;
+}());
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/EditMode.ts
+var __extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+var setEditMode = function (vditor, type, event) {
+ var markdownText;
+ if (typeof event !== "string") {
+ hidePanel(vditor, ["subToolbar", "hint"]);
+ event.preventDefault();
+ markdownText = getMarkdown(vditor);
+ }
+ else {
+ markdownText = event;
+ }
+ if (vditor.currentMode === type && typeof event !== "string") {
+ return;
+ }
+ if (vditor.devtools) {
+ vditor.devtools.renderEchart(vditor);
+ }
+ if (vditor.options.preview.mode === "both" && type === "sv") {
+ vditor.preview.element.style.display = "block";
+ }
+ else {
+ vditor.preview.element.style.display = "none";
+ }
+ enableToolbar(vditor.toolbar.elements, constants/* Constants.EDIT_TOOLBARS */.g.EDIT_TOOLBARS);
+ removeCurrentToolbar(vditor.toolbar.elements, constants/* Constants.EDIT_TOOLBARS */.g.EDIT_TOOLBARS);
+ disableToolbar(vditor.toolbar.elements, ["outdent", "indent"]);
+ if (type === "ir") {
+ hideToolbar(vditor.toolbar.elements, ["both"]);
+ showToolbar(vditor.toolbar.elements, ["outdent", "indent", "outline", "insert-before", "insert-after"]);
+ vditor.sv.element.style.display = "none";
+ vditor.wysiwyg.element.parentElement.style.display = "none";
+ vditor.ir.element.parentElement.style.display = "block";
+ vditor.lute.SetVditorIR(true);
+ vditor.lute.SetVditorWYSIWYG(false);
+ vditor.lute.SetVditorSV(false);
+ vditor.currentMode = "ir";
+ vditor.ir.element.innerHTML = vditor.lute.Md2VditorIRDOM(markdownText);
+ process_processAfterRender(vditor, {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: false,
+ });
+ setPadding(vditor);
+ vditor.ir.element.querySelectorAll(".vditor-ir__preview[data-render='2']").forEach(function (item) {
+ processCodeRender(item, vditor);
+ });
+ vditor.ir.element.querySelectorAll(".vditor-toc").forEach(function (item) {
+ (0,mathRender/* mathRender */.H)(item, {
+ cdn: vditor.options.cdn,
+ math: vditor.options.preview.math,
+ });
+ });
+ }
+ else if (type === "wysiwyg") {
+ hideToolbar(vditor.toolbar.elements, ["both"]);
+ showToolbar(vditor.toolbar.elements, ["outdent", "indent", "outline", "insert-before", "insert-after"]);
+ vditor.sv.element.style.display = "none";
+ vditor.wysiwyg.element.parentElement.style.display = "block";
+ vditor.ir.element.parentElement.style.display = "none";
+ vditor.lute.SetVditorIR(false);
+ vditor.lute.SetVditorWYSIWYG(true);
+ vditor.lute.SetVditorSV(false);
+ vditor.currentMode = "wysiwyg";
+ setPadding(vditor);
+ renderDomByMd(vditor, markdownText, {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: false,
+ });
+ vditor.wysiwyg.element.querySelectorAll(".vditor-toc").forEach(function (item) {
+ (0,mathRender/* mathRender */.H)(item, {
+ cdn: vditor.options.cdn,
+ math: vditor.options.preview.math,
+ });
+ });
+ vditor.wysiwyg.popover.style.display = "none";
+ }
+ else if (type === "sv") {
+ showToolbar(vditor.toolbar.elements, ["both"]);
+ hideToolbar(vditor.toolbar.elements, ["outdent", "indent", "outline", "insert-before", "insert-after"]);
+ vditor.wysiwyg.element.parentElement.style.display = "none";
+ vditor.ir.element.parentElement.style.display = "none";
+ if (vditor.options.preview.mode === "both") {
+ vditor.sv.element.style.display = "block";
+ }
+ else if (vditor.options.preview.mode === "editor") {
+ vditor.sv.element.style.display = "block";
+ }
+ vditor.lute.SetVditorIR(false);
+ vditor.lute.SetVditorWYSIWYG(false);
+ vditor.lute.SetVditorSV(true);
+ vditor.currentMode = "sv";
+ var svHTML = processSpinVditorSVDOM(markdownText, vditor);
+ if (svHTML === "") {
+ // https://github.com/Vanessa219/vditor/issues/654 SV 模式 Placeholder 显示问题
+ svHTML = "";
+ }
+ vditor.sv.element.innerHTML = svHTML;
+ combineFootnote(vditor.sv.element);
+ processAfterRender(vditor, {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: false,
+ });
+ setPadding(vditor);
+ }
+ vditor.undo.resetIcon(vditor);
+ if (typeof event !== "string") {
+ // 初始化不 focus
+ vditor[vditor.currentMode].element.focus();
+ highlightToolbar(vditor);
+ }
+ renderToc(vditor);
+ setTypewriterPosition(vditor);
+ if (vditor.toolbar.elements["edit-mode"]) {
+ vditor.toolbar.elements["edit-mode"].querySelectorAll("button").forEach(function (item) {
+ item.classList.remove("vditor-menu--current");
+ });
+ vditor.toolbar.elements["edit-mode"].querySelector("button[data-mode=\"".concat(vditor.currentMode, "\"]")).classList.add("vditor-menu--current");
+ }
+ vditor.outline.toggle(vditor, vditor.currentMode !== "sv" && vditor.options.outline.enable, typeof event !== "string");
+};
+var EditMode = /** @class */ (function (_super) {
+ __extends(EditMode, _super);
+ function EditMode(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ var panelElement = document.createElement("div");
+ panelElement.className = "vditor-hint".concat(menuItem.level === 2 ? "" : " vditor-panel--arrow");
+ panelElement.innerHTML = "\n\n");
+ _this.element.appendChild(panelElement);
+ _this._bindEvent(vditor, panelElement, menuItem);
+ return _this;
+ }
+ EditMode.prototype._bindEvent = function (vditor, panelElement, menuItem) {
+ var actionBtn = this.element.children[0];
+ toggleSubMenu(vditor, panelElement, actionBtn, menuItem.level);
+ panelElement.children.item(0).addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ // wysiwyg
+ setEditMode(vditor, "wysiwyg", event);
+ event.preventDefault();
+ event.stopPropagation();
+ });
+ panelElement.children.item(1).addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ // ir
+ setEditMode(vditor, "ir", event);
+ event.preventDefault();
+ event.stopPropagation();
+ });
+ panelElement.children.item(2).addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ // markdown
+ setEditMode(vditor, "sv", event);
+ event.preventDefault();
+ event.stopPropagation();
+ });
+ };
+ return EditMode;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/util/getSelectText.ts
+
+var getSelectText = function (editor, range) {
+ if ((0,selection/* selectIsEditor */.Gb)(editor, range)) {
+ return getSelection().toString();
+ }
+ return "";
+};
+
+;// CONCATENATED MODULE: ./src/ts/util/editorCommonEvent.ts
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+var focusEvent = function (vditor, editorElement) {
+ editorElement.addEventListener("focus", function () {
+ if (vditor.options.focus) {
+ vditor.options.focus(getMarkdown(vditor));
+ }
+ hidePanel(vditor, ["subToolbar", "hint"]);
+ });
+};
+var dblclickEvent = function (vditor, editorElement) {
+ editorElement.addEventListener("dblclick", function (event) {
+ if (event.target.tagName === "IMG") {
+ if (vditor.options.image.preview) {
+ vditor.options.image.preview(event.target);
+ }
+ else if (vditor.options.image.isPreview) {
+ (0,preview_image/* previewImage */.E)(event.target, vditor.options.lang, vditor.options.theme);
+ }
+ }
+ });
+};
+var blurEvent = function (vditor, editorElement) {
+ editorElement.addEventListener("blur", function (event) {
+ if (vditor.currentMode === "ir") {
+ var expandElement = vditor.ir.element.querySelector(".vditor-ir__node--expand");
+ if (expandElement) {
+ expandElement.classList.remove("vditor-ir__node--expand");
+ }
+ }
+ else if (vditor.currentMode === "wysiwyg" &&
+ !vditor.wysiwyg.selectPopover.contains(event.relatedTarget)) {
+ vditor.wysiwyg.hideComment();
+ }
+ vditor[vditor.currentMode].range = (0,selection/* getEditorRange */.zh)(vditor);
+ if (vditor.options.blur) {
+ vditor.options.blur(getMarkdown(vditor));
+ }
+ });
+};
+var dropEvent = function (vditor, editorElement) {
+ editorElement.addEventListener("dragstart", function (event) {
+ // 选中编辑器中的文字进行拖拽
+ event.dataTransfer.setData(constants/* Constants.DROP_EDITOR */.g.DROP_EDITOR, constants/* Constants.DROP_EDITOR */.g.DROP_EDITOR);
+ });
+ editorElement.addEventListener("drop", function (event) {
+ if (event.dataTransfer.getData(constants/* Constants.DROP_EDITOR */.g.DROP_EDITOR)) {
+ // 编辑器内选中文字拖拽
+ execAfterRender(vditor);
+ }
+ else if (event.dataTransfer.types.includes("Files") || event.dataTransfer.types.includes("text/html")) {
+ // 外部文件拖入编辑器中或者编辑器内选中文字拖拽
+ paste(vditor, event, {
+ pasteCode: function (code) {
+ document.execCommand("insertHTML", false, code);
+ },
+ });
+ }
+ });
+};
+var copyEvent = function (vditor, editorElement, copy) {
+ editorElement.addEventListener("copy", function (event) { return copy(event, vditor); });
+};
+var cutEvent = function (vditor, editorElement, copy) {
+ editorElement.addEventListener("cut", function (event) {
+ copy(event, vditor);
+ // 获取 comment
+ if (vditor.options.comment.enable && vditor.currentMode === "wysiwyg") {
+ vditor.wysiwyg.getComments(vditor);
+ }
+ document.execCommand("delete");
+ });
+};
+var scrollCenter = function (vditor) {
+ if (vditor.currentMode === "wysiwyg" && vditor.options.comment.enable) {
+ vditor.options.comment.adjustTop(vditor.wysiwyg.getComments(vditor, true));
+ }
+ if (!vditor.options.typewriterMode) {
+ return;
+ }
+ var editorElement = vditor[vditor.currentMode].element;
+ var cursorTop = (0,selection/* getCursorPosition */.Ny)(editorElement).top;
+ if (vditor.options.height === "auto" && !vditor.element.classList.contains("vditor--fullscreen")) {
+ window.scrollTo(window.scrollX, cursorTop + vditor.element.offsetTop + vditor.toolbar.element.offsetHeight - window.innerHeight / 2 + 10);
+ }
+ if (vditor.options.height !== "auto" || vditor.element.classList.contains("vditor--fullscreen")) {
+ editorElement.scrollTop = cursorTop + editorElement.scrollTop - editorElement.clientHeight / 2 + 10;
+ }
+};
+var hotkeyEvent = function (vditor, editorElement) {
+ editorElement.addEventListener("keydown", function (event) {
+ if (!event.isComposing && vditor.options.keydown) {
+ vditor.options.keydown(event);
+ }
+ // hint: 上下选择
+ if ((vditor.options.hint.extend.length > 1 || vditor.toolbar.elements.emoji) &&
+ vditor.hint.select(event, vditor)) {
+ return;
+ }
+ // 重置 comment
+ if (vditor.options.comment.enable && vditor.currentMode === "wysiwyg" &&
+ (event.key === "Backspace" || matchHotKey("⌘X", event))) {
+ vditor.wysiwyg.getComments(vditor);
+ }
+ if (vditor.currentMode === "sv") {
+ if (processKeydown_processKeydown(vditor, event)) {
+ return;
+ }
+ }
+ else if (vditor.currentMode === "wysiwyg") {
+ if (wysiwyg_processKeydown_processKeydown(vditor, event)) {
+ return;
+ }
+ }
+ else if (vditor.currentMode === "ir") {
+ if (processKeydown(vditor, event)) {
+ return;
+ }
+ }
+ if (vditor.options.ctrlEnter && matchHotKey("⌘Enter", event)) {
+ vditor.options.ctrlEnter(getMarkdown(vditor));
+ event.preventDefault();
+ return;
+ }
+ // undo
+ if (matchHotKey("⌘Z", event) && !vditor.toolbar.elements.undo) {
+ vditor.undo.undo(vditor);
+ event.preventDefault();
+ return;
+ }
+ // redo
+ if (matchHotKey("⌘Y", event) && !vditor.toolbar.elements.redo) {
+ vditor.undo.redo(vditor);
+ event.preventDefault();
+ return;
+ }
+ // esc
+ if (event.key === "Escape") {
+ if (vditor.hint.element.style.display === "block") {
+ vditor.hint.element.style.display = "none";
+ }
+ else if (vditor.options.esc && !event.isComposing) {
+ vditor.options.esc(getMarkdown(vditor));
+ }
+ event.preventDefault();
+ return;
+ }
+ // h1 - h6 hotkey
+ if ((0,compatibility/* isCtrl */.yl)(event) && event.altKey && !event.shiftKey && /^Digit[1-6]$/.test(event.code)) {
+ if (vditor.currentMode === "wysiwyg") {
+ var tagName = event.code.replace("Digit", "H");
+ if ((0,hasClosest/* hasClosestByMatchTag */.lG)(getSelection().getRangeAt(0).startContainer, tagName)) {
+ removeHeading(vditor);
+ }
+ else {
+ setHeading(vditor, tagName);
+ }
+ afterRenderEvent(vditor);
+ }
+ else if (vditor.currentMode === "sv") {
+ processHeading(vditor, "#".repeat(parseInt(event.code.replace("Digit", ""), 10)) + " ");
+ }
+ else if (vditor.currentMode === "ir") {
+ process_processHeading(vditor, "#".repeat(parseInt(event.code.replace("Digit", ""), 10)) + " ");
+ }
+ event.preventDefault();
+ return true;
+ }
+ // toggle edit mode
+ if ((0,compatibility/* isCtrl */.yl)(event) && event.altKey && !event.shiftKey && /^Digit[7-9]$/.test(event.code)) {
+ if (event.code === "Digit7") {
+ setEditMode(vditor, "wysiwyg", event);
+ }
+ else if (event.code === "Digit8") {
+ setEditMode(vditor, "ir", event);
+ }
+ else if (event.code === "Digit9") {
+ setEditMode(vditor, "sv", event);
+ }
+ return true;
+ }
+ // toolbar action
+ vditor.options.toolbar.find(function (menuItem) {
+ if (!menuItem.hotkey || menuItem.toolbar) {
+ if (menuItem.toolbar) {
+ var sub = menuItem.toolbar.find(function (subMenuItem) {
+ if (!subMenuItem.hotkey) {
+ return false;
+ }
+ if (matchHotKey(subMenuItem.hotkey, event)) {
+ vditor.toolbar.elements[subMenuItem.name].children[0]
+ .dispatchEvent(new CustomEvent((0,compatibility/* getEventName */.Le)()));
+ event.preventDefault();
+ return true;
+ }
+ });
+ return sub ? true : false;
+ }
+ return false;
+ }
+ if (matchHotKey(menuItem.hotkey, event)) {
+ vditor.toolbar.elements[menuItem.name].children[0].dispatchEvent(new CustomEvent((0,compatibility/* getEventName */.Le)()));
+ event.preventDefault();
+ return true;
+ }
+ });
+ });
+};
+var selectEvent = function (vditor, editorElement) {
+ editorElement.addEventListener("selectstart", function (event) {
+ editorElement.onmouseup = function () {
+ setTimeout(function () {
+ var selectText = getSelectText(vditor[vditor.currentMode].element);
+ if (selectText.trim()) {
+ if (vditor.currentMode === "wysiwyg" && vditor.options.comment.enable) {
+ if (!(0,hasClosest/* hasClosestByAttribute */.a1)(event.target, "data-type", "footnotes-block") &&
+ !(0,hasClosest/* hasClosestByAttribute */.a1)(event.target, "data-type", "link-ref-defs-block")) {
+ vditor.wysiwyg.showComment();
+ }
+ else {
+ vditor.wysiwyg.hideComment();
+ }
+ }
+ if (vditor.options.select) {
+ vditor.options.select(selectText);
+ }
+ }
+ else {
+ if (vditor.currentMode === "wysiwyg" && vditor.options.comment.enable) {
+ vditor.wysiwyg.hideComment();
+ }
+ if (typeof vditor.options.unSelect === 'function') {
+ vditor.options.unSelect();
+ }
+ }
+ });
+ };
+ });
+};
+
+;// CONCATENATED MODULE: ./src/ts/sv/process.ts
+
+
+
+
+
+
+
+
+
+var processPaste = function (vditor, text) {
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ range.extractContents();
+ range.insertNode(document.createTextNode(Lute.Caret));
+ range.insertNode(document.createTextNode(text));
+ var blockElement = (0,hasClosest/* hasClosestByAttribute */.a1)(range.startContainer, "data-block", "0");
+ if (!blockElement) {
+ blockElement = vditor.sv.element;
+ }
+ var spinHTML = vditor.lute.SpinVditorSVDOM(blockElement.textContent);
+ spinHTML = "" +
+ spinHTML.replace(/
\n<\/span><\/span>
\n<\/span><\/span>
\n
\n
<') +
+ "
";
+ if (blockElement.isEqualNode(vditor.sv.element)) {
+ blockElement.innerHTML = spinHTML;
+ }
+ else {
+ blockElement.outerHTML = spinHTML;
+ }
+ combineFootnote(vditor.sv.element);
+ (0,selection/* setRangeByWbr */.ib)(vditor.sv.element, range);
+ scrollCenter(vditor);
+};
+var getSideByType = function (spanNode, type, isPrevious) {
+ if (isPrevious === void 0) { isPrevious = true; }
+ var sideElement = spanNode;
+ if (sideElement.nodeType === 3) {
+ sideElement = sideElement.parentElement;
+ }
+ while (sideElement) {
+ if (sideElement.getAttribute("data-type") === type) {
+ return sideElement;
+ }
+ if (isPrevious) {
+ sideElement = sideElement.previousElementSibling;
+ }
+ else {
+ sideElement = sideElement.nextElementSibling;
+ }
+ }
+ return false;
+};
+var processSpinVditorSVDOM = function (html, vditor) {
+ log("SpinVditorSVDOM", html, "argument", vditor.options.debugger);
+ var spinHTML = vditor.lute.SpinVditorSVDOM(html);
+ html = "" +
+ spinHTML.replace(/
\n<\/span><\/span>
\n<\/span><\/span>
\n
\n
<') +
+ "
";
+ log("SpinVditorSVDOM", html, "result", vditor.options.debugger);
+ return html;
+};
+var processPreviousMarkers = function (spanElement) {
+ var spanType = spanElement.getAttribute("data-type");
+ var previousElement = spanElement.previousElementSibling;
+ // 有内容的子列表/标题,在其 marker 后换行
+ var markerText = (spanType && spanType !== "text" && spanType !== "table" && spanType !== "heading-marker" &&
+ spanType !== "newline" && spanType !== "yaml-front-matter-open-marker" && spanType !== "yaml-front-matter-close-marker"
+ && spanType !== "code-block-info" && spanType !== "code-block-close-marker" && spanType !== "code-block-open-marker") ?
+ spanElement.textContent : "";
+ var hasNL = false;
+ if (spanType === "newline") {
+ hasNL = true;
+ }
+ while (previousElement && !hasNL) {
+ var previousType = previousElement.getAttribute("data-type");
+ if (previousType === "li-marker" || previousType === "blockquote-marker" || previousType === "task-marker" ||
+ previousType === "padding") {
+ var previousText = previousElement.textContent;
+ if (previousType === "li-marker" &&
+ (spanType === "code-block-open-marker" || spanType === "code-block-info")) {
+ // https://github.com/Vanessa219/vditor/issues/586
+ markerText = previousText.replace(/\S/g, " ") + markerText;
+ }
+ else if (spanType === "code-block-close-marker" &&
+ previousElement.nextElementSibling.isSameNode(spanElement)) {
+ // https://github.com/Vanessa219/vditor/issues/594
+ var openMarker = getSideByType(spanElement, "code-block-open-marker");
+ if (openMarker && openMarker.previousElementSibling) {
+ previousElement = openMarker.previousElementSibling;
+ markerText = previousText + markerText;
+ }
+ }
+ else {
+ markerText = previousText + markerText;
+ }
+ }
+ else if (previousType === "newline") {
+ hasNL = true;
+ }
+ previousElement = previousElement.previousElementSibling;
+ }
+ return markerText;
+};
+var processAfterRender = function (vditor, options) {
+ if (options === void 0) { options = {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: true,
+ }; }
+ if (options.enableHint) {
+ vditor.hint.render(vditor);
+ }
+ vditor.preview.render(vditor);
+ var text = getMarkdown(vditor);
+ if (typeof vditor.options.input === "function" && options.enableInput) {
+ vditor.options.input(text);
+ }
+ if (vditor.options.counter.enable) {
+ vditor.counter.render(vditor, text);
+ }
+ if (vditor.options.cache.enable && (0,compatibility/* accessLocalStorage */.pK)()) {
+ localStorage.setItem(vditor.options.cache.id, text);
+ if (vditor.options.cache.after) {
+ vditor.options.cache.after(text);
+ }
+ }
+ if (vditor.devtools) {
+ vditor.devtools.renderEchart(vditor);
+ }
+ clearTimeout(vditor.sv.processTimeoutId);
+ vditor.sv.processTimeoutId = window.setTimeout(function () {
+ if (options.enableAddUndoStack && !vditor.sv.composingLock) {
+ vditor.undo.addToUndoStack(vditor);
+ }
+ }, vditor.options.undoDelay);
+};
+var processHeading = function (vditor, value) {
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var headingElement = (0,hasClosestByHeadings/* hasClosestByTag */.S)(range.startContainer, "SPAN");
+ if (headingElement && headingElement.textContent.trim() !== "") {
+ value = "\n" + value;
+ }
+ range.collapse(true);
+ document.execCommand("insertHTML", false, value);
+};
+var processToolbar = function (vditor, actionBtn, prefix, suffix) {
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var commandName = actionBtn.getAttribute("data-type");
+ // 添加
+ if (vditor.sv.element.childNodes.length === 0) {
+ vditor.sv.element.innerHTML = "
\n";
+ (0,selection/* setRangeByWbr */.ib)(vditor.sv.element, range);
+ }
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer);
+ var spanElement = (0,hasClosestByHeadings/* hasClosestByTag */.S)(range.startContainer, "SPAN");
+ if (!blockElement) {
+ return;
+ }
+ if (commandName === "link") {
+ var html = void 0;
+ if (range.toString() === "") {
+ html = "".concat(prefix).concat(Lute.Caret).concat(suffix);
+ }
+ else {
+ html = "".concat(prefix).concat(range.toString()).concat(suffix.replace(")", Lute.Caret + ")"));
+ }
+ document.execCommand("insertHTML", false, html);
+ return;
+ }
+ else if (commandName === "italic" || commandName === "bold" || commandName === "strike" ||
+ commandName === "inline-code" || commandName === "code" || commandName === "table" || commandName === "line") {
+ var html = void 0;
+ // https://github.com/Vanessa219/vditor/issues/563 代码块不需要后面的 ```
+ if (range.toString() === "") {
+ html = "".concat(prefix).concat(Lute.Caret).concat(commandName === "code" ? "" : suffix);
+ }
+ else {
+ html = "".concat(prefix).concat(range.toString()).concat(Lute.Caret).concat(commandName === "code" ? "" : suffix);
+ }
+ if (commandName === "table" || (commandName === "code" && spanElement && spanElement.textContent !== "")) {
+ html = "\n\n" + html;
+ }
+ else if (commandName === "line") {
+ html = "\n\n".concat(prefix, "\n").concat(Lute.Caret);
+ }
+ document.execCommand("insertHTML", false, html);
+ return;
+ }
+ else if (commandName === "check" || commandName === "list" || commandName === "ordered-list" ||
+ commandName === "quote") {
+ if (spanElement) {
+ var marker = "* ";
+ if (commandName === "check") {
+ marker = "* [ ] ";
+ }
+ else if (commandName === "ordered-list") {
+ marker = "1. ";
+ }
+ else if (commandName === "quote") {
+ marker = "> ";
+ }
+ var newLine = getSideByType(spanElement, "newline");
+ if (newLine) {
+ newLine.insertAdjacentText("afterend", marker);
+ }
+ else {
+ blockElement.insertAdjacentText("afterbegin", marker);
+ }
+ inputEvent(vditor);
+ return;
+ }
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor.sv.element, range);
+ processAfterRender(vditor);
+};
+
+;// CONCATENATED MODULE: ./src/ts/upload/getElement.ts
+var getElement = function (vditor) {
+ switch (vditor.currentMode) {
+ case "ir":
+ return vditor.ir.element;
+ case "wysiwyg":
+ return vditor.wysiwyg.element;
+ case "sv":
+ return vditor.sv.element;
+ }
+};
+
+;// CONCATENATED MODULE: ./src/ts/upload/setHeaders.ts
+var setHeaders = function (vditor, xhr) {
+ if (vditor.options.upload.setHeaders) {
+ vditor.options.upload.headers = vditor.options.upload.setHeaders();
+ }
+ if (vditor.options.upload.headers) {
+ Object.keys(vditor.options.upload.headers).forEach(function (key) {
+ xhr.setRequestHeader(key, vditor.options.upload.headers[key]);
+ });
+ }
+};
+
+;// CONCATENATED MODULE: ./src/ts/upload/index.ts
+var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
+ return new (P || (P = Promise))(function (resolve, reject) {
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+};
+var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
+ function verb(n) { return function (v) { return step([n, v]); }; }
+ function step(op) {
+ if (f) throw new TypeError("Generator is already executing.");
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
+ if (y = 0, t) op = [op[0] & 2, t.value];
+ switch (op[0]) {
+ case 0: case 1: t = op; break;
+ case 4: _.label++; return { value: op[1], done: false };
+ case 5: _.label++; y = op[1]; op = [0]; continue;
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
+ default:
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
+ if (t[2]) _.ops.pop();
+ _.trys.pop(); continue;
+ }
+ op = body.call(thisArg, _);
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
+ }
+};
+
+
+
+var Upload = /** @class */ (function () {
+ function Upload() {
+ this.isUploading = false;
+ this.element = document.createElement("div");
+ this.element.className = "vditor-upload";
+ }
+ return Upload;
+}());
+var validateFile = function (vditor, files) {
+ vditor.tip.hide();
+ var uploadFileList = [];
+ var errorTip = "";
+ var uploadingStr = "";
+ var lang = vditor.options.lang;
+ var options = vditor.options;
+ var _loop_1 = function (iMax, i) {
+ var file = files[i];
+ var validate = true;
+ if (!file.name) {
+ errorTip += "".concat(window.VditorI18n.nameEmpty, "");
+ validate = false;
+ }
+ if (file.size > vditor.options.upload.max) {
+ errorTip += "".concat(file.name, " ").concat(window.VditorI18n.over, " ").concat(vditor.options.upload.max / 1024 / 1024, "M");
+ validate = false;
+ }
+ var lastIndex = file.name.lastIndexOf(".");
+ var fileExt = file.name.substr(lastIndex);
+ var filename = vditor.options.upload.filename(file.name.substr(0, lastIndex)) + fileExt;
+ if (vditor.options.upload.accept) {
+ var isAccept = vditor.options.upload.accept.split(",").some(function (item) {
+ var type = item.trim();
+ if (type.indexOf(".") === 0) {
+ if (fileExt.toLowerCase() === type.toLowerCase()) {
+ return true;
+ }
+ }
+ else {
+ if (file.type.split("/")[0] === type.split("/")[0]) {
+ return true;
+ }
+ }
+ return false;
+ });
+ if (!isAccept) {
+ errorTip += "".concat(file.name, " ").concat(window.VditorI18n.fileTypeError, "");
+ validate = false;
+ }
+ }
+ if (validate) {
+ uploadFileList.push(file);
+ uploadingStr += "".concat(filename, " ").concat(window.VditorI18n.uploading, " ").concat(window.VditorI18n.cancelUpload, "");
+ }
+ };
+ for (var iMax = files.length, i = 0; i < iMax; i++) {
+ _loop_1(iMax, i);
+ }
+ vditor.tip.show("".concat(errorTip).concat(uploadingStr, "
"));
+ if (vditor.options.upload.cancel) {
+ var vditorCancelUploadElement = vditor.tip.element.querySelector(".vditorCancelUpload");
+ if (vditorCancelUploadElement) {
+ vditorCancelUploadElement.addEventListener("click", function () {
+ vditor.options.upload.cancel(uploadFileList);
+ vditor.tip.hide();
+ vditor.upload.isUploading = false;
+ });
+ }
+ }
+ return uploadFileList;
+};
+var genUploadedLabel = function (responseText, vditor) {
+ var editorElement = getElement(vditor);
+ editorElement.focus();
+ var response = JSON.parse(responseText);
+ var errorTip = "";
+ if (response.code === 1) {
+ errorTip = "".concat(response.msg);
+ }
+ if (response.data.errFiles && response.data.errFiles.length > 0) {
+ errorTip = "- ".concat(errorTip, "
");
+ response.data.errFiles.forEach(function (data) {
+ var lastIndex = data.lastIndexOf(".");
+ var filename = vditor.options.upload.filename(data.substr(0, lastIndex)) + data.substr(lastIndex);
+ errorTip += "- ".concat(filename, " ").concat(window.VditorI18n.uploadError, "
");
+ });
+ errorTip += "
";
+ }
+ if (errorTip) {
+ vditor.tip.show(errorTip);
+ }
+ else {
+ vditor.tip.hide();
+ }
+ var succFileText = "";
+ Object.keys(response.data.succMap).forEach(function (key) {
+ var path = response.data.succMap[key];
+ var lastIndex = key.lastIndexOf(".");
+ var type = key.substr(lastIndex);
+ var filename = vditor.options.upload.filename(key.substr(0, lastIndex)) + type;
+ type = type.toLowerCase();
+ if (type.indexOf(".wav") === 0 || type.indexOf(".mp3") === 0 || type.indexOf(".ogg") === 0) {
+ if (vditor.currentMode === "wysiwyg") {
+ succFileText += "<audio controls=\"controls\" src=\"".concat(path, "\"></audio>
\n");
+ }
+ else if (vditor.currentMode === "ir") {
+ succFileText += "\n");
+ }
+ else {
+ succFileText += "[".concat(filename, "](").concat(path, ")\n");
+ }
+ }
+ else if (type.indexOf(".apng") === 0
+ || type.indexOf(".bmp") === 0
+ || type.indexOf(".gif") === 0
+ || type.indexOf(".ico") === 0 || type.indexOf(".cur") === 0
+ || type.indexOf(".jpg") === 0 || type.indexOf(".jpeg") === 0 || type.indexOf(".jfif") === 0 || type.indexOf(".pjp") === 0 || type.indexOf(".pjpeg") === 0
+ || type.indexOf(".png") === 0
+ || type.indexOf(".svg") === 0
+ || type.indexOf(".webp") === 0) {
+ if (vditor.currentMode === "wysiwyg") {
+ succFileText += "
\n");
+ }
+ else {
+ succFileText += ".concat(path, ")\n");
+ }
+ }
+ else {
+ if (vditor.currentMode === "wysiwyg") {
+ succFileText += "").concat(filename, "\n");
+ }
+ else {
+ succFileText += "[".concat(filename, "](").concat(path, ")\n");
+ }
+ }
+ });
+ (0,selection/* setSelectionFocus */.Hc)(vditor.upload.range);
+ document.execCommand("insertHTML", false, succFileText);
+ vditor.upload.range = getSelection().getRangeAt(0).cloneRange();
+};
+var uploadFiles = function (vditor, files, element) { return __awaiter(void 0, void 0, void 0, function () {
+ var fileList, filesMax, i, fileItem, isValidate, isValidate, editorElement, validateResult, formData, extraData, _i, _a, key, i, iMax, xhr;
+ return __generator(this, function (_b) {
+ switch (_b.label) {
+ case 0:
+ fileList = [];
+ filesMax = vditor.options.upload.multiple === true ? files.length : 1;
+ for (i = 0; i < filesMax; i++) {
+ fileItem = files[i];
+ if (fileItem instanceof DataTransferItem) {
+ fileItem = fileItem.getAsFile();
+ }
+ fileList.push(fileItem);
+ }
+ if (!vditor.options.upload.handler) return [3 /*break*/, 2];
+ return [4 /*yield*/, vditor.options.upload.handler(fileList)];
+ case 1:
+ isValidate = _b.sent();
+ if (element) {
+ element.value = "";
+ }
+ if (typeof isValidate === "string") {
+ vditor.tip.show(isValidate);
+ return [2 /*return*/];
+ }
+ return [2 /*return*/];
+ case 2:
+ if (!vditor.options.upload.url || !vditor.upload) {
+ if (element) {
+ element.value = "";
+ }
+ vditor.tip.show("please config: options.upload.url");
+ return [2 /*return*/];
+ }
+ if (!vditor.options.upload.file) return [3 /*break*/, 4];
+ return [4 /*yield*/, vditor.options.upload.file(fileList)];
+ case 3:
+ fileList = _b.sent();
+ _b.label = 4;
+ case 4:
+ if (vditor.options.upload.validate) {
+ isValidate = vditor.options.upload.validate(fileList);
+ if (typeof isValidate === "string") {
+ vditor.tip.show(isValidate);
+ return [2 /*return*/];
+ }
+ }
+ editorElement = getElement(vditor);
+ vditor.upload.range = (0,selection/* getEditorRange */.zh)(vditor);
+ validateResult = validateFile(vditor, fileList);
+ if (validateResult.length === 0) {
+ if (element) {
+ element.value = "";
+ }
+ return [2 /*return*/];
+ }
+ formData = new FormData();
+ extraData = vditor.options.upload.extraData;
+ for (_i = 0, _a = Object.keys(extraData); _i < _a.length; _i++) {
+ key = _a[_i];
+ formData.append(key, extraData[key]);
+ }
+ for (i = 0, iMax = validateResult.length; i < iMax; i++) {
+ formData.append(vditor.options.upload.fieldName, validateResult[i]);
+ }
+ xhr = new XMLHttpRequest();
+ vditor.upload.xhr = xhr;
+ xhr.open("POST", vditor.options.upload.url);
+ if (vditor.options.upload.token) {
+ xhr.setRequestHeader("X-Upload-Token", vditor.options.upload.token);
+ }
+ if (vditor.options.upload.withCredentials) {
+ xhr.withCredentials = true;
+ }
+ setHeaders(vditor, xhr);
+ vditor.upload.isUploading = true;
+ editorElement.setAttribute("contenteditable", "false");
+ xhr.onreadystatechange = function () {
+ if (xhr.readyState === XMLHttpRequest.DONE) {
+ vditor.upload.isUploading = false;
+ editorElement.setAttribute("contenteditable", "true");
+ if (xhr.status >= 200 && xhr.status < 300) {
+ if (vditor.options.upload.success) {
+ vditor.options.upload.success(editorElement, xhr.responseText);
+ }
+ else {
+ var responseText = xhr.responseText;
+ if (vditor.options.upload.format) {
+ responseText = vditor.options.upload.format(files, xhr.responseText);
+ }
+ genUploadedLabel(responseText, vditor);
+ }
+ }
+ else {
+ if (vditor.options.upload.error) {
+ vditor.options.upload.error(xhr.responseText);
+ }
+ else {
+ vditor.tip.show(xhr.responseText);
+ }
+ }
+ if (element) {
+ element.value = "";
+ }
+ vditor.upload.element.style.display = "none";
+ vditor.upload.xhr = undefined;
+ }
+ };
+ xhr.upload.onprogress = function (event) {
+ if (!event.lengthComputable) {
+ return;
+ }
+ var progress = event.loaded / event.total * 100;
+ vditor.upload.element.style.display = "block";
+ var progressBar = vditor.upload.element;
+ progressBar.style.width = progress + "%";
+ };
+ xhr.send(formData);
+ return [2 /*return*/];
+ }
+ });
+}); };
+
+
+;// CONCATENATED MODULE: ./src/ts/wysiwyg/input.ts
+
+
+
+
+
+
+
+
+var input_input = function (vditor, range, event) {
+ var _a;
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer);
+ if (!blockElement) {
+ // 使用顶级块元素,应使用 innerHTML
+ blockElement = vditor.wysiwyg.element;
+ }
+ if (event && event.inputType !== "formatItalic"
+ && event.inputType !== "deleteByDrag"
+ && event.inputType !== "insertFromDrop"
+ && event.inputType !== "formatBold"
+ && event.inputType !== "formatRemove"
+ && event.inputType !== "formatStrikeThrough"
+ && event.inputType !== "insertUnorderedList"
+ && event.inputType !== "insertOrderedList"
+ && event.inputType !== "formatOutdent"
+ && event.inputType !== "formatIndent"
+ && event.inputType !== "" // document.execCommand('unlink', false)
+ || !event) {
+ var previousAEmptyElement = previoueIsEmptyA(range.startContainer);
+ if (previousAEmptyElement) {
+ // 链接结尾回车不应该复制到下一行 https://github.com/Vanessa219/vditor/issues/163
+ previousAEmptyElement.remove();
+ }
+ // 保存光标
+ vditor.wysiwyg.element.querySelectorAll("wbr").forEach(function (wbr) {
+ wbr.remove();
+ });
+ range.insertNode(document.createElement("wbr"));
+ // 在行首进行删除,后面的元素会带有样式,需清除
+ blockElement.querySelectorAll("[style]").forEach(function (item) {
+ item.removeAttribute("style");
+ });
+ // 移除空评论
+ blockElement.querySelectorAll(".vditor-comment").forEach(function (item) {
+ if (item.textContent.trim() === "") {
+ item.classList.remove("vditor-comment", "vditor-comment--focus");
+ item.removeAttribute("data-cmtids");
+ }
+ });
+ // 在有评论的行首换行后,该行的前一段会带有评论标识
+ (_a = blockElement.previousElementSibling) === null || _a === void 0 ? void 0 : _a.querySelectorAll(".vditor-comment").forEach(function (item) {
+ if (item.textContent.trim() === "") {
+ item.classList.remove("vditor-comment", "vditor-comment--focus");
+ item.removeAttribute("data-cmtids");
+ }
+ });
+ var html_1 = "";
+ if (blockElement.getAttribute("data-type") === "link-ref-defs-block") {
+ // 修改链接引用
+ blockElement = vditor.wysiwyg.element;
+ }
+ var isWYSIWYGElement = blockElement.isEqualNode(vditor.wysiwyg.element);
+ var footnoteElement = (0,hasClosest/* hasClosestByAttribute */.a1)(blockElement, "data-type", "footnotes-block");
+ if (!isWYSIWYGElement) {
+ // 列表需要到最顶层
+ var topListElement = (0,hasClosest/* getTopList */.O9)(range.startContainer);
+ if (topListElement && !footnoteElement) {
+ var blockquoteElement = (0,hasClosestByHeadings/* hasClosestByTag */.S)(range.startContainer, "BLOCKQUOTE");
+ if (blockquoteElement) {
+ // li 中有 blockquote 就只渲染 blockquote
+ blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer) || blockElement;
+ }
+ else {
+ blockElement = topListElement;
+ }
+ }
+ // 修改脚注
+ if (footnoteElement) {
+ blockElement = footnoteElement;
+ }
+ html_1 = blockElement.outerHTML;
+ if (blockElement.tagName === "UL" || blockElement.tagName === "OL") {
+ // 如果为列表的话,需要把上下的列表都重绘
+ var listPrevElement = blockElement.previousElementSibling;
+ var listNextElement = blockElement.nextElementSibling;
+ if (listPrevElement && (listPrevElement.tagName === "UL" || listPrevElement.tagName === "OL")) {
+ html_1 = listPrevElement.outerHTML + html_1;
+ listPrevElement.remove();
+ }
+ if (listNextElement && (listNextElement.tagName === "UL" || listNextElement.tagName === "OL")) {
+ html_1 = html_1 + listNextElement.outerHTML;
+ listNextElement.remove();
+ }
+ // firefox 列表回车不会产生新的 list item https://github.com/Vanessa219/vditor/issues/194
+ html_1 = html_1.replace("
", "
");
+ }
+ if (!blockElement.innerText.startsWith("```")) {
+ // 添加链接引用
+ vditor.wysiwyg.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach(function (item) {
+ if (item && !blockElement.isEqualNode(item)) {
+ html_1 += item.outerHTML;
+ item.remove();
+ }
+ });
+ // 添加脚注
+ vditor.wysiwyg.element.querySelectorAll("[data-type='footnotes-block']").forEach(function (item) {
+ if (item && !blockElement.isEqualNode(item)) {
+ html_1 += item.outerHTML;
+ item.remove();
+ }
+ });
+ }
+ }
+ else {
+ html_1 = blockElement.innerHTML;
+ }
+ // 合并多个 em, strong,s。以防止多个相同元素在一起时不满足 commonmark 规范,出现标记符
+ html_1 = html_1.replace(/<\/(strong|b)>/g, "")
+ .replace(/<\/(em|i)>/g, "")
+ .replace(/<\/(s|strike)>/g, "");
+ if (html_1 === '```
' && vditor.hint.recentLanguage) {
+ html_1 = '```
'.replace("```", "```" + vditor.hint.recentLanguage);
+ }
+ log("SpinVditorDOM", html_1, "argument", vditor.options.debugger);
+ html_1 = vditor.lute.SpinVditorDOM(html_1);
+ log("SpinVditorDOM", html_1, "result", vditor.options.debugger);
+ if (isWYSIWYGElement) {
+ blockElement.innerHTML = html_1;
+ }
+ else {
+ blockElement.outerHTML = html_1;
+ if (footnoteElement) {
+ // 更新正文中的 tip
+ var footnoteItemElement = (0,hasClosest/* hasTopClosestByTag */.E2)(vditor.wysiwyg.element.querySelector("wbr"), "LI");
+ if (footnoteItemElement) {
+ var footnoteRefElement = vditor.wysiwyg.element.querySelector("sup[data-type=\"footnotes-ref\"][data-footnotes-label=\"".concat(footnoteItemElement.getAttribute("data-marker"), "\"]"));
+ if (footnoteRefElement) {
+ footnoteRefElement.setAttribute("aria-label", footnoteItemElement.textContent.trim().substr(0, 24));
+ }
+ }
+ }
+ }
+ var firstLinkRefDefElement_1;
+ var allLinkRefDefsElement = vditor.wysiwyg.element.querySelectorAll("[data-type='link-ref-defs-block']");
+ allLinkRefDefsElement.forEach(function (item, index) {
+ if (index === 0) {
+ firstLinkRefDefElement_1 = item;
+ }
+ else {
+ firstLinkRefDefElement_1.insertAdjacentHTML("beforeend", item.innerHTML);
+ item.remove();
+ }
+ });
+ if (allLinkRefDefsElement.length > 0) {
+ vditor.wysiwyg.element.insertAdjacentElement("beforeend", allLinkRefDefsElement[0]);
+ }
+ // 脚注合并后添加的末尾
+ var firstFootnoteElement_1;
+ var allFootnoteElement = vditor.wysiwyg.element.querySelectorAll("[data-type='footnotes-block']");
+ allFootnoteElement.forEach(function (item, index) {
+ if (index === 0) {
+ firstFootnoteElement_1 = item;
+ }
+ else {
+ firstFootnoteElement_1.insertAdjacentHTML("beforeend", item.innerHTML);
+ item.remove();
+ }
+ });
+ if (allFootnoteElement.length > 0) {
+ vditor.wysiwyg.element.insertAdjacentElement("beforeend", allFootnoteElement[0]);
+ }
+ // 设置光标
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ vditor.wysiwyg.element.querySelectorAll(".vditor-wysiwyg__preview[data-render='2']")
+ .forEach(function (item) {
+ processCodeRender(item, vditor);
+ });
+ if (event && (event.inputType === "deleteContentBackward" || event.inputType === "deleteContentForward") &&
+ vditor.options.comment.enable) {
+ vditor.wysiwyg.triggerRemoveComment(vditor);
+ vditor.options.comment.adjustTop(vditor.wysiwyg.getComments(vditor, true));
+ }
+ }
+ renderToc(vditor);
+ afterRenderEvent(vditor, {
+ enableAddUndoStack: true,
+ enableHint: true,
+ enableInput: true,
+ });
+};
+
+;// CONCATENATED MODULE: ./src/ts/util/fixBrowserBehavior.ts
+var __makeTemplateObject = (undefined && undefined.__makeTemplateObject) || function (cooked, raw) {
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
+ return cooked;
+};
+var fixBrowserBehavior_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
+ return new (P || (P = Promise))(function (resolve, reject) {
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+};
+var fixBrowserBehavior_generator = (undefined && undefined.__generator) || function (thisArg, body) {
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
+ function verb(n) { return function (v) { return step([n, v]); }; }
+ function step(op) {
+ if (f) throw new TypeError("Generator is already executing.");
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
+ if (y = 0, t) op = [op[0] & 2, t.value];
+ switch (op[0]) {
+ case 0: case 1: t = op; break;
+ case 4: _.label++; return { value: op[1], done: false };
+ case 5: _.label++; y = op[1]; op = [0]; continue;
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
+ default:
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
+ if (t[2]) _.ops.pop();
+ _.trys.pop(); continue;
+ }
+ op = body.call(thisArg, _);
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
+ }
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+// https://github.com/Vanessa219/vditor/issues/508 软键盘无法删除空块
+var fixGSKeyBackspace = function (event, vditor, startContainer) {
+ if (event.keyCode === 229 && event.code === "" && event.key === "Unidentified" && vditor.currentMode !== "sv") {
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(startContainer);
+ // 移动端的标点符号都显示为 299,因此需限定为空删除的条件
+ if (blockElement && blockElement.textContent.trim() === "") {
+ vditor[vditor.currentMode].composingLock = true;
+ return false;
+ }
+ }
+ return true;
+};
+// https://github.com/Vanessa219/vditor/issues/361 代码块后输入中文
+var fixCJKPosition = function (range, vditor, event) {
+ if (event.key === "Enter" || event.key === "Tab" || event.key === "Backspace" || event.key.indexOf("Arrow") > -1
+ || (0,compatibility/* isCtrl */.yl)(event) || event.key === "Escape" || event.shiftKey || event.altKey) {
+ return;
+ }
+ var pLiElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "P") ||
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "LI");
+ if (pLiElement && (0,selection/* getSelectPosition */.im)(pLiElement, vditor[vditor.currentMode].element, range).start === 0) {
+ // https://github.com/Vanessa219/vditor/issues/1289 WKWebView切换输入法产生六分之一空格,造成光标错位
+ if (pLiElement.nodeValue) {
+ pLiElement.nodeValue = pLiElement.nodeValue.replace(/\u2006/g, '');
+ }
+ var zwspNode = document.createTextNode(constants/* Constants.ZWSP */.g.ZWSP);
+ range.insertNode(zwspNode);
+ range.setStartAfter(zwspNode);
+ }
+};
+// https://github.com/Vanessa219/vditor/issues/381 光标在内联数学公式中无法向下移动
+var fixCursorDownInlineMath = function (range, key) {
+ if (key === "ArrowDown" || key === "ArrowUp") {
+ var inlineElement = (0,hasClosest/* hasClosestByAttribute */.a1)(range.startContainer, "data-type", "math-inline") ||
+ (0,hasClosest/* hasClosestByAttribute */.a1)(range.startContainer, "data-type", "html-entity") ||
+ (0,hasClosest/* hasClosestByAttribute */.a1)(range.startContainer, "data-type", "html-inline");
+ if (inlineElement) {
+ if (key === "ArrowDown") {
+ range.setStartAfter(inlineElement.parentElement);
+ }
+ if (key === "ArrowUp") {
+ range.setStartBefore(inlineElement.parentElement);
+ }
+ }
+ }
+};
+var insertEmptyBlock = function (vditor, position) {
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer);
+ if (blockElement) {
+ blockElement.insertAdjacentHTML(position, "".concat(constants/* Constants.ZWSP */.g.ZWSP, "\n
"));
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ highlightToolbar(vditor);
+ execAfterRender(vditor);
+ }
+};
+var isFirstCell = function (cellElement) {
+ var tableElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(cellElement, "TABLE");
+ if (tableElement && tableElement.rows[0].cells[0].isSameNode(cellElement)) {
+ return tableElement;
+ }
+ return false;
+};
+var isLastCell = function (cellElement) {
+ var tableElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(cellElement, "TABLE");
+ if (tableElement && tableElement.lastElementChild.lastElementChild.lastElementChild.isSameNode(cellElement)) {
+ return tableElement;
+ }
+ return false;
+};
+// 光标设置到前一个表格中
+var goPreviousCell = function (cellElement, range, isSelected) {
+ if (isSelected === void 0) { isSelected = true; }
+ var previousElement = cellElement.previousElementSibling;
+ if (!previousElement) {
+ if (cellElement.parentElement.previousElementSibling) {
+ previousElement = cellElement.parentElement.previousElementSibling.lastElementChild;
+ }
+ else if (cellElement.parentElement.parentElement.tagName === "TBODY" &&
+ cellElement.parentElement.parentElement.previousElementSibling) {
+ previousElement = cellElement.parentElement
+ .parentElement.previousElementSibling.lastElementChild.lastElementChild;
+ }
+ else {
+ previousElement = null;
+ }
+ }
+ if (previousElement) {
+ range.selectNodeContents(previousElement);
+ if (!isSelected) {
+ range.collapse(false);
+ }
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ return previousElement;
+};
+var insertAfterBlock = function (vditor, event, range, element, blockElement) {
+ var position = (0,selection/* getSelectPosition */.im)(element, vditor[vditor.currentMode].element, range);
+ if ((event.key === "ArrowDown" && element.textContent.trimRight().substr(position.start).indexOf("\n") === -1) ||
+ (event.key === "ArrowRight" && position.start >= element.textContent.trimRight().length)) {
+ var nextElement = blockElement.nextElementSibling;
+ if (!nextElement ||
+ (nextElement && (nextElement.tagName === "TABLE" || nextElement.getAttribute("data-type")))) {
+ blockElement.insertAdjacentHTML("afterend", "".concat(constants/* Constants.ZWSP */.g.ZWSP, "
"));
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ }
+ else {
+ range.selectNodeContents(nextElement);
+ range.collapse(true);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ event.preventDefault();
+ return true;
+ }
+ return false;
+};
+var insertBeforeBlock = function (vditor, event, range, element, blockElement) {
+ var position = (0,selection/* getSelectPosition */.im)(element, vditor[vditor.currentMode].element, range);
+ if ((event.key === "ArrowUp" && element.textContent.substr(0, position.start).indexOf("\n") === -1) ||
+ ((event.key === "ArrowLeft" || (event.key === "Backspace" && range.toString() === "")) &&
+ position.start === 0)) {
+ var previousElement = blockElement.previousElementSibling;
+ // table || code
+ if (!previousElement ||
+ (previousElement && (previousElement.tagName === "TABLE" || previousElement.getAttribute("data-type")))) {
+ blockElement.insertAdjacentHTML("beforebegin", "".concat(constants/* Constants.ZWSP */.g.ZWSP, "
"));
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ }
+ else {
+ range.selectNodeContents(previousElement);
+ range.collapse(false);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ event.preventDefault();
+ return true;
+ }
+ return false;
+};
+var listToggle = function (vditor, range, type, cancel) {
+ if (cancel === void 0) { cancel = true; }
+ var itemElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "LI");
+ vditor[vditor.currentMode].element.querySelectorAll("wbr").forEach(function (wbr) {
+ wbr.remove();
+ });
+ range.insertNode(document.createElement("wbr"));
+ if (cancel && itemElement) {
+ // 取消
+ var pHTML = "";
+ for (var i = 0; i < itemElement.parentElement.childElementCount; i++) {
+ var inputElement = itemElement.parentElement.children[i].querySelector("input");
+ if (inputElement) {
+ inputElement.remove();
+ }
+ pHTML += "".concat(itemElement.parentElement.children[i].innerHTML.trimLeft(), "
");
+ }
+ itemElement.parentElement.insertAdjacentHTML("beforebegin", pHTML);
+ itemElement.parentElement.remove();
+ }
+ else {
+ if (!itemElement) {
+ // 添加
+ var blockElement = (0,hasClosest/* hasClosestByAttribute */.a1)(range.startContainer, "data-block", "0");
+ if (!blockElement) {
+ vditor[vditor.currentMode].element.querySelector("wbr").remove();
+ blockElement = vditor[vditor.currentMode].element.querySelector("p");
+ blockElement.innerHTML = "";
+ }
+ if (type === "check") {
+ blockElement.insertAdjacentHTML("beforebegin", ""));
+ blockElement.remove();
+ }
+ else if (type === "list") {
+ blockElement.insertAdjacentHTML("beforebegin", "- ".concat(blockElement.innerHTML, "
"));
+ blockElement.remove();
+ }
+ else if (type === "ordered-list") {
+ blockElement.insertAdjacentHTML("beforebegin", "- ".concat(blockElement.innerHTML, "
"));
+ blockElement.remove();
+ }
+ }
+ else {
+ // 切换
+ if (type === "check") {
+ itemElement.parentElement.querySelectorAll("li").forEach(function (item) {
+ item.insertAdjacentHTML("afterbegin", "".concat(item.textContent.indexOf(" ") === 0 ? "" : " "));
+ item.classList.add("vditor-task");
+ });
+ }
+ else {
+ if (itemElement.querySelector("input")) {
+ itemElement.parentElement.querySelectorAll("li").forEach(function (item) {
+ item.querySelector("input").remove();
+ item.classList.remove("vditor-task");
+ });
+ }
+ var element = void 0;
+ if (type === "list") {
+ element = document.createElement("ul");
+ element.setAttribute("data-marker", "*");
+ }
+ else {
+ element = document.createElement("ol");
+ element.setAttribute("data-marker", "1.");
+ }
+ element.setAttribute("data-block", "0");
+ element.setAttribute("data-tight", itemElement.parentElement.getAttribute("data-tight"));
+ element.innerHTML = itemElement.parentElement.innerHTML;
+ itemElement.parentElement.parentNode.replaceChild(element, itemElement.parentElement);
+ }
+ }
+ }
+};
+var listIndent = function (vditor, liElement, range) {
+ var previousElement = liElement.previousElementSibling;
+ if (liElement && previousElement) {
+ var liElements_1 = [liElement];
+ Array.from(range.cloneContents().children).forEach(function (item, index) {
+ if (item.nodeType !== 3 && liElement && item.textContent.trim() !== ""
+ && liElement.getAttribute("data-node-id") === item.getAttribute("data-node-id")) {
+ if (index !== 0) {
+ liElements_1.push(liElement);
+ }
+ liElement = liElement.nextElementSibling;
+ }
+ });
+ vditor[vditor.currentMode].element.querySelectorAll("wbr").forEach(function (wbr) {
+ wbr.remove();
+ });
+ range.insertNode(document.createElement("wbr"));
+ var liParentElement = previousElement.parentElement;
+ var liHTML_1 = "";
+ liElements_1.forEach(function (item) {
+ var marker = item.getAttribute("data-marker");
+ if (marker.length !== 1) {
+ marker = "1".concat(marker.slice(-1));
+ }
+ liHTML_1 += "").concat(item.innerHTML, "");
+ item.remove();
+ });
+ previousElement.insertAdjacentHTML("beforeend", "<".concat(liParentElement.tagName, " data-block=\"0\">").concat(liHTML_1, "").concat(liParentElement.tagName, ">"));
+ if (vditor.currentMode === "wysiwyg") {
+ liParentElement.outerHTML = vditor.lute.SpinVditorDOM(liParentElement.outerHTML);
+ }
+ else {
+ liParentElement.outerHTML = vditor.lute.SpinVditorIRDOM(liParentElement.outerHTML);
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ var tempTopListElement = (0,hasClosest/* getTopList */.O9)(range.startContainer);
+ if (tempTopListElement) {
+ tempTopListElement.querySelectorAll(".vditor-".concat(vditor.currentMode, "__preview[data-render='2']"))
+ .forEach(function (item) {
+ processCodeRender(item, vditor);
+ if (vditor.currentMode === "wysiwyg") {
+ item.previousElementSibling.setAttribute("style", "display:none");
+ }
+ });
+ }
+ execAfterRender(vditor);
+ highlightToolbar(vditor);
+ }
+ else {
+ vditor[vditor.currentMode].element.focus();
+ }
+};
+var listOutdent = function (vditor, liElement, range, topListElement) {
+ var liParentLiElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(liElement.parentElement, "LI");
+ if (liParentLiElement) {
+ vditor[vditor.currentMode].element.querySelectorAll("wbr").forEach(function (wbr) {
+ wbr.remove();
+ });
+ range.insertNode(document.createElement("wbr"));
+ var liParentElement = liElement.parentElement;
+ var liParentAfterElement = liParentElement.cloneNode();
+ var liElements_2 = [liElement];
+ Array.from(range.cloneContents().children).forEach(function (item, index) {
+ if (item.nodeType !== 3 && liElement && item.textContent.trim() !== "" &&
+ liElement.getAttribute("data-node-id") === item.getAttribute("data-node-id")) {
+ if (index !== 0) {
+ liElements_2.push(liElement);
+ }
+ liElement = liElement.nextElementSibling;
+ }
+ });
+ var isMatch_1 = false;
+ var afterHTML_1 = "";
+ liParentElement.querySelectorAll("li").forEach(function (item) {
+ if (isMatch_1) {
+ afterHTML_1 += item.outerHTML;
+ if (!item.nextElementSibling && !item.previousElementSibling) {
+ item.parentElement.remove();
+ }
+ else {
+ item.remove();
+ }
+ }
+ if (item.isSameNode(liElements_2[liElements_2.length - 1])) {
+ isMatch_1 = true;
+ }
+ });
+ liElements_2.reverse().forEach(function (item) {
+ liParentLiElement.insertAdjacentElement("afterend", item);
+ });
+ if (afterHTML_1) {
+ liParentAfterElement.innerHTML = afterHTML_1;
+ liElements_2[0].insertAdjacentElement("beforeend", liParentAfterElement);
+ }
+ if (vditor.currentMode === "wysiwyg") {
+ topListElement.outerHTML = vditor.lute.SpinVditorDOM(topListElement.outerHTML);
+ }
+ else {
+ topListElement.outerHTML = vditor.lute.SpinVditorIRDOM(topListElement.outerHTML);
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ var tempTopListElement = (0,hasClosest/* getTopList */.O9)(range.startContainer);
+ if (tempTopListElement) {
+ tempTopListElement.querySelectorAll(".vditor-".concat(vditor.currentMode, "__preview[data-render='2']"))
+ .forEach(function (item) {
+ processCodeRender(item, vditor);
+ if (vditor.currentMode === "wysiwyg") {
+ item.previousElementSibling.setAttribute("style", "display:none");
+ }
+ });
+ }
+ execAfterRender(vditor);
+ highlightToolbar(vditor);
+ }
+ else {
+ vditor[vditor.currentMode].element.focus();
+ }
+};
+var setTableAlign = function (tableElement, type) {
+ var cell = getSelection().getRangeAt(0).startContainer.parentElement;
+ var columnCnt = tableElement.rows[0].cells.length;
+ var rowCnt = tableElement.rows.length;
+ var currentColumn = 0;
+ for (var i = 0; i < rowCnt; i++) {
+ for (var j = 0; j < columnCnt; j++) {
+ if (tableElement.rows[i].cells[j].isSameNode(cell)) {
+ currentColumn = j;
+ break;
+ }
+ }
+ }
+ for (var k = 0; k < rowCnt; k++) {
+ tableElement.rows[k].cells[currentColumn].setAttribute("align", type);
+ }
+};
+var isHrMD = function (text) {
+ // - _ *
+ var marker = text.trimRight().split("\n").pop();
+ if (marker === "") {
+ return false;
+ }
+ if (marker.replace(/ |-/g, "") === ""
+ || marker.replace(/ |_/g, "") === ""
+ || marker.replace(/ |\*/g, "") === "") {
+ if (marker.replace(/ /g, "").length > 2) {
+ if (marker.indexOf("-") > -1 && marker.trimLeft().indexOf(" ") === -1
+ && text.trimRight().split("\n").length > 1) {
+ // 满足 heading
+ return false;
+ }
+ if (marker.indexOf(" ") === 0 || marker.indexOf("\t") === 0) {
+ // 代码块
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+ return false;
+};
+var isHeadingMD = function (text) {
+ // - =
+ var textArray = text.trimRight().split("\n");
+ text = textArray.pop();
+ if (text.indexOf(" ") === 0 || text.indexOf("\t") === 0) {
+ return false;
+ }
+ text = text.trimLeft();
+ if (text === "" || textArray.length === 0) {
+ return false;
+ }
+ if (text.replace(/-/g, "") === ""
+ || text.replace(/=/g, "") === "") {
+ return true;
+ }
+ return false;
+};
+var execAfterRender = function (vditor, options) {
+ if (options === void 0) { options = {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: true,
+ }; }
+ if (vditor.currentMode === "wysiwyg") {
+ afterRenderEvent(vditor, options);
+ }
+ else if (vditor.currentMode === "ir") {
+ process_processAfterRender(vditor, options);
+ }
+ else if (vditor.currentMode === "sv") {
+ processAfterRender(vditor, options);
+ }
+};
+var fixList = function (range, vditor, pElement, event) {
+ var _a;
+ var startContainer = range.startContainer;
+ var liElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "LI");
+ if (liElement) {
+ if (!(0,compatibility/* isCtrl */.yl)(event) && !event.altKey && event.key === "Enter" &&
+ // fix li 中有多个 P 时,在第一个 P 中换行会在下方生成新的 li
+ (!event.shiftKey && pElement && liElement.contains(pElement) && pElement.nextElementSibling)) {
+ if (liElement && !liElement.textContent.endsWith("\n")) {
+ // li 结尾需 \n
+ liElement.insertAdjacentText("beforeend", "\n");
+ }
+ range.insertNode(document.createTextNode("\n\n"));
+ range.collapse(false);
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ if (!(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey && event.key === "Backspace" &&
+ !liElement.previousElementSibling && range.toString() === "" &&
+ (0,selection/* getSelectPosition */.im)(liElement, vditor[vditor.currentMode].element, range).start === 0) {
+ // 光标位于点和第一个字符中间时,无法删除 li 元素
+ if (liElement.nextElementSibling) {
+ liElement.parentElement.insertAdjacentHTML("beforebegin", "".concat(liElement.innerHTML, "
"));
+ liElement.remove();
+ }
+ else {
+ liElement.parentElement.outerHTML = "".concat(liElement.innerHTML, "
");
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ // 空列表删除后与上一级段落对齐
+ if (!(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey && event.key === "Backspace" &&
+ liElement.textContent.trim().replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" &&
+ range.toString() === "" && ((_a = liElement.previousElementSibling) === null || _a === void 0 ? void 0 : _a.tagName) === "LI") {
+ liElement.previousElementSibling.insertAdjacentText("beforeend", "\n\n");
+ range.selectNodeContents(liElement.previousElementSibling);
+ range.collapse(false);
+ liElement.remove();
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ if (!(0,compatibility/* isCtrl */.yl)(event) && !event.altKey && event.key === "Tab") {
+ // 光标位于第一/零字符时,tab 用于列表的缩进
+ var isFirst = false;
+ if (range.startOffset === 0
+ && ((startContainer.nodeType === 3 && !startContainer.previousSibling)
+ || (startContainer.nodeType !== 3 && startContainer.nodeName === "LI"))) {
+ // 有序/无序列表
+ isFirst = true;
+ }
+ else if (liElement.classList.contains("vditor-task") && range.startOffset === 1
+ && startContainer.previousSibling.nodeType !== 3
+ && startContainer.previousSibling.tagName === "INPUT") {
+ // 任务列表
+ isFirst = true;
+ }
+ if (isFirst || range.toString() !== "") {
+ if (event.shiftKey) {
+ listOutdent(vditor, liElement, range, liElement.parentElement);
+ }
+ else {
+ listIndent(vditor, liElement, range);
+ }
+ event.preventDefault();
+ return true;
+ }
+ }
+ }
+ return false;
+};
+// tab 处理: block code render, table, 列表第一个字符中的 tab 处理单独写在上面
+var fixTab = function (vditor, range, event) {
+ if (vditor.options.tab && event.key === "Tab") {
+ if (event.shiftKey) {
+ // TODO shift+tab
+ }
+ else {
+ if (range.toString() === "") {
+ range.insertNode(document.createTextNode(vditor.options.tab));
+ range.collapse(false);
+ }
+ else {
+ range.extractContents();
+ range.insertNode(document.createTextNode(vditor.options.tab));
+ range.collapse(false);
+ }
+ }
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+};
+var fixMarkdown = function (event, vditor, pElement, range) {
+ if (!pElement) {
+ return;
+ }
+ if (!(0,compatibility/* isCtrl */.yl)(event) && !event.altKey && event.key === "Enter") {
+ var pText = String.raw(templateObject_1 || (templateObject_1 = __makeTemplateObject(["", ""], ["", ""])), pElement.textContent).replace(/\\\|/g, "").trim();
+ var pTextList = pText.split("|");
+ if (pText.startsWith("|") && pText.endsWith("|") && pTextList.length > 3) {
+ // table 自动完成
+ var tableHeaderMD = pTextList.map(function () { return "---"; }).join("|");
+ tableHeaderMD =
+ pElement.textContent + "\n" + tableHeaderMD.substring(3, tableHeaderMD.length - 3) + "\n|";
+ pElement.outerHTML = vditor.lute.SpinVditorDOM(tableHeaderMD);
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ execAfterRender(vditor);
+ scrollCenter(vditor);
+ event.preventDefault();
+ return true;
+ }
+ // hr 渲染
+ if (isHrMD(pElement.innerHTML) && pElement.previousElementSibling) {
+ // 软换行后 hr 前有内容
+ var pInnerHTML = "";
+ var innerHTMLList = pElement.innerHTML.trimRight().split("\n");
+ if (innerHTMLList.length > 1) {
+ innerHTMLList.pop();
+ pInnerHTML = "".concat(innerHTMLList.join("\n"), "
");
+ }
+ pElement.insertAdjacentHTML("afterend", "".concat(pInnerHTML, "
\n
"));
+ pElement.remove();
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ execAfterRender(vditor);
+ scrollCenter(vditor);
+ event.preventDefault();
+ return true;
+ }
+ if (isHeadingMD(pElement.innerHTML)) {
+ // heading 渲染
+ if (vditor.currentMode === "wysiwyg") {
+ pElement.outerHTML = vditor.lute.SpinVditorDOM(pElement.innerHTML + '\n
');
+ }
+ else {
+ pElement.outerHTML = vditor.lute.SpinVditorIRDOM(pElement.innerHTML + '\n
');
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ execAfterRender(vditor);
+ scrollCenter(vditor);
+ event.preventDefault();
+ return true;
+ }
+ }
+ // 软换行会被切割 https://github.com/Vanessa219/vditor/issues/220
+ if (range.collapsed && pElement.previousElementSibling && event.key === "Backspace" &&
+ !(0,compatibility/* isCtrl */.yl)(event) && !event.altKey && !event.shiftKey &&
+ pElement.textContent.trimRight().split("\n").length > 1 &&
+ (0,selection/* getSelectPosition */.im)(pElement, vditor[vditor.currentMode].element, range).start === 0) {
+ var lastElement = (0,hasClosest/* getLastNode */.DX)(pElement.previousElementSibling);
+ if (!lastElement.textContent.endsWith("\n")) {
+ lastElement.textContent = lastElement.textContent + "\n";
+ }
+ lastElement.parentElement.insertAdjacentHTML("beforeend", "".concat(pElement.innerHTML));
+ pElement.remove();
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ return false;
+ }
+ return false;
+};
+var insertRow = function (vditor, range, cellElement) {
+ var rowHTML = "";
+ for (var m = 0; m < cellElement.parentElement.childElementCount; m++) {
+ rowHTML += " | ");
+ }
+ if (cellElement.tagName === "TH") {
+ cellElement.parentElement.parentElement.insertAdjacentHTML("afterend", "".concat(rowHTML, "
"));
+ }
+ else {
+ cellElement.parentElement.insertAdjacentHTML("afterend", "".concat(rowHTML, "
"));
+ }
+ execAfterRender(vditor);
+};
+var insertRowAbove = function (vditor, range, cellElement) {
+ var rowHTML = "";
+ for (var m = 0; m < cellElement.parentElement.childElementCount; m++) {
+ if (cellElement.tagName === "TH") {
+ rowHTML += " | ");
+ }
+ else {
+ rowHTML += " | ");
+ }
+ }
+ if (cellElement.tagName === "TH") {
+ cellElement.parentElement.parentElement.insertAdjacentHTML("beforebegin", "".concat(rowHTML, "
"));
+ range.insertNode(document.createElement("wbr"));
+ var theadHTML = cellElement.parentElement.innerHTML.replace(//g, " | ").replace(/<\/th>/g, " | ");
+ cellElement.parentElement.parentElement.nextElementSibling.insertAdjacentHTML("afterbegin", theadHTML);
+ cellElement.parentElement.parentElement.remove();
+ (0,selection/* setRangeByWbr */.ib)(vditor.ir.element, range);
+ }
+ else {
+ cellElement.parentElement.insertAdjacentHTML("beforebegin", "".concat(rowHTML, "
"));
+ }
+ execAfterRender(vditor);
+};
+var insertColumn = function (vditor, tableElement, cellElement, type) {
+ if (type === void 0) { type = "afterend"; }
+ var index = 0;
+ var previousElement = cellElement.previousElementSibling;
+ while (previousElement) {
+ index++;
+ previousElement = previousElement.previousElementSibling;
+ }
+ for (var i = 0; i < tableElement.rows.length; i++) {
+ if (i === 0) {
+ tableElement.rows[i].cells[index].insertAdjacentHTML(type, " | ");
+ }
+ else {
+ tableElement.rows[i].cells[index].insertAdjacentHTML(type, " | ");
+ }
+ }
+ execAfterRender(vditor);
+};
+var deleteRow = function (vditor, range, cellElement) {
+ if (cellElement.tagName === "TD") {
+ var tbodyElement = cellElement.parentElement.parentElement;
+ if (cellElement.parentElement.previousElementSibling) {
+ range.selectNodeContents(cellElement.parentElement.previousElementSibling.lastElementChild);
+ }
+ else {
+ range.selectNodeContents(tbodyElement.previousElementSibling.lastElementChild.lastElementChild);
+ }
+ if (tbodyElement.childElementCount === 1) {
+ tbodyElement.remove();
+ }
+ else {
+ cellElement.parentElement.remove();
+ }
+ range.collapse(false);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ execAfterRender(vditor);
+ }
+};
+var deleteColumn = function (vditor, range, tableElement, cellElement) {
+ var index = 0;
+ var previousElement = cellElement.previousElementSibling;
+ while (previousElement) {
+ index++;
+ previousElement = previousElement.previousElementSibling;
+ }
+ if (cellElement.previousElementSibling || cellElement.nextElementSibling) {
+ range.selectNodeContents(cellElement.previousElementSibling || cellElement.nextElementSibling);
+ range.collapse(true);
+ }
+ for (var i = 0; i < tableElement.rows.length; i++) {
+ var cells = tableElement.rows[i].cells;
+ if (cells.length === 1) {
+ tableElement.remove();
+ highlightToolbar(vditor);
+ break;
+ }
+ cells[index].remove();
+ }
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ execAfterRender(vditor);
+};
+var fixTable = function (vditor, event, range) {
+ var startContainer = range.startContainer;
+ var cellElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TD") ||
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "TH");
+ if (cellElement) {
+ // 换行或软换行:在 cell 中添加 br
+ if (!(0,compatibility/* isCtrl */.yl)(event) && !event.altKey && event.key === "Enter") {
+ if (!cellElement.lastElementChild ||
+ (cellElement.lastElementChild && (!cellElement.lastElementChild.isSameNode(cellElement.lastChild) ||
+ cellElement.lastElementChild.tagName !== "BR"))) {
+ cellElement.insertAdjacentHTML("beforeend", "
");
+ }
+ var brElement = document.createElement("br");
+ range.insertNode(brElement);
+ range.setStartAfter(brElement);
+ execAfterRender(vditor);
+ scrollCenter(vditor);
+ event.preventDefault();
+ return true;
+ }
+ // tab:光标移向下一个 cell
+ if (event.key === "Tab") {
+ if (event.shiftKey) {
+ // shift + tab 光标移动到前一个 cell
+ goPreviousCell(cellElement, range);
+ event.preventDefault();
+ return true;
+ }
+ var nextElement = cellElement.nextElementSibling;
+ if (!nextElement) {
+ if (cellElement.parentElement.nextElementSibling) {
+ nextElement = cellElement.parentElement.nextElementSibling.firstElementChild;
+ }
+ else if (cellElement.parentElement.parentElement.tagName === "THEAD" &&
+ cellElement.parentElement.parentElement.nextElementSibling) {
+ nextElement =
+ cellElement.parentElement.parentElement.nextElementSibling.firstElementChild.firstElementChild;
+ }
+ else {
+ nextElement = null;
+ }
+ }
+ if (nextElement) {
+ range.selectNodeContents(nextElement);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ event.preventDefault();
+ return true;
+ }
+ var tableElement = cellElement.parentElement.parentElement.parentElement;
+ if (event.key === "ArrowUp") {
+ event.preventDefault();
+ if (cellElement.tagName === "TH") {
+ if (tableElement.previousElementSibling) {
+ range.selectNodeContents(tableElement.previousElementSibling);
+ range.collapse(false);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ else {
+ insertEmptyBlock(vditor, "beforebegin");
+ }
+ return true;
+ }
+ var m = 0;
+ var trElement = cellElement.parentElement;
+ for (; m < trElement.cells.length; m++) {
+ if (trElement.cells[m].isSameNode(cellElement)) {
+ break;
+ }
+ }
+ var previousElement = trElement.previousElementSibling;
+ if (!previousElement) {
+ previousElement = trElement.parentElement.previousElementSibling.firstChild;
+ }
+ range.selectNodeContents(previousElement.cells[m]);
+ range.collapse(false);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ return true;
+ }
+ if (event.key === "ArrowDown") {
+ event.preventDefault();
+ var trElement = cellElement.parentElement;
+ if (!trElement.nextElementSibling && cellElement.tagName === "TD") {
+ if (tableElement.nextElementSibling) {
+ range.selectNodeContents(tableElement.nextElementSibling);
+ range.collapse(true);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ else {
+ insertEmptyBlock(vditor, "afterend");
+ }
+ return true;
+ }
+ var m = 0;
+ for (; m < trElement.cells.length; m++) {
+ if (trElement.cells[m].isSameNode(cellElement)) {
+ break;
+ }
+ }
+ var nextElement = trElement.nextElementSibling;
+ if (!nextElement) {
+ nextElement = trElement.parentElement.nextElementSibling.firstChild;
+ }
+ range.selectNodeContents(nextElement.cells[m]);
+ range.collapse(true);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ return true;
+ }
+ // focus row input, only wysiwyg
+ if (vditor.currentMode === "wysiwyg" &&
+ !(0,compatibility/* isCtrl */.yl)(event) && event.key === "Enter" && !event.shiftKey && event.altKey) {
+ var inputElement = vditor.wysiwyg.popover.querySelector(".vditor-input");
+ inputElement.focus();
+ inputElement.select();
+ event.preventDefault();
+ return true;
+ }
+ // Backspace:光标移动到前一个 cell
+ if (!(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey && event.key === "Backspace"
+ && range.startOffset === 0 && range.toString() === "") {
+ var previousCellElement = goPreviousCell(cellElement, range, false);
+ if (!previousCellElement && tableElement) {
+ if (tableElement.textContent.trim() === "") {
+ tableElement.outerHTML = "\n
";
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ }
+ else {
+ range.setStartBefore(tableElement);
+ range.collapse(true);
+ }
+ execAfterRender(vditor);
+ }
+ event.preventDefault();
+ return true;
+ }
+ // 上方新添加一行
+ if (matchHotKey("⇧⌘F", event)) {
+ insertRowAbove(vditor, range, cellElement);
+ event.preventDefault();
+ return true;
+ }
+ // 下方新添加一行 https://github.com/Vanessa219/vditor/issues/46
+ if (matchHotKey("⌘=", event)) {
+ insertRow(vditor, range, cellElement);
+ event.preventDefault();
+ return true;
+ }
+ // 左方新添加一列
+ if (matchHotKey("⇧⌘G", event)) {
+ insertColumn(vditor, tableElement, cellElement, "beforebegin");
+ event.preventDefault();
+ return true;
+ }
+ // 后方新添加一列
+ if (matchHotKey("⇧⌘=", event)) {
+ insertColumn(vditor, tableElement, cellElement);
+ event.preventDefault();
+ return true;
+ }
+ // 删除当前行
+ if (matchHotKey("⌘-", event)) {
+ deleteRow(vditor, range, cellElement);
+ event.preventDefault();
+ return true;
+ }
+ // 删除当前列
+ if (matchHotKey("⇧⌘-", event)) {
+ deleteColumn(vditor, range, tableElement, cellElement);
+ event.preventDefault();
+ return true;
+ }
+ // 剧左
+ if (matchHotKey("⇧⌘L", event)) {
+ if (vditor.currentMode === "ir") {
+ setTableAlign(tableElement, "left");
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ else {
+ var itemElement = vditor.wysiwyg.popover.querySelector('[data-type="left"]');
+ if (itemElement) {
+ itemElement.click();
+ event.preventDefault();
+ return true;
+ }
+ }
+ }
+ // 剧中
+ if (matchHotKey("⇧⌘C", event)) {
+ if (vditor.currentMode === "ir") {
+ setTableAlign(tableElement, "center");
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ else {
+ var itemElement = vditor.wysiwyg.popover.querySelector('[data-type="center"]');
+ if (itemElement) {
+ itemElement.click();
+ event.preventDefault();
+ return true;
+ }
+ }
+ }
+ // 剧右
+ if (matchHotKey("⇧⌘R", event)) {
+ if (vditor.currentMode === "ir") {
+ setTableAlign(tableElement, "right");
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ else {
+ var itemElement = vditor.wysiwyg.popover.querySelector('[data-type="right"]');
+ if (itemElement) {
+ itemElement.click();
+ event.preventDefault();
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+};
+var fixCodeBlock = function (vditor, event, codeRenderElement, range) {
+ // 行级代码块中 command + a,近对当前代码块进行全选
+ if (codeRenderElement.tagName === "PRE" && matchHotKey("⌘A", event)) {
+ range.selectNodeContents(codeRenderElement.firstElementChild);
+ event.preventDefault();
+ return true;
+ }
+ // tab
+ // TODO shift + tab, shift and 选中文字
+ if (vditor.options.tab && event.key === "Tab" && !event.shiftKey && range.toString() === "") {
+ range.insertNode(document.createTextNode(vditor.options.tab));
+ range.collapse(false);
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ // Backspace: 光标位于第零个字符,仅删除代码块标签
+ if (event.key === "Backspace" && !(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey) {
+ var codePosition = (0,selection/* getSelectPosition */.im)(codeRenderElement, vditor[vditor.currentMode].element, range);
+ if ((codePosition.start === 0 ||
+ (codePosition.start === 1 && codeRenderElement.innerText === "\n")) // 空代码块,光标在 \n 后
+ && range.toString() === "") {
+ codeRenderElement.parentElement.outerHTML =
+ "".concat(codeRenderElement.firstElementChild.innerHTML, "
");
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ }
+ // 换行
+ if (!(0,compatibility/* isCtrl */.yl)(event) && !event.altKey && event.key === "Enter") {
+ if (!codeRenderElement.firstElementChild.textContent.endsWith("\n")) {
+ codeRenderElement.firstElementChild.insertAdjacentText("beforeend", "\n");
+ }
+ range.extractContents();
+ range.insertNode(document.createTextNode("\n"));
+ range.collapse(false);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ if (!(0,compatibility/* isFirefox */.vU)()) {
+ if (vditor.currentMode === "wysiwyg") {
+ input_input(vditor, range);
+ }
+ else {
+ input(vditor, range);
+ }
+ }
+ scrollCenter(vditor);
+ event.preventDefault();
+ return true;
+ }
+ return false;
+};
+var fixBlockquote = function (vditor, range, event, pElement) {
+ var startContainer = range.startContainer;
+ var blockquoteElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "BLOCKQUOTE");
+ if (blockquoteElement && range.toString() === "") {
+ if (event.key === "Backspace" && !(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey &&
+ (0,selection/* getSelectPosition */.im)(blockquoteElement, vditor[vditor.currentMode].element, range).start === 0) {
+ // Backspace: 光标位于引用中的第零个字符,仅删除引用标签
+ range.insertNode(document.createElement("wbr"));
+ blockquoteElement.outerHTML = blockquoteElement.innerHTML;
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ if (pElement && event.key === "Enter" && !(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey
+ && pElement.parentElement.tagName === "BLOCKQUOTE") {
+ // Enter: 空行回车应逐层跳出
+ var isEmpty = false;
+ if (pElement.innerHTML.replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "\n" ||
+ pElement.innerHTML.replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "") {
+ // 空 P
+ isEmpty = true;
+ pElement.remove();
+ }
+ else if (pElement.innerHTML.endsWith("\n\n") &&
+ (0,selection/* getSelectPosition */.im)(pElement, vditor[vditor.currentMode].element, range).start ===
+ pElement.textContent.length - 1) {
+ // 软换行
+ pElement.innerHTML = pElement.innerHTML.substr(0, pElement.innerHTML.length - 2);
+ isEmpty = true;
+ }
+ if (isEmpty) {
+ // 需添加零宽字符,否则的话无法记录 undo
+ blockquoteElement.insertAdjacentHTML("afterend", "".concat(constants/* Constants.ZWSP */.g.ZWSP, "\n
"));
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ }
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(startContainer);
+ if (vditor.currentMode === "wysiwyg" && blockElement && matchHotKey("⇧⌘;", event)) {
+ // 插入 blockquote
+ range.insertNode(document.createElement("wbr"));
+ blockElement.outerHTML = "".concat(blockElement.outerHTML, "
");
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ afterRenderEvent(vditor);
+ event.preventDefault();
+ return true;
+ }
+ if (insertAfterBlock(vditor, event, range, blockquoteElement, blockquoteElement)) {
+ return true;
+ }
+ if (insertBeforeBlock(vditor, event, range, blockquoteElement, blockquoteElement)) {
+ return true;
+ }
+ }
+ return false;
+};
+var fixTask = function (vditor, range, event) {
+ var startContainer = range.startContainer;
+ var taskItemElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(startContainer, "LI");
+ if (taskItemElement && taskItemElement.classList.contains("vditor-task")) {
+ if (matchHotKey("⇧⌘J", event)) {
+ // ctrl + shift: toggle checked
+ var inputElement = taskItemElement.firstElementChild;
+ if (inputElement.checked) {
+ inputElement.removeAttribute("checked");
+ }
+ else {
+ inputElement.setAttribute("checked", "checked");
+ }
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ // Backspace: 在选择框前进行删除
+ if (event.key === "Backspace" && !(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey && range.toString() === ""
+ && range.startOffset === 1
+ && ((startContainer.nodeType === 3 && startContainer.previousSibling &&
+ startContainer.previousSibling.tagName === "INPUT")
+ || startContainer.nodeType !== 3)) {
+ var previousElement = taskItemElement.previousElementSibling;
+ taskItemElement.querySelector("input").remove();
+ if (previousElement) {
+ var lastNode = (0,hasClosest/* getLastNode */.DX)(previousElement);
+ lastNode.parentElement.insertAdjacentHTML("beforeend", "" + taskItemElement.innerHTML.trim());
+ taskItemElement.remove();
+ }
+ else {
+ taskItemElement.parentElement.insertAdjacentHTML("beforebegin", "".concat(taskItemElement.innerHTML.trim() || "\n", "
"));
+ if (taskItemElement.nextElementSibling) {
+ taskItemElement.remove();
+ }
+ else {
+ taskItemElement.parentElement.remove();
+ }
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ if (event.key === "Enter" && !(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey) {
+ if (taskItemElement.textContent.trim() === "") {
+ // 当前任务列表无文字
+ if ((0,hasClosest/* hasClosestByClassName */.fb)(taskItemElement.parentElement, "vditor-task")) {
+ // 为子元素时,需进行反向缩进
+ var topListElement = (0,hasClosest/* getTopList */.O9)(startContainer);
+ if (topListElement) {
+ listOutdent(vditor, taskItemElement, range, topListElement);
+ }
+ }
+ else {
+ // 仅有一级任务列表
+ if (taskItemElement.nextElementSibling) {
+ // 任务列表下方还有元素,需要使用用段落隔断
+ var afterHTML_2 = "";
+ var beforeHTML_1 = "";
+ var isAfter_1 = false;
+ Array.from(taskItemElement.parentElement.children).forEach(function (taskItem) {
+ if (taskItemElement.isSameNode(taskItem)) {
+ isAfter_1 = true;
+ }
+ else {
+ if (isAfter_1) {
+ afterHTML_2 += taskItem.outerHTML;
+ }
+ else {
+ beforeHTML_1 += taskItem.outerHTML;
+ }
+ }
+ });
+ var parentTagName = taskItemElement.parentElement.tagName;
+ var dataMarker = taskItemElement.parentElement.tagName === "OL" ? "" : " data-marker=\"".concat(taskItemElement.parentElement.getAttribute("data-marker"), "\"");
+ var startAttribute = "";
+ if (beforeHTML_1) {
+ startAttribute = taskItemElement.parentElement.tagName === "UL" ? "" : " start=\"1\"";
+ beforeHTML_1 = "<".concat(parentTagName, " data-tight=\"true\"").concat(dataMarker, " data-block=\"0\">").concat(beforeHTML_1, "").concat(parentTagName, ">");
+ }
+ // \n
=> \n
+ // https://github.com/Vanessa219/vditor/issues/430
+ taskItemElement.parentElement.outerHTML = "".concat(beforeHTML_1, "\n
<").concat(parentTagName, "\n data-tight=\"true\"").concat(dataMarker, " data-block=\"0\"").concat(startAttribute, ">").concat(afterHTML_2, "").concat(parentTagName, ">");
+ }
+ else {
+ // 任务列表下方无任务列表元素
+ taskItemElement.parentElement.insertAdjacentHTML("afterend", "\n
");
+ if (taskItemElement.parentElement.querySelectorAll("li").length === 1) {
+ // 任务列表仅有一项时,使用 p 元素替换
+ taskItemElement.parentElement.remove();
+ }
+ else {
+ // 任务列表有多项时,当前任务列表位于最后一项,移除该任务列表
+ taskItemElement.remove();
+ }
+ }
+ }
+ }
+ else if (startContainer.nodeType !== 3 && range.startOffset === 0 &&
+ startContainer.firstChild.tagName === "INPUT") {
+ // 光标位于 input 之前
+ range.setStart(startContainer.childNodes[1], 1);
+ }
+ else {
+ // 当前任务列表有文字,光标后的文字需添加到新任务列表中
+ range.setEndAfter(taskItemElement.lastChild);
+ taskItemElement.insertAdjacentHTML("afterend", " "));
+ document.querySelector("wbr").after(range.extractContents());
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ execAfterRender(vditor);
+ scrollCenter(vditor);
+ event.preventDefault();
+ return true;
+ }
+ }
+ return false;
+};
+var fixDelete = function (vditor, range, event, pElement) {
+ if (range.startContainer.nodeType !== 3) {
+ // 光标位于 hr 前,hr 前有内容
+ var rangeElement = range.startContainer.children[range.startOffset];
+ if (rangeElement && rangeElement.tagName === "HR") {
+ range.selectNodeContents(rangeElement.previousElementSibling);
+ range.collapse(false);
+ event.preventDefault();
+ return true;
+ }
+ }
+ if (pElement) {
+ var previousElement = pElement.previousElementSibling;
+ if (previousElement && (0,selection/* getSelectPosition */.im)(pElement, vditor[vditor.currentMode].element, range).start === 0 &&
+ (((0,compatibility/* isFirefox */.vU)() && previousElement.tagName === "HR") || previousElement.tagName === "TABLE")) {
+ if (previousElement.tagName === "TABLE") {
+ // table 后删除 https://github.com/Vanessa219/vditor/issues/243
+ var lastCellElement = previousElement.lastElementChild.lastElementChild.lastElementChild;
+ lastCellElement.innerHTML =
+ lastCellElement.innerHTML.trimLeft() + "" + pElement.textContent.trim();
+ pElement.remove();
+ }
+ else {
+ // 光标位于 hr 后进行删除
+ previousElement.remove();
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ execAfterRender(vditor);
+ event.preventDefault();
+ return true;
+ }
+ }
+ return false;
+};
+var fixHR = function (range) {
+ if ((0,compatibility/* isFirefox */.vU)() && range.startContainer.nodeType !== 3 &&
+ range.startContainer.tagName === "HR") {
+ range.setStartBefore(range.startContainer);
+ }
+};
+// firefox https://github.com/Vanessa219/vditor/issues/407
+var fixFirefoxArrowUpTable = function (event, blockElement, range) {
+ var _a, _b;
+ if (!(0,compatibility/* isFirefox */.vU)()) {
+ return false;
+ }
+ if (event.key === "ArrowUp" && blockElement && ((_a = blockElement.previousElementSibling) === null || _a === void 0 ? void 0 : _a.tagName) === "TABLE") {
+ var tableElement = blockElement.previousElementSibling;
+ range.selectNodeContents(tableElement.rows[tableElement.rows.length - 1].lastElementChild);
+ range.collapse(false);
+ event.preventDefault();
+ return true;
+ }
+ if (event.key === "ArrowDown" && blockElement && ((_b = blockElement.nextElementSibling) === null || _b === void 0 ? void 0 : _b.tagName) === "TABLE") {
+ range.selectNodeContents(blockElement.nextElementSibling.rows[0].cells[0]);
+ range.collapse(true);
+ event.preventDefault();
+ return true;
+ }
+ return false;
+};
+var paste = function (vditor, event, callback) { return fixBrowserBehavior_awaiter(void 0, void 0, void 0, function () {
+ var textHTML, textPlain, files, renderers, renderLinkDest, doc, height, code, codeElement, position, tempElement, fileReader_1, file_1, range, blockElement, range;
+ var _a;
+ return fixBrowserBehavior_generator(this, function (_b) {
+ switch (_b.label) {
+ case 0:
+ if (vditor[vditor.currentMode].element.getAttribute("contenteditable") !== "true") {
+ return [2 /*return*/];
+ }
+ event.stopPropagation();
+ event.preventDefault();
+ if ("clipboardData" in event) {
+ textHTML = event.clipboardData.getData("text/html");
+ textPlain = event.clipboardData.getData("text/plain");
+ files = event.clipboardData.files;
+ }
+ else {
+ textHTML = event.dataTransfer.getData("text/html");
+ textPlain = event.dataTransfer.getData("text/plain");
+ if (event.dataTransfer.types.includes("Files")) {
+ files = event.dataTransfer.items;
+ }
+ }
+ renderers = {};
+ renderLinkDest = function (node, entering) {
+ if (!entering) {
+ return ["", Lute.WalkContinue];
+ }
+ if (vditor.options.upload.renderLinkDest) {
+ return vditor.options.upload.renderLinkDest(vditor, node, entering);
+ }
+ var src = node.TokensStr();
+ if (node.__internal_object__.Parent.Type === 34 && src && src.indexOf("file://") === -1 &&
+ vditor.options.upload.linkToImgUrl) {
+ var xhr_1 = new XMLHttpRequest();
+ xhr_1.open("POST", vditor.options.upload.linkToImgUrl);
+ if (vditor.options.upload.token) {
+ xhr_1.setRequestHeader("X-Upload-Token", vditor.options.upload.token);
+ }
+ if (vditor.options.upload.withCredentials) {
+ xhr_1.withCredentials = true;
+ }
+ setHeaders(vditor, xhr_1);
+ xhr_1.setRequestHeader("Content-Type", "application/json; charset=utf-8");
+ xhr_1.onreadystatechange = function () {
+ if (xhr_1.readyState === XMLHttpRequest.DONE) {
+ if (xhr_1.status === 200) {
+ var responseText = xhr_1.responseText;
+ if (vditor.options.upload.linkToImgFormat) {
+ responseText = vditor.options.upload.linkToImgFormat(xhr_1.responseText);
+ }
+ var responseJSON_1 = JSON.parse(responseText);
+ if (responseJSON_1.code !== 0) {
+ vditor.tip.show(responseJSON_1.msg);
+ return;
+ }
+ var original_1 = responseJSON_1.data.originalURL;
+ if (vditor.currentMode === "sv") {
+ vditor.sv.element.querySelectorAll(".vditor-sv__marker--link")
+ .forEach(function (item) {
+ if (item.textContent === original_1) {
+ item.textContent = responseJSON_1.data.url;
+ }
+ });
+ }
+ else {
+ var imgElement = vditor[vditor.currentMode].element.querySelector("img[src=\"".concat(original_1, "\"]"));
+ imgElement.src = responseJSON_1.data.url;
+ if (vditor.currentMode === "ir") {
+ imgElement.previousElementSibling.previousElementSibling.innerHTML =
+ responseJSON_1.data.url;
+ }
+ }
+ execAfterRender(vditor);
+ }
+ else {
+ vditor.tip.show(xhr_1.responseText);
+ }
+ if (vditor.options.upload.linkToImgCallback) {
+ vditor.options.upload.linkToImgCallback(xhr_1.responseText);
+ }
+ }
+ };
+ xhr_1.send(JSON.stringify({ url: src }));
+ }
+ if (vditor.currentMode === "ir") {
+ return ["".concat(Lute.EscapeHTMLStr(src), ""), Lute.WalkContinue];
+ }
+ else if (vditor.currentMode === "wysiwyg") {
+ return ["", Lute.WalkContinue];
+ }
+ else {
+ return ["".concat(Lute.EscapeHTMLStr(src), ""), Lute.WalkContinue];
+ }
+ };
+ // 浏览器地址栏拷贝处理
+ if (textHTML.replace(/&/g, "&").replace(/<(|\/)(html|body|meta)[^>]*?>/ig, "").trim() ===
+ "").concat(textPlain, "") ||
+ textHTML.replace(/&/g, "&").replace(/<(|\/)(html|body|meta)[^>]*?>/ig, "").trim() ===
+ "").concat(textPlain, "")) {
+ textHTML = "";
+ }
+ doc = new DOMParser().parseFromString(textHTML, "text/html");
+ if (doc.body) {
+ textHTML = doc.body.innerHTML;
+ }
+ textHTML = Lute.Sanitize(textHTML);
+ vditor.wysiwyg.getComments(vditor);
+ height = vditor[vditor.currentMode].element.scrollHeight;
+ code = processPasteCode(textHTML, textPlain, vditor.currentMode);
+ codeElement = vditor.currentMode === "sv" ?
+ (0,hasClosest/* hasClosestByAttribute */.a1)(event.target, "data-type", "code-block") :
+ (0,hasClosest/* hasClosestByMatchTag */.lG)(event.target, "CODE");
+ if (!codeElement) return [3 /*break*/, 1];
+ // 粘贴在代码位置
+ if (vditor.currentMode === "sv") {
+ document.execCommand("insertHTML", false, textPlain.replace(/&/g, "&").replace(/ 0)) return [3 /*break*/, 7];
+ if (!(vditor.options.upload.url || vditor.options.upload.handler)) return [3 /*break*/, 5];
+ return [4 /*yield*/, uploadFiles(vditor, files)];
+ case 4:
+ _b.sent();
+ return [3 /*break*/, 6];
+ case 5:
+ fileReader_1 = new FileReader();
+ if ("clipboardData" in event) {
+ files = event.clipboardData.files;
+ file_1 = files[0];
+ }
+ else if (event.dataTransfer.types.includes("Files")) {
+ files = event.dataTransfer.items;
+ file_1 = files[0].getAsFile();
+ }
+ if (file_1 && file_1.type.startsWith("image")) {
+ fileReader_1.readAsDataURL(file_1);
+ fileReader_1.onload = function () {
+ var imgHTML = '';
+ if (vditor.currentMode === "wysiwyg") {
+ imgHTML += "
\n");
+ }
+ else {
+ imgHTML += ".concat(fileReader_1.result.toString(), ")\n");
+ }
+ document.execCommand("insertHTML", false, imgHTML);
+ };
+ }
+ _b.label = 6;
+ case 6: return [3 /*break*/, 8];
+ case 7:
+ if (textPlain.trim() !== "" && files.length === 0) {
+ range = (0,selection/* getEditorRange */.zh)(vditor);
+ if (range.toString() !== "" && vditor.lute.IsValidLinkDest(textPlain)) {
+ textPlain = "[".concat(range.toString(), "](").concat(textPlain, ")");
+ }
+ if (vditor.currentMode === "ir") {
+ renderers.Md2VditorIRDOM = { renderLinkDest: renderLinkDest };
+ vditor.lute.SetJSRenderers({ renderers: renderers });
+ (0,selection/* insertHTML */.oC)(vditor.lute.Md2VditorIRDOM(textPlain), vditor);
+ }
+ else if (vditor.currentMode === "wysiwyg") {
+ renderers.Md2VditorDOM = { renderLinkDest: renderLinkDest };
+ vditor.lute.SetJSRenderers({ renderers: renderers });
+ (0,selection/* insertHTML */.oC)(vditor.lute.Md2VditorDOM(textPlain), vditor);
+ }
+ else {
+ renderers.Md2VditorSVDOM = { renderLinkDest: renderLinkDest };
+ vditor.lute.SetJSRenderers({ renderers: renderers });
+ processPaste(vditor, textPlain);
+ }
+ vditor.outline.render(vditor);
+ }
+ _b.label = 8;
+ case 8:
+ if (vditor.currentMode !== "sv") {
+ blockElement = (0,hasClosest/* hasClosestBlock */.F9)((0,selection/* getEditorRange */.zh)(vditor).startContainer);
+ if (blockElement) {
+ range = (0,selection/* getEditorRange */.zh)(vditor);
+ vditor[vditor.currentMode].element.querySelectorAll("wbr").forEach(function (wbr) {
+ wbr.remove();
+ });
+ range.insertNode(document.createElement("wbr"));
+ if (vditor.currentMode === "wysiwyg") {
+ blockElement.outerHTML = vditor.lute.SpinVditorDOM(blockElement.outerHTML);
+ }
+ else {
+ blockElement.outerHTML = vditor.lute.SpinVditorIRDOM(blockElement.outerHTML);
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, range);
+ }
+ vditor[vditor.currentMode].element.querySelectorAll(".vditor-".concat(vditor.currentMode, "__preview[data-render='2']"))
+ .forEach(function (item) {
+ processCodeRender(item, vditor);
+ });
+ }
+ vditor.wysiwyg.triggerRemoveComment(vditor);
+ execAfterRender(vditor);
+ if (vditor[vditor.currentMode].element.scrollHeight - height >
+ Math.min(vditor[vditor.currentMode].element.clientHeight, window.innerHeight) / 2) {
+ scrollCenter(vditor);
+ }
+ return [2 /*return*/];
+ }
+ });
+}); };
+var templateObject_1;
+
+;// CONCATENATED MODULE: ./src/ts/ir/process.ts
+
+
+
+
+
+
+
+
+
+var processHint = function (vditor) {
+ var _a, _b;
+ vditor.hint.render(vditor);
+ var startContainer = (0,selection/* getEditorRange */.zh)(vditor).startContainer;
+ // 代码块语言提示
+ var preBeforeElement = (0,hasClosest/* hasClosestByAttribute */.a1)(startContainer, "data-type", "code-block-info");
+ if (preBeforeElement) {
+ if (preBeforeElement.textContent.replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" && vditor.hint.recentLanguage) {
+ preBeforeElement.textContent = constants/* Constants.ZWSP */.g.ZWSP + vditor.hint.recentLanguage;
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ range.selectNodeContents(preBeforeElement);
+ }
+ else {
+ var matchLangData_1 = [];
+ var key_1 = preBeforeElement.textContent.substring(0, (0,selection/* getSelectPosition */.im)(preBeforeElement, vditor.ir.element).start)
+ .replace(constants/* Constants.ZWSP */.g.ZWSP, "");
+ (vditor.options.preview.hljs.langs || constants/* Constants.ALIAS_CODE_LANGUAGES.concat */.g.ALIAS_CODE_LANGUAGES.concat(((_b = (_a = window.hljs) === null || _a === void 0 ? void 0 : _a.listLanguages()) !== null && _b !== void 0 ? _b : []).sort())).forEach(function (keyName) {
+ if (keyName.indexOf(key_1.toLowerCase()) > -1) {
+ matchLangData_1.push({
+ html: keyName,
+ value: keyName,
+ });
+ }
+ });
+ vditor.hint.genHTML(matchLangData_1, key_1, vditor);
+ }
+ }
+};
+var process_processAfterRender = function (vditor, options) {
+ if (options === void 0) { options = {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: true,
+ }; }
+ if (options.enableHint) {
+ processHint(vditor);
+ }
+ clearTimeout(vditor.ir.processTimeoutId);
+ vditor.ir.processTimeoutId = window.setTimeout(function () {
+ if (vditor.ir.composingLock) {
+ return;
+ }
+ var text = getMarkdown(vditor);
+ if (typeof vditor.options.input === "function" && options.enableInput) {
+ vditor.options.input(text);
+ }
+ if (vditor.options.counter.enable) {
+ vditor.counter.render(vditor, text);
+ }
+ if (vditor.options.cache.enable && (0,compatibility/* accessLocalStorage */.pK)()) {
+ localStorage.setItem(vditor.options.cache.id, text);
+ if (vditor.options.cache.after) {
+ vditor.options.cache.after(text);
+ }
+ }
+ if (vditor.devtools) {
+ vditor.devtools.renderEchart(vditor);
+ }
+ if (options.enableAddUndoStack) {
+ vditor.undo.addToUndoStack(vditor);
+ }
+ }, vditor.options.undoDelay);
+};
+var process_processHeading = function (vditor, value) {
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var headingElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer) || range.startContainer;
+ if (headingElement) {
+ var headingMarkerElement = headingElement.querySelector(".vditor-ir__marker--heading");
+ if (headingMarkerElement) {
+ headingMarkerElement.innerHTML = value;
+ }
+ else {
+ headingElement.insertAdjacentText("afterbegin", value);
+ range.selectNodeContents(headingElement);
+ range.collapse(false);
+ }
+ input(vditor, range.cloneRange());
+ highlightToolbarIR(vditor);
+ }
+};
+var removeInline = function (range, vditor, type) {
+ var inlineElement = (0,hasClosest/* hasClosestByAttribute */.a1)(range.startContainer, "data-type", type);
+ if (inlineElement) {
+ inlineElement.firstElementChild.remove();
+ inlineElement.lastElementChild.remove();
+ range.insertNode(document.createElement("wbr"));
+ var tempElement = document.createElement("div");
+ tempElement.innerHTML = vditor.lute.SpinVditorIRDOM(inlineElement.outerHTML);
+ inlineElement.outerHTML = tempElement.firstElementChild.innerHTML.trim();
+ }
+};
+var process_processToolbar = function (vditor, actionBtn, prefix, suffix) {
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var commandName = actionBtn.getAttribute("data-type");
+ var typeElement = range.startContainer;
+ if (typeElement.nodeType === 3) {
+ typeElement = typeElement.parentElement;
+ }
+ var useHighlight = true;
+ // 移除
+ if (actionBtn.classList.contains("vditor-menu--current")) {
+ if (commandName === "quote") {
+ var quoteElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(typeElement, "BLOCKQUOTE");
+ if (quoteElement) {
+ range.insertNode(document.createElement("wbr"));
+ quoteElement.outerHTML = quoteElement.innerHTML.trim() === "" ?
+ "".concat(quoteElement.innerHTML, "
") : quoteElement.innerHTML;
+ }
+ }
+ else if (commandName === "link") {
+ var aElement = (0,hasClosest/* hasClosestByAttribute */.a1)(range.startContainer, "data-type", "a");
+ if (aElement) {
+ var aTextElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-ir__link");
+ if (aTextElement) {
+ range.insertNode(document.createElement("wbr"));
+ aElement.outerHTML = aTextElement.innerHTML;
+ }
+ else {
+ aElement.outerHTML = aElement.querySelector(".vditor-ir__link").innerHTML + "";
+ }
+ }
+ }
+ else if (commandName === "italic") {
+ removeInline(range, vditor, "em");
+ }
+ else if (commandName === "bold") {
+ removeInline(range, vditor, "strong");
+ }
+ else if (commandName === "strike") {
+ removeInline(range, vditor, "s");
+ }
+ else if (commandName === "inline-code") {
+ removeInline(range, vditor, "code");
+ }
+ else if (commandName === "check" || commandName === "list" || commandName === "ordered-list") {
+ listToggle(vditor, range, commandName);
+ useHighlight = false;
+ actionBtn.classList.remove("vditor-menu--current");
+ }
+ }
+ else {
+ // 添加
+ if (vditor.ir.element.childNodes.length === 0) {
+ vditor.ir.element.innerHTML = '
';
+ (0,selection/* setRangeByWbr */.ib)(vditor.ir.element, range);
+ }
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer);
+ if (commandName === "line") {
+ if (blockElement) {
+ var hrHTML = '
\n
';
+ if (blockElement.innerHTML.trim() === "") {
+ blockElement.outerHTML = hrHTML;
+ }
+ else {
+ blockElement.insertAdjacentHTML("afterend", hrHTML);
+ }
+ }
+ }
+ else if (commandName === "quote") {
+ if (blockElement) {
+ range.insertNode(document.createElement("wbr"));
+ blockElement.outerHTML = "".concat(blockElement.outerHTML, "
");
+ useHighlight = false;
+ actionBtn.classList.add("vditor-menu--current");
+ }
+ }
+ else if (commandName === "link") {
+ var html = void 0;
+ if (range.toString() === "") {
+ html = "".concat(prefix, "").concat(suffix);
+ }
+ else {
+ html = "".concat(prefix).concat(range.toString()).concat(suffix.replace(")", ")"));
+ }
+ document.execCommand("insertHTML", false, html);
+ useHighlight = false;
+ actionBtn.classList.add("vditor-menu--current");
+ }
+ else if (commandName === "italic" || commandName === "bold" || commandName === "strike"
+ || commandName === "inline-code" || commandName === "code" || commandName === "table") {
+ var html = void 0;
+ if (range.toString() === "") {
+ html = "".concat(prefix, "").concat(suffix);
+ }
+ else {
+ if (commandName === "code") {
+ html = "".concat(prefix, "\n").concat(range.toString(), "").concat(suffix);
+ }
+ else if (commandName === "table") {
+ html = "".concat(prefix).concat(range.toString(), "").concat(suffix);
+ }
+ else {
+ html = "".concat(prefix).concat(range.toString()).concat(suffix, "");
+ }
+ range.deleteContents();
+ }
+ if (commandName === "table" || commandName === "code") {
+ html = "\n" + html + "\n\n";
+ }
+ var spanElement = document.createElement("span");
+ spanElement.innerHTML = html;
+ range.insertNode(spanElement);
+ input(vditor, range);
+ if (commandName === "table") {
+ range.selectNodeContents(getSelection().getRangeAt(0).startContainer.parentElement);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ }
+ else if (commandName === "check" || commandName === "list" || commandName === "ordered-list") {
+ listToggle(vditor, range, commandName, false);
+ useHighlight = false;
+ removeCurrentToolbar(vditor.toolbar.elements, ["check", "list", "ordered-list"]);
+ actionBtn.classList.add("vditor-menu--current");
+ }
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor.ir.element, range);
+ process_processAfterRender(vditor);
+ if (useHighlight) {
+ highlightToolbarIR(vditor);
+ }
+};
+
+;// CONCATENATED MODULE: ./src/ts/hint/index.ts
+var hint_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
+ return new (P || (P = Promise))(function (resolve, reject) {
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
+ });
+};
+var hint_generator = (undefined && undefined.__generator) || function (thisArg, body) {
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
+ function verb(n) { return function (v) { return step([n, v]); }; }
+ function step(op) {
+ if (f) throw new TypeError("Generator is already executing.");
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
+ if (y = 0, t) op = [op[0] & 2, t.value];
+ switch (op[0]) {
+ case 0: case 1: t = op; break;
+ case 4: _.label++; return { value: op[1], done: false };
+ case 5: _.label++; y = op[1]; op = [0]; continue;
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
+ default:
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
+ if (t[2]) _.ops.pop();
+ _.trys.pop(); continue;
+ }
+ op = body.call(thisArg, _);
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
+ }
+};
+
+
+
+
+
+
+
+
+var Hint = /** @class */ (function () {
+ function Hint(hintExtends) {
+ var _this = this;
+ this.splitChar = "";
+ this.lastIndex = -1;
+ this.fillEmoji = function (element, vditor) {
+ _this.element.style.display = "none";
+ var value = decodeURIComponent(element.getAttribute("data-value"));
+ var range = window.getSelection().getRangeAt(0);
+ // 代码提示
+ if (vditor.currentMode === "ir") {
+ var preBeforeElement = (0,hasClosest/* hasClosestByAttribute */.a1)(range.startContainer, "data-type", "code-block-info");
+ if (preBeforeElement) {
+ preBeforeElement.textContent = constants/* Constants.ZWSP */.g.ZWSP + value.trimRight();
+ range.selectNodeContents(preBeforeElement);
+ range.collapse(false);
+ process_processAfterRender(vditor);
+ preBeforeElement.parentElement.querySelectorAll("code").forEach(function (item) {
+ item.className = "language-" + value.trimRight();
+ });
+ processCodeRender(preBeforeElement.parentElement.querySelector(".vditor-ir__preview"), vditor);
+ _this.recentLanguage = value.trimRight();
+ return;
+ }
+ }
+ if (vditor.currentMode === "wysiwyg" && range.startContainer.nodeType !== 3) {
+ var startContainer = range.startContainer;
+ var inputElement = void 0;
+ if (startContainer.classList.contains("vditor-input")) {
+ inputElement = startContainer;
+ }
+ else {
+ inputElement = startContainer.firstElementChild;
+ }
+ if (inputElement && inputElement.classList.contains("vditor-input")) {
+ inputElement.value = value.trimRight();
+ range.selectNodeContents(inputElement);
+ range.collapse(false);
+ // {detail: 1}用于标识这个自定义事件是在编程语言选择后触发的
+ // 用于在鼠标选择语言后,自动聚焦到代码输入框
+ inputElement.dispatchEvent(new CustomEvent("input", { detail: 1 }));
+ _this.recentLanguage = value.trimRight();
+ return;
+ }
+ }
+ range.setStart(range.startContainer, _this.lastIndex);
+ range.deleteContents();
+ if (vditor.options.hint.parse) {
+ if (vditor.currentMode === "sv") {
+ (0,selection/* insertHTML */.oC)(vditor.lute.SpinVditorSVDOM(value), vditor);
+ }
+ else if (vditor.currentMode === "wysiwyg") {
+ (0,selection/* insertHTML */.oC)(vditor.lute.SpinVditorDOM(value), vditor);
+ }
+ else {
+ (0,selection/* insertHTML */.oC)(vditor.lute.SpinVditorIRDOM(value), vditor);
+ }
+ }
+ else {
+ (0,selection/* insertHTML */.oC)(value, vditor);
+ }
+ if (_this.splitChar === ":" && value.indexOf(":") > -1 && vditor.currentMode !== "sv") {
+ range.insertNode(document.createTextNode(" "));
+ }
+ range.collapse(false);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ if (vditor.currentMode === "wysiwyg") {
+ var preElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-wysiwyg__block");
+ if (preElement && preElement.lastElementChild.classList.contains("vditor-wysiwyg__preview")) {
+ preElement.lastElementChild.innerHTML = preElement.firstElementChild.innerHTML;
+ processCodeRender(preElement.lastElementChild, vditor);
+ }
+ }
+ else if (vditor.currentMode === "ir") {
+ var preElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-ir__marker--pre");
+ if (preElement && preElement.nextElementSibling.classList.contains("vditor-ir__preview")) {
+ preElement.nextElementSibling.innerHTML = preElement.innerHTML;
+ processCodeRender(preElement.nextElementSibling, vditor);
+ }
+ }
+ execAfterRender(vditor);
+ };
+ this.timeId = -1;
+ this.element = document.createElement("div");
+ this.element.className = "vditor-hint";
+ this.recentLanguage = "";
+ hintExtends.push({ key: ":" });
+ }
+ Hint.prototype.render = function (vditor) {
+ var _this = this;
+ if (!window.getSelection().focusNode) {
+ return;
+ }
+ var currentLineValue;
+ var range = getSelection().getRangeAt(0);
+ currentLineValue = range.startContainer.textContent.substring(0, range.startOffset) || "";
+ var key = this.getKey(currentLineValue, vditor.options.hint.extend);
+ if (typeof key === "undefined") {
+ this.element.style.display = "none";
+ clearTimeout(this.timeId);
+ }
+ else {
+ if (this.splitChar === ":") {
+ var emojiHint_1 = key === "" ? vditor.options.hint.emoji : vditor.lute.GetEmojis();
+ var matchEmojiData_1 = [];
+ Object.keys(emojiHint_1).forEach(function (keyName) {
+ if (keyName.indexOf(key.toLowerCase()) === 0) {
+ if (emojiHint_1[keyName].indexOf(".") > -1) {
+ matchEmojiData_1.push({
+ html: "
:").concat(keyName, ":"),
+ value: ":".concat(keyName, ":"),
+ });
+ }
+ else {
+ matchEmojiData_1.push({
+ html: "".concat(emojiHint_1[keyName], "").concat(keyName),
+ value: emojiHint_1[keyName],
+ });
+ }
+ }
+ });
+ this.genHTML(matchEmojiData_1, key, vditor);
+ }
+ else {
+ vditor.options.hint.extend.forEach(function (item) {
+ if (item.key === _this.splitChar) {
+ clearTimeout(_this.timeId);
+ _this.timeId = window.setTimeout(function () { return hint_awaiter(_this, void 0, void 0, function () {
+ var _a;
+ return hint_generator(this, function (_b) {
+ switch (_b.label) {
+ case 0:
+ _a = this.genHTML;
+ return [4 /*yield*/, item.hint(key)];
+ case 1:
+ _a.apply(this, [_b.sent(), key, vditor]);
+ return [2 /*return*/];
+ }
+ });
+ }); }, vditor.options.hint.delay);
+ }
+ });
+ }
+ }
+ };
+ Hint.prototype.genHTML = function (data, key, vditor) {
+ var _this = this;
+ if (data.length === 0) {
+ this.element.style.display = "none";
+ return;
+ }
+ var editorElement = vditor[vditor.currentMode].element;
+ var textareaPosition = (0,selection/* getCursorPosition */.Ny)(editorElement);
+ var x = textareaPosition.left +
+ (vditor.options.outline.position === "left" ? vditor.outline.element.offsetWidth : 0);
+ var y = textareaPosition.top;
+ var hintsHTML = "";
+ data.forEach(function (hintData, i) {
+ if (i > 7) {
+ return;
+ }
+ // process high light
+ var html = hintData.html;
+ if (key !== "") {
+ var lastIndex = html.lastIndexOf(">") + 1;
+ var replaceHtml = html.substr(lastIndex);
+ var replaceIndex = replaceHtml.toLowerCase().indexOf(key.toLowerCase());
+ if (replaceIndex > -1) {
+ replaceHtml = replaceHtml.substring(0, replaceIndex) + "" +
+ replaceHtml.substring(replaceIndex, replaceIndex + key.length) + "" +
+ replaceHtml.substring(replaceIndex + key.length);
+ html = html.substr(0, lastIndex) + replaceHtml;
+ }
+ }
+ hintsHTML += "");
+ });
+ this.element.innerHTML = hintsHTML;
+ var lineHeight = parseInt(document.defaultView.getComputedStyle(editorElement, null)
+ .getPropertyValue("line-height"), 10);
+ this.element.style.top = "".concat(y + (lineHeight || 22), "px");
+ this.element.style.left = "".concat(x, "px");
+ this.element.style.display = "block";
+ this.element.style.right = "auto";
+ this.element.querySelectorAll("button").forEach(function (element) {
+ element.addEventListener("click", function (event) {
+ _this.fillEmoji(element, vditor);
+ event.preventDefault();
+ });
+ });
+ // hint 展现在上部
+ if (this.element.getBoundingClientRect().bottom > window.innerHeight) {
+ this.element.style.top = "".concat(y - this.element.offsetHeight, "px");
+ }
+ if (this.element.getBoundingClientRect().right > window.innerWidth) {
+ this.element.style.left = "auto";
+ this.element.style.right = "0";
+ }
+ };
+ Hint.prototype.select = function (event, vditor) {
+ if (this.element.querySelectorAll("button").length === 0 ||
+ this.element.style.display === "none") {
+ return false;
+ }
+ var currentHintElement = this.element.querySelector(".vditor-hint--current");
+ if (event.key === "ArrowDown") {
+ event.preventDefault();
+ event.stopPropagation();
+ currentHintElement.removeAttribute("class");
+ if (!currentHintElement.nextElementSibling) {
+ this.element.children[0].className = "vditor-hint--current";
+ }
+ else {
+ currentHintElement.nextElementSibling.className = "vditor-hint--current";
+ }
+ return true;
+ }
+ else if (event.key === "ArrowUp") {
+ event.preventDefault();
+ event.stopPropagation();
+ currentHintElement.removeAttribute("class");
+ if (!currentHintElement.previousElementSibling) {
+ var length_1 = this.element.children.length;
+ this.element.children[length_1 - 1].className = "vditor-hint--current";
+ }
+ else {
+ currentHintElement.previousElementSibling.className = "vditor-hint--current";
+ }
+ return true;
+ }
+ else if (!(0,compatibility/* isCtrl */.yl)(event) && !event.shiftKey && !event.altKey && event.key === "Enter" && !event.isComposing) {
+ event.preventDefault();
+ event.stopPropagation();
+ this.fillEmoji(currentHintElement, vditor);
+ return true;
+ }
+ return false;
+ };
+ Hint.prototype.getKey = function (currentLineValue, extend) {
+ var _this = this;
+ this.lastIndex = -1;
+ this.splitChar = "";
+ extend.forEach(function (item) {
+ var currentLastIndex = currentLineValue.lastIndexOf(item.key);
+ if (_this.lastIndex < currentLastIndex) {
+ _this.splitChar = item.key;
+ _this.lastIndex = currentLastIndex;
+ }
+ });
+ var key;
+ if (this.lastIndex === -1) {
+ return key;
+ }
+ var lineArray = currentLineValue.split(this.splitChar);
+ var lastItem = lineArray[lineArray.length - 1];
+ var maxLength = 32;
+ if (lineArray.length > 1 && lastItem.trim() === lastItem) {
+ if (lineArray.length === 2 && lineArray[0] === "" && lineArray[1].length < maxLength) {
+ key = lineArray[1];
+ }
+ else {
+ var preChar = lineArray[lineArray.length - 2].slice(-1);
+ if ((0,code160to32/* code160to32 */.X)(preChar) === " " && lastItem.length < maxLength) {
+ key = lastItem;
+ }
+ }
+ }
+ return key;
+ };
+ return Hint;
+}());
+
+
+;// CONCATENATED MODULE: ./src/ts/ir/index.ts
+
+
+
+
+
+
+
+
+
+
+
+
+var IR = /** @class */ (function () {
+ function IR(vditor) {
+ this.composingLock = false;
+ var divElement = document.createElement("div");
+ divElement.className = "vditor-ir";
+ divElement.innerHTML = "");
+ this.element = divElement.firstElementChild;
+ this.bindEvent(vditor);
+ focusEvent(vditor, this.element);
+ dblclickEvent(vditor, this.element);
+ blurEvent(vditor, this.element);
+ hotkeyEvent(vditor, this.element);
+ selectEvent(vditor, this.element);
+ dropEvent(vditor, this.element);
+ copyEvent(vditor, this.element, this.copy);
+ cutEvent(vditor, this.element, this.copy);
+ }
+ IR.prototype.copy = function (event, vditor) {
+ var range = getSelection().getRangeAt(0);
+ if (range.toString() === "") {
+ return;
+ }
+ event.stopPropagation();
+ event.preventDefault();
+ var tempElement = document.createElement("div");
+ tempElement.appendChild(range.cloneContents());
+ event.clipboardData.setData("text/plain", vditor.lute.VditorIRDOM2Md(tempElement.innerHTML).trim());
+ event.clipboardData.setData("text/html", "");
+ };
+ IR.prototype.bindEvent = function (vditor) {
+ var _this = this;
+ this.element.addEventListener("paste", function (event) {
+ paste(vditor, event, {
+ pasteCode: function (code) {
+ document.execCommand("insertHTML", false, code);
+ },
+ });
+ });
+ this.element.addEventListener("scroll", function () {
+ hidePanel(vditor, ["hint"]);
+ });
+ this.element.addEventListener("compositionstart", function (event) {
+ _this.composingLock = true;
+ });
+ this.element.addEventListener("compositionend", function (event) {
+ if (!(0,compatibility/* isFirefox */.vU)()) {
+ input(vditor, getSelection().getRangeAt(0).cloneRange());
+ }
+ _this.composingLock = false;
+ });
+ this.element.addEventListener("input", function (event) {
+ if (event.inputType === "deleteByDrag" || event.inputType === "insertFromDrop") {
+ // https://github.com/Vanessa219/vditor/issues/801 编辑器内容拖拽问题
+ return;
+ }
+ if (_this.preventInput) {
+ _this.preventInput = false;
+ process_processAfterRender(vditor, {
+ enableAddUndoStack: true,
+ enableHint: true,
+ enableInput: true,
+ });
+ return;
+ }
+ if (_this.composingLock || event.data === "‘" || event.data === "“" || event.data === "《") {
+ return;
+ }
+ input(vditor, getSelection().getRangeAt(0).cloneRange(), false, event);
+ });
+ this.element.addEventListener("click", function (event) {
+ if (event.target.tagName === "INPUT") {
+ if (event.target.checked) {
+ event.target.setAttribute("checked", "checked");
+ }
+ else {
+ event.target.removeAttribute("checked");
+ }
+ _this.preventInput = true;
+ process_processAfterRender(vditor);
+ return;
+ }
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ // 点击后光标落于预览区
+ var previewElement = (0,hasClosest/* hasClosestByClassName */.fb)(event.target, "vditor-ir__preview");
+ if (!previewElement) {
+ previewElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-ir__preview");
+ }
+ if (previewElement) {
+ if (previewElement.previousElementSibling.firstElementChild) {
+ range.selectNodeContents(previewElement.previousElementSibling.firstElementChild);
+ }
+ else {
+ // 行内数学公式
+ range.selectNodeContents(previewElement.previousElementSibling);
+ }
+ range.collapse(true);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ scrollCenter(vditor);
+ }
+ // 点击图片光标选中图片地址
+ if (event.target.tagName === "IMG") {
+ var linkElement = event.target.parentElement.querySelector(".vditor-ir__marker--link");
+ if (linkElement) {
+ range.selectNode(linkElement);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ }
+ // 打开链接
+ var aElement = (0,hasClosest/* hasClosestByAttribute */.a1)(event.target, "data-type", "a");
+ if (aElement && (!aElement.classList.contains("vditor-ir__node--expand"))) {
+ if (vditor.options.link.click) {
+ vditor.options.link.click(aElement.querySelector(":scope > .vditor-ir__marker--link"));
+ }
+ else if (vditor.options.link.isOpen) {
+ window.open(aElement.querySelector(":scope > .vditor-ir__marker--link").textContent);
+ }
+ return;
+ }
+ if (event.target.isEqualNode(_this.element) && _this.element.lastElementChild && range.collapsed) {
+ var lastRect = _this.element.lastElementChild.getBoundingClientRect();
+ if (event.y > lastRect.top + lastRect.height) {
+ if (_this.element.lastElementChild.tagName === "P" &&
+ _this.element.lastElementChild.textContent.trim().replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "") {
+ range.selectNodeContents(_this.element.lastElementChild);
+ range.collapse(false);
+ }
+ else {
+ _this.element.insertAdjacentHTML("beforeend", "".concat(constants/* Constants.ZWSP */.g.ZWSP, "
"));
+ (0,selection/* setRangeByWbr */.ib)(_this.element, range);
+ }
+ }
+ }
+ if (range.toString() === "") {
+ expandMarker(range, vditor);
+ }
+ else {
+ // https://github.com/Vanessa219/vditor/pull/681 当点击选中区域时 eventTarget 与 range 不一致,需延迟等待 range 发生变化
+ setTimeout(function () {
+ expandMarker((0,selection/* getEditorRange */.zh)(vditor), vditor);
+ });
+ }
+ clickToc(event, vditor);
+ highlightToolbarIR(vditor);
+ });
+ this.element.addEventListener("keyup", function (event) {
+ if (event.isComposing || (0,compatibility/* isCtrl */.yl)(event)) {
+ return;
+ }
+ if (event.key === "Enter") {
+ scrollCenter(vditor);
+ }
+ highlightToolbarIR(vditor);
+ if ((event.key === "Backspace" || event.key === "Delete") &&
+ vditor.ir.element.innerHTML !== "" && vditor.ir.element.childNodes.length === 1 &&
+ vditor.ir.element.firstElementChild && vditor.ir.element.firstElementChild.tagName === "P"
+ && vditor.ir.element.firstElementChild.childElementCount === 0
+ && (vditor.ir.element.textContent === "" || vditor.ir.element.textContent === "\n")) {
+ // 为空时显示 placeholder
+ vditor.ir.element.innerHTML = "";
+ return;
+ }
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ if (event.key === "Backspace") {
+ // firefox headings https://github.com/Vanessa219/vditor/issues/211
+ if ((0,compatibility/* isFirefox */.vU)() && range.startContainer.textContent === "\n" && range.startOffset === 1) {
+ range.startContainer.textContent = "";
+ expandMarker(range, vditor);
+ }
+ // 数学公式前是空块,空块前是 table,在空块前删除,数学公式会多一个 br
+ _this.element.querySelectorAll(".language-math").forEach(function (item) {
+ var brElement = item.querySelector("br");
+ if (brElement) {
+ brElement.remove();
+ }
+ });
+ }
+ else if (event.key.indexOf("Arrow") > -1) {
+ if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
+ processHint(vditor);
+ }
+ expandMarker(range, vditor);
+ }
+ else if (event.keyCode === 229 && event.code === "" && event.key === "Unidentified") {
+ // https://github.com/Vanessa219/vditor/issues/508 IR 删除到节点需展开
+ expandMarker(range, vditor);
+ }
+ var previewRenderElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-ir__preview");
+ if (previewRenderElement) {
+ if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
+ if (previewRenderElement.previousElementSibling.firstElementChild) {
+ range.selectNodeContents(previewRenderElement.previousElementSibling.firstElementChild);
+ }
+ else {
+ // 行内数学公式/html entity
+ range.selectNodeContents(previewRenderElement.previousElementSibling);
+ }
+ range.collapse(false);
+ event.preventDefault();
+ return true;
+ }
+ if (previewRenderElement.tagName === "SPAN" &&
+ (event.key === "ArrowDown" || event.key === "ArrowRight")) {
+ if (previewRenderElement.parentElement.getAttribute("data-type") === "html-entity") {
+ // html entity
+ previewRenderElement.parentElement.insertAdjacentText("afterend", constants/* Constants.ZWSP */.g.ZWSP);
+ range.setStart(previewRenderElement.parentElement.nextSibling, 1);
+ }
+ else {
+ range.selectNodeContents(previewRenderElement.parentElement.lastElementChild);
+ }
+ range.collapse(false);
+ event.preventDefault();
+ return true;
+ }
+ }
+ });
+ };
+ return IR;
+}());
+
+
+;// CONCATENATED MODULE: ./src/ts/markdown/getHTML.ts
+
+var getHTML = function (vditor) {
+ if (vditor.currentMode === "sv") {
+ return vditor.lute.Md2HTML(getMarkdown(vditor));
+ }
+ else if (vditor.currentMode === "wysiwyg") {
+ return vditor.lute.VditorDOM2HTML(vditor.wysiwyg.element.innerHTML);
+ }
+ else if (vditor.currentMode === "ir") {
+ return vditor.lute.VditorIRDOM2HTML(vditor.ir.element.innerHTML);
+ }
+};
+
+// EXTERNAL MODULE: ./src/ts/markdown/setLute.ts
+var setLute = __webpack_require__(214);
+// EXTERNAL MODULE: ./src/ts/markdown/outlineRender.ts
+var outlineRender = __webpack_require__(436);
+;// CONCATENATED MODULE: ./src/ts/outline/index.ts
+
+
+
+
+var Outline = /** @class */ (function () {
+ function Outline(outlineLabel) {
+ this.element = document.createElement("div");
+ this.element.className = "vditor-outline";
+ this.element.innerHTML = "".concat(outlineLabel, "
\n");
+ }
+ Outline.prototype.render = function (vditor) {
+ var html = "";
+ if (vditor.preview.element.style.display === "block") {
+ html = (0,outlineRender/* outlineRender */.k)(vditor.preview.previewElement, this.element.lastElementChild, vditor);
+ }
+ else {
+ html = (0,outlineRender/* outlineRender */.k)(vditor[vditor.currentMode].element, this.element.lastElementChild, vditor);
+ }
+ return html;
+ };
+ Outline.prototype.toggle = function (vditor, show, focus) {
+ var _a;
+ if (show === void 0) { show = true; }
+ if (focus === void 0) { focus = true; }
+ var btnElement = (_a = vditor.toolbar.elements.outline) === null || _a === void 0 ? void 0 : _a.firstElementChild;
+ if (show && window.innerWidth >= constants/* Constants.MOBILE_WIDTH */.g.MOBILE_WIDTH) {
+ this.element.style.display = "block";
+ this.render(vditor);
+ btnElement === null || btnElement === void 0 ? void 0 : btnElement.classList.add("vditor-menu--current");
+ }
+ else {
+ this.element.style.display = "none";
+ btnElement === null || btnElement === void 0 ? void 0 : btnElement.classList.remove("vditor-menu--current");
+ }
+ if (focus && getSelection().rangeCount > 0) {
+ var range = getSelection().getRangeAt(0);
+ if (vditor[vditor.currentMode].element.contains(range.startContainer)) {
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ }
+ }
+ setPadding(vditor);
+ };
+ return Outline;
+}());
+
+
+// EXTERNAL MODULE: ./src/ts/markdown/mediaRender.ts
+var mediaRender = __webpack_require__(280);
+;// CONCATENATED MODULE: ./src/ts/preview/index.ts
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+var Preview = /** @class */ (function () {
+ function Preview(vditor) {
+ var _this = this;
+ this.element = document.createElement("div");
+ this.element.className = "vditor-preview";
+ this.previewElement = document.createElement("div");
+ this.previewElement.className = "vditor-reset";
+ if (vditor.options.classes.preview) {
+ this.previewElement.classList.add(vditor.options.classes.preview);
+ }
+ this.previewElement.style.maxWidth = vditor.options.preview.maxWidth + "px";
+ this.previewElement.addEventListener("copy", function (event) {
+ if (event.target.tagName === "TEXTAREA") {
+ // https://github.com/Vanessa219/vditor/issues/901
+ return;
+ }
+ var tempElement = document.createElement("div");
+ tempElement.className = "vditor-reset";
+ tempElement.appendChild(getSelection().getRangeAt(0).cloneContents());
+ _this.copyToX(vditor, tempElement, "default");
+ event.preventDefault();
+ });
+ this.previewElement.addEventListener("click", function (event) {
+ var spanElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(event.target, "SPAN");
+ if (spanElement && (0,hasClosest/* hasClosestByClassName */.fb)(spanElement, "vditor-toc")) {
+ var headingElement = _this.previewElement.querySelector("#" + spanElement.getAttribute("data-target-id"));
+ if (headingElement) {
+ _this.element.scrollTop = headingElement.offsetTop;
+ }
+ return;
+ }
+ if (event.target.tagName === "A") {
+ if (vditor.options.link.click) {
+ vditor.options.link.click(event.target);
+ }
+ else if (vditor.options.link.isOpen) {
+ window.open(event.target.getAttribute("href"));
+ }
+ event.preventDefault();
+ return;
+ }
+ if (event.target.tagName === "IMG") {
+ if (vditor.options.image.preview) {
+ vditor.options.image.preview(event.target);
+ }
+ else if (vditor.options.image.isPreview) {
+ (0,preview_image/* previewImage */.E)(event.target, vditor.options.lang, vditor.options.theme);
+ }
+ }
+ });
+ this.element.appendChild(this.previewElement);
+ var actions = vditor.options.preview.actions;
+ if (actions.length === 0) {
+ return;
+ }
+ var actionElement = document.createElement("div");
+ actionElement.className = "vditor-preview__action";
+ var actionHtml = [];
+ for (var i = 0; i < actions.length; i++) {
+ var action = actions[i];
+ if (typeof action === "object") {
+ actionHtml.push(""));
+ continue;
+ }
+ switch (action) {
+ case "desktop":
+ actionHtml.push("");
+ break;
+ case "tablet":
+ actionHtml.push("");
+ break;
+ case "mobile":
+ actionHtml.push("");
+ break;
+ case "mp-wechat":
+ actionHtml.push("");
+ break;
+ case "zhihu":
+ actionHtml.push("");
+ break;
+ }
+ }
+ actionElement.innerHTML = actionHtml.join("");
+ actionElement.addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ var btn = (0,hasClosestByHeadings/* hasClosestByTag */.S)(event.target, "BUTTON");
+ if (!btn) {
+ return;
+ }
+ var type = btn.getAttribute("data-type");
+ var actionCustom = actions.find(function (w) { return (w === null || w === void 0 ? void 0 : w.key) === type; });
+ if (actionCustom) {
+ actionCustom.click(type);
+ return;
+ }
+ if (type === "mp-wechat" || type === "zhihu") {
+ _this.copyToX(vditor, _this.previewElement.cloneNode(true), type);
+ return;
+ }
+ if (type === "desktop") {
+ _this.previewElement.style.width = "auto";
+ }
+ else if (type === "tablet") {
+ _this.previewElement.style.width = "780px";
+ }
+ else {
+ _this.previewElement.style.width = "360px";
+ }
+ if (_this.previewElement.scrollWidth > _this.previewElement.parentElement.clientWidth) {
+ _this.previewElement.style.width = "auto";
+ }
+ _this.render(vditor);
+ actionElement.querySelectorAll("button").forEach(function (item) {
+ item.classList.remove("vditor-preview__action--current");
+ });
+ btn.classList.add("vditor-preview__action--current");
+ });
+ this.element.insertBefore(actionElement, this.previewElement);
+ }
+ Preview.prototype.render = function (vditor, value) {
+ var _this = this;
+ clearTimeout(this.mdTimeoutId);
+ if (this.element.style.display === "none") {
+ if (this.element.getAttribute("data-type") === "renderPerformance") {
+ vditor.tip.hide();
+ }
+ return;
+ }
+ if (value) {
+ this.previewElement.innerHTML = value;
+ return;
+ }
+ if (getMarkdown(vditor)
+ .replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "") === "") {
+ this.previewElement.innerHTML = "";
+ return;
+ }
+ var renderStartTime = new Date().getTime();
+ var markdownText = getMarkdown(vditor);
+ this.mdTimeoutId = window.setTimeout(function () {
+ if (vditor.options.preview.url) {
+ var xhr_1 = new XMLHttpRequest();
+ xhr_1.open("POST", vditor.options.preview.url);
+ xhr_1.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
+ xhr_1.onreadystatechange = function () {
+ if (xhr_1.readyState === XMLHttpRequest.DONE) {
+ if (xhr_1.status === 200) {
+ var responseJSON = JSON.parse(xhr_1.responseText);
+ if (responseJSON.code !== 0) {
+ vditor.tip.show(responseJSON.msg);
+ return;
+ }
+ if (vditor.options.preview.transform) {
+ responseJSON.data = vditor.options.preview.transform(responseJSON.data);
+ }
+ _this.previewElement.innerHTML = responseJSON.data;
+ _this.afterRender(vditor, renderStartTime);
+ }
+ else {
+ var html = vditor.lute.Md2HTML(markdownText);
+ if (vditor.options.preview.transform) {
+ html = vditor.options.preview.transform(html);
+ }
+ _this.previewElement.innerHTML = html;
+ _this.afterRender(vditor, renderStartTime);
+ }
+ }
+ };
+ xhr_1.send(JSON.stringify({ markdownText: markdownText }));
+ }
+ else {
+ var html = vditor.lute.Md2HTML(markdownText);
+ if (vditor.options.preview.transform) {
+ html = vditor.options.preview.transform(html);
+ }
+ _this.previewElement.innerHTML = html;
+ _this.afterRender(vditor, renderStartTime);
+ }
+ }, vditor.options.preview.delay);
+ };
+ Preview.prototype.afterRender = function (vditor, startTime) {
+ if (vditor.options.preview.parse) {
+ vditor.options.preview.parse(this.element);
+ }
+ var time = (new Date().getTime() - startTime);
+ if ((new Date().getTime() - startTime) > 2600) {
+ // https://github.com/b3log/vditor/issues/67
+ vditor.tip.show(window.VditorI18n.performanceTip.replace("${x}", time.toString()));
+ vditor.preview.element.setAttribute("data-type", "renderPerformance");
+ }
+ else if (vditor.preview.element.getAttribute("data-type") === "renderPerformance") {
+ vditor.tip.hide();
+ vditor.preview.element.removeAttribute("data-type");
+ }
+ var cmtFocusElement = vditor.preview.element.querySelector(".vditor-comment--focus");
+ if (cmtFocusElement) {
+ cmtFocusElement.classList.remove("vditor-comment--focus");
+ }
+ (0,codeRender/* codeRender */.O)(vditor.preview.previewElement, vditor.options.preview.hljs);
+ (0,highlightRender/* highlightRender */.s)(vditor.options.preview.hljs, vditor.preview.previewElement, vditor.options.cdn);
+ (0,mermaidRender/* mermaidRender */.i)(vditor.preview.previewElement, vditor.options.cdn, vditor.options.theme);
+ (0,markmapRender/* markmapRender */.K)(vditor.preview.previewElement, vditor.options.cdn);
+ (0,SMILESRender/* SMILESRender */.J)(vditor.preview.previewElement, vditor.options.cdn, vditor.options.theme);
+ (0,flowchartRender/* flowchartRender */.P)(vditor.preview.previewElement, vditor.options.cdn);
+ (0,graphvizRender/* graphvizRender */.v)(vditor.preview.previewElement, vditor.options.cdn);
+ (0,chartRender/* chartRender */.p)(vditor.preview.previewElement, vditor.options.cdn, vditor.options.theme);
+ (0,mindmapRender/* mindmapRender */.P)(vditor.preview.previewElement, vditor.options.cdn, vditor.options.theme);
+ (0,plantumlRender/* plantumlRender */.B)(vditor.preview.previewElement, vditor.options.cdn);
+ (0,abcRender/* abcRender */.Q)(vditor.preview.previewElement, vditor.options.cdn);
+ if (vditor.options.preview.render.media.enable) {
+ (0,mediaRender/* mediaRender */.Y)(vditor.preview.previewElement);
+ }
+ vditor.options.customRenders.forEach(function (item) {
+ item.render(vditor.preview.previewElement, vditor);
+ });
+ // toc render
+ var editorElement = vditor.preview.element;
+ var tocHTML = vditor.outline.render(vditor);
+ if (tocHTML === "") {
+ tocHTML = "[ToC]";
+ }
+ editorElement.querySelectorAll('[data-type="toc-block"]').forEach(function (item) {
+ item.innerHTML = tocHTML;
+ (0,mathRender/* mathRender */.H)(item, {
+ cdn: vditor.options.cdn,
+ math: vditor.options.preview.math,
+ });
+ });
+ (0,mathRender/* mathRender */.H)(vditor.preview.previewElement, {
+ cdn: vditor.options.cdn,
+ math: vditor.options.preview.math,
+ });
+ };
+ Preview.prototype.copyToX = function (vditor, copyElement, type) {
+ if (type === void 0) { type = "mp-wechat"; }
+ // fix math render
+ if (type !== "zhihu") {
+ copyElement.querySelectorAll(".katex-html .base").forEach(function (item) {
+ item.style.display = "initial";
+ });
+ }
+ else {
+ copyElement.querySelectorAll(".language-math").forEach(function (item) {
+ item.outerHTML = "
");
+ });
+ }
+ // 防止背景色被粘贴到公众号中
+ copyElement.style.backgroundColor = "#fff";
+ // 代码背景
+ copyElement.querySelectorAll("code").forEach(function (item) {
+ item.style.backgroundImage = "none";
+ });
+ this.element.append(copyElement);
+ var range = copyElement.ownerDocument.createRange();
+ range.selectNode(copyElement);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ document.execCommand("copy");
+ copyElement.remove();
+ vditor.tip.show(['zhihu', 'mp-wechat'].includes(type) ? "\u5DF2\u590D\u5236\uFF0C\u53EF\u5230".concat(type === "zhihu" ? "知乎" : "微信公众号平台", "\u8FDB\u884C\u7C98\u8D34") : "\u5DF2\u590D\u5236\u5230\u526A\u5207\u677F");
+ };
+ return Preview;
+}());
+
+
+;// CONCATENATED MODULE: ./src/ts/resize/index.ts
+var Resize = /** @class */ (function () {
+ function Resize(vditor) {
+ this.element = document.createElement("div");
+ this.element.className = "vditor-resize vditor-resize--".concat(vditor.options.resize.position);
+ this.element.innerHTML = "";
+ this.bindEvent(vditor);
+ }
+ Resize.prototype.bindEvent = function (vditor) {
+ var _this = this;
+ this.element.addEventListener("mousedown", function (event) {
+ var documentSelf = document;
+ var y = event.clientY;
+ var height = vditor.element.offsetHeight;
+ var minHeight = 63 + vditor.element.querySelector(".vditor-toolbar").clientHeight;
+ documentSelf.ondragstart = function () { return false; };
+ if (window.captureEvents) {
+ window.captureEvents();
+ }
+ _this.element.classList.add("vditor-resize--selected");
+ documentSelf.onmousemove = function (moveEvent) {
+ if (vditor.options.resize.position === "top") {
+ vditor.element.style.height = Math.max(minHeight, height + (y - moveEvent.clientY)) + "px";
+ }
+ else {
+ vditor.element.style.height = Math.max(minHeight, height + (moveEvent.clientY - y)) + "px";
+ }
+ if (vditor.options.typewriterMode) {
+ vditor.sv.element.style.paddingBottom =
+ vditor.sv.element.parentElement.offsetHeight / 2 + "px";
+ }
+ };
+ documentSelf.onmouseup = function () {
+ if (vditor.options.resize.after) {
+ vditor.options.resize.after(vditor.element.offsetHeight - height);
+ }
+ if (window.captureEvents) {
+ window.captureEvents();
+ }
+ documentSelf.onmousemove = null;
+ documentSelf.onmouseup = null;
+ documentSelf.ondragstart = null;
+ documentSelf.onselectstart = null;
+ documentSelf.onselect = null;
+ _this.element.classList.remove("vditor-resize--selected");
+ };
+ });
+ };
+ return Resize;
+}());
+
+
+;// CONCATENATED MODULE: ./src/ts/sv/index.ts
+
+
+
+
+
+
+var Editor = /** @class */ (function () {
+ function Editor(vditor) {
+ this.composingLock = false;
+ this.element = document.createElement("pre");
+ this.element.className = "vditor-sv vditor-reset";
+ this.element.setAttribute("placeholder", vditor.options.placeholder);
+ this.element.setAttribute("contenteditable", "true");
+ this.element.setAttribute("spellcheck", "false");
+ this.bindEvent(vditor);
+ focusEvent(vditor, this.element);
+ blurEvent(vditor, this.element);
+ hotkeyEvent(vditor, this.element);
+ selectEvent(vditor, this.element);
+ dropEvent(vditor, this.element);
+ copyEvent(vditor, this.element, this.copy);
+ cutEvent(vditor, this.element, this.copy);
+ }
+ Editor.prototype.copy = function (event, vditor) {
+ event.stopPropagation();
+ event.preventDefault();
+ event.clipboardData.setData("text/plain", getSelectText(vditor[vditor.currentMode].element));
+ };
+ Editor.prototype.bindEvent = function (vditor) {
+ var _this = this;
+ this.element.addEventListener("paste", function (event) {
+ paste(vditor, event, {
+ pasteCode: function (code) {
+ document.execCommand("insertHTML", false, code);
+ },
+ });
+ });
+ this.element.addEventListener("scroll", function () {
+ if (vditor.preview.element.style.display !== "block") {
+ return;
+ }
+ var textScrollTop = _this.element.scrollTop;
+ var textHeight = _this.element.clientHeight;
+ var textScrollHeight = _this.element.scrollHeight - parseFloat(_this.element.style.paddingBottom || "0");
+ var preview = vditor.preview.element;
+ if ((textScrollTop / textHeight > 0.5)) {
+ preview.scrollTop = (textScrollTop + textHeight) *
+ preview.scrollHeight / textScrollHeight - textHeight;
+ }
+ else {
+ preview.scrollTop = textScrollTop *
+ preview.scrollHeight / textScrollHeight;
+ }
+ });
+ this.element.addEventListener("compositionstart", function (event) {
+ _this.composingLock = true;
+ });
+ this.element.addEventListener("compositionend", function (event) {
+ if (!(0,compatibility/* isFirefox */.vU)()) {
+ inputEvent(vditor, event);
+ }
+ _this.composingLock = false;
+ });
+ this.element.addEventListener("input", function (event) {
+ if (event.inputType === "deleteByDrag" || event.inputType === "insertFromDrop") {
+ // https://github.com/Vanessa219/vditor/issues/801 编辑器内容拖拽问题
+ return;
+ }
+ if (_this.composingLock || event.data === "‘" || event.data === "“" || event.data === "《") {
+ return;
+ }
+ if (_this.preventInput) {
+ _this.preventInput = false;
+ processAfterRender(vditor, {
+ enableAddUndoStack: true,
+ enableHint: true,
+ enableInput: true,
+ });
+ return;
+ }
+ inputEvent(vditor, event);
+ });
+ this.element.addEventListener("keyup", function (event) {
+ if (event.isComposing || (0,compatibility/* isCtrl */.yl)(event)) {
+ return;
+ }
+ if ((event.key === "Backspace" || event.key === "Delete") &&
+ vditor.sv.element.innerHTML !== "" && vditor.sv.element.childNodes.length === 1 &&
+ vditor.sv.element.firstElementChild && vditor.sv.element.firstElementChild.tagName === "DIV"
+ && vditor.sv.element.firstElementChild.childElementCount === 2
+ && (vditor.sv.element.firstElementChild.textContent === "" || vditor.sv.element.textContent === "\n")) {
+ // 为空时显示 placeholder
+ vditor.sv.element.innerHTML = "";
+ return;
+ }
+ if (event.key === "Enter") {
+ scrollCenter(vditor);
+ }
+ });
+ };
+ return Editor;
+}());
+
+
+;// CONCATENATED MODULE: ./src/ts/tip/index.ts
+var Tip = /** @class */ (function () {
+ function Tip() {
+ this.element = document.createElement("div");
+ this.element.className = "vditor-tip";
+ }
+ Tip.prototype.show = function (text, time) {
+ var _this = this;
+ if (time === void 0) { time = 6000; }
+ this.element.className = "vditor-tip vditor-tip--show";
+ if (time === 0) {
+ this.element.innerHTML = "");
+ this.element.querySelector(".vditor-tip__close").addEventListener("click", function () {
+ _this.hide();
+ });
+ }
+ else {
+ this.element.innerHTML = "".concat(text, "
");
+ setTimeout(function () {
+ _this.hide();
+ }, time);
+ }
+ // 需在动画结束后才能确定位置
+ this.element.removeAttribute("style");
+ setTimeout(function () {
+ var rect = _this.element.getBoundingClientRect();
+ if (rect.top < 46) {
+ _this.element.style.position = "fixed";
+ _this.element.style.top = "46px";
+ }
+ }, 150);
+ };
+ Tip.prototype.hide = function () {
+ this.element.className = "vditor-messageElementtip";
+ this.element.innerHTML = "";
+ };
+ return Tip;
+}());
+
+
+;// CONCATENATED MODULE: ./src/ts/ui/setPreviewMode.ts
+
+
+var setPreviewMode = function (mode, vditor) {
+ if (vditor.options.preview.mode === mode) {
+ return;
+ }
+ vditor.options.preview.mode = mode;
+ switch (mode) {
+ case "both":
+ vditor.sv.element.style.display = "block";
+ vditor.preview.element.style.display = "block";
+ vditor.preview.render(vditor);
+ setCurrentToolbar(vditor.toolbar.elements, ["both"]);
+ break;
+ case "editor":
+ vditor.sv.element.style.display = "block";
+ vditor.preview.element.style.display = "none";
+ removeCurrentToolbar(vditor.toolbar.elements, ["both"]);
+ break;
+ default:
+ break;
+ }
+ if (vditor.devtools) {
+ vditor.devtools.renderEchart(vditor);
+ }
+};
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Both.ts
+var Both_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+var Both = /** @class */ (function (_super) {
+ Both_extends(Both, _super);
+ function Both(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ if (vditor.options.preview.mode === "both") {
+ _this.element.children[0].classList.add("vditor-menu--current");
+ }
+ _this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ var btnElement = _this.element.firstElementChild;
+ if (btnElement.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ return;
+ }
+ event.preventDefault();
+ if (vditor.currentMode !== "sv") {
+ return;
+ }
+ if (vditor.options.preview.mode === "both") {
+ setPreviewMode("editor", vditor);
+ }
+ else {
+ setPreviewMode("both", vditor);
+ }
+ });
+ return _this;
+ }
+ return Both;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Br.ts
+var Br = /** @class */ (function () {
+ function Br() {
+ this.element = document.createElement("div");
+ this.element.className = "vditor-toolbar__br";
+ }
+ return Br;
+}());
+
+
+// EXTERNAL MODULE: ./src/ts/ui/setCodeTheme.ts
+var setCodeTheme = __webpack_require__(580);
+;// CONCATENATED MODULE: ./src/ts/toolbar/CodeTheme.ts
+var CodeTheme_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+
+var CodeTheme = /** @class */ (function (_super) {
+ CodeTheme_extends(CodeTheme, _super);
+ function CodeTheme(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ var actionBtn = _this.element.children[0];
+ var panelElement = document.createElement("div");
+ panelElement.className = "vditor-hint".concat(menuItem.level === 2 ? "" : " vditor-panel--arrow");
+ var innerHTML = "";
+ constants/* Constants.CODE_THEME.forEach */.g.CODE_THEME.forEach(function (theme) {
+ innerHTML += "");
+ });
+ panelElement.innerHTML =
+ "").concat(innerHTML, "
");
+ panelElement.addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ if (event.target.tagName === "BUTTON") {
+ hidePanel(vditor, ["subToolbar"]);
+ vditor.options.preview.hljs.style = event.target.textContent;
+ (0,setCodeTheme/* setCodeTheme */.Y)(event.target.textContent, vditor.options.cdn);
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ });
+ _this.element.appendChild(panelElement);
+ toggleSubMenu(vditor, panelElement, actionBtn, menuItem.level);
+ return _this;
+ }
+ return CodeTheme;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/ContentTheme.ts
+var ContentTheme_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+var ContentTheme = /** @class */ (function (_super) {
+ ContentTheme_extends(ContentTheme, _super);
+ function ContentTheme(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ var actionBtn = _this.element.children[0];
+ var panelElement = document.createElement("div");
+ panelElement.className = "vditor-hint".concat(menuItem.level === 2 ? "" : " vditor-panel--arrow");
+ var innerHTML = "";
+ Object.keys(vditor.options.preview.theme.list).forEach(function (key) {
+ innerHTML += "");
+ });
+ panelElement.innerHTML =
+ "").concat(innerHTML, "
");
+ panelElement.addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ if (event.target.tagName === "BUTTON") {
+ hidePanel(vditor, ["subToolbar"]);
+ vditor.options.preview.theme.current = event.target.getAttribute("data-type");
+ (0,setContentTheme/* setContentTheme */.Z)(vditor.options.preview.theme.current, vditor.options.preview.theme.path);
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ });
+ _this.element.appendChild(panelElement);
+ toggleSubMenu(vditor, panelElement, actionBtn, menuItem.level);
+ return _this;
+ }
+ return ContentTheme;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Counter.ts
+var Counter = /** @class */ (function () {
+ function Counter(vditor) {
+ this.element = document.createElement("span");
+ this.element.className = "vditor-counter vditor-tooltipped vditor-tooltipped__nw";
+ this.render(vditor, "");
+ }
+ Counter.prototype.render = function (vditor, mdText) {
+ var length = mdText.endsWith("\n") ? mdText.length - 1 : mdText.length;
+ if (vditor.options.counter.type === "text" && vditor[vditor.currentMode]) {
+ var tempElement = vditor[vditor.currentMode].element.cloneNode(true);
+ tempElement.querySelectorAll(".vditor-wysiwyg__preview").forEach(function (item) {
+ item.remove();
+ });
+ length = tempElement.textContent.length;
+ }
+ if (typeof vditor.options.counter.max === "number") {
+ if (length > vditor.options.counter.max) {
+ this.element.className = "vditor-counter vditor-counter--error";
+ }
+ else {
+ this.element.className = "vditor-counter";
+ }
+ this.element.innerHTML = "".concat(length, "/").concat(vditor.options.counter.max);
+ }
+ else {
+ this.element.innerHTML = "".concat(length);
+ }
+ this.element.setAttribute("aria-label", vditor.options.counter.type);
+ if (vditor.options.counter.after) {
+ vditor.options.counter.after(length, {
+ enable: vditor.options.counter.enable,
+ max: vditor.options.counter.max,
+ type: vditor.options.counter.type,
+ });
+ }
+ };
+ return Counter;
+}());
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Custom.ts
+var Custom_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+var Custom = /** @class */ (function (_super) {
+ Custom_extends(Custom, _super);
+ function Custom(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ _this.element.children[0].innerHTML = menuItem.icon;
+ _this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ if (event.currentTarget.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ return;
+ }
+ menuItem.click(event, vditor);
+ });
+ return _this;
+ }
+ return Custom;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Devtools.ts
+var Devtools_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+var Devtools = /** @class */ (function (_super) {
+ Devtools_extends(Devtools, _super);
+ function Devtools(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ _this.element.firstElementChild.addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ var btnElement = _this.element.firstElementChild;
+ if (btnElement.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ return;
+ }
+ event.preventDefault();
+ if (btnElement.classList.contains("vditor-menu--current")) {
+ btnElement.classList.remove("vditor-menu--current");
+ vditor.devtools.element.style.display = "none";
+ setPadding(vditor);
+ }
+ else {
+ btnElement.classList.add("vditor-menu--current");
+ vditor.devtools.element.style.display = "block";
+ setPadding(vditor);
+ vditor.devtools.renderEchart(vditor);
+ }
+ });
+ return _this;
+ }
+ return Devtools;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Divider.ts
+var Divider = /** @class */ (function () {
+ function Divider() {
+ this.element = document.createElement("div");
+ this.element.className = "vditor-toolbar__divider";
+ }
+ return Divider;
+}());
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Emoji.ts
+var Emoji_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+
+
+
+
+var Emoji = /** @class */ (function (_super) {
+ Emoji_extends(Emoji, _super);
+ function Emoji(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ var panelElement = document.createElement("div");
+ panelElement.className = "vditor-panel vditor-panel--arrow";
+ var commonEmojiHTML = "";
+ Object.keys(vditor.options.hint.emoji).forEach(function (key) {
+ var emojiValue = vditor.options.hint.emoji[key];
+ if (emojiValue.indexOf(".") > -1) {
+ commonEmojiHTML += "");
+ }
+ else {
+ commonEmojiHTML += "");
+ }
+ });
+ panelElement.innerHTML = "").concat(commonEmojiHTML, "
\n ").concat(vditor.options.hint.emojiTail || "", "\n
");
+ _this.element.appendChild(panelElement);
+ toggleSubMenu(vditor, panelElement, _this.element.firstElementChild, menuItem.level);
+ _this.bindEvent(vditor);
+ return _this;
+ }
+ Emoji.prototype.bindEvent = function (vditor) {
+ var _this = this;
+ this.element.lastElementChild.addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ var btnElement = (0,hasClosestByHeadings/* hasClosestByTag */.S)(event.target, "BUTTON");
+ if (btnElement) {
+ event.preventDefault();
+ var value = btnElement.getAttribute("data-value");
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var html = value;
+ if (vditor.currentMode === "wysiwyg") {
+ html = vditor.lute.SpinVditorDOM(value);
+ }
+ else if (vditor.currentMode === "ir") {
+ html = vditor.lute.SpinVditorIRDOM(value);
+ }
+ if (value.indexOf(":") > -1 && vditor.currentMode !== "sv") {
+ var tempElement = document.createElement("div");
+ tempElement.innerHTML = html;
+ html = tempElement.firstElementChild.firstElementChild.outerHTML + " ";
+ (0,selection/* insertHTML */.oC)(html, vditor);
+ }
+ else {
+ range.extractContents();
+ range.insertNode(document.createTextNode(value));
+ if (!(0,hasClosest/* hasClosestBlock */.F9)(range.startContainer)) {
+ modifyPre(vditor, range);
+ }
+ }
+ range.collapse(false);
+ (0,selection/* setSelectionFocus */.Hc)(range);
+ _this.element.lastElementChild.style.display = "none";
+ execAfterRender(vditor);
+ }
+ });
+ this.element.lastElementChild.addEventListener("mouseover", function (event) {
+ var btnElement = (0,hasClosestByHeadings/* hasClosestByTag */.S)(event.target, "BUTTON");
+ if (btnElement) {
+ _this.element.querySelector(".vditor-emojis__tip").innerHTML = btnElement.getAttribute("data-key");
+ }
+ });
+ };
+ return Emoji;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/export/index.ts
+
+
+var download = function (vditor, content, filename) {
+ var aElement = document.createElement("a");
+ if ("download" in aElement) {
+ aElement.download = filename;
+ aElement.style.display = "none";
+ aElement.href = URL.createObjectURL(new Blob([content]));
+ document.body.appendChild(aElement);
+ aElement.click();
+ aElement.remove();
+ }
+ else {
+ vditor.tip.show(window.VditorI18n.downloadTip, 0);
+ }
+};
+var exportMarkdown = function (vditor) {
+ var content = getMarkdown(vditor);
+ download(vditor, content, content.substr(0, 10) + ".md");
+};
+var exportPDF = function (vditor) {
+ vditor.tip.show(window.VditorI18n.generate, 3800);
+ var iframe = document.querySelector("#vditorExportIframe");
+ iframe.contentDocument.open();
+ iframe.contentDocument.write("\n\n\n"));
+ iframe.contentDocument.close();
+ setTimeout(function () {
+ iframe.contentWindow.postMessage(getMarkdown(vditor), "*");
+ }, 200);
+};
+var exportHTML = function (vditor) {
+ var content = getHTML(vditor);
+ var html = "\n\n\n").concat(content, "
\n\n");
+ download(vditor, html, content.substr(0, 10) + ".html");
+};
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Export.ts
+var Export_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+var Export = /** @class */ (function (_super) {
+ Export_extends(Export, _super);
+ function Export(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ var actionBtn = _this.element.children[0];
+ var panelElement = document.createElement("div");
+ panelElement.className = "vditor-hint".concat(menuItem.level === 2 ? "" : " vditor-panel--arrow");
+ panelElement.innerHTML = "\n\n";
+ panelElement.addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ var btnElement = event.target;
+ if (btnElement.tagName === "BUTTON") {
+ switch (btnElement.getAttribute("data-type")) {
+ case "markdown":
+ exportMarkdown(vditor);
+ break;
+ case "pdf":
+ exportPDF(vditor);
+ break;
+ case "html":
+ exportHTML(vditor);
+ break;
+ default:
+ break;
+ }
+ hidePanel(vditor, ["subToolbar"]);
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ });
+ _this.element.appendChild(panelElement);
+ toggleSubMenu(vditor, panelElement, actionBtn, menuItem.level);
+ return _this;
+ }
+ return Export;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Fullscreen.ts
+var Fullscreen_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+var Fullscreen = /** @class */ (function (_super) {
+ Fullscreen_extends(Fullscreen, _super);
+ function Fullscreen(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ _this._bindEvent(vditor, menuItem);
+ return _this;
+ }
+ Fullscreen.prototype._bindEvent = function (vditor, menuItem) {
+ this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ if (vditor.element.className.includes("vditor--fullscreen")) {
+ if (!menuItem.level) {
+ this.innerHTML = menuItem.icon;
+ }
+ vditor.element.style.zIndex = "";
+ document.body.style.overflow = "";
+ vditor.element.classList.remove("vditor--fullscreen");
+ Object.keys(vditor.toolbar.elements).forEach(function (key) {
+ var svgElement = vditor.toolbar.elements[key].firstChild;
+ if (svgElement) {
+ svgElement.className = svgElement.className.replace("__s", "__n");
+ vditor.options.toolbar.forEach(function (item) {
+ if (typeof item !== "string" && item.tipPosition && item.name === svgElement.dataset.type) {
+ svgElement.className = "vditor-tooltipped vditor-tooltipped__".concat(item.tipPosition);
+ }
+ });
+ }
+ });
+ if (vditor.counter) {
+ vditor.counter.element.className = vditor.counter.element.className.replace("__s", "__n");
+ }
+ }
+ else {
+ if (!menuItem.level) {
+ this.innerHTML = '';
+ }
+ vditor.element.style.zIndex = vditor.options.fullscreen.index.toString();
+ document.body.style.overflow = "hidden";
+ vditor.element.classList.add("vditor--fullscreen");
+ Object.keys(vditor.toolbar.elements).forEach(function (key) {
+ var svgElement = vditor.toolbar.elements[key].firstChild;
+ if (svgElement) {
+ svgElement.className = svgElement.className.replace("__n", "__s");
+ }
+ });
+ if (vditor.counter) {
+ vditor.counter.element.className = vditor.counter.element.className.replace("__n", "__s");
+ }
+ }
+ if (vditor.devtools) {
+ vditor.devtools.renderEchart(vditor);
+ }
+ if (menuItem.click) {
+ menuItem.click(event, vditor);
+ }
+ setPadding(vditor);
+ setTypewriterPosition(vditor);
+ });
+ };
+ return Fullscreen;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Headings.ts
+var Headings_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+
+
+
+
+var Headings = /** @class */ (function (_super) {
+ Headings_extends(Headings, _super);
+ function Headings(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ var panelElement = document.createElement("div");
+ panelElement.className = "vditor-hint vditor-panel--arrow";
+ panelElement.innerHTML = "\n\n\n\n\n");
+ _this.element.appendChild(panelElement);
+ _this._bindEvent(vditor, panelElement);
+ return _this;
+ }
+ Headings.prototype._bindEvent = function (vditor, panelElement) {
+ var actionBtn = this.element.children[0];
+ actionBtn.addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ // https://github.com/Vanessa219/vditor/issues/1391
+ clearTimeout(vditor.wysiwyg.afterRenderTimeoutId);
+ clearTimeout(vditor.ir.processTimeoutId);
+ clearTimeout(vditor.sv.processTimeoutId);
+ if (actionBtn.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ return;
+ }
+ actionBtn.blur();
+ if (actionBtn.classList.contains("vditor-menu--current")) {
+ if (vditor.currentMode === "wysiwyg") {
+ removeHeading(vditor);
+ afterRenderEvent(vditor);
+ }
+ else if (vditor.currentMode === "ir") {
+ process_processHeading(vditor, "");
+ }
+ actionBtn.classList.remove("vditor-menu--current");
+ }
+ else {
+ hidePanel(vditor, ["subToolbar"]);
+ panelElement.style.display = "block";
+ }
+ });
+ for (var i = 0; i < 6; i++) {
+ panelElement.children.item(i).addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ if (vditor.currentMode === "wysiwyg") {
+ setHeading(vditor, event.target.getAttribute("data-tag"));
+ afterRenderEvent(vditor);
+ actionBtn.classList.add("vditor-menu--current");
+ }
+ else if (vditor.currentMode === "ir") {
+ process_processHeading(vditor, event.target.getAttribute("data-value"));
+ actionBtn.classList.add("vditor-menu--current");
+ }
+ else {
+ processHeading(vditor, event.target.getAttribute("data-value"));
+ }
+ panelElement.style.display = "none";
+ });
+ }
+ };
+ return Headings;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Help.ts
+var Help_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+var Help = /** @class */ (function (_super) {
+ Help_extends(Help, _super);
+ function Help(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ _this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ vditor.tip.show("\n
\n
Markdown \u4F7F\u7528\u6307\u5357
\n
\n
\n
\n
Vditor \u652F\u6301
\n
\n
", 0);
+ });
+ return _this;
+ }
+ return Help;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Indent.ts
+var Indent_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+
+
+var Indent = /** @class */ (function (_super) {
+ Indent_extends(Indent, _super);
+ function Indent(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ _this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ if (_this.element.firstElementChild.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED) ||
+ vditor.currentMode === "sv") {
+ return;
+ }
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var liElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "LI");
+ if (liElement) {
+ listIndent(vditor, liElement, range);
+ }
+ });
+ return _this;
+ }
+ return Indent;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Info.ts
+var Info_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+var Info = /** @class */ (function (_super) {
+ Info_extends(Info, _super);
+ function Info(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ _this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ vditor.tip.show("\n
\n \u4E0B\u4E00\u4EE3\u7684 Markdown \u7F16\u8F91\u5668\uFF0C\u4E3A\u672A\u6765\u800C\u6784\u5EFA\n
\n
\n

\n
\n
\n Vditor \u662F\u4E00\u6B3E\u6D4F\u89C8\u5668\u7AEF\u7684 Markdown \u7F16\u8F91\u5668\uFF0C\u652F\u6301\u6240\u89C1\u5373\u6240\u5F97\u3001\u5373\u65F6\u6E32\u67D3\uFF08\u7C7B\u4F3C Typora\uFF09\u548C\u5206\u5C4F\u9884\u89C8\u6A21\u5F0F\u3002\n \u5B83\u4F7F\u7528 TypeScript \u5B9E\u73B0\uFF0C\u652F\u6301\u539F\u751F JavaScript \u4EE5\u53CA Vue\u3001React\u3001Angular \u548C Svelte \u7B49\u6846\u67B6\u3002\n
\n
\n
\n
\n - \n \u9879\u76EE\u5730\u5740\uFF1Ab3log.org/vditor\n
\n - \n \u5F00\u6E90\u534F\u8BAE\uFF1AMIT\n
\n
\n
\n - \n \u7EC4\u4EF6\u7248\u672C\uFF1AVditor v".concat(constants/* VDITOR_VERSION */.H, " / Lute v").concat(Lute.Version, "\n
\n - \n \u8D5E\u52A9\u6350\u8D60\uFF1Ahttps://ld246.com/sponsor\n
\n
\n
\n
"), 0);
+ });
+ return _this;
+ }
+ return Info;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/InsertAfter.ts
+var InsertAfter_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+var InsertAfter = /** @class */ (function (_super) {
+ InsertAfter_extends(InsertAfter, _super);
+ function InsertAfter(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ _this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ if (_this.element.firstElementChild.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED) ||
+ vditor.currentMode === "sv") {
+ return;
+ }
+ insertEmptyBlock(vditor, "afterend");
+ });
+ return _this;
+ }
+ return InsertAfter;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/InsertBefore.ts
+var InsertBefore_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+var InsertBefore = /** @class */ (function (_super) {
+ InsertBefore_extends(InsertBefore, _super);
+ function InsertBefore(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ _this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ if (_this.element.firstElementChild.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED) ||
+ vditor.currentMode === "sv") {
+ return;
+ }
+ insertEmptyBlock(vditor, "beforebegin");
+ });
+ return _this;
+ }
+ return InsertBefore;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Outdent.ts
+var Outdent_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+
+
+var Outdent = /** @class */ (function (_super) {
+ Outdent_extends(Outdent, _super);
+ function Outdent(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ _this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ if (_this.element.firstElementChild.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED) ||
+ vditor.currentMode === "sv") {
+ return;
+ }
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var liElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "LI");
+ if (liElement) {
+ listOutdent(vditor, liElement, range, liElement.parentElement);
+ }
+ });
+ return _this;
+ }
+ return Outdent;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Outline.ts
+var Outline_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+var Outline_Outline = /** @class */ (function (_super) {
+ Outline_extends(Outline, _super);
+ function Outline(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ if (vditor.options.outline) {
+ _this.element.firstElementChild.classList.add("vditor-menu--current");
+ }
+ _this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ var btnElement = vditor.toolbar.elements.outline.firstElementChild;
+ if (btnElement.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ return;
+ }
+ vditor.options.outline.enable = !_this.element.firstElementChild.classList.contains("vditor-menu--current");
+ vditor.outline.toggle(vditor, vditor.options.outline.enable);
+ });
+ return _this;
+ }
+ return Outline;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Preview.ts
+var Preview_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+
+var Preview_Preview = /** @class */ (function (_super) {
+ Preview_extends(Preview, _super);
+ function Preview(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ _this._bindEvent(vditor);
+ return _this;
+ }
+ Preview.prototype._bindEvent = function (vditor) {
+ var _this = this;
+ this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ var btnElement = _this.element.firstElementChild;
+ if (btnElement.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ return;
+ }
+ var toolbars = constants/* Constants.EDIT_TOOLBARS.concat */.g.EDIT_TOOLBARS.concat(["both", "edit-mode", "devtools"]);
+ if (btnElement.classList.contains("vditor-menu--current")) {
+ btnElement.classList.remove("vditor-menu--current");
+ if (vditor.currentMode === "sv") {
+ vditor.sv.element.style.display = "block";
+ if (vditor.options.preview.mode === "both") {
+ vditor.preview.element.style.display = "block";
+ }
+ else {
+ vditor.preview.element.style.display = "none";
+ }
+ }
+ else {
+ vditor[vditor.currentMode].element.parentElement.style.display = "block";
+ vditor.preview.element.style.display = "none";
+ }
+ enableToolbar(vditor.toolbar.elements, toolbars);
+ vditor.outline.render(vditor);
+ }
+ else {
+ disableToolbar(vditor.toolbar.elements, toolbars);
+ vditor.preview.element.style.display = "block";
+ if (vditor.currentMode === "sv") {
+ vditor.sv.element.style.display = "none";
+ }
+ else {
+ vditor[vditor.currentMode].element.parentElement.style.display = "none";
+ }
+ vditor.preview.render(vditor);
+ btnElement.classList.add("vditor-menu--current");
+ hidePanel(vditor, ["subToolbar", "hint", "popover"]);
+ setTimeout(function () {
+ vditor.outline.render(vditor);
+ }, vditor.options.preview.delay + 10);
+ }
+ setPadding(vditor);
+ });
+ };
+ return Preview;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/util/RecordMedia.ts
+var RecordMedia = /** @class */ (function () {
+ function RecordMedia(e) {
+ this.SAMPLE_RATE = 5000; // 44100 suggested by demos;
+ this.isRecording = false;
+ this.readyFlag = false;
+ this.leftChannel = [];
+ this.rightChannel = [];
+ this.recordingLength = 0;
+ var context;
+ // creates the audio context
+ if (typeof AudioContext !== "undefined") {
+ context = new AudioContext();
+ }
+ else if (webkitAudioContext) {
+ context = new webkitAudioContext();
+ }
+ else {
+ return;
+ }
+ this.DEFAULT_SAMPLE_RATE = context.sampleRate;
+ // creates a gain node
+ var volume = context.createGain();
+ // creates an audio node from the microphone incoming stream
+ var audioInput = context.createMediaStreamSource(e);
+ // connect the stream to the gain node
+ audioInput.connect(volume);
+ /* From the spec: The size of the buffer controls how frequently the audioprocess event is
+ dispatched and how many sample-frames need to be processed each call.
+ Lower values for buffer size will result in a lower (better) latency.
+ Higher values will be necessary to avoid audio breakup and glitches */
+ this.recorder = context.createScriptProcessor(2048, 2, 1);
+ // The onaudioprocess event needs to be defined externally, so make sure it is not set:
+ this.recorder.onaudioprocess = null;
+ // we connect the recorder
+ volume.connect(this.recorder);
+ this.recorder.connect(context.destination);
+ this.readyFlag = true;
+ }
+ // Publicly accessible methods:
+ RecordMedia.prototype.cloneChannelData = function (leftChannelData, rightChannelData) {
+ this.leftChannel.push(new Float32Array(leftChannelData));
+ this.rightChannel.push(new Float32Array(rightChannelData));
+ this.recordingLength += 2048;
+ };
+ RecordMedia.prototype.startRecordingNewWavFile = function () {
+ if (this.readyFlag) {
+ this.isRecording = true;
+ this.leftChannel.length = this.rightChannel.length = 0;
+ this.recordingLength = 0;
+ }
+ };
+ RecordMedia.prototype.stopRecording = function () {
+ this.isRecording = false;
+ };
+ RecordMedia.prototype.buildWavFileBlob = function () {
+ // we flat the left and right channels down
+ var leftBuffer = this.mergeBuffers(this.leftChannel);
+ var rightBuffer = this.mergeBuffers(this.rightChannel);
+ // Interleave the left and right channels together:
+ var interleaved = new Float32Array(leftBuffer.length);
+ for (var i = 0; i < leftBuffer.length; ++i) {
+ interleaved[i] = 0.5 * (leftBuffer[i] + rightBuffer[i]);
+ }
+ // Downsample the audio data if necessary:
+ if (this.DEFAULT_SAMPLE_RATE > this.SAMPLE_RATE) {
+ interleaved = this.downSampleBuffer(interleaved, this.SAMPLE_RATE);
+ }
+ var totalByteCount = (44 + interleaved.length * 2);
+ var buffer = new ArrayBuffer(totalByteCount);
+ var view = new DataView(buffer);
+ // Build the RIFF chunk descriptor:
+ this.writeUTFBytes(view, 0, "RIFF");
+ view.setUint32(4, totalByteCount, true);
+ this.writeUTFBytes(view, 8, "WAVE");
+ // Build the FMT sub-chunk:
+ this.writeUTFBytes(view, 12, "fmt "); // subchunk1 ID is format
+ view.setUint32(16, 16, true); // The sub-chunk size is 16.
+ view.setUint16(20, 1, true); // The audio format is 1.
+ view.setUint16(22, 1, true); // Number of interleaved channels.
+ view.setUint32(24, this.SAMPLE_RATE, true); // Sample rate.
+ view.setUint32(28, this.SAMPLE_RATE * 2, true); // Byte rate.
+ view.setUint16(32, 2, true); // Block align
+ view.setUint16(34, 16, true); // Bits per sample.
+ // Build the data sub-chunk:
+ var subChunk2ByteCount = interleaved.length * 2;
+ this.writeUTFBytes(view, 36, "data");
+ view.setUint32(40, subChunk2ByteCount, true);
+ // Write the PCM samples to the view:
+ var lng = interleaved.length;
+ var index = 44;
+ var volume = 1;
+ for (var j = 0; j < lng; j++) {
+ view.setInt16(index, interleaved[j] * (0x7FFF * volume), true);
+ index += 2;
+ }
+ return new Blob([view], { type: "audio/wav" });
+ };
+ RecordMedia.prototype.downSampleBuffer = function (buffer, rate) {
+ if (rate === this.DEFAULT_SAMPLE_RATE) {
+ return buffer;
+ }
+ if (rate > this.DEFAULT_SAMPLE_RATE) {
+ // throw "downsampling rate show be smaller than original sample rate";
+ return buffer;
+ }
+ var sampleRateRatio = this.DEFAULT_SAMPLE_RATE / rate;
+ var newLength = Math.round(buffer.length / sampleRateRatio);
+ var result = new Float32Array(newLength);
+ var offsetResult = 0;
+ var offsetBuffer = 0;
+ while (offsetResult < result.length) {
+ var nextOffsetBuffer = Math.round((offsetResult + 1) * sampleRateRatio);
+ var accum = 0;
+ var count = 0;
+ for (var i = offsetBuffer; i < nextOffsetBuffer && i < buffer.length; i++) {
+ accum += buffer[i];
+ count++;
+ }
+ result[offsetResult] = accum / count;
+ offsetResult++;
+ offsetBuffer = nextOffsetBuffer;
+ }
+ return result;
+ };
+ RecordMedia.prototype.mergeBuffers = function (desiredChannelBuffer) {
+ var result = new Float32Array(this.recordingLength);
+ var offset = 0;
+ var lng = desiredChannelBuffer.length;
+ for (var i = 0; i < lng; ++i) {
+ var buffer = desiredChannelBuffer[i];
+ result.set(buffer, offset);
+ offset += buffer.length;
+ }
+ return result;
+ };
+ RecordMedia.prototype.writeUTFBytes = function (view, offset, value) {
+ var lng = value.length;
+ for (var i = 0; i < lng; i++) {
+ view.setUint8(offset + i, value.charCodeAt(i));
+ }
+ };
+ return RecordMedia;
+}());
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Record.ts
+var Record_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+
+var Record = /** @class */ (function (_super) {
+ Record_extends(Record, _super);
+ function Record(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ _this._bindEvent(vditor);
+ return _this;
+ }
+ Record.prototype._bindEvent = function (vditor) {
+ var _this = this;
+ var mediaRecorder;
+ this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ if (_this.element.firstElementChild.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ return;
+ }
+ var editorElement = vditor[vditor.currentMode].element;
+ if (!mediaRecorder) {
+ navigator.mediaDevices.getUserMedia({ audio: true }).then(function (mediaStream) {
+ mediaRecorder = new RecordMedia(mediaStream);
+ mediaRecorder.recorder.onaudioprocess = function (e) {
+ // Do nothing if not recording:
+ if (!mediaRecorder.isRecording) {
+ return;
+ }
+ // Copy the data from the input buffers;
+ var left = e.inputBuffer.getChannelData(0);
+ var right = e.inputBuffer.getChannelData(1);
+ mediaRecorder.cloneChannelData(left, right);
+ };
+ mediaRecorder.startRecordingNewWavFile();
+ vditor.tip.show(window.VditorI18n.recording);
+ editorElement.setAttribute("contenteditable", "false");
+ _this.element.children[0].classList.add("vditor-menu--current");
+ }).catch(function () {
+ vditor.tip.show(window.VditorI18n["record-tip"]);
+ });
+ return;
+ }
+ if (mediaRecorder.isRecording) {
+ mediaRecorder.stopRecording();
+ vditor.tip.hide();
+ var file = new File([mediaRecorder.buildWavFileBlob()], "record".concat((new Date()).getTime(), ".wav"), { type: "video/webm" });
+ uploadFiles(vditor, [file]);
+ _this.element.children[0].classList.remove("vditor-menu--current");
+ }
+ else {
+ vditor.tip.show(window.VditorI18n.recording);
+ editorElement.setAttribute("contenteditable", "false");
+ mediaRecorder.startRecordingNewWavFile();
+ _this.element.children[0].classList.add("vditor-menu--current");
+ }
+ });
+ };
+ return Record;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Redo.ts
+var Redo_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+var Redo = /** @class */ (function (_super) {
+ Redo_extends(Redo, _super);
+ function Redo(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ disableToolbar({ redo: _this.element }, ["redo"]);
+ _this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ if (_this.element.firstElementChild.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ return;
+ }
+ vditor.undo.redo(vditor);
+ });
+ return _this;
+ }
+ return Redo;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Undo.ts
+var Undo_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+var Undo = /** @class */ (function (_super) {
+ Undo_extends(Undo, _super);
+ function Undo(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ disableToolbar({ undo: _this.element }, ["undo"]);
+ _this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ event.preventDefault();
+ if (_this.element.firstElementChild.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ return;
+ }
+ vditor.undo.undo(vditor);
+ });
+ return _this;
+ }
+ return Undo;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/Upload.ts
+var Upload_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+var Upload_Upload = /** @class */ (function (_super) {
+ Upload_extends(Upload, _super);
+ function Upload(vditor, menuItem) {
+ var _this = _super.call(this, vditor, menuItem) || this;
+ var inputHTML = '')).concat(inputHTML, ">");
+ _this._bindEvent(vditor);
+ return _this;
+ }
+ Upload.prototype._bindEvent = function (vditor) {
+ var _this = this;
+ this.element.children[0].addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ if (_this.element.firstElementChild.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ event.stopPropagation();
+ event.preventDefault();
+ return;
+ }
+ });
+ this.element.querySelector("input").addEventListener("change", function (event) {
+ if (_this.element.firstElementChild.classList.contains(constants/* Constants.CLASS_MENU_DISABLED */.g.CLASS_MENU_DISABLED)) {
+ event.stopPropagation();
+ event.preventDefault();
+ return;
+ }
+ if (event.target.files.length === 0) {
+ return;
+ }
+ uploadFiles(vditor, event.target.files, event.target);
+ });
+ };
+ return Upload;
+}(MenuItem));
+
+
+;// CONCATENATED MODULE: ./src/ts/toolbar/index.ts
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+var Toolbar = /** @class */ (function () {
+ function Toolbar(vditor) {
+ var _this = this;
+ var options = vditor.options;
+ this.elements = {};
+ this.element = document.createElement("div");
+ this.element.className = "vditor-toolbar";
+ options.toolbar.forEach(function (menuItem, i) {
+ var itemElement = _this.genItem(vditor, menuItem, i);
+ _this.element.appendChild(itemElement);
+ if (menuItem.toolbar) {
+ var panelElement_1 = document.createElement("div");
+ panelElement_1.className = "vditor-hint vditor-panel--arrow";
+ panelElement_1.addEventListener((0,compatibility/* getEventName */.Le)(), function (event) {
+ panelElement_1.style.display = "none";
+ });
+ menuItem.toolbar.forEach(function (subMenuItem, subI) {
+ subMenuItem.level = 2;
+ panelElement_1.appendChild(_this.genItem(vditor, subMenuItem, i + subI));
+ });
+ itemElement.appendChild(panelElement_1);
+ toggleSubMenu(vditor, panelElement_1, itemElement.children[0], 2);
+ }
+ });
+ if (vditor.options.toolbarConfig.hide) {
+ this.element.classList.add("vditor-toolbar--hide");
+ }
+ if (vditor.options.toolbarConfig.pin) {
+ this.element.classList.add("vditor-toolbar--pin");
+ }
+ if (vditor.options.counter.enable) {
+ vditor.counter = new Counter(vditor);
+ this.element.appendChild(vditor.counter.element);
+ }
+ }
+ Toolbar.prototype.updateConfig = function (vditor, options) {
+ vditor.options.toolbarConfig = Object.assign({
+ hide: false,
+ pin: false,
+ }, options);
+ if (vditor.options.toolbarConfig.hide) {
+ this.element.classList.add("vditor-toolbar--hide");
+ }
+ else {
+ this.element.classList.remove("vditor-toolbar--hide");
+ }
+ if (vditor.options.toolbarConfig.pin) {
+ this.element.classList.add("vditor-toolbar--pin");
+ }
+ else {
+ this.element.classList.remove("vditor-toolbar--pin");
+ }
+ };
+ Toolbar.prototype.genItem = function (vditor, menuItem, index) {
+ var menuItemObj;
+ switch (menuItem.name) {
+ case "bold":
+ case "italic":
+ case "more":
+ case "strike":
+ case "line":
+ case "quote":
+ case "list":
+ case "ordered-list":
+ case "check":
+ case "code":
+ case "inline-code":
+ case "link":
+ case "table":
+ menuItemObj = new MenuItem(vditor, menuItem);
+ break;
+ case "emoji":
+ menuItemObj = new Emoji(vditor, menuItem);
+ break;
+ case "headings":
+ menuItemObj = new Headings(vditor, menuItem);
+ break;
+ case "|":
+ menuItemObj = new Divider();
+ break;
+ case "br":
+ menuItemObj = new Br();
+ break;
+ case "undo":
+ menuItemObj = new Undo(vditor, menuItem);
+ break;
+ case "redo":
+ menuItemObj = new Redo(vditor, menuItem);
+ break;
+ case "help":
+ menuItemObj = new Help(vditor, menuItem);
+ break;
+ case "both":
+ menuItemObj = new Both(vditor, menuItem);
+ break;
+ case "preview":
+ menuItemObj = new Preview_Preview(vditor, menuItem);
+ break;
+ case "fullscreen":
+ menuItemObj = new Fullscreen(vditor, menuItem);
+ break;
+ case "upload":
+ menuItemObj = new Upload_Upload(vditor, menuItem);
+ break;
+ case "record":
+ menuItemObj = new Record(vditor, menuItem);
+ break;
+ case "info":
+ menuItemObj = new Info(vditor, menuItem);
+ break;
+ case "edit-mode":
+ menuItemObj = new EditMode(vditor, menuItem);
+ break;
+ case "devtools":
+ menuItemObj = new Devtools(vditor, menuItem);
+ break;
+ case "outdent":
+ menuItemObj = new Outdent(vditor, menuItem);
+ break;
+ case "indent":
+ menuItemObj = new Indent(vditor, menuItem);
+ break;
+ case "outline":
+ menuItemObj = new Outline_Outline(vditor, menuItem);
+ break;
+ case "insert-after":
+ menuItemObj = new InsertAfter(vditor, menuItem);
+ break;
+ case "insert-before":
+ menuItemObj = new InsertBefore(vditor, menuItem);
+ break;
+ case "code-theme":
+ menuItemObj = new CodeTheme(vditor, menuItem);
+ break;
+ case "content-theme":
+ menuItemObj = new ContentTheme(vditor, menuItem);
+ break;
+ case "export":
+ menuItemObj = new Export(vditor, menuItem);
+ break;
+ default:
+ menuItemObj = new Custom(vditor, menuItem);
+ break;
+ }
+ if (!menuItemObj) {
+ return;
+ }
+ var key = menuItem.name;
+ if (key === "br" || key === "|") {
+ key = key + index;
+ }
+ this.elements[key] = menuItemObj.element;
+ return menuItemObj.element;
+ };
+ return Toolbar;
+}());
+
+
+// EXTERNAL MODULE: ./node_modules/.pnpm/diff-match-patch@1.0.5/node_modules/diff-match-patch/index.js
+var diff_match_patch = __webpack_require__(173);
+;// CONCATENATED MODULE: ./src/ts/undo/index.ts
+
+
+
+
+
+
+
+
+
+var undo_Undo = /** @class */ (function () {
+ function Undo() {
+ this.stackSize = 50;
+ this.resetStack();
+ // @ts-ignore
+ this.dmp = new diff_match_patch();
+ }
+ Undo.prototype.clearStack = function (vditor) {
+ this.resetStack();
+ this.resetIcon(vditor);
+ };
+ Undo.prototype.resetIcon = function (vditor) {
+ if (!vditor.toolbar) {
+ return;
+ }
+ if (this[vditor.currentMode].undoStack.length > 1) {
+ enableToolbar(vditor.toolbar.elements, ["undo"]);
+ }
+ else {
+ disableToolbar(vditor.toolbar.elements, ["undo"]);
+ }
+ if (this[vditor.currentMode].redoStack.length !== 0) {
+ enableToolbar(vditor.toolbar.elements, ["redo"]);
+ }
+ else {
+ disableToolbar(vditor.toolbar.elements, ["redo"]);
+ }
+ };
+ Undo.prototype.undo = function (vditor) {
+ if (vditor[vditor.currentMode].element.getAttribute("contenteditable") === "false") {
+ return;
+ }
+ if (this[vditor.currentMode].undoStack.length < 2) {
+ return;
+ }
+ var state = this[vditor.currentMode].undoStack.pop();
+ if (!state) {
+ return;
+ }
+ this[vditor.currentMode].redoStack.push(state);
+ this.renderDiff(state, vditor);
+ this[vditor.currentMode].hasUndo = true;
+ // undo 操作后,需要关闭 hint
+ hidePanel(vditor, ["hint"]);
+ };
+ Undo.prototype.redo = function (vditor) {
+ if (vditor[vditor.currentMode].element.getAttribute("contenteditable") === "false") {
+ return;
+ }
+ var state = this[vditor.currentMode].redoStack.pop();
+ if (!state) {
+ return;
+ }
+ this[vditor.currentMode].undoStack.push(state);
+ this.renderDiff(state, vditor, true);
+ };
+ Undo.prototype.recordFirstPosition = function (vditor, event) {
+ if (getSelection().rangeCount === 0) {
+ return;
+ }
+ if (this[vditor.currentMode].undoStack.length !== 1 || this[vditor.currentMode].undoStack[0].length === 0 ||
+ this[vditor.currentMode].redoStack.length > 0) {
+ return;
+ }
+ if ((0,compatibility/* isFirefox */.vU)() && event.key === "Backspace") {
+ // Firefox 第一次删除无效
+ return;
+ }
+ if ((0,compatibility/* isSafari */.G6)()) {
+ // Safari keydown 在 input 之后,不需要重复记录历史
+ return;
+ }
+ var text = this.addCaret(vditor);
+ if (text.replace("", "").replace(" vditor-ir__node--expand", "")
+ !== this[vditor.currentMode].undoStack[0][0].diffs[0][1].replace("", "")) {
+ // 当还不没有存入 undo 栈时,按下 ctrl 后会覆盖 lastText
+ return;
+ }
+ this[vditor.currentMode].undoStack[0][0].diffs[0][1] = text;
+ this[vditor.currentMode].lastText = text;
+ // 不能添加 setSelectionFocus(cloneRange); 否则 windows chrome 首次输入会烂
+ };
+ Undo.prototype.addToUndoStack = function (vditor) {
+ // afterRenderEvent.ts 已经 debounce
+ var text = this.addCaret(vditor, true);
+ var diff = this.dmp.diff_main(text, this[vditor.currentMode].lastText, true);
+ var patchList = this.dmp.patch_make(text, this[vditor.currentMode].lastText, diff);
+ if (patchList.length === 0 && this[vditor.currentMode].undoStack.length > 0) {
+ return;
+ }
+ this[vditor.currentMode].lastText = text;
+ this[vditor.currentMode].undoStack.push(patchList);
+ if (this[vditor.currentMode].undoStack.length > this.stackSize) {
+ this[vditor.currentMode].undoStack.shift();
+ }
+ if (this[vditor.currentMode].hasUndo) {
+ this[vditor.currentMode].redoStack = [];
+ this[vditor.currentMode].hasUndo = false;
+ disableToolbar(vditor.toolbar.elements, ["redo"]);
+ }
+ if (this[vditor.currentMode].undoStack.length > 1) {
+ enableToolbar(vditor.toolbar.elements, ["undo"]);
+ }
+ };
+ Undo.prototype.renderDiff = function (state, vditor, isRedo) {
+ if (isRedo === void 0) { isRedo = false; }
+ var text;
+ if (isRedo) {
+ var redoPatchList = this.dmp.patch_deepCopy(state).reverse();
+ redoPatchList.forEach(function (patch) {
+ patch.diffs.forEach(function (diff) {
+ diff[0] = -diff[0];
+ });
+ });
+ text = this.dmp.patch_apply(redoPatchList, this[vditor.currentMode].lastText)[0];
+ }
+ else {
+ text = this.dmp.patch_apply(state, this[vditor.currentMode].lastText)[0];
+ }
+ this[vditor.currentMode].lastText = text;
+ vditor[vditor.currentMode].element.innerHTML = text;
+ if (vditor.currentMode !== "sv") {
+ vditor[vditor.currentMode].element.querySelectorAll(".vditor-".concat(vditor.currentMode, "__preview"))
+ .forEach(function (blockElement) {
+ if (blockElement.parentElement.querySelector(".language-echarts")) {
+ if (vditor.currentMode === "ir") {
+ blockElement.parentElement.outerHTML = vditor.lute.SpinVditorIRDOM(blockElement.parentElement.outerHTML);
+ }
+ else {
+ blockElement.parentElement.outerHTML = vditor.lute.SpinVditorDOM(blockElement.parentElement.outerHTML);
+ }
+ }
+ });
+ vditor[vditor.currentMode].element.querySelectorAll(".vditor-".concat(vditor.currentMode, "__preview[data-render='2']"))
+ .forEach(function (blockElement) {
+ processCodeRender(blockElement, vditor);
+ });
+ }
+ if (!vditor[vditor.currentMode].element.querySelector("wbr")) {
+ // Safari 第一次输入没有光标,需手动定位到结尾
+ var range = getSelection().getRangeAt(0);
+ range.setEndBefore(vditor[vditor.currentMode].element);
+ range.collapse(false);
+ }
+ else {
+ (0,selection/* setRangeByWbr */.ib)(vditor[vditor.currentMode].element, vditor[vditor.currentMode].element.ownerDocument.createRange());
+ scrollCenter(vditor);
+ }
+ renderToc(vditor);
+ execAfterRender(vditor, {
+ enableAddUndoStack: false,
+ enableHint: false,
+ enableInput: true,
+ });
+ highlightToolbar(vditor);
+ vditor[vditor.currentMode].element.querySelectorAll(".vditor-".concat(vditor.currentMode, "__preview[data-render='2']"))
+ .forEach(function (item) {
+ processCodeRender(item, vditor);
+ });
+ if (this[vditor.currentMode].undoStack.length > 1) {
+ enableToolbar(vditor.toolbar.elements, ["undo"]);
+ }
+ else {
+ disableToolbar(vditor.toolbar.elements, ["undo"]);
+ }
+ if (this[vditor.currentMode].redoStack.length !== 0) {
+ enableToolbar(vditor.toolbar.elements, ["redo"]);
+ }
+ else {
+ disableToolbar(vditor.toolbar.elements, ["redo"]);
+ }
+ };
+ Undo.prototype.resetStack = function () {
+ this.ir = {
+ hasUndo: false,
+ lastText: "",
+ redoStack: [],
+ undoStack: [],
+ };
+ this.sv = {
+ hasUndo: false,
+ lastText: "",
+ redoStack: [],
+ undoStack: [],
+ };
+ this.wysiwyg = {
+ hasUndo: false,
+ lastText: "",
+ redoStack: [],
+ undoStack: [],
+ };
+ };
+ Undo.prototype.addCaret = function (vditor, setFocus) {
+ if (setFocus === void 0) { setFocus = false; }
+ var cloneRange;
+ if (getSelection().rangeCount !== 0 && !vditor[vditor.currentMode].element.querySelector("wbr")) {
+ var range = getSelection().getRangeAt(0);
+ if (vditor[vditor.currentMode].element.contains(range.startContainer)) {
+ cloneRange = range.cloneRange();
+ var wbrElement = document.createElement("span");
+ wbrElement.className = "vditor-wbr";
+ range.insertNode(wbrElement);
+ }
+ }
+ // 移除数学公式、echart 渲染 https://github.com/Vanessa219/vditor/issues/1738
+ var cloneElement = vditor[vditor.currentMode].element.cloneNode(true);
+ cloneElement.querySelectorAll(".vditor-".concat(vditor.currentMode, "__preview[data-render='1']"))
+ .forEach(function (item) {
+ if (!item.firstElementChild) {
+ return;
+ }
+ if (item.firstElementChild.classList.contains("language-echarts") ||
+ item.firstElementChild.classList.contains("language-plantuml") ||
+ item.firstElementChild.classList.contains("language-mindmap")) {
+ item.firstElementChild.removeAttribute("_echarts_instance_");
+ item.firstElementChild.removeAttribute("data-processed");
+ item.firstElementChild.innerHTML = item.previousElementSibling.firstElementChild.innerHTML;
+ item.setAttribute("data-render", "2");
+ }
+ else if (item.firstElementChild.classList.contains("language-math")) {
+ item.setAttribute("data-render", "2");
+ item.firstElementChild.textContent = item.firstElementChild.getAttribute("data-math");
+ item.firstElementChild.removeAttribute("data-math");
+ }
+ });
+ var text = cloneElement.innerHTML;
+ vditor[vditor.currentMode].element.querySelectorAll(".vditor-wbr").forEach(function (item) {
+ item.remove();
+ // 使用 item.outerHTML = "" 会产生 https://github.com/Vanessa219/vditor/pull/686;
+ });
+ if (setFocus && cloneRange) {
+ (0,selection/* setSelectionFocus */.Hc)(cloneRange);
+ }
+ return text.replace('', "");
+ };
+ return Undo;
+}());
+
+
+// EXTERNAL MODULE: ./src/ts/util/merge.ts
+var merge = __webpack_require__(673);
+;// CONCATENATED MODULE: ./src/ts/util/Options.ts
+
+
+var Options = /** @class */ (function () {
+ function Options(options) {
+ this.defaultOptions = {
+ rtl: false,
+ after: undefined,
+ cache: {
+ enable: true,
+ },
+ cdn: constants/* Constants.CDN */.g.CDN,
+ classes: {
+ preview: "",
+ },
+ comment: {
+ enable: false,
+ },
+ counter: {
+ enable: false,
+ type: "markdown",
+ },
+ customRenders: [],
+ debugger: false,
+ fullscreen: {
+ index: 90,
+ },
+ height: "auto",
+ hint: {
+ delay: 200,
+ emoji: {
+ "+1": "👍",
+ "-1": "👎",
+ "confused": "😕",
+ "eyes": "👀️",
+ "heart": "❤️",
+ "rocket": "🚀️",
+ "smile": "😄",
+ "tada": "🎉️",
+ },
+ emojiPath: "".concat(constants/* Constants.CDN */.g.CDN, "/dist/images/emoji"),
+ extend: [],
+ parse: true,
+ },
+ icon: "ant",
+ lang: "zh_CN",
+ mode: "ir",
+ outline: {
+ enable: false,
+ position: "left",
+ },
+ placeholder: "",
+ preview: {
+ actions: ["desktop", "tablet", "mobile", "mp-wechat", "zhihu"],
+ delay: 1000,
+ hljs: constants/* Constants.HLJS_OPTIONS */.g.HLJS_OPTIONS,
+ markdown: constants/* Constants.MARKDOWN_OPTIONS */.g.MARKDOWN_OPTIONS,
+ math: constants/* Constants.MATH_OPTIONS */.g.MATH_OPTIONS,
+ maxWidth: 800,
+ mode: "both",
+ theme: constants/* Constants.THEME_OPTIONS */.g.THEME_OPTIONS,
+ render: {
+ media: {
+ enable: true,
+ }
+ }
+ },
+ link: {
+ isOpen: true,
+ },
+ image: {
+ isPreview: true,
+ },
+ resize: {
+ enable: false,
+ position: "bottom",
+ },
+ theme: "classic",
+ toolbar: [
+ "emoji",
+ "headings",
+ "bold",
+ "italic",
+ "strike",
+ "link",
+ "|",
+ "list",
+ "ordered-list",
+ "check",
+ "outdent",
+ "indent",
+ "|",
+ "quote",
+ "line",
+ "code",
+ "inline-code",
+ "insert-before",
+ "insert-after",
+ "|",
+ "upload",
+ "record",
+ "table",
+ "|",
+ "undo",
+ "redo",
+ "|",
+ "fullscreen",
+ "edit-mode",
+ {
+ name: "more",
+ toolbar: [
+ "both",
+ "code-theme",
+ "content-theme",
+ "export",
+ "outline",
+ "preview",
+ "devtools",
+ "info",
+ "help",
+ ],
+ },
+ ],
+ toolbarConfig: {
+ hide: false,
+ pin: false,
+ },
+ typewriterMode: false,
+ undoDelay: 800,
+ upload: {
+ extraData: {},
+ fieldName: "file[]",
+ filename: function (name) { return name.replace(/\W/g, ""); },
+ linkToImgUrl: "",
+ max: 10 * 1024 * 1024,
+ multiple: true,
+ url: "",
+ withCredentials: false,
+ },
+ value: "",
+ width: "auto",
+ };
+ this.options = options;
+ }
+ Options.prototype.merge = function () {
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
+ if (this.options) {
+ if (this.options.toolbar) {
+ this.options.toolbar = this.mergeToolbar(this.options.toolbar);
+ }
+ else {
+ this.options.toolbar = this.mergeToolbar(this.defaultOptions.toolbar);
+ }
+ if ((_b = (_a = this.options.preview) === null || _a === void 0 ? void 0 : _a.theme) === null || _b === void 0 ? void 0 : _b.list) {
+ this.defaultOptions.preview.theme.list = this.options.preview.theme.list;
+ }
+ if ((_e = (_d = (_c = this.options.preview) === null || _c === void 0 ? void 0 : _c.render) === null || _d === void 0 ? void 0 : _d.media) === null || _e === void 0 ? void 0 : _e.enable) {
+ this.defaultOptions.preview.render.media.enable = this.options.preview.render.media.enable;
+ }
+ if ((_f = this.options.hint) === null || _f === void 0 ? void 0 : _f.emoji) {
+ this.defaultOptions.hint.emoji = this.options.hint.emoji;
+ }
+ if (this.options.comment) {
+ this.defaultOptions.comment = this.options.comment;
+ }
+ if (this.options.cdn) {
+ if (!((_h = (_g = this.options.preview) === null || _g === void 0 ? void 0 : _g.theme) === null || _h === void 0 ? void 0 : _h.path)) {
+ this.defaultOptions.preview.theme.path = "".concat(this.options.cdn, "/dist/css/content-theme");
+ }
+ if (!((_j = this.options.hint) === null || _j === void 0 ? void 0 : _j.emojiPath)) {
+ this.defaultOptions.hint.emojiPath = "".concat(this.options.cdn, "/dist/images/emoji");
+ }
+ }
+ }
+ var mergedOptions = (0,merge/* merge */.T)(this.defaultOptions, this.options);
+ if (mergedOptions.cache.enable && !mergedOptions.cache.id) {
+ throw new Error("need options.cache.id, see https://ld246.com/article/1549638745630#options");
+ }
+ return mergedOptions;
+ };
+ Options.prototype.mergeToolbar = function (toolbar) {
+ var _this = this;
+ var toolbarItem = [
+ {
+ icon: '',
+ name: "export",
+ tipPosition: "ne",
+ },
+ {
+ hotkey: "⌘E",
+ icon: '',
+ name: "emoji",
+ tipPosition: "ne",
+ },
+ {
+ hotkey: "⌘H",
+ icon: '',
+ name: "headings",
+ tipPosition: "ne",
+ },
+ {
+ hotkey: "⌘B",
+ icon: '',
+ name: "bold",
+ prefix: "**",
+ suffix: "**",
+ tipPosition: "ne",
+ },
+ {
+ hotkey: "⌘I",
+ icon: '',
+ name: "italic",
+ prefix: "*",
+ suffix: "*",
+ tipPosition: "ne",
+ },
+ {
+ hotkey: "⌘D",
+ icon: '',
+ name: "strike",
+ prefix: "~~",
+ suffix: "~~",
+ tipPosition: "ne",
+ },
+ {
+ hotkey: "⌘K",
+ icon: '',
+ name: "link",
+ prefix: "[",
+ suffix: "](https://)",
+ tipPosition: "n",
+ },
+ {
+ name: "|",
+ },
+ {
+ hotkey: "⌘L",
+ icon: '',
+ name: "list",
+ prefix: "* ",
+ tipPosition: "n",
+ },
+ {
+ hotkey: "⌘O",
+ icon: '',
+ name: "ordered-list",
+ prefix: "1. ",
+ tipPosition: "n",
+ },
+ {
+ hotkey: "⌘J",
+ icon: '',
+ name: "check",
+ prefix: "* [ ] ",
+ tipPosition: "n",
+ },
+ {
+ hotkey: "⇧⌘I",
+ icon: '',
+ name: "outdent",
+ tipPosition: "n",
+ },
+ {
+ hotkey: "⇧⌘O",
+ icon: '',
+ name: "indent",
+ tipPosition: "n",
+ },
+ {
+ name: "|",
+ },
+ {
+ hotkey: "⌘;",
+ icon: '',
+ name: "quote",
+ prefix: "> ",
+ tipPosition: "n",
+ },
+ {
+ hotkey: "⇧⌘H",
+ icon: '',
+ name: "line",
+ prefix: "---",
+ tipPosition: "n",
+ },
+ {
+ hotkey: "⌘U",
+ icon: '',
+ name: "code",
+ prefix: "```",
+ suffix: "\n```",
+ tipPosition: "n",
+ },
+ {
+ hotkey: "⌘G",
+ icon: '',
+ name: "inline-code",
+ prefix: "`",
+ suffix: "`",
+ tipPosition: "n",
+ },
+ {
+ hotkey: "⇧⌘B",
+ icon: '',
+ name: "insert-before",
+ tipPosition: "n",
+ },
+ {
+ hotkey: "⇧⌘E",
+ icon: '',
+ name: "insert-after",
+ tipPosition: "n",
+ },
+ {
+ name: "|",
+ },
+ {
+ icon: '',
+ name: "upload",
+ tipPosition: "n",
+ },
+ {
+ icon: '',
+ name: "record",
+ tipPosition: "n",
+ },
+ {
+ hotkey: "⌘M",
+ icon: '',
+ name: "table",
+ prefix: "| col1",
+ suffix: " | col2 | col3 |\n| --- | --- | --- |\n| | | |\n| | | |",
+ tipPosition: "n",
+ },
+ {
+ name: "|",
+ },
+ {
+ hotkey: "⌘Z",
+ icon: '',
+ name: "undo",
+ tipPosition: "nw",
+ },
+ {
+ hotkey: "⌘Y",
+ icon: '',
+ name: "redo",
+ tipPosition: "nw",
+ },
+ {
+ name: "|",
+ },
+ {
+ icon: '',
+ name: "more",
+ tipPosition: "e",
+ },
+ {
+ hotkey: "⌘'",
+ icon: '',
+ name: "fullscreen",
+ tipPosition: "nw",
+ },
+ {
+ icon: '',
+ name: "edit-mode",
+ tipPosition: "nw",
+ },
+ {
+ hotkey: "⌘P",
+ icon: '',
+ name: "both",
+ tipPosition: "nw",
+ },
+ {
+ icon: '',
+ name: "preview",
+ tipPosition: "nw",
+ },
+ {
+ icon: '',
+ name: "outline",
+ tipPosition: "nw",
+ },
+ {
+ icon: '',
+ name: "content-theme",
+ tipPosition: "nw",
+ },
+ {
+ icon: '',
+ name: "code-theme",
+ tipPosition: "nw",
+ },
+ {
+ icon: '',
+ name: "devtools",
+ tipPosition: "nw",
+ },
+ {
+ icon: '',
+ name: "info",
+ tipPosition: "nw",
+ },
+ {
+ icon: '',
+ name: "help",
+ tipPosition: "nw",
+ },
+ {
+ name: "br",
+ },
+ ];
+ var toolbarResult = [];
+ toolbar.forEach(function (menuItem) {
+ var currentMenuItem = menuItem;
+ toolbarItem.forEach(function (defaultMenuItem) {
+ if (typeof menuItem === "string" &&
+ defaultMenuItem.name === menuItem) {
+ currentMenuItem = defaultMenuItem;
+ }
+ if (typeof menuItem === "object" &&
+ defaultMenuItem.name === menuItem.name) {
+ currentMenuItem = Object.assign({}, defaultMenuItem, menuItem);
+ }
+ });
+ if (menuItem.toolbar) {
+ currentMenuItem.toolbar = _this.mergeToolbar(menuItem.toolbar);
+ }
+ toolbarResult.push(currentMenuItem);
+ });
+ return toolbarResult;
+ };
+ return Options;
+}());
+
+
+;// CONCATENATED MODULE: ./src/ts/wysiwyg/index.ts
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+var WYSIWYG = /** @class */ (function () {
+ function WYSIWYG(vditor) {
+ var _this = this;
+ this.composingLock = false;
+ this.commentIds = [];
+ var divElement = document.createElement("div");
+ divElement.className = "vditor-wysiwyg";
+ divElement.innerHTML = "\n\n\n \n
");
+ this.element = divElement.firstElementChild;
+ this.popover = divElement.firstElementChild.nextElementSibling;
+ this.selectPopover = divElement.lastElementChild;
+ this.bindEvent(vditor);
+ focusEvent(vditor, this.element);
+ dblclickEvent(vditor, this.element);
+ blurEvent(vditor, this.element);
+ hotkeyEvent(vditor, this.element);
+ selectEvent(vditor, this.element);
+ dropEvent(vditor, this.element);
+ copyEvent(vditor, this.element, this.copy);
+ cutEvent(vditor, this.element, this.copy);
+ if (vditor.options.comment.enable) {
+ this.selectPopover.querySelector("button").onclick = function () {
+ var id = Lute.NewNodeID();
+ var range = getSelection().getRangeAt(0);
+ var rangeClone = range.cloneRange();
+ var contents = range.extractContents();
+ var blockStartElement;
+ var blockEndElement;
+ var removeStart = false;
+ var removeEnd = false;
+ contents.childNodes.forEach(function (item, index) {
+ var wrap = false;
+ if (item.nodeType === 3) {
+ wrap = true;
+ }
+ else if (!item.classList.contains("vditor-comment")) {
+ wrap = true;
+ }
+ else if (item.classList.contains("vditor-comment")) {
+ item.setAttribute("data-cmtids", item.getAttribute("data-cmtids") + " " + id);
+ }
+ if (wrap) {
+ if (item.nodeType !== 3 && item.getAttribute("data-block") === "0"
+ && index === 0 && rangeClone.startOffset > 0) {
+ item.innerHTML =
+ "");
+ blockStartElement = item;
+ }
+ else if (item.nodeType !== 3 && item.getAttribute("data-block") === "0"
+ && index === contents.childNodes.length - 1
+ && rangeClone.endOffset < rangeClone.endContainer.textContent.length) {
+ item.innerHTML =
+ "");
+ blockEndElement = item;
+ }
+ else if (item.nodeType !== 3 && item.getAttribute("data-block") === "0") {
+ if (index === 0) {
+ removeStart = true;
+ }
+ else if (index === contents.childNodes.length - 1) {
+ removeEnd = true;
+ }
+ item.innerHTML =
+ "");
+ }
+ else {
+ var commentElement = document.createElement("span");
+ commentElement.classList.add("vditor-comment");
+ commentElement.setAttribute("data-cmtids", id);
+ item.parentNode.insertBefore(commentElement, item);
+ commentElement.appendChild(item);
+ }
+ }
+ });
+ var startElement = (0,hasClosest/* hasClosestBlock */.F9)(rangeClone.startContainer);
+ if (startElement) {
+ if (blockStartElement) {
+ startElement.insertAdjacentHTML("beforeend", blockStartElement.innerHTML);
+ blockStartElement.remove();
+ }
+ else if (startElement.textContent.trim().replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" && removeStart) {
+ startElement.remove();
+ }
+ }
+ var endElement = (0,hasClosest/* hasClosestBlock */.F9)(rangeClone.endContainer);
+ if (endElement) {
+ if (blockEndElement) {
+ endElement.insertAdjacentHTML("afterbegin", blockEndElement.innerHTML);
+ blockEndElement.remove();
+ }
+ else if (endElement.textContent.trim().replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "" && removeEnd) {
+ endElement.remove();
+ }
+ }
+ range.insertNode(contents);
+ vditor.options.comment.add(id, range.toString(), _this.getComments(vditor, true));
+ afterRenderEvent(vditor, {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: false,
+ });
+ _this.hideComment();
+ };
+ }
+ }
+ WYSIWYG.prototype.getComments = function (vditor, getData) {
+ var _this = this;
+ if (getData === void 0) { getData = false; }
+ if (vditor.currentMode === "wysiwyg" && vditor.options.comment.enable) {
+ this.commentIds = [];
+ this.element.querySelectorAll(".vditor-comment").forEach(function (item) {
+ _this.commentIds =
+ _this.commentIds.concat(item.getAttribute("data-cmtids").split(" "));
+ });
+ this.commentIds = Array.from(new Set(this.commentIds));
+ var comments_1 = [];
+ if (getData) {
+ this.commentIds.forEach(function (id) {
+ comments_1.push({
+ id: id,
+ top: _this.element.querySelector(".vditor-comment[data-cmtids=\"".concat(id, "\"]")).offsetTop,
+ });
+ });
+ return comments_1;
+ }
+ }
+ else {
+ return [];
+ }
+ };
+ WYSIWYG.prototype.triggerRemoveComment = function (vditor) {
+ var difference = function (a, b) {
+ var s = new Set(b);
+ return a.filter(function (x) { return !s.has(x); });
+ };
+ if (vditor.currentMode === "wysiwyg" && vditor.options.comment.enable && vditor.wysiwyg.commentIds.length > 0) {
+ var oldIds = JSON.parse(JSON.stringify(this.commentIds));
+ this.getComments(vditor);
+ var removedIds = difference(oldIds, this.commentIds);
+ if (removedIds.length > 0) {
+ vditor.options.comment.remove(removedIds);
+ }
+ }
+ };
+ WYSIWYG.prototype.showComment = function () {
+ var position = (0,selection/* getCursorPosition */.Ny)(this.element);
+ this.selectPopover.setAttribute("style", "left:".concat(position.left, "px;display:block;top:").concat(Math.max(-8, position.top - 21), "px"));
+ };
+ WYSIWYG.prototype.hideComment = function () {
+ this.selectPopover.setAttribute("style", "display:none");
+ };
+ WYSIWYG.prototype.unbindListener = function () {
+ window.removeEventListener("scroll", this.scrollListener);
+ };
+ WYSIWYG.prototype.copy = function (event, vditor) {
+ var range = getSelection().getRangeAt(0);
+ if (range.toString() === "") {
+ return;
+ }
+ event.stopPropagation();
+ event.preventDefault();
+ var codeElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "CODE");
+ var codeEndElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.endContainer, "CODE");
+ if (codeElement && codeEndElement && codeEndElement.isSameNode(codeElement)) {
+ var codeText = "";
+ if (codeElement.parentElement.tagName === "PRE") {
+ codeText = range.toString();
+ }
+ else {
+ codeText = "`" + range.toString() + "`";
+ }
+ event.clipboardData.setData("text/plain", codeText);
+ event.clipboardData.setData("text/html", "");
+ return;
+ }
+ var aElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.startContainer, "A");
+ var aEndElement = (0,hasClosest/* hasClosestByMatchTag */.lG)(range.endContainer, "A");
+ if (aElement && aEndElement && aEndElement.isSameNode(aElement)) {
+ var aTitle = aElement.getAttribute("title") || "";
+ if (aTitle) {
+ aTitle = " \"".concat(aTitle, "\"");
+ }
+ event.clipboardData.setData("text/plain", "[".concat(range.toString(), "](").concat(aElement.getAttribute("href")).concat(aTitle, ")"));
+ event.clipboardData.setData("text/html", "");
+ return;
+ }
+ var tempElement = document.createElement("div");
+ tempElement.appendChild(range.cloneContents());
+ event.clipboardData.setData("text/plain", vditor.lute.VditorDOM2Md(tempElement.innerHTML).trim());
+ event.clipboardData.setData("text/html", "");
+ };
+ WYSIWYG.prototype.bindEvent = function (vditor) {
+ var _this = this;
+ this.unbindListener();
+ window.addEventListener("scroll", this.scrollListener = function () {
+ hidePanel(vditor, ["hint"]);
+ if (_this.popover.style.display !== "block" || _this.selectPopover.style.display !== "block") {
+ return;
+ }
+ var top = parseInt(_this.popover.getAttribute("data-top"), 10);
+ if (vditor.options.height !== "auto") {
+ if (vditor.options.toolbarConfig.pin && vditor.toolbar.element.getBoundingClientRect().top === 0) {
+ var popoverTop = Math.max(window.scrollY - vditor.element.offsetTop - 8, Math.min(top - vditor.wysiwyg.element.scrollTop, _this.element.clientHeight - 21)) + "px";
+ if (_this.popover.style.display === "block") {
+ _this.popover.style.top = popoverTop;
+ }
+ if (_this.selectPopover.style.display === "block") {
+ _this.selectPopover.style.top = popoverTop;
+ }
+ }
+ return;
+ }
+ else if (!vditor.options.toolbarConfig.pin) {
+ return;
+ }
+ var popoverTop1 = Math.max(top, (window.scrollY - vditor.element.offsetTop - 8)) + "px";
+ if (_this.popover.style.display === "block") {
+ _this.popover.style.top = popoverTop1;
+ }
+ if (_this.selectPopover.style.display === "block") {
+ _this.selectPopover.style.top = popoverTop1;
+ }
+ });
+ this.element.addEventListener("scroll", function () {
+ hidePanel(vditor, ["hint"]);
+ if (vditor.options.comment && vditor.options.comment.enable && vditor.options.comment.scroll) {
+ vditor.options.comment.scroll(vditor.wysiwyg.element.scrollTop);
+ }
+ if (_this.popover.style.display !== "block") {
+ return;
+ }
+ var top = parseInt(_this.popover.getAttribute("data-top"), 10) - vditor.wysiwyg.element.scrollTop;
+ var max = -8;
+ if (vditor.options.toolbarConfig.pin && vditor.toolbar.element.getBoundingClientRect().top === 0) {
+ max = window.scrollY - vditor.element.offsetTop + max;
+ }
+ var topPx = Math.max(max, Math.min(top, _this.element.clientHeight - 21)) + "px";
+ _this.popover.style.top = topPx;
+ _this.selectPopover.style.top = topPx;
+ });
+ this.element.addEventListener("paste", function (event) {
+ paste(vditor, event, {
+ pasteCode: function (code) {
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ var node = document.createElement("template");
+ node.innerHTML = code;
+ range.insertNode(node.content.cloneNode(true));
+ var blockElement = (0,hasClosest/* hasClosestByAttribute */.a1)(range.startContainer, "data-block", "0");
+ if (blockElement) {
+ blockElement.outerHTML = vditor.lute.SpinVditorDOM(blockElement.outerHTML);
+ }
+ else {
+ vditor.wysiwyg.element.innerHTML = vditor.lute.SpinVditorDOM(vditor.wysiwyg.element.innerHTML);
+ }
+ (0,selection/* setRangeByWbr */.ib)(vditor.wysiwyg.element, range);
+ },
+ });
+ });
+ // 中文处理
+ this.element.addEventListener("compositionstart", function () {
+ _this.composingLock = true;
+ });
+ this.element.addEventListener("compositionend", function (event) {
+ var headingElement = (0,hasClosestByHeadings/* hasClosestByHeadings */.W)(getSelection().getRangeAt(0).startContainer);
+ if (headingElement && headingElement.textContent === "") {
+ // heading 为空删除 https://github.com/Vanessa219/vditor/issues/150
+ renderToc(vditor);
+ return;
+ }
+ if (!(0,compatibility/* isFirefox */.vU)()) {
+ input_input(vditor, getSelection().getRangeAt(0).cloneRange(), event);
+ }
+ _this.composingLock = false;
+ });
+ this.element.addEventListener("input", function (event) {
+ if (event.inputType === "deleteByDrag" || event.inputType === "insertFromDrop") {
+ // https://github.com/Vanessa219/vditor/issues/801 编辑器内容拖拽问题
+ return;
+ }
+ if (_this.preventInput) {
+ _this.preventInput = false;
+ afterRenderEvent(vditor);
+ return;
+ }
+ if (_this.composingLock || event.data === "‘" || event.data === "“" || event.data === "《") {
+ afterRenderEvent(vditor);
+ return;
+ }
+ var range = getSelection().getRangeAt(0);
+ var blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer);
+ if (!blockElement) {
+ // 没有被块元素包裹
+ modifyPre(vditor, range);
+ blockElement = (0,hasClosest/* hasClosestBlock */.F9)(range.startContainer);
+ }
+ if (!blockElement) {
+ return;
+ }
+ // 前后空格处理
+ var startOffset = (0,selection/* getSelectPosition */.im)(blockElement, vditor.wysiwyg.element, range).start;
+ // 开始可以输入空格
+ var startSpace = true;
+ for (var i = startOffset - 1; i > blockElement.textContent.substr(0, startOffset).lastIndexOf("\n"); i--) {
+ if (blockElement.textContent.charAt(i) !== " " &&
+ // 多个 tab 前删除不形成代码块 https://github.com/Vanessa219/vditor/issues/162 1
+ blockElement.textContent.charAt(i) !== "\t") {
+ startSpace = false;
+ break;
+ }
+ }
+ if (startOffset === 0) {
+ startSpace = false;
+ }
+ // 结尾可以输入空格
+ var endSpace = true;
+ for (var i = startOffset - 1; i < blockElement.textContent.length; i++) {
+ if (blockElement.textContent.charAt(i) !== " " && blockElement.textContent.charAt(i) !== "\n") {
+ endSpace = false;
+ break;
+ }
+ }
+ // https://github.com/Vanessa219/vditor/issues/729
+ if (endSpace && /^#{1,6} $/.test(blockElement.textContent)) {
+ endSpace = false;
+ }
+ var headingElement = (0,hasClosestByHeadings/* hasClosestByHeadings */.W)(getSelection().getRangeAt(0).startContainer);
+ if (headingElement && headingElement.textContent === "") {
+ // heading 为空删除 https://github.com/Vanessa219/vditor/issues/150
+ renderToc(vditor);
+ headingElement.remove();
+ }
+ if ((startSpace && blockElement.getAttribute("data-type") !== "code-block")
+ || endSpace || isHeadingMD(blockElement.innerHTML) ||
+ (isHrMD(blockElement.innerHTML) && blockElement.previousElementSibling)) {
+ if (typeof vditor.options.input === "function") {
+ vditor.options.input(getMarkdown(vditor));
+ }
+ return;
+ }
+ // https://github.com/Vanessa219/vditor/issues/1565
+ if (event.inputType === "insertParagraph" && _this.element.innerHTML === '
') {
+ blockElement.previousElementSibling.remove();
+ }
+ input_input(vditor, range, event);
+ });
+ this.element.addEventListener("click", function (event) {
+ if (event.target.tagName === "INPUT") {
+ var checkElement = event.target;
+ if (checkElement.checked) {
+ checkElement.setAttribute("checked", "checked");
+ }
+ else {
+ checkElement.removeAttribute("checked");
+ }
+ _this.preventInput = true;
+ if (getSelection().rangeCount > 0) {
+ (0,selection/* setSelectionFocus */.Hc)(getSelection().getRangeAt(0));
+ }
+ afterRenderEvent(vditor);
+ return;
+ }
+ if (event.target.tagName === "IMG" &&
+ // plantuml 图片渲染不进行提示
+ !event.target.parentElement.classList.contains("vditor-wysiwyg__preview")) {
+ if (event.target.getAttribute("data-type") === "link-ref") {
+ genLinkRefPopover(vditor, event.target);
+ }
+ else {
+ genImagePopover(event, vditor);
+ }
+ return;
+ }
+ // 打开链接
+ var a = (0,hasClosest/* hasClosestByMatchTag */.lG)(event.target, "A");
+ if (a) {
+ if (vditor.options.link.click) {
+ vditor.options.link.click(a);
+ }
+ else if (vditor.options.link.isOpen) {
+ window.open(a.getAttribute("href"));
+ }
+ event.preventDefault();
+ return;
+ }
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ if (event.target.isEqualNode(_this.element) && _this.element.lastElementChild && range.collapsed) {
+ var lastRect = _this.element.lastElementChild.getBoundingClientRect();
+ if (event.y > lastRect.top + lastRect.height) {
+ if (_this.element.lastElementChild.tagName === "P" &&
+ _this.element.lastElementChild.textContent.trim().replace(constants/* Constants.ZWSP */.g.ZWSP, "") === "") {
+ range.selectNodeContents(_this.element.lastElementChild);
+ range.collapse(false);
+ }
+ else {
+ _this.element.insertAdjacentHTML("beforeend", "".concat(constants/* Constants.ZWSP */.g.ZWSP, "
"));
+ (0,selection/* setRangeByWbr */.ib)(_this.element, range);
+ }
+ }
+ }
+ highlightToolbarWYSIWYG(vditor);
+ // 点击后光标落于预览区,需展开代码块
+ var previewElement = (0,hasClosest/* hasClosestByClassName */.fb)(event.target, "vditor-wysiwyg__preview");
+ if (!previewElement) {
+ previewElement =
+ (0,hasClosest/* hasClosestByClassName */.fb)((0,selection/* getEditorRange */.zh)(vditor).startContainer, "vditor-wysiwyg__preview");
+ }
+ if (previewElement) {
+ showCode(previewElement, vditor);
+ }
+ clickToc(event, vditor);
+ });
+ this.element.addEventListener("keyup", function (event) {
+ if (event.isComposing || (0,compatibility/* isCtrl */.yl)(event)) {
+ return;
+ }
+ // 除 md 处理、cell 内换行、table 添加新行/列、代码块语言切换、block render 换行、跳出/逐层跳出 blockquote、h6 换行、
+ // 任务列表换行、软换行外需在换行时调整文档位置
+ if (event.key === "Enter") {
+ scrollCenter(vditor);
+ }
+ if ((event.key === "Backspace" || event.key === "Delete") &&
+ vditor.wysiwyg.element.innerHTML !== "" && vditor.wysiwyg.element.childNodes.length === 1 &&
+ vditor.wysiwyg.element.firstElementChild && vditor.wysiwyg.element.firstElementChild.tagName === "P"
+ && vditor.wysiwyg.element.firstElementChild.childElementCount === 0
+ && (vditor.wysiwyg.element.textContent === "" || vditor.wysiwyg.element.textContent === "\n")) {
+ // 为空时显示 placeholder
+ vditor.wysiwyg.element.innerHTML = "";
+ }
+ var range = (0,selection/* getEditorRange */.zh)(vditor);
+ if (event.key === "Backspace") {
+ // firefox headings https://github.com/Vanessa219/vditor/issues/211
+ if ((0,compatibility/* isFirefox */.vU)() && range.startContainer.textContent === "\n" && range.startOffset === 1) {
+ range.startContainer.textContent = "";
+ }
+ }
+ // 没有被块元素包裹
+ modifyPre(vditor, range);
+ highlightToolbarWYSIWYG(vditor);
+ if (event.key !== "ArrowDown" && event.key !== "ArrowRight" && event.key !== "Backspace"
+ && event.key !== "ArrowLeft" && event.key !== "ArrowUp") {
+ return;
+ }
+ if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
+ vditor.hint.render(vditor);
+ }
+ // 上下左右,删除遇到块预览的处理
+ var previewElement = (0,hasClosest/* hasClosestByClassName */.fb)(range.startContainer, "vditor-wysiwyg__preview");
+ if (!previewElement && range.startContainer.nodeType !== 3 && range.startOffset > 0) {
+ // table 前删除遇到代码块
+ var blockRenderElement = range.startContainer;
+ if (blockRenderElement.classList.contains("vditor-wysiwyg__block")) {
+ previewElement = blockRenderElement.lastElementChild;
+ }
+ }
+ if (!previewElement) {
+ return;
+ }
+ var previousElement = previewElement.previousElementSibling;
+ if (previousElement.style.display === "none") {
+ if (event.key === "ArrowDown" || event.key === "ArrowRight") {
+ showCode(previewElement, vditor);
+ }
+ else {
+ showCode(previewElement, vditor, false);
+ }
+ return;
+ }
+ var codeElement = previewElement.previousElementSibling;
+ if (codeElement.tagName === "PRE") {
+ codeElement = codeElement.firstElementChild;
+ }
+ if (event.key === "ArrowDown" || event.key === "ArrowRight") {
+ var blockRenderElement = previewElement.parentElement;
+ var nextNode = getRenderElementNextNode(blockRenderElement);
+ if (nextNode && nextNode.nodeType !== 3) {
+ // 下一节点依旧为代码渲染块
+ var nextRenderElement = nextNode.querySelector(".vditor-wysiwyg__preview");
+ if (nextRenderElement) {
+ showCode(nextRenderElement, vditor);
+ return;
+ }
+ }
+ // 跳过渲染块,光标移动到下一个节点
+ if (nextNode.nodeType === 3) {
+ // inline
+ while (nextNode.textContent.length === 0 && nextNode.nextSibling) {
+ // https://github.com/Vanessa219/vditor/issues/100 2
+ nextNode = nextNode.nextSibling;
+ }
+ range.setStart(nextNode, 1);
+ }
+ else {
+ // block
+ range.setStart(nextNode.firstChild, 0);
+ }
+ }
+ else {
+ range.selectNodeContents(codeElement);
+ range.collapse(false);
+ }
+ });
+ };
+ return WYSIWYG;
+}());
+
+
+;// CONCATENATED MODULE: ./src/index.ts
+var src_extends = (undefined && undefined.__extends) || (function () {
+ var extendStatics = function (d, b) {
+ extendStatics = Object.setPrototypeOf ||
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
+ return extendStatics(d, b);
+ };
+ return function (d, b) {
+ if (typeof b !== "function" && b !== null)
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
+ extendStatics(d, b);
+ function __() { this.constructor = d; }
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
+ };
+})();
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+var Vditor = /** @class */ (function (_super) {
+ src_extends(Vditor, _super);
+ /**
+ * @param id 要挂载 Vditor 的元素或者元素 ID。
+ * @param options Vditor 参数
+ */
+ function Vditor(id, options) {
+ var _this = _super.call(this) || this;
+ _this.isDestroyed = false;
+ _this.version = constants/* VDITOR_VERSION */.H;
+ if (typeof id === "string") {
+ if (!options) {
+ options = {
+ cache: {
+ id: "vditor".concat(id),
+ },
+ };
+ }
+ else if (!options.cache) {
+ options.cache = { id: "vditor".concat(id) };
+ }
+ else if (!options.cache.id) {
+ options.cache.id = "vditor".concat(id);
+ }
+ if (!document.getElementById(id)) {
+ _this.showErrorTip("Failed to get element by id: ".concat(id));
+ return _this;
+ }
+ id = document.getElementById(id);
+ }
+ var getOptions = new Options(options);
+ var mergedOptions = getOptions.merge();
+ // 支持自定义国际化
+ if (!mergedOptions.i18n) {
+ if (!["de_DE", "en_US", "fr_FR", "pt_BR", "ja_JP", "ko_KR", "ru_RU", "sv_SE", "zh_CN", "zh_TW"].includes(mergedOptions.lang)) {
+ throw new Error("options.lang error, see https://ld246.com/article/1549638745630#options");
+ }
+ else {
+ var i18nScriptPrefix = "vditorI18nScript";
+ var i18nScriptID_1 = i18nScriptPrefix + mergedOptions.lang;
+ document.querySelectorAll("head script[id^=\"".concat(i18nScriptPrefix, "\"]")).forEach(function (el) {
+ if (el.id !== i18nScriptID_1) {
+ document.head.removeChild(el);
+ }
+ });
+ (0,addScript/* addScript */.G)("".concat(mergedOptions.cdn, "/dist/js/i18n/").concat(mergedOptions.lang, ".js"), i18nScriptID_1).then(function () {
+ _this.init(id, mergedOptions);
+ }).catch(function (error) {
+ _this.showErrorTip("GET ".concat(mergedOptions.cdn, "/dist/js/i18n/").concat(mergedOptions.lang, ".js net::ERR_ABORTED 404 (Not Found)"));
+ });
+ }
+ }
+ else {
+ window.VditorI18n = mergedOptions.i18n;
+ _this.init(id, mergedOptions);
+ }
+ return _this;
+ }
+ Vditor.prototype.showErrorTip = function (error) {
+ var tip = new Tip();
+ document.body.appendChild(tip.element);
+ tip.show(error, 0);
+ };
+ Vditor.prototype.updateToolbarConfig = function (options) {
+ this.vditor.toolbar.updateConfig(this.vditor, options);
+ };
+ /** 设置主题 */
+ Vditor.prototype.setTheme = function (theme, contentTheme, codeTheme, contentThemePath) {
+ this.vditor.options.theme = theme;
+ setTheme(this.vditor);
+ if (contentTheme) {
+ this.vditor.options.preview.theme.current = contentTheme;
+ (0,setContentTheme/* setContentTheme */.Z)(contentTheme, contentThemePath || this.vditor.options.preview.theme.path);
+ }
+ if (codeTheme) {
+ this.vditor.options.preview.hljs.style = codeTheme;
+ (0,setCodeTheme/* setCodeTheme */.Y)(codeTheme, this.vditor.options.cdn);
+ }
+ };
+ /** 获取 Markdown 内容 */
+ Vditor.prototype.getValue = function () {
+ return getMarkdown(this.vditor);
+ };
+ /** 获取编辑器当前编辑模式 */
+ Vditor.prototype.getCurrentMode = function () {
+ return this.vditor.currentMode;
+ };
+ /** 聚焦到编辑器 */
+ Vditor.prototype.focus = function () {
+ if (this.vditor.currentMode === "sv") {
+ this.vditor.sv.element.focus();
+ }
+ else if (this.vditor.currentMode === "wysiwyg") {
+ this.vditor.wysiwyg.element.focus();
+ }
+ else if (this.vditor.currentMode === "ir") {
+ this.vditor.ir.element.focus();
+ }
+ };
+ /** 让编辑器失焦 */
+ Vditor.prototype.blur = function () {
+ if (this.vditor.currentMode === "sv") {
+ this.vditor.sv.element.blur();
+ }
+ else if (this.vditor.currentMode === "wysiwyg") {
+ this.vditor.wysiwyg.element.blur();
+ }
+ else if (this.vditor.currentMode === "ir") {
+ this.vditor.ir.element.blur();
+ }
+ };
+ /** 禁用编辑器 */
+ Vditor.prototype.disabled = function () {
+ hidePanel(this.vditor, ["subToolbar", "hint", "popover"]);
+ disableToolbar(this.vditor.toolbar.elements, constants/* Constants.EDIT_TOOLBARS.concat */.g.EDIT_TOOLBARS.concat(["undo", "redo", "fullscreen", "edit-mode"]));
+ this.vditor[this.vditor.currentMode].element.setAttribute("contenteditable", "false");
+ };
+ /** 解除编辑器禁用 */
+ Vditor.prototype.enable = function () {
+ enableToolbar(this.vditor.toolbar.elements, constants/* Constants.EDIT_TOOLBARS.concat */.g.EDIT_TOOLBARS.concat(["undo", "redo", "fullscreen", "edit-mode"]));
+ this.vditor.undo.resetIcon(this.vditor);
+ this.vditor[this.vditor.currentMode].element.setAttribute("contenteditable", "true");
+ };
+ /** 返回选中的字符串 */
+ Vditor.prototype.getSelection = function () {
+ if (this.vditor.currentMode === "wysiwyg") {
+ return getSelectText(this.vditor.wysiwyg.element);
+ }
+ else if (this.vditor.currentMode === "sv") {
+ return getSelectText(this.vditor.sv.element);
+ }
+ else if (this.vditor.currentMode === "ir") {
+ return getSelectText(this.vditor.ir.element);
+ }
+ };
+ /** 设置预览区域内容 */
+ Vditor.prototype.renderPreview = function (value) {
+ this.vditor.preview.render(this.vditor, value);
+ };
+ /** 获取焦点位置 */
+ Vditor.prototype.getCursorPosition = function () {
+ return (0,selection/* getCursorPosition */.Ny)(this.vditor[this.vditor.currentMode].element);
+ };
+ /** 上传是否还在进行中 */
+ Vditor.prototype.isUploading = function () {
+ return this.vditor.upload.isUploading;
+ };
+ /** 清除缓存 */
+ Vditor.prototype.clearCache = function () {
+ if (this.vditor.options.cache.enable && (0,compatibility/* accessLocalStorage */.pK)()) {
+ localStorage.removeItem(this.vditor.options.cache.id);
+ }
+ };
+ /** 禁用缓存 */
+ Vditor.prototype.disabledCache = function () {
+ this.vditor.options.cache.enable = false;
+ };
+ /** 启用缓存 */
+ Vditor.prototype.enableCache = function () {
+ if (!this.vditor.options.cache.id) {
+ throw new Error("need options.cache.id, see https://ld246.com/article/1549638745630#options");
+ }
+ this.vditor.options.cache.enable = true;
+ };
+ /** HTML 转 md */
+ Vditor.prototype.html2md = function (value) {
+ return this.vditor.lute.HTML2Md(value);
+ };
+ /** markdown 转 JSON 输出 */
+ Vditor.prototype.exportJSON = function (value) {
+ return this.vditor.lute.RenderJSON(value);
+ };
+ /** 获取 HTML */
+ Vditor.prototype.getHTML = function () {
+ return getHTML(this.vditor);
+ };
+ /** 消息提示。time 为 0 将一直显示 */
+ Vditor.prototype.tip = function (text, time) {
+ this.vditor.tip.show(text, time);
+ };
+ /** 设置预览模式 */
+ Vditor.prototype.setPreviewMode = function (mode) {
+ setPreviewMode(mode, this.vditor);
+ };
+ /** 删除选中内容 */
+ Vditor.prototype.deleteValue = function () {
+ if (window.getSelection().isCollapsed) {
+ return;
+ }
+ document.execCommand("delete", false);
+ };
+ /** 更新选中内容 */
+ Vditor.prototype.updateValue = function (value) {
+ document.execCommand("insertHTML", false, value);
+ };
+ /** 在焦点处插入内容,并默认进行 Markdown 渲染 */
+ Vditor.prototype.insertValue = function (value, render) {
+ if (render === void 0) { render = true; }
+ var range = (0,selection/* getEditorRange */.zh)(this.vditor);
+ range.collapse(true);
+ // https://github.com/Vanessa219/vditor/issues/716
+ // https://github.com/Vanessa219/vditor/issues/917
+ var tmpElement = document.createElement("template");
+ tmpElement.innerHTML = value;
+ range.insertNode(tmpElement.content.cloneNode(true));
+ range.collapse(false);
+ if (this.vditor.currentMode === "sv") {
+ this.vditor.sv.preventInput = true;
+ if (render) {
+ inputEvent(this.vditor);
+ }
+ }
+ else if (this.vditor.currentMode === "wysiwyg") {
+ // 由于 https://github.com/Vanessa219/vditor/issues/1566 不能使用 this.vditor.wysiwyg.preventInput = true;
+ if (render) {
+ input_input(this.vditor, getSelection().getRangeAt(0));
+ }
+ }
+ else if (this.vditor.currentMode === "ir") {
+ this.vditor.ir.preventInput = true;
+ if (render) {
+ input(this.vditor, getSelection().getRangeAt(0), true);
+ }
+ }
+ };
+ /** 在焦点处插入 Markdown */
+ Vditor.prototype.insertMD = function (md) {
+ // https://github.com/Vanessa219/vditor/issues/1640
+ if (this.vditor.currentMode === "ir") {
+ (0,selection/* insertHTML */.oC)(this.vditor.lute.Md2VditorIRDOM(md), this.vditor);
+ }
+ else if (this.vditor.currentMode === "wysiwyg") {
+ (0,selection/* insertHTML */.oC)(this.vditor.lute.Md2VditorDOM(md), this.vditor);
+ }
+ else {
+ processPaste(this.vditor, md);
+ }
+ this.vditor.outline.render(this.vditor);
+ execAfterRender(this.vditor);
+ };
+ /** 设置编辑器内容 */
+ Vditor.prototype.setValue = function (markdown, clearStack) {
+ var _this = this;
+ if (clearStack === void 0) { clearStack = false; }
+ if (this.vditor.currentMode === "sv") {
+ this.vditor.sv.element.innerHTML = "".concat(this.vditor.lute.SpinVditorSVDOM(markdown), "
");
+ processAfterRender(this.vditor, {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: false,
+ });
+ }
+ else if (this.vditor.currentMode === "wysiwyg") {
+ renderDomByMd(this.vditor, markdown, {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: false,
+ });
+ }
+ else {
+ this.vditor.ir.element.innerHTML = this.vditor.lute.Md2VditorIRDOM(markdown);
+ this.vditor.ir.element
+ .querySelectorAll(".vditor-ir__preview[data-render='2']")
+ .forEach(function (item) {
+ processCodeRender(item, _this.vditor);
+ });
+ process_processAfterRender(this.vditor, {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: false,
+ });
+ }
+ this.vditor.outline.render(this.vditor);
+ if (!markdown) {
+ hidePanel(this.vditor, ["emoji", "headings", "submenu", "hint"]);
+ if (this.vditor.wysiwyg.popover) {
+ this.vditor.wysiwyg.popover.style.display = "none";
+ }
+ this.clearCache();
+ }
+ if (clearStack) {
+ this.clearStack();
+ }
+ };
+ /** 空块 */
+ Vditor.prototype.insertEmptyBlock = function (position) {
+ insertEmptyBlock(this.vditor, position);
+ };
+ /** 清空 undo & redo 栈 */
+ Vditor.prototype.clearStack = function () {
+ this.vditor.undo.clearStack(this.vditor);
+ this.vditor.undo.addToUndoStack(this.vditor);
+ };
+ /** 销毁编辑器 */
+ Vditor.prototype.destroy = function () {
+ this.vditor.element.innerHTML = this.vditor.originalInnerHTML;
+ this.vditor.element.classList.remove("vditor");
+ this.vditor.element.removeAttribute("style");
+ var iconScript = document.getElementById("vditorIconScript");
+ if (iconScript) {
+ iconScript.remove();
+ }
+ this.clearCache();
+ UIUnbindListener();
+ this.vditor.wysiwyg.unbindListener();
+ this.vditor.options.after = undefined;
+ this.isDestroyed = true;
+ };
+ /** 获取评论 ID */
+ Vditor.prototype.getCommentIds = function () {
+ if (this.vditor.currentMode !== "wysiwyg") {
+ return [];
+ }
+ return this.vditor.wysiwyg.getComments(this.vditor, true);
+ };
+ /** 高亮评论 */
+ Vditor.prototype.hlCommentIds = function (ids) {
+ if (this.vditor.currentMode !== "wysiwyg") {
+ return;
+ }
+ var hlItem = function (item) {
+ item.classList.remove("vditor-comment--hover");
+ ids.forEach(function (id) {
+ if (item.getAttribute("data-cmtids").indexOf(id) > -1) {
+ item.classList.add("vditor-comment--hover");
+ }
+ });
+ };
+ this.vditor.wysiwyg.element
+ .querySelectorAll(".vditor-comment")
+ .forEach(function (item) {
+ hlItem(item);
+ });
+ if (this.vditor.preview.element.style.display !== "none") {
+ this.vditor.preview.element
+ .querySelectorAll(".vditor-comment")
+ .forEach(function (item) {
+ hlItem(item);
+ });
+ }
+ };
+ /** 取消评论高亮 */
+ Vditor.prototype.unHlCommentIds = function (ids) {
+ if (this.vditor.currentMode !== "wysiwyg") {
+ return;
+ }
+ var unHlItem = function (item) {
+ ids.forEach(function (id) {
+ if (item.getAttribute("data-cmtids").indexOf(id) > -1) {
+ item.classList.remove("vditor-comment--hover");
+ }
+ });
+ };
+ this.vditor.wysiwyg.element
+ .querySelectorAll(".vditor-comment")
+ .forEach(function (item) {
+ unHlItem(item);
+ });
+ if (this.vditor.preview.element.style.display !== "none") {
+ this.vditor.preview.element
+ .querySelectorAll(".vditor-comment")
+ .forEach(function (item) {
+ unHlItem(item);
+ });
+ }
+ };
+ /** 删除评论 */
+ Vditor.prototype.removeCommentIds = function (removeIds) {
+ var _this = this;
+ if (this.vditor.currentMode !== "wysiwyg") {
+ return;
+ }
+ var removeItem = function (item, removeId) {
+ var ids = item.getAttribute("data-cmtids").split(" ");
+ ids.find(function (id, index) {
+ if (id === removeId) {
+ ids.splice(index, 1);
+ return true;
+ }
+ });
+ if (ids.length === 0) {
+ item.outerHTML = item.innerHTML;
+ (0,selection/* getEditorRange */.zh)(_this.vditor).collapse(true);
+ }
+ else {
+ item.setAttribute("data-cmtids", ids.join(" "));
+ }
+ };
+ removeIds.forEach(function (removeId) {
+ _this.vditor.wysiwyg.element
+ .querySelectorAll(".vditor-comment")
+ .forEach(function (item) {
+ removeItem(item, removeId);
+ });
+ if (_this.vditor.preview.element.style.display !== "none") {
+ _this.vditor.preview.element
+ .querySelectorAll(".vditor-comment")
+ .forEach(function (item) {
+ removeItem(item, removeId);
+ });
+ }
+ });
+ afterRenderEvent(this.vditor, {
+ enableAddUndoStack: true,
+ enableHint: false,
+ enableInput: false,
+ });
+ };
+ Vditor.prototype.init = function (id, mergedOptions) {
+ var _this = this;
+ if (this.isDestroyed) {
+ return;
+ }
+ this.vditor = {
+ currentMode: mergedOptions.mode,
+ element: id,
+ hint: new Hint(mergedOptions.hint.extend),
+ lute: undefined,
+ options: mergedOptions,
+ originalInnerHTML: id.innerHTML,
+ outline: new Outline(window.VditorI18n.outline),
+ tip: new Tip(),
+ };
+ this.vditor.sv = new Editor(this.vditor);
+ this.vditor.undo = new undo_Undo();
+ this.vditor.wysiwyg = new WYSIWYG(this.vditor);
+ this.vditor.ir = new IR(this.vditor);
+ this.vditor.toolbar = new Toolbar(this.vditor);
+ if (mergedOptions.resize.enable) {
+ this.vditor.resize = new Resize(this.vditor);
+ }
+ if (this.vditor.toolbar.elements.devtools) {
+ this.vditor.devtools = new DevTools();
+ }
+ if (mergedOptions.upload.url || mergedOptions.upload.handler) {
+ this.vditor.upload = new Upload();
+ }
+ (0,addScript/* addScript */.G)(mergedOptions._lutePath ||
+ "".concat(mergedOptions.cdn, "/dist/js/lute/lute.min.js"), "vditorLuteScript").then(function () {
+ _this.vditor.lute = (0,setLute/* setLute */.X)({
+ autoSpace: _this.vditor.options.preview.markdown.autoSpace,
+ gfmAutoLink: _this.vditor.options.preview.markdown.gfmAutoLink,
+ codeBlockPreview: _this.vditor.options.preview.markdown
+ .codeBlockPreview,
+ emojiSite: _this.vditor.options.hint.emojiPath,
+ emojis: _this.vditor.options.hint.emoji,
+ fixTermTypo: _this.vditor.options.preview.markdown.fixTermTypo,
+ footnotes: _this.vditor.options.preview.markdown.footnotes,
+ headingAnchor: false,
+ inlineMathDigit: _this.vditor.options.preview.math.inlineDigit,
+ linkBase: _this.vditor.options.preview.markdown.linkBase,
+ linkPrefix: _this.vditor.options.preview.markdown.linkPrefix,
+ listStyle: _this.vditor.options.preview.markdown.listStyle,
+ mark: _this.vditor.options.preview.markdown.mark,
+ mathBlockPreview: _this.vditor.options.preview.markdown
+ .mathBlockPreview,
+ paragraphBeginningSpace: _this.vditor.options.preview.markdown
+ .paragraphBeginningSpace,
+ sanitize: _this.vditor.options.preview.markdown.sanitize,
+ toc: _this.vditor.options.preview.markdown.toc,
+ });
+ _this.vditor.preview = new Preview(_this.vditor);
+ initUI(_this.vditor);
+ if (mergedOptions.after) {
+ mergedOptions.after();
+ }
+ if (mergedOptions.icon) {
+ // 防止初始化 2 个编辑器时加载 2 次
+ (0,addScript/* addScriptSync */.J)("".concat(mergedOptions.cdn, "/dist/js/icons/").concat(mergedOptions.icon, ".js"), "vditorIconScript");
+ }
+ });
+ };
+ return Vditor;
+}(method["default"]));
+/* harmony default export */ const src = (Vditor);
+
+})();
+
+__webpack_exports__ = __webpack_exports__["default"];
+/******/ return __webpack_exports__;
+/******/ })()
+;
+});
\ No newline at end of file
diff --git a/src/components/BootstrapBlazor.Vditor/wwwroot/js/vditor.min.js b/src/components/BootstrapBlazor.Vditor/wwwroot/js/vditor.min.js
new file mode 100644
index 00000000..273950e2
--- /dev/null
+++ b/src/components/BootstrapBlazor.Vditor/wwwroot/js/vditor.min.js
@@ -0,0 +1 @@
+!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Vditor=t():e.Vditor=t()}(this,(function(){return(()=>{var e={173:e=>{var t=function(){this.Diff_Timeout=1,this.Diff_EditCost=4,this.Match_Threshold=.5,this.Match_Distance=1e3,this.Patch_DeleteThreshold=.5,this.Patch_Margin=4,this.Match_MaxBits=32},n=-1;t.Diff=function(e,t){return[e,t]},t.prototype.diff_main=function(e,n,r,i){void 0===i&&(i=this.Diff_Timeout<=0?Number.MAX_VALUE:(new Date).getTime()+1e3*this.Diff_Timeout);var o=i;if(null==e||null==n)throw new Error("Null input. (diff_main)");if(e==n)return e?[new t.Diff(0,e)]:[];void 0===r&&(r=!0);var a=r,s=this.diff_commonPrefix(e,n),l=e.substring(0,s);e=e.substring(s),n=n.substring(s),s=this.diff_commonSuffix(e,n);var c=e.substring(e.length-s);e=e.substring(0,e.length-s),n=n.substring(0,n.length-s);var d=this.diff_compute_(e,n,a,o);return l&&d.unshift(new t.Diff(0,l)),c&&d.push(new t.Diff(0,c)),this.diff_cleanupMerge(d),d},t.prototype.diff_compute_=function(e,r,i,o){var a;if(!e)return[new t.Diff(1,r)];if(!r)return[new t.Diff(n,e)];var s=e.length>r.length?e:r,l=e.length>r.length?r:e,c=s.indexOf(l);if(-1!=c)return a=[new t.Diff(1,s.substring(0,c)),new t.Diff(0,l),new t.Diff(1,s.substring(c+l.length))],e.length>r.length&&(a[0][0]=a[2][0]=n),a;if(1==l.length)return[new t.Diff(n,e),new t.Diff(1,r)];var d=this.diff_halfMatch_(e,r);if(d){var u=d[0],p=d[1],m=d[2],f=d[3],h=d[4],v=this.diff_main(u,m,i,o),g=this.diff_main(p,f,i,o);return v.concat([new t.Diff(0,h)],g)}return i&&e.length>100&&r.length>100?this.diff_lineMode_(e,r,o):this.diff_bisect_(e,r,o)},t.prototype.diff_lineMode_=function(e,r,i){var o=this.diff_linesToChars_(e,r);e=o.chars1,r=o.chars2;var a=o.lineArray,s=this.diff_main(e,r,!1,i);this.diff_charsToLines_(s,a),this.diff_cleanupSemantic(s),s.push(new t.Diff(0,""));for(var l=0,c=0,d=0,u="",p="";l=1&&d>=1){s.splice(l-c-d,c+d),l=l-c-d;for(var m=this.diff_main(u,p,!1,i),f=m.length-1;f>=0;f--)s.splice(l,0,m[f]);l+=m.length}d=0,c=0,u="",p=""}l++}return s.pop(),s},t.prototype.diff_bisect_=function(e,r,i){for(var o=e.length,a=r.length,s=Math.ceil((o+a)/2),l=s,c=2*s,d=new Array(c),u=new Array(c),p=0;pi);y++){for(var w=-y+h;w<=y-v;w+=2){for(var E=l+w,k=(M=w==-y||w!=y&&d[E-1]o)v+=2;else if(k>a)h+=2;else if(f){if((T=l+m-w)>=0&&T=(L=o-u[T]))return this.diff_bisectSplit_(e,r,M,k,i)}}for(var S=-y+g;S<=y-b;S+=2){for(var L,T=l+S,C=(L=S==-y||S!=y&&u[T-1]o)b+=2;else if(C>a)g+=2;else if(!f){if((E=l+m-S)>=0&&E=(L=o-L))return this.diff_bisectSplit_(e,r,M,k,i)}}}}return[new t.Diff(n,e),new t.Diff(1,r)]},t.prototype.diff_bisectSplit_=function(e,t,n,r,i){var o=e.substring(0,n),a=t.substring(0,r),s=e.substring(n),l=t.substring(r),c=this.diff_main(o,a,!1,i),d=this.diff_main(s,l,!1,i);return c.concat(d)},t.prototype.diff_linesToChars_=function(e,t){var n=[],r={};function i(e){for(var t="",i=0,a=-1,s=n.length;ar?e=e.substring(n-r):nt.length?e:t,r=e.length>t.length?t:e;if(n.length<4||2*r.length=e.length?[r,o,a,s,d]:null}var a,s,l,c,d,u=o(n,r,Math.ceil(n.length/4)),p=o(n,r,Math.ceil(n.length/2));return u||p?(a=p?u&&u[4].length>p[4].length?u:p:u,e.length>t.length?(s=a[0],l=a[1],c=a[2],d=a[3]):(c=a[0],d=a[1],s=a[2],l=a[3]),[s,l,c,d,a[4]]):null},t.prototype.diff_cleanupSemantic=function(e){for(var r=!1,i=[],o=0,a=null,s=0,l=0,c=0,d=0,u=0;s0?i[o-1]:-1,l=0,c=0,d=0,u=0,a=null,r=!0)),s++;for(r&&this.diff_cleanupMerge(e),this.diff_cleanupSemanticLossless(e),s=1;s=h?(f>=p.length/2||f>=m.length/2)&&(e.splice(s,0,new t.Diff(0,m.substring(0,f))),e[s-1][1]=p.substring(0,p.length-f),e[s+1][1]=m.substring(f),s++):(h>=p.length/2||h>=m.length/2)&&(e.splice(s,0,new t.Diff(0,p.substring(0,h))),e[s-1][0]=1,e[s-1][1]=m.substring(0,m.length-h),e[s+1][0]=n,e[s+1][1]=p.substring(h),s++),s++}s++}},t.prototype.diff_cleanupSemanticLossless=function(e){function n(e,n){if(!e||!n)return 6;var r=e.charAt(e.length-1),i=n.charAt(0),o=r.match(t.nonAlphaNumericRegex_),a=i.match(t.nonAlphaNumericRegex_),s=o&&r.match(t.whitespaceRegex_),l=a&&i.match(t.whitespaceRegex_),c=s&&r.match(t.linebreakRegex_),d=l&&i.match(t.linebreakRegex_),u=c&&e.match(t.blanklineEndRegex_),p=d&&n.match(t.blanklineStartRegex_);return u||p?5:c||d?4:o&&!s&&l?3:s||l?2:o||a?1:0}for(var r=1;r=p&&(p=m,c=i,d=o,u=a)}e[r-1][1]!=c&&(c?e[r-1][1]=c:(e.splice(r-1,1),r--),e[r][1]=d,u?e[r+1][1]=u:(e.splice(r+1,1),r--))}r++}},t.nonAlphaNumericRegex_=/[^a-zA-Z0-9]/,t.whitespaceRegex_=/\s/,t.linebreakRegex_=/[\r\n]/,t.blanklineEndRegex_=/\n\r?\n$/,t.blanklineStartRegex_=/^\r?\n\r?\n/,t.prototype.diff_cleanupEfficiency=function(e){for(var r=!1,i=[],o=0,a=null,s=0,l=!1,c=!1,d=!1,u=!1;s0?i[o-1]:-1,d=u=!1),r=!0)),s++;r&&this.diff_cleanupMerge(e)},t.prototype.diff_cleanupMerge=function(e){e.push(new t.Diff(0,""));for(var r,i=0,o=0,a=0,s="",l="";i1?(0!==o&&0!==a&&(0!==(r=this.diff_commonPrefix(l,s))&&(i-o-a>0&&0==e[i-o-a-1][0]?e[i-o-a-1][1]+=l.substring(0,r):(e.splice(0,0,new t.Diff(0,l.substring(0,r))),i++),l=l.substring(r),s=s.substring(r)),0!==(r=this.diff_commonSuffix(l,s))&&(e[i][1]=l.substring(l.length-r)+e[i][1],l=l.substring(0,l.length-r),s=s.substring(0,s.length-r))),i-=o+a,e.splice(i,o+a),s.length&&(e.splice(i,0,new t.Diff(n,s)),i++),l.length&&(e.splice(i,0,new t.Diff(1,l)),i++),i++):0!==i&&0==e[i-1][0]?(e[i-1][1]+=e[i][1],e.splice(i,1)):i++,a=0,o=0,s="",l=""}""===e[e.length-1][1]&&e.pop();var c=!1;for(i=1;it));r++)a=i,s=o;return e.length!=r&&e[r][0]===n?s:s+(t-a)},t.prototype.diff_prettyHtml=function(e){for(var t=[],r=/&/g,i=//g,a=/\n/g,s=0;s");switch(l){case 1:t[s]=''+c+"";break;case n:t[s]=''+c+"";break;case 0:t[s]=""+c+""}}return t.join("")},t.prototype.diff_text1=function(e){for(var t=[],n=0;nthis.Match_MaxBits)throw new Error("Pattern too long for this browser.");var r=this.match_alphabet_(t),i=this;function o(e,r){var o=e/t.length,a=Math.abs(n-r);return i.Match_Distance?o+a/i.Match_Distance:a?1:o}var a=this.Match_Threshold,s=e.indexOf(t,n);-1!=s&&(a=Math.min(o(0,s),a),-1!=(s=e.lastIndexOf(t,n+t.length))&&(a=Math.min(o(0,s),a)));var l,c,d=1<=f;g--){var b=r[e.charAt(g-1)];if(v[g]=0===m?(v[g+1]<<1|1)&b:(v[g+1]<<1|1)&b|(u[g+1]|u[g])<<1|1|u[g+1],v[g]&d){var y=o(m,g-1);if(y<=a){if(a=y,!((s=g-1)>n))break;f=Math.max(1,2*n-s)}}}if(o(m+1,n)>a)break;u=v}return s},t.prototype.match_alphabet_=function(e){for(var t={},n=0;n2&&(this.diff_cleanupSemantic(a),this.diff_cleanupEfficiency(a));else if(e&&"object"==typeof e&&void 0===r&&void 0===i)a=e,o=this.diff_text1(a);else if("string"==typeof e&&r&&"object"==typeof r&&void 0===i)o=e,a=r;else{if("string"!=typeof e||"string"!=typeof r||!i||"object"!=typeof i)throw new Error("Unknown call format to patch_make.");o=e,a=i}if(0===a.length)return[];for(var s=[],l=new t.patch_obj,c=0,d=0,u=0,p=o,m=o,f=0;f=2*this.Patch_Margin&&c&&(this.patch_addContext_(l,p),s.push(l),l=new t.patch_obj,c=0,p=m,d=u)}1!==h&&(d+=v.length),h!==n&&(u+=v.length)}return c&&(this.patch_addContext_(l,p),s.push(l)),s},t.prototype.patch_deepCopy=function(e){for(var n=[],r=0;rthis.Match_MaxBits?-1!=(s=this.match_main(t,d.substring(0,this.Match_MaxBits),c))&&(-1==(u=this.match_main(t,d.substring(d.length-this.Match_MaxBits),c+d.length-this.Match_MaxBits))||s>=u)&&(s=-1):s=this.match_main(t,d,c),-1==s)o[a]=!1,i-=e[a].length2-e[a].length1;else if(o[a]=!0,i=s-c,d==(l=-1==u?t.substring(s,s+d.length):t.substring(s,u+this.Match_MaxBits)))t=t.substring(0,s)+this.diff_text2(e[a].diffs)+t.substring(s+d.length);else{var p=this.diff_main(d,l,!1);if(d.length>this.Match_MaxBits&&this.diff_levenshtein(p)/d.length>this.Patch_DeleteThreshold)o[a]=!1;else{this.diff_cleanupSemanticLossless(p);for(var m,f=0,h=0;ha[0][1].length){var s=n-a[0][1].length;a[0][1]=r.substring(a[0][1].length)+a[0][1],o.start1-=s,o.start2-=s,o.length1+=s,o.length2+=s}if(0==(a=(o=e[e.length-1]).diffs).length||0!=a[a.length-1][0])a.push(new t.Diff(0,r)),o.length1+=n,o.length2+=n;else if(n>a[a.length-1][1].length){s=n-a[a.length-1][1].length;a[a.length-1][1]+=r.substring(0,s),o.length1+=s,o.length2+=s}return r},t.prototype.patch_splitMax=function(e){for(var r=this.Match_MaxBits,i=0;i2*r?(c.length1+=p.length,a+=p.length,d=!1,c.diffs.push(new t.Diff(u,p)),o.diffs.shift()):(p=p.substring(0,r-c.length1-this.Patch_Margin),c.length1+=p.length,a+=p.length,0===u?(c.length2+=p.length,s+=p.length):d=!1,c.diffs.push(new t.Diff(u,p)),p==o.diffs[0][1]?o.diffs.shift():o.diffs[0][1]=o.diffs[0][1].substring(p.length))}l=(l=this.diff_text2(c.diffs)).substring(l.length-this.Patch_Margin);var m=this.diff_text1(o.diffs).substring(0,this.Patch_Margin);""!==m&&(c.length1+=m.length,c.length2+=m.length,0!==c.diffs.length&&0===c.diffs[c.diffs.length-1][0]?c.diffs[c.diffs.length-1][1]+=m:c.diffs.push(new t.Diff(0,m))),d||e.splice(++i,0,c)}}},t.prototype.patch_toText=function(e){for(var t=[],n=0;n{"use strict";n.d(t,{default:()=>D});var r=n(135),i=n(840),o=n(775),a=n(428),s=n(325),l=n(483),c=n(999),d=function(e){void 0===e&&(e=document);var t=function(e){var t=document.createElement("img");t.src=e.getAttribute("data-src"),t.addEventListener("load",(function(){e.getAttribute("style")||e.getAttribute("class")||e.getAttribute("width")||e.getAttribute("height")||t.naturalHeight>t.naturalWidth&&t.naturalWidth/t.naturalHeightwindow.innerHeight-40&&(e.style.height=window.innerHeight-40+"px"),e.src=t.src})),e.removeAttribute("data-src")};if(!("IntersectionObserver"in window))return e.querySelectorAll("img").forEach((function(e){e.getAttribute("data-src")&&t(e)})),!1;window.vditorImageIntersectionObserver?(window.vditorImageIntersectionObserver.disconnect(),e.querySelectorAll("img").forEach((function(e){window.vditorImageIntersectionObserver.observe(e)}))):(window.vditorImageIntersectionObserver=new IntersectionObserver((function(e){e.forEach((function(e){(void 0===e.isIntersecting?0!==e.intersectionRatio:e.isIntersecting)&&e.target.getAttribute("data-src")&&t(e.target)}))})),e.querySelectorAll("img").forEach((function(e){window.vditorImageIntersectionObserver.observe(e)})))},u=n(472),p=n(280),m=n(637),f=n(825),h=n(11),v=n(194),g=n(436),b=n(229),y=n(145),w=n(538),E=n(413),k=n(106),S=n(673),L=n(214),T=n(810),C=function(e,t){if(void 0===t&&(t="zh_CN"),"undefined"!=typeof speechSynthesis&&"undefined"!=typeof SpeechSynthesisUtterance){var n=function(){var e,n;return speechSynthesis.getVoices().forEach((function(r){r.lang===t.replace("_","-")&&(e=r),r.default&&(n=r)})),e||(e=n),e},r='',i='';document.getElementById("vditorIconScript")||(r='',i='');var o=document.querySelector(".vditor-speech");o||((o=document.createElement("button")).className="vditor-speech",e.insertAdjacentElement("beforeend",o),void 0!==speechSynthesis.onvoiceschanged&&(speechSynthesis.onvoiceschanged=n));var a=n(),s=new SpeechSynthesisUtterance;s.voice=a,s.onend=s.onerror=function(){o.style.display="none",speechSynthesis.cancel(),o.classList.remove("vditor-speech--current"),o.innerHTML=r},e.addEventListener(void 0!==window.ontouchstart?"touchend":"click",(function(t){var n=t.target;if(n.classList.contains("vditor-speech")||n.parentElement.classList.contains("vditor-speech"))return o.classList.contains("vditor-speech--current")?speechSynthesis.speaking&&(speechSynthesis.paused?(speechSynthesis.resume(),o.innerHTML=i):(speechSynthesis.pause(),o.innerHTML=r)):(s.text=o.getAttribute("data-text"),speechSynthesis.speak(s),o.classList.add("vditor-speech--current"),o.innerHTML=i),(0,T.Hc)(window.vditorSpeechRange),void e.focus();if(o.style.display="none",speechSynthesis.cancel(),o.classList.remove("vditor-speech--current"),o.innerHTML=r,0!==getSelection().rangeCount){var a=getSelection().getRangeAt(0),l=a.toString().trim();if(l){window.vditorSpeechRange=a.cloneRange();var c=a.getBoundingClientRect();o.innerHTML=r,o.style.display="block",o.style.top=c.top+c.height+document.querySelector("html").scrollTop-20+"px",void 0!==window.ontouchstart?o.style.left=t.changedTouches[t.changedTouches.length-1].pageX+2+"px":o.style.left=t.clientX+2+"px",o.setAttribute("data-text",l)}}}))}},M=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))},x=function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]{"use strict";n.d(t,{H:()=>r,g:()=>i});var r="3.11.1",i=function(){function e(){}return e.ZWSP="",e.DROP_EDITOR="application/editor",e.MOBILE_WIDTH=520,e.CLASS_MENU_DISABLED="vditor-menu--disabled",e.EDIT_TOOLBARS=["emoji","headings","bold","italic","strike","link","list","ordered-list","outdent","indent","check","line","quote","code","inline-code","insert-after","insert-before","upload","record","table"],e.CODE_THEME=["a11y-dark","agate","an-old-hope","androidstudio","arta","atom-one-dark","atom-one-dark-reasonable","base16/3024","base16/apathy","base16/apprentice","base16/ashes","base16/atelier-cave","base16/atelier-dune","base16/atelier-estuary","base16/atelier-forest","base16/atelier-heath","base16/atelier-lakeside","base16/atelier-plateau","base16/atelier-savanna","base16/atelier-seaside","base16/atelier-sulphurpool","base16/atlas","base16/bespin","base16/black-metal","base16/black-metal-bathory","base16/black-metal-burzum","base16/black-metal-dark-funeral","base16/black-metal-gorgoroth","base16/black-metal-immortal","base16/black-metal-khold","base16/black-metal-marduk","base16/black-metal-mayhem","base16/black-metal-nile","base16/black-metal-venom","base16/brewer","base16/bright","base16/brogrammer","base16/brush-trees-dark","base16/chalk","base16/circus","base16/classic-dark","base16/codeschool","base16/colors","base16/danqing","base16/darcula","base16/dark-violet","base16/darkmoss","base16/darktooth","base16/decaf","base16/default-dark","base16/dracula","base16/edge-dark","base16/eighties","base16/embers","base16/equilibrium-dark","base16/equilibrium-gray-dark","base16/espresso","base16/eva","base16/eva-dim","base16/flat","base16/framer","base16/gigavolt","base16/google-dark","base16/grayscale-dark","base16/green-screen","base16/gruvbox-dark-hard","base16/gruvbox-dark-medium","base16/gruvbox-dark-pale","base16/gruvbox-dark-soft","base16/hardcore","base16/harmonic16-dark","base16/heetch-dark","base16/helios","base16/hopscotch","base16/horizon-dark","base16/humanoid-dark","base16/ia-dark","base16/icy-dark","base16/ir-black","base16/isotope","base16/kimber","base16/london-tube","base16/macintosh","base16/marrakesh","base16/materia","base16/material","base16/material-darker","base16/material-palenight","base16/material-vivid","base16/mellow-purple","base16/mocha","base16/monokai","base16/nebula","base16/nord","base16/nova","base16/ocean","base16/oceanicnext","base16/onedark","base16/outrun-dark","base16/papercolor-dark","base16/paraiso","base16/pasque","base16/phd","base16/pico","base16/pop","base16/porple","base16/qualia","base16/railscasts","base16/rebecca","base16/ros-pine","base16/ros-pine-moon","base16/sandcastle","base16/seti-ui","base16/silk-dark","base16/snazzy","base16/solar-flare","base16/solarized-dark","base16/spacemacs","base16/summercamp","base16/summerfruit-dark","base16/synth-midnight-terminal-dark","base16/tango","base16/tender","base16/tomorrow-night","base16/twilight","base16/unikitty-dark","base16/vulcan","base16/windows-10","base16/windows-95","base16/windows-high-contrast","base16/windows-nt","base16/woodland","base16/xcode-dusk","base16/zenburn","codepen-embed","dark","devibeans","far","felipec","github-dark","github-dark-dimmed","gml","gradient-dark","hybrid","ir-black","isbl-editor-dark","kimbie-dark","lioshi","monokai","monokai-sublime","night-owl","nnfx-dark","nord","obsidian","panda-syntax-dark","paraiso-dark","pojoaque","qtcreator-dark","rainbow","shades-of-purple","srcery","stackoverflow-dark","sunburst","tomorrow-night-blue","tomorrow-night-bright","tokyo-night-dark","vs2015","xt256","ant-design","a11y-light","arduino-light","ascetic","atom-one-light","base16/atelier-cave-light","base16/atelier-dune-light","base16/atelier-estuary-light","base16/atelier-forest-light","base16/atelier-heath-light","base16/atelier-lakeside-light","base16/atelier-plateau-light","base16/atelier-savanna-light","base16/atelier-seaside-light","base16/atelier-sulphurpool-light","base16/brush-trees","base16/classic-light","base16/cupcake","base16/cupertino","base16/default-light","base16/dirtysea","base16/edge-light","base16/equilibrium-gray-light","base16/equilibrium-light","base16/fruit-soda","base16/github","base16/google-light","base16/grayscale-light","base16/gruvbox-light-hard","base16/gruvbox-light-medium","base16/gruvbox-light-soft","base16/harmonic16-light","base16/heetch-light","base16/humanoid-light","base16/horizon-light","base16/ia-light","base16/material-lighter","base16/mexico-light","base16/one-light","base16/papercolor-light","base16/ros-pine-dawn","base16/sagelight","base16/shapeshifter","base16/silk-light","base16/solar-flare-light","base16/solarized-light","base16/summerfruit-light","base16/synth-midnight-terminal-light","base16/tomorrow","base16/unikitty-light","base16/windows-10-light","base16/windows-95-light","base16/windows-high-contrast-light","brown-paper","base16/windows-nt-light","color-brewer","docco","foundation","github","googlecode","gradient-light","grayscale","idea","intellij-light","isbl-editor-light","kimbie-light","lightfair","magula","mono-blue","nnfx-light","panda-syntax-light","paraiso-light","purebasic","qtcreator-light","routeros","school-book","stackoverflow-light","tokyo-night-light","vs","xcode","default"],e.ALIAS_CODE_LANGUAGES=["abc","plantuml","mermaid","flowchart","echarts","mindmap","graphviz","math","markmap","smiles","js","ts","html","toml","c#","bat"],e.CDN="https://unpkg.com/vditor@".concat("3.11.1"),e.MARKDOWN_OPTIONS={autoSpace:!1,gfmAutoLink:!0,codeBlockPreview:!0,fixTermTypo:!1,footnotes:!0,linkBase:"",linkPrefix:"",listStyle:!1,mark:!1,mathBlockPreview:!0,paragraphBeginningSpace:!1,sanitize:!0,toc:!1},e.HLJS_OPTIONS={enable:!0,lineNumber:!1,defaultLang:"",style:"github"},e.MATH_OPTIONS={engine:"KaTeX",inlineDigit:!1,macros:{}},e.THEME_OPTIONS={current:"light",list:{"ant-design":"Ant Design",dark:"Dark",light:"Light",wechat:"WeChat"},path:"".concat(e.CDN,"/dist/css/content-theme")},e}()},825:(e,t,n)=>{"use strict";n.d(t,{J:()=>s});var r=n(145),i=n(413),o=n(840),a=n(494),s=function(e,t,n){void 0===e&&(e=document),void 0===t&&(t=r.g.CDN);var s=o.SMILESRenderAdapter.getElements(e);s.length>0&&(0,i.G)("".concat(t,"/dist/js/smiles-drawer/smiles-drawer.min.js?v=2.1.7"),"vditorAbcjsScript").then((function(){var e=new SmiDrawer({},{});s.forEach((function(t){var r=o.SMILESRenderAdapter.getCode(t).trim();if("true"!==t.getAttribute("data-processed")&&""!==r.trim()){var i="smiles"+(0,a.Wb)();t.innerHTML=''),e.draw(r,"#"+i,"dark"===n?"dark":void 0),t.setAttribute("data-processed","true")}}))}))}},135:(e,t,n)=>{"use strict";n.d(t,{Q:()=>a});var r=n(145),i=n(413),o=n(840),a=function(e,t){void 0===e&&(e=document),void 0===t&&(t=r.g.CDN);var n=o.abcRenderAdapter.getElements(e);n.length>0&&(0,i.G)("".concat(t,"/dist/js/abcjs/abcjs_basic.min.js"),"vditorAbcjsScript").then((function(){n.forEach((function(e){e.parentElement.classList.contains("vditor-wysiwyg__pre")||e.parentElement.classList.contains("vditor-ir__marker--pre")||"true"!==e.getAttribute("data-processed")&&(ABCJS.renderAbc(e,o.abcRenderAdapter.getCode(e).trim()),e.style.overflowX="auto",e.setAttribute("data-processed","true"))}))}))}},840:(e,t,n)=>{"use strict";n.r(t),n.d(t,{mathRenderAdapter:()=>r,SMILESRenderAdapter:()=>i,mermaidRenderAdapter:()=>o,markmapRenderAdapter:()=>a,mindmapRenderAdapter:()=>s,chartRenderAdapter:()=>l,abcRenderAdapter:()=>c,graphvizRenderAdapter:()=>d,flowchartRenderAdapter:()=>u,plantumlRenderAdapter:()=>p});var r={getCode:function(e){return e.textContent},getElements:function(e){return e.querySelectorAll(".language-math")}},i={getCode:function(e){return e.textContent},getElements:function(e){return e.querySelectorAll(".language-smiles")}},o={getCode:function(e){return e.textContent},getElements:function(e){return e.querySelectorAll(".language-mermaid")}},a={getCode:function(e){return e.textContent},getElements:function(e){return e.querySelectorAll(".language-markmap")}},s={getCode:function(e){return e.getAttribute("data-code")},getElements:function(e){return e.querySelectorAll(".language-mindmap")}},l={getCode:function(e){return e.innerText},getElements:function(e){return e.querySelectorAll(".language-echarts")}},c={getCode:function(e){return e.textContent},getElements:function(e){return e.querySelectorAll(".language-abc")}},d={getCode:function(e){return e.textContent},getElements:function(e){return e.querySelectorAll(".language-graphviz")}},u={getCode:function(e){return e.textContent},getElements:function(e){return e.querySelectorAll(".language-flowchart")}},p={getCode:function(e){return e.textContent},getElements:function(e){return e.querySelectorAll(".language-plantuml")}}},775:(e,t,n)=>{"use strict";n.d(t,{p:()=>c});var r=n(145),i=n(413),o=n(840),a=n(494),s=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))},l=function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]0&&(0,i.G)("".concat(t,"/dist/js/echarts/echarts.min.js?v=5.5.1"),"vditorEchartsScript").then((function(){c.forEach((function(e){return s(void 0,void 0,void 0,(function(){var t,r,i;return l(this,(function(s){switch(s.label){case 0:if(e.parentElement.classList.contains("vditor-wysiwyg__pre")||e.parentElement.classList.contains("vditor-ir__marker--pre"))return[2];if(!(t=o.chartRenderAdapter.getCode(e).trim()))return[2];s.label=1;case 1:return s.trys.push([1,3,,4]),"true"===e.getAttribute("data-processed")?[2]:[4,(0,a.Qf)(t)];case 2:return r=s.sent(),echarts.init(e,"dark"===n?"dark":void 0).setOption(r),e.setAttribute("data-processed","true"),[3,4];case 3:return i=s.sent(),e.className="vditor-reset--error",e.innerHTML="echarts render error:
".concat(i),[3,4];case 4:return[2]}}))}))}))}))}},428:(e,t,n)=>{"use strict";n.d(t,{O:()=>o});var r=n(105),i=n(145),o=function(e,t){Array.from(e.querySelectorAll("pre > code")).filter((function(t,n){return!t.parentElement.classList.contains("vditor-wysiwyg__pre")&&!t.parentElement.classList.contains("vditor-ir__marker--pre")&&(!(t.classList.contains("language-mermaid")||t.classList.contains("language-flowchart")||t.classList.contains("language-echarts")||t.classList.contains("language-mindmap")||t.classList.contains("language-plantuml")||t.classList.contains("language-markmap")||t.classList.contains("language-abc")||t.classList.contains("language-graphviz")||t.classList.contains("language-math")||t.classList.contains("language-smiles"))&&(!(t.style.maxHeight.indexOf("px")>-1)&&!(e.classList.contains("vditor-preview")&&n>5)))})).forEach((function(e){var n,o,a,s=e.innerText;if(e.classList.contains("highlight-chroma")){var l=e.cloneNode(!0);l.querySelectorAll(".highlight-ln").forEach((function(e){e.remove()})),s=l.innerText}else s.endsWith("\n")&&(s=s.substr(0,s.length-1));var c='';document.getElementById("vditorIconScript")||(c='');var d=document.createElement("div");d.className="vditor-copy",d.innerHTML='").concat(c,"");var u=document.createElement("textarea");u.value=(0,r.X)(s),d.insertAdjacentElement("afterbegin",u),t&&t.renderMenu&&t.renderMenu(e,d),e.before(d),e.style.maxHeight=window.outerHeight-40+"px",e.insertAdjacentHTML("afterend",''.concat(i.g.ZWSP,""))}))}},325:(e,t,n)=>{"use strict";n.d(t,{P:()=>a});var r=n(145),i=n(413),o=n(840),a=function(e,t){void 0===t&&(t=r.g.CDN);var n=o.flowchartRenderAdapter.getElements(e);0!==n.length&&(0,i.G)("".concat(t,"/dist/js/flowchart.js/flowchart.min.js"),"vditorFlowchartScript").then((function(){n.forEach((function(e){if("true"!==e.getAttribute("data-processed")){var t=flowchart.parse(o.flowchartRenderAdapter.getCode(e));e.innerHTML="",t.drawSVG(e),e.setAttribute("data-processed","true")}}))}))}},483:(e,t,n)=>{"use strict";n.d(t,{v:()=>a});var r=n(145),i=n(413),o=n(840),a=function(e,t){void 0===t&&(t=r.g.CDN);var n=o.graphvizRenderAdapter.getElements(e);0!==n.length&&(0,i.G)("".concat(t,"/dist/js/graphviz/viz.js"),"vditorGraphVizScript").then((function(){n.forEach((function(e){var t=o.graphvizRenderAdapter.getCode(e);if(!e.parentElement.classList.contains("vditor-wysiwyg__pre")&&!e.parentElement.classList.contains("vditor-ir__marker--pre")&&"true"!==e.getAttribute("data-processed")&&""!==t.trim()){try{var n=new Blob(["importScripts('".concat(document.getElementById("vditorGraphVizScript").src.replace("viz.js","full.render.js"),"');")],{type:"application/javascript"}),r=(window.URL||window.webkitURL).createObjectURL(n),i=new Worker(r);new Viz({worker:i}).renderSVGElement(t).then((function(t){e.innerHTML=t.outerHTML})).catch((function(t){e.innerHTML="graphviz render error:
".concat(t),e.className="vditor-reset--error"}))}catch(e){console.error("graphviz error",e)}e.setAttribute("data-processed","true")}}))}))}},999:(e,t,n)=>{"use strict";n.d(t,{s:()=>a});var r=n(145),i=n(413),o=n(290),a=function(e,t,n){void 0===t&&(t=document),void 0===n&&(n=r.g.CDN);var a=e.style;r.g.CODE_THEME.includes(a)||(a="github");var s=document.getElementById("vditorHljsStyle"),l="".concat(n,"/dist/js/highlight.js/styles/").concat(a,".min.css");(s&&s.getAttribute("href")!==l&&s.remove(),(0,o.c)("".concat(n,"/dist/js/highlight.js/styles/").concat(a,".min.css"),"vditorHljsStyle"),!1!==e.enable)&&(0!==t.querySelectorAll("pre > code").length&&(0,i.G)("".concat(n,"/dist/js/highlight.js/highlight.min.js?v=11.7.0"),"vditorHljsScript").then((function(){(0,i.G)("".concat(n,"/dist/js/highlight.js/third-languages.js?v=1.0.1"),"vditorHljsThirdScript").then((function(){t.querySelectorAll("pre > code").forEach((function(t){if(!t.parentElement.classList.contains("vditor-ir__marker--pre")&&!t.parentElement.classList.contains("vditor-wysiwyg__pre")&&!(t.classList.contains("language-mermaid")||t.classList.contains("language-flowchart")||t.classList.contains("language-echarts")||t.classList.contains("language-mindmap")||t.classList.contains("language-plantuml")||t.classList.contains("language-smiles")||t.classList.contains("language-abc")||t.classList.contains("language-graphviz")||t.classList.contains("language-math"))){""!==e.defaultLang&&-1===t.className.indexOf("language-")&&t.classList.add("language-"+e.defaultLang);var n=t.className.replace("language-","");if(window.hljs.getLanguage(n)||(n="plaintext"),t.innerHTML=window.hljs.highlight(t.textContent,{language:n,ignoreIllegals:!0}).value,t.classList.add("hljs"),e.lineNumber){t.classList.add("vditor-linenumber");var r=t.querySelector(".vditor-linenumber__temp");r||((r=document.createElement("div")).className="vditor-linenumber__temp",t.insertAdjacentElement("beforeend",r));var i=getComputedStyle(t).whiteSpace,o=!1;"pre-wrap"!==i&&"pre-line"!==i||(o=!0);var a="",s=t.textContent.split(/\r\n|\r|\n/g);s.pop(),s.map((function(e){var t="";o&&(r.textContent=e||"\n",t=' style="height:'.concat(r.getBoundingClientRect().height,'px"')),a+="")})),r.style.display="none",a=''.concat(a,""),t.insertAdjacentHTML("beforeend",a)}}}))}))})))}},11:(e,t,n)=>{"use strict";n.d(t,{K:()=>l});var r=n(145),i=n(413),o=n(840),a={},s=function(e,t){var n=window.markmap,r=n.Transformer,i=n.Markmap,o=n.deriveOptions,s=(n.globalCSS,new r);e.innerHTML='';var l=e.firstChild,c=i.create(l,null),d=function(e,t){var n=e.transform(t),r=Object.keys(n.features).filter((function(e){return!a[e]}));r.forEach((function(e){a[e]=!0}));var i=e.getAssets(r),o=i.styles,s=i.scripts,l=window.markmap;return o&&l.loadCSS(o),s&&l.loadJS(s),n}(s,t),u=d.root,p=d.frontmatter,m=o(null==p?void 0:p.markmap);c.setData(u,m),c.fit()},l=function(e,t){void 0===e&&(e=document),void 0===t&&(t=r.g.CDN);var n=o.markmapRenderAdapter.getElements(e);0!==n.length&&(0,i.G)("".concat(t,"/dist/js/markmap/markmap.min.js"),"vditorMarkerScript").then((function(){n.forEach((function(e){var t=o.markmapRenderAdapter.getCode(e);if("true"!==e.getAttribute("data-processed")&&""!==t.trim()){var n=document.createElement("div");n.className="language-markmap",e.parentNode.appendChild(n),s(n,t),"CODE"==e.parentNode.childNodes[0].nodeName&&e.parentNode.removeChild(e.parentNode.childNodes[0])}}))}))}},472:(e,t,n)=>{"use strict";n.d(t,{H:()=>l});var r=n(145),i=n(413),o=n(290),a=n(105),s=n(840),l=function(e,t){void 0===e&&(e=document);var n=s.mathRenderAdapter.getElements(e);if(0!==n.length){var l={cdn:r.g.CDN,math:{engine:"KaTeX",inlineDigit:!1,macros:{}}};if(t&&t.math&&(t.math=Object.assign({},l.math,t.math)),"KaTeX"===(t=Object.assign({},l,t)).math.engine)(0,o.c)("".concat(t.cdn,"/dist/js/katex/katex.min.css?v=0.16.9"),"vditorKatexStyle"),(0,i.G)("".concat(t.cdn,"/dist/js/katex/katex.min.js?v=0.16.9"),"vditorKatexScript").then((function(){(0,i.G)("".concat(t.cdn,"/dist/js/katex/mhchem.min.js?v=0.16.9"),"vditorKatexChemScript").then((function(){n.forEach((function(e){if(!e.parentElement.classList.contains("vditor-wysiwyg__pre")&&!e.parentElement.classList.contains("vditor-ir__marker--pre")&&!e.getAttribute("data-math")){var n=(0,a.X)(s.mathRenderAdapter.getCode(e));e.setAttribute("data-math",n);try{e.innerHTML=katex.renderToString(n,{displayMode:"DIV"===e.tagName,output:"html",macros:t.math.macros})}catch(t){e.innerHTML=t.message,e.className="language-math vditor-reset--error"}e.addEventListener("copy",(function(e){e.stopPropagation(),e.preventDefault();var t=e.currentTarget.closest(".language-math");e.clipboardData.setData("text/html",t.innerHTML),e.clipboardData.setData("text/plain",t.getAttribute("data-math"))}))}}))}))}));else if("MathJax"===t.math.engine){window.MathJax||(window.MathJax={loader:{paths:{mathjax:"".concat(t.cdn,"/dist/js/mathjax")}},startup:{typeset:!1},tex:{macros:t.math.macros}},Object.assign(window.MathJax,t.math.mathJaxOptions)),(0,i.J)("".concat(t.cdn,"/dist/js/mathjax/tex-svg-full.js"),"protyleMathJaxScript");var c=function(e,t){var n=(0,a.X)(e.textContent).trim(),r=window.MathJax.getMetricsFor(e);r.display="DIV"===e.tagName,window.MathJax.tex2svgPromise(n,r).then((function(r){e.innerHTML="",e.setAttribute("data-math",n),e.append(r),window.MathJax.startup.document.clear(),window.MathJax.startup.document.updateDocument();var i=r.querySelector('[data-mml-node="merror"]');i&&""!==i.textContent.trim()&&(e.innerHTML=i.textContent.trim(),e.className="vditor-reset--error"),t&&t()}))};window.MathJax.startup.promise.then((function(){for(var e=[],t=function(t){var r=n[t];r.parentElement.classList.contains("vditor-wysiwyg__pre")||r.parentElement.classList.contains("vditor-ir__marker--pre")||r.getAttribute("data-math")||!(0,a.X)(r.textContent).trim()||e.push((function(e){t===n.length-1?c(r):c(r,e)}))},r=0;r{"use strict";n.d(t,{Y:()=>i});var r=n(494),i=function(e){e&&e.querySelectorAll("a").forEach((function(e){var t=e.getAttribute("href");t&&(t.match(/^.+.(mp4|m4v|ogg|ogv|webm)$/)?function(e,t){e.insertAdjacentHTML("afterend",'')),e.remove()}(e,t):t.match(/^.+.(mp3|wav|flac)$/)?function(e,t){e.insertAdjacentHTML("afterend",'')),e.remove()}(e,t):function(e,t){var n=t.match(/\/\/(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w|-]{11})(?:(?:[\?&]t=)(\S+))?/),i=t.match(/\/\/v\.youku\.com\/v_show\/id_(\w+)=*\.html/),o=t.match(/\/\/v\.qq\.com\/x\/cover\/.*\/([^\/]+)\.html\??.*/),a=t.match(/(?:www\.|\/\/)coub\.com\/view\/(\w+)/),s=t.match(/(?:www\.|\/\/)facebook\.com\/([^\/]+)\/videos\/([0-9]+)/),l=t.match(/.+dailymotion.com\/(video|hub)\/(\w+)\?/),c=t.match(/(?:www\.|\/\/)bilibili\.com\/video\/(\w+)/),d=t.match(/(?:www\.|\/\/)ted\.com\/talks\/(\w+)/);if(n&&11===n[1].length)e.insertAdjacentHTML("afterend",'')),e.remove();else if(i&&i[1])e.insertAdjacentHTML("afterend",'')),e.remove();else if(o&&o[1])e.insertAdjacentHTML("afterend",'')),e.remove();else if(a&&a[1])e.insertAdjacentHTML("afterend",'')),e.remove();else if(s&&s[0])e.insertAdjacentHTML("afterend",'')),e.remove();else if(l&&l[2])e.insertAdjacentHTML("afterend",'')),e.remove();else if(t.indexOf("bilibili.com")>-1&&(t.indexOf("bvid=")>-1||c&&c[1])){var u={bvid:(0,r.on)("bvid",t)||c&&c[1],page:"1",high_quality:"1",as_wide:"1",allowfullscreen:"true",autoplay:"0"};new URL(t.startsWith("http")?t:"https:"+t).search.split("&").forEach((function(e,t){if(e){0===t&&(e=e.substr(1));var n=e.split("=");u[n[0]]=n[1]}}));var p="https://player.bilibili.com/player.html?",m=Object.keys(u);m.forEach((function(e,t){p+="".concat(e,"=").concat(u[e]),t')),e.remove()}else d&&d[1]&&(e.insertAdjacentHTML("afterend",'')),e.remove())}(e,t))}))}},637:(e,t,n)=>{"use strict";n.d(t,{i:()=>c});var r=n(145),i=n(413),o=n(840),a=n(494),s=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))},l=function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]\n').concat(i.message.replace(/\n/,"
"),"
"),s.parentElement.remove(),[3,4];case 4:return e.setAttribute("data-processed","true"),[2]}}))}))}))}))}},194:(e,t,n)=>{"use strict";n.d(t,{P:()=>a});var r=n(145),i=n(413),o=n(840),a=function(e,t,n){void 0===e&&(e=document),void 0===t&&(t=r.g.CDN);var a=o.mindmapRenderAdapter.getElements(e);a.length>0&&(0,i.G)("".concat(t,"/dist/js/echarts/echarts.min.js?v=5.5.1"),"vditorEchartsScript").then((function(){a.forEach((function(e){if(!e.parentElement.classList.contains("vditor-wysiwyg__pre")&&!e.parentElement.classList.contains("vditor-ir__marker--pre")){var t=o.mindmapRenderAdapter.getCode(e);if(t)try{if("true"===e.getAttribute("data-processed"))return;echarts.init(e,"dark"===n?"dark":void 0).setOption({series:[{data:[JSON.parse(decodeURIComponent(t))],initialTreeDepth:-1,itemStyle:{borderWidth:0,color:"#4285f4"},label:{backgroundColor:"#f6f8fa",borderColor:"#d1d5da",borderRadius:5,borderWidth:.5,color:"#586069",lineHeight:20,offset:[-5,0],padding:[0,5],position:"insideRight"},lineStyle:{color:"#d1d5da",width:1},roam:!0,symbol:function(e,t){var n;return(null===(n=null==t?void 0:t.data)||void 0===n?void 0:n.children)?"circle":"path://"},type:"tree"}],tooltip:{trigger:"item",triggerOn:"mousemove"}}),e.setAttribute("data-processed","true")}catch(t){e.className="vditor-reset--error",e.innerHTML="mindmap render error:
".concat(t)}}}))}))}},436:(e,t,n)=>{"use strict";n.d(t,{k:()=>o});var r=n(771),i=n(472),o=function(e,t,n){var o="",a=[];if(Array.from(e.children).forEach((function(e,t){if((0,r.W)(e)){if(n){var i=e.id.lastIndexOf("_");e.id=e.id.substring(0,-1===i?void 0:i)+"_"+t}a.push(e.id),o+=e.outerHTML.replace("","")}})),""===o)return t.innerHTML="","";var s=document.createElement("div");if(n)n.lute.SetToC(!0),"wysiwyg"!==n.currentMode||n.preview.element.contains(e)?"ir"!==n.currentMode||n.preview.element.contains(e)?s.innerHTML=n.lute.HTML2VditorDOM("[ToC]
"+o):s.innerHTML=n.lute.SpinVditorIRDOM("[ToC]
"+o):s.innerHTML=n.lute.SpinVditorDOM("[ToC]
"+o),n.lute.SetToC(n.options.preview.markdown.toc);else{t.classList.add("vditor-outline");var l=Lute.New();l.SetToC(!0),s.innerHTML=l.HTML2VditorDOM("[ToC]
"+o)}var c=s.firstElementChild.querySelectorAll("li > span[data-target-id]");return c.forEach((function(e,t){if(e.nextElementSibling&&"UL"===e.nextElementSibling.tagName){var n="";document.getElementById("vditorIconScript")||(n=''),e.innerHTML="".concat(n,"").concat(e.innerHTML,"")}else e.innerHTML="".concat(e.innerHTML,"");e.setAttribute("data-target-id",a[t])})),o=s.firstElementChild.innerHTML,0===c.length?(t.innerHTML="",o):(t.innerHTML=o,n&&(0,i.H)(t,{cdn:n.options.cdn,math:n.options.preview.math}),t.firstElementChild.addEventListener("click",(function(r){for(var i=r.target;i&&!i.isEqualNode(t);){if(i.classList.contains("vditor-outline__action")){i.classList.contains("vditor-outline__action--close")?(i.classList.remove("vditor-outline__action--close"),i.parentElement.nextElementSibling.setAttribute("style","display:block")):(i.classList.add("vditor-outline__action--close"),i.parentElement.nextElementSibling.setAttribute("style","display:none")),r.preventDefault(),r.stopPropagation();break}if(i.getAttribute("data-target-id")){r.preventDefault(),r.stopPropagation();var o=document.getElementById(i.getAttribute("data-target-id"));if(!o)return;if(n)if("auto"===n.options.height){var a=o.offsetTop+n.element.offsetTop;n.options.toolbarConfig.pin||(a+=n.toolbar.element.offsetHeight),window.scrollTo(window.scrollX,a)}else n.element.offsetTop{"use strict";n.d(t,{B:()=>a});var r=n(145),i=n(413),o=n(840),a=function(e,t){void 0===e&&(e=document),void 0===t&&(t=r.g.CDN);var n=o.plantumlRenderAdapter.getElements(e);0!==n.length&&(0,i.G)("".concat(t,"/dist/js/plantuml/plantuml-encoder.min.js"),"vditorPlantumlScript").then((function(){n.forEach((function(e){if(!e.parentElement.classList.contains("vditor-wysiwyg__pre")&&!e.parentElement.classList.contains("vditor-ir__marker--pre")){var t=o.plantumlRenderAdapter.getCode(e).trim();if(t)try{e.innerHTML='')}catch(t){e.className="vditor-reset--error",e.innerHTML="plantuml render error:
".concat(t)}}}))}))}},214:(e,t,n)=>{"use strict";n.d(t,{X:()=>r});var r=function(e){var t=Lute.New();return t.PutEmojis(e.emojis),t.SetEmojiSite(e.emojiSite),t.SetHeadingAnchor(e.headingAnchor),t.SetInlineMathAllowDigitAfterOpenMarker(e.inlineMathDigit),t.SetAutoSpace(e.autoSpace),t.SetToC(e.toc),t.SetFootnotes(e.footnotes),t.SetFixTermTypo(e.fixTermTypo),t.SetVditorCodeBlockPreview(e.codeBlockPreview),t.SetVditorMathBlockPreview(e.mathBlockPreview),t.SetSanitize(e.sanitize),t.SetChineseParagraphBeginningSpace(e.paragraphBeginningSpace),t.SetRenderListStyle(e.listStyle),t.SetLinkBase(e.linkBase),t.SetLinkPrefix(e.linkPrefix),t.SetMark(e.mark),t.SetGFMAutoLink(e.gfmAutoLink),e.lazyLoadImage&&t.SetImageLazyLoading(e.lazyLoadImage),t}},190:(e,t,n)=>{"use strict";n.d(t,{E:()=>r});var r=function(e,t,n){void 0===t&&(t="zh_CN"),void 0===n&&(n="classic");var r=e.getBoundingClientRect();document.body.insertAdjacentHTML("beforeend",'\n
\n \n \n ').concat(window.VditorI18n.spin,"\n \n \n X ").concat(window.VditorI18n.close,'\n \n
\n
\n
.concat(e.getAttribute()
\n
\n
')),document.body.style.overflow="hidden";var i=document.querySelector(".vditor-img img"),o="translate3d(".concat(Math.max(0,window.innerWidth-e.naturalWidth)/2,"px, ").concat(Math.max(0,window.innerHeight-36-e.naturalHeight)/2,"px, 0)");setTimeout((function(){i.setAttribute("style","transition: transform .3s ease-in-out;transform: ".concat(o)),setTimeout((function(){i.parentElement.scrollTo((i.parentElement.scrollWidth-i.parentElement.clientWidth)/2,(i.parentElement.scrollHeight-i.parentElement.clientHeight)/2)}),400)}));var a=document.querySelector(".vditor-img__btn");a.addEventListener("click",(function(){var t=parseInt(a.getAttribute("data-deg"),10)+90;t/90%2==1&&e.naturalWidth>i.parentElement.clientHeight?i.style.transform="translate3d(".concat(Math.max(0,window.innerWidth-e.naturalWidth)/2,"px, ").concat(e.naturalWidth/2-e.naturalHeight/2,"px, 0) rotateZ(").concat(t,"deg)"):i.style.transform="".concat(o," rotateZ(").concat(t,"deg)"),a.setAttribute("data-deg",t.toString()),setTimeout((function(){i.parentElement.scrollTo((i.parentElement.scrollWidth-i.parentElement.clientWidth)/2,(i.parentElement.scrollHeight-i.parentElement.clientHeight)/2)}),400)}))}},580:(e,t,n)=>{"use strict";n.d(t,{Y:()=>o});var r=n(145),i=n(290),o=function(e,t){void 0===t&&(t=r.g.CDN),r.g.CODE_THEME.includes(e)||(e="github");var n=document.getElementById("vditorHljsStyle"),o="".concat(t,"/dist/js/highlight.js/styles/").concat(e,".min.css");n?n.getAttribute("href")!==o&&(n.remove(),(0,i.c)(o,"vditorHljsStyle")):(0,i.c)(o,"vditorHljsStyle")}},538:(e,t,n)=>{"use strict";n.d(t,{Z:()=>i});var r=n(290),i=function(e,t){if(e&&t){var n=document.getElementById("vditorContentTheme"),i="".concat(t,"/").concat(e,".css");n?n.getAttribute("href")!==i&&(n.remove(),(0,r.c)(i,"vditorContentTheme")):(0,r.c)(i,"vditorContentTheme")}}},413:(e,t,n)=>{"use strict";n.d(t,{J:()=>r,G:()=>i});var r=function(e,t){if(document.getElementById(t))return!1;var n=new XMLHttpRequest;n.open("GET",e,!1),n.setRequestHeader("Accept","text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01"),n.send("");var r=document.createElement("script");r.type="text/javascript",r.text=n.responseText,r.id=t,document.head.appendChild(r)},i=function(e,t){return new Promise((function(n,r){if(document.getElementById(t))return n(!0),!1;var i=document.createElement("script");i.src=e,i.async=!0,document.head.appendChild(i),i.onerror=function(e){r(e)},i.onload=function(){if(document.getElementById(t))return i.remove(),n(!0),!1;i.id=t,n(!0)}}))}},290:(e,t,n)=>{"use strict";n.d(t,{c:()=>r});var r=function(e,t){if(!document.getElementById(t)){var n=document.createElement("link");n.id=t,n.rel="stylesheet",n.type="text/css",n.href=e,document.getElementsByTagName("head")[0].appendChild(n)}}},105:(e,t,n)=>{"use strict";n.d(t,{X:()=>r});var r=function(e){return e.replace(/\u00a0/g," ")}},410:(e,t,n)=>{"use strict";n.d(t,{G6:()=>r,vU:()=>i,pK:()=>o,Le:()=>a,yl:()=>s,ns:()=>l,i7:()=>c});var r=function(){return navigator.userAgent.indexOf("Safari")>-1&&-1===navigator.userAgent.indexOf("Chrome")},i=function(){return navigator.userAgent.toLowerCase().indexOf("firefox")>-1},o=function(){try{return"undefined"!=typeof localStorage}catch(e){return!1}},a=function(){return navigator.userAgent.indexOf("iPhone")>-1?"touchstart":"click"},s=function(e){return navigator.platform.toUpperCase().indexOf("MAC")>=0?!(!e.metaKey||e.ctrlKey):!(e.metaKey||!e.ctrlKey)},l=function(e){return/Mac/.test(navigator.platform)||"iPhone"===navigator.platform?e.indexOf("⇧")>-1&&i()&&(e=e.replace(";",":").replace("=","+").replace("-","_")):(e=(e=e.startsWith("⌘")?e.replace("⌘","⌘+"):e.startsWith("⌥")&&"⌘"!==e.substr(1,1)?e.replace("⌥","⌥+"):e.replace("⇧⌘","⌘+⇧+").replace("⌥⌘","⌥+⌘+")).replace("⌘","Ctrl").replace("⇧","Shift").replace("⌥","Alt")).indexOf("Shift")>-1&&(e=e.replace(";",":").replace("=","+").replace("-","_")),e},c=function(){return/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)}},494:(e,t,n)=>{"use strict";n.d(t,{Wb:()=>r,on:()=>i,Qf:()=>o});var r=function(){return([1e7].toString()+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(function(e){return(parseInt(e,10)^window.crypto.getRandomValues(new Uint32Array(1))[0]&15>>parseInt(e,10)/4).toString(16)}))},i=function(e,t){void 0===t&&(t=window.location.search);var n=t.substring(t.indexOf("?")),r=n.indexOf("#");return new URLSearchParams(n.substring(0,r>=0?r:void 0)).get(e)},o=function(e){return Function('"use strict";return ('.concat(e,")"))()}},106:(e,t,n)=>{"use strict";n.d(t,{JQ:()=>i,E2:()=>o,O9:()=>a,a1:()=>s,F9:()=>l,lG:()=>c,fb:()=>d,DX:()=>u});var r=n(771),i=function(e,t){for(var n=d(e,t),r=!1,i=!1;n&&!n.classList.contains("vditor-reset")&&!i;)(r=d(n.parentElement,t))?n=r:i=!0;return n||!1},o=function(e,t){for(var n=(0,r.S)(e,t),i=!1,o=!1;n&&!n.classList.contains("vditor-reset")&&!o;)(i=(0,r.S)(n.parentElement,t))?n=i:o=!0;return n||!1},a=function(e){var t=o(e,"UL"),n=o(e,"OL"),r=t;return n&&(!t||t&&n.contains(t))&&(r=n),r},s=function(e,t,n){if(!e)return!1;3===e.nodeType&&(e=e.parentElement);for(var r=e,i=!1;r&&!i&&!r.classList.contains("vditor-reset");)r.getAttribute(t)===n?i=!0:r=r.parentElement;return i&&r},l=function(e){if(!e)return!1;3===e.nodeType&&(e=e.parentElement);var t=e,n=!1,r=s(e,"data-block","0");if(r)return r;for(;t&&!n&&!t.classList.contains("vditor-reset");)"H1"===t.tagName||"H2"===t.tagName||"H3"===t.tagName||"H4"===t.tagName||"H5"===t.tagName||"H6"===t.tagName||"P"===t.tagName||"BLOCKQUOTE"===t.tagName||"OL"===t.tagName||"UL"===t.tagName?n=!0:t=t.parentElement;return n&&t},c=function(e,t){if(!e)return!1;3===e.nodeType&&(e=e.parentElement);for(var n=e,r=!1;n&&!r&&!n.classList.contains("vditor-reset");)n.nodeName===t?r=!0:n=n.parentElement;return r&&n},d=function(e,t){if(!e)return!1;3===e.nodeType&&(e=e.parentElement);for(var n=e,r=!1;n&&!r&&!n.classList.contains("vditor-reset");)n.classList.contains(t)?r=!0:n=n.parentElement;return r&&n},u=function(e){for(;e&&e.lastChild;)e=e.lastChild;return e}},771:(e,t,n)=>{"use strict";n.d(t,{S:()=>r,W:()=>i});var r=function(e,t){if(!e)return!1;3===e.nodeType&&(e=e.parentElement);for(var n=e,r=!1;n&&!r&&!n.classList.contains("vditor-reset");)0===n.nodeName.indexOf(t)?r=!0:n=n.parentElement;return r&&n},i=function(e){var t=r(e,"H");return!(!t||2!==t.tagName.length||"HR"===t.tagName)&&t}},673:(e,t,n)=>{"use strict";n.d(t,{T:()=>r});var r=function(){for(var e=[],t=0;t{"use strict";n.d(t,{zh:()=>a,Ny:()=>s,Gb:()=>l,Hc:()=>c,im:()=>d,$j:()=>u,ib:()=>p,oC:()=>m});var r=n(145),i=n(410),o=n(106),a=function(e){var t,n=e[e.currentMode].element;return getSelection().rangeCount>0&&(t=getSelection().getRangeAt(0),n.isEqualNode(t.startContainer)||n.contains(t.startContainer))?t:e[e.currentMode].range?e[e.currentMode].range:(n.focus(),(t=n.ownerDocument.createRange()).setStart(n,0),t.collapse(!0),t)},s=function(e){var t=window.getSelection().getRangeAt(0);if(!e.contains(t.startContainer)&&!(0,o.fb)(t.startContainer,"vditor-panel--none"))return{left:0,top:0};var n,r=e.parentElement.getBoundingClientRect();if(0===t.getClientRects().length)if(3===t.startContainer.nodeType){var i=t.startContainer.parentElement;if(!(i&&i.getClientRects().length>0))return{left:0,top:0};n=i.getClientRects()[0]}else{var a=t.startContainer.children;if(a[t.startOffset]&&a[t.startOffset].getClientRects().length>0)n=a[t.startOffset].getClientRects()[0];else if(t.startContainer.childNodes.length>0){var s=t.cloneRange();t.selectNode(t.startContainer.childNodes[Math.max(0,t.startOffset-1)]),n=t.getClientRects()[0],t.setEnd(s.endContainer,s.endOffset),t.setStart(s.startContainer,s.startOffset)}else n=t.startContainer.getClientRects()[0];if(!n){for(var l=t.startContainer.childNodes[t.startOffset];!l.getClientRects||l.getClientRects&&0===l.getClientRects().length;)l=l.parentElement;n=l.getClientRects()[0]}}else n=t.getClientRects()[0];return{left:n.left-r.left,top:n.top-r.top}},l=function(e,t){if(!t){if(0===getSelection().rangeCount)return!1;t=getSelection().getRangeAt(0)}var n=t.commonAncestorContainer;return e.isEqualNode(n)||e.contains(n)},c=function(e){var t=window.getSelection();t.removeAllRanges(),t.addRange(e)},d=function(e,t,n){var r={end:0,start:0};if(!n){if(0===getSelection().rangeCount)return r;n=window.getSelection().getRangeAt(0)}if(l(t,n)){var i=n.cloneRange();e.childNodes[0]&&e.childNodes[0].childNodes[0]?i.setStart(e.childNodes[0].childNodes[0],0):i.selectNodeContents(e),i.setEnd(n.startContainer,n.startOffset),r.start=i.toString().length,r.end=r.start+n.toString().length}return r},u=function(e,t,n){var r=0,i=0,o=n.childNodes[i],a=!1,s=!1;e=Math.max(0,e),t=Math.max(0,t);var l=n.ownerDocument.createRange();for(l.setStart(o||n,0),l.collapse(!0);!s&&o;){var d=r+o.textContent.length;if(!a&&e>=r&&e<=d&&(0===e?l.setStart(o,0):3===o.childNodes[0].nodeType?l.setStart(o.childNodes[0],e-r):o.nextSibling?l.setStartBefore(o.nextSibling):l.setStartAfter(o),a=!0,e===t)){s=!0;break}a&&t>=r&&t<=d&&(0===t?l.setEnd(o,0):3===o.childNodes[0].nodeType?l.setEnd(o.childNodes[0],t-r):o.nextSibling?l.setEndBefore(o.nextSibling):l.setEndAfter(o),s=!0),r=d,o=n.childNodes[++i]}return!s&&n.childNodes[i-1]&&l.setStartBefore(n.childNodes[i-1]),c(l),l},p=function(e,t){var n=e.querySelector("wbr");if(n){if(n.previousElementSibling)if(n.previousElementSibling.isSameNode(n.previousSibling)){if(n.previousElementSibling.lastChild)return t.setStartBefore(n),t.collapse(!0),c(t),!(0,i.i7)()||"EM"!==n.previousElementSibling.tagName&&"STRONG"!==n.previousElementSibling.tagName&&"S"!==n.previousElementSibling.tagName||(t.insertNode(document.createTextNode(r.g.ZWSP)),t.collapse(!1)),void n.remove();t.setStartAfter(n.previousElementSibling)}else t.setStart(n.previousSibling,n.previousSibling.textContent.length);else n.previousSibling?t.setStart(n.previousSibling,n.previousSibling.textContent.length):n.nextSibling?3===n.nextSibling.nodeType?t.setStart(n.nextSibling,0):t.setStartBefore(n.nextSibling):t.setStart(n.parentElement,0);t.collapse(!0),n.remove(),c(t)}},m=function(e,t){var n=document.createElement("div");n.innerHTML=e;var r=n.querySelectorAll("p");1===r.length&&!r[0].previousSibling&&!r[0].nextSibling&&t[t.currentMode].element.children.length>0&&"P"===n.firstElementChild.tagName&&(e=r[0].innerHTML.trim());var i=document.createElement("div");i.innerHTML=e;var s=a(t);if(""!==s.toString()&&(t[t.currentMode].preventInput=!0,document.execCommand("delete",!1,"")),i.firstElementChild&&"0"===i.firstElementChild.getAttribute("data-block")){i.lastElementChild.insertAdjacentHTML("beforeend","");var l=(0,o.F9)(s.startContainer);l?l.insertAdjacentHTML("afterend",i.innerHTML):t[t.currentMode].element.insertAdjacentHTML("beforeend",i.innerHTML),p(t[t.currentMode].element,s)}else{var d=document.createElement("template");d.innerHTML=e,s.insertNode(d.content.cloneNode(!0)),s.collapse(!1),c(s)}}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.d(r,{default:()=>Jn});var e,t=n(408),i=n(145),o=n(105),a=function(e){return"sv"===e.currentMode?(0,o.X)("".concat(e.sv.element.textContent,"\n").replace(/\n\n$/,"\n")):"wysiwyg"===e.currentMode?e.lute.VditorDOM2Md(e.wysiwyg.element.innerHTML):"ir"===e.currentMode?e.lute.VditorIRDOM2Md(e.ir.element.innerHTML):""},s=n(413),l=function(){function e(){this.element=document.createElement("div"),this.element.className="vditor-devtools",this.element.innerHTML=''}return e.prototype.renderEchart=function(e){var t=this;"block"===e.devtools.element.style.display&&(0,s.G)("".concat(e.options.cdn,"/dist/js/echarts/echarts.min.js?v=5.5.1"),"vditorEchartsScript").then((function(){t.ASTChart||(t.ASTChart=echarts.init(e.devtools.element.lastElementChild));try{t.element.lastElementChild.style.display="block",t.element.firstElementChild.innerHTML="",t.ASTChart.setOption({series:[{data:JSON.parse(e.lute.RenderEChartsJSON(a(e))),initialTreeDepth:-1,label:{align:"left",backgroundColor:"rgba(68, 77, 86, .68)",borderRadius:3,color:"#d1d5da",fontSize:12,lineHeight:12,offset:[9,12],padding:[2,4,2,4],position:"top",verticalAlign:"middle"},lineStyle:{color:"#4285f4",type:"curve",width:1},orient:"vertical",roam:!0,type:"tree"}],toolbox:{bottom:25,emphasis:{iconStyle:{color:"#4285f4"}},feature:{restore:{show:!0},saveAsImage:{show:!0}},right:15,show:!0}}),t.ASTChart.resize()}catch(e){t.element.lastElementChild.style.display="none",t.element.firstElementChild.innerHTML=e}}))},e}(),c=n(410),d=function(e,t){t.forEach((function(t){if(e[t]){var n=e[t].children[0];n&&n.classList.contains("vditor-menu--current")&&n.classList.remove("vditor-menu--current")}}))},u=function(e,t){t.forEach((function(t){if(e[t]){var n=e[t].children[0];n&&!n.classList.contains("vditor-menu--current")&&n.classList.add("vditor-menu--current")}}))},p=function(e,t){t.forEach((function(t){if(e[t]){var n=e[t].children[0];n&&n.classList.contains(i.g.CLASS_MENU_DISABLED)&&n.classList.remove(i.g.CLASS_MENU_DISABLED)}}))},m=function(e,t){t.forEach((function(t){if(e[t]){var n=e[t].children[0];n&&!n.classList.contains(i.g.CLASS_MENU_DISABLED)&&n.classList.add(i.g.CLASS_MENU_DISABLED)}}))},f=function(e,t){t.forEach((function(t){e[t]&&e[t]&&(e[t].style.display="none")}))},h=function(e,t){t.forEach((function(t){e[t]&&e[t]&&(e[t].style.display="block")}))},v=function(e,t,n){t.includes("subToolbar")&&(e.toolbar.element.querySelectorAll(".vditor-hint").forEach((function(e){n&&e.isEqualNode(n)||(e.style.display="none")})),e.toolbar.elements.emoji&&(e.toolbar.elements.emoji.lastElementChild.style.display="none")),t.includes("hint")&&(e.hint.element.style.display="none"),e.wysiwyg.popover&&t.includes("popover")&&(e.wysiwyg.popover.style.display="none")},g=function(e,t,n,r){n.addEventListener((0,c.Le)(),(function(r){r.preventDefault(),r.stopPropagation(),n.classList.contains(i.g.CLASS_MENU_DISABLED)||(e.toolbar.element.querySelectorAll(".vditor-hint--current").forEach((function(e){e.classList.remove("vditor-hint--current")})),"block"===t.style.display?t.style.display="none":(v(e,["subToolbar","hint","popover"],n.parentElement.parentElement),n.classList.contains("vditor-tooltipped")||n.classList.add("vditor-hint--current"),t.style.display="block",e.toolbar.element.getBoundingClientRect().right-n.getBoundingClientRect().right<250?t.classList.add("vditor-panel--left"):t.classList.remove("vditor-panel--left")))}))},b=n(106),y=n(771),w=function(e,t,n,r){r&&console.log("".concat(e," - ").concat(n,": ").concat(t))},E=n(135),k=n(775),S=n(428),L=n(325),T=n(483),C=n(999),M=n(472),x=n(637),A=n(11),_=n(194),H=n(229),N=n(825),O=function(e,t){if(e)if("html-block"!==e.parentElement.getAttribute("data-type")){var n=e.firstElementChild.className.replace("language-","");if("abc"===n)(0,E.Q)(e,t.options.cdn);else if("mermaid"===n)(0,x.i)(e,t.options.cdn,t.options.theme);else if("smiles"===n)(0,N.J)(e,t.options.cdn,t.options.theme);else if("markmap"===n)(0,A.K)(e,t.options.cdn);else if("flowchart"===n)(0,L.P)(e,t.options.cdn);else if("echarts"===n)(0,k.p)(e,t.options.cdn,t.options.theme);else if("mindmap"===n)(0,_.P)(e,t.options.cdn,t.options.theme);else if("plantuml"===n)(0,H.B)(e,t.options.cdn);else if("graphviz"===n)(0,T.v)(e,t.options.cdn);else if("math"===n)(0,M.H)(e,{cdn:t.options.cdn,math:t.options.preview.math});else{t.options.customRenders.find((function(r){if(r.language===n)return r.render(e,t),!0}))||((0,C.s)(Object.assign({},t.options.preview.hljs),e,t.options.cdn),(0,S.O)(e,t.options.preview.hljs))}e.setAttribute("data-render","1")}else e.setAttribute("data-render","1")},D=n(810),I=function(e){if("sv"!==e.currentMode){var t=e[e.currentMode].element,n=e.outline.render(e);""===n&&(n="[ToC]"),t.querySelectorAll('[data-type="toc-block"]').forEach((function(t){t.innerHTML=n,(0,M.H)(t,{cdn:e.options.cdn,math:e.options.preview.math})}))}},j=function(e,t){var n=(0,b.lG)(e.target,"SPAN");if(n&&(0,b.fb)(n,"vditor-toc")){var r=t[t.currentMode].element.querySelector("#"+n.getAttribute("data-target-id"));if(r)if("auto"===t.options.height){var i=r.offsetTop+t.element.offsetTop;t.options.toolbarConfig.pin||(i+=t.toolbar.element.offsetHeight),window.scrollTo(window.scrollX,i)}else t.element.offsetTop=e.textContent.trimRight().length)return e.nextElementSibling.remove(),ut(t),!0;if(rt(t,n,r,e,e.nextElementSibling))return!0}if("Backspace"===n.key||"Delete"===n.key){var i=(0,b.fb)(r.startContainer,"vditor-toc");if(i)return i.remove(),ut(t),!0}},P=function(e,t,n,r){void 0===n&&(n=!1);var o=(0,b.F9)(t.startContainer);if(o&&!n&&"code-block"!==o.getAttribute("data-type")){if(ct(o.innerHTML)&&o.previousElementSibling||dt(o.innerHTML))return;for(var s=(0,D.im)(o,e.ir.element,t).start,l=!0,c=s-1;c>o.textContent.substr(0,s).lastIndexOf("\n");c--)if(" "!==o.textContent.charAt(c)&&"\t"!==o.textContent.charAt(c)){l=!1;break}0===s&&(l=!1);var d=!0;for(c=s-1;c"):t.insertNode(document.createElement("wbr"))}o.querySelectorAll("[style]").forEach((function(e){e.removeAttribute("style")})),"link-ref-defs-block"===o.getAttribute("data-type")&&(o=e.ir.element);var m,f=o.isEqualNode(e.ir.element),h=(0,b.a1)(o,"data-type","footnotes-block"),v="";if(f)v=o.innerHTML;else{var g=(0,y.S)(t.startContainer,"BLOCKQUOTE"),E=(0,b.O9)(t.startContainer);if(E&&(o=E),g&&(!E||E&&!g.contains(E))&&(o=g),h&&(o=h),v=o.outerHTML,"UL"===o.tagName||"OL"===o.tagName){var k=o.previousElementSibling,S=o.nextElementSibling;!k||"UL"!==k.tagName&&"OL"!==k.tagName||(v=k.outerHTML+v,k.remove()),!S||"UL"!==S.tagName&&"OL"!==S.tagName||(v+=S.outerHTML,S.remove()),v=v.replace("
","
")}else o.previousElementSibling&&""!==o.previousElementSibling.textContent.replace(i.g.ZWSP,"")&&r&&"insertParagraph"===r.inputType&&(v=o.previousElementSibling.outerHTML+v,o.previousElementSibling.remove());o.innerText.startsWith("```")||(e.ir.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((function(e){e&&!o.isEqualNode(e)&&(v+=e.outerHTML,e.remove())})),e.ir.element.querySelectorAll("[data-type='footnotes-block']").forEach((function(e){e&&!o.isEqualNode(e)&&(v+=e.outerHTML,e.remove())})))}if(w("SpinVditorIRDOM",v,"argument",e.options.debugger),v=e.lute.SpinVditorIRDOM(v),w("SpinVditorIRDOM",v,"result",e.options.debugger),f)o.innerHTML=v;else if(o.outerHTML=v,h){var L=(0,b.a1)(e.ir.element.querySelector("wbr"),"data-type","footnotes-def");if(L){var T=L.textContent,C=T.substring(1,T.indexOf("]:")),M=e.ir.element.querySelector('sup[data-type="footnotes-ref"][data-footnotes-label="'.concat(C,'"]'));M&&M.setAttribute("aria-label",T.substr(C.length+3).trim().substr(0,24))}}var x,A=e.ir.element.querySelectorAll("[data-type='link-ref-defs-block']");A.forEach((function(e,t){0===t?m=e:(m.insertAdjacentHTML("beforeend",e.innerHTML),e.remove())})),A.length>0&&e.ir.element.insertAdjacentElement("beforeend",A[0]);var _=e.ir.element.querySelectorAll("[data-type='footnotes-block']");_.forEach((function(e,t){0===t?x=e:(x.insertAdjacentHTML("beforeend",e.innerHTML),e.remove())})),_.length>0&&e.ir.element.insertAdjacentElement("beforeend",_[0]),(0,D.ib)(e.ir.element,t),e.ir.element.querySelectorAll(".vditor-ir__preview[data-render='2']").forEach((function(t){O(t,e)})),I(e),At(e,{enableAddUndoStack:!0,enableHint:!0,enableInput:!0})},q=function(e,t){if(""===e)return!1;if(-1===e.indexOf("⇧")&&-1===e.indexOf("⌘")&&-1===e.indexOf("⌥"))return!((0,c.yl)(t)||t.altKey||t.shiftKey||t.code!==e);if("⇧Tab"===e)return!((0,c.yl)(t)||t.altKey||!t.shiftKey||"Tab"!==t.code);var n=e.split("");if(e.startsWith("⌥")){var r=3===n.length?n[2]:n[1];return!((3===n.length?!(0,c.yl)(t):(0,c.yl)(t))||!t.altKey||t.shiftKey||t.code!==(/^[0-9]$/.test(r)?"Digit":"Key")+r)}"⌘Enter"===e&&(n=["⌘","Enter"]);var i=n.length>2&&"⇧"===n[0],o=i?n[2]:n[1];return!i||!(0,c.vU)()&&/Mac/.test(navigator.platform)||("-"===o?o="_":"="===o&&(o="+")),!(!(0,c.yl)(t)||t.key.toLowerCase()!==o.toLowerCase()||t.altKey||!(!i&&!t.shiftKey||i&&t.shiftKey))},B=function(e,t){t.ir.element.querySelectorAll(".vditor-ir__node--expand").forEach((function(e){e.classList.remove("vditor-ir__node--expand")}));var n=(0,b.JQ)(e.startContainer,"vditor-ir__node"),r=!e.collapsed&&(0,b.JQ)(e.endContainer,"vditor-ir__node");if(e.collapsed||n&&n===r){n&&(n.classList.add("vditor-ir__node--expand"),n.classList.remove("vditor-ir__node--hidden"),(0,D.Hc)(e));var i=function(e){var t=e.startContainer;if(3===t.nodeType&&t.nodeValue.length!==e.startOffset)return!1;for(var n=t.nextSibling;n&&""===n.textContent;)n=n.nextSibling;if(!n){var r=(0,b.fb)(t,"vditor-ir__marker");if(r&&!r.nextSibling){var i=t.parentElement.parentElement.nextSibling;if(i&&3!==i.nodeType&&i.classList.contains("vditor-ir__node"))return i}return!1}return!(!n||3===n.nodeType||!n.classList.contains("vditor-ir__node")||n.getAttribute("data-block"))&&n}(e);if(i)return i.classList.add("vditor-ir__node--expand"),void i.classList.remove("vditor-ir__node--hidden");var o=function(e){var t=e.startContainer,n=t.previousSibling;return!(3!==t.nodeType||0!==e.startOffset||!n||3===n.nodeType||!n.classList.contains("vditor-ir__node")||n.getAttribute("data-block"))&&n}(e);return o?(o.classList.add("vditor-ir__node--expand"),void o.classList.remove("vditor-ir__node--hidden")):void 0}},V=n(190),U=function(e,t){e.querySelectorAll("[data-type=footnotes-link]").forEach((function(e){for(var n=e.parentElement,r=n.nextSibling;r&&r.textContent.startsWith(" ");){var i=r;i.childNodes.forEach((function(e){n.append(e.cloneNode(!0))})),r=r.nextSibling,i.remove()}t&&t(n)}))},W=function(e,t){var n,r=getSelection().getRangeAt(0).cloneRange(),i=r.startContainer;3!==r.startContainer.nodeType&&"DIV"===r.startContainer.tagName&&(i=r.startContainer.childNodes[r.startOffset-1]);var o=(0,b.a1)(i,"data-block","0");if(o&&t&&("deleteContentBackward"===t.inputType||" "===t.data)){for(var a=(0,D.im)(o,e.sv.element,r).start,s=!0,l=a-1;l>o.textContent.substr(0,a).lastIndexOf("\n");l--)if(" "!==o.textContent.charAt(l)&&"\t"!==o.textContent.charAt(l)){s=!1;break}if(0===a&&(s=!1),s)return void Re(e);if("deleteContentBackward"===t.inputType){var c=(0,b.a1)(i,"data-type","code-block-open-marker")||(0,b.a1)(i,"data-type","code-block-close-marker");if(c){var d;if("code-block-close-marker"===c.getAttribute("data-type"))if(d=De(i,"code-block-open-marker"))return d.textContent=c.textContent,void Re(e);if("code-block-open-marker"===c.getAttribute("data-type"))if(d=De(i,"code-block-close-marker",!1))return d.textContent=c.textContent,void Re(e)}var u=(0,b.a1)(i,"data-type","math-block-open-marker");if(u){var p=u.nextElementSibling.nextElementSibling;return void(p&&"math-block-close-marker"===p.getAttribute("data-type")&&(p.remove(),Re(e)))}o.querySelectorAll('[data-type="code-block-open-marker"]').forEach((function(e){1===e.textContent.length&&e.remove()})),o.querySelectorAll('[data-type="code-block-close-marker"]').forEach((function(e){1===e.textContent.length&&e.remove()}));var m=(0,b.a1)(i,"data-type","heading-marker");if(m&&-1===m.textContent.indexOf("#"))return void Re(e)}if((" "===t.data||"deleteContentBackward"===t.inputType)&&((0,b.a1)(i,"data-type","padding")||(0,b.a1)(i,"data-type","li-marker")||(0,b.a1)(i,"data-type","task-marker")||(0,b.a1)(i,"data-type","blockquote-marker")))return void Re(e)}if(o&&"$$"===o.textContent.trimRight())Re(e);else{o||(o=e.sv.element),"link-ref-defs-block"===(null===(n=o.firstElementChild)||void 0===n?void 0:n.getAttribute("data-type"))&&(o=e.sv.element),(0,b.a1)(i,"data-type","footnotes-link")&&(o=e.sv.element),-1===o.textContent.indexOf(Lute.Caret)&&r.insertNode(document.createTextNode(Lute.Caret)),o.querySelectorAll("[style]").forEach((function(e){e.removeAttribute("style")})),o.querySelectorAll("font").forEach((function(e){e.outerHTML=e.innerHTML}));var f=o.textContent,h=o.isEqualNode(e.sv.element);if(h)f=o.textContent;else{o.previousElementSibling&&(f=o.previousElementSibling.textContent+f,o.previousElementSibling.remove()),o.previousElementSibling&&0===f.indexOf("---\n")&&(f=o.previousElementSibling.textContent+f,o.previousElementSibling.remove());var v="";e.sv.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((function(e,t){e&&!o.isEqualNode(e.parentElement)&&(v+=e.parentElement.textContent+"\n",e.parentElement.remove())})),e.sv.element.querySelectorAll("[data-type='footnotes-link']").forEach((function(e,t){e&&!o.isEqualNode(e.parentElement)&&(v+=e.parentElement.textContent+"\n",e.parentElement.remove())})),f=v+f}f=Ie(f,e),h?o.innerHTML=f:o.outerHTML=f,e.sv.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((function(t){e.sv.element.insertAdjacentElement("beforeend",t.parentElement)})),U(e.sv.element,(function(t){e.sv.element.insertAdjacentElement("beforeend",t)})),(0,D.ib)(e.sv.element,r),_e(e),Re(e,{enableAddUndoStack:!0,enableHint:!0,enableInput:!0})}},z=n(538),G=function(e){"dark"===e.options.theme?e.element.classList.add("vditor--dark"):e.element.classList.remove("vditor--dark")},K=function(e){var t=window.innerWidth<=i.g.MOBILE_WIDTH?10:35;if("none"!==e.wysiwyg.element.parentElement.style.display){var n=(e.wysiwyg.element.parentElement.clientWidth-e.options.preview.maxWidth)/2;e.wysiwyg.element.style.padding="10px ".concat(Math.max(t,n),"px")}if("none"!==e.ir.element.parentElement.style.display){n=(e.ir.element.parentElement.clientWidth-e.options.preview.maxWidth)/2;e.ir.element.style.padding="10px ".concat(Math.max(t,n),"px")}"block"!==e.preview.element.style.display?e.toolbar.element.style.paddingLeft=Math.max(5,parseInt(e[e.currentMode].element.style.paddingLeft||"0",10)+("left"===e.options.outline.position?e.outline.element.offsetWidth:0))+"px":e.toolbar.element.style.paddingLeft=5+("left"===e.options.outline.position?e.outline.element.offsetWidth:0)+"px"},F=function(e){if(e.options.typewriterMode){var t=window.innerHeight;"number"==typeof e.options.height?(t=e.options.height,"number"==typeof e.options.minHeight&&(t=Math.max(t,e.options.minHeight)),t=Math.min(window.innerHeight,t)):t=e.element.clientHeight,e.element.classList.contains("vditor--fullscreen")&&(t=window.innerHeight),e[e.currentMode].element.style.setProperty("--editor-bottom",(t-e.toolbar.element.offsetHeight)/2+"px")}};function Z(){window.removeEventListener("resize",e)}var J,X,Y=function(t){F(t),Z(),window.addEventListener("resize",e=function(){K(t),F(t)});var n=(0,c.pK)()&&localStorage.getItem(t.options.cache.id);return t.options.cache.enable&&n||(t.options.value?n=t.options.value:t.originalInnerHTML?n=t.lute.HTML2Md(t.originalInnerHTML):t.options.cache.enable||(n="")),n||""},Q=function(e){clearTimeout(e[e.currentMode].hlToolbarTimeoutId),e[e.currentMode].hlToolbarTimeoutId=window.setTimeout((function(){if("false"!==e[e.currentMode].element.getAttribute("contenteditable")&&(0,D.Gb)(e[e.currentMode].element)){d(e.toolbar.elements,i.g.EDIT_TOOLBARS),p(e.toolbar.elements,i.g.EDIT_TOOLBARS);var t=(0,D.zh)(e),n=t.startContainer;3===t.startContainer.nodeType&&(n=t.startContainer.parentElement),n.classList.contains("vditor-reset")&&(n=n.childNodes[t.startOffset]),("sv"===e.currentMode?(0,b.a1)(n,"data-type","heading"):(0,y.W)(n))&&u(e.toolbar.elements,["headings"]),("sv"===e.currentMode?(0,b.a1)(n,"data-type","blockquote"):(0,b.lG)(n,"BLOCKQUOTE"))&&u(e.toolbar.elements,["quote"]),(0,b.a1)(n,"data-type","strong")&&u(e.toolbar.elements,["bold"]),(0,b.a1)(n,"data-type","em")&&u(e.toolbar.elements,["italic"]),(0,b.a1)(n,"data-type","s")&&u(e.toolbar.elements,["strike"]),(0,b.a1)(n,"data-type","a")&&u(e.toolbar.elements,["link"]);var r=(0,b.lG)(n,"LI");r?(r.classList.contains("vditor-task")?u(e.toolbar.elements,["check"]):"OL"===r.parentElement.tagName?u(e.toolbar.elements,["ordered-list"]):"UL"===r.parentElement.tagName&&u(e.toolbar.elements,["list"]),p(e.toolbar.elements,["outdent","indent"])):m(e.toolbar.elements,["outdent","indent"]),(0,b.a1)(n,"data-type","code-block")&&(m(e.toolbar.elements,["headings","bold","italic","strike","line","quote","list","ordered-list","check","code","inline-code","upload","link","table","record"]),u(e.toolbar.elements,["code"])),(0,b.a1)(n,"data-type","code")&&(m(e.toolbar.elements,["headings","bold","italic","strike","line","quote","list","ordered-list","check","code","upload","link","table","record"]),u(e.toolbar.elements,["inline-code"])),(0,b.a1)(n,"data-type","table")&&m(e.toolbar.elements,["headings","list","ordered-list","check","line","quote","code","table"])}}),200)},$=function(e,t){void 0===t&&(t={enableAddUndoStack:!0,enableHint:!1,enableInput:!0}),t.enableHint&&e.hint.render(e),clearTimeout(e.wysiwyg.afterRenderTimeoutId),e.wysiwyg.afterRenderTimeoutId=window.setTimeout((function(){if(!e.wysiwyg.composingLock){var n=a(e);"function"==typeof e.options.input&&t.enableInput&&e.options.input(n),e.options.counter.enable&&e.counter.render(e,n),e.options.cache.enable&&(0,c.pK)()&&(localStorage.setItem(e.options.cache.id,n),e.options.cache.after&&e.options.cache.after(n)),e.devtools&&e.devtools.renderEchart(e),t.enableAddUndoStack&&e.undo.addToUndoStack(e)}}),e.options.undoDelay)},ee=function(e){for(var t="",n=e.nextSibling;n;)3===n.nodeType?t+=n.textContent:t+=n.outerHTML,n=n.nextSibling;return t},te=function(e){for(var t="",n=e.previousSibling;n;)t=3===n.nodeType?n.textContent+t:n.outerHTML+t,n=n.previousSibling;return t},ne=function(e,t){Array.from(e.wysiwyg.element.childNodes).find((function(n){if(3===n.nodeType){var r=document.createElement("p");r.setAttribute("data-block","0"),r.textContent=n.textContent;var i=3===t.startContainer.nodeType?t.startOffset:n.textContent.length;return n.parentNode.insertBefore(r,n),n.remove(),t.setStart(r.firstChild,Math.min(r.firstChild.textContent.length,i)),t.collapse(!0),(0,D.Hc)(t),!0}if(!n.getAttribute("data-block"))return"P"===n.tagName?n.remove():("DIV"===n.tagName?(t.insertNode(document.createElement("wbr")),n.outerHTML=''.concat(n.innerHTML,"
")):"BR"===n.tagName?n.outerHTML=''.concat(n.outerHTML,"
"):(t.insertNode(document.createElement("wbr")),n.outerHTML=''.concat(n.outerHTML,"
")),(0,D.ib)(e.wysiwyg.element,t),t=getSelection().getRangeAt(0)),!0}))},re=function(e,t){var n=(0,D.zh)(e),r=(0,b.F9)(n.startContainer);r||(r=n.startContainer.childNodes[n.startOffset]),r||0!==e.wysiwyg.element.children.length||(r=e.wysiwyg.element),r&&!r.classList.contains("vditor-wysiwyg__block")&&(n.insertNode(document.createElement("wbr")),""===r.innerHTML.trim()&&(r.innerHTML="
"),"BLOCKQUOTE"===r.tagName||r.classList.contains("vditor-reset")?r.innerHTML="<".concat(t,' data-block="0">').concat(r.innerHTML.trim(),"").concat(t,">"):r.outerHTML="<".concat(t,' data-block="0">').concat(r.innerHTML.trim(),"").concat(t,">"),(0,D.ib)(e.wysiwyg.element,n),I(e))},ie=function(e){var t=getSelection().getRangeAt(0),n=(0,b.F9)(t.startContainer);n||(n=t.startContainer.childNodes[t.startOffset]),n&&(t.insertNode(document.createElement("wbr")),n.outerHTML=''.concat(n.innerHTML,"
"),(0,D.ib)(e.wysiwyg.element,t)),e.wysiwyg.popover.style.display="none"},oe=function(e,t,n){void 0===n&&(n=!0);var r=e.previousElementSibling,i=r.ownerDocument.createRange();"CODE"===r.tagName?(r.style.display="inline-block",n?i.setStart(r.firstChild,1):i.selectNodeContents(r)):(r.style.display="block",r.firstChild.firstChild||r.firstChild.appendChild(document.createTextNode("")),i.selectNodeContents(r.firstChild)),n?i.collapse(!0):i.collapse(!1),(0,D.Hc)(i),e.firstElementChild.classList.contains("language-mindmap")||_e(t)},ae=function(e,t){if(q("⇧⌘X",t)){var n=e.wysiwyg.popover.querySelector('[data-type="remove"]');return n&&n.click(),t.preventDefault(),!0}},se=function(e){clearTimeout(e.wysiwyg.hlToolbarTimeoutId),e.wysiwyg.hlToolbarTimeoutId=window.setTimeout((function(){if("false"!==e.wysiwyg.element.getAttribute("contenteditable")&&(0,D.Gb)(e.wysiwyg.element)){d(e.toolbar.elements,i.g.EDIT_TOOLBARS),p(e.toolbar.elements,i.g.EDIT_TOOLBARS);var t=getSelection().getRangeAt(0),n=t.startContainer;n=3===t.startContainer.nodeType?t.startContainer.parentElement:n.childNodes[t.startOffset>=n.childNodes.length?n.childNodes.length-1:t.startOffset];var r=(0,b.a1)(n,"data-type","footnotes-block");if(r)return e.wysiwyg.popover.innerHTML="",pe(r,e),void le(e,r);var o=(0,b.lG)(n,"LI");o?(o.classList.contains("vditor-task")?u(e.toolbar.elements,["check"]):"OL"===o.parentElement.tagName?u(e.toolbar.elements,["ordered-list"]):"UL"===o.parentElement.tagName&&u(e.toolbar.elements,["list"]),p(e.toolbar.elements,["outdent","indent"])):m(e.toolbar.elements,["outdent","indent"]),(0,b.lG)(n,"BLOCKQUOTE")&&u(e.toolbar.elements,["quote"]),((0,b.lG)(n,"B")||(0,b.lG)(n,"STRONG"))&&u(e.toolbar.elements,["bold"]),((0,b.lG)(n,"I")||(0,b.lG)(n,"EM"))&&u(e.toolbar.elements,["italic"]),((0,b.lG)(n,"STRIKE")||(0,b.lG)(n,"S"))&&u(e.toolbar.elements,["strike"]),e.wysiwyg.element.querySelectorAll(".vditor-comment--focus").forEach((function(e){e.classList.remove("vditor-comment--focus")}));var s=(0,b.fb)(n,"vditor-comment");if(s){var l=s.getAttribute("data-cmtids").split(" ");if(l.length>1&&s.nextSibling.isSameNode(s.nextElementSibling)){var f=s.nextElementSibling.getAttribute("data-cmtids").split(" ");l.find((function(e){if(f.includes(e))return l=[e],!0}))}e.wysiwyg.element.querySelectorAll(".vditor-comment").forEach((function(e){e.getAttribute("data-cmtids").indexOf(l[0])>-1&&e.classList.add("vditor-comment--focus")}))}var h=(0,b.lG)(n,"A");h&&u(e.toolbar.elements,["link"]);var v=(0,b.lG)(n,"TABLE"),g=(0,y.W)(n);(0,b.lG)(n,"CODE")?(0,b.lG)(n,"PRE")?(m(e.toolbar.elements,["headings","bold","italic","strike","line","quote","list","ordered-list","check","code","inline-code","upload","link","table","record"]),u(e.toolbar.elements,["code"])):(m(e.toolbar.elements,["headings","bold","italic","strike","line","quote","list","ordered-list","check","code","upload","link","table","record"]),u(e.toolbar.elements,["inline-code"])):g?(m(e.toolbar.elements,["bold"]),u(e.toolbar.elements,["headings"])):v&&m(e.toolbar.elements,["table"]);var w=(0,b.fb)(n,"vditor-toc");if(w)return e.wysiwyg.popover.innerHTML="",pe(w,e),void le(e,w);var E=(0,y.S)(n,"BLOCKQUOTE");if(E&&(e.wysiwyg.popover.innerHTML="",de(t,E,e),ue(t,E,e),pe(E,e),le(e,E)),o&&(e.wysiwyg.popover.innerHTML="",de(t,o,e),ue(t,o,e),pe(o,e),le(e,o)),v){e.options.lang,e.options;e.wysiwyg.popover.innerHTML="";var k=function(){var t=v.rows.length,n=v.rows[0].cells.length,r=parseInt(P.value,10)||t,i=parseInt(B.value,10)||n;if(r!==t||n!==i){if(n!==i)for(var o=i-n,s=0;s0)for(var l=0;l "):v.rows[s].lastElementChild.insertAdjacentHTML("afterend"," | ");else for(var c=n-1;c>=i;c--)v.rows[s].cells[c].remove();if(t!==r){var d=r-t;if(d>0){for(var u="",p=0;p ";for(var m=0;m")}else for(p=t-1;p>=r;p--)v.rows[p].remove(),1===v.rows.length&&v.querySelector("tbody").remove()}"function"==typeof e.options.input&&e.options.input(a(e))}},S=function(n){lt(v,n),"right"===n?(M.classList.remove("vditor-icon--current"),x.classList.remove("vditor-icon--current"),A.classList.add("vditor-icon--current")):"center"===n?(M.classList.remove("vditor-icon--current"),A.classList.remove("vditor-icon--current"),x.classList.add("vditor-icon--current")):(x.classList.remove("vditor-icon--current"),A.classList.remove("vditor-icon--current"),M.classList.add("vditor-icon--current")),(0,D.Hc)(t),$(e)},L=(0,b.lG)(n,"TD"),T=(0,b.lG)(n,"TH"),C="left";L?C=L.getAttribute("align")||"left":T&&(C=T.getAttribute("align")||"center");var M=document.createElement("button");M.setAttribute("type","button"),M.setAttribute("aria-label",window.VditorI18n.alignLeft+"<"+(0,c.ns)("⇧⌘L")+">"),M.setAttribute("data-type","left"),M.innerHTML='',M.className="vditor-icon vditor-tooltipped vditor-tooltipped__n"+("left"===C?" vditor-icon--current":""),M.onclick=function(){S("left")};var x=document.createElement("button");x.setAttribute("type","button"),x.setAttribute("aria-label",window.VditorI18n.alignCenter+"<"+(0,c.ns)("⇧⌘C")+">"),x.setAttribute("data-type","center"),x.innerHTML='',x.className="vditor-icon vditor-tooltipped vditor-tooltipped__n"+("center"===C?" vditor-icon--current":""),x.onclick=function(){S("center")};var A=document.createElement("button");A.setAttribute("type","button"),A.setAttribute("aria-label",window.VditorI18n.alignRight+"<"+(0,c.ns)("⇧⌘R")+">"),A.setAttribute("data-type","right"),A.innerHTML='',A.className="vditor-icon vditor-tooltipped vditor-tooltipped__n"+("right"===C?" vditor-icon--current":""),A.onclick=function(){S("right")};var _=document.createElement("button");_.setAttribute("type","button"),_.setAttribute("aria-label",window.VditorI18n.insertRowBelow+"<"+(0,c.ns)("⌘=")+">"),_.setAttribute("data-type","insertRow"),_.innerHTML='',_.className="vditor-icon vditor-tooltipped vditor-tooltipped__n",_.onclick=function(){var n=getSelection().getRangeAt(0).startContainer,r=(0,b.lG)(n,"TD")||(0,b.lG)(n,"TH");r&&ht(e,t,r)};var H=document.createElement("button");H.setAttribute("type","button"),H.setAttribute("aria-label",window.VditorI18n.insertRowAbove+"<"+(0,c.ns)("⇧⌘F")+">"),H.setAttribute("data-type","insertRow"),H.innerHTML='',H.className="vditor-icon vditor-tooltipped vditor-tooltipped__n",H.onclick=function(){var n=getSelection().getRangeAt(0).startContainer,r=(0,b.lG)(n,"TD")||(0,b.lG)(n,"TH");r&&vt(e,t,r)};var N=document.createElement("button");N.setAttribute("type","button"),N.setAttribute("aria-label",window.VditorI18n.insertColumnRight+"<"+(0,c.ns)("⇧⌘=")+">"),N.setAttribute("data-type","insertColumn"),N.innerHTML='',N.className="vditor-icon vditor-tooltipped vditor-tooltipped__n",N.onclick=function(){var t=getSelection().getRangeAt(0).startContainer,n=(0,b.lG)(t,"TD")||(0,b.lG)(t,"TH");n&>(e,v,n)};var I=document.createElement("button");I.setAttribute("type","button"),I.setAttribute("aria-label",window.VditorI18n.insertColumnLeft+"<"+(0,c.ns)("⇧⌘G")+">"),I.setAttribute("data-type","insertColumn"),I.innerHTML='',I.className="vditor-icon vditor-tooltipped vditor-tooltipped__n",I.onclick=function(){var t=getSelection().getRangeAt(0).startContainer,n=(0,b.lG)(t,"TD")||(0,b.lG)(t,"TH");n&>(e,v,n,"beforebegin")};var j=document.createElement("button");j.setAttribute("type","button"),j.setAttribute("aria-label",window.VditorI18n["delete-row"]+"<"+(0,c.ns)("⌘-")+">"),j.setAttribute("data-type","deleteRow"),j.innerHTML='',j.className="vditor-icon vditor-tooltipped vditor-tooltipped__n",j.onclick=function(){var n=getSelection().getRangeAt(0).startContainer,r=(0,b.lG)(n,"TD")||(0,b.lG)(n,"TH");r&&bt(e,t,r)};var R=document.createElement("button");R.setAttribute("type","button"),R.setAttribute("aria-label",window.VditorI18n["delete-column"]+"<"+(0,c.ns)("⇧⌘-")+">"),R.setAttribute("data-type","deleteColumn"),R.innerHTML='',R.className="vditor-icon vditor-tooltipped vditor-tooltipped__n",R.onclick=function(){var n=getSelection().getRangeAt(0).startContainer,r=(0,b.lG)(n,"TD")||(0,b.lG)(n,"TH");r&&yt(e,t,v,r)},(J=document.createElement("span")).setAttribute("aria-label",window.VditorI18n.row),J.className="vditor-tooltipped vditor-tooltipped__n";var P=document.createElement("input");J.appendChild(P),P.type="number",P.min="1",P.className="vditor-input",P.style.width="42px",P.style.textAlign="center",P.setAttribute("placeholder",window.VditorI18n.row),P.value=v.rows.length.toString(),P.oninput=function(){k()},P.onkeydown=function(n){if(!n.isComposing)return"Tab"===n.key?(B.focus(),B.select(),void n.preventDefault()):void(ae(e,n)||he(n,t))};var q=document.createElement("span");q.setAttribute("aria-label",window.VditorI18n.column),q.className="vditor-tooltipped vditor-tooltipped__n";var B=document.createElement("input");q.appendChild(B),B.type="number",B.min="1",B.className="vditor-input",B.style.width="42px",B.style.textAlign="center",B.setAttribute("placeholder",window.VditorI18n.column),B.value=v.rows[0].cells.length.toString(),B.oninput=function(){k()},B.onkeydown=function(n){if(!n.isComposing)return"Tab"===n.key?(P.focus(),P.select(),void n.preventDefault()):void(ae(e,n)||he(n,t))},de(t,v,e),ue(t,v,e),pe(v,e),e.wysiwyg.popover.insertAdjacentElement("beforeend",M),e.wysiwyg.popover.insertAdjacentElement("beforeend",x),e.wysiwyg.popover.insertAdjacentElement("beforeend",A),e.wysiwyg.popover.insertAdjacentElement("beforeend",H),e.wysiwyg.popover.insertAdjacentElement("beforeend",_),e.wysiwyg.popover.insertAdjacentElement("beforeend",I),e.wysiwyg.popover.insertAdjacentElement("beforeend",N),e.wysiwyg.popover.insertAdjacentElement("beforeend",j),e.wysiwyg.popover.insertAdjacentElement("beforeend",R),e.wysiwyg.popover.insertAdjacentElement("beforeend",J),e.wysiwyg.popover.insertAdjacentHTML("beforeend"," x "),e.wysiwyg.popover.insertAdjacentElement("beforeend",q),le(e,v)}var V=(0,b.a1)(n,"data-type","link-ref");V&&ce(e,V,t);var U=(0,b.a1)(n,"data-type","footnotes-ref");if(U){e.options.lang,e.options;e.wysiwyg.popover.innerHTML="",(J=document.createElement("span")).setAttribute("aria-label",window.VditorI18n.footnoteRef+"<"+(0,c.ns)("⌥Enter")+">"),J.className="vditor-tooltipped vditor-tooltipped__n";var W=document.createElement("input");J.appendChild(W),W.className="vditor-input",W.setAttribute("placeholder",window.VditorI18n.footnoteRef+"<"+(0,c.ns)("⌥Enter")+">"),W.style.width="120px",W.value=U.getAttribute("data-footnotes-label"),W.oninput=function(){""!==W.value.trim()&&U.setAttribute("data-footnotes-label",W.value),"function"==typeof e.options.input&&e.options.input(a(e))},W.onkeydown=function(n){n.isComposing||ae(e,n)||he(n,t)},pe(U,e),e.wysiwyg.popover.insertAdjacentElement("beforeend",J),le(e,U)}var z=(0,b.fb)(n,"vditor-wysiwyg__block"),G=!!z&&z.getAttribute("data-type").indexOf("block")>-1;if(e.wysiwyg.element.querySelectorAll(".vditor-wysiwyg__preview").forEach((function(e){(!z||z&&G&&!z.contains(e))&&(e.previousElementSibling.style.display="none")})),z&&G){if(e.wysiwyg.popover.innerHTML="",de(t,z,e),ue(t,z,e),pe(z,e),"code-block"===z.getAttribute("data-type")){var K=document.createElement("span");K.setAttribute("aria-label",window.VditorI18n.language+"<"+(0,c.ns)("⌥Enter")+">"),K.className="vditor-tooltipped vditor-tooltipped__n";var F=document.createElement("input");K.appendChild(F);var Z=z.firstElementChild.firstElementChild;F.className="vditor-input",F.setAttribute("placeholder",window.VditorI18n.language+"<"+(0,c.ns)("⌥Enter")+">"),F.value=Z.className.indexOf("language-")>-1?Z.className.split("-")[1].split(" ")[0]:"",F.oninput=function(n){""!==F.value.trim()?Z.className="language-".concat(F.value):(Z.className="",e.hint.recentLanguage=""),z.lastElementChild.classList.contains("vditor-wysiwyg__preview")&&(z.lastElementChild.innerHTML=z.firstElementChild.innerHTML,O(z.lastElementChild,e)),$(e),1===n.detail&&(t.setStart(Z.firstChild,0),t.collapse(!0),(0,D.Hc)(t))},F.onkeydown=function(n){if(!n.isComposing&&!ae(e,n)){if("Escape"===n.key&&"block"===e.hint.element.style.display)return e.hint.element.style.display="none",void n.preventDefault();e.hint.select(n,e),he(n,t)}},F.onkeyup=function(t){var n,r;if(!t.isComposing&&"Enter"!==t.key&&"ArrowUp"!==t.key&&"Escape"!==t.key&&"ArrowDown"!==t.key){var o=[],a=F.value.substring(0,F.selectionStart);(e.options.preview.hljs.langs||i.g.ALIAS_CODE_LANGUAGES.concat((null!==(r=null===(n=window.hljs)||void 0===n?void 0:n.listLanguages())&&void 0!==r?r:[]).sort())).forEach((function(e){e.indexOf(a.toLowerCase())>-1&&o.push({html:e,value:e})})),e.hint.genHTML(o,a,e),t.preventDefault()}},e.wysiwyg.popover.insertAdjacentElement("beforeend",K)}le(e,z)}else z=void 0;if(g){var J;e.wysiwyg.popover.innerHTML="",(J=document.createElement("span")).setAttribute("aria-label","ID<"+(0,c.ns)("⌥Enter")+">"),J.className="vditor-tooltipped vditor-tooltipped__n";var X=document.createElement("input");J.appendChild(X),X.className="vditor-input",X.setAttribute("placeholder","ID<"+(0,c.ns)("⌥Enter")+">"),X.style.width="120px",X.value=g.getAttribute("data-id")||"",X.oninput=function(){g.setAttribute("data-id",X.value),"function"==typeof e.options.input&&e.options.input(a(e))},X.onkeydown=function(n){n.isComposing||ae(e,n)||he(n,t)},de(t,g,e),ue(t,g,e),pe(g,e),e.wysiwyg.popover.insertAdjacentElement("beforeend",J),le(e,g)}if(h&&fe(e,h,t),!(E||o||v||z||h||V||U||g||w)){var Y=(0,b.a1)(n,"data-block","0");Y&&Y.parentElement.isEqualNode(e.wysiwyg.element)?(e.wysiwyg.popover.innerHTML="",de(t,Y,e),ue(t,Y,e),pe(Y,e),le(e,Y)):e.wysiwyg.popover.style.display="none"}e.wysiwyg.element.querySelectorAll('span[data-type="backslash"] > span').forEach((function(e){e.style.display="none"}));var Q=(0,b.a1)(t.startContainer,"data-type","backslash");Q&&(Q.querySelector("span").style.display="inline")}}),200)},le=function(e,t){var n=t,r=(0,b.lG)(t,"TABLE");r&&(n=r),e.wysiwyg.popover.style.left="0",e.wysiwyg.popover.style.display="block",e.wysiwyg.popover.style.top=Math.max(-8,n.offsetTop-21-e.wysiwyg.element.scrollTop)+"px",e.wysiwyg.popover.style.left=Math.min(n.offsetLeft,e.wysiwyg.element.clientWidth-e.wysiwyg.popover.clientWidth)+"px",e.wysiwyg.popover.setAttribute("data-top",(n.offsetTop-21).toString())},ce=function(e,t,n){void 0===n&&(n=getSelection().getRangeAt(0)),e.wysiwyg.popover.innerHTML="";var r=function(){""!==o.value.trim()&&("IMG"===t.tagName?t.setAttribute("alt",o.value):t.textContent=o.value),""!==l.value.trim()&&t.setAttribute("data-link-label",l.value),"function"==typeof e.options.input&&e.options.input(a(e))},i=document.createElement("span");i.setAttribute("aria-label",window.VditorI18n.textIsNotEmpty),i.className="vditor-tooltipped vditor-tooltipped__n";var o=document.createElement("input");i.appendChild(o),o.className="vditor-input",o.setAttribute("placeholder",window.VditorI18n.textIsNotEmpty),o.style.width="120px",o.value=t.getAttribute("alt")||t.textContent,o.oninput=function(){r()},o.onkeydown=function(r){ae(e,r)||he(r,n)||me(e,t,r,l)};var s=document.createElement("span");s.setAttribute("aria-label",window.VditorI18n.linkRef),s.className="vditor-tooltipped vditor-tooltipped__n";var l=document.createElement("input");s.appendChild(l),l.className="vditor-input",l.setAttribute("placeholder",window.VditorI18n.linkRef),l.value=t.getAttribute("data-link-label"),l.oninput=function(){r()},l.onkeydown=function(r){ae(e,r)||he(r,n)||me(e,t,r,o)},pe(t,e),e.wysiwyg.popover.insertAdjacentElement("beforeend",i),e.wysiwyg.popover.insertAdjacentElement("beforeend",s),le(e,t)},de=function(e,t,n){var r=t.previousElementSibling;if(r&&(t.parentElement.isEqualNode(n.wysiwyg.element)||"LI"===t.tagName)){var i=document.createElement("button");i.setAttribute("type","button"),i.setAttribute("data-type","up"),i.setAttribute("aria-label",window.VditorI18n.up+"<"+(0,c.ns)("⇧⌘U")+">"),i.innerHTML='',i.className="vditor-icon vditor-tooltipped vditor-tooltipped__n",i.onclick=function(){e.insertNode(document.createElement("wbr")),r.insertAdjacentElement("beforebegin",t),(0,D.ib)(n.wysiwyg.element,e),$(n),se(n),_e(n)},n.wysiwyg.popover.insertAdjacentElement("beforeend",i)}},ue=function(e,t,n){var r=t.nextElementSibling;if(r&&(t.parentElement.isEqualNode(n.wysiwyg.element)||"LI"===t.tagName)){var i=document.createElement("button");i.setAttribute("type","button"),i.setAttribute("data-type","down"),i.setAttribute("aria-label",window.VditorI18n.down+"<"+(0,c.ns)("⇧⌘D")+">"),i.innerHTML='',i.className="vditor-icon vditor-tooltipped vditor-tooltipped__n",i.onclick=function(){e.insertNode(document.createElement("wbr")),r.insertAdjacentElement("afterend",t),(0,D.ib)(n.wysiwyg.element,e),$(n),se(n),_e(n)},n.wysiwyg.popover.insertAdjacentElement("beforeend",i)}},pe=function(e,t){var n=document.createElement("button");n.setAttribute("type","button"),n.setAttribute("data-type","remove"),n.setAttribute("aria-label",window.VditorI18n.remove+"<"+(0,c.ns)("⇧⌘X")+">"),n.innerHTML='',n.className="vditor-icon vditor-tooltipped vditor-tooltipped__n",n.onclick=function(){var n=(0,D.zh)(t);n.setStartAfter(e),(0,D.Hc)(n),e.remove(),$(t),se(t),["H1","H2","H3","H4","H5","H6"].includes(e.tagName)&&I(t)},t.wysiwyg.popover.insertAdjacentElement("beforeend",n)},me=function(e,t,n,r){if(!n.isComposing){if("Tab"===n.key)return r.focus(),r.select(),void n.preventDefault();if(!(0,c.yl)(n)&&!n.shiftKey&&n.altKey&&"Enter"===n.key){var o=(0,D.zh)(e);t.insertAdjacentHTML("afterend",i.g.ZWSP),o.setStartAfter(t.nextSibling),o.collapse(!0),(0,D.Hc)(o),n.preventDefault()}}},fe=function(e,t,n){e.wysiwyg.popover.innerHTML="";var r=function(){""!==o.value.trim()&&(t.innerHTML=o.value),t.setAttribute("href",s.value),t.setAttribute("title",c.value),$(e)};t.querySelectorAll("[data-marker]").forEach((function(e){e.removeAttribute("data-marker")}));var i=document.createElement("span");i.setAttribute("aria-label",window.VditorI18n.textIsNotEmpty),i.className="vditor-tooltipped vditor-tooltipped__n";var o=document.createElement("input");i.appendChild(o),o.className="vditor-input",o.setAttribute("placeholder",window.VditorI18n.textIsNotEmpty),o.style.width="120px",o.value=t.innerHTML||"",o.oninput=function(){r()},o.onkeydown=function(r){ae(e,r)||he(r,n)||me(e,t,r,s)};var a=document.createElement("span");a.setAttribute("aria-label",window.VditorI18n.link),a.className="vditor-tooltipped vditor-tooltipped__n";var s=document.createElement("input");a.appendChild(s),s.className="vditor-input",s.setAttribute("placeholder",window.VditorI18n.link),s.value=t.getAttribute("href")||"",s.oninput=function(){r()},s.onkeydown=function(r){ae(e,r)||he(r,n)||me(e,t,r,c)};var l=document.createElement("span");l.setAttribute("aria-label",window.VditorI18n.tooltipText),l.className="vditor-tooltipped vditor-tooltipped__n";var c=document.createElement("input");l.appendChild(c),c.className="vditor-input",c.setAttribute("placeholder",window.VditorI18n.tooltipText),c.style.width="60px",c.value=t.getAttribute("title")||"",c.oninput=function(){r()},c.onkeydown=function(r){ae(e,r)||he(r,n)||me(e,t,r,o)},pe(t,e),e.wysiwyg.popover.insertAdjacentElement("beforeend",i),e.wysiwyg.popover.insertAdjacentElement("beforeend",a),e.wysiwyg.popover.insertAdjacentElement("beforeend",l),le(e,t)},he=function(e,t){if(!(0,c.yl)(e)&&!e.shiftKey&&"Enter"===e.key||"Escape"===e.key)return t&&(0,D.Hc)(t),e.preventDefault(),e.stopPropagation(),!0},ve=function(e){"wysiwyg"===e.currentMode?se(e):"ir"===e.currentMode&&Q(e)},ge=function(e,t,n){void 0===n&&(n={enableAddUndoStack:!0,enableHint:!1,enableInput:!0});var r=e.wysiwyg.element;r.innerHTML=e.lute.Md2VditorDOM(t),r.querySelectorAll(".vditor-wysiwyg__preview[data-render='2']").forEach((function(t){O(t,e),t.previousElementSibling.setAttribute("style","display:none")})),$(e,n)},be=function(e,t,n){for(var r=e.startContainer.parentElement,o=!1,a="",s="",l=function(e){var t=te(e.startContainer),n=ee(e.startContainer),r=e.startContainer.textContent,o=e.startOffset,a="",s="";return(""!==r.substr(0,o)&&r.substr(0,o)!==i.g.ZWSP||t)&&(a="".concat(t).concat(r.substr(0,o))),(""!==r.substr(o)&&r.substr(o)!==i.g.ZWSP||n)&&(s="".concat(r.substr(o)).concat(n)),{afterHTML:s,beforeHTML:a}}(e),c=l.beforeHTML,d=l.afterHTML;r&&!o;){var u=r.tagName;if("STRIKE"===u&&(u="S"),"I"===u&&(u="EM"),"B"===u&&(u="STRONG"),"S"===u||"STRONG"===u||"EM"===u){var p="",m="",f="";"0"!==r.parentElement.getAttribute("data-block")&&(m=te(r),f=ee(r)),(c||m)&&(c=p="".concat(m,"<").concat(u,">").concat(c,"").concat(u,">")),("bold"===n&&"STRONG"===u||"italic"===n&&"EM"===u||"strikeThrough"===n&&"S"===u)&&(p+="".concat(a).concat(i.g.ZWSP,"").concat(s),o=!0),(d||f)&&(p+=d="<".concat(u,">").concat(d,"").concat(u,">").concat(f)),"0"!==r.parentElement.getAttribute("data-block")?(r=r.parentElement).innerHTML=p:(r.outerHTML=p,r=r.parentElement),a="<".concat(u,">")+a,s="".concat(u,">")+s}else o=!0}(0,D.ib)(t.wysiwyg.element,e)},ye=function(e,t){var n,r=this;this.element=document.createElement("div"),t.className&&(n=this.element.classList).add.apply(n,t.className.split(" "));var o=t.hotkey?" <".concat((0,c.ns)(t.hotkey),">"):"";2===t.level&&(o=t.hotkey?" <".concat((0,c.ns)(t.hotkey),">"):"");var a=t.tip?t.tip+o:"".concat(window.VditorI18n[t.name]).concat(o),s="upload"===t.name?"div":"button";if(2===t.level)this.element.innerHTML="<".concat(s,' data-type="').concat(t.name,'">').concat(a,"").concat(s,">");else{this.element.classList.add("vditor-toolbar__item");var l=document.createElement(s);l.setAttribute("data-type",t.name),l.className="vditor-tooltipped vditor-tooltipped__".concat(t.tipPosition),l.setAttribute("aria-label",a),l.innerHTML=t.icon,this.element.appendChild(l)}t.prefix&&this.element.children[0].addEventListener((0,c.Le)(),(function(n){n.preventDefault(),r.element.firstElementChild.classList.contains(i.g.CLASS_MENU_DISABLED)||("wysiwyg"===e.currentMode?function(e,t,n){if(!(e.wysiwyg.composingLock&&n instanceof CustomEvent)){var r=!0,o=!0;e.wysiwyg.element.querySelector("wbr")&&e.wysiwyg.element.querySelector("wbr").remove();var a=(0,D.zh)(e),s=t.getAttribute("data-type");if(t.classList.contains("vditor-menu--current"))if("strike"===s&&(s="strikeThrough"),"quote"===s){var l=(0,b.lG)(a.startContainer,"BLOCKQUOTE");l||(l=a.startContainer.childNodes[a.startOffset]),l&&(r=!1,t.classList.remove("vditor-menu--current"),a.insertNode(document.createElement("wbr")),l.outerHTML=""===l.innerHTML.trim()?''.concat(l.innerHTML,"
"):l.innerHTML,(0,D.ib)(e.wysiwyg.element,a))}else if("inline-code"===s){var c=(0,b.lG)(a.startContainer,"CODE");c||(c=a.startContainer.childNodes[a.startOffset]),c&&(c.outerHTML=c.innerHTML.replace(i.g.ZWSP,"")+"",(0,D.ib)(e.wysiwyg.element,a))}else"link"===s?a.collapsed?(a.selectNode(a.startContainer.parentElement),document.execCommand("unlink",!1,"")):document.execCommand("unlink",!1,""):"check"===s||"list"===s||"ordered-list"===s?(ot(e,a,s),(0,D.ib)(e.wysiwyg.element,a),r=!1,t.classList.remove("vditor-menu--current")):(r=!1,t.classList.remove("vditor-menu--current"),""===a.toString()?be(a,e,s):document.execCommand(s,!1,""));else{0===e.wysiwyg.element.childNodes.length&&(e.wysiwyg.element.innerHTML='
',(0,D.ib)(e.wysiwyg.element,a));var u=(0,b.F9)(a.startContainer);if("quote"===s){if(u||(u=a.startContainer.childNodes[a.startOffset]),u){r=!1,t.classList.add("vditor-menu--current"),a.insertNode(document.createElement("wbr"));var p=(0,b.lG)(a.startContainer,"LI");p&&u.contains(p)?p.innerHTML=''.concat(p.innerHTML,"
"):u.outerHTML=''.concat(u.outerHTML,"
"),(0,D.ib)(e.wysiwyg.element,a)}}else if("check"===s||"list"===s||"ordered-list"===s)ot(e,a,s,!1),(0,D.ib)(e.wysiwyg.element,a),r=!1,d(e.toolbar.elements,["check","list","ordered-list"]),t.classList.add("vditor-menu--current");else if("inline-code"===s){if(""===a.toString())(m=document.createElement("code")).textContent=i.g.ZWSP,a.insertNode(m),a.setStart(m.firstChild,1),a.collapse(!0),(0,D.Hc)(a);else if(3===a.startContainer.nodeType){var m=document.createElement("code");a.surroundContents(m),a.insertNode(m),(0,D.Hc)(a)}t.classList.add("vditor-menu--current")}else if("code"===s)(m=document.createElement("div")).className="vditor-wysiwyg__block",m.setAttribute("data-type","code-block"),m.setAttribute("data-block","0"),m.setAttribute("data-marker","```"),""===a.toString()?m.innerHTML="\n
":(m.innerHTML="".concat(a.toString(),"
"),a.deleteContents()),a.insertNode(m),u&&(u.outerHTML=e.lute.SpinVditorDOM(u.outerHTML)),(0,D.ib)(e.wysiwyg.element,a),e.wysiwyg.element.querySelectorAll(".vditor-wysiwyg__preview[data-render='2']").forEach((function(t){O(t,e)})),t.classList.add("vditor-menu--disabled");else if("link"===s){if(""===a.toString()){var f=document.createElement("a");f.innerText=i.g.ZWSP,a.insertNode(f),a.setStart(f.firstChild,1),a.collapse(!0),fe(e,f,a);var h=e.wysiwyg.popover.querySelector("input");h.value="",h.focus(),o=!1}else{(m=document.createElement("a")).setAttribute("href",""),m.innerHTML=a.toString(),a.surroundContents(m),a.insertNode(m),(0,D.Hc)(a),fe(e,m,a);var v=e.wysiwyg.popover.querySelectorAll("input");v[0].value=m.innerText,v[1].focus()}r=!1,t.classList.add("vditor-menu--current")}else if("table"===s){var g='';if(""===a.toString().trim())u&&""===u.innerHTML.trim().replace(i.g.ZWSP,"")?u.outerHTML=g:document.execCommand("insertHTML",!1,g),a.selectNode(e.wysiwyg.element.querySelector("wbr").previousSibling),e.wysiwyg.element.querySelector("wbr").remove(),(0,D.Hc)(a);else{g='';var y=a.toString().split("\n"),w=y[0].split(",").length>y[0].split("\t").length?",":"\t";y.forEach((function(e,t){0===t?(e.split(w).forEach((function(e,t){g+="| ".concat(e,0===t?" | ":"")})),g+="
"):(g+=1===t?"":"
",e.split(w).forEach((function(e){g+="| ".concat(e," | ")})),g+="
")})),g+="
",document.execCommand("insertHTML",!1,g),(0,D.ib)(e.wysiwyg.element,a)}r=!1,t.classList.add("vditor-menu--disabled")}else if("line"===s){if(u){var E='
\n
';""===u.innerHTML.trim()?u.outerHTML=E:u.insertAdjacentHTML("afterend",E),(0,D.ib)(e.wysiwyg.element,a)}}else if(r=!1,t.classList.add("vditor-menu--current"),"strike"===s&&(s="strikeThrough"),""!==a.toString()||"bold"!==s&&"italic"!==s&&"strikeThrough"!==s)document.execCommand(s,!1,"");else{var k="strong";"italic"===s?k="em":"strikeThrough"===s&&(k="s"),(m=document.createElement(k)).textContent=i.g.ZWSP,a.insertNode(m),m.previousSibling&&m.previousSibling.textContent===i.g.ZWSP&&(m.previousSibling.textContent=""),a.setStart(m.firstChild,1),a.collapse(!0),(0,D.Hc)(a)}}r&&se(e),o&&$(e)}}(e,r.element.children[0],n):"ir"===e.currentMode?Nt(e,r.element.children[0],t.prefix||"",t.suffix||""):qe(e,r.element.children[0],t.prefix||"",t.suffix||""))}))},we=(J=function(e,t){return J=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},J(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}J(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),Ee=function(e,t,n){var r;if("string"!=typeof n?(v(e,["subToolbar","hint"]),n.preventDefault(),r=a(e)):r=n,e.currentMode!==t||"string"==typeof n){if(e.devtools&&e.devtools.renderEchart(e),"both"===e.options.preview.mode&&"sv"===t?e.preview.element.style.display="block":e.preview.element.style.display="none",p(e.toolbar.elements,i.g.EDIT_TOOLBARS),d(e.toolbar.elements,i.g.EDIT_TOOLBARS),m(e.toolbar.elements,["outdent","indent"]),"ir"===t)f(e.toolbar.elements,["both"]),h(e.toolbar.elements,["outdent","indent","outline","insert-before","insert-after"]),e.sv.element.style.display="none",e.wysiwyg.element.parentElement.style.display="none",e.ir.element.parentElement.style.display="block",e.lute.SetVditorIR(!0),e.lute.SetVditorWYSIWYG(!1),e.lute.SetVditorSV(!1),e.currentMode="ir",e.ir.element.innerHTML=e.lute.Md2VditorIRDOM(r),At(e,{enableAddUndoStack:!0,enableHint:!1,enableInput:!1}),K(e),e.ir.element.querySelectorAll(".vditor-ir__preview[data-render='2']").forEach((function(t){O(t,e)})),e.ir.element.querySelectorAll(".vditor-toc").forEach((function(t){(0,M.H)(t,{cdn:e.options.cdn,math:e.options.preview.math})}));else if("wysiwyg"===t)f(e.toolbar.elements,["both"]),h(e.toolbar.elements,["outdent","indent","outline","insert-before","insert-after"]),e.sv.element.style.display="none",e.wysiwyg.element.parentElement.style.display="block",e.ir.element.parentElement.style.display="none",e.lute.SetVditorIR(!1),e.lute.SetVditorWYSIWYG(!0),e.lute.SetVditorSV(!1),e.currentMode="wysiwyg",K(e),ge(e,r,{enableAddUndoStack:!0,enableHint:!1,enableInput:!1}),e.wysiwyg.element.querySelectorAll(".vditor-toc").forEach((function(t){(0,M.H)(t,{cdn:e.options.cdn,math:e.options.preview.math})})),e.wysiwyg.popover.style.display="none";else if("sv"===t){h(e.toolbar.elements,["both"]),f(e.toolbar.elements,["outdent","indent","outline","insert-before","insert-after"]),e.wysiwyg.element.parentElement.style.display="none",e.ir.element.parentElement.style.display="none",("both"===e.options.preview.mode||"editor"===e.options.preview.mode)&&(e.sv.element.style.display="block"),e.lute.SetVditorIR(!1),e.lute.SetVditorWYSIWYG(!1),e.lute.SetVditorSV(!0),e.currentMode="sv";var o=Ie(r,e);""===o&&(o=""),e.sv.element.innerHTML=o,U(e.sv.element),Re(e,{enableAddUndoStack:!0,enableHint:!1,enableInput:!1}),K(e)}e.undo.resetIcon(e),"string"!=typeof n&&(e[e.currentMode].element.focus(),ve(e)),I(e),F(e),e.toolbar.elements["edit-mode"]&&(e.toolbar.elements["edit-mode"].querySelectorAll("button").forEach((function(e){e.classList.remove("vditor-menu--current")})),e.toolbar.elements["edit-mode"].querySelector('button[data-mode="'.concat(e.currentMode,'"]')).classList.add("vditor-menu--current")),e.outline.toggle(e,"sv"!==e.currentMode&&e.options.outline.enable,"string"!=typeof n)}},ke=function(e){function t(t,n){var r=e.call(this,t,n)||this,i=document.createElement("div");return i.className="vditor-hint".concat(2===n.level?"":" vditor-panel--arrow"),i.innerHTML='\n\n"),r.element.appendChild(i),r._bindEvent(t,i,n),r}return we(t,e),t.prototype._bindEvent=function(e,t,n){var r=this.element.children[0];g(e,t,r,n.level),t.children.item(0).addEventListener((0,c.Le)(),(function(t){Ee(e,"wysiwyg",t),t.preventDefault(),t.stopPropagation()})),t.children.item(1).addEventListener((0,c.Le)(),(function(t){Ee(e,"ir",t),t.preventDefault(),t.stopPropagation()})),t.children.item(2).addEventListener((0,c.Le)(),(function(t){Ee(e,"sv",t),t.preventDefault(),t.stopPropagation()}))},t}(ye),Se=function(e,t){return(0,D.Gb)(e,t)?getSelection().toString():""},Le=function(e,t){t.addEventListener("focus",(function(){e.options.focus&&e.options.focus(a(e)),v(e,["subToolbar","hint"])}))},Te=function(e,t){t.addEventListener("dblclick",(function(t){"IMG"===t.target.tagName&&(e.options.image.preview?e.options.image.preview(t.target):e.options.image.isPreview&&(0,V.E)(t.target,e.options.lang,e.options.theme))}))},Ce=function(e,t){t.addEventListener("blur",(function(t){if("ir"===e.currentMode){var n=e.ir.element.querySelector(".vditor-ir__node--expand");n&&n.classList.remove("vditor-ir__node--expand")}else"wysiwyg"!==e.currentMode||e.wysiwyg.selectPopover.contains(t.relatedTarget)||e.wysiwyg.hideComment();e[e.currentMode].range=(0,D.zh)(e),e.options.blur&&e.options.blur(a(e))}))},Me=function(e,t){t.addEventListener("dragstart",(function(e){e.dataTransfer.setData(i.g.DROP_EDITOR,i.g.DROP_EDITOR)})),t.addEventListener("drop",(function(t){t.dataTransfer.getData(i.g.DROP_EDITOR)?ut(e):(t.dataTransfer.types.includes("Files")||t.dataTransfer.types.includes("text/html"))&&Mt(e,t,{pasteCode:function(e){document.execCommand("insertHTML",!1,e)}})}))},xe=function(e,t,n){t.addEventListener("copy",(function(t){return n(t,e)}))},Ae=function(e,t,n){t.addEventListener("cut",(function(t){n(t,e),e.options.comment.enable&&"wysiwyg"===e.currentMode&&e.wysiwyg.getComments(e),document.execCommand("delete")}))},_e=function(e){if("wysiwyg"===e.currentMode&&e.options.comment.enable&&e.options.comment.adjustTop(e.wysiwyg.getComments(e,!0)),e.options.typewriterMode){var t=e[e.currentMode].element,n=(0,D.Ny)(t).top;"auto"!==e.options.height||e.element.classList.contains("vditor--fullscreen")||window.scrollTo(window.scrollX,n+e.element.offsetTop+e.toolbar.element.offsetHeight-window.innerHeight/2+10),("auto"!==e.options.height||e.element.classList.contains("vditor--fullscreen"))&&(t.scrollTop=n+t.scrollTop-t.clientHeight/2+10)}},He=function(e,t){t.addEventListener("keydown",(function(t){if(!t.isComposing&&e.options.keydown&&e.options.keydown(t),!(e.options.hint.extend.length>1||e.toolbar.elements.emoji)||!e.hint.select(t,e)){if(e.options.comment.enable&&"wysiwyg"===e.currentMode&&("Backspace"===t.key||q("⌘X",t))&&e.wysiwyg.getComments(e),"sv"===e.currentMode){if(function(e,t){var n,r,i,o,a;if(e.sv.composingLock=t.isComposing,t.isComposing)return!1;if(-1!==t.key.indexOf("Arrow")||"Meta"===t.key||"Control"===t.key||"Alt"===t.key||"Shift"===t.key||"CapsLock"===t.key||"Escape"===t.key||/^F\d{1,2}$/.test(t.key)||e.undo.recordFirstPosition(e,t),"Enter"!==t.key&&"Tab"!==t.key&&"Backspace"!==t.key&&-1===t.key.indexOf("Arrow")&&!(0,c.yl)(t)&&"Escape"!==t.key)return!1;var s=(0,D.zh)(e),l=s.startContainer;3!==s.startContainer.nodeType&&"DIV"===s.startContainer.tagName&&(l=s.startContainer.childNodes[s.startOffset-1]);var d=(0,b.a1)(l,"data-type","text"),u=(0,b.a1)(l,"data-type","blockquote-marker");if(!u&&0===s.startOffset&&d&&d.previousElementSibling&&"blockquote-marker"===d.previousElementSibling.getAttribute("data-type")&&(u=d.previousElementSibling),u&&"Enter"===t.key&&!(0,c.yl)(t)&&!t.altKey&&""===u.nextElementSibling.textContent.trim()&&(0,D.im)(u,e.sv.element,s).start===u.textContent.length)return"padding"===(null===(n=u.previousElementSibling)||void 0===n?void 0:n.getAttribute("data-type"))&&u.previousElementSibling.setAttribute("data-action","enter-remove"),u.remove(),Re(e),t.preventDefault(),!0;var p=(0,b.a1)(l,"data-type","li-marker"),m=(0,b.a1)(l,"data-type","task-marker"),f=p;if(f||m&&"task-marker"!==m.nextElementSibling.getAttribute("data-type")&&(f=m),f||0!==s.startOffset||!d||!d.previousElementSibling||"li-marker"!==d.previousElementSibling.getAttribute("data-type")&&"task-marker"!==d.previousElementSibling.getAttribute("data-type")||(f=d.previousElementSibling),f){var h=(0,D.im)(f,e.sv.element,s).start,v="task-marker"===f.getAttribute("data-type"),g=f;if(v&&(g=f.previousElementSibling.previousElementSibling.previousElementSibling),h===f.textContent.length){if("Enter"===t.key&&!(0,c.yl)(t)&&!t.altKey&&!t.shiftKey&&""===f.nextElementSibling.textContent.trim())return"padding"===(null===(r=g.previousElementSibling)||void 0===r?void 0:r.getAttribute("data-type"))?(g.previousElementSibling.remove(),W(e)):(v&&(g.remove(),f.previousElementSibling.previousElementSibling.remove(),f.previousElementSibling.remove()),f.nextElementSibling.remove(),f.remove(),Re(e)),t.preventDefault(),!0;if("Tab"===t.key)return t.shiftKey?"padding"===g.previousElementSibling.getAttribute("data-type")&&g.previousElementSibling.remove():g.insertAdjacentHTML("beforebegin",''.concat(g.textContent.replace(/\S/g," "),"")),/^\d/.test(g.textContent)&&(g.textContent=g.textContent.replace(/^\d{1,}/,"1"),s.selectNodeContents(f.firstChild),s.collapse(!1)),W(e),t.preventDefault(),!0}}if(mt(e,s,t))return!0;var w=(0,b.a1)(l,"data-block","0"),E=(0,y.S)(l,"SPAN");if("Enter"===t.key&&!(0,c.yl)(t)&&!t.altKey&&!t.shiftKey&&w){var k=!1,S=w.textContent.match(/^\n+/);(0,D.im)(w,e.sv.element).start<=(S?S[0].length:0)&&(k=!0);var L="\n";if(E){if("enter-remove"===(null===(i=E.previousElementSibling)||void 0===i?void 0:i.getAttribute("data-action")))return E.previousElementSibling.remove(),Re(e),t.preventDefault(),!0;L+=je(E)}return s.insertNode(document.createTextNode(L)),s.collapse(!1),w&&""!==w.textContent.trim()&&!k?W(e):Re(e),t.preventDefault(),!0}if("Backspace"===t.key&&!(0,c.yl)(t)&&!t.altKey&&!t.shiftKey){if(E&&"newline"===(null===(o=E.previousElementSibling)||void 0===o?void 0:o.getAttribute("data-type"))&&1===(0,D.im)(E,e.sv.element,s).start&&-1===E.getAttribute("data-type").indexOf("code-block-"))return s.setStart(E,0),s.extractContents(),""!==E.textContent.trim()?W(e):Re(e),t.preventDefault(),!0;if(w&&0===(0,D.im)(w,e.sv.element,s).start&&w.previousElementSibling){s.extractContents();var T=w.previousElementSibling.lastElementChild;return"newline"===T.getAttribute("data-type")&&(T.remove(),T=w.previousElementSibling.lastElementChild),"newline"!==T.getAttribute("data-type")&&(T.insertAdjacentHTML("afterend",w.innerHTML),w.remove()),""===w.textContent.trim()||(null===(a=w.previousElementSibling)||void 0===a?void 0:a.querySelector('[data-type="code-block-open-marker"]'))?("newline"!==T.getAttribute("data-type")&&(s.selectNodeContents(T.lastChild),s.collapse(!1)),Re(e)):W(e),t.preventDefault(),!0}}return!1}(e,t))return}else if("wysiwyg"===e.currentMode){if(function(e,t){if(e.wysiwyg.composingLock=t.isComposing,t.isComposing)return!1;-1!==t.key.indexOf("Arrow")||"Meta"===t.key||"Control"===t.key||"Alt"===t.key||"Shift"===t.key||"CapsLock"===t.key||"Escape"===t.key||/^F\d{1,2}$/.test(t.key)||e.undo.recordFirstPosition(e,t);var n=(0,D.zh)(e),r=n.startContainer;if(!Xe(t,e,r))return!1;if(Ye(n,e,t),Tt(n),"Enter"!==t.key&&"Tab"!==t.key&&"Backspace"!==t.key&&-1===t.key.indexOf("Arrow")&&!(0,c.yl)(t)&&"Escape"!==t.key&&"Delete"!==t.key)return!1;var o=(0,b.F9)(r),a=(0,b.lG)(r,"P");if(ft(t,e,a,n))return!0;if(pt(n,e,a,t))return!0;if(wt(e,t,n))return!0;var s=(0,b.fb)(r,"vditor-wysiwyg__block");if(s){if("Escape"===t.key&&2===s.children.length)return e.wysiwyg.popover.style.display="none",s.firstElementChild.style.display="none",e.wysiwyg.element.blur(),t.preventDefault(),!0;if(!(0,c.yl)(t)&&!t.shiftKey&&t.altKey&&"Enter"===t.key&&"code-block"===s.getAttribute("data-type")){var l=e.wysiwyg.popover.querySelector(".vditor-input");return l.focus(),l.select(),t.preventDefault(),!0}if("0"===s.getAttribute("data-block")){if(Et(e,t,s.firstElementChild,n))return!0;if(rt(e,t,n,s.firstElementChild,s))return!0;if("yaml-front-matter"!==s.getAttribute("data-type")&&it(e,t,n,s.firstElementChild,s))return!0}}if(kt(e,n,t,a))return!0;var d=(0,b.E2)(r,"BLOCKQUOTE");if(d&&!t.shiftKey&&t.altKey&&"Enter"===t.key){(0,c.yl)(t)?n.setStartBefore(d):n.setStartAfter(d),(0,D.Hc)(n);var u=document.createElement("p");return u.setAttribute("data-block","0"),u.innerHTML="\n",n.insertNode(u),n.collapse(!0),(0,D.Hc)(n),$(e),_e(e),t.preventDefault(),!0}var p,m=(0,y.W)(r);if(m){if("H6"===m.tagName&&r.textContent.length===n.startOffset&&!(0,c.yl)(t)&&!t.shiftKey&&!t.altKey&&"Enter"===t.key){var f=document.createElement("p");return f.textContent="\n",f.setAttribute("data-block","0"),r.parentElement.insertAdjacentElement("afterend",f),n.setStart(f,0),(0,D.Hc)(n),$(e),_e(e),t.preventDefault(),!0}var h;if(q("⌘=",t))return(h=parseInt(m.tagName.substr(1),10)-1)>0&&(re(e,"h".concat(h)),$(e)),t.preventDefault(),!0;if(q("⌘-",t))return(h=parseInt(m.tagName.substr(1),10)+1)<7&&(re(e,"h".concat(h)),$(e)),t.preventDefault(),!0;"Backspace"!==t.key||(0,c.yl)(t)||t.shiftKey||t.altKey||1!==m.textContent.length||ie(e)}if(St(e,n,t))return!0;if(t.altKey&&"Enter"===t.key&&!(0,c.yl)(t)&&!t.shiftKey){var v=(0,b.lG)(r,"A"),g=(0,b.a1)(r,"data-type","link-ref"),w=(0,b.a1)(r,"data-type","footnotes-ref");if(v||g||w||m&&2===m.tagName.length){var E=e.wysiwyg.popover.querySelector("input");E.focus(),E.select()}}if(ae(e,t))return!0;if(q("⇧⌘U",t)&&(p=e.wysiwyg.popover.querySelector('[data-type="up"]')))return p.click(),t.preventDefault(),!0;if(q("⇧⌘D",t)&&(p=e.wysiwyg.popover.querySelector('[data-type="down"]')))return p.click(),t.preventDefault(),!0;if(mt(e,n,t))return!0;if(!(0,c.yl)(t)&&t.shiftKey&&!t.altKey&&"Enter"===t.key&&"LI"!==r.parentElement.tagName&&"P"!==r.parentElement.tagName)return["STRONG","STRIKE","S","I","EM","B"].includes(r.parentElement.tagName)?n.insertNode(document.createTextNode("\n"+i.g.ZWSP)):n.insertNode(document.createTextNode("\n")),n.collapse(!1),(0,D.Hc)(n),$(e),_e(e),t.preventDefault(),!0;if("Backspace"===t.key&&!(0,c.yl)(t)&&!t.shiftKey&&!t.altKey&&""===n.toString()){if(Lt(e,n,t,a))return!0;if(o){if(o.previousElementSibling&&o.previousElementSibling.classList.contains("vditor-wysiwyg__block")&&"0"===o.previousElementSibling.getAttribute("data-block")&&"UL"!==o.tagName&&"OL"!==o.tagName){var k=(0,D.im)(o,e.wysiwyg.element,n).start;if(0===k&&0===n.startOffset||1===k&&o.innerText.startsWith(i.g.ZWSP))return oe(o.previousElementSibling.lastElementChild,e,!1),""===o.innerHTML.trim().replace(i.g.ZWSP,"")&&(o.remove(),$(e)),t.preventDefault(),!0}var S=n.startOffset;if(""===n.toString()&&3===r.nodeType&&"\n"===r.textContent.charAt(S-2)&&r.textContent.charAt(S-1)!==i.g.ZWSP&&["STRONG","STRIKE","S","I","EM","B"].includes(r.parentElement.tagName))return r.textContent=r.textContent.substring(0,S-1)+i.g.ZWSP,n.setStart(r,S),n.collapse(!0),$(e),t.preventDefault(),!0;r.textContent===i.g.ZWSP&&1===n.startOffset&&!r.previousSibling&&function(e){for(var t=e.startContainer.nextSibling;t&&""===t.textContent;)t=t.nextSibling;return!(!t||3===t.nodeType||"CODE"!==t.tagName&&"math-inline"!==t.getAttribute("data-type")&&"html-entity"!==t.getAttribute("data-type")&&"html-inline"!==t.getAttribute("data-type"))}(n)&&(r.textContent=""),o.querySelectorAll("span.vditor-wysiwyg__block[data-type='math-inline']").forEach((function(e){e.firstElementChild.style.display="inline",e.lastElementChild.style.display="none"})),o.querySelectorAll("span.vditor-wysiwyg__block[data-type='html-entity']").forEach((function(e){e.firstElementChild.style.display="inline",e.lastElementChild.style.display="none"}))}}if((0,c.vU)()&&1===n.startOffset&&r.textContent.indexOf(i.g.ZWSP)>-1&&r.previousSibling&&3!==r.previousSibling.nodeType&&"CODE"===r.previousSibling.tagName&&("Backspace"===t.key||"ArrowLeft"===t.key))return n.selectNodeContents(r.previousSibling),n.collapse(!1),t.preventDefault(),!0;if(Ct(t,o,n))return t.preventDefault(),!0;if(Qe(n,t.key),"ArrowDown"===t.key){var L=r.nextSibling;L&&3!==L.nodeType&&"math-inline"===L.getAttribute("data-type")&&n.setStartAfter(L)}return!(!o||!R(o,e,t,n)||(t.preventDefault(),0))}(e,t))return}else if("ir"===e.currentMode&&function(e,t){if(e.ir.composingLock=t.isComposing,t.isComposing)return!1;-1!==t.key.indexOf("Arrow")||"Meta"===t.key||"Control"===t.key||"Alt"===t.key||"Shift"===t.key||"CapsLock"===t.key||"Escape"===t.key||/^F\d{1,2}$/.test(t.key)||e.undo.recordFirstPosition(e,t);var n=(0,D.zh)(e),r=n.startContainer;if(!Xe(t,e,r))return!1;if(Ye(n,e,t),Tt(n),"Enter"!==t.key&&"Tab"!==t.key&&"Backspace"!==t.key&&-1===t.key.indexOf("Arrow")&&!(0,c.yl)(t)&&"Escape"!==t.key&&"Delete"!==t.key)return!1;var o=(0,b.a1)(r,"data-newline","1");if(!(0,c.yl)(t)&&!t.altKey&&!t.shiftKey&&"Enter"===t.key&&o&&n.startOffset-1&&f){var h=et(f);if(h&&it(e,t,n,f,h))return!0;var g=tt(f);if(g&&rt(e,t,n,f,g))return!0}if(wt(e,t,n))return!0;if(St(e,n,t))return!0;if(mt(e,n,t))return!0;var w=(0,y.W)(r);if(w){var E;if(q("⌘=",t))return(E=w.querySelector(".vditor-ir__marker--heading"))&&E.textContent.trim().length>1&&_t(e,E.textContent.substr(1)),t.preventDefault(),!0;if(q("⌘-",t))return(E=w.querySelector(".vditor-ir__marker--heading"))&&E.textContent.trim().length<6&&_t(e,E.textContent.trim()+"# "),t.preventDefault(),!0}var k=(0,b.F9)(r);if("Backspace"===t.key&&!(0,c.yl)(t)&&!t.shiftKey&&!t.altKey&&""===n.toString()){if(Lt(e,n,t,l))return!0;if(k&&k.previousElementSibling&&"UL"!==k.tagName&&"OL"!==k.tagName&&("code-block"===k.previousElementSibling.getAttribute("data-type")||"math-block"===k.previousElementSibling.getAttribute("data-type"))){var S=(0,D.im)(k,e.ir.element,n).start;if(0===S||1===S&&k.innerText.startsWith(i.g.ZWSP))return n.selectNodeContents(k.previousElementSibling.querySelector(".vditor-ir__marker--pre code")),n.collapse(!1),B(n,e),""===k.textContent.trim().replace(i.g.ZWSP,"")&&(k.remove(),At(e)),t.preventDefault(),!0}if(w){var L=w.firstElementChild.textContent.length;(0,D.im)(w,e.ir.element).start===L&&0!==L&&(n.setStart(w.firstElementChild.firstChild,L-1),n.collapse(!0),(0,D.Hc)(n))}}return!(("ArrowUp"!==t.key&&"ArrowDown"!==t.key||!k||(k.querySelectorAll(".vditor-ir__node").forEach((function(e){e.contains(r)||e.classList.add("vditor-ir__node--hidden")})),!Ct(t,k,n)))&&(Qe(n,t.key),!k||!R(k,e,t,n)||(t.preventDefault(),0)))}(e,t))return;if(e.options.ctrlEnter&&q("⌘Enter",t))return e.options.ctrlEnter(a(e)),void t.preventDefault();if(q("⌘Z",t)&&!e.toolbar.elements.undo)return e.undo.undo(e),void t.preventDefault();if(q("⌘Y",t)&&!e.toolbar.elements.redo)return e.undo.redo(e),void t.preventDefault();if("Escape"===t.key)return"block"===e.hint.element.style.display?e.hint.element.style.display="none":e.options.esc&&!t.isComposing&&e.options.esc(a(e)),void t.preventDefault();if((0,c.yl)(t)&&t.altKey&&!t.shiftKey&&/^Digit[1-6]$/.test(t.code)){if("wysiwyg"===e.currentMode){var n=t.code.replace("Digit","H");(0,b.lG)(getSelection().getRangeAt(0).startContainer,n)?ie(e):re(e,n),$(e)}else"sv"===e.currentMode?Pe(e,"#".repeat(parseInt(t.code.replace("Digit",""),10))+" "):"ir"===e.currentMode&&_t(e,"#".repeat(parseInt(t.code.replace("Digit",""),10))+" ");return t.preventDefault(),!0}if((0,c.yl)(t)&&t.altKey&&!t.shiftKey&&/^Digit[7-9]$/.test(t.code))return"Digit7"===t.code?Ee(e,"wysiwyg",t):"Digit8"===t.code?Ee(e,"ir",t):"Digit9"===t.code&&Ee(e,"sv",t),!0;e.options.toolbar.find((function(n){return!n.hotkey||n.toolbar?!!n.toolbar&&!!n.toolbar.find((function(n){return!!n.hotkey&&(q(n.hotkey,t)?(e.toolbar.elements[n.name].children[0].dispatchEvent(new CustomEvent((0,c.Le)())),t.preventDefault(),!0):void 0)})):q(n.hotkey,t)?(e.toolbar.elements[n.name].children[0].dispatchEvent(new CustomEvent((0,c.Le)())),t.preventDefault(),!0):void 0}))}}))},Ne=function(e,t){t.addEventListener("selectstart",(function(n){t.onmouseup=function(){setTimeout((function(){var t=Se(e[e.currentMode].element);t.trim()?("wysiwyg"===e.currentMode&&e.options.comment.enable&&((0,b.a1)(n.target,"data-type","footnotes-block")||(0,b.a1)(n.target,"data-type","link-ref-defs-block")?e.wysiwyg.hideComment():e.wysiwyg.showComment()),e.options.select&&e.options.select(t)):("wysiwyg"===e.currentMode&&e.options.comment.enable&&e.wysiwyg.hideComment(),"function"==typeof e.options.unSelect&&e.options.unSelect())}))}}))},Oe=function(e,t){var n=(0,D.zh)(e);n.extractContents(),n.insertNode(document.createTextNode(Lute.Caret)),n.insertNode(document.createTextNode(t));var r=(0,b.a1)(n.startContainer,"data-block","0");r||(r=e.sv.element);var i=e.lute.SpinVditorSVDOM(r.textContent);i=""+i.replace(/
\n<\/span><\/span>
\n<\/span><\/span>
\n
\n
<')+"
",r.isEqualNode(e.sv.element)?r.innerHTML=i:r.outerHTML=i,U(e.sv.element),(0,D.ib)(e.sv.element,n),_e(e)},De=function(e,t,n){void 0===n&&(n=!0);var r=e;for(3===r.nodeType&&(r=r.parentElement);r;){if(r.getAttribute("data-type")===t)return r;r=n?r.previousElementSibling:r.nextElementSibling}return!1},Ie=function(e,t){return w("SpinVditorSVDOM",e,"argument",t.options.debugger),e=""+t.lute.SpinVditorSVDOM(e).replace(/
\n<\/span><\/span>
\n<\/span><\/span>
\n
\n
<')+"
",w("SpinVditorSVDOM",e,"result",t.options.debugger),e},je=function(e){var t=e.getAttribute("data-type"),n=e.previousElementSibling,r=t&&"text"!==t&&"table"!==t&&"heading-marker"!==t&&"newline"!==t&&"yaml-front-matter-open-marker"!==t&&"yaml-front-matter-close-marker"!==t&&"code-block-info"!==t&&"code-block-close-marker"!==t&&"code-block-open-marker"!==t?e.textContent:"",i=!1;for("newline"===t&&(i=!0);n&&!i;){var o=n.getAttribute("data-type");if("li-marker"===o||"blockquote-marker"===o||"task-marker"===o||"padding"===o){var a=n.textContent;if("li-marker"!==o||"code-block-open-marker"!==t&&"code-block-info"!==t)if("code-block-close-marker"===t&&n.nextElementSibling.isSameNode(e)){var s=De(e,"code-block-open-marker");s&&s.previousElementSibling&&(n=s.previousElementSibling,r=a+r)}else r=a+r;else r=a.replace(/\S/g," ")+r}else"newline"===o&&(i=!0);n=n.previousElementSibling}return r},Re=function(e,t){void 0===t&&(t={enableAddUndoStack:!0,enableHint:!1,enableInput:!0}),t.enableHint&&e.hint.render(e),e.preview.render(e);var n=a(e);"function"==typeof e.options.input&&t.enableInput&&e.options.input(n),e.options.counter.enable&&e.counter.render(e,n),e.options.cache.enable&&(0,c.pK)()&&(localStorage.setItem(e.options.cache.id,n),e.options.cache.after&&e.options.cache.after(n)),e.devtools&&e.devtools.renderEchart(e),clearTimeout(e.sv.processTimeoutId),e.sv.processTimeoutId=window.setTimeout((function(){t.enableAddUndoStack&&!e.sv.composingLock&&e.undo.addToUndoStack(e)}),e.options.undoDelay)},Pe=function(e,t){var n=(0,D.zh)(e),r=(0,y.S)(n.startContainer,"SPAN");r&&""!==r.textContent.trim()&&(t="\n"+t),n.collapse(!0),document.execCommand("insertHTML",!1,t)},qe=function(e,t,n,r){var i=(0,D.zh)(e),o=t.getAttribute("data-type");0===e.sv.element.childNodes.length&&(e.sv.element.innerHTML='
\n',(0,D.ib)(e.sv.element,i));var a=(0,b.F9)(i.startContainer),s=(0,y.S)(i.startContainer,"SPAN");if(a){if("link"===o){var l=void 0;return l=""===i.toString()?"".concat(n).concat(Lute.Caret).concat(r):"".concat(n).concat(i.toString()).concat(r.replace(")",Lute.Caret+")")),void document.execCommand("insertHTML",!1,l)}if("italic"===o||"bold"===o||"strike"===o||"inline-code"===o||"code"===o||"table"===o||"line"===o){l=void 0;return l=""===i.toString()?"".concat(n).concat(Lute.Caret).concat("code"===o?"":r):"".concat(n).concat(i.toString()).concat(Lute.Caret).concat("code"===o?"":r),"table"===o||"code"===o&&s&&""!==s.textContent?l="\n\n"+l:"line"===o&&(l="\n\n".concat(n,"\n").concat(Lute.Caret)),void document.execCommand("insertHTML",!1,l)}if(("check"===o||"list"===o||"ordered-list"===o||"quote"===o)&&s){var c="* ";"check"===o?c="* [ ] ":"ordered-list"===o?c="1. ":"quote"===o&&(c="> ");var d=De(s,"newline");return d?d.insertAdjacentText("afterend",c):a.insertAdjacentText("afterbegin",c),void W(e)}(0,D.ib)(e.sv.element,i),Re(e)}},Be=function(e){switch(e.currentMode){case"ir":return e.ir.element;case"wysiwyg":return e.wysiwyg.element;case"sv":return e.sv.element}},Ve=function(e,t){e.options.upload.setHeaders&&(e.options.upload.headers=e.options.upload.setHeaders()),e.options.upload.headers&&Object.keys(e.options.upload.headers).forEach((function(n){t.setRequestHeader(n,e.options.upload.headers[n])}))},Ue=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))},We=function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]".concat(window.VditorI18n.nameEmpty,""),l=!1),s.size>e.options.upload.max&&(r+="".concat(s.name," ").concat(window.VditorI18n.over," ").concat(e.options.upload.max/1024/1024,"M"),l=!1);var c=s.name.lastIndexOf("."),d=s.name.substr(c),u=e.options.upload.filename(s.name.substr(0,c))+d;e.options.upload.accept&&(e.options.upload.accept.split(",").some((function(e){var t=e.trim();if(0===t.indexOf(".")){if(d.toLowerCase()===t.toLowerCase())return!0}else if(s.type.split("/")[0]===t.split("/")[0])return!0;return!1}))||(r+="".concat(s.name," ").concat(window.VditorI18n.fileTypeError,""),l=!1)),l&&(n.push(s),i+="".concat(u," ").concat(window.VditorI18n.uploading,' ').concat(window.VditorI18n.cancelUpload,""))}),a=t.length,s=0;s".concat(r).concat(i,"")),e.options.upload.cancel){var l=e.tip.element.querySelector(".vditorCancelUpload");l&&l.addEventListener("click",(function(){e.options.upload.cancel(n),e.tip.hide(),e.upload.isUploading=!1}))}return n}(e,r),0===l.length)return n&&(n.value=""),[2];for(c=new FormData,d=e.options.upload.extraData,u=0,p=Object.keys(d);u=200&&v.status<300)if(e.options.upload.success)e.options.upload.success(s,v.responseText);else{var r=v.responseText;e.options.upload.format&&(r=e.options.upload.format(t,v.responseText)),function(e,t){Be(t).focus();var n=JSON.parse(e),r="";1===n.code&&(r="".concat(n.msg)),n.data.errFiles&&n.data.errFiles.length>0&&(r="- ".concat(r,"
"),n.data.errFiles.forEach((function(e){var n=e.lastIndexOf("."),i=t.options.upload.filename(e.substr(0,n))+e.substr(n);r+="- ".concat(i," ").concat(window.VditorI18n.uploadError,"
")})),r+="
"),r?t.tip.show(r):t.tip.hide();var i="";Object.keys(n.data.succMap).forEach((function(e){var r=n.data.succMap[e],o=e.lastIndexOf("."),a=e.substr(o),s=t.options.upload.filename(e.substr(0,o))+a;0===(a=a.toLowerCase()).indexOf(".wav")||0===a.indexOf(".mp3")||0===a.indexOf(".ogg")?"wysiwyg"===t.currentMode?i+='<audio controls="controls" src="'.concat(r,'"></audio>
\n'):"ir"===t.currentMode?i+='\n'):i+="[".concat(s,"](").concat(r,")\n"):0===a.indexOf(".apng")||0===a.indexOf(".bmp")||0===a.indexOf(".gif")||0===a.indexOf(".ico")||0===a.indexOf(".cur")||0===a.indexOf(".jpg")||0===a.indexOf(".jpeg")||0===a.indexOf(".jfif")||0===a.indexOf(".pjp")||0===a.indexOf(".pjpeg")||0===a.indexOf(".png")||0===a.indexOf(".svg")||0===a.indexOf(".webp")?"wysiwyg"===t.currentMode?i+='
\n'):i+=".concat(r,")\n"):"wysiwyg"===t.currentMode?i+='').concat(s,"\n"):i+="[".concat(s,"](").concat(r,")\n")})),(0,D.Hc)(t.upload.range),document.execCommand("insertHTML",!1,i),t.upload.range=getSelection().getRangeAt(0).cloneRange()}(r,e)}else e.options.upload.error?e.options.upload.error(v.responseText):e.tip.show(v.responseText);n&&(n.value=""),e.upload.element.style.display="none",e.upload.xhr=void 0}},v.upload.onprogress=function(t){if(t.lengthComputable){var n=t.loaded/t.total*100;e.upload.element.style.display="block",e.upload.element.style.width=n+"%"}},v.send(c),[2]}}))}))},Ke=function(e,t,n){var r,o=(0,b.F9)(t.startContainer);if(o||(o=e.wysiwyg.element),n&&"formatItalic"!==n.inputType&&"deleteByDrag"!==n.inputType&&"insertFromDrop"!==n.inputType&&"formatBold"!==n.inputType&&"formatRemove"!==n.inputType&&"formatStrikeThrough"!==n.inputType&&"insertUnorderedList"!==n.inputType&&"insertOrderedList"!==n.inputType&&"formatOutdent"!==n.inputType&&"formatIndent"!==n.inputType&&""!==n.inputType||!n){var a=function(e){for(var t=e.previousSibling;t;){if(3!==t.nodeType&&"A"===t.tagName&&!t.previousSibling&&""===t.innerHTML.replace(i.g.ZWSP,"")&&t.nextSibling)return t;t=t.previousSibling}return!1}(t.startContainer);a&&a.remove(),e.wysiwyg.element.querySelectorAll("wbr").forEach((function(e){e.remove()})),t.insertNode(document.createElement("wbr")),o.querySelectorAll("[style]").forEach((function(e){e.removeAttribute("style")})),o.querySelectorAll(".vditor-comment").forEach((function(e){""===e.textContent.trim()&&(e.classList.remove("vditor-comment","vditor-comment--focus"),e.removeAttribute("data-cmtids"))})),null===(r=o.previousElementSibling)||void 0===r||r.querySelectorAll(".vditor-comment").forEach((function(e){""===e.textContent.trim()&&(e.classList.remove("vditor-comment","vditor-comment--focus"),e.removeAttribute("data-cmtids"))}));var s="";"link-ref-defs-block"===o.getAttribute("data-type")&&(o=e.wysiwyg.element);var l,c=o.isEqualNode(e.wysiwyg.element),d=(0,b.a1)(o,"data-type","footnotes-block");if(c)s=o.innerHTML;else{var u=(0,b.O9)(t.startContainer);if(u&&!d){var p=(0,y.S)(t.startContainer,"BLOCKQUOTE");o=p?(0,b.F9)(t.startContainer)||o:u}if(d&&(o=d),s=o.outerHTML,"UL"===o.tagName||"OL"===o.tagName){var m=o.previousElementSibling,f=o.nextElementSibling;!m||"UL"!==m.tagName&&"OL"!==m.tagName||(s=m.outerHTML+s,m.remove()),!f||"UL"!==f.tagName&&"OL"!==f.tagName||(s+=f.outerHTML,f.remove()),s=s.replace("
","
")}o.innerText.startsWith("```")||(e.wysiwyg.element.querySelectorAll("[data-type='link-ref-defs-block']").forEach((function(e){e&&!o.isEqualNode(e)&&(s+=e.outerHTML,e.remove())})),e.wysiwyg.element.querySelectorAll("[data-type='footnotes-block']").forEach((function(e){e&&!o.isEqualNode(e)&&(s+=e.outerHTML,e.remove())})))}if('```
'===(s=s.replace(/<\/(strong|b)>/g,"").replace(/<\/(em|i)>/g,"").replace(/<\/(s|strike)>/g,""))&&e.hint.recentLanguage&&(s='```
'.replace("```","```"+e.hint.recentLanguage)),w("SpinVditorDOM",s,"argument",e.options.debugger),s=e.lute.SpinVditorDOM(s),w("SpinVditorDOM",s,"result",e.options.debugger),c)o.innerHTML=s;else if(o.outerHTML=s,d){var h=(0,b.E2)(e.wysiwyg.element.querySelector("wbr"),"LI");if(h){var v=e.wysiwyg.element.querySelector('sup[data-type="footnotes-ref"][data-footnotes-label="'.concat(h.getAttribute("data-marker"),'"]'));v&&v.setAttribute("aria-label",h.textContent.trim().substr(0,24))}}var g,E=e.wysiwyg.element.querySelectorAll("[data-type='link-ref-defs-block']");E.forEach((function(e,t){0===t?l=e:(l.insertAdjacentHTML("beforeend",e.innerHTML),e.remove())})),E.length>0&&e.wysiwyg.element.insertAdjacentElement("beforeend",E[0]);var k=e.wysiwyg.element.querySelectorAll("[data-type='footnotes-block']");k.forEach((function(e,t){0===t?g=e:(g.insertAdjacentHTML("beforeend",e.innerHTML),e.remove())})),k.length>0&&e.wysiwyg.element.insertAdjacentElement("beforeend",k[0]),(0,D.ib)(e.wysiwyg.element,t),e.wysiwyg.element.querySelectorAll(".vditor-wysiwyg__preview[data-render='2']").forEach((function(t){O(t,e)})),n&&("deleteContentBackward"===n.inputType||"deleteContentForward"===n.inputType)&&e.options.comment.enable&&(e.wysiwyg.triggerRemoveComment(e),e.options.comment.adjustTop(e.wysiwyg.getComments(e,!0)))}I(e),$(e,{enableAddUndoStack:!0,enableHint:!0,enableInput:!0})},Fe=function(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e},Ze=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))},Je=function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]-1||(0,c.yl)(n)||"Escape"===n.key||n.shiftKey||n.altKey)){var r=(0,b.lG)(e.startContainer,"P")||(0,b.lG)(e.startContainer,"LI");if(r&&0===(0,D.im)(r,t[t.currentMode].element,e).start){r.nodeValue&&(r.nodeValue=r.nodeValue.replace(/\u2006/g,""));var o=document.createTextNode(i.g.ZWSP);e.insertNode(o),e.setStartAfter(o)}}},Qe=function(e,t){if("ArrowDown"===t||"ArrowUp"===t){var n=(0,b.a1)(e.startContainer,"data-type","math-inline")||(0,b.a1)(e.startContainer,"data-type","html-entity")||(0,b.a1)(e.startContainer,"data-type","html-inline");n&&("ArrowDown"===t&&e.setStartAfter(n.parentElement),"ArrowUp"===t&&e.setStartBefore(n.parentElement))}},$e=function(e,t){var n=(0,D.zh)(e),r=(0,b.F9)(n.startContainer);r&&(r.insertAdjacentHTML(t,''.concat(i.g.ZWSP,"\n
")),(0,D.ib)(e[e.currentMode].element,n),ve(e),ut(e))},et=function(e){var t=(0,b.lG)(e,"TABLE");return!(!t||!t.rows[0].cells[0].isSameNode(e))&&t},tt=function(e){var t=(0,b.lG)(e,"TABLE");return!(!t||!t.lastElementChild.lastElementChild.lastElementChild.isSameNode(e))&&t},nt=function(e,t,n){void 0===n&&(n=!0);var r=e.previousElementSibling;return r||(r=e.parentElement.previousElementSibling?e.parentElement.previousElementSibling.lastElementChild:"TBODY"===e.parentElement.parentElement.tagName&&e.parentElement.parentElement.previousElementSibling?e.parentElement.parentElement.previousElementSibling.lastElementChild.lastElementChild:null),r&&(t.selectNodeContents(r),n||t.collapse(!1),(0,D.Hc)(t)),r},rt=function(e,t,n,r,o){var a=(0,D.im)(r,e[e.currentMode].element,n);if("ArrowDown"===t.key&&-1===r.textContent.trimRight().substr(a.start).indexOf("\n")||"ArrowRight"===t.key&&a.start>=r.textContent.trimRight().length){var s=o.nextElementSibling;return!s||s&&("TABLE"===s.tagName||s.getAttribute("data-type"))?(o.insertAdjacentHTML("afterend",''.concat(i.g.ZWSP,"
")),(0,D.ib)(e[e.currentMode].element,n)):(n.selectNodeContents(s),n.collapse(!0),(0,D.Hc)(n)),t.preventDefault(),!0}return!1},it=function(e,t,n,r,o){var a=(0,D.im)(r,e[e.currentMode].element,n);if("ArrowUp"===t.key&&-1===r.textContent.substr(0,a.start).indexOf("\n")||("ArrowLeft"===t.key||"Backspace"===t.key&&""===n.toString())&&0===a.start){var s=o.previousElementSibling;return!s||s&&("TABLE"===s.tagName||s.getAttribute("data-type"))?(o.insertAdjacentHTML("beforebegin",''.concat(i.g.ZWSP,"
")),(0,D.ib)(e[e.currentMode].element,n)):(n.selectNodeContents(s),n.collapse(!1),(0,D.Hc)(n)),t.preventDefault(),!0}return!1},ot=function(e,t,n,r){void 0===r&&(r=!0);var i=(0,b.lG)(t.startContainer,"LI");if(e[e.currentMode].element.querySelectorAll("wbr").forEach((function(e){e.remove()})),t.insertNode(document.createElement("wbr")),r&&i){for(var o="",a=0;a'.concat(i.parentElement.children[a].innerHTML.trimLeft(),"")}i.parentElement.insertAdjacentHTML("beforebegin",o),i.parentElement.remove()}else if(i)if("check"===n)i.parentElement.querySelectorAll("li").forEach((function(e){e.insertAdjacentHTML("afterbegin",''.concat(0===e.textContent.indexOf(" ")?"":" ")),e.classList.add("vditor-task")}));else{i.querySelector("input")&&i.parentElement.querySelectorAll("li").forEach((function(e){e.querySelector("input").remove(),e.classList.remove("vditor-task")}));var l=void 0;"list"===n?(l=document.createElement("ul")).setAttribute("data-marker","*"):(l=document.createElement("ol")).setAttribute("data-marker","1."),l.setAttribute("data-block","0"),l.setAttribute("data-tight",i.parentElement.getAttribute("data-tight")),l.innerHTML=i.parentElement.innerHTML,i.parentElement.parentNode.replaceChild(l,i.parentElement)}else{var c=(0,b.a1)(t.startContainer,"data-block","0");c||(e[e.currentMode].element.querySelector("wbr").remove(),(c=e[e.currentMode].element.querySelector("p")).innerHTML=""),"check"===n?(c.insertAdjacentHTML("beforebegin",'")),c.remove()):"list"===n?(c.insertAdjacentHTML("beforebegin",'")),c.remove()):"ordered-list"===n&&(c.insertAdjacentHTML("beforebegin",'- '.concat(c.innerHTML,"
")),c.remove())}},at=function(e,t,n){var r=t.previousElementSibling;if(t&&r){var i=[t];Array.from(n.cloneContents().children).forEach((function(e,n){3!==e.nodeType&&t&&""!==e.textContent.trim()&&t.getAttribute("data-node-id")===e.getAttribute("data-node-id")&&(0!==n&&i.push(t),t=t.nextElementSibling)})),e[e.currentMode].element.querySelectorAll("wbr").forEach((function(e){e.remove()})),n.insertNode(document.createElement("wbr"));var o=r.parentElement,a="";i.forEach((function(e){var t=e.getAttribute("data-marker");1!==t.length&&(t="1".concat(t.slice(-1))),a+='').concat(e.innerHTML,""),e.remove()})),r.insertAdjacentHTML("beforeend","<".concat(o.tagName,' data-block="0">').concat(a,"").concat(o.tagName,">")),"wysiwyg"===e.currentMode?o.outerHTML=e.lute.SpinVditorDOM(o.outerHTML):o.outerHTML=e.lute.SpinVditorIRDOM(o.outerHTML),(0,D.ib)(e[e.currentMode].element,n);var s=(0,b.O9)(n.startContainer);s&&s.querySelectorAll(".vditor-".concat(e.currentMode,"__preview[data-render='2']")).forEach((function(t){O(t,e),"wysiwyg"===e.currentMode&&t.previousElementSibling.setAttribute("style","display:none")})),ut(e),ve(e)}else e[e.currentMode].element.focus()},st=function(e,t,n,r){var i=(0,b.lG)(t.parentElement,"LI");if(i){e[e.currentMode].element.querySelectorAll("wbr").forEach((function(e){e.remove()})),n.insertNode(document.createElement("wbr"));var o=t.parentElement,a=o.cloneNode(),s=[t];Array.from(n.cloneContents().children).forEach((function(e,n){3!==e.nodeType&&t&&""!==e.textContent.trim()&&t.getAttribute("data-node-id")===e.getAttribute("data-node-id")&&(0!==n&&s.push(t),t=t.nextElementSibling)}));var l=!1,c="";o.querySelectorAll("li").forEach((function(e){l&&(c+=e.outerHTML,e.nextElementSibling||e.previousElementSibling?e.remove():e.parentElement.remove()),e.isSameNode(s[s.length-1])&&(l=!0)})),s.reverse().forEach((function(e){i.insertAdjacentElement("afterend",e)})),c&&(a.innerHTML=c,s[0].insertAdjacentElement("beforeend",a)),"wysiwyg"===e.currentMode?r.outerHTML=e.lute.SpinVditorDOM(r.outerHTML):r.outerHTML=e.lute.SpinVditorIRDOM(r.outerHTML),(0,D.ib)(e[e.currentMode].element,n);var d=(0,b.O9)(n.startContainer);d&&d.querySelectorAll(".vditor-".concat(e.currentMode,"__preview[data-render='2']")).forEach((function(t){O(t,e),"wysiwyg"===e.currentMode&&t.previousElementSibling.setAttribute("style","display:none")})),ut(e),ve(e)}else e[e.currentMode].element.focus()},lt=function(e,t){for(var n=getSelection().getRangeAt(0).startContainer.parentElement,r=e.rows[0].cells.length,i=e.rows.length,o=0,a=0;a2&&(!(t.indexOf("-")>-1&&-1===t.trimLeft().indexOf(" ")&&e.trimRight().split("\n").length>1)&&(0!==t.indexOf(" ")&&0!==t.indexOf("\t")))))},dt=function(e){var t=e.trimRight().split("\n");return 0!==(e=t.pop()).indexOf(" ")&&0!==e.indexOf("\t")&&(""!==(e=e.trimLeft())&&0!==t.length&&(""===e.replace(/-/g,"")||""===e.replace(/=/g,"")))},ut=function(e,t){void 0===t&&(t={enableAddUndoStack:!0,enableHint:!1,enableInput:!0}),"wysiwyg"===e.currentMode?$(e,t):"ir"===e.currentMode?At(e,t):"sv"===e.currentMode&&Re(e,t)},pt=function(e,t,n,r){var o,a=e.startContainer,s=(0,b.lG)(a,"LI");if(s){if(!(0,c.yl)(r)&&!r.altKey&&"Enter"===r.key&&!r.shiftKey&&n&&s.contains(n)&&n.nextElementSibling)return s&&!s.textContent.endsWith("\n")&&s.insertAdjacentText("beforeend","\n"),e.insertNode(document.createTextNode("\n\n")),e.collapse(!1),ut(t),r.preventDefault(),!0;if(!((0,c.yl)(r)||r.shiftKey||r.altKey||"Backspace"!==r.key||s.previousElementSibling||""!==e.toString()||0!==(0,D.im)(s,t[t.currentMode].element,e).start))return s.nextElementSibling?(s.parentElement.insertAdjacentHTML("beforebegin",''.concat(s.innerHTML,"
")),s.remove()):s.parentElement.outerHTML=''.concat(s.innerHTML,"
"),(0,D.ib)(t[t.currentMode].element,e),ut(t),r.preventDefault(),!0;if(!(0,c.yl)(r)&&!r.shiftKey&&!r.altKey&&"Backspace"===r.key&&""===s.textContent.trim().replace(i.g.ZWSP,"")&&""===e.toString()&&"LI"===(null===(o=s.previousElementSibling)||void 0===o?void 0:o.tagName))return s.previousElementSibling.insertAdjacentText("beforeend","\n\n"),e.selectNodeContents(s.previousElementSibling),e.collapse(!1),s.remove(),(0,D.ib)(t[t.currentMode].element,e),ut(t),r.preventDefault(),!0;if(!(0,c.yl)(r)&&!r.altKey&&"Tab"===r.key){var l=!1;if((0===e.startOffset&&(3===a.nodeType&&!a.previousSibling||3!==a.nodeType&&"LI"===a.nodeName)||s.classList.contains("vditor-task")&&1===e.startOffset&&3!==a.previousSibling.nodeType&&"INPUT"===a.previousSibling.tagName)&&(l=!0),l||""!==e.toString())return r.shiftKey?st(t,s,e,s.parentElement):at(t,s,e),r.preventDefault(),!0}}return!1},mt=function(e,t,n){if(e.options.tab&&"Tab"===n.key)return n.shiftKey||(""===t.toString()?(t.insertNode(document.createTextNode(e.options.tab)),t.collapse(!1)):(t.extractContents(),t.insertNode(document.createTextNode(e.options.tab)),t.collapse(!1))),(0,D.Hc)(t),ut(e),n.preventDefault(),!0},ft=function(e,t,n,r){if(n){if(!(0,c.yl)(e)&&!e.altKey&&"Enter"===e.key){var i=String.raw(X||(X=Fe(["",""],["",""])),n.textContent).replace(/\\\|/g,"").trim(),o=i.split("|");if(i.startsWith("|")&&i.endsWith("|")&&o.length>3){var a=o.map((function(){return"---"})).join("|");return a=n.textContent+"\n"+a.substring(3,a.length-3)+"\n|",n.outerHTML=t.lute.SpinVditorDOM(a),(0,D.ib)(t[t.currentMode].element,r),ut(t),_e(t),e.preventDefault(),!0}if(ct(n.innerHTML)&&n.previousElementSibling){var s="",l=n.innerHTML.trimRight().split("\n");return l.length>1&&(l.pop(),s=''.concat(l.join("\n"),"
")),n.insertAdjacentHTML("afterend","".concat(s,'
\n
')),n.remove(),(0,D.ib)(t[t.currentMode].element,r),ut(t),_e(t),e.preventDefault(),!0}if(dt(n.innerHTML))return"wysiwyg"===t.currentMode?n.outerHTML=t.lute.SpinVditorDOM(n.innerHTML+'\n
'):n.outerHTML=t.lute.SpinVditorIRDOM(n.innerHTML+'\n
'),(0,D.ib)(t[t.currentMode].element,r),ut(t),_e(t),e.preventDefault(),!0}if(r.collapsed&&n.previousElementSibling&&"Backspace"===e.key&&!(0,c.yl)(e)&&!e.altKey&&!e.shiftKey&&n.textContent.trimRight().split("\n").length>1&&0===(0,D.im)(n,t[t.currentMode].element,r).start){var d=(0,b.DX)(n.previousElementSibling);return d.textContent.endsWith("\n")||(d.textContent=d.textContent+"\n"),d.parentElement.insertAdjacentHTML("beforeend","".concat(n.innerHTML)),n.remove(),(0,D.ib)(t[t.currentMode].element,r),!1}return!1}},ht=function(e,t,n){for(var r="",i=0;i ');"TH"===n.tagName?n.parentElement.parentElement.insertAdjacentHTML("afterend","".concat(r,"
")):n.parentElement.insertAdjacentHTML("afterend","".concat(r,"
")),ut(e)},vt=function(e,t,n){for(var r="",i=0;i '):r+=' | ');if("TH"===n.tagName){n.parentElement.parentElement.insertAdjacentHTML("beforebegin","".concat(r,"
")),t.insertNode(document.createElement("wbr"));var o=n.parentElement.innerHTML.replace(//g," | ").replace(/<\/th>/g," | ");n.parentElement.parentElement.nextElementSibling.insertAdjacentHTML("afterbegin",o),n.parentElement.parentElement.remove(),(0,D.ib)(e.ir.element,t)}else n.parentElement.insertAdjacentHTML("beforebegin","".concat(r,"
"));ut(e)},gt=function(e,t,n,r){void 0===r&&(r="afterend");for(var i=0,o=n.previousElementSibling;o;)i++,o=o.previousElementSibling;for(var a=0;a "):t.rows[a].cells[i].insertAdjacentHTML(r," | ");ut(e)},bt=function(e,t,n){if("TD"===n.tagName){var r=n.parentElement.parentElement;n.parentElement.previousElementSibling?t.selectNodeContents(n.parentElement.previousElementSibling.lastElementChild):t.selectNodeContents(r.previousElementSibling.lastElementChild.lastElementChild),1===r.childElementCount?r.remove():n.parentElement.remove(),t.collapse(!1),(0,D.Hc)(t),ut(e)}},yt=function(e,t,n,r){for(var i=0,o=r.previousElementSibling;o;)i++,o=o.previousElementSibling;(r.previousElementSibling||r.nextElementSibling)&&(t.selectNodeContents(r.previousElementSibling||r.nextElementSibling),t.collapse(!0));for(var a=0;a");var o=document.createElement("br");return n.insertNode(o),n.setStartAfter(o),ut(e),_e(e),t.preventDefault(),!0}if("Tab"===t.key)return t.shiftKey?(nt(i,n),t.preventDefault(),!0):((u=i.nextElementSibling)||(u=i.parentElement.nextElementSibling?i.parentElement.nextElementSibling.firstElementChild:"THEAD"===i.parentElement.parentElement.tagName&&i.parentElement.parentElement.nextElementSibling?i.parentElement.parentElement.nextElementSibling.firstElementChild.firstElementChild:null),u&&(n.selectNodeContents(u),(0,D.Hc)(n)),t.preventDefault(),!0);var a=i.parentElement.parentElement.parentElement;if("ArrowUp"===t.key){if(t.preventDefault(),"TH"===i.tagName)return a.previousElementSibling?(n.selectNodeContents(a.previousElementSibling),n.collapse(!1),(0,D.Hc)(n)):$e(e,"beforebegin"),!0;for(var s=0,l=i.parentElement;s\n',(0,D.ib)(e[e.currentMode].element,n)):(n.setStartBefore(a),n.collapse(!0)),ut(e)),t.preventDefault(),!0;if(q("⇧⌘F",t))return vt(e,n,i),t.preventDefault(),!0;if(q("⌘=",t))return ht(e,n,i),t.preventDefault(),!0;if(q("⇧⌘G",t))return gt(e,a,i,"beforebegin"),t.preventDefault(),!0;if(q("⇧⌘=",t))return gt(e,a,i),t.preventDefault(),!0;if(q("⌘-",t))return bt(e,n,i),t.preventDefault(),!0;if(q("⇧⌘-",t))return yt(e,n,a,i),t.preventDefault(),!0;if(q("⇧⌘L",t)){if("ir"===e.currentMode)return lt(a,"left"),ut(e),t.preventDefault(),!0;if(m=e.wysiwyg.popover.querySelector('[data-type="left"]'))return m.click(),t.preventDefault(),!0}if(q("⇧⌘C",t)){if("ir"===e.currentMode)return lt(a,"center"),ut(e),t.preventDefault(),!0;if(m=e.wysiwyg.popover.querySelector('[data-type="center"]'))return m.click(),t.preventDefault(),!0}if(q("⇧⌘R",t)){if("ir"===e.currentMode)return lt(a,"right"),ut(e),t.preventDefault(),!0;var m;if(m=e.wysiwyg.popover.querySelector('[data-type="right"]'))return m.click(),t.preventDefault(),!0}}return!1},Et=function(e,t,n,r){if("PRE"===n.tagName&&q("⌘A",t))return r.selectNodeContents(n.firstElementChild),t.preventDefault(),!0;if(e.options.tab&&"Tab"===t.key&&!t.shiftKey&&""===r.toString())return r.insertNode(document.createTextNode(e.options.tab)),r.collapse(!1),ut(e),t.preventDefault(),!0;if("Backspace"===t.key&&!(0,c.yl)(t)&&!t.shiftKey&&!t.altKey){var i=(0,D.im)(n,e[e.currentMode].element,r);if((0===i.start||1===i.start&&"\n"===n.innerText)&&""===r.toString())return n.parentElement.outerHTML=''.concat(n.firstElementChild.innerHTML,"
"),(0,D.ib)(e[e.currentMode].element,r),ut(e),t.preventDefault(),!0}return!(0,c.yl)(t)&&!t.altKey&&"Enter"===t.key&&(n.firstElementChild.textContent.endsWith("\n")||n.firstElementChild.insertAdjacentText("beforeend","\n"),r.extractContents(),r.insertNode(document.createTextNode("\n")),r.collapse(!1),(0,D.Hc)(r),(0,c.vU)()||("wysiwyg"===e.currentMode?Ke(e,r):P(e,r)),_e(e),t.preventDefault(),!0)},kt=function(e,t,n,r){var o=t.startContainer,a=(0,b.lG)(o,"BLOCKQUOTE");if(a&&""===t.toString()){if("Backspace"===n.key&&!(0,c.yl)(n)&&!n.shiftKey&&!n.altKey&&0===(0,D.im)(a,e[e.currentMode].element,t).start)return t.insertNode(document.createElement("wbr")),a.outerHTML=a.innerHTML,(0,D.ib)(e[e.currentMode].element,t),ut(e),n.preventDefault(),!0;if(r&&"Enter"===n.key&&!(0,c.yl)(n)&&!n.shiftKey&&!n.altKey&&"BLOCKQUOTE"===r.parentElement.tagName){var s=!1;if("\n"===r.innerHTML.replace(i.g.ZWSP,"")||""===r.innerHTML.replace(i.g.ZWSP,"")?(s=!0,r.remove()):r.innerHTML.endsWith("\n\n")&&(0,D.im)(r,e[e.currentMode].element,t).start===r.textContent.length-1&&(r.innerHTML=r.innerHTML.substr(0,r.innerHTML.length-2),s=!0),s)return a.insertAdjacentHTML("afterend",''.concat(i.g.ZWSP,"\n
")),(0,D.ib)(e[e.currentMode].element,t),ut(e),n.preventDefault(),!0}var l=(0,b.F9)(o);if("wysiwyg"===e.currentMode&&l&&q("⇧⌘;",n))return t.insertNode(document.createElement("wbr")),l.outerHTML=''.concat(l.outerHTML,"
"),(0,D.ib)(e.wysiwyg.element,t),$(e),n.preventDefault(),!0;if(rt(e,n,t,a,a))return!0;if(it(e,n,t,a,a))return!0}return!1},St=function(e,t,n){var r=t.startContainer,i=(0,b.lG)(r,"LI");if(i&&i.classList.contains("vditor-task")){if(q("⇧⌘J",n)){var o=i.firstElementChild;return o.checked?o.removeAttribute("checked"):o.setAttribute("checked","checked"),ut(e),n.preventDefault(),!0}if("Backspace"===n.key&&!(0,c.yl)(n)&&!n.shiftKey&&!n.altKey&&""===t.toString()&&1===t.startOffset&&(3===r.nodeType&&r.previousSibling&&"INPUT"===r.previousSibling.tagName||3!==r.nodeType)){var a=i.previousElementSibling;if(i.querySelector("input").remove(),a)(0,b.DX)(a).parentElement.insertAdjacentHTML("beforeend",""+i.innerHTML.trim()),i.remove();else i.parentElement.insertAdjacentHTML("beforebegin",''.concat(i.innerHTML.trim()||"\n","
")),i.nextElementSibling?i.remove():i.parentElement.remove();return(0,D.ib)(e[e.currentMode].element,t),ut(e),n.preventDefault(),!0}if("Enter"===n.key&&!(0,c.yl)(n)&&!n.shiftKey&&!n.altKey){if(""===i.textContent.trim())if((0,b.fb)(i.parentElement,"vditor-task")){var s=(0,b.O9)(r);s&&st(e,i,t,s)}else if(i.nextElementSibling){var l="",d="",u=!1;Array.from(i.parentElement.children).forEach((function(e){i.isSameNode(e)?u=!0:u?l+=e.outerHTML:d+=e.outerHTML}));var p=i.parentElement.tagName,m="OL"===i.parentElement.tagName?"":' data-marker="'.concat(i.parentElement.getAttribute("data-marker"),'"'),f="";d&&(f="UL"===i.parentElement.tagName?"":' start="1"',d="<".concat(p,' data-tight="true"').concat(m,' data-block="0">').concat(d,"").concat(p,">")),i.parentElement.outerHTML="".concat(d,'\n
<').concat(p,'\n data-tight="true"').concat(m,' data-block="0"').concat(f,">").concat(l,"").concat(p,">")}else i.parentElement.insertAdjacentHTML("afterend",'\n
'),1===i.parentElement.querySelectorAll("li").length?i.parentElement.remove():i.remove();else 3!==r.nodeType&&0===t.startOffset&&"INPUT"===r.firstChild.tagName?t.setStart(r.childNodes[1],1):(t.setEndAfter(i.lastChild),i.insertAdjacentHTML("afterend",' ')),document.querySelector("wbr").after(t.extractContents()));return(0,D.ib)(e[e.currentMode].element,t),ut(e),_e(e),n.preventDefault(),!0}}return!1},Lt=function(e,t,n,r){if(3!==t.startContainer.nodeType){var i=t.startContainer.children[t.startOffset];if(i&&"HR"===i.tagName)return t.selectNodeContents(i.previousElementSibling),t.collapse(!1),n.preventDefault(),!0}if(r){var o=r.previousElementSibling;if(o&&0===(0,D.im)(r,e[e.currentMode].element,t).start&&((0,c.vU)()&&"HR"===o.tagName||"TABLE"===o.tagName)){if("TABLE"===o.tagName){var a=o.lastElementChild.lastElementChild.lastElementChild;a.innerHTML=a.innerHTML.trimLeft()+""+r.textContent.trim(),r.remove()}else o.remove();return(0,D.ib)(e[e.currentMode].element,t),ut(e),n.preventDefault(),!0}}return!1},Tt=function(e){(0,c.vU)()&&3!==e.startContainer.nodeType&&"HR"===e.startContainer.tagName&&e.setStartBefore(e.startContainer)},Ct=function(e,t,n){var r,i;if(!(0,c.vU)())return!1;if("ArrowUp"===e.key&&t&&"TABLE"===(null===(r=t.previousElementSibling)||void 0===r?void 0:r.tagName)){var o=t.previousElementSibling;return n.selectNodeContents(o.rows[o.rows.length-1].lastElementChild),n.collapse(!1),e.preventDefault(),!0}return!("ArrowDown"!==e.key||!t||"TABLE"!==(null===(i=t.nextElementSibling)||void 0===i?void 0:i.tagName))&&(n.selectNodeContents(t.nextElementSibling.rows[0].cells[0]),n.collapse(!0),e.preventDefault(),!0)},Mt=function(e,t,n){return Ze(void 0,void 0,void 0,(function(){var r,o,a,s,l,c,d,u,p,m,f,h,v,g,y,w;return Je(this,(function(E){switch(E.label){case 0:return"true"!==e[e.currentMode].element.getAttribute("contenteditable")?[2]:(t.stopPropagation(),t.preventDefault(),"clipboardData"in t?(r=t.clipboardData.getData("text/html"),o=t.clipboardData.getData("text/plain"),a=t.clipboardData.files):(r=t.dataTransfer.getData("text/html"),o=t.dataTransfer.getData("text/plain"),t.dataTransfer.types.includes("Files")&&(a=t.dataTransfer.items)),s={},l=function(t,n){if(!n)return["",Lute.WalkContinue];if(e.options.upload.renderLinkDest)return e.options.upload.renderLinkDest(e,t,n);var r=t.TokensStr();if(34===t.__internal_object__.Parent.Type&&r&&-1===r.indexOf("file://")&&e.options.upload.linkToImgUrl){var i=new XMLHttpRequest;i.open("POST",e.options.upload.linkToImgUrl),e.options.upload.token&&i.setRequestHeader("X-Upload-Token",e.options.upload.token),e.options.upload.withCredentials&&(i.withCredentials=!0),Ve(e,i),i.setRequestHeader("Content-Type","application/json; charset=utf-8"),i.onreadystatechange=function(){if(i.readyState===XMLHttpRequest.DONE){if(200===i.status){var t=i.responseText;e.options.upload.linkToImgFormat&&(t=e.options.upload.linkToImgFormat(i.responseText));var n=JSON.parse(t);if(0!==n.code)return void e.tip.show(n.msg);var r=n.data.originalURL;if("sv"===e.currentMode)e.sv.element.querySelectorAll(".vditor-sv__marker--link").forEach((function(e){e.textContent===r&&(e.textContent=n.data.url)}));else{var o=e[e.currentMode].element.querySelector('img[src="'.concat(r,'"]'));o.src=n.data.url,"ir"===e.currentMode&&(o.previousElementSibling.previousElementSibling.innerHTML=n.data.url)}ut(e)}else e.tip.show(i.responseText);e.options.upload.linkToImgCallback&&e.options.upload.linkToImgCallback(i.responseText)}},i.send(JSON.stringify({url:r}))}return"ir"===e.currentMode?[''.concat(Lute.EscapeHTMLStr(r),""),Lute.WalkContinue]:"wysiwyg"===e.currentMode?["",Lute.WalkContinue]:[''.concat(Lute.EscapeHTMLStr(r),""),Lute.WalkContinue]},r.replace(/&/g,"&").replace(/<(|\/)(html|body|meta)[^>]*?>/gi,"").trim()!=='').concat(o,"")&&r.replace(/&/g,"&").replace(/<(|\/)(html|body|meta)[^>]*?>/gi,"").trim()!=='\x3c!--StartFragment--\x3e').concat(o,"\x3c!--EndFragment--\x3e")||(r=""),(c=(new DOMParser).parseFromString(r,"text/html")).body&&(r=c.body.innerHTML),r=Lute.Sanitize(r),e.wysiwyg.getComments(e),d=e[e.currentMode].element.scrollHeight,u=function(e,t,n){void 0===n&&(n="sv");var r=document.createElement("div");r.innerHTML=e;var i=!1;1===r.childElementCount&&r.lastElementChild.style.fontFamily.indexOf("monospace")>-1&&(i=!0);var o=r.querySelectorAll("pre");if(1===r.childElementCount&&1===o.length&&"vditor-wysiwyg"!==o[0].className&&"vditor-sv"!==o[0].className&&(i=!0),0===e.indexOf('\n')&&(i=!0),1===r.childElementCount&&"TABLE"===r.firstElementChild.tagName&&r.querySelector(".line-number")&&r.querySelector(".line-content")&&(i=!0),i){var a=t||e;return/\n/.test(a)||1===o.length?"wysiwyg"===n?'
'.concat(a.replace(/&/g,"&").replace(/
"):"\n```\n"+a.replace(/&/g,"&").replace(/".concat(a.replace(/&/g,"&").replace(/"):"`".concat(a,"`")}return!1}(r,o,e.currentMode),(p="sv"===e.currentMode?(0,b.a1)(t.target,"data-type","code-block"):(0,b.lG)(t.target,"CODE"))?("sv"===e.currentMode?document.execCommand("insertHTML",!1,o.replace(/&/g,"&").replace(/0?e.options.upload.url||e.options.upload.handler?[4,Ge(e,a)]:[3,5]:[3,7];case 4:return E.sent(),[3,6];case 5:h=new FileReader,"clipboardData"in t?(a=t.clipboardData.files,v=a[0]):t.dataTransfer.types.includes("Files")&&(a=t.dataTransfer.items,v=a[0].getAsFile()),v&&v.type.startsWith("image")&&(h.readAsDataURL(v),h.onload=function(){var t="";"wysiwyg"===e.currentMode?t+='
\n'):t+=".concat(h.result.toString(),")\n"),document.execCommand("insertHTML",!1,t)}),E.label=6;case 6:return[3,8];case 7:""!==o.trim()&&0===a.length&&(""!==(y=(0,D.zh)(e)).toString()&&e.lute.IsValidLinkDest(o)&&(o="[".concat(y.toString(),"](").concat(o,")")),"ir"===e.currentMode?(s.Md2VditorIRDOM={renderLinkDest:l},e.lute.SetJSRenderers({renderers:s}),(0,D.oC)(e.lute.Md2VditorIRDOM(o),e)):"wysiwyg"===e.currentMode?(s.Md2VditorDOM={renderLinkDest:l},e.lute.SetJSRenderers({renderers:s}),(0,D.oC)(e.lute.Md2VditorDOM(o),e)):(s.Md2VditorSVDOM={renderLinkDest:l},e.lute.SetJSRenderers({renderers:s}),Oe(e,o)),e.outline.render(e)),E.label=8;case 8:return"sv"!==e.currentMode&&((g=(0,b.F9)((0,D.zh)(e).startContainer))&&(y=(0,D.zh)(e),e[e.currentMode].element.querySelectorAll("wbr").forEach((function(e){e.remove()})),y.insertNode(document.createElement("wbr")),"wysiwyg"===e.currentMode?g.outerHTML=e.lute.SpinVditorDOM(g.outerHTML):g.outerHTML=e.lute.SpinVditorIRDOM(g.outerHTML),(0,D.ib)(e[e.currentMode].element,y)),e[e.currentMode].element.querySelectorAll(".vditor-".concat(e.currentMode,"__preview[data-render='2']")).forEach((function(t){O(t,e)}))),e.wysiwyg.triggerRemoveComment(e),ut(e),e[e.currentMode].element.scrollHeight-d>Math.min(e[e.currentMode].element.clientHeight,window.innerHeight)/2&&_e(e),[2]}}))}))},xt=function(e){var t,n;e.hint.render(e);var r=(0,D.zh)(e).startContainer,o=(0,b.a1)(r,"data-type","code-block-info");if(o)if(""===o.textContent.replace(i.g.ZWSP,"")&&e.hint.recentLanguage){o.textContent=i.g.ZWSP+e.hint.recentLanguage,(0,D.zh)(e).selectNodeContents(o)}else{var a=[],s=o.textContent.substring(0,(0,D.im)(o,e.ir.element).start).replace(i.g.ZWSP,"");(e.options.preview.hljs.langs||i.g.ALIAS_CODE_LANGUAGES.concat((null!==(n=null===(t=window.hljs)||void 0===t?void 0:t.listLanguages())&&void 0!==n?n:[]).sort())).forEach((function(e){e.indexOf(s.toLowerCase())>-1&&a.push({html:e,value:e})})),e.hint.genHTML(a,s,e)}},At=function(e,t){void 0===t&&(t={enableAddUndoStack:!0,enableHint:!1,enableInput:!0}),t.enableHint&&xt(e),clearTimeout(e.ir.processTimeoutId),e.ir.processTimeoutId=window.setTimeout((function(){if(!e.ir.composingLock){var n=a(e);"function"==typeof e.options.input&&t.enableInput&&e.options.input(n),e.options.counter.enable&&e.counter.render(e,n),e.options.cache.enable&&(0,c.pK)()&&(localStorage.setItem(e.options.cache.id,n),e.options.cache.after&&e.options.cache.after(n)),e.devtools&&e.devtools.renderEchart(e),t.enableAddUndoStack&&e.undo.addToUndoStack(e)}}),e.options.undoDelay)},_t=function(e,t){var n=(0,D.zh)(e),r=(0,b.F9)(n.startContainer)||n.startContainer;if(r){var i=r.querySelector(".vditor-ir__marker--heading");i?i.innerHTML=t:(r.insertAdjacentText("afterbegin",t),n.selectNodeContents(r),n.collapse(!1)),P(e,n.cloneRange()),Q(e)}},Ht=function(e,t,n){var r=(0,b.a1)(e.startContainer,"data-type",n);if(r){r.firstElementChild.remove(),r.lastElementChild.remove(),e.insertNode(document.createElement("wbr"));var i=document.createElement("div");i.innerHTML=t.lute.SpinVditorIRDOM(r.outerHTML),r.outerHTML=i.firstElementChild.innerHTML.trim()}},Nt=function(e,t,n,r){var i=(0,D.zh)(e),o=t.getAttribute("data-type"),a=i.startContainer;3===a.nodeType&&(a=a.parentElement);var s=!0;if(t.classList.contains("vditor-menu--current"))if("quote"===o){var l=(0,b.lG)(a,"BLOCKQUOTE");l&&(i.insertNode(document.createElement("wbr")),l.outerHTML=""===l.innerHTML.trim()?''.concat(l.innerHTML,"
"):l.innerHTML)}else if("link"===o){var c=(0,b.a1)(i.startContainer,"data-type","a");if(c){var u=(0,b.fb)(i.startContainer,"vditor-ir__link");u?(i.insertNode(document.createElement("wbr")),c.outerHTML=u.innerHTML):c.outerHTML=c.querySelector(".vditor-ir__link").innerHTML+""}}else"italic"===o?Ht(i,e,"em"):"bold"===o?Ht(i,e,"strong"):"strike"===o?Ht(i,e,"s"):"inline-code"===o?Ht(i,e,"code"):"check"!==o&&"list"!==o&&"ordered-list"!==o||(ot(e,i,o),s=!1,t.classList.remove("vditor-menu--current"));else{0===e.ir.element.childNodes.length&&(e.ir.element.innerHTML='
',(0,D.ib)(e.ir.element,i));var p=(0,b.F9)(i.startContainer);if("line"===o){if(p){var m='
\n
';""===p.innerHTML.trim()?p.outerHTML=m:p.insertAdjacentHTML("afterend",m)}}else if("quote"===o)p&&(i.insertNode(document.createElement("wbr")),p.outerHTML=''.concat(p.outerHTML,"
"),s=!1,t.classList.add("vditor-menu--current"));else if("link"===o){var f=void 0;f=""===i.toString()?"".concat(n,"").concat(r):"".concat(n).concat(i.toString()).concat(r.replace(")",")")),document.execCommand("insertHTML",!1,f),s=!1,t.classList.add("vditor-menu--current")}else if("italic"===o||"bold"===o||"strike"===o||"inline-code"===o||"code"===o||"table"===o){f=void 0;""===i.toString()?f="".concat(n,"").concat(r):(f="code"===o?"".concat(n,"\n").concat(i.toString(),"").concat(r):"table"===o?"".concat(n).concat(i.toString(),"").concat(r):"".concat(n).concat(i.toString()).concat(r,""),i.deleteContents()),"table"!==o&&"code"!==o||(f="\n"+f+"\n\n");var h=document.createElement("span");h.innerHTML=f,i.insertNode(h),P(e,i),"table"===o&&(i.selectNodeContents(getSelection().getRangeAt(0).startContainer.parentElement),(0,D.Hc)(i))}else"check"!==o&&"list"!==o&&"ordered-list"!==o||(ot(e,i,o,!1),s=!1,d(e.toolbar.elements,["check","list","ordered-list"]),t.classList.add("vditor-menu--current"))}(0,D.ib)(e.ir.element,i),At(e),s&&Q(e)},Ot=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))},Dt=function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]-1&&"sv"!==n.currentMode&&o.insertNode(document.createTextNode(" ")),o.collapse(!1),(0,D.Hc)(o),"wysiwyg"===n.currentMode)(c=(0,b.fb)(o.startContainer,"vditor-wysiwyg__block"))&&c.lastElementChild.classList.contains("vditor-wysiwyg__preview")&&(c.lastElementChild.innerHTML=c.firstElementChild.innerHTML,O(c.lastElementChild,n));else if("ir"===n.currentMode){var c;(c=(0,b.fb)(o.startContainer,"vditor-ir__marker--pre"))&&c.nextElementSibling.classList.contains("vditor-ir__preview")&&(c.nextElementSibling.innerHTML=c.innerHTML,O(c.nextElementSibling,n))}ut(n)},this.timeId=-1,this.element=document.createElement("div"),this.element.className="vditor-hint",this.recentLanguage="",e.push({key:":"})}return e.prototype.render=function(e){var t=this;if(window.getSelection().focusNode){var n,r=getSelection().getRangeAt(0);n=r.startContainer.textContent.substring(0,r.startOffset)||"";var i=this.getKey(n,e.options.hint.extend);if(void 0===i)this.element.style.display="none",clearTimeout(this.timeId);else if(":"===this.splitChar){var o=""===i?e.options.hint.emoji:e.lute.GetEmojis(),a=[];Object.keys(o).forEach((function(e){0===e.indexOf(i.toLowerCase())&&(o[e].indexOf(".")>-1?a.push({html:'
:').concat(e,":"),value:":".concat(e,":")}):a.push({html:''.concat(o[e],"").concat(e),value:o[e]}))})),this.genHTML(a,i,e)}else e.options.hint.extend.forEach((function(n){n.key===t.splitChar&&(clearTimeout(t.timeId),t.timeId=window.setTimeout((function(){return Ot(t,void 0,void 0,(function(){var t;return Dt(this,(function(r){switch(r.label){case 0:return t=this.genHTML,[4,n.hint(i)];case 1:return t.apply(this,[r.sent(),i,e]),[2]}}))}))}),e.options.hint.delay))}))}},e.prototype.genHTML=function(e,t,n){var r=this;if(0!==e.length){var i=n[n.currentMode].element,o=(0,D.Ny)(i),a=o.left+("left"===n.options.outline.position?n.outline.element.offsetWidth:0),s=o.top,l="";e.forEach((function(e,n){if(!(n>7)){var r=e.html;if(""!==t){var i=r.lastIndexOf(">")+1,o=r.substr(i),a=o.toLowerCase().indexOf(t.toLowerCase());a>-1&&(o=o.substring(0,a)+""+o.substring(a,a+t.length)+""+o.substring(a+t.length),r=r.substr(0,i)+o)}l+='")}})),this.element.innerHTML=l;var c=parseInt(document.defaultView.getComputedStyle(i,null).getPropertyValue("line-height"),10);this.element.style.top="".concat(s+(c||22),"px"),this.element.style.left="".concat(a,"px"),this.element.style.display="block",this.element.style.right="auto",this.element.querySelectorAll("button").forEach((function(e){e.addEventListener("click",(function(t){r.fillEmoji(e,n),t.preventDefault()}))})),this.element.getBoundingClientRect().bottom>window.innerHeight&&(this.element.style.top="".concat(s-this.element.offsetHeight,"px")),this.element.getBoundingClientRect().right>window.innerWidth&&(this.element.style.left="auto",this.element.style.right="0")}else this.element.style.display="none"},e.prototype.select=function(e,t){if(0===this.element.querySelectorAll("button").length||"none"===this.element.style.display)return!1;var n=this.element.querySelector(".vditor-hint--current");if("ArrowDown"===e.key)return e.preventDefault(),e.stopPropagation(),n.removeAttribute("class"),n.nextElementSibling?n.nextElementSibling.className="vditor-hint--current":this.element.children[0].className="vditor-hint--current",!0;if("ArrowUp"===e.key){if(e.preventDefault(),e.stopPropagation(),n.removeAttribute("class"),n.previousElementSibling)n.previousElementSibling.className="vditor-hint--current";else{var r=this.element.children.length;this.element.children[r-1].className="vditor-hint--current"}return!0}return!((0,c.yl)(e)||e.shiftKey||e.altKey||"Enter"!==e.key||e.isComposing)&&(e.preventDefault(),e.stopPropagation(),this.fillEmoji(n,t),!0)},e.prototype.getKey=function(e,t){var n,r=this;if(this.lastIndex=-1,this.splitChar="",t.forEach((function(t){var n=e.lastIndexOf(t.key);r.lastIndex1&&a.trim()===a)if(2===i.length&&""===i[0]&&i[1].length<32)n=i[1];else{var s=i[i.length-2].slice(-1);" "===(0,o.X)(s)&&a.length<32&&(n=a)}return n},e}(),jt=function(){function e(e){this.composingLock=!1;var t=document.createElement("div");t.className="vditor-ir",t.innerHTML=''),this.element=t.firstElementChild,this.bindEvent(e),Le(e,this.element),Te(e,this.element),Ce(e,this.element),He(e,this.element),Ne(e,this.element),Me(e,this.element),xe(e,this.element,this.copy),Ae(e,this.element,this.copy)}return e.prototype.copy=function(e,t){var n=getSelection().getRangeAt(0);if(""!==n.toString()){e.stopPropagation(),e.preventDefault();var r=document.createElement("div");r.appendChild(n.cloneContents()),e.clipboardData.setData("text/plain",t.lute.VditorIRDOM2Md(r.innerHTML).trim()),e.clipboardData.setData("text/html","")}},e.prototype.bindEvent=function(e){var t=this;this.element.addEventListener("paste",(function(t){Mt(e,t,{pasteCode:function(e){document.execCommand("insertHTML",!1,e)}})})),this.element.addEventListener("scroll",(function(){v(e,["hint"])})),this.element.addEventListener("compositionstart",(function(e){t.composingLock=!0})),this.element.addEventListener("compositionend",(function(n){(0,c.vU)()||P(e,getSelection().getRangeAt(0).cloneRange()),t.composingLock=!1})),this.element.addEventListener("input",(function(n){if("deleteByDrag"!==n.inputType&&"insertFromDrop"!==n.inputType)return t.preventInput?(t.preventInput=!1,void At(e,{enableAddUndoStack:!0,enableHint:!0,enableInput:!0})):void(t.composingLock||"‘"===n.data||"“"===n.data||"《"===n.data||P(e,getSelection().getRangeAt(0).cloneRange(),!1,n))})),this.element.addEventListener("click",(function(n){if("INPUT"===n.target.tagName)return n.target.checked?n.target.setAttribute("checked","checked"):n.target.removeAttribute("checked"),t.preventInput=!0,void At(e);var r=(0,D.zh)(e),o=(0,b.fb)(n.target,"vditor-ir__preview");if(o||(o=(0,b.fb)(r.startContainer,"vditor-ir__preview")),o&&(o.previousElementSibling.firstElementChild?r.selectNodeContents(o.previousElementSibling.firstElementChild):r.selectNodeContents(o.previousElementSibling),r.collapse(!0),(0,D.Hc)(r),_e(e)),"IMG"===n.target.tagName){var a=n.target.parentElement.querySelector(".vditor-ir__marker--link");a&&(r.selectNode(a),(0,D.Hc)(r))}var s=(0,b.a1)(n.target,"data-type","a");if(!s||s.classList.contains("vditor-ir__node--expand")){if(n.target.isEqualNode(t.element)&&t.element.lastElementChild&&r.collapsed){var l=t.element.lastElementChild.getBoundingClientRect();n.y>l.top+l.height&&("P"===t.element.lastElementChild.tagName&&""===t.element.lastElementChild.textContent.trim().replace(i.g.ZWSP,"")?(r.selectNodeContents(t.element.lastElementChild),r.collapse(!1)):(t.element.insertAdjacentHTML("beforeend",''.concat(i.g.ZWSP,"
")),(0,D.ib)(t.element,r)))}""===r.toString()?B(r,e):setTimeout((function(){B((0,D.zh)(e),e)})),j(n,e),Q(e)}else e.options.link.click?e.options.link.click(s.querySelector(":scope > .vditor-ir__marker--link")):e.options.link.isOpen&&window.open(s.querySelector(":scope > .vditor-ir__marker--link").textContent)})),this.element.addEventListener("keyup",(function(n){if(!n.isComposing&&!(0,c.yl)(n))if("Enter"===n.key&&_e(e),Q(e),"Backspace"!==n.key&&"Delete"!==n.key||""===e.ir.element.innerHTML||1!==e.ir.element.childNodes.length||!e.ir.element.firstElementChild||"P"!==e.ir.element.firstElementChild.tagName||0!==e.ir.element.firstElementChild.childElementCount||""!==e.ir.element.textContent&&"\n"!==e.ir.element.textContent){var r=(0,D.zh)(e);"Backspace"===n.key?((0,c.vU)()&&"\n"===r.startContainer.textContent&&1===r.startOffset&&(r.startContainer.textContent="",B(r,e)),t.element.querySelectorAll(".language-math").forEach((function(e){var t=e.querySelector("br");t&&t.remove()}))):n.key.indexOf("Arrow")>-1?("ArrowLeft"!==n.key&&"ArrowRight"!==n.key||xt(e),B(r,e)):229===n.keyCode&&""===n.code&&"Unidentified"===n.key&&B(r,e);var o=(0,b.fb)(r.startContainer,"vditor-ir__preview");if(o){if("ArrowUp"===n.key||"ArrowLeft"===n.key)return o.previousElementSibling.firstElementChild?r.selectNodeContents(o.previousElementSibling.firstElementChild):r.selectNodeContents(o.previousElementSibling),r.collapse(!1),n.preventDefault(),!0;if("SPAN"===o.tagName&&("ArrowDown"===n.key||"ArrowRight"===n.key))return"html-entity"===o.parentElement.getAttribute("data-type")?(o.parentElement.insertAdjacentText("afterend",i.g.ZWSP),r.setStart(o.parentElement.nextSibling,1)):r.selectNodeContents(o.parentElement.lastElementChild),r.collapse(!1),n.preventDefault(),!0}}else e.ir.element.innerHTML=""}))},e}(),Rt=function(e){return"sv"===e.currentMode?e.lute.Md2HTML(a(e)):"wysiwyg"===e.currentMode?e.lute.VditorDOM2HTML(e.wysiwyg.element.innerHTML):"ir"===e.currentMode?e.lute.VditorIRDOM2HTML(e.ir.element.innerHTML):void 0},Pt=n(214),qt=n(436),Bt=function(){function e(e){this.element=document.createElement("div"),this.element.className="vditor-outline",this.element.innerHTML=''.concat(e,'
\n')}return e.prototype.render=function(e){return"block"===e.preview.element.style.display?(0,qt.k)(e.preview.previewElement,this.element.lastElementChild,e):(0,qt.k)(e[e.currentMode].element,this.element.lastElementChild,e)},e.prototype.toggle=function(e,t,n){var r;void 0===t&&(t=!0),void 0===n&&(n=!0);var o=null===(r=e.toolbar.elements.outline)||void 0===r?void 0:r.firstElementChild;if(t&&window.innerWidth>=i.g.MOBILE_WIDTH?(this.element.style.display="block",this.render(e),null==o||o.classList.add("vditor-menu--current")):(this.element.style.display="none",null==o||o.classList.remove("vditor-menu--current")),n&&getSelection().rangeCount>0){var a=getSelection().getRangeAt(0);e[e.currentMode].element.contains(a.startContainer)&&(0,D.Hc)(a)}K(e)},e}(),Vt=n(280),Ut=function(){function e(e){var t=this;this.element=document.createElement("div"),this.element.className="vditor-preview",this.previewElement=document.createElement("div"),this.previewElement.className="vditor-reset",e.options.classes.preview&&this.previewElement.classList.add(e.options.classes.preview),this.previewElement.style.maxWidth=e.options.preview.maxWidth+"px",this.previewElement.addEventListener("copy",(function(n){if("TEXTAREA"!==n.target.tagName){var r=document.createElement("div");r.className="vditor-reset",r.appendChild(getSelection().getRangeAt(0).cloneContents()),t.copyToX(e,r,"default"),n.preventDefault()}})),this.previewElement.addEventListener("click",(function(n){var r=(0,b.lG)(n.target,"SPAN");if(r&&(0,b.fb)(r,"vditor-toc")){var i=t.previewElement.querySelector("#"+r.getAttribute("data-target-id"));i&&(t.element.scrollTop=i.offsetTop)}else{if("A"===n.target.tagName)return e.options.link.click?e.options.link.click(n.target):e.options.link.isOpen&&window.open(n.target.getAttribute("href")),void n.preventDefault();"IMG"===n.target.tagName&&(e.options.image.preview?e.options.image.preview(n.target):e.options.image.isPreview&&(0,V.E)(n.target,e.options.lang,e.options.theme))}})),this.element.appendChild(this.previewElement);var n=e.options.preview.actions;if(0!==n.length){var r=document.createElement("div");r.className="vditor-preview__action";for(var i=[],o=0;oDesktop');break;case"tablet":i.push('');break;case"mobile":i.push('');break;case"mp-wechat":i.push('');break;case"zhihu":i.push('')}else i.push('"))}r.innerHTML=i.join(""),r.addEventListener((0,c.Le)(),(function(i){var o=(0,y.S)(i.target,"BUTTON");if(o){var a=o.getAttribute("data-type"),s=n.find((function(e){return(null==e?void 0:e.key)===a}));s?s.click(a):"mp-wechat"!==a&&"zhihu"!==a?(t.previewElement.style.width="desktop"===a?"auto":"tablet"===a?"780px":"360px",t.previewElement.scrollWidth>t.previewElement.parentElement.clientWidth&&(t.previewElement.style.width="auto"),t.render(e),r.querySelectorAll("button").forEach((function(e){e.classList.remove("vditor-preview__action--current")})),o.classList.add("vditor-preview__action--current")):t.copyToX(e,t.previewElement.cloneNode(!0),a)}})),this.element.insertBefore(r,this.previewElement)}}return e.prototype.render=function(e,t){var n=this;if(clearTimeout(this.mdTimeoutId),"none"!==this.element.style.display)if(t)this.previewElement.innerHTML=t;else if(""!==a(e).replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")){var r=(new Date).getTime(),i=a(e);this.mdTimeoutId=window.setTimeout((function(){if(e.options.preview.url){var t=new XMLHttpRequest;t.open("POST",e.options.preview.url),t.setRequestHeader("Content-Type","application/json;charset=UTF-8"),t.onreadystatechange=function(){if(t.readyState===XMLHttpRequest.DONE)if(200===t.status){var o=JSON.parse(t.responseText);if(0!==o.code)return void e.tip.show(o.msg);e.options.preview.transform&&(o.data=e.options.preview.transform(o.data)),n.previewElement.innerHTML=o.data,n.afterRender(e,r)}else{var a=e.lute.Md2HTML(i);e.options.preview.transform&&(a=e.options.preview.transform(a)),n.previewElement.innerHTML=a,n.afterRender(e,r)}},t.send(JSON.stringify({markdownText:i}))}else{var o=e.lute.Md2HTML(i);e.options.preview.transform&&(o=e.options.preview.transform(o)),n.previewElement.innerHTML=o,n.afterRender(e,r)}}),e.options.preview.delay)}else this.previewElement.innerHTML="";else"renderPerformance"===this.element.getAttribute("data-type")&&e.tip.hide()},e.prototype.afterRender=function(e,t){e.options.preview.parse&&e.options.preview.parse(this.element);var n=(new Date).getTime()-t;(new Date).getTime()-t>2600?(e.tip.show(window.VditorI18n.performanceTip.replace("${x}",n.toString())),e.preview.element.setAttribute("data-type","renderPerformance")):"renderPerformance"===e.preview.element.getAttribute("data-type")&&(e.tip.hide(),e.preview.element.removeAttribute("data-type"));var r=e.preview.element.querySelector(".vditor-comment--focus");r&&r.classList.remove("vditor-comment--focus"),(0,S.O)(e.preview.previewElement,e.options.preview.hljs),(0,C.s)(e.options.preview.hljs,e.preview.previewElement,e.options.cdn),(0,x.i)(e.preview.previewElement,e.options.cdn,e.options.theme),(0,A.K)(e.preview.previewElement,e.options.cdn),(0,N.J)(e.preview.previewElement,e.options.cdn,e.options.theme),(0,L.P)(e.preview.previewElement,e.options.cdn),(0,T.v)(e.preview.previewElement,e.options.cdn),(0,k.p)(e.preview.previewElement,e.options.cdn,e.options.theme),(0,_.P)(e.preview.previewElement,e.options.cdn,e.options.theme),(0,H.B)(e.preview.previewElement,e.options.cdn),(0,E.Q)(e.preview.previewElement,e.options.cdn),e.options.preview.render.media.enable&&(0,Vt.Y)(e.preview.previewElement),e.options.customRenders.forEach((function(t){t.render(e.preview.previewElement,e)}));var i=e.preview.element,o=e.outline.render(e);""===o&&(o="[ToC]"),i.querySelectorAll('[data-type="toc-block"]').forEach((function(t){t.innerHTML=o,(0,M.H)(t,{cdn:e.options.cdn,math:e.options.preview.math})})),(0,M.H)(e.preview.previewElement,{cdn:e.options.cdn,math:e.options.preview.math})},e.prototype.copyToX=function(e,t,n){void 0===n&&(n="mp-wechat"),"zhihu"!==n?t.querySelectorAll(".katex-html .base").forEach((function(e){e.style.display="initial"})):t.querySelectorAll(".language-math").forEach((function(e){e.outerHTML='
')})),t.style.backgroundColor="#fff",t.querySelectorAll("code").forEach((function(e){e.style.backgroundImage="none"})),this.element.append(t);var r=t.ownerDocument.createRange();r.selectNode(t),(0,D.Hc)(r),document.execCommand("copy"),t.remove(),e.tip.show(["zhihu","mp-wechat"].includes(n)?"已复制,可到".concat("zhihu"===n?"知乎":"微信公众号平台","进行粘贴"):"已复制到剪切板")},e}(),Wt=function(){function e(e){this.element=document.createElement("div"),this.element.className="vditor-resize vditor-resize--".concat(e.options.resize.position),this.element.innerHTML='',this.bindEvent(e)}return e.prototype.bindEvent=function(e){var t=this;this.element.addEventListener("mousedown",(function(n){var r=document,i=n.clientY,o=e.element.offsetHeight,a=63+e.element.querySelector(".vditor-toolbar").clientHeight;r.ondragstart=function(){return!1},window.captureEvents&&window.captureEvents(),t.element.classList.add("vditor-resize--selected"),r.onmousemove=function(t){"top"===e.options.resize.position?e.element.style.height=Math.max(a,o+(i-t.clientY))+"px":e.element.style.height=Math.max(a,o+(t.clientY-i))+"px",e.options.typewriterMode&&(e.sv.element.style.paddingBottom=e.sv.element.parentElement.offsetHeight/2+"px")},r.onmouseup=function(){e.options.resize.after&&e.options.resize.after(e.element.offsetHeight-o),window.captureEvents&&window.captureEvents(),r.onmousemove=null,r.onmouseup=null,r.ondragstart=null,r.onselectstart=null,r.onselect=null,t.element.classList.remove("vditor-resize--selected")}}))},e}(),zt=function(){function e(e){this.composingLock=!1,this.element=document.createElement("pre"),this.element.className="vditor-sv vditor-reset",this.element.setAttribute("placeholder",e.options.placeholder),this.element.setAttribute("contenteditable","true"),this.element.setAttribute("spellcheck","false"),this.bindEvent(e),Le(e,this.element),Ce(e,this.element),He(e,this.element),Ne(e,this.element),Me(e,this.element),xe(e,this.element,this.copy),Ae(e,this.element,this.copy)}return e.prototype.copy=function(e,t){e.stopPropagation(),e.preventDefault(),e.clipboardData.setData("text/plain",Se(t[t.currentMode].element))},e.prototype.bindEvent=function(e){var t=this;this.element.addEventListener("paste",(function(t){Mt(e,t,{pasteCode:function(e){document.execCommand("insertHTML",!1,e)}})})),this.element.addEventListener("scroll",(function(){if("block"===e.preview.element.style.display){var n=t.element.scrollTop,r=t.element.clientHeight,i=t.element.scrollHeight-parseFloat(t.element.style.paddingBottom||"0"),o=e.preview.element;o.scrollTop=n/r>.5?(n+r)*o.scrollHeight/i-r:n*o.scrollHeight/i}})),this.element.addEventListener("compositionstart",(function(e){t.composingLock=!0})),this.element.addEventListener("compositionend",(function(n){(0,c.vU)()||W(e,n),t.composingLock=!1})),this.element.addEventListener("input",(function(n){if("deleteByDrag"!==n.inputType&&"insertFromDrop"!==n.inputType&&!t.composingLock&&"‘"!==n.data&&"“"!==n.data&&"《"!==n.data)return t.preventInput?(t.preventInput=!1,void Re(e,{enableAddUndoStack:!0,enableHint:!0,enableInput:!0})):void W(e,n)})),this.element.addEventListener("keyup",(function(t){t.isComposing||(0,c.yl)(t)||("Backspace"!==t.key&&"Delete"!==t.key||""===e.sv.element.innerHTML||1!==e.sv.element.childNodes.length||!e.sv.element.firstElementChild||"DIV"!==e.sv.element.firstElementChild.tagName||2!==e.sv.element.firstElementChild.childElementCount||""!==e.sv.element.firstElementChild.textContent&&"\n"!==e.sv.element.textContent?"Enter"===t.key&&_e(e):e.sv.element.innerHTML="")}))},e}(),Gt=function(){function e(){this.element=document.createElement("div"),this.element.className="vditor-tip"}return e.prototype.show=function(e,t){var n=this;void 0===t&&(t=6e3),this.element.className="vditor-tip vditor-tip--show",0===t?(this.element.innerHTML=''),this.element.querySelector(".vditor-tip__close").addEventListener("click",(function(){n.hide()}))):(this.element.innerHTML=''.concat(e,"
"),setTimeout((function(){n.hide()}),t)),this.element.removeAttribute("style"),setTimeout((function(){n.element.getBoundingClientRect().top<46&&(n.element.style.position="fixed",n.element.style.top="46px")}),150)},e.prototype.hide=function(){this.element.className="vditor-messageElementtip",this.element.innerHTML=""},e}(),Kt=function(e,t){if(t.options.preview.mode!==e){switch(t.options.preview.mode=e,e){case"both":t.sv.element.style.display="block",t.preview.element.style.display="block",t.preview.render(t),u(t.toolbar.elements,["both"]);break;case"editor":t.sv.element.style.display="block",t.preview.element.style.display="none",d(t.toolbar.elements,["both"])}t.devtools&&t.devtools.renderEchart(t)}},Ft=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Zt=function(e){function t(t,n){var r=e.call(this,t,n)||this;return"both"===t.options.preview.mode&&r.element.children[0].classList.add("vditor-menu--current"),r.element.children[0].addEventListener((0,c.Le)(),(function(e){r.element.firstElementChild.classList.contains(i.g.CLASS_MENU_DISABLED)||(e.preventDefault(),"sv"===t.currentMode&&("both"===t.options.preview.mode?Kt("editor",t):Kt("both",t)))})),r}return Ft(t,e),t}(ye),Jt=function(){this.element=document.createElement("div"),this.element.className="vditor-toolbar__br"},Xt=n(580),Yt=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),Qt=function(e){function t(t,n){var r=e.call(this,t,n)||this,o=r.element.children[0],a=document.createElement("div");a.className="vditor-hint".concat(2===n.level?"":" vditor-panel--arrow");var s="";return i.g.CODE_THEME.forEach((function(e){s+="")})),a.innerHTML='').concat(s,"
"),a.addEventListener((0,c.Le)(),(function(e){"BUTTON"===e.target.tagName&&(v(t,["subToolbar"]),t.options.preview.hljs.style=e.target.textContent,(0,Xt.Y)(e.target.textContent,t.options.cdn),e.preventDefault(),e.stopPropagation())})),r.element.appendChild(a),g(t,a,o,n.level),r}return Yt(t,e),t}(ye),$t=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),en=function(e){function t(t,n){var r=e.call(this,t,n)||this,i=r.element.children[0],o=document.createElement("div");o.className="vditor-hint".concat(2===n.level?"":" vditor-panel--arrow");var a="";return Object.keys(t.options.preview.theme.list).forEach((function(e){a+='")})),o.innerHTML='').concat(a,"
"),o.addEventListener((0,c.Le)(),(function(e){"BUTTON"===e.target.tagName&&(v(t,["subToolbar"]),t.options.preview.theme.current=e.target.getAttribute("data-type"),(0,z.Z)(t.options.preview.theme.current,t.options.preview.theme.path),e.preventDefault(),e.stopPropagation())})),r.element.appendChild(o),g(t,o,i,n.level),r}return $t(t,e),t}(ye),tn=function(){function e(e){this.element=document.createElement("span"),this.element.className="vditor-counter vditor-tooltipped vditor-tooltipped__nw",this.render(e,"")}return e.prototype.render=function(e,t){var n=t.endsWith("\n")?t.length-1:t.length;if("text"===e.options.counter.type&&e[e.currentMode]){var r=e[e.currentMode].element.cloneNode(!0);r.querySelectorAll(".vditor-wysiwyg__preview").forEach((function(e){e.remove()})),n=r.textContent.length}"number"==typeof e.options.counter.max?(n>e.options.counter.max?this.element.className="vditor-counter vditor-counter--error":this.element.className="vditor-counter",this.element.innerHTML="".concat(n,"/").concat(e.options.counter.max)):this.element.innerHTML="".concat(n),this.element.setAttribute("aria-label",e.options.counter.type),e.options.counter.after&&e.options.counter.after(n,{enable:e.options.counter.enable,max:e.options.counter.max,type:e.options.counter.type})},e}(),nn=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),rn=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.element.children[0].innerHTML=n.icon,r.element.children[0].addEventListener((0,c.Le)(),(function(e){e.preventDefault(),e.currentTarget.classList.contains(i.g.CLASS_MENU_DISABLED)||n.click(e,t)})),r}return nn(t,e),t}(ye),on=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),an=function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.element.firstElementChild.addEventListener((0,c.Le)(),(function(e){var n=r.element.firstElementChild;n.classList.contains(i.g.CLASS_MENU_DISABLED)||(e.preventDefault(),n.classList.contains("vditor-menu--current")?(n.classList.remove("vditor-menu--current"),t.devtools.element.style.display="none",K(t)):(n.classList.add("vditor-menu--current"),t.devtools.element.style.display="block",K(t),t.devtools.renderEchart(t)))})),r}return on(t,e),t}(ye),sn=function(){this.element=document.createElement("div"),this.element.className="vditor-toolbar__divider"},ln=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),cn=function(e){function t(t,n){var r=e.call(this,t,n)||this,i=document.createElement("div");i.className="vditor-panel vditor-panel--arrow";var o="";return Object.keys(t.options.hint.emoji).forEach((function(e){var n=t.options.hint.emoji[e];n.indexOf(".")>-1?o+=''):o+='")})),i.innerHTML='').concat(o,'
\n ').concat(t.options.hint.emojiTail||"","\n
"),r.element.appendChild(i),g(t,i,r.element.firstElementChild,n.level),r.bindEvent(t),r}return ln(t,e),t.prototype.bindEvent=function(e){var t=this;this.element.lastElementChild.addEventListener((0,c.Le)(),(function(n){var r=(0,y.S)(n.target,"BUTTON");if(r){n.preventDefault();var i=r.getAttribute("data-value"),o=(0,D.zh)(e),a=i;if("wysiwyg"===e.currentMode?a=e.lute.SpinVditorDOM(i):"ir"===e.currentMode&&(a=e.lute.SpinVditorIRDOM(i)),i.indexOf(":")>-1&&"sv"!==e.currentMode){var s=document.createElement("div");s.innerHTML=a,a=s.firstElementChild.firstElementChild.outerHTML+" ",(0,D.oC)(a,e)}else o.extractContents(),o.insertNode(document.createTextNode(i)),(0,b.F9)(o.startContainer)||ne(e,o);o.collapse(!1),(0,D.Hc)(o),t.element.lastElementChild.style.display="none",ut(e)}})),this.element.lastElementChild.addEventListener("mouseover",(function(e){var n=(0,y.S)(e.target,"BUTTON");n&&(t.element.querySelector(".vditor-emojis__tip").innerHTML=n.getAttribute("data-key"))}))},t}(ye),dn=function(e,t,n){var r=document.createElement("a");"download"in r?(r.download=n,r.style.display="none",r.href=URL.createObjectURL(new Blob([t])),document.body.appendChild(r),r.click(),r.remove()):e.tip.show(window.VditorI18n.downloadTip,0)},un=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),pn=function(e){function t(t,n){var r=e.call(this,t,n)||this,i=r.element.children[0],o=document.createElement("div");return o.className="vditor-hint".concat(2===n.level?"":" vditor-panel--arrow"),o.innerHTML='\n\n',o.addEventListener((0,c.Le)(),(function(e){var n=e.target;if("BUTTON"===n.tagName){switch(n.getAttribute("data-type")){case"markdown":!function(e){var t=a(e);dn(e,t,t.substr(0,10)+".md")}(t);break;case"pdf":!function(e){e.tip.show(window.VditorI18n.generate,3800);var t=document.querySelector("#vditorExportIframe");t.contentDocument.open(),t.contentDocument.write('\n