Skip to content

Instantly share code, notes, and snippets.

@floriandierickx
Created April 6, 2019 11:41
Show Gist options
  • Save floriandierickx/7ef67ed2de867eaf63069e375c97ce0e to your computer and use it in GitHub Desktop.
Save floriandierickx/7ef67ed2de867eaf63069e375c97ce0e to your computer and use it in GitHub Desktop.
This file has been truncated, but you can view the full file.
! function(t) {
function e(t) {
Object.defineProperty(this, t, {
enumerable: !0,
get: function() {
return this[f][t]
}
})
}
function n(t) {
if ("undefined" != typeof System && System.isModule ? System.isModule(t) : "[object Module]" === Object.prototype.toString.call(t)) return t;
var e = {
default: t,
__useDefault: t
};
if (t && t.__esModule)
for (var n in t) Object.hasOwnProperty.call(t, n) && (e[n] = t[n]);
return new i(e)
}
function i(t) {
Object.defineProperty(this, f, {
value: t
}), Object.keys(t).forEach(e, this)
}
function r(t) {
return "@node/" === t.substr(0, 6) ? c(t, n(h(t.substr(6)))) : l[t]
}
function o(e) {
var n = r(e);
if (!n) throw new Error('Module "' + e + '" expected, but not contained in build.');
if (n.module) return n.module;
var i = n.linkRecord;
return function e(n, i) {
if (!i.depLoads) {
i.declare && function(e, n) {
var i = n.moduleObj,
r = e.importerSetters,
o = !1,
a = n.declare.call(t, function(t, e) {
if (!o) {
if ("object" == typeof t)
for (var n in t) "__useDefault" !== n && (i[n] = t[n]);
else i[t] = e;
o = !0;
for (var a = 0; a < r.length; a++) r[a](i);
return o = !1, e
}
}, {
id: e.key
});
"function" != typeof a ? (n.setters = a.setters, n.execute = a.execute) : (n.setters = [], n.execute = a)
}(n, i), i.depLoads = [];
for (var o = 0; o < i.deps.length; o++) {
var a = r(i.deps[o]);
i.depLoads.push(a), a.linkRecord && e(a, a.linkRecord);
var s = i.setters && i.setters[o];
s && (s(a.module || a.linkRecord.moduleObj), a.importerSetters.push(s))
}
return n
}
}(n, i), u(n, i, []), n.module
}
function a(t, e, n) {
return l[t] = {
key: t,
module: void 0,
importerSetters: [],
linkRecord: {
deps: e,
depLoads: void 0,
declare: n,
setters: void 0,
execute: void 0,
moduleObj: {}
}
}
}
function s(t, e, n, i) {
var r = {};
return l[t] = {
key: t,
module: void 0,
importerSetters: [],
linkRecord: {
deps: e,
depLoads: void 0,
declare: void 0,
execute: i,
executingRequire: n,
moduleObj: {
default: r,
__useDefault: r
},
setters: void 0
}
}
}
function u(e, n, r) {
if (r.push(e), e.module) return e.module;
if (n.setters) {
for (var o = 0; o < n.deps.length; o++) {
var a = n.depLoads[o],
s = a.linkRecord;
s && -1 === r.indexOf(a) && u(a, s, s.setters ? r : [])
}
n.execute.call(d)
} else {
var c = {
id: e.key
},
l = n.moduleObj;
Object.defineProperty(c, "exports", {
configurable: !0,
set: function(t) {
l.default = l.__useDefault = t
},
get: function() {
return l.__useDefault
}
});
var f = (p = n.deps, g = n.depLoads, b = r, function(t) {
for (var e = 0; e < p.length; e++)
if (p[e] === t) {
var n, i = g[e],
r = i.linkRecord;
return "__useDefault" in (n = r ? -1 === b.indexOf(i) ? u(i, r, b) : r.moduleObj : i.module) ? n.__useDefault : n
}
});
if (!n.executingRequire)
for (o = 0; o < n.deps.length; o++) f(n.deps[o]);
var h = n.execute.call(t, f, l.__useDefault, c);
void 0 !== h ? l.default = l.__useDefault = h : c.exports !== l.__useDefault && (l.default = l.__useDefault = c.exports);
var m = l.__useDefault;
if (m && m.__esModule)
for (var v in m) Object.hasOwnProperty.call(m, v) && (l[v] = m[v])
}
var p, g, b;
c = e.module = new i(n.moduleObj);
if (!n.setters)
for (o = 0; o < e.importerSetters.length; o++) e.importerSetters[o](c);
return c
}
function c(t, e) {
return l[t] = {
key: t,
module: e,
importerSetters: [],
linkRecord: void 0
}
}
var l = {},
f = "undefined" != typeof Symbol ? Symbol() : "@@baseObject";
i.prototype = Object.create(null), "undefined" != typeof Symbol && Symbol.toStringTag && (i.prototype[Symbol.toStringTag] = "Module");
var h = "undefined" != typeof System && System._nodeRequire || "undefined" != typeof require && void 0 !== require.resolve && "undefined" != typeof process && process.platform && require,
d = {};
return Object.freeze && Object.freeze(d),
function(t, e, r, u) {
return function(f) {
f(function(f) {
var d = {
_nodeRequire: h,
register: a,
registerDynamic: s,
registry: {
get: function(t) {
return l[t].module
},
set: c
},
newModule: function(t) {
return new i(t)
}
};
c("@empty", new i({}));
for (var m = 0; m < e.length; m++) c(e[m], n(arguments[m]));
u(d);
var v = o(t[0]);
if (t.length > 1)
for (m = 1; m < t.length; m++) o(t[m]);
return r ? v.__useDefault : (v instanceof i && Object.defineProperty(v, "__esModule", {
value: !0
}), v)
})
}
}
}("undefined" != typeof self ? self : "undefined" != typeof global ? global : this)(["a"], [], !0, function($__System) {
var require = this.require,
exports = this.exports,
module = this.module;
! function(t) {
function e(t, e) {
for (var n = t.split("."); n.length;) e = e[n.shift()];
return e
}
function n(e) {
if (-1 === o.indexOf(e)) {
try {
var n = t[e]
} catch (t) {
o.push(e)
}
this(e, n)
}
}
var i, r = $__System,
o = ["_g", "sessionStorage", "localStorage", "clipboardData", "frames", "frameElement", "external", "mozAnimationStartTime", "webkitStorageInfo", "webkitIndexedDB", "mozInnerScreenY", "mozInnerScreenX"];
r.registry.set("@@global-helpers", r.newModule({
prepareGlobal: function(r, o, a) {
var s = t.define;
t.define = void 0;
var u;
if (a) {
u = {};
for (var c in a) u[c] = t[c], t[c] = a[c]
}
return o || (i = {}, Object.keys(t).forEach(n, function(t, e) {
i[t] = e
})),
function() {
var r, a = o ? function(n) {
if ("string" == typeof n) return e(n, t);
if (!(n instanceof Array)) throw new Error("Global exports must be a string or array.");
for (var i = {}, r = 0; r < n.length; r++) i[n[r].split(".").pop()] = e(n[r], t);
return i
}(o) : {},
c = !!o;
if (o || Object.keys(t).forEach(n, function(t, e) {
i[t] !== e && void 0 !== e && (o || (a[t] = e, void 0 !== r ? c || r === e || (c = !0) : r = e))
}), a = c ? a : r, u)
for (var l in u) t[l] = u[l];
return t.define = s, a
}
}
}))
}("undefined" != typeof self ? self : "undefined" != typeof global ? global : this),
function(t) {
"use strict";
var e = function() {},
n = t.requestAnimationFrame || t.webkitRequestAnimationFrame || t.mozRequestAnimationFrame || t.msRequestAnimationFrame || function(t) {
return setTimeout(t, 16)
};
function i() {
this.reads = [], this.writes = [], this.raf = n.bind(t), e("initialized", this)
}
i.prototype = {
constructor: i,
measure: function(t, n) {
e("measure");
var i = n ? t.bind(n) : t;
return this.reads.push(i), r(this), i
},
mutate: function(t, n) {
e("mutate");
var i = n ? t.bind(n) : t;
return this.writes.push(i), r(this), i
},
clear: function(t) {
return e("clear", t), a(this.reads, t) || a(this.writes, t)
},
extend: function(t) {
if (e("extend", t), "object" != typeof t) throw new Error("expected object");
var n = Object.create(this);
return function(t, e) {
for (var n in e) e.hasOwnProperty(n) && (t[n] = e[n])
}(n, t), n.fastdom = this, n.initialize && n.initialize(), n
},
catch: null
};
function r(t) {
t.scheduled || (t.scheduled = !0, t.raf(function(t) {
e("flush");
var n, i = t.writes,
a = t.reads;
try {
e("flushing reads", a.length), o(a), e("flushing writes", i.length), o(i)
} catch (t) {
n = t
}
t.scheduled = !1, (a.length || i.length) && r(t);
if (n) {
if (e("task errored", n.message), !t.catch) throw n;
t.catch(n)
}
}.bind(null, t)), e("flush scheduled"))
}
function o(t) {
e("run tasks");
for (var n; n = t.shift();) n()
}
function a(t, e) {
var n = t.indexOf(e);
return !!~n && !!t.splice(n, 1)
}
var s = t.fastdom = t.fastdom || new i;
"f" == "function" [0] ? $__System.registerDynamic("b", [], !1, function(t, e, n) {
return function() {
return s
}.call(this)
}): "o" == (typeof module)[0] && (module.exports = s)
}(window || this),
function() {
var t = {
initialize: function() {
this._tasks = new Map
},
mutate: function(t, n) {
return e(this, "mutate", t, n)
},
measure: function(t, n) {
return e(this, "measure", t, n)
},
clear: function(t) {
var e = this._tasks,
n = e.get(t);
this.fastdom.clear(n), e.delete(n)
}
};
function e(t, e, n, i) {
var r, o = t._tasks,
a = t.fastdom,
s = new Promise(function(t, u) {
r = a[e](function() {
o.delete(s);
try {
t(i ? n.call(i) : n())
} catch (t) {
u(t)
}
}, i)
});
return o.set(s, r), s
}
"f" == "function" [0] ? $__System.registerDynamic("c", [], !1, function(e, n, i) {
return function() {
return t
}.call(this)
}): "o" == (typeof module)[0] ? module.exports = t : window.fastdomPromised = t
}(), $__System.registerDynamic("d", ["e"], !0, function(t, e, n) {
this || self;
! function(t) {
var e;
e = function(t) {
return t
}, t.defaultLanguage = e(navigator.languages && navigator.languages.length > 0 ? navigator.languages[0] : navigator.language || navigator.userLanguage), t.localize = function(n, i) {
var r, o, a, s, u, c, l, f, h, d, m, v, p, g, b, y, w, F;
return null == i && (i = {}), F = this, s = {}, a = i.fileExtension || "json", o = t.Deferred(), l = function(t, e, n) {
switch (null == n && (n = 1), n) {
case 1:
return s = {}, u(e + ".lproj/" + t + "." + a, t, e, n);
default:
return o.resolve()
}
}, u = function(e, n, r, o) {
var a, u, c;
return null != i.pathPrefix && (e = i.pathPrefix + "/" + e), c = function(e) {
return t.extend(s, e), p(s), l(n, r, o + 1)
}, u = function() {
return 2 === o && r.indexOf("-") > -1 ? l(n, r, o + 1) : i.fallback && i.fallback !== r ? l(n, i.fallback) : void 0
}, t.localize.data[n] ? c(t.localize.data[n]) : (a = {
url: e,
dataType: "json",
async: !0,
timeout: null != i.timeout ? i.timeout : 500,
success: c,
error: u
}, "file:" === window.location.protocol && (a.error = function(e) {
return c(e.responseText ? t.parseJSON(e.responseText) : {})
}), t.ajax(a))
}, p = function(t) {
return null != i.callback ? i.callback(t, r) : r(t)
}, r = function(e) {
return t.localize.data[n] = e, F.each(function() {
var n, i, r;
if (i = ((n = t(this)).data("localize") || n.data("afterContent") || n.attr("ty-hint") || "").replace(/\\n/g, "\n"), r = w(i, e)) return f(n, i, r)
})
}, f = function(e, n, i) {
if (e.is("input") ? m(e, n, i) : e.is("textarea") ? m(e, n, i) : e.is("img") ? d(e, n, i) : e.is("optgroup") && v(e, n, i), e[0].hasAttribute("data-after-content")) e.attr("data-after-content", i);
else if (e[0].hasAttribute("ty-hint")) e.attr("ty-hint", i).attr("aria-label", i);
else if (e[0].hasAttribute("data-lt")) e.html(i);
else {
if (t.isPlainObject(i)) return h(e, i);
e.text(i)
}
}, m = function(e, n, i) {
var r;
if (r = t.isPlainObject(i) ? i.value : i, e.is("[placeholder]")) return e.attr("placeholder", r)
}, h = function(t, e) {
return b(t, "title", e), y(t, "text", e)
}, v = function(t, e, n) {
return t.attr("label", n)
}, d = function(t, e, n) {
return b(t, "alt", n), b(t, "src", n)
}, w = function(t, e) {
return e[t] || t
}, b = function(t, e, n) {
if (null != (n = w(e, n))) return t.attr(e, n)
}, y = function(t, e, n) {
if (null != (n = w(e, n))) return t.text(n)
}, g = function(t) {
var e;
return "string" == typeof t ? "^" + t + "$" : null != t.length ? function() {
var n, i, r;
for (r = [], n = 0, i = t.length; n < i; n++) e = t[n], r.push(g(e));
return r
}().join("|") : t
}, c = e(i.language ? i.language : t.defaultLanguage), i.skipLanguage && c.match(g(i.skipLanguage)) ? o.resolve() : l(n, c, 1), F.localizePromise = o, F
}, t.fn.localize = t.localize, t.localize.getString = function(e, n) {
return (t.localize.data[n || "Front"] || {})[e] || e
}, t.localize.isLoaded = function(e) {
return !!t.localize.data[e || "Front"]
}, t.localize.data = {}
}(t("e"))
}), $__System.registerDynamic("f", ["e"], !0, function(t, e, n) {
"use strict";
this || self;
if (window.jQuery || (window.$ = t("e"), window.jQuery = window.$), "undefined" == typeof jQuery) throw new Error("Bootstrap's JavaScript requires jQuery");
! function(t) {
var e = '[data-dismiss="alert"]',
n = function(n) {
t(n).on("click", e, this.close)
};
n.VERSION = "3.2.0", n.prototype.close = function(e) {
var n = t(this),
i = n.attr("data-target");
i || (i = (i = n.attr("href")) && i.replace(/.*(?=#[^\s]*$)/, ""));
var r = t(i);
e && e.preventDefault(), r.length || (r = n.hasClass("alert") ? n : n.parent()), r.trigger(e = t.Event("close.bs.alert")), e.isDefaultPrevented() || (r.removeClass("in"), t.support.transition && r.hasClass("fade") ? r.one("bsTransitionEnd", o).emulateTransitionEnd(150) : o());
function o() {
r.detach().trigger("closed.bs.alert").remove()
}
};
var i = t.fn.alert;
t.fn.alert = function(e) {
return this.each(function() {
var i = t(this),
r = i.data("bs.alert");
r || i.data("bs.alert", r = new n(this)), "string" == typeof e && r[e].call(i)
})
}, t.fn.alert.Constructor = n, t.fn.alert.noConflict = function() {
return t.fn.alert = i, this
}, t(document).on("click.bs.alert.data-api", e, n.prototype.close)
}(jQuery),
function(t) {
var e = function(n, i) {
this.$element = t(n), this.options = t.extend({}, e.DEFAULTS, i), this.isLoading = !1
};
e.VERSION = "3.2.0", e.DEFAULTS = {
loadingText: "loading..."
}, e.prototype.setState = function(e) {
var n = "disabled",
i = this.$element,
r = i.is("input") ? "val" : "html",
o = i.data();
e += "Text", null == o.resetText && i.data("resetText", i[r]()), i[r](null == o[e] ? this.options[e] : o[e]), setTimeout(t.proxy(function() {
"loadingText" == e ? (this.isLoading = !0, i.addClass(n).attr(n, n)) : this.isLoading && (this.isLoading = !1, i.removeClass(n).removeAttr(n))
}, this), 0)
}, e.prototype.toggle = function() {
var t = !0,
e = this.$element.closest('[data-toggle="buttons"]');
if (e.length) {
var n = this.$element.find("input");
"radio" == n.prop("type") && (n.prop("checked") && this.$element.hasClass("active") ? t = !1 : e.find(".active").removeClass("active")), t && n.prop("checked", !this.$element.hasClass("active")).trigger("change")
}
t && this.$element.toggleClass("active")
};
function n(n) {
return this.each(function() {
var i = t(this),
r = i.data("bs.button"),
o = "object" == typeof n && n;
r || i.data("bs.button", r = new e(this, o)), "toggle" == n ? r.toggle() : n && r.setState(n)
})
}
var i = t.fn.button;
t.fn.button = n, t.fn.button.Constructor = e, t.fn.button.noConflict = function() {
return t.fn.button = i, this
}, t(document).on("click.bs.button.data-api", '[data-toggle^="button"]', function(e) {
var i = t(e.target);
i.hasClass("btn") || (i = i.closest(".btn")), n.call(i, "toggle"), e.preventDefault()
})
}(jQuery),
function(t) {
var e = ".dropdown-backdrop",
n = '[data-toggle="dropdown"]',
i = function(e) {
t(e).on("click.bs.dropdown", this.toggle)
};
i.VERSION = "3.2.0", i.prototype.toggle = function(e) {
var n = t(this);
if (!n.is(".disabled, :disabled")) {
var i = o(n),
a = i.hasClass("open");
if (r(), !a) {
"ontouchstart" in document.documentElement && !i.closest(".navbar-nav").length && t('<div class="dropdown-backdrop"/>').insertAfter(t(this)).on("click", r);
var s = {
relatedTarget: this
};
if (i.trigger(e = t.Event("show.bs.dropdown", s)), e.isDefaultPrevented()) return;
n.trigger("focus"), i.toggleClass("open").trigger("shown.bs.dropdown", s)
}
return !1
}
}, i.prototype.keydown = function(e) {
if (/(38|40|27)/.test(e.keyCode)) {
var i = t(this);
if (e.preventDefault(), e.stopPropagation(), !i.is(".disabled, :disabled")) {
var r = o(i),
a = r.hasClass("open");
if (!a || a && 27 == e.keyCode) return 27 == e.which && r.find(n).trigger("focus"), i.trigger("click");
var s = " li:not(.divider):visible a",
u = r.find('[role="menu"]' + s + ', [role="listbox"]' + s);
if (u.length) {
var c = u.index(u.filter(":focus"));
38 == e.keyCode && c > 0 && c--, 40 == e.keyCode && c < u.length - 1 && c++, ~c || (c = 0), u.eq(c).trigger("focus")
}
}
}
};
function r(i) {
i && 3 === i.which || (t(e).remove(), t(n).each(function() {
var e = o(t(this)),
n = {
relatedTarget: this
};
e.hasClass("open") && (e.trigger(i = t.Event("hide.bs.dropdown", n)), i.isDefaultPrevented() || e.removeClass("open").trigger("hidden.bs.dropdown", n))
}))
}
function o(e) {
var n = e.attr("data-target");
n || (n = (n = e.attr("href")) && /#[A-Za-z]/.test(n) && n.replace(/.*(?=#[^\s]*$)/, ""));
var i = n && t(n);
return i && i.length ? i : e.parent()
}
var a = t.fn.dropdown;
t.fn.dropdown = function(e) {
return this.each(function() {
var n = t(this),
r = n.data("bs.dropdown");
r || n.data("bs.dropdown", r = new i(this)), "string" == typeof e && r[e].call(n)
})
}, t.fn.dropdown.Constructor = i, t.fn.dropdown.noConflict = function() {
return t.fn.dropdown = a, this
}, t(document).on("click.bs.dropdown.data-api", "modal.fade.in", r).on("click.bs.dropdown.data-api", ".dropdown form", function(t) {
t.stopPropagation()
}).on("click.bs.dropdown.data-api", n, i.prototype.toggle).on("keydown.bs.dropdown.data-api", n + ', [role="menu"], [role="listbox"]', i.prototype.keydown)
}(jQuery),
function(t) {
var e = function(e, n) {
this.options = n, this.$body = t(document.body), this.$element = t(e), this.$backdrop = this.isShown = null, this.scrollbarWidth = 0, this.options.remote && this.$element.find(".modal-content").load(this.options.remote, t.proxy(function() {
this.$element.trigger("loaded.bs.modal")
}, this))
};
e.VERSION = "3.2.0", e.DEFAULTS = {
backdrop: !0,
keyboard: !0,
show: !0
}, e.prototype.toggle = function(t) {
return this.isShown ? this.hide() : this.show(t)
}, e.prototype.show = function(e) {
var n = this,
i = t.Event("show.bs.modal", {
relatedTarget: e
});
this.$element.trigger(i), this.isShown || i.isDefaultPrevented() || (this.isShown = !0, this.checkScrollbar(), this.$body.addClass("modal-open"), this.setScrollbar(), this.escape(), this.$element.on("click.dismiss.bs.modal", '[data-dismiss="modal"]', t.proxy(this.hide, this)), this.backdrop(function() {
var i = t.support.transition && n.$element.hasClass("fade");
n.$element.parent().length || n.$element.appendTo(n.$body), n.$element.show().scrollTop(0), i && n.$element[0].offsetWidth, n.$element.addClass("in").attr("aria-hidden", !1), n.enforceFocus();
var r = t.Event("shown.bs.modal", {
relatedTarget: e
});
i ? n.$element.find(".modal-dialog").one("bsTransitionEnd", function() {
n.$element.trigger("focus").trigger(r)
}).emulateTransitionEnd(300) : n.$element.trigger("focus").trigger(r)
}))
}, e.prototype.hide = function(e) {
e && e.preventDefault(), e = t.Event("hide.bs.modal"), this.$element.trigger(e), this.isShown && !e.isDefaultPrevented() && (this.isShown = !1, this.resetScrollbar(), this.escape(), t(document).off("focusin.bs.modal"), this.$element.removeClass("in").attr("aria-hidden", !0).off("click.dismiss.bs.modal"), t.support.transition && this.$element.hasClass("fade") ? this.$element.one("bsTransitionEnd", t.proxy(this.hideModal, this)).emulateTransitionEnd(300) : this.hideModal())
}, e.prototype.enforceFocus = function() {
t(document).off("focusin.bs.modal").on("focusin.bs.modal", t.proxy(function(t) {
this.$element[0] === t.target || this.$element.has(t.target).length || this.$element.trigger("focus")
}, this))
}, e.prototype.escape = function() {
this.isShown && this.options.keyboard ? this.$element.on("keyup.dismiss.bs.modal", t.proxy(function(t) {
27 == t.which && this.hide()
}, this)) : this.isShown || this.$element.off("keyup.dismiss.bs.modal")
}, e.prototype.hideModal = function() {
var e = this;
this.$element.hide(), this.backdrop(function() {
e.$element.trigger("hidden.bs.modal"), t("body").removeClass("modal-open")
})
}, e.prototype.removeBackdrop = function() {
this.$backdrop && this.$backdrop.remove(), this.$backdrop = null
}, e.prototype.backdrop = function(e) {
var n = this,
i = this.$element.hasClass("fade") ? "fade" : "";
if (this.isShown && this.options.backdrop) {
var r = t.support.transition && i;
if (this.$backdrop = t('<div class="modal-backdrop ' + i + '" />').appendTo(this.$body), this.$element.on("click.dismiss.bs.modal", t.proxy(function(t) {
t.target === t.currentTarget && ("static" == this.options.backdrop ? this.$element[0].focus.call(this.$element[0]) : this.hide.call(this))
}, this)), r && this.$backdrop[0].offsetWidth, this.$backdrop.addClass("in"), !e) return;
r ? this.$backdrop.one("bsTransitionEnd", e).emulateTransitionEnd(150) : e()
} else if (!this.isShown && this.$backdrop) {
this.$backdrop.removeClass("in");
var o = function() {
n.removeBackdrop(), e && e()
};
t.support.transition && this.$element.hasClass("fade") ? this.$backdrop.one("bsTransitionEnd", o).emulateTransitionEnd(150) : o()
} else e && e()
}, e.prototype.checkScrollbar = function() {
document.body.clientWidth >= window.innerWidth || (this.scrollbarWidth = this.scrollbarWidth || this.measureScrollbar())
}, e.prototype.setScrollbar = function() {
var t = parseInt(this.$body.css("padding-right") || 0, 10);
this.scrollbarWidth && this.$body.css("padding-right", t + this.scrollbarWidth)
}, e.prototype.resetScrollbar = function() {
this.$body.css("padding-right", "")
}, e.prototype.measureScrollbar = function() {
var t = document.createElement("div");
t.className = "modal-scrollbar-measure", this.$body.append(t);
var e = t.offsetWidth - t.clientWidth;
return this.$body[0].removeChild(t), e
};
function n(n, i) {
return this.each(function() {
var r = t(this),
o = r.data("bs.modal"),
a = t.extend({}, e.DEFAULTS, r.data(), "object" == typeof n && n);
o || r.data("bs.modal", o = new e(this, a)), "string" == typeof n ? o[n](i) : a.show && o.show(i)
})
}
var i = t.fn.modal;
t.fn.modal = n, t.fn.modal.Constructor = e, t.fn.modal.noConflict = function() {
return t.fn.modal = i, this
}, t(document).on("click.bs.modal.data-api", '[data-toggle="modal"]', function(e) {
var i = t(this),
r = i.attr("href"),
o = t(i.attr("data-target") || r && r.replace(/.*(?=#[^\s]+$)/, "")),
a = o.data("bs.modal") ? "toggle" : t.extend({
remote: !/#/.test(r) && r
}, o.data(), i.data());
i.is("a") && e.preventDefault(), o.one("show.bs.modal", function(t) {
t.isDefaultPrevented() || o.one("hidden.bs.modal", function() {
i.is(":visible") && i.trigger("focus")
})
}), n.call(o, a, this)
})
}(jQuery),
function(t) {
var e = function(e) {
this.element = t(e)
};
e.VERSION = "3.2.0", e.prototype.show = function() {
var e = this.element,
n = e.closest("ul:not(.dropdown-menu)"),
i = e.data("target");
if (i || (i = (i = e.attr("href")) && i.replace(/.*(?=#[^\s]*$)/, "")), !e.parent("li").hasClass("active")) {
var r = n.find(".active:last a")[0],
o = t.Event("show.bs.tab", {
relatedTarget: r
});
if (e.trigger(o), !o.isDefaultPrevented()) {
var a = t(i);
this.activate(e.closest("li"), n), this.activate(a, a.parent(), function() {
e.trigger({
type: "shown.bs.tab",
relatedTarget: r
})
})
}
}
}, e.prototype.activate = function(e, n, i) {
var r = n.find("> .active"),
o = i && t.support.transition && r.hasClass("fade");
function a() {
r.removeClass("active").find("> .dropdown-menu > .active").removeClass("active"), e.addClass("active"), o ? (e[0].offsetWidth, e.addClass("in")) : e.removeClass("fade"), e.parent(".dropdown-menu") && e.closest("li.dropdown").addClass("active"), i && i()
}
o ? r.one("bsTransitionEnd", a).emulateTransitionEnd(150) : a(), r.removeClass("in")
};
function n(n) {
return this.each(function() {
var i = t(this),
r = i.data("bs.tab");
r || i.data("bs.tab", r = new e(this)), "string" == typeof n && r[n]()
})
}
var i = t.fn.tab;
t.fn.tab = n, t.fn.tab.Constructor = e, t.fn.tab.noConflict = function() {
return t.fn.tab = i, this
}, t(document).on("click.bs.tab.data-api", '[data-toggle="tab"], [data-toggle="pill"]', function(e) {
e.preventDefault(), n.call(t(this), "show")
})
}(jQuery)
}), $__System.registerDynamic("10", [], !0, function(t, e, n) {
"use strict";
this || self;
var i = window.reqnode ? reqnode("electron") : null,
r = i ? i.remote.app : null,
o = window.bridge,
a = null,
s = {
clipboard: {
readText: function() {
return i ? i.clipboard.readText() || "" : o ? o.callSync("clipboard.readText") : void 0
},
writeForMac: function(t, e) {
return o.callHandler("clipboard.write", {
data: t,
shouldClear: !!e
})
},
read: function(t, e) {
var n = e || {},
i = t && (t.clipboardData || t.dataTransfer);
return i && (n.html = i.getData("text/html"), n.markhtml = i.getData("text/markhtml"), n.text = i.getData("text/plain")), o ? new Promise(function(t, e) {
o.callHandler("clipboard.read", {}, function(e) {
n.html || n.markhtml || (n.html = (e.html || [])[0], n.baseUrlInClipboard = (e.html || [])[1]), i || n.html || (n.text = e.text), n.files = e.files || [], t(n)
})
}) : Promise.resolve(n)
},
readImage: function() {
var t = File.editor.imgEdit;
return new Promise(function(e, n) {
var a = t.getTagetImageStorageFolder();
if (o) o.callHandler("clipboard.readImage", {
imageStorageFolder: a,
slient: a == t.getTagetImageStorageFolderFromSetting()
}, e);
else if (i) {
var s = i.clipboard.readImage();
s && !s.isEmpty() ? (a = a || r.getPath("userData") + "/typora-user-images", t.prepImageMove(a).then(function() {
var t = reqnode("path").join(a, Number(new Date) + ".png");
reqnode("fs").writeFileSync(t, s.toPNG()), e([t])
})) : e(null)
} else e(null)
})
}
},
menu: {
update: function(t, e) {
if (t) {
if (e && "string" == typeof t) {
var n = t;
(t = {})[n] = e
}
File.isNode ? i.ipcRenderer.send("menu.updateMenu", t) : o && o.callHandler("menu.updateMenu", t)
}
}
},
putSetting: function(t, e) {
o ? o.callHandler("setting.put", {
key: t,
value: e
}) : r && r.setting.put(t, e)
},
getSetting: function(t, e) {
var n = void 0;
return void 0 == (n = o ? o.callSync("setting.get", t) : r && r.setting.get(t)) ? e : n
},
showInFinder: function(t) {
File.isMac ? o.callHandler("path.showInFinder", t) : i.remote.shell.showItemInFolder(t)
},
fsCaseInsensitive: function() {
return null === a && (File.isNode && (a = File.isWin || reqnode("fs-plus").isCaseInsensitive), File.isMac && (a = !0)), a
}
};
window.JSBridge = s, e.JSBridge = s
}), $__System.registerDynamic("11", ["12", "13", "14"], !0, function(t, e, n) {
this || self, t("12");
var i = t("13"),
r = i.Node,
o = i.NodeMap,
a = i.TYPE,
s = t("14"),
u = /\uE027/gi,
c = ["-", "+", "*"];
r.UL_DEFAULT_START = c, r.prototype.toMark = function() {
var t = f.call(this);
return t instanceof Array ? t.join(File.useCRLF ? "\r\n" : "\n").replace(u, "") : t
};
var l = function(t, e) {
return "right" == t ? "-".repeat(e - 1) + ":" : "center" == t ? ":" + "-".repeat(e - 2) + ":" : "left" == t ? ":" + "-".repeat(e - 1) : "-".repeat(e)
},
f = function() {
var t, e, n, i = [];
function o(t) {
if (t.get("children").length) return v(t.get("children"));
var e = t.get("text") ? t.get("text") : "";
return e = e.replace(/(\u200B*):(\u200B*)/g, ":").replace(/\u200B\$/, "$")
}
function c(t, e) {
g(t, e.get("ahead") || 0)
}
function p(t, e, n) {
void 0 === n && (n = e.get("after") ? 1 : 0), g(t, void 0 == e.get("tail") ? n : e.get("tail"))
}
function g(t, e) {
for (var n = 0; n < e; n++) t.push("")
}
function b(t) {
return r.isType(t.get("parent"), a.list_item) && !1 !== t.get("parent").get("tight")
}
function y(t, e) {
var n = -1,
i = "",
o = this.get("alignText");
for (J = 0; J < t.length; J++)
if (K = this.get("align")[J], o) {
var a = o[J];
if (a) i += a, n = J;
else if (n > -1) {
var s = o[n],
u = this.get("align")[n];
" " != s[0] || " " === s[s.length - 1] || u && "center" != u || (o[n] = s + " ", i += " "), i += r.adjustAlignText(this, n, K)
} else i += ((H = e.getNthChild(J)).get("marginLeft") || "") + l(K, 4) + (H.get("marginRight") || "");
i += "|"
} else i += " " + l(K, t[J]) + " |";
return i
}
try {
switch (this.get("type")) {
case a.meta_block:
return i.push("---"), (i = i.concat((this.get("text") || "").replace(/^---/gm, "​---").split(/\r*\n/))).push("---"), p(i, this), i;
case a.heading:
if (c(i, this), this.get("pattern")) i = i.concat(this.get("pattern").replace("{0}", o(this)).split(/\r*\n/));
else if (!r.isType(this.get("parent"), a.list_item) && (1 == File.option.headingStyle || 3 == File.option.headingStyle) && this.get("depth") <= 2) i.push(o(this)), 3 == File.option.headingStyle ? i.push((1 == this.get("depth") ? "=" : "-").repeat(Math.max(1, s.wcswidth(this.get("text"))))) : i.push(1 == this.get("depth") ? "===" : "---");
else {
var w = "#".repeat(this.get("depth")) + " " + o(this);
2 == File.option.headingStyle && (w += " " + "#".repeat(this.get("depth"))), i.push(w)
}
return p(i, this), i;
case a.paragraph:
c(i, this), e = this.get("text").split(/\r?\n/g).map(function(t) {
return t || ""
}), i = /^( {4}|\t)/.exec(e[0]) ? i.concat(e.map(function(t) {
return t.replace(/^( {4}|\t)/, "​$1")
})) : i.concat(e);
return void 0 === (B = this.get("tail")) && this.get("after") && r.isType(this.get("parent"), a.list_item) && (B = b(this) ? 0 : void 0), r.isType(this.get("after"), a.paragraph) && B < 1 && this.unset("tail"), r.isType(this.get("after"), a.math_block) && !this.get("tail") && (B = 0), void 0 === B ? p(i, this, B) : g(i, B), i;
case a.blockquote:
return c(i, this), e = o(this), (A = this.get("userIndent")) && A.length == e.length ? e.map(function(t, n) {
e[n] = (A[n] || "") + t
}) : (this.unset("userIndent"), n = m(a.blockquote, 0, this, this.get("pattern")), e.map(function(t, i) {
e[i] = t ? n + t : n.replace(/\s+$/, "")
})), p(i = i.concat(e), this), "" !== i.last() && r.isType(this.get("after"), a.blockquote) && i.push(""), i;
case a.list:
c(i, this);
var F = this.get("style"),
k = this.isLoose(),
x = this.get("children").length,
_ = this;
if (x)
for (var $ = this.getFirstChild(), E = Number.isNaN(Number.parseInt(this.get("start"))) ? 0 : Number.parseInt(this.get("start")) - 1, C = 0; $;) {
$.set("tight", !k), e = f.call($), t = this.get("pattern"), k && t && $.get("markindent") && (t = d(F, t.trim(), $.get("markindent")));
var A, S = Math.min($.get("prespace") || 0, 3),
T = void 0 === this.get("isFixed") && File.option.olStyle || this.get("isFixed"),
M = (n = " ".repeat(S) + m(F, (T ? 0 : C) + E, $, t, (x + "").length)).length,
D = "",
L = F == r.ListType.ol ? (C + E + "").length - 1 : 0;
D = (M = $.get("subindent") ? Math.min(n.replace(/\s+$/, "").length + 4, $.get("subindent") + L) : _.get("subindent") ? Math.min(n.replace(/\s+$/, "").length + 4, _.get("subindent") + L) : File.option.indentByTab ? 0 : Math.max(M, File.option.indentSize)) ? " ".repeat(M) : "\t";
if ((A = $.get("userIndent")) && A.length == e.length) $.get("style") == r.ListType.task && (A[0].trim().length && -1 == A[0].indexOf("[") && (A[0] = A[0] + "[ ] "), $.get("checked") ? A[0] = A[0].replace("[ ]", "[x]") : A[0] = A[0].replace(/\[x\]/i, "[ ]")), e.map(function(t, n) {
e[n] = A[n] + t, i.push(e[n].replace(u, ""))
});
else {
$.unset("userIndent");
var R = n;
$.get("style") == r.ListType.task && (R = n + ($.get("checked") ? "[x] " : "[ ] ")), e.map(function(t, n) {
e[n] = (n ? t ? D : "" : R) + e[n], i.push(e[n].replace(u, ""))
})
}
C++, $ = $.get("after")
}
return r.isType(this.get("after"), a.list) && (!this.get("tail") || this.get("tail")) < 1 && this.get("pattern") == this.get("after").get("pattern") && this.get("style") == this.get("after").get("style") && (this.unset("tail"), i.push(""), b(this) && i.push("")), p(i, this, b(this) ? 0 : function(t) {
var e = _.get("tail"),
n = _.get("after");
if (0 === e) {
if (r.isType(n, a.paragraph)) return void t.unset("tail");
if (r.isType(n, a.fences) && /^\s+$/.exec(n.get("pattern") || "")) return void t.unset("tail")
}
return e
}(this)), i;
case a.list_item:
"string" == typeof(e = o(this)) && (e = [e]), i = i.concat(e);
var B;
for (void 0 == (B = this.get("tail")) && !this.get("tight") && this.get("after") && (B = 1), B > 0 && i.push(""); i.length > 2 && "" === i.last() && "" === i[i.length - 2];) i.pop();
return i;
case a.fences:
c(i, this);
var I = this.getText();
e = I.split(/\r*\n/), this.get("lang") ? (this.get("pattern") || "").trim() ? t = this.get("pattern") : (this.unset("pattern"), t = /^\s*```/gm.exec(this.get("text") || "") ? "~~~{0}" : "```{0}") : t = this.get("pattern") || "```{0}";
var N = t.replace(/\s*\{0\}/, "");
this.get("pattern") && (N = this.get("patternEnd") || N);
var O, j = t.match(/^\s+$/),
P = (t.match(/[`~]/) || [])[0];
P && (O = new RegExp("^(" + P + "{3})"));
for (C = 0; C < e.length; C++) e[C] = (j ? t : "") + (O ? e[C].replace(O, "​$1") : e[C]), e[C] = e[C] || "";
return !j && i.push(t.replace(/\{0\}/, this.get("lang") || "")), i = i.concat(e), !j && i.push(N), p(i, this), i;
case a.math_block:
return c(i, this), this.get("tagBefore") ? i.push("$$ {" + this.get("tagBefore") + "}") : i.push("$$"), i = i.concat(this.get("text").replace(/(^\n)|(\n$)/g, "").split(/\r?\n/).map(function(t) {
return t || ""
})), this.get("tagAfter") ? i.push("$$ {" + this.get("tagAfter") + "}") : i.push("$$"), p(i, this, r.isType(this.get("after"), a.paragraph) && r.isType(this.get("before"), a.paragraph) ? 0 : void 0), i;
case a.hr:
return i.push(this.get("pattern") || "------"), p(i, this), i;
case a.def_footnote:
return c(i, this), i.push("[^" + this.get("ref") + "]:" + s.orDefault(this.get("pattern"), " ") + o(this)), p(i, this, !this.get("after") || r.isType(this.get("after"), r.TYPE.def_footnote) ? 0 : 1), i;
case a.def_link:
c(i, this);
var q, U = this.safeGetStrAttr("title").length;
if (this.get("pattern")) {
var z = this.get("pattern").split(";");
q = z[0] + this.get("ref") + z[1] + this.safeGetStrAttr("href") + z[2], U && (q += (z[3] || "\t") + '"' + this.get("title") + '"')
} else q = "[" + this.get("ref") + "]: " + this.safeGetStrAttr("href") + (U ? '\t"' + this.get("title") + '"' : "");
return i.push(q), p(i, this, !this.get("after") || r.isType(this.get("after"), r.TYPE.def_link) ? 0 : 1), i;
case a.table:
if (c(i, this), this.get("userText")) return p(i = i.concat(this.get("userText").clone()), this), i;
for (var H, W, J, Y, G, K, V, Q = [], X = [], Z = 0, tt = this.getFirstChild(); tt;) {
for (W = tt.getFirstChild(), X[Z] = [], J = 0; W;) X[Z][J] = W.toMark().trim(), W = W.get("after"), 0 === Z && (Q[J] = 4), Q[J] = Math.max(s.wcswidth(X[Z][J]), Q[J]), Q[J] = Math.min(Q[J], 60), J++;
tt = tt.get("after"), Z++
}
var et = "npTable" == this.get("style") && Q.length > 1;
for (tt = this.getFirstChild(), Z = 0; Z < X.length; Z++) {
for (Y = "|", H = tt.getFirstChild(), J = 0; J < Q.length; J++) void 0 !== H.get("marginLeft") ? (Y += H.get("marginLeft") + X[Z][J] + H.get("marginRight"), Y += "|") : (Y += " ", G = Math.max(Q[J] - s.wcswidth(X[Z][J]), 0), Y += "right" == (K = this.get("align")[J]) ? " ".repeat(G) + X[Z][J] : "center" == K ? " ".repeat(V = ~~(G / 2)) + X[Z][J] + " ".repeat(G - V) : X[Z][J] + " ".repeat(G), Y += " |"), H = H.get("after");
et ? i.push(Y.replace(/(^\s*\|)|(\|\s*$)/g, "")) : i.push(Y.replace(/\s$/, "")), 0 === Z && (Y = "|" + y.call(this, Q, tt), et ? i.push(Y.replace(/(^\s*\|)|(\|\s*$)/g, "")) : i.push(Y.replace(/\s$/, ""))), tt = tt.get("after")
}
return p(i, this), i;
case a.table_row:
return console.sendError("cannot call toMark on table_row"), "";
case a.table_cell:
return h(o(this));
case a.toc:
return c(i, this), i.push(this.get("pattern") || "[TOC]"), ~(this.get("pattern") || "").indexOf("\n") && this.get("after") ? p(i, this, 2) : p(i, this), i;
case a.html_block:
return c(i, this), p(i = i.concat(this.get("text").replace(/(^\n)|(\n$)/g, "").split(/\r?\n/).map(function(t) {
return t || ""
})), this), i;
default:
return o(this)
}
} catch (t) {
return console.error(t.stack), i
}
},
h = function(t) {
var e = "",
n = "",
i = [],
r = 0,
o = 0;
return t = t.replace(/(^|[^\\])`[^`]*\|[^`]*`/g, function(t) {
return i.push(t), [e, ++r - 1, n].join("")
}), File.option.enableInlineMath && (t = t.replace(/(^|[^\\])\$[^$]*\|[^$]*\$/g, function(t) {
return i.push(t), [e, ++r - 1, n].join("")
})), t.replace(/\|/g, "\\|").replace(/\\\\\|/g, "\\|").replace(/\uE07A[^\uE07B]+\uE07B/g, function() {
return i[++o - 1]
})
},
d = function(t, e, n) {
var i = File.option.prettyIndent;
return void 0 !== n ? n -= 0 : n = Math.max(File.option.indentSize - 0, 2), t == a.blockquote ? ">" + " ".repeat(Math.min(n - 1, i ? 4 : 1)) : t === r.ListType.ol ? "{0}." + " ".repeat(Math.min(n - 2, i ? 4 : 1) || 1) : t === r.ListType.ul ? (e || c[File.option.ulStyle]) + " ".repeat(Math.min(n - 1, i ? 4 : 1)) : c[File.option.ulStyle] + " "
},
m = function(t, e, n, i) {
var o = File.option.indentSize;
return e++, i = i || d(t), (!$.isNumeric(o) || o < 2) && (o = 2), t == a.blockquote ? i : t === r.ListType.ol ? i.replace("{0}", e) : i
};
r.getIndentPrefix = m, r.getDefaultPrefixPattern = d, r.markFromArr = function(t) {
var e = v(t);
return e instanceof Array ? e.join(File.useCRLF ? "\r\n" : "\n").replace(u, "") : e
};
var v = function(t) {
var e = [],
n = "";
function i(t) {
var i = f.call(t);
i instanceof Array ? e = e.concat(i) : n += i
}
if (t.length)
if (t instanceof Array) t.map(function(t) {
i(t)
});
else {
var r = t.sortedFirst();
do {
i(r), r = r.get("after")
} while (r)
}
return e.length ? e : n
};
o.prototype.toMark = function() {
if (this.blocks.length > 0) {
var t = this.blocks.sortedFirst();
t = t.getLastBrother(!0);
var e = [],
n = "";
do {
var i = f.call(t);
i instanceof Array ? e = e.concat(i) : n += i, t = t.get("after")
} while (t);
return e.length ? e.join(File.useCRLF ? "\r\n" : "\n").replace(u, "") : n
}
return ""
}, r.getIndentPrefix = m
}), $__System.registerDynamic("15", ["12", "13", "14", "16", "17", "18", "19"], !0, function(t, e, n) {
this || self, t("12");
var i = t("13"),
r = i.Node,
o = (i.NodeMap, i.TYPE),
a = (i.NodeCollectionUtils, t("14")),
s = t("16"),
u = (t("17"), t("18")),
c = t("19"),
l = document.querySelector("#md-rawblock-tooltip-templ").innerHTML;
r.prototype.toHTML = function(t, e) {
var n, f = ["h1", "h2", "h3", "h4", "h5", "h6"];
File.option.expandSimpleBlock && r.isType(this, o.paragraph) && (f.indexOf(e) > -1 ? this.set("depth", f.indexOf(e) + 1) : this.unset("depth"));
function h(e, n) {
var a, s = e.get("children");
return void 0 !== t && null !== t ? t : s && s.length > 0 ? i.NodeCollectionUtils.toHTML(s, n) : (a = e.safeGetStrAttr("text"), r.isType(e, o.paragraph) && /^\u200b( {4}|\t)/g.exec(a) && (a = a.replace(/^\u200b( {4}|\t)/g, "$1"), e.set("text", a)), e.cursorDiff = [], c.parseInline(e.safeGetStrAttr("text"), {
attr: !r.isType(e, o.heading)
}, e.cursorDiff))
}
function d(t) {
var n = function(t) {
try {
if (r.isType(t, o.fences, o.hr, o.def_link, o.def_footnote, o.table, o.math_block)) return !1;
if (r.isType(t, o.list_item) && t.get("style") == r.ListType.task) return !1;
if (t.canContainBlock()) return;
return File.inBusyMode ? 0 == t.get("children").length || void 0 : 0 == t.get("children").length || r.isType(t.get("parent"), o.list_item) || void 0
} catch (t) {}
}(t),
i = n ? " contenteditable='true' " : !1 === n ? " contenteditable='false' " : "",
a = e ? "mdlike='" + e + "' " : " ",
s = " cid = '" + t.id + "' mdtype = '" + t.get("type") + "' " + i + a;
return (t.get("text") || "").length > 1e4 && (s += " spellcheck='false' "), s
}
switch (this.get("type")) {
case o.meta_block:
var m = this.get("text") || "";
return m.match(/^\n/g) && (m = m.replace(/^\n/g, "\n\n")), "<pre " + d(this) + " class='md-meta-block md-end-block' >" + a.escape(m, !1, !0) + "\n</pre>";
case o.paragraph:
return "<p " + d(this) + " class='md-end-block md-p'>" + h(this) + "</p>";
case o.raw_edit:
return "<p class='rawedit' contenteditable ='true' spellcheck='false' " + d(this) + ">" + this.safeGetStrAttr("text", !0) + "</p>";
case o.heading:
return "<h" + this.get("depth") + d(this) + "class='md-end-block md-heading' >" + h(this) + "</h" + this.get("depth") + ">";
case o.blockquote:
return "<blockquote " + d(this) + " >" + h(this) + "</blockquote>";
case o.list:
var v = this.get("style"),
p = ((this.get("pattern") || r.UL_DEFAULT_START[File.option.ulStyle] || "-").match(/[*+-]/) || [])[0];
if (p = " data-mark='" + p + "' ", v == r.ListType.ol) {
var g = "" === this.get("start") ? void 0 : this.get("start") - 0;
return "<ol class='ol-list' " + (g = Number.isNaN(g) || 1 == g ? "" : "start='" + this.get("start") + "' ") + d(this) + " >" + h(this) + "</ol>"
}
return "<ul class='ul-list' " + d(this) + p + " >" + h(this) + "</ul>";
case o.list_item:
return this.get("parent") && this.get("style") === r.ListType.task ? "<li class='md-list-item task-list-item md-task-list-item task-list-" + (this.get("checked") ? "done" : "not-done") + " ' " + d(this) + "><input type='checkbox' " + (this.get("checked") ? "checked" : "") + "></input>" + h(this) + "</li>" : "<li class='md-list-item' " + d(this) + " >" + h(this) + "</li>";
case o.fences:
var b = "<pre spellcheck='false' class='md-fences mock-cm md-end-block" + (File.option.showLineNumbersForFence ? " md-fences-with-lineno" : "") + "' lang='" + a.escape(this.get("lang") || "") + "' contenteditable='false'" + d(this) + ">" + (this.get("text") && this.get("text").trim().length ? a.escape(this.get("text")) + "\n" : "<br/>") + "</pre>";
if (s.isDiagramType(this.get("lang"))) {
var y = File.editor.findElemById(this.cid);
if (y.find("textarea").val() == this.get("text")) {
b = $(b).append(y.find(".md-diagram-panel").clone())[0].outerHTML
}
}
return b;
case o.hr:
return "<div tabindex='-1' contenteditable='false' " + d(this) + " class='md-hr md-end-block' ><hr /></div>";
case o.def_footnote:
return "<div class='footnotes md-def-footnote md-end-block' contenteditable='false'" + d(this) + "><span class='md-def-name' contenteditable='true'>" + a.escape(this.get("ref") ? this.get("ref") : "​") + "</span><span class='md-def-split md-def-f' contenteditable='false' >&nbsp;</span><span class='md-def-content' contenteditable='true'>" + h(this) + "</span></div>";
case o.def_link:
return "<div class='footnotes md-def-link md-end-block' contenteditable='false'" + d(this) + "><span class='md-def-name' contenteditable='true'>" + a.escape(this.get("ref") ? this.get("ref") : "​") + "</span><span class='md-def-split md-def-f' contenteditable='false' >&nbsp;</span><span class='md-def-content md-def-url md-auto-disp' href='#' contenteditable='true'>" + a.escape(this.get("href")) + "</span><span class='md-def-split md-auto-hide' contenteditable='false'>&nbsp;</span><span class='md-def-title md-auto-disp md-auto-hide' contenteditable='true'>" + a.escape(this.get("title")) + "</span></div>";
case o.table:
this.get("align").length, b = "<figure class='md-table-fig' contenteditable='false' " + d(this) + "><table class='md-table'>";
for (var w = this.getFirstChild(); w;) w.get("before") ? b += w.toHTML() : b += "<thead>" + w.toHTML() + "</thead><tbody>", (w = w.get("after")) || (b += "</tbody>");
return b += "</table></figure>";
case o.table_row:
b = "<tr class='md-end-block' " + d(this) + ">", w = this.getFirstChild();
var F, k = this.get("parent").get("align") || [],
x = 0,
_ = this.get("before") ? "td" : "th";
for (this.get("parent").get("align") || this.get("parent").set("align", []); w;) b += "<" + _ + (F = (F = k[x]) ? " style='text-align:" + F + ";' " : "") + ">" + w.toHTML() + "</" + _ + ">", w = w.get("after"), x++;
return b += "</tr>";
case o.table_cell:
return "<span contenteditable='true' class='td-span' " + d(this) + ">" + h(this) + "</span>";
case o.math_block:
var E = document.createElement("script");
return E.textContent = this.get("text") || "<Empty \\space Math \\space Block>", E.setAttribute("type", "math/tex; mode=display"), "<div contenteditable='false' spellcheck='false' class='mathjax-block md-end-block md-math-block md-rawblock' id='mathjax-" + this.cid + "' " + d(this) + ">" + l.replace("{type}", $.localize.getString("Math", "Menu")) + "<div class='md-rawblock-container md-math-container' tabindex='-1'>" + $(E.outerHTML)[0].outerHTML + "</div></div>";
case o.toc:
return n = this.get("in"), "<div contenteditable='false' tabindex='-1' class='md-toc md-end-block' " + d(this) + "><div class='md-tooltip-hide md-toc-tooltip'><span>" + $.localize.getString("Table of Contents") + "</span> <button type='button' class='btn md-delete-toc'><span class='ty-icon ty-delete'></span></button></div><p class='md-toc-content'>" + (n.toc ? n.toc.getTocInnerHTML() : "") + "</p></div>";
case o.html_block:
return u.HIDDEN_TYPE.indexOf(this.get("displayStyle") || this.get("style")) > -1 && !u.checkIsWhiteList(this) ? "<div contenteditable='false' spellcheck='false' class='md-htmlblock md-rawblock md-end-block' " + d(this) + ">" + l.replace("{type}", "HTML") + "<div class='md-htmlblock-panel md-rawblock-control' style='display:none;' contenteditable='false'></div><div class='md-htmlblock-container md-rawblock-container md-raw-html-src' contenteditable='false'><div class='md-raw-html-src-content'>" + a.escape(this.get("text")) + "</div></div></div>" : "<div contenteditable='false' spellcheck='false' class='md-htmlblock md-rawblock md-end-block' " + d(this) + "><span style='position:absolute;'>​</span>" + l.replace("{type}", "HTML") + "<div class='md-htmlblock-panel md-rawblock-control' style='display:none;' contenteditable='false;'></div><div class='md-htmlblock-container md-rawblock-container' tabindex='-1' contenteditable='false'>" + u.buildHTML(this) + "</div><span style='position:absolute;'>​</span></div>";
default:
return "<p " + d(this) + ">unknow type: " + this.get("type") + "</p>"
}
}
}), $__System.registerDynamic("1a", ["12", "13", "14", "1b", "16", "1c", "1d"], !0, function(t, e, n) {
"use strict";
this || self, t("12");
var i = t("13"),
r = i.Node,
o = i.TYPE,
a = (i.NodeCollectionUtils, t("14")),
s = t("1b"),
u = t("16"),
c = t("1c"),
l = t("1d");
r.normalizeNode = function(t) {
if (0 == t.get("children").length && r.isType(t, o.blockquote)) {
var e = new r({
type: o.paragraph,
parent: t,
in: t.get("in")
});
return r.normalizeNode(e)
}
};
r.genNormalSplitExitFunc = function(t, e, n) {
return function(t, i) {
var a = {
prev: t,
next: i
};
return t.get("type") == o.paragraph && (!n && t.parseFrom({
skips: {
enableStartMatch: !0
}
}), r.isType(t, o.paragraph) || (a.oldCid = t.cid, a.prev = t)), i.get("type") == o.paragraph && (!e && function(t, e) {
try {
var n, i, a = !e.isDeleted() && e.get("parent");
if (a = r.isType(a, o.list_item) && a.get("parent"), !(n = r.isType(a, o.list) && a.get("style"))) return;
if ((i = t.get("text")).match(/^(\s{2, }|\t)/)) return;
n == r.ListType.ol ? i = i.replace(/^\s*\d+\.\s+/, "") : n == r.ListType.ul && (i = i.replace(/^\s*[+*-]\s+/, "")), t.set("text", i)
} catch (t) {}
}(i, t), !n && i.parseFrom(), r.isType(i, o.paragraph) || (a.next = i)), a
}
}, r.prototype.breakOn = function(t, e, n) {
var i, a;
if (r.isType(this, o.table, o.table_row, o.table_cell, o.blockquote, o.list, o.list_item)) return null;
var u = e.selection.buildUndo();
if (r.isType(this, o.def_footnote)) {
var c = e.getJQueryElem(window.getSelection().baseNode);
i = c.closest(".md-def-name").length ? e.selection.getOffset(c.closest(".md-def-name")) : this.get("ref").length + 1 + e.selection.getOffset(c.closest(".md-def-content"))
} else {
var l = e.findElemById(this.id);
l.find(".md-emoji").each(function() {
var t = [];
this.childNodes.forEach(function(e) {
3 == e.nodeType && t.push(e)
});
for (var e = 0; e < t.length; e++) this.removeChild(t[e])
}), l.find(".md-ruby-container").remove(), i = e.selection.getOffset(l)
}
if (!this.get("children").length && (a = this.getText(!1).length, r.isType(this, o.def_link, o.def_footnote) && (a += this.get("ref").length + 1), !this.get("children").length)) {
var f;
return (f = function(e) {
if (e = e.getClosetBlock(), a <= 1 && r.isType(e, o.def_footnote, o.def_footnote) && !t && !n && r.isEmptyBlock(e, null, !0)) return (c = s.makeEmptyCommand(u)).undo.push(s.buildReplaceUndo(e)), e.unset("ahead"), e.unset("tail"), e.set("type", o.paragraph), r.normalizeNode(e), c.redo.push(s.buildReplaceUndo(e)), c.redo.push({
type: "cursor",
id: e.getLastChild().cid,
start: 0
}), {
command: c,
nextFocus: e.getLastChild().cid,
oldCid: e.cid,
newHtml: e.toHTML()
};
if (0 == i && 0 == a && !t && !n && e.closest(o.blockquote, o.list) && e.get("parent") && e.get("parent").canContainBlock(!0) && (e.get("parent").get("type") != o.list_item || !e.get("after")) && ! function(t) {
var e = t.get("parent");
return r.isType(e, o.list_item) && !t.get("before") && !t.get("after") && !e.get("before") && !e.get("after") && e.get("parent").get("attachTo")
}(e)) {
var c;
(c = s.makeEmptyCommand()).undo.push(u);
var l = {},
f = e.get("before") && r.isEmptyBlock(e.get("before"));
return l = e.upStream(f), c.undo = c.undo.concat(l.command.undo), c.redo = c.redo.concat(l.command.redo), l.nextFocus = l.nextFocus || e.id, c.redo.push({
type: "cursor",
id: l.nextFocus,
start: 0
}), l.command = c, l
}
}(this.getClosetBlock())) ? f : (f = function(t) {
if (i == a && t == e.nodeMap.getFirst() && r.isType(t, o.paragraph) && (u = t.get("text"), File.shouldRemapPunctuation() ? "---" == (u || "").replace(/\u2013/g, "--").replace(/\u2014/g, "---") : "---" == u)) {
var n = e.stylize.insertMetaBlock(!0);
return n.command.undo.push(s.buildReplaceUndo(t)), t.set("text", ""), n.command.redo.push(s.buildReplaceUndo(t)), n.newHtml = n.node.toHTML() + t.toHTML(), n.nextFocus = n.node.id, n.oldCid = t.id, n
}
var u
}(this)) ? f : function(i, c, l) {
l = l || s.makeEmptyCommand();
var f = {},
m = c == a && c > 0,
v = i.getClosetBlock();
return l.undo.push(u), r.isType(v.get("parent"), o.list_item) && !t ? l.undo.push(s.buildReplaceUndo(v.get("parent"))) : l.undo.push(s.buildReplaceUndo(v)), v.unset("ahead"), v.unset("tail"), n && r.isType(i, o.paragraph) ? h(i, c, l, m) : (f = r.splitAt(i, c, e, t), l.redo.push(e.undo.buildReplaceUndo(f.prev)), f.prev && f.prev.contains(i) || l.redo.push(e.undo.buildReplaceUndo(i)), i = f.insertArray[0] ? f.insertArray[0].get("before") : i, f.oldCid = i.cid, s.addUndoForInsertArray(l, f.insertArray), f.newHtml = i.toHTML() + f.insertArray.map(function(t) {
return t.toHTML()
}).join(""), d(f, m), l.redo.push({
type: "cursor",
id: f.nextFocus,
start: 0
}), f.command = l, f)
}(this, i = Math.min(a, i))
}
function h(t, i, a, u) {
if (n && r.isType(t, o.paragraph)) {
var c = t.get("text") || "";
if ("\n" == c[i] ? n = !1 : "\n" == c[i - 1] && (n = !1, i--), a.undo.push(s.buildReplaceUndo(t)), t.set("text", c.substring(0, i)), !n) return a.redo.push(s.buildReplaceUndo(t)),
function(t, e, n) {
var i = new r({
type: o.paragraph,
text: n,
in: t.get("in")
});
return t.insert(i), s.addUndoForInsert(e, i), {
oldCid: t.cid,
prev: t,
next: i,
command: e,
nextFocus: i.cid,
newHtml: t.toHTML() + i.toHTML()
}
}(t, a, c.substring(i + 1));
var l = r.smartSplit(e.findElemById(t.id), i);
t.set("text", l[0]);
var f, h = t.parseFrom({
skips: {
enableStartMatch: !0
}
}, void 0, !0);
if (1 == h[1].length && r.isType(h[1][0], o.paragraph)) return t.set("text", l[0] + "\n" + l[1]), a.redo.push(s.buildReplaceUndo(t)), f = {
type: "cursor",
id: t.id,
start: l[0].length + 1
}, a.redo.push(f), {
oldCid: t.cid,
nextFocus: t.cid,
prev: t,
newHtml: t.toHTML(),
command: a,
cursor: f
};
a.redo.push(s.buildReplaceUndo(t));
var m = h[1],
v = m.last(),
p = v.getVeryFirst(!0).getClosetBlock();
r.isType(p, o.paragraph) ? (f = {
type: "cursor",
id: p.id,
start: p.get("text").length + 1
}, p.set("text", p.get("text") + "\n" + l[1])) : (f = {
type: "cursor",
id: (p = new r({
type: o.paragraph,
text: l[1]
})).id,
start: 0
}, m.last().insert(p), m.push(p)), s.addUndoForInsertArray(a, m.subarray(1));
var g = {
oldCid: t.cid,
nextFocus: p.cid,
prev: v,
next: v.get("after"),
newHtml: m.map(function(t) {
return t.toHTML()
}).join(""),
command: a,
cursor: f
};
return 0 == f.start ? (g.cursor = void 0, d(g, u), a.redo.push({
type: "cursor",
id: g.nextFocus,
start: 0
})) : a.redo.push(f), g
}
}
function d(t, e) {
if (r.isType(t.prev, o.meta_block) && e && t.prev.get("text").match(/\n$/)) t.nextFocus = t.next.getVeryFirst().id;
else if (e && r.isType(t.prev && t.prev.getLastChild() || t.prev, o.math_block, o.fences, o.meta_block, o.html_block)) {
var n = t.prev.getVeryFirst(!0);
!r.isType(n, o.html_block) || /\n/.exec(n.get("text")) || n.get("depth") ? t.nextFocus = n.id : t.nextFocus = t.next.getVeryFirst().cid
} else e && r.isType(t.prev, o.table) ? t.nextFocus = t.prev.getLastChild().getVeryFirst().cid : t.nextFocus = t.next.getVeryFirst().cid
}
}, r.isEmptyBlock = function(t, e, n) {
var i = n ? a.isNullOrBlank : a.isNullOrEmpty;
if (r.isType(t, e || [])) return !1;
if (t.get("children").length) {
if (r.isType(t, o.paragraph)) return i(t.get("text"))
} else {
if (r.isType(t, o.def_link)) return i(t.get("ref")) && i(t.get("href")) && i(t.get("title"));
if (r.isType(t, o.def_footnote)) return i(t.get("ref")) && i(t.get("text"));
if (!r.isType(t, o.table_cell, o.table_row, o.hr, o.toc)) return i(t.get("text"))
}
return !1
};
r.smartSplit = function(t, e, n) {
var i, r, o, a = c.createRange();
if (0 == e) return ["", t.rawText()];
if (e == (t[0].textContent || t[0].innerText).length) {
var s = t.rawText();
return File.isMac && File.option.smartQuote && !File.option.convertSmartOnRender && /["']$/.exec(s) && s.length > 1 && (s = s.replace(/["']$/, function(t) {
return l.userQuote("'" == t ? 3 : 1, !1, !0)
})), [s, ""]
}
n ? (o = $.parseHTML("<span />")[0], t[0].appendChild(o), t.prepend("<span />"), a.moveToBookmark({
containerNode: t[0],
start: e,
end: e
}), a.setEndAfter(o), r = (o = a.extractContents()).querySelectorAll("[md-inline='strong'], [md-inline='em'], [md-inline='del'], [md-inline='code']"), i = t[0].querySelectorAll("[md-inline='strong'], [md-inline='em'], [md-inline='del'], [md-inline='code']")) : (t[0].childElementCount < 3 && (o = $.parseHTML("<span />")[0], t[0].insertBefore(o, t[0].firstChild), t.append("<span />")), a.moveToBookmark({
containerNode: t[0],
start: 0,
end: e
}), o && a.setStart(o, 0), i = (o = a.extractContents()).querySelectorAll("[md-inline='strong'], [md-inline='em'], [md-inline='del'], [md-inline='code']"), r = t[0].querySelectorAll("[md-inline='strong'], [md-inline='em'], [md-inline='del'], [md-inline='code']"));
for (var u = 0; u < i.length; u++) {
(f = $(i[u])).find(":not(.md-meta)").text().length ? f.children(".md-after").length || f.append(f.children(".md-before").clone().removeClass("md-before").addClass("md-after")) : f.html("")
}
for (u = 0; u < r.length; u++) {
var f;
(f = $(r[u])).find(":not(.md-meta)").text().length ? f.children(".md-before").length || f.prepend(f.children(".md-after").clone().removeClass("md-after").addClass("md-before")) : f.html("")
}
var h = o.querySelectorAll("svg");
for (u = 0; u < h.length; u++) h[u].parentElement.removeChild(h[u]);
return [$(o).rawText(), t.rawText()]
};
r.splitAt = function(t, e, n, i, a, s) {
if (s = s || !a, r.isType(t, o.def_link, o.def_footnote)) return function(t, e, n) {
var i, a, s = t.clone(),
u = t.get("ref");
if (e <= u.length) t.set("ref", u.substring(0, e)), s.set("ref", u.substring(e)), s.set("href", t.get("href")), s.set("title", t.get("title")), t.set("href", ""), t.set("title", ""), i = "", a = t.get("text");
else if (r.isType(t, o.def_link)) {
var c = t.get("href") || "",
l = t.get("title") || "";
e <= u.length + c.length ? (t.set("title", ""), s.set("ref", ""), t.set("href", c.substring(0, e - u.length - 1)), s.set("href", c.substring(e - u.length - 1))) : (s.set("ref", ""), s.set("href", ""), t.set("title", l.substring(0, e - u.length - c.length - 1)), s.set("title", l.substring(e - u.length - c.length - 1)))
} else {
var f = t.get("text") || "";
s.set("ref", ""), i = f.substring(0, e - u.length - 1), a = f.substring(e - u.length - 1)
}
return t.set("text", i), r.isType(s, o.def_link) || s.set("text", a || ""), r.isEmptyBlock(s) && !r.isType(s, o.paragraph) && (s.set("type", o.paragraph), s.set("text", "")), t.insert(s), {
oldCid: t.cid,
prev: t,
next: s,
insertArray: [s]
}
}(t, e);
var u, c, l, f = t.clone();
if (t.get("children").length) return console.error("cannot do Node.split at this ndoe"), null;
r.isType(t, o.paragraph, o.heading) ? (u = (l = r.smartSplit(n.findElemById(t.id), e))[0].replace(/\n$/, ""), c = l[1].replace(/^\n/, ""), r.isType(t.get("parent"), o.list_item) && t.get("parent").get("parent").get("children").toArray().forEach(function(t) {
t.unset("tail")
})) : (u = t.getText().substring(0, e), c = t.getText().substring(e)), t.set("text", u), f.set("text", c);
var h = t,
d = [h],
m = [];
a || r.isType(t, o.paragraph) && !a && (m = (d = t.parseFrom({
skips: {
enableStartMatch: !0
}
}, void 0, !0)[1]).subarray(1), h = d.last().getVeryFirst().getClosetBlock()), h.insert(f), d.last() == h && m.push(f), r.isEmptyBlock(f) ? f.set("type", o.paragraph) : r.isEmptyBlock(h) && h.set("type", o.paragraph);
var v = {
prev: h,
next: f,
insertArray: m
};
if (i) return v;
if (s && r.isType(h.get("parent"), o.list_item) && !h.get("before")) {
var p = h.get("parent"),
g = p.clone();
p.get("style") == r.ListType.task && g.set("checked", !1), p.insert(g), g.appendTillEnd(f), m = d.subarray(1), d.last() == h && (d = [p]), d.last() == p && m.push(g), v = {
prev: p,
next: g,
insertArray: m
}
}
return v
};
r.getTreePosition = function(t, e) {
function n(t) {
return t.get("parent") ? 1 + n(t.get("parent")) : 0
}
if (t == e) return [t, t, e];
var i = n(t) - n(e);
if (i > 0)
for (; i > 0;) t = t.get("parent"), i--;
else if (i < 0)
for (; i < 0;) e = e.get("parent"), i++;
return function t(e, n) {
return e == n ? [e, e, n] : e.get("parent") == n.get("parent") || !e.get("parent") && !e.get("parent") ? [e.get("parent"), e, n] : t(e.get("parent"), n.get("parent"))
}(t, e)
}, r.prototype.copyContentFrom = function(t) {
var e = this;
r.property.map(function(n) {
e.set(n, t.get(n))
})
}, r.prototype.clone = function() {
var t = new r;
return t.copyContentFrom(this), t.set("in", this.get("in")), t
};
r.reverseAttrFromElem = function(t, e, n, i) {
var s, u = e.attr("mdtype");
t.set("type", u), n && (e.find("[data-emoji]").text(function() {
return this.getAttribute("data-emoji")
}), e.find(".md-meta, .md-content").remove()), t.set("text", !i && r.isType(u, o.paragraph, o.def_footnote, o.heading) ? (c = e, c.find("[md-inline='image'], [md-inline='imgtag']").each(function() {
var t = $(this),
e = t.attr("data-src");
if (!/^[a-z0-9\-]+:/i.exec(e)) {
var n = t.find("img").attr("src") || "",
i = t.text(),
r = File.editor.imgEdit.resolveImagePath(n.replace(/^file:\/\//, "").replace(/[#?]([^.]*)$/, ""));
i = "image" == this.getAttribute("md-inline") ? i.replace(/(\(<?)((?:\([^)]*\)|[^()])*?)(>?[ \t]*((['"])(.*?)\5[ \t]*)?\))/, "$1" + r + "$3") : i.replace(/(^<img(\s+.+)*?\s+src=)("([^"]+)"|'([^']+)')(.*?(\/?\s*>.*?(<\/img>)?))/, '$1"' + r + '"$6'), t.text(i)
}
}), c).text() : e.text());
var c;
switch (u) {
case t.TYPE.heading:
t.set("depth", e[0].tagName.replace(/H/gi, ""));
break;
case t.TYPE.list:
t.set("style", e[0].tagName.toLowerCase()), t.set("start", (e[0].getAttribute("start") || 1) - 0);
break;
case t.TYPE.math_block:
break;
case t.TYPE.fences:
t.set("lang", a.unescape(e.attr("lang")) || e.find(".ty-input").text()), t.set("text", e.find("textarea[id]").val() || e.text());
break;
case t.TYPE.list_item:
e.hasClass("md-task-list-item") && t.set("style", r.ListType.task), t.set("checked", "checked" == e.children("input").attr("checked"));
break;
case t.TYPE.def_link:
t.set("ref", e.find(".md-def-name").text()), t.set("title", e.find(".md-def-title").text()), t.set("href", e.find(".md-def-content").text());
break;
case t.TYPE.def_footnote:
t.set("text", e.find(".md-def-content").rawText()), t.set("ref", e.find(".md-def-name").text());
break;
case t.TYPE.table:
s = [], e.find("tbody>tr:first").children().toArray().map(function(t) {
s[t.cellIndex] = t.style.textAlign, "" == t.style.textAlign && (s[t.cellIndex] = null)
}), s.length || e.find("thead>tr:first").children().toArray().map(function(t) {
s[t.cellIndex] = t.style.textAlign, "" == t.style.textAlign && (s[t.cellIndex] = null)
}), t.set("align", s);
break;
case t.TYPE.table_row:
t.set("header", e.closest("thead").length > 0);
break;
case t.TYPE.html_block:
t.set("text", e.text()), t.set("style", e.attr("data-tag"))
}
}, r.reverse = function(t, e, n, i) {
if (t.length && t[0].hasAttribute("mdtype")) {
var o, a, s = new r({ in: e
});
return r.reverseAttrFromElem(s, t, n, i), s.get("type") == s.TYPE.table ? (t.find("tr[mdtype]").toArray().map(function(t) {
(a = r.reverse($(t), e, n, i)).set("parent", s), a.set("before", o), o = a
}), r.TableEdit.valify(s)) : s.get("type") == s.TYPE.table_row ? t.children().children("span[mdtype]").toArray().map(function(t) {
(a = r.reverse($(t), e, n, i)).set("parent", s), a.set("before", o), o = a
}) : t.children("[mdtype]").toArray().map(function(t) {
(a = r.reverse($(t), e, n, i)).set("parent", s), a.set("before", o), o = a
}), s
}
}, r.prototype.downStream = function(t) {
var e = new r({
type: t,
parent: this.get("parent"),
before: this.get("before"),
after: this.get("after"),
in: this.get("in"),
attachTo: this.get("attachTo")
});
this.set("parent", e)
}, r.prototype.upStream = function(t, e) {
var n, i = this.get("parent"),
a = {};
if (a.command = e || s.makeEmptyCommand(), i)
if (!r.isType(i, o.list_item) || this.get("before") || this.get("after")) {
a.command.undo.push(s.buildReplaceUndo(i)), a.oldCid = i.id;
var u = this.get("after"),
c = this.get("before"),
l = i.get("type") == o.list_item;
if (this.set("parent", i.get("parent")), i.get("parent") || this.set("attachTo", this.get("in")), this.get("type") !== o.table && (this.get("type") == o.list_item && (this.set("type", o.paragraph), this.set("text", ""), this.clearChildren(), a.nextFocus = this.cid), i.get("type") == o.list_item)) {
this.set("type", i.get("type")), this.set("style", i.get("style"));
var f = new r({
type: o.paragraph,
in: this.get("in")
});
f.clearChildren(), f.set("parent", this), r.normalizeNode(f)
}
if (a.newHtml = this.toHTML(), u)
if (u.set("before", this.canContainBlock(!1) ? this.getFirstChild() : null), l) {
do {
u.set("parent", this), u = u.get("after")
} while (u);
a.newHtml = this.toHTML()
} else {
n = i.clone();
do {
u.set("parent", n), u = u.get("after")
} while (u);
a.newHtml += n.toHTML()
}
c ? (a.command.redo.push(s.buildReplaceUndo(i)), i.insert(this), s.addUndoForInsert(a.command, this), a.newHtml = i.toHTML() + a.newHtml) : (i.insert(this, !0), s.addUndoForInsert(a.command, this), s.addUndoForRemove(a.command, i), i.remove()), n && (this.insert(n), s.addUndoForInsert(a.command, n))
} else {
var h = s.buildReplaceUndo(i);
this.giveChildrenTo(i), this.remove(), (a = i.upStream()).command.undo.unshift(h), a.nextFocus = a.nextFocus || i.id
}
return a
}, r.prototype.attr = function(t, e, n, i) {
function s(i, r) {
var o = n.undo.UndoManager.makeEmptyCommand();
return o.undo.push({
type: "attr",
id: i.id,
key: t,
value: r || i.safeGetStrAttr(t)
}), o.redo.push({
type: "attr",
key: t,
id: i.id,
value: e
}), o
}
if (this.get(t) != e) {
i || n.store();
var c = s(this);
switch (i || "align_idx" == t || n.undo.register(c), e = "string" == typeof e ? a.escape(e) : e, t) {
case "tagBefore":
case "tagAfter":
(f = n.mathBlock.currentCm) && f.cid == this.cid || n.mathBlock.startEditing(this.cid), this.set(t, e);
var l = $("[cid='" + this.id + "'] .md-rawblock-" + ("tagBefore" == t ? "before" : "after") + " .ty-input").text(e || "").focus();
n.selection.selectAllElem(l);
break;
case "lang":
var f;
if (!(f = n.fences.getCm(this.id))) {
Reporter.error(new Error("Failed to get CodeMirror"));
break
}
var h = $("[cid='" + this.id + "']");
if (f.options.mode == e) break;
u.isDiagramType(f.options.mode) && n.diagrams.cancelDiagram(this.id), f.setOption("mode", getCodeMirrorMode(e));
var d = n.fences.getOptionsFromFencesAttr(e);
if (File.option.showLineNumbersForFence || (d.lineNumbers ? (f.setOption("lineNumbers", !0), h.addClass("md-fences-with-lineno")) : h.removeClass("md-fences-with-lineno")), d.firstLineNumber && f.setOption("firstLineNumber", d.firstLineNumber), f.refresh(), this.set("lang", e), h.attr("lang", e).find(".CodeMirror").attr("lang", (e || "").toLowerCase()), i) {
var m = $("[cid='" + this.id + "'] .code-tooltip").show().find(".ty-input").text(e || "").focus();
n.selection.selectAllElem(m)
}
u.isDiagramType(e) && n.diagrams.updateDiagram(this.id);
break;
case "checked":
var v = document.querySelector("[cid='" + this.id + "']>input");
e ? (v.setAttribute("checked", "checked"), v.parentElement.classList.remove("task-list-not-done"), v.parentElement.classList.add("task-list-done")) : (v.removeAttribute("checked"), v.parentElement.classList.remove("task-list-done"), v.parentElement.classList.add("task-list-not-done")), v.checked = e || !1, this.set("checked", e || !1);
break;
case "href-title":
if (this.get("type") == o.image) {
var p = e.split(/\s/);
if (n.findElemById(this.id).find("img").attr("src", p[0]), this.set("href", p[0]), this.set("title", p[1]), i) {
(l = $("[cid='" + this.id + "']")).hasClass("onfocus") || (l.addClass("onfocus").focus(), n.EditHelper.showTooltipForImage(n, l), $("[cid='" + this.id + "'] input.t-bracket-input").val(e || "").focus())
}
}
break;
case "alt":
if (this.get("type") == o.image && (n.findElemById(this.id).find("img").attr("alt", e), this.set("alt", e), i)) {
(l = $("[cid='" + this.id + "']")).hasClass("onfocus") || (l.addClass("onfocus").focus(), n.EditHelper.showTooltipForImage(n, l), $("[cid='" + this.id + "'] input.t-alt-input").val(e || "").focus())
}
break;
case "align_idx":
if (this.get("type") == o.table) {
var g = e[0],
b = e[1],
y = e[2];
l = n.findElemById(this.id), c = s(this, [g, this.get("align")[g]]);
if (i || ((y = r.adjustAlignText(this, g, b)) && (c.undo.last().value.push(this.get("alignText")[g]), c.redo.last().value.push(y)), n.undo.register(c)), this.get("alignText") && (this.get("alignText")[g] = y), this.get("align")[g] = b, b = b || "", l.find("tbody>tr>td:nth-child(" + (g + 1) + ")").css("text-align", b), l.find("thead>tr>th:nth-child(" + (g + 1) + ")").css("text-align", b), i) n.tableEdit.showTableEdit(l);
else {
var w = l.find(".md-align-gp[data-col='" + g + "']");
w.find("button").removeClass("active").blur(), w.find(".md-align-" + b).addClass("active").focus()
}
}
}
return c
}
}, r.adjustAlignText = function(t, e, n) {
if (t.get("alignText")) {
var i = t.get("alignText")[e];
if (i) return i = "left" == n || "center" == n ? (i = i.replace(/(^\s*)-/, "$1:")).replace(/(^\s*):(\s*$)/, "$1:-$2") : i.replace(/(^\s*):/, "$1-"), i = "right" == n || "center" == n ? (i = i.replace(/-(\s*$)/, ":$1")).replace(/(^\s*):(\s*$)/, "$1-:$2") : i.replace(/:(\s*$)/, "-$1"), /^\s*::\s*$/.exec(i) && (i = i.replace("::", ":-:")), i
}
}, r.tryResetTable = function(t) {
t && !t.isDeleted() && t.get("type") == o.table && t.get("userText") && t.set("userText", void 0)
}, r.prototype.unwrap = function(t) {
var e = [],
n = this.getFirstChild();
do {
var r = n.get("after");
n.set("parent", this.get("parent")), n.set("attachTo", this.get("attachTo")), n.get("before") || n.set("before", this.get("before")), n.get("after") || n.set("after", this.get("after")), e.push(n), n.get("pattern") && n.set("pattern", n.get("pattern").replace(/^\s+/, "")), n = r
} while (n);
return this.remove(!0), t && t.findElemById(this.cid).replaceWith(i.NodeCollectionUtils.toHTML(e)), e
}, r.prototype.wrap = function(t, e, n, i) {
for (var r, o = t, a = [], s = {
parent: t.get("parent"),
before: t.get("before"),
after: e ? e.get("after") : t.get("after")
}; o && o != s.after;) n && n.findElemById(o.id).remove(), r = o, o = o.get("after"), this.append(r);
s.after && (s.after.insert(this, !0), i || (a = n.findElemById(s.after.id)).before(this.toHTML())), !a.length && s.before && (s.before.insert(this, !1), i || (a = n.findElemById(s.before.id)).after(this.toHTML())), a.length || (s.parent ? (this.set("parent", s.parent), !i && n && n.findElemById(s.parent.id).html(this.toHTML())) : i || 0 !== $(n.sessionStr).children().length || (this.set("attachTo", this.get("in")), n && ($(n.sessionStr).html(this.toHTML()), n.focusCid = null)))
}
}), $__System.registerDynamic("1e", ["1f"], !0, function(t, e, n) {
"use strict";
this || self;
! function(t) {
t.defineOption("styleSelectedText", !1, function(i, r, o) {
var a = o && o != t.Init;
r && !a ? (i.state.markedSelection = [], i.state.markedSelectionStyle = "string" == typeof r ? r : "CodeMirror-selectedtext", u(i), i.on("cursorActivity", e), i.on("change", n)) : !r && a && (i.off("cursorActivity", e), i.off("change", n), s(i), i.state.markedSelection = i.state.markedSelectionStyle = null)
});
function e(t) {
t.state.markedSelection && t.operation(function() {
! function(t) {
if (!t.somethingSelected()) return s(t);
if (t.listSelections().length > 1) return u(t);
var e = t.getCursor("start"),
n = t.getCursor("end"),
r = t.state.markedSelection;
if (!r.length) return a(t, e, n);
var c = r[0].find(),
l = r[r.length - 1].find();
if (!c || !l || n.line - e.line < i || o(e, l.to) >= 0 || o(n, c.from) <= 0) return u(t);
for (; o(e, c.from) > 0;) r.shift().clear(), c = r[0].find();
o(e, c.from) < 0 && (c.to.line - e.line < i ? (r.shift().clear(), a(t, e, c.to, 0)) : a(t, e, c.from, 0));
for (; o(n, l.to) < 0;) r.pop().clear(), l = r[r.length - 1].find();
o(n, l.to) > 0 && (n.line - l.from.line < i ? (r.pop().clear(), a(t, l.from, n)) : a(t, l.to, n))
}(t)
})
}
function n(t) {
t.state.markedSelection && t.state.markedSelection.length && t.operation(function() {
s(t)
})
}
var i = 8,
r = t.Pos,
o = t.cmpPos;
function a(t, e, n, a) {
if (0 != o(e, n))
for (var s = t.state.markedSelection, u = t.state.markedSelectionStyle, c = e.line;;) {
var l = c == e.line ? e : r(c, 0),
f = c + i,
h = f >= n.line,
d = h ? n : r(f, 0),
m = t.markText(l, d, {
className: u
});
if (null == a ? s.push(m) : s.splice(a++, 0, m), h) break;
c = f
}
}
function s(t) {
for (var e = t.state.markedSelection, n = 0; n < e.length; ++n) e[n].clear();
e.length = 0
}
function u(t) {
s(t);
for (var e = t.listSelections(), n = 0; n < e.length; n++) a(t, e[n].from(), e[n].to())
}
}(t("1f"))
}), $__System.registerDynamic("20", ["1f"], !0, function(t, e, n) {
this || self;
! function(t) {
var e = {
pairs: "()[]{}''\"\"",
triples: "",
explode: "[]{}"
},
n = t.Pos;
t.defineOption("autoCloseBrackets", !1, function(e, n, i) {
i && i != t.Init && (e.removeKeyMap(o), e.state.closeBrackets = null), n && (e.state.closeBrackets = n, e.addKeyMap(o))
});
function i(t, n) {
return "pairs" == n && "string" == typeof t ? t : "object" == typeof t && null != t[n] ? t[n] : e[n]
}
for (var r = e.pairs + "`", o = {
Backspace: function(e) {
var r = u(e);
if (!r || e.getOption("disableInput")) return t.Pass;
for (var o = i(r, "pairs"), a = e.listSelections(), s = 0; s < a.length; s++) {
if (!a[s].empty()) return t.Pass;
var c = f(e, a[s].head);
if (!c || o.indexOf(c) % 2 != 0) return t.Pass
}
for (var s = a.length - 1; s >= 0; s--) {
var l = a[s].head;
e.replaceRange("", n(l.line, l.ch - 1), n(l.line, l.ch + 1), "+delete")
}
},
Enter: function(e) {
var n = u(e),
r = n && i(n, "explode");
if (!r || e.getOption("disableInput")) return t.Pass;
for (var o = e.listSelections(), a = 0; a < o.length; a++) {
if (!o[a].empty()) return t.Pass;
var s = f(e, o[a].head);
if (!s || r.indexOf(s) % 2 != 0) return t.Pass
}
if (e.getModeAt(e.getCursor()).indent || e.getMode().indent) return e.operation(function() {
e.replaceSelection("\n", null), e.execCommand("goCharLeft");
for (var t = 0; t < o.length; t++) {
var n = o[t].head.line;
e.indentLine(n, null, !0), e.indentLine(n + 1, null, !0)
}
}), t.Pass;
e.operation(function() {
e.replaceSelection("\n\n", null), e.execCommand("goCharLeft"), o = e.listSelections();
for (var t = 0; t < o.length; t++) {
var n = o[t].head.line;
e.indentLine(n, null, !0), e.indentLine(n + 1, null, !0), e.indentLine(n, "add", !0)
}
})
}
}, a = 0; a < r.length; a++) o["'" + r.charAt(a) + "'"] = s(r.charAt(a));
function s(e) {
return function(r) {
return function(e, r) {
var o = u(e);
if (!o || e.getOption("disableInput")) return t.Pass;
var a = i(o, "pairs"),
s = a.indexOf(r);
if (-1 == s) return t.Pass;
for (var f, m = i(o, "triples"), v = a.charAt(s + 1) == r, p = e.listSelections(), g = s % 2 == 0, b = 0; b < p.length; b++) {
var y, w = p[b],
F = w.head,
k = e.getRange(F, n(F.line, F.ch + 1));
if (g && !w.empty()) y = "surround";
else if (!v && g || k != r)
if (v && F.ch > 1 && m.indexOf(r) >= 0 && e.getRange(n(F.line, F.ch - 2), F) == r + r && (F.ch <= 2 || e.getRange(n(F.line, F.ch - 3), n(F.line, F.ch - 2)) != r)) y = "addFour";
else if (v) {
if (t.isWordChar(k) || !h(e, F, r)) return t.Pass;
y = "both"
} else {
if (!g || e.getLine(F.line).length != F.ch && !l(k, a) && !/\s/.test(k)) return t.Pass;
y = "both"
} else y = v && d(e, F) ? "both" : m.indexOf(r) >= 0 && e.getRange(F, n(F.line, F.ch + 3)) == r + r + r ? "skipThree" : "skip";
if (f) {
if (f != y) return t.Pass
} else f = y
}
var x = s % 2 ? a.charAt(s - 1) : r,
_ = s % 2 ? r : a.charAt(s + 1);
e.operation(function() {
if ("skip" == f) e.execCommand("goCharRight");
else if ("skipThree" == f)
for (var t = 0; t < 3; t++) e.execCommand("goCharRight");
else if ("surround" == f) {
for (var n = e.getSelections(), t = 0; t < n.length; t++) n[t] = x + n[t] + _;
e.replaceSelections(n, "around"), n = e.listSelections().slice();
for (var t = 0; t < n.length; t++) n[t] = c(n[t]);
e.setSelections(n)
} else "both" == f ? (e.replaceSelection(x + _, null), e.triggerElectric(x + _), e.execCommand("goCharLeft")) : "addFour" == f && (e.replaceSelection(x + x + x + x, "before"), e.execCommand("goCharRight"))
})
}(r, e)
}
}
function u(t) {
var e = t.state.closeBrackets;
if (!e || e.override) return e;
return t.getModeAt(t.getCursor()).closeBrackets || e
}
function c(e) {
var i = t.cmpPos(e.anchor, e.head) > 0;
return {
anchor: new n(e.anchor.line, e.anchor.ch + (i ? -1 : 1)),
head: new n(e.head.line, e.head.ch + (i ? 1 : -1))
}
}
function l(t, e) {
var n = e.lastIndexOf(t);
return n > -1 && n % 2 == 1
}
function f(t, e) {
var i = t.getRange(n(e.line, e.ch - 1), n(e.line, e.ch + 1));
return 2 == i.length ? i : null
}
function h(e, n, i) {
var r = e.getLine(n.line),
o = e.getTokenAt(n);
if (/\bstring2?\b/.test(o.type) || d(e, n)) return !1;
var a = new t.StringStream(r.slice(0, n.ch) + i + r.slice(n.ch), 4);
for (a.pos = a.start = o.start;;) {
var s = e.getMode().token(a, o.state);
if (a.pos >= n.ch + 1) return /\bstring2?\b/.test(s);
a.start = a.pos
}
}
function d(t, e) {
var i = t.getTokenAt(n(e.line, e.ch + 1));
return /\bstring/.test(i.type) && i.start == e.ch
}
}(t("1f"))
}), $__System.registerDynamic("21", ["1f"], !0, function(t, e, n) {
this || self;
var i = t("1f");
! function() {
i.defineOption("autoCloseTags", !1, function(a, s, u) {
if (u != i.Init && u && a.removeKeyMap("autoCloseTags"), s) {
var c = {
name: "autoCloseTags"
};
("object" != typeof s || s.whenClosing) && (c["'/'"] = function(t) {
return (e = t).getOption("disableInput") ? i.Pass : n(e, !0);
var e
}), ("object" != typeof s || s.whenOpening) && (c["'>'"] = function(n) {
return function(n) {
if (n.getOption("disableInput")) return i.Pass;
for (var a = n.listSelections(), s = [], u = 0; u < a.length; u++) {
if (!a[u].empty()) return i.Pass;
var c = a[u].head,
l = n.getTokenAt(c),
f = i.innerMode(n.getMode(), l.state),
h = f.state;
if ("xml" != f.mode.name || !h.tagName) return i.Pass;
var d = n.getOption("autoCloseTags"),
m = "html" == f.mode.configuration,
v = "object" == typeof d && d.dontCloseTags || m && t,
p = "object" == typeof d && d.indentTags || m && e,
g = h.tagName;
l.end > c.ch && (g = g.slice(0, g.length - l.end + c.ch));
var b = g.toLowerCase();
if (!g || "string" == l.type && (l.end != c.ch || !/[\"\']/.test(l.string.charAt(l.string.length - 1)) || 1 == l.string.length) || "tag" == l.type && "closeTag" == h.type || l.string.indexOf("/") == l.string.length - 1 || v && r(v, b) > -1 || o(n, g, c, h, !0)) return i.Pass;
var y = p && r(p, b) > -1;
s[u] = {
indent: y,
text: ">" + (y ? "\n\n" : "") + "</" + g + ">",
newPos: y ? i.Pos(c.line + 1, 0) : i.Pos(c.line, c.ch + 1)
}
}
for (var u = a.length - 1; u >= 0; u--) {
var w = s[u];
n.replaceRange(w.text, a[u].head, a[u].anchor, "+insert");
var F = n.listSelections().slice(0);
F[u] = {
head: w.newPos,
anchor: w.newPos
}, n.setSelections(F), w.indent && (n.indentLine(w.newPos.line, null, !0), n.indentLine(w.newPos.line + 1, null, !0))
}
}(n)
}), a.addKeyMap(c)
}
});
var t = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"],
e = ["applet", "blockquote", "body", "button", "div", "dl", "fieldset", "form", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "html", "iframe", "layer", "legend", "object", "ol", "p", "select", "table", "ul"];
function n(t, e) {
for (var n = t.listSelections(), r = [], a = e ? "/" : "</", s = 0; s < n.length; s++) {
if (!n[s].empty()) return i.Pass;
var u = n[s].head,
c = t.getTokenAt(u),
l = i.innerMode(t.getMode(), c.state),
f = l.state;
if (e && ("string" == c.type || "<" != c.string.charAt(0) || c.start != u.ch - 1)) return i.Pass;
var h;
if ("xml" != l.mode.name)
if ("htmlmixed" == t.getMode().name && "javascript" == l.mode.name) h = a + "script";
else {
if ("htmlmixed" != t.getMode().name || "css" != l.mode.name) return i.Pass;
h = a + "style"
}
else {
if (!f.context || !f.context.tagName || o(t, f.context.tagName, u, f)) return i.Pass;
h = a + f.context.tagName
}
">" != t.getLine(u.line).charAt(c.end) && (h += ">"), r[s] = h
}
t.replaceSelections(r), n = t.listSelections();
for (s = 0; s < n.length; s++)(s == n.length - 1 || n[s].head.line < n[s + 1].head.line) && t.indentLine(n[s].head.line)
}
i.commands.closeTag = function(t) {
return n(t)
};
function r(t, e) {
if (t.indexOf) return t.indexOf(e);
for (var n = 0, i = t.length; n < i; ++n)
if (t[n] == e) return n;
return -1
}
function o(t, e, n, r, o) {
if (!i.scanForClosingTag) return !1;
var a = Math.min(t.lastLine() + 1, n.line + 500),
s = i.scanForClosingTag(t, n, null, a);
if (!s || s.tag != e) return !1;
for (var u = r.context, c = o ? 1 : 0; u && u.tagName == e; u = u.prev) ++c;
n = s.to;
for (var l = 1; l < c; l++) {
var f = i.scanForClosingTag(t, n, null, a);
if (!f || f.tag != e) return !1;
n = f.to
}
return !0
}
}()
}), $__System.registerDynamic("22", ["1f"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("1f");
i.overlayMode = function(t, e, n) {
return {
startState: function() {
return {
base: i.startState(t),
overlay: i.startState(e),
basePos: 0,
baseCur: null,
overlayPos: 0,
overlayCur: null,
streamSeen: null
}
},
copyState: function(n) {
return {
base: i.copyState(t, n.base),
overlay: i.copyState(e, n.overlay),
basePos: n.basePos,
baseCur: null,
overlayPos: n.overlayPos,
overlayCur: null
}
},
token: function(i, r) {
return (i != r.streamSeen || Math.min(r.basePos, r.overlayPos) < i.start) && (r.streamSeen = i, r.basePos = r.overlayPos = i.start), i.start == r.basePos && (r.base.lineBefore = r.lineBefore, r.base.lineAfter = r.lineAfter, r.baseCur = t.token(i, r.base), r.basePos = i.pos), i.start == r.overlayPos && (i.pos = i.start, r.overlayCur = e.token(i, r.overlay), r.overlayPos = i.pos), i.pos = Math.min(r.basePos, r.overlayPos), null == r.overlayCur ? r.baseCur : null != r.baseCur && r.overlay.combineTokens || n && null == r.overlay.combineTokens ? r.baseCur + " " + r.overlayCur : r.overlayCur
},
indent: t.indent && function(e, n) {
return t.indent(e.base, n)
},
electricChars: t.electricChars,
innerMode: function(e) {
return {
state: e.base,
mode: t
}
},
blankLine: function(i) {
var r, o;
return t.blankLine && (r = t.blankLine(i.base)), e.blankLine && (o = e.blankLine(i.overlay)), null == o ? r : n && null != r ? r + " " + o : o
}
}
}
}), $__System.registerDynamic("23", ["1f"], !0, function(t, e, n) {
this || self;
var i = t("1f"),
r = "CodeMirror-lint-markers";
function o(t) {
t.parentNode && t.parentNode.removeChild(t)
}
function a(t, e, n) {
var r = function(t, e) {
var n = document.createElement("div");
n.className = "CodeMirror-lint-tooltip", n.appendChild(e.cloneNode(!0)), document.body.appendChild(n);
function r(t) {
if (!n.parentNode) return i.off(document, "mousemove", r);
n.style.top = Math.max(0, t.clientY - n.offsetHeight - 5) + "px", n.style.left = t.clientX + 5 + "px"
}
return i.on(document, "mousemove", r), r(t), null != n.style.opacity && (n.style.opacity = 1), n
}(t, e);
function a() {
i.off(n, "mouseout", a), r && ((t = r).parentNode && (null == t.style.opacity && o(t), t.style.opacity = 0, setTimeout(function() {
o(t)
}, 600)), r = null);
var t
}
var s = setInterval(function() {
if (r)
for (var t = n;; t = t.parentNode) {
if (t && 11 == t.nodeType && (t = t.host), t == document.body) return;
if (!t) {
a();
break
}
}
if (!r) return clearInterval(s)
}, 400);
i.on(n, "mouseout", a)
}
function s(t, e, n) {
this.marked = [], this.options = e, this.timeout = null, this.hasGutter = n, this.onMouseOver = function(e) {
! function(t, e) {
var n = e.target || e.srcElement;
if (!/\bCodeMirror-lint-mark-/.test(n.className)) return;
for (var i = n.getBoundingClientRect(), r = (i.left + i.right) / 2, o = (i.top + i.bottom) / 2, s = t.findMarksAt(t.coordsChar({
left: r,
top: o
}, "client")), u = [], c = 0; c < s.length; ++c) {
var f = s[c].__annotation;
f && u.push(f)
}
u.length && function(t, e) {
for (var n = e.target || e.srcElement, i = document.createDocumentFragment(), r = 0; r < t.length; r++) {
var o = t[r];
i.appendChild(l(o))
}
a(e, i, n)
}(u, e)
}(t, e)
}, this.waitingFor = 0
}
function u(t) {
var e = t.state.lint;
e.hasGutter && t.clearGutter(r);
for (var n = 0; n < e.marked.length; ++n) e.marked[n].clear();
e.marked.length = 0
}
function c(t, e, n, r) {
var o = document.createElement("div"),
s = o;
return o.className = "CodeMirror-lint-marker-" + e, n && ((s = o.appendChild(document.createElement("div"))).className = "CodeMirror-lint-marker-multiple"), 0 != r && i.on(s, "mouseover", function(e) {
a(e, t, s)
}), o
}
function l(t) {
var e = t.severity;
e || (e = "error");
var n = document.createElement("div");
return n.className = "CodeMirror-lint-message-" + e, n.appendChild(document.createTextNode(t.message)), n
}
function f(t) {
var e = t.state.lint.options,
n = e.options || e,
r = e.getAnnotations || t.getHelper(i.Pos(0, 0), "lint");
if (r)
if (e.async || r.async) ! function(t, e, n) {
var r = t.state.lint,
o = ++r.waitingFor;
function a() {
o = -1, t.off("change", a)
}
t.on("change", a), e(t.getValue(), function(e, n) {
t.off("change", a), r.waitingFor == o && (n && e instanceof i && (e = n), h(t, e))
}, n, t)
}(t, r, n);
else {
var o = r(t.getValue(), n, t);
if (!o) return;
o.then ? o.then(function(e) {
h(t, e)
}) : h(t, o)
}
}
function h(t, e) {
u(t);
for (var n = t.state.lint, i = n.options, o = function(t) {
for (var e = [], n = 0; n < t.length; ++n) {
var i = t[n],
r = i.from.line;
(e[r] || (e[r] = [])).push(i)
}
return e
}(e), a = 0; a < o.length; ++a) {
var s = o[a];
if (s) {
for (var f = null, h = n.hasGutter && document.createDocumentFragment(), d = 0; d < s.length; ++d) {
var m = s[d],
v = m.severity;
v || (v = "error"), f = "error" == (p = f) ? p : v, i.formatAnnotation && (m = i.formatAnnotation(m)), n.hasGutter && h.appendChild(l(m)), m.to && n.marked.push(t.markText(m.from, m.to, {
className: "CodeMirror-lint-mark-" + v,
__annotation: m
}))
}
n.hasGutter && t.setGutterMarker(a, r, c(h, f, s.length > 1, n.options.tooltips))
}
}
var p;
i.onUpdateLinting && i.onUpdateLinting(e, o, t)
}
function d(t) {
var e = t.state.lint;
e && (clearTimeout(e.timeout), e.timeout = setTimeout(function() {
f(t)
}, e.options.delay || 500))
}
i.defineOption("lint", !1, function(t, e, n) {
if (n && n != i.Init && (u(t), !1 !== t.state.lint.options.lintOnChange && t.off("change", d), i.off(t.getWrapperElement(), "mouseover", t.state.lint.onMouseOver), clearTimeout(t.state.lint.timeout), delete t.state.lint), e) {
for (var o = t.getOption("gutters"), a = !1, c = 0; c < o.length; ++c) o[c] == r && (a = !0);
var l = t.state.lint = new s(t, (h = e, h instanceof Function ? {
getAnnotations: h
} : (h && !0 !== h || (h = {}), h)), a);
!1 !== l.options.lintOnChange && t.on("change", d), 0 != l.options.tooltips && "gutter" != l.options.tooltips && i.on(t.getWrapperElement(), "mouseover", l.onMouseOver), f(t)
}
var h
}), i.defineExtension("performLint", function() {
this.state.lint && f(this)
}), i.clearMarks = u, i.updateLinting = h
}), $__System.registerDynamic("24", ["1f", "14", "e", "12", "25", "13", "26", "1b", "16", "1e", "20", "21", "22", "23"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("1f"),
r = t("14"),
o = t("e"),
a = t("12"),
s = t("25"),
u = t("13"),
c = t("26"),
l = (t("1b"), t("16")),
f = c.map;
Node = u.Node;
var h = i.prototype.focus;
i.prototype.focus = function() {
i.signal(this, "focus", this), h.apply(this)
};
t("1e"), t("20"), t("21"), t("22"), t("23");
var d = ["js", "javascript", "java", "json", "typescript", "clojure", "coffeescript", "css", "less", "scss", "gfm", "markdown", "xaml", "xml", "haskell", "html", "lua", "lisp", "commonlisp", "pascal", "perl", "php", "php+HTML", "python", "cython", "ruby", "shell", "sh", "sql", "sqlite", "mssql", "mysql", "CQL", "mariadb", "cassandra", "plsql", "tiddlywiki", "wiki", "vb", "basic", "visual basic", "vbscript", "velocity", "verilog", "xquery", "yaml", "go", "groovy", "nginx", "octave", "c", "clike", "c++", "cpp", "objc", "objective-c", "csharp", "c#", "squirrel", "ceylon", "kotlin", "tex", "latex", "swift", "scala", "R", "D", "diff", "erlang", "http", "jade", "rst", "rust", "jinja2", "reStructuredText", "asp", "jsp", "erb", "ejs", "embeddedjs", "powershell", "dockerfile", "jsx", "tsx", "react", "vue", "nsis", "mathematica", "tiki wiki", "properties", "ini", "livescript", "assembly", "gas", "toml", "matlab", "ocaml", "F#", "fsharp", "elm", "pgp", "asciiarmor", "spreadsheet", "elixir", "cmake", "cypher", "dart", "django", "dtd", "xml-dtd", "dylan", "handlebars", "idl", "web-idl", "yacas", "mbox", "vhdl", "julia", "haxe", "hxml", "fortran", "protobuf", "makefile", "tcl", "scheme", "twig", "bash", "SAS", "pseudocode", "stylus", "cobol", "oz", "SPARQL", "crystal"];
! function(t) {
var e = t.commands.delLineLeft;
t.commands.delLineLeft = function(n) {
try {
return 0 == n.getCursor().ch ? t.commands.delCharBefore(n) : e(n)
} catch (t) {}
}
}(i);
var m = function(t, e) {
var n = [];
return d.map(function(e) {
0 == e.toLowerCase().indexOf(t.toLowerCase()) && n.push(e)
}), n.sort(), n.length < 4 && d.map(function(e) {
e.toLowerCase().indexOf(t.toLowerCase()) > 0 && n.push(e)
}), e && 1 == n.length && n[0] == t ? [] : n
};
function v(t, e) {
if (t) switch (t) {
case "javascript":
case "text/javascript":
case "js":
return t = "javascript";
case "json":
return e ? t : t = {
name: "javascript",
json: !0
};
case "jsonld":
case "json-ld":
return e ? t : "application/ld+json";
case "text/typescript":
case "typescript":
case "ts":
return e ? "typescript" : t = {
name: "javascript",
typescript: !0
};
case "clojure":
return t;
case "coffee":
case "coffeescript":
case "css":
return t;
case "less":
return e ? "less" : "text/x-less";
case "scss":
return e ? "scss" : t = "text/x-scss";
case "gfm":
case "github flavored markdown":
return t = "gfm";
case "markdown":
case "md":
case "mkd":
return t;
case "xml":
case "xaml":
case "mjml":
case "xul":
case "enml":
return e ? t : "xml";
case "haskell":
return t;
case "htmlmixed":
case "html":
case "xhtml":
case "svg":
case "epub":
return e ? /^html/.exec(t) ? "html" : t : t = "htmlmixed";
case "lua":
return t;
case "lisp":
case "commonlisp":
case "common lisp":
return t = "commonlisp";
case "pascal":
case "perl":
return t;
case "php+html":
return e ? "php" : "application/x-httpd-php";
case "php":
case "php3":
case "php4":
case "php5":
case "php6":
return e ? t : "text/x-php";
case "cython":
return e ? t : t = "text/x-cython";
case "python":
return e ? t : t = "text/x-python";
case "ruby":
return t;
case "shell":
case "sh":
case "zsh":
case "bash":
return t = "shell";
case "sql":
case "sql lite":
case "sqlite":
return e ? t : t = "text/x-sql";
case "mssql":
return e ? t : t = "text/x-mssql";
case "mysql":
return e ? t : t = "text/x-mysql";
case "mariadb":
return e ? t : t = "text/x-mariadb";
case "cassandra":
case "cql":
return e ? t : t = "text/x-cassandra";
case "plsql":
return e ? t : t = "text/x-plsql";
case "stex":
case "tex":
case "latex":
return e ? t : "text/x-stex";
case "tiddlywiki":
case "wiki":
return e ? t : t = "tiddlywiki";
case "vb":
case "visual basic":
case "visualbasic":
case "basic":
return e ? t : t = "vb";
case "vbscript":
case "velocity":
return t;
case "verilog":
return e ? t : t = "text/x-verilog";
case "xquery":
return t;
case "yaml":
case "yml":
return e ? t : "yaml";
case "go":
case "groovy":
case "nginx":
return t;
case "octave":
case "matlab":
return e ? t : "text/x-octave";
case "c":
case "clike":
case "csrc":
return e ? t : t = "text/x-csrc";
case "c++":
case "c++src":
case "cpp":
case "cc":
case "hpp":
case "h++":
case "h":
return e ? t : t = "text/x-c++src";
case "obj-c":
case "objc":
case "objective c":
case "objective-c":
case "objectivec":
return e ? t : t = "text/x-objectivec";
case "text/x-scala":
case "scala":
return e ? t : t = "text/x-scala";
case "csharp":
case "c#":
case "cs":
return e ? t : t = "text/x-csharp";
case "java":
return e ? t : t = "text/x-java";
case "squirrel":
return e ? t : t = "text/x-squirrel";
case "ceylon":
return e ? t : t = "text/x-ceylon";
case "kotlin":
return e ? t : t = "text/x-kotlin";
case "swift":
return t = "swift";
case "r":
case "rlang":
case "r-lang":
return e ? t : t = "text/x-rsrc";
case "d":
case "diff":
case "erlang":
case "http":
case "jade":
return t;
case "rst":
case "restructuredtext":
return t = "rst";
case "rust":
case "jinja2":
return t;
case "aspx":
case "asp":
case "asp.net":
return e ? t : t = "application/x-aspx";
case "jsp":
return e ? t : t = "application/x-jsp";
case "erb":
return e ? t : t = "application/x-erb";
case "ejs":
case "embeddedjs":
case "embedded javaScript":
return e ? t : t = "application/x-ejs";
case "powershell":
case "bat":
case "cmd":
return e ? t : "application/x-powershell";
case "dockerfile":
return e ? t : "text/x-dockerfile";
case "jsx":
case "react":
return e ? t : "text/jsx";
case "tsx":
return e ? t : "text/typescript-jsx";
case "vue.js":
case "vue":
case "vue-template":
return e ? t : "script/x-vue";
case "nsis":
return e ? t : "text/x-nsis";
case "mathematica":
return e ? t : "text/x-mathematica";
case "tiki":
case "tiki wiki":
case "tiki-wiki":
case "tikiwiki":
return "tiki";
case "properties":
case "ini":
return e ? t : "text/x-properties";
case "livescript":
return e ? t : "text/x-livescript";
case "asm":
case "assembly":
case "nasm":
case "gas":
return e ? t : "assembly";
case "toml":
return e ? t : "text/x-toml";
case "sequence":
return "sequence";
case "flow":
case "flowchart":
return "flow";
case "mermaid":
return "mermaid";
case "ocaml":
return e ? t : "text/x-ocaml";
case "f#":
case "fsharp":
return e ? t : "text/x-fsharp";
case "elm":
return e ? t : "text/x-elm";
case "pgp":
case "pgp-keys":
case "pgp-key":
case "pgp-signature":
case "asciiarmor":
case "ascii-armor":
case "ascii armor":
return e ? t : "application/pgp";
case "spreadsheet":
case "excel":
return e ? t : "text/x-spreadsheet";
case "elixir":
return "elixir";
case "cmake":
return e ? t : "text/x-cmake";
case "cypher":
case "cypher-query":
return e ? t : "application/x-cypher-query";
case "dart":
return "dart";
case "django":
return e ? t : "text/x-django";
case "dtd":
case "xml-dtd":
case "xml dtd":
case "xmldtd":
return e ? t : "application/xml-dtd";
case "dylan":
return e ? t : "text/x-dylan";
case "handlebars":
return e ? t : "text/x-handlebars-template";
case "idl":
return e ? t : "text/x-idl";
case "webidl":
case "web-idl":
case "web idl":
return e ? t : "text/x-webidl";
case "yacas":
return e ? t : "text/x-yacas";
case "mbox":
return e ? t : "application/mbox";
case "vhdl":
return e ? t : "text/x-vhdl";
case "julia":
return "julia";
case "haxe":
return e ? t : "text/x-haxe";
case "hxml":
return e ? t : "text/x-hxml";
case "fortran":
return e ? t : "text/x-fortran";
case "protobuf":
return e ? t : "text/x-protobuf";
case "makefile":
return e ? t : "text/x-makefile";
case "tcl":
return e ? t : "text/x-tcl";
case "scheme":
return e ? t : "text/x-scheme";
case "twig":
return e ? t : "text/x-twig";
case "sas":
return e ? t : "text/x-sas";
case "pseudocode":
return e ? t : "text/x-pseudocode";
case "julia":
case "text/x-julia":
case "stylus":
case "cobol":
case "oz":
case "sparql":
case "crystal":
return t;
default:
return ""
}
}
var p = function(t) {
if (!t) return {};
if ("{" != t[0] || "}" != t[t.length - 1]) return {};
var e = t.replace(/(^{)|(}$)/g, "").split(/\s+/);
if (!e || !e.length) return {};
var n = {};
return e.forEach(function(t) {
var e;
(e = /^[.]number((-?l)|L)ines/.exec(t)) ? n.lineNumbers = !0: (e = /^startFrom=['"](\d+)['"]$/.exec(t)) && (n.firstLineNumber = e[1] - 0)
}), n
};
window.getCodeMirrorMode = function(t, e, n) {
var i = ((t = (t = t ? t.toLowerCase() : "").replace(/^\s*\.*lang(uage)*-/g, "").replace(/[{}]/g, "").trim()).split(/\s+/) || [t])[0],
r = v(t, n);
return r || t == i || (r = v(i.replace(/(^[.])|(,$)/g, ""), n)), r || (n ? i : e ? null : t)
};
var g = a.Model.extend({
initialize: function(t) {
var e = this;
this.editor = t, this.queue = {}, this.cachedCharWidth, this.$container = o("#fences-auto-suggest"), this.editor.diagrams = new l(t), File.option.enableDiagram && (d = d.concat(l.MODES)), o(document).on("losefocus", ".md-fences", function() {
var t = o(this),
n = e.queue[t.attr("cid")];
n && (e.syncToNode(this.getAttribute("cid")), n.doc.setCursor(0, 0, {
scroll: !1
}), t.find(".md-tooltip-hide").hide(), t[0].style.marginBottom = "")
}).on("endfocus", ".md-fences", function() {
var t = o(this);
e.queue[t.attr("cid")] && (t.find(".md-tooltip-hide").hide(), t[0].style.marginBottom = "")
}).on("mousedown", ".autoComplt-list li", function(e) {
var n = o(".ty-input:focus");
return n.text(this.textContent), t.selection.jumpIntoElemEnd(n), !1
}), this.lazyload(), this.editor.diagrams.lazyload()
},
onLeaveDocument: function() {
this.queue = {}, this.intersectionObserve(null, !0)
},
getOptionsFromFencesAttr: p,
showAutoSuggest: function(t, e) {
if (e.token === t) return !1;
var n = m(t, !0),
i = "";
if (e.type = "fences", e.token = t, e.match = n, e.found = n.length, e.pageNo = 0, e.pageCnt = Math.floor((n.length - 1) / 5 + 1), !e.found) return this.$container.removeClass("ty-show"), !1;
for (var r = 0; r < n.length && r < 40; r++) r % 5 == 0 && (i += (r > 0 ? "</ul>" : "") + "<ul data-page='" + r / 5 + "' style='display:none'>"), i += "<li data-content='" + n[r] + "' > " + n[r] + "</span></li>";
return i += "</ul>", this.$container.html(i), this.$container
},
clickEventHandled: function(t, e) {
var n, i, r;
this.queue[e] || (r = window.scrollY, this.getCm(e), r -= window.scrollY, window.scrollBy(0, r), (n = document.elementFromPoint(t.clientX, t.clientY)) && (t.stopPropagation(), (i = document.createEvent("MouseEvents")).initMouseEvent("mousedown", !0, !0, n.ownerDocument.defaultView, 1, t.screenX, t.screenY, t.clientX, t.clientY, t.ctrlKey, t.altKey, t.shiftKey, t.metaKey, t.button), n.dispatchEvent(i)), this.editor.refocus(e))
},
getCm: function(t) {
if (this.queue[t]) {
if (o("[cid='" + t + "'] textarea").length) return this.queue[t];
delete this.queue[t]
}
if (!this.queue[t]) return this.addCodeBlock(t)
},
getValue: function(t) {
return this.queue[t] ? this.queue[t].getValue() : this.editor.findElemById(t).text()
},
addCodeBlock: function(t) {
var e = this.editor,
n = this;
function r(t, r) {
var o, a = r.which || r.keyCode,
s = i.keyName(r),
u = !r.metaKey && !r.shiftKey && !r.ctrlKey;
if ("Up" == i.keyNames[a]) {
if ((o = t.getCursor()) && 0 == o.line) {
if (u) return e.selection.moveUpOrDown(!0, r), r.codemirrorIgnore;
if (0 == o.ch && !r.shiftKey && (File.isNode && r.ctrlKey || File.isMac && r.metaKey)) return void(r.codemirrorIgnore = !0)
}
r.stopPropagation()
} else if ("Down" == i.keyNames[a]) {
if ((o = t.getCursor()) && o.line >= t.lineCount() - 1) {
if (u) return e.selection.moveUpOrDown(!1, r), r.codemirrorIgnore;
if (o.ch == t.doc.getLine(o.line).length && !r.shiftKey && (File.isNode && r.ctrlKey || File.isMac && r.metaKey)) return void(r.codemirrorIgnore = !0)
}
r.stopPropagation()
} else e.selection.clearGlobalColumn();
if ("Left" == i.keyNames[a]) {
if (t.getSelection().length > 0) return;
if ((o = t.doc.getCursor()) && !o.line && !o.ch && u) return e.selection.moveUpOrDown(!0, r), r.codemirrorIgnore;
r.stopPropagation()
} else if ("Right" == i.keyNames[a]) {
if (t.getSelection().length > 0) return;
if ((o = t.doc.getCursor()) && o.line >= t.lineCount() - 1 && o.ch >= t.doc.getLine(o.line).length && u) return e.selection.moveUpOrDown(!1, r), r.codemirrorIgnore;
r.stopPropagation()
} else if ("Backspace" == i.keyNames[a]) {
if ((o = t.doc.getCursor()) && t.lineCount() <= 1 && !o.line && !o.ch && !t.getSelection().length) return function(t) {
var i = e.getNode(t.cid),
r = e.undo.UndoManager,
o = r.makeEmptyCommand();
n.beforeDeleteFences(t.cid), o.undo.push({
type: "fences-pos",
pos: t.getCursor(),
id: t.cid
}), r.append(o, e.UserOp.backToParagraph(e, i, !1)), e.undo.register(o)
}(t), r.preventDefault(), r.codemirrorIgnore;
r.stopPropagation()
} else if ("PageDown" == i.keyNames[a]) {
if (!(o = t.doc.getCursor(o)) || t.doc.indexFromPos(o) >= t.doc.getValue().length) return t.execCommand("goDocEnd"), e.selection.moveUpOrDown(!1), void(r.codemirrorIgnore = !0)
} else if ("PageUp" == i.keyNames[a]) {
if (!(o = t.doc.getCursor()) || 0 == o.line && 0 == o.ch) return t.execCommand("goDocStart"), e.selection.moveUpOrDown(!0), void(r.codemirrorIgnore = !0)
} else if ("Enter" == i.keyNames[a] && (File.isMac ? r.metaKey : r.ctrlKey)) {
if (t.getSelection().length > 0) return;
if (o = t.doc.getCursor(), t.lineCount() - 1 == o.line && o.ch >= t.doc.getLine(o.line).length) return e.UserOp.insertParagraph(!1), r.stopPropagation(), void(r.codemirrorIgnore = !0)
}(i.keyMap.macDefault[s] || i.keyMap.pcDefault[s]) && r.stopPropagation()
}
function a(n) {
e.refocus(t.id), n.getWrapperElement().offsetHeight || n.refresh();
o(n.getWrapperElement()).closest(".md-fences").find(".md-tooltip-hide").show(), d(n), l.isDiagramType(n.options.mode) && e.diagrams.startPreview(n.cid), File.isMac && bridge.callHandler("touchBar.setFencesOnSetLang", !1)
}
function u(t, e) {
if (t.focus(), "" == t.getSelection()) {
var n = t.findWordAt(i.posFromMouse(t, e));
t.setSelection(n.head, n.anchor)
}
File.isNodeHtml && File.contextMenu.show(e, t.getWrapperElement())
}
function c(n, i) {
e.wordCount.quickUpdate(n.cid), e.selection.clearGlobalColumn(), l.isDiagramType(n.options.mode) && e.diagrams.updateDiagram(n.cid), File.isTypeWriterMode && !File.option.scrollWithCursor && e.selection.typeWriterScroll(n.cursorCoords(n.getCursor())), t.set("text", n.getValue()), i.length && i[0].origin && e.syncChange([{
type: "sync",
id: n.cid,
cmChanges: i
}])
}
function h(t, n) {
l.isDiagramType(t.options.mode) && n.ranges.length && n.ranges[0].anchor.line != (t.getCursor() || {}).line && e.diagrams.attachError(t)
}
function d(t, n) {
File.isTypeWriterMode && File.option.scrollWithCursor && e.selection.typeWriterScroll(t.cursorCoords(t.getCursor())), e.wordCount.updateInSelection()
}
function v(t, e) {
File.isTypeWriterMode && e.preventDefault()
}
if ("string" == typeof t && (t = this.editor.getNode(t)), !this.queue[t.id] && t.get("type") == t.TYPE.fences) {
if (!(w = o("[cid = " + t.id + "]").removeClass("mock-cm")).length) return;
var g = w.find(".md-diagram-panel").clone();
w.addClass("ty-contain-cm").html("");
var b = getCodeMirrorMode(t.get("lang"));
t.id, this.modeLoaded;
var y = {
lineWrapping: !File.option.noLineWrapping,
mode: b,
styleSelectedText: !0,
maxHighlightLength: 1 / 0,
viewportMargin: 1 / 0,
styleActiveLine: !0,
autoCloseBrackets: !File.option.noPairingMatch,
autoCloseTags: !File.option.noPairingMatch,
theme: " inner",
lineNumbers: File.option.showLineNumbersForFence,
resetSelectionOnContextMenu: !0,
cursorScrollMargin: 60,
dragDrop: !1,
indentUnit: File.option.codeIndentSize,
tabSize: File.option.codeIndentSize,
scrollbarStyle: "null",
value: t.safeGetStrAttr("text").replace(/\u200b```/gm, "```")
};
Object.assign(y, p(t.get("lang"))), this.queue[t.id] = i(w[0], y, this.editor, t.id), t.get("history") && this.queue[t.id].setHistory(t.get("history")), this.queue[t.id].off("keydown", r), this.queue[t.id].on("keydown", r), this.queue[t.id].off("focus", a), this.queue[t.id].on("focus", a), this.queue[t.id].off("changes", c), this.queue[t.id].on("changes", c), this.queue[t.id].off("scrollCursorIntoView", v), this.queue[t.id].on("scrollCursorIntoView", v), this.queue[t.id].off("cursorActivity", d), this.queue[t.id].on("cursorActivity", d), this.queue[t.id].off("contextmenu", u), this.queue[t.id].on("contextmenu", u), this.queue[t.id].off("beforeSelectionChange", h), this.queue[t.id].on("beforeSelectionChange", h);
var w = o("[cid = " + t.id + "]"),
F = document.createElement("div");
F.setAttribute("class", "code-tooltip md-tooltip-hide"), F.setAttribute("align", "right"), F.setAttribute("contenteditable", "false"), F.innerHTML = "<span class='ty-input ty-input-after ty-cm-lang-input' contenteditable='plaintext-only' tabindex='-1' autocorrect='false' placeholder='" + o.localize.getString("select a language") + "'></span>", F.childNodes[0].textContent = t.get("lang") || "", w[0].insertChildAtIndex(F, 1), w.children(".CodeMirror").attr("lang", (t.get("lang") || "").toLowerCase()), this.modeLoaded && w.addClass("modeLoaded"), !File.option.showLineNumbersForFence && y.lineNumbers && w.addClass("md-fences-with-lineno"), g.length && w.append(g),
function(t, e) {
var n = this,
i = t.find(".ty-input").on("change blur", function() {
o(this).val() != e.get("lang") && n.tryAddLangUndo(e, this)
}).keydown(function(t) {
var e = t.which || t.keyCode;
"Enter" == f[e] && o(this).trigger("change")
}).focus(function() {
File.isMac && bridge.callHandler("touchBar.setFencesOnSetLang", !0)
}).on("keydown", function(t) {
var e, i = t.keyCode || t.which;
if ("Delete" == f[i]) {
if ((e = n.editor.selection.getRangy()).commonAncestorContainer.parentElement != this) return !1;
if (e.commonAncestorContainer == this || e.startOffset == e.endOffset && e.endOffset == this.textContent.length) return n.editor.selection.moveUpOrDown(!1), !1
} else if ("Backspace" == f[i]) {
if ((e = n.editor.selection.getRangy()).commonAncestorContainer.parentElement != this) return !1;
if (e.commonAncestorContainer == this || e.startOffset == e.endOffset && 0 == e.startOffset) return n.editor.selection.moveUpOrDown(!0), !1
} else if ("Return" == f[i] || "Enter" == f[i]) return n.editor.selection.moveUpOrDown(!1), !1
}).on("paste", function(t) {
setTimeout(function() {
t.target.textContent = t.target.textContent.replace(/(^\n+)|(\n+$)/g, "").split(/\r?\n/)[0], o(t.target).trigger("change")
}, 0)
}).on("input", function(t) {
this.querySelector("*") && (this.textContent = this.textContent.replace(/(^\n+)|(\n+$)/g, ""))
});
return s.enable(i[0], {
hintsFetcher: function(t, e) {
e(m(t));
var n = document.querySelector(".autoComplt-list");
n && (n.style.height = "auto")
},
maxHintNum: 5
}), t
}.call(this, w, t)
}
return this.queue[t.id]
},
toggleFocusedComponent: function() {
var t = document.activeElement,
e = o(t).closest(".md-fences");
if (e.length)
if (t.classList && t.classList.contains("ty-cm-lang-input")) {
var n = e.attr("cid"),
i = this.getCm(n),
r = i.getCursor();
i.focus(), i.setCursor(r)
} else e.find(".CodeMirror-focused").removeClass("CodeMirror-focused").end().find(".ty-input").show().focus()
},
focus: function(t) {
var e = "string" == typeof t ? t : t.id;
this.getCm(e).focus()
},
getFocused: function() {
for (var t in this.queue)
if (this.queue.hasOwnProperty(t) && this.queue[t].hasFocus()) return this.queue[t]
},
updateCodeNum: function() {
for (var t in this.queue) this.editor.getNode(t) || delete this.queue[t]
},
syncToNode: function(t) {
var e, n;
(e = "string" == typeof t ? this.editor.getNode(t) : t) && (n = this.getCm(e.id), e.set("history", n.doc.getHistory()), e.set("text", n.getValue()))
},
intersectionObserve: function(t, e) {
this.continueRenderTimer && clearTimeout(this.continueRenderTimer), this.intersectionObserver && e && this.intersectionObserver.disconnect();
var n = this;
t && (this.intersectionObserver || (this.intersectionObserver = new IntersectionObserver(function(t) {
t.forEach(function(t) {
t.intersectionRatio <= 0 || (n.addCodeBlock(t.target.getAttribute("cid")), n.intersectionObserver.unobserve(t.target))
})
})), this.intersectionObserver.observe(t))
},
refreshEditor: function(t, e, n) {
if (this.modeLoaded) {
var i = this,
r = 0;
for (var o in this.queue) {
var a = this.editor.findElemById(o);
if (a.find(".CodeMirror").length && this.editor.getNode(o)) {
var s = this.queue[o];
if (a.hasClass("modeLoaded")) e && s.refresh();
else {
var u = this.editor.getNode(o);
s.setOption("mode", getCodeMirrorMode(u.get("lang"))), s.refresh()
}
r++
} else delete this.queue[o]
}
var c = (n || document).querySelectorAll("\t[mdtype='fences']"),
l = window.IntersectionObserver ? 8 : 30,
f = 0;
c.length != r && c.forEach(function(e) {
var n = e.getAttribute("cid");
i.queue[n] || (t || f < l ? (i.addCodeBlock(n), f++) : window.IntersectionObserver && i.intersectionObserve(e))
})
}
},
lazyload: function() {
var t = this;
o.getScript((File.isNode && !window.debugMode ? "./lib.asar" : "./lib") + "/codemirror/mode.min.js").then(function() {
t.modeLoaded = !0, t.refreshEditor()
})
},
addToUndoManager: function(t) {
this.editor.undo.register({
undo: [{
type: "fences",
cmd: "undo",
id: t.cid
}],
redo: [{
type: "fences",
cmd: "redo",
id: t.cid
}]
})
},
jumpCmEnd: function(t) {
var e = t,
n = t;
"string" == typeof e ? n = this.getCm(e) : e = n.cid;
var i = 0,
r = 0;
n && (i = n.doc.lastLine(), r = n.doc.getLine(i).length, n.focus(), n.setCursor({
line: i,
ch: r
}))
},
jumpCmBegin: function(t) {
var e = t;
"string" == typeof e && (e = this.getCm(e)), e.focus(), e.setCursor({
line: 0,
ch: 0
})
},
beforeDeleteFences: function(t, e) {
var n, i;
"string" == typeof t ? (n = this.queue[t], i = this.editor.getNode(t)) : (i = t, n = this.queue[i.id]), n && (i.set("text", n.getValue()), i.set("history", n.doc.getHistory()), n.doc.history = null, delete this.queue[i.id], e && e.map(function(t) {
t && (t.id == i.id && t.json && t.json.content && t.json.content.type == i.TYPE.fences ? (t.json.content.text = i.get("text"), t.json.content.history = i.get("history")) : Array.isArray(t.json) && t.json.map(function(t) {
t.id == i.id && t.content.type == i.TYPE.fences && (t.content.text = i.get("text"), t.content.history = i.get("history"))
}))
}))
},
searchOn: function(t, e, n) {
this.searchStatus = this.searchStatus || {}, this.searchStatus.overlay = this.searchStatus.overlay || {}, this.searchStatus.queue = this.searchStatus.queue || [];
var i = new RegExp("^" + r.escapeRegExp(e), n.caseSensitive ? "" : "i");
this.searchStatus.overlay[t.cid || "source"] = (o = e, {
token: function(t) {
return n.wholeWord && t.pos && /[a-z_\\u00C0-\\u024f]/.exec(t.string.substring(t.pos - 1, t.pos)) || !t.match(i) || n.wholeWord && /[a-z_\\u00C0-\\u024f]/.exec(t.string.substr(t.pos, t.pos + 1)) ? (t.next(), t.pos = t.string.toLowerCase().indexOf(o, t.pos), !~t.pos && t.skipToEnd(), null) : "search-hit"
}
});
var o;
t.addOverlay(this.searchStatus.overlay[t.cid || "source"]), this.searchStatus.queue.push(t)
},
clearSearchOn: function(t) {
this.searchStatus && (t.removeOverlay(this.searchStatus.overlay[t.cid || "source"]), this.searchStatus.queue.remove(t))
},
clearSearchAll: function() {
if (this.editor.sourceView.inSourceMode) return this.searchStatus && this.editor.sourceView.cm.removeOverlay(this.searchStatus.overlay.source), void(this.searchStatus = null);
this.searchStatus && this.searchStatus.overlay && this.searchStatus.queue.forEach(function(t) {
this.searchStatus.overlay[t.cid] && t.removeOverlay(this.searchStatus.overlay[t.cid])
}, this), this.searchStatus = null
},
tryAddLangUndo: function(t, e) {
if (e || (e = document.activeElement), !e.classList || !e.classList.contains("ty-cm-lang-input")) return !1;
if (t || (t = this.editor.getNode(o(e).closest("[cid]").attr("cid"))), !t) return !1;
var n = t.get("lang") || "",
i = e.textContent || "";
return n != i && (t.attr("lang", i, this.editor, !1), !0)
}
});
n.exports = g, window.CodeMirror = i, window.Fences = g
}), $__System.registerDynamic("27", ["1f", "e", "12", "13", "1b", "14", "26"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("1f"),
r = t("e"),
o = t("12"),
a = t("13"),
s = a.Node,
u = t("1b"),
c = (u.SnapFlag, t("14")),
l = t("26"),
f = l.map,
h = a.TYPE,
d = (f = l.map, document.querySelector("#md-rawblock-tooltip-templ").innerHTML);
var m = !1;
function v() {
if (m || !window.MathJax) return !0;
File.option.autoNumberingForMath && (MathJax.Hub.config.TeX.equationNumbers ? MathJax.Hub.config.TeX.equationNumbers.autoNumber = "all" : MathJax.Hub.config.TeX.equationNumbers = {
autoNumber: "all",
useLabelIds: !0
}),
function() {
var t = [],
e = [];
MathJax.Hub.Register.MessageHook("Begin Attach MathJax", function(n) {
w() && (t = Object.keys(p.labels).clone(), e = Object.keys(p.eqlabels).clone())
}), MathJax.Hub.Register.MessageHook("End Attach MathJax", function(n) {
var i = [],
o = [],
a = r(n[1]).closest("[mdtype='math_block']");
if (w() && a.length) {
var s = File.editor.findNodeByElem(a);
for (var u in p.labels) - 1 == t.indexOf(u) && i.push(u);
for (var c in p.eqlabels) - 1 == e.indexOf(c) && o.push(c);
s.set("mathLabel", i), s.set("mathEqLabel", o)
}
})
}(), m = !0
}
var p, g = o.Model.extend({
initialize: function(t) {
this.editor = t, this.queue = {}, this.preview, this.bindEvent(), v()
},
bindEvent: function() {
var t = this,
e = this.editor;
r(this.editor.sessionStr).on("mousedown", ".md-math-container", function(t) {
e.undo.prepCursorSnap()
}).on("click startedit", ".md-math-container", function(n) {
if (void 0 === n.which || 1 == n.which) return t.startEditing(r(this).closest("[cid]"), "auto"), e.undo.endSnap(), !1
}).on("losefocus", ".md-math-block", function(n) {
t.stopEditing(this.getAttribute("cid")), e.selection.scrollAdjust()
}).on("endfocus", ".md-math-block", function(n) {
t.stopEditing(this.getAttribute("cid"), !1, !0), e.selection.scrollAdjust()
}).on("keydown", ".md-math-block", function(e) {
var n = event.keyCode || event.which;
if ("Enter" === f[n]) return t.startEditing(r(this), "auto"), e.stopPropagation(), e.preventDefault()
}).on("blur inline-change", ".md-math-block .ty-input", function() {
if (t.currentCm) {
var e = t.editor.getNode(t.currentCm.cid);
t.tryAddTagUndo(e, r(this))
}
}).on("keydown", ".md-math-block .ty-input", function(e) {
"Enter" == f[e.keyCode || e.which] && t.editor.selection.moveUpOrDown(!1, e)
}).on("click", ".md-math-block .md-rawblock-after, .md-math-block .md-rawblock-before", function(t) {
t.target == this && this.querySelector(".ty-input").focus()
}).on("keydown", ".md-math-block .ty-input", function(e) {
var n, i = e.keyCode || e.which;
if ("Delete" == f[i]) {
if ((n = t.editor.selection.getRangy()).commonAncestorContainer.parentElement != this) return !1;
if (n.startOffset == n.endOffset && n.endOffset == this.textContent.length) return t.editor.selection.moveUpOrDown(!1), !1
} else if ("Backspace" == f[i]) {
if ((n = t.editor.selection.getRangy()).commonAncestorContainer.parentElement != this) return !1;
if (n.startOffset == n.endOffset && 0 == n.startOffset) return t.editor.selection.moveUpOrDown(!0), !1
} else if ("Return" == f[i] || "Enter" == f[i]) return t.editor.selection.moveUpOrDown(!1), !1
}).on("paste", ".md-math-block .ty-input", function(t) {
setTimeout(function() {
t.target.textContent = t.target.textContent.replace(/(^[\n{]+)|([\n}]+$)/g, "").split(/\r?\n/)[0], r(t.target).trigger("change")
}, 0)
})
},
tryAddTagUndo: function(t, e) {
if (!e.hasClass("ty-input")) return !1;
t || (t = this.editor.getNode(this.currentCm.cid));
var n = e.hasClass("ty-input-before") ? "tagBefore" : "tagAfter",
i = t.get(n),
r = e.text();
if (i != r) {
var o = u.makeEmptyCommand();
return o.undo.push({
id: t.cid,
type: "attr",
key: n,
value: i || ""
}), t.set(n, r), o.redo.push({
id: t.cid,
type: "attr",
key: n,
value: r
}), self.editor.undo.register(o), !0
}
return !1
},
renderAll: function(t, e) {
if (!window.MathJax) {
var n = this;
setTimeout(function() {
n.renderAll(t, e)
}, 1e3)
}
var i = (t || document).querySelectorAll(".md-math-block");
t || (v(), F.Init());
for (var r = 0; r < i.length; r++) {
var o = i[r],
a = o.querySelector("script");
if (a && (!a.MathJax && !a.parentElement.classList.contains("md-mathjax-preview "))) {
if (File.option.autoNumberingForMath && !e) return void this.forceRefresh();
var s = this.editor.getNode(o.getAttribute("cid"));
MathJax.Hub.Queue(["BeforeRender", F, s], ["Process", MathJax.Hub, o.getAttribute("id")], ["AfterRender", F, s])
}
}
},
getTex: function(t) {
return this.editor.findElemById(t).find("script").text()
},
getCidAndElem: function(t) {
var e = t,
n = t;
return "string" == typeof t ? n = this.editor.findElemById(e) : e = n.attr("cid"), [e, n]
},
syncToNode: function(t) {
var e = "string" == typeof t ? this.editor.getNode(t) : t;
return (this.currentCm || {}).cid === e.cid && (e.set("history", this.currentCm.doc.getHistory()), e.set("text", this.currentCm.getValue())), e
},
remove: function(t) {
var e, n = this.getCidAndElem(t),
i = n[0],
o = n[1],
a = editor.getNode(i),
u = editor.undo.UndoManager,
c = u.makeEmptyCommand(),
l = (a.get("before"), this.currentCm);
this.beforeDeleteFences(a), l && l.cid === a.cid ? c.undo.push({
type: "fences-pos",
pos: l.getCursor(),
id: l.cid
}) : c.undo.push(this.editor.selection.buildUndo()), c.undo.push(u.buildReplaceUndo(a)), a.set("type", a.TYPE.paragraph), a.set("text", ""), s.normalizeNode(a), c.redo.push(u.buildReplaceUndo(a)), e = r(r.parseHTML(a.toHTML())[0]), o.replaceWith(e), editor.selection.jumpIntoElemEnd(e), c.redo.push(editor.selection.buildUndo()), editor.undo.register(c), this.currentCm = void 0, this.renderAll()
},
beforeDeleteFences: function(t) {
var e = this.syncToNode(t);
this.currentCm = void 0;
var n = this.editor.findElemById(t);
(n = n && n.find("script")[0]) && n.MathJax && File.option.autoNumberingForMath ? b.call(this) : w() && k(e), this.stopEditing(e.cid, !1, !0)
},
stopEditing: function(t, e, n) {
if (this.currentCm && this.currentCm.cid && t) {
var i = this.getCidAndElem(t),
o = i[0],
a = i[1],
s = this.editor,
c = this.currentCm,
l = a[0].querySelectorAll(".mathjax-candidate");
if (l[0]) {
var f = u.makeEmptyCommand();
f.undo.push({
type: "fences-pos",
pos: c.getCursor(),
id: c.cid
});
var h = "hidden" === l[0].style.visibility ? l[1] : l[0],
m = this.syncToNode(o),
v = this;
h && (this.currentCm = void 0, a.html(d.replace("{type}", r.localize.getString("Math", "Menu"))).removeClass("md-rawblock-on-edit"), h.setAttribute("class", "md-rawblock-container md-math-container"), h.setAttribute("tabindex", "-1"), a[0].appendChild(h), e && s.selection.jumpToNextBlock(m, f), !n && s.undo.register(f), File.option.autoNumberingForMath && F.isDirty ? (F.Init(), this.forceRefresh()) : (h.querySelector("script").MathJax = void 0, MathJax.Hub.Queue(["BeforeRender", F, m], ["Typeset", MathJax.Hub, h], ["AfterRender", F, m]), MathJax.Hub.Queue(function() {
void 0 !== v.startNumber && (p.startNumber = Math.max(v.startNumber, p.startNumber), p.number = p.startNumber, v.startNumber = void 0, F.Init())
})))
}
}
},
startEditing: function(t, e) {
var n = this.getCidAndElem(t),
o = n[0],
a = n[1],
u = this.editor,
c = this.editor.getNode(o);
if (s.isType(c, h.math_block)) {
var l = document.querySelector("content"),
f = null;
if (r(document.activeElement).closest(".md-math-block").length && (f = l.scrollHeight - l.scrollTop - l.clientHeight), o) {
if (this.currentCm && this.currentCm.cid === o) {
if (u.writingArea.contains(this.currentCm.getWrapperElement())) return this.currentCm.focus(), this.currentCm;
this.currentCm = null
}
this.currentCm && (this.stopEditing(this.currentCm.cid), window.getSelection().removeAllRanges()),
function() {
if (File.option.autoNumberingForMath) {
var t = this.editor.findElemById(c.id).find("script")[0];
F.startNumber = this.startNumber = void 0, t && t.MathJax && void 0 !== t.MathJax.startNumber && (this.startNumber = w().startNumber, F.startNumber = t.MathJax.startNumber, t.MathJax = void 0), void 0 == F.startNumber && File.option.autoNumberingForMath && (F.startNumber = (w() || {}).startNumber || 0)
}
}.call(this), a.html(d.replace("{type}", r.localize.getString("Math", "Menu")) + document.querySelector("#md-mathblock-panel-templ").textContent).addClass("md-rawblock-on-edit"), c.get("tagBefore") && a.find(".md-rawblock-before .ty-input").text(c.get("tagBefore")), c.get("tagAfter") && a.find(".md-rawblock-after .ty-input").text(c.get("tagAfter"));
var m = a.children(".md-mathblock-panel");
this.currentCm = function(t) {
var e = i(m[0].querySelector(".md-rawblock-input"), {
styleSelectedText: !0,
styleActiveLine: !0,
lineWrapping: !0,
mode: "stex",
placeholder: r.localize.getString("Input Math TeX here"),
theme: " inner",
autoCloseBrackets: !File.option.noPairingMatch,
autoCloseTags: !File.option.noPairingMatch,
value: c.get("text").trim(),
lineNumbers: File.option.showLineNumbersForFence,
resetSelectionOnContextMenu: !0,
dragDrop: !1,
indentUnit: File.option.codeIndentSize,
tabSize: File.option.codeIndentSize
}, t, o);
return c.get("history") && e.setHistory(c.get("history")), e.doc.on("change", function(n) {
t.wordCount.quickUpdate(e.cid), F.getTextFunc && F.Update(), t.selection.clearGlobalColumn(), t.syncChange([{
type: "sync",
id: c.id,
tex: e.getValue()
}]), File.isTypeWriterMode && !File.option.scrollWithCursor && t.selection.typeWriterScroll(e.cursorCoords(e.getCursor()))
}), e.on("cursorActivity", function() {
File.isTypeWriterMode && File.option.scrollWithCursor && t.selection.typeWriterScroll(e.cursorCoords(e.getCursor()))
}), e.on("blur", function(t) {
try {
c.set("history", t.doc.getHistory()), c.set("text", t.getValue())
} catch (t) {
console.warn(t.stack)
}
}), e.on("keydown", function(e, n) {
var r, o = n.which || n.keyCode,
a = i.keyName(n);
if (!n.metaKey && !n.shiftKey && n.ctrlKey, "Up" == i.keyNames[o]) return t.selection.moveUpOrDown(!0, n), n.codemirrorIgnore;
if ("Down" == i.keyNames[o]) return t.selection.moveUpOrDown(!1, n), n.codemirrorIgnore;
if (t.selection.clearGlobalColumn(), "Backspace" == i.keyNames[o]) {
if (!e.getValue().length) return t.mathBlock.remove(e.cid), n.preventDefault(), n.codemirrorIgnore
} else {
if ("Enter" == i.keyNames[o] && (n.ctrlKey || n.metaKey) && p(e)) return setTimeout(function() {
t.UserOp.insertParagraph()
}, 20), n.stopPropagation(), n.codemirrorIgnore;
if ("PageDown" == i.keyNames[o]) {
if (p(e)) return e.execCommand("goDocEnd"), t.selection.moveUpOrDown(!1), void(n.codemirrorIgnore = !0)
} else if ("PageUp" == i.keyNames[o] && (!(r = e.doc.getCursor()) || 0 == r.line && 0 == r.ch)) return e.execCommand("goDocStart"), t.selection.moveUpOrDown(!0), void(n.codemirrorIgnore = !0)
}(i.keyMap.macDefault[a] || i.keyMap.pcDefault[a]) && n.stopPropagation()
}), e.focus(), e
}(this.editor),
function(t, e, n, i) {
var r = t.querySelector(".CodeMirror").CodeMirror,
o = t.querySelector(".md-mathjax-preview");
o.textContent = "$$\n" + r.getValue() + "\n$$", F.Init(o, t.querySelector(".md-mathjax-buffer"), function() {
return "$$\n" + (e.doc.getValue().trim() || "<Empty \\space Math \\space Block>") + "\n$$"
}, n), F.startNumber = i, MathJax.Hub.Queue(["BeforeRender", F, n, !1], ["Typeset", MathJax.Hub, o]), F.Update()
}(a[0], this.currentCm, c, F.startNumber), (v = this.currentCm).focus(), e && ("<Empty \\space Math \\space Block>" == v.getValue() ? v.execCommand("selectAll") : "end" == e || "auto" == e ? v.execCommand("goDocEnd") : "start" == e && v.execCommand("goDocStart"), u.refocus(o), null === f || f > 100 ? u.selection.scrollAdjust() : l.scrollTop = l.scrollHeight - f - l.clientHeight)
}
var v;
return this.currentCm
}
function p(t) {
var e = t.doc.getCursor();
return !e || t.doc.indexFromPos(e) >= t.doc.getValue().length
}
},
copyAsTex: function(t) {
var e = r(t || document.activeElement).closest("[cid]").find("script")[0].textContent.trim();
this.editor.UserOp.setClipboard(null, null, e, !0)
},
copyAsMathML: function(t, e) {
var n = MathJax.Hub.getAllJax(r(t || document.activeElement).closest("[cid]")[0])[0],
i = this.editor;
y(n, function(t) {
if (e) i.UserOp.nativeCopyText(t);
else {
var n = "<pre class='md-fences' lang='xml'>" + c.escape(t) + "</pre>";
i.UserOp.setClipboard(n, null, t, !0)
}
})
},
copyAsImage: function(t) {
var e = (t && t.querySelector || document.activeElement).querySelector("svg"),
n = this.editor,
i = n.EditHelper.SVG2HtmlImg(e);
n.UserOp.setClipboard(i, null, i, !0)
},
forceRefresh: function() {
if (!File.editor.sourceView.inSourceMode) {
v(), this.editor.brush.clearAndPause(), b.call(this, !0), r(".md-math-container").each(function() {
MathJax.Hub.Queue(["Process", MathJax.Hub, this])
}), File.option.enableInlineMath && this.editor.mathInline.renderAll(!0);
var t = this;
MathJax.Hub.Queue(function() {
t.renderAll(document, !0), t.editor.brush.resume()
})
}
}
}),
b = function(t) {
!t && this.currentCm && (self.stopEditing(this.currentCm.cid), window.getSelection().removeAllRanges(), this.editor.refocus(null));
for (var e = document.querySelectorAll("script"), n = 0; n < e.length; n++) e[n].MathJax && (e[n].MathJax = void 0);
w() && (p.labels = p.eqlabels = p.IDs = p.eqIDs = {}, p.refs = [], this.startNumber = p.number = p.startNumber = 0, F.Init())
},
y = function(t, e) {
var n;
try {
n = t.root.toMathML("")
} catch (n) {
if (!n.restart) throw n;
return MathJax.Callback.After([y, t, e], n.restart)
}
MathJax.Callback(e)(n)
},
w = function() {
return p = MathJax.Extension["TeX/AMSmath"]
},
F = {
delay: 0,
preview: null,
buffer: null,
timeout: null,
mjRunning: !1,
oldText: null,
maxIgnored: 3,
curIgnored: 0,
startNumber: void 0,
originalEnd: void 0,
isDirty: !1,
Init: function(t, e, n, i) {
File.editor.mathBlock && !n && this.getTextFunc && File.editor.mathBlock.currentCm || (this.preview = t, this.buffer = e, this.getTextFunc = n, this.node = i, this.originalEnd = void 0, this.isDirty = !1, this.startNumber = void 0)
},
SwapBuffers: function() {
var t = this.preview,
e = this.buffer;
this.buffer = t, this.preview = e, t && e && (t.style.visibility = "hidden", t.style.position = "absolute", e.style.position = "", e.style.visibility = "")
},
Update: function() {
this.callback()
},
CreatePreview: function() {
if (this.curIgnored = 0, F.timeout = null, !this.mjRunning) {
var t = this.getTextFunc();
t !== this.oldtext && (this.buffer.textContent = this.oldtext = t, this.mjRunning = !0, MathJax.Hub.Queue(["BeforeRender", this, this.node, !1], ["Typeset", MathJax.Hub, this.buffer], ["AfterRender", this, this.node], ["PreviewDone", this, this.node]))
}
},
PreviewDone: function() {
this.mjRunning = !1, this.SwapBuffers()
},
BeforeRender: function(t, e) {
w() && (e ? (t.unset("mathLabel"), t.unset("mathEqLabel")) : k(t), void 0 !== this.startNumber && (p.startNumber = p.number = this.startNumber))
},
AfterRender: function(t) {
File.option.autoNumberingForMath && w() && (this.isDirty || (void 0 === this.originalEnd ? this.originalEnd = p.startNumber : this.isDirty = this.originalEnd !== p.startNumber))
}
};
function k(t) {
(t.get("mathLabel") || []).map(function(t) {
delete p.labels[t]
}), (t.get("mathEqLabel") || []).map(function(t) {
delete p.eqlabels[t]
})
}
F.callback = MathJax.Callback(["CreatePreview", F]), F.callback.autoReset = !0, g.Preview = F, n.exports = g
}), $__System.registerDynamic("28", ["e", "12", "13", "1b", "26", "29", "14", "1c"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("e"),
r = t("12"),
o = (t("13").Node, t("1b"), t("26")),
a = t("29"),
s = (o.map, t("14"));
t("1c");
window.svgCache = {};
var u, c = function(t, e, n) {
return !!e.length && (!n && MathJax.Hub.Queue(function() {
t.brush.pause()
}), e.forEach(function(t) {
(function(t) {
t && MathJax.Hub.Queue(["Process", MathJax.Hub, t], function() {
t.querySelector(".noError") && t.querySelector("script").classList.add("math-jax-error");
var e = t.parentElement;
if (e && !e.classList.contains("math-jax-postprocess")) {
e.classList.add("math-jax-postprocess"), e.classList.remove("math-jax-preprocess");
var n = t.querySelector("script").innerText.replace(/\u200B+/g, ""),
i = t.cloneNode(!0);
i.children.forEach(function(t) {
t.hasAttribute("id") && t.removeAttribute("id")
}), svgCache[n] = a.processExportedSVG(i.innerHTML)
}
})
}).call(this, t, n)
}, this), !n && MathJax.Hub.Queue(function() {
t.brush.resume()
}), !0)
},
l = null,
f = function(t, e) {
u = e[0];
var n = i("#math-inline-preview"),
r = i("#math-inline-preview-content"),
o = e.clone().find("svg").remove().end().text();
l = function() {
var e = MathJax.Hub.getAllJax(r[0])[0],
o = i(".md-inline-math.md-expand"),
s = o.find("script"),
u = s.text().replace(/\u200B+/g, ""),
c = l;
if (e) return s.height() ? void(svgCache[u] || MathJax.Hub.Queue(["Text", e, u], function() {
a.fixPopoverPosition(s, n), o.find("svg").replaceWith(n.find("svg").clone())
})) : i(t.sessionStr).off("inline-math-changed", c)
}, (n.hasClass("md-math-inline-prep-preview") || "none" === n[0].style.display) && /^\$/.exec(o) && (n.removeClass("md-math-inline-prep-preview"), r.text(o), MathJax.Hub.Queue(["Typeset", MathJax.Hub, r[0]], function() {
n.show(), a.fixPopoverPosition(e.find("script"), n), i(t.sessionStr).on("inline-math-changed", l)
}))
},
h = function(t) {
u = null;
var e = i("#math-inline-preview");
"none" !== e[0].style.display && e.hide(), l && (i(t.sessionStr).off("inline-math-changed", l), l = null)
},
d = function(t, e) {
var n;
try {
n = t.root.toMathML("")
} catch (n) {
if (!n.restart) throw n;
return MathJax.Callback.After([d, t, e], n.restart)
}
MathJax.Callback(e)(n)
},
m = function() {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, document.querySelector("#math-preheat")])
},
v = r.Model.extend({
initialize: function(t) {
this.editor = t, this.queue = {},
function() {
var t = this.editor;
i(this.editor.sessionStr).on("cursorChange", function(e) {
var n, r = e.cursor || t.selection.getRangy();
if (!r) return h(t);
(n = i(r.commonAncestorContainer).closest(".md-inline-math.md-expand")).find("script").length ? (u != n[0] && h(t), f(t, n)) : h(t)
}).on("mousedown", ".md-inline-math svg", function(e) {
h(t), i(".md-expand").removeClass("md-expand");
var n = i(this).closest(".md-inline-math"),
r = n.addClass("md-expand").find("script");
t.selection.selectAllElem(r), f(t, n)
})
}.call(this), File.option.enableInlineMath && setTimeout(m, 1e3)
},
brush: function(t, e, n) {
var i = t.querySelectorAll(".math-jax-preprocess .inline-math-svg");
return c.call(this, this.editor, i, n && e && t.getAttribute("cid") === e.startId ? e : null), i.length
},
showAutoSuggest: function(t) {
if (File.option.enableInlineMath) {
i(".md-math-prep").removeClass("md-math-prep"), a.markRange(t, "md-math-prep");
var e = i("#math-inline-preview").show().addClass("md-math-inline-prep-preview").css("width", "auto");
e.find("#math-inline-preview-content").text("<Empty Inline Math>"), a.fixPopoverPosition(i(".md-math-prep"), e)
}
},
renderAll: function(t, e) {
if (File.option.enableInlineMath) {
var n = [];
t ? (window.svgCache = {}, (n = document.querySelectorAll(".inline-math-svg")).forEach(function(t) {
t.innerHTML = "<script type='math/tex'>" + t.querySelector("script").innerText + "<\/script>", t.parentElement.classList.add("math-jax-preprocess"), t.parentElement.classList.remove("math-jax-postprocess")
})) : n = (e || document).querySelectorAll(".math-jax-preprocess .inline-math-svg"), n.length && (c.call(this, this.editor, n), this.renderInToc())
}
},
renderInToc: function() {
File.option.enableInlineMath && document.querySelectorAll(".math-in-toc").forEach(function(t) {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, t])
}, this)
},
tryCloseInlinePreview: function() {
h(this.editor)
},
copyAsTex: function() {
var t = function() {
var t = this.editor.selection.getRangy();
return i(t.commonAncestorContainer).closest(".md-inline-math")
}.call(this),
e = t.attr("pattern"),
n = t.text().replace("$$" == e ? /(^\$\$)|(\$\$$)/g : /(^\$)|(\$$)/g, "");
this.editor.UserOp.setClipboard(null, null, n, !0)
},
copyAsMathML: function(t) {
var e = i("#math-inline-preview-content")[0],
n = MathJax.Hub.getAllJax(e)[0],
r = this.editor;
d(n, function(e) {
if (t) r.UserOp.nativeCopyText(e);
else {
var n = "<pre class='md-fences' lang='xml'>" + s.escape(e) + "</pre>";
r.UserOp.setClipboard(n, null, e, !0)
}
})
},
copyAsImage: function() {
var t = document.querySelector("#math-inline-preview-content svg"),
e = this.editor,
n = e.EditHelper.SVG2HtmlImg(t);
e.UserOp.setClipboard(n, null, n, !0)
}
});
n.exports = v
}), $__System.registerDynamic("2a", ["12", "14", "19", "13", "2b", "1b", "29", "2c", "1c"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("12"),
r = t("14"),
o = t("19"),
a = t("13"),
s = a.Node,
u = a.TYPE,
c = t("2b"),
l = t("1b"),
f = (t("29"), t("2c"), l.SnapFlag),
h = t("1c"),
d = function(t) {
this.editor = t, this.queue = [], this.interval = 200, this.inline = new o.InlineLexer, this.articleArea = document.querySelector(this.editor.sessionStr), b.call(this)
},
m = null,
v = null,
p = {},
g = function(t, e) {
if (t || e) {
try {
t.brush.pause(), v ? t.focusCid = v.id || v.startId : t.refocus(void 0, void 0, !0);
var n = m,
i = h.createRange(),
r = l.makeEmptyCommand(v || t.selection.buildUndo()),
o = t.getNode(t.focusCid);
if (r.undo.push(l.buildReplaceUndo(o)), i.moveToBookmark(n), t.selection.deRange(i), i.deleteContents(), i.insertNode(document.createTextNode(e)), n.start = n.start += e.length, n.end = n.start, t.store(t.focusCid, !0), i.moveToBookmark(n), r.redo.push(l.buildReplaceUndo(o)), t.selection.setRange(i, !0), r.redo.push(t.selection.buildUndo()), t.undo.register(r), "fences" == p.type) {
var a = o.breakOn(!1, t);
t.findElemById(a.oldCid).replaceWith(a.newHtml), t.selection.jumpIntoElemBegin(t.findElemById(a.nextFocus)), t.undo.register(a.command)
} else t.brush.addToQueue(t.focusCid, !0)
} catch (t) {
console.sendError(t.stack)
}
t.brush.hideAutoComplete(), t.brush.resume(!0)
} else t.brush.hideAutoComplete()
},
b = function() {
this.autoCompleteShown = !1;
var t = this.editor;
$(document).click(function(e) {
document.activeElement !== t.brush.articleArea && t.brush.hideAutoComplete()
}), $(".auto-suggest-container").on("mousedown", "li[data-content]", function(e) {
v = t.selection.buildUndo()
}).on("click", "li[data-content]", function(e) {
g(t, this.getAttribute("data-content"))
})
},
y = function(t) {
if (!t || !t.length) return !1;
var e = window.getSelection().getRangeAt(0).getClientRects()[0],
n = !t.hasClass("ty-show"),
i = document.querySelector("content").getBoundingClientRect(),
r = e.left - 15;
return n && (r = r + 200 > window.innerWidth ? window.innerWidth - 200 : r, t.css({
top: e.bottom + (File.isMac && app.shouldFixFontGlitch ? $("content").scrollTop() - i.top : 0),
left: r
}).addClass("ty-show")), t.find("[data-page]").hide().filter("[data-page=" + p.pageNo + "]").show(), this.autoCompleteShown = !0, !0
};
d.prototype = {
addToQueue: function(t, e) {
e = e || !1, r.isNullOrEmpty(t) || this.queue.push({
cid: t,
inlineOnly: e
})
},
run: function() {
this.timerID || this.scheduleNext()
},
scheduleNext: function() {
var t = this;
this.timerID = window.setTimeout(function() {
t.brushQueue(), t.scheduleNext()
}, this.interval)
},
clearAndPause: function() {
this.queue = [], this.pause()
},
pause: function() {
clearTimeout(this.timerID), this.timerID = null
},
resume: function(t) {
t && this.brushQueue(), this.run()
},
restart: function() {
this.queue = [], this.run()
},
brushNode: function(t) {
var e = this.editor.selection.buildUndo();
x.call(this, t, {}, e, !1) && this.editor.undo.exeCommand(e)
},
brushQueue: function() {
var t = this,
e = {},
n = t.queue.length;
if (!this.editor.isIME && !this.editor.isMousePressed) {
if (t.queue.length > 0 && !File.isLocked) {
var i = t.editor.selection.buildUndo(),
r = !1,
o = !0;
t.queue.map(function(n) {
e[n.cid] || (r = x.call(t, n.cid, e, i, n.inlineOnly) || r, e[n.cid] = 1, o = o && n.inlineOnly)
}), t.queue = [], r && i && t.editor.undo.exeCommand(i), this.expand(!0, !1, o)
}
n && this.triggerAutoComplete()
}
},
applyAutocompleteByKey: function() {
v = null, this.autoCompleteShown && g(this.editor, ((document.querySelector(".auto-suggest-container.ty-show .active") || {}).dataset || {}).content)
},
triggerAutoComplete: function(t) {
var e, n, i = null,
r = this.editor,
o = this.editor.selection.getTextAround(),
a = o[0],
s = o[1],
u = o[2],
c = this.editor.getJQueryElem((this.editor.selection.getRangy() || {}).commonAncestorContainer),
l = c.closest(".md-inline-math").length,
h = t && File.option.enableInlineMath,
d = this.editor.selection.getRangy();
if (u && d && d.collapsed && (a || s)) {
if (r.lastCursor = r.selection.buildUndo(d), n = function() {
if (d && d.collapsed) {
var t = $(d.endContainer).closest(".md-lang"),
e = t.text(),
n = t.prev().text().length + t.parent().prevAll().text().length;
if (e) return m = {
start: n,
end: n + e.length,
containerNode: t.closest("[mdtype]")[0]
}, e
}
}.call(this)) return void y.call(this, this.editor.fences.showAutoSuggest(n, p));
if (i = _.exec(a)) return void((e = /^(\w*:*)(\s|$)/.exec(s || "")) && (y.call(this, this.editor.emoji.showAutoSuggest(i[1] + e[1], p)), u.start -= i[1].length + 1, u.end += e[1].length, m = u));
if (h && (n = /\$?\$$/.exec(a)) && 0 == $(".md-expand.md-inline-math").length) {
var v, g = (/^\$+/.exec(s) || "").length;
if (g <= n[0].length) return (v = "$".repeat(n[0].length - g)).length && (d.insertNode(document.createTextNode(v)), d.collapse(!0)), u.start -= n[0].length, u.end += n[0].length, d.moveToBookmark(u), this.editor.mathInline.showAutoSuggest(d), this.editor.restoreLastCursor(null, !0), this.editor.undo.addSnap(r.focusCid, f.REPLACE), void(m = null)
}
} else {
if (!l) return this.hideAutoComplete();
c.trigger("inline-math-changed")
}
this.hideAutoComplete()
},
changeAutoCompleteSelection: function(t, e) {
if (this.isAutoCompleteShown()) {
var n, i = $(".auto-suggest-container.ty-show"),
r = i.find(".active");
i.length && p.pageCnt && (e && e.preventDefault(), r.length ? (r.length && (r = r.removeClass("active")[t ? "prev" : "next"]().addClass("active")), r.length || (p.pageNo += t ? -1 : 1, p.pageNo < 0 ? p.pageNo = p.pageCnt - 1 : p.pageNo >= p.pageCnt && (p.pageNo = 0), n = i.find("[data-page]").hide().filter("[data-page=" + p.pageNo + "]").show(), t ? n.find("li:last").addClass("active") : n.find("li:first").addClass("active"))) : r = i.find("ul:first>li:first").addClass("active"))
}
},
hideAutoComplete: function() {
p = {}, m = null, this.autoCompleteShown = !1, $(".auto-suggest-container.ty-show").removeClass("ty-show").find(".active").removeClass("active")
},
expandOnDelay: function(t) {
var e = this;
this.willExpandSoon && clearTimeout(this.willExpandSoon), this.willExpandSoon = setTimeout(function() {
e.expand(t)
}, 10)
},
closestExpandable: function(t) {
var e = t.closest("[md-inline]"),
n = e.parent().closest("[md-inline]");
if (!n.length) return e;
var i = e.attr("md-inline");
return i && !s.isType(i, u.plain, u.br, u.tag, u.autolink, u.pants, u.attr, u.linebreak) && e.prevAll("[md-inline]").length || e.nextAll("[md-inline]").length ? e : this.closestExpandable(n)
},
expand: function(t, e, n) {
if (!e && this.editor.wordCount.updateInSelection(), this.willExpandSoon && (clearTimeout(this.willExpandSoon), this.willExpandSoon = null), !this.editor.isIME) {
var i = this.editor.selection,
r = i.getRangy(),
o = i.rangy,
a = r ? r.cloneRange() : null;
if (a && (a.startContainer != this.editor.writingArea || 0 != a.startOffset)) {
var c;
if ($(".selected").removeClass("selected"), r && !File.isLocked) {
if (this.editor.selection.deRange(r), c = this.editor.getJQueryElem(r.commonAncestorContainer), this.editor.stylize.putBookmark(a, this.editor.stylize.buildBookmark(c)), !e && !n && function(t, e) {
var n = t.closest("[cid]");
if (n.length && t.closest("[md-inline]").length && !t.closest(".md-block-like").length) {
var i = n.find(".md-block-like");
if (!i.length) return !1;
var r = editor.findNodeByElem(t.closest("[cid]")),
o = editor.selection.buildUndo(e);
if (r.cid != o.endId) return !1;
var a = i.prevAll().rawText().length,
s = i.rawText().length;
if (!editor.lastCursor || editor.lastCursor.endId != o.endId || editor.lastCursor.startOffset > a + s || editor.lastCursor.endOffset < a + s) return !1;
var u = !1;
e.comparePoint(i[0], 0) < 0 && (o.start = o.end = o.end - a - s, u = !0);
var c = editor.simpleParse(r, !1);
if (c) return editor.findElemById(c[2]).replaceWith(c[1]), u && c[3].length > 1 && (o.startId = o.endId = c[3].last().getVeryFirst().cid), editor.undo.exeCommand(o), c[0].undo[0] = editor.lastCursor, c[0].redo.push(editor.selection.buildUndo()), editor.undo.register(c[0]), editor.quickRefresh(), !0
}
return !1
}(c, r)) return;
if (isInputComponent(document.activeElement) || document.activeElement.hasAttribute("tabindex")) return $(".md-expand").removeClass("md-expand"), $(this.editor.sessionStr).trigger("cursorChange", this.editor.styleBookmark);
if (!c.closest("[cid]").length || s.isType(c.closest("[cid]").attr("mdtype"), u.fences, u.math_block, u.html_block)) return $(this.editor.sessionStr).trigger("cursorChange", this.editor.styleBookmark);
if (r.collapsed) {
var l, f = k(c),
h = c.closest("[mdtype]"),
d = (h.attr("contenteditable"), []),
m = f.visibleText().length;
if (r.endOffset === m && m < f.text().length) l = f.addClass("md-expand"), (a = o.createRange()).collapseToPoint(f[0], f[0].childNodes.length), this.editor.selection.setRange(a, !0);
else if (b(r, -1), l = h[0] != $(r.startContainer).closest("[mdtype]")[0] ? f : k(this.editor.getJQueryElem(r.startContainer)), r.startContainer === r.endContainer)
if (r.toString().length && r.collapse(!1), 3 == r.endContainer.nodeType && r.endOffset == r.endContainer.textContent.length && y(r.endContainer.nextElementSibling)) r.endContainer.nextElementSibling.classList.add("selected"), r.selectNode(r.endContainer.nextElementSibling);
else {
b(r, 1);
var v = r.getNodes([1], y);
v.length && (a.setStart(v[0], 0), a.setEnd(v[0], 0), editor.selection.setRange(a, !0))
}
} else l = k(this.editor.getJQueryElem(r.startContainer));
if (!(d = k(this.editor.getJQueryElem(r.endContainer))).length && (d = l), l.length || d.length) {
var p = !1;
a.collapsed || (p = (a = function(e) {
try {
var n, i, r = e.commonAncestorContainer;
if (0 == e.startOffset && l.length && (l = editor.getJQueryElem(e.startContainer)).length)
if (l.closest(".md-expand").length || l[0].hasAttribute("cid") || l[0].querySelector("[cid]") || l.closest(".md-image:not(.md-img-loaded)").length)(i = l.closest(".md-expand")).length && (l = i);
else {
n = l.closest("[cid]")[0];
var o = e.collapsed;
l = function e(n, i) {
if (!n.prevAll(":not(.md-meta, .md-content)").text().length) {
var r = n.parent();
return r.attr("mdtype") ? n : i.contains(r[0]) || t ? e(r, i) : k(n)
}
return k(n)
}(l, r.contains && r.contains(n) ? n : r), e.setStartBefore(l[0]), o && e.collapse(!0)
}
if (e.endOffset == (e.endContainer.nodeType === document.TEXT_NODE ? e.endContainer.length : e.endContainer.childNodes.length)) {
var a = editor.getJQueryElem(e.endContainer);
if (a.length)
if (a.closest(".md-expand").length || a[0].hasAttribute("cid") || a[0].querySelector("[cid]") || a.closest(".md-image:not(.md-img-loaded)").length)(i = a.closest(".md-expand")).length && (a = i);
else {
if (n = a.closest("[cid]")[0], !(a = function t(e, n) {
if (!e.nextAll(":not(.md-meta, .md-content)").text().length) {
var i = e.parent();
return i.hasClass("[mdtype]") || i[0].contains(n) ? k(e) : t(i, n)
}
return k(e)
}(a, r.contains && r.contains(n) ? n : r)).length) return null;
e.setEndAfter(a[0])
}
}
} catch (t) {
console.warn(t)
}
return e
}(a) || a) && !a.collapsed), fastdom.mutate(function() {
$(".md-expand").removeClass("md-expand"), l.length ? F.call(this, l) : F.call(this, d), l.length && d.length && l.next().is(d) && !d.hasClass("md-img-loaded") && F.call(this, d, !0)
})
} else $(".md-expand").removeClass("md-expand");
if (p) this.editor.selection.deRange(a, !0, a);
else {
var g = window.getSelection().anchorNode;
g && (3 === g.nodeType || g.hasAttribute && g.hasAttribute("contenteditable")) && (a = a || this.editor.selection.getRangy(), this.editor.selection.deRange(a, !0, a)), a.commonAncestorContainer.parentElement && a.commonAncestorContainer.parentElement.classList.contains("ty-focusable-btn") ? a.commonAncestorContainer.parentElement.classList.add("selected") : y(g) && g.classList.add("selected")
}
$(this.editor.sessionStr).trigger("cursorChange", this.editor.styleBookmark)
} else c = this.editor.getMarkElem(), $(".md-expand").removeClass("md-expand"), c.length && s.isType(c.attr("mdtype"), s.TYPE.hr, s.TYPE.toc) && (this.editor.stylize.putBookmark(null, this.editor.stylize.buildBookmark(c)), $(this.editor.sessionStr).trigger("cursorChange", this.editor.styleBookmark))
}
}
function b(t, e) {
return i.extendRange(t, e)
}
function y(t) {
return t && t.classList && t.classList.contains("ty-focusable-btn")
}
},
isAutoCompleteShown: function() {
return this.autoCompleteShown
},
focusContainer: function(t) {
w.call(this, t)
}
};
var w = function(t) {
var e = t.closest("tr.md-end-block, li[cid]")[0],
n = t[0];
if (e && n) {
for (; e !== n && e.contains(n);) {
if (n.previousSibling && n.previousSibling.hasAttribute && n.previousSibling.hasAttribute("cid")) return !1;
n = n.parentElement
}
e.classList.add("md-focus-container")
}
},
F = function(t, e) {
e || $(".md-focus-container").removeClass("md-focus-container"), t.length && w(t.addClass("md-expand").trigger("expand").closest("[cid]").addClass("md-focus"))
};
function k(t) {
var e = t.parent().closest("[md-inline]");
return e.length ? k(e) : t.closest("[md-inline]")
}
var x = function(t, e, n, r) {
function a(t) {
for (var e = 0; e < t.attributes.length; e++) s.isType(t.attributes[e].name, "cid", "contenteditable", "id", "for", "onerror", "onload") && t.removeAttributeNode(t.attributes[e]);
t.classList.remove("md-img-loaded"), t.classList.remove("md-img-error")
}
function l(t) {
for (var e = t.querySelectorAll("*"), n = 0; n < e.length; n++) a(e[n]);
a(t)
}
function f(t, e, n, r, o, a) {
if (t.length) {
var s, u = n.innerHtml,
c = t[0].cloneNode(!0),
f = document.createElement("div");
a = n.cursorDiff;
return f.innerHTML = u, c.querySelectorAll(".md-inline-math").forEach(function(t) {
t.textContent = t.rawText()
}), c.querySelectorAll(".md-expand").forEach(function(t) {
t.classList.remove("md-expand")
}), f.querySelectorAll(".md-inline-math").forEach(function(t) {
t.textContent = t.rawText()
}), l(c), l(f), c.innerHTML.replace(/\s*class=\"\"/gi, "") != f.innerHTML.replace(/\s*class=\"\"/gi, "") ? (t.html(u), n.mdlike ? t.attr("mdlike") != n.mdlike && t.attr("mdlike", n.mdlike) : t.attr("mdlike") && t.removeAttr("mdlike"), o.selection.clearGlobalColumn(), o.mathInline.brush(t[0], r, !0), s = !0) : (t.hasClass("unholdable") && t.removeClass("unholdable"), t.find(".math-jax-preprocess").length && o.mathInline.brush(t[0], r, !0)),
function(t, e, n, r, o) {
if (e.length && o.focusCid === r.cid) return t && (n && n.undo.unshift(i.utils.clone(t)), t.start = d(e, t.start), t.end = d(e, t.end), n && n.redo.push(i.utils.clone(t))), o.undo && o.undo.register(n), !0;
return !1
}(r, a, n.command, e, o) || s
}
}
function h(t, e, n, r, o) {
return n.blockChanged ? function(t, e, n, r, o) {
var a = n.cursorDiff || [];
return o.selection.clearGlobalColumn(), n.replaceCid ? (o.findElemById(n.replaceCid).replaceWith(n.html), o.refreshUnder(o.findElemById(n.replaceCid)[0])) : t.closest("p").replaceWith(n.html), n.toRemove && n.toRemove.forEach(function(t) {
o.findElemById(t).remove()
}), o.focusCid && o.focusCid !== e.cid || (o.focusCid = n.focus, o.focusCid && w(o.findElemById(o.focusCid)), r && (n.command.undo.unshift(i.utils.clone(r)), a.length && (r.start = d(a, r.start), r.end = d(a, r.end)), r.id = n.focus, r.startId = n.focus, r.endId = n.focus, r.start -= n.offset, r.end -= n.offset, n.command.redo.push(i.utils.clone(r))), o.undo.register(n.command)), !0
}(t, e, n, r, o) : f(t, e, n, r, o)
}
function d(t, e) {
var n = e;
for (var i in t) void 0 !== i && i <= e && (n += t[i]);
return n
}
try {
var m, v, p = t,
g = t;
if ("string" == typeof t ? p = this.editor.getNode(t) : g = p.id, !p) return;
if (s.isType(p, u.meta_block)) return;
if (c.CONST.NoInline.indexOf(p.get("type")) > -1) return;
if (p.get("children").length) return p.get("children").toArray().map(function(t) {
e && (e[t.id] = 1), x.call(this, t, e, n, r)
}, this), !0;
if (m = this.editor.findElemById(g), p.get("type") == u.def_footnote) {
var b = m.children(".md-def-content");
return v = b.rawText(), h(b, p, o.quickParse(v, this, p, !0), n, this.editor)
}
return v = m.rawText(), h(m, p, o.quickParse(v, this, p, r || !s.isType(p, u.paragraph), null, n), n, this.editor)
} catch (t) {
t.stack
}
},
_ = /:(\w+)$/;
n.exports = d
}), $__System.registerDynamic("2d", ["e", "12", "13", "2e", "2f", "30", "1b", "29", "14", "31"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("e"),
r = t("12"),
o = t("13"),
a = o.Node,
s = o.TYPE,
u = t("2e"),
c = t("2f"),
l = t("30").rangy,
f = t("1b"),
h = t("29"),
d = t("14"),
m = t("31"),
v = window.reqnode ? reqnode("electron").remote : null,
p = null,
g = {},
b = null,
y = "typora-copy-images-to",
w = "http://support.typora.io/Images/";
window.imgLastModified = Math.floor((new Date - 0) / 1e3), window.uploadImageQueue = new Set, window.moveImageQueue = new Set, window.imagePreLoadAfterMove = {};
function F(t, e, n) {
if (n && t && e) {
var i = n.clientHeight,
r = n.clientWidth;
i && r && (imagePreLoadAfterMove["file://" + t.replace(/^file:\/\//, "").replace(/\\/g, "/")] = {
src: e,
size: "height:" + i + "px;width:" + r + "px;"
})
}
}
function k(t, e) {
return t.replace(/(\(<?)((?:\([^)]*\)|[^()])*?)(>?[ \t]*((['"])(.*?)\5[ \t]*)?\))/, "$1" + e + "$3")
}
function x(t, e) {
return /src\s*=\s*['"]/.exec(t) ? t.replace(/(src\s*=\s*(["'])).+?(\2)/i, "$1" + e + "$3") : t.replace(/(src\s*=\s*)([^\s'"]+)(\s|$)/i, '$1"' + e + '"$3')
}
function _(t) {
var e = i("[data-origin-path=" + JSON.stringify(t) + "]");
e.length, uploadImageQueue.delete(t), moveImageQueue.delete(t), (n = e).removeClass("md-on-uploading").removeClass("md-on-moving"), n.find(".md-image-uploading-mask-wrapper").remove(), n.removeAttr("data-origin-path");
var n;
return e
}
var $ = {};
window.onImageDownloaded = function(t, e, n, i) {
var r = $[t];
r && (r.callbacks.map(function(t) {
t(e, n, i)
}), delete $[t])
};
function E(t, e, n, i) {
var r = c.applyUploadingStyle;
if (t.length) {
var o = t.find("img")[0];
loadedImgCache.remove(o.getAttribute("src") || ""), o.onload = null
}
return this.editor.brush.clearAndPause(!0), window.moveImageQueue.add(n), r(t, n, !0, !0), this.editor.brush.resume(), File.isMac ? function(t, e) {
if (e = e.replace(/^file:\/\//, ""), !/^\w+:/.exec(e)) try {
e = decodeURI(e)
} catch (t) {}
return new Promise(function(n, r) {
bridge.callHandler("images.copyImage", {
src: e,
folder: t,
fileNameDefined: i || !1
}, function(t) {
t.success ? n(t.msg) : r(t.msg)
})
})
}.call(this, e, n) : function(t, e) {
return new Promise(function(n, r) {
var o = reqnode("fs-extra"),
a = null;
function s(t, e, i) {
var a;
if (/^(http(s?))|(ftp):\/\//.exec(t)) ! function(t, e, n, i, r) {
var o = v.getCurrentWindow(),
a = reqnode("fs-extra"),
s = reqnode("path").dirname(e),
u = function(o, s, u) {
u && !/^image/.exec(u) ? i(t + " is not an image, mimeType is " + u) : "completed" === o ? (r && s != e ? a.renameSync(s, e) : e = s, n(e)) : i(o ? "Image download " + o : "")
};
$[t] ? $[t].callbacks.push(u) : $[t] = {
dest: e,
callbacks: [u]
}, v.app.download(o.webContents.id, t, s), setTimeout(function() {
$[t] && ($[t].callbacks.remove(u), $[t].callbacks.length || delete $[t]), i("Download timeout.")
}, 3e4)
}(t, e, n, r, i);
else if (a = /^data:image\/[^;]+;base64,/.exec(t)) {
var s = decodeURI(t.substr(a[0].length));
try {
s = decodeURI(s)
} catch (t) {}
o.writeFile(e, s, "base64", function(t) {
if (t) return r("Failed to copy image\n." + t.message);
n(e)
})
} else {
try {
t = decodeURI(t)
} catch (t) {}
o.copy(t, e, {
overwrite: i
}, function(t) {
if (t) return r("Failed to copy image\n." + t.message);
n(e)
})
}
}
var u, c = File.isWin ? "\\" : "/";
if (i) s(e, a = t, !0);
else {
if (/^data:/.exec(e)) {
if (!(u = (/^data:image\/([^;]+);base64,/.exec(e) || [])[1])) return n(e);
u = d.removeInvalidPathCh(function() {
var t = new Date;
t.setHours(t.getHours() - t.getTimezoneOffset() / 60);
var e = t.toUTCString();
return e.substr(0, e.length - 4)
}() + "." + u)
} else u = m.getFileNameFromPath(e), u = d.removeInvalidPathCh(u.replace(/\?([^./]*)$/, ""));
t = (t + c).replace(/[\/\\]{2}$/, c), a = t + u, o.access(a, o.R_OK, function(t) {
t || (a = function(t) {
var e = reqnode("path");
return t.replace(/(\.[^.\/\\]+?$)/, "") + "-" + (new Date - 0) + e.extname(t)
}(a)), s(e, a, !1)
})
}
})
}.call(this, e, n)
}
function C(t, e, n) {
if (e = this.resolveImagePath(e), !t[0]) return this.editor.selection.buildUndo();
var r = this.editor,
o = r.selection.getRangy(),
a = t[0].querySelector(".md-content").textContent,
u = t.attr("md-inline") == s.imgtag ? x(a, e) : k(a, e),
c = r.selection.buildUndo(o),
l = f.makeEmptyCommand(c),
h = i.extend({}, c),
d = u.length - a.length,
m = r.findNodeByElem(t.closest("[cid]"));
r.undo.endSnap(!0);
var v = t.find(".md-content")[0];
o && v && o.comparePoint && o.comparePoint(v, 1) < 0 && (h.start += d), o && v && o.comparePoint && o.comparePoint(v, 2) < 0 && (h.end += d), l.undo.push(f.buildReplaceUndo(m)), t.find(".md-content").text(u), r.store(m, !0);
var p = r.findElemById(m.cid);
return r.brush.brushNode(m.cid), p.removeClass("md-expand"), r.undo.exeCommand(h), (o = r.selection.getRangy()) && i(o.commonAncestorContainer).closest(".md-image").length && (h = r.imgEdit.selectComponent(!0, !0)), l.redo.push(f.buildReplaceUndo(m)), l.redo.push(h), r.undo.register(l), h
}
function A(t, e, n, r, o) {
var a = this;
t && t.length && n && E.call(this, t, e, n, r).then(function(e) {
t = _(n), F(e, n, t.find("img")[0]), C.call(a, t, e)
}, function(e) {
t = _(n), e && console.error(e), e && !o && setTimeout(function() {
h.showNotification(i.localize.getString("Failed to Copy Image to Target Folder.") + " <code>" + d.escape(e) + "</code>", !0)
}, 500)
})
}
var S = r.Model.extend({
initialize: function(t) {
var e = this;
this.editor = t, i(t.sessionStr).on("mousemove", ".md-image>.md-meta", function(t) {
fastdom.measure(function() {
t.offsetX - t.target.offsetLeft < 20 && t.offsetY < 30 ? this.nextElementSibling && this.nextElementSibling.getAttribute("src").trim().length && fastdom.mutate(function() {
this.classList.add("md-show-hint")
}, this) : fastdom.mutate(function() {
this.classList.remove("md-show-hint")
}, this)
}, this)
}).on("mouseleave", ".md-image>.md-meta", function() {
fastdom.mutate(function() {
this.classList.remove("md-show-hint")
}, this)
}).on("click", "img", function(e) {
var n = i(e.target).closest(".md-image").addClass("md-expand");
if (n.length) {
var r = l.createRange();
r.moveToBookmark({
containerNode: n.children(".md-meta")[0],
start: 2,
end: 2 + (e.target.getAttribute("alt") || "").length
}), t.selection.setRange(r, !0)
}
}).on("btn-action", ".md-image-input-src-btn", function(e) {
i("#ty-tooltip").hide();
var n = document.createRange();
n.setStart(this.parentElement, 0), n.setEnd(this.parentElement, 0), i(this).remove(), t.selection.setRange(n, !0)
}).on("click btn-action", ".md-image-pick-file-btn", function(t) {
return i("#ty-tooltip").hide(), e.insertLocalImage(), !1
}).on("cursorChange", function(e, n) {
n && -1 != n.style.inline.indexOf("image") || !document.querySelector("#user-context-menu.show") || t.contextMenu.hide("#user-context-menu")
}), i(".context-menu").on("click", "[data-key='select-img-target'] a", function() {
File.editor.contextMenu.hide(), e.copyToSelectedFolderAction()
}).on("click", "[data-key='upload-img'] a", function() {
File.editor.contextMenu.hide(), e.uploadAction()
}).on("click", "[data-key='move-img-to-target'] a", function() {
File.editor.contextMenu.hide(), e.copyToTargetFolderAction()
}).on("click", "[data-key='reveal-img-in-finder'] a", function() {
if (File.editor.contextMenu.hide(), File.isNode) {
var t = i(".md-expand.md-img-loaded");
if (!t) return;
var n = e.getAbsolutePath(t.attr("data-src"));
n && v.shell.showItemInFolder(n)
}
}), this.registerBridge()
},
registerBridge: function() {
if (File.isMac) {
var t = this;
bridge.registerHandler("images.fetchImageLocalStorageFolder", function(e, n) {
n(t.getTagetImageStorageFolder() || null)
}), bridge.registerHandler("images.replaceImageMap", function(e, n) {
t.replaceImageMap(e.updateMap, e.allSuccess), n && n()
}), bridge.registerHandler("images.tagetImageStorageFolderExcludeSelf", function(e, n) {
n && n(t.getTagetImageStorageFolder(!0))
}), bridge.registerHandler("images.doSetImageCopyToFolder", function(e, n) {
t.doSetImageCopyToFolder(e), n && n()
}), bridge.registerHandler("images.doSetImageCopyToIPic", function(e, n) {
t.doSetImageCopyToFolder("ipic", !0), n && n()
}), bridge.registerHandler("images.doRemoveImageCopyToFolder", function(e, n) {
t.doRemoveImageCopyToFolder(), n && n()
}), bridge.registerHandler("images.doSetImageRootPath", function(e, n) {
t.doSetImageRootPath(e), n && n()
})
}
},
getLocalRootUrlForInsert: function() {
return this.editor.docMenu.getLocalRootUrl() || File.option.useRelativePathForImg && m.getCurrentFileFolderPath() || ""
},
getSrcFromDom: function(t, e) {
return t ? t.dataset.isDataSrc && t.querySelector("img") ? t.querySelector("img").getAttribute("src") : e ? this.getAbsolutePath(t.dataset.src) : t.dataset.src : ""
},
getAbsolutePath: function(t, e) {
if (!t) return t;
var n = this.getRealSrc(t).replace(/^file:\/\//, "");
return File.isWin && (n = n.replace(/^[\/\\]+/, "")), e && /^[\/\\]/.exec(n) ? "file://" + n : n
},
getRealSrc: function(t) {
if (!t) return t;
if (t = d.decodeFromEscapedURL(t), /^data:/.exec(t)) return t;
if (/^\/\//.exec(t)) return "http:" + t;
function e(t, e) {
return "file://" + m.normalizePath(t.replace(/^file:\/\//, "").replace(/\/$/, "") + "/" + e.replace(/^\//gi, ""))
}
try {
if (/^(file|ftp|https?):(\/\/|\\\\)/gi.exec(t)) return t;
if (File.isNode) {
var n = reqnode("path"),
i = this.editor.docMenu.getLocalRootUrl();
return File.isWin || !/^\//.exec(t) || i ? "file://" + n.resolve(this.editor.docMenu.getLocalRootUrl() || m.getCurrentFileFolderPath() || "", t.replace(/^\s*(\\\\|\/)/, "")) : "file://" + t
}
return /^(\/)|(\/\/)|(\\\\)|([a-z]+\:\\\\)/gi.exec(t) ? e(this.editor.docMenu.getLocalRootUrl() || "", t || "") : e(m.getCurrentFileFolderPath() || "", t || "")
} catch (t) {}
return t
},
updateImgRef: function(t) {
var e = this.editor.brush.inline;
i("[data-ref='" + d.escape(t) + "']").each(function() {
var t = (this.querySelector(".md-content") || {}).textContent;
void 0 !== t && i(this).replaceWith(e.output(t))
})
},
willUpdateImgRef: function(t) {
t && (b && clearTimeout(b), g[t] = !0, p = p || new Date, new Date - p > 200 ? setTimeout(function() {
Object.keys(g).map(this.updateImgRef, this)
}.bind(this), 10) : b = setTimeout(function() {
Object.keys(g).map(this.updateImgRef, this)
}.bind(this), 300))
},
refreshLocalImg: function() {
if (!File.inBusyMode) {
var t = Math.floor((new Date - 0) / 1e3);
i(".md-image img").each(function() {
var e = this.getAttribute("src");
if (/^file:/i.exec(e)) {
var n = e.replace(/\?lastModify=\d+$/, ""),
i = n + "?lastModify=" + imgLastModified;
failImgCache.remove(i), loadedImgCache.remove(i), this.setAttribute("src", n + "?lastModify=" + t), this.dataset.localRefresh = !0, this.onload = onImageLoadedFunc, this.onError = onImageErrorFunc
}
}), imgLastModified = t
}
},
updateLocalRootUrl: function() {
var t = this.editor.docMenu.getLocalRootUrl() || "";
if (this.editor.localRootUrl != t) {
for (var e = document.querySelectorAll("[md-inline='image']"), n = 0; n < e.length; n++) {
var r = (u = e[n]).querySelector("img");
if (u.getAttribute("data-src") != r.getAttribute("src")) {
var a = i.parseHTML(c.decorate({
type: o.TYPE.image,
markdown: u.textContent,
alt: r.getAttribute("alt"),
href: u.getAttribute("data-src")
}))[0];
u.parentElement.replaceChild(a, u)
}
}
var s = document.querySelectorAll("[data-ty-watch-src]");
for (n = 0; n < s.length; n++) {
var u, l = (u = s[n]).dataset.src;
u.getAttribute("src") != l && (u.src = this.getAbsolutePath(l, !0), "VIDEO" == u.tagName && this.editor.htmlBlock.resetVideoDom(u))
}
}
},
selectComponent: function(t, e) {
var n = this.editor.selection.getRangy(),
r = i(n.startContainer).closest("[md-inline='image']"),
o = r.text(),
a = n.getBookmark(r[0]),
s = o.indexOf("]"),
u = f.makeEmptyCommand(this.editor.selection.buildUndo());
t ? (a.start = s + 2, a.end = o.length - 1) : (a.start = 2, a.end = s), n.moveToBookmark(a), this.editor.selection.setRange(n, !0);
var c = this.editor.selection.buildUndo();
return u.redo.push(c), !e && this.editor.undo.register(u), c
},
buildImageMapToUpload: function() {
M = {};
for (var t, e, n = document.querySelectorAll(".md-image.md-img-loaded"), i = n.length, r = 0; r < i; r++) T(e = (t = n[r]).querySelector("img").getAttribute("src") || "") && (e = e.replace(/\?[^.\\\/]*$/, ""), M[e] = M[e] || [], M[e].push(t));
return Object.keys(M)
},
replaceImageMap: function(t, e) {
var n = f.makeEmptyCommand(this.editor.selection.buildUndo()),
r = this.editor,
o = new Set;
if (Object.keys(t).forEach(function(e) {
if (M[e]) {
var u = t[e];
M[e].forEach(function(t) {
t.querySelector("img").src = u, t.hasAttribute("data-src") && t.setAttribute("data-src", u);
var e, c, l = r.findNodeByElem(i(t).closest("[cid]")),
h = t.getAttribute("md-inline");
if (!o.has(l) && a.isType(h, s.image, s.imgtag) && (o.add(l), n.undo.push(f.buildReplaceUndo(l))), e = t.querySelector(".md-content").textContent, h == s.image) c = k(e, u), t.querySelector(".md-content").textContent = c;
else if (h == s.imgtag) c = x(e, u), t.querySelector(".md-content").textContent = c;
else if (h == s.refimg) {
var d = /^!\[((?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)\]\s*\[([^\]]*)\]/.exec(e),
m = (d[2] || d[1]).replace(/\s+/g, " "),
v = r.nodeMap.link_list.getNodeByRef(m);
if (o.has(v)) return;
o.add(v), n.undo.push(f.buildReplaceUndo(v)), v.set("href", u), r.findElemById(v.cid).replaceWith(v.toHTML())
}
})
}
}), o.forEach(function(t) {
t.get("type") !== s.def_link && r.store(t, !0), n.redo.push(f.buildReplaceUndo(t))
}), n.redo.push(r.selection.buildUndo()), r.undo.register(n), e) {
var u = Object.keys(t).length;
h.showNotification(i.localize.getString("Successfully uploaded {0} images.").format(u), !0, i.localize.getString("Undo"), function() {
r.undo.undo()
})
}
},
insertLocalImage: function() {
if (!File.isLocked) {
var t = this.editor;
File.isNode ? function() {
var t = reqnode("electron").remote,
n = t.getCurrentWindow();
t.dialog.showOpenDialog(n, {
filters: [{
name: "Images",
extensions: ["png", "jpg", "jpeg", "bmp", "svg", "tiff", "webp", "gif"]
}],
properties: ["openFile", "multiSelections"],
buttonLabel: "Select"
}, e)
}() : File.isMac && window.bridge.callHandler("images.insertLocalImage", e)
}
function e(e) {
e && 0 != e.length && t.imgEdit.doInsertFromURLs(e)
}
},
shouldTriggerMove: function(t, e) {
if (void 0 === e && (e = this.getTagetImageStorageFolder()), !t) return !1;
if (/^\s*(https?|ftp):\/\//.exec(t)) return File.option.applyImageMoveForWeb;
if (File.option.applyImageMoveForLocal && !/^data:/.exec(t)) {
var n = this.getAbsolutePath(t);
if (0 != n.indexOf(e) || n.substring(e.length + 1).match(/[\\\/]/g)) return !0
}
return !1
},
tryMoveImageDom: function(t, e, n) {
if (e && t.length) {
var i = this.getSrcFromDom(t[0]);
this.shouldTriggerMove(i, e) && (File.isMac && "ipic" == e ? this.uploadAction(t, !0) : A.call(this, t, e, i, void 0, n))
}
},
prepImageMove: function(t, e) {
var n = this;
return new Promise(function(r, o) {
if (e) return r();
function a(t) {
t && alert(t.message || t), o()
}
if (File.isMac) {
if (void 0 === t && (t = n.getTagetImageStorageFolder()), "ipic" == t) return r();
bridge.callHandler("images.prepImageMove", {
folder: folder,
slient: folder == n.getTagetImageStorageFolderFromSetting()
}, function(t) {
"success" != t ? a(t) : r()
})
} else {
var s = reqnode("fs-extra"),
u = !1;
n.getTagetImageStorageFolder(!0) && (u = !0), void 0 === t && (t = n.getTagetImageStorageFolder()),
function(t, e) {
var n = reqnode("fs-extra");
return new Promise(function(r, o) {
if (!e) return r();
n.stat(t, function(e) {
if (!e) return r();
if ("ENOENT" != e.code) return o(e.message);
var n = i("#image-create-folder-confirm").find("#image-create-folder-target").text(t).end().modal({
backdrop: "static",
keyboard: !1
});
File.isLocked = !0, n.off("mousedown", ".image-create-folder-dialog-yes, .image-create-folder-dialog-no, .image-create-folder-dialog-help, .close").one("mousedown", ".image-create-folder-dialog-yes", function() {
n.modal("hide"), File.isLocked = !1, File.freshMenu(), r()
}).one("mousedown", ".image-create-folder-dialog-no", function() {
n.modal("hide"), File.isLocked = !1, File.freshMenu(), o(!1)
}).one("mousedown", ".close", function() {
n.modal("hide"), File.isLocked = !1, File.freshMenu(), o(!1)
}).on("mousedown", ".image-create-folder-dialog-help", function() {
v.shell.openExternal(w)
})
})
})
}(t, u).then(function() {
s.ensureDir(t, function(t) {
t ? a(t) : r()
})
}, a)
}
})
},
tryMoveImageInRange: function(t, e) {
var n = this.editor,
r = this.getTagetImageStorageFolder();
if (r) {
this.editor.brush.clearAndPause();
var o = t.getNodes([document.ELEMENT_NODE], function(t) {
return "image" == t.getAttribute("md-inline")
});
if (!o.length && t) {
var a = t.commonAncestorContainer.parentElement;
a && "image" == a.getAttribute("md-inline") && (o = [t.commonAncestorContainer.parentElement])
}
o.length && this.prepImageMove(r).then(function() {
o.forEach(function(t) {
n.imgEdit.tryMoveImageDom(i(t), r, e)
})
}), this.editor.brush.resume()
}
},
generateAlt: function(t) {
return (m.getFileNameFromPath(t) || "").replace(/(^\.)|(\.[^.]+$)/g, "")
},
doInsertFromURL: function(t, e, n) {
var r = t;
function o() {
return File.editor.imgEdit.generateAlt(t)
}
function a() {
var t = window.getSelection(),
e = "";
return !File.editor.sourceView.inSourceMode && t.startOffset > 0 && (e = " "), e
}
function s(t) {
var e = this.editor,
n = e.getMarkElem();
if (!n.length || !e.stylize.canContainInline(n)) return !1;
u.backspaceHandler(e, null, "delSelection");
var r, s = o(),
c = a(),
l = e.getNode(n.attr("cid")),
h = this.resolveImagePath(t),
d = c + "![" + s + "](" + h + ")",
m = e.selection.getRangy();
if (!m) return null;
if ((r = i(m.startContainer).closest("[md-inline='image']")).length) return window.moveImageQueue.add(t), C.call(this, r, t), r.attr("data-src", h), this.selectComponent(!0), r;
var v = m.getBookmark(n[0]).start,
p = f.makeEmptyCommand();
p.undo.push(e.selection.buildUndo()), u.insertInlineText(e, l, d, v, p, !0);
var g = e.findElemById(l.cid);
return e.brush.brushNode(l.cid), g.removeClass("md-expand"), m.moveToBookmark({
containerNode: g[0],
start: v + d.length,
end: v + d.length
}), (r = i(m.startContainer).closest(".md-image")).find("img").attr("src", "file://" + t), e.undo.register(p), window.getSelection(), r
}
if (t = this.resolveImagePath(t))
if (/\.(png|jpg|jpeg|svg|gif|bmp|webp|tiff)$/gi.exec(t)) {
var c, l = r,
h = this,
d = this.editor,
v = this.getTagetImageStorageFolder();
if (function() {
var e, n = o(),
s = a(),
c = d.selection.getRangy();
c && (e = i(c.startContainer).closest("[md-inline='image']")).length && ! function(t) {
if (t.startContainer.parentElement.classList.contains("md-image-after-src") && t.startContainer.textContent.length == t.startOffset) return !0
}(c) ? (C.call(this, e, r, !0), this.selectComponent(!0)) : u.pasteHandler(this.editor, s + "![" + n + "](" + t + ")", !0, !0)
}.call(this), this.shouldTriggerMove(t, v) && v)
if (File.isMac && "ipic" == v) bridge.callHandler("images.iPicValidateBeforeUpload", function(t) {
t && (h.editor.brush.clearAndPause(), c = s.call(h, l), h.uploadAction(c), h.editor.brush.resume())
});
else if (v && !e) return l = m.normalizePath(l), this.editor.brush.clearAndPause(), c = s.call(this, l), h.prepImageMove(v, File.isMac).then(function() {
A.call(h, c, v, l)
}), void this.editor.brush.resume()
} else if (/\.(flv|mov|mp4|avi|ogg|webm)$/gi.exec(t)) this.doInsertVideoFromURL(t);
else {
if (!/\.(wave|mp3|flac|aac)$/gi.exec(t)) return !1;
this.doInsertAudioFromURL(t)
}
},
doInsertVideoFromURL: function(t) {
var e = '<video src="{url}"></video>'.replace("{url}", t);
u.pasteHandler(this.editor, e, !1, !0)
},
doInsertAudioFromURL: function(t) {
var e = '<audio src="{url}"></audio>'.replace("{url}", t);
u.pasteHandler(this.editor, e, !1, !0)
},
doInsertFromURLs: function(t, e) {
var n = this.editor;
t.forEach(function(t, i) {
i > 0 && n.UserOp.insertParagraph(!1, n), n.imgEdit.doInsertFromURL(t, !1, e)
})
},
resolveImagePath: function(t) {
if (/^\/\//.exec(t)) return "https://" + t;
if (/^[^:]+:\/\//.exec(t)) return t;
var e = this.getLocalRootUrlForInsert(),
n = m.getCurrentFileFolderPath();
if (e && e.length) {
var i = d.getRelativePath(e, t);
e == n && (i = i.replace(/^\s*(\\\\|\/)/, "")), t = (!i.match(/^\.[\/\\]/) && this.editor.docMenu.getLocalRootUrl() ? "/" : "") + i
} else {
if (!File.option.useRelativePathForImg || !n || 0 !== t.indexOf(n)) return t;
t = t.substring(n.length).replace(/^\//, "").replace(/\\/, "/")
}
return File.isWin && (t = t.replace(/[\/\\]{1,2}/g, "/")), t
},
getTagetImageStorageFolder: function(t) {
var e = this.editor.docMenu.getValueInMeta(y);
if (e && !File.editor.sourceView.inSourceMode) {
if (File.option.allowImageUpload && "ipic" == e.toLowerCase()) return "ipic";
var n = m.getCurrentFileFolderPath();
if (n) return /[\\/]$/.exec(n[n.length - 1]) || (n += "/"), m.normalizePath(n + e.replace(/\${filename}/g, (File.getFileName() || "").replace(/\.[^.\/\\]+$/, "")), !0)
}
return t ? null : this.getTagetImageStorageFolderFromSetting()
},
getTagetImageStorageFolderFromSetting: function() {
if ("ipic" == File.option.defaultImageStorage) return "ipic";
var t = m.getCurrentFileFolderPath();
if (this.cachedFileImageStorage) return this.cachedFileImageStorage;
var e = File.option.defaultImageStorage;
if (t && (/[\\/]$/.exec(t[t.length - 1]) || (t += "/")), "folder" == e) {
if (t) return this.cachedFileImageStorage = m.normalizePath(t.replace(/[\\/]$/, ""), !0), this.cachedFileImageStorage
} else if ("assert" == e) {
if (t) return this.cachedFileImageStorage = m.normalizePath(t + "assets", !0), this.cachedFileImageStorage
} else if ("per-file-assert" == e) {
if (t) return this.cachedFileImageStorage = m.normalizePath(t + File.getFileName().replace(/\.[^.\/\\]+$/, "") + ".assets", !0), this.cachedFileImageStorage
} else if (e && !a.isType(e, "ipic")) {
var n = File.getFileName();
if (e.indexOf("${filename}") > -1) {
if (!n) return null;
e = e.replace(/\${filename}/g, n.replace(/\.[^.\/\\]+$/, ""))
}
/^\.\.?[\\\/]/.exec(e) ? t && (this.cachedFileImageStorage = m.normalizePath(t + e, !0)) : this.cachedFileImageStorage = m.normalizePath(e, !0)
}
return this.cachedFileImageStorage || ""
},
onFileMoved: function() {
"per-file-assert" != !File.option.defaultImageStorage && (this.cachedFileImageStorage = void 0)
},
revealInFinder: function() {
var t = i(".md-expand.md-img-loaded img").attr("src").replace(/^file:\/\//, "").replace(/\?lastModify=.+/, "");
JSBridge.showInFinder(t)
},
t: function(t, e, n, i) {
A.call(this, t, e, n, i)
},
copyToSelectedFolderAction: function() {
var t = i(".md-expand.md-img-loaded");
if (t) {
var e = this,
n = e.getSrcFromDom(t[0], !0),
r = m.getFileNameFromPath(n);
if (/^data:/.exec(n)) {
var o = (/^data:[\\\/]*image\/([^;]+)/.exec(n) || [])[1];
r = t.find("img").attr("alt") || new Date + "", o && (r = r + "." + o)
}
File.isMac ? bridge.callHandler("images.selectImageSavePath", {
defaultName: r || "",
absolutePath: n || ""
}, function(i) {
i && e.t(t, i, n, !0)
}) : v.dialog.showSaveDialog({
title: "Copy and update image srouce to..",
defaultPath: r
}, function(i) {
i && e.t(t, i, n, !0)
})
}
},
copyToTargetFolderAction: function() {
this.editor.brush.clearAndPause();
var t = i(".md-expand.md-img-loaded");
if (t) {
var e = this.getSrcFromDom(t[0], !0),
n = this.getTagetImageStorageFolder(),
r = this;
e && this.prepImageMove(n, File.isMac).then(function() {
r.t(t, n, e)
}), this.editor.brush.resume()
}
},
uploadAction: function(t, e) {
if (t = t || i(".md-expand.md-img-loaded")) {
var n = this;
File.isMac && bridge.callHandler("images.iPicValidateBeforeUpload", function(r) {
if (r) {
var o = n.getRealSrc(t.attr("data-src")).replace(/^file:\/\//, "");
(function(t, e) {
return this.editor.brush.pause(), window.uploadImageQueue.add(e.replace(/^file:\/\//, "")), c.applyUploadingStyle(t, e, !1), e = e.replace(/^file:\/\//, ""), File.isWin && (e = e.replace(/^[\/\\]+/, "")), this.editor.brush.resume(), new Promise(function(t, n) {
bridge.callHandler("images.upload", e, function(e) {
e.success ? t(e.msg) : n(e.msg)
})
})
}).call(n, t, o).then(function(i) {
e || F(i, o, t), t = _(o), C.call(n, t, i)
}, function(e) {
t = _(o), C.call(n, t, o), e && setTimeout(function() {
i("#md-notification").html("<p style='padding-right: 100px;'>" + i.localize.getString("Failed to upload image. Error Message:") + " <code>" + d.escape(e) + "</code><span class='btn-default btn-xs btn ok-btn' style='right: 40px;position: absolute;bottom: 8px;'>" + i.localize.getString("Close") + "</span></p>").show()
}, 500)
})
}
})
}
},
contextMenuItems: function(t) {
var e = (t.getAttribute("src") || "").replace(/\?(.+)$/, ""),
n = [],
i = this.getTagetImageStorageFolder();
i && "ipic" != i && (i = i.replace(/[\\\/]$/, "") + (File.isWin ? "\\" : "/"));
var r = d.escapeURL(i);
if (i && "ipic" != i && (0 != e.replace(/^file:\/\//, "").indexOf(r) || e.replace(/^file:\/\//, "").substring(r.length + 1).match(/[\\\/]/g))) {
var o = d.getFolder(i);
o && n.push("copyImgToTarget-" + o.replace(/\|/g, ""))
}
return n.push("copyImgToSelect"), File.isMac && ("ipic" == i ? n.unshift("uploadImg") : n.push("uploadImg")), /^file:\/\//.exec(e) && n.unshift("revealImgInFinder"), n
},
afterUserInsertImage: function(t) {
var e = (t.getAttribute("src") || "").replace(/\?(.+)$/, "");
if (e != this.lastUrl && t.parentElement && t.parentElement.contains(window.getSelection().anchorNode)) {
var n = [],
r = this.editor,
o = this.getTagetImageStorageFolder();
if (o && "ipic" != o) {
o = o.replace(/[\\\/]$/, "") + (File.isWin ? "\\" : "/"), e = e.replace(/^file:\/\//, ""), File.isWin && (e = e.replace(/^[\/\\]+/, ""));
var a = d.escapeURL(o);
if (0 != e.replace(/[\\]/g, "/").indexOf(a) || e.substring(a.length + 1).match(/[\\\/]/g)) {
var s = d.getFolder(o);
s && n.push({
label: "Copy to %@",
key: "move-img-to-target",
variable: s
})
} else this.lastUrl = e
}
if (n.push({
label: "Copy Image to...",
key: "select-img-target"
}), File.isMac && File.option.showiPic && ("ipic" == o ? n.unshift({
label: "Upload via iPic",
key: "upload-img"
}) : n.push({
label: "Upload via iPic",
key: "upload-img"
})), n.length) {
var u = r.selection.getRangy(),
c = i(u.endContainer).closest("[md-inline='image']");
u && c.length && !c.hasClass("md-on-moving") && !c.hasClass("md-on-uploading") && r.contextMenu.showCustom(n, "image")
}
}
},
toggleCopyToFolder: function() {
var t = reqnode("electron").remote,
e = t.getCurrentWindow(),
n = t.dialog,
r = this,
o = this.getTagetImageStorageFolder(!0),
a = m.getCurrentFileFolderPath();
if (File.refreshImageCopyStatus(!0), !File.isLocked && !File.editor.sourceView.inSourceMode)
if (o) this.doRemoveImageCopyToFolder(!1);
else {
if (!a) return void n.showMessageBox(e, {
title: i.localize.getString("Document must be saved first.", "Panel"),
message: i.localize.getString("Typora will copy newly inserted image to folder by selected relative path, so please save the file first.", "Panel"),
defaultId: 0,
cancelId: 0,
buttons: [i.localize.getString("OK")]
});
n.showOpenDialog(e, {
defaultPath: m.getCurrentFileFolderPath(),
title: i.localize.getString("Select Container Folder"),
properties: ["openDirectory", "createDirectory"],
buttonLabel: i.localize.getString("Select")
}, function(t) {
t && 0 != t.length && r.doSetImageCopyToFolder(t[0])
})
}
},
toggleUseImageRootPath: function() {
var t = reqnode("electron").remote,
e = t.getCurrentWindow(),
n = t.dialog,
r = this.editor.docMenu.getLocalRootUrl(),
o = this.editor;
r ? this.editor.docMenu.removeProperty("typora-root-url") : n.showOpenDialog(e, {
defaultPath: m.getCurrentFileFolderPath(),
title: i.localize.getString("Select Container Folder"),
properties: ["openDirectory", "createDirectory"],
buttonLabel: i.localize.getString("Select")
}, function(t) {
t && 0 != t.length && o.imgEdit.doSetImageRootPath(t[0])
})
},
doSetImageCopyToFolder: function(t, e) {
t = e && File.isMac ? "ipic" : d.getRelativePath(m.getCurrentFileFolderPath(), t, !0), this.editor.docMenu.writeProperty(y, t)
},
doSetImageRootPath: function(t) {
this.editor.docMenu.writeProperty("typora-root-url", d.getRelativePath(m.getCurrentFileFolderPath(), t, !0)), this.refreshLocalImg()
},
doRemoveImageCopyToFolder: function(t) {
return this.editor.docMenu.removeProperty(y, t)
}
});
function T(t) {
return !!/^\s*(file|data):/.exec(t)
}
var M = {};
n.exports = S
}), $__System.registerDynamic("32", [], !0, function(t, e, n) {
"use strict";
this || self;
if (window.reqnode) {
var i = reqnode("fs"),
r = reqnode("path"),
o = {},
a = function(t) {
return r.join(r.dirname(t), ".~" + r.basename(t))
},
s = function(t) {
this.file = t, this.callbacks = [], this.nextData = null, this.nextCallbacks = []
};
s.prototype.write = function(t, e) {
var n = this;
function r(t) {
for (; this.callbacks.length;) this.callbacks.shift()(t);
e(t), o()
}
function o() {
if (n.lock = !1, n.nextData) {
var t = n.nextData;
n.callbacks = n.nextCallbacks, n.nextData = null, n.nextCallbacks = [], n.write(t, n.callbacks.pop())
}
}
function s(t, n) {
for (; this.callbacks.length;) this.callbacks.shift()(t);
e(null, n), o()
}
this.lock ? (e && this.nextCallbacks.push(e), this.nextData = t) : (this.lock = !0, i.stat(this.file, function(e, n) {
if (!e && n) {
var o = a(this.file);
i.writeFile(o, t, function(e) {
i.writeFile(this.file, t, function(t) {
if (t) return r.call(this, t), void i.unlink(o, function() {});
i.unlink(o, s.bind(this))
}.bind(this))
}.bind(this))
} else(function() {
i.writeFile(this.file, t, function(t) {
t ? r.call(this, t) : s.call(this, null, !0)
}.bind(this))
}).call(this)
}.bind(this)))
}, e.writeFile = function(t, e, n) {
t = r.resolve(t), o[t] = o[t] || new s(t), o[t].write(e, n)
}, e.writeFileSync = function(t, e) {
i.writeFileSync(a(t), e), i.renameSync(a(t), t)
}
}
}), $__System.registerDynamic("33", ["34", "12", "e", "14", "1b", "13", "35", "29", "31", "36", "37", "32"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("34"),
r = (t("12"), t("e")),
o = t("14"),
a = t("1b"),
s = (a.SnapFlag, t("13")),
u = s.Node,
c = s.TYPE,
l = (t("35"), t("29")),
f = t("31"),
h = t("36"),
d = t("37"),
m = f.ChangeCounter,
v = (f.ChangeType, t("32")),
p = window.reqnode ? reqnode("electron").remote : null,
g = p ? p.app : window.app,
b = {
MAX_FILE_SIZE: 2e6,
option: {
indentByTab: !1,
indentSize: 2,
codeIndentSize: 4,
enableInlineMath: !0,
autoNumberingForMath: !1,
enableHighlight: !1,
enableSubscript: !1,
enableSuperscript: !1,
enableDiagram: !1,
copyMarkdownByDefault: !1,
showLineNumbersForFence: !1,
useRelativePathForImg: !1,
autoCorrectMisspell: !1,
noPairingMatch: !1,
autoPairExtendSymbol: !1,
enableAutoSave: !1,
scrollWithCursor: !1,
expandSimpleBlock: !1,
allowImageMove: !0,
allowImageUpload: !0,
headingStyle: 0,
ulStyle: 0,
olStyle: 0,
strictMarkdown: !1,
preferCRLF: !1,
sortType: 0,
sidebarTab: "",
useTreeStyle: !1,
noLineWrapping: !1,
prettyIndent: !1,
defaultImageStorage: null,
applyImageMoveForWeb: !1,
applyImageMoveForLocal: !0,
ignoreLineBreak: !1,
preLinebreakOnExport: !1,
hideBrAndLineBreak: !1,
indentFirstLine: !1,
monocolorEmoji: !1,
useFsQueue: !0,
isLocked: !1,
notGroupByFolder: !1,
convertSmartOnRender: !1,
remapUnicodePunctuation: !1,
smartDash: !1,
smartQuote: !1,
userQuotesArray: null,
autoResizeIframe: !0,
blockHTML: !0,
imageExportFontSize: "24px",
imageExportWidth: 640,
sendAnonymousUsage: !0,
presetSpellCheck: "auto",
sidebarWidth: null,
caseSensitive: !1,
wholeWord: !1,
fileSearchCaseSensitive: !1,
fileSearchWholeWord: !1,
wordCountDelimiter: 0,
expandFolders: !1,
customWordsPerMinute: !1,
wordsPerMinute: 382
},
needSaveState: !1,
fileHasModified: !1,
readOption: function() {
window._options && (b.option = r.extend(b.option, window._options)), b.option.headingStyle = b.option.headingStyle || 0, b.option.ulStyle = b.option.ulStyle || 0, b.option.olStyle = b.option.olStyle || 0, b.option.wordCountDelimiter = b.option.wordCountDelimiter || 0, b.option.sortType = b.option.sortType || 0, b.option.indentSize = b.option.indentSize || 2, b.option.codeIndentSize = b.option.codeIndentSize || 4, _options.mountFolder && b.setMountFolder(_options.mountFolder), b.isMac && b.setupSafari(), b.setIndentSize(b.option.indentSize), window.innerWidth < 540 && (b.option.sidebarTab = null), b.option.useCustomFontSize && (document.body.parentElement.style.fontSize = b.option.customFontSize + "px"), b.setCanCollapsePinnedOutline(b.option.canCollapseOutlinePanel), 3 == b.option.headingStyle && document.body.classList.add("use-varible-width-setex"), b.option.noLineWrapping && r("#write").addClass("fences-no-line-wrapping"), b.setIndentFirstLine(b.option.indentFirstLine, !0), b.setHideBrAndLineBreak(b.option.hideBrAndLineBreak || !1, !0), b.isFocusMode = b.option.isFocusMode, b.isTypeWriterMode = b.option.isTypeWriterMode, b.setIgnoreLineBreak(b.option.ignoreLineBreak || !1), b.option.monocolorEmoji && document.body.classList.add("monocolor-emoji"), i.setTagsContext({
appVersion: b.option.appVersion,
instance: b.option.instance,
arch: window.process ? process.arch : "x64",
lang: b.option.userLocale
}), i.setExtraContext({
setting: b.option
}), i.setUserContext({
id: b.option.uuid
})
},
setupSafari: function() {
try {
var t = Object.defineProperty({}, "passive", {
get: function() {
b.option.passiveEvents = !0
}
});
window.addEventListener("test", null, t)
} catch (t) {}
},
shouldRemapPunctuation: function() {
return b.option.remapUnicodePunctuation || !b.option.convertSmartOnRender && (b.option.smartQuote || b.option.smartDash)
},
setIndentFirstLine: function(t, e, n) {
b.option.indentFirstLine = t, b.option.indentFirstLine ? b.editor.writingArea.classList.add("first-line-indent") : b.editor.writingArea.classList.remove("first-line-indent"), e && (JSBridge.menu.update("Edit→Whitespace and Line Breaks→Indent first line of paragraphs", {
state: b.option.indentFirstLine
}), h.forceRefreshMenu()), n && JSBridge.putSetting("indentFirstLine", t)
},
setHideBrAndLineBreak: function(t, e, n) {
b.option.hideBrAndLineBreak = t, b.option.hideBrAndLineBreak ? document.body.classList.add("hide-br-and-line-break") : document.body.classList.remove("hide-br-and-line-break"), e && (JSBridge.menu.update("Edit→Whitespace and Line Breaks→Visible <br/>", {
state: !b.option.hideBrAndLineBreak
}), h.forceRefreshMenu()), n && JSBridge.putSetting("hideBrAndLineBreak", t)
},
setIgnoreLineBreak: function(t, e, n) {
(t = 1 == t || "true" == t) ? document.body.classList.add("ignore-line-break"): document.body.classList.remove("ignore-line-break"), b.option.ignoreLineBreak != t && (t ? r(".md-softbreak").html("<span contenteditable='false'></span>\n") : (r(".md-softbreak-emptyline").replaceWith("&#10;<span md-inline='emptyline' class='md-emptyline'>&#10;</span>"), r(".md-softbreak [contenteditable]").remove())), b.option.ignoreLineBreak = t, n && JSBridge.putSetting("ignoreLineBreak", t), e && (JSBridge.menu.update("Edit→Whitespace and Line Breaks→Preserve single line break", {
state: !t
}), h.forceRefreshMenu())
},
setIndentSize: function(t) {
b.option.indentSize = (t || 2) - 0, b.option.indentSize < 0 ? (b.option.indentSize = 2, b.option.indentByTab = !0) : b.option.indentByTab = !1
},
setEditor: function(t) {
b.isLocked = b.isMac && g.document.isLocked(), b.editor = t, b.isMac || (b.changeCounter = new m)
},
onFileOpened: function() {
if (b.isNode) {
reqnode("electron").ipcRenderer.send("addBackup", {
path: b.filePath,
mountFolder: b.e,
encode: b.encode,
useCRLF: b.useCRLF
}), b.needSaveState = !1
}
},
getFilePathUseNode: function() {
if (b.isNode) {
var t = p.getCurrentWindow(),
e = p.app.getDocumentController().getDocumentFromWindowId(t.id).path;
b.e || (b.e = t.initMountFolder, t.initMountFolder = void 0)
}
return e
},
setLineEnding: function(t, e, n) {
if (t != b.useCRLF || n) {
b.useCRLF = t;
var i = {
"Edit→Line Endings→Windows Line Endings (CRLF)": {
state: b.useCRLF,
enabled: !b.isLocked
},
"Edit→Line Endings→Unix Line Endings (LF)": {
state: !b.useCRLF,
enabled: !b.isLocked
}
};
if (JSBridge.menu.update(i), e) {
b.sync();
var r = b.editor.getMarkdown();
r = (r.split(/\r?\n/g) || [r]).join(b.useCRLF ? "\r\n" : "\n"), b.reloadContent(r), b.backupWindow()
}
}
},
loadInitData: function() {
function t(t) {
var e = b.editor;
e.reset(t), e.writingArea.focus(), void 0 != t && t.trim().length ? (e.selection.lockScroll(), e.selection.jumpIntoElemEnd(r("[cid]").last())) : (r(e.sessionStr + ">*:first-child").addClass("md-focus"), e.selection.jumpTop())
}
if (b.isMacWK) bridge.callHandler("document.loadInitData", function(e) {
var n = e[0],
i = e[1];
i && i.nodeMap ? b.restoreEditStateFromData(i, !1, !0) : t(n)
});
else {
var e = b.getDocumentSnap();
(e || {}).nodeMap ? (d.setFileTitle(b.getFilePathUseNode(), e.fileEncode), b.restoreEditStateFromData(e, !1, !0)) : b.recoverFromBackup() || b.getContent().then(t), onFileOpened()
}
},
recoverFromBackup: function() {
if (!b.isNode) return !1;
var t = b.getCurrentDocByNode(),
e = t && t.popBackupState();
if (!e || !e.content) return !1;
if (b.setLineEnding(e.useCRLF), d.setFileTitle(e.path || "", e.encode), b.e = e.mountFolder, b.editor.reset(e.content), b.updateChangeCount(f.ChangeType.NSChangeDone), e.path) {
var n = a.makeEmptyCommand();
n.redo.push(a.buildAllDoc(b.editor.nodeMap)), b.fs.readFile(e.path, e.encode || "utf8", function(t, e) {
t || (n.undo.push({
type: "initSrc",
src: e
}), b.changeCounter.doneStack.unshift(f.ChangeType.NSChangeCleared), b.editor.undo.register(n, !0, void 0, !0))
})
}
return !0
},
getContent: function(t, e) {
b.setLineEnding(b.option.preferCRLF);
var n;
if (b.isMac) return n = g.document.content || "", n = b.tryEnterOversize(n), b.setLineEnding(n.indexOf("\r\n") > -1 && !/[^\r]\n/.exec("a" + n)), n;
if (b.isNode) {
var i = t;
try {
if (i = t || b.getFilePathUseNode()) {
var o = b.fs.readFileSync(i),
a = e;
return o.length > b.MAX_FILE_SIZE ? (b.unsupported = !0, n = "", b.tryEnterOversize(null, !0)) : (a = a || f.getItemInDB("[encode]" + i) || f.detectEncodeByNode(o), n = f.getContentFromBuffer(o, a), b.setLineEnding(n.indexOf("\r\n") > -1 || !(n.indexOf("\n") > -1) && b.option.preferCRLF)), d.setFileTitle(i, a), n
}
d.setFileTitle()
} catch (t) {
if (b.option.slientOpenFailure = b.option.slientOpenFailure || p.getCurrentWindow().slientOpenFailure, !b.option.slientOpenFailure) {
var s = t.message || "";
debugMode || (s = s.splits && s.splits(/\n/)[0] || s), p.dialog.showErrorBox(r.localize.getString("Failed to load file"), s), b.editor && b.editor.library && b.editor.library.isFileTabShown() && b.editor.library.refreshPanelCommand()
}
if (b.option.slientOpenFailure = !1, d.setFileTitle(""), d.watchFileChange(null), i) {
var u = g.getDocumentController().getDocument(i);
u && u.switchToUntitled()
}
return ""
}
}
return ""
},
setContent: function(t, e) {
b.unsupported || (b.isMac ? g.document.content = t : e && b.isNode && g.documentController.setContentForWindow(t, p.getCurrentWindow().id), b.editor.tryEnterBusyMode(t))
},
getMountFolder: function() {
return b.e
},
setMountFolder: function(t) {
b.e = t
},
sync: function(t, e, n) {
if (!b.unsupported) {
var i;
if (b.editor.sourceView && b.editor.sourceView.inSourceMode) i = b.editor.sourceView.cm.getValue(b.useCRLF ? "\r\n" : "\n"), !n && b.setContent(i, e), (b.isMacLegacy || b.isMacWK) && t && b.isDocumentEdited() && b.editor.sourceView.onSave();
else {
b.editor.store(null, !0), isInputComponent(document.activeElement) && r(document.activeElement).trigger("change").trigger("inline-change");
try {
r(".md-focus").closest(".unholdable").length || b.editor.autoRemoveUnholdable()
} catch (t) {
Reporter.error(t, {
level: "warning"
}), console.sendError(t.stack)
}
b.setContent(b.editor.getMarkdown(), e)
}
}
},
isActiveWindow: function() {
if (b.isMac) return g.controller.isActiveWindow();
if (!b.isNode) return !0;
var t = p.getCurrentWindow();
if (t.id === (b.getCurrentDocByNode().activeWindow || {}).id) return !0;
t.isFocused() && (console.warn("error found on windows focus management"), window.onWindowFocus())
},
shouldTriggerSyncChange: function() {
if (b.isMac) return g.controller.shouldTriggerSyncChange();
if (b.isNode) {
var t = b.getCurrentDocByNode();
return b.isActiveWindow() && t.windows.size > 1
}
},
getCurrentDocByNode: function() {
return b.isNode ? g.documentController.getDocumentFromWindowId(p.getCurrentWindow().id) : null
},
saveUseNode: function(t, e, n) {
if (b.isActiveWindow() && !b.unsupported) {
b.sync();
var i, o = b.getFilePathUseNode(),
a = o,
s = b.fileEncode || "utf8",
u = b.editor.getMarkdown(),
c = !1;
if (!o && b.filePath && !n) {
o = b.filePath;
var h = reqnode("path").dirname(o);
reqnode("fs").existsSync(h) || (o = void 0), c = !0
}
if ((o || !n) && b.isNode) {
var m = reqnode("iconv-lite"),
p = reqnode("electron").ipcRenderer;
try {
i = m.encode(u, s)
} catch (t) {
y()
}
0 == i.length && "" != u && y(), o && !e ? (b.inSavingProcess = b.inSavingProcess || !e, !c && g.sendEvent("willSave", o), v.writeFile(o, i, function(e, n) {
if (e) return Reporter.error(e, {
fingerprint: ["steno2", "writeFile"]
}), void F(e.stack, e.code);
(c || n) && d.watchFileChange(o);
try {
if (i.length && 0 == b.fs.statSync(o).size) return F("Failed to write file"), void Reporter.error("Failed to write file: File size is 0 but data is not", {
fingerprint: ["steno2", "afterWriteFile"]
});
var r = b.fs.statSync(o);
b.lastModifiedDate = r.mtimeMs
} catch (t) {
return F(t.stack, t.code), void Reporter.error(t)
}
b.lastSaved = new Date;
var a = b.getCurrentDocByNode();
c && a.rename(o), a.setLastSync(b.lastSaved - 0), b.changeCounter.isDocumentEdited() && b.updateChangeCount(b.ChangeType.NSChangeAutosaved), t && t(e), c || g.sendEvent("didSave", {
path: o,
summary: u.substr(0, 200),
lastModifiedDate: b.lastModifiedDate
}), b.inSavingProcess = !1, b.needSaveState = !0, f.refreshTitlebarText(), b.backupWindow()
}), b.updateChangeCount(b.ChangeType.NSChangeAutosaved)) : n || (f.showSaveDialog(t || void 0), p.send("countly_add_event", {
key: "saveFile"
}))
}
}
function y() {
console.log("swith to utf8 encode"), i = Buffer.from(u), b.fileEncode = "utf8"
}
function w(t) {
var e = a ? [r.localize.getString("Save As", "Menu"), r.localize.getString("Open File Location", "Menu"), r.localize.getString("Cancel")] : [r.localize.getString("Save As", "Menu"), r.localize.getString("Cancel")];
l.showDialog({
title: r.localize.getString("Save File Failed"),
message: t,
buttons: e,
type: "error",
callback: function(t) {
0 == t ? ClientCommand.saveAs() : t == e.length - 2 && ClientCommand.openFileLocation()
}
})
}
function F(t, e) {
n || (w("EPERM" == e ? r.localize.getString("The file is read-only, or you do not have right permissions to modify the file.") : t), console.sendError("fs write failed -- \n" + (e || t))), b.updateChangeCount(b.ChangeType.NodeSaveFailed), b.inSavingProcess = !1, b.backupWindow()
}
},
recordEvent: function(t, e) {
b.isNode && ipc.send("countly_add_event", {
key: t,
segment: e
}), b.isMac && bridge.callHandler("controller.recordEvent", {
key: t,
segment: JSON.stringify(e || {})
})
},
updateChangeCount: function(t) {
if (!b.unsupported)
if (b.editor.sourceView && b.editor.sourceView.inSourceMode) b.isMac ? t == b.ChangeType.NSChangeAutosaved ? g.document.updateChangeCount(t) : t == b.ChangeType.NSChangeCleared ? g.document.updateChangeCount(t) : g.document.isDocumentEdited() || g.document.updateChangeCount(b.ChangeType.NSChangeDone) : b.changeCounter.updateChangeCount(t);
else {
b.needsUpdateSnap();
var e = null;
b.isMac ? (g.document.updateChangeCount(t), e = {
"Edit→Undo": {
enabled: b.editor.undo.hasUndo()
},
"Edit→Redo": {
enabled: b.editor.undo.hasRedo()
}
}) : (b.changeCounter.updateChangeCount(t), t === b.ChangeType.NSChangeAutosaved ? w = !1 : (w = !0, b.needSaveState = !0), b.isNode && (e = {
"Edit→Undo": {
enabled: b.editor.undo.hasUndo()
},
"Edit→Redo": {
enabled: b.editor.undo.hasRedo()
}
}, releasePrintWin_(), releaseCaptureWin_())), JSBridge.menu.update(e)
}
},
setDefaultImageStorage: function(t) {
b.option.defaultImageStorage = t, b.editor.imgEdit && (b.editor.imgEdit.cachedFileImageStorage = null)
},
exitOversize: function() {
var t = document.querySelector("#ty-oversize-body");
t.style.display || (t.style.display = "none"), b.unsupported = !1
},
tryEnterOversize: function(t, e, n) {
if (b.isMac && !g.document.currentFilePath()) return t;
if (f.bindOversizePlaceholder(), e || t.length > b.MAX_FILE_SIZE) {
if (document.querySelector("#ty-oversize-body").style.display = "", b.unsupported = !0, b.isNode) {
var i = b.getCurrentDocByNode();
i && !n && i.addSnap(null)
}
return ""
}
return t
},
onSwitchDocumentTarget: function(t, e) {
b.editor.brush.clearAndPause(), b.editor.searchPanel.closePanel(), b.fileHasModified = !1, b.editor.focusCid = null, b.exitOversize(), b.isMac && b.editor.library.markCurrentFile();
var n = b.tryEnterOversize(b.getContent(e)),
i = b.editor.sourceView.inSourceMode;
if (b.setDefaultImageStorage(b.option.defaultImageStorage), b._onInitParse = !0, t && b.isNode) {
var o = b.getCurrentDocByNode();
o.shouldReadFromDisk() && (t = null, o.addSnap(null))
}
t && t.nodeMap && t.undoRedo ? b.restoreEditStateFromData(t, void 0, !0) : (b.changeCounter && b.changeCounter.reset(), b.editor.undo.reset(), b.editor.nodeMap.reset(!1, !0), b.editor.reset(i ? "" : n)), i && b.editor.sourceView.setValue(n, !0);
var a = null,
s = 0;
if ((!t || !t.nodeMap) && b.editor.undo.reset(), b.isMac) {
var u = g.controller.getLastCursor() || [];
a = JSON.parse(u[1] || "null"), s = u[2] || 0
}
b.freshMenu(), b.editor.refresh(!1), b.editor.imgEdit.preFileImageStorage = void 0, b._onInitParse = !1, b.getMountFolder() || b.editor.library.onRootChanged(), a ? b.editor.undo.exeCommand(a) : window._hasSwitchCallback || (window.getSelection().removeAllRanges(), r("content").scrollTop(s), window._hasSwitchCallback = !1), b.backupWindow(), b.editor.brush.restart(), f.refreshTitlebarText()
},
getDocumentSnap: function() {
if (b.isMac) return g.document.snap;
if (b.isNode) {
var t = b.getCurrentDocByNode();
if (t) return t.getSnap()
}
},
restoreEditStateFromData: function(t, e, n) {
if (!t || !t.undoRedo || !t.nodeMap) return !0;
if (t.timeStamp == (b.isMac ? g.controller.contentSnapRestoredTime : b.contentSnapRestoredTime)) return !0;
b.fileHasModified = !0;
var i = null,
o = b.editor,
a = o.sourceView && o.sourceView.inSourceMode,
u = !1;
if (b._onInitParse = !0, b.editor.focusCid = null, b.editor.lastCursor = null, o.nodeMap.restoreFromJson(JSON.parse(t.nodeMap)), o.undo.restoreFromJson(JSON.parse(t.undoRedo)), b.setLineEnding(t.useCRLF), b._onInitParse = !1, b.isNode && (u = b.getCurrentDocByNode().shouldReadFromDisk(), t.content = t.srcContent = b.getCurrentDocByNode().getContent(), o.tryEnterBusyMode(t.content)), n && o.fences && o.fences.onLeaveDocument(), a) e && (i = o.sourceView.cm.getScrollInfo().top), b.reloadContent(t.srcContent, !0, !1, !1, !0), t.srcHist && (o.sourceView.cm.doc.clearHistory(), o.sourceView.cm.doc.setHistory(JSON.parse(t.srcHist))), t.fromSourceMode || b.reloadContent(t.content, !1, !1, !1, n || b.isMac && !g.document.isDocumentEdited()), e && o.sourceView.cm.scrollTo(0, i);
else if (e && (i = r("content").scrollTop()), t.fromSourceMode ? b.reloadContent(t.srcContent, !1, !1, !1, !0, n) : u || (r(o.sessionStr).html(s.NodeCollectionUtils.toHTML(o.nodeMap.blocks)), n || (o.focusCid = void 0, o.refresh())), e) {
if ("object" == typeof e) try {
o.undo.exeCommand(e)
} catch (t) {}
r("content").scrollTop(i)
}
if (b.isMac && (g.controller.contentSnapRestoredTime = t.timeStamp), b.isNode) {
if (b._needsUpdateSnap = !1, b.contentSnapRestoredTime = t.timeStamp, b.changeCounter.reset(t.changeCounter), u) return b.reloadContent(b.getContent(), !1, !1, !0, !1, n), b.updateChangeCount(b.ChangeType.NSChangeAutosaved), void(b.fileHasModified = !1);
d.setFileTitle(b.filePath, t.fileEncode), b.editor.spellChecker && b.editor.spellChecker.reset(!0)
}
n || (b.freshMenu(), b.editor.refresh(!1, !0));
var c = b.editor.wordCount;
c && c.update()
},
needsUpdateSnap: function() {
b.isMac ? g.document.needsUpdateSnap() : b._needsUpdateSnap = !0
},
backupDocumentSnap: function() {
b.isMac && g.document.backupDocumentSnap(), b.isNode && !b._onInitParse && b.buildDocumentSnap()
},
backupLastCursor: function() {
if (b.isMac) {
var t = b.editor.sourceView.inSourceMode;
bridge.callHandler("window.setLastCursor", {
cursor: JSON.stringify(b.editor.selection.buildUndo() || null),
offset: t ? 0 : r("content").scrollTop()
})
}
},
buildDocumentSnap: function() {
if (!b.unsupported && (b.sync(!1, !0), b.isMac && g.document.buildDocumentSnap(e()), b.isNode)) {
var t;
if (!b._needsUpdateSnap) return;
b._needsUpdateSnap = !1, (t = b.getCurrentDocByNode()) && t.shouldSaveSnap() && t.addSnap(e())
}
function e() {
var t = b.editor.sourceView.inSourceMode,
e = {
nodeMap: JSON.stringify(b.editor.nodeMap.storeToJson()),
undoRedo: JSON.stringify(b.editor.undo.storeToJson()),
timeStamp: new Date - 0,
cursorPos: JSON.stringify(b.editor.selection.buildUndo()),
useCRLF: b.useCRLF
};
return e.scrollOffset = t ? 0 : r("content").scrollTop(), t && (e.fromSourceMode = !0, e.srcHist = JSON.stringify(b.editor.sourceView.cm.doc.getHistory())), b.isNode && (e.fileEncode = b.fileEncode, e.changeCounter = b.changeCounter.clone(), b.contentSnapRestoredTime = e.timeStamp), b.isMac && (g.controller.contentSnapRestoredTime = e.timeStamp), e
}
},
presentedItemChanged: function(t) {
if (b.isActiveWindow() && !b.unsupported)
if (console.log("presentedItemChanged"), t && clientHanlderOnPresentationMoved(), b.isNode) {
if (b.filePath) {
if (b.inSavingProcess) return
} else b.filePath = b.getFilePathUseNode(), b.fileName = f.getFileNameFromPath(b.filePath);
b.filePath && b.fs.stat(b.filePath, function(t, e) {
if (e && !(b.lastModifiedDate >= e.mtimeMs)) {
b.lastModifiedDate = e.mtimeMs, console.log("presentedItemChanged did happen");
var n = b.changeCounter.isDocumentEdited();
if (function(t) {
var e, n = r("content").scrollTop();
if (t) {
if (b.isMac ? e = g.document.getDataFromFile(!0) : b.isNode && (e = b.getContent(b.filePath, b.fileEncode)), b.unsupported) {
if (b.isNode) {
var i = b.getCurrentDocByNode();
i && i.enterOversize()
}
return
}
b.reloadContent(e, !1, !1, !0), b.updateChangeCount(b.ChangeType.NSChangeAutosaved);
var o = b.editor.sourceView;
if (o.inSourceMode) {
var a = o.cm.getScrollInfo().top,
s = o.cm.listSelections();
o.setValue(e), o.cm.setSelections(s), o.cm.scrollTo(0, a)
}
setTimeout(function() {
b.setContent(e), r("content").scrollTop(n)
}, 0)
} else b.updateChangeCount(b.ChangeType.NSChangeReadOtherContents)
}(!n || confirm(r.localize.getString("File content is changed by external applications. Reload content from disk ?"))), n) {
p.getCurrentWindow().focus()
}
}
})
} else b.isMac && (g.document.isDocumentEdited() && !confirm(r.localize.getString("File content is changed by external applications. Reload content from disk ?")) || g.document.refreshContentFromDisk())
},
reloadWithEncoding: function(t) {
if (b.isNode && b.filePath && t != b.fileEncode) {
f.setItemInDB("[encode]" + b.filePath, t);
var e = b.getContent(b.filePath, t);
b.reloadContent(e), b.updateChangeCount(b.ChangeType.NSChangeCleared), b.backupWindow()
}
},
reloadContent: function(t, e, n, i, r, o) {
if (!b.unsupported && b.isMac && i && (t = b.tryEnterOversize(t), b.unsupported && g.document.enterOversize()), !b.unsupported) {
var u, c, l = a.makeEmptyCommand(),
f = b.editor.sourceView && b.editor.sourceView.inSourceMode;
b.isMac && b.setLineEnding(b.useCRLF), f || o || (b.editor.store(), l.undo.push(b.editor.selection.buildUndo())), b.editor.focusCid = null, b.editor.lastCursor = null, l.undo.push(a.buildAllDoc(b.editor.nodeMap, i));
var h;
if (f && (h = b.editor.sourceView.cm.getScrollInfo().top, c = b.editor.sourceView.cm.getCursor(), b.editor.sourceView.setValue(t, !0, i || r ? "fromDisk" : "begin")), f && i || (b.editor.nodeMap.reset(), (u = s.Node.parseFrom(t, b.editor.nodeMap, {
skips: {
old_code: !1
}
}))[1].map(function(t) {
t.set("attachTo", b.editor.nodeMap)
}), l.redo.push(a.buildAllDoc(b.editor.nodeMap, i)), b.editor.tryEnterBusyMode(t), f ? (b.editor.sourceView.renderedHTML = u[0], b.editor.undo.register(l, r)) : (b.editor.writingArea.innerHTML = u[0], b.editor.runAllScript())), f) {
var d = b.editor.sourceView.cm.getInputField();
return d.setSelectionRange && d.setSelectionRange(0, 0), b.editor.sourceView.cm.setCursor(c), void(i && void 0 !== h && b.editor.sourceView.cm.scrollTo(0, h))
}
if (i) {
var m = b.editor.undo.lastRegisteredOperationCommand(),
v = m && m.undo.last();
v && "reload" == v.type && v.reloadFromDisk && (l.undo = [v], b.editor.undo.removeLastRegisteredOperationCommand())
}
e || b.editor.undo.register(l, r), o || (e ? (b.editor.undo.reset(), b.updateChangeCount(b.ChangeType.NSChangeAutosaved)) : window.getSelection().removeAllRanges(), setTimeout(function() {
b.editor.refresh(), b.editor.selection.scrollAdjust()
}, n ? 500 : 0))
}
},
copy: function() {
b.editor.UserOp.copyHandler(b.editor)
},
delete: function() {
isInputComponent(document.activeElement) || b.editor.UserOp.backspaceHandler(b.editor, null, "Backspace")
},
editActive: function() {
var t = b.editor;
t.undo.prepCursorSnap();
var e = t.findElemById(t.focusCid);
u.isType(e.attr("mdtype"), c.html_block, c.math_block) && e.find(".md-rawblock-container").trigger("startedit")
},
deleteActive: function() {
var t = b.editor.getMarkElem(),
e = b.editor.findNodeByElem(t),
n = b.editor.UserOp.backToParagraph(editor, e, !0);
b.editor.undo.register(n)
},
cut: function() {
if (b.isLocked) return !1;
b.editor.refocus(void 0, !0), b.editor.UserOp.copyHandler(editor, null), b.editor.UserOp.backspaceHandler(editor, null, "delSelection")
},
pasteAsPlainText: function() {
r(b.editor.sessionStr).trigger("pasteAsPlainText")
},
lock: function() {
b.isLocked = !0, b.freshLock()
},
unlock: function() {
b.isLocked = !1, b.freshLock()
},
toggleSourceMode: function() {
b.editor.sourceView.inSourceMode ? (b.editor.sourceView.hide(), b.editor.library.recoverSidebar()) : (b.editor.library.tmpHideSidebar(), b.editor.sourceView.show()), b.freshMenuWithDeplay()
},
isFocusedOnWriteDiv: function() {
return r(document.activeElement).closest("#write").length > 0
},
getCurBlockType: function() {
try {
if (document.activeElement.hasAttribute && document.activeElement.hasAttribute("tabindex")) return r(document.activeElement).closest("[mdtype]").attr("mdtype") || "";
if (rangy.getSelection().rangeCount) {
var t = b.editor.selection.getRangy();
return r(t.commonAncestorContainer).closest("[mdtype]").attr("mdtype") || ""
}
} catch (t) {}
return ""
},
freshLock: function(t) {
b.editor && (void 0 !== t && (b.isLocked = t), r("content input, selector").prop("readOnly", b.isLocked || !1), r(".CodeMirror").each(function() {
this.CodeMirror && (this.CodeMirror.options.readOnly = b.isLocked || !1)
}), b.isLocked ? (b.editor.tableEdit.unfocusAll(), r("[contenteditable=true]").attr("locked", "true").attr("contenteditable", "false"), r(b.editor.sessionStr).blur(), r(".md-expand").removeClass("md-expand")) : r("[locked='true']").attr("locked", "false").attr("contenteditable", "true"), r("#md-searchpanel input").prop("readOnly", !1), b.freshMenu(), b.editor && b.editor.sourceView && b.editor.sourceView.inSourceMode && b.editor.sourceView.cm.focus())
},
setTheme: function(t) {
b.colorBrightness = 1;
function e() {
var t = (window.getComputedStyle(document.body).backgroundColor.match(/[\d.]+/gi) || []).map(function(t) {
return t - 0
});
void 0 !== t[3] && null !== t[3] || (t[3] = 1);
function e(t) {
var e = Number(t).toString(16).toUpperCase();
return 1 == e.length ? "0" + e : e
}
t.length && (b.isMac ? (t[0] + t[1] + t[2] + t[3] == 0 && (t = [255, 255, 255, 0]), bridge.callHandler("window.setBackground", t)) : JSBridge.putSetting("backgroundColor", (n = t[0], i = t[1], r = t[2], "#" + e(n) + e(i) + e(r))), b.colorBrightness = (299 * t[0] + 587 * t[1] + 114 * t[2]) / 256e3);
var n, i, r;
if (b.isMac) {
var o = null;
"true" != (window.getComputedStyle(document.body).getPropertyValue("--typora-center-window-title") || "").trim() && document.body.classList.contains("pin-outline") && (o = document.querySelector("#typora-sidebar").getBoundingClientRect().width), bridge.callHandler("window.setTitlebarTextMarginLeft", o)
}
}
var n = function() {
setTimeout(e, 1e3), b.editor.refresh(!0), b.isFocusMode && b.editor.updateFocusMode(!1), b.isTypeWriterMode && b.editor.setTypeWriterMode(!0, !0)
};
if (b.isMac) {
var i = document.getElementById("theme_css"),
o = i.getAttribute("href"),
a = "http://typora-theme";
if (t = (t = t || b.option.theme || "github").replace(/\s*([A-Z])/g, "-$1").replace(/^-/, "").toLowerCase(), b.option.useCustomFontSize) {
var s = (b.option.customFontSize || 16) + "";
document.body.parentElement.style.fontSize = s + "px"
} else document.body.parentElement.style.fontSize = "";
(o = (/([^\\\/]+)\.css$/.exec(o) || [])[1]) != t ? r.get(a + "/" + t + ".css", function() {
i.setAttribute("href", a + "/" + t + ".css")
}).then(function() {
setTimeout(n, 20)
}) : setTimeout(e, 20), document.querySelector("#base_user_css").setAttribute("href", a + "/base.user.css"), document.querySelector("#theme_user_css").setAttribute("href", a + "/" + t + ".user.css")
} else if (b.isNode) {
t = (t || b.option.theme || "").replace(/\.css$/, "");
var u = b.option.userDataPath,
c = b.isWin ? "\\" : "/";
r("#theme_css").attr("href", [u, "themes", t + ".css"].join(c)), setTimeout(n, 20), document.querySelector("#base_user_css").setAttribute("href", [u, "themes", "base.user.css"].join(c)), document.querySelector("#theme_user_css").setAttribute("href", [u, "themes", t + ".user.css"].join(c)), b.isMacNode && g.setting.refreshThemeMenu()
}
document.body.style.backgroundColor = "", document.body.style.setProperty("--bg-color", "")
},
getFileName: function(t) {
if (b.isMac) {
var e = g.document.currentFilePath(),
n = g.document.currentFolderPath(),
i = void 0;
return e && n && (i = e.replace(n, "").replace(/^\//g, "")), i || (t ? b.getSuggestedFileName() : void 0)
}
return b.fileName || (t ? b.getSuggestedFileName() : void 0)
},
getSuggestedFileName: function(t) {
if (b.fileName) return b.fileName.replace(/\.[^.]+$/, "");
if (t) {
var e = b.getFileName();
if (e) return e.replace(/\.[^.]+$/, "")
}
var n, i, a = "",
s = "";
try {
(i = b.editor.docMenu.getMetaNode()) && (s = b.editor.docMenu.getValueInMeta("date", i) || "", s = (/\d+-\d+-\d+/g.exec(s) || /\d+\/\d+\/\d+/g.exec(s) || [""])[0], a = (a = b.editor.docMenu.getValueInMeta("title", i) || "").replace(/(^\s*("|'))|(("|')\s*)/gi, "").replace(/\s+(.)/gi, "-$1").toLocaleString(), a = s && a ? [s, a].join("-") : a), 0 != a.trim().length && "-" != a || (n = r(r("#write h1, #write h2, #write h3")[0]), b.editor.sourceView.inSourceMode ? (a = (a = b.editor.getMarkdown()).substr(0, a.indexOf("\n")) || a).length > 60 && (a = a.substr(0, a.indexOf(".")) || a) : n.length ? a = b.editor.UserOp.getDisplayText(n).replace(/\r?\n/gi, "") : (a = (a = (n = r(r("[cid]:not(.md-meta-block)")[0])).length ? b.editor.UserOp.getDisplayText(n) : "").substr(0, a.indexOf("\n")) || a).length > 60 && (a = a.substr(0, a.indexOf(".")) || a)), a.length > 120 && (a = a.substr(0, 120))
} catch (t) {}
return 0 == a.trim().length && (a = r.localize.getString("Untitled", "Front")), o.removeInvalidPathCh(a.trim()) || "Untitled"
},
setCanCollapsePinnedOutline: function(t) {
t ? document.body.classList.remove("no-collapse-outline") : document.body.classList.add("no-collapse-outline"), this.editor && this.editor.nodeMap && this.editor.nodeMap.toc && this.editor.nodeMap.toc.updateHTML()
},
refreshImageCopyStatus: function(t, e) {
t ? (y && clearTimeout(y), y = setTimeout(function() {
h.doRefreshImageCopyStatus(e)
}, 500)) : h.doRefreshImageCopyStatus(e)
},
isDocumentEdited: function() {
return b.isNode ? b.changeCounter.isDocumentEdited() : b.isMacWK ? bridge.callSync("document.isDocumentEdited") : b.isMac ? g.document.isDocumentEdited() : void 0
},
backupWindow: function() {
if (b.isNode)
if (b._onInitParse) b.needSaveState = !1;
else try {
if (!b.needSaveState || !b.editor.brush.timerID || !b.isActiveWindow()) return;
var t = b.fileHasModified && b.changeCounter.isDocumentEdited();
if (!t && b.changeCounter.isDiscardableUntitled() && !b.e) return;
t && b.option.enableAutoSave && (b.saveUseNode(null, null, !0), t = b.changeCounter.isDocumentEdited());
var e = {
path: b.filePath,
encode: b.encode,
hasUnsaved: t,
scrollPos: r("content").scrollTop(),
useCRLF: b.useCRLF,
syncDate: new Date - 0,
mountFolder: b.e,
content: null
};
t && (b.editor.store(null, !0), e.content = b.editor.getMarkdown());
return reqnode("electron").ipcRenderer.send("addBackup", e), b.needSaveState = !1, e
} catch (t) {
console.sendError(t.stack)
}
}
},
y = null,
w = !1,
F = function() {
b.editor.brush.timerID && b.isActiveWindow() && w && (w = !1, d.saveToRecover(b.editor.getMarkdown()))
};
b.ChangeType = f.ChangeType, b.isMacLegacy = b.isMac = void 0 !== window.app, b.isNode = void 0 !== window.reqnode, b.isMacNode = b.isNode && "darwin" == process.platform, b.isMacOrMacNode = b.isMac || b.isMacNode || b.isMacLegacy, b.isNodeHtml = window.isOnWindowHtml, b.isWin = b.isNode && "win32" == process.platform, b.isLinux = b.isNode && "linux" == process.platform, b.isUnixNode = b.isLinux || b.isMacNode, b.FileInfoPanel = d, b.backupVersionWorker = F, b.freshMenu = h.freshMenu, b.freshMenuWithDeplay = h.freshMenuWithDeplay, b.bindMenu = h.bindMenu, b.MenuHelper = h;
var k = navigator.userAgent.toLowerCase();
b.isSafari = b.isMac || k.indexOf("safari/") > -1 && -1 == k.indexOf("chrome"), b.startAutoSaveAndBackupService = function() {
if (b.isNode) {
p.getCurrentWindow().on("blur", b.backupWindow);
var t = g.setting.config || {},
e = Number.parseFloat(t.autoSaveTimer || 3);
e && !Number.isNaN(e) || (e = 3), setInterval(b.backupWindow, 60 * e * 1e3), setInterval(F, 6e5)
}
}, b.isNode && (b.fs = reqnode("fs"), b.startAutoSaveAndBackupService()), n.exports = b
}), $__System.registerDynamic("38", ["12", "14", "1c", "26", "1f", "13", "29"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("12"),
r = t("14"),
o = t("1c"),
a = t("26"),
s = t("1f"),
u = t("13"),
c = t("29"),
l = u.Node,
f = u.TYPE,
h = /[A-Za-z_\\u00C0-\\u024f]/i;
function d(t, e) {
return new RegExp(r.escapeRegExp(t) + (e.wholeWord ? "(?![A-Za-z_\\u00C0-\\u024f])" : ""), e.caseSensitive ? "g" : "gi")
}
var m = null;
function v(t) {
if (t) {
var e = t.initPos;
if (!e && t.curSelection)
if (t.curSelection.isCm) e = t.curSelection;
else {
var n = o.createRange(),
i = t.curSelection;
if (!i.parentElement) return;
n.selectNode(i), (i = $(i).closest("[cid]")[0]) && (e = n.getBookmark(i)), e && (e.cid = i.getAttribute("cid"))
}
return e || null
}
return null
}
var p = i.Model.extend({
initialize: function(t) {
this.editor = t, this.curSel = null, this.searchTimer, this.caseSensitive = File.option.caseSensitive, this.wholeWord = File.option.wholeWord, this.bindEvents()
},
bindEvents: function() {
var t, e = this,
n = !1,
i = a.map;
!File.isMac && !File.isNode && a("command+f, ctrl+f", function(t) {
e.showPanel(), t.preventDefault()
}), !File.isMac && !File.isNode && a("command+h, ctrl+h", function(t) {
e.showPanel(!0), t.preventDefault()
}), $(document.body).on("keydown", function(t) {
var n = event.keyCode || event.which;
if ("Esc" == i[n] && e.isOpen) return e.closePanel(), !1
}).on("mouseup", ".md-search-hit", function() {
e.closePanel(!1, $(this))
}).on("mouseup", ".cm-search-hit", function(t) {
var n = $(t.target).closest(".CodeMirror")[0].CodeMirror,
i = s.posFromMouse(n, t),
r = n.indexFromPos(i),
o = e.searchStatus.hits.find(function(t) {
return t.isCm == n && t.start <= r && t.end >= r
});
if (e.closePanel(!0), o) return n.doc.setSelection(n.posFromIndex(o.start), n.posFromIndex(o.end)), !1
}).on("mouseup", ".CodeMirror", function(t) {
e.closePanel(!0)
}), $("#md-searchpanel").on("blur", function() {
e.closePanel()
}).on("click", ".close-btn", function() {
e.closePanel()
}).on("keydown", "input", function() {
var t = event.keyCode || event.which;
if ("Esc" == i[t]) return e.closePanel(), !1
}).on("keydown", "#search-panel-input", function(t) {
var r = t.keyCode || t.which;
return n = 229 == r, "Enter" == i[r] ? (e.highlightNext(t.shiftKey), !1) : "Tab" == i[r] ? $("#md-searchpanel.searchpanel-replace-mode").length ? ($("#search-panel-replace-input").focus(), !1) : (this.value += "\t", !1) : void(e.inKeydown = !0)
}).on("keyup", "#search-panel-input", function() {
var r = event.keyCode || event.which;
(n = n && !(String.fromCharCode(r).match(/\s|[0-9]/g) || "Enter" == i[r])) || t == $(this).val() || (t = $(this).val(), e.inKeydown = !1, e.doSearch(t))
}).on("keydown", "#search-panel-replace-input", function() {
var t = event.keyCode || event.which;
if ((n = 229 == t) || "Enter" != i[t]) {
if ("Tab" == i[t] && !event.shiftKey) return !1
} else e.replaceSelection()
}).on("mousedown", "#search-panel-prev", function() {
e.highlightNext(!0)
}).on("mousedown", "#search-panel-next", function() {
e.highlightNext()
}).on("click", "#md-search-type-label", function() {
$("#md-searchpanel").addClass("searchpanel-replace-mode"), $("#search-panel-replace-input").focus(), document.body.classList.add("on-replace-panel-open")
}).on("click", "#md-replace-type-label", function() {
$("#md-searchpanel").removeClass("searchpanel-replace-mode").removeClass("searchpanel-msg-mode"), $("#search-panel-input").focus(), document.body.classList.remove("on-replace-panel-open"), $("content").removeClass("on-replace-panel-open")
}).on("click", "#search-panel-replace-btn", function() {
e.replaceSelection(), $("#md-searchpanel").removeClass("searchpanel-msg-mode")
}).on("click", "#search-panel-replaceall-btn", function() {
$("#md-searchpanel").removeClass("searchpanel-msg-mode"), e.replaceAll()
}).on("click", "#searchpanel-msg-close-btn", function() {
$("#md-searchpanel").removeClass("searchpanel-msg-mode")
}).on("click", "#searchpanel-msg-undo-btn", function() {
e.editor.undo.undo(), $("#md-searchpanel").removeClass("searchpanel-msg-mode"), !e.editor.sourceView.inSourceMode && e.doSearch($("#search-panel-input").val())
}).on("mousedown", "#searchpanel-case-option-btn", function(t) {
return this.classList.toggle("active"), e.caseSensitive = !e.caseSensitive, File.isMac && bridge.callHandler("touchBar.updateFindReplaceMode"), JSBridge.putSetting("caseSensitive", e.caseSensitive), e.doSearch(), !1
}).on("mousedown", "#searchpanel-word-option-btn", function() {
return this.classList.toggle("active"), e.wholeWord = !e.wholeWord, File.isMac && bridge.callHandler("touchBar.updateFindReplaceMode"), JSBridge.putSetting("wholeWord", e.wholeWord), e.doSearch(), !1
}), e.wholeWord && document.querySelector("#searchpanel-word-option-btn").classList.add("active"), e.caseSensitive && document.querySelector("#searchpanel-case-option-btn").classList.add("active")
},
replaceAll: function() {
if (this.searchStatus && this.searchStatus.hits.length) {
var t, e = this.searchStatus.searchText,
n = $("#search-panel-replace-input").val(),
r = this.searchStatus.hits;
(function(t) {
m && clearTimeout(m), $("#md-searchpanel.searchpanel-replace-mode").addClass("searchpanel-msg-mode").find("#searchpanel-msg-content").text(t), m = setTimeout(function() {
$("#md-searchpanel").removeClass("searchpanel-msg-mode")
}, 5e3)
}).call(this, (a = this.searchStatus.hits.length, this.searchStatus.searchText, "Replaced " + a + " occurrence(s)"));
var a;
if (this.editor.sourceView.inSourceMode) {
var s = "",
u = 0,
c = r.length;
for (t = 0, e = this.editor.sourceView.cm.getValue(); u < c; u++) s = s + e.substring(t, r[u].start - 0) + n, t = r[u].end - 0;
s += e.substring(t);
var l = this.editor.sourceView.cm.getScrollInfo().top;
return this.editor.sourceView.cm.setValue(s), this.editor.sourceView.cm.scrollTo(0, l), void this.clearSearch()
}
var f = this.editor.undo.UndoManager,
v = f.makeEmptyCommand(),
p = this.searchStatus,
g = this.searchStatus.curSelection;
if (g && g.isCm) v.undo.push(i.utils.extend(this.searchStatus.curSelection, {
type: "cursor"
}));
else if (g && g.parentElement) {
var b = o.createRange();
b.selectNode(g), v.undo.push(this.editor.selection.buildUndo(b))
}
this.resetSearchStatus();
var y;
for (u = 0; u < r.length; u++) {
var w = (t = r[u]).isCm ? t.cid : $(t).closest("[cid]").attr("cid");
y != w && (y = w, k.call(this, w))
}
this.editor.undo.register(v)
}
function F(t, i) {
var r = t.get(i);
r && t.set(i, r.replace(d(e, p), function(t, e, i) {
return p.wholeWord && e > 0 && h.exec(i.substr(e - 1, 1)) ? t : n
}))
}
function k(t) {
var e = this.editor.getNode(t);
v.undo.push(f.buildReplaceUndo(e)), F(e, "text"), F(e, "title"), F(e, "ref"), v.redo.push(f.buildReplaceUndo(e)), this.editor.findElemById(e.cid).replaceWith(e.toHTML())
}
},
replaceSelection: function() {
if (this.editor.sourceView.inSourceMode && !this.searchStatus.curSelection && this.highlightNext(), this.searchStatus.curSelection && this.searchStatus.hits.length && $("#md-searchpanel.searchpanel-replace-mode").length) {
var t = $("#search-panel-replace-input").val(),
e = this.searchStatus.curPos,
n = this.editor.undo.UndoManager.makeEmptyCommand(),
i = this.searchStatus.curSelection,
r = i.isCm;
r ? r.doc.replaceSelection(t, "start", "+findReplace") : function(t, e, n, i) {
var r = t.undo.UndoManager,
a = t.nodeMap.allNodes.get($(e).closest("[cid]").attr("cid")),
s = o.createRange();
s.selectNode(e), i.undo.push(t.selection.buildUndo(s)), i.undo.push(r.buildReplaceUndo(a));
var u = document.createTextNode(n);
e.parentElement.insertBefore(u, e), e.remove(), t.store(a.cid), i.redo.push(r.buildReplaceUndo(a)), s.selectNode(u), i.redo.push(t.selection.buildUndo(s))
}(editor, i, t, n), this.highlightNext(), this.searchStatus.hits.splice(e, 1), this.searchStatus.curPos > 0 && this.searchStatus.curPos--, this.searchStatus.hits.length || this.clearSearch(), this.editor.sourceView.inSourceMode || this.editor.undo.register(n)
}
},
isOpen: function() {
return "block" == document.querySelector("#md-searchpanel").style.display
},
showPanel: function(t) {
if (!$("#md-searchpanel").is(":visible")) {
var e = editor.selection.getRangy();
editor.lastCursor = editor.selection.buildUndo(e), $(".md-search-select").removeClass("md-search-select"), this.clearSearch(), this.searchStatus.initPos = editor.selection.getPosBookmark(), $("#md-searchpanel").show();
var n = document.querySelector("#search-panel-input");
n.value || (n.value = e && e.toString()), n.focus(), n.select(), n.value && this.doSearch(n.value), document.body.classList.add("on-search-panel-open")
}
t ? ($("#md-searchpanel").addClass("searchpanel-replace-mode"), document.body.classList.add("on-replace-panel-open")) : ($("#md-searchpanel").removeClass("searchpanel-replace-mode"), document.body.classList.remove("on-replace-panel-open")), File.isMac && (bridge.callHandler("touchBar.showFindReplaceTouchBar"), bridge.callHandler("touchBar.updateFindReplaceMode"))
},
closePanel: function(t, e) {
e = e || $(".md-search-select");
var n = this.editor.getMarkElem().length;
document.body.classList.remove("on-replace-panel-open"), document.body.classList.remove("on-search-panel-open");
var i = document.querySelector("#file-library-search-result .select");
if (i && i.classList.remove("select"), $("#md-searchpanel").removeClass("searchpanel-msg-mode").hide(), this.editor.sourceView.inSourceMode) return this.searchStatus && this.searchStatus.hits.length && (this.editor.fences.clearSearchAll(), this.editor.sourceView.cm.focus()), void this.resetSearchStatus();
t ? n = !0 : e.length ? (this.editor.selection.selectAllElem(e), this.editor.lastCursor = this.editor.selection.buildUndo(), n = !1) : this.searchStatus && this.searchStatus.curSelection && this.searchStatus.curSelection.isCm && (this.searchStatus.curSelection.isCm.focus(), this.editor.lastCursor = this.editor.selection.buildUndo(), n = !1), $(".md-search-select").removeClass("md-search-select"), this.clearSearch(), $(".md-search-hit").removeClass("md-search-hit"), !n && this.editor.restoreLastCursor(), !t && this.editor.refocus()
},
doSearch: function(t, e) {
var n = this.editor,
i = this,
r = this.searchStatus,
o = r && v(r),
a = o && document.querySelector("[cid='" + o.cid + "']"),
s = e;
if (e || (s = {
caseSensitive: $("#searchpanel-case-option-btn.active").length,
wholeWord: $("#searchpanel-word-option-btn.active").length
}), (s = Object.assign({
caseSensitive: !1,
wholeWord: !1,
noSelect: !1,
deply: 100
}, s)).initPosContainer = a, s.initPos = o, s.searchText = (void 0 === t ? $("#search-panel-input").val() : t || "").trim(), (r = Object.assign(this.emptySearchStatus(), s)).searchText.length) {
r.searchText.match(/^[a-z]$/i) && (r.wholeWord = !0);
i = this;
if (this.editor.sourceView.inSourceMode) return this.clearSearch(void 0, !0), this.searchStatus = r, void this.findAtNode(this.editor.sourceView.cm, r.searchText, r, !0);
this.searchTimer && (clearTimeout(this.searchTimer), this.searchTimer = null), this.searchTimer = setTimeout(function() {
if (i.clearSearch(void 0, !0), $(".md-search-expand").removeClass("md-search-expand"), !i.inKeydown) {
i.searchStatus = r;
for (var t = n.nodeMap.getFirst(); t;) i.findAtNode(t, r.searchText, r, !1), t = t.get("after");
!s.noSelect && i.highlightNext()
}
}, s.deply)
} else $(".md-search-expand").removeClass("md-search-expand"), this.clearSearch(void 0, !0), this.searchStatus = r
},
findAtNode: function(t, e, n, i) {
var r = this.editor,
a = n.initPosContainer,
s = n.initPos;
function u(t) {
var e = t.containerNode || document.querySelector("[cid='" + t.cid + "']");
return !!a && (a.compareDocumentPosition(e) == Element.DOCUMENT_POSITION_PRECEDING || a == e && t.start < s.start)
}
function m(t) {
var e = $(t);
if (e.closest(".md-meta, .md-content, script").length || e.hasClass("md-meta") || e.hasClass("md-content") || e[0] && "script" == e[0].tagName) e.closest("[md-inline]").addClass("md-search-expand");
else {
t.querySelectorAll(".md-meta, .md-content, script").forEach(function(t) {
$(t).closest("[md-inline]").addClass("md-search-expand")
})
}
}
function v(t, e) {
for (var i = d(e, n), o = t.getValue(), a = !1, s = null; i.exec(o);) a = !0, s = {
isCm: t,
cid: t.cid,
start: i.lastIndex - e.length,
end: i.lastIndex
}, n.wholeWord && s.start > 0 && h.exec(o.substr(s.start - 1, 1)) || (n.hits.push(s), u(s) && n.curPos++);
a && r.fences.searchOn(t, e, n)
}
i ? v(this.editor.sourceView.cm, e) : function t(e, i) {
e.get("children").length ? e.get("children").toArray().map(function(e) {
t(e, i)
}) : r.fences.queue[e.cid] ? v(r.fences.queue[e.cid], i) : l.isType(e, f.math_block) ? (r.mathBlock.currentCm || {}).cid === e.cid && (r.fences.clearSearchOn(r.mathBlock.currentCm), v(r.mathBlock.currentCm, i)) : function(t, e) {
for (var i, a, s = d(e, n), l = r.findElemById(t.cid)[0], f = l.textContent; s.exec(f);)
if (a = {
cid: t.cid,
containerNode: l,
start: s.lastIndex - e.length,
end: s.lastIndex
}, !(n.wholeWord && a.start > 0 && h.exec(f.substr(a.start - 1, 1)))) {
(i = i || o.createRange()).moveToBookmark(a);
var v = (p = i, c.markRange(p, "md-search-hit"));
m(v), n.hits.push(v), u(a) && n.curPos++
}
var p
}(e, i)
}(t, e)
},
highlightNext: function(t) {
if (!$("#md-searchpanel").is(":visible")) return this.showPanel();
$("#md-searchpanel").removeClass("searchpanel-msg-mode");
var e, n = this.searchStatus,
i = this.editor;
if (n && n.hits.length) {
var r = null;
n.curSelection ? n.curPos += t ? -1 : 1 : function() {
if (i.lastCursor)
if (void 0 != i.lastCursor.startId) {
var t = i.selection.rangy.createRange();
t.moveToBookmark({
containerNode: i.findElemById(i.lastCursor.startId)[0],
start: i.lastCursor.start,
end: i.lastCursor.start
}), n.curPos = 0;
for (var e = 0; e < n.hits.length; e++) {
if (!(o(t, r = n.hits[e]) > 0)) return;
n.curPos++
}
} else if (i.lastCursor.pos)
for (n.curPos = 0, e = 0; e < n.hits.length; e++) {
var r = n.hits[e];
if (!(a(i.lastCursor, r) > 0)) return;
n.curPos++
}
}(), n.curPos >= n.hits.length ? n.curPos = 0 : n.curPos < 0 ? n.curPos = n.hits.length - 1 : isNaN(n.curPos - 0) && (n.curPos = 0),
function(r) {
(function() {
n.curSelection && ((e = n.curSelection.isCm) ? e.execCommand(t ? "goDocStart" : "goDocEnd") : n.curSelection.classList.remove("md-search-select"))
}).call(this), n.curSelection = n.hits[n.curPos], n.initPos = null, $(".md-focus").removeClass("md-focus"), (e = n.curSelection.isCm) ? (n.lastRange = null, e.doc.setSelection(e.posFromIndex(n.curSelection.start), e.posFromIndex(n.curSelection.end)), File.isTypeWriterMode ? i.selection.typeWriterScroll($(".CodeMirror-selectedtext")) : i.selection.scrollAdjust($(".CodeMirror-selectedtext"), void 0, 200), $(".CodeMirror-selectedtext").closest("[cid]").addClass("md-focus")) : (n.curSelection.classList.add("md-search-select"), n.lastRange = n.curSelection, File.isTypeWriterMode ? i.selection.typeWriterScroll($(n.curSelection)) : i.selection.scrollAdjust($(n.curSelection), void 0, 200), $(n.curSelection).closest("[cid]").addClass("md-focus"))
}.call(this, n.curPos)
}
function o(t, e) {
try {
var n = i.selection.rangy.createRange();
return e.isCm ? n.selectNode(e.isCm.getWrapperElement()) : n.selectNode(e), t.compareBoundaryPoints(Range.END_TO_END, n)
} catch (t) {
Reporter.error(t, {
level: "warning"
})
}
}
function a(t, e) {
try {
if (e.isCm && e.isCm.cid == t.id) return e.isCm.indexFromPos(t.pos) - e.end;
r || (r = i.selection.rangy.createRange()).selectNode(i.findElemById(t.id)[0]);
var n = i.selection.rangy.createRange();
return e.isCm ? n.selectNode(e.isCm.getWrapperElement()) : n.selectNode(e), r.compareBoundaryPoints(Range.END_TO_END, n)
} catch (t) {
Reporter.error(t, {
level: "warning"
})
}
}
},
clearSearch: function(t, e) {
var n = v(this.searchStatus);
if (this.editor.sourceView.inSourceMode) return this.editor.fences.clearSearchAll(), this.resetSearchStatus(n), clearTimeout(this.searchTimer), void(this.searchTimer = null);
if (e || $(".md-search-expand").removeClass("md-search-expand"), this.searchStatus) {
for (var i = 0; i < this.searchStatus.hits.length; i++) {
var r = this.searchStatus.hits[i];
r.isCm || (s = r, c.unmarkSpan(s))
}
var o = this.searchStatus.curSelection,
a = (o || {}).isCm;
a && (a.doc.setSelection(a.posFromIndex(o.start)), $(a.display.input.textarea).blur())
}
var s;
this.editor.fences.clearSearchAll(), clearTimeout(this.searchTimer), this.searchTimer = null, this.resetSearchStatus(n)
},
emptySearchStatus: function(t) {
return {
hits: [],
curPos: 0,
searchText: null,
lastRange: null,
initPos: t,
curSelection: null
}
},
resetSearchStatus: function(t) {
this.searchStatus = this.emptySearchStatus(t)
}
});
n.exports = p
}), $__System.registerDynamic("39", ["14", "e", "13", "12"], !0, function(t, e, n) {
this || self, t("14");
var i = t("e"),
r = t("13"),
o = r.Node,
a = r.TYPE,
s = function(t) {
if (0 === t.trim().length) return 0;
var e = 0,
n = ["d", t.replace(/[\u3040-\uABFF\uD7A4-\uFAFF]/gi, function(t) {
return e++, " "
}).replace(/(^|\s+)[(\u3000-\u303F)!-\/:-@\[-`{-~]+(\s+|$)/gm, " "), "d"].join(" ").split(/[(\u3000-\u303F)\s!-,\.\\:-@\[-`{-~]+/g).length;
return e + n - 2
},
u = {
WORD: 0,
CHAR: 1,
LINE: 2,
TIME: 3
},
c = ["Words", "Characters", "Lines", "Minutes"],
l = ["Word", "Character", "Line", "Minute"],
f = t("12").Model.extend({
initialize: function(t) {
this.editor = t, this.delimiter = (File.option.wordCountDelimiter || 0) - 0, this.Delimiter = u, this.defferUpdateTimer = null, this.defferSelectionUpdateTimer = null, this.lastCount = -1, this.excludedCid = null, this.excludedCount = -1, File.isNodeHtml && this.bindWordCountOnNode()
},
getText: function(t) {
var e = this.editor,
n = t,
i = t;
void 0 === i.nodeType ? i = document.querySelector("[cid='" + n + "']") : n = i.getAttribute("cid");
var r = i && i.getAttribute("mdtype");
if (r == a.toc) return "toc";
if (o.isType(r, a.html_block, a.math_block, a.fences)) {
var s = (i.querySelector(".CodeMirror") || {}).CodeMirror;
if (s) {
if (r == a.fences) {
var u = i.getAttribute("lang");
return (u ? "```" + u + "\n" : "") + s.getValue() + (u ? "```" : "")
}
return r == a.math_block ? "$$\n" + s.getValue() + "\n$$" : s.getValue()
}
var c = e.getNode(n);
return c ? c.get("text") : ""
}
return r && !o.canContainBlock(r, !0) ? this.useWordDelimiter() ? i.rawText() : i.textContent : null
},
useWordDelimiter: function() {
return this.delimiter == u.WORD
},
clearTimer: function() {
this.defferUpdateTimer && (clearTimeout(this.defferUpdateTimer), this.defferUpdateTimer = null)
},
quickUpdate: function(t, e, n) {
var i = null,
r = t;
t && (t.cid ? (i = t.get("text"), r = t.cid) : i = this.getText(r)), e && (this.excludedCount = -1, this.excludedCid = null), null !== i && (this.delimiter == u.CHAR && this.quickUpdateCharCount(r, i, n), this.delimiter == u.WORD && this.quickUpdateWordCount(r, i, n), this.delimiter == u.LINE && this.quickUpdateLineCount(r, i, n), this.delimiter == u.TIME && this.quickUpdateReadTime(r, i, n))
},
quickUpdateWordCount: function(t, e, n, i) {
var r;
if (this.excludedCid == t && this.excludedCount >= 0) {
if (r = s(e) + this.excludedCount, n && r == this.lastCount) return;
return this.lastCount = r, void this.updateLabel(0, i ? Math.round(this.lastCount / File.option.wordsPerMinute) : this.lastCount)
}
if (!n) {
this.clearTimer();
var o = this;
this.defferUpdateTimer = setTimeout(function() {
o.lastCount = o.getWordCount(), o.excludedCid = t, o.excludedCount = o.lastCount - s(e), o.updateLabel(0, i ? Math.round(o.lastCount / File.option.wordsPerMinute) : o.lastCount)
}, 50)
}
},
quickUpdateCharCount: function(t, e, n, i) {
var r;
if (this.excludedCid == t && this.excludedCount >= 0) {
if (r = (i ? e.split(/\n/g).length : e.length) + this.excludedCount, n && r == this.lastCount) return;
return this.lastCount = r, void this.updateLabel(0, this.lastCount)
}
if (!n) {
File.sync(!1, !1, !0);
var o = this.editor.getMarkdown();
this.lastCount = i ? o.split(/\n/g).length : o.length, this.excludedCid = t, this.excludedCount = this.lastCount - (i ? e.split(/\n/g).length : e.length), this.updateLabel(0, this.lastCount)
}
},
quickUpdateReadTime: function(t, e, n) {
this.quickUpdateWordCount(t, e, n, !0)
},
quickUpdateLineCount: function(t, e, n) {
this.quickUpdateCharCount(t, e, n, !0)
},
getLabelsToShowOnMac: function() {
File.sync();
var t = this.getWordCount(),
e = this.editor.selection.getTextInSelection();
return e.length ? [t, s(e), e.length, Math.round(t / File.option.wordsPerMinute)].join("|") : [t, 0, 0, Math.round(t / File.option.wordsPerMinute)].join("|")
},
updateLabel: function(t, e) {
var n = i.localize.getString(c[this.delimiter], "Panel");
if (t > 0 && t < e) {
if (File.isMac) bridge.callHandler("word.updateWordCount", {
sel: t,
all: e
});
else if (File.isNodeHtml) {
var r = document.querySelector("#footer-word-count-label"),
o = r.textContent,
a = t + " / " + e + " " + n;
o != a && fastdom.mutate(function() {
r.textContent = a
})
}
} else if (e >= 0)
if (File.isMac) bridge.callHandler("word.updateWordCount", {
sel: t,
all: e
});
else if (File.isNodeHtml) {
var s = document.querySelector("#footer-word-count-label");
this.delimiter == u.TIME && 0 == e ? (n = i.localize.getString(l[this.delimiter], "Panel"), e = "≤ 1") : e <= 1 && (n = i.localize.getString(l[this.delimiter], "Panel")), fastdom.mutate(function() {
s.textContent = e + " " + n
})
}
},
updateLineCount: function(t) {
var e = (t = !0 === t ? this.editor.getMarkdown() : t || this.editor.getMarkdown()).split(/\n/g).length;
this.lastCount != e && (this.lastCount = e, this.updateLabel(0, this.lastCount))
},
updateCharCount: function(t) {
t = t || this.editor.getMarkdown();
this.lastCount != t.length && (this.lastCount = t.length, this.updateLabel(0, this.lastCount))
},
getWordCount: function() {
var t = "";
return this.editor.writingArea.querySelectorAll("[mdtype]").forEach(function(e) {
var n = this.getText(e);
n && (t += "\n" + n)
}, this), s(t)
},
updateWordCount: function() {
if (this.delimiter == u.WORD) {
this.clearTimer();
var t = this;
this.defferUpdateTimer = setTimeout(function() {
t.lastCount = t.getWordCount(), t.updateLabel(0, t.lastCount)
}, File.inBusyMode ? 500 : 100)
}
},
updateReadTime: function() {
this.clearTimer();
var t = this;
this.defferUpdateTimer = setTimeout(function() {
t.lastCount = t.getWordCount(), t.updateLabel(0, Math.round(t.lastCount / File.option.wordsPerMinute))
}, File.inBusyMode ? 500 : 100)
},
update: function(t) {
this.delimiter == u.WORD ? this.updateWordCount() : this.delimiter == u.CHAR ? this.updateCharCount(t) : this.delimiter == u.LINE ? this.updateLineCount(t) : this.delimiter == u.TIME && this.updateReadTime(t)
},
updateInSelection: function(t) {
this.defferSelectionUpdateTimer && clearTimeout(this.defferSelectionUpdateTimer);
var e = this.editor,
n = this;
this.defferSelectionUpdateTimer = setTimeout(function() {
var i = void 0 == t || null == t ? e.selection.getTextInSelection() : t;
i = i || "";
var r = 0;
if (this.defferSelectionUpdateTimer = null, n.delimiter == u.CHAR) r = i.length;
else {
if (n.delimiter != u.WORD) return;
r = s(i)
}
r = Math.min(r, n.lastCount);
n.updateLabel(r, n.lastCount)
}, 50)
},
getWordCountInSelection: function() {
var t = editor.selection.getTextInSelection();
return s(t)
},
getCharCountInSelection: function() {
return editor.selection.getTextInSelection().length
},
bindWordCountOnNode: function() {
var t = this,
e = this.editor;
i("#footer-word-count").on("click", function() {
if (document.body.classList.contains("ty-show-word-count")) document.body.classList.remove("ty-show-word-count"), document.body.classList.remove("ty-show-word-count-in-selection");
else {
document.body.classList.remove("ty-show-spell-check"), document.body.classList.add("ty-show-word-count"), File.sync();
var n = t.getWordCount();
i("#footer-word-count-td").text(n);
var r = e.getMarkdown(),
o = Math.round(n / File.option.wordsPerMinute);
i("#footer-read-time-count-td").text(o || "≤ 1"), i("#footer-line-count-td").text((r.match(/\n/g) || []).length + 1), i("#footer-char-count-td").text(r.length);
var a = e.selection.getTextInSelection();
a.length ? (i("#footer-char-count-td-sel").text(a.length), i("#footer-word-count-td-sel").text(s(a)), document.body.classList.add("ty-show-word-count-in-selection")) : document.body.classList.remove("ty-show-word-count-in-selection")
}
}).on("before-show-ty-hint", function(t) {
document.body.classList.contains("ty-show-word-count") && (t.cancel = !0)
}), i("#footer-word-count-info").on("click", "[data-delimiter]", function() {
var n = this.dataset.delimiter - 0;
t.setDelimiter(n);
var i = this.children[0].textContent + " " + this.children[1].textContent;
document.querySelector("#footer-word-count-label").textContent = i, document.body.classList.remove("ty-show-word-count"), e.restoreLastCursor(null, !0)
})
},
setDelimiter: function(t) {
this.delimiter = t, this.update(!0), this.quickUpdate(editor.focusCid, !0), JSBridge.putSetting("wordCountDelimiter", this.delimiter)
}
});
f.Delimiter = u, n.exports = f
}), $__System.registerDynamic("3a", ["e", "12"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("e"),
r = t("12").Model.extend({
initialize: function(t) {
this.editor = t, this.$container = i("#word-auto-suggest")
},
search: function(t, e, n, i) {
var r = t.substring(e, e + n);
return r ? new Promise(function(o, a) {
File.isMac ? bridge.callHandler("word.getSpellSuggestionInContext", {
context: t,
start: e,
length: n
}, function(t) {
i.type = "word", i.token = r, i.match = t, i.found = t.length, i.pageNo = 0, i.pageCnt = Math.floor((t.length - 1) / 5 + 1), o(i)
}) : o(i)
}) : []
},
showAutoSuggest: function(t, e, n, r) {
if (r.token === t.substring(e, e + n)) return !1;
var o = this.search(t, e, n, r),
a = "";
if (!r.found) return this.$container.hide(), !1;
for (var s = 0; s < o.length && s < 40; s++) s % 5 == 0 && (a += (s > 0 ? "</ul>" : "") + "<ul data-page='" + s / 5 + "' style='display:none'>"), a += i("<li/>").attr("data-content", o[s]).text(o[s])[0].outerHTML;
return a += "</ul>", this.$container.html(a), this.$container
}
});
n.exports = r
}), $__System.registerDynamic("3b", ["12", "13", "14", "16", "19", "29"], !0, function(t, e, n) {
"use strict";
this || self, t("12");
var i, r, o = t("13"),
a = o.Node,
s = o.NodeMap,
u = o.TYPE,
c = t("14"),
l = t("16"),
f = t("19"),
h = t("29"),
d = {
"\b": "\\b",
"\t": "\\t",
"\n": "\\n",
"\f": "\\f",
"\r": "\\r",
'"': '\\"',
"'": "'",
"\\": "\\\\"
};
var m, v, p = "",
g = {},
b = [],
y = [];
function w(t, e, n) {
var i = h.svg2DataURL(t, e),
r = t.getBoundingClientRect(),
o = new Image;
o.onerror = function(t) {
n("")
}, o.onload = function() {
var t = document.createElement("canvas"),
e = t.getContext("2d"),
i = File.canvasratio,
a = o.width,
s = r.bottom - r.top;
t.width = o.width, t.height = r.bottom - r.top, i > 1.1 && (t.width = a * i, t.height = s * i, e.scale(i, i)), e.drawImage(o, 0, 0), t.style.width = a + "px", t.style.height = s + "px", setTimeout(function() {
var e = "";
try {
e = t.toDataURL("image/png")
} catch (t) {
console.warn(t)
}! function(t, e) {
var n;
if (File.isNode) {
var i = t.replace(/^data:image\/png;base64,/, ""),
r = reqnode("electron").remote.app;
n = r.getPath("temp").replace(/[/\\]$/, "") + (File.isWin ? "\\\\" : "/") + Number(new Date) + ".png", reqnode("fs").writeFile(n, i, "base64", function(t) {
t ? console.sendError(t.stack) : (e(n), y.push(n))
})
} else File.isMac && bridge.callHandler("images.savePNG", t, function(t) {
e(t), y.push(t)
})
}(e, n)
}, 100)
}, o.src = i
}
function F(t, e) {
var n = document.querySelector("[cid='" + t + "'] svg"),
i = $(n).closest("[lang='mermaid']").length;
File.isMac && i ? function(t, e) {
var n = "<html><body>$1</body></html>",
i = t.getBoundingClientRect();
i = {
x: 0,
y: 0,
width: i.width,
height: i.height
}, n = n.replace("$1", h.svg2DataURL(t, !0, !0)), bridge.callHandler("controller.screenshotHTML", {
html: n,
rect: i
}, e)
}(n, e) : w(n, i, e)
}
function k(t, e, n, i) {
var r = t.split(/(\uE040\d+)\uE041/g);
if (!r) return e(t);
Promise.all(r.map(function(t) {
return new Promise(function(e) {
if (t.charAt(0) == p) {
var r = t.substring(1) - 0,
o = m[r].cid;
F(o, function(t) {
v.delete(o), "latex" == n ? (r = t, a = i, a ? new Promise(function(t) {
if (File.isNode) {
var e = reqnode("path").basename(r);
reqnode("fs-extra").move(r, a + "/" + e, function() {
t(e)
})
} else File.isMac && bridge.callHandler("path.moveTo", {
source: r,
folder: a
}, t)
}) : Promise.resolve(r)).then(function(t) {
e(JSON.stringify(t))
}) : e(JSON.stringify(t));
var r, a
})
} else e(t)
})
})).then(function(n) {
t = n.join(""), e(t)
}, function(n) {
t = r.join("").replace(/[\uE040-\uE041]/g, ""), e(t)
})
}
function x() {
if (File.isNode)
for (; y.length;) reqnode("fs").unlink(y.pop(), function() {});
else File.isMac && (bridge.callHandler("path.removeFiles", y), y = [])
}
var _, E = function(t) {
return f.recoverEscape(t).replace(/["'\\\b\t\n\f\r]/g, function(t) {
return d[t]
}).replace(/\u200b/g, "")
},
C = {
left: "AlignLeft",
right: "AlignRight",
center: "AlignCenter"
},
A = function(t, e, n, i) {
e = void 0 === e ? "," : e, i = i || g;
for (var r, o = [], a = n || t.getFirstChild(); a;)(r = R(a, i)) && o.push(r), a = a.get("after");
return o.join(e)
},
S = function(t, e) {
return e = e || t.get("text"), _.output(e, null, t).replace(/, $/, "") || 'Str ""'
},
T = function(t) {
return a.isType(t, "epub", "rst", "opml", "textile")
},
M = /([^\\]|^)\\tag{([^}]+)}\s*/,
D = /([^\\]|^)\\label{([^}]+)}\s*/,
L = /([^\\]|^)\\over[^\w\d]/,
R = function(t, e) {
var n;
T(e.target);
switch (t.get("type")) {
case u.paragraph:
return "Para [" + (n = S(t)) + "]";
case u.meta_block:
return "";
case u.heading:
var i = a.isType(e.target, "textile", "opml") ? "" : "header-" + t.cid;
return "Header " + t.get("depth") + ' ("' + i + '", [], []) [' + S(t) + "]";
case u.blockquote:
return "BlockQuote [" + (n = A(t)) + "]";
case u.list:
var o = t.get("style");
return n = A(t), o == a.ListType.ol ? "OrderedList (1,Decimal,Period) [" + n + "]" : "BulletList [" + n + "]";
case u.list_item:
return "[" + (n = A(t)) + "]";
case u.fences:
if (l.isDiagramType(t.get("lang")) && a.isType(e.target, "epub", "docx", "odt", "latex")) {
m.push(t), v.add(t.cid);
var s = document.querySelector("[cid='" + t.cid + "'] svg").getBoundingClientRect();
return 'Div ("",[],[("style","text-align:center"), ("align", "center")]) [Para [Image (' + JSON.stringify(t.get("lang")) + ',[],[("width", "' + (s.right - s.left) + '"), ("align", "center")]) [Str ""] (' + (p + (m.length - 1)) + ',"fig:")]] '
}
var h = f.parsePandocAttr(t.get("lang"));
if (Object.keys(h).length) {
var d = [];
for (var g in h.nativeAttr) d.push('("' + g.replace(/['"]/g, "") + '","' + h.nativeAttr[g].replace(/['"]/g, "") + '")');
return 'CodeBlock ("' + E(h.id || "") + '",[' + (h.class || "").trim().split(/\s+/).map(function(t) {
return '"' + E(t) + '"'
}).join(",") + "],[" + d.join(",") + ']) "' + E(t.get("text")) + '"'
}
return 'CodeBlock ("",["' + E(getCodeMirrorMode(t.get("lang") || "", !1, !0)) + '"],[]) "' + E(t.get("text")) + '"';
case u.math_block:
if (n = t.get("text").trim().replace(/\u200b/g, ""), "epub" == e.target) {
var b = r[n];
if (b) return 'RawBlock (Format "html") ' + JSON.stringify(function(t) {
try {
var e = (new DOMParser).parseFromString(t, "text/html");
return e.querySelectorAll("mtable").forEach(function(t) {
t.hasAttribute("columnalign") && !t.getAttribute("columnalign") && t.removeAttribute("columnalign")
}), e.body.innerHTML
} catch (t) {}
return t
}(b)) + " "
} else if ("latex" == e.target) {
if (n.match(/^\\(begin|newcommand|renewcommand|newenvironment|renewenvironment|def|let){/)) return 'RawBlock (Format "latex") ' + JSON.stringify(n)
} else if ("docx" == e.target && File.option.autoNumberingForMath) {
var y = function(t, e) {
e.number = e.number || 1;
var n;
if (File.option.autoNumberingForMath && (n = e.number, e.number++), L.test(t)) return [t, n];
var i = M.exec(t);
return t = t.replace(/([^\\]|^)\\eqref{([^}]+)}\s*/g, "$1($2)"), i ? (n = i[2], [t = t.replace(/([^\\]|^)\\tag{([^}]+)}\s*/g, "$1") + "\\qquad\\text{(" + c.escapeInQuote(n) + ")}", n]) : (t = t += "\\qquad\\text{(" + c.escapeInQuote(n + "") + ")}", (i = D.exec(t)) && (n = i[2]), [t, n])
}(n, e);
return "Plain [" + ['RawInline (Format "openxml") "<w:bookmarkStart w:id=\\"0\\" w:name=\\"%s\\"/><w:r><w:t>" '.replace("%s", y[1]), 'Math DisplayMath "' + E(y[0]) + '" ', 'RawInline (Format "openxml") "</w:t></w:r><w:bookmarkEnd w:id=\\"0\\"/>"'].join(",") + "]"
}
return 'Plain [Math DisplayMath "' + E(n) + '"]';
case u.hr:
return "HorizontalRule";
case u.def_footnote:
case u.def_link:
return "";
case u.toc:
return "latex" == e.target ? 'RawBlock (Format "latex") "\\\\tableofcontents"' : "wiki" == e.target ? 'RawBlock (Format "mediawiki") "__TOC__", RawBlock (Format "mediawiki") ""' : "rst" == e.target ? 'RawBlock (Format "rst") ".. contents::", RawBlock (Format "rst") "\n"' : "opml" == e.target ? "" : "textile" == e.target ? 'RawBlock (Format "textile") "{toc}", RawBlock (Format "textile") "\n"' : function(t, e) {
try {
return 'Div ("toc", [], []) [Para [' + t.toc.headers.map(e ? function(t) {
return 'Str "' + " ".repeat(t.get("depth") - 1) + '", Link ("", [], []) [' + S(t) + '] ("#header-' + t.cid + '","")'
} : function(t) {
return 'Str "' + "\\t".repeat(t.get("depth") - 1) + '", Link ("", [], []) [' + S(t) + '] ("#header-' + t.cid + '","")'
}).join(",LineBreak,") + "]]"
} catch (t) {
return console.warn(t.stack), ""
}
}(t.get("in"), "epub" == e.target);
case u.table:
var w = t.get("align").map(function(t) {
return C[t] || "AlignDefault"
}),
F = w.map(function() {
return "0.0"
}),
k = t.getFirstChild();
return "Table [] [" + w.join(",") + "] [" + F.join(",") + "] [" + A(k) + "] [" + A(t, ",", k.get("after")) + "]";
case u.table_row:
return "[" + A(t) + "]";
case u.table_cell:
return "[Plain [" + S(t) + "]]";
default:
return ""
}
},
B = [];
B[u.strong] = "Strong", B[u.em] = "Emph", B[u.del] = "Strikeout", B[u.subscript] = "Subscript", B[u.superscript] = "Superscript";
var I, N = {
html: 'RawInline (Format "html") "<u>", $0, RawInline (Format "html") "</u>", ',
docx: 'RawInline (Format "openxml") "<w:r><w:rPr><w:u w:val=\\"single\\" /></w:rPr><w:t>$0</w:t></w:r>", ',
rtf: 'RawInline (Format "rtf") "{\\\\ul ", $0, RawInline (Format "rtf") " }", ',
latex: 'RawInline (Format "latex") "\\\\underline{", $0, RawInline (Format "latex") "}", '
},
O = {
html: 'RawInline (Format "html") "<mark>", $0, RawInline (Format "html") "</mark>", ',
docx: 'RawInline (Format "openxml") "<w:r><w:rPr><w:shd w:val=\\"clear\\" w:fill=\\"ffff00\\" /></w:rPr><w:t>$0</w:t></w:r>", ',
rtf: 'RawInline (Format "rtf") "{{\\\\colortbl;\\\\red255\\\\green255\\\\blue0;} \\\\cb1 ", $0, RawInline (Format "rtf") "}", ',
latex: 'RawInline (Format "latex") "\\\\hl{", $0, RawInline (Format "latex") "}", '
},
j = {
atag: !1,
imgtag: !1,
comment: !0,
citation: !0
},
P = function(t, e) {
var n = function(t) {
if (a.isType(t.type, u.plain, u.escape, u.emoji)) return t.inner || t.text;
if (e) return t.text || "";
throw Error("caught styles")
};
I || (I = new f.InlineLexer({
skipOp: j
}, n));
try {
return I.output(t.text, n, !0)
} catch (t) {
return !1
}
},
q = function(t, e) {
var n, i, o, a, s, l = /^(\S*)(?:(\n)|(\s*))/,
f = function(t) {
for (var e, n = ""; t.length && (e = l.exec(t));) t = t.substring(e[0].length), e[1] && (n += 'Str "' + E(e[1]) + '", '), e[2] ? n += File.option.preLinebreakOnExport ? "LineBreak, " : "SoftBreak, " : e[3] && (n += "Space, ");
return n
};
t.inner && (t.inner = t.inner.replace(/, $/, ""));
var h = /^file:[\\\/]{0,2}/i;
switch (t.type) {
case u.strong:
case u.em:
case u.del:
case u.subscript:
case u.superscript:
return B[t.type] + " [" + t.inner + "], ";
case u.plain:
case u.escape:
case u.tab:
case u.emptyline:
return f(t.text);
case u.html_entity:
return f(c.decodeHtmlEntity(t.text) || t.text);
case u.pants:
return f(t.inner);
case u.softbreak:
return File.option.preLinebreakOnExport ? "LineBreak, " : "SoftBreak, ";
case u.code:
return 'Code ("", [], []) "' + E(t.text.trim()) + '", ';
case u.autolink:
case u.url:
return 'Link ("", [], []) [Str "' + E(t.text) + '"] ("' + E(t.href) + '", ""), ';
case u.atag:
if (!T(e.target)) return 'Link ("", [], []) [' + t.inner + '] ("' + E(t.href) + '", "' + E("") + '"), ';
case u.imgtag:
if (!T(e.target)) {
var d = $($.parseHTML(t.text));
return 'Image ("",[],[]) [Str "' + E(d.attr("title") || d.attr("alt") || "") + '"] ("' + E(File.editor.imgEdit.getRealSrc(t.href).replace(h, "")) + '","fig:"), '
}
case u.tag:
case u.comment:
case u.citation:
case u.ruby:
return 'RawInline (Format "html") "' + E(t.text) + '", ';
case u.link:
if ("#" == (t.href || "").trim()[0]) {
var m = t.href.substr(1),
v = $("h1, h2, h3, h4, h5, h6").filter(function() {
return $(this).text().toLowerCase().trim() == m.toLowerCase().trim()
});
v.length && (t.href = "#header-" + v.attr("cid"))
}
return 'Link ("", [], []) [' + t.inner + '] ("' + E(t.href) + '", "' + E(t.title || "") + '"), ';
case u.image:
return 'Image ("",[],[]) [Str "' + E(t.title || "") + '"] ("' + E(File.editor.imgEdit.getRealSrc(t.href).replace(h, "")) + '","fig:"), ';
case u.refimg:
o = "Image";
case u.reflink:
return i = (n = e.nodeMap.link_list.getNodeByRef(t.ref || t.text)) ? E(n.get("href").replace(h, "")) : "", m = E(n && n.get("title") || ""), "Image" == (o = o || "Link") && (t.inner = 'Str "' + E(m || "") + '"'), o + ' ("", [], []) [' + t.inner + '] ("' + i + '", "' + m + '"), ';
case u.footnote:
var p = e.nodeMap.foot_list.getNodeByRef(t.text);
return p ? "Note [Para [" + S(p) + "]], " : f(t.text);
case u.attr:
return f(t.text);
case u.emoji:
return 'Str "' + E(t.inner) + '", ';
case u.inline_math:
if ("epub" == e.target) {
var g = r[t.text.replace(/(^\s*\$+)|(\$+\s*$)|\u200b/g, "").trim()];
if (g) return 'RawInline (Format "html") ' + JSON.stringify(g) + ", "
}
return 'Math InlineMath "' + E(t.text.replace(/(^\s*\$+)|(\$+\s*$)|\u200b/g, "")) + '", ';
case u.linebreak:
return "LineBreak, ";
case u.highlight:
if ("latex" == e.target) b.push("\\usepackage{color}"), b.push("\\usepackage{soulutf8}");
else if ("docx" == e.target) return s = P(t, !0), O[e.target].replace("$0", E(c.escape(s)));
a = O;
case u.underline:
return a = a || N, "docx" == e.target ? (s = P(t, !0), a[e.target].replace("$0", E(c.escape(s)))) : (a[e.target] || a.html).replace("$0", t.inner);
default:
return f(t.text || "")
}
},
U = function(t) {
var e = [];
function n(t, e) {
if (e instanceof Array) return n = e, '("' + E(t) + '", MetaList [' + n.map(function(t) {
return 'MetaInlines [RawInline (Format "tex") "' + E(t) + '"]'
}).join(", ") + "])";
var n;
return '("' + E(t) + '", MetaInlines [ ' + (_.output(e).replace(/, $/, "") || 'Str ""') + "])"
}
t["header-includes"] && t["header-includes"] instanceof Array ? t["header-includes"] = t["header-includes"].concat(b) : b.length && (t["header-includes"] = b);
for (var i in t) e.push(n(i, t[i]));
return e.join(", ")
};
s.prototype.exportToNative = function(t, e, n) {
File.editor.export.cleanUpTempFiles = x,
function(t) {
if (g = {
forExport: !0,
target: t,
nodeMap: this,
skipOp: j
}, b = [], m = [], v = new Set, void 0 === File.canvasratio) {
File.canvasratio = 1;
var e = document.createElement("canvas").getContext("2d"),
n = window.devicePixelRatio || 1,
i = e.webkitBackingStorePixelRatio || e.mozBackingStorePixelRatio || e.msBackingStorePixelRatio || e.oBackingStorePixelRatio || e.backingStorePixelRatio || 1;
File.canvasratio = n / i
}
}.call(this, t), "epub" == t && (r = Object.create(null), !i && File.option.enableInlineMath && (i = document.querySelector("#inline-math-export-jax"), MathJax.Hub.Typeset(i), i = MathJax.Hub.getAllJax(i)[0]), $(".md-inline-math, [mdtype='math_block']").each(function() {
try {
var t, e = this.querySelector("script").textContent.trim().replace(/\u200b/g, "");
this.classList.contains("md-inline-math") ? (i.Text(e), t = i.root.toMathML("")) : t = MathJax.Hub.getAllJax(this)[0].root.toMathML(""), r[e] = t
} catch (t) {}
})), _ && _.options.nodeMap === this || (_ = new f.InlineLexer(g, q));
var o = A(null, "\n ,", this.getFirst(), g),
s = "Pandoc (Meta {unMeta = fromList [" + U(File.editor.docMenu.buildMetaMap()) + "]})\n [" + o + "]";
return a.isType(t, "epub", "docx", "odt", "latex") ? k(s, e, t, n) : e(s), s
}
}), $__System.registerDynamic("3c", ["12", "13", "14", "19", "2f", "3b", "29", "18", "e", "35"], !0, function(t, e, n) {
"use strict";
this || self;
var i, r, o = t("12"),
a = t("13"),
s = a.Node,
u = a.TYPE,
c = (a.NodeCollectionUtils, t("14")),
l = t("19"),
f = t("2f"),
h = (t("3b"), t("29")),
d = t("18"),
m = t("e"),
v = (t("35"), File.isWin ? 8e3 : 960),
p = File.isWin ? 5 : 40,
g = function() {
for (var t = document.querySelectorAll("#write figure"), e = 0; e < t.length; e++) {
var n = t[e];
n.style.zoom = Math.min(n.clientWidth / n.scrollWidth, 1), n.style.overflowX = "hidden", n.style.overflowy = "hidden"
}
},
b = function() {
for (var t = document.querySelectorAll("#write a"), e = /^\s*#(.+)$/, n = {
"\b": "\\b",
"\t": "\\t",
"\n": "\\n",
"\f": "\\f",
"\r": "\\r",
'"': '\\"',
"'": "\\'",
"\\": "\\\\"
}, i = function(t) {
return t.replace(/["\\\b\t\n\f\r]/g, function(t) {
return n[t]
}).replace(/\u200b/g, "")
}, r = 0; r < t.length; r++) {
var o, a = t[r],
s = a.getAttribute("name"),
u = a.getAttribute("href");
if (s) {
var c = document.createElement("a"),
l = document.createTextNode(" ");
c.appendChild(l), c.setAttribute("class", "md-print-anchor"), c.setAttribute("href", "uaf://" + i(s)), a.parentNode.insertBefore(c, a)
}
u && (o = e.exec(u)) && (u = o[1], a.setAttribute("href", "uat://" + i(u)))
}
};
function y(t) {
if (r) r.close(), r.destroy(), r = null;
else if (!t) return;
m("#md-notification").hide()
}
window.i = y;
var w = o.Model.extend({
initialize: function(t) {
this.editor = t, window.debugMode && SystemJS.import("FileSaver.min.js").then(function(t) {
i = t
}), this.registerBridge()
},
registerBridge: function() {
if (File.isMac) {
var t = this;
bridge.registerHandler("export.exportToNative", function(e, n) {
t.exportToNative(e.target, n, e.folder)
}), bridge.registerHandler("export.onExportSuccess", function(t, e) {
k(t.type, t.path), e && e()
}), bridge.registerHandler("export.dataForExport", function(e, n) {
setTimeout(function() {
n({
suggestedFilename: File.getSuggestedFileName() || "",
content: t.exportToHTML(e || {})
})
}, t.beforeExport(e.forPrint) ? 1e3 : 0)
})
}
},
beforeExport: function(t) {
var e = !1;
return t && File.editor.sourceView.inSourceMode && (File.editor.sourceView.hide(), e = !0), File.sync(), e
},
exportToNative: function(t, e, n) {
return e = e || function() {}, this.editor.nodeMap.exportToNative(t, e, n)
},
exportToImage: function() {
function t() {
y(!0), i && (i.postMessage("terminiate"), i.terminate(), i = null)
}
var e, n = File.option.imageExportWidth,
i = new Worker((window.debugMode ? "lib" : "lib.asar") + "/image-worker.js"),
o = reqnode("electron").remote,
a = o.getCurrentWindow(),
s = o.app,
u = o.dialog,
c = o.BrowserWindow,
l = this,
f = o.screen.getPrimaryDisplay().scaleFactor || 1,
h = JSBridge.getSetting("zoomFactor") || 1,
d = 0,
g = null;
i.onmessage = function(e) {
e.data.success ? (t(), o.shell.showItemInFolder(g)) : (console.sendError(e.data.error), Reporter.error(e.data.error, {
level: "warn"
}), t())
};
try {
(function() {
File.editor.store(!0), y(!0);
var t = l.exportToHTML({
forPrint: !0,
forImage: !0
}),
e = o.app.setting.config;
return (r = new c({
skipTaskbar: !0,
show: !1,
webPreferences: {
devTools: !1,
webSecurity: !1,
allowDisplayingInsecureContent: !0,
allowRunningInsecureContent: !0,
nodeIntegration: !1,
directWrite: e.directWrite,
defaultFontFamily: e.defaultFontFamily,
zoomFactor: h,
safeDialogs: !0
},
webgl: !1,
useContentSize: !0,
width: n,
height: v,
frame: !1,
enableLargerThanScreen: !!File.isWin,
offscreen: !0,
alwaysOnTop: !0,
minimizable: !1,
closable: !0
})).loadURL("data:text/html;charset=UTF-8, " + encodeURIComponent(t)), r
})().webContents.once("did-finish-load", function() {
r.webContents.executeJavaScript("window.innerHeight").then(function(o) {
File.isLinux && (v = o), setTimeout(function() {
r.webContents.executeJavaScript("document.body.parentElement.scrollTop = document.body.clientHeight;\nMath.max(document.body.clientHeight, document.body.parentElement.scrollHeight)").then(function(o) {
return o -= 0, isNaN(o) || null == o ? y(!0) : (e = o) > v * p ? (t(), u.showErrorBox(m.localize.getString("Export Failed", "Panel"), m.localize.getString("Generated Image too Large", "Panel")), !1) : void
function o(a) {
var s = e - a;
s > v && (s = v), r.setSize(n, s), r.setContentSize(n, s), r.webContents.executeJavaScript("document.body.parentElement.scrollTop = {d}; document.body.parentElement.scrollHeight;".replace("{d}", a)).then(function(u) {
setTimeout(function() {
r ? ((u -= 0) > e + 100 && (i.postMessage({
action: "updateTotalHeight",
totalHeight: u
}), e = u), r.webContents.capturePage(function(r) {
if (r.isEmpty()) return t();
f > 1 && (r = r.resize({
width: n,
quality: "best"
})), i.postMessage({
action: "addImage",
buffer: r.toDataURL(),
index: d,
position: {
width: n,
offset: a
},
totalHeight: e,
total: Math.ceil(e / v)
}), a + s < e && (d++, o(a += s))
})) : t()
}, 50)
})
}(0)
})
}, 1e3)
})
})
} catch (e) {
t()
}
u.showSaveDialog(a, {
properties: ["saveFile"],
title: "Export to…",
defaultPath: s.getPath("userDesktop") + "/" + File.getSuggestedFileName(!0) + ".png",
filters: [{
name: "PNG",
extensions: ["png"]
}, {
name: "JPEG",
extensions: ["jpg", "jpeg"]
}]
}, function(e) {
if (!e) return t();
g = e, i.postMessage({
action: "setPath",
path: g
}), m("#md-notification").html("<p> " + m.localize.getString("Exporting in progress...", "Panel") + " </p>").show()
})
},
exportAndSaveHTML: function(t) {
var e = new Blob([this.exportToHTML({
forPrint: t
})], {
type: "text/html;charset=utf-8"
});
i(e, "export.html")
},
exportCollection: function(t, e, n) {
var i = n || {},
r = i.forPrint,
o = i.noStyle,
a = i.exportFooter,
v = i.exportInline,
p = i.forImage,
g = this.editor.nodeMap,
b = this.editor,
y = (v = v || new l.InlineLexer({
nodeMap: g,
count: 1,
footnoteList: [],
appendFootnote: function(t, n) {
if (!e[n]) {
e[n] = [""];
var i = v.output(t.get("text"), f.decorateAsExport, !1, {
parent: t,
skipFootnote: n
});
e[n][0] = "<span class='md-fn-count'>" + n + "</span> " + i
}
var r = e[n].length - 1,
o = n + (r ? "-" + r : "");
return e[n].push("<a name='dfref-footnote-" + o + "' href='#ref-footnote-" + o + "' title='" + m.localize.getString("back to document") + "' class='reversefootnote' >↩</a>"), o
},
noStyle: o,
forPrint: r,
skipOp: {
atag: !0,
underline: !0,
comment: !0,
citation: !0,
imgtag: !0
}
}, f.decorateAsExport), ""),
w = void 0 === i.split || null === i.split ? o ? "\n" : "" : i.split,
k = this;
i.exportInline = v, e = e || [];
function x(t, n) {
if ("string" == typeof t) return v.output(t, f.decorateAsExport);
var r = t.get("children");
return s.canContainBlock(t.get("type")) ? r && r.length > 0 ? k.exportCollection(r, e, i) : v.output(t.get("text"), f.decorateAsExport) : v.output(t.get("text"), f.decorateAsExport, void 0, void 0, n)
}
function _(t) {
var e = null;
function n(t) {
return t ? g.toc.headers.findIndex(function(e) {
return e.cid == t
}) : -1
}
var i = {
cid: t.cid
};
switch (t.get("type")) {
case u.paragraph:
if (-1 == t.get("text").indexOf("\n")) {
var a = s.parseFrom(t.getText(), null, {
noTop: !0,
skips: {
fromP: !0
}
}, !0)[1][0];
if (s.isType(a, u.heading) && (a.cid = t.cid, -1 == n(a.cid) && t.isTopBlock())) {
var f = b.findElemById(a.cid).prevAll(".md-heading").last().attr("cid");
g.toc.headers.splice(n(f) + 1, 0, a)
}
if (s.isType(a, u.heading, u.def_footnote, u.def_link)) return a.cid = t.cid, _(a)
}
var v = x(t, i);
return "" == v || i.hasContent ? "<p>" + (v || "&nbsp;") + "</p>" : v;
case u.heading:
var y = "";
return r && 1 == t.get("depth") && !t.get("parent") && t.get("before") && (y = " data-breakpage"), "<h" + t.get("depth") + y + ">" + (o || p ? "" : "<a name='header-" + t.cid + "' class='md-header-anchor " + (r ? "md-print-anchor' href='af://" + t.cid + "'> " : "'>") + "</a>") + x(t, i) + "</h" + t.get("depth") + ">";
case u.blockquote:
return "<blockquote>" + x(t, i) + "</blockquote>";
case u.list:
var F = t.get("style"),
$ = function() {
for (var e = t.get("children").toArray(), n = 0; n < e.length; n++) {
var i = e[n].getFirstChild();
if (!s.isType(i, u.paragraph) || i.get("after")) return !0
}
return !1
}();
t.set("loose", $);
var E = "";
return F == s.ListType.ol && (E = "" === t.get("start") ? void 0 : t.get("start") - 0, E = Number.isNaN(E) || 1 == E ? "" : " start='" + t.get("start") + "' "), "<" + F + E + ">" + w + x(t, i) + w + "</" + F + ">";
case u.list_item:
return t.get("style") === s.ListType.task ? "<li" + (o ? "" : " class='md-task-list-item task-list-item task-list-" + (t.get("checked") ? "done" : "not-done") + "' ") + "><input type='checkbox' disabled='disabled' " + (t.get("checked") ? "checked" : "") + "/>" + x(t, i) + "</li>" : "<li>" + (j = t, P = i, !1 === j.get("parent").get("loose") ? x(j.getFirstChild(), P) : x(j, P)) + "</li>";
case u.fences:
if (o) {
var C = t.get("lang") || "";
if (C) {
return "<pre" + l.attrToString(l.parsePandocAttr(C)) + "><code class='language-" + (C = c.escapeInQuote(getCodeMirrorMode(C, !1, !0))) + "' lang='" + C + "'>" + c.escape(t.get("text")) + w + "</code></pre>"
}
return "<pre><code>" + c.escape(t.get("text")) + w + "</code></pre>"
}
var A, S = b.findElemById(t.id).clone();
if (File.option.enableDiagram && s.isType((t.get("lang") || "").toLowerCase(), "flow", "sequence", "mermaid")) {
A = !1;
var T = b.findElemById(t.id).find("svg"),
M = S.find("svg");
return T.attr("width") && !T.attr("viewBox") && (M.attr("viewBox", "0 0 " + T.attr("width") + " " + T.height()), M.css("max-width", "100%"), M.css("height", "auto")), h.processExportedSVG(S.find(".md-diagram-panel").html(S.find(".md-diagram-panel-preview").html())[0].outerHTML)
}
if (!1 !== A && (A = t.get("text").split(/\n/).length > 13), S.children(".CodeMirror").length && S.removeAttr("cid").removeAttr("contenteditable").removeAttr("mdtype").html(S.children(".CodeMirror")[0].outerHTML).find(".CodeMirror-cursors, .CodeMirror-hscrollbar, .CodeMirror-vscrollbar, .CodeMirror-selected").remove().end().find(".CodeMirror-sizer").css("min-height", "").end().find(".CodeMirror-selectedtext").removeClass("CodeMirror-selectedtext").end(), r && File.option.noLineWrapping && S.children(".CodeMirror").addClass("CodeMirror-wrap").find(".CodeMirror-sizer").css("min-width", ""), A && S.css("page-break-inside", "unset"), r && File.isNode) {
var D = window.getComputedStyle(File.editor.writingArea).fontFamily || "initial";
D = D.replace(/'/g, "\\'"), S.find(".CodeMirror-line > span").each(function() {
! function t(e, n) {
if (e.nodeType == document.TEXT_NODE) {
var i = e.textContent;
(i = i.split(/(;|-)/).map(function(t) {
return ";" == t || "-" == t ? "<span style='font-family:" + n + "'>" + t + "</span>" : c.escape(t)
}).join("")) != e.textContent && (e.innerHTML = i)
} else 1 == e.nodeType && e.childNodes.forEach(function(e) {
t(e, n)
})
}(this, D)
})
}
return S[0].outerHTML;
case u.html_block:
return d.buildHTMLForExport(t, b, r);
case u.math_block:
return k.getSVGForExport(t, p);
case u.hr:
return "<hr />";
case u.def_footnote:
case u.def_link:
return "";
case u.table:
t.get("align").length;
for (var L = "<figure><table>" + w, R = t.getFirstChild(); R;) R.get("before") ? L += _(R) : L += "<thead>" + w + _(R) + "</thead>" + w + "<tbody>", (R = R.get("after")) || (L += "</tbody>" + w);
return L += "</table></figure>";
case u.table_row:
L = "<tr>", R = t.getFirstChild();
for (var B, I = t.get("parent").get("align"), N = 0, O = t.get("before") ? "td" : "th"; R;) L += "<" + O + (B = (B = I[N]) ? " style='text-align:" + B + ";' " : "") + ">" + _(R) + "</" + O + ">", R = R.get("after"), N++;
return L += "</tr>";
case u.table_cell:
return x(t, i) || "&nbsp;";
case u.meta_block:
return "";
case u.toc:
return function() {
if (o) return "<div>[TOC]</div>";
if (!e) {
var t = m(document.querySelector(".md-toc-content")).clone();
t.find("[data-ref]").each(function() {
this.querySelector("a").setAttribute("href", (r && File.isMac ? "at://" : "#header-") + this.getAttribute("data-ref"))
}), t.find(".md-meta").remove(), e = "<div class='md-toc' mdtype='toc'>" + t[0].outerHTML + "</div>"
}
return e
}();
default:
return "<p>" + x(t, i) + "</p>"
}
var j, P
}
if ("string" == typeof t) return x(t);
if (t.length) {
var $ = t instanceof Array,
E = $ ? t[0] : t.sortedFirst();
do {
y += _(E) + w, E = E.get("after")
} while (E && (!$ || t.indexOf(E) > -1))
}
return y + (a ? F(e) : "")
},
getSVGForExport: function(t, e) {
var n = this.editor.findElemById(t.id),
i = n.width(),
r = n.find("svg"),
o = [r.width(), r.height()],
a = n.find(".MathJax_SVG").width();
if (e) {
var s = n.find(".MathJax_SVG").clone();
return function(t, n) {
if (t && n) {
var i = (t.getAttribute("viewBox") || "").split(" ");
if (i && 4 === i.length) {
i = i.map(function(t) {
return t - 0
});
var r = t.getBoundingClientRect(),
o = t.querySelector("g").getBoundingClientRect();
i[0] = i[0] + (o.left - r.left) / r.width * i[2], i[2] = o.width / r.width * i[2], n.setAttribute("viewBox", i.join(" ")), e ? n.setAttribute("width", Math.min(o.width, 640)) : n.setAttribute("width", o.width)
}
}
}(n.find("svg")[0], s.find("svg")[0]), s[0] ? h.processExportedSVG(s[0].outerHTML) : "<p class='md-math-block'>$$" + c.escape(t.get("text")) + "$$</p>"
}
return (n = n.clone()).find(".md-rawblock-tooltip").remove(), n.find("svg").attr("width", o[0] + "px").attr("height", o[1] + "px").css("max-width", "100%"), i < a - 10 && n.find(".MathJax_SVG").css("zoom", i / a), n.length ? h.processExportedSVG(n[0].outerHTML) : "<p class='md-math-block'>{math}</p>".replace("{math}", "$$\n" + c.escape(t.get("text")) + "\n$$")
},
exportToHTML: function(t) {
var e = (t = t || {}).forPrint,
n = t.noStyle,
i = t.noBackground,
r = t.forImage,
o = t.extraCss,
a = this.editor.nodeMap,
s = this.editor,
u = [],
l = File.editor.docMenu.getValueInMeta("title") || (File.getFileName() || "").replace(/\.(md|mmd|markdown|txt|text)$/i, ""),
f = File.option.enableDiagram && m(".md-fences[lang='mermaid']").length,
h = Object.keys(File.editor.fences.queue).length,
d = "";
File.option.showLineNumbersForFence && s.fences.refreshEditor(!0);
function v(t, e) {
if (!t) return "";
e = e || [];
var n, i = /^\s*@include-when-export\s+(url)?([('"]+)([^\)"']+)([)'"]+)/im;
function r(t) {
File.isMac ? t && e.push(c.getFilePathFromMacProxy(t)) : t && e.push(t)
}
try {
(n = t.match(/^\s*@include-when-export\s.+$/gim)) && n.map(function(t) {
r((i.exec(t) || [])[3])
})
} catch (t) {}
i = /^\s*@import\s+(url)?([('"]+)([^\)"']+)([)'"]+)/im;
try {
(n = t.match(/^\s*@import\s.+$/gim)) && n.map(function(t) {
r((i.exec(t) || [])[3])
})
} catch (t) {}
return e.map(function(t) {
return "<link href='" + t + "' rel='stylesheet' type='text/css' />"
}).join("\n")
}
function p(t) {
return File.isMac ? bridge.callSync("path.readText", t) : File.isNode ? reqnode("fs").readFileSync(t, "utf-8") : void 0
}
return function(t, a) {
a = c.escape(a) || "";
var s = File.option.splitPages;
u.length && (t += "<div class='footnotes-area' " + (e ? "data-breakpage" : "") + " ><hr/>" + F(u) + "</div>");
var l = e ? "<script> window.setBreakPage = function(b){var node = document.querySelectorAll('[data-breakpage]'); for(var i=0;i<node.length;i++){node[i].style.pageBreakBefore = b ? 'always':'' }}; setBreakPage(" + (s ? "true" : "false") + ");<\/script>" : "",
y = File.isMac ? "is-mac" : "is-node",
w = r ? File.option.imageExportFontSize : document.body.parentElement.style.fontSize || "";
if (w && (w = " style='font-size:" + w + " !important'"), e && File.isMac && (l += "<script>(" + b.toString() + ")();<\/script>"), e && (l += "<script>(" + g.toString() + ")();<\/script>"), n) return "<!doctype html>\n<html>\n<head>\n<meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'>\n<title>" + a + "</title></head>\n<body>" + t + "</body>\n</html>";
var k = function() {
var t, n, o, a = [];
if (d = "", e) {
if (document.querySelectorAll("link[css-include]").forEach(function(t) {
d += "<link rel='stylesheet' href='" + c.escapeInQuote(t.href) + "' type='text/css' />"
}), !r && File.colorBrightness < .5 && File.isNode) {
var s = reqnode("electron").remote.app.getPath("userData");
d += ["github.css", "base.user.css", "github.user.css"].map(function(t) {
return "<link rel='stylesheet' href='file:///" + c.escapeInQuote(s + "/themes/" + t) + "' type='text/css' />"
}).join("\n")
} else !r && File.colorBrightness < .5 && i && File.isMac ? d += ["github.css", "base.user.css", "github.user.css"].map(function(t) {
return "<link rel='stylesheet' href='http://typora-theme/" + c.escapeInQuote(t) + "' type='text/css' />"
}).join("\n") : d += ["theme_css", "base_user_css", "theme_user_css"].map(function(t) {
return File.isMac ? "<link rel='stylesheet' href='" + c.escapeInQuote(m("#" + t).attr("href")) + "' type='text/css' />" : "<link rel='stylesheet' href='file://" + (File.isWin ? "/" : "") + c.escapeInQuote(m("#" + t).attr("href")) + "' type='text/css' />"
}).join("\n");
return ""
}
function u(t) {
for (var e in t.cssRules) {
var n = t.cssRules[e];
if (n.styleSheet) {
if (n.href.match(/mermaid/i) && !f) continue;
if (n.href.match(/sourcemode\.dark\.css/i)) continue;
u(n.styleSheet)
} else /@font\-face/.exec(n.cssText || "") || a.push((n.cssText || "").replace(/content: ([^;]{1});/g, "content: '$1';"))
}
}
var l, g, b;
File.isMac && (o = ["theme_css", "base_user_css", "theme_user_css"].map(function(t) {
return g = [], b = c.getFilePathFromMacProxy(m("#" + t).attr("href")).replace(/^file:\/\//, ""), v(l = p(b), g), g.forEach(function(t) {
(/^\/\//.exec(t) || /.+:\/\//.exec(t)) && (d += "<link href='" + t + "' rel='stylesheet' type='text/css' />")
}),
function t(e, n) {
var i = /^["']/,
r = [];
File.isMac && (n = c.getFilePathFromMacProxy(n).replace(/^file:\/\/?/, ""));
function o(e) {
var o = (e.match(i) || [""])[0];
return e = decodeURI(o.length ? e.substring(1, e.length - 1) : e), (e = c.getAbsolutePath(n, e)).match(/\.css$/) ? (r.push(t(p(e), e)), e = "") : e = (File.isMac ? "file://" : "file:///") + e, o + encodeURI(e) + o
}
return e = (e || "").replace(/@font\-face\s*{[^}]+}\s*\n/g, "").replace(/(^|;|\n)[\s]*@import([^;\n]+)(;|$|\n)/g, function(t, e) {
var n = (/['"]([^"']+)['"]/.exec(t) || [])[0];
return n ? t.replace(n, o(n)) : t
}).replace(/url\([^:)]+\)/gi, function(t) {
return "url(" + o(t = t.substring(4, t.length - 1)) + ")"
}), e = r.join("\n") + e
}(l, b)
}).join("\n")), n = ["(base\\.css)"], o || n.push("(theme)"), h && n.push("(codemirror)"), f && n.push("(mermaid)"), n = new RegExp(n.join("|"), "i");
for (var y = 0; y < document.styleSheets.length; y++)
if (t = document.styleSheets[y], n.exec(t.href) && (u(t), /themes/.exec(t.href))) try {
var w = t.href;
File.isMac && (w = c.getFilePathFromMacProxy(w));
var F = decodeURI(w.replace(File.isWin ? /^[\w_-]+:[\/]+/ : /^[\w_-]+:\/\/?/, ""));
d += v(p(F))
} catch (t) {}
return o && a.push(o), a.join("\n")
}(),
x = ["typora-export"];
return r && (x.push("for-image"), k += " ::-webkit-scrollbar {display: none;} "), File.option.preLinebreakOnExport || (k += " .typora-export li, .typora-export p, .typora-export, .footnote-line {white-space: normal;} "), File.option.indentFirstLine && (y += " first-line-indent"), document.body.classList.contains("os-windows") && (x.push("os-windows"), File.option.monocolorEmoji && x.push("monocolor-emoji")), o && (k += " " + o), "<!doctype html>\n<html" + w + (e ? " class='blink-to-pdf' " : "") + ">\n<head>\n<meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'>\n<title>" + a + "</title>" + d + "<style type='text/css'>html {overflow-x: initial !important;}" + k + "\n</style>\n</head>\n<body class='" + x.join(" ") + "' >\n<div id='write' " + (e ? "style='top:auto'" : "") + " class = '" + y + "'>" + t + "</div>\n" + l + "</body>\n</html>"
}(this.exportCollection(a.blocks, u, {
forPrint: e,
noStyle: n,
forImage: r
}), l)
},
cleanUpTempFiles: function() {}
});
function F(t) {
return t.map(function(t) {
return "<div class='footnote-line'>" + t.join("") + "</div>"
}).join("\n")
}
var k = function(t, e) {
var n = m.localize.getString(File.isMac ? "Reveal in Finder" : "Reveal in File Explorer", "Front"),
i = "pdf" == t ? "Export to PDF successfully." : "Export operation finished successfully.";
i = m.localize.getString(i, "Panel"), h.showNotification(i, !1, n, function() {
JSBridge.showInFinder(e)
}), File.isMac && File.editor.export.cleanUpTempFiles()
};
w.onExportSuccess = k, n.exports = w
}), $__System.registerDynamic("3d", ["1f"], !0, function(t, e, n) {
this || self;
var i = t("1f"),
r = "CodeMirror-activeline",
o = "CodeMirror-activeline-background",
a = "CodeMirror-activeline-gutter";
i.defineOption("styleActiveLine", !1, function(t, e, n) {
var r = n != i.Init && n;
e != r && (r && (t.off("beforeSelectionChange", c), s(t), delete t.state.activeLines), e && (t.state.activeLines = [], u(t, t.listSelections()), t.on("beforeSelectionChange", c)))
});
function s(t) {
for (var e = 0; e < t.state.activeLines.length; e++) t.removeLineClass(t.state.activeLines[e], "wrap", r), t.removeLineClass(t.state.activeLines[e], "background", o), t.removeLineClass(t.state.activeLines[e], "gutter", a)
}
function u(t, e) {
for (var n = [], i = 0; i < e.length; i++) {
var u = e[i],
c = t.getOption("styleActiveLine");
if ("object" == typeof c && c.nonEmpty ? u.anchor.line == u.head.line : u.empty()) {
var l = t.getLineHandleVisualStart(u.head.line);
n[n.length - 1] != l && n.push(l)
}
}(function(t, e) {
if (t.length != e.length) return !1;
for (var n = 0; n < t.length; n++)
if (t[n] != e[n]) return !1;
return !0
})(t.state.activeLines, n) || t.operation(function() {
s(t);
for (var e = 0; e < n.length; e++) t.addLineClass(n[e], "wrap", r), t.addLineClass(n[e], "background", o), t.addLineClass(n[e], "gutter", a);
t.state.activeLines = n
})
}
function c(t, e) {
u(t, e.ranges)
}
}), $__System.registerDynamic("3e", ["1f"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("1f");
i.defineOption("visibleSpace", !1, function(t, e, n) {
n == i.Init && (n = !1), n && !e ? t.removeOverlay("visiblespace") : !n && e && t.addOverlay({
token: function(t, e) {
if (!e) return null;
if (e.atBlockStart && t.pos < e.atBlockStart) return t.eat(" ") ? "startspace startspace-" + (t.pos - 1) : t.eat("\t") ? "starttab startspace-" + (t.pos - 1) : (t.pos++, null);
var n = /(^[ \t]+)|(\s+$)/.exec(t.string),
i = t.string.length,
r = n && n[1] ? n[1].length : -1;
n && n[2] && n[2].length;
return r > 0 && r > t.pos ? (t.pos++, "startspace-" + (t.pos - 1) + ("\t" == t.string.charAt(t.pos - 1) ? " starttab" : " startspace")) : (t.pos = i, null)
},
name: "visiblespace"
})
})
}), $__System.registerDynamic("3f", ["1f", "3d", "3e", "e", "12", "13", "14", "19", "1b"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("1f"),
r = (t("3d"), t("3e"), t("e")),
o = (t("12"), t("13")),
a = t("14"),
s = t("19"),
u = t("1b"),
c = window.reqnode ? reqnode("electron").remote : null,
l = o.Node,
f = o.TYPE,
h = r("#typora-source"),
d = (r("#toggle-sourceview-btn"), !1),
m = function(t) {
this.editor = t, this.cm = null, this.inSourceMode = !1, this.renderedHTML = ""
};
m.prototype.prep = function() {
if (!this.cm) {
var t = this;
this.cm = i(document.querySelector("#typora-source"), {
lineWrapping: !0,
mode: "gfm",
theme: "typora-default",
styleSelectedText: !0,
maxHighlightLength: 1 / 0,
styleActiveLine: !0,
visibleSpace: !0,
viewportMargin: 100,
autoCloseBrackets: !0,
autoCloseTags: !0,
resetSelectionOnContextMenu: !1,
extraKeys: {
Enter: "newlineAndIndentContinueMarkdownList"
},
lineNumbers: !0,
dragDrop: !1,
indentUnit: File.option.codeIndentSize,
tabSize: File.option.codeIndentSize
}, this.editor), h.css("z-index", "2");
var e = this.editor;
this.cm.on("changes", function(n, i) {
if (t.inSourceMode && (document.querySelector(".on-search-panel-open") && "+findReplace" !== i[0].origin && "setValue" !== i[0].origin && t.editor.searchPanel.closePanel(), "begin" !== i[0].origin && "sync" !== i[0].origin)) {
d = !0;
var r = File.editor.sourceView.cm.doc.historySize();
JSBridge.menu.update({
"Edit→Undo": {
enabled: !File.isLocked && r.undo > 0
},
"Edit→Redo": {
enabled: !File.isLocked && r.redo > 0
}
}), "fromDisk" !== i[0].origin && File.updateChangeCount(File.ChangeType.NSChangeDone), e.syncChange([{
type: "sync",
srcChanges: i
}]), File.needsUpdateSnap()
}
}), this.cm.on("contextmenu", function(e, n) {
if (t.inSourceMode) {
var i = e.getCursor("from"),
r = e.getCursor("to");
setTimeout(function() {
e.setSelection(i, r, {
scroll: !1
})
}, 180), File.isNodeHtml && File.contextMenu.show(n)
}
}), this.cm.on("cursorActivity", function(n, i) {
t.inSourceMode && (File.isFocusMode && e.updateFocusMode(!0), File.isTypeWriterMode && t.scrollAdjust(), File.isNodeHtml && File.contextMenu.hide(i))
}), this.cm.on("scrollCursorIntoView", function(e, n) {
t.inSourceMode && !File.isTypeWriterMode || n.preventDefault()
}), this.cm.display.scroller.addEventListener("wheel", function(t) {
Math.abs(t.deltaY) < 4 || File.isFocusMode && File.isTypeWriterMode && e.updateFocusMode(!1)
}, {
passive: !0
})
}
}, m.prototype.show = function() {
File.sync();
var t, e = this.editor.getMarkdown();
try {
t = x.call(this)
} catch (e) {
t = null, console.warn(e.stack)
}
this.editor.refocus(null), this.editor.cleanTooltip(), this.editor.searchPanel.closePanel(!0), this.inSourceMode = !0, File.isNode && c.getCurrentWindow().setInSourceMode(!0), r("body").addClass("typora-sourceview-on");
var n = r("content");
r("body").find(".md-tooltip-hide, #md-notification").hide(), n.find(".auto-suggest-container.ty-show").removeClass("ty-show"), this.renderedHTML = "", this.prep(), this.cm.setValue(e, "begin"), d = !1, h.show(), _.call(this, t), this.cm.refresh(), this.cm.focus(), this.cm.getDoc().clearHistory(), this.cm.options.readOnly = File.isLocked, this.enableTypeWriterMode(File.isTypeWriterMode)
};
var v;
m.prototype.enableTypeWriterMode = function(t) {
if (this.cm) {
if (t) {
var e = this.cm.defaultTextHeight();
v = document.querySelector("content").clientHeight, this.cm.display.lineSpace.parentNode.style.paddingTop = (v - e) / 2 + "px", this.cm.display.lineSpace.parentNode.style.paddingBottom = (v - e) / 2 + "px"
} else this.cm.display.lineSpace.parentNode.style.paddingTop = "", this.cm.display.lineSpace.parentNode.style.paddingBottom = "";
this.scrollAdjust()
}
}, m.prototype.setValue = function(t, e, n) {
this.cm && (this.cm.setValue(t, n || "begin"), e && (d = !0))
}, m.prototype.onSave = function() {
if (this.cm.doc.history.lastModTime = 0, d) {
var t = this.cm.getScrollInfo().top;
File.reloadContent(this.cm.getValue(File.useCRLF ? "\r\n" : "\n"), !1, !0, !1, !0), this.cm.scrollTo(0, t)
}
}, m.prototype.hide = function() {
var t = this.editor;
t.searchPanel.closePanel(), r("body").removeClass("typora-sourceview-on"), this.inSourceMode = !1, File.isNode && c.getCurrentWindow().setInSourceMode(!1);
var e = this.cm.getCursor();
e.lineText = this.cm.getLine(e.line),
function(t) {
var e = t.lineText.substring(0, t.ch);
t.inRef = e.match(b) && !e.match(y), t.textBefore = e
}(e), d && (File.isMac && !app.document.isDocumentEdited() && this.renderedHTML ? (r(File.editor.sessionStr).html(this.renderedHTML), setTimeout(function() {
File.editor.refresh()
}, 500), File.editor.syncChange([{
type: "sync",
allHtml: this.renderedHTML,
json: u.buildAllDoc(File.editor.nodeMap).json
}])) : File.reloadContent(this.cm.getValue(File.useCRLF ? "\r\n" : "\n"), !1, !0, !1, !0)), h.hide(), k.call(this, e), t.selection.scrollAdjust()
}, m.prototype.scrollAdjust = function() {
var t = this.cm;
if (File.isTypeWriterMode) {
var e = t.cursorCoords(!0, "window"),
n = e.top - (v + e.bottom - e.top) / 2;
Math.abs(n) > 2 && t.scrollTo(null, t.getScrollInfo().top + n)
} else {
var i = this.cm.charCoords(this.cm.getCursor(), "local").top,
r = this.cm.getScrollerElement().offsetHeight / 2;
this.cm.scrollTo(null, i - r - 5)
}
};
function p(t, e) {
var n = "number" == typeof t ? t : t.get("tail");
return void 0 === n ? void 0 === e ? t.get("after") ? 1 : 0 : e : n
}
function g(t, e) {
function n(t, e) {
return t.get("children").toArray().reduce(function(t, n) {
return t + g(n, e)
}, 0)
}
function i(t) {
return l.isType(t.get("parent"), f.list_item) && !1 !== t.get("parent").get("tight")
}
switch (t.get("type")) {
case f.meta_block:
return 2 + t.get("text").match(/(\n|$)/g).length + p(t);
case f.heading:
return (t.get("ahead") || 0) + ((t.get("pattern") || (!l.isType(t.get("parent"), f.list_item) && (1 == File.option.headingStyle || 3 == File.option.headingStyle) && t.get("depth") <= 2 ? "===" : "#")).match(/[-=]/) ? 2 : 1) + p(t);
case f.paragraph:
var r = t.get("tail");
return (e || i(t)) && (r = 0), l.isType(t.get("after"), f.paragraph) && r < 1 && (t.unset("tail"), r = 1), void 0 !== r || !l.isType(t.get("after"), f.math_block) && t.get("after") || (r = 0), (t.get("ahead") || 0) + (t.get("text").split(/\n/g).length || 1) + p(void 0 === r ? t : r, r);
case f.blockquote:
return (t.get("ahead") || 0) + n(t) + p(t);
case f.list:
var o = t.get("ahead") || 0;
return t.isLoose(!0), o += n(t), l.isType(t.get("after"), f.list) && (!t.get("tail") || t.get("tail")) < 2 && t.get("pattern") == t.get("after").get("pattern") && t.get("style") == t.get("after").get("style") && (t.unset("tail"), o++, i(t) && o++), e || (o += p(t, i(t) ? 0 : 1)), o;
case f.list_item:
return t.toMark().split(/\n/).length;
case f.html_block:
return (t.get("ahead") || 1) + (t.get("text").match(/\n/g) || []).length + p(t);
case f.fences:
var a = /`|~/.exec(t.get("pattern") || "```");
return (t.get("ahead") || 0) + (a ? 3 : 1) + (t.get("text").match(/\n/g) || []).length + p(t);
case f.math_block:
return (t.get("ahead") || 0) + 3 + (t.get("text").match(/\n/g) || []).length + p(t, l.isType(t.get("before"), f.paragraph) && l.isType(t.get("after"), f.paragraph) ? 0 : 1);
case f.hr:
return p(t) + 1;
case f.toc:
return (t.get("ahead") || 0) + (t.get("pattern") || "").split(/\n/).length + p(t);
case f.def_footnote:
case f.def_link:
return (t.get("ahead") || 0) + 1 + p(t, !t.get("after") || l.isType(t.get("after"), l.TYPE.def_link) ? 0 : 1);
case f.table:
return (t.get("ahead") || 0) + t.get("children").length + 1 + p(t);
case f.table_row:
return t.get("before") ? 1 : 2;
case f.table_cell:
return 0;
default:
return 1
}
}
var b = /\[/,
y = /\]/;
var w = function(t, e, n, i) {
var r = null;
function o(t, e, n) {
return void 0 === n && (n = (n = e ? i.lineText.indexOf(t) : i.lineText.lastIndexOf(t)) < 0 ? 0 : n), Math.max(0, i.ch - n)
}
switch (e.get("type")) {
case f.paragraph:
for (var u = e.get("text").split(/\n/), c = 0, l = 0; l < n && l < u.length; l++) c += u[l].length + 1;
t.undo.exeCommand({
type: "cursor",
id: e.cid,
start: c + o(u[n])
});
break;
case f.heading:
t.undo.exeCommand({
type: "cursor",
id: e.cid,
start: function(t, e) {
var n = e;
for (var i in t) void 0 !== i && i <= e && (n += t[i]);
return n
}(e.cursorDiff || [], o(e.get("text")))
});
break;
case f.hr:
case f.toc:
e.get("after") ? t.selection.jumpIntoElemBegin(t.findElemById(e.get("after").getVeryFirst().cid)) : t.selection.selectNode(e);
break;
case f.math_block:
r = t.mathBlock.startEditing(e.cid), n--;
break;
case f.html_block:
r = t.htmlBlock.startEditing(e.cid);
break;
case f.fences:
(e.get("pattern") || "```").match(/`/) && n--, r = t.fences.getCm(e.cid);
break;
case f.def_link:
case f.def_footnote:
if (i.inRef) t.undo.exeCommand({
type: "cursor",
id: e.cid,
start: o(e.get("ref"), !0)
});
else {
var h = new RegExp("(]:\\s*)" + a.escapeRegExp(e.get("href") || e.get("text"))).exec(i.lineText),
d = h ? h.index + h[1].length : 0;
t.undo.exeCommand({
type: "cursor",
id: e.cid,
start: e.get("ref").length + o(void 0, void 0, d)
})
}
break;
case f.meta_block:
for (u = e.get("text").split(/\n/), d = i.ch, l = 0; l < n - 1; l++) d += (u[l] || "").length + 1;
t.undo.exeCommand({
type: "cursor",
id: e.cid,
start: d
});
break;
case f.table_row:
! function(t) {
var e = t.textBefore;
t.cellsBefore = s.splitTableCell(e.replace(/^\s*\|/, ""), !0) || [e], t.cellsOffset = t.cellsBefore.last().length, t.cellsBefore = t.cellsBefore.length
}(i), t.undo.exeCommand({
type: "cursor",
id: e.getNthChild(Math.max(0, i.cellsBefore - 1)).cid,
start: i.cellsOffset
});
break;
default:
t.selection.jumpIntoElemEnd(t.findElemById(e.getVeryFirst(!0).cid))
}
r && (r.focus(), n >= r.lineCount() ? r.execCommand("goDocEnd") : r.setCursor({
line: n,
ch: o(r.getLine(n))
}))
},
F = function(t, e, n, i) {
var r = 0;
for (n + (e.get("ahead") || 0) > i.line && t.selection.jumpIntoElemBegin(t.findElemById(e.getVeryFirst().cid)), r = g(e); e.get("after") && n + r <= i.line;) n += r, r = g(e = e.get("after"));
e.get("children").length && !l.isType(e, f.table_row) ? F(t, e.getFirstChild(), n + (e.get("ahead") || 0), i) : n + r - (o = e, l.isType(o, f.table_row) ? 0 : p(o)) > i.line ? w(t, e, i.line - n - (e.get("ahead") || 0), i) : t.selection.jumpIntoElemEnd(t.findElemById(e.getVeryFirst(!0).cid));
var o
};
m.prototype.gotoLine = function(t) {
var e = this.editor;
try {
F(e, e.nodeMap.getFirst(), 0, t)
} catch (t) {
console.warn(t.stack)
}
};
var k = function(t) {
var e = this.editor;
try {
F(e, e.nodeMap.getFirst(), 0, t)
} catch (t) {
console.warn(t.stack)
}
e.refocus()
},
x = function(t) {
if (this.editor.focusCid) {
var e = this.editor.findElemById(this.editor.focusCid),
n = this.editor.getNode(this.editor.focusCid),
i = 0,
o = "",
s = "",
u = this.editor.selection.getRangy();
if (n) {
if (i = function t(e, n) {
return n = n || 0, e ? e.get("before") ? t(e.get("before"), n + g(e.get("before"))) : e.get("parent") ? t(e.get("parent"), n + (e.get("parent").get("ahead") || 0)) : n : n
}(n) + (n.get("ahead") || 0), l.isType(n, f.fences)) {
var c = !/`|~/.exec(n.get("pattern") || "```");
return !c && i++, (t = document.activeElement.classList.contains("ty-cm-lang-input") ? {
line: -1,
before: n.get("pattern") || "```"
} : this.editor.fences.getCm(n.cid).doc.getCursor()).before = (c ? n.get("pattern") : "") + this.editor.fences.getCm(n.cid).getLine(t.line).substring(0, t.ch), t.line = t.line + i, t.ch = void 0, t
}
if (l.isType(n, f.math_block)) return this.editor.mathBlock.currentCm ? ((t = this.editor.mathBlock.currentCm.doc.getCursor()).line = t.line + i + 1, t) : {
line: i,
ch: -1
};
if (l.isType(n, f.toc)) return {
line: i,
before: "]"
};
if (l.isType(n, f.hr)) return {
line: i,
before: this.get("pattern") || "------"
};
if (l.isType(n, f.def_link, f.def_footnote)) {
var h, d = this.editor.getJQueryElem(u.startContainer);
if ((h = d.closest(".md-def-content")).length) return u.setStartBefore(h[0]), {
line: i,
before: o = "]: " + u.toString()
};
if ((h = d.closest(".md-def-title")).length && d.text().length) return u.setStartBefore(h[0]), {
line: i,
before: o = '"' + u.toString()
}
}
if (l.isType(n, f.table, f.table_row)) return {
line: i,
ch: -1
};
if (u.setStartBefore(e[0]), o = r(u.toHtml()).rawText(), l.isType(n, f.table_cell)) {
for (s = "", n = n.get("before"); n;) s = "\\|[^|]*" + s, n = n.get("before");
return {
line: i,
beforeRegExp: o = s + "\\|\\s*" + a.escapeRegExp(o)
}
}
if (l.isType(n, f.meta_block)) return {
line: i = ((o = o.replace(/^---/gm, "​---").replace(/\n$/g, "")).match(/\n/g) || []).length + 1,
before: o = o.substring(o.lastIndexOf("\\n"))
};
if (l.isType(n, f.html_block)) return this.editor.htmlBlock.currentCm ? ((t = this.editor.htmlBlock.currentCm.doc.getCursor()).line = t.line + i, t) : {
line: i + 2,
ch: -1
};
if ("" === o && l.isType(n, f.paragraph, f.heading)) {
if (l.isType(n, f.heading)) {
var m = n.toMark();
if (/^\s*#/.exec(m)) return {
line: i,
beforeRegExp: "^\\s*#+\\s*"
}
}
var v = n.getTopBlock();
if (l.isType(v, f.list, f.blockquote)) return {
line: i,
ch: 0,
afterIndent: !0
}
}
var p = o.split(/\n/) || [o];
return o = p.last(), {
line: i + p.length - 1,
before: o
}
}
}
},
_ = function(t) {
if (t) try {
var e = t.ch;
if (t.line < 0 && (t.line = this.cm.doc.lineCount() - 1), t.afterIndent) {
var n = this.cm.doc.getLine(t.line);
e = (/^((\s+)|([-+*]\s)|(\[( |x)\])|>|(\d+\.\s))+/i.exec(n) || [""])[0].length
}
if (void 0 === e) {
n = this.cm.doc.getLine(t.line) || "";
if (t.before) e = n.indexOf(t.before) + t.before.length;
else if (t.beforeRegExp) {
var i = new RegExp(t.beforeRegExp, "g");
i.exec(n), e = i.lastIndex
}
}
this.cm.doc.setCursor({
line: t.line,
ch: e > 0 ? e : 0
}), e < 0 && this.cm.execCommand("goLineEnd")
} catch (t) {
console.warn(t.stack)
}
};
n.exports = m
}), $__System.registerDynamic("40", ["e", "14", "26", "31"], !0, function(t, e, n) {
"use strict";
this || self;
var i, r = t("e"),
o = t("14"),
a = t("26").map,
s = t("31"),
u = window.reqnode ? reqnode("electron").remote : null,
c = u ? u.app : window.app,
l = function(t) {
this.editor = t, this.worker = null
},
f = r(r("#typora-quick-open-item-templ").html()),
h = r(r("#typora-quick-loading-item-templ").html()),
d = r(".typora-quick-open-list"),
m = r(".typora-quick-open-list-inner"),
v = r("#typora-quick-open-input input"),
p = [],
g = [],
b = [],
y = [],
w = 0,
F = [],
k = "",
x = [],
_ = 40,
$ = 8,
E = -1,
C = null,
A = null,
S = 0,
T = !0,
M = -1,
D = 20;
function L(t, e) {
File.isMac && (e ? bridge.callHandler("controller.openFolder", t) : bridge.callHandler("path.openFile", t)), File.isNode && (e ? c.openFolder(t, u.getCurrentWindow()) : c.openFileOrFolder(t, {
mountFolder: function(t, e) {
var n = File.isWin ? "\\" : "/";
return t && e && 0 == e.indexOf(t.replace(/[\/\\]$/, "") + n)
}(File.getMountFolder(), t) ? File.getMountFolder() : void 0
}))
}
function R(t, e, n, i) {
var r, a, s;
if (t.n) r = t.n, a = t.p.replace(/[\/\\][^\/\\]+$/, "") + (File.isWin ? "\\" : "/"), s = t.p;
else {
s = t;
var u = /[^\\\/]+$/.exec(t);
r = u[0], a = t.substring(0, u.index)
}
x.length && (r = r.replace(/</g, "").replace(/>/g, "").replace(new RegExp("((" + x.join(")|(") + "))", "gi"), function(t, e) {
return "<b>" + e.replace(/</g, "").replace(/>/g, "") + "</b>"
}).replace(/\uE27A/g, "&lt;").replace(/\uE27B/g, "&gt;").replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&#39;")), i && (r += File.isWin ? "\\" : "/");
var c, l = e.children(".typora-quick-open-info-item"),
h = f.find(".typora-quick-open-item-title").html(r).end().find(".typora-quick-open-item-path").text((c = a, !A && File.option.userPath && (A = new RegExp("^" + o.escapeRegExp(File.option.userPath))), (c = A ? c.replace(A, "~") : c).length > 60 ? c.substring(0, 30) + "..." + c.substring(c.length - 30, c.length) : c)).end().clone().attr("data-is-dir", i || !1).attr("data-path", s).attr("data-index", n + "").addClass(M == n ? "active" : "");
l.length ? l.before(h) : e.append(h).css("translate3d", "(0, 0, 0)")
}
l.prototype.init = function() {
this.bindEvent(), File.isMac ? (this.registerBridge(), bridge.callHandler("quickOpen.cacheRecentFiles")) : File.isNode && (this.initWorker(), T = !1, this.setRecentFiles((c.setting.getRecentDocuments() || []).map(function(t) {
return t.path
})), this.setRecentFolders((c.setting.getRecentFolders() || []).map(function(t) {
return t.path
})), this.cacheFolder(File.getMountFolder()), this.listenIpc())
}, l.prototype.registerBridge = function() {
var t = this;
bridge.registerHandler("quickOpen.initFileCache", function(e, n) {
t.initFileCache.apply(t, e || []), n && n()
}), bridge.registerHandler("quickOpen.updateResult", function(e, n) {
t.updateResult(e), n && n()
}), bridge.registerHandler("quickOpen.setSearchState", function(e, n) {
t.setSearchState(e), n && n()
}), bridge.registerHandler("quickOpen.setRecentFiles", function(e, n) {
t.setRecentFiles(e), n && n()
}), bridge.registerHandler("quickOpen.setRecentFolders", function(e, n) {
t.setRecentFolders(e), n && n()
}), bridge.registerHandler("quickOpen.updateCacheByRename", function(e, n) {
t.updateCacheByRename(e.src, e.dest), n && n()
}), bridge.registerHandler("quickOpen.updateCache", function(e, n) {
t.updateCache(e.toDel, e.toAdd, e.group), n && n()
})
}, l.prototype.bindEvent = function() {
var t = this;
v.on("input", function() {
var e = r(this).val();
e != k && (k = e.replace(/[()'"%\\\/.?]/, " "), H.call(t, k))
}).on("keydown", function(e) {
var n = e.keyCode || e.which;
if ("Esc" == a[n] || "o" == a[n] && e.shiftKey && e.metaKey) return t.close(), !1;
if ("Tab" == a[n]) return !1;
if ("Up" == a[n]) return I(-1), !1;
if ("Down" == a[n]) return I(1), !1;
if ("Enter" == a[n]) {
var i = r(".typora-quick-open-item.active")[0];
if (i) return L(i.dataset.path, i.dataset.isDir + "" == "true"), t.close(), !1
}
if (File.isMac && e.ctrlKey && !e.metaKey && !e.shiftKey) {
if ("P" == String.fromCharCode(n)) return I(-1), !1;
if ("N" == String.fromCharCode(n)) return I(1), !1
}
e.stopPropagation()
}).on("blur", function() {
setTimeout(t.close, 200)
}), d.on("mousedown", ".typora-quick-open-item", function(t) {
1 == t.which && L(this.dataset.path, this.dataset.isDir + "" == "true")
}).on("scroll", N)
}, l.prototype.listenIpc = function() {
var t = this;
reqnode("electron").ipcRenderer.on("updateQuickOpenCache", function(e, n) {
t.updateCache(n.toDel, n.toAdd, n.group)
})
};
function B(t) {
var e = 0;
return F.forEach(function(n) {
n < t && (e += 20)
}), e
}
function I(t) {
if (p.length) {
M = -1 == M ? 0 : (M + t) % p.length, r(".typora-quick-open-item.active").removeClass("active"), r(".typora-quick-open-item[data-index='" + M + "']").addClass("active");
var e = B(M),
n = M * _ + e,
i = d.scrollTop();
(n < i || n > i + _ * $ - 25) && d.scrollTop(Math.min(n, (p.length - $) * _ + B(p.length)) - 4)
}
}
function N(t, e) {
e = e || m;
var n = p.length - w;
function o(t) {
if (!(t < 0)) {
e.find("[data-block-index='" + t + "']").remove();
var o = r("<div class='quick-open-group-block' data-block-index='" + t + "'>").css("position", "absolute").css("top", t * D * 40 + "px").css("width", "100%");
if (i = Math.min(n + S, t * D + D + S), !(t * D > i)) {
for (var a = t * D; a < i; a++) a == n ? (s = n, o.append(h.clone().find(".typora-quick-open-info").text(r.localize.getString(s ? "Gathering more results" : "Searching")).end())) : R(p[a + w], o, a + w);
var s;
e.append(o)
}
}
}
var a = d.scrollTop(),
s = Math.floor(a / 40),
u = Math.floor(s / D);
u != E && (o((E = u) - 1), o(E), o(E + 1))
}
function O(t, e, n) {
if (t) {
var i = n.parent().show();
return e > 0 ? i.addClass("ty-has-prev") : i.removeClass("ty-has-prev"), !0
}
n.parent().hide()
}
function j(t, e, n, i) {
P(t), t.length && F.push(e), n.html(""), t.forEach(function(t, r) {
R(t, n, e + r, i)
}), O(t.length, e, n)
}
function P(t) {
C && M < 0 && (M = t.findIndex(function(t) {
return t.p == C
}))
}
function q(t) {
var e = (x = t.split(/\s+/).filter(o.isNotNullOrEmpty).map(function(t) {
return t.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace("*", ".*")
})).map(function(t) {
return new RegExp("(.)?" + t + "(.)?", "i")
});
p = [], F = [], M = -1, (File.filePath = s.getCurrentFilePath()) && (p = [File.filePath]);
var n, i, a = 0;
File.getMountFolder() ? (i = U(e, x.length ? b : b.slice(0, 12), p), n = U(e, x.length ? y : y.slice(0, 7), p)) : (n = U(e, x.length ? y : y.slice(0, 7), p), i = U(e, x.length ? b : b.slice(0, 12), p));
var u = U(e, g, p);
File.filePath && p.splice(0, 1), j(n, a, r("#ty-quick-open-folder-list-inner"), !0), j(i, a += n.length, r("#ty-quick-open-recent-list-inner")), a += i.length, l = a, E = -1, P(c = u), c.length && F.push(l), w = l, m.html("").height(_ * (c.length + S)), O(c.length + S, l, m) && (0 == w ? m.prev().css("height", "0") : m.prev().css("height", "auto")), N(0, m);
var c, l;
if ((a += u.length) > 0 && !r(".typora-quick-open-item.active").length) {
var f = r(".typora-quick-open-item")[0];
f && f.classList.add("active")
}
}
function U(t, e, n) {
n = n || [];
var i = File.getMountFolder() + (File.isWin ? "\\" : "/"),
r = [],
o = [];
return t.length ? (e.forEach(function(e) {
var a, s = 0;
if (!(n.indexOf(e.p) > -1)) {
for (var u = 0; u < t.length; u++) {
if (!(a = z(e.n, t[u]))) return;
s += a
}
0 == e.p.indexOf(i) && (s += 1.5), e.s = s, r.push(e), o.push(e.p)
}
}), r.sort(function(t, e) {
var n = e.s - t.s;
return n || e.d - t.d
})) : ((r = e.filter(function(t) {
return -1 == n.indexOf(t.p)
})).sort(function(t, e) {
var n = (0 == e.p.indexOf(i) ? 1 : 0) - (0 == t.p.indexOf(i) ? 1 : 0);
return n || e.d - t.d
}), o = r.map(function(t) {
return t.p
})), n.splice.apply(n, [n.length, 0].concat(o)), r
}
function z(t, e) {
t = o.removeDiacritics(t);
var n = e.exec(t);
return n ? (n[1] = n[1] || "", n[3] = n[3] || "", 4 - n[1].length - (/\w/.test(n[1]) ? 1 : 0) - (/\w/.test(n[3]) ? 1 : 0)) : 0
}
function H(t) {
C = p[M], T ? (this.setSearchState(1), File.isMac && bridge.callHandler("quickOpen.query", t), File.isNode && File.e && this.worker.postMessage(["quickFind", File.e, t])) : this.setSearchState(0), q.call(this, t), File.isMac && bridge.callHandler("quickOpen.reindexFolderIfNeeded")
}
l.prototype.stopQuery = function() {
File.isMac && bridge.callHandler("quickOpen.stopQuery"), File.isNode && this.worker.postMessage(["stopQuery"])
}, l.prototype.initWorker = function() {
this.worker = new Worker("app/finder-worker.js");
var t = this;
this.worker.onmessage = function(e) {
switch (e.data.type) {
case "initFileCache":
t.initFileCache.apply(t, e.data.detail);
break;
case "addInitFiles":
t.addInitFiles.apply(t, e.data.detail);
break;
case "removeInitFiles":
t.removeInitFiles.apply(t, e.data.detail);
break;
case "queryMatch":
t.updateResult.apply(t, e.data.detail);
break;
case "queryEnd":
t.setSearchState.apply(t, [0])
}
}
}, l.prototype.cacheFolder = function(t) {
T = !0, g = [], File.isNode && this.worker.postMessage(["listAllFiles", t])
}, l.prototype.show = function() {
var t = r("#typora-quick-open:not(:visible)").show();
this.editor.searchPanel.closePanel(!0), t.length && (v[0].select(), M = -1, H.call(this, v.val().replace(/[()'"%\\\/.?]/, " ")))
}, l.prototype.close = function() {
r("#typora-quick-open:visible").hide().length && File.isMac && bridge.callHandler("quickOpen.stopQuery"), M = -1
}, l.prototype.appendResultAtEnd = function(t, e) {
var n = m.children().last();
return !!(n.hasClass("quick-open-group-block") && n[0].childElementCount + t.length <= D) && (t.forEach(function(t, i) {
R(t, n, e + i)
}), !0)
}, l.prototype.updateResult = function(t) {
t = t.filter(function(t) {
return -1 == p.indexOf(t)
});
var e = p.length;
t.length && (p = p.concat(t), m.height(_ * (p.length - w + S)), p.length - e == t.length && this.appendResultAtEnd(t, e) || (E = -1, m.html(""), N(0, m)))
}, l.prototype.addInitFiles = function(t, e, n) {
g = g.concat(t.map(function(t, i) {
return {
n: e[i],
p: t,
d: n[i]
}
}))
}, l.prototype.removeInitFiles = function(t) {
var e = t.length;
g = g.filter(function(n) {
return n.p.substring(0, e) != t
})
}, l.prototype.initFileCache = function(t, e, n, i, o) {
g = t.map(function(t, i) {
return {
n: e[i],
p: t,
d: n[i]
}
}), o && (b = o.map(function(t) {
return {
n: (/[^\\\/]+$/.exec(t) || [])[0] || "",
p: t
}
})), T = i > t.length, r("#typora-quick-open:visible").length && 0 == x.length && this.updateResult(g)
}, l.prototype.updateCache = function(t, e, n) {
var i = File.isWin ? "\\" : "/";
if (t && [b, y].forEach(function(e) {
e.removeIf(function(e) {
return e.p != t && 0 != (t + i).indexOf(e.p)
})
}, this), e && e != File.filepath) {
var r = {
recentFiles: b,
recentFolders: y
}[n];
r.removeIf(function(t) {
return t.p == e
}), r.unshift({
n: (/[^\\\/]+$/.exec(e) || [])[0] || "",
p: e
})
}
}, l.prototype.updateCacheByRename = function(t, e) {
var n = File.isWin ? "\\" : "/",
i = [b, y];
File.isNode && i.push(g), i.forEach(function(i) {
i.forEach(function(i) {
i.p != t && 0 != i.p.indexOf(t + n) || (i.p = e + i.p.substring(t.length), i.n = (/[^\\\/]+$/.exec(i.p) || [])[0] || "")
})
}, this)
}, l.prototype.setRecentFiles = function(t) {
b = t.map(function(t) {
return {
n: (/[^\\\/]+$/.exec(t) || [])[0] || "",
p: t
}
})
}, l.prototype.setRecentFolders = function(t) {
y = t.map(function(t) {
return {
n: (/[^\\\/]+$/.exec(t) || [])[0] || "",
p: t
}
})
}, l.prototype.setSearchState = function(t) {
S !== t && (t && i == p.length - w ? (r(".typora-quick-open-item:last").after(h.clone().find(".typora-quick-open-info").text(r.localize.getString(i ? "Gathering more results" : "Searching")).end()), i++) : t || (r(".typora-quick-open-info-item").remove().length && m.height(m.height() - 40), i == p.length - w + 1 && i--), S = t)
}, n.exports = l
}), $__System.registerDynamic("41", ["12", "14", "13", "1b", "1c"], !0, function(t, e, n) {
"use strict";
this || self, t("12"), t("14");
var i = t("13"),
r = t("1b"),
o = i.Node,
a = i.TYPE,
s = i.NodeCollectionUtils,
u = (t("1c"), function(t, e) {
if (e(t)) return t;
var n = t.get("parent");
return n ? u(n, e) : null
}),
c = function(t, e) {
if (o.isType(t, a.list) && o.isType(t.get("before"), a.list) && t.get("style") == t.get("before").get("style")) return t.get("before").appendTillEnd(t.getFirstChild(), !0), t.remove(), e && e.remove.push(t.cid), !0
};
function l(t, e) {
var n, i;
if (!t) return t;
if (o.isType(t.get("before"), a.list)) return t;
if (!(n = u(t, function(t) {
return o.isType(t.get("parent"), a.list_item)
})) && e)
for (i = e; i;) {
if (i == t || i.contains(t)) return i;
i = i.get("after")
}
return n
}
function f(t) {
return t ? u(t, function(t) {
return o.isType(t.get("parent"), a.list_item)
}) : t
}
function h(t) {
return u(t, function(t) {
return o.isType(t.get("parent"), a.blockquote)
})
}
function d(t, e) {
return t ? t.get("after") ? e(t.get("after").getVeryFirst()) : d(t.get("parent"), e) : null
}
var m = function(t, e, n, i, s, u) {
u = u || {
replace: [],
remove: []
};
function f(t) {
var e, n, s, l = t.get("before");
if (o.isType(l, a.list)) return s = t.get("after"), i.undo.push(r.buildReplaceUndo(l)), r.addUndoForRemove(i, t), l.getLastChild().getLastChild().set("tail", l.get("tail") || l.getLastChild().get("tail") || l.getLastChild().getLastChild().get("tail")), v(l, 2), l.getLastChild().append(t), v(t), o.isType(s, a.list) && s.get("style") == l.get("style") && (r.addUndoForRemove(i, s), c(s, u)), i.redo.push(r.buildReplaceUndo(l)), u.remove.push(t.cid), u.replace.push(l), !0;
if (n = (e = t.get("parent")).get("before"), !l && n) {
var f = n.getLastChild();
return i.undo.push(r.buildReplaceUndo(n)), o.isType(f, a.list) ? (f.getLastChild().set("tail", n.get("tail") || f.get("tail")), n.set("tail", t.get("tail"))) : (n.getLastChild().set("tail", n.get("tail")), v(n), (f = e.get("parent").clone()).unset("start"), v(f), n.append(f), n.set("tail", t.get("tail")), v(t)),
function(t, e, n) {
var o, a = n.get("parent");
r.addUndoForRemove(i, a), o = n.get("after"), t.append(a), o && (o.set("before", null), e.set("tail", a.get("tail")), v(a), e.appendTillEnd(o), v(e.getLastChild(), 2), c(o, u));
v(a, 2), i.redo.push(r.buildReplaceUndo(e)), u.remove.push(a.cid), u.replace.push(e)
}(f, n, t), !0
}
}
var h, p, g, b = e.get("parent");
if (e.get("before")) g = f(e);
else {
if (!b.get("before")) {
if (h = (p = b.get("parent")).get("before"), !o.isType(h, a.list) || h.get("style") != p.get("style")) return !1;
i.undo.push(r.buildReplaceUndo(h)), r.addUndoForRemove(i, p), h.getLastChild().set("tail", Math.min(h.get("tail"), 1)), h.set("tail", p.get("tail")), c(p, u), i.redo.push(r.buildReplaceUndo(h)), u.remove.push(p.cid), u.replace.push(h)
}
s.containsNode(document.querySelector("[cid='" + b.getLastChild().cid + "']"), !0) ? (g = function(t) {
var e, n = t.get("before");
return !!n && (i.undo.push(r.buildReplaceUndo(n)), e = n.getLastChild(), o.isType(e, a.list) ? e.getLastChild().set("tail", n.get("tail") || e.get("tail")) : ((e = n.get("parent").clone()).unset("start"), n.getLastChild().set("tail", n.get("tail")), n.append(e), v(e)), r.addUndoForRemove(i, t), e.append(t), n.set("tail", t.get("tail")), v(t, 2), i.redo.push(r.buildReplaceUndo(n)), u.remove.push(t.cid), u.replace.push(n), !0)
}(b), e = b) : g = f(e)
}
return !g || e == n || e.contains(n) || n.contains(e) || (e = d(e, l)) && m(t, e, n, i, s, u), g && u
};
function v(t, e) {
for (e = e || 1; e > 0 && t;) t.unset("tail"), t = t.getLastChild(), e--
}
var p = function(t, e, n, i, o, a) {
a = a || [];
function u() {
var t, n, o = e.get("parent"),
u = {},
c = [];
u.oldCid = o.cid, i.undo.push(r.buildReplaceUndo(o)), e.get("before") ? (n = [e], c.push(o), e.get("after") && (t = o.clone(), n.push(t), t.appendTillEnd(e.get("after")), o.insert(t)), o.insert(e), o.set("tail", o.getLastChild().get("tail")), v(o.getLastChild()), c.push(e), t && c.push(t), i.redo.push(r.buildReplaceUndo(o)), r.addUndoForInsertArray(i, n)) : (r.addUndoForRemove(i, e), o.insert(e, !0), r.addUndoForInsert(i, e), c.push(e), o.get("children").length ? (i.redo.push(r.buildReplaceUndo(o)), c.push(o)) : (r.addUndoForRemove(i, o), o.remove())), u.html = s.toHTML(c), a.push(u)
}
for (u(); e && e != n && !e.contains(n) && !n.contains(e);) e && (e = d(e, h)), u();
return a
},
g = function(t, e) {
for (var n = [], i = t; i != e;) n.push(i), i = i.get("after");
return e && n.push(e), n
},
b = function(t, e, n, i, u, l) {
l = l || [];
var h, m, p, y = e.get("before"),
w = e.get("parent"),
F = {};
if (y) m = e.getLastBrother(), i.undo.push(r.buildReplaceUndo(w)), F.oldCid = w.get("parent").cid, w.get("after") && (p = g(w.get("after")), r.addUndoForRemoveArray(i, p), (h = w.get("parent").clone()).unset("start"), w.get("parent").set("tail", w.getLastChild().get("tail")), v(w, 2), h.appendTillEnd(w.get("after")), w.append(h), c(h)), v(e.get("before")), p = g(e), w.get("parent").insertTillEnd(e), i.redo.push(r.buildReplaceUndo(w)), r.addUndoForInsertArray(i, p), e = m, p.unshift(w.get("parent")), F.html = s.toHTML(p), l.push(F);
else {
var k = w.get("parent").get("parent"),
x = k && k.get("parent");
if (!o.isType(x, a.list)) return !1;
if (w.get("parent").get("before") || w.get("before")) {
if (i.undo.push(r.buildReplaceUndo(x)), m = w.getLastChild(), !u.containsNode(document.querySelector("[cid='" + w.getLastChild().cid + "']"), !0) && o.isType(n.get("before"), a.list)) {
var _ = n.get("before");
_.getLastChild().getLastChild().set("tail", _.get("tail"), _.getLastChild().get("tail")), v(_, 2), _.set("tail", n.getLastBrother().get("tail")), v(n.getLastBrother()), _.getLastChild().appendTillEnd(n)
}! function() {
var t, e;
if (w.get("after")) {
(t = w.get("parent").clone()).unset("start"), w.getLastChild().set("tail", w.get("tail")), v(w);
var n = w.get("after");
v(n),
function(t) {
if (t) {
var e = g(t),
n = e[0].get("userIndent");
n && !/^\s*1\./.exec(n) && e.forEach(function(t) {
t.unset("userIndent")
})
}
}(n), t.appendTillEnd(n), w.append(t)
}
e = (t = w.get("parent")).get("parent"), t.get("after") && (v(t), w.set("tail", e.get("tail") || w.get("tail")), t.getLastChild().appendTillEnd(t.get("after"))), e.insert(w), 0 == t.get("children").length && t.remove(), e.set("tail", e.getLastChild().get("tail")), v(e.getLastChild()), F.oldCid = e.cid, F.html = s.toHTML(g(e, w)), l.push(F)
}(), e = m, i.redo.push(r.buildReplaceUndo(x))
} else i.undo.push(r.buildReplaceUndo(k)), m = w.getLastChild(),
function() {
var t, e;
e = (t = w.get("parent")).get("parent"), w.detach(), 0 == t.get("children").length && t.remove();
for (var n, i = w.getLastChild(); i;) n = i.get("before"), e.append(i, !0), i = n;
F.oldCid = e.cid, F.html = e.toHTML(), l.push(F)
}(), e = m, i.redo.push(r.buildReplaceUndo(k))
}
return m = d(e, f), l && m && u.containsNode(document.querySelector("[cid='" + m.cid + "']"), !0) && b(t, m, n, i, u, l), l
};
e.moreIndent = function(t) {
var e = t.selection.getRangy();
if (!e || File.isLocked) return !0;
if (o.isType(isInputComponent(document.activeElement))) {
var n = $(document.activeElement).closest(".CodeMirror")[0];
return n && n.CodeMirror.execCommand("indentMore"), !0
}
var i = t.getMarkElem(e.startContainer),
s = l(t.findNodeByElem(i)),
u = t.getMarkElem(e.endContainer),
c = l(t.findNodeByElem(u), s);
t.brush.pause(), s && !c && (c = s.closest(a.list).getLastChild().getFirstChild());
var f = !1;
if (s && c) {
var h = t.selection.buildUndo(),
d = r.makeEmptyCommand(h);
return (f = m(t, s, c, d, e)) && (d.redo.push(h), f.remove.forEach(function(e) {
t.findElemById(e).remove()
}), f.replace.forEach(function(e) {
e.isDeleted() || t.findElemById(e.cid).replaceWith(e.toHTML())
}), t.undo.exeCommand(h), t.undo.register(d)), t.refresh(), t.selection.scrollAdjust(), t.brush.resume(), f || s !== c
}
return t.brush.resume(), !1
}, e.lessIndent = function(t) {
var e = t.selection.getRangy();
if (!e || File.isLocked) return !0;
if (isInputComponent(document.activeElement)) {
var n = $(e.startContainer).closest(".CodeMirror")[0];
return n && n.CodeMirror.execCommand("indentLess"), !0
}
e = t.selection.deRange(e);
var i, s, u = t.getMarkElem(e.startContainer),
c = f(t.findNodeByElem(u)),
l = t.getMarkElem(e.endContainer),
d = f(t.findNodeByElem(l));
c && !d && (d = c.closest(a.list).getLastChild().getFirstChild());
function m() {
t.brush.pause(), i = t.selection.buildUndo(), s = r.makeEmptyCommand(i)
}
var v = !1;
if (c && d && (m(), v = b(t, c, d, s, e)), v || (c = h(t.findNodeByElem(u)), d = h(t.findNodeByElem(l)), o.isType(c, a.paragraph, a.def_footnote, a.def_link, a.heading) && d && (m(), v = p(t, c, d, s, e))), v) {
for (var g = 0; g < v.length; g++) {
t.findElemById(v[g].oldCid).replaceWith(v[g].html);
var y = t.findElemById(v[g].oldCid)[0];
y && (y.parentElement ? t.fences.refreshEditor(!1, !1, y.parentElement) : (t.fences.refreshEditor(!1, !1, y), y.nextElementSibling && t.fences.refreshEditor(!1, !1, y.nextElementSibling)))
}
t.undo.exeCommand(i), s.redo.push(i), t.mathBlock.renderAll(), t.undo.register(s)
}
return t.brush.resume(), v && c != d
}
}), $__System.registerDynamic("42", ["e", "12", "13", "1b", "35", "36", "26"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("e"),
r = t("12"),
o = t("13"),
a = o.TYPE,
s = o.Node,
u = t("1b"),
c = (t("35"), t("36")),
l = t("26").map,
f = 99,
h = 20,
d = r.Model.extend({
initialize: function(t) {
var e = this;
this.editor = t, this.TableEdit = d;
i(t.sessionStr).on("click", ".md-align-gp button", function(e) {
var n, r = /md-align-\S+/g.exec(this.className)[0].substring(9),
o = i(this).closest(".md-align-gp").attr("data-col"),
a = i(this).closest('[mdtype="table"]'),
s = t.findNodeByElem(a);
void 0 != o && (o -= 0, n = s.get("align")[o] == r ? null : r, s.attr("align_idx", [o, n], t), e.stopPropagation(), t.lastCursor && t.undo.exeCommand(t.lastCursor))
}).on("click", ".md-delete-table", function() {
t.tableEdit.deleteTable(i(this).closest("[mdtype='table']"))
}).on("click", ".md-resize-table", function(n) {
i(this).next(".md-table-resize-popover").length ? (i(".md-table-resize-popover").remove(), t.lastCursor && t.undo.exeCommand(t.lastCursor)) : function(n) {
var r, o = '<div class="popover bottom md-table-resize-popover" style="display:block; bottom:auto; top:20px; margin-left:-10px;" contenteditable="false">\t\t\t\t<div class="arrow" style="left:20px;"></div>\t\t\t\t<div class="md-grid-board-wrap md-reset code-tooltip-content">\t\t\t\t\t<table role="grid" class="md-grid-board md-reset">\t\t\t\t\t\t<tbody>\t\t\t\t\t\t\t<tr class="md-reset" row="1">\t\t\t\t\t\t\t\t<td class="md-reset" col="1"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="2"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="3"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="4"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="5"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="6"><a href="#"></a></td>\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t<tr class="md-reset" row="2">\t\t\t\t\t\t\t\t<td class="md-reset" col="1"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="2"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="3"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="4"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="5"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="6"><a href="#"></a></td>\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t<tr class="md-reset" row="3">\t\t\t\t\t\t\t\t<td class="md-reset" col="1"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="2"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="3"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="4"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="5"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="6"><a href="#"></a></td>\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t<tr class="md-reset" row="4">\t\t\t\t\t\t\t\t<td class="md-reset" col="1"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="2"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="3"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="4"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="5"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="6"><a href="#"></a></td>\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t<tr class="md-reset" row="5">\t\t\t\t\t\t\t\t<td class="md-reset" col="1"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="2"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="3"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="4"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="5"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="6"><a href="#"></a></td>\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t<tr class="md-reset" row="6">\t\t\t\t\t\t\t\t<td class="md-reset" col="1"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="2"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="3"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="4"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="5"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="6"><a href="#"></a></td>\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t<tr class="md-reset" row="7">\t\t\t\t\t\t\t\t<td class="md-reset" col="1"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="2"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="3"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="4"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="5"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="6"><a href="#"></a></td>\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t<tr class="md-reset" row="8">\t\t\t\t\t\t\t\t<td class="md-reset" col="1"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="2"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="3"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="4"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="5"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="6"><a href="#"></a></td>\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t<tr class="md-reset" row="9">\t\t\t\t\t\t\t\t<td class="md-reset" col="1"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="2"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="3"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="4"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="5"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="6"><a href="#"></a></td>\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t<tr class="md-reset" row="10">\t\t\t\t\t\t\t\t<td class="md-reset" col="1"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="2"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="3"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="4"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="5"><a href="#"></a></td>\t\t\t\t\t\t\t\t<td class="md-reset" col="6"><a href="#"></a></td>\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t</tbody>\t\t\t\t\t</table>\t\t\t\t\t<div class="popover-title">\t\t\t\t\t\t<input id="md-grid-width" type="text" max="20" size="2" min="1" value="0" /> x <input id="md-grid-height" maxlength="2" size="2" min="1" value="0"/><button id="md-resize-grid" class="btn btn-primary btn-xs">' + i.localize.getString("OK") + "</button>\t\t\t\t\t</div>\t\t\t\t</div>\t\t\t</div>",
a = n.closest('[mdtype="table"]'),
s = t.findNodeByElem(a),
u = s.get("align").length,
c = a.children("table").children("tbody").children("tr").length + 1;
function m() {
i(this).val().trim().length || i(this).val(2);
var t = r.find("#md-grid-width").val(),
e = r.find("#md-grid-height").val();
r.find("a.md-active").removeClass("md-active"), r.find("tr:nth-child(-n+" + e + ")>td:nth-child(-n+" + t + ")>a").addClass("md-active")
}
i(".md-table-resize-popover").remove(), n.append(o), (r = n.find(".md-table-resize-popover")).find("tr:nth-child(-n+" + c + ")>td:nth-child(-n+" + u + ")").addClass("md-grid-ext"), r.find("#md-grid-width, #md-grid-height").off("keydown keypress").on("keypress", function(t) {
if (!/\d/.exec(String.fromCharCode(t.which))) return !1
}).on("keydown", function(t) {
var e = t.keyCode || t.which;
return "Up" === l[e] ? (this.value = this.value - 0 + 1, this.value = Math.min("md-grid-height" == this.getAttribute("id") ? f : h, this.value), !1) : "Down" === l[e] ? (this.value = this.value - 1, this.value = Math.max(2, this.value), !1) : void 0
}), r.find("#md-grid-width").val(u).off("blur focus").blur(m).focus(function() {
r.find("#md-resize-grid").show()
}).blur(function() {
this.value > h ? this.value = h : this.value < 2 && (this.value = 2)
}).on("keydown", function(t) {
var e = t.keyCode || t.which;
if ("Tab" === l[e] && !t.ctrlKey) return r.find("#md-grid-height").focus(), !1;
"Enter" === l[e] && r.find("#md-grid-height").focus()
}), r.find("#md-grid-height").val(c).off("blur focus").blur(m).focus(function() {
r.find("#md-resize-grid").show()
}).blur(function() {
this.value > f ? this.value = f : this.value < 2 && (this.value = 2)
}).on("keydown", function(t) {
var e = t.keyCode || t.which;
if ("Tab" === l[e] && !t.ctrlKey) return r.find("#md-grid-width").focus(), !1;
"Enter" === l[e] && r.find("#md-resize-grid").click()
}), r.find(".md-grid-board a").off("mouseenter mouseleave click").hover(function() {
var t = i(this).closest("td"),
e = t.prevAll().length + 1,
n = t.closest("tr").prevAll().length + 1;
n = 1 === n ? 2 : n, r.find("a.md-active").removeClass("md-active"), r.find("tr:nth-child(-n+" + n + ")>td:nth-child(-n+" + e + ")>a").addClass("md-active"), r.find("#md-grid-width").val(e), r.find("#md-grid-height").val(n), r.find("#md-resize-grid").hide()
}).click(function(t) {
t.stopPropagation(), t.preventDefault(), r.find("#md-resize-grid").click()
}), r.find(".md-grid-board").off("mouseleave").on("mouseleave", function(t) {
i(this).find("a").removeClass("md-active"), i("#md-grid-width").val(u), i("#md-grid-height").val(c)
}), r.find("#md-resize-grid").off("click").click(function(n) {
var i, o = (r.find("#md-grid-width").val() || 0) - 0,
u = (r.find("#md-grid-height").val() || 0) - 0,
c = s.getFirstChild(),
l = s.get("align").length,
f = 0,
h = t.undo.UndoManager.makeEmptyCommand();
for (h.undo.push(t.undo.buildReplaceUndo(s)); c || f < u;) f < u ? (c ? d.resizeRow(c, o, s) : c = d.newEmptyRowAfter(i, o, s), c = (i = c).get("after")) : c && (i = c, c = c.get("after"), i.delete()), f++;
o < l ? s.set("align", s.get("align").slice(0, o)) : s.set("align", s.get("align").concat([].repeat(null, o - l))), a.replaceWith(s.toHTML()), t.lastCursor ? t.undo.exeCommand(t.lastCursor) : window.getSelection().removeAllRanges(), e.showTableEdit(s), h.redo.push(t.undo.buildReplaceUndo(s)), t.undo.register(h)
})
}(i(this).parent()), n.stopPropagation()
}).on("click", ".ty-table-edit", function(e) {
i(e.target).closest(".md-table-resize-popover").length || (i(".md-table-resize-popover").remove(), t.lastCursor && i(".md-table-resize-popover").length && t.undo.exeCommand(t.lastCursor)), e.stopPropagation()
}).on("mousedown", ".ty-table-edit button", function() {
File.editor.lastCursor = File.editor.selection.buildUndo() || File.editor.lastCursor
}).on("refocus", "[mdtype='table']", function() {
i(document.activeElement).closest("[md-inline='image']").length || e.showTableEdit(i(this))
}).on("mouseup", ".ty-table-edit", function(t) {
t.stopPropagation()
}).on("click", ".md-table-more", function() {
i(File.editor.sessionStr).trigger("cursorChange"), File.editor.lastCursor = File.editor.selection.buildUndo(), File.editor.contextMenu.updateTableVisiblity(), File.editor.contextMenu.showExtMenu("#table-menu", i(this)), this.focus()
}),
function() {
var e = i("#table-insert-dialog");
e.find("#table-insert-col, #table-insert-row").off("keydown keypress keyup change").on("keypress", function(t) {
if (!/\d/.exec(String.fromCharCode(t.which))) return !1
}).on("keydown", function(t) {
var n = t.keyCode || t.which;
return "Up" === l[n] ? (this.value = this.value - 0 + 1, this.value = Math.min("table-insert-row" == this.getAttribute("id") ? f : h, this.value), !1) : "Down" === l[n] ? (this.value = this.value - 1, this.value = Math.max(2, this.value), !1) : void("ESC" === l[n] && e.modal("hide"))
}).on("keyup", function() {
i(this).trigger("change")
}).on("change", function() {
File.isMac && bridge.callHandler("touchBar.updateInsertTableTouchBar")
}), e.find("#table-insert-col").blur(function() {
0 === i(this).val().trim().length && i(this).val(2), this.value > h ? this.value = h : this.value < 1 && (this.value = 1)
}).on("keydown", function(t) {
var n = t.keyCode || t.which;
if ("Tab" === l[n] && !event.ctrlKey || "Enter" === l[n]) return e.find("#table-insert-row").focus(), !1
}), e.find("#table-insert-row").blur(function() {
0 === i(this).val().trim().length && i(this).val(2), this.value > f ? this.value = f : this.value < 2 && (this.value = 2)
}).on("keydown", function(t) {
var n = t.keyCode || t.which;
if ("Tab" === l[n] && !event.ctrlKey) return e.find("#table-insert-col").focus(), !1;
"Enter" === l[n] && e.find(".btn-primary").trigger("click")
}), e.find(".btn-primary").click(function() {
e.modal("hide"), t.restoreLastCursor(), i(File.editor.sessionStr).trigger("cursorChange");
var n = new s({
type: s.TYPE.table,
in: t.nodeMap
});
d.valify(n, e.find("#table-insert-col").val(), e.find("#table-insert-row").val()), t.stylize.insertBlock(s.TYPE.table, n)
}), e.on("hidden.bs.modal", function() {
File.isMac && setTimeout(function() {
c.refreshBlockMenu(null, !0)
}, 100)
})
}();
var n, r, o, a, u, v, p, g, b, y, w, F, k = 0;
setTimeout(function() {
a = i("content").offset().top
}, 200),
function() {
var e = i("#typora-table-row-tracker"),
a = i("#typora-table-col-tracker");
i(t.sessionStr).on("mouseenter click", "th, td", function(t) {
if (0 != (o = i(this)).children("[mdtype]").length) {
r = o.closest("tr"), n = r.closest("[mdtype='table']"), b = o.prevAll().length;
var s = r.offset(),
u = o.offset(),
c = n.offset();
e.show().offset(s).find(".typora-table-drag-area").height(r[0].offsetHeight + 1), u.top = c.top;
var l = n.width();
a.show().offset(u).find(".typora-table-drag-area").width(Math.min(o[0].offsetWidth + 1, l - (c.left - u.left) - 1))
}
}), i(document).on("mousedown", "#typora-table-row-tracker", x).on("mousedown", "#typora-table-col-tracker", _).on("mousemove", $).on("mouseup", T)
}();
function x(t) {
if (!File.isLocked) {
e.editor.focusCid = null, u = !0, window.getSelection().removeAllRanges(), C();
var o = r.children();
i("#typora-table-row-tracker .typora-table-data-area").html(function() {
var t = r.height();
return r.closest("thead").length ? "<table class='md-table' style='margin:0 ; padding:0; margin-left:0; height:" + t + "px;'><thead>" + r[0].outerHTML + "</thead></table>" : "<table class='md-table' style='margin:0 ; padding:0; margin-left:0; height:" + t + "px;'><tbody>" + r[0].outerHTML + "</tbody></table>"
}()).find("td, th").each(function(t) {
this.style.width = o[t].offsetWidth + "px"
}), w = t.offsetX, F = t.offsetY, g = p = r.closest("thead").length ? 0 : r.prevAll().length + 1, y = [];
var a = n.offset().top;
return r.closest("table").find("[mdtype='table_row']").each(function() {
y.push(this.offsetTop + a)
}), y.push(y.last() + n.find("tbody tr:last-child")[0].offsetHeight), !1
}
}
function _(t) {
if (!File.isLocked) {
e.editor.focusCid = null, v = !0, window.getSelection().removeAllRanges();
var r = A(g = p = b),
a = i(r[0]).offset();
i("#typora-table-col-tracker .typora-table-data-area").offset(a).html(function(t) {
var e = o[0].offsetWidth;
return "<table class='md-table' style='margin:0 ; padding:0; height:" + n.height() + "px; width:" + e + "px;'><thead><tr>" + t[0].outerHTML + "</tr></thead><tbody>" + t.toArray().map(function(t, e) {
return e ? "<tr style='width:" + t.offsetWidth + "px; height:" + t.offsetHeight + "px;'>" + t.outerHTML + "</tr>" : ""
}).join("") + "</tbody></table>"
}(r)), C(!0), w = t.offsetX, F = t.offsetY, k = i("content").offset().left, y = [];
var s = n.offset().left;
n.find("thead:last-of-type th").each(function() {
y.push(this.offsetLeft + s)
}), y.push(y.last() + n.find("thead [mdtype='table_row'] th:last-child")[0].offsetWidth)
}
}
function $(t) {
u ? function(t) {
if (!u) return;
i("#typora-table-row-tracker").css("top", t.clientY - F - a + document.querySelector("content").scrollTop);
var e;
(e = y.findIndex(function(e, n) {
return y[n] > t.clientY
})) > 0 && (e -= 1); - 1 == e && (e = y.length - 1);
p != e && function(t) {
var e;
if (t >= y.length - 1)(e = n.find("tbody tr:last-child").offset()).top += n.find("tbody tr:last-child")[0].offsetHeight;
else {
var o = i(n.find("tr[mdtype]")[t]);
if (o[0] == r[0] || !o.length) return void E();
e = o.offset()
}
i("#typora-table-row-insert-marker").width(n[0].offsetWidth).show().offset(e)
}(p = e)
}(t) : v && function(t) {
if (!v) return;
i("#typora-table-col-tracker").css("left", t.clientX - w - k);
var e, r = n.scrollLeft();
(e = y.findIndex(function(e, n) {
return y[n] > t.clientX + r
})) > 0 && (e -= 1); - 1 == e && (e = y.length - 1);
p != e && function(t) {
var e;
if (t >= y.length - 1)(e = n.offset()).left += n[0].offsetWidth;
else {
if (g == t || g + 1 == t) return void E();
e = A(t).offset()
}
n.find(".ty-table-edit").remove(), i("#typora-table-col-insert-marker").height(n[0].offsetHeight).show().offset(e)
}(p = e)
}(t)
}
function E() {
i(".typora-table-insert-marker").hide()
}
function C(t) {
i("#write").addClass("no-selection"), File.preventScroll = !0, t ? (A(b).addClass("typora-on-moving"), i("#typora-table-row-tracker").hide()) : (r.addClass("typora-on-moving"), i("#typora-table-col-tracker").hide())
}
function A(t) {
return n.find("[mdtype='table_row']>*:nth-child(" + (t + 1) + ")")
}
function S(t) {
File.preventScroll = !1, i("#write").removeClass("no-selection"), i("content").removeClass("prevent-scroll"), i(".typora-on-moving").removeClass("typora-on-moving"), E()
}
function T(t) {
u ? function(t) {
if (!u) return;
u = !1, S(), m(), e.moveTableRow(g, p, n), M()
}() : v && function(t) {
if (!v) return;
v = !1, S(), m(), e.moveTableCol(g, p, n), e.showAlignCol(n), M()
}()
}
function M() {
u = !1, v = !1, n = null, r = null, o = null, g = null, p = null
}
},
moveTableRow: function(t, e, n) {
if (t != e && t + 1 != e) {
n = n || this.editor.getMarkElem().closest("[mdtype='table']");
var i = this.editor,
r = i.selection.buildUndo(),
o = u.makeEmptyCommand(r),
a = i.findNodeByElem(n),
c = a.getNthChild(t);
o.undo.push(u.buildReplaceUndo(a)), s.tryResetTable(a), t < --e && e--, c.detach(), e >= 0 ? a.getNthChild(e).insert(c) : a.getFirstChild().insert(c, !0), o.redo.push(u.buildReplaceUndo(a)), n.replaceWith(a.toHTML()), r && (i.undo.exeCommand(r), o.redo.push(i.selection.buildUndo())), i.undo.register(o), this.showTableEdit(a)
}
},
moveTableCol: function(t, e, n) {
n = n || this.editor.getMarkElem().closest(".md-table");
var i = this.editor,
r = i.selection.buildUndo(),
o = u.makeEmptyCommand(r),
a = i.findNodeByElem(n),
c = a.getFirstChild();
if (t != e && t + 1 != e) {
for (o.undo.push(u.buildReplaceUndo(a)), s.tryResetTable(a), t < --e && e--; c;) {
var l = c.getNthChild(t);
l.detach(), e >= 0 ? c.getNthChild(e).insert(l) : c.getFirstChild().insert(l, !0), c = c.get("after")
}
var f = a.get("align").splice(t, 1)[0];
a.get("align").splice(e + 1, 0, f), a.get("alignText") && (f = a.get("alignText").splice(t, 1)[0], a.get("alignText").splice(e + 1, 0, f)), o.redo.push(u.buildReplaceUndo(a)), n.replaceWith(a.toHTML()), r && (i.undo.exeCommand(r), o.redo.push(i.selection.buildUndo())), i.undo.register(o), this.showTableEdit(a)
} else this.showTableEdit(a)
},
moveRowUpOrDown: function(t) {
var e = this.editor.selection.getRangy();
if (e && !File.isLocked) {
var n = i(e.commonAncestorContainer).closest("[mdtype='table_row']").closest("tr");
if (0 != n.length) {
var r = n.closest("thead").length ? 0 : n.prevAll().length + 1;
t && 0 == r || !t && r && 0 == n.nextAll().length || this.moveTableRow(r, t ? r - 1 : r + 2, n.closest("[mdtype='table']"))
}
}
},
moveColLeftOrRight: function(t) {
var e = this.editor.selection.getRangy();
if (e && !File.isLocked) {
var n = i(e.commonAncestorContainer).closest("[mdtype='table_cell']").closest("td, th");
if (0 != n.length) {
var r = n.prevAll().length;
t && 0 == r || !t && 0 == n.nextAll().length || this.moveTableCol(r, t ? r - 1 : r + 2, n.closest("[mdtype='table']"))
}
}
},
insertTable: function() {
File.isLocked || document.body.classList.contains("modal-open") || (this.editor.lastCursor = this.editor.selection.buildUndo(), i("#table-insert-dialog").modal({
keyboard: !0
}), File.isMac && bridge.callHandler("touchBar.showInsertTableTouchBar"), setTimeout(function() {
i("#table-insert-col").focus()
}, 500))
},
resizeTableEdit: function(t) {
var e = t.parent().children(".ty-table-edit"),
n = t.parent()[0].getBoundingClientRect(),
i = e.length && e[0].getBoundingClientRect();
e.length && (e[0].style.marginTop = "-" + i.height + "px", e[0].style.width = n.width + 10 + "px")
},
showTableEdit: function(t) {
var e = t,
n = t;
t.jquery ? e = editor.findNodeByElem(t) : n = editor.findElemById(e.id), n.children(".md-table").length && (n = n.children(".md-table"));
function r(t) {
var e = [],
n = i.localize.getString("Align Left"),
r = i.localize.getString("Align Center"),
o = i.localize.getString("Align Right"),
a = i.localize.getString("Resize Table"),
s = i.localize.getString("Delete Table"),
u = i.localize.getString("More Actions"),
c = '<span class="btn-group btn-group-xs md-align-gp"><button type="button" class="btn btn-default md-align-left" ty-hint="' + n + '" aria-label="' + n + '"><span class="ty-icon ty-left-alignment"></span></button><button type="button" class="btn btn-default md-align-center" ty-hint="' + r + '" aria-label="' + r + '"><span class="ty-icon ty-justify-align"></span></button><button type="button" class="btn btn-default md-align-right" ty-hint="' + o + '" aria-label="' + o + '"><span class="ty-icon ty-right-alignment"></span></button></span>';
return e.push("<div class='ty-table-edit md-table-edit md-tooltip-remove' contenteditable='false'>"), e.push('<span class="md-th-button btn-group-xs md-resize-table-th"><button type="button" class="btn btn-default md-resize-table" ty-hint="' + a + '" aria-label="' + a + '"><span class="ty-icon ty-menu"></span></button></span>'), e.push(c), e.push('<span class="md-th-button right-th-button btn-group-xs"><button type="button" class="btn btn-default md-delete-table" ty-hint="' + s + '" aria-label="' + s + '"><span class="ty-icon ty-delete"></span></button></span>'), e.push('<span class="md-th-button right-th-button"><button type="button" class="btn btn-default md-table-more" aria-label="' + u + '"><span class="md-table-more-label">More Actions</span><span class="ty-icon ty-dots-v" style="margin-left:8px;"></span></button></span>'), e.push("</div>"), e.join("")
}
n.prev(".ty-table-edit").length || (i(".ty-table-edit").remove(), r(), n.before(r())), this.resizeTableEdit(n), this.showAlignCol(n)
},
showAlignCol: function(t) {
var e = this.editor.selection.getRangy(),
n = e && i(e.commonAncestorContainer).closest("td, th");
if (n && n.length) {
File.isMac || i(".md-table-more").show();
var r = this.editor.findNodeByElem(t.closest("[cid]")).get("align"),
o = n.prevAll().length;
! function(e, n) {
var i = t.closest("figure").find(".md-align-gp").show();
i.find("button").removeClass("active"), i.attr("data-col", e), "left" !== n && "right" !== n && "center" !== n || i.find(".md-align-" + n).addClass("active")
}(o, r[o])
} else i(".md-align-gp, .md-table-more").hide()
},
keydownHandler: function(t) {
var e = t.keyCode || t.which;
if ("Tab" === l[e] && !t.ctrlKey) return this.moveToNextCell(!0, t.shiftKey), !1;
if ("Enter" === l[e]) {
var n = this.editor.UserOp.backspaceHandler(this.editor, null, "delSelection");
if (t.shiftKey) this.editor.UserOp.pasteHandler(this.editor, "<br />", !0);
else if (File.isMacOrMacNode ? t.metaKey : t.ctrlKey) {
var i = this.addRow(!1, this.editor.undo.commandStack.indexOf(n) > -1);
u.append(n, i)
} else this.moveToBelowCell(u.isEmptyCommand(n));
return !1
}
return File.isMac && s.isType(l[e], "Left", "Right", "Up", "Down") && t.metaKey && t.ctrlKey ? ("Up" == l[e] ? this.moveRowUpOrDown(!0) : "Down" == l[e] ? this.moveRowUpOrDown(!1) : "Left" == l[e] ? this.moveColLeftOrRight(!0) : "Right" == l[e] && this.moveColLeftOrRight(!1), !1) : File.isNode && s.isType(l[e], "Left", "Right", "Up", "Down") && t.shiftKey && t.ctrlKey ? ("Up" == l[e] ? this.moveRowUpOrDown(!0) : "Down" == l[e] ? this.moveRowUpOrDown(!1) : "Left" == l[e] ? this.moveColLeftOrRight(!0) : "Right" == l[e] && this.moveColLeftOrRight(!1), !1) : (File.isMacOrMacNode ? t.metaKey : t.ctrlKey) && ("Left" === l[e] || "Right" === l[e]) ? (this.moveToNextCell(t.shiftKey, "Left" === l[e], !0), !1) : void 0
},
moveToNextCell: function(t, e, n) {
try {
var i, r = this.editor.getMarkElem(window.getSelection().anchorNode).closest("[mdtype='table_cell']").parent(),
o = (e ? r.prev() : r.next()).children("[mdtype='table_cell']"),
a = this.editor.selection,
s = this.editor.selection.getRangy();
if (n) {
var u = s.getBookmark(r[0]);
if (e && u.start > 0) return t ? a.extendToLineEdge(!1, r[0]) : a.jumpIntoElemBegin(r), this.editor.refocus(), !0;
if (!e && u.end < r.text().length) return t ? a.extendToLineEdge(!0, r[0]) : a.jumpIntoElemEnd(r), this.editor.refocus(), !0
}
if (!o.length && r.length && (i = r.parent(), (o = (e ? i.prev().children(":last") : i.next().children(":first")).children("[mdtype='table_cell']")).length || (e && "TD" === r[0].tagName ? o = i.closest("table").find("thead>tr>th:last>[mdtype='table_cell']") : e || "TH" !== r[0].tagName || (o = i.closest("table").find("tbody>tr:first>td:first>[mdtype='table_cell']")))), o.focus(), o.length) {
if (t)
if (n) {
var c = this.editor.selection.extendToLineEdge(!e, o[0], !0);
e ? s.setStart(c.startContainer, c.startOffset) : s.setEnd(c.endContainer, c.endOffset), this.editor.selection.setRange(s)
} else this.editor.selection.selectAllElem(o);
else e ? this.editor.selection.jumpIntoElemEnd(o) : this.editor.selection.jumpIntoElemBegin(o);
return this.editor.refocus(), !0
}
} catch (t) {}
},
moveToBelowCell: function(t, e, n) {
try {
var i = this.editor.getMarkElem(window.getSelection().anchorNode).closest("[mdtype='table_cell']"),
r = this.editor.findNodeByElem(i),
o = d.getNextCellInColumn(r, e),
a = o && this.editor.findElemById(o.cid);
o ? a.length && (t ? this.editor.selection.selectAllElem(a) : e ? this.editor.selection.jumpIntoElemEnd(a) : this.editor.selection.jumpIntoElemBegin(a)) : this.editor.selection.moveUpOrDown()
} catch (t) {}
},
getSibling: function(t, e, n) {
return d.getSibling(t, e, n)
},
unfocusAll: function(t) {
t ? i(".ty-table-edit").fadeOut(function() {
i(".ty-table-edit").remove()
}) : i(".ty-table-edit").remove(), i(".typora-table-tracker").hide()
},
deleteRow: function() {
d.deleteRow(this.editor)
},
addRow: function(t, e) {
return d.addRow(this.editor, t, e)
},
deleteCol: function() {
d.deleteCol(this.editor)
},
addCol: function(t) {
d.addCol(this.editor, t)
},
copyTable: function() {
var t = this.editor.getMarkElem(window.getSelection().anchorNode).closest(".md-table-fig");
if (t.length) {
(t = t.clone()).find(".md-tooltip-remove").remove(), t.find("td, th").attr("style", function(t, e) {
return "border: 1px solid rgb(204, 204, 204);min-height:1ch;min-width:4ch;" + (this.style.textAlign ? "text-align:" + this.style.textAlign + ";" : "")
});
var e = t.html(),
n = this.editor.UserOp.prepMarkHtml(t[0].outerHTML, editor),
i = this.editor.UserOp.getMarkdownSourceFrom(n.html());
this.editor.UserOp.setClipboard(e, "", i, !0)
}
},
deleteTable: function(t, e) {
m(), i("#ty-tooltip").hide(), t = t || editor.getMarkElem(window.getSelection().anchorNode).closest("[mdtype='table']");
var n = this.editor.getNode(t.attr("cid")),
r = editor.undo.UndoManager.makeEmptyCommand(this.editor.selection.buildUndo()),
o = n.get("after"),
c = n.get("before");
return o || c ? (u.addUndoForRemove(r, n), n.remove(), t.remove()) : (r.undo.push(u.buildReplaceUndo(n)), n.set("type", a.paragraph), n.set("text", ""), n.clearChildren(), s.normalizeNode(n), t.replaceWith(n.toHTML()), r.redo.push(u.buildReplaceUndo(n))), editor.focusCid = null, o ? this.editor.selection.jumpIntoElemBegin(this.editor.findElemById(o.id)) : this.editor.selection.jumpIntoElemEnd(this.editor.findElemById((c || n).id)), this.editor.lastCursor = null, r.redo.push(this.editor.selection.buildUndo()), !e && this.editor.undo.register(r), r
},
isTableEmpty: function(t) {
function e(t) {
for (var e = 0, n = t.get("children").length; e < n; e++)
if (t.get("children").at(e).get("text")) return !1;
return !0
}
for (var n = 0, i = t.get("children").length; n < i; n++)
if (!e(t.get("children").at(n))) return !1;
return !0
},
reformatTable: function(t) {
if ((t = t || editor.getMarkElem(window.getSelection().anchorNode).closest("[mdtype='table']")).length) {
var e = this.editor.getNode(t.attr("cid")),
n = editor.undo.UndoManager.makeEmptyCommand(this.editor.selection.buildUndo());
n.undo.push(u.buildReplaceUndo(e)), e.set("userText", void 0), e.set("style", void 0), e.set("alignText", void 0);
for (var i = e.getFirstChild(); i;) {
for (var r = i.getFirstChild(); r;) r.set("marginRight", void 0), r.set("marginLeft", void 0), r = r.get("after");
i = i.get("after")
}
n.redo.push(u.buildReplaceUndo(e)), n.redo.push(this.editor.selection.buildUndo()), this.editor.undo.register(n)
}
}
});
d.deleteRow = function(t) {
i(".md-tooltip-hide").hide();
var e, n, r, o, a, u = t.getMarkElem(window.getSelection().anchorNode).closest("td"),
c = t.getMarkElem(window.getSelection().anchorNode).closest("tr[mdtype='table_row']"),
l = c.prevAll().length;
if (c.siblings().length) {
for (n = t.findNodeByElem(c).get("parent"), (e = t.undo.UndoManager.makeEmptyCommand()).undo.push(t.selection.buildUndo()), e.undo.push(t.undo.UndoManager.buildReplaceUndo(n)), s.tryResetTable(n), o = n.getNthChild(1), r = l; r;) o = o.get("after"), r--;
o.remove(), e.redo.push(t.undo.UndoManager.buildReplaceUndo(n)), t.findElemById(n.id).replaceWith(n.toHTML()), l ? l-- : l++, a = document.createRange();
try {
a.setStart(t.findElemById(n.id).find("tbody>tr:nth-child(" + (l + 1) + ")>td:nth-child(" + (u.prevAll().length + 1) + ")>span")[0], 0), window.getSelection().removeAllRanges(), window.getSelection().addRange(a), e.redo.push(t.selection.buildUndo())
} catch (t) {}
t.undo.register(e), t.tableEdit.showTableEdit(n)
}
}, d.addRow = function(t, e, n) {
i(".md-tooltip-hide").hide();
var r, o, a = t.getMarkElem(window.getSelection().anchorNode).closest("tr[mdtype='table_row']"),
u = "TBODY" == (a.parent()[0] || {}).tagName,
c = u ? a.prevAll().length + 1 : 0,
l = t.undo.UndoManager.makeEmptyCommand();
r = t.findNodeByElem(a).get("parent"), l.undo.push(t.selection.buildUndo()), l.undo.push(t.undo.UndoManager.buildReplaceUndo(r)), s.tryResetTable(r), o = r.getNthChild(c), o = d.newEmptyRowAfter(e ? o.get("before") : o, o.get("children").length, r, e ? o : o.get("after")), u ? a[e ? "before" : "after"](o.toHTML()) : t.findElemById(r.id).replaceWith(r.toHTML());
var f = t.findElemById(o.getFirstChild().id);
return t.selection.jumpIntoElemBegin(f), t.selection.scrollAdjust(), l.redo.push(t.undo.UndoManager.buildReplaceUndo(r)), l.redo.push(t.selection.buildUndo()), !n && t.undo.register(l), t.tableEdit.showTableEdit(r), l
}, d.addCol = function(t, e) {
i(".md-tooltip-hide").hide();
var n, r, o = t.getMarkElem(window.getSelection().anchorNode).closest("td, th"),
a = o.find("[cid]").attr("cid"),
u = o.prevAll().length;
if (o.length) {
if (r = t.findNodeByElem(o.children("[cid]")).get("parent").get("parent"), (n = t.undo.UndoManager.makeEmptyCommand()).undo.push(t.selection.buildUndo()), n.undo.push(t.undo.UndoManager.buildReplaceUndo(r)), s.tryResetTable(r), r.get("children").toArray().map(function(t) {
var n = t.getNthChild(u);
n.insert(new s({
type: s.TYPE.table_cell,
text: "",
marginLeft: n.get("marginLeft"),
marginRight: n.get("marginRight")
}), e)
}), r.get("align").splice(e ? u : u + 1, 0, null), r.get("alignText")) {
var c = s.adjustAlignText(r, 0, null);
r.get("align").splice(e ? u : u + 1, 0, c)
}
t.findElemById(r.id).replaceWith(r.toHTML()), o = t.findElemById(a).closest("th, td"), t.selection.jumpIntoElemBegin(e ? o.prev() : o.next()), n.redo.push(t.undo.UndoManager.buildReplaceUndo(r)), t.undo.register(n), t.tableEdit.showTableEdit(r)
}
}, d.deleteCol = function(t) {
i(".md-tooltip-hide").hide();
var e, n, r = t.getMarkElem(window.getSelection().anchorNode).closest("td, th"),
o = r.prevAll().length,
a = r.nextAll().length,
u = r.closest("tr"),
c = "TBODY" == u.parent()[0].tagName ? u.prevAll().length + 1 : 0;
if (o || a) {
n = t.findNodeByElem(r.children("[cid]")).get("parent").get("parent"), (e = t.undo.UndoManager.makeEmptyCommand()).undo.push(t.selection.buildUndo()), e.undo.push(t.undo.UndoManager.buildReplaceUndo(n)), s.tryResetTable(n), n.get("children").toArray().map(function(t) {
t.getNthChild(o).remove()
}), n.get("align").splice(o, 1), n.get("alignText") && n.get("alignText").splice(o, 1), t.findElemById(n.id).replaceWith(n.toHTML());
var l = document.createRange();
try {
c ? l.setStart(t.findElemById(n.id).find("tbody>tr:nth-child(" + c + ")>td:nth-child(" + (o + 1) + ")>span")[0], 0) : l.setStart(t.findElemById(n.id).find("thead>tr[mdtype]>th:nth-child(" + (o + 1) + ")>span")[0], 0), window.getSelection().removeAllRanges(), window.getSelection().addRange(l), e.redo.push(t.selection.buildUndo())
} catch (t) {}
e.redo.push(t.undo.UndoManager.buildReplaceUndo(n)), t.undo.register(e), t.tableEdit.showTableEdit(n)
}
}, d.getSibling = function(t, e, n) {
if (s.isType(t, s.TYPE.table_cell)) {
e = e || "after";
var i = t.get(e),
r = t.get("parent").get(e);
return i || !r || n || (i = "after" == e ? r.getFirstChild() : r.getLastChild()), i
}
}, d.getColumnIndex = function(t) {
return t.get("before") ? 1 + d.getColumnIndex(t.get("before")) : 0
}, d.getCellAt = function(t, e) {
if (s.isType(t, s.TYPE.table_row)) {
for (var n = t.getFirstChild(); e > 0;) e--, n = n.get("after");
return n
}
}, d.getNextCellInColumn = function(t, e, n) {
if (s.isType(t, s.TYPE.table_cell)) {
n = n || d.getColumnIndex(t), e = e || "after";
var i = t.get("parent").get(e);
return i ? d.getCellAt(i, n) : void 0
}
}, d.resizeRow = function(t, e) {
var n, i = t.getFirstChild(),
r = 0,
o = t.get("before"),
a = o ? o.getFirstChild() : null,
u = t.get("parent");
s.tryResetTable(u);
function c(t) {
return t.length > 1 ? t[0] : t
}
for (var l = Math.max(e, t.get("children").length); r < l;) r < e ? (i || (i = new s({
type: s.TYPE.table_cell,
in: t.get("in"),
parent: t,
before: n
}), a && void 0 !== a.get("marginLeft") ? (i.set("marginLeft", c(a.get("marginLeft"))), i.set("marginRight", c(a.get("marginRight")))) : !o && n && void 0 !== n.get("marginLeft") && (i.set("marginLeft", c(n.get("marginLeft"))), i.set("marginRight", c(n.get("marginRight")))), u.get("alignText") && !u.get("alignText")[r] && (u.get("alignText")[r] = s.adjustAlignText(u, 0, null))), i = (n = i).get("after")) : i && (i = (n = i).get("after"), n.delete()), r++, a && (a = a.get("after"))
}, d.newEmptyRowAfter = function(t, e, n, i) {
var r = new s({
type: s.TYPE.table_row,
in: n.get("in"),
parent: n,
before: t,
after: t ? t.get("after") : i || null
});
return d.resizeRow(r, e), r
};
function m() {
i("#typora-table-row-tracker, #typora-table-col-tracker").hide().find(".typora-table-data-area").html("")
}
d.valify = function(t, e, n, i) {
var r;
if (n = n || 2, void 0 === e && (e = (e = t.get("children").at(0)) ? e.get("children").length : 1), i && 1 == t.get("children").length && 1 == e) i(t, t.get("children").at(0).get("children").at(0).get("text"));
else {
t.get("children").map(function(t) {
for (var n = t.get("children").length; n < e; n++) n === t.get("children").length && (r = t.getLastChild()), r = new s({
type: s.TYPE.table_cell,
parent: t,
in: t.get("in"),
before: r,
text: ""
})
});
for (var o = t.get("children").length; o < n; o++) d.newEmptyRowAfter(t.get("children").at(o - 1), e, t);
t.get("align") || t.set("align", new Array(e - 0))
}
}, s.TableEdit = d, n.exports = d
}), $__System.registerDynamic("43", ["12", "14", "13", "42", "19", "18", "e"], !0, function(t, e, n) {
"use strict";
this || self, t("12");
var i = t("14"),
r = t("13"),
o = r.Node,
a = r.TYPE,
s = (r.NodeCollectionUtils, t("42")),
u = t("19"),
c = t("18"),
l = t("e"),
f = ["CONTENT", "HEADER", "FOOTER", "ARTICLE", "SECTION", "DIV", "P", "BLOCKQUOTE", "PRE", "UL", "OL", "TABLE", "HR", "H1", "H2", "H3", "H4", "H5", "H6", "DL", "DT", "DD", "TBODY", "THEAD", "TFOOT", "ASID", "LI", "HTML", "BODY", "IFRAME", "STYLE", "SCRIPT", "FIGURE", "VIDEO", "AUDIO"],
h = ["TITLE", "SELECT", "TEXTAREA", "INPUT", "BUTTON", "SELECT", "SCRIPT", "CANVAS", "META", "PROGRESS", "HEAD", "EMBED", "STYLE", "TEMPLATE", "LINK", "NOSCRIPT", "MENU", "EMBED", "OBJECT"],
d = function(t) {
var e = t.find(".gist-file>.gist-data .blob-wrapper");
if (!e.length) return null;
var n = e.find(".blob-code.blob-code-inner").map(function() {
return this.textContent
}).toArray().join("\n"),
i = /\stype-([^\s]+)/.exec(e.attr("class") || ["", ""])[1];
return "text" == i && (i = ""), {
type: a.fences,
text: n,
lang: i
}
},
m = /^\s*<(iframe|div|p|table|details|figure|img|a|video|audio|script|style|meta|svg|pre|code)(\s|\/?>)/,
v = /(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)/,
p = /\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)/,
g = {
NORMAL: "normal",
HTML: "html"
},
b = function(t, e, n, r) {
n = n || File.editor;
function o(t) {
var e = ["", t, ""],
n = /^(\s*)/.exec(t);
return n && (t = t.substring(n[0].length), e[0] = n[0]), (n = /(\s*)$/.exec(t)) && (t = t.substring(0, t.length - n[0].length), e[2] = n[0]), e[1] = t, e
}
var a, s, u, c;
t.find("img").each(function() {
(a = l(this)).text("![" + (a.attr("alt") || a.attr("title") || "img").replace(/\r?\n/gi, " ") + "](" + (t = a.attr("src") || "", File.isMac && (0 == t.indexOf("file:///") && -1 == t.substring("file:///".length).indexOf("/") ? (t = t.substring("file:///".length), t = i.getAbsoluteURL(r, t)) : 0 == t.indexOf("webkit-fake-url:") && (File.isMacWK || (t = bridge.callSync("images.convertFakeUrl", t)))), -1 == t.indexOf(":/") && n && n.imgEdit && (t = n.imgEdit.resolveImagePath(t)), t) + ")");
var t;
a.replaceWith(a[0].childNodes[0])
}), t.find("strong, b").each(function() {
a = l(this), "normal" !== this.style.fontWeight && ((c = o(a.text()))[1] = c[1] ? "**" + c[1].replace(/([^\\])\*/g, "$1\\*") + "**" : "", a.text(c.join("")))
}), t.find("em, i").each(function() {
a = l(this), (c = o(a.text()))[1] = c[1] ? "*" + c[1].replace(/([^\\*])\*([^*])/g, "$1\\*$2") + "*" : "", a.text(c.join(""))
}), t.find("code, pre, tt").each(function() {
(a = l(this)).text("`" + a.text() + "`")
}), t.find("del, strike").each(function() {
(a = l(this)).text("~~" + a.text() + "~~")
}), t.find("span").each(function() {
a = l(this), 0 != (this.style.fontWeight || "").indexOf("bold") && 700 != this.style.fontWeight && 900 != this.style.fontWeight || ((c = o(a.text()))[1] = c[1] ? "**" + c[1].replace(/([^\\])\*/g, "$1\\*") + "**" : "", a.text(c.join(""))), "italic" == this.style.fontStyle && ((c = o(a.text()))[1] = c[1] ? "*" + c[1].replace(/([^\\*])\*([^*])/g, "$1\\*$2") + "*" : "", a.text(c.join("")))
}), t.find("br").each(function() {
(a = l(this)).replaceWith("")
}), t.find("a[href]:not(:empty)").each(function() {
a = l(this), s = i.getAbsoluteURL(r, a.attr("href")), 0 == (u = a.text()).length ? a.replaceWith("") : s == u ? a.replaceWith("&lt;" + s.replace(/</g, encodeURI("<")).replace(/>/g, encodeURI(">")) + "&gt;") : a.replaceWith("[" + u.replace(/([^\\])]([^(]|$)/, "$1\\]$2").replace(/\r?\n/gi, " ") + "](" + s + ")")
}), File.option.highlight && t.find("mark").each(function() {
(a = l(this)).text("==" + a.text().replace(/([^\\])\=/, "\\=") + "==")
});
var f = (t[0].innerText || t[0].textContent || "").replace(/(\r?\n)|\u00a0/gi, " ");
return e ? f.split(/\uE033/g) : f.replace(/\uE033/g, " ")
};
e.parseInlineHTML = function(t, e, n) {
var i = l(l.parseHTML("<div>" + t + "</div>")[0]);
i.find("head, meta, script, css, .gutter, style, title, template, wbr, menu").remove(), i[0].normalize && i[0].normalize();
for (var r = 0; r < i[0].childNodes.length; r++) {
var o = i[0].childNodes[r];
o.nodeType == o.TEXT_NODE ? /^[\s\r\n]*$/.exec(o.textContent) && (o.remove(), r--) : o.nodeType !== o.ELEMENT_NODE && (o.remove(), r--)
}
return b(i, void 0, e, n)
}, e.convertToPlain = function(t) {
function e(t, e) {
for (var i = (t instanceof Array ? t[0] : t.first()).getLastBrother(!0), r = [], o = 0; o < t.length; o++) r = r.concat(n(i, e)), i = i.get("after");
return r
}
function n(t, i) {
var r, s = [];
function u(t) {
return i ? [t] : [t, ""]
}
switch (t.get("type")) {
case a.fences:
s = t.get("text").replace(/\u200B/g, "").split("\n");
for (var c = 0; c < s.length; c++) s[c] = " " + s[c];
return i || s.push(""), s;
case a.list:
var l = t.get("style"),
f = Number.isNaN(Number.parseInt(t.get("start"))) ? 0 : Number.parseInt(t.get("start")) - 1,
h = t.get("children").length;
if (h) {
var d = t.getFirstChild();
for (c = 0; d;) {
var m = n(d, !0),
v = o.getIndentPrefix(l, c + f, d, void 0, (h + "").length);
m.map(function(t, e) {
m[e] = (e ? " ".repeat(v.length) : v) + m[e], s.push(m[e])
}), c++, d = d.get("after")
}
}
return i || s.push(""), s;
case a.table:
for (var p, g, b, y, w, F, k = [], x = [], _ = 0, $ = t.getFirstChild(); $;) {
for (p = $.getFirstChild(), x[_] = [], g = 0; p;) x[_][g] = p.toMark().trim(), p = p.get("after"), 0 === _ && (k[g] = 4), k[g] = Math.max(x[_][g].length, k[g]), k[g] = Math.min(k[g], 40), g++;
$ = $.get("after"), _++
}
for (_ = 0; _ < x.length; _++) {
for (b = " ", g = 0; g < k.length; g++) y = Math.max(k[g] - x[_][g].length, 0), b += "right" == (w = t.get("align")[g]) ? " ".repeat(y) + x[_][g] : "center" == w ? " ".repeat(F = ~~(y / 2)) + x[_][g] + " ".repeat(y - F) : x[_][g] + " ".repeat(y), b += "\t";
s.push(b.replace(/\s$/, ""))
}
return i || s.push(""), s;
case a.hr:
return u("---");
case a.def_link:
return r = "[" + t.get("ref") + "]: " + t.safeGetStrAttr("href") + (t.safeGetStrAttr("title").length ? '\t"' + t.get("title") + '"' : ""), o.isType(t.get("after"), a.def_link) ? [r] : u(r);
case a.def_footnote:
return r = "[" + t.get("ref") + "]: " + t.get("text"), o.isType(t.get("after"), a.def_footnote) ? [r] : u(r);
default:
return t.get("children") && t.get("children").length > 0 ? e(t.get("children"), i) : u(t.get("text"))
}
}
return e(t).join("\n")
}, e.parseHTML = function(t, e, n, r) {
var y = l(l.parseHTML("<div>" + t + "</div>")[0]),
w = [];
function F(t, n, i) {
t.in = e, t.parent = n, t.before = i.last(), t && t.text && (t.text = t.text.replace(/\u200b/g, "").replace(/\u00a0/g, " "));
var r = new o(t);
return i.push(r), r
}
function k(t, e, i) {
var s = [];
if (e)
for (var u = 0; u < t[0].childNodes.length; u++) E(l(t[0].childNodes[u]), i, s);
else o.isType(i, a.blockquote, a.list_item) ? _(t, i, s) : i.set("text", b(t, void 0, n, r))
}
function x(t, e, n) {
for (var r, o = [], s = null, c = 0; c < t.length; c++) r = t[c], (o = u.reDefLink.exec(r)) ? (s = null, F({
type: a.def_link,
ref: o[1],
href: o[3],
title: o[7]
}, e, n)) : (o = u.reDefFootnote.exec(r)) ? (s = null, F({
type: a.def_footnote,
ref: o[1],
text: (o[3] || "").trim()
}, e, n)) : null == s ? s = F({
type: a.paragraph,
text: i.escapeHead(r)
}, e, n) : r ? s.set("text", s.get("text") + "\n" + i.escapeHead(r)) : s = null
}
function _(t, e, i) {
if (t.find("br").length) x(b(t, !0, n.baseURL), e, i);
else {
if (3 == t[0].nodeType && !t.text().trim().length) return;
if (1 == t[0].nodeType && "BR" == t[0].tagName) return;
x([b(t, void 0, n, r)], e, i)
}
}
var $ = {
center: "center",
left: "left",
right: "right"
};
function E(t, i, u, y) {
var w, x, C = function(t) {
if (!t[0] || !t[0].tagName) return !1;
if (-1 == f.indexOf(t[0].tagName.toUpperCase())) return t[0].querySelector("video, div, p");
var e = !1;
return t.children().each(function() {
e = e || this.tagName && (f.indexOf(this.tagName.toUpperCase()) > -1 || "BLOCK" == this.style.display)
}), e || t[0].querySelector("video, div, p")
}(t),
A = t[0].tagName;
if (!(t.data("skip") || h.indexOf(A) > -1 || t[0].nodeType === document.CITATION_NODE)) {
if (y && y.length) y.push(("P" == A ? "\n" : "") + t.text());
else if ("BLOCKQUOTE" === A) k(t, C, w = F({
type: a.blockquote
}, i, u));
else if ("LI" === A && o.isType(i, a.list)) k(t, C, w = F({
type: a.list_item
}, i, u));
else if ("UL" === A || "OL" === A) k(t, C, w = F({
type: a.list,
style: A.toLowerCase()
}, i, u));
else if ("DL" === A) w = F({
type: a.list,
style: "ul"
}, i, u),
function(t, e) {
for (var i, o = [], s = 0; s < t.length; s++) "DT" == t[s].tagName && ((i = F({
type: a.list_item
}, e, o)).itemList = [], F({
type: a.paragraph,
text: b(l(t[s]), void 0, n, r)
}, i, i.itemList)), "DD" == t[s].tagName && i && F({
type: a.paragraph,
text: b(l(t[s]), void 0, n, r)
}, i, i.itemList)
}(t.children(), w);
else if ("TABLE" === A)(x = t.children().children("tr").add(t.children("tr"))).length && (w = F({
type: a.table
}, i, u), u = [], w.cols = 1, w.set("align", new Array(w.cols - 0)), x.toArray().map(function(t) {
E(l(t), w, u)
}), s.valify(w, w.cols, 2, function(t, e) {
var n = e.split(/(\r|\n)+/);
t.set("type", a.paragraph), t.set("text", n[0]);
for (var r = 1; r < n.length; r++) n[r].trim().length && F({
type: a.paragraph,
text: n[r]
}, i, u)
}));
else if ("THEAD" === A || "TBODY" === A || "TFOOTER" === A) {
for (var T = [t], M = $elem.next(); M.length && o.isType(M[0].tagName, "THEAD", "TBODY", "TFOOTER");) T.push(M), M.data("skip", !0);
t.wrap("<table></table>"), E(t.parent(), i, u)
} else if ("TR" === A && o.isType(i, a.table)) {
var D;
D = (x = t.children("th")).length, x = x.add(t.children("td")), i.cols = x.length > i.cols ? x.length : i.cols, w = F({
type: a.table_row,
isHeader: D
}, i, u), u = [], x.toArray().map(function(t) {
E(l(t), w, u)
})
} else if ("TD" !== A && "TH" !== A || !o.isType(i, a.table_row))
if ("HR" === A) F({
type: a.hr
}, i, u);
else if (/H[1-6]/g.exec(A)) F({
type: a.heading,
text: b(t, void 0, n, r),
depth: t[0].tagName[1]
}, i, u);
else if ("CODE" === A || "PRE" === A && 0 == t.find("pre").length || "FIGURE" == A && t.hasClass("highlight")) {
S = "";
var L = t.attr("class") + " " + t.children("code").attr("class"),
R = (/lang(?:uage)?\-([^\s]+)/.exec(L) || [])[1],
B = t.find("tr");
B.length > 1 ? S = B.map(function() {
return this.innerText
}).toArray().join("\n") : (t.find("div").each(function() {
l(this).before("<br/>")
}), S = t[0].innerText.replace(/(^\s*\n+)|([\r\n]+$)/g, "")), F({
type: a.fences,
text: S,
lang: R
}, i, u)
} else {
if (o.isType((A || "").toUpperCase(), "VIDEO", "AUDIO", "IFRAME", "DETAILS", "SVG")) return S = t[0].outerHTML, F({
type: a.html_block,
text: S
}, i, u), S;
if ("P" != A && C) {
if (C) {
var I, N;
if (t.is("div.gist") && (N = d(t))) return void F(N, i, u);
var O = [];
if (t[0].childNodes.forEach(function(t, e) {
(t.nodeType != t.TEXT_NODE || t.nodeValue.trim().length) && (t.nodeType == t.TEXT_NODE || c.ALL_INLINE_TYPE.indexOf((t.tagName || "").toUpperCase()) > -1 ? I ? I.append(l(t)) : I = l(t).wrap("<p></p>").parent() : t.nodeType == t.ELEMENT_NODE && (I && (E(I, i, u, O), I = null), E(l(t), i, u, O)))
}), O.length) {
var j = O.join("\n"),
P = o.parseFrom(j, e, void 0, !0)[1];
return u.splice.apply(u, [u.length, 0].concat(P)), j
}
I && (E(I, i, u), I = null)
}
} else {
var q = function(t) {
t = t || "";
var e = !1;
try {
e = (e = (t.match(/\n\s*(\!?\[|#{1,5}|>|```|([-+*]\s)|(\d+\.\s))/gm) || "").length > 3 || t.match(p) || t.match(v)) ? g.NORMAL : null
} catch (t) {}
return e || (e = (e = m.exec(t)) ? g.HTML : null), e || (e = (e = (t.match(/(\/\w*>)|(\n\s+<)/g) || []).length > 6) ? g.HTML : null), e
}(S = t[0].innerText || t[0].textContent || "");
if (q) {
var U = new o({
type: a.paragraph,
text: S.replace(/^[\r\n]+\s*/, "").replace(/\s*[\r\n]+$/, ""),
in: e
});
if (i) i.append(U);
else {
var z = (U.parseFrom(void 0, void 0, !0) || [])[1];
z && z.length && (y && 1 == z.length && !u.length && z[0].get("type") == a.html_block ? y.push(S) : u.splice.apply(u, [u.length, 0].concat(z)))
}
} else _(t, i, u);
if (q) return S
}
} else w = F({
type: a.table_cell,
text: b(t, void 0, n, r)
}, i, u), "TH" === A && function(t, e) {
if ("TH" === t[0].tagName) {
var n = t.attr("style") || "",
i = /text\-align:([^;]+)($|;)/.exec(n),
r = null;
if (i && (r = $[i[1].replace(/;/g, "").trim()] || null), r) {
var o = t.prevAll("th").length;
(e.get("parent").get("parent").get("align") || [])[o] = r
}
}
}(t, w);
return null
}
}
y.find("head, meta, script, css, .gutter, style, title, template, wbr, menu").remove(), y[0].normalize && y[0].normalize();
var C = E(y, null, w);
if (C) return C;
if (w.length && (function t(e, n, i, r) {
var s, u = n,
c = [];
if (n && n !== i) {
for (; u && u !== i && o.isType(u, a.paragraph) && o.isEmptyBlock(u);) s = u, u = u.get("after"), s.remove(), r && r.splice(r.indexOf(s), 1), u = u.get("after");
for (n = u.get("before") || u, u = i; u && u !== n && o.isType(u, a.paragraph) && o.isEmptyBlock(u);) s = u, u = u.get("before"), s.remove(), r && r.splice(r.indexOf(s), 1), u = u.get("before")
}
for (u = n; u;) {
var l = null;
if (o.isType(u, a.blockquote, a.list_item)) t(u, u.getFirstChild(), u.getLastChild());
else if (o.isType(u, a.fences) && o.isType(u.get("before"), a.fences)) c.push(u), u.head = u.get("before").head || u.get("before"), u.head.set("text", u.head.get("text") + "\n" + u.get("text"));
else if (o.isType(u, a.list) && 0 === u.get("children").length) u.set("type", a.paragraph);
else if (o.isType(u, a.paragraph) && (l = /^(`+)([\s\S]*?[^`])\1(?!`)\s*$/g.exec(u.get("text")))) {
u.set("type", a.fences), u.set("text", l[2]);
continue
}
u = u.get("after")
}
c.map(function(t) {
r && r.splice(r.indexOf(t), 1), t.remove()
})
}(0, w[0], w.last(), w), 1 === w.length && o.isType(w[0], a.paragraph))) {
y.find("br").replaceWith(""), y.html(y.html().replace(/^\s+/gm, ""));
var A = (S = y.text()).indexOf("") > -1,
S = S.replace(/^(\s*\n)+/, "").replace(/(\r?\n)+$/, "").replace(/\u00a0/g, " ").replace(/\u200b/g, "");
return A && (S = S.replace(/\uE033/g, "\n").replace(/(\r?\n){2,}/g, "\n")), w[0].delete(), S.indexOf(/\n/) > -1 ? o.parseFrom(S, e, {
noTop: !0,
skips: {
old_code: !0
}
}, !0)[1] : S
}
return w
}
}), $__System.registerDynamic("2b", ["12", "14", "13", "1b", "1c", "19", "36"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("12"),
r = t("14"),
o = t("13"),
a = t("1b"),
s = a.SnapFlag,
u = o.Node,
c = o.TYPE,
l = (o.NodeCollectionUtils, t("1c")),
f = t("19"),
h = t("36");
function d(t) {
if (t.get("style") == u.ListType.ol) return u.ListType.ol;
var e = !1;
return t.get("children").map(function(t) {
e = e || t.get("style") !== u.ListType.task
}), e ? u.ListType.ul : u.ListType.task
}
var m = function(t, e, n, i, r) {
var o = l.createRange();
function a(t) {
var i;
i = t.attr("md-inline") == e ? t.children(".md-meta:not(.md-content)") : t.find('[md-inline="' + e + '"]').children(".md-meta:not(.md-content)"), n && (n.end -= i.text().length), i.remove(), t.attr("md-inline") == e && n && (n.end = n.start + t.text().length)
}
if (t[0].hasAttribute("mdtype") && (t.wrapInner("<span></span>"), t = $(t[0].firstChild)), n ? (n.containerNode = t[0], o.moveToBookmark(n)) : o.selectNode(t[0]), o.commonAncestorContainer.nodeType == document.ELEMENT_NODE && o.commonAncestorContainer.getAttribute("md-inline") == e) a($(o.commonAncestorContainer));
else {
for (var s = document.createElement("SPAN"), u = o.extractContents(), c = 0; c < u.childNodes.length; c++) s.appendChild(u.childNodes[c].cloneNode(!0));
a($(s)), s.childNodes.length != s.childElementCount || 1 != s.childNodes.length || s.childNodes[0].getAttribute("md-inline") || (s = s.childNodes[0]), o.insertNode(s), o.setStart(s, 0), o.setEnd(s, s.childNodes.length)
}
return r || v.call(this, o, e, t[0], i ? n : null), this.editor.brush.addToQueue(t.attr("cid")), o
},
v = function(t, e, n, i) {
if (u.isType(e, c.link, c.image)) p.call(this, t, e, n, i);
else if (t.commonAncestorContainer == t.startContainer && t.startContainer == t.endContainer) {
var r = function(t) {
var e, n = [],
i = 0,
r = t.commonAncestorContainer;
if (!r.childElementCount) return [t];
function o() {
if (e != i && 0 != e) {
var t = l.createRange();
t.setStart(r.children[i], 0), t.setEndAfter(r.children[e - 1]), n.push(t)
}
}
for (e = 0; e < r.childElementCount; e++) r.children[e].classList.contains("md-softbreak") && (o(), i = e + 1);
return i < e && o(), n
}(t),
o = r.length > 1,
a = this;
r.forEach(function(t, s) {
var u = p.call(a, t, e, n, s == r.length - 1 ? i : void 0, o);
i && u && (i instanceof Object ? i.end += u : i += u)
})
} else p.call(this, t, e, n, i)
},
p = function(t, e, n, i, o) {
var a, s, l, f, h, d, m = y.SyntaxMap[e];
if (i) {
var v, p = this.editor.getJQueryElem(t.startContainer),
g = this.editor.getJQueryElem(t.endContainer);
if (p.closest("md-before").length || p.closest("md-content").length ? (t.setStartBefore(p.closest("[md-inline]")[0]), v = !0) : p.closest("md-meta").length && (t.setStartAfter(p.closest("[md-inline]")[0]), v = !0), g.closest("md-after").length || p.closest("md-content").length ? (t.setEndAfter(p.closest("[md-inline]")[0]), v = !0) : g.closest("md-meta").length && (t.setEndBefore(p.closest("[md-inline]")[0]), v = !0), a = t.toString(), t.collapsed || 0 === a.trim()) return;
s = v ? s || t.getBookmark(n && document.body.contains(n) ? n : t.commonAncestorContainer) : i instanceof Object ? i : {
start: i,
end: i
}
} else a = t.toString();
return l = /^\s+/g.exec(a), f = /\s+$/g.exec(a), l = l ? l[0].length : 0, f = f ? f[0].length : 0, (l || f) && ((s = s || t.getBookmark(n && document.body.contains(n) ? n : t.commonAncestorContainer || t.commonAncestorContainer)).start += l, s.end -= f, t.moveToBookmark(s)), h = m[1], (d = JSBridge.clipboard.readText()) && d.length > 5e3 && (d = ""), u.isType(e, c.link) ? r.isURL(a) ? h = "](" + a + ")" : r.isURL(d) && (h = "](" + d + ")") : u.isType(e, c.image) && (r.isImg(a) ? h = "](" + a + ")" : r.isImg(d) && (h = "](" + d + ")")), t.insertNodeAtEnd(document.createTextNode(h)), t.insertNode(document.createTextNode(m[0])), i && (u.isType(e, c.link) ? t.moveToBookmark({
containerNode: n,
start: s.start + 1,
end: 1 + s.end
}) : t.moveToBookmark({
containerNode: n,
start: s.start + (o ? 0 : m[0].length),
end: s.end + m[0].length + (o ? m[1].length : 0)
}), editor.selection.setRange(t, !0)), (m[0] || "").length + (m[1] || "").length
};
function g(t, e, n, i) {
var r, o = e.closest('[md-inline="' + i + '"]');
o.length || "link" != i || (o = e.closest('[md-inline="reflink"], [md-inline="autolink"]')), "image" == i && (o.length ? r = /!\[([^\]]*)\]/.exec(o.text())[1] : r || ((o = e.closest('[md-inline="refimg"]')).length ? r = /!\[((?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)\]/.exec(o.text())[1] : (o = e.closest(".md-url").closest("[md-inline]")).length && (r = "!" + o.text()))), i == c.comment && (r = o.text().replace(/(^<\!--)|(-->)$/g, ""));
var a = t.findNodeByElem(n);
r ? (o.text(r), t.selection.selectAllElem(o)) : (o.children(".md-meta, .md-content").remove(), t.brush.addToQueue(o.closest("[cid]").attr("cid"), !0)), a && t.undo.addSnap(a.id, s.REPLACE)
}
var b = i.Model.extend({
initialize: function(t) {
this.editor = t, this.CONST = y, this.putBookmark(null, {
block: []
})
},
removeStyle: function(t, e, n) {
t.children(".md-meta").remove()
},
canContainInline: function(t) {
return t.jquery && (t = t.attr("mdtype")), u.isType(t, c.paragraph, c.def_footnote, c.heading, c.table_cell)
},
putStyle: function(t, e, n) {
this.editor.selection.deRange(t);
var i, r = this.editor.getMarkElem(t.commonAncestorContainer),
o = y.InsertInline.indexOf(e) > -1;
if (o && (r = this.editor.getMarkElem(t.startContainer)), r.length && 0 === r.find("[mdtype]").length && this.canContainInline(r)) {
var s = a.makeEmptyCommand(this.editor.selection.buildUndo()),
c = this.editor.store(r.attr("cid"));
s.undo.push(a.buildReplaceUndo(c)), i = n && this.hasStyleInRange(e, t, !0), (t = this.putStyleForRange(r, e, t, !0, i)).select(), this.editor.store(r.attr("cid")), s.redo.push(a.buildReplaceUndo(c)), s.redo.push(this.editor.selection.buildUndo()), this.editor.undo.register(s), this.editor.brush.addToQueue(c.id, !0)
} else if (!o) return i = n && this.hasStyleInRange(e, t, !1),
function(t, e, n) {
var i = this.editor;
function r(t) {
var o = t.get("children");
return o.length ? o.toArray().map(r) : i.stylize.canContainInline(t.get("type")) && i.findElemById(t.id).text().length && (i.stylize.putStyleInBlock(i.findElemById(t.id), e, void 0, void 0, !0, n), i.store(t), i.brush.addToQueue(t.id)), t
}
var o = i.selection.getDetailPos(t.startContainer, t.startOffset),
s = i.selection.getDetailPos(t.endContainer, t.endOffset),
c = i.getMarkElem(o[0]),
l = i.getMarkElem(s[0]),
f = i.findNodeByElem(c),
h = i.findNodeByElem(l),
d = u.getTreePosition(f, h),
m = d[1],
v = d[2],
p = a.makeEmptyCommand(i.selection.buildUndo()),
g = t.cloneRange(),
b = t.cloneRange(),
y = m;
for (p.undo.push(a.buildReplaceUndo(m)), b.setEndAfter(c[0]), this.canContainInline(f) && b.toString().length && (this.putStyleInBlock(c, e, b.getBookmark(c[0]), void 0, !0, n), i.store(f, !0)), i.UserOp.decorateOneSide(f, m, "after", r), p.redo.push(a.buildReplaceUndo(m)), i.brush.addToQueue(c.attr("cid")), y = m.get("after"); y && y !== v;) p.undo.push(a.buildReplaceUndo(y)), r(y), p.redo.push(a.buildReplaceUndo(y)), y = y.get("after");
h && h != m && (g.setStartBefore(l[0]), g.toString().length && (p.undo.push(a.buildReplaceUndo(v)), this.canContainInline(h) && (this.putStyleInBlock(l, e, g.getBookmark(l[0]), void 0, !0, n), i.store(h, !0)), i.UserOp.decorateOneSide(h, v, "before", r), p.redo.push(a.buildReplaceUndo(v)), i.brush.addToQueue(l.attr("cid")))), p.redo.push(i.selection.buildUndo()), i.undo.register(p), $(".md-expand").removeClass("md-expand"), i.brush.resume(!0)
}.call(this, t, e, i)
},
putStyleInBlock: function(t, e, n, i, r, o) {
if (!r || 0 != t.text().length) {
t[0].hasAttribute("mdtype") && t.addClass("md-expand");
try {
return m.call(this, t, e, n, i, o)
} catch (t) {
console.error(t)
}
}
},
putStyleForRange: function(t, e, n, i, r) {
var o = n.getBookmark(t[0]);
return t[0].hasAttribute("mdtype") && n.commonAncestorContainer.nodeType != document.TEXT_NODE && t.addClass("md-expand"), m.call(this, t, e, o, i, r)
},
addStyle: function(t, e) {
var n, i = y.SyntaxMap[e],
o = document.createElement("SPAN");
o.className = "md-meta md-expand", o.setAttribute("md-inline", e), "link" == e && (n = JSBridge.clipboard.readText(), r.isURL(n) && (i[1] = "](" + n + ")")), o.appendChild(document.createTextNode(i[0] + i[1])), t.insertNode(o), t.moveToBookmark({
containerNode: o,
start: i[0].length,
end: i[0].length
}), this.editor.selection.rangy.getSelection().setSingleRange(t)
},
detach: function(t, e) {
return !(!t.collapsed || !$.parseHTML("<div>" + t.toHtml() + "</div>")[0].querySelector('[md-inline="' + e + '"]')) || $(t.commonAncestorContainer).closest('[md-inline="' + e + '"]').length
},
canToggleStyle: function(t, e, n) {
var i = function(t) {
for (var e = 0; e < t.CONST.NoInline.length; e++)
if (t.hasStyle(t.CONST.NoInline[e])) return !0
}(this);
return !!this.hasStyle(t) || !(i || /(md-meta|md-content)(\s+|$)/g.exec(e[0].className) && !n || /md-blockmeta/g.exec(e[0].className)) && !i
},
clearStyle: function() {
if (window.getSelection().rangeCount && !isInputComponent(document.activeElement) && !File.isLocked) {
this.editor.brush.clearAndPause();
var t = this.editor.selection.getRangy();
if (t) {
for (var e, n = a.makeEmptyCommand(editor.selection.buildUndo()), i = editor.selection.getDetailPos(t.startContainer, t.startOffset), r = editor.selection.getDetailPos(t.endContainer, t.endOffset), o = editor.getMarkElem(i[0]), s = editor.getMarkElem(r[0]), c = editor.findNodeByElem(o), l = editor.findNodeByElem(s), f = u.getTreePosition(c, l), h = f[1], d = f[2], m = h; m && m != d.get("after");) e = m, m = m.get("after"), n.undo.push(a.buildReplaceUndo(e)), this.editor.findElemById(e.id).find(".md-meta, .md-content").remove(), this.editor.store(e.id), this.editor.brush.addToQueue(e.id), n.redo.push(a.buildReplaceUndo(e));
this.editor.undo.register(n)
}
this.editor.brush.resume(), this.editor.brush.expand()
}
},
toggleStyle: function(t) {
if (!File.isLocked && window.getSelection().rangeCount && "INPUT" != document.activeElement.tagName && "TEXTAREA" != document.activeElement.tagName && !File.isLocked) {
var e, n, i = this.editor.selection.getRangy(),
r = this.hasStyle(t),
o = this.editor.getJQueryElem(i.commonAncestorContainer),
a = this.editor.getMarkElem(i.commonAncestorContainer);
if (!r) {
var u = this.editor.getJQueryElem(i.startContainer);
"link" == t && (r = u.closest('[md-inline="reflink"], [md-inline="autolink"]').length), "image" == t && (r = u.closest('[md-inline="refimg"], .md-url').length)
}
this.editor.brush.pause();
do {
if (!this.canToggleStyle(t, o, i.collapsed)) break;
if (r) g(this.editor, o, a, t);
else {
if (!i.collapsed) {
this.putStyle(i, t, !0);
break
}
if (!(n = this.editor.findNodeByElem(a))) return;
e = i.getBookmark(a[0]).start;
var l = a.text().substring(e - 1, e + 1),
f = "**" == l && $(i.startContainer).closest("[md-inline='plain']").length;
t == c.em && f ? (i.moveToBookmark({
containerNode: a[0],
start: e - 1,
end: e + 1
}), i.extractContents()) : !(d = l) || i.collapsed && /^[\(\)\[\]\^&_\-+*#@!~`\\\/\{\}'":;<>,.?%\s]+$/.exec(d) ? this.addStyle(i, t) : (a.addClass("md-expand"), f || t == c.image || this.editor.selection.selectWord(!0, !1, i), (i = this.editor.selection.getRangy()).collapsed ? this.addStyle(i, t) : v.call(this, i, t, a[0], e)), n && this.editor.undo.addSnap(n.id, s.REPLACE)
}
if (this.editor.brush.addToQueue(a.attr("cid")), t == c.inline_math && !r) {
var h = this.editor;
setTimeout(function() {
h.brush.triggerAutoComplete(!0)
}, 100)
}
} while (0);
var d;
this.editor.brush.resume(!0)
}
},
putBookmark: function(t, e) {
return this.editor.styleBookmark = {
cursor: t,
style: e
}
},
isAtFootnoteDefSpan: function() {
var t = this.editor.selection.getRangy();
return t && this.editor.getJQueryElem(t.startContainer).closest(".md-def-name").length
},
buildBookmark: function(t) {
if (File.ignoreStyleChange) return File.editor.styleBookmark.style;
var e, n = {
inline: [],
block: [],
state: ""
},
i = this.editor.selection.getRangy(),
r = (t = t || this.editor.getJQueryElem(i && i.commonAncestorContainer || document.activeElement) || $()).closest("[md-inline]"),
o = t;
if (0 == t.length) {
if (!(t = this.editor.getMarkElem()).length || !u.isType(t.attr("mdtype"), u.TYPE.hr, u.TYPE.toc)) return n;
o = t
}
for (; r.length;) e = r.attr("md-inline"), this.CONST.LinkList.indexOf(e) > -1 && (e = "link"), n.inline.push(e), o = r, r = r.parent().closest("[md-inline]");
for (r = o.closest("[mdtype], [mdlike]"); r.length;)(e = r.attr("mdlike") || r.attr("mdtype")) === c.heading ? n.block.push("header" + r[0].tagName.substring(1)) : e === c.list ? n.block.push(d(this.editor.findNodeByElem(r))) : e === c.list_item ? r.hasClass("md-task-list-item") && !n.state && (n.state = r.hasClass("task-list-done") ? "checked" : "unchecked") : (e = e.replace(/^h([1-6])$/, "header$1"), n.block.push(e)), r = r.parent().closest("[mdtype]");
return n
},
hasStyleInRange: function(t, e, n) {
var i = e.toHtml();
return n && (i = "<div>" + i + "</div>"), 0 == $(i).find("[md-inline='" + t + "']").remove().end().text().trim().length
},
hasStyle: function(t) {
var e = this.editor.styleBookmark.style;
if (e) return (e.inline || []).indexOf(t) > -1 || (e.block || []).indexOf(t) > -1
},
changeStyleFromMenu: function(t) {
if (!File.isLocked && !document.body.classList.contains("modal-open")) {
var e = y.NameMapToStyle[t.toLowerCase()];
u.isType(e, "header1", "header2", "header3", "header4", "header5", "header6", c.paragraph) ? this.changeBlock(e) : u.isType(e, c.def_footnote, c.def_link, c.hr, c.fences, c.math_block, c.toc) ? this.insertBlock(e) : u.isType(e, c.table) ? File.editor.tableEdit.insertTable() : u.isType(e, c.meta_block) ? this.insertMetaBlock() : u.isType(e, c.blockquote) && this.toggleIndent(c.blockquote)
}
},
changeBetweenCodeMirror: function(t, e) {
if (u.isType(e, c.math_block, c.fences)) {
var n = this.editor,
i = a.makeEmptyCommand(n.selection.buildUndo());
u.isType(e, c.fences) ? (n.fences.syncToNode(e.cid), n.fences.beforeDeleteFences(e)) : (n.mathBlock.syncToNode(e.cid), n.mathBlock.beforeDeleteFences(e)), i.undo.push(a.buildReplaceUndo(e)), e.set("type", t), i.redo.push(a.buildReplaceUndo(e)), n.findElemById(e.id).replaceWith(e.toHTML()), t == c.fences ? n.fences.getCm(e.id) : t == c.math_block && n.mathBlock.startEditing(e.id), n.selection.jumpIntoElemBegin(n.findElemById(e.id)), i.redo.push(n.selection.buildUndo()), n.undo.register(i), n.refocus(), h.refreshBlockMenu()
}
},
toggleFences: function() {
if (!File.isLocked && !document.body.classList.contains("modal-open")) {
var t = this.editor.getNode(null, !0);
u.isType(t, c.fences) ? this.changeBlock(c.paragraph, t) : u.isType(t, c.math_block) ? this.changeBetweenCodeMirror(c.fences, t) : this.insertBlock(c.fences)
}
},
toggleMathBlock: function() {
if (!File.isLocked && !document.body.classList.contains("modal-open")) {
var t = this.editor.getNode(null, !0);
u.isType(t, c.math_block) ? this.changeBlock(c.paragraph, t) : u.isType(t, c.fences) ? this.changeBetweenCodeMirror(c.math_block, t) : this.insertBlock(c.math_block)
}
},
changeBlock: function(t, e, n) {
if (!File.isLocked && !document.body.classList.contains("modal-open") && (e = e || this.editor.getNode(null, !0))) {
var o, s, h, d, m = y.getMenuBlockType(e),
v = this.editor,
p = e.cid;
if (u.isType(m, c.math_block, c.html_block, c.table)) v.UserOp.insertParagraph();
else if (!u.isType(e, c.table_row, c.table_cell, c.blockquote, c.list) && (File.option.expandSimpleBlock && u.isType(m, c.paragraph) && e.get("depth") > 0 && (m = "header" + e.get("depth")), v.lastCursor = v.selection.buildUndo(), m == t && n && u.isType(e, c.heading) && (t = c.paragraph), m != t && m)) {
if (u.isType(m, c.fences) && (v.fences.syncToNode(e.cid), v.fences.beforeDeleteFences(e)), (o = a.makeEmptyCommand(v.lastCursor)).undo.push(a.buildReplaceUndo(e)), u.isType(m, c.def_link) && e.set("text", (e.get("href") || "") + (e.get("tittle") ? ' "' + e.get("tittle") + '"' : "")), 0 == t.indexOf("header")) h = t.substr(6) - 0, (s = e.get("pattern")) && /-|=/.exec(s) ? s = h <= 2 ? s.replace(/-|=/g, 1 == h ? "=" : "-") : void 0 : s && (s = s.replace(/#+/g, "#".repeat(h))), e = u.isType(e, c.paragraph) ? File.option.expandSimpleBlock && e.get("depth") && /^#/.exec(e.get("text")) ? function(t, n, r) {
(d = i.utils.clone(o.undo[0])).start += t - e.get("depth"), d.end += t - e.get("depth"), e.set("depth", t);
var s = e.get("text");
if (s = s.replace(/^#+/, "#".repeat(t)).replace(/#+$/, "#".repeat(t)), e.set("text", s), !r) {
var u = f.renderHtmlWithBlockMeta(e, File.editor.brush);
v.findElemById(e.id).replaceWith(u)
}
return o.redo.push(a.buildReplaceUndo(e)), e
}(h) : function(t, n) {
var s = function() {
var t, n, s = e.get("text") || "",
l = s.split(/\n/) || [];
if (e.set("text", s), !l.length) return [t, e, n];
var f = r.findLine(s, v.lastCursor.start);
return e.set("text", f.line), f.start > 0 && (t = e.insert(new u({
type: c.paragraph,
text: s.substring(0, f.start - 1)
}), !0), a.addUndoForInsert(o, t)), f.start + f.line.length < s.length && (n = e.insert(new u({
type: c.paragraph,
text: s.substring(f.start + f.line.length + 1)
}), !1), a.addUndoForInsert(o, n)), (d = i.utils.clone(o.undo[0])).start -= f.start, d.end -= f.start, [t, e, n]
}();
x(t, n, !0);
var l = (s[0] ? s[0].toHTML() : "") + s[1].toHTML() + (s[2] ? s[2].toHTML() : "");
return v.findElemById(e.id).replaceWith(l), s[1]
}(h, s) : x(h, s);
else {
u.isType(e, c.paragraph) && m !== c.paragraph && e.set("text", e.get("text").replace(/^#+\s*/, "")), e.set("type", t), e.set("pattern", void 0);
var g;
if (u.isType(e, c.paragraph) || m != c.paragraph || e.set("text", e.get("text").replace(/\r?\n/g, " ")), u.isType(m, c.meta_block, c.fences) && u.isType(e, c.paragraph) && (e.set("type", c.raw_edit), (g = v.simpleParse(e)) || e.set("type", c.paragraph)), g) {
var b = $(g[1]),
w = b[0].getAttribute("cid"),
F = b.last()[0].getAttribute("cid"),
k = l.createRange();
v.findElemById(g[2]).replaceWith(g[1]), g && a.append(o, g[0]), k.setStartBefore(v.findElemById(w)[0]), k.setEndAfter(v.findElemById(F)[0]), k = v.selection.deRange(k, !0), d = v.selection.buildUndo(k)
} else u.normalizeNode(e), o.redo.push(a.buildReplaceUndo(e)), v.findElemById(e.id).replaceWith(e.toHTML())
}
d || ((d = i.utils.clone(o.undo[0])).startId === p && (d.startId = e.cid), d.endId === p && (d.endId = e.cid), d.id === p && (d.id = e.cid)), v.undo.exeCommand(d), o.redo.push(d), v.undo.register(o), v.refocus()
}
}
function x(t, n, i) {
return e.set("type", c.heading), e.set("depth", t), e.set("pattern", n), i || v.findElemById(e.id).replaceWith(e.toHTML()), o.redo.push(a.buildReplaceUndo(e)), e
}
},
increaseHeaderLevel: function() {
if (!File.isLocked && !document.body.classList.contains("modal-open")) {
var t = this.editor.getMarkElem(),
e = t.attr("mdtype");
e != c.heading && e != c.paragraph || this.editor.stylize.changeHeadingLevel(this.editor.findNodeByElem(t), !0, t.attr("mdlike"))
}
},
decreaseHeaderLevel: function() {
if (!File.isLocked && !document.body.classList.contains("modal-open")) {
var t = this.editor.getMarkElem(),
e = t.attr("mdtype");
e != c.heading && e != c.paragraph || this.editor.stylize.changeHeadingLevel(this.editor.findNodeByElem(t), !1, t.attr("mdlike"))
}
},
insertMetaBlock: function(t, e) {
if (!File.isLocked && !document.body.classList.contains("modal-open")) {
e = e || "";
var n = this.editor.nodeMap.getFirst();
if (!u.isType(n, c.meta_block)) {
this.editor.lastCursor = this.editor.selection.buildUndo();
var i = a.makeEmptyCommand(this.editor.lastCursor || this.editor.selection.buildUndo()),
r = new u({
type: c.meta_block,
in: this.editor.nodeMap,
attachTo: this.editor.nodeMap,
after: n,
text: e
});
return a.addUndoForInsert(i, r), t ? {
command: i,
node: r
} : (this.editor.findElemById(n.cid).before(r.toHTML()), this.editor.selection.restoreSelection(this.editor.findElemById(r.cid), 0), i.redo.push(this.editor.selection.buildUndo()), this.editor.undo.register(i), $(this.editor.sessionStr).trigger("cursorChange"), this.editor.selection.scrollAdjust(), this.editor.refocus(r.cid), r)
}
}
},
insertBlock: function(t, e) {
if (!(File.isLocked || "table" != t && document.body.classList.contains("modal-open"))) {
var n = this.editor,
i = n.selection.getRangy(),
r = "",
o = null,
s = "";
!i || i.collapsed || e ? o = a.makeEmptyCommand() : (r = n.UserOp.prepMarkHtml(i.toHtml(), n).html(), s = i.toString(), o = n.UserOp.backspaceHandler(n, null, "delSelection", !0), i = n.selection.getRangy(), n.selection.deRange(i, !0), n.refocus(null, !1, !0));
var l = this.editor.getNode(null, !0);
if (l) {
var f = y.getMenuBlockType(l),
h = this.editor.findElemById(l.id);
if (this.editor.lastCursor = this.editor.selection.buildUndo(i), f != t && f && u.isType(l, c.paragraph, c.heading)) {
o.undo.push(this.editor.lastCursor), o.undo.push(a.buildReplaceUndo(l));
var d, m = u.splitAt(l, (this.editor.lastCursor || {
start: 0
}).start, n, !0),
v = m.prev,
p = e || new u({
type: t,
text: ""
}),
g = m.next,
b = "",
w = t == c.hr ? g.id : p.id;
u.isType(t, c.math_block, c.fences) ? p.set("text", r ? n.UserOp.getMarkdownSourceFrom(r) : "") : t == c.def_link && (s = (s.trim().split(/\n/) || [])[0] || "", /[\/\\]/.exec(s) ? p.set("href", s.substr(0, 160)) : p.set("ref", (s.split(/\s/)[0] || s).substr(0, 20))), o.redo.push(n.undo.buildReplaceUndo(l)), a.addUndoForInsertArray(o, m.insertArray), v.insert(p, !1), a.addUndoForInsert(o, p), m.insertArray.indexOf(g) > -1 && m.insertArray.splice(m.insertArray.indexOf(g), 0, p), e && F(e, l.get("in")), g && u.isEmptyBlock(g) && u.isType(g.get("after"), c.paragraph) && (a.addUndoForRemove(o, g), g.remove(), g = null), u.isEmptyBlock(v) && (a.addUndoForRemove(o, v), v.remove(), v = null), b = (l.isDeleted() ? "" : l.toHTML()) + m.insertArray.map(function(t) {
return t.isDeleted() ? "" : t.toHTML()
}).join(""), h.replaceWith(b), d = this.editor.findElemById(w), this.editor.selection.jumpIntoElemBegin(d)
} else {
l = l.getClosetBlock(!1);
p = e || new u({
type: t,
text: ""
});
l.insert(p), e && F(e, l.get("in")), a.addUndoForInsert(o, p), this.editor.findElemById(l.cid).after(p.toHTML()), this.editor.selection.jumpIntoElemBegin(this.editor.findElemById(p.cid))
}
this.editor.lastCursor = this.editor.selection.buildUndo(), o.redo.push(this.editor.lastCursor), this.editor.undo.register(o), this.editor.refocus(), $(this.editor.sessionStr).trigger("cursorChange"), this.editor.selection.scrollAdjust()
}
}
function F(t, e) {
t.set("in", e), t.get("children").toArray().map(function(t) {
F(t, e)
})
}
},
toggleTaskStatus: function(t) {
if (!File.isLocked && !document.body.classList.contains("modal-open")) {
var e = this.editor.selection.getRangy(),
n = this.editor.getMarkElem(e && e.startContainer).closest(".md-task-list-item"),
i = n.hasClass("task-list-done");
if (void 0 === t && (t = !i), n.length && t !== i) {
var r = this.editor;
if (e.collapsed) r.getNode(n.attr("cid")).attr("checked", t, r, !1);
else {
var o = a.makeEmptyCommand(),
s = $.parseHTML(e.toHtml());
$(s).find(t ? ".task-list-not-done" : ".task-list-done").addBack(t ? ".task-list-not-done" : ".task-list-done").each(function() {
var e = r.getNode(this.getAttribute("cid")).attr("checked", t, r, !0);
a.append(o, e)
}), o.undo.length ? r.undo.register(o) : r.getNode(n.attr("cid")).attr("checked", t, r, !1)
}
JSBridge.menu.update({
"Paragraph→Task Status→Mark as Complete": {
state: t
},
"Paragraph→Task Status→Mark as Incomplete": {
state: !t
}
})
}
}
},
toggleIndent: function(t, e) {
if (!File.isLocked && !document.body.classList.contains("modal-open")) {
var n, i, r = this.editor,
o = a.makeEmptyCommand(r.selection.buildUndo()),
s = this.editor.selection.getRangy();
if (!(isInputComponent(document.activeElement) && !this.editor.fences.getFocused() || File.isLocked)) {
this.editor.store();
var l = this.editor.selection.buildUndo();
if (this.editor.lastCursor = l, function(t) {
if (t && !t.collapsed) {
var e = !1;
! function t(i) {
var r, o = n(i.endContainer);
o.text().length || o.parent()[0] != i.commonAncestorContainer || (r = o.prev()[0]) && (e = !0, i.setEndAfter(r), t(i))
}(t),
function t(i) {
var r, o = n(i.startContainer);
o.text().length || o.parent()[0] != i.commonAncestorContainer || (r = o.after()[0]) && (e = !0, i.setStartBefore(r), t(i))
}(t), e && r.selection.deRange(t)
}
function n(t) {
return $(t).closest("p")
}
}(s), s) {
var f = r.selection.getDetailPos(s.startContainer, s.startOffset),
h = r.selection.getDetailPos(s.endContainer, s.endOffset),
m = r.getMarkElem(f[0]),
v = r.getMarkElem(h[0]),
p = r.findNodeByElem(m),
g = r.findNodeByElem(v),
b = u.getTreePosition(p, g),
y = (w = b, F = s, F.collapsed && w[2] === w[1] && u.isType(w[1], c.line) ? [w[0], w[1].getLastBrother(!0), w[1].getLastBrother(!1)] : w);
n = y[1], i = y[1] === y[2] ? null : y[2]
} else n = this.editor.findNodeByElem(this.editor.getMarkElem());
var w, F;
n && (this.editor.brush.pause(!0), t == c.blockquote ? function(e, n, i) {
e = e.getClosetBlock(), n = n && n.getClosetBlock();
var o = e.get("parent");
if (f = e, d = o, h = (h = n) || f, d && d.get("type") == c.blockquote && (s.collapsed || !f.get("before") && !h.get("after"))) a.addUndoForUnwrap(i, o), o.unwrap(r);
else {
var l = new u({
type: t,
in: e.get("in")
});
l.wrap(e, n, r), a.addUndoForWrap(i, l)
}
var f, h, d
}(n, i, o) : function(n, i, o, l, f) {
var h = function(t, e) {
e = e || t;
var n = t.get("parent");
if (s.collapsed) {
if (!t.get("before") && !e.get("after") && n && u.isType(n.get("parent"), c.list)) return n.get("parent")
} else if (n && u.isType(n.getClosetBlock(), c.list)) return n.getClosetBlock()
}(n, i),
m = h ? d(h) : void 0;
if (e)
if ("none" == l) {
if (!h) return;
l = m
} else if (h && l == m) return;
if (h) m == l ? (h.get("children").map(function(t) {
a.addUndoForUnwrap(o, t), t.unwrap()
}), a.addUndoForUnwrap(o, h), h.unwrap(r)) : (o.undo.push(a.buildReplaceUndo(h)), h.set("pattern", void 0), k(h, l), r.findElemById(h.id).replaceWith(h.toHTML()), o.redo.push(a.buildReplaceUndo(h)));
else {
for (var v, p = n, g = [], b = (i = i || n).get("after"); p && p != b;) {
var y;
v = p, File.option.ignoreLineBreak || ((y = x(p, o, f)) && y[0] && (v = p = n = y[0]), y && y[1] && (b = y[1]));
var w = new u({
type: c.list_item,
in: n.get("in")
});
p = p.get("after"), w.wrap(v, v, r, !0), g.push(w), a.addUndoForWrap(o, w)
}
k(h = new u({
type: c.list,
in: n.get("in")
}), l);
var F = g[0],
_ = g.last();
if (t == u.ListType.task)
for (var $ = F; $ != _.get("after");) $.set("style", u.ListType.task), $ = $.get("after");
h.wrap(F, _, r), a.addUndoForWrap(o, h), r.refresh()
}
}(n, i, o, t, l), o.redo.push(l), this.editor.undo.exeCommand(l), this.editor.undo.register(o), this.editor.brush.resume(), this.editor.refocus(), this.editor.selection.scrollAdjust())
}
}
function k(t, e) {
e != u.ListType.ol && e != u.ListType.ul || (t.set("style", e), t.get("children").map(function(t) {
t.unset("style"), t.unset("checked")
})), e == u.ListType.task && (t.set("style", u.ListType.ul), t.get("children").map(function(t) {
t.set("style", u.ListType.task)
}))
}
function x(t, e, n) {
if (!u.isType(t, c.paragraph)) return t;
var i = t.get("text").split(/\n/g) || [];
if (i.length < 2) return t;
var o = n.startId == t.cid,
s = n.endId == t.cid,
l = n.start == n.end;
if (o && s) {
e.undo.push(a.buildReplaceUndo(t));
var f, h = [],
d = t;
t.set("text", i[0]);
for (var m, v = t, p = 1; p < i.length; p++) {
var g = i[p];
if (n.start > i[p - 1].length + i[p].length && !l) i[p] = t.get("text") + "\n" + g, t.set("text", i[p]);
else if (f = new u({
type: c.paragraph,
text: g
}), d.insert(f), d = f, h.push(f), o && n.start > i[p - 1].length ? (n.startId = f.cid, n.start -= i[p - 1].length + 1, v = f) : o = !1, s && n.end > i[p - 1].length) {
if (n.endId = f.cid, n.end -= i[p - 1].length + 1, !l && p < i.length - 1 && n.end <= i[p].length) {
m = new u({
type: c.paragraph,
text: i.slice(p + 1).join("\n")
}), d.insert(m), h.push(m);
break
}
} else s = !1
}
return (t.get("text").indexOf("\n") > -1 || v != t) && (r.findElemById(t.cid).replaceWith(t.toHTML()), e.redo.push(a.buildReplaceUndo(t))), m && r.findElemById(t.cid).after(m.toHTML()), a.addUndoForInsertArray(e, h), [v, m]
}
}
},
changeHeadingLevel: function(t, e, n) {
var i, r, o = null;
t.get("type") == c.paragraph ? n && (i = /h(\d)/.exec(n)) ? r = i[1] - 0 : e && (o = "header6") : t.get("type") == c.heading && (r = t.get("depth") - 0), void 0 !== r && (7 == (r -= e ? 1 : -1) ? o = "paragraph" : r > 0 && (o = "header" + r)), o && this.changeBlock(o)
}
}),
y = {
SyntaxMap: {
strong: ["**", "**"],
em: ["*", "*"],
code: ["`", "`"],
del: ["~~", "~~"],
underline: ["<u>", "</u>"],
footnote: ["[^", " ]"],
link: ["[", "]()"],
image: ["![", "]()"],
highlight: ["==", "=="],
superscript: ["^", "^"],
subscript: ["~", "~"],
inline_math: ["$", "$"],
comment: ["\x3c!--", "--\x3e"]
},
NormalBlockMap: {
line: "Paragraph",
paragraph: "Paragraph",
header1: "Header 1",
header2: "Header 2",
header3: "Header 3",
header4: "Header 4",
header5: "Header 5",
header6: "Header 6",
def_link: "Link Reference",
def_footnote: "Footnotes"
},
InsertInline: ["link", "image", "footnote", "inline_math"],
LinkList: ["autolink", "reflink", "link"],
NoInline: ["hr", "fences", "def_link", "code", "meta_block", "raw_edit", "math_block", "toc", "comment", "citation", "tag", "atag", "imgtag", "html_block"],
Selectable: ["hr", "math_block", "toc", "html_block", "fences"],
InsertBlock: ["table", "fences", "hr"],
StyleToNameMap: {
paragraph: "Paragraph",
header1: "Heading 1",
header2: "Heading 2",
header3: "Heading 3",
header4: "Heading 4",
header5: "Heading 5",
header6: "Heading 6",
def_link: "Link Reference",
def_footnote: "Footnotes",
table: "Table",
fences: "Code Fences",
blockquote: "Quote",
toc: "Table of Contents",
hr: "Horizontal Line",
meta_block: "YAML Front Matter",
ol: "Ordered List",
ul: "Unordered List",
tasklist: "Task List",
html_block: "HTML Block",
strong: "Strong",
em: "Emphasis",
code: "Code",
del: "Strike",
highlight: "Highlight",
inline_math: "Inline Math",
math_block: "Math Block",
superscript: "Superscript",
subscript: "subscript",
image: "Image",
footnote: "Superscript",
autolink: "Hyperlink",
reflink: "Hyperlink",
link: "Hyperlink",
url: "Hyperlink",
underline: "Underline",
comment: "Comment",
citation: "Citation"
}
};
y.NameMapToStyle = {};
for (var w in y.StyleToNameMap) y.NameMapToStyle[y.StyleToNameMap[w].toLowerCase()] = w;
y.InsertQuery = '[md-inline="' + y.InsertInline.join('"],[md-inline="') + '"]', y.getMenuBlockType = function(t) {
var e = t.get("type");
switch (e) {
case c.heading:
return "header" + t.get("depth");
case c.list:
return t.get("style")
}
return e
}, b.CONST = y, n.exports = b
}), $__System.registerDynamic("44", ["12", "14", "13", "1b", "1c", "1d"], !0, function(t, e, n) {
"use strict";
this || self, t("12"), t("14");
var i = t("13"),
r = t("1b").SnapFlag,
o = (i.Node, i.TYPE, t("1c"), t("1d")),
a = {
"(": ")",
"[": "]",
"{": "}",
'"': '"',
"'": "'",
"~": "~",
"^": "^",
"=": "=",
"*": "*",
"`": "`",
$: "$",
_: "_"
},
s = null;
var u = null;
var c = null;
e.hanldePair = function(t, e, n, i, s, u) {
if (!File.option.noPairingMatch) {
var l, f, h, d;
if (/^[\]\)\}'"]$/.exec(e)) {
if (t.undo.endSnap(), l = t.findElemById(n.cid).rawText(), e === l.substring(i.start, i.start + 1)) return w(), s || !0;
if ("'" == e || '"' == e) {
if ("" == l) return F();
f = (d = l.substring(0, i.start)).slice(-1);
var m = "'" == e;
if (o.shouldTriggerReplaceQuote(!0) && -1 == "\"'".indexOf(o.userQuote(m ? 2 : 0)) && o.shouldTriggerReplace(t, u)) {
if (h = l.substring(i.start, i.start + 1), o.userQuote(m ? 3 : 1) == h) return w(), s || !0;
if (o.userQuote(m ? 2 : 0) == f) return function(e) {
var i = t.selection.getRangy(),
o = document.createTextNode(e);
return i.insertNode(o), o.parentElement.normalize(), w(), s && t.undo.register(s), t.undo.addSnap(n.cid, r.REPLACE), !0
}(o.userQuote(m ? 3 : 1))
}
if (e != f && "\\" != f && !/\w/.exec(l.substring(Math.max(0, i.start - 1), i.start + 1)) && ! function(t, e) {
for (var n, i, r = t.length, o = 0; o < r; o++) {
var a = t[o];
"'" != a && '"' != a || (n ? n == a ? (n = null, i = null) : i = i ? null : a : n = a)
}
return e == n || e == i
}(d, e)) return F()
}
} else if (/^[\[\(\{]$/.exec(e)) {
if (t.undo.endSnap(), h = (l = t.findElemById(n.cid).rawText()).substring(i.start, i.start + 1), !/[^\[\]{}()"'\s`>$]/.exec(h)) return F()
} else if (File.option.autoPairExtendSymbol && function() {
if (!c) {
var t = "*`_";
File.option.enableInlineMath && (t += "$"), c = new RegExp("^[" + t + "]$")
}
return c
}().exec(e)) {
if (t.undo.endSnap(), u && u.commonAncestorContainer && u.commonAncestorContainer.parentElement && ("CODE" == u.commonAncestorContainer.parentElement.tagName && "`" != e || "SCRIPT" == u.commonAncestorContainer.parentElement.tagName && "$" != e)) return;
if (l = t.findElemById(n.cid).rawText(), File.option.enableInlineMath && "$" == l.substring(i.start - 1, i.start) && /[*`^_~=]/.exec(e)) return;
var v = (d = d || l.substring(0, i.start))[d.length - 1] || "";
if ("\\" == v) return !1;
h = l.substring(i.start, i.start + 1);
var p = l.substring(i.start + 1, i.start + 2),
g = /[*_]/.exec(e);
if (h == e) {
if (g) {
if (g && p) return w() || !0;
var b = $(t.selection.getRangy().commonAncestorContainer);
return b.closest(".md-after").length && b.parent().parent("[md-inline='strong'], [md-inline='em']").length ? w() || !0 : (d = l.substring(0, i.start), /[*_]$/.exec(d) ? F() : w() || !0)
}
return w() || !0
}
var y = 0 == v.trim().length;
if (y || ! function(t, e) {
if ("`" == e && /``$/.exec(t)) return !0;
t.replace(/\\[*`_$]/g, ""), "_" == e && (t = t.replace(/([a-z])_([a-z])/gi, ""));
for (var n = t.length, i = !1, r = 0; r < n; r++) t[r] == e && (i = !i);
return i
}(d, e)) {
if (y && !/^[^\s\>\)\]}'";:.,?!~*\/&#=_+-]/.exec(h)) return F();
if ((v + "a").trim().split(/\b/).length > 1) return F()
}
}
return !1
}
function w() {
var e = t.selection.rangy.createRange();
i.end++, i.start++, e.moveToBookmark(i), e.select(e.isBackward), s && s.redo.push(t.selection.buildUndo())
}
function F() {
var i = t.selection.getRangy(),
c = document.createTextNode(e + a[e]);
i.insertNode(c), o.shouldTriggerReplaceQuote(!0) && /['"]/.exec(e) && o.shouldTriggerReplace(t, u) && o.replaceQuote(c);
var l = c.textContent.toString().length > 2;
return c.parentElement.normalize(), w(), l && w(), s && t.undo.register(s), t.undo.addSnap(n.cid, r.REPLACE), !0
}
}, e.surroundPair = function(t, e, n) {
if (!File.option.noPairingMatch) {
var i, u, c, l = $(n.commonAncestorContainer).closest("[cid]"),
f = $(n.commonAncestorContainer).closest(".md-def-content:not(.md-def-url)");
if ((l.length && !l.find("[cid], .md-def-name").length || f.length) && function() {
if (!s) {
var t = "\\{\\(\\[\"'";
File.option.autoPairExtendSymbol && (t += "*`~_", File.option.enableInlineMath && (t += "$"), File.option.enableSuperscript && (t += "^"), File.option.enableHighlight && (t += "=")), s = new RegExp("^[" + t + "]$")
}
return s
}().exec(e)) {
u = t.findNodeByElem(l), l = f.length ? f : l, i = n.getBookmark(l[0]), c = u.get("text"), u.set("text", c.substring(0, i.start) + e + c.substring(i.start, i.end) + a[e] + c.substring(i.end)), (n = t.selection.rangy.createRange()).moveToBookmark(i), t.selection.deRange(n);
var h = document.createTextNode(e),
d = document.createTextNode(a[e]);
return n.insertNodeAtEnd(d), n.insertNode(h), i.start++, i.end++, n.moveToBookmark(i), n.select(n.isBackward), o.shouldTriggerReplaceQuote(!0) && /['"]/.exec(e) && !/['"]/.exec(o.userQuote('"' == e ? 0 : 2)) && o.shouldTriggerReplace(t, n) && (o.replaceQuote(h, d), n.moveToBookmark(i), n.select(n.isBackward)), t.undo.addSnap(u.cid, r.REPLACE), !0
}
}
}, e.tryRemovePairStart = function(t, e) {
var n = e.toString();
if (!File.option.noPairingMatch && (1 != e.endOffset || !$(e.endContainer).closest(".md-after, .md-before").length) && (function() {
if (!u) {
var t = "\\{\\(\\[\"'";
File.option.autoPairExtendSymbol && (t += "*`~_", File.option.enableInlineMath && (t += "$"), File.option.enableSuperscript && (t += "^")), u = new RegExp("[" + t + "]")
}
return u
}().exec(n) || o.userQuote(0, !0) == n || o.userQuote(2, !0) == n)) {
var i = $(e.commonAncestorContainer).closest("[cid]"),
r = i.text(),
s = e.getBookmark(i[0]),
c = r.substring(s.end, s.end + 1);
if (a[n] == c || o.userQuote(0, !0) == n && o.userQuote(1, !0) == c || o.userQuote(2, !0) == n && o.userQuote(3, !0) == c) return s.end++, e.moveToBookmark(s), e
}
}
}), $__System.registerDynamic("45", ["12", "14", "13", "1b", "1c", "19", "42", "43", "2b", "46", "29", "31", "44"], !0, function(t, e, n) {
this || self, t("12"), t("14");
var i = t("13"),
r = t("1b"),
o = r.SnapFlag,
a = i.Node,
s = i.TYPE,
u = (i.NodeCollectionUtils, t("1c"), t("19"), t("42")),
c = (t("43"), t("2b")),
l = (t("46"), t("29"), t("31"), t("44")),
f = (window.reqnode && reqnode("electron").remote, "skipCommand"),
h = $("content"),
d = function(t, e) {
var n = e.get("parent"),
i = n && n.get("parent");
if (i && i.get("style") == a.ListType.task && !n.get("before") && a.isType(n, s.paragraph)) {
var o = r.makeEmptyCommand(t.selection.buildUndo());
return o.undo.push(r.buildReplaceUndo(i)), i.unset("style"), i.unset("checked"), t.findElemById(i.cid).replaceWith(i.toHTML()), o.redo.push(r.buildReplaceUndo(i)), t.undo.exeCommand(o.undo[0]), o.redo.push(t.selection.buildUndo()), o
}
},
m = function(t, e, n) {
if (a.isType(e.get("parent"), s.blockquote) && (n || !e.get("before"))) {
var o = r.makeEmptyCommand(t.selection.buildUndo()),
u = e.upStream();
return r.append(o, u.command), t.findElemById(u.oldCid).replaceWith(u.newHtml), t.undo.exeCommand(o.undo[0]), o.redo.push(t.selection.buildUndo()), o
}
if (a.isType(e.get("parent"), s.list_item) && (n || !e.get("parent").get("before") && !e.get("before"))) {
o = r.makeEmptyCommand(t.selection.buildUndo());
var c = e.get("parent"),
l = c.get("parent");
o.undo.push(r.buildReplaceUndo(l)), l.unset("start"), c.set("parent", null), c.set("after", null), l.insert(c, !0);
var f = c.unwrap();
return r.addUndoForInsertArray(o, f), t.findElemById(l.id).before(i.NodeCollectionUtils.toHTML(f)), l.get("children").length ? (t.findElemById(l.id).replaceWith(l.toHTML()), o.redo.push(r.buildReplaceUndo(l))) : (r.addUndoForRemove(o, l), l.remove(), t.findElemById(l.id).remove()), t.selection.jumpIntoElemBegin(t.findElemById(f[0].id)), o.redo.push(t.selection.buildUndo()), o
}
},
v = function(t, e, n, i) {
var o = r.makeEmptyCommand(t.selection.buildUndo());
return o.undo.push(r.buildReplaceUndo(e)), e.set("type", s.paragraph), e.clearChildren(), n ? e.set("text", "") : e.set("text", e.get("text").replace(/\u200B|(\r?\n)/g, "")), a.normalizeNode(e), o.redo.push(r.buildReplaceUndo(e)), t.findElemById(e.id).replaceWith(e.toHTML()), t.selection.jumpIntoElemBegin(t.findElemById(e.id)), o.redo.push(t.selection.buildUndo()), !i && $(t.sessionStr).trigger("cursorChange"), o
},
p = function(t, e, n, i) {
if (e && e.length) {
n && n.preventDefault();
var o = t.findNodeByElem(e),
a = r.makeEmptyCommand(t.selection.buildUndo());
return o ? (o.set("text", ""), a = r.append(a, v(t, o))) : (o = t.findNodeByElem(e.closest("[mdtype]")), a.undo.push(r.buildReplaceUndo(o)), t.selection.moveLeftOrRight(!0, n), e.remove(), t.store(o.id), a.redo.push(r.buildReplaceUndo(o)), a.redo.push(t.selection.buildUndo())), !i && t.undo.register(a), a
}
},
g = function(t, e, n, g, b) {
var y, w, F, k, x = t.selection.includeTrailMeta(t.selection.getRangy()),
_ = x && t.selection.deRange(x.cloneRange()),
E = document.activeElement,
C = !1,
A = x;
function S(t, e, n) {
var i, r = t;
if (t == e) return null;
for (i = t.get(n); i;) $("[cid='" + i.id + "']").remove(), i.remove(), i = t.get(n);
return S(t.get("parent"), e, n), r
}
function T(t, e, n, i, o) {
var s, u, l, f = e.cloneRange(),
h = t.findElemById(n.id);
return f.setEndAfter(h[0]), t.selection.deRange(f), u = t.findNodeByElem(t.getMarkElem(f.startContainer)), !o && $(f.startContainer).closest("table").length ? (r.append(i, O(t, f, !0)), u = t.findNodeByElem($(f.startContainer).closest("[mdtype='table']")), n.contains(u) && (S(u, n, "after"), 0 === u.getText().length) ? (r.append(i, v(t, u)), "abortAndSkipCursor") : "abort") : (i.undo.push(r.buildReplaceUndo(n)), s = $(f.extractContents()), a.isType.apply(null, [n].concat(c.CONST.Selectable)) && r.append(i, v(t, n, !0, !0)), t.store(u, !0), t.findElemById(u.cid).replaceWith(u.toHTML()), l = S(u, n, "after"), !!(s.text().length || s.find("img").length || l) && (i.redo.push(r.buildReplaceUndo(n)), u))
}
function M(t, e, n, i, o) {
var a, s, u, c = e.cloneRange(),
l = t.findElemById(n.id);
if (c.setStartBefore(l[0]), t.selection.deRange(c), !o && $(c.endContainer).closest("table").length) return r.append(i, O(t, c, !0)), s = t.findNodeByElem($(c.endContainer).closest("[mdtype='table']")), "abort";
i.undo.push(r.buildReplaceUndo(n)), s = t.findNodeByElem(t.getMarkElem(t.selection.getEndNode(c))), a = $(c.extractContents()), t.store(s, !0);
var f = t.findElemById(s.cid);
if (u = S(s, n, "before"), a.text().length || a.find("img").length || u) {
for (i.redo.push(r.buildReplaceUndo(n)); f.parent().closest(".md-task-list-item").length;) f = f.parent().closest(".md-task-list-item");
return f.hasClass("md-task-list-item") ? f.replaceWith(t.findNodeByElem(f).toHTML()) : f.replaceWith(s.toHTML()), s
}
return f.replaceWith(s.toHTML()), !1
}
function D(t, e, n, i, o, u, c) {
var l, f, h, d;
function m(t, e) {
return t == e || t.get("before") || t.get("after") ? t : m(t.get("parent"), e)
}
var v = a.isEmptyBlock(i);
if (!v || i == o || a.isEmptyBlock(o) && !c)
if (v && i == o && o.isBlock()) o.set("type", s.paragraph), o.set("text", ""), o.clearChildren(), t.findElemById(o.id).replaceWith(o.toHTML()), t.selection.jumpIntoElemBegin(t.findElemById(o.id)), u.redo.push(t.selection.buildUndo());
else {
if (console.assert(e != n, "Error on spliceStartAndEnd"), e != n) {
if (l = n.safeGetStrAttr("text"), d = m(n, o), r.addUndoForRemove(u, d), t.findElemById(d.id).remove(), d.remove(), f = $(e.toHTML()).rawText().length, u.undo.push(r.buildReplaceUndo(i)), a.isType(e, s.def_link))
if (e.safeGetStrAttr("title").length) e.set("title", e.get("title") + l);
else {
var p = /["']([^"]*)["']\s*$/g.exec(l);
l = l.replace(/"([^"])*"\s*$/, ""), p && e.set("title", p[1]), e.set("href", e.get("href") + l)
}
else e.set("text", e.safeGetStrAttr("text") + l);
if (d != o && o !== n && o.get("before") == i && a.isType(i, s.list_item)) {
var g = o.getFirstChild();
g.set("before", i.getLastChild()), o.giveChildrenTo(i, g), r.addUndoForRemove(u, o), t.findElemById(o.id).remove(), o.remove()
}
u.redo.push(r.buildReplaceUndo(i)), t.findElemById(i.id).replaceWith(i.toHTML()), h = t.findElemById(e.id)
}((h = t.findElemById(e.id)).hasClass("md-def-link") || h.hasClass("md-def-footnote")) && h.attr("contenteditable", "true"), t.undo.exeCommand({
type: "cursor",
id: e.id,
start: f,
end: f
}), u.redo.push(t.selection.buildUndo())
}
else t.findElemById(i.id).remove(), r.addUndoForRemove(u, i), i.remove(), d = m(n, o), t.findElemById(d.id).replaceWith(d.toHTML()), t.selection.jumpIntoElemBegin(t.findElemById(d.id))
}
function L(t, e) {
var n = e.get("before");
function i(e) {
var n = r.makeEmptyCommand(t.selection.buildUndo());
return r.addUndoForRemove(n, e), t.findElemById(e.id).remove(), e.remove(), n.redo.push(t.selection.buildUndo()), n
}
return a.isType(n, s.hr) ? i(n) : n && !a.isEmptyBlock(e) && a.isEmptyBlock(n) ? i(n) : !n && a.isType(e.get("parent"), s.list_item) && (n = e.get("parent").get("before")) && 1 == n.get("children").length && a.isEmptyBlock(n.get("children").at(0)) ? i(n) : void 0
}
function R(t, i) {
if (a.isType(i, s.table_cell)) {
var o = i.get("parent").get("parent");
if (e && !n && !i.get("before") && !i.get("parent").get("before") && t.tableEdit.isTableEmpty(o)) return t.tableEdit.deleteTable(t.findElemById(o.cid), !0);
var c = u.getSibling(i, "before");
return c && (F = r.makeEmptyCommand(t.selection.buildUndo()), t.selection.jumpIntoElemEnd(t.findElemById(c.id)), F.redo.push(t.selection.buildUndo())), F
}
}
function B(t, e) {
if (a.isType(e.get("parent"), s.list_item) && e.get("parent").get("before") && !e.get("before")) return function(t, e) {
var n, o = r.makeEmptyCommand(t.selection.buildUndo()),
a = e.get("before"),
s = a.get("children").at(a.get("children").length - 1).getLastBrother();
return o.undo.push(r.buildReplaceUndo(a.get("parent"))), t.findElemById(e.id).remove(), s.insert(e), n = e.unwrap(), o.redo.push(r.buildReplaceUndo(a.get("parent"))), t.findElemById(s.id).after(i.NodeCollectionUtils.toHTML(n)), t.selection.jumpIntoElemBegin(t.findElemById(n[0].id)), o.redo.push(t.selection.buildUndo()), o
}(t, e.get("parent"))
}
function I(t, e) {
if (a.isType(e, a.backToParagraphBeforeDelete)) return t.stylize.changeBlock(s.paragraph, e), f
}
function N(t, e, n, i, o) {
for (var u = [R, L, d, m, B, I], c = null, l = 0; l < u.length; l++)
if (c = u[l](t, e)) return c;
if (n = n || e, o = o || n.get("before"), i = i || o && o.getVeryFirst(!0), !c && i && D(t, i, e, o, n, c = r.makeEmptyCommand(t.selection.buildUndo())), !c && !i && a.isType(e, s.paragraph) && a.isEmptyBlock(e) && e.get("after")) {
c = r.makeEmptyCommand(t.selection.buildUndo());
var f = e.get("after").cid;
r.addUndoForRemove(c, e), e.remove(), t.findElemById(e.cid).remove(), t.selection.jumpIntoElemBegin(t.findElemById(f)), c.redo.push(t.selection.buildUndo())
}
return c
}
function O(t, e, n) {
var i, o = t.selection.getDetailPos(e.startContainer, e.startOffset),
u = t.selection.getDetailPos(e.endContainer, e.endOffset),
c = r.makeEmptyCommand(),
l = t.getMarkElem(o[0]),
f = t.getMarkElem(u[0]),
h = l.closest('[mdtype="table"]'),
d = t.findNodeByElem(h),
m = t.findNodeByElem(l),
v = t.findNodeByElem(f);
if (n || ((i = e.cloneRange()).collapse(!0), i = t.selection.buildUndo(i)), e.setStart(o[0], o[1]), e.setEnd(u[0], u[1]), m == v) return e.collapsed || !a.isType(m, s.table_cell) || l[0] != e.commonAncestorContainer && !l[0].contains(e.commonAncestorContainer) || (c.undo.push(r.buildReplaceUndo(m)), e.extractContents(), t.store(m, !0), c.redo.push(r.buildReplaceUndo(m)), c.redo.push(t.selection.buildUndo(e))), c;
c.undo.push(r.buildReplaceUndo(d));
var p, g, b = T(t, e, m, c, !0),
y = M(t, e, v, c, !0);
for (b && (b.unset("marginLeft"), b.unset("marginRight")), y && (y.unset("marginLeft"), y.unset("marginRight")), p = t.tableEdit.getSibling(m, "after"); p && p != v;) p.set("text", ""), p.unset("marginLeft"), p.unset("marginRight"), g = !0, p = t.tableEdit.getSibling(p, "after");
return b || y || g ? (t.findElemById(d.id).replaceWith(d.toHTML()), c.redo.push(r.buildReplaceUndo(d))) : c.undo.pop(), n || (c.redo.push(i), t.undo.exeCommand(i)), c
}
function j(e) {
return t.selection.deRange(e), y = t.getMarkElem(e.commonAncestorContainer), w = t.nodeMap.allNodes.get(y.attr("cid")), k = e.getBookmark(y[0]), y.length && w && !w.get("children").length && 0 == k.start && !n
}
function P() {
var n = null;
if (a.isType(w.get("before"), a.TYPE.hr, a.TYPE.toc) && (n = w.get("before")), e && e.preventDefault(), $(".md-tooltip-remove").remove(), y.prev("[cid]").addClass("md-expand"), (F = N(t, w)) === f);
else if (!g) return n && (t.selection.selectNode(n), F.redo.push(t.selection.buildUndo())), t.undo.register(F), t.refresh(), n || t.findElemById(w.cid).trigger("refocus"), t.refocus(), t.selection.scrollAdjust(), F
}
var q = $(document.activeElement).closest(".CodeMirror");
if (q.length) {
q[0].CodeMirror.execCommand("delCharBefore")
} else {
if (a.isType(E.getAttribute("mdtype"), a.TYPE.hr, a.TYPE.toc)) {
var U = $(E).closest("[mdtype]");
return p(t, U, e, g)
}
if (E.getAttribute("mdtype") == s.math_block) return e && e.preventDefault(), t.mathBlock.remove(E.getAttribute("cid")), F;
if (n && "Backspace" != n ? !0 === n && (n = "Delete") : n = !1, _) {
if ($(_.commonAncestorContainer).closest("[mdtype='table_row']").length && e && e.shiftKey && (File.isMac ? e.metaKey : e.ctrlKey)) return e.preventDefault(), t.tableEdit.deleteRow(), f;
if (_.collapsed) {
if (n) {
if ("Delete" == n && (z = _, t.selection.deRange(z), y = t.getMarkElem(z.commonAncestorContainer), w = t.nodeMap.allNodes.get(y.attr("cid")), k = z.getBookmark(y[0]), "Delete" == n && a.isType(y.attr("mdtype"), s.paragraph, s.heading) && !w.get("children").length && 0 == k.start && 0 == y.text().length && (F = w.get("after") ? function(e, n) {
var i = r.makeEmptyCommand(t.selection.buildUndo());
return t.findElemById(e.cid).remove(), r.addUndoForRemove(i, e), e.remove(), t.selection.jumpIntoElemBegin(t.findElemById(n)), i.redo.push(t.selection.buildUndo()), i
}(w, w.get("after").getVeryFirst().cid) : null))) return g || (t.undo.register(F), t.refocus()), e && e.preventDefault(), F
} else if (j(_)) return P();
if (!0 === (_ = function() {
var i = e && (File.isNodeHtml ? e.ctrlKey : e.altKey),
r = !1;
return "delSelection" == n ? t.selection.getRangy() : (i || (r = t.selection.extendCharFromCollapse(_, !n)), r || (C = !0, n ? (window.getSelection().modify("extend", "forward", i ? "word" : "character"), _ = t.selection.getRangy()) : (window.getSelection().modify("extend", "backward", i ? "word" : "character"), _ = i ? (/\n/.exec(window.getSelection().toString()) ? (_.setStart(_.startContainer, 0), _.select(_.isBackward)) : _ = t.selection.getRangy(), _) : t.selection.getRangy())), !n && /^\u200b|\007F$/g.exec(_.toString()) ? (t.selection.extendCharFromCollapse(_, !0), j(_) || _) : _)
}())) return P();
if (!n && l.tryRemovePairStart(t, _) && (b = !1), "delSelection" == n && _ && _.collapsed) return e && e.preventDefault(), r.makeEmptyCommand()
} else ! function(e) {
if (t.selection.selectWordTime && File.isMac)
if (n) "Delete" == n && e.endContainer.nodeType === document.TEXT_NODE && (i = e.endContainer.textContent.charAt(e.endOffset), /\s/.exec(i) && (e.endOffset++, A = e.cloneRange()));
else if (e.startOffset > 0 && e.startContainer.nodeType === document.TEXT_NODE) {
var i = e.startContainer.textContent.charAt(e.startOffset - 1);
/\s/.exec(i) && (e.startOffset--, A = e.cloneRange())
}
}(_);
var z;
(H = _).startContainer.parentElement && H.startContainer.parentElement.classList.contains("md-pants") && 0 == H.startOffset && H.setStart(H.startContainer.parentElement, 0);
var H;
if (b && function() {
if (!(_.commonAncestorContainer.nodeType != document.TEXT_NODE || 0 == n && _.startOffset <= 1 || "Delete" == n && _.endOffset >= _.commonAncestorContainer.textContent.length - 1) && t.selection.getRangy().endContainer == _.endContainer) return !0
}()) return null;
if (t.selection.selectWordTime = null, t.selection.deRange(_), y = t.getMarkElem(_.commonAncestorContainer), w = t.nodeMap.allNodes.get(y.attr("cid")), C && (window.getSelection().removeAllRanges(), window.getSelection().addRange(x.nativeRange)), y.length && !w.get("children").length) {
if (y.get("type") !== s.fences) return function(t, e, n, i, u) {
var c, l = 3 !== n.commonAncestorContainer.nodeType,
f = t.getNode(i.attr("cid"));
u || (t.undo.addSnap(f.cid, o.NONE), t.brush.clearAndPause());
var d = t.selection.buildUndo(A);
if ((F = r.makeEmptyCommand(d)).undo.push(r.buildReplaceUndo(f)), !l && d && d.startId == d.endId && a.isType(f, s.line)) {
var m = (i.text().substring(0, d.start).match(/\u200b/g) || []).length,
v = (i.text().substring(0, d.end).match(/\u200b/g) || []).length;
t.undo.lastSnap && t.undo.lastSnap.selection.end == d.end && t.undo.lastSnap.selection.start == d.start ? (t.undo.lastSnap.selection.start -= m, t.undo.lastSnap.selection.end -= v) : (d.start -= m, d.end -= v)
}
var p = h.scrollTop(),
g = n.commonAncestorContainer;
if (!g.contains(document.querySelector("#write"))) {
if (g.parentElement.getAttribute("md-inline")) {
var b = g.parentElement;
1 == i.children().length && i.children()[0] == b && (b.textContent.length != n.toString().length || b.style.display || (b.style.display = "inline-block"))
}
if (c = n.extractContents(), p != h.scrollTop() && t.undo.clearEventTimer(), t.store(f.cid), t.wordCount.quickUpdate(f, !0), F.redo.push(r.buildReplaceUndo(f)), a.isType(f, s.def_link, s.def_footnote) ? t.selection.deRange(n, !0) : f.getText().length || (t.findElemById(f.cid).html($(f.toHTML()).html()), n = t.selection.getRangy(), t.selection.deRange(n, !0)), F.redo.push(t.selection.buildUndo()), c.querySelector("img"), n.collapse(!1), l) {
var y = i.attr("cid");
l = t.selection.saveSelection(i, n), n.setStart(i[0], 0);
var w = (n.toString().match(/(:\u200b)|(\u200b:)/g) || []).length;
t.store(y, !0), i.replaceWith(t.nodeMap.allNodes.get(y).toHTML()), i = t.findElemById(y), l.start -= w, l.end -= w, t.selection.restoreSelection(i, l), t.focusCid = null, t.refocus()
}
return t.brush.addToQueue(i.attr("cid")), !u && t.brush.resume(!0), e && (e.preventDefault(), $("#write").trigger("input")), u || null != e || t.undo.register(F), F
}
}(t, e, _, y, g);
F = p(t, y, e, g)
} else e && e.preventDefault(), $(".md-tooltip-remove").remove(), F = function(t, e, n) {
if (!document.contains(e.startContainer) && !(e = t.selection.getRangy())) return r.makeEmptyCommand();
var i = t.selection.getDetailPos(e.startContainer, e.startOffset),
o = t.selection.getDetailPos(e.endContainer, e.endOffset),
s = t.getMarkElem(i[0]),
u = t.getMarkElem(o[0]),
c = t.findNodeByElem(s),
l = t.findNodeByElem(u);
if (!c || !l) return r.makeEmptyCommand();
var f = a.getTreePosition(c, l),
h = f[1],
d = f[2],
m = r.makeEmptyCommand(t.selection.buildUndo()),
v = e.cloneRange();
if (s[0] == u[0]) return m;
if (v.collapse(!0), v = t.selection.buildUndo(v), e.setStart(i[0], i[1]), e.setEnd(o[0], o[1]), $(e.commonAncestorContainer).closest('[mdtype="table"]').length) return r.append(m, O(t, e));
var p = T(t, e, h, m),
g = M(t, e, d, m),
b = h.get("after"),
y = [];
for (e = t.selection.getRangy(), t.selection.deRange(e, !0); b && b != d;) y.push(b), b = b.get("after");
return r.addUndoForRemoveArray(m, y, h, d), y.map(function(e) {
t.findElemById(e.id).remove(), e.remove()
}), "abort" == p || "abort" == g || "abortAndSkipCursor" == p ? ("abortAndSkipCursor" != p && (e.collapse(!0), m.redo.push(v), t.undo.exeCommand(v)), !1 === g && 0 == l.getText().length && (r.addUndoForRemove(m, l), t.findElemById(l.id).remove(), l.remove())) : p || g || y.length || n ? D(t, p || c, g || l, h, d, m, p) : m = N(t, l, d, c, h), m.redo.push(t.selection.buildUndo()), m
}(t, _, n), g || (t.undo.register(F), t.refocus(), t.refresh()), t.selection.scrollAdjust();
return F
}
}
},
b = {
"[mdtype='hr']": g,
"tr[mdtype='table_row']": u.deleteRow,
".md-toc": p
};
e.backspaceHandler = g, e.deleteSelectable = p, e.deleteLineProcessor = b, e.deleteLine = function(t) {
var e = $(document.activeElement).closest(".CodeMirror");
if (e.length) e[0].CodeMirror.execCommand("deleteLine");
else {
var n, i = t.getMarkElem();
if (i && i.length) {
for (n in b)
if (i.closest(n).length) return void b[n](t, i.closest(n));
! function(e) {
var n = e.hasClass("md-expand");
e.addClass("md-expand"), window.getSelection().modify("move", "backward", "sentence"), window.getSelection().modify("extend", "forward", "sentence"), n && e.removeClass("md-expand"), g(t, null, "delSelection")
}(i)
}
}
}, e.deleteBlock = function(t) {
t || File.editor;
var e = t.getNode(t.focusCid);
if (e) {
var n = r.makeEmptyCommand(t.selection.buildUndo());
e = e.getClosetBlock(!1), !a.isType(e, s.paragraph) || e.get("before") || e.get("after") || !e.get("parent") || a.isVirtualBlock(e.get("parent")) || (e = e.get("parent"));
var i = e.getClosetBlock(!0).getVeryFirstBrotherIncludeTopBlock(!1, !0);
i ? (t.findElemById(e.cid).remove(), r.addUndoForRemove(n, e), e.remove()) : (e.set("type", s.paragraph), e.set("text", ""), e.clearChildren(), n.redo.push(t.undo.buildReplaceUndo(e)), t.findElemById(e.cid).replaceWith(e.toHTML())), t.selection.jumpIntoElemBegin(t.findElemById(i.cid)), n.redo.push(t.selection.buildUndo()), t.refocus(i.cid), t.undo.register(n)
}
}, e.backToParagraph = v
}), $__System.registerDynamic("47", ["12", "14", "13", "1b", "1c", "19", "42", "43", "2b", "46", "18", "31", "45"], !0, function(t, e, n) {
"use strict";
this || self, t("12");
var i = t("14"),
r = t("13"),
o = t("1b"),
a = r.Node,
s = r.TYPE,
u = r.NodeCollectionUtils,
c = (t("1c"), t("19")),
l = t("42"),
f = t("43"),
h = t("2b"),
d = t("46"),
m = t("18"),
v = (t("31"), t("45")),
p = window.reqnode ? reqnode("electron").remote : null,
g = v.backspaceHandler,
b = function(t) {
return a.isEmptyBlock(t) || a.isType(t, s.list_item) && 1 == t.get("children").length && a.isEmptyBlock(t.getFirstChild())
},
y = function(t, e, n, r, u, l) {
if (e = e || (h = t.getMarkElem(), t.getNode(h.attr("cid")))) {
var f = t.getJQueryElem(window.getSelection().anchorNode),
h = t.findElemById(e.id);
a.noChangeLine(e) && (n = n.trim().split(/[\n\r]+/gi)[0]), "\n" == n && h.text().length <= r && (n = "\n​"), u && u.undo.push(o.buildReplaceUndo(e, void 0));
var d = f.closest(".md-def-link, .md-def-footnote").length;
if (d && f.hasClass("md-def-name")) h = f.closest("[cid]"), t.selection.getRangy().insertNode(document.createTextNode(i.escape(n))), e.set("ref", f.text());
else if (d && f.hasClass("md-def-url")) h = f.closest("[cid]"), n = n.replace(/\s/gi, ""), t.selection.getRangy().insertNode(document.createTextNode(i.escape(n))), e.set("href", f.text());
else if (d && f.hasClass("md-def-title")) h = f.closest("[cid]"), t.selection.getRangy().insertNode(document.createTextNode(i.escape(n))), e.set("title", f.text());
else {
var m, v = "",
p = r;
f.hasClass("md-meta-block") && 0 == f.text().length && "\n​" == n ? m = "\n\n" : (f.hasClass("md-meta-block") && v.length == r && "\n" == v[r - 1] ? r-- : d && f.closest(".md-def-content").length ? (p -= e.get("ref").length + 1, v = f.closest(".md-def-content").rawText()) : (v = h.rawText(), a.isType(e, s.meta_block) && (v = v.replace(/\n$/, ""))), m = void 0 !== p ? v.substring(0, p) + n + v.substring(p) : v.text() + n), e.set("text", m.replace("​", "")), h.html($(c.renderHtmlWithBlockMeta(e, t.brush)).html())
}
u && (t.store(e, !0), u.redo.push(o.buildReplaceUndo(e, void 0)));
var g = {
id: e.id,
type: "cursor",
start: r + n.length
};
l && (t.undo.exeCommand(g), t.brush.addToQueue(e.id)), u && u.redo.push(g), t.brush.addToQueue(e.id), h = t.findElemById(e.id), l && h.addClass("md-focus"), h.length && t.refreshUnder(h[0])
}
},
w = function(t, e, n, r, o) {
if (File.isMac) ! function(t, e, n, r) {
var o = {};
i.isDefined(t) && (o["text/html"] = A(t)[0]), i.isDefined(e) && (o["text/markhtml"] = e), i.isDefined(n) && (o["text/plain"] = n), JSBridge.clipboard.writeForMac(o, r)
}(t, e, n, r);
else if (File.isNode)
if (o) {
if ("cut_before" === File._CopyContentFlag || "cut" == o.type && t) {
if (!t) return setTimeout(p.getCurrentWindow().webContents.copy, 0), void(File._CopyContentFlag = "cut_after");
g(File.editor, null, "delSelection"), File._CopyContentFlag = !1
} else if ("cut_after" === File._CopyContentFlag) File._CopyContentFlag = !1, t = (A(p.clipboard.readHTML()) || [])[0], g(File.editor, null, "delSelection");
else if (t && !File._CopyContentFlag);
else {
if (!File._CopyContentFlag) return File._CopyContentFlag = !0, void(!t && setTimeout(p.getCurrentWindow().webContents.copy, 0));
!0 === File._CopyContentFlag && (t = (A(p.clipboard.readHTML() || t) || [])[0] || ""), File._CopyContentFlag = !1
}
null != n ? o.clipboardData.setData("text/plain", n) : r && o.clipboardData.setData("text/plain", ""), null != t ? o.clipboardData.setData("text/html", t) : r && o.clipboardData.setData("text/html", ""), null != e ? o.clipboardData.setData("text/markhtml", e) : r && o.clipboardData.setData("text/markhtml", ""), o.preventDefault()
} else r && p.clipboard.clear(), p.clipboard.write({
html: A(t)[0] || n,
text: n
}), e && (File._CopyContentFlag = "mock_copy", setTimeout(p.getCurrentWindow().webContents.copy, 0))
},
F = function(t, e, n) {
e = e || File.editor;
var i, r, o, a;
return t.find(".md-fences").toArray().map(function(t) {
i = t.getAttribute("cid"), (r = $(t)).attr("lang", r.attr("lang")), r.text(e.fences.getValue(i))
}), n && n.skipEmoji || t.find(".md-emoji").toArray().map(function(t) {
(r = $(t)).text(":" + r.attr("data-content") + ":")
}), t.find("[mdtype='math_block']").toArray().map(function(t) {
i = t.getAttribute("cid"), (r = $(t)).text(e.mathBlock.getTex(i))
}), t.find("[mdtype='html_block']").toArray().map(function(t) {
i = t.getAttribute("cid");
var n = e.getNode(i);
(r = $(t)).text(n.get("text"))
}), t.find(".md-math-after-sym").remove(), (o = t.children("li[cid]")).length && ((a = $(document.querySelector("[cid='" + o[0].getAttribute("cid") + "']").parentElement).clone()).empty().append(o).wrap("div"), t = a.parent()), t
},
k = function(t, e) {
/^\<(tbody|thead)/.exec(t) && (t = "<table mdtype='table'>" + t + "</table>");
var n = $($.parseHTML("<div>" + t + "</div>"));
return F(n, e)
},
x = function(t, e) {
t = t || File.editor;
var n = document.activeElement,
i = t.selection.getRangy();
if (t.sourceView.inSourceMode) w(null, null, File.editor.sourceView.cm.getSelection(), !0, e);
else if ("HR" == n.getAttribute("mdtype")) w(null, null, "---", !0, e);
else if (n.getAttribute("mdtype") !== s.math_block || i && !i.collapsed) {
if (isInputComponent(n) || void 0 !== n.tabindex) w(null, null, n.value || n.textContent, !0, e);
else if (window.getSelection().rangeCount) {
var r, o = "";
i.collapsed && (r = (r = $(i.startContainer).closest(".md-table-fig")).length ? k(r[0].outerHTML, t) : null), r || (r = k(i.toHtml(), t)), o = r.html(), w(null, o, D(o), !0, e)
}
} else w(null, null, "$$\n" + t.mathBlock.getTex(n.getAttribute("cid")) + "\n$$", !0, e);
File._CopyContentFlag = !1
};
function _(t, e, n) {
var i = "",
r = T(i = k(t, e).html());
return [e.export.exportCollection(r, null, {
forPrint: !0,
noStyle: !0,
exportFooter: !0,
prettyForRendering: n,
split: "\n"
}), i]
}
var E = function(t, e) {
t = t || File.editor;
var n = document.activeElement,
r = t.selection.getRangy();
if (t.sourceView.inSourceMode) w(null, null, File.editor.sourceView.cm.getSelection(), !0, e);
else if ("HR" == n.getAttribute("mdtype")) w(null, null, "<hr/>", !0, e);
else if (n.getAttribute("mdtype") !== s.math_block || r && !r.collapsed) {
if (isInputComponent(n) || 0 == n.childElementCount) {
if (n.classList.contains("md-content") && r.toString() == n.textContent) {
var o = $(n).closest(".md-image");
if (o.length) {
var a = _(o[0].outerHTML, t)[0];
return void w(null, "<pre mdtype='fences' lang='HTML'>" + i.escape(a) + "</pre>", a, !0, e)
}
}
w(null, null, n.value || n.textContent, !0, e)
} else if (window.getSelection().rangeCount) {
a = _(r.toHtml(), t)[0];
w(null, "<pre mdtype='fences' lang='HTML'>" + i.escape(a) + "</pre>", a, !0, e)
}
} else w(null, null, "$$\n" + t.mathBlock.getTex(n.getAttribute("cid")) + "\n$$", !0, e)
},
C = function(t, e) {
t = t || File.editor;
var n, i, r = document.activeElement,
o = t.selection.getRangy();
if (t.sourceView.inSourceMode) w(null, null, File.editor.sourceView.cm.getSelection(), !0, e);
else if ("HR" == r.getAttribute("mdtype")) {
var a = t.getNode(r.getAttribute("cid"));
w("<hr/>", null, a.get("text"), !0, e)
} else if (r.getAttribute("mdtype") !== s.math_block || o && !o.collapsed)
if (isInputComponent(r) || 0 == r.childElementCount) {
if (r.classList.contains("md-content") && o.toString() == r.textContent) {
if ($(r).closest(".md-image").length) return i = _(o.toHtml(), t, !0), void w(i[0], i[1], null, !0, e)
}
w(r.value || r.textContent, null, r.value || r.textContent, !0, e)
} else window.getSelection().rangeCount && (i = _(o.toHtml(), t, !0), w(i[0], i[1], null, !0, e));
else {
n = r.getAttribute("cid");
var u = t.getNode(n);
w(t.export.getSVGForExport(u, !1), "$$\n" + t.mathBlock.getTex(n) + "\n$$", "$$\n" + t.mathBlock.getTex(n) + "\n$$", !0, e)
}
},
A = function(t) {
if (!t) return "";
var e = $.parseHTML(t || ""),
n = "<!DOCTYPE html>",
i = "<!DOCTYPE html>",
r = File.option.showLineNumbersForFence ? "&nbsp;" : "";
return e ? (e.map(function(t) {
var e = $(t),
o = e.find(".md-emoji").addBack(".md-emoji");
if (e.hasClass("md-br")) return n += "<br/>", void(i += "<br/>");
o.text(function(t) {
return $(o[t]).children("[data-emoji]").attr("data-emoji")
}), e.find(".ty-table-edit, .md-meta, .md-content, .md-rawblock-tooltip").remove(), e.find("[cid].md-fences").addBack("[cid].md-fences").html(function() {
var t = this.querySelectorAll("pre.CodeMirror-line");
if (t.length) {
for (var e = [], n = 0; n < t.length; n++) t[n].innerHTML && e.push(r + t[n].innerHTML);
return e.join("<br/>")
}
return this.innerHTML
}), e.find("p, h1, h2, h3, h4, h5, h6, .md-def-link, .md-def-footnoote").css("width", ""), e.find(".md-br").text("\n"), e.find(".md-def-name").before("[").after("] "), e.find(".task-list-item > p").oldReplaceWith(function() {
return (this.previousElementSibling && "INPUT" == this.previousElementSibling.tagName ? " " : "") + this.innerHTML + (this.nextSibling ? "\n" : "")
}), e.find(".md-entity").text(function() {
return this.dataset.content
}), e.find("[contenteditable]").removeAttr("contenteditable"), n += t.outerHTML || t.textContent, t.getAttribute && t.getAttribute("mdtype") == s.toc || (e.find(".md-toc").remove(), e.find(".mathjax-block").addBack(".mathjax-block").html(function() {
try {
return File.editor.findElemById(this.getAttribute("cid")).find("script").text()
} catch (t) {
return ""
}
}).css("font-size", "1rem"), e.find("li p").oldReplaceWith(function() {
return this.innerHTML + (this.nextSibling ? "\n" : "")
}), e.find("ul, ol, .md-def-link, .md-def-footnoote, blockquote, .md-fences, .mathjax-block").after("<br/>"), e.find(".md-def-name").before("[").after("] "), i += t.outerHTML || t.textContent, a.isType(t.tagName, "UL", "OL", "PRE") ? i += "<br/>" : t.classList && t.classList.contains("md-toc") && (i += "<br/>"))
}), [n, i]) : ["", ""]
};
function S(t, e, n, i) {
e || (M.reset(!0), e = M);
var r, o, s = $($.parseHTML("<div>" + t + "</div>")[0]),
u = [],
c = s.children("[mdtype]");
return c.length ? (c.each(function() {
(o = a.reverse($(this), e, n, i)).set("before", r), r = o, u.push(o)
}), u) : n ? (s.find("[data-emoji]").text(function() {
return this.getAttribute("data-emoji")
}), s.find(".md-meta, .md-content").remove(), s.text()) : s.rawText()
}
function T(t, e, n, i, r) {
return S(t, e, !1, r)
}
var M = new r.NodeMap;
function D(t) {
var e = T(t, void 0, 0, 0, !0);
return "string" == typeof e ? e : a.markFromArr(e)
}
var L = function(t, e, n, r, c) {
var d = "";
if (File._PasteContentFlag = !1, t = t || File.editor) {
var v = "string" != typeof e || n ? null : e,
p = "string" == typeof e && n ? e : null,
w = "object" == typeof e ? e : null;
if ("INPUT" == document.activeElement.tagName || document.activeElement.classList && document.activeElement.classList.contains("ty-input")) return !0;
if ("TEXTAREA" == document.activeElement.tagName) {
if (!w && p) {
var F = $(document.activeElement).closest(".CodeMirror");
F && (F = F[0].CodeMirror).replaceSelection(p)
}
return !0
}
if (a.isType(A, s.hr)) return !1;
if ("BODY" == document.activeElement.tagName) return !1;
var k, x, _, E = t.UserOp.backspaceHandler(t, null, "delSelection", !0, !1) || o.makeEmptyCommand(),
C = t.getMarkElem(),
A = t.findNodeByElem(C),
S = {
html: v,
text: p
};
w ? (w.preventDefault(), JSBridge.clipboard.read(w, S).then(j)) : S.html || S.text ? j(S) : JSBridge.clipboard.read(null, S).then(j)
}
function M(t, e) {
return t.get("attr") && t.get("attr").trim().length ? t.get("attr") : void 0
}
function D(e, n, i, r) {
var u = t.tableEdit.TableEdit;
function c(t, e, n, i) {
var r = t.safeGetStrAttr("text"),
o = function t(e) {
return a.isType(e, a.TYPE.paragraph, a.TYPE.heading, a.TYPE.raw_edit, a.TYPE.fences, a.TYPE.table_cell) ? e.get("text") : (!a.isType(e, s.def_footnote) || M(e) && M(e)) && (!a.isType(e, s.def_link) || M(e) && M(e)) ? e.get("children").toArray().reduce(function(e, n) {
return e + t(n)
}, " ") : M(blocks[0]) || M(blocks[0]) || M(blocks[0]) || M(blocks[0]) || ""
}(n).replace(/\r?\n/g, " ");
return t.set("text", r.substr(0, e) + o + r.substr(e)), e + o.length
}
var l, f = e.get("parent").get("parent"),
h = e,
d = h;
r.undo.push(o.buildReplaceUndo(f));
var m = [];
i.forEach(function(t, e) {
t.get("type") == s.table ? m = m.concat(function(t) {
for (var e, n = t.getFirstChild().getFirstChild(), i = []; n;) e = n, i.push(n), n = u.getSibling(n), e.detach();
return t.remove(), i
}(t)) : m.push(t)
});
for (var v = 0; v < m.length && h; v++) l = c(h, 0 === v ? n : 0, m[v]), d = h, h = a.isType(m[v], s.table_cell) ? u.getSibling(h, !1, !0) : u.getNextCellInColumn(h);
t.findElemById(f.id).replaceWith(f.toHTML()), r.redo.push(o.buildReplaceUndo(f)), void 0 !== l ? t.selection.jumpInto(t.findElemById(d.id), l) : t.selection.jumpIntoElemEnd(t.findElemById(d.id)), r.redo.push(t.selection.buildUndo())
}
function L(e, n, i, o, a) {
if (!r) try {
var s = t.selection.restoreEdge(t.findElemById(e), n);
void 0 !== o ? s = t.selection.restoreEdge(t.findElemById(i), o, !0, s) : s.setEndAfter(t.findElemById(i)[0] || t.findElemById(e)[0]), t.imgEdit.tryMoveImageInRange(s, !0)
} catch (t) {
console.error(t)
}
}
function B(e, n, i, r, o, u) {
i.undo.push(t.selection.buildUndo());
var c = o(r, t.nodeMap, t, d);
if ("string" == typeof c) return N(e, n, c, i);
if (1 == c.length && n && -1 == c[0].get("text").indexOf("\n")) return N(e, n, c[0].get("text"), i);
if (0 != c.length) {
if (a.isType(e, s.table_cell)) D(e, n, c, i);
else if (a.isType(e, s.table_row, s.table));
else {
a.isType(e.get("parent"), s.list_item) ? i.undo.push(t.undo.buildReplaceUndo(e.get("parent"))) : i.undo.push(t.undo.buildReplaceUndo(e));
var l = e === t.nodeMap.getFirst() && 0 === n,
f = [];
c.map(function(t, e) {
a.isType(t, s.meta_block) && (0 != e || !l) && f.push(t)
}), f.map(function(t) {
c.remove(t)
});
var h = a.splitAt(e, n, t, !1, !0, !0);
if (O(h.prev, h.next, c, i, h.insertArray, e), h.prev && c.last()) try {
var m = h.prev.isDeleted() ? c[0] : h.prev,
v = c.last();
!h.prev.isDeleted() && a.isType(h.prev, s.list_item) && (v.isDeleted() || h.prev.contains(c.last())) && (m = h.prev.getVeryFirst()), L(m.getVeryFirst(!0, !1).cid, n, c.last().cid, void 0)
} catch (t) {
console.stackError(t)
}
}
t.undo.register(i)
}
}
function I(e, n, i, r) {
if (!e.isDeleted() && !n.isDeleted()) {
var u = e.canContainBlock() ? e.getLastChild() : e,
c = n.canContainBlock() ? n.getFirstChild() : n,
l = -1;
if (t.stylize.canContainInline(u) && t.stylize.canContainInline(c) && !a.isType(u, s.table_cell) && !a.isType(c, s.table_cell)) {
l = u.get("text").length, u.set("text", u.get("text") + c.get("text"));
var f = function t(e) {
if (e && !e.isDeleted()) {
var n = e.get("parent");
return n ? e.get("before") || e.get("after") ? e : t(n) : e
}
}(c);
return o.addUndoForRemove(i, f), f.remove(), r.remove(f), n.isDeleted() || a.isType(n, s.list_item) && a.isType(e, s.list_item) && (i.undo.push(o.buildReplaceUndo(e)), e.getLastChild().insertTillEnd(n.getFirstChild()), o.addUndoForRemove(i, n), n.remove(), r.remove(n)), i.redo.push(o.buildReplaceUndo(e)), l
}
}
}
function N(e, n, i, r) {
var u = (i = i.replace(/\u00a0/g, " ").replace(/\u200b/g, "").replace(/^[\r\n]+/g, "").replace(/[\r\n]+$/g, "")).split(/\r?\n/g);
if (u.length > 1 && !u[0].trim().length && u[1].trim().length && (u = u.slice(1)), a.isType(e, s.table_cell)) return function(e, n, i, r) {
r.undo.push(t.selection.buildUndo()), i = i.trim();
var a = null;
/\|/.exec(i) && (a = /\s*\|\s*/);
var s, u = e;
if (a) {
var c = i.split(/\n/).filter(function(t) {
return t.length
}),
f = e.get("parent"),
h = l.getColumnIndex(e);
c.map(function(i, c) {
if (f && !/^[-\s:|]+$/.exec(i)) {
var l = i.split(a);
"" == l[0] && (l = l.subarray(1)), "" == l.last() && (l = l.subarray(0, l.length - 1));
var d = f.getNthChild(h);
l.map(function(t, i) {
d && (r.undo.push(o.buildReplaceUndo(d)), 0 == c && 0 == i ? (e.set("text", e.get("text").substring(0, n) + t + e.get("text").substring(n)), s = n + t.length) : (i == l.length - 1 ? d.set("text", t + d.get("text")) : d.set("text", t), u = d, s = t.length), r.redo.push(o.buildReplaceUndo(d)), d = d.get("after"))
}), t.findElemById(f.id).replaceWith(f.toHTML()), f = f.get("after")
}
})
} else r.undo.push(o.buildReplaceUndo(e)), i = i.replace(/<br\/?>/g, "\n").replace(/\n/, "<br/>"), e.set("text", e.get("text").substring(0, n) + i + e.get("text").substring(n)), r.redo.push(o.buildReplaceUndo(e)), t.findElemById(e.id).replaceWith(e.toHTML()), s = n + i.length;
var d = t.findElemById(u.cid);
t.selection.jumpInto(d, s), r.redo.push(t.selection.buildUndo()), t.undo.register(r), d.length && t.refreshUnder(d[0]), L(e.cid, 0, u.cid, u.get("text").length)
}(e, n, i, r);
if (a.noChangeLine(e) && (u = [u[0]]), u.length <= 1 || h.CONST.NoInline.indexOf(e.get("type")) > -1) i = u.join("\n"), y(t, e, i, n, r, !0),
function(t, e, n, i, r) {
if (a.isType(e, s.paragraph) && m.BLOCK_OPEN_REG.exec(n) && m.BLOCK_OPEN_REG.exec(e.get("text"))) {
var u = r.redo.last(),
c = e.parseFrom({
skips: {
old_code: !1,
pass_format: !0
}
});
r.redo.push(o.buildReplaceUndo(e)), o.addUndoForInsertArray(r, c[1].subarray(1));
var l = c[1].last().getVeryFirst(!0),
f = u.end || n.length + i;
t.findElemById(e.id).replaceWith(c[0]), t.selection.jumpInto(t.findElemById(l.cid), f), r.redo.push(t.selection.buildUndo())
}
}(t, e, i, n, r);
else {
if (r.undo.push(t.selection.buildUndo()), a.isType(e, s.paragraph) && a.isType(e.get("parent"), s.list_item) ? r.undo.push(o.buildReplaceUndo(e.get("parent"))) : r.undo.push(o.buildReplaceUndo(e)), a.isType(e, s.paragraph) && !a.isType(e.get("parent"), s.list_item)) return function(e, n, i, r) {
var a = e.get("text");
e.set("text", a.substring(0, n) + i + a.substring(n));
var s = e.parseFrom({
skips: {
old_code: !1,
pass_format: !0
}
});
r.redo.push(o.buildReplaceUndo(e)), o.addUndoForInsertArray(r, s[1].subarray(1)), t.findElemById(e.id).replaceWith(s[0]);
var u = s[1].last().getVeryFirst(!0),
c = Math.max(u.get("text").length - (a.length - n), 0);
t.selection.jumpInto(t.findElemById(u.cid), c), r.redo.push(t.selection.buildUndo()), t.undo.register(r), t.focusCid = u.cid, t.refresh(), L(e.cid, 0, u.cid, u.get("text").length)
}(e, n, i, r);
var c = a.splitAt(e, n, t),
f = a.parseFrom(u.join("\n"), e.get("in"), {
noTop: !c.prev.get("attachTo"),
skips: {
old_code: !1,
pass_format: !0
}
}, !0);
a.isType(c.prev, s.list_item) && r.undo.push(o.buildReplaceUndo(c.prev)), O(c.prev, c.next, f[1], r, c.insertArray, e)
}
t.undo.register(r), L(e.cid, n, e.cid, n + i.length)
}
function O(e, n, i, r, c, l) {
var f, d = l.id,
m = -1;
i = function(t) {
for (var e = [], n = -2, i = 0; i < t.length; i++) {
var r = t[i];
a.isType(r, s.table_cell) ? (n !== i - 1 ? (r.set("type", s.paragraph), e.push(r)) : (e.last().set("text", e.last().get("text") + " " + r.get("text")), r.remove()), n = i) : e.push(r)
}
return e
}(i = function(t) {
var e, n, i = [],
r = t[0].get("before"),
o = t.last().get("after"),
u = t[0].get("parent");
return t.map(function(t) {
a.isType(t, s.list_item) ? (n = !0, e || (e = new a({
type: e,
in: t.get("in")
}), i.push(e)), e.append(t)) : (e = null, i.push(t))
}), n && (console.log("group list items"), i.map(function(e, n) {
0 == n ? e.set("before", r) : e.set("before", t[n - 1]), n == i.length - 1 ? e.set("after", o) : e.set("after", t[n + 1]), e.set("parent", u)
})), i
}(i)), f = i.last().getVeryFirst(!0), c = c || [n], l = l || e;
var v = c.indexOf(n),
p = !1;
if (b(n) ? (c.remove(n), n.remove(), p = !0) : a.isType(f, h.CONST.Selectable) && (f = n), !a.isType(e, s.blockquote, s.list)) {
if (a.isType(e, s.list_item) && a.isType(i[0], s.list, s.list_item)) ! function(e, l) {
r.redo.push(o.buildReplaceUndo(e));
var h, v = n,
p = e.get("parent");
if (d = e.id, a.isType(i[0], s.list)) {
e.insert(i[0]);
var g = i.shift().unwrap();
if (h = g.concat(c), o.addUndoForInsertArray(r, h), !l || b(e)) {
var y = h.shift();
void 0 == I(e, y, r, h) && (y.isDeleted() || h.unshift(y))
}
h.unshift(e), n.isDeleted() || i.length || (m = I(g.last(), n, r, h))
}
if (i.length) {
var w;
d = p.cid, p.insertArray(i, !1, !0);
var F = i.clone();
h = (h = [p]).concat(i), v && !v.isDeleted() ? (d = p.cid, r.undo.push(o.buildReplaceUndo(p)), p.unset("ahead"), p.unset("tail"), (w = p.clone()).unset("start"), p.giveChildrenTo(w, v, null, !0), r.redo.push(o.buildReplaceUndo(p)), i.last().insert(w), h.push(w), F.push(w), o.addUndoForInsertArray(r, F)) : o.addUndoForInsertArray(r, F)
} else f = h.last();
t.findElemById(d).replaceWith(u.toHTML(h))
}(e, p);
else {
var g = e.getVeryFirst(!0);
g.insertArray(i, !1, !0), v > -1 && c.splice.apply(c, [v, 0].concat(i)), o.addUndoForInsertArray(r, c), a.isEmptyBlock(g) ? (o.addUndoForRemove(r, g), g.remove()) : I(g, i.shift(), r, c), n.isDeleted() || (a.isEmptyBlock(n) ? (o.addUndoForRemove(r, n), n.remove()) : m = i.length ? I(i.last(), n, r, c) : I(e, n, r, c)), (f = i.last() || e) && !f.isDeleted() && (f = f.getVeryFirst(!0)), l.isDeleted() || r.redo.push(o.buildReplaceUndo(l));
var y = (l.isDeleted() ? "" : l.toHTML()) + c.map(function(t) {
return t.isDeleted() ? "" : t.toHTML()
}).join("");
t.findElemById(d).replaceWith(y)
}
a.isType(f, h.CONST.Selectable) && (n && !n.isDeleted() && (f = n), m = -1);
try {
m >= 0 ? t.selection.jumpInto(t.findElemById(f.cid), m) : f == n ? t.selection.jumpIntoElemBegin(t.findElemById(n.cid)) : t.selection.jumpIntoElemEnd(t.findElemById(f.getVeryFirst(!0).cid)), r.redo.push(t.selection.buildUndo())
} catch (t) {
console.warn(t)
}
t.tryEnterBusyMode(), setTimeout(function() {
t.refocus(), t.refresh()
}, 0), setTimeout(function() {
t.selection.scrollAdjust()
}, 100)
}
}
function j(e) {
if (E.undo.push(t.selection.buildUndo()), E = o.append(E, g(t, w, "delSelection", !0)), A = t.findNodeByElem(t.getMarkElem()), k = t.selection.getRangy(), c || A && k) {
x = k.getBookmark(t.findElemById(A.id)[0]).start;
var a = t.getJQueryElem(k.startContainer);
if (n = n || k.startContainer && a.closest(".md-def-url, .md-def-name, .md-def-title, pre, code").length, _ = e.markhtml, v = e.html, p = e.text, d = e.baseUrlInClipboard || "", n) i.isDefined(p) || (p = f.parseInlineHTML(v, t, d)), N(A, x, p = p || "", E);
else if (_) r = !0, B(A, x, E, _, T);
else {
if (!v) return void JSBridge.clipboard.readImage().then(function(e) {
e && e.length ? R(t, e) : N(A, x, p, E), t.selection.scrollAdjust()
});
a.closest(".md-def-content").length ? (p = f.parseInlineHTML(v, t, d), N(A, x, p, E)) : B(A, x, E, v, f.parseHTML)
}
t.selection.scrollAdjust()
}
}
},
R = function(t, e) {
if (window.app) {
if (app.document.isLocked()) return
} else if (File.isLocked) return !1;
t.sourceView.inSourceMode || t.imgEdit.doInsertFromURLs(e, !0)
};
e.getMarkdownSourceFrom = D, e.nativeCopyText = function(t) {
var e = document.createElement("textarea");
document.body.appendChild(e), e.value = t, e.focus(), e.select(), document.execCommand("Copy"), e.remove()
}, e.copyAsMarkdown = x, e.copyAsSemanticHTML = C, e.copyAsHTMLSource = E, e.copyHandler = function(t, e) {
if ("copyAsMarkdown" === File._CopyContentFlag) return x(t, e);
if ("copyAsHTMLSource" === File._CopyContentFlag) return E(t, e);
if ("copyAsSemanticHTML" === File._CopyContentFlag) return C(t, e);
var n = document.activeElement,
r = t.selection.getRangy(),
o = $(n).closest("[cid]");
if (t.sourceView.inSourceMode) w(null, null, File.editor.sourceView.cm.getSelection(), !0, e);
else {
if (isInputComponent(n)) return e || console.sendError("in copyHandler : shouldn't be here"), !0;
if ("hr" == n.getAttribute("mdtype")) w(n.outerHTML, null, "---", !0, e);
else if ("toc" == n.getAttribute("mdtype")) w(n.outerHTML, "<div mdtype='toc'><div>", "[toc]", !0, e);
else if ("IMG" == n.tagName) w(n.outerHTML, null, n.getAttribute("src") || "", !0, e);
else if (o.attr("mdtype") !== s.math_block || r && !r.collapsed)
if (o.attr("mdtype") !== s.html_block || r && !r.collapsed) {
if (window.getSelection().rangeCount) {
if (!File._CopyContentFlag && File.isNode) return File._CopyContentFlag = !0, p.clipboard.clear(), void setTimeout(p.getCurrentWindow().webContents.copy, 0);
t.selection.includeTrailMeta(r);
var a = r.toHtml(),
u = $($.parseHTML("<div>" + a + "</div>"));
u.find(".md-emoji").text(function() {
return d.data[this.getAttribute("data-content")]
}), u.find(".md-header-span").oldReplaceWith(function() {
var t = $(this).prev();
if (t.length) {
var e = t.text().trim().length;
return t.remove(), t.next().remove(), "<h" + e + " mdtype='heading'>" + this.innerHTML + "</h" + e + ">"
}
}), u.find(".math-jax-postprocess svg").remove();
var c = (u = F(u, t, {
skipEmoji: !File.option.copyMarkdownByDefault
})).html(),
l = File.option.copyMarkdownByDefault ? D(c) : function(t) {
var e = S(t, null, !0);
return "string" == typeof e ? e : f.convertToPlain(e)
}(c).replace(/\u200B/gi, "");
w(null, c, l, !1, e)
}
} else {
var h = t.getNode(o.attr("cid")),
m = h.get("text");
w(m, "<div mdtype='" + s.html_block + "' data-tag='" + i.escape(h.get("style")) + "'>" + i.escape(m) + "</div>", m, !0, e)
}
else {
var v = t.mathBlock.getTex(o.attr("cid"));
w(n.querySelector(".MathJax_Display").outerHTML, "<div mdtype='" + s.math_block + "'>" + v + "</div>", v, !0, e)
}
}
}, e.insertInlineText = y, e.pasteHandler = L, e.setClipboard = w, e.prepMarkHtml = k, e.insertParagraph = function(t, e, n) {
if (!File.isNode || !File.isLocked) {
e = e || File.editor, n = n || e.getMarkElem();
var i = e.findNodeByElem(n),
r = new a({
type: s.paragraph,
text: ""
}),
u = o.makeEmptyCommand(e.selection.buildUndo(void 0, n));
i && ((i = i.getClosetBlock()).insert(r, t), o.addUndoForInsert(u, r), t ? e.findElemById(i.cid).before(r.toHTML()) : e.findElemById(i.cid).after(r.toHTML()), e.selection.jumpIntoElemBegin(e.findElemById(r.cid)), u.redo.push(e.selection.buildUndo()), e.undo.register(u), e.refocus())
}
}, e.insertDom = function(t) {
File.editor.focusAndRestorePos(), L(File.editor, $("<div>").append(t).html(), !1)
}, e.processClipboardHTML = A
}), $__System.registerDynamic("2e", ["12", "14", "13", "1b", "1c", "19", "42", "31", "43", "45", "41", "44", "1d", "47"], !0, function(t, e, n) {
"use strict";
this || self, t("12");
var i = t("14"),
r = t("13"),
o = t("1b"),
a = r.Node,
s = r.TYPE,
u = (r.NodeCollectionUtils, t("1c"), t("19")),
c = (t("42"), t("31")),
l = (t("43"), t("45")),
f = t("41"),
h = t("44"),
d = t("1d"),
m = t("47"),
v = function(t, e, n, i) {
var r, o = t;
if (t == e) return null;
for (r = t.get(n); r;) i(r, o), r = (o = r).get(n);
return v(t.get("parent"), e, n, i), o
};
e.getDisplayText = function(t) {
var e = t.clone();
return e.find(".md-meta, .md-content").remove(), e.text().replace(/\u00A0/g, " ")
}, e.decorateOneSide = v, e.simpleExpand = function(t, e) {
if (File.isLocked) return !1;
var n, i, r, c = t.getNode(e),
l = t.selection.buildUndo();
if (!a.isType(c, s.heading, s.def_footnote, s.def_link) || l.startId && l.startId != l.endId) return !1;
if ((n = c.toMark().trim()).match(/\n/)) return !1;
var f = o.makeEmptyCommand(t.lastCursor);
if (!f.undo.length || !f.undo[0].id && f.undo[0].startId != f.undo[0].endId) return !1;
if (f.undo.push(o.buildReplaceUndo(c)), a.isType(c, s.heading) && (i = c.get("pattern") && c.get("pattern").replace("{0}", "").length || c.get("depth") + 1), a.isType(c, s.def_link, s.def_footnote)) {
var h, d = t.selection.getRangy(),
m = t.getJQueryElem(d.startContainer);
h = m.closest(".md-def-content"), i = a.isType(c, s.def_link) ? 1 : 2, h.length && (i += 3), (h = m.closest(".md-def-title")).length && m.text().length && (i += 5)
}
return c.set("text", n), c.set("type", s.paragraph), f.redo.push(o.buildReplaceUndo(c)), (l = t.selection.buildUndo()).start += i, l.end += i, l.id = c.cid, l.startId = l.endId = void 0, f.redo.push(l), r = u.renderHtmlWithBlockMeta(c, t.brush), t.findElemById(c.cid).replaceWith(r), t.undo.exeCommand(l, []), f.incomplete = !0, t.undo.register(f), c.cid
}, e.insertFileLink = function(t, e) {
if (!File.isLocked) {
var n = c.getFileNameFromPath(e);
e = i.getRelativePath(c.getCurrentFileFolderPath(), e), m.pasteHandler(t, " [" + n + "](" + e + ") ", !0, !0, !0)
}
}, e.backspaceHandler = l.backspaceHandler, e.deleteSelectable = l.deleteSelectable, e.deleteLineProcessor = l.deleteLineProcessor, e.deleteLine = l.deleteLine, e.deleteBlock = l.deleteBlock, e.backToParagraph = l.backToParagraph, e.getMarkdownSourceFrom = m.getMarkdownSourceFrom, e.nativeCopyText = m.nativeCopyText, e.copyAsMarkdown = m.copyAsMarkdown, e.copyAsSemanticHTML = m.copyAsSemanticHTML, e.copyAsHTMLSource = m.copyAsHTMLSource, e.copyHandler = m.copyHandler, e.insertInlineText = m.insertInlineText, e.pasteHandler = m.pasteHandler, e.setClipboard = m.setClipboard, e.insertDom = m.insertDom, e.prepMarkHtml = m.prepMarkHtml, e.insertParagraph = m.insertParagraph, e.processClipboardHTML = m.processClipboardHTML, e.moreIndent = f.moreIndent, e.lessIndent = f.lessIndent, e.hanldePair = h.hanldePair, e.surroundPair = h.surroundPair, e.PunctuationOp = d
}), $__System.registerDynamic("48", ["26", "13", "2b", "2e", "14", "1b"], !0, function(t, e, n) {
"use strict";
this || self;
var i = "",
r = t("26"),
o = t("13"),
a = o.Node,
s = o.TYPE,
u = t("2b"),
c = t("2e"),
l = t("14"),
f = (r = t("26"), t("1b").SnapFlag, r.map),
h = window.reqnode ? reqnode("electron").remote : null;
function d(t) {
t = t || ".context-menu", $(t).removeClass("show").find(".active").removeClass("active")
}
function m(t) {
var e = h.getCurrentWindow();
d(), e.inspectElement(t.clientX, t.clientY)
}
var v = !1;
function p() {
v = !0;
var t = (h.app.setting.config || {}).searchService || [
["Search with Google", "https://google.com/search?q=%s"]
];
t.forEach(function(e, n) {
var r = $($.parseHTML('<li data-group="search" data-key>\n<a role="menuitem">' + l.escape($.localize.getString(e[0], "Menu")) + "</a></li>")[0]);
0 === n ? ($("#search-service-placeholder").after('<li class="divider" data-group="search"></li>').replaceWith(r), r.attr("data-key", "search-default"), t.length > 2 && r.after('<li data-key="search-with" data-group="search" class="has-extra-menu">\n<a role="menuitem"><span>' + $.localize.getString("Search With…") + '</span><i class="fa fa-caret-right"></i></a></li>')) : 1 === n && 2 == t.length ? $("[data-key='search-default']").after(r) : $("#search-menu").append(r), r.click(function() {
t = e[1], d(), h.shell.openExternal(t.replace(/%s/, encodeURIComponent(i)));
var t
})
})
}
function g(t, e) {
var n = $("[data-group='" + t + "']");
e ? n.show() : n.hide()
}
function b() {
return File.editor && File.editor.spellChecker && File.editor.spellChecker.curSpellchecker
}
function y() {
if (File.editor.sourceView && File.editor.sourceView.inSourceMode) {
var t = File.editor.sourceView.cm,
e = t.getCursor("from"),
n = t.getCursor("to");
t.setSelection(e, n, {
scroll: !1
}), t.focus()
} else File.editor.lastCursor && File.editor.undo.exeCommand(File.editor.lastCursor)
}
var w = function(t) {
this.sessionStr = t, $(document).ready(k.bind(this))
},
F = function() {
!!document.querySelector("#user-context-menu.show") ? this.showCustom(j, O) : d()
},
k = function() {
$("content").on("post-scroll", F.bind(this)), $(window).on("resize", F.bind(this)), M.call(this), File.isMac || (A.call(this), L.call(this), x.call(this), S.call(this), T.call(this), window.reqnode && setTimeout(D.bind(this), 1e3))
},
x = function() {
document.querySelector("#context-menu");
$("[data-style]").click(function() {
d(), y(), File.editor.refocus(), File.editor.stylize.toggleStyle(this.getAttribute("data-style"))
})
},
_ = function() {
var t = File.editor.getMarkElem(),
e = !1;
t.closest("thead").length || (t.closest("tbody").children().length >= 2 ? ($("[data-key='delete_table_row']").show(), e = !0) : $("[data-key='delete_table_row']").hide()), t.closest("tr").children().length >= 2 ? ($("[data-key='delete_table_col']").show(), e = !0) : $("[data-key='delete_table_col']").hide(), e ? $("[data-key='delete_table_col']").next(".divider").show() : $("[data-key='delete_table_col']").next(".divider").hide()
};
w.prototype.updateTableVisiblity = _;
var E, C, A = function() {
$("body").on("mouseenter", ".context-menu [data-key]", function() {
var t = $(this);
t.closest(".context-menu").find(".active").removeClass("active"), t.addClass("active")
}).on("mouseleave", ".context-menu", function(t) {
$(this).find(".active:not(.has-extra-menu)").removeClass("active")
}), $("#context-menu").on("mouseenter", "[data-key]", function() {
var t = $(this);
"block-style" == t.attr("data-key") ? (B("#block-style-menu", t), t.addClass("active")) : (document.querySelector("#block-style-menu").classList.remove("show"), document.querySelector("[data-key='block-style']").classList.remove("active")), "insert" == t.attr("data-key") ? (B("#insert-menu", t), t.addClass("active")) : (document.querySelector("#insert-menu").classList.remove("show"), document.querySelector("[data-key='insert']").classList.remove("active")), "copy-as" == t.attr("data-key") ? (B("#edit-menu", t), t.addClass("active")) : (document.querySelector("[data-key='copy-as']").classList.remove("active"), document.querySelector("#edit-menu").classList.remove("show")), "search-with" == t.attr("data-key") ? (B("#search-menu", t), t.addClass("active")) : (document.querySelector("#search-menu").classList.remove("show"), $("[data-key='search-with']").removeClass("active")), "table" == t.attr("data-key") ? (_(), B("#table-menu", t), t.addClass("active")) : (document.querySelector("#table-menu").classList.remove("show"), document.querySelector("[data-key='table']").classList.remove("active")), "math" == t.attr("data-key") ? (B("#math-menu", t), t.addClass("active")) : (document.querySelector("#math-menu").classList.remove("show"), document.querySelector("[data-key='math']").classList.remove("active"))
})
},
S = function() {
$("#context-menu").on("click", "[data-indent]", function() {
var t = this.getAttribute("data-indent");
d(), y(), File.editor.refocus(), File.editor.stylize.toggleIndent(t)
}).on("click", "[data-tab]", function() {
d(), y(), File.editor.refocus();
"left" == this.getAttribute("data-tab") ? c.lessIndent(File.editor) : c.moreIndent(File.editor)
}), $("#block-style-menu").on("click", "[data-block]", function() {
var t = this.getAttribute("data-block");
d(), y(), File.editor.refocus(), File.editor.stylize.changeBlock(t)
}), $("#insert-menu").on("click", "[data-insert]", function() {
var t = this.getAttribute("data-insert");
d(), y(), File.editor.refocus(), t === s.table ? File.editor.tableEdit.insertTable() : t === s.meta_block ? File.editor.stylize.insertMetaBlock() : File.editor.stylize.insertBlock(t)
}).on("click", "[data-insert-p]", function() {
var t = "before" == this.getAttribute("data-insert-p");
d(), File.editor.refocus(E.attr("cid")), File.editor.UserOp.insertParagraph(t, File.editor, E)
})
},
T = function() {
$("#math-menu").on("click", '[data-key="copy_as_mathml"]', function() {
d(), y(), File.editor.styleBookmark.style.block.indexOf(s.math_block) > -1 ? File.editor.mathBlock.copyAsMathML(E[0]) : File.editor.mathInline.copyAsMathML()
}).on("click", '[data-key="copy_as_word"]', function() {
d(), y(), File.editor.styleBookmark.style.block.indexOf(s.math_block) > -1 ? File.editor.mathBlock.copyAsMathML(E[0], !0) : File.editor.mathInline.copyAsMathML(!0)
}).on("click", '[data-key="copy_as_math_tex"]', function() {
d(), y(), File.editor.styleBookmark.style.block.indexOf(s.math_block) > -1 ? File.editor.mathBlock.copyAsTex(E[0]) : File.editor.mathInline.copyAsTex()
}).on("click", '[data-key="copy_as_math_image"]', function() {
d(), y(), File.editor.styleBookmark.style.block.indexOf(s.math_block) > -1 ? File.editor.mathBlock.copyAsImage(E[0]) : File.editor.mathInline.copyAsImage()
}), File.isWin || $("#math-menu [menu-for-win]").hide()
},
M = function() {
$("#table-menu").on("click", '[data-key="insert_row_before"]', function() {
d(), y(), File.editor.tableEdit.addRow(!0)
}).on("click", '[data-key="insert_row_after"]', function() {
d(), y(), File.editor.tableEdit.addRow(!1)
}).on("click", '[data-key="delete_table_row"]', function() {
d(), y(), File.editor.tableEdit.deleteRow(!1)
}).on("click", '[data-key="insert_col_before"]', function() {
d(), y(), File.editor.tableEdit.addCol(!0)
}).on("click", '[data-key="insert_col_after"]', function() {
d(), y(), File.editor.tableEdit.addCol(!1)
}).on("click", '[data-key="delete_table_col"]', function() {
d(), y(), File.editor.tableEdit.deleteCol()
}).on("click", '[data-key="delete_table"]', function() {
d(), y(), File.editor.tableEdit.deleteTable()
}).on("click", '[data-key="copy_table"]', function() {
d(), y(), File.editor.tableEdit.copyTable()
}).on("click", '[data-key="reformat_table"]', function() {
d(), y(), File.editor.tableEdit.reformatTable()
})
},
D = function() {
$("#context-menu").on("click", "[data-key='learn']", function() {
d(), y(), b().add(i)
}).on("click", "[data-key='unlearn']", function() {
d(), y(), b().remove(i)
}).on("click", "[data-key='correct']", function(t) {
d(), y(), c.pasteHandler(File.editor, $(t.target).text(), !0)
})
},
L = function() {
$("[data-key='jumpto']").click(function() {
d(), y(), File.editor.tryOpenLink(File.editor.getJQueryElem(window.getSelection().anchorNode).closest("a"))
}), $(".context-menu").mousedown(function(t) {
if (!$(t.target).closest("a").length) return !1
}), $("[data-key='dev-tool']").click(m), File.isNode && (JSBridge.getSetting("debug", !1) ? $("[data-group='dev-tool']").show() : $("[data-group='dev-tool']").hide()), $("[data-key='edit']").click(function(t) {
return d(), y(), File.editor.undo.prepCursorSnap(), $(C).closest(".md-rawblock-container").trigger("startedit"), File.editor.undo.endSnap(), !1
}), $("[data-key='cut']").click(function(t) {
d(), y(), ClientCommand.cut();
var e;
(e = $(document.activeElement.tagName).closest(".CodeMirror")[0]) && setTimeout(function() {
e.CodeMirror.replaceSelection("", "start")
}, 30)
}), $("[data-key='copy']").click(function(t) {
d(), E.find(".md-rawblock-container").focus().length || y(), ClientCommand.copy()
}), $("[data-key='delete-block']").click(function(t) {
d(), y(), E.length && (File.editor.refocus(E.attr("cid")), File.editor.UserOp.deleteBlock(File.editor))
}), $("[data-key='copy_as_markdown']").click(function(t) {
d(), y(), ClientCommand.copyAsMarkdown()
}), $("[data-key='paste_as_plain']").click(function(t) {
d(), y(), ClientCommand.pasteAsPlain()
}), $("[data-key='paste']").click(function() {
d(), y(), ClientCommand.paste()
}), $("[data-key='copy-emoji']").click(function() {
d(), y();
var t = $(".md-emoji.md-expand [data-emoji]").attr("data-emoji");
File.editor.UserOp.setClipboard("", "", t, !0)
}), $("[data-key='play']").click(function(t) {
d();
try {
$(C).closest("video")[0].play()
} catch (t) {}
}), $("[data-key='pause']").click(function(t) {
d();
try {
$(C).closest("video")[0].pause()
} catch (t) {}
})
},
R = function(t, e) {
t.addClass("show");
var n = t.height() + 48,
i = e.clientX > window.innerWidth - 220 ? window.innerWidth - 220 : e.clientX,
r = e.clientY > window.innerHeight - n ? window.innerHeight - n : e.clientY - $("#top-titlebar").height() + 8;
t.css({
top: r + "px",
left: i + "px"
})
};
w.prototype.show = function(t, e) {
if (!v && window.reqnode && p.call(this), C = e || t.target, (E = $(C).closest("[cid]")).hasClass("md-rawblock") ? File.editor.stylize.putBookmark(null, File.editor.stylize.buildBookmark(E)) : ($(File.editor.sessionStr).trigger("cursorChange"), File.editor.lastCursor = File.editor.selection.buildUndo(), File.editor.stylize.putBookmark(null, File.editor.stylize.buildBookmark(E))), $(".context-menu").removeClass("show").find(".active").removeClass("active"), File.editor.sourceView.inSourceMode) return R($("#context-menu-for-source"), t), !1;
! function() {
try {
var t = File.editor.getJQueryElem(window.getSelection().anchorNode).closest("a");
g("hyperlink", t.attr("href") || t.attr("data-ref"))
} catch (t) {
g("hyperlink", !1)
}
}(),
function() {
i = "";
try {
g("search", (i = window.getSelection().toString()).trim().length > 0 && -1 == i.indexOf("\n"))
} catch (t) {
g("search")
}
}(),
function() {
var t = File.editor,
e = t.styleBookmark.style,
n = e.block[0],
i = document.querySelector("#context-menu"),
r = !1,
o = !1,
c = !1,
f = !1,
h = !1;
g("inline-style", !(t.stylize.CONST.NoInline.indexOf(e.block[0]) > -1)), $("[data-style]").removeClass("active"), e.inline.map(function(t) {
var e = document.querySelector("[data-style='" + t + "']");
e && e.classList.add("active"), a.isType(t, s.inline_math) && (c = !0), (a.isType(t, s.image) || a.isType(t, s.imgtag)) && (f = !0), a.isType(t, s.emoji) && (h = !0)
}), e.block.map(function(t) {
a.isType(t, s.blockquote, s.list_item) && (r = !0), a.isType(t, s.table) && (o = !0), a.isType(t, s.math_block) && (c = !0)
});
var d = $.localize.getString(u.CONST.StyleToNameMap[n], "Menu");
if (a.isType(n, s.html_block, s.math_block) ? $("[data-key='block-style']").hide() : ($("[data-key='block-style']").show(), $("[data-key='block-style'] span").text(d)), n == s.paragraph) {
var m = t.getNode(E.attr("cid"));
!m || m.get("before") || m.get("after") || m.get("parent") && (m = m.get("parent")), m && (d = $.localize.getString(u.CONST.StyleToNameMap[m.get("type")], "Menu"))
}
if (!d || a.isType(n, s.paragraph, s.heading) || /header/.exec(n) ? $("[data-group='delete-block']").hide() : $("[data-key='delete-block']").children("a").text($.localize.getString("Delete %@", "Menu").replace("%@", d || "")), $("#block-style-menu [data-block]").removeClass("state-on").filter("[data-block='" + n + "']").addClass("state-on"), e.block.length > 0 && File.editor.stylize.CONST.NormalBlockMap[n] ? ($("[data-block-auto-disable]").removeClass("disabled"), $("[data-block-auto-hide]").removeClass("hide")) : ($("[data-block-auto-disable]").addClass("disabled"), $("[data-block-auto-hide]").addClass("hide")), n != s.def_footnote && n != s.def_link || ($("#insert-menu [data-block-auto-disable]").addClass("disabled"), $("#insert-menu [data-block-auto-hide]").addClass("hide")), n == s.meta_block ? $('[data-insert-p="before"]').parent().addClass("disabled") : $('[data-insert="meta_block"]').removeClass("hide"), a.isType(n, s.html_block, s.math_block, s.meta_block) ? $("[data-group='block-wrap']").hide() : $("[data-group='block-wrap']").show(), r ? i.querySelector('[data-group="block-tab"]').classList.remove("hide") : i.querySelector('[data-group="block-tab"]').classList.add("hide"), o ? ($('[data-group="table"]').show(), i.querySelector('[data-key="block-style"]').classList.add("hide")) : ($('[data-group="table"]').hide(), i.querySelector('[data-key="block-style"]').classList.remove("hide")), c ? i.querySelector('[data-key="math"]').classList.remove("hide") : i.querySelector('[data-key="math"]').classList.add("hide"), h) {
var v = $(".md-emoji.md-expand [data-emoji]").attr("data-emoji");
v && (i.querySelector('[data-key="copy-emoji"] a').textContent = $.localize.getString("Copy '%@'", "Menu").replace("%@", v)), $("#context-menu [data-group='emoji']").addClass(v ? "show" : "hide")
} else $("#context-menu [data-group='emoji']").addClass("hide");
if ($("#context-menu [data-group='image']").addClass("hide"), f) {
var p = $(".md-image.md-expand").find("img").attr("src") || "";
if (!p) return;
/^file:\/\//.exec(p) && i.querySelector('[data-key="reveal-img-in-finder"]').classList.remove("hide");
var b = File.editor.imgEdit.getTagetImageStorageFolder();
if (b) {
var y = l.escapeURL(b);
if (-1 == p.replace(/^file:\/\//, "").indexOf(y)) {
var w = l.getFolder(b);
w && ($(i).find('[data-key="move-img-to-target"] a').text($.localize.getString("Copy to %@", "Menu").replace("%@", w)), i.querySelector('[data-key="move-img-to-target"]').classList.remove("hide"))
}
}
i.querySelector('[data-key="select-img-target"]').classList.remove("hide"), $('.divider[data-group="image"]').removeClass("hide")
}
var F = $(C).closest(".md-rawblock-container");
F.length ? ($("[data-group='copy-paste']").hide(), $("[data-key='copy'], [data-group='edit-block']").show(), F.hasClass("md-htmlblock-container") && $("[data-key='copy']").hide()) : ($("[data-group='copy-paste']").show(), $("[data-group='edit-block']").hide()), $(C).closest("video").length ? $("[data-group='video']").show() : $(C).closest("video").length && $("[data-group='video']").hide()
}(), window.reqnode && function() {
var t = b(),
e = $("#context-menu");
if (i = ";" == i.trim() ? "" : i.trim(), t && i.length)
if (t.isMisspelled(i)) {
g("spell-check", !0), e.find("[data-key='correct']").remove(), e.find("[data-key='unlearn']").hide();
var n = t.getCorrectionsForMisspelling(i.trim());
0 == n.length ? e.find("#divider-before-learn").hide() : (n = n.slice(0, 6), e.find("#divider-before-learn").show().before(n.reduce(function(t, e) {
return t += '<li data-group="spell-check" data-key="correct"><a role="menuitem">' + e + "</a></li>"
}, "")))
} else t.isLearned(i) ? (e.find("[data-key='correct']").remove(), g("spell-check", !0), e.find("[data-key='learn'], #divider-before-learn").hide(), e.find("[data-key='unlearn']").show()) : g("spell-check", !1);
else g("spell-check", !1)
}(), R($("#context-menu"), t), t.preventDefault(), t.stopPropagation()
}, w.prototype.hide = d;
var B = function(t, e) {
var n = $(t).addClass("show"),
i = n.height() + 48,
r = e.offset(),
o = r.left,
a = o + 200,
s = r.top - 30,
u = a + 160 > window.innerWidth ? o - 184 : a,
c = s + i > window.innerHeight ? window.innerHeight - i : s;
return n.css({
top: c + "px",
left: u + "px"
}), !1
};
w.prototype.showExtMenu = B;
var I = function(t, e) {
var n, i, r = $(t);
if ("Enter" == e) {
if (!r.hasClass("has-extra-menu")) {
var o = r.find("a");
return o.length ? o.trigger("click") : r.trigger("click"), !0
}
e = "OpenSubmenu"
}
if ("Up" == e || "Down" == e) return r = r.closest("li"), 0 == (n = "Up" == e ? r.prev() : r.next()).length ? (r.closest("#user-context-menu").length && d(), !0) : !n.height() || n.hasClass("divider") ? I(n[0], e) : (r = r.closest(".context-menu").find(".active"), n.hasClass("has-btn-submenu") ? (i = r.prevAll("a").length / (r.closest(".has-btn-submenu").find("a").length || 1) * n.find("a").length, (n = $(n.find("[data-key]")[Math.floor(i)])).trigger("mouseenter"), !0) : (r.removeClass("active"), n.addClass("active"), !0));
if (("Left" == e || "Right" == e) && "A" == r[0].tagName) return n = "Left" == e ? r.prev() : r.next(), r.removeClass("active"), n.addClass("active"), !0;
if ("Left" == e || "Esc" == e) {
if ((r = r.closest(".context-menu")).hasClass("ext-context-menu")) return r.find(".active").removeClass("active"), r.removeClass("show"), !0;
if ("Left" == e) return !0
}
return "Right" == e || "OpenSubmenu" == e ? (r.hasClass("has-extra-menu") && (r.trigger("mouseenter"), $(".ext-context-menu:visible [data-key]:visible").first().trigger("mouseenter")), !0) : void 0
};
w.prototype.handleKeyEvent = function(t) {
var e = f[t.keyCode || t.which];
if (a.isType(e, "Esc", "Right", "Left", "Up", "Down", "Return", "Enter")) {
var n, i = $(".context-menu:visible");
return !!i.length && ("Esc" == e ? ($(".context-menu").removeClass("show").find(".active").removeClass("active"), !0) : i.find(".active").length ? (n = $(".ext-context-menu .active")[0]) ? I(n, e) : I($(".context-menu .active")[0], e) : "Up" == e ? (i.find("li[data-key]:visible").last().addClass("active"), !0) : "Down" == e ? (i.find("li[data-key]:visible").first().addClass("active"), !0) : void 0)
}
};
var N, O, j;
w.prototype.getCustomFocuedElem = function() {
return N.length ? N : null
}, w.prototype.hideCustomMenu = function(t) {
t == O && $("#user-context-menu.show").length && this.hide()
}, w.prototype.showCustom = function(t, e) {
if (N = null, window.getSelection().rangeCount) {
O = e, j = t;
var n = $("#user-context-menu").html(t.map(function(t) {
return t.key == w.SPLITER ? '<li for-file class="divider"></li>' : '<li data-key="' + t.key + '"><a role="menuitem">' + $.localize.getString(t.label, "Menu").replace("%@", t.variable || "") + "</a></li>"
}).join(""));
setTimeout(function() {
var t = window.getSelection().getRangeAt(0),
e = t.getClientRects(),
i = e.length && e[e.length - 1];
if ((!i || 0 == i.left && 0 == i.height) && (t.selectNodeContents(t.commonAncestorContainer), i = (e = t.getClientRects()).length && e[e.length - 1]), i && (0 != i.left || 0 != i.height)) {
var r = $(t.commonAncestorContainer).closest("[cid]")[0],
o = r ? r.getBoundingClientRect().left || 0 : 0;
n.addClass("show").css({
top: i.bottom + "px",
left: Math.max(o, i.right - n.width() + 20) + "px"
}), N = $(t.commonAncestorContainer).closest("[md-inline]")
}
}, 100)
}
}, w.prototype.getContextTarget = function() {
return C
}, w.prototype.getMenuItemsForMac = function(t) {
C = t;
if (!t) return [];
if (void(t.ownerDocument.defaultView != window && (t = function t(e) {
return e.parent == window ? e.frameElement : e && e.parent ? t(e.parent) : null
}(t.ownerDocument.defaultView))) || document.querySelector("#write").contains(t)) return function() {
try {
var e = editor.getMarkElem(t);
if (a.isType(document.activeElement.tagName, "INPUT", "TEXTAREA") && !e.length) return ["input"];
e.length && File.editor.refocus(e.attr("cid"));
var n = editor.selection.getRangy(),
i = $(t).closest(".md-expand"),
r = e.attr("mdtype");
if (/^table/g.exec(r) && !File.isLocked) return ["normal", "table", "|", "insertParagraphBefore", "insertParagraphAfter"];
if (a.isType(r, s.html_block)) return ["normal", "edit", "|", "insertParagraphBefore", "insertParagraphAfter", "delete"];
if (a.isType(r, s.math_block)) return ["normal", "edit", "copyMathBlock", "|", "insertParagraphBefore", "insertParagraphAfter", "delete"];
if (a.isType(r, s.fences)) return ["normal", "insertParagraphBefore", "insertParagraphAfter", "delete-fences"];
if (e.attr("tabindex")) return ["normal", "|", "insertParagraphBefore", "insertParagraphAfter", "delete"];
if (e.hasClass("md-def-link")) {
var o = $(n.commonAncestorContainer).closest(".md-def-url");
return o.length ? (File.editor.setCurLinkElem(o), ["normal", "openLink"]) : ["normal"]
}
if ($(t).closest(".md-emoji").length) return ["normal", "copyEmoji-" + $(t).closest(".md-emoji").find("[data-emoji]").attr("data-emoji"), "|"];
if (n && $(n.commonAncestorContainer).closest(".md-inline-math").length) return ["normal", "copyMathInline"];
if (a.isType(i.hasClass("md-img-loaded") && i.attr("md-inline"), s.image, s.imgtag)) return ["normal"].concat(File.editor.imgEdit.contextMenuItems(i.find("img")[0]));
if (a.isType(i.hasClass("md-img-loaded") && i.attr("md-inline"), s.refimg) && /^file:\/\//.exec(i.find("img").attr("src") || "")) return ["normal", "revealInFinder", "|"]
} catch (t) {}
return ["normal"]
}();
if (File.editor.sourceView.inSourceMode && document.querySelector("#typora-source").contains(t)) return ["input"];
if (File.getMountFolder()) {
var e = File.editor.getJQueryElem(t).closest(".file-library-node");
if (File.editor.library.useTreeStyle) {
if (e.length) return e.attr("data-path") == File.getMountFolder() ? ["folder-root"] : ["true" == e.attr("data-is-directory") ? "folder" : "file"];
if (File.getMountFolder()) return ["folder-root"]
} else if (e.length) return ["file-list"];
return []
}
return []
}, w.SPLITER = "divider", n.exports = w
}), $__System.registerDynamic("49", ["35", "e", "31", "26"], !0, function(t, e, n) {
"use strict";
this || self, t("35");
var i = t("e"),
r = t("31"),
o = t("26").map,
a = window.reqnode ? reqnode("electron").remote : null,
s = a ? a.app : null,
u = [{
code: "en-US",
userLang: "en-US",
label: "English (US)",
enLabel: "English (US)"
}, {
code: "en-GB",
userLang: "en-GB",
label: "English (UK)",
enLabel: "English (UK)"
}, {
code: "cs",
userLang: "cs-CZ",
label: "Čeština",
enLabel: "Czech"
}, {
code: "de",
userLang: "de-DE",
label: "Deutsch",
enLabel: "German"
}, {
code: "es",
userLang: "es-ES",
label: "Español",
enLabel: "Spanish"
}, {
code: "el",
userLang: "el-GR",
label: "Ελληνικά",
enLabel: "Greek"
}, {
code: "fr",
userLang: "fr-FR",
label: "Français",
enLabel: "French"
}, {
code: "gl",
userLang: "gl-ES",
label: "Galego",
enLabel: "Galician"
}, {
code: "hr",
userLang: "hr-HR",
label: "Hrvatski",
enLabel: "Croatian"
}, {
code: "it",
userLang: "it-IT",
label: "Italiana",
enLabel: "Italian"
}, {
code: "id",
userLang: "id-ID",
label: "Bahasa Indonesia",
enLabel: "Indonesian"
}, {
code: "nl",
userLang: "nl-NL",
label: "Nederlands",
enLabel: "Dutch"
}, {
code: "hu",
userLang: "hu-HU",
label: "Magyar",
enLabel: "Hungarian"
}, {
code: "pl",
userLang: "pl-PL",
label: "Polski",
enLabel: "Polish"
}, {
code: "pt-BR",
userLang: "pt-BR",
label: "Português (Brasil)",
enLabel: "Portuguese (Brazil)"
}, {
code: "pt",
userLang: "pt-PT",
label: "Português (Portugal)",
enLabel: "Portuguese (Portugal)"
}, {
code: "ru",
userLang: "ru-RU",
label: "Ру́сский",
enLabel: "Russian"
}, {
code: "sv",
userLang: "sv-SE",
label: "Svenska",
enLabel: "Swedish "
}, {
code: "vi",
userLang: "vi-VN",
label: "Tiếng Việt",
enLabel: "Vietnamese"
}, {
code: "ko",
userLang: "jo-KR",
label: "한국어",
enLabel: "Korean"
}, {
code: "zh",
userLang: "zh",
label: "中文",
enLabel: "Chinese"
}, {
code: "ja",
userLang: "ja-JP",
label: "日本語",
enLabel: "Janapese"
}],
c = "disabled",
l = function(t) {
this.editor = t, this.r = new Map, this.u = File.option.presetSpellCheck, this.c, this.l(), this.f(), this.reset()
};
l.prototype.useHunSpell = function() {
return !/Windows NT (8|10)\./.exec(navigator.userAgent)
}, l.prototype.h = function() {
var t = new Map;
this.labelMap = {}, u.forEach(function(e) {
t.set(e.userLang, e.code), this.labelMap[e.code] = e.label
}, this);
var e = File.option.userLocale,
n = t.get(e);
n || (n = /^zh/.exec(e) ? "zh" : t.get(s.getLocale() || "en-US") || "en-US"), this.g = n
}, l.prototype.w = function() {
if (this.spellCheckFactory) {
File.filePath ? this.r.has(File.filePath) ? this.u = this.r.get(File.filePath) || File.option.presetSpellCheck : (this.u = r.getItemInDB("[spellcheck]" + File.filePath), this.r.set(File.filePath, this.u), this.u = this.u || File.option.presetSpellCheck) : this.u = File.option.presetSpellCheck;
var t = this;
"auto" != this.u && this.u != c && File.isNode && setTimeout(function() {
t.curSpellchecker = t.spellCheckFactory.getSpellChecker(/^(zh|ja)/.exec(t.u || "") ? "en-US" : t.u)
}, 1e3)
}
}, l.prototype.f = function() {
File.isNodeHtml && (this.$label = document.querySelector("#footer-spell-check"), this.F(), File.isNode && (this.k = null, this.h(), this.C()))
}, l.prototype.F = function() {
var t = this;
i("#footer-spell-check").on("click", function() {
document.body.classList.contains("ty-show-spell-check") ? t.hide() : t.show()
}), i("#spell-check-panel").on("click", "[data-spell-lang]", function() {
t.setLangMode(this.dataset.spellLang, !0), t.hide(), document.querySelector("#footer-spell-check").classList.contains("ty-spell-check-dict-error") && t.showDictMissing()
}).on("click", "#ty-spell-check-global-setting", function() {
File.megaMenu.highlight("spellcheck-option-wrapper")
}), i("#md-notification").on("click", ".dropdown-toggle", function() {
i("#md-notification .dropdown-menu:visible").length ? i("#md-notification .dropdown-menu").parent().removeClass("open") : i("#md-notification .dropdown-menu").dropdown("toggle")
}).on("blur", ".dropdown-toggle", function() {
i("#md-notification .dropdown-menu").parent().removeClass("open")
}).on("shown.bs.dropdown", function(t) {
var e = i(this),
n = e.find(".dropdown-toggle-split"),
r = e.find(".dropdown-menu"),
o = n.offset();
o.top += n[0].clientHeight + 4, o.left += n[0].clientWidth - r[0].clientWidth + 2, r.offset(o)
}).on("click", "#ty-spell-check-dict-missing-disable-btn", function() {
t.setLangMode(c, !0), i("#md-notification").fadeOut()
}).on("click", "#ty-spell-check-dict-missing-close-btn", function() {
i("#md-notification").fadeOut()
}).on("click", "#ty-spell-check-dict-missing-primary-btn", function() {
t.useHunSpell() ? t.A() : a.shell.openExternal("http://support.typora.io/Spellcheck/")
}).on("mousedown", "#ty-spell-check-dict-missing-secondary-btn", function() {
t.useHunSpell() ? a.shell.openExternal("http://support.typora.io/Spellcheck/") : t.A()
}), i("#dict-install-dialog").on("click", ".btn-primary", function() {
t.S()
})
}, l.prototype.T = function(t, e) {
if (this.M(), this.userDictPath)
if (null == this.curSpellchecker && this.downloadDicts[t] <= 1) i("#footer-spell-check").attr("ty-hint", i.localize.getString("Spell Check (%@ downloading)").replace("%@", this.labelMap[t])).removeClass("ty-spell-check-dict-error").addClass("ty-spell-check-dict-downloading");
else if (i("#footer-spell-check").removeClass("ty-spell-check-dict-downloading"), null == this.curSpellchecker && e) i("#footer-spell-check").attr("ty-hint", i.localize.getString("Spell Check (%@ unavailable)").replace("%@", this.labelMap[t])).addClass("ty-spell-check-dict-error");
else {
var n;
n = this.labelMap[t] ? (i.localize.getString("Spell Check") + " (%@)").replace("%@", this.labelMap[t]) : this.u == c ? i.localize.getString("Spell Check (Disabled)") : i.localize.getString("Spell Check"), i("#footer-spell-check").attr("ty-hint", n).removeClass("ty-spell-check-dict-error"), i("#md-notification").fadeOut()
}
}, l.prototype.setLangMode = function(t, e) {
this.spellCheckFactory || (t = c, e = !1), this.u = t, File.filePath && e && (r.setItemInDB("[spellcheck]" + File.filePath, t), this.r.set(File.filePath, this.u));
var n, o = this.curSpellchecker,
a = !1;
this.u == c ? this.curSpellchecker = null : "auto" == this.u ? this.D ? (n = this.D, this.curSpellchecker = this.getSpellChecker(this.D), a = !0) : (this.curSpellchecker = null, this.scheduleAutoUpdateLang()) : (n = this.u, this.curSpellchecker = this.getSpellChecker(this.u), a = !0), this.T(n, a), o && o != this.curSpellchecker && (o || {}).lang != (this.curSpellchecker || {}).lang && i("[contenteditable='true']").prop("contenteditable", !1).prop("contenteditable", !0), this.updatePanel()
}, l.prototype.L = function() {
if (!this.R) {
this.$panel = i("#spell-check-panel"), this.B(u);
var t = this;
this.R = !0;
var e = null;
i("#ty-spell-check-panel-item-label").on("keydown", function(e) {
e.stopPropagation();
var n = e.keyCode || e.which;
if ("Esc" == o[n]) t.hide();
else {
if ("Tab" == o[n]) return !1;
if ("Up" == o[n] || "Down" == o[n]) return t.I("Up" == o[n]), !1;
"Enter" == o[n] ? i("[data-spell-lang].ty-active").trigger("click") : "Backspace" != o[n] && "Delete" != o[n] || i(this).trigger("input")
}
}).on("input cut copy", function(n) {
e && clearTimeout(e), e = setTimeout(function() {
t.N(), e = null
}, 50)
}), this.updatePanel()
}
}, l.prototype.B = function(t) {
var e = this.$panel[0].querySelector(".ty-lang-list"),
n = this.$panel[0].querySelector("#ty-spell-check-panel-item-temp").innerText.trim(),
i = this.u,
r = t.map(function(t) {
return n.replace("%label", t.label).replace(/%code/g, t.code).replace(/%select/, i == t.code ? "ty-checked" : "")
}).join("");
e.innerHTML = r
}, l.prototype.N = function() {
var t = i("#ty-spell-check-panel-item-label").val().trim().toLocaleLowerCase();
if (!t) return this.B(u), void this.O();
if (!this.$panel[0].style.height) {
var e = this.$panel[0];
e.style.height = e.clientHeight + "px"
}
var n = {},
r = u.filter(function(e) {
var i = [e.code, e.userLang, e.label, e.enLabel].map(function(e) {
var n = e.toLocaleLowerCase().indexOf(t);
return ~n ? n : 99
}).sort()[0];
return 99 != i && (n[e.code] = i, !0)
});
r = r.sort(function(t, e) {
return n[t.code] - n[e.code]
}), this.B(r), this.O()
}, l.prototype.O = function() {
var t = this.$panel.find(".ty-active");
return t.length || (t = this.$panel.find(".ty-lang-list>.ty-spell-check-panel-item").first().addClass("ty-active")), t
}, l.prototype.I = function(t) {
var e = this.O(),
n = t ? e.prev() : e.next();
e.removeClass("ty-active"), n.addClass("ty-active")
}, l.prototype.j = function() {
return this.u == c ? null : "auto" == this.u ? this.D || "" : this.u
}, l.prototype.updatePanel = function() {
var t = this.j();
i("#footer-spell-check-label").html((t || "").toUpperCase() || '<span class="ty-icon ty-spellcheck" style="font-size: 1.1em;vertical-align: middle;"></span>'), this.R && (this.$panel.find(".ty-checked").removeClass("ty-checked"), this.$panel.find("[data-spell-lang='" + this.u + "']").addClass("ty-checked"), this.$panel.find("[data-spell-lang='auto'] .ty-spell-check-panel-item-code").text(this.D || ""))
}, l.prototype.show = function() {
this.loadSpellCheckErr && this.P(), this.editor.lastCursor = this.editor.selection.buildUndo(), this.L(), document.body.classList.add("ty-show-spell-check"), document.body.classList.remove("ty-show-word-count"), this.autoUpdateLang(!0), document.querySelector("#footer-spell-check").classList.contains("ty-spell-check-dict-error") && this.showDictMissing(), setTimeout(function() {
document.querySelector("#ty-spell-check-panel-item-label").focus()
}, 10);
this.$panel[0].style.height = ""
}, l.prototype.hide = function() {
document.body.classList.remove("ty-show-spell-check"), this.editor.restoreLastCursor(), i("#ty-spell-check-panel-item-label").val(""), this.$panel.find(".ty-active").removeClass("ty-active"), this.$panel[0].style.height = "", this.B(u)
}, l.prototype.A = function() {
var t = i("#dict-install-dialog"),
e = this.c;
t.find("#dict-install-dialog-title").text(i.localize.getString("Download dictionary file for %@").replace("%@", e.label));
var n = "https://dict.typora.io/" + e.code + "/LICENSE";
t.modal({
backdrop: "static"
}).focus(), setTimeout(function() {
t.find("webview").attr("src", n)
}, 100)
}, l.prototype.q = function(t) {
this.j() == t && (this.downloadDicts[t] = void 0, this.spellCheckFactory.clearCache(), i("#footer-spell-check").addClass("ty-spell-check-dict-downloaded"), this.setLangMode(t), setTimeout(function() {
i("#footer-spell-check").removeClass("ty-spell-check-dict-downloaded")
}, 1e3))
}, l.prototype.U = function(t, e, n) {
var r = this.z,
o = e || 0;
e < 0 ? (r[t] = void 0, this.downloadDicts[t] = void 0) : (r[t] || (r[t] = [0, 0]), void 0 !== e && (r[t][0] = e), void 0 !== n && (r[t][1] = n), o = (r[t][0] + r[t][1]) / 2, this.downloadDicts[t] = o), this.j() == t && (e < 0 ? (i("#footer-spell-check").attr("ty-hint", i.localize.getString("Spell Check (%@ unavailable)").replace("%@", this.labelMap[t])).addClass("ty-spell-check-dict-error").removeClass("ty-spell-check-dict-downloading"), document.querySelector("#footer-spell-check-download-process").innerText = "") : (i("#footer-spell-check").attr("ty-hint", i.localize.getString("Spell Check (%@ downloading)").replace("%@", this.labelMap[t])).removeClass("ty-spell-check-dict-error").addClass("ty-spell-check-dict-downloading"), document.querySelector("#footer-spell-check-download-process").innerText = "#footer-spell-check.ty-spell-check-dict-downloading:before {width: " + 100 * o + "%;}"))
}, l.prototype.S = function() {
var t = this.c.code;
s.setting.downloadDict(t, a.getCurrentWindow().id), this.U(t, 0, 0), i("#md-notification").fadeOut()
}, l.prototype.C = function() {
var t = this;
try {
var e = reqnode("electron").ipcRenderer;
e.on("dict-loaded", function(e, n) {
t.u, t.userDictPath = n, t.spellCheckFactory.setUserDictionaryPath(t.userDictPath), t.u && t.setLangMode(t.u)
}), this.downloadDicts = {}, this.z = {}, e.on("dict-download-start", function(e, n) {
t.U(n, 0, 0)
}), e.on("dict-download-process", function(e, n) {
t.U(n.locale, "dic" == n.type ? n.process : void 0, "dic" == n.type ? void 0 : n.process)
}), e.on("dict-download-end", function(e, n) {
t.U(n, 1, 1), t.q(n)
}), e.on("dict-download-err", function(e, n) {
t.U(n, -1)
});
s.setting.getDownloadingDicts().forEach(function(e) {
t.U(e, 0, 0)
}), this.spellCheckFactory = reqnode("spellchecker"), this.curSpellchecker = null, this.userDictPath = s.setting.getUserDictionaryPath(), this.userDictPath, this.userDictPath && this.spellCheckFactory.setUserDictionaryPath(this.userDictPath);
var n = new(reqnode("events").EventEmitter);
n.add = function(t, n) {
e.send("user-dict-add", {
lang: t,
word: n
})
}, n.remove = function(t, n) {
e.send("user-dict-remove", {
lang: t,
word: n
})
}, n.loadUserDict = function() {
return s.setting.userDict || {}
}, e.on("user-dict-update", function(t, e) {
n.emit("update", e)
}), this.spellCheckFactory.setUserDictProvider(n), this.M()
} catch (t) {
this.loadSpellCheckErr = t.stack || t.message, console.error(t)
}
this.spellCheckFactory || i("#footer-spell-check").off("click").on("click", function() {
t.P()
})
}, l.prototype.P = function() {
this.editor.EditHelper.showDialog({
title: i.localize.getString("Failed to load spellcheck module"),
message: this.loadSpellCheckErr.split(/\n/).map(function(t) {
return t.replace(/\((.+)(TypeMark|app)/, "(")
}).join("\n"),
type: "error",
backdrop: "static"
})
}, l.prototype.M = function(t) {
var e = this;
if (this.u != c) {
var n = this.j() || this.g || "en-US";
/^(zh|ja)/.exec(n) && (n = "en-US"), reqnode("electron").webFrame.setSpellCheckProvider(n, !1, {
spellCheck: function(t) {
return e.curSpellchecker ? !e.curSpellchecker.isMisspelled(t) : (e.scheduleAutoUpdateLang(), !0)
}
})
} else this.curSpellchecker = null
}, l.prototype.H = function() {
var t = this.editor;
var e = this.j() || this.g;
return this.spellCheckFactory ? this.spellCheckFactory.detectLanguageForText(function() {
for (var e = t.writingArea.querySelectorAll("p, h1, h2, h3, h4, h5, h6"), n = Math.min(e.length, 4), i = "", r = 0; r < n && ((e[r].querySelectorAll("[md-inline='plain']") || []).forEach(function(t) {
i += t.textContent
}), !((i += "\n").length > 100)); r++);
return i
}(), {
httpHint: e
}) : Promise.resolve("")
}, l.prototype.getSpellChecker = function(t) {
return this.spellCheckFactory.getSpellChecker(/^(zh|ja)/.exec(t || "") ? "en-US" : t)
}, l.prototype.autoUpdateLang = function(t) {
if (!0 === t || !this.D && this.u != c) {
var e = this;
this.H().then(function(n, i) {
if (i) Reporter.error(i);
else if (n && (/^en/.exec(n) ? n = /^en/.exec(e.g) ? e.g : "en-US" : /^zh/.exec(n) ? n = "zh" : e.labelMap[n] || (n = null)), n) {
if (e.D = n, e.updatePanel(), "auto" != e.u) return;
e.curSpellchecker = e.getSpellChecker(n), e.T(n, !0)
} else t && e.D && (e.D = null, e.updatePanel())
}), this.k = null
}
}, l.prototype.scheduleAutoUpdateLang = function(t) {
if ("auto" == this.u || t) {
this.k && clearTimeout(this.k);
var e = this;
this.k = setTimeout(function() {
e.autoUpdateLang(t)
}, 2e3)
}
}, l.prototype.W = function() {
this.w(), this.autoUpdateLang()
}, l.prototype.l = function() {
this.D = "", this.curSpellchecker = null, this.k && clearTimeout(this.k)
}, l.prototype.reset = function(t) {
File.isNode && (this.l(), this.w(), this.setLangMode(this.u), t && this.scheduleAutoUpdateLang(!0))
}, l.prototype.showDictMissing = function() {
var t = u.find(function(t) {
return t.code == ("auto" == this.u ? this.D : this.u)
}, this);
if (t) {
this.c = t;
var e = document.querySelector("#ty-spell-check-dict-missing-temp").innerText;
i("#md-notification").html(e.replace("$1", i.localize.getString("Dictionary file is missing to enable spellcheck support for %@.")).replace("%@", t.label).replace("$2", i.localize.getString("Install Language Support")).replace("$3", i.localize.getString("Disable Spell Check")).replace("$4", i.localize.getString("Dismiss"))).show(), this.useHunSpell() ? i("#ty-spell-check-dict-missing-secondary-btn").text(i.localize.getString("Learn More…")) : i("#ty-spell-check-dict-missing-secondary-btn").text(i.localize.getString("Install dictionary file only for Typora"))
}
}, n.exports = l
}), $__System.registerDynamic("4a", ["14", "12", "13", "31", "37", "26", "e", "2c"], !0, function(t, e, n) {
"use strict";
this || self;
var i, r = t("14"),
o = t("12"),
a = t("13"),
s = (a.Node, a.TYPE, t("31")),
u = t("37"),
c = (r = t("14"), t("26").map, t("e")),
l = t("2c"),
f = window.reqnode ? reqnode("electron").remote : null,
h = f ? f.app : window.app,
d = !1,
m = (f && f.getCurrentWindow(), "_recent"),
v = [];
function p(t, e) {
t.length && e.length && l(t[0], e[0], {
childrenOnly: !0,
getNodeKey: function(t) {
return t.dataset && t.dataset.path
},
onBeforeElUpdated: function(t, e) {
t.classList.contains("file-node-collapsed") && (e.classList.add("file-node-collapsed"), e.classList.remove("file-node-expanded"))
}
})
}
var g = s.statWrapper;
function b(t, e) {
return File.isMac ? new Promise(function(e) {
y(t, e)
}) : w(t, !1, e)
}
function y(t, e) {
if (!t.path) return e(null);
bridge.callHandler("library.listDocsUnder", t.path, function(n) {
if (!n || !n.name) return e(null);
t.fetched = !0, t.subdir = n.subdir, t.lastModified = n.lastModified, (i = t.subdir.map(function(e, n) {
return new Promise(function(i) {
e.isOpen ? (e.fetched = !0, i()) : document.querySelector(".file-node-expanded.file-tree-node[data-path='" + r.escapeSelector(e.path) + "']") ? y(e.path, function(e) {
t.subdir[n] = e, t.subdir[n] && (t.subdir[n].isOpen = !0), i()
}) : i()
})
}), i && i.length ? Promise.all(i) : Promise.resolve()).then(function() {
t.content = n.content, t.isDirectory = n.isDirectory, t.isFile = n.isFile, t.name = n.name, e && e(t)
});
var i
})
}
function w(t, e, n) {
var i = reqnode("fs-plus"),
o = reqnode("path"),
a = File.isWin ? "\\" : "/";
return new Promise(function(u, c) {
var l = t.path;
if (t.name = o.basename(l) || l, t.subdir = [], t.content = [], t.fetched = !e, "." == t.name[0]) return u();
g(l, function(o) {
if (!o || o.shouldIgnore) return u();
if (t.isDirectory = o.isDir, t.isFile = o.isFile, t.lastModified = o.mtime, o.isFile) return t.fetched = !0, s.isSupportedFile(t.name) ? u(t) : u();
if (o.isDir) {
if (c = l, File.filePath && c && 0 == File.filePath.indexOf(c.replace(/[\/\\]$/, "") + a)) t.isOpen = !0;
else if (e) return u(t);
t.isDirectory && (t.fetched || t.isOpen) && File.isUnixNode && n.addFolderWatchByUnix(t), i.list(l, void 0, function(e, i) {
if (e) return u();
t.isOpen || document.querySelector(".file-node-expanded.file-tree-node[data-path='" + r.escapeSelector(l) + "']") && (t.isOpen = !0), Promise.all(i.map(function(e) {
return w({
path: e
}, !t.isOpen, n)
})).then(function(e) {
if (t.subdir.length + t.content.length > 0) return t.fetched = !0, void u(t);
e.forEach(function(e) {
e && (e.isDirectory ? t.subdir.push(e) : t.content.push(e))
}), t.fetched = !0, u(t)
})
})
}
var c
})
})
}
var F = o.Model.extend({
initialize: function(t) {
this.parent = t, this.editor = t.editor, this.$template = c(document.querySelector("#file-library-node-template").textContent), this.root, this.unixWatchers = {}
},
getRoot: function() {
return this.parent.root
},
setRoot: function(t) {
return this.parent.root = t
},
renderNode: function(t, e) {
if (!t) return c();
var n = this.$template.clone(),
i = this.parent;
e || (t.subdir && t.subdir.sort(i.compareItem.bind(i)), t.content && t.content.sort(i.compareItem.bind(i))), t == this.getRoot() ? (t.isOpen = !0, n.find(".file-node-open-state").remove()) : t.isDirectory && t.subdir && (t.subdir.length || t.content.length) && n.attr("data-has-sub", "true").addClass(t.isOpen ? "file-node-expanded" : "file-node-collapsed");
var o = t.name.lastIndexOf(".");
if ((o < 0 || t.isDirectory) && (o = t.name.length), n.find(".file-node-title-name-part").text(t.name.substr(0, o)), n.find(".file-node-title-ext-part").text(t.name.substr(o)), n.attr("data-path", t.path).attr("data-is-directory", t.isDirectory), n.find(".file-node-icon").addClass(function(t) {
return t == this.getRoot() ? t.path == m ? "fa fa-history" : "fa fa-folder" : t.isDirectory ? "fa fa-folder" : "fa fa-file-text-o"
}.call(this, t)), n.find(".file-node-title").attr("title", r.abbreviatingWithTilde(t.path)), t.isDirectory || n.addClass("file-library-file-node"), t == this.getRoot() ? n.addClass("file-node-root") : t.isDirectory || t.path != s.getCurrentFilePath() || n.addClass("active"), t.isDirectory && t.subdir) {
var a = n.find(".file-node-children");
a.html(""), t.isOpen && (t.subdir.forEach(function(t) {
a.append(this.renderNode(t))
}, this), t.content.forEach(function(t) {
a.append(this.renderNode(t))
}, this))
}
return n
},
renderIfNeed: function() {
return !d && (this.render(), File.isWin && this.parent.addFolderWatchByWin(File.getMountFolder()), !0)
},
render: function(t) {
d = !0;
var e = this,
n = File.getMountFolder();
(e.getRoot() ? Promise.resolve(e.getRoot()) : new Promise(function(t) {
e.parent.calcMountFolder().then(function(n) {
e.parent.root = {
path: n,
isOpen: !0
}, n ? b(e.parent.root, e).then(function(n) {
e.parent.root = n, t(n), e.parent.slient = !1
}) : t(null)
})
})).then(function(i) {
i && i.path ? (t || 1 == d) && function() {
d = "complete", c("#file-library-tree").html("").append(this.renderNode(this.getRoot())).attr("data-state", ""), this.parent.markCurrentFile()
}.call(e) : (c("#file-library-tree").html(""), e.parent.onLoadFolderFailed(!n))
}), c("#file-library-tree").attr("data-state", "rendering").html("")
},
findElemFromPath: function(t) {
return c(".file-tree-node[data-path='" + r.escapeSelector(t) + "']")
},
focusToFile: function(t, e, n, i) {
if (this.getRoot() && t && !0 !== d) {
var r = File.getMountFolder(),
o = File.isWin ? "\\" : "/",
a = this,
s = window.innerHeight,
u = File.isMac ? c(".sidebar-content") : c("#file-library"),
l = u.scrollTop();
if (0 === t.indexOf(r)) {
! function e(r, c) {
if (0 != c.length)
if (1 == c.length) {
var f = n ? a.findElemFromPath(t) : a.markOpenedFile(t);
! function(t) {
if (t.length) {
var e = t[0].offsetTop;
e < l ? (l = e, u.scrollTop(l)) : e - l > s - 200 && (l = e - s + 300, u.scrollTop(l))
}
}(f), 0 == u.scrollTop() && setTimeout(function() {
0 != u.scrollTop() || l || u.scrollTop(l)
}, 200), i && i(f)
} else r = (r + o + c.shift()).replace(/[\\]+/, "\\"), a.expandNode(a.findElemFromPath(r), r, function() {
e(r, c)
})
}(r, t.substr(r.length).replace(/^[\\/]+/g, "").split(/[\\/]+/) || [])
}
}
},
highlight: function(t) {
var e = this;
this.focusToFile(t, !1, !0, function(t) {
t.addClass("blink-area"), setTimeout(function() {
t.removeClass("blink-area")
}, 2e3), t.length && (e.parent.nextChangeHighlight = null)
})
},
markOpenedFile: function(t) {
return this.parent.markOpenedFile(t).filter(".file-tree-node")
},
needRepaint: function() {
d = !1
},
addFolderWatchByUnix: function(t) {
var e = this,
n = this.unixWatchers[t.path];
n && (n.close(), n = null);
function r() {
var t = v.clone();
i = null, v = [];
var n = [];
e.parent.isSuppressOnChange() || t.forEach(function(t) {
e.onChangeForLinux(t[0], t[1], n)
})
}
var o;
try {
o = reqnode("pathwatcher")
} catch (t) {
this.parent.showUnixWatchError(t.message)
}
if (o) try {
this.unixWatchers[t.path] = o.watch(t.path, function(n) {
o = n, a = t, e.parent.isSuppressOnChange() || (i && clearTimeout(i), v.push([o, a]), i = setTimeout(r, 200));
var o, a
})
} catch (e) {
console.warn("Unable to watch path " + t.path)
}
},
findNodeFromPath: function(t, e) {
if (t && this.getRoot()) return e = e || [],
function t(n, i) {
if (n) {
if (r.isSamePath(n.path, i)) return n;
e.push(n);
for (var o = 0; o < n.subdir.length; o++) {
var a = n.subdir[o];
if (r.isSamePath(a.path, i)) return a;
if (r.isAncesterPathOf(a.path, i)) return t(a, i)
}
return n.content.find(function(t) {
return r.isSamePath(t.path, i)
})
}
return null
}(this.getRoot(), t)
},
expand: function(t, e, n) {
var i;
return 1 != (i = e ? c(e) : this.findElemFromPath(t))[0].dataset.hasSub && "true" != i[0].dataset.hasSub || !i.hasClass("file-node-collapsed") ? (n && n(), !1) : (this.expandNode(i, t, n), !0)
},
expandNode: function(t, e, n) {
if (!0 !== d) {
var i = this.findNodeFromPath(e, []),
r = this;
i && (i.isOpen = !0, t.children(".file-node-children").children().length ? t.removeClass("file-node-collapsed").addClass("file-node-expanded") : !i.fetched || i.subdir.length > 0 && !i.subdir[0].fetched ? b(i, r).then(function(e) {
e && (t.replaceWith(r.renderNode(e)), c(".file-library-node.active").length || r.markOpenedFile(s.getCurrentFilePath()), n && n())
}) : t.replaceWith(this.renderNode(i)), c(".file-library-node.active").length || this.markOpenedFile(s.getCurrentFilePath()), n && n())
}
},
setSortType: function() {
"complete" === d && this.getRoot() && this.getRoot().fetched && this.render(!0)
},
onChangeForMac: function(t) {
if (d) {
var e, n = [],
i = new Set,
o = new Set,
a = this;
if (t.forEach(function(t) {
if (e = this.findNodeFromPath(t.path, n), this.getRoot())
if ("removed" == t.type) t.path == this.getRoot().path ? this.parent.root = null : e && n.length && l.call(this, e, n.last());
else if ("rename" == t.type) {
if (t.oldPath == this.getRoot().path) return void(this.parent.root = null);
n = [], e = this.findNodeFromPath(t.oldPath, n), l.call(this, e, n.last()), f(t.newPath, t.isDir)
} else "created" != t.type || e || e == this.getRoot() || f(t.path, t.isDir)
}, this), this.getRoot()) {
a = this;
o.forEach(function(t) {
y(t, function(t) {
t && s.call(a, t)
}), i.delete(t)
}, this), i.forEach(function(t) {
s.call(this, t)
}, this)
} else this.parent.onRootChanged()
}
function s(t) {
var e = a.findElemFromPath(t.path),
n = null;
e.hasClass("file-node-root") && (n = c(".sidebar-content").scrollTop()), p(e, a.renderNode(t)), n && c(".sidebar-content").scrollTop(n), u(t.path)
}
function u(t) {
var e = a.parent.nextChangeHighlight;
e && 0 == e.indexOf(t) && a.highlight(e)
}
function l(t, e) {
t && (t.isDirectory ? e.subdir.remove(t) : e.content.remove(t), e.subdir.length + e.content.length == 0 ? (t.isOpen = !1, s.call(this, e)) : a.findElemFromPath(t.path).remove())
}
function f(t, e) {
var n = r.pathByDeleteLastComponent(t),
s = a.findNodeFromPath(n);
s && function(t, e, n) {
if (e.fetched && !o.has(e)) {
var r;
if (e.content.length + e.subdir.length == 0 && o.add(e), n) {
if (e.subdir.findIndex(function(e) {
return e.path == t
}) > -1) return;
o.add(e)
} else {
if (e.content.findIndex(function(e) {
return e.path == t
}) > -1) return;
r = {
path: t,
isDirectory: !1,
name: t.split("/").last(),
lastModified: (new Date).getTime() / 1e3
}, e.content.push(r)
}
i.add(e)
}
}.call(a, t, s, e), u(t)
}
},
isPathTooDeepToDisplay: function(t, e) {
if (e = e || [], this.findNodeFromPath(t, e), !e.length) return !0;
return !!t.substr(e.last().path.length).replace(/^[\\/]+/, "").match(/[\\/]/)
},
onChangeForWin: function(t, e) {
if (d && !this.parent.isSuppressOnChange()) {
var n = [],
i = File.isWin ? "\\" : "/",
r = this;
this.isPathTooDeepToDisplay(t, n) || function(t, n, o) {
if (n = n || [], !e.find(function(e) {
return e == t || 0 == t.indexOf(e + i)
})) {
e.push(t);
var a = reqnode("path").dirname(t),
s = r.findNodeFromPath(a);
if (s && s.fetched) {
var u = !s.isOpen;
w({
path: t
}, u, r).then(function(e) {
e ? (function(t, e, n) {
var i = r.findNodeFromPath(t);
i && i.fetched ? i.path != t && (r.findElemFromPath(i.path).replaceWith(r.renderNode(e)), i.path = e.path, i.name = e.name) : r.onAddFile(e, n)
}(t, e, s), o && o()) : function(t, e) {
e = e || [];
var n = r.findNodeFromPath(t, e);
if (n) {
var i = e.last();
i.subdir.remove(n), i.content.remove(n), i.subdir.length + i.content.length == 0 ? r.findElemFromPath(i.path).replaceWith(r.renderNode(i)) : r.findElemFromPath(t).remove()
}
}(t, n)
})
}
}
}(t, n, function() {
if (r.parent.useTreeStyle) {
var e = r.parent.nextChangeHighlight;
e && 0 == e.indexOf(t) && r.highlight(e)
}
})
}
},
onChangeForLinux: function(t, e, n) {
var i = this;
n.find(function(t) {
return t == e.path || 0 == e.path.indexOf(t + "/")
}) || (n.push(e.path), "change" == t && w(e, !1, this).then(function(t) {
if (t) {
p(i.findElemFromPath(t.path), i.renderNode(t)), File.filePath && File.filePath.substring(0, File.filePath.lastIndexOf("/")) == t.path && i.parent.markCurrentFile(!0, !0);
var e = i.parent.nextChangeHighlight;
e && 0 == e.indexOf(t.path) && i.highlight(e)
}
}), "rename" == t && e == i.getRoot() && i.parent.onRootChanged(), "delete" == t && e == i.getRoot() && i.parent.onRootChanged())
},
onAddFile: function(t, e) {
var n = e || this.findNodeFromPath(t.folderPath),
i = n.content.length + n.subdir.length == 0,
r = t.isDirectory ? n.subdir : n.content,
o = r.findIndex(function(e) {
return this.parent.compareItem(t, e) < 0
}, this);
if (o < 0 && (o = r.length), r.splice(o, 0, t), t.isDirectory || (o += n.subdir.length), i) this.findElemFromPath(n.path).replaceWith(this.renderNode(n));
else {
var a = this.findElemFromPath(n.path).children(".file-node-children");
if (n.isOpen || a.children().length) {
var s = this.renderNode(t)[0];
return a[0].insertChildAtIndex(s, o), s
}
}
},
newFile: function(t) {
this.newFileCommand(this.findElemFromPath(t), !1)
},
newFolderCommand: function(t) {
this.newFileCommand(t, !0)
},
newFileCommand: function(t, e) {
var n = this.editor.getJQueryElem(t).closest(".file-library-node"),
i = n.attr("data-path"),
o = "true" == n.attr("data-is-directory"),
a = this;
if (i || (n = c("#file-library-tree .file-node-root"), i = n.attr("data-path"), o = !0), i)
if (o || (i = r.pathByDeleteLastComponent(i)), o) {
a = this;
this.expandNode(n, i, function() {
u.call(a)
})
} else u.call(this);
function s(t, e, n, i) {
if (i) {
if (t.content.push(n), a.parent.isDiscardableUntitled()) return a.parent.openFile(n.path), p(e, a.renderNode(t, !0)), a.focusToFile(n.path), void setTimeout(function() {
a.parent.markCurrentFile(), a.parent.resumeOnChange(), a.renameFileCommand(a.findElemFromPath(n.path)[0], !0)
}, 10)
} else t.subdir.push(n);
p(e, a.renderNode(t, !0)), a.markOpenedFile(n.path), a.renameFileCommand(a.findElemFromPath(n.path)[0], !0)
}
function u() {
var t = this.findNodeFromPath(i);
if (t) {
var n = function(t, e) {
var n = 0;
return e ? (t.subdir.forEach(function(t) {
var e = /^untitled folder( (\d+))?$/i.exec(t.name);
e && (n = Math.max(n, (e[2] || 0) - 0 + 1))
}), "Untitled Folder" + (n ? " " + n : "")) : (t.content.forEach(function(t) {
var e = /^untitled( (\d+))?\./i.exec(t.name);
e && (n = Math.max(n, (e[2] || 0) - 0 + 1))
}), "Untitled" + (n ? " " + n : "") + ".md")
}(t, e),
r = File.isNode && reqnode("fs");
try {
var o = this.findElemFromPath(i),
u = i + (File.isWin ? "\\" : "/") + n,
c = {
fetched: !0,
subdir: [],
content: [],
isDirectory: !!e,
name: n,
path: u
};
if (a.parent.pauseOnChange(!0), e) File.isNode ? r.mkdir(u, function(e) {
e ? a.parent.resumeOnChange() : s(t, o, c, !1)
}) : bridge.callHandler("library.newFolder", u, function(e) {
e ? s(t, o, c, !1) : a.parent.resumeOnChange()
});
else if (File.isNode) {
var l = r.openSync(u, "wx");
r.close(l), s(t, o, c, !0)
} else bridge.callHandler("library.newFile", u, function(e) {
e ? s(t, o, c, !0) : a.parent.resumeOnChange()
})
} catch (t) {
a.parent.resumeOnChange()
}
}
}
},
renameFileCommand: function(t, e) {
c(".file-node-on-edit").removeClass("file-node-on-edit");
var n = this.editor.getJQueryElem(t).closest(".file-library-node").addClass("file-node-on-edit"),
i = n.attr("data-path"),
o = (n.attr("data-is-directory"), n.children(".file-node-content").children(".file-tree-rename-div")),
a = o.prev().text().trim(),
l = o.children("input").val(a),
d = this,
m = c("#sidebar-content").width() - 48 - o[0].offsetLeft;
m = Math.min(m, 200), m = Math.max(m, 140), l.width(m);
this.parent.bindRename(l, function(t) {
File.isMac ? function(t) {
var e = t.val().replace(/[\/\\]/g, "").trim(),
o = r.pathByDeleteLastComponent(i) + "/" + e;
d.parent.pauseOnChange(!0);
var u = i == s.getCurrentFilePath();
i != o ? bridge.callHandler("library.renameFile", {
old: i,
new: o
}, function(i) {
i ? (n.children(".file-node-content").children(".file-node-title").text(e), u && setTimeout(function() {
d.parent.markOpenedFile(o, !0), d.focusToFile(o)
}, 200), d.parent.scheduleChangeHighlight(o)) : t.val(a)
}) : t.val(a), n.removeClass("file-node-on-edit"), d.editor.restoreLastCursor()
}(t) : function(t) {
var o = t.val().trim();
d.parent.resumeOnChange(), o = File.isWin ? o.replace(/[\\\/:*?"<>\|\000-\031]/g, "").trim() : o.replace(/[\/\\\000-\031]/g, "");
var s = r.pathByDeleteLastComponent(i) + (File.isWin ? "\\" : "/") + o;
s = s.trim(), t.closest(".file-node-on-edit").removeClass("file-node-on-edit");
var l = File.filePath && r.isAncesterPathOf(i, File.filePath),
m = f.getCurrentWindow().id,
v = reqnode("fs-extra");
File.filePath;
function p(t) {
f.dialog.showErrorBox(c.localize.getString("Rename Failed"), c.localize.getString('Failed to rename from "{0}" to "{1}"').format(a, o) + "\n" + t), l && u.watchFileChange(File.filePath), h.filesOp.clearUndo()
}
r.isSamePath(i, s) || !v.existsSync(s) ? (h.sendEvent("willRename", {
oldPath: i,
fromWin: m
}), v.rename(i, s, function(t) {
n.removeClass("file-node-on-edit"), d.editor.restoreLastCursor(), t && (s = i), h.sendEvent("didRename", {
oldPath: i,
newPath: s,
fromWin: m
});
var o = reqnode("path");
if (File.isWin && !d.parent.folderWatchedOnWin) {
n.attr("data-path", s), n.find(".file-node-title").attr("title", r.abbreviatingWithTilde(s));
var a = o.basename(s),
u = a.lastIndexOf(".");
u < 0 && (u = a.length), n.find(".file-node-title-name-part").text(a.substr(0, u)), n.find(".file-node-title-ext-part").text(a.substr(u))
}
if (t) p(t);
else if (e || (h.filesOp.registerUndo(s, i, c.localize.getString("Rename %@", "Panel").replace("%@", o.basename(i))), d.parent.scheduleChangeHighlight(s)), !File.filePath) return
})) : p(c.localize.getString("File with same name already exists at target path."))
}(t)
}, function() {
l.closest(".file-node-on-edit").removeClass("file-node-on-edit")
}), l.focus()
},
bindEvents: function() {
var t = this;
c("#file-library-tree").on("click", ".file-node-content", function(e) {
if (1 === e.which) {
e.preventDefault(), e.stopPropagation(), document.activeElement.blur();
var n = c(this).parent(),
i = n.attr("data-path"),
r = n.attr("data-is-directory");
if (n.hasClass("file-node-on-edit")) return !1;
if (File.isMacOrMacNode ? e.metaKey : e.ctrlKey) t.parent.openWithCtrl(i, "true" == r);
else {
if ("false" == r) t.parent.openFile(i);
else if ("true" == n.attr("data-has-sub")) {
n.hasClass("file-node-expanded") ? (o = n, a = i, t.findNodeFromPath(a).isOpen = !1, o.addClass("file-node-collapsed").removeClass("file-node-expanded")) : t.expandNode(n, i)
}
var o, a
}
}
})
}
});
n.exports = F
}), $__System.registerDynamic("37", ["14", "12", "31", "29", "26"], !0, function(t, e, n) {
"use strict";
this || self;
var i, r = t("14"),
o = (t("12"), t("31")),
a = (t("29"), t("26").map, window.reqnode ? reqnode("electron").remote : null),
s = (r.date2NatrualLang, null),
u = null,
c = function(t) {
var e = new Date;
return i = r.formateDateOnly(new Date) + " " + (t || "untitled").replace(/\.[^.]*$/, "") + " " + r.formateTimeOnly(e, !0).replace(/:/g, "") + ".md"
};
function l(t) {
var e;
try {
var n = reqnode("fs");
u && n.unwatchFile(u), u = t, n.watchFile(t, function(i, r) {
r && r.mtime == i.mtime || (e && clearTimeout(e), e = setTimeout(function() {
n.existsSync(t) ? File.presentedItemChanged() : v(), e = null
}, 100))
})
} catch (t) {
console.log(t)
}
}
var f = !1;
function h(t, e) {
var n = reqnode("fs");
!t || n.existsSync(e) ? (File.presentedItemChanged(), t && m(e)) : (m(null), v()), t = !1, d = null
}
var d;
function m(t) {
if (reqnode) {
var e = reqnode("fs");
if (s && (s.removeAllListeners(), s.close(), s._handle = null, s = null), d && clearTimeout(d), d = null, u && e.unwatchFile(u), t) try {
(s = e.watch(t, {
persistent: !1
})).on("change", function(e, n) {
File.inSavingProcess && "rename" == e ? m(t) : (f = f || "change" == e, d && clearTimeout(d), d = setTimeout(function() {
h(h, t)
}, 500))
}), s.on("error", function(e) {
s.close(), s._handle = null, s = null, l(t)
})
} catch (e) {
l(t)
}
}
}
var v = function() {
File.getCurrentDocByNode().switchToUntitled(), Reporter.record("current file is moved/deleted")
};
window.clientHanlderOnPresentationMoved = function() {
File.isNode && (File.updateChangeCount(File.ChangeType.NSChangeReadOtherContents), m(null)), File.editor.imgEdit.onFileMoved()
};
var p = function(t) {
t && window.debugMode && console.warn(t)
},
g = function(t) {
if (i && t) {
var e = reqnode("fs"),
n = reqnode("path"),
r = o.getUnsavedDraftsPath(),
a = n.resolve(r, i);
e.stat(a, function(i, o) {
!i && e.rename(a, n.resolve(r, c(t)), p)
})
}
},
b = function(t, e, n) {
var r = $("#title-text"),
s = a.app,
u = a.getCurrentWindow(),
l = {
"File→Open File Location": {
enabled: !!t
},
"File→Reveal in Sidebar": {
enabled: !!t
}
};
if (File.isWin && (l["File→Properties"] = {
enabled: !!t
}), File.fileEncode = void 0, t) {
n = o.getFileNameFromPath(t);
File.filePath = t, File.fileName = n, File.fileEncode = e, s.getDocumentController().hasDuplicateName(n) ? (r.text(t), u.setTitle(t + " - Typora")) : (r.text(n), u.setTitle(n + " - Typora")), m(t), g(n), File.editor.library && (File.editor.library.markCurrentFile(), File.e && -1 != t.indexOf(File.e + (File.isWin ? "\\" : "/")) || (File.setMountFolder(reqnode("path").dirname(t)), File.editor.library.onRootChanged(File.e, !0)))
} else(n = n || File.fileName) ? (File.fileName = n, r.text(n), u.setTitle(n + "• - Typora")) : (r.text($.localize.getString("Untitled")), u.setTitle($.localize.getString("Untitled") + " - Typora")), File.filePath = void 0, i || c();
o.refreshTitlebarText(), JSBridge.menu.update(l)
};
e.watchFileChange = m, e.onPresentationMoved = v, e.setFileTitle = b, e.saveToRecover = function(t) {
t.trim().length && -1 == (File.filePath || "").indexOf(o.getUnsavedDraftsPath()) && reqnode("fs").writeFile(o.getUnsavedDraftsPath() + "/" + (i || c()), t, "utf8", function(t) {
t ? p(t) : g(File.fileName || File.getSuggestedFileName())
})
}, e.prepareInfoPanel = function() {
document.querySelector("#file-library").style.display = "", document.querySelector("#file-info-content").style.display = "none";
function t(t) {
$(".info-panel-tab.active").removeClass("active"), "file" == t ? File.editor.library.switch("files", !0) : File.editor.library.switch("outline")
}
$("#info-panel-tab-file").click(function() {
t("file")
}), $("#info-panel-tab-outline").click(function() {
t("outline")
})
}
}), $__System.registerDynamic("4b", ["14", "12", "13", "31", "37", "26", "29", "e"], !0, function(t, e, n) {
"use strict";
this || self;
var i, r, o, a, s, u = t("14"),
c = t("12"),
l = t("13"),
f = l.Node,
h = (l.TYPE, t("31")),
d = (t("37"), u = t("14"), t("26").map, t("29"), t("e")),
m = window.reqnode ? reqnode("electron").remote : null,
v = m ? m.app : window.app,
p = d("#file-library-list-children"),
g = d("#file-library-list"),
b = [],
y = function(t) {
return t.replace(/^\s*(([\n#>]+)|([-=*`\s]{3,}))/gm, "").replace(/\s*[*_`$=]+\s*/gm, " ").replace(/\[([^\]]+)\]\([^)]*\)/gm, "$1")
},
w = function(t, e, n, i) {
for (var r = e + 1; r < i; r++) {
if (t[r].indexOf(":") >= 0) return n;
n += "\n" + t[r]
}
return n
},
F = function(t, e) {
var n = e.lastIndexOf(".");
n < 0 && (n = e.length), t.find(".file-list-item-file-name-part").text(e.substr(0, n)), t.find(".file-list-item-file-ext-part").text(e.substr(n))
},
k = function(t, e) {
var n, i = t.split(/\r*\n+/),
r = i.length;
if ("---" == i[0]) {
for (var o, a = [], s = 1; s < r; s++) {
if ("---" == i[s]) return a.length < 3 && a.push(y(i.slice(s + 1).join("\n") || t)), a.join("\n");
(n = /^\s*(title)\s*:(.+)$/.exec(i[s])) ? (o = w(i, s, n[2], r)) && a.push(o.trim()): (n = /^\s*(subtitle)\s*:(.+)$/.exec(i[s])) ? (o = w(i, s, n[2], r)) && a.push(o.trim()) : (n = /^\s*(overview|summary|description|excerpt)\s*:(.+)$/.exec(i[s])) && (o = w(i, s, n[2], r)) && a.push(o.trim())
}
return y(t)
}
return y(t)
},
x = h.statWrapper;
function _(t, e, n) {
var i = File.isWin ? "\\" : "/";
if (e.find(function(e) {
return e == t || 0 == t.indexOf(e + i)
})) return !0;
!n && e.push(t)
}
var $ = 400,
E = c.Model.extend({
initialize: function(t) {
this.parent = t, this.editor = t.editor, this.$template = d(document.querySelector("#file-list-item-template").textContent), this.expandFolders = File.option.expandFolders || !1, this.setGroupByFolder(this.expandFolders), this.unixWatchers = {}, this.registerBridge(), this.needRepaint(), File.isNode && ($ = Number.parseInt(v.setting.config.maxFetchCountOnFileList) || 200, Number.isNaN($) && ($ = 200))
},
registerBridge: function() {
if (File.isMac) {
var t = this;
bridge.registerHandler("fileList.renderAll", function(e, n) {
if ("oversize" != i) {
var r = document.createDocumentFragment();
e[0].forEach(function(e) {
t.appendItemToView(e, !1, r)
}), p.html(""), p.append(r), t.endRender(e[1], e[2], e[2]), n && n(null)
}
}), bridge.registerHandler("fileList.appendItem", function(e, n) {
t.appendItemToView(e[0], e[1], void 0, {
forceMark: e[2]
}), n && n(null)
})
}
},
isShown: function() {
return this.parent.isFileTabShown() && !this.parent.useTreeStyle
},
isRendering: function() {
return i
},
renderIfNeed: function() {
return !i && (this.render(), File.isWin && this.parent.addFolderWatchByWin(File.getMountFolder()), !0)
},
appendTreeByNode: function(t, e, n, r) {
var o = reqnode("fs-plus"),
a = reqnode("path"),
s = (reqnode("util"), this),
u = File.option.useFsQueue;
n = n || 0, e = e || function() {};
var c = !!r;
r = r || g;
var l = [],
f = 0,
d = function() {
l = []
},
m = function() {
if ("oversize" != i)
for (var t = 0; t < 20 && l.length;) {
t++;
var e = l.shift();
e[1] ? v(e[0], e[2]) : p(e[0], e[2])
} else d()
},
v = function(t, e) {
f++, o.readdir(t, function(t, n) {
f--, u && f < 50 && m(), e(t, n)
})
},
p = function(t, e) {
f++, x(t, function(t) {
f--, u && f < 50 && m(), e(t)
})
},
b = function(t, e, o, c) {
if (!t) return c();
h = t, m = function(h, m) {
if (h) return c(void 0, h);
!File.isWin && s.addFileWatchByUnix(t, !0);
var v = m.length;
v || c();
var g = function() {
--v <= 0 && c()
};
m.forEach(function(c) {
var h = a.join(t, c);
m = h, v = function(a) {
if (i) {
if (!a || a.shouldIgnore) return g();
if (50 == n && !0 === i && "rendering" != r.attr("data-state") && r.attr("data-state", "rendering"), n > $) return d(), void s.endRender(!0);
a.isFile ? e(a, c, t, h, g) && n++ : a.isDir && o(a, c, t, h) ? b(h, e, o, g) : g()
}
}, u && f >= 50 ? l.push([m, !1, v]) : p(m, v);
var m, v
})
}, u && f >= 50 ? l.push([h, !0, m]) : v(h, m);
var h, m
};
b(t, function(t, e, n, i, o) {
if (!t.shouldIgnore) {
var a = {
folderPath: n,
folderName: h.getFileNameFromPath(n),
name: e,
path: i,
lastModified: t.mtime
};
return s.fetchSummaryByNode(i, function(t) {
a.summary = t, s.appendItemToView(a, !1, c ? r[0] : void 0), !File.isWin && s.addFileWatchByUnix(a.path, !1, a), o()
}), !0
}
o()
}, function(t, e, n, i) {
return !t.shouldIgnore
}, e)
},
fecthAllDocsByNode: function() {
var t = this;
this.parent.calcMountFolder(!0).then(function(e) {
t.appendTreeByNode(e || "", t.endRender.bind(t))
})
},
fetchSummaryByNode: function(t, e) {
var n;
reqnode("fs-plus").createReadStream(t, {
start: 0,
end: 600
}).on("data", function(t) {
if ("string" == typeof t) n = t;
else {
var e = h.detectEncodeByNode(t),
i = h.getContentFromBuffer(t, e);
n = i
}
}).on("end", function() {
void 0 === n && (n = ""), e(n)
})
},
render: function(t) {
if (t && this.needRepaint(), !i) {
i = !0, r = new Date, o = !1;
var e = this;
setTimeout(function() {
!0 === i && "rendering" != g.attr("data-state") && g.attr("data-state", "rendering")
}, 500), p.html("").removeClass("show-folder-name"), File.isMac ? this.parent.calcMountFolder(!0).then(function(t) {
bridge.callHandler("library.fetchAllDocs", t || "")
}) : File.isNode && this.fecthAllDocsByNode(), setTimeout(function() {
!0 === i && new Date - r > 8e3 && (console.warn("render file list timeout"), e.endRender(!0))
}, 1e4)
}
},
endRender: function(t, e, n) {
if ("oversize" != i || !t) {
if (i = t ? "oversize" : "complete", d("#file-library-list").attr("data-state", i), a && clearTimeout(a), a = setTimeout(function() {
"oversize" == i && d("#file-library-list").attr("data-state", "oversize-end")
}, 2e3), t)(File.isLinux || File.isMacNode) && Object.values(this.unixWatchers || {}).map(function(t) {
try {
t && t.close()
} catch (t) {}
});
else {
if (e && File.getMountFolder()) return void this.parent.onLoadFolderFailed();
this.parent.markCurrentFile(!1)
}
this.parent.slient = !1
}
},
setSortType: function() {
if ("complete" === i) {
p.html("");
var t = document.createDocumentFragment();
this.expandFolders ? (this.files.sort(this.parent.compareItem.bind(this.parent)), this.files.forEach(function(e) {
this.appendItemToView(e, !1, t)
}, this)) : this.dirArr.forEach(function(e) {
var n = e.content;
e.content = [], n.forEach(function(e) {
this.appendItemToView(e, !1, t)
}, this)
}, this), p.append(t)
}
},
setGroupByFolder: function(t) {
if (t ? d("#ty-group-by-folder-btn").removeClass("active") : d("#ty-group-by-folder-btn").addClass("active"), this.expandFolders != t) {
this.expandFolders = t, JSBridge.putSetting("not_group_by_folders", t), p.html("");
var e = document.createDocumentFragment();
t ? (this.files = [], this.dirArr.forEach(function(t) {
this.files = this.files.concat(t.content)
}, this), this.dirArr = [], this.dirMap = {}, this.files.sort(this.parent.compareItem.bind(this.parent)), this.files.forEach(function(t) {
this.appendItemToView(t, !1, e)
}, this)) : (this.dirArr = [], this.dirMap = {}, this.files.forEach(function(t) {
this.appendItemToView(t, !1, e)
}, this), this.files = []), p.append(e), "oversize" == i ? this.endRender(!0) : "complete" == i && this.endRender(!1)
}
},
getItem: function(t) {
if (this.expandFolders)
for (var e = this.files.length, n = 0; n < e; n++) {
if (this.files[n].path == t) return this.files[n];
if (this.files[n].folderPath == t) return {
path: t,
isDir: !0
}
} else {
if (this.dirMap[t]) return {
path: t,
isDir: !0
};
var i = u.pathByDeleteLastComponent(t);
if (this.dirMap[i]) return this.dirMap[i].content.find(function(e) {
return e.path == t
})
}
},
computeIndex: function(t) {
return (this.expandFolders ? function(t) {
var e = this.files.indexOf(t);
if (e > -1) return e;
e = 0;
for (var n = 0; n < this.files.length && !(this.parent.compareItem(this.files[n], t) > 0); n++) e++;
return this.files.splice(e, 0, t), e
} : function(t) {
var e = t.folderPath,
n = this.dirMap[e],
i = 0,
r = 0;
n || (n = {
path: e,
content: []
}, this.dirArr.push(n), this.dirMap[e] = n);
for (var o = 0; o < this.dirArr.length - 1; o++) {
var a = this.dirArr[o];
if (a.path == e) break;
i += a.content.length
}
for (o = 0; o < n.content.length && !(this.parent.compareItem(n.content[o], t) > 0); o++) r++;
return n.content.splice(r, 0, t), r + i
}).call(this, t)
},
appendItemToView: function(t, e, n, r) {
if ("oversize" != i && i) {
var a = r || {},
s = a.forceMark,
c = a.skipAnim,
l = this,
f = this.$template.clone();
if (t && t.path && File.getMountFolder()) {
o || File.getMountFolder() != t.folderPath && (o = !0, p.addClass("show-folder-name")), f.attr("data-path", t.path).attr("data-parent-path", t.folderPath), f.find(".file-list-item-file-name").attr("title", u.abbreviatingWithTilde(t.path)), f.children(".file-list-item-parent-loc").text(t.folderName), f.children(".file-list-item-time").text(u.date2NatrualLang(new Date(t.lastModified), !0)), F(f, t.name);
var d = f.children(".file-list-item-summary");
d.text(k(t.summary, t.name)), d.html(d.html().replace(/([^\s]+)\s*\n+/g, "$1<br/>")), t.path == h.getCurrentFilePath() && f.addClass("active");
var m;
if (n) this.expandFolders ? (this.computeIndex(t), n.appendChild(f[0])) : (m = this.computeIndex(t), n.insertChildAtIndex(f[0], m));
else {
if (e) {
var v, g, b = this.removeItemFromView(t, !0),
y = b.hasClass("active");
if (b && b.length) return g = b.prevAll().length, m = this.computeIndex(t), g != m || t.oldPath ? (t.oldPath = void 0, v = b[0].clientHeight, b.remove(), p[0].insertChildAtIndex(f[0], m), (y || s) && f.addClass("active"), c || p.children().each(function(t) {
var e = this;
if (e == f[0]) e.style.transition = "transform 0s", e.style.transform = "translate(0px, " + v * (g - t) + "px)";
else if (t >= m && t < g) e.style.transition = "transform 0s", e.style.transform = "translate(0px, -" + v + "px)";
else {
if (!(t >= g && t < m)) return;
e.style.transform = "translate(0px, " + v + "px)"
}
requestAnimationFrame(function() {
e.style.transform = "", e.style.transition = "transform 400ms"
})
}), h.getCurrentFilePath() == t.path && this.parent.markCurrentFile(), w(), f[0]) : b.find("input").length ? b[0] : (b.replaceWith(f), w(), f[0])
}
m = this.computeIndex(t), p[0].insertChildAtIndex(f[0], m)
}
return w(), f[0]
}
}
function w() {
var e = l.parent.nextChangeHighlight;
e && 0 == e.indexOf(t.path) && l.highlight(e)
}
},
removeFileOrFolder: function(t, e) {
var n = this,
i = File.isWin ? "\\" : "/";
function r(t) {
var i = n.findElemFromPath(t);
i.length && (e ? i.remove() : i.hide("slow", function() {
i.remove()
}))
}
if (n.expandFolders) return o = t, void n.files.removeIf(function(t) {
if (t.path == o || 0 == t.path.indexOf(o + i)) return r(t.path), !0
});
var o;
n.findElemFromPath(t).length ? n.removeItemFromView({
path: t
}, !1, e) : function(t) {
var e = 0;
n.dirArr.removeIf(function(n) {
return e++, n.path == t || 0 == n.path.indexOf(t + i)
}), 0 != e && Object.keys(n.dirMap).clone().forEach(function(e) {
e != t && 0 != e.indexOf(t + i) || (n.dirMap[e].content.forEach(function(t) {
r(t.path)
}), delete n.dirMap[e])
})
}(t)
},
removeItemFromView: function(t, e, n) {
function i(t, e) {
~t.indexOf(e) ? t.remove(e) : t.removeIf(function(t) {
return t.path.toLowerCase() == (e.oldPath || e.path).toLowerCase()
}, !0)
}
var r = this.findElemFromPath(t.oldPath || t.path);
if (t.folderPath || (t.folderPath = r.attr("data-parent-path")), !r.length) return d();
if (this.expandFolders) i(this.files, t);
else {
var o = this.dirMap[t.folderPath];
o && i(o.content, t)
}
return e || (n ? r.remove() : r.hide("slow", function() {
r.remove()
})), r
},
appendItemToViewByMac: function(t, e, n) {
this.appendItemToView(JSON.parse(t), e, void 0, {
forceMark: n
})
},
bindEvents: function() {
var t = this;
p.on("mousedown", ".file-list-item", function(e) {
if ("INPUT" == document.activeElement.tagName && d(document.activeElement).trigger("blur"), 1 == event.which) return event.ctrlKey || event.metaKey ? t.parent.openFileInNewWindowCommand(this) : (d(".file-list-item:focus").blur(), t.parent.openFile(this.getAttribute("data-path"))), !1
}), d("#switch-to-tree-on-oversize").on("click", function(e) {
t.parent.switch("file-tree")
});
var e = 0;
d("#file-library").on("dragenter", function(n) {
if (!t.parent.useTreeStyle) {
(n.originalEvent.dataTransfer.types || []).indexOf("Files") > -1 && (n.preventDefault(), n.stopPropagation(), e || document.querySelector("#sidebar-content").classList.add("on-drop")), e++
}
}).on("dragover", function(t) {
t.preventDefault(), t.stopPropagation()
}).on("dragleave", function(n) {
t.parent.useTreeStyle || --e || document.querySelector("#sidebar-content").classList.remove("on-drop")
}).on("drop", function(n) {
if (!t.parent.useTreeStyle && File.getMountFolder() && File.isActiveWindow()) {
document.querySelector("#sidebar-content").classList.remove("on-drop"), e = 0, n.stopPropagation(), n.preventDefault();
var i = n.originalEvent.dataTransfer,
r = [];
if (i.files.item(o).path)
for (var o = 0; o < i.files.length; o++) {
var a = i.files.item(o).path;
a && r.push(a)
} else r = t.parent.filesInDragging || [];
t.parent.copyOrMoveFiles(r, File.getMountFolder())
}
})
},
needRepaint: function(t) {
(t || !0 !== i) && (i = !1, this.dirArr = [], this.dirMap = {}, this.files = [])
},
findElemFromPath: function(t) {
return d(".file-list-item[data-path='" + u.escapeSelector(t) + "']")
},
onAddFile: function(t) {
return this.appendItemToView(t, !0)
},
onChangeForMac: function(t) {
if ("complete" == i && !this.parent.isSuppressOnChange()) {
for (var e = [], n = !1, r = 0; r < t.length; r++) {
var o = t[r];
if (f.isType(o.type, "created", "modified") && _(o.path, e)) return;
if ("rename" == o.type) {
if (o.isDir) {
n = !0;
break
}
var a = h.getCurrentFilePath() == o.oldPath;
this.removeFileOrFolder(o.oldPath), bridge.callHandler("library.updateListItem", {
path: o.newPath,
mark: a || !1
})
} else "removed" == o.type && this.removeFileOrFolder(o.path);
if (o.isDir && "modified" != o.type) {
n = !0;
break
}
"created" == o.type ? bridge.callHandler("library.updateListItem", {
path: o.path,
mark: !1
}) : "modified" != o.type || o.isDir || "oversize" != i && bridge.callHandler("library.updateListItemIfIsOpen", o.path)
}
if (!i && n && this.isShown()) {
var s = d("#file-library").scrollTop();
this.render(!0), setTimeout(function() {
d("#file-library").scrollTop(s)
}, 0)
}
}
},
onChangeForWin: function(t, e, n) {
if ("complete" == i && !this.parent.isSuppressOnChange()) {
var r = this;
e ? _(a = t, n, !0) || 0 != r.findElemFromPath(a).length && x(a, function(t) {
if (t && !t.shouldIgnore && t.isFile) {
var e = r.getItem(a);
if (!e) return;
r.fetchSummaryByNode(a, function(n) {
e.summary = n, e.lastModified = t.mtime, r.appendItemToView(e, !0)
}), n.push(a)
}
}) : (o = t, File.getMountFolder() && 0 == o.indexOf(File.getMountFolder()) && x(o, function(t) {
t && !t.shouldIgnore ? _(o, n) || function(t, e) {
if (e.isFile) {
var n = u.pathByDeleteLastComponent(t),
i = {
folderPath: n,
folderName: h.getFileNameFromPath(n),
name: h.getFileNameFromPath(t),
path: t
};
r.fetchSummaryByNode(t, function(t) {
i.summary = t, i.lastModified = e.mtime, r.appendItemToView(i, !0)
})
} else e.isDir && r.appendTreeByNode(t)
}(o, t) : r.removeFileOrFolder(o)
}));
var o, a
}
},
addFileWatchByUnix: function(t, e) {
if (!File.isMac && !File.isWin && "oversize" != i) {
var n, r = this,
o = (reqnode("fs-plus"), reqnode("util"), "/"),
a = this.unixWatchers[t];
try {
n = reqnode("pathwatcher")
} catch (t) {
this.parent.showUnixWatchError(t.message)
}
if (n) try {
a && (a.close(), a = null), this.unixWatchers[t] = n.watch(t, function(n) {
i = n, o = t, a = e, r.parent.isSuppressOnChange() || (s && clearTimeout(s), b.push([i, o, a]), s = setTimeout(u, 200));
var i, o, a
})
} catch (t) {
console.warn(t)
}
}
function u() {
var t = b.clone();
s = null, b = [];
var e = [];
if (!r.parent.isSuppressOnChange()) {
for (var n = [], i = [], a = !1, u = 0; u < t.length; u++) {
var c = t[u],
l = c[1];
if (c[2]) {
if ("change" != c[0]) {
a = !1;
break
} - 1 == i.indexOf(l) && i.push(l)
} else if (-1 == n.indexOf(l)) a = c[0], n.push(l);
else if (a != c[0]) {
a = !1;
break
}
}
a && 1 == n.length && 1 == i.length && 0 == n[0].indexOf(i[0]) && ("delete" == a ? t.length <= 2 && (t = [
[a, n[0], !1]
]) : "change" == a && (t = [
[a, n[0], !1]
])), t.forEach(function(t) {
! function(t, e, n, i) {
if (!i.find(function(t) {
return t == e || 0 == e.indexOf(t + o)
}))
if (i.push(e), "rename" != t && "delete" != t || e != File.getMountFolder()) {
if ("change" == t)
if (n) {
var a = File.getMountFolder() == e,
s = d("#file-library").scrollTop();
r.removeFileOrFolder(e, a), r.appendTreeByNode(e, function() {
a && d("#file-library").scrollTop(s)
})
} else {
var u = r.getItem(e);
if (!u) return;
h.statWrapper(e, function(t) {
t && !t.shouldIgnore && r.fetchSummaryByNode(e, function(e) {
u.summary = e, u.lastModified = t.mtime, r.appendItemToView(u, !0)
})
})
}
else if ("delete" == t) r.removeFileOrFolder(e);
else if ("rename" == t);
} else r.parent.onRootChanged()
}(t[0], t[1], t[2], e)
})
}
}
},
update: function(t, e) {
if (void 0 !== e) {
var n = this.parent.findElemFromPath(t).children(".file-list-item-summary");
n.text(k(e.substr(0, 500))), n.html(n.html().replace(/([^\s]+)\s*\n+/g, "$1<br/>"))
}
},
highlight: function(t) {
var e = this.focusToFile(t, !0);
e && (e.classList.add("blink-area"), setTimeout(function() {
e.classList.remove("blink-area"), this.parent.nextChangeHighlight = null
}, 2e3))
},
focusToFile: function(t, e) {
var n = this.findElemFromPath(t)[0];
if (n) {
var i = n ? n.offsetTop : 0,
r = n.clientHeight,
o = n ? {
scrollTop: Math.max(0, i - r)
} : null,
a = d(File.isMac ? ".sidebar-content" : "#file-library"),
s = a.parent().height();
return !o || a.scrollTop() < i + 40 && s + a.scrollTop() > i + 40 || (e ? a.finish().scrollTop(o.scrollTop) : a.animate(o, 500)), n
}
},
newFile: function() {
var t = this;
function e(e, n) {
var i = this.appendItemToView({
folderPath: File.getMountFolder(),
folderName: h.getFileNameFromPath(File.getMountFolder()),
name: n,
path: e,
lastModified: new Date,
summary: ""
}, !0);
if (t.parent.isDiscardableUntitled()) return t.parent.openFile(e), void setTimeout(function() {
t.renameFileCommand(i, !0)
}, 100);
t.renameFileCommand(i, !0)
}
if (File.getMountFolder())
if (o) File.isMac ? bridge.callHandler("library.newFileUnder", File.getMountFolder()) : m.dialog.showSaveDialog(File.isLinux ? null : m.getCurrentWindow(), {
title: "New",
defaultPath: File.getMountFolder() + "/Untitled.md",
buttonLabel: "Create",
filters: [{
name: "Markdown",
extensions: ["md", "markdown", "mmd", "mdown", "txt", "text"]
}]
}, function(e) {
e && (t.parent.scheduleChangeHighlight(e), reqnode("fs").writeFile(e, "", function() {
t.parent.openFile(e)
}))
});
else {
var n = function(t) {
var e = 0;
return d(".file-list-item[data-parent-path='" + JSON.stringify(t).replace(/(^")|("$)/g, "") + "']").each(function() {
var t = /^untitled( (\d+))?\./i.exec(this.querySelector(".file-list-item-file-name").textContent.trim());
t && (e = Math.max(e, (t[2] || 0) - 0 + 1))
}), "Untitled" + (e ? " " + e : "") + ".md"
}(File.getMountFolder()),
i = File.getMountFolder() + (File.isWin ? "\\" : "/") + n;
t = this;
if (this.parent.pauseOnChange(!0), File.isMac) this.parent.pauseOnChange(!0), bridge.callHandler("library.newFile", i, function(r) {
r ? e.call(this, i, n) : (t.parent.resumeOnChange(), bridge.callHandler("library.newFileUnder", File.getMountFolder()))
});
else {
var r = reqnode("fs");
i = reqnode("path").resolve(i);
var a = r.openSync(i, "wx");
r.close(a), this.parent.pauseOnChange(!0), e.call(this, i, n)
}
}
},
newFileCommand: function(t) {
this.newFile()
},
renameFileCommand: function(t, e) {
t = d(t).closest(".file-library-node")[0], File.isMac && bridge.callHandler("window.focus");
var n = this,
i = d("<input class='file-list-item-file-name' />"),
r = d(t).find(".file-list-item-file-name"),
o = r.clone(),
a = t.getAttribute("data-path"),
s = r.children().text();
r.replaceWith(i), i.val(s);
function c(e, r) {
if (r = r.trim(), e = e.trim(), F(o, e), i.replaceWith(o), a != r) {
var s = d(t);
n.appendItemToView({
path: r,
folderPath: t.getAttribute("data-parent-path"),
folderName: d(t).children(".file-list-item-parent-loc").text(),
lastModified: new Date,
name: e,
summary: (u = s.children(".file-list-item-summary"), u.length ? u[0].textContent || u[0].innerText : ""),
oldPath: a
}, !0)
}
var u;
n.editor.restoreLastCursor()
}
this.parent.bindRename(i, function(t) {
return File.isMac ? function(t) {
var e = t.val().replace(/[\/\\]/g, ""),
i = u.pathByDeleteLastComponent(a) + "/" + e;
n.parent.pauseOnChange(!0), a != i ? bridge.callHandler("library.renameFile", {
old: a,
new: i
}, function(t) {
t ? (c(e, i), a == h.getCurrentFilePath() && setTimeout(function() {
n.parent.markOpenedFile(i), n.focusToFile(i, !0)
}, 200), n.highlight(i)) : c(s, a)
}) : c(s, a)
}(t) : function(t) {
var i = t.val();
i = (File.isWin ? i.replace(/[\\\/:*?"<>\|\000-\031]/g, "") : i.replace(/[\/\\\000-\031]/g, "")).trim();
var r = reqnode("path").resolve(u.pathByDeleteLastComponent(a) + (File.isWin ? "\\" : "/") + i),
o = m.getCurrentWindow().id,
l = reqnode("fs");
a != r ? u.isSamePath(a, r) || !l.existsSync(r) ? (n.parent.pauseOnChange(!0), v.sendEvent("willRename", {
oldPath: a,
fromWin: o
}), l.rename(a, r, function(t) {
v.sendEvent("didRename", {
oldPath: a,
newPath: t ? a : r,
fromWin: o
}), t ? f(t) : (e || v.filesOp.registerUndo(r, a, d.localize.getString("Rename %@", "Panel").replace("%@", reqnode("path").basename(a))), c(i, r), n.highlight(r))
})) : f(d.localize.getString("File with same name already exists at target path.")) : c(s, a);
function f(t) {
c(s, a), m.dialog.showErrorBox(d.localize.getString("Operation Failed"), d.localize.getString('Failed to rename from "{0}" to "{1}"').format(s, i) + "\n" + t)
}
}(t)
}, function() {
c(s, a)
}, e), i.focus()
}
});
n.exports = E
}), $__System.registerDynamic("46", ["e", "12"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("e"),
r = t("12").Model.extend({
initialize: function(t) {
this.editor = t, this.$container = i("#emoji-auto-suggest"), setTimeout(function() {
i.getScript("./app/editor/EmojiSearchMap.js", function() {
var t = window.EmojiSearchMap;
for (var e in r.data) t[e] || (t[e] = [e])
})
}, 1e3)
},
search: function(t, e) {
if (!t) return [];
var n, i = new RegExp("(^" + t + ")|(_" + t + ")|(-" + t + ")", "i"),
o = Object.keys(r.data).filter(function(e) {
return i.exec(e) && e !== t
});
if (o.sort(), r.data[t] && o.unshift(t), n = (window.EmojiSearchMap || {})[t])
for (var a = 0; a < n.length; a++) - 1 == o.indexOf(n[a]) && o.push(n[a]);
return e.type = "emoji", e.token = t, e.match = o, e.found = o.length, e.pageNo = 0, e.pageCnt = Math.floor((o.length - 1) / 5 + 1), o
},
showAutoSuggest: function(t, e) {
if (e.token === t) return !1;
var n = this.search(t, e),
i = "";
if (!e.found) return this.$container.hide(), !1;
for (var o = 0; o < n.length && o < 40; o++) o % 5 == 0 && (i += (o > 0 ? "</ul>" : "") + "<ul data-page='" + o / 5 + "' style='display:none'>"), i += "<li data-content=':" + n[o] + ":' ><span>" + r.data[n[o]] + "</span> <span class='emoji-meta'>:" + n[o] + ":</span></li>";
return i += "</ul>", this.$container.html(i), this.$container
}
});
r.data = {
100: "💯",
1234: "🔢",
grinning: "😀",
smiley: "😃",
smile: "😄",
grin: "😁",
laughing: "😆",
satisfied: "😆",
sweat_smile: "😅",
joy: "😂",
rofl: "🤣",
relaxed: "☺️",
blush: "😊",
innocent: "😇",
slightly_smiling_face: "🙂",
upside_down_face: "🙃",
wink: "😉",
relieved: "😌",
heart_eyes: "😍",
kissing_heart: "😘",
kissing: "😗",
kissing_smiling_eyes: "😙",
kissing_closed_eyes: "😚",
yum: "😋",
stuck_out_tongue_winking_eye: "😜",
stuck_out_tongue_closed_eyes: "😝",
stuck_out_tongue: "😛",
money_mouth_face: "🤑",
hugs: "🤗",
nerd_face: "🤓",
sunglasses: "😎",
clown_face: "🤡",
cowboy_hat_face: "🤠",
smirk: "😏",
unamused: "😒",
disappointed: "😞",
pensive: "😔",
worried: "😟",
confused: "😕",
slightly_frowning_face: "🙁",
frowning_face: "☹️",
persevere: "😣",
confounded: "😖",
tired_face: "😫",
weary: "😩",
triumph: "😤",
angry: "😠",
rage: "😡",
pout: "😡",
no_mouth: "😶",
neutral_face: "😐",
expressionless: "😑",
hushed: "😯",
frowning: "😦",
anguished: "😧",
open_mouth: "😮",
astonished: "😲",
dizzy_face: "😵",
flushed: "😳",
scream: "😱",
fearful: "😨",
cold_sweat: "😰",
cry: "😢",
disappointed_relieved: "😥",
drooling_face: "🤤",
sob: "😭",
sweat: "😓",
sleepy: "😪",
sleeping: "😴",
roll_eyes: "🙄",
thinking: "🤔",
lying_face: "🤥",
grimacing: "😬",
zipper_mouth_face: "🤐",
nauseated_face: "🤢",
sneezing_face: "🤧",
mask: "😷",
face_with_thermometer: "🤒",
face_with_head_bandage: "🤕",
smiling_imp: "😈",
imp: "👿",
japanese_ogre: "👹",
japanese_goblin: "👺",
hankey: "💩",
poop: "💩",
shit: "💩",
ghost: "👻",
skull: "💀",
skull_and_crossbones: "☠️",
alien: "👽",
space_invader: "👾",
robot: "🤖",
jack_o_lantern: "🎃",
smiley_cat: "😺",
smile_cat: "😸",
joy_cat: "😹",
heart_eyes_cat: "😻",
smirk_cat: "😼",
kissing_cat: "😽",
scream_cat: "🙀",
crying_cat_face: "😿",
pouting_cat: "😾",
open_hands: "👐",
raised_hands: "🙌",
clap: "👏",
pray: "🙏",
handshake: "🤝",
"+1": "👍",
thumbsup: "👍",
"-1": "👎",
thumbsdown: "👎",
fist_oncoming: "👊",
facepunch: "👊",
punch: "👊",
fist_raised: "✊",
fist: "✊",
fist_left: "🤛",
fist_right: "🤜",
crossed_fingers: "🤞",
v: "✌️",
metal: "🤘",
ok_hand: "👌",
point_left: "👈",
point_right: "👉",
point_up_2: "👆",
point_down: "👇",
point_up: "☝️",
hand: "✋",
raised_hand: "✋",
raised_back_of_hand: "🤚",
raised_hand_with_fingers_splayed: "🖐",
vulcan_salute: "🖖",
wave: "👋",
call_me_hand: "🤙",
muscle: "💪",
middle_finger: "🖕",
fu: "🖕",
writing_hand: "✍️",
selfie: "🤳",
nail_care: "💅",
ring: "💍",
lipstick: "💄",
kiss: "💋",
lips: "👄",
tongue: "👅",
ear: "👂",
nose: "👃",
footprints: "👣",
eye: "👁",
eyes: "👀",
speaking_head: "🗣",
bust_in_silhouette: "👤",
busts_in_silhouette: "👥",
baby: "👶",
boy: "👦",
girl: "👧",
man: "👨",
woman: "👩",
blonde_woman: "👱‍♀",
blonde_man: "👱",
person_with_blond_hair: "👱",
older_man: "👴",
older_woman: "👵",
man_with_gua_pi_mao: "👲",
woman_with_turban: "👳‍♀",
man_with_turban: "👳",
policewoman: "👮‍♀",
policeman: "👮",
cop: "👮",
construction_worker_woman: "👷‍♀",
construction_worker_man: "👷",
construction_worker: "👷",
guardswoman: "💂‍♀",
guardsman: "💂",
female_detective: "🕵️‍♀️",
male_detective: "🕵",
detective: "🕵",
woman_health_worker: "👩‍⚕",
man_health_worker: "👨‍⚕",
woman_farmer: "👩‍🌾",
man_farmer: "👨‍🌾",
woman_cook: "👩‍🍳",
man_cook: "👨‍🍳",
woman_student: "👩‍🎓",
man_student: "👨‍🎓",
woman_singer: "👩‍🎤",
man_singer: "👨‍🎤",
woman_teacher: "👩‍🏫",
man_teacher: "👨‍🏫",
woman_factory_worker: "👩‍🏭",
man_factory_worker: "👨‍🏭",
woman_technologist: "👩‍💻",
man_technologist: "👨‍💻",
woman_office_worker: "👩‍💼",
man_office_worker: "👨‍💼",
woman_mechanic: "👩‍🔧",
man_mechanic: "👨‍🔧",
woman_scientist: "👩‍🔬",
man_scientist: "👨‍🔬",
woman_artist: "👩‍🎨",
man_artist: "👨‍🎨",
woman_firefighter: "👩‍🚒",
man_firefighter: "👨‍🚒",
woman_pilot: "👩‍✈",
man_pilot: "👨‍✈",
woman_astronaut: "👩‍🚀",
man_astronaut: "👨‍🚀",
woman_judge: "👩‍⚖",
man_judge: "👨‍⚖",
mrs_claus: "🤶",
santa: "🎅",
princess: "👸",
prince: "🤴",
bride_with_veil: "👰",
man_in_tuxedo: "🤵",
angel: "👼",
pregnant_woman: "🤰",
bowing_woman: "🙇‍♀",
bowing_man: "🙇",
bow: "🙇",
tipping_hand_woman: "💁",
information_desk_person: "💁",
sassy_woman: "💁",
tipping_hand_man: "💁‍♂",
sassy_man: "💁‍♂",
no_good_woman: "🙅",
no_good: "🙅",
ng_woman: "🙅",
no_good_man: "🙅‍♂",
ng_man: "🙅‍♂",
ok_woman: "🙆",
ok_man: "🙆‍♂",
raising_hand_woman: "🙋",
raising_hand: "🙋",
raising_hand_man: "🙋‍♂",
woman_facepalming: "🤦‍♀",
man_facepalming: "🤦‍♂",
woman_shrugging: "🤷‍♀",
man_shrugging: "🤷‍♂",
pouting_woman: "🙎",
person_with_pouting_face: "🙎",
pouting_man: "🙎‍♂",
frowning_woman: "🙍",
person_frowning: "🙍",
frowning_man: "🙍‍♂",
haircut_woman: "💇",
haircut: "💇",
haircut_man: "💇‍♂",
massage_woman: "💆",
massage: "💆",
massage_man: "💆‍♂",
business_suit_levitating: "🕴",
dancer: "💃",
man_dancing: "🕺",
dancing_women: "👯",
dancers: "👯",
dancing_men: "👯‍♂",
walking_woman: "🚶‍♀",
walking_man: "🚶",
walking: "🚶",
running_woman: "🏃‍♀",
running_man: "🏃",
runner: "🏃",
running: "🏃",
couple: "👫",
two_women_holding_hands: "👭",
two_men_holding_hands: "👬",
couple_with_heart_woman_man: "💑",
couple_with_heart: "💑",
couple_with_heart_woman_woman: "👩‍❤️‍👩",
couple_with_heart_man_man: "👨‍❤️‍👨",
couplekiss_man_woman: "💏",
couplekiss_woman_woman: "👩‍❤️‍💋‍👩",
couplekiss_man_man: "👨‍❤️‍💋‍👨",
family_man_woman_boy: "👪",
family: "👪",
family_man_woman_girl: "👨‍👩‍👧",
family_man_woman_girl_boy: "👨‍👩‍👧‍👦",
family_man_woman_boy_boy: "👨‍👩‍👦‍👦",
family_man_woman_girl_girl: "👨‍👩‍👧‍👧",
family_woman_woman_boy: "👩‍👩‍👦",
family_woman_woman_girl: "👩‍👩‍👧",
family_woman_woman_girl_boy: "👩‍👩‍👧‍👦",
family_woman_woman_boy_boy: "👩‍👩‍👦‍👦",
family_woman_woman_girl_girl: "👩‍👩‍👧‍👧",
family_man_man_boy: "👨‍👨‍👦",
family_man_man_girl: "👨‍👨‍👧",
family_man_man_girl_boy: "👨‍👨‍👧‍👦",
family_man_man_boy_boy: "👨‍👨‍👦‍👦",
family_man_man_girl_girl: "👨‍👨‍👧‍👧",
family_woman_boy: "👩‍👦",
family_woman_girl: "👩‍👧",
family_woman_girl_boy: "👩‍👧‍👦",
family_woman_boy_boy: "👩‍👦‍👦",
family_woman_girl_girl: "👩‍👧‍👧",
family_man_boy: "👨‍👦",
family_man_girl: "👨‍👧",
family_man_girl_boy: "👨‍👧‍👦",
family_man_boy_boy: "👨‍👦‍👦",
family_man_girl_girl: "👨‍👧‍👧",
womans_clothes: "👚",
shirt: "👕",
tshirt: "👕",
jeans: "👖",
necktie: "👔",
dress: "👗",
bikini: "👙",
kimono: "👘",
high_heel: "👠",
sandal: "👡",
boot: "👢",
mans_shoe: "👞",
shoe: "👞",
athletic_shoe: "👟",
womans_hat: "👒",
tophat: "🎩",
mortar_board: "🎓",
crown: "👑",
rescue_worker_helmet: "⛑",
school_satchel: "🎒",
pouch: "👝",
purse: "👛",
handbag: "👜",
briefcase: "💼",
eyeglasses: "👓",
dark_sunglasses: "🕶",
closed_umbrella: "🌂",
open_umbrella: "☂️",
dog: "🐶",
cat: "🐱",
mouse: "🐭",
hamster: "🐹",
rabbit: "🐰",
fox_face: "🦊",
bear: "🐻",
panda_face: "🐼",
koala: "🐨",
tiger: "🐯",
lion: "🦁",
cow: "🐮",
pig: "🐷",
pig_nose: "🐽",
frog: "🐸",
monkey_face: "🐵",
see_no_evil: "🙈",
hear_no_evil: "🙉",
speak_no_evil: "🙊",
monkey: "🐒",
chicken: "🐔",
penguin: "🐧",
bird: "🐦",
baby_chick: "🐤",
hatching_chick: "🐣",
hatched_chick: "🐥",
duck: "🦆",
eagle: "🦅",
owl: "🦉",
bat: "🦇",
wolf: "🐺",
boar: "🐗",
horse: "🐴",
unicorn: "🦄",
bee: "🐝",
honeybee: "🐝",
bug: "🐛",
butterfly: "🦋",
snail: "🐌",
shell: "🐚",
beetle: "🐞",
ant: "🐜",
spider: "🕷",
spider_web: "🕸",
turtle: "🐢",
snake: "🐍",
lizard: "🦎",
scorpion: "🦂",
crab: "🦀",
squid: "🦑",
octopus: "🐙",
shrimp: "🦐",
tropical_fish: "🐠",
fish: "🐟",
blowfish: "🐡",
dolphin: "🐬",
flipper: "🐬",
shark: "🦈",
whale: "🐳",
whale2: "🐋",
crocodile: "🐊",
leopard: "🐆",
tiger2: "🐅",
water_buffalo: "🐃",
ox: "🐂",
cow2: "🐄",
deer: "🦌",
dromedary_camel: "🐪",
camel: "🐫",
elephant: "🐘",
rhinoceros: "🦏",
gorilla: "🦍",
racehorse: "🐎",
pig2: "🐖",
goat: "🐐",
ram: "🐏",
sheep: "🐑",
dog2: "🐕",
poodle: "🐩",
cat2: "🐈",
rooster: "🐓",
turkey: "🦃",
dove: "🕊",
rabbit2: "🐇",
mouse2: "🐁",
rat: "🐀",
chipmunk: "🐿",
feet: "🐾",
paw_prints: "🐾",
dragon: "🐉",
dragon_face: "🐲",
cactus: "🌵",
christmas_tree: "🎄",
evergreen_tree: "🌲",
deciduous_tree: "🌳",
palm_tree: "🌴",
seedling: "🌱",
herb: "🌿",
shamrock: "☘️",
four_leaf_clover: "🍀",
bamboo: "🎍",
tanabata_tree: "🎋",
leaves: "🍃",
fallen_leaf: "🍂",
maple_leaf: "🍁",
mushroom: "🍄",
ear_of_rice: "🌾",
bouquet: "💐",
tulip: "🌷",
rose: "🌹",
wilted_flower: "🥀",
sunflower: "🌻",
blossom: "🌼",
cherry_blossom: "🌸",
hibiscus: "🌺",
earth_americas: "🌎",
earth_africa: "🌍",
earth_asia: "🌏",
full_moon: "🌕",
waning_gibbous_moon: "🌖",
last_quarter_moon: "🌗",
waning_crescent_moon: "🌘",
new_moon: "🌑",
waxing_crescent_moon: "🌒",
first_quarter_moon: "🌓",
moon: "🌔",
waxing_gibbous_moon: "🌔",
new_moon_with_face: "🌚",
full_moon_with_face: "🌝",
sun_with_face: "🌞",
first_quarter_moon_with_face: "🌛",
last_quarter_moon_with_face: "🌜",
crescent_moon: "🌙",
dizzy: "💫",
star: "⭐️",
star2: "🌟",
sparkles: "✨",
zap: "⚡️",
fire: "🔥",
boom: "💥",
collision: "💥",
comet: "☄",
sunny: "☀️",
sun_behind_small_cloud: "🌤",
partly_sunny: "⛅️",
sun_behind_large_cloud: "🌥",
sun_behind_rain_cloud: "🌦",
rainbow: "🌈",
cloud: "☁️",
cloud_with_rain: "🌧",
cloud_with_lightning_and_rain: "⛈",
cloud_with_lightning: "🌩",
cloud_with_snow: "🌨",
snowman_with_snow: "☃️",
snowman: "⛄️",
snowflake: "❄️",
wind_face: "🌬",
dash: "💨",
tornado: "🌪",
fog: "🌫",
ocean: "🌊",
droplet: "💧",
sweat_drops: "💦",
umbrella: "☔️",
green_apple: "🍏",
apple: "🍎",
pear: "🍐",
tangerine: "🍊",
orange: "🍊",
mandarin: "🍊",
lemon: "🍋",
banana: "🍌",
watermelon: "🍉",
grapes: "🍇",
strawberry: "🍓",
melon: "🍈",
cherries: "🍒",
peach: "🍑",
pineapple: "🍍",
kiwi_fruit: "🥝",
avocado: "🥑",
tomato: "🍅",
eggplant: "🍆",
cucumber: "🥒",
carrot: "🥕",
corn: "🌽",
hot_pepper: "🌶",
potato: "🥔",
sweet_potato: "🍠",
chestnut: "🌰",
peanuts: "🥜",
honey_pot: "🍯",
croissant: "🥐",
bread: "🍞",
baguette_bread: "🥖",
cheese: "🧀",
egg: "🥚",
fried_egg: "🍳",
bacon: "🥓",
pancakes: "🥞",
fried_shrimp: "🍤",
poultry_leg: "🍗",
meat_on_bone: "🍖",
pizza: "🍕",
hotdog: "🌭",
hamburger: "🍔",
fries: "🍟",
stuffed_flatbread: "🥙",
taco: "🌮",
burrito: "🌯",
green_salad: "🥗",
shallow_pan_of_food: "🥘",
spaghetti: "🍝",
ramen: "🍜",
stew: "🍲",
fish_cake: "🍥",
sushi: "🍣",
bento: "🍱",
curry: "🍛",
rice: "🍚",
rice_ball: "🍙",
rice_cracker: "🍘",
oden: "🍢",
dango: "🍡",
shaved_ice: "🍧",
ice_cream: "🍨",
icecream: "🍦",
cake: "🍰",
birthday: "🎂",
custard: "🍮",
lollipop: "🍭",
candy: "🍬",
chocolate_bar: "🍫",
popcorn: "🍿",
doughnut: "🍩",
cookie: "🍪",
milk_glass: "🥛",
baby_bottle: "🍼",
coffee: "☕️",
tea: "🍵",
sake: "🍶",
beer: "🍺",
beers: "🍻",
clinking_glasses: "🥂",
wine_glass: "🍷",
tumbler_glass: "🥃",
cocktail: "🍸",
tropical_drink: "🍹",
champagne: "🍾",
spoon: "🥄",
fork_and_knife: "🍴",
plate_with_cutlery: "🍽",
soccer: "⚽️",
basketball: "🏀",
football: "🏈",
baseball: "⚾️",
tennis: "🎾",
volleyball: "🏐",
rugby_football: "🏉",
"8ball": "🎱",
ping_pong: "🏓",
badminton: "🏸",
goal_net: "🥅",
ice_hockey: "🏒",
field_hockey: "🏑",
cricket: "🏏",
golf: "⛳️",
bow_and_arrow: "🏹",
fishing_pole_and_fish: "🎣",
boxing_glove: "🥊",
martial_arts_uniform: "🥋",
ice_skate: "⛸",
ski: "🎿",
skier: "⛷",
snowboarder: "🏂",
weight_lifting_woman: "🏋️‍♀️",
weight_lifting_man: "🏋",
person_fencing: "🤺",
women_wrestling: "🤼‍♀",
men_wrestling: "🤼‍♂",
woman_cartwheeling: "🤸‍♀",
man_cartwheeling: "🤸‍♂",
basketball_woman: "⛹️‍♀️",
basketball_man: "⛹",
woman_playing_handball: "🤾‍♀",
man_playing_handball: "🤾‍♂",
golfing_woman: "🏌️‍♀️",
golfing_man: "🏌",
surfing_woman: "🏄‍♀",
surfing_man: "🏄",
surfer: "🏄",
swimming_woman: "🏊‍♀",
swimming_man: "🏊",
swimmer: "🏊",
woman_playing_water_polo: "🤽‍♀",
man_playing_water_polo: "🤽‍♂",
rowing_woman: "🚣‍♀",
rowing_man: "🚣",
rowboat: "🚣",
horse_racing: "🏇",
biking_woman: "🚴‍♀",
biking_man: "🚴",
bicyclist: "🚴",
mountain_biking_woman: "🚵‍♀",
mountain_biking_man: "🚵",
mountain_bicyclist: "🚵",
running_shirt_with_sash: "🎽",
medal_sports: "🏅",
medal_military: "🎖",
"1st_place_medal": "🥇",
"2nd_place_medal": "🥈",
"3rd_place_medal": "🥉",
trophy: "🏆",
rosette: "🏵",
reminder_ribbon: "🎗",
ticket: "🎫",
tickets: "🎟",
circus_tent: "🎪",
woman_juggling: "🤹‍♀",
man_juggling: "🤹‍♂",
performing_arts: "🎭",
art: "🎨",
clapper: "🎬",
microphone: "🎤",
headphones: "🎧",
musical_score: "🎼",
musical_keyboard: "🎹",
drum: "🥁",
saxophone: "🎷",
trumpet: "🎺",
guitar: "🎸",
violin: "🎻",
game_die: "🎲",
dart: "🎯",
bowling: "🎳",
video_game: "🎮",
slot_machine: "🎰",
car: "🚗",
red_car: "🚗",
taxi: "🚕",
blue_car: "🚙",
bus: "🚌",
trolleybus: "🚎",
racing_car: "🏎",
police_car: "🚓",
ambulance: "🚑",
fire_engine: "🚒",
minibus: "🚐",
truck: "🚚",
articulated_lorry: "🚛",
tractor: "🚜",
kick_scooter: "🛴",
bike: "🚲",
motor_scooter: "🛵",
motorcycle: "🏍",
rotating_light: "🚨",
oncoming_police_car: "🚔",
oncoming_bus: "🚍",
oncoming_automobile: "🚘",
oncoming_taxi: "🚖",
aerial_tramway: "🚡",
mountain_cableway: "🚠",
suspension_railway: "🚟",
railway_car: "🚃",
train: "🚋",
mountain_railway: "🚞",
monorail: "🚝",
bullettrain_side: "🚄",
bullettrain_front: "🚅",
light_rail: "🚈",
steam_locomotive: "🚂",
train2: "🚆",
metro: "🚇",
tram: "🚊",
station: "🚉",
helicopter: "🚁",
small_airplane: "🛩",
airplane: "✈️",
flight_departure: "🛫",
flight_arrival: "🛬",
rocket: "🚀",
artificial_satellite: "🛰",
seat: "💺",
canoe: "🛶",
boat: "⛵️",
sailboat: "⛵️",
motor_boat: "🛥",
speedboat: "🚤",
passenger_ship: "🛳",
ferry: "⛴",
ship: "🚢",
anchor: "⚓️",
construction: "🚧",
fuelpump: "⛽️",
busstop: "🚏",
vertical_traffic_light: "🚦",
traffic_light: "🚥",
world_map: "🗺",
moyai: "🗿",
statue_of_liberty: "🗽",
fountain: "⛲️",
tokyo_tower: "🗼",
european_castle: "🏰",
japanese_castle: "🏯",
stadium: "🏟",
ferris_wheel: "🎡",
roller_coaster: "🎢",
carousel_horse: "🎠",
parasol_on_ground: "⛱",
beach_umbrella: "🏖",
desert_island: "🏝",
mountain: "⛰",
mountain_snow: "🏔",
mount_fuji: "🗻",
volcano: "🌋",
desert: "🏜",
camping: "🏕",
tent: "⛺️",
railway_track: "🛤",
motorway: "🛣",
building_construction: "🏗",
factory: "🏭",
house: "🏠",
house_with_garden: "🏡",
houses: "🏘",
derelict_house: "🏚",
office: "🏢",
department_store: "🏬",
post_office: "🏣",
european_post_office: "🏤",
hospital: "🏥",
bank: "🏦",
hotel: "🏨",
convenience_store: "🏪",
school: "🏫",
love_hotel: "🏩",
wedding: "💒",
classical_building: "🏛",
church: "⛪️",
mosque: "🕌",
synagogue: "🕍",
kaaba: "🕋",
shinto_shrine: "⛩",
japan: "🗾",
rice_scene: "🎑",
national_park: "🏞",
sunrise: "🌅",
sunrise_over_mountains: "🌄",
stars: "🌠",
sparkler: "🎇",
fireworks: "🎆",
city_sunrise: "🌇",
city_sunset: "🌆",
cityscape: "🏙",
night_with_stars: "🌃",
milky_way: "🌌",
bridge_at_night: "🌉",
foggy: "🌁",
watch: "⌚️",
iphone: "📱",
calling: "📲",
computer: "💻",
keyboard: "⌨️",
desktop_computer: "🖥",
printer: "🖨",
computer_mouse: "🖱",
trackball: "🖲",
joystick: "🕹",
clamp: "🗜",
minidisc: "💽",
floppy_disk: "💾",
cd: "💿",
dvd: "📀",
vhs: "📼",
camera: "📷",
camera_flash: "📸",
video_camera: "📹",
movie_camera: "🎥",
film_projector: "📽",
film_strip: "🎞",
telephone_receiver: "📞",
phone: "☎️",
telephone: "☎️",
pager: "📟",
fax: "📠",
tv: "📺",
radio: "📻",
studio_microphone: "🎙",
level_slider: "🎚",
control_knobs: "🎛",
stopwatch: "⏱",
timer_clock: "⏲",
alarm_clock: "⏰",
mantelpiece_clock: "🕰",
hourglass: "⌛️",
hourglass_flowing_sand: "⏳",
satellite: "📡",
battery: "🔋",
electric_plug: "🔌",
bulb: "💡",
flashlight: "🔦",
candle: "🕯",
wastebasket: "🗑",
oil_drum: "🛢",
money_with_wings: "💸",
dollar: "💵",
yen: "💴",
euro: "💶",
pound: "💷",
moneybag: "💰",
credit_card: "💳",
gem: "💎",
balance_scale: "⚖️",
wrench: "🔧",
hammer: "🔨",
hammer_and_pick: "⚒",
hammer_and_wrench: "🛠",
pick: "⛏",
nut_and_bolt: "🔩",
gear: "⚙️",
chains: "⛓",
gun: "🔫",
bomb: "💣",
hocho: "🔪",
knife: "🔪",
dagger: "🗡",
crossed_swords: "⚔️",
shield: "🛡",
smoking: "🚬",
coffin: "⚰️",
funeral_urn: "⚱️",
amphora: "🏺",
crystal_ball: "🔮",
prayer_beads: "📿",
barber: "💈",
alembic: "⚗️",
telescope: "🔭",
microscope: "🔬",
hole: "🕳",
pill: "💊",
syringe: "💉",
thermometer: "🌡",
toilet: "🚽",
potable_water: "🚰",
shower: "🚿",
bathtub: "🛁",
bath: "🛀",
bellhop_bell: "🛎",
key: "🔑",
old_key: "🗝",
door: "🚪",
couch_and_lamp: "🛋",
bed: "🛏",
sleeping_bed: "🛌",
framed_picture: "🖼",
shopping: "🛍",
shopping_cart: "🛒",
gift: "🎁",
balloon: "🎈",
flags: "🎏",
ribbon: "🎀",
confetti_ball: "🎊",
tada: "🎉",
dolls: "🎎",
izakaya_lantern: "🏮",
lantern: "🏮",
wind_chime: "🎐",
email: "✉️",
envelope: "✉️",
envelope_with_arrow: "📩",
incoming_envelope: "📨",
"e-mail": "📧",
love_letter: "💌",
inbox_tray: "📥",
outbox_tray: "📤",
package: "📦",
label: "🏷",
mailbox_closed: "📪",
mailbox: "📫",
mailbox_with_mail: "📬",
mailbox_with_no_mail: "📭",
postbox: "📮",
postal_horn: "📯",
scroll: "📜",
page_with_curl: "📃",
page_facing_up: "📄",
bookmark_tabs: "📑",
bar_chart: "📊",
chart_with_upwards_trend: "📈",
chart_with_downwards_trend: "📉",
spiral_notepad: "🗒",
spiral_calendar: "🗓",
calendar: "📆",
date: "📅",
card_index: "📇",
card_file_box: "🗃",
ballot_box: "🗳",
file_cabinet: "🗄",
clipboard: "📋",
file_folder: "📁",
open_file_folder: "📂",
card_index_dividers: "🗂",
newspaper_roll: "🗞",
newspaper: "📰",
notebook: "📓",
notebook_with_decorative_cover: "📔",
ledger: "📒",
closed_book: "📕",
green_book: "📗",
blue_book: "📘",
orange_book: "📙",
books: "📚",
book: "📖",
open_book: "📖",
bookmark: "🔖",
link: "🔗",
paperclip: "📎",
paperclips: "🖇",
triangular_ruler: "📐",
straight_ruler: "📏",
pushpin: "📌",
round_pushpin: "📍",
scissors: "✂️",
pen: "🖊",
fountain_pen: "🖋",
black_nib: "✒️",
paintbrush: "🖌",
crayon: "🖍",
memo: "📝",
pencil: "📝",
pencil2: "✏️",
mag: "🔍",
mag_right: "🔎",
lock_with_ink_pen: "🔏",
closed_lock_with_key: "🔐",
lock: "🔒",
unlock: "🔓",
heart: "❤️",
yellow_heart: "💛",
green_heart: "💚",
blue_heart: "💙",
purple_heart: "💜",
black_heart: "🖤",
broken_heart: "💔",
heavy_heart_exclamation: "❣️",
two_hearts: "💕",
revolving_hearts: "💞",
heartbeat: "💓",
heartpulse: "💗",
sparkling_heart: "💖",
cupid: "💘",
gift_heart: "💝",
heart_decoration: "💟",
peace_symbol: "☮️",
latin_cross: "✝️",
star_and_crescent: "☪️",
om: "🕉",
wheel_of_dharma: "☸️",
star_of_david: "✡️",
six_pointed_star: "🔯",
menorah: "🕎",
yin_yang: "☯️",
orthodox_cross: "☦️",
place_of_worship: "🛐",
ophiuchus: "⛎",
aries: "♈️",
taurus: "♉️",
gemini: "♊️",
cancer: "♋️",
leo: "♌️",
virgo: "♍️",
libra: "♎️",
scorpius: "♏️",
sagittarius: "♐️",
capricorn: "♑️",
aquarius: "♒️",
pisces: "♓️",
id: "🆔",
atom_symbol: "⚛️",
accept: "🉑",
radioactive: "☢️",
biohazard: "☣️",
mobile_phone_off: "📴",
vibration_mode: "📳",
eight_pointed_black_star: "✴️",
vs: "🆚",
white_flower: "💮",
ideograph_advantage: "🉐",
secret: "㊙️",
congratulations: "㊗️",
u6e80: "🈵",
a: "🅰️",
b: "🅱️",
ab: "🆎",
cl: "🆑",
o2: "🅾️",
sos: "🆘",
x: "❌",
o: "⭕️",
stop_sign: "🛑",
no_entry: "⛔️",
name_badge: "📛",
no_entry_sign: "🚫",
anger: "💢",
hotsprings: "♨️",
no_pedestrians: "🚷",
do_not_litter: "🚯",
no_bicycles: "🚳",
"non-potable_water": "🚱",
underage: "🔞",
no_mobile_phones: "📵",
no_smoking: "🚭",
exclamation: "❗️",
heavy_exclamation_mark: "❗️",
grey_exclamation: "❕",
question: "❓",
grey_question: "❔",
bangbang: "‼️",
interrobang: "⁉️",
low_brightness: "🔅",
high_brightness: "🔆",
part_alternation_mark: "〽️",
warning: "⚠️",
children_crossing: "🚸",
trident: "🔱",
fleur_de_lis: "⚜️",
beginner: "🔰",
recycle: "♻️",
white_check_mark: "✅",
chart: "💹",
sparkle: "❇️",
eight_spoked_asterisk: "✳️",
negative_squared_cross_mark: "❎",
globe_with_meridians: "🌐",
diamond_shape_with_a_dot_inside: "💠",
m: "Ⓜ️",
cyclone: "🌀",
zzz: "💤",
atm: "🏧",
wc: "🚾",
wheelchair: "♿️",
parking: "🅿️",
sa: "🈂️",
passport_control: "🛂",
customs: "🛃",
baggage_claim: "🛄",
left_luggage: "🛅",
mens: "🚹",
womens: "🚺",
baby_symbol: "🚼",
restroom: "🚻",
put_litter_in_its_place: "🚮",
cinema: "🎦",
signal_strength: "📶",
koko: "🈁",
symbols: "🔣",
information_source: "ℹ️",
abc: "🔤",
abcd: "🔡",
capital_abcd: "🔠",
ng: "🆖",
ok: "🆗",
up: "🆙",
cool: "🆒",
new: "🆕",
free: "🆓",
zero: "0️⃣",
one: "1️⃣",
two: "2️⃣",
three: "3️⃣",
four: "4️⃣",
five: "5️⃣",
six: "6️⃣",
seven: "7️⃣",
eight: "8️⃣",
nine: "9️⃣",
keycap_ten: "🔟",
hash: "#️⃣",
asterisk: "*️⃣",
arrow_forward: "▶️",
pause_button: "⏸",
play_or_pause_button: "⏯",
stop_button: "⏹",
record_button: "⏺",
next_track_button: "⏭",
previous_track_button: "⏮",
fast_forward: "⏩",
rewind: "⏪",
arrow_double_up: "⏫",
arrow_double_down: "⏬",
arrow_backward: "◀️",
arrow_up_small: "🔼",
arrow_down_small: "🔽",
arrow_right: "➡️",
arrow_left: "⬅️",
arrow_up: "⬆️",
arrow_down: "⬇️",
arrow_upper_right: "↗️",
arrow_lower_right: "↘️",
arrow_lower_left: "↙️",
arrow_upper_left: "↖️",
arrow_up_down: "↕️",
left_right_arrow: "↔️",
arrow_right_hook: "↪️",
leftwards_arrow_with_hook: "↩️",
arrow_heading_up: "⤴️",
arrow_heading_down: "⤵️",
twisted_rightwards_arrows: "🔀",
repeat: "🔁",
repeat_one: "🔂",
arrows_counterclockwise: "🔄",
arrows_clockwise: "🔃",
musical_note: "🎵",
notes: "🎶",
heavy_plus_sign: "➕",
heavy_minus_sign: "➖",
heavy_division_sign: "➗",
heavy_multiplication_x: "✖️",
heavy_dollar_sign: "💲",
currency_exchange: "💱",
tm: "™️",
copyright: "©️",
registered: "®️",
wavy_dash: "〰️",
curly_loop: "➰",
loop: "➿",
end: "🔚",
back: "🔙",
on: "🔛",
top: "🔝",
soon: "🔜",
heavy_check_mark: "✔️",
ballot_box_with_check: "☑️",
radio_button: "🔘",
white_circle: "⚪️",
black_circle: "⚫️",
red_circle: "🔴",
large_blue_circle: "🔵",
small_red_triangle: "🔺",
small_red_triangle_down: "🔻",
small_orange_diamond: "🔸",
small_blue_diamond: "🔹",
large_orange_diamond: "🔶",
large_blue_diamond: "🔷",
white_square_button: "🔳",
black_square_button: "🔲",
black_small_square: "▪️",
white_small_square: "▫️",
black_medium_small_square: "◾️",
white_medium_small_square: "◽️",
black_medium_square: "◼️",
white_medium_square: "◻️",
black_large_square: "⬛️",
white_large_square: "⬜️",
speaker: "🔈",
mute: "🔇",
sound: "🔉",
loud_sound: "🔊",
bell: "🔔",
no_bell: "🔕",
mega: "📣",
loudspeaker: "📢",
eye_speech_bubble: "👁‍🗨",
speech_balloon: "💬",
thought_balloon: "💭",
right_anger_bubble: "🗯",
spades: "♠️",
clubs: "♣️",
hearts: "♥️",
diamonds: "♦️",
black_joker: "🃏",
flower_playing_cards: "🎴",
mahjong: "🀄️",
clock1: "🕐",
clock2: "🕑",
clock3: "🕒",
clock4: "🕓",
clock5: "🕔",
clock6: "🕕",
clock7: "🕖",
clock8: "🕗",
clock9: "🕘",
clock10: "🕙",
clock11: "🕚",
clock12: "🕛",
clock130: "🕜",
clock230: "🕝",
clock330: "🕞",
clock430: "🕟",
clock530: "🕠",
clock630: "🕡",
clock730: "🕢",
clock830: "🕣",
clock930: "🕤",
clock1030: "🕥",
clock1130: "🕦",
clock1230: "🕧",
white_flag: "🏳️",
black_flag: "🏴",
checkered_flag: "🏁",
triangular_flag_on_post: "🚩",
rainbow_flag: "🏳️‍🌈",
afghanistan: "🇦🇫",
aland_islands: "🇦🇽",
albania: "🇦🇱",
algeria: "🇩🇿",
american_samoa: "🇦🇸",
andorra: "🇦🇩",
angola: "🇦🇴",
anguilla: "🇦🇮",
antarctica: "🇦🇶",
antigua_barbuda: "🇦🇬",
argentina: "🇦🇷",
armenia: "🇦🇲",
aruba: "🇦🇼",
australia: "🇦🇺",
austria: "🇦🇹",
azerbaijan: "🇦🇿",
bahamas: "🇧🇸",
bahrain: "🇧🇭",
bangladesh: "🇧🇩",
barbados: "🇧🇧",
belarus: "🇧🇾",
belgium: "🇧🇪",
belize: "🇧🇿",
benin: "🇧🇯",
bermuda: "🇧🇲",
bhutan: "🇧🇹",
bolivia: "🇧🇴",
caribbean_netherlands: "🇧🇶",
bosnia_herzegovina: "🇧🇦",
botswana: "🇧🇼",
brazil: "🇧🇷",
british_indian_ocean_territory: "🇮🇴",
british_virgin_islands: "🇻🇬",
brunei: "🇧🇳",
bulgaria: "🇧🇬",
burkina_faso: "🇧🇫",
burundi: "🇧🇮",
cape_verde: "🇨🇻",
cambodia: "🇰🇭",
cameroon: "🇨🇲",
canada: "🇨🇦",
canary_islands: "🇮🇨",
cayman_islands: "🇰🇾",
central_african_republic: "🇨🇫",
chad: "🇹🇩",
chile: "🇨🇱",
cn: "🇨🇳",
christmas_island: "🇨🇽",
cocos_islands: "🇨🇨",
colombia: "🇨🇴",
comoros: "🇰🇲",
congo_brazzaville: "🇨🇬",
congo_kinshasa: "🇨🇩",
cook_islands: "🇨🇰",
costa_rica: "🇨🇷",
cote_divoire: "🇨🇮",
croatia: "🇭🇷",
cuba: "🇨🇺",
curacao: "🇨🇼",
cyprus: "🇨🇾",
czech_republic: "🇨🇿",
denmark: "🇩🇰",
djibouti: "🇩🇯",
dominica: "🇩🇲",
dominican_republic: "🇩🇴",
ecuador: "🇪🇨",
egypt: "🇪🇬",
el_salvador: "🇸🇻",
equatorial_guinea: "🇬🇶",
eritrea: "🇪🇷",
estonia: "🇪🇪",
ethiopia: "🇪🇹",
eu: "🇪🇺",
european_union: "🇪🇺",
falkland_islands: "🇫🇰",
faroe_islands: "🇫🇴",
fiji: "🇫🇯",
finland: "🇫🇮",
fr: "🇫🇷",
french_guiana: "🇬🇫",
french_polynesia: "🇵🇫",
french_southern_territories: "🇹🇫",
gabon: "🇬🇦",
gambia: "🇬🇲",
georgia: "🇬🇪",
de: "🇩🇪",
ghana: "🇬🇭",
gibraltar: "🇬🇮",
greece: "🇬🇷",
greenland: "🇬🇱",
grenada: "🇬🇩",
guadeloupe: "🇬🇵",
guam: "🇬🇺",
guatemala: "🇬🇹",
guernsey: "🇬🇬",
guinea: "🇬🇳",
guinea_bissau: "🇬🇼",
guyana: "🇬🇾",
haiti: "🇭🇹",
honduras: "🇭🇳",
hong_kong: "🇭🇰",
hungary: "🇭🇺",
iceland: "🇮🇸",
india: "🇮🇳",
indonesia: "🇮🇩",
iran: "🇮🇷",
iraq: "🇮🇶",
ireland: "🇮🇪",
isle_of_man: "🇮🇲",
israel: "🇮🇱",
it: "🇮🇹",
jamaica: "🇯🇲",
jp: "🇯🇵",
crossed_flags: "🎌",
jersey: "🇯🇪",
jordan: "🇯🇴",
kazakhstan: "🇰🇿",
kenya: "🇰🇪",
kiribati: "🇰🇮",
kosovo: "🇽🇰",
kuwait: "🇰🇼",
kyrgyzstan: "🇰🇬",
laos: "🇱🇦",
latvia: "🇱🇻",
lebanon: "🇱🇧",
lesotho: "🇱🇸",
liberia: "🇱🇷",
libya: "🇱🇾",
liechtenstein: "🇱🇮",
lithuania: "🇱🇹",
luxembourg: "🇱🇺",
macau: "🇲🇴",
macedonia: "🇲🇰",
madagascar: "🇲🇬",
malawi: "🇲🇼",
malaysia: "🇲🇾",
maldives: "🇲🇻",
mali: "🇲🇱",
malta: "🇲🇹",
marshall_islands: "🇲🇭",
martinique: "🇲🇶",
mauritania: "🇲🇷",
mauritius: "🇲🇺",
mayotte: "🇾🇹",
mexico: "🇲🇽",
micronesia: "🇫🇲",
moldova: "🇲🇩",
monaco: "🇲🇨",
mongolia: "🇲🇳",
montenegro: "🇲🇪",
montserrat: "🇲🇸",
morocco: "🇲🇦",
mozambique: "🇲🇿",
myanmar: "🇲🇲",
namibia: "🇳🇦",
nauru: "🇳🇷",
nepal: "🇳🇵",
netherlands: "🇳🇱",
new_caledonia: "🇳🇨",
new_zealand: "🇳🇿",
nicaragua: "🇳🇮",
niger: "🇳🇪",
nigeria: "🇳🇬",
niue: "🇳🇺",
norfolk_island: "🇳🇫",
northern_mariana_islands: "🇲🇵",
north_korea: "🇰🇵",
norway: "🇳🇴",
oman: "🇴🇲",
pakistan: "🇵🇰",
palau: "🇵🇼",
palestinian_territories: "🇵🇸",
panama: "🇵🇦",
papua_new_guinea: "🇵🇬",
paraguay: "🇵🇾",
peru: "🇵🇪",
philippines: "🇵🇭",
pitcairn_islands: "🇵🇳",
poland: "🇵🇱",
portugal: "🇵🇹",
puerto_rico: "🇵🇷",
qatar: "🇶🇦",
reunion: "🇷🇪",
romania: "🇷🇴",
ru: "🇷🇺",
rwanda: "🇷🇼",
st_barthelemy: "🇧🇱",
st_helena: "🇸🇭",
st_kitts_nevis: "🇰🇳",
st_lucia: "🇱🇨",
st_pierre_miquelon: "🇵🇲",
st_vincent_grenadines: "🇻🇨",
samoa: "🇼🇸",
san_marino: "🇸🇲",
sao_tome_principe: "🇸🇹",
saudi_arabia: "🇸🇦",
senegal: "🇸🇳",
serbia: "🇷🇸",
seychelles: "🇸🇨",
sierra_leone: "🇸🇱",
singapore: "🇸🇬",
sint_maarten: "🇸🇽",
slovakia: "🇸🇰",
slovenia: "🇸🇮",
solomon_islands: "🇸🇧",
somalia: "🇸🇴",
south_africa: "🇿🇦",
south_georgia_south_sandwich_islands: "🇬🇸",
kr: "🇰🇷",
south_sudan: "🇸🇸",
es: "🇪🇸",
sri_lanka: "🇱🇰",
sudan: "🇸🇩",
suriname: "🇸🇷",
swaziland: "🇸🇿",
sweden: "🇸🇪",
switzerland: "🇨🇭",
syria: "🇸🇾",
taiwan: "🇹🇼",
tajikistan: "🇹🇯",
tanzania: "🇹🇿",
thailand: "🇹🇭",
timor_leste: "🇹🇱",
togo: "🇹🇬",
tokelau: "🇹🇰",
tonga: "🇹🇴",
trinidad_tobago: "🇹🇹",
tunisia: "🇹🇳",
tr: "🇹🇷",
turkmenistan: "🇹🇲",
turks_caicos_islands: "🇹🇨",
tuvalu: "🇹🇻",
uganda: "🇺🇬",
ukraine: "🇺🇦",
united_arab_emirates: "🇦🇪",
gb: "🇬🇧",
uk: "🇬🇧",
us: "🇺🇸",
us_virgin_islands: "🇻🇮",
uruguay: "🇺🇾",
uzbekistan: "🇺🇿",
vanuatu: "🇻🇺",
vatican_city: "🇻🇦",
venezuela: "🇻🇪",
vietnam: "🇻🇳",
wallis_futuna: "🇼🇫",
western_sahara: "🇪🇭",
yemen: "🇾🇪",
zambia: "🇿🇲",
zimbabwe: "🇿🇼"
}, r.data.happy = r.data.smile, n.exports = r
}), $__System.registerDynamic("1d", ["12", "14", "13", "1b", "1c"], !0, function(t, e, n) {
"use strict";
this || self, t("12"), t("14");
var i, r, o = t("13"),
a = t("1b").SnapFlag,
s = (o.Node, o.TYPE, t("1c")),
u = ["“", "”", "‘", "’"],
c = {
isSmartQuote: function(t) {
return !!c.shouldTriggerReplaceQuote() && [c.userQuote(0), c.userQuote(1), c.userQuote(2), c.userQuote(3)].indexOf(t) > -1
},
shouldTriggerReplaceQuote: function(t) {
return !File.option.convertSmartOnRender && (t || !File.isMac) && File.option.smartQuote
},
replaceQuote: function(t, e) {
if (!File.option.convertSmartOnRender && File.option.smartQuote) {
var n = "'" == t.textContent.toString()[0];
t && (2 == t.textContent.length ? t.nodeValue = c.userQuote(n ? 2 : 0, !1, !0) + c.userQuote(n ? 3 : 1, !1, !0) : t.nodeValue = c.userQuote(n ? 2 : 0, !1, !0)), e && (e.nodeValue = c.userQuote(n ? 3 : 1, !1, !0))
}
},
userQuote: function(t, e, n) {
var i = (File.option.userQuotesArray || u)[t] || u[t];
return !e || '"' != i && "'" != i ? n ? i : i.trim() : null
},
shouldTriggerReplace: function(t, e) {
var n = t.getJQueryElem(e.commonAncestorContainer);
return !n.closest("code, script, pre, [md-inline='escape']").length && !n.find("code, script, [md-inline='escape']").length
},
clearLastQuoteState: function() {
i = !1, r = !1
},
handlerCh: function(t, e, n, o, u, l) {
var f, h = function(t, e) {
var n = t[t.length - 1] || "";
return !(!/(^|[\(\{\[\s\-/\u2018])$/.exec(n) && !/(^|\s)[*`~+^$_]$/.exec(t)) || (!(!e || c.userQuote(0) != n) || !e && c.userQuote(2) == n)
},
d = function() {
return void 0 !== f ? f : f = m().replace(/\\[-."']/g, "")
},
m = function() {
try {
var t = s.createRange();
return t.setEnd(l.startContainer, l.startOffset), t.setStart($(l.startContainer).closest("[md-inline], [cid]")[0], 0), t.toString()
} catch (t) {}
return ""
},
v = function(i, r) {
var o = function() {
var n = t.selection.buildUndo(l);
return l.insertNode(document.createTextNode(e)), n.end = n.start + 1, n.start = n.end, n
}();
o.start -= 1 + i, t.selection.restoreSelection(t.findElemById(n.cid)[0], {
start: o.end,
end: o.end
});
var s = t.selection.restoreSelection(t.findElemById(n.cid)[0], {
start: o.start,
end: o.end
});
if (s) {
var u = document.createTextNode(r);
s.deleteContents(), s.insertNode(u), s.setStartAndEnd(u, 1), s.select()
}
t.undo.addSnap(n.cid, a.REPLACE)
},
p = function(e, n) {
var o = t.getMarkElem(e.startContainer),
a = t.selection.getOffset(o, e);
return n ? !(!i || i.startContainer != o[0] || i.startOffset != a) || (i = {
startContainer: o[0],
startOffset: a
}, !1) : !(!r || r.startContainer != o[0] || r.startOffset != a) || (r = {
startContainer: o[0],
startOffset: a
}, !1)
};
if (!File.option.convertSmartOnRender && !File.isMac) {
if ("-" == e && File.option.smartDash) {
if (!c.shouldTriggerReplace(t, l)) return;
var g;
if (/\\$/.exec(d())) return;
if (g = /(--|–)$/.exec(d())) return v(g[0].length, "—"), !0;
if (/-$/.exec(d())) return v(1, "–"), !0
}
if ("." == e && File.option.smartDash) {
if (!c.shouldTriggerReplace(t, l)) return;
if (/\\$/.exec(d())) return;
if (/\.\.$/.exec(d())) return v(2, "…"), !0
}
var b;
if ("'" == e && File.option.smartQuote) {
if (!c.shouldTriggerReplace(t, l)) return;
if (/\\$/.exec(d())) return;
return b = h(d(), !0), p(l, !0) && (i = null, b = !b), b ? (v(0, c.userQuote(2)), !0) : (v(0, c.userQuote(3)), !0)
}
if ('"' == e && File.option.smartQuote) {
if (!c.shouldTriggerReplace(t, l)) return;
if (/\\$/.exec(d())) return;
return b = h(d(), !1), p(l, !1) && (r = null, b = !b), b ? (v(0, c.userQuote(0)), !0) : (v(0, c.userQuote(1)), !0)
}
}
}
};
n.exports = c
}), $__System.registerDynamic("19", ["14", "13", "2f", "1b", "46", "18", "1d"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("14"),
r = t("13"),
o = r.Node,
a = r.TYPE,
s = t("2f"),
u = t("1b"),
c = t("46"),
l = t("18"),
f = t("1d"),
h = {
ul: /^(\s*)(([-+*])\s+)/,
ol: /^(\s*)\d+\.\s+/,
tasklist: /^(\s*)(([-+*])\s*)\[((x|X)| )\]\s+/
},
d = /^(\s*)([-+*>\[]|\d+\.)\s+/,
m = /^(\s*)[^\s]/,
v = null,
p = {
ul: /^(\s*)([-+*])\s+/,
ol: /^(\s*)(\d+\.)\s+/,
tasklist: /^(\s*)([-+*]\s*\[((x|X)| )\])\s+/
},
g = {
ul: /^(\s{0,3})([-+*])\s+/,
ol: /^(\s{0,3})(\d+\.)\s+/,
tasklist: /^(\s{0,3})([-+*]\s*\[((x|X)| )\])\s+/
},
b = /\r\n|\r|\n|\u2424/,
y = /^[ \u00A0]{0,3}$/,
w = /^[\s\u00A0]*$/,
F = /(^\s{0,3}>[ \t]*)(.*)$/,
k = /(^\s*(#{1,6})\s*)([^\n]+?)(\s+#+\s*)*$/,
x = /(^\s*(#{1,6})\s+)([^\n]+?)(\s+#+\s*)*$/,
_ = /^ *(=|-){2,}[\s\u00A0]*$/,
$ = /^\s*[-+*_<\[\{|#0-9`~=>$]/,
E = /^( *(`{3,}|~{3,}|·{3,})[ \t\u00A0]*)([^\n`]+)? *$/,
C = /^\s*(`{3,}|~{3,})\s*$/,
A = /^\s*\${2}\s*(?:\{(.+)\})?$/,
S = /^( {4}|\t)(\s*\S.*)$/,
T = /^( {4}|\t)/,
M = /^\s*([-+_*])\s*\1\s*\1(\s|\1)*$/,
D = /^\s*\[toc\]\s*$/i,
L = /^\s*\{:toc\}\s*$/i,
R = /^\s?\{:\s*toc(\s*|(\s+.*))\}/,
B = /^\s*\[([^\]]+)\]:(\s*<?)([^\s>]+)(>?)((\s+)["'(]([^\n]*)["')])?\s*$/,
I = /^\s*\[\^([^\]\n]+)\]:(\s*)([^\n]*)$/,
N = /^-{3}$/,
O = /^ *\|([^\|]+\|.+)\|\s*$/,
j = /^\s*\|(.+)\|\s*$/,
P = /^ *\|(\s*[-:]+\s*\|[-| :]*)$/,
q = /^ *([-:]+\s*\|[-| :]*)$/,
U = /\|/,
z = l.BLOCK_OPEN_REG,
H = /^\s*[-\u2013\u2014+*_<\u3010\[\{|#0-9`~=>$]/,
W = /^\s*([-\u2013\u2014])/,
J = /^\s*[\[\u3010]toc[\]\u3011]\s*$/i,
Y = /^(-{3}|\u2013[-\u2013\u2014]+|\u2014[-\u2013\u2014]*)$/,
G = {},
K = {},
V = {},
Q = {},
X = " ",
Z = function(t) {
if (t.get("style") == o.ListType.ol) {
for (var e = function(t) {
if (t.get("style") == o.ListType.ol) {
for (var e = t.getFirstChild(), n = !1, i = e.get("after"); i && i._numText;) {
if (e._numText.trim() != i._numText.trim()) return !1;
n = !0, i = (e = i).get("after")
}
return n
}
}(t), n = t.getFirstChild(), i = n._numText; n;) n._numText = void 0, n = n.get("after");
e && t.set("pattern", i), t.set("isFixed", e)
}
},
tt = function(t) {
return (t || "").replace(/\t/g, X).length
},
et = {
NOT_CLOSE: 0,
CLOSE_EXCLUDE: 1,
CLOSE_INCLUDE: 2,
UNKNOWN: -1
},
nt = l.getHTMLTagReg,
it = {
paragraph: {
shouldClose: function(t) {
return t.match(y) ? (this.cur.set("tail", 1), et.CLOSE_INCLUDE) : et.UNKNOWN
},
onClose: function(t) {
this.cur._lines.length > 1 && this.cur._lines[0].match(w) && (this.cur.set("ahead", 1), this.cur._lines.shift()), !this.cur._lines.length && this.cur._lines.push(""), this.cur.set("text", this.cur._lines.join("\n")), this.cur._lines = void 0
},
onContinue: function(t) {
this.cur._lines.push(t)
}
},
html_block: {
shouldClose: function(t) {
var e, n = this.cur.get("depth") || 0,
i = nt(this.cur.get("style")),
r = t;
if (!t.trim()) return et.CLOSE_EXCLUDE;
for (; e = i.exec(r);) r = r.substring(e.index + e[0].length), e[2] ? n-- : e[1] || n++;
return n <= 0 ? (this.cur.set("depth", 0), this.cur._lines.push(t), et.CLOSE_INCLUDE) : (this.cur.set("depth", n), et.NOT_CLOSE)
},
onClose: function(t) {
var e = this.cur.get("depth");
this.cur.set("text", this.cur._lines.join("\n")), e && this.skips.enableStartMatch && (1 != this.cur._lines.length || />/.exec(this.cur._lines[0]) ? l.autoCloseTag(this.cur) : (this.cur.set("type", a.paragraph), this.cur.unset("style"))), this.cur._lines = void 0
},
onContinue: function(t) {
this.cur._lines.push(t)
}
},
blockquote: {
shouldClose: function(t) {
return t.trim().length ? t.match(F) ? et.NOT_CLOSE : t.match(/\t|( {2,})/) ? et.NOT_CLOSE : et.UNKNOWN : (this.cur.set("tail", 1), et.CLOSE_INCLUDE)
},
onClose: function(t) {
new ot(this.cur._lines, this.cur, null, null, this.skips), this.cur._lines = void 0, this.cur.unset("text"), (this.skips || {}).pass_format || this.cur.set("userIndent", this.cur._lineIndents), this.cur._lineIndents = void 0
},
onContinue: function(t) {
var e = this.cur._indent;
G[e] || (G[e] = new RegExp("^((( {0," + (e + 4) + "}|\\t)> {0," + (e || 1) + "})|\\t|>(\\t| {0," + (e || 1) + "}))"), G[e].toString());
var n = G[e].exec(t) || [""],
i = n[0];
if (n[2] && e < 4 && !/^\s*([-+*>]|\d+\.)\s/.exec(t.substring(i.length)) && (K[e] || (K[e] = new RegExp("^( {1," + (4 - e) + "}|\\t)>")), !K[e].exec(t.substring(i.length)))) {
i += (new RegExp("^ {1," + (4 - e) + "}").exec(t.substring(i.length)) || [""])[0]
}
this.cur._lineIndents.push(i), this.cur._lines.push(t.substring(i.length))
}
},
list: {
shouldClose: function(t) {
var e, n = this.cur.getLastChild();
if (V[n._indent] || (V[n._indent] = new RegExp("^( {" + n._indent + ",}|\\t)")), t.match(V[n._indent])) return this.cur.unset("tail"), et.NOT_CLOSE;
if (t.match(w)) return this.cur.set("tail", (this.cur.get("tail") || 0) + 1), this.cur.get("tail") > 1 ? (this.cur.set("tail", 1), et.CLOSE_EXCLUDE) : et.NOT_CLOSE;
if (n._minIndent < n._indent && (V[n._minIndent] || (V[n._minIndent] = new RegExp("^( {" + n._minIndent + ",})")), t.match(V[n._minIndent]))) return this.cur.unset("tail"), n._indent = /^\s+/.exec(t)[0].length, n._indentDecided = !1, et.NOT_CLOSE;
if (e = h[this.cur.get("style")].exec(t)) return this.cur.get("style") != o.ListType.ol ? e[3] == this.cur._mark ? 0 : 1 : et.NOT_CLOSE;
return this.lines[this.ln - 1].match(w) ? et.CLOSE_EXCLUDE : et.UNKNOWN
},
onClose: function() {
for (var t = this.cur.getLastChild(), e = this.cur.get("tail") || 0; e > 0 && !t._lines.last().trim().length;) t._lines.pop(), t._lineIndents.pop(), e--;
new ot(t._lines, t, null, null, this.skips), t.unset("text"), (this.skips || {}).pass_format || t.set("userIndent", t._lineIndents), t._lines = void 0, t._indent = void 0, t._minIndent = void 0, t._indentDecided = void 0, t._lineIndents = void 0, this.cur._mark = void 0, this.cur.unset("text"), (this.skips || {}).pass_format || (Z(this.cur), !this.cur.get("tail") && this.lines[this.ln] && this.cur.set("tail", 0))
},
onContinue: function(t, e, n) {
var i, r = this.cur.getLastChild(),
s = tt(e),
u = File.option.strictMarkdown ? s - n : 2,
c = this.cur.get("style"),
l = 0;
n = n || (r ? r.get("prespace") : 0) || 0;
function f(t, e, n) {
n && (t._lines = []), t._lines.push(e)
}
t.match(w) || this.cur.unset("tail");
var p, g;
if (!r) return c == o.ListType.ol && (l = /^\s*(\d+)\.\s+/.exec(t)[1].length - 1), r = new o({
type: a.list_item,
prespace: n,
markindent: s - l - n
}), this.cur.append(r), r._indent = u + n, r._minIndent = l + (c == o.ListType.ol ? 3 : 2) + n, c == o.ListType.ol && (r._numText = (/^\s*(\d+\.\s+)/.exec(t) || [])[1], r._numLength = l), (g = h[o.ListType.task].exec(t)) ? (r.set("checked", !!g[5]), r.set("style", o.ListType.task), p = g[0]) : p = h[c].exec(t)[0], r._lineIndents = [p], void f(r, t.substring(p.length), !0);
r._numLength = r._numLength || 0, V[r._indent] || (V[r._indent] = new RegExp("^( {" + r._indent + ",}|\\t)"));
var b = t.match(V[r._indent]),
y = 0;
if (Q[r._indent] || (Q[r._indent] = new RegExp("^ {2," + r._indent + "}|\\t")), y = (t.match(Q[r._indent]) || [""])[0].length, p = (Q[r._indent].exec(t) || [""])[0], t = b ? t.substring(p.length) : t, r.get("style") == o.ListType.task && !File.option.strictMarkdown && b && (p += (t.match(/^ {4}/) || [""])[0], t = t.replace(/^ {4}/, "")), !b && (i = v[c].exec(t))) return n = (i[1] || "").length, e = i[0], s = tt(e), u = File.option.strictMarkdown ? s - n : 2, r._lines.length > 1 && r._lines.last().match(w) ? (r._lines.pop(), r.set("tail", 1)) : r.set("tail", 0), this.cur.unset("tail"), new ot(r._lines, r, null, null, this.skips), (this.skips || {}).pass_format || r.set("userIndent", r._lineIndents), r.unset("text"), r._lines = void 0, r._lineIndents = void 0, r._indent = void 0, c == o.ListType.ol && (l = /^\s*(\d+)\.\s+/.exec(t)[1].length - 1), (r = new o({
type: a.list_item,
prespace: n,
markindent: s - l - n
}))._numLength = l, r._numText = (/^\s*(\d+\.\s+)/.exec(t) || [])[1], r._minIndent = l + (c == o.ListType.ol ? 3 : 2) + n, p = i[0], (g = h[o.ListType.task].exec(t)) && (r.set("checked", !!g[5]), r.set("style", o.ListType.task), p = g[0]), this.cur.append(r), r._indent = u + n, r._lineIndents = [p], void f(r, t.substring(p.length), !0);
if (!r._indentDecided) {
if ((i = m.exec(t)) && r._indent && r._indent - n < 4)
if (i[1].length) {
var F = i[1].length,
k = F + r._indent;
k > n + r.get("markindent") && (x = r._lines, d.exec(function(t) {
if (!t || 0 == t.length) return "";
for (var e = t.length - 1; e >= 0; e--)
if (t[e].trim().length > 0) return t[e];
return ""
}(x))) ? F = r.get("markindent") - r._indent : k >= n + r.get("markindent") + 4 && (F = F + r._indent - 4 - r.get("markindent")), r._indent += F, this.cur.set("subindent", r._indent - r._numLength), r.set("subindent", r._indent - r._numLength), p += t.substring(0, F), t = t.substring(F)
} else r.set("subindent", Math.max(2, y - r._numLength));
r._indentDecided = !!i
}
return r._lineIndents.push(p), void f(r, t, !1);
var x
}
},
fences: {
shouldClose: function(t) {
var e;
if (e = C.exec(t)) {
var n = e[1][0] == this.cur._mark[0] ? et.CLOSE_INCLUDE : et.NOT_CLOSE;
return n == et.CLOSE_INCLUDE && this.cur._mark != e[1] && this.cur.set("patternEnd", e[1]), n
}
return et.NOT_CLOSE
},
onContinue: function(t) {
this.cur._lines.push(t)
},
onClose: function() {
this.cur.set("text", this.cur._lines.join("\n")), this.cur._mark = void 0, this.cur._lines = void 0;
var t = this.lines[this.ln + 1];
void 0 !== t && t.match(w) && (this.cur.set("tail", 1), this.ln++)
}
},
code: {
shouldClose: function(t) {
return t.match(S) ? et.NOT_CLOSE : t.trim().length ? et.CLOSE_EXCLUDE : this.cur._lines.length > 1 && !this.cur._lines.last().trim().length ? et.CLOSE_EXCLUDE : et.NOT_CLOSE
},
onClose: function() {
var t = this.lines[this.ln];
t && !t.trim().length && this.cur._lines.push(t.replace(T, "")), this.cur._lines.length > 1 && (this.cur._lines.last().match(w) ? (this.cur.set("tail", 1), this.cur._lines.pop(), this.cur._lines.length > 1 && this.cur._lines.last().match(w) && (this.cur._lines.pop(), this.ln--)) : this.cur.set("tail", 0)), this.cur.set("text", this.cur._lines.join("\n")), this.cur.attributes.type = a.fences, this.cur._lines = void 0
},
onContinue: function(t) {
this.cur._lines.push(t.replace(T, ""))
}
}
};
function rt(t, e, n) {
var i, r, o = "",
a = "",
s = [],
u = 0;
if (!e) {
if (!(r = j.exec(t))) return null;
t = r[1]
}
if (t = t.replace(/(^|[^\\])((`+)([\s\S]*?[^`])\3(?!`))/g, function(t, e, n) {
return s.push(n), [e, o, ++u - 1, a].join("")
}), File.option.enableInlineMath && (t = t.replace(/\\\$/g, "").replace(/(^|[^\\])((\$+)([\s\S]*?[^$])\3(?!\$))/g, function(t, e, n) {
return s.push(n.replace(/\uE07D/g, "\\$")), u++, [e.replace(/\uE07D/g, "\\$"), o, u - 1, a].join("")
})), i = (t = t.replace(/\\\\/g, lt.ESCAPE_ESCAPE).replace(/\\\|/g, lt.ESCAPE_VLINE).replace(/\\\ /g, lt.ESCAPE_SPACE)).split(U), e && i.length <= 1) return null;
if (i.length < n && File.option.enableInlineMath) {
var c = (t = t.replace(/\uE07A(\d+)\uE07B/g, function(t, e) {
return s[e - 0]
})).split(U);
c.length == n && (i = c)
}
return i.map(function(t) {
return (e = t.replace(/\uE022/g, "\\ ").replace(new RegExp("", "g"), "\\$").replace(/\uE07A(\d+)\uE07B/g, function(t, e) {
return s[e - 0]
})) ? e.replace(new RegExp(lt.ESCAPE_ESCAPE, "g"), "\\\\").replace(new RegExp(lt.ESCAPE_VLINE, "g"), "\\|") : e;
var e
})
}
var ot = function(t, e, n, i, r) {
v = File.option.strictMarkdown ? g : p;
var o = t;
this.remap = File.shouldRemapPunctuation() && (r.enableRemap || i && i.cid == File.editor.focusCid), "string" == typeof t && (o = t.split(b), "\n" === t.charCodeAt(t.length - 1) && (a -= 1));
var a = o.length;
this.lines = o, u = e, c = n, l = i, f = r, (s = this).parent = u, s.cur = null, s.skips = f, s.ln = 0, s.blocks = [], s.oldNode = l, s.nodeMap = u || l, s.nodeMap = s.nodeMap ? s.nodeMap.get("in") : c, X = " ".repeat(File.option.indentSize);
var s, u, c, l, f;
for (this.skips.enableMetaBlock = this.skips.enableMetaBlock && !e; this.ln <= a; this.ln++) at.call(this, o[this.ln], a);
return this
};
function at(t, e) {
var n = this.ln >= e;
function r(t) {
if (o.isType(this.cur, a.paragraph) && this.cur._lines && 1 == this.cur._lines.length && this.cur._lines[0].match(w)) return function(t) {
this.blocks.remove(t), t.remove()
}.call(this, this.cur), this.cur = null, t.set("ahead", 1), !0
}
function s(t) {
var e = this.lines[this.ln + 1];
if (void 0 !== e && e.match(w)) return this.ln++, t.set("tail", 1), !0;
void 0 !== e && t.set("tail", 0)
}
function u(t, e) {
var n, i = t = t || this.cur;
this.oldNode && !this.blocks.length ? (this.oldNode !== t && (n = t.get("userIndent"), t.giveChildrenTo(this.oldNode), this.oldNode.copyContentFrom(t), this.oldNode.set("userIndent", n), t._lines && (this.oldNode._lines = t._lines), t.remove()), this.blocks.push(this.oldNode), i = this.oldNode) : (this.parent ? this.parent.append(t) : this.blocks.length ? this.blocks.last().insert(t) : (console.sendError("parse error: " + t.getText()), t.set("parent", this.parent), t.set("in", this.nodeMap), t.set("attachTo", this.nodeMap)), this.blocks.push(t)), this.cur = e ? i : null
}
var c, f, d;
function m(t, n) {
this.cur && (!o.isType(this.cur, a.paragraph) || (this.cur._lines || []).length ? (d.onClose && d.onClose.call(this, n), this.ln < e - 1 && void 0 == this.cur.get("tail") && this.cur.set("tail", 0), u.call(this, this.cur, t)) : this.cur = null)
}
function v(t, e, n) {
var i = new o({
type: a.list,
style: t,
in: this.nodeMap,
pattern: e
});
t == o.ListType.ol ? i.set("start", n) : i._mark = n, r.call(this, i), m.call(this), this.cur = i
}
function p(e) {
var n = e ? q : P;
if (i = rt(t, e)) {
var i, r, o = this.ln + 1,
a = this.lines.length,
s = this.lines[o],
u = [];
if (o < a && this.lines[o].match(n))
for (o++; o < a && (r = null, r = rt(this.lines[o], e, i.length)); o++) u.push(r);
if (u.length) return s = e ? s.split(U) : s.replace(/^ *\||\| *$/g, "").split(U), b.call(this, i, s, u, o - 1, e), !0
}
return !1
}
function g(t) {
f = new o({
type: a.toc,
in: this.nodeMap,
pattern: t
}), r.call(this, f), s.call(this, f), m.call(this, !0), u.call(this, f)
}
function b(t, e, n, c, l) {
var f, h = (this.skips || {}).pass_format,
d = new o({
type: a.table,
in: this.nodeMap,
style: !h && e && l ? "npTable" : void 0
}),
v = t.length,
p = h || function(t, e, n) {
if (!e || !n) return !0;
for (var r = 0; r < t.length; r++) {
var o = (t[r] || "").length;
if (!(o > 40)) {
var a = i.wcswidth(t[r]);
if (o != (e[r] || "").length && a != i.wcswidth(e[r])) return !1;
for (var s = 0; s < n.length; s++) {
var u = (n[s] || [])[r] || "";
if (!(u.length > 40) && o !== u.length && a != i.wcswidth(u)) return !1
}
}
}
return !0
}(t, e, n);
function g(t, e) {
var n, i = new o({
type: a.table_row,
parent: t,
in: t.get("in"),
header: !f,
before: f
});
for (y = 0; y < v; y++) {
var r = (e[y] || "").match(/^\s*/)[0];
e[y] = (e[y] || "").substring(r.length);
var s = (e[y] || "").match(/\s*$/)[0];
n = new o({
type: a.table_cell,
parent: i,
in: i.get("in"),
before: n,
text: (e[y] || "").trim(),
marginLeft: p ? void 0 : r,
marginRight: p ? void 0 : s
})
}
return i
}
if (d.set("alignText", p ? void 0 : e.slice(0)), !h && e && n) {
var b = [t.join("|"), e.join("|")].concat(n.map(function(t) {
return t.join("|")
}));
l || (b = b.map(function(t) {
return "|" + t + "|"
})), d.set("userText", b)
}
e = e || new Array(t.length), n = n || [
[]
];
for (var y = 0; y < v; y++) e[y] = e[y] || "", e[y].match(/^ *-+: *$/) ? e[y] = "right" : e[y].match(/^ *:-+: *$/) ? e[y] = "center" : e[y].match(/^ *:-+ *$/) ? e[y] = "left" : e[y] = null;
d.set("align", e), f = g.call(this, d, t), n.forEach(function(t) {
f = g.call(this, d, t)
}, this), r.call(this, d), m.call(this), c && (this.ln = c), s.call(this, d), u.call(this, d), this.cur = null
}
if (this.cur) {
d = it[this.cur.get("type")];
var y = !n && d.shouldClose.call(this, t);
if (y > 0 || n) {
if (m.call(this, !1, n), 2 == y) return
} else if (!y) return void(d.onContinue && d.onContinue.call(this, t))
}
if (!n)
if (this.skips.old_code || this.skips.fromP || !(c = S.exec(t))) {
if ((c = _.exec(t)) && o.isType(this.cur, a.paragraph) && !i.isNullOrBlank(this.cur._lines.last())) return f = new o({
type: a.heading,
depth: "=" == c[1] ? 1 : 2,
text: this.cur._lines.pop(),
pattern: "{0}\n" + t,
in: this.nodeMap
}), r.call(this, f), m.call(this), s.call(this, f), void u.call(this, f);
if (t.match(this.remap ? H : $)) {
if (c = (File.option.strictMarkdown ? x : k).exec(t)) return f = new o({
type: a.heading,
depth: c[2].length,
text: c[3],
pattern: (this.skips.enableStartMatch ? c[1].replace(/#$/, "# ") : c[1]) + "{0}" + (c[4] || ""),
in: this.nodeMap
}), r.call(this, f), s.call(this, f), m.call(this), void u.call(this, f);
if (c = I.exec(t)) return f = new o({
type: a.def_footnote,
ref: c[1],
pattern: c[2],
text: c[3],
in: this.nodeMap
}), r.call(this, f), s.call(this, f), m.call(this, !0), void u.call(this, f);
if (c = B.exec(t)) return f = new o({
type: a.def_link,
ref: c[1],
href: c[3],
title: c[7],
in: this.nodeMap,
pattern: "[;]:" + c[2] + ";" + c[4] + (c[5] ? ";" + c[6] : "")
}), r.call(this, f), s.call(this, f), m.call(this, !0), void u.call(this, f);
if (this.skips.fromP) return this.cur || (this.cur = new o({
type: a.paragraph,
in: this.nodeMap
}), this.cur._lines = []), void this.cur._lines.push(t);
if (this.skips.enableStartMatch && (c = O.exec(t))) {
var C = rt(t, !1);
if (C && C.length > 1) return void b.call(this, C)
}
if (c = F.exec(t)) return f = new o({
type: a.blockquote,
in: this.nodeMap,
pattern: c[1]
}), r.call(this, f), f._lines = [c[2]], f._indent = c[1].replace(/[ \u00A0]*>/, "").length, f._lineIndents = [c[1]], m.call(this), void(this.cur = f);
var T = this.remap ? Y : N;
if (this.skips.enableMetaBlock && 0 == this.ln && t.match(T)) {
var j = this.ln + 1,
G = this.lines.length;
if (!(X = this.skips.enableStartMatch || !1))
for (; j < G; j++)
if (this.lines[j].match(T)) {
X = j > this.ln + 1;
break
}
if (X) return f = new o({
type: a.meta_block,
in: this.nodeMap,
text: this.lines.slice(this.ln + 1, j).join("\n")
}), r.call(this, f), this.ln = j, s.call(this, f), m.call(this, !0), void u.call(this, f)
}
if (this.remap) {
if (t.match(W)) {
var K = t.replace(/\u2013/g, "--").replace(/\u2014/g, "---");
if (c = M.exec(K)) return f = new o({
type: a.hr,
pattern: K.trim(),
in: this.nodeMap
}), r.call(this, f), s.call(this, f), m.call(this, !0), void u.call(this, f)
}
} else if (c = M.exec(t)) return f = new o({
type: a.hr,
pattern: t.trim(),
in: this.nodeMap
}), r.call(this, f), s.call(this, f), m.call(this, !0), void u.call(this, f);
if (c = h.ul.exec(t)) return R.exec(this.lines[this.ln + 1] || "") ? (g.call(this, t + "\n" + this.lines[this.ln + 1]), void this.ln++) : (v.call(this, o.ListType.ul, c[2], c[3]), void(d = it[a.list]).onContinue.call(this, t, c[0], c[1].length));
if (c = h.ol.exec(t)) return v.call(this, o.ListType.ol, c[0].replace(/\d+/, "{0}"), c[0].match(/\d+/)[0].replace(/^1$/, "")), void(d = it[a.list]).onContinue.call(this, t, c[0], c[1].length);
if ((c = t.match(A)) && !this.skips.math_block) {
j = this.ln + 1, G = this.lines.length;
var V, Q, X = this.skips.enableStartMatch || !1;
if (V = c[1], !X)
for (; j < G; j++)
if (c = this.lines[j].match(A)) {
Q = c[1], X = !0;
break
}
if (X) return f = new o({
type: a.math_block,
in: this.nodeMap,
tagBefore: V,
tagAfter: Q,
text: this.lines.slice(this.ln + 1, j).join("\n")
}), r.call(this, f), this.ln = j, s.call(this, f), m.call(this, !0), void u.call(this, f)
}
if (c = E.exec(t)) return (f = new o({
type: a.fences,
lang: c[3],
pattern: c[1] + "{0}",
in: this.nodeMap
}))._mark = c[2], f._lines = [], r.call(this, f), m.call(this), void(this.cur = f);
var Z = this.remap ? J : D;
if (t.match(Z)) return void g.call(this);
if (t.match(L)) return void g.call(this, t);
if (p.call(this, !1)) return;
if (File.option.blockHTML && (c = z.exec(t))) {
f = new o({
type: a.html_block,
in: this.nodeMap,
style: (c[1] || "").toLowerCase(),
depth: 0
}), r.call(this, f), m.call(this, !0);
var tt = this.cur || (this.blocks || []).last();
if (tt && o.isType(tt, a.html_block) && 0 === tt.get("tail") && !f.get("ahead")) {
tt !== this.oldNode && tt.detach(), this.blocks.pop(), this.cur = tt, tt._lines = tt.get("text").split(/\n/);
var nt = tt.get("displayStyle") || tt.get("style");
l.HIDDEN_TYPE.indexOf(nt) > -1 && (nt = c[1]), tt.set("displayStyle", nt), tt.unset("tail"), tt.set("style", c[1]), tt.set("depth", 0), f.remove(), f = tt
} else r.call(this, f), this.cur = f, this.cur._lines = [];
return d = it[a.html_block], void(it.html_block.shouldClose.call(this, t) == et.CLOSE_INCLUDE ? (m.call(this, !0), s.call(this, this.cur), this.cur = null) : (this.cur._lines = this.cur._lines || [], this.cur._lines.push(t)))
}
} else if (!this.skips.fromP && p.call(this, !0)) return;
this.cur || (this.cur = new o({
type: a.paragraph,
in: this.nodeMap
}), this.cur._lines = []), o.isType(this.cur, a.paragraph) ? this.cur._lines.push(t) : d && d.onContinue && d.onContinue.call(this, t)
} else o.isType(this.cur, a.code) && d ? d.onContinue && d.onContinue.call(this, t) : o.isType(this.cur, a.paragraph) && (this.cur._lines.last() || "").trim().length ? this.cur._lines.push(t) : (f = new o({
type: a.code,
pattern: c[1],
in: this.nodeMap
}), r.call(this, f), f._lines = [c[2]], m.call(this), this.cur = f)
}
o.parseFrom = function(t, e, n, i) {
n = n || {};
return new o({
type: a.raw_edit,
in: e,
attachTo: n.noTop ? null : e,
text: t
}).parseFrom(n, void 0, i)
}, o.prototype.parseFrom = function(t, e, n) {
if (t = t || {}, o.isType(this.get("parent"), a.table_row)) return this.set("type", a.table_cell), this.set("text", this.safeGetStrAttr("text").replace(/\n|\r/gi, "").replace(/([^\\])\|/gi, "$1|")), [!n && this.toHTML(), [this]];
if (!o.isType(this, a.paragraph, a.raw_edit, a.html_block, a.list_item)) return [!n && this.toHTML(), [this]];
var i = function(t) {
if (o.isType(t, a.list_item) && !t.get("children").length) {
var e = new o({
type: a.paragraph,
text: t.get("text"),
parent: t,
in: t.get("in")
});
return t.set("text", ""), e
}
return null
}(this) || this,
s = t.skips || {};
if (e = e || i.get("text"), File.option.ignoreLineBreak && (e = e.replace(/\u00a0/g, " ")), s.enableMetaBlock = this.get("attachTo") && !this.get("before"), s.old_code = !1 !== s.old_code, this.isBlock(!0)) {
var u = this.get("before"),
c = this.get("after"),
l = new ot(e, null, i.get("in"), i, s).blocks;
return l.length <= 1 ? [!n && this.toHTML(), [this]] : (l[0].set("before", u), l.last().set("after", c), [!n && r.NodeCollectionUtils.toHTML(l), l])
}
};
var st = function(t) {
var e = t.last();
if (e) return e.text || ""
},
ut = {
escape: /^\\([\\`*{}\[\]()#+\-.!_>$|<~"'&])/,
escape2: /^[\uE013\uE014\uE018\uE020]/,
autolink: /^<\uE016?((([^ >]+(@|:)[^ >]+))|(\s*www\.[^ >]+))\uE017?>/,
url: /^\uE016([^\uE017]+)\uE017/i,
comment: /^<!--[\s\S]*?-->/,
citation: /^(?:^|[ ;\[-])\@\w\S+([^\]\s]*)/,
br: /^<w?br[\s/]*>(\s*<\/w?br>)*/i,
tag: /^(?:<([A-Za-z][A-Za-z0-9-]*)(?:\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\s*=\s*(?:[^"'=<>`\x00-\x20]+|'[^']*'|"[^"]*"))?)*\s*(\/?)>|<(\/)([A-Za-z][A-Za-z0-9-]*)\s*[>]|[<][?].*?[?][>]|<![A-Z]+\s+[^>]*>|<!\[CDATA\[[\s\S]*?\]\]>)/,
underline: /^<u>([^\r]*?\S)<\/u>/i,
atag: /^(<a\s.+?>)(.*?)(<\/\s*a>)/i,
imgtag: /^<img(\s+[^<]+)(\/?\s*>([^<]*(<\/img>))?)/i,
link: /^\[((?:\[[^\]]*\]|[^\[\]])*)\]\(<?((?:\([^)]*\)|[^()])*?)>?[ \t]*((['"])(.*?)\4[ \t]*)?\)/,
image: /(^\!\[((?:\[[^\]]*\]|[^\[\]])*)\]\()(<?((?:\([^)]*\)|[^()])*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?)(\)(?:\s*{([^{}\(\)]*)})?)/,
reflink: /^(!?)\[(inside)\]\[([^\]]*)\]/,
strong: /^(\*\*|__)(?=\S)([^\r]*?\S?[*_]?)\1/,
strong_esp: /^\uE031([^\uE031]+)\uE031/,
em1: /^(\_)(?=\S)([^\r]*?[^\s_])\1(?!\1)/,
em2: /^(\*)(?=\S)([^\r]*?[^\s*])(\1{1}|\1{3})(?!\1)/,
highlight: /^(\=\=)(?=\S)([^\r]*?\S)\1/,
code: /^(`+)([\s\S]*?[^`])\1(?!`)/,
del: /^~~(?=\S)([\s\S]*?\S)~~/,
tab: /^[\t]+/,
text: /^(\s|\S)+?[^\n\t\u200B\uE010-\uE020\uE006\\<!\[._*`&{\$\:~\^\="'\-]*/,
footnote: /^\[\^([^\]\n]+)\]/,
attr: /^{( *([#.][-\w_\uE006]+ *|[-\w_\uE006]+=[-\w_"'\uE006]+ *)+)}/,
entity: /^&#?[a-z0-9]+;/i,
emoji: /^(\u200B*):([+\-\w\uE006]+):(\u200B*)/,
inline_math: /^\$(.|\n)*(?:[^\\])\$/,
subscript: /^~(([^\s\n]|(\\\s))+?)~/,
superscript: /^\^(([^\s\n]|(\\\s))+?)\^/,
linebreak: /[ \u00A0]{2}$/,
emptyline: /^(\n)(?:\n|$)/
};
ut.comment_ext = /^<!(--|\u2013|\u2014)[\s\S]*?(--|\u2013|\u2014)>/, ut.citation_ext = /^(?:^|[ ;\[-])(\@|\u0040|\uFE6B|\uFF20|\u0040)\w\S+([^\]\s]*)/, ut.link_ext = /^[\[\u3010]((?:[\[\u3010][^\]\u3011]*[\u3011\]]|[^\[\]\u3010\u3011])*)[\]\u3011]\(<?((?:\([^)]*\)|[^()])*?)>?[ \t]*((["'«»‘’‚‛„‟‹›])(.*?)["'«»‘’‚‛„‟‹›][ \t]*)?\)/, ut.image_ext = /(^\![\[\u3010]((?:[\[\u3010][^\]\u3011]*[\]\u3011]|[^\[\]\u3010\u3011])*)[\]\u3011][\(\uff08])(<?((?:[\(\uff08][^)\uff09]*[\)\uff09]|[^()\uff08\uff09])*?)>?)([\)\uff09](?:\s*{([^{}\(\)\uff08\uff09]*)})?)/, ut.attr_ext = /^{( *([#.][-\w_\uE006]+ *|[-\w_\uE006]+=[-\w_"'«»‘’‚‛„‟‹›\uE006]+ *)+)}/, ut._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/, ut._inside_ext = /(?:[\[\u3010][^\]\u3011]*[\]\u3011]|[^\[\]\u3010\u3011]|[\]\u3011](?=[^\[\u3010]*[\]\u3011]))*/, ut.tag_ext = /^(?:<([A-Za-z][A-Za-z0-9-]*)(?:\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\s*=\s*(?:[^"'=<>`\x00-\x20]+|[’‚‛'‹›][^'’‚‛]*['’‚‛‹›]|["“«»„‟][^"“«»„‟]*["“«»„‟]))?)*\s*(\/?)>|<(\/)([A-Za-z][A-Za-z0-9-]*)\s*[>]|[<][?].*?[?][>]|<![A-Z]+\s+[^>]*>|<!\[CDATA\[[\s\S]*?\]\]>)/, ut.reflink = pt(ut.reflink)("inside", ut._inside)(), ut.normal = bt({}, ut), ut.pedantic = bt({}, ut.normal, {
strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
}), ut.gfm = ut.normal, ut.breaks = bt({}, ut.gfm, {
text: pt(ut.gfm.text)("{2,}", "*")()
});
function ct(t, e, n) {
this.options = t || bt({}, Ct.defaults), this.options.decorate = e || s.decorate, this.options.context = n || this, this.rules = ut.normal, this.options.gfm ? this.options.breaks ? this.rules = ut.breaks : this.rules = ut.gfm : this.options.pedantic && (this.rules = ut.pedantic), File.option.enableHighlight && (this.rules.escape2 = /^[\uE013\uE014\uE015\uE018\uE020]/), File.option.enableSuperscript ? File.option.enableHighlight ? this.rules.escape = /^\\([\\`*{}\[\]()#+\-.!_>$|<~^=])/ : this.rules.escape = /^\\([\\`*{}\[\]()#+\-.!_>$|<~^])/ : File.option.enableHighlight && (this.rules.escape = /^\\([\\`*{}\[\]()#+\-.!_>$|<~=])/)
}
ct.rules = ut;
var lt = {
UNDER_CHAR: "",
MATH_CHAR: "",
DEF_FOOT_PERFIX_CHAR: "",
ESCAPE_SATR: "",
ESCAPE_UNDERLINE: "",
ESCAPE_EQUAL: "",
URL_START: "",
URL_END: "",
ESCAPE_END_SQUARE_BRACKET: "",
NOT_USED: "",
ESCAPE_ESCAPE: "",
ESCAPE_VLINE: "",
ESCAPE_SPACE: ""
},
ft = {
"": "[^",
"": "*",
"": "_",
"": "=",
"": "]",
"": "\\"
},
ht = {
"": "_",
"": "",
"": ""
},
dt = {
"\\\\": lt.ESCAPE_ESCAPE,
"\\*": lt.ESCAPE_SATR,
"\\=": lt.ESCAPE_EQUAL,
"\\_": lt.ESCAPE_UNDERLINE,
"\\]": lt.ESCAPE_END_SQUARE_BRACKET
};
function mt(t) {
return t.replace(/[\uE006-\uE020]/g, function(t) {
return ft[t] ? "\\" + ft[t] : ht[t] || ""
})
}
ct.skipLink = {
autolink: 1,
url: 1,
link: 1,
reflink: 1
};
var vt = function(t) {
for (var e = t.length - 1; e >= 0; e--)
if (t[e].type == a.pants) {
if ("open_double_quote" == t[e].desc) return !0;
if ("close_double_quote" == t[e].desc) return !1
}
return !1
};
ct.prototype.output = function(t, e, n, r, o) {
e = e || this.options.decorate, (r = bt(r || {}, this.options.skipOp)).attr = !1 !== r.attr, r.markLinebreak = !0, File.option.enableInlineMath || (r.inline_math = !0), File.option.enableSubscript || (r.subscript = !0), File.option.enableSuperscript || (r.superscript = !0), File.option.enableHighlight || (r.highlight = !0);
var u, h, d, m, v, p = (o = o || {
cursorDiff: [],
openQuote: null,
hasContent: !1
}).isCur || File.shouldRemapPunctuation(),
g = o.cursorDiff || [],
b = 0,
y = [],
w = this.options,
F = e == s.decorate,
k = w.forPrint;
function x(t, e) {
var n = t.last();
n && n.type === a.plain ? n.text += e : t.push({
type: a.plain,
text: e
})
}
function _(t, e, n) {
for (var i = 1, r = e; r < t.length; r++)
if (t[r].name == n && (t[r].pos < 0 && i--, t[r].pos > 0 && i++, !i)) return r;
return 0
}
function $(t) {
for (var n = "", i = 0; i < t.length; i++) {
var r = t[i];
r.name = r.name || "";
var s = l.INLINE_TYPE.indexOf(r.name.toLowerCase()) > -1,
u = l.HIDDEN_TYPE.indexOf(r.name.toLowerCase()) > -1,
c = k && l.UNSFAE_TAGS.indexOf(r.name.toLowerCase()) > -1;
if ((F && (s || u) || c) && r.type == a.tag && r.pos > 0 && r.name) {
var f = r.name || "",
h = _(t, i + 1, f);
if (h > 0) {
n += e({
type: a.html_inline,
inner: $(t.subarray(i + 1, h)),
name: f.toLowerCase(),
before: r.text,
after: t[h].text,
isMeta: !s
}, w, o), i = h;
continue
}
}
n += e(r, w, o)
}
return n
}
for (t.length > 1e5 && (n = !0, x(y, t), t = ""), n || (t = function(t, e) {
for (var n, i = /([a-z0-9])_([a-z0-9])/gi; n = i.exec(t);) t = t.substring(0, n.index + 1) + lt.UNDER_CHAR + t.substring(n.index + 2), i.lastIndex && i.lastIndex--;
return t = t.replace(/\\[\*_=\]\\]/gi, function(t) {
return dt[t] || t
}), e && t.length < 2e4 && (t = t.replace(/((?:(https?:\/\/([a-z0-9]|\/|\.\.\/|([-@+.,!\/~?%&=:#\uE006_](?![\s.~*-,_]|$)))+)|((mailto:\/{0,2})?[a-z0-9][a-z0-9\-_+\.\uE006]*(@)[a-z0-9](?:[a-z0-9\-_\uE006]{0,15}\.?){0,2}\.(com|co|net|org|edu|io|tv|fm|me|info|cc|ca|de|cn|ru))|(www\.[a-z0-9][a-z0-9\-_\uE006]*(\.[a-z0-9\-_\uE006]+)+\/?(\/|\.\.\/|[a-z0-9]|([-@+.,!\/~?%&=:#\uE006_](?![\s.~*-,_]|$)))*)))/gi, lt.URL_START + "$1" + lt.URL_END)), t
}(t, !r.url)); t;)
if (r.markLinebreak && (d = /^\r?\n/.exec(t))) b += d[0].length, t = t.substring(d[0].length), y.push({
type: t || r.emptyline ? a.softbreak : a.emptyline,
text: "\n",
inner: "\n"
});
else if (d = this.rules.escape2.exec(t)) b += d[0].length, t = t.substring(d[0].length), y.push({
type: a.escape,
text: ft[d[0]]
}), o.hasContent = !0;
else if (d = this.rules.escape.exec(t)) b += d[0].length, t = t.substring(d[0].length), y.push({
type: a.escape,
text: d[1]
}), o.hasContent = !0;
else if (r.autolink || !(d = this.rules.autolink.exec(t)))
if (r.url || !(d = this.rules.url.exec(t)))
if (d = (p ? this.rules.comment_ext : this.rules.comment).exec(t)) b += d[0].length, t = t.substring(d[0].length), u = d[0], p && (u = u.replace(/[\u2013\u2014]/g, "--"), g[b] = u.length - d[0].length), y.push({
type: r.comment ? a.tag : a.comment,
text: u
});
else if (d = this.rules.br.exec(t)) b += d[0].length, t = t.substring(d[0].length), y.push({
type: "br",
text: d[0]
});
else if (r.autolink || !(d = this.rules.autolink.exec(t)))
if (r.url || !(d = this.rules.url.exec(t)))
if (d = (p ? this.rules.citation_ext : this.rules.citation).exec(t)) b += d[0].length, t = t.substring(d[0].length), u = d[0], p && (u = u.replace(/[\u2013\u2014]/g, "--"), g[b] = u.length - d[0].length), y.push({
type: r.citation ? a.tag : a.citation,
text: u
});
else if (d = this.rules.br.exec(t)) b += d[0].length, t = t.substring(d[0].length), y.push({
type: "br",
text: d[0]
});
else if (d = (File.shouldRemapPunctuation() ? this.rules.tag_ext : this.rules.tag).exec(t)) {
var E;
if (!r.underline && (E = this.rules.underline.exec(t))) {
b += E[0].length, t = t.substring(E[0].length), y.push({
type: a.underline,
inner: this.output(mt(E[1]), e, !0, r),
text: E[0]
}), o.hasContent = !0;
continue
}
if (!r.imgtag && (E = this.rules.imgtag.exec(t))) {
var C = E[0];
p && (C = C.replace(/(\w=)[«»“”„‟〝〟]/g, '$1"').replace(/(\w=)[‚‘’‛‹›]/g, "$1'").replace(/[»«”“〞]([\s\/>]|$)/g, '"$1').replace(/[’‛‘›‹']([\s\/>]|$)/g, "'$1"));
var A = (/src\s*=\s*(['"])((.|\n)*?)\1/.exec(C) || [])[2];
if (A || (A = (/src\s*=\s*([^\s'"]+)(\s|$)/.exec(C) || [])[1]), A) {
b += E[0].length, t = t.substring(E[0].length);
var S = (/\sstyle=(['"])(.+?)\1/.exec(C) || [])[2] || "",
T = (/(^|[^\w-])width\s*:\s*(.+?)(\s*;|$)/.exec(S) || [])[2],
M = (/(^|[^\w-])height*:\s*(.+?)(\s*;|$)/.exec(S) || [])[2],
D = (/(^|[^\w-])zoom*:\s*(.+?)(\s*;|$)/.exec(S) || [])[2];
T || (T = (/\swidth=(['"])(.+?)\1/.exec(C) || /\swidth=((.+?))[\s/>]/.exec(C) || [])[2], /\d\s*$/.exec(T || "") && (T += "px;")), M || (M = (/\sheight=(['"])(.+?)\1/.exec(C) || /\sheight=((.+?))[\s/>]/.exec(C) || [])[2], /\d\s*$/.exec(M || "") && (T += "px;")), y.push({
type: a.imgtag,
text: C,
href: mt(A),
width: T,
height: M,
zoom: D
})
} else b += d[0].length, t = t.substring(d[0].length), u = d[0].replace(/(\w=)[«»“”„‟〝〟]/g, '$1"').replace(/(\w=)[‚‘’‛‹›]/g, "$1'").replace(/[»«”“〞]([\s\/>]|$)/g, '"$1').replace(/[’‛‘›‹']([\s\/>]|$)/g, "'$1"), y.push({
type: a.tag,
text: mt(u)
});
o.hasContent = !0;
continue
}
if (b += d[0].length, t = t.substring(d[0].length), u = d[0].replace(/(\w=)[«»“”„‟〝〟]/g, '$1"').replace(/(\w=)[‚‘’‛‹›]/g, "$1'").replace(/[»«”“〞]([\s\/>]|$)/g, '"$1').replace(/[’‛‘›‹']([\s\/>]|$)/g, "'$1"), "ruby" == (v = {
type: a.tag,
pos: d[1] || d[4] ? d[3] ? -1 : d[2] ? 0 : 1 : 0,
name: (d[1] || d[4] || "").toLowerCase()
}).name && v.pos > 0 && F && (d = /<\/ruby>/.exec(t))) {
var L = d.index + d[0].length;
b += L, u += t.substring(0, L), t = t.substring(L), v = {
type: a.ruby,
text: mt(u)
}
} else v.text = mt(u);
y.push(v), o.hasContent = o.hasContent || -1 == l.NO_TEXT_BLOCK_TYPE.indexOf(v.name)
} else {
if (o.hasContent = !0, !r.link && (d = (p ? this.rules.link_ext : this.rules.link).exec(t))) {
var R = d[0];
if (m = d[0].length, p && (R = R.replace(/[‘’‚‛‹›]/g, "'").replace(/[«»“”„‟]/g, '"').replace(/\u3010/g, "[").replace(/\u3011/g, "]"), R = "[" + d[1] + "]" + R.substring(d[1].length + 2), d = this.rules.link.exec(R)), d) {
b += m, t = t.substring(m), y.push({
type: "link",
href: mt(d[2]),
title: d[5],
markdown: R,
text: d[1] || "",
inner: d[1] ? this.output(d[1], e, !0, ct.skipLink, o) : "",
meta: mt(R.substring(d[1].length + 2))
});
continue
}
}
if (!r.image) {
if (!p && (d = this.rules.image.exec(t))) {
b += d[0].length, t = t.substring(d[0].length), y.push({
type: "image",
href: mt(d[4]),
title: d[5],
markdown: d[0],
components: [d[1], d[3], d[8]],
alt: d[2],
onlychild: !t && !y.length
});
continue
}
if (p && (d = this.rules.image_ext.exec(t))) {
m = d[0].length;
var B = d[0].replace(/\u3010/g, "[").replace(/\u3011/g, "]").replace(/\uff08/g, "(").replace(/\uff09/g, ")").replace(/[«»“”„‟]/g, '"').replace(/[‘’‚‛‹›]/g, "'");
if (d = this.rules.image.exec(B)) {
b += m, t = t.substring(m), y.push({
type: "image",
href: mt(d[4]),
title: d[5],
markdown: d[0],
components: [d[1], d[3], d[8]],
alt: d[2],
onlychild: !t && !y.length
});
continue
}
}
}
if (!r.footnote && b && (d = this.rules.footnote.exec(t))) {
b += d[0].length, t = t.substring(d[0].length);
var I = (d[2] || d[1]).replace(/\s+/g, " ");
y.push({
type: a.footnote,
inner: this.output(d[1], e, !0, ct.skipLink),
text: mt(d[1])
})
} else if (!(d = this.rules.reflink.exec(t)) || r.reflink && !d[1])
if (r.attr || !(d = (p ? this.rules.attr_ext : this.rules.attr).exec(t)))
if (d = this.rules.strong.exec(t)) b += d[0].length, t = t.substring(d[0].length), y.push({
type: a.strong,
pattern: d[1],
inner: this.output(d[2], e, !0, r, o),
text: d[2]
});
else if (d = this.rules.em1.exec(t)) b += d[0].length, t = t.substring(d[0].length), y.push({
type: a.em,
pattern: d[1],
inner: this.output(d[2], e, !0),
text: d[2]
});
else if (d = this.rules.em2.exec(t)) {
var N = (d[2] + d[3].substring(1, 3)).match(/\s\*(?!\*)/);
if (N) {
b += N.index + 1, t = t.substring(N.index + 1), x(y, d[0].substr(0, N.index + 1));
continue
}
if ("***" === d[3] && !d[2].match(/\*\*/)) {
b += d[0].length - 2, t = t.substring(d[0].length - 2), y.push({
type: a.em,
pattern: d[1],
inner: this.output(d[2], e, !0),
text: d[2]
});
continue
}
b += d[0].length, t = t.substring(d[0].length), y.push({
type: a.em,
pattern: d[1],
inner: this.output(d[2] + d[3].substring(1, 3), e, !0),
text: d[2] + d[3].substring(1, 3)
})
} else if (d = this.rules.code.exec(t)) b += d[0].length, t = t.substring(d[0].length), y.push({
type: a.code,
pattern: d[1],
text: d[2]
});
else if (d = this.rules.del.exec(t)) b += d[0].length, t = t.substring(d[0].length), y.push({
type: a.del,
pattern: "~~",
inner: this.output(d[1], e, !0),
text: d[1]
});
else if ((d = this.rules.emoji.exec(t)) && c.data[d[2] = d[2].replace(/\uE006/g, "_")]) t = t.substring(d[0].length), y.push({
type: a.emoji,
text: d[2],
inner: c.data[d[2]]
}), !d[1].length && (g[b] = 1), b += d[0].length, !d[3].length && (g[b] = 1);
else {
if (!r.subscript && (d = this.rules.subscript.exec(t))) {
b += d[0].length, t = t.substring(d[0].length);
var O = [];
(d = d[1].split(/\\\s/g))[0] && O.push({
type: a.plain,
text: d[0]
});
for (var j = 1; j < d.length; j++) O.push({
type: a.escape,
text: " "
}), d[j] && O.push({
type: a.plain,
text: d[j]
});
y.push({
type: a.subscript,
inner: $(O),
text: d[0]
})
}
if (!r.superscript && (d = this.rules.superscript.exec(t))) {
b += d[0].length, t = t.substring(d[0].length);
O = [];
(d = d[1].split(/\\\s/g))[0] && O.push({
type: a.plain,
text: d[0]
});
for (j = 1; j < d.length; j++) O.push({
type: a.escape,
text: " "
}), d[j] && O.push({
type: a.plain,
text: d[j]
});
y.push({
type: a.superscript,
inner: $(O),
text: d[0]
})
}
if (r.inline_math || !(d = this.rules.inline_math.exec(t)))
if (r.highlight || !(d = this.rules.highlight.exec(t)))
if (d = this.rules.entity.exec(t)) b += d[0].length, t = t.substring(d[0].length), i.decodeHtmlEntity(d[0]) ? y.push({
type: a.html_entity,
inner: d[0],
text: d[0]
}) : x(y, d[0] || "");
else {
if (File.option.convertSmartOnRender && File.option.smartDash) {
if (d = /^(---)($|[^-])/.exec(t)) {
b += d[1].length, t = t.substring(d[1].length), y.push({
type: a.pants,
inner: "—",
desc: "em_dash",
meta: "--",
text: "---"
});
continue
}
if (d = /^--/.exec(t)) {
t = t.substring(d[0].length), b += d[0].length, y.push({
type: a.pants,
inner: "–",
desc: "en_dash",
meta: "-",
text: "--"
});
continue
}
if (d = /^\.{3}/.exec(t)) {
b += d[0].length, "." !== (t = t.substring(d[0].length))[4] ? y.push({
type: a.pants,
inner: "…",
desc: "ellipsis",
meta: "..",
text: "..."
}) : x(y, d[0]);
continue
}
}
if (File.option.convertSmartOnRender && File.option.smartQuote) {
var P, q;
if ('"' == t[0]) {
if (q = (P = st(y) || "")[P.length - 1] || "", /(^|[\(\{\[\s\-/\u2018])$/.exec(P) || q == f.userQuote(2)) {
b++, t = t.substring(1), y.push({
type: a.pants,
inner: f.userQuote(0),
desc: "open_double_quote",
text: '"'
});
continue
}
if (d = /^"($|[\)\s/.,;:?!\u2019])/.exec(t)) {
b++, t = t.substring(1), y.push({
type: a.pants,
inner: f.userQuote(1),
desc: "close_double_quote",
text: '"'
});
continue
}
if (vt(y)) {
b++, t = t.substring(1), y.push({
type: a.pants,
inner: f.userQuote(1),
desc: "close_double_quote",
text: '"'
});
continue
}
b++, t = t.substring(1), y.push({
type: a.pants,
inner: f.userQuote(0),
desc: "open_double_quote",
text: '"'
});
continue
}
if ("'" == t[0]) {
if (o.openQuote && (d = /^'($|[\)\s".,;:?!-])/.exec(t))) {
b++, t = t.substring(1), y.push({
type: a.pants,
inner: f.userQuote(3),
desc: "close_single",
text: "'"
}), o.openQuote.inner = f.userQuote(2), o.openQuote.desc = "open_single", o.openQuote = null;
continue
}
if (P = st(y) || "", t.length <= 1 && /((^|[\s])$)/.exec(P)) {
b += t.length, x(y, t), t = "";
continue
}
b++, t = t.substring(1), y.push({
type: a.pants,
inner: "’" == f.userQuote(3) ? "’" : "'",
desc: "close_single",
text: "'"
}), /(^|[\(\s"-])$/.exec(P) && (o.openQuote = y.last());
continue
}
}
if (d = this.rules.tab.exec(t)) b += d[0].length, t = t.substring(d[0].length), y.push({
type: a.tab,
inner: d[0],
text: d[0]
});
else if (d = this.rules.text.exec(t)) b += d[0].length, "\n" == (t = t.substring(d[0].length))[0] && this.rules.linebreak.exec(d[0] || "") ? (b++, t = t.substring(1), x(y, d[0].replace(this.rules.linebreak, "")), y.push({
type: a.linebreak,
text: " \n",
isLast: !t
})) : x(y, d[0] || "");
else if (t) throw new Error("Infinite loop on byte: " + t.charCodeAt(0))
}
else b += d[0].length, t = t.substring(d[0].length), y.push({
type: a.highlight,
inner: this.output(d[2], e, !0),
text: d[2]
});
else {
var U = null,
z = 0,
H = "",
W = null,
J = /\$/,
Y = "$";
for (/^\$\$/.exec(d[0]) ? (U = /{|}|\$\$/g, Y = "$$") : (U = /{|}|\$/g, Y = "$"), U.exec(d[0]); W = U.exec(d[0]);) {
if (J.exec(W[0]) && z <= 0 && "\\" != d[0].substring(W.index - 1, W.index)) {
H = d[0].substring(0, W.index + W[0].length);
break
}
"{" === W[0] ? "\\" === W.input[W.index - 1] && "\\" !== !W.input[W.index - 2] || z++ : "}" === W[0] && ("\\" === W.input[W.index - 1] && "\\" !== !W.input[W.index - 2] || z--)
}
var G = Y.length;
if (H.length - 2 * G > 0 && /[^\s$]/.exec(H)) {
var K = H.indexOf("​");
K > -1 && (g[b + K] = -1), b += H.length, t = t.substring(H.length), y.push({
type: "inline_math",
text: mt(H.substring(G, H.length - G)),
pattern: Y
});
continue
}
b += d[0].length, t = t.substring(d[0].length), x(y, d[0] || "")
}
} else {
b += d[0].length, t = t.substring(d[0].length);
var V = d[0];
p && (V = V.replace(/[‘’‚‛‹›]/g, "'").replace(/[«»“”„‟]/g, '"')), y.push({
type: a.attr,
text: d[0]
})
} else {
b += d[0].length, t = t.substring(d[0].length);
I = (d[3] || "").replace(/\s+/g, " ");
y.push({
type: d[1] ? "refimg" : "reflink",
ref: mt(I),
inner: this.output(d[2], e, !0, ct.skipLink),
text: mt(d[2]),
markdown: d[0],
onlychild: !t && !y.length
})
}
} else t = t.substring(d[0].length), b += d[1].length, h = u = d[1], null === /^\w+:\/\//.exec(u) && /@/.exec(u) && (h = "mailto:" + h), y.push({
type: a.url,
href: mt(h),
text: u
}), o.hasContent = !0;
else b += d[0].length, t = t.substring(d[0].length), "", u = d[1], h = "@" === d[4] ? ":" === d[1].charAt(6) ? u : "mailto:" + d[1] : u, y.push({
type: a.autolink,
href: mt(h),
text: u
}), o.hasContent = !0;
var Q = $(y);
return n || (Q = mt(Q)), Q
}, ct.prototype.mangle = function(t) {
for (var e, n = "", i = t.length, r = 0; r < i; r++) e = t.charCodeAt(r), Math.random() > .5 && (e = "x" + e.toString(16)), n += "&#" + e + ";";
return n
};
function pt(t, e) {
return t = t.source, e = e || "",
function n(i, r) {
return i ? (r = (r = r.source || r).replace(/(^|[^\[])\^/g, "$1"), t = t.replace(i, r), n) : new RegExp(t, e)
}
}
function gt() {}
gt.exec = gt;
function bt(t) {
for (var e, n, i = 1; i < arguments.length; i++) {
e = arguments[i];
for (n in e) Object.prototype.hasOwnProperty.call(e, n) && (t[n] = e[n])
}
return t
}
var yt = /^( *)[*+-][ \t\u00A0]+(\[(x|X)\]|\[ \]) +/,
wt = /^( *)[*+-][ \t\u00A0]+/,
Ft = /^( *)\d+\.[ \t\u00A0]+/,
kt = function() {
return File.shouldRemapPunctuation() ? /^ *[>〉》][^\n]+/ : /^ *>[^\n]+/
};
var xt = /^( *#{1,6}\s*)([^\n]+?)(\s+#+ *)*$/m,
_t = /^( *#{1,6}\s+)([^\n]+?)(\s+#+ *)*$/m;
function $t(t, e, n, i, r, s) {
var u = [],
c = "",
l = l || {
cursorDiff: r
};
i && i.cid == File.editor.focusCid && (l.isCur = !0);
function f(t, n, r) {
var s = [];
return s[0] = t.substr(0, n.index), s[1] = t.substr(n.index, n[0].length), s[2] = t.substr(n.index + n[0].length), s.map(function(t, n) {
return 1 == n ? e.options.decorate(r) : t ? e.options.decorate({
type: a.paragraph,
inner: e.output(t, null, null, {
attr: !o.isType(i, a.heading),
emptyline: 2 != n
}, l)
}) : ""
}).join("")
}
for (; t;) {
if (!n && /^\s*[-+*_<\[\{|#0-9`~=>$]/m.exec(t)) {
if (u = /^ *>[^\n]+/m.exec(t)) {
c = f(t, u, {
type: a.blockquote,
pattern: u[0].match(/^( *> ?)+/gm)[0],
inner: $t(u[0].replace(/^( *> ?)+/gm, ""), e, !0, i, r)
});
break
}
if (u = (File.option.strictMarkdown ? _t : xt).exec(t)) {
var h = "h" + u[0].match(/#/g).length;
s.push(h), c = f(t, u, {
type: a.heading,
meta_before: u[0].substring(0, u[1].length),
meta_after: u[3] || "",
mdlike: h,
inner: e.output(u[2], null, null, {
attr: !1
}, l)
});
break
}
if (u = /^( *(`{3,}|~{3,}|·{3,})[ \t\u00A0]*)([^\n`]+)? *$/m.exec(t)) {
c = f(t, u, {
type: a.fences,
lang: u[3],
pattern: u[1]
});
break
}
if (u = /^\s*\[\^([^\]\n]+)\]:(\s*)([^\n]*)$/m.exec(t)) {
c = f(t, u, {
type: a.def_footnote,
ref: u[1],
pattern: u[2],
inner: e.output(u[3] || "", null, null, null, l)
});
break
}
if (u = /^\s*\[([^\]\n]+)\]:(\s*)([^\n]*)/m.exec(t)) {
c = f(t, u, {
type: a.def_link,
ref: u[1],
pattern: u[2],
inner: e.output(u[3] || "", null, null, null, l)
});
break
}
if (u = /^(\s*)(([-+*]|\d+\.)\s+)/m.exec(t)) {
c = f(t, u, {
type: "block",
inner: e.output(u[0] || "", null, null, null, l)
});
break
}
if (u = /^\s*(\$\$|\[toc\])\s*$/im.exec(t)) {
c = f(t, u, {
type: "block",
inner: e.output(u[0] || "", null, null, null, l)
});
break
}
if (u = /^\s*([-+_*])\s*\1\s*\1(\s|\1)*$/m.exec(t)) {
c = f(t, u, {
type: "block",
inner: e.output(u[0] || "", null, null, null, l)
});
break
}
if (u = /^ *\|([^\|]+\|.+)\|\s*$/m.exec(t)) {
c = f(t, u, {
type: "block",
inner: e.output(u[0] || "", null, null, null, l)
});
break
}
}
c = e.options.decorate({
type: a.paragraph,
inner: e.output(t, null, null, {
attr: !o.isType(i, a.heading)
}, l)
});
break
}
return c
}
var Et, Ct = {};
Ct.options = Ct.setOptions = function(t) {
return bt(Ct.defaults, t), Ct
}, Ct.defaults = {
gfm: !0,
tables: !0,
breaks: !1,
pedantic: !1,
sanitize: !1,
smartLists: !1,
silent: !1,
highlight: null,
langPrefix: "lang-",
smartypants: !1,
headerPrefix: ""
}, Ct.parseInline = function(t, e, n) {
return Et || (Et = new ct), Et.output(t, null, null, e, {
cursorDiff: n
})
}, Ct.parsePandocAttr = function(t) {
var e = {};
return t && "{" == t[0] && "}" == t[t.length - 1] ? (((t = t.replace(/(^{)|(}$)/g, "")).split(/\s+/) || [t]).forEach(function(t) {
var n;
(n = /^#(.+)/.exec(t)) ? e.id = i.escapeInQuote(n[1]): (n = /^\.(.+)/.exec(t)) ? e.class = (e.class || "") + " " + i.escapeInQuote(n[1]) : (n = /^(.+)=(['"])([^'"]+)\2/.exec(t)) && (e.attr = (e.attr || "") + " " + t, e.nativeAttr = e.nativeAttr || {}, e.nativeAttr[n[1]] = n[3])
}), e) : e
}, Ct.attrToString = function(t) {
var e = "";
return t.id && (e += " id='" + t.id + "'"), t.class && (e += " class='" + t.class.trim() + "'"), t.attr && (e += t.attr), e
}, Ct.InlineLexer = ct, Ct.quickParse = function t(e, n, r, s, c, l) {
var f, h = 0,
d = r,
m = [];
c = c || !s && u.makeEmptyCommand();
function v(t, e, n) {
return new o({
type: n || a.paragraph,
text: t,
parent: e,
in: e.get("in")
})
}
function p(t, i, r, s) {
r.cid == n.editor.focusCid && n.editor.store(), i.undo.push(u.buildReplaceUndo(r));
var c = null;
return s && s.start ? (h = h - s.start + t.length, c = r.insert(new o({
type: a.paragraph,
text: e.substring(0, s.start - 1)
}), !0), u.addUndoForInsert(i, c)) : h += t.length, e = e.substring((s ? s.start : 0) + t.length), c
}
function g(i, r, o, a, s) {
return a = a || t(e, n, i, !1, r, l), r.redo.push(u.buildReplaceUndo(o)), {
html: (s ? s.toHTML() : "") + o.toHTML(a.html),
offset: h + a.offset,
focus: a.focus,
blockChanged: !0,
command: r,
splits: void 0
}
}
function b(i, s, c, l) {
var f, h, m, b = File.option.indentSize,
y = p(i = i.replace("【", "[").replace("】", "]"), s, r, l);
if (r.set("type", a.list), r.set("text", ""), r.set("style", c), (h = v("", r, a.list_item)).set("checked", null != /x|X/g.exec(l.line)), i.indexOf("[") > -1 && h.set("style", o.ListType.task), c == o.ListType.ul && (File.option.prettyIndent ? r.set("pattern", i.replace(/\[[xX\s]\]\s+/, "").trim() + " ".repeat(b - 1)) : r.set("pattern", i.replace(/\[[xX\s]\]\s+/, "").trim() + " ")), c == o.ListType.ol) {
var w = i.match(/\d+/)[0].replace(/^1$/, "");
"" != w ? r.set("start", w) : r.unset("start")
}
if (i && File.option.autoPairExtendSymbol && /\*\s$/.exec(i) && (e = e.replace(/^\*/, "")), d = v(e, h, a.paragraph), (m = t(e, n, d, !1)).html = h.toHTML(m.html), f = g(null, s, r, m, y), !y) return f;
var F = (r = f.splits && f.splits[1] || r).get("before"),
k = r.get("after");
return f.splits && !f.splits[0] && o.isType(F, a.list) && F.get("style") == r.get("style") && (f.replaceCid = F.cid, f.toRemove = [r.cid], s.undo.push(u.buildReplaceUndo(F)), u.addUndoForRemove(s, r), F.appendTillEnd(r.getFirstChild()), F.getFirstChild().unset("tail"), F.getFirstChild().getLastChild().unset("tail"), r.remove(), o.isType(k, a.list) && k.get("style") == k.get("style") && (f.toRemove.push(k.cid), u.addUndoForRemove(s, k), F.appendTillEnd(k.getFirstChild()), F.getFirstChild().unset("tail"), F.getFirstChild().getLastChild().unset("tail"), k.remove()), s.redo.push(u.buildReplaceUndo(F)), f.html = F.toHTML(), f.splits[2] && (f.html += f.splits[2].toHTML())), f
}
if (File.option.strictMarkdown && (yt = File.shouldRemapPunctuation() ? /^( {0,3})[*+-][ \t\u00A0]+([\[【](x|X)[\]】]|[\[【] [\]】]) +/ : /^( {0,3})[*+-][ \t\u00A0]+(\[(x|X)\]|\[ \]) +/, wt = /^( {0,3})[*+-][ \t\u00A0]+/, Ft = /^( {0,3})\d+\.[ \t\u00A0]+/), l && void 0 === l.endId && (l.endId = l.id), l && void 0 === l.startId && (l.startId = l.id), !(s = s || !l || l.endId != r.cid)) {
var y = i.findLine(e, l.end);
if (kt().exec(y.line)) return function(t, n) {
var i = p(n.line.match(/^ *[>〉》][ \u00A0]?/)[0], t, r, n);
return r.set("type", a.blockquote), r.set("text", ""), d = v(e, r), t.redo.push(u.buildReplaceUndo(r)), g(d, t, r, void 0, i)
}(c, y);
if (f = yt.exec(y.line)) return b(f[0], c, o.ListType.ul, y);
if (f = wt.exec(y.line)) return b(f[0], c, o.ListType.ul, y);
if (f = Ft.exec(y.line)) return b(f[0], c, o.ListType.ol, y);
if (f = function(t, e) {
var n = t.get("parent");
return o.isType(t, a.paragraph) && !t.get("before") && o.isType(n, a.list_item) && n.get("style") !== o.ListType.task && n.get("parent").get("style") == o.ListType.ul && (File.shouldRemapPunctuation() ? /(^ *[\[【](x|X)[\]】]( |\t)+)|((^ *[\[【] [\]】]) +)/g : /(^ *\[(x|X)\]( |\t)+)|((^ *\[ \]) +)/g).exec(e)
}(r, e)) return function(i, a) {
var s, u, c = r.get("parent");
return p(i, a, c), c.set("style", o.ListType.task), c.set("checked", null != /x|X/g.exec(i)), r.set("text", e), (u = t(e, n, d = r, !0, a)).html = void 0, (s = g(null, a, c, u)).replaceCid = c.cid, s
}(f[0], c)
}
var w = [],
F = {
innerHtml: $t(e, n.inline, o.isType(r, a.heading), r, m, w),
offset: 0,
focus: r.cid,
blockChanged: !1,
command: c,
cursorDiff: m,
mdlike: w[0]
};
return F.html = r && r.toHTML(F.innerHtml, w[0]), F
}, Ct.reDefLink = B, Ct.reDefFootnote = I, Ct.renderHtmlWithBlockMeta = function t(e, n) {
if (o.isType(e, a.paragraph)) {
var i = [],
r = $t(e.safeGetStrAttr("text"), n.inline, !1, e, [], i);
return e.toHTML(r, i[0])
}
if (e.get("children").length) {
for (var s = e.getFirstChild(), u = []; s;) u.push(t(s, n)), s = s.get("after");
return e.toHTML(u.join(""))
}
return e.toHTML()
}, Ct.splitTableCell = rt, Ct.recoverEscape = mt, n.exports = Ct
}), $__System.registerDynamic("1c", [], !0, function(t, e, n) {
"use strict";
this || self;
var i = function(t) {
var e = "object",
n = "function",
i = "undefined",
r = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed", "commonAncestorContainer"],
o = ["setStart", "setStartBefore", "setStartAfter", "setEnd", "setEndBefore", "setEndAfter", "collapse", "selectNode", "selectNodeContents", "compareBoundaryPoints", "deleteContents", "extractContents", "cloneContents", "insertNode", "surroundContents", "cloneRange", "toString", "detach"],
a = ["boundingHeight", "boundingLeft", "boundingTop", "boundingWidth", "htmlText", "text"],
s = ["collapse", "compareEndPoints", "duplicate", "moveToElementText", "parentElement", "select", "setEndPoint", "getBoundingClientRect"];
function u(t, i) {
var r = typeof t[i];
return r == n || !(r != e || !t[i]) || "unknown" == r
}
function c(t, n) {
return !(typeof t[n] != e || !t[n])
}
function l(t, e) {
return typeof t[e] != i
}
function f(t) {
return function(e, n) {
for (var i = n.length; i--;)
if (!t(e, n[i])) return !1;
return !0
}
}
var h = f(u),
d = f(c),
m = f(l);
function v(t) {
return t && h(t, s) && m(t, a)
}
function p(t) {
return c(t, "body") ? t.body : t.getElementsByTagName("body")[0]
}
var g = {},
b = {
version: "1.3alpha.20140716",
initialized: !1,
supported: !0,
util: {
isHostMethod: u,
isHostObject: c,
isHostProperty: l,
areHostMethods: h,
areHostObjects: d,
areHostProperties: m,
isTextRange: v,
getBody: p
},
features: {},
modules: g,
config: {
alertOnFail: !0,
alertOnWarn: !1,
preferTextRange: !1
}
};
function y(t) {
c(window, "console") && u(window.console, "log") && window.console.log(t)
}
function w(t, e) {
e ? window.alert(t) : y(t)
}
function F(t) {
b.initialized = !0, b.supported = !1, w("Rangy is not supported on this page in your browser. Reason: " + t, b.config.alertOnFail)
}
b.fail = F;
b.warn = function(t) {
w("Rangy warning: " + t, b.config.alertOnWarn)
}, !{}.hasOwnProperty ? F("hasOwnProperty not supported") : b.util.extend = function(t, e, n) {
var i, r;
for (var o in e) e.hasOwnProperty(o) && (i = t[o], r = e[o], n && null !== i && "object" == typeof i && null !== r && "object" == typeof r && b.util.extend(i, r, !0), t[o] = r);
return e.hasOwnProperty("toString") && (t.toString = e.toString), t
},
function() {
var t = document.createElement("div");
t.appendChild(document.createElement("span"));
var e, n = [].slice;
try {
1 == n.call(t.childNodes, 0)[0].nodeType && (e = function(t) {
return n.call(t, 0)
})
} catch (t) {}
e || (e = function(t) {
for (var e = [], n = 0, i = t.length; n < i; ++n) e[n] = t[n];
return e
}), b.util.toArray = e
}();
var k;
u(document, "addEventListener") ? k = function(t, e, n) {
t.addEventListener(e, n, !1)
} : u(document, "attachEvent") ? k = function(t, e, n) {
t.attachEvent("on" + e, n)
} : F("Document does not have required addEventListener or attachEvent method"), b.util.addListener = k;
var x = [];
function _(t) {
return t.message || t.description || String(t)
}
function $() {
if (!b.initialized) {
var t, e = !1,
n = !1;
u(document, "createRange") && (t = document.createRange(), h(t, o) && m(t, r) && (e = !0));
var i = p(document);
if (i && "body" == i.nodeName.toLowerCase())
if (i && u(i, "createTextRange") && v(t = i.createTextRange()) && (n = !0), e || n) {
b.initialized = !0, b.features = {
implementsDomRange: e,
implementsTextRange: n
};
var a;
for (var s in g)(a = g[s]) instanceof C && a.init(a, b);
for (var c = 0, l = x.length; c < l; ++c) try {
x[c](b)
} catch (t) {
y("Rangy init listener threw an exception. Continuing. Detail: " + _(t))
}
} else F("Neither Range nor TextRange are available");
else F("No body element found")
}
}
b.init = $, b.addInitListener = function(t) {
b.initialized ? t(b) : x.push(t)
};
var E = [];
b.addCreateMissingNativeApiListener = function(t) {
E.push(t)
};
b.createMissingNativeApi = function(t) {
t = t || window, $();
for (var e = 0, n = E.length; e < n; ++e) E[e](t)
};
function C(t, e, n) {
this.name = t, this.dependencies = e, this.initialized = !1, this.supported = !1, this.initializer = n
}
C.prototype = {
init: function(t) {
for (var e, n, i = this.dependencies || [], r = 0, o = i.length; r < o; ++r) {
if (n = i[r], !((e = g[n]) && e instanceof C)) throw new Error("required module '" + n + "' not found");
if (e.init(), !e.supported) throw new Error("required module '" + n + "' not supported")
}
this.initializer(this)
},
fail: function(t) {
throw this.initialized = !0, this.supported = !1, new Error("Module '" + this.name + "' failed to load: " + t)
},
warn: function(t) {
b.warn("Module " + this.name + ": " + t)
},
deprecationNotice: function(t, e) {
b.warn("DEPRECATED: " + t + " in module " + this.name + "is deprecated. Please use " + e + " instead")
},
createError: function(t) {
return new Error("Error in Rangy " + this.name + " module: " + t)
}
};
function A(t, e, n, i) {
var r = new C(e, n, function(t) {
if (!t.initialized) {
t.initialized = !0;
try {
i(b, t), t.supported = !0
} catch (t) {
y("Module '" + e + "' failed to load: " + _(t))
}
}
});
g[e] = r
}
b.createModule = function(t) {
var e, n;
2 == arguments.length ? (e = arguments[1], n = []) : (e = arguments[2], n = arguments[1]), A(0, t, n, e)
}, b.createCoreModule = function(t, e, n) {
A(0, t, e, n)
};
function S() {}
b.RangePrototype = S, b.rangePrototype = new S;
b.selectionPrototype = new function() {};
var T = !1,
M = function(t) {
T || (T = !0, b.initialized || $())
};
if (typeof window != i) {
if (typeof document != i) return u(document, "addEventListener") && document.addEventListener("DOMContentLoaded", M, !1), k(window, "load", M), b;
F("No document found")
} else F("No window found")
}();
i.createCoreModule("DomUtil", [], function(t, e) {
var n = "undefined",
i = t.util;
i.areHostMethods(document, ["createDocumentFragment", "createElement", "createTextNode"]) || e.fail("document missing a Node creation method"), i.isHostMethod(document, "getElementsByTagName") || e.fail("document missing getElementsByTagName method");
var r = document.createElement("div");
i.areHostMethods(r, ["insertBefore", "appendChild", "cloneNode"] || !i.areHostObjects(r, ["previousSibling", "nextSibling", "childNodes", "parentNode"])) || e.fail("Incomplete Element implementation"), i.isHostProperty(r, "innerHTML") || e.fail("Element is missing innerHTML property");
var o = document.createTextNode("test");
i.areHostMethods(o, ["splitText", "deleteData", "insertData", "appendData", "cloneNode"] || !i.areHostObjects(r, ["previousSibling", "nextSibling", "childNodes", "parentNode"]) || !i.areHostProperties(o, ["data"])) || e.fail("Incomplete Text Node implementation");
var a = function(t, e) {
for (var n = t.length; n--;)
if (t[n] === e) return !0;
return !1
};
function s(t) {
for (var e = 0; t = t.previousSibling;) ++e;
return e
}
function u(t, e) {
var n, i = [];
for (n = t; n; n = n.parentNode) i.push(n);
for (n = e; n; n = n.parentNode)
if (a(i, n)) return n;
return null
}
function c(t, e, n) {
for (var i = n ? e : e.parentNode; i;) {
if (i === t) return !0;
i = i.parentNode
}
return !1
}
function l(t, e, n) {
for (var i, r = n ? t : t.parentNode; r;) {
if ((i = r.parentNode) === e) return r;
r = i
}
return null
}
function f(t) {
var e = t.nodeType;
return 3 == e || 4 == e || 8 == e
}
function h(t, e) {
var n = e.nextSibling,
i = e.parentNode;
return n ? i.insertBefore(t, n) : i.appendChild(t), t
}
function d(t) {
if (9 == t.nodeType) return t;
if (typeof t.ownerDocument != n) return t.ownerDocument;
if (typeof t.document != n) return t.document;
if (t.parentNode) return d(t.parentNode);
throw e.createError("getDocument: no document found for node")
}
function m(t) {
var i = d(t);
if (typeof i.defaultView != n) return i.defaultView;
if (typeof i.parentWindow != n) return i.parentWindow;
throw e.createError("Cannot get a window object for node")
}
function v(t) {
if (typeof t.contentDocument != n) return t.contentDocument;
if (typeof t.contentWindow != n) return t.contentWindow.document;
throw e.createError("getIframeDocument: No Document object found for iframe element")
}
function p(t) {
return t && i.isHostMethod(t, "setTimeout") && i.isHostObject(t, "document")
}
var g = !1;
function b(t) {
try {
return t.parentNode, !1
} catch (t) {
return !0
}
}! function() {
var e = document.createElement("b");
e.innerHTML = "1";
var n = e.firstChild;
e.innerHTML = "<br>", g = b(n), t.features.crashyTextNodes = g
}();
function y(t) {
if (!t) return "[No node]";
if (g && b(t)) return "[Broken node]";
if (f(t)) return '"' + t.data + '"';
if (1 == t.nodeType) {
var e = t.id ? ' id="' + t.id + '"' : "";
return "<" + t.nodeName + e + ">[index:" + s(t) + ",length:" + t.childNodes.length + "][" + (t.innerHTML || "[innerHTML not supported]").slice(0, 25) + "]"
}
return t.nodeName
}
var w;
typeof window.getComputedStyle != n ? w = function(t, e) {
return m(t).getComputedStyle(t, null)[e]
} : typeof document.documentElement.currentStyle != n ? w = function(t, e) {
return t.currentStyle[e]
} : e.fail("No means of obtaining computed style properties found");
function F(t) {
this.root = t, this._next = t
}
F.prototype = {
_current: null,
hasNext: function() {
return !!this._next
},
next: function() {
var t, e, n = this._current = this._next;
if (this._current)
if (t = n.firstChild) this._next = t;
else {
for (e = null; n !== this.root && !(e = n.nextSibling);) n = n.parentNode;
this._next = e
}
return this._current
},
detach: function() {
this._current = this._next = this.root = null
}
};
function k(t, e) {
this.node = t, this.offset = e
}
k.prototype = {
equals: function(t) {
return !!t && this.node === t.node && this.offset == t.offset
},
inspect: function() {
return "[DomPosition(" + y(this.node) + ":" + this.offset + ")]"
},
toString: function() {
return this.inspect()
}
};
function x(t) {
this.code = this[t], this.codeName = t, this.message = "DOMException: " + this.codeName
}
x.prototype = {
INDEX_SIZE_ERR: 1,
HIERARCHY_REQUEST_ERR: 3,
WRONG_DOCUMENT_ERR: 4,
NO_MODIFICATION_ALLOWED_ERR: 7,
NOT_FOUND_ERR: 8,
NOT_SUPPORTED_ERR: 9,
INVALID_STATE_ERR: 11,
INVALID_NODE_TYPE_ERR: 24
}, x.prototype.toString = function() {
return this.message
}, t.dom = {
arrayContains: a,
isHtmlNamespace: function(t) {
var e;
return typeof t.namespaceURI == n || null === (e = t.namespaceURI) || "http://www.w3.org/1999/xhtml" == e
},
parentElement: function(t) {
var e = t.parentNode;
return 1 == e.nodeType ? e : null
},
getNodeIndex: s,
getNodeLength: function(t) {
switch (t.nodeType) {
case 7:
case 10:
return 0;
case 3:
case 8:
return t.length;
default:
return t.childNodes.length
}
},
getCommonAncestor: u,
isAncestorOf: c,
isOrIsAncestorOf: function(t, e) {
return c(t, e, !0)
},
getClosestAncestorIn: l,
isCharacterDataNode: f,
isTextOrCommentNode: function(t) {
if (!t) return !1;
var e = t.nodeType;
return 3 == e || 8 == e
},
insertAfter: h,
splitDataNode: function(t, e, n) {
var i = t.cloneNode(!1);
if (i.deleteData(0, e), t.deleteData(e, t.length - e), h(i, t), n)
for (var r, o = 0; r = n[o++];) r.node == t && r.offset > e ? (r.node = i, r.offset -= e) : r.node == t.parentNode && r.offset > s(t) && ++r.offset;
return i
},
getDocument: d,
getWindow: m,
getIframeWindow: function(t) {
if (typeof t.contentWindow != n) return t.contentWindow;
if (typeof t.contentDocument != n) return t.contentDocument.defaultView;
throw e.createError("getIframeWindow: No Window object found for iframe element")
},
getIframeDocument: v,
getBody: i.getBody,
isWindow: p,
getContentDocument: function(t, e, n) {
var r;
if (t ? i.isHostProperty(t, "nodeType") ? r = 1 == t.nodeType && "iframe" == t.tagName.toLowerCase() ? v(t) : d(t) : p(t) && (r = t.document) : r = document, !r) throw e.createError(n + "(): Parameter must be a Window object or DOM node");
return r
},
getRootContainer: function(t) {
for (var e; e = t.parentNode;) t = e;
return t
},
comparePoints: function(t, n, i, r) {
var o, a, c, f, h;
if (t == i) return n === r ? 0 : n < r ? -1 : 1;
if (o = l(i, t, !0)) return n <= s(o) ? -1 : 1;
if (o = l(t, i, !0)) return s(o) < r ? -1 : 1;
if (!(a = u(t, i))) throw new Error("comparePoints error: nodes have no common ancestor");
if ((c = t === a ? a : l(t, a, !0)) === (f = i === a ? a : l(i, a, !0))) throw e.createError("comparePoints got to case 4 and childA and childB are the same!");
for (h = a.firstChild; h;) {
if (h === c) return -1;
if (h === f) return 1;
h = h.nextSibling
}
},
isBrokenNode: b,
inspectNode: y,
getComputedStyleProperty: w,
fragmentFromNodeChildren: function(t) {
for (var e, n = d(t).createDocumentFragment(); e = t.firstChild;) n.appendChild(e);
return n
},
createIterator: function(t) {
return new F(t)
},
DomPosition: k
}, t.DOMException = x
}), i.createCoreModule("DomRange", ["DomUtil"], function(t, e) {
var n = t.dom,
i = t.util,
r = n.DomPosition,
o = t.DOMException,
a = n.isCharacterDataNode,
s = n.getNodeIndex,
u = n.isOrIsAncestorOf,
c = n.getDocument,
l = n.comparePoints,
f = n.splitDataNode,
h = n.getClosestAncestorIn,
d = n.getNodeLength,
m = n.arrayContains,
v = n.getRootContainer,
p = t.features.crashyTextNodes;
function g(t, e) {
return 3 != t.nodeType && (u(t, e.startContainer) || u(t, e.endContainer))
}
function b(t) {
return t.document || c(t.startContainer)
}
function y(t) {
return new r(t.parentNode, s(t))
}
function w(t) {
return new r(t.parentNode, s(t) + 1)
}
function F(t, e, i) {
var r = 11 == t.nodeType ? t.firstChild : t;
return a(e) ? i == e.length ? n.insertAfter(t, e) : e.parentNode.insertBefore(t, 0 == i ? e : f(e, i)) : i >= e.childNodes.length ? e.appendChild(t) : e.insertBefore(t, e.childNodes[i]), r
}
function k(t, e, n) {
if (W(t), W(e), b(e) != b(t)) throw new o("WRONG_DOCUMENT_ERR");
var i = l(t.startContainer, t.startOffset, e.endContainer, e.endOffset),
r = l(t.endContainer, t.endOffset, e.startContainer, e.startOffset);
return n ? i <= 0 && r >= 0 : i < 0 && r > 0
}
function x(t, e, i) {
var r, o;
i = i || {
stop: !1
};
for (var a, s; a = t.next();)
if (t.isPartiallySelectedSubtree()) {
if (!1 === e(a)) return void(i.stop = !0);
if (x(s = t.getSubtreeIterator(), e, i), s.detach(), i.stop) return
} else
for (r = n.createIterator(a); o = r.next();)
if (!1 === e(o)) return void(i.stop = !0)
}
function _(t) {
for (var e; t.next();) t.isPartiallySelectedSubtree() ? (_(e = t.getSubtreeIterator()), e.detach()) : t.remove()
}
function $(t) {
for (var e, n, i = b(t.range).createDocumentFragment(); e = t.next();) {
if (t.isPartiallySelectedSubtree() ? (e = e.cloneNode(!1), n = t.getSubtreeIterator(), e.appendChild($(n)), n.detach()) : t.remove(), 10 == e.nodeType) throw new o("HIERARCHY_REQUEST_ERR");
i.appendChild(e)
}
return i
}
function E(t) {
return "[" + (void 0 === t.getName ? "Range" : t.getName()) + "(" + n.inspectNode(t.startContainer) + ":" + t.startOffset + ", " + n.inspectNode(t.endContainer) + ":" + t.endOffset + ")]"
}
function C(t, e) {
if (this.range = t, this.clonePartiallySelectedTextNodes = e, !t.collapsed) {
this.sc = t.startContainer, this.so = t.startOffset, this.ec = t.endContainer, this.eo = t.endOffset;
var n = t.commonAncestorContainer;
this.sc === this.ec && a(this.sc) ? (this.isSingleCharacterDataNode = !0, this._first = this._last = this._next = this.sc) : (this._first = this._next = this.sc !== n || a(this.sc) ? h(this.sc, n, !0) : this.sc.childNodes[this.so], this._last = this.ec !== n || a(this.ec) ? h(this.ec, n, !0) : this.ec.childNodes[this.eo - 1])
}
}
C.prototype = {
_current: null,
_next: null,
_first: null,
_last: null,
isSingleCharacterDataNode: !1,
reset: function() {
this._current = null, this._next = this._first
},
hasNext: function() {
return !!this._next
},
next: function() {
var t = this._current = this._next;
return t && (this._next = t !== this._last ? t.nextSibling : null, a(t) && this.clonePartiallySelectedTextNodes && (t === this.ec && (t = t.cloneNode(!0)).deleteData(this.eo, t.length - this.eo), this._current === this.sc && (t = t.cloneNode(!0)).deleteData(0, this.so))), t
},
remove: function() {
var t, e, n = this._current;
!a(n) || n !== this.sc && n !== this.ec ? n.parentNode && n.parentNode.removeChild(n) : (t = n === this.sc ? this.so : 0) != (e = n === this.ec ? this.eo : n.length) && n.deleteData(t, e - t)
},
isPartiallySelectedSubtree: function() {
return g(this._current, this.range)
},
getSubtreeIterator: function() {
var t;
if (this.isSingleCharacterDataNode)(t = this.range.cloneRange()).collapse(!1);
else {
t = new ft(b(this.range));
var e = this._current,
n = e,
i = 0,
r = e,
o = d(e);
u(e, this.sc) && (n = this.sc, i = this.so), u(e, this.ec) && (r = this.ec, o = this.eo), lt(t, n, i, r, o)
}
return new C(t, this.clonePartiallySelectedTextNodes)
},
detach: function() {
this.range = this._current = this._next = this._first = this._last = this.sc = this.so = this.ec = this.eo = null
}
};
var A = [1, 3, 4, 5, 7, 8, 10],
S = [2, 9, 11],
T = [1, 3, 4, 5, 7, 8, 10, 11],
M = [1, 3, 4, 5, 7, 8];
function D(t) {
return function(e, n) {
for (var i, r = n ? e : e.parentNode; r;) {
if (i = r.nodeType, m(t, i)) return r;
r = r.parentNode
}
return null
}
}
var L = D([9, 11]),
R = D([5, 6, 10, 12]),
B = D([6, 10, 12]);
function I(t, e) {
if (B(t, e)) throw new o("INVALID_NODE_TYPE_ERR")
}
function N(t, e) {
if (!m(e, t.nodeType)) throw new o("INVALID_NODE_TYPE_ERR")
}
function O(t, e) {
if (e < 0 || e > (a(t) ? t.length : t.childNodes.length)) throw new o("INDEX_SIZE_ERR")
}
function j(t, e) {
if (L(t, !0) !== L(e, !0)) throw new o("WRONG_DOCUMENT_ERR")
}
function P(t) {
if (R(t, !0)) throw new o("NO_MODIFICATION_ALLOWED_ERR")
}
function q(t, e) {
if (!t) throw new o(e)
}
function U(t) {
return p && n.isBrokenNode(t) || !m(S, t.nodeType) && !L(t, !0)
}
function z(t, e) {
return e <= (a(t) ? t.length : t.childNodes.length)
}
function H(t) {
return !!t.startContainer && !!t.endContainer && !U(t.startContainer) && !U(t.endContainer) && z(t.startContainer, t.startOffset) && z(t.endContainer, t.endOffset)
}
function W(t) {
if (!H(t)) throw new Error("Range error: Range is no longer valid after DOM mutation (" + t.inspect() + ")")
}
var J = document.createElement("style"),
Y = !1;
try {
J.innerHTML = "<b>x</b>", Y = 3 == J.firstChild.nodeType
} catch (t) {}
t.features.htmlParsingConforms = Y;
var G = Y ? function(t) {
var e = this.startContainer,
i = c(e);
if (!e) throw new o("INVALID_STATE_ERR");
var r = null;
return 1 == e.nodeType ? r = e : a(e) && (r = n.parentElement(e)), (r = null === r || "HTML" == r.nodeName && n.isHtmlNamespace(c(r).documentElement) && n.isHtmlNamespace(r) ? i.createElement("body") : r.cloneNode(!1)).innerHTML = t, n.fragmentFromNodeChildren(r)
} : function(t) {
var e = b(this).createElement("body");
return e.innerHTML = t, n.fragmentFromNodeChildren(e)
};
function K(t, e) {
W(t);
var n = t.startContainer,
i = t.startOffset,
r = t.endContainer,
o = t.endOffset,
u = n === r;
a(r) && o > 0 && o < r.length && f(r, o, e), a(n) && i > 0 && i < n.length && (n = f(n, i, e), u ? (o -= i, r = n) : r == n.parentNode && o >= s(n) && o++, i = 0), t.setStartAndEnd(n, i, r, o)
}
var V = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed", "commonAncestorContainer"],
Q = 0,
X = 1,
Z = 2,
tt = 3,
et = 0,
nt = 1,
it = 2,
rt = 3;
i.extend(t.rangePrototype, {
compareBoundaryPoints: function(t, e) {
W(this), j(this.startContainer, e.startContainer);
var n, i, r, o, a = t == tt || t == Q ? "start" : "end",
s = t == X || t == Q ? "start" : "end";
return n = this[a + "Container"], i = this[a + "Offset"], r = e[s + "Container"], o = e[s + "Offset"], l(n, i, r, o)
},
insertNode: function(t) {
if (W(this), N(t, T), P(this.startContainer), u(t, this.startContainer)) throw new o("HIERARCHY_REQUEST_ERR");
var e = F(t, this.startContainer, this.startOffset);
this.setStartBefore(e)
},
cloneContents: function() {
W(this);
var t, e;
if (this.collapsed) return b(this).createDocumentFragment();
if (this.startContainer === this.endContainer && a(this.startContainer)) return (t = this.startContainer.cloneNode(!0)).data = t.data.slice(this.startOffset, this.endOffset), (e = b(this).createDocumentFragment()).appendChild(t), e;
var n = new C(this, !0);
return t = function t(e) {
for (var n, i, r, a = b(e.range).createDocumentFragment(); i = e.next();) {
if (n = e.isPartiallySelectedSubtree(), i = i.cloneNode(!n), n && (r = e.getSubtreeIterator(), i.appendChild(t(r)), r.detach()), 10 == i.nodeType) throw new o("HIERARCHY_REQUEST_ERR");
a.appendChild(i)
}
return a
}(n), n.detach(), t
},
canSurroundContents: function() {
W(this), P(this.startContainer), P(this.endContainer);
var t = new C(this, !0),
e = t._first && g(t._first, this) || t._last && g(t._last, this);
return t.detach(), !e
},
surroundContents: function(t) {
if (N(t, M), !this.canSurroundContents()) throw new o("INVALID_STATE_ERR");
var e = this.extractContents();
if (t.hasChildNodes())
for (; t.lastChild;) t.removeChild(t.lastChild);
F(t, this.startContainer, this.startOffset), t.appendChild(e), this.selectNode(t)
},
cloneRange: function() {
W(this);
for (var t, e = new ft(b(this)), n = V.length; n--;) e[t = V[n]] = this[t];
return e.isBackward = this.isBackward, e
},
toString: function() {
W(this);
var t = this.startContainer;
if (t === this.endContainer && a(t)) return 3 == t.nodeType || 4 == t.nodeType ? t.data.slice(this.startOffset, this.endOffset) : "";
var e = [],
n = new C(this, !0);
return x(n, function(t) {
3 != t.nodeType && 4 != t.nodeType || e.push(t.data)
}), n.detach(), e.join("")
},
compareNode: function(t) {
W(this);
var e = t.parentNode,
n = s(t);
if (!e) throw new o("NOT_FOUND_ERR");
var i = this.comparePoint(e, n),
r = this.comparePoint(e, n + 1);
return i < 0 ? r > 0 ? it : et : r > 0 ? nt : rt
},
comparePoint: function(t, e) {
return W(this), q(t, "HIERARCHY_REQUEST_ERR"), j(t, this.startContainer), l(t, e, this.startContainer, this.startOffset) < 0 ? -1 : l(t, e, this.endContainer, this.endOffset) > 0 ? 1 : 0
},
createContextualFragment: G,
toHtml: function() {
W(this);
var t = this.commonAncestorContainer.parentNode.cloneNode(!1);
return t.appendChild(this.cloneContents()), t.innerHTML
},
intersectsNode: function(t, e) {
if (W(this), q(t, "NOT_FOUND_ERR"), c(t) !== b(this)) return !1;
var n = t.parentNode,
i = s(t);
q(n, "NOT_FOUND_ERR");
var r = l(n, i, this.endContainer, this.endOffset),
o = l(n, i + 1, this.startContainer, this.startOffset);
return e ? r <= 0 && o >= 0 : r < 0 && o > 0
},
isPointInRange: function(t, e) {
return W(this), q(t, "HIERARCHY_REQUEST_ERR"), j(t, this.startContainer), l(t, e, this.startContainer, this.startOffset) >= 0 && l(t, e, this.endContainer, this.endOffset) <= 0
},
intersectsRange: function(t) {
return k(this, t, !1)
},
intersectsOrTouchesRange: function(t) {
return k(this, t, !0)
},
intersection: function(t) {
if (this.intersectsRange(t)) {
var e = l(this.startContainer, this.startOffset, t.startContainer, t.startOffset),
n = l(this.endContainer, this.endOffset, t.endContainer, t.endOffset),
i = this.cloneRange();
return -1 == e && i.setStart(t.startContainer, t.startOffset), 1 == n && i.setEnd(t.endContainer, t.endOffset), i
}
return null
},
union: function(t) {
if (this.intersectsOrTouchesRange(t)) {
var e = this.cloneRange();
return -1 == l(t.startContainer, t.startOffset, this.startContainer, this.startOffset) && e.setStart(t.startContainer, t.startOffset), 1 == l(t.endContainer, t.endOffset, this.endContainer, this.endOffset) && e.setEnd(t.endContainer, t.endOffset), e
}
throw new o("Ranges do not intersect")
},
containsNode: function(t, e) {
return e ? this.intersectsNode(t, !1) : this.compareNode(t) == rt
},
containsNodeContents: function(t) {
return this.comparePoint(t, 0) >= 0 && this.comparePoint(t, d(t)) <= 0
},
containsRange: function(t) {
var e = this.intersection(t);
return null !== e && t.equals(e)
},
containsNodeText: function(t) {
var e = this.cloneRange();
e.selectNode(t);
var n = e.getNodes([3]);
if (n.length > 0) {
e.setStart(n[0], 0);
var i = n.pop();
return e.setEnd(i, i.length), this.containsRange(e)
}
return this.containsNodeContents(t)
},
getNodes: function(t, e) {
return W(this),
function(t, e, n) {
var i, r = !(!e || !e.length),
o = !!n;
r && (i = new RegExp("^(" + e.join("|") + ")$"));
var s = [];
return x(new C(t, !1), function(e) {
if ((!r || i.test(e.nodeType)) && (!o || n(e))) {
var u = t.startContainer;
if (e != u || !a(u) || t.startOffset != u.length) {
var c = t.endContainer;
e == c && a(c) && 0 == t.endOffset || s.push(e)
}
}
}), s
}(this, t, e)
},
getDocument: function() {
return b(this)
},
collapseBefore: function(t) {
this.setEndBefore(t), this.collapse(!1)
},
collapseAfter: function(t) {
this.setStartAfter(t), this.collapse(!0)
},
getBookmark: function(e) {
if (!e) return {};
function i(t) {
var e = t.cloneContents();
if (e.querySelector("text, ruby")) {
for (var n = e.querySelectorAll("svg, ruby"), i = 0; i < n.length; i++) n[i].parentElement.removeChild(n[i]);
return e.textContent.length
}
return t.toString().length
}
var r = b(this),
o = t.createRange(r);
e = e || n.getBody(r), o.selectNodeContents(e);
var a = this.intersection(o),
s = e.querySelectorAll("text, ruby").length,
u = 0,
c = 0;
return a && (o.setEnd(a.startContainer, a.startOffset), c = (u = s ? i(o) : o.toString().length) + (s ? i(a) : a.toString().length)), {
start: u,
end: c,
containerNode: e
}
},
moveToBookmark: function(t) {
var e = t.containerNode,
n = 0;
this.setStart(e, 0), this.collapse(!0);
for (var i, r, o, a, s = [e], u = !1, c = !1; !c && (i = s.pop());)
if (3 == i.nodeType) r = n + i.length, !u && t.start >= n && t.start <= r && (this.setStart(i, t.start - n), u = !0), u && t.end >= n && t.end <= r && (this.setEnd(i, t.end - n), c = !0), n = r;
else if (!/^(text|RUBY)$/i.exec(i.tagName || ""))
for (o = (a = i.childNodes).length; o--;) s.push(a[o])
},
getName: function() {
return "DomRange"
},
equals: function(t) {
return ft.rangesEqual(this, t)
},
isValid: function() {
return H(this)
},
inspect: function() {
return E(this)
},
detach: function() {}
});
function ot(t) {
t.START_TO_START = Q, t.START_TO_END = X, t.END_TO_END = Z, t.END_TO_START = tt, t.NODE_BEFORE = et, t.NODE_AFTER = nt, t.NODE_BEFORE_AND_AFTER = it, t.NODE_INSIDE = rt
}
function at(t) {
ot(t), ot(t.prototype)
}
function st(t, e) {
return function() {
W(this);
var n, i = this.startContainer,
r = this.startOffset,
o = this.commonAncestorContainer,
a = new C(this, !0);
i !== o && (i = (n = w(h(i, o, !0))).node, r = n.offset), x(a, P), a.reset();
var s = t(a);
return a.detach(), e(this, i, r, i, r), s
}
}
function ut(e, n) {
function r(t, e) {
return function(n) {
N(n, A), N(v(n), S);
var i = (t ? y : w)(n);
(e ? o : u)(this, i.node, i.offset)
}
}
function o(t, e, i) {
var r = t.endContainer,
o = t.endOffset;
e === t.startContainer && i === t.startOffset || (v(e) == v(r) && 1 != l(e, i, r, o) || (r = e, o = i), n(t, e, i, r, o))
}
function u(t, e, i) {
var r = t.startContainer,
o = t.startOffset;
e === t.endContainer && i === t.endOffset || (v(e) == v(r) && -1 != l(e, i, r, o) || (r = e, o = i), n(t, r, o, e, i))
}
var c = function() {};
c.prototype = t.rangePrototype, e.prototype = new c, i.extend(e.prototype, {
setStart: function(t, e) {
I(t, !0), O(t, e), o(this, t, e)
},
setEnd: function(t, e) {
I(t, !0), O(t, e), u(this, t, e)
},
setStartAndEnd: function() {
var t = arguments,
e = t[0],
i = t[1],
r = e,
o = i;
switch (t.length) {
case 3:
o = t[2];
break;
case 4:
r = t[2], o = t[3]
}
n(this, e, i, r, o)
},
setBoundary: function(t, e, n) {
this["set" + (n ? "Start" : "End")](t, e)
},
setStartBefore: r(!0, !0),
setStartAfter: r(!1, !0),
setEndBefore: r(!0, !1),
setEndAfter: r(!1, !1),
collapse: function(t) {
W(this), t ? n(this, this.startContainer, this.startOffset, this.startContainer, this.startOffset) : n(this, this.endContainer, this.endOffset, this.endContainer, this.endOffset)
},
selectNodeContents: function(t) {
I(t, !0), n(this, t, 0, t, d(t))
},
selectNode: function(t) {
I(t, !1), N(t, A);
var e = y(t),
i = w(t);
n(this, e.node, e.offset, i.node, i.offset)
},
extractContents: st($, n),
deleteContents: st(_, n),
canSurroundContents: function() {
W(this), P(this.startContainer), P(this.endContainer);
var t = new C(this, !0),
e = t._first && g(t._first, this) || t._last && g(t._last, this);
return t.detach(), !e
},
splitBoundaries: function() {
K(this)
},
splitBoundariesPreservingPositions: function(t) {
K(this, t)
},
normalizeBoundaries: function() {
W(this);
var t = this.startContainer,
e = this.startOffset,
i = this.endContainer,
r = this.endOffset,
o = function(t) {
var e = t.nextSibling;
e && e.nodeType == t.nodeType && (i = t, r = t.length, t.appendData(e.data), e.parentNode.removeChild(e))
},
u = function(n) {
var o = n.previousSibling;
if (o && o.nodeType == n.nodeType) {
t = n;
var a = n.length;
if (e = o.length, n.insertData(0, o.data), o.parentNode.removeChild(o), t == i) r += e, i = t;
else if (i == n.parentNode) {
var u = s(n);
r == u ? (i = n, r = a) : r > u && r--
}
}
},
c = !0;
if (a(i)) i.length == r && o(i);
else {
if (r > 0) {
var l = i.childNodes[r - 1];
l && a(l) && o(l)
}
c = !this.collapsed
}
if (c) {
if (a(t)) 0 == e && u(t);
else if (e < t.childNodes.length) {
var f = t.childNodes[e];
f && a(f) && u(f)
}
} else t = i, e = r;
n(this, t, e, i, r)
},
collapseToPoint: function(t, e) {
I(t, !0), O(t, e), this.setStartAndEnd(t, e)
}
}), at(e)
}
function ct(t) {
t.collapsed = t.startContainer === t.endContainer && t.startOffset === t.endOffset, t.commonAncestorContainer = t.collapsed ? t.startContainer : n.getCommonAncestor(t.startContainer, t.endContainer)
}
function lt(t, e, i, r, o) {
t.startContainer = e, t.startOffset = i, t.endContainer = r, t.endOffset = o, t.document = n.getDocument(e), ct(t)
}
function ft(t) {
this.startContainer = t, this.startOffset = 0, this.endContainer = t, this.endOffset = 0, this.document = t, ct(this)
}
ut(ft, lt), i.extend(ft, {
rangeProperties: V,
RangeIterator: C,
copyComparisonConstants: at,
createPrototypeRange: ut,
inspect: E,
getRangeDocument: b,
rangesEqual: function(t, e) {
return t.startContainer === e.startContainer && t.startOffset === e.startOffset && t.endContainer === e.endContainer && t.endOffset === e.endOffset
}
}), t.DomRange = ft
}), i.createCoreModule("WrappedRange", ["DomRange"], function(t, e) {
var n, i, r = t.dom,
o = t.util,
a = r.DomPosition,
s = t.DomRange,
u = r.getBody,
c = r.getContentDocument,
l = r.isCharacterDataNode;
if (t.features.implementsDomRange && function() {
var i, a = s.rangeProperties;
function l(t) {
for (var e, n = a.length; n--;) t[e = a[n]] = t.nativeRange[e];
t.collapsed = t.startContainer === t.endContainer && t.startOffset === t.endOffset
}
var f;
n = function(t) {
if (!t) throw e.createError("WrappedRange: Range must be specified");
this.nativeRange = t, l(this)
}, s.createPrototypeRange(n, function(t, e, n, i, r) {
var o = t.startContainer !== e || t.startOffset != n,
a = t.endContainer !== i || t.endOffset != r,
s = !t.equals(t.nativeRange);
(o || a || s) && (t.setEnd(i, r), t.setStart(e, n))
}), (i = n.prototype).selectNode = function(t) {
this.nativeRange.selectNode(t), l(this)
}, i.cloneContents = function() {
return this.nativeRange.cloneContents()
}, i.surroundContents = function(t) {
this.nativeRange.surroundContents(t), l(this)
}, i.collapse = function(t) {
this.nativeRange.collapse(t), l(this)
}, i.cloneRange = function() {
var t = new n(this.nativeRange.cloneRange());
return t.isBackward = this.isBackward, t
}, i.refresh = function() {
l(this)
}, i.toString = function() {
return this.nativeRange.toString()
};
var h = document.createTextNode("test");
u(document).appendChild(h);
var d = document.createRange();
d.setStart(h, 0), d.setEnd(h, 0);
try {
d.setStart(h, 1), i.setStart = function(t, e) {
this.nativeRange.setStart(t, e), l(this)
}, i.setEnd = function(t, e) {
this.nativeRange.setEnd(t, e), l(this)
}, f = function(t) {
return function(e) {
this.nativeRange[t](e), l(this)
}
}
} catch (t) {
i.setStart = function(t, e) {
try {
this.nativeRange.setStart(t, e)
} catch (n) {
this.nativeRange.setEnd(t, e), this.nativeRange.setStart(t, e)
}
l(this)
}, i.setEnd = function(t, e) {
try {
this.nativeRange.setEnd(t, e)
} catch (n) {
this.nativeRange.setStart(t, e), this.nativeRange.setEnd(t, e)
}
l(this)
}, f = function(t, e) {
return function(n) {
try {
this.nativeRange[t](n)
} catch (i) {
this.nativeRange[e](n), this.nativeRange[t](n)
}
l(this)
}
}
}
i.setStartBefore = f("setStartBefore", "setEndBefore"), i.setStartAfter = f("setStartAfter", "setEndAfter"), i.setEndBefore = f("setEndBefore", "setStartBefore"), i.setEndAfter = f("setEndAfter", "setStartAfter"), i.selectNodeContents = function(t) {
this.setStartAndEnd(t, 0, r.getNodeLength(t))
}, d.selectNodeContents(h), d.setEnd(h, 3);
var m = document.createRange();
m.selectNodeContents(h), m.setEnd(h, 4), m.setStart(h, 2), -1 == d.compareBoundaryPoints(d.START_TO_END, m) && 1 == d.compareBoundaryPoints(d.END_TO_START, m) ? i.compareBoundaryPoints = function(t, e) {
return t == (e = e.nativeRange || e).START_TO_END ? t = e.END_TO_START : t == e.END_TO_START && (t = e.START_TO_END), this.nativeRange.compareBoundaryPoints(t, e)
} : i.compareBoundaryPoints = function(t, e) {
return this.nativeRange.compareBoundaryPoints(t, e.nativeRange || e)
};
var v = document.createElement("div");
v.innerHTML = "123";
var p = v.firstChild,
g = u(document);
g.appendChild(v), d.setStart(p, 1), d.setEnd(p, 2), d.deleteContents(), "13" == p.data && (i.deleteContents = function() {
this.nativeRange.deleteContents(), l(this)
}, i.extractContents = function() {
var t = this.nativeRange.extractContents();
return l(this), t
}), g.removeChild(v), g = null, o.isHostMethod(d, "createContextualFragment") && (i.createContextualFragment = function(t) {
return this.nativeRange.createContextualFragment(t)
}), u(document).removeChild(h), i.getName = function() {
return "WrappedRange"
}, t.WrappedRange = n, t.createNativeRange = function(t) {
return (t = c(t, e, "createNativeRange")).createRange()
}
}(), t.features.implementsTextRange) {
var f = function(t, e, n, i, o) {
var s = t.duplicate();
s.collapse(n);
var u = s.parentElement();
if (r.isOrIsAncestorOf(e, u) || (u = e), !u.canHaveHTML) {
var c = new a(u.parentNode, r.getNodeIndex(u));
return {
boundaryPosition: c,
nodeInfo: {
nodeIndex: c.offset,
containerElement: c.node
}
}
}
var f = r.getDocument(u).createElement("span");
f.parentNode && f.parentNode.removeChild(f);
for (var h, d, m, v, p, g = n ? "StartToStart" : "StartToEnd", b = o && o.containerElement == u ? o.nodeIndex : 0, y = u.childNodes.length, w = y, F = w; F == y ? u.appendChild(f) : u.insertBefore(f, u.childNodes[F]), s.moveToElementText(f), 0 != (h = s.compareEndPoints(g, t)) && b != w;) {
if (-1 == h) {
if (w == b + 1) break;
b = F
} else w = w == b + 1 ? b : F;
F = Math.floor((b + w) / 2), u.removeChild(f)
}
if (p = f.nextSibling, -1 == h && p && l(p)) {
s.setEndPoint(n ? "EndToStart" : "EndToEnd", t);
var k;
if (/[\r\n]/.test(p.data)) {
var x = s.duplicate(),
_ = x.text.replace(/\r\n/g, "\r").length;
for (k = x.moveStart("character", _); - 1 == (h = x.compareEndPoints("StartToEnd", x));) k++, x.moveStart("character", 1)
} else k = s.text.length;
v = new a(p, k)
} else d = (i || !n) && f.previousSibling, v = (m = (i || n) && f.nextSibling) && l(m) ? new a(m, 0) : d && l(d) ? new a(d, d.data.length) : new a(u, r.getNodeIndex(f));
return f.parentNode.removeChild(f), {
boundaryPosition: v,
nodeInfo: {
nodeIndex: F,
containerElement: u
}
}
},
h = function(t, e) {
var n, i, o, a, s = t.offset,
c = r.getDocument(t.node),
f = u(c).createTextRange(),
h = l(t.node);
return h ? i = (n = t.node).parentNode : (n = s < (a = t.node.childNodes).length ? a[s] : null, i = t.node), (o = c.createElement("span")).innerHTML = "&#feff;", n ? i.insertBefore(o, n) : i.appendChild(o), f.moveToElementText(o), f.collapse(!e), i.removeChild(o), h && f[e ? "moveStart" : "moveEnd"]("character", s), f
};
if ((i = function(t) {
this.textRange = t, this.refresh()
}).prototype = new s(document), i.prototype.refresh = function() {
var t, e, n, i = function(t) {
var e = t.parentElement(),
n = t.duplicate();
n.collapse(!0);
var i = n.parentElement();
(n = t.duplicate()).collapse(!1);
var o = n.parentElement(),
a = i == o ? i : r.getCommonAncestor(i, o);
return a == e ? a : r.getCommonAncestor(e, a)
}(this.textRange);
0 == (o = this.textRange).compareEndPoints("StartToEnd", o) ? e = t = f(this.textRange, i, !0, !0).boundaryPosition : (t = (n = f(this.textRange, i, !0, !1)).boundaryPosition, e = f(this.textRange, i, !1, !1, n.nodeInfo).boundaryPosition);
var o;
this.setStart(t.node, t.offset), this.setEnd(e.node, e.offset)
}, i.prototype.getName = function() {
return "WrappedTextRange"
}, s.copyComparisonConstants(i), i.rangeToTextRange = function(t) {
if (t.collapsed) return h(new a(t.startContainer, t.startOffset), !0);
var e = h(new a(t.startContainer, t.startOffset), !0),
n = h(new a(t.endContainer, t.endOffset), !1),
i = u(s.getRangeDocument(t)).createTextRange();
return i.setEndPoint("StartToStart", e), i.setEndPoint("EndToEnd", n), i
}, t.WrappedTextRange = i, !t.features.implementsDomRange || t.config.preferTextRange) {
var d = function() {
return this
}();
void 0 === d.Range && (d.Range = i), t.createNativeRange = function(t) {
return t = c(t, e, "createNativeRange"), u(t).createTextRange()
}, t.WrappedRange = i
}
}
t.createRange = function(n) {
return n = c(n, e, "createRange"), new t.WrappedRange(t.createNativeRange(n))
}, t.createRangyRange = function(t) {
return t = c(t, e, "createRangyRange"), new s(t)
}, t.createIframeRange = function(n) {
return e.deprecationNotice("createIframeRange()", "createRange(iframeEl)"), t.createRange(n)
}, t.createIframeRangyRange = function(n) {
return e.deprecationNotice("createIframeRangyRange()", "createRangyRange(iframeEl)"), t.createRangyRange(n)
}, t.addCreateMissingNativeApiListener(function(e) {
var n = e.document;
void 0 === n.createRange && (n.createRange = function() {
return t.createRange(n)
}), n = e = null
})
}), i.createCoreModule("WrappedSelection", ["DomRange", "WrappedRange"], function(t, e) {
t.config.checkSelectionRanges = !0;
var n, i, r = t.dom,
o = t.util,
a = o.isHostMethod,
s = t.DomRange,
u = t.WrappedRange,
c = t.DOMException,
l = r.DomPosition,
f = t.features,
h = "Control",
d = r.getDocument,
m = r.getBody,
v = s.rangesEqual;
function p(t) {
return "string" == typeof t ? /^backward(s)?$/i.test(t) : !!t
}
function g(t, n) {
if (t) {
if (r.isWindow(t)) return t;
if (t instanceof q) return t.win;
var i = r.getContentDocument(t, e, n);
return r.getWindow(i)
}
return window
}
function b(t) {
return g(t, "getDocSelection").document.selection
}
function y(t) {
var e = !1;
return t.anchorNode && (e = 1 == r.comparePoints(t.anchorNode, t.anchorOffset, t.focusNode, t.focusOffset)), e
}
var w = a(window, "getSelection"),
F = o.isHostObject(document, "selection");
f.implementsWinGetSelection = w, f.implementsDocSelection = F;
var k = F && (!w || t.config.preferTextRange);
k ? (n = b, t.isSelectionValid = function(t) {
var e = g(t, "isSelectionValid").document,
n = e.selection;
return "None" != n.type || d(n.createRange().parentElement()) == e
}) : w ? (n = function(t) {
return g(t, "getWinSelection").getSelection()
}, t.isSelectionValid = function() {
return !0
}) : e.fail("Neither document.selection or window.getSelection() detected."), t.getNativeSelection = n;
var x = n(),
_ = t.createNativeRange(document),
$ = m(document),
E = o.areHostProperties(x, ["anchorNode", "focusNode", "anchorOffset", "focusOffset"]);
f.selectionHasAnchorAndFocus = E;
var C = a(x, "extend");
f.selectionHasExtend = C;
var A = "number" == typeof x.rangeCount;
f.selectionHasRangeCount = A;
var S = C ? function(e, n) {
var i = s.getRangeDocument(n),
r = t.createRange(i);
r.collapseToPoint(n.endContainer, n.endOffset), e.addRange(R(r)), e.extend(n.startContainer, n.startOffset)
} : null;
o.areHostMethods(x, ["addRange", "getRangeAt", "removeAllRanges"]) && "number" == typeof x.rangeCount && f.implementsDomRange && function() {
var e = window.getSelection();
if (e) {
for (var n = e.rangeCount, i = [], r = y(e), o = 0; o < n; ++o) i[o] = e.getRangeAt(o);
for (o = 0; o < n; ++o) 0 == o && r ? S ? S(e, i[o]) : (t.warn("Rangy initialization: original selection was backwards but selection has been restored forwards because the browser does not support Selection.extend"), e.addRange(i[o])) : e.addRange(i[o])
}
}(), f.selectionSupportsMultipleRanges = !1, f.collapsedNonEditableSelectionsSupported = !0;
var T, M = !1;
$ && a($, "createControlRange") && (T = $.createControlRange(), o.areHostProperties(T, ["item", "add"]) && (M = !0)), f.implementsControlRange = M, i = E ? function(t) {
return t.anchorNode === t.focusNode && t.anchorOffset === t.focusOffset
} : function(t) {
return !!t.rangeCount && t.getRangeAt(t.rangeCount - 1).collapsed
};
function D(t, e, n) {
var i = n ? "end" : "start",
r = n ? "start" : "end";
t.anchorNode = e[i + "Container"], t.anchorOffset = e[i + "Offset"], t.focusNode = e[r + "Container"], t.focusOffset = e[r + "Offset"]
}
function L(t) {
t.anchorNode = t.focusNode = null, t.anchorOffset = t.focusOffset = 0, t.rangeCount = 0, t.isCollapsed = !0, t._ranges.length = 0
}
function R(e) {
var n;
return e instanceof s ? ((n = t.createNativeRange(e.getDocument())).setEnd(e.endContainer, e.endOffset), n.setStart(e.startContainer, e.startOffset)) : e instanceof u ? n = e.nativeRange : f.implementsDomRange && e instanceof r.getWindow(e.startContainer).Range && (n = e), n
}
function B(t) {
var n = t.getNodes();
if (! function(t) {
if (!t.length || 1 != t[0].nodeType) return !1;
for (var e = 1, n = t.length; e < n; ++e)
if (!r.isAncestorOf(t[0], t[e])) return !1;
return !0
}(n)) throw e.createError("getSingleElementFromRange: range " + t.inspect() + " did not consist of a single element");
return n[0]
}
function I(t) {
return !!t && void 0 !== t.text
}
function N(t, e) {
var n = new u(e);
t._ranges = [n], D(t, n, !1), t.rangeCount = 1, t.isCollapsed = n.collapsed
}
function O(e) {
if (e._ranges.length = 0, "None" == e.docSelection.type) L(e);
else {
var n = e.docSelection.createRange();
if (I(n)) N(e, n);
else {
e.rangeCount = n.length;
for (var i, r = d(n.item(0)), o = 0; o < e.rangeCount; ++o)(i = t.createRange(r)).selectNode(n.item(o)), e._ranges.push(i);
e.isCollapsed = 1 == e.rangeCount && e._ranges[0].collapsed, D(e, e._ranges[e.rangeCount - 1], !1)
}
}
}
function j(t, n) {
for (var i = t.docSelection.createRange(), r = B(n), o = d(i.item(0)), a = m(o).createControlRange(), s = 0, u = i.length; s < u; ++s) a.add(i.item(s));
try {
a.add(r)
} catch (t) {
throw e.createError("addRange(): Element within the specified Range could not be added to control selection (does it have layout?)")
}
newControlrange.select(n.isBackward), O(t)
}
var P;
a(x, "getRangeAt") ? P = function(t, e) {
try {
return t.getRangeAt(e)
} catch (t) {
return null
}
} : E && (P = function(e) {
var n = d(e.anchorNode),
i = t.createRange(n);
return i.setStartAndEnd(e.anchorNode, e.anchorOffset, e.focusNode, e.focusOffset), i.collapsed !== this.isCollapsed && i.setStartAndEnd(e.focusNode, e.focusOffset, e.anchorNode, e.anchorOffset), i
});
function q(t, e, n) {
this.nativeSelection = t, this.docSelection = e, this._ranges = [], this.win = n, this.refresh()
}
q.prototype = t.selectionPrototype;
function U(t) {
t.win = t.anchorNode = t.focusNode = t._ranges = null, t.rangeCount = t.anchorOffset = t.focusOffset = 0, t.detached = !0
}
var z = [];
function H(t, e) {
for (var n, i, r = z.length; r--;)
if (i = (n = z[r]).selection, "deleteAll" == e) U(i);
else if (n.win == t) return "delete" == e ? (z.splice(r, 1), !0) : i;
return "deleteAll" == e && (z.length = 0), null
}
var W = function(t) {
if (t && t instanceof q) return t.refresh(), t;
var e = H(t = g(t, "getNativeSelection")),
i = n(t),
r = F ? b(t) : null;
return e ? (e.nativeSelection = i, e.docSelection = r, e.refresh()) : (e = new q(i, r, t), z.push({
win: t,
selection: e
})), e
};
t.getSelection = W, t.getIframeSelection = function(n) {
return e.deprecationNotice("getIframeSelection()", "getSelection(iframeEl)"), t.getSelection(r.getIframeWindow(n))
};
var J = q.prototype;
function Y(t, n) {
for (var i, r = d(n[0].startContainer), o = m(r).createControlRange(), a = 0, s = n.length; a < s; ++a) {
i = B(n[a]);
try {
o.add(i)
} catch (t) {
throw e.createError("setRanges(): Element within one of the specified Ranges could not be added to control selection (does it have layout?)")
}
}
controlrange.select(range.isBackward), O(t)
}
if (!k && E && o.areHostMethods(x, ["removeAllRanges", "addRange"])) {
J.removeAllRanges = function() {
this.nativeSelection.removeAllRanges(), L(this)
};
var G = function(t, e) {
S(t.nativeSelection, e), t.refresh()
};
J.addRange = A ? function(e, n) {
if (M && F && this.docSelection.type == h) j(this, e);
else if (p(n) && C) G(this, e);
else {
var r;
if (this.removeAllRanges(), r = 0, this.nativeSelection.addRange(R(e).cloneRange()), this.rangeCount = this.nativeSelection.rangeCount, this.rangeCount == r + 1) {
if (t.config.checkSelectionRanges) {
var o = P(this.nativeSelection, this.rangeCount - 1);
o && !v(o, e) && (e = new u(o))
}
this._ranges[this.rangeCount - 1] = e, D(this, e, Q(this.nativeSelection)), this.isCollapsed = i(this)
} else this.refresh()
}
} : function(t, e) {
p(e) && C ? G(this, t) : (this.nativeSelection.addRange(R(t)), this.refresh())
}, J.setRanges = function(t) {
if (M && t.length > 1) Y(this, t);
else {
this.removeAllRanges();
for (var e = 0, n = t.length; e < n; ++e) this.addRange(t[e])
}
}
} else {
if (!(a(x, "empty") && a(_, "select") && M && k)) return e.fail("No means of selecting a Range or TextRange was found"), !1;
J.removeAllRanges = function() {
try {
if (this.docSelection.empty(), "None" != this.docSelection.type) {
var t;
if (this.anchorNode) t = d(this.anchorNode);
else if (this.docSelection.type == h) {
var e = this.docSelection.createRange();
e.length && (t = d(e.item(0)))
}
if (t) {
m(t).createTextRange();
textrange.select(range.isBackward), this.docSelection.empty()
}
}
} catch (t) {}
L(this)
}, J.addRange = function(e) {
this.docSelection.type == h ? j(this, e) : (t.WrappedTextRange.rangeToTextRange(e).select(), this._ranges[0] = e, this.rangeCount = 1, this.isCollapsed = this._ranges[0].collapsed, D(this, e, !1))
}, J.setRanges = function(t) {
this.removeAllRanges();
var e = t.length;
e > 1 ? Y(this, t) : e && this.addRange(t[0])
}
}
J.getRangeAt = function(t) {
if (t < 0 || t >= this.rangeCount) throw new c("INDEX_SIZE_ERR");
return this._ranges[t].cloneRange()
};
var K;
if (k) K = function(e) {
var n;
t.isSelectionValid(e.win) ? n = e.docSelection.createRange() : (n = m(e.win.document).createTextRange()).collapse(!0), e.docSelection.type == h ? O(e) : I(n) ? N(e, n) : L(e)
};
else if (a(x, "getRangeAt") && "number" == typeof x.rangeCount) K = function(e) {
if (M && F && e.docSelection.type == h) O(e);
else if (e._ranges.length = e.rangeCount = e.nativeSelection.rangeCount, e.rangeCount) {
for (var n = 0, r = e.rangeCount; n < r; ++n) e._ranges[n] = new t.WrappedRange(e.nativeSelection.getRangeAt(n));
D(e, e._ranges[e.rangeCount - 1], Q(e.nativeSelection)), e.isCollapsed = i(e)
} else L(e)
};
else {
if (!E || "boolean" != typeof x.isCollapsed || "boolean" != typeof _.collapsed || !f.implementsDomRange) return e.fail("No means of obtaining a Range or TextRange from the user's selection was found"), !1;
K = function(t) {
var e, n = t.nativeSelection;
n.anchorNode ? (e = P(n, 0), t._ranges = [e], t.rangeCount = 1, function(t) {
var e = t.nativeSelection;
t.anchorNode = e.anchorNode, t.anchorOffset = e.anchorOffset, t.focusNode = e.focusNode, t.focusOffset = e.focusOffset
}(t), t.isCollapsed = i(t)) : L(t)
}
}
J.refresh = function(t) {
var e = t ? this._ranges.slice(0) : null,
n = this.anchorNode,
i = this.anchorOffset;
if (K(this), t) {
var r = e.length;
if (r != this._ranges.length) return !0;
if (this.anchorNode != n || this.anchorOffset != i) return !0;
for (; r--;)
if (!v(e[r], this._ranges[r])) return !0;
return !1
}
};
var V = function(t, e) {
var n = t.getAllRanges();
t.removeAllRanges();
for (var i = 0, r = n.length; i < r; ++i) v(e, n[i]) || t.addRange(n[i]);
t.rangeCount || L(t)
};
J.removeRange = M ? function(t) {
if (this.docSelection.type == h) {
for (var e = this.docSelection.createRange(), n = B(t), i = d(e.item(0)), r = m(i).createControlRange(), o = !1, a = 0, s = e.length; a < s; ++a) e.item(a) !== n || o ? r.add(e.item(a)) : o = !0;
newControlrange.select(t.isBackward), O(this)
} else V(this, t)
} : function(t) {
V(this, t)
};
var Q;
!k && E && f.implementsDomRange ? (Q = y, J.isBackward = function() {
return Q(this)
}) : Q = J.isBackward = function() {
return !1
}, J.isBackwards = J.isBackward, J.toString = function() {
for (var t = [], e = 0, n = this.rangeCount; e < n; ++e) t[e] = "" + this._ranges[e];
return t.join("")
};
function X(t, e) {
if (t.win.document != d(e)) throw new c("WRONG_DOCUMENT_ERR")
}
J.collapse = function(e, n) {
X(this, e);
var i = t.createRange(e);
i.collapseToPoint(e, n), this.setSingleRange(i), this.isCollapsed = !0
}, J.collapseToStart = function() {
if (!this.rangeCount) throw new c("INVALID_STATE_ERR");
var t = this._ranges[0];
this.collapse(t.startContainer, t.startOffset)
}, J.collapseToEnd = function() {
if (!this.rangeCount) throw new c("INVALID_STATE_ERR");
var t = this._ranges[this.rangeCount - 1];
this.collapse(t.endContainer, t.endOffset)
}, J.selectAllChildren = function(e) {
X(this, e);
var n = t.createRange(e);
n.selectNodeContents(e), this.setSingleRange(n)
}, J.deleteFromDocument = function() {
if (M && F && this.docSelection.type == h) {
for (var t, e = this.docSelection.createRange(); e.length;) t = e.item(0), e.remove(t), t.parentNode.removeChild(t);
this.refresh()
} else if (this.rangeCount) {
var n = this.getAllRanges();
if (n.length) {
this.removeAllRanges();
for (var i = 0, r = n.length; i < r; ++i) n[i].deleteContents();
this.addRange(n[r - 1])
}
}
}, J.eachRange = function(t, e) {
for (var n = 0, i = this._ranges.length; n < i; ++n)
if (t(this.getRangeAt(n))) return e
}, J.getAllRanges = function() {
var t = [];
return this.eachRange(function(e) {
t.push(e)
}), t
}, J.setSingleRange = function(t, e) {
this.removeAllRanges(), this.addRange(t, e)
}, J.callMethodOnEachRange = function(t, e) {
var n = [];
return this.eachRange(function(i) {
n.push(i[t].apply(i, e))
}), n
};
function Z(e) {
return function(n, i) {
var r;
this.rangeCount ? (r = this.getRangeAt(0))["set" + (e ? "Start" : "End")](n, i) : (r = t.createRange(this.win.document)).setStartAndEnd(n, i), this.setSingleRange(r, this.isBackward())
}
}
J.setStart = Z(!0), J.setEnd = Z(!1), t.rangePrototype.select = function(t) {
W(this.getDocument()).setSingleRange(this, t)
}, J.changeEachRange = function(t) {
var e = [],
n = this.isBackward();
this.eachRange(function(n) {
t(n), e.push(n)
}), this.removeAllRanges(), n && 1 == e.length ? this.addRange(e[0], "backward") : this.setRanges(e)
}, J.containsNode = function(t, e) {
return this.eachRange(function(n) {
return n.containsNode(t, e)
}, !0)
}, J.getBookmark = function(t) {
return {
backward: this.isBackward(),
rangeBookmarks: this.callMethodOnEachRange("getBookmark", [t])
}
}, J.moveToBookmark = function(e) {
for (var n, i, r = [], o = 0; n = e.rangeBookmarks[o++];)(i = t.createRange(this.win)).moveToBookmark(n), r.push(i);
e.backward ? this.setSingleRange(r[0], "backward") : this.setRanges(r)
}, J.toHtml = function() {
return this.callMethodOnEachRange("toHtml").join("")
};
function tt(t) {
var e = [],
n = new l(t.anchorNode, t.anchorOffset),
i = new l(t.focusNode, t.focusOffset),
r = "function" == typeof t.getName ? t.getName() : "Selection";
if (void 0 !== t.rangeCount)
for (var o = 0, a = t.rangeCount; o < a; ++o) e[o] = s.inspect(t.getRangeAt(o));
return "[" + r + "(Ranges: " + e.join(", ") + ")(anchor: " + n.inspect() + ", focus: " + i.inspect() + "]"
}
J.getName = function() {
return "WrappedSelection"
}, J.inspect = function() {
return tt(this)
}, J.detach = function() {
H(this.win, "delete"), U(this)
}, q.detachAll = function() {
H(null, "deleteAll")
}, q.inspect = tt, q.isDirectionBackward = p, t.Selection = q, t.selectionPrototype = J, t.addCreateMissingNativeApiListener(function(t) {
void 0 === t.getSelection && (t.getSelection = function() {
return W(t)
}), t = null
})
}), n.exports = i
}), $__System.registerDynamic("30", ["14", "e", "1c", "1f", "13", "26"], !0, function(t, e, n) {
"use strict";
this || self;
var i = t("14"),
r = t("e"),
o = t("1c"),
a = t("1f"),
s = t("13"),
u = s.Node,
c = t("26").map,
l = u.TYPE,
f = i.WESTERN_WORD_SPLITER,
h = function(t) {
this.rangy = o, o.init(), this.savedSel = {}, this.editor = t, r(document).on("selectionchange", function(e) {
t.selection.selectWordTime && new Date - t.selection.selectWordTime > 200 && (t.selection.selectWordTime = null)
}), this.updateMetrics()
},
d = !1,
m = r.fn.scrollTop;
r.fn.oldScrollTop = m, r.fn.scrollTop = function(t) {
if (void 0 === t || !d) return m.apply(this, arguments)
};
var v;
r(document.body).on("hidden.bs.modal", ".modal", function(t) {
File.editor.restoreLastCursor()
}).on(".show.bs.modal", ".modal", function() {
var t = File.editor.selection.buildUndo();
t && (File.editor.lastCursor = t)
});
function p(t) {
return !1
}
function g(t) {
r("content").on(t ? "scroll" : "DOMMouseScroll mousewheel", p), setTimeout(function() {
r("content").off(t ? "scroll" : "DOMMouseScroll mousewheel", p)
}, 500)
}
g(), o.rangePrototype.insertNodeAtEnd = function(t) {
var e = this.cloneRange();
e.collapse(!1), e.insertNode(t), e.detach(), this.setEndAfter(t)
};
var b;
r(window).on("resize", function() {
File.suppressResize || (b = document.querySelector("content").clientHeight)
}), h.prototype = {
preventScrollOnce: g,
enableScroll: function(t) {
r("content").off(t ? "scroll" : "DOMMouseScroll mousewheel", p)
},
clearGlobalColumn: function() {
v = void 0
},
updateMetrics: function() {
b = document.querySelector("content").clientHeight, this.editor.defaultTextHeight = parseInt(r("#write p").css("line-height"))
},
jumpIntoElemBegin: function(t, e) {
try {
var n = this,
i = this.editor,
a = t.find(".CodeMirror")[0],
s = t.children("[mdtype]");
if (!t || !t.length) return Reporter.error("cannot jumpIntoElemBegin to empty elem", {
level: "warning"
}), window.getSelection().removeAllRanges(), !1;
if (t.length > 1 && (t = r(t[0])), a) return a.CodeMirror.focus(), a.CodeMirror.execCommand("goDocStart");
if (_(i, !1, i.findNodeByElem(t))) return;
if (u.isType(t.attr("mdtype"), u.TYPE.image, u.TYPE.hr, u.TYPE.math_block)) return this.selectNode(null, t);
if (t.hasClass("footnotes")) return this.jumpIntoElemBegin(t.find(".md-def-name"));
if (s.length) return this.jumpIntoElemBegin(r(s[0]), e);
var c = o.createRange();
return c.setStart(t[0], 0), c.setEnd(t[0], 0), this.deRange(c), n.setRange(c, !0), e ? setTimeout(function() {
n.setRange(c, !0), n.editor.refocus()
}, 20) : !window.getSelection().anchorNode && t.length && (! function t(e) {
3 == e.nodeType ? (c.setStart(e, 0), c.setEnd(e, 0)) : e.childNodes.length ? t(e.childNodes[0]) : (c.setStart(e, 0), c.setEnd(e, 0))
}(t[0]), window.getSelection().addRange(c.nativeRange)), window.getSelection().anchorOffset
} catch (e) {
Reporter.error("cursor may go wrong", {
level: "warning",
filename: "Selection.js",
extra: {
dom: Reporter.sanitizeDom(t[0])
}
})
}
},
jumpIntoElemEnd: function(t, e) {
var n = t.find(".CodeMirror")[0];
if (t.length > 1 && (t = r(t[0])), n) n.CodeMirror.execCommand("goDocEnd");
else {
if (_(this.editor, !0, this.editor.findNodeByElem(t))) return;
if (u.isType(t.attr("mdtype"), u.TYPE.image, u.TYPE.hr, u.TYPE.math_block)) return this.selectNode(null, t);
if (t.children("[mdtype]").length) return this.jumpIntoElemEnd(r(t.children("[mdtype]")[0]), e);
t.addClass("md-expand"), this.restoreSelection(t[0], t.text().length), t.removeClass("md-expand")
}
},
jumpInto: function(t, e) {
if ("" == t.text()) return this.jumpIntoElemBegin(t);
this.restoreSelection(t[0], e)
},
setRange: function(t, e) {
this.editor.wordCount.updateInSelection(), e || (this.editor.brush.closestExpandable(r(t.startContainer)).addClass("md-expand"), this.editor.brush.closestExpandable(r(t.endContainer)).addClass("md-expand")), t.commonAncestorContainer && t.commonAncestorContainer.getAttribute && "linebreak" == t.commonAncestorContainer.getAttribute("md-inline") && "\n" == t.toString() && t.collapse(!0), File.isTypeWriterMode && File.option.scrollWithCursor && this.typeWriterScroll(t.nativeRange || t), this.rangy.getSelection().setSingleRange(t, t.isBackward)
},
getOffset: function(t, e) {
if (e = e || this.getRangy()) try {
return e.getBookmark(t[0]).start
} catch (t) {}
return 0
},
restoreEdge: function(t, e, n, i) {
t.jquery && (t = t.length ? t[0] : null);
var a, s = 0,
u = {};
if (!n) {
var c = r(t).closest("[mdtype='line'], [mdtype='heading']");
a = c.length && e < c.text().length
}
i = i || o.createRange();
try {
t && function t(r) {
if (3 == r.nodeType) {
var o = s + r.textContent.length;
if (n) {
if (e >= s && e <= o) throw i.setEnd(r, e - s), u
} else if (a) {
if (e >= s && e < o) throw i.setStart(r, e - s), u
} else if (e >= s && e <= o) throw i.setStart(r, e - s), u;
s = o
} else {
r.childNodes.length || r.nodeType !== r.ELEMENT_NODE || r.appendChild(document.createTextNode(""));
for (var c = 0, l = r.childNodes.length; c < l; ++c) t(r.childNodes[c])
}
}(t)
} catch (t) {
if (t == u) return i;
throw t
}
return i
},
saveSelection: function(t, e) {
if (t) {
t.jquery && (t = t[0]);
return (e = e || this.getRangy()) ? (this.savedSel = e.getBookmark(t), this.savedSel) : void 0
}
},
restoreSelection: function(t, e) {
if (!t) return window.getSelection().removeAllRanges();
if (t.jquery && (t = t[0]), !t) return window.getSelection().removeAllRanges();
var n = "false" === t.getAttribute("contenteditable");
if (void 0 === e || null === e || "" === e ? e = this.savedSel : "number" == typeof e && (e = {
start: e,
end: e
}), !k(this.editor, t, e.start)) {
var i = o.createRange();
if (i.moveToBookmark({
start: e.start,
end: e.end,
containerNode: t
}), i.endContainer == t && 0 == i.endOffset && e.end > 0) {
var a = t.rawText().length;
e.end > a && i.moveToBookmark({
start: Math.min(e.start, a),
end: Math.min(e.end, a),
containerNode: t
})
}
if ("BODY" == document.activeElement.tagName || document.activeElement.hasAttribute("tabindex")) {
var s = r("content").scrollTop();
this.editor.writingArea.focus(), r("content").scrollTop(s)
}
return i.collapsed && this.deRange(i), n && t.setAttribute("contenteditable", "true"), this.setRange(i), !n || t.classList.contains("md-def-link") || t.classList.contains("md-def-footnote") || t.setAttribute("contenteditable", "false"), i
}
},
getVeryFirstElem: function(t) {
return t.children("[cid]").length > 0 ? this.getVeryFirstElem(t.children("[cid]").first()) : t
},
getVeryLastElem: function(t) {
return t.children("[cid]").length > 0 ? this.getVeryLastElem(t.children("[cid]").last()) : t
},
getSelection: function() {
return this.rangy.getSelection()
},
prepNode: function(t, e, n, i) {
var r, a = this.editor,
c = this.getRangy(),
f = this.editor.undo.UndoManager,
h = f.SnapFlag,
d = c && !c.collapsed;
v = void 0, File.inBusyMode && setAttributeOnlyNeeded(this.editor.writingArea, "contenteditable", "false");
try {
if (d) {
if (n) return r;
if (a.UserOp.surroundPair(a, t, c)) return void(e && e.preventDefault());
r = a.UserOp.backspaceHandler(a, null, "delSelection", !0, !0)
}
c = this.getRangy();
var m, p, g = this.rangy.getSelection(),
b = g.anchorOffset == o.dom.getNodeLength(g.anchorNode),
y = a.getJQueryElem(g.anchorNode),
w = a.getMarkElem(g.anchorNode),
F = a.findNodeByElem(w),
k = c.getBookmark(w[0]);
if (y.hasClass("ty-input")) return;
if (r || n || (a.undo.addSnap(F.cid, h.NONE), a.brush.addToQueue(F.cid)), File.inBusyMode) {
var x = y.closest("[contenteditable='true']");
document.activeElement !== x[0] && x.focus()
}
if (y.hasClass("md-def-url") && (t.match(/\s/g) || []).length) return b && this.jumpIntoElemBegin(w.find(".md-def-title")), e && e.preventDefault();
!n && r && a.undo.addSnap(w.attr("cid"), t.length > 1 ? h.REPLACE : h.ADD, a.docMenu.getAttrByElem(y));
if ((w.is(".unholdable") ? w : w.closest(".unholdable")).find(".math-jax-postprocess>.md-math-after-sym").text(""), u.isType(F, l.def_link, l.def_footnote)) {
if (w[0] == y[0] && c.collapsed) return void this.jumpIntoElemBegin(w.find(".md-def-name"))
} else F.get("type") == l.meta_block || F.get("type") == l.fences || (F.isBlock() && F.canNotDirectEdit() ? (window.getSelection().removeAllRanges(), e && e.preventDefault()) : y.hasClass("md-image") && (1 != c.startOffset || y.prev().length || (y.before("​"), c.setStartBefore(y.parent()), g.setSingleRange(c))));
if (F.get("children").length) {
var _ = window.getSelection().anchorNode.childNodes,
$ = window.getSelection().anchorOffset,
E = $ > 0 ? _[$ - 1] : null,
C = $ < _.length ? _[$] : null,
A = a.findNodeByElem(E ? a.getMarkElem(E) : []),
S = a.findNodeByElem(C ? a.getMarkElem(C) : []);
if (t = t.replace("​", ""), u.isType(S, s.TYPE.table)) {
a.undo.endSnap(!0), r = r || f.makeEmptyCommand();
var T = new u({
type: s.TYPE.paragraph,
text: t,
in: S.get("in")
});
S.insert(T, !0), f.addUndoForInsert(r, T), a.findElemById(S.id).before(T.toHTML()), a.selection.restoreSelection(a.findElemById(T.id)[0], t.length), m = T
} else if (u.isType(A, s.TYPE.table)) {
a.undo.endSnap(!0), r = r || f.makeEmptyCommand();
T = new u({
type: s.TYPE.paragraph,
text: t,
in: A.get("in")
});
A.insert(T), f.addUndoForInsert(r, T), a.findElemById(A.id).after(T.toHTML()), a.selection.restoreSelection(a.findElemById(T.id)[0], t.length), m = T
} else S ? (S = S.getVeryFirst(), a.undo.addSnap(S.cid, h.NONE), S.set("text", t + S.safeGetStrAttr("text", !0)), a.findElemById(S.id).replaceWith(S.toHTML()), S && a.selection.jumpInto(a.findElemById(S.id), 1), r = null) : A && (A = A.getVeryFirst(!0), a.undo.addSnap(A.cid, h.NONE), A.set("text", A.safeGetStrAttr("text", !0) + t), a.findElemById(A.id).replaceWith(A.toHTML()), a.selection.jumpIntoElemEnd(a.findElemById(A.id)), r = null);
r && r.redo.push(this.buildUndo()), !n && a.refocus(m.id), e && e.preventDefault()
}
return n || (d ? r && (a.UserOp.insertInlineText(a, F, t, k.start, r, !0), e && e.preventDefault()) : ((p = a.UserOp.hanldePair(a, t, F, k, r, c)) || (p = a.UserOp.PunctuationOp.handlerCh(a, t, F, k, r, c)), p || (p = a.htmlBlock.autoCloseTagWhenInput(a, t, F, k, r, c)), p && ("object" == typeof p && (r = p), e && e.preventDefault()))), !n && r && this.editor.undo.register(r), r
} catch (t) {
console.warn(t)
}
},
getPosBookmark: function() {
var t = editor.getMarkElem();
if (t.length) {
var e = this.editor.fences.queue[t.attr("cid")];
if (e) return {
isCm: e,
cid: e.cid,
start: e.indexFromPos(e.getCursor())
};
return null
}
},
getRangy: function(t) {
var e = this.rangy.getSelection(),
n = e.rangeCount ? e.getRangeAt(0) : null;
return n && (n.isBackward = e.isBackward(), t && this.deRange(n)), n
},
buildUndo: function(t, e) {
var n = {};
if (n.type = "cursor", this.editor.sourceView.inSourceMode) return n.pos = this.editor.sourceView.cm.getCursor(), n.inSourceMode = !0, n;
try {
if ((e = ((t = t || this.getRangy()) && t.commonAncestorContainer ? this.editor.getMarkElem(t.commonAncestorContainer) : e) || this.editor.getMarkElem()).find(".CodeMirror").length) {
var i = e.find(".CodeMirror")[0].CodeMirror;
n.id = i.cid, n.pos = i.getCursor(), n.selections = i.listSelections()
} else if (e.attr("mdtype") && e.children("[tabindex]").addBack("[tabindex]").length) n.id = e.attr("cid"), n.focus = e.attr("mdtype");
else {
if (!t) return null;
var r = this.editor.getMarkElem(this.getDetailPos(t.startContainer, t.startOffset)[0]),
o = this.editor.getMarkElem(this.getDetailPos(t.endContainer, t.endOffset)[0]),
a = t.getBookmark(r[0]);
if (r[0] === o[0]) {
if (n.id = r.attr("cid"), !n.id) return null;
n.start = a.start, n.end = a.end
} else {
if (n.startId = r.attr("cid"), n.endId = o.attr("cid"), !n.startId || !n.endId) return null;
n.start = a.start, n.end = t.getBookmark(o[0]).end
}
}
} catch (t) {
return t.stack, null
}
return n
},
selectNode: function(t, e) {
(e = e || editor.findElemById(t.id)).length && void 0 !== e.attr("tabindex") && (window.getSelection().removeAllRanges(), e.addClass("onfocus"), e.focus())
},
extendToLineEdge: function(t, e, n) {
e = e || this.editor.getMarkElem()[0];
var i = this.getRangy();
if (i && e && !isInputComponent(e)) {
var r = i.getBookmark(e),
a = o.createRange();
return t ? r.end = e.textContent.length : r.start = 0, a.moveToBookmark(r), !n && this.setRange(a), a
}
},
extendCharFromCollapse: function(t, e) {
var n, i = !1,
r = !e;
if (t.commonAncestorContainer.nodeType == document.TEXT_NODE && (e && t.startOffset > 0 && (t.setStart(t.startContainer, t.startOffset - 1), t.startOffset > 0 && (n = t.toString().charCodeAt(0)) >= 56320 && n <= 57343 && (t.setStart(t.startContainer, t.startOffset - 1), (n = t.toString().charCodeAt(0)) >= 55296 && n <= 56319 || t.setStart(t.startContainer, t.startOffset + 1)), i = !0), r && t.endOffset < t.commonAncestorContainer.textContent.length && (t.setEnd(t.endContainer, t.endOffset + 1), (n = t.toString().charCodeAt(t.toString().length)) >= 55296 && n <= 56319 && t.endOffset < t.commonAncestorContainer.textContent.length && t.setEnd(t.endContainer, t.endOffset + 1), i = !0)), !i) {
var o = this.editor.getMarkElem(t.startContainer)[0],
a = t.getBookmark(o);
if (e && 0 === a.start || r && a.end >= o.textContent.length) return !1;
if (e ? a.start-- : a.end++, o.classList.contains("md-def-link") || o.classList.contains("md-def-footnote")) {
var s = o.querySelector(".md-def-name").textContent.length;
a.start != s && a.start != s + 1 + o.querySelector(".md-def-content").textContent.length || (e ? (a.end - a.start <= 1 && a.end--, a.start--) : (a.end - a.start <= 1 && a.start++, a.end++))
}
t.moveToBookmark(a)
}
return t
},
moveLeftOrRight: function(t, e) {
v = void 0;
var n = this.editor.getMarkElem()[0],
i = this.getRangy(),
a = this.editor;
if (!(e && isInputComponent(e.target) || !i) && n) {
!File.inBusyMode || i && !r(i.startContainer).closest("[contenteditable='false'][cid]").length || a.writingArea.setAttribute("contenteditable", "true");
var s;
if (!e || !(s = r(e.target).closest("[mdtype='table_cell']")).length || s.closest("th").length && !s.closest("th").prev().length) {
var u = i.getBookmark(n),
c = o.createRange();
if (e && i.toString().length && !e.metaKey && !e.ctrlKey && !e.shiftKey) {
i.collapse(t), this.setRange(i, !0);
var l = this.editor.getMarkElem(i.startContainer);
return l.length && _(this.editor, !t, this.editor.findNodeByElem(l)), e.preventDefault(), !0
}
if (e && !e.metaKey) {
if (t && 0 === u.start) return this.moveUpOrDown(!0, e, !0);
if (!t && u.end >= n.textContent.length && (!n.classList.contains("md-def-link") || 0 != a.getJQueryElem(i.startContainer).closest(".md-def-title").length)) return this.moveUpOrDown(!1, e, !0);
var f = document.querySelector(".ty-focusable-btn.selected");
if (f && !e.ctrlKey && !e.shiftKey && u.end == u.start) return f.classList.remove("selected"), u.end += t ? -1 : 1, u.start += t ? -1 : 1, c.moveToBookmark(u), this.setRange(c, !0), e.preventDefault(), !0
}
if (File.isNodeHtml && !t && e && e.ctrlKey && !e.shiftKey) {
var h = n.textContent.substring(u.end) || "";
if (/^\w+$/.exec(h)) return u.start = u.end = n.textContent.length, c.moveToBookmark(u), this.setRange(c, !0), e.preventDefault(), !0
}
if (t ? (u.end = u.start, u.start--) : (u.start = u.end, u.end++), c.moveToBookmark(u), /\u200b|\007F/g.exec(c.toString())) return c.collapse(t), this.setRange(c, !0), !0;
if (d = c, r(t ? d.startContainer : d.endContainer).closest(".md-inline-math").addClass("md-expand").length && !e.ctrlKey && !e.metaKey && !e.altKey) return c.collapse(t), this.setRange(c, !0), e && e.preventDefault(), !0;
var d
}
}
},
addUnholdable: function(t, e, n, i) {
var o = function(t, e, n) {
var i = l.paragraph;
t.get("type") == l.list_item && (i = l.list_item);
var r = new u({
type: i
});
return t.insert(r, e), u.normalizeNode(r), r
}(t, n),
a = this.editor.findElemById(t.id),
s = n ? t : void 0,
c = n ? void 0 : t;
return n ? a.before(o.toHTML()) : a.after(o.toHTML()), e = e || this.editor.undo.UndoManager.makeEmptyCommand(), r(".unholdable").removeClass("unholdable"), this.editor.findElemById(o.id).addClass(i ? "" : "unholdable"), this.editor.undo.UndoManager.addUndoForInsert(e, o, c, s), e.discardable = !0, o
},
jumpToNextBlock: function(t, e) {
var n, i = t.getClosetBlock(!0).getVeryFirstBrotherIncludeTopBlock(!1);
if (i);
else {
if (!e) return void window.getSelection().removeAllRanges();
i = this.addUnholdable(t, e)
}
n = this.editor.findElemById(i.cid), this.jumpIntoElemBegin(n), e.redo.push(this.buildUndo());
var r = this.editor;
setTimeout(function() {
r.refocus()
}, 50)
},
moveUpOrDown: function(t, e, n) {
File.inBusyMode && e && (e.shiftKey || e.metaKey || e.ctrlK) && this.editor.writingArea.setAttribute("contenteditable", "true");
var i, o = this.getRangy(),
a = this,
f = e && u.isType(c[e.keyCode || e.which], "Right", "Left"),
h = File.isNode && e && e.ctrlKey && !e.shiftKey;
function d(t, e) {
return e ? !t || u.isType(t, l.fences, l.html_block, l.table, l.math_block, l.hr, l.toc) : u.isType(t, l.fences, l.html_block, l.table, l.math_block, l.hr, l.toc, l.def_footnote, l.def_link)
}
function m(t, e, n, i, r) {
var o = t.getVeryFirstBrotherIncludeTopBlock(e),
s = a.editor.undo.UndoManager.makeEmptyCommand();
return (!f && !o && !t.get(e ? "before" : "after") || d(t) && d(t.get(e ? "before" : "after"), !0)) && (e && u.isType(t, t.TYPE.meta_block) || (o = a.addUnholdable(function t(e, n) {
if (u.isType(e, l.fences, l.html_block, l.table, l.hr, l.def_link, l.def_footnote)) return e;
var i = n ? "before" : "after";
return e.get("parent") ? e.get("parent").get(i) ? e : e.get(i) ? e : t(e.get("parent")) : e
}(t), s, e))), s.undo.push(a.buildUndo()), n && n(), h ? a.jumpIntoElemBegin(a.editor.findElemById(o.id), !0) : b(o, i, s, r), s
}
function p(t, n, i) {
A = m(t.getClosetBlock(), n, void 0, i), e && e.preventDefault(), a.editor.undo.UndoManager.isEmptyCommand(A) || (A.redo.push(a.buildUndo()), a.editor.undo.register(A)), a.scrollAdjust()
}
function g(t, n, s, u) {
var c, f = s || a.editor.fences.getCm(t.id),
d = (f.doc.getCursor(), u[0].contains(document.activeElement) && document.activeElement.classList.contains("ty-input")),
p = n && 0 == f.doc.getCursor().line,
g = !n && f.doc.getCursor().line == f.lineCount() - 1;
if (p && n && (p = (c = f.cursorCoords().top) == f.cursorCoords({
line: 0,
ch: 0
}).top), g && !n && (g = (c = f.cursorCoords().top) == f.cursorCoords({
line: f.lineCount() - 1,
ch: f.getLine(f.lineCount() - 1).length
}).top), h && (p = !0), s || !r(".autoComplt-list").is(":visible")) {
if (void 0 == v && (v = d ? r(document.activeElement).offset().left + document.activeElement.clientWidth : f.cursorCoords(f.getCursor()).right), d) {
var b = document.activeElement.classList.contains("ty-input-before");
if (!b && n) return a.editor.fences.jumpCmEnd(f), x(f, v), y(e);
if (b && !n) return a.editor.fences.jumpCmBegin(f), x(f, v), y(e);
(g = g || document.activeElement.classList.contains("ty-input-after")) && r(document.activeElement).closest(".md-tooltip-hide").hide()
} else if (g && !n) {
if (t.get("type") == l.fences || t.get("type") == l.math_block && t.get("tagAfter")) return f.getInputField().blur(), setTimeout(function() {
a.selectAllElem(u.find(".ty-input-after").focus())
}, 0), y(e)
} else if (p && n && t.get("type") == l.math_block && t.get("tagBefore")) return f.getInputField().blur(), setTimeout(function() {
a.selectAllElem(u.find(".ty-input-before").focus())
}, 0), y(e);
if (p || g) {
var w = f.getCursor();
d || (h = !v && (0 == w.ch || c != f.cursorCoords({
line: w.line,
ch: w.ch - 1
}).top), i = $(o.nativeRange) || {}), A = m(t, n, function() {
f.getInputField().blur()
}, u, d ? v : i.x), n && !a.editor.undo.UndoManager.isEmptyCommand(A) && (A.redo.push(a.buildUndo()), a.editor.undo.register(A)), y(e)
}
e && e.stopPropagation()
}
}
function b(i, s, c, f) {
if (i) {
var h = a.editor.findElemById(i.id);
d = s.closest(".unholdable"), m = C, p = c, d.hasClass("unholdable") && m && (d.text().length ? d.removeClass("unholdable") : (a.editor.undo.UndoManager.addUndoForRemove(p, m), p.redo.push(a.buildUndo()), m.remove(), d.remove(), a.editor.undo.register(p)));
var d, m, p;
if (_(a.editor, t, i, e, c, v));
else {
if (F(h)) return y(e), h.find("img:first").trigger("click"), !0;
if (u.isType(i, l.table, l.table_row, l.table_cell)) a.jumpIntoElemBegin(h), y(e);
else if (u.isType(i, l.paragraph, l.heading, l.def_link, l.def_footnote) && !i.get("text")) a.jumpIntoElemBegin(h), e && e.preventDefault();
else if (u.isType(i, l.meta_block) && t) a.jumpIntoElemEnd(h), e && e.preventDefault();
else if (h.length) {
if (n || 0 == s.closest("#write").length) t ? a.jumpIntoElemEnd(h) : a.jumpIntoElemBegin(h);
else {
editor.selection.scrollAdjust(h, void 0, !0, !0), File.inBusyMode && editor.writingArea.setAttribute("contenteditable", "true");
var g = o && o.getBookmark(s[0]).end == s.text().length ? v : f;
if (void 0 != g) {
var b = a.getRangy(),
w = null;
if (b && b.nativeRange.getClientRects()[0] || void 0 != f) {
var k = (h.children[0] || h[0]).getBoundingClientRect(),
x = t ? k.y + k.height - 3 : k.y + 3;
w = document.caretRangeFromPoint(g, x)
}
w && (h[0] == w.startContainer || h[0].contains(w.startContainer)) ? a.setRange(w) : void 0 != f ? t ? a.jumpIntoElemEnd(h) : a.jumpIntoElemBegin(h) : window.getSelection().modify("move", t ? "backward" : "forward", "line")
} else t ? a.jumpIntoElemEnd(h) : a.jumpIntoElemBegin(h)
}
File.isFocusMode && (r(".md-focus").removeClass("md-focus"), h.addClass("md-focus")), y(e)
}
}
}
}
try {
var k = this.editor.getMarkElem(o && o.startContainer),
E = k.attr("mdtype"),
C = this.editor.findNodeByElem(k),
A = a.editor.undo.UndoManager.makeEmptyCommand();
if (!C) return;
if (w(C, k) || k.hasClass("rawedit")) p(C, t, k);
else if (E == s.TYPE.fences) g(C, t, void 0, k);
else if (E == s.TYPE.html_block && this.editor.htmlBlock.currentCm) g(C, t, this.editor.htmlBlock.currentCm, k);
else if (E == s.TYPE.math_block && this.editor.mathBlock.currentCm) g(C, t, this.editor.mathBlock.currentCm, k);
else if (k.closest(".td-span").length) {
var S = function(t, e) {
var n, i = t.closest("td"),
r = i.prevAll().length + 1;
if (!i.length) {
if (e) return [];
r = (i = t.closest("th")).prevAll().length + 1
}
return "TD" == i[0].tagName ? (n = i.closest("tr")[e ? "prev" : "next"]().find("td:nth-child(" + r + ")>.td-span"), e && !n.length && (n = i.closest("tbody").prev().find("tr:last > th:nth-child(" + r + ") > .td-span")), n) : e ? [] : i.closest("thead").next().find("tr:first > td:nth-child(" + r + ")>.td-span")
}(k.closest(".td-span"), t);
if (S.length) e && e.preventDefault(), t ? this.jumpIntoElemEnd(S) : this.jumpIntoElemBegin(S), this.scrollAdjust(void 0, void 0, !0);
else {
if (f) return y(e), !1;
p(C, t, k)
}
} else if (k.closest(".md-meta-block").length && !t) !k.text().substring(window.getSelection().focusOffset).match(/\S+\n+/) && p(C, t, k);
else {
void 0 == v && (v = (o.nativeRange.getClientRects()[0] || {}).left);
var T = C.getClosetBlock(!0).getVeryFirstBrotherIncludeTopBlock(t);
if (A.undo.push(this.editor.lastCursor), function(t, e, n) {
if ((n = n || this.getRangy()).collapsed) {
if (!(i = $(n.nativeRange)) || !t.length) return 0 == t.text().length;
var r = t[0].getBoundingClientRect();
return e ? !! function(t, e) {
var n = e.endContainer.nodeType == document.TEXT_NODE ? e.endContainer.parentElement.parentElement : null;
if (n && n.classList.contains("md-meta") && (n = n.parentElement), n && n.classList.contains("md-image")) {
if (e.endContainer.textContent.length == e.endOffset && t.rawText().length == e.getBookmark(t[0]).end) return !0;
var i = e.nativeRange.getClientRects();
if (!i.length) return;
var r = i[i.length - 1],
o = document.elementFromPoint(r.x, r.y + 28);
if (o && "IMG" == o.tagName && (e.collapseAfter(o), t.rawText().length == e.getBookmark(t[0]).end)) return !0
}
}(t, n) || r.bottom - i.bottom < parseInt(t.css("paddingBottom")) + 10 : i.top - r.top < parseInt(t.css("paddingTop")) + 10
}
}.call(this, k, !t)) T ? b(T, k, A) : !t && k.text().trim().length && p(C, t, k);
else {
var M = r(o.commonAncestorContainer.parentElement);
if (!t && M.hasClass("md-image-after-src")) {
var D = M.closest(".md-image").next();
return D.length ? (a.jumpIntoElemBegin(D), y(e)) : p(C, t, k), !1
}
if (!t && o.collapsed && o.startContainer.parentElement.classList.contains("md-def-name") && i && i.left) {
var L = i.left,
R = t ? i.top - 9 : i.bottom + 9,
B = document.caretRangeFromPoint(L, R);
this.setRange(B, !0), y(e)
} else if (File.isTypeWriterMode && File.option.scrollWithCursor && i && i.left) {
L = i.left, R = t ? i.top - 9 : i.bottom + 9, B = document.caretRangeFromPoint(L, R);
this.editor.writingArea.contains(B.startContainer) && ($(B) || {}).top != i.top && (this.setRange(B), y(e))
}
}
}
} catch (t) {
t.stack
}
},
click: function(t, e, n) {
window.getSelection().removeAllRanges();
var i = document.createEvent("MouseEvent"),
r = document.elementFromPoint(t, e);
n = "click", i.initMouseEvent(n, !0, !0, window, null, t, e, 0, 0, !1, !1, !1, !1, 0, null), r.dispatchEvent(i)
},
jumpDefComponent: function(t) {
var e = this.editor.getMarkElem(),
n = o.createRange();
t ? (n.selectNodeContents(e.children(".md-def-name")[0]), this.deRange(n, !0)) : (n.selectNodeContents(e.children(".md-def-content")[0]), this.deRange(n, !0)), this.editor.refocus()
},
jumpSelection: function() {
return this.scrollAdjust(null, 20)
},
jumpTop: function(t) {
var e = this.editor;
if (e.sourceView.inSourceMode) e.sourceView.cm.execCommand("goDocStart");
else {
var n = this.getRangy();
t && n ? (n.setStart(e.writingArea, 0), this.deRange(n, !0)) : e.nodeMap && this.jumpIntoElemBegin(e.findElemById((e.nodeMap.getFirst() || {}).cid)), File.isTypeWriterMode || r("content").animate({
scrollTop: 0
}, "100", "swing", function() {
e.library.outline.highlightVisibleHeader()
})
}
},
jumpBottom: function(t) {
var e = this.editor;
if (e.sourceView.inSourceMode) e.sourceView.cm.execCommand("goDocEnd");
else {
var n = this.getRangy();
if (t && n) {
n.setEnd(e.writingArea, e.writingArea.childNodes.length), n = this.deRange(n, !0);
try {
n.endContainer.parentElement.classList.contains("md-def-title") && "" == n.endContainer.parentElement.textContent && (n.setEndAfter(n.endContainer.parentElement.previousSibling.previousSibling), n = this.deRange(n, !0))
} catch (t) {}
} else this.jumpIntoElemEnd(this.editor.findElemById(this.editor.nodeMap.getLast().getVeryFirst(!0).cid));
File.isTypeWriterMode || r("content").animate({
scrollTop: document.querySelector(this.editor.sessionStr).scrollHeight - window.innerHeight
}, "100", "swing", function() {
e.library.outline.highlightVisibleHeader()
})
}
},
lockScroll: function() {
d = !0
},
unlockScroll: function() {
d = !1
},
typeWriterScroll: function(t, e, n) {
d = !1;
var i = this.editor;
function o(t) {
return !(!t || 0 == t.top && 0 == t.bottom) && (t = t.top - b / 2 + i.defaultTextHeight / 2, Math.abs(t) > 2 && (n ? r("content").animate({
scrollTop: r("content").scrollTop() + t
}, 120, "swing", n) : r("content").scrollTop(r("content").scrollTop() + t)), !0)
}
if (File.isTypeWriterMode) {
var a;
if (e) return void((a = t.jquery && t.length && t[0].getBoundingClientRect()) && (a = document.caretRangeFromPoint((a.left + a.right) / 2, a.bottom - 10), this.typeWriterScroll(a)));
if (!t || t.getBoundingClientRect) return void((a = t || window.getSelection().rangeCount && window.getSelection().getRangeAt(0)) && (a.startContainer.nodeType == document.TEXT_NODE && a.startContainer.parentElement.hasAttribute("cid") ? o(a.startContainer.parentElement.getBoundingClientRect()) : o($(a))));
t.top ? o(t) : t.jquery && t.length && o(t[0].getBoundingClientRect())
}
},
scrollAdjust: function(t, e, n, i) {
if (this.editor.sourceView && this.editor.sourceView.inSourceMode) this.editor.sourceView.scrollAdjust();
else {
if (File.isTypeWriterMode && !i) return this.typeWriterScroll(t);
n && (n = window.isNaN(n - 0) ? 70 : n);
try {
var o, a, s, u = window.innerHeight,
c = r("content").scrollTop(),
l = this.editor,
f = t && t.jquery && t.closest("[mdtype='heading']").toArray();
if (t && t.jquery) {
if (!t.length) return;
o = t.offset().top + c
} else if (t && void 0 !== t.startContainer) o = (t.nativeRange || t).getClientRects()[0].top + c;
else {
if (r(document.activeElement).closest(".CodeMirror-focused").find(".CodeMirror-selected").length) return this.scrollAdjust(selectedCodeMirrorDom);
(a = window.getSelection().getRangeAt(0)) ? ((s = a.getClientRects()[0]) || (s = a.endContainer.nodeType === document.TEXT_NODE ? a.endContainer.parentElement.getClientRects()[0] : a.endContainer.getClientRects()[0]), o = s.top + c) : o = r(document.activeElement).offset().top
}
var h = (File.isNodeHtml ? r("#top-titlebar").height() : document.body.classList.contains("mac-seamless-mode") ? 30 : 0) + (r("#md-searchpanel:visible").height() || 0);
void 0 !== e && null !== e ? r("content").animate({
scrollTop: o - e - h
}, "500", "swing", function() {
l.library.outline.highlightVisibleHeader(f)
}) : o > u + c - (n ? 70 : 140) + h ? d(o - u + (n || 140)) : o < c + h ? d(o - h - (n || 140)) : l.library.outline.highlightVisibleHeader()
} catch (t) {}
}
function d(t) {
r("content").scrollTop(t), l.library.outline.highlightVisibleHeader(), g()
}
},
selectAllElem: function(t) {
if (!t[0] || "INPUT" != t[0].tagName && "TEXTAREA" != t[0].tagName)
if (this.editor.sourceView.inSourceMode) this.editor.sourceView.cm.execCommand("selectAll");
else {
if (r("body").hasClass("typora-sourceview-on")) return this.editor.sourceView.cm.execCommand("selectAll");
r(".math-jax-postprocess>.md-math-after-sym").text("​");
var e = o.createRange();
t.children().length ? (e.setStart(t.children()[0]), e.setEndAfter(t.children()[t.children().length - 1])) : e.selectNode(t[0]), this.deRange(e, !0)
}
else t[0].select()
},
selectAll: function(t) {
if (this.editor.sourceView.inSourceMode) this.editor.sourceView.cm.execCommand("selectAll");
else if (File.inBusyMode && !File.isLocked && this.editor.writingArea.setAttribute("contenteditable", "true"), r(".math-jax-postprocess>.md-math-after-sym").text("​"), document.activeElement && u.isType(document.activeElement.tagName, "INPUT", "TEXTAREA")) document.activeElement.select();
else {
var e = this.editor.getMarkElem(),
n = o.createRange();
if (e.hasClass("rawedit")) t || (n.selectNode(e[0]), this.setRange(n));
else {
if (t && u.isType(t.target.tagName, "INPUT", "TEXTAREA")) return t.target.select(), !0;
if (isInputComponent(t && t.target || document.activeElement)) return this.selectAllElem(r(t && t.target || document.activeElement)), !1;
if (e.find(".CodeMirror").length) {
e.find(".CodeMirror")[0].CodeMirror.execCommand("selectAll")
} else e.closest('[mdtype="table"]').length ? (this.selectAllElem(e.closest("[mdtype='table_cell']")), t && t.preventDefault()) : e.closest(".md-meta-block").length ? (this.selectAllElem(e.closest("[mdtype='meta_block']")), t && t.preventDefault()) : (r(this.editor.sessionStr).addClass("md-expand"), r(".footnotes, .md-fences, .hr, .md-rawblock").attr("contenteditable", !0), n.setStart(r(this.editor.sessionStr).children()[0]), r(this.editor.sessionStr).children()[0].classList.contains("md-hr") && n.setStart(r(this.editor.sessionStr).children()[1]), n.setEndAfter(r(this.editor.sessionStr).children().last()[0]), r(this.editor.sessionStr).removeClass("md-expand"), n = this.deRange(n), this.fixSafariRange(n), this.setRange(n), t && t.preventDefault(), File.isMac && setTimeout(function() {
r(".footnotes, .md-fences, .hr, .md-rawblock").prop("contenteditable", !1)
}, 10))
}
this.editor.lastCursor = this.buildUndo()
}
},
getEndNode: function(t) {
return this.getDetailPos(t.endContainer, t.endOffset)[0]
},
getDetailPos: function(t, e, n) {
var i = {};
function r(t) {
1 === t.nodeType && 0 === t.childNodes.length && t.appendChild(document.createTextNode(""))
}
function o(t) {
if (r(t), t.childNodes.length) return t.childNodes.length;
if (3 === t.nodeType) return t.textContent.length;
if (void 0 !== t.length) return t.length;
throw i
}
if (t.parentElement && t.parentElement.classList.contains("md-def-split")) return 0 == e ? this.getDetailPos(t.parentElement.previousElementSibling, t.parentElement.previousElementSibling.textContent.length, n) : this.getDetailPos(t.parentElement.nextElementSibling, 0, n);
if (1 == t.nodeType) {
var a = t.childNodes;
if (t.classList.contains("md-image") && 2 === e && (e = 1), r(t), !a || !a.length || t.classList && t.classList.contains("md-fences")) return [t, e];
try {
var s = a[e] && a[e].getAttribute && "checkbox" === a[e].getAttribute("type");
return n ? (s && e++, e == a.length ? this.getDetailPos(a[e - 1], o(a[e - 1])) : this.getDetailPos(a[e], 0, !0)) : 0 == e ? (s && e++, this.getDetailPos(a[e], 0)) : this.getDetailPos(a[e - 1], o(a[e - 1]))
} catch (n) {
return [t, e]
}
}
return [t, e]
},
fixSafariRange: function(t) {
if (File.isSafari) {
var e, n, i = r(t.startContainer).closest(".md-meta, .md-content");
i.length && 0 == t.startOffset && (n = (e = i.closest("[contenteditable='true'], [cid]")).children()[0]) && t.setStart(n, 0), (i = r(t.endContainer).closest(".md-meta, .md-content")).length && ((e = i.closest("[contenteditable='true'], [cid]")).hasClass("md-meta") && (e = e.parent().closest("[contenteditable='true'], [cid]")), (n = e.children().last()[0]) && t.setEndAfter(n))
}
},
deRange: function(t, e, n) {
var i = t.cloneRange();
try {
var r = this.getDetailPos(t.startContainer, t.startOffset, !0),
o = this.getDetailPos(t.endContainer, t.endOffset, !1);
return e && r[0].parentElement && "HR" == r[0].parentElement.tagName && (r[0] = r[0].parentElement.parentElement), t.setStart.apply(t, r), t.setEnd.apply(t, o), n && n.equals(t) ? n : (e && this.setRange(t, !0), t)
} catch (t) {}
return i
},
selectLine: function() {
var t, e;
if (this.editor.sourceView.inSourceMode) return e = (t = this.editor.sourceView.cm).getCursor(), void t.setSelection(a.Pos(e.line, 0), a.Pos(e.line, t.getLine(e.line).length));
var n = r(document.activeElement).closest(".CodeMirror");
if (n.length) return e = (t = n[0].CodeMirror).getCursor(), void t.setSelection(a.Pos(e.line, 0), a.Pos(e.line, t.getLine(e.line).length));
if (document.activeElement && u.isType(document.activeElement.tagName, "INPUT")) document.activeElement.select();
else {
if (window.getSelection().rangeCount) {
var i = window.getSelection(),
s = this.editor.getMarkElem(i.commonAncestorContainer),
c = o.createRange();
if (s.length)
if (s.closest("tr[mdtype='table_row']").length) {
var l = s.closest("tr[mdtype='table_row']");
c.selectNode(l[0]), l.closest('[mdtype="table"]').attr("contenteditable", !0), this.deRange(c, !0), l.closest('[mdtype="table"]').attr("contenteditable", !1)
} else {
s.addClass("md-expand-on-selection"), window.getSelection().modify("move", "backward", "sentence"), window.getSelection().modify("extend", "forward", "sentence"), c = this.getRangy();
var f = r(c.commonAncestorContainer).closest(".md-meta");
f.length ? this.selectAllElem(f.closest("[md-inline]")) : (f = this.editor.getMarkElem(c.startContainer)).length && f[0] !== this.editor.getMarkElem(c.endContainer)[0] && (c.setEndAfter(f[0]), this.deRange(c, !0)), s.removeClass("md-expand-on-selection")
}
}
this.editor.wordCount.updateInSelection()
}
},
selectWord: function(t, e, n) {
var o, a;
if (this.editor.sourceView.inSourceMode) return a = (o = this.editor.sourceView.cm).findWordAt(o.getCursor()), void o.extendSelection(a.anchor, a.head);
this.selectWordTime = new Date;
var s = r(document.activeElement).closest(".CodeMirror");
if (s.length) return a = (o = s[0].CodeMirror).findWordAt(o.getCursor()), void o.extendSelection(a.anchor, a.head);
if (n = n || this.getRangy()) {
var u = null;
if (t && (u = r(n.startContainer).closest(".md-meta, .md-content")).length) return n.selectNode(u.closest("[md-inline]")[0]), void this.setRange(n);
if ((u = r(n.startContainer).closest(".md-content, [md-inline='url'], [md-inline='emoji'], [md-inline='escape']")).length) return n.selectNode(u.closest("[md-inline]")[0]), void this.setRange(n, !0);
if ((u = r(n.startContainer).closest("[md-inline]")).length || (u = r(n.startContainer).closest("[cid]")), u.length) {
var c = n.getBookmark(u[0]).start,
l = u.text(),
h = /[\u3040-\uABFF\uD7A4-\uFAFF]/,
d = [],
m = null;
if (l.split(f).filter(function(t) {
return !!t
}).forEach(function(t) {
h.test(t) ? m ? m += t : m = t : (m && d.push(m), d.push(t), m = null)
}), m && d.push(m), d.length) {
var v = 0,
p = l.length,
g = 0,
b = 0,
y = !1;
for (b = 0; b < d.length; b++) {
var w = d[b].length;
if (g + w >= c) {
y = g + w == c;
break
}
g += w
}
if (b >= d.length - 1) {
if (v = (p = l.length) - d.last().length, t && i.NOT_WORD.exec(d.last())) return
} else if (y && !i.NOT_WORD.exec(d[b + 1])) p = (v = g + d[b].length) + d[1 + b].length, e && /\s/.exec(d[b + 2] || "a") && (p += 1);
else if (i.NOT_WORD.exec(d[b])) {
if (t) return;
p = (v = g + d[b].length) + d[1 + b].length
} else p = (v = g) + d[b].length, e && /\s/.exec(d[b + 1] || "a") && (p += 1);
n.moveToBookmark({
containerNode: u[0],
start: v,
end: p
}), this.setRange(n, !0), this.editor.wordCount.updateInSelection()
}
}
}
},
selectPhrase: function() {
if (this.editor.sourceView.inSourceMode) {
var t = this.editor.sourceView.cm,
e = t.findWordAt(t.getCursor());
t.extendSelection(e.anchor, e.head)
} else if (document.activeElement && u.isType(document.activeElement.tagName, "INPUT")) document.activeElement.select();
else {
var n, i = this.getRangy(!0),
o = !1;
if (i) {
if (this.editor.styleBookmark.style) {
var a = this.editor.styleBookmark.style.block;
if (a.indexOf(l.def_footnote) > -1 || a.indexOf(l.def_link) > -1 ? /md-def-(name|url|title)|/gi.exec(document.activeElement.className) && (o = !0, n = r(i.startContainer).closest(".md-def-name, .md-def-url, .md-def-title")[0]) : a.indexOf(l.table) > -1 && (o = !0, n = r(i.startContainer).closest("[mdtype='table_cell']")[0]), n = n || function t(e) {
return e ? e.nodeType === e.ELEMENT_NODE ? e.hasAttribute("md-inline") && e.getAttribute("md-inline") !== l.plain ? e : e.hasAttribute("mdtype") ? e : e.classList.contains("md-def-name") || e.classList.contains("md-def-content") || e.classList.contains("md-def-title") ? e : t(e.parentElement) : e.nodeType === e.TEXT_NODE ? t(e.parentElement) : null : null
}(i.startContainer)) return c = i, f = o, (s = n).getAttribute("md-inline") == l.image && (f = !1, s = s.children[0]), f ? c.selectNodeContents(s) : (c.selectNode(s), editor.selection.deRange(c)), this.setRange(i, !0)
}
return this.selectWord()
}
var s, c, f
}
},
isCrossBlock: function(t) {
return (t = t || this.getRangy()) ? !t.collapsed && this.editor.getJQueryElem(t.commonAncestorContainer).find("[mdtype]").length : t
},
handleMouseSelection: function(t) {
if ("false" == this.editor.writingArea.getAttribute("contenteditable")) {
this.getBlockFromMouseEvent(t).closest(".md-focus").length || this.editor.writingArea.setAttribute("contenteditable", "true")
}
},
getBlockFromMouseEvent: function(t) {
var e = t.target;
return this.editor.writingArea.contains(t.target) || (e = document.elementFromPoint(t.clientX, t.clientY)), r(e).closest("[cid]")
},
getTextAround: function() {
var t, e, n = this.getRangy();
if (n && n.collapsed) {
var i = r(n.startContainer).closest("[md-inline='plain'], .md-lang")[0];
if (i) {
var o = n.getBookmark(i);
return n.setStartBefore(i), t = n.toString(), n.collapse(!1), n.setEndAfter(i), e = n.toString(), n.setStart(i, 0), [t, e, o]
}
}
return []
},
getTextInSelection: function() {
var t = r(document.activeElement).closest(".CodeMirror");
if (t.length) {
return t[0].CodeMirror.getSelection()
}
var e = this.getRangy();
if (e && !e.collapsed && r(e.commonAncestorContainer).closest("#write").length) {
return r(r.parseHTML("<div>" + e.toHtml() + "</div>")).find("[mdtype]").after("\n").filter(".md-toc").text("[toc]").end().filter(".md-math-block").text(function() {
return r(this).find("script").html()
}).end().find(".CodeMirror-gutter-wrapper").remove().end().end().text()
}
return ""
},
extendRange: function(t, e) {
if (t.commonAncestorContainer.nodeType === document.TEXT_NODE) {
if (e > 0 && t.endOffset + e <= t.commonAncestorContainer.length) return t.setEnd(t.commonAncestorContainer, t.endOffset + e), t;
if (e < 0 && t.startOffset + e >= 0) return t.setStart(t.commonAncestorContainer, t.startOffset + e), t
}
var n = r(t.startContainer).closest("[cid]")[0],
i = t.getBookmark(n);
return e > 0 ? i.end += e : i.start += e, t.moveToBookmark(i), t
},
createRange: function(t, e, n, i) {
var r = o.createRange();
return r.setStart(t, e), r.setEnd(n, i), r.startContainer ? r : null
},
moveToSelectable: function(t, e) {
return _(this.editor, t, e)
},
includeTrailMeta: function(t) {
if (!t || t.collapsed) return t;
function e(n, i, o) {
var a = i ? n.previousElementSibling : n.nextElementSibling;
return n == t.commonAncestorContainer || n.parentElement == t.commonAncestorContainer || !n.parentElement || n.getAttribute && n.getAttribute("cid") ? o : (a && a.classList && a.classList.contains("md-meta") && !r(a.parentElement).closest(".md-expand").length && (o = a), e(n.parentElement, i, o))
}
var n;
if (0 == t.startOffset) {
var i = e(t.startContainer, !0);
i && (n = !0, t.setStart(i, 0))
}
if (t.endContainer.childNodes && t.endOffset == t.endContainer.childNodes.length || t.endContainer.nodeType == document.TEXT_NODE && t.endOffset == t.endContainer.nodeValue.length) {
var o = e(t.endContainer, !1);
o && (n = !0, t.setEnd(o, o.childNodes.length))
}
return n && this.setRange(t, !0), t
}
};
var y = function(t) {
t && (t.codemirrorIgnore = !0, t.preventDefault(), t.stopPropagation())
},
w = function(t, e) {
return u.isType(t, u.TYPE.hr, u.TYPE.toc) && (!e || e[0].hasAttribute("tabindex"))
},
F = function(t) {
var e = t[0];
return e.childElementCount > 0 && function() {
for (var t = 0; t < e.childElementCount; t++)
if (e.children[0].getAttribute("md-inline") !== l.image) return !1;
return !0
}()
},
k = function(t, e, n) {
var i;
if (e.getAttribute("mdtype") === l.fences && (i = t.fences.getCm(e.getAttribute("cid"))), e.getAttribute("mdtype") === l.math_block && (i = t.mathBlock.startEditing(r(e))), e.getAttribute("mdtype") === l.html_block && (i = t.htmlBlock.startEditing(r(e))), i) return i.focus(), i.setCursor(n), !0
},
x = function(t, e) {
if (void 0 != e) {
var n = t.cursorCoords(t.getCursor());
n.left = n.right = e;
var i = t.coordsChar(n);
t.setCursor(i)
}
},
_ = function(t, e, n, i, r, o) {
if (!n) return !1;
var a = t.findElemById(n.id);
t.lastCursor = t.selection.buildUndo();
var s = !r;
if (u.isType(n, l.fences)) return (c = t.fences.getCm(n.id)).focus(), e ? setTimeout(function() {
a.find(".ty-input-after").focus()
}, 0) : (c.execCommand(e ? "goDocEnd" : "goDocStart"), x(c, o)), y(i), !0;
if (u.isType(n, l.math_block)) return e ? (c = t.mathBlock.startEditing(a, !n.get("tagAfter") && "end", s), n.get("tagAfter") ? setTimeout(function() {
t.selection.selectAllElem(a.find(".ty-input-after").focus())
}, 0) : x(c, o)) : (c = t.mathBlock.startEditing(a, !n.get("tagBefore") && "start", s), n.get("tagBefore") ? setTimeout(function() {
t.selection.selectAllElem(a.find(".ty-input-before").focus())
}, 0) : x(c, o)), y(i), !0;
if (u.isType(n, l.html_block)) {
var c = t.htmlBlock.startEditing(a, e ? "end" : "start", s);
return x(c, o), y(i), !0
}
return !!w(n) && (y(i), window.getSelection().removeAllRanges(), t.findElemById(n.id).focus(), t.refocus(), !0)
},
$ = function(t) {
var e, n = t.getClientRects(),
i = n.length && n[n.length - 1];
return !i && t.collapsed ? "write" == (e = t.startContainer.nodeType == document.TEXT_NODE ? t.startContainer.parentElement : t.startContainer).getAttribute("id") ? null : (i = e.getBoundingClientRect()).height > 150 ? null : i : i
};
n.exports = h, n.exports.buildRange = function(t, e, n) {
if (!t) return window.getSelection().removeAllRanges();
var i = 0,
r = o.createRange(),
a = !1,
s = {};
r.collapseToPoint(t, 0);
try {
! function t(o) {
if (3 == o.nodeType) {
var u = i + o.textContent.length;
if (!a && e >= i && e <= u && (r.setStart(o, e - i), a = !0), a && n >= i && n <= u) throw r.setEnd(o, n - i), s;
i = u
} else
for (var c = 0, l = o.childNodes.length; c < l; ++c) t(o.childNodes[c])
}(t)
} catch (t) {
if (t == s) return r;
throw t
}
}, n.exports.rangy = o
}), $__System.registerDynamic("17", [], !0, function(t, e, n) {
this || self;
var i = ["a", "abbr", "acronym", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "decorator", "del", "details", "dfn", "dir", "div", "dl", "dt", "element", "em", "fieldset", "figcaption", "figure", "font", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", "i", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "marquee", "menu", "menuitem", "meter", "nav", "nobr", "ol", "optgroup", "option", "output", "p", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "section", "select", "shadow", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "iframe", "dialog", "embed"],
r = ["svg", "a", "altglyph", "altglyphdef", "altglyphitem", "animatecolor", "animatemotion", "animatetransform", "audio", "canvas", "circle", "clippath", "defs", "desc", "ellipse", "filter", "font", "g", "glyph", "glyphref", "hkern", "image", "line", "lineargradient", "marker", "mask", "metadata", "mpath", "path", "pattern", "polygon", "polyline", "radialgradient", "rect", "stop", "style", "switch", "symbol", "text", "textpath", "title", "tref", "tspan", "video", "view", "vkern"],
o = ["feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence"],
a = ["math", "menclose", "merror", "mfenced", "mfrac", "mglyph", "mi", "mlabeledtr", "mmuliscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mroot", "mrow", "ms", "mpspace", "msqrt", "mystyle", "msub", "msup", "msubsup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover"],
s = ["#text"],
u = ["accept", "action", "align", "alt", "autocomplete", "background", "bgcolor", "border", "cellpadding", "cellspacing", "checked", "cite", "class", "clear", "color", "cols", "colspan", "coords", "crossorigin", "datetime", "default", "dir", "disabled", "download", "enctype", "face", "for", "headers", "height", "hidden", "high", "href", "hreflang", "id", "integrity", "ismap", "label", "lang", "list", "loop", "low", "max", "maxlength", "media", "method", "min", "multiple", "name", "noshade", "novalidate", "nowrap", "open", "optimum", "pattern", "placeholder", "poster", "preload", "pubdate", "radiogroup", "readonly", "rel", "required", "rev", "reversed", "role", "rows", "rowspan", "spellcheck", "scope", "selected", "shape", "size", "sizes", "span", "srclang", "start", "src", "srcset", "step", "style", "summary", "tabindex", "title", "type", "usemap", "valign", "value", "width", "xmlns", "charset", "async", "srcdoc"],
c = ["accent-height", "accumulate", "additivive", "alignment-baseline", "ascent", "attributename", "attributetype", "azimuth", "basefrequency", "baseline-shift", "begin", "bias", "by", "class", "clip", "clip-path", "clip-rule", "color", "color-interpolation", "color-interpolation-filters", "color-profile", "color-rendering", "cx", "cy", "d", "dx", "dy", "diffuseconstant", "direction", "display", "divisor", "dur", "edgemode", "elevation", "end", "fill", "fill-opacity", "fill-rule", "filter", "flood-color", "flood-opacity", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "fx", "fy", "g1", "g2", "glyph-name", "glyphref", "gradientunits", "gradienttransform", "height", "href", "id", "image-rendering", "in", "in2", "k", "k1", "k2", "k3", "k4", "kerning", "keypoints", "keysplines", "keytimes", "lang", "lengthadjust", "letter-spacing", "kernelmatrix", "kernelunitlength", "lighting-color", "local", "marker-end", "marker-mid", "marker-start", "markerheight", "markerunits", "markerwidth", "maskcontentunits", "maskunits", "max", "mask", "media", "method", "mode", "min", "name", "numoctaves", "offset", "operator", "opacity", "order", "orient", "orientation", "origin", "overflow", "paint-order", "path", "pathlength", "patterncontentunits", "patterntransform", "patternunits", "points", "preservealpha", "preserveaspectratio", "r", "rx", "ry", "radius", "refx", "refy", "repeatcount", "repeatdur", "restart", "result", "rotate", "scale", "seed", "shape-rendering", "specularconstant", "specularexponent", "spreadmethod", "stddeviation", "stitchtiles", "stop-color", "stop-opacity", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke", "stroke-width", "style", "surfacescale", "tabindex", "targetx", "targety", "transform", "text-anchor", "text-decoration", "text-rendering", "textlength", "type", "u1", "u2", "unicode", "values", "viewbox", "visibility", "vert-adv-y", "vert-origin-x", "vert-origin-y", "width", "word-spacing", "wrap", "writing-mode", "xchannelselector", "ychannelselector", "x", "x1", "x2", "xmlns", "y", "y1", "y2", "z", "zoomandpan"],
l = ["accent", "accentunder", "align", "bevelled", "close", "columnsalign", "columnlines", "columnspan", "denomalign", "depth", "dir", "display", "displaystyle", "fence", "frame", "height", "href", "id", "largeop", "length", "linethickness", "lspace", "lquote", "mathbackground", "mathcolor", "mathsize", "mathvariant", "maxsize", "minsize", "movablelimits", "notation", "numalign", "open", "rowalign", "rowlines", "rowspacing", "rowspan", "rspace", "rquote", "scriptlevel", "scriptminsize", "scriptsizemultiplier", "selection", "separator", "separators", "stretchy", "subscriptshift", "supscriptshift", "symmetric", "voffset", "width", "xmlns"],
f = ["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"];
function h(t, e) {
for (var n = e.length; n--;) "string" == typeof e[n] && (e[n] = e[n].toLowerCase()), t[e[n]] = !0;
return t
}
function d(t) {
var e = {},
n = void 0;
for (n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
return e
}
var m = /\{\{[\s\S]*|[\s\S]*\}\}/gm,
v = /<%[\s\S]*|[\s\S]*%>/gm,
p = /^data-[\-\w.\u00B7-\uFFFF]/,
g = /^aria-[\-\w]+$/,
b = /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i,
y = /^(?:\w+script|data):/i,
w = /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g,
F = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
return typeof t
} : function(t) {
return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t
};
function k(t) {
if (Array.isArray(t)) {
for (var e = 0, n = Array(t.length); e < t.length; e++) n[e] = t[e];
return n
}
return Array.from(t)
}
var x = function() {
return "undefined" == typeof window ? null : window
};
var _ = function t() {
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : x(),
n = function(e) {
return t(e)
};
if (n.version = "1.0.4", n.removed = [], !e || !e.document || 9 !== e.document.nodeType) return n.isSupported = !1, n;
var _ = e.document,
$ = !1,
E = !1,
C = e.document,
A = e.DocumentFragment,
S = e.HTMLTemplateElement,
T = e.Node,
M = e.NodeFilter,
D = e.NamedNodeMap,
L = void 0 === D ? e.NamedNodeMap || e.MozNamedAttrMap : D,
R = e.Text,
B = e.Comment,
I = e.DOMParser,
N = e.XMLHttpRequest,
O = void 0 === N ? e.XMLHttpRequest : N,
j = e.encodeURI,
P = void 0 === j ? e.encodeURI : j;
if ("function" == typeof S) {
var q = C.createElement("template");
q.content && q.content.ownerDocument && (C = q.content.ownerDocument)
}
var U = C,
z = U.implementation,
H = U.createNodeIterator,
W = U.getElementsByTagName,
J = U.createDocumentFragment,
Y = _.importNode,
G = {};
n.isSupported = z && void 0 !== z.createHTMLDocument && 9 !== C.documentMode;
var K = m,
V = v,
Q = p,
X = g,
Z = y,
tt = w,
et = b,
nt = null,
it = h({}, [].concat(k(i), k(r), k(o), k(a), k(s))),
rt = null,
ot = h({}, [].concat(k(u), k(c), k(l), k(f))),
at = null,
st = null,
ut = !0,
ct = !0,
lt = !1,
ft = !1,
ht = !1,
dt = !1,
mt = !1,
vt = !1,
pt = !1,
gt = !1,
bt = !1,
yt = !0,
wt = !0,
Ft = {},
kt = h({}, ["audio", "head", "math", "script", "style", "template", "svg", "video"]),
xt = h({}, ["audio", "video", "img", "source", "image", "iframe"]),
_t = h({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "summary", "title", "value", "style", "xmlns"]),
$t = null,
Et = C.createElement("form"),
Ct = function(t) {
"object" !== (void 0 === t ? "undefined" : F(t)) && (t = {}), nt = "ALLOWED_TAGS" in t ? h({}, t.ALLOWED_TAGS) : it, rt = "ALLOWED_ATTR" in t ? h({}, t.ALLOWED_ATTR) : ot, at = "FORBID_TAGS" in t ? h({}, t.FORBID_TAGS) : {}, st = "FORBID_ATTR" in t ? h({}, t.FORBID_ATTR) : {}, Ft = "USE_PROFILES" in t && t.USE_PROFILES, ut = !1 !== t.ALLOW_ARIA_ATTR, ct = !1 !== t.ALLOW_DATA_ATTR, lt = t.ALLOW_UNKNOWN_PROTOCOLS || !1, ft = t.SAFE_FOR_JQUERY || !1, ht = t.SAFE_FOR_TEMPLATES || !1, dt = t.WHOLE_DOCUMENT || !1, pt = t.RETURN_DOM || !1, gt = t.RETURN_DOM_FRAGMENT || !1, bt = t.RETURN_DOM_IMPORT || !1, vt = t.FORCE_BODY || !1, yt = !1 !== t.SANITIZE_DOM, wt = !1 !== t.KEEP_CONTENT, et = t.ALLOWED_URI_REGEXP || et, ht && (ct = !1), gt && (pt = !0), Ft && (nt = h({}, [].concat(k(s))), rt = [], !0 === Ft.html && (h(nt, i), h(rt, u)), !0 === Ft.svg && (h(nt, r), h(rt, c), h(rt, f)), !0 === Ft.svgFilters && (h(nt, o), h(rt, c), h(rt, f)), !0 === Ft.mathMl && (h(nt, a), h(rt, l), h(rt, f))), t.ADD_TAGS && (nt === it && (nt = d(nt)), h(nt, t.ADD_TAGS)), t.ADD_ATTR && (rt === ot && (rt = d(rt)), h(rt, t.ADD_ATTR)), t.ADD_URI_SAFE_ATTR && h(_t, t.ADD_URI_SAFE_ATTR), wt && (nt["#text"] = !0), Object && "freeze" in Object && Object.freeze(t), $t = t
},
At = function(t) {
n.removed.push({
element: t
});
try {
t.parentNode.removeChild(t)
} catch (e) {
t.outerHTML = ""
}
},
St = function(t, e) {
try {
n.removed.push({
attribute: e.getAttributeNode(t),
from: e
})
} catch (t) {
n.removed.push({
attribute: null,
from: e
})
}
e.removeAttribute(t)
},
Tt = function(t) {
var e = void 0,
n = void 0;
if (vt && (t = "<remove></remove>" + t), E) {
try {
t = P(t)
} catch (t) {}
var i = new O;
i.responseType = "document", i.open("GET", "data:text/html;charset=utf-8," + t, !1), i.send(null), e = i.response
}
if ($) try {
e = (new I).parseFromString(t, "text/html")
} catch (t) {}
return e && e.documentElement || ((n = (e = z.createHTMLDocument("")).body).parentNode.removeChild(n.parentNode.firstElementChild), n.outerHTML = t), W.call(e, dt ? "html" : "body")[0]
};
n.isSupported && function() {
var t = Tt('<svg><g onload="this.parentNode.remove()"></g></svg>');
t.querySelector("svg") || (E = !0);
try {
(t = Tt('<svg><p><style><img src="</style><img src=x onerror=alert(1)//">')).querySelector("svg img") && ($ = !0)
} catch (t) {}
}();
var Mt = function(t) {
return H.call(t.ownerDocument || t, t, M.SHOW_ELEMENT | M.SHOW_COMMENT | M.SHOW_TEXT, function() {
return M.FILTER_ACCEPT
}, !1)
},
Dt = function(t) {
return "object" === (void 0 === T ? "undefined" : F(T)) ? t instanceof T : t && "object" === (void 0 === t ? "undefined" : F(t)) && "number" == typeof t.nodeType && "string" == typeof t.nodeName
},
Lt = function(t, e, i) {
G[t] && G[t].forEach(function(t) {
t.call(n, e, i, $t)
})
},
Rt = function(t) {
var e = void 0;
if (Lt("beforeSanitizeElements", t, null), !((i = t) instanceof R || i instanceof B || "string" == typeof i.nodeName && "string" == typeof i.textContent && "function" == typeof i.removeChild && i.attributes instanceof L && "function" == typeof i.removeAttribute && "function" == typeof i.setAttribute)) return At(t), !0;
var i, r = t.nodeName.toLocaleLowerCase();
if (Lt("uponSanitizeElement", t, {
tagName: r,
allowedTags: nt
}), !nt[r] || at[r]) {
if (wt && !kt[r] && "function" == typeof t.insertAdjacentHTML) try {
t.insertAdjacentHTML("AfterEnd", t.innerHTML)
} catch (t) {}
return At(t), !0
}
return !ft || t.firstElementChild || t.content && t.content.firstElementChild || !/</g.test(t.textContent) || (n.removed.push({
element: t.cloneNode()
}), t.innerHTML = t.textContent.replace(/</g, "&lt;")), ht && 3 === t.nodeType && (e = (e = (e = t.textContent).replace(K, " ")).replace(V, " "), t.textContent !== e && (n.removed.push({
element: t.cloneNode()
}), t.textContent = e)), Lt("afterSanitizeElements", t, null), !1
},
Bt = function(t) {
var e = void 0,
i = void 0,
r = void 0,
o = void 0,
a = void 0,
s = void 0,
u = void 0;
if (Lt("beforeSanitizeAttributes", t, null), s = t.attributes) {
var c = {
attrName: "",
attrValue: "",
keepAttr: !0,
allowedAttributes: rt
};
for (u = s.length; u--;) {
if (i = (e = s[u]).name, r = e.value.trim(), o = i.toLocaleLowerCase(), c.attrName = o, c.attrValue = r, c.keepAttr = !0, Lt("uponSanitizeAttribute", t, c), r = c.attrValue, "name" === o && "IMG" === t.nodeName && s.id) a = s.id, s = Array.prototype.slice.apply(s), St("id", t), St(i, t), s.indexOf(a) > u && t.setAttribute("id", a.value);
else {
if ("INPUT" === t.nodeName && "type" === o && "file" === r && (rt[o] || !st[o])) continue;
"id" === i && t.setAttribute(i, ""), St(i, t)
}
if (c.keepAttr && (!yt || "id" !== o && "name" !== o || !(r in C || r in Et))) {
if (ht && (r = (r = r.replace(K, " ")).replace(V, " ")), ct && Q.test(o));
else if (ut && X.test(o));
else {
if (!rt[o] || st[o]) continue;
if (_t[o]);
else if (et.test(r.replace(tt, "")));
else if ("src" !== o && "xlink:href" !== o || 0 !== r.indexOf("data:") || !xt[t.nodeName.toLocaleLowerCase()])
if (lt && !Z.test(r.replace(tt, "")));
else if (r) continue
}
try {
t.setAttribute(i, r), n.removed.pop()
} catch (t) {}
}
}
Lt("afterSanitizeAttributes", t, null)
}
},
It = function t(e) {
var n = void 0,
i = Mt(e);
for (Lt("beforeSanitizeShadowDOM", e, null); n = i.nextNode();) Lt("uponSanitizeShadowNode", n, null), Rt(n) || (n.content instanceof A && t(n.content), Bt(n));
Lt("afterSanitizeShadowDOM", e, null)
};
return n.sanitize = function(t, i) {
var r = void 0,
o = void 0,
a = void 0,
s = void 0,
u = void 0;
if (t || (t = "\x3c!--\x3e"), "string" != typeof t && !Dt(t)) {
if ("function" != typeof t.toString) throw new TypeError("toString is not a function");
if ("string" != typeof(t = t.toString())) throw new TypeError("dirty is not a string, aborting")
}
if (!n.isSupported) {
if ("object" === F(e.toStaticHTML) || "function" == typeof e.toStaticHTML) {
if ("string" == typeof t) return e.toStaticHTML(t);
if (Dt(t)) return e.toStaticHTML(t.outerHTML)
}
return t
}
if (mt || Ct(i), n.removed = [], t instanceof T) 1 === (o = (r = Tt("\x3c!--\x3e")).ownerDocument.importNode(t, !0)).nodeType && "BODY" === o.nodeName ? r = o : r.appendChild(o);
else {
if (!pt && !dt && -1 === t.indexOf("<")) return t;
if (!(r = Tt(t))) return pt ? null : ""
}
vt && At(r.firstChild);
for (var c = Mt(r); a = c.nextNode();) 3 === a.nodeType && a === s || Rt(a) || (a.content instanceof A && It(a.content), Bt(a), s = a);
if (pt) {
if (gt)
for (u = J.call(r.ownerDocument); r.firstChild;) u.appendChild(r.firstChild);
else u = r;
return bt && (u = Y.call(_, u, !0)), u
}
return dt ? r.outerHTML : r.innerHTML
}, n.setConfig = function(t) {
Ct(t), mt = !0
}, n.clearConfig = function() {
$t = null, mt = !1
}, n.addHook = function(t, e) {
"function" == typeof e && (G[t] = G[t] || [], G[t].push(e))
}, n.removeHook = function(t) {
G[t] && G[t].pop()
}, n.removeHooks = function(t) {
G[t] && (G[t] = [])
}, n.removeAllHooks = function() {
G = {}
}, n
}();
n.exports = _
}), $__System.registerDynamic("25", ["e"], !0, function(t, e, n) {
this || self;
var i = t("e"),
r = function() {
var t = "autoComplt-list",
e = "autoComplt-hint",
n = "active",
r = 10,
o = 100,
a = {
attr: "data-listStatus",
open: "open"
},
s = {
up: 38,
down: 40,
esc: 27,
enter: 13,
left: 37,
right: 39
},
u = {
autoCompltList: {
maxHeight: "none",
border: "1px solid #aaa",
padding: "0",
margin: "0",
zIndex: 99,
overflowX: "hidden",
overflowY: "auto",
display: "none",
position: "absolute",
backgroundColor: "#fff"
},
autoCompltHint: {
height: "1.5em",
padding: "2px 6px 2px 10px",
margin: "6px 0",
overflow: "hidden",
listStyleType: "none",
color: "#000",
backgroundColor: "#fff",
cursor: "default",
fontSize: "1em"
},
autoCompltHintSelected: {
color: "#fff",
backgroundColor: "#3399ff"
}
},
c = function(t) {
return (t = t || window.event).target = t.target || t.srcElement, t
},
l = function(t, e, n) {
t.addEventListener ? t.addEventListener(e, n) : t.attachEvent && t.attachEvent("on" + e, n)
},
f = function(t, e, n) {
t.removeEventListener ? t.removeEventListener(e, n) : t.detachEvent && t.detachEvent("on" + e, n)
},
h = function(t, e) {
var n = null;
if (window.getComputedStyle) n = window.getComputedStyle(t)[e] || null;
else if (t.currentStyle) {
n = t.currentStyle && t.currentStyle[e];
var i, r, o = t.style;
null == n && o && o[e] && (n = o[e]), i = o.left, (r = t.runtimeStyle && t.runtimeStyle.left) && (t.runtimeStyle.left = t.currentStyle.left), o.left = "fontSize" === e ? "1em" : n, n = o.pixelLeft + "px", o.left = i, r && (t.runtimeStyle.left = r)
}
return n
},
d = {
buildElem: function(t) {
var e = document.createElement("DIV");
return e.innerHTML = t, e.firstChild.cloneNode(!0)
},
buildHint: function(t, n) {
if ("string" == typeof t && t) {
return t = this.buildElem('<li class="' + e + '">' + t + "</li>")
}
return null
},
buildList: function(e) {
return this.buildElem('<div class="auto-suggest-container"><ul class="' + t + '"></ul></div>')
}
},
m = function(t) {
this.uiElem = null, this.assocInput = t, this.mouseOnList = !1, this.pauseMouseoverSelection = !1, this.pauseMouseoutDeselection = !1, this.maxHintNum = r, this.styles = JSON.parse(JSON.stringify(u))
};
m.prototype.genList = function() {
if (!this.uiElem) {
var t = this;
this.uiElem = d.buildList(this.styles), l(this.uiElem, "mouseover", function(e) {
e = c(e), t.isHint(e.target) && (t.select(e.target), t.autoScroll())
}), l(this.uiElem, "mouseout", function(e) {
e = c(e), t.deselect()
}), l(this.uiElem, "mousedown", function(e) {
t.mouseOnList = !0, "INPUT" !== t.assocInput.tagName && t.getSelected() && e.preventDefault()
}), l(this.uiElem, "mouseup", function(e) {
e = c(e), t.isHint(e.target) && (t.select(e.target), p(t.assocInput, t.getSelected().innerHTML), t.assocInput.autoComplt.close(), i(t.assocInput).trigger("change"))
}), document.body.appendChild(this.uiElem)
}
}, m.prototype.isHint = function(t) {
if (t && "object" == typeof t && 1 === t.nodeType) {
return (" " + t.className + " ").indexOf(" " + e + " ") >= 0
}
return !1
}, m.prototype.putHints = function(t) {
var e = 0;
if (t instanceof Array) {
var n, i, r = [];
for (i = Math.min(t.length, this.maxHintNum), n = 0; n < i; n++) r.push(d.buildHint(t[n], this.styles)), r[r.length - 1] || r.pop();
if (r.length > 0) {
var o = document.createDocumentFragment();
for (n = 0, e = r.length; n < e; n++) o.appendChild(r[n]);
this.clearHints(), this.genList(), this.uiElem.querySelector("ul").appendChild(o)
}
}
return e
}, m.prototype.clearHints = function() {
this.uiElem && (this.uiElem.querySelector("ul").innerHTML = "")
}, m.prototype.isOpen = function() {
return !!this.uiElem && this.uiElem.getAttribute(a.attr) == a.open
}, m.prototype.open = function() {
var t;
if (this.uiElem && (t = this.uiElem.querySelectorAll("." + e)) && t.length) {
var n, i;
for (i = this.assocInput.getBoundingClientRect(), this.uiElem.style.top = (document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + i.bottom + "px", this.uiElem.style.left = i.left + "px", i = i.right - i.left - parseFloat(h(this.uiElem, "borderLeftWidth")) - parseFloat(h(this.uiElem, "borderRightWidth")), this.uiElem.style.width = i + "px", n = 0, i = 0; n < t.length; n++) i += parseFloat(h(t[n], "height")) + parseFloat(h(t[n], "paddingTop")) + parseFloat(h(t[n], "paddingBottom")), t[n + 1] && (i += Math.max(parseFloat(h(t[n], "marginBottom")), parseFloat(h(t[n + 1], "marginTop"))));
i += parseFloat(h(t[0], "marginTop")) + parseFloat(h(t[t.length - 1], "marginBottom")), this.uiElem.style.height = i + 1 + "px", this.uiElem.setAttribute(a.attr, a.open), this.uiElem.classList.add("ty-show")
}
}, m.prototype.close = function() {
this.uiElem && (this.mouseOnList = !1, this.uiElem.parentNode.removeChild(this.uiElem), this.uiElem = null, i(this.assocInput).trigger("change"))
}, m.prototype.autoScroll = function() {
var t = this.getSelected();
if (t) {
var e, n = 0,
i = 0,
r = t.clientHeight,
o = parseFloat(h(t, "marginTop")),
a = parseFloat(h(t, "marginBottom"));
for (i = r + ((e = t.previousSibling) ? Math.max(o, a) : o); e;) n += r, n += (e = e.previousSibling) ? Math.max(o, a) : o;
(this.uiElem.clientHeight + this.uiElem.scrollTop - n < i || n - this.uiElem.scrollTop < i) && (this.uiElem.scrollTop = n)
}
}, m.prototype.select = function(t) {
if (this.uiElem) {
var i = null;
if (this.isHint(t)) i = t;
else if ("number" == typeof t && (t >= 0 || -1 === t)) {
var r = this.uiElem.querySelectorAll("." + e);
r.length > 0 && (i = r[i = -1 === (i = +t) || i > r.length - 1 ? r.length - 1 : i])
}
null !== i && (this.deselect(), i.className += " " + n)
}
}, m.prototype.deselect = function() {
if (this.uiElem) {
var t = this.getSelected();
t && (t.className = e)
}
}, m.prototype.getSelected = function() {
return this.uiElem ? this.uiElem.querySelector("." + n) || null : null
};
var v = function(t) {
return "INPUT" == t.tagName ? t.value : t.textContent
},
p = function(t, e) {
if ("INPUT" == t.tagName) t.value = e;
else if (t.textContent = e, e) {
var n = document.createRange();
n.setStart(t.childNodes[0], e.length), n.setEnd(t.childNodes[0], e.length);
var i = window.getSelection();
i.removeAllRanges(), i.addRange(n)
}
};
return {
enable: function(t, e) {
if (t && 1 === t.nodeType && !t.autoComplt) {
t.autoComplt = {};
var n = o,
r = !0,
a = "",
u = null,
c = new m(t),
h = function() {
if (r) {
var t = c.getSelected();
p(this, t ? t.innerHTML : a)
}
},
d = function(e) {
c.mouseOnList && "INPUT" == t.tagName && (t.focus(), c.mouseOnList = !1), t.autoComplt.close()
},
g = function(e) {
if (r)
if ("keydown" == e.type) {
if (e.keyCode === s.enter) return e.preventDefault();
if (c.isOpen() && (e.keyCode === s.up || e.keyCode === s.down)) {
var o = c.getSelected();
if (e.keyCode === s.up) {
if (!o) return void t.autoComplt.close();
e.preventDefault(), o.previousSibling ? c.select(o.previousSibling) : c.deselect()
} else e.keyCode === s.down && (e.preventDefault(), o ? o.nextSibling ? c.select(o.nextSibling) : c.deselect() : c.select(0));
c.autoScroll(), h.call(t)
}
} else if ("keyup" == e.type) {
var l = !1;
switch (e.keyCode) {
case s.up:
case s.down:
e.preventDefault();
break;
case s.left:
case s.right:
break;
case s.esc:
c.isOpen() && (t.value = a, t.autoComplt.close());
break;
case s.enter:
c.isOpen() && (h.call(t), t.autoComplt.close(), i(t).trigger("change"));
break;
default:
l = !0
}
l && function() {
if (v(this).length > 0 && r && "function" == typeof u && a !== v(this)) {
var e = {};
e.call = function() {
u.call(e.that, e.compltTarget, e.openHint)
}, e.that = t, e.compltTarget = a = v(this), e.openHint = function(n) {
if (e.compltTarget === a)
if (c.putHints(n)) {
var r = i(t).offset();
r.top += t.offsetHeight + 5, c.open(), i(c.uiElem).css("min-width", 100), i(c.uiElem).offset(r)
} else e.that.autoComplt.close()
}, setTimeout(e.call, n)
}
}.call(t)
}
};
return t.autoComplt.setHintsFetcher = function(t) {
return "function" == typeof t && (u = t, !0)
}, t.autoComplt.config = function(t) {
if (t instanceof Object) {
var e, i = {};
return (e = Math.floor(t.delay)) > 0 && (n = i.delay = e), (e = Math.floor(t.maxHintNum)) > 0 && (c.maxHintNum = i.maxHintNum = e), i
}
return !1
}, t.autoComplt.close = function() {
a = "", c.close()
}, t.autoComplt.enable = function() {
r = !0
}, t.autoComplt.disable = function() {
this.close(), r = !1
}, t.autoComplt.destroy = function() {
f(t, "blur", d), f(t, "keyup", g), f(t, "keydown", g), this.close(), delete t.autoComplt
}, l(t, "blur", d), l(t, "keyup", g), l(t, "keydown", g), e instanceof Object && (t.autoComplt.config(e), t.autoComplt.setHintsFetcher(e.hintsFetcher)), t
}
return null
}
}
}();
n.exports = r
}), $__System.registerDynamic("1f", [], !0, function(t, e, n) {
this || self;
n.exports = function() {
"use strict";
var t = navigator.userAgent,
e = navigator.platform,
n = /gecko\/\d/i.test(t),
i = /MSIE \d/.test(t),
r = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(t),
o = /Edge\/(\d+)/.exec(t),
a = i || r || o,
s = a && (i ? document.documentMode || 6 : +(o || r)[1]),
u = !o && /WebKit\//.test(t),
c = u && /Qt\/\d+\.\d+/.test(t),
l = !o && /Chrome\//.test(t),
f = /Opera\//.test(t),
h = /Apple Computer/.test(navigator.vendor),
d = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(t),
m = /PhantomJS/.test(t),
v = !o && /AppleWebKit/.test(t) && /Mobile\/\w+/.test(t),
p = /Android/.test(t),
g = v || p || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(t),
b = v || /Mac/.test(e),
y = /\bCrOS\b/.test(t),
w = /win/i.test(e),
F = f && t.match(/Version\/(\d*\.\d*)/);
F && (F = Number(F[1])), F && F >= 15 && (f = !1, u = !0);
var k = b && (c || f && (null == F || F < 12.11)),
x = n || a && s >= 9;
function _(t) {
return new RegExp("(^|\\s)" + t + "(?:$|\\s)\\s*")
}
var $ = function(t, e) {
var n = t.className,
i = _(e).exec(n);
if (i) {
var r = n.slice(i.index + i[0].length);
t.className = n.slice(0, i.index) + (r ? i[1] + r : "")
}
};
function E(t) {
for (var e = t.childNodes.length; e > 0; --e) t.removeChild(t.firstChild);
return t
}
function C(t, e) {
return E(t).appendChild(e)
}
function A(t, e, n, i) {
var r = document.createElement(t);
if (n && (r.className = n), i && (r.style.cssText = i), "string" == typeof e) r.appendChild(document.createTextNode(e));
else if (e)
for (var o = 0; o < e.length; ++o) r.appendChild(e[o]);
return r
}
function S(t, e, n, i) {
var r = A(t, e, n, i);
return r.setAttribute("role", "presentation"), r
}
var T;
T = document.createRange ? function(t, e, n, i) {
var r = document.createRange();
return r.setEnd(i || t, n), r.setStart(t, e), r
} : function(t, e, n) {
var i = document.body.createTextRange();
try {
i.moveToElementText(t.parentNode)
} catch (t) {
return i
}
return i.collapse(!0), i.moveEnd("character", n), i.moveStart("character", e), i
};
function M(t, e) {
if (3 == e.nodeType && (e = e.parentNode), t.contains) return t.contains(e);
do {
if (11 == e.nodeType && (e = e.host), e == t) return !0
} while (e = e.parentNode)
}
function D() {
var t;
try {
t = document.activeElement
} catch (e) {
t = document.body || null
}
for (; t && t.shadowRoot && t.shadowRoot.activeElement;) t = t.shadowRoot.activeElement;
return t
}
function L(t, e) {
var n = t.className;
_(e).test(n) || (t.className += (n ? " " : "") + e)
}
function R(t, e) {
for (var n = t.split(" "), i = 0; i < n.length; i++) n[i] && !_(n[i]).test(e) && (e += " " + n[i]);
return e
}
var B = function(t) {
t.select()
};
v ? B = function(t) {
t.selectionStart = 0, t.selectionEnd = t.value.length
} : a && (B = function(t) {
try {
t.select()
} catch (t) {}
});
function I(t) {
var e = Array.prototype.slice.call(arguments, 1);
return function() {
return t.apply(null, e)
}
}
function N(t, e, n) {
e || (e = {});
for (var i in t) !t.hasOwnProperty(i) || !1 === n && e.hasOwnProperty(i) || (e[i] = t[i]);
return e
}
function O(t, e, n, i, r) {
null == e && -1 == (e = t.search(/[^\s\u00a0]/)) && (e = t.length);
for (var o = i || 0, a = r || 0;;) {
var s = t.indexOf("\t", o);
if (s < 0 || s >= e) return a + (e - o);
a += s - o, a += n - a % n, o = s + 1
}
}
var j = function() {
this.id = null
};
j.prototype.set = function(t, e) {
clearTimeout(this.id), this.id = setTimeout(e, t)
};
function P(t, e) {
for (var n = 0; n < t.length; ++n)
if (t[n] == e) return n;
return -1
}
var q = 0,
U = {
toString: function() {
return "CodeMirror.Pass"
}
},
z = {
scroll: !1
},
H = {
origin: "*mouse"
},
W = {
origin: "+move"
};
function J(t, e, n) {
for (var i = 0, r = 0;;) {
var o = t.indexOf("\t", i); - 1 == o && (o = t.length);
var a = o - i;
if (o == t.length || r + a >= e) return i + Math.min(a, e - r);
if (r += o - i, i = o + 1, (r += n - r % n) >= e) return i
}
}
var Y = [""];
function G(t) {
for (; Y.length <= t;) Y.push(K(Y) + " ");
return Y[t]
}
function K(t) {
return t[t.length - 1]
}
function V(t, e) {
for (var n = [], i = 0; i < t.length; i++) n[i] = e(t[i], i);
return n
}
function Q() {}
function X(t, e) {
var n;
return Object.create ? n = Object.create(t) : (Q.prototype = t, n = new Q), e && N(e, n), n
}
var Z = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
function tt(t) {
return /\w/.test(t) || t > "€" && (t.toUpperCase() != t.toLowerCase() || Z.test(t))
}
function et(t, e) {
return e ? !!(e.source.indexOf("\\w") > -1 && tt(t)) || e.test(t) : tt(t)
}
function nt(t) {
for (var e in t)
if (t.hasOwnProperty(e) && t[e]) return !1;
return !0
}
var it = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
function rt(t) {
return t.charCodeAt(0) >= 768 && it.test(t)
}
function ot(t, e, n) {
for (;
(n < 0 ? e > 0 : e < t.length) && rt(t.charAt(e));) e += n;
return e
}
function at(t, e, n) {
for (;;) {
if (Math.abs(e - n) <= 1) return t(e) ? e : n;
var i = Math.floor((e + n) / 2);
t(i) ? n = i : e = i
}
}
function st(t, e) {
if ((e -= t.first) < 0 || e >= t.size) throw new Error("There is no line " + (e + t.first) + " in the document.");
for (var n = t; !n.lines;)
for (var i = 0;; ++i) {
var r = n.children[i],
o = r.chunkSize();
if (e < o) {
n = r;
break
}
e -= o
}
return n.lines[e]
}
function ut(t, e, n) {
var i = [],
r = e.line;
return t.iter(e.line, n.line + 1, function(t) {
var o = t.text;
r == n.line && (o = o.slice(0, n.ch)), r == e.line && (o = o.slice(e.ch)), i.push(o), ++r
}), i
}
function ct(t, e, n) {
var i = [];
return t.iter(e, n, function(t) {
i.push(t.text)
}), i
}
function lt(t, e) {
var n = e - t.height;
if (n)
for (var i = t; i; i = i.parent) i.height += n
}
function ft(t) {
if (null == t.parent) return null;
for (var e = t.parent, n = P(e.lines, t), i = e.parent; i; e = i, i = i.parent)
for (var r = 0; i.children[r] != e; ++r) n += i.children[r].chunkSize();
return n + e.first
}
function ht(t, e) {
var n = t.first;
t: do {
for (var i = 0; i < t.children.length; ++i) {
var r = t.children[i],
o = r.height;
if (e < o) {
t = r;
continue t
}
e -= o, n += r.chunkSize()
}
return n
} while (!t.lines);
for (var a = 0; a < t.lines.length; ++a) {
var s = t.lines[a].height;
if (e < s) break;
e -= s
}
return n + a
}
function dt(t, e) {
return e >= t.first && e < t.first + t.size
}
function mt(t, e) {
return String(t.lineNumberFormatter(e + t.firstLineNumber))
}
function vt(t, e, n) {
if (void 0 === n && (n = null), !(this instanceof vt)) return new vt(t, e, n);
this.line = t, this.ch = e, this.sticky = n
}
function pt(t, e) {
return t.line - e.line || t.ch - e.ch
}
function gt(t, e) {
return t.sticky == e.sticky && 0 == pt(t, e)
}
function bt(t) {
return vt(t.line, t.ch)
}
function yt(t, e) {
return pt(t, e) < 0 ? e : t
}
function wt(t, e) {
return pt(t, e) < 0 ? t : e
}
function Ft(t, e) {
return Math.max(t.first, Math.min(e, t.first + t.size - 1))
}
function kt(t, e) {
if (e.line < t.first) return vt(t.first, 0);
var n = t.first + t.size - 1;
return e.line > n ? vt(n, st(t, n).text.length) : function(t, e) {
var n = t.ch;
return null == n || n > e ? vt(t.line, e) : n < 0 ? vt(t.line, 0) : t
}(e, st(t, e.line).text.length)
}
function xt(t, e) {
for (var n = [], i = 0; i < e.length; i++) n[i] = kt(t, e[i]);
return n
}
var _t = !1,
$t = !1;
function Et(t, e, n) {
this.marker = t, this.from = e, this.to = n
}
function Ct(t, e) {
if (t)
for (var n = 0; n < t.length; ++n) {
var i = t[n];
if (i.marker == e) return i
}
}
function At(t, e) {
for (var n, i = 0; i < t.length; ++i) t[i] != e && (n || (n = [])).push(t[i]);
return n
}
function St(t, e) {
if (e.full) return null;
var n = dt(t, e.from.line) && st(t, e.from.line).markedSpans,
i = dt(t, e.to.line) && st(t, e.to.line).markedSpans;
if (!n && !i) return null;
var r = e.from.ch,
o = e.to.ch,
a = 0 == pt(e.from, e.to),
s = function(t, e, n) {
var i;
if (t)
for (var r = 0; r < t.length; ++r) {
var o = t[r],
a = o.marker;
if (null == o.from || (a.inclusiveLeft ? o.from <= e : o.from < e) || o.from == e && "bookmark" == a.type && (!n || !o.marker.insertLeft)) {
var s = null == o.to || (a.inclusiveRight ? o.to >= e : o.to > e);
(i || (i = [])).push(new Et(a, o.from, s ? null : o.to))
}
}
return i
}(n, r, a),
u = function(t, e, n) {
var i;
if (t)
for (var r = 0; r < t.length; ++r) {
var o = t[r],
a = o.marker;
if (null == o.to || (a.inclusiveRight ? o.to >= e : o.to > e) || o.from == e && "bookmark" == a.type && (!n || o.marker.insertLeft)) {
var s = null == o.from || (a.inclusiveLeft ? o.from <= e : o.from < e);
(i || (i = [])).push(new Et(a, s ? null : o.from - e, null == o.to ? null : o.to - e))
}
}
return i
}(i, o, a),
c = 1 == e.text.length,
l = K(e.text).length + (c ? r : 0);
if (s)
for (var f = 0; f < s.length; ++f) {
var h = s[f];
if (null == h.to) {
var d = Ct(u, h.marker);
d ? c && (h.to = null == d.to ? null : d.to + l) : h.to = r
}
}
if (u)
for (var m = 0; m < u.length; ++m) {
var v = u[m];
if (null != v.to && (v.to += l), null == v.from) {
Ct(s, v.marker) || (v.from = l, c && (s || (s = [])).push(v))
} else v.from += l, c && (s || (s = [])).push(v)
}
s && (s = Tt(s)), u && u != s && (u = Tt(u));
var p = [s];
if (!c) {
var g, b = e.text.length - 2;
if (b > 0 && s)
for (var y = 0; y < s.length; ++y) null == s[y].to && (g || (g = [])).push(new Et(s[y].marker, null, null));
for (var w = 0; w < b; ++w) p.push(g);
p.push(u)
}
return p
}
function Tt(t) {
for (var e = 0; e < t.length; ++e) {
var n = t[e];
null != n.from && n.from == n.to && !1 !== n.marker.clearWhenEmpty && t.splice(e--, 1)
}
return t.length ? t : null
}
function Mt(t) {
var e = t.markedSpans;
if (e) {
for (var n = 0; n < e.length; ++n) e[n].marker.detachLine(t);
t.markedSpans = null
}
}
function Dt(t, e) {
if (e) {
for (var n = 0; n < e.length; ++n) e[n].marker.attachLine(t);
t.markedSpans = e
}
}
function Lt(t) {
return t.inclusiveLeft ? -1 : 0
}
function Rt(t) {
return t.inclusiveRight ? 1 : 0
}
function Bt(t, e) {
var n = t.lines.length - e.lines.length;
if (0 != n) return n;
var i = t.find(),
r = e.find(),
o = pt(i.from, r.from) || Lt(t) - Lt(e);
if (o) return -o;
var a = pt(i.to, r.to) || Rt(t) - Rt(e);
return a || e.id - t.id
}
function It(t, e) {
var n, i = $t && t.markedSpans;
if (i)
for (var r = void 0, o = 0; o < i.length; ++o)(r = i[o]).marker.collapsed && null == (e ? r.from : r.to) && (!n || Bt(n, r.marker) < 0) && (n = r.marker);
return n
}
function Nt(t) {
return It(t, !0)
}
function Ot(t) {
return It(t, !1)
}
function jt(t, e, n, i, r) {
var o = st(t, e),
a = $t && o.markedSpans;
if (a)
for (var s = 0; s < a.length; ++s) {
var u = a[s];
if (u.marker.collapsed) {
var c = u.marker.find(0),
l = pt(c.from, n) || Lt(u.marker) - Lt(r),
f = pt(c.to, i) || Rt(u.marker) - Rt(r);
if (!(l >= 0 && f <= 0 || l <= 0 && f >= 0) && (l <= 0 && (u.marker.inclusiveRight && r.inclusiveLeft ? pt(c.to, n) >= 0 : pt(c.to, n) > 0) || l >= 0 && (u.marker.inclusiveRight && r.inclusiveLeft ? pt(c.from, i) <= 0 : pt(c.from, i) < 0))) return !0
}
}
}
function Pt(t) {
for (var e; e = Nt(t);) t = e.find(-1, !0).line;
return t
}
function qt(t, e) {
var n = st(t, e),
i = Pt(n);
return n == i ? e : ft(i)
}
function Ut(t, e) {
if (e > t.lastLine()) return e;
var n, i = st(t, e);
if (!zt(t, i)) return e;
for (; n = Ot(i);) i = n.find(1, !0).line;
return ft(i) + 1
}
function zt(t, e) {
var n = $t && e.markedSpans;
if (n)
for (var i = void 0, r = 0; r < n.length; ++r)
if ((i = n[r]).marker.collapsed) {
if (null == i.from) return !0;
if (!i.marker.widgetNode && 0 == i.from && i.marker.inclusiveLeft && Ht(t, e, i)) return !0
}
}
function Ht(t, e, n) {
if (null == n.to) {
var i = n.marker.find(1, !0);
return Ht(t, i.line, Ct(i.line.markedSpans, n.marker))
}
if (n.marker.inclusiveRight && n.to == e.text.length) return !0;
for (var r = void 0, o = 0; o < e.markedSpans.length; ++o)
if ((r = e.markedSpans[o]).marker.collapsed && !r.marker.widgetNode && r.from == n.to && (null == r.to || r.to != n.from) && (r.marker.inclusiveLeft || n.marker.inclusiveRight) && Ht(t, e, r)) return !0
}
function Wt(t) {
for (var e = 0, n = (t = Pt(t)).parent, i = 0; i < n.lines.length; ++i) {
var r = n.lines[i];
if (r == t) break;
e += r.height
}
for (var o = n.parent; o; n = o, o = n.parent)
for (var a = 0; a < o.children.length; ++a) {
var s = o.children[a];
if (s == n) break;
e += s.height
}
return e
}
function Jt(t) {
if (0 == t.height) return 0;
for (var e, n = t.text.length, i = t; e = Nt(i);) {
var r = e.find(0, !0);
i = r.from.line, n += r.from.ch - r.to.ch
}
for (i = t; e = Ot(i);) {
var o = e.find(0, !0);
n -= i.text.length - o.from.ch, n += (i = o.to.line).text.length - o.to.ch
}
return n
}
function Yt(t) {
var e = t.display,
n = t.doc;
e.maxLine = st(n, n.first), e.maxLineLength = Jt(e.maxLine), e.maxLineChanged = !0, n.iter(function(t) {
var n = Jt(t);
n > e.maxLineLength && (e.maxLineLength = n, e.maxLine = t)
})
}
var Gt = null;
function Kt(t, e, n) {
var i;
Gt = null;
for (var r = 0; r < t.length; ++r) {
var o = t[r];
if (o.from < e && o.to > e) return r;
o.to == e && (o.from != o.to && "before" == n ? i = r : Gt = r), o.from == e && (o.from != o.to && "before" != n ? i = r : Gt = r)
}
return null != i ? i : Gt
}
var Vt = function() {
var t = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN",
e = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";
var n = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,
i = /[stwN]/,
r = /[LRr]/,
o = /[Lb1n]/,
a = /[1n]/;
function s(t, e, n) {
this.level = t, this.from = e, this.to = n
}
return function(u, c) {
var l = "ltr" == c ? "L" : "R";
if (0 == u.length || "ltr" == c && !n.test(u)) return !1;
for (var f = u.length, h = [], d = 0; d < f; ++d) h.push((m = u.charCodeAt(d)) <= 247 ? t.charAt(m) : 1424 <= m && m <= 1524 ? "R" : 1536 <= m && m <= 1785 ? e.charAt(m - 1536) : 1774 <= m && m <= 2220 ? "r" : 8192 <= m && m <= 8203 ? "w" : 8204 == m ? "b" : "L");
for (var m, v = 0, p = l; v < f; ++v) {
var g = h[v];
"m" == g ? h[v] = p : p = g
}
for (var b = 0, y = l; b < f; ++b) {
var w = h[b];
"1" == w && "r" == y ? h[b] = "n" : r.test(w) && (y = w, "r" == w && (h[b] = "R"))
}
for (var F = 1, k = h[0]; F < f - 1; ++F) {
var x = h[F];
"+" == x && "1" == k && "1" == h[F + 1] ? h[F] = "1" : "," != x || k != h[F + 1] || "1" != k && "n" != k || (h[F] = k), k = x
}
for (var _ = 0; _ < f; ++_) {
var $ = h[_];
if ("," == $) h[_] = "N";
else if ("%" == $) {
var E = void 0;
for (E = _ + 1; E < f && "%" == h[E]; ++E);
for (var C = _ && "!" == h[_ - 1] || E < f && "1" == h[E] ? "1" : "N", A = _; A < E; ++A) h[A] = C;
_ = E - 1
}
}
for (var S = 0, T = l; S < f; ++S) {
var M = h[S];
"L" == T && "1" == M ? h[S] = "L" : r.test(M) && (T = M)
}
for (var D = 0; D < f; ++D)
if (i.test(h[D])) {
var L = void 0;
for (L = D + 1; L < f && i.test(h[L]); ++L);
for (var R = "L" == (D ? h[D - 1] : l), B = R == ("L" == (L < f ? h[L] : l)) ? R ? "L" : "R" : l, I = D; I < L; ++I) h[I] = B;
D = L - 1
}
for (var N, O = [], j = 0; j < f;)
if (o.test(h[j])) {
var P = j;
for (++j; j < f && o.test(h[j]); ++j);
O.push(new s(0, P, j))
} else {
var q = j,
U = O.length;
for (++j; j < f && "L" != h[j]; ++j);
for (var z = q; z < j;)
if (a.test(h[z])) {
q < z && O.splice(U, 0, new s(1, q, z));
var H = z;
for (++z; z < j && a.test(h[z]); ++z);
O.splice(U, 0, new s(2, H, z)), q = z
} else ++z;
q < j && O.splice(U, 0, new s(1, q, j))
}
return 1 == O[0].level && (N = u.match(/^\s+/)) && (O[0].from = N[0].length, O.unshift(new s(0, 0, N[0].length))), 1 == K(O).level && (N = u.match(/\s+$/)) && (K(O).to -= N[0].length, O.push(new s(0, f - N[0].length, f))), "rtl" == c ? O.reverse() : O
}
}();
function Qt(t, e) {
var n = t.order;
return null == n && (n = t.order = Vt(t.text, e)), n
}
function Xt(t, e, n) {
var i = ot(t.text, e + n, n);
return i < 0 || i > t.text.length ? null : i
}
function Zt(t, e, n) {
var i = Xt(t, e.ch, n);
return null == i ? null : new vt(e.line, i, n < 0 ? "after" : "before")
}
function te(t, e, n, i, r) {
if (t) {
var o = Qt(n, e.doc.direction);
if (o) {
var a, s = r < 0 ? K(o) : o[0],
u = r < 0 == (1 == s.level) ? "after" : "before";
if (s.level > 0) {
var c = Tn(e, n);
a = r < 0 ? n.text.length - 1 : 0;
var l = Mn(e, c, a).top;
a = at(function(t) {
return Mn(e, c, t).top == l
}, r < 0 == (1 == s.level) ? s.from : s.to - 1, a), "before" == u && (a = Xt(n, a, 1))
} else a = r < 0 ? s.to : s.from;
return new vt(i, a, u)
}
}
return new vt(i, r < 0 ? n.text.length : 0, r < 0 ? "before" : "after")
}
function ee(t, e, n, i) {
var r = Qt(e, t.doc.direction);
if (!r) return Zt(e, n, i);
n.ch >= e.text.length ? (n.ch = e.text.length, n.sticky = "before") : n.ch <= 0 && (n.ch = 0, n.sticky = "after");
var o = Kt(r, n.ch, n.sticky),
a = r[o];
if ("ltr" == t.doc.direction && a.level % 2 == 0 && (i > 0 ? a.to > n.ch : a.from < n.ch)) return Zt(e, n, i);
var s, u = function(t, n) {
return Xt(e, t instanceof vt ? t.ch : t, n)
},
c = function(n) {
return t.options.lineWrapping ? (s = s || Tn(t, e), function(t, e, n, i) {
var r = Pn(t, e, Mn(t, n, i), "line").top;
return Yn(t, e, n, r)
}(t, e, s, n)) : {
begin: 0,
end: e.text.length
}
},
l = c("before" == n.sticky ? u(n, -1) : n.ch);
if ("rtl" == t.doc.direction || 1 == a.level) {
var f = 1 == a.level == i < 0,
h = u(n, f ? 1 : -1);
if (null != h && (f ? h <= a.to && h <= l.end : h >= a.from && h >= l.begin)) {
var d = f ? "before" : "after";
return new vt(n.line, h, d)
}
}
var m = function(t, e, i) {
for (var o = function(t, e) {
return e ? new vt(n.line, u(t, 1), "before") : new vt(n.line, t, "after")
}; t >= 0 && t < r.length; t += e) {
var a = r[t],
s = e > 0 == (1 != a.level),
c = s ? i.begin : u(i.end, -1);
if (a.from <= c && c < a.to) return o(c, s);
if (c = s ? a.from : u(a.to, -1), i.begin <= c && c < i.end) return o(c, s)
}
},
v = m(o + i, i, l);
if (v) return v;
var p = i > 0 ? l.end : u(l.begin, -1);
return null == p || i > 0 && p == e.text.length || !(v = m(i > 0 ? 0 : r.length - 1, i, c(p))) ? null : v
}
var ne = [],
ie = function(t, e, n) {
if (t.addEventListener) {
var i = File.option.passiveEvents && ("scroll" == e || "mousewheel" == e || "DOMMouseScroll" == e);
t.addEventListener(e, n, !!i && {
passive: !0,
capture: !1
})
} else if (t.attachEvent) t.attachEvent("on" + e, n);
else {
var r = t._handlers || (t._handlers = {});
r[e] = (r[e] || ne).concat(n)
}
};
function re(t, e) {
return t._handlers && t._handlers[e] || ne
}
function oe(t, e, n) {
if (t.removeEventListener) t.removeEventListener(e, n, !1);
else if (t.detachEvent) t.detachEvent("on" + e, n);
else {
var i = t._handlers,
r = i && i[e];
if (r) {
var o = P(r, n);
o > -1 && (i[e] = r.slice(0, o).concat(r.slice(o + 1)))
}
}
}
function ae(t, e) {
var n = re(t, e);
if (n.length)
for (var i = Array.prototype.slice.call(arguments, 2), r = 0; r < n.length; ++r) n[r].apply(null, i)
}
function se(t, e, n) {
return "string" == typeof e && (e = {
type: e,
preventDefault: function() {
this.defaultPrevented = !0
}
}), ae(t, n || e.type, t, e), de(e) || e.codemirrorIgnore
}
function ue(t) {
var e = t._handlers && t._handlers.cursorActivity;
if (e)
for (var n = t.curOp.cursorActivityHandlers || (t.curOp.cursorActivityHandlers = []), i = 0; i < e.length; ++i) - 1 == P(n, e[i]) && n.push(e[i])
}
function ce(t, e) {
return re(t, e).length > 0
}
function le(t) {
t.prototype.on = function(t, e) {
ie(this, t, e)
}, t.prototype.off = function(t, e) {
oe(this, t, e)
}
}
function fe(t) {
t.preventDefault ? t.preventDefault() : t.returnValue = !1
}
function he(t) {
t.stopPropagation ? t.stopPropagation() : t.cancelBubble = !0
}
function de(t) {
return null != t.defaultPrevented ? t.defaultPrevented : 0 == t.returnValue
}
function me(t) {
fe(t), he(t)
}
function ve(t) {
return t.target || t.srcElement
}
function pe(t) {
var e = t.which;
return null == e && (1 & t.button ? e = 1 : 2 & t.button ? e = 3 : 4 & t.button && (e = 2)), b && t.ctrlKey && 1 == e && (e = 3), e
}
var ge, be = function() {
if (a && s < 9) return !1;
var t = A("div");
return "draggable" in t || "dragDrop" in t
}();
function ye(t) {
if (null == ge) {
var e = A("span", "​");
C(t, A("span", [e, document.createTextNode("x")])), 0 != t.firstChild.offsetHeight && (ge = e.offsetWidth <= 1 && e.offsetHeight > 2 && !(a && s < 8))
}
var n = ge ? A("span", "​") : A("span", " ", null, "display: inline-block; width: 1px; margin-right: -1px");
return n.setAttribute("cm-text", ""), n
}
var we;
function Fe(t) {
if (null != we) return we;
var e = C(t, document.createTextNode("AخA")),
n = T(e, 0, 1).getBoundingClientRect(),
i = T(e, 1, 2).getBoundingClientRect();
return E(t), !(!n || n.left == n.right) && (we = i.right - n.right < 3)
}
var ke = 3 != "\n\nb".split(/\n/).length ? function(t) {
for (var e = 0, n = [], i = t.length; e <= i;) {
var r = t.indexOf("\n", e); - 1 == r && (r = t.length);
var o = t.slice(e, "\r" == t.charAt(r - 1) ? r - 1 : r),
a = o.indexOf("\r"); - 1 != a ? (n.push(o.slice(0, a)), e += a + 1) : (n.push(o), e = r + 1)
}
return n
} : function(t) {
return t.split(/\r\n?|\n/)
},
xe = window.getSelection ? function(t) {
try {
return t.selectionStart != t.selectionEnd
} catch (t) {
return !1
}
} : function(t) {
var e;
try {
e = t.ownerDocument.selection.createRange()
} catch (t) {}
return !(!e || e.parentElement() != t) && 0 != e.compareEndPoints("StartToEnd", e)
},
_e = function() {
var t = A("div");
return "oncopy" in t || (t.setAttribute("oncopy", "return;"), "function" == typeof t.oncopy)
}(),
$e = null;
var Ee = {},
Ce = {};
function Ae(t) {
if ("string" == typeof t && Ce.hasOwnProperty(t)) t = Ce[t];
else if (t && "string" == typeof t.name && Ce.hasOwnProperty(t.name)) {
var e = Ce[t.name];
"string" == typeof e && (e = {
name: e
}), (t = X(e, t)).name = e.name
} else {
if ("string" == typeof t && /^[\w\-]+\/[\w\-]+\+xml$/.test(t)) return Ae("application/xml");
if ("string" == typeof t && /^[\w\-]+\/[\w\-]+\+json$/.test(t)) return Ae("application/json")
}
return "string" == typeof t ? {
name: t
} : t || {
name: "null"
}
}
function Se(t, e) {
e = Ae(e);
var n = Ee[e.name];
if (!n) return Se(t, "text/plain");
var i = n(t, e);
if (Te.hasOwnProperty(e.name)) {
var r = Te[e.name];
for (var o in r) r.hasOwnProperty(o) && (i.hasOwnProperty(o) && (i["_" + o] = i[o]), i[o] = r[o])
}
if (i.name = e.name, e.helperType && (i.helperType = e.helperType), e.modeProps)
for (var a in e.modeProps) i[a] = e.modeProps[a];
return i
}
var Te = {};
function Me(t, e) {
N(e, Te.hasOwnProperty(t) ? Te[t] : Te[t] = {})
}
function De(t, e) {
if (!0 === e) return e;
if (t.copyState) return t.copyState(e);
var n = {};
for (var i in e) {
var r = e[i];
r instanceof Array && (r = r.concat([])), n[i] = r
}
return n
}
function Le(t, e) {
for (var n; t.innerMode && (n = t.innerMode(e)) && n.mode && n.mode != t;) e = n.state, t = n.mode;
return n && !n.mode && (n = void 0), n || {
mode: t,
state: e
}
}
function Re(t, e, n) {
return !t.startState || t.startState(e, n)
}
var Be = function(t, e) {
this.pos = this.start = 0, this.string = t, this.tabSize = e || 8, this.lastColumnPos = this.lastColumnValue = 0, this.lineStart = 0
};
Be.prototype.eol = function() {
return this.pos >= this.string.length
}, Be.prototype.sol = function() {
return this.pos == this.lineStart
}, Be.prototype.peek = function() {
return this.string.charAt(this.pos) || void 0
}, Be.prototype.next = function() {
if (this.pos < this.string.length) return this.string.charAt(this.pos++)
}, Be.prototype.eat = function(t) {
var e = this.string.charAt(this.pos);
if ("string" == typeof t ? e == t : e && (t.test ? t.test(e) : t(e))) return ++this.pos, e
}, Be.prototype.eatWhile = function(t) {
for (var e = this.pos; this.eat(t););
return this.pos > e
}, Be.prototype.eatSpace = function() {
for (var t = this.pos;
/[\s\u00a0]/.test(this.string.charAt(this.pos));) ++this.pos;
return this.pos > t
}, Be.prototype.skipToEnd = function() {
this.pos = this.string.length
}, Be.prototype.skipTo = function(t) {
var e = this.string.indexOf(t, this.pos);
if (e > -1) return this.pos = e, !0
}, Be.prototype.backUp = function(t) {
this.pos -= t
}, Be.prototype.column = function() {
return this.lastColumnPos < this.start && (this.lastColumnValue = O(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue), this.lastColumnPos = this.start), this.lastColumnValue - (this.lineStart ? O(this.string, this.lineStart, this.tabSize) : 0)
}, Be.prototype.indentation = function() {
return O(this.string, null, this.tabSize) - (this.lineStart ? O(this.string, this.lineStart, this.tabSize) : 0)
}, Be.prototype.match = function(t, e, n) {
if ("string" != typeof t) {
var i = this.string.slice(this.pos).match(t);
return i && i.index > 0 ? null : (i && !1 !== e && (this.pos += i[0].length), i)
}
var r = function(t) {
return n ? t.toLowerCase() : t
};
if (r(this.string.substr(this.pos, t.length)) == r(t)) return !1 !== e && (this.pos += t.length), !0
}, Be.prototype.current = function() {
return this.string.slice(this.start, this.pos)
}, Be.prototype.hideFirstChars = function(t, e) {
this.lineStart += t;
try {
return e()
} finally {
this.lineStart -= t
}
};
function Ie(t, e, n, i) {
var r = [t.state.modeGen],
o = {},
a = ft(e);
"object" == typeof n && (n.lineBefore = t.getLine(a - 1), n.lineAfter = t.getLine(a + 1)), He(t, e.text, t.doc.mode, n, function(t, e) {
return r.push(t, e)
}, o, i);
for (var s = function(i) {
var a = t.state.overlays[i],
s = 1,
u = 0;
He(t, e.text, a.mode, "visiblespace" !== a.mode.name || n, function(t, e) {
for (var n = s; u < t;) {
var i = r[s];
i > t && r.splice(s, 1, t, r[s + 1], i), s += 2, u = Math.min(t, i)
}
if (e)
if (a.opaque) r.splice(n, s - n, t, "overlay " + e), s = n + 2;
else
for (; n < s; n += 2) {
var o = r[n + 1];
r[n + 1] = (o ? o + " " : "") + "overlay " + e
}
}, o)
}, u = 0; u < t.state.overlays.length; ++u) s(u);
return {
styles: r,
classes: o.bgClass || o.textClass ? o : null
}
}
function Ne(t, e, n) {
if (!e.styles || e.styles[0] != t.state.modeGen) {
var i = Oe(t, ft(e)),
r = Ie(t, e, e.text.length > t.options.maxHighlightLength ? De(t.doc.mode, i) : i);
e.stateAfter = i, e.styles = r.styles, r.classes ? e.styleClasses = r.classes : e.styleClasses && (e.styleClasses = null), n === t.doc.frontier && t.doc.frontier++
}
return e.styles
}
function Oe(t, e, n) {
var i = t.doc,
r = t.display;
if (!i.mode.startState) return !0;
var o = function(t, e, n) {
for (var i, r, o = t.doc, a = n ? -1 : e - (t.doc.mode.innerMode ? 1e3 : 100), s = e; s > a; --s) {
if (s <= o.first) return o.first;
var u = st(o, s - 1);
if (u.stateAfter && (!n || s <= o.frontier)) return s;
var c = O(u.text, null, t.options.tabSize);
(null == r || i > c) && (r = s - 1, i = c)
}
return r
}(t, e, n),
a = o > i.first && st(i, o - 1).stateAfter;
return a = a ? De(i.mode, a) : Re(i.mode), i.iter(o, e, function(n) {
"object" == typeof a && (a.lineBefore = t.getLine(e - 1), a.lineAfter = t.getLine(e + 1)), je(t, n.text, a);
var s = o == e - 1 || o % 5 == 0 || o >= r.viewFrom && o < r.viewTo;
n.stateAfter = s ? De(i.mode, a) : null, ++o
}), n && (i.frontier = o), a
}
function je(t, e, n, i) {
var r = t.doc.mode,
o = new Be(e, t.options.tabSize);
for (o.start = o.pos = i || 0, n.lineBefore = n.lineBefore || "", n.lineAfter = n.lineAfter || "", "" == e && Pe(r, n); !o.eol();) qe(r, o, n), o.start = o.pos
}
function Pe(t, e) {
if (t.blankLine) return t.blankLine(e);
if (t.innerMode) {
var n = Le(t, e);
return n.mode.blankLine ? n.mode.blankLine(n.state) : void 0
}
}
function qe(t, e, n, i) {
for (var r = 0; r < 10; r++) {
i && (i[0] = Le(t, n).mode);
var o = t.token(e, n);
if (e.pos > e.start) return o
}
if ("gfm" == t.name) return e.pos = e.start + 1, null;
throw new Error("Mode " + t.name + " failed to advance stream.")
}
function Ue(t, e, n, i) {
var r, o = function(t) {
return {
start: f.start,
end: f.pos,
string: f.current(),
type: r || null,
state: t ? De(a.mode, l) : l
}
},
a = t.doc,
s = a.mode;
e = kt(a, e);
var u, c = st(a, e.line),
l = Oe(t, e.line, n),
f = new Be(c.text, t.options.tabSize);
for (i && (u = []);
(i || f.pos < e.ch) && !f.eol();) f.start = f.pos, r = qe(s, f, l), i && u.push(o(!0));
return i ? u : o()
}
function ze(t, e) {
if (t)
for (;;) {
var n = t.match(/(?:^|\s+)line-(background-)?(\S+)/);
if (!n) break;
t = t.slice(0, n.index) + t.slice(n.index + n[0].length);
var i = n[1] ? "bgClass" : "textClass";
null == e[i] ? e[i] = n[2] : new RegExp("(?:^|s)" + n[2] + "(?:$|s)").test(e[i]) || (e[i] += " " + n[2])
}
return t
}
function He(t, e, n, i, r, o, a) {
var s = n.flattenSpans;
null == s && (s = t.options.flattenSpans);
var u, c = 0,
l = null,
f = new Be(e, t.options.tabSize),
h = t.options.addModeClass && [null];
for ("" == e && ze(Pe(n, i), o); !f.eol();) {
if (f.pos > t.options.maxHighlightLength ? (s = !1, a && je(t, e, i, f.pos), f.pos = e.length, u = null) : u = ze(qe(n, f, i, h), o), h) {
var d = h[0].name;
d && (u = "m-" + (u ? d + " " + u : d))
}
if (!s || l != u) {
for (; c < f.start;) r(c = Math.min(f.start, c + 5e3), l);
l = u
}
f.start = f.pos
}
for (; c < f.pos;) {
var m = Math.min(f.pos, c + 5e3);
r(m, l), c = m
}
}
var We = function(t, e, n) {
this.text = t, Dt(this, e), this.height = n ? n(this) : 1
};
We.prototype.lineNo = function() {
return ft(this)
}, le(We);
var Je = {},
Ye = {};
function Ge(t, e) {
if (!t || /^\s*$/.test(t)) return null;
var n = e.addModeClass ? Ye : Je;
return n[t] || (n[t] = t.replace(/\S+/g, "cm-$&"))
}
function Ke(t, e) {
var n = S("span", null, null, u ? "padding-right: .1px" : null),
i = {
pre: S("pre", [n], "CodeMirror-line"),
content: n,
col: 0,
pos: 0,
cm: t,
trailingSpace: !1,
splitSpaces: (a || u) && t.getOption("lineWrapping")
};
e.measure = {};
for (var r = 0; r <= (e.rest ? e.rest.length : 0); r++) {
var o = r ? e.rest[r - 1] : e.line,
s = void 0;
i.pos = 0, i.addToken = Qe, Fe(t.display.measure) && (s = Qt(o, t.doc.direction)) && (i.addToken = Xe(i.addToken, s)), i.map = [];
tn(o, i, Ne(t, o, e != t.display.externalMeasured && ft(o))), o.styleClasses && (o.styleClasses.bgClass && (i.bgClass = R(o.styleClasses.bgClass, i.bgClass || "")), o.styleClasses.textClass && (i.textClass = R(o.styleClasses.textClass, i.textClass || ""))), 0 == i.map.length && i.map.push(0, 0, i.content.appendChild(ye(t.display.measure))), 0 == r ? (e.measure.map = i.map, e.measure.cache = {}) : ((e.measure.maps || (e.measure.maps = [])).push(i.map), (e.measure.caches || (e.measure.caches = [])).push({}))
}
if (u) {
var c = i.content.lastChild;
(/\bcm-tab\b/.test(c.className) || c.querySelector && c.querySelector(".cm-tab")) && (i.content.className = "cm-tab-wrap-hack")
}
return ae(t, "renderLine", t, e.line, i.pre), i.pre.className && (i.textClass = R(i.pre.className, i.textClass || "")), i
}
function Ve(t) {
var e = A("span", "•", "cm-invalidchar");
return e.title = "\\u" + t.charCodeAt(0).toString(16), e.setAttribute("aria-label", e.title), e
}
function Qe(t, e, n, i, r, o, u) {
if (e) {
var c, l = t.splitSpaces ? function(t, e) {
if (t.length > 1 && !/ /.test(t)) return t;
for (var n = e, i = "", r = 0; r < t.length; r++) {
var o = t.charAt(r);
" " != o || !n || r != t.length - 1 && 32 != t.charCodeAt(r + 1) || (o = " "), i += o, n = " " == o
}
return i
}(e, t.trailingSpace) : e,
f = t.cm.state.specialChars,
h = !1;
if (f.test(e)) {
c = document.createDocumentFragment();
for (var d = 0;;) {
f.lastIndex = d;
var m = f.exec(e),
v = m ? m.index - d : e.length - d;
if (v) {
var p = document.createTextNode(l.slice(d, d + v));
a && s < 9 ? c.appendChild(A("span", [p])) : c.appendChild(p), t.map.push(t.pos, t.pos + v, p), t.col += v, t.pos += v
}
if (!m) break;
d += v + 1;
var g = void 0;
if ("\t" == m[0]) {
var b = t.cm.options.tabSize,
y = b - t.col % b;
(g = c.appendChild(A("span", G(y), "cm-tab"))).setAttribute("role", "presentation"), g.setAttribute("cm-text", "\t"), t.col += y
} else "\r" == m[0] || "\n" == m[0] ? ((g = c.appendChild(A("span", "\r" == m[0] ? "␍" : "␤", "cm-invalidchar"))).setAttribute("cm-text", m[0]), t.col += 1) : ((g = t.cm.options.specialCharPlaceholder(m[0])).setAttribute("cm-text", m[0]), a && s < 9 ? c.appendChild(A("span", [g])) : c.appendChild(g), t.col += 1);
t.map.push(t.pos, t.pos + 1, g), t.pos++
}
} else t.col += e.length, c = document.createTextNode(l), t.map.push(t.pos, t.pos + e.length, c), a && s < 9 && (h = !0), t.pos += e.length;
if (t.trailingSpace = 32 == l.charCodeAt(e.length - 1), n || i || r || h || u) {
var w = n || "";
i && (w += i), r && (w += r);
var F = A("span", [c], w, u);
return o && (F.title = o), t.content.appendChild(F)
}
t.content.appendChild(c)
}
}
function Xe(t, e) {
return function(n, i, r, o, a, s, u) {
r = r ? r + " cm-force-border" : "cm-force-border";
for (var c = n.pos, l = c + i.length;;) {
for (var f = void 0, h = 0; h < e.length && !((f = e[h]).to > c && f.from <= c); h++);
if (f.to >= l) return t(n, i, r, o, a, s, u);
t(n, i.slice(0, f.to - c), r, o, null, s, u), o = null, i = i.slice(f.to - c), c = f.to
}
}
}
function Ze(t, e, n, i) {
var r = !i && n.widgetNode;
r && t.map.push(t.pos, t.pos + e, r), !i && t.cm.display.input.needsContentAttribute && (r || (r = t.content.appendChild(document.createElement("span"))), r.setAttribute("cm-marker", n.id)), r && (t.cm.display.input.setUneditable(r), t.content.appendChild(r)), t.pos += e, t.trailingSpace = !1
}
function tn(t, e, n) {
var i = t.markedSpans,
r = t.text,
o = 0;
if (i)
for (var a, s, u, c, l, f, h, d = r.length, m = 0, v = 1, p = "", g = 0;;) {
if (g == m) {
u = c = l = f = s = "", h = null, g = 1 / 0;
for (var b = [], y = void 0, w = 0; w < i.length; ++w) {
var F = i[w],
k = F.marker;
"bookmark" == k.type && F.from == m && k.widgetNode ? b.push(k) : F.from <= m && (null == F.to || F.to > m || k.collapsed && F.to == m && F.from == m) ? (null != F.to && F.to != m && g > F.to && (g = F.to, c = ""), k.className && (u += " " + k.className), k.css && (s = (s ? s + ";" : "") + k.css), k.startStyle && F.from == m && (l += " " + k.startStyle), k.endStyle && F.to == g && (y || (y = [])).push(k.endStyle, F.to), k.title && !f && (f = k.title), k.collapsed && (!h || Bt(h.marker, k) < 0) && (h = F)) : F.from > m && g > F.from && (g = F.from)
}
if (y)
for (var x = 0; x < y.length; x += 2) y[x + 1] == g && (c += " " + y[x]);
if (!h || h.from == m)
for (var _ = 0; _ < b.length; ++_) Ze(e, 0, b[_]);
if (h && (h.from || 0) == m) {
if (Ze(e, (null == h.to ? d + 1 : h.to) - m, h.marker, null == h.from), null == h.to) return;
h.to == m && (h = !1)
}
}
if (m >= d) break;
for (var $ = Math.min(d, g);;) {
if (p) {
var E = m + p.length;
if (!h) {
var C = E > $ ? p.slice(0, $ - m) : p;
e.addToken(e, C, a ? a + u : u, l, m + C.length == g ? c : "", f, s)
}
if (E >= $) {
p = p.slice($ - m), m = $;
break
}
m = E, l = ""
}
p = r.slice(o, o = n[v++]), a = Ge(n[v++], e.cm.options)
}
} else
for (var A = 1; A < n.length; A += 2) e.addToken(e, r.slice(o, o = n[A]), Ge(n[A + 1], e.cm.options))
}
function en(t, e, n) {
this.line = e, this.rest = function(t) {
for (var e, n; e = Ot(t);) t = e.find(1, !0).line, (n || (n = [])).push(t);
return n
}(e), this.size = this.rest ? ft(K(this.rest)) - n + 1 : 1, this.node = this.text = null, this.hidden = zt(t, e)
}
function nn(t, e, n) {
for (var i, r = [], o = e; o < n; o = i) {
var a = new en(t.doc, st(t.doc, o), o);
i = o + a.size, r.push(a)
}
return r
}
var rn = null;
var on = null;
function an(t, e) {
var n = re(t, e);
if (n.length) {
var i, r = Array.prototype.slice.call(arguments, 2);
rn ? i = rn.delayedCallbacks : on ? i = on : (i = on = [], setTimeout(sn, 0));
for (var o = function(t) {
i.push(function() {
return n[t].apply(null, r)
})
}, a = 0; a < n.length; ++a) o(a)
}
}
function sn() {
var t = on;
on = null;
for (var e = 0; e < t.length; ++e) t[e]()
}
function un(t, e, n, i) {
for (var r = 0; r < e.changes.length; r++) {
var o = e.changes[r];
"text" == o ? fn(t, e) : "gutter" == o ? dn(t, e, n, i) : "class" == o ? hn(t, e) : "widget" == o && mn(t, e, i)
}
e.changes = null
}
function cn(t) {
return t.node == t.text && (t.node = A("div", null, null, "position: relative"), t.text.parentNode && t.text.parentNode.replaceChild(t.node, t.text), t.node.appendChild(t.text), a && s < 8 && (t.node.style.zIndex = 2)), t.node
}
function ln(t, e) {
var n = t.display.externalMeasured;
return n && n.line == e.line ? (t.display.externalMeasured = null, e.measure = n.measure, n.built) : Ke(t, e)
}
function fn(t, e) {
var n = e.text.className,
i = ln(t, e);
e.text == e.node && (e.node = i.pre), e.text.parentNode.replaceChild(i.pre, e.text), e.text = i.pre, i.bgClass != e.bgClass || i.textClass != e.textClass ? (e.bgClass = i.bgClass, e.textClass = i.textClass, hn(t, e)) : n && (e.text.className = n)
}
function hn(t, e) {
! function(t, e) {
var n = e.bgClass ? e.bgClass + " " + (e.line.bgClass || "") : e.line.bgClass;
if (n && (n += " CodeMirror-linebackground"), e.background) n ? e.background.className = n : (e.background.parentNode.removeChild(e.background), e.background = null);
else if (n) {
var i = cn(e);
e.background = i.insertBefore(A("div", null, n), i.firstChild), t.display.input.setUneditable(e.background)
}
}(t, e), e.line.wrapClass ? cn(e).className = e.line.wrapClass : e.node != e.text && (e.node.className = "");
var n = e.textClass ? e.textClass + " " + (e.line.textClass || "") : e.line.textClass;
e.text.className = n || ""
}
function dn(t, e, n, i) {
if (e.gutter && (e.node.removeChild(e.gutter), e.gutter = null), e.gutterBackground && (e.node.removeChild(e.gutterBackground), e.gutterBackground = null), e.line.gutterClass) {
var r = cn(e);
e.gutterBackground = A("div", null, "CodeMirror-gutter-background " + e.line.gutterClass, "left: " + (t.options.fixedGutter ? i.fixedPos : -i.gutterTotalWidth) + "px; width: " + i.gutterTotalWidth + "px"), t.display.input.setUneditable(e.gutterBackground), r.insertBefore(e.gutterBackground, e.text)
}
var o = e.line.gutterMarkers;
if (t.options.lineNumbers || o) {
var a = 0 === n || n === t.lineCount() - 1 || (n + 1) % 10 == 0 ? " CodeMirror-linenumber-show" : "",
s = cn(e),
u = e.gutter = A("div", null, "CodeMirror-gutter-wrapper", "left: " + (t.options.fixedGutter ? i.fixedPos : -i.gutterTotalWidth) + "px");
if (t.display.input.setUneditable(u), s.insertBefore(u, e.text), e.line.gutterClass && (u.className += " " + e.line.gutterClass), !t.options.lineNumbers || o && o["CodeMirror-linenumbers"] || (e.lineNumber = u.appendChild(A("div", mt(t.options, n), "CodeMirror-linenumber CodeMirror-gutter-elt" + a, "left: " + i.gutterLeft["CodeMirror-linenumbers"] + "px; width: " + t.display.lineNumInnerWidth + "px"))), o)
for (var c = 0; c < t.options.gutters.length; ++c) {
var l = t.options.gutters[c],
f = o.hasOwnProperty(l) && o[l];
f && u.appendChild(A("div", [f], "CodeMirror-gutter-elt", "left: " + i.gutterLeft[l] + "px; width: " + i.gutterWidth[l] + "px"))
}
}
}
function mn(t, e, n) {
e.alignable && (e.alignable = null);
for (var i = e.node.firstChild, r = void 0; i; i = r) r = i.nextSibling, "CodeMirror-linewidget" == i.className && e.node.removeChild(i);
pn(t, e, n)
}
function vn(t, e, n, i) {
var r = ln(t, e);
return e.text = e.node = r.pre, r.bgClass && (e.bgClass = r.bgClass), r.textClass && (e.textClass = r.textClass), hn(t, e), dn(t, e, n, i), pn(t, e, i), e.node
}
function pn(t, e, n) {
if (gn(t, e.line, e, n, !0), e.rest)
for (var i = 0; i < e.rest.length; i++) gn(t, e.rest[i], e, n, !1)
}
function gn(t, e, n, i, r) {
if (e.widgets)
for (var o = cn(n), a = 0, s = e.widgets; a < s.length; ++a) {
var u = s[a],
c = A("div", [u.node], "CodeMirror-linewidget");
u.handleMouseEvents || c.setAttribute("cm-ignore-events", "true"), bn(u, c, n, i), t.display.input.setUneditable(c), r && u.above ? o.insertBefore(c, n.gutter || n.text) : o.appendChild(c), an(u, "redraw")
}
}
function bn(t, e, n, i) {
if (t.noHScroll) {
(n.alignable || (n.alignable = [])).push(e);
var r = i.wrapperWidth;
e.style.left = i.fixedPos + "px", t.coverGutter || (r -= i.gutterTotalWidth, e.style.paddingLeft = i.gutterTotalWidth + "px"), e.style.width = r + "px"
}
t.coverGutter && (e.style.zIndex = 5, e.style.position = "relative", t.noHScroll || (e.style.marginLeft = -i.gutterTotalWidth + "px"))
}
function yn(t) {
if (null != t.height) return t.height;
var e = t.doc.cm;
if (!e) return 0;
if (!M(document.body, t.node)) {
var n = "position: relative;";
t.coverGutter && (n += "margin-left: -" + e.display.gutters.offsetWidth + "px;"), t.noHScroll && (n += "width: " + e.display.wrapper.clientWidth + "px;"), C(e.display.measure, A("div", [t.node], null, n))
}
return t.height = t.node.parentNode.offsetHeight
}
function wn(t, e) {
for (var n = ve(e); n != t.wrapper; n = n.parentNode)
if (!n || 1 == n.nodeType && "true" == n.getAttribute("cm-ignore-events") || n.parentNode == t.sizer && n != t.mover) return !0
}
function Fn(t) {
return t.lineSpace.offsetTop
}
function kn(t) {
return t.mover.offsetHeight - t.lineSpace.offsetHeight
}
function xn(t) {
if (t.cachedPaddingH) return t.cachedPaddingH;
var e = C(t.measure, A("pre", "x")),
n = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle,
i = {
left: parseInt(n.paddingLeft),
right: parseInt(n.paddingRight)
};
return isNaN(i.left) || isNaN(i.right) || (t.cachedPaddingH = i), i
}
function _n(t) {
return q - t.display.nativeBarWidth
}
function $n(t) {
return t.display.lineDiv.clientWidth
}
function En(t) {
return t.display.scroller.clientHeight - _n(t) - t.display.barHeight
}
function Cn(t, e, n) {
if (t.line == e) return {
map: t.measure.map,
cache: t.measure.cache
};
for (var i = 0; i < t.rest.length; i++)
if (t.rest[i] == e) return {
map: t.measure.maps[i],
cache: t.measure.caches[i]
};
for (var r = 0; r < t.rest.length; r++)
if (ft(t.rest[r]) > n) return {
map: t.measure.maps[r],
cache: t.measure.caches[r],
before: !0
}
}
function An(t, e, n, i) {
return Mn(t, Tn(t, e), n, i)
}
function Sn(t, e) {
if (e >= t.display.viewFrom && e < t.display.viewTo) return t.display.view[ii(t, e)];
var n = t.display.externalMeasured;
return n && e >= n.lineN && e < n.lineN + n.size ? n : void 0
}
function Tn(t, e) {
var n = ft(e),
i = Sn(t, n);
i && !i.text ? i = null : i && i.changes && (un(t, i, n, Xn(t)), t.curOp.forceUpdate = !0), i || (i = function(t, e) {
var n = ft(e = Pt(e)),
i = t.display.externalMeasured = new en(t.doc, e, n);
i.lineN = n;
var r = i.built = Ke(t, i);
return i.text = r.pre, C(t.display.lineMeasure, r.pre), i
}(t, e));
var r = Cn(i, e, n);
return {
line: e,
view: i,
rect: null,
map: r.map,
cache: r.cache,
before: r.before,
hasHeights: !1
}
}
function Mn(t, e, n, i, r) {
e.before && (n = -1);
var o, u = n + (i || "");
return e.cache.hasOwnProperty(u) ? o = e.cache[u] : (e.rect || (e.rect = e.view.text.getBoundingClientRect()), e.hasHeights || (! function(t, e, n) {
var i = t.options.lineWrapping,
r = i && $n(t);
if (!e.measure.heights || i && e.measure.width != r) {
var o = e.measure.heights = [];
if (i) {
e.measure.width = r;
for (var a = e.text.firstChild.getClientRects(), s = 0; s < a.length - 1; s++) {
var u = a[s],
c = a[s + 1];
Math.abs(u.bottom - c.bottom) > 2 && o.push((u.bottom + c.top) / 2 - n.top)
}
}
o.push(n.bottom - n.top)
}
}(t, e.view, e.rect), e.hasHeights = !0), (o = function(t, e, n, i) {
var r, o = Ln(e.map, n, i),
u = o.node,
c = o.start,
l = o.end,
f = o.collapse;
if (3 == u.nodeType) {
for (var h = 0; h < 4; h++) {
for (; c && rt(e.line.text.charAt(o.coverStart + c));) --c;
for (; o.coverStart + l < o.coverEnd && rt(e.line.text.charAt(o.coverStart + l));) ++l;
if ((r = a && s < 9 && 0 == c && l == o.coverEnd - o.coverStart ? u.parentNode.getBoundingClientRect() : Rn(T(u, c, l).getClientRects(), i)).left || r.right || 0 == c) break;
l = c, c -= 1, f = "right"
}
a && s < 11 && (r = function(t, e) {
if (!window.screen || null == screen.logicalXDPI || screen.logicalXDPI == screen.deviceXDPI || ! function(t) {
if (null != $e) return $e;
var e = C(t, A("span", "x")),
n = e.getBoundingClientRect(),
i = T(e, 0, 1).getBoundingClientRect();
return $e = Math.abs(n.left - i.left) > 1
}(t)) return e;
var n = screen.logicalXDPI / screen.deviceXDPI,
i = screen.logicalYDPI / screen.deviceYDPI;
return {
left: e.left * n,
right: e.right * n,
top: e.top * i,
bottom: e.bottom * i
}
}(t.display.measure, r))
} else {
c > 0 && (f = i = "right");
var d;
r = t.options.lineWrapping && (d = u.getClientRects()).length > 1 ? d["right" == i ? d.length - 1 : 0] : u.getBoundingClientRect()
}
if (a && s < 9 && !c && (!r || !r.left && !r.right)) {
var m = u.parentNode.getClientRects()[0];
r = m ? {
left: m.left,
right: m.left + Qn(t.display),
top: m.top,
bottom: m.bottom
} : Dn
}
for (var v = r.top - e.rect.top, p = r.bottom - e.rect.top, g = (v + p) / 2, b = e.view.measure.heights, y = 0; y < b.length - 1 && !(g < b[y]); y++);
var w = y ? b[y - 1] : 0,
F = b[y],
k = {
left: ("right" == f ? r.right : r.left) - e.rect.left,
right: ("left" == f ? r.left : r.right) - e.rect.left,
top: w,
bottom: F
};
r.left || r.right || (k.bogus = !0);
t.options.singleCursorHeightPerLine || (k.rtop = v, k.rbottom = p);
return k
}(t, e, n, i)).bogus || (e.cache[u] = o)), {
left: o.left,
right: o.right,
top: r ? o.rtop : o.top,
bottom: r ? o.rbottom : o.bottom
}
}
var Dn = {
left: 0,
right: 0,
top: 0,
bottom: 0
};
function Ln(t, e, n) {
for (var i, r, o, a, s, u, c = 0; c < t.length; c += 3)
if (s = t[c], u = t[c + 1], e < s ? (r = 0, o = 1, a = "left") : e < u ? o = (r = e - s) + 1 : (c == t.length - 3 || e == u && t[c + 3] > e) && (r = (o = u - s) - 1, e >= u && (a = "right")), null != r) {
if (i = t[c + 2], s == u && n == (i.insertLeft ? "left" : "right") && (a = n), "left" == n && 0 == r)
for (; c && t[c - 2] == t[c - 3] && t[c - 1].insertLeft;) i = t[2 + (c -= 3)], a = "left";
if ("right" == n && r == u - s)
for (; c < t.length - 3 && t[c + 3] == t[c + 4] && !t[c + 5].insertLeft;) i = t[(c += 3) + 2], a = "right";
break
}
return {
node: i,
start: r,
end: o,
collapse: a,
coverStart: s,
coverEnd: u
}
}
function Rn(t, e) {
var n = Dn;
if ("left" == e)
for (var i = 0; i < t.length && (n = t[i]).left == n.right; i++);
else
for (var r = t.length - 1; r >= 0 && (n = t[r]).left == n.right; r--);
return n
}
function Bn(t) {
if (t.measure && (t.measure.cache = {}, t.measure.heights = null, t.rest))
for (var e = 0; e < t.rest.length; e++) t.measure.caches[e] = {}
}
function In(t) {
t.display.externalMeasure = null, E(t.display.lineMeasure);
for (var e = 0; e < t.display.view.length; e++) Bn(t.display.view[e])
}
function Nn(t) {
In(t), t.display.cachedCharWidth = t.display.cachedTextHeight = t.display.cachedPaddingH = null, t.options.lineWrapping || (t.display.maxLineChanged = !0), t.display.lineNumChars = null
}
function On() {
return l && p ? -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft)) : window.pageXOffset || (document.documentElement || document.body).scrollLeft
}
function jn() {
return l && p ? -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop)) : window.pageYOffset || (document.documentElement || document.body).scrollTop
}
function Pn(t, e, n, i, r) {
if (!r && e.widgets)
for (var o = 0; o < e.widgets.length; ++o)
if (e.widgets[o].above) {
var a = yn(e.widgets[o]);
n.top += a, n.bottom += a
}
if ("line" == i) return n;
i || (i = "local");
var s = Wt(e);
if ("local" == i ? s += Fn(t.display) : s -= t.display.viewOffset, "page" == i || "window" == i) {
var u = t.display.lineSpace.getBoundingClientRect();
s += u.top + ("window" == i ? 0 : jn());
var c = u.left + ("window" == i ? 0 : On());
n.left += c, n.right += c
}
return n.top += s, n.bottom += s, n
}
function qn(t, e, n) {
if ("div" == n) return e;
var i = e.left,
r = e.top;
if ("page" == n) i -= On(), r -= jn();
else if ("local" == n || !n) {
var o = t.display.sizer.getBoundingClientRect();
i += o.left, r += o.top
}
var a = t.display.lineSpace.getBoundingClientRect();
return {
left: i - a.left,
top: r - a.top
}
}
function Un(t, e, n, i, r) {
return i || (i = st(t.doc, e.line)), Pn(t, i, An(t, i, e.ch, r), n)
}
function zn(t, e, n, i, r, o) {
i = i || st(t.doc, e.line), r || (r = Tn(t, i));
function a(e, a) {
var s = Mn(t, r, e, a ? "right" : "left", o);
return a ? s.left = s.right : s.right = s.left, Pn(t, i, s, n)
}
var s = Qt(i, t.doc.direction),
u = e.ch,
c = e.sticky;
if (u >= i.text.length ? (u = i.text.length, c = "before") : u <= 0 && (u = 0, c = "after"), !s) return a("before" == c ? u - 1 : u, "before" == c);
function l(t, e, n) {
var i = s[e].level % 2 != 0;
return a(n ? t - 1 : t, i != n)
}
var f = Kt(s, u, c),
h = Gt,
d = l(u, f, "before" == c);
return null != h && (d.other = l(u, h, "before" != c)), d
}
function Hn(t, e) {
var n = 0;
e = kt(t.doc, e), t.options.lineWrapping || (n = Qn(t.display) * e.ch);
var i = st(t.doc, e.line),
r = Wt(i) + Fn(t.display);
return {
left: n,
right: n,
top: r,
bottom: r + i.height
}
}
function Wn(t, e, n, i, r) {
var o = vt(t, e, n);
return o.xRel = r, i && (o.outside = !0), o
}
function Jn(t, e, n) {
var i = t.doc;
if ((n += t.display.viewOffset) < 0) return Wn(i.first, 0, null, !0, -1);
var r = ht(i, n),
o = i.first + i.size - 1;
if (r > o) return Wn(i.first + i.size - 1, st(i, o).text.length, null, !0, 1);
e < 0 && (e = 0);
for (var a = st(i, r);;) {
var s = Gn(t, a, r, e, n),
u = Ot(a),
c = u && u.find(0, !0);
if (!u || !(s.ch > c.from.ch || s.ch == c.from.ch && s.xRel > 0)) return s;
r = ft(a = c.to.line)
}
}
function Yn(t, e, n, i) {
var r = function(i) {
return Pn(t, e, Mn(t, n, i), "line")
},
o = e.text.length,
a = at(function(t) {
return r(t - 1).bottom <= i
}, o, 0);
return {
begin: a,
end: o = at(function(t) {
return r(t).top > i
}, a, o)
}
}
function Gn(t, e, n, i, r) {
r -= Wt(e);
var o, a = 0,
s = e.text.length,
u = Tn(t, e);
if (Qt(e, t.doc.direction)) {
if (t.options.lineWrapping) {
var c;
a = (c = Yn(t, e, u, r)).begin, s = c.end
}
o = new vt(n, a);
var l, f, h = zn(t, o, "line", e, u).left,
d = h < i ? 1 : -1,
m = h - i;
do {
if (l = m, f = o, null == (o = ee(t, e, o, d)) || o.ch < a || s <= ("before" == o.sticky ? o.ch - 1 : o.ch)) {
o = f;
break
}
m = zn(t, o, "line", e, u).left - i
} while (d < 0 != m < 0 && Math.abs(m) <= Math.abs(l));
if (Math.abs(m) > Math.abs(l)) {
if (m < 0 == l < 0) throw new Error("Broke out of infinite loop in coordsCharInner");
o = f
}
} else {
var v = at(function(n) {
var o = Pn(t, e, Mn(t, u, n), "line");
return o.top > r ? (s = Math.min(n, s), !0) : !(o.bottom <= r) && (o.left > i || !(o.right < i) && i - o.left < o.right - i)
}, a, s);
o = new vt(n, v = ot(e.text, v, 1), v == s ? "before" : "after")
}
var p = zn(t, o, "line", e, u);
return (r < p.top || p.bottom < r) && (o.outside = !0), o.xRel = i < p.left ? -1 : i > p.right ? 1 : 0, o
}
var Kn;
function Vn(t) {
if (null != t.cachedTextHeight) return t.cachedTextHeight;
if (null == Kn) {
Kn = A("pre");
for (var e = 0; e < 49; ++e) Kn.appendChild(document.createTextNode("x")), Kn.appendChild(A("br"));
Kn.appendChild(document.createTextNode("x"))
}
C(t.measure, Kn);
var n = Kn.offsetHeight / 50;
return n > 3 && (t.cachedTextHeight = n), E(t.measure), n || 1
}
function Qn(t) {
if (null != t.cachedCharWidth) return t.cachedCharWidth;
var e = A("span", "xxxxxxxxxx"),
n = A("pre", [e]);
C(t.measure, n);
var i = e.getBoundingClientRect(),
r = (i.right - i.left) / 10;
return r > 2 && (t.cachedCharWidth = r), r || 10
}
function Xn(t) {
for (var e = t.display, n = {}, i = {}, r = e.gutters.clientLeft, o = e.gutters.firstChild, a = 0; o; o = o.nextSibling, ++a) n[t.options.gutters[a]] = o.offsetLeft + o.clientLeft + r, i[t.options.gutters[a]] = o.clientWidth;
return {
fixedPos: Zn(e),
gutterTotalWidth: e.gutters.offsetWidth,
gutterLeft: n,
gutterWidth: i,
wrapperWidth: e.wrapper.clientWidth
}
}
function Zn(t) {
return t.scroller.getBoundingClientRect().left - t.sizer.getBoundingClientRect().left
}
function ti(t) {
var e = Vn(t.display),
n = t.options.lineWrapping,
i = n && Math.max(5, t.display.scroller.clientWidth / Qn(t.display) - 3);
return function(r) {
if (zt(t.doc, r)) return 0;
var o = 0;
if (r.widgets)
for (var a = 0; a < r.widgets.length; a++) r.widgets[a].height && (o += r.widgets[a].height);
return n ? o + (Math.ceil(r.text.length / i) || 1) * e : o + e
}
}
function ei(t) {
var e = t.doc,
n = ti(t);
e.iter(function(t) {
var e = n(t);
e != t.height && lt(t, e)
})
}
function ni(t, e, n, i) {
var r = t.display;
if (!n && "true" == ve(e).getAttribute("cm-not-content")) return null;
var o, a, s = r.lineSpace.getBoundingClientRect();
try {
o = e.clientX - s.left, a = e.clientY - s.top
} catch (e) {
return null
}
var u, c = Jn(t, o, a);
if (i && 1 == c.xRel && (u = st(t.doc, c.line).text).length == c.ch) {
var l = O(u, u.length, t.options.tabSize) - u.length;
c = vt(c.line, Math.max(0, Math.round((o - xn(t.display).left) / Qn(t.display)) - l))
}
return c
}
la.posFromMouse = ni;
function ii(t, e) {
if (e >= t.display.viewTo) return null;
if ((e -= t.display.viewFrom) < 0) return null;
for (var n = t.display.view, i = 0; i < n.length; i++)
if ((e -= n[i].size) < 0) return i
}
function ri(t) {
t.display.input.showSelection(t.display.input.prepareSelection())
}
function oi(t, e) {
for (var n = t.doc, i = {}, r = i.cursors = document.createDocumentFragment(), o = i.selection = document.createDocumentFragment(), a = 0; a < n.sel.ranges.length; a++)
if (!1 !== e || a != n.sel.primIndex) {
var s = n.sel.ranges[a];
if (!(s.from().line >= t.display.viewTo || s.to().line < t.display.viewFrom)) {
var u = s.empty();
(u || t.options.showCursorWhenSelecting) && ai(t, s.head, r), u || si(t, s, o)
}
}
return i
}
function ai(t, e, n) {
var i = zn(t, e, "div", null, null, !t.options.singleCursorHeightPerLine),
r = n.appendChild(A("div", " ", "CodeMirror-cursor"));
if (r.style.left = i.left + "px", r.style.top = i.top + "px", r.style.height = Math.max(0, i.bottom - i.top) * t.options.cursorHeight + "px", i.other) {
var o = n.appendChild(A("div", " ", "CodeMirror-cursor CodeMirror-secondarycursor"));
o.style.display = "", o.style.left = i.other.left + "px", o.style.top = i.other.top + "px", o.style.height = .85 * (i.other.bottom - i.other.top) + "px"
}
}
function si(t, e, n) {
var i = t.display,
r = t.doc,
o = document.createDocumentFragment(),
a = xn(t.display),
s = a.left,
u = Math.max(i.sizerWidth, $n(t) - i.sizer.offsetLeft) - a.right;
function c(t, e, n, i) {
e < 0 && (e = 0), e = Math.round(e), i = Math.round(i), o.appendChild(A("div", null, "CodeMirror-selected", "position: absolute; left: " + t + "px;\n top: " + e + "px; width: " + (null == n ? u - t : n) + "px;\n height: " + (i - e) + "px"))
}
function l(e, n, i) {
var o, a, l = st(r, e),
f = l.text.length;
function h(n, i) {
return Un(t, vt(e, n), "div", l, i)
}
return function(t, e, n, i) {
if (!t) return i(e, n, "ltr");
for (var r = !1, o = 0; o < t.length; ++o) {
var a = t[o];
(a.from < n && a.to > e || e == n && a.to == e) && (i(Math.max(a.from, e), Math.min(a.to, n), 1 == a.level ? "rtl" : "ltr"), r = !0)
}
r || i(e, n, "ltr")
}(Qt(l, r.direction), n || 0, null == i ? f : i, function(t, e, r) {
var l, d, m, v = h(t, "left");
if (t == e) l = v, d = m = v.left;
else {
if (l = h(e - 1, "right"), "rtl" == r) {
var p = v;
v = l, l = p
}
d = v.left, m = l.right
}
null == n && 0 == t && (d = s), l.top - v.top > 3 && (c(d, v.top, null, v.bottom), d = s, v.bottom < l.top && c(d, v.bottom, null, l.top)), null == i && e == f && (m = u), (!o || v.top < o.top || v.top == o.top && v.left < o.left) && (o = v), (!a || l.bottom > a.bottom || l.bottom == a.bottom && l.right > a.right) && (a = l), d < s + 1 && (d = s), c(d, l.top, m - d, l.bottom)
}), {
start: o,
end: a
}
}
var f = e.from(),
h = e.to();
if (f.line == h.line) l(f.line, f.ch, h.ch);
else {
var d = st(r, f.line),
m = st(r, h.line),
v = Pt(d) == Pt(m),
p = l(f.line, f.ch, v ? d.text.length + 1 : null).end,
g = l(h.line, v ? 0 : null, h.ch).start;
v && (p.top < g.top - 2 ? (c(p.right, p.top, null, p.bottom), c(s, g.top, g.left, g.bottom)) : c(p.right, p.top, g.left - p.right, p.bottom)), p.bottom < g.top && c(s, p.bottom, null, g.top)
}
n.appendChild(o)
}
function ui(t) {
if (t.state.focused) {
var e = t.display;
clearInterval(e.blinker);
var n = !0;
e.cursorDiv.style.visibility = "", t.options.cursorBlinkRate > 0 ? e.blinker = setInterval(function() {
return e.cursorDiv.style.visibility = (n = !n) ? "" : "hidden"
}, t.options.cursorBlinkRate) : t.options.cursorBlinkRate < 0 && (e.cursorDiv.style.visibility = "hidden")
}
}
function ci(t) {
t.state.focused || (t.display.input.focus(), fi(t))
}
function li(t) {
t.state.delayingBlurEvent = !0, setTimeout(function() {
t.state.delayingBlurEvent && (t.state.delayingBlurEvent = !1, hi(t))
}, 100)
}
function fi(t, e) {
t.state.delayingBlurEvent && (t.state.delayingBlurEvent = !1), "nocursor" != t.options.readOnly && (t.state.focused || (ae(t, "focus", t, e), t.state.focused = !0, L(t.display.wrapper, "CodeMirror-focused"), t.curOp || t.display.selForContextMenu == t.doc.sel || (t.display.input.reset(), u && setTimeout(function() {
return t.display.input.reset(!0)
}, 20)), t.display.input.receivedFocus()), ui(t))
}
function hi(t, e) {
t.state.delayingBlurEvent || (t.state.focused && (ae(t, "blur", t, e), t.state.focused = !1, $(t.display.wrapper, "CodeMirror-focused")), clearInterval(t.display.blinker), setTimeout(function() {
t.state.focused || (t.display.shift = !1)
}, 150))
}
function di(t) {
for (var e = t.display, n = e.lineDiv.offsetTop, i = 0; i < e.view.length; i++) {
var r = e.view[i],
o = void 0;
if (!r.hidden) {
if (a && s < 8) {
var u = r.node.offsetTop + r.node.offsetHeight;
o = u - n, n = u
} else {
var c = r.node.getBoundingClientRect();
o = c.bottom - c.top
}
var l = r.line.height - o;
if (o < 2 && (o = Vn(e)), (l > .001 || l < -.001) && (lt(r.line, o), mi(r.line), r.rest))
for (var f = 0; f < r.rest.length; f++) mi(r.rest[f])
}
}
}
function mi(t) {
if (t.widgets)
for (var e = 0; e < t.widgets.length; ++e) t.widgets[e].height = t.widgets[e].node.parentNode.offsetHeight
}
function vi(t, e, n) {
var i = n && null != n.top ? Math.max(0, n.top) : t.scroller.scrollTop;
i = Math.floor(i - Fn(t));
var r = n && null != n.bottom ? n.bottom : i + t.wrapper.clientHeight,
o = ht(e, i),
a = ht(e, r);
if (n && n.ensure) {
var s = n.ensure.from.line,
u = n.ensure.to.line;
s < o ? (o = s, a = ht(e, Wt(st(e, s)) + t.wrapper.clientHeight)) : Math.min(u, e.lastLine()) >= a && (o = ht(e, Wt(st(e, u)) - t.wrapper.clientHeight), a = u)
}
return {
from: o,
to: Math.max(a, o + 1)
}
}
function pi(t) {
var e = t.display,
n = e.view;
if (e.alignWidgets || e.gutters.firstChild && t.options.fixedGutter) {
for (var i = Zn(e) - e.scroller.scrollLeft + t.doc.scrollLeft, r = e.gutters.offsetWidth, o = i + "px", a = 0; a < n.length; a++)
if (!n[a].hidden) {
t.options.fixedGutter && (n[a].gutter && (n[a].gutter.style.left = o), n[a].gutterBackground && (n[a].gutterBackground.style.left = o));
var s = n[a].alignable;
if (s)
for (var u = 0; u < s.length; u++) s[u].style.left = o
}
t.options.fixedGutter && (e.gutters.style.left = i + r + "px")
}
}
function gi(t) {
if (!t.options.lineNumbers) return !1;
var e = t.doc,
n = mt(t.options, e.first + e.size - 1),
i = t.display;
if (n.length != i.lineNumChars) {
var r = i.measure.appendChild(A("div", [A("div", n)], "CodeMirror-linenumber CodeMirror-gutter-elt")),
o = r.firstChild.offsetWidth,
a = r.offsetWidth - o;
return i.lineGutter.style.width = "", i.lineNumInnerWidth = Math.max(o, i.lineGutter.offsetWidth - a) + a + 2, i.lineNumWidth = i.lineNumInnerWidth + a, i.lineNumChars = i.lineNumInnerWidth ? n.length : -1, i.lineGutter.style.width = i.lineNumWidth + "px", nr(t), !0
}
return !1
}
function bi(t, e) {
var n = t.display,
i = Vn(t.display);
e.top < 0 && (e.top = 0);
var r = t.curOp && null != t.curOp.scrollTop ? t.curOp.scrollTop : n.scroller.scrollTop,
o = En(t),
a = {};
e.bottom - e.top > o && (e.bottom = e.top + o);
var s = t.doc.height + kn(n),
u = e.top < i,
c = e.bottom > s - i;
if (e.top < r) a.scrollTop = u ? 0 : e.top;
else if (e.bottom > r + o) {
var l = Math.min(e.top, (c ? s : e.bottom) - o);
l != r && (a.scrollTop = l)
}
var f = t.curOp && null != t.curOp.scrollLeft ? t.curOp.scrollLeft : n.scroller.scrollLeft,
h = $n(t) - (t.options.fixedGutter ? n.gutters.offsetWidth : 0),
d = e.right - e.left > h;
return d && (e.right = e.left + h), e.left < 10 ? a.scrollLeft = 0 : e.left < f ? a.scrollLeft = Math.max(0, e.left - (d ? 0 : 10)) : e.right > h + f - 3 && (a.scrollLeft = e.right + (d ? 0 : 10) - h), a
}
function yi(t, e) {
null != e && (ki(t), t.curOp.scrollTop = (null == t.curOp.scrollTop ? t.doc.scrollTop : t.curOp.scrollTop) + e)
}
function wi(t) {
ki(t);
var e = t.getCursor(),
n = e,
i = e;
t.options.lineWrapping || (n = e.ch ? vt(e.line, e.ch - 1) : e, i = vt(e.line, e.ch + 1)), t.curOp.scrollToPos = {
from: n,
to: i,
margin: t.options.cursorScrollMargin
}
}
function Fi(t, e, n) {
null == e && null == n || ki(t), null != e && (t.curOp.scrollLeft = e), null != n && (t.curOp.scrollTop = n)
}
function ki(t) {
var e = t.curOp.scrollToPos;
if (e) {
t.curOp.scrollToPos = null;
xi(t, Hn(t, e.from), Hn(t, e.to), e.margin)
}
}
function xi(t, e, n, i) {
var r = bi(t, {
left: Math.min(e.left, n.left),
top: Math.min(e.top, n.top) - i,
right: Math.max(e.right, n.right),
bottom: Math.max(e.bottom, n.bottom) + i
});
Fi(t, r.scrollLeft, r.scrollTop)
}
function _i(t, e) {
Math.abs(t.doc.scrollTop - e) < 2 || (n || er(t, {
top: e
}), $i(t, e, !0), n && er(t), Vi(t, 100))
}
function $i(t, e, n) {
e = Math.min(t.display.scroller.scrollHeight - t.display.scroller.clientHeight, e), (t.display.scroller.scrollTop != e || n) && (t.doc.scrollTop = e, t.display.scrollbars.setScrollTop(e), t.display.scroller.scrollTop != e && (t.display.scroller.scrollTop = e))
}
function Ei(t, e, n, i) {
e = Math.min(e, t.display.scroller.scrollWidth - t.display.scroller.clientWidth), (n ? e == t.doc.scrollLeft : Math.abs(t.doc.scrollLeft - e) < 2) && !i || (t.doc.scrollLeft = e, pi(t), t.display.scroller.scrollLeft != e && (t.display.scroller.scrollLeft = e), t.display.scrollbars.setScrollLeft(e))
}
function Ci(t) {
var e = t.display,
n = e.gutters.offsetWidth,
i = Math.round(t.doc.height + kn(t.display));
return {
clientHeight: e.scroller.clientHeight,
viewHeight: e.wrapper.clientHeight,
scrollWidth: e.scroller.scrollWidth,
clientWidth: e.scroller.clientWidth,
viewWidth: e.wrapper.clientWidth,
barLeft: t.options.fixedGutter ? n : 0,
docHeight: i,
scrollHeight: i + _n(t) + e.barHeight,
nativeBarWidth: e.nativeBarWidth,
gutterWidth: n
}
}
var Ai = function(t, e, n) {
this.cm = n;
var i = this.vert = A("div", [A("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar"),
r = this.horiz = A("div", [A("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
t(i), t(r), ie(i, "scroll", function() {
i.clientHeight && e(i.scrollTop, "vertical")
}), ie(r, "scroll", function() {
r.clientWidth && e(r.scrollLeft, "horizontal")
}), this.checkedZeroWidth = !1, a && s < 8 && (this.horiz.style.minHeight = this.vert.style.minWidth = "18px")
};
Ai.prototype.update = function(t) {
var e = t.scrollWidth > t.clientWidth + 1,
n = t.scrollHeight > t.clientHeight + 1,
i = t.nativeBarWidth;
if (n) {
this.vert.style.display = "block", this.vert.style.bottom = e ? i + "px" : "0";
var r = t.viewHeight - (e ? i : 0);
this.vert.firstChild.style.height = Math.max(0, t.scrollHeight - t.clientHeight + r) + "px"
} else this.vert.style.display = "", this.vert.firstChild.style.height = "0";
if (e) {
this.horiz.style.display = "block", this.horiz.style.right = n ? i + "px" : "0", this.horiz.style.left = t.barLeft + "px";
var o = t.viewWidth - t.barLeft - (n ? i : 0);
this.horiz.firstChild.style.width = Math.max(0, t.scrollWidth - t.clientWidth + o) + "px"
} else this.horiz.style.display = "", this.horiz.firstChild.style.width = "0";
return !this.checkedZeroWidth && t.clientHeight > 0 && (0 == i && this.zeroWidthHack(), this.checkedZeroWidth = !0), {
right: n ? i : 0,
bottom: e ? i : 0
}
}, Ai.prototype.setScrollLeft = function(t) {
this.horiz.scrollLeft != t && (this.horiz.scrollLeft = t), this.disableHoriz && this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz")
}, Ai.prototype.setScrollTop = function(t) {
this.vert.scrollTop != t && (this.vert.scrollTop = t), this.disableVert && this.enableZeroWidthBar(this.vert, this.disableVert, "vert")
}, Ai.prototype.zeroWidthHack = function() {
var t = b && !d ? "12px" : "18px";
this.horiz.style.height = this.vert.style.width = t, this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none", this.disableHoriz = new j, this.disableVert = new j
}, Ai.prototype.enableZeroWidthBar = function(t, e, n) {
t.style.pointerEvents = "auto";
e.set(1e3, function i() {
var r = t.getBoundingClientRect();
("vert" == n ? document.elementFromPoint(r.right - 1, (r.top + r.bottom) / 2) : document.elementFromPoint((r.right + r.left) / 2, r.bottom - 1)) != t ? t.style.pointerEvents = "none" : e.set(1e3, i)
})
}, Ai.prototype.clear = function() {
var t = this.horiz.parentNode;
t.removeChild(this.horiz), t.removeChild(this.vert)
};
var Si = function() {};
Si.prototype.update = function() {
return {
bottom: 0,
right: 0
}
}, Si.prototype.setScrollLeft = function() {}, Si.prototype.setScrollTop = function() {}, Si.prototype.clear = function() {};
function Ti(t, e) {
e || (e = Ci(t));
var n = t.display.barWidth,
i = t.display.barHeight;
Mi(t, e);
for (var r = 0; r < 4 && n != t.display.barWidth || i != t.display.barHeight; r++) n != t.display.barWidth && t.options.lineWrapping && di(t), Mi(t, Ci(t)), n = t.display.barWidth, i = t.display.barHeight
}
function Mi(t, e) {
var n = t.display,
i = n.scrollbars.update(e);
n.sizer.style.paddingRight = (n.barWidth = i.right) + "px", n.sizer.style.paddingBottom = (n.barHeight = i.bottom) + "px", n.heightForcer.style.borderBottom = i.bottom + "px solid transparent", i.right && i.bottom ? (n.scrollbarFiller.style.display = "block", n.scrollbarFiller.style.height = i.bottom + "px", n.scrollbarFiller.style.width = i.right + "px") : n.scrollbarFiller.style.display = "", i.bottom && t.options.coverGutterNextToScrollbar && t.options.fixedGutter ? (n.gutterFiller.style.display = "block", n.gutterFiller.style.height = i.bottom + "px", n.gutterFiller.style.width = e.gutterWidth + "px") : n.gutterFiller.style.display = ""
}
var Di = {
native: Ai,
null: Si
};
function Li(t) {
t.display.scro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment