2158 lines
220 KiB
JavaScript
2158 lines
220 KiB
JavaScript
|
"no use strict";
|
|||
|
;(function(window) {
|
|||
|
if (typeof window.window != "undefined" && window.document)
|
|||
|
return;
|
|||
|
if (window.require && window.define)
|
|||
|
return;
|
|||
|
|
|||
|
if (!window.console) {
|
|||
|
window.console = function() {
|
|||
|
var msgs = Array.prototype.slice.call(arguments, 0);
|
|||
|
postMessage({type: "log", data: msgs});
|
|||
|
};
|
|||
|
window.console.error =
|
|||
|
window.console.warn =
|
|||
|
window.console.log =
|
|||
|
window.console.trace = window.console;
|
|||
|
}
|
|||
|
window.window = window;
|
|||
|
window.ace = window;
|
|||
|
|
|||
|
window.onerror = function(message, file, line, col, err) {
|
|||
|
postMessage({type: "error", data: {
|
|||
|
message: message,
|
|||
|
data: err.data,
|
|||
|
file: file,
|
|||
|
line: line,
|
|||
|
col: col,
|
|||
|
stack: err.stack
|
|||
|
}});
|
|||
|
};
|
|||
|
|
|||
|
window.normalizeModule = function(parentId, moduleName) {
|
|||
|
// normalize plugin requires
|
|||
|
if (moduleName.indexOf("!") !== -1) {
|
|||
|
var chunks = moduleName.split("!");
|
|||
|
return window.normalizeModule(parentId, chunks[0]) + "!" + window.normalizeModule(parentId, chunks[1]);
|
|||
|
}
|
|||
|
// normalize relative requires
|
|||
|
if (moduleName.charAt(0) == ".") {
|
|||
|
var base = parentId.split("/").slice(0, -1).join("/");
|
|||
|
moduleName = (base ? base + "/" : "") + moduleName;
|
|||
|
|
|||
|
while (moduleName.indexOf(".") !== -1 && previous != moduleName) {
|
|||
|
var previous = moduleName;
|
|||
|
moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return moduleName;
|
|||
|
};
|
|||
|
|
|||
|
window.require = function require(parentId, id) {
|
|||
|
if (!id) {
|
|||
|
id = parentId;
|
|||
|
parentId = null;
|
|||
|
}
|
|||
|
if (!id.charAt)
|
|||
|
throw new Error("worker.js require() accepts only (parentId, id) as arguments");
|
|||
|
|
|||
|
id = window.normalizeModule(parentId, id);
|
|||
|
|
|||
|
var module = window.require.modules[id];
|
|||
|
if (module) {
|
|||
|
if (!module.initialized) {
|
|||
|
module.initialized = true;
|
|||
|
module.exports = module.factory().exports;
|
|||
|
}
|
|||
|
return module.exports;
|
|||
|
}
|
|||
|
|
|||
|
if (!window.require.tlns)
|
|||
|
return console.log("unable to load " + id);
|
|||
|
|
|||
|
var path = resolveModuleId(id, window.require.tlns);
|
|||
|
if (path.slice(-3) != ".js") path += ".js";
|
|||
|
|
|||
|
window.require.id = id;
|
|||
|
window.require.modules[id] = {}; // prevent infinite loop on broken modules
|
|||
|
importScripts(path);
|
|||
|
return window.require(parentId, id);
|
|||
|
};
|
|||
|
function resolveModuleId(id, paths) {
|
|||
|
var testPath = id, tail = "";
|
|||
|
while (testPath) {
|
|||
|
var alias = paths[testPath];
|
|||
|
if (typeof alias == "string") {
|
|||
|
return alias + tail;
|
|||
|
} else if (alias) {
|
|||
|
return alias.location.replace(/\/*$/, "/") + (tail || alias.main || alias.name);
|
|||
|
} else if (alias === false) {
|
|||
|
return "";
|
|||
|
}
|
|||
|
var i = testPath.lastIndexOf("/");
|
|||
|
if (i === -1) break;
|
|||
|
tail = testPath.substr(i) + tail;
|
|||
|
testPath = testPath.slice(0, i);
|
|||
|
}
|
|||
|
return id;
|
|||
|
}
|
|||
|
window.require.modules = {};
|
|||
|
window.require.tlns = {};
|
|||
|
|
|||
|
window.define = function(id, deps, factory) {
|
|||
|
if (arguments.length == 2) {
|
|||
|
factory = deps;
|
|||
|
if (typeof id != "string") {
|
|||
|
deps = id;
|
|||
|
id = window.require.id;
|
|||
|
}
|
|||
|
} else if (arguments.length == 1) {
|
|||
|
factory = id;
|
|||
|
deps = [];
|
|||
|
id = window.require.id;
|
|||
|
}
|
|||
|
|
|||
|
if (typeof factory != "function") {
|
|||
|
window.require.modules[id] = {
|
|||
|
exports: factory,
|
|||
|
initialized: true
|
|||
|
};
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (!deps.length)
|
|||
|
// If there is no dependencies, we inject "require", "exports" and
|
|||
|
// "module" as dependencies, to provide CommonJS compatibility.
|
|||
|
deps = ["require", "exports", "module"];
|
|||
|
|
|||
|
var req = function(childId) {
|
|||
|
return window.require(id, childId);
|
|||
|
};
|
|||
|
|
|||
|
window.require.modules[id] = {
|
|||
|
exports: {},
|
|||
|
factory: function() {
|
|||
|
var module = this;
|
|||
|
var returnExports = factory.apply(this, deps.map(function(dep) {
|
|||
|
switch (dep) {
|
|||
|
// Because "require", "exports" and "module" aren't actual
|
|||
|
// dependencies, we must handle them seperately.
|
|||
|
case "require": return req;
|
|||
|
case "exports": return module.exports;
|
|||
|
case "module": return module;
|
|||
|
// But for all other dependencies, we can just go ahead and
|
|||
|
// require them.
|
|||
|
default: return req(dep);
|
|||
|
}
|
|||
|
}));
|
|||
|
if (returnExports)
|
|||
|
module.exports = returnExports;
|
|||
|
return module;
|
|||
|
}
|
|||
|
};
|
|||
|
};
|
|||
|
window.define.amd = {};
|
|||
|
require.tlns = {};
|
|||
|
window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
|
|||
|
for (var i in topLevelNamespaces)
|
|||
|
require.tlns[i] = topLevelNamespaces[i];
|
|||
|
};
|
|||
|
|
|||
|
window.initSender = function initSender() {
|
|||
|
|
|||
|
var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter;
|
|||
|
var oop = window.require("ace/lib/oop");
|
|||
|
|
|||
|
var Sender = function() {};
|
|||
|
|
|||
|
(function() {
|
|||
|
|
|||
|
oop.implement(this, EventEmitter);
|
|||
|
|
|||
|
this.callback = function(data, callbackId) {
|
|||
|
postMessage({
|
|||
|
type: "call",
|
|||
|
id: callbackId,
|
|||
|
data: data
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
this.emit = function(name, data) {
|
|||
|
postMessage({
|
|||
|
type: "event",
|
|||
|
name: name,
|
|||
|
data: data
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
}).call(Sender.prototype);
|
|||
|
|
|||
|
return new Sender();
|
|||
|
};
|
|||
|
|
|||
|
var main = window.main = null;
|
|||
|
var sender = window.sender = null;
|
|||
|
|
|||
|
window.onmessage = function(e) {
|
|||
|
var msg = e.data;
|
|||
|
if (msg.event && sender) {
|
|||
|
sender._signal(msg.event, msg.data);
|
|||
|
}
|
|||
|
else if (msg.command) {
|
|||
|
if (main[msg.command])
|
|||
|
main[msg.command].apply(main, msg.args);
|
|||
|
else if (window[msg.command])
|
|||
|
window[msg.command].apply(window, msg.args);
|
|||
|
else
|
|||
|
throw new Error("Unknown command:" + msg.command);
|
|||
|
}
|
|||
|
else if (msg.init) {
|
|||
|
window.initBaseUrls(msg.tlns);
|
|||
|
require("ace/lib/es5-shim");
|
|||
|
sender = window.sender = window.initSender();
|
|||
|
var clazz = require(msg.module)[msg.classname];
|
|||
|
main = window.main = new clazz(sender);
|
|||
|
}
|
|||
|
};
|
|||
|
})(this);
|
|||
|
|
|||
|
ace.define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.inherits = function(ctor, superCtor) {
|
|||
|
ctor.super_ = superCtor;
|
|||
|
ctor.prototype = Object.create(superCtor.prototype, {
|
|||
|
constructor: {
|
|||
|
value: ctor,
|
|||
|
enumerable: false,
|
|||
|
writable: true,
|
|||
|
configurable: true
|
|||
|
}
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
exports.mixin = function(obj, mixin) {
|
|||
|
for (var key in mixin) {
|
|||
|
obj[key] = mixin[key];
|
|||
|
}
|
|||
|
return obj;
|
|||
|
};
|
|||
|
|
|||
|
exports.implement = function(proto, mixin) {
|
|||
|
exports.mixin(proto, mixin);
|
|||
|
};
|
|||
|
|
|||
|
});
|
|||
|
|
|||
|
ace.define("ace/range",["require","exports","module"], function(require, exports, module) {
|
|||
|
"use strict";
|
|||
|
var comparePoints = function(p1, p2) {
|
|||
|
return p1.row - p2.row || p1.column - p2.column;
|
|||
|
};
|
|||
|
var Range = function(startRow, startColumn, endRow, endColumn) {
|
|||
|
this.start = {
|
|||
|
row: startRow,
|
|||
|
column: startColumn
|
|||
|
};
|
|||
|
|
|||
|
this.end = {
|
|||
|
row: endRow,
|
|||
|
column: endColumn
|
|||
|
};
|
|||
|
};
|
|||
|
|
|||
|
(function() {
|
|||
|
this.isEqual = function(range) {
|
|||
|
return this.start.row === range.start.row &&
|
|||
|
this.end.row === range.end.row &&
|
|||
|
this.start.column === range.start.column &&
|
|||
|
this.end.column === range.end.column;
|
|||
|
};
|
|||
|
this.toString = function() {
|
|||
|
return ("Range: [" + this.start.row + "/" + this.start.column +
|
|||
|
"] -> [" + this.end.row + "/" + this.end.column + "]");
|
|||
|
};
|
|||
|
|
|||
|
this.contains = function(row, column) {
|
|||
|
return this.compare(row, column) == 0;
|
|||
|
};
|
|||
|
this.compareRange = function(range) {
|
|||
|
var cmp,
|
|||
|
end = range.end,
|
|||
|
start = range.start;
|
|||
|
|
|||
|
cmp = this.compare(end.row, end.column);
|
|||
|
if (cmp == 1) {
|
|||
|
cmp = this.compare(start.row, start.column);
|
|||
|
if (cmp == 1) {
|
|||
|
return 2;
|
|||
|
} else if (cmp == 0) {
|
|||
|
return 1;
|
|||
|
} else {
|
|||
|
return 0;
|
|||
|
}
|
|||
|
} else if (cmp == -1) {
|
|||
|
return -2;
|
|||
|
} else {
|
|||
|
cmp = this.compare(start.row, start.column);
|
|||
|
if (cmp == -1) {
|
|||
|
return -1;
|
|||
|
} else if (cmp == 1) {
|
|||
|
return 42;
|
|||
|
} else {
|
|||
|
return 0;
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
this.comparePoint = function(p) {
|
|||
|
return this.compare(p.row, p.column);
|
|||
|
};
|
|||
|
this.containsRange = function(range) {
|
|||
|
return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
|
|||
|
};
|
|||
|
this.intersects = function(range) {
|
|||
|
var cmp = this.compareRange(range);
|
|||
|
return (cmp == -1 || cmp == 0 || cmp == 1);
|
|||
|
};
|
|||
|
this.isEnd = function(row, column) {
|
|||
|
return this.end.row == row && this.end.column == column;
|
|||
|
};
|
|||
|
this.isStart = function(row, column) {
|
|||
|
return this.start.row == row && this.start.column == column;
|
|||
|
};
|
|||
|
this.setStart = function(row, column) {
|
|||
|
if (typeof row == "object") {
|
|||
|
this.start.column = row.column;
|
|||
|
this.start.row = row.row;
|
|||
|
} else {
|
|||
|
this.start.row = row;
|
|||
|
this.start.column = column;
|
|||
|
}
|
|||
|
};
|
|||
|
this.setEnd = function(row, column) {
|
|||
|
if (typeof row == "object") {
|
|||
|
this.end.column = row.column;
|
|||
|
this.end.row = row.row;
|
|||
|
} else {
|
|||
|
this.end.row = row;
|
|||
|
this.end.column = column;
|
|||
|
}
|
|||
|
};
|
|||
|
this.inside = function(row, column) {
|
|||
|
if (this.compare(row, column) == 0) {
|
|||
|
if (this.isEnd(row, column) || this.isStart(row, column)) {
|
|||
|
return false;
|
|||
|
} else {
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
};
|
|||
|
this.insideStart = function(row, column) {
|
|||
|
if (this.compare(row, column) == 0) {
|
|||
|
if (this.isEnd(row, column)) {
|
|||
|
return false;
|
|||
|
} else {
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
};
|
|||
|
this.insideEnd = function(row, column) {
|
|||
|
if (this.compare(row, column) == 0) {
|
|||
|
if (this.isStart(row, column)) {
|
|||
|
return false;
|
|||
|
} else {
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
};
|
|||
|
this.compare = function(row, column) {
|
|||
|
if (!this.isMultiLine()) {
|
|||
|
if (row === this.start.row) {
|
|||
|
return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (row < this.start.row)
|
|||
|
return -1;
|
|||
|
|
|||
|
if (row > this.end.row)
|
|||
|
return 1;
|
|||
|
|
|||
|
if (this.start.row === row)
|
|||
|
return column >= this.start.column ? 0 : -1;
|
|||
|
|
|||
|
if (this.end.row === row)
|
|||
|
return column <= this.end.column ? 0 : 1;
|
|||
|
|
|||
|
return 0;
|
|||
|
};
|
|||
|
this.compareStart = function(row, column) {
|
|||
|
if (this.start.row == row && this.start.column == column) {
|
|||
|
return -1;
|
|||
|
} else {
|
|||
|
return this.compare(row, column);
|
|||
|
}
|
|||
|
};
|
|||
|
this.compareEnd = function(row, column) {
|
|||
|
if (this.end.row == row && this.end.column == column) {
|
|||
|
return 1;
|
|||
|
} else {
|
|||
|
return this.compare(row, column);
|
|||
|
}
|
|||
|
};
|
|||
|
this.compareInside = function(row, column) {
|
|||
|
if (this.end.row == row && this.end.column == column) {
|
|||
|
return 1;
|
|||
|
} else if (this.start.row == row && this.start.column == column) {
|
|||
|
return -1;
|
|||
|
} else {
|
|||
|
return this.compare(row, column);
|
|||
|
}
|
|||
|
};
|
|||
|
this.clipRows = function(firstRow, lastRow) {
|
|||
|
if (this.end.row > lastRow)
|
|||
|
var end = {row: lastRow + 1, column: 0};
|
|||
|
else if (this.end.row < firstRow)
|
|||
|
var end = {row: firstRow, column: 0};
|
|||
|
|
|||
|
if (this.start.row > lastRow)
|
|||
|
var start = {row: lastRow + 1, column: 0};
|
|||
|
else if (this.start.row < firstRow)
|
|||
|
var start = {row: firstRow, column: 0};
|
|||
|
|
|||
|
return Range.fromPoints(start || this.start, end || this.end);
|
|||
|
};
|
|||
|
this.extend = function(row, column) {
|
|||
|
var cmp = this.compare(row, column);
|
|||
|
|
|||
|
if (cmp == 0)
|
|||
|
return this;
|
|||
|
else if (cmp == -1)
|
|||
|
var start = {row: row, column: column};
|
|||
|
else
|
|||
|
var end = {row: row, column: column};
|
|||
|
|
|||
|
return Range.fromPoints(start || this.start, end || this.end);
|
|||
|
};
|
|||
|
|
|||
|
this.isEmpty = function() {
|
|||
|
return (this.start.row === this.end.row && this.start.column === this.end.column);
|
|||
|
};
|
|||
|
this.isMultiLine = function() {
|
|||
|
return (this.start.row !== this.end.row);
|
|||
|
};
|
|||
|
this.clone = function() {
|
|||
|
return Range.fromPoints(this.start, this.end);
|
|||
|
};
|
|||
|
this.collapseRows = function() {
|
|||
|
if (this.end.column == 0)
|
|||
|
return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
|
|||
|
else
|
|||
|
return new Range(this.start.row, 0, this.end.row, 0)
|
|||
|
};
|
|||
|
this.toScreenRange = function(session) {
|
|||
|
var screenPosStart = session.documentToScreenPosition(this.start);
|
|||
|
var screenPosEnd = session.documentToScreenPosition(this.end);
|
|||
|
|
|||
|
return new Range(
|
|||
|
screenPosStart.row, screenPosStart.column,
|
|||
|
screenPosEnd.row, screenPosEnd.column
|
|||
|
);
|
|||
|
};
|
|||
|
this.moveBy = function(row, column) {
|
|||
|
this.start.row += row;
|
|||
|
this.start.column += column;
|
|||
|
this.end.row += row;
|
|||
|
this.end.column += column;
|
|||
|
};
|
|||
|
|
|||
|
}).call(Range.prototype);
|
|||
|
Range.fromPoints = function(start, end) {
|
|||
|
return new Range(start.row, start.column, end.row, end.column);
|
|||
|
};
|
|||
|
Range.comparePoints = comparePoints;
|
|||
|
|
|||
|
Range.comparePoints = function(p1, p2) {
|
|||
|
return p1.row - p2.row || p1.column - p2.column;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
exports.Range = Range;
|
|||
|
});
|
|||
|
|
|||
|
ace.define("ace/apply_delta",["require","exports","module"], function(require, exports, module) {
|
|||
|
"use strict";
|
|||
|
|
|||
|
function throwDeltaError(delta, errorText){
|
|||
|
console.log("Invalid Delta:", delta);
|
|||
|
throw "Invalid Delta: " + errorText;
|
|||
|
}
|
|||
|
|
|||
|
function positionInDocument(docLines, position) {
|
|||
|
return position.row >= 0 && position.row < docLines.length &&
|
|||
|
position.column >= 0 && position.column <= docLines[position.row].length;
|
|||
|
}
|
|||
|
|
|||
|
function validateDelta(docLines, delta) {
|
|||
|
if (delta.action != "insert" && delta.action != "remove")
|
|||
|
throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
|
|||
|
if (!(delta.lines instanceof Array))
|
|||
|
throwDeltaError(delta, "delta.lines must be an Array");
|
|||
|
if (!delta.start || !delta.end)
|
|||
|
throwDeltaError(delta, "delta.start/end must be an present");
|
|||
|
var start = delta.start;
|
|||
|
if (!positionInDocument(docLines, delta.start))
|
|||
|
throwDeltaError(delta, "delta.start must be contained in document");
|
|||
|
var end = delta.end;
|
|||
|
if (delta.action == "remove" && !positionInDocument(docLines, end))
|
|||
|
throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
|
|||
|
var numRangeRows = end.row - start.row;
|
|||
|
var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
|
|||
|
if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
|
|||
|
throwDeltaError(delta, "delta.range must match delta lines");
|
|||
|
}
|
|||
|
|
|||
|
exports.applyDelta = function(docLines, delta, doNotValidate) {
|
|||
|
|
|||
|
var row = delta.start.row;
|
|||
|
var startColumn = delta.start.column;
|
|||
|
var line = docLines[row] || "";
|
|||
|
switch (delta.action) {
|
|||
|
case "insert":
|
|||
|
var lines = delta.lines;
|
|||
|
if (lines.length === 1) {
|
|||
|
docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
|
|||
|
} else {
|
|||
|
var args = [row, 1].concat(delta.lines);
|
|||
|
docLines.splice.apply(docLines, args);
|
|||
|
docLines[row] = line.substring(0, startColumn) + docLines[row];
|
|||
|
docLines[row + delta.lines.length - 1] += line.substring(startColumn);
|
|||
|
}
|
|||
|
break;
|
|||
|
case "remove":
|
|||
|
var endColumn = delta.end.column;
|
|||
|
var endRow = delta.end.row;
|
|||
|
if (row === endRow) {
|
|||
|
docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
|
|||
|
} else {
|
|||
|
docLines.splice(
|
|||
|
row, endRow - row + 1,
|
|||
|
line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
|
|||
|
);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
|
|||
|
"use strict";
|
|||
|
|
|||
|
var EventEmitter = {};
|
|||
|
var stopPropagation = function() { this.propagationStopped = true; };
|
|||
|
var preventDefault = function() { this.defaultPrevented = true; };
|
|||
|
|
|||
|
EventEmitter._emit =
|
|||
|
EventEmitter._dispatchEvent = function(eventName, e) {
|
|||
|
this._eventRegistry || (this._eventRegistry = {});
|
|||
|
this._defaultHandlers || (this._defaultHandlers = {});
|
|||
|
|
|||
|
var listeners = this._eventRegistry[eventName] || [];
|
|||
|
var defaultHandler = this._defaultHandlers[eventName];
|
|||
|
if (!listeners.length && !defaultHandler)
|
|||
|
return;
|
|||
|
|
|||
|
if (typeof e != "object" || !e)
|
|||
|
e = {};
|
|||
|
|
|||
|
if (!e.type)
|
|||
|
e.type = eventName;
|
|||
|
if (!e.stopPropagation)
|
|||
|
e.stopPropagation = stopPropagation;
|
|||
|
if (!e.preventDefault)
|
|||
|
e.preventDefault = preventDefault;
|
|||
|
|
|||
|
listeners = listeners.slice();
|
|||
|
for (var i=0; i<listeners.length; i++) {
|
|||
|
listeners[i](e, this);
|
|||
|
if (e.propagationStopped)
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if (defaultHandler && !e.defaultPrevented)
|
|||
|
return defaultHandler(e, this);
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
EventEmitter._signal = function(eventName, e) {
|
|||
|
var listeners = (this._eventRegistry || {})[eventName];
|
|||
|
if (!listeners)
|
|||
|
return;
|
|||
|
listeners = listeners.slice();
|
|||
|
for (var i=0; i<listeners.length; i++)
|
|||
|
listeners[i](e, this);
|
|||
|
};
|
|||
|
|
|||
|
EventEmitter.once = function(eventName, callback) {
|
|||
|
var _self = this;
|
|||
|
callback && this.addEventListener(eventName, function newCallback() {
|
|||
|
_self.removeEventListener(eventName, newCallback);
|
|||
|
callback.apply(null, arguments);
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
EventEmitter.setDefaultHandler = function(eventName, callback) {
|
|||
|
var handlers = this._defaultHandlers
|
|||
|
if (!handlers)
|
|||
|
handlers = this._defaultHandlers = {_disabled_: {}};
|
|||
|
|
|||
|
if (handlers[eventName]) {
|
|||
|
var old = handlers[eventName];
|
|||
|
var disabled = handlers._disabled_[eventName];
|
|||
|
if (!disabled)
|
|||
|
handlers._disabled_[eventName] = disabled = [];
|
|||
|
disabled.push(old);
|
|||
|
var i = disabled.indexOf(callback);
|
|||
|
if (i != -1)
|
|||
|
disabled.splice(i, 1);
|
|||
|
}
|
|||
|
handlers[eventName] = callback;
|
|||
|
};
|
|||
|
EventEmitter.removeDefaultHandler = function(eventName, callback) {
|
|||
|
var handlers = this._defaultHandlers
|
|||
|
if (!handlers)
|
|||
|
return;
|
|||
|
var disabled = handlers._disabled_[eventName];
|
|||
|
|
|||
|
if (handlers[eventName] == callback) {
|
|||
|
var old = handlers[eventName];
|
|||
|
if (disabled)
|
|||
|
this.setDefaultHandler(eventName, disabled.pop());
|
|||
|
} else if (disabled) {
|
|||
|
var i = disabled.indexOf(callback);
|
|||
|
if (i != -1)
|
|||
|
disabled.splice(i, 1);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
EventEmitter.on =
|
|||
|
EventEmitter.addEventListener = function(eventName, callback, capturing) {
|
|||
|
this._eventRegistry = this._eventRegistry || {};
|
|||
|
|
|||
|
var listeners = this._eventRegistry[eventName];
|
|||
|
if (!listeners)
|
|||
|
listeners = this._eventRegistry[eventName] = [];
|
|||
|
|
|||
|
if (listeners.indexOf(callback) == -1)
|
|||
|
listeners[capturing ? "unshift" : "push"](callback);
|
|||
|
return callback;
|
|||
|
};
|
|||
|
|
|||
|
EventEmitter.off =
|
|||
|
EventEmitter.removeListener =
|
|||
|
EventEmitter.removeEventListener = function(eventName, callback) {
|
|||
|
this._eventRegistry = this._eventRegistry || {};
|
|||
|
|
|||
|
var listeners = this._eventRegistry[eventName];
|
|||
|
if (!listeners)
|
|||
|
return;
|
|||
|
|
|||
|
var index = listeners.indexOf(callback);
|
|||
|
if (index !== -1)
|
|||
|
listeners.splice(index, 1);
|
|||
|
};
|
|||
|
|
|||
|
EventEmitter.removeAllListeners = function(eventName) {
|
|||
|
if (this._eventRegistry) this._eventRegistry[eventName] = [];
|
|||
|
};
|
|||
|
|
|||
|
exports.EventEmitter = EventEmitter;
|
|||
|
|
|||
|
});
|
|||
|
|
|||
|
ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
|
|||
|
"use strict";
|
|||
|
|
|||
|
var oop = require("./lib/oop");
|
|||
|
var EventEmitter = require("./lib/event_emitter").EventEmitter;
|
|||
|
|
|||
|
var Anchor = exports.Anchor = function(doc, row, column) {
|
|||
|
this.$onChange = this.onChange.bind(this);
|
|||
|
this.attach(doc);
|
|||
|
|
|||
|
if (typeof column == "undefined")
|
|||
|
this.setPosition(row.row, row.column);
|
|||
|
else
|
|||
|
this.setPosition(row, column);
|
|||
|
};
|
|||
|
|
|||
|
(function() {
|
|||
|
|
|||
|
oop.implement(this, EventEmitter);
|
|||
|
this.getPosition = function() {
|
|||
|
return this.$clipPositionToDocument(this.row, this.column);
|
|||
|
};
|
|||
|
this.getDocument = function() {
|
|||
|
return this.document;
|
|||
|
};
|
|||
|
this.$insertRight = false;
|
|||
|
this.onChange = function(delta) {
|
|||
|
if (delta.start.row == delta.end.row && delta.start.row != this.row)
|
|||
|
return;
|
|||
|
|
|||
|
if (delta.start.row > this.row)
|
|||
|
return;
|
|||
|
|
|||
|
var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight);
|
|||
|
this.setPosition(point.row, point.column, true);
|
|||
|
};
|
|||
|
|
|||
|
function $pointsInOrder(point1, point2, equalPointsInOrder) {
|
|||
|
var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
|
|||
|
return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
|
|||
|
}
|
|||
|
|
|||
|
function $getTransformedPoint(delta, point, moveIfEqual) {
|
|||
|
var deltaIsInsert = delta.action == "insert";
|
|||
|
var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
|
|||
|
var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
|
|||
|
var deltaStart = delta.start;
|
|||
|
var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
|
|||
|
if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
|
|||
|
return {
|
|||
|
row: point.row,
|
|||
|
column: point.column
|
|||
|
};
|
|||
|
}
|
|||
|
if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
|
|||
|
return {
|
|||
|
row: point.row + deltaRowShift,
|
|||
|
column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
return {
|
|||
|
row: deltaStart.row,
|
|||
|
column: deltaStart.column
|
|||
|
};
|
|||
|
}
|
|||
|
this.setPosition = function(row, column, noClip) {
|
|||
|
var pos;
|
|||
|
if (noClip) {
|
|||
|
pos = {
|
|||
|
row: row,
|
|||
|
column: column
|
|||
|
};
|
|||
|
} else {
|
|||
|
pos = this.$clipPositionToDocument(row, column);
|
|||
|
}
|
|||
|
|
|||
|
if (this.row == pos.row && this.column == pos.column)
|
|||
|
return;
|
|||
|
|
|||
|
var old = {
|
|||
|
row: this.row,
|
|||
|
column: this.column
|
|||
|
};
|
|||
|
|
|||
|
this.row = pos.row;
|
|||
|
this.column = pos.column;
|
|||
|
this._signal("change", {
|
|||
|
old: old,
|
|||
|
value: pos
|
|||
|
});
|
|||
|
};
|
|||
|
this.detach = function() {
|
|||
|
this.document.removeEventListener("change", this.$onChange);
|
|||
|
};
|
|||
|
this.attach = function(doc) {
|
|||
|
this.document = doc || this.document;
|
|||
|
this.document.on("change", this.$onChange);
|
|||
|
};
|
|||
|
this.$clipPositionToDocument = function(row, column) {
|
|||
|
var pos = {};
|
|||
|
|
|||
|
if (row >= this.document.getLength()) {
|
|||
|
pos.row = Math.max(0, this.document.getLength() - 1);
|
|||
|
pos.column = this.document.getLine(pos.row).length;
|
|||
|
}
|
|||
|
else if (row < 0) {
|
|||
|
pos.row = 0;
|
|||
|
pos.column = 0;
|
|||
|
}
|
|||
|
else {
|
|||
|
pos.row = row;
|
|||
|
pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
|
|||
|
}
|
|||
|
|
|||
|
if (column < 0)
|
|||
|
pos.column = 0;
|
|||
|
|
|||
|
return pos;
|
|||
|
};
|
|||
|
|
|||
|
}).call(Anchor.prototype);
|
|||
|
|
|||
|
});
|
|||
|
|
|||
|
ace.define("ace/document",["require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
|
|||
|
"use strict";
|
|||
|
|
|||
|
var oop = require("./lib/oop");
|
|||
|
var applyDelta = require("./apply_delta").applyDelta;
|
|||
|
var EventEmitter = require("./lib/event_emitter").EventEmitter;
|
|||
|
var Range = require("./range").Range;
|
|||
|
var Anchor = require("./anchor").Anchor;
|
|||
|
|
|||
|
var Document = function(textOrLines) {
|
|||
|
this.$lines = [""];
|
|||
|
if (textOrLines.length === 0) {
|
|||
|
this.$lines = [""];
|
|||
|
} else if (Array.isArray(textOrLines)) {
|
|||
|
this.insertMergedLines({row: 0, column: 0}, textOrLines);
|
|||
|
} else {
|
|||
|
this.insert({row: 0, column:0}, textOrLines);
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
(function() {
|
|||
|
|
|||
|
oop.implement(this, EventEmitter);
|
|||
|
this.setValue = function(text) {
|
|||
|
var len = this.getLength() - 1;
|
|||
|
this.remove(new Range(0, 0, len, this.getLine(len).length));
|
|||
|
this.insert({row: 0, column: 0}, text);
|
|||
|
};
|
|||
|
this.getValue = function() {
|
|||
|
return this.getAllLines().join(this.getNewLineCharacter());
|
|||
|
};
|
|||
|
this.createAnchor = function(row, column) {
|
|||
|
return new Anchor(this, row, column);
|
|||
|
};
|
|||
|
if ("aaa".split(/a/).length === 0) {
|
|||
|
this.$split = function(text) {
|
|||
|
return text.replace(/\r\n|\r/g, "\n").split("\n");
|
|||
|
};
|
|||
|
} else {
|
|||
|
this.$split = function(text) {
|
|||
|
return text.split(/\r\n|\r|\n/);
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
this.$detectNewLine = function(text) {
|
|||
|
var match = text.match(/^.*?(\r\n|\r|\n)/m);
|
|||
|
this.$autoNewLine = match ? match[1] : "\n";
|
|||
|
this._signal("changeNewLineMode");
|
|||
|
};
|
|||
|
this.getNewLineCharacter = function() {
|
|||
|
switch (this.$newLineMode) {
|
|||
|
case "windows":
|
|||
|
return "\r\n";
|
|||
|
case "unix":
|
|||
|
return "\n";
|
|||
|
default:
|
|||
|
return this.$autoNewLine || "\n";
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
this.$autoNewLine = "";
|
|||
|
this.$newLineMode = "auto";
|
|||
|
this.setNewLineMode = function(newLineMode) {
|
|||
|
if (this.$newLineMode === newLineMode)
|
|||
|
return;
|
|||
|
|
|||
|
this.$newLineMode = newLineMode;
|
|||
|
this._signal("changeNewLineMode");
|
|||
|
};
|
|||
|
this.getNewLineMode = function() {
|
|||
|
return this.$newLineMode;
|
|||
|
};
|
|||
|
this.isNewLine = function(text) {
|
|||
|
return (text == "\r\n" || text == "\r" || text == "\n");
|
|||
|
};
|
|||
|
this.getLine = function(row) {
|
|||
|
return this.$lines[row] || "";
|
|||
|
};
|
|||
|
this.getLines = function(firstRow, lastRow) {
|
|||
|
return this.$lines.slice(firstRow, lastRow + 1);
|
|||
|
};
|
|||
|
this.getAllLines = function() {
|
|||
|
return this.getLines(0, this.getLength());
|
|||
|
};
|
|||
|
this.getLength = function() {
|
|||
|
return this.$lines.length;
|
|||
|
};
|
|||
|
this.getTextRange = function(range) {
|
|||
|
return this.getLinesForRange(range).join(this.getNewLineCharacter());
|
|||
|
};
|
|||
|
this.getLinesForRange = function(range) {
|
|||
|
var lines;
|
|||
|
if (range.start.row === range.end.row) {
|
|||
|
lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
|
|||
|
} else {
|
|||
|
lines = this.getLines(range.start.row, range.end.row);
|
|||
|
lines[0] = (lines[0] || "").substring(range.start.column);
|
|||
|
var l = lines.length - 1;
|
|||
|
if (range.end.row - range.start.row == l)
|
|||
|
lines[l] = lines[l].substring(0, range.end.column);
|
|||
|
}
|
|||
|
return lines;
|
|||
|
};
|
|||
|
this.insertLines = function(row, lines) {
|
|||
|
console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead.");
|
|||
|
return this.insertFullLines(row, lines);
|
|||
|
};
|
|||
|
this.removeLines = function(firstRow, lastRow) {
|
|||
|
console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead.");
|
|||
|
return this.removeFullLines(firstRow, lastRow);
|
|||
|
};
|
|||
|
this.insertNewLine = function(position) {
|
|||
|
console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.");
|
|||
|
return this.insertMergedLines(position, ["", ""]);
|
|||
|
};
|
|||
|
this.insert = function(position, text) {
|
|||
|
if (this.getLength() <= 1)
|
|||
|
this.$detectNewLine(text);
|
|||
|
|
|||
|
return this.insertMergedLines(position, this.$split(text));
|
|||
|
};
|
|||
|
this.insertInLine = function(position, text) {
|
|||
|
var start = this.clippedPos(position.row, position.column);
|
|||
|
var end = this.pos(position.row, position.column + text.length);
|
|||
|
|
|||
|
this.applyDelta({
|
|||
|
start: start,
|
|||
|
end: end,
|
|||
|
action: "insert",
|
|||
|
lines: [text]
|
|||
|
}, true);
|
|||
|
|
|||
|
return this.clonePos(end);
|
|||
|
};
|
|||
|
|
|||
|
this.clippedPos = function(row, column) {
|
|||
|
var length = this.getLength();
|
|||
|
if (row === undefined) {
|
|||
|
row = length;
|
|||
|
} else if (row < 0) {
|
|||
|
row = 0;
|
|||
|
} else if (row >= length) {
|
|||
|
row = length - 1;
|
|||
|
column = undefined;
|
|||
|
}
|
|||
|
var line = this.getLine(row);
|
|||
|
if (column == undefined)
|
|||
|
column = line.length;
|
|||
|
column = Math.min(Math.max(column, 0), line.length);
|
|||
|
return {row: row, column: column};
|
|||
|
};
|
|||
|
|
|||
|
this.clonePos = function(pos) {
|
|||
|
return {row: pos.row, column: pos.column};
|
|||
|
};
|
|||
|
|
|||
|
this.pos = function(row, column) {
|
|||
|
return {row: row, column: column};
|
|||
|
};
|
|||
|
|
|||
|
this.$clipPosition = function(position) {
|
|||
|
var length = this.getLength();
|
|||
|
if (position.row >= length) {
|
|||
|
position.row = Math.max(0, length - 1);
|
|||
|
position.column = this.getLine(length - 1).length;
|
|||
|
} else {
|
|||
|
position.row = Math.max(0, position.row);
|
|||
|
position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
|
|||
|
}
|
|||
|
return position;
|
|||
|
};
|
|||
|
this.insertFullLines = function(row, lines) {
|
|||
|
row = Math.min(Math.max(row, 0), this.getLength());
|
|||
|
var column = 0;
|
|||
|
if (row < this.getLength()) {
|
|||
|
lines = lines.concat([""]);
|
|||
|
column = 0;
|
|||
|
} else {
|
|||
|
lines = [""].concat(lines);
|
|||
|
row--;
|
|||
|
column = this.$lines[row].length;
|
|||
|
}
|
|||
|
this.insertMergedLines({row: row, column: column}, lines);
|
|||
|
};
|
|||
|
this.insertMergedLines = function(position, lines) {
|
|||
|
var start = this.clippedPos(position.row, position.column);
|
|||
|
var end = {
|
|||
|
row: start.row + lines.length - 1,
|
|||
|
column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length
|
|||
|
};
|
|||
|
|
|||
|
this.applyDelta({
|
|||
|
start: start,
|
|||
|
end: end,
|
|||
|
action: "insert",
|
|||
|
lines: lines
|
|||
|
});
|
|||
|
|
|||
|
return this.clonePos(end);
|
|||
|
};
|
|||
|
this.remove = function(range) {
|
|||
|
var start = this.clippedPos(range.start.row, range.start.column);
|
|||
|
var end = this.clippedPos(range.end.row, range.end.column);
|
|||
|
this.applyDelta({
|
|||
|
start: start,
|
|||
|
end: end,
|
|||
|
action: "remove",
|
|||
|
lines: this.getLinesForRange({start: start, end: end})
|
|||
|
});
|
|||
|
return this.clonePos(start);
|
|||
|
};
|
|||
|
this.removeInLine = function(row, startColumn, endColumn) {
|
|||
|
var start = this.clippedPos(row, startColumn);
|
|||
|
var end = this.clippedPos(row, endColumn);
|
|||
|
|
|||
|
this.applyDelta({
|
|||
|
start: start,
|
|||
|
end: end,
|
|||
|
action: "remove",
|
|||
|
lines: this.getLinesForRange({start: start, end: end})
|
|||
|
}, true);
|
|||
|
|
|||
|
return this.clonePos(start);
|
|||
|
};
|
|||
|
this.removeFullLines = function(firstRow, lastRow) {
|
|||
|
firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1);
|
|||
|
lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1);
|
|||
|
var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0;
|
|||
|
var deleteLastNewLine = lastRow < this.getLength() - 1;
|
|||
|
var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow );
|
|||
|
var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 );
|
|||
|
var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow );
|
|||
|
var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length );
|
|||
|
var range = new Range(startRow, startCol, endRow, endCol);
|
|||
|
var deletedLines = this.$lines.slice(firstRow, lastRow + 1);
|
|||
|
|
|||
|
this.applyDelta({
|
|||
|
start: range.start,
|
|||
|
end: range.end,
|
|||
|
action: "remove",
|
|||
|
lines: this.getLinesForRange(range)
|
|||
|
});
|
|||
|
return deletedLines;
|
|||
|
};
|
|||
|
this.removeNewLine = function(row) {
|
|||
|
if (row < this.getLength() - 1 && row >= 0) {
|
|||
|
this.applyDelta({
|
|||
|
start: this.pos(row, this.getLine(row).length),
|
|||
|
end: this.pos(row + 1, 0),
|
|||
|
action: "remove",
|
|||
|
lines: ["", ""]
|
|||
|
});
|
|||
|
}
|
|||
|
};
|
|||
|
this.replace = function(range, text) {
|
|||
|
if (!(range instanceof Range))
|
|||
|
range = Range.fromPoints(range.start, range.end);
|
|||
|
if (text.length === 0 && range.isEmpty())
|
|||
|
return range.start;
|
|||
|
if (text == this.getTextRange(range))
|
|||
|
return range.end;
|
|||
|
|
|||
|
this.remove(range);
|
|||
|
var end;
|
|||
|
if (text) {
|
|||
|
end = this.insert(range.start, text);
|
|||
|
}
|
|||
|
else {
|
|||
|
end = range.start;
|
|||
|
}
|
|||
|
|
|||
|
return end;
|
|||
|
};
|
|||
|
this.applyDeltas = function(deltas) {
|
|||
|
for (var i=0; i<deltas.length; i++) {
|
|||
|
this.applyDelta(deltas[i]);
|
|||
|
}
|
|||
|
};
|
|||
|
this.revertDeltas = function(deltas) {
|
|||
|
for (var i=deltas.length-1; i>=0; i--) {
|
|||
|
this.revertDelta(deltas[i]);
|
|||
|
}
|
|||
|
};
|
|||
|
this.applyDelta = function(delta, doNotValidate) {
|
|||
|
var isInsert = delta.action == "insert";
|
|||
|
if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
|
|||
|
: !Range.comparePoints(delta.start, delta.end)) {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (isInsert && delta.lines.length > 20000)
|
|||
|
this.$splitAndapplyLargeDelta(delta, 20000);
|
|||
|
applyDelta(this.$lines, delta, doNotValidate);
|
|||
|
this._signal("change", delta);
|
|||
|
};
|
|||
|
|
|||
|
this.$splitAndapplyLargeDelta = function(delta, MAX) {
|
|||
|
var lines = delta.lines;
|
|||
|
var l = lines.length;
|
|||
|
var row = delta.start.row;
|
|||
|
var column = delta.start.column;
|
|||
|
var from = 0, to = 0;
|
|||
|
do {
|
|||
|
from = to;
|
|||
|
to += MAX - 1;
|
|||
|
var chunk = lines.slice(from, to);
|
|||
|
if (to > l) {
|
|||
|
delta.lines = chunk;
|
|||
|
delta.start.row = row + from;
|
|||
|
delta.start.column = column;
|
|||
|
break;
|
|||
|
}
|
|||
|
chunk.push("");
|
|||
|
this.applyDelta({
|
|||
|
start: this.pos(row + from, column),
|
|||
|
end: this.pos(row + to, column = 0),
|
|||
|
action: delta.action,
|
|||
|
lines: chunk
|
|||
|
}, true);
|
|||
|
} while(true);
|
|||
|
};
|
|||
|
this.revertDelta = function(delta) {
|
|||
|
this.applyDelta({
|
|||
|
start: this.clonePos(delta.start),
|
|||
|
end: this.clonePos(delta.end),
|
|||
|
action: (delta.action == "insert" ? "remove" : "insert"),
|
|||
|
lines: delta.lines.slice()
|
|||
|
});
|
|||
|
};
|
|||
|
this.indexToPosition = function(index, startRow) {
|
|||
|
var lines = this.$lines || this.getAllLines();
|
|||
|
var newlineLength = this.getNewLineCharacter().length;
|
|||
|
for (var i = startRow || 0, l = lines.length; i < l; i++) {
|
|||
|
index -= lines[i].length + newlineLength;
|
|||
|
if (index < 0)
|
|||
|
return {row: i, column: index + lines[i].length + newlineLength};
|
|||
|
}
|
|||
|
return {row: l-1, column: lines[l-1].length};
|
|||
|
};
|
|||
|
this.positionToIndex = function(pos, startRow) {
|
|||
|
var lines = this.$lines || this.getAllLines();
|
|||
|
var newlineLength = this.getNewLineCharacter().length;
|
|||
|
var index = 0;
|
|||
|
var row = Math.min(pos.row, lines.length);
|
|||
|
for (var i = startRow || 0; i < row; ++i)
|
|||
|
index += lines[i].length + newlineLength;
|
|||
|
|
|||
|
return index + pos.column;
|
|||
|
};
|
|||
|
|
|||
|
}).call(Document.prototype);
|
|||
|
|
|||
|
exports.Document = Document;
|
|||
|
});
|
|||
|
|
|||
|
ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
|
|||
|
"use strict";
|
|||
|
|
|||
|
exports.last = function(a) {
|
|||
|
return a[a.length - 1];
|
|||
|
};
|
|||
|
|
|||
|
exports.stringReverse = function(string) {
|
|||
|
return string.split("").reverse().join("");
|
|||
|
};
|
|||
|
|
|||
|
exports.stringRepeat = function (string, count) {
|
|||
|
var result = '';
|
|||
|
while (count > 0) {
|
|||
|
if (count & 1)
|
|||
|
result += string;
|
|||
|
|
|||
|
if (count >>= 1)
|
|||
|
string += string;
|
|||
|
}
|
|||
|
return result;
|
|||
|
};
|
|||
|
|
|||
|
var trimBeginRegexp = /^\s\s*/;
|
|||
|
var trimEndRegexp = /\s\s*$/;
|
|||
|
|
|||
|
exports.stringTrimLeft = function (string) {
|
|||
|
return string.replace(trimBeginRegexp, '');
|
|||
|
};
|
|||
|
|
|||
|
exports.stringTrimRight = function (string) {
|
|||
|
return string.replace(trimEndRegexp, '');
|
|||
|
};
|
|||
|
|
|||
|
exports.copyObject = function(obj) {
|
|||
|
var copy = {};
|
|||
|
for (var key in obj) {
|
|||
|
copy[key] = obj[key];
|
|||
|
}
|
|||
|
return copy;
|
|||
|
};
|
|||
|
|
|||
|
exports.copyArray = function(array){
|
|||
|
var copy = [];
|
|||
|
for (var i=0, l=array.length; i<l; i++) {
|
|||
|
if (array[i] && typeof array[i] == "object")
|
|||
|
copy[i] = this.copyObject(array[i]);
|
|||
|
else
|
|||
|
copy[i] = array[i];
|
|||
|
}
|
|||
|
return copy;
|
|||
|
};
|
|||
|
|
|||
|
exports.deepCopy = function deepCopy(obj) {
|
|||
|
if (typeof obj !== "object" || !obj)
|
|||
|
return obj;
|
|||
|
var copy;
|
|||
|
if (Array.isArray(obj)) {
|
|||
|
copy = [];
|
|||
|
for (var key = 0; key < obj.length; key++) {
|
|||
|
copy[key] = deepCopy(obj[key]);
|
|||
|
}
|
|||
|
return copy;
|
|||
|
}
|
|||
|
if (Object.prototype.toString.call(obj) !== "[object Object]")
|
|||
|
return obj;
|
|||
|
|
|||
|
copy = {};
|
|||
|
for (var key in obj)
|
|||
|
copy[key] = deepCopy(obj[key]);
|
|||
|
return copy;
|
|||
|
};
|
|||
|
|
|||
|
exports.arrayToMap = function(arr) {
|
|||
|
var map = {};
|
|||
|
for (var i=0; i<arr.length; i++) {
|
|||
|
map[arr[i]] = 1;
|
|||
|
}
|
|||
|
return map;
|
|||
|
|
|||
|
};
|
|||
|
|
|||
|
exports.createMap = function(props) {
|
|||
|
var map = Object.create(null);
|
|||
|
for (var i in props) {
|
|||
|
map[i] = props[i];
|
|||
|
}
|
|||
|
return map;
|
|||
|
};
|
|||
|
exports.arrayRemove = function(array, value) {
|
|||
|
for (var i = 0; i <= array.length; i++) {
|
|||
|
if (value === array[i]) {
|
|||
|
array.splice(i, 1);
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
exports.escapeRegExp = function(str) {
|
|||
|
return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
|
|||
|
};
|
|||
|
|
|||
|
exports.escapeHTML = function(str) {
|
|||
|
return str.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<");
|
|||
|
};
|
|||
|
|
|||
|
exports.getMatchOffsets = function(string, regExp) {
|
|||
|
var matches = [];
|
|||
|
|
|||
|
string.replace(regExp, function(str) {
|
|||
|
matches.push({
|
|||
|
offset: arguments[arguments.length-2],
|
|||
|
length: str.length
|
|||
|
});
|
|||
|
});
|
|||
|
|
|||
|
return matches;
|
|||
|
};
|
|||
|
exports.deferredCall = function(fcn) {
|
|||
|
var timer = null;
|
|||
|
var callback = function() {
|
|||
|
timer = null;
|
|||
|
fcn();
|
|||
|
};
|
|||
|
|
|||
|
var deferred = function(timeout) {
|
|||
|
deferred.cancel();
|
|||
|
timer = setTimeout(callback, timeout || 0);
|
|||
|
return deferred;
|
|||
|
};
|
|||
|
|
|||
|
deferred.schedule = deferred;
|
|||
|
|
|||
|
deferred.call = function() {
|
|||
|
this.cancel();
|
|||
|
fcn();
|
|||
|
return deferred;
|
|||
|
};
|
|||
|
|
|||
|
deferred.cancel = function() {
|
|||
|
clearTimeout(timer);
|
|||
|
timer = null;
|
|||
|
return deferred;
|
|||
|
};
|
|||
|
|
|||
|
deferred.isPending = function() {
|
|||
|
return timer;
|
|||
|
};
|
|||
|
|
|||
|
return deferred;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
exports.delayedCall = function(fcn, defaultTimeout) {
|
|||
|
var timer = null;
|
|||
|
var callback = function() {
|
|||
|
timer = null;
|
|||
|
fcn();
|
|||
|
};
|
|||
|
|
|||
|
var _self = function(timeout) {
|
|||
|
if (timer == null)
|
|||
|
timer = setTimeout(callback, timeout || defaultTimeout);
|
|||
|
};
|
|||
|
|
|||
|
_self.delay = function(timeout) {
|
|||
|
timer && clearTimeout(timer);
|
|||
|
timer = setTimeout(callback, timeout || defaultTimeout);
|
|||
|
};
|
|||
|
_self.schedule = _self;
|
|||
|
|
|||
|
_self.call = function() {
|
|||
|
this.cancel();
|
|||
|
fcn();
|
|||
|
};
|
|||
|
|
|||
|
_self.cancel = function() {
|
|||
|
timer && clearTimeout(timer);
|
|||
|
timer = null;
|
|||
|
};
|
|||
|
|
|||
|
_self.isPending = function() {
|
|||
|
return timer;
|
|||
|
};
|
|||
|
|
|||
|
return _self;
|
|||
|
};
|
|||
|
});
|
|||
|
|
|||
|
ace.define("ace/worker/mirror",["require","exports","module","ace/range","ace/document","ace/lib/lang"], function(require, exports, module) {
|
|||
|
"use strict";
|
|||
|
|
|||
|
var Range = require("../range").Range;
|
|||
|
var Document = require("../document").Document;
|
|||
|
var lang = require("../lib/lang");
|
|||
|
|
|||
|
var Mirror = exports.Mirror = function(sender) {
|
|||
|
this.sender = sender;
|
|||
|
var doc = this.doc = new Document("");
|
|||
|
|
|||
|
var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
|
|||
|
|
|||
|
var _self = this;
|
|||
|
sender.on("change", function(e) {
|
|||
|
var data = e.data;
|
|||
|
if (data[0].start) {
|
|||
|
doc.applyDeltas(data);
|
|||
|
} else {
|
|||
|
for (var i = 0; i < data.length; i += 2) {
|
|||
|
if (Array.isArray(data[i+1])) {
|
|||
|
var d = {action: "insert", start: data[i], lines: data[i+1]};
|
|||
|
} else {
|
|||
|
var d = {action: "remove", start: data[i], end: data[i+1]};
|
|||
|
}
|
|||
|
doc.applyDelta(d, true);
|
|||
|
}
|
|||
|
}
|
|||
|
if (_self.$timeout)
|
|||
|
return deferredUpdate.schedule(_self.$timeout);
|
|||
|
_self.onUpdate();
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
(function() {
|
|||
|
|
|||
|
this.$timeout = 500;
|
|||
|
|
|||
|
this.setTimeout = function(timeout) {
|
|||
|
this.$timeout = timeout;
|
|||
|
};
|
|||
|
|
|||
|
this.setValue = function(value) {
|
|||
|
this.doc.setValue(value);
|
|||
|
this.deferredUpdate.schedule(this.$timeout);
|
|||
|
};
|
|||
|
|
|||
|
this.getValue = function(callbackId) {
|
|||
|
this.sender.callback(this.doc.getValue(), callbackId);
|
|||
|
};
|
|||
|
|
|||
|
this.onUpdate = function() {
|
|||
|
};
|
|||
|
|
|||
|
this.isPending = function() {
|
|||
|
return this.deferredUpdate.isPending();
|
|||
|
};
|
|||
|
|
|||
|
}).call(Mirror.prototype);
|
|||
|
|
|||
|
});
|
|||
|
|
|||
|
ace.define("ace/mode/coffee/coffee",["require","exports","module"], function(require, exports, module) {
|
|||
|
function define(f) { module.exports = f() }; define.amd = {};
|
|||
|
(function(root){var CoffeeScript=function(){function _dereq_(e){return _dereq_[e]}return _dereq_["./helpers"]=function(){var e={},t={exports:e};return function(){var t,n,i,r,s,o;e.starts=function(e,t,n){return t===e.substr(n,t.length)},e.ends=function(e,t,n){var i;return i=t.length,t===e.substr(e.length-i-(n||0),i)},e.repeat=s=function(e,t){var n;for(n="";t>0;)1&t&&(n+=e),t>>>=1,e+=e;return n},e.compact=function(e){var t,n,i,r;for(r=[],t=0,i=e.length;i>t;t++)n=e[t],n&&r.push(n);return r},e.count=function(e,t){var n,i;if(n=i=0,!t.length)return 1/0;for(;i=1+e.indexOf(t,i);)n++;return n},e.merge=function(e,t){return n(n({},e),t)},n=e.extend=function(e,t){var n,i;for(n in t)i=t[n],e[n]=i;return e},e.flatten=i=function(e){var t,n,r,s;for(n=[],r=0,s=e.length;s>r;r++)t=e[r],t instanceof Array?n=n.concat(i(t)):n.push(t);return n},e.del=function(e,t){var n;return n=e[t],delete e[t],n},e.some=null!=(r=Array.prototype.some)?r:function(e){var t,n,i;for(n=0,i=this.length;i>n;n++)if(t=this[n],e(t))return!0;return!1},e.invertLiterate=function(e){var t,n,i;return i=!0,n=function(){var n,r,s,o;for(s=e.split("\n"),o=[],n=0,r=s.length;r>n;n++)t=s[n],i&&/^([ ]{4}|[ ]{0,3}\t)/.test(t)?o.push(t):(i=/^\s*$/.test(t))?o.push(t):o.push("# "+t);return o}(),n.join("\n")},t=function(e,t){return t?{first_line:e.first_line,first_column:e.first_column,last_line:t.last_line,last_column:t.last_column}:e},e.addLocationDataFn=function(e,n){return function(i){return"object"==typeof i&&i.updateLocationDataIfMissing&&i.updateLocationDataIfMissing(t(e,n)),i}},e.locationDataToString=function(e){var t;return"2"in e&&"first_line"in e[2]?t=e[2]:"first_line"in e&&(t=e),t?t.first_line+1+":"+(t.first_column+1)+"-"+(t.last_line+1+":"+(t.last_column+1)):"No location data"},e.baseFileName=function(e,t,n){var i,r;return null==t&&(t=!1),null==n&&(n=!1),r=n?/\\|\//:/\//,i=e.split(r),e=i[i.length-1],t&&e.indexOf(".")>=0?(i=e.split("."),i.pop(),"coffee"===i[i.length-1]&&i.length>1&&i.pop(),i.join(".")):e},e.isCoffee=function(e){return/\.((lit)?coffee|coffee\.md)$/.test(e)},e.isLiterate=function(e){return/\.(litcoffee|coffee\.md)$/.test(e)},e.throwSyntaxError=function(e,t){var n;throw n=new SyntaxError(e),n.location=t,n.toString=o,n.stack=""+n,n},e.updateSyntaxError=function(e,t,n){return e.toString===o&&(e.code||(e.code=t),e.filename||(e.filename=n),e.stack=""+e),e},o=function(){var e,t,n,i,r,o,a,c,h,l,u,p,d,f,m;return this.code&&this.location?(u=this.location,a=u.first_line,o=u.first_column,h=u.last_line,c=u.last_column,null==h&&(h=a),null==c&&(c=o),r=this.filename||"[stdin]",e=this.code.split("\n")[a],m=o,i=a===h?c+1:e.length,l=e.slice(0,m).replace(/[^\s]/g," ")+s("^",i-m),"undefined"!=typeof process&&null!==process&&(n=(null!=(p=process.stdout)?p.isTTY:void 0)&&!(null!=(d=process.env)?d.NODE_DISABLE_COLORS:void 0)),(null!=(f=this.colorful)?f:n)&&(t=function(e){return"[1;31m"+e+"[0m"},e=e.slice(0,m)+t(e.slice(m,i))+e.slice(i),l=t(l)),r+":"+(a+1)+":"+(o+1)+": error: "+this.message+"\n"+e+"\n"+l):Error.prototype.toString.call(this)},e.nameWhitespaceCharacter=function(e){switch(e){case" ":return"space";case"\n":return"newline";case"\r":return"carriage return";case" ":return"tab";default:return e}}}.call(this),t.exports}(),_dereq_["./rewriter"]=function(){var e={},t={exports:e};return function(){var t,n,i,r,s,o,a,c,h,l,u,p,d,f,m,g,v,y,b,k=[].indexOf||function(e){for(var t=0,n=this.length;n>t;t++)if(t in this&&this[t]===e)return t;return-1},w=[].slice;for(f=function(e,t,n){var i;return i=[e,t],i.generated=!0,n&&(i.origin=n),i},e.Rewriter=function(){function e(){}return e.prototype.rewrite=function(e){return this.tokens=e,this.removeLeadingNewlines(),this.closeOpenCalls(),this.closeOpenIndexes(),this.normalizeLines(),this.tagPostfixConditionals(),this.addImplicitBracesAndParens(),this.addLocationDataToGeneratedTokens(),this.tokens},e.prototype.scanTokens=function(e){var t,n,i;for(i=this.tokens,t=0;n=i[t];)t+=e.call(this,n,t,i);return!0},e.prototype.detectEnd=function(e,t,n){var i,o,a,c,h;for(h=this.tokens,i=0;c=h[e];){if(0===i&&t.call(this,c,e))return n.call(this,c,e);if(!c||
|
|||
|
switch(r){case 1:return this.$=i.addLocationDataFn(o[a],o[a])(new i.Block);case 2:return this.$=s[a];case 3:this.$=i.addLocationDataFn(o[a],o[a])(i.Block.wrap([s[a]]));break;case 4:this.$=i.addLocationDataFn(o[a-2],o[a])(s[a-2].push(s[a]));break;case 5:this.$=s[a-1];break;case 6:case 7:case 8:case 9:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 27:case 32:case 34:case 45:case 46:case 47:case 48:case 56:case 57:case 67:case 68:case 69:case 70:case 75:case 76:case 79:case 83:case 89:case 133:case 134:case 136:case 166:case 167:case 183:case 189:this.$=s[a];break;case 10:case 25:case 26:case 28:case 30:case 33:case 35:this.$=i.addLocationDataFn(o[a],o[a])(new i.Literal(s[a]));break;case 23:this.$=i.addLocationDataFn(o[a-1],o[a])(new i.Block);break;case 24:case 31:case 90:this.$=i.addLocationDataFn(o[a-2],o[a])(s[a-1]);break;case 29:case 146:this.$=i.addLocationDataFn(o[a-2],o[a])(new i.Parens(s[a-1]));break;case 36:this.$=i.addLocationDataFn(o[a],o[a])(new i.Undefined);break;case 37:this.$=i.addLocationDataFn(o[a],o[a])(new i.Null);break;case 38:this.$=i.addLocationDataFn(o[a],o[a])(new i.Bool(s[a]));break;case 39:this.$=i.addLocationDataFn(o[a-2],o[a])(new i.Assign(s[a-2],s[a]));break;case 40:this.$=i.addLocationDataFn(o[a-3],o[a])(new i.Assign(s[a-3],s[a]));break;case 41:this.$=i.addLocationDataFn(o[a-4],o[a])(new i.Assign(s[a-4],s[a-1]));break;case 42:case 72:case 77:case 78:case 80:case 81:case 82:case 168:case 169:this.$=i.addLocationDataFn(o[a],o[a])(new i.Value(s[a]));break;case 43:this.$=i.addLocationDataFn(o[a-2],o[a])(new i.Assign(i.addLocationDataFn(o[a-2])(new i.Value(s[a-2])),s[a],"object"));break;case 44:this.$=i.addLocationDataFn(o[a-4],o[a])(new i.Assign(i.addLocationDataFn(o[a-4])(new i.Value(s[a-4])),s[a-1],"object"));break;case 49:this.$=i.addLocationDataFn(o[a-1],o[a])(new i.Return(s[a]));break;case 50:this.$=i.addLocationDataFn(o[a],o[a])(new i.Return);break;case 51:this.$=i.addLocationDataFn(o[a],o[a])(new i.Comment(s[a]));break;case 52:this.$=i.addLocationDataFn(o[a-4],o[a])(new i.Code(s[a-3],s[a],s[a-1]));break;case 53:this.$=i.addLocationDataFn(o[a-1],o[a])(new i.Code([],s[a],s[a-1]));break;case 54:this.$=i.addLocationDataFn(o[a],o[a])("func");break;case 55:this.$=i.addLocationDataFn(o[a],o[a])("boundfunc");break;case 58:case 95:this.$=i.addLocationDataFn(o[a],o[a])([]);break;case 59:case 96:case 128:case 170:this.$=i.addLocationDataFn(o[a],o[a])([s[a]]);break;case 60:case 97:case 129:this.$=i.addLocationDataFn(o[a-2],o[a])(s[a-2].concat(s[a]));break;case 61:case 98:case 130:this.$=i.addLocationDataFn(o[a-3],o[a])(s[a-3].concat(s[a]));break;case 62:case 99:case 132:this.$=i.addLocationDataFn(o[a-5],o[a])(s[a-5].concat(s[a-2]));break;case 63:this.$=i.addLocationDataFn(o[a],o[a])(new i.Param(s[a]));break;case 64:this.$=i.addLocationDataFn(o[a-1],o[a])(new i.Param(s[a-1],null,!0));break;case 65:this.$=i.addLocationDataFn(o[a-2],o[a])(new i.Param(s[a-2],s[a]));break;case 66:case 135:this.$=i.addLocationDataFn(o[a],o[a])(new i.Expansion);break;case 71:this.$=i.addLocationDataFn(o[a-1],o[a])(new i.Splat(s[a-1]));break;case 73:this.$=i.addLocationDataFn(o[a-1],o[a])(s[a-1].add(s[a]));break;case 74:this.$=i.addLocationDataFn(o[a-1],o[a])(new i.Value(s[a-1],[].concat(s[a])));break;case 84:this.$=i.addLocationDataFn(o[a-1],o[a])(new i.Access(s[a]));break;case 85:this.$=i.addLocationDataFn(o[a-1],o[a])(new i.Access(s[a],"soak"));break;case 86:this.$=i.addLocationDataFn(o[a-1],o[a])([i.addLocationDataFn(o[a-1])(new i.Access(new i.Literal("prototype"))),i.addLocationDataFn(o[a])(new i.Access(s[a]))]);break;case 87:this.$=i.addLocationDataFn(o[a-1],o[a])([i.addLocationDataFn(o[a-1])(new i.Access(new i.Literal("prototype"),"soak")),i.addLocationDataFn(o[a])(new i.Access(s[a]))]);break;case 88:this.$=i.addLocationDataFn(o[a],o[a])(new i.Access(new i.Literal("prototype")));break;case 91:this.$=i.addLocationDataFn(o[a-1],o[a])(i.extend(s[a],{soak:!0}));break;case 92:this.$=i.addLocationDataFn(o[a],o[a])(new i.Index(s[a]));break;case 93:this.$=i.addLocationDataFn
|
|||
|
this.trace(e)},parse:function(e){function t(){var e;return e=f.lex()||p,"number"!=typeof e&&(e=n.symbols_[e]||e),e}var n=this,i=[0],r=[null],s=[],o=this.table,a="",c=0,h=0,l=0,u=2,p=1,d=s.slice.call(arguments,1),f=Object.create(this.lexer),m={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(m.yy[g]=this.yy[g]);f.setInput(e,m.yy),m.yy.lexer=f,m.yy.parser=this,f.yylloc===void 0&&(f.yylloc={});var v=f.yylloc;s.push(v);var y=f.options&&f.options.ranges;this.parseError="function"==typeof m.yy.parseError?m.yy.parseError:Object.getPrototypeOf(this).parseError;for(var b,k,w,T,C,E,F,N,L,x={};;){if(w=i[i.length-1],this.defaultActions[w]?T=this.defaultActions[w]:((null===b||b===void 0)&&(b=t()),T=o[w]&&o[w][b]),T===void 0||!T.length||!T[0]){var S="";L=[];for(E in o[w])this.terminals_[E]&&E>u&&L.push("'"+this.terminals_[E]+"'");S=f.showPosition?"Parse error on line "+(c+1)+":\n"+f.showPosition()+"\nExpecting "+L.join(", ")+", got '"+(this.terminals_[b]||b)+"'":"Parse error on line "+(c+1)+": Unexpected "+(b==p?"end of input":"'"+(this.terminals_[b]||b)+"'"),this.parseError(S,{text:f.match,token:this.terminals_[b]||b,line:f.yylineno,loc:v,expected:L})}if(T[0]instanceof Array&&T.length>1)throw Error("Parse Error: multiple actions possible at state: "+w+", token: "+b);switch(T[0]){case 1:i.push(b),r.push(f.yytext),s.push(f.yylloc),i.push(T[1]),b=null,k?(b=k,k=null):(h=f.yyleng,a=f.yytext,c=f.yylineno,v=f.yylloc,l>0&&l--);break;case 2:if(F=this.productions_[T[1]][1],x.$=r[r.length-F],x._$={first_line:s[s.length-(F||1)].first_line,last_line:s[s.length-1].last_line,first_column:s[s.length-(F||1)].first_column,last_column:s[s.length-1].last_column},y&&(x._$.range=[s[s.length-(F||1)].range[0],s[s.length-1].range[1]]),C=this.performAction.apply(x,[a,h,c,m.yy,T[1],r,s].concat(d)),C!==void 0)return C;F&&(i=i.slice(0,2*-1*F),r=r.slice(0,-1*F),s=s.slice(0,-1*F)),i.push(this.productions_[T[1]][0]),r.push(x.$),s.push(x._$),N=o[i[i.length-2]][i[i.length-1]],i.push(N);break;case 3:return!0}}return!0}};return e.prototype=gn,gn.Parser=e,new e}();return _dereq_!==void 0&&e!==void 0&&(e.parser=n,e.Parser=n.Parser,e.parse=function(){return n.parse.apply(n,arguments)},e.main=function(t){t[1]||(console.log("Usage: "+t[0]+" FILE"),process.exit(1));var n=_dereq_("fs").readFileSync(_dereq_("path").normalize(t[1]),"utf8");return e.parser.parse(n)},t!==void 0&&_dereq_.main===t&&e.main(process.argv.slice(1))),t.exports}(),_dereq_["./scope"]=function(){var e={},t={exports:e};return function(){var t,n=[].indexOf||function(e){for(var t=0,n=this.length;n>t;t++)if(t in this&&this[t]===e)return t;return-1};e.Scope=t=function(){function e(e,t,n,i){var r,s;this.parent=e,this.expressions=t,this.method=n,this.referencedVars=i,this.variables=[{name:"arguments",type:"arguments"}],this.positions={},this.parent||(this.utilities={}),this.root=null!=(r=null!=(s=this.parent)?s.root:void 0)?r:this}return e.prototype.add=function(e,t,n){return this.shared&&!n?this.parent.add(e,t,n):Object.prototype.hasOwnProperty.call(this.positions,e)?this.variables[this.positions[e]].type=t:this.positions[e]=this.variables.push({name:e,type:t})-1},e.prototype.namedMethod=function(){var e;return(null!=(e=this.method)?e.name:void 0)||!this.parent?this.method:this.parent.namedMethod()},e.prototype.find=function(e){return this.check(e)?!0:(this.add(e,"var"),!1)},e.prototype.parameter=function(e){return this.shared&&this.parent.check(e,!0)?void 0:this.add(e,"param")},e.prototype.check=function(e){var t;return!!(this.type(e)||(null!=(t=this.parent)?t.check(e):void 0))},e.prototype.temporary=function(e,t,n){return null==n&&(n=!1),n?(t+parseInt(e,36)).toString(36).replace(/\d/g,"a"):e+(t||"")},e.prototype.type=function(e){var t,n,i,r;for(i=this.variables,t=0,n=i.length;n>t;t++)if(r=i[t],r.name===e)return r.type;return null},e.prototype.freeVariable=function(e,t){var i,r,s;for(null==t&&(t={}),i=0;;){if(s=this.temporary(e,i,t.single),!(this.check(s)||n.call(this.root.referencedVars,s)>=0))break;i++}return(null!=(r=t.reserve)?r:!0)&&this.add(s,"var",!0),s},e.prototype.assign=f
|
|||
|
},n.prototype.assigns=function(e){return this["object"===this.context?"value":"variable"].assigns(e)},n.prototype.unfoldSoak=function(e){return yt(e,this,"variable")},n.prototype.compileNode=function(e){var t,n,i,r,s,o,a,h,l,u,p,d,f,m;if(i=this.variable instanceof z){if(this.variable.isArray()||this.variable.isObject())return this.compilePatternMatch(e);if(this.variable.isSplice())return this.compileSplice(e);if("||="===(h=this.context)||"&&="===h||"?="===h)return this.compileConditional(e);if("**="===(l=this.context)||"//="===l||"%%="===l)return this.compileSpecialMath(e)}return this.value instanceof c&&(this.value["static"]?(this.value.klass=this.variable.base,this.value.name=this.variable.properties[0],this.value.variable=this.variable):(null!=(u=this.variable.properties)?u.length:void 0)>=2&&(p=this.variable.properties,o=p.length>=3?Ct.call(p,0,r=p.length-2):(r=0,[]),a=p[r++],s=p[r++],"prototype"===(null!=(d=a.name)?d.value:void 0)&&(this.value.klass=new z(this.variable.base,o),this.value.name=s,this.value.variable=this.variable))),this.context||(m=this.variable.unwrapAll(),m.isAssignable()||this.variable.error('"'+this.variable.compile(e)+'" cannot be assigned'),("function"==typeof m.hasProperties?m.hasProperties():void 0)||(this.param?e.scope.add(m.value,"var"):e.scope.find(m.value))),f=this.value.compileToFragments(e,E),n=this.variable.compileToFragments(e,E),"object"===this.context?n.concat(this.makeCode(": "),f):(t=n.concat(this.makeCode(" "+(this.context||"=")+" "),f),E>=e.level?t:this.wrapInBraces(t))},n.prototype.compilePatternMatch=function(e){var i,r,s,o,a,c,h,l,u,d,f,m,v,y,b,k,T,C,N,S,D,R,A,I,_,j,M,B;if(I=e.level===L,j=this.value,y=this.variable.base.objects,!(b=y.length))return s=j.compileToFragments(e),e.level>=F?this.wrapInBraces(s):s;if(l=this.variable.isObject(),I&&1===b&&!((v=y[0])instanceof G))return v instanceof n?(T=v,C=T.variable,h=C.base,v=T.value):h=l?v["this"]?v.properties[0].name:v:new x(0),i=g.test(h.unwrap().value||0),j=new z(j),j.properties.push(new(i?t:w)(h)),N=v.unwrap().value,Tt.call($,N)>=0&&v.error("assignment to a reserved word: "+v.compile(e)),new n(v,j,null,{param:this.param}).compileToFragments(e,L);for(M=j.compileToFragments(e,E),B=st(M),r=[],o=!1,(!g.test(B)||this.variable.assigns(B))&&(r.push([this.makeCode((k=e.scope.freeVariable("ref"))+" = ")].concat(Ct.call(M))),M=[this.makeCode(k)],B=k),c=d=0,f=y.length;f>d;c=++d){if(v=y[c],h=c,l&&(v instanceof n?(S=v,D=S.variable,h=D.base,v=S.value):v.base instanceof O?(R=new z(v.unwrapAll()).cacheReference(e),v=R[0],h=R[1]):h=v["this"]?v.properties[0].name:v),!o&&v instanceof G)m=v.name.unwrap().value,v=v.unwrap(),_=b+" <= "+B+".length ? "+bt("slice",e)+".call("+B+", "+c,(A=b-c-1)?(u=e.scope.freeVariable("i",{single:!0}),_+=", "+u+" = "+B+".length - "+A+") : ("+u+" = "+c+", [])"):_+=") : []",_=new x(_),o=u+"++";else{if(!o&&v instanceof p){(A=b-c-1)&&(1===A?o=B+".length - 1":(u=e.scope.freeVariable("i",{single:!0}),_=new x(u+" = "+B+".length - "+A),o=u+"++",r.push(_.compileToFragments(e,E))));continue}m=v.unwrap().value,(v instanceof G||v instanceof p)&&v.error("multiple splats/expansions are disallowed in an assignment"),"number"==typeof h?(h=new x(o||h),i=!1):i=l&&g.test(h.unwrap().value||0),_=new z(new x(B),[new(i?t:w)(h)])}null!=m&&Tt.call($,m)>=0&&v.error("assignment to a reserved word: "+v.compile(e)),r.push(new n(v,_,null,{param:this.param,subpattern:!0}).compileToFragments(e,E))}return I||this.subpattern||r.push(M),a=this.joinFragmentArrays(r,", "),E>e.level?a:this.wrapInBraces(a)},n.prototype.compileConditional=function(e){var t,i,r,s;return r=this.variable.cacheReference(e),i=r[0],s=r[1],!i.properties.length&&i.base instanceof x&&"this"!==i.base.value&&!e.scope.check(i.base.value)&&this.variable.error('the variable "'+i.base.value+"\" can't be assigned with "+this.context+" because it has not been declared before"),Tt.call(this.context,"?")>=0?(e.isExistentialEquals=!0,new b(new u(i),s,{type:"if"}).addElse(new n(s,this.value,"=")).compileToFragments(e)):(t=new I(this.context.slice(0,-1),i,new n(s,this.value,"=")).compileToFragm
|
|||
|
}catch(r){if(i=r,"string"!=typeof t)throw i;throw h.updateSyntaxError(i,t,n.filename)}}},e.compile=r=y(function(e,t){var i,r,s,o,a,c,l,u,f,m,g,v,y,b,k;for(v=h.merge,o=h.extend,t=o({},t),t.sourceMap&&(g=new n),k=p.tokenize(e,t),t.referencedVars=function(){var e,t,n;for(n=[],e=0,t=k.length;t>e;e++)b=k[e],b.variable&&n.push(b[1]);return n}(),c=d.parse(k).compileToFragments(t),s=0,t.header&&(s+=1),t.shiftLine&&(s+=1),r=0,f="",u=0,m=c.length;m>u;u++)a=c[u],t.sourceMap&&(a.locationData&&!/^[;\s]*$/.test(a.code)&&g.add([a.locationData.first_line,a.locationData.first_column],[s,r],{noReplace:!0}),y=h.count(a.code,"\n"),s+=y,y?r=a.code.length-(a.code.lastIndexOf("\n")+1):r+=a.code.length),f+=a.code;return t.header&&(l="Generated by CoffeeScript "+this.VERSION,f="// "+l+"\n"+f),t.sourceMap?(i={js:f},i.sourceMap=g,i.v3SourceMap=g.generate(t,e),i):f}),e.tokens=y(function(e,t){return p.tokenize(e,t)}),e.nodes=y(function(e,t){return"string"==typeof e?d.parse(p.tokenize(e,t)):d.parse(e)}),e.run=function(e,t){var n,i,s,o;return null==t&&(t={}),s=_dereq_.main,s.filename=process.argv[1]=t.filename?a.realpathSync(t.filename):".",s.moduleCache&&(s.moduleCache={}),i=t.filename?f.dirname(a.realpathSync(t.filename)):a.realpathSync("."),s.paths=_dereq_("module")._nodeModulePaths(i),(!h.isCoffee(s.filename)||_dereq_.extensions)&&(n=r(e,t),e=null!=(o=n.js)?o:n),s._compile(e,s.filename)},e.eval=function(e,t){var n,i,s,o,a,c,h,l,u,p,d,m,g,y,k,w,T;if(null==t&&(t={}),e=e.trim()){if(o=null!=(m=v.Script.createContext)?m:v.createContext,c=null!=(g=v.isContext)?g:function(){return t.sandbox instanceof o().constructor},o){if(null!=t.sandbox){if(c(t.sandbox))w=t.sandbox;else{w=o(),y=t.sandbox;for(l in y)b.call(y,l)&&(T=y[l],w[l]=T)}w.global=w.root=w.GLOBAL=w}else w=global;if(w.__filename=t.filename||"eval",w.__dirname=f.dirname(w.__filename),w===global&&!w.module&&!w.require){for(n=_dereq_("module"),w.module=i=new n(t.modulename||"eval"),w.require=s=function(e){return n._load(e,i,!0)},i.filename=w.__filename,k=Object.getOwnPropertyNames(_dereq_),a=0,u=k.length;u>a;a++)d=k[a],"paths"!==d&&(s[d]=_dereq_[d]);s.paths=i.paths=n._nodeModulePaths(process.cwd()),s.resolve=function(e){return n._resolveFilename(e,i)}}}p={};for(l in t)b.call(t,l)&&(T=t[l],p[l]=T);return p.bare=!0,h=r(e,p),w===global?v.runInThisContext(h):v.runInContext(h,w)}},e.register=function(){return _dereq_("./register")},_dereq_.extensions)for(m=this.FILE_EXTENSIONS,l=0,u=m.length;u>l;l++)s=m[l],null==(i=_dereq_.extensions)[s]&&(i[s]=function(){throw Error("Use CoffeeScript.register() or require the coffee-script/register module to require "+s+" files.")});e._compileFile=function(e,t){var n,i,s,o;null==t&&(t=!1),s=a.readFileSync(e,"utf8"),o=65279===s.charCodeAt(0)?s.substring(1):s;try{n=r(o,{filename:e,sourceMap:t,literate:h.isLiterate(e)})}catch(c){throw i=c,h.updateSyntaxError(i,o,e)}return n},p=new t,d.lexer={lex:function(){var e,t;return t=d.tokens[this.pos++],t?(e=t[0],this.yytext=t[1],this.yylloc=t[2],d.errorToken=t.origin||t,this.yylineno=this.yylloc.first_line):e="",e},setInput:function(e){return d.tokens=e,this.pos=0},upcomingInput:function(){return""}},d.yy=_dereq_("./nodes"),d.yy.parseError=function(e,t){var n,i,r,s,o,a;return o=t.token,s=d.errorToken,a=d.tokens,i=s[0],r=s[1],n=s[2],r=function(){switch(!1){case s!==a[a.length-1]:return"end of input";case"INDENT"!==i&&"OUTDENT"!==i:return"indentation";case"IDENTIFIER"!==i&&"NUMBER"!==i&&"STRING"!==i&&"STRING_START"!==i&&"REGEX"!==i&&"REGEX_START"!==i:return i.replace(/_START$/,"").toLowerCase();default:return h.nameWhitespaceCharacter(r)}}(),h.throwSyntaxError("unexpected "+r,n)},o=function(e,t){var n,i,r,s,o,a,c,h,l,u,p,d;return s=void 0,r="",e.isNative()?r="native":(e.isEval()?(s=e.getScriptNameOrSourceURL(),s||(r=e.getEvalOrigin()+", ")):s=e.getFileName(),s||(s="<anonymous>"),h=e.getLineNumber(),i=e.getColumnNumber(),u=t(s,h,i),r=u?s+":"+u[0]+":"+u[1]:s+":"+h+":"+i),o=e.getFunctionName(),a=e.isConstructor(),c=!(e.isToplevel()||a),c?(l=e.getMethodName(),d=e.getTypeName(),o?(p=n="",d&&o.indexOf(d)&&(p=d+"."),l&&o.indexOf("."+l)!==o.
|
|||
|
});
|
|||
|
|
|||
|
ace.define("ace/mode/coffee_worker",["require","exports","module","ace/lib/oop","ace/worker/mirror","ace/mode/coffee/coffee"], function(require, exports, module) {
|
|||
|
"use strict";
|
|||
|
|
|||
|
var oop = require("../lib/oop");
|
|||
|
var Mirror = require("../worker/mirror").Mirror;
|
|||
|
var coffee = require("../mode/coffee/coffee");
|
|||
|
|
|||
|
window.addEventListener = function() {};
|
|||
|
|
|||
|
|
|||
|
var Worker = exports.Worker = function(sender) {
|
|||
|
Mirror.call(this, sender);
|
|||
|
this.setTimeout(250);
|
|||
|
};
|
|||
|
|
|||
|
oop.inherits(Worker, Mirror);
|
|||
|
|
|||
|
(function() {
|
|||
|
|
|||
|
this.onUpdate = function() {
|
|||
|
var value = this.doc.getValue();
|
|||
|
var errors = [];
|
|||
|
try {
|
|||
|
coffee.compile(value);
|
|||
|
} catch(e) {
|
|||
|
var loc = e.location;
|
|||
|
if (loc) {
|
|||
|
errors.push({
|
|||
|
row: loc.first_line,
|
|||
|
column: loc.first_column,
|
|||
|
endRow: loc.last_line,
|
|||
|
endColumn: loc.last_column,
|
|||
|
text: e.message,
|
|||
|
type: "error"
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
this.sender.emit("annotate", errors);
|
|||
|
};
|
|||
|
|
|||
|
}).call(Worker.prototype);
|
|||
|
|
|||
|
});
|
|||
|
|
|||
|
ace.define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) {
|
|||
|
|
|||
|
function Empty() {}
|
|||
|
|
|||
|
if (!Function.prototype.bind) {
|
|||
|
Function.prototype.bind = function bind(that) { // .length is 1
|
|||
|
var target = this;
|
|||
|
if (typeof target != "function") {
|
|||
|
throw new TypeError("Function.prototype.bind called on incompatible " + target);
|
|||
|
}
|
|||
|
var args = slice.call(arguments, 1); // for normal call
|
|||
|
var bound = function () {
|
|||
|
|
|||
|
if (this instanceof bound) {
|
|||
|
|
|||
|
var result = target.apply(
|
|||
|
this,
|
|||
|
args.concat(slice.call(arguments))
|
|||
|
);
|
|||
|
if (Object(result) === result) {
|
|||
|
return result;
|
|||
|
}
|
|||
|
return this;
|
|||
|
|
|||
|
} else {
|
|||
|
return target.apply(
|
|||
|
that,
|
|||
|
args.concat(slice.call(arguments))
|
|||
|
);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
};
|
|||
|
if(target.prototype) {
|
|||
|
Empty.prototype = target.prototype;
|
|||
|
bound.prototype = new Empty();
|
|||
|
Empty.prototype = null;
|
|||
|
}
|
|||
|
return bound;
|
|||
|
};
|
|||
|
}
|
|||
|
var call = Function.prototype.call;
|
|||
|
var prototypeOfArray = Array.prototype;
|
|||
|
var prototypeOfObject = Object.prototype;
|
|||
|
var slice = prototypeOfArray.slice;
|
|||
|
var _toString = call.bind(prototypeOfObject.toString);
|
|||
|
var owns = call.bind(prototypeOfObject.hasOwnProperty);
|
|||
|
var defineGetter;
|
|||
|
var defineSetter;
|
|||
|
var lookupGetter;
|
|||
|
var lookupSetter;
|
|||
|
var supportsAccessors;
|
|||
|
if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
|
|||
|
defineGetter = call.bind(prototypeOfObject.__defineGetter__);
|
|||
|
defineSetter = call.bind(prototypeOfObject.__defineSetter__);
|
|||
|
lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
|
|||
|
lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
|
|||
|
}
|
|||
|
if ([1,2].splice(0).length != 2) {
|
|||
|
if(function() { // test IE < 9 to splice bug - see issue #138
|
|||
|
function makeArray(l) {
|
|||
|
var a = new Array(l+2);
|
|||
|
a[0] = a[1] = 0;
|
|||
|
return a;
|
|||
|
}
|
|||
|
var array = [], lengthBefore;
|
|||
|
|
|||
|
array.splice.apply(array, makeArray(20));
|
|||
|
array.splice.apply(array, makeArray(26));
|
|||
|
|
|||
|
lengthBefore = array.length; //46
|
|||
|
array.splice(5, 0, "XXX"); // add one element
|
|||
|
|
|||
|
lengthBefore + 1 == array.length
|
|||
|
|
|||
|
if (lengthBefore + 1 == array.length) {
|
|||
|
return true;// has right splice implementation without bugs
|
|||
|
}
|
|||
|
}()) {//IE 6/7
|
|||
|
var array_splice = Array.prototype.splice;
|
|||
|
Array.prototype.splice = function(start, deleteCount) {
|
|||
|
if (!arguments.length) {
|
|||
|
return [];
|
|||
|
} else {
|
|||
|
return array_splice.apply(this, [
|
|||
|
start === void 0 ? 0 : start,
|
|||
|
deleteCount === void 0 ? (this.length - start) : deleteCount
|
|||
|
].concat(slice.call(arguments, 2)))
|
|||
|
}
|
|||
|
};
|
|||
|
} else {//IE8
|
|||
|
Array.prototype.splice = function(pos, removeCount){
|
|||
|
var length = this.length;
|
|||
|
if (pos > 0) {
|
|||
|
if (pos > length)
|
|||
|
pos = length;
|
|||
|
} else if (pos == void 0) {
|
|||
|
pos = 0;
|
|||
|
} else if (pos < 0) {
|
|||
|
pos = Math.max(length + pos, 0);
|
|||
|
}
|
|||
|
|
|||
|
if (!(pos+removeCount < length))
|
|||
|
removeCount = length - pos;
|
|||
|
|
|||
|
var removed = this.slice(pos, pos+removeCount);
|
|||
|
var insert = slice.call(arguments, 2);
|
|||
|
var add = insert.length;
|
|||
|
if (pos === length) {
|
|||
|
if (add) {
|
|||
|
this.push.apply(this, insert);
|
|||
|
}
|
|||
|
} else {
|
|||
|
var remove = Math.min(removeCount, length - pos);
|
|||
|
var tailOldPos = pos + remove;
|
|||
|
var tailNewPos = tailOldPos + add - remove;
|
|||
|
var tailCount = length - tailOldPos;
|
|||
|
var lengthAfterRemove = length - remove;
|
|||
|
|
|||
|
if (tailNewPos < tailOldPos) { // case A
|
|||
|
for (var i = 0; i < tailCount; ++i) {
|
|||
|
this[tailNewPos+i] = this[tailOldPos+i];
|
|||
|
}
|
|||
|
} else if (tailNewPos > tailOldPos) { // case B
|
|||
|
for (i = tailCount; i--; ) {
|
|||
|
this[tailNewPos+i] = this[tailOldPos+i];
|
|||
|
}
|
|||
|
} // else, add == remove (nothing to do)
|
|||
|
|
|||
|
if (add && pos === lengthAfterRemove) {
|
|||
|
this.length = lengthAfterRemove; // truncate array
|
|||
|
this.push.apply(this, insert);
|
|||
|
} else {
|
|||
|
this.length = lengthAfterRemove + add; // reserves space
|
|||
|
for (i = 0; i < add; ++i) {
|
|||
|
this[pos+i] = insert[i];
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return removed;
|
|||
|
};
|
|||
|
}
|
|||
|
}
|
|||
|
if (!Array.isArray) {
|
|||
|
Array.isArray = function isArray(obj) {
|
|||
|
return _toString(obj) == "[object Array]";
|
|||
|
};
|
|||
|
}
|
|||
|
var boxedString = Object("a"),
|
|||
|
splitString = boxedString[0] != "a" || !(0 in boxedString);
|
|||
|
|
|||
|
if (!Array.prototype.forEach) {
|
|||
|
Array.prototype.forEach = function forEach(fun /*, thisp*/) {
|
|||
|
var object = toObject(this),
|
|||
|
self = splitString && _toString(this) == "[object String]" ?
|
|||
|
this.split("") :
|
|||
|
object,
|
|||
|
thisp = arguments[1],
|
|||
|
i = -1,
|
|||
|
length = self.length >>> 0;
|
|||
|
if (_toString(fun) != "[object Function]") {
|
|||
|
throw new TypeError(); // TODO message
|
|||
|
}
|
|||
|
|
|||
|
while (++i < length) {
|
|||
|
if (i in self) {
|
|||
|
fun.call(thisp, self[i], i, object);
|
|||
|
}
|
|||
|
}
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Array.prototype.map) {
|
|||
|
Array.prototype.map = function map(fun /*, thisp*/) {
|
|||
|
var object = toObject(this),
|
|||
|
self = splitString && _toString(this) == "[object String]" ?
|
|||
|
this.split("") :
|
|||
|
object,
|
|||
|
length = self.length >>> 0,
|
|||
|
result = Array(length),
|
|||
|
thisp = arguments[1];
|
|||
|
if (_toString(fun) != "[object Function]") {
|
|||
|
throw new TypeError(fun + " is not a function");
|
|||
|
}
|
|||
|
|
|||
|
for (var i = 0; i < length; i++) {
|
|||
|
if (i in self)
|
|||
|
result[i] = fun.call(thisp, self[i], i, object);
|
|||
|
}
|
|||
|
return result;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Array.prototype.filter) {
|
|||
|
Array.prototype.filter = function filter(fun /*, thisp */) {
|
|||
|
var object = toObject(this),
|
|||
|
self = splitString && _toString(this) == "[object String]" ?
|
|||
|
this.split("") :
|
|||
|
object,
|
|||
|
length = self.length >>> 0,
|
|||
|
result = [],
|
|||
|
value,
|
|||
|
thisp = arguments[1];
|
|||
|
if (_toString(fun) != "[object Function]") {
|
|||
|
throw new TypeError(fun + " is not a function");
|
|||
|
}
|
|||
|
|
|||
|
for (var i = 0; i < length; i++) {
|
|||
|
if (i in self) {
|
|||
|
value = self[i];
|
|||
|
if (fun.call(thisp, value, i, object)) {
|
|||
|
result.push(value);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return result;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Array.prototype.every) {
|
|||
|
Array.prototype.every = function every(fun /*, thisp */) {
|
|||
|
var object = toObject(this),
|
|||
|
self = splitString && _toString(this) == "[object String]" ?
|
|||
|
this.split("") :
|
|||
|
object,
|
|||
|
length = self.length >>> 0,
|
|||
|
thisp = arguments[1];
|
|||
|
if (_toString(fun) != "[object Function]") {
|
|||
|
throw new TypeError(fun + " is not a function");
|
|||
|
}
|
|||
|
|
|||
|
for (var i = 0; i < length; i++) {
|
|||
|
if (i in self && !fun.call(thisp, self[i], i, object)) {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
return true;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Array.prototype.some) {
|
|||
|
Array.prototype.some = function some(fun /*, thisp */) {
|
|||
|
var object = toObject(this),
|
|||
|
self = splitString && _toString(this) == "[object String]" ?
|
|||
|
this.split("") :
|
|||
|
object,
|
|||
|
length = self.length >>> 0,
|
|||
|
thisp = arguments[1];
|
|||
|
if (_toString(fun) != "[object Function]") {
|
|||
|
throw new TypeError(fun + " is not a function");
|
|||
|
}
|
|||
|
|
|||
|
for (var i = 0; i < length; i++) {
|
|||
|
if (i in self && fun.call(thisp, self[i], i, object)) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Array.prototype.reduce) {
|
|||
|
Array.prototype.reduce = function reduce(fun /*, initial*/) {
|
|||
|
var object = toObject(this),
|
|||
|
self = splitString && _toString(this) == "[object String]" ?
|
|||
|
this.split("") :
|
|||
|
object,
|
|||
|
length = self.length >>> 0;
|
|||
|
if (_toString(fun) != "[object Function]") {
|
|||
|
throw new TypeError(fun + " is not a function");
|
|||
|
}
|
|||
|
if (!length && arguments.length == 1) {
|
|||
|
throw new TypeError("reduce of empty array with no initial value");
|
|||
|
}
|
|||
|
|
|||
|
var i = 0;
|
|||
|
var result;
|
|||
|
if (arguments.length >= 2) {
|
|||
|
result = arguments[1];
|
|||
|
} else {
|
|||
|
do {
|
|||
|
if (i in self) {
|
|||
|
result = self[i++];
|
|||
|
break;
|
|||
|
}
|
|||
|
if (++i >= length) {
|
|||
|
throw new TypeError("reduce of empty array with no initial value");
|
|||
|
}
|
|||
|
} while (true);
|
|||
|
}
|
|||
|
|
|||
|
for (; i < length; i++) {
|
|||
|
if (i in self) {
|
|||
|
result = fun.call(void 0, result, self[i], i, object);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return result;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Array.prototype.reduceRight) {
|
|||
|
Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
|
|||
|
var object = toObject(this),
|
|||
|
self = splitString && _toString(this) == "[object String]" ?
|
|||
|
this.split("") :
|
|||
|
object,
|
|||
|
length = self.length >>> 0;
|
|||
|
if (_toString(fun) != "[object Function]") {
|
|||
|
throw new TypeError(fun + " is not a function");
|
|||
|
}
|
|||
|
if (!length && arguments.length == 1) {
|
|||
|
throw new TypeError("reduceRight of empty array with no initial value");
|
|||
|
}
|
|||
|
|
|||
|
var result, i = length - 1;
|
|||
|
if (arguments.length >= 2) {
|
|||
|
result = arguments[1];
|
|||
|
} else {
|
|||
|
do {
|
|||
|
if (i in self) {
|
|||
|
result = self[i--];
|
|||
|
break;
|
|||
|
}
|
|||
|
if (--i < 0) {
|
|||
|
throw new TypeError("reduceRight of empty array with no initial value");
|
|||
|
}
|
|||
|
} while (true);
|
|||
|
}
|
|||
|
|
|||
|
do {
|
|||
|
if (i in this) {
|
|||
|
result = fun.call(void 0, result, self[i], i, object);
|
|||
|
}
|
|||
|
} while (i--);
|
|||
|
|
|||
|
return result;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
|
|||
|
Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
|
|||
|
var self = splitString && _toString(this) == "[object String]" ?
|
|||
|
this.split("") :
|
|||
|
toObject(this),
|
|||
|
length = self.length >>> 0;
|
|||
|
|
|||
|
if (!length) {
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
var i = 0;
|
|||
|
if (arguments.length > 1) {
|
|||
|
i = toInteger(arguments[1]);
|
|||
|
}
|
|||
|
i = i >= 0 ? i : Math.max(0, length + i);
|
|||
|
for (; i < length; i++) {
|
|||
|
if (i in self && self[i] === sought) {
|
|||
|
return i;
|
|||
|
}
|
|||
|
}
|
|||
|
return -1;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
|
|||
|
Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
|
|||
|
var self = splitString && _toString(this) == "[object String]" ?
|
|||
|
this.split("") :
|
|||
|
toObject(this),
|
|||
|
length = self.length >>> 0;
|
|||
|
|
|||
|
if (!length) {
|
|||
|
return -1;
|
|||
|
}
|
|||
|
var i = length - 1;
|
|||
|
if (arguments.length > 1) {
|
|||
|
i = Math.min(i, toInteger(arguments[1]));
|
|||
|
}
|
|||
|
i = i >= 0 ? i : length - Math.abs(i);
|
|||
|
for (; i >= 0; i--) {
|
|||
|
if (i in self && sought === self[i]) {
|
|||
|
return i;
|
|||
|
}
|
|||
|
}
|
|||
|
return -1;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Object.getPrototypeOf) {
|
|||
|
Object.getPrototypeOf = function getPrototypeOf(object) {
|
|||
|
return object.__proto__ || (
|
|||
|
object.constructor ?
|
|||
|
object.constructor.prototype :
|
|||
|
prototypeOfObject
|
|||
|
);
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Object.getOwnPropertyDescriptor) {
|
|||
|
var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
|
|||
|
"non-object: ";
|
|||
|
Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
|
|||
|
if ((typeof object != "object" && typeof object != "function") || object === null)
|
|||
|
throw new TypeError(ERR_NON_OBJECT + object);
|
|||
|
if (!owns(object, property))
|
|||
|
return;
|
|||
|
|
|||
|
var descriptor, getter, setter;
|
|||
|
descriptor = { enumerable: true, configurable: true };
|
|||
|
if (supportsAccessors) {
|
|||
|
var prototype = object.__proto__;
|
|||
|
object.__proto__ = prototypeOfObject;
|
|||
|
|
|||
|
var getter = lookupGetter(object, property);
|
|||
|
var setter = lookupSetter(object, property);
|
|||
|
object.__proto__ = prototype;
|
|||
|
|
|||
|
if (getter || setter) {
|
|||
|
if (getter) descriptor.get = getter;
|
|||
|
if (setter) descriptor.set = setter;
|
|||
|
return descriptor;
|
|||
|
}
|
|||
|
}
|
|||
|
descriptor.value = object[property];
|
|||
|
return descriptor;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Object.getOwnPropertyNames) {
|
|||
|
Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
|
|||
|
return Object.keys(object);
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Object.create) {
|
|||
|
var createEmpty;
|
|||
|
if (Object.prototype.__proto__ === null) {
|
|||
|
createEmpty = function () {
|
|||
|
return { "__proto__": null };
|
|||
|
};
|
|||
|
} else {
|
|||
|
createEmpty = function () {
|
|||
|
var empty = {};
|
|||
|
for (var i in empty)
|
|||
|
empty[i] = null;
|
|||
|
empty.constructor =
|
|||
|
empty.hasOwnProperty =
|
|||
|
empty.propertyIsEnumerable =
|
|||
|
empty.isPrototypeOf =
|
|||
|
empty.toLocaleString =
|
|||
|
empty.toString =
|
|||
|
empty.valueOf =
|
|||
|
empty.__proto__ = null;
|
|||
|
return empty;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Object.create = function create(prototype, properties) {
|
|||
|
var object;
|
|||
|
if (prototype === null) {
|
|||
|
object = createEmpty();
|
|||
|
} else {
|
|||
|
if (typeof prototype != "object")
|
|||
|
throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
|
|||
|
var Type = function () {};
|
|||
|
Type.prototype = prototype;
|
|||
|
object = new Type();
|
|||
|
object.__proto__ = prototype;
|
|||
|
}
|
|||
|
if (properties !== void 0)
|
|||
|
Object.defineProperties(object, properties);
|
|||
|
return object;
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function doesDefinePropertyWork(object) {
|
|||
|
try {
|
|||
|
Object.defineProperty(object, "sentinel", {});
|
|||
|
return "sentinel" in object;
|
|||
|
} catch (exception) {
|
|||
|
}
|
|||
|
}
|
|||
|
if (Object.defineProperty) {
|
|||
|
var definePropertyWorksOnObject = doesDefinePropertyWork({});
|
|||
|
var definePropertyWorksOnDom = typeof document == "undefined" ||
|
|||
|
doesDefinePropertyWork(document.createElement("div"));
|
|||
|
if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
|
|||
|
var definePropertyFallback = Object.defineProperty;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (!Object.defineProperty || definePropertyFallback) {
|
|||
|
var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
|
|||
|
var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
|
|||
|
var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
|
|||
|
"on this javascript engine";
|
|||
|
|
|||
|
Object.defineProperty = function defineProperty(object, property, descriptor) {
|
|||
|
if ((typeof object != "object" && typeof object != "function") || object === null)
|
|||
|
throw new TypeError(ERR_NON_OBJECT_TARGET + object);
|
|||
|
if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
|
|||
|
throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
|
|||
|
if (definePropertyFallback) {
|
|||
|
try {
|
|||
|
return definePropertyFallback.call(Object, object, property, descriptor);
|
|||
|
} catch (exception) {
|
|||
|
}
|
|||
|
}
|
|||
|
if (owns(descriptor, "value")) {
|
|||
|
|
|||
|
if (supportsAccessors && (lookupGetter(object, property) ||
|
|||
|
lookupSetter(object, property)))
|
|||
|
{
|
|||
|
var prototype = object.__proto__;
|
|||
|
object.__proto__ = prototypeOfObject;
|
|||
|
delete object[property];
|
|||
|
object[property] = descriptor.value;
|
|||
|
object.__proto__ = prototype;
|
|||
|
} else {
|
|||
|
object[property] = descriptor.value;
|
|||
|
}
|
|||
|
} else {
|
|||
|
if (!supportsAccessors)
|
|||
|
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
|
|||
|
if (owns(descriptor, "get"))
|
|||
|
defineGetter(object, property, descriptor.get);
|
|||
|
if (owns(descriptor, "set"))
|
|||
|
defineSetter(object, property, descriptor.set);
|
|||
|
}
|
|||
|
|
|||
|
return object;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Object.defineProperties) {
|
|||
|
Object.defineProperties = function defineProperties(object, properties) {
|
|||
|
for (var property in properties) {
|
|||
|
if (owns(properties, property))
|
|||
|
Object.defineProperty(object, property, properties[property]);
|
|||
|
}
|
|||
|
return object;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Object.seal) {
|
|||
|
Object.seal = function seal(object) {
|
|||
|
return object;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Object.freeze) {
|
|||
|
Object.freeze = function freeze(object) {
|
|||
|
return object;
|
|||
|
};
|
|||
|
}
|
|||
|
try {
|
|||
|
Object.freeze(function () {});
|
|||
|
} catch (exception) {
|
|||
|
Object.freeze = (function freeze(freezeObject) {
|
|||
|
return function freeze(object) {
|
|||
|
if (typeof object == "function") {
|
|||
|
return object;
|
|||
|
} else {
|
|||
|
return freezeObject(object);
|
|||
|
}
|
|||
|
};
|
|||
|
})(Object.freeze);
|
|||
|
}
|
|||
|
if (!Object.preventExtensions) {
|
|||
|
Object.preventExtensions = function preventExtensions(object) {
|
|||
|
return object;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Object.isSealed) {
|
|||
|
Object.isSealed = function isSealed(object) {
|
|||
|
return false;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Object.isFrozen) {
|
|||
|
Object.isFrozen = function isFrozen(object) {
|
|||
|
return false;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Object.isExtensible) {
|
|||
|
Object.isExtensible = function isExtensible(object) {
|
|||
|
if (Object(object) === object) {
|
|||
|
throw new TypeError(); // TODO message
|
|||
|
}
|
|||
|
var name = '';
|
|||
|
while (owns(object, name)) {
|
|||
|
name += '?';
|
|||
|
}
|
|||
|
object[name] = true;
|
|||
|
var returnValue = owns(object, name);
|
|||
|
delete object[name];
|
|||
|
return returnValue;
|
|||
|
};
|
|||
|
}
|
|||
|
if (!Object.keys) {
|
|||
|
var hasDontEnumBug = true,
|
|||
|
dontEnums = [
|
|||
|
"toString",
|
|||
|
"toLocaleString",
|
|||
|
"valueOf",
|
|||
|
"hasOwnProperty",
|
|||
|
"isPrototypeOf",
|
|||
|
"propertyIsEnumerable",
|
|||
|
"constructor"
|
|||
|
],
|
|||
|
dontEnumsLength = dontEnums.length;
|
|||
|
|
|||
|
for (var key in {"toString": null}) {
|
|||
|
hasDontEnumBug = false;
|
|||
|
}
|
|||
|
|
|||
|
Object.keys = function keys(object) {
|
|||
|
|
|||
|
if (
|
|||
|
(typeof object != "object" && typeof object != "function") ||
|
|||
|
object === null
|
|||
|
) {
|
|||
|
throw new TypeError("Object.keys called on a non-object");
|
|||
|
}
|
|||
|
|
|||
|
var keys = [];
|
|||
|
for (var name in object) {
|
|||
|
if (owns(object, name)) {
|
|||
|
keys.push(name);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (hasDontEnumBug) {
|
|||
|
for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
|
|||
|
var dontEnum = dontEnums[i];
|
|||
|
if (owns(object, dontEnum)) {
|
|||
|
keys.push(dontEnum);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return keys;
|
|||
|
};
|
|||
|
|
|||
|
}
|
|||
|
if (!Date.now) {
|
|||
|
Date.now = function now() {
|
|||
|
return new Date().getTime();
|
|||
|
};
|
|||
|
}
|
|||
|
var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
|
|||
|
"\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
|
|||
|
"\u2029\uFEFF";
|
|||
|
if (!String.prototype.trim || ws.trim()) {
|
|||
|
ws = "[" + ws + "]";
|
|||
|
var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
|
|||
|
trimEndRegexp = new RegExp(ws + ws + "*$");
|
|||
|
String.prototype.trim = function trim() {
|
|||
|
return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
function toInteger(n) {
|
|||
|
n = +n;
|
|||
|
if (n !== n) { // isNaN
|
|||
|
n = 0;
|
|||
|
} else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
|
|||
|
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
|||
|
}
|
|||
|
return n;
|
|||
|
}
|
|||
|
|
|||
|
function isPrimitive(input) {
|
|||
|
var type = typeof input;
|
|||
|
return (
|
|||
|
input === null ||
|
|||
|
type === "undefined" ||
|
|||
|
type === "boolean" ||
|
|||
|
type === "number" ||
|
|||
|
type === "string"
|
|||
|
);
|
|||
|
}
|
|||
|
|
|||
|
function toPrimitive(input) {
|
|||
|
var val, valueOf, toString;
|
|||
|
if (isPrimitive(input)) {
|
|||
|
return input;
|
|||
|
}
|
|||
|
valueOf = input.valueOf;
|
|||
|
if (typeof valueOf === "function") {
|
|||
|
val = valueOf.call(input);
|
|||
|
if (isPrimitive(val)) {
|
|||
|
return val;
|
|||
|
}
|
|||
|
}
|
|||
|
toString = input.toString;
|
|||
|
if (typeof toString === "function") {
|
|||
|
val = toString.call(input);
|
|||
|
if (isPrimitive(val)) {
|
|||
|
return val;
|
|||
|
}
|
|||
|
}
|
|||
|
throw new TypeError();
|
|||
|
}
|
|||
|
var toObject = function (o) {
|
|||
|
if (o == null) { // this matches both null and undefined
|
|||
|
throw new TypeError("can't convert "+o+" to object");
|
|||
|
}
|
|||
|
return Object(o);
|
|||
|
};
|
|||
|
|
|||
|
});
|