vue-cuihovah-ueditor
Version:
将ueditor添加了修改mathjax公式的功能,封装成了Vue组件
1,215 lines • 262 kB
JavaScript
/*!
* ====================================================
* Kity Formula Editor - v1.0.0 - 2014-09-03
* https://github.com/kitygraph/formula
* GitHub: https://github.com/kitygraph/formula.git
* Copyright (c) 2014 Baidu Kity Group; Licensed MIT
* ====================================================
*/
!
function() {
function a(a) {
b.r([c[a]])
}
var b = {
r: function(a) {
if (b[a].inited) return b[a].value;
if ("function" != typeof b[a].value) return b[a].inited = !0,
b[a].value;
var c = {
exports: {}
},
d = b[a].value(null, c.exports, c);
if (b[a].inited = !0, b[a].value = d, void 0 !== d) return d;
for (var e in c.exports) if (c.exports.hasOwnProperty(e)) return b[a].inited = !0,
b[a].value = c.exports,
c.exports
}
};
b[0] = {
value: function() {
function a(d, e, f, g) {
return g = 0 | g,
g > b ? f: (g++, c.each(f,
function(b, f) {
d ? !b || "object" != typeof b && "function" != typeof b ? e[f] = b: (e[f] = e[f] || (c.isArray(b) ? [] : {}), e[f] = a(d, e[f], b, g)) : e[f] = b
}), e)
}
var b = 10,
c = {
extend: function(b, d) {
var e = !1;
if ("boolean" == typeof b ? (e = b, b = d, d = [].splice.call(arguments, 2)) : d = [].splice.call(arguments, 1), !b) throw new Error("Utils: extend, target can not be empty");
return c.each(d,
function(c) { (c && "object" == typeof c || "function" == typeof c) && a(e, b, c)
}),
b
},
contains: function(a, b) {
return a.contains ? a.contains(b) : a.compareDocumentPosition ? !!(16 & a.compareDocumentPosition(b)) : void 0
},
getRect: function(a) {
return a.getBoundingClientRect()
},
isArray: function(a) {
return a && "[object Array]" === {}.toString.call(a)
},
isString: function(a) {
return "string" == typeof a
},
proxy: function(a, b) {
return function() {
return a.apply(b, arguments)
}
},
each: function(a, b) {
if (a) if ("length" in a && "number" == typeof a.length) for (var c = 0,
d = a.length; d > c && b.call(null, a[c], c, a) !== !1; c++);
else for (var e in a) if (a.hasOwnProperty(e) && b.call(null, a[e], e, a) === !1) break
}
};
return c
}
},
b[1] = {
value: function() {
var a = b.r(20);
return a.createClass("Component", {
constructor: function() {}
})
}
},
b[2] = {
value: function() {
function a() {
return++d
}
var c = {},
d = 0,
e = !0,
f = b.r(3),
g = b.r(0),
h = function(a) {
var b = a.type,
d = a.target,
f = this.__kfe_eid,
h = /^(?:before|after)/.test(b),
j = c[f][b];
return h || (i.trigger(d, "before" + b), e !== !1) ? (g.each(j,
function(b) {
return b && b.call(d, a) === !1 ? e = !1 : void 0
}), void(h || i.trigger(d, "after" + b))) : (e = !0, !1)
},
i = {
addEvent: function(b, d, e) {
var f = !0,
g = null;
b.__kfe_eid || (f = !1, b.__kfe_eid = a(), c[b.__kfe_eid] = {}),
g = c[b.__kfe_eid],
g[d] || (f = !1, g[d] = []),
g[d].push(e),
f || b.addEventListener(d, h, !1)
},
trigger: function(a, b, c) {
c = c || f.createEvent(b, c),
a.dispatchEvent(c)
}
};
return i
}
},
b[3] = {
value: function() {
return {
createEvent: function(a) {
var b = document.createEvent("Event");
return b.initEvent(a, !0, !0),
b
}
}
}
},
b[4] = {
value: function() {
var a = {},
c = b.r(0);
return c.extend(a, c, b.r(2)),
a
}
},
b[5] = {
value: function() {
var a = b.r(20),
c = b.r(8),
d = a.createClass("ControllerComponent", {
constructor: function(a) {
this.kfEditor = a,
this.components = {},
this.initComponents()
},
initComponents: function() {
this.components.listener = new c(this, this.kfEditor)
}
});
return d
}
},
b[6] = {
value: function() {
var a = {
32 : "\\,",
"s+219": "\\{",
"s+221": "\\}",
220 : "\\backslash",
"s+51": "\\#",
"s+52": "\\$",
"s+53": "\\%",
"s+54": "\\^",
"s+55": "\\&",
"s+189": "\\_",
"s+192": "\\~"
};
return {
getReplaceString: function(b) {
return a[b] || null
}
}
}
},
b[7] = {
value: function() {
var a = b.r(20),
c = b.r(4),
d = b.r(6),
e = {
LEFT: 37,
RIGHT: 39,
DELETE: 8,
INPUT: 229
};
return a.createClass("InputComponent", {
constructor: function(a, b) {
this.parentComponent = a,
this.kfEditor = b,
this.inputBox = this.createInputBox(),
this.initServices(),
this.initCommands(),
this.initEvent()
},
initServices: function() {
this.kfEditor.registerService("control.update.input", this, {
updateInput: this.updateInput
}),
this.kfEditor.registerService("control.insert.string", this, {
insertStr: this.insertStr
})
},
initCommands: function() {
this.kfEditor.registerCommand("focus", this, this.focus)
},
createInputBox: function() {
var a = this.kfEditor.getContainer(),
b = this.kfEditor.getDocument().createElement("input");
return b.className = "kf-editor-input-box",
b.type = "text",
b.isTrusted = !1,
a.appendChild(b),
b
},
focus: function() {
var a = null;
this.inputBox.focus(),
this.kfEditor.requestService("syntax.has.cursor.info") || (a = this.kfEditor.requestService("syntax.get.root.group.info"), this.kfEditor.requestService("syntax.update.record.cursor", {
groupId: a.id,
startOffset: 0,
endOffset: a.content.length
}), this.kfEditor.requestService("control.update.input")),
this.kfEditor.requestService("control.reselect")
},
setUntrusted: function() {
this.inputBox.isTrusted = !1
},
setTrusted: function() {
this.inputBox.isTrusted = !0
},
updateInput: function() {
var a = this.kfEditor.requestService("syntax.serialization");
this.setUntrusted(),
this.inputBox.value = a.str,
this.inputBox.selectionStart = a.startOffset,
this.inputBox.selectionEnd = a.endOffset,
this.inputBox.focus(),
this.setTrusted()
},
insertStr: function(a) {
var b = this.kfEditor.requestService("syntax.serialization"),
c = b.str;
c = c.substring(0, b.startOffset) + " " + a + " " + c.substring(b.endOffset),
this.restruct(c),
this.updateInput(),
this.kfEditor.requestService("ui.update.canvas.view")
},
initEvent: function() {
var a = this;
c.addEvent(this.inputBox, "keydown",
function(b) {
var c = !1;
if (b.ctrlKey) return void a.processUserCtrl(b);
switch (b.keyCode) {
case e.INPUT:
return;
case e.LEFT:
b.preventDefault(),
a.leftMove(),
c = !0;
break;
case e.RIGHT:
b.preventDefault(),
a.rightMove(),
c = !0;
break;
case e.DELETE:
b.preventDefault(),
a.delete(),
c = !0
}
c && a.kfEditor.requestService("ui.update.canvas.view"),
a.pretreatmentInput(b) || b.preventDefault()
}),
c.addEvent(this.inputBox, "input",
function() {
a.processingInput()
}),
c.addEvent(this.inputBox, "blur",
function() {
a.kfEditor.requestService("ui.toolbar.disable"),
a.kfEditor.requestService("ui.toolbar.close"),
a.kfEditor.requestService("control.cursor.hide"),
a.kfEditor.requestService("render.clear.select")
}),
c.addEvent(this.inputBox, "focus",
function() {
a.kfEditor.requestService("ui.toolbar.enable"),
this.isTrusted && a.kfEditor.requestService("control.reselect")
}),
c.addEvent(this.inputBox, "paste",
function(a) {
a.preventDefault()
})
},
hasRootplaceholder: function() {
return this.kfEditor.requestService("syntax.has.root.placeholder")
},
leftMove: function() {
this.hasRootplaceholder() || (this.kfEditor.requestService("syntax.cursor.move.left"), this.update())
},
rightMove: function() {
this.hasRootplaceholder() || (this.kfEditor.requestService("syntax.cursor.move.right"), this.update())
},
"delete": function() {
var a = null;
this.hasRootplaceholder() || (a = this.kfEditor.requestService("syntax.delete.group"), a ? (this.updateInput(), this.processingInput()) : (this.updateInput(), this.kfEditor.requestService("control.reselect")))
},
processUserCtrl: function(a) {
switch (a.preventDefault(), a.keyCode) {
case 65:
this.kfEditor.requestService("control.select.all");
break;
case 83:
this.kfEditor.requestService("print.image")
}
},
pretreatmentInput: function(a) {
var b = this.getKeyCode(a),
c = d.getReplaceString(b);
return null === c ? !0 : (this.insertStr(c), !1)
},
getKeyCode: function(a) {
return (a.shiftKey ? "s+": "") + a.keyCode
},
processingInput: function() {
this.restruct(this.inputBox.value),
this.kfEditor.requestService("ui.update.canvas.view")
},
restruct: function(a) {
this.kfEditor.requestService("render.draw", a),
this.kfEditor.requestService("control.reselect")
},
update: function() {
this.updateInput(),
this.kfEditor.requestService("control.reselect")
}
})
}
},
b[8] = {
value: function() {
var a = b.r(20),
c = b.r(9),
d = b.r(7),
e = b.r(10);
return a.createClass("MoveComponent", {
constructor: function(a, b) {
this.parentComponent = a,
this.kfEditor = b,
this.components = {},
this.initComponents()
},
initComponents: function() {
this.components.location = new c(this, this.kfEditor),
this.components.selection = new e(this, this.kfEditor),
this.components.input = new d(this, this.kfEditor)
}
})
}
},
b[9] = {
value: function() {
function a(a) {
return a.getBoundingClientRect()
}
var c = b.r(20);
return c.createClass("LocationComponent", {
constructor: function(a, b) {
this.parentComponent = a,
this.kfEditor = b,
this.paper = this.getPaper(),
this.cursorShape = this.createCursor(),
this.initServices(),
this.initEvent()
},
getPaper: function() {
return this.kfEditor.requestService("render.get.paper")
},
initServices: function() {
this.kfEditor.registerService("control.cursor.relocation", this, {
relocationCursor: this.updateCursor
}),
this.kfEditor.registerService("control.cursor.hide", this, {
hideCursor: this.hideCursor
}),
this.kfEditor.registerService("control.reselect", this, {
reselect: this.reselect
}),
this.kfEditor.registerService("control.get.cursor.location", this, {
getCursorLocation: this.getCursorLocation
})
},
createCursor: function() {
var a = new c.Rect(1, 0, 0, 0).fill("black");
return a.setAttr("style", "display: none"),
this.paper.addShape(a),
a
},
initEvent: function() {
var a = this.kfEditor.request("ui.canvas.container.event"),
b = this;
a.on("mousedown",
function(a) {
a.preventDefault(),
b.updateCursorInfo(a),
b.kfEditor.requestService("control.update.input"),
b.reselect()
})
},
updateCursorInfo: function(a) {
var b = null,
c = null,
d = -1;
return this.kfEditor.requestService("syntax.has.root.placeholder") ? (this.kfEditor.requestService("syntax.update.record.cursor", {
groupId: this.kfEditor.requestService("syntax.get.root.group.info").id,
startOffset: 0,
endOffset: 1
}), !1) : (b = this.kfEditor.requestService("position.get.wrap", a.target), b && this.kfEditor.requestService("syntax.is.placeholder.node", b.id) ? (c = this.kfEditor.requestService("position.get.group.info", b), void this.kfEditor.requestService("syntax.update.record.cursor", c.group.id, c.index, c.index + 1)) : (c = this.kfEditor.requestService("position.get.group", a.target), null === c && (c = this.kfEditor.requestService("syntax.get.root.group.info")), d = this.getIndex(a.clientX, c), void this.kfEditor.requestService("syntax.update.record.cursor", c.id, d)))
},
hideCursor: function() {
this.cursorShape.setAttr("style", "display: none")
},
reselect: function() {
var a = this.kfEditor.requestService("syntax.get.record.cursor"),
b = null;
return this.hideCursor(),
this.kfEditor.requestService("syntax.is.select.placeholder") ? (b = this.kfEditor.requestService("syntax.get.group.content", a.groupId), void this.kfEditor.requestService("render.select.group", b.content[a.startOffset].id)) : void(a.startOffset === a.endOffset ? (this.updateCursor(), this.kfEditor.requestService("render.tint.current.cursor")) : this.kfEditor.requestService("render.select.current.cursor"))
},
updateCursor: function() {
var b = this.kfEditor.requestService("syntax.get.record.cursor");
if (b.startOffset !== b.endOffset) return void this.hideCursor();
var c = this.kfEditor.requestService("syntax.get.group.content", b.groupId),
d = 0 === b.endOffset,
e = d ? 0 : b.endOffset - 1,
f = c.content[e],
g = a(this.paper.container.node),
h = 0,
i = a(f),
j = this.cursorShape.getTransform(this.cursorShape),
k = this.kfEditor.requestService("render.get.canvas.zoom"),
l = this.paper.getZoom();
this.cursorShape.setHeight(i.height / k / l),
h = d ? i.left - 2 : i.left + i.width - 2,
h -= g.left,
j.m.e = Math.floor(h / k / l) + .5,
j.m.f = (i.top - g.top) / k / l,
this.cursorShape.setMatrix(j),
this.cursorShape.setAttr("style", "display: block")
},
getCursorLocation: function() {
var a = this.cursorShape.getRenderBox("paper");
return {
x: a.x,
y: a.y
}
},
getIndex: function(b, c) {
for (var d = -1,
e = c.content,
f = null,
g = e.length - 1,
h = null; g >= 0; g--) if (d = g, h = e[g], f = a(h), f.left < b) {
f.left + f.width / 2 < b && (d += 1);
break
}
return d
}
})
}
},
b[10] = {
value: function() {
var a = b.r(20),
c = b.r(4),
d = 10;
return a.createClass("SelectionComponent", {
constructor: function(a, b) {
this.parentComponent = a,
this.kfEditor = b,
this.isDrag = !1,
this.isMousedown = !1,
this.startPoint = {
x: -1,
y: -1
},
this.startGroupIsPlaceholder = !1,
this.startGroup = {},
this.initServices(),
this.initEvent()
},
initServices: function() {
this.kfEditor.registerService("control.select.all", this, {
selectAll: this.selectAll
})
},
initEvent: function() {
var a = this.kfEditor.request("ui.canvas.container.event"),
b = this;
a.on("mousedown",
function(a) {
return a.preventDefault(),
b.kfEditor.requestService("syntax.has.root.placeholder") ? !1 : (b.isMousedown = !0, b.updateStartPoint(a.clientX, a.clientY), void b.updateStartGroup())
}),
a.on("mouseup",
function(a) {
a.preventDefault(),
b.stopUpdateSelection()
}),
a.on("mousemove",
function(a) {
if (a.preventDefault(), b.isDrag) {
if (1 !== a.which) return void b.stopUpdateSelection();
b.updateSelection(a.target, a.clientX, a.clientY)
} else b.isMousedown && d < b.getDistance(a.clientX, a.clientY) && (b.kfEditor.requestService("control.cursor.hide"), b.startUpdateSelection())
}),
a.on("dblclick",
function(a) {
b.updateSelectionByTarget(a.target)
})
},
getDistance: function(a, b) {
var c = Math.abs(a - this.startPoint.x),
d = Math.abs(b - this.startPoint.y);
return Math.max(c, d)
},
updateStartPoint: function(a, b) {
this.startPoint.x = a,
this.startPoint.y = b
},
updateStartGroup: function() {
var a = this.kfEditor.requestService("syntax.get.record.cursor");
this.startGroupIsPlaceholder = this.kfEditor.requestService("syntax.is.select.placeholder"),
this.startGroup = {
groupInfo: this.kfEditor.requestService("syntax.get.group.content", a.groupId),
offset: a.startOffset
}
},
startUpdateSelection: function() {
this.isDrag = !0,
this.isMousedown = !1,
this.clearSelection()
},
stopUpdateSelection: function() {
this.isDrag = !1,
this.isMousedown = !1,
this.kfEditor.requestService("control.update.input")
},
clearSelection: function() {
this.kfEditor.requestService("render.clear.select")
},
updateSelection: function(a, b) {
var d = b > this.startPoint.x,
e = {},
f = null,
g = !1,
h = this.startGroup,
i = null,
j = this.getGroupInof(b, a);
j.groupInfo.id === h.groupInfo.id ? (e = {
groupId: j.groupInfo.id,
startOffset: h.offset,
endOffset: j.offset
},
this.startGroupIsPlaceholder && (d ? e.startOffset === e.endOffset && (e.endOffset += 1) : e.startOffset += 1)) : c.contains(h.groupInfo.groupObj, j.groupInfo.groupObj) ? e = {
groupId: h.groupInfo.id,
startOffset: h.offset,
endOffset: this.getIndex(h.groupInfo.groupObj, a, b)
}: c.contains(j.groupInfo.groupObj, h.groupInfo.groupObj) ? (e = {
groupId: j.groupInfo.id,
startOffset: this.kfEditor.requestService("position.get.index", j.groupInfo.groupObj, h.groupInfo.groupObj),
endOffset: j.offset
},
d || (e.startOffset += 1)) : (f = this.getCommunityGroup(h.groupInfo, j.groupInfo), f.startOffset === f.endOffset ? f.endOffset += 1 : (i = f.group.content[f.endOffset], g = this.kfEditor.requestService("position.get.area", i, b), g && (f.endOffset += 1), d || (f.startOffset += 1)), e = {
groupId: f.group.id,
startOffset: f.startOffset,
endOffset: f.endOffset
}),
this.kfEditor.requestService("syntax.update.record.cursor", e.groupId, e.startOffset, e.endOffset),
this.kfEditor.requestService("control.reselect")
},
updateSelectionByTarget: function(a) {
var b = this.kfEditor.requestService("position.get.parent.group", a),
c = null,
d = {};
if (null !== b) {
if (this.kfEditor.requestService("syntax.is.root.node", b.id)) return void this.selectAll();
this.kfEditor.requestService("syntax.is.virtual.node", b.id) ? (c = this.kfEditor.requestService("position.get.group.info", b.groupObj), d = {
groupId: c.group.id,
startOffset: c.index,
endOffset: c.index + 1
}) : d = {
groupId: b.id,
startOffset: 0,
endOffset: b.content.length
},
this.kfEditor.requestService("syntax.update.record.cursor", d),
this.kfEditor.requestService("control.reselect"),
this.kfEditor.requestService("control.update.input")
}
},
selectAll: function() {
var a = this.kfEditor.requestService("syntax.get.root.group.info"),
b = {
groupId: a.id,
startOffset: 0,
endOffset: a.content.length
};
this.kfEditor.requestService("syntax.update.record.cursor", b),
this.kfEditor.requestService("control.reselect"),
this.kfEditor.requestService("control.update.input")
},
getGroupInof: function(a, b) {
var c = this.kfEditor.requestService("position.get.group", b);
null === c && (c = this.kfEditor.requestService("syntax.get.root.group.info"));
var d = this.kfEditor.requestService("position.get.location.info", a, c);
return {
groupInfo: c,
offset: d
}
},
getIndex: function(a, b, d) {
var e = this.kfEditor.requestService("position.get.index", a, b),
f = this.kfEditor.requestService("syntax.get.group.content", a.id),
g = f.content[e],
h = c.getRect(g);
return h.left + h.width / 2 < d && (e += 1),
e
},
getCommunityGroup: function(a, b) {
for (var d = null,
e = a.groupObj,
f = null; (d = this.kfEditor.requestService("position.get.group.info", e)) && (e = d.group.groupObj, !c.contains(d.group.groupObj, b.groupObj)););
return f = d.group.groupObj,
{
group: d.group,
startOffset: d.index,
endOffset: this.kfEditor.requestService("position.get.index", f, b.groupObj)
}
}
})
}
},
b[11] = {
value: function() {
return {
GROUP: "kf-editor-group",
VIRTUAL: "kf-editor-virtual-group"
}
}
},
b[12] = {
value: function() {
function a(a) {
var b = this.services[a];
if (!b) throw new Error("KFEditor: not found service, " + a);
return b
}
var c = b.r(20),
d = b.r(4),
e = {
formula: {
fontsize: 50,
autoresize: !1
},
ui: {
zoom: !0,
maxzoom: 2,
minzoom: 1
}
},
f = {},
g = b.r(19).ResourceManager,
h = c.createClass("KFEditor", {
constructor: function(a, b) {
this.options = d.extend(!0, {},
e, b),
this.FormulaClass = null,
this._readyState = !1,
this._callbacks = [],
this.container = a,
this.services = {},
this.commands = {},
this.initResource()
},
isReady: function() {
return !! this._readyState
},
triggerReady: function() {
for (var a = null,
b = this; a = this._callbacks.shift();) a.call(b, b)
},
ready: function(a) {
this._readyState ? a.call(this, this) : this._callbacks.push(a)
},
getContainer: function() {
return this.container
},
getDocument: function() {
return this.container.ownerDocument
},
getFormulaClass: function() {
return this.FormulaClass
},
getOptions: function() {
return this.options
},
initResource: function() {
var a = this;
g.ready(function(b) {
a.FormulaClass = b,
a.initComponents(),
a._readyState = !0,
a.triggerReady()
},
this.options.resource)
},
initComponents: function() {
var a = this;
d.each(f,
function(b, c) {
new b(a, a.options[c])
})
},
requestService: function(b) {
var c = a.call(this, b);
return c.service[c.key].apply(c.provider, [].slice.call(arguments, 1))
},
request: function(b) {
var c = a.call(this, b);
return c.service
},
registerService: function(a, b, c) {
var e = null;
for (e in c) c[e] && c.hasOwnProperty(e) && (c[e] = d.proxy(c[e], b));
this.services[a] = {
provider: b,
key: e,
service: c
}
},
registerCommand: function(a, b, c) {
this.commands[a] = {
executor: b,
execFn: c
}
},
execCommand: function(a) {
var b = this.commands[a];
if (!b) throw new Error("KFEditor: not found command, " + a);
return b.execFn.apply(b.executor, [].slice.call(arguments, 1))
}
});
return d.extend(h, {
registerComponents: function(a, b) {
f[a] = b
}
}),
h
}
},
b[13] = {
value: function() {
function a(a, b) {
var c = this;
this._callbacks = [],
this.editor = new d(a, b),
this.editor.ready(function() {
c._trigger()
})
}
var c = b.r(20),
d = b.r(12);
return a.prototype._trigger = function() {
var a = this.editor;
c.Utils.each(this._callbacks,
function(b) {
b.call(a, a)
})
},
a.prototype.ready = function(a) {
this.editor.isReady() ? a.call(this.editor, this.editor) : this._callbacks.push(a)
},
{
create: function(b, c) {
return new a(b, c)
}
}
}
},
b[14] = {
value: function() {
return window.jQuery
}
},
b[15] = {
value: function() {
return {
selectColor: "rgba(42, 106, 189, 0.2)",
allSelectColor: "rgba(42, 106, 189, 0.6)"
}
}
},
b[16] = {
value: function() {
var a = b.r(20),
c = b.r(19),
d = b.r(18);
return a.createClass("PlaceholderExpression", {
base: c.CompoundExpression,
constructor: function() {
this.callBase(),
this.setFlag("Placeholder"),
this.label = null,
this.box.setAttr("data-type", null),
this.setOperator(new d)
},
setLabel: function(a) {
this.label = a
},
getLabel: function() {
return this.label
},
setAttr: function(a, b) {
"label" === a ? this.setLabel(b) : (a.label && (this.setLabel(a.label), delete a.label), this.callBase(a, b))
},
select: function() {
this.getOperator().select()
},
selectAll: function() {
this.getOperator().selectAll()
},
unselect: function() {
this.getOperator().unselect()
}
})
}
},
b[17] = {
value: function() {
function a(a) {
c.PlaceholderExpression = b.r(16),
c.Expression.prototype.select = function() {
this.box.fill(d)
},
c.Expression.prototype.selectAll = function() {
this.box.fill(e)
},
c.Expression.prototype.unselect = function() {
this.box.fill("transparent")
},
a.getKFParser().expand({
parse: {
placeholder: {
name: "placeholder",
handler: function(a) {
return delete a.handler,
a.operand = [],
a
},
sign: !1
}
},
reverse: {
placeholder: function() {
return "\\placeholder "
}
}
})
}
var c = b.r(19),
d = b.r(15).selectColor,
e = b.r(15).allSelectColor;
return {
ext: a
}
}
},
b[18] = {
value: function() {
function a(a, b) {
return null !== b ? d(a, b) : c(a)
}
function c(a) {
var b = 35,
c = 50,
d = null;
return d = new e.Rect(b, c, 0, 0).stroke("black").fill("transparent"),
d.setAttr("stroke-dasharray", "5, 5"),
a.addOperatorShape(d),
d
}
function d(a, b) {
var c = new e.Text(b).fill(f),
d = new e.Group,
//g = 20,
g = 2,
h = 7,
i = new e.Rect(0, 0, 0, 0, h).stroke(f).fill("transparent"),
j = null;
return c.setFontSize(40),
d.addShape(i),
d.addShape(c),
a.addOperatorShape(d),
j = c.getFixRenderBox(),
i.stroke(f).fill("transparent"),
i.setSize(j.width + 2 * g, j.height + 2 * g),
i.setRadius(h),
i.setAttr("stroke-dasharray", "5, 5"),
c.setAttr({
dx: 0 - j.x,
dy: 0 - j.y
}),
c.translate(g, g),
i
}
var e = b.r(20),
f = b.r(29).rootPlaceholder.color,
g = b.r(15).selectColor,
h = b.r(15).allSelectColor;
return e.createClass("PlaceholderOperator", {
base: b.r(19).Operator,
constructor: function() {
this.opShape = null,
this.callBase("Placeholder")
},
applyOperand: function() {
this.opShape = a(this, this.parentExpression.getLabel()),
this.parentExpression.expand(20, 20),
this.parentExpression.translateElement(10, 10)
},
select: function() {
this.opShape.fill(g)
},
selectAll: function() {
this.opShape.fill(h)
},
unselect: function() {
this.opShape.fill("transparent")
}
})
}
},
b[19] = {
value: function() {
return window.kf
}
},
b[20] = {
value: function() {
return window.kity
}
},
b[21] = {
value: function() {
function a(a, b, c) {
var i = null,
j = !c;
b.attr = b.attr || {},
b.attr.id = a.getGroupId(),
j ? d(a, b) : c.attr["data-root"] && "placeholder" === b.name && g(c.operand) && (b.attr.label = o);
for (var k = 0,
l = b.operand.length; l > k; k++) i = b.operand[k],
h(b) ? e(a, k, b, i) : f(a, k, b, i);
return b
}
function c() {
return q + ++s
}
function d(a, b) {
a.isResetId ? b.attr["data-root"] = "true": b.attr["data-type"] = r.VIRTUAL
}
function e(b, c, d, e) {
"brackets" === d.name && 2 > c || ("function" !== d.name || 0 !== c) && (d.attr["data-type"] = r.VIRTUAL, e ? "string" == typeof e ? (d.operand[c] = j(b), d.operand[c].operand[0] = e) : i(e) ? (d.operand[c] = j(b), d.operand[c].operand[0] = a(b, e, d.operand[c])) : d.operand[c] = a(b, e, d) : d.operand[c] = e)
}
function f(b, c, d, e) {
d.attr["data-type"] = r.GROUP,
d.operand[c] = e && "string" != typeof e ? "text" === e.name ? e: a(b, e, d) : e
}
function g(a) {
var b = 1;
if (a.length > 3) return ! 1;
for (var c = 0,
d = a.length; d > c; c++) a[c] !== m && a[c] && "placeholder" === a[c].name && b--;
return ! b
}
function h(a) {
return !! n[a.name]
}
function i(a) {
return "placeholder" === a.name
}
function j(a) {
return {
name: p,
attr: {
"data-type": r.GROUP,
id: a.getGroupId()
},
operand: []
}
}
var k = b.r(19).Parser,
l = b.r(20),
m = b.r(29).cursorCharacter,
n = b.r(22),
o = b.r(29).rootPlaceholder.content,
p = "combination",
q = "_kf_editor_",
r = b.r(11),
s = 0,
t = l.createClass("Parser", {
constructor: function(a) {
this.kfEditor = a,
this.callBase(),
this.kfParser = k.use("latex"),
this.initKFormulExtension(),
this.pid = c(),
this.groupRecord = 0,
this.tree = null,
this.isResetId = !0,
this.initServices()
},
parse: function(b, c) {
var d = null;
return this.isResetId = !!c,
this.isResetId && this.resetGroupId(),
d = this.kfParser.parse(b),
a(this, d.tree),
d
},
serialization: function(a) {
return this.kfParser.serialization(a)
},
initServices: function() {
this.kfEditor.registerService("parser.parse", this, {
parse: this.parse
}),
this.kfEditor.registerService("parser.latex.serialization", this, {
serialization: this.serialization
})
},
getKFParser: function() {
return this.kfParser
},
initKFormulExtension: function() {
b.r(17).ext(this)
},
resetGroupId: function() {
this.groupRecord = 0
},
getGroupId: function() {
return this.pid + "_" + ++this.groupRecord
}
});
return t
}
},
b[22] = {
value: function() {
return {
radical: !0,
fraction: !0,
summation: !0,
integration: !0,
placeholder: !0,
script: !0,
superscript: !0,
subscript: !0,
brackets: !0,
"function": !0,
// added by michael
stackrel: !0,
underline: !0,
overline: !0,
widehat: !0,
underbrace: !0
}
}
},
b[23] = {
value: function() {
function a(b, c, d) {
var e = null;
return b.ownerSVGElement ? (b = b.parentNode, e = b.tagName.toLowerCase(), b && "body" !== e && "svg" !== e ? "kf-editor-group" === b.getAttribute("data-type") ? b: c && "kf-editor-virtual-group" === b.getAttribute("data-type") ? b: d && null !== b.getAttribute("data-flag") ? b: a(b, c, d) : null) : null
}
var c = b.r(20),
d = b.r(4),
e = c.createClass("PositionComponenet", {
constructor: function(a) {
this.kfEditor = a,
this.initServices()
},
initServices: function() {
this.kfEditor.registerService("position.get.group", this, {
getGroupByTarget: this.getGroupByTarget
}),
this.kfEditor.registerService("position.get.index", this, {
getIndexByTargetInGroup: this.getIndexByTargetInGroup
}),
this.kfEditor.registerService("position.get.location.info", this, {
getLocationInfo: this.getLocationInfo
}),
this.kfEditor.registerService("position.get.parent.group", this, {
getParentGroupByTarget: this.getParentGroupByTarget
}),
this.kfEditor.registerService("position.get.wrap", this, {
getWrap: this.getWrap
}),
this.kfEditor.registerService("position.get.area", this, {
getAreaByCursorInGroup: this.getAreaByCursorInGroup
}),
this.kfEditor.registerService("position.get.group.info", this, {
getGroupInfoByNode: this.getGroupInfoByNode
}),
this.kfEditor.registerService("position.get.parent.info", this, {
getParentInfoByNode: this.getParentInfoByNode
})
},
getGroupByTarget: function(b) {
var c = a(b, !1, !1);
return c ? this.kfEditor.requestService("syntax.get.group.content", c.id) : null
},
getIndexByTargetInGroup: function(a, b) {
var e = this.kfEditor.requestService("syntax.get.group.content", a.id),
f = -1;
return c.Utils.each(e.content,
function(a, c) {
return f = c,
d.contains(a, b) ? !1 : void 0
}),
f
},
getAreaByCursorInGroup: function(a, b) {
var c = d.getRect(a);
return c.left + c.width / 2 < b
},
getLocationInfo: function(a, b) {
for (var c = -1,
e = b.content,
f = null,
g = e.length - 1,
h = null; g >= 0; g--) if (c = g, h = e[g], f = d.getRect(h), f.left < a) {
f.left + f.width / 2 < a && (c += 1);
break
}
return c
},
getParentGroupByTarget: function(b) {
var c = a(b, !0, !1);
return c ? this.kfEditor.requestService("syntax.get.group.content", c.id) : null
},
getWrap: function(b) {
return a(b, !0, !0)
},
getGroupInfoByNode: function(b) {
var c = {},
e = a(b, !1, !1),
f = null;
if (!e) return null;
f = this.kfEditor.requestService("syntax.get.group.content", e.id);
for (var g = 0,
h = f.content.length; h > g && (c.index = g, !d.contains(f.content[g], b)); g++);
return c.group = f,
c
},
getParentInfoByNode: function(b) {
var c = a(b, !0, !1);
return c = this.kfEditor.requestService("syntax.get.group.content", c.id),
{
group: c,
index: c.content.indexOf(b)
}
}
});
return e
}
},
b[24] = {
value: function() {
var a = b.r(20);
return a.createClass("Printer", {
constructor: function(a) {
this.kfEditor = a,
this.initServices(),
this.initCommands()
},
initServices: function() {
this.kfEditor.registerService("print.image", this, {
printImage: this.printImage
})
},
initCommands: function() {
this.kfEditor.registerCommand("get.image.data", this, this.getImageData)
},
printImage: function() {
var a = this.kfEditor.requestService("render.get.paper");
this._formatCanvas(),
a.toPNG(function(a) {
document.body.innerHTML = '<img style="background: red;" src="' + a + '">'
}),
this._restoreCanvas()
},
getImageData: function(a) {
var b = this.kfEditor.requestService("render.get.canvas"),
c = this.kfEditor.requestService("render.get.paper");
this._formatCanvas(),
c.toPNG(function(c) {
a({
width: b.width,
height: b.hei